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