1 /* 2 * $RCSfile: ErrorDiffusionDescriptor.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:35 $ 10 * $State: Exp $ 11 */ 12 package com.lightcrafts.mediax.jai.operator; 13 import java.awt.RenderingHints; 14 import java.awt.image.RenderedImage; 15 import java.awt.image.renderable.ParameterBlock; 16 import com.lightcrafts.mediax.jai.JAI; 17 import com.lightcrafts.mediax.jai.KernelJAI; 18 import com.lightcrafts.mediax.jai.LookupTableJAI; 19 import com.lightcrafts.mediax.jai.OperationDescriptorImpl; 20 import com.lightcrafts.mediax.jai.ParameterBlockJAI; 21 import com.lightcrafts.mediax.jai.RenderedOp; 22 import com.lightcrafts.mediax.jai.registry.RenderedRegistryMode; 23 24 /** 25 * An <code>OperationDescriptor</code> describing the "ErrorDiffusion" 26 * operation. 27 * 28 * <p> The "ErrorDiffusion" operation performs color quantization by 29 * finding the nearest color to each pixel in a supplied color map 30 * and "diffusing" the color quantization error below and to the right 31 * of the pixel. 32 * 33 * <p><table border=1> 34 * <caption>Resource List</caption> 35 * <tr><th>Name</th> <th>Value</th></tr> 36 * <tr><td>GlobalName</td> <td>ErrorDiffusion</td></tr> 37 * <tr><td>LocalName</td> <td>ErrorDiffusion</td></tr> 38 * <tr><td>Vendor</td> <td>com.lightcrafts.media.jai</td></tr> 39 * <tr><td>Description</td> <td>Performs error diffusion color quantization 40 * using a specified color map and 41 * error filter.</td></tr> 42 * <tr><td>DocURL</td> <td>http://java.sun.com/products/java-media/jai/forDevelopers/jai-apidocs/javax/media/jai/operator/ErrorDiffusionDescriptor.html</td></tr> 43 * <tr><td>Version</td> <td>1.0</td></tr> 44 * <tr><td>arg0Desc</td> <td>The color map.</td></tr> 45 * <tr><td>arg1Desc</td> <td>The error filter kernel.</td></tr> 46 * </table></p> 47 * 48 * <p><table border=1> 49 * <caption>Parameter List</caption> 50 * <tr><th>Name</th> <th>Class Type</th> 51 * <th>Default Value</th></tr> 52 * <tr><td>colorMap</td> <td>com.lightcrafts.mediax.jai.LookupTableJAI</td> 53 * <td>NO_PARAMETER_DEFAULT</td> 54 * <tr><td>errorKernel</td> <td>com.lightcrafts.mediax.jai.KernelJAI</td> 55 * <td>com.lightcrafts.mediax.jai.KernelJAI.ERROR_FILTER_FLOYD_STEINBERG</td> 56 * </table></p> 57 * 58 * @see com.lightcrafts.mediax.jai.LookupTableJAI 59 * @see com.lightcrafts.mediax.jai.KernelJAI 60 * @see com.lightcrafts.mediax.jai.ColorCube 61 * @see com.lightcrafts.mediax.jai.OperationDescriptor 62 */ 63 public class ErrorDiffusionDescriptor extends OperationDescriptorImpl { 64 65 /** 66 * The resource strings that provide the general documentation and 67 * specify the parameter list for the "ErrorDiffusion" operation. 68 */ 69 private static final String[][] resources = { 70 {"GlobalName", "ErrorDiffusion"}, 71 {"LocalName", "ErrorDiffusion"}, 72 {"Vendor", "com.lightcrafts.media.jai"}, 73 {"Description", JaiI18N.getString("ErrorDiffusionDescriptor0")}, 74 {"DocURL", "http://java.sun.com/products/java-media/jai/forDevelopers/jai-apidocs/javax/media/jai/operator/ErrorDiffusionDescriptor.html"}, 75 {"Version", JaiI18N.getString("DescriptorVersion")}, 76 {"arg0Desc", JaiI18N.getString("ErrorDiffusionDescriptor1")}, 77 {"arg1Desc", JaiI18N.getString("ErrorDiffusionDescriptor2")} 78 }; 79 80 /** The parameter names for the "ErrorDiffusion" operation. */ 81 private static final String[] paramNames = { 82 "colorMap", "errorKernel" 83 }; 84 85 /** The parameter class types for the "ErrorDiffusion" operation. */ 86 private static final Class[] paramClasses = { 87 com.lightcrafts.mediax.jai.LookupTableJAI.class, 88 com.lightcrafts.mediax.jai.KernelJAI.class 89 }; 90 91 /** The parameter default values for the "ErrorDiffusion" operation. */ 92 private static final Object[] paramDefaults = { 93 NO_PARAMETER_DEFAULT, 94 // Default error filter to Floyd-Steinberg. 95 KernelJAI.ERROR_FILTER_FLOYD_STEINBERG 96 }; 97 98 /** Constructor. */ ErrorDiffusionDescriptor()99 public ErrorDiffusionDescriptor() { 100 super(resources, 1, paramClasses, paramNames, paramDefaults); 101 } 102 103 104 /** 105 * Performs error diffusion color quantization using a specified color map and error filter. 106 * 107 * <p>Creates a <code>ParameterBlockJAI</code> from all 108 * supplied arguments except <code>hints</code> and invokes 109 * {@link JAI#create(String,ParameterBlock,RenderingHints)}. 110 * 111 * @see JAI 112 * @see ParameterBlockJAI 113 * @see RenderedOp 114 * 115 * @param source0 <code>RenderedImage</code> source 0. 116 * @param colorMap The color map. 117 * @param errorKernel The error filter kernel. 118 * May be <code>null</code>. 119 * @param hints The <code>RenderingHints</code> to use. 120 * May be <code>null</code>. 121 * @return The <code>RenderedOp</code> destination. 122 * @throws IllegalArgumentException if <code>source0</code> is <code>null</code>. 123 * @throws IllegalArgumentException if <code>colorMap</code> is <code>null</code>. 124 */ create(RenderedImage source0, LookupTableJAI colorMap, KernelJAI errorKernel, RenderingHints hints)125 public static RenderedOp create(RenderedImage source0, 126 LookupTableJAI colorMap, 127 KernelJAI errorKernel, 128 RenderingHints hints) { 129 ParameterBlockJAI pb = 130 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 } 141