001: /*
002: * $RCSfile: BandMergeDescriptor.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:30 $
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 "BandMerge" operation.
029: *
030: * <p> The BandMerge operation takes two or more rendered or renderable images,
031: * and
032: * performs "BandMerge" on every pixel. Each source image should be non-null.
033: * The number of bands of the destination image is the sum of those of
034: * all source images.
035: *
036: * <p> Intuitively, "BandMerge" stacks all the bands of source images
037: * in the order given in a ParameterBlock. If image1 has three bands
038: * and image2 has one band, the bandmerged image has 4 bands.
039: * Three grayscale images can be used to merge into an RGB image in
040: * this way.
041: *
042: * The destination image bound is the intersection of the source image
043: * bounds. If the sources don't intersect, the destination will
044: * have a width and height of 0.
045: *
046: * <p><table border=1>
047: * <caption>Resource List</caption>
048: * <tr><th>Name</th> <th>Value</th></tr>
049: * <tr><td>GlobalName</td> <td>BandMerge</td></tr>
050: * <tr><td>LocalName</td> <td>BandMerge</td></tr>
051: * <tr><td>Vendor</td> <td>com.sun.media.jai</td></tr>
052: * <tr><td>Description</td> <td>"bandmerges" rendered images.</td></tr>
053: * <tr><td>DocURL</td> <td>http://java.sun.com/products/java-media/jai/forDevelopers/jai-apidocs/javax/media/jai/operator/BandMergeDescriptor.html</td></tr>
054: * <tr><td>Version</td> <td>1.0</td></tr>
055: * </table></p>
056: *
057: * <p> No parameters are needed for this operation.
058: *
059: * @see javax.media.jai.OperationDescriptor
060: *
061: * @since JAI 1.1
062: */
063: public class BandMergeDescriptor extends OperationDescriptorImpl {
064:
065: /**
066: * The resource strings that provide the general documentation
067: * and specify the parameter list for this operation.
068: */
069: private static final String[][] resources = {
070: { "GlobalName", "BandMerge" },
071: { "LocalName", "BandMerge" },
072: { "Vendor", "com.sun.media.jai" },
073: { "Description", JaiI18N.getString("BandMergeDescriptor0") },
074: {
075: "DocURL",
076: "http://java.sun.com/products/java-media/jai/forDevelopers/jai-apidocs/javax/media/jai/operator/BandMergeDescriptor.html" },
077: { "Version", JaiI18N.getString("DescriptorVersion") } };
078:
079: /** Constructor. */
080: // XXX will make this arbitrary number of bands
081: public BandMergeDescriptor() {
082: super (resources, 2, null, null, null);
083: }
084:
085: /** Returns <code>true</code> since renderable operation is supported. */
086: public boolean isRenderableSupported() {
087: return true;
088: }
089:
090: /**
091: * Merge (possibly multi-banded)images into a multibanded image.
092: *
093: * <p>Creates a <code>ParameterBlockJAI</code> from all
094: * supplied arguments except <code>hints</code> and invokes
095: * {@link JAI#create(String,ParameterBlock,RenderingHints)}.
096: *
097: * @see JAI
098: * @see ParameterBlockJAI
099: * @see RenderedOp
100: *
101: * @param source0 <code>RenderedImage</code> source 0.
102: * @param source1 <code>RenderedImage</code> source 1.
103: * @param hints The <code>RenderingHints</code> to use.
104: * May be <code>null</code>.
105: * @return The <code>RenderedOp</code> destination.
106: * @throws IllegalArgumentException if <code>source0</code> is <code>null</code>.
107: * @throws IllegalArgumentException if <code>source1</code> is <code>null</code>.
108: */
109: public static RenderedOp create(RenderedImage source0,
110: RenderedImage source1, RenderingHints hints) {
111: ParameterBlockJAI pb = new ParameterBlockJAI("BandMerge",
112: RenderedRegistryMode.MODE_NAME);
113:
114: pb.setSource("source0", source0);
115: pb.setSource("source1", source1);
116:
117: return JAI.create("BandMerge", pb, hints);
118: }
119:
120: /**
121: * Merge (possibly multi-banded)images into a multibanded image.
122: *
123: * <p>Creates a <code>ParameterBlockJAI</code> from all
124: * supplied arguments except <code>hints</code> and invokes
125: * {@link JAI#createRenderable(String,ParameterBlock,RenderingHints)}.
126: *
127: * @see JAI
128: * @see ParameterBlockJAI
129: * @see RenderableOp
130: *
131: * @param source0 <code>RenderableImage</code> source 0.
132: * @param source1 <code>RenderableImage</code> source 1.
133: * @param hints The <code>RenderingHints</code> to use.
134: * May be <code>null</code>.
135: * @return The <code>RenderableOp</code> destination.
136: * @throws IllegalArgumentException if <code>source0</code> is <code>null</code>.
137: * @throws IllegalArgumentException if <code>source1</code> is <code>null</code>.
138: */
139: public static RenderableOp createRenderable(
140: RenderableImage source0, RenderableImage source1,
141: RenderingHints hints) {
142: ParameterBlockJAI pb = new ParameterBlockJAI("BandMerge",
143: RenderableRegistryMode.MODE_NAME);
144:
145: pb.setSource("source0", source0);
146: pb.setSource("source1", source1);
147:
148: return JAI.createRenderable("BandMerge", pb, hints);
149: }
150: }
|