use of javax.imageio.metadata.IIOInvalidTreeException in project imageio-ext by geosolutions-it.
the class TIFFBaseJPEGCompressor method getImageMetadata.
/**
* Retrieves image metadata with non-core nodes removed.
*/
private IIOMetadata getImageMetadata(boolean pruneTables) throws IIOException {
if (DEBUG) {
System.out.println("getImageMetadata(" + pruneTables + ")");
}
if (JPEGImageMetadata == null && IMAGE_METADATA_NAME.equals(JPEGWriter.getOriginatingProvider().getNativeImageMetadataFormatName())) {
TIFFImageWriter tiffWriter = (TIFFImageWriter) this.writer;
// Get default image metadata.
JPEGImageMetadata = JPEGWriter.getDefaultImageMetadata(tiffWriter.imageType, JPEGParam);
// Get the DOM tree.
Node tree = JPEGImageMetadata.getAsTree(IMAGE_METADATA_NAME);
// Remove unwanted marker segments.
try {
pruneNodes(tree, pruneTables);
} catch (IllegalArgumentException e) {
throw new IIOException("Error pruning unwanted nodes", e);
}
// Set the DOM back into the metadata.
try {
JPEGImageMetadata.setFromTree(IMAGE_METADATA_NAME, tree);
} catch (IIOInvalidTreeException e) {
// present of JPEGTables field.
throw new IIOException("Cannot set pruned image metadata!", e);
}
}
return JPEGImageMetadata;
}
use of javax.imageio.metadata.IIOInvalidTreeException in project quick-media by liuyueyi.
the class ImageIOJPEGImageWriter method updateMetadata.
/**
* {@inheritDoc}
*/
@Override
protected IIOMetadata updateMetadata(IIOMetadata meta, ImageWriterParams params) {
// ImageIODebugUtil.dumpMetadata(meta);
if (JPEG_NATIVE_FORMAT.equals(meta.getNativeMetadataFormatName())) {
meta = addAdobeTransform(meta);
IIOMetadataNode root = (IIOMetadataNode) meta.getAsTree(JPEG_NATIVE_FORMAT);
IIOMetadataNode jv = getChildNode(root, "JPEGvariety");
if (jv == null) {
jv = new IIOMetadataNode("JPEGvariety");
root.appendChild(jv);
}
IIOMetadataNode child;
if (params.getResolution() != null) {
child = getChildNode(jv, "app0JFIF");
if (child == null) {
child = new IIOMetadataNode("app0JFIF");
jv.appendChild(child);
}
// JPEG gets special treatment because there seems to be a bug in
// the JPEG codec in ImageIO converting the pixel size incorrectly
// (or not at all) when using standard metadata format.
child.setAttribute("majorVersion", null);
child.setAttribute("minorVersion", null);
// dots per inch
child.setAttribute("resUnits", "1");
child.setAttribute("Xdensity", params.getResolution().toString());
child.setAttribute("Ydensity", params.getResolution().toString());
child.setAttribute("thumbWidth", null);
child.setAttribute("thumbHeight", null);
}
try {
meta.setFromTree(JPEG_NATIVE_FORMAT, root);
} catch (IIOInvalidTreeException e) {
throw new RuntimeException("Cannot update image metadata: " + e.getMessage(), e);
}
// ImageIODebugUtil.dumpMetadata(meta);
}
return meta;
}
use of javax.imageio.metadata.IIOInvalidTreeException in project quick-media by liuyueyi.
the class ImageIOJPEGImageWriter method addAdobeTransform.
private static IIOMetadata addAdobeTransform(IIOMetadata meta) {
// add the adobe transformation (transform 1 -> to YCbCr)
IIOMetadataNode root = (IIOMetadataNode) meta.getAsTree(JPEG_NATIVE_FORMAT);
IIOMetadataNode markerSequence = getChildNode(root, "markerSequence");
if (markerSequence == null) {
throw new RuntimeException("Invalid metadata!");
}
IIOMetadataNode adobeTransform = getChildNode(markerSequence, "app14Adobe");
if (adobeTransform == null) {
adobeTransform = new IIOMetadataNode("app14Adobe");
// convert RGB to YCbCr
adobeTransform.setAttribute("transform", "1");
adobeTransform.setAttribute("version", "101");
adobeTransform.setAttribute("flags0", "0");
adobeTransform.setAttribute("flags1", "0");
markerSequence.appendChild(adobeTransform);
} else {
adobeTransform.setAttribute("transform", "1");
}
try {
meta.setFromTree(JPEG_NATIVE_FORMAT, root);
} catch (IIOInvalidTreeException e) {
throw new RuntimeException("Cannot update image metadata: " + e.getMessage(), e);
}
return meta;
}
Aggregations