ImageTypeSpecifier imageTypeSpecifier = imageTypes.next(); img = imageTypeSpecifier.createBufferedImage(width, height); param.setDestination(img); } else { lastException = new IOException("unable to load even a truncated version of the image.");
@Test(expected = IIOException.class) public void testGetDestinationParamIllegalDestination() throws IIOException { ImageReadParam param = new ImageReadParam(); param.setDestination(new BufferedImage(21, 1, BufferedImage.TYPE_USHORT_565_RGB)); ImageReaderBase.getDestination(param, TYPES.iterator(), 42, 1); }
ImageReadParam param = reader.getDefaultReadParam(); param.setDestination(img); for (int i = 0; i++; i < n) { param.setDestinationOffset(new Point(w * i, 0); reader.read(i, param); }
@Test public void testGetDestinationParamGoodDestination() throws IIOException { ImageReadParam param = new ImageReadParam(); param.setDestination(new BufferedImage(21, 1, BufferedImage.TYPE_INT_ARGB)); BufferedImage destination = ImageReaderBase.getDestination(param, TYPES.iterator(), 42, 1); assertEquals(BufferedImage.TYPE_INT_ARGB, destination.getType()); assertEquals(21, destination.getWidth()); assertEquals(1, destination.getHeight()); }
@Test public void testGetDestinationParamDestinationWider() throws IIOException { ImageReadParam param = new ImageReadParam(); param.setDestination(new BufferedImage(42, 1, BufferedImage.TYPE_INT_RGB)); BufferedImage destination = ImageReaderBase.getDestination(param, TYPES.iterator(), 3, 3); assertEquals(42, destination.getWidth()); assertEquals(1, destination.getHeight()); assertEquals(BufferedImage.TYPE_INT_RGB, destination.getType()); }
@Test public void testGetDestinationParamDestinationTaller() throws IIOException { ImageReadParam param = new ImageReadParam(); param.setDestination(new BufferedImage(1, 42, BufferedImage.TYPE_INT_ARGB)); BufferedImage destination = ImageReaderBase.getDestination(param, TYPES.iterator(), 3, 3); assertEquals(1, destination.getWidth()); assertEquals(42, destination.getHeight()); assertEquals(BufferedImage.TYPE_INT_ARGB, destination.getType()); }
param.setDestination(image);
@Test public void testHandHotspotExplicitDestination() throws IOException { CURImageReader reader = createReader(); reader.setInput(getTestData().get(0).getInputStream()); BufferedImage image = reader.read(0); // Create dest image with same data, except properties... BufferedImage dest = new BufferedImage( image.getColorModel(), image.getRaster(), image.getColorModel().isAlphaPremultiplied(), null ); ImageReadParam param = new ImageReadParam(); param.setDestination(dest); assertHotSpot(getTestData().get(0), param, new Point(15, 15)); }
@Test public void testHasExplicitDestinationParamWithDestination() { ImageReadParam param = new ImageReadParam(); param.setDestination(new BufferedImage(1, 1, BufferedImage.TYPE_BYTE_GRAY)); assertTrue(ImageReaderBase.hasExplicitDestination(param)); }
for (ImageTypeSpecifier illegalType : illegalTypes) { BufferedImage destination = illegalType.createBufferedImage(50, 50); param.setDestination(destination);
@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(); }
@Test public void testReadLayersExplicitDestination() throws IOException { PSDImageReader imageReader = createReader(); try (ImageInputStream stream = getTestData().get(3).getInputStream()) { imageReader.setInput(stream); int numImages = imageReader.getNumImages(true); for (int i = 0; i < numImages; i++) { Iterator<ImageTypeSpecifier> types = imageReader.getImageTypes(i); int width = imageReader.getWidth(i); int height = imageReader.getHeight(i); while (types.hasNext()) { ImageTypeSpecifier type = types.next(); ImageReadParam param = imageReader.getDefaultReadParam(); BufferedImage destination = type.createBufferedImage(width, height); param.setDestination(destination); BufferedImage image = imageReader.read(i, param); assertSame(destination, image); } } } }
@Test public void testSetDestinationRaw() throws IOException { ImageReader reader = createReader(); TestData data = getTestData().get(0); reader.setInput(data.getInputStream()); ImageReadParam param = reader.getDefaultReadParam(); ImageTypeSpecifier type = reader.getRawImageType(0); if (type != null) { BufferedImage destination = type.createBufferedImage(reader.getWidth(0), reader.getHeight(0)); param.setDestination(destination); BufferedImage result = null; try { result = reader.read(0, param); } catch (Exception e) { failBecause("Image could not be read", e); } assertSame(destination, result); } else { System.err.println("WARNING: Test skipped due to reader.getRawImageType(0) returning null"); } reader.dispose(); }
@Test(expected = IIOException.class) public void testBrokenBogusSegmentLengthReadWithDestination() throws IOException { JPEGImageReader reader = createReader(); try { reader.setInput(ImageIO.createImageInputStream(getClassLoaderResource("/broken-jpeg/broken-bogus-segment-length.jpg"))); assertEquals(467, reader.getWidth(0)); assertEquals(612, reader.getHeight(0)); ImageTypeSpecifier type = reader.getImageTypes(0).next(); BufferedImage image = type.createBufferedImage(reader.getWidth(0), reader.getHeight(0)); ImageReadParam param = reader.getDefaultReadParam(); param.setDestination(image); try { reader.read(0, param); } catch (IOException e) { // Even if we get an exception here, the image should contain 10-15% of the image assertRGBEquals(0xffffffff, image.getRGB(0, 0)); // white area assertRGBEquals(0xff0000ff, image.getRGB(67, 22)); // blue area assertRGBEquals(0xffff00ff, image.getRGB(83, 22)); // purple area throw e; } } finally { reader.dispose(); } }
param.setDestination(destination);
ImageInputStream stream = ImageIO.createImageInputStream(input); ImageReader reader = ImageIO.getImageReaders(stream).next(); // TODO: Test hasNext() reader.setInput(stream); int width = reader.getWidth(0); int height = reader.getHeight(0); ImageTypeSpecifier spec = reader.getImageTypes(0).next(); // TODO: Test hasNext(); BufferedImage image = MappedImageFactory.createCompatibleMappedImage(width, height, spec) ImageReadParam param = reader.getDefaultReadParam(); param.setDestination(image); image = reader.read(0, param); // Will return same image as created above // ...process image as needed...
ImageReader reader; // the reader for your format reader.setInput(input); // your input // Create image from type specifier ImageTypeSpecifier spec = reader.getImageTypes(0).next(); BufferedImage destination = spec.createBufferedImage(reader.getWidth(), reader.getHeight(); ImageReadParam param = reader.getDefaultReadParam(); param.setDestination(destination); reader.read(0, param); // Image will be decoded to destination
@Test public void testGetDestinationParamGoodDestination() throws IIOException { ImageReadParam param = new ImageReadParam(); param.setDestination(new BufferedImage(21, 1, BufferedImage.TYPE_INT_ARGB)); BufferedImage destination = ImageReaderBase.getDestination(param, TYPES.iterator(), 42, 1); assertEquals(BufferedImage.TYPE_INT_ARGB, destination.getType()); assertEquals(21, destination.getWidth()); assertEquals(1, destination.getHeight()); }
@Test public void testGetDestinationParamDestinationWider() throws IIOException { ImageReadParam param = new ImageReadParam(); param.setDestination(new BufferedImage(42, 1, BufferedImage.TYPE_INT_RGB)); BufferedImage destination = ImageReaderBase.getDestination(param, TYPES.iterator(), 3, 3); assertEquals(42, destination.getWidth()); assertEquals(1, destination.getHeight()); assertEquals(BufferedImage.TYPE_INT_RGB, destination.getType()); }
public void testSetDestinationRaw() throws IOException { ImageReader reader = createReader(); TestData data = getTestData().get(0); reader.setInput(data.getInputStream()); ImageReadParam param = reader.getDefaultReadParam(); ImageTypeSpecifier type = reader.getRawImageType(0); BufferedImage destination = type.createBufferedImage(reader.getWidth(0), reader.getHeight(0)); param.setDestination(destination); BufferedImage result = reader.read(0, param); assertSame(destination, result); }