Contributor: HERBERT ZARB 
Herbert Zarb 
 This Text File explains the format of Gif Files.
---------------------------------------------------------------------------
 G I F (tm)
 Graphics Interchange Format (tm)
 A standard defining a mechanism
 For the storage and transmission
 of raster-based Graphics information
 June 15, 1987
 (c) CompuServe Incorporated, 1987
 All rights reserved
 While this document is copyrighted, the information
 contained Within is made available For use in computer
 software Without royalties, or licensing restrictions.
 Gif and 'Graphics Interchange Format' are trademarks of
 CompuServe, Incorporated.
 an H&R Block Company
 5000 Arlington Centre Blvd.
 Columbus, Ohio 43220
 (614) 457-8600
 Page 2
 Graphics Interchange Format (GIF) Specification
 Table of Contents
 INTRODUCTION . . . . . . . . . . . . . . . . . page 3
 GENERAL File FORMAT . . . . . . . . . . . . . page 3
 Gif SIGNATURE . . . . . . . . . . . . . . . . page 4
 SCREEN DESCRIPTOR . . . . . . . . . . . . . . page 4
 GLOBAL COLOR MAP . . . . . . . . . . . . . . . page 5
 IMAGE DESCRIPTOR . . . . . . . . . . . . . . . page 6
 LOCAL COLOR MAP . . . . . . . . . . . . . . . page 7
 RASTER DATA . . . . . . . . . . . . . . . . . page 7
 Gif TERMINATOR . . . . . . . . . . . . . . . . page 8
 Gif EXTENSION BLOCKS . . . . . . . . . . . . . page 8
 APPendIX A - GLOSSARY . . . . . . . . . . . . page 9
 APPendIX B - INTERACTIVE SEQUENCES . . . . . . page 10
 APPendIX C - IMAGE PACKAGING & COMPRESSION . . page 12
 APPendIX D - MULTIPLE IMAGE PROCESSING . . . . page 15
INTRODUCTION
 'GIF' (tm) is CompuServe's standard For defining generalized color
 raster images. This 'Graphics Interchange Format' (tm) allows
 high-quality, high-resolution Graphics to be displayed on a Variety of
 Graphics hardware and is intended as an exchange and display mechanism
 For Graphics images. The image format described in this document is
 designed to support current and future image technology and will in
 addition serve as a basis For future CompuServe Graphics products.
 The main focus of this document is to provide the technical
 information necessary For a Programmer to implement Gif encoders and
 decoders. As such, some assumptions are made as to terminology relavent
 to Graphics and Programming in general.
 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.
 Graphics Interchange Format Data Definition
 GENERAL File FORMAT
 +-----------------------+
 | +-------------------+ |
 | | Gif Signature | |
 | +-------------------+ |
 | +-------------------+ |
 | | Screen Descriptor | |
 | +-------------------+ |
 | +-------------------+ |
 | | Global Color Map | |
 | +-------------------+ |
 . . . . . .
 | +-------------------+ | ---+
 | | Image Descriptor | | |
 | +-------------------+ | |
 | +-------------------+ | |
 | | Local Color Map | | |- Repeated 1 to n times
 | +-------------------+ | |
 | +-------------------+ | |
 | | Raster Data | | |
 | +-------------------+ | ---+
 . . . . . .
 |- Gif Terminator -|
 +-----------------------+
 Gif SIGNATURE
 The following Gif Signature identifies the data following as a
 valid Gif image stream. It consists of the following six Characters:
 G I F 8 7 a
 The last three Characters '87a' may be viewed as a version number
 For this particular Gif definition and will be used in general as a
 reference in documents regarding Gif that address any version
 dependencies.
 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.
 The value of 'pixel' also defines the maximum number of colors
 Within an image. The range of values For 'pixel' is 0 to 7 which
 represents 1 to 8 bits. This translates to a range of 2 (B & W) to 256
 colors. Bit 3 of Word 5 is reserved For future definition and must be
 zero.
 GLOBAL COLOR MAP
 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)
 Each image pixel value received will be displayed according to its
 closest match With an available color of the display based on this color
 map. The color components represent a fractional intensity value from
 none (0) to full (255). White would be represented as (255,255,255),
 black as (0,0,0) and medium yellow as (180,180,0). For display, if the
 device supports fewer than 8 bits per color component, the higher order
 bits of each component are used. In the creation of a Gif color map
 entry With hardware supporting fewer than 8 bits per component, the
 component values For the hardware should be converted to the 8-bit
 format With the following calculation: