use of javax.imageio.metadata.IIOMetadataNode in project jdk8u_jdk by JetBrains.
the class PNGMetadata method mergeNativeTree.
private void mergeNativeTree(Node root) throws IIOInvalidTreeException {
Node node = root;
if (!node.getNodeName().equals(nativeMetadataFormatName)) {
fatal(node, "Root must be " + nativeMetadataFormatName);
}
node = node.getFirstChild();
while (node != null) {
String name = node.getNodeName();
if (name.equals("IHDR")) {
IHDR_width = getIntAttribute(node, "width");
IHDR_height = getIntAttribute(node, "height");
IHDR_bitDepth = Integer.valueOf(IHDR_bitDepths[getEnumeratedAttribute(node, "bitDepth", IHDR_bitDepths)]);
IHDR_colorType = getEnumeratedAttribute(node, "colorType", IHDR_colorTypeNames);
IHDR_compressionMethod = getEnumeratedAttribute(node, "compressionMethod", IHDR_compressionMethodNames);
IHDR_filterMethod = getEnumeratedAttribute(node, "filterMethod", IHDR_filterMethodNames);
IHDR_interlaceMethod = getEnumeratedAttribute(node, "interlaceMethod", IHDR_interlaceMethodNames);
IHDR_present = true;
} else if (name.equals("PLTE")) {
byte[] red = new byte[256];
byte[] green = new byte[256];
byte[] blue = new byte[256];
int maxindex = -1;
Node PLTE_entry = node.getFirstChild();
if (PLTE_entry == null) {
fatal(node, "Palette has no entries!");
}
while (PLTE_entry != null) {
if (!PLTE_entry.getNodeName().equals("PLTEEntry")) {
fatal(node, "Only a PLTEEntry may be a child of a PLTE!");
}
int index = getIntAttribute(PLTE_entry, "index");
if (index < 0 || index > 255) {
fatal(node, "Bad value for PLTEEntry attribute index!");
}
if (index > maxindex) {
maxindex = index;
}
red[index] = (byte) getIntAttribute(PLTE_entry, "red");
green[index] = (byte) getIntAttribute(PLTE_entry, "green");
blue[index] = (byte) getIntAttribute(PLTE_entry, "blue");
PLTE_entry = PLTE_entry.getNextSibling();
}
int numEntries = maxindex + 1;
PLTE_red = new byte[numEntries];
PLTE_green = new byte[numEntries];
PLTE_blue = new byte[numEntries];
System.arraycopy(red, 0, PLTE_red, 0, numEntries);
System.arraycopy(green, 0, PLTE_green, 0, numEntries);
System.arraycopy(blue, 0, PLTE_blue, 0, numEntries);
PLTE_present = true;
} else if (name.equals("bKGD")) {
// Guard against partial overwrite
bKGD_present = false;
Node bKGD_node = node.getFirstChild();
if (bKGD_node == null) {
fatal(node, "bKGD node has no children!");
}
String bKGD_name = bKGD_node.getNodeName();
if (bKGD_name.equals("bKGD_Palette")) {
bKGD_index = getIntAttribute(bKGD_node, "index");
bKGD_colorType = PNGImageReader.PNG_COLOR_PALETTE;
} else if (bKGD_name.equals("bKGD_Grayscale")) {
bKGD_gray = getIntAttribute(bKGD_node, "gray");
bKGD_colorType = PNGImageReader.PNG_COLOR_GRAY;
} else if (bKGD_name.equals("bKGD_RGB")) {
bKGD_red = getIntAttribute(bKGD_node, "red");
bKGD_green = getIntAttribute(bKGD_node, "green");
bKGD_blue = getIntAttribute(bKGD_node, "blue");
bKGD_colorType = PNGImageReader.PNG_COLOR_RGB;
} else {
fatal(node, "Bad child of a bKGD node!");
}
if (bKGD_node.getNextSibling() != null) {
fatal(node, "bKGD node has more than one child!");
}
bKGD_present = true;
} else if (name.equals("cHRM")) {
cHRM_whitePointX = getIntAttribute(node, "whitePointX");
cHRM_whitePointY = getIntAttribute(node, "whitePointY");
cHRM_redX = getIntAttribute(node, "redX");
cHRM_redY = getIntAttribute(node, "redY");
cHRM_greenX = getIntAttribute(node, "greenX");
cHRM_greenY = getIntAttribute(node, "greenY");
cHRM_blueX = getIntAttribute(node, "blueX");
cHRM_blueY = getIntAttribute(node, "blueY");
cHRM_present = true;
} else if (name.equals("gAMA")) {
gAMA_gamma = getIntAttribute(node, "value");
gAMA_present = true;
} else if (name.equals("hIST")) {
char[] hist = new char[256];
int maxindex = -1;
Node hIST_entry = node.getFirstChild();
if (hIST_entry == null) {
fatal(node, "hIST node has no children!");
}
while (hIST_entry != null) {
if (!hIST_entry.getNodeName().equals("hISTEntry")) {
fatal(node, "Only a hISTEntry may be a child of a hIST!");
}
int index = getIntAttribute(hIST_entry, "index");
if (index < 0 || index > 255) {
fatal(node, "Bad value for histEntry attribute index!");
}
if (index > maxindex) {
maxindex = index;
}
hist[index] = (char) getIntAttribute(hIST_entry, "value");
hIST_entry = hIST_entry.getNextSibling();
}
int numEntries = maxindex + 1;
hIST_histogram = new char[numEntries];
System.arraycopy(hist, 0, hIST_histogram, 0, numEntries);
hIST_present = true;
} else if (name.equals("iCCP")) {
iCCP_profileName = getAttribute(node, "profileName");
iCCP_compressionMethod = getEnumeratedAttribute(node, "compressionMethod", iCCP_compressionMethodNames);
Object compressedProfile = ((IIOMetadataNode) node).getUserObject();
if (compressedProfile == null) {
fatal(node, "No ICCP profile present in user object!");
}
if (!(compressedProfile instanceof byte[])) {
fatal(node, "User object not a byte array!");
}
iCCP_compressedProfile = (byte[]) ((byte[]) compressedProfile).clone();
iCCP_present = true;
} else if (name.equals("iTXt")) {
Node iTXt_node = node.getFirstChild();
while (iTXt_node != null) {
if (!iTXt_node.getNodeName().equals("iTXtEntry")) {
fatal(node, "Only an iTXtEntry may be a child of an iTXt!");
}
String keyword = getAttribute(iTXt_node, "keyword");
if (isValidKeyword(keyword)) {
iTXt_keyword.add(keyword);
boolean compressionFlag = getBooleanAttribute(iTXt_node, "compressionFlag");
iTXt_compressionFlag.add(Boolean.valueOf(compressionFlag));
String compressionMethod = getAttribute(iTXt_node, "compressionMethod");
iTXt_compressionMethod.add(Integer.valueOf(compressionMethod));
String languageTag = getAttribute(iTXt_node, "languageTag");
iTXt_languageTag.add(languageTag);
String translatedKeyword = getAttribute(iTXt_node, "translatedKeyword");
iTXt_translatedKeyword.add(translatedKeyword);
String text = getAttribute(iTXt_node, "text");
iTXt_text.add(text);
}
// silently skip invalid text entry
iTXt_node = iTXt_node.getNextSibling();
}
} else if (name.equals("pHYs")) {
pHYs_pixelsPerUnitXAxis = getIntAttribute(node, "pixelsPerUnitXAxis");
pHYs_pixelsPerUnitYAxis = getIntAttribute(node, "pixelsPerUnitYAxis");
pHYs_unitSpecifier = getEnumeratedAttribute(node, "unitSpecifier", unitSpecifierNames);
pHYs_present = true;
} else if (name.equals("sBIT")) {
// Guard against partial overwrite
sBIT_present = false;
Node sBIT_node = node.getFirstChild();
if (sBIT_node == null) {
fatal(node, "sBIT node has no children!");
}
String sBIT_name = sBIT_node.getNodeName();
if (sBIT_name.equals("sBIT_Grayscale")) {
sBIT_grayBits = getIntAttribute(sBIT_node, "gray");
sBIT_colorType = PNGImageReader.PNG_COLOR_GRAY;
} else if (sBIT_name.equals("sBIT_GrayAlpha")) {
sBIT_grayBits = getIntAttribute(sBIT_node, "gray");
sBIT_alphaBits = getIntAttribute(sBIT_node, "alpha");
sBIT_colorType = PNGImageReader.PNG_COLOR_GRAY_ALPHA;
} else if (sBIT_name.equals("sBIT_RGB")) {
sBIT_redBits = getIntAttribute(sBIT_node, "red");
sBIT_greenBits = getIntAttribute(sBIT_node, "green");
sBIT_blueBits = getIntAttribute(sBIT_node, "blue");
sBIT_colorType = PNGImageReader.PNG_COLOR_RGB;
} else if (sBIT_name.equals("sBIT_RGBAlpha")) {
sBIT_redBits = getIntAttribute(sBIT_node, "red");
sBIT_greenBits = getIntAttribute(sBIT_node, "green");
sBIT_blueBits = getIntAttribute(sBIT_node, "blue");
sBIT_alphaBits = getIntAttribute(sBIT_node, "alpha");
sBIT_colorType = PNGImageReader.PNG_COLOR_RGB_ALPHA;
} else if (sBIT_name.equals("sBIT_Palette")) {
sBIT_redBits = getIntAttribute(sBIT_node, "red");
sBIT_greenBits = getIntAttribute(sBIT_node, "green");
sBIT_blueBits = getIntAttribute(sBIT_node, "blue");
sBIT_colorType = PNGImageReader.PNG_COLOR_PALETTE;
} else {
fatal(node, "Bad child of an sBIT node!");
}
if (sBIT_node.getNextSibling() != null) {
fatal(node, "sBIT node has more than one child!");
}
sBIT_present = true;
} else if (name.equals("sPLT")) {
sPLT_paletteName = getAttribute(node, "name");
sPLT_sampleDepth = getIntAttribute(node, "sampleDepth");
int[] red = new int[256];
int[] green = new int[256];
int[] blue = new int[256];
int[] alpha = new int[256];
int[] frequency = new int[256];
int maxindex = -1;
Node sPLT_entry = node.getFirstChild();
if (sPLT_entry == null) {
fatal(node, "sPLT node has no children!");
}
while (sPLT_entry != null) {
if (!sPLT_entry.getNodeName().equals("sPLTEntry")) {
fatal(node, "Only an sPLTEntry may be a child of an sPLT!");
}
int index = getIntAttribute(sPLT_entry, "index");
if (index < 0 || index > 255) {
fatal(node, "Bad value for PLTEEntry attribute index!");
}
if (index > maxindex) {
maxindex = index;
}
red[index] = getIntAttribute(sPLT_entry, "red");
green[index] = getIntAttribute(sPLT_entry, "green");
blue[index] = getIntAttribute(sPLT_entry, "blue");
alpha[index] = getIntAttribute(sPLT_entry, "alpha");
frequency[index] = getIntAttribute(sPLT_entry, "frequency");
sPLT_entry = sPLT_entry.getNextSibling();
}
int numEntries = maxindex + 1;
sPLT_red = new int[numEntries];
sPLT_green = new int[numEntries];
sPLT_blue = new int[numEntries];
sPLT_alpha = new int[numEntries];
sPLT_frequency = new int[numEntries];
System.arraycopy(red, 0, sPLT_red, 0, numEntries);
System.arraycopy(green, 0, sPLT_green, 0, numEntries);
System.arraycopy(blue, 0, sPLT_blue, 0, numEntries);
System.arraycopy(alpha, 0, sPLT_alpha, 0, numEntries);
System.arraycopy(frequency, 0, sPLT_frequency, 0, numEntries);
sPLT_present = true;
} else if (name.equals("sRGB")) {
sRGB_renderingIntent = getEnumeratedAttribute(node, "renderingIntent", renderingIntentNames);
sRGB_present = true;
} else if (name.equals("tEXt")) {
Node tEXt_node = node.getFirstChild();
while (tEXt_node != null) {
if (!tEXt_node.getNodeName().equals("tEXtEntry")) {
fatal(node, "Only an tEXtEntry may be a child of an tEXt!");
}
String keyword = getAttribute(tEXt_node, "keyword");
tEXt_keyword.add(keyword);
String text = getAttribute(tEXt_node, "value");
tEXt_text.add(text);
tEXt_node = tEXt_node.getNextSibling();
}
} else if (name.equals("tIME")) {
tIME_year = getIntAttribute(node, "year");
tIME_month = getIntAttribute(node, "month");
tIME_day = getIntAttribute(node, "day");
tIME_hour = getIntAttribute(node, "hour");
tIME_minute = getIntAttribute(node, "minute");
tIME_second = getIntAttribute(node, "second");
tIME_present = true;
} else if (name.equals("tRNS")) {
// Guard against partial overwrite
tRNS_present = false;
Node tRNS_node = node.getFirstChild();
if (tRNS_node == null) {
fatal(node, "tRNS node has no children!");
}
String tRNS_name = tRNS_node.getNodeName();
if (tRNS_name.equals("tRNS_Palette")) {
byte[] alpha = new byte[256];
int maxindex = -1;
Node tRNS_paletteEntry = tRNS_node.getFirstChild();
if (tRNS_paletteEntry == null) {
fatal(node, "tRNS_Palette node has no children!");
}
while (tRNS_paletteEntry != null) {
if (!tRNS_paletteEntry.getNodeName().equals("tRNS_PaletteEntry")) {
fatal(node, "Only a tRNS_PaletteEntry may be a child of a tRNS_Palette!");
}
int index = getIntAttribute(tRNS_paletteEntry, "index");
if (index < 0 || index > 255) {
fatal(node, "Bad value for tRNS_PaletteEntry attribute index!");
}
if (index > maxindex) {
maxindex = index;
}
alpha[index] = (byte) getIntAttribute(tRNS_paletteEntry, "alpha");
tRNS_paletteEntry = tRNS_paletteEntry.getNextSibling();
}
int numEntries = maxindex + 1;
tRNS_alpha = new byte[numEntries];
tRNS_colorType = PNGImageReader.PNG_COLOR_PALETTE;
System.arraycopy(alpha, 0, tRNS_alpha, 0, numEntries);
} else if (tRNS_name.equals("tRNS_Grayscale")) {
tRNS_gray = getIntAttribute(tRNS_node, "gray");
tRNS_colorType = PNGImageReader.PNG_COLOR_GRAY;
} else if (tRNS_name.equals("tRNS_RGB")) {
tRNS_red = getIntAttribute(tRNS_node, "red");
tRNS_green = getIntAttribute(tRNS_node, "green");
tRNS_blue = getIntAttribute(tRNS_node, "blue");
tRNS_colorType = PNGImageReader.PNG_COLOR_RGB;
} else {
fatal(node, "Bad child of a tRNS node!");
}
if (tRNS_node.getNextSibling() != null) {
fatal(node, "tRNS node has more than one child!");
}
tRNS_present = true;
} else if (name.equals("zTXt")) {
Node zTXt_node = node.getFirstChild();
while (zTXt_node != null) {
if (!zTXt_node.getNodeName().equals("zTXtEntry")) {
fatal(node, "Only an zTXtEntry may be a child of an zTXt!");
}
String keyword = getAttribute(zTXt_node, "keyword");
zTXt_keyword.add(keyword);
int compressionMethod = getEnumeratedAttribute(zTXt_node, "compressionMethod", zTXt_compressionMethodNames);
zTXt_compressionMethod.add(new Integer(compressionMethod));
String text = getAttribute(zTXt_node, "text");
zTXt_text.add(text);
zTXt_node = zTXt_node.getNextSibling();
}
} else if (name.equals("UnknownChunks")) {
Node unknown_node = node.getFirstChild();
while (unknown_node != null) {
if (!unknown_node.getNodeName().equals("UnknownChunk")) {
fatal(node, "Only an UnknownChunk may be a child of an UnknownChunks!");
}
String chunkType = getAttribute(unknown_node, "type");
Object chunkData = ((IIOMetadataNode) unknown_node).getUserObject();
if (chunkType.length() != 4) {
fatal(unknown_node, "Chunk type must be 4 characters!");
}
if (chunkData == null) {
fatal(unknown_node, "No chunk data present in user object!");
}
if (!(chunkData instanceof byte[])) {
fatal(unknown_node, "User object not a byte array!");
}
unknownChunkType.add(chunkType);
unknownChunkData.add(((byte[]) chunkData).clone());
unknown_node = unknown_node.getNextSibling();
}
} else {
fatal(node, "Unknown child of root node!");
}
node = node.getNextSibling();
}
}
use of javax.imageio.metadata.IIOMetadataNode in project jdk8u_jdk by JetBrains.
the class PNGMetadata method getStandardChromaNode.
public IIOMetadataNode getStandardChromaNode() {
IIOMetadataNode chroma_node = new IIOMetadataNode("Chroma");
// scratch node
IIOMetadataNode node = null;
node = new IIOMetadataNode("ColorSpaceType");
node.setAttribute("name", colorSpaceTypeNames[IHDR_colorType]);
chroma_node.appendChild(node);
node = new IIOMetadataNode("NumChannels");
node.setAttribute("value", Integer.toString(getNumChannels()));
chroma_node.appendChild(node);
if (gAMA_present) {
node = new IIOMetadataNode("Gamma");
node.setAttribute("value", Float.toString(gAMA_gamma * 1.0e-5F));
chroma_node.appendChild(node);
}
node = new IIOMetadataNode("BlackIsZero");
node.setAttribute("value", "TRUE");
chroma_node.appendChild(node);
if (PLTE_present) {
boolean hasAlpha = tRNS_present && (tRNS_colorType == PNGImageReader.PNG_COLOR_PALETTE);
node = new IIOMetadataNode("Palette");
for (int i = 0; i < PLTE_red.length; i++) {
IIOMetadataNode entry = new IIOMetadataNode("PaletteEntry");
entry.setAttribute("index", Integer.toString(i));
entry.setAttribute("red", Integer.toString(PLTE_red[i] & 0xff));
entry.setAttribute("green", Integer.toString(PLTE_green[i] & 0xff));
entry.setAttribute("blue", Integer.toString(PLTE_blue[i] & 0xff));
if (hasAlpha) {
int alpha = (i < tRNS_alpha.length) ? (tRNS_alpha[i] & 0xff) : 255;
entry.setAttribute("alpha", Integer.toString(alpha));
}
node.appendChild(entry);
}
chroma_node.appendChild(node);
}
if (bKGD_present) {
if (bKGD_colorType == PNGImageReader.PNG_COLOR_PALETTE) {
node = new IIOMetadataNode("BackgroundIndex");
node.setAttribute("value", Integer.toString(bKGD_index));
} else {
node = new IIOMetadataNode("BackgroundColor");
int r, g, b;
if (bKGD_colorType == PNGImageReader.PNG_COLOR_GRAY) {
r = g = b = bKGD_gray;
} else {
r = bKGD_red;
g = bKGD_green;
b = bKGD_blue;
}
node.setAttribute("red", Integer.toString(r));
node.setAttribute("green", Integer.toString(g));
node.setAttribute("blue", Integer.toString(b));
}
chroma_node.appendChild(node);
}
return chroma_node;
}
use of javax.imageio.metadata.IIOMetadataNode in project jdk8u_jdk by JetBrains.
the class PNGMetadata method getStandardDimensionNode.
public IIOMetadataNode getStandardDimensionNode() {
IIOMetadataNode dimension_node = new IIOMetadataNode("Dimension");
// scratch node
IIOMetadataNode node = null;
node = new IIOMetadataNode("PixelAspectRatio");
float ratio = pHYs_present ? (float) pHYs_pixelsPerUnitXAxis / pHYs_pixelsPerUnitYAxis : 1.0F;
node.setAttribute("value", Float.toString(ratio));
dimension_node.appendChild(node);
node = new IIOMetadataNode("ImageOrientation");
node.setAttribute("value", "Normal");
dimension_node.appendChild(node);
if (pHYs_present && pHYs_unitSpecifier == PHYS_UNIT_METER) {
node = new IIOMetadataNode("HorizontalPixelSize");
node.setAttribute("value", Float.toString(1000.0F / pHYs_pixelsPerUnitXAxis));
dimension_node.appendChild(node);
node = new IIOMetadataNode("VerticalPixelSize");
node.setAttribute("value", Float.toString(1000.0F / pHYs_pixelsPerUnitYAxis));
dimension_node.appendChild(node);
}
return dimension_node;
}
use of javax.imageio.metadata.IIOMetadataNode in project jdk8u_jdk by JetBrains.
the class PNGMetadata method getStandardDocumentNode.
public IIOMetadataNode getStandardDocumentNode() {
if (!tIME_present) {
return null;
}
IIOMetadataNode document_node = new IIOMetadataNode("Document");
// scratch node
IIOMetadataNode node = null;
node = new IIOMetadataNode("ImageModificationTime");
node.setAttribute("year", Integer.toString(tIME_year));
node.setAttribute("month", Integer.toString(tIME_month));
node.setAttribute("day", Integer.toString(tIME_day));
node.setAttribute("hour", Integer.toString(tIME_hour));
node.setAttribute("minute", Integer.toString(tIME_minute));
node.setAttribute("second", Integer.toString(tIME_second));
document_node.appendChild(node);
return document_node;
}
use of javax.imageio.metadata.IIOMetadataNode in project jdk8u_jdk by JetBrains.
the class JPEGMetadata method getStandardCompressionNode.
protected IIOMetadataNode getStandardCompressionNode() {
IIOMetadataNode compression = new IIOMetadataNode("Compression");
// CompressionTypeName
IIOMetadataNode name = new IIOMetadataNode("CompressionTypeName");
name.setAttribute("value", "JPEG");
compression.appendChild(name);
// Lossless - false
IIOMetadataNode lossless = new IIOMetadataNode("Lossless");
lossless.setAttribute("value", "FALSE");
compression.appendChild(lossless);
// NumProgressiveScans - count sos segments
int sosCount = 0;
Iterator iter = markerSequence.iterator();
while (iter.hasNext()) {
MarkerSegment ms = (MarkerSegment) iter.next();
if (ms.tag == JPEG.SOS) {
sosCount++;
}
}
if (sosCount != 0) {
IIOMetadataNode prog = new IIOMetadataNode("NumProgressiveScans");
prog.setAttribute("value", Integer.toString(sosCount));
compression.appendChild(prog);
}
return compression;
}
Aggregations