Global Color Map

This component is not absolutely necessary, but is a good idea when accurate color representation is needed. A value of “1” in the “M” field in byte number 5 of the Screen Descriptor file component indicates the existence of a global color map. Each image in a GIF file can have its own color map, but normally it will use a global map. Inside each Image Descriptor component, the “M” field will normally be set to zero (0).

If a Global Color Map is in use, the component definition must follow the Screen Descriptor. The number of color map entries following the Screen Descriptor equals 2**(number of bits per pixel); each map entry is composed of three byte values that represent relative intensities of red, green, and blue. Pixel values are displayed according to the closest match to available display colors. Color components reflect fractional intensity values from none (0) to full (255). White is 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 eight 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 eight bits per component, the component values for the hardware should be converted to the 8-bit format with the following calculation:

            <map_value> = <component_value>*255/(2**<nbits> -1)

This algorithm provides accurate translation of colors for all displays. If the Global Color Map is missing, a default color map is generated internally which maps each incoming color index to a hardware color index.