001: /*
002: * $RCSfile: FCT.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:25 $
010: * $State: Exp $
011: */
012: package com.sun.media.jai.opimage;
013:
014: import java.awt.image.DataBuffer;
015: import javax.media.jai.operator.DFTDescriptor;
016: import com.sun.media.jai.util.MathJAI;
017:
018: /**
019: * The Fast Cosine Transform (FCT) class.
020: *
021: * @since EA3
022: */
023: public class FCT {
024: /*
025: * Flag indicating whether the transform is forward (true)
026: * or inverse (false).
027: */
028: protected boolean isForwardTransform;
029:
030: /** The FFT object by which the FCT is actually calculated. */
031: private FFT fft = null;
032:
033: /** Default constructor */
034: public FCT() {
035: }
036:
037: /**
038: * Construct a new FCT object.
039: *
040: * @param length The length of the FCT; must be a positive power of 2.
041: */
042: public FCT(boolean isForwardTransform, int length) {
043: // Cache the directional flag.
044: this .isForwardTransform = isForwardTransform;
045:
046: // Create the FFT object.
047: fft = new FFT(isForwardTransform, new Integer(
048: DFTDescriptor.SCALING_NONE.getValue()), length);
049: }
050:
051: /**
052: * Initialize the length-dependent fields.
053: *
054: * @param length The length of the FCT; must be a positive power of 2.
055: */
056: public void setLength(int length) {
057: fft.setLength(length);
058: }
059:
060: /**
061: * Set the internal work data array of the FCT object.
062: *
063: * @param dataType The data type of the source data according to
064: * one of the DataBuffer TYPE_* flags. This should be either
065: * DataBuffer.TYPE_FLOAT or DataBuffer.TYPE_DOUBLE.
066: * @param data Float or double array of data.
067: * @param offset Offset into the data array.
068: * @param stride The data array stride value.
069: * @param count The number of values to copy.
070: */
071: public void setData(int dataType, Object data, int offset,
072: int stride, int count) {
073: if (isForwardTransform) {
074: fft.setFCTData(dataType, data, offset, stride, count);
075: } else {
076: fft.setIFCTData(dataType, data, offset, stride, count);
077: }
078: }
079:
080: /**
081: * Get data from the internal work data array of the FCT object.
082: *
083: * @param dataType The data type of the source data according to
084: * one of the DataBuffer TYPE_* flags. This should be either
085: * DataBuffer.TYPE_FLOAT or DataBuffer.TYPE_DOUBLE.
086: * @param data Float or double array of data.
087: * @param offset Offset into the data array.
088: * @param stride The data array stride value.
089: */
090: public void getData(int dataType, Object data, int offset,
091: int stride) {
092: if (isForwardTransform) {
093: fft.getFCTData(dataType, data, offset, stride);
094: } else {
095: fft.getIFCTData(dataType, data, offset, stride);
096: }
097: }
098:
099: /**
100: * Calculate the DCT of a sequence using the FCT algorithm.
101: */
102: public void transform() {
103: fft.transform();
104: }
105: }
|