001: /*
002: * $RCSfile: MlibSubsampleAverageOpImage.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:06 $
010: * $State: Exp $
011: */package com.sun.media.jai.mlib;
012:
013: import java.awt.Rectangle;
014: import java.awt.image.DataBuffer;
015: import java.awt.image.Raster;
016: import java.awt.image.RenderedImage;
017: import java.awt.image.WritableRaster;
018: import java.util.Map;
019: import javax.media.jai.BorderExtender;
020: import javax.media.jai.GeometricOpImage;
021: import javax.media.jai.ImageLayout;
022: import javax.media.jai.Interpolation;
023: import com.sun.media.jai.opimage.SubsampleAverageOpImage;
024: import com.sun.medialib.mlib.Image;
025: import com.sun.medialib.mlib.mediaLibImage;
026:
027: public class MlibSubsampleAverageOpImage extends
028: SubsampleAverageOpImage {
029: /* XXX
030: public static void main(String[] args) throws Throwable {
031: RenderedImage source =
032: javax.media.jai.JAI.create("fileload", args[0]);
033: double scaleX = args.length > 1 ?
034: Double.valueOf(args[1]).doubleValue() : 0.25;
035: double scaleY = args.length > 2 ?
036: Double.valueOf(args[2]).doubleValue() : scaleX;
037:
038: RenderedImage dest =
039: new MlibSubsampleAverageOpImage(source, null, null,
040: scaleX, scaleY);
041:
042: System.out.println(source.getClass().getName()+": "+
043: new ImageLayout(source));
044: System.out.println(dest.getClass().getName()+": "+
045: new ImageLayout(dest));
046:
047: java.awt.Frame frame = new java.awt.Frame("Mlib Sub-average Test");
048: frame.setLayout(new java.awt.GridLayout(1, 2));
049: javax.media.jai.widget.ScrollingImagePanel ps =
050: new javax.media.jai.widget.ScrollingImagePanel(source,
051: 512, 512);
052: javax.media.jai.widget.ScrollingImagePanel pd =
053: new javax.media.jai.widget.ScrollingImagePanel(dest,
054: 512, 512);
055: frame.add(ps);
056: frame.add(pd);
057: frame.pack();
058: frame.show();
059: }
060: */
061:
062: public MlibSubsampleAverageOpImage(RenderedImage source,
063: ImageLayout layout, Map config, double scaleX, double scaleY) {
064: super (source, layout, config, scaleX, scaleY);
065: }
066:
067: protected void computeRect(Raster[] sources, WritableRaster dest,
068: Rectangle destRect) {
069: Raster source = sources[0];
070: Rectangle srcRect = source.getBounds();
071:
072: int formatTag = MediaLibAccessor.findCompatibleTag(sources,
073: dest);
074:
075: MediaLibAccessor srcAccessor = new MediaLibAccessor(source,
076: srcRect, formatTag);
077: MediaLibAccessor dstAccessor = new MediaLibAccessor(dest,
078: destRect, formatTag);
079:
080: mediaLibImage srcML[], dstML[];
081:
082: switch (dstAccessor.getDataType()) {
083: case DataBuffer.TYPE_BYTE:
084: case DataBuffer.TYPE_USHORT:
085: case DataBuffer.TYPE_SHORT:
086: case DataBuffer.TYPE_INT:
087: srcML = srcAccessor.getMediaLibImages();
088: dstML = dstAccessor.getMediaLibImages();
089:
090: Image.SubsampleAverage(dstML[0], srcML[0], scaleX, scaleY);
091: break;
092:
093: case DataBuffer.TYPE_FLOAT:
094: case DataBuffer.TYPE_DOUBLE:
095: srcML = srcAccessor.getMediaLibImages();
096: dstML = dstAccessor.getMediaLibImages();
097:
098: Image.SubsampleAverage_Fp(dstML[0], srcML[0], scaleX,
099: scaleY);
100: break;
101:
102: default:
103: // XXX?
104: }
105:
106: if (dstAccessor.isDataCopy()) {
107: dstAccessor.copyDataToRaster();
108: }
109: }
110: }
|