mirror of
https://github.com/haraldk/TwelveMonkeys.git
synced 2025-08-05 04:25:29 -04:00
Added test case for RGB JPEG
+ fixed an issue in getImageTypes to avoid incompatible conversion.
This commit is contained in:
parent
3a86bfab98
commit
fb3c5f8440
@ -1428,8 +1428,9 @@ public abstract class ImageReaderAbstractTest<T extends ImageReader> {
|
||||
catch (IIOException | IllegalArgumentException expected) {
|
||||
// TODO: This is thrown by ImageReader.getDestination. But are we happy with that?
|
||||
String message = expected.getMessage().toLowerCase();
|
||||
if (!(message.contains("destination") && message.contains("type"))) {
|
||||
// Allow this to bubble up, du to a bug in the Sun PNGImageReader
|
||||
if (!(message.contains("destination") && message.contains("type")
|
||||
|| message.contains("num source & dest bands differ"))) {
|
||||
// Allow this to bubble up, due to a bug in the Sun PNGImageReader
|
||||
throw expected;
|
||||
}
|
||||
}
|
||||
|
@ -274,6 +274,20 @@ public final class JPEGImageReader extends ImageReaderBase {
|
||||
|
||||
return typeList.iterator();
|
||||
}
|
||||
else if (csType == JPEGColorSpace.RGB) {
|
||||
// Bug in com.sun...JPEGImageReader: returns gray as acceptable type, but refuses to convert
|
||||
ArrayList<ImageTypeSpecifier> typeList = new ArrayList<>();
|
||||
|
||||
// Filter out the gray type
|
||||
while (types.hasNext()) {
|
||||
ImageTypeSpecifier type = types.next();
|
||||
if (type.getBufferedImageType() != BufferedImage.TYPE_BYTE_GRAY) {
|
||||
typeList.add(type);
|
||||
}
|
||||
}
|
||||
|
||||
return typeList.iterator();
|
||||
}
|
||||
|
||||
return types;
|
||||
}
|
||||
|
@ -88,6 +88,7 @@ public class JPEGImageReaderTest extends ImageReaderAbstractTest<JPEGImageReader
|
||||
new TestData(getClassLoaderResource("/jpeg/cmm-exception-adobe-rgb.jpg"), new Dimension(626, 76)),
|
||||
new TestData(getClassLoaderResource("/jpeg/cmm-exception-srgb.jpg"), new Dimension(1800, 1200)),
|
||||
new TestData(getClassLoaderResource("/jpeg/corrupted-icc-srgb.jpg"), new Dimension(1024, 685)),
|
||||
new TestData(getClassLoaderResource("/jpeg/adobe-unknown-rgb-ids.jpg"), new Dimension(225, 156)), // Adobe, unknown transform, component ids R, G & B
|
||||
new TestData(getClassLoaderResource("/jpeg/gray-sample.jpg"), new Dimension(386, 396)),
|
||||
new TestData(getClassLoaderResource("/jpeg/cmyk-sample.jpg"), new Dimension(160, 227)),
|
||||
new TestData(getClassLoaderResource("/jpeg/cmyk-sample-multiple-chunk-icc.jpg"), new Dimension(2707, 3804)),
|
||||
@ -1005,6 +1006,28 @@ public class JPEGImageReaderTest extends ImageReaderAbstractTest<JPEGImageReader
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAdobeUnknownRGBComponentIds() throws IOException {
|
||||
JPEGImageReader reader = createReader();
|
||||
reader.setInput(ImageIO.createImageInputStream(getClassLoaderResource("/jpeg/adobe-unknown-rgb-ids.jpg")));
|
||||
|
||||
assertEquals(225, reader.getWidth(0));
|
||||
assertEquals(156, reader.getHeight(0));
|
||||
|
||||
ImageReadParam param = reader.getDefaultReadParam();
|
||||
param.setSourceRegion(new Rectangle(0, 0, 225, 8));
|
||||
BufferedImage image = reader.read(0, param);
|
||||
assertNotNull(image);
|
||||
assertEquals(225, image.getWidth());
|
||||
assertEquals(8, image.getHeight());
|
||||
|
||||
// Validate strip colors
|
||||
for (int i = 0; i < image.getWidth() / 10; i++) {
|
||||
int actualRGB = image.getRGB(i * 10, 7);
|
||||
assertRGBEquals(0xffffffff, actualRGB); // Will be pink/purple if decoded as YCbCr and not RGB
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Slightly fuzzy RGB equals method. Tolerance +/-5 steps.
|
||||
*/
|
||||
|
Binary file not shown.
After Width: | Height: | Size: 9.0 KiB |
Loading…
x
Reference in New Issue
Block a user