001: /*
002: * $RCSfile: MlibExpOpImage.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:56 $
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: * An OpImage class that divides an image into a constant
029: *
030: */
031: final class MlibExpOpImage extends PointOpImage {
032:
033: /**
034: * Constructs an MlibExpOpImage. The image dimensions are copied
035: * from the source image. The tile grid layout, SampleModel, and
036: * ColorModel may optionally be specified by an ImageLayout object.
037: *
038: * @param source a RenderedImage.
039: * @param layout an ImageLayout optionally containing the tile
040: * grid layout, SampleModel, and ColorModel, or null.
041: */
042: public MlibExpOpImage(RenderedImage source, Map config,
043: ImageLayout layout) {
044: super (source, layout, config, true);
045: // Set flag to permit in-place operation.
046: permitInPlaceOperation();
047: }
048:
049: /**
050: * Divide the pixel values of a rectangle into a given constant.
051: * The sources are cobbled.
052: *
053: * @param sources an array of sources, guarantee to provide all
054: * necessary source data for computing the rectangle.
055: * @param dest a tile that contains the rectangle to be computed.
056: * @param destRect the rectangle within this OpImage to be processed.
057: */
058: protected void computeRect(Raster[] sources, WritableRaster dest,
059: Rectangle destRect) {
060: Raster source = sources[0];
061: Rectangle srcRect = mapDestRect(destRect, 0);
062:
063: int formatTag = MediaLibAccessor.findCompatibleTag(sources,
064: dest);
065:
066: MediaLibAccessor srcAccessor = new MediaLibAccessor(source,
067: srcRect, formatTag);
068: MediaLibAccessor dstAccessor = new MediaLibAccessor(dest,
069: destRect, formatTag);
070:
071: mediaLibImage[] srcML = srcAccessor.getMediaLibImages();
072: mediaLibImage[] dstML = dstAccessor.getMediaLibImages();
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: for (int i = 0; i < dstML.length; i++) {
080: Image.Exp(dstML[i], srcML[i]);
081: }
082: break;
083:
084: case DataBuffer.TYPE_FLOAT:
085: case DataBuffer.TYPE_DOUBLE:
086: for (int i = 0; i < dstML.length; i++) {
087: Image.Exp_Fp(dstML[i], srcML[i]);
088: }
089: break;
090:
091: default:
092: String className = this .getClass().getName();
093: throw new RuntimeException(className
094: + JaiI18N.getString("Generic2"));
095: }
096:
097: if (dstAccessor.isDataCopy()) {
098: dstAccessor.clampDataArrays();
099: dstAccessor.copyDataToRaster();
100: }
101: }
102: }
|