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