Uploaded image for project: 'Commons Imaging'
  1. Commons Imaging
  2. IMAGING-204

reading monochrome TIFF leads to unhandled exception

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Open
    • Major
    • Resolution: Unresolved
    • 1.0-alpha1
    • None
    • Format: TIFF
    • None

    Description

      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.

      Attachments

        Activity

          People

            Unassigned Unassigned
            thomas.elsner.66@gmail.com Thomas Elsner
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated: