use of it.geosolutions.imageio.plugins.tiff.TIFFField in project imageio-ext by geosolutions-it.
the class TIFFImageMetadata method getStandardCompressionNode.
public IIOMetadataNode getStandardCompressionNode() {
IIOMetadataNode compression_node = new IIOMetadataNode("Compression");
// scratch node
IIOMetadataNode node = null;
TIFFField f;
f = getTIFFField(BaselineTIFFTagSet.TAG_COMPRESSION);
if (f != null) {
String compressionTypeName = null;
int compression = f.getAsInt(0);
// obligate initialization.
boolean isLossless = true;
if (compression == BaselineTIFFTagSet.COMPRESSION_NONE) {
compressionTypeName = "None";
isLossless = true;
} else {
int[] compressionNumbers = TIFFImageWriter.compressionNumbers;
for (int i = 0; i < compressionNumbers.length; i++) {
if (compression == compressionNumbers[i]) {
compressionTypeName = TIFFImageWriter.compressionTypes[i];
isLossless = TIFFImageWriter.isCompressionLossless[i];
break;
}
}
}
if (compressionTypeName != null) {
node = new IIOMetadataNode("CompressionTypeName");
node.setAttribute("value", compressionTypeName);
compression_node.appendChild(node);
node = new IIOMetadataNode("Lossless");
node.setAttribute("value", isLossless ? "TRUE" : "FALSE");
compression_node.appendChild(node);
}
}
node = new IIOMetadataNode("NumProgressiveScans");
node.setAttribute("value", "1");
compression_node.appendChild(node);
return compression_node;
}
use of it.geosolutions.imageio.plugins.tiff.TIFFField in project imageio-ext by geosolutions-it.
the class TIFFImageMetadata method getStandardDocumentNode.
public IIOMetadataNode getStandardDocumentNode() {
IIOMetadataNode document_node = new IIOMetadataNode("Document");
// scratch node
IIOMetadataNode node = null;
TIFFField f;
node = new IIOMetadataNode("FormatVersion");
node.setAttribute("value", "6.0");
document_node.appendChild(node);
f = getTIFFField(BaselineTIFFTagSet.TAG_NEW_SUBFILE_TYPE);
if (f != null) {
int newSubFileType = f.getAsInt(0);
String value = null;
if ((newSubFileType & BaselineTIFFTagSet.NEW_SUBFILE_TYPE_TRANSPARENCY) != 0) {
value = "TransparencyMask";
} else if ((newSubFileType & BaselineTIFFTagSet.NEW_SUBFILE_TYPE_REDUCED_RESOLUTION) != 0) {
value = "ReducedResolution";
} else if ((newSubFileType & BaselineTIFFTagSet.NEW_SUBFILE_TYPE_SINGLE_PAGE) != 0) {
value = "SinglePage";
}
if (value != null) {
node = new IIOMetadataNode("SubimageInterpretation");
node.setAttribute("value", value);
document_node.appendChild(node);
}
}
f = getTIFFField(BaselineTIFFTagSet.TAG_DATE_TIME);
if (f != null) {
String s = f.getAsString(0);
// DateTime should be formatted as "YYYY:MM:DD hh:mm:ss".
if (s.length() == 19) {
node = new IIOMetadataNode("ImageCreationTime");
// Files with incorrect DateTime format have been
// observed so anticipate an exception from substring()
// and only add the node if the format is presumably
// correct.
boolean appendNode;
try {
node.setAttribute("year", s.substring(0, 4));
node.setAttribute("month", s.substring(5, 7));
node.setAttribute("day", s.substring(8, 10));
node.setAttribute("hour", s.substring(11, 13));
node.setAttribute("minute", s.substring(14, 16));
node.setAttribute("second", s.substring(17, 19));
appendNode = true;
} catch (IndexOutOfBoundsException e) {
appendNode = false;
}
if (appendNode) {
document_node.appendChild(node);
}
}
}
return document_node;
}
use of it.geosolutions.imageio.plugins.tiff.TIFFField in project imageio-ext by geosolutions-it.
the class TIFFImageMetadata method addShortOrLongField.
public void addShortOrLongField(int tagNumber, int value) {
TIFFField field = new TIFFField(rootIFD.getTag(tagNumber), value);
rootIFD.addTIFFField(field);
}
use of it.geosolutions.imageio.plugins.tiff.TIFFField 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 it.geosolutions.imageio.plugins.tiff.TIFFField 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;
}
Aggregations