#include #include "mex.h" #define Int16 short #define Uint16 unsigned short /* * Read image data from an array of unsigned 8-bit integers. */ static void geread_i(double *img, double *pbytes, const unsigned char *data, const int Ndata, const Uint16 width, const Uint16 height, const Uint16 depth, const Uint16 compress, const double *map_left, const double *map_wide) { unsigned row; unsigned bytes=0; /* * For strict compatibility with imagefaq, last_pixel should be Uint16, * but some of the images I have seen seem to include negative pixels. * Uint16 last_pixel=0; */ int last_pixel=0; for (row=0; row= Ndata) return; byte = data[bytes++]; if (byte & 0x80) { unsigned char byte2; if (bytes >= Ndata) return; byte2 = data[bytes++]; if (byte & 0x40) { // next word if (bytes >= Ndata) return; byte = data[bytes++]; last_pixel= (((Uint16)byte2<<8)+byte); } else { // 14 bit delta if (byte & 0x20) byte|=0xe0; else byte&=0x1f; inc = (((Int16)byte<<8)+byte2); last_pixel += inc; } } else { // 7 bit delta if (byte & 0x40) byte|=0xc0; last_pixel+=(signed char)byte; } img[row + start*height] = (double)last_pixel; ++start; } } else { while (start= Ndata) return; byte2 = data[bytes++]; if (bytes >= Ndata) return; byte = data[bytes++]; last_pixel=(((Uint16)byte2<<8)+byte); img[row + start*height] = (double)last_pixel; ++start; } } // Pad the last "empty" part of the line ... for (j=end; j 6) { left = (double *) classFullPr(prhs[6], 1, (int)height, "double", "Seventh input variable (LEFT)"); wide = (double *) classFullPr(prhs[7], 1, (int)height, "double", "Eighth input variable (WIDE)"); } else { left = (double *) NULL; wide = (double *) NULL; } /* * Create the output variables; if nlhs<2, the second output arg is a temp */ plhs[0] = mxCreateDoubleMatrix(height, width, mxREAL); img = mxGetPr(plhs[0]); if (nlhs > 1) { plhs[1] = mxCreateDoubleMatrix(1, 1, mxREAL); pbytes = mxGetPr(plhs[1]); } else { tmpbytes = mxCreateDoubleMatrix(1, 1, mxREAL); pbytes = mxGetPr(tmpbytes); } /* * Call the function geread_i */ geread_i(img, pbytes, data, Ndata, width, height, depth, compress, left, wide); }