encodeGif

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

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.

dither applies Floyd-Steinberg error diffusion when quantisation actually loses colours, which is what keeps a photograph from banding. It is ignored when the palette came out exact, since there is no error to spread.

Throws

if a side of bitmap is larger than 65535, which a GIF cannot store


fun encodeGif(animation: KiteAnimation, dither: Boolean = true): ByteArray(source)

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.

Throws

if the canvas is larger than 65535 on a side, which a GIF cannot store, if the frames are not all canvas-sized, or if the total play count is outside GIF's 0..65536 range (0 means forever)


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

encodeGif that also writes metadata (#186), in application extensions before the first frame: the ICC profile in an ICCRGBG1 012 extension (ICC.1:2022, B.6), and the XMP packet in an XMP DataXMP extension with the trailer XMP Part 3 gives it. A GIF has no place for EXIF, so it is left out. The pixels are those the overload without metadata writes, and readMetadata reads both blocks back.

Throws

as the overload without metadata does


fun encodeGif(animation: KiteAnimation, metadata: ImageMetadata, dither: Boolean = true): ByteArray(source)

encodeGif of animation that also writes metadata, as the still overload with metadata does.

Throws

as the overload without metadata does