001: /*
002: * $RCSfile: NotDescriptor.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 "Not" operation.
029: *
030: * <p> The Not operation takes one rendered or renderable image, and
031: * performs bit-wise logical "not" on every pixel from every band of
032: * the source image. No additional parameters are required.
033: *
034: * <p> The source image must have an integral data type. By default,
035: * the destination image bound, data type, and number of bands are the
036: * same as the source image.
037: *
038: * <p>The following matrix defines the logical "not" operation.
039: * <p><table border=1>
040: * <caption>Logical "not"</caption>
041: * <tr align=center><th>src</th> <th>Result</th></tr>
042: * <tr align=center><td>1</td> <td>0</td></tr>
043: * <tr align=center><td>0</td> <td>1</td></tr>
044: * </table></p>
045: *
046: * <p> The destination pixel values are defined by the pseudocode:
047: * <pre>
048: * dst[x][y][b] = ~src[x][y][b];
049: * </pre>
050: *
051: * <p><table border=1>
052: * <caption>Resource List</caption>
053: * <tr><th>Name</th> <th>Value</th></tr>
054: * <tr><td>GlobalName</td> <td>Not</td></tr>
055: * <tr><td>LocalName</td> <td>Not</td></tr>
056: * <tr><td>Vendor</td> <td>com.sun.media.jai</td></tr>
057: * <tr><td>Description</td> <td>Logically "nots" an image.</td></tr>
058: * <tr><td>DocURL</td> <td>http://java.sun.com/products/java-media/jai/forDevelopers/jai-apidocs/javax/media/jai/operator/NotDescriptor.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 NotDescriptor 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", "Not" },
074: { "LocalName", "Not" },
075: { "Vendor", "com.sun.media.jai" },
076: { "Description", JaiI18N.getString("NotDescriptor0") },
077: {
078: "DocURL",
079: "http://java.sun.com/products/java-media/jai/forDevelopers/jai-apidocs/javax/media/jai/operator/NotDescriptor.html" },
080: { "Version", JaiI18N.getString("DescriptorVersion") } };
081:
082: private static final String[] supportedModes = { "rendered",
083: "renderable" };
084:
085: /** Constructor. */
086: public NotDescriptor() {
087: super (resources, supportedModes, 1, null, null, null, null);
088: }
089:
090: /**
091: * Validates the input source.
092: *
093: * <p> In addition to the standard checks performed by the
094: * superclass method, this method checks that the source image
095: * is of integral data type.
096: */
097: protected boolean validateSources(String modeName,
098: ParameterBlock args, StringBuffer msg) {
099: if (!super .validateSources(modeName, args, msg)) {
100: return false;
101: }
102:
103: if (!modeName.equalsIgnoreCase("rendered"))
104: return true;
105:
106: RenderedImage src = args.getRenderedSource(0);
107:
108: int dtype = src.getSampleModel().getDataType();
109:
110: if (dtype != DataBuffer.TYPE_BYTE
111: && dtype != DataBuffer.TYPE_USHORT
112: && dtype != DataBuffer.TYPE_SHORT
113: && dtype != DataBuffer.TYPE_INT) {
114: msg.append(getName() + " "
115: + JaiI18N.getString("NotDescriptor1"));
116: return false;
117: }
118:
119: return true;
120: }
121:
122: /**
123: * Logically "nots" an image.
124: *
125: * <p>Creates a <code>ParameterBlockJAI</code> from all
126: * supplied arguments except <code>hints</code> and invokes
127: * {@link JAI#create(String,ParameterBlock,RenderingHints)}.
128: *
129: * @see JAI
130: * @see ParameterBlockJAI
131: * @see RenderedOp
132: *
133: * @param source0 <code>RenderedImage</code> source 0.
134: * @param hints The <code>RenderingHints</code> to use.
135: * May be <code>null</code>.
136: * @return The <code>RenderedOp</code> destination.
137: * @throws IllegalArgumentException if <code>source0</code> is <code>null</code>.
138: */
139: public static RenderedOp create(RenderedImage source0,
140: RenderingHints hints) {
141: ParameterBlockJAI pb = new ParameterBlockJAI("Not",
142: RenderedRegistryMode.MODE_NAME);
143:
144: pb.setSource("source0", source0);
145:
146: return JAI.create("Not", pb, hints);
147: }
148:
149: /**
150: * Logically "nots" an image.
151: *
152: * <p>Creates a <code>ParameterBlockJAI</code> from all
153: * supplied arguments except <code>hints</code> and invokes
154: * {@link JAI#createRenderable(String,ParameterBlock,RenderingHints)}.
155: *
156: * @see JAI
157: * @see ParameterBlockJAI
158: * @see RenderableOp
159: *
160: * @param source0 <code>RenderableImage</code> source 0.
161: * @param hints The <code>RenderingHints</code> to use.
162: * May be <code>null</code>.
163: * @return The <code>RenderableOp</code> destination.
164: * @throws IllegalArgumentException if <code>source0</code> is <code>null</code>.
165: */
166: public static RenderableOp createRenderable(
167: RenderableImage source0, RenderingHints hints) {
168: ParameterBlockJAI pb = new ParameterBlockJAI("Not",
169: RenderableRegistryMode.MODE_NAME);
170:
171: pb.setSource("source0", source0);
172:
173: return JAI.createRenderable("Not", pb, hints);
174: }
175: }
|