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