Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

PCX images

PCX files store palette-indexed raster images with scanline compression.

SKY_61.PCX is an 8-bit, single-plane image with a trailing 256-color palette.

Overall Structure

[PCX header — bounds, color depth, encoding, and scanline stride]
[Image data — raw or run-length encoded scanlines]
[Palette marker — 0C]
[Palette — 256 RGB triples]

Multibyte header integers are little-endian.

The header occupies 128 bytes.

OffsetSizeTypeNameDescription
0x001u8manufacturer0x0A
0x011u8versionFormat revision; 5 in SKY_61.PCX
0x021u8encoding0 for raw bytes, 1 for RLE
0x031u8bits_per_pixelBits per pixel per plane; 8
0x042u16x_minLeft bound
0x062u16y_minTop bound
0x082u16x_maxInclusive right bound
0x0A2u16y_maxInclusive bottom bound
0x0C2u16horizontal_dpiHorizontal resolution
0x0E2u16vertical_dpiVertical resolution
0x1048[u8; 48]header_paletteLegacy 16-color palette
0x401u8reservedReserved byte
0x411u8planesNumber of color planes; 1
0x422u16bytes_per_lineDecoded stride for each plane
0x442u16palette_infoPalette interpretation field
0x462u16horizontal_screen_sizeScreen width field
0x482u16vertical_screen_sizeScreen height field
0x4A54[u8; 54]reserved_tailReserved bytes

Width is x_max - x_min + 1; height is y_max - y_min + 1. Each decoded scanline contains bytes_per_line bytes. Bytes beyond the visible width are padding and do not produce pixels.

Run-length encoding

A byte below 0xC0 is a literal pixel index. A byte with both high bits set encodes a repeat count in its low six bits; the following byte is the repeated index. Counts range from 1 through 63. A literal index of 0xC0 or above uses a one-byte repeat. Runs end within the decoded scanline boundary.

Palette

The final 769 bytes contain marker 0x0C and 256 three-byte RGB entries. Components use their full eight-bit range. Pixel indices select these colors; index zero is opaque. The legacy header palette does not supply the colors for this layout. See also COL palettes.

External References