/** Creates a <code>Box</code> object with the provided <code>type</code> * based on the provided Node object based on reflection. */ public static Box createBox(int type, Node node) throws IIOInvalidTreeException { Class boxClass = (Class)boxClasses.get(new Integer(type)); try { // gets the constructor with <code>Node</code parameter Constructor cons = boxClass.getConstructor(new Class[] {Node.class}); if (cons != null) { return (Box)cons.newInstance(new Object[]{node}); } } catch(NoSuchMethodException e) { // If exception throws, create a <code>Box</code> instance. e.printStackTrace(); return new Box(node); } catch(InvocationTargetException e) { e.printStackTrace(); return new Box(node); } catch (IllegalAccessException e) { e.printStackTrace(); return new Box(node); } catch (InstantiationException e) { e.printStackTrace(); return new Box(node); } return null; }
/** Returns the box content in byte array. */ public byte[] getContent() { if (data == null) compose(); return data; }
private void writeBox(IIOMetadataNode node) throws IOException { int type = Box.getTypeInt((String)Box.getAttribute(node, "Type")); int length = new Integer((String)Box.getAttribute(node, "Length")).intValue(); Box box = Box.createBox(type, node); otherLength += length; stream.writeInt(length); stream.writeInt(type); byte[] data = box.getContent(); stream.write(data, 0, data.length); }
/** Constructs a <code>DataEntryURLBox</code> from a Node. */ public DataEntryURLBox(Node node) throws IIOInvalidTreeException { super(node); NodeList children = node.getChildNodes(); for (int i = 0; i < children.getLength(); i++) { Node child = children.item(i); String name = child.getNodeName(); if ("Version".equals(name)) { version = Box.getByteElementValue(child); } if ("Flags".equals(name)) { flags = Box.getByteArrayElementValue(child); } if ("URL".equals(name)) { url = Box.getStringElementValue(child); } } }
/** Constructs a <code>FileTypeBox</code> from * <code>org.w3c.dom.Node</code>. */ public FileTypeBox(Node node) throws IIOInvalidTreeException { super(node); NodeList children = node.getChildNodes(); for (int i = 0; i < children.getLength(); i++) { Node child = children.item(i); String name = child.getNodeName(); if ("Brand".equals(name)) { brand = Box.getIntElementValue(child); } if ("MinorVersion".equals(name)) { minorVersion = Box.getIntElementValue(child); } if ("CompatibilityList".equals(name)) { compatibility = Box.getIntArrayElementValue(child); } } }
/** Constructs an Image Header Box from a Node. */ public HeaderBox(Node node) throws IIOInvalidTreeException { super(node); NodeList children = node.getChildNodes(); for (int i = 0; i < children.getLength(); i++) { Node child = children.item(i); String name = child.getNodeName(); if ("Height".equals(name)) { height = Box.getIntElementValue(child); } if ("Width".equals(name)) { width = Box.getIntElementValue(child); } if ("NumComponents".equals(name)) { numComp = Box.getShortElementValue(child); } if ("BitDepth".equals(name)) { bitDepth = Box.getByteElementValue(child); } if ("CompressionType".equals(name)) { compressionType = Box.getByteElementValue(child); } if ("UnknownColorspace".equals(name)) { unknownColor = Box.getByteElementValue(child); } if ("IntellectualProperty".equals(name)) { intelProp = Box.getByteElementValue(child); } } }
method = Box.getByteElementValue(child); precedence = Box.getByteElementValue(child); approximation = Box.getByteElementValue(child); ecs = Box.getIntElementValue(child); String value = node.getNodeValue(); if (value != null) profile = ICC_Profile.getInstance(Box.parseByteArray(value));
NodeList children = node.getChildNodes(); String value = (String)Box.getAttribute(node, "Type"); type = getTypeInt(value); if (value == null || names.get(new Integer(type)) == null) throw new IIOInvalidTreeException("Type is not defined", node); value = (String)Box.getAttribute(node, "Length"); if (value != null) length = new Integer(value).intValue(); value = (String)Box.getAttribute(node, "ExtraLength"); if (value != null) extraLength = new Long(value).longValue(); data = getByteArrayElementValue(child);
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); } } } }
if (s.startsWith("JPEG2000")) { addAttribute(s, "Length", DATATYPE_INTEGER, true, null); addAttribute(s, "Type", DATATYPE_STRING, true, Box.getTypeByName(s)); addAttribute(s, "ExtraLength", DATATYPE_STRING, false, null); Class c = Box.getBoxClass(Box.getTypeInt(Box.getTypeByName(s)));
/** Constructs a <code>ResolutionBox</code> based on the provided * <code>org.w3c.dom.Node</code>. */ public ResolutionBox(Node node) throws IIOInvalidTreeException { super(node); NodeList children = node.getChildNodes(); for (int i = 0; i < children.getLength(); i++) { Node child = children.item(i); String name = child.getNodeName(); if ("VerticalResolutionNumerator".equals(name)) { numV = Box.getShortElementValue(child); } if ("VerticalResolutionDenominator".equals(name)) { denomV = Box.getShortElementValue(child); } if ("HorizontalResolutionNumerator".equals(name)) { numH = Box.getShortElementValue(child); } if ("HorizontalResolutionDenominator".equals(name)) { denomH = Box.getShortElementValue(child); } if ("VerticalResolutionExponent".equals(name)) { expV = Box.getByteElementValue(child); } if ("HorizontalResolutionExponent".equals(name)) { expH = Box.getByteElementValue(child); } } }
private void createColorSpecificationBoxFromStandardNode(Node node) { if (node.getNodeName() != "ColorSpaceType") throw new IllegalArgumentException(I18N.getString("J2KMetadata4")); String name = (String)Box.getAttribute(node, "name"); int ecs = name.equals("RGB") ? ColorSpecificationBox.ECS_sRGB : (name.equals("Gray") ? ColorSpecificationBox.ECS_GRAY : 0); if (ecs == ColorSpecificationBox.ECS_sRGB || ecs ==ColorSpecificationBox.ECS_GRAY) { replace ("JPEG2000ColorSpecificationBox", new ColorSpecificationBox((byte)1, (byte)0, (byte)0, ecs, null)); } }
/** Constructs a <code>UUIDListBox</code> based on the provided * <code>org.w3c.dom.Node</code>. */ public UUIDListBox(Node node) throws IIOInvalidTreeException { super(node); NodeList children = node.getChildNodes(); int index = 0; for (int i = 0; i < children.getLength(); i++) { Node child = children.item(i); if ("NumberUUID".equals(child.getNodeName())) { num = (short)Box.getShortElementValue(child); uuids = new byte[num][]; } } for (int i = 0; i < children.getLength(); i++) { Node child = children.item(i); if ("UUID".equals(child.getNodeName()) && index < num) { uuids[index++] = Box.getByteArrayElementValue(child); } } }
numEntries = Box.getIntElementValue(child); numComps = Box.getIntElementValue(child); bitDepth = Box.getByteArrayElementValue(child); name = child1.getNodeName(); if ("LUTRow".equals(name)) { tlut[index++] = Box.getByteArrayElementValue(child1);
String s = (String)Box.getAttribute(child, "value"); bits = (byte[])Box.parseByteArray(s).clone(); } else if(name.equals("SampleFormat")) { String s = (String)Box.getAttribute(child, "value"); isSigned = s.equals("SignedIntegral");
/** Constructs a <code>UUIDBox</code> based on the provided * <code>org.w3c.dom.Node</code>. */ public UUIDBox(Node node) throws IIOInvalidTreeException { super(node); NodeList children = node.getChildNodes(); for (int i = 0; i < children.getLength(); i++) { Node child = children.item(i); String name = child.getNodeName(); if ("UUID".equals(name)) { uuid = Box.getByteArrayElementValue(child); } if ("Data".equals(name)) { udata = Box.getByteArrayElementValue(child); } } }
protected IIOMetadataNode getStandardTextNode() { if (boxes == null) return null; IIOMetadataNode text = null; Iterator iterator = boxes.iterator(); while(iterator.hasNext()) { Box box = (Box)iterator.next(); if (box instanceof XMLBox) { if (text == null) text = new IIOMetadataNode("Text"); IIOMetadataNode subNode = new IIOMetadataNode("TextEntry"); String content = new String(box.getContent()); subNode.setAttribute("value", content); text.appendChild(subNode); } } return text; }
/** Constructs a <code>ComponentMappingBox</code> based on the provided * <code>org.w3c.dom.Node</code>. */ public ComponentMappingBox(Node node) throws IIOInvalidTreeException { super(node); NodeList children = node.getChildNodes(); int len = children.getLength() / 3; components = new short[len]; type = new byte[len]; map = new byte[len]; len *= 3; int index = 0; for (int i = 0; i < len; i++) { Node child = children.item(i); String name = child.getNodeName(); if ("Component".equals(name)) { components[index] = Box.getShortElementValue(child); } if ("ComponentType".equals(name)) { type[index] = Box.getByteElementValue(child); } if ("ComponentAssociation".equals(name)) { map[index++] = Box.getByteElementValue(child); } } }
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) ; }
/** Constructs a <code>BitsPerComponentBox</code> based on the provide * <code>org.w3c.dom.Node</code>. */ public BitsPerComponentBox(Node node) throws IIOInvalidTreeException { super(node); NodeList children = node.getChildNodes(); for (int i = 0; i < children.getLength(); i++) { Node child = children.item(i); String name = child.getNodeName(); if ("BitDepth".equals(name)) { data = Box.getByteArrayElementValue(child); } } }