001: /*
002: * $RCSfile: PolarToComplexDescriptor.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:43 $
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 "PolarToComplex"
029: * operation.
030: *
031: * <p> The "PolarToComplex" operation creates an image with complex-valued
032: * pixels from two images the respective pixel values of which represent the
033: * magnitude (modulus) and phase of the corresponding complex pixel in the
034: * destination image. The source images should have the same number of bands.
035: * The first source image contains the magnitude values and the second source
036: * image the phase values. The destination will have twice as many bands with
037: * the even-indexed bands (0, 2, ...) representing the real and the
038: * odd-indexed bands (1, 3, ...) the imaginary parts of each pixel. The
039: * pixel values of the destination image are defined for a given complex
040: * sample by the pseudocode:
041: *
042: * <pre>
043: * dst[x][y][2*b] = src0[x][y][b]*Math.cos(src1[x][y][b])
044: * dst[x][y][2*b+1] = src0[x][y][b]*Math.sin(src1[x][y][b])
045: * </pre>
046: *
047: * where the index <i>b</i> varies from zero to one less than the number
048: * of bands in the source images.
049: *
050: * <p> For phase images with integral data type, it is assumed that the actual
051: * phase angle is scaled from the range [-PI, PI] to the range [0, MAX_VALUE]
052: * where MAX_VALUE is the maximum value of the data type in question.
053: *
054: * <p>"PolarToComplex" defines a PropertyGenerator that sets the "COMPLEX"
055: * property of the image to <code>java.lang.Boolean.TRUE</code>, which may
056: * be retrieved by calling the <code>getProperty()</code> method with
057: * "COMPLEX" as the property name.
058: *
059: * <p><table border=1>
060: * <caption>Resource List</caption>
061: * <tr><th>Name</th> <th>Value</th></tr>
062: * <tr><td>GlobalName</td> <td>PolarToComplex</td></tr>
063: * <tr><td>LocalName</td> <td>PolarToComplex</td></tr>
064: * <tr><td>Vendor</td> <td>com.sun.media.jai</td></tr>
065: * <tr><td>Description</td> <td>Computes a complex image from a magnitude and a phase image.</td></tr>
066: * <tr><td>DocURL</td> <td>http://java.sun.com/products/java-media/jai/forDevelopers/jai-apidocs/javax/media/jai/operator/PolarToComplexDescriptor.html</td></tr>
067: * <tr><td>Version</td> <td>1.0</td></tr>
068: * </table></p>
069: *
070: * <p> No parameters are needed for the "PolarToComplex" operation.
071: *
072: * @see javax.media.jai.OperationDescriptor
073: * @see javax.media.jai.operator.PhaseDescriptor
074: */
075: public class PolarToComplexDescriptor extends OperationDescriptorImpl {
076:
077: /**
078: * The resource strings that provide the general documentation
079: * and specify the parameter list for this operation.
080: */
081: private static final String[][] resources = {
082: { "GlobalName", "PolarToComplex" },
083: { "LocalName", "PolarToComplex" },
084: { "Vendor", "com.sun.media.jai" },
085: { "Description",
086: JaiI18N.getString("PolarToComplexDescriptor0") },
087: {
088: "DocURL",
089: "http://java.sun.com/products/java-media/jai/forDevelopers/jai-apidocs/javax/media/jai/operator/PolarToComplexDescriptor.html" },
090: { "Version", JaiI18N.getString("DescriptorVersion") } };
091:
092: private static final String[] supportedModes = { "rendered",
093: "renderable" };
094:
095: /** Constructor. */
096: public PolarToComplexDescriptor() {
097: super (resources, supportedModes, 2, null, null, null, null);
098: }
099:
100: /**
101: * Validates the input sources.
102: *
103: * <p> In addition to the standard checks performed by the
104: * superclass method, this method checks that the source images
105: * have the same number of bands.
106: */
107: protected boolean validateSources(String modeName,
108: ParameterBlock args, StringBuffer msg) {
109: if (!super .validateSources(modeName, args, msg)) {
110: return false;
111: }
112:
113: if (!modeName.equalsIgnoreCase("rendered"))
114: return true;
115:
116: RenderedImage src1 = args.getRenderedSource(0);
117: RenderedImage src2 = args.getRenderedSource(1);
118:
119: if (src1.getSampleModel().getNumBands() != src2
120: .getSampleModel().getNumBands()) {
121: msg.append(getName() + " "
122: + JaiI18N.getString("PolarToComplexDescriptor1"));
123: return false;
124: }
125:
126: return true;
127: }
128:
129: /**
130: * Returns an array of <code>PropertyGenerators</code> implementing
131: * property inheritance for the "Conjugate" operation.
132: *
133: * @return An array of property generators.
134: */
135: public PropertyGenerator[] getPropertyGenerators(String modeName) {
136: PropertyGenerator[] pg = new PropertyGenerator[1];
137: pg[0] = new ComplexPropertyGenerator();
138: return pg;
139: }
140:
141: /**
142: * Computes a complex image from a magnitude and a phase image.
143: *
144: * <p>Creates a <code>ParameterBlockJAI</code> from all
145: * supplied arguments except <code>hints</code> and invokes
146: * {@link JAI#create(String,ParameterBlock,RenderingHints)}.
147: *
148: * @see JAI
149: * @see ParameterBlockJAI
150: * @see RenderedOp
151: *
152: * @param source0 <code>RenderedImage</code> source 0.
153: * @param source1 <code>RenderedImage</code> source 1.
154: * @param hints The <code>RenderingHints</code> to use.
155: * May be <code>null</code>.
156: * @return The <code>RenderedOp</code> destination.
157: * @throws IllegalArgumentException if <code>source0</code> is <code>null</code>.
158: * @throws IllegalArgumentException if <code>source1</code> is <code>null</code>.
159: */
160: public static RenderedOp create(RenderedImage source0,
161: RenderedImage source1, RenderingHints hints) {
162: ParameterBlockJAI pb = new ParameterBlockJAI("PolarToComplex",
163: RenderedRegistryMode.MODE_NAME);
164:
165: pb.setSource("source0", source0);
166: pb.setSource("source1", source1);
167:
168: return JAI.create("PolarToComplex", pb, hints);
169: }
170:
171: /**
172: * Computes a complex image from a magnitude and a phase image.
173: *
174: * <p>Creates a <code>ParameterBlockJAI</code> from all
175: * supplied arguments except <code>hints</code> and invokes
176: * {@link JAI#createRenderable(String,ParameterBlock,RenderingHints)}.
177: *
178: * @see JAI
179: * @see ParameterBlockJAI
180: * @see RenderableOp
181: *
182: * @param source0 <code>RenderableImage</code> source 0.
183: * @param source1 <code>RenderableImage</code> source 1.
184: * @param hints The <code>RenderingHints</code> to use.
185: * May be <code>null</code>.
186: * @return The <code>RenderableOp</code> destination.
187: * @throws IllegalArgumentException if <code>source0</code> is <code>null</code>.
188: * @throws IllegalArgumentException if <code>source1</code> is <code>null</code>.
189: */
190: public static RenderableOp createRenderable(
191: RenderableImage source0, RenderableImage source1,
192: RenderingHints hints) {
193: ParameterBlockJAI pb = new ParameterBlockJAI("PolarToComplex",
194: RenderableRegistryMode.MODE_NAME);
195:
196: pb.setSource("source0", source0);
197: pb.setSource("source1", source1);
198:
199: return JAI.createRenderable("PolarToComplex", pb, hints);
200: }
201: }
|