01: /*
02: * $RCSfile: MlibCompositeOpImage.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.Rectangle;
15: import java.awt.image.DataBuffer;
16: import java.awt.image.Raster;
17: import java.awt.image.RenderedImage;
18: import java.awt.image.WritableRaster;
19: import javax.media.jai.ImageLayout;
20: import javax.media.jai.PointOpImage;
21: import java.util.Map;
22: import com.sun.medialib.mlib.*;
23:
24: /**
25: * An <code>OpImage</code> implementing the "Composite" operation
26: * using MediaLib.
27: *
28: * @see javax.media.jai.operator.CompositeDescriptor
29: * @see MlibCompositeRIF
30: *
31: * @since 1.0
32: *
33: */
34: final class MlibCompositeOpImage extends PointOpImage {
35:
36: /** The alpha image. */
37: private RenderedImage alpha;
38:
39: /** Constructor. */
40: public MlibCompositeOpImage(RenderedImage source1,
41: RenderedImage source2, Map config, ImageLayout layout,
42: RenderedImage alpha) {
43: super (source1, source2, layout, config, true);
44:
45: this .alpha = alpha;
46: }
47:
48: /**
49: * Performs the "Composite" operation on a rectangular region of
50: * the same.
51: */
52: protected void computeRect(Raster[] sources, WritableRaster dest,
53: Rectangle destRect) {
54: int formatTag = MediaLibAccessor.findCompatibleTag(sources,
55: dest);
56:
57: MediaLibAccessor srcMA1 = new MediaLibAccessor(sources[0],
58: destRect, formatTag);
59: MediaLibAccessor srcMA2 = new MediaLibAccessor(sources[1],
60: destRect, formatTag);
61: MediaLibAccessor dstMA = new MediaLibAccessor(dest, destRect,
62: formatTag);
63: MediaLibAccessor alphaMA = new MediaLibAccessor(alpha
64: .getData(destRect), destRect, formatTag);
65:
66: mediaLibImage[] srcMLI1 = srcMA1.getMediaLibImages();
67: mediaLibImage[] srcMLI2 = srcMA2.getMediaLibImages();
68: mediaLibImage[] dstMLI = dstMA.getMediaLibImages();
69: mediaLibImage[] alphaMLI = alphaMA.getMediaLibImages();
70:
71: switch (dstMA.getDataType()) {
72: case DataBuffer.TYPE_BYTE:
73: case DataBuffer.TYPE_USHORT:
74: case DataBuffer.TYPE_SHORT:
75: case DataBuffer.TYPE_INT:
76: for (int i = 0; i < dstMLI.length; i++) {
77: Image.Blend(dstMLI[i], srcMLI1[i], srcMLI2[i],
78: alphaMLI[0]);
79: }
80: break;
81:
82: case DataBuffer.TYPE_FLOAT:
83: case DataBuffer.TYPE_DOUBLE:
84: for (int i = 0; i < dstMLI.length; i++) {
85: Image.Blend_Fp(dstMLI[i], srcMLI1[i], srcMLI2[i],
86: alphaMLI[0]);
87: }
88: break;
89:
90: default:
91: throw new RuntimeException(JaiI18N.getString("Generic2"));
92: }
93:
94: if (dstMA.isDataCopy()) {
95: dstMA.clampDataArrays();
96: dstMA.copyDataToRaster();
97: }
98: }
99: }
|