feat(jdk8): move files to new folder to avoid resources compiled.

This commit is contained in:
2025-09-07 15:25:52 +08:00
parent 3f0047bf6f
commit 8c35cfb1c0
17415 changed files with 217 additions and 213 deletions

View File

@@ -0,0 +1,446 @@
/*
* Copyright (c) 2000, 2005, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.imageio.plugins.gif;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import javax.imageio.ImageTypeSpecifier;
import javax.imageio.metadata.IIOInvalidTreeException;
import javax.imageio.metadata.IIOMetadata;
import javax.imageio.metadata.IIOMetadataNode;
import javax.imageio.metadata.IIOMetadataFormat;
import javax.imageio.metadata.IIOMetadataFormatImpl;
import org.w3c.dom.Node;
public class GIFImageMetadata extends GIFMetadata {
// package scope
static final String
nativeMetadataFormatName = "javax_imageio_gif_image_1.0";
static final String[] disposalMethodNames = {
"none",
"doNotDispose",
"restoreToBackgroundColor",
"restoreToPrevious",
"undefinedDisposalMethod4",
"undefinedDisposalMethod5",
"undefinedDisposalMethod6",
"undefinedDisposalMethod7"
};
// Fields from Image Descriptor
public int imageLeftPosition;
public int imageTopPosition;
public int imageWidth;
public int imageHeight;
public boolean interlaceFlag = false;
public boolean sortFlag = false;
public byte[] localColorTable = null;
// Fields from Graphic Control Extension
public int disposalMethod = 0;
public boolean userInputFlag = false;
public boolean transparentColorFlag = false;
public int delayTime = 0;
public int transparentColorIndex = 0;
// Fields from Plain Text Extension
public boolean hasPlainTextExtension = false;
public int textGridLeft;
public int textGridTop;
public int textGridWidth;
public int textGridHeight;
public int characterCellWidth;
public int characterCellHeight;
public int textForegroundColor;
public int textBackgroundColor;
public byte[] text;
// Fields from ApplicationExtension
// List of byte[]
public List applicationIDs = null; // new ArrayList();
// List of byte[]
public List authenticationCodes = null; // new ArrayList();
// List of byte[]
public List applicationData = null; // new ArrayList();
// Fields from CommentExtension
// List of byte[]
public List comments = null; // new ArrayList();
protected GIFImageMetadata(boolean standardMetadataFormatSupported,
String nativeMetadataFormatName,
String nativeMetadataFormatClassName,
String[] extraMetadataFormatNames,
String[] extraMetadataFormatClassNames)
{
super(standardMetadataFormatSupported,
nativeMetadataFormatName,
nativeMetadataFormatClassName,
extraMetadataFormatNames,
extraMetadataFormatClassNames);
}
public GIFImageMetadata() {
this(true,
nativeMetadataFormatName,
"com.sun.imageio.plugins.gif.GIFImageMetadataFormat",
null, null);
}
public boolean isReadOnly() {
return true;
}
public Node getAsTree(String formatName) {
if (formatName.equals(nativeMetadataFormatName)) {
return getNativeTree();
} else if (formatName.equals
(IIOMetadataFormatImpl.standardMetadataFormatName)) {
return getStandardTree();
} else {
throw new IllegalArgumentException("Not a recognized format!");
}
}
private String toISO8859(byte[] data) {
try {
return new String(data, "ISO-8859-1");
} catch (UnsupportedEncodingException e) {
return "";
}
}
private Node getNativeTree() {
IIOMetadataNode node; // scratch node
IIOMetadataNode root =
new IIOMetadataNode(nativeMetadataFormatName);
// Image descriptor
node = new IIOMetadataNode("ImageDescriptor");
node.setAttribute("imageLeftPosition",
Integer.toString(imageLeftPosition));
node.setAttribute("imageTopPosition",
Integer.toString(imageTopPosition));
node.setAttribute("imageWidth", Integer.toString(imageWidth));
node.setAttribute("imageHeight", Integer.toString(imageHeight));
node.setAttribute("interlaceFlag",
interlaceFlag ? "TRUE" : "FALSE");
root.appendChild(node);
// Local color table
if (localColorTable != null) {
node = new IIOMetadataNode("LocalColorTable");
int numEntries = localColorTable.length/3;
node.setAttribute("sizeOfLocalColorTable",
Integer.toString(numEntries));
node.setAttribute("sortFlag",
sortFlag ? "TRUE" : "FALSE");
for (int i = 0; i < numEntries; i++) {
IIOMetadataNode entry =
new IIOMetadataNode("ColorTableEntry");
entry.setAttribute("index", Integer.toString(i));
int r = localColorTable[3*i] & 0xff;
int g = localColorTable[3*i + 1] & 0xff;
int b = localColorTable[3*i + 2] & 0xff;
entry.setAttribute("red", Integer.toString(r));
entry.setAttribute("green", Integer.toString(g));
entry.setAttribute("blue", Integer.toString(b));
node.appendChild(entry);
}
root.appendChild(node);
}
// Graphic control extension
node = new IIOMetadataNode("GraphicControlExtension");
node.setAttribute("disposalMethod",
disposalMethodNames[disposalMethod]);
node.setAttribute("userInputFlag",
userInputFlag ? "TRUE" : "FALSE");
node.setAttribute("transparentColorFlag",
transparentColorFlag ? "TRUE" : "FALSE");
node.setAttribute("delayTime",
Integer.toString(delayTime));
node.setAttribute("transparentColorIndex",
Integer.toString(transparentColorIndex));
root.appendChild(node);
if (hasPlainTextExtension) {
node = new IIOMetadataNode("PlainTextExtension");
node.setAttribute("textGridLeft",
Integer.toString(textGridLeft));
node.setAttribute("textGridTop",
Integer.toString(textGridTop));
node.setAttribute("textGridWidth",
Integer.toString(textGridWidth));
node.setAttribute("textGridHeight",
Integer.toString(textGridHeight));
node.setAttribute("characterCellWidth",
Integer.toString(characterCellWidth));
node.setAttribute("characterCellHeight",
Integer.toString(characterCellHeight));
node.setAttribute("textForegroundColor",
Integer.toString(textForegroundColor));
node.setAttribute("textBackgroundColor",
Integer.toString(textBackgroundColor));
node.setAttribute("text", toISO8859(text));
root.appendChild(node);
}
// Application extensions
int numAppExtensions = applicationIDs == null ?
0 : applicationIDs.size();
if (numAppExtensions > 0) {
node = new IIOMetadataNode("ApplicationExtensions");
for (int i = 0; i < numAppExtensions; i++) {
IIOMetadataNode appExtNode =
new IIOMetadataNode("ApplicationExtension");
byte[] applicationID = (byte[])applicationIDs.get(i);
appExtNode.setAttribute("applicationID",
toISO8859(applicationID));
byte[] authenticationCode = (byte[])authenticationCodes.get(i);
appExtNode.setAttribute("authenticationCode",
toISO8859(authenticationCode));
byte[] appData = (byte[])applicationData.get(i);
appExtNode.setUserObject((byte[])appData.clone());
node.appendChild(appExtNode);
}
root.appendChild(node);
}
// Comment extensions
int numComments = comments == null ? 0 : comments.size();
if (numComments > 0) {
node = new IIOMetadataNode("CommentExtensions");
for (int i = 0; i < numComments; i++) {
IIOMetadataNode commentNode =
new IIOMetadataNode("CommentExtension");
byte[] comment = (byte[])comments.get(i);
commentNode.setAttribute("value", toISO8859(comment));
node.appendChild(commentNode);
}
root.appendChild(node);
}
return root;
}
public IIOMetadataNode getStandardChromaNode() {
IIOMetadataNode chroma_node = new IIOMetadataNode("Chroma");
IIOMetadataNode node = null; // scratch node
node = new IIOMetadataNode("ColorSpaceType");
node.setAttribute("name", "RGB");
chroma_node.appendChild(node);
node = new IIOMetadataNode("NumChannels");
node.setAttribute("value", transparentColorFlag ? "4" : "3");
chroma_node.appendChild(node);
// Gamma not in format
node = new IIOMetadataNode("BlackIsZero");
node.setAttribute("value", "TRUE");
chroma_node.appendChild(node);
if (localColorTable != null) {
node = new IIOMetadataNode("Palette");
int numEntries = localColorTable.length/3;
for (int i = 0; i < numEntries; i++) {
IIOMetadataNode entry =
new IIOMetadataNode("PaletteEntry");
entry.setAttribute("index", Integer.toString(i));
entry.setAttribute("red",
Integer.toString(localColorTable[3*i] & 0xff));
entry.setAttribute("green",
Integer.toString(localColorTable[3*i + 1] & 0xff));
entry.setAttribute("blue",
Integer.toString(localColorTable[3*i + 2] & 0xff));
node.appendChild(entry);
}
chroma_node.appendChild(node);
}
// BackgroundIndex not in image
// BackgroundColor not in format
return chroma_node;
}
public IIOMetadataNode getStandardCompressionNode() {
IIOMetadataNode compression_node = new IIOMetadataNode("Compression");
IIOMetadataNode node = null; // scratch node
node = new IIOMetadataNode("CompressionTypeName");
node.setAttribute("value", "lzw");
compression_node.appendChild(node);
node = new IIOMetadataNode("Lossless");
node.setAttribute("value", "TRUE");
compression_node.appendChild(node);
node = new IIOMetadataNode("NumProgressiveScans");
node.setAttribute("value", interlaceFlag ? "4" : "1");
compression_node.appendChild(node);
// BitRate not in format
return compression_node;
}
public IIOMetadataNode getStandardDataNode() {
IIOMetadataNode data_node = new IIOMetadataNode("Data");
IIOMetadataNode node = null; // scratch node
// PlanarConfiguration not in format
node = new IIOMetadataNode("SampleFormat");
node.setAttribute("value", "Index");
data_node.appendChild(node);
// BitsPerSample not in image
// SignificantBitsPerSample not in format
// SampleMSB not in format
return data_node;
}
public IIOMetadataNode getStandardDimensionNode() {
IIOMetadataNode dimension_node = new IIOMetadataNode("Dimension");
IIOMetadataNode node = null; // scratch node
// PixelAspectRatio not in image
node = new IIOMetadataNode("ImageOrientation");
node.setAttribute("value", "Normal");
dimension_node.appendChild(node);
// HorizontalPixelSize not in format
// VerticalPixelSize not in format
// HorizontalPhysicalPixelSpacing not in format
// VerticalPhysicalPixelSpacing not in format
// HorizontalPosition not in format
// VerticalPosition not in format
node = new IIOMetadataNode("HorizontalPixelOffset");
node.setAttribute("value", Integer.toString(imageLeftPosition));
dimension_node.appendChild(node);
node = new IIOMetadataNode("VerticalPixelOffset");
node.setAttribute("value", Integer.toString(imageTopPosition));
dimension_node.appendChild(node);
// HorizontalScreenSize not in image
// VerticalScreenSize not in image
return dimension_node;
}
// Document not in image
public IIOMetadataNode getStandardTextNode() {
if (comments == null) {
return null;
}
Iterator commentIter = comments.iterator();
if (!commentIter.hasNext()) {
return null;
}
IIOMetadataNode text_node = new IIOMetadataNode("Text");
IIOMetadataNode node = null; // scratch node
while (commentIter.hasNext()) {
byte[] comment = (byte[])commentIter.next();
String s = null;
try {
s = new String(comment, "ISO-8859-1");
} catch (UnsupportedEncodingException e) {
throw new RuntimeException("Encoding ISO-8859-1 unknown!");
}
node = new IIOMetadataNode("TextEntry");
node.setAttribute("value", s);
node.setAttribute("encoding", "ISO-8859-1");
node.setAttribute("compression", "none");
text_node.appendChild(node);
}
return text_node;
}
public IIOMetadataNode getStandardTransparencyNode() {
if (!transparentColorFlag) {
return null;
}
IIOMetadataNode transparency_node =
new IIOMetadataNode("Transparency");
IIOMetadataNode node = null; // scratch node
// Alpha not in format
node = new IIOMetadataNode("TransparentIndex");
node.setAttribute("value",
Integer.toString(transparentColorIndex));
transparency_node.appendChild(node);
// TransparentColor not in format
// TileTransparencies not in format
// TileOpacities not in format
return transparency_node;
}
public void setFromTree(String formatName, Node root)
throws IIOInvalidTreeException
{
throw new IllegalStateException("Metadata is read-only!");
}
protected void mergeNativeTree(Node root) throws IIOInvalidTreeException
{
throw new IllegalStateException("Metadata is read-only!");
}
protected void mergeStandardTree(Node root) throws IIOInvalidTreeException
{
throw new IllegalStateException("Metadata is read-only!");
}
public void reset() {
throw new IllegalStateException("Metadata is read-only!");
}
}

View File

@@ -0,0 +1,171 @@
/*
* Copyright (c) 2001, 2004, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.imageio.plugins.gif;
import java.util.Arrays;
import javax.imageio.ImageTypeSpecifier;
import javax.imageio.metadata.IIOMetadataFormat;
import javax.imageio.metadata.IIOMetadataFormatImpl;
public class GIFImageMetadataFormat extends IIOMetadataFormatImpl {
private static IIOMetadataFormat instance = null;
private GIFImageMetadataFormat() {
super(GIFImageMetadata.nativeMetadataFormatName,
CHILD_POLICY_SOME);
// root -> ImageDescriptor
addElement("ImageDescriptor",
GIFImageMetadata.nativeMetadataFormatName,
CHILD_POLICY_EMPTY);
addAttribute("ImageDescriptor", "imageLeftPosition",
DATATYPE_INTEGER, true, null,
"0", "65535", true, true);
addAttribute("ImageDescriptor", "imageTopPosition",
DATATYPE_INTEGER, true, null,
"0", "65535", true, true);
addAttribute("ImageDescriptor", "imageWidth",
DATATYPE_INTEGER, true, null,
"1", "65535", true, true);
addAttribute("ImageDescriptor", "imageHeight",
DATATYPE_INTEGER, true, null,
"1", "65535", true, true);
addBooleanAttribute("ImageDescriptor", "interlaceFlag",
false, false);
// root -> LocalColorTable
addElement("LocalColorTable",
GIFImageMetadata.nativeMetadataFormatName,
2, 256);
addAttribute("LocalColorTable", "sizeOfLocalColorTable",
DATATYPE_INTEGER, true, null,
Arrays.asList(GIFStreamMetadata.colorTableSizes));
addBooleanAttribute("LocalColorTable", "sortFlag",
false, false);
// root -> LocalColorTable -> ColorTableEntry
addElement("ColorTableEntry", "LocalColorTable",
CHILD_POLICY_EMPTY);
addAttribute("ColorTableEntry", "index",
DATATYPE_INTEGER, true, null,
"0", "255", true, true);
addAttribute("ColorTableEntry", "red",
DATATYPE_INTEGER, true, null,
"0", "255", true, true);
addAttribute("ColorTableEntry", "green",
DATATYPE_INTEGER, true, null,
"0", "255", true, true);
addAttribute("ColorTableEntry", "blue",
DATATYPE_INTEGER, true, null,
"0", "255", true, true);
// root -> GraphicControlExtension
addElement("GraphicControlExtension",
GIFImageMetadata.nativeMetadataFormatName,
CHILD_POLICY_EMPTY);
addAttribute("GraphicControlExtension", "disposalMethod",
DATATYPE_STRING, true, null,
Arrays.asList(GIFImageMetadata.disposalMethodNames));
addBooleanAttribute("GraphicControlExtension", "userInputFlag",
false, false);
addBooleanAttribute("GraphicControlExtension", "transparentColorFlag",
false, false);
addAttribute("GraphicControlExtension", "delayTime",
DATATYPE_INTEGER, true, null,
"0", "65535", true, true);
addAttribute("GraphicControlExtension", "transparentColorIndex",
DATATYPE_INTEGER, true, null,
"0", "255", true, true);
// root -> PlainTextExtension
addElement("PlainTextExtension",
GIFImageMetadata.nativeMetadataFormatName,
CHILD_POLICY_EMPTY);
addAttribute("PlainTextExtension", "textGridLeft",
DATATYPE_INTEGER, true, null,
"0", "65535", true, true);
addAttribute("PlainTextExtension", "textGridTop",
DATATYPE_INTEGER, true, null,
"0", "65535", true, true);
addAttribute("PlainTextExtension", "textGridWidth",
DATATYPE_INTEGER, true, null,
"1", "65535", true, true);
addAttribute("PlainTextExtension", "textGridHeight",
DATATYPE_INTEGER, true, null,
"1", "65535", true, true);
addAttribute("PlainTextExtension", "characterCellWidth",
DATATYPE_INTEGER, true, null,
"1", "65535", true, true);
addAttribute("PlainTextExtension", "characterCellHeight",
DATATYPE_INTEGER, true, null,
"1", "65535", true, true);
addAttribute("PlainTextExtension", "textForegroundColor",
DATATYPE_INTEGER, true, null,
"0", "255", true, true);
addAttribute("PlainTextExtension", "textBackgroundColor",
DATATYPE_INTEGER, true, null,
"0", "255", true, true);
// root -> ApplicationExtensions
addElement("ApplicationExtensions",
GIFImageMetadata.nativeMetadataFormatName,
1, Integer.MAX_VALUE);
// root -> ApplicationExtensions -> ApplicationExtension
addElement("ApplicationExtension", "ApplicationExtensions",
CHILD_POLICY_EMPTY);
addAttribute("ApplicationExtension", "applicationID",
DATATYPE_STRING, true, null);
addAttribute("ApplicationExtension", "authenticationCode",
DATATYPE_STRING, true, null);
addObjectValue("ApplicationExtension", byte.class,
0, Integer.MAX_VALUE);
// root -> CommentExtensions
addElement("CommentExtensions",
GIFImageMetadata.nativeMetadataFormatName,
1, Integer.MAX_VALUE);
// root -> CommentExtensions -> CommentExtension
addElement("CommentExtension", "CommentExtensions",
CHILD_POLICY_EMPTY);
addAttribute("CommentExtension", "value",
DATATYPE_STRING, true, null);
}
public boolean canNodeAppear(String elementName,
ImageTypeSpecifier imageType) {
return true;
}
public static synchronized IIOMetadataFormat getInstance() {
if (instance == null) {
instance = new GIFImageMetadataFormat();
}
return instance;
}
}

View File

@@ -0,0 +1,104 @@
/*
* Copyright (c) 2001, 2005, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.imageio.plugins.gif;
import java.util.ListResourceBundle;
public class GIFImageMetadataFormatResources extends ListResourceBundle {
public GIFImageMetadataFormatResources() {}
protected Object[][] getContents() {
return new Object[][] {
// Node name, followed by description
{ "ImageDescriptor", "The image descriptor" },
{ "LocalColorTable", "The local color table" },
{ "ColorTableEntry", "A local color table entry" },
{ "GraphicControlExtension", "A graphic control extension" },
{ "PlainTextExtension", "A plain text (text grid) extension" },
{ "ApplicationExtensions", "A set of application extensions" },
{ "ApplicationExtension", "An application extension" },
{ "CommentExtensions", "A set of comments" },
{ "CommentExtension", "A comment" },
// Node name + "/" + AttributeName, followed by description
{ "ImageDescriptor/imageLeftPosition",
"The X offset of the image relative to the screen origin" },
{ "ImageDescriptor/imageTopPosition",
"The Y offset of the image relative to the screen origin" },
{ "ImageDescriptor/imageWidth",
"The width of the image" },
{ "ImageDescriptor/imageHeight",
"The height of the image" },
{ "ImageDescriptor/interlaceFlag",
"True if the image is stored using interlacing" },
{ "LocalColorTable/sizeOfLocalColorTable",
"The number of entries in the local color table" },
{ "LocalColorTable/sortFlag",
"True if the local color table is sorted by frequency" },
{ "ColorTableEntry/index", "The index of the color table entry" },
{ "ColorTableEntry/red",
"The red value for the color table entry" },
{ "ColorTableEntry/green",
"The green value for the color table entry" },
{ "ColorTableEntry/blue",
"The blue value for the color table entry" },
{ "GraphicControlExtension/disposalMethod",
"The disposal method for this frame" },
{ "GraphicControlExtension/userInputFlag",
"True if the frame should be advanced based on user input" },
{ "GraphicControlExtension/transparentColorFlag",
"True if a transparent color exists" },
{ "GraphicControlExtension/delayTime",
"The time to delay between frames, in hundredths of a second" },
{ "GraphicControlExtension/transparentColorIndex",
"The transparent color, if transparentColorFlag is true" },
{ "PlainTextExtension/textGridLeft",
"The X offset of the text grid" },
{ "PlainTextExtension/textGridTop",
"The Y offset of the text grid" },
{ "PlainTextExtension/textGridWidth",
"The number of columns in the text grid" },
{ "PlainTextExtension/textGridHeight",
"The number of rows in the text grid" },
{ "PlainTextExtension/characterCellWidth",
"The width of a character cell" },
{ "PlainTextExtension/characterCellHeight",
"The height of a character cell" },
{ "PlainTextExtension/textForegroundColor",
"The text foreground color index" },
{ "PlainTextExtension/textBackgroundColor",
"The text background color index" },
{ "ApplicationExtension/applicationID",
"The application ID" },
{ "ApplicationExtension/authenticationCode",
"The authentication code" },
{ "CommentExtension/value", "The comment" },
};
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,99 @@
/*
* Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.imageio.plugins.gif;
import java.io.IOException;
import java.util.Locale;
import java.util.Iterator;
import javax.imageio.ImageReader;
import javax.imageio.metadata.IIOMetadataFormat;
import javax.imageio.metadata.IIOMetadataFormatImpl;
import javax.imageio.spi.ImageReaderSpi;
import javax.imageio.stream.ImageInputStream;
public class GIFImageReaderSpi extends ImageReaderSpi {
private static final String vendorName = "Oracle Corporation";
private static final String version = "1.0";
private static final String[] names = { "gif", "GIF" };
private static final String[] suffixes = { "gif" };
private static final String[] MIMETypes = { "image/gif" };
private static final String readerClassName =
"com.sun.imageio.plugins.gif.GIFImageReader";
private static final String[] writerSpiNames = {
"com.sun.imageio.plugins.gif.GIFImageWriterSpi"
};
public GIFImageReaderSpi() {
super(vendorName,
version,
names,
suffixes,
MIMETypes,
readerClassName,
new Class[] { ImageInputStream.class },
writerSpiNames,
true,
GIFStreamMetadata.nativeMetadataFormatName,
"com.sun.imageio.plugins.gif.GIFStreamMetadataFormat",
null, null,
true,
GIFImageMetadata.nativeMetadataFormatName,
"com.sun.imageio.plugins.gif.GIFImageMetadataFormat",
null, null
);
}
public String getDescription(Locale locale) {
return "Standard GIF image reader";
}
public boolean canDecodeInput(Object input) throws IOException {
if (!(input instanceof ImageInputStream)) {
return false;
}
ImageInputStream stream = (ImageInputStream)input;
byte[] b = new byte[6];
stream.mark();
stream.readFully(b);
stream.reset();
return b[0] == 'G' && b[1] == 'I' && b[2] == 'F' && b[3] == '8' &&
(b[4] == '7' || b[4] == '9') && b[5] == 'a';
}
public ImageReader createReaderInstance(Object extension) {
return new GIFImageReader(this);
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,104 @@
/*
* Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.imageio.plugins.gif;
import java.awt.image.ColorModel;
import java.awt.image.SampleModel;
import java.util.Locale;
import javax.imageio.ImageTypeSpecifier;
import javax.imageio.ImageWriter;
import javax.imageio.spi.ImageWriterSpi;
import javax.imageio.stream.ImageOutputStream;
import com.sun.imageio.plugins.common.PaletteBuilder;
public class GIFImageWriterSpi extends ImageWriterSpi {
private static final String vendorName = "Oracle Corporation";
private static final String version = "1.0";
private static final String[] names = { "gif", "GIF" };
private static final String[] suffixes = { "gif" };
private static final String[] MIMETypes = { "image/gif" };
private static final String writerClassName =
"com.sun.imageio.plugins.gif.GIFImageWriter";
private static final String[] readerSpiNames = {
"com.sun.imageio.plugins.gif.GIFImageReaderSpi"
};
public GIFImageWriterSpi() {
super(vendorName,
version,
names,
suffixes,
MIMETypes,
writerClassName,
new Class[] { ImageOutputStream.class },
readerSpiNames,
true,
GIFWritableStreamMetadata.NATIVE_FORMAT_NAME,
"com.sun.imageio.plugins.gif.GIFStreamMetadataFormat",
null, null,
true,
GIFWritableImageMetadata.NATIVE_FORMAT_NAME,
"com.sun.imageio.plugins.gif.GIFImageMetadataFormat",
null, null
);
}
public boolean canEncodeImage(ImageTypeSpecifier type) {
if (type == null) {
throw new IllegalArgumentException("type == null!");
}
SampleModel sm = type.getSampleModel();
ColorModel cm = type.getColorModel();
boolean canEncode = sm.getNumBands() == 1 &&
sm.getSampleSize(0) <= 8 &&
sm.getWidth() <= 65535 &&
sm.getHeight() <= 65535 &&
(cm == null || cm.getComponentSize()[0] <= 8);
if (canEncode) {
return true;
} else {
return PaletteBuilder.canCreatePalette(type);
}
}
public String getDescription(Locale locale) {
return "Standard GIF image writer";
}
public ImageWriter createWriterInstance(Object extension) {
return new GIFImageWriter(this);
}
}

View File

@@ -0,0 +1,317 @@
/*
* Copyright (c) 2005, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.imageio.plugins.gif;
import javax.imageio.metadata.IIOInvalidTreeException;
import javax.imageio.metadata.IIOMetadata;
import javax.imageio.metadata.IIOMetadataFormatImpl;
import org.w3c.dom.Node;
/**
* Class which adds utility DOM element attribute access methods to
* <code>IIOMetadata</code> for subclass use.
*/
abstract class GIFMetadata extends IIOMetadata {
/**
* Represents an undefined value of integer attributes.
*/
static final int UNDEFINED_INTEGER_VALUE = -1;
//
// Note: These attribute methods were shamelessly lifted from
// com.sun.imageio.plugins.png.PNGMetadata and modified.
//
// Shorthand for throwing an IIOInvalidTreeException
protected static void fatal(Node node, String reason)
throws IIOInvalidTreeException {
throw new IIOInvalidTreeException(reason, node);
}
// Get an integer-valued attribute
protected static String getStringAttribute(Node node, String name,
String defaultValue,
boolean required,
String[] range)
throws IIOInvalidTreeException {
Node attr = node.getAttributes().getNamedItem(name);
if (attr == null) {
if (!required) {
return defaultValue;
} else {
fatal(node, "Required attribute " + name + " not present!");
}
}
String value = attr.getNodeValue();
if (range != null) {
if (value == null) {
fatal(node,
"Null value for "+node.getNodeName()+
" attribute "+name+"!");
}
boolean validValue = false;
int len = range.length;
for (int i = 0; i < len; i++) {
if (value.equals(range[i])) {
validValue = true;
break;
}
}
if (!validValue) {
fatal(node,
"Bad value for "+node.getNodeName()+
" attribute "+name+"!");
}
}
return value;
}
// Get an integer-valued attribute
protected static int getIntAttribute(Node node, String name,
int defaultValue, boolean required,
boolean bounded, int min, int max)
throws IIOInvalidTreeException {
String value = getStringAttribute(node, name, null, required, null);
if (value == null || "".equals(value)) {
return defaultValue;
}
int intValue = defaultValue;
try {
intValue = Integer.parseInt(value);
} catch (NumberFormatException e) {
fatal(node,
"Bad value for "+node.getNodeName()+
" attribute "+name+"!");
}
if (bounded && (intValue < min || intValue > max)) {
fatal(node,
"Bad value for "+node.getNodeName()+
" attribute "+name+"!");
}
return intValue;
}
// Get a float-valued attribute
protected static float getFloatAttribute(Node node, String name,
float defaultValue,
boolean required)
throws IIOInvalidTreeException {
String value = getStringAttribute(node, name, null, required, null);
if (value == null) {
return defaultValue;
}
return Float.parseFloat(value);
}
// Get a required integer-valued attribute
protected static int getIntAttribute(Node node, String name,
boolean bounded, int min, int max)
throws IIOInvalidTreeException {
return getIntAttribute(node, name, -1, true, bounded, min, max);
}
// Get a required float-valued attribute
protected static float getFloatAttribute(Node node, String name)
throws IIOInvalidTreeException {
return getFloatAttribute(node, name, -1.0F, true);
}
// Get a boolean-valued attribute
protected static boolean getBooleanAttribute(Node node, String name,
boolean defaultValue,
boolean required)
throws IIOInvalidTreeException {
Node attr = node.getAttributes().getNamedItem(name);
if (attr == null) {
if (!required) {
return defaultValue;
} else {
fatal(node, "Required attribute " + name + " not present!");
}
}
String value = attr.getNodeValue();
// Allow lower case booleans for backward compatibility, #5082756
if (value.equals("TRUE") || value.equals("true")) {
return true;
} else if (value.equals("FALSE") || value.equals("false")) {
return false;
} else {
fatal(node, "Attribute " + name + " must be 'TRUE' or 'FALSE'!");
return false;
}
}
// Get a required boolean-valued attribute
protected static boolean getBooleanAttribute(Node node, String name)
throws IIOInvalidTreeException {
return getBooleanAttribute(node, name, false, true);
}
// Get an enumerated attribute as an index into a String array
protected static int getEnumeratedAttribute(Node node,
String name,
String[] legalNames,
int defaultValue,
boolean required)
throws IIOInvalidTreeException {
Node attr = node.getAttributes().getNamedItem(name);
if (attr == null) {
if (!required) {
return defaultValue;
} else {
fatal(node, "Required attribute " + name + " not present!");
}
}
String value = attr.getNodeValue();
for (int i = 0; i < legalNames.length; i++) {
if(value.equals(legalNames[i])) {
return i;
}
}
fatal(node, "Illegal value for attribute " + name + "!");
return -1;
}
// Get a required enumerated attribute as an index into a String array
protected static int getEnumeratedAttribute(Node node,
String name,
String[] legalNames)
throws IIOInvalidTreeException {
return getEnumeratedAttribute(node, name, legalNames, -1, true);
}
// Get a String-valued attribute
protected static String getAttribute(Node node, String name,
String defaultValue, boolean required)
throws IIOInvalidTreeException {
Node attr = node.getAttributes().getNamedItem(name);
if (attr == null) {
if (!required) {
return defaultValue;
} else {
fatal(node, "Required attribute " + name + " not present!");
}
}
return attr.getNodeValue();
}
// Get a required String-valued attribute
protected static String getAttribute(Node node, String name)
throws IIOInvalidTreeException {
return getAttribute(node, name, null, true);
}
protected GIFMetadata(boolean standardMetadataFormatSupported,
String nativeMetadataFormatName,
String nativeMetadataFormatClassName,
String[] extraMetadataFormatNames,
String[] extraMetadataFormatClassNames) {
super(standardMetadataFormatSupported,
nativeMetadataFormatName,
nativeMetadataFormatClassName,
extraMetadataFormatNames,
extraMetadataFormatClassNames);
}
public void mergeTree(String formatName, Node root)
throws IIOInvalidTreeException {
if (formatName.equals(nativeMetadataFormatName)) {
if (root == null) {
throw new IllegalArgumentException("root == null!");
}
mergeNativeTree(root);
} else if (formatName.equals
(IIOMetadataFormatImpl.standardMetadataFormatName)) {
if (root == null) {
throw new IllegalArgumentException("root == null!");
}
mergeStandardTree(root);
} else {
throw new IllegalArgumentException("Not a recognized format!");
}
}
protected byte[] getColorTable(Node colorTableNode,
String entryNodeName,
boolean lengthExpected,
int expectedLength)
throws IIOInvalidTreeException {
byte[] red = new byte[256];
byte[] green = new byte[256];
byte[] blue = new byte[256];
int maxIndex = -1;
Node entry = colorTableNode.getFirstChild();
if (entry == null) {
fatal(colorTableNode, "Palette has no entries!");
}
while (entry != null) {
if (!entry.getNodeName().equals(entryNodeName)) {
fatal(colorTableNode,
"Only a "+entryNodeName+" may be a child of a "+
entry.getNodeName()+"!");
}
int index = getIntAttribute(entry, "index", true, 0, 255);
if (index > maxIndex) {
maxIndex = index;
}
red[index] = (byte)getIntAttribute(entry, "red", true, 0, 255);
green[index] = (byte)getIntAttribute(entry, "green", true, 0, 255);
blue[index] = (byte)getIntAttribute(entry, "blue", true, 0, 255);
entry = entry.getNextSibling();
}
int numEntries = maxIndex + 1;
if (lengthExpected && numEntries != expectedLength) {
fatal(colorTableNode, "Unexpected length for palette!");
}
byte[] colorTable = new byte[3*numEntries];
for (int i = 0, j = 0; i < numEntries; i++) {
colorTable[j++] = red[i];
colorTable[j++] = green[i];
colorTable[j++] = blue[i];
}
return colorTable;
}
protected abstract void mergeNativeTree(Node root)
throws IIOInvalidTreeException;
protected abstract void mergeStandardTree(Node root)
throws IIOInvalidTreeException;
}

