KiteImageDecoder

class KiteImageDecoder(source: ImageSource, options: Options, maxCacheableAnimationBytes: Long = Factory.DEFAULT_MAX_CACHEABLE_ANIMATION_BYTES, colorTarget: ColorTarget = ColorTarget.Srgb()) : Decoder(source)

A coil3.decode.Decoder backed by ImageKodec's pure-Kotlin codecs.

Register the Factory on your ImageLoader and Coil keeps doing everything it is good at (network fetch, disk + memory cache, request lifecycle) while decoding runs through ImageKodec with identical behavior on every target:

ImageLoader.Builder(context)
.components { add(KiteImageDecoder.Factory()) }
.build()

The factory uses ImageKodec.probe and a complete WebP chunk-header walk to decide whether this build can decode the bytes. It claims PNG and APNG, JPEG, GIF, BMP, lossy and lossless WebP (including animations), TIFF, JP2, AVIF and JPEG XL, and HEIC once a codec for its items is installed: HEVC needs the imagekodec-heic module and a call to ImageKodecHeic.install() at startup, which this module does not make. Without it a HEIC file falls through to the platform decoder. A HEIF file whose meta box runs past the first 64 KiB is read up to the end of that box to decide. Unsupported formats such as SVG, and the features probe names as not decodable, fall through to Coil's platform decoders.

Static results honor the request's size, FIT/FILL scale, single defined side and maximum bitmap size (box-filter downscale, never up), and memory-cache normally. A still passes that size down to ImageKodec.decodeDownscaledTo: a JPEG, JPEG 2000 or JPEG XR reduces inside its inverse transform, and a HEIC or AVIF grid one row of tiles at a time, so a photo shown as an avatar never exists at full size. Animated results come back as KiteAnimationImage with every frame downscaled to the target size: that is where animated memory goes: and are marked shareable (memory-cacheable) when their pixel bytes fit under Factory.maxCacheableAnimationBytes. A cancelled request (fast scroll) stops a still at the decoder's next step, such as a row of JPEG blocks or a HEIC tile, and a multi-frame decode at the next frame boundary, instead of finishing the whole file, and a request with maxFrames decodes only that many frames.

The colours are converted to sRGB by default, through the ICC profile or the colour chunks the file carries, as Coil's platform decoders and browsers do. A file that declares nothing, or sRGB, is not touched. Pass ColorTarget.Source to Factory to keep the samples as stored.

Constructors

Link copied to clipboard
constructor(source: ImageSource, options: Options, maxCacheableAnimationBytes: Long = Factory.DEFAULT_MAX_CACHEABLE_ANIMATION_BYTES, colorTarget: ColorTarget = ColorTarget.Srgb())

Types

Link copied to clipboard
class Factory(maxCacheableAnimationBytes: Long = DEFAULT_MAX_CACHEABLE_ANIMATION_BYTES, colorTarget: ColorTarget = ColorTarget.Srgb()) : Decoder.Factory

maxCacheableAnimationBytes: animations whose decoded pixel bytes (frames × width × height × 4) fit under this threshold are marked shareable, so Coil's memory cache keeps them and revisits skip the re-decode entirely. Animations above it stay unshareable (decode again from the disk cache on revisit) so a single huge GIF cannot evict everything else. 0 restores the old always-skip behavior; Long.MAX_VALUE caches unconditionally.

Functions

Link copied to clipboard
open suspend override fun decode(): DecodeResult