001: /*
002: * $RCSfile: MlibNotOpImage.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:02 $
010: * $State: Exp $
011: */
012: package com.sun.media.jai.mlib;
013:
014: import java.awt.Rectangle;
015: import java.awt.image.DataBuffer;
016: import java.awt.image.PixelInterleavedSampleModel;
017: import java.awt.image.Raster;
018: import java.awt.image.RenderedImage;
019: import java.awt.image.SampleModel;
020: import java.awt.image.WritableRaster;
021: import javax.media.jai.ImageLayout;
022: import javax.media.jai.OpImage;
023: import javax.media.jai.PointOpImage;
024: import java.util.Map;
025: import com.sun.medialib.mlib.*;
026:
027: // import com.sun.media.jai.test.OpImageTester;
028:
029: /**
030: * An OpImage that performs the Not operation on 2 images through mediaLib.
031: *
032: */
033: final class MlibNotOpImage extends PointOpImage {
034:
035: /**
036: * Constructs an MlibNotOpImage. The image dimensions are copied
037: * from the source image. The tile grid layout, SampleModel, and
038: * ColorModel may optionally be specified by an ImageLayout object.
039: *
040: * @param source a RenderedImage.
041: * @param layout an ImageLayout optionally containing the tile
042: * grid layout, SampleModel, and ColorModel, or null.
043: */
044: public MlibNotOpImage(RenderedImage source, Map config,
045: ImageLayout layout) {
046: super (source, layout, config, true);
047: // Set flag to permit in-place operation.
048: permitInPlaceOperation();
049: }
050:
051: /**
052: * Not the pixel values of a rectangle from the source.
053: * The source is cobbled.
054: *
055: * @param sources an array of sources, guarantee to provide all
056: * necessary source data for computing the rectangle.
057: * @param dest a tile that contains the rectangle to be computed.
058: * @param destRect the rectangle within this OpImage to be processed.
059: */
060: protected void computeRect(Raster[] sources, WritableRaster dest,
061: Rectangle destRect) {
062:
063: int formatTag = MediaLibAccessor.findCompatibleTag(sources,
064: dest);
065:
066: MediaLibAccessor srcAccessor = new MediaLibAccessor(sources[0],
067: destRect, formatTag);
068: MediaLibAccessor dstAccessor = new MediaLibAccessor(dest,
069: destRect, formatTag);
070:
071: switch (dstAccessor.getDataType()) {
072: case DataBuffer.TYPE_BYTE:
073: case DataBuffer.TYPE_USHORT:
074: case DataBuffer.TYPE_SHORT:
075: case DataBuffer.TYPE_INT:
076: mediaLibImage[] srcML = srcAccessor.getMediaLibImages();
077: mediaLibImage[] dstML = dstAccessor.getMediaLibImages();
078: for (int i = 0; i < dstML.length; i++) {
079: Image.Not(dstML[i], srcML[i]);
080: }
081: break;
082: default:
083: String className = this .getClass().getName();
084: throw new RuntimeException(className
085: + JaiI18N.getString("Generic2"));
086: }
087:
088: if (dstAccessor.isDataCopy()) {
089: dstAccessor.clampDataArrays();
090: dstAccessor.copyDataToRaster();
091: }
092: }
093:
094: // public static void main (String args[]) {
095: // System.out.println("MlibNotOpImage Test");
096: // ImageLayout layout;
097: // OpImage src, dst;
098: // Rectangle rect = new Rectangle(0, 0, 5, 5);
099:
100: // System.out.println("1. PixelInterleaved byte 3-band");
101: // layout = OpImageTester.createImageLayout(0, 0, 800, 800, 0, 0,
102: // 200, 200, DataBuffer.TYPE_BYTE,
103: // 3, false);
104: // src = OpImageTester.createRandomOpImage(layout);
105: // dst = new MlibNotOpImage(src, null, null);
106: // OpImageTester.testOpImage(dst, rect);
107: // OpImageTester.timeOpImage(dst, 10);
108:
109: // System.out.println("2. Banded byte 3-band");
110: // layout = OpImageTester.createImageLayout(0, 0, 800, 800, 0, 0,
111: // 200, 200, DataBuffer.TYPE_BYTE,
112: // 3, true);
113: // src = OpImageTester.createRandomOpImage(layout);
114: // dst = new MlibNotOpImage(src, null, null);
115: // OpImageTester.testOpImage(dst, rect);
116: // OpImageTester.timeOpImage(dst, 10);
117:
118: // System.out.println("3. PixelInterleaved int 3-band");
119: // layout = OpImageTester.createImageLayout(0, 0, 512, 512, 0, 0, 200, 200,
120: // DataBuffer.TYPE_INT, 3, false);
121: // src = OpImageTester.createRandomOpImage(layout);
122: // dst = new MlibNotOpImage(src, null, null);
123: // OpImageTester.testOpImage(dst, rect);
124: // OpImageTester.timeOpImage(dst, 10);
125:
126: // System.out.println("4. Banded int 3-band");
127: // layout = OpImageTester.createImageLayout(0, 0, 512, 512, 0, 0,
128: // 200, 200, DataBuffer.TYPE_INT,
129: // 3, true);
130: // src = OpImageTester.createRandomOpImage(layout);
131: // dst = new MlibNotOpImage(src, null, null);
132: // OpImageTester.testOpImage(dst, rect);
133: // OpImageTester.timeOpImage(dst, 10);
134: // }
135: }
|