PCX

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.

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.