www.pudn.com > vcmatlab20060426WaterMark.zip > dct2.cpp
//
// MATLAB Compiler: 2.2
// Date: Mon May 16 12:44:11 2005
// 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" "C_dct2"
//
#include "dct2.hpp"
#include "images_private_dct.hpp"
#include "libmatlbm.hpp"
static mxChar _array1_[126] = { 'R', 'u', 'n', '-', 't', 'i', 'm', 'e', ' ',
'E', 'r', 'r', 'o', 'r', ':', ' ', 'F', 'i',
'l', 'e', ':', ' ', 'd', 'c', 't', '2', ' ',
'L', 'i', 'n', 'e', ':', ' ', '1', ' ', 'C',
'o', 'l', 'u', 'm', 'n', ':', ' ', '1', ' ',
'T', 'h', 'e', ' ', 'f', 'u', 'n', 'c', 't',
'i', 'o', 'n', ' ', '"', 'd', 'c', 't', '2',
'"', ' ', 'w', 'a', 's', ' ', 'c', 'a', 'l',
'l', 'e', 'd', ' ', 'w', 'i', 't', 'h', ' ',
'm', 'o', 'r', 'e', ' ', 't', 'h', 'a', 'n',
' ', 't', 'h', 'e', ' ', 'd', 'e', 'c', 'l',
'a', 'r', 'e', 'd', ' ', 'n', 'u', 'm', 'b',
'e', 'r', ' ', 'o', 'f', ' ', 'o', 'u', 't',
'p', 'u', 't', 's', ' ', '(', '1', ')', '.' };
static mwArray _mxarray0_ = mclInitializeString(126, _array1_);
static mxChar _array3_[125] = { 'R', 'u', 'n', '-', 't', 'i', 'm', 'e', ' ',
'E', 'r', 'r', 'o', 'r', ':', ' ', 'F', 'i',
'l', 'e', ':', ' ', 'd', 'c', 't', '2', ' ',
'L', 'i', 'n', 'e', ':', ' ', '1', ' ', 'C',
'o', 'l', 'u', 'm', 'n', ':', ' ', '1', ' ',
'T', 'h', 'e', ' ', 'f', 'u', 'n', 'c', 't',
'i', 'o', 'n', ' ', '"', 'd', 'c', 't', '2',
'"', ' ', 'w', 'a', 's', ' ', 'c', 'a', 'l',
'l', 'e', 'd', ' ', 'w', 'i', 't', 'h', ' ',
'm', 'o', 'r', 'e', ' ', 't', 'h', 'a', 'n',
' ', 't', 'h', 'e', ' ', 'd', 'e', 'c', 'l',
'a', 'r', 'e', 'd', ' ', 'n', 'u', 'm', 'b',
'e', 'r', ' ', 'o', 'f', ' ', 'i', 'n', 'p',
'u', 't', 's', ' ', '(', '3', ')', '.' };
static mwArray _mxarray2_ = mclInitializeString(125, _array3_);
static mwArray _mxarray4_ = mclInitializeDouble(1.0);
static mwArray _mxarray5_ = mclInitializeDouble(0.0);
static mwArray _mxarray6_ = 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:\matlab\matlab\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(mclGetUninitializedArray());
b = Mdct2(nargout, arg1, mrows, ncols);
return b;
}
//
// The function "mlxDct2" contains the feval interface for the "dct2"
// M-function from file "D:\matlab\matlab\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;
mclCppUninitializeArrays(1, mplhs);
if (nlhs > 1) {
error(_mxarray0_);
}
if (nrhs > 3) {
error(_mxarray2_);
}
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:\matlab\matlab\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:\\matlab\\matlab\\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(mclGetUninitializedArray());
mwArray npad(mclGetUninitializedArray());
mwArray mpad(mclGetUninitializedArray());
mwArray a(mclGetUninitializedArray());
mwArray n(mclGetUninitializedArray());
mwArray m(mclGetUninitializedArray());
//
// %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 of class double or of any integer class. 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-2001 The MathWorks, Inc.
// % $Revision: 5.19 $ $Date: 2001/02/28 15:29:58 $
//
// % 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") > _mxarray4_);
if (tobool(a_) && tobool(a_ & mwVv(n, "n") > _mxarray4_)) {
//
// b = dct(dct(arg1).').';
//
mclMline(49);
b
= transpose(
mwVe(
images_private_dct(
transpose(
mwVe(images_private_dct(mwVa(arg1, "arg1")))))));
//
// return;
//
mclMline(50);
goto return_;
//
// else
//
} else {
//
// mrows = m;
//
mclMline(52);
mrows = mwVsv(m, "m");
//
// ncols = n;
//
mclMline(53);
ncols = mwVsv(n, "n");
}
//
// end
// end
//
mclMline(55);
}
//
//
// % Padding for vector input.
// a = arg1;
//
mclMline(58);
a = mwVsa(arg1, "arg1");
//
// if nargin==2, ncols = mrows(2); mrows = mrows(1); end
//
mclMline(59);
if (nargin_ == 2) {
ncols = mclIntArrayRef(mwVsa(mrows, "mrows"), 2);
mrows = mclIntArrayRef(mwVsa(mrows, "mrows"), 1);
}
//
// mpad = mrows; npad = ncols;
//
mclMline(60);
mpad = mwVsa(mrows, "mrows");
npad = mwVsa(ncols, "ncols");
//
// if m == 1 & mpad > m, a(2, 1) = 0; m = 2; end
//
mclMline(61);
{
mwArray a_(mwVv(m, "m") == _mxarray4_);
if (tobool(a_) && tobool(a_ & mwVv(mpad, "mpad") > mwVv(m, "m"))) {
mclIntArrayAssign(&a, _mxarray5_, 2, 1);
m = _mxarray6_;
} else {
}
}
//
// if n == 1 & npad > n, a(1, 2) = 0; n = 2; end
//
mclMline(62);
{
mwArray a_(mwVv(n, "n") == _mxarray4_);
if (tobool(a_) && tobool(a_ & mwVv(npad, "npad") > mwVv(n, "n"))) {
mclIntArrayAssign(&a, _mxarray5_, 1, 2);
n = _mxarray6_;
} else {
}
}
//
// if m == 1, mpad = npad; npad = 1; end % For row vector.
//
mclMline(63);
if (mclEqBool(mwVv(m, "m"), _mxarray4_)) {
mpad = mwVsv(npad, "npad");
npad = _mxarray4_;
}
//
//
// % 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") > _mxarray4_);
if (tobool(a_) && tobool(a_ & mwVv(n, "n") > _mxarray4_)) {
b
= transpose(
mwVe(
images_private_dct(
transpose(mwVv(b, "b")), mwVv(npad, "npad"))));
} else {
}
}
return_:
mwValidateOutput(b, 1, nargout_, "b", "dct2");
mclMlineFunctionReturn()
return b;
mclMlineExitFunctionReturn();
}