01: /*
02: * $RCSfile: ConvolveRIF.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:20 $
10: * $State: Exp $
11: */
12: package com.sun.media.jai.opimage;
13:
14: import java.awt.RenderingHints;
15: import java.awt.image.DataBuffer;
16: import java.awt.image.RenderedImage;
17: import java.awt.image.SampleModel;
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: * @see ConvolveOpImage
27: */
28: public class ConvolveRIF implements RenderedImageFactory {
29:
30: /** Constructor. */
31: public ConvolveRIF() {
32: }
33:
34: /**
35: * Create a new instance of ConvolveOpImage in the rendered layer.
36: * This method satisfies the implementation of RIF.
37: *
38: * @param paramBlock The source image and the convolution kernel.
39: */
40: public RenderedImage create(ParameterBlock paramBlock,
41: RenderingHints renderHints) {
42: // Get ImageLayout from renderHints if any.
43: ImageLayout layout = RIFUtil.getImageLayoutHint(renderHints);
44:
45: // Get BorderExtender from renderHints if any.
46: BorderExtender extender = RIFUtil
47: .getBorderExtenderHint(renderHints);
48:
49: KernelJAI unRotatedKernel = (KernelJAI) paramBlock
50: .getObjectParameter(0);
51: KernelJAI kJAI = unRotatedKernel.getRotatedKernel();
52:
53: int dataType = paramBlock.getRenderedSource(0).getSampleModel()
54: .getDataType();
55: boolean dataTypeOk = (dataType == DataBuffer.TYPE_BYTE
56: || dataType == DataBuffer.TYPE_SHORT || dataType == DataBuffer.TYPE_INT);
57:
58: if (kJAI.getWidth() == 3 && kJAI.getHeight() == 3
59: && kJAI.getXOrigin() == 1 && kJAI.getYOrigin() == 1
60: && dataTypeOk) {
61: return new Convolve3x3OpImage(paramBlock
62: .getRenderedSource(0), extender, renderHints,
63: layout, kJAI);
64: } else if (kJAI.isSeparable()) {
65: return new SeparableConvolveOpImage(paramBlock
66: .getRenderedSource(0), extender, renderHints,
67: layout, kJAI);
68:
69: } else {
70: return new ConvolveOpImage(paramBlock.getRenderedSource(0),
71: extender, renderHints, layout, kJAI);
72: }
73: }
74: }
|