Ignore:
Timestamp:
May 6, 2016, 3:06:29 PM (9 years ago)
Author:
meunier
Message:
  • Added several versions of rosenfeld: { SLOW, FAST } x { FEATURES, NO_FEATURES }
  • Added native linux compilation support
  • Added a script to check results natively
  • Started to refactor nrc code
File:
1 edited

Legend:

Unmodified
Added
Removed
  • soft/giet_vm/applications/rosenfeld/nrc2/src/nralloc2.c

    r772 r821  
    3030#include <malloc.h>
    3131#include <math.h> // fabs
    32 // #include <memory.h> // memcpy
    33 
     32
     33#include "nrc_os_config.h"
    3434#include "mypredef.h"
    3535#include "nrtype.h"
     36#include "nrtypex.h"
    3637#include "nrdef.h"
    3738#include "nrmacro.h"
    3839#include "nrkernel.h"
    3940
    40 #include "nralloc1.h"
    4141#include "nralloc2.h"
    42 //#include "nrarith.h"
    4342
    4443/*
     
    4746 * --------------
    4847 */
    49 /* ------------------------------------------------ */
    50 float** matrix(long nrl, long nrh, long ncl, long nch)
    51 /* ------------------------------------------------ */
    52 {
    53     long i, nrow=nrh-nrl+1,ncol=nch-ncl+1;
    54     float **m;
    55    
    56     /* allocate pointers to rows */
    57     m=(float **) malloc((size_t)((nrow+NR_END)*sizeof(float*)));
    58     if (!m) nrerror("allocation failure 1 in matrix()");
    59     m += NR_END;
    60     m -= nrl;
    61    
    62    
    63     /* allocate rows and set pointers to them */
    64     m[nrl]=(float *) malloc((size_t)((nrow*ncol+NR_END)*sizeof(float)));
    65     if (!m[nrl]) nrerror("allocation failure 2 in matrix()");
    66     m[nrl] += NR_END;
    67     m[nrl] -= ncl;
    68    
    69     for(i=nrl+1;i<=nrh;i++) m[i]=m[i-1]+ncol;
    70    
    71     /* return pointer to array of pointers to rows */
    72     return m;
    73 }
    74 /* -------------------------------------------------------------- */
    75 IMAGE_EXPORT(byte**) bmatrix(long nrl, long nrh, long ncl, long nch)
    76 /* -------------------------------------------------------------- */
    77 {
    78     long i, nrow=nrh-nrl+1,ncol=nch-ncl+1;
    79     byte **m;
    80    
    81     /* allocate pointers to rows */
    82     m=(byte **) malloc((size_t)((nrow+NR_END)*sizeof(byte*)));
    83     if (!m) nrerror("allocation failure 1 in bmatrix()");
    84     m += NR_END;
    85     m -= nrl;
    86    
    87    
    88     /* allocate rows and set pointers to them */
    89     m[nrl]=(byte *) malloc((size_t)((nrow*ncol+NR_END)*sizeof(byte)));
    90     if (!m[nrl]) nrerror("allocation failure 2 in bmatrix()");
    91     m[nrl] += NR_END;
    92     m[nrl] -= ncl;
    93    
    94     for(i=nrl+1;i<=nrh;i++) m[i]=m[i-1]+ncol;
    95    
    96     /* return pointer to array of pointers to rows */
    97     return m;
    98 }/* ---------------------------------------------------------------- */
    99 IMAGE_EXPORT(sint8**) si8matrix(long nrl, long nrh, long ncl, long nch)
    100 /* ----------------------------------------------------------------- */
    101 {
    102     long i, nrow=nrh-nrl+1,ncol=nch-ncl+1;
    103     sint8 **m;
    104    
    105     /* allocate pointers to rows */
    106     m=(sint8 **) malloc((size_t)((nrow+NR_END)*sizeof(sint8*)));
    107     if (!m) nrerror("allocation failure 1 in i8matrix()");
    108     m += NR_END;
    109     m -= nrl;
    110    
    111     /* allocate rows and set pointers to them */
    112     m[nrl]=(sint8 *) malloc((size_t)((nrow*ncol+NR_END)*sizeof(sint8)));
    113     if (!m[nrl]) nrerror("allocation failure 2 in i8matrix()");
    114     m[nrl] += NR_END;
    115     m[nrl] -= ncl;
    116    
    117     for(i=nrl+1;i<=nrh;i++) m[i]=m[i-1]+ncol;
    118    
    119     /* return pointer to array of pointers to rows */
    120     return m;
    121 }
    122 /* ----------------------------------------------------------------- */
    123 IMAGE_EXPORT(uint8**) ui8matrix(long nrl, long nrh, long ncl, long nch)
    124 /* ----------------------------------------------------------------- */
    125 {
    126     long i, nrow=nrh-nrl+1,ncol=nch-ncl+1;
    127     uint8 **m;
    128    
    129     /* allocate pointers to rows */
    130     m=(uint8 **) malloc((size_t)((nrow+NR_END)*sizeof(uint8*)));
    131     if (!m) nrerror("allocation failure 1 in ui8matrix()");
    132     m += NR_END;
    133     m -= nrl;
    134    
    135     /* allocate rows and set pointers to them */
    136     m[nrl]=(uint8 *) malloc((size_t)((nrow*ncol+NR_END)*sizeof(uint8)));
    137     if (!m[nrl]) nrerror("allocation failure 2 in ui8matrix()");
    138     m[nrl] += NR_END;
    139     m[nrl] -= ncl;
    140    
    141     for(i=nrl+1;i<=nrh;i++) m[i]=m[i-1]+ncol;
    142    
    143     /* return pointer to array of pointers to rows */
    144     return m;
    145 }
    146 /* ------------------------------------------------------------------- */
    147 IMAGE_EXPORT(sint16**) si16matrix(long nrl, long nrh, long ncl, long nch)
    148 /* ------------------------------------------------------------------- */
    149 {
    150     long i, nrow=nrh-nrl+1,ncol=nch-ncl+1;
    151     sint16 **m;
    152    
    153     /* allocate pointers to rows */
    154     m=(sint16 **) malloc((size_t)((nrow+NR_END)*sizeof(sint16*)));
    155     if (!m) nrerror("allocation failure 1 in si16matrix()");
    156     m += NR_END;
    157     m -= nrl;
    158    
    159     /* allocate rows and set pointers to them */
    160     m[nrl]=(sint16 *) malloc((size_t)((nrow*ncol+NR_END)*sizeof(sint16)));
    161     if (!m[nrl]) nrerror("allocation failure 2 in si16matrix()");
    162     m[nrl] += NR_END;
    163     m[nrl] -= ncl;
    164    
    165     for(i=nrl+1;i<=nrh;i++) m[i]=m[i-1]+ncol;
    166    
    167     /* return pointer to array of pointers to rows */
    168     return m;
    169 }
    170 /* ------------------------------------------------------------------- */
    171 IMAGE_EXPORT(uint16**) ui16matrix(long nrl, long nrh, long ncl, long nch)
    172 /* ------------------------------------------------------------------- */
    173 {
    174     long i, nrow=nrh-nrl+1,ncol=nch-ncl+1;
    175     uint16 **m;
    176    
    177     /* allocate pointers to rows */
    178     m=(uint16 **) malloc((size_t)((nrow+NR_END)*sizeof(uint16*)));
    179     if (!m) nrerror("allocation failure 1 in ui16matrix()");
    180     m += NR_END;
    181     m -= nrl;
    182    
    183     /* allocate rows and set pointers to them */
    184     m[nrl]=(uint16 *) malloc((size_t)((nrow*ncol+NR_END)*sizeof(uint16)));
    185     if (!m[nrl]) nrerror("allocation failure 2 in ui16matrix()");
    186     m[nrl] += NR_END;
    187     m[nrl] -= ncl;
    188    
    189     for(i=nrl+1;i<=nrh;i++)
    190         m[i]=m[i-1]+ncol;
    191    
    192     /* return pointer to array of pointers to rows */
    193     return m;
    194 }
    195 /* ------------------------------------------------------------------- */
    196 IMAGE_EXPORT(sint32**) si32matrix(long nrl, long nrh, long ncl, long nch)
    197 /* ------------------------------------------------------------------- */
    198 /* allocate a int32 matrix with subscript range m[nrl..nrh][ncl..nch] */
    199 {
    200     long i, nrow=nrh-nrl+1,ncol=nch-ncl+1;
    201     sint32 **m;
    202    
    203     /* allocate pointers to rows */
    204     m=(sint32 **) malloc((size_t)((nrow+NR_END)*sizeof(sint32*)));
    205     if (!m) nrerror("allocation failure 1 in si32matrix()");
    206     m += NR_END;
    207     m -= nrl;
    208    
    209     /* allocate rows and set pointers to them */
    210     m[nrl]=(sint32 *) malloc((size_t)((nrow*ncol+NR_END)*sizeof(sint32)));
    211     if (!m[nrl]) nrerror("allocation failure 2 in si32matrix()");
    212     m[nrl] += NR_END;
    213     m[nrl] -= ncl;
    214    
    215     for(i=nrl+1;i<=nrh;i++) m[i]=m[i-1]+ncol;
    216    
    217     /* return pointer to array of pointers to rows */
    218     return m;
    219 }
    220 /* ------------------------------------------------------------------- */
    221 IMAGE_EXPORT(uint32**) ui32matrix(long nrl, long nrh, long ncl, long nch)
    222 /* ------------------------------------------------------------------- */
    223 /* allocate a uint32 matrix with subscript range m[nrl..nrh][ncl..nch] */
    224 {
    225     long i, nrow=nrh-nrl+1,ncol=nch-ncl+1;
    226     uint32 **m;
    227    
    228     /* allocate pointers to rows */
    229     m=(uint32 **) malloc((size_t)((nrow+NR_END)*sizeof(uint32*)));
    230     if (!m) nrerror("allocation failure 1 in ui32matrix()");
    231     m += NR_END;
    232     m -= nrl;
    233    
    234     /* allocate rows and set pointers to them */
    235     m[nrl]=(uint32 *) malloc((size_t)((nrow*ncol+NR_END)*sizeof(uint32)));
    236     if (!m[nrl]) nrerror("allocation failure 2 in ui32matrix()");
    237     m[nrl] += NR_END;
    238     m[nrl] -= ncl;
    239    
    240     for(i=nrl+1;i<=nrh;i++)
    241         m[i]=m[i-1]+ncol;
    242    
    243     /* return pointer to array of pointers to rows */
    244     return m;
    245 }
    246 /* ------------------------------------------------------------------- */
    247 IMAGE_EXPORT(sint64**) si64matrix(long nrl, long nrh, long ncl, long nch)
    248 /* ------------------------------------------------------------------- */
    249 /* allocate a int64 matrix with subscript range m[nrl..nrh][ncl..nch] */
    250 {
    251     long i, nrow=nrh-nrl+1,ncol=nch-ncl+1;
    252     sint64 **m;
    253    
    254     /* allocate pointers to rows */
    255     m=(sint64 **) malloc((size_t)((nrow+NR_END)*sizeof(sint64*)));
    256     if (!m) nrerror("allocation failure 1 in si64matrix()");
    257     m += NR_END;
    258     m -= nrl;
    259    
    260     /* allocate rows and set pointers to them */
    261     m[nrl]=(sint64 *) malloc((size_t)((nrow*ncol+NR_END)*sizeof(sint64)));
    262     if (!m[nrl]) nrerror("allocation failure 2 in si64matrix()");
    263     m[nrl] += NR_END;
    264     m[nrl] -= ncl;
    265    
    266     for(i=nrl+1;i<=nrh;i++) m[i]=m[i-1]+ncol;
    267    
    268     /* return pointer to array of pointers to rows */
    269     return m;
    270 }
    271 /* ------------------------------------------------------------------- */
    272 IMAGE_EXPORT(uint64**) ui64matrix(long nrl, long nrh, long ncl, long nch)
    273 /* ------------------------------------------------------------------- */
    274 /* allocate a int64 matrix with subscript range m[nrl..nrh][ncl..nch] */
    275 {
    276     long i, nrow=nrh-nrl+1,ncol=nch-ncl+1;
    277     uint64 **m;
    278    
    279     /* allocate pointers to rows */
    280     m=(uint64 **) malloc((size_t)((nrow+NR_END)*sizeof(uint64*)));
    281     if (!m) nrerror("allocation failure 1 in ui64matrix()");
    282     m += NR_END;
    283     m -= nrl;
    284    
    285     /* allocate rows and set pointers to them */
    286     m[nrl]=(uint64 *) malloc((size_t)((nrow*ncol+NR_END)*sizeof(uint64)));
    287     if (!m[nrl]) nrerror("allocation failure 2 in ui64matrix()");
    288     m[nrl] += NR_END;
    289     m[nrl] -= ncl;
    290    
    291     for(i=nrl+1;i<=nrh;i++) m[i]=m[i-1]+ncol;
    292    
    293     /* return pointer to array of pointers to rows */
    294     return m;
    295 }
    296 /* ------------------------------------------------------------------- */
    297 IMAGE_EXPORT(float32**) f32matrix(long nrl, long nrh, long ncl, long nch)
    298 /* ------------------------------------------------------------------- */
    299 /* allocate a float matrix with subscript range m[nrl..nrh][ncl..nch] */
    300 {
    301     long i, nrow=nrh-nrl+1,ncol=nch-ncl+1;
    302     float32 **m;
    303    
    304     /* allocate pointers to rows */
    305     m=(float32 **) malloc((size_t)((nrow+NR_END)*sizeof(float32*)));
    306     if (!m) nrerror("allocation failure 1 in f32matrix()");
    307     m += NR_END;
    308     m -= nrl;
    309    
    310     /* allocate rows and set pointers to them */
    311     m[nrl]=(float32 *) malloc((size_t)((nrow*ncol+NR_END)*sizeof(float32)));
    312     if (!m[nrl]) nrerror("allocation failure 2 in f32matrix()");
    313     m[nrl] += NR_END;
    314     m[nrl] -= ncl;
    315    
    316     for(i=nrl+1;i<=nrh;i++) m[i]=m[i-1]+ncol;
    317    
    318     /* return pointer to array of pointers to rows */
    319     return m;
    320 }/* ------------------------------------------------------------------- */
    321 IMAGE_EXPORT(float64**) f64matrix(long nrl, long nrh, long ncl, long nch)
    322 /* ------------------------------------------------------------------- */
    323 
    324 /* allocate a float matrix with subscript range m[nrl..nrh][ncl..nch] */
    325 {
    326     long i, nrow=nrh-nrl+1,ncol=nch-ncl+1;
    327     float64 **m;
    328    
    329     /* allocate pointers to rows */
    330     m=(float64 **) malloc((size_t)((nrow+NR_END)*sizeof(float64*)));
    331     if (!m) nrerror("allocation failure 1 in f64matrix()");
    332     m += NR_END;
    333     m -= nrl;
    334    
    335     /* allocate rows and set pointers to them */
    336     m[nrl]=(float64 *) malloc((size_t)((nrow*ncol+NR_END)*sizeof(float64)));
    337     if (!m[nrl]) nrerror("allocation failure 2 in f64matrix()");
    338     m[nrl] += NR_END;
    339     m[nrl] -= ncl;
    340    
    341     for(i=nrl+1;i<=nrh;i++) m[i]=m[i-1]+ncol;
    342     /* return pointer to array of pointers to rows */
    343     return m;
    344 }
    345 /* --------------------------------------------------------------------- */
    346 IMAGE_EXPORT(complex32**) c32matrix(long nrl, long nrh, long ncl, long nch)
    347 /* --------------------------------------------------------------------- */
    348 /* allocate a complex32 matrix with subscript range m[nrl..nrh][ncl..nch] */
    349 {
    350     long i, nrow=nrh-nrl+1,ncol=nch-ncl+1;
    351     complex32 **m;
    352    
    353     /* allocate pointers to rows */
    354     m=(complex32 **) malloc((size_t)((nrow+NR_END)*sizeof(complex32*)));
    355     if (!m) nrerror("allocation failure 1 in c32matrix()");
    356     m += NR_END;
    357     m -= nrl;
    358    
    359     /* allocate rows and set pointers to them */
    360     m[nrl]=(complex32 *) malloc((size_t)((nrow*ncol+NR_END)*sizeof(complex32)));
    361     if (!m[nrl]) nrerror("allocation failure 2 in c32matrix()");
    362     m[nrl] += NR_END;
    363     m[nrl] -= ncl;
    364    
    365     for(i=nrl+1;i<=nrh;i++) m[i]=m[i-1]+ncol;
    366    
    367     /* return pointer to array of pointers to rows */
    368     return m;
    369 }
    370 /* --------------------------------------------------------------------- */
    371 IMAGE_EXPORT(complex64**) c64matrix(long nrl, long nrh, long ncl, long nch)
    372 /* --------------------------------------------------------------------- */
    373 /* allocate a complex32 matrix with subscript range m[nrl..nrh][ncl..nch] */
    374 {
    375     long i, nrow=nrh-nrl+1,ncol=nch-ncl+1;
    376     complex64 **m;
    377    
    378     /* allocate pointers to rows */
    379     m=(complex64 **) malloc((size_t)((nrow+NR_END)*sizeof(complex64*)));
    380     if (!m) nrerror("allocation failure 1 in c64matrix()");
    381     m += NR_END;
    382     m -= nrl;
    383    
    384     /* allocate rows and set pointers to them */
    385     m[nrl]=(complex64 *) malloc((size_t)((nrow*ncol+NR_END)*sizeof(complex64)));
    386     if (!m[nrl]) nrerror("allocation failure 2 in c64matrix()");
    387     m[nrl] += NR_END;
    388     m[nrl] -= ncl;
    389    
    390     for(i=nrl+1;i<=nrh;i++) m[i]=m[i-1]+ncol;
    391    
    392     /* return pointer to array of pointers to rows */
    393     return m;
    394 }
    395 /* ----------------------------------------------------------------- */
    396 IMAGE_EXPORT(rgb8**) rgb8matrix(long nrl, long nrh, long ncl, long nch)
    397 /* ----------------------------------------------------------------- */
    398 /* allocate a sint16  matrix with subscript range m[nrl..nrh][ncl..nch] */
    399 {
    400     long i, nrow=nrh-nrl+1,ncol=nch-ncl+1;
    401     rgb8 **m;
    402    
    403     /* allocate pointers to rows */
    404     m=(rgb8**) malloc((size_t)((nrow+NR_END)*sizeof(rgb8*)));
    405     if (!m) nrerror("allocation failure 1 in rgb8matrix()");
    406     m += NR_END;
    407     m -= nrl;
    408    
    409     /* allocate rows and set pointers to them */
    410     m[nrl]=(rgb8*) malloc((size_t)((nrow*ncol+NR_END)*sizeof(rgb8)));
    411     if (!m[nrl]) nrerror("allocation failure 2 in rgb8matrix()");
    412     m[nrl] += NR_END;
    413     m[nrl] -= ncl;
    414    
    415     for(i=nrl+1;i<=nrh;i++) m[i]=m[i-1]+ncol;
    416    
    417     /* return pointer to array of pointers to rows */
    418     return m;
    419 }
    420 /* ------------------------------------------------------------------- */
    421 IMAGE_EXPORT(rgbx8**) rgbx8matrix(long nrl, long nrh, long ncl, long nch)
    422 /* ------------------------------------------------------------------- */
    423 /* allocate a sint16  matrix with subscript range m[nrl..nrh][ncl..nch] */
    424 {
    425     long i, nrow=nrh-nrl+1,ncol=nch-ncl+1;
    426     rgbx8 **m;
    427    
    428     /* allocate pointers to rows */
    429     m=(rgbx8**) malloc((size_t)((nrow+NR_END)*sizeof(rgbx8*)));
    430     if (!m) nrerror("allocation failure 1 in rgbx8matrix()");
    431     m += NR_END;
    432     m -= nrl;
    433    
    434     /* allocate rows and set pointers to them */
    435     m[nrl]=(rgbx8*) malloc((size_t)((nrow*ncol+NR_END)*sizeof(rgbx8)));
    436     if (!m[nrl]) nrerror("allocation failure 2 in rgbx8matrix()");
    437     m[nrl] += NR_END;
    438     m[nrl] -= ncl;
    439    
    440     for(i=nrl+1;i<=nrh;i++) m[i]=m[i-1]+ncol;
    441    
    442     /* return pointer to array of pointers to rows */
    443     return m;
    444 }
    445 /* ------------------------------------------------------------------- */
    446 IMAGE_EXPORT(rgb32**) rgb32matrix(long nrl, long nrh, long ncl, long nch)
    447 /* ------------------------------------------------------------------- */
    448 /* allocate a sint16  matrix with subscript range m[nrl..nrh][ncl..nch] */
    449 {
    450     long i, nrow=nrh-nrl+1,ncol=nch-ncl+1;
    451     rgb32 **m;
    452    
    453     /* allocate pointers to rows */
    454     m=(rgb32**) malloc((size_t)((nrow+NR_END)*sizeof(rgb32*)));
    455     if (!m) nrerror("allocation failure 1 in rgb32matrix()");
    456     m += NR_END;
    457     m -= nrl;
    458    
    459     /* allocate rows and set pointers to them */
    460     m[nrl]=(rgb32*) malloc((size_t)((nrow*ncol+NR_END)*sizeof(rgb32)));
    461     if (!m[nrl]) nrerror("allocation failure 2 in rgb32matrix()");
    462     m[nrl] += NR_END;
    463     m[nrl] -= ncl;
    464    
    465     for(i=nrl+1;i<=nrh;i++) m[i]=m[i-1]+ncol;
    466    
    467     /* return pointer to array of pointers to rows */
    468     return m;
    469 }
    470 /* --------------------------------------------------------------------- */
    471 IMAGE_EXPORT(rgbx32**) rgbx32matrix(long nrl, long nrh, long ncl, long nch)
    472 /* --------------------------------------------------------------------- */
    473 /* allocate a sint16  matrix with subscript range m[nrl..nrh][ncl..nch] */
    474 {
    475     long i, nrow=nrh-nrl+1,ncol=nch-ncl+1;
    476     rgbx32 **m;
    477    
    478     /* allocate pointers to rows */
    479     m=(rgbx32**) malloc((size_t)((nrow+NR_END)*sizeof(rgbx32*)));
    480     if (!m) nrerror("allocation failure 1 in rgbx32matrix()");
    481     m += NR_END;
    482     m -= nrl;
    483    
    484     /* allocate rows and set pointers to them */
    485     m[nrl]=(rgbx32*) malloc((size_t)((nrow*ncol+NR_END)*sizeof(rgbx32)));
    486     if (!m[nrl]) nrerror("allocation failure 2 in rgbx32matrix()");
    487     m[nrl] += NR_END;
    488     m[nrl] -= ncl;
    489    
    490     for(i=nrl+1;i<=nrh;i++) m[i]=m[i-1]+ncol;
    491    
    492     /* return pointer to array of pointers to rows */
    493     return m;
    494 }
    495 
    496 /*
    497  * ---------------
    498  * --- matrix0 ---
    499  * ---------------
    500  */
    501 
    502 /* --------------------------------------------------------------- */
    503 IMAGE_EXPORT(byte**) bmatrix0(long nrl, long nrh, long ncl, long nch)
    504 /* --------------------------------------------------------------- */
    505 /* allocate a byte matrix with subscript range m[nrl..nrh][ncl..nch] */
    506 {
    507     long i, nrow=nrh-nrl+1,ncol=nch-ncl+1;
    508     byte **m;
    509    
    510     /* allocate pointers to rows */
    511     m=(byte **) malloc((size_t)((nrow+NR_END)*sizeof(byte*)));
    512     if (!m) nrerror("allocation failure 1 in bmatrix0()");
    513     m += NR_END;
    514     m -= nrl;
    515    
    516     /* allocate rows and set pointers to them */
    517     m[nrl]=(byte *) calloc((size_t)(nrow*ncol+NR_END),sizeof(byte));
    518     if (!m[nrl]) nrerror("allocation failure 2 in bmatrix0()");
    519     m[nrl] += NR_END;
    520     m[nrl] -= ncl;
    521    
    522     for(i=nrl+1;i<=nrh;i++) m[i]=m[i-1]+ncol;
    523    
    524     /* return pointer to array of pointers to rows */
    525     return m;
    526 }
    527 /* ------------------------------------------------------------------ */
    528 IMAGE_EXPORT(sint8**) si8matrix0(long nrl, long nrh, long ncl, long nch)
    529 /* ------------------------------------------------------------------ */
    530 {
    531     long i, nrow=nrh-nrl+1,ncol=nch-ncl+1;
    532     sint8 **m;
    533    
    534     /* allocate pointers to rows */
    535     m=(sint8 **) malloc((size_t)((nrow+NR_END)*sizeof(sint8*)));
    536     if (!m) nrerror("allocation failure 1 in i8matrix0()");
    537     m += NR_END;
    538     m -= nrl;
    539    
    540     /* allocate rows and set pointers to them */
    541     m[nrl]=(sint8 *) calloc((size_t)(nrow*ncol+NR_END),sizeof(sint8));
    542     if (!m[nrl]) nrerror("allocation failure 2 in imatrix0()");
    543     m[nrl] += NR_END;
    544     m[nrl] -= ncl;
    545    
    546     for(i=nrl+1;i<=nrh;i++) m[i]=m[i-1]+ncol;
    547    
    548     /* return pointer to array of pointers to rows */
    549     return m;
    550 }
    551 /* ------------------------------------------------------------------ */
    552 IMAGE_EXPORT(uint8**) ui8matrix0(long nrl, long nrh, long ncl, long nch)
    553 /* ------------------------------------------------------------------ */
    554 {
    555     long i, nrow=nrh-nrl+1,ncol=nch-ncl+1;
    556     uint8 **m;
    557    
    558     /* allocate pointers to rows */
    559     m=(uint8 **) malloc((size_t)((nrow+NR_END)*sizeof(uint8*)));
    560     if (!m) nrerror("allocation failure 1 in ui8matrix0()");
    561     m += NR_END;
    562     m -= nrl;
    563    
    564     /* allocate rows and set pointers to them */
    565     m[nrl]=(uint8 *) calloc((size_t)(nrow*ncol+NR_END),sizeof(uint8));
    566     if (!m[nrl]) nrerror("allocation failure 2 in ui8matrix0()");
    567     m[nrl] += NR_END;
    568     m[nrl] -= ncl;
    569    
    570     for(i=nrl+1;i<=nrh;i++) m[i]=m[i-1]+ncol;
    571    
    572     /* return pointer to array of pointers to rows */
    573     return m;
    574 }
    575 /* -------------------------------------------------------------------- */
    576 IMAGE_EXPORT(sint16**) si16matrix0(long nrl, long nrh, long ncl, long nch)
    577 /* -------------------------------------------------------------------- */
    578 /* allocate a sint16  matrix with subscript range m[nrl..nrh][ncl..nch] */
    579 {
    580     long i, nrow=nrh-nrl+1,ncol=nch-ncl+1;
    581     sint16 **m;
    582    
    583     /* allocate pointers to rows */
    584     m=(sint16 **) malloc((size_t)((nrow+NR_END)*sizeof(sint16*)));
    585     if (!m) nrerror("allocation failure 1 in si16matrix0()");
    586     m += NR_END;
    587     m -= nrl;
    588    
    589     /* allocate rows and set pointers to them */
    590     m[nrl]=(sint16 *) calloc(nrow*ncol, sizeof(int16));
    591     if (!m[nrl]) nrerror("allocation failure 2 in si16matrix0()");
    592     m[nrl] += NR_END;
    593     m[nrl] -= ncl;
    594    
    595     for(i=nrl+1;i<=nrh;i++) m[i]=m[i-1]+ncol;
    596    
    597     /* return pointer to array of pointers to rows */
    598     return m;
    599 }
    600 /* -------------------------------------------------------------------- */
    601 IMAGE_EXPORT(uint16**) ui16matrix0(long nrl, long nrh, long ncl, long nch)
    602 /* -------------------------------------------------------------------- */
    603 /* allocate a sint16  matrix with subscript range m[nrl..nrh][ncl..nch] */
    604 {
    605     long i, nrow=nrh-nrl+1,ncol=nch-ncl+1;
    606     uint16 **m;
    607    
    608     /* allocate pointers to rows */
    609     m=(uint16 **) malloc((size_t)((nrow+NR_END)*sizeof(uint16*)));
    610     if (!m) nrerror("allocation failure 1 in ui16matrix0()");
    611     m += NR_END;
    612     m -= nrl;
    613    
    614     /* allocate rows and set pointers to them */
    615     m[nrl]=(uint16 *) calloc(nrow*ncol, sizeof(uint16));
    616     if (!m[nrl]) nrerror("allocation failure 2 in ui16matrix0()");
    617     m[nrl] += NR_END;
    618     m[nrl] -= ncl;
    619    
    620     for(i=nrl+1;i<=nrh;i++) m[i]=m[i-1]+ncol;
    621    
    622     /* return pointer to array of pointers to rows */
    623     return m;
    624 }
    625 /* -------------------------------------------------------------------- */
    626 IMAGE_EXPORT(sint32**) si32matrix0(long nrl, long nrh, long ncl, long nch)
    627 /* -------------------------------------------------------------------- */
    628 /* allocate a int32 matrix with subscript range m[nrl..nrh][ncl..nch] */
    629 {
    630     long i, nrow=nrh-nrl+1,ncol=nch-ncl+1;
    631     sint32 **m;
    632    
    633     /* allocate pointers to rows */
    634     m=(sint32 **) malloc((size_t)((nrow+NR_END)*sizeof(sint32*)));
    635     if (!m) nrerror("allocation failure 1 in si32matrix0()");
    636     m += NR_END;
    637     m -= nrl;
    638    
    639     /* allocate rows and set pointers to them */
    640     m[nrl]=(sint32 *) calloc((size_t)(nrow*ncol+NR_END),sizeof(sint32));
    641     if (!m[nrl]) nrerror("allocation failure 2 in si32matrix0()");
    642     m[nrl] += NR_END;
    643     m[nrl] -= ncl;
    644    
    645     for(i=nrl+1;i<=nrh;i++) m[i]=m[i-1]+ncol;
    646    
    647     /* return pointer to array of pointers to rows */
    648     return m;
    649 }
    650 /* -------------------------------------------------------------------- */
    651 IMAGE_EXPORT(uint32**) ui32matrix0(long nrl, long nrh, long ncl, long nch)
    652 /* -------------------------------------------------------------------- */
    653 /* allocate a sint16  matrix with subscript range m[nrl..nrh][ncl..nch] */
    654 {
    655     long i, nrow=nrh-nrl+1,ncol=nch-ncl+1; 
    656     uint32 **m;
    657     /* allocate pointers to rows */
    658     m=(uint32 **) malloc((size_t)((nrow+NR_END)*sizeof(uint32*)));
    659     if (!m) nrerror("allocation failure 1 in ui32matrix0()");
    660     m += NR_END;
    661     m -= nrl;
    662 
    663     /* allocate rows and set pointers to them */
    664     m[nrl]=(uint32 *) calloc((size_t)(nrow*ncol+NR_END), sizeof(uint32));
    665     if (!m[nrl]) nrerror("allocation failure 2 in ui32matrix0()");
    666     m[nrl] += NR_END;
    667     m[nrl] -= ncl;
    668    
    669     for(i=nrl+1;i<=nrh;i++) m[i]=m[i-1]+ncol;
    670     /* return pointer to array of pointers to rows */
    671     return m;   
    672 }
    673 /* -------------------------------------------------------------------- */
    674 IMAGE_EXPORT(sint64**) si64matrix0(long nrl, long nrh, long ncl, long nch)
    675 /* -------------------------------------------------------------------- */
    676 {
    677     long i, nrow=nrh-nrl+1,ncol=nch-ncl+1;
    678     sint64 **m;
    679    
    680     /* allocate pointers to rows */
    681     m=(sint64 **) malloc((size_t)((nrow+NR_END)*sizeof(sint64*)));
    682     if (!m) nrerror("allocation failure 1 in si64matrix0()");
    683     m += NR_END;
    684     m -= nrl;
    685    
    686     /* allocate rows and set pointers to them */
    687     m[nrl]=(sint64 *) calloc((size_t)(nrow*ncol+NR_END),sizeof(sint64));
    688     if (!m[nrl]) nrerror("allocation failure 2 in si64matrix0()");
    689     m[nrl] += NR_END;
    690     m[nrl] -= ncl;
    691    
    692     for(i=nrl+1;i<=nrh;i++) m[i]=m[i-1]+ncol;
    693    
    694     /* return pointer to array of pointers to rows */
    695     return m;
    696 }
    697 /* -------------------------------------------------------------------- */
    698 IMAGE_EXPORT(uint64**) ui64matrix0(long nrl, long nrh, long ncl, long nch)
    699 /* -------------------------------------------------------------------- */
    700 {
    701     long i, nrow=nrh-nrl+1,ncol=nch-ncl+1;
    702     uint64 **m;
    703    
    704     /* allocate pointers to rows */
    705     m=(uint64 **) malloc((size_t)((nrow+NR_END)*sizeof(uint64*)));
    706     if (!m) nrerror("allocation failure 1 in i64matrix0()");
    707     m += NR_END;
    708     m -= nrl;
    709    
    710     /* allocate rows and set pointers to them */
    711     m[nrl]=(uint64 *) calloc((size_t)(nrow*ncol+NR_END),sizeof(uint64));
    712     if (!m[nrl]) nrerror("allocation failure 2 in i64matrix0()");
    713     m[nrl] += NR_END;
    714     m[nrl] -= ncl;
    715    
    716     for(i=nrl+1;i<=nrh;i++) m[i]=m[i-1]+ncol;
    717    
    718     /* return pointer to array of pointers to rows */
    719     return m;
    720 }
    721 /* -------------------------------------------------------------------- */
    722 IMAGE_EXPORT(float32**) f32matrix0(long nrl, long nrh, long ncl, long nch)
    723 /* -------------------------------------------------------------------- */
    724 {
    725     long i, nrow=nrh-nrl+1,ncol=nch-ncl+1;
    726     float32 **m;
    727    
    728     /* allocate pointers to rows */
    729     m=(float32 **) malloc((size_t)((nrow+NR_END)*sizeof(float32*)));
    730     if (!m) nrerror("allocation failure 1 in f32matrix0()");
    731     m += NR_END;
    732     m -= nrl;
    733    
    734     /* allocate rows and set pointers to them */
    735     m[nrl]=(float32 *) calloc((size_t)(nrow*ncol+NR_END),sizeof(float32));
    736     if (!m[nrl]) nrerror("allocation failure 2 in f32matrix0()");
    737     m[nrl] += NR_END;
    738     m[nrl] -= ncl;
    739    
    740     for(i=nrl+1;i<=nrh;i++) m[i]=m[i-1]+ncol;
    741    
    742     /* return pointer to array of pointers to rows */
    743     return m;
    744 }
    745 /* -------------------------------------------------------------------- */
    746 IMAGE_EXPORT(float64**) f64matrix0(long nrl, long nrh, long ncl, long nch)
    747 /* -------------------------------------------------------------------- */
    748 {
    749     long i, nrow=nrh-nrl+1,ncol=nch-ncl+1;
    750     float64 **m;
    751    
    752     /* allocate pointers to rows */
    753     m=(float64 **) malloc((size_t)((nrow+NR_END)*sizeof(float64*)));
    754     if (!m) nrerror("allocation failure 1 in f64matrix0()");
    755     m += NR_END;
    756     m -= nrl;
    757    
    758     /* allocate rows and set pointers to them */
    759     m[nrl]=(float64 *) calloc((size_t)(nrow*ncol+NR_END),sizeof(float64));
    760     if (!m[nrl]) nrerror("allocation failure 2 in f64matrix0()");
    761     m[nrl] += NR_END;
    762     m[nrl] -= ncl;
    763    
    764     for(i=nrl+1;i<=nrh;i++) m[i]=m[i-1]+ncol;
    765     /* return pointer to array of pointers to rows */
    766     return m;
    767 }
    768 /* ---------------------------------------------------------------------- */
    769 IMAGE_EXPORT(complex32**) c32matrix0(long nrl, long nrh, long ncl, long nch)
    770 /* ---------------------------------------------------------------------- */
    771 {
    772     long i, nrow=nrh-nrl+1,ncol=nch-ncl+1;
    773     complex32 **m;
    774    
    775     /* allocate pointers to rows */
    776     m=(complex32 **) malloc((size_t)((nrow+NR_END)*sizeof(complex32*)));
    777     if (!m) nrerror("allocation failure 1 in c32matrix0()");
    778     m += NR_END;
    779     m -= nrl;
    780    
    781     /* allocate rows and set pointers to them */
    782     m[nrl]=(complex32 *) calloc((size_t)(nrow*ncol+NR_END),sizeof(complex32));
    783     if (!m[nrl]) nrerror("allocation failure 2 in c32matrix0()");
    784     m[nrl] += NR_END;
    785     m[nrl] -= ncl;
    786    
    787     for(i=nrl+1;i<=nrh;i++) m[i]=m[i-1]+ncol;
    788    
    789     /* return pointer to array of pointers to rows */
    790     return m;
    791 }
    792 /* ---------------------------------------------------------------------- */
    793 IMAGE_EXPORT(complex64**) c64matrix0(long nrl, long nrh, long ncl, long nch)
    794 /* ---------------------------------------------------------------------- */
    795 {
    796     long i, nrow=nrh-nrl+1,ncol=nch-ncl+1;
    797     complex64 **m;
    798    
    799     /* allocate pointers to rows */
    800     m=(complex64 **) malloc((size_t)((nrow+NR_END)*sizeof(complex64*)));
    801     if (!m) nrerror("allocation failure 1 in c64matrix0()");
    802     m += NR_END;
    803     m -= nrl;
    804    
    805     /* allocate rows and set pointers to them */
    806     m[nrl]=(complex64 *) calloc((size_t)(nrow*ncol+NR_END),sizeof(complex64));
    807     if (!m[nrl]) nrerror("allocation failure 2 in c64matrix0()");
    808     m[nrl] += NR_END;
    809     m[nrl] -= ncl;
    810    
    811     for(i=nrl+1;i<=nrh;i++) m[i]=m[i-1]+ncol;
    812    
    813     /* return pointer to array of pointers to rows */
    814     return m;
    815 }
    816 /* ------------------------------------------------------------------ */
    817 IMAGE_EXPORT(rgb8**) rgb8matrix0(long nrl, long nrh, long ncl, long nch)
    818 /* ------------------------------------------------------------------ */
    819 /* allocate a sint16  matrix with subscript range m[nrl..nrh][ncl..nch] */
    820 {
    821     long i, nrow=nrh-nrl+1,ncol=nch-ncl+1;
    822     rgb8 **m;
    823    
    824     /* allocate pointers to rows */
    825     m=(rgb8**) malloc((size_t)((nrow+NR_END)*sizeof(rgb8*)));
    826     if (!m) nrerror("allocation failure 1 in rgb8matrix0()");
    827     m += NR_END;
    828     m -= nrl;
    829    
    830     /* allocate rows and set pointers to them */
    831     m[nrl]=(rgb8*) calloc((size_t)(nrow*ncol+NR_END), sizeof(rgb8));
    832     if (!m[nrl]) nrerror("allocation failure 2 in rgb8matrix0()");
    833     m[nrl] += NR_END;
    834     m[nrl] -= ncl;
    835    
    836     for(i=nrl+1;i<=nrh;i++) m[i]=m[i-1]+ncol;
    837    
    838     /* return pointer to array of pointers to rows */
    839     return m;
    840 }
    841 /* -------------------------------------------------------------------- */
    842 IMAGE_EXPORT(rgbx8**) rgbx8matrix0(long nrl, long nrh, long ncl, long nch)
    843 /* -------------------------------------------------------------------- */
    844 /* allocate a sint16  matrix with subscript range m[nrl..nrh][ncl..nch] */
    845 {
    846     long i, nrow=nrh-nrl+1,ncol=nch-ncl+1;
    847     rgbx8 **m;
    848    
    849     /* allocate pointers to rows */
    850     m=(rgbx8**) malloc((size_t)((nrow+NR_END)*sizeof(rgbx8*)));
    851     if (!m) nrerror("allocation failure 1 in rgbx8matrix()");
    852     m += NR_END;
    853     m -= nrl;
    854    
    855     /* allocate rows and set pointers to them */
    856     m[nrl]=(rgbx8*) calloc((size_t)(nrow*ncol+NR_END), sizeof(rgbx8));
    857     if (!m[nrl]) nrerror("allocation failure 2 in rgbx8matrix()");
    858     m[nrl] += NR_END;
    859     m[nrl] -= ncl;
    860    
    861     for(i=nrl+1;i<=nrh;i++) m[i]=m[i-1]+ncol;
    862    
    863     /* return pointer to array of pointers to rows */
    864     return m;
    865 }
    866 /* -------------------------------------------------------------------- */
    867 IMAGE_EXPORT(rgb32**) rgb32matrix0(long nrl, long nrh, long ncl, long nch)
    868 /* -------------------------------------------------------------------- */
    869 /* allocate a rgb32 matrix with subscript range m[nrl..nrh][ncl..nch] */
    870 {
    871     long i, nrow=nrh-nrl+1,ncol=nch-ncl+1;
    872     rgb32 **m;
    873    
    874     /* allocate pointers to rows */
    875     m=(rgb32**) malloc((size_t)((nrow+NR_END)*sizeof(rgb32*)));
    876     if (!m) nrerror("allocation failure 1 in rgb32matrix0()");
    877     m += NR_END;
    878     m -= nrl;
    879    
    880     /* allocate rows and set pointers to them */
    881     m[nrl]=(rgb32*) calloc((nrow*ncol+NR_END), sizeof(rgb32));
    882     if (!m[nrl]) nrerror("allocation failure 2 in rgb32matrix0()");
    883     m[nrl] += NR_END;
    884     m[nrl] -= ncl;
    885    
    886     for(i=nrl+1;i<=nrh;i++) m[i]=m[i-1]+ncol;
    887    
    888     /* return pointer to array of pointers to rows */
    889     return m;
    890 }
    891 /* ---------------------------------------------------------------------- */
    892 IMAGE_EXPORT(rgbx32**) rgbx32matrix0(long nrl, long nrh, long ncl, long nch)
    893 /* ---------------------------------------------------------------------- */
    894 /* allocate a rgb32 matrix with subscript range m[nrl..nrh][ncl..nch] */
    895 {
    896     long i, nrow=nrh-nrl+1,ncol=nch-ncl+1;
    897     rgbx32 **m;
    898    
    899     /* allocate pointers to rows */
    900     m=(rgbx32**) malloc((size_t)((nrow+NR_END)*sizeof(rgbx32*)));
    901     if (!m) nrerror("allocation failure 1 in rgbx32matrix()");
    902     m += NR_END;
    903     m -= nrl;
    904    
    905     /* allocate rows and set pointers to them */
    906     m[nrl]=(rgbx32*) calloc((size_t)(nrow*ncol+NR_END), sizeof(rgbx32));
    907     if (!m[nrl]) nrerror("allocation failure 2 in rgbx32matrix()");
    908     m[nrl] += NR_END;
    909     m[nrl] -= ncl;
    910    
    911     for(i=nrl+1;i<=nrh;i++) m[i]=m[i-1]+ncol;
    912    
    913     /* return pointer to array of pointers to rows */
    914     return m;
    915 }
    916 /*
    917  * -------------------
    918  * --- free_matrix ---
    919  * -------------------
    920  */
    921 
    922 /* ------------------------------------------------------------- */
    923 void free_matrix(float **m, long nrl, long nrh, long ncl, long nch)
    924 /* ------------------------------------------------------------- */
    925 /* free a float matrix allocated by matrix() */
    926 {
    927     free((FREE_ARG) (m[nrl]+ncl-NR_END));
    928     free((FREE_ARG) (m+nrl-NR_END));
    929 }
    930 /* --------------------------------------------------------------------------- */
    931 IMAGE_EXPORT(void) free_bmatrix(byte **m, long nrl, long nrh, long ncl, long nch)
    932 /* --------------------------------------------------------------------------- */
    933 {
    934     free((FREE_ARG) (m[nrl]+ncl-NR_END));
    935     free((FREE_ARG) (m+nrl-NR_END));
    936 }
    937 /* ------------------------------------------------------------------------------ */
    938 IMAGE_EXPORT(void) free_si8matrix(sint8 **m, long nrl, long nrh, long ncl, long nch)
    939 /* ------------------------------------------------------------------------------ */
    940 {
    941     free((FREE_ARG) (m[nrl]+ncl-NR_END));
    942     free((FREE_ARG) (m+nrl-NR_END));
    943 }
    944 /* ------------------------------------------------------------------------------ */
    945 IMAGE_EXPORT(void) free_ui8matrix(uint8 **m, long nrl, long nrh, long ncl, long nch)
    946 /* ------------------------------------------------------------------------------ */
    947 {
    948     free((FREE_ARG) (m[nrl]+ncl-NR_END));
    949     free((FREE_ARG) (m+nrl-NR_END));
    950 }/* -------------------------------------------------------------------------------- */
    951 IMAGE_EXPORT(void) free_si16matrix(sint16 **m, long nrl, long nrh, long ncl, long nch)
    952 /* -------------------------------------------------------------------------------- */
    953 
    954     free((FREE_ARG) (m[nrl]+ncl-NR_END));
    955     free((FREE_ARG) (m+nrl-NR_END));
    956 }
    957 /* -------------------------------------------------------------------------------- */
    958 IMAGE_EXPORT(void) free_ui16matrix(uint16 **m, long nrl, long nrh, long ncl, long nch)
    959 /* -------------------------------------------------------------------------------- */
    960 
    961     free((FREE_ARG) (m[nrl]+ncl-NR_END));
    962     free((FREE_ARG) (m+nrl-NR_END));
    963 }
    964 /* -------------------------------------------------------------------------------- */
    965 IMAGE_EXPORT(void) free_si32matrix(sint32 **m, long nrl, long nrh, long ncl, long nch)
    966 /* -------------------------------------------------------------------------------- */
    967 
    968     free((FREE_ARG) (m[nrl]+ncl-NR_END));
    969     free((FREE_ARG) (m+nrl-NR_END));
    970 }
    971 /* -------------------------------------------------------------------------------- */
    972 IMAGE_EXPORT(void) free_ui32matrix(uint32 **m, long nrl, long nrh, long ncl, long nch)
    973 /* -------------------------------------------------------------------------------- */
    974 
    975     free((FREE_ARG) (m[nrl]+ncl-NR_END));
    976     free((FREE_ARG) (m+nrl-NR_END));
    977 }
    978 /* -------------------------------------------------------------------------------- */
    979 IMAGE_EXPORT(void) free_si64matrix(sint64 **m, long nrl, long nrh, long ncl, long nch)
    980 /* -------------------------------------------------------------------------------- */
    981 
    982     free((FREE_ARG) (m[nrl]+ncl-NR_END));
    983     free((FREE_ARG) (m+nrl-NR_END));
    984 }
    985 /* -------------------------------------------------------------------------------- */
    986 IMAGE_EXPORT(void) free_ui64matrix(uint64 **m, long nrl, long nrh, long ncl, long nch)
    987 /* -------------------------------------------------------------------------------- */
    988 
    989     free((FREE_ARG) (m[nrl]+ncl-NR_END));
    990     free((FREE_ARG) (m+nrl-NR_END));
    991 }
    992 /* -------------------------------------------------------------------------------- */
    993 IMAGE_EXPORT(void) free_f32matrix(float32 **m, long nrl, long nrh, long ncl, long nch)
    994 /* -------------------------------------------------------------------------------- */
    995 {
    996     free((FREE_ARG) (m[nrl]+ncl-NR_END));
    997     free((FREE_ARG) (m+nrl-NR_END));
    998 }
    999 /* -------------------------------------------------------------------------------- */
    1000 IMAGE_EXPORT(void) free_f64matrix(float64 **m, long nrl, long nrh, long ncl, long nch)
    1001 /* -------------------------------------------------------------------------------- */
    1002 {
    1003     free((FREE_ARG) (m[nrl]+ncl-NR_END));
    1004     free((FREE_ARG) (m+nrl-NR_END));
    1005 }
    1006 /* ---------------------------------------------------------------------------------- */
    1007 IMAGE_EXPORT(void) free_c32matrix(complex32 **m, long nrl, long nrh, long ncl, long nch)
    1008 /* ---------------------------------------------------------------------------------- */
    1009 {
    1010     free((FREE_ARG) (m[nrl]+ncl-NR_END));
    1011     free((FREE_ARG) (m+nrl-NR_END));
    1012 }
    1013 /* ---------------------------------------------------------------------------------- */
    1014 IMAGE_EXPORT(void) free_c64matrix(complex64 **m, long nrl, long nrh, long ncl, long nch)
    1015 /* ---------------------------------------------------------------------------------- */
    1016 {
    1017     free((FREE_ARG) (m[nrl]+ncl-NR_END));
    1018     free((FREE_ARG) (m+nrl-NR_END));
    1019 }
    1020 /* ------------------------------------------------------------------------------ */
    1021 IMAGE_EXPORT(void) free_rgb8matrix(rgb8 **m, long nrl, long nrh, long ncl, long nch)
    1022 /* ------------------------------------------------------------------------------ */
    1023 {
    1024     free((FREE_ARG) (m[nrl]+ncl-NR_END));
    1025     free((FREE_ARG) (m+nrl-NR_END));
    1026 }
    1027 /* -------------------------------------------------------------------------------- */
    1028 IMAGE_EXPORT(void) free_rgbx8matrix(rgbx8 **m, long nrl, long nrh, long ncl, long nch)
    1029 /* -------------------------------------------------------------------------------- */
    1030 {
    1031     free((FREE_ARG) (m[nrl]+ncl-NR_END));
    1032     free((FREE_ARG) (m+nrl-NR_END));
    1033 }
    1034 /* ------------------------------------------------------------------------------ */
    1035 IMAGE_EXPORT(void) free_rgb32matrix(rgb32 **m, long nrl, long nrh, long ncl, long nch)
    1036 /* ------------------------------------------------------------------------------ */
    1037 {
    1038     free((FREE_ARG) (m[nrl]+ncl-NR_END));
    1039     free((FREE_ARG) (m+nrl-NR_END));
    1040 }
    1041 /* ---------------------------------------------------------------------------------- */
    1042 IMAGE_EXPORT(void) free_rgbx32matrix(rgbx32 **m, long nrl, long nrh, long ncl, long nch)
    1043 /* ---------------------------------------------------------------------------------- */
    1044 {
    1045     free((FREE_ARG) (m[nrl]+ncl-NR_END));
    1046     free((FREE_ARG) (m+nrl-NR_END));
    1047 }
     48
     49
     50#undef type_matrix
     51#define type_matrix(t) \
     52t ** short_name(t,,matrix)(int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch) \
     53{                                                                              \
     54    int32_t nrow = nrh - nrl + 1;                                              \
     55    int32_t ncol = nch - ncl + 1;                                              \
     56    t ** m;                                                                    \
     57    /* allocate pointers to row */                                             \
     58    m = malloc((nrow + NR_END) * sizeof(t *));                                 \
     59    if (m == NULL) {                                                           \
     60        nrerror("*** Error: allocation failure in %s\n", __func__);            \
     61    }                                                                          \
     62    m += NR_END;                                                               \
     63    m -= nrl;                                                                  \
     64    /* allocate rows and set pointers to them */                               \
     65    m[nrl] = malloc((nrow * ncol + NR_END) * sizeof(t));                       \
     66    if (m[nrl] == NULL) {                                                      \
     67        nrerror("*** Error: allocation failure in %s\n", __func__);            \
     68    }                                                                          \
     69    m[nrl] += NR_END;                                                          \
     70    m[nrl] -= ncl;                                                             \
     71    for (int32_t i = nrl + 1; i <= nrh; i++) {                                 \
     72        m[i] = m[i - 1] + ncol;                                                \
     73    }                                                                          \
     74    /* return pointer to array of pointers to rows */                          \
     75    return m;                                                                  \
     76}
     77
     78
     79type_matrix(int8_t);
     80type_matrix(uint8_t);
     81type_matrix(int16_t);
     82type_matrix(uint16_t);
     83type_matrix(int32_t);
     84type_matrix(uint32_t);
     85type_matrix(int64_t);
     86type_matrix(uint64_t);
     87type_matrix(float);
     88type_matrix(double);
     89type_matrix(void_p);
     90type_matrix(rgb8);
     91type_matrix(rgbx8);
     92type_matrix(rgb32);
     93type_matrix(rgbx32);
     94type_matrix(complex32);
     95type_matrix(complex64);
     96type_matrix(si16Point);
     97type_matrix(ui16Point);
     98type_matrix(si32Point);
     99type_matrix(ui32Point);
     100type_matrix(f32Point);
     101type_matrix(si16Triplet);
     102type_matrix(ui16Triplet);
     103type_matrix(si32Triplet);
     104type_matrix(ui32Triplet);
     105type_matrix(f32Triplet);
     106
     107
     108
     109
     110#undef type_matrix0
     111#define type_matrix0(t) \
     112t ** short_name(t,,matrix0)(int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch) \
     113{                                                                               \
     114    int32_t nrow = nrh - nrl + 1;                                               \
     115    int32_t ncol = nch - ncl + 1;                                               \
     116    t ** m;                                                                     \
     117    /* allocate pointers to row */                                              \
     118    m = malloc((nrow + NR_END) * sizeof(t *));                                  \
     119    if (m == NULL) {                                                            \
     120        nrerror("*** Error: allocation failure in %s\n", __func__);             \
     121    }                                                                           \
     122    m += NR_END;                                                                \
     123    m -= nrl;                                                                   \
     124    /* allocate rows and set pointers to them */                                \
     125    m[nrl] = calloc((nrow * ncol + NR_END), sizeof(t));                         \
     126    if (m[nrl] == NULL) {                                                       \
     127        nrerror("*** Error: allocation failure in %s\n", __func__);             \
     128    }                                                                           \
     129    m[nrl] += NR_END;                                                           \
     130    m[nrl] -= ncl;                                                              \
     131    for (int32_t i = nrl + 1; i <= nrh; i++) {                                  \
     132        m[i] = m[i - 1] + ncol;                                                 \
     133    }                                                                           \
     134    /* return pointer to array of pointers to rows */                           \
     135    return m;                                                                   \
     136}
     137
     138
     139type_matrix0(int8_t);
     140type_matrix0(uint8_t);
     141type_matrix0(int16_t);
     142type_matrix0(uint16_t);
     143type_matrix0(int32_t);
     144type_matrix0(uint32_t);
     145type_matrix0(int64_t);
     146type_matrix0(uint64_t);
     147type_matrix0(float);
     148type_matrix0(double);
     149type_matrix0(void_p);
     150type_matrix0(rgb8);
     151type_matrix0(rgbx8);
     152type_matrix0(rgb32);
     153type_matrix0(rgbx32);
     154type_matrix0(complex32);
     155type_matrix0(complex64);
     156
     157
     158#if TARGET_OS == GIETVM
     159
     160#undef remote_type_matrix
     161#define remote_type_matrix(t) \
     162t ** short_name(t,remote_,matrix)(int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch) \
     163{                                                                              \
     164    int32_t nrow = nrh - nrl + 1;                                              \
     165    int32_t ncol = nch - ncl + 1;                                              \
     166    t ** m;                                                                    \
     167    /* allocate pointers to row */                                             \
     168    m = malloc((nrow + NR_END) * sizeof(t *));                                 \
     169    if (m == NULL) {                                                           \
     170        nrerror("*** Error: allocation failure in %s\n", __func__);            \
     171    }                                                                          \
     172    m += NR_END;                                                               \
     173    m -= nrl;                                                                  \
     174    /* allocate rows and set pointers to them */                               \
     175    m[nrl] = malloc((nrow * ncol + NR_END) * sizeof(t));                       \
     176    if (m[nrl] == NULL) {                                                      \
     177        nrerror("*** Error: allocation failure in %s\n", __func__);            \
     178    }                                                                          \
     179    m[nrl] += NR_END;                                                          \
     180    m[nrl] -= ncl;                                                             \
     181    for (int32_t i = nrl + 1; i <= nrh; i++) {                                 \
     182        m[i] = m[i - 1] + ncol;                                                \
     183    }                                                                          \
     184    /* return pointer to array of pointers to rows */                          \
     185    return m;                                                                  \
     186}
     187
     188
     189remote_type_matrix(int8_t);
     190remote_type_matrix(uint8_t);
     191remote_type_matrix(int16_t);
     192remote_type_matrix(uint16_t);
     193remote_type_matrix(int32_t);
     194remote_type_matrix(uint32_t);
     195remote_type_matrix(int64_t);
     196remote_type_matrix(uint64_t);
     197remote_type_matrix(float);
     198remote_type_matrix(double);
     199remote_type_matrix(void_p);
     200remote_type_matrix(rgb8);
     201remote_type_matrix(rgbx8);
     202remote_type_matrix(rgb32);
     203remote_type_matrix(rgbx32);
     204remote_type_matrix(complex32);
     205remote_type_matrix(complex64);
     206
     207#endif
     208
     209
     210#undef free_type_matrix
     211#define free_type_matrix(t) \
     212void short_name(t,free_,matrix)(t ** m, int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch) \
     213{ \
     214    free((FREE_ARG) (m[nrl] + ncl - NR_END)); \
     215    free((FREE_ARG) (m + nrl - NR_END)); \
     216}
     217
     218free_type_matrix(int8_t);
     219free_type_matrix(uint8_t);
     220free_type_matrix(int16_t);
     221free_type_matrix(uint16_t);
     222free_type_matrix(int32_t);
     223free_type_matrix(uint32_t);
     224free_type_matrix(int64_t);
     225free_type_matrix(uint64_t);
     226free_type_matrix(float);
     227free_type_matrix(double);
     228free_type_matrix(void_p);
     229free_type_matrix(rgb8);
     230free_type_matrix(rgbx8);
     231free_type_matrix(rgb32);
     232free_type_matrix(rgbx32);
     233free_type_matrix(complex32);
     234free_type_matrix(complex64);
     235free_type_matrix(si16Point);
     236free_type_matrix(ui16Point);
     237free_type_matrix(si32Point);
     238free_type_matrix(ui32Point);
     239free_type_matrix(f32Point);
     240free_type_matrix(si16Triplet);
     241free_type_matrix(ui16Triplet);
     242free_type_matrix(si32Triplet);
     243free_type_matrix(ui32Triplet);
     244free_type_matrix(f32Triplet);
     245
     246
     247
     248// Local Variables:
     249// tab-width: 4
     250// c-basic-offset: 4
     251// c-file-offsets:((innamespace . 0)(inline-open . 0))
     252// indent-tabs-mode: nil
     253// End:
     254// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4
     255
Note: See TracChangeset for help on using the changeset viewer.