Every PCX file starts with the same 128-byte header. Numbers of two bytes are little-endian, low byte first.
Layout
| Offset | Size | Type | Name | Description |
|---|---|---|---|---|
| 0 | 1 | u8 | manufacturer | Always 10 (0A), the ZSoft PCX marker. |
| 1 | 1 | u8 | version | The PC Paintbrush version the file is for. |
| 2 | 1 | u8 | encoding | 1 for PCX run-length encoding; 0, which is rare, for none. |
| 3 | 1 | u8 | bits per pixel | The bits a pixel has in each plane: 1, 2, 4 or 8. |
| 4 | 2 | u16 | Xmin | Left edge of the image. |
| 6 | 2 | u16 | Ymin | Top edge of the image. |
| 8 | 2 | u16 | Xmax | Right edge of the image. |
| 10 | 2 | u16 | Ymax | Bottom edge of the image. |
| 12 | 2 | u16 | HDpi | Horizontal resolution in DPI. |
| 14 | 2 | u16 | VDpi | Vertical resolution in DPI. |
| 16 | 48 | 16 × 3 bytes | colormap | A palette of 16 colours. |
| 64 | 1 | u8 | reserved | Should be 0. |
| 65 | 1 | u8 | planes | The number of colour planes. |
| 66 | 2 | u16 | bytes per line | The bytes of one plane of one row. Must be even. |
| 68 | 2 | u16 | palette info | 1 for colour or black and white, 2 for greyscale. PC Paintbrush IV ignores it. |
| 70 | 2 | u16 | H screen size | Screen width in pixels (PC Paintbrush IV only). |
| 72 | 2 | u16 | V screen size | Screen height in pixels (PC Paintbrush IV only). |
| 74 | 54 | bytes | filler | Zero, up to the end of the header. |
Version
| Value | Meaning |
|---|---|
| 0 | PC Paintbrush 2.5 |
| 2 | PC Paintbrush 2.8, with palette information |
| 3 | PC Paintbrush 2.8, without palette information |
| 4 | PC Paintbrush for Windows |
| 5 | PC Paintbrush 3.0 and later, including 24-bit files |
All the versions share this one header. The field that differs in practice is whether a palette is meaningful: version 3 says it has no palette information, and only version 5 can have the 256-colour palette at the end of the file.
The window
The picture is Xmax − Xmin + 1 pixels wide and
Ymax − Ymin + 1 pixels high. The minimum corner is usually 0, 0.
Bytes per line
One row of the image is planes × bytes per line bytes once decoded, and
the field counts one plane. ZSoft’s reference says the value must be even. It is the
true length of a plane’s data, so a row can have padding after the pixels the window
uses, and the reference warns not to work it out from the window instead.
Pixel formats
A row is one set of bytes for each plane in turn, so a pixel’s bits are spread across the planes.
| Bits per pixel | Planes | Image |
|---|---|---|
| 1 | 1 | Black and white |
| 1 | 3 | 8 colours |
| 1 | 4 | 16 colours |
| 2 | 1 | 4 colours (CGA) |
| 4 | 1 | 16 colours |
| 8 | 1 | 256 colours, or greys |
| 8 | 3 | 24-bit colour: red, green and blue planes |