Thank you for your response. I’ve just re-verified the process and realized that I had previously confused one of the cases. Below is the code I used for testing. It appears that for images encoded with ISO 21496-1, transcoding to JPEG does not preserve the ISO 21496-1 gain map.
guard let p3colorSpace = CGColorSpace(name: CGColorSpace.displayP3),
let sdrimage = CIImage(data: data, options: [.applyOrientationProperty: true]),
let gainMapImage = CIImage(data: data, options: [.auxiliaryHDRGainMap: true, .applyOrientationProperty: true]),
let hdrimage = CIImage(data: data, options: [.expandToHDR: true, .applyOrientationProperty: true]) else {
return
}
do {
let context = CIContext()
let url = URL(fileURLWithPath: path + "hdr_1.heic")
try context.writeHEIFRepresentation(of: sdrimage, to: url, format: .ARGB8, colorSpace: p3colorSpace, options: [.hdrImage: hdrimage])
let url4 = URL(fileURLWithPath: path + "hdr_2.heic")
try context.writeHEIF10Representation(of: sdrimage, to: url4, colorSpace: p3colorSpace, options: [
.hdrImage: hdrimage
])
let url2 = URL(fileURLWithPath: path + "hdr_3.jpg")
try context.writeJPEGRepresentation(of: sdrimage, to: url2, colorSpace: p3colorSpace, options: [.hdrGainMapImage: gainMapImage])
let url3 = URL(fileURLWithPath: path + "hdr_4.jpg")
try context.writeJPEGRepresentation(of: sdrimage, to: url3, colorSpace: p3colorSpace, options: [.hdrImage: hdrimage])
} catch {
print(error)
}
Behavior Observed:
• When data contains an image encoded with ISO 21496-1:
• hdr_1.heic and hdr_2.heic preserve the HDR data correctly.
• hdr_3.jpg and hdr_4.jpg lose the HDR information.
• When data contains an Apple Gain Map image:
• hdr_1.heic and hdr_2.heic convert it to an ISO 21496-1-compliant image.
• hdr_3.jpg outputs an Apple Gain Map JPEG.
• hdr_4.jpg loses HDR information.
Question:
Given that iPhone-captured images can natively support ISO 21496-1 in JPEG format, is there currently an API available that allows transcoding from HEIC to JPEG while preserving the ISO 21496-1 gain map? Or is this capability not yet exposed via Core Image or Image I/O?