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