⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dct2.cpp

📁 一篇有关数字水印的程序
💻 CPP
字号:
//
// MATLAB Compiler: 3.0
// Date: Wed Apr 25 16:41:03 2007
// Arguments: "-B" "macro_default" "-O" "all" "-O" "fold_scalar_mxarrays:on"
// "-O" "fold_non_scalar_mxarrays:on" "-O" "optimize_integer_for_loops:on" "-O"
// "array_indexing:on" "-O" "optimize_conditionals:on" "-B" "sglcpp" "-p" "-W"
// "main" "-L" "Cpp" "-t" "-T" "link:exe" "-h" "libmmfile.mlib" "-W" "mainhg"
// "libmwsglm.mlib" "-l" "-p" "-W" "main" "-L" "Cpp" "-t" "-T" "link:exe" "-h"
// "libmmfile.mlib" "-h" "dct2.m" 
//
#include "dct2.hpp"
#include "images_private_dct.hpp"
#include "libmatlbm.hpp"
static mwArray _mxarray0_ = mclInitializeDouble(1.0);
static mwArray _mxarray1_ = mclInitializeDouble(0.0);
static mwArray _mxarray2_ = mclInitializeDouble(2.0);

void InitializeModule_dct2() {
}

void TerminateModule_dct2() {
}

static mwArray Mdct2(int nargout_, mwArray arg1, mwArray mrows, mwArray ncols);

_mexLocalFunctionTable _local_function_table_dct2
  = { 0, (mexFunctionTableEntry *)NULL };

//
// The function "dct2" contains the normal interface for the "dct2" M-function
// from file "d:\matlab6p5\toolbox\images\images\dct2.m" (lines 1-69). This
// function processes any input arguments and passes them to the implementation
// version of the function, appearing above.
//
mwArray dct2(mwArray arg1, mwArray mrows, mwArray ncols) {
    int nargout = 1;
    mwArray b = mwArray::UNDEFINED;
    b = Mdct2(nargout, arg1, mrows, ncols);
    return b;
}

//
// The function "mlxDct2" contains the feval interface for the "dct2"
// M-function from file "d:\matlab6p5\toolbox\images\images\dct2.m" (lines
// 1-69). The feval function calls the implementation version of dct2 through
// this function. This function processes any input arguments and passes them
// to the implementation version of the function, appearing above.
//
void mlxDct2(int nlhs, mxArray * plhs[], int nrhs, mxArray * prhs[]) {
    MW_BEGIN_MLX();
    {
        mwArray mprhs[3];
        mwArray mplhs[1];
        int i;
        mclCppUndefineArrays(1, mplhs);
        if (nlhs > 1) {
            error(
              mwVarargin(
                mwArray(
                  "Run-time Error: File: dct2 Line: 1 Column: 1"
                  " The function \"dct2\" was called with more "
                  "than the declared number of outputs (1).")));
        }
        if (nrhs > 3) {
            error(
              mwVarargin(
                mwArray(
                  "Run-time Error: File: dct2 Line: 1 Column: 1"
                  " The function \"dct2\" was called with more "
                  "than the declared number of inputs (3).")));
        }
        for (i = 0; i < 3 && i < nrhs; ++i) {
            mprhs[i] = mwArray(prhs[i], 0);
        }
        for (; i < 3; ++i) {
            mprhs[i].MakeDIN();
        }
        mplhs[0] = Mdct2(nlhs, mprhs[0], mprhs[1], mprhs[2]);
        plhs[0] = mplhs[0].FreezeData();
    }
    MW_END_MLX();
}