View File

@@ -0,0 +1,317 @@
/*
* Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.imageio.plugins.gif;
import javax.imageio.metadata.IIOInvalidTreeException;
import javax.imageio.metadata.IIOMetadataNode;
import javax.imageio.metadata.IIOMetadataFormatImpl;
import org.w3c.dom.Node;
// TODO - document elimination of globalColorTableFlag
public class GIFStreamMetadata extends GIFMetadata {
// package scope
static final String
nativeMetadataFormatName = "javax_imageio_gif_stream_1.0";
static final String[] versionStrings = { "87a", "89a" };
public String version; // 87a or 89a
public int logicalScreenWidth;
public int logicalScreenHeight;
public int colorResolution; // 1 to 8
public int pixelAspectRatio;
public int backgroundColorIndex; // Valid if globalColorTable != null
public boolean sortFlag; // Valid if globalColorTable != null
static final String[] colorTableSizes = {
"2", "4", "8", "16", "32", "64", "128", "256"
};
// Set global color table flag in header to 0 if null, 1 otherwise
public byte[] globalColorTable = null;
protected GIFStreamMetadata(boolean standardMetadataFormatSupported,
String nativeMetadataFormatName,
String nativeMetadataFormatClassName,
String[] extraMetadataFormatNames,
String[] extraMetadataFormatClassNames)
{
super(standardMetadataFormatSupported,
nativeMetadataFormatName,
nativeMetadataFormatClassName,
extraMetadataFormatNames,
extraMetadataFormatClassNames);
}
public GIFStreamMetadata() {
this(true,
nativeMetadataFormatName,
"com.sun.imageio.plugins.gif.GIFStreamMetadataFormat",
null, null);
}
public boolean isReadOnly() {
return true;
}
public Node getAsTree(String formatName) {
if (formatName.equals(nativeMetadataFormatName)) {
return getNativeTree();
} else if (formatName.equals
(IIOMetadataFormatImpl.standardMetadataFormatName)) {
return getStandardTree();
} else {
throw new IllegalArgumentException("Not a recognized format!");
}
}
private Node getNativeTree() {
IIOMetadataNode node; // scratch node
IIOMetadataNode root =
new IIOMetadataNode(nativeMetadataFormatName);
node = new IIOMetadataNode("Version");
node.setAttribute("value", version);
root.appendChild(node);
// Image descriptor
node = new IIOMetadataNode("LogicalScreenDescriptor");
/* NB: At the moment we use empty strings to support undefined
* integer values in tree representation.
* We need to add better support for undefined/default values later.
*/
node.setAttribute("logicalScreenWidth",
logicalScreenWidth == UNDEFINED_INTEGER_VALUE ?
"" : Integer.toString(logicalScreenWidth));
node.setAttribute("logicalScreenHeight",
logicalScreenHeight == UNDEFINED_INTEGER_VALUE ?
"" : Integer.toString(logicalScreenHeight));
// Stored value plus one
node.setAttribute("colorResolution",
colorResolution == UNDEFINED_INTEGER_VALUE ?
"" : Integer.toString(colorResolution));
node.setAttribute("pixelAspectRatio",
Integer.toString(pixelAspectRatio));
root.appendChild(node);
if (globalColorTable != null) {
node = new IIOMetadataNode("GlobalColorTable");
int numEntries = globalColorTable.length/3;
node.setAttribute("sizeOfGlobalColorTable",
Integer.toString(numEntries));
node.setAttribute("backgroundColorIndex",
Integer.toString(backgroundColorIndex));
node.setAttribute("sortFlag",
sortFlag ? "TRUE" : "FALSE");
for (int i = 0; i < numEntries; i++) {
IIOMetadataNode entry =
new IIOMetadataNode("ColorTableEntry");
entry.setAttribute("index", Integer.toString(i));
int r = globalColorTable[3*i] & 0xff;
int g = globalColorTable[3*i + 1] & 0xff;
int b = globalColorTable[3*i + 2] & 0xff;
entry.setAttribute("red", Integer.toString(r));
entry.setAttribute("green", Integer.toString(g));
entry.setAttribute("blue", Integer.toString(b));
node.appendChild(entry);
}
root.appendChild(node);
}
return root;
}
public IIOMetadataNode getStandardChromaNode() {
IIOMetadataNode chroma_node = new IIOMetadataNode("Chroma");
IIOMetadataNode node = null; // scratch node
node = new IIOMetadataNode("ColorSpaceType");
node.setAttribute("name", "RGB");
chroma_node.appendChild(node);
node = new IIOMetadataNode("BlackIsZero");
node.setAttribute("value", "TRUE");
chroma_node.appendChild(node);
// NumChannels not in stream
// Gamma not in format
if (globalColorTable != null) {
node = new IIOMetadataNode("Palette");
int numEntries = globalColorTable.length/3;
for (int i = 0; i < numEntries; i++) {
IIOMetadataNode entry =
new IIOMetadataNode("PaletteEntry");
entry.setAttribute("index", Integer.toString(i));
entry.setAttribute("red",
Integer.toString(globalColorTable[3*i] & 0xff));
entry.setAttribute("green",
Integer.toString(globalColorTable[3*i + 1] & 0xff));
entry.setAttribute("blue",
Integer.toString(globalColorTable[3*i + 2] & 0xff));
node.appendChild(entry);
}
chroma_node.appendChild(node);
// backgroundColorIndex is valid iff there is a color table
node = new IIOMetadataNode("BackgroundIndex");
node.setAttribute("value", Integer.toString(backgroundColorIndex));
chroma_node.appendChild(node);
}
return chroma_node;
}
public IIOMetadataNode getStandardCompressionNode() {
IIOMetadataNode compression_node = new IIOMetadataNode("Compression");
IIOMetadataNode node = null; // scratch node
node = new IIOMetadataNode("CompressionTypeName");
node.setAttribute("value", "lzw");
compression_node.appendChild(node);
node = new IIOMetadataNode("Lossless");
node.setAttribute("value", "TRUE");
compression_node.appendChild(node);
// NumProgressiveScans not in stream
// BitRate not in format
return compression_node;
}
public IIOMetadataNode getStandardDataNode() {
IIOMetadataNode data_node = new IIOMetadataNode("Data");
IIOMetadataNode node = null; // scratch node
// PlanarConfiguration
node = new IIOMetadataNode("SampleFormat");
node.setAttribute("value", "Index");
data_node.appendChild(node);
node = new IIOMetadataNode("BitsPerSample");
node.setAttribute("value",
colorResolution == UNDEFINED_INTEGER_VALUE ?
"" : Integer.toString(colorResolution));
data_node.appendChild(node);
// SignificantBitsPerSample
// SampleMSB
return data_node;
}
public IIOMetadataNode getStandardDimensionNode() {
IIOMetadataNode dimension_node = new IIOMetadataNode("Dimension");
IIOMetadataNode node = null; // scratch node
node = new IIOMetadataNode("PixelAspectRatio");
float aspectRatio = 1.0F;
if (pixelAspectRatio != 0) {
aspectRatio = (pixelAspectRatio + 15)/64.0F;
}
node.setAttribute("value", Float.toString(aspectRatio));
dimension_node.appendChild(node);
node = new IIOMetadataNode("ImageOrientation");
node.setAttribute("value", "Normal");
dimension_node.appendChild(node);
// HorizontalPixelSize not in format
// VerticalPixelSize not in format
// HorizontalPhysicalPixelSpacing not in format
// VerticalPhysicalPixelSpacing not in format
// HorizontalPosition not in format
// VerticalPosition not in format
// HorizontalPixelOffset not in stream
// VerticalPixelOffset not in stream
node = new IIOMetadataNode("HorizontalScreenSize");
node.setAttribute("value",
logicalScreenWidth == UNDEFINED_INTEGER_VALUE ?
"" : Integer.toString(logicalScreenWidth));
dimension_node.appendChild(node);
node = new IIOMetadataNode("VerticalScreenSize");
node.setAttribute("value",
logicalScreenHeight == UNDEFINED_INTEGER_VALUE ?
"" : Integer.toString(logicalScreenHeight));
dimension_node.appendChild(node);
return dimension_node;
}
public IIOMetadataNode getStandardDocumentNode() {
IIOMetadataNode document_node = new IIOMetadataNode("Document");
IIOMetadataNode node = null; // scratch node
node = new IIOMetadataNode("FormatVersion");
node.setAttribute("value", version);
document_node.appendChild(node);
// SubimageInterpretation not in format
// ImageCreationTime not in format
// ImageModificationTime not in format
return document_node;
}
public IIOMetadataNode getStandardTextNode() {
// Not in stream
return null;
}
public IIOMetadataNode getStandardTransparencyNode() {
// Not in stream
return null;
}
public void setFromTree(String formatName, Node root)
throws IIOInvalidTreeException
{
throw new IllegalStateException("Metadata is read-only!");
}
protected void mergeNativeTree(Node root) throws IIOInvalidTreeException
{
throw new IllegalStateException("Metadata is read-only!");
}
protected void mergeStandardTree(Node root) throws IIOInvalidTreeException
{
throw new IllegalStateException("Metadata is read-only!");
}
public void reset() {
throw new IllegalStateException("Metadata is read-only!");
}
}

