001: /*
002: * $RCSfile: MlibXorConstOpImage.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:09 $
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.Raster;
017: import java.awt.image.RenderedImage;
018: import java.awt.image.WritableRaster;
019: import javax.media.jai.ImageLayout;
020: import javax.media.jai.OpImage;
021: import javax.media.jai.PointOpImage;
022: import java.util.Map;
023: import com.sun.medialib.mlib.*;
024:
025: // import com.sun.media.jai.test.OpImageTester;
026:
027: /**
028: * A mediaLib implementation of "XorConst" operator.
029: *
030: */
031: final class MlibXorConstOpImage extends PointOpImage {
032: int[] constants;
033:
034: /**
035: * Constructs an MlibXorConstOpImage. The image dimensions are copied
036: * from the source image. The tile grid layout, SampleModel, and
037: * ColorModel may optionally be specified by an ImageLayout object.
038: *
039: * @param source a RenderedImage.
040: * @param layout an ImageLayout optionally containing the tile
041: * grid layout, SampleModel, and ColorModel, or null.
042: */
043: public MlibXorConstOpImage(RenderedImage source, Map config,
044: ImageLayout layout, int[] constants) {
045: super (source, layout, config, true);
046: this .constants = MlibUtils.initConstants(constants,
047: getSampleModel().getNumBands());
048: // Set flag to permit in-place operation.
049: permitInPlaceOperation();
050: }
051:
052: /**
053: * Xor the pixel values of a rectangle with a given constant.
054: * The sources are cobbled.
055: *
056: * @param sources an array of sources, guarantee to provide all
057: * necessary source data for computing the rectangle.
058: * @param dest a tile that contains the rectangle to be computed.
059: * @param destRect the rectangle within this OpImage to be processed.
060: */
061: protected void computeRect(Raster[] sources, WritableRaster dest,
062: Rectangle destRect) {
063: Raster source = sources[0];
064: int formatTag = MediaLibAccessor.findCompatibleTag(sources,
065: dest);
066:
067: // For PointOpImages, srcRect is the same as destRect
068: MediaLibAccessor srcAccessor = new MediaLibAccessor(source,
069: destRect, formatTag);
070: MediaLibAccessor dstAccessor = new MediaLibAccessor(dest,
071: destRect, formatTag);
072:
073: switch (dstAccessor.getDataType()) {
074: case DataBuffer.TYPE_BYTE:
075: case DataBuffer.TYPE_USHORT:
076: case DataBuffer.TYPE_SHORT:
077: case DataBuffer.TYPE_INT:
078: mediaLibImage[] srcML = srcAccessor.getMediaLibImages();
079: mediaLibImage[] dstML = dstAccessor.getMediaLibImages();
080: for (int i = 0; i < dstML.length; i++) {
081: int mlconstants[] = dstAccessor.getIntParameters(i,
082: constants);
083: Image.ConstXor(dstML[i], srcML[i], mlconstants);
084: }
085: break;
086: default:
087: String className = this .getClass().getName();
088: throw new RuntimeException(JaiI18N.getString("Generic2"));
089: }
090:
091: if (dstAccessor.isDataCopy()) {
092: dstAccessor.clampDataArrays();
093: dstAccessor.copyDataToRaster();
094: }
095: }
096:
097: // public static OpImage createTestImage(OpImageTester oit) {
098: // int[] consts = {5, 5, 5};
099: // return new MlibXorConstOpImage(oit.getSource(), null,
100: // new ImageLayout(oit.getSource()),
101: // consts);
102: // }
103:
104: // // Calls a method on OpImage that uses introspection, to make this
105: // // class, discover it's createTestImage() call, call it and then
106: // // benchmark the performance of the created OpImage chain.
107: // public static void main (String args[]) {
108: // String classname = "com.sun.media.jai.mlib.MlibXorConstOpImage";
109: // OpImageTester.performDiagnostics(classname,args);
110: // }
111: }
|