//
// The function "Mdct2" is the implementation version of the "dct2" M-function
// from file "d:\matlab6p5\toolbox\images\images\dct2.m" (lines 1-69). It
// contains the actual compiled code for that M-function. It is a static
// function and must only be called from one of the interface functions,
// appearing below.
//
//
// function b=dct2(arg1,mrows,ncols)
//
static mwArray Mdct2(int nargout_, mwArray arg1, mwArray mrows, mwArray ncols) {
    mclMlineEnterFunction(
      "d:\\matlab6p5\\toolbox\\images\\images\\dct2.m", "dct2")
    mwLocalFunctionTable save_local_function_table_
      = &_local_function_table_dct2;
    int nargin_ = nargin(3, mwVarargin(arg1, mrows, ncols));
    mwArray b = mwArray::UNDEFINED;
    mwArray npad = mwArray::UNDEFINED;
    mwArray mpad = mwArray::UNDEFINED;
    mwArray a = mwArray::UNDEFINED;
    mwArray n = mwArray::UNDEFINED;
    mwArray m = mwArray::UNDEFINED;
    //
    // %DCT2 Compute 2-D discrete cosine transform.
    // %   B = DCT2(A) returns the discrete cosine transform of A.
    // %   The matrix B is the same size as A and contains the
    // %   discrete cosine transform coefficients.
    // %
    // %   B = DCT2(A,[M N]) or B = DCT2(A,M,N) pads the matrix A with
    // %   zeros to size M-by-N before transforming. If M or N is
    // %   smaller than the corresponding dimension of A, DCT2 truncates
    // %   A. 
    // %
    // %   This transform can be inverted using IDCT2.
    // %
    // %   Class Support
    // %   -------------
    // %   A can be numeric or logical. The returned matrix B is of 
    // %   class double.
    // %
    // %   Example
    // %   -------
    // %       RGB = imread('autumn.tif');
    // %       I = rgb2gray(RGB);
    // %       J = dct2(I);
    // %       imshow(log(abs(J)),[]), colormap(jet), colorbar
    // %
    // %   The commands below set values less than magnitude 10 in the
    // %   DCT matrix to zero, then reconstruct the image using the
    // %   inverse DCT function IDCT2.
    // %
    // %       J(abs(J)<10) = 0;
    // %       K = idct2(J);
    // %       imshow(I), figure, imshow(K,[0 255])
    // %
    // %   See also FFT2, IDCT2, IFFT2.
    // 
    // %   Copyright 1993-2002 The MathWorks, Inc.  
    // %   $Revision: 5.22 $  $Date: 2002/03/28 20:41:59 $
    // 
    // %   References: 
    // %        1) A. K. Jain, "Fundamentals of Digital Image
    // %           Processing", pp. 150-153.
    // %        2) Wallace, "The JPEG Still Picture Compression Standard",
    // %           Communications of the ACM, April 1991.
    // 
    // [m, n] = size(arg1);
    //
    mclMline(45);
    size(mwVarargout(m, n), mwVa(arg1, "arg1"));
    //
    // % Basic algorithm.
    // if (nargin == 1),
    //
    mclMline(47);
    if (nargin_ == 1) {
        //
        // if (m > 1) & (n > 1),
        //
        mclMline(48);
        mwArray a_ = mwVv(m, "m") > _mxarray0_;
        if (tobool(a_) && tobool(a_ & mwVv(n, "n") > _mxarray0_)) {
            //
            // b = dct(dct(arg1).').';
            //
            mclMline(49);
            b
              = transpose(
                  images_private_dct(
                    transpose(images_private_dct(mwVa(arg1, "arg1")))));
            //
            // return;
            //
            mclMline(50);
            goto return_;
        //
        // else
        //
        } else {
            //
            // mrows = m;
            //
            mclMline(52);
            mrows = mwVv(m, "m");
            //
            // ncols = n;
            //
            mclMline(53);
            ncols = mwVv(n, "n");
        }
    //
    // end
    // end
    //
    mclMline(55);
    }
    //
    // 
    // % Padding for vector input.
    // a = arg1;
    //
    mclMline(58);
    a = mwVa(arg1, "arg1");
    //
    // if nargin==2, ncols = mrows(2); mrows = mrows(1); end
    //
    mclMline(59);
    if (nargin_ == 2) {
        ncols = mclIntArrayRef(mwVa(mrows, "mrows"), 2);
        mrows = mclIntArrayRef(mwVa(mrows, "mrows"), 1);
    }
    //
    // mpad = mrows; npad = ncols;
    //
    mclMline(60);
    mpad = mwVa(mrows, "mrows");
    npad = mwVa(ncols, "ncols");
    //
    // if m == 1 & mpad > m, a(2, 1) = 0; m = 2; end
    //
    mclMline(61);
    {
        mwArray a_ = mwVv(m, "m") == _mxarray0_;
        if (tobool(a_) && tobool(a_ & mwVv(mpad, "mpad") > mwVv(m, "m"))) {
            mclIntArrayAssign(&a, _mxarray1_, 2, 1);
            m = _mxarray2_;
        } else {
        }
    }
    //
    // if n == 1 & npad > n, a(1, 2) = 0; n = 2; end
    //
    mclMline(62);
    {
        mwArray a_ = mwVv(n, "n") == _mxarray0_;
        if (tobool(a_) && tobool(a_ & mwVv(npad, "npad") > mwVv(n, "n"))) {
            mclIntArrayAssign(&a, _mxarray1_, 1, 2);
            n = _mxarray2_;
        } else {
        }
    }
    //
    // if m == 1, mpad = npad; npad = 1; end   % For row vector.
    //
    mclMline(63);
    if (mclEqBool(mwVv(m, "m"), _mxarray0_)) {
        mpad = mwVv(npad, "npad");
        npad = _mxarray0_;
    }
    //
    // 
    // % Transform.
    // 
    // b = dct(a, mpad);
    //
    mclMline(67);
    b = images_private_dct(mwVv(a, "a"), mwVv(mpad, "mpad"));
    //
    // if m > 1 & n > 1, b = dct(b.', npad).'; end
    //
    mclMline(68);
    {
        mwArray a_ = mwVv(m, "m") > _mxarray0_;
        if (tobool(a_) && tobool(a_ & mwVv(n, "n") > _mxarray0_)) {
            b
              = transpose(
                  images_private_dct(
                    transpose(mwVv(b, "b")), mwVv(npad, "npad")));
        } else {
        }
    }
    return_:
    mwValidateOutput(b, 1, nargout_, "b", "dct2");
    mclMlineFunctionReturn()
    return b;
    mclMlineExitFunctionReturn();
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -