When shooting with an iPhone 15 or later, it’s possible to capture HEIC or JPEG images that include gain map information conforming to the ISO 21496-1 standard. However, during image format transcoding, the HEIC codec is able to preserve the ISO 21496-1 gain map. But when converting from HEIC to JPEG, the gain map is transformed into the Apple Gain Map format instead. Is there any solution to this issue?
How to transcode HEIC to JPEG while preserving the ISO 21496-1 gain map
Hi. Can you provide a small source listing showing the APIs you are using? Can you confirm you are using one of the workflows discussed in the following WWDC presentation:
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?
Additionally, when a JPEG image captured by the camera with ISO 21496-1 metadata is cropped using the built-in editing tool, it becomes an Apple Gain Map JPEG.