commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dam...@apache.org
Subject svn commit: r1221631 - in /commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan: SanselanConstants.java formats/bmp/BmpImageParser.java formats/tiff/write/TiffImageWriterBase.java
Date Wed, 21 Dec 2011 07:03:18 GMT
Author: damjan
Date: Wed Dec 21 07:03:18 2011
New Revision: 1221631

URL: http://svn.apache.org/viewvc?rev=1221631&view=rev
Log:
Make it possible to set the x and y resolution
of images when writing them. This is currently
only supported for file formats where Sanselan
already writes the resolution, ie.
BMP and TIFF.


Modified:
    commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/SanselanConstants.java
    commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/bmp/BmpImageParser.java
    commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/tiff/write/TiffImageWriterBase.java

Modified: commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/SanselanConstants.java
URL: http://svn.apache.org/viewvc/commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/SanselanConstants.java?rev=1221631&r1=1221630&r2=1221631&view=diff
==============================================================================
--- commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/SanselanConstants.java
(original)
+++ commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/SanselanConstants.java
Wed Dec 21 07:03:18 2011
@@ -105,5 +105,20 @@ public interface SanselanConstants
      * <p>
      */
     public static final String PARAM_KEY_XMP_XML = "XMP_XML";
+    
+    /**
+     * Parameter key. Used in write operations to indicate the desired
+     * x resolution to write into the image.
+     * <p>
+     * Valid values: any Integer
+     */
+    public static final String PARAM_KEY_X_RESOLUTION = "X_RESOLUTION";
 
+    /**
+     * Parameter key. Used in write operations to indicate the desired
+     * y resolution to write into the image.
+     * <p>
+     * Valid values: any Integer
+     */
+    public static final String PARAM_KEY_Y_RESOLUTION = "Y_RESOLUTION";
 }

Modified: commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/bmp/BmpImageParser.java
URL: http://svn.apache.org/viewvc/commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/bmp/BmpImageParser.java?rev=1221631&r1=1221630&r2=1221631&view=diff
==============================================================================
--- commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/bmp/BmpImageParser.java
(original)
+++ commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/bmp/BmpImageParser.java
Wed Dec 21 07:03:18 2011
@@ -741,9 +741,16 @@ public class BmpImageParser extends Imag
         // make copy of params; we'll clear keys as we consume them.
         params = (params == null) ? new HashMap() : new HashMap(params);
 
+        Integer xResolution = Integer.valueOf(0);
+        Integer yResolution = Integer.valueOf(0);
+        
         // clear format key.
         if (params.containsKey(PARAM_KEY_FORMAT))
             params.remove(PARAM_KEY_FORMAT);
+        if (params.containsKey(PARAM_KEY_X_RESOLUTION))
+            xResolution = (Integer) params.remove(PARAM_KEY_X_RESOLUTION);
+        if (params.containsKey(PARAM_KEY_Y_RESOLUTION))
+            yResolution = (Integer) params.remove(PARAM_KEY_Y_RESOLUTION);
 
         if (params.size() > 0)
         {
@@ -791,8 +798,8 @@ public class BmpImageParser extends Imag
 
             bos.write4Bytes(BI_RGB); // Compression
             bos.write4Bytes(imagedata.length); // Bitmap Data Size
-            bos.write4Bytes(0); // HResolution
-            bos.write4Bytes(0); // VResolution
+            bos.write4Bytes(xResolution.intValue()); // HResolution
+            bos.write4Bytes(yResolution.intValue()); // VResolution
             if (palette == null)
                 bos.write4Bytes(0); // Colors
             else

Modified: commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/tiff/write/TiffImageWriterBase.java
URL: http://svn.apache.org/viewvc/commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/tiff/write/TiffImageWriterBase.java?rev=1221631&r1=1221630&r2=1221631&view=diff
==============================================================================
--- commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/tiff/write/TiffImageWriterBase.java
(original)
+++ commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/tiff/write/TiffImageWriterBase.java
Wed Dec 21 07:03:18 2011
@@ -270,6 +270,13 @@ public abstract class TiffImageWriterBas
             xmpXml = (String) params.get(PARAM_KEY_XMP_XML);
             params.remove(PARAM_KEY_XMP_XML);
         }
+        
+        Integer xResolution = Integer.valueOf(72);
+        if (params.containsKey(PARAM_KEY_X_RESOLUTION))
+            xResolution = (Integer) params.remove(PARAM_KEY_X_RESOLUTION);
+        Integer yResolution = Integer.valueOf(72);
+        if (params.containsKey(PARAM_KEY_Y_RESOLUTION))
+            yResolution = (Integer) params.remove(PARAM_KEY_Y_RESOLUTION);
 
         int width = src.getWidth();
         int height = src.getHeight();
@@ -443,20 +450,18 @@ public abstract class TiffImageWriterBas
             }
 
             {
-                int xResolution = 72;
                 TiffOutputField field = new TiffOutputField(
                         TIFF_TAG_XRESOLUTION, FIELD_TYPE_RATIONAL, 1,
                         FIELD_TYPE_RATIONAL
-                                .writeData(xResolution, 1, byteOrder));
+                                .writeData(xResolution.intValue(), 1, byteOrder));
                 directory.add(field);
             }
 
             {
-                int yResolution = 72;
                 TiffOutputField field = new TiffOutputField(
                         TIFF_TAG_YRESOLUTION, FIELD_TYPE_RATIONAL, 1,
                         FIELD_TYPE_RATIONAL
-                                .writeData(yResolution, 1, byteOrder));
+                                .writeData(yResolution.intValue(), 1, byteOrder));
                 directory.add(field);
             }
 



Mime
View raw message