001: /*
002: * $RCSfile: MultiplyDescriptor.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:41 $
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 "Multiply" operation.
027: *
028: * <p> The Multiply operation takes two rendered or renderable source
029: * images, and multiplies every pair of pixels, one from each source
030: * image of the corresponding position and band. No additional
031: * parameters 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>Multiply</td></tr>
064: * <tr><td>LocalName</td> <td>Multiply</td></tr>
065: * <tr><td>Vendor</td> <td>com.sun.media.jai</td></tr>
066: * <tr><td>Description</td> <td>Multiplies 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/MultiplyDescriptor.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: */
075: public class MultiplyDescriptor extends OperationDescriptorImpl {
076:
077: /**
078: * The resource strings that provide the general documentation
079: * and specify the parameter list for this operation.
080: */
081: private static final String[][] resources = {
082: { "GlobalName", "Multiply" },
083: { "LocalName", "Multiply" },
084: { "Vendor", "com.sun.media.jai" },
085: { "Description", JaiI18N.getString("MultiplyDescriptor0") },
086: {
087: "DocURL",
088: "http://java.sun.com/products/java-media/jai/forDevelopers/jai-apidocs/javax/media/jai/operator/MultiplyDescriptor.html" },
089: { "Version", JaiI18N.getString("DescriptorVersion") } };
090:
091: /** Constructor. */
092: public MultiplyDescriptor() {
093: super (resources, 2, null, null, null);
094: }
095:
096: /** Returns <code>true</code> since renderable operation is supported. */
097: public boolean isRenderableSupported() {
098: return true;
099: }
100:
101: /**
102: * Multiplies two images.
103: *
104: * <p>Creates a <code>ParameterBlockJAI</code> from all
105: * supplied arguments except <code>hints</code> and invokes
106: * {@link JAI#create(String,ParameterBlock,RenderingHints)}.
107: *
108: * @see JAI
109: * @see ParameterBlockJAI
110: * @see RenderedOp
111: *
112: * @param source0 <code>RenderedImage</code> source 0.
113: * @param source1 <code>RenderedImage</code> source 1.
114: * @param hints The <code>RenderingHints</code> to use.
115: * May be <code>null</code>.
116: * @return The <code>RenderedOp</code> destination.
117: * @throws IllegalArgumentException if <code>source0</code> is <code>null</code>.
118: * @throws IllegalArgumentException if <code>source1</code> is <code>null</code>.
119: */
120: public static RenderedOp create(RenderedImage source0,
121: RenderedImage source1, RenderingHints hints) {
122: ParameterBlockJAI pb = new ParameterBlockJAI("Multiply",
123: RenderedRegistryMode.MODE_NAME);
124:
125: pb.setSource("source0", source0);
126: pb.setSource("source1", source1);
127:
128: return JAI.create("Multiply", pb, hints);
129: }
130:
131: /**
132: * Multiplies two images.
133: *
134: * <p>Creates a <code>ParameterBlockJAI</code> from all
135: * supplied arguments except <code>hints</code> and invokes
136: * {@link JAI#createRenderable(String,ParameterBlock,RenderingHints)}.
137: *
138: * @see JAI
139: * @see ParameterBlockJAI
140: * @see RenderableOp
141: *
142: * @param source0 <code>RenderableImage</code> source 0.
143: * @param source1 <code>RenderableImage</code> source 1.
144: * @param hints The <code>RenderingHints</code> to use.
145: * May be <code>null</code>.
146: * @return The <code>RenderableOp</code> destination.
147: * @throws IllegalArgumentException if <code>source0</code> is <code>null</code>.
148: * @throws IllegalArgumentException if <code>source1</code> is <code>null</code>.
149: */
150: public static RenderableOp createRenderable(
151: RenderableImage source0, RenderableImage source1,
152: RenderingHints hints) {
153: ParameterBlockJAI pb = new ParameterBlockJAI("Multiply",
154: RenderableRegistryMode.MODE_NAME);
155:
156: pb.setSource("source0", source0);
157: pb.setSource("source1", source1);
158:
159: return JAI.createRenderable("Multiply", pb, hints);
160: }
161: }
|