You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by br...@apache.org on 2016/06/20 17:00:17 UTC

svn commit: r1749362 - in /commons/proper/imaging/trunk/src: changes/changes.xml main/java/org/apache/commons/imaging/formats/tiff/TiffImageParser.java test/data/images/tiff/8/ test/data/images/tiff/8/no-compression-tag.tiff

Author: britter
Date: Mon Jun 20 17:00:17 2016
New Revision: 1749362

URL: http://svn.apache.org/viewvc?rev=1749362&view=rev
Log:
IMAGING-176: TiffImageParser.getImageInfo() throws exception when "Compression"
field is missing. Thank you to Gabriel Axel. This also fixes #19 from GitHub.


Added:
    commons/proper/imaging/trunk/src/test/data/images/tiff/8/
    commons/proper/imaging/trunk/src/test/data/images/tiff/8/no-compression-tag.tiff
Modified:
    commons/proper/imaging/trunk/src/changes/changes.xml
    commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/tiff/TiffImageParser.java

Modified: commons/proper/imaging/trunk/src/changes/changes.xml
URL: http://svn.apache.org/viewvc/commons/proper/imaging/trunk/src/changes/changes.xml?rev=1749362&r1=1749361&r2=1749362&view=diff
==============================================================================
--- commons/proper/imaging/trunk/src/changes/changes.xml (original)
+++ commons/proper/imaging/trunk/src/changes/changes.xml Mon Jun 20 17:00:17 2016
@@ -46,6 +46,9 @@ The <action> type attribute can be add,u
   <body>
 
     <release version="1.0" date="TBA" description="First major release">
+      <action issue="IMAGING-176" dev="britter" type="fix" due-to="Gabriel Axel">
+        TiffImageParser.getImageInfo() throws exception when "Compression" field is missing.
+      </action>
       <action issue="IMAGING-178" dev="britter" type="fix" due-to="emopers">
         PnmImageParser does not check the validity of input PAM header.
       </action>

Modified: commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/tiff/TiffImageParser.java
URL: http://svn.apache.org/viewvc/commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/tiff/TiffImageParser.java?rev=1749362&r1=1749361&r2=1749362&view=diff
==============================================================================
--- commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/tiff/TiffImageParser.java (original)
+++ commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/tiff/TiffImageParser.java Mon Jun 20 17:00:17 2016
@@ -259,8 +259,11 @@ public class TiffImageParser extends Ima
 
         final ImageInfo.ColorType colorType = ImageInfo.ColorType.RGB;
 
-        final int compression = 0xffff & directory
-                .getSingleFieldValue(TiffTagConstants.TIFF_TAG_COMPRESSION);
+        final short[] compressionFieldValues = directory
+            .getFieldValue(TiffTagConstants.TIFF_TAG_COMPRESSION, false);
+        final short compressionFieldValue = compressionFieldValues != null ?
+            compressionFieldValues[0] : TIFF_COMPRESSION_UNCOMPRESSED_1;
+        final int compression = 0xffff & compressionFieldValue;
         ImageInfo.CompressionAlgorithm compressionAlgorithm;
 
         switch (compression) {
@@ -552,7 +555,11 @@ public class TiffImageParser extends Ima
 
         final int photometricInterpretation = 0xffff & directory.getSingleFieldValue(
                 TiffTagConstants.TIFF_TAG_PHOTOMETRIC_INTERPRETATION);
-        final int compression = 0xffff & directory.getSingleFieldValue(TiffTagConstants.TIFF_TAG_COMPRESSION);
+        final short[] compressionFieldValues = directory
+            .getFieldValue(TiffTagConstants.TIFF_TAG_COMPRESSION, false);
+        final short compressionFieldValue = compressionFieldValues != null ?
+                compressionFieldValues[0] : TIFF_COMPRESSION_UNCOMPRESSED_1;
+        final int compression = 0xffff & compressionFieldValue;
         final int width = directory.getSingleFieldValue(TiffTagConstants.TIFF_TAG_IMAGE_WIDTH);
         final int height = directory.getSingleFieldValue(TiffTagConstants.TIFF_TAG_IMAGE_LENGTH);      
         

Added: commons/proper/imaging/trunk/src/test/data/images/tiff/8/no-compression-tag.tiff
URL: http://svn.apache.org/viewvc/commons/proper/imaging/trunk/src/test/data/images/tiff/8/no-compression-tag.tiff?rev=1749362&view=auto
==============================================================================
Binary files commons/proper/imaging/trunk/src/test/data/images/tiff/8/no-compression-tag.tiff (added) and commons/proper/imaging/trunk/src/test/data/images/tiff/8/no-compression-tag.tiff Mon Jun 20 17:00:17 2016 differ