Martin Mirchev created IMAGING-392:
--------------------------------------
Summary: Plain (P1) PBM images decode inverted: 0 is read as black
and 1 as white
Key: IMAGING-392
URL: https://issues.apache.org/jira/browse/IMAGING-392
Project: Commons Imaging
Issue Type: Bug
Reporter: Martin Mirchev
In PBM, a 1 bit is black and a 0 bit is white, in both the plain (P1) and the
raw (P4) format (netpbm's pbm(5)). {{PbmFileInfo.getRgb(InputStream)}}, used
for P4, follows this; {{PbmFileInfo.getRgb(WhiteSpaceReader)}}, used for P1,
has the two colors swapped, so every plain PBM file decodes as its negative.
{{PbmWriter}} writes 0 for bright pixels, as the format says, so writing a
plain PBM with Commons Imaging and reading it back also gives the negative.
Reproducer:
{code:java}
byte[] plain = "P1\n2 1\n0 1\n".getBytes(StandardCharsets.US_ASCII);
byte[] raw = { 'P', '4', '\n', '2', ' ', '1', '\n', 0x40 }; // the same two
pixels
Imaging.getBufferedImage(raw).getRGB(0, 0); // 0xffffffff (white), as expected
Imaging.getBufferedImage(plain).getRGB(0, 0); // 0xff000000 (black), expected
white
{code}
Suggested fix: swap the two colors in {{getRgb(WhiteSpaceReader)}}. A pull
request with the fix and a test follows; the full test suite passes with it.
This issue was found by an LLM-Enhanced Static Analysis Engine and verified
manually.
--
This message was sent by Atlassian Jira
(v10.3.26#10030026)