001: /*
002: * $RCSfile: ImageFunctionDescriptor.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 com.sun.media.jai.util.PropertyGeneratorImpl;
015: import java.awt.RenderingHints;
016: import java.awt.geom.AffineTransform;
017: import java.awt.image.RenderedImage;
018: import java.awt.image.renderable.ParameterBlock;
019: import javax.media.jai.ImageFunction;
020: import javax.media.jai.JAI;
021: import javax.media.jai.OperationDescriptorImpl;
022: import javax.media.jai.ParameterBlockJAI;
023: import javax.media.jai.PropertyGenerator;
024: import javax.media.jai.RenderableOp;
025: import javax.media.jai.RenderedOp;
026: import javax.media.jai.registry.RenderedRegistryMode;
027:
028: /**
029: * This property generator computes the properties for the operation
030: * "ImageFunction" dynamically.
031: */
032: class ImageFunctionPropertyGenerator extends PropertyGeneratorImpl {
033:
034: /** Constructor. */
035: public ImageFunctionPropertyGenerator() {
036: super (new String[] { "COMPLEX" },
037: new Class[] { Boolean.class }, new Class[] {
038: RenderedOp.class, RenderableOp.class });
039: }
040:
041: /**
042: * Returns the specified property.
043: *
044: * @param name Property name.
045: * @param opNode Operation node.
046: */
047: public Object getProperty(String name, Object opNode) {
048: validate(name, opNode);
049:
050: if (name.equalsIgnoreCase("complex")) {
051: if (opNode instanceof RenderedOp) {
052: RenderedOp op = (RenderedOp) opNode;
053: ParameterBlock pb = op.getParameterBlock();
054: ImageFunction imFunc = (ImageFunction) pb
055: .getObjectParameter(0);
056: return imFunc.isComplex() ? Boolean.TRUE
057: : Boolean.FALSE;
058: } else if (opNode instanceof RenderableOp) {
059: RenderableOp op = (RenderableOp) opNode;
060: ParameterBlock pb = op.getParameterBlock();
061: ImageFunction imFunc = (ImageFunction) pb
062: .getObjectParameter(0);
063: return imFunc.isComplex() ? Boolean.TRUE
064: : Boolean.FALSE;
065: }
066: }
067:
068: return java.awt.Image.UndefinedProperty;
069: }
070: }
071:
072: /**
073: * An <code>OperationDescriptor</code> describing the "ImageFunction"
074: * operation.
075: *
076: * <p> The "ImageFunction" operation generates an image on the basis of
077: * a functional description provided by an object which is an instance of
078: * a class which implements the <code>ImageFunction</code> interface.
079: * The <i>(x,y)</i> coordinates passed to the <code>getElements()</code>
080: * methods of the <code>ImageFunction</code> object are derived by applying
081: * an optional translation and scaling to the X- and Y-coordinates of the
082: * image. The image X- and Y-coordinates as usual depend on the values of
083: * the minimum X- and Y- coordinates of the image which need not be zero.
084: * Specifically, the function coordinates passed to <code>getElements()</code>
085: * are calculated from the image coordinates as:
086: *
087: * <pre>
088: * functionX = xScale*(imageX - xTrans);
089: * functionY = yScale*(imageY - yTrans);
090: * </pre>
091: *
092: * This implies that the pixel at coordinates <i>(xTrans,yTrans)</i> will
093: * be assigned the value of the function at <i>(0,0)</i>.
094: *
095: * <p> The number of bands in the destination image must be equal to the
096: * value returned by the <code>getNumElements()</code> method of the
097: * <code>ImageFunction</code> unless the <code>isComplex()</code> method
098: * of the <code>ImageFunction</code> returns <code>true</code> in which
099: * case it will be twice that. The data type of the destination image is
100: * determined by the <code>SampleModel</code> specified by an
101: * <code>ImageLayout</code> object provided via a hint. If no layout hint
102: * is provided, the data type will default to single-precision floating point.
103: * The double precision floating point form of the <code>getElements()</code>
104: * method of the <code>ImageFunction</code> will be invoked if and only if
105: * the data type is specified to be <code>double</code>. For all other data
106: * types the single precision form of <code>getElements()</code> will be
107: * invoked and the destination sample values will be clamped to the data type
108: * of the image.
109: *
110: * <p> The width and height of the image are provided explicitely as
111: * parameters. These values override the width and height specified via
112: * an <code>ImageLayout</code> if such is provided.
113: *
114: * <p>"ImageFunction" defines a PropertyGenerator that sets the "COMPLEX"
115: * property of the image to <code>java.lang.Boolean.TRUE</code> or
116: * <code>java.lang.Boolean.FALSE</code> depending on whether the
117: * <code>isComplex()</code> method of the <code>ImageFunction</code>
118: * parameter returns <code>true</code> or <code>false</code>, respectively.
119: * This property may be retrieved by calling the <code>getProperty()</code>
120: * method with "COMPLEX" as the property name.
121: *
122: * <p><table border=1>
123: * <caption>Resource List</caption>
124: * <tr><th>Name</th> <th>Value</th></tr>
125: * <tr><td>GlobalName</td> <td>ImageFunction</td></tr>
126: * <tr><td>LocalName</td> <td>ImageFunction</td></tr>
127: * <tr><td>Vendor</td> <td>com.sun.media.jai</td></tr>
128: * <tr><td>Description</td> <td>Generates an image from a functional description.</td></tr>
129: * <tr><td>DocURL</td> <td>http://java.sun.com/products/java-media/jai/forDevelopers/jai-apidocs/javax/media/jai/operator/ImageFunctionDescriptor.html</td></tr>
130: * <tr><td>Version</td> <td>1.0</td></tr>
131: * <tr><td>arg0Desc</td> <td>The functional description.</td></tr>
132: * <tr><td>arg1Desc</td> <td>The image width.</td></tr>
133: * <tr><td>arg2Desc</td> <td>The image height.</td></tr>
134: * <tr><td>arg3Desc</td> <td>The X scale factor.</td></tr>
135: * <tr><td>arg4Desc</td> <td>The Y scale factor.</td></tr>
136: * <tr><td>arg5Desc</td> <td>The X translation.</td></tr>
137: * <tr><td>arg6Desc</td> <td>The Y translation.</td></tr>
138: * </table></p>
139: *
140: * <p><table border=1>
141: * <caption>Parameter List</caption>
142: * <tr><th>Name</th> <th>Class Type</th>
143: * <th>Default Value</th></tr>
144: * <tr><td>function</td> <td>javax.media.jai.ImageFunction</td>
145: * <td>NO_PARAMETER_DEFAULT</td>
146: * <tr><td>width</td> <td>java.lang.Integer</td>
147: * <td>NO_PARAMETER_DEFAULT</td>
148: * <tr><td>height</td> <td>java.lang.Integer</td>
149: * <td>NO_PARAMETER_DEFAULT</td>
150: * <tr><td>xScale</td> <td>java.lang.Float</td>
151: * <td>1.0F</td>
152: * <tr><td>yScale</td> <td>java.lang.Float</td>
153: * <td>1.0F</td>
154: * <tr><td>xTrans</td> <td>java.lang.Float</td>
155: * <td>0.0F</td>
156: * <tr><td>yTrans</td> <td>java.lang.Float</td>
157: * <td>0.0F</td>
158: * </table></p>
159: *
160: * @see java.awt.geom.AffineTransform
161: * @see javax.media.jai.OperationDescriptor
162: * @see javax.media.jai.ImageFunction
163: */
164: public class ImageFunctionDescriptor extends OperationDescriptorImpl {
165:
166: /**
167: * The resource strings that provide the general documentation
168: * and specify the parameter list for this operation.
169: */
170: private static final String[][] resources = {
171: { "GlobalName", "ImageFunction" },
172: { "LocalName", "ImageFunction" },
173: { "Vendor", "com.sun.media.jai" },
174: { "Description",
175: JaiI18N.getString("ImageFunctionDescriptor0") },
176: {
177: "DocURL",
178: "http://java.sun.com/products/java-media/jai/forDevelopers/jai-apidocs/javax/media/jai/operator/ImageFunctionDescriptor.html" },
179: { "Version", JaiI18N.getString("DescriptorVersion") },
180: { "arg0Desc", JaiI18N.getString("ImageFunctionDescriptor1") },
181: { "arg1Desc", JaiI18N.getString("ImageFunctionDescriptor2") },
182: { "arg2Desc", JaiI18N.getString("ImageFunctionDescriptor3") },
183: { "arg3Desc", JaiI18N.getString("ImageFunctionDescriptor4") },
184: { "arg4Desc", JaiI18N.getString("ImageFunctionDescriptor5") },
185: { "arg5Desc", JaiI18N.getString("ImageFunctionDescriptor6") },
186: { "arg6Desc", JaiI18N.getString("ImageFunctionDescriptor7") } };
187:
188: /** The parameter class list for this operation. */
189: private static final Class[] paramClasses = {
190: javax.media.jai.ImageFunction.class,
191: java.lang.Integer.class, java.lang.Integer.class,
192: java.lang.Float.class, java.lang.Float.class,
193: java.lang.Float.class, java.lang.Float.class };
194:
195: /** The parameter name list for this operation. */
196: private static final String[] paramNames = { "function", "width",
197: "height", "xScale", "yScale", "xTrans", "yTrans" };
198:
199: /** The parameter default value list for this operation. */
200: private static final Object[] paramDefaults = {
201: NO_PARAMETER_DEFAULT, NO_PARAMETER_DEFAULT,
202: NO_PARAMETER_DEFAULT, new Float(1.0F), new Float(1.0F), // unity scale
203: new Float(0.0F), new Float(0.0F) // zero translation
204: };
205:
206: /** Constructor. */
207: public ImageFunctionDescriptor() {
208: super (resources, 0, paramClasses, paramNames, paramDefaults);
209: }
210:
211: /**
212: * Returns an array of <code>PropertyGenerators</code> implementing
213: * property inheritance for the "ImageFunction" operation.
214: *
215: * @return An array of property generators.
216: */
217: public PropertyGenerator[] getPropertyGenerators() {
218: PropertyGenerator[] pg = new PropertyGenerator[1];
219: pg[0] = new ImageFunctionPropertyGenerator();
220: return pg;
221: }
222:
223: /**
224: * Generates an image from a functional description.
225: *
226: * <p>Creates a <code>ParameterBlockJAI</code> from all
227: * supplied arguments except <code>hints</code> and invokes
228: * {@link JAI#create(String,ParameterBlock,RenderingHints)}.
229: *
230: * @see JAI
231: * @see ParameterBlockJAI
232: * @see RenderedOp
233: *
234: * @param function The functional description.
235: * @param width The image width.
236: * @param height The image height.
237: * @param xScale The X scale factor.
238: * May be <code>null</code>.
239: * @param yScale The Y scale factor.
240: * May be <code>null</code>.
241: * @param xTrans The X translation.
242: * May be <code>null</code>.
243: * @param yTrans The Y translation.
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>function</code> is <code>null</code>.
249: * @throws IllegalArgumentException if <code>width</code> is <code>null</code>.
250: * @throws IllegalArgumentException if <code>height</code> is <code>null</code>.
251: */
252: public static RenderedOp create(ImageFunction function,
253: Integer width, Integer height, Float xScale, Float yScale,
254: Float xTrans, Float yTrans, RenderingHints hints) {
255: ParameterBlockJAI pb = new ParameterBlockJAI("ImageFunction",
256: RenderedRegistryMode.MODE_NAME);
257:
258: pb.setParameter("function", function);
259: pb.setParameter("width", width);
260: pb.setParameter("height", height);
261: pb.setParameter("xScale", xScale);
262: pb.setParameter("yScale", yScale);
263: pb.setParameter("xTrans", xTrans);
264: pb.setParameter("yTrans", yTrans);
265:
266: return JAI.create("ImageFunction", pb, hints);
267: }
268: }
|