001: /*
002: * $RCSfile: PhaseDescriptor.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:42 $
010: * $State: Exp $
011: */
012: package javax.media.jai.operator;
013:
014: import java.awt.RenderingHints;
015: import java.awt.image.DataBuffer;
016: import java.awt.image.RenderedImage;
017: import java.awt.image.renderable.ParameterBlock;
018: import java.awt.image.renderable.RenderableImage;
019: import javax.media.jai.JAI;
020: import javax.media.jai.OperationDescriptorImpl;
021: import javax.media.jai.ParameterBlockJAI;
022: import javax.media.jai.PropertyGenerator;
023: import javax.media.jai.RenderableOp;
024: import javax.media.jai.RenderedOp;
025: import javax.media.jai.registry.RenderableRegistryMode;
026: import javax.media.jai.registry.RenderedRegistryMode;
027:
028: /**
029: * An <code>OperationDescriptor</code> describing the "Phase" operation.
030: *
031: * <p> The "Phase" operation computes the phase angle of each pixel of a
032: * complex image. The source image must have an even number of bands, with
033: * the even bands (0, 2, ...) representing the real parts and the odd bands
034: * (1, 3, ...) the imaginary parts of each complex pixel. The destination
035: * image has at most half the number of bands of the source image with each
036: * sample in a pixel representing the phase angle of the corresponding complex
037: * source sample. The angular values of the destination image are defined
038: * for a given sample by the pseudocode:
039: *
040: * <pre>dst[x][y][b] = Math.atan2(src[x][y][2*b+1], src[x][y][2*b])</pre>
041: *
042: * where the number of bands <i>b</i> varies from zero to one less than the
043: * number of bands in the destination image.
044: *
045: * <p> For integral image datatypes, the result will be rounded and
046: * scaled so the the "natural" arctangent range [-PI, PI) is remapped into
047: * the range [0, MAX_VALUE); the result for floating point image datatypes
048: * is the value returned by the atan2() method.
049: *
050: * <p>"Phase" defines a PropertyGenerator that sets the "COMPLEX"
051: * property of the image to <code>java.lang.Boolean.FALSE</code>, which may
052: * be retrieved by calling the <code>getProperty()</code> method with
053: * "COMPLEX" as the property name.
054: *
055: * <p><table border=1>
056: * <caption>Resource List</caption>
057: * <tr><th>Name</th> <th>Value</th></tr>
058: * <tr><td>GlobalName</td> <td>Phase</td></tr>
059: * <tr><td>LocalName</td> <td>Phase</td></tr>
060: * <tr><td>Vendor</td> <td>com.sun.media.jai</td></tr>
061: * <tr><td>Description</td> <td>Computes the phase angle of each pixel of
062: * an image.</td></tr>
063: * <tr><td>DocURL</td> <td>http://java.sun.com/products/java-media/jai/forDevelopers/jai-apidocs/javax/media/jai/operator/PhaseDescriptor.html</td></tr>
064: * <tr><td>Version</td> <td>1.0</td></tr>
065: * </table></p>
066: *
067: * <p> No parameters are needed for the "Phase" operation.
068: *
069: * @see javax.media.jai.OperationDescriptor
070: */
071: public class PhaseDescriptor extends OperationDescriptorImpl {
072:
073: /**
074: * The resource strings that provide the general documentation
075: * and specify the parameter list for this operation.
076: */
077: private static final String[][] resources = {
078: { "GlobalName", "Phase" },
079: { "LocalName", "Phase" },
080: { "Vendor", "com.sun.media.jai" },
081: { "Description", JaiI18N.getString("PhaseDescriptor0") },
082: {
083: "DocURL",
084: "http://java.sun.com/products/java-media/jai/forDevelopers/jai-apidocs/javax/media/jai/operator/PhaseDescriptor.html" },
085: { "Version", JaiI18N.getString("DescriptorVersion") } };
086:
087: private static final String[] supportedModes = { "rendered",
088: "renderable" };
089:
090: /** Constructor. */
091: public PhaseDescriptor() {
092: super (resources, supportedModes, 1, null, null, null, null);
093: }
094:
095: /**
096: * Validates the input source.
097: *
098: * <p> In addition to the standard checks performed by the
099: * superclass method, this method checks that the source image
100: * has an even number of bands.
101: */
102: protected boolean validateSources(String modeName,
103: ParameterBlock args, StringBuffer msg) {
104: if (!super .validateSources(modeName, args, msg)) {
105: return false;
106: }
107:
108: if (!modeName.equalsIgnoreCase("rendered"))
109: return true;
110:
111: RenderedImage src = args.getRenderedSource(0);
112:
113: int bands = src.getSampleModel().getNumBands();
114:
115: if (bands % 2 != 0) {
116: msg.append(getName() + " "
117: + JaiI18N.getString("PhaseDescriptor1"));
118: return false;
119: }
120:
121: return true;
122: }
123:
124: /**
125: * Returns an array of <code>PropertyGenerators</code> implementing
126: * property inheritance for the "Phase" operation.
127: *
128: * @return An array of property generators.
129: */
130: public PropertyGenerator[] getPropertyGenerators(String modeName) {
131: PropertyGenerator[] pg = new PropertyGenerator[1];
132: pg[0] = new ComplexPropertyGenerator();
133: return pg;
134: }
135:
136: /**
137: * Computes the phase angle of each pixel of an image.
138: *
139: * <p>Creates a <code>ParameterBlockJAI</code> from all
140: * supplied arguments except <code>hints</code> and invokes
141: * {@link JAI#create(String,ParameterBlock,RenderingHints)}.
142: *
143: * @see JAI
144: * @see ParameterBlockJAI
145: * @see RenderedOp
146: *
147: * @param source0 <code>RenderedImage</code> source 0.
148: * @param hints The <code>RenderingHints</code> to use.
149: * May be <code>null</code>.
150: * @return The <code>RenderedOp</code> destination.
151: * @throws IllegalArgumentException if <code>source0</code> is <code>null</code>.
152: */
153: public static RenderedOp create(RenderedImage source0,
154: RenderingHints hints) {
155: ParameterBlockJAI pb = new ParameterBlockJAI("Phase",
156: RenderedRegistryMode.MODE_NAME);
157:
158: pb.setSource("source0", source0);
159:
160: return JAI.create("Phase", pb, hints);
161: }
162:
163: /**
164: * Computes the phase angle of each pixel of an image.
165: *
166: * <p>Creates a <code>ParameterBlockJAI</code> from all
167: * supplied arguments except <code>hints</code> and invokes
168: * {@link JAI#createRenderable(String,ParameterBlock,RenderingHints)}.
169: *
170: * @see JAI
171: * @see ParameterBlockJAI
172: * @see RenderableOp
173: *
174: * @param source0 <code>RenderableImage</code> source 0.
175: * @param hints The <code>RenderingHints</code> to use.
176: * May be <code>null</code>.
177: * @return The <code>RenderableOp</code> destination.
178: * @throws IllegalArgumentException if <code>source0</code> is <code>null</code>.
179: */
180: public static RenderableOp createRenderable(
181: RenderableImage source0, RenderingHints hints) {
182: ParameterBlockJAI pb = new ParameterBlockJAI("Phase",
183: RenderableRegistryMode.MODE_NAME);
184:
185: pb.setSource("source0", source0);
186:
187: return JAI.createRenderable("Phase", pb, hints);
188: }
189: }
|