

pcx ( PC Paintbrush ) format
----------------------------

HEADER (128 bytes)

0  $0A  always
1  ver  byte, Version nr:       0   2.5
                                2   2.8 with palette info or
                                    3.0 without or
                                    MS Paintbrush 1.0
                                3   2.8 or 3.0 without or
                                    MS Paintbrush 1.0
                                5   3.0 with palette info or
                                    MS Paintbrush 1.0
2  1    run length encoding mode
3  n    bits per pixel
4  X1   word, x position upper left corner, normally 0
6  Y1   word, y position upper left corner, normally 0
8  X2   word, x position lower right corner
A  Y2   word, y position lower right corner
C  HRES word, card horizontal resolution ?
E  VRES word, card vertical resolution ?
10 PAL  48 bytes, palette info
40 NPL  byte, number of planes
41 BPL  word, bytes per line in picture

Picture dimensions are given by:
        horizontal = X2 - X1 + 1
        vertical = Y2 - Y1 + 1

Palette has one of two formats:
      EGA: Data is stored as 16 triples. Each triple is a 3 byte
           quantity of Red, Green and Blue, ranging 0-255. As 
           there are only four levels of RGB on IBM EGA, only
           the two most significant bits need to be used.
      CGA: First triple, first byte: 4 msb's give background.
           Second triple, first byte: 3 msb's give foreground.

Data begins at position 128 ($80) in the file. The image is stored
line by line, so if we have an RGBI-image we get:

      scan line 0:    RRR
                        GGG
                        BBB
                        III
        scan line 1:    RRR
                        GGG
                        BBB
                        III

        etc...

Encoding:

        A count byte (byte with two most sign. bits set)
        means we should repeat next byte n times. n is given
        by the six least sign. bits in the count byte.

        tot is nr of bytes expected

        count=0;
        while( count<tot )
                ch = getnext()
                if( ( ch & 0xC0 ) == 0xC0 )
                        nr = ch & 0x3F
                        ch = getnext()
                else
                        nr = 1;
                put(ch,nr)
                count += nr
        end while

-- 
=======================================================
