1 /*
2  * $RCSfile: ColorConvertDescriptor.java,v $
3  *
4  * Copyright (c) 2005 Sun Microsystems, Inc. All rights reserved.
5  *
6  * Use is subject to license terms.
7  *
8  * $Revision: 1.1 $
9  * $Date: 2005/02/11 04:57:31 $
10  * $State: Exp $
11  */
12 package com.lightcrafts.mediax.jai.operator;
13 import java.awt.RenderingHints;
14 import java.awt.image.ColorModel;
15 import java.awt.image.RenderedImage;
16 import java.awt.image.renderable.RenderableImage;
17 import com.lightcrafts.mediax.jai.JAI;
18 import com.lightcrafts.mediax.jai.OperationDescriptorImpl;
19 import com.lightcrafts.mediax.jai.ParameterBlockJAI;
20 import com.lightcrafts.mediax.jai.RenderableOp;
21 import com.lightcrafts.mediax.jai.RenderedOp;
22 import com.lightcrafts.mediax.jai.registry.RenderableRegistryMode;
23 import com.lightcrafts.mediax.jai.registry.RenderedRegistryMode;
24 
25 /**
26  * An <code>OperationDescriptor</code> describing the "ColorConvert" operation.
27  *
28  * <p> The "ColorConvert" operation performs a pixel-by-pixel color
29  * conversion of the data in a rendered or renderable source image.
30  *
31  * <p> The data are treated as having no alpha channel, i.e., all bands are
32  * color bands.  The color space of the source image is specified by the
33  * <code>ColorSpace</code> object of the source image <code>ColorModel</code>
34  * which must not be <code>null</code>.  The color space of the destination
35  * image is specified by the <code>ColorSpace</code> of the "colorModel"
36  * parameter which must be a <code>ColorModel</code>.  If a
37  * <code>ColorModel</code> is suggested via the <code>RenderingHints</code>
38  * it is ignored.
39  *
40  * <p> The calculation pathway is selected to optimize performance and
41  * accuracy based on which <code>ColorSpace</code> subclasses are used to
42  * represent the source and destination color spaces.  The subclass
43  * categories are <code>ICC_ColorSpace</code>, <code>ColorSpaceJAI</code>,
44  * and generic <code>ColorSpace</code>, i.e., one which is not an instance
45  * of either the two aforementioned subclasses.  Note that in the Sun
46  * Microsystems implementation, an <code>ICC_ColorSpace</code> instance
47  * is what is returned by <code>ColorSpace.getInstance()</code>.
48  *
49  * <p> Integral data are assumed to occupy the full range of the respective
50  * data type; floating point data are assumed to be normalized to the range
51  * [0.0,1.0].
52  *
53  * <p> By default, the destination image bounds, data type, and number of
54  * bands are the same as those of the source image.
55  *
56  * <p><table border=1>
57  * <caption>Resource List</caption>
58  * <tr><th>Name</th>        <th>Value</th></tr>
59  * <tr><td>GlobalName</td>  <td>ColorConvert</td></tr>
60  * <tr><td>LocalName</td>   <td>ColorConvert</td></tr>
61  * <tr><td>Vendor</td>      <td>com.lightcrafts.media.jai</td></tr>
62  * <tr><td>Description</td> <td>Convert the color space of an image.<td></tr>
63  * <tr><td>DocURL</td>      <td>http://java.sun.com/products/java-media/jai/forDevelopers/jai-apidocs/javax/media/jai/operator/ColorConvertDescriptor.html</td></tr>
64  * <tr><td>Version</td>     <td>1.0</td></tr>
65  * <tr><td>arg0Desc</td>    <td>The destination <code>ColorModel</code>.</td></tr>
66  * </table></p>
67  *
68  * <p><table border=1>
69  * <caption>Parameter List</caption>
70  * <tr><th>Name</th>      <th>Class Type</th>
71  *                        <th>Default Value</th></tr>
72  * <tr><td>colorModel</td> <td>java.awt.image.ColorModel</td>
73  *                        <td>NO_PARAMETER_DEFAULT</td>
74  * </table></p>
75  *
76  * @see com.lightcrafts.mediax.jai.OperationDescriptor
77  * @see java.awt.color.ColorSpace
78  * @see java.awt.color.ICC_ColorSpace
79  * @see java.awt.image.ColorModel
80  * @see com.lightcrafts.mediax.jai.ColorSpaceJAI
81  * @see com.lightcrafts.mediax.jai.IHSColorSpace
82  */
83 public class ColorConvertDescriptor extends OperationDescriptorImpl {
84 
85     /**
86      * The resource strings that provide the general documentation
87      * and specify the parameter list for this operation.
88      */
89     private static final String[][] resources = {
90         {"GlobalName",  "ColorConvert"},
91         {"LocalName",   "ColorConvert"},
92         {"Vendor",      "com.lightcrafts.media.jai"},
93         {"Description", JaiI18N.getString("ColorConvertDescriptor0")},
94         {"DocURL",      "http://java.sun.com/products/java-media/jai/forDevelopers/jai-apidocs/javax/media/jai/operator/ColorConvertDescriptor.html"},
95         {"Version",     JaiI18N.getString("DescriptorVersion2")},
96         {"arg0Desc",    JaiI18N.getString("ColorConvertDescriptor1")}
97     };
98 
99     /**
100      * The parameter class list for this operation.
101      */
102     private static final Class[] paramClasses = {
103         java.awt.image.ColorModel.class
104     };
105 
106     /** The parameter name list for this operation. */
107     private static final String[] paramNames = {
108         "colorModel"
109     };
110 
111     /** The parameter default value list for this operation. */
112     private static final Object[] paramDefaults = {
113         NO_PARAMETER_DEFAULT
114     };
115 
116     /** Constructor. */
ColorConvertDescriptor()117     public ColorConvertDescriptor() {
118         super(resources, 1, paramClasses, paramNames, paramDefaults);
119     }
120 
121     /** Returns <code>true</code> since renderable operation is supported. */
isRenderableSupported()122     public boolean isRenderableSupported() {
123         return true;
124     }
125 
126 
127     /**
128      * Convert the color space of an image.
129      *
130      * <p>Creates a <code>ParameterBlockJAI</code> from all
131      * supplied arguments except <code>hints</code> and invokes
132      * {@link JAI#create(String,ParameterBlock,RenderingHints)}.
133      *
134      * @see JAI
135      * @see ParameterBlockJAI
136      * @see RenderedOp
137      *
138      * @param source0 <code>RenderedImage</code> source 0.
139      * @param colorModel The destination color space.
140      * @param hints The <code>RenderingHints</code> to use.
141      * May be <code>null</code>.
142      * @return The <code>RenderedOp</code> destination.
143      * @throws IllegalArgumentException if <code>source0</code> is <code>null</code>.
144      * @throws IllegalArgumentException if <code>colorModel</code> is <code>null</code>.
145      */
create(RenderedImage source0, ColorModel colorModel, RenderingHints hints)146     public static RenderedOp create(RenderedImage source0,
147                                     ColorModel colorModel,
148                                     RenderingHints hints)  {
149         ParameterBlockJAI pb =
150             new ParameterBlockJAI("ColorConvert",
151                                   RenderedRegistryMode.MODE_NAME);
152 
153         pb.setSource("source0", source0);
154 
155         pb.setParameter("colorModel", colorModel);
156 
157         return JAI.create("ColorConvert", pb, hints);
158     }
159 
160     /**
161      * Convert the color space of an image.
162      *
163      * <p>Creates a <code>ParameterBlockJAI</code> from all
164      * supplied arguments except <code>hints</code> and invokes
165      * {@link JAI#createRenderable(String,ParameterBlock,RenderingHints)}.
166      *
167      * @see JAI
168      * @see ParameterBlockJAI
169      * @see RenderableOp
170      *
171      * @param source0 <code>RenderableImage</code> source 0.
172      * @param colorModel The destination color space.
173      * @param hints The <code>RenderingHints</code> to use.
174      * May be <code>null</code>.
175      * @return The <code>RenderableOp</code> destination.
176      * @throws IllegalArgumentException if <code>source0</code> is <code>null</code>.
177      * @throws IllegalArgumentException if <code>colorModel</code> is <code>null</code>.
178      */
createRenderable(RenderableImage source0, ColorModel colorModel, RenderingHints hints)179     public static RenderableOp createRenderable(RenderableImage source0,
180                                                 ColorModel colorModel,
181                                                 RenderingHints hints)  {
182         ParameterBlockJAI pb =
183             new ParameterBlockJAI("ColorConvert",
184                                   RenderableRegistryMode.MODE_NAME);
185 
186         pb.setSource("source0", source0);
187 
188         pb.setParameter("colorModel", colorModel);
189 
190         return JAI.createRenderable("ColorConvert", pb, hints);
191     }
192 }
193