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