use of it.geosolutions.imageio.plugins.png.PNGWriter in project imageio-ext by geosolutions-it.
the class CustomUShortImageTypesTest method testCustomUShortImage.
@Test
public void testCustomUShortImage() throws Exception {
BufferedImage bi = ImageTypeSpecifier.createGrayscale(nbits, DataBuffer.TYPE_USHORT, false).createBufferedImage(size, size);
Graphics2D graphics = bi.createGraphics();
graphics.setColor(Color.BLACK);
graphics.fillRect(0, 0, 16, 32);
graphics.setColor(Color.WHITE);
graphics.fillRect(16, 0, 16, 32);
graphics.dispose();
ByteArrayOutputStream bos = new ByteArrayOutputStream();
float quality = 5f / 9 - 1;
new PNGWriter().writePNG(bi, bos, -quality, FilterType.FILTER_NONE);
BufferedImage read = ImageIO.read(new ByteArrayInputStream(bos.toByteArray()));
ImageAssert.assertImagesEqual(bi, read);
// now using imagewriter interface
ImageWriter writer = new PNGImageWriterSPI().createWriterInstance();
writer.setOutput(bos);
ImageWriteParam wp = writer.getDefaultWriteParam();
wp.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
wp.setCompressionQuality(-quality);
writer.write(null, new IIOImage(bi, null, null), wp);
writer.dispose();
ImageAssert.assertImagesEqual(bi, ImageIO.read(new ByteArrayInputStream(bos.toByteArray())));
}
use of it.geosolutions.imageio.plugins.png.PNGWriter in project imageio-ext by geosolutions-it.
the class PngSuiteImagesTest method roundTripPNGJ.
private void roundTripPNGJ(BufferedImage original, RenderedImage source) throws Exception {
// write the PNG
ByteArrayOutputStream bos = new ByteArrayOutputStream();
float quality = 4f / 9 - 1;
new PNGWriter().writePNG(original, bos, -quality, FilterType.FILTER_NONE);
// write the output to file for eventual visual comparison
byte[] bytes = bos.toByteArray();
writeToFile(new File("./target/roundTripNone", sourceFile.getName()), bytes);
// read it back
ByteArrayInputStream bis = new ByteArrayInputStream(bytes);
BufferedImage image = ImageIO.read(bis);
ImageAssert.assertImagesEqual(original, image);
// now using imagewriter interface
ImageWriter writer = new PNGImageWriterSPI().createWriterInstance();
writer.setOutput(bos);
ImageWriteParam wp = writer.getDefaultWriteParam();
wp.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
wp.setCompressionQuality(-quality);
writer.write(null, new IIOImage(original, null, null), wp);
writer.dispose();
ImageAssert.assertImagesEqual(original, ImageIO.read(new ByteArrayInputStream(bos.toByteArray())));
}
use of it.geosolutions.imageio.plugins.png.PNGWriter in project imageio-ext by geosolutions-it.
the class BufferedImageTypesTest method compareImage.
@Test
public void compareImage() throws Exception {
ByteArrayOutputStream bos = new ByteArrayOutputStream();
float quality = 4f / 9 - 1;
new PNGWriter().writePNG(image, bos, -quality, FilterType.FILTER_NONE);
ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray());
BufferedImage readBack = ImageIO.read(bis);
boolean success = false;
try {
ImageAssert.assertImagesEqual(image, readBack);
success = true;
} finally {
if (!success) {
ImageIO.write(image, "PNG", new File("./target/" + name + "_expected.png"));
ImageIO.write(readBack, "PNG", new File("./target/" + name + "_actual.png"));
}
}
// now using imagewriter interface
ImageWriter writer = new PNGImageWriterSPI().createWriterInstance();
writer.setOutput(bos);
ImageWriteParam wp = writer.getDefaultWriteParam();
wp.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
wp.setCompressionQuality(-quality);
writer.write(null, new IIOImage(image, null, null), wp);
writer.dispose();
bis = new ByteArrayInputStream(bos.toByteArray());
readBack = ImageIO.read(bis);
success = false;
try {
ImageAssert.assertImagesEqual(image, readBack);
success = true;
} finally {
if (!success) {
ImageIO.write(image, "PNG", new File("./target/" + name + "_expected.png"));
ImageIO.write(readBack, "PNG", new File("./target/" + name + "_actual.png"));
}
}
}
Aggregations