use of javax.imageio.ImageWriteParam in project jdk8u_jdk by JetBrains.
the class DisableCompressionTest method testFormat.
protected static void testFormat(String format) {
ImageWriter writer = ImageIO.getImageWritersByFormatName(format).next();
if (writer == null) {
throw new RuntimeException("No writer for " + format);
}
ImageWriteParam param = writer.getDefaultWriteParam();
int[] supported_modes = new int[] { ImageWriteParam.MODE_COPY_FROM_METADATA, ImageWriteParam.MODE_DEFAULT, ImageWriteParam.MODE_EXPLICIT };
for (int mode : supported_modes) {
String mode_name = getModeName(mode);
System.out.println("Test mode " + mode_name + "...");
// we know that GIF image writer supports compression
// and supports any compression mode form supportd_modes
// If exception would be thrown here then test failed.
param.setCompressionMode(mode);
// now we are trying to disable compression.
// This operation is not supported because GIF image writer
// does not provide uncompressed output.
// The expected behaviour is that UnsupportedOperationException
// will be thrown here and current compression mode will not be
// changed.
boolean gotException = false;
try {
param.setCompressionMode(ImageWriteParam.MODE_DISABLED);
} catch (UnsupportedOperationException e) {
gotException = true;
} catch (Throwable e) {
throw new RuntimeException("Test failed due to unexpected exception", e);
}
if (!gotException) {
throw new RuntimeException("Test failed.");
}
if (param.getCompressionMode() != mode) {
throw new RuntimeException("Param state was changed.");
}
System.out.println("Test passed.");
}
}
use of javax.imageio.ImageWriteParam in project jdk8u_jdk by JetBrains.
the class EmbeddedFormatTest method doTest.
public void doTest(String compression, int bi_type) throws IOException {
System.out.println("Test " + compression + " on " + getImageTypeName(bi_type));
BufferedImage src = createTestImage(bi_type);
writer.reset();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ImageOutputStream ios = ImageIO.createImageOutputStream(baos);
writer.setOutput(ios);
ImageWriteParam wparam = prepareWriteParam(compression);
writer.write(null, new IIOImage(src, null, null), wparam);
ios.flush();
ios.close();
// read result
ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
ImageInputStream iis = ImageIO.createImageInputStream(bais);
reader.reset();
reader.setInput(iis);
BufferedImage dst = reader.read(0);
checkResult(dst);
}
use of javax.imageio.ImageWriteParam in project jdk8u_jdk by JetBrains.
the class TestCompressionBI_BITFIELDS method prepareWriteParam.
protected ImageWriteParam prepareWriteParam(BufferedImage src) {
ImageWriteParam wparam = writer.getDefaultWriteParam();
wparam.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
wparam.setCompressionType("BI_BITFIELDS");
return wparam;
}
use of javax.imageio.ImageWriteParam in project jdk8u_jdk by JetBrains.
the class RasterWithMinXTest method main.
public static void main(String[] args) {
String format = "jpeg";
// Set output file.
ImageOutputStream output = new MemoryCacheImageOutputStream(new ByteArrayOutputStream());
// Create image.
BufferedImage bi = new BufferedImage(256, 256, BufferedImage.TYPE_3BYTE_BGR);
// Populate image.
int[] rgbArray = new int[256];
for (int i = 0; i < 256; i++) {
Arrays.fill(rgbArray, i);
bi.setRGB(0, i, 256, 1, rgbArray, 0, 256);
}
// create translated raster in order to get non-zero minX and minY
WritableRaster r = (WritableRaster) bi.getRaster().createTranslatedChild(64, 64);
Iterator i = ImageIO.getImageWritersByFormatName(format);
ImageWriter iw = null;
while (i.hasNext() && iw == null) {
Object o = i.next();
if (o instanceof com.sun.imageio.plugins.jpeg.JPEGImageWriter) {
iw = (ImageWriter) o;
}
}
if (iw == null) {
throw new RuntimeException("No available image writer");
}
ImageWriteParam iwp = iw.getDefaultWriteParam();
IIOMetadata metadata = iw.getDefaultImageMetadata(new ImageTypeSpecifier(bi.getColorModel(), r.getSampleModel()), iwp);
IIOImage img = new IIOImage(r, null, metadata);
iw.setOutput(output);
try {
iw.write(img);
} catch (RasterFormatException e) {
e.printStackTrace();
throw new RuntimeException("RasterException occurs. Test Failed!");
} catch (Exception ex) {
ex.printStackTrace();
throw new RuntimeException("Unexpected Exception");
}
// test case of theImageWriteParam with non-null sourceRegion
iwp.setSourceRegion(new Rectangle(32, 32, 192, 192));
metadata = iw.getDefaultImageMetadata(new ImageTypeSpecifier(bi.getColorModel(), r.getSampleModel()), iwp);
try {
iw.write(metadata, img, iwp);
} catch (RasterFormatException e) {
e.printStackTrace();
throw new RuntimeException("SetSourceRegion causes the RasterException. Test Failed!");
} catch (Exception ex) {
ex.printStackTrace();
throw new RuntimeException("Unexpected Exception");
}
}
use of javax.imageio.ImageWriteParam in project jdk8u_jdk by JetBrains.
the class DestTypeTest method getWriteParam.
public ImageWriteParam getWriteParam() {
ImageWriteParam p = w.getDefaultWriteParam();
p.setSourceBands(new int[] { 0, 1, 2 });
ImageTypeSpecifier type = ImageTypeSpecifier.createFromBufferedImageType(BufferedImage.TYPE_INT_RGB);
p.setDestinationType(type);
return p;
}
Aggregations