Gif 87
Gif 87
CompuServe, Incorporated.
an H&R Block Company
5000 Arlington Centre Blvd.
Columbus, Ohio 43220
(614) 457-8600
Page 2
Specification
INTRODUCTION
The first section of this document describes the GIF data format
and its components and applies to all GIF decoders, either as standalone
programs or as part of a communications package. Appendix B is a
section relavent to decoders that are part of a communications software
package and describes the protocol requirements for entering and exiting
GIF mode, and responding to host interrogations. A glossary in Appendix
A defines some of the terminology used in this document. Appendix C
gives a detailed explanation of how the graphics image itself is
packaged as a series of data bytes.
+-----------------------+
| +-------------------+ |
| | GIF Signature | |
| +-------------------+ |
| +-------------------+ |
| | Screen Descriptor | |
| +-------------------+ |
| +-------------------+ |
| | Global Color Map | |
| +-------------------+ |
. . . . . .
| +-------------------+ | ---+
| | Image Descriptor | | |
| +-------------------+ | |
| +-------------------+ | |
| | Local Color Map | | |- Repeated 1 to n times
| +-------------------+ | |
| +-------------------+ | |
| | Raster Data | | |
| +-------------------+ | ---+
. . . . . .
|- GIF Terminator -|
+-----------------------+
Specification
GIF SIGNATURE
G I F 8 7 a
SCREEN DESCRIPTOR
The Screen Descriptor describes the overall parameters for all GIF
images following. It defines the overall dimensions of the image space
or logical screen required, the existance of color mapping information,
background screen color, and color depth information. This information
is stored in a series of 8-bit bytes as described below.
bits
7 6 5 4 3 2 1 0 Byte #
+---------------+
| | 1
+-Screen Width -+ Raster width in pixels (LSB first)
| | 2
+---------------+
| | 3
+-Screen Height-+ Raster height in pixels (LSB first)
| | 4
+-+-----+-+-----+ M = 1, Global color map follows Descriptor
|M| cr |0|pixel| 5 cr+1 = # bits of color resolution
+-+-----+-+-----+ pixel+1 = # bits/pixel in image
| background | 6 background=Color index of screen background
+---------------+ (color is defined from the Global color
|0 0 0 0 0 0 0 0| 7 map or default map if none specified)
+---------------+
The logical screen width and height can both be larger than the
physical display. How images larger than the physical display are
handled is implementation dependent and can take advantage of hardware
characteristics (e.g. Macintosh scrolling windows). Otherwise images
can be clipped to the edges of the display.
Specification
The Global Color Map is optional but recommended for images where
accurate color rendition is desired. The existence of this color map is
indicated in the 'M' field of byte 5 of the Screen Descriptor. A color
map can also be associated with each image in a GIF file as described
later. However this global map will normally be used because of
hardware restrictions in equipment available today. In the individual
Image Descriptors the 'M' flag will normally be zero. If the Global
Color Map is present, it's definition immediately follows the Screen
Descriptor. The number of color map entries following a Screen
Descriptor is equal to 2**(# bits per pixel), where each entry consists
of three byte values representing the relative intensities of red, green
and blue respectively. The structure of the Color Map block is:
bits
7 6 5 4 3 2 1 0 Byte #
+---------------+
| red intensity | 1 Red value for color index 0
+---------------+
|green intensity| 2 Green value for color index 0
+---------------+
| blue intensity| 3 Blue value for color index 0
+---------------+
| red intensity | 4 Red value for color index 1
+---------------+
|green intensity| 5 Green value for color index 1
+---------------+
| blue intensity| 6 Blue value for color index 1
+---------------+
: : (Continues for remaining colors)
Specification
IMAGE DESCRIPTOR
bits
7 6 5 4 3 2 1 0 Byte #
+---------------+
|0 0 1 0 1 1 0 0| 1 ',' - Image separator character
+---------------+
| | 2 Start of image in pixels from the
+- Image Left -+ left side of the screen (LSB first)
| | 3
+---------------+
| | 4
+- Image Top -+ Start of image in pixels from the
| | 5 top of the screen (LSB first)
+---------------+
| | 6
+- Image Width -+ Width of the image in pixels (LSB first)
| | 7
+---------------+
| | 8
+- Image Height-+ Height of the image in pixels (LSB first)
| | 9
+-+-+-+-+-+-----+ M=0 - Use global color map, ignore 'pixel'
|M|I|0|0|0|pixel| 10 M=1 - Local color map follows, use 'pixel'
+-+-+-+-+-+-----+ I=0 - Image formatted in Sequential order
I=1 - Image formatted in Interlaced order
pixel+1 - # bits per pixel for this image
The specifications for the image position and size must be confined
to the dimensions defined by the Screen Descriptor. On the other hand
it is not necessary that the image fill the entire screen defined.
Specification
A Local Color Map is optional and defined here for future use. If
the 'M' bit of byte 10 of the Image Descriptor is set, then a color map
follows the Image Descriptor that applies only to the following image.
At the end of the image, the color map will revert to that defined after
the Screen Descriptor. Note that the 'pixel' field of byte 10 of the
Image Descriptor is used only if a Local Color Map is indicated. This
defines the parameters not only for the image pixel size, but determines
the number of color map entries that follow. The bits per pixel value
will also revert to the value specified in the Screen Descriptor when
processing of the image is complete.
RASTER DATA
Image
Specification
GIF TERMINATOR
7 6 5 4 3 2 1 0 Byte #
+---------------+
|0 0 1 0 0 0 0 1| 1 '!' - GIF Extension Block Introducer
+---------------+
| function code | 2 Extension function code (0 to 255)
+---------------+ ---+
| byte count | |
+---------------+ |
: : +-- Repeated as many times as necessary
|func data bytes| |
: : |
+---------------+ ---+
. . . . . .
+---------------+
|0 0 0 0 0 0 0 0| zero byte count (terminates block)
+---------------+
Appendix A - Glossary
GLOSSARY
LSB - Least Significant Byte. Refers to a convention for two byte numeric
values in which the less significant byte of the value preceeds the more
significant byte. This convention is typical on many microcomputers.
Color Map - The list of definitions of each color used in a GIF image.
These desired colors are converted to available colors through a table
which is derived by assigning an incoming color index (from the image)
to an output color index (of the hardware). While the color map
definitons are specified in a GIF image, the output pixel colors will
vary based on the hardware used and its ability to match the defined
color.
This basic algorithm is also used in the public domain ARC file
compression utilities. The CompuServe adaptation of LZW for GIF is
described in Appendix C.
Note that all values in the GCR are returned as ASCII decimal
numbers and the message is terminated by a Carriage Return character.
INTERACTIVE ENVIRONMENT
The assumed environment for the transmission of GIF image data from
an interactive application is a full 8-bit data stream from host to
micro. All 256 character codes must be transferrable. The establishing
of an 8-bit data path for communications will normally be taken care of
by the host application programs. It is however up to the receiving
communications programs supporting GIF to be able to receive and pass on
all 256 8-bit codes to the GIF decoder software.
The Raster Data stream that represents the actual output image can
be represented as:
7 6 5 4 3 2 1 0
+---------------+
| code size |
+---------------+ ---+
|blok byte count| |
+---------------+ |
: : +-- Repeated as many times as necessary
| data bytes | |
: : |
+---------------+ ---+
. . . . . .
+---------------+
|0 0 0 0 0 0 0 0| zero byte count (terminates data stream)
+---------------+
The first byte of the GIF Raster Data stream is a value indicating
the minimum number of bits required to represent the set of actual pixel
values. Normally this will be the same as the number of color bits.
Because of some algorithmic constraints however, black & white images
which have one color bit must be indicated as having a code size of 2.
This code size value also implies that the compression codes must start
out one bit longer.
COMPRESSION
Once the bytes have been created, they are grouped into blocks for
output by preceeding each block of 0 to 255 bytes with a character count
byte. A block with a zero byte count terminates the Raster Data stream
for a given image. These blocks are what are actually output for the
Graphics Interchange Format (GIF) Page 14
GIF image. This block format has the side effect of allowing a decoding
program the ability to read past the actual image data if necessary by
reading block counts and then skipping over the data.