001: /*
002: * Copyright 2003-2004 Sun Microsystems, Inc. All Rights Reserved.
003: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004: *
005: * This code is free software; you can redistribute it and/or modify it
006: * under the terms of the GNU General Public License version 2 only, as
007: * published by the Free Software Foundation. Sun designates this
008: * particular file as subject to the "Classpath" exception as provided
009: * by Sun in the LICENSE file that accompanied this code.
010: *
011: * This code is distributed in the hope that it will be useful, but WITHOUT
012: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
014: * version 2 for more details (a copy is included in the LICENSE file that
015: * accompanied this code).
016: *
017: * You should have received a copy of the GNU General Public License version
018: * 2 along with this work; if not, write to the Free Software Foundation,
019: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
020: *
021: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
022: * CA 95054 USA or visit www.sun.com if you need additional information or
023: * have any questions.
024: */
025:
026: package com.sun.imageio.plugins.bmp;
027:
028: import java.util.Arrays;
029: import javax.imageio.ImageTypeSpecifier;
030: import javax.imageio.metadata.IIOMetadataFormat;
031: import javax.imageio.metadata.IIOMetadataFormatImpl;
032:
033: public class BMPMetadataFormat extends IIOMetadataFormatImpl {
034:
035: private static IIOMetadataFormat instance = null;
036:
037: private BMPMetadataFormat() {
038: super (BMPMetadata.nativeMetadataFormatName, CHILD_POLICY_SOME);
039:
040: // root -> ImageDescriptor
041: addElement("ImageDescriptor",
042: BMPMetadata.nativeMetadataFormatName,
043: CHILD_POLICY_EMPTY);
044: addAttribute("ImageDescriptor", "bmpVersion", DATATYPE_STRING,
045: true, null);
046: addAttribute("ImageDescriptor", "width", DATATYPE_INTEGER,
047: true, null, "0", "65535", true, true);
048: addAttribute("ImageDescriptor", "height", DATATYPE_INTEGER,
049: true, null, "1", "65535", true, true);
050: addAttribute("ImageDescriptor", "bitsPerPixel",
051: DATATYPE_INTEGER, true, null, "1", "65535", true, true);
052: addAttribute("ImageDescriptor", "compression",
053: DATATYPE_INTEGER, false, null);
054: addAttribute("ImageDescriptor", "imageSize", DATATYPE_INTEGER,
055: true, null, "1", "65535", true, true);
056:
057: addElement("PixelsPerMeter",
058: BMPMetadata.nativeMetadataFormatName,
059: CHILD_POLICY_EMPTY);
060: addAttribute("PixelsPerMeter", "X", DATATYPE_INTEGER, false,
061: null, "1", "65535", true, true);
062: addAttribute("PixelsPerMeter", "Y", DATATYPE_INTEGER, false,
063: null, "1", "65535", true, true);
064:
065: addElement("ColorsUsed", BMPMetadata.nativeMetadataFormatName,
066: CHILD_POLICY_EMPTY);
067: addAttribute("ColorsUsed", "value", DATATYPE_INTEGER, true,
068: null, "0", "65535", true, true);
069:
070: addElement("ColorsImportant",
071: BMPMetadata.nativeMetadataFormatName,
072: CHILD_POLICY_EMPTY);
073: addAttribute("ColorsImportant", "value", DATATYPE_INTEGER,
074: false, null, "0", "65535", true, true);
075:
076: addElement("BI_BITFIELDS_Mask",
077: BMPMetadata.nativeMetadataFormatName,
078: CHILD_POLICY_EMPTY);
079: addAttribute("BI_BITFIELDS_Mask", "red", DATATYPE_INTEGER,
080: false, null, "0", "65535", true, true);
081: addAttribute("BI_BITFIELDS_Mask", "green", DATATYPE_INTEGER,
082: false, null, "0", "65535", true, true);
083: addAttribute("BI_BITFIELDS_Mask", "blue", DATATYPE_INTEGER,
084: false, null, "0", "65535", true, true);
085:
086: addElement("ColorSpace", BMPMetadata.nativeMetadataFormatName,
087: CHILD_POLICY_EMPTY);
088: addAttribute("ColorSpace", "value", DATATYPE_INTEGER, false,
089: null, "0", "65535", true, true);
090:
091: addElement("LCS_CALIBRATED_RGB",
092: BMPMetadata.nativeMetadataFormatName,
093: CHILD_POLICY_EMPTY);
094:
095: /// Should the max value be 1.7976931348623157e+308 ?
096: addAttribute("LCS_CALIBRATED_RGB", "redX", DATATYPE_DOUBLE,
097: false, null, "0", "65535", true, true);
098: addAttribute("LCS_CALIBRATED_RGB", "redY", DATATYPE_DOUBLE,
099: false, null, "0", "65535", true, true);
100: addAttribute("LCS_CALIBRATED_RGB", "redZ", DATATYPE_DOUBLE,
101: false, null, "0", "65535", true, true);
102: addAttribute("LCS_CALIBRATED_RGB", "greenX", DATATYPE_DOUBLE,
103: false, null, "0", "65535", true, true);
104: addAttribute("LCS_CALIBRATED_RGB", "greenY", DATATYPE_DOUBLE,
105: false, null, "0", "65535", true, true);
106: addAttribute("LCS_CALIBRATED_RGB", "greenZ", DATATYPE_DOUBLE,
107: false, null, "0", "65535", true, true);
108: addAttribute("LCS_CALIBRATED_RGB", "blueX", DATATYPE_DOUBLE,
109: false, null, "0", "65535", true, true);
110: addAttribute("LCS_CALIBRATED_RGB", "blueY", DATATYPE_DOUBLE,
111: false, null, "0", "65535", true, true);
112: addAttribute("LCS_CALIBRATED_RGB", "blueZ", DATATYPE_DOUBLE,
113: false, null, "0", "65535", true, true);
114:
115: addElement("LCS_CALIBRATED_RGB_GAMMA",
116: BMPMetadata.nativeMetadataFormatName,
117: CHILD_POLICY_EMPTY);
118: addAttribute("LCS_CALIBRATED_RGB_GAMMA", "red",
119: DATATYPE_INTEGER, false, null, "0", "65535", true, true);
120: addAttribute("LCS_CALIBRATED_RGB_GAMMA", "green",
121: DATATYPE_INTEGER, false, null, "0", "65535", true, true);
122: addAttribute("LCS_CALIBRATED_RGB_GAMMA", "blue",
123: DATATYPE_INTEGER, false, null, "0", "65535", true, true);
124:
125: addElement("Intent", BMPMetadata.nativeMetadataFormatName,
126: CHILD_POLICY_EMPTY);
127: addAttribute("Intent", "value", DATATYPE_INTEGER, false, null,
128: "0", "65535", true, true);
129:
130: // root -> Palette
131: addElement("Palette", BMPMetadata.nativeMetadataFormatName, 2,
132: 256);
133: addAttribute("Palette", "sizeOfPalette", DATATYPE_INTEGER,
134: true, null);
135: addBooleanAttribute("Palette", "sortFlag", false, false);
136:
137: // root -> Palette -> PaletteEntry
138: addElement("PaletteEntry", "Palette", CHILD_POLICY_EMPTY);
139: addAttribute("PaletteEntry", "index", DATATYPE_INTEGER, true,
140: null, "0", "255", true, true);
141: addAttribute("PaletteEntry", "red", DATATYPE_INTEGER, true,
142: null, "0", "255", true, true);
143: addAttribute("PaletteEntry", "green", DATATYPE_INTEGER, true,
144: null, "0", "255", true, true);
145: addAttribute("PaletteEntry", "blue", DATATYPE_INTEGER, true,
146: null, "0", "255", true, true);
147:
148: // root -> CommentExtensions
149: addElement("CommentExtensions",
150: BMPMetadata.nativeMetadataFormatName, 1,
151: Integer.MAX_VALUE);
152:
153: // root -> CommentExtensions -> CommentExtension
154: addElement("CommentExtension", "CommentExtensions",
155: CHILD_POLICY_EMPTY);
156: addAttribute("CommentExtension", "value", DATATYPE_STRING,
157: true, null);
158: }
159:
160: public boolean canNodeAppear(String elementName,
161: ImageTypeSpecifier imageType) {
162: return true;
163: }
164:
165: public static synchronized IIOMetadataFormat getInstance() {
166: if (instance == null) {
167: instance = new BMPMetadataFormat();
168: }
169: return instance;
170: }
171: }
|