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