001: /*
002: * $RCSfile: IIPResolutionDescriptor.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:37 $
010: * $State: Exp $
011: */
012: package javax.media.jai.operator;
013:
014: import java.awt.RenderingHints;
015: import java.awt.image.RenderedImage;
016: import java.awt.image.renderable.ParameterBlock;
017: import java.net.URL;
018: import javax.media.jai.JAI;
019: import javax.media.jai.OperationDescriptorImpl;
020: import javax.media.jai.ParameterBlockJAI;
021: import javax.media.jai.RenderedOp;
022: import javax.media.jai.registry.RenderedRegistryMode;
023:
024: /**
025: * An <code>OperationDescriptor</code> describing the "IIPResolution"
026: * operation.
027: *
028: * <p> This operation provides client-side support of the Internet Imaging
029: * Protocol (IIP) in the rendered mode. It is resolution-specific. It
030: * requests from the IIP server an image at a particular resolution level,
031: * and creates a <code>java.awt.image.RenderedImage</code> based on the
032: * data received from the server. Once the <code>RenderedImage</code>
033: * is created, the resolution level cannot be changed.
034: *
035: * <p> The layout of the created <code>RenderedImage</code> is set as
036: * follows:
037: * <ul>
038: * <li> <code>minX</code>, <code>minY</code>, <code>tileGridXOffset</code>,
039: * and <code>tileGridYOffset</code> are set to 0;
040: * <li> <code>width</code> and <code>height</code> are determined based
041: * on the specified resolution level;
042: * <li> <code>tileWidth</code> and <code>tileHeight</code> are set to 64;
043: * <li> <code>sampleModel</code> is of the type
044: * <code>java.awt.image.PixelInterleavedSampleModel</code> with byte
045: * data type and the appropriate number of bands;
046: * <li> <code>colorModel</code> is of the type
047: * <code>java.awt.image.ComponentColorModel</code>, with the
048: * <code>ColorSpace</code> set to sRGB, PhotoYCC, or Grayscale, depending
049: * on the color space of the remote image; if an alpha channel is
050: * present, it will be premultiplied.
051: * </ul>
052: *
053: * <p> The "URL" parameter specifies the URL of the IIP image as a
054: * <code>java.lang.String</code>. It must represent a valid URL, and
055: * include any required FIF or SDS commands. It cannot be <code>null</code>.
056: *
057: * <p> The "resolution" parameter specifies the resolution level of the
058: * requested IIP image from the server. The lowest resolution level is
059: * 0, with larger integers representing higher resolution levels. If the
060: * requested resolution level does not exist, the nearest resolution level
061: * is used. If this parameter is not specified, it is set to the default
062: * value <code>IIPResolutionDescriptor.MAX_RESOLUTION</code> which indicates
063: * the highest resolution level.
064: *
065: * <p> The "subImage" parameter indicates the sub-image to be used by the
066: * server to get the image at the specified resolution level. This parameter
067: * cannot be negative. If this parameter is not specified, it is set to
068: * the default value 0.
069: *
070: * <p> There is no source image associated with this operation.
071: *
072: * <p> If available from the IIP server certain properties may be set on the
073: * <code>RenderedImage</code>. The names of properties and the class types
074: * of their associated values are listed in the following table.
075: *
076: * <p><table border=1>
077: * <caption>Property List</caption>
078: * <tr><th>Property Name</th> <th>Property Value Class Type</th>
079: * <tr><td>affine-transform</td> <td>java.awt.geom.AffineTransform</td>
080: * <tr><td>app-name</td> <td>java.lang.String</td>
081: * <tr><td>aspect-ratio</td> <td>java.lang.Float</td>
082: * <tr><td>author</td> <td>java.lang.String</td>
083: * <tr><td>colorspace</td> <td>int[]</td>
084: * <tr><td>color-twist</td> <td>float[16]</td>
085: * <tr><td>comment</td> <td>java.lang.String</td>
086: * <tr><td>contrast-adjust</td> <td>java.lang.Float</td>
087: * <tr><td>copyright</td> <td>java.lang.String</td>
088: * <tr><td>create-dtm</td> <td>java.lang.String</td>
089: * <tr><td>edit-time</td> <td>java.lang.String</td>
090: * <tr><td>filtering-value</td> <td>java.lang.Float</td>
091: * <tr><td>iip</td> <td>java.lang.String</td>
092: * <tr><td>iip-server</td> <td>java.lang.String</td>
093: * <tr><td>keywords</td> <td>java.lang.String</td>
094: * <tr><td>last-author</td> <td>java.lang.String</td>
095: * <tr><td>last-printed</td> <td>java.lang.String</td>
096: * <tr><td>last-save-dtm</td> <td>java.lang.String</td>
097: * <tr><td>max-size</td> <td>int[2]</td>
098: * <tr><td>resolution-number</td> <td>java.lang.Integer</td>
099: * <tr><td>rev-number</td> <td>java.lang.String</td>
100: * <tr><td>roi-iip</td> <td>java.awt.geom.Rectangle2D.Float</td>
101: * <tr><td>subject</td> <td>java.lang.String</td>
102: * <tr><td>title</td> <td>java.lang.String</td>
103: * </table></p>
104: *
105: * For information on the significance of each of the above properties please
106: * refer to the IIP specification.
107: *
108: * <p><table border=1>
109: * <caption>Resource List</caption>
110: * <tr><th>Name</th> <th>Value</th></tr>
111: * <tr><td>GlobalName</td> <td>IIPResolution</td></tr>
112: * <tr><td>LocalName</td> <td>IIPResolution</td></tr>
113: * <tr><td>Vendor</td> <td>com.sun.media.jai</td></tr>
114: * <tr><td>Description</td> <td>Provides client-side support of the Internet
115: * Imaging Protocol in the rendered mode.</td></tr>
116: * <tr><td>DocURL</td> <td>http://java.sun.com/products/java-media/jai/forDevelopers/jai-apidocs/javax/media/jai/operator/IIPResolutionDescriptor.html</td></tr>
117: * <tr><td>Version</td> <td>1.0</td></tr>
118: * <tr><td>arg0Desc</td> <td>The URL of the IIP image.</td></tr>
119: * <tr><td>arg1Desc</td> <td>The resolution level to request.</td></tr>
120: * <tr><td>arg2Desc</td> <td>The sub-image to be used by the
121: * server.</td></tr>
122: * </table></p>
123: *
124: * <p><table border=1>
125: * <caption>Parameter List</caption>
126: * <tr><th>Name</th> <th>Class Type</th>
127: * <th>Default Value</th></tr>
128: * <tr><td>URL</td> <td>java.lang.String</td>
129: * <td>NO_PARAMETER_DEFAULT</td>
130: * <tr><td>resolution</td> <td>java.lang.Integer</td>
131: * <td>IIPResolutionDescriptor.MAX_RESOLUTION</td>
132: * <tr><td>subImage</td> <td>java.lang.Integer</td>
133: * <td>0</td>
134: * </table></p>
135: *
136: * @see <a href="http://www.digitalimaging.org">Digital Imaging Group</a>
137: * @see java.awt.image.RenderedImage
138: * @see IIPDescriptor
139: */
140: public class IIPResolutionDescriptor extends OperationDescriptorImpl {
141:
142: /** Convenience name for Max Resolution of an image on an IIP server. */
143: public static final Integer MAX_RESOLUTION = new Integer(
144: Integer.MAX_VALUE);
145:
146: /**
147: * The resource strings that provide the general documentation
148: * and specify the parameter list for this operation.
149: */
150: private static final String[][] resources = {
151: { "GlobalName", "IIPResolution" },
152: { "LocalName", "IIPResolution" },
153: { "Vendor", "com.sun.media.jai" },
154: { "Description",
155: JaiI18N.getString("IIPResolutionDescriptor0") },
156: {
157: "DocURL",
158: "http://java.sun.com/products/java-media/jai/forDevelopers/jai-apidocs/javax/media/jai/operator/IIPResolutionDescriptor.html" },
159: { "Version", JaiI18N.getString("DescriptorVersion") },
160: { "arg0Desc", JaiI18N.getString("IIPResolutionDescriptor1") },
161: { "arg1Desc", JaiI18N.getString("IIPResolutionDescriptor2") },
162: { "arg2Desc", JaiI18N.getString("IIPResolutionDescriptor3") } };
163:
164: /** The parameter class types for this operation. */
165: private static final Class[] paramClasses = {
166: java.lang.String.class, java.lang.Integer.class,
167: java.lang.Integer.class };
168:
169: /** The parameter names for this operation. */
170: private static final String[] paramNames = { "URL", "resolution",
171: "subImage" };
172:
173: /** The parameter default values for this operation. */
174: private static final Object[] paramDefaults = {
175: NO_PARAMETER_DEFAULT, MAX_RESOLUTION, new Integer(0) };
176:
177: /** Constructor. */
178: public IIPResolutionDescriptor() {
179: super (resources, 0, paramClasses, paramNames, paramDefaults);
180: }
181:
182: /**
183: * Returns the minimum legal value of a specified numeric parameter
184: * for this operation. If the supplied <code>index</code> does not
185: * correspond to a numeric parameter, this method returns
186: * <code>null</code>.
187: *
188: * @return An <code>Integer</code> of value 0 if <code>index</code>
189: * is 1 or 2, or <code>null</code> if <code>index</code> is 0.
190: *
191: * @throws ArrayIndexOutOfBoundsException if <code>index</code> is less
192: * than 0 or greater than 2.
193: */
194: public Number getParamMinValue(int index) {
195: if (index == 0) {
196: return null;
197: } else if (index == 1 || index == 2) {
198: return new Integer(0);
199: } else {
200: throw new ArrayIndexOutOfBoundsException();
201: }
202: }
203:
204: /**
205: * Validates the input parameters.
206: *
207: * <p> In addition to the standard checks performed by the
208: * superclass method, this method checks that the supplied URL
209: * string specifies a valid protocol.
210: */
211: protected boolean validateParameters(ParameterBlock args,
212: StringBuffer msg) {
213: if (!super .validateParameters(args, msg)) {
214: return false;
215: }
216:
217: try {
218: new URL((String) args.getObjectParameter(0));
219: } catch (Exception e) {
220: /* Use the same error message as IIPDescriptor. */
221: msg.append(getName() + " "
222: + JaiI18N.getString("IIPDescriptor15"));
223: return false;
224: }
225:
226: return true;
227: }
228:
229: /**
230: * Provides client support of the Internet Imaging Protocol in the rendered mode.
231: *
232: * <p>Creates a <code>ParameterBlockJAI</code> from all
233: * supplied arguments except <code>hints</code> and invokes
234: * {@link JAI#create(String,ParameterBlock,RenderingHints)}.
235: *
236: * @see JAI
237: * @see ParameterBlockJAI
238: * @see RenderedOp
239: *
240: * @param URL The URL of the IIP image.
241: * @param resolution The resolution level to request.
242: * May be <code>null</code>.
243: * @param subImage The sub-image to be used by the server.
244: * May be <code>null</code>.
245: * @param hints The <code>RenderingHints</code> to use.
246: * May be <code>null</code>.
247: * @return The <code>RenderedOp</code> destination.
248: * @throws IllegalArgumentException if <code>URL</code> is <code>null</code>.
249: */
250: public static RenderedOp create(String URL, Integer resolution,
251: Integer subImage, RenderingHints hints) {
252: ParameterBlockJAI pb = new ParameterBlockJAI("IIPResolution",
253: RenderedRegistryMode.MODE_NAME);
254:
255: pb.setParameter("URL", URL);
256: pb.setParameter("resolution", resolution);
257: pb.setParameter("subImage", subImage);
258:
259: return JAI.create("IIPResolution", pb, hints);
260: }
261: }
|