KiteImage

object KiteImage

The KiteImage facade. Everything is pure computation on byte arrays: no I/O, no threads, no platform types: so it behaves identically on every KMP target.

val bitmap = KiteImage.decode(bytes)          // sniffs the format, dispatches
val anim = KiteImage.decodeAnimation(bytes) // frames + delays + loop count
val format = KiteImage.detect(bytes) // just the sniff
val info = KiteImage.probe(bytes) // size + depth + frames, no decode

Functions

Link copied to clipboard
fun decode(data: ByteArray, applyOrientation: Boolean = false): KiteBitmap

Decode data into a KiteBitmap, sniffing the format first. Animated inputs yield their first frame (composited); use decodeAnimation for the full sequence.

Link copied to clipboard
fun decodeAnimation(data: ByteArray, applyOrientation: Boolean = false, cancellationCheck: () -> Unit? = null): KiteAnimation

Decode data as an animation. GIF returns every composited frame with delays and the loop count; static formats return a single zero-delay frame, so this is safe to call on anything decode accepts.

Link copied to clipboard

Identify data's format from its magic bytes, or null if unrecognised.

Link copied to clipboard

Encode bitmap as a BMP: 24-bit BI_RGB when it is opaque, or 32-bit BI_BITFIELDS under a V4 header when it carries alpha (plain 32-bit BMP alpha is officially "reserved", and half the world's readers discard it). Uncompressed and lossless either way.

Link copied to clipboard
fun encodeGif(animation: KiteAnimation, dither: Boolean = true): ByteArray

Encode animation as an animated GIF89a: one shared colour table, per-frame delays, and the NETSCAPE2.0 loop count. Frames must all be canvas-sized, which is exactly what decodeAnimation produces.

fun encodeGif(bitmap: KiteBitmap, dither: Boolean = true): ByteArray

Encode bitmap as a GIF89a. Colours are quantised to the format's 256-entry limit; images that already fit encode losslessly. Alpha is reduced to GIF's single transparent index at a 50% threshold.

Link copied to clipboard
fun encodeJpeg(bitmap: KiteBitmap, quality: Int = 90): ByteArray

Encode bitmap as a baseline JPEG at quality 1..100 (default 90). Alpha is discarded (JPEG has none); quality ≤ 90 uses 4:2:0 chroma subsampling, above that 4:4:4; stb_image_write's behavior.

Link copied to clipboard

Encode bitmap as a PNG: 8-bit RGB, or RGBA when any pixel carries alpha. Lossless: decoding the result returns the exact same pixels.

Link copied to clipboard

Read data's header and report what it says: dimensions, bit depth, declared alpha, animation frame count, EXIF orientation, and whether this build can decode it. No pixels are decoded and no image-sized buffer is allocated, so this stays cheap on a 50 MP file.

Link copied to clipboard

probe, but null instead of throwing on unrecognised or malformed input.