001: /*
002: * $RCSfile: ErrorDiffusionDescriptor.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:35 $
010: * $State: Exp $
011: */
012: package javax.media.jai.operator;
013:
014: import java.awt.RenderingHints;
015: import java.awt.image.RenderedImage;
016: import java.awt.image.renderable.ParameterBlock;
017: import javax.media.jai.JAI;
018: import javax.media.jai.KernelJAI;
019: import javax.media.jai.LookupTableJAI;
020: import javax.media.jai.OperationDescriptorImpl;
021: import javax.media.jai.ParameterBlockJAI;
022: import javax.media.jai.ROI;
023: import javax.media.jai.RenderedOp;
024: import javax.media.jai.registry.RenderedRegistryMode;
025:
026: /**
027: * An <code>OperationDescriptor</code> describing the "ErrorDiffusion"
028: * operation.
029: *
030: * <p> The "ErrorDiffusion" operation performs color quantization by
031: * finding the nearest color to each pixel in a supplied color map
032: * and "diffusing" the color quantization error below and to the right
033: * of the pixel.
034: *
035: * <p><table border=1>
036: * <caption>Resource List</caption>
037: * <tr><th>Name</th> <th>Value</th></tr>
038: * <tr><td>GlobalName</td> <td>ErrorDiffusion</td></tr>
039: * <tr><td>LocalName</td> <td>ErrorDiffusion</td></tr>
040: * <tr><td>Vendor</td> <td>com.sun.media.jai</td></tr>
041: * <tr><td>Description</td> <td>Performs error diffusion color quantization
042: * using a specified color map and
043: * error filter.</td></tr>
044: * <tr><td>DocURL</td> <td>http://java.sun.com/products/java-media/jai/forDevelopers/jai-apidocs/javax/media/jai/operator/ErrorDiffusionDescriptor.html</td></tr>
045: * <tr><td>Version</td> <td>1.0</td></tr>
046: * <tr><td>arg0Desc</td> <td>The color map.</td></tr>
047: * <tr><td>arg1Desc</td> <td>The error filter kernel.</td></tr>
048: * </table></p>
049: *
050: * <p><table border=1>
051: * <caption>Parameter List</caption>
052: * <tr><th>Name</th> <th>Class Type</th>
053: * <th>Default Value</th></tr>
054: * <tr><td>colorMap</td> <td>javax.media.jai.LookupTableJAI</td>
055: * <td>NO_PARAMETER_DEFAULT</td>
056: * <tr><td>errorKernel</td> <td>javax.media.jai.KernelJAI</td>
057: * <td>javax.media.jai.KernelJAI.ERROR_FILTER_FLOYD_STEINBERG</td>
058: * </table></p>
059: *
060: * @see javax.media.jai.LookupTableJAI
061: * @see javax.media.jai.KernelJAI
062: * @see javax.media.jai.ColorCube
063: * @see javax.media.jai.OperationDescriptor
064: */
065: public class ErrorDiffusionDescriptor extends OperationDescriptorImpl {
066:
067: /**
068: * The resource strings that provide the general documentation and
069: * specify the parameter list for the "ErrorDiffusion" operation.
070: */
071: private static final String[][] resources = {
072: { "GlobalName", "ErrorDiffusion" },
073: { "LocalName", "ErrorDiffusion" },
074: { "Vendor", "com.sun.media.jai" },
075: { "Description",
076: JaiI18N.getString("ErrorDiffusionDescriptor0") },
077: {
078: "DocURL",
079: "http://java.sun.com/products/java-media/jai/forDevelopers/jai-apidocs/javax/media/jai/operator/ErrorDiffusionDescriptor.html" },
080: { "Version", JaiI18N.getString("DescriptorVersion") },
081: { "arg0Desc",
082: JaiI18N.getString("ErrorDiffusionDescriptor1") },
083: { "arg1Desc",
084: JaiI18N.getString("ErrorDiffusionDescriptor2") } };
085:
086: /** The parameter names for the "ErrorDiffusion" operation. */
087: private static final String[] paramNames = { "colorMap",
088: "errorKernel" };
089:
090: /** The parameter class types for the "ErrorDiffusion" operation. */
091: private static final Class[] paramClasses = {
092: javax.media.jai.LookupTableJAI.class,
093: javax.media.jai.KernelJAI.class };
094:
095: /** The parameter default values for the "ErrorDiffusion" operation. */
096: private static final Object[] paramDefaults = {
097: NO_PARAMETER_DEFAULT,
098: // Default error filter to Floyd-Steinberg.
099: KernelJAI.ERROR_FILTER_FLOYD_STEINBERG };
100:
101: /** Constructor. */
102: public ErrorDiffusionDescriptor() {
103: super (resources, 1, paramClasses, paramNames, paramDefaults);
104: }
105:
106: /**
107: * Performs error diffusion color quantization using a specified color map and error filter.
108: *
109: * <p>Creates a <code>ParameterBlockJAI</code> from all
110: * supplied arguments except <code>hints</code> and invokes
111: * {@link JAI#create(String,ParameterBlock,RenderingHints)}.
112: *
113: * @see JAI
114: * @see ParameterBlockJAI
115: * @see RenderedOp
116: *
117: * @param source0 <code>RenderedImage</code> source 0.
118: * @param colorMap The color map.
119: * @param errorKernel The error filter kernel.
120: * May be <code>null</code>.
121: * @param hints The <code>RenderingHints</code> to use.
122: * May be <code>null</code>.
123: * @return The <code>RenderedOp</code> destination.
124: * @throws IllegalArgumentException if <code>source0</code> is <code>null</code>.
125: * @throws IllegalArgumentException if <code>colorMap</code> is <code>null</code>.
126: */
127: public static RenderedOp create(RenderedImage source0,
128: LookupTableJAI colorMap, KernelJAI errorKernel,
129: RenderingHints hints) {
130: ParameterBlockJAI pb = new ParameterBlockJAI("ErrorDiffusion",
131: RenderedRegistryMode.MODE_NAME);
132:
133: pb.setSource("source0", source0);
134:
135: pb.setParameter("colorMap", colorMap);
136: pb.setParameter("errorKernel", errorKernel);
137:
138: return JAI.create("ErrorDiffusion", pb, hints);
139: }
140: }
|