001/*
002 * $RCSfile: BMPMetadataFormat.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/04/14 21:29:14 $
043 * $State: Exp $
044 */
045package com.github.jaiimageio.impl.plugins.bmp;
046
047import javax.imageio.ImageTypeSpecifier;
048import javax.imageio.metadata.IIOMetadataFormat;
049import javax.imageio.metadata.IIOMetadataFormatImpl;
050
051public class BMPMetadataFormat extends IIOMetadataFormatImpl {
052
053    private static IIOMetadataFormat instance = null;
054
055    private BMPMetadataFormat() {
056        super(BMPMetadata.nativeMetadataFormatName,
057              CHILD_POLICY_SOME);
058
059        // root -> ImageDescriptor
060        addElement("ImageDescriptor",
061                   BMPMetadata.nativeMetadataFormatName,
062                   CHILD_POLICY_EMPTY);
063        addAttribute("ImageDescriptor", "bmpVersion",
064                     DATATYPE_STRING, true, null);
065        addAttribute("ImageDescriptor", "width",
066                     DATATYPE_INTEGER, true, null,
067                     "0", "65535", true, true);
068        addAttribute("ImageDescriptor", "height",
069                     DATATYPE_INTEGER, true, null,
070                     "1", "65535", true, true);
071        addAttribute("ImageDescriptor", "bitsPerPixel",
072                     DATATYPE_INTEGER, true, null,
073                     "1", "65535", true, true);
074        addAttribute("ImageDescriptor", "compression",
075                      DATATYPE_INTEGER, false, null);
076        addAttribute("ImageDescriptor", "imageSize",
077                     DATATYPE_INTEGER, true, null,
078                     "1", "65535", true, true);
079
080        addElement("PixelsPerMeter",
081                   BMPMetadata.nativeMetadataFormatName,
082                   CHILD_POLICY_EMPTY);
083        addAttribute("PixelsPerMeter", "X",
084                     DATATYPE_INTEGER, false, null,
085                     "1", "65535", true, true);
086        addAttribute("PixelsPerMeter", "Y",
087                     DATATYPE_INTEGER, false, null,
088                     "1", "65535", true, true);
089
090        addElement("ColorsUsed",
091                   BMPMetadata.nativeMetadataFormatName,
092                   CHILD_POLICY_EMPTY);
093        addAttribute("ColorsUsed", "value",
094                     DATATYPE_INTEGER, true, null,
095                     "0", "65535", true, true);
096
097        addElement("ColorsImportant",
098                   BMPMetadata.nativeMetadataFormatName,
099                   CHILD_POLICY_EMPTY);
100        addAttribute("ColorsImportant", "value",
101                     DATATYPE_INTEGER, false, null,
102                     "0", "65535", true, true);
103
104        addElement("BI_BITFIELDS_Mask",
105                   BMPMetadata.nativeMetadataFormatName,
106                   CHILD_POLICY_EMPTY);
107        addAttribute("BI_BITFIELDS_Mask", "red",
108                     DATATYPE_INTEGER, false, null,
109                     "0", "65535", true, true);
110        addAttribute("BI_BITFIELDS_Mask", "green",
111                     DATATYPE_INTEGER, false, null,
112                     "0", "65535", true, true);
113        addAttribute("BI_BITFIELDS_Mask", "blue",
114                     DATATYPE_INTEGER, false, null,
115                     "0", "65535", true, true);
116
117        addElement("ColorSpace",
118                   BMPMetadata.nativeMetadataFormatName,
119                   CHILD_POLICY_EMPTY);
120        addAttribute("ColorSpace", "value",
121                     DATATYPE_INTEGER, false, null,
122                     "0", "65535", true, true);
123
124        addElement("LCS_CALIBRATED_RGB",
125                   BMPMetadata.nativeMetadataFormatName,
126                   CHILD_POLICY_EMPTY);
127
128        /// Should the max value be 1.7976931348623157e+308 ?
129        addAttribute("LCS_CALIBRATED_RGB", "redX",
130                     DATATYPE_DOUBLE, false, null,
131                     "0", "65535", true, true);
132        addAttribute("LCS_CALIBRATED_RGB", "redY",
133                     DATATYPE_DOUBLE, false, null,
134                     "0", "65535", true, true);
135        addAttribute("LCS_CALIBRATED_RGB", "redZ",
136                     DATATYPE_DOUBLE, false, null,
137                     "0", "65535", true, true);
138        addAttribute("LCS_CALIBRATED_RGB", "greenX",
139                     DATATYPE_DOUBLE, false, null,
140                     "0", "65535", true, true);
141        addAttribute("LCS_CALIBRATED_RGB", "greenY",
142                     DATATYPE_DOUBLE, false, null,
143                     "0", "65535", true, true);
144        addAttribute("LCS_CALIBRATED_RGB", "greenZ",
145                     DATATYPE_DOUBLE, false, null,
146                     "0", "65535", true, true);
147        addAttribute("LCS_CALIBRATED_RGB", "blueX",
148                     DATATYPE_DOUBLE, false, null,
149                     "0", "65535", true, true);
150        addAttribute("LCS_CALIBRATED_RGB", "blueY",
151                     DATATYPE_DOUBLE, false, null,
152                     "0", "65535", true, true);
153        addAttribute("LCS_CALIBRATED_RGB", "blueZ",
154                     DATATYPE_DOUBLE, false, null,
155                     "0", "65535", true, true);
156
157        addElement("LCS_CALIBRATED_RGB_GAMMA",
158                   BMPMetadata.nativeMetadataFormatName,
159                   CHILD_POLICY_EMPTY);
160        addAttribute("LCS_CALIBRATED_RGB_GAMMA","red",
161                     DATATYPE_INTEGER, false, null,
162                     "0", "65535", true, true);
163        addAttribute("LCS_CALIBRATED_RGB_GAMMA","green",
164                     DATATYPE_INTEGER, false, null,
165                     "0", "65535", true, true);
166        addAttribute("LCS_CALIBRATED_RGB_GAMMA","blue",
167                     DATATYPE_INTEGER, false, null,
168                     "0", "65535", true, true);
169
170        addElement("Intent",
171                   BMPMetadata.nativeMetadataFormatName,
172                   CHILD_POLICY_EMPTY);
173        addAttribute("Intent", "value",
174                     DATATYPE_INTEGER, false, null,
175                     "0", "65535", true, true);
176
177        // root -> Palette
178        addElement("Palette",
179                   BMPMetadata.nativeMetadataFormatName,
180                   2, 256);
181        addAttribute("Palette", "sizeOfPalette",
182                     DATATYPE_INTEGER, true, null);
183        addBooleanAttribute("Palette", "sortFlag",
184                            false, false);
185
186        // root -> Palette -> PaletteEntry
187        addElement("PaletteEntry", "Palette",
188                   CHILD_POLICY_EMPTY);
189        addAttribute("PaletteEntry", "index",
190                     DATATYPE_INTEGER, true, null,
191                     "0", "255", true, true);
192        addAttribute("PaletteEntry", "red",
193                     DATATYPE_INTEGER, true, null,
194                     "0", "255", true, true);
195        addAttribute("PaletteEntry", "green",
196                     DATATYPE_INTEGER, true, null,
197                     "0", "255", true, true);
198        addAttribute("PaletteEntry", "blue",
199                     DATATYPE_INTEGER, true, null,
200                     "0", "255", true, true);
201
202
203        // root -> CommentExtensions
204        addElement("CommentExtensions",
205                   BMPMetadata.nativeMetadataFormatName,
206                   1, Integer.MAX_VALUE);
207
208        // root -> CommentExtensions -> CommentExtension
209        addElement("CommentExtension", "CommentExtensions",
210                   CHILD_POLICY_EMPTY);
211        addAttribute("CommentExtension", "value",
212                     DATATYPE_STRING, true, null);
213    }
214
215    public boolean canNodeAppear(String elementName,
216                                 ImageTypeSpecifier imageType) {
217        return true;
218    }
219
220    public static synchronized IIOMetadataFormat getInstance() {
221        if (instance == null) {
222            instance = new BMPMetadataFormat();
223        }
224        return instance;
225    }
226}