throws ImageReadException, IOException
{
final List<TiffField> entries = directory.entries;
if (entries == null) {
throw new ImageReadException("TIFF missing entries");
}
final int photometricInterpretation = 0xffff & directory.getSingleFieldValue(
TiffTagConstants.TIFF_TAG_PHOTOMETRIC_INTERPRETATION);
final int compression = 0xffff & directory.getSingleFieldValue(TiffTagConstants.TIFF_TAG_COMPRESSION);
final int width = directory.getSingleFieldValue(TiffTagConstants.TIFF_TAG_IMAGE_WIDTH);
final int height = directory.getSingleFieldValue(TiffTagConstants.TIFF_TAG_IMAGE_LENGTH);
Rectangle subImage = checkForSubImage(params);
if (subImage != null) {
// Check for valid subimage specification. The following checks
// are consistent with BufferedImage.getSubimage()
if (subImage.width <= 0) {
throw new ImageReadException("negative or zero subimage width");
}
if (subImage.height <= 0) {
throw new ImageReadException("negative or zero subimage height");
}
if (subImage.x < 0 || subImage.x >= width) {
throw new ImageReadException("subimage x is outside raster");
}
if (subImage.x + subImage.width > width) {
throw new ImageReadException("subimage (x+width) is outside raster");
}
if (subImage.y < 0 || subImage.y >= height) {
throw new ImageReadException("subimage y is outside raster");
}
if (subImage.y + subImage.height > height) {
throw new ImageReadException("subimage (y+height) is outside raster");
}
// if the subimage is just the same thing as the whole
// image, suppress the subimage processing
if (subImage.x == 0
&& subImage.y == 0
&& subImage.width == width
&& subImage.height == height) {
subImage = null;
}
}
int samplesPerPixel = 1;
final TiffField samplesPerPixelField = directory.findField(
TiffTagConstants.TIFF_TAG_SAMPLES_PER_PIXEL);
if (samplesPerPixelField != null) {
samplesPerPixel = samplesPerPixelField.getIntValue();
}
int[] bitsPerSample = { 1 };
int bitsPerPixel = samplesPerPixel;
final TiffField bitsPerSampleField = directory.findField(
TiffTagConstants.TIFF_TAG_BITS_PER_SAMPLE);
if (bitsPerSampleField != null) {
bitsPerSample = bitsPerSampleField.getIntArrayValue();
bitsPerPixel = bitsPerSampleField.getIntValueOrArraySum();
}
// int bitsPerPixel = getTagAsValueOrArraySum(entries,
// TIFF_TAG_BITS_PER_SAMPLE);
int predictor = -1;
{
// dumpOptionalNumberTag(entries, TIFF_TAG_FILL_ORDER);
// dumpOptionalNumberTag(entries, TIFF_TAG_FREE_BYTE_COUNTS);
// dumpOptionalNumberTag(entries, TIFF_TAG_FREE_OFFSETS);
// dumpOptionalNumberTag(entries, TIFF_TAG_ORIENTATION);
// dumpOptionalNumberTag(entries, TIFF_TAG_PLANAR_CONFIGURATION);
final TiffField predictorField = directory.findField(
TiffTagConstants.TIFF_TAG_PREDICTOR);
if (null != predictorField) {
predictor = predictorField.getIntValueOrArraySum();
}
}
if (samplesPerPixel != bitsPerSample.length) {
throw new ImageReadException("Tiff: samplesPerPixel ("
+ samplesPerPixel + ")!=fBitsPerSample.length ("
+ bitsPerSample.length + ")");
}