kinow commented on a change in pull request #75:
URL: https://github.com/apache/commons-imaging/pull/75#discussion_r426459905



##########
File path: 
src/main/java/org/apache/commons/imaging/formats/tiff/photometricinterpreters/PhotometricInterpreterPalette.java
##########
@@ -45,11 +46,24 @@ public PhotometricInterpreterPalette(final int 
samplesPerPixel,
                     | blue;
         }
 
+        // Fix for IMAGING-247  5/17/2020
+        // This interpreter is used with TIFF_COMPRESSION_PACKBITS (32773).
+        // which unpacks to 8 bits per sample.  But if the bits-per-pixel
+        // is less than 8 bits, some authoring tools do not zero-out the
+        // unused bits.  This results in cases where the decoded by index
+        // exceeds the size of the palette.  So we set up a mask to protect
+        // the code from an array bounds exception.
+        int temp = 0;
+        for (int i = 0; i < bitsPerPixel; i++) {
+            temp = (temp << 1) | 1;
+        }

Review comment:
       I liked the for-loop here! Much simpler than something like `int temp = 
(bitsPerPixel < 32 ? (1 << bitsPerPixel) -1 : -1)` which I **think** would give 
something similar, but much harder to maintain/read. :clap: we definitely need 
more clarity in our code, and your comment above is very helpful too!




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to