PCX Format                                  

Note:     This section is adapted from "Technical Documentation
          for PC Paintbrush & Frieze Graphics," © 1985 ZSoft
          Corporation.  To obtain this document, contact ZSoft
          Corporation at (404) 428-0008.

A PCX format file stores one page image in the form of a rectangular bitmap.
PCX files have a 128-byte header followed by compressed image data. The PCX
file format allows for multiple colors each with multiple shades, but Fax Mode
transfers require black and white, no shades.  The PCX file format also allows
for different resolutions, but a PCX file for Fax Mode transfer is interpreted
as having 200 pels per inch both horizontally and vertically, no matter what
the file header says.  The PCX file format can handle very large page sizes,
but for Fax Transfer mode, the bitmap width must not exceed 1728 pels (about
8.5 inches wide).  Lengths are unlimited, since fax paper comes in rolls, but
2200 pels is 11 inches, and that is the recommended maximum length for easy
handling by the receiver.  Pel locations can be given in X,Y coordinates where
the origin is at the top left corner of the page, X increases toward the
right, and Y increases toward the bottom.

                                Data Encoding                                 

The compression technique used is a simple run length encoding, where
duplicate bytes (not bits) are compressed.  To compress a bitmap, it is
read one horizontal line at a time from top to bottom.  (No line wrapping
is performed.)  Each line is read from left to right.  The line is read
eight pels at a time (one byte).  Within a byte, the most significant bit
corresponds to the leftmost pel.  Runs of up to 63 bytes that are all the
same are stored as a run pair: a count byte followed by the byte that
repeats. The count byte of a run pair has the two most significant bits
set, and the 6 other bits contain the count.  If a byte of data does not
repeat, it is stored just as is, unless it happens to have its two most
significant bits set, in which case it is stored as run pair with a repeat
count of one.

This is the algorithm for decompressing the byte stream from a PCX file:

    FOR each byte, X, read from the file
    IF the top two bits of X are 1's
      BEGIN
        runlength = 6 lowest bits of X
        data      = net byte following X
      END
    ELSE
      BEGIN
        runlength = 1
        data = X
      END

                                 File Header                                  

Here is the structure at the start of a PCX file for fax images:

     Ofs  Len  Description

     0    1    PCX ID, Must be 0Ah.

     1    1    Version info.  A value of 2 is suggested. Anything higher is
                 allowed.

     2    1    Encoding method.  Must be 1.

     3    1    Bits per pixel.  Must be 1 for Fax Mode transfer.

     4    2    X position of the upper left corner, usually 0.

     6    2    Y position of the upper left corner, usually 0.

     8    2    X position of the bottom right corner, maximum 1727.  The
                 difference between this field and the upper left corner X
                 position plus 1 is the width of the bitmap.  This width
                 must be a multiple of 8.

     10   2    Y position of the bottom right corner, 2200 recommended
                 maximum.

     12   2    Display card horizontal resolution.  Ignored in Fax Transfer
                 mode.  A value of 640 is recommended for compatibility
                 with Intel's Graphics Editor.

     14   2    Display card vertical resolution.  Ignored in Fax Transfer
                 mode.  A value of 200 is recommended for compatibility
                 with Intel's Graphics Editor.

     16   48   Palette information.  Ignored in Fax Transfer mode.  Should
                 be 0's.

     64   1    Reserved.  Must be 0.

     65   1    Number of color planes.  Must be 1 for Fax Transfer Mode.

     66   2    Horizontal line width in bytes, equal to (XRight - XLeft +
                 1)/8.

     68   60   Reserved.  Should be 0.

The data for the first line starts immediately after the header.

See Also DCX Format Error Codes


Copyright © 1985 to 2022 Beta Systems                            Last modified: Wednesday, January 05, 2022 .