001: /*
002: * $RCSfile: WBMPMetadata.java,v $
003: *
004: *
005: * Copyright (c) 2005 Sun Microsystems, Inc. All Rights Reserved.
006: *
007: * Redistribution and use in source and binary forms, with or without
008: * modification, are permitted provided that the following conditions
009: * are met:
010: *
011: * - Redistribution of source code must retain the above copyright
012: * notice, this list of conditions and the following disclaimer.
013: *
014: * - Redistribution in binary form must reproduce the above copyright
015: * notice, this list of conditions and the following disclaimer in
016: * the documentation and/or other materials provided with the
017: * distribution.
018: *
019: * Neither the name of Sun Microsystems, Inc. or the names of
020: * contributors may be used to endorse or promote products derived
021: * from this software without specific prior written permission.
022: *
023: * This software is provided "AS IS," without a warranty of any
024: * kind. ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND
025: * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY,
026: * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY
027: * EXCLUDED. SUN MIDROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL
028: * NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF
029: * USING, MODIFYING OR DISTRIBUTING THIS SOFTWARE OR ITS
030: * DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR
031: * ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL,
032: * CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER CAUSED AND
033: * REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF THE USE OF OR
034: * INABILITY TO USE THIS SOFTWARE, EVEN IF SUN HAS BEEN ADVISED OF THE
035: * POSSIBILITY OF SUCH DAMAGES.
036: *
037: * You acknowledge that this software is not designed or intended for
038: * use in the design, construction, operation or maintenance of any
039: * nuclear facility.
040: *
041: * $Revision: 1.2 $
042: * $Date: 2006/03/21 00:27:22 $
043: * $State: Exp $
044: */
045:
046: package com.sun.media.imageioimpl.plugins.wbmp;
047:
048: import java.io.UnsupportedEncodingException;
049: import java.util.ArrayList;
050: import java.util.Iterator;
051: import java.util.List;
052: import javax.imageio.ImageTypeSpecifier;
053: import javax.imageio.metadata.IIOMetadata;
054: import javax.imageio.metadata.IIOMetadataNode;
055: import javax.imageio.metadata.IIOMetadataFormat;
056: import javax.imageio.metadata.IIOMetadataFormatImpl;
057: import org.w3c.dom.Node;
058: import com.sun.media.imageioimpl.common.ImageUtil;
059:
060: public class WBMPMetadata extends IIOMetadata {
061:
062: public static final String nativeMetadataFormatName = "com_sun_media_imageio_plugins_wbmp_image_1.0";
063:
064: public int wbmpType;
065:
066: public int width;
067: public int height;
068:
069: public WBMPMetadata() {
070: super (
071: true,
072: nativeMetadataFormatName,
073: "com.sun.media.imageioimpl.plugins.wbmp.WBMPMetadataFormat",
074: null, null);
075: }
076:
077: public boolean isReadOnly() {
078: return true;
079: }
080:
081: public Node getAsTree(String formatName) {
082: if (formatName.equals(nativeMetadataFormatName)) {
083: return getNativeTree();
084: } else if (formatName
085: .equals(IIOMetadataFormatImpl.standardMetadataFormatName)) {
086: return getStandardTree();
087: } else {
088: throw new IllegalArgumentException(I18N
089: .getString("WBMPMetadata0"));
090: }
091: }
092:
093: private Node getNativeTree() {
094: IIOMetadataNode root = new IIOMetadataNode(
095: nativeMetadataFormatName);
096:
097: addChildNode(root, "WBMPType", new Integer(wbmpType));
098: addChildNode(root, "Width", new Integer(width));
099: addChildNode(root, "Height", new Integer(height));
100:
101: return root;
102: }
103:
104: public void setFromTree(String formatName, Node root) {
105: throw new IllegalStateException(I18N.getString("WBMPMetadata1"));
106: }
107:
108: public void mergeTree(String formatName, Node root) {
109: throw new IllegalStateException(I18N.getString("WBMPMetadata1"));
110: }
111:
112: public void reset() {
113: throw new IllegalStateException(I18N.getString("WBMPMetadata1"));
114: }
115:
116: private IIOMetadataNode addChildNode(IIOMetadataNode root,
117: String name, Object object) {
118: IIOMetadataNode child = new IIOMetadataNode(name);
119: if (object != null) {
120: child.setUserObject(object);
121: child.setNodeValue(ImageUtil.convertObjectToString(object));
122: }
123: root.appendChild(child);
124: return child;
125: }
126:
127: protected IIOMetadataNode getStandardChromaNode() {
128:
129: IIOMetadataNode node = new IIOMetadataNode("Chroma");
130:
131: IIOMetadataNode subNode = new IIOMetadataNode("ColorSpaceType");
132: subNode.setAttribute("name", "GRAY");
133: node.appendChild(subNode);
134:
135: subNode = new IIOMetadataNode("NumChannels");
136: subNode.setAttribute("value", "1");
137: node.appendChild(subNode);
138:
139: subNode = new IIOMetadataNode("BlackIsZero");
140: subNode.setAttribute("value", "TRUE");
141: node.appendChild(subNode);
142:
143: return node;
144: }
145:
146: protected IIOMetadataNode getStandardDataNode() {
147: IIOMetadataNode node = new IIOMetadataNode("Data");
148:
149: IIOMetadataNode subNode = new IIOMetadataNode("SampleFormat");
150: subNode.setAttribute("value", "UnsignedIntegral");
151: node.appendChild(subNode);
152:
153: subNode = new IIOMetadataNode("BitsPerSample");
154: subNode.setAttribute("value", "1");
155: node.appendChild(subNode);
156:
157: return node;
158: }
159:
160: protected IIOMetadataNode getStandardDimensionNode() {
161: IIOMetadataNode dimension_node = new IIOMetadataNode(
162: "Dimension");
163: IIOMetadataNode node = null; // scratch node
164:
165: // PixelAspectRatio not in image
166:
167: node = new IIOMetadataNode("ImageOrientation");
168: node.setAttribute("value", "Normal");
169: dimension_node.appendChild(node);
170:
171: return dimension_node;
172: }
173:
174: }
|