001: /*
002: * $RCSfile: SubtractDescriptor.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:45 $
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 "Subtract"
027: * operation.
028: *
029: * <p> The Subtract operation takes two rendered or renderable images,
030: * and for every
031: * pair of pixels, one from each source image of the corresponding
032: * position and band, subtracts the pixel from the second source from
033: * the pixel from the first source. No additional parameters are
034: * required.
035: *
036: * <p> The two source images may have different numbers of bands and
037: * data types. By default, the destination image bounds are the
038: * intersection of the two source image bounds. If the sources don't
039: * intersect, the destination will have a width and height of 0.
040: *
041: * <p> The default number of bands of the destination image is equal
042: * to the smallest number of bands of the sources, and the data type
043: * is the smallest data type with sufficient range to cover the range
044: * of both source data types (not necessarily the range of their
045: * sums).
046: *
047: * <p> As a special case, if one of the source images has N bands (N >
048: * 1), the other source has 1 band, and an <code>ImageLayout</code>
049: * hint is provided containing a destination <code>SampleModel</code>
050: * with K bands (1 < K <= N), then the single band of the 1-banded
051: * source is subtracted from or into each of the first K bands of the
052: * N-band source.
053: *
054: * <p> If the result of the operation underflows/overflows the
055: * minimum/maximum value supported by the destination data type, then
056: * it will be clamped to the minimum/maximum value respectively.
057: *
058: * <p> The destination pixel values are defined by the pseudocode:
059: * <pre>
060: * dst[x][y][dstBand] = clamp(srcs[0][x][y][src0Band] -
061: * srcs[1][x][y][src1Band]);
062: * </pre>
063: *
064: * <p><table border=1>
065: * <caption>Resource List</caption>
066: * <tr><th>Name</th> <th>Value</th></tr>
067: * <tr><td>GlobalName</td> <td>Subtract</td></tr>
068: * <tr><td>LocalName</td> <td>Subtract</td></tr>
069: * <tr><td>Vendor</td> <td>com.sun.media.jai</td></tr>
070: * <tr><td>Description</td> <td>Subtracts one image from
071: * another image.</td></tr>
072: * <tr><td>DocURL</td> <td>http://java.sun.com/products/java-media/jai/forDevelopers/jai-apidocs/javax/media/jai/operator/SubtractDescriptor.html</td></tr>
073: * <tr><td>Version</td> <td>1.0</td></tr>
074: * </table></p>
075: *
076: * <p> No parameters are needed for this operation.
077: *
078: * @see javax.media.jai.OperationDescriptor
079: */
080: public class SubtractDescriptor extends OperationDescriptorImpl {
081:
082: /**
083: * The resource strings that provide the general documentation
084: * and specify the parameter list for this operation.
085: */
086: private static final String[][] resources = {
087: { "GlobalName", "Subtract" },
088: { "LocalName", "Subtract" },
089: { "Vendor", "com.sun.media.jai" },
090: { "Description", JaiI18N.getString("SubtractDescriptor0") },
091: {
092: "DocURL",
093: "http://java.sun.com/products/java-media/jai/forDevelopers/jai-apidocs/javax/media/jai/operator/SubtractDescriptor.html" },
094: { "Version", JaiI18N.getString("DescriptorVersion") } };
095:
096: /** Constructor. */
097: public SubtractDescriptor() {
098: super (resources, 2, null, null, null);
099: }
100:
101: /** Returns <code>true</code> since renderable operation is supported. */
102: public boolean isRenderableSupported() {
103: return true;
104: }
105:
106: /**
107: * Subtracts one image from another image.
108: *
109: * <p>Creates a <code>ParameterBlockJAI</code> from all
110: * supplied arguments except <code>hints</code> and invokes
111: * {@link JAI#create(String,ParameterBlock,RenderingHints)}.
112: *
113: * @see JAI
114: * @see ParameterBlockJAI
115: * @see RenderedOp
116: *
117: * @param source0 <code>RenderedImage</code> source 0.
118: * @param source1 <code>RenderedImage</code> source 1.
119: * @param hints The <code>RenderingHints</code> to use.
120: * May be <code>null</code>.
121: * @return The <code>RenderedOp</code> destination.
122: * @throws IllegalArgumentException if <code>source0</code> is <code>null</code>.
123: * @throws IllegalArgumentException if <code>source1</code> is <code>null</code>.
124: */
125: public static RenderedOp create(RenderedImage source0,
126: RenderedImage source1, RenderingHints hints) {
127: ParameterBlockJAI pb = new ParameterBlockJAI("Subtract",
128: RenderedRegistryMode.MODE_NAME);
129:
130: pb.setSource("source0", source0);
131: pb.setSource("source1", source1);
132:
133: return JAI.create("Subtract", pb, hints);
134: }
135:
136: /**
137: * Subtracts one image from another image.
138: *
139: * <p>Creates a <code>ParameterBlockJAI</code> from all
140: * supplied arguments except <code>hints</code> and invokes
141: * {@link JAI#createRenderable(String,ParameterBlock,RenderingHints)}.
142: *
143: * @see JAI
144: * @see ParameterBlockJAI
145: * @see RenderableOp
146: *
147: * @param source0 <code>RenderableImage</code> source 0.
148: * @param source1 <code>RenderableImage</code> source 1.
149: * @param hints The <code>RenderingHints</code> to use.
150: * May be <code>null</code>.
151: * @return The <code>RenderableOp</code> destination.
152: * @throws IllegalArgumentException if <code>source0</code> is <code>null</code>.
153: * @throws IllegalArgumentException if <code>source1</code> is <code>null</code>.
154: */
155: public static RenderableOp createRenderable(
156: RenderableImage source0, RenderableImage source1,
157: RenderingHints hints) {
158: ParameterBlockJAI pb = new ParameterBlockJAI("Subtract",
159: RenderableRegistryMode.MODE_NAME);
160:
161: pb.setSource("source0", source0);
162: pb.setSource("source1", source1);
163:
164: return JAI.createRenderable("Subtract", pb, hints);
165: }
166: }
|