Logical Screen Descriptor in GIF Files

The Logical Screen Descriptor is a mandatory 7-byte metadata block positioned immediately after the file header in both GIF87a and GIF89a specifications. It defines the overall display dimensions, color table characteristics, background color, and pixel proportions required to correctly render the image sequence.

Byte Breakdown of the Logical Screen Descriptor

The 7 bytes of the Logical Screen Descriptor contain the following structural information:

1. Logical Screen Width (Bytes 1–2)

A 16-bit unsigned integer stored in little-endian byte order. It specifies the total width of the canvas or display area in pixels required to render the GIF. Individual image frames within the file cannot exceed this boundary.

2. Logical Screen Height (Bytes 3–4)

A 16-bit unsigned integer stored in little-endian byte order. It specifies the total height of the canvas or display area in pixels required to display the image.

3. Packed Fields (Byte 5)

A single byte containing four distinct bitfields that dictate how colors are managed:

4. Background Color Index (Byte 6)

An 8-bit index pointing to a specific entry in the Global Color Table. The color at this index is used for portions of the screen not covered by an image frame or when transparent pixels are cleared. If no Global Color Table exists, this byte is ignored.

5. Pixel Aspect Ratio (Byte 7)

An 8-bit value that approximates the aspect ratio of the pixels in the original image. If the byte value is 0, no aspect ratio information is given, and square pixels (1:1) are assumed. If the value is non-zero, the actual aspect ratio is computed using the formula:

\[\text{Aspect Ratio} = \frac{\text{Value} + 15}{64}\]