3

我正在尝试为我的应用程序编写一个允许 16 位深度 HEIF 文件的导出函数。Apple 的文档没有说明是否支持 16 位,也没有说明该writeHEIFRepresentation()方法是否需要任何特定选项。我一直在尝试使用每种颜色 16 位(每像素 64 位)格式和扩展的 Display P3 或 HLG 颜色空间,但输出仍然是 8 位。源图像是 16 位 TIFF。

这是我的游乐场代码:

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.")
}

请问你们有没有在CoreImage上创建HEIF文件的经验来分享?也许 Apple 的编码器还不支持 16 位 HEIF 文件?

非常感谢你。

4

0 回答 0