use of javax.imageio.metadata.IIOMetadataNode in project imageio-ext by geosolutions-it.
the class TIFFImageMetadata method getIFDAsTree.
private Node getIFDAsTree(TIFFIFD ifd, String parentTagName, int parentTagNumber) {
IIOMetadataNode IFDRoot = new IIOMetadataNode("TIFFIFD");
if (parentTagNumber != 0) {
IFDRoot.setAttribute("parentTagNumber", Integer.toString(parentTagNumber));
}
if (parentTagName != null) {
IFDRoot.setAttribute("parentTagName", parentTagName);
}
List tagSets = ifd.getTagSetList();
if (tagSets.size() > 0) {
Iterator iter = tagSets.iterator();
String tagSetNames = "";
while (iter.hasNext()) {
TIFFTagSet tagSet = (TIFFTagSet) iter.next();
tagSetNames += tagSet.getClass().getName();
if (iter.hasNext()) {
tagSetNames += ",";
}
}
IFDRoot.setAttribute("tagSets", tagSetNames);
}
Iterator iter = ifd.iterator();
while (iter.hasNext()) {
TIFFField f = (TIFFField) iter.next();
int tagNumber = f.getTagNumber();
TIFFTag tag = TIFFIFD.getTag(tagNumber, tagSets);
Node node = null;
if (tag == null) {
node = f.getAsNativeNode();
} else if (tag.isIFDPointer()) {
TIFFIFD subIFD = (TIFFIFD) f.getData();
// Recurse
node = getIFDAsTree(subIFD, tag.getName(), tag.getNumber());
} else {
node = f.getAsNativeNode();
}
if (node != null) {
IFDRoot.appendChild(node);
}
}
return IFDRoot;
}
use of javax.imageio.metadata.IIOMetadataNode in project imageio-ext by geosolutions-it.
the class TIFFImageMetadata method getStandardTransparencyNode.
public IIOMetadataNode getStandardTransparencyNode() {
IIOMetadataNode transparency_node = new IIOMetadataNode("Transparency");
// scratch node
IIOMetadataNode node = null;
TIFFField f;
node = new IIOMetadataNode("Alpha");
String value = "none";
f = getTIFFField(BaselineTIFFTagSet.TAG_EXTRA_SAMPLES);
if (f != null) {
int[] extraSamples = f.getAsInts();
for (int i = 0; i < extraSamples.length; i++) {
if (extraSamples[i] == BaselineTIFFTagSet.EXTRA_SAMPLES_ASSOCIATED_ALPHA) {
value = "premultiplied";
break;
} else if (extraSamples[i] == BaselineTIFFTagSet.EXTRA_SAMPLES_UNASSOCIATED_ALPHA) {
value = "nonpremultiplied";
break;
}
}
}
node.setAttribute("value", value);
transparency_node.appendChild(node);
return transparency_node;
}
use of javax.imageio.metadata.IIOMetadataNode in project imageio-ext by geosolutions-it.
the class TIFFBaseJPEGCompressor method pruneNodes.
/**
* Removes nonessential nodes from a JPEG native image metadata tree.
* All nodes derived from JPEG marker segments other than DHT, DQT,
* SOF, SOS segments are removed unless <code>pruneTables</code> is
* <code>true</code> in which case the nodes derived from the DHT and
* DQT marker segments are also removed.
*
* @param tree A <tt>javax_imageio_jpeg_image_1.0</tt> tree.
* @param pruneTables Whether to prune Huffman and quantization tables.
* @throws IllegalArgumentException if <code>tree</code> is
* <code>null</code> or is not the root of a JPEG native image
* metadata tree.
*/
private static void pruneNodes(Node tree, boolean pruneTables) {
if (tree == null) {
throw new IllegalArgumentException("tree == null!");
}
if (!tree.getNodeName().equals(IMAGE_METADATA_NAME)) {
throw new IllegalArgumentException("root node name is not " + IMAGE_METADATA_NAME + "!");
}
if (DEBUG) {
System.out.println("pruneNodes(" + tree + "," + pruneTables + ")");
}
// Create list of required nodes.
List wantedNodes = new ArrayList();
wantedNodes.addAll(Arrays.asList(new String[] { "JPEGvariety", "markerSequence", "sof", "componentSpec", "sos", "scanComponentSpec" }));
// Add Huffman and quantization table nodes if not pruning tables.
if (!pruneTables) {
wantedNodes.add("dht");
wantedNodes.add("dhtable");
wantedNodes.add("dqt");
wantedNodes.add("dqtable");
}
IIOMetadataNode iioTree = (IIOMetadataNode) tree;
List nodes = getAllNodes(iioTree, null);
int numNodes = nodes.size();
for (int i = 0; i < numNodes; i++) {
Node node = (Node) nodes.get(i);
if (!wantedNodes.contains(node.getNodeName())) {
if (DEBUG) {
System.out.println("Removing " + node.getNodeName());
}
node.getParentNode().removeChild(node);
}
}
}
use of javax.imageio.metadata.IIOMetadataNode in project imageio-ext by geosolutions-it.
the class TIFFBaseJPEGCompressor method getAllNodes.
private static List getAllNodes(IIOMetadataNode root, List nodes) {
if (nodes == null)
nodes = new ArrayList();
if (root.hasChildNodes()) {
Node sibling = root.getFirstChild();
while (sibling != null) {
nodes.add(sibling);
nodes = getAllNodes((IIOMetadataNode) sibling, nodes);
sibling = sibling.getNextSibling();
}
}
return nodes;
}
use of javax.imageio.metadata.IIOMetadataNode in project imageio-ext by geosolutions-it.
the class BaseJP2KBox method getNativeNodeForSimpleBox.
/**
* 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(BoxUtilities.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("Box0");
}
}
Aggregations