01: /*
02: * $RCSfile: MlibBinarizeRIF.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:51 $
10: * $State: Exp $
11: */
12: package com.sun.media.jai.mlib;
13:
14: import java.awt.RenderingHints;
15: import java.awt.geom.AffineTransform;
16: import java.awt.image.DataBuffer;
17: import java.awt.image.MultiPixelPackedSampleModel;
18: import java.awt.image.RenderedImage;
19: import java.awt.image.SampleModel;
20: import java.awt.image.renderable.RenderedImageFactory;
21: import java.awt.image.renderable.ParameterBlock;
22: import javax.media.jai.BorderExtender;
23: import javax.media.jai.ImageLayout;
24: import java.util.Map;
25: import com.sun.media.jai.opimage.RIFUtil;
26:
27: /**
28: * A <code>RIF</code> supporting the "Binarize" operation in the
29: * rendered image mode using MediaLib.
30: *
31: * @see javax.media.jai.operator.BinarizeDescriptor
32: */
33: public class MlibBinarizeRIF implements RenderedImageFactory {
34:
35: /** Constructor. */
36: public MlibBinarizeRIF() {
37: }
38:
39: /**
40: * Creates a new instance of <code>MlibBinarizeOpImage</code> in
41: * the rendered image mode.
42: *
43: * @param args The source image, thresh value
44: * @param hints May contain rendering hints and destination image layout.
45: */
46: public RenderedImage create(ParameterBlock args,
47: RenderingHints hints) {
48: // Get the source and its SampleModel.
49: RenderedImage source = args.getRenderedSource(0);
50: SampleModel sm = source.getSampleModel();
51:
52: // Check that the source is single-banded and mediaLib compatible.
53: // Ignore the layout because if it doesn't specify a bilevel image
54: // then MlibBinarizeOpImage will revise it.
55: if (!MediaLibAccessor.isMediaLibCompatible(args)
56: || sm.getNumBands() > 1) {
57: return null;
58: }
59:
60: // Get the threshold value.
61: double thresh = args.getDoubleParameter(0);
62:
63: // java set all 0's or 1's fast
64: if ((thresh > 255 || thresh <= 0)
65: && sm.getDataType() == DataBuffer.TYPE_BYTE
66: || (thresh > Short.MAX_VALUE || thresh <= 0)
67: && sm.getDataType() == DataBuffer.TYPE_SHORT
68: || (thresh > Integer.MAX_VALUE || thresh <= 0)
69: && sm.getDataType() == DataBuffer.TYPE_INT)
70: return null;
71:
72: // Get ImageLayout from RenderingHints.
73: ImageLayout layout = RIFUtil.getImageLayoutHint(hints);
74:
75: return new MlibBinarizeOpImage(source, layout, hints, thresh);
76: }
77: }
|