01: /*
02: * $RCSfile: MlibCompositeRIF.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:52 $
10: * $State: Exp $
11: */
12: package com.sun.media.jai.mlib;
13:
14: import java.awt.RenderingHints;
15: import java.awt.image.ComponentSampleModel;
16: import java.awt.image.ComponentColorModel;
17: import java.awt.image.DataBuffer;
18: import java.awt.image.RenderedImage;
19: import java.awt.image.SampleModel;
20: import java.awt.image.renderable.ParameterBlock;
21: import java.awt.image.renderable.RenderedImageFactory;
22: import javax.media.jai.EnumeratedParameter;
23: import javax.media.jai.ImageLayout;
24: import java.util.Map;
25: import javax.media.jai.operator.CompositeDescriptor;
26: import com.sun.media.jai.opimage.RIFUtil;
27:
28: /**
29: * A <code>RIF</code> supporting the "Composite" operation in the
30: * rendered image mode using MediaLib.
31: *
32: * @see javax.media.jai.operator.CompositeDescriptor
33: * @see MlibCompositeOpImage
34: *
35: * @since 1.0
36: *
37: */
38: public class MlibCompositeRIF implements RenderedImageFactory {
39:
40: /** Constructor. */
41: public MlibCompositeRIF() {
42: }
43:
44: /**
45: * Creates a new instance of <code>MlibCompositeOpImage</code> in
46: * the rendered image mode.
47: *
48: * @param args The source images.
49: * @param hints May contain rendering hints and destination image layout.
50: */
51: public RenderedImage create(ParameterBlock args,
52: RenderingHints hints) {
53: /* Get ImageLayout and TileCache from RenderingHints. */
54: ImageLayout layout = RIFUtil.getImageLayoutHint(hints);
55:
56: if (!MediaLibAccessor.isMediaLibCompatible(args, layout)
57: || !MediaLibAccessor.hasSameNumBands(args, layout)) {
58: return null;
59: }
60:
61: RenderedImage alpha1 = (RenderedImage) args
62: .getObjectParameter(0);
63: Object alpha2 = args.getObjectParameter(1);
64: boolean premultiplied = ((Boolean) args.getObjectParameter(2))
65: .booleanValue();
66: EnumeratedParameter destAlpha = (EnumeratedParameter) args
67: .getObjectParameter(3);
68:
69: SampleModel sm = alpha1.getSampleModel();
70:
71: if (!(sm instanceof ComponentSampleModel)
72: || sm.getNumBands() != 1
73: || !(alpha1.getColorModel() instanceof ComponentColorModel)
74: || alpha2 != null
75: || premultiplied
76: || !(destAlpha
77: .equals(CompositeDescriptor.NO_DESTINATION_ALPHA))) {
78: return null;
79: }
80:
81: return new MlibCompositeOpImage(args.getRenderedSource(0), args
82: .getRenderedSource(1), hints, layout, alpha1);
83: }
84: }
|