use of javax.imageio.metadata.IIOInvalidTreeException in project jdk8u_jdk by JetBrains.
the class WriteMetadataTest method testWritableMetadata.
public static void testWritableMetadata(IIOMetadata m) {
String nativeFormatName = m.getNativeMetadataFormatName();
System.out.println("Format: " + nativeFormatName);
IIOMetadataNode root = (IIOMetadataNode) m.getAsTree(nativeFormatName);
if (m.isReadOnly()) {
throw new RuntimeException("Metadata is read only!");
}
try {
m.setFromTree(nativeFormatName, root);
} catch (IIOInvalidTreeException e) {
e.printStackTrace();
throw new RuntimeException("Test failed!", e);
} catch (IllegalStateException e) {
throw new RuntimeException("Test failed!", e);
}
System.out.println("Test passed.\n\n");
}
use of javax.imageio.metadata.IIOInvalidTreeException in project jdk8u_jdk by JetBrains.
the class ShortHistogramTest method upgradeMetadata.
private IIOMetadata upgradeMetadata(IIOMetadata src, BufferedImage bi) {
String format = src.getNativeMetadataFormatName();
System.out.println("Native format: " + format);
Node root = src.getAsTree(format);
// add hIST node
Node n = lookupChildNode(root, "hIST");
if (n == null) {
System.out.println("Appending new hIST node...");
Node hIST = gethISTNode(bi);
root.appendChild(hIST);
}
System.out.println("Upgraded metadata tree:");
dump(root, "");
System.out.println("Merging metadata...");
try {
src.mergeTree(format, root);
} catch (IIOInvalidTreeException e) {
throw new RuntimeException("Test FAILED!", e);
}
return src;
}
use of javax.imageio.metadata.IIOInvalidTreeException in project jdk8u_jdk by JetBrains.
the class PngDitDepthTest method main.
public static void main(String[] args) throws IIOInvalidTreeException {
// getting the writer for the png format
Iterator iter = ImageIO.getImageWritersByFormatName("png");
ImageWriter writer = (ImageWriter) iter.next();
// creating a color model
ColorModel colorModel = ColorModel.getRGBdefault();
// creating a sample model
SampleModel sampleModel = colorModel.createCompatibleSampleModel(640, 480);
// creating a default metadata object
IIOMetadata metaData = writer.getDefaultImageMetadata(new ImageTypeSpecifier(colorModel, sampleModel), null);
String formatName = metaData.getNativeMetadataFormatName();
// first call
Node metaDataNode = metaData.getAsTree(formatName);
try {
metaData.setFromTree(formatName, metaDataNode);
} catch (Exception ex) {
ex.printStackTrace();
}
// second call (bitdepht is already set to an invalid value)
metaDataNode = metaData.getAsTree(formatName);
metaData.setFromTree(formatName, metaDataNode);
}
use of javax.imageio.metadata.IIOInvalidTreeException in project jdk8u_jdk by JetBrains.
the class JPEGMetadata method mergeSequenceSubtree.
private void mergeSequenceSubtree(Node sequenceTree) throws IIOInvalidTreeException {
NodeList children = sequenceTree.getChildNodes();
for (int i = 0; i < children.getLength(); i++) {
Node node = children.item(i);
String name = node.getNodeName();
if (name.equals("dqt")) {
mergeDQTNode(node);
} else if (name.equals("dht")) {
mergeDHTNode(node);
} else if (name.equals("dri")) {
mergeDRINode(node);
} else if (name.equals("com")) {
mergeCOMNode(node);
} else if (name.equals("app14Adobe")) {
mergeAdobeNode(node);
} else if (name.equals("unknown")) {
mergeUnknownNode(node);
} else if (name.equals("sof")) {
mergeSOFNode(node);
} else if (name.equals("sos")) {
mergeSOSNode(node);
} else {
throw new IIOInvalidTreeException("Invalid node: " + name, node);
}
}
}
use of javax.imageio.metadata.IIOInvalidTreeException in project jdk8u_jdk by JetBrains.
the class JPEGMetadata method mergeTree.
public void mergeTree(String formatName, Node root) throws IIOInvalidTreeException {
if (formatName == null) {
throw new IllegalArgumentException("null formatName!");
}
if (root == null) {
throw new IllegalArgumentException("null root!");
}
List copy = null;
if (resetSequence == null) {
// Deep copy
resetSequence = cloneSequence();
// Avoid cloning twice
copy = resetSequence;
} else {
copy = cloneSequence();
}
if (isStream && (formatName.equals(JPEG.nativeStreamMetadataFormatName))) {
mergeNativeTree(root);
} else if (!isStream && (formatName.equals(JPEG.nativeImageMetadataFormatName))) {
mergeNativeTree(root);
} else if (!isStream && (formatName.equals(IIOMetadataFormatImpl.standardMetadataFormatName))) {
mergeStandardTree(root);
} else {
throw new IllegalArgumentException("Unsupported format name: " + formatName);
}
if (!isConsistent()) {
markerSequence = copy;
throw new IIOInvalidTreeException("Merged tree is invalid; original restored", root);
}
}
Aggregations