www.pudn.com > vcmatlab20060426WaterMark.zip > imread.cpp


// 
// MATLAB Compiler: 2.2 
// Date: Tue May 10 11:47:29 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" "huatu"  
// 
#include "imread.hpp" 
#include "iofun_private_imftype.hpp" 
#include "iofun_private_readbmp.hpp" 
#include "iofun_private_readcur.hpp" 
#include "iofun_private_readgif.hpp" 
#include "iofun_private_readhdf.hpp" 
#include "iofun_private_readico.hpp" 
#include "iofun_private_readjpg.hpp" 
#include "iofun_private_readpcx.hpp" 
#include "iofun_private_readpng.hpp" 
#include "iofun_private_readtif.hpp" 
#include "iofun_private_readxwd.hpp" 
#include "libmatlbm.hpp" 
#include "libmmfile.hpp" 
 
static mxChar _array1_[130] = { 'R', 'u', 'n', '-', 't', 'i', 'm', 'e', ' ', 
                                'E', 'r', 'r', 'o', 'r', ':', ' ', 'F', 'i', 
                                'l', 'e', ':', ' ', 'i', 'm', 'r', 'e', 'a', 
                                'd', ' ', 'L', 'i', 'n', 'e', ':', ' ', '1', 
                                ' ', 'C', 'o', 'l', 'u', 'm', 'n', ':', ' ', 
                                '1', ' ', 'T', 'h', 'e', ' ', 'f', 'u', 'n', 
                                'c', 't', 'i', 'o', 'n', ' ', '"', 'i', 'm', 
                                'r', 'e', 'a', 'd', '"', ' ', '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', ' ', 
                                '(', '3', ')', '.' }; 
static mwArray _mxarray0_ = mclInitializeString(130, _array1_); 
 
static mxChar _array3_[158] = { 'R', 'u', 'n', '-', 't', 'i', 'm', 'e', ' ', 
                                'E', 'r', 'r', 'o', 'r', ':', ' ', 'F', 'i', 
                                'l', 'e', ':', ' ', 'i', 'm', 'r', 'e', 'a', 
                                'd', '/', 'p', 'a', 'r', 's', 'e', '_', 'i', 
                                'n', 'p', 'u', 't', 's', ' ', 'L', 'i', 'n', 
                                'e', ':', ' ', '2', '7', '3', ' ', 'C', 'o', 
                                'l', 'u', 'm', 'n', ':', ' ', '1', ' ', 'T', 
                                'h', 'e', ' ', 'f', 'u', 'n', 'c', 't', 'i', 
                                'o', 'n', ' ', '"', 'i', 'm', 'r', 'e', 'a', 
                                'd', '/', 'p', 'a', 'r', 's', 'e', '_', 'i', 
                                'n', 'p', 'u', 't', 's', '"', ' ', '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', 
                                ' ', '(', '4', ')', '.' }; 
static mwArray _mxarray2_ = mclInitializeString(158, _array3_); 
 
static mxChar _array5_[1] = { 'r' }; 
static mwArray _mxarray4_ = mclInitializeString(1, _array5_); 
static mwArray _mxarray6_ = mclInitializeDouble(-1.0); 
 
static mxChar _array8_[90] = { 'C', 'a', 'n', 0x0027, 't', ' ', 'o', 'p', 'e', 
                               'n', ' ', 'f', 'i', 'l', 'e', ' ', '"', '%', 
                               's', '"', ' ', 'f', 'o', 'r', ' ', 'r', 'e', 
                               'a', 'd', 'i', 'n', 'g', ';', 0x005c, 'n', ' ', 
                               'i', 't', ' ', 'm', 'a', 'y', ' ', 'n', 'o', 
                               't', ' ', 'e', 'x', 'i', 's', 't', ',', ' ', 
                               'o', 'r', ' ', 'y', 'o', 'u', ' ', 'm', 'a', 
                               'y', ' ', 'n', 'o', 't', ' ', 'h', 'a', 'v', 
                               'e', ' ', 'r', 'e', 'a', 'd', ' ', 'p', 'e', 
                               'r', 'm', 'i', 's', 's', 'i', 'o', 'n', '.' }; 
static mwArray _mxarray7_ = mclInitializeString(90, _array8_); 
 
static mxChar _array10_[35] = { 'U', 'n', 'a', 'b', 'l', 'e', ' ', 't', 'o', 
                                ' ', 'd', 'e', 't', 'e', 'r', 'm', 'i', 'n', 
                                'e', ' ', 't', 'h', 'e', ' ', 'f', 'i', 'l', 
                                'e', ' ', 'f', 'o', 'r', 'm', 'a', 't' }; 
static mwArray _mxarray9_ = mclInitializeString(35, _array10_); 
 
static mxChar _array12_[3] = { 't', 'i', 'f' }; 
static mwArray _mxarray11_ = mclInitializeString(3, _array12_); 
 
static mxChar _array14_[4] = { '.', 't', 'i', 'f' }; 
static mwArray _mxarray13_ = mclInitializeString(4, _array14_); 
 
static mxChar _array16_[5] = { '.', 't', 'i', 'f', 'f' }; 
static mwArray _mxarray15_ = mclInitializeString(5, _array16_); 
 
static mxChar _array18_[3] = { 'b', 'm', 'p' }; 
static mwArray _mxarray17_ = mclInitializeString(3, _array18_); 
 
static mxChar _array20_[4] = { '.', 'b', 'm', 'p' }; 
static mwArray _mxarray19_ = mclInitializeString(4, _array20_); 
 
static mxChar _array22_[3] = { 'h', 'd', 'f' }; 
static mwArray _mxarray21_ = mclInitializeString(3, _array22_); 
 
static mxChar _array24_[4] = { '.', 'h', 'd', 'f' }; 
static mwArray _mxarray23_ = mclInitializeString(4, _array24_); 
 
static mxChar _array26_[3] = { 'p', 'c', 'x' }; 
static mwArray _mxarray25_ = mclInitializeString(3, _array26_); 
 
