01: /*
02: * $RCSfile: DilateRIF.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:23 $
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.MultiPixelPackedSampleModel;
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 DilateOpImage
28: */
29: public class DilateRIF implements RenderedImageFactory {
30:
31: /** Constructor. */
32: public DilateRIF() {
33: }
34:
35: /**
36: * Create a new instance of DilateOpImage in the rendered layer.
37: * This method satisfies the implementation of RIF.
38: *
39: * @param paramBlock The source image and the dilation kernel.
40: */
41: public RenderedImage create(ParameterBlock paramBlock,
42: RenderingHints renderHints) {
43: // Get ImageLayout from renderHints if any.
44: ImageLayout layout = RIFUtil.getImageLayoutHint(renderHints);
45:
46: // Get BorderExtender from renderHints if any.
47: BorderExtender extender = RIFUtil
48: .getBorderExtenderHint(renderHints);
49:
50: KernelJAI unRotatedKernel = (KernelJAI) paramBlock
51: .getObjectParameter(0);
52: KernelJAI kJAI = unRotatedKernel.getRotatedKernel();
53:
54: RenderedImage source = paramBlock.getRenderedSource(0);
55: SampleModel sm = source.getSampleModel();
56:
57: // check dataType and binary
58: int dataType = sm.getDataType();
59:
60: boolean isBinary = (sm instanceof MultiPixelPackedSampleModel)
61: && (sm.getSampleSize(0) == 1)
62: && (dataType == DataBuffer.TYPE_BYTE
63: || dataType == DataBuffer.TYPE_USHORT || dataType == DataBuffer.TYPE_INT);
64:
65: // possible speed up later: 3x3 with table lookup
66: if (isBinary) {
67:
68: return new DilateBinaryOpImage(source, extender,
69: renderHints, layout, kJAI);
70: } else {
71: return new DilateOpImage(source, extender, renderHints,
72: layout, kJAI);
73: }
74: }
75: }
|