fix(mobile): show 10-bit heic and avif originals on ios (#32821)

(cherry picked from commit ca25e8becc4bfb18d63ca7920d26a984eae0e16f)
This commit is contained in:
Santo Shakil
2026-10-31 07:23:57 +03:00
committed by Codex
parent e15bdf9af3
commit a3a52a43ca
3 changed files with 21 additions and 2 deletions
@@ -1,3 +1,4 @@
import Accelerate
import Foundation import Foundation
enum ImageProcessing { enum ImageProcessing {
@@ -11,4 +12,22 @@ enum ImageProcessing {
static let cancelledResult = Result<[String: Int64]?, any Error>.success(nil) static let cancelledResult = Result<[String: Int64]?, any Error>.success(nil)
// Impeller shrinks each side to the GPU texture limit on its own, which squishes long images. // Impeller shrinks each side to the GPU texture limit on its own, which squishes long images.
static let maxPixelSize = 16384 static let maxPixelSize = 16384
static func rgbaBuffer(_ image: CGImage, format: vImage_CGImageFormat) throws -> vImage_Buffer {
guard image.bitsPerComponent == 10 else {
return try vImage_Buffer(cgImage: image, format: format)
}
// vImage can't convert packed 10-bit images.
let buffer = try vImage_Buffer(width: image.width, height: image.height, bitsPerPixel: format.bitsPerPixel)
guard let context = CGContext(data: buffer.data, width: image.width, height: image.height, bitsPerComponent: Int(format.bitsPerComponent), bytesPerRow: buffer.rowBytes, space: format.colorSpace.takeUnretainedValue(), bitmapInfo: format.bitmapInfo.rawValue) else {
buffer.free()
throw vImage.Error.invalidImageFormat
}
context.setRenderingIntent(format.renderingIntent)
context.setBlendMode(.copy)
context.draw(image, in: CGRect(x: 0, y: 0, width: image.width, height: image.height))
return buffer
}
} }
@@ -165,7 +165,7 @@ class LocalImageApiImpl: LocalImageApi {
} }
do { do {
let buffer = try vImage_Buffer(cgImage: cgImage, format: Self.rgbaFormat) let buffer = try ImageProcessing.rgbaBuffer(cgImage, format: Self.rgbaFormat)
if request.isCancelled { if request.isCancelled {
buffer.free() buffer.free()
@@ -148,7 +148,7 @@ class RemoteImageApiImpl: NSObject, RemoteImageApi {
} }
do { do {
let buffer = try vImage_Buffer(cgImage: cgImage, format: rgbaFormat) let buffer = try ImageProcessing.rgbaBuffer(cgImage, format: rgbaFormat)
if request.isCancelled { if request.isCancelled {
buffer.free() buffer.free()