/** @see org.apache.fop.image.BatikImage */
protected CachableRed decodeImage(SeekableStream stream) throws IOException {
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);
}
fld = dir.getField(TIFFImageDecoder.TIFF_COMPRESSION);
if (fld != null) {
compression = fld.getAsInt(0);
}
fld = dir.getField(TIFFImageDecoder.TIFF_BITS_PER_SAMPLE);
if (fld != null) {
bitsPerPixel = fld.getAsInt(0);
}
fld = dir.getField(TIFFImageDecoder.TIFF_ROWS_PER_STRIP);
if (fld == null) {
stripCount = 1;
} else {
stripCount = (int)(dir.getFieldAsLong(TIFFImageDecoder.TIFF_IMAGE_LENGTH)
/ fld.getAsLong(0));
}
stripOffset = dir.getField(TIFFImageDecoder.TIFF_STRIP_OFFSETS).getAsLong(0);
stripLength = dir.getField(TIFFImageDecoder.TIFF_STRIP_BYTE_COUNTS).getAsLong(0);
if (this.bitsPerPixel == 1) {
this.colorSpace = ColorSpace.getInstance(ColorSpace.CS_GRAY);
}
return img;