mirror of
https://github.com/haraldk/TwelveMonkeys.git
synced 2025-08-05 12:35:29 -04:00
Merge pull request #286 from Schmidor/TMI268
Fix #268: Reading with source region for JPEG-in-TIFF
This commit is contained in:
commit
5ab3fdd1d3
@ -992,14 +992,15 @@ public class TIFFImageReader extends ImageReaderBase {
|
|||||||
|
|
||||||
// Read only tiles that lies within region
|
// Read only tiles that lies within region
|
||||||
Rectangle tileRect = new Rectangle(col, row, colsInTile, rowsInTile);
|
Rectangle tileRect = new Rectangle(col, row, colsInTile, rowsInTile);
|
||||||
if (tileRect.intersects(srcRegion)) {
|
Rectangle intersection = tileRect.intersection( srcRegion );
|
||||||
|
if (!intersection.isEmpty()) {
|
||||||
imageInput.seek(stripTileOffsets[i]);
|
imageInput.seek(stripTileOffsets[i]);
|
||||||
|
|
||||||
int length = stripTileByteCounts != null ? (int) stripTileByteCounts[i] : Short.MAX_VALUE;
|
int length = stripTileByteCounts != null ? (int) stripTileByteCounts[i] : Short.MAX_VALUE;
|
||||||
|
|
||||||
try (ImageInputStream subStream = new SubImageInputStream(imageInput, length)) {
|
try (ImageInputStream subStream = new SubImageInputStream(imageInput, length)) {
|
||||||
jpegReader.setInput(subStream);
|
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,
|
// TODO: If we have non-standard reference B/W or yCbCr coefficients,
|
||||||
// we might still have to do extra color space conversion...
|
// we might still have to do extra color space conversion...
|
||||||
@ -1008,7 +1009,7 @@ public class TIFFImageReader extends ImageReaderBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!needsCSConversion) {
|
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);
|
jpegParam.setDestination(destination);
|
||||||
jpegReader.read(0, jpegParam);
|
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
|
// We'll have to use readAsRaster and later apply color space conversion ourselves
|
||||||
Raster raster = jpegReader.readRaster(0, jpegParam);
|
Raster raster = jpegReader.readRaster(0, jpegParam);
|
||||||
normalizeColor(interpretation, ((DataBufferByte) raster.getDataBuffer()).getData());
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -273,7 +273,6 @@ public class TIFFImageReaderTest extends ImageReaderAbstractTest<TIFFImageReader
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Ignore("Known issue")
|
|
||||||
@Test
|
@Test
|
||||||
public void testReadJPEGRasterCaseWithSrcRegion() throws IOException {
|
public void testReadJPEGRasterCaseWithSrcRegion() throws IOException {
|
||||||
// Problematic test data, which is YCbCr encoded (as correctly specified by the PhotometricInterpretation tag,
|
// Problematic test data, which is YCbCr encoded (as correctly specified by the PhotometricInterpretation tag,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user