decodeScaled

fun decodeScaled(data: ByteArray, maxWidth: Int, maxHeight: Int, applyOrientation: Boolean = false, colorTarget: ColorTarget = ColorTarget.Source, cancellationCheck: () -> Unit? = null): KiteBitmap(source)

Decode data at the size decode(data, applyOrientation).scaled(maxWidth, maxHeight) gives: fitted inside maxWidth by maxHeight with the image's own aspect ratio, and never larger than the image. Use it for a thumbnail or a preview, where the full-size pixels would only be thrown away.

A JPEG, JPEG 2000 or JPEG XR decodes at the largest reduction decodeReduced offers whose output still covers that size, as libjpeg's scaled decode or Android's sample size is chosen, and the box filter of scaled finishes the rest. The full-size pixels never exist, and the result differs from the full decode only by the reduced inverse transform. A HEIC or AVIF image made of a grid of tiles reduces while it decodes: one row of tiles at a time is decoded, converted to RGB and fed to the box filter, so the full-size pixels never exist either, and the result equals the full decode then scaled, pixel for pixel. Its tiles still decode at full size, so this saves memory, not time. Other formats decode in full and filter once. colorTarget converts as for decode, and cancellationCheck runs as for decode, and at least once a tile of a grid.

Throws

on malformed/truncated input or unknown format

on formats recognised but not yet decodable