01: /*
02: * $RCSfile: MlibGradientRIF.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:55:57 $
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 "Gradient" operation in the
26: * rendered image mode using MediaLib.
27: *
28: * @see javax.media.jai.operator.GradientDescriptor
29: * @see MlibGradientOpImage
30: */
31: public class MlibGradientRIF implements RenderedImageFactory {
32:
33: /** Constructor. */
34: public MlibGradientRIF() {
35: }
36:
37: /**
38: * Creates a new instance of <code>MlibGradientOpImage</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: /*
60: * Get the Horizontal & Vertical kernels.
61: * At this point these kernels should have the same width & height
62: */
63: KernelJAI kern_h = (KernelJAI) args.getObjectParameter(0);
64: KernelJAI kern_v = (KernelJAI) args.getObjectParameter(1);
65:
66: /* Get the width & height of the kernels. */
67: int kWidth = kern_h.getWidth();
68: int kHeight = kern_v.getHeight();
69:
70: /* Check and see if the operation is a Sobel. */
71: float khdata[], kvdata[];
72: khdata = kern_h.getKernelData();
73: kvdata = kern_v.getKernelData();
74: if ((khdata[0] == -1.0F && khdata[1] == -2.0F
75: && khdata[2] == -1.0F && khdata[3] == 0.0F
76: && khdata[4] == 0.0F && khdata[5] == 0.0F
77: && khdata[6] == 1.0F && khdata[7] == 2.0F && khdata[8] == 1.0F)
78: && (kvdata[0] == -1.0F && kvdata[1] == 0.0F
79: && kvdata[2] == 1.0F && kvdata[3] == -2.0F
80: && kvdata[4] == 0.0F && kvdata[5] == 2.0F
81: && kvdata[6] == -1.0F && kvdata[7] == 0.0F && kvdata[8] == 1.0F)
82: && kWidth == 3 && kHeight == 3) {
83: return new MlibSobelOpImage(source, extender, hints,
84: layout, kern_h);
85: }
86:
87: /* Call the Generic version. */
88: return new MlibGradientOpImage(source, extender, hints, layout,
89: kern_h, kern_v);
90: }
91: }
|