tinyimg 1.0.0
Lightweight image manipulation library for Cloudflare Workers
Loading...
Searching...
No Matches
gif.h File Reference

Graphics Interchange Format codec. More...

Go to the source code of this file.

Variables

const TinyCodec tiny_codec_gif
 The GIF codec.

Detailed Description

Graphics Interchange Format codec.

Author
Gregory Mitchell (me@gm.nosp@m.itch.nosp@m.215.x.nosp@m.yz)
Version
1.0.0
Date
2026-09-02

Variable Documentation

◆ tiny_codec_gif

const TinyCodec tiny_codec_gif
extern

The GIF codec.

Decodes the first frame of either version, with a global or a local color table, interlaced or not, and honors the graphic control extension's transparent index. probe reports how many frames the file holds, so an animation is identifiable without decoding it; composing or re-timing frames is out of scope.

The canvas is the logical screen the file declares rather than the frame, which for a frame smaller than the screen or placed at an offset is what a viewer shows. A file with a transparent index decodes to four channels and one without to three.

Encoding writes a single frame with one global color table. An image already inside 256 colors keeps them exactly, so a logo or a flat illustration round trips without loss; anything wider goes through an octree quantizer with Floyd-Steinberg error diffusion, which is applied when and only when colors had to be discarded. A source with alpha spends one palette entry on a transparent index, since the format has no partial transparency to spend it on.

Note
LZW is decoded into a whole index plane rather than streamed a row at a time. The plane is one byte per pixel, an eighth of what the RGBA plane the other row-streaming codecs avoid would cost, and the format's codes cross row boundaries freely, so streaming would need a pull interface for what is already the cheapest buffer in the library.