001: /*
002: * @(#) $Header: /cvs/jai-operators/src/main/ca/forklabs/media/jai/operator/UnaryFunctionDescriptor.java,v 1.6 2007/09/07 18:10:06 forklabs Exp $
003: *
004: * Copyright (C) 2007 Forklabs Daniel Léonard
005: *
006: * This program is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU General Public License
008: * as published by the Free Software Foundation; either version 2
009: * of the License, or (at your option) any later version.
010: *
011: * This program is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
014: * GNU General Public License for more details.
015: *
016: * You should have received a copy of the GNU General Public License
017: * along with this program; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
019: */
020:
021: package ca.forklabs.media.jai.operator;
022:
023: import java.awt.RenderingHints;
024: import java.awt.image.RenderedImage;
025: import java.awt.image.renderable.ParameterBlock;
026: import java.awt.image.renderable.RenderableImage;
027: import javax.media.jai.JAI;
028: import javax.media.jai.OperationDescriptor;
029: import javax.media.jai.OperationDescriptorImpl;
030: import javax.media.jai.ParameterBlockJAI;
031: import javax.media.jai.RenderableOp;
032: import javax.media.jai.RenderedOp;
033: import javax.media.jai.registry.RenderableRegistryMode;
034: import javax.media.jai.registry.RenderedRegistryMode;
035: import ca.forklabs.baselib.util.UnaryFunction;
036:
037: /**
038: * Class {@code UnaryFunctionDescriptor} is an {@link OperationDescriptor}
039: * describing the <em>unaryfunction</em> operation. This operation takes a
040: * source image and creates a new image in which each pixel is the result of
041: * applying an {@link UnaryFunction} to its corresponding pixel of the source
042: * image. Only one source and one parameter are needed.
043: *
044: * <table border=1>
045: * <caption>Resource List</caption>
046: * <tr><th>Name</th> <th>Value</th></tr>
047: * <tr><td>GlobalName</td> <td>UnaryFunction</td></tr>
048: * <tr><td>LocalName</td> <td>UnaryFunction</td></tr>
049: * <tr><td>Vendor</td> <td>ca.forklabs.media.jai.opimage</td></tr>
050: * <tr><td>Description</td> <td>Application of an unary function on all the pixels</td></tr>
051: * <tr><td>DocURL</td> <td>n/a</td></tr>
052: * <tr><td>Version</td> <td>$Version$</td></tr>
053: * <tr><td>Arg0Desct</td> <td>The {@link UnaryFunction}</td></tr>
054: * </table>
055: *
056: * <table border=1>
057: * <caption>Parameter List</caption>
058: * <tr><th>Name</th> <th>Class Type</th> <th>Default Value</th></tr>
059: * <tr><td>function</td> <td>UnaryFunction<Double, Double></td> <td>NO_PARAMETER_DEFAULT</td>
060: * </table>
061: *
062: * @author <a href="mailto:forklabs at dev.java.net?subject=ca.forklabs.media.jai.operator.UnaryFunctionDescriptor">Daniel Léonard</a>
063: * @version $Revision: 1.6 $
064: */
065: public class UnaryFunctionDescriptor extends OperationDescriptorImpl {
066:
067: //---------------------------
068: // Class variables
069: //---------------------------
070:
071: /** <em>serialVersionUID</em>. */
072: private static final long serialVersionUID = -3900844847894674507L;
073:
074: /** The name of this operator. */
075: @SuppressWarnings("nls")
076: public static final String NAME = "UnaryFunction";
077:
078: /** The name of the unary function parameter. */
079: @SuppressWarnings("nls")
080: public static final String FUNCTION_PARAMETER_NAME = "function";
081: /** The index in the parameter block of the unary function parameter. */
082: public static final int FUNCTION_PARAMETER_INDEX = 0;
083:
084: /**
085: * The resource strings that provide the general documentation and specify
086: * the parameter list for this operation.
087: */
088: @SuppressWarnings({"nls","static-access"})
089: private static final String[][] RESOURCES = {
090: { "GlobalName", UnaryFunctionDescriptor.NAME, },
091: { "LocalName", UnaryFunctionDescriptor.NAME, },
092: { "Vendor", "ca.forklabs.media.jai.", },
093: { "Description", UnaryFunctionDescriptor.getDescription(), },
094: { "DocURL", "n/a", },
095: { "Version", "$Version$", },
096: { "arg0Desc", UnaryFunctionDescriptor.getArg0Description(), }, };
097:
098: /** The supported modes. */
099: private static final String[] SUPPORTED_MODES = {
100: RenderedRegistryMode.MODE_NAME,
101: RenderableRegistryMode.MODE_NAME, };
102:
103: /** The parameter class list for this operation. */
104: private static final Class<?>[] PARAMETER_CLASSES = new Class<?>[] { UnaryFunction.class, };
105:
106: /** The parameter name list for this operation. */
107: private static final String[] PARAMETER_NAMES = new String[] { UnaryFunctionDescriptor.FUNCTION_PARAMETER_NAME, };
108:
109: // TODO : change for the identity function and update the documentation and manual
110: /** The default parameters. */
111: @SuppressWarnings("boxing")
112: private static final Object[] PARAMETER_DEFAULTS = new Object[] { OperationDescriptor.NO_PARAMETER_DEFAULT, };
113:
114: /** Valid parameter values. */
115: private static final Object[] VALID_PARAMETERS = new Object[] { null, };
116:
117: //---------------------------
118: // Constructor
119: //---------------------------
120:
121: /**
122: * Constructor.
123: */
124: public UnaryFunctionDescriptor() {
125: super (RESOURCES, SUPPORTED_MODES, 1, PARAMETER_NAMES,
126: PARAMETER_CLASSES, PARAMETER_DEFAULTS, VALID_PARAMETERS);
127: }
128:
129: //---------------------------
130: // Class methods
131: //---------------------------
132:
133: /**
134: * Creates and fills a new parameter block.
135: * @param mode the rendering mode.
136: * @param source the source image.
137: * @param function the unary function.
138: * @return a new parameter block.
139: */
140: public static ParameterBlockJAI createParameterBlock(String mode,
141: Object source, UnaryFunction<Double, Double> function) {
142: String name = UnaryFunctionDescriptor.NAME;
143: ParameterBlockJAI pb = new ParameterBlockJAI(name, mode);
144: if (null != source) {
145: pb.addSource(source);
146: }
147: pb.setParameter(
148: UnaryFunctionDescriptor.FUNCTION_PARAMETER_NAME,
149: function);
150: return pb;
151: }
152:
153: /**
154: * Creates a rendered image.
155: * @param source the source image.
156: * @param function the unary function.
157: * @param hints the rendering hints, may be {@code null}.
158: * @return the new image.
159: */
160: public static RenderedOp create(RenderedImage source,
161: UnaryFunction<Double, Double> function, RenderingHints hints) {
162: String operation = UnaryFunctionDescriptor.NAME;
163: String mode = RenderedRegistryMode.MODE_NAME;
164: ParameterBlock pb = UnaryFunctionDescriptor
165: .createParameterBlock(mode, source, function);
166: RenderedOp image = JAI.create(operation, pb, hints);
167: return image;
168: }
169:
170: /**
171: * Creates a renderable image.
172: * @param source the source image.
173: * @param function the unary function.
174: * @param hints the rendering hints, may be {@code null}.
175: * @return the new image.
176: */
177: public static RenderableOp createRenderable(RenderableImage source,
178: UnaryFunction<Double, Double> function, RenderingHints hints) {
179: String operation = UnaryFunctionDescriptor.NAME;
180: String mode = RenderableRegistryMode.MODE_NAME;
181: ParameterBlock pb = UnaryFunctionDescriptor
182: .createParameterBlock(mode, source, function);
183: RenderableOp image = JAI.createRenderable(operation, pb, hints);
184: return image;
185: }
186:
187: //---------------------------
188: // External resources methods
189: //---------------------------
190:
191: /**
192: * Gets the description of this operation.
193: * @return the description message.
194: */
195: protected static String getDescription() {
196: String key = Resources.UNARY_FUNCTION_DESCRIPTION;
197: String message = Resources.getLocalizedString(key);
198: return message;
199: }
200:
201: /**
202: * Gets the description of the first parameter.
203: * @return the description message.
204: */
205: protected static String getArg0Description() {
206: String key = Resources.UNARY_FUNCTION_ARG0_DESCRIPTION;
207: String message = Resources.getLocalizedString(key);
208: return message;
209: }
210:
211: }
212:
213: /*
214: * $Log: UnaryFunctionDescriptor.java,v $
215: * Revision 1.6 2007/09/07 18:10:06 forklabs
216: * Added a TODO marker.
217: *
218: * Revision 1.5 2007/08/16 21:23:33 forklabs
219: * Changed local variable names.
220: *
221: * Revision 1.4 2007/05/03 20:53:47 forklabs
222: * Trimmed trailing spaces.
223: *
224: * Revision 1.3 2007/05/03 20:53:23 forklabs
225: * javadoc
226: *
227: * Revision 1.2 2007/05/03 20:25:33 forklabs
228: * Trimmed trailing spaces.
229: *
230: * Revision 1.1 2007/05/03 18:32:28 forklabs
231: * Initial commit for the unaryfunction operator.
232: *
233: */
|