3.4 GIF. Graphics Interchange Format
Cf.
This format is organized by a block structure.
- Header-block:
- 'GIF' ... 3 byte identifier
- version ... 3 bytes (e.g. '87a', '89a')
- Logical Screen Descriptor:
- Logical Screen Width ... 2 bytes
- Logical Screen Height ... 2 bytes
- Flags ... 1 byte consisting of
- Global Color Table Flag ... 1 bit
- Color Resolution ... 3 bits
- Color Table Sort Flag .. 1 bit
- Size of Color Table ... 3 bits
- Background Color Index ... 1 byte
- Pixel Aspect Ratio ... 1 byte
- Global Color Table (if Global Color Table Flag is 1):
Colors are coded by a selectable color-table of 256 entries.
(Size of Color Table) bytes of R/G/B information.
- Image Descriptor:
- 0x2C ... 1 byte Image Separator
- Image Left Pos ... 2 bytes
- Image Top Pos .... 2 bytes
- Image Width ...... 2 bytes
- Image Height ..... 2 bytes
- Flags ............ 1 byte consisting of
Local Color Table Flag, Interlace Flag, Sort Flag, Reserved, Size Local Color Table
- Table Based Image Data (packed with LZW):
- LZW minimum code ... 1 byte
- Subblocks of at most 255 bytes each, these are LZW compressed
with
variable length output codes starting at codesize+1 (minimum 3 bits)
and ending at 12 bits (Maximal code is thus 4095=0xFFF)
Uses LZ78 (patented by Unisys), see below.
Bits are packed from right to left.
Then output is cut into subblocks of length .
- Terminated by a zero length subblock
- Graphic Control Extension (Identifier: 0x21 0xF9)
- Comment Extension (Identifier: 0x21 0xFE)
- Plain Text Extension (Identifier: 0x21 0x01)
- Application Extension (Identifier: 0x21 0xFF)
- Trailer:
0x3B ... 1 byte
This format is best used for small images (e.g. icons),
images with sharp edges, and images with few colors.
For details on LZ78 used by GIF see
www.dcs.ed.ac.uk/.../GIF-comp.txt
Andreas Kriegl 2003-07-23