001: /*
002: * $RCSfile: CLibPNGMetadataFormat.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.1 $
042: * $Date: 2005/02/11 05:01:39 $
043: * $State: Exp $
044: */
045:
046: package com.sun.media.imageioimpl.plugins.png;
047:
048: import java.util.ArrayList;
049: import java.util.Arrays;
050: import java.util.List;
051: import java.util.ListResourceBundle;
052: import javax.imageio.ImageTypeSpecifier;
053: import javax.imageio.metadata.IIOMetadataFormat;
054: import javax.imageio.metadata.IIOMetadataFormatImpl;
055:
056: public class CLibPNGMetadataFormat extends IIOMetadataFormatImpl {
057:
058: private static IIOMetadataFormat instance = null;
059:
060: private static String VALUE_0 = "0";
061: private static String VALUE_1 = "1";
062: private static String VALUE_12 = "12";
063: private static String VALUE_23 = "23";
064: private static String VALUE_31 = "31";
065: private static String VALUE_59 = "59";
066: private static String VALUE_60 = "60";
067: private static String VALUE_255 = "255";
068: private static String VALUE_MAX_16 = "65535"; // 2^16 - 1
069: private static String VALUE_MAX_32 = "2147483647"; // 2^32 - 1
070:
071: private CLibPNGMetadataFormat() {
072: super (CLibPNGMetadata.nativeMetadataFormatName,
073: CHILD_POLICY_SOME);
074:
075: // root -> IHDR
076: addElement("IHDR", CLibPNGMetadata.nativeMetadataFormatName,
077: CHILD_POLICY_EMPTY);
078:
079: addAttribute("IHDR", "width", DATATYPE_INTEGER, true, null,
080: VALUE_1, VALUE_MAX_32, true, true);
081:
082: addAttribute("IHDR", "height", DATATYPE_INTEGER, true, null,
083: VALUE_1, VALUE_MAX_32, true, true);
084:
085: addAttribute("IHDR", "bitDepth", DATATYPE_INTEGER, true, null,
086: Arrays.asList(CLibPNGMetadata.IHDR_bitDepths));
087:
088: String[] colorTypes = { "Grayscale", "RGB", "Palette",
089: "GrayAlpha", "RGBAlpha" };
090: addAttribute("IHDR", "colorType", DATATYPE_STRING, true, null,
091: Arrays.asList(colorTypes));
092:
093: addAttribute(
094: "IHDR",
095: "compressionMethod",
096: DATATYPE_STRING,
097: true,
098: null,
099: Arrays
100: .asList(CLibPNGMetadata.IHDR_compressionMethodNames));
101:
102: addAttribute("IHDR", "filterMethod", DATATYPE_STRING, true,
103: null, Arrays
104: .asList(CLibPNGMetadata.IHDR_filterMethodNames));
105:
106: addAttribute(
107: "IHDR",
108: "interlaceMethod",
109: DATATYPE_STRING,
110: true,
111: null,
112: Arrays
113: .asList(CLibPNGMetadata.IHDR_interlaceMethodNames));
114:
115: // root -> PLTE
116: addElement("PLTE", CLibPNGMetadata.nativeMetadataFormatName, 1,
117: 256);
118:
119: // root -> PLTE -> PLTEEntry
120: addElement("PLTEEntry", "PLTE", CHILD_POLICY_EMPTY);
121:
122: addAttribute("PLTEEntry", "index", DATATYPE_INTEGER, true,
123: null, VALUE_0, VALUE_255, true, true);
124:
125: addAttribute("PLTEEntry", "red", DATATYPE_INTEGER, true, null,
126: VALUE_0, VALUE_255, true, true);
127:
128: addAttribute("PLTEEntry", "green", DATATYPE_INTEGER, true,
129: null, VALUE_0, VALUE_255, true, true);
130:
131: addAttribute("PLTEEntry", "blue", DATATYPE_INTEGER, true, null,
132: VALUE_0, VALUE_255, true, true);
133:
134: // root -> bKGD
135: addElement("bKGD", CLibPNGMetadata.nativeMetadataFormatName,
136: CHILD_POLICY_CHOICE);
137:
138: // root -> bKGD -> bKGD_Grayscale
139: addElement("bKGD_Grayscale", "bKGD", CHILD_POLICY_EMPTY);
140:
141: addAttribute("bKGD_Grayscale", "gray", DATATYPE_INTEGER, true,
142: null, VALUE_0, VALUE_MAX_16, true, true);
143:
144: // root -> bKGD -> bKGD_RGB
145: addElement("bKGD_RGB", "bKGD", CHILD_POLICY_EMPTY);
146:
147: addAttribute("bKGD_RGB", "red", DATATYPE_INTEGER, true, null,
148: VALUE_0, VALUE_MAX_16, true, true);
149:
150: addAttribute("bKGD_RGB", "green", DATATYPE_INTEGER, true, null,
151: VALUE_0, VALUE_MAX_16, true, true);
152:
153: addAttribute("bKGD_RGB", "blue", DATATYPE_INTEGER, true, null,
154: VALUE_0, VALUE_MAX_16, true, true);
155:
156: // root -> bKGD -> bKGD_Palette
157: addElement("bKGD_Palette", "bKGD", CHILD_POLICY_EMPTY);
158:
159: addAttribute("bKGD_Palette", "index", DATATYPE_INTEGER, true,
160: null, VALUE_0, VALUE_255, true, true);
161:
162: // root -> cHRM
163: addElement("cHRM", CLibPNGMetadata.nativeMetadataFormatName,
164: CHILD_POLICY_EMPTY);
165:
166: addAttribute("cHRM", "whitePointX", DATATYPE_INTEGER, true,
167: null, VALUE_0, VALUE_MAX_16, true, true);
168:
169: addAttribute("cHRM", "whitePointY", DATATYPE_INTEGER, true,
170: null, VALUE_0, VALUE_MAX_16, true, true);
171:
172: addAttribute("cHRM", "redX", DATATYPE_INTEGER, true, null,
173: VALUE_0, VALUE_MAX_16, true, true);
174:
175: addAttribute("cHRM", "redY", DATATYPE_INTEGER, true, null,
176: VALUE_0, VALUE_MAX_16, true, true);
177:
178: addAttribute("cHRM", "greenX", DATATYPE_INTEGER, true, null,
179: VALUE_0, VALUE_MAX_16, true, true);
180:
181: addAttribute("cHRM", "greenY", DATATYPE_INTEGER, true, null,
182: VALUE_0, VALUE_MAX_16, true, true);
183:
184: addAttribute("cHRM", "blueX", DATATYPE_INTEGER, true, null,
185: VALUE_0, VALUE_MAX_16, true, true);
186:
187: addAttribute("cHRM", "blueY", DATATYPE_INTEGER, true, null,
188: VALUE_0, VALUE_MAX_16, true, true);
189:
190: // root -> gAMA
191: addElement("gAMA", CLibPNGMetadata.nativeMetadataFormatName,
192: CHILD_POLICY_EMPTY);
193:
194: addAttribute("gAMA", "value", DATATYPE_INTEGER, true, null,
195: VALUE_0, VALUE_MAX_32, true, true);
196:
197: // root -> hIST
198: addElement("hIST", CLibPNGMetadata.nativeMetadataFormatName, 1,
199: 256);
200:
201: // root -> hISTEntry
202: addElement("hISTEntry", "hIST", CHILD_POLICY_EMPTY);
203:
204: addAttribute("hISTEntry", "index", DATATYPE_INTEGER, true,
205: null, VALUE_0, VALUE_255, true, true);
206:
207: addAttribute("hISTEntry", "value", DATATYPE_INTEGER, true,
208: null, VALUE_0, VALUE_MAX_16, true, true);
209:
210: // root -> iCCP
211: addElement("iCCP", CLibPNGMetadata.nativeMetadataFormatName,
212: CHILD_POLICY_EMPTY);
213:
214: addAttribute("iCCP", "profileName", DATATYPE_STRING, true, null);
215:
216: addAttribute(
217: "iCCP",
218: "compressionMethod",
219: DATATYPE_STRING,
220: true,
221: null,
222: Arrays
223: .asList(CLibPNGMetadata.iCCP_compressionMethodNames));
224:
225: addObjectValue("iCCP", byte.class, 0, Integer.MAX_VALUE);
226:
227: // root -> iTXt
228: addElement("iTXt", CLibPNGMetadata.nativeMetadataFormatName, 1,
229: Integer.MAX_VALUE);
230:
231: // root -> iTXt -> iTXtEntry
232: addElement("iTXtEntry", "iTXt", CHILD_POLICY_EMPTY);
233:
234: addAttribute("iTXtEntry", "keyword", DATATYPE_STRING, true,
235: null);
236:
237: addBooleanAttribute("iTXtEntry", "compressionFlag", false,
238: false);
239:
240: addAttribute("iTXtEntry", "compressionMethod", DATATYPE_STRING,
241: true, null);
242:
243: addAttribute("iTXtEntry", "languageTag", DATATYPE_STRING, true,
244: null);
245:
246: addAttribute("iTXtEntry", "translatedKeyword", DATATYPE_STRING,
247: true, null);
248:
249: addAttribute("iTXtEntry", "text", DATATYPE_STRING, true, null);
250:
251: // root -> pHYS
252: addElement("pHYS", CLibPNGMetadata.nativeMetadataFormatName,
253: CHILD_POLICY_EMPTY);
254:
255: addAttribute("pHYS", "pixelsPerUnitXAxis", DATATYPE_INTEGER,
256: true, null, VALUE_0, VALUE_MAX_32, true, true);
257: addAttribute("pHYS", "pixelsPerUnitYAxis", DATATYPE_INTEGER,
258: true, null, VALUE_0, VALUE_MAX_32, true, true);
259: addAttribute("pHYS", "unitSpecifier", DATATYPE_STRING, true,
260: null, Arrays.asList(CLibPNGMetadata.unitSpecifierNames));
261:
262: // root -> sBIT
263: addElement("sBIT", CLibPNGMetadata.nativeMetadataFormatName,
264: CHILD_POLICY_CHOICE);
265:
266: // root -> sBIT -> sBIT_Grayscale
267: addElement("sBIT_Grayscale", "sBIT", CHILD_POLICY_EMPTY);
268:
269: addAttribute("sBIT_Grayscale", "gray", DATATYPE_INTEGER, true,
270: null, VALUE_0, VALUE_255, true, true);
271:
272: // root -> sBIT -> sBIT_GrayAlpha
273: addElement("sBIT_GrayAlpha", "sBIT", CHILD_POLICY_EMPTY);
274:
275: addAttribute("sBIT_GrayAlpha", "gray", DATATYPE_INTEGER, true,
276: null, VALUE_0, VALUE_255, true, true);
277:
278: addAttribute("sBIT_GrayAlpha", "alpha", DATATYPE_INTEGER, true,
279: null, VALUE_0, VALUE_255, true, true);
280:
281: // root -> sBIT -> sBIT_RGB
282: addElement("sBIT_RGB", "sBIT", CHILD_POLICY_EMPTY);
283:
284: addAttribute("sBIT_RGB", "red", DATATYPE_INTEGER, true, null,
285: VALUE_0, VALUE_255, true, true);
286:
287: addAttribute("sBIT_RGB", "green", DATATYPE_INTEGER, true, null,
288: VALUE_0, VALUE_255, true, true);
289:
290: addAttribute("sBIT_RGB", "blue", DATATYPE_INTEGER, true, null,
291: VALUE_0, VALUE_255, true, true);
292:
293: // root -> sBIT -> sBIT_RGBAlpha
294: addElement("sBIT_RGBAlpha", "sBIT", CHILD_POLICY_EMPTY);
295:
296: addAttribute("sBIT_RGBAlpha", "red", DATATYPE_INTEGER, true,
297: null, VALUE_0, VALUE_255, true, true);
298:
299: addAttribute("sBIT_RGBAlpha", "green", DATATYPE_INTEGER, true,
300: null, VALUE_0, VALUE_255, true, true);
301:
302: addAttribute("sBIT_RGBAlpha", "blue", DATATYPE_INTEGER, true,
303: null, VALUE_0, VALUE_255, true, true);
304:
305: addAttribute("sBIT_RGBAlpha", "alpha", DATATYPE_INTEGER, true,
306: null, VALUE_0, VALUE_255, true, true);
307:
308: // root -> sBIT -> sBIT_Palette
309: addElement("sBIT_Palette", "sBIT", CHILD_POLICY_EMPTY);
310:
311: addAttribute("sBIT_Palette", "red", DATATYPE_INTEGER, true,
312: null, VALUE_0, VALUE_255, true, true);
313:
314: addAttribute("sBIT_Palette", "green", DATATYPE_INTEGER, true,
315: null, VALUE_0, VALUE_255, true, true);
316:
317: addAttribute("sBIT_Palette", "blue", DATATYPE_INTEGER, true,
318: null, VALUE_0, VALUE_255, true, true);
319:
320: // root -> sPLT
321: addElement("sPLT", CLibPNGMetadata.nativeMetadataFormatName, 1,
322: 256);
323:
324: // root -> sPLT -> sPLTEntry
325: addElement("sPLTEntry", "sPLT", CHILD_POLICY_EMPTY);
326:
327: addAttribute("sPLTEntry", "index", DATATYPE_INTEGER, true,
328: null, VALUE_0, VALUE_255, true, true);
329:
330: addAttribute("sPLTEntry", "red", DATATYPE_INTEGER, true, null,
331: VALUE_0, VALUE_255, true, true);
332:
333: addAttribute("sPLTEntry", "green", DATATYPE_INTEGER, true,
334: null, VALUE_0, VALUE_255, true, true);
335:
336: addAttribute("sPLTEntry", "blue", DATATYPE_INTEGER, true, null,
337: VALUE_0, VALUE_255, true, true);
338:
339: addAttribute("sPLTEntry", "alpha", DATATYPE_INTEGER, true,
340: null, VALUE_0, VALUE_255, true, true);
341:
342: // root -> sRGB
343: addElement("sRGB", CLibPNGMetadata.nativeMetadataFormatName,
344: CHILD_POLICY_EMPTY);
345:
346: addAttribute("sRGB", "renderingIntent", DATATYPE_STRING, true,
347: null, Arrays
348: .asList(CLibPNGMetadata.renderingIntentNames));
349:
350: // root -> tEXt
351: addElement("tEXt", CLibPNGMetadata.nativeMetadataFormatName, 1,
352: Integer.MAX_VALUE);
353:
354: // root -> tEXt -> tEXtEntry
355: addElement("tEXtEntry", "tEXt", CHILD_POLICY_EMPTY);
356:
357: addAttribute("tEXtEntry", "keyword", DATATYPE_STRING, true,
358: null);
359:
360: addAttribute("tEXtEntry", "value", DATATYPE_STRING, true, null);
361:
362: // root -> tIME
363: addElement("tIME", CLibPNGMetadata.nativeMetadataFormatName,
364: CHILD_POLICY_EMPTY);
365:
366: addAttribute("tIME", "year", DATATYPE_INTEGER, true, null,
367: VALUE_0, VALUE_MAX_16, true, true);
368:
369: addAttribute("tIME", "month", DATATYPE_INTEGER, true, null,
370: VALUE_1, VALUE_12, true, true);
371:
372: addAttribute("tIME", "day", DATATYPE_INTEGER, true, null,
373: VALUE_1, VALUE_31, true, true);
374:
375: addAttribute("tIME", "hour", DATATYPE_INTEGER, true, null,
376: VALUE_0, VALUE_23, true, true);
377:
378: addAttribute("tIME", "minute", DATATYPE_INTEGER, true, null,
379: VALUE_0, VALUE_59, true, true);
380:
381: addAttribute("tIME", "second", DATATYPE_INTEGER, true, null,
382: VALUE_0, VALUE_60, true, true);
383:
384: // root -> tRNS
385: addElement("tRNS", CLibPNGMetadata.nativeMetadataFormatName,
386: CHILD_POLICY_CHOICE);
387:
388: // root -> tRNS -> tRNS_Grayscale
389: addElement("tRNS_Grayscale", "tRNS", CHILD_POLICY_EMPTY);
390:
391: addAttribute("tRNS_Grayscale", "gray", DATATYPE_INTEGER, true,
392: null, VALUE_0, VALUE_MAX_16, true, true);
393:
394: // root -> tRNS -> tRNS_RGB
395: addElement("tRNS_RGB", "tRNS", CHILD_POLICY_EMPTY);
396:
397: addAttribute("tRNS_RGB", "red", DATATYPE_INTEGER, true, null,
398: VALUE_0, VALUE_MAX_16, true, true);
399:
400: addAttribute("tRNS_RGB", "green", DATATYPE_INTEGER, true, null,
401: VALUE_0, VALUE_MAX_16, true, true);
402:
403: addAttribute("tRNS_RGB", "blue", DATATYPE_INTEGER, true, null,
404: VALUE_0, VALUE_MAX_16, true, true);
405:
406: // root -> tRNS -> tRNS_Palette
407: addElement("tRNS_Palette", "tRNS", CHILD_POLICY_EMPTY);
408:
409: addAttribute("tRNS_Palette", "index", DATATYPE_INTEGER, true,
410: null, VALUE_0, VALUE_255, true, true);
411:
412: addAttribute("tRNS_Palette", "alpha", DATATYPE_INTEGER, true,
413: null, VALUE_0, VALUE_255, true, true);
414:
415: // root -> zTXt
416: addElement("zTXt", CLibPNGMetadata.nativeMetadataFormatName, 1,
417: Integer.MAX_VALUE);
418:
419: // root -> zTXt -> zTXtEntry
420: addElement("zTXtEntry", "zTXt", CHILD_POLICY_EMPTY);
421:
422: addAttribute("zTXtEntry", "keyword", DATATYPE_STRING, true,
423: null);
424:
425: addAttribute(
426: "zTXtEntry",
427: "compressionMethod",
428: DATATYPE_STRING,
429: true,
430: null,
431: Arrays
432: .asList(CLibPNGMetadata.zTXt_compressionMethodNames));
433:
434: addAttribute("zTXtEntry", "text", DATATYPE_STRING, true, null);
435:
436: // root -> UnknownChunks
437: addElement("UnknownChunks",
438: CLibPNGMetadata.nativeMetadataFormatName, 1,
439: Integer.MAX_VALUE);
440:
441: // root -> UnknownChunks -> UnknownChunk
442: addElement("UnknownChunk", "UnknownChunks", CHILD_POLICY_EMPTY);
443:
444: addAttribute("UnknownChunk", "type", DATATYPE_STRING, true,
445: null);
446:
447: addObjectValue("UnknownChunk", byte.class, 0, Integer.MAX_VALUE);
448: }
449:
450: public boolean canNodeAppear(String elementName,
451: ImageTypeSpecifier imageType) {
452: return true;
453: }
454:
455: public static synchronized IIOMetadataFormat getInstance() {
456: if (instance == null) {
457: instance = new CLibPNGMetadataFormat();
458: }
459: return instance;
460: }
461: }
|