PCX File Format Questions

Hello everybody, I’m trying to expand my texturing class to the PCX file format for my MD2 loader and I have some questions.

I read in the header for the pcx and it says that my image is 8 bits per pixel. How does that make any sense at all? Isn’t that just 256 colors? I open it up in photoshop and it looks a lot nicer than 256 colors. I’m confused about the differences between the versions and what roll the pallete plays in the image.

In terms of the encoding, when RLE is enabled this is what I understand you do:

Read in a byte, if the first two digits of it are 1’s, then the number the next 6 bits in the byte indicate the number of repeats of the next byte or bytes of information. If they arn’t both 0’s then that is the byte data.

So what do I do after I read in the header? I can’t find a decent specification for the pcx format, all of it is very unclear. Any help would be greatly appreciated. Thanks in advance.

pcx files can be 8-bit 256 color or 24-bit color.

The info in the header describes this.

Get the zsoft specs at www.wotsit.org

Thats my 3rd specification I’ve read, but I’m still lacking.

What if the runlength variable in the header isn’t a 1? Then is it just raw image data?

Also, how do I convert the data in the pcx to true color if its 256 colors? How is it different for 24 bit color?

I just wrote a function which retrieves the run length of a scan line (I guess thats the appropriate term?) but I’m lost as to where to go from there.

And what’s a scan line??

The encoding and decoding of all pcx files are the same. That means you can
use the same encoder/decoder on 8-bit and 24-bit pcx files.

The difference is the how to interpret the data once it is decoded. 24-bit
pcx files separate the r,g,b channels, on the assumption that it gives you
better compression, or so I guess. So you have to write something to put
these channels back together again.