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