@Test public void testColorsVsReference() throws IOException { ImageReader reader = createReader(); TestData data = new TestData(getClassLoaderResource("/ppm/colors.ppm"), new Dimension(3, 2)); reader.setInput(data.getInputStream()); BufferedImage expected = new BufferedImage(3, 2, BufferedImage.TYPE_3BYTE_BGR); expected.setRGB(0, 0, new Color(255, 0, 0).getRGB()); expected.setRGB(1, 0, new Color(0, 255, 0).getRGB()); expected.setRGB(2, 0, new Color(0, 0, 255).getRGB()); expected.setRGB(0, 1, new Color(255, 255, 0).getRGB()); expected.setRGB(1, 1, new Color(255, 255, 255).getRGB()); expected.setRGB(2, 1, new Color(0, 0, 0).getRGB()); assertImageDataEquals("Images differ from reference", expected, reader.read(0)); }
@Test public void testRGBAVsReference() throws IOException { ImageReader reader = createReader(); TestData data = new TestData(getClassLoaderResource("/pam/rgba.pam"), new Dimension(4, 2)); reader.setInput(data.getInputStream()); BufferedImage expected = new BufferedImage(4, 2, BufferedImage.TYPE_4BYTE_ABGR); expected.setRGB(0, 0, new Color(0, 0, 255).getRGB()); expected.setRGB(1, 0, new Color(0, 255, 0).getRGB()); expected.setRGB(2, 0, new Color(255, 0, 0).getRGB()); expected.setRGB(3, 0, new Color(255, 255, 255).getRGB()); expected.setRGB(0, 1, new Color(0, 0, 255, 127).getRGB()); expected.setRGB(1, 1, new Color(0, 255, 0, 127).getRGB()); expected.setRGB(2, 1, new Color(255, 0, 0, 127).getRGB()); expected.setRGB(3, 1, new Color(255, 255, 255, 127).getRGB()); assertImageDataEquals("Images differ from reference", expected, reader.read(0)); }
@Override protected List<TestData> getTestData() { return Collections.singletonList( new TestData(getClassLoaderResource("/dcx/input.dcx"), new Dimension(70, 46)) // RLE encoded RGB (the only sample I've found) ); }
@Test public void testAddIIOReadProgressListenerCallbacksJPEG() { ImageReader reader = createReader(); TestData data = new TestData(getClassLoaderResource("/bmpsuite/q/rgb24jpeg.bmp"), new Dimension(127, 64)); reader.setInput(data.getInputStream()); IIOReadProgressListener listener = mock(IIOReadProgressListener.class); reader.addIIOReadProgressListener(listener); try { reader.read(0); } catch (IOException e) { fail("Could not read image"); } // At least imageStarted and imageComplete, plus any number of imageProgress InOrder ordered = inOrder(listener); ordered.verify(listener).imageStarted(reader, 0); ordered.verify(listener, atLeastOnce()).imageProgress(eq(reader), anyInt()); ordered.verify(listener).imageComplete(reader); }
protected List<TestData> getBrokenTestData() { // These files are considered too broken to be read (ie. most other software does not read them either). return Arrays.asList( new TestData(getClassLoaderResource("/broken-jpeg/broken-bogus-segment-length.jpg"), new Dimension(467, 612)), // Semi-readable, parts missing new TestData(getClassLoaderResource("/broken-jpeg/broken-adobe-marker-bad-length.jpg"), new Dimension(1800, 1200)), // Unreadable, segment lengths are wrong new TestData(getClassLoaderResource("/broken-jpeg/broken-invalid-adobe-ycc-gray.jpg"), new Dimension(11, 440)), // Image readable, broken metadata (fixable?) new TestData(getClassLoaderResource("/broken-jpeg/broken-no-sof-ascii-transfer-mode.jpg"), new Dimension(-1, -1)), // Unreadable, can't find SOFn marker new TestData(getClassLoaderResource("/broken-jpeg/broken-sos-before-sof.jpg"), new Dimension(-1, -1)), // Unreadable, can't find SOFn marker new TestData(getClassLoaderResource("/broken-jpeg/broken-adobe-segment-length-beyond-eof.jpg"), new Dimension(-1, -1)), // Unreadable, no EOI new TestData(getClassLoaderResource("/broken-jpeg/513f29d0-02a8-11e7-9756-6035edb96e79.jpg"), new Dimension(-1, -1)), new TestData(getClassLoaderResource("/broken-jpeg/51432b02-02a8-11e7-9203-b42b1c43c0c3.jpg"), new Dimension(-1, -1)), new TestData(getClassLoaderResource("/broken-jpeg/5145e95a-02a8-11e7-8372-4787a7307ab8.jpg"), new Dimension(-1, -1)), new TestData(getClassLoaderResource("/broken-jpeg/514b20dc-02a8-11e7-92c6-d4fed7b4ebb1.jpg"), new Dimension(-1, -1)), new TestData(getClassLoaderResource("/broken-jpeg/514c48ea-02a8-11e7-8789-bb75321f404f.jpg"), new Dimension(-1, -1)), new TestData(getClassLoaderResource("/broken-jpeg/514e4122-02a8-11e7-8c03-0830d60cd585.jpg"), new Dimension(-1, -1)), new TestData(getClassLoaderResource("/broken-jpeg/513f29d0-02a8-11e7-9756-6035edb96e79.jpg"), new Dimension(-1, -1)) ); // More test data in specific tests below }
@Test public void testEmbeddedNoBaseURI() throws IOException { // With no base URI, we will throw an exception, about the missing embedded resource URL resource = getClassLoaderResource("/svg/barChart.svg"); SVGImageReader reader = createReader(); TestData data = new TestData(resource, (Dimension) null); try (ImageInputStream stream = data.getInputStream()) { reader.setInput(stream); BufferedImage image = reader.read(0); assertNotNull(image); assertEquals(450, image.getWidth()); assertEquals(500, image.getHeight()); } catch (IIOException allowed) { assertTrue(allowed.getMessage().contains("batikLogo.svg")); // The embedded resource we don't find } finally { reader.dispose(); } } }
@Test public void testAddIIOReadProgressListenerCallbacksPNG() { ImageReader reader = createReader(); TestData data = new TestData(getClassLoaderResource("/bmpsuite/q/rgb24png.bmp"), new Dimension(127, 64)); reader.setInput(data.getInputStream()); IIOReadProgressListener listener = mock(IIOReadProgressListener.class); reader.addIIOReadProgressListener(listener); try { reader.read(0); } catch (IOException e) { fail("Could not read image"); } // At least imageStarted and imageComplete, plus any number of imageProgress InOrder ordered = inOrder(listener); ordered.verify(listener).imageStarted(reader, 0); ordered.verify(listener, atLeastOnce()).imageProgress(eq(reader), anyInt()); ordered.verify(listener).imageComplete(reader); }
@Test public void testRepeatedRead() throws IOException { Dimension dim = new Dimension(100, 100); ImageReader reader = createReader(); ImageReadParam param = reader.getDefaultReadParam(); param.setSourceRenderSize(dim); TestData redSquare = new TestData(getClassLoaderResource("/svg/red-square.svg"), dim); reader.setInput(redSquare.getInputStream()); BufferedImage imageRed = reader.read(0, param); assertEquals(0xFF0000, imageRed.getRGB(50, 50) & 0xFFFFFF); TestData blueSquare = new TestData(getClassLoaderResource("/svg/blue-square.svg"), dim); reader.setInput(blueSquare.getInputStream()); BufferedImage imageBlue = reader.read(0, param); assertEquals(0x0000FF, imageBlue.getRGB(50, 50) & 0xFFFFFF); }
@Test public void testGetRawImageTypeCMYK() throws IOException { // Make sure images that are encoded as CMYK (not YCCK) actually return non-null for getRawImageType JPEGImageReader reader = createReader(); List<TestData> cmykData = Arrays.asList( new TestData(getClassLoaderResource("/jpeg/cmyk-sample.jpg"), new Dimension(100, 100)), new TestData(getClassLoaderResource("/jpeg/cmyk-sample-no-icc.jpg"), new Dimension(100, 100)) ); for (TestData data : cmykData) { reader.setInput(data.getInputStream()); ImageTypeSpecifier rawType = reader.getRawImageType(0); assertNotNull("No raw type for " + data, rawType); } }
@Override protected List<TestData> getTestData() { return Arrays.asList( new TestData(getClassLoaderResource("/ppm/lena.ppm"), new Dimension(128, 128)), // P6 (PPM RAW) new TestData(getClassLoaderResource("/ppm/colors.ppm"), new Dimension(3, 2)), // P3 (PPM PLAIN) new TestData(getClassLoaderResource("/pbm/j.pbm"), new Dimension(6, 10)), // P1 (PBM PLAIN) new TestData(getClassLoaderResource("/pgm/feep.pgm"), new Dimension(24, 7)), // P2 (PGM PLAIN) new TestData(getClassLoaderResource("/pgm/feep16.pgm"), new Dimension(24, 7)), // P2 (PGM PLAIN, 16 bits/sample) new TestData(getClassLoaderResource("/pgm/house.l.pgm"), new Dimension(367, 241)), // P5 (PGM RAW) new TestData(getClassLoaderResource("/ppm/lighthouse_rgb48.ppm"), new Dimension(768, 512)), // P6 (PPM RAW, 16 bits/sample) new TestData(getClassLoaderResource("/pam/lena.pam"), new Dimension(128, 128)), // P7 RGB new TestData(getClassLoaderResource("/pam/rgba.pam"), new Dimension(4, 2)) // P7 RGB_ALPHA ); }
@Override protected List<TestData> getTestData() { return Collections.singletonList( new TestData(getClassLoaderResource("/sgi/MARBLES.SGI"), new Dimension(1419, 1001)) // RLE encoded RGB ); }
protected List<TestData> getTestData() { return Arrays.asList( new TestData(getClassLoaderResource("/svg/batikLogo.svg"), new Dimension(450, 500)), new TestData(getClassLoaderResource("/svg/red-square.svg"), new Dimension(100, 100)), new TestData(getClassLoaderResource("/svg/blue-square.svg"), new Dimension(100, 100)), new TestData(getClassLoaderResource("/svg/Android_robot.svg"), new Dimension(400, 400)) ); }
@Override protected List<TestData> getTestData() { return Arrays.asList( new TestData(getClassLoaderResource("/hdr/memorial_o876.hdr"), new Dimension(512, 768)) ); }
@Test public void testProviderNotMatchJPEG() throws IOException { // This JPEG contains PICT magic bytes at locations a PICT would normally have them. // We should not claim to be able read it. assertFalse(sProvider.canDecodeInput( new TestData(getClassLoaderResource("/jpeg/R-7439-1151526181.jpeg"), new Dimension(386, 396) ))); }
@Override protected List<TestData> getTestData() { return Collections.singletonList( new TestData(getClassLoaderResource("/png/12monkeys-splash.png"), new Dimension(300, 410)) ); }
protected List<TestData> getTestData() { return Collections.singletonList( new TestData(getClassLoaderResource("/wmf/test.wmf"), new Dimension(133, 106)) ); }
@Test public void testXVThumbNotIncorrectlyRecognizedAsPAM() throws IOException { ImageReaderSpi provider = createProvider(); assertTrue("Should recognize PAM format", provider.canDecodeInput(new TestData(getClassLoaderResource("/pam/rgba.pam"), new Dimension()).getInputStream())); // Sanity assertFalse("Should distinguish xv-thumbs from PAM format", provider.canDecodeInput(new TestData(getClassLoaderResource("/xv-thumb/xv-thumb.xvt"), new Dimension()).getInputStream())); } }
@Override protected List<TestData> getTestData() { return Collections.singletonList( new TestData(getClassLoaderResource("/jpeg/R-7439-1151526181.jpeg"), new Dimension(386, 396)) ); }
private List<TestData> getCMYKData() { return Arrays.asList( new TestData(getClassLoaderResource("/jpeg/cmyk-sample.jpg"), new Dimension(100, 100)), new TestData(getClassLoaderResource("/jpeg/cmyk-sample-multiple-chunk-icc.jpg"), new Dimension(100, 100)), new TestData(getClassLoaderResource("/jpeg/cmyk-sample-custom-icc-bright.jpg"), new Dimension(100, 100)), new TestData(getClassLoaderResource("/jpeg/cmyk-sample-no-icc.jpg"), new Dimension(100, 100)) ); }