001: /*
002: * $RCSfile: MlibDFTRIF.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:53 $
010: * $State: Exp $
011: */
012: package com.sun.media.jai.mlib;
013:
014: import java.awt.RenderingHints;
015: import java.awt.image.RenderedImage;
016: import java.awt.image.renderable.ParameterBlock;
017: import java.awt.image.renderable.RenderedImageFactory;
018: import javax.media.jai.BorderExtender;
019: import javax.media.jai.EnumeratedParameter;
020: import javax.media.jai.ImageLayout;
021: import javax.media.jai.JAI;
022: import java.util.Map;
023: import javax.media.jai.operator.DFTDescriptor;
024: import com.sun.media.jai.opimage.RIFUtil;
025: import com.sun.media.jai.opimage.DFTOpImage;
026: import com.sun.media.jai.opimage.FFT;
027: import com.sun.media.jai.util.MathJAI;
028:
029: /**
030: * A <code>RIF</code> supporting the "DFT" operation in the
031: * rendered image mode using MediaLib.
032: *
033: * @since EA4
034: *
035: * @see javax.media.jai.operator.DFTDescriptor
036: * @see com.sun.media.jai.opimage.DFTOpImage
037: *
038: */
039: public class MlibDFTRIF implements RenderedImageFactory {
040:
041: /** Constructor. */
042: public MlibDFTRIF() {
043: }
044:
045: /**
046: * Creates a new instance of <code>DFTOpImage</code> in
047: * the rendered image mode.
048: *
049: * @param args The source image.
050: * @param hints May contain rendering hints and destination image layout.
051: */
052: public RenderedImage create(ParameterBlock args,
053: RenderingHints hints) {
054: /* Get ImageLayout and TileCache from RenderingHints. */
055: ImageLayout layout = RIFUtil.getImageLayoutHint(hints);
056:
057: if (!MediaLibAccessor
058: .isMediaLibCompatible(new ParameterBlock())) {
059: return null;
060: }
061:
062: RenderedImage source = args.getRenderedSource(0);
063: EnumeratedParameter scalingType = (EnumeratedParameter) args
064: .getObjectParameter(0);
065: EnumeratedParameter dataNature = (EnumeratedParameter) args
066: .getObjectParameter(1);
067:
068: boolean isComplexSource = !dataNature
069: .equals(DFTDescriptor.REAL_TO_COMPLEX);
070: int numSourceBands = source.getSampleModel().getNumBands();
071:
072: // Use the two-dimensional mediaLib DFT if possible: it supports
073: // only data which have a single component (real or complex)
074: // per pixel and which have dimensions which are equal to a positive
075: // power of 2.
076: if (((isComplexSource && numSourceBands == 2) || (!isComplexSource && numSourceBands == 1))
077: && MlibDFTOpImage.isAcceptableSampleModel(source
078: .getSampleModel())) {
079: // If necessary, pad the source to ensure that
080: // both dimensions are positive powers of 2.
081: int sourceWidth = source.getWidth();
082: int sourceHeight = source.getHeight();
083: if (!MathJAI.isPositivePowerOf2(sourceWidth)
084: || !MathJAI.isPositivePowerOf2(sourceHeight)) {
085: ParameterBlock pb = new ParameterBlock();
086: pb.addSource(source);
087: pb.add(0);
088: pb.add(MathJAI.nextPositivePowerOf2(sourceWidth)
089: - sourceWidth);
090: pb.add(0);
091: pb.add(MathJAI.nextPositivePowerOf2(sourceHeight)
092: - sourceHeight);
093: pb.add(BorderExtender
094: .createInstance(BorderExtender.BORDER_ZERO));
095: source = JAI.create("border", pb, null);
096: }
097:
098: return new MlibDFTOpImage(source, hints, layout,
099: dataNature, true, scalingType);
100: } else { // General case
101: FFT fft = new FFTmediaLib(true, new Integer(scalingType
102: .getValue()), 2);
103:
104: return new DFTOpImage(source, hints, layout, dataNature,
105: fft);
106: }
107: }
108: }
|