Graphics Interchange Format

From ModdingWiki
(Redirected from Gif)
Jump to navigation Jump to search
Edge of map!
Graphics Interchange Format
There is no example of an image in this format — upload one!
Format typeImage
HardwareUnknown
Colour depth8-bit
Minimum size (pixels)0×0
Maximum size (pixels)65536×65536
PaletteInternal
Plane countUnknown
Transparent pixels?Yes
Hitmap pixels?No
Games

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.

Header

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.

Data type Description
char[3] "GIF"
char[3] Version mark (e.g. "87a")
UINT16LE How many pixels wide the entire viewport is
UINT16LE How many pixels tall the entire viewport is
BYTE
  • Bits 0-2: Color count indicator for Global Color Table. The formula to calculate the number of colors is 2^(indicator+1).
  • Bit 3: Boolean flag, is the global color table sorted by decreasing order of importance
  • Bits 4-6: Original color depth (bits per color) minus one. E.g. binary 101 (dec. 5) = 6 bits per color (VGA)
  • Bit 7: Boolean flag, does a global color table exist
UINT8 Palette index of transparent color; ignored if the global color table bit is unset.
UINT8 Pixel aspect ratio (0 = default)

Color tables

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:

Data type Description
UINT8 Red component
UINT8 Green component
UINT8 Blue component

Local color tables (used for a single frame in a multi-frame image) are also possible.

Image descriptor

Every image in a GIF file (even single frame GIFs) must have its own image descriptor.

Data type Description
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
BYTE
  • Bits 0-2: Indicate color count for local color table. 2^(indicator+1) = number of colors.
  • Bits 3-4: Reserved
  • Bit 5: Boolean flag, is the local color table sorted by color importance
  • Bit 6: Boolean flag, is the frame interlaced
  • Bit 7: Boolean flag, is there a local color table

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.

Source

Links