01: /*
02: * $RCSfile: MlibCopyOpImage.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:53 $
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.OpImage;
21: import javax.media.jai.PointOpImage;
22: import java.util.Map;
23: import com.sun.medialib.mlib.*;
24:
25: // import com.sun.media.jai.test.OpImageTester;
26:
27: /**
28: * An OpImage class that copies an image from source to dest.
29: *
30: */
31: final class MlibCopyOpImage extends PointOpImage {
32:
33: /**
34: * Constructs an MlibCopyOpImage. The image dimensions are copied
35: * from the source image. The tile grid layout, SampleModel, and
36: * ColorModel may optionally be specified by an ImageLayout object.
37: *
38: * @param source a RenderedImage.
39:
40: * or null. If null, a default cache will be used.
41: * @param layout an ImageLayout optionally containing the tile
42: * grid layout, SampleModel, and ColorModel, or null.
43: */
44: public MlibCopyOpImage(RenderedImage source, Map config,
45: ImageLayout layout) {
46: super (source, layout, config, true);
47:
48: }
49:
50: /**
51: * Copy the pixel values of a rectangle with a given constant.
52: * The sources are cobbled.
53: *
54: * @param sources an array of sources, guarantee to provide all
55: * necessary source data for computing the rectangle.
56: * @param dest a tile that contains the rectangle to be computed.
57: * @param destRect the rectangle within this OpImage to be processed.
58: */
59: protected void computeRect(Raster[] sources, WritableRaster dest,
60: Rectangle destRect) {
61: int formatTag = MediaLibAccessor.findCompatibleTag(sources,
62: dest);
63:
64: MediaLibAccessor srcMA = new MediaLibAccessor(sources[0],
65: destRect, formatTag);
66: MediaLibAccessor dstMA = new MediaLibAccessor(dest, destRect,
67: formatTag);
68:
69: mediaLibImage[] srcMLI = srcMA.getMediaLibImages();
70: mediaLibImage[] dstMLI = dstMA.getMediaLibImages();
71:
72: for (int i = 0; i < dstMLI.length; i++) {
73: Image.Copy(dstMLI[i], srcMLI[i]);
74: }
75:
76: if (dstMA.isDataCopy()) {
77: dstMA.copyDataToRaster();
78: }
79: }
80: }
|