01: /*
02: * $RCSfile: UnsharpMaskRIF.java,v $
03: *
04: * Copyright (c) 2005 Sun Microsystems, Inc. All rights reserved.
05: *
06: * Use is subject to license terms.
07: *
08: * $Revision: 1.1 $
09: * $Date: 2005/02/11 04:56:46 $
10: * $State: Exp $
11: */
12: package com.sun.media.jai.opimage;
13:
14: import com.sun.media.jai.util.ImageUtil;
15: import java.awt.RenderingHints;
16: import java.awt.image.DataBuffer;
17: import java.awt.image.RenderedImage;
18: import java.awt.image.SampleModel;
19: import java.awt.image.renderable.ParameterBlock;
20: import java.awt.image.renderable.RenderedImageFactory;
21: import javax.media.jai.BorderExtender;
22: import javax.media.jai.ImageLayout;
23: import javax.media.jai.KernelJAI;
24: import java.util.Map;
25:
26: /**
27: * @see UnsharpMaskOpImage
28: */
29: public class UnsharpMaskRIF implements RenderedImageFactory {
30:
31: /** Constructor. */
32: public UnsharpMaskRIF() {
33: }
34:
35: /**
36: * Create a new instance of UnsharpMaskOpImage in the rendered layer.
37: * This method satisfies the implementation of RIF.
38: *
39: * @param paramBlock The source image, the unsharp mask kernel and
40: * the gain factor.
41: */
42: public RenderedImage create(ParameterBlock paramBlock,
43: RenderingHints renderHints) {
44: // Get ImageLayout from renderHints if any.
45: ImageLayout layout = RIFUtil.getImageLayoutHint(renderHints);
46:
47: // Get BorderExtender from renderHints if any.
48: BorderExtender extender = RIFUtil
49: .getBorderExtenderHint(renderHints);
50:
51: // map the input kernel + gain factor to an equivalent
52: // convolution kernel and then do a normal convolve.
53: KernelJAI unRotatedKernel = ImageUtil
54: .getUnsharpMaskEquivalentKernel((KernelJAI) paramBlock
55: .getObjectParameter(0), paramBlock
56: .getFloatParameter(1));
57:
58: KernelJAI kJAI = unRotatedKernel.getRotatedKernel();
59:
60: RenderedImage source = paramBlock.getRenderedSource(0);
61: int dataType = source.getSampleModel().getDataType();
62:
63: boolean dataTypeOk = (dataType == DataBuffer.TYPE_BYTE
64: || dataType == DataBuffer.TYPE_SHORT || dataType == DataBuffer.TYPE_INT);
65:
66: if ((kJAI.getWidth() == 3) && (kJAI.getHeight() == 3)
67: && (kJAI.getXOrigin() == 1) && (kJAI.getYOrigin() == 1)
68: && dataTypeOk) {
69: return new Convolve3x3OpImage(source, extender,
70: renderHints, layout, kJAI);
71: } else if (kJAI.isSeparable()) {
72: return new SeparableConvolveOpImage(source, extender,
73: renderHints, layout, kJAI);
74:
75: } else {
76: return new ConvolveOpImage(source, extender, renderHints,
77: layout, kJAI);
78: }
79: }
80: }
|