01: /*
02: * $RCSfile: MlibSubsampleAverageRIF.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: */package com.sun.media.jai.mlib;
12:
13: import java.awt.RenderingHints;
14: import java.awt.image.RenderedImage;
15: import java.awt.image.renderable.RenderedImageFactory;
16: import java.awt.image.renderable.ParameterBlock;
17: import javax.media.jai.ImageLayout;
18: import com.sun.media.jai.opimage.RIFUtil;
19:
20: /**
21: * A <code>RIF</code> supporting the "SubsampleAverage" operation in the
22: * rendered image mode using MediaLib.
23: *
24: * @see javax.media.jai.operator.SubsampleaverageDescriptor
25: * @see MlibSubsampleAverageOpImage
26:
27: */
28: public class MlibSubsampleAverageRIF implements RenderedImageFactory {
29:
30: /** Constructor. */
31: public MlibSubsampleAverageRIF() {
32: }
33:
34: /**
35: * Creates a new instance of <code>MlibSubsampleAverageOpImage</code> in
36: * the rendered image mode.
37: *
38: * @param args The source image, scale factors,
39: * and the <code>Interpolation</code>.
40: * @param hints May contain rendering hints and destination image layout.
41: */
42: public RenderedImage create(ParameterBlock args,
43: RenderingHints hints) {
44: // Get the scale factors.
45: double scaleX = args.getDoubleParameter(0);
46: double scaleY = args.getDoubleParameter(1);
47:
48: // If unity scaling return the source directly.
49: if (scaleX == 1.0 && scaleY == 1.0) {
50: return args.getRenderedSource(0);
51: }
52:
53: // Get the layout.
54: ImageLayout layout = RIFUtil.getImageLayoutHint(hints);
55:
56: // Check mediaLib compatibility.
57: if (!MediaLibAccessor.isMediaLibCompatible(args, layout)
58: || !MediaLibAccessor.hasSameNumBands(args, layout)) {
59: // Return null to indicate to fallback to next RIF.
60: return null;
61: }
62:
63: // Create and return the OpImage.
64: return new MlibSubsampleAverageOpImage(args
65: .getRenderedSource(0), layout, hints, scaleX, scaleY);
66: }
67: }
|