001: /*
002: * $RCSfile: ColorConvertDescriptor.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:31 $
010: * $State: Exp $
011: */
012: package javax.media.jai.operator;
013:
014: import java.awt.RenderingHints;
015: import java.awt.image.ColorModel;
016: import java.awt.image.RenderedImage;
017: import java.awt.image.renderable.RenderableImage;
018: import javax.media.jai.JAI;
019: import javax.media.jai.OperationDescriptorImpl;
020: import javax.media.jai.ParameterBlockJAI;
021: import javax.media.jai.RenderableOp;
022: import javax.media.jai.RenderedOp;
023: import javax.media.jai.registry.RenderableRegistryMode;
024: import javax.media.jai.registry.RenderedRegistryMode;
025:
026: /**
027: * An <code>OperationDescriptor</code> describing the "ColorConvert" operation.
028: *
029: * <p> The "ColorConvert" operation performs a pixel-by-pixel color
030: * conversion of the data in a rendered or renderable source image.
031: *
032: * <p> The data are treated as having no alpha channel, i.e., all bands are
033: * color bands. The color space of the source image is specified by the
034: * <code>ColorSpace</code> object of the source image <code>ColorModel</code>
035: * which must not be <code>null</code>. The color space of the destination
036: * image is specified by the <code>ColorSpace</code> of the "colorModel"
037: * parameter which must be a <code>ColorModel</code>. If a
038: * <code>ColorModel</code> is suggested via the <code>RenderingHints</code>
039: * it is ignored.
040: *
041: * <p> The calculation pathway is selected to optimize performance and
042: * accuracy based on which <code>ColorSpace</code> subclasses are used to
043: * represent the source and destination color spaces. The subclass
044: * categories are <code>ICC_ColorSpace</code>, <code>ColorSpaceJAI</code>,
045: * and generic <code>ColorSpace</code>, i.e., one which is not an instance
046: * of either the two aforementioned subclasses. Note that in the Sun
047: * Microsystems implementation, an <code>ICC_ColorSpace</code> instance
048: * is what is returned by <code>ColorSpace.getInstance()</code>.
049: *
050: * <p> Integral data are assumed to occupy the full range of the respective
051: * data type; floating point data are assumed to be normalized to the range
052: * [0.0,1.0].
053: *
054: * <p> By default, the destination image bounds, data type, and number of
055: * bands are the same as those of the source image.
056: *
057: * <p><table border=1>
058: * <caption>Resource List</caption>
059: * <tr><th>Name</th> <th>Value</th></tr>
060: * <tr><td>GlobalName</td> <td>ColorConvert</td></tr>
061: * <tr><td>LocalName</td> <td>ColorConvert</td></tr>
062: * <tr><td>Vendor</td> <td>com.sun.media.jai</td></tr>
063: * <tr><td>Description</td> <td>Convert the color space of an image.<td></tr>
064: * <tr><td>DocURL</td> <td>http://java.sun.com/products/java-media/jai/forDevelopers/jai-apidocs/javax/media/jai/operator/ColorConvertDescriptor.html</td></tr>
065: * <tr><td>Version</td> <td>1.0</td></tr>
066: * <tr><td>arg0Desc</td> <td>The destination <code>ColorModel</code>.</td></tr>
067: * </table></p>
068: *
069: * <p><table border=1>
070: * <caption>Parameter List</caption>
071: * <tr><th>Name</th> <th>Class Type</th>
072: * <th>Default Value</th></tr>
073: * <tr><td>colorModel</td> <td>java.awt.image.ColorModel</td>
074: * <td>NO_PARAMETER_DEFAULT</td>
075: * </table></p>
076: *
077: * @see javax.media.jai.OperationDescriptor
078: * @see java.awt.color.ColorSpace
079: * @see java.awt.color.ICC_ColorSpace
080: * @see java.awt.image.ColorModel
081: * @see javax.media.jai.ColorSpaceJAI
082: * @see javax.media.jai.IHSColorSpace
083: */
084: public class ColorConvertDescriptor extends OperationDescriptorImpl {
085:
086: /**
087: * The resource strings that provide the general documentation
088: * and specify the parameter list for this operation.
089: */
090: private static final String[][] resources = {
091: { "GlobalName", "ColorConvert" },
092: { "LocalName", "ColorConvert" },
093: { "Vendor", "com.sun.media.jai" },
094: { "Description",
095: JaiI18N.getString("ColorConvertDescriptor0") },
096: {
097: "DocURL",
098: "http://java.sun.com/products/java-media/jai/forDevelopers/jai-apidocs/javax/media/jai/operator/ColorConvertDescriptor.html" },
099: { "Version", JaiI18N.getString("DescriptorVersion2") },
100: { "arg0Desc", JaiI18N.getString("ColorConvertDescriptor1") } };
101:
102: /**
103: * The parameter class list for this operation.
104: */
105: private static final Class[] paramClasses = { java.awt.image.ColorModel.class };
106:
107: /** The parameter name list for this operation. */
108: private static final String[] paramNames = { "colorModel" };
109:
110: /** The parameter default value list for this operation. */
111: private static final Object[] paramDefaults = { NO_PARAMETER_DEFAULT };
112:
113: /** Constructor. */
114: public ColorConvertDescriptor() {
115: super (resources, 1, paramClasses, paramNames, paramDefaults);
116: }
117:
118: /** Returns <code>true</code> since renderable operation is supported. */
119: public boolean isRenderableSupported() {
120: return true;
121: }
122:
123: /**
124: * Convert the color space of an image.
125: *
126: * <p>Creates a <code>ParameterBlockJAI</code> from all
127: * supplied arguments except <code>hints</code> and invokes
128: * {@link JAI#create(String,ParameterBlock,RenderingHints)}.
129: *
130: * @see JAI
131: * @see ParameterBlockJAI
132: * @see RenderedOp
133: *
134: * @param source0 <code>RenderedImage</code> source 0.
135: * @param colorModel The destination color space.
136: * @param hints The <code>RenderingHints</code> to use.
137: * May be <code>null</code>.
138: * @return The <code>RenderedOp</code> destination.
139: * @throws IllegalArgumentException if <code>source0</code> is <code>null</code>.
140: * @throws IllegalArgumentException if <code>colorModel</code> is <code>null</code>.
141: */
142: public static RenderedOp create(RenderedImage source0,
143: ColorModel colorModel, RenderingHints hints) {
144: ParameterBlockJAI pb = new ParameterBlockJAI("ColorConvert",
145: RenderedRegistryMode.MODE_NAME);
146:
147: pb.setSource("source0", source0);
148:
149: pb.setParameter("colorModel", colorModel);
150:
151: return JAI.create("ColorConvert", pb, hints);
152: }
153:
154: /**
155: * Convert the color space of an image.
156: *
157: * <p>Creates a <code>ParameterBlockJAI</code> from all
158: * supplied arguments except <code>hints</code> and invokes
159: * {@link JAI#createRenderable(String,ParameterBlock,RenderingHints)}.
160: *
161: * @see JAI
162: * @see ParameterBlockJAI
163: * @see RenderableOp
164: *
165: * @param source0 <code>RenderableImage</code> source 0.
166: * @param colorModel The destination color space.
167: * @param hints The <code>RenderingHints</code> to use.
168: * May be <code>null</code>.
169: * @return The <code>RenderableOp</code> destination.
170: * @throws IllegalArgumentException if <code>source0</code> is <code>null</code>.
171: * @throws IllegalArgumentException if <code>colorModel</code> is <code>null</code>.
172: */
173: public static RenderableOp createRenderable(
174: RenderableImage source0, ColorModel colorModel,
175: RenderingHints hints) {
176: ParameterBlockJAI pb = new ParameterBlockJAI("ColorConvert",
177: RenderableRegistryMode.MODE_NAME);
178:
179: pb.setSource("source0", source0);
180:
181: pb.setParameter("colorModel", colorModel);
182:
183: return JAI.createRenderable("ColorConvert", pb, hints);
184: }
185: }
|