View File

@@ -0,0 +1,106 @@
/*
* Copyright (c) 2001, 2004, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.imageio.plugins.gif;
import java.util.Arrays;
import javax.imageio.ImageTypeSpecifier;
import javax.imageio.metadata.IIOMetadataFormat;
import javax.imageio.metadata.IIOMetadataFormatImpl;
public class GIFStreamMetadataFormat extends IIOMetadataFormatImpl {
private static IIOMetadataFormat instance = null;
private GIFStreamMetadataFormat() {
super(GIFStreamMetadata.nativeMetadataFormatName,
CHILD_POLICY_SOME);
// root -> Version
addElement("Version", GIFStreamMetadata.nativeMetadataFormatName,
CHILD_POLICY_EMPTY);
addAttribute("Version", "value",
DATATYPE_STRING, true, null,
Arrays.asList(GIFStreamMetadata.versionStrings));
// root -> LogicalScreenDescriptor
addElement("LogicalScreenDescriptor",
GIFStreamMetadata.nativeMetadataFormatName,
CHILD_POLICY_EMPTY);
addAttribute("LogicalScreenDescriptor", "logicalScreenWidth",
DATATYPE_INTEGER, true, null,
"1", "65535", true, true);
addAttribute("LogicalScreenDescriptor", "logicalScreenHeight",
DATATYPE_INTEGER, true, null,
"1", "65535", true, true);
addAttribute("LogicalScreenDescriptor", "colorResolution",
DATATYPE_INTEGER, true, null,
"1", "8", true, true);
addAttribute("LogicalScreenDescriptor", "pixelAspectRatio",
DATATYPE_INTEGER, true, null,
"0", "255", true, true);
// root -> GlobalColorTable
addElement("GlobalColorTable",
GIFStreamMetadata.nativeMetadataFormatName,
2, 256);
addAttribute("GlobalColorTable", "sizeOfGlobalColorTable",
DATATYPE_INTEGER, true, null,
Arrays.asList(GIFStreamMetadata.colorTableSizes));
addAttribute("GlobalColorTable", "backgroundColorIndex",
DATATYPE_INTEGER, true, null,
"0", "255", true, true);
addBooleanAttribute("GlobalColorTable", "sortFlag",
false, false);
// root -> GlobalColorTable -> ColorTableEntry
addElement("ColorTableEntry", "GlobalColorTable",
CHILD_POLICY_EMPTY);
addAttribute("ColorTableEntry", "index",
DATATYPE_INTEGER, true, null,
"0", "255", true, true);
addAttribute("ColorTableEntry", "red",
DATATYPE_INTEGER, true, null,
"0", "255", true, true);
addAttribute("ColorTableEntry", "green",
DATATYPE_INTEGER, true, null,
"0", "255", true, true);
addAttribute("ColorTableEntry", "blue",
DATATYPE_INTEGER, true, null,
"0", "255", true, true);
}
public boolean canNodeAppear(String elementName,
ImageTypeSpecifier imageType) {
return true;
}
public static synchronized IIOMetadataFormat getInstance() {
if (instance == null) {
instance = new GIFStreamMetadataFormat();
}
return instance;
}
}

View File

@@ -0,0 +1,71 @@
/*
* Copyright (c) 2001, 2005, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.imageio.plugins.gif;
import java.util.ListResourceBundle;
public class GIFStreamMetadataFormatResources extends ListResourceBundle {
public GIFStreamMetadataFormatResources() {}
protected Object[][] getContents() {
return new Object[][] {
// Node name, followed by description
{ "Version", "The file version, either 87a or 89a" },
{ "LogicalScreenDescriptor",
"The logical screen descriptor, except for the global color table" },
{ "GlobalColorTable", "The global color table" },
{ "ColorTableEntry", "A global color table entry" },
// Node name + "/" + AttributeName, followed by description
{ "Version/value",
"The version string" },
{ "LogicalScreenDescriptor/logicalScreenWidth",
"The width in pixels of the whole picture" },
{ "LogicalScreenDescriptor/logicalScreenHeight",
"The height in pixels of the whole picture" },
{ "LogicalScreenDescriptor/colorResolution",
"The number of bits of color resolution, beteen 1 and 8" },
{ "LogicalScreenDescriptor/pixelAspectRatio",
"If 0, indicates square pixels, else W/H = (value + 15)/64" },
{ "GlobalColorTable/sizeOfGlobalColorTable",
"The number of entries in the global color table" },
{ "GlobalColorTable/backgroundColorIndex",
"The index of the color table entry to be used as a background" },
{ "GlobalColorTable/sortFlag",
"True if the global color table is sorted by frequency" },
{ "ColorTableEntry/index", "The index of the color table entry" },
{ "ColorTableEntry/red",
"The red value for the color table entry" },
{ "ColorTableEntry/green",
"The green value for the color table entry" },
{ "ColorTableEntry/blue",
"The blue value for the color table entry" },
};
}
}

View File

@@ -0,0 +1,402 @@
/*
* Copyright (c) 2005, 2008, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.imageio.plugins.gif;
import java.io.UnsupportedEncodingException;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import javax.imageio.ImageTypeSpecifier;
import javax.imageio.metadata.IIOInvalidTreeException;
import javax.imageio.metadata.IIOMetadata;
import javax.imageio.metadata.IIOMetadataNode;
import javax.imageio.metadata.IIOMetadataFormat;
import javax.imageio.metadata.IIOMetadataFormatImpl;
import org.w3c.dom.Node;
class GIFWritableImageMetadata extends GIFImageMetadata {
// package scope
static final String
NATIVE_FORMAT_NAME = "javax_imageio_gif_image_1.0";
GIFWritableImageMetadata() {
super(true,
NATIVE_FORMAT_NAME,
"com.sun.imageio.plugins.gif.GIFImageMetadataFormat",
null, null);
}
public boolean isReadOnly() {
return false;
}
public void reset() {
// Fields from Image Descriptor
imageLeftPosition = 0;
imageTopPosition = 0;
imageWidth = 0;
imageHeight = 0;
interlaceFlag = false;
sortFlag = false;
localColorTable = null;
// Fields from Graphic Control Extension
disposalMethod = 0;
userInputFlag = false;
transparentColorFlag = false;
delayTime = 0;
transparentColorIndex = 0;
// Fields from Plain Text Extension
hasPlainTextExtension = false;
textGridLeft = 0;
textGridTop = 0;
textGridWidth = 0;
textGridHeight = 0;
characterCellWidth = 0;
characterCellHeight = 0;
textForegroundColor = 0;
textBackgroundColor = 0;
text = null;
// Fields from ApplicationExtension
applicationIDs = null;
authenticationCodes = null;
applicationData = null;
// Fields from CommentExtension
// List of byte[]
comments = null;
}
private byte[] fromISO8859(String data) {
try {
return data.getBytes("ISO-8859-1");
} catch (UnsupportedEncodingException e) {
return "".getBytes();
}
}
protected 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("ImageDescriptor")) {
imageLeftPosition = getIntAttribute(node,
"imageLeftPosition",
-1, true,
true, 0, 65535);
imageTopPosition = getIntAttribute(node,
"imageTopPosition",
-1, true,
true, 0, 65535);
imageWidth = getIntAttribute(node,
"imageWidth",
-1, true,
true, 1, 65535);
imageHeight = getIntAttribute(node,
"imageHeight",
-1, true,
true, 1, 65535);
interlaceFlag = getBooleanAttribute(node, "interlaceFlag",
false, true);
} else if (name.equals("LocalColorTable")) {
int sizeOfLocalColorTable =
getIntAttribute(node, "sizeOfLocalColorTable",
true, 2, 256);
if (sizeOfLocalColorTable != 2 &&
sizeOfLocalColorTable != 4 &&
sizeOfLocalColorTable != 8 &&
sizeOfLocalColorTable != 16 &&
sizeOfLocalColorTable != 32 &&
sizeOfLocalColorTable != 64 &&
sizeOfLocalColorTable != 128 &&
sizeOfLocalColorTable != 256) {
fatal(node,
"Bad value for LocalColorTable attribute sizeOfLocalColorTable!");
}
sortFlag = getBooleanAttribute(node, "sortFlag", false, true);
localColorTable = getColorTable(node, "ColorTableEntry",
true, sizeOfLocalColorTable);
} else if (name.equals("GraphicControlExtension")) {
String disposalMethodName =
getStringAttribute(node, "disposalMethod", null,
true, disposalMethodNames);
disposalMethod = 0;
while(!disposalMethodName.equals(disposalMethodNames[disposalMethod])) {
disposalMethod++;
}
userInputFlag = getBooleanAttribute(node, "userInputFlag",
false, true);
transparentColorFlag =
getBooleanAttribute(node, "transparentColorFlag",
false, true);
delayTime = getIntAttribute(node,
"delayTime",
-1, true,
true, 0, 65535);
transparentColorIndex =
getIntAttribute(node, "transparentColorIndex",
-1, true,
true, 0, 65535);
} else if (name.equals("PlainTextExtension")) {
hasPlainTextExtension = true;
textGridLeft = getIntAttribute(node,
"textGridLeft",
-1, true,
true, 0, 65535);
textGridTop = getIntAttribute(node,
"textGridTop",
-1, true,
true, 0, 65535);
textGridWidth = getIntAttribute(node,
"textGridWidth",
-1, true,
true, 1, 65535);
textGridHeight = getIntAttribute(node,
"textGridHeight",
-1, true,
true, 1, 65535);
characterCellWidth = getIntAttribute(node,
"characterCellWidth",
-1, true,
true, 1, 65535);
characterCellHeight = getIntAttribute(node,
"characterCellHeight",
-1, true,
true, 1, 65535);
textForegroundColor = getIntAttribute(node,
"textForegroundColor",
-1, true,
true, 0, 255);
textBackgroundColor = getIntAttribute(node,
"textBackgroundColor",
-1, true,
true, 0, 255);
// XXX The "text" attribute of the PlainTextExtension element
// is not defined in the GIF image metadata format but it is
// present in the GIFImageMetadata class. Consequently it is
// used here but not required and with a default of "". See
// bug 5082763.
String textString =
getStringAttribute(node, "text", "", false, null);
text = fromISO8859(textString);
} else if (name.equals("ApplicationExtensions")) {
IIOMetadataNode applicationExtension =
(IIOMetadataNode)node.getFirstChild();
if (!applicationExtension.getNodeName().equals("ApplicationExtension")) {
fatal(node,
"Only a ApplicationExtension may be a child of a ApplicationExtensions!");
}
String applicationIDString =
getStringAttribute(applicationExtension, "applicationID",
null, true, null);
String authenticationCodeString =
getStringAttribute(applicationExtension, "authenticationCode",
null, true, null);
Object applicationExtensionData =
applicationExtension.getUserObject();
if (applicationExtensionData == null ||
!(applicationExtensionData instanceof byte[])) {
fatal(applicationExtension,
"Bad user object in ApplicationExtension!");
}
if (applicationIDs == null) {
applicationIDs = new ArrayList();
authenticationCodes = new ArrayList();
applicationData = new ArrayList();
}
applicationIDs.add(fromISO8859(applicationIDString));
authenticationCodes.add(fromISO8859(authenticationCodeString));
applicationData.add(applicationExtensionData);
} else if (name.equals("CommentExtensions")) {
Node commentExtension = node.getFirstChild();
if (commentExtension != null) {
while(commentExtension != null) {
if (!commentExtension.getNodeName().equals("CommentExtension")) {
fatal(node,
"Only a CommentExtension may be a child of a CommentExtensions!");
}
if (comments == null) {
comments = new ArrayList();
}
String comment =
getStringAttribute(commentExtension, "value", null,
true, null);
comments.add(fromISO8859(comment));
commentExtension = commentExtension.getNextSibling();
}
}
} else {
fatal(node, "Unknown child of root node!");
}
node = node.getNextSibling();
}
}
protected void mergeStandardTree(Node root)
throws IIOInvalidTreeException {
Node node = root;
if (!node.getNodeName()
.equals(IIOMetadataFormatImpl.standardMetadataFormatName)) {
fatal(node, "Root must be " +
IIOMetadataFormatImpl.standardMetadataFormatName);
}
node = node.getFirstChild();
while (node != null) {
String name = node.getNodeName();
if (name.equals("Chroma")) {
Node childNode = node.getFirstChild();
while(childNode != null) {
String childName = childNode.getNodeName();
if (childName.equals("Palette")) {
localColorTable = getColorTable(childNode,
"PaletteEntry",
false, -1);
break;
}
childNode = childNode.getNextSibling();
}
} else if (name.equals("Compression")) {
Node childNode = node.getFirstChild();
while(childNode != null) {
String childName = childNode.getNodeName();
if (childName.equals("NumProgressiveScans")) {
int numProgressiveScans =
getIntAttribute(childNode, "value", 4, false,
true, 1, Integer.MAX_VALUE);
if (numProgressiveScans > 1) {
interlaceFlag = true;
}
break;
}
childNode = childNode.getNextSibling();
}
} else if (name.equals("Dimension")) {
Node childNode = node.getFirstChild();
while(childNode != null) {
String childName = childNode.getNodeName();
if (childName.equals("HorizontalPixelOffset")) {
imageLeftPosition = getIntAttribute(childNode,
"value",
-1, true,
true, 0, 65535);
} else if (childName.equals("VerticalPixelOffset")) {
imageTopPosition = getIntAttribute(childNode,
"value",
-1, true,
true, 0, 65535);
}
childNode = childNode.getNextSibling();
}
} else if (name.equals("Text")) {
Node childNode = node.getFirstChild();
while(childNode != null) {
String childName = childNode.getNodeName();
if (childName.equals("TextEntry") &&
getAttribute(childNode, "compression",
"none", false).equals("none") &&
Charset.isSupported(getAttribute(childNode,
"encoding",
"ISO-8859-1",
false))) {
String value = getAttribute(childNode, "value");
byte[] comment = fromISO8859(value);
if (comments == null) {
comments = new ArrayList();
}
comments.add(comment);
}
childNode = childNode.getNextSibling();
}
} else if (name.equals("Transparency")) {
Node childNode = node.getFirstChild();
while(childNode != null) {
String childName = childNode.getNodeName();
if (childName.equals("TransparentIndex")) {
transparentColorIndex = getIntAttribute(childNode,
"value",
-1, true,
true, 0, 255);
transparentColorFlag = true;
break;
}
childNode = childNode.getNextSibling();
}
}
node = node.getNextSibling();
}
}
public void setFromTree(String formatName, Node root)
throws IIOInvalidTreeException
{
reset();
mergeTree(formatName, root);
}
}

View File

@@ -0,0 +1,267 @@
/*
* Copyright (c) 2005, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.imageio.plugins.gif;
/*
* The source for this class was copied verbatim from the source for
* package com.sun.imageio.plugins.gif.GIFImageMetadata and then modified
* to make the class read-write capable.
*/
import javax.imageio.ImageTypeSpecifier;
import javax.imageio.metadata.IIOInvalidTreeException;
import javax.imageio.metadata.IIOMetadata;
import javax.imageio.metadata.IIOMetadataNode;
import javax.imageio.metadata.IIOMetadataFormat;
import javax.imageio.metadata.IIOMetadataFormatImpl;
import org.w3c.dom.Node;
class GIFWritableStreamMetadata extends GIFStreamMetadata {
// package scope
static final String
NATIVE_FORMAT_NAME = "javax_imageio_gif_stream_1.0";
public GIFWritableStreamMetadata() {
super(true,
NATIVE_FORMAT_NAME,
"com.sun.imageio.plugins.gif.GIFStreamMetadataFormat", // XXX J2SE
null, null);
// initialize metadata fields by default values
reset();
}
public boolean isReadOnly() {
return false;
}
public void mergeTree(String formatName, Node root)
throws IIOInvalidTreeException {
if (formatName.equals(nativeMetadataFormatName)) {
if (root == null) {
throw new IllegalArgumentException("root == null!");
}
mergeNativeTree(root);
} else if (formatName.equals
(IIOMetadataFormatImpl.standardMetadataFormatName)) {
if (root == null) {
throw new IllegalArgumentException("root == null!");
}
mergeStandardTree(root);
} else {
throw new IllegalArgumentException("Not a recognized format!");
}
}
public void reset() {
version = null;
logicalScreenWidth = UNDEFINED_INTEGER_VALUE;
logicalScreenHeight = UNDEFINED_INTEGER_VALUE;
colorResolution = UNDEFINED_INTEGER_VALUE;
pixelAspectRatio = 0;
backgroundColorIndex = 0;
sortFlag = false;
globalColorTable = null;
}
protected 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("Version")) {
version = getStringAttribute(node, "value", null,
true, versionStrings);
} else if (name.equals("LogicalScreenDescriptor")) {
/* NB: At the moment we use empty strings to support undefined
* integer values in tree representation.
* We need to add better support for undefined/default values
* later.
*/
logicalScreenWidth = getIntAttribute(node,
"logicalScreenWidth",
UNDEFINED_INTEGER_VALUE,
true,
true, 1, 65535);
logicalScreenHeight = getIntAttribute(node,
"logicalScreenHeight",
UNDEFINED_INTEGER_VALUE,
true,
true, 1, 65535);
colorResolution = getIntAttribute(node,
"colorResolution",
UNDEFINED_INTEGER_VALUE,
true,
true, 1, 8);
pixelAspectRatio = getIntAttribute(node,
"pixelAspectRatio",
0, true,
true, 0, 255);
} else if (name.equals("GlobalColorTable")) {
int sizeOfGlobalColorTable =
getIntAttribute(node, "sizeOfGlobalColorTable",
true, 2, 256);
if (sizeOfGlobalColorTable != 2 &&
sizeOfGlobalColorTable != 4 &&
sizeOfGlobalColorTable != 8 &&
sizeOfGlobalColorTable != 16 &&
sizeOfGlobalColorTable != 32 &&
sizeOfGlobalColorTable != 64 &&
sizeOfGlobalColorTable != 128 &&
sizeOfGlobalColorTable != 256) {
fatal(node,
"Bad value for GlobalColorTable attribute sizeOfGlobalColorTable!");
}
backgroundColorIndex = getIntAttribute(node,
"backgroundColorIndex",
0, true,
true, 0, 255);
sortFlag = getBooleanAttribute(node, "sortFlag", false, true);
globalColorTable = getColorTable(node, "ColorTableEntry",
true, sizeOfGlobalColorTable);
} else {
fatal(node, "Unknown child of root node!");
}
node = node.getNextSibling();
}
}
protected void mergeStandardTree(Node root)
throws IIOInvalidTreeException {
Node node = root;
if (!node.getNodeName()
.equals(IIOMetadataFormatImpl.standardMetadataFormatName)) {
fatal(node, "Root must be " +
IIOMetadataFormatImpl.standardMetadataFormatName);
}
node = node.getFirstChild();
while (node != null) {
String name = node.getNodeName();
if (name.equals("Chroma")) {
Node childNode = node.getFirstChild();
while(childNode != null) {
String childName = childNode.getNodeName();
if (childName.equals("Palette")) {
globalColorTable = getColorTable(childNode,
"PaletteEntry",
false, -1);
} else if (childName.equals("BackgroundIndex")) {
backgroundColorIndex = getIntAttribute(childNode,
"value",
-1, true,
true, 0, 255);
}
childNode = childNode.getNextSibling();
}
} else if (name.equals("Data")) {
Node childNode = node.getFirstChild();
while(childNode != null) {
String childName = childNode.getNodeName();
if (childName.equals("BitsPerSample")) {
colorResolution = getIntAttribute(childNode,
"value",
-1, true,
true, 1, 8);
break;
}
childNode = childNode.getNextSibling();
}
} else if (name.equals("Dimension")) {
Node childNode = node.getFirstChild();
while(childNode != null) {
String childName = childNode.getNodeName();
if (childName.equals("PixelAspectRatio")) {
float aspectRatio = getFloatAttribute(childNode,
"value");
if (aspectRatio == 1.0F) {
pixelAspectRatio = 0;
} else {
int ratio = (int)(aspectRatio*64.0F - 15.0F);
pixelAspectRatio =
Math.max(Math.min(ratio, 255), 0);
}
} else if (childName.equals("HorizontalScreenSize")) {
logicalScreenWidth = getIntAttribute(childNode,
"value",
-1, true,
true, 1, 65535);
} else if (childName.equals("VerticalScreenSize")) {
logicalScreenHeight = getIntAttribute(childNode,
"value",
-1, true,
true, 1, 65535);
}
childNode = childNode.getNextSibling();
}
} else if (name.equals("Document")) {
Node childNode = node.getFirstChild();
while(childNode != null) {
String childName = childNode.getNodeName();
if (childName.equals("FormatVersion")) {
String formatVersion =
getStringAttribute(childNode, "value", null,
true, null);
for (int i = 0; i < versionStrings.length; i++) {
if (formatVersion.equals(versionStrings[i])) {
version = formatVersion;
break;
}
}
break;
}
childNode = childNode.getNextSibling();
}
}
node = node.getNextSibling();
}
}
public void setFromTree(String formatName, Node root)
throws IIOInvalidTreeException
{
reset();
mergeTree(formatName, root);
}
}