static mxChar _array28_[4] = { '.', 'p', 'c', 'x' }; 
static mwArray _mxarray27_ = mclInitializeString(4, _array28_); 
 
static mxChar _array30_[3] = { 'x', 'w', 'd' }; 
static mwArray _mxarray29_ = mclInitializeString(3, _array30_); 
 
static mxChar _array32_[4] = { '.', 'x', 'w', 'd' }; 
static mwArray _mxarray31_ = mclInitializeString(4, _array32_); 
 
static mxChar _array34_[3] = { 'j', 'p', 'g' }; 
static mwArray _mxarray33_ = mclInitializeString(3, _array34_); 
 
static mxChar _array36_[4] = { '.', 'j', 'p', 'g' }; 
static mwArray _mxarray35_ = mclInitializeString(4, _array36_); 
 
static mxChar _array38_[5] = { '.', 'j', 'p', 'e', 'g' }; 
static mwArray _mxarray37_ = mclInitializeString(5, _array38_); 
 
static mxChar _array40_[3] = { 'p', 'n', 'g' }; 
static mwArray _mxarray39_ = mclInitializeString(3, _array40_); 
 
static mxChar _array42_[4] = { '.', 'p', 'n', 'g' }; 
static mwArray _mxarray41_ = mclInitializeString(4, _array42_); 
 
static mxChar _array44_[3] = { 'g', 'i', 'f' }; 
static mwArray _mxarray43_ = mclInitializeString(3, _array44_); 
 
static mxChar _array46_[4] = { '.', 'g', 'i', 'f' }; 
static mwArray _mxarray45_ = mclInitializeString(4, _array46_); 
 
static mxChar _array48_[3] = { 'c', 'u', 'r' }; 
static mwArray _mxarray47_ = mclInitializeString(3, _array48_); 
 
static mxChar _array50_[4] = { '.', 'c', 'u', 'r' }; 
static mwArray _mxarray49_ = mclInitializeString(4, _array50_); 
 
static mxChar _array52_[3] = { 'i', 'c', 'o' }; 
static mwArray _mxarray51_ = mclInitializeString(3, _array52_); 
 
static mxChar _array54_[4] = { '.', 'i', 'c', 'o' }; 
static mwArray _mxarray53_ = mclInitializeString(4, _array54_); 
 
static mxChar _array56_[32] = { 'C', 'a', 'n', 0x0027, 't', ' ', 'o', 'p', 
                                'e', 'n', ' ', 'f', 'i', 'l', 'e', ' ', 
                                '"', '%', 's', '"', ' ', 'f', 'o', 'r', 
                                ' ', 'r', 'e', 'a', 'd', 'i', 'n', 'g' }; 
static mwArray _mxarray55_ = mclInitializeString(32, _array56_); 
static mwArray _mxarray57_ = mclInitializeDoubleVector(0, 0, (double *)NULL); 
 
static mxChar _array59_[39] = { 'U', 'n', 'r', 'e', 'c', 'o', 'g', 'n', 
                                'i', 'z', 'e', 'd', ' ', 'o', 'r', ' ', 
                                'u', 'n', 's', 'u', 'p', 'p', 'o', 'r', 
                                't', 'e', 'd', ' ', 'f', 'o', 'r', 'm', 
                                'a', 't', ' ', '"', '%', 's', '"' }; 
static mwArray _mxarray58_ = mclInitializeString(39, _array59_); 
static mwArray _mxarray60_ = mclInitializeCharVector(0, 0, (mxChar *)NULL); 
static mwArray _mxarray61_ = mclInitializeCellVector(0, 0, (mxArray * *)NULL); 
 
static mxChar _array63_[30] = { 'b', 'x', 'p', 'h', 't', 'j', 'p', 'g', 
                                'c', 'i', 'm', 'w', 'c', 'd', 'i', 'p', 
                                'n', 'i', 'u', 'c', 'p', 'd', 'x', 'f', 
                                'f', 'g', 'g', 'f', 'r', 'o' }; 
static mwArray _mxarray62_ = mclInitializeCharVector(10, 3, _array63_); 
static mwArray _mxarray64_ = mclInitializeDouble(0.0); 
 
static mxChar _array66_[23] = { 'T', 'o', 'o', ' ', 'f', 'e', 'w', ' ', 
                                'i', 'n', 'p', 'u', 't', ' ', 'a', 'r', 
                                'g', 'u', 'm', 'e', 'n', 't', 's' }; 
static mwArray _mxarray65_ = mclInitializeString(23, _array66_); 
static mwArray _mxarray67_ = mclInitializeDouble(1.0); 
static mwArray _mxarray68_ = mclInitializeDouble(2.0); 
 
static mxChar _array70_[4] = { 't', 'i', 'f', 'f' }; 
static mwArray _mxarray69_ = mclInitializeString(4, _array70_); 
 
static mxChar _array72_[4] = { 'j', 'p', 'e', 'g' }; 
static mwArray _mxarray71_ = mclInitializeString(4, _array72_); 
 
static mxChar _array74_[5] = { 'e', 'x', 'a', 'c', 't' }; 
static mwArray _mxarray73_ = mclInitializeString(5, _array74_); 
static mwArray _mxarray75_ = mclInitializeDouble(3.0); 
 
void InitializeModule_imread() { 
} 
 
void TerminateModule_imread() { 
} 
 
static mwArray imread_parse_inputs(mwArray * format, 
                                   mwArray * extraArgs, 
                                   mwArray * msg, 
                                   mwVarargin varargin = mwVarargin::DIN); 
#ifdef __cplusplus 
extern "C" 
#endif 
void mlxImread_parse_inputs(int nlhs, 
                            mxArray * plhs[], 
                            int nrhs, 
                            mxArray * prhs[]); 
static mwArray Mimread(mwArray * map, 
                       mwArray * alpha, 
                       int nargout_, 
                       mwArray varargin); 
static mwArray Mimread_parse_inputs(mwArray * format, 
                                    mwArray * extraArgs, 
                                    mwArray * msg, 
                                    int nargout_, 
                                    mwArray varargin); 
 
