| 1 | /* |
| 2 | * $RCSfile: ThresholdBlurRIF.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 java.awt.RenderingHints; |
| 26 | import java.awt.image.RenderedImage; |
| 27 | import java.awt.image.renderable.ParameterBlock; |
| 28 | import java.awt.image.renderable.RenderedImageFactory; |
| 29 | import javax.media.jai.BorderExtender; |
| 30 | import javax.media.jai.ImageLayout; |
| 31 | import javax.media.jai.KernelJAI; |
| 32 | import javax.media.jai.JAI; |
| 33 | |
| 34 | /** |
| 35 | * @see ThresholdBlurRIF |
| 36 | */ |
| 37 | public class ThresholdBlurRIF implements RenderedImageFactory |
| 38 | { |
| 39 | |
| 40 | /** |
| 41 | * Constructor. |
| 42 | */ |
| 43 | public ThresholdBlurRIF() { |
| 44 | super(); |
| 45 | } |
| 46 | |
| 47 | /** |
| 48 | * Create a new instance of ThresholdBlurOpImage in the rendered layer. This method satisfies |
| 49 | * the implementation of RIF. |
| 50 | * |
| 51 | * @param paramBlock The source image and the convolution kernel. |
| 52 | */ |
| 53 | public RenderedImage create(ParameterBlock paramBlock, |
| 54 | RenderingHints renderHints) { |
| 55 | // Get ImageLayout from renderHints if any. |
| 56 | ImageLayout layout = null; |
| 57 | |
| 58 | if (renderHints != null) { |
| 59 | layout = (ImageLayout) renderHints.get(JAI.KEY_IMAGE_LAYOUT); |
| 60 | } |
| 61 | |
| 62 | // Get BorderExtender from renderHints if any. |
| 63 | BorderExtender extender = null; |
| 64 | |
| 65 | if (renderHints != null) { |
| 66 | extender = (BorderExtender) renderHints.get(JAI.KEY_BORDER_EXTENDER); |
| 67 | } |
| 68 | |
| 69 | KernelJAI unRotatedKernel = |
| 70 | (KernelJAI) paramBlock.getObjectParameter(0); |
| 71 | KernelJAI kJAI = unRotatedKernel.getRotatedKernel(); |
| 72 | int threshold = paramBlock.getIntParameter(1); |
| 73 | |
| 74 | return new ThresholdBlurOpImage(paramBlock.getRenderedSource(0), |
| 75 | extender, |
| 76 | renderHints, |
| 77 | layout, |
| 78 | kJAI, threshold); |
| 79 | } |
| 80 | } |