aboutsummaryrefslogtreecommitdiffstats
path: root/src/java/org
diff options
context:
space:
mode:
authorJeremias Maerki <jeremias@apache.org>2005-08-12 10:46:39 +0000
committerJeremias Maerki <jeremias@apache.org>2005-08-12 10:46:39 +0000
commit0a6c44e1bafc9c1c8d77858b18e5f37e2d07e7da (patch)
tree170a353e7f28602a2ad4e393d1f877dd4046cd5a /src/java/org
parentff1072cb52160c65b5ecd1a084f3dea42b47a12f (diff)
downloadxmlgraphics-fop-0a6c44e1bafc9c1c8d77858b18e5f37e2d07e7da.tar.gz
xmlgraphics-fop-0a6c44e1bafc9c1c8d77858b18e5f37e2d07e7da.zip
Read the bitmap resolution from PNGs and TIFFs.
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@232263 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/java/org')
-rw-r--r--src/java/org/apache/fop/image/PNGImage.java10
-rw-r--r--src/java/org/apache/fop/image/TIFFImage.java30
2 files changed, 37 insertions, 3 deletions
diff --git a/src/java/org/apache/fop/image/PNGImage.java b/src/java/org/apache/fop/image/PNGImage.java
index 292febc0e..fcbfebdfb 100644
--- a/src/java/org/apache/fop/image/PNGImage.java
+++ b/src/java/org/apache/fop/image/PNGImage.java
@@ -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;
}
}
diff --git a/src/java/org/apache/fop/image/TIFFImage.java b/src/java/org/apache/fop/image/TIFFImage.java
index 254b81912..9dc9b9c95 100644
--- a/src/java/org/apache/fop/image/TIFFImage.java
+++ b/src/java/org/apache/fop/image/TIFFImage.java
@@ -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;
}
}