001: /*
002: * $RCSfile: MlibAndConstOpImage.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:55:49 $
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 "AndConst" operator.
029: *
030: */
031: final class MlibAndConstOpImage extends PointOpImage {
032: int[] constants;
033:
034: /**
035: * Constructs an MlibAndConstOpImage. 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 MlibAndConstOpImage(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: * And 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:
064: Raster source = sources[0];
065: int formatTag = MediaLibAccessor.findCompatibleTag(sources,
066: dest);
067:
068: // For PointOpImages, the srcRect and the destRect are the same.
069: MediaLibAccessor srcAccessor = new MediaLibAccessor(source,
070: destRect, formatTag);
071: MediaLibAccessor dstAccessor = new MediaLibAccessor(dest,
072: destRect, formatTag);
073:
074: switch (dstAccessor.getDataType()) {
075: case DataBuffer.TYPE_BYTE:
076: case DataBuffer.TYPE_USHORT:
077: case DataBuffer.TYPE_SHORT:
078: case DataBuffer.TYPE_INT:
079: mediaLibImage[] srcML = srcAccessor.getMediaLibImages();
080: mediaLibImage[] dstML = dstAccessor.getMediaLibImages();
081: for (int i = 0; i < dstML.length; i++) {
082: int mlconstants[] = dstAccessor.getIntParameters(i,
083: constants);
084: Image.ConstAnd(dstML[i], srcML[i], mlconstants);
085: }
086: break;
087: default:
088: String className = this .getClass().getName();
089: throw new RuntimeException(className
090: + JaiI18N.getString("Generic2"));
091: }
092:
093: if (dstAccessor.isDataCopy()) {
094: dstAccessor.clampDataArrays();
095: dstAccessor.copyDataToRaster();
096: }
097: }
098:
099: // public static OpImage createTestImage(OpImageTester oit) {
100: // int[] consts = {5, 5, 5};
101: // return new MlibAndConstOpImage(oit.getSource(), null,
102: // new ImageLayout(oit.getSource()),
103: // consts);
104: // }
105:
106: // // Calls a method on OpImage that uses introspection, to make this
107: // // class, discover it's createTestImage() call, call it and then
108: // // benchmark the performance of the created OpImage chain.
109: // public static void main (String args[]) {
110: // String classname = "com.sun.media.jai.mlib.MlibAndConstOpImage";
111: // OpImageTester.performDiagnostics(classname,args);
112: // }
113: }
|