01: /*
02: * $RCSfile: MlibInvertOpImage.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:58 $
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 "Invert" operation
26: * using MediaLib.
27: *
28: * @see javax.media.jai.operator.InvertDescriptor
29: * @see MlibInvertRIF
30: *
31: * @since 1.0
32: *
33: */
34: final class MlibInvertOpImage extends PointOpImage {
35:
36: /** Constructor. */
37: public MlibInvertOpImage(RenderedImage source, Map config,
38: ImageLayout layout) {
39: super (source, layout, config, true);
40: // Set flag to permit in-place operation.
41: permitInPlaceOperation();
42: }
43:
44: /**
45: * Performs the "Invert" 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 srcMA = new MediaLibAccessor(sources[0],
54: destRect, formatTag);
55: MediaLibAccessor dstMA = new MediaLibAccessor(dest, destRect,
56: formatTag);
57:
58: mediaLibImage[] srcMLI = srcMA.getMediaLibImages();
59: mediaLibImage[] dstMLI = dstMA.getMediaLibImages();
60:
61: switch (dstMA.getDataType()) {
62: case DataBuffer.TYPE_BYTE:
63: case DataBuffer.TYPE_USHORT:
64: case DataBuffer.TYPE_SHORT:
65: case DataBuffer.TYPE_INT:
66: for (int i = 0; i < dstMLI.length; i++) {
67: Image.Invert(dstMLI[i], srcMLI[i]);
68: }
69: break;
70:
71: case DataBuffer.TYPE_FLOAT:
72: case DataBuffer.TYPE_DOUBLE:
73: for (int i = 0; i < dstMLI.length; i++) {
74: Image.Invert_Fp(dstMLI[i], srcMLI[i]);
75: }
76: break;
77:
78: default:
79: throw new RuntimeException(JaiI18N.getString("Generic2"));
80: }
81:
82: if (dstMA.isDataCopy()) {
83: dstMA.clampDataArrays();
84: dstMA.copyDataToRaster();
85: }
86: }
87: }
|