001: /*
002: * $RCSfile: OrDescriptor.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.DataBuffer;
016: import java.awt.image.RenderedImage;
017: import java.awt.image.renderable.ParameterBlock;
018: import java.awt.image.renderable.RenderableImage;
019: import javax.media.jai.JAI;
020: import javax.media.jai.OperationDescriptorImpl;
021: import javax.media.jai.ParameterBlockJAI;
022: import javax.media.jai.RenderableOp;
023: import javax.media.jai.RenderedOp;
024: import javax.media.jai.registry.RenderableRegistryMode;
025: import javax.media.jai.registry.RenderedRegistryMode;
026:
027: /**
028: * An <code>OperationDescriptor</code> describing the "Or" operation.
029: *
030: * <p> The Or operation takes two rendered or renderable images, and
031: * performs bit-wise logical "or" on every pair of pixels, one from
032: * each source image of the corresponding position and band. No
033: * additional parameters are required.
034: *
035: * <p> Both source images must have integral data types. The two
036: * data types may be different.
037: *
038: * <p> Unless altered by an <code>ImageLayout</code> hint, the
039: * destination image bound is the intersection of the two source image
040: * bounds. If the two sources don't intersect, the destination will
041: * have a width and height of 0. The number of bands of the
042: * destination image is equal to the lesser number of bands of the
043: * sources, and the data type is the smallest data type with
044: * sufficient range to cover the range of both source data types.
045: *
046: * <p> The following matrix defines the logical "or" operation.
047: * <p><table border=1>
048: * <caption>Logical "or"</caption>
049: * <tr align=center><th>src1</th> <th>src2</th> <th>Result</th></tr>
050: * <tr align=center><td>0</td> <td>0</td> <td>0</td></tr>
051: * <tr align=center><td>0</td> <td>1</td> <td>1</td></tr>
052: * <tr align=center><td>1</td> <td>0</td> <td>1</td></tr>
053: * <tr align=center><td>1</td> <td>1</td> <td>1</td></tr>
054: * </table></p>
055: *
056: * <p> The destination pixel values are defined by the pseudocode:
057: * <pre>
058: * dst[x][y][b] = srcs[0][x][y][b] | srcs[1][x][y][b];
059: * </pre>
060: *
061: * <p><table border=1>
062: * <caption>Resource List</caption>
063: * <tr><th>Name</th> <th>Value</th></tr>
064: * <tr><td>GlobalName</td> <td>Or</td></tr>
065: * <tr><td>LocalName</td> <td>Or</td></tr>
066: * <tr><td>Vendor</td> <td>com.sun.media.jai</td></tr>
067: * <tr><td>Description</td> <td>Logically "ors" two images.</td></tr>
068: * <tr><td>DocURL</td> <td>http://java.sun.com/products/java-media/jai/forDevelopers/jai-apidocs/javax/media/jai/operator/OrDescriptor.html</td></tr>
069: * <tr><td>Version</td> <td>1.0</td></tr>
070: * </table></p>
071: *
072: * <p> No parameters are needed for this operation.
073: *
074: * @see javax.media.jai.OperationDescriptor
075: */
076: public class OrDescriptor extends OperationDescriptorImpl {
077:
078: /**
079: * The resource strings that provide the general documentation
080: * and specify the parameter list for this operation.
081: */
082: private static final String[][] resources = {
083: { "GlobalName", "Or" },
084: { "LocalName", "Or" },
085: { "Vendor", "com.sun.media.jai" },
086: { "Description", JaiI18N.getString("OrDescriptor0") },
087: {
088: "DocURL",
089: "http://java.sun.com/products/java-media/jai/forDevelopers/jai-apidocs/javax/media/jai/operator/OrDescriptor.html" },
090: { "Version", JaiI18N.getString("DescriptorVersion") } };
091:
092: private static final String[] supportedModes = { "rendered",
093: "renderable" };
094:
095: /** Constructor. */
096: public OrDescriptor() {
097: super (resources, supportedModes, 2, null, null, null, null);
098: }
099:
100: /**
101: * Validates the input sources.
102: *
103: * <p> In addition to the standard checks performed by the
104: * superclass method, this method checks that the source images
105: * are of integral data type.
106: */
107: protected boolean validateSources(String modeName,
108: ParameterBlock args, StringBuffer msg) {
109: if (!super .validateSources(modeName, args, msg)) {
110: return false;
111: }
112:
113: if (!modeName.equalsIgnoreCase("rendered"))
114: return true;
115:
116: for (int i = 0; i < 2; i++) {
117: RenderedImage src = args.getRenderedSource(i);
118:
119: int dtype = src.getSampleModel().getDataType();
120:
121: if (dtype != DataBuffer.TYPE_BYTE
122: && dtype != DataBuffer.TYPE_USHORT
123: && dtype != DataBuffer.TYPE_SHORT
124: && dtype != DataBuffer.TYPE_INT) {
125: msg.append(getName() + " "
126: + JaiI18N.getString("OrDescriptor1"));
127: return false;
128: }
129: }
130:
131: return true;
132: }
133:
134: /**
135: * Logically "ors" two images.
136: *
137: * <p>Creates a <code>ParameterBlockJAI</code> from all
138: * supplied arguments except <code>hints</code> and invokes
139: * {@link JAI#create(String,ParameterBlock,RenderingHints)}.
140: *
141: * @see JAI
142: * @see ParameterBlockJAI
143: * @see RenderedOp
144: *
145: * @param source0 <code>RenderedImage</code> source 0.
146: * @param source1 <code>RenderedImage</code> source 1.
147: * @param hints The <code>RenderingHints</code> to use.
148: * May be <code>null</code>.
149: * @return The <code>RenderedOp</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 RenderedOp create(RenderedImage source0,
154: RenderedImage source1, RenderingHints hints) {
155: ParameterBlockJAI pb = new ParameterBlockJAI("Or",
156: RenderedRegistryMode.MODE_NAME);
157:
158: pb.setSource("source0", source0);
159: pb.setSource("source1", source1);
160:
161: return JAI.create("Or", pb, hints);
162: }
163:
164: /**
165: * Logically "ors" two images.
166: *
167: * <p>Creates a <code>ParameterBlockJAI</code> from all
168: * supplied arguments except <code>hints</code> and invokes
169: * {@link JAI#createRenderable(String,ParameterBlock,RenderingHints)}.
170: *
171: * @see JAI
172: * @see ParameterBlockJAI
173: * @see RenderableOp
174: *
175: * @param source0 <code>RenderableImage</code> source 0.
176: * @param source1 <code>RenderableImage</code> source 1.
177: * @param hints The <code>RenderingHints</code> to use.
178: * May be <code>null</code>.
179: * @return The <code>RenderableOp</code> destination.
180: * @throws IllegalArgumentException if <code>source0</code> is <code>null</code>.
181: * @throws IllegalArgumentException if <code>source1</code> is <code>null</code>.
182: */
183: public static RenderableOp createRenderable(
184: RenderableImage source0, RenderableImage source1,
185: RenderingHints hints) {
186: ParameterBlockJAI pb = new ParameterBlockJAI("Or",
187: RenderableRegistryMode.MODE_NAME);
188:
189: pb.setSource("source0", source0);
190: pb.setSource("source1", source1);
191:
192: return JAI.createRenderable("Or", pb, hints);
193: }
194: }
|