The GIF File Format


Original Documentation

The Graphics Interchange Format (tm) was created by Compuserve Inc. as a
standard for the storage and transmission of raster-based graphics information,
i.e. images. A GIF file may contain several images, which are to be displayed
overlapping and without any delay betwenn the images. The image data itself is
compressed using a LZW scheme. Please note that the LZW algorithm is patented by
UniSys and that since Jan. 1995 royalties to Compuserve are due for every software
that implements GIF images.
The GIF file consists of a global GIF header, one or more image blocks and
optionally some GIF extensions.

OFFSET              Count TYPE   Description
0000h                   6 char   ID='GIF87a', ID='GIF89a'
								 This ID may be viewed as a version number
0006h                   1 word   Image width
0008h                   1 word   Image height
000Ah                   1 byte   bit mapped
								 0-2 - bits per pixel -1
								   3 - reserved
								 4-6 - bits of color resolution
								   7 - Global color map follows image descriptor
000Bh                   1 byte   Color index of screen background
000Ch                   1 byte   reserved

The global color map immediately follows the screen descriptor and has the size
(2**BitsPerPixel), and has the RGB colors for each color index. 0 is none, 255
is full intensity. The bytes are stored in the following format :
OFFSET              Count TYPE   Description
0000h                   1 byte   Red component
0001h                   1 byte   Green component
0002h                   1 byte   Blue component

After the first picture, there may be more pictures attached in the file
whic overlay the first picture or parts of the first picture. The Image
Descriptor defines the actual placement and extents of the following image
within the space defined in the Screen Descriptor. Each Image Descriptor is
introduced by an image separator character. The role of the Image Separator
is simply to provide a synchronization character to introduce an Image
Descriptor, the image separator is defined as ",", 02Ch, Any characters
encountered between the end of a previous image and the image separator
character are to be ignored.

The format of the Image descriptor looks like this :
OFFSET              Count TYPE   Description
0000h                   1 char   Image separator
								 ID=','
0001h                   1 word   Left offset of image
0003h                   1 word   Upper offset of image
0005h                   1 word   Width of image
0007h                   1 word   Height of image
0009h                   1 byte   Palette description - bitmapped
								 0-2 - Number of bits per pixel-1
								 3-5 - reserved (0)
								   6 - Interlaced / sequential image
								   7 - local / global color map, ignore bits 0-2

To provide for some possibility of an extension of the GIF files, a special
extension block introducer can be added after the GIF data block. The block has
the following structure :

OFFSET              Count TYPE   Description
0000h                   1 char   ID='!'
0001h                   1 byte   Extension ID
0002h                   ? rec
						1 word   Byte count
						? byte   Extra data
????h                   1 byte   Zero byte count - terminates extension block.

EXTENSION:GIF
OCCURENCES:PC
PROGRAMS:CSHOW.EXE
SEE ALSO:
VALIDATION:

This information is from Corion.net and is used with permission.

More Resources