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;
}
use of javax.imageio.ImageWriteParam in project jdk8u_jdk by JetBrains.
the class GIFImageWriteParam method computeRegions.
/**
* Compute the source region and destination dimensions taking any
* parameter settings into account.
*/
private static void computeRegions(Rectangle sourceBounds, Dimension destSize, ImageWriteParam p) {
ImageWriteParam param;
int periodX = 1;
int periodY = 1;
if (p != null) {
int[] sourceBands = p.getSourceBands();
if (sourceBands != null && (sourceBands.length != 1 || sourceBands[0] != 0)) {
throw new IllegalArgumentException("Cannot sub-band image!");
}
// Get source region and subsampling factors
Rectangle sourceRegion = p.getSourceRegion();
if (sourceRegion != null) {
// Clip to actual image bounds
sourceRegion = sourceRegion.intersection(sourceBounds);
sourceBounds.setBounds(sourceRegion);
}
// Adjust for subsampling offsets
int gridX = p.getSubsamplingXOffset();
int gridY = p.getSubsamplingYOffset();
sourceBounds.x += gridX;
sourceBounds.y += gridY;
sourceBounds.width -= gridX;
sourceBounds.height -= gridY;
// Get subsampling factors
periodX = p.getSourceXSubsampling();
periodY = p.getSourceYSubsampling();
}
// Compute output dimensions
destSize.setSize((sourceBounds.width + periodX - 1) / periodX, (sourceBounds.height + periodY - 1) / periodY);
if (destSize.width <= 0 || destSize.height <= 0) {
throw new IllegalArgumentException("Empty source region!");
}
}
use of javax.imageio.ImageWriteParam in project jdk8u_jdk by JetBrains.
the class ImageWriteParamMisc method test4434870.
private static void test4434870() {
ImageWriteParam iwp = new ImageWriteParam4434870();
try {
Dimension[] dimensions = iwp.getPreferredTileSizes();
iwp.setTilingMode(ImageWriteParam.MODE_EXPLICIT);
iwp.setTiling(100, 100, 0, 0);
throw new RuntimeException("Failed to get IAE!");
} catch (IllegalArgumentException e) {
}
}
use of javax.imageio.ImageWriteParam in project jdk8u_jdk by JetBrains.
the class UshortOutOfMemoryTest method testGetAsTree.
public void testGetAsTree() {
ImageWriteParam p = w.getDefaultWriteParam();
IIOMetadata m = w.getDefaultImageMetadata(ImageTypeSpecifier.createFromBufferedImageType(type), p);
String format = m.getNativeMetadataFormatName();
System.out.println("native format: " + format);
int count = 0;
try {
while (count < 100) {
System.out.println(" test " + count++);
m.getAsTree(format);
}
} catch (OutOfMemoryError e) {
System.gc();
throw new RuntimeException("Test failed. Number of performed operations: " + count, e);
}
}
Aggregations