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;
}
}
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 {
* @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;
}
}