| 1 | /* |
| 2 | * $RCSfile: ThresholdDifferenceBlurDescriptor.java $ |
| 3 | * |
| 4 | * Copyright (c) 2007 Jeremiah Spaulding |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License as published by |
| 8 | * the Free Software Foundation; either version 2 of the License, or |
| 9 | * (at your option) any later version. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * GNU General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License |
| 17 | * along with this program; if not, write to the Free Software |
| 18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 19 | * |
| 20 | * $Revision: 1.0 $ |
| 21 | * $Date: 2007/07/15 00:00:00 $ |
| 22 | */ |
| 23 | package net.sf.jomic.tools; |
| 24 | |
| 25 | import com.sun.media.jai.util.AreaOpPropertyGenerator; |
| 26 | import java.awt.RenderingHints; |
| 27 | import java.awt.image.RenderedImage; |
| 28 | import javax.media.jai.JAI; |
| 29 | import javax.media.jai.KernelJAI; |
| 30 | import javax.media.jai.OperationDescriptorImpl; |
| 31 | import javax.media.jai.ParameterBlockJAI; |
| 32 | import javax.media.jai.PropertyGenerator; |
| 33 | import javax.media.jai.RenderedOp; |
| 34 | import javax.media.jai.registry.RenderedRegistryMode; |
| 35 | |
| 36 | /** |
| 37 | * An <code>OperationDescriptor</code> describing the "ThresholdBlur" operation. |
| 38 | * |
| 39 | * @see Convolve |
| 40 | */ |
| 41 | public class ThresholdDifferenceBlurDescriptor extends OperationDescriptorImpl |
| 42 | { |
| 43 | |
| 44 | /** |
| 45 | * The parameter class types for the ThresholdDifferenceBlur operation. |
| 46 | */ |
| 47 | private static final Class[] paramClasses = { |
| 48 | javax.media.jai.KernelJAI.class, Integer.class |
| 49 | }; |
| 50 | |
| 51 | /** |
| 52 | * The parameter default values for the ThresholdDifferenceBlur operation. |
| 53 | */ |
| 54 | private static final Object[] paramDefaults = { |
| 55 | NO_PARAMETER_DEFAULT, new Integer(5) |
| 56 | }; |
| 57 | |
| 58 | /** |
| 59 | * The parameter names for the ThresholdDifferenceBlur operation. |
| 60 | */ |
| 61 | private static final String[] paramNames = { |
| 62 | "kernel", "threshold" |
| 63 | }; |
| 64 | |
| 65 | /** |
| 66 | * The resource strings that provide the general documentation and specify the parameter list |
| 67 | * for a ThresholdDifferenceBlur operation. |
| 68 | */ |
| 69 | private static final String[][] resources = { |
| 70 | {"GlobalName", "ThresholdDifferenceBlur"}, |
| 71 | {"LocalName", "ThresholdDifferenceBlur"}, |
| 72 | {"Vendor", "JWS"}, |
| 73 | {"Description", "ThresholdDifferenceBlur"}, |
| 74 | {"DocURL", ""}, |
| 75 | {"Version", "1.0"}, |
| 76 | {"arg0Desc", "The Kernel to use"}, |
| 77 | {"arg1Desc", "The threshold"}, |
| 78 | }; |
| 79 | |
| 80 | /** |
| 81 | * Constructor. |
| 82 | */ |
| 83 | public ThresholdDifferenceBlurDescriptor() { |
| 84 | super(resources, 1, paramClasses, paramNames, paramDefaults); |
| 85 | } |
| 86 | |
| 87 | /** |
| 88 | * Returns an array of <code>PropertyGenerators</code> implementing property inheritance for |
| 89 | * the "ThresholdDifferenceBlur" operation. |
| 90 | * |
| 91 | * @return An array of property generators. |
| 92 | */ |
| 93 | public PropertyGenerator[] getPropertyGenerators() { |
| 94 | PropertyGenerator[] pg = new PropertyGenerator[1]; |
| 95 | |
| 96 | pg[0] = new AreaOpPropertyGenerator(); |
| 97 | return pg; |
| 98 | } |
| 99 | |
| 100 | |
| 101 | /** |
| 102 | * Performs kernel-based ThresholdDifferenceBlur on an image. |
| 103 | * |
| 104 | * @return The <code>RenderedOp</code> destination. |
| 105 | * @throws IllegalArgumentException if <code>source0</code> is <code>null</code>. |
| 106 | * @throws IllegalArgumentException if <code>kernel</code> is <code>null</code>. |
| 107 | * @param source0 <code>RenderedImage</code> source 0. |
| 108 | * @param kernel The convolution kernel. |
| 109 | * @param threshold The threshold to use. |
| 110 | * @param hints The <code>RenderingHints</code> to use. May be <code>null</code> |
| 111 | * . |
| 112 | */ |
| 113 | public static RenderedOp create(RenderedImage source0, |
| 114 | KernelJAI kernel, |
| 115 | int threshold, |
| 116 | RenderingHints hints) { |
| 117 | ParameterBlockJAI pb = |
| 118 | new ParameterBlockJAI("ThresholdDifferenceBlur", |
| 119 | RenderedRegistryMode.MODE_NAME); |
| 120 | |
| 121 | pb.setSource("source0", source0); |
| 122 | |
| 123 | pb.setParameter("kernel", kernel); |
| 124 | pb.setParameter("threshold", threshold); |
| 125 | |
| 126 | return JAI.create("ThresholdDifferenceBlur", pb, hints); |
| 127 | } |
| 128 | } |