PCX is a graphics format developed by the company Zsoft and is one of the oldest, but one of the most common in recent times. It enables coding of 2-. 3-, 8-, and 24-bit images. For compression it uses RLE coding. The principle of coding is based on the application of equal characters, while the flag of repetition is detected through setting the two first bits to 1.

Example: A series of the following bytes: 32, 32, 32, 32, 32, 32, 32, 32 is coded in binary form as: 11001000 00100000 (where the two first bits 11 are flags, with the meaning that here is stored a byte in which is marked the number of repetition of the following byte). In total, for coding of 7 bytes we needed only 2. This method is, however, effective, only if the picture has a lot consecutive equal bytes

    Format description

    Originally, this format was optimized only for 16 colors. The header is also adapted to it, by which there is room for defining maximally 16 colors. If we want to use more colors, the pallet is stored at the end of the file. In the case of using the maximum 256 color pallet, this takes in the end 3*256 = 768 bytes, where every color is from the RGB model. In the case of 24 bit colors, every component of R, G, B is stored in a separate block.

Sample of the header of individual types of PCX files


Sample of the header of 256 color GIF

Sample of the header of 2 color PCX file

Sample of the header of 16 color PCX file
16 colors, 60x35 pixels, resulting size of the file = 1613 bytes

Sample of the header of 256 color PCX file
256 colors, 60x35 pixels, resulting size of the file = 2862 bytes

Sample of the header of 16.7 mill. color file
16 mill. colors, 60x35 pixels, resulting size of the file = 8601bytes

PCX file header

Offset Size Meaning
0 1 Constant = 10  
1 1 Information on version
    0 = Version2.5 
    2 = Version 2.8 w/pallet information
    3 = Version 2.8 w/o pallet information
    4 = PC Paintbrush for Windows
    5 = Version 3.0 and PC Paintbrush, including 24-bit PCX files
2 1 Coding type, if 1 then the PCX is compressed by RLE compression  
3 1 Number of bits per one pixel. Values can be 1, 2, 4, or 8.
4 12 Image dimensions: Xmin, Ymin, Xmax, and Ymax. 
12 2 Horizontal resolution in the image in DPI
14 2 Vertical resolution in the image in DPI
16 48 Color pallet for max 16 colors
64 1 Must be 0.
65 1 Number of color planes
66 2 Number of bytes per one line (BytesPerLine) identifies the number of bytes for allocation of the scanline plane. Must be an even number. Do not count it from Xmax ? Xmin!
68 2 Information how to pallet is interpreted (PaletteInfo).
                      1 = color or black & white
                      2 = gray shades (grayscale) 
70 2 Horizontal image size in pixels (HscreenSize). 
72 2 Vertical image size in pixels (VscreenSize). 
74 54 All bytes are   = 0.

PCX   with 256 colors.

    The pallet (number of colors x 3 bytes) is stored at the end of the PCX file. Because sometimes the VGA device has expected the value of pallet in the range 0-63 as opposed to the current range 0-255, it is necessary to divide the read value of the pallet by 4.

PCX with 24 bits per pixel .

    The 24-bit images are stored as 8-bit, 3 plane images. The 24-bit images do not contain a pallet. The bit planes are stored as lines of red, green, and blues levels.