KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > imageio > plugins > jpeg > JPEGImageMetadataFormat


1 /*
2  * @(#)JPEGImageMetadataFormat.java 1.12 03/12/19
3  *
4  * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
5  * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
6  */

7
8 package com.sun.imageio.plugins.jpeg;
9
10 import javax.imageio.metadata.IIOMetadataFormat JavaDoc;
11 import javax.imageio.metadata.IIOMetadataFormatImpl JavaDoc;
12 import javax.imageio.ImageTypeSpecifier JavaDoc;
13
14 import java.awt.color.ICC_Profile JavaDoc;
15 import java.awt.color.ColorSpace JavaDoc;
16 import java.awt.image.ColorModel JavaDoc;
17
18 import java.util.List JavaDoc;
19 import java.util.ArrayList JavaDoc;
20
21 public class JPEGImageMetadataFormat extends JPEGMetadataFormat {
22
23     private static JPEGImageMetadataFormat theInstance = null;
24
25     private JPEGImageMetadataFormat() {
26         super(JPEG.nativeImageMetadataFormatName,
27               CHILD_POLICY_ALL);
28
29         addElement("JPEGvariety",
30                    JPEG.nativeImageMetadataFormatName,
31                    CHILD_POLICY_CHOICE);
32
33         addElement("markerSequence",
34                    JPEG.nativeImageMetadataFormatName,
35                    CHILD_POLICY_SEQUENCE);
36
37         addElement("app0JFIF", "JPEGvariety", CHILD_POLICY_SOME);
38
39         addStreamElements("markerSequence");
40
41         addElement("app14Adobe", "markerSequence", CHILD_POLICY_EMPTY);
42
43         addElement("sof", "markerSequence", 1, 4);
44
45         addElement("sos", "markerSequence", 1, 4);
46
47         addElement("JFXX", "app0JFIF", 1, Integer.MAX_VALUE);
48
49         addElement("app0JFXX", "JFXX", CHILD_POLICY_CHOICE);
50
51         addElement("app2ICC", "app0JFIF", CHILD_POLICY_EMPTY);
52
53         addAttribute("app0JFIF",
54                      "majorVersion",
55                      DATATYPE_INTEGER,
56                      false,
57                      "1",
58                      "0", "255",
59                      true, true);
60         addAttribute("app0JFIF",
61                      "minorVersion",
62                      DATATYPE_INTEGER,
63                      false,
64                      "2",
65                      "0", "255",
66                      true, true);
67         List JavaDoc resUnits = new ArrayList JavaDoc();
68         resUnits.add("0");
69         resUnits.add("1");
70         resUnits.add("2");
71         addAttribute("app0JFIF",
72                      "resUnits",
73                      DATATYPE_INTEGER,
74                      false,
75                      "0",
76                      resUnits);
77         addAttribute("app0JFIF",
78                      "Xdensity",
79                      DATATYPE_INTEGER,
80                      false,
81                      "1",
82                      "1", "65535",
83                      true, true);
84         addAttribute("app0JFIF",
85                      "Ydensity",
86                      DATATYPE_INTEGER,
87                      false,
88                      "1",
89                      "1", "65535",
90                      true, true);
91         addAttribute("app0JFIF",
92                      "thumbWidth",
93                      DATATYPE_INTEGER,
94                      false,
95                      "0",
96                      "0", "255",
97                      true, true);
98         addAttribute("app0JFIF",
99                      "thumbHeight",
100                      DATATYPE_INTEGER,
101                      false,
102                      "0",
103                      "0", "255",
104                      true, true);
105
106         addElement("JFIFthumbJPEG", "app0JFXX", CHILD_POLICY_SOME);
107         addElement("JFIFthumbPalette", "app0JFXX", CHILD_POLICY_EMPTY);
108         addElement("JFIFthumbRGB", "app0JFXX", CHILD_POLICY_EMPTY);
109
110         List JavaDoc codes = new ArrayList JavaDoc();
111         codes.add("16"); // Hex 10
112
codes.add("17"); // Hex 11
113
codes.add("19"); // Hex 13
114
addAttribute("app0JFXX",
115                      "extensionCode",
116                      DATATYPE_INTEGER,
117                      false,
118                      null,
119                      codes);
120
121         addChildElement("markerSequence", "JFIFthumbJPEG");
122
123         addAttribute("JFIFthumbPalette",
124                      "thumbWidth",
125                      DATATYPE_INTEGER,
126                      false,
127                      null,
128                      "0", "255",
129                      true, true);
130         addAttribute("JFIFthumbPalette",
131                      "thumbHeight",
132                      DATATYPE_INTEGER,
133                      false,
134                      null,
135                      "0", "255",
136                      true, true);
137
138         addAttribute("JFIFthumbRGB",
139                      "thumbWidth",
140                      DATATYPE_INTEGER,
141                      false,
142                      null,
143                      "0", "255",
144                      true, true);
145         addAttribute("JFIFthumbRGB",
146                      "thumbHeight",
147                      DATATYPE_INTEGER,
148                      false,
149                      null,
150                      "0", "255",
151                      true, true);
152
153         addObjectValue("app2ICC", ICC_Profile JavaDoc.class, false, null);
154
155         addAttribute("app14Adobe",
156                      "version",
157                      DATATYPE_INTEGER,
158                      false,
159                      "100",
160                      "100", "255",
161                      true, true);
162         addAttribute("app14Adobe",
163                      "flags0",
164                      DATATYPE_INTEGER,
165                      false,
166                      "0",
167                      "0", "65535",
168                      true, true);
169         addAttribute("app14Adobe",
170                      "flags1",
171                      DATATYPE_INTEGER,
172                      false,
173                      "0",
174                      "0", "65535",
175                      true, true);
176
177         List JavaDoc transforms = new ArrayList JavaDoc();
178         transforms.add("0");
179         transforms.add("1");
180         transforms.add("2");
181         addAttribute("app14Adobe",
182                      "transform",
183                      DATATYPE_INTEGER,
184                      true,
185                      null,
186                      transforms);
187
188         addElement("componentSpec", "sof", CHILD_POLICY_EMPTY);
189
190         List JavaDoc procs = new ArrayList JavaDoc();
191         procs.add("0");
192         procs.add("1");
193         procs.add("2");
194         addAttribute("sof",
195                      "process",
196                      DATATYPE_INTEGER,
197                      false,
198                      null,
199                      procs);
200         addAttribute("sof",
201                      "samplePrecision",
202                      DATATYPE_INTEGER,
203                      false,
204                      "8");
205         addAttribute("sof",
206                      "numLines",
207                      DATATYPE_INTEGER,
208                      false,
209                      null,
210                      "0", "65535",
211                      true, true);
212         addAttribute("sof",
213                      "samplesPerLine",
214                      DATATYPE_INTEGER,
215                      false,
216                      null,
217                      "0", "65535",
218                      true, true);
219         List JavaDoc comps = new ArrayList JavaDoc();
220         comps.add("1");
221         comps.add("2");
222         comps.add("3");
223         comps.add("4");
224         addAttribute("sof",
225                      "numFrameComponents",
226                      DATATYPE_INTEGER,
227                      false,
228                      null,
229                      comps);
230
231         addAttribute("componentSpec",
232                      "componentId",
233                      DATATYPE_INTEGER,
234                      true,
235                      null,
236                      "0", "255",
237                      true, true);
238         addAttribute("componentSpec",
239                      "HsamplingFactor",
240                      DATATYPE_INTEGER,
241                      true,
242                      null,
243                      "1", "255",
244                      true, true);
245         addAttribute("componentSpec",
246                      "VsamplingFactor",
247                      DATATYPE_INTEGER,
248                      true,
249                      null,
250                      "1", "255",
251                      true, true);
252         List JavaDoc tabids = new ArrayList JavaDoc();
253         tabids.add("0");
254         tabids.add("1");
255         tabids.add("2");
256         tabids.add("3");
257         addAttribute("componentSpec",
258                      "QtableSelector",
259                      DATATYPE_INTEGER,
260                      true,
261                      null,
262                      tabids);
263
264         addElement("scanComponentSpec", "sos", CHILD_POLICY_EMPTY);
265
266         addAttribute("sos",
267                      "numScanComponents",
268                      DATATYPE_INTEGER,
269                      true,
270                      null,
271                      comps);
272         addAttribute("sos",
273                      "startSpectralSelection",
274                       DATATYPE_INTEGER,
275                      false,
276                      "0",
277                      "0", "63",
278                      true, true);
279         addAttribute("sos",
280                      "endSpectralSelection",
281                       DATATYPE_INTEGER,
282                      false,
283                      "63",
284                      "0", "63",
285                      true, true);
286         addAttribute("sos",
287                      "approxHigh",
288                       DATATYPE_INTEGER,
289                      false,
290                      "0",
291                      "0", "15",
292                      true, true);
293         addAttribute("sos",
294                      "approxLow",
295                       DATATYPE_INTEGER,
296                      false,
297                      "0",
298                      "0", "15",
299                      true, true);
300
301         addAttribute("scanComponentSpec",
302                      "componentSelector",
303                      DATATYPE_INTEGER,
304                      true,
305                      null,
306                      "0", "255",
307                      true, true);
308         addAttribute("scanComponentSpec",
309                      "dcHuffTable",
310                      DATATYPE_INTEGER,
311                      true,
312                      null,
313                      tabids);
314         addAttribute("scanComponentSpec",
315                      "acHuffTable",
316                      DATATYPE_INTEGER,
317                      true,
318                      null,
319                      tabids);
320     }
321
322     public boolean canNodeAppear(String JavaDoc elementName,
323                                  ImageTypeSpecifier JavaDoc imageType) {
324         // All images can have these
325
if (elementName.equals(getRootName())
326             || elementName.equals("JPEGvariety")
327             || isInSubtree(elementName, "markerSequence")) {
328             return true;
329         }
330
331         // If it is an element in the app0jfif subtree, just check
332
// that the image type is JFIF compliant.
333
if ((isInSubtree(elementName, "app0JFIF"))
334             && JPEG.isJFIFcompliant(imageType, true)) {
335             return true;
336         }
337         
338         return false;
339     }
340
341
342     public static synchronized IIOMetadataFormat JavaDoc getInstance() {
343         if (theInstance == null) {
344             theInstance = new JPEGImageMetadataFormat();
345         }
346         return theInstance;
347     }
348 }
349
Popular Tags