public static synchronized J2KMetadataFormat getInstance() { if (instance == null) instance = new J2KMetadataFormat(); return instance; }
/** Constructs <code>J2KMetadataFormat</code>. Calls the super * class constructor. Sets the resource base name. Adds the elements * into this format object based on the XML schema and DTD. */ J2KMetadataFormat() { super("com_sun_media_imageio_plugins_jpeg2000_image_1.0", CHILD_POLICY_ALL); setResourceBaseName(resourceBaseName); addElements(); }
addElement("JPEG2000SignatureBox", getParent("JPEG2000SignatureBox"), CHILD_POLICY_EMPTY); addElement("JPEG2000FileTypeBox", getParent("JPEG2000FileTypeBox"), CHILD_POLICY_ALL); addElement("OtherBoxes", getParent("OtherBoxes"), CHILD_POLICY_CHOICE); addElement("JPEG2000HeaderSuperBox", getParent("JPEG2000HeaderSuperBox"), CHILD_POLICY_CHOICE); addElement("JPEG2000CodeStreamBox", getParent("JPEG2000CodeStreamBox"), CHILD_POLICY_EMPTY); addElement("JPEG2000IntellectualPropertyRightsBox", getParent("JPEG2000IntellectualPropertyRightsBox"), CHILD_POLICY_ALL); addElement("JPEG2000XMLBox", getParent("JPEG2000XMLBox"), CHILD_POLICY_ALL); addElement("JPEG2000UUIDBox", getParent("JPEG2000UUIDBox"), CHILD_POLICY_ALL); addElement("JPEG2000UUIDInfoBox", getParent("JPEG2000UUIDInfoBox"), CHILD_POLICY_ALL);
private void mergeNativeTree(Node root) throws IIOInvalidTreeException { NodeList list = root.getChildNodes(); for (int i = list.getLength() - 1; i >= 0; i--) { Node node = list.item(i); String name = node.getNodeName(); if (format.getParent(name) != null) { if (format.isLeaf(name)) { String s = (String)Box.getAttribute(node, "Type"); Box box = Box.createBox(Box.getTypeInt(s), node); if (format.singleInstance(name)&&getElement(name) != null) { replace(name, box); } else boxes.add(box); } else { mergeNativeTree(node); } } } }
public boolean canNodeAppear(String elementName, ImageTypeSpecifier imageType) { ColorModel cm = imageType.getColorModel(); if (!(cm instanceof IndexColorModel)) if ("JPEG2000PaletteBox".equals(elementName)) return false; if (!cm.hasAlpha()) if ("JPEG2000ChannelDefinitionBox".equals(elementName)) return false; if (getParent(elementName) != null) return true; return false; }
private int computeLength(IIOMetadataNode root) { NodeList list = root.getChildNodes(); int length = 0; for (int i = 0; i < list.getLength(); i++) { IIOMetadataNode node = (IIOMetadataNode)list.item(i); String name = node.getNodeName(); if (format.isLeaf(name)) length += new Integer((String)Box.getAttribute(node, "Length")).intValue(); else length += computeLength(node); } return length + (root.getNodeName().startsWith("JPEG2000") ? 8 : 0) ; }
private IIOMetadataNode createNodeIntoTree(IIOMetadataNode root, String name) { IIOMetadataNode node = getNodeFromTree(root, name, null); if (node != null) return node; node = new IIOMetadataNode(name); String parent = format.getParent(name); IIOMetadataNode parentNode = createNodeIntoTree(root, parent); parentNode.appendChild(node); return node; }
private void writeSuperBox(IIOMetadataNode node) throws IOException { NodeList list = node.getChildNodes(); String name = node.getNodeName(); if (name.startsWith("JPEG2000")) { stream.writeInt(computeLength(node)); stream.writeInt(Box.getTypeInt((String)Box.getTypeByName(name))); otherLength += 8; } for (int i = 0; i < list.getLength(); i++) { IIOMetadataNode child = (IIOMetadataNode)list.item(i); name = child.getNodeName(); if (name.startsWith("JPEG2000") && format.isLeaf(name)) writeBox(child); else writeSuperBox(child); } }
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; }