01: /*
02: * $RCSfile: MlibSubsampleBinaryToGrayRIF.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:06 $
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 javax.media.jai.Interpolation;
25: import javax.media.jai.InterpolationNearest;
26: import java.util.Map;
27: import com.sun.media.jai.opimage.CopyOpImage;
28: import com.sun.media.jai.opimage.RIFUtil;
29: import com.sun.media.jai.util.ImageUtil;
30:
31: /**
32: * A <code>RIF</code> supporting the "SubsampleBinaryToGray" operation in the
33: * rendered image mode using MediaLib.
34: *
35: * @see javax.media.jai.operator.SubsampleBinaryToGrayDescriptor
36: */
37: public class MlibSubsampleBinaryToGrayRIF implements
38: RenderedImageFactory {
39:
40: /**
41: * The width and height of blocks to be condensed into one gray pixel.
42: * They are expected to be computed in the same way as in
43: * import com.sun.media.jai.opimage.SubsampleBinaryToGrayOpImage;
44: */
45: private int blockX;
46: private int blockY;
47:
48: /** Constructor. */
49: public MlibSubsampleBinaryToGrayRIF() {
50: }
51:
52: /**
53: * Creates a new instance of <code>MlibSubsampleBinaryToGrayOpImage</code> in
54: * the rendered image mode.
55: *
56: * @param args The source image, scale factors,
57: * and the <code>Interpolation</code>.
58: * @param hints May contain rendering hints and destination image layout.
59: */
60: public RenderedImage create(ParameterBlock args,
61: RenderingHints hints) {
62: RenderedImage source = args.getRenderedSource(0);
63:
64: // Verify that the source is mediaLib-compatible.
65: if (!MediaLibAccessor.isMediaLibBinaryCompatible(args, null)) {
66: return null;
67: }
68:
69: // Get ImageLayout from RenderingHints.
70: ImageLayout layout = RIFUtil.getImageLayoutHint(hints);
71:
72: // Verify that the destination is mediaLib-compatible and has
73: // the same number of bands as the source.
74: if ((layout != null
75: && layout.isValid(ImageLayout.SAMPLE_MODEL_MASK) && !MediaLibAccessor
76: .isMediaLibCompatible(layout.getSampleModel(null),
77: layout.getColorModel(null)))
78: || !MediaLibAccessor.hasSameNumBands(args, layout)) {
79: return null;
80: }
81:
82: // Get BorderExtender from hints if any.
83: // BorderExtender extender = RIFUtil.getBorderExtenderHint(hints);
84:
85: float xScale = args.getFloatParameter(0);
86: float yScale = args.getFloatParameter(1);
87:
88: // When scaling by 1.0 in both x and y, a copy is all we need
89: if (xScale == 1.0F && yScale == 1.0F) {
90: // Use CopyOpImage as MlibCopyOpImage doesn't handle
91: // binary-to-gray case.
92: return new CopyOpImage(source, hints, layout);
93: }
94:
95: return new MlibSubsampleBinaryToGrayOpImage(source, layout,
96: hints, xScale, yScale);
97:
98: }
99: }
|