001: /*
002: * $RCSfile: MaxDescriptor.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:39 $
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 "Max" operation.
027: *
028: * <p> The Max 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 maximum 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>Max</td></tr>
054: * <tr><td>LocalName</td> <td>Max</td></tr>
055: * <tr><td>Vendor</td> <td>com.sun.media.jai</td></tr>
056: * <tr><td>Description</td> <td>Computes the pixel-wise maximum 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/MaxDescriptor.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: public class MaxDescriptor extends OperationDescriptorImpl {
066:
067: /**
068: * The resource strings that provide the general documentation
069: * and specify the parameter list for this operation.
070: */
071: private static final String[][] resources = {
072: { "GlobalName", "Max" },
073: { "LocalName", "Max" },
074: { "Vendor", "com.sun.media.jai" },
075: { "Description", JaiI18N.getString("MaxDescriptor0") },
076: {
077: "DocURL",
078: "http://java.sun.com/products/java-media/jai/forDevelopers/jai-apidocs/javax/media/jai/operator/MaxDescriptor.html" },
079: { "Version", JaiI18N.getString("DescriptorVersion") } };
080:
081: /** Constructor. */
082: public MaxDescriptor() {
083: super (resources, 2, null, null, null);
084: }
085:
086: /** Returns <code>true</code> since renderable operation is supported. */
087: public boolean isRenderableSupported() {
088: return true;
089: }
090:
091: /**
092: * Computes the pixel-wise maximum of two images.
093: *
094: * <p>Creates a <code>ParameterBlockJAI</code> from all
095: * supplied arguments except <code>hints</code> and invokes
096: * {@link JAI#create(String,ParameterBlock,RenderingHints)}.
097: *
098: * @see JAI
099: * @see ParameterBlockJAI
100: * @see RenderedOp
101: *
102: * @param source0 <code>RenderedImage</code> source 0.
103: * @param source1 <code>RenderedImage</code> source 1.
104: * @param hints The <code>RenderingHints</code> to use.
105: * May be <code>null</code>.
106: * @return The <code>RenderedOp</code> destination.
107: * @throws IllegalArgumentException if <code>source0</code> is <code>null</code>.
108: * @throws IllegalArgumentException if <code>source1</code> is <code>null</code>.
109: */
110: public static RenderedOp create(RenderedImage source0,
111: RenderedImage source1, RenderingHints hints) {
112: ParameterBlockJAI pb = new ParameterBlockJAI("Max",
113: RenderedRegistryMode.MODE_NAME);
114:
115: pb.setSource("source0", source0);
116: pb.setSource("source1", source1);
117:
118: return JAI.create("Max", pb, hints);
119: }
120:
121: /**
122: * Computes the pixel-wise maximum of two images.
123: *
124: * <p>Creates a <code>ParameterBlockJAI</code> from all
125: * supplied arguments except <code>hints</code> and invokes
126: * {@link JAI#createRenderable(String,ParameterBlock,RenderingHints)}.
127: *
128: * @see JAI
129: * @see ParameterBlockJAI
130: * @see RenderableOp
131: *
132: * @param source0 <code>RenderableImage</code> source 0.
133: * @param source1 <code>RenderableImage</code> source 1.
134: * @param hints The <code>RenderingHints</code> to use.
135: * May be <code>null</code>.
136: * @return The <code>RenderableOp</code> destination.
137: * @throws IllegalArgumentException if <code>source0</code> is <code>null</code>.
138: * @throws IllegalArgumentException if <code>source1</code> is <code>null</code>.
139: */
140: public static RenderableOp createRenderable(
141: RenderableImage source0, RenderableImage source1,
142: RenderingHints hints) {
143: ParameterBlockJAI pb = new ParameterBlockJAI("Max",
144: RenderableRegistryMode.MODE_NAME);
145:
146: pb.setSource("source0", source0);
147: pb.setSource("source1", source1);
148:
149: return JAI.createRenderable("Max", pb, hints);
150: }
151: }
|