Search in sources :

Example 51 with IIOMetadata

use of javax.imageio.metadata.IIOMetadata in project jdk8u_jdk by JetBrains.

the class ITXtTest method readFrom.

private static ITXtTest readFrom(File f) {
    try {
        ImageInputStream iis = ImageIO.createImageInputStream(f);
        ImageReader r = ImageIO.getImageReaders(iis).next();
        r.setInput(iis);
        IIOImage dst = r.readAll(0, null);
        // look for iTXt node
        IIOMetadata m = dst.getMetadata();
        Node root = m.getAsTree(m.getNativeMetadataFormatName());
        Node n = root.getFirstChild();
        while (n != null && !"iTXt".equals(n.getNodeName())) {
            n = n.getNextSibling();
        }
        if (n == null) {
            throw new RuntimeException("No iTXt node!");
        }
        ITXtTest t = ITXtTest.getFromNode((IIOMetadataNode) n);
        return t;
    } catch (Throwable e) {
        throw new RuntimeException("Reading test failed.", e);
    }
}
Also used : IIOMetadata(javax.imageio.metadata.IIOMetadata) ImageInputStream(javax.imageio.stream.ImageInputStream) IIOMetadataNode(javax.imageio.metadata.IIOMetadataNode) Node(org.w3c.dom.Node) ImageReader(javax.imageio.ImageReader) IIOImage(javax.imageio.IIOImage)

Example 52 with IIOMetadata

use of javax.imageio.metadata.IIOMetadata in project jdk8u_jdk by JetBrains.

the class MergeStdCommentTest method main.

public static void main(String[] args) throws Exception {
    String format = "javax_imageio_1.0";
    BufferedImage img = new BufferedImage(16, 16, BufferedImage.TYPE_INT_RGB);
    ImageWriter iw = ImageIO.getImageWritersByMIMEType("image/png").next();
    IIOMetadata meta = iw.getDefaultImageMetadata(new ImageTypeSpecifier(img), null);
    DOMImplementationRegistry registry;
    registry = DOMImplementationRegistry.newInstance();
    DOMImplementation impl = registry.getDOMImplementation("XML 3.0");
    Document doc = impl.createDocument(null, format, null);
    Element root, text, entry;
    root = doc.getDocumentElement();
    root.appendChild(text = doc.createElement("Text"));
    text.appendChild(entry = doc.createElement("TextEntry"));
    // keyword isn't #REQUIRED by the standard metadata format.
    // However, it is required by the PNG format, so we include it here.
    entry.setAttribute("keyword", "Comment");
    entry.setAttribute("value", "Some demo comment");
    meta.mergeTree(format, root);
}
Also used : IIOMetadata(javax.imageio.metadata.IIOMetadata) Element(org.w3c.dom.Element) ImageWriter(javax.imageio.ImageWriter) DOMImplementationRegistry(org.w3c.dom.bootstrap.DOMImplementationRegistry) DOMImplementation(org.w3c.dom.DOMImplementation) Document(org.w3c.dom.Document) BufferedImage(java.awt.image.BufferedImage) ImageTypeSpecifier(javax.imageio.ImageTypeSpecifier)

Example 53 with IIOMetadata

use of javax.imageio.metadata.IIOMetadata in project jdk8u_jdk by JetBrains.

the class BMPPluginTest method test.

public boolean test() throws IIOException, IOException {
    ir.reset();
    iw.reset();
    String[] suffixes = iw.getOriginatingProvider().getFileSuffixes();
    IIOMetadata md = iw.getDefaultImageMetadata(new ImageTypeSpecifier(img), param);
    System.out.println("Image type " + img.getType());
    ImageWriterSpi spi = iw.getOriginatingProvider();
    boolean bCanEncode = spi.canEncodeImage(img);
    System.out.println("Can encode image? " + (bCanEncode ? "YES" : "NO"));
    if (!bCanEncode) {
        return true;
    }
    IIOImage iio_img = new IIOImage(img, null, md);
    String fname = "test" + img.getType() + "." + suffixes[0];
    iw.setOutput(ImageIO.createImageOutputStream(new FileOutputStream(new File(fname))));
    System.out.print("write image ... ");
    iw.write(iio_img);
    System.out.println("OK");
    System.out.print("read image ... ");
    byte[] ba_image = baos.toByteArray();
    ByteArrayInputStream bais = new ByteArrayInputStream(ba_image);
    ir.setInput(ImageIO.createImageInputStream(new FileInputStream(new File(fname))));
    BufferedImage res = ir.read(0);
    System.out.println("OK");
    System.out.print("compare images ... ");
    boolean r = compare(img, res);
    System.out.println(r ? "OK" : "FAILED");
    return r;
}
Also used : ImageTypeSpecifier(javax.imageio.ImageTypeSpecifier) FileInputStream(java.io.FileInputStream) BufferedImage(java.awt.image.BufferedImage) IIOImage(javax.imageio.IIOImage) IIOMetadata(javax.imageio.metadata.IIOMetadata) ByteArrayInputStream(java.io.ByteArrayInputStream) FileOutputStream(java.io.FileOutputStream) ImageWriterSpi(javax.imageio.spi.ImageWriterSpi) File(java.io.File)

Example 54 with IIOMetadata

use of javax.imageio.metadata.IIOMetadata 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);
    }
}
Also used : IIOMetadata(javax.imageio.metadata.IIOMetadata) ImageWriteParam(javax.imageio.ImageWriteParam)

Example 55 with IIOMetadata

use of javax.imageio.metadata.IIOMetadata in project jdk8u_jdk by JetBrains.

the class WBMPPluginTest method test.

public boolean test() throws IIOException, IOException {
    ir.reset();
    iw.reset();
    String[] suffixes = iw.getOriginatingProvider().getFileSuffixes();
    IIOMetadata md = iw.getDefaultImageMetadata(new ImageTypeSpecifier(img), param);
    IIOImage iio_img = new IIOImage(img, null, md);
    System.out.println("Image type " + img.getType());
    String fname = "test" + img.getType() + "." + suffixes[0];
    iw.setOutput(ImageIO.createImageOutputStream(new FileOutputStream(new File(fname))));
    System.out.print("write image ... ");
    iw.write(iio_img);
    System.out.println("OK");
    System.out.print("read image ... ");
    byte[] ba_image = baos.toByteArray();
    ByteArrayInputStream bais = new ByteArrayInputStream(ba_image);
    ir.setInput(ImageIO.createImageInputStream(new FileInputStream(new File(fname))));
    BufferedImage res = ir.read(0);
    System.out.println("OK");
    System.out.print("compare images ... ");
    boolean r = compare(img, res);
    System.out.println(r ? "OK" : "FAILED");
    return r;
}
Also used : IIOMetadata(javax.imageio.metadata.IIOMetadata) ByteArrayInputStream(java.io.ByteArrayInputStream) FileOutputStream(java.io.FileOutputStream) File(java.io.File) ImageTypeSpecifier(javax.imageio.ImageTypeSpecifier) FileInputStream(java.io.FileInputStream) BufferedImage(java.awt.image.BufferedImage) IIOImage(javax.imageio.IIOImage)

Aggregations

IIOMetadata (javax.imageio.metadata.IIOMetadata)81 BufferedImage (java.awt.image.BufferedImage)36 ImageWriter (javax.imageio.ImageWriter)35 ImageTypeSpecifier (javax.imageio.ImageTypeSpecifier)32 IIOImage (javax.imageio.IIOImage)30 ImageOutputStream (javax.imageio.stream.ImageOutputStream)30 File (java.io.File)27 ImageWriteParam (javax.imageio.ImageWriteParam)22 Node (org.w3c.dom.Node)22 IOException (java.io.IOException)20 ImageReader (javax.imageio.ImageReader)19 IIOMetadataNode (javax.imageio.metadata.IIOMetadataNode)17 Rectangle (java.awt.Rectangle)13 NodeList (org.w3c.dom.NodeList)13 Point (java.awt.Point)11 ByteArrayOutputStream (java.io.ByteArrayOutputStream)11 ByteArrayInputStream (java.io.ByteArrayInputStream)10 ImageInputStream (javax.imageio.stream.ImageInputStream)10 Test (org.junit.Test)9 ColorModel (java.awt.image.ColorModel)7