use of javax.imageio.ImageWriteParam in project jdk8u_jdk by JetBrains.
the class ImageWriteParamMisc method test4434886.
private static void test4434886() {
ImageWriteParam iwp = new ImageWriteParam4434886();
iwp.setTilingMode(ImageWriteParam.MODE_EXPLICIT);
try {
iwp.setTiling(-1, -2, -3, -4);
throw new RuntimeException("Failed to get IAE!");
} catch (IllegalArgumentException e) {
}
}
use of javax.imageio.ImageWriteParam in project jdk8u_jdk by JetBrains.
the class BMPSubsamplingTest method getImageWriteParam.
private ImageWriteParam getImageWriteParam(ImageWriter writer, String value) {
ImageWriteParam imageWriteParam = writer.getDefaultWriteParam();
imageWriteParam.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
imageWriteParam.setCompressionType(value);
return imageWriteParam;
}
use of javax.imageio.ImageWriteParam in project jdk8u_jdk by JetBrains.
the class BMPWriteParamTest method getWriteResult.
private static BufferedImage getWriteResult(BufferedImage img, String format) throws IOException {
ImageWriter iw = null;
Iterator writers = ImageIO.getImageWritersByFormatName(format);
while (writers.hasNext()) {
iw = (ImageWriter) writers.next();
System.out.println(format + " -> " + iw.toString());
}
if (iw == null) {
throw new RuntimeException("No available Image writer for " + format);
}
ImageWriteParam param = iw.getDefaultWriteParam();
param.setSourceRegion(new Rectangle(10, 10, 31, 31));
param.setSourceSubsampling(3, 3, 0, 0);
IIOMetadata meta = iw.getDefaultImageMetadata(new ImageTypeSpecifier(img), param);
IIOImage iio_img = new IIOImage(img, null, meta);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ImageOutputStream ios = ImageIO.createImageOutputStream(baos);
iw.setOutput(ios);
iw.write(meta, iio_img, param);
ios.flush();
byte[] ba_image = baos.toByteArray();
ByteArrayInputStream bais = new ByteArrayInputStream(ba_image);
ImageReader ir = null;
Iterator readers = ImageIO.getImageReadersByFormatName(format);
while (readers.hasNext()) {
ir = (ImageReader) readers.next();
System.out.println(format + " -> " + ir.toString());
}
if (ir == null) {
throw new RuntimeException("No available Image reader for " + format);
}
ir.setInput(ImageIO.createImageInputStream(bais));
BufferedImage res = ir.read(0);
return res;
}
use of javax.imageio.ImageWriteParam in project jdk8u_jdk by JetBrains.
the class RleEncodingTest method doTest.
private static void doTest(BufferedImage src, String compressionType, int compressionMode) throws IOException {
ImageWriter iw = (ImageWriter) ImageIO.getImageWritersBySuffix("bmp").next();
if (iw == null) {
throw new RuntimeException("No available writer. Test failed.");
}
IIOImage iioImg = new IIOImage(src, null, null);
ImageWriteParam param = iw.getDefaultWriteParam();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ImageOutputStream ios = ImageIO.createImageOutputStream(baos);
iw.setOutput(ios);
System.out.println("Compression Type is " + compressionType);
System.out.println("Compression Mode is " + compressionMode);
param.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
param.setCompressionType(compressionType);
if (compressionMode != ImageWriteParam.MODE_EXPLICIT) {
param.setCompressionMode(compressionMode);
}
try {
iw.write(null, iioImg, param);
} catch (IOException e) {
int bpp = src.getColorModel().getPixelSize();
if (compressionMode == ImageWriteParam.MODE_EXPLICIT) {
if ((compressionType.equals("BI_RLE4") && bpp != 4) || (compressionType.equals("BI_RLE8") && bpp != 8)) {
System.out.println("Can not encode " + bpp + "bpp image as" + compressionType);
return;
} else {
throw new RuntimeException("Unable to encode " + bpp + "bpp image as " + compressionType + ". Test failed");
}
}
}
baos.close();
ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
ImageInputStream iis = ImageIO.createImageInputStream(bais);
BufferedImage dst = ImageIO.read(iis);
int w = src.getWidth();
int h = src.getHeight();
Object dstPixel = dst.getRaster().getDataElements(w / 2, h / 2, null);
Object srcPixel = src.getRaster().getDataElements(w / 2, h / 2, null);
if ((src.getColorModel().getRed(srcPixel) != dst.getColorModel().getRed(dstPixel)) || (src.getColorModel().getGreen(srcPixel) != dst.getColorModel().getGreen(dstPixel)) || (src.getColorModel().getBlue(srcPixel) != dst.getColorModel().getBlue(dstPixel)) || (src.getColorModel().getAlpha(srcPixel) != dst.getColorModel().getAlpha(dstPixel))) {
showPixel(src, w / 2, h / 2);
showPixel(dst, w / 2, h / 2);
throw new RuntimeException("Colors are different: " + Integer.toHexString(src.getColorModel().getRGB(srcPixel)) + " and " + Integer.toHexString(dst.getColorModel().getRGB(dstPixel)));
}
}
use of javax.imageio.ImageWriteParam in project jdk8u_jdk by JetBrains.
the class TestCompressionBI_BITFIELDS method writeAndRead.
public BufferedImage writeAndRead(BufferedImage src) throws IOException {
writer.reset();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
writer.setOutput(ImageIO.createImageOutputStream(baos));
ImageWriteParam wparam = prepareWriteParam(src);
IIOImage img = new IIOImage(src, null, null);
writer.write(null, img, wparam);
if (doSave) {
// save images to file in order to be able to check
// that image is well-formed using standard windows tools.
File f = File.createTempFile("wr_test_", "." + format, new File("."));
System.out.println("Save to file: " + f.getCanonicalPath());
FileOutputStream fos = new FileOutputStream(f);
fos.write(baos.toByteArray());
fos.flush();
fos.close();
}
// read result
reader.reset();
ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
reader.setInput(ImageIO.createImageInputStream(bais));
return reader.read(0);
}
Aggregations