Fix #268: Reading with source region for JPEG-in-TIFF

This commit is contained in:
Oliver Schmidtmer 2016-10-19 15:54:11 +02:00
parent 17eeda210e
commit 610f9bec9f
2 changed files with 5 additions and 5 deletions

View File

@ -992,14 +992,15 @@ public class TIFFImageReader extends ImageReaderBase {
// Read only tiles that lies within region
Rectangle tileRect = new Rectangle(col, row, colsInTile, rowsInTile);
if (tileRect.intersects(srcRegion)) {
Rectangle intersection = tileRect.intersection( srcRegion );
if (!intersection.isEmpty()) {
imageInput.seek(stripTileOffsets[i]);
int length = stripTileByteCounts != null ? (int) stripTileByteCounts[i] : Short.MAX_VALUE;
try (ImageInputStream subStream = new SubImageInputStream(imageInput, length)) {
jpegReader.setInput(subStream);
jpegParam.setSourceRegion(new Rectangle(0, 0, colsInTile, rowsInTile));
jpegParam.setSourceRegion(new Rectangle( intersection.x - col, intersection.y - row, intersection.width, intersection.height));
// TODO: If we have non-standard reference B/W or yCbCr coefficients,
// we might still have to do extra color space conversion...
@ -1008,7 +1009,7 @@ public class TIFFImageReader extends ImageReaderBase {
}
if (!needsCSConversion) {
jpegParam.setDestinationOffset(new Point(col - srcRegion.x, row - srcRegion.y));
jpegParam.setDestinationOffset(new Point(intersection.x - srcRegion.x, intersection.y - srcRegion.y));
jpegParam.setDestination(destination);
jpegReader.read(0, jpegParam);
}
@ -1017,7 +1018,7 @@ public class TIFFImageReader extends ImageReaderBase {
// We'll have to use readAsRaster and later apply color space conversion ourselves
Raster raster = jpegReader.readRaster(0, jpegParam);
normalizeColor(interpretation, ((DataBufferByte) raster.getDataBuffer()).getData());
destination.getRaster().setDataElements(col - srcRegion.x, row - srcRegion.y, raster);
destination.getRaster().setDataElements(intersection.x - srcRegion.x, intersection.y - srcRegion.y, raster);
}
}
}

View File

@ -273,7 +273,6 @@ public class TIFFImageReaderTest extends ImageReaderAbstractTest<TIFFImageReader
}
}
@Ignore("Known issue")
@Test
public void testReadJPEGRasterCaseWithSrcRegion() throws IOException {
// Problematic test data, which is YCbCr encoded (as correctly specified by the PhotometricInterpretation tag,