"Fossies" - the Fresh Open Source Software Archive

Member "sip-0.12.1/src/sip_common.h" (20 Sep 2013, 8638 Bytes) of package /linux/privat/sip-0.12.1.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "sip_common.h" see the Fossies "Dox" file reference documentation and the latest Fossies "Diffs" side-by-side code changes report: 0.5.6_vs_0.12.1.

    1 /*
    2  * -------------------------------------------------------------------------
    3  * SIP - Scilab Image Processing toolbox
    4  * Copyright (C) 2002  Ricardo Fabbri
    5  *
    6  * This program is free software; you can redistribute it and/or modify
    7  * it under the terms of the GNU General Public License as published by
    8  * the Free Software Foundation; either version 2 of the License, or
    9  * (at your option) any later version.
   10  * 
   11  * This program is distributed in the hope that it will be useful,
   12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
   13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   14  * GNU General Public License for more details.
   15  * 
   16  * You should have received a copy of the GNU General Public License
   17  * along with this program; if not, write to the Free Software
   18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   19  * -------------------------------------------------------------------------
   20  */ 
   21   
   22 
   23 #ifndef SIP_COMMON_H
   24 #define SIP_COMMON_H 1
   25 
   26 #ifdef HAVE_CONFIG_H
   27 #include "sip_config.h"
   28 #endif
   29 
   30 #if defined(WIN32) &&  !defined(__CYGWIN__)
   31 #   if defined (_DLL) && !defined(SIP_DLL)
   32 #       define SIP_DLL
   33 #  endif
   34 #  if defined(SIP_DLL)
   35 #     define SipExport __declspec(dllexport)
   36 #   else
   37 #       define SipExport
   38 #   endif
   39 #else
   40 #  define SipExport
   41 #endif
   42 
   43 #ifndef SIP_HAVE_GetLocaleExceptionMessage
   44 #  define SipGetLocaleExceptionMessage(severity,description) description
   45 #else
   46 #  define SipGetLocaleExceptionMessage(severity,description) GetLocaleExceptionMessage(severity,description) 
   47 #endif
   48 
   49 #ifndef SIP_HAVE_QueryColorDatabase_3args
   50 #  define SIP_QueryColorDatabase(arg1,arg2,exception) QueryColorDatabase(arg1,arg2)
   51 #else
   52 #  define SIP_QueryColorDatabase(arg1,arg2,exception) QueryColorDatabase(arg1,arg2,exception)
   53 #endif
   54 
   55 
   56 #include <stack-c.h>
   57 #include <api_scilab.h>
   58 #include <Scierror.h>
   59 #include <stdio.h>
   60 #include <time.h>
   61 #include <sys/types.h>
   62 #include <magick/api.h>
   63 #ifdef SIP_HAVE_LIBLEPT
   64 #include <allheaders.h>
   65 #endif
   66 #ifdef SIP_HAVE_MagickWand
   67 #include <wand/MagickWand.h>
   68 #endif
   69 
   70 
   71 #include <animal/img.h>
   72 #include <animal/util.h>
   73 
   74 #ifdef SIP_HAVE_OPENCV
   75 #include <opencv2/imgproc/imgproc_c.h>
   76 
   77 #define SIVP_FLOAT 32
   78 #define SIVP_DOUBLE 64
   79 #endif
   80 
   81 
   82 // sip for scilab types
   83 #define USUALMATRIX 1
   84 #define STRING 10
   85 #define HYPERMATRIX 17
   86 
   87 #define ARG_2D 2 
   88 #define ARG_3D 3
   89 #define ARG_INDEX_MAP 4
   90 
   91 #define IndexImgByRow(M, i, j) M[(j) + (i)*(image->columns)]
   92 #define IndexImgByRowInPix(M, i, j) M[(j) + (i)*(pixcolumn)]
   93 #define IndexImgByCol(M, i, j) M[(i) + (j)*(image->rows)]
   94 #define IndexImgByColInPix(M, i, j) M[(i) + (j)*(pixrow)]
   95 #define IndexImg3d(M, i, j, k) M[(i) + (j)*(image->rows) + \
   96                                  (k) * (image->rows)*(image->columns)]
   97 #define IndexImg3dInPix(M, i, j, k) M[(i) + (j)*(pixrow) + \
   98                                  (k) * (pixrow)*(pixcolumn)]
   99 
  100 /* (Row, Col) indexing of 1D arrays in Pix*/
  101 #define RCbyRInPix(a,i,j,pixcolumn) a[(j) + (i)*pixcolumn]
  102 #define RCbyCInPix(a,i,j,pixrow) a[(i) + (j)*pixrow]
  103 #define RC3DbyCInPix(a,i,j,k,pixrow,pixcolumn) a[(i) + (j)*(pixrow) + \
  104                                          (k) * (pixrow)*(pixcolumn)]
  105                                  
  106 // SIP error utility macros
  107 // - It is useful to print the fname so the source of error is
  108 //   easier identifyed inside a big script
  109 // - Scierror does not exit the function!!
  110 
  111 #define sip_error(str) {Scierror(999,"%s: %s.\n\r",fname, (str)); fprintf(stderr,"%s: %s.\n",fname, (str)); return false;}
  112 #define sip_warning(str) sciprint("%s (warning): %s.\n\r",fname, (str));
  113 
  114 /* It would be best if an error handler would be set and then
  115  * CatchImageException and CatchException would be used.*/
  116 #define SIP_MAGICK_ERROR do {                                             \
  117    fprintf(stderr,"%s: ",fname); \
  118    Scierror(999,""); \
  119    sciprint("%s: ",fname); \
  120    if (image != (Image *) NULL) { \
  121      GetImageException(image,&exception);                                  \
  122    } \
  123    if( (exception.reason != NULL)  ) {\
  124       fprintf(stderr,"%s ", \
  125          GetLocaleExceptionMessage(exception.severity,exception.reason)); \
  126       sciprint("%s ", \
  127          GetLocaleExceptionMessage(exception.severity,exception.reason)); \
  128       if (exception.description != NULL) { \
  129          fprintf(stderr,": %s", \
  130          GetLocaleExceptionMessage(exception.severity,exception.description));\
  131          sciprint(": %s", \
  132          GetLocaleExceptionMessage(exception.severity,exception.description));\
  133          fprintf(stderr,".\n"); \
  134          sciprint(".\n\r"); \
  135       } \
  136    } else { \
  137       fprintf(stderr,"unknown reason\n"); \
  138       sciprint("unknown reason.\n\r"); \
  139    } \
  140 } while (0)
  141 
  142 /* Hypermatrix I/O */                                 
  143 #define GetRhsHMat(pos,H) if (!sip_get_rhs_hmat(pos,H)) { return false;}
  144 #define CreateHMat(pos,H) if (!sip_cre_hmat(pos,H)) { return false;}
  145 
  146 /*
  147  *  Data Types
  148  */
  149 
  150 typedef struct HyperMat {
  151   SciIntMat sc;   /* coding informations */
  152   int    it,      /* it=1 for complex; it=0 for real */
  153          size;    /* size of data array              */
  154   double *R,      /* real part                       */
  155          *I;      /* imaginary part (NULL for real hypermatrices) */
  156 } HyperMat;
  157 
  158 /* verbose levels */
  159 typedef enum {
  160    SIP_QUIET,
  161    SIP_WORDY,
  162 } sip_verbose_level;
  163 
  164 #define SIP_DEFAULT_VERBOSE_LEVEL SIP_WORDY
  165 
  166 /* global variables */
  167 extern sip_verbose_level sip_verbose;
  168 
  169 
  170 /* 
  171  *  Useful functions
  172  */
  173 
  174 /* ???'static' keyword should be used because these functions are
  175 seen only in SIP and wont conflict with function names available
  176 to Scilab when the toolbox is loaded */
  177 
  178 void
  179    free_sci_tru_img(HyperMat **hh);
  180 
  181 HyperMat
  182    *new_sci_tru_img(unsigned rows, unsigned cols);
  183 
  184 bool 
  185 /* Scilab <--> Imagemagick I/O */
  186    sci_2D_double_matrix_to_magick(char *fname, int p, int r, int c, 
  187          Image *image,PixelPacket **ppix), 
  188    sci_3D_double_hypermat_to_magick(char *fname, int nv, Image *image, PixelPacket **ppix),
  189    sci_index_map_to_magick(char *fname, int nv, Image *image, 
  190          PixelPacket **ppix),
  191    magick_grayscale_image_to_double_array(char *fname, PixelPacket *pix, 
  192          double **dbl_array, int rows, int cols),
  193    magick_truecolor_image_to_double_hypermat(char *fname,PixelPacket *pix,
  194          HyperMat **H, int rows, int cols),
  195    magick_binary_image_to_double_array(char *fname, PixelPacket *pix, 
  196          double **dbl_array, int rows, int cols),
  197    magick_index_map_to_sci_dbl(char *fname, Image *image, int nv),
  198 
  199 /* Scilab <--> C hypermatrix I/O */
  200    sip_get_rhs_hmat(int pos, HyperMat *H),
  201    sip_get_rhs_tru_img(int pos, HyperMat *h, char *fname),
  202    sip_cre_hmat(int pos, HyperMat *H),
  203 
  204 /* Scilab <--> Animal I/O */
  205    animal_grayscale_image_to_double_array(char *fname, Img *img, double **ptr),
  206    animal_grayscale_imgpuint32_to_double_array(char *fname, ImgPUInt32 *img, double **ptr);
  207 
  208 /* PIX <--> Scilab */
  209 #ifdef SIP_HAVE_LIBLEPT
  210 bool
  211    pix_truecolor_image_to_double_hypermat(char *fname, PIX *pixme, HyperMat **H, int rows, int cols),
  212    pix_binary_image_to_double_array(char *fname, PIX *pixme, double **dbl_array, int rows, int cols),
  213    pix_index_map_to_sci_dbl(char *fname, PIX *pixme, int nv),
  214    pix_gray_image_to_double_array(char *fname, PIX *pixme, double **dbl_array, int rows, int cols);
  215 
  216 PIX
  217 /* Scilab <--> PIX */
  218    *sci_2D_double_matrix_to_pix(char *fname, int p, int r, int c),
  219    *sci_3D_double_hypermat_to_pix(char *fname, int nv),
  220    *sci_index_map_to_pix(char *fname, int nv),
  221    *sci_2D_gray_double_matrix_to_pix(char *fname, int p, int r, int c);
  222 #endif
  223 
  224 #define sci_2D_double_matrix_to_animal(ptr,r,c,img,pixtype,maxval) { \
  225    for (i=0; i<(r)*(c); ++i) \
  226       DATA(img)[i] = PROUND(pixtype,*stk(ptr+i) * maxval); \
  227 }
  228 
  229 /* Scilab <--> OpenCV I/O */
  230 #ifdef SIP_HAVE_OPENCV
  231   IplImage * Mat2IplImg(int nPos);
  232   int IplImg2Mat(IplImage * pImage, int nPos);
  233   int Create2DIntMat(int nPos, int nRow, int nCol, void * pData, int nType);
  234   int Create2DFloatMat(int nPos, int nRow, int nCol, float * pData);
  235   int Create2DDoubleMat(int nPos, int nRow, int nCol, double * pData);
  236   int Create3DIntMat(int nPos, int nRow, int nCol, int nCh, void * pData, int nType);
  237   int Create3DFloatMat(int nPos, int nRow, int nCol, int nCh, float* pData);
  238   int Create3DDoubleMat(int nPos, int nRow, int nCol, int nCh, double* pData);
  239 
  240   IplImage * CreateIplImgFromHm(int nPos);
  241 
  242   int MatData2ImgData(IplImage * pImage, void * pMatData);
  243 
  244   int IplType2SciType(int IplType);
  245   int SciType2IplType(int SciType);
  246 
  247   int MatData2ImgData(IplImage * pImage, void * pMatData);
  248   int ImgData2MatData(IplImage * pImage, void * pMatData);
  249 
  250 
  251 #endif
  252 
  253 
  254 #endif