static mexFunctionTableEntry local_function_table_[1] 
  = { { "parse_inputs", mlxImread_parse_inputs, -1, 4, NULL } }; 
 
_mexLocalFunctionTable _local_function_table_imread 
  = { 1, local_function_table_ }; 
 
// 
// The function "Nimread" contains the nargout interface for the "imread" 
// M-function from file "D:\matlab\matlab\toolbox\matlab\iofun\imread.m" (lines 
// 1-273). This interface is only produced if the M-function uses the special 
// variable "nargout". The nargout interface allows the number of requested 
// outputs to be specified via the nargout argument, as opposed to the normal 
// interface which dynamically calculates the number of outputs based on the 
// number of non-NULL inputs it receives. This function processes any input 
// arguments and passes them to the implementation version of the function, 
// appearing above. 
// 
mwArray Nimread(int nargout, 
                mwArray * map, 
                mwArray * alpha, 
                mwVarargin varargin) { 
    mwArray X(mclGetUninitializedArray()); 
    mwArray map__(mclGetUninitializedArray()); 
    mwArray alpha__(mclGetUninitializedArray()); 
    X = Mimread(&map__, &alpha__, nargout, varargin.ToArray()); 
    if (map != NULL) { 
        *map = map__; 
    } 
    if (alpha != NULL) { 
        *alpha = alpha__; 
    } 
    return X; 
} 
 
// 
// The function "imread" contains the normal interface for the "imread" 
// M-function from file "D:\matlab\matlab\toolbox\matlab\iofun\imread.m" (lines 
// 1-273). This function processes any input arguments and passes them to the 
// implementation version of the function, appearing above. 
// 
mwArray imread(mwArray * map, mwArray * alpha, mwVarargin varargin) { 
    int nargout(1); 
    mwArray X(mclGetUninitializedArray()); 
    mwArray map__(mclGetUninitializedArray()); 
    mwArray alpha__(mclGetUninitializedArray()); 
    if (map != NULL) { 
        ++nargout; 
    } 
    if (alpha != NULL) { 
        ++nargout; 
    } 
    X = Mimread(&map__, &alpha__, nargout, varargin.ToArray()); 
    if (map != NULL) { 
        *map = map__; 
    } 
    if (alpha != NULL) { 
        *alpha = alpha__; 
    } 
    return X; 
} 
 
// 
// The function "Vimread" contains the void interface for the "imread" 
// M-function from file "D:\matlab\matlab\toolbox\matlab\iofun\imread.m" (lines 
// 1-273). The void interface is only produced if the M-function uses the 
// special variable "nargout", and has at least one output. The void interface 
// function specifies zero output arguments to the implementation version of 
// the function, and in the event that the implementation version still returns 
// an output (which, in MATLAB, would be assigned to the "ans" variable), it 
// deallocates the output. This function processes any input arguments and 
// passes them to the implementation version of the function, appearing above. 
// 
void Vimread(mwVarargin varargin) { 
    mwArray X(mwArray::UNDEFINED); 
    mwArray map(mwArray::UNDEFINED); 
    mwArray alpha(mwArray::UNDEFINED); 
    X = Mimread(&map, &alpha, 0, varargin.ToArray()); 
} 
 
// 
// The function "mlxImread" contains the feval interface for the "imread" 
// M-function from file "D:\matlab\matlab\toolbox\matlab\iofun\imread.m" (lines 
// 1-273). The feval function calls the implementation version of imread 
// through this function. This function processes any input arguments and 
// passes them to the implementation version of the function, appearing above. 
// 
void mlxImread(int nlhs, mxArray * plhs[], int nrhs, mxArray * prhs[]) { 
    MW_BEGIN_MLX(); 
    { 
        mwArray mprhs[1]; 
        mwArray mplhs[3]; 
        int i; 
        mclCppUninitializeArrays(3, mplhs); 
        if (nlhs > 3) { 
            error(_mxarray0_); 
        } 
        mprhs[0] = mclCreateVararginCell(nrhs, prhs); 
        mplhs[0] = Mimread(&mplhs[1], &mplhs[2], nlhs, mprhs[0]); 
        plhs[0] = mplhs[0].FreezeData(); 
        for (i = 1; i < 3 && i < nlhs; ++i) { 
            plhs[i] = mplhs[i].FreezeData(); 
        } 
    } 
    MW_END_MLX(); 
} 
 
// 
// The function "imread_parse_inputs" contains the normal interface for the 
// "imread/parse_inputs" M-function from file 
// "D:\matlab\matlab\toolbox\matlab\iofun\imread.m" (lines 273-324). This 
// function processes any input arguments and passes them to the implementation 
// version of the function, appearing above. 
// 
static mwArray imread_parse_inputs(mwArray * format, 
                                   mwArray * extraArgs, 
                                   mwArray * msg, 
                                   mwVarargin varargin) { 
    int nargout(1); 
    mwArray filename(mclGetUninitializedArray()); 
    mwArray format__(mclGetUninitializedArray()); 
    mwArray extraArgs__(mclGetUninitializedArray()); 
    mwArray msg__(mclGetUninitializedArray()); 
    if (format != NULL) { 
        ++nargout; 
    } 
    if (extraArgs != NULL) { 
        ++nargout; 
    } 
    if (msg != NULL) { 
        ++nargout; 
    } 
    filename 
      = Mimread_parse_inputs( 
          &format__, &extraArgs__, &msg__, nargout, varargin.ToArray()); 
    if (format != NULL) { 
        *format = format__; 
    } 
    if (extraArgs != NULL) { 
        *extraArgs = extraArgs__; 
    } 
    if (msg != NULL) { 
        *msg = msg__; 
    } 
    return filename; 
} 
 
