KickJava   Java API By Example, From Geeks To Geeks.

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


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 /**
13  * PNG <code>MediaHeader</code> based on the Java Image I/O API.
14  *
15  * @version <tt>$Revision: 1.1 $</tt>
16  * @author <a HREF="mailto:ricardoarguello@users.sourceforge.net">Ricardo Argüello</a>
17  */

18 public class PNGMediaHeader extends IIOMediaHeader
19 {
20    // FIXME
21
private static final long serialVersionUID = 0L;
22
23    private static final String JavaDoc PNG_METADATA_FORMAT_NAME =
24       "javax_imageio_png_1.0";
25
26    private static final String JavaDoc[] FIELD_NAMES =
27       {
28          "width",
29          "height",
30          "bitDepth",
31          "colorType",
32          "compressionMethod",
33          "filterMethod",
34          "interlaceMethod" };
35
36    /** The IHDR chunk, containing the header. */
37    private static final String JavaDoc IHDR = "IHDR";
38
39    /**
40     * Constructor.
41     *
42     * @param metadata
43     * @param metadataFormat
44     */

45    public PNGMediaHeader(IIOMetadata JavaDoc imageMetadata)
46    {
47       super(imageMetadata, PNG_METADATA_FORMAT_NAME);
48    }
49
50    /**
51     * @see javax.emb.MediaHeader#getFieldNames()
52     */

53    public String JavaDoc[] getFieldNames()
54    {
55       return FIELD_NAMES;
56    }
57
58    /**
59     * @see javax.emb.MediaHeader#getField(java.lang.String)
60     */

61    public Object JavaDoc getField(String JavaDoc fieldname)
62    {
63       Object JavaDoc field = null;
64
65       if (fieldname.equals("width"))
66       {
67          field = new Integer JavaDoc(getWidth());
68       }
69
70       if (fieldname.equals("height"))
71       {
72          field = new Integer JavaDoc(getHeight());
73       }
74
75       if (fieldname.equals("bitDepth"))
76       {
77          field = getBitDepth();
78       }
79
80       if (fieldname.equals("colorType"))
81       {
82          field = getColorType();
83       }
84
85       if (fieldname.equals("compressionMethod"))
86       {
87          field = getCompressionMethod();
88       }
89
90       if (fieldname.equals("filterMethod"))
91       {
92          field = getFilterMethod();
93       }
94
95       if (fieldname.equals("interlaceMethod"))
96       {
97          field = getInterlaceMethod();
98       }
99
100       return field;
101    }
102
103    /**
104     * The width of the image in pixels.
105     *
106     * @return 1 (inclusive) to 2147483647 (inclusive).
107     */

108    public int getWidth()
109    {
110       String JavaDoc width = getAttribute(IHDR, "width");
111       return Integer.parseInt(width);
112    }
113
114    /**
115     * The height of the image in pixels.
116     *
117     * @return 1 (inclusive) to 2147483647 (inclusive).
118     */

119    public int getHeight()
120    {
121       String JavaDoc height = getAttribute(IHDR, "height");
122       return Integer.parseInt(height);
123    }
124
125    /**
126     * The bit depth of the image samples.
127     *
128     * @return "1", "2", "4", "8" or "16".
129     */

130    public String JavaDoc getBitDepth()
131    {
132       return getAttribute(IHDR, "bitDepth");
133    }
134
135    /**
136     * The color type of the image.
137     *
138     * @return "Grayscale", "RGB", "Palette", "GrayAlpha" or "RGBAlpha".
139     */

140    public String JavaDoc getColorType()
141    {
142       return getAttribute(IHDR, "colorType");
143    }
144
145    /**
146     * The compression used for image data.
147     *
148     * @return allways "deflate".
149     */

150    public String JavaDoc getCompressionMethod()
151    {
152       return getAttribute(IHDR, "compressionMethod");
153    }
154
155    /**
156     * The filtering method used for compression.
157     *
158     * @return allways "adaptive".
159     */

160    public String JavaDoc getFilterMethod()
161    {
162       return getAttribute(IHDR, "filterMethod");
163    }
164
165    /**
166     * The interlacing method.
167     *
168     * @return "none" or "adam7".
169     */

170    public String JavaDoc getInterlaceMethod()
171    {
172       return getAttribute(IHDR, "interlaceMethod");
173    }
174
175    /**
176     * The image gamma, multiplied by 1e5.
177     *
178     * @return 0 (inclusive) to 2147483647 (inclusive).
179     */

180    public int getGamma()
181    {
182       String JavaDoc gamma = getAttribute("gAMA", "value");
183       return Integer.parseInt(gamma);
184    }
185
186    /**
187     * The number of horizontal pixels per unit, multiplied by 1e5.
188     *
189     * @return 0 (inclusive) to 2147483647 (inclusive).
190     */

191    public int getPixelsPerUnitXAxis()
192    {
193       String JavaDoc pixelsPerUnitXAxis = getAttribute("pHYS", "pixelsPerUnitXAxis");
194       return Integer.parseInt(pixelsPerUnitXAxis);
195    }
196
197    /**
198     * The number of vertical pixels per unit, multiplied by 1e5.
199     *
200     * @return 0 (inclusive) to 2147483647 (inclusive).
201     */

202    public int getPixelsPerUnitYAxis()
203    {
204       String JavaDoc pixelsPerUnitYAxis = getAttribute("pHYS", "pixelsPerUnitYAxis");
205       return Integer.parseInt(pixelsPerUnitYAxis);
206    }
207
208    /**
209     * The unit specifier for this chunk (i.e., meters).
210     *
211     * @return "unknown" or "meter".
212     */

213    public String JavaDoc getPixelsPerUnitSpecifier()
214    {
215       return getAttribute("pHYS", "unitSpecifier");
216    }
217 }
218
Popular Tags