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