public void testReRead() throws IOException { ImageReader reader = createReader(); TestData data = getTestData().get(0); reader.setInput(data.getInputStream(), false); // Explicitly allow repositioning, even though it's the default BufferedImage first = reader.read(0); assertNotNull(first); BufferedImage second = reader.read(0); assertNotNull(second); // TODO: These images should be exactly the same, but there's no equals for images assertEquals(first.getType(), second.getType()); assertEquals(first.getWidth(), second.getWidth()); assertEquals(first.getHeight(), second.getHeight()); }
public void testGetMinIndexNoInput() { ImageReader reader = createReader(); int num = 0; try { num = reader.getMinIndex(); } catch (IllegalStateException ignore) { } assertEquals(0, num); }
public void testSetDestinationOffset() throws IOException { final ImageReader reader = createReader(); TestData data = getTestData().get(0); reader.setInput(data.getInputStream()); ImageReadParam param = reader.getDefaultReadParam(); Point point = new Point(37, 42); param.setDestinationOffset(point); BufferedImage image = reader.read(0, param); assertNotNull(image); assertEquals(reader.getWidth(0) + point.x, image.getWidth()); assertEquals(reader.getHeight(0) + point.y, image.getHeight()); }
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) { fail("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()); }
public void testGetMinIndex() { ImageReader reader = createReader(); TestData data = getTestData().get(0); reader.setInput(data.getInputStream()); int num = 0; try { num = reader.getMinIndex(); } catch (IllegalStateException ignore) { } assertEquals(0, num); }
public void testReadWithSourceRegionParam() { ImageReader reader = createReader(); TestData data = getTestData().get(0); reader.setInput(data.getInputStream()); ImageReadParam param = reader.getDefaultReadParam(); param.setSourceRegion(new Rectangle(0, 0, 10, 10)); BufferedImage image = null; try { image = reader.read(0, param); } catch (IOException e) { fail("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()); }
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) { fail("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()); }
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) { fail("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()); }
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) { fail("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()); }
public void testGetAspectratio() { ImageReader reader = createReader(); TestData data = getTestData().get(0); reader.setInput(data.getInputStream()); float aspect = 0f; try { aspect = reader.getAspectRatio(0); } catch (IOException e) { fail("Could not read image aspectratio" + e); } Dimension d = data.getDimension(0); assertEquals("Wrong aspect aspectratio", d.getWidth() / d.getHeight(), aspect, 0.001); }
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) { fail("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()); }
public void testReadWithSizeParam() { ImageReader reader = createReader(); TestData data = getTestData().get(0); reader.setInput(data.getInputStream()); ImageReadParam param = reader.getDefaultReadParam(); if (param.canSetSourceRenderSize()) { param.setSourceRenderSize(new Dimension(10, 10)); BufferedImage image = null; try { image = reader.read(0, param); } catch (IOException e) { fail("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()); } }
public void testGetNumImagesNoInput() { ImageReader reader = createReader(); int num = -1; try { num = reader.getNumImages(false); } catch (IllegalStateException ignore) { } catch (IOException e) { fail(e.getMessage()); } assertEquals(-1, num); try { num = reader.getNumImages(true); fail("Should throw IllegalStateException"); } catch (IllegalStateException ignore) { } catch (IOException e) { fail(e.getMessage()); } assertEquals(-1, num); }
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); }
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); }
public void testReadWithSubsampleParam() { 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) { fail("Image could not be read: " + e); } assertNotNull("Image was null!", image); assertEquals("Read image has wrong width: ", (double) data.getDimension(0).width / 5.0, image.getWidth(), 1.0); assertEquals("Read image has wrong height: ", (double) data.getDimension(0).height / 5.0, image.getHeight(), 1.0); }
public void testProviderAndMetadataFormatNamesMatch() throws IOException { ImageReaderSpi provider = createProvider(); ImageReader reader = createReader(); reader.setInput(getTestData().get(0).getInputStream()); IIOMetadata imageMetadata = reader.getImageMetadata(0); if (imageMetadata != null) { assertEquals(provider.getNativeImageMetadataFormatName(), imageMetadata.getNativeMetadataFormatName()); } IIOMetadata streamMetadata = reader.getStreamMetadata(); if (streamMetadata != null) { assertEquals(provider.getNativeStreamMetadataFormatName(), streamMetadata.getNativeMetadataFormatName()); } }
public void testGetWidthNoInput() { ImageReader reader = createReader(); int width = 0; try { width = reader.getWidth(0); fail("Width read without imput"); } catch (IllegalStateException ignore) { } catch (IOException e) { fail("Could not read image width: " + e); } assertEquals("Wrong width reported", 0, width); }
public void testGetAspectratioNoInput() { ImageReader reader = createReader(); float aspect = 0f; try { aspect = reader.getAspectRatio(0); fail("aspect read without imput"); } catch (IllegalStateException ignore) { } catch (IOException e) { fail("Could not read image aspectratio" + e); } assertEquals("Wrong aspect aspectratio", 0f, aspect, 0f); }
public void testGetHeightNoInput() { ImageReader reader = createReader(); int height = 0; try { height = reader.getHeight(0); fail("height read without imput"); } catch (IllegalStateException ignore) { } catch (IOException e) { fail("Could not read image height: " + e); } assertEquals("Wrong height reported", 0, height); }