use of javax.imageio.metadata.IIOMetadataNode in project jdk8u_jdk by JetBrains.
the class PNGMetadata method getNativeTree.
private Node getNativeTree() {
// scratch node
IIOMetadataNode node = null;
IIOMetadataNode root = new IIOMetadataNode(nativeMetadataFormatName);
// IHDR
if (IHDR_present) {
IIOMetadataNode IHDR_node = new IIOMetadataNode("IHDR");
IHDR_node.setAttribute("width", Integer.toString(IHDR_width));
IHDR_node.setAttribute("height", Integer.toString(IHDR_height));
IHDR_node.setAttribute("bitDepth", Integer.toString(IHDR_bitDepth));
IHDR_node.setAttribute("colorType", IHDR_colorTypeNames[IHDR_colorType]);
// IHDR_compressionMethod must be 0 in PNG 1.1
IHDR_node.setAttribute("compressionMethod", IHDR_compressionMethodNames[IHDR_compressionMethod]);
// IHDR_filterMethod must be 0 in PNG 1.1
IHDR_node.setAttribute("filterMethod", IHDR_filterMethodNames[IHDR_filterMethod]);
IHDR_node.setAttribute("interlaceMethod", IHDR_interlaceMethodNames[IHDR_interlaceMethod]);
root.appendChild(IHDR_node);
}
// PLTE
if (PLTE_present) {
IIOMetadataNode PLTE_node = new IIOMetadataNode("PLTE");
int numEntries = PLTE_red.length;
for (int i = 0; i < numEntries; i++) {
IIOMetadataNode entry = new IIOMetadataNode("PLTEEntry");
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));
PLTE_node.appendChild(entry);
}
root.appendChild(PLTE_node);
}
// bKGD
if (bKGD_present) {
IIOMetadataNode bKGD_node = new IIOMetadataNode("bKGD");
if (bKGD_colorType == PNGImageReader.PNG_COLOR_PALETTE) {
node = new IIOMetadataNode("bKGD_Palette");
node.setAttribute("index", Integer.toString(bKGD_index));
} else if (bKGD_colorType == PNGImageReader.PNG_COLOR_GRAY) {
node = new IIOMetadataNode("bKGD_Grayscale");
node.setAttribute("gray", Integer.toString(bKGD_gray));
} else if (bKGD_colorType == PNGImageReader.PNG_COLOR_RGB) {
node = new IIOMetadataNode("bKGD_RGB");
node.setAttribute("red", Integer.toString(bKGD_red));
node.setAttribute("green", Integer.toString(bKGD_green));
node.setAttribute("blue", Integer.toString(bKGD_blue));
}
bKGD_node.appendChild(node);
root.appendChild(bKGD_node);
}
// cHRM
if (cHRM_present) {
IIOMetadataNode cHRM_node = new IIOMetadataNode("cHRM");
cHRM_node.setAttribute("whitePointX", Integer.toString(cHRM_whitePointX));
cHRM_node.setAttribute("whitePointY", Integer.toString(cHRM_whitePointY));
cHRM_node.setAttribute("redX", Integer.toString(cHRM_redX));
cHRM_node.setAttribute("redY", Integer.toString(cHRM_redY));
cHRM_node.setAttribute("greenX", Integer.toString(cHRM_greenX));
cHRM_node.setAttribute("greenY", Integer.toString(cHRM_greenY));
cHRM_node.setAttribute("blueX", Integer.toString(cHRM_blueX));
cHRM_node.setAttribute("blueY", Integer.toString(cHRM_blueY));
root.appendChild(cHRM_node);
}
// gAMA
if (gAMA_present) {
IIOMetadataNode gAMA_node = new IIOMetadataNode("gAMA");
gAMA_node.setAttribute("value", Integer.toString(gAMA_gamma));
root.appendChild(gAMA_node);
}
// hIST
if (hIST_present) {
IIOMetadataNode hIST_node = new IIOMetadataNode("hIST");
for (int i = 0; i < hIST_histogram.length; i++) {
IIOMetadataNode hist = new IIOMetadataNode("hISTEntry");
hist.setAttribute("index", Integer.toString(i));
hist.setAttribute("value", Integer.toString(hIST_histogram[i]));
hIST_node.appendChild(hist);
}
root.appendChild(hIST_node);
}
// iCCP
if (iCCP_present) {
IIOMetadataNode iCCP_node = new IIOMetadataNode("iCCP");
iCCP_node.setAttribute("profileName", iCCP_profileName);
iCCP_node.setAttribute("compressionMethod", iCCP_compressionMethodNames[iCCP_compressionMethod]);
Object profile = iCCP_compressedProfile;
if (profile != null) {
profile = ((byte[]) profile).clone();
}
iCCP_node.setUserObject(profile);
root.appendChild(iCCP_node);
}
// iTXt
if (iTXt_keyword.size() > 0) {
IIOMetadataNode iTXt_parent = new IIOMetadataNode("iTXt");
for (int i = 0; i < iTXt_keyword.size(); i++) {
IIOMetadataNode iTXt_node = new IIOMetadataNode("iTXtEntry");
iTXt_node.setAttribute("keyword", iTXt_keyword.get(i));
iTXt_node.setAttribute("compressionFlag", iTXt_compressionFlag.get(i) ? "TRUE" : "FALSE");
iTXt_node.setAttribute("compressionMethod", iTXt_compressionMethod.get(i).toString());
iTXt_node.setAttribute("languageTag", iTXt_languageTag.get(i));
iTXt_node.setAttribute("translatedKeyword", iTXt_translatedKeyword.get(i));
iTXt_node.setAttribute("text", iTXt_text.get(i));
iTXt_parent.appendChild(iTXt_node);
}
root.appendChild(iTXt_parent);
}
// pHYs
if (pHYs_present) {
IIOMetadataNode pHYs_node = new IIOMetadataNode("pHYs");
pHYs_node.setAttribute("pixelsPerUnitXAxis", Integer.toString(pHYs_pixelsPerUnitXAxis));
pHYs_node.setAttribute("pixelsPerUnitYAxis", Integer.toString(pHYs_pixelsPerUnitYAxis));
pHYs_node.setAttribute("unitSpecifier", unitSpecifierNames[pHYs_unitSpecifier]);
root.appendChild(pHYs_node);
}
// sBIT
if (sBIT_present) {
IIOMetadataNode sBIT_node = new IIOMetadataNode("sBIT");
if (sBIT_colorType == PNGImageReader.PNG_COLOR_GRAY) {
node = new IIOMetadataNode("sBIT_Grayscale");
node.setAttribute("gray", Integer.toString(sBIT_grayBits));
} else if (sBIT_colorType == PNGImageReader.PNG_COLOR_GRAY_ALPHA) {
node = new IIOMetadataNode("sBIT_GrayAlpha");
node.setAttribute("gray", Integer.toString(sBIT_grayBits));
node.setAttribute("alpha", Integer.toString(sBIT_alphaBits));
} else if (sBIT_colorType == PNGImageReader.PNG_COLOR_RGB) {
node = new IIOMetadataNode("sBIT_RGB");
node.setAttribute("red", Integer.toString(sBIT_redBits));
node.setAttribute("green", Integer.toString(sBIT_greenBits));
node.setAttribute("blue", Integer.toString(sBIT_blueBits));
} else if (sBIT_colorType == PNGImageReader.PNG_COLOR_RGB_ALPHA) {
node = new IIOMetadataNode("sBIT_RGBAlpha");
node.setAttribute("red", Integer.toString(sBIT_redBits));
node.setAttribute("green", Integer.toString(sBIT_greenBits));
node.setAttribute("blue", Integer.toString(sBIT_blueBits));
node.setAttribute("alpha", Integer.toString(sBIT_alphaBits));
} else if (sBIT_colorType == PNGImageReader.PNG_COLOR_PALETTE) {
node = new IIOMetadataNode("sBIT_Palette");
node.setAttribute("red", Integer.toString(sBIT_redBits));
node.setAttribute("green", Integer.toString(sBIT_greenBits));
node.setAttribute("blue", Integer.toString(sBIT_blueBits));
}
sBIT_node.appendChild(node);
root.appendChild(sBIT_node);
}
// sPLT
if (sPLT_present) {
IIOMetadataNode sPLT_node = new IIOMetadataNode("sPLT");
sPLT_node.setAttribute("name", sPLT_paletteName);
sPLT_node.setAttribute("sampleDepth", Integer.toString(sPLT_sampleDepth));
int numEntries = sPLT_red.length;
for (int i = 0; i < numEntries; i++) {
IIOMetadataNode entry = new IIOMetadataNode("sPLTEntry");
entry.setAttribute("index", Integer.toString(i));
entry.setAttribute("red", Integer.toString(sPLT_red[i]));
entry.setAttribute("green", Integer.toString(sPLT_green[i]));
entry.setAttribute("blue", Integer.toString(sPLT_blue[i]));
entry.setAttribute("alpha", Integer.toString(sPLT_alpha[i]));
entry.setAttribute("frequency", Integer.toString(sPLT_frequency[i]));
sPLT_node.appendChild(entry);
}
root.appendChild(sPLT_node);
}
// sRGB
if (sRGB_present) {
IIOMetadataNode sRGB_node = new IIOMetadataNode("sRGB");
sRGB_node.setAttribute("renderingIntent", renderingIntentNames[sRGB_renderingIntent]);
root.appendChild(sRGB_node);
}
// tEXt
if (tEXt_keyword.size() > 0) {
IIOMetadataNode tEXt_parent = new IIOMetadataNode("tEXt");
for (int i = 0; i < tEXt_keyword.size(); i++) {
IIOMetadataNode tEXt_node = new IIOMetadataNode("tEXtEntry");
tEXt_node.setAttribute("keyword", (String) tEXt_keyword.get(i));
tEXt_node.setAttribute("value", (String) tEXt_text.get(i));
tEXt_parent.appendChild(tEXt_node);
}
root.appendChild(tEXt_parent);
}
// tIME
if (tIME_present) {
IIOMetadataNode tIME_node = new IIOMetadataNode("tIME");
tIME_node.setAttribute("year", Integer.toString(tIME_year));
tIME_node.setAttribute("month", Integer.toString(tIME_month));
tIME_node.setAttribute("day", Integer.toString(tIME_day));
tIME_node.setAttribute("hour", Integer.toString(tIME_hour));
tIME_node.setAttribute("minute", Integer.toString(tIME_minute));
tIME_node.setAttribute("second", Integer.toString(tIME_second));
root.appendChild(tIME_node);
}
// tRNS
if (tRNS_present) {
IIOMetadataNode tRNS_node = new IIOMetadataNode("tRNS");
if (tRNS_colorType == PNGImageReader.PNG_COLOR_PALETTE) {
node = new IIOMetadataNode("tRNS_Palette");
for (int i = 0; i < tRNS_alpha.length; i++) {
IIOMetadataNode entry = new IIOMetadataNode("tRNS_PaletteEntry");
entry.setAttribute("index", Integer.toString(i));
entry.setAttribute("alpha", Integer.toString(tRNS_alpha[i] & 0xff));
node.appendChild(entry);
}
} else if (tRNS_colorType == PNGImageReader.PNG_COLOR_GRAY) {
node = new IIOMetadataNode("tRNS_Grayscale");
node.setAttribute("gray", Integer.toString(tRNS_gray));
} else if (tRNS_colorType == PNGImageReader.PNG_COLOR_RGB) {
node = new IIOMetadataNode("tRNS_RGB");
node.setAttribute("red", Integer.toString(tRNS_red));
node.setAttribute("green", Integer.toString(tRNS_green));
node.setAttribute("blue", Integer.toString(tRNS_blue));
}
tRNS_node.appendChild(node);
root.appendChild(tRNS_node);
}
// zTXt
if (zTXt_keyword.size() > 0) {
IIOMetadataNode zTXt_parent = new IIOMetadataNode("zTXt");
for (int i = 0; i < zTXt_keyword.size(); i++) {
IIOMetadataNode zTXt_node = new IIOMetadataNode("zTXtEntry");
zTXt_node.setAttribute("keyword", (String) zTXt_keyword.get(i));
int cm = ((Integer) zTXt_compressionMethod.get(i)).intValue();
zTXt_node.setAttribute("compressionMethod", zTXt_compressionMethodNames[cm]);
zTXt_node.setAttribute("text", (String) zTXt_text.get(i));
zTXt_parent.appendChild(zTXt_node);
}
root.appendChild(zTXt_parent);
}
// Unknown chunks
if (unknownChunkType.size() > 0) {
IIOMetadataNode unknown_parent = new IIOMetadataNode("UnknownChunks");
for (int i = 0; i < unknownChunkType.size(); i++) {
IIOMetadataNode unknown_node = new IIOMetadataNode("UnknownChunk");
unknown_node.setAttribute("type", (String) unknownChunkType.get(i));
unknown_node.setUserObject((byte[]) unknownChunkData.get(i));
unknown_parent.appendChild(unknown_node);
}
root.appendChild(unknown_parent);
}
return root;
}
use of javax.imageio.metadata.IIOMetadataNode in project jdk8u_jdk by JetBrains.
the class PNGMetadata method getStandardTextNode.
public IIOMetadataNode getStandardTextNode() {
int numEntries = tEXt_keyword.size() + iTXt_keyword.size() + zTXt_keyword.size();
if (numEntries == 0) {
return null;
}
IIOMetadataNode text_node = new IIOMetadataNode("Text");
// scratch node
IIOMetadataNode node = null;
for (int i = 0; i < tEXt_keyword.size(); i++) {
node = new IIOMetadataNode("TextEntry");
node.setAttribute("keyword", (String) tEXt_keyword.get(i));
node.setAttribute("value", (String) tEXt_text.get(i));
node.setAttribute("encoding", "ISO-8859-1");
node.setAttribute("compression", "none");
text_node.appendChild(node);
}
for (int i = 0; i < iTXt_keyword.size(); i++) {
node = new IIOMetadataNode("TextEntry");
node.setAttribute("keyword", iTXt_keyword.get(i));
node.setAttribute("value", iTXt_text.get(i));
node.setAttribute("language", iTXt_languageTag.get(i));
if (iTXt_compressionFlag.get(i)) {
node.setAttribute("compression", "zip");
} else {
node.setAttribute("compression", "none");
}
text_node.appendChild(node);
}
for (int i = 0; i < zTXt_keyword.size(); i++) {
node = new IIOMetadataNode("TextEntry");
node.setAttribute("keyword", (String) zTXt_keyword.get(i));
node.setAttribute("value", (String) zTXt_text.get(i));
node.setAttribute("compression", "zip");
text_node.appendChild(node);
}
return text_node;
}
use of javax.imageio.metadata.IIOMetadataNode in project jdk8u_jdk by JetBrains.
the class SOSMarkerSegment method getNativeNode.
IIOMetadataNode getNativeNode() {
IIOMetadataNode node = new IIOMetadataNode("sos");
node.setAttribute("numScanComponents", Integer.toString(componentSpecs.length));
node.setAttribute("startSpectralSelection", Integer.toString(startSpectralSelection));
node.setAttribute("endSpectralSelection", Integer.toString(endSpectralSelection));
node.setAttribute("approxHigh", Integer.toString(approxHigh));
node.setAttribute("approxLow", Integer.toString(approxLow));
for (int i = 0; i < componentSpecs.length; i++) {
node.appendChild(componentSpecs[i].getNativeNode());
}
return node;
}
use of javax.imageio.metadata.IIOMetadataNode in project jdk8u_jdk by JetBrains.
the class PNGMetadata method getStandardTransparencyNode.
public IIOMetadataNode getStandardTransparencyNode() {
IIOMetadataNode transparency_node = new IIOMetadataNode("Transparency");
// scratch node
IIOMetadataNode node = null;
node = new IIOMetadataNode("Alpha");
boolean hasAlpha = (IHDR_colorType == PNGImageReader.PNG_COLOR_RGB_ALPHA) || (IHDR_colorType == PNGImageReader.PNG_COLOR_GRAY_ALPHA) || (IHDR_colorType == PNGImageReader.PNG_COLOR_PALETTE && tRNS_present && (tRNS_colorType == IHDR_colorType) && (tRNS_alpha != null));
node.setAttribute("value", hasAlpha ? "nonpremultipled" : "none");
transparency_node.appendChild(node);
if (tRNS_present) {
node = new IIOMetadataNode("TransparentColor");
if (tRNS_colorType == PNGImageReader.PNG_COLOR_RGB) {
node.setAttribute("value", Integer.toString(tRNS_red) + " " + Integer.toString(tRNS_green) + " " + Integer.toString(tRNS_blue));
} else if (tRNS_colorType == PNGImageReader.PNG_COLOR_GRAY) {
node.setAttribute("value", Integer.toString(tRNS_gray));
}
transparency_node.appendChild(node);
}
return transparency_node;
}
use of javax.imageio.metadata.IIOMetadataNode in project jdk8u_jdk by JetBrains.
the class PNGMetadata method getStandardDataNode.
public IIOMetadataNode getStandardDataNode() {
IIOMetadataNode data_node = new IIOMetadataNode("Data");
// scratch node
IIOMetadataNode node = null;
node = new IIOMetadataNode("PlanarConfiguration");
node.setAttribute("value", "PixelInterleaved");
data_node.appendChild(node);
node = new IIOMetadataNode("SampleFormat");
node.setAttribute("value", IHDR_colorType == PNGImageReader.PNG_COLOR_PALETTE ? "Index" : "UnsignedIntegral");
data_node.appendChild(node);
String bitDepth = Integer.toString(IHDR_bitDepth);
node = new IIOMetadataNode("BitsPerSample");
node.setAttribute("value", repeat(bitDepth, getNumChannels()));
data_node.appendChild(node);
if (sBIT_present) {
node = new IIOMetadataNode("SignificantBitsPerSample");
String sbits;
if (sBIT_colorType == PNGImageReader.PNG_COLOR_GRAY || sBIT_colorType == PNGImageReader.PNG_COLOR_GRAY_ALPHA) {
sbits = Integer.toString(sBIT_grayBits);
} else {
// sBIT_colorType == PNGImageReader.PNG_COLOR_RGB ||
// sBIT_colorType == PNGImageReader.PNG_COLOR_RGB_ALPHA
sbits = Integer.toString(sBIT_redBits) + " " + Integer.toString(sBIT_greenBits) + " " + Integer.toString(sBIT_blueBits);
}
if (sBIT_colorType == PNGImageReader.PNG_COLOR_GRAY_ALPHA || sBIT_colorType == PNGImageReader.PNG_COLOR_RGB_ALPHA) {
sbits += " " + Integer.toString(sBIT_alphaBits);
}
node.setAttribute("value", sbits);
data_node.appendChild(node);
}
return data_node;
}
Aggregations