// 
// The function "mlxImread_parse_inputs" contains the feval interface for the 
// "imread/parse_inputs" M-function from file 
// "D:\matlab\matlab\toolbox\matlab\iofun\imread.m" (lines 273-324). The feval 
// function calls the implementation version of imread/parse_inputs through 
// this function. This function processes any input arguments and passes them 
// to the implementation version of the function, appearing above. 
// 
void mlxImread_parse_inputs(int nlhs, 
                            mxArray * plhs[], 
                            int nrhs, 
                            mxArray * prhs[]) { 
    MW_BEGIN_MLX(); 
    { 
        mwArray mprhs[1]; 
        mwArray mplhs[4]; 
        int i; 
        mclCppUninitializeArrays(4, mplhs); 
        if (nlhs > 4) { 
            error(_mxarray2_); 
        } 
        mprhs[0] = mclCreateVararginCell(nrhs, prhs); 
        mplhs[0] 
          = Mimread_parse_inputs( 
              &mplhs[1], &mplhs[2], &mplhs[3], nlhs, mprhs[0]); 
        plhs[0] = mplhs[0].FreezeData(); 
        for (i = 1; i < 4 && i < nlhs; ++i) { 
            plhs[i] = mplhs[i].FreezeData(); 
        } 
    } 
    MW_END_MLX(); 
} 
 
