commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Thomas Elsner (JIRA)" <j...@apache.org>
Subject [jira] [Created] (IMAGING-204) reading monochrome TIFF leads to unhandled exception
Date Thu, 24 Aug 2017 18:09:01 GMT
Thomas Elsner created IMAGING-204:
-------------------------------------

             Summary: reading monochrome TIFF leads to unhandled exception
                 Key: IMAGING-204
                 URL: https://issues.apache.org/jira/browse/IMAGING-204
             Project: Commons Imaging
          Issue Type: Bug
          Components: Format: TIFF
    Affects Versions: 1.0
            Reporter: Thomas Elsner


reading monochrome TIFF doesn't work.
wrong function getSamplesAsBytes(bis, samples);
Here with having 1 Bit per Pixel it returns value samples[0] = 255 instead of 1.

Then  photometricInterpreter.interpretPixel(imageBuilder, samples, x, y); has a problem
 public void interpretPixel(final ImageBuilder imageBuilder, final int[] samples, final int
x,
            final int y) throws ImageReadException, IOException {
        imageBuilder.setRGB(x, y, indexColorMap[samples[0]]);
    }
 as the indexColorMaps only has two entries (black and white), but not 256 entries

The same problem will occur as the colour does not have 8 Bit.

The fix seems simple:
In routine 
    void getSamplesAsBytes(final BitInputStream bis, final int[] result) throws IOException
{
        for (int i = 0; i < bitsPerSample.length; i++) {
            final int bits = bitsPerSample[i];
            int sample = bis.readBits(bits);
            if (bits < 8) {
                final int sign = sample & 1;
                sample = sample << (8 - bits); // scale to byte.
                if (sign > 0) {
                    sample = sample | ((1 << (8 - bits)) - 1); // extend to byte
                }
            }...

if 'sign>0' don't fill up to 8 bits, but to 'bits' amount of '1'.
I am not sure about other side effects, so I post this suggestion.




--
This message was sent by Atlassian JIRA
(v6.4.14#64029)

Mime
View raw message