001: /*
002: * $RCSfile: MultiplyComplexDescriptor.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:40 $
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.awt.image.renderable.RenderableImage;
018: import javax.media.jai.JAI;
019: import javax.media.jai.OperationDescriptorImpl;
020: import javax.media.jai.ParameterBlockJAI;
021: import javax.media.jai.PropertyGenerator;
022: import javax.media.jai.RenderableOp;
023: import javax.media.jai.RenderedOp;
024: import javax.media.jai.registry.RenderableRegistryMode;
025: import javax.media.jai.registry.RenderedRegistryMode;
026:
027: /**
028: * An <code>OperationDescriptor</code> describing the "MultiplyComplex"
029: * operation.
030: *
031: * <p> The "MultiplyComplex" operation multiplies two images representing
032: * complex data. The source images must each contain an even number of bands
033: * with the even-indexed bands (0, 2, ...) representing the real and the
034: * odd-indexed bands (1, 3, ...) the imaginary parts of each pixel. The
035: * destination image similarly contains an even number of bands with the
036: * same interpretation and with contents defined by:
037: *
038: * <pre>
039: * a = src0[x][y][2*k];
040: * b = src0[x][y][2*k+1];
041: * c = src1[x][y][2*k];
042: * d = src1[x][y][2*k+1];
043: *
044: * dst[x][y][2*k] = a*c - b*d;
045: * dst[x][y][2*k+1] = a*d + b*c;
046: * </pre>
047: *
048: * where 0 <= <i>k</i> < numBands/2.
049: *
050: * By default, the number of bands of the destination image is the
051: * the minimum of the number of bands of the two sources, and the
052: * data type is the biggest data type of the sources.
053: * However, the number of destination bands can be specified to be
054: * M = 2*L through an <code>ImageLayout</code> hint, when
055: * one source image has 2 bands and the other has N = 2*K bands
056: * where K > 1, with a natural restriction 1 <= L <= K.
057: * In such a special case each of the first L complex components
058: * in the N-band source will be multiplied by the single complex
059: * component in the 1-band source.
060: *
061: * <p> If the result of the operation underflows/overflows the
062: * minimum/maximum value supported by the destination data type, then it will
063: * be clamped to the minimum/maximum value respectively.
064: *
065: * <p>"MultiplyComplex" defines a PropertyGenerator that sets the "COMPLEX"
066: * property of the image to <code>java.lang.Boolean.TRUE</code>, which may
067: * be retrieved by calling the <code>getProperty()</code> method with
068: * "COMPLEX" as the property name.
069: *
070: * <p><table border=1>
071: * <caption>Resource List</caption>
072: * <tr><th>Name</th> <th>Value</th></tr>
073: * <tr><td>GlobalName</td> <td>MultiplyComplex</td></tr>
074: * <tr><td>LocalName</td> <td>MultiplyComplex</td></tr>
075: * <tr><td>Vendor</td> <td>com.sun.media.jai</td></tr>
076: * <tr><td>Description</td> <td>Computes the complex product of two images.</td></tr>
077: * <tr><td>DocURL</td> <td>http://java.sun.com/products/java-media/jai/forDevelopers/jai-apidocs/javax/media/jai/operator/MultiplyComplexDescriptor.html</td></tr>
078: * <tr><td>Version</td> <td>1.0</td></tr>
079: * </table></p>
080: *
081: * <p> No parameters are needed for the "MultiplyComplex" operation.
082: *
083: * @see javax.media.jai.OperationDescriptor
084: */
085: public class MultiplyComplexDescriptor extends OperationDescriptorImpl {
086:
087: /**
088: * The resource strings that provide the general documentation
089: * and specify the parameter list for this operation.
090: */
091: private static final String[][] resources = {
092: { "GlobalName", "MultiplyComplex" },
093: { "LocalName", "MultiplyComplex" },
094: { "Vendor", "com.sun.media.jai" },
095: { "Description",
096: JaiI18N.getString("MultiplyComplexDescriptor0") },
097: {
098: "DocURL",
099: "http://java.sun.com/products/java-media/jai/forDevelopers/jai-apidocs/javax/media/jai/operator/MultiplyComplexDescriptor.html" },
100: { "Version", JaiI18N.getString("DescriptorVersion") } };
101:
102: private static final String[] supportedModes = { "rendered",
103: "renderable" };
104:
105: /** Constructor. */
106: public MultiplyComplexDescriptor() {
107: super (resources, supportedModes, 2, null, null, null, null);
108: }
109:
110: /**
111: * Validates the input sources.
112: *
113: * <p> In addition to the standard checks performed by the
114: * superclass method, this method checks that the source images
115: * each have an even number of bands.
116: */
117: protected boolean validateSources(String modeName,
118: ParameterBlock args, StringBuffer msg) {
119: if (!super .validateSources(modeName, args, msg)) {
120: return false;
121: }
122:
123: if (!modeName.equalsIgnoreCase("rendered"))
124: return true;
125:
126: RenderedImage src1 = args.getRenderedSource(0);
127: RenderedImage src2 = args.getRenderedSource(1);
128:
129: if (src1.getSampleModel().getNumBands() % 2 != 0
130: || src2.getSampleModel().getNumBands() % 2 != 0) {
131: msg.append(getName() + " "
132: + JaiI18N.getString("MultiplyComplexDescriptor1"));
133: return false;
134: }
135:
136: return true;
137: }
138:
139: /**
140: * Returns an array of <code>PropertyGenerators</code> implementing
141: * property inheritance for the "MultiplyComplex" operation.
142: *
143: * @return An array of property generators.
144: */
145: public PropertyGenerator[] getPropertyGenerators(String modeName) {
146: PropertyGenerator[] pg = new PropertyGenerator[1];
147: pg[0] = new ComplexPropertyGenerator();
148: return pg;
149: }
150:
151: /**
152: * Computes the complex product of two images.
153: *
154: * <p>Creates a <code>ParameterBlockJAI</code> from all
155: * supplied arguments except <code>hints</code> and invokes
156: * {@link JAI#create(String,ParameterBlock,RenderingHints)}.
157: *
158: * @see JAI
159: * @see ParameterBlockJAI
160: * @see RenderedOp
161: *
162: * @param source0 <code>RenderedImage</code> source 0.
163: * @param source1 <code>RenderedImage</code> source 1.
164: * @param hints The <code>RenderingHints</code> to use.
165: * May be <code>null</code>.
166: * @return The <code>RenderedOp</code> destination.
167: * @throws IllegalArgumentException if <code>source0</code> is <code>null</code>.
168: * @throws IllegalArgumentException if <code>source1</code> is <code>null</code>.
169: */
170: public static RenderedOp create(RenderedImage source0,
171: RenderedImage source1, RenderingHints hints) {
172: ParameterBlockJAI pb = new ParameterBlockJAI("MultiplyComplex",
173: RenderedRegistryMode.MODE_NAME);
174:
175: pb.setSource("source0", source0);
176: pb.setSource("source1", source1);
177:
178: return JAI.create("MultiplyComplex", pb, hints);
179: }
180:
181: /**
182: * Computes the complex product of two images.
183: *
184: * <p>Creates a <code>ParameterBlockJAI</code> from all
185: * supplied arguments except <code>hints</code> and invokes
186: * {@link JAI#createRenderable(String,ParameterBlock,RenderingHints)}.
187: *
188: * @see JAI
189: * @see ParameterBlockJAI
190: * @see RenderableOp
191: *
192: * @param source0 <code>RenderableImage</code> source 0.
193: * @param source1 <code>RenderableImage</code> source 1.
194: * @param hints The <code>RenderingHints</code> to use.
195: * May be <code>null</code>.
196: * @return The <code>RenderableOp</code> destination.
197: * @throws IllegalArgumentException if <code>source0</code> is <code>null</code>.
198: * @throws IllegalArgumentException if <code>source1</code> is <code>null</code>.
199: */
200: public static RenderableOp createRenderable(
201: RenderableImage source0, RenderableImage source1,
202: RenderingHints hints) {
203: ParameterBlockJAI pb = new ParameterBlockJAI("MultiplyComplex",
204: RenderableRegistryMode.MODE_NAME);
205:
206: pb.setSource("source0", source0);
207: pb.setSource("source1", source1);
208:
209: return JAI.createRenderable("MultiplyComplex", pb, hints);
210: }
211: }
|