You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Is your feature request related to a problem? Please describe.
In skia (as well as in skiko) HEIC format doesn't supported.
This leads to incorrect flow on modern ios devices for image rendering (for example, custom media picker).
My idea is to add support of it inside a library.
Describe the solution you'd like
I have a simple workaround of this problem: convert heic image to jpeg.
My solution isn't elegant enough as I don't have access to coil internal methods.
I think there is a better way to support it
var builder =ImageRequest.Builder(LocalPlatformContext.current)
.data(uri) // uri is usually a path. For example, /var/storage/image.HEICif (uri.substringAfterLast('.').equals("HEIC", ignoreCase =true)) {
builder = builder.decoderFactory { result, options, imageLoader ->HEICImageDecoderFactory().create(result, options, imageLoader)
}
}
AsyncImage(
model = builder.build(),
contentDescription =null,
)
expectclassHEICImageDecoder(
source:ImageSource,
options:Options,
) : Decoder
// Decoder logicclassHEICImageDecoderFactory : Decoder.Factory {
overridefuncreate(
result:SourceFetchResult,
options:Options,
imageLoader:ImageLoader,
): Decoder {
returnHEICImageDecoder(result.source, options)
}
}
// ios implementation of expect classprivateconstvalCOMPRESSION=0.3actualclassHEICImageDecoder actual constructor(
privatevalsource:ImageSource,
privatevaloptions:Options
) : Decoder {
@OptIn(ExperimentalCoilApi::class)
overridesuspendfundecode(): DecodeResult {
val originalBytes = source.source().use { it.readByteArray() }
val jpegBytes = originalBytes.toJpegBytes()
val image =Image.makeFromEncoded(jpegBytes)
val isSampled:Booleanval bitmap:Bitmaptry {
bitmap =Bitmap.makeFromImage(image, options)
bitmap.setImmutable()
isSampled = bitmap.width < image.width || bitmap.height < image.height
} finally {
image.close()
}
returnDecodeResult(
image = bitmap.asCoilImage(),
isSampled = isSampled,
)
}
}
@OptIn(ExperimentalForeignApi::class)
privatefun ByteArray.toJpegBytes(): ByteArray= memScoped {
val image =UIImage(data =this@toJpegBytes.toNSData())
returnUIImageJPEGRepresentation(image, compressionQuality =COMPRESSION)!!.toByteArray()
}
The text was updated successfully, but these errors were encountered:
I think this is best implemented as an external library to Coil since it could be implemented with a custom Decoder.Factory and doesn't require access to Coil's internals. HEIC is a complex format and adding support for it on all of Coil's platforms would be a large task.
Is your feature request related to a problem? Please describe.
In skia (as well as in skiko) HEIC format doesn't supported.
This leads to incorrect flow on modern ios devices for image rendering (for example, custom media picker).
My idea is to add support of it inside a library.
Describe the solution you'd like
I have a simple workaround of this problem: convert heic image to jpeg.
My solution isn't elegant enough as I don't have access to coil internal methods.
I think there is a better way to support it
The text was updated successfully, but these errors were encountered: