javax.imageio.metadata.IIOMetadataNode Java Examples
The following examples show how to use
javax.imageio.metadata.IIOMetadataNode.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: JFIFMarkerSegment.java From jdk1.8-source-analysis with Apache License 2.0 | 6 votes |
/** * Returns a tree of DOM nodes representing this object and any * subordinate JFXX extension or ICC Profile segments. */ IIOMetadataNode getNativeNode() { IIOMetadataNode node = new IIOMetadataNode("app0JFIF"); node.setAttribute("majorVersion", Integer.toString(majorVersion)); node.setAttribute("minorVersion", Integer.toString(minorVersion)); node.setAttribute("resUnits", Integer.toString(resUnits)); node.setAttribute("Xdensity", Integer.toString(Xdensity)); node.setAttribute("Ydensity", Integer.toString(Ydensity)); node.setAttribute("thumbWidth", Integer.toString(thumbWidth)); node.setAttribute("thumbHeight", Integer.toString(thumbHeight)); if (!extSegments.isEmpty()) { IIOMetadataNode JFXXnode = new IIOMetadataNode("JFXX"); node.appendChild(JFXXnode); for (Iterator iter = extSegments.iterator(); iter.hasNext();) { JFIFExtensionMarkerSegment seg = (JFIFExtensionMarkerSegment) iter.next(); JFXXnode.appendChild(seg.getNativeNode()); } } if (iccSegment != null) { node.appendChild(iccSegment.getNativeNode()); } return node; }
Example #2
Source File: BMPMetadata.java From dragonwell8_jdk with GNU General Public License v2.0 | 6 votes |
protected IIOMetadataNode getStandardDataNode() { IIOMetadataNode node = new IIOMetadataNode("Data"); String bits = ""; if (bitsPerPixel == 24) bits = "8 8 8 "; else if (bitsPerPixel == 16 || bitsPerPixel == 32) { bits = "" + countBits(redMask) + " " + countBits(greenMask) + countBits(blueMask) + "" + countBits(alphaMask); } IIOMetadataNode subNode = new IIOMetadataNode("BitsPerSample"); subNode.setAttribute("value", bits); node.appendChild(subNode); return node; }
Example #3
Source File: ITXtTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
private static ITXtTest readFrom(File f) { try (ImageInputStream imageInputStream = ImageIO.createImageInputStream(f)) { ImageReader r = ImageIO.getImageReaders(imageInputStream).next(); r.setInput(imageInputStream); 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); } }
Example #4
Source File: Box.java From healthcare-dicom-dicomweb-adapter with Apache License 2.0 | 6 votes |
/** Creates an <code>IIOMetadataNode</code> from this * box. The format of this node is defined in the XML dtd and xsd * for the JP2 image file. * * This method is designed for the types of boxes whose XML tree * only has 2 levels. */ protected IIOMetadataNode getNativeNodeForSimpleBox() { try { Method m = this.getClass().getMethod("getElementNames", (Class[])null); String[] elementNames = (String[])m.invoke(null, (Object[])null); IIOMetadataNode node = new IIOMetadataNode(Box.getName(getType())); setDefaultAttributes(node); for (int i = 0; i < elementNames.length; i++) { IIOMetadataNode child = new IIOMetadataNode(elementNames[i]); m = this.getClass().getMethod("get" + elementNames[i], (Class[])null); Object obj = m.invoke(this, (Object[])null); child.setUserObject(obj); child.setNodeValue(ImageUtil.convertObjectToString(obj)); node.appendChild(child); } return node; } catch (Exception e) { throw new IllegalArgumentException(I18N.getString("Box0")); } }
Example #5
Source File: SetAttributeNode.java From openjdk-8 with GNU General Public License v2.0 | 6 votes |
public static void test1() { IIOMetadataNode parent = new IIOMetadataNode("parent"); IIOMetadataNode elem = new IIOMetadataNode("elem"); MyAttrNode attrNode = new MyAttrNode("name", "value"); elem.setAttributeNode(attrNode); attrNode.setOwnerElement(elem); try { parent.setAttributeNode(attrNode); } catch (DOMException e) { if (e.code != DOMException.INUSE_ATTRIBUTE_ERR) { throw new RuntimeException("Test 1 failed: " + "Invalid exception code: " + e.code); } return; } throw new RuntimeException("Test 1 failed: DOMException not thrown"); }
Example #6
Source File: ITXtTest.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 6 votes |
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); } }
Example #7
Source File: SetAttributeNode.java From TencentKona-8 with GNU General Public License v2.0 | 6 votes |
public static void test1() { IIOMetadataNode parent = new IIOMetadataNode("parent"); IIOMetadataNode elem = new IIOMetadataNode("elem"); MyAttrNode attrNode = new MyAttrNode("name", "value"); elem.setAttributeNode(attrNode); attrNode.setOwnerElement(elem); try { parent.setAttributeNode(attrNode); } catch (DOMException e) { if (e.code != DOMException.INUSE_ATTRIBUTE_ERR) { throw new RuntimeException("Test 1 failed: " + "Invalid exception code: " + e.code); } return; } throw new RuntimeException("Test 1 failed: DOMException not thrown"); }
Example #8
Source File: SetAttributeNode.java From openjdk-8-source with GNU General Public License v2.0 | 6 votes |
public static void test1() { IIOMetadataNode parent = new IIOMetadataNode("parent"); IIOMetadataNode elem = new IIOMetadataNode("elem"); MyAttrNode attrNode = new MyAttrNode("name", "value"); elem.setAttributeNode(attrNode); attrNode.setOwnerElement(elem); try { parent.setAttributeNode(attrNode); } catch (DOMException e) { if (e.code != DOMException.INUSE_ATTRIBUTE_ERR) { throw new RuntimeException("Test 1 failed: " + "Invalid exception code: " + e.code); } return; } throw new RuntimeException("Test 1 failed: DOMException not thrown"); }
Example #9
Source File: ShortHistogramTest.java From jdk8u-jdk with GNU General Public License v2.0 | 6 votes |
private IIOMetadataNode gethISTNode(BufferedImage bi) { IndexColorModel icm = (IndexColorModel)bi.getColorModel(); int mapSize = icm.getMapSize(); int[] hist = new int[mapSize]; Arrays.fill(hist, 0); Raster r = bi.getData(); for (int y = 0; y < bi.getHeight(); y++) { for (int x = 0; x < bi.getWidth(); x++) { int s = r.getSample(x, y, 0); hist[s] ++; } } IIOMetadataNode hIST = new IIOMetadataNode("hIST"); for (int i = 0; i < hist.length; i++) { IIOMetadataNode n = new IIOMetadataNode("hISTEntry"); n.setAttribute("index", "" + i); n.setAttribute("value", "" + hist[i]); hIST.appendChild(n); } return hIST; }
Example #10
Source File: ImageBmpFile.java From MyBox with Apache License 2.0 | 6 votes |
public static IIOMetadata getWriterMeta(ImageAttributes attributes, BufferedImage image, ImageWriter writer, ImageWriteParam param) { try { BMPMetadata metaData = (BMPMetadata) writer.getDefaultImageMetadata(new ImageTypeSpecifier(image), param); if (metaData != null && !metaData.isReadOnly() && attributes != null && attributes.getDensity() > 0) { String format = metaData.getNativeMetadataFormatName(); // "com_sun_media_imageio_plugins_bmp_image_1.0" int dpm = dpi2dpm(attributes.getDensity()); // If set nodes' attributes in normal way, error will be popped about "Meta Data is read only" // By setting its fields, the class will write resolution data under standard format "javax_imageio_1.0" // but leave itself's section as empty~ Anyway, the data is record. metaData.xPixelsPerMeter = dpm; metaData.yPixelsPerMeter = dpm; metaData.palette = null; // Error will happen if not define this for Black-white bmp. IIOMetadataNode tree = (IIOMetadataNode) metaData.getAsTree(format); metaData.mergeTree(format, tree); } return metaData; } catch (Exception e) { logger.error(e.toString()); return null; } }
Example #11
Source File: BMPMetadata.java From jdk8u-jdk with GNU General Public License v2.0 | 6 votes |
protected IIOMetadataNode getStandardChromaNode() { if ((palette != null) && (paletteSize > 0)) { IIOMetadataNode node = new IIOMetadataNode("Chroma"); IIOMetadataNode subNode = new IIOMetadataNode("Palette"); int numComps = palette.length / paletteSize; subNode.setAttribute("value", "" + numComps); for (int i = 0, j = 0; i < paletteSize; i++) { IIOMetadataNode subNode1 = new IIOMetadataNode("PaletteEntry"); subNode1.setAttribute("index", ""+i); subNode1.setAttribute("red", "" + palette[j++]); subNode1.setAttribute("green", "" + palette[j++]); subNode1.setAttribute("blue", "" + palette[j++]); if (numComps == 4 && palette[j] != 0) subNode1.setAttribute("alpha", "" + palette[j++]); subNode.appendChild(subNode1); } node.appendChild(subNode); return node; } return null; }
Example #12
Source File: SetAttributeNode.java From jdk8u60 with GNU General Public License v2.0 | 6 votes |
public static void test1() { IIOMetadataNode parent = new IIOMetadataNode("parent"); IIOMetadataNode elem = new IIOMetadataNode("elem"); MyAttrNode attrNode = new MyAttrNode("name", "value"); elem.setAttributeNode(attrNode); attrNode.setOwnerElement(elem); try { parent.setAttributeNode(attrNode); } catch (DOMException e) { if (e.code != DOMException.INUSE_ATTRIBUTE_ERR) { throw new RuntimeException("Test 1 failed: " + "Invalid exception code: " + e.code); } return; } throw new RuntimeException("Test 1 failed: DOMException not thrown"); }
Example #13
Source File: ShortHistogramTest.java From dragonwell8_jdk with GNU General Public License v2.0 | 6 votes |
private IIOMetadataNode gethISTNode(BufferedImage bi) { IndexColorModel icm = (IndexColorModel)bi.getColorModel(); int mapSize = icm.getMapSize(); int[] hist = new int[mapSize]; Arrays.fill(hist, 0); Raster r = bi.getData(); for (int y = 0; y < bi.getHeight(); y++) { for (int x = 0; x < bi.getWidth(); x++) { int s = r.getSample(x, y, 0); hist[s] ++; } } IIOMetadataNode hIST = new IIOMetadataNode("hIST"); for (int i = 0; i < hist.length; i++) { IIOMetadataNode n = new IIOMetadataNode("hISTEntry"); n.setAttribute("index", "" + i); n.setAttribute("value", "" + hist[i]); hIST.appendChild(n); } return hIST; }
Example #14
Source File: BMPMetadata.java From jdk8u_jdk with GNU General Public License v2.0 | 6 votes |
protected IIOMetadataNode getStandardChromaNode() { if ((palette != null) && (paletteSize > 0)) { IIOMetadataNode node = new IIOMetadataNode("Chroma"); IIOMetadataNode subNode = new IIOMetadataNode("Palette"); int numComps = palette.length / paletteSize; subNode.setAttribute("value", "" + numComps); for (int i = 0, j = 0; i < paletteSize; i++) { IIOMetadataNode subNode1 = new IIOMetadataNode("PaletteEntry"); subNode1.setAttribute("index", ""+i); subNode1.setAttribute("red", "" + palette[j++]); subNode1.setAttribute("green", "" + palette[j++]); subNode1.setAttribute("blue", "" + palette[j++]); if (numComps == 4 && palette[j] != 0) subNode1.setAttribute("alpha", "" + palette[j++]); subNode.appendChild(subNode1); } node.appendChild(subNode); return node; } return null; }
Example #15
Source File: SetAttributeNode.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 6 votes |
public static void test1() { IIOMetadataNode parent = new IIOMetadataNode("parent"); IIOMetadataNode elem = new IIOMetadataNode("elem"); MyAttrNode attrNode = new MyAttrNode("name", "value"); elem.setAttributeNode(attrNode); attrNode.setOwnerElement(elem); try { parent.setAttributeNode(attrNode); } catch (DOMException e) { if (e.code != DOMException.INUSE_ATTRIBUTE_ERR) { throw new RuntimeException("Test 1 failed: " + "Invalid exception code: " + e.code); } return; } throw new RuntimeException("Test 1 failed: DOMException not thrown"); }
Example #16
Source File: ITXtTest.java From hottub with GNU General Public License v2.0 | 6 votes |
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); } }
Example #17
Source File: ITXtTest.java From TencentKona-8 with GNU General Public License v2.0 | 6 votes |
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); } }
Example #18
Source File: JFIFMarkerSegment.java From openjdk-jdk8u with GNU General Public License v2.0 | 6 votes |
/** * Returns a tree of DOM nodes representing this object and any * subordinate JFXX extension or ICC Profile segments. */ IIOMetadataNode getNativeNode() { IIOMetadataNode node = new IIOMetadataNode("app0JFIF"); node.setAttribute("majorVersion", Integer.toString(majorVersion)); node.setAttribute("minorVersion", Integer.toString(minorVersion)); node.setAttribute("resUnits", Integer.toString(resUnits)); node.setAttribute("Xdensity", Integer.toString(Xdensity)); node.setAttribute("Ydensity", Integer.toString(Ydensity)); node.setAttribute("thumbWidth", Integer.toString(thumbWidth)); node.setAttribute("thumbHeight", Integer.toString(thumbHeight)); if (!extSegments.isEmpty()) { IIOMetadataNode JFXXnode = new IIOMetadataNode("JFXX"); node.appendChild(JFXXnode); for (Iterator iter = extSegments.iterator(); iter.hasNext();) { JFIFExtensionMarkerSegment seg = (JFIFExtensionMarkerSegment) iter.next(); JFXXnode.appendChild(seg.getNativeNode()); } } if (iccSegment != null) { node.appendChild(iccSegment.getNativeNode()); } return node; }
Example #19
Source File: JFIFMarkerSegment.java From jdk8u60 with GNU General Public License v2.0 | 5 votes |
ICCMarkerSegment(Node node) throws IIOInvalidTreeException { super(JPEG.APP2); if (node instanceof IIOMetadataNode) { IIOMetadataNode ourNode = (IIOMetadataNode) node; ICC_Profile prof = (ICC_Profile) ourNode.getUserObject(); if (prof != null) { // May be null profile = prof.getData(); } } }
Example #20
Source File: WBMPMetadata.java From JDKSourceCode1.8 with MIT License | 5 votes |
private IIOMetadataNode addChildNode(IIOMetadataNode root, String name, Object object) { IIOMetadataNode child = new IIOMetadataNode(name); if (object != null) { child.setUserObject(object); child.setNodeValue(ImageUtil.convertObjectToString(object)); } root.appendChild(child); return child; }
Example #21
Source File: JFIFMarkerSegment.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
IIOMetadataNode getNativeNode() { IIOMetadataNode node = new IIOMetadataNode("JFIFthumbJPEG"); if (thumbMetadata != null) { node.appendChild(thumbMetadata.getNativeTree()); } return node; }
Example #22
Source File: WBMPMetadata.java From dragonwell8_jdk with GNU General Public License v2.0 | 5 votes |
private Node getNativeTree() { IIOMetadataNode root = new IIOMetadataNode(nativeMetadataFormatName); addChildNode(root, "WBMPType", new Integer(wbmpType)); addChildNode(root, "Width", new Integer(width)); addChildNode(root, "Height", new Integer(height)); return root; }
Example #23
Source File: J2KMetadata.java From healthcare-dicom-dicomweb-adapter with Apache License 2.0 | 5 votes |
private boolean insertNodeIntoTree(IIOMetadataNode root, IIOMetadataNode node) { String name = node.getNodeName(); String parent = format.getParent(name); if (parent == null) return false; IIOMetadataNode parentNode = getNodeFromTree(root, parent, name); if (parentNode == null) parentNode = createNodeIntoTree(root, parent); parentNode.appendChild(node); return true; }
Example #24
Source File: BMPMetadata.java From jdk8u60 with GNU General Public License v2.0 | 5 votes |
private IIOMetadataNode addChildNode(IIOMetadataNode root, String name, Object object) { IIOMetadataNode child = new IIOMetadataNode(name); if (object != null) { child.setUserObject(object); child.setNodeValue(ImageUtil.convertObjectToString(object)); } root.appendChild(child); return child; }
Example #25
Source File: ITXtTest.java From jdk8u60 with GNU General Public License v2.0 | 5 votes |
public IIOMetadataNode getNode() { IIOMetadataNode iTXt = new IIOMetadataNode("iTXt"); IIOMetadataNode iTXtEntry = new IIOMetadataNode("iTXtEntry"); iTXtEntry.setAttribute("keyword", keyword); iTXtEntry.setAttribute("compressionFlag", isCompressed ? "true" : "false"); iTXtEntry.setAttribute("compressionMethod", Integer.toString(compression)); iTXtEntry.setAttribute("languageTag", language); iTXtEntry.setAttribute("translatedKeyword", trasKeyword); iTXtEntry.setAttribute("text", text); iTXt.appendChild(iTXtEntry); return iTXt; }
Example #26
Source File: DHTMarkerSegment.java From dragonwell8_jdk with GNU General Public License v2.0 | 5 votes |
IIOMetadataNode getNativeNode() { IIOMetadataNode node = new IIOMetadataNode("dhtable"); node.setAttribute("class", Integer.toString(tableClass)); node.setAttribute("htableId", Integer.toString(tableID)); node.setUserObject(new JPEGHuffmanTable(numCodes, values)); return node; }
Example #27
Source File: ITXtTest.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 5 votes |
private static void writeTo(File f, ITXtTest t) { BufferedImage src = createBufferedImage(); try { ImageOutputStream imageOutputStream = ImageIO.createImageOutputStream(f); ImageTypeSpecifier imageTypeSpecifier = new ImageTypeSpecifier(src); ImageWriter imageWriter = ImageIO.getImageWritersByFormatName("PNG").next(); imageWriter.setOutput(imageOutputStream); IIOMetadata m = imageWriter.getDefaultImageMetadata(imageTypeSpecifier, null); String format = m.getNativeMetadataFormatName(); Node root = m.getAsTree(format); IIOMetadataNode iTXt = t.getNode(); root.appendChild(iTXt); m.setFromTree(format, root); imageWriter.write(new IIOImage(src, null, m)); imageOutputStream.close(); System.out.println("Writing done."); } catch (Throwable e) { throw new RuntimeException("Writing test failed.", e); } }
Example #28
Source File: BMPMetadata.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
private IIOMetadataNode addChildNode(IIOMetadataNode root, String name, Object object) { IIOMetadataNode child = new IIOMetadataNode(name); if (object != null) { child.setUserObject(object); child.setNodeValue(ImageUtil.convertObjectToString(object)); } root.appendChild(child); return child; }
Example #29
Source File: COMMarkerSegment.java From dragonwell8_jdk with GNU General Public License v2.0 | 5 votes |
/** * Returns an <code>IIOMetadataNode</code> containing the data array * as a user object and a string encoded using ISO-8895-1, as an * attribute. */ IIOMetadataNode getNativeNode() { IIOMetadataNode node = new IIOMetadataNode("com"); node.setAttribute("comment", getComment()); if (data != null) { node.setUserObject(data.clone()); } return node; }
Example #30
Source File: ITXtTest.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
public IIOMetadataNode getNode() { IIOMetadataNode iTXt = new IIOMetadataNode("iTXt"); IIOMetadataNode iTXtEntry = new IIOMetadataNode("iTXtEntry"); iTXtEntry.setAttribute("keyword", keyword); iTXtEntry.setAttribute("compressionFlag", isCompressed ? "true" : "false"); iTXtEntry.setAttribute("compressionMethod", Integer.toString(compression)); iTXtEntry.setAttribute("languageTag", language); iTXtEntry.setAttribute("translatedKeyword", trasKeyword); iTXtEntry.setAttribute("text", text); iTXt.appendChild(iTXtEntry); return iTXt; }