decodeReduced

fun decodeReduced(data: ByteArray, reduction: Int, colorTarget: ColorTarget = ColorTarget.Source, cancellationCheck: () -> Unit? = null): KiteBitmap(source)

Decode data with each side divided by reduction, rounded up: 1, 2, 4 or 8. Use it for an image that will draw smaller than its pixels, such as a scan on a phone screen or a thumbnail. Like decode by default, it does not apply EXIF orientation.

A JPEG reduces inside its inverse DCT, as libjpeg's scaled decode does, so the full-size pixels never exist: a baseline 35-megapixel scan decoded at an eighth needs memory for about half a megapixel. A progressive JPEG still keeps the coefficients of the full size, 2 bytes a sample, until its last scan. A BMP that holds a JPEG as its pixel array reduces as that JPEG does. A JPEG 2000 image drops its finest wavelet levels, as OpenJPEG's reduce option does. A JPEG XR image decodes jxrlib's thumbnail, as JxrDecApp -T does: every second sample of the full transform at 2, and every fourth or eighth, the DCs of the second transform stage alone, at 4 and 8, for which a file in frequency order skips its highpass. Where jxrlib would round a side otherwise, the image decodes in full and averages as below. Other formats decode in full, then average each block of reduction by reduction pixels, weighted by alpha as scaled does. colorTarget converts as for decode, after the reduction, and cancellationCheck runs as for decode.

Throws

if reduction is not 1, 2, 4 or 8

on malformed/truncated input or unknown format

on formats recognised but not yet decodable