@Test public void testReadWithNullParam() { ImageReader reader = createReader(); TestData data = getTestData().get(0); reader.setInput(data.getInputStream()); BufferedImage image = null; try { image = reader.read(0, null); } catch (IOException e) { failBecause("Image could not be read", e); } assertNotNull("Image was null!", image); assertEquals("Read image has wrong width: " + image.getWidth(), data.getDimension(0).width, image.getWidth()); assertEquals("Read image has wrong height: " + image.getHeight(), data.getDimension(0).height, image.getHeight()); reader.dispose(); }
@Test public void testReadWithNewParam() { ImageReader reader = createReader(); TestData data = getTestData().get(0); reader.setInput(data.getInputStream()); BufferedImage image = null; try { image = reader.read(0, new ImageReadParam()); } catch (IOException e) { failBecause("Image could not be read", e); } assertNotNull("Image was null!", image); assertEquals("Read image has wrong width: " + image.getWidth(), data.getDimension(0).width, image.getWidth()); assertEquals("Read image has wrong height: " + image.getHeight(), data.getDimension(0).height, image.getHeight()); reader.dispose(); }
@Test public void testReadWithDefaultParam() { ImageReader reader = createReader(); TestData data = getTestData().get(0); reader.setInput(data.getInputStream()); BufferedImage image = null; try { image = reader.read(0, reader.getDefaultReadParam()); } catch (IOException e) { failBecause("Image could not be read", e); } assertNotNull("Image was null!", image); assertEquals("Read image has wrong width: " + image.getWidth(), data.getDimension(0).width, image.getWidth()); assertEquals("Read image has wrong height: " + image.getHeight(), data.getDimension(0).height, image.getHeight()); reader.dispose(); }
@Test public void testReadAsRenderedImage() { ImageReader reader = createReader(); TestData data = getTestData().get(0); reader.setInput(data.getInputStream()); RenderedImage image = null; try { image = reader.readAsRenderedImage(0, null); } catch (IOException e) { failBecause("Image could not be read", e); } assertNotNull("Image was null!", image); assertEquals("Read image has wrong width: " + image.getWidth(), data.getDimension(0).width, image.getWidth()); assertEquals("Read image has wrong height: " + image.getHeight(), data.getDimension(0).height, image.getHeight()); }
@Test public void testReadWithSubsampleParamDimensions() { ImageReader reader = createReader(); TestData data = getTestData().get(0); reader.setInput(data.getInputStream()); ImageReadParam param = reader.getDefaultReadParam(); param.setSourceSubsampling(5, 5, 0, 0); BufferedImage image = null; try { image = reader.read(0, param); } catch (IOException e) { failBecause("Image could not be read", e); } assertNotNull("Image was null!", image); assertEquals("Read image has wrong width: ", (data.getDimension(0).width + 4) / 5, image.getWidth()); assertEquals("Read image has wrong height: ", (data.getDimension(0).height + 4) / 5, image.getHeight()); }
@Test public void testReadWithNullParam() { ImageReader reader = createReader(); TestData data = getTestData().get(0); reader.setInput(data.getInputStream()); BufferedImage image = null; try { image = reader.read(0, null); } catch (IOException e) { failBecause("Image could not be read", e); } assertNotNull("Image was null!", image); assertEquals("Read image has wrong width: " + image.getWidth(), data.getDimension(0).width, image.getWidth()); assertEquals("Read image has wrong height: " + image.getHeight(), data.getDimension(0).height, image.getHeight()); }
@Test public void testGetAspectRatio() { ImageReader reader = createReader(); TestData data = getTestData().get(0); reader.setInput(data.getInputStream()); float aspectRatio = 0f; try { aspectRatio = reader.getAspectRatio(0); } catch (IOException e) { fail("Could not read image aspect ratio" + e); } Dimension d = data.getDimension(0); assertEquals("Wrong aspect aspect ratio", d.getWidth() / d.getHeight(), aspectRatio, 0.001); }
@Test public void testReadWithNewParam() { ImageReader reader = createReader(); TestData data = getTestData().get(0); reader.setInput(data.getInputStream()); BufferedImage image = null; try { image = reader.read(0, new ImageReadParam()); } catch (IOException e) { failBecause("Image could not be read", e); } assertNotNull("Image was null!", image); assertEquals("Read image has wrong width: " + image.getWidth(), data.getDimension(0).width, image.getWidth()); assertEquals("Read image has wrong height: " + image.getHeight(), data.getDimension(0).height, image.getHeight()); }
@Test public void testReadWithDefaultParam() { ImageReader reader = createReader(); TestData data = getTestData().get(0); reader.setInput(data.getInputStream()); BufferedImage image = null; try { image = reader.read(0, reader.getDefaultReadParam()); } catch (IOException e) { failBecause("Image could not be read", e); } assertNotNull("Image was null!", image); assertEquals("Read image has wrong width: " + image.getWidth(), data.getDimension(0).width, image.getWidth()); assertEquals("Read image has wrong height: " + image.getHeight(), data.getDimension(0).height, image.getHeight()); }
@Test public void testGetHeight() { ImageReader reader = createReader(); TestData data = getTestData().get(0); reader.setInput(data.getInputStream()); int height = 0; try { height = reader.getHeight(0); } catch (IOException e) { fail("Could not read image height: " + e); } assertEquals("Wrong height reported", data.getDimension(0).height, height); }
@Test public void testGetWidth() { ImageReader reader = createReader(); TestData data = getTestData().get(0); reader.setInput(data.getInputStream()); int width = 0; try { width = reader.getWidth(0); } catch (IOException e) { fail("Could not read image width: " + e); } assertEquals("Wrong width reported", data.getDimension(0).width, width); }
@Test public void testReadWithSizeAndSourceRegionParam() { // TODO: Is this test correct??? ImageReader reader = createReader(); TestData data = getTestData().get(0); reader.setInput(data.getInputStream()); ImageReadParam param = reader.getDefaultReadParam(); if (param.canSetSourceRenderSize()) { Dimension size = data.getDimension(0); size = new Dimension(size.width * 2, size.height * 2); param.setSourceRenderSize(size); param.setSourceRegion(new Rectangle(0, 0, 10, 10)); BufferedImage image = null; try { image = reader.read(0, param); } catch (IOException e) { failBecause("Image could not be read", e); } assertNotNull("Image was null!", image); assertEquals("Read image has wrong width: " + image.getWidth(), 10, image.getWidth()); assertEquals("Read image has wrong height: " + image.getHeight(), 10, image.getHeight()); } reader.dispose(); }
@Test public void testBrokenGetDimensions() throws IOException { JPEGImageReader reader = createReader(); try { for (TestData broken : getBrokenTestData()) { reader.setInput(broken.getInputStream()); Dimension exptectedSize = broken.getDimension(0); try { assertEquals(exptectedSize.width, reader.getWidth(0)); assertEquals(exptectedSize.height, reader.getHeight(0)); } catch (IIOException expected) { assertNotNull(expected.getMessage()); } catch (IOException expected) { if (!(expected instanceof EOFException)) { assertNotNull(expected.getMessage()); } } } } finally { reader.dispose(); } }
@Test public void testRead() { ImageReader reader = createReader(); for (TestData data : getTestData()) { reader.setInput(data.getInputStream()); for (int i = 0; i < data.getImageCount(); i++) { BufferedImage image = null; try { image = reader.read(i); } catch (Exception e) { failBecause(String.format("Image %s index %s could not be read: %s", data.getInput(), i, e), e); } assertNotNull(String.format("Image %s index %s was null!", data.getInput(), i), image); assertEquals( String.format("Image %s index %s has wrong width: %s", data.getInput(), i, image.getWidth()), data.getDimension(i).width, image.getWidth() ); assertEquals( String.format("Image %s index %s has wrong height: %s", data.getInput(), i, image.getHeight()), data.getDimension(i).height, image.getHeight() ); } } reader.dispose(); }
@Test public void testReadAsRenderedImage() { ImageReader reader = createReader(); TestData data = getTestData().get(0); reader.setInput(data.getInputStream()); RenderedImage image = null; try { image = reader.readAsRenderedImage(0, null); } catch (IOException e) { failBecause("Image could not be read", e); } assertNotNull("Image was null!", image); assertEquals("Read image has wrong width: " + image.getWidth(), data.getDimension(0).width, image.getWidth()); assertEquals("Read image has wrong height: " + image.getHeight(), data.getDimension(0).height, image.getHeight()); reader.dispose(); }
@Test public void testReadWithSubsampleParamDimensions() { ImageReader reader = createReader(); TestData data = getTestData().get(0); reader.setInput(data.getInputStream()); ImageReadParam param = reader.getDefaultReadParam(); param.setSourceSubsampling(5, 5, 0, 0); BufferedImage image = null; try { image = reader.read(0, param); } catch (IOException e) { failBecause("Image could not be read", e); } assertNotNull("Image was null!", image); assertEquals("Read image has wrong width: ", (data.getDimension(0).width + 4) / 5, image.getWidth()); assertEquals("Read image has wrong height: ", (data.getDimension(0).height + 4) / 5, image.getHeight()); reader.dispose(); }
@Test public void testReadAsRenderedImageWithDefaultParam() { ImageReader reader = createReader(); TestData data = getTestData().get(0); reader.setInput(data.getInputStream()); RenderedImage image = null; try { image = reader.readAsRenderedImage(0, reader.getDefaultReadParam()); } catch (IOException e) { failBecause("Image could not be read", e); } assertNotNull("Image was null!", image); assertEquals("Read image has wrong width: " + image.getWidth(), data.getDimension(0).width, image.getWidth()); assertEquals("Read image has wrong height: " + image.getHeight(), data.getDimension(0).height, image.getHeight()); reader.dispose(); }
@Test public void testGetHeight() { ImageReader reader = createReader(); TestData data = getTestData().get(0); reader.setInput(data.getInputStream()); int height = 0; try { height = reader.getHeight(0); } catch (IOException e) { fail("Could not read image height: " + e); } assertEquals("Wrong height reported", data.getDimension(0).height, height); reader.dispose(); }
@Test public void testGetAspectRatio() { ImageReader reader = createReader(); TestData data = getTestData().get(0); reader.setInput(data.getInputStream()); float aspectRatio = 0f; try { aspectRatio = reader.getAspectRatio(0); } catch (IOException e) { fail("Could not read image aspect ratio" + e); } Dimension d = data.getDimension(0); assertEquals("Wrong aspect aspect ratio", d.getWidth() / d.getHeight(), aspectRatio, 0.001); reader.dispose(); }
@Test public void testGetWidth() { ImageReader reader = createReader(); TestData data = getTestData().get(0); reader.setInput(data.getInputStream()); int width = 0; try { width = reader.getWidth(0); } catch (IOException e) { fail("Could not read image width: " + e); } assertEquals("Wrong width reported", data.getDimension(0).width, width); reader.dispose(); }