PCX File Format - OpenSMSG/OpenSMSG GitHub Wiki

A lot of the following information was adapted from the DOS Game Modding Wiki article on the PCX Graphics Format. The content on this page is a combination of info from that site and research I have done using the SMSG game files.

About

The PCX Format is an image format which is usually used to store 16-color EGA, and later 256-color VGA , graphics. It was, at one time, a general picture format similar to .bmp, .jpeg or .png, and was the primary format used by PC Paintbrush. It declined in popularity after a late addition of 24-bit true color and the fact that it lacked support for transparency.

File Structure

There are two main parts to a PCX file, the 128 byte header and the image data (which is usually compressed).

Header

Offset Size (Bytes) Content About
0x0 2 Manufacturer Always 0x0A
0x1 2 Version PC Paintbrush version. Acts as file format version.0 = v2.52 = v2.8 with palette3 = v2.8 without palette4 = Paintbrush for Windows5 = v3.0 or higher
0x2 2 Encoding Should be 0x010 = uncompressed image (not officially allowed, but some software supports it)1 = PCX run length encoding
0x3 2 Bits Per Plane Number of bits per pixel in each entry of the color planes (1, 2, 4, 8, 24)
0x4 4 Window X Min Image X minimum (Normally set to 0)
0x6 4 Window Y Min Image Y minimum (Normally set to 0)
0x8 4 Window X Max Image X maximum (Normally the width of the image - 1)
0xa 4 Window Y Max Image Y maximum (Normally the height of the image - 1)
0xc 4 Vertical DPI Vertical resolution of image in DPI (Often contains the image dimensions, or nothing at all)
0xe 4 Horizontal DPI Horizontal resolution of image in DPI (Often contains the image dimensions, or nothing at all)
0x10 2 Palette Palette for 16 colors or less, in three-byte RGB entries. End is padded with 0x00 to achieve 48 bytes in total length
0x? 2 ? Reserved space which should be set to 0
0x? 2 Color Planes Number of color planes. Multiply by Bits Per Plane to get actual color depth
0x? 4 Bytes Per Plane Line Number of bytes to read for a single plane's scanline, i.e. at least ImageWidth รท 8 bits per byte ร— BitsPerPlane (Must be an even number)
0x? 4 Palette Info How to interpret palette:1 = Color/BW2 = Grayscale (ignored in PC Paintbrush IV and later)
0x? 4 Horizontal Scroll Size Unused (Only supported by PC Paintbrush IV or higher; deals with scrolling)
0x? 4 Vertical Scroll Size Unused (Only supported by PC Paintbrush IV or higher; deals with scrolling)
0x? ? ? Filler at the end of the header to bring to to 128 bytes in size

Image Data

Image data starts after the header (starting at offset 0x80 in a PCX file), and depending on what is indicated in the header it may be RLE compressed. The way the data is stored depends on how many color planes are specified. Each row has its color planes stored sequentially, similar to raw EGA data.