Graphics Interchange Format
The Graphics Interchange Format (GIF) stores images with palettes of up to 256 colors and enjoyed widespread use. It supports transparency, the possibility of multiple frames in a file, animation, and LZW Compression.
The header specifies some information that applies to the image as a whole, including a maximum width and height that all frames within the file must fit inside.
|char||Version mark (e.g. "87a")|
|UINT16LE||How many pixels wide the entire viewport is|
|UINT16LE||How many pixels tall the entire viewport is|
|UINT8||Palette index of transparent color; ignored if the global color table bit is unset.|
|UINT8||Pixel aspect ratio (0 = default)|
If the relevant bit is set in the header, then a global color table (palette) will appear immediately after the GIF header, containing the number of colors also indicated in the header.
Every color consists of three bytes, which may use their full 0-255 range of values:
Local color tables (used for a single frame in a multi-frame image) are also possible.
Every image in a GIF file (even single frame GIFs) must have its own image descriptor.
|BYTE||Image separator, always 0x2C|
|UINT16LE||Pixel position of frame's left edge relative to total viewport (0 = leftmost column)|
|UINT16LE||Pixel position of frame's top edge relative to total viewport (0 = topmost row)|
|UINT16LE||Width of frame in pixels|
|UINT16LE||Height of frame in pixels|
If a local color table is present, it appears immediately after the image descriptor. Next comes the compressed image data for the frame.
End of file
A GIF file must end with a byte whose value is 0x3B.