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