001: /*
002: * $RCSfile: AbsoluteDescriptor.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:28 $
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.RenderableImage;
017: import javax.media.jai.JAI;
018: import javax.media.jai.OperationDescriptorImpl;
019: import javax.media.jai.ParameterBlockJAI;
020: import javax.media.jai.RenderableOp;
021: import javax.media.jai.RenderedOp;
022: import javax.media.jai.registry.RenderableRegistryMode;
023: import javax.media.jai.registry.RenderedRegistryMode;
024:
025: /**
026: * An <code>OperationDescriptor</code> describing the "Absolute" operation.
027: *
028: * <p> The "Absolute" operation takes a single rendered or renderable
029: * source image, and computes the mathematical absolute value of each pixel:
030: *
031: * <pre>
032: * if (src[x][y][b] < 0) {
033: * dst[x][y][b] = -src[x][y][b];
034: * } else {
035: * dst[x][y][b] = src[x][y][b];
036: * }
037: * </pre>
038: *
039: * <p> For signed integral data types, the smallest value of the data
040: * type does not have a positive counterpart; such values will be left
041: * unchanged. This behavior parallels that of the Java unary minus
042: * operator (see <i>The Java Language Specification</i>, section
043: * 15.14.4).
044: *
045: * <p><table border=1>
046: * <caption>Resource List</caption>
047: * <tr><th>Name</th> <th>Value</th></tr>
048: * <tr><td>GlobalName</td> <td>Absolute</td></tr>
049: * <tr><td>LocalName</td> <td>Absolute</td></tr>
050: * <tr><td>Vendor</td> <td>com.sun.media.jai</td></tr>
051: * <tr><td>Description</td> <td>Replaces the pixel values of an image by their absolute values.</td></tr>
052: * <tr><td>DocURL</td> <td>http://java.sun.com/products/java-media/jai/forDevelopers/jai-apidocs/javax/media/jai/operator/AbsoluteDescriptor.html</td></tr>
053: * <tr><td>Version</td> <td>1.0</td></tr>
054: * </table></p>
055: *
056: * <p> No parameters are needed for the "Absolute" operation.
057: *
058: * @see javax.media.jai.OperationDescriptor
059: */
060: public class AbsoluteDescriptor extends OperationDescriptorImpl {
061:
062: /**
063: * The resource strings that provide the general documentation
064: * and specify the parameter list for this operation.
065: */
066: private static final String[][] resources = {
067: { "GlobalName", "Absolute" },
068: { "LocalName", "Absolute" },
069: { "Vendor", "com.sun.media.jai" },
070: { "Description", JaiI18N.getString("AbsoluteDescriptor0") },
071: {
072: "DocURL",
073: "http://java.sun.com/products/java-media/jai/forDevelopers/jai-apidocs/javax/media/jai/operator/AbsoluteDescriptor.html" },
074: { "Version", JaiI18N.getString("DescriptorVersion") } };
075:
076: /** Constructor. */
077: public AbsoluteDescriptor() {
078: super (resources, 1, null, null, null);
079: }
080:
081: /** Returns <code>true</code> since renderable operation is supported. */
082: public boolean isRenderableSupported() {
083: return true;
084: }
085:
086: /**
087: * Replaces the pixel values of an image by their absolute values.
088: *
089: * <p>Creates a <code>ParameterBlockJAI</code> from all
090: * supplied arguments except <code>hints</code> and invokes
091: * {@link JAI#create(String,ParameterBlock,RenderingHints)}.
092: *
093: * @see JAI
094: * @see ParameterBlockJAI
095: * @see RenderedOp
096: *
097: * @param source0 <code>RenderedImage</code> source 0.
098: * @param hints The <code>RenderingHints</code> to use.
099: * May be <code>null</code>.
100: * @return The <code>RenderedOp</code> destination.
101: * @throws IllegalArgumentException if <code>source0</code> is <code>null</code>.
102: */
103: public static RenderedOp create(RenderedImage source0,
104: RenderingHints hints) {
105: ParameterBlockJAI pb = new ParameterBlockJAI("Absolute",
106: RenderedRegistryMode.MODE_NAME);
107:
108: pb.setSource("source0", source0);
109:
110: return JAI.create("Absolute", pb, hints);
111: }
112:
113: /**
114: * Replaces the pixel values of an image by their absolute values.
115: *
116: * <p>Creates a <code>ParameterBlockJAI</code> from all
117: * supplied arguments except <code>hints</code> and invokes
118: * {@link JAI#createRenderable(String,ParameterBlock,RenderingHints)}.
119: *
120: * @see JAI
121: * @see ParameterBlockJAI
122: * @see RenderableOp
123: *
124: * @param source0 <code>RenderableImage</code> source 0.
125: * @param hints The <code>RenderingHints</code> to use.
126: * May be <code>null</code>.
127: * @return The <code>RenderableOp</code> destination.
128: * @throws IllegalArgumentException if <code>source0</code> is <code>null</code>.
129: */
130: public static RenderableOp createRenderable(
131: RenderableImage source0, RenderingHints hints) {
132: ParameterBlockJAI pb = new ParameterBlockJAI("Absolute",
133: RenderableRegistryMode.MODE_NAME);
134:
135: pb.setSource("source0", source0);
136:
137: return JAI.createRenderable("Absolute", pb, hints);
138: }
139: }
|