How to access HDRGainMap from AVCapturePhoto

Hey, I'm building a camera app and I want to use the captured HDRGainMap along side the photo to do some processing with a CIFilter chain. How can this be done? I can't find any documentation any where on this, only on how to access the HDRGainMap from an existing HEIC file, which I have done successfully. For this I'm doing something like the following:

let gainmap = CGImageSourceCopyAuxiliaryDataInfoAtIndex(source, 0, kCGImageAuxiliaryDataTypeHDRGainMap)
let gainDict = NSDictionary(dictionary: gainmap)
let gainData = gainDict[kCGImageAuxiliaryDataInfoData] as? Data
let gainDescription = gainDict[kCGImageAuxiliaryDataInfoDataDescription]
let gainMeta = gainDict[kCGImageAuxiliaryDataInfoMetadata]

However I'm not sure what the approach is with a AVCapturePhoto output from a AVCaptureDevice.

Thanks!

Answered by DTS Engineer in 821329022

Hello @alexfoxdev,

Assuming there is an HDR gain map in the photo your captured, you can access it like this:

// `photo` is an AVCapturePhoto
let data = photo.fileDataRepresentation()!
        
let gainMap = CIImage(data: data, options: [.auxiliaryHDRGainMap : true])
        
print(gainMap)

-- Greg

Hello @alexfoxdev,

Assuming there is an HDR gain map in the photo your captured, you can access it like this:

// `photo` is an AVCapturePhoto
let data = photo.fileDataRepresentation()!
        
let gainMap = CIImage(data: data, options: [.auxiliaryHDRGainMap : true])
        
print(gainMap)

-- Greg

Hello @alexfoxdev,

Make sure your capture device's activeFormat reports true for isHighestPhotoQualitySupported. (or use the ".photo" sessionPreset on the capture session).

-- Greg

How to access HDRGainMap from AVCapturePhoto
 
 
Q