001: /*
002: * $RCSfile: PNGDescriptor.java,v $
003: *
004: * Copyright (c) 2005 Sun Microsystems, Inc. All rights reserved.
005: *
006: * Use is subject to license terms.
007: *
008: * $Revision: 1.1 $
009: * $Date: 2005/02/11 04:57:42 $
010: * $State: Exp $
011: */
012: package javax.media.jai.operator;
013:
014: import com.sun.media.jai.codec.PNGDecodeParam;
015: import com.sun.media.jai.codec.SeekableStream;
016: import java.awt.RenderingHints;
017: import java.awt.image.RenderedImage;
018: import java.awt.image.renderable.ParameterBlock;
019: import javax.media.jai.JAI;
020: import javax.media.jai.OperationDescriptorImpl;
021: import javax.media.jai.ParameterBlockJAI;
022: import javax.media.jai.RenderedOp;
023: import javax.media.jai.registry.RenderedRegistryMode;
024:
025: /**
026: * An <code>OperationDescriptor</code> describing the "PNG" operation.
027: *
028: * <p> The "PNG" operation reads a standard PNG version 1.1 input stream.
029: * The PNG (Portable Network Graphics) specification may be
030: * found at <a href="http://www.cdrom.com/pub/png/spec">
031: * <code>http://www.cdrom.com/pub/png/spec</code></a>.
032: *
033: * <p> The "PNG" operation implements the entire PNG specification,
034: * but provides access only to the final, high-resolution version of
035: * interlaced images.
036: *
037: * <p> The second parameter contains an instance of
038: * <code>PNGDecodeParam</code> to be used during the decoding.
039: * It may be set to <code>null</code> in order to perform default
040: * decoding, or equivalently may be omitted.
041: *
042: * <p> The documentation for <code>PNGDecodeParam</code> describes the
043: * possible output formats of PNG images after decoding.
044: *
045: * <p><b> The classes in the <code>com.sun.media.jai.codec</code>
046: * package are not a committed part of the JAI API. Future releases
047: * of JAI will make use of new classes in their place. This
048: * class will change accordingly.</b>
049: *
050: * <p><table border=1>
051: * <caption>Resource List</caption>
052: * <tr><th>Name</th> <th>Value</th></tr>
053: * <tr><td>GlobalName</td> <td>PNG</td></tr>
054: * <tr><td>LocalName</td> <td>PNG</td></tr>
055: * <tr><td>Vendor</td> <td>com.sun.media.jai</td></tr>
056: * <tr><td>Description</td> <td>Reads an image from a PNG stream.</td></tr>
057: * <tr><td>DocURL</td> <td>http://java.sun.com/products/java-media/jai/forDevelopers/jai-apidocs/javax/media/jai/operator/PNGDescriptor.html</td></tr>
058: * <tr><td>Version</td> <td>1.0</td></tr>
059: * <tr><td>arg0Desc</td> <td>The SeekableStream to read from.</td></tr>
060: * <tr><td>arg1Desc</td> <td>The PNGDecodeParam to use.</td></tr>
061: * </table></p>
062: *
063: * <p><table border=1>
064: * <caption>Parameter List</caption>
065: * <tr><th>Name</th> <th>Class Type</th>
066: * <th>Default Value</th></tr>
067: * <tr><td>stream</td> <td>com.sun.media.jai.codec.SeekableStream</td>
068: * <td>NO_PARAMETER_DEFAULT</td>
069: * <tr><td>param</td> <td>com.sun.media.jai.codec.PNGDecodeParam</td>
070: * <td>null</td>
071: * </table></p>
072: *
073: * <p><table border=1>
074: * <caption>Properties</caption>
075: * <tr><th>Property Name</th> <th>Class</th> <th>Comment</th></tr>
076: *
077: * <tr><td>file_type</td> <td>String</td>
078: * <td>"PNG v. 1.0"</td> </tr>
079: * <tr><td>background_color</td> <td>java.awt.Color</td>
080: * <td>The suggested background color.</td> </tr>
081: * <tr><td>significant_bits</td> <td>int[]</td>
082: * <td>The number of significant bits stored in the file.</td> </tr>
083: * <tr><td>bit_depth</td> <td>Integer</td>
084: * <td>The bit depth of the file</td> </tr>
085: * <tr><td>color_type</td> <td>String</td>
086: * <td>One of "Grayscale", "Truecolor", "Index",
087: * "Grayscale with alpha" or "Truecolor with alpha"</td> </tr>
088: * <tr><td>interlace_method</td> <td>String</td>
089: * <td>"None" or "Adam7"</td> </tr>
090: * <tr><td>white_point_x</td> <td>Float</td>
091: * <td>The CIE X coordinate of the white point, if known.</td> </tr>
092: * <tr><td>white_point_y</td> <td>Float</td>
093: * <td>The CIE Y coordinate of the white point, if known.</td> </tr>
094: * <tr><td>red_x</td> <td>Float</td>
095: * <td>The CIE X coordinate of the red primary, if known.</td> </tr>
096: * <tr><td>red_y</td> <td>Float</td>
097: * <td>The CIE Y coordinate of the red primary, if known.</td> </tr>
098: * <tr><td>green_x</td> <td>Float</td>
099: * <td>The CIE X coordinate of the green primary, if known.</td> </tr>
100: * <tr><td>green_y</td> <td>Float</td>
101: * <td>The CIE Y coordinate of the green primary, if known.</td> </tr>
102: * <tr><td>blue_x</td> <td>Float</td>
103: * <td>The CIE X coordinate of the blue primary, if known.</td> </tr>
104: * <tr><td>blue_y</td> <td>Float</td>
105: * <td>The CIE Y coordinate of the blue primary, if known.</td> </tr>
106: * <tr><td>gamma</td> <td>Float</td>
107: * <td>The image gamma, if known.</td> </tr>
108: * <tr><td>x_pixels_per_unit</td> <td>Integer</td>
109: * <td>The number of horizontal pixels per unit.</td> </tr>
110: * <tr><td>y_pixels_per_unit</td> <td>Integer</td>
111: * <td>The number of vertical pixels per unit.</td> </tr>
112: * <tr><td>pixel_aspect_ratio</td> <td>Float</td>
113: * <td>The width of a pixel divided by its height.</td> </tr>
114: * <tr><td>pixel_units</td> <td>String</td>
115: * <td>"Meters" or <code>null</code></td> </tr>
116: * <tr><td>timestamp</td> <td>java.util.Date</td>
117: * <td>The creation or modification time of the image.</td> </tr>
118: * <tr><td>text:*</td> <td>String</td>
119: * <td>The value of a tEXt chunk.</td> </tr>
120: * <tr><td>ztext:*</td> <td>String</td>
121: * <td>The value of a zTXt chunk (not yet implemented).</td> </tr>
122: * <tr><td>chunk:*</td> <td>byte[]</td>
123: * <td>The contents of any non-standard chunks.</td> </tr>
124: * </table></p>
125: *
126: * @see com.sun.media.jai.codec.PNGDecodeParam
127: * @see com.sun.media.jai.codec.SeekableStream
128: * @see javax.media.jai.OperationDescriptor
129: */
130: public class PNGDescriptor extends OperationDescriptorImpl {
131:
132: /**
133: * The resource strings that provide the general documentation and
134: * specify the parameter list for the "PNG" operation.
135: */
136: private static final String[][] resources = {
137: { "GlobalName", "PNG" },
138: { "LocalName", "PNG" },
139: { "Vendor", "com.sun.media.jai" },
140: { "Description", JaiI18N.getString("PNGDescriptor0") },
141: {
142: "DocURL",
143: "http://java.sun.com/products/java-media/jai/forDevelopers/jai-apidocs/javax/media/jai/operator/PNGDescriptor.html" },
144: { "Version", JaiI18N.getString("DescriptorVersion") },
145: { "arg0Desc", JaiI18N.getString("PNGDescriptor1") },
146: { "arg1Desc", JaiI18N.getString("PNGDescriptor2") }, };
147:
148: /** The parameter names for the "PNG" operation. */
149: private static final String[] paramNames = { "stream", "param" };
150:
151: /** The parameter class types for the "PNG" operation. */
152: private static final Class[] paramClasses = {
153: com.sun.media.jai.codec.SeekableStream.class,
154: com.sun.media.jai.codec.PNGDecodeParam.class };
155:
156: /** The parameter default values for the "PNG" operation. */
157: private static final Object[] paramDefaults = {
158: NO_PARAMETER_DEFAULT, null };
159:
160: /** Constructor. */
161: public PNGDescriptor() {
162: super (resources, 0, paramClasses, paramNames, paramDefaults);
163: }
164:
165: /**
166: * Reads a standard JFIF (PNG) file.
167: *
168: * <p>Creates a <code>ParameterBlockJAI</code> from all
169: * supplied arguments except <code>hints</code> and invokes
170: * {@link JAI#create(String,ParameterBlock,RenderingHints)}.
171: *
172: * @see JAI
173: * @see ParameterBlockJAI
174: * @see RenderedOp
175: *
176: * @param stream The SeekableStream to read from.
177: * @param param The PNGDecodeParam to use.
178: * May be <code>null</code>.
179: * @param hints The <code>RenderingHints</code> to use.
180: * May be <code>null</code>.
181: * @return The <code>RenderedOp</code> destination.
182: * @throws IllegalArgumentException if <code>stream</code> is <code>null</code>.
183: */
184: public static RenderedOp create(SeekableStream stream,
185: PNGDecodeParam param, RenderingHints hints) {
186: ParameterBlockJAI pb = new ParameterBlockJAI("PNG",
187: RenderedRegistryMode.MODE_NAME);
188:
189: pb.setParameter("stream", stream);
190: pb.setParameter("param", param);
191:
192: return JAI.create("PNG", pb, hints);
193: }
194: }
|