use of javax.imageio.ImageTypeSpecifier in project jdk8u_jdk by JetBrains.
the class AnimationTest method main.
public static void main(String[] args) {
try {
AnimationTest t = new AnimationTest();
t.initFrame();
ImageWriter w = t.initWriter();
ImageWriteParam p = w.getDefaultWriteParam();
IIOMetadata streamMetadata = w.getDefaultStreamMetadata(p);
w.prepareWriteSequence(streamMetadata);
for (int i = 0; i < 50; i++) {
BufferedImage f = t.createNextFrame();
ImageTypeSpecifier type = new ImageTypeSpecifier(f);
IIOMetadata m = w.getDefaultImageMetadata(type, p);
w.writeToSequence(new IIOImage(f, null, m), p);
}
w.endWriteSequence();
t.checkAnimation();
} catch (Exception e) {
throw new RuntimeException("Test failed.", e);
}
}
use of javax.imageio.ImageTypeSpecifier 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.ImageTypeSpecifier in project jdk8u_jdk by JetBrains.
the class CanEncodeShort method main.
public static void main(String[] args) {
for (int i = 0; i < types.length; i++) {
BufferedImage img = new BufferedImage(32, 32, types[i]);
ImageTypeSpecifier spec = ImageTypeSpecifier.createFromRenderedImage(img);
Iterator writers = ImageIO.getImageWriters(spec, "png");
if (!writers.hasNext()) {
throw new RuntimeException("Test failed: " + "no PNG writer found for type " + typeNames[i]);
}
}
}
use of javax.imageio.ImageTypeSpecifier in project jdk8u_jdk by JetBrains.
the class ReadAsGrayTest method doTest.
private static void doTest(int type) throws IOException {
BufferedImage src = createTestImage(type);
File f = new File("test.jpg");
if (!ImageIO.write(src, "jpg", f)) {
throw new RuntimeException("Failed to write test image.");
}
ImageInputStream iis = ImageIO.createImageInputStream(f);
ImageReader reader = ImageIO.getImageReaders(iis).next();
reader.setInput(iis);
Iterator<ImageTypeSpecifier> types = reader.getImageTypes(0);
ImageTypeSpecifier srgb = null;
ImageTypeSpecifier gray = null;
// look for gray and srgb types
while ((srgb == null || gray == null) && types.hasNext()) {
ImageTypeSpecifier t = types.next();
if (t.getColorModel().getColorSpace().getType() == TYPE_GRAY) {
gray = t;
}
if (t.getColorModel().getColorSpace() == sRGB) {
srgb = t;
}
}
if (gray == null) {
throw new RuntimeException("No gray type available.");
}
if (srgb == null) {
throw new RuntimeException("No srgb type available.");
}
System.out.println("Read as GRAY...");
testType(reader, gray, src);
System.out.println("Read as sRGB...");
testType(reader, srgb, src);
}
use of javax.imageio.ImageTypeSpecifier in project jdk8u_jdk by JetBrains.
the class UshortGrayTest method main.
public static void main(String[] args) {
Iterator iter;
BufferedImage bi = new BufferedImage(10, 10, BufferedImage.TYPE_USHORT_GRAY);
// Part 1: ensure that JPEGImageWriter throws an exception if it
// encounters an image with 16-bit samples
ImageWriter writer = null;
iter = ImageIO.getImageWritersByFormatName("jpeg");
if (iter.hasNext()) {
writer = (ImageWriter) iter.next();
} else {
throw new RuntimeException("No JPEG reader found");
}
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ImageOutputStream ios = null;
boolean exceptionThrown = false;
try {
ios = ImageIO.createImageOutputStream(baos);
} catch (IOException ioe) {
throw new RuntimeException("Could not create ImageOutputStream");
}
try {
writer.setOutput(ios);
writer.write(bi);
} catch (IOException ioe) {
exceptionThrown = true;
}
if (!exceptionThrown) {
throw new RuntimeException("JPEG writer should not be able to " + "write USHORT_GRAY images");
}
// Part 2: ensure that JPEGImageWriterSpi.canEncodeImage() returns
// false for images with 16-bit samples
ImageTypeSpecifier its = ImageTypeSpecifier.createFromRenderedImage(bi);
iter = ImageIO.getImageWriters(its, "jpeg");
if (iter.hasNext()) {
throw new RuntimeException("JPEG writer should not be available" + " for USHORT_GRAY images");
}
}
Aggregations