@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(); }
if (data.getInput().toString().contains("pal8offs")) { continue;
@Override @Test public void testGetTypeSpecifiers() throws IOException { final ImageReader reader = createReader(); for (TestData data : getTestData()) { reader.setInput(data.getInputStream()); ImageTypeSpecifier rawType = reader.getRawImageType(0); // As the JPEGImageReader we delegate to returns null for YCbCr, we'll have to do the same if (rawType == null && data.getInput().toString().contains("jpeg")) { continue; } assertNotNull(rawType); Iterator<ImageTypeSpecifier> types = reader.getImageTypes(0); assertNotNull(types); assertTrue(types.hasNext()); // TODO: This might fail even though the specifiers are obviously equal, if the // color spaces they use are not the SAME instance, as ColorSpace uses identity equals // and Interleaved ImageTypeSpecifiers are only equal if color spaces are equal... boolean rawFound = false; while (types.hasNext()) { ImageTypeSpecifier type = types.next(); if (type.equals(rawType)) { rawFound = true; break; } } assertTrue("ImageTypeSepcifier from getRawImageType should be in the iterator from getImageTypes", rawFound); } }
failBecause("Could not read " + data.getInput() + " with explicit destination type " + type, e);
@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() ); } } }
@Test public void testSetDestination() throws IOException { ImageReader reader = createReader(); TestData data = getTestData().get(0); reader.setInput(data.getInputStream()); ImageReadParam param = reader.getDefaultReadParam(); Iterator<ImageTypeSpecifier> types = reader.getImageTypes(0); while (types.hasNext()) { ImageTypeSpecifier type = types.next(); BufferedImage destination = type.createBufferedImage(50, 50); param.setDestination(destination); BufferedImage result = null; try { result = reader.read(0, param); } catch (Exception e) { failBecause("Could not read " + data.getInput() + " with explicit destination " + destination, e); } assertSame(destination, result); } }
failBecause("Could not read " + data.getInput() + " with explicit destination type " + type, e);
@Test public void testSetDestination() throws IOException { ImageReader reader = createReader(); TestData data = getTestData().get(0); reader.setInput(data.getInputStream()); ImageReadParam param = reader.getDefaultReadParam(); Iterator<ImageTypeSpecifier> types = reader.getImageTypes(0); while (types.hasNext()) { ImageTypeSpecifier type = types.next(); BufferedImage destination = type.createBufferedImage(50, 50); param.setDestination(destination); BufferedImage result = null; try { result = reader.read(0, param); } catch (Exception e) { failBecause("Could not read " + data.getInput() + " with explicit destination " + destination, e); } assertSame(destination, result); } reader.dispose(); }