| 1 | /* |
| 2 | * $RCSfile: ThresholdBlurDescriptor.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 | * AreaOp based gaussian convolution with a cutoff threshold |
| 38 | * |
| 39 | * @see javax.media.jai.OperationDescriptor |
| 40 | * @see javax.media.jai.KernelJAI |
| 41 | */ |
| 42 | public class ThresholdBlurDescriptor extends OperationDescriptorImpl |
| 43 | { |
| 44 | |
| 45 | /** |
| 46 | * The parameter class types for the operation. |
| 47 | */ |
| 48 | private static final Class[] paramClasses = { |
| 49 | javax.media.jai.KernelJAI.class, Integer.class |
| 50 | }; |
| 51 | |
| 52 | /** |
| 53 | * The parameter default values for the operation. |
| 54 | */ |
| 55 | private static final Object[] paramDefaults = { |
| 56 | NO_PARAMETER_DEFAULT, new Integer(5) |
| 57 | }; |
| 58 | |
| 59 | /** |
| 60 | * The parameter names for the operation. |
| 61 | */ |
| 62 | private static final String[] paramNames = { |
| 63 | "kernel", "threshold" |
| 64 | }; |
| 65 | |
| 66 | /** |
| 67 | * The resource strings that provide the general documentation and specify the parameter list |
| 68 | * for a Convolve operation. |
| 69 | */ |
| 70 | private static final String[][] resources = { |
| 71 | {"GlobalName", "ThresholdBlur"}, |
| 72 | {"LocalName", "ThresholdBlur"}, |
| 73 | {"Vendor", "JWS"}, |
| 74 | {"Description", "ThresholdBlur"}, |
| 75 | {"DocURL", ""}, |
| 76 | {"Version", "1.0"}, |
| 77 | {"arg0Desc", "The Kernel to use"}, |
| 78 | {"arg1Desc", "The threshold"}, |
| 79 | }; |
| 80 | |
| 81 | /** |
| 82 | * Constructor. |
| 83 | */ |
| 84 | public ThresholdBlurDescriptor() { |
| 85 | super(resources, 1, paramClasses, paramNames, paramDefaults); |
| 86 | } |
| 87 | |
| 88 | /** |
| 89 | * Returns an array of <code>PropertyGenerators</code> implementing property inheritance for |
| 90 | * the operation. |
| 91 | * |
| 92 | * @return An array of property generators. |
| 93 | */ |
| 94 | public PropertyGenerator[] getPropertyGenerators() { |
| 95 | PropertyGenerator[] pg = new PropertyGenerator[1]; |
| 96 | |
| 97 | pg[0] = new AreaOpPropertyGenerator(); |
| 98 | return pg; |
| 99 | } |
| 100 | |
| 101 | |
| 102 | /** |
| 103 | * Performs kernel-based threshold blur on an image. |
| 104 | * |
| 105 | * @return The <code>RenderedOp</code> destination. |
| 106 | * @throws IllegalArgumentException if <code>source0</code> is <code>null</code>. |
| 107 | * @throws IllegalArgumentException if <code>kernel</code> is <code>null</code>. |
| 108 | * @param source0 <code>RenderedImage</code> source 0. |
| 109 | * @param kernel The convolution kernel. |
| 110 | * @param threshold The limit to use. |
| 111 | * @param hints The <code>RenderingHints</code> to use. May be <code>null</code> |
| 112 | * . |
| 113 | */ |
| 114 | public static RenderedOp create(RenderedImage source0, |
| 115 | KernelJAI kernel, |
| 116 | int threshold, |
| 117 | RenderingHints hints) { |
| 118 | ParameterBlockJAI pb = |
| 119 | new ParameterBlockJAI("ThresholdBlur", |
| 120 | RenderedRegistryMode.MODE_NAME); |
| 121 | |
| 122 | pb.setSource("source0", source0); |
| 123 | |
| 124 | pb.setParameter("kernel", kernel); |
| 125 | pb.setParameter("threshold", threshold); |
| 126 | |
| 127 | return JAI.create("ThresholdBlur", pb, hints); |
| 128 | } |
| 129 | } |