// 
// The function "Mimread" is the implementation version of the "imread" 
// M-function from file "D:\matlab\matlab\toolbox\matlab\iofun\imread.m" (lines 
// 1-273). 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 [X, map, alpha] = imread(varargin) 
// 
static mwArray Mimread(mwArray * map, 
                       mwArray * alpha, 
                       int nargout_, 
                       mwArray varargin) { 
    mwLocalFunctionTable save_local_function_table_ 
      (&_local_function_table_imread); 
    mwArray X(mclGetUninitializedArray()); 
    mwArray fid(mclGetUninitializedArray()); 
    mwArray ans(mclGetUninitializedArray()); 
    mwArray msg(mclGetUninitializedArray()); 
    mwArray extraArgs(mclGetUninitializedArray()); 
    mwArray format(mclGetUninitializedArray()); 
    mwArray filename(mclGetUninitializedArray()); 
    // 
    // %IMREAD Read image from graphics file. 
    // %   A = IMREAD(FILENAME,FMT) reads the image in FILENAME into 
    // %   A. If the file contains a grayscale intensity image, A is 
    // %   a two-dimensional array.  If the file contains a truecolor 
    // %   (RGB) image, A is a three-dimensional (M-by-N-by-3) array. 
    // %   FILENAME is a string that specifies the name of the 
    // %   graphics file, and FMT is a string that specifies the 
    // %   format of the file.  The file must be in the current 
    // %   directory or in a directory on the MATLAB path.  If IMREAD 
    // %   cannot find a file named FILENAME, it looks for a file 
    // %   named FILENAME.FMT. 
    // % 
    // %   The possible values for FMT include: 
    // % 
    // %      'jpg' or 'jpeg' Joint Photographic Experts Group (JPEG) 
    // %      'tif' or 'tiff' Tagged Image File Format (TIFF) 
    // %      'gif'           Graphics Interchange Format (GIF) 
    // %      'bmp'           Windows Bitmap (BMP) 
    // %      'png'           Portable Network Graphics 
    // %      'hdf'           Hierarchical Data Format (HDF) 
    // %      'pcx'           Windows Paintbrush (PCX) 
    // %      'xwd'           X Window Dump (XWD) 
    // %      'cur'           Windows Cursor resources (CUR) 
    // %      'ico'           Windows Icon resources (ICO) 
    // % 
    // %   [X,MAP] = IMREAD(FILENAME,FMT) reads the indexed image in 
    // %   FILENAME into X and its associated colormap into MAP. 
    // %   Colormap values in the image file are automatically 
    // %   rescaled into the range [0,1].  
    // % 
    // %   [...] = IMREAD(FILENAME) attempts to infer the format of the 
    // %   file from its content. 
    // % 
    // %   Data types 
    // %   ---------- 
    // %   In most of the image file formats supported by IMREAD, 
    // %   pixels are stored using 8 or fewer bits per color plane. 
    // %   When reading such a file, the class of the output (A or X) 
    // %   is uint8.  IMREAD also supports reading 16-bit-per-pixel 
    // %   data from BMP, TIFF and PNG files. For 16-bit TIFF and PNG image  
    // %   files, the class of the output (A or X) is uint16 and for 16-bit  
    // %   BMP image files, the class of the output is uint8. 
    // % 
    // %   TIFF-specific syntaxes 
    // %   ---------------------- 
    // %   [...] = IMREAD(...,IDX) reads in one image from a 
    // %   multi-image TIFF file.  IDX is an integer value that 
    // %   specifies the order that the image appears in the file. 
    // %   For example, if IDX is 3, IMREAD reads the third image in 
    // %   the file.  If you omit this argument, IMREAD reads the 
    // %   first image in the file.  
    // % 
    // %   PNG-specific syntaxes 
    // %   --------------------- 
    // %   [...] = IMREAD(...,'BackgroundColor',BG) composites any 
    // %   transparent pixels in the input image against the color 
    // %   specified in BG.  If BG is 'none', then no compositing is 
    // %   performed. Otherwise, if the input image is indexed, BG 
    // %   should be an integer in the range [1,P] where P is the 
    // %   colormap length. If the input image is grayscale, BG 
    // %   should be an integer in the range [0,1].  If the input 
    // %   image is RGB, BG should be a three-element vector whose 
    // %   values are in the range [0,1]. The string 
    // %   'BackgroundColor' may be abbreviated.   
    // % 
    // %   If the ALPHA output argument is used (see below), then BG 
    // %   defaults to 'none' if not specified by the 
    // %   user. Otherwise, if the PNG file contains a background 
    // %   color chunk, that color is used as the default value for 
    // %   BG. If ALPHA is not used and the file does not contain a 
    // %   background color chunk, then the default value for BG is 1 
    // %   for indexed images; 0 for grayscale images; and [0 0 0] 
    // %   for RGB images.   
    // % 
    // %   [A,MAP,ALPHA] = IMREAD(...) returns the alpha channel if 
    // %   one is present; otherwise ALPHA is [].  Note that MAP may 
    // %   be empty if the file contains a grayscale or truecolor  
    // %   image. 
    // % 
    // %   HDF-specific syntaxes 
    // %   --------------------- 
    // %   [...] = IMREAD(...,REF) reads in one image from a 
    // %   multi-image HDF file.  REF is an integer value that 
    // %   specifies the reference number used to identify the image. 
    // %   For example, if REF is 12, IMREAD reads the image whose 
    // %   reference number is 12.  (Note that in an HDF file the 
    // %   reference numbers do not necessarily correspond with the 
    // %   order of the images in the file.  You can use IMFINFO to 
    // %   match up image order with reference number.)  If you omit 
    // %   this argument, IMREAD reads the first image in the file. 
    // % 
    // %   ICO- and CUR-specific syntaxes 
    // %   ------------------------------ 
    // %   [...] = IMREAD(...,IDX) reads in one image from a 
    // %   multi-image icon or cursor file.  IDX is an integer value 
    // %   that specifies the order that the image appears in the file. 
    // %   For example, if IDX is 3, IMREAD reads the third image in 
    // %   the file.  If you omit this argument, IMREAD reads the 
    // %   first image in the file.  
    // % 
    // %   [A,MAP,ALPHA] = IMREAD(...) returns the AND mask for the 
    // %   resource, which can be used to determine the transparency 
    // %   information.  For cursor files, this mask may contain the 
    // %   only useful data. 
    // % 
    // %   Supported file types 
    // %   -------------------- 
    // %   JPEG  Any baseline JPEG image; JPEG images with some 
    // %         commonly used extensions 
    // % 
    // %   TIFF  Any baseline TIFF image, including 1-bit, 8-bit, and 
    // %         24-bit uncompressed images; 1-bit, 8-bit, and 24-bit 
    // %         images with packbits compression; 1-bit images with 
    // %         CCITT compression; also, 16-bit grayscale, 16-bit 
    // %         indexed, and 48-bit RGB images 
    // % 
    // %   GIF   Any 1-bit to 8-bit GIF image 
    // % 
    // %   BMP   1-bit, 4-bit, 8-bit, 16-bit, 24-bit, and 32-bit uncompressed 
    // %         images; 4-bit and 8-bit run-length encoded (RLE) images 
    // % 
    // %   PNG   Any PNG image, including 1-bit, 2-bit, 4-bit, 8-bit, 
    // %         and 16-bit grayscale images; 8-bit and 16-bit 
    // %         indexed images; 24-bit and 48-bit RGB images 
    // % 
    // %   HDF   8-bit raster image datasets, with or without an 
    // %         associated colormap; 24-bit raster image datasets 
    // % 
    // %   PCX   1-bit, 8-bit, and 24-bit images 
    // % 
    // %   XWD   1-bit and 8-bit ZPixmaps; XYBitmaps; 1-bit XYPixmaps 
    // % 
    // %   ICO   1-bit, 4-bit, and 8-bit uncompressed images 
    // % 
    // %   CUR   1-bit, 4-bit, and 8-bit uncompressed images 
    // % 
    // %   See also IMFINFO, IMWRITE, FREAD, IMAGE, DOUBLE, UINT8. 
    //  
    // %   Steven L. Eddins, June 1996 
    // %   Copyright 1984-2001 The MathWorks, Inc. 
    // %   $Revision: 1.22 $  $Date: 2001/03/12 23:37:46 $ 
    //  
    // [filename, format, extraArgs, msg] = parse_inputs(varargin{:}); 
    // 
    filename 
    = imread_parse_inputs( 
        &format, 
        &extraArgs, 
        &msg, 
        mwVarargin(mwVe(mwVsa(varargin, "varargin").cell(colon())))); 
    // 
    // if (~isempty(msg)) 
    // 
    if (mclNotBool(mwVe(isempty(mwVv(msg, "msg"))))) { 
        // 
        // error(msg); 
        // 
        error(mwVv(msg, "msg")); 
    // 
    // end 
    // 
    } 
    // 
    //  
    // % 
    // % Open the file and determine/verify its format 
    // % 
    // if (isempty(format)) 
    // 
    if (tobool(mwVe(isempty(mwVv(format, "format"))))) { 
        // 
        // % The format wasn't specified explicitly 
        //  
        // fid = fopen(filename, 'r'); 
        // 
        fid = fopen(mwVv(filename, "filename"), _mxarray4_); 
        // 
        // if (fid == -1) 
        // 
        if (mclEqBool(mwVv(fid, "fid"), _mxarray6_)) { 
            // 
            // error(sprintf('Can''t open file "%s" for reading;\n it may not exist, or you may not have read permission.', ... 
            // 
            error( 
              mwVe( 
                sprintf(_mxarray7_, mwVarargin(mwVv(filename, "filename"))))); 
        // 
        // filename)); 
        // else 
        // 
        } else { 
            // 
            // filename = fopen(fid); 
            // 
            filename = fopen(mwVv(fid, "fid")); 
            // 
            // fclose(fid); 
            // 
            ans.EqAns(fclose(mwVv(fid, "fid"))); 
        // 
        // end 
        // 
        } 
        // 
        //  
        // format = imftype(filename); 
        // 
        format = iofun_private_imftype(mwVv(filename, "filename")); 
        // 
        // if (isempty(format)) 
        // 
        if (tobool(mwVe(isempty(mwVv(format, "format"))))) { 
            // 
            // error('Unable to determine the file format'); 
            // 
            error(_mxarray9_); 
        // 
        // end 
        // 
        } 
    // 
    //  
    // else 
    // 
    } else { 
        // 
        // % The format was specified explicitly 
        //  
        // fid = fopen(filename, 'r'); 
        // 
        fid = fopen(mwVv(filename, "filename"), _mxarray4_); 
        // 
        // if (fid == -1) 
        // 
        if (mclEqBool(mwVv(fid, "fid"), _mxarray6_)) { 
            // 
            // % Couldn't open using the given filename; search for a 
            // % file with an appropriate extension. 
            // switch format 
            // 
            mwArray v_(mwVv(format, "format")); 
            if (switchcompare(v_, _mxarray11_)) { 
                // 
                // case 'tif' 
                // fid = fopen([filename '.tif'], 'r'); 
                // 
                fid 
                  = fopen( 
                      horzcat( 
                        mwVarargin(mwVv(filename, "filename"), _mxarray13_)), 
                      _mxarray4_); 
                // 
                // if (fid == -1) 
                // 
                if (mclEqBool(mwVv(fid, "fid"), _mxarray6_)) { 
                    // 
                    // fid = fopen([filename '.tiff'], 'r'); 
                    // 
                    fid 
                      = fopen( 
                          horzcat( 
                            mwVarargin( 
                              mwVv(filename, "filename"), _mxarray15_)), 
                          _mxarray4_); 
                // 
                // end 
                // 
                } 
            // 
            //  
            // case 'bmp' 
            // 
            } else if (switchcompare(v_, _mxarray17_)) { 
                // 
                // fid = fopen([filename '.bmp'], 'r'); 
                // 
                fid 
                  = fopen( 
                      horzcat( 
                        mwVarargin(mwVv(filename, "filename"), _mxarray19_)), 
                      _mxarray4_); 
            // 
            //  
            // case 'hdf' 
            // 
            } else if (switchcompare(v_, _mxarray21_)) { 
                // 
                // fid = fopen([filename '.hdf'], 'r'); 
                // 
                fid 
                  = fopen( 
                      horzcat( 
                        mwVarargin(mwVv(filename, "filename"), _mxarray23_)), 
                      _mxarray4_); 
            // 
            //  
            // case 'pcx'  
            // 
            } else if (switchcompare(v_, _mxarray25_)) { 
                // 
                // fid = fopen([filename '.pcx'], 'r'); 
                // 
                fid 
                  = fopen( 
                      horzcat( 
                        mwVarargin(mwVv(filename, "filename"), _mxarray27_)), 
                      _mxarray4_); 
            // 
            //  
            // case 'xwd' 
            // 
            } else if (switchcompare(v_, _mxarray29_)) { 
                // 
                // fid = fopen([filename '.xwd'], 'r'); 
                // 
                fid 
                  = fopen( 
                      horzcat( 
                        mwVarargin(mwVv(filename, "filename"), _mxarray31_)), 
                      _mxarray4_); 
            // 
            //  
            // case 'jpg' 
            // 
            } else if (switchcompare(v_, _mxarray33_)) { 
                // 
                // fid = fopen([filename '.jpg'], 'r'); 
                // 
                fid 
                  = fopen( 
                      horzcat( 
                        mwVarargin(mwVv(filename, "filename"), _mxarray35_)), 
                      _mxarray4_); 
                // 
                // if (fid == -1) 
                // 
                if (mclEqBool(mwVv(fid, "fid"), _mxarray6_)) { 
                    // 
                    // fid = fopen([filename '.jpeg'], 'r'); 
                    // 
                    fid 
                      = fopen( 
                          horzcat( 
                            mwVarargin( 
                              mwVv(filename, "filename"), _mxarray37_)), 
                          _mxarray4_); 
                // 
                // end 
                // 
                } 
            // 
            //  
            // case 'png' 
            // 
            } else if (switchcompare(v_, _mxarray39_)) { 
                // 
                // fid = fopen([filename '.png'], 'r'); 
                // 
                fid 
                  = fopen( 
                      horzcat( 
                        mwVarargin(mwVv(filename, "filename"), _mxarray41_)), 
                      _mxarray4_); 
            // 
            //  
            // case 'gif' 
            // 
            } else if (switchcompare(v_, _mxarray43_)) { 
                // 
                // fid = fopen([filename '.gif'], 'r'); 
                // 
                fid 
                  = fopen( 
                      horzcat( 
                        mwVarargin(mwVv(filename, "filename"), _mxarray45_)), 
                      _mxarray4_); 
            // 
            //  
            // case 'cur' 
            // 
            } else if (switchcompare(v_, _mxarray47_)) { 
                // 
                // fid = fopen([filename '.cur'], 'r'); 
                // 
                fid 
                  = fopen( 
                      horzcat( 
                        mwVarargin(mwVv(filename, "filename"), _mxarray49_)), 
                      _mxarray4_); 
            // 
            //  
            // case 'ico' 
            // 
            } else if (switchcompare(v_, _mxarray51_)) { 
                // 
                // fid = fopen([filename '.ico'], 'r'); 
                // 
                fid 
                  = fopen( 
                      horzcat( 
                        mwVarargin(mwVv(filename, "filename"), _mxarray53_)), 
                      _mxarray4_); 
            // 
            //  
            // end 
            // 
            } 
        // 
        // end 
        // 
        } 
        // 
        //  
        // if (fid == -1) 
        // 
        if (mclEqBool(mwVv(fid, "fid"), _mxarray6_)) { 
            // 
            // error(sprintf('Can''t open file "%s" for reading', filename)); 
            // 
            error( 
              mwVe( 
                sprintf(_mxarray55_, mwVarargin(mwVv(filename, "filename"))))); 
        // 
        //  
        // else 
        // 
        } else { 
            // 
            // filename = fopen(fid); 
            // 
            filename = fopen(mwVv(fid, "fid")); 
            // 
            // fclose(fid); 
            // 
            ans.EqAns(fclose(mwVv(fid, "fid"))); 
        // 
        // end 
        // 
        } 
    // 
    //  
    // end 
    // 
    } 
    // 
    //  
    // alpha = []; 
    // 
    *alpha = _mxarray57_; 
    // 
    //  
    // switch format 
    // 
    { 
        mwArray v_(mwVv(format, "format")); 
        if (switchcompare(v_, _mxarray17_)) { 
            // 
            // case 'bmp' 
            // [X,map] = readbmp(filename, extraArgs{:}); 
            // 
            feval( 
              mwVarargout(X, *map), 
              mlxIofun_private_readbmp, 
              mwVarargin( 
                mwVv(filename, "filename"), 
                mwVe(mwVsv(extraArgs, "extraArgs").cell(colon())))); 
        // 
        //  
        // case 'xwd' 
        // 
        } else if (switchcompare(v_, _mxarray29_)) { 
            // 
            // [X,map] = readxwd(filename, extraArgs{:}); 
            // 
            feval( 
              mwVarargout(X, *map), 
              mlxIofun_private_readxwd, 
              mwVarargin( 
                mwVv(filename, "filename"), 
                mwVe(mwVsv(extraArgs, "extraArgs").cell(colon())))); 
        // 
        //  
        // case 'pcx' 
        // 
        } else if (switchcompare(v_, _mxarray25_)) { 
            // 
            // [X,map] = readpcx(filename, extraArgs{:}); 
            // 
            feval( 
              mwVarargout(X, *map), 
              mlxIofun_private_readpcx, 
              mwVarargin( 
                mwVv(filename, "filename"), 
                mwVe(mwVsv(extraArgs, "extraArgs").cell(colon())))); 
        // 
        //  
        // case 'hdf' 
        // 
        } else if (switchcompare(v_, _mxarray21_)) { 
            // 
            // [X,map] = readhdf(filename, extraArgs{:}); 
            // 
            feval( 
              mwVarargout(X, *map), 
              mlxIofun_private_readhdf, 
              mwVarargin( 
                mwVv(filename, "filename"), 
                mwVe(mwVsv(extraArgs, "extraArgs").cell(colon())))); 
        // 
        //  
        // case 'tif' 
        // 
        } else if (switchcompare(v_, _mxarray11_)) { 
            // 
            // [X,map] = readtif(filename, extraArgs{:}); 
            // 
            feval( 
              mwVarargout(X, *map), 
              mlxIofun_private_readtif, 
              mwVarargin( 
                mwVv(filename, "filename"), 
                mwVe(mwVsv(extraArgs, "extraArgs").cell(colon())))); 
        // 
        //  
        // case 'jpg' 
        // 
        } else if (switchcompare(v_, _mxarray33_)) { 
            // 
            // [X,map] = readjpg(filename, extraArgs{:}); 
            // 
            X 
            = iofun_private_readjpg( 
                map, 
                mwVv(filename, "filename"), 
                mwVarargin(mwVe(mwVsv(extraArgs, "extraArgs").cell(colon())))); 
        // 
        //  
        // case 'png' 
        // 
        } else if (switchcompare(v_, _mxarray39_)) { 
            // 
            // % PNG has slightly different behavior if alpha is 
            // % requested, so we need the following if statement. 
            // if (nargout >= 3) 
            // 
            if (nargout_ >= 3) { 
                // 
                // [X,map,alpha] = readpng(filename, extraArgs{:}); 
                // 
                X 
                = Niofun_private_readpng( 
                    3, 
                    map, 
                    alpha, 
                    mwVv(filename, "filename"), 
                    mwVarargin( 
                      mwVe(mwVsv(extraArgs, "extraArgs").cell(colon())))); 
            // 
            // else 
            // 
            } else { 
                // 
                // [X,map] = readpng(filename, extraArgs{:}); 
                // 
                X 
                = Niofun_private_readpng( 
                    2, 
                    map, 
                    NULL, 
                    mwVv(filename, "filename"), 
                    mwVarargin( 
                      mwVe(mwVsv(extraArgs, "extraArgs").cell(colon())))); 
            // 
            // end 
            // 
            } 
        // 
        // case 'gif' 
        // 
        } else if (switchcompare(v_, _mxarray43_)) { 
            // 
            // [X,map] = readgif(filename,extraArgs{:}); 
            // 
            X 
            = iofun_private_readgif( 
                map, 
                mwVv(filename, "filename"), 
                mwVarargin(mwVe(mwVsv(extraArgs, "extraArgs").cell(colon())))); 
        // 
        //  
        // case 'cur' 
        // 
        } else if (switchcompare(v_, _mxarray47_)) { 
            // 
            // [X,map,alpha] = readcur(filename, extraArgs{:}); 
            // 
            feval( 
              mwVarargout(X, *map, *alpha), 
              mlxIofun_private_readcur, 
              mwVarargin( 
                mwVv(filename, "filename"), 
                mwVe(mwVsv(extraArgs, "extraArgs").cell(colon())))); 
        // 
        //  
        // case 'ico' 
        // 
        } else if (switchcompare(v_, _mxarray51_)) { 
            // 
            // [X,map,alpha] = readico(filename, extraArgs{:}); 
            // 
            feval( 
              mwVarargout(X, *map, *alpha), 
              mlxIofun_private_readico, 
              mwVarargin( 
                mwVv(filename, "filename"), 
                mwVe(mwVsv(extraArgs, "extraArgs").cell(colon())))); 
        // 
        //  
        // otherwise 
        // 
        } else { 
            // 
            // error(sprintf('Unrecognized or unsupported format "%s"', format)); 
            // 
            error( 
              mwVe(sprintf(_mxarray58_, mwVarargin(mwVv(format, "format"))))); 
        // 
        //  
        // end 
        // 
        } 
    } 
    mwValidateOutput(X, 1, nargout_, "X", "imread"); 
    mwValidateOutput(*map, 2, nargout_, "map", "imread"); 
    mwValidateOutput(*alpha, 3, nargout_, "alpha", "imread"); 
    return X; 
    // 
    //  
    //  
    // %%% 
    // %%% Function parse_inputs 
    // %%% 
    // function [filename, format, extraArgs, msg] = ... 
    // parse_inputs(varargin) 
    //  
    // filename = ''; 
    // format = ''; 
    // extraArgs = {}; 
    // msg = ''; 
    //  
    // formatStrings = ['bmp' 
    // 'xwd' 
    // 'pcx' 
    // 'hdf' 
    // 'tif' 
    // 'jpg' 
    // 'png' 
    // 'gif' 
    // 'cur' 
    // 'ico']; 
    //  
    // switch (nargin) 
    // case 0 
    // msg = 'Too few input arguments'; 
    // return; 
    //  
    // case 1 
    // filename = varargin{1}; 
    //  
    // otherwise 
    // filename = varargin{1}; 
    //  
    // % Is the second argument a format specifier? 
    // % Allow some variability in specifying some of the formats. 
    // arg2 = lower(varargin{2}); 
    // if (strcmp(arg2, 'tiff')) 
    // arg2 = 'tif'; 
    // elseif (strcmp(arg2, 'jpeg')) 
    // arg2 = 'jpg'; 
    // end 
    // idx = strmatch(arg2, formatStrings, 'exact'); 
    // if (~isempty(idx)) 
    // % The second input argument is a format specifier 
    // format = deblank(formatStrings(idx,:)); 
    // extraArgs = varargin(3:end); 
    //  
    // else 
    // % The second input argument is not a format specifier 
    // extraArgs = varargin(2:end); 
    // end 
    //  
    // end 
    //  
    // 
} 
 
