01: /*
02: * $RCSfile: MlibMaxOpImage.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:59 $
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 "Max" operation
26: * using MediaLib.
27: *
28: * @see javax.media.jai.operator.MaxDescriptor
29: * @see MlibMaxRIF
30: *
31: * @since 1.0
32: *
33: */
34: final class MlibMaxOpImage extends PointOpImage {
35:
36: /** Constructor. */
37: public MlibMaxOpImage(RenderedImage source1, RenderedImage source2,
38: Map config, ImageLayout layout) {
39: super (source1, source2, layout, config, true);
40: // Set flag to permit in-place operation.
41: permitInPlaceOperation();
42: }
43:
44: /**
45: * Performs the "Max" operation on a rectangular region of
46: * the same.
47: */
48: protected void computeRect(Raster[] sources, WritableRaster dest,
49: Rectangle destRect) {
50: int formatTag = MediaLibAccessor.findCompatibleTag(sources,
51: dest);
52:
53: MediaLibAccessor srcMA1 = new MediaLibAccessor(sources[0],
54: destRect, formatTag);
55: MediaLibAccessor srcMA2 = new MediaLibAccessor(sources[1],
56: destRect, formatTag);
57: MediaLibAccessor dstMA = new MediaLibAccessor(dest, destRect,
58: formatTag);
59:
60: mediaLibImage[] srcMLI1 = srcMA1.getMediaLibImages();
61: mediaLibImage[] srcMLI2 = srcMA2.getMediaLibImages();
62: mediaLibImage[] dstMLI = dstMA.getMediaLibImages();
63:
64: switch (dstMA.getDataType()) {
65: case DataBuffer.TYPE_BYTE:
66: case DataBuffer.TYPE_USHORT:
67: case DataBuffer.TYPE_SHORT:
68: case DataBuffer.TYPE_INT:
69: for (int i = 0; i < dstMLI.length; i++) {
70: Image.Max(dstMLI[i], srcMLI1[i], srcMLI2[i]);
71: }
72: break;
73:
74: case DataBuffer.TYPE_FLOAT:
75: case DataBuffer.TYPE_DOUBLE:
76: for (int i = 0; i < dstMLI.length; i++) {
77: Image.Max_Fp(dstMLI[i], srcMLI1[i], srcMLI2[i]);
78: }
79: break;
80:
81: }
82:
83: if (dstMA.isDataCopy()) {
84: dstMA.clampDataArrays();
85: dstMA.copyDataToRaster();
86: }
87: }
88: }
|