commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From brit...@apache.org
Subject svn commit: r1650744 - in /commons/proper/imaging/trunk/src: changes/changes.xml main/java/org/apache/commons/imaging/formats/tiff/constants/TiffConstants.java main/java/org/apache/commons/imaging/formats/tiff/write/TiffImageWriterBase.java
Date Sat, 10 Jan 2015 14:08:29 GMT
Author: britter
Date: Sat Jan 10 14:08:29 2015
New Revision: 1650744

URL: http://svn.apache.org/r1650744
Log:
IMAGING-126: TIFF and PNG images should not be bigger than the ones created by java ImageIO.
Thanks to Gary Lucas.

Modified:
    commons/proper/imaging/trunk/src/changes/changes.xml
    commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/tiff/constants/TiffConstants.java
    commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/tiff/write/TiffImageWriterBase.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=1650744&r1=1650743&r2=1650744&view=diff
==============================================================================
--- commons/proper/imaging/trunk/src/changes/changes.xml (original)
+++ commons/proper/imaging/trunk/src/changes/changes.xml Sat Jan 10 14:08:29 2015
@@ -46,6 +46,9 @@ The <action> type attribute can be add,u
   <body>
 
     <release version="1.0" date="TBA" description="TBA">
+      <action issue="IMAGING-126" dev="britter" type="update" due-to="Gary Lucas">
+        TIFF and PNG images should not be bigger than the ones created by java ImageIO
+      </action>
       <action issue="IMAGING-147" dev="britter" type="update" due-to="Stephan Koeninger">
         Add color constants
       </action>

Modified: commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/tiff/constants/TiffConstants.java
URL: http://svn.apache.org/viewvc/commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/tiff/constants/TiffConstants.java?rev=1650744&r1=1650743&r2=1650744&view=diff
==============================================================================
--- commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/tiff/constants/TiffConstants.java
(original)
+++ commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/tiff/constants/TiffConstants.java
Sat Jan 10 14:08:29 2015
@@ -72,4 +72,28 @@ public interface TiffConstants
     String PARAM_KEY_SUBIMAGE_Y = "SUBIMAGE_Y";
     String PARAM_KEY_SUBIMAGE_WIDTH = "SUBIMAGE_WIDTH";
     String PARAM_KEY_SUBIMAGE_HEIGHT = "SUBIMAGE_HEIGHT";
+
+    /**
+     * Specifies the amount of memory in bytes to be used for a strip
+     * or tile size when employing LZW compression.  The default is
+     * 8000 (roughly 8K). Minimum value is 8000.
+     */
+    String PARAM_KEY_LZW_COMPRESSION_BLOCK_SIZE =
+            "PARAM_KEY_LZW_COMPRESSION_BLOCK_SIZE";
+
+    /**
+     * Specifies a larger strip-size to be used for compression. This setting
+     * generally produces smaller output files, but requires a slightly longer
+     * processing time. Used in conjunction with the
+     * PARAM_KEY_LZW_COMPRESSION_STRIP_SIZE
+     */
+    int TIFF_LZW_COMPRESSION_BLOCK_SIZE_MEDIUM = 32768;
+
+    /**
+     * Specifies a larger strip-size to be used for compression. This setting
+     * generally produces smaller output files, but requires a slightly longer
+     * processing time. Used in conjunction with the
+     * PARAM_KEY_LZW_COMPRESSION_STRIP_SIZE
+     */
+    int TIFF_LZW_COMPRESSION_BLOCK_SIZE_LARGE = 65536;
 }

Modified: commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/tiff/write/TiffImageWriterBase.java
URL: http://svn.apache.org/viewvc/commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/tiff/write/TiffImageWriterBase.java?rev=1650744&r1=1650743&r2=1650744&view=diff
==============================================================================
--- commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/tiff/write/TiffImageWriterBase.java
(original)
+++ commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/tiff/write/TiffImageWriterBase.java
Sat Jan 10 14:08:29 2015
@@ -272,16 +272,34 @@ public abstract class TiffImageWriterBas
         final int height = src.getHeight();
 
         int compression = TIFF_COMPRESSION_LZW; // LZW is default
+        int stripSizeInBits = 64000; // the default from legacy implementation
         if (params.containsKey(PARAM_KEY_COMPRESSION)) {
             final Object value = params.get(PARAM_KEY_COMPRESSION);
             if (value != null) {
                 if (!(value instanceof Number)) {
                     throw new ImageWriteException(
-                            "Invalid compression parameter: " + value);
+                            "Invalid compression parameter, must be numeric: "
+                                    + value);
                 }
                 compression = ((Number) value).intValue();
             }
             params.remove(PARAM_KEY_COMPRESSION);
+            if (params.containsKey(PARAM_KEY_LZW_COMPRESSION_BLOCK_SIZE)) {
+                final Object bValue =
+                    params.get(PARAM_KEY_LZW_COMPRESSION_BLOCK_SIZE);
+                if (!(bValue instanceof Number)) {
+                    throw new ImageWriteException(
+                            "Invalid compression block-size parameter: " + value);
+                }
+                final int stripSizeInBytes = ((Number) bValue).intValue();
+                if (stripSizeInBytes < 8000) {
+                    throw new ImageWriteException(
+                            "Block size parameter " + stripSizeInBytes
+                            + " is less than 8000 minimum");
+                }
+                stripSizeInBits = stripSizeInBytes*8;
+                params.remove(PARAM_KEY_LZW_COMPRESSION_BLOCK_SIZE);
+            }
         }
         final HashMap<String, Object> rawParams = new HashMap<String, Object>(params);
         params.remove(PARAM_KEY_T4_OPTIONS);
@@ -306,7 +324,7 @@ public abstract class TiffImageWriterBas
             photometricInterpretation = 2;
         }
 
-        int rowsPerStrip = 64000 / (width * bitsPerSample * samplesPerPixel); // TODO:
+        int rowsPerStrip = stripSizeInBits / (width * bitsPerSample * samplesPerPixel);
         rowsPerStrip = Math.max(1, rowsPerStrip); // must have at least one.
 
         final byte[][] strips = getStrips(src, samplesPerPixel, bitsPerSample, rowsPerStrip);



Mime
View raw message