TMI-19: Fix for broken JFIF raw RGB thumbnails

This commit is contained in:
Harald Kuhr 2012-04-16 22:55:32 +02:00
parent c16ffaca13
commit 0bdb68ea6f
3 changed files with 31 additions and 5 deletions

View File

@ -739,7 +739,7 @@ public class JPEGImageReader extends ImageReaderBase {
stream.readUnsignedShort(),
x = stream.readUnsignedByte(),
y = stream.readUnsignedByte(),
readFully(stream, x * y)
readFully(stream, x * y * 3)
);
}
@ -928,9 +928,8 @@ public class JPEGImageReader extends ImageReaderBase {
// TODO: Candidate for util method
private BufferedImage readRawThumbnail(final byte[] thumbnail, final int size, final int offset, int w, int h) {
DataBufferByte buffer;WritableRaster raster;
buffer = new DataBufferByte(thumbnail, size, offset);
raster = Raster.createInterleavedRaster(buffer, w, h, w * 3, 3, new int[] {0, 1, 2}, null);
DataBufferByte buffer = new DataBufferByte(thumbnail, size, offset);
WritableRaster raster = Raster.createInterleavedRaster(buffer, w, h, w * 3, 3, new int[] {0, 1, 2}, null);
ColorModel cm = new ComponentColorModel(ColorSpace.getInstance(ColorSpace.CS_sRGB),false, false, Transparency.OPAQUE, DataBuffer.TYPE_BYTE);
return new BufferedImage(cm, raster, cm.isAlphaPremultiplied(), null);

View File

@ -270,7 +270,34 @@ public class JPEGImageReaderTest extends ImageReaderAbstractTestCase<JPEGImageRe
assertFalse(reader.hasThumbnails(0)); // Should just not blow up, even if the EXIF IFD1 is missing
}
// TODO: Test JFIF raw thumbnail
@Test
public void testJFIFRawRGBThumbnail() throws IOException {
// JFIF with raw RGB thumbnail (+ EXIF thumbnail)
JPEGImageReader reader = createReader();
reader.setInput(ImageIO.createImageInputStream(getClassLoaderResource("/jpeg/jfif-jfif-and-exif-thumbnail-sharpshot-iphone.jpg")));
assertTrue(reader.hasThumbnails(0));
assertEquals(2, reader.getNumThumbnails(0));
// RAW JFIF
assertEquals(131, reader.getThumbnailWidth(0, 0));
assertEquals(122, reader.getThumbnailHeight(0, 0));
BufferedImage rawJFIFThumb = reader.readThumbnail(0, 0);
assertNotNull(rawJFIFThumb);
assertEquals(131, rawJFIFThumb.getWidth());
assertEquals(122, rawJFIFThumb.getHeight());
// Exif (old thumbnail, from original image, should probably been removed by the software...)
assertEquals(160, reader.getThumbnailWidth(0, 1));
assertEquals(120, reader.getThumbnailHeight(0, 1));
BufferedImage exifThumb = reader.readThumbnail(0, 1);
assertNotNull(exifThumb);
assertEquals(160, exifThumb.getWidth());
assertEquals(120, exifThumb.getHeight());
}
// TODO: Test JFXX indexed thumbnail
// TODO: Test JFXX RGB thumbnail

Binary file not shown.

After

Width:  |  Height:  |  Size: 460 KiB