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 046package com.github.jaiimageio.impl.plugins.wbmp; 047 048import java.io.UnsupportedEncodingException; 049import java.util.ArrayList; 050import java.util.Iterator; 051import java.util.List; 052 053import javax.imageio.ImageTypeSpecifier; 054import javax.imageio.metadata.IIOMetadata; 055import javax.imageio.metadata.IIOMetadataNode; 056import javax.imageio.metadata.IIOMetadataFormat; 057import javax.imageio.metadata.IIOMetadataFormatImpl; 058 059import org.w3c.dom.Node; 060 061import com.github.jaiimageio.impl.common.ImageUtil; 062 063public class WBMPMetadata extends IIOMetadata { 064 065 public static final String nativeMetadataFormatName = 066 "com_sun_media_imageio_plugins_wbmp_image_1.0"; 067 068 public int wbmpType; 069 070 public int width; 071 public int height; 072 073 public WBMPMetadata() { 074 super(true, 075 nativeMetadataFormatName, 076 "com.github.jaiimageio.impl.plugins.wbmp.WBMPMetadataFormat", 077 null, null); 078 } 079 080 public boolean isReadOnly() { 081 return true; 082 } 083 084 public Node getAsTree(String formatName) { 085 if (formatName.equals(nativeMetadataFormatName)) { 086 return getNativeTree(); 087 } else if (formatName.equals 088 (IIOMetadataFormatImpl.standardMetadataFormatName)) { 089 return getStandardTree(); 090 } else { 091 throw new IllegalArgumentException(I18N.getString("WBMPMetadata0")); 092 } 093 } 094 095 private Node getNativeTree() { 096 IIOMetadataNode root = 097 new IIOMetadataNode(nativeMetadataFormatName); 098 099 addChildNode(root, "WBMPType", new Integer(wbmpType)); 100 addChildNode(root, "Width", new Integer(width)); 101 addChildNode(root, "Height", new Integer(height)); 102 103 return root; 104 } 105 106 public void setFromTree(String formatName, Node root) { 107 throw new IllegalStateException(I18N.getString("WBMPMetadata1")); 108 } 109 110 public void mergeTree(String formatName, Node root) { 111 throw new IllegalStateException(I18N.getString("WBMPMetadata1")); 112 } 113 114 public void reset() { 115 throw new IllegalStateException(I18N.getString("WBMPMetadata1")); 116 } 117 118 private IIOMetadataNode addChildNode(IIOMetadataNode root, 119 String name, 120 Object object) { 121 IIOMetadataNode child = new IIOMetadataNode(name); 122 if (object != null) { 123 child.setUserObject(object); 124 child.setNodeValue(ImageUtil.convertObjectToString(object)); 125 } 126 root.appendChild(child); 127 return child; 128 } 129 130 131 protected IIOMetadataNode getStandardChromaNode() { 132 133 IIOMetadataNode node = new IIOMetadataNode("Chroma"); 134 135 IIOMetadataNode subNode = new IIOMetadataNode("ColorSpaceType"); 136 subNode.setAttribute("name", "GRAY"); 137 node.appendChild(subNode); 138 139 subNode = new IIOMetadataNode("NumChannels"); 140 subNode.setAttribute("value", "1"); 141 node.appendChild(subNode); 142 143 subNode = new IIOMetadataNode("BlackIsZero"); 144 subNode.setAttribute("value", "TRUE"); 145 node.appendChild(subNode); 146 147 return node; 148 } 149 150 151 protected IIOMetadataNode getStandardDataNode() { 152 IIOMetadataNode node = new IIOMetadataNode("Data"); 153 154 IIOMetadataNode subNode = new IIOMetadataNode("SampleFormat"); 155 subNode.setAttribute("value", "UnsignedIntegral"); 156 node.appendChild(subNode); 157 158 subNode = new IIOMetadataNode("BitsPerSample"); 159 subNode.setAttribute("value", "1"); 160 node.appendChild(subNode); 161 162 return node; 163 } 164 165 protected IIOMetadataNode getStandardDimensionNode() { 166 IIOMetadataNode dimension_node = new IIOMetadataNode("Dimension"); 167 IIOMetadataNode node = null; // scratch node 168 169 // PixelAspectRatio not in image 170 171 node = new IIOMetadataNode("ImageOrientation"); 172 node.setAttribute("value", "Normal"); 173 dimension_node.appendChild(node); 174 175 return dimension_node; 176 } 177 178}