KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > media > format > image > iio > StandardMediaHeader


1 /*
2  * JBoss, the OpenSource J2EE webOS
3  *
4  * Distributable under LGPL license.
5  * See terms of license at gnu.org.
6  */

7
8 package org.jboss.media.format.image.iio;
9
10 import javax.imageio.metadata.IIOMetadata JavaDoc;
11
12 import org.w3c.dom.Node JavaDoc;
13
14 /**
15  * <code>MediaHeader</code> based on the Standard (Plug-in Neutral)
16  * Metadata Format Specification of the Java Image I/O API.
17  *
18  * @version <tt>$Revision: 1.1 $</tt>
19  * @author <a HREF="mailto:ricardoarguello@users.sourceforge.net">Ricardo Argüello</a>
20  */

21 public class StandardMediaHeader extends IIOMediaHeader
22 {
23    // FIXME
24
private static final long serialVersionUID = 0L;
25
26    private static final String JavaDoc STANDARD_METADATA_FORMAT_NAME =
27       "javax_imageio_1.0";
28
29    private static final String JavaDoc[] FIELD_NAMES =
30       {
31          "colorSpaceType",
32          "numChannels",
33          "gamma",
34          "blackIsZero",
35          "compressionTypeName",
36          "lossless",
37          "numProgressiveScans",
38          "bitRate",
39          "planarConfiguration",
40          "sampleFormat",
41          "bitsPerSample",
42          "significantBitsPerSample",
43          "sampleMSB",
44          "pixelAspectRatio",
45          "imageOrientation",
46          "horizontalPixelSize",
47          "verticalPixelSize",
48          "horizontalPhysicalPixelSpacing",
49          "verticalPhysicalPixelSpacing",
50          "horizontalPosition",
51          "verticalPosition",
52          "horizontalPixelOffset",
53          "verticalPixelOffset",
54          "horizontalScreenSize",
55          "verticalScreenSize",
56          "formatVersion",
57          "subimageInterpretation",
58          "imageCreationYear" };
59
60    /**
61     * Constructor.
62     *
63     * @param metadata
64     * @param metadataFormat
65     */

66    public StandardMediaHeader(IIOMetadata JavaDoc imageMetadata)
67    {
68       super(imageMetadata, STANDARD_METADATA_FORMAT_NAME);
69    }
70
71    /**
72     * @see javax.emb.MediaHeader#getFieldNames()
73     */

74    public String JavaDoc[] getFieldNames()
75    {
76       return FIELD_NAMES;
77    }
78
79    /**
80     * @see javax.emb.MediaHeader#getField(java.lang.String)
81     */

82    public Object JavaDoc getField(String JavaDoc fieldname)
83    {
84       Object JavaDoc field = null;
85
86       if (fieldname.equals("colorSpaceType"))
87       {
88          field = getColorSpaceType();
89       }
90
91       if (fieldname.equals("numChannels"))
92       {
93          field = getNumChannels();
94       }
95
96       if (fieldname.equals("gamma"))
97       {
98          field = new Float JavaDoc(getGamma());
99       }
100
101       if (fieldname.equals("blackIsZero"))
102       {
103          field = getBlackIsZero();
104       }
105
106       if (fieldname.equals("compressionTypeName"))
107       {
108          field = getCompressionTypeName();
109       }
110
111       if (fieldname.equals("lossless"))
112       {
113          field = getLossless();
114       }
115
116       if (fieldname.equals("numProgressiveScans"))
117       {
118          field = new Integer JavaDoc(getNumProgressiveScans());
119       }
120
121       if (fieldname.equals("bitRate"))
122       {
123          field = new Float JavaDoc(getBitRate());
124       }
125
126       if (fieldname.equals("planarConfiguration"))
127       {
128          field = getPlanarConfiguration();
129       }
130
131       if (fieldname.equals("sampleFormat"))
132       {
133          field = getSampleFormat();
134       }
135
136       if (fieldname.equals("bitsPerSample"))
137       {
138          field = getBitsPerSample();
139       }
140
141       if (fieldname.equals("significantBitsPerSample"))
142       {
143          field = getSignificantBitsPerSample();
144       }
145
146       if (fieldname.equals("sampleMSB"))
147       {
148          field = getSampleMSB();
149       }
150
151       if (fieldname.equals("pixelAspectRatio"))
152       {
153          field = new Float JavaDoc(getPixelAspectRatio());
154       }
155
156       if (fieldname.equals("imageOrientation"))
157       {
158          field = getImageOrientation();
159       }
160
161       if (fieldname.equals("horizontalPixelSize"))
162       {
163          field = new Float JavaDoc(getHorizontalPixelSize());
164       }
165
166       if (fieldname.equals("verticalPixelSize"))
167       {
168          field = new Float JavaDoc(getVerticalPixelSize());
169       }
170
171       if (fieldname.equals("horizontalPhysicalPixelSpacing"))
172       {
173          field = new Float JavaDoc(getHorizontalPhysicalPixelSpacing());
174       }
175
176       if (fieldname.equals("verticalPhysicalPixelSpacing"))
177       {
178          field = new Float JavaDoc(getVerticalPhysicalPixelSpacing());
179       }
180
181       if (fieldname.equals("horizontalPosition"))
182       {
183          field = new Float JavaDoc(getHorizontalPosition());
184       }
185
186       if (fieldname.equals("verticalPosition"))
187       {
188          field = new Float JavaDoc(getVerticalPosition());
189       }
190
191       if (fieldname.equals("horizontalPixelOffset"))
192       {
193          field = new Integer JavaDoc(getHorizontalPixelOffset());
194       }
195
196       if (fieldname.equals("verticalPixelOffset"))
197       {
198          field = new Integer JavaDoc(getVerticalPixelOffset());
199       }
200
201       if (fieldname.equals("horizontalScreenSize"))
202       {
203          field = new Integer JavaDoc(getHorizontalScreenSize());
204       }
205
206       if (fieldname.equals("verticalScreenSize"))
207       {
208          field = new Integer JavaDoc(getVerticalScreenSize());
209       }
210
211       if (fieldname.equals("formatVersion"))
212       {
213          field = getFormatVersion();
214       }
215
216       if (fieldname.equals("subimageInterpretation"))
217       {
218          field = getSubimageInterpretation();
219       }
220
221       if (fieldname.equals("imageCreationYear"))
222       {
223          field = new Integer JavaDoc(getImageCreationYear());
224       }
225
226       return field;
227    }
228
229    /**
230     * The raw color space of the image.
231     *
232     * @return "XYZ", "Lab", "Luv", "YCbCr", "Yxy", "YCCK", "PhotoYCC", "RGB",
233     * "GRAY", "HSV", "HLS", "CMYK", "CMY", "2CLR", "3CLR", "4CLR",
234     * "5CLR", "6CLR", "7CLR", "8CLR", "9CLR", "ACLR", "BCLR", "CCLR",
235     * "DCLR", "ECLR" or "FCLR".
236     */

237    public String JavaDoc getColorSpaceType()
238    {
239       Node JavaDoc chroma = getChromaNode();
240       Node JavaDoc colorSpaceType = getNode(chroma, "ColorSpaceType");
241       return getAttribute(colorSpaceType, "name");
242    }
243
244    /**
245     * The number of channels in the raw image, including alpha.
246     *
247     * @return number of channels.
248     */

249    public String JavaDoc getNumChannels()
250    {
251       Node JavaDoc chroma = getChromaNode();
252       Node JavaDoc numChannels = getNode(chroma, "NumChannels");
253       return getAttribute(numChannels, "value");
254    }
255
256    /**
257     * The image gamma.
258     *
259     * @return gamma.
260     */

261    public float getGamma()
262    {
263       Node JavaDoc chroma = getChromaNode();
264       Node JavaDoc gamma = getNode(chroma, "Gamma");
265       String JavaDoc value = getAttribute(gamma, "value");
266       return Float.parseFloat(value);
267    }
268
269    /**
270     * True if smaller values represent darker shades.
271     *
272     * @return "TRUE" or "FALSE".
273     */

274    public String JavaDoc getBlackIsZero()
275    {
276       Node JavaDoc chroma = getChromaNode();
277       Node JavaDoc blackIsZero = getNode(chroma, "BlackIsZero");
278       return getAttribute(blackIsZero, "value");
279    }
280
281    /**
282     * The name of the compression scheme in use.
283     *
284     * @return compression type name.
285     */

286    public String JavaDoc getCompressionTypeName()
287    {
288       Node JavaDoc compression = getCompressionNode();
289       Node JavaDoc compressionTypeName = getNode(compression, "CompressionTypeName");
290       return getAttribute(compressionTypeName, "value");
291    }
292
293    /**
294     * True if the compression scheme is lossless.
295     *
296     * @return lossless.
297     */

298    public String JavaDoc getLossless()
299    {
300       Node JavaDoc compression = getCompressionNode();
301       Node JavaDoc lossless = getNode(compression, "Lossless");
302       return getAttribute(lossless, "value");
303    }
304
305    /**
306     * The number of progressive scans used in the image encoding.
307     *
308     * @param number of progressive scans.
309     */

310    public int getNumProgressiveScans()
311    {
312       Node JavaDoc compression = getCompressionNode();
313       Node JavaDoc numProgressiveScans = getNode(compression, "NumProgressiveScans");
314       String JavaDoc value = getAttribute(numProgressiveScans, "value");
315       return Integer.parseInt(value);
316    }
317
318    /**
319     * The estimated bit rate of the compression scheme.
320     *
321     * @return bit rate.
322     */

323    public float getBitRate()
324    {
325       Node JavaDoc compression = getCompressionNode();
326       Node JavaDoc bitRate = getNode(compression, "BitRate");
327       String JavaDoc value = getAttribute(bitRate, "value");
328       return value == null ? 0 : Float.parseFloat(value);
329    }
330
331    /**
332     * The organization of image samples in the stream.
333     *
334     * @return "PixelInterleaved", "PlaneInterleaved", "LineInterleaved" or
335     * "TileInterleaved".
336     */

337    public String JavaDoc getPlanarConfiguration()
338    {
339       Node JavaDoc data = getDataNode();
340       Node JavaDoc planarConfiguration = getNode(data, "PlanarConfiguration");
341       return getAttribute(planarConfiguration, "value");
342    }
343
344    /**
345     * The numeric format of image samples.
346     *
347     * @return "SignedIntegral", "UnsignedIntegral", "Real" or "Index".
348     */

349    public String JavaDoc getSampleFormat()
350    {
351       Node JavaDoc data = getDataNode();
352       Node JavaDoc sampleFormat = getNode(data, "SampleFormat");
353       return getAttribute(sampleFormat, "value");
354    }
355
356    /**
357     * The number of bits per sample.
358     *
359     * @return bits per sample.
360     */

361    public String JavaDoc getBitsPerSample()
362    {
363       Node JavaDoc data = getDataNode();
364       Node JavaDoc bitsPerSample = getNode(data, "BitsPerSample");
365       return getAttribute(bitsPerSample, "value");
366    }
367
368    /**
369     * The number of significant bits per sample.
370     *
371     * @return significant bits per sample.
372     */

373    public String JavaDoc getSignificantBitsPerSample()
374    {
375       Node JavaDoc data = getDataNode();
376       Node JavaDoc significantBitsPerSample = getNode(data, "SignificantBitsPerSample");
377       return getAttribute(significantBitsPerSample, "value");
378    }
379
380    /**
381     * The position of the most significant bit of each sample.
382     *
383     * @return sample most significant bit.
384     */

385    public String JavaDoc getSampleMSB()
386    {
387       Node JavaDoc data = getDataNode();
388       Node JavaDoc sampleMSB = getNode(data, "SampleMSB");
389       return getAttribute(sampleMSB, "value");
390    }
391
392    /**
393     * The width of a pixel divided by its height.
394     *
395     * @return pixel aspect ratio.
396     */

397    public float getPixelAspectRatio()
398    {
399       Node JavaDoc dimension = getDimensionNode();
400       Node JavaDoc pixelAspectRatio = getNode(dimension, "PixelAspectRatio");
401       String JavaDoc value = getAttribute(pixelAspectRatio, "value");
402       return Float.parseFloat(value);
403    }
404
405    /**
406     * The desired orientation of the image in terms of flips and
407     * counter-clockwise rotations.
408     *
409     * @return image orientation.
410     */

411    public String JavaDoc getImageOrientation()
412    {
413       Node JavaDoc dimension = getDimensionNode();
414       Node JavaDoc imageOrientation = getNode(dimension, "ImageOrientation");
415       return getAttribute(imageOrientation, "value");
416    }
417
418    /**
419     * The width of a pixel, in millimeters, as it should be rendered on media.
420     *
421     * @return horizontal pixel size.
422     */

423    public float getHorizontalPixelSize()
424    {
425       Node JavaDoc dimension = getDimensionNode();
426       Node JavaDoc horizontalPixelSize = getNode(dimension, "HorizontalPixelSize");
427       String JavaDoc value = getAttribute(horizontalPixelSize, "value");
428       return Float.parseFloat(value);
429    }
430
431    /**
432     * The height of a pixel, in millimeters, as it should be rendered on media.
433     *
434     * @return vertical pixel size.
435     */

436    public float getVerticalPixelSize()
437    {
438       Node JavaDoc dimension = getDimensionNode();
439       Node JavaDoc verticalPixelSize = getNode(dimension, "VerticalPixelSize");
440       String JavaDoc value = getAttribute(verticalPixelSize, "value");
441       return Float.parseFloat(value);
442    }
443
444    /**
445     * The horizontal distance in the subject of the image, in millimeters,
446     * represented by one pixel at the center of the image.
447     *
448     * @return horizontal physical pixel spacing.
449     */

450    public float getHorizontalPhysicalPixelSpacing()
451    {
452       Node JavaDoc dimension = getDimensionNode();
453       Node JavaDoc horizontalPhysicalPixelSpacing =
454          getNode(dimension, "HorizontalPhysicalPixelSpacing");
455       String JavaDoc value = getAttribute(horizontalPhysicalPixelSpacing, "value");
456       return value == null ? 0 : Float.parseFloat(value);
457    }
458
459    /**
460     * The vertical distance in the subject of the image, in millimeters,
461     * represented by one pixel at the center of the image.
462     *
463     * @return vertical physical pixel spacing.
464     */

465    public float getVerticalPhysicalPixelSpacing()
466    {
467       Node JavaDoc dimension = getDimensionNode();
468       Node JavaDoc verticalPhysicalPixelSpacing =
469          getNode(dimension, "VerticalPhysicalPixelSpacing");
470       String JavaDoc value = getAttribute(verticalPhysicalPixelSpacing, "value");
471       return value == null ? 0 : Float.parseFloat(value);
472    }
473
474    /**
475     * The horizontal position, in millimeters, where the image should be
476     * rendered on media.
477     *
478     * @return horizontal position.
479     */

480    public float getHorizontalPosition()
481    {
482       Node JavaDoc dimension = getDimensionNode();
483       Node JavaDoc horizontalPosition = getNode(dimension, "HorizontalPosition");
484       String JavaDoc value = getAttribute(horizontalPosition, "value");
485       return value == null ? 0 : Float.parseFloat(value);
486    }
487
488    /**
489     * The vertical position, in millimeters, where the image should be
490     * rendered on media.
491     *
492     * @return vertical position.
493     */

494    public float getVerticalPosition()
495    {
496       Node JavaDoc dimension = getDimensionNode();
497       Node JavaDoc verticalPosition = getNode(dimension, "VerticalPosition");
498       String JavaDoc value = getAttribute(verticalPosition, "value");
499       return value == null ? 0 : Float.parseFloat(value);
500    }
501
502    /**
503     * The horizonal position, in pixels, where the image should be rendered
504     * onto a raster display.
505     *
506     * @return horizontal pixel offset.
507     */

508    public int getHorizontalPixelOffset()
509    {
510       Node JavaDoc dimension = getDimensionNode();
511       Node JavaDoc horizontalPixelOffset = getNode(dimension, "HorizontalPixelOffset");
512       String JavaDoc value = getAttribute(horizontalPixelOffset, "value");
513       return value == null ? 0 : Integer.parseInt(value);
514    }
515
516    /**
517     * The vertical position, in pixels, where the image should be rendered
518     * onto a raster display.
519     *
520     * @return vertical pixel offset.
521     */

522    public int getVerticalPixelOffset()
523    {
524       Node JavaDoc dimension = getDimensionNode();
525       Node JavaDoc verticalPixelOffset = getNode(dimension, "VerticalPixelOffset");
526       String JavaDoc value = getAttribute(verticalPixelOffset, "value");
527       return value == null ? 0 : Integer.parseInt(value);
528    }
529
530    /**
531     * The width, in pixels, of the raster display into which the image should
532     * be rendered.
533     *
534     * @return horizontal screen size.
535     */

536    public int getHorizontalScreenSize()
537    {
538       Node JavaDoc dimension = getDimensionNode();
539       Node JavaDoc horizontalScreenSize = getNode(dimension, "HorizontalScreenSize");
540       String JavaDoc value = getAttribute(horizontalScreenSize, "value");
541       return value == null ? 0 : Integer.parseInt(value);
542    }
543
544    /**
545     * The height, in pixels, of the raster display into which the image should
546     * be rendered.
547     *
548     * @return vertical screen size.
549     */

550    public int getVerticalScreenSize()
551    {
552       Node JavaDoc dimension = getDimensionNode();
553       Node JavaDoc verticalScreenSize = getNode(dimension, "VerticalScreenSize");
554       String JavaDoc value = getAttribute(verticalScreenSize, "value");
555       return value == null ? 0 : Integer.parseInt(value);
556    }
557
558    /**
559     * The version of the format used by the stream.
560     *
561     * @return format version.
562     */

563    public String JavaDoc getFormatVersion()
564    {
565       Node JavaDoc document = getDocumentNode();
566       Node JavaDoc formatVersion = getNode(document, "FormatVersion");
567       return getAttribute(formatVersion, "value");
568    }
569
570    /**
571     * The interpretation of this image in relation to the other images stored
572     * in the same stream.
573     *
574     * @return "Standalone", "SinglePage", "FullResolution", "ReducedResolution"
575     * "PyramidLayer", "Preview", "VolumeSlice", "ObjectView",
576     * "Panorama", "AnimationFrame", "TransparencyMask",
577     * "CompositingLayer", "SpectralSlice" or "Unknown".
578     */

579    public String JavaDoc getSubimageInterpretation()
580    {
581       Node JavaDoc document = getDocumentNode();
582       Node JavaDoc subimageInterpretation = getNode(document, "SubimageInterpretation");
583       return getAttribute(subimageInterpretation, "value");
584    }
585
586    /**
587     * The full year of image creation (e.g., 1967, not 67).
588     *
589     * @return image creation year.
590     */

591    public int getImageCreationYear()
592    {
593       Node JavaDoc document = getDocumentNode();
594       Node JavaDoc formatVersion = getNode(document, "ImageCreationTime");
595       String JavaDoc value = getAttribute(formatVersion, "year");
596       return value == null ? 0 : Integer.parseInt(value);
597    }
598
599    //-------------------------
600
private Node JavaDoc getChromaNode()
601    {
602       return getNode("Chroma");
603    }
604
605    private Node JavaDoc getCompressionNode()
606    {
607       return getNode("Compression");
608    }
609
610    private Node JavaDoc getDataNode()
611    {
612       return getNode("Data");
613    }
614
615    private Node JavaDoc getDimensionNode()
616    {
617       return getNode("Dimension");
618    }
619
620    private Node JavaDoc getDocumentNode()
621    {
622       return getNode("Document");
623    }
624
625    /* <!ELEMENT "Document" (FormatVersion?, SubimageInterpretation?,
626          ImageCreationTime?, ImageModificationTime?)>
627          <!-- Document information -->
628    
629    
630          <!ELEMENT "ImageCreationTime" EMPTY>
631            <!-- The time of image creation -->
632            <!ATTLIST "ImageCreationTime" "year" #CDATA #REQUIRED>
633              <!-- The full year (e.g., 1967, not 67) -->
634              <!-- Data type: Integer -->
635            <!ATTLIST "ImageCreationTime" "month" #CDATA #REQUIRED>
636              <!-- The month, with January = 1 -->
637              <!-- Data type: Integer -->
638              <!-- Min value: 1 (inclusive) -->
639              <!-- Max value: 12 (inclusive) -->
640            <!ATTLIST "ImageCreationTime" "day" #CDATA #REQUIRED>
641              <!-- The day of the month -->
642              <!-- Data type: Integer -->
643              <!-- Min value: 1 (inclusive) -->
644              <!-- Max value: 31 (inclusive) -->
645            <!ATTLIST "ImageCreationTime" "hour" #CDATA "0">
646              <!-- The hour from 0 to 23 -->
647              <!-- Data type: Integer -->
648              <!-- Min value: 0 (inclusive) -->
649              <!-- Max value: 23 (inclusive) -->
650            <!ATTLIST "ImageCreationTime" "minute" #CDATA "0">
651              <!-- The minute from 0 to 59 -->
652              <!-- Data type: Integer -->
653              <!-- Min value: 0 (inclusive) -->
654              <!-- Max value: 59 (inclusive) -->
655            <!ATTLIST "ImageCreationTime" "second" #CDATA "0">
656              <!-- The second from 0 to 60 (60 = leap second) -->
657              <!-- Data type: Integer -->
658              <!-- Min value: 0 (inclusive) -->
659              <!-- Max value: 60 (inclusive) -->
660    
661          <!ELEMENT "ImageModificationTime" EMPTY>
662            <!-- The time of the last image modification -->
663            <!ATTLIST "ImageModificationTime" "year" #CDATA #REQUIRED>
664              <!-- The full year (e.g., 1967, not 67) -->
665              <!-- Data type: Integer -->
666            <!ATTLIST "ImageModificationTime" "month" #CDATA #REQUIRED>
667              <!-- The month, with January = 1 -->
668              <!-- Data type: Integer -->
669              <!-- Min value: 1 (inclusive) -->
670              <!-- Max value: 12 (inclusive) -->
671            <!ATTLIST "ImageModificationTime" "day" #CDATA #REQUIRED>
672              <!-- The day of the month -->
673              <!-- Data type: Integer -->
674              <!-- Min value: 1 (inclusive) -->
675              <!-- Max value: 31 (inclusive) -->
676            <!ATTLIST "ImageModificationTime" "hour" #CDATA "0">
677              <!-- The hour from 0 to 23 -->
678              <!-- Data type: Integer -->
679              <!-- Min value: 0 (inclusive) -->
680              <!-- Max value: 23 (inclusive) -->
681            <!ATTLIST "ImageModificationTime" "minute" #CDATA "0">
682              <!-- The minute from 0 to 59 -->
683              <!-- Data type: Integer -->
684              <!-- Min value: 0 (inclusive) -->
685              <!-- Max value: 59 (inclusive) -->
686            <!ATTLIST "ImageModificationTime" "second" #CDATA "0">
687              <!-- The second from 0 to 60 (60 = leap second) -->
688              <!-- Data type: Integer -->
689              <!-- Min value: 0 (inclusive) -->
690              <!-- Max value: 60 (inclusive) -->
691    */

692 }
693
Popular Tags