I am trying to write an export function for my app that allows 16-bit depth HEIF files. Apple's documentation doesn't specify whether 16-bit is supported nor if the writeHEIFRepresentation()
method requires any specific option for that. I have been trying with a 16-bit per color (64-bits per pixel) format and either the extended Display P3 or the HLG color spaces, but the output is still 8-bits. The source image is a 16-bits TIFF.
This is my playground code:
import Cocoa
import CoreImage
let originalImageURL = URL(fileURLWithPath: "/Users/myself/Desktop/DSC00990-HDR-3.tif")
let exportedImageURL = URL(fileURLWithPath: "/Users/myself/Desktop/DSC00990-HDR.heic")
guard let colorSpace = CGColorSpace(name: CGColorSpace.displayP3) else {
print("Couldn't create a color space. :(")
exit(1)
}
let context = CIContext()
let options = [kCGImageDestinationLossyCompressionQuality as CIImageRepresentationOption: 1.0 as CGFloat]
guard let image = CIImage(contentsOf: originalImageURL) else {
print("Couldn't create an image. :(")
exit(1)
}
do {
_ = try context.writeHEIFRepresentation(of: image, to: exportedImageURL, format: CIFormat.RGBA16, colorSpace: colorSpace, options: options)
print("It worked")
}
catch {
print("It failed.")
}
Would any of you have experience with creating HEIF files on CoreImage to share, please? Perhaps Apple's encoder doesn't support 16-bit HEIF files yet?
Thank you so much in advance.