001: /*
002: * $RCSfile: CompositeCRIF.java,v $
003: *
004: * Copyright (c) 2005 Sun Microsystems, Inc. All rights reserved.
005: *
006: * Use is subject to license terms.
007: *
008: * $Revision: 1.1 $
009: * $Date: 2005/02/11 04:56:18 $
010: * $State: Exp $
011: */
012: package com.sun.media.jai.opimage;
013:
014: import java.awt.RenderingHints;
015: import java.awt.image.RenderedImage;
016: import java.awt.image.renderable.ParameterBlock;
017: import java.awt.image.renderable.RenderableImage;
018: import java.awt.image.renderable.RenderContext;
019: import javax.media.jai.CRIFImpl;
020: import javax.media.jai.EnumeratedParameter;
021: import javax.media.jai.ImageLayout;
022: import javax.media.jai.JAI;
023: import java.util.Map;
024: import javax.media.jai.operator.CompositeDescriptor;
025:
026: /**
027: * A <code>CRIF</code> supporting the "Composite" operation in the
028: * rendered and renderable image modes.
029: *
030: * @see javax.media.jai.operator.CompositeDescriptor
031: * @see CompositeOpImage
032: * @see CompositeNoAlphaOpImage
033: *
034: */
035: public class CompositeCRIF extends CRIFImpl {
036:
037: /** Constructor. */
038: public CompositeCRIF() {
039: super ("composite");
040: }
041:
042: /**
043: * Creates a new instance of <code>CompositeOpImage</code>
044: * in the rendered layer. This method satisfies the
045: * implementation of RIF.
046: */
047: public RenderedImage create(ParameterBlock args,
048: RenderingHints hints) {
049: /* Get ImageLayout from RenderingHints if any. */
050: ImageLayout layout = RIFUtil.getImageLayoutHint(hints);
051:
052: RenderedImage source1 = args.getRenderedSource(0);
053: RenderedImage source2 = args.getRenderedSource(1);
054:
055: RenderedImage alpha1 = (RenderedImage) args
056: .getObjectParameter(0);
057: RenderedImage alpha2 = null;
058: if (args.getObjectParameter(1) != null) {
059: alpha2 = (RenderedImage) args.getObjectParameter(1);
060: }
061:
062: boolean premultiplied = ((Boolean) args.getObjectParameter(2))
063: .booleanValue();
064: EnumeratedParameter destAlpha = (EnumeratedParameter) args
065: .getObjectParameter(3);
066:
067: if (destAlpha.equals(CompositeDescriptor.NO_DESTINATION_ALPHA)) {
068: return new CompositeNoDestAlphaOpImage(source1, source2,
069: hints, layout, alpha1, alpha2, premultiplied);
070: } else {
071: return new CompositeOpImage(
072: source1,
073: source2,
074: hints,
075: layout,
076: alpha1,
077: alpha2,
078: premultiplied,
079: destAlpha
080: .equals(CompositeDescriptor.DESTINATION_ALPHA_FIRST));
081: }
082: }
083:
084: /**
085: * Creates a <Code>RenderedImage</Code> from the renderable layer.
086: *
087: * @param renderContext The rendering information associated with
088: * this rendering.
089: * @param paramBlock The parameters used to create the image.
090: * @return A <code>RenderedImage</code>.
091: */
092: public RenderedImage create(RenderContext renderContext,
093: ParameterBlock paramBlock) {
094:
095: // Get the two renderable alpha images from the parameter block
096: RenderableImage alphaImage1 = (RenderableImage) paramBlock
097: .getObjectParameter(0);
098: RenderableImage alphaImage2 = (RenderableImage) paramBlock
099: .getObjectParameter(1);
100:
101: // Cause the two renderable alpha images to be rendered
102: RenderedImage rAlphaImage1 = alphaImage1
103: .createRendering(renderContext);
104: RenderedImage rAlphaImage2 = alphaImage2
105: .createRendering(renderContext);
106:
107: ParameterBlock newPB = (ParameterBlock) paramBlock.clone();
108:
109: // Replace the renderable alpha images in the ParameterBlock with
110: // their renderings
111: newPB.set(rAlphaImage1, 0);
112: newPB.set(rAlphaImage2, 1);
113:
114: // Return JAI.create("composite")
115: return JAI.create("composite", newPB, renderContext
116: .getRenderingHints());
117: }
118:
119: }
|