001: /*
002: * $RCSfile: MlibAbsoluteOpImage.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:47 $
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 Absolute operation on 1 image through mediaLib.
031: *
032: */
033: final class MlibAbsoluteOpImage extends PointOpImage {
034:
035: /**
036: * Constructs an MlibAbsoluteOpImage. 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 MlibAbsoluteOpImage(RenderedImage source1, Map config,
045: ImageLayout layout) {
046:
047: super (source1, layout, config, true);
048: // Set flag to permit in-place operation.
049: permitInPlaceOperation();
050: }
051:
052: /**
053: * Absolute the pixel values of a rectangle from the source.
054: * The source is 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: int formatTag = MediaLibAccessor.findCompatibleTag(sources,
065: dest);
066:
067: MediaLibAccessor srcAccessor = new MediaLibAccessor(sources[0],
068: destRect, formatTag);
069: MediaLibAccessor dstAccessor = new MediaLibAccessor(dest,
070: destRect, formatTag);
071:
072: mediaLibImage[] srcML = srcAccessor.getMediaLibImages();
073: mediaLibImage[] dstML = dstAccessor.getMediaLibImages();
074:
075: switch (dstAccessor.getDataType()) {
076: case DataBuffer.TYPE_BYTE:
077: case DataBuffer.TYPE_USHORT:
078: case DataBuffer.TYPE_SHORT:
079: case DataBuffer.TYPE_INT:
080: for (int i = 0; i < dstML.length; i++) {
081: Image.Abs(dstML[i], srcML[i]);
082: }
083: break;
084:
085: case DataBuffer.TYPE_FLOAT:
086: case DataBuffer.TYPE_DOUBLE:
087: for (int i = 0; i < dstML.length; i++) {
088: Image.Abs_Fp(dstML[i], srcML[i]);
089: }
090: break;
091:
092: default:
093: String className = this .getClass().getName();
094: throw new RuntimeException(className
095: + JaiI18N.getString("Generic2"));
096: }
097:
098: if (dstAccessor.isDataCopy()) {
099: dstAccessor.clampDataArrays();
100: dstAccessor.copyDataToRaster();
101: }
102: }
103:
104: // public static void main (String args[]) {
105: // System.out.println("MlibAbsoluteOpImage Test");
106: // ImageLayout layout;
107: // OpImage src, dst;
108: // Rectangle rect = new Rectangle(0, 0, 5, 5);
109:
110: // System.out.println("1. PixelInterleaved byte 3-band");
111: // layout = OpImageTester.createImageLayout(0, 0, 800, 800, 0, 0,
112: // 200, 200, DataBuffer.TYPE_BYTE,
113: // 3, false);
114: // src = OpImageTester.createRandomOpImage(layout);
115: // dst = new MlibAbsoluteOpImage(src, null, null);
116: // OpImageTester.testOpImage(dst, rect);
117: // OpImageTester.timeOpImage(dst, 10);
118:
119: // System.out.println("2. Banded byte 3-band");
120: // layout = OpImageTester.createImageLayout(0, 0, 800, 800, 0, 0,
121: // 200, 200, DataBuffer.TYPE_BYTE,
122: // 3, true);
123: // src = OpImageTester.createRandomOpImage(layout);
124: // dst = new MlibAbsoluteOpImage(src, null, null);
125: // OpImageTester.testOpImage(dst, rect);
126: // OpImageTester.timeOpImage(dst, 10);
127:
128: // System.out.println("3. PixelInterleaved int 3-band");
129: // layout = OpImageTester.createImageLayout(0, 0, 512, 512, 0, 0, 200, 200,
130: // DataBuffer.TYPE_INT, 3, false);
131: // src = OpImageTester.createRandomOpImage(layout);
132: // dst = new MlibAbsoluteOpImage(src, null, null);
133: // OpImageTester.testOpImage(dst, rect);
134: // OpImageTester.timeOpImage(dst, 10);
135:
136: // System.out.println("4. Banded int 3-band");
137: // layout = OpImageTester.createImageLayout(0, 0, 512, 512, 0, 0,
138: // 200, 200, DataBuffer.TYPE_INT,
139: // 3, true);
140: // src = OpImageTester.createRandomOpImage(layout);
141: // dst = new MlibAbsoluteOpImage(src, null, null);
142: // OpImageTester.testOpImage(dst, rect);
143: // OpImageTester.timeOpImage(dst, 10);
144: // }
145: }
|