1 /* 2 * $RCSfile: PNGDescriptor.java,v $ 3 * 4 * Copyright (c) 2005 Sun Microsystems, Inc. All rights reserved. 5 * 6 * Use is subject to license terms. 7 * 8 * $Revision: 1.1 $ 9 * $Date: 2005/02/11 04:57:42 $ 10 * $State: Exp $ 11 */ 12 package com.lightcrafts.mediax.jai.operator; 13 import com.lightcrafts.media.jai.codec.PNGDecodeParam; 14 import com.lightcrafts.media.jai.codec.SeekableStream; 15 import java.awt.RenderingHints; 16 import java.awt.image.renderable.ParameterBlock; 17 import com.lightcrafts.mediax.jai.JAI; 18 import com.lightcrafts.mediax.jai.OperationDescriptorImpl; 19 import com.lightcrafts.mediax.jai.ParameterBlockJAI; 20 import com.lightcrafts.mediax.jai.RenderedOp; 21 import com.lightcrafts.mediax.jai.registry.RenderedRegistryMode; 22 23 /** 24 * An <code>OperationDescriptor</code> describing the "PNG" operation. 25 * 26 * <p> The "PNG" operation reads a standard PNG version 1.1 input stream. 27 * The PNG (Portable Network Graphics) specification may be 28 * found at <a href="http://www.cdrom.com/pub/png/spec"> 29 * <code>http://www.cdrom.com/pub/png/spec</code></a>. 30 * 31 * <p> The "PNG" operation implements the entire PNG specification, 32 * but provides access only to the final, high-resolution version of 33 * interlaced images. 34 * 35 * <p> The second parameter contains an instance of 36 * <code>PNGDecodeParam</code> to be used during the decoding. 37 * It may be set to <code>null</code> in order to perform default 38 * decoding, or equivalently may be omitted. 39 * 40 * <p> The documentation for <code>PNGDecodeParam</code> describes the 41 * possible output formats of PNG images after decoding. 42 * 43 * <p><b> The classes in the <code>com.lightcrafts.media.jai.codec</code> 44 * package are not a committed part of the JAI API. Future releases 45 * of JAI will make use of new classes in their place. This 46 * class will change accordingly.</b> 47 * 48 * <p><table border=1> 49 * <caption>Resource List</caption> 50 * <tr><th>Name</th> <th>Value</th></tr> 51 * <tr><td>GlobalName</td> <td>PNG</td></tr> 52 * <tr><td>LocalName</td> <td>PNG</td></tr> 53 * <tr><td>Vendor</td> <td>com.lightcrafts.media.jai</td></tr> 54 * <tr><td>Description</td> <td>Reads an image from a PNG stream.</td></tr> 55 * <tr><td>DocURL</td> <td>http://java.sun.com/products/java-media/jai/forDevelopers/jai-apidocs/javax/media/jai/operator/PNGDescriptor.html</td></tr> 56 * <tr><td>Version</td> <td>1.0</td></tr> 57 * <tr><td>arg0Desc</td> <td>The SeekableStream to read from.</td></tr> 58 * <tr><td>arg1Desc</td> <td>The PNGDecodeParam to use.</td></tr> 59 * </table></p> 60 * 61 * <p><table border=1> 62 * <caption>Parameter List</caption> 63 * <tr><th>Name</th> <th>Class Type</th> 64 * <th>Default Value</th></tr> 65 * <tr><td>stream</td> <td>com.lightcrafts.media.jai.codec.SeekableStream</td> 66 * <td>NO_PARAMETER_DEFAULT</td> 67 * <tr><td>param</td> <td>com.lightcrafts.media.jai.codec.PNGDecodeParam</td> 68 * <td>null</td> 69 * </table></p> 70 * 71 * <p><table border=1> 72 * <caption>Properties</caption> 73 * <tr><th>Property Name</th> <th>Class</th> <th>Comment</th></tr> 74 * 75 * <tr><td>file_type</td> <td>String</td> 76 * <td>"PNG v. 1.0"</td> </tr> 77 * <tr><td>background_color</td> <td>java.awt.Color</td> 78 * <td>The suggested background color.</td> </tr> 79 * <tr><td>significant_bits</td> <td>int[]</td> 80 * <td>The number of significant bits stored in the file.</td> </tr> 81 * <tr><td>bit_depth</td> <td>Integer</td> 82 * <td>The bit depth of the file</td> </tr> 83 * <tr><td>color_type</td> <td>String</td> 84 * <td>One of "Grayscale", "Truecolor", "Index", 85 * "Grayscale with alpha" or "Truecolor with alpha"</td> </tr> 86 * <tr><td>interlace_method</td> <td>String</td> 87 * <td>"None" or "Adam7"</td> </tr> 88 * <tr><td>white_point_x</td> <td>Float</td> 89 * <td>The CIE X coordinate of the white point, if known.</td> </tr> 90 * <tr><td>white_point_y</td> <td>Float</td> 91 * <td>The CIE Y coordinate of the white point, if known.</td> </tr> 92 * <tr><td>red_x</td> <td>Float</td> 93 * <td>The CIE X coordinate of the red primary, if known.</td> </tr> 94 * <tr><td>red_y</td> <td>Float</td> 95 * <td>The CIE Y coordinate of the red primary, if known.</td> </tr> 96 * <tr><td>green_x</td> <td>Float</td> 97 * <td>The CIE X coordinate of the green primary, if known.</td> </tr> 98 * <tr><td>green_y</td> <td>Float</td> 99 * <td>The CIE Y coordinate of the green primary, if known.</td> </tr> 100 * <tr><td>blue_x</td> <td>Float</td> 101 * <td>The CIE X coordinate of the blue primary, if known.</td> </tr> 102 * <tr><td>blue_y</td> <td>Float</td> 103 * <td>The CIE Y coordinate of the blue primary, if known.</td> </tr> 104 * <tr><td>gamma</td> <td>Float</td> 105 * <td>The image gamma, if known.</td> </tr> 106 * <tr><td>x_pixels_per_unit</td> <td>Integer</td> 107 * <td>The number of horizontal pixels per unit.</td> </tr> 108 * <tr><td>y_pixels_per_unit</td> <td>Integer</td> 109 * <td>The number of vertical pixels per unit.</td> </tr> 110 * <tr><td>pixel_aspect_ratio</td> <td>Float</td> 111 * <td>The width of a pixel divided by its height.</td> </tr> 112 * <tr><td>pixel_units</td> <td>String</td> 113 * <td>"Meters" or <code>null</code></td> </tr> 114 * <tr><td>timestamp</td> <td>java.util.Date</td> 115 * <td>The creation or modification time of the image.</td> </tr> 116 * <tr><td>text:*</td> <td>String</td> 117 * <td>The value of a tEXt chunk.</td> </tr> 118 * <tr><td>ztext:*</td> <td>String</td> 119 * <td>The value of a zTXt chunk (not yet implemented).</td> </tr> 120 * <tr><td>chunk:*</td> <td>byte[]</td> 121 * <td>The contents of any non-standard chunks.</td> </tr> 122 * </table></p> 123 * 124 * @see com.lightcrafts.media.jai.codec.PNGDecodeParam 125 * @see com.lightcrafts.media.jai.codec.SeekableStream 126 * @see com.lightcrafts.mediax.jai.OperationDescriptor 127 */ 128 public class PNGDescriptor extends OperationDescriptorImpl { 129 130 /** 131 * The resource strings that provide the general documentation and 132 * specify the parameter list for the "PNG" operation. 133 */ 134 private static final String[][] resources = { 135 {"GlobalName", "PNG"}, 136 {"LocalName", "PNG"}, 137 {"Vendor", "com.lightcrafts.media.jai"}, 138 {"Description", JaiI18N.getString("PNGDescriptor0")}, 139 {"DocURL", "http://java.sun.com/products/java-media/jai/forDevelopers/jai-apidocs/javax/media/jai/operator/PNGDescriptor.html"}, 140 {"Version", JaiI18N.getString("DescriptorVersion")}, 141 {"arg0Desc", JaiI18N.getString("PNGDescriptor1")}, 142 {"arg1Desc", JaiI18N.getString("PNGDescriptor2")}, 143 }; 144 145 /** The parameter names for the "PNG" operation. */ 146 private static final String[] paramNames = { 147 "stream", "param" 148 }; 149 150 /** The parameter class types for the "PNG" operation. */ 151 private static final Class[] paramClasses = { 152 com.lightcrafts.media.jai.codec.SeekableStream.class, 153 com.lightcrafts.media.jai.codec.PNGDecodeParam.class 154 }; 155 156 /** The parameter default values for the "PNG" operation. */ 157 private static final Object[] paramDefaults = { 158 NO_PARAMETER_DEFAULT, null 159 }; 160 161 /** Constructor. */ PNGDescriptor()162 public PNGDescriptor() { 163 super(resources, 0, paramClasses, paramNames, paramDefaults); 164 } 165 166 167 /** 168 * Reads a standard JFIF (PNG) file. 169 * 170 * <p>Creates a <code>ParameterBlockJAI</code> from all 171 * supplied arguments except <code>hints</code> and invokes 172 * {@link JAI#create(String,ParameterBlock,RenderingHints)}. 173 * 174 * @see JAI 175 * @see ParameterBlockJAI 176 * @see RenderedOp 177 * 178 * @param stream The SeekableStream to read from. 179 * @param param The PNGDecodeParam to use. 180 * May be <code>null</code>. 181 * @param hints The <code>RenderingHints</code> to use. 182 * May be <code>null</code>. 183 * @return The <code>RenderedOp</code> destination. 184 * @throws IllegalArgumentException if <code>stream</code> is <code>null</code>. 185 */ create(SeekableStream stream, PNGDecodeParam param, RenderingHints hints)186 public static RenderedOp create(SeekableStream stream, 187 PNGDecodeParam param, 188 RenderingHints hints) { 189 ParameterBlockJAI pb = 190 new ParameterBlockJAI("PNG", 191 RenderedRegistryMode.MODE_NAME); 192 193 pb.setParameter("stream", stream); 194 pb.setParameter("param", param); 195 196 return JAI.create("PNG", pb, hints); 197 } 198 } 199