1

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:

...and a bunch of other, less useful pages, which don't seem to discuss the subject in question.

Harald K
  • 26,314
  • 7
  • 65
  • 111
  • 1
    The bear is a v2 image... IIRC, v2 does not use a palette for 1-bit, only for higher colour types. The train is a v5 image, though. It should not use the palette info byte. The file is just wrong. PCX specs have been rather vague over the years, and were misinterpreted by lots of apps, though, so there are a lot of pcx files out there that are just incorrect. And don't get me started on CGA colour handling, ugh... – Nyerguds Aug 05 '19 at 08:59
  • 1
    I've been editing the modding wiki article recently to try to clear that mess up, btw, but 1bpp is always difficult to handle. There are just too many incorrectly-saved files. Luckily it's not hard to swap the colours if it turns out to be wrong. – Nyerguds Aug 05 '19 at 09:06

0 Answers0