01: /*
02: * $RCSfile: MlibUnsharpMaskRIF.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.2 $
09: * $Date: 2005/08/15 22:17:03 $
10: * $State: Exp $
11: */
12: package com.sun.media.jai.mlib;
13:
14: import com.sun.media.jai.opimage.RIFUtil;
15: import com.sun.media.jai.util.ImageUtil;
16: import java.awt.RenderingHints;
17: import java.awt.image.RenderedImage;
18: import java.awt.image.renderable.ParameterBlock;
19: import java.awt.image.renderable.RenderedImageFactory;
20: import javax.media.jai.BorderExtender;
21: import javax.media.jai.ImageLayout;
22: import javax.media.jai.KernelJAI;
23: import java.util.Map;
24:
25: /**
26: * A <code>RIF</code> supporting the "Convolve" operation in the
27: * rendered image mode using MediaLib.
28: *
29: * @see javax.media.jai.operator.ConvolveDescriptor
30: * @see MlibConvolveOpImage
31: */
32: public class MlibUnsharpMaskRIF implements RenderedImageFactory {
33:
34: /** Constructor. */
35: public MlibUnsharpMaskRIF() {
36: }
37:
38: /**
39: * Creates a new instance of <code>MlibConvolveOpImage</code> in
40: * the rendered image mode.
41: *
42: * @param args The source image and convolution kernel.
43: * @param hints May contain rendering hints and destination image layout.
44: */
45: public RenderedImage create(ParameterBlock args,
46: RenderingHints hints) {
47:
48: /* Get ImageLayout and TileCache from RenderingHints. */
49: ImageLayout layout = RIFUtil.getImageLayoutHint(hints);
50:
51: if (!MediaLibAccessor.isMediaLibCompatible(args, layout)
52: || !MediaLibAccessor.hasSameNumBands(args, layout)) {
53: return null;
54: }
55:
56: /* Get BorderExtender from hints if any. */
57: BorderExtender extender = RIFUtil.getBorderExtenderHint(hints);
58:
59: RenderedImage source = args.getRenderedSource(0);
60:
61: // map the input kernel + gain factor to an equivalent
62: // convolution kernel and then do a normal convolve.
63: KernelJAI unRotatedKernel = ImageUtil
64: .getUnsharpMaskEquivalentKernel((KernelJAI) args
65: .getObjectParameter(0), args
66: .getFloatParameter(1));
67:
68: KernelJAI kJAI = unRotatedKernel.getRotatedKernel();
69:
70: int kWidth = kJAI.getWidth();
71: int kHeight = kJAI.getHeight();
72:
73: /* mediaLib does not handle kernels with either dimension < 2. */
74: if (kWidth < 2 || kHeight < 2) {
75: return null;
76: }
77:
78: if (kJAI.isSeparable() && kWidth >= 3 && kWidth <= 7
79: && kWidth == kHeight) {
80: return new MlibSeparableConvolveOpImage(source, extender,
81: hints, layout, kJAI);
82: } else if ((kWidth == 3 && kHeight == 3)
83: || (kWidth == 5 && kHeight == 5)) {
84: return new MlibConvolveNxNOpImage(source, extender, hints,
85: layout, kJAI);
86: } else {
87: return new MlibConvolveOpImage(source, extender, hints,
88: layout, kJAI);
89: }
90: }
91: }
|