I've written a PCX decoder (an ImageIO
plug-in in Java) and it works just fine, except for one detail:
I don't understand if and/or when I should use the two first colors of the palette in the header, or just use a fixed B/W palette for 1 bit data.
Is there an algorithm or heuristic that will work to determine if the palette should be used, or if a standard B/W should be used instead? Is there some setting in the header I'm missing? Or does one simply need to know this information in advance, before decoding?
The sample files I have, shows quite inconsistent behavior:
I have a sample file I can't share, where it does not matter: Version: 0, bpp: 1, planes: 1, palette info: 0 Using the header palette is fine, as it's the same as the default B/W.
Sample file, where the palette should probably not be used (but being version 2, perhaps is should?): Version: 2, bpp: 1, planes: 1, palette info: 0. Using the palette will make the background blue. Default B/W looks good.
- I also have a sample file I can't share where I understand the palette should not be used: Version: 3, bpp: 1, planes: 1, palette info: 0 Here the palette is all black (all 0s), which makes sense as version 3 means no palette.
- Sample file, where palette should be used (based on manual inspection of the colors): Version: 5, bpp: 1, planes: 1, palette info: 0. Using the header palette is fine. Default B/W looks inverted.
- Sample file, where the palette should not be used: Version: 5, bpp: 1, planes: 1, palette info: 0 (as the previous sample). Using the palette will make the train white on black background. Default B/W looks good.
- Sample file, where it doesn't matter: Version: 5, bpp: 1, planes: 1, palette info: 0. Using the header palette is fine, as it's the same as the default B/W.
- I also have a sample file written by Photoshop, that I can't share where the palette should not be used: Version: 5, bpp: 1, planes: 1, palette info: 0 Here the palette is just rubbish values (15,15,15, 14,14,14...0,0,0), making the image look all black. Default B/W looks good.
I've read pretty much all the documentation that I can find on the internet, including:
- This pretty informative Dr. Dobbs article
- PCX graphics explained
- ZSoft PCX File Format Technical Reference Manual
- PCX Format
...and a bunch of other, less useful pages, which don't seem to discuss the subject in question.