]> source.dussan.org Git - xmlgraphics-fop.git/commitdiff
Read the bitmap resolution from PNGs and TIFFs.
authorJeremias Maerki <jeremias@apache.org>
Fri, 12 Aug 2005 10:46:39 +0000 (10:46 +0000)
committerJeremias Maerki <jeremias@apache.org>
Fri, 12 Aug 2005 10:46:39 +0000 (10:46 +0000)
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@232263 13f79535-47bb-0310-9956-ffa450edef68

src/java/org/apache/fop/image/PNGImage.java
src/java/org/apache/fop/image/TIFFImage.java

index 292febc0e80a4c708f8bff9e4a428e885ee0c7ee..fcbfebdfb73ddc72decb90a70e78440caed040a7 100644 (file)
@@ -48,7 +48,15 @@ public class PNGImage extends BatikImage {
         PNGDecodeParam param = new PNGDecodeParam();
         param.setPerformGammaCorrection(true);
         param.setDisplayExponent(2.2f); // sRGB gamma
-        return new PNGRed(stream, param);
+        PNGRed red = new PNGRed(stream, param); 
+        String unit = (String)red.getProperty("pixel_units");
+        if ("Meters".equals(unit)) {
+            this.dpiHorizontal = ((Integer)red.getProperty("x_pixels_per_unit")).intValue() 
+                * 25.4f / 1000f;
+            this.dpiVertical = ((Integer)red.getProperty("y_pixels_per_unit")).intValue()
+                * 25.4f / 1000f;
+        }
+        return red;
     }
     
 }
index 254b81912d0567bdaad46b851cdc8869d235171e..9dc9b9c95edf24240ed4d8ce059ee701e580f6e0 100644 (file)
@@ -21,10 +21,13 @@ package org.apache.fop.image;
 import java.io.IOException;
 
 import org.apache.batik.ext.awt.image.codec.SeekableStream;
+import org.apache.batik.ext.awt.image.codec.tiff.TIFFDirectory;
+import org.apache.batik.ext.awt.image.codec.tiff.TIFFField;
+import org.apache.batik.ext.awt.image.codec.tiff.TIFFImageDecoder;
 import org.apache.batik.ext.awt.image.rendered.CachableRed;
 
 /**
- * @author Jeremias Maerki
+ * TIFF implementation using the Batik codecs.
  */
 public class TIFFImage extends BatikImage {
 
@@ -40,8 +43,31 @@ public class TIFFImage extends BatikImage {
      * @see org.apache.fop.image.BatikImage#decodeImage(org.apache.batik.ext.awt.image.codec.SeekableStream)
      */
     protected CachableRed decodeImage(SeekableStream stream) throws IOException {
-        return new org.apache.batik.ext.awt.image.codec.tiff.TIFFImage
+        org.apache.batik.ext.awt.image.codec.tiff.TIFFImage img
+            = new org.apache.batik.ext.awt.image.codec.tiff.TIFFImage
                 (stream, null, 0);
+        TIFFDirectory dir = (TIFFDirectory)img.getProperty("tiff_directory");
+        TIFFField fld = dir.getField(TIFFImageDecoder.TIFF_RESOLUTION_UNIT);
+        int resUnit = fld.getAsInt(0);
+        fld = dir.getField(TIFFImageDecoder.TIFF_X_RESOLUTION);
+        double xRes = fld.getAsDouble(0);
+        fld = dir.getField(TIFFImageDecoder.TIFF_Y_RESOLUTION);
+        double yRes = fld.getAsDouble(0);
+        switch (resUnit) {
+        case 2: //inch
+            this.dpiHorizontal = xRes;
+            this.dpiVertical = yRes;
+            break;
+        case 3: //cm
+            this.dpiHorizontal = xRes * 2.54f;
+            this.dpiVertical = yRes * 2.54f;
+            break;
+        default:
+            //ignored
+            log.warn("Cannot determine bitmap resolution."
+                    + " Unimplemented resolution unit: " + resUnit);
+        }
+        return img;
     }
     
 }