I'm playing around with HDR images in iOS. I'm able to load an HDR image, but it isn't displaying with the expected "pop" I see of the same image in the Photos app. I exported the photo from Photos (on the Mac) using Export Unmodified. I reimported to confirm Photos shows the "pop."
I'm trying both UIImage and CIImage, with the same results. The below is tested on my iPhone 14 Pro (not Simulator).
The Storyboard for the code below has three UIImageViews (top, middle, and bottom).
let fileURL = Bundle.main.url(forResource: "IMG_6972", withExtension:"HEIC")!
var config = UIImageReader.Configuration()
config.prefersHighDynamicRange = true
let imageReader = UIImageReader(configuration: config)
let topImage = imageReader.image(contentsOf: fileURL)!
topImageView.preferredImageDynamicRange = .high
topImageView.image = topImage
// The image appears, looks SDR
print("topImage.isHighDynamicRange: \(topImage.isHighDynamicRange)") // true
let ciimage = CIImage(contentsOf: fileURL)!
bottomImageView.image = UIImage(ciImage: ciimage)
// The image appears, looks SDR - identical to topImage
print("color space: \(ciimage.colorSpace!)") // (kCGColorSpaceICCBased; kCGColorSpaceModelRGB; Display P3)
let gainMap = CIImage(contentsOf: fileURL, options: [.auxiliaryHDRGainMap: true])!
middleImageView.image = UIImage(ciImage: gainMap)
// The gain map image appears as expected
Additionally, for comparison, I tried:
let sdrImage = UIImage(named: "IMG_6972.HEIC")! // UIImage.named doesn't support HDR
print("sdrImage.isHighDynamicRange: \(sdrImage.isHighDynamicRange)")``` // false, as expected
bottomImageView.image = sdrImage
and the image matches the other two, further confirming the HDR version of the image isn't displaying in either UIImageReader or CIImage versions above.
I also track the UIScreen's use of EDR with:
print("currentEDR: \(UIScreen.main.currentEDRHeadroom)")
print("maxEDR: \(UIScreen.main.potentialEDRHeadroom)")
maxEDR is 8.0. currentEDR is 1.0 at launch, 1.3 after a 1.0 second delay. Which makes me think it might be showing a little HDR, but not enough to be noticeable.
Is there something special I need to do to set the UIViewController, UIScreen, or UIApplication (etc) to be an an "HDR Mode" or similar?