// 
// The function "Mimread_parse_inputs" is the implementation version of the 
// "imread/parse_inputs" M-function from file 
// "D:\matlab\matlab\toolbox\matlab\iofun\imread.m" (lines 273-324). 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 [filename, format, extraArgs, msg] = ... 
// 
static mwArray Mimread_parse_inputs(mwArray * format, 
                                    mwArray * extraArgs, 
                                    mwArray * msg, 
                                    int nargout_, 
                                    mwArray varargin) { 
    mwLocalFunctionTable save_local_function_table_ 
      (&_local_function_table_imread); 
    int nargin_(nargin(-1, mwVarargin(varargin))); 
    mwArray filename(mclGetUninitializedArray()); 
    mwArray idx(mclGetUninitializedArray()); 
    mwArray arg2(mclGetUninitializedArray()); 
    mwArray formatStrings(mclGetUninitializedArray()); 
    // 
    // parse_inputs(varargin) 
    //  
    // filename = ''; 
    // 
    filename = _mxarray60_; 
    // 
    // format = ''; 
    // 
    *format = _mxarray60_; 
    // 
    // extraArgs = {}; 
    // 
    *extraArgs = _mxarray61_; 
    // 
    // msg = ''; 
    // 
    *msg = _mxarray60_; 
    // 
    //  
    // formatStrings = ['bmp' 
    // 
    formatStrings = _mxarray62_; 
    // 
    // 'xwd' 
    // 'pcx' 
    // 'hdf' 
    // 'tif' 
    // 'jpg' 
    // 'png' 
    // 'gif' 
    // 'cur' 
    // 'ico']; 
    //  
    // switch (nargin) 
    // 
    { 
        mwArray v_(nargin_); 
        if (switchcompare(v_, _mxarray64_)) { 
            // 
            // case 0 
            // msg = 'Too few input arguments'; 
            // 
            *msg = _mxarray65_; 
        // 
        // return; 
        //  
        // case 1 
        // 
        } else if (switchcompare(v_, _mxarray67_)) { 
            // 
            // filename = varargin{1}; 
            // 
            filename = mwVsa(varargin, "varargin").cell(_mxarray67_); 
        // 
        //  
        // otherwise 
        // 
        } else { 
            // 
            // filename = varargin{1}; 
            // 
            filename = mwVsa(varargin, "varargin").cell(_mxarray67_); 
            // 
            //  
            // % Is the second argument a format specifier? 
            // % Allow some variability in specifying some of the formats. 
            // arg2 = lower(varargin{2}); 
            // 
            arg2 
              = feval( 
                  mwValueVarargout(), 
                  mlxLower, 
                  mwVarargin( 
                    mwVe(mwVsa(varargin, "varargin").cell(_mxarray68_)))); 
            // 
            // if (strcmp(arg2, 'tiff')) 
            // 
            if (tobool(mwVe(strcmp(mwVv(arg2, "arg2"), _mxarray69_)))) { 
                // 
                // arg2 = 'tif'; 
                // 
                arg2 = _mxarray11_; 
            // 
            // elseif (strcmp(arg2, 'jpeg')) 
            // 
            } else if (tobool(mwVe(strcmp(mwVv(arg2, "arg2"), _mxarray71_)))) { 
                // 
                // arg2 = 'jpg'; 
                // 
                arg2 = _mxarray33_; 
            // 
            // end 
            // 
            } 
            // 
            // idx = strmatch(arg2, formatStrings, 'exact'); 
            // 
            idx 
              = strmatch( 
                  mwVv(arg2, "arg2"), 
                  mwVv(formatStrings, "formatStrings"), 
                  _mxarray73_); 
            // 
            // if (~isempty(idx)) 
            // 
            if (mclNotBool(mwVe(isempty(mwVv(idx, "idx"))))) { 
                // 
                // % The second input argument is a format specifier 
                // format = deblank(formatStrings(idx,:)); 
                // 
                *format 
                  = deblank( 
                      mwVe( 
                        mclArrayRef( 
                          mwVsv(formatStrings, "formatStrings"), 
                          mwVsv(idx, "idx"), 
                          colon()))); 
                // 
                // extraArgs = varargin(3:end); 
                // 
                *extraArgs 
                  = mclArrayRef( 
                      mwVsa(varargin, "varargin"), 
                      colon( 
                        _mxarray75_, 
                        end( 
                          mwVa(varargin, "varargin"), 
                          _mxarray67_, 
                          _mxarray67_))); 
            // 
            //  
            // else 
            // 
            } else { 
                // 
                // % The second input argument is not a format specifier 
                // extraArgs = varargin(2:end); 
                // 
                *extraArgs 
                  = mclArrayRef( 
                      mwVsa(varargin, "varargin"), 
                      colon( 
                        _mxarray68_, 
                        end( 
                          mwVa(varargin, "varargin"), 
                          _mxarray67_, 
                          _mxarray67_))); 
            // 
            // end 
            // 
            } 
        // 
        //  
        // end 
        // 
        } 
    } 
    mwValidateOutput(filename, 1, nargout_, "filename", "imread/parse_inputs"); 
    mwValidateOutput(*format, 2, nargout_, "format", "imread/parse_inputs"); 
    mwValidateOutput( 
      *extraArgs, 3, nargout_, "extraArgs", "imread/parse_inputs"); 
    mwValidateOutput(*msg, 4, nargout_, "msg", "imread/parse_inputs"); 
    return filename; 
    // 
    //  
    // 
}