Changeset 823 for soft


Ignore:
Timestamp:
Jun 14, 2016, 5:23:56 PM (8 years ago)
Author:
meunier
Message:
  • Improved scripts for simulations and graphes
  • Continued to clean up the lib nrc2 (from nrio2x.x to nrmem1.c)
  • Added a version (Fast - Parmerge - No stats)
Location:
soft/giet_vm/applications/rosenfeld
Files:
22 edited

Legend:

Unmodified
Added
Removed
  • soft/giet_vm/applications/rosenfeld/Makefile

    r822 r823  
    66
    77TARGET ?= linux
     8IGNORE_ASSERT ?= false
     9
    810#
    911# -- Config ----------
     
    1113ifeq ($(TARGET),giet-vm)
    1214
    13 C_DEBUG_FLAGS = -O0
    1415C_OPTIM_FLAGS = -std=c99 -O2 -fstrict-aliasing
    1516C_OS_FLAGS = -DGTODay -DTARGET_OS=GIETVM
    1617C_CONFIG_FLAGS = -DCLI
    1718C_INC_FLAGS = -I$(INC_PATH) -Inrc2/include -I../.. -I../../giet_libs -I../../giet_xml/
    18 CFLAGSCPU := -mips32 -EL -G0 -mhard-float -fomit-frame-pointer -fno-builtin -ffreestanding
     19CFLAGSCPU = -mips32 -EL -G0 -mhard-float -fomit-frame-pointer -fno-builtin -ffreestanding
    1920
    20 LDFLAGS := -Lnrc2 -L../../build/libs -Trosenfeld.ld --start-group -lnrc2x -luser -lmath --end-group
     21LDFLAGS = -Lnrc2 -L../../build/libs -Trosenfeld.ld --start-group -lnrc2x -luser -lmath --end-group
    2122
    2223endif
     
    2829
    2930# -- Config ----------
    30 C_DEBUG_FLAGS = -O0
    3131C_OPTIM_FLAGS = -std=c99 -O2 -fstrict-aliasing
    3232C_OS_FLAGS = -DGTODay -DTARGET_OS=LINUX -D_GNU_SOURCE
     
    3434C_INC_FLAGS = -I$(INC_PATH) -Inrc2/include
    3535CFLAGSCPU =
     36ifeq ($(IGNORE_ASSERT),true)
     37C_OPTIM_FLAGS := $(C_OPTIM_FLAGS) -DNDEBUG
     38endif
    3639
    37 LDFLAGS := -Lnrc2 -Wl,--start-group -lnrc2x -lm -lpthread -Wl,--end-group
     40LDFLAGS = -Lnrc2 -Wl,--start-group -lnrc2x -lm -lpthread -Wl,--end-group
    3841
    3942endif
     
    4144
    4245
    43 CFLAGSW := -Wredundant-decls -Wdisabled-optimization -Winline -Wpointer-arith -Wsign-compare -Wendif-labels -Wno-unused-function -Wno-unused-variable
     46CFLAGSW = -Wredundant-decls -Wdisabled-optimization -Winline -Wpointer-arith -Wsign-compare -Wendif-labels -Wno-unused-function -Wno-unused-variable
    4447
    4548# -- Flags ----------
    46 #CFLAGS = $(C_DEBUG_FLAGS) $(C_OS_FLAGS) $(C_INC_FLAGS) $(C_CONFIG_FLAGS)
    4749CFLAGS = $(C_OPTIM_FLAGS) $(C_OS_FLAGS) $(C_INC_FLAGS) $(C_CONFIG_FLAGS) -g -Wall $(CFLAGSW) $(CFLAGSCPU)
    4850
  • soft/giet_vm/applications/rosenfeld/include/clock.h

    r822 r823  
    77#include "nrc_os_config.h"
    88#if TARGET_OS == LINUX
     9    #include <x86intrin.h>
    910    #include <sys/time.h>
    1011#endif
     
    1718 * - CLOCK_APP_CREATE;
    1819 * - CLOCK_THREAD_START(thread_id);
    19  * - CLOCK_THREAD_COMPUTE_START(thread_id;
    20  * - CLOCK_THREAD_START_STEP(thread_id, step_id)
    21  * - CLOCK_THREAD_END_STEP(thread_id, step_id)
    22  * - (repeat num_steps times)
    23  * - CLOCK_THREAD_COMPUTE_END(thread_id);
     20 * - Repeat num_runs times:
     21 *     - CLOCK_THREAD_COMPUTE_START(thread_id;
     22 *     - Repeat num_step times:
     23 *         - CLOCK_THREAD_START_STEP(thread_id, step_id)
     24 *         - CLOCK_THREAD_END_STEP(thread_id, step_id)
     25 *     - CLOCK_THREAD_COMPUTE_END(thread_id);
     26 *     - CLOCK_ACCUMULATE;
    2427 * - CLOCK_THREAD_END(thread_id)
    2528 * - CLOCK_APP_JOIN;
     
    2831 * - PRINT_CLOCK;
    2932 * - CLOCK_FREE;
     33 * In case of several runs, the THREAD_COMPUTE and all the THREAD_STEP resulting times
     34 * are averaged over all the runs. The other times are kind of irrelevant.
     35 * TODO: make a struct gathering all variables and change macros to functions
    3036 */
    3137
    3238
    3339static void local_sort_asc(uint64_t tab[], int32_t size) {
    34     int32_t tmp;
     40    uint64_t tmp;
    3541    int32_t i, j;
    3642    for (i = 0; i < size; i++) {
     
    6167                  int32_t step_number;                  \
    6268                  int32_t clock_thread_num;             \
     69                  int32_t clock_num_runs;               \
    6370                  uint64_t ** thread_start_step;        \
    6471                  uint64_t ** thread_end_step;          \
     
    6774                  uint64_t global_thread_compute_start; \
    6875                  uint64_t global_thread_compute_end;   \
     76                  uint64_t accumulated_thread_compute;  \
    6977                  uint64_t * global_thread_start_step;  \
    70                   uint64_t * global_thread_end_step;
     78                  uint64_t * global_thread_end_step;    \
     79                  uint64_t * accumulated_thread_step;
    7180
    7281#if TARGET_OS == GIETVM
    7382    #define CLOCK(x)  ({ x = giet_proctime(); })
    7483#elif TARGET_OS == LINUX
    75     #define CLOCK(x)  ({                      \
     84    /*#define CLOCK(x)  ({                      \
    7685            struct timeval full_time;         \
    7786            gettimeofday(&full_time, NULL);   \
    7887            x = (uint64_t) ((full_time.tv_usec + full_time.tv_sec * 1000000)); \
    79             })
     88            }) */
     89    #define CLOCK(x) ({ x = __rdtsc(); })
    8090#endif
    8191
     
    8494    clock_thread_num = (x);                                                         \
    8595    step_number = (y);                                                              \
     96    clock_num_runs = 0;                                                             \
    8697    global_thread_start = 0xFFFFFFFFFFFFFFFFLLU;                                    \
    8798    global_thread_end = 0;                                                          \
    8899    global_thread_compute_start = 0xFFFFFFFFFFFFFFFFLLU;                            \
    89100    global_thread_compute_end = 0;                                                  \
     101    accumulated_thread_compute = 0;                                                 \
    90102    if ((x) > 0) {                                                                  \
    91103        thread_start = (uint64_t *) malloc(sizeof(uint64_t) * (x));                 \
     
    98110            thread_start_step = (uint64_t **) malloc(sizeof(uint64_t *) * (y));     \
    99111            thread_end_step = (uint64_t **) malloc(sizeof(uint64_t *) * (y));       \
     112            accumulated_thread_step = (uint64_t *) malloc(sizeof(uint64_t) * (y));  \
    100113            for (int32_t j = 0; j < (y); j++) {                                     \
    101                 global_thread_start_step[j] = 0xFFFFFFFFFFFFFFFFLU;                 \
     114                global_thread_start_step[j] = 0xFFFFFFFFFFFFFFFFLLU;                \
    102115                global_thread_end_step[j] = 0;                                      \
     116                accumulated_thread_step[j] = 0;                                     \
    103117                thread_start_step[j] = (uint64_t *) malloc(sizeof(uint64_t) * (x)); \
    104118                thread_end_step[j] = (uint64_t *) malloc(sizeof(uint64_t) * (x));   \
     
    120134#define CLOCK_THREAD_END_STEP(x, y)   ({ CLOCK(thread_end_step[y][x]); })
    121135
     136#define CLOCK_ACCUMULATE ({                                              \
     137    for (int32_t i = 0; i < clock_thread_num; i++) {                     \
     138        if (thread_compute_start[i] < global_thread_compute_start) {     \
     139            global_thread_compute_start = thread_compute_start[i];       \
     140        }                                                                \
     141        if (thread_compute_end[i] > global_thread_compute_end) {         \
     142            global_thread_compute_end = thread_compute_end[i];           \
     143        }                                                                \
     144        for (int32_t j = 0; j < step_number; j++) {                      \
     145            if (thread_start_step[j][i] < global_thread_start_step[j]) { \
     146                global_thread_start_step[j] = thread_start_step[j][i];   \
     147            }                                                            \
     148            if (thread_end_step[j][i] > global_thread_end_step[j]) {     \
     149                global_thread_end_step[j] = thread_end_step[j][i];       \
     150            }                                                            \
     151        }                                                                \
     152    }                                                                    \
     153    for (int32_t j = 0; j < step_number; j++) {                          \
     154        accumulated_thread_step[j] += (global_thread_end_step[j] - global_thread_start_step[j]); \
     155        global_thread_start_step[j] = 0xFFFFFFFFFFFFFFFFLLU;             \
     156        global_thread_end_step[j] = 0;                                   \
     157    }                                                                    \
     158    accumulated_thread_compute += (global_thread_compute_end - global_thread_compute_start); \
     159    global_thread_compute_start = 0xFFFFFFFFFFFFFFFFLLU;                 \
     160    global_thread_compute_end = 0;                                       \
     161    clock_num_runs++;                                                    \
     162})
     163
    122164
    123165#define CLOCK_FINALIZE ({                                                \
     166    if (clock_num_runs == 0) {                                           \
     167        CLOCK_ACCUMULATE;                                                \
     168    }                                                                    \
    124169    for (int32_t i = 0; i < clock_thread_num; i++) {                     \
    125170        if (thread_start[i] < global_thread_start) {                     \
     
    146191})
    147192
    148 #define PRINT_CLOCK ({                                                                                                         \
    149     MCA_VERBOSE1(printf("Timestamps:\n"));                                                                                     \
    150     MCA_VERBOSE1(printf("[APP_START]            : %llu\n", app_start));                                                        \
    151     MCA_VERBOSE1(printf("[APP_CREATE]           : %llu\n", app_create));                                                       \
    152     MCA_VERBOSE1(printf("[THREAD_START]         : %llu\n", global_thread_start));                                              \
    153     MCA_VERBOSE1(printf("[THREAD_COMPUTE_START] : %llu\n", global_thread_compute_start));                                      \
    154     for (int32_t j = 0; j < step_number; j++) {                                                                                \
    155         MCA_VERBOSE1(printf("[THREAD_START_STEP_%d]  : %llu\n", j, global_thread_start_step[j]));                              \
    156         MCA_VERBOSE1(printf("[THREAD_END_STEP_%d]    : %llu\n", j, global_thread_end_step[j]));                                \
    157     }                                                                                                                          \
    158     MCA_VERBOSE1(printf("[THREAD_COMPUTE_END]   : %llu\n", global_thread_compute_end));                                        \
    159     MCA_VERBOSE1(printf("[THREAD_END]           : %llu\n", global_thread_end));                                                \
    160     MCA_VERBOSE1(printf("[APP_JOIN]             : %llu\n", app_join));                                                         \
    161     MCA_VERBOSE1(printf("[APP_END]              : %llu\n", app_end));                                                          \
    162     MCA_VERBOSE1(printf("Durations (in cycles):\n"));                                                                          \
    163     MCA_VERBOSE1(printf("[TOTAL]                : %llu\n", app_end - app_start));                                              \
    164     MCA_VERBOSE1(printf("[THREAD]               : %llu\n", app_join - app_create));                                            \
    165     MCA_VERBOSE1(printf("[PARALLEL]             : %llu\n", global_thread_end - global_thread_start));                          \
    166     MCA_VERBOSE1(printf("[PARALLEL_COMPUTE]     : %llu\n", global_thread_compute_end - global_thread_compute_start));          \
    167     for (int32_t j = 0; j < step_number; j++) {                                                                                \
    168         MCA_VERBOSE1(printf("[THREAD_STEP_%d]        : %llu\n", j, global_thread_end_step[j] - global_thread_start_step[j]));  \
    169     }                                                                                                                          \
    170     MCA_VERBOSE1(printf("\n"));                                                                                                \
    171     MCA_VERBOSE1(printf("*** All threads times output in a gnuplot data-style ***\n"));                                        \
    172     local_sort_asc(thread_start, clock_thread_num);                                                                            \
    173     local_sort_asc(thread_compute_start, clock_thread_num);                                                                    \
    174     local_sort_asc(thread_compute_end, clock_thread_num);                                                                      \
    175     local_sort_asc(thread_end, clock_thread_num);                                                                              \
    176     for (int32_t j = 0; j < step_number; j++) {                                                                                \
    177         local_sort_asc(thread_start_step[j], clock_thread_num);                                                                \
    178         local_sort_asc(thread_end_step[j], clock_thread_num);                                                                  \
    179     }                                                                                                                          \
    180     MCA_VERBOSE1(printf("# cycle     thread_id\n"));                                                                           \
    181     for (int32_t i = 0; i < clock_thread_num; i++) {                                                                           \
    182         MCA_VERBOSE1(printf("%llu\t%d\n", thread_start[i], i));                                                                \
    183         MCA_VERBOSE1(printf("%llu\t%d\n", thread_compute_start[i], i));                                                        \
    184         for (int32_t j = 0; j < step_number; j++) {                                                                            \
    185             MCA_VERBOSE1(printf("%llu\t%d\n", thread_start_step[j][i], i));                                                    \
    186             MCA_VERBOSE1(printf("%llu\t%d\n", thread_end_step[j][i], i));                                                      \
    187         }                                                                                                                      \
    188         MCA_VERBOSE1(printf("%llu\t%d\n", thread_compute_end[i], i));                                                          \
    189         MCA_VERBOSE1(printf("%llu\t%d\n", thread_end[i], i));                                                                  \
    190     }                                                                                                                          \
     193
     194#define PRINT_CLOCK ({                                                                                                        \
     195    MCA_VERBOSE1(printf("Timestamps:\n"));                                                                                    \
     196    if (clock_num_runs > 1) {                                                                                                 \
     197        MCA_VERBOSE1(printf("(THREAD_COMPUTE_START, THREAD_COMPUTE_END, THREAD_START_STEPs and THREAD_END_STEPs)\n"));        \
     198        MCA_VERBOSE1(printf("(are those of the last run)\n"));                                                                \
     199    }                                                                                                                         \
     200    MCA_VERBOSE1(printf("[APP_START]            : %llu\n", app_start));                                                       \
     201    MCA_VERBOSE1(printf("[APP_CREATE]           : %llu\n", app_create));                                                      \
     202    MCA_VERBOSE1(printf("[THREAD_START]         : %llu\n", global_thread_start));                                             \
     203    MCA_VERBOSE1(printf("[THREAD_COMPUTE_START] : %llu\n", global_thread_compute_start));                                     \
     204    for (int32_t j = 0; j < step_number; j++) {                                                                               \
     205        MCA_VERBOSE1(printf("[THREAD_START_STEP_%d]  : %llu\n", j, global_thread_start_step[j]));                             \
     206        MCA_VERBOSE1(printf("[THREAD_END_STEP_%d]    : %llu\n", j, global_thread_end_step[j]));                               \
     207    }                                                                                                                         \
     208    MCA_VERBOSE1(printf("[THREAD_COMPUTE_END]   : %llu\n", global_thread_compute_end));                                       \
     209    MCA_VERBOSE1(printf("[THREAD_END]           : %llu\n", global_thread_end));                                               \
     210    MCA_VERBOSE1(printf("[APP_JOIN]             : %llu\n", app_join));                                                        \
     211    MCA_VERBOSE1(printf("[APP_END]              : %llu\n", app_end));                                                         \
     212    MCA_VERBOSE1(printf("Durations (in cycles):\n"));                                                                         \
     213    if (clock_num_runs > 1) {                                                                                                 \
     214        MCA_VERBOSE1(printf("(PARALLEL_COMPUTE and THREAD_STEPs are averaged over %d runs)\n", clock_num_runs));              \
     215    }                                                                                                                         \
     216    MCA_VERBOSE1(printf("[TOTAL]                : %llu\n", app_end - app_start));                                             \
     217    MCA_VERBOSE1(printf("[THREAD]               : %llu\n", app_join - app_create));                                           \
     218    MCA_VERBOSE1(printf("[PARALLEL]             : %llu\n", global_thread_end - global_thread_start));                         \
     219    MCA_VERBOSE1(printf("[PARALLEL_COMPUTE]     : %llu\n", accumulated_thread_compute / clock_num_runs));                     \
     220    for (int32_t j = 0; j < step_number; j++) {                                                                               \
     221        MCA_VERBOSE1(printf("[THREAD_STEP_%d]        : %llu\n", j, accumulated_thread_step[j] / clock_num_runs));             \
     222    }                                                                                                                         \
     223    MCA_VERBOSE1(printf("\n"));                                                                                               \
     224    MCA_VERBOSE1(printf("*** All threads times output in a gnuplot data-style ***\n"));                                       \
     225    local_sort_asc(thread_start, clock_thread_num);                                                                           \
     226    local_sort_asc(thread_compute_start, clock_thread_num);                                                                   \
     227    local_sort_asc(thread_compute_end, clock_thread_num);                                                                     \
     228    local_sort_asc(thread_end, clock_thread_num);                                                                             \
     229    for (int32_t j = 0; j < step_number; j++) {                                                                               \
     230        local_sort_asc(thread_start_step[j], clock_thread_num);                                                               \
     231        local_sort_asc(thread_end_step[j], clock_thread_num);                                                                 \
     232    }                                                                                                                         \
     233    MCA_VERBOSE1(printf("# cycle     thread_id\n"));                                                                          \
     234    for (int32_t i = 0; i < clock_thread_num; i++) {                                                                          \
     235        MCA_VERBOSE1(printf("%llu\t%d\n", thread_start[i] - app_start, i));                                                   \
     236        MCA_VERBOSE1(printf("%llu\t%d\n", thread_compute_start[i] - app_start, i));                                           \
     237        for (int32_t j = 0; j < step_number; j++) {                                                                           \
     238            MCA_VERBOSE1(printf("%llu\t%d\n", thread_start_step[j][i] - app_start, i));                                       \
     239            MCA_VERBOSE1(printf("%llu\t%d\n", thread_end_step[j][i] - app_start, i));                                         \
     240        }                                                                                                                     \
     241        MCA_VERBOSE1(printf("%llu\t%d\n", thread_compute_end[i] - app_start, i));                                             \
     242        MCA_VERBOSE1(printf("%llu\t%d\n", thread_end[i] - app_start, i));                                                     \
     243    }                                                                                                                         \
    191244})
    192245
     
    205258            free(global_thread_start_step);             \
    206259            free(global_thread_end_step);               \
     260            free(accumulated_thread_step);              \
    207261            for (int32_t j = 0; j < step_number; j++) { \
    208262                free(thread_start_step[j]);             \
  • soft/giet_vm/applications/rosenfeld/include/config.h

    r822 r823  
    44
    55#define SLOW 0
    6 #define FEATURES 1
     6#define FEATURES 0
    77#define FAST 1
    88#define PYR_BARRIERS 0
    9 #define PARMERGE 0
     9#define PARMERGE 1
    1010#define ARSP 0
    1111
     
    2121#if FAST
    2222    #if   !FEATURES && !PARMERGE && !ARSP
    23         #define vuse2_Rosenfeld(e, f,    T, D, alpha, F) vuse2_Rosenfeld_Dist(e, f,    T, D, alpha)
    24         #define vuse3_Rosenfeld(e, f, g, T, D, alpha, F) vuse3_Rosenfeld_Dist(e, f, g, T, D, alpha)
     23        #define vuse2_Rosenfeld(e, f,    T, D, alpha, F)  vuse2_Rosenfeld_Dist(e, f,    T, D, alpha)
     24        #define vuse3_Rosenfeld(e, f, g, T, D, alpha, F)  vuse3_Rosenfeld_Dist(e, f, g, T, D, alpha)
    2525    #elif !FEATURES && !PARMERGE &&  ARSP
    26         #define vuse2_Rosenfeld(e, f,    T, D, alpha, F) vuse2_Arsp_Rosenfeld_Dist(e, f,    T, D, alpha)
    27         #define vuse3_Rosenfeld(e, f, g, T, D, alpha, F) vuse3_Arsp_Rosenfeld_Dist(e, f, g, T, D, alpha)
     26        #define vuse2_Rosenfeld(e, f,    T, D, alpha, F)  vuse2_Arsp_Rosenfeld_Dist(e, f,    T, D, alpha)
     27        #define vuse3_Rosenfeld(e, f, g, T, D, alpha, F)  vuse3_Arsp_Rosenfeld_Dist(e, f, g, T, D, alpha)
    2828        #error "Configuration Not implemented"
    2929    #elif !FEATURES &&  PARMERGE && !ARSP
    30         #define vuse2_Rosenfeld(e, f,    T, D, alpha, F) vuse2_Parallel_Rosenfeld_Dist(e, f,    T, D, alpha, F)
    31         #define vuse3_Rosenfeld(e, f, g, T, D, alpha, F) vuse3_Parallel_Rosenfeld_Dist(e, f, g, T, D, alpha, F)
    32         #error "Configuration Not implemented"
     30        #define vuse2_Rosenfeld(e, f,    T, D, alpha, F)  vuse2_Parallel_Rosenfeld_Dist(e, f,    T, D, alpha, F)
     31        #define vuse3_Rosenfeld(e, f, g, T, D, alpha, F)  vuse3_Parallel_Rosenfeld_Dist(e, f, g, T, D, alpha, F)
     32        #define SetRoot_Parallel_FNF(D, rl, rd, alpha, F) SetRoot_Parallel_Rosenfeld_Dist(D, rl, rd, alpha, F)
    3333    #elif !FEATURES &&  PARMERGE &&  ARSP
    34         #define vuse2_Rosenfeld(e, f,    T, D, alpha, F) vuse2_Parallel_Arsp_Rosenfeld_Dist(e, f,    T, D, alpha, F)
    35         #define vuse3_Rosenfeld(e, f, g, T, D, alpha, F) vuse3_Parallel_Arsp_Rosenfeld_Dist(e, f, g, T, D, alpha, F)
     34        #define vuse2_Rosenfeld(e, f,    T, D, alpha, F)  vuse2_Parallel_Arsp_Rosenfeld_Dist(e, f,    T, D, alpha, F)
     35        #define vuse3_Rosenfeld(e, f, g, T, D, alpha, F)  vuse3_Parallel_Arsp_Rosenfeld_Dist(e, f, g, T, D, alpha, F)
    3636    #elif  FEATURES && !PARMERGE && !ARSP
    37         #define vuse2_Rosenfeld(e, f,    T, D, alpha, F) vuse2_Features_Rosenfeld_Dist(e, f,    T, D, alpha, F)
    38         #define vuse3_Rosenfeld(e, f, g, T, D, alpha, F) vuse3_Features_Rosenfeld_Dist(e, f, g, T, D, alpha, F)
     37        #define vuse2_Rosenfeld(e, f,    T, D, alpha, F)  vuse2_Features_Rosenfeld_Dist(e, f,    T, D, alpha, F)
     38        #define vuse3_Rosenfeld(e, f, g, T, D, alpha, F)  vuse3_Features_Rosenfeld_Dist(e, f, g, T, D, alpha, F)
    3939    #elif  FEATURES && !PARMERGE &&  ARSP
    40         #define vuse2_Rosenfeld(e, f,    T, D, alpha, F) vuse2_Features_Arsp_Rosenfeld_Dist(e, f,    T, D, alpha, F)
    41         #define vuse3_Rosenfeld(e, f, g, T, D, alpha, F) vuse3_Features_Arsp_Rosenfeld_Dist(e, f, g, T, D, alpha, F)
     40        #define vuse2_Rosenfeld(e, f,    T, D, alpha, F)  vuse2_Features_Arsp_Rosenfeld_Dist(e, f,    T, D, alpha, F)
     41        #define vuse3_Rosenfeld(e, f, g, T, D, alpha, F)  vuse3_Features_Arsp_Rosenfeld_Dist(e, f, g, T, D, alpha, F)
    4242        #error "Configuration Not implemented"
    4343    #elif  FEATURES &&  PARMERGE && !ARSP
    44         #define vuse2_Rosenfeld(e, f,    T, D, alpha, F) vuse2_Parallel_Features_Rosenfeld_Dist(e, f,    T, D, alpha, F)
    45         #define vuse3_Rosenfeld(e, f, g, T, D, alpha, F) vuse3_Parallel_Features_Rosenfeld_Dist(e, f, g, T, D, alpha, F)
     44        #define vuse2_Rosenfeld(e, f,    T, D, alpha, F)  vuse2_Parallel_Rosenfeld_Dist(e, f,    T, D, alpha, F)
     45        #define vuse3_Rosenfeld(e, f, g, T, D, alpha, F)  vuse3_Parallel_Rosenfeld_Dist(e, f, g, T, D, alpha, F)
     46        #define SetRoot_Parallel_FNF(D, rl, rd, alpha, F) SetRoot_Parallel_Features_Rosenfeld_Dist(D, rl, rd, alpha, F)
    4647    #elif  FEATURES &&  PARMERGE && ARSP
    47         #define vuse2_Rosenfeld(e, f,    T, D, alpha, F) vuse2_Parallel_Features_Arsp_Rosenfeld_Dist(e, f,    T, D, alpha, F)
    48         #define vuse3_Rosenfeld(e, f, g, T, D, alpha, F) vuse3_Parallel_Features_Arsp_Rosenfeld_Dist(e, f, g, T, D, alpha, F)
     48        #define vuse2_Rosenfeld(e, f,    T, D, alpha, F)  vuse2_Parallel_Features_Arsp_Rosenfeld_Dist(e, f,    T, D, alpha, F)
     49        #define vuse3_Rosenfeld(e, f, g, T, D, alpha, F)  vuse3_Parallel_Features_Arsp_Rosenfeld_Dist(e, f, g, T, D, alpha, F)
    4950        #error "Configuration Not implemented"
    5051    #endif
     
    7273// 2 : Standard level
    7374// 3 : Maximum (debug) level
    74 #define MCA_VERBOSE_LEVEL 2
    75 
    76 #endif // __CONFIG_H__
     75#define MCA_VERBOSE_LEVEL 1
    7776
    7877
     78#endif
     79
  • soft/giet_vm/applications/rosenfeld/include/mca.h

    r822 r823  
    6767
    6868typedef struct sMCA {
    69     int p, np;         // numero du processeur et nb total de processeurs
     69    int p, np;   // numero du processeur et nb total de processeurs
     70    int nr;      // nombre de runs successifs à mesurer
    7071   
    7172    uint8  ** X; // image source
     
    7879    int j0, j1;
    7980   
    80     uint32 e0, e1; // indice pour chaque bande
    81     uint32 ne;     // indice max d'etiquettes utilise par bande
     81    uint32 e0, e1;  // indice pour chaque bande
     82    uint32 ne;      // indice max d'etiquettes utilise par bande
     83    uint32 ne_prev; // ne de l'image précédente (pour le reset de T)
    8284
    83     int alpha;     // puissance de 2 >= a la taille d'un bloc
    84     uint32  * T;   // table d'quivalence table (Rosenfeld) ou d'indices (Warp)
    85     uint32 ** D;   // distributed table (instanciee dans chaque worker)
     85    int alpha;      // puissance de 2 >= a la taille d'un bloc
     86    uint32  * T;    // table d'quivalence table (Rosenfeld) ou d'indices (Warp)
     87    uint32 ** D;    // distributed table (instanciee dans chaque worker)
    8688   
    8789    RegionStats * stats;
     
    106108void MCA_Set_Size(MCA * mca, int width, int height);
    107109void MCA_Set_NP(MCA * mca, int np);
     110void MCA_Set_NR(MCA * mca, int nr);
    108111
    109112uint32 MCA_CalcMaxLabels(int connection, uint32 height, uint32 width);
  • soft/giet_vm/applications/rosenfeld/nrc2/Makefile

    r822 r823  
    88# -- File list ----------
    99FILE = nralloc1.c, nralloc2.c, nralloc2x.c, nrarith0.c, nrarith1.c, nrarith2.c, nrarith2x.c, nrbool1.c, nrbool2.c, nrio0.c, nrio1.c, nrio1x.c, nrio2.c, nrlinalg.c, nrlut.c, nrmem1.c, nrmem1x.c, nrmem2.c, nrmem2x.c, nrset1.c, nrset2.c, nrset2x.c, nrsort1.c, nrsort2.c, nrwrap1.c, nrwrap2.c
    10 FILE := $(FILE), nrio1f.c, nrio1xf.c, nrio2f.c # comment if giet
     10FILE := $(FILE), nrio1f.c, nrio1xf.c, nrio2f.c nrio2x.c nrio2xf.c nrio3.c # comment if giet
    1111
    1212
  • soft/giet_vm/applications/rosenfeld/nrc2/include/nrio2x.h

    r772 r823  
    1111#define __NRIO2X_H__
    1212
    13 #ifdef __cplusplus
    14 #pragma message ("C++")
    15 extern "C" {
    16 #endif
    17    
    18 #ifdef VERBOSE_PRAGMA
    19 //#pragma message ("- *** include nrio2x.h ***")
    20 #endif
    2113
    22 IMAGE_EXPORT(void) display_matrix_endline    (byte   **m, long i0, long i1, long j0, long j1, char *format, char *name);
    23 IMAGE_EXPORT(void) display_i16matrix_endline (int16  **m, long i0, long i1, long j0, long j1, char *format, char *name);
    24 IMAGE_EXPORT(void) display_ui16matrix_endline(uint16 **m, long i0, long i1, long j0, long j1, char *format, char *name);
    25 IMAGE_EXPORT(void) display_i32matrix_endline (int32  **m, long i0, long i1, long j0, long j1, char *format, char *name);
    26 IMAGE_EXPORT(void) display_ui32matrix_endline(uint32 **m, long i0, long i1, long j0, long j1, char *format, char *name);
    27 IMAGE_EXPORT(void) display_i64matrix_endline (int64  **m, long i0, long i1, long j0, long j1, char *format, char *name);
    28 IMAGE_EXPORT(void) display_imatrix_endline   (int    **m, long i0, long i1, long j0, long j1, char *format, char *name);
     14/* ------------------------------ */
     15/* --- display_matrix_endline --- */
     16/* --- display_matrix_endline0 --- */
     17/* --- display_matrix_endline1 --- */
     18/* --- display_matrix_number_endline0 --- */
     19/* --- display_matrix_number_endline1 --- */
     20/* ------------------------------ */
    2921
    30 /* ------------------------------- */
    31 /* --- display_matrix_endline0 --- */
     22#define display_type_matrix_endline(t) \
     23void short_name(t,display_,matrix_endline)(t ** m, int32_t i0, int32_t i1, int32_t j0, int32_t j1, char * format, char * name); \
     24void short_name(t,display_,matrix_endline0)(t ** m, int32_t i0, int32_t i1, int32_t j0, int32_t j1, char * format, char * name); \
     25void short_name(t,display_,matrix_endline1)(t ** m, int32_t i0, int32_t i1, int32_t j0, int32_t j1, char * format, char * name); \
     26void short_name(t,display_,matrix_number_endline0)(t ** m, int32_t i0, int32_t i1, int32_t j0, int32_t j1, char * format, char * name); \
     27void short_name(t,display_,matrix_number_endline1)(t ** m, int32_t i0, int32_t i1, int32_t j0, int32_t j1, char * format, char * name);
    3228
    33 IMAGE_EXPORT(void) display_bmatrix_endline0   (byte   **m, long i0, long i1, char *format, char *name);
    34 IMAGE_EXPORT(void) display_i16matrix_endline0 (int16  **m, long i0, long i1, char *format, char *name);
    35 IMAGE_EXPORT(void) display_ui16matrix_endline0(uint16 **m, long i0, long i1, char *format, char *name);
    36 IMAGE_EXPORT(void) display_i32matrix_endline0 (int32  **m, long i0, long i1, char *format, char *name);
    37 IMAGE_EXPORT(void) display_ui32matrix_endline0(uint32 **m, long i0, long i1, char *format, char *name);
    38 IMAGE_EXPORT(void) display_i64matrix_endline0 (int64  **m, long i0, long i1, char *format, char *name);
    39 IMAGE_EXPORT(void) display_imatrix_endline0   (int    **m, long i0, long i1, char *format, char *name);
     29display_type_matrix_endline(int8_t);
     30display_type_matrix_endline(uint8_t);
     31display_type_matrix_endline(int16_t);
     32display_type_matrix_endline(uint16_t);
     33display_type_matrix_endline(int32_t);
     34display_type_matrix_endline(uint32_t);
     35display_type_matrix_endline(int64_t);
     36display_type_matrix_endline(uint64_t);
    4037
    41 /* ------------------------------- */
    42 /* --- display_matrix_endline1 --- */
    43 /* ------------------------------- */
    44 IMAGE_EXPORT(void) display_bmatrix_endline1   (byte   **m,long i0, long i1, long j0, long j1, char *format, char *name);
    45 IMAGE_EXPORT(void) display_i16matrix_endline1 (int16  **m,long i0, long i1, long j0, long j1, char *format, char *name);
    46 IMAGE_EXPORT(void) display_ui16matrix_endline1(uint16 **m,long i0, long i1, long j0, long j1, char *format, char *name);
    47 IMAGE_EXPORT(void) display_i32matrix_endline1 (int32  **m,long i0, long i1, long j0, long j1, char *format, char *name);
    48 IMAGE_EXPORT(void) display_ui32matrix_endline1(uint32 **m,long i0, long i1, long j0, long j1, char *format, char *name);
    49 IMAGE_EXPORT(void) display_i64matrix_endline1 (int64  **m,long i0, long i1, long j0, long j1, char *format, char *name);
    50 IMAGE_EXPORT(void) display_imatrix_endline1   (int    **m,long i0, long i1, long j0, long j1, char *format, char *name);
    51 
    52 /* -------------------------------------- */
    53 /* --- display_matrix_number_endline0 --- */
    54 /* -------------------------------------- */
    55 
    56 IMAGE_EXPORT(void) display_bmatrix_number_endline0   (byte   **m,long i0, long i1, long j0, long j1, char *format, char *name);
    57 IMAGE_EXPORT(void) display_i16matrix_number_endline0 (int16  **m,long i0, long i1, long j0, long j1, char *format, char *name);
    58 IMAGE_EXPORT(void) display_ui16matrix_number_endline0(uint16 **m,long i0, long i1, long j0, long j1, char *format, char *name);
    59 IMAGE_EXPORT(void) display_i32matrix_number_endline0 (int32  **m,long i0, long i1, long j0, long j1, char *format, char *name);
    60 IMAGE_EXPORT(void) display_ui32matrix_number_endline0(uint32 **m,long i0, long i1, long j0, long j1, char *format, char *name);
    61 IMAGE_EXPORT(void) display_i64matrix_number_endline0 (int64  **m,long i0, long i1, long j0, long j1, char *format, char *name);
    62 IMAGE_EXPORT(void) display_imatrix_number_endline0   (int    **m,long i0, long i1, long j0, long j1, char *format, char *name);
    63 
    64 /* -------------------------------------- */
    65 /* --- display_matrix_number_endline1 --- */
    66 /* -------------------------------------- */
    67 
    68 IMAGE_EXPORT(void) display_bmatrix_number_endline1   (byte   **m,long i0, long i1, long j0, long j1, char *format, char *name);
    69 IMAGE_EXPORT(void) display_i16matrix_number_endline1 (int16  **m,long i0, long i1, long j0, long j1, char *format, char *name);
    70 IMAGE_EXPORT(void) display_ui16matrix_number_endline1(uint16 **m,long i0, long i1, long j0, long j1, char *format, char *name);
    71 IMAGE_EXPORT(void) display_i32matrix_number_endline1 (int32  **m,long i0, long i1, long j0, long j1, char *format, char *name);
    72 IMAGE_EXPORT(void) display_ui32matrix_number_endline1(uint32 **m,long i0, long i1, long j0, long j1, char *format, char *name);
    73 IMAGE_EXPORT(void) display_i64matrix_number_endline1 (int64  **m,long i0, long i1, long j0, long j1, char *format, char *name);
    74 IMAGE_EXPORT(void) display_imatrix_number_endline1   (int    **m,long i0, long i1, long j0, long j1, char *format, char *name);
    7538
    7639/* ------------------------- */
     
    7841/* ------------------------- */
    7942
    80 IMAGE_EXPORT(void) display_btrimatrix   (byte    **m, long i0, long i1, long j0, long j1, long step, char *format, char *name);
    81 IMAGE_EXPORT(void) display_i16trimatrix (int16   **m, long i0, long i1, long j0, long j1, long step, char *format, char *name);
    82 IMAGE_EXPORT(void) display_ui16trimatrix(uint16  **m, long i0, long i1, long j0, long j1, long step, char *format, char *name);
    83 IMAGE_EXPORT(void) display_itrimatrix   (int     **m, long i0, long i1, long j0, long j1, long step, char *format, char *name);
    84 IMAGE_EXPORT(void) display_i32trimatrix (int32   **m, long i0, long i1, long j0, long j1, long step, char *format, char *name);
    85 IMAGE_EXPORT(void) display_f32trimatrix (float32 **m, long i0, long i1, long j0, long j1, long step, char *format, char *name);
    86 IMAGE_EXPORT(void) display_f64trimatrix (float64 **m, long i0, long i1, long j0, long j1, long step, char *format, char *name);
     43#define display_type_trimatrix(t) \
     44void short_name(t,display_,trimatrix)(t ** m, int32_t i0, int32_t i1, int32_t j0, int32_t j1, int32_t step, char * format, char * name);
     45
     46display_type_trimatrix(int8_t);
     47display_type_trimatrix(uint8_t);
     48display_type_trimatrix(int16_t);
     49display_type_trimatrix(uint16_t);
     50display_type_trimatrix(int32_t);
     51display_type_trimatrix(uint32_t);
     52display_type_trimatrix(int64_t);
     53display_type_trimatrix(uint64_t);
     54display_type_trimatrix(float);
     55display_type_trimatrix(double);
     56
     57
     58
    8759
    8860/* ----------------------- */
    8961/* --- write_trimatrix --- */
     62/* --- write_matrix_endline --- */
     63/* --- write_imatrix_endline0 --- */
     64/* --- write_imatrix_endline1 --- */
     65/* --- write_imatrix_number_endline0 --- */
     66/* --- write_imatrix_number_endline1 --- */
     67/* -- fwrite_trimatrix -- */
     68/* -- fread_trimatrix -- */
    9069/* ----------------------- */
    9170
    92 IMAGE_EXPORT(void) write_btrimatrix   (byte    **m,long i0,long i1,long j0, long j1, long step, char *format, char *filename);
    93 IMAGE_EXPORT(void) write_i16trimatrix (int16   **m,long i0,long i1,long j0, long j1, long step, char *format, char *filename);
    94 IMAGE_EXPORT(void) write_ui16trimatrix(uint16  **m,long i0,long i1,long j0, long j1, long step, char *format, char *filename);
    95 IMAGE_EXPORT(void) write_itrimatrix   (int     **m,long i0,long i1,long j0, long j1, long step, char *format, char *filename);
    96 IMAGE_EXPORT(void) write_i32trimatrix (int32   **m,long i0,long i1,long j0, long j1, long step, char *format, char *filename);
    97 IMAGE_EXPORT(void) write_f32trimatrix (float32 **m,long i0,long i1,long j0, long j1, long step, char *format, char *filename);
    98 IMAGE_EXPORT(void) write_f64trimatrix (float64 **m,long i0,long i1,long j0, long j1, long step, char *format, char *filename);
     71#define write_type_trimatrix(t) \
     72void short_name(t,write_,trimatrix)(t ** m, int32_t i0, int32_t i1, int32_t j0, int32_t j1, int32_t step, char * format, char * filename); \
     73void short_name(t,write_,matrix_endline)(t ** m, int32_t i0, int32_t i1, int32_t j0, int32_t j1, char * format, char * filename); \
     74void short_name(t,write_,matrix_endline0)(t ** m, int32_t i0, int32_t i1, int32_t j0, int32_t j1, char * format, char * filename); \
     75void short_name(t,write_,matrix_endline1)(t ** m, int32_t i0, int32_t i1, int32_t j0, int32_t j1, char * format, char * filename); \
     76void short_name(t,write_,matrix_number_endline0)(t ** m, int32_t i0, int32_t i1, int32_t j0, int32_t j1, char * format, char * filename); \
     77void short_name(t,write_,matrix_number_endline1)(t ** m, int32_t i0, int32_t i1, int32_t j0, int32_t j1, char * format, char * filename); \
     78void short_name(t,fwrite_,trimatrix)(t ** m, int32_t i0, int32_t i1, int32_t j0, int32_t j1, int32_t step, char * filename); \
     79void short_name(t,fread_,trimatrix)(char * filename, t ** m, int32_t i0, int32_t i1, int32_t j0, int32_t j1, int32_t step);
    9980
    100 /* ---------------------------- */
    101 /* --- write_matrix_endline --- */
    102 /* ---------------------------- */
     81write_type_trimatrix(int8_t);
     82write_type_trimatrix(uint8_t);
     83write_type_trimatrix(int16_t);
     84write_type_trimatrix(uint16_t);
     85write_type_trimatrix(int32_t);
     86write_type_trimatrix(uint32_t);
     87write_type_trimatrix(int64_t);
     88write_type_trimatrix(uint64_t);
     89write_type_trimatrix(float);
     90write_type_trimatrix(double);
    10391
    104 IMAGE_EXPORT(void) write_bmatrix_endline   (byte   **m,long i0, long i1, long j0, long j1, char *format, char *filename);
    105 IMAGE_EXPORT(void) write_i16matrix_endline (int16  **m,long i0, long i1, long j0, long j1, char *format, char *filename);
    106 IMAGE_EXPORT(void) write_ui16matrix_endline(uint16 **m,long i0, long i1, long j0, long j1, char *format, char *filename);
    107 IMAGE_EXPORT(void) write_i32matrix_endline (int32  **m,long i0, long i1, long j0, long j1, char *format, char *filename);
    108 IMAGE_EXPORT(void) write_ui32matrix_endline(uint32 **m,long i0, long i1, long j0, long j1, char *format, char *filename);
    109 IMAGE_EXPORT(void) write_i64matrix_endline (int64  **m,long i0, long i1, long j0, long j1, char *format, char *filename);
    110 IMAGE_EXPORT(void) write_imatrix_endline   (int    **m,long i0, long i1, long j0, long j1, char *format, char *filename);
    11192
    112 /* ------------------------------ */
    113 /* --- write_imatrix_endline0 --- */
    114 /* ------------------------------ */
    115 
    116 IMAGE_EXPORT(void) write_bmatrix_endline0   (byte   **m,long i0, long i1, long j0, long j1, char *format, char *filename);
    117 IMAGE_EXPORT(void) write_i16matrix_endline0 (int16  **m,long i0, long i1, long j0, long j1, char *format, char *filename);
    118 IMAGE_EXPORT(void) write_ui16matrix_endline0(uint16 **m,long i0, long i1, long j0, long j1, char *format, char *filename);
    119 IMAGE_EXPORT(void) write_i32matrix_endline0 (int32  **m,long i0, long i1, long j0, long j1, char *format, char *filename);
    120 IMAGE_EXPORT(void) write_i64matrix_endline0 (int64  **m,long i0, long i1, long j0, long j1, char *format, char *filename);
    121 IMAGE_EXPORT(void) write_ui32matrix_endline0(uint32 **m,long i0, long i1, long j0, long j1, char *format, char *filename);
    122 IMAGE_EXPORT(void) write_imatrix_endline0   (int    **m,long i0, long i1, long j0, long j1, char *format, char *filename);
    123 
    124 /* ------------------------------ */
    125 /* --- write_imatrix_endline1 --- */
    126 /* ------------------------------ */
    127 
    128 IMAGE_EXPORT(void) write_bmatrix_endline1   (byte   **m,long i0, long i1, long j0, long j1, char *format, char *filename);
    129 IMAGE_EXPORT(void) write_i16matrix_endline1 (int16  **m,long i0, long i1, long j0, long j1, char *format, char *filename);
    130 IMAGE_EXPORT(void) write_ui16matrix_endline1(uint16 **m,long i0, long i1, long j0, long j1, char *format, char *filename);
    131 IMAGE_EXPORT(void) write_i32matrix_endline1 (int32  **m,long i0, long i1, long j0, long j1, char *format, char *filename);
    132 IMAGE_EXPORT(void) write_ui32matrix_endline1(uint32 **m,long i0, long i1, long j0, long j1, char *format, char *filename);
    133 IMAGE_EXPORT(void) write_i64matrix_endline1 (int64  **m,long i0, long i1, long j0, long j1, char *format, char *filename);
    134 IMAGE_EXPORT(void) write_imatrix_endline1   (int    **m,long i0, long i1, long j0, long j1, char *format, char *filename);
    135 
    136 /* ------------------------------------- */
    137 /* --- write_imatrix_number_endline0 --- */
    138 /* ------------------------------------- */
    139 
    140 IMAGE_EXPORT(void) write_bmatrix_number_endline0   (byte   **m, long i0, long i1, long j0, long j1, char *format, char *filename);
    141 IMAGE_EXPORT(void) write_i16matrix_number_endline0 (int16  **m, long i0, long i1, long j0, long j1, char *format, char *filename);
    142 IMAGE_EXPORT(void) write_ui16matrix_number_endline0(uint16 **m, long i0, long i1, long j0, long j1, char *format, char *filename);
    143 IMAGE_EXPORT(void) write_i32matrix_number_endline0 (int32  **m, long i0, long i1, long j0, long j1, char *format, char *filename);
    144 IMAGE_EXPORT(void) write_ui32matrix_number_endline0(uint32 **m, long i0, long i1, long j0, long j1, char *format, char *filename);
    145 IMAGE_EXPORT(void) write_i64matrix_number_endline0 (int64  **m, long i0, long i1, long j0, long j1, char *format, char *filename);
    146 IMAGE_EXPORT(void) write_imatrix_number_endline0   (int    **m, long i0, long i1, long j0, long j1, char *format, char *filename);
    147 
    148 /* ------------------------------------- */
    149 /* --- write_imatrix_number_endline1 --- */
    150 /* ------------------------------------- */
    151 
    152 IMAGE_EXPORT(void) write_bmatrix_number_endline1   (byte   **m,long i0, long i1, long j0, long j1, char *format, char *filename);
    153 IMAGE_EXPORT(void) write_i16matrix_number_endline1 (int16  **m,long i0, long i1, long j0, long j1, char *format, char *filename);
    154 IMAGE_EXPORT(void) write_ui16matrix_number_endline1(uint16 **m,long i0, long i1, long j0, long j1, char *format, char *filename);
    155 IMAGE_EXPORT(void) write_i32matrix_number_endline1 (int32  **m,long i0, long i1, long j0, long j1, char *format, char *filename);
    156 IMAGE_EXPORT(void) write_ui32matrix_number_endline1(uint32 **m,long i0, long i1, long j0, long j1, char *format, char *filename);
    157 IMAGE_EXPORT(void) write_i64matrix_number_endline1 (int64  **m,long i0, long i1, long j0, long j1, char *format, char *filename);
    158 IMAGE_EXPORT(void) write_imatrix_number_endline1   (int    **m,long i0, long i1, long j0, long j1, char *format, char *filename);
    159 
    160 /* ---------------------- */
    161 /* -- fwrite_trimatrix -- */
    162 /* ---------------------- */
    163 
    164 IMAGE_EXPORT(void) fwrite_btrimatrix   (byte    **m,long i0,long i1,long j0, long j1, long step, char *filename);
    165 IMAGE_EXPORT(void) fwrite_i16trimatrix (int16   **m,long i0,long i1,long j0, long j1, long step, char *filename);
    166 IMAGE_EXPORT(void) fwrite_ui16trimatrix(uint16  **m,long i0,long i1,long j0, long j1, long step, char *filename);
    167 IMAGE_EXPORT(void) fwrite_i32trimatrix (int32   **m,long i0,long i1,long j0, long j1, long step, char *filename);
    168 IMAGE_EXPORT(void) fwrite_f32trimatrix (float32 **m,long i0,long i1,long j0, long j1, long step, char *filename);
    169 IMAGE_EXPORT(void) fwrite_f64trimatrix (float64 **m,long i0,long i1,long j0, long j1, long step, char *filename);
    170 
    171 /* --------------------- */
    172 /* -- fread_trimatrix -- */
    173 /* --------------------- */
    174 
    175 IMAGE_EXPORT(void) fread_btrimatrix   (char *filename, byte    **m,long i0,long i1,long j0, long j1, long step);
    176 IMAGE_EXPORT(void) fread_i16trimatrix (char *filename, int16   **m,long i0,long i1,long j0, long j1, long step);
    177 IMAGE_EXPORT(void) fread_ui16trimatrix(char *filename, uint16  **m,long i0,long i1,long j0, long j1, long step);
    178 IMAGE_EXPORT(void) fread_itrimatrix   (char *filename, int     **m,long i0,long i1,long j0, long j1, long step);
    179 IMAGE_EXPORT(void) fread_i32trimatrix (char *filename, int32   **m,long i0,long i1,long j0, long j1, long step);
    180 IMAGE_EXPORT(void) fread_f32trimatrix (char *filename, float32 **m,long i0,long i1,long j0, long j1, long step);
    181 IMAGE_EXPORT(void) fread_f64trimatrix (char *filename, float64 **m,long i0,long i1,long j0, long j1, long step);
    182 
    183 #ifdef __cplusplus
    184 }
    185 #endif
    18693
    18794#endif /* __NRIO2X_H__ */
     95
     96
     97// Local Variables:
     98// tab-width: 4
     99// c-basic-offset: 4
     100// c-file-offsets:((innamespace . 0)(inline-open . 0))
     101// indent-tabs-mode: nil
     102// End:
     103
     104// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4
     105
  • soft/giet_vm/applications/rosenfeld/nrc2/include/nrio3.h

    r772 r823  
    77 * Univ Paris Sud XI, CNRS
    88*/
     9
     10#ifndef _NR_IO3_H_
     11#define _NR_IO3_H_
     12
    913/* -------------------- */
    1014/* --- display_cube --- */
     15/* -- write_cube -- */
     16/* -- fread_cube -- */
     17/* -- fwrite_cube -- */
    1118/* -------------------- */
    12 IMAGE_EXPORT(void) display_i8cube  (int8    ***c,long ndl, long ndh, long nrl,long nrh,long ncl, long nch, char *format, char *name);
    13 IMAGE_EXPORT(void) display_i16cube (int16   ***c,long ndl, long ndh, long nrl,long nrh,long ncl, long nch, char *format, char *name);
    14 IMAGE_EXPORT(void) display_ui16cube(uint16  ***c,long ndl, long ndh, long nrl,long nrh,long ncl, long nch, char *format, char *name);
    15 IMAGE_EXPORT(void) display_i32cube (int32   ***c,long ndl, long ndh, long nrl,long nrh,long ncl, long nch, char *format, char *name);
    16 IMAGE_EXPORT(void) display_ui32cube(uint32  ***c,long ndl, long ndh, long nrl,long nrh,long ncl, long nch, char *format, char *name);
    17 IMAGE_EXPORT(void) display_i64cube (int64   ***c,long ndl, long ndh, long nrl,long nrh,long ncl, long nch, char *format, char *name);
    18 IMAGE_EXPORT(void) display_f32cube (float32 ***c,long ndl, long ndh, long nrl,long nrh,long ncl, long nch, char *format, char *name);
    1919
    20 /* ---------------- */
    21 /* -- write_cube -- */
    22 /* ---------------- */
    23 IMAGE_EXPORT(void) write_i8cube  (int8    ***c, long ndl, long ndh, long nrl, long nrh, long ncl, long nch, char *format, char *filename);
    24 IMAGE_EXPORT(void) write_i16cube (int16   ***c, long ndl, long ndh, long nrl, long nrh, long ncl, long nch, char *format, char *filename);
    25 IMAGE_EXPORT(void) write_ui16cube(uint16  ***c, long ndl, long ndh, long nrl, long nrh, long ncl, long nch, char *format, char *filename);
    26 IMAGE_EXPORT(void) write_i32cube (int32   ***c, long ndl, long ndh, long nrl, long nrh, long ncl, long nch, char *format, char *filename);
    27 IMAGE_EXPORT(void) write_ui32cube(uint32  ***c, long ndl, long ndh, long nrl, long nrh, long ncl, long nch, char *format, char *filename);
    28 IMAGE_EXPORT(void) write_i64cube (int64   ***c, long ndl, long ndh, long nrl, long nrh, long ncl, long nch, char *format, char *filename);
    29 IMAGE_EXPORT(void) write_f32cube (float32 ***c, long ndl, long ndh, long nrl, long nrh, long ncl, long nch, char *format, char *filename);
     20#define display_type_cube(t) \
     21void short_name(t,display_,cube)(t *** c, int32_t ndl, int32_t ndh, int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch, char * format, char * name); \
     22void short_name(t,write_,cube)(t *** c, int32_t ndl, int32_t ndh, int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch, char * format, char * filename); \
     23void short_name(t,fread_,cube)(t *** c, int32_t ndl, int32_t ndh, int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch, char * format, char * filename); \
     24void short_name(t,fwrite_,cube)(t *** c, int32_t ndl, int32_t ndh, int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch, char * format, char * filename);
    3025
    31 IMAGE_EXPORT(void) fread_i8cube(char   *filename, int8    ***c, long ndl, long ndh, long nrl, long nrh, long ncl, long nch);
    32 IMAGE_EXPORT(void) fread_i16cube(char  *filename, int16   ***c, long ndl, long ndh, long nrl, long nrh, long ncl, long nch);
    33 IMAGE_EXPORT(void) fread_ui16cube(char *filename, uint16  ***c, long ndl, long ndh, long nrl, long nrh, long ncl, long nch);
    34 IMAGE_EXPORT(void) fread_i32cube(char  *filename, int32   ***c, long ndl, long ndh, long nrl, long nrh, long ncl, long nch);
    35 IMAGE_EXPORT(void) fread_ui32cube(char *filename, uint32  ***c, long ndl, long ndh, long nrl, long nrh, long ncl, long nch);
    36 IMAGE_EXPORT(void) fread_i64cube(char  *filename, int64   ***c, long ndl, long ndh, long nrl, long nrh, long ncl, long nch);
    37 IMAGE_EXPORT(void) fread_f32cube(char  *filename, float32 ***c, long ndl, long ndh, long nrl, long nrh, long ncl, long nch);
     26display_type_cube(int8_t);
     27display_type_cube(uint8_t);
     28display_type_cube(int16_t);
     29display_type_cube(uint16_t);
     30display_type_cube(int32_t);
     31display_type_cube(uint32_t);
     32display_type_cube(int64_t);
     33display_type_cube(uint64_t);
     34display_type_cube(float);
     35display_type_cube(double);
    3836
    39 /* ----------------- */
    40 /* -- fwrite_cube -- */
    41 /* ----------------- */
    42 IMAGE_EXPORT(void) fwrite_i8cube(int8     ***c, long ndl, long ndh, long nrl, long nrh, long ncl, long nch, char *filename);
    43 IMAGE_EXPORT(void) fwrite_i16cube(int16   ***c, long ndl, long ndh, long nrl, long nrh, long ncl, long nch, char *filename);
    44 IMAGE_EXPORT(void) fwrite_ui16cube(uint16 ***c, long ndl, long ndh, long nrl, long nrh, long ncl, long nch, char *filename);
    45 IMAGE_EXPORT(void) fwrite_i32cube(int32   ***c, long ndl, long ndh, long nrl, long nrh, long ncl, long nch, char *filename);
    46 IMAGE_EXPORT(void) fwrite_ui32cube(uint32 ***c, long ndl, long ndh, long nrl, long nrh, long ncl, long nch, char *filename);
    47 IMAGE_EXPORT(void) fwrite_i64cube(int64   ***c, long ndl, long ndh, long nrl, long nrh, long ncl, long nch, char *filename);
     37#endif
     38
  • soft/giet_vm/applications/rosenfeld/nrc2/include/nrlinalg.h

    r772 r823  
    1111#define __NRLINALG_H__
    1212
    13 #ifdef __cplusplus
    14 extern "C" {
    15 #endif
     13#define transpose_type_matrix(t) \
     14void short_name(t,transpose_,matrix)(t ** S, int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch, t ** D); \
     15void short_name(t,transpose1_,matrix)(t ** S, int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch);
    1616
    17 IMAGE_EXPORT(void) transpose_bmatrix(byte **S, long nrl,long nrh,long ncl, long nch, byte **D);
    18 IMAGE_EXPORT(void) transpose_si16matrix(sint16 **S, long nrl,long nrh,long ncl, long nch, sint16 **D);
    19 IMAGE_EXPORT(void) transpose_ui16matrix(uint16 **S, long nrl,long nrh,long ncl, long nch, uint16 **D);
    20 IMAGE_EXPORT(void) transpose_si32matrix(sint32 **S, long nrl,long nrh,long ncl, long nch, sint32 **D);
    21 IMAGE_EXPORT(void) transpose_ui32matrix(uint32 **S, long nrl,long nrh,long ncl, long nch, uint32 **D);
    22 IMAGE_EXPORT(void) transpose_f32matrix(float32 **S, long nrl,long nrh,long ncl, long nch, float32 **D);
    23 IMAGE_EXPORT(void) transpose_dmatrix(float64 **S, long nrl,long nrh,long ncl, long nch, float64 **D);
    24 IMAGE_EXPORT(void) transpose_rgb8matrix(rgb8 **S, long nrl,long nrh,long ncl, long nch, rgb8 **D);
    25 IMAGE_EXPORT(void) transpose1_bmatrix(byte **S, long nrl,long nrh,long ncl, long nch);
    26 IMAGE_EXPORT(void) transpose1_si16matrix(sint16 **S, long nrl,long nrh,long ncl, long nch);
    27 IMAGE_EXPORT(void) transpose1_ui16matrix(uint16 **S, long nrl,long nrh,long ncl, long nch);
    28 IMAGE_EXPORT(void) transpose1_si32matrix(sint32 **S, long nrl,long nrh,long ncl, long nch);
    29 IMAGE_EXPORT(void) transpose1_ui32matrix(uint32 **S, long nrl,long nrh,long ncl, long nch);
    30 IMAGE_EXPORT(void) transpose1_f32matrix(float32 **S, long nrl,long nrh,long ncl, long nch);
    31 IMAGE_EXPORT(void) transpose1_f64matrix(float64 **S, long nrl,long nrh,long ncl, long nch);
    32 IMAGE_EXPORT(void) transpose1_rgb8matrix(rgb8 **S, long nrl,long nrh,long ncl, long nch);
     17transpose_type_matrix(int8_t);
     18transpose_type_matrix(uint8_t);
     19transpose_type_matrix(int16_t);
     20transpose_type_matrix(uint16_t);
     21transpose_type_matrix(int32_t);
     22transpose_type_matrix(uint32_t);
     23transpose_type_matrix(int64_t);
     24transpose_type_matrix(uint64_t);
     25transpose_type_matrix(float);
     26transpose_type_matrix(double);
     27transpose_type_matrix(rgb8);
     28transpose_type_matrix(rgbx8);
    3329
    34 #ifdef __cplusplus
    35 }
    36 #endif
    3730
    3831#endif // __NRLINALG_H__
     32
  • soft/giet_vm/applications/rosenfeld/nrc2/include/nrlut.h

    r772 r823  
    55/*
    66 * Copyright (c) 2000-2014, Lionel Lacassagne, All rights reserved
    7 * Univ Paris Sud XI, CNRS
    8 */
     7 * Univ Paris Sud XI, CNRS
     8 */
    99
    1010#ifndef _NRLUT_H_
    1111#define _NRLUT_H_
    1212
    13 #ifdef __cplusplus
    14 #ifdef PRAGMA_VERBOSE
    15 #pragma message ("C++")
    16 #endif
    17 extern "C" {
    18 #endif
     13#define init_type_lut(t) \
     14void short_name(t,init_,lut)(t * v, int32_t nl, int32_t nh, int32_t n0, int32_t n1, t k); \
     15void short_name(t,lut_,matrix)(t ** S, int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch, t * L, t ** D);
    1916
    20 #ifdef PRAGMA_VERBOSE
    21 #pragma message("- include nrlut.h")
    22 #endif
     17init_type_lut(int8_t);
     18init_type_lut(uint8_t);
     19init_type_lut(int16_t);
     20init_type_lut(uint16_t);
     21init_type_lut(int32_t);
     22init_type_lut(uint32_t);
     23init_type_lut(rgb8);
    2324
    2425
    25 IMAGE_EXPORT(void) init_blut   (byte   *v, int nl, int nh, int n0, int n1, byte   k);
    26 IMAGE_EXPORT(void) init_i8lut  (int8   *v, int nl, int nh, int n0, int n1, int8   k);
    27 IMAGE_EXPORT(void) init_i16lut (int16  *v, int nl, int nh, int n0, int n1, int16  k);
    28 IMAGE_EXPORT(void) init_i32lut (int32  *v, int nl, int nh, int n0, int n1, int32  k);
    29 IMAGE_EXPORT(void) init_ui16lut(uint16 *v, int nl, int nh, int n0, int n1, uint16 k);
    30 IMAGE_EXPORT(void) init_rgb8lut(rgb8   *v, int nl, int nh, int n0, int n1, rgb8   k);
     26void lut_si16matrix_si8matrix(int16_t ** S, int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch, int8_t * L, int8_t ** D);
     27void lut_ui16matrix_ui8matrix(uint16_t ** S, int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch, uint8_t * L, uint8_t ** D);
     28void lut_si32matrix_si16matrix(int32_t ** S, int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch, int16_t * L, int16_t ** D);
     29void lut_ui32matrix_ui16matrix(uint32_t ** S, int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch, uint16_t * L, uint16_t ** D);
    3130
    32 IMAGE_EXPORT(void) lut_bmatrix   (byte    **S, long nrl, long nrh, long ncl, long nch, byte    *L, byte    **D);
    33 IMAGE_EXPORT(void) lut_ui8matrix (uint8   **S, long nrl, long nrh, long ncl, long nch, uint8   *L, uint8   **D);
    34 IMAGE_EXPORT(void) lut_si8matrix (sint8   **S, long nrl, long nrh, long ncl, long nch, sint8   *L, sint8   **D);
    35 IMAGE_EXPORT(void) lut_ui16matrix(uint16  **S, long nrl, long nrh, long ncl, long nch, uint16  *L, uint16  **D);
    36 IMAGE_EXPORT(void) lut_si16matrix(sint16  **S, long nrl, long nrh, long ncl, long nch, sint16  *L, sint16  **D);
    37 IMAGE_EXPORT(void) lut_ui32matrix(uint32  **S, long nrl, long nrh, long ncl, long nch, uint32  *L, uint32  **D);
    38 IMAGE_EXPORT(void) lut_si32matrix(sint32  **S, long nrl, long nrh, long ncl, long nch, sint32  *L, sint32  **D);
    39 IMAGE_EXPORT(void) lut_rgb8matrix(rgb8    **S, long nrl, long nrh, long ncl, long nch, rgb8    *L, rgb8    **D);
    4031
    41 IMAGE_EXPORT(void) lut_si16matrix_si8matrix(sint16 **S, long nrl, long nrh, long ncl, long nch, sint8 *L, sint8 **D);
    42 IMAGE_EXPORT(void) lut_ui16matrix_ui8matrix(uint16 **S, long nrl, long nrh, long ncl, long nch, uint8 *L, uint8 **D);
    43 IMAGE_EXPORT(void) lut_si32matrix_si16matrix(sint32 **S, long nrl, long nrh, long ncl, long nch, sint16 *L, sint16 **D);
    44 IMAGE_EXPORT(void) lut_ui32matrix_ui16matrix(uint32 **S, long nrl, long nrh, long ncl, long nch, uint16 *L, uint16 **D);
    45    
    46 IMAGE_EXPORT(void) histogram_bmatrix   (byte   **S, long nrl, long nrh, long ncl, long nch, int32 *H);
    47 IMAGE_EXPORT(void) histogram_ui16matrix(uint16 **S, long nrl, long nrh, long ncl, long nch, int32 *H);
    48 IMAGE_EXPORT(void) histogram_rgb8matrix(rgb8   **S, long nrl, long nrh, long ncl, long nch, rgb32 *H);
     32#define histogram_type_matrix(t) \
     33void short_name(t,histogram_,matrix)(t ** S, int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch, t * H);
    4934
    50 #ifdef __cplusplus
    51 }
    52 #endif
     35histogram_type_matrix(int8_t);
     36histogram_type_matrix(uint8_t);
     37histogram_type_matrix(int16_t);
     38histogram_type_matrix(uint16_t);
     39histogram_type_matrix(int32_t);
     40histogram_type_matrix(uint32_t);
     41void histogram_rgb8matrix(rgb8 ** S, int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch, rgb32 * H);
     42
    5343
    5444#endif /* _NRLUT_H_ */
     45
  • soft/giet_vm/applications/rosenfeld/nrc2/include/nrmem1.h

    r772 r823  
    1212#define __NRMEM1_H__
    1313
    14 #ifdef __cplusplus
    15 #pragma message ("C++")
    16 extern "C" {
    17 #endif
    18    
    19 #ifdef VERBOSE_PRAGMA
    20 //#pragma message ("- *** include nrmem1.h ***")
    21 #endif
     14
     15#define dup_type_vector(t) \
     16void short_name(t,dup_,vector)(t * X, int32_t nl, int32_t nh, t * Y);
     17
     18dup_type_vector(int8_t);
     19dup_type_vector(uint8_t);
     20dup_type_vector(int16_t);
     21dup_type_vector(uint16_t);
     22dup_type_vector(int32_t);
     23dup_type_vector(uint32_t);
     24dup_type_vector(int64_t);
     25dup_type_vector(uint64_t);
     26dup_type_vector(float);
     27dup_type_vector(double);
     28dup_type_vector(rgb8);
     29dup_type_vector(rgbx8);
     30
     31/* --------------------- */
     32/* --- split & merge --- */
     33/* --------------------- */
     34
     35void split_rgb8vector(rgb8 * X, int32_t nl, int32_t nh,  uint8_t * R,  uint8_t * G,  uint8_t * B);
     36void split_rgb32vector(rgb32 * X, int32_t nl, int32_t nh, uint32_t * R, uint32_t * G, uint32_t * B);
     37
     38void merge_rgb8vector(uint8_t * R, uint8_t * G, uint8_t * B, int32_t nl, int32_t nh, rgb8 * X);
     39void merge_rgb32vector(uint32_t * R, uint32_t * G, uint32_t * B, int32_t nl, int32_t nh, rgb32 * X);
    2240
    2341
    24 IMAGE_EXPORT(void) dup_si8vector   (sint8   *X, long nl, long nh, sint8   *Y);
    25 IMAGE_EXPORT(void) dup_ui8vector   (uint8   *X, long nl, long nh, uint8   *Y);
    26 IMAGE_EXPORT(void) dup_si16vector  (sint16  *X, long nl, long nh, sint16  *Y);
    27 IMAGE_EXPORT(void) dup_ui16vector  (uint16  *X, long nl, long nh, uint16  *Y);
    28 IMAGE_EXPORT(void) dup_si32vector  (sint32  *X, long nl, long nh, sint32  *Y);
    29 IMAGE_EXPORT(void) dup_ui32vector  (uint32  *X, long nl, long nh, uint32  *Y);
    30 IMAGE_EXPORT(void) dup_si64vector  (sint64  *X, long nl, long nh, sint64  *Y);
    31 IMAGE_EXPORT(void) dup_ui64vector  (uint64  *X, long nl, long nh, uint64  *Y);
    32 IMAGE_EXPORT(void) dup_f32vector   (float32 *X, long nl, long nh, float32 *Y);
    33 IMAGE_EXPORT(void) dup_f64vector   (float64 *X, long nl, long nh, float64 *Y);
    34 IMAGE_EXPORT(void) dup_rgb8vector  (rgb8    *X, long nl, long nh, rgb8    *Y);
    35 IMAGE_EXPORT(void) dup_rgbx8vector (rgbx8   *X, long nl, long nh, rgbx8   *Y);
    3642
    3743/* ---------------- */
    38 /* -- Convertion -- */
     44/* -- Conversion -- */
    3945/* ---------------- */
    4046
    41 // UP
     47#define convert_type1_vector_type2_vector(t1, t2) \
     48void short_name(t1,convert_,short_name(t2,vector_,vector))(t1 * X, int32_t nl, int32_t nh, t2 * Y);
    4249
    43 IMAGE_EXPORT(void) convert_si8vector_si16vector (sint8 *X, long nl, long nh, sint16  *Y);
    44 IMAGE_EXPORT(void) convert_si8vector_si32vector (sint8 *X, long nl, long nh, sint32  *Y);
    45 IMAGE_EXPORT(void) convert_si8vector_f32vector  (sint8 *X, long nl, long nh, float32 *Y);
    46 IMAGE_EXPORT(void) convert_si8vector_f64vector  (sint8 *X, long nl, long nh, float64 *Y);
     50convert_type1_vector_type2_vector(int8_t,int16_t);
     51convert_type1_vector_type2_vector(int8_t,int32_t);
     52convert_type1_vector_type2_vector(int8_t,float);
     53convert_type1_vector_type2_vector(int8_t,double);
     54convert_type1_vector_type2_vector(uint8_t,uint16_t);
     55convert_type1_vector_type2_vector(uint8_t,uint32_t);
     56convert_type1_vector_type2_vector(uint8_t,float);
     57convert_type1_vector_type2_vector(uint8_t,double);
     58convert_type1_vector_type2_vector(int16_t,int32_t);
     59convert_type1_vector_type2_vector(int16_t,float);
     60convert_type1_vector_type2_vector(int16_t,double);
     61convert_type1_vector_type2_vector(uint16_t,uint32_t);
     62convert_type1_vector_type2_vector(uint16_t,float);
     63convert_type1_vector_type2_vector(uint16_t,double);
     64convert_type1_vector_type2_vector(int32_t,float);
     65convert_type1_vector_type2_vector(int32_t,double);
     66convert_type1_vector_type2_vector(uint32_t,float);
     67convert_type1_vector_type2_vector(uint32_t,double);
     68convert_type1_vector_type2_vector(int16_t,int8_t);
     69convert_type1_vector_type2_vector(uint16_t,uint8_t);
     70convert_type1_vector_type2_vector(int32_t,int8_t);
     71convert_type1_vector_type2_vector(int32_t,int16_t);
     72convert_type1_vector_type2_vector(uint32_t,uint8_t);
     73convert_type1_vector_type2_vector(uint32_t,uint16_t);
     74convert_type1_vector_type2_vector(float,int8_t);
     75convert_type1_vector_type2_vector(float,uint8_t);
     76convert_type1_vector_type2_vector(float,int16_t);
     77convert_type1_vector_type2_vector(float,uint16_t);
     78convert_type1_vector_type2_vector(float,int32_t);
     79convert_type1_vector_type2_vector(float,uint32_t);
     80convert_type1_vector_type2_vector(double,int8_t);
     81convert_type1_vector_type2_vector(double,uint8_t);
     82convert_type1_vector_type2_vector(double,int16_t);
     83convert_type1_vector_type2_vector(double,uint16_t);
     84convert_type1_vector_type2_vector(double,int32_t);
     85convert_type1_vector_type2_vector(double,uint32_t);
     86convert_type1_vector_type2_vector(double,float);
     87convert_type1_vector_type2_vector(uint8_t,rgb8);
     88convert_type1_vector_type2_vector(uint8_t,rgbx8);
     89convert_type1_vector_type2_vector(rgb8,uint8_t);
     90convert_type1_vector_type2_vector(rgbx8,uint8_t);
    4791
    48 IMAGE_EXPORT(void) convert_ui8vector_ui16vector (uint8 *X, long nl, long nh, uint16  *Y);
    49 IMAGE_EXPORT(void) convert_ui8vector_ui32vector (uint8 *X, long nl, long nh, uint32  *Y);
    50 IMAGE_EXPORT(void) convert_ui8vector_f32vector  (uint8 *X, long nl, long nh, float32 *Y);
    51 IMAGE_EXPORT(void) convert_ui8vector_f64vector  (uint8 *X, long nl, long nh, float64 *Y);
    52 IMAGE_EXPORT(void) convert_ui8vector_rgb8vector (uint8 *X, long nl, long nh, rgb8    *Y);
    53 IMAGE_EXPORT(void) convert_ui8vector_rgbx8vector(uint8 *X, long nl, long nh, rgbx8   *Y);
    54 
    55 IMAGE_EXPORT(void) convert_si16vector_si32vector (sint16 *X, long nl, long nh, sint32  *Y);
    56 IMAGE_EXPORT(void) convert_si16vector_f32vector  (sint16 *X, long nl, long nh, float32 *Y);
    57 IMAGE_EXPORT(void) convert_si16vector_f64vector  (sint16 *X, long nl, long nh, float64 *Y);
    58 
    59 IMAGE_EXPORT(void) convert_ui16vector_ui32vector (uint16 *X, long nl, long nh, uint32  *Y);
    60 IMAGE_EXPORT(void) convert_ui16vector_f32vector  (uint16 *X, long nl, long nh, float32 *Y);
    61 IMAGE_EXPORT(void) convert_ui16vector_f64vector  (uint16 *X, long nl, long nh, float64 *Y);
    62 
    63 IMAGE_EXPORT(void) convert_si32vector_f32vector (sint32 *X, long nl, long nh, float32 *Y);
    64 IMAGE_EXPORT(void) convert_si32vector_f64vector (sint32 *X, long nl, long nh, float64 *Y);
    65 
    66 IMAGE_EXPORT(void) convert_ui32vector_f32vector (uint32 *X, long nl, long nh, float32 *Y);
    67 IMAGE_EXPORT(void) convert_ui32vector_f64vector (uint32 *X, long nl, long nh, float64 *Y);
    68 
    69 IMAGE_EXPORT(void) convert_f32vector_f64vector (float32 *X, long nl, long nh, float64 *Y);
    70 
    71 // DOWN
    72 
    73 IMAGE_EXPORT(void) convert_si16vector_si8vector(sint16 *X, long nl, long nh, sint8 *Y);
    74 
    75 IMAGE_EXPORT(void) convert_ui16vector_ui8vector(uint16 *X, long nl, long nh, uint8 *Y);
    76 
    77 IMAGE_EXPORT(void) convert_si32vector_si8vector (sint32 *X, long nl, long nh, sint8  *Y);
    78 IMAGE_EXPORT(void) convert_si32vector_si16vector(sint32 *X, long nl, long nh, sint16 *Y);
    79 
    80 IMAGE_EXPORT(void) convert_ui32vector_ui8vector (uint32 *X, long nl, long nh, uint8  *Y);
    81 IMAGE_EXPORT(void) convert_ui32vector_ui16vector(uint32 *X, long nl, long nh, uint16 *Y);
    82 
    83 IMAGE_EXPORT(void) convert_f32vector_si8vector (float32 *X, long nl, long nh, sint8  *Y);
    84 IMAGE_EXPORT(void) convert_f32vector_ui8vector (float32 *X, long nl, long nh, uint8  *Y);
    85 IMAGE_EXPORT(void) convert_f32vector_si16vector(float32 *X, long nl, long nh, sint16 *Y);
    86 IMAGE_EXPORT(void) convert_f32vector_ui16vector(float32 *X, long nl, long nh, uint16 *Y);
    87 IMAGE_EXPORT(void) convert_f32vector_si32vector(float32 *X, long nl, long nh, sint32 *Y);
    88 IMAGE_EXPORT(void) convert_f32vector_ui32vector(float32 *X, long nl, long nh, uint32 *Y);
    89 
    90 IMAGE_EXPORT(void) convert_f64vector_si8vector (float64 *X, long nl, long nh, sint8   *Y);
    91 IMAGE_EXPORT(void) convert_f64vector_ui8vector (float64 *X, long nl, long nh, uint8   *Y);
    92 IMAGE_EXPORT(void) convert_f64vector_si16vector(float64 *X, long nl, long nh, sint16  *Y);
    93 IMAGE_EXPORT(void) convert_f64vector_ui16vector(float64 *X, long nl, long nh, uint16  *Y);
    94 IMAGE_EXPORT(void) convert_f64vector_si32vector(float64 *X, long nl, long nh, sint32  *Y);
    95 IMAGE_EXPORT(void) convert_f64vector_ui32vector(float64 *X, long nl, long nh, uint32  *Y);
    96 IMAGE_EXPORT(void) convert_f64vector_f32vector (float64 *X, long nl, long nh, float32 *Y);
    97 
    98 IMAGE_EXPORT(void) convert_rgb8vector_ui8vector (rgb8  *X, long nl, long nh, uint8 *Y);
    99 IMAGE_EXPORT(void) convert_rgbx8vector_ui8vector(rgbx8 *X, long nl, long nh, uint8 *Y);
    10092
    10193/*
     
    10597 */
    10698
    107 IMAGE_EXPORT(void) lowpart_ui16vector_ui8vector(uint16 *X, long nl,long nh, uint8 *Y);
    108 IMAGE_EXPORT(void) lowpart_ui32vector_ui8vector(uint32 *X, long nl,long nh, uint8 *Y);
    109 
    110 /* --------------------- */
    111 /* --- split & merge --- */
    112 /* --------------------- */
    113 
    114 IMAGE_EXPORT(void) split_rgb8vector(rgb8   *X, long nl, long nh,  uint8 *R,  uint8 *G,  uint8 *B);
    115 IMAGE_EXPORT(void) split_rgb32vector(rgb32 *X, long nl, long nh, uint32 *R, uint32 *G, uint32 *B);
    116 
    117 IMAGE_EXPORT(void) merge_rgb8vector(uint8   *R, uint8  *G, uint8  *B, long nl, long nh, rgb8  *X);
    118 IMAGE_EXPORT(void) merge_rgb32vector(uint32 *R, uint32 *G, uint32 *B, long nl, long nh, rgb32 *X);
    119 
    120 #ifdef __cplusplus
    121 }
    122 #endif
     99void lowpart_ui16vector_ui8vector(uint16_t * X, int32_t nl, int32_t nh, uint8_t * Y);
     100void lowpart_ui32vector_ui8vector(uint32_t * X, int32_t nl, int32_t nh, uint8_t * Y);
    123101
    124102#endif /* __NRMEM1_H__ */
     103
  • soft/giet_vm/applications/rosenfeld/nrc2/include/nrtype.h

    r822 r823  
    2424// Short names
    2525
    26 #define sn_int8_t(p,s)      p##i8##s
    27 #define sn_int16_t(p,s)     p##i16##s
    28 #define sn_int32_t(p,s)     p##i32##s
    29 #define sn_int64_t(p,s)     p##i64##s
     26#define sn_int8_t(p,s)      p##si8##s
     27#define sn_int16_t(p,s)     p##si16##s
     28#define sn_int32_t(p,s)     p##si32##s
     29#define sn_int64_t(p,s)     p##si64##s
    3030#define sn_uint8_t(p,s)     p##ui8##s
    3131#define sn_uint16_t(p,s)    p##ui16##s
  • soft/giet_vm/applications/rosenfeld/nrc2/src/nrio2x.c

    r772 r823  
    2626#include "nrio2x.h"
    2727
     28
     29
    2830/* ------------------------------ */
    2931/* --- display_matrix_endline --- */
    3032/* ------------------------------ */
    31 /* ---------------------------------------------------------------------------------------------------------- */
    32 IMAGE_EXPORT(void) display_matrix_endline(byte **m,long i0, long i1, long j0, long j1, char *format, char *name)
    33 /* ---------------------------------------------------------------------------------------------------------- */
    34 {
    35   int i, j;
    36   int n = (i1-i0+1) * (j1-j0+1);
    37   byte *p = &m[i0][j0];
    38 
    39   if(name != NULL) puts(name);
    40 
    41   for(i=i0; i<=i1; i++) {
    42     for(j=j0; j<=j0+n; j++) {
    43       printf(format, *p++);
    44     }
    45     putchar('\n');
    46   }
    47   putchar('\n');
    48 }
    49 /* -------------------------------------------------------------------------------------------------------------- */
    50 IMAGE_EXPORT(void) display_i16matrix_endline(int16 **m,long i0, long i1, long j0, long j1, char *format, char *name)
    51 /* -------------------------------------------------------------------------------------------------------------- */
    52 {
    53   int i, j;
    54   int n = (i1-i0+1) * (j1-j0+1);
    55   int16 *p = &m[i0][j0];
    56 
    57   if(name != NULL) puts(name);
    58 
    59   for(i=i0; i<=i1; i++) {
    60     for(j=j0; j<=j0+n; j++) {
    61       printf(format, *p++);
    62     }
    63     putchar('\n');
    64   }
    65   putchar('\n');
    66 }
    67 /* ---------------------------------------------------------------------------------------------------------------- */
    68 IMAGE_EXPORT(void) display_ui16matrix_endline(uint16 **m,long i0, long i1, long j0, long j1, char *format, char *name)
    69 /* ---------------------------------------------------------------------------------------------------------------- */
    70 {
    71   int i, j;
    72   int n = (i1-i0+1) * (j1-j0+1);
    73   uint16 *p = &m[i0][j0];
    74 
    75   if(name != NULL) puts(name);
    76 
    77   for(i=i0; i<=i1; i++) {
    78     for(j=j0; j<=j0+n; j++) {
    79       printf(format, *p++);
    80     }
    81     putchar('\n');
    82   }
    83   putchar('\n');
    84 }
    85 /* -------------------------------------------------------------------------------------------------------------- */
    86 IMAGE_EXPORT(void) display_i32matrix_endline(int32 **m,long i0, long i1, long j0, long j1, char *format, char *name)
    87 /* -------------------------------------------------------------------------------------------------------------- */
    88 {
    89   int i, j;
    90   int n = (i1-i0+1) * (j1-j0+1);
    91   int32 *p = &m[i0][j0];
    92 
    93   if(name != NULL) puts(name);
    94 
    95   for(i=i0; i<=i1; i++) {
    96     for(j=j0; j<=j0+n; j++) {
    97       printf(format, *p++);
    98     }
    99     putchar('\n');
    100   }
    101   putchar('\n');
    102 }
    103 /* ----------------------------------------------------------------------------------------------------------------- */
    104 IMAGE_EXPORT(void) display_ui32matrix_endline(uint32 **m, long i0, long i1, long j0, long j1, char *format, char *name)
    105 /* ----------------------------------------------------------------------------------------------------------------- */
    106 {
    107   int i, j;
    108   int n = (i1-i0+1) * (j1-j0+1);
    109   uint32 *p = &m[i0][j0];
    110 
    111   if(name != NULL) puts(name);
    112 
    113   for(i=i0; i<=i1; i++) {
    114     for(j=j0; j<=j0+n; j++) {
    115       printf(format, *p++);
    116     }
    117     putchar('\n');
    118   }
    119   putchar('\n');
    120 }
    121 /* -------------------------------------------------------------------------------------------------------------- */
    122 IMAGE_EXPORT(void) display_i64matrix_endline(int64 **m,long i0, long i1, long j0, long j1, char *format, char *name)
    123 /* -------------------------------------------------------------------------------------------------------------- */
    124 {
    125   int i, j;
    126   int n = (i1-i0+1) * (j1-j0+1);
    127   int64 *p = &m[i0][j0];
    128 
    129   if(name != NULL) puts(name);
    130 
    131   for(i=i0; i<=i1; i++) {
    132     for(j=j0; j<=j0+n; j++) {
    133       printf(format, *p++);
    134     }
    135     putchar('\n');
    136   }
    137   putchar('\n');
    138 }
    139 /* ---------------------------------------------------------------------------------------------------------- */
    140 IMAGE_EXPORT(void) display_imatrix_endline(int **m,long i0, long i1, long j0, long j1, char *format, char *name)
    141 /* ---------------------------------------------------------------------------------------------------------- */
    142 {
    143   int i, j;
    144   int n = (i1-i0+1) * (j1-j0+1);
    145   int *p = &m[i0][j0];
    146 
    147   if(name != NULL) puts(name);
    148 
    149   for(i=i0; i<=i1; i++) {
    150     for(j=j0; j<=j0+n; j++) {
    151       printf(format, *p++);
    152     }
    153     putchar('\n');
    154   }
    155   putchar('\n');
    156 }
     33
     34#undef display_type_matrix_endline
     35#define display_type_matrix_endline(t) \
     36void short_name(t,display_,matrix_endline)(t ** m, int32_t i0, int32_t i1, int32_t j0, int32_t j1, char * format, char * name) \
     37{                                                \
     38    int32_t n = (i1 - i0 + 1) * (j1 - j0 + 1);   \
     39    t * p = &m[i0][j0];                          \
     40                                                 \
     41    if (name != NULL) {                          \
     42        printf(name);                            \
     43    }                                            \
     44                                                 \
     45    for (int32_t i = i0; i <= i1; i++) {         \
     46        for (int32_t j = j0; j <= j0 + n; j++) { \
     47            printf(format, *p++);                \
     48        }                                        \
     49        printf("\n");                            \
     50    }                                            \
     51    printf("\n");                                \
     52}
     53
     54display_type_matrix_endline(int8_t);
     55display_type_matrix_endline(uint8_t);
     56display_type_matrix_endline(int16_t);
     57display_type_matrix_endline(uint16_t);
     58display_type_matrix_endline(int32_t);
     59display_type_matrix_endline(uint32_t);
     60display_type_matrix_endline(int64_t);
     61display_type_matrix_endline(uint64_t);
     62
     63
    15764/* ------------------------------- */
    15865/* --- display_matrix_endline0 --- */
    15966/* ------------------------------- */
    160 /* ------------------------------------------------------------------------------------------------------------ */
    161 //IMAGE_EXPORT(void) display_bmatrix_endline0(byte **m,long i0, long i1, long j0, long j1, char *format, char *name)
    162 /* ------------------------------------------------------------------------------------------------------------ */
    163 /*{
    164   int i, j, n;
    165 
    166   if(name != NULL) puts(name);
    167 
    168   for(i=i0; i<=i1; i++) {
    169     n = m[i][j0];
    170     for(j=j0; j<=j0+n; j++) {
    171       printf(format, m[i][j]);
    172     }
    173     putchar('\n');
    174   }
    175   putchar('\n');
    176 }*/
    177 /* ----------------------------------------------------------------------------------------- */
    178 IMAGE_EXPORT(void) display_bmatrix_endline0(byte **m,long i0, long i1,char *format, char *name)
    179 /* ----------------------------------------------------------------------------------------- */
    180 {
    181   int i, j, n;
    182 
    183   if(name != NULL) puts(name);
    184 
    185   for(i=i0; i<=i1; i++) {
    186     printf("[%3d] ", i);
    187     n = m[i][0];
    188     for(j=1; j<=+n; j++) {
    189       printf(format, m[i][j]);
    190     }
    191     putchar('\n');
    192   }
    193   putchar('\n');
    194 }
    195 /* --------------------------------------------------------------------------------------------------------------- */
    196 //IMAGE_EXPORT(void) display_i16matrix_endline0(int16 **m,long i0, long i1, long j0, long j1, char *format, char *name)
    197 /* --------------------------------------------------------------------------------------------------------------- */
    198 /*{
    199   int i, j, n;
    200 
    201   if(name != NULL) puts(name);
    202 
    203   for(i=i0; i<=i1; i++) {
    204     n = m[i][j0];
    205     for(j=j0; j<=j0+n; j++) {
    206       printf(format, m[i][j]);
    207     }
    208     putchar('\n');
    209   }
    210   putchar('\n');
    211 }*/
    212 /* --------------------------------------------------------------------------------------------- */
    213 IMAGE_EXPORT(void) display_i16matrix_endline0(int16 **m,long i0, long i1, char *format, char *name)
    214 /* --------------------------------------------------------------------------------------------- */
    215 {
    216   int i, j, n;
    217 
    218   if(name != NULL) puts(name);
    219 
    220   for(i=i0; i<=i1; i++) {
    221     printf("[%3d] ", i);
    222     n = m[i][0];
    223     for(j=1; j<=+n; j++) {
    224       printf(format, m[i][j]);
    225     }
    226     putchar('\n');
    227   }
    228   putchar('\n');
    229 }
    230 /* ---------------------------------------------------------------------------------------------------------------- */
    231 //IMAGE_EXPORT(void) display_ui16matrix_endline0(uint16 **m,long i0, long i1, long j0, long j1, char *format, char *name)
    232 /* ---------------------------------------------------------------------------------------------------------------- */
    233 /*{
    234   int i, j, n;
    235 
    236   if(name != NULL) puts(name);
    237 
    238   for(i=i0; i<=i1; i++) {
    239     n = m[i][j0];
    240     for(j=j0; j<=j0+n; j++) {
    241       printf(format, m[i][j]);
    242     }
    243     putchar('\n');
    244   }
    245   putchar('\n');
    246 }*/
    247 /* ----------------------------------------------------------------------------------------------- */
    248 IMAGE_EXPORT(void) display_ui16matrix_endline0(uint16 **m,long i0, long i1, char *format, char *name)
    249 /* ----------------------------------------------------------------------------------------------- */
    250 {
    251   int i, j, n;
    252 
    253   if(name != NULL) puts(name);
    254 
    255   for(i=i0; i<=i1; i++) {
    256     printf("[%3d] ", i);
    257     n = m[i][0];
    258     for(j=1; j<=+n; j++) {
    259       printf(format, m[i][j]);
    260     }
    261     putchar('\n');
    262   }
    263   putchar('\n');
    264 }
    265 /* --------------------------------------------------------------------------------------------------------------- */
    266 //IMAGE_EXPORT(void) display_i32matrix_endline0(int32 **m,long i0, long i1, long j0, long j1, char *format, char *name)
    267 /* --------------------------------------------------------------------------------------------------------------- */
    268 /*{
    269   int i, j, n;
    270 
    271   if(name != NULL) puts(name);
    272 
    273   for(i=i0; i<=i1; i++) {
    274     n = m[i][j0];
    275     for(j=j0; j<=j0+n; j++) {
    276       printf(format, m[i][j]);
    277     }
    278     putchar('\n');
    279   }
    280   putchar('\n');
    281 }*/
    282 /* --------------------------------------------------------------------------------------------- */
    283 IMAGE_EXPORT(void) display_i32matrix_endline0(int32 **m,long i0, long i1, char *format, char *name)
    284 /* --------------------------------------------------------------------------------------------- */
    285 {
    286   int i, j, n;
    287 
    288   if(name != NULL) puts(name);
    289 
    290   for(i=i0; i<=i1; i++) {
    291     printf("[%3d] ", i);
    292     n = m[i][0];
    293     for(j=1; j<=+n; j++) {
    294       printf(format, m[i][j]);
    295     }
    296     putchar('\n');
    297   }
    298   putchar('\n');
    299 }
    300 /* ---------------------------------------------------------------------------------------------------------------- */
    301 //IMAGE_EXPORT(void) display_ui32matrix_endline0(uint32 **m,long i0, long i1, long j0, long j1, char *format, char *name)
    302 /* ---------------------------------------------------------------------------------------------------------------- */
    303 /*{
    304   int i, j, n;
    305 
    306   if(name != NULL) puts(name);
    307 
    308   for(i=i0; i<=i1; i++) {
    309     n = m[i][j0];
    310     for(j=j0; j<=j0+n; j++) {
    311       printf(format, m[i][j]);
    312     }
    313     putchar('\n');
    314   }
    315   putchar('\n');
    316 }*/
    317 /* ----------------------------------------------------------------------------------------------- */
    318 IMAGE_EXPORT(void) display_ui32matrix_endline0(uint32 **m,long i0, long i1, char *format, char *name)
    319 /* ----------------------------------------------------------------------------------------------- */
    320 {
    321   int i, j, n;
    322 
    323   if(name != NULL) puts(name);
    324 
    325   for(i=i0; i<=i1; i++) {
    326     printf("[%3d] ", i);
    327     n = m[i][0];
    328     for(j=1; j<=+n; j++) {
    329       printf(format, m[i][j]);
    330     }
    331     putchar('\n');
    332   }
    333   putchar('\n');
    334 }
    335 /* --------------------------------------------------------------------------------------------- */
    336 IMAGE_EXPORT(void) display_i64matrix_endline0(int64 **m,long i0, long i1, char *format, char *name)
    337 /* --------------------------------------------------------------------------------------------- */
    338 {
    339   int i, j;
    340   int64 n;
    341 
    342   if(name != NULL) puts(name);
    343 
    344   for(i=i0; i<=i1; i++) {
    345     printf("[%3d] ", i);
    346     n = m[i][0];
    347     for(j=1; j<=+n; j++) {
    348       printf(format, m[i][j]);
    349     }
    350     putchar('\n');
    351   }
    352   putchar('\n');
    353 }
    354 /* ----------------------------------------------------------------------------------------------------------- */
    355 //IMAGE_EXPORT(void) display_imatrix_endline0(int **m,long i0, long i1, long j0, long j1, char *format, char *name)
    356 /* ----------------------------------------------------------------------------------------------------------- */
    357 /*{
    358   int i, j, n;
    359 
    360   if(name != NULL) puts(name);
    361 
    362   for(i=i0; i<=i1; i++) {
    363     n = m[i][j0];
    364     for(j=j0; j<=j0+n; j++) {
    365       printf(format, m[i][j]);
    366     }
    367     putchar('\n');
    368   }
    369   putchar('\n');
    370 }*/
    371 /* ----------------------------------------------------------------------------------------- */
    372 IMAGE_EXPORT(void) display_imatrix_endline0(int **m,long i0, long i1, char *format, char *name)
    373 /* ----------------------------------------------------------------------------------------- */
    374 {
    375   int i, j, n;
    376 
    377   if(name != NULL) puts(name);
    378 
    379   for(i=i0; i<=i1; i++) {
    380     printf("[%3d] ", i);
    381     n = m[i][0];
    382     for(j=1; j<=+n; j++) {
    383       printf(format, m[i][j]);
    384     }
    385     putchar('\n');
    386   }
    387   putchar('\n');
    388 }
     67
     68#undef display_type_matrix_endline0
     69#define display_type_matrix_endline0(t) \
     70void short_name(t,display_,matrix_endline0)(t ** m, int32_t i0, int32_t i1, int32_t j0, int32_t j1, char * format, char * name) \
     71{                                                \
     72    if (name != NULL) {                          \
     73        printf(name);                            \
     74    }                                            \
     75                                                 \
     76    for (int32_t i = i0; i <= i1; i++) {         \
     77        int32_t n = (int32_t) m[i][j0];          \
     78        for (int32_t j = j0; j <= j0 + n; j++) { \
     79            printf(format, m[i][j]);             \
     80        }                                        \
     81        printf("\n");                            \
     82    }                                            \
     83    printf("\n");                                \
     84}
     85
     86display_type_matrix_endline0(int8_t);
     87display_type_matrix_endline0(uint8_t);
     88display_type_matrix_endline0(int16_t);
     89display_type_matrix_endline0(uint16_t);
     90display_type_matrix_endline0(int32_t);
     91display_type_matrix_endline0(uint32_t);
     92display_type_matrix_endline0(int64_t);
     93display_type_matrix_endline0(uint64_t);
     94
     95
    38996/* ------------------------------- */
    39097/* --- display_matrix_endline1 --- */
    39198/* ------------------------------- */
    392 /* ------------------------------------------------------------------------------------------------------------ */
    393 IMAGE_EXPORT(void) display_bmatrix_endline1(byte **m,long i0, long i1, long j0, long j1, char *format, char *name)
    394 /* ------------------------------------------------------------------------------------------------------------ */
    395 {
    396   int i, j, n;
    397 
    398   if(name != NULL) puts(name);
    399 
    400   for(i=i0; i<=i1; i++) {
    401     n = m[i][j0-1];
    402     for(j=j0; j<=j0+n-1; j++) {
    403       printf(format, m[i][j]);
    404     }
    405     putchar('\n');
    406   }
    407   putchar('\n');
    408 }
    409 /* --------------------------------------------------------------------------------------------------------------- */
    410 IMAGE_EXPORT(void) display_i16matrix_endline1(int16 **m,long i0, long i1, long j0, long j1, char *format, char *name)
    411 /* --------------------------------------------------------------------------------------------------------------- */
    412 {
    413   int i, j, n;
    414 
    415   if(name != NULL) puts(name);
    416 
    417   for(i=i0; i<=i1; i++) {
    418     n = m[i][j0-1];
    419     for(j=j0; j<=j0+n-1; j++) {
    420       printf(format, m[i][j]);
    421     }
    422     putchar('\n');
    423   }
    424   putchar('\n');
    425 }
    426 /* ----------------------------------------------------------------------------------------------------------------- */
    427 IMAGE_EXPORT(void) display_ui16matrix_endline1(uint16 **m,long i0, long i1, long j0, long j1, char *format, char *name)
    428 /* ----------------------------------------------------------------------------------------------------------------- */
    429 {
    430   int i, j, n;
    431 
    432   if(name != NULL) puts(name);
    433 
    434   for(i=i0; i<=i1; i++) {
    435     n = m[i][j0-1];
    436     for(j=j0; j<=j0+n-1; j++) {
    437       printf(format, m[i][j]);
    438     }
    439     putchar('\n');
    440   }
    441   putchar('\n');
    442 }
    443 /* --------------------------------------------------------------------------------------------------------------- */
    444 IMAGE_EXPORT(void) display_i32matrix_endline1(int32 **m,long i0, long i1, long j0, long j1, char *format, char *name)
    445 /* --------------------------------------------------------------------------------------------------------------- */
    446 {
    447   int i, j, n;
    448 
    449   if(name != NULL) puts(name);
    450 
    451   for(i=i0; i<=i1; i++) {
    452     n = m[i][j0-1];
    453     for(j=j0; j<=j0+n-1; j++) {
    454       printf(format, m[i][j]);
    455     }
    456     putchar('\n');
    457   }
    458   putchar('\n');
    459 }
    460 /* ----------------------------------------------------------------------------------------------------------------- */
    461 IMAGE_EXPORT(void) display_ui32matrix_endline1(uint32 **m,long i0, long i1, long j0, long j1, char *format, char *name)
    462 /* ----------------------------------------------------------------------------------------------------------------- */
    463 {
    464   int i, j, n;
    465 
    466   if(name != NULL) puts(name);
    467 
    468   for(i=i0; i<=i1; i++) {
    469     n = m[i][j0-1];
    470     for(j=j0; j<=j0+n-1; j++) {
    471       printf(format, m[i][j]);
    472     }
    473     putchar('\n');
    474   }
    475   putchar('\n');
    476 }
    477 /* --------------------------------------------------------------------------------------------------------------- */
    478 IMAGE_EXPORT(void) display_i64matrix_endline1(int64 **m,long i0, long i1, long j0, long j1, char *format, char *name)
    479 /* --------------------------------------------------------------------------------------------------------------- */
    480 {
    481   int i, j;
    482   int64 n;
    483 
    484   if(name != NULL) puts(name);
    485 
    486   for(i=i0; i<=i1; i++) {
    487     n = m[i][j0-1];
    488     for(j=j0; j<=j0+n-1; j++) {
    489       printf(format, m[i][j]);
    490     }
    491     putchar('\n');
    492   }
    493   putchar('\n');
    494 }
    495 /* ----------------------------------------------------------------------------------------------------------- */
    496 IMAGE_EXPORT(void) display_imatrix_endline1(int **m,long i0, long i1, long j0, long j1, char *format, char *name)
    497 /* ----------------------------------------------------------------------------------------------------------- */
    498 {
    499   int i, j, n;
    500 
    501   if(name != NULL) puts(name);
    502 
    503   for(i=i0; i<=i1; i++) {
    504     n = m[i][j0-1];
    505     for(j=j0; j<=j0+n-1; j++) {
    506       printf(format, m[i][j]);
    507     }
    508     putchar('\n');
    509   }
    510   putchar('\n');
    511 }
     99
     100#undef display_type_matrix_endline1
     101#define display_type_matrix_endline1(t) \
     102void short_name(t,display_,matrix_endline1)(t ** m, int32_t i0, int32_t i1, int32_t j0, int32_t j1, char * format, char * name) \
     103{                                                    \
     104    if (name != NULL) {                              \
     105        printf(name);                                \
     106    }                                                \
     107                                                     \
     108    for (int32_t i = i0; i <= i1; i++) {             \
     109        int32_t n = (int32_t) m[i][j0 - 1];          \
     110        for (int32_t j = j0; j <= j0 + n - 1; j++) { \
     111            printf(format, m[i][j]);                 \
     112        }                                            \
     113        printf("\n");                                \
     114    }                                                \
     115    printf("\n");                                    \
     116}
     117
     118display_type_matrix_endline1(int8_t);
     119display_type_matrix_endline1(uint8_t);
     120display_type_matrix_endline1(int16_t);
     121display_type_matrix_endline1(uint16_t);
     122display_type_matrix_endline1(int32_t);
     123display_type_matrix_endline1(uint32_t);
     124display_type_matrix_endline1(int64_t);
     125display_type_matrix_endline1(uint64_t);
     126
     127
    512128/* -------------------------------------- */
    513129/* --- display_matrix_number_endline0 --- */
    514130/* -------------------------------------- */
    515 /* ------------------------------------------------------------------------------------------------------------------- */
    516 IMAGE_EXPORT(void) display_bmatrix_number_endline0(byte **m,long i0, long i1, long j0, long j1, char *format, char *name)
    517 /* ------------------------------------------------------------------------------------------------------------------- */
    518 {
    519   int i, j, n;
    520 
    521   if(name != NULL) puts(name);
    522 
    523   for(i=i0; i<=i1; i++) {
    524     printf("[%3d]", i);
    525     n = m[i][j0];
    526     for(j=j0; j<=j0+n; j++) {
    527       printf(format, m[i][j]);
    528     }
    529     putchar('\n');
    530   }
    531   putchar('\n');
    532 }
    533 /* ---------------------------------------------------------------------------------------------------------------------- */
    534 IMAGE_EXPORT(void) display_i16matrix_number_endline0(int16 **m,long i0, long i1, long j0, long j1, char *format, char *name)
    535 /* ---------------------------------------------------------------------------------------------------------------------- */
    536 {
    537   int i, j, n;
    538 
    539   if(name != NULL) puts(name);
    540 
    541   for(i=i0; i<=i1; i++) {
    542     printf("[%3d]", i);
    543     n = m[i][j0];
    544     for(j=j0; j<=j0+n; j++) {
    545       printf(format, m[i][j]);
    546     }
    547     putchar('\n');
    548   }
    549   putchar('\n');
    550 }
    551 /* ------------------------------------------------------------------------------------------------------------------------ */
    552 IMAGE_EXPORT(void) display_ui16matrix_number_endline0(uint16 **m,long i0, long i1, long j0, long j1, char *format, char *name)
    553 /* ------------------------------------------------------------------------------------------------------------------------ */
    554 {
    555   int i, j, n;
    556 
    557   if(name != NULL) puts(name);
    558 
    559   for(i=i0; i<=i1; i++) {
    560     printf("[%3d]", i);
    561     n = m[i][j0];
    562     for(j=j0; j<=j0+n; j++) {
    563       printf(format, m[i][j]);
    564     }
    565     putchar('\n');
    566   }
    567   putchar('\n');
    568 }
    569 /* ---------------------------------------------------------------------------------------------------------------------- */
    570 IMAGE_EXPORT(void) display_i32matrix_number_endline0(int32 **m,long i0, long i1, long j0, long j1, char *format, char *name)
    571 /* ---------------------------------------------------------------------------------------------------------------------- */
    572 {
    573   int i, j, n;
    574 
    575   if(name != NULL) puts(name);
    576 
    577   for(i=i0; i<=i1; i++) {
    578     printf("[%3d]", i);
    579     n = m[i][j0];
    580     for(j=j0; j<=j0+n; j++) {
    581       printf(format, m[i][j]);
    582     }
    583     putchar('\n');
    584   }
    585   putchar('\n');
    586 }
    587 /* ------------------------------------------------------------------------------------------------------------------------ */
    588 IMAGE_EXPORT(void) display_ui32matrix_number_endline0(uint32 **m,long i0, long i1, long j0, long j1, char *format, char *name)
    589 /* ------------------------------------------------------------------------------------------------------------------------ */
    590 {
    591   int i, j, n;
    592 
    593   if(name != NULL) puts(name);
    594 
    595   for(i=i0; i<=i1; i++) {
    596     printf("[%3d]", i);
    597     n = m[i][j0];
    598     for(j=j0; j<=j0+n; j++) {
    599       printf(format, m[i][j]);
    600     }
    601     putchar('\n');
    602   }
    603   putchar('\n');
    604 }
    605 /* ---------------------------------------------------------------------------------------------------------------------- */
    606 IMAGE_EXPORT(void) display_i64matrix_number_endline0(int64 **m,long i0, long i1, long j0, long j1, char *format, char *name)
    607 /* ---------------------------------------------------------------------------------------------------------------------- */
    608 {
    609   int i, j;
    610   int64 n;
    611 
    612   if(name != NULL) puts(name);
    613 
    614   for(i=i0; i<=i1; i++) {
    615     printf("[%3d]", i);
    616     n = m[i][j0];
    617     for(j=j0; j<=j0+n; j++) {
    618       printf(format, m[i][j]);
    619     }
    620     putchar('\n');
    621   }
    622   putchar('\n');
    623 }
    624 /* ------------------------------------------------------------------------------------------------------------------ */
    625 IMAGE_EXPORT(void) display_imatrix_number_endline0(int **m,long i0, long i1, long j0, long j1, char *format, char *name)
    626 /* ------------------------------------------------------------------------------------------------------------------ */
    627 {
    628   int i, j, n;
    629 
    630   if(name != NULL) puts(name);
    631 
    632   for(i=i0; i<=i1; i++) {
    633     printf("[%3d]", i);
    634     n = m[i][j0];
    635     for(j=j0; j<=j0+n; j++) {
    636       printf(format, m[i][j]);
    637     }
    638     putchar('\n');
    639   }
    640   putchar('\n');
    641 }
     131
     132#undef display_type_matrix_number_endline0
     133#define display_type_matrix_number_endline0(t) \
     134void short_name(t,display_,matrix_number_endline0)(t ** m, int32_t i0, int32_t i1, int32_t j0, int32_t j1, char * format, char * name) \
     135{                                                    \
     136    if (name != NULL) {                              \
     137        printf(name);                                \
     138    }                                                \
     139                                                     \
     140    for (int32_t i = i0; i <= i1; i++) {             \
     141        printf("[%3d] ", i);                         \
     142        int32_t n = (int32_t) m[i][j0];              \
     143        for (int32_t j = j0; j <= j0 + n; j++) {     \
     144            printf(format, m[i][j]);                 \
     145        }                                            \
     146        printf("\n");                                \
     147    }                                                \
     148    printf("\n");                                    \
     149}
     150
     151display_type_matrix_number_endline0(int8_t);
     152display_type_matrix_number_endline0(uint8_t);
     153display_type_matrix_number_endline0(int16_t);
     154display_type_matrix_number_endline0(uint16_t);
     155display_type_matrix_number_endline0(int32_t);
     156display_type_matrix_number_endline0(uint32_t);
     157display_type_matrix_number_endline0(int64_t);
     158display_type_matrix_number_endline0(uint64_t);
     159
     160
    642161/* -------------------------------------- */
    643162/* --- display_matrix_number_endline1 --- */
    644163/* -------------------------------------- */
    645 /* ------------------------------------------------------------------------------------------------------------------- */
    646 IMAGE_EXPORT(void) display_bmatrix_number_endline1(byte **m,long i0, long i1, long j0, long j1, char *format, char *name)
    647 /* ------------------------------------------------------------------------------------------------------------------- */
    648 {
    649   int i, j, n;
    650 
    651   if(name != NULL) puts(name);
    652 
    653   for(i=i0; i<=i1; i++) {
    654     printf("[%3d]", i);
    655     n = m[i][j0-1];
    656     for(j=j0; j<=j0+n-1; j++) {
    657       printf(format, m[i][j]);
    658     }
    659     putchar('\n');
    660   }
    661   putchar('\n');
    662 }
    663 /* ---------------------------------------------------------------------------------------------------------------------- */
    664 IMAGE_EXPORT(void) display_i16matrix_number_endline1(int16 **m,long i0, long i1, long j0, long j1, char *format, char *name)
    665 /* ---------------------------------------------------------------------------------------------------------------------- */
    666 {
    667   int i, j, n;
    668 
    669   if(name != NULL) puts(name);
    670 
    671   for(i=i0; i<=i1; i++) {
    672     printf("[%3d]", i);
    673     n = m[i][j0-1];
    674     for(j=j0; j<=j0+n-1; j++) {
    675       printf(format, m[i][j]);
    676     }
    677     putchar('\n');
    678   }
    679   putchar('\n');
    680 }
    681 /* ------------------------------------------------------------------------------------------------------------------------ */
    682 IMAGE_EXPORT(void) display_ui16matrix_number_endline1(uint16 **m,long i0, long i1, long j0, long j1, char *format, char *name)
    683 /* ------------------------------------------------------------------------------------------------------------------------ */
    684 {
    685   int i, j, n;
    686 
    687   if(name != NULL) puts(name);
    688 
    689   for(i=i0; i<=i1; i++) {
    690     printf("[%3d]", i);
    691     n = m[i][j0-1];
    692     for(j=j0; j<=j0+n-1; j++) {
    693       printf(format, m[i][j]);
    694     }
    695     putchar('\n');
    696   }
    697   putchar('\n');
    698 }
    699 /* ---------------------------------------------------------------------------------------------------------------------- */
    700 IMAGE_EXPORT(void) display_i32matrix_number_endline1(int32 **m,long i0, long i1, long j0, long j1, char *format, char *name)
    701 /* ---------------------------------------------------------------------------------------------------------------------- */
    702 {
    703   int i, j, n;
    704 
    705   if(name != NULL) puts(name);
    706 
    707   for(i=i0; i<=i1; i++) {
    708     printf("[%3d]", i);
    709     n = m[i][j0-1];
    710     for(j=j0; j<=j0+n-1; j++) {
    711       printf(format, m[i][j]);
    712     }
    713     putchar('\n');
    714   }
    715   putchar('\n');
    716 }
    717 /* ------------------------------------------------------------------------------------------------------------------------ */
    718 IMAGE_EXPORT(void) display_ui32matrix_number_endline1(uint32 **m,long i0, long i1, long j0, long j1, char *format, char *name)
    719 /* ------------------------------------------------------------------------------------------------------------------------ */
    720 {
    721   int i, j, n;
    722 
    723   if(name != NULL) puts(name);
    724 
    725   for(i=i0; i<=i1; i++) {
    726     printf("[%3d]", i);
    727     n = m[i][j0-1];
    728     for(j=j0; j<=j0+n-1; j++) {
    729       printf(format, m[i][j]);
    730     }
    731     putchar('\n');
    732   }
    733   putchar('\n');
    734 }
    735 /* ---------------------------------------------------------------------------------------------------------------------- */
    736 IMAGE_EXPORT(void) display_i64matrix_number_endline1(int64 **m,long i0, long i1, long j0, long j1, char *format, char *name)
    737 /* ---------------------------------------------------------------------------------------------------------------------- */
    738 {
    739   int i, j;
    740   int64 n;
    741 
    742   if(name != NULL) puts(name);
    743 
    744   for(i=i0; i<=i1; i++) {
    745     printf("[%3d]", i);
    746     n = m[i][j0-1];
    747     for(j=j0; j<=j0+n-1; j++) {
    748       printf(format, m[i][j]);
    749     }
    750     putchar('\n');
    751   }
    752   putchar('\n');
    753 }
    754 /* ------------------------------------------------------------------------------------------------------------------ */
    755 IMAGE_EXPORT(void) display_imatrix_number_endline1(int **m,long i0, long i1, long j0, long j1, char *format, char *name)
    756 /* ------------------------------------------------------------------------------------------------------------------ */
    757 {
    758   int i, j, n;
    759 
    760   if(name != NULL) puts(name);
    761 
    762   for(i=i0; i<=i1; i++) {
    763     printf("[%3d]", i);
    764     n = m[i][j0-1];
    765     for(j=j0; j<=j0+n-1; j++) {
    766       printf(format, m[i][j]);
    767     }
    768     putchar('\n');
    769   }
    770   putchar('\n');
    771 }
     164
     165#undef display_type_matrix_number_endline1
     166#define display_type_matrix_number_endline1(t) \
     167void short_name(t,display_,matrix_number_endline1)(t ** m, int32_t i0, int32_t i1, int32_t j0, int32_t j1, char * format, char * name) \
     168{                                                    \
     169    if (name != NULL) {                              \
     170        printf(name);                                \
     171    }                                                \
     172                                                     \
     173    for (int32_t i = i0; i <= i1; i++) {             \
     174        printf("[%3d] ", i);                         \
     175        int32_t n = (int32_t) m[i][j0 - 1];          \
     176        for (int32_t j = j0; j <= j0 + n - 1; j++) { \
     177            printf(format, m[i][j]);                 \
     178        }                                            \
     179        printf("\n");                                \
     180    }                                                \
     181    printf("\n");                                    \
     182}
     183
     184display_type_matrix_number_endline1(int8_t);
     185display_type_matrix_number_endline1(uint8_t);
     186display_type_matrix_number_endline1(int16_t);
     187display_type_matrix_number_endline1(uint16_t);
     188display_type_matrix_number_endline1(int32_t);
     189display_type_matrix_number_endline1(uint32_t);
     190display_type_matrix_number_endline1(int64_t);
     191display_type_matrix_number_endline1(uint64_t);
     192
     193
    772194/* ------------------------- */
    773195/* --- display_trimatrix --- */
    774196/* ------------------------- */
    775 /* ------------------------------------------------------------------------------------------------------------------ */
    776 IMAGE_EXPORT(void) display_btrimatrix(byte **m, long i0, long i1, long j0, long j1, long step, char *format, char *name)
    777 /* ------------------------------------------------------------------------------------------------------------------ */
    778 {
    779   int i, j;
    780   if(name != NULL) puts(name);
    781 
    782   for(i=i0; i<=i1; i++) {
    783     for(j=j0; j<=j1; j++) {
    784       printf(format, m[i][j]);
    785     }
    786     putchar('\n');
    787     j1 += step;
    788   }
    789   putchar('\n');
    790 }
    791 /* --------------------------------------------------------------------------------------------------------------------- */
    792 IMAGE_EXPORT(void) display_i16trimatrix(int16 **m, long i0, long i1, long j0, long j1, long step, char *format, char *name)
    793 /* --------------------------------------------------------------------------------------------------------------------- */
    794 {
    795   int i, j;
    796 
    797   if(name != NULL) puts(name);
    798 
    799   for(i=i0; i<=i1; i++) {
    800     for(j=j0; j<=j1; j++) {
    801       printf(format, m[i][j]);
    802     }
    803     putchar('\n');
    804     j1 += step;
    805   }
    806   putchar('\n');
    807 }
    808 /* ----------------------------------------------------------------------------------------------------------------------- */
    809 IMAGE_EXPORT(void) display_ui16trimatrix(uint16 **m, long i0, long i1, long j0, long j1, long step, char *format, char *name)
    810 /* ----------------------------------------------------------------------------------------------------------------------- */
    811 {
    812   int i, j;
    813 
    814   if(name != NULL) puts(name);
    815 
    816   for(i=i0; i<=i1; i++) {
    817     for(j=j0; j<=j1; j++) {
    818       printf(format, m[i][j]);
    819     }
    820     putchar('\n');
    821     j1 += step;
    822   }
    823   putchar('\n');
    824 }
    825 /* ----------------------------------------------------------------------------------------------------------------- */
    826 IMAGE_EXPORT(void) display_itrimatrix(int **m, long i0, long i1, long j0, long j1, long step, char *format, char *name)
    827 /* ----------------------------------------------------------------------------------------------------------------- */
    828 {
    829   int i, j;
    830 
    831   if(name != NULL) puts(name);
    832 
    833   for(i=i0; i<=i1; i++) {
    834     for(j=j0; j<=j1; j++) {
    835       printf(format, m[i][j]);
    836     }
    837     putchar('\n');
    838     j1 += step;
    839   }
    840   putchar('\n');
    841 }
    842 /* --------------------------------------------------------------------------------------------------------------------- */
    843 IMAGE_EXPORT(void) display_i32trimatrix(int32 **m, long i0, long i1, long j0, long j1, long step, char *format, char *name)
    844 /* --------------------------------------------------------------------------------------------------------------------- */
    845 {
    846   int i, j;
    847 
    848   if(name != NULL) puts(name);
    849 
    850   for(i=i0; i<=i1; i++) {
    851     for(j=j0; j<=j1; j++) {
    852       printf(format, m[i][j]);
    853     }
    854     putchar('\n');
    855     j1 += step;
    856   }
    857   putchar('\n');
    858 }
    859 /* ------------------------------------------------------------------------------------------------------------------ */
    860 IMAGE_EXPORT(void) display_f32trimatrix(float32 **m, long i0, long i1, long j0, long j1, long step, char *format, char *name)
    861 /* ------------------------------------------------------------------------------------------------------------------ */
    862 {
    863   int i, j;
    864 
    865   if(name != NULL) puts(name);
    866 
    867   for(i=i0; i<=i1; i++) {
    868     for(j=j0; j<=j1; j++) {
    869       printf(format, m[i][j]);
    870     }
    871     putchar('\n');
    872     j1 += step;
    873   }
    874   putchar('\n');
    875 }
    876 /* ------------------------------------------------------------------------------------------------------------------ */
    877 IMAGE_EXPORT(void) display_f64trimatrix(float64 **m, long i0, long i1, long j0, long j1, long step, char *format, char *name)
    878 /* ------------------------------------------------------------------------------------------------------------------ */
    879 {
    880   int i, j;
    881 
    882   if(name != NULL) puts(name);
    883 
    884   for(i=i0; i<=i1; i++) {
    885     for(j=j0; j<=j1; j++) {
    886       printf(format, m[i][j]);
    887     }
    888     putchar('\n');
    889     j1 += step;
    890   }
    891   putchar('\n');
    892 }
     197
     198#undef display_type_trimatrix
     199#define display_type_trimatrix(t) \
     200void short_name(t,display_,trimatrix)(t ** m, int32_t i0, int32_t i1, int32_t j0, int32_t j1, int32_t step, char * format, char * name) \
     201{                                                    \
     202    if (name != NULL) {                              \
     203        printf(name);                                \
     204    }                                                \
     205                                                     \
     206    for (int32_t i = i0; i <= i1; i++) {             \
     207        for (int32_t j = j0; j <= j1; j++) {         \
     208            printf(format, m[i][j]);                 \
     209        }                                            \
     210        printf("\n");                                \
     211        j1 += step;                                  \
     212    }                                                \
     213    printf("\n");                                    \
     214}
     215
     216display_type_trimatrix(int8_t);
     217display_type_trimatrix(uint8_t);
     218display_type_trimatrix(int16_t);
     219display_type_trimatrix(uint16_t);
     220display_type_trimatrix(int32_t);
     221display_type_trimatrix(uint32_t);
     222display_type_trimatrix(int64_t);
     223display_type_trimatrix(uint64_t);
     224display_type_trimatrix(float);
     225display_type_trimatrix(double);
     226
     227
     228// Local Variables:
     229// tab-width: 4
     230// c-basic-offset: 4
     231// c-file-offsets:((innamespace . 0)(inline-open . 0))
     232// indent-tabs-mode: nil
     233// End:
     234
     235// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4
     236
  • soft/giet_vm/applications/rosenfeld/nrc2/src/nrio2xf.c

    r772 r823  
    2525#include "nrio2x.h"
    2626
    27 /* ------------------------------ */
    28 /* --- display_matrix_endline --- */
    29 /* ------------------------------ */
    3027/* ----------------------- */
    3128/* --- write_trimatrix --- */
    3229/* ----------------------- */
    3330
    34 /* ----------------------------------------------------------------------------------------------------------------- */
    35 IMAGE_EXPORT(void) write_btrimatrix(byte **m,long i0,long i1,long j0, long j1, long step, char *format, char *filename)
    36 /* ----------------------------------------------------------------------------------------------------------------- */
    37 {
    38   int i,j;
    39  
    40   FILE *f;
    41 
    42   f = fopen(filename, "wt");
    43   if(f == NULL) {
    44     nrerror("Can't open file in write_btrimatrix");
    45   }
    46 
    47   for(i=i0; i<=i1; i++) {
    48     for(j=j0; j<=j1; j++) {
    49       fprintf(f, format, m[i][j]);
    50     }
    51     fputc('\n', f);
    52     j1 += step;
    53   }
    54   fputc('\n', f);
    55 
    56   fclose(f);
    57 }
    58 
    59 /* -------------------------------------------------------------------------------------------------------------------- */
    60 IMAGE_EXPORT(void) write_i16trimatrix(int16 **m,long i0,long i1,long j0, long j1, long step, char *format, char *filename)
    61 /* -------------------------------------------------------------------------------------------------------------------- */
    62 {
    63   int i,j;
    64  
    65   FILE *f;
    66 
    67   f = fopen(filename, "wt");
    68   if(f == NULL) {
    69     nrerror("Can't open file in write_i16trimatrix");
    70   }
    71 
    72   for(i=i0; i<=i1; i++) {
    73     for(j=j0; j<=j1; j++) {
    74       fprintf(f, format, m[i][j]);
    75     }
    76     fputc('\n', f);
    77     j1 += step;
    78   }
    79   fputc('\n', f);
    80 
    81   fclose(f);
    82 }
    83 /* ---------------------------------------------------------------------------------------------------------------------- */
    84 IMAGE_EXPORT(void) write_ui16trimatrix(uint16 **m,long i0,long i1,long j0, long j1, long step, char *format, char *filename)
    85 /* ---------------------------------------------------------------------------------------------------------------------- */
    86 {
    87   int i,j;
    88  
    89   FILE *f;
    90 
    91   f = fopen(filename, "wt");
    92   if(f == NULL) {
    93     nrerror("Can't open file in write_ui16trimatrix");
    94   }
    95 
    96   for(i=i0; i<=i1; i++) {
    97     for(j=j0; j<=j1; j++) {
    98       fprintf(f, format, m[i][j]);
    99     }
    100     fputc('\n', f);
    101     j1 += step;
    102   }
    103   fputc('\n', f);
    104 
    105   fclose(f);
    106 }
    107 /* ---------------------------------------------------------------------------------------------------------------- */
    108 IMAGE_EXPORT(void) write_itrimatrix(int **m,long i0,long i1,long j0, long j1, long step, char *format, char *filename)
    109 /* ---------------------------------------------------------------------------------------------------------------- */
    110 {
    111   int i,j;
    112  
    113   FILE *f;
    114 
    115   f = fopen(filename, "wt");
    116   if(f == NULL) {
    117     nrerror("Can't open file in write_itrimatrix");
    118   }
    119 
    120   for(i=i0; i<=i1; i++) {
    121     for(j=j0; j<=j1; j++) {
    122       fprintf(f, format, m[i][j]);
    123     }
    124     fputc('\n', f);
    125     j1 += step;
    126   }
    127   fputc('\n', f);
    128 
    129   fclose(f);
    130 }
    131 /* ------------------------------------------------------------------------------------------------------------------------ */
    132 IMAGE_EXPORT(void) write_i32trimatrix(int32 **m,long i0,long i1,long j0, long j1, long step, char *format, char *filename)
    133 /* ------------------------------------------------------------------------------------------------------------------------ */
    134 {
    135   int i,j;
    136  
    137   FILE *f;
    138 
    139   f = fopen(filename, "wt");
    140   if(f == NULL) {
    141     nrerror("Can't open file in write_i32trimatrix");
    142   }
    143 
    144   for(i=i0; i<=i1; i++) {
    145     for(j=j0; j<=j1; j++) {
    146       fprintf(f, format, m[i][j]);
    147     }
    148     fputc('\n', f);
    149     j1 += step;
    150   }
    151   fputc('\n', f);
    152 
    153   fclose(f);
    154 }
    155 /* ---------------------------------------------------------------------------------------------------------------------- */
    156 IMAGE_EXPORT(void) write_f32trimatrix(float32 **m,long i0,long i1,long j0, long j1, long step, char *format, char *filename)
    157 /* ---------------------------------------------------------------------------------------------------------------------- */
    158 {
    159   int i,j;
    160  
    161   FILE *f;
    162 
    163   f = fopen(filename, "wt");
    164   if(f == NULL) {
    165     nrerror("Can't open file in write_f32trimatrix");
    166   }
    167 
    168   for(i=i0; i<=i1; i++) {
    169     for(j=j0; j<=j1; j++) {
    170       fprintf(f, format, m[i][j]);
    171     }
    172     fputc('\n', f);
    173     j1 += step;
    174   }
    175   fputc('\n', f);
    176 
    177   fclose(f);
    178 }
    179 /* ---------------------------------------------------------------------------------------------------------------------- */
    180 IMAGE_EXPORT(void) write_f64trimatrix(float64 **m,long i0,long i1,long j0, long j1, long step, char *format, char *filename)
    181 /* ---------------------------------------------------------------------------------------------------------------------- */
    182 {
    183   int i,j;
    184  
    185   FILE *f;
    186 
    187   f = fopen(filename, "wt");
    188   if(f == NULL) {
    189     nrerror("Can't open file in write_f64trimatrix");
    190   }
    191 
    192   for(i=i0; i<=i1; i++) {
    193     for(j=j0; j<=j1; j++) {
    194       fprintf(f, format, m[i][j]);
    195     }
    196     fputc('\n', f);
    197     j1 += step;
    198   }
    199   fputc('\n', f);
    200 
    201   fclose(f);
    202 }
     31#undef write_type_trimatrix
     32#define write_type_trimatrix(t) \
     33void short_name(t,write_,trimatrix)(t ** m, int32_t i0, int32_t i1, int32_t j0, int32_t j1, int32_t step, char * format, char * filename) \
     34{                                                                \
     35    FILE * f = fopen(filename, "wt");                            \
     36    if (f == NULL) {                                             \
     37        nrerror("Can't open file %s in %s", filename, __func__); \
     38    }                                                            \
     39    for (int32_t i = i0; i <= i1; i++) {                         \
     40        for (int32_t j = j0; j <= j1; j++) {                     \
     41            fprintf(f, format, m[i][j]);                         \
     42        }                                                        \
     43        fprintf(f, "\n");                                        \
     44        j1 += step;                                              \
     45    }                                                            \
     46    fprintf(f, "\n");                                            \
     47    fclose(f);                                                   \
     48}
     49
     50write_type_trimatrix(int8_t);
     51write_type_trimatrix(uint8_t);
     52write_type_trimatrix(int16_t);
     53write_type_trimatrix(uint16_t);
     54write_type_trimatrix(int32_t);
     55write_type_trimatrix(uint32_t);
     56write_type_trimatrix(int64_t);
     57write_type_trimatrix(uint64_t);
     58write_type_trimatrix(float);
     59write_type_trimatrix(double);
     60
     61
    20362/* ---------------------------- */
    20463/* --- write_matrix_endline --- */
    20564/* ---------------------------- */
    206 /* ------------------------------------------------------------------------------------------------------------ */
    207 IMAGE_EXPORT(void) write_bmatrix_endline(byte **m,long i0, long i1, long j0, long j1, char *format, char *filename)
    208 /* ------------------------------------------------------------------------------------------------------------ */
    209 {
    210   int i,j;
    211   //int n = (i1-i0+1) * (j1-j0+1);
    212   byte *p = &m[i0][j0];
    213 
    214   FILE *f;
    215 
    216   f = fopen(filename, "wt");
    217   if(f == NULL) {
    218     nrerror("Can't open file in write_bmatrix_endline");
    219   }
    220 
    221   for(i=i0; i<=i1; i++) {
    222     for(j=j0; j<=j1; j++) {
    223       fprintf(f, format, *p++);
    224     }
    225     fputc('\n', f);
    226   }
    227   fclose(f);
    228 }
    229 /* ---------------------------------------------------------------------------------------------------------------- */
    230 IMAGE_EXPORT(void) write_i16matrix_endline(int16 **m,long i0, long i1, long j0, long j1, char *format, char *filename)
    231 /* ---------------------------------------------------------------------------------------------------------------- */
    232 {
    233   int i,j;
    234   //int n = (i1-i0+1) * (j1-j0+1);
    235   int16 *p = &m[i0][j0];
    236 
    237   FILE *f;
    238 
    239   f = fopen(filename, "wt");
    240   if(f == NULL) {
    241     nrerror("Can't open file in write_i16matrix_endline");
    242   }
    243 
    244   for(i=i0; i<=i1; i++) {
    245     for(j=j0; j<=j1; j++) {
    246       fprintf(f, format, *p++);
    247     }
    248     fputc('\n', f);
    249   }
    250   fclose(f);
    251 }
    252 /* ------------------------------------------------------------------------------------------------------------------ */
    253 IMAGE_EXPORT(void) write_ui16matrix_endline(uint16 **m,long i0, long i1, long j0, long j1, char *format, char *filename)
    254 /* ------------------------------------------------------------------------------------------------------------------ */
    255 {
    256   int i,j;
    257   //int n = (i1-i0+1) * (j1-j0+1);
    258   uint16 *p = &m[i0][j0];
    259 
    260   FILE *f;
    261 
    262   f = fopen(filename, "wt");
    263   if(f == NULL) {
    264     nrerror("Can't open file in write_ui16matrix_endline");
    265   }
    266 
    267   for(i=i0; i<=i1; i++) {
    268     for(j=j0; j<=j1; j++) {
    269       fprintf(f, format, *p++);
    270     }
    271     fputc('\n', f);
    272   }
    273   fclose(f);
    274 }
    275 /* ---------------------------------------------------------------------------------------------------------------- */
    276 IMAGE_EXPORT(void) write_i32matrix_endline(int32 **m,long i0, long i1, long j0, long j1, char *format, char *filename)
    277 /* ---------------------------------------------------------------------------------------------------------------- */
    278 {
    279   int i,j;
    280   //int n = (i1-i0+1) * (j1-j0+1);
    281   int32 *p = &m[i0][j0];
    282 
    283   FILE *f;
    284 
    285   f = fopen(filename, "wt");
    286   if(f == NULL) {
    287     nrerror("Can't open file in write_i32matrix_endline");
    288   }
    289 
    290   for(i=i0; i<=i1; i++) {
    291     for(j=j0; j<=j1; j++) {
    292       fprintf(f, format, *p++);
    293     }
    294     fputc('\n', f);
    295   }
    296   fclose(f);
    297 }
    298 /* ------------------------------------------------------------------------------------------------------------------ */
    299 IMAGE_EXPORT(void) write_ui32matrix_endline(uint32 **m,long i0, long i1, long j0, long j1, char *format, char *filename)
    300 /* ------------------------------------------------------------------------------------------------------------------ */
    301 {
    302   int i,j;
    303   //int n = (i1-i0+1) * (j1-j0+1);
    304   uint32 *p = &m[i0][j0];
    305 
    306   FILE *f;
    307 
    308   f = fopen(filename, "wt");
    309   if(f == NULL) {
    310     nrerror("Can't open file in write_ui32matrix_endline");
    311   }
    312 
    313   for(i=i0; i<=i1; i++) {
    314     for(j=j0; j<=j1; j++) {
    315       fprintf(f, format, *p++);
    316     }
    317     fputc('\n', f);
    318   }
    319   fclose(f);
    320 }
    321 /* ---------------------------------------------------------------------------------------------------------------- */
    322 IMAGE_EXPORT(void) write_i64matrix_endline(int64 **m,long i0, long i1, long j0, long j1, char *format, char *filename)
    323 /* ---------------------------------------------------------------------------------------------------------------- */
    324 {
    325   int i,j;
    326   //int n = (i1-i0+1) * (j1-j0+1);
    327   int64 *p = &m[i0][j0];
    328 
    329   FILE *f;
    330 
    331   f = fopen(filename, "wt");
    332   if(f == NULL) {
    333     nrerror("Can't open file in write_i64matrix_endline");
    334   }
    335 
    336   for(i=i0; i<=i1; i++) {
    337     for(j=j0; j<=j1; j++) {
    338       fprintf(f, format, *p++);
    339     }
    340     fputc('\n', f);
    341   }
    342   fclose(f);
    343 }
    344 /* ------------------------------------------------------------------------------------------------------------ */
    345 IMAGE_EXPORT(void) write_imatrix_endline(int **m,long i0, long i1, long j0, long j1, char *format, char *filename)
    346 /* ------------------------------------------------------------------------------------------------------------ */
    347 {
    348   int i,j;
    349   //int n = (i1-i0+1) * (j1-j0+1);
    350   int *p = &m[i0][j0];
    351 
    352   FILE *f;
    353 
    354   f = fopen(filename, "wt");
    355   if(f == NULL) {
    356     nrerror("Can't open file in write_imatrix_endline");
    357   }
    358 
    359   for(i=i0; i<=i1; i++) {
    360     for(j=j0; j<=j1; j++) {
    361       fprintf(f, format, *p++);
    362     }
    363     fputc('\n', f);
    364   }
    365   fclose(f);
    366 }
     65
     66#undef write_type_matrix_endline
     67#define write_type_matrix_endline(t) \
     68void short_name(t,write_,matrix_endline)(t ** m, int32_t i0, int32_t i1, int32_t j0, int32_t j1, char * format, char * filename) \
     69{                                                                \
     70    t * p = &m[i0][j0];                                          \
     71    FILE * f = fopen(filename, "wt");                            \
     72    if (f == NULL) {                                             \
     73        nrerror("Can't open file %s in %s", filename, __func__); \
     74    }                                                            \
     75    for (int32_t i = i0; i <= i1; i++) {                         \
     76        for (int32_t j = j0; j <= j1; j++) {                     \
     77            fprintf(f, format, *p++);                            \
     78        }                                                        \
     79        fprintf(f, "\n");                                        \
     80    }                                                            \
     81    fprintf(f, "\n");                                            \
     82    fclose(f);                                                   \
     83}
     84
     85write_type_matrix_endline(int8_t);
     86write_type_matrix_endline(uint8_t);
     87write_type_matrix_endline(int16_t);
     88write_type_matrix_endline(uint16_t);
     89write_type_matrix_endline(int32_t);
     90write_type_matrix_endline(uint32_t);
     91write_type_matrix_endline(int64_t);
     92write_type_matrix_endline(uint64_t);
     93write_type_matrix_endline(float);
     94write_type_matrix_endline(double);
     95
     96
    36797/* ------------------------------ */
    36898/* --- write_imatrix_endline0 --- */
    36999/* ------------------------------ */
    370 /* -------------------------------------------------------------------------------------------------------------- */
    371 IMAGE_EXPORT(void) write_bmatrix_endline0(byte **m,long i0, long i1, long j0, long j1, char *format, char *filename)
    372 /* -------------------------------------------------------------------------------------------------------------- */
    373 {
    374   int i,j, n;
    375  
    376   FILE *f;
    377 
    378   f = fopen(filename, "wt");
    379   if(f == NULL) {
    380     nrerror("Can't open file in write_bmatrix_endline0");
    381   }
    382 
    383   for(i=i0; i<=i1; i++) {
    384     n = m[i][j0];
    385     for(j=j0; j<=j0+n; j++) {
    386       fprintf(f, format, m[i][j]);
    387     }
    388     fputc('\n', f);
    389   }
    390   fclose(f);
    391 }
    392 /* ----------------------------------------------------------------------------------------------------------------- */
    393 IMAGE_EXPORT(void) write_i16matrix_endline0(int16 **m,long i0, long i1, long j0, long j1, char *format, char *filename)
    394 /* ----------------------------------------------------------------------------------------------------------------- */
    395 {
    396   int i,j, n;
    397  
    398   FILE *f;
    399 
    400   f = fopen(filename, "wt");
    401   if(f == NULL) {
    402     nrerror("Can't open file in write_i16matrix_endline0");
    403   }
    404 
    405   for(i=i0; i<=i1; i++) {
    406     n = m[i][j0];
    407     for(j=j0; j<=j0+n; j++) {
    408       fprintf(f, format, m[i][j]);
    409     }
    410     fputc('\n', f);
    411   }
    412   fclose(f);
    413 }
    414 /* ------------------------------------------------------------------------------------------------------------------- */
    415 IMAGE_EXPORT(void) write_ui16matrix_endline0(uint16 **m,long i0, long i1, long j0, long j1, char *format, char *filename)
    416 /* ------------------------------------------------------------------------------------------------------------------- */
    417 {
    418   int i,j, n;
    419  
    420   FILE *f;
    421 
    422   f = fopen(filename, "wt");
    423   if(f == NULL) {
    424     nrerror("Can't open file in write_ui16matrix_endline0");
    425   }
    426 
    427   for(i=i0; i<=i1; i++) {
    428     n = m[i][j0];
    429     for(j=j0; j<=j0+n; j++) {
    430       fprintf(f, format, m[i][j]);
    431     }
    432     fputc('\n', f);
    433   }
    434   fclose(f);
    435 }
    436 /* ----------------------------------------------------------------------------------------------------------------- */
    437 IMAGE_EXPORT(void) write_i32matrix_endline0(int32 **m,long i0, long i1, long j0, long j1, char *format, char *filename)
    438 /* ----------------------------------------------------------------------------------------------------------------- */
    439 {
    440   int i,j, n;
    441  
    442   FILE *f;
    443 
    444   f = fopen(filename, "wt");
    445   if(f == NULL) {
    446     nrerror("Can't open file in write_i32matrix_endline0");
    447   }
    448 
    449   for(i=i0; i<=i1; i++) {
    450     n = m[i][j0];
    451     for(j=j0; j<=j0+n; j++) {
    452       fprintf(f, format, m[i][j]);
    453     }
    454     fputc('\n', f);
    455   }
    456   fclose(f);
    457 }
    458 /* ----------------------------------------------------------------------------------------------------------------- */
    459 IMAGE_EXPORT(void) write_i64matrix_endline0(int64 **m,long i0, long i1, long j0, long j1, char *format, char *filename)
    460 /* ----------------------------------------------------------------------------------------------------------------- */
    461 {
    462   int i,j;
    463   int64 n;
    464  
    465   FILE *f;
    466 
    467   f = fopen(filename, "wt");
    468   if(f == NULL) {
    469     nrerror("Can't open file in write_i64matrix_endline0");
    470   }
    471 
    472   for(i=i0; i<=i1; i++) {
    473     n = m[i][j0];
    474     for(j=j0; j<=j0+n; j++) {
    475       fprintf(f, format, m[i][j]);
    476     }
    477     fputc('\n', f);
    478   }
    479   fclose(f);
    480 }
    481 /* ------------------------------------------------------------------------------------------------------------------- */
    482 IMAGE_EXPORT(void) write_ui32matrix_endline0(uint32 **m,long i0, long i1, long j0, long j1, char *format, char *filename)
    483 /* ------------------------------------------------------------------------------------------------------------------- */
    484 {
    485   int i,j, n;
    486  
    487   FILE *f;
    488 
    489   f = fopen(filename, "wt");
    490   if(f == NULL) {
    491     nrerror("Can't open file in write_ui32matrix_endline0");
    492   }
    493 
    494   for(i=i0; i<=i1; i++) {
    495     n = m[i][j0];
    496     for(j=j0; j<=j0+n; j++) {
    497       fprintf(f, format, m[i][j]);
    498     }
    499     fputc('\n', f);
    500   }
    501   fclose(f);
    502 }
    503 /* ------------------------------------------------------------------------------------------------------------- */
    504 IMAGE_EXPORT(void) write_imatrix_endline0(int **m,long i0, long i1, long j0, long j1, char *format, char *filename)
    505 /* ------------------------------------------------------------------------------------------------------------- */
    506 {
    507   int i,j, n;
    508  
    509   FILE *f;
    510 
    511   f = fopen(filename, "wt");
    512   if(f == NULL) {
    513     nrerror("Can't open file in write_imatrix_endline0");
    514   }
    515 
    516   for(i=i0; i<=i1; i++) {
    517     n = m[i][j0];
    518     for(j=j0; j<=j0+n; j++) {
    519       fprintf(f, format, m[i][j]);
    520     }
    521     fputc('\n', f);
    522   }
    523   fclose(f);
    524 }
     100
     101#undef write_type_matrix_endline0
     102#define write_type_matrix_endline0(t) \
     103void short_name(t,write_,matrix_endline0)(t ** m, int32_t i0, int32_t i1, int32_t j0, int32_t j1, char * format, char * filename) \
     104{                                                                \
     105    FILE * f = fopen(filename, "wt");                            \
     106    if (f == NULL) {                                             \
     107        nrerror("Can't open file %s in %s", filename, __func__); \
     108    }                                                            \
     109    for (int32_t i = i0; i <= i1; i++) {                         \
     110        int32_t n = (int32_t) m[i][j0];                          \
     111        for (int32_t j = j0; j <= j0 + n; j++) {                 \
     112            fprintf(f, format, m[i][j]);                         \
     113        }                                                        \
     114        fprintf(f, "\n");                                        \
     115    }                                                            \
     116    fprintf(f, "\n");                                            \
     117    fclose(f);                                                   \
     118}
     119
     120write_type_matrix_endline0(int8_t);
     121write_type_matrix_endline0(uint8_t);
     122write_type_matrix_endline0(int16_t);
     123write_type_matrix_endline0(uint16_t);
     124write_type_matrix_endline0(int32_t);
     125write_type_matrix_endline0(uint32_t);
     126write_type_matrix_endline0(int64_t);
     127write_type_matrix_endline0(uint64_t);
     128write_type_matrix_endline0(float);
     129write_type_matrix_endline0(double);
     130
     131
     132
    525133/* ------------------------------ */
    526134/* --- write_imatrix_endline1 --- */
    527135/* ------------------------------ */
    528 /* -------------------------------------------------------------------------------------------------------------- */
    529 IMAGE_EXPORT(void) write_bmatrix_endline1(byte **m,long i0, long i1, long j0, long j1, char *format, char *filename)
    530 /* -------------------------------------------------------------------------------------------------------------- */
    531 {
    532   int i,j, n;
    533  
    534   FILE *f;
    535 
    536   f = fopen(filename, "wt");
    537   if(f == NULL) {
    538     nrerror("Can't open file in write_bmatrix_endline1");
    539   }
    540 
    541   for(i=i0; i<=i1; i++) {
    542     n = m[i][j0-1];
    543     for(j=j0; j<=j0+n-1; j++) {
    544       fprintf(f, format, m[i][j]);
    545     }
    546     fputc('\n', f);
    547   }
    548   fclose(f);
    549 }
    550 /* ----------------------------------------------------------------------------------------------------------------- */
    551 IMAGE_EXPORT(void) write_i16matrix_endline1(int16 **m,long i0, long i1, long j0, long j1, char *format, char *filename)
    552 /* ----------------------------------------------------------------------------------------------------------------- */
    553 {
    554   int i,j, n;
    555  
    556   FILE *f;
    557 
    558   f = fopen(filename, "wt");
    559   if(f == NULL) {
    560     nrerror("Can't open file in write_i16matrix_endline0");
    561   }
    562 
    563   for(i=i0; i<=i1; i++) {
    564     n = m[i][j0-1];
    565     for(j=j0; j<=j0+n-1; j++) {
    566       fprintf(f, format, m[i][j]);
    567     }
    568     fputc('\n', f);
    569   }
    570   fclose(f);
    571 }
    572 /* ------------------------------------------------------------------------------------------------------------------- */
    573 IMAGE_EXPORT(void) write_ui16matrix_endline1(uint16 **m,long i0, long i1, long j0, long j1, char *format, char *filename)
    574 /* ------------------------------------------------------------------------------------------------------------------- */
    575 {
    576   int i,j, n;
    577  
    578   FILE *f;
    579 
    580   f = fopen(filename, "wt");
    581   if(f == NULL) {
    582     nrerror("Can't open file in write_ui16matrix_endline0");
    583   }
    584 
    585   for(i=i0; i<=i1; i++) {
    586     n = m[i][j0-1];
    587     for(j=j0; j<=j0+n-1; j++) {
    588       fprintf(f, format, m[i][j]);
    589     }
    590     fputc('\n', f);
    591   }
    592   fclose(f);
    593 }
    594 /* ----------------------------------------------------------------------------------------------------------------- */
    595 IMAGE_EXPORT(void) write_i32matrix_endline1(int32 **m,long i0, long i1, long j0, long j1, char *format, char *filename)
    596 /* ----------------------------------------------------------------------------------------------------------------- */
    597 {
    598   int i,j, n;
    599  
    600   FILE *f;
    601 
    602   f = fopen(filename, "wt");
    603   if(f == NULL) {
    604     nrerror("Can't open file in write_i32matrix_endline0");
    605   }
    606 
    607   for(i=i0; i<=i1; i++) {
    608     n = m[i][j0-1];
    609     for(j=j0; j<=j0+n-1; j++) {
    610       fprintf(f, format, m[i][j]);
    611     }
    612     fputc('\n', f);
    613   }
    614   fclose(f);
    615 }
    616 /* ------------------------------------------------------------------------------------------------------------------- */
    617 IMAGE_EXPORT(void) write_ui32matrix_endline1(uint32 **m,long i0, long i1, long j0, long j1, char *format, char *filename)
    618 /* ------------------------------------------------------------------------------------------------------------------- */
    619 {
    620   int i,j, n;
    621  
    622   FILE *f;
    623 
    624   f = fopen(filename, "wt");
    625   if(f == NULL) {
    626     nrerror("Can't open file in write_ui32matrix_endline0");
    627   }
    628 
    629   for(i=i0; i<=i1; i++) {
    630     n = m[i][j0-1];
    631     for(j=j0; j<=j0+n-1; j++) {
    632       fprintf(f, format, m[i][j]);
    633     }
    634     fputc('\n', f);
    635   }
    636   fclose(f);
    637 }
    638 /* ----------------------------------------------------------------------------------------------------------------- */
    639 IMAGE_EXPORT(void) write_i64matrix_endline1(int64 **m,long i0, long i1, long j0, long j1, char *format, char *filename)
    640 /* ----------------------------------------------------------------------------------------------------------------- */
    641 {
    642   int i,j;
    643   int64 n;
    644  
    645   FILE *f;
    646 
    647   f = fopen(filename, "wt");
    648   if(f == NULL) {
    649     nrerror("Can't open file in write_i64matrix_endline0");
    650   }
    651 
    652   for(i=i0; i<=i1; i++) {
    653     n = m[i][j0-1];
    654     for(j=j0; j<=j0+n-1; j++) {
    655       fprintf(f, format, m[i][j]);
    656     }
    657     fputc('\n', f);
    658   }
    659   fclose(f);
    660 }
    661 /* ------------------------------------------------------------------------------------------------------------- */
    662 IMAGE_EXPORT(void) write_imatrix_endline1(int **m,long i0, long i1, long j0, long j1, char *format, char *filename)
    663 /* ------------------------------------------------------------------------------------------------------------- */
    664 {
    665   int i,j, n;
    666  
    667   FILE *f;
    668 
    669   f = fopen(filename, "wt");
    670   if(f == NULL) {
    671     nrerror("Can't open file in write_imatrix_endline0");
    672   }
    673 
    674   for(i=i0; i<=i1; i++) {
    675     n = m[i][j0-1];
    676     for(j=j0; j<=j0+n-1; j++) {
    677       fprintf(f, format, m[i][j]);
    678     }
    679     fputc('\n', f);
    680   }
    681   fclose(f);
    682 }
     136
     137#undef write_type_matrix_endline1
     138#define write_type_matrix_endline1(t) \
     139void short_name(t,write_,matrix_endline1)(t ** m, int32_t i0, int32_t i1, int32_t j0, int32_t j1, char * format, char * filename) \
     140{                                                                \
     141    FILE * f = fopen(filename, "wt");                            \
     142    if (f == NULL) {                                             \
     143        nrerror("Can't open file %s in %s", filename, __func__); \
     144    }                                                            \
     145    for (int32_t i = i0; i <= i1; i++) {                         \
     146        int32_t n = (int32_t) m[i][j0 - 1];                      \
     147        for (int32_t j = j0; j <= j0 + n - 1; j++) {             \
     148            fprintf(f, format, m[i][j]);                         \
     149        }                                                        \
     150        fprintf(f, "\n");                                        \
     151    }                                                            \
     152    fprintf(f, "\n");                                            \
     153    fclose(f);                                                   \
     154}
     155
     156write_type_matrix_endline1(int8_t);
     157write_type_matrix_endline1(uint8_t);
     158write_type_matrix_endline1(int16_t);
     159write_type_matrix_endline1(uint16_t);
     160write_type_matrix_endline1(int32_t);
     161write_type_matrix_endline1(uint32_t);
     162write_type_matrix_endline1(int64_t);
     163write_type_matrix_endline1(uint64_t);
     164write_type_matrix_endline1(float);
     165write_type_matrix_endline1(double);
     166
     167
    683168/* ------------------------------------- */
    684169/* --- write_imatrix_number_endline0 --- */
    685170/* ------------------------------------- */
    686 /* --------------------------------------------------------------------------------------------------------------------- */
    687 IMAGE_EXPORT(void) write_bmatrix_number_endline0(byte **m,long i0, long i1, long j0, long j1, char *format, char *filename)
    688 /* --------------------------------------------------------------------------------------------------------------------- */
    689 {
    690   int i,j, n;
    691  
    692   FILE *f;
    693 
    694   f = fopen(filename, "wt");
    695   if(f == NULL) {
    696     nrerror("Can't open file in write_bmatrix_number_endline0");
    697   }
    698 
    699   for(i=i0; i<=i1; i++) {
    700     fprintf(f, "[%3d] ", i);
    701     n = m[i][j0];
    702     for(j=j0; j<=j0+n; j++) {
    703       fprintf(f, format, m[i][j]);
    704     }
    705     fputc('\n', f);
    706   }
    707   fclose(f);
    708 }
    709 /* ------------------------------------------------------------------------------------------------------------------------- */
    710 IMAGE_EXPORT(void) write_i16matrix_number_endline0(int16 **m,long i0, long i1, long j0, long j1, char *format, char *filename)
    711 /* ------------------------------------------------------------------------------------------------------------------------ */
    712 {
    713   int i,j, n;
    714  
    715   FILE *f;
    716 
    717   f = fopen(filename, "wt");
    718   if(f == NULL) {
    719     nrerror("Can't open file in write_i16matrix_number_endline0");
    720   }
    721 
    722   for(i=i0; i<=i1; i++) {
    723     fprintf(f, "[%3d] ", i);
    724     n = m[i][j0];
    725     for(j=j0; j<=j0+n; j++) {
    726       fprintf(f, format, m[i][j]);
    727     }
    728     fputc('\n', f);
    729   }
    730   fclose(f);
    731 }
    732 /* -------------------------------------------------------------------------------------------------------------------------- */
    733 IMAGE_EXPORT(void) write_ui16matrix_number_endline0(uint16 **m,long i0, long i1, long j0, long j1, char *format, char *filename)
    734 /* -------------------------------------------------------------------------------------------------------------------------- */
    735 {
    736   int i,j, n;
    737  
    738   FILE *f;
    739 
    740   f = fopen(filename, "wt");
    741   if(f == NULL) {
    742     nrerror("Can't open file in write_ui16matrix_number_endline0");
    743   }
    744 
    745   for(i=i0; i<=i1; i++) {
    746     fprintf(f, "[%3d] ", i);
    747     n = m[i][j0];
    748     for(j=j0; j<=j0+n; j++) {
    749       fprintf(f, format, m[i][j]);
    750     }
    751     fputc('\n', f);
    752   }
    753   fclose(f);
    754 }
    755 /* ------------------------------------------------------------------------------------------------------------------------ */
    756 IMAGE_EXPORT(void) write_i32matrix_number_endline0(int32 **m,long i0, long i1, long j0, long j1, char *format, char *filename)
    757 /* ------------------------------------------------------------------------------------------------------------------------ */
    758 {
    759   int i,j, n;
    760  
    761   FILE *f;
    762 
    763   f = fopen(filename, "wt");
    764   if(f == NULL) {
    765     nrerror("Can't open file in write_i32matrix_number_endline0");
    766   }
    767 
    768   for(i=i0; i<=i1; i++) {
    769     fprintf(f, "[%3d] ", i);
    770     n = m[i][j0];
    771     for(j=j0; j<=j0+n; j++) {
    772       fprintf(f, format, m[i][j]);
    773     }
    774     fputc('\n', f);
    775   }
    776   fclose(f);
    777 }
    778 /* -------------------------------------------------------------------------------------------------------------------------- */
    779 IMAGE_EXPORT(void) write_ui32matrix_number_endline0(uint32 **m,long i0, long i1, long j0, long j1, char *format, char *filename)
    780 /* -------------------------------------------------------------------------------------------------------------------------- */
    781 {
    782   int i,j, n;
    783  
    784   FILE *f;
    785 
    786   f = fopen(filename, "wt");
    787   if(f == NULL) {
    788     nrerror("Can't open file in write_ui32matrix_number_endline0");
    789   }
    790 
    791   for(i=i0; i<=i1; i++) {
    792     fprintf(f, "[%3d] ", i);
    793     n = m[i][j0];
    794     for(j=j0; j<=j0+n; j++) {
    795       fprintf(f, format, m[i][j]);
    796     }
    797     fputc('\n', f);
    798   }
    799   fclose(f);
    800 }
    801 /* ------------------------------------------------------------------------------------------------------------------------ */
    802 IMAGE_EXPORT(void) write_i64matrix_number_endline0(int64 **m,long i0, long i1, long j0, long j1, char *format, char *filename)
    803 /* ------------------------------------------------------------------------------------------------------------------------ */
    804 {
    805   int i,j;
    806   int64 n;
    807  
    808   FILE *f;
    809 
    810   f = fopen(filename, "wt");
    811   if(f == NULL) {
    812     nrerror("Can't open file in write_i64matrix_number_endline0");
    813   }
    814 
    815   for(i=i0; i<=i1; i++) {
    816     fprintf(f, "[%3d] ", i);
    817     n = m[i][j0];
    818     for(j=j0; j<=j0+n; j++) {
    819       fprintf(f, format, m[i][j]);
    820     }
    821     fputc('\n', f);
    822   }
    823   fclose(f);
    824 }
    825 /* -------------------------------------------------------------------------------------------------------------------- */
    826 IMAGE_EXPORT(void) write_imatrix_number_endline0(int **m,long i0, long i1, long j0, long j1, char *format, char *filename)
    827 /* -------------------------------------------------------------------------------------------------------------------- */
    828 {
    829   int i,j, n;
    830  
    831   FILE *f;
    832 
    833   f = fopen(filename, "wt");
    834   if(f == NULL) {
    835     nrerror("Can't open file in write_imatrix_number_endline0");
    836   }
    837 
    838   for(i=i0; i<=i1; i++) {
    839     fprintf(f, "[%3d] ", i);
    840     n = m[i][j0];
    841     for(j=j0; j<=j0+n; j++) {
    842       fprintf(f, format, m[i][j]);
    843     }
    844     fputc('\n', f);
    845   }
    846   fclose(f);
    847 }
     171
     172#undef write_type_matrix_number_endline0
     173#define write_type_matrix_number_endline0(t) \
     174void short_name(t,write_,matrix_number_endline0)(t ** m, int32_t i0, int32_t i1, int32_t j0, int32_t j1, char * format, char * filename) \
     175{                                                                \
     176    FILE * f = fopen(filename, "wt");                            \
     177    if (f == NULL) {                                             \
     178        nrerror("Can't open file %s in %s", filename, __func__); \
     179    }                                                            \
     180    for (int32_t i = i0; i <= i1; i++) {                         \
     181        fprintf(f, "[%3d] ", i);                                 \
     182        int32_t n = (int32_t) m[i][j0];                          \
     183        for (int32_t j = j0; j <= j0 + n; j++) {                 \
     184            fprintf(f, format, m[i][j]);                         \
     185        }                                                        \
     186        fprintf(f, "\n");                                        \
     187    }                                                            \
     188    fprintf(f, "\n");                                            \
     189    fclose(f);                                                   \
     190}
     191
     192write_type_matrix_number_endline0(int8_t);
     193write_type_matrix_number_endline0(uint8_t);
     194write_type_matrix_number_endline0(int16_t);
     195write_type_matrix_number_endline0(uint16_t);
     196write_type_matrix_number_endline0(int32_t);
     197write_type_matrix_number_endline0(uint32_t);
     198write_type_matrix_number_endline0(int64_t);
     199write_type_matrix_number_endline0(uint64_t);
     200write_type_matrix_number_endline0(float);
     201write_type_matrix_number_endline0(double);
     202
     203
    848204/* ------------------------------------- */
    849205/* --- write_imatrix_number_endline1 --- */
    850206/* ------------------------------------- */
    851 /* --------------------------------------------------------------------------------------------------------------------- */
    852 IMAGE_EXPORT(void) write_bmatrix_number_endline1(byte **m,long i0, long i1, long j0, long j1, char *format, char *filename)
    853 /* --------------------------------------------------------------------------------------------------------------------- */
    854 {
    855   int i,j, n;
    856  
    857   FILE *f;
    858 
    859   f = fopen(filename, "wt");
    860   if(f == NULL) {
    861     nrerror("Can't open file in write_bmatrix_number_endline1");
    862   }
    863 
    864   for(i=i0; i<=i1; i++) {
    865     fprintf(f, "[%3d] ", i);
    866     n = m[i][j0-1];
    867     for(j=j0; j<=j0+n-1; j++) {
    868       fprintf(f, format, m[i][j]);
    869     }
    870     fputc('\n', f);
    871   }
    872   fclose(f);
    873 }
    874 /* ------------------------------------------------------------------------------------------------------------------------ */
    875 IMAGE_EXPORT(void) write_i16matrix_number_endline1(int16 **m,long i0, long i1, long j0, long j1, char *format, char *filename)
    876 /* ------------------------------------------------------------------------------------------------------------------------ */
    877 {
    878   int i,j, n;
    879  
    880   FILE *f;
    881 
    882   f = fopen(filename, "wt");
    883   if(f == NULL) {
    884     nrerror("Can't open file in write_i16matrix_number_endline0");
    885   }
    886 
    887   for(i=i0; i<=i1; i++) {
    888     fprintf(f, "[%3d] ", i);
    889     n = m[i][j0-1];
    890     for(j=j0; j<=j0+n-1; j++) {
    891       fprintf(f, format, m[i][j]);
    892     }
    893     fputc('\n', f);
    894   }
    895   fclose(f);
    896 }
    897 /* -------------------------------------------------------------------------------------------------------------------------- */
    898 IMAGE_EXPORT(void) write_ui16matrix_number_endline1(uint16 **m,long i0, long i1, long j0, long j1, char *format, char *filename)
    899 /* -------------------------------------------------------------------------------------------------------------------------- */
    900 {
    901   int i,j, n;
    902  
    903   FILE *f;
    904 
    905   f = fopen(filename, "wt");
    906   if(f == NULL) {
    907     nrerror("Can't open file in write_ui16matrix_number_endline0");
    908   }
    909 
    910   for(i=i0; i<=i1; i++) {
    911     fprintf(f, "[%3d] ", i);
    912     n = m[i][j0-1];
    913     for(j=j0; j<=j0+n-1; j++) {
    914       fprintf(f, format, m[i][j]);
    915     }
    916     fputc('\n', f);
    917   }
    918   fclose(f);
    919 }
    920 /* ------------------------------------------------------------------------------------------------------------------------ */
    921 IMAGE_EXPORT(void) write_i32matrix_number_endline1(int32 **m,long i0, long i1, long j0, long j1, char *format, char *filename)
    922 /* ------------------------------------------------------------------------------------------------------------------------ */
    923 {
    924   int i,j, n;
    925  
    926   FILE *f;
    927 
    928   f = fopen(filename, "wt");
    929   if(f == NULL) {
    930     nrerror("Can't open file in write_i32matrix_number_endline0");
    931   }
    932 
    933   for(i=i0; i<=i1; i++) {
    934     fprintf(f, "[%3d] ", i);
    935     n = m[i][j0-1];
    936     for(j=j0; j<=j0+n-1; j++) {
    937       fprintf(f, format, m[i][j]);
    938     }
    939     fputc('\n', f);
    940   }
    941   fclose(f);
    942 }
    943 /* -------------------------------------------------------------------------------------------------------------------------- */
    944 IMAGE_EXPORT(void) write_ui32matrix_number_endline1(uint32 **m,long i0, long i1, long j0, long j1, char *format, char *filename)
    945 /* -------------------------------------------------------------------------------------------------------------------------- */
    946 {
    947   int i,j, n;
    948  
    949   FILE *f;
    950 
    951   f = fopen(filename, "wt");
    952   if(f == NULL) {
    953     nrerror("Can't open file in write_ui32matrix_number_endline0");
    954   }
    955 
    956   for(i=i0; i<=i1; i++) {
    957     fprintf(f, "[%3d] ", i);
    958     n = m[i][j0-1];
    959     for(j=j0; j<=j0+n-1; j++) {
    960       fprintf(f, format, m[i][j]);
    961     }
    962     fputc('\n', f);
    963   }
    964   fclose(f);
    965 }
    966 /* ------------------------------------------------------------------------------------------------------------------------ */
    967 IMAGE_EXPORT(void) write_i64matrix_number_endline1(int64 **m,long i0, long i1, long j0, long j1, char *format, char *filename)
    968 /* ------------------------------------------------------------------------------------------------------------------------ */
    969 {
    970   int i,j;
    971   int64 n;
    972  
    973   FILE *f;
    974 
    975   f = fopen(filename, "wt");
    976   if(f == NULL) {
    977     nrerror("Can't open file in write_i64matrix_number_endline0");
    978   }
    979 
    980   for(i=i0; i<=i1; i++) {
    981     fprintf(f, "[%3d] ", i);
    982     n = m[i][j0-1];
    983     for(j=j0; j<=j0+n-1; j++) {
    984       fprintf(f, format, m[i][j]);
    985     }
    986     fputc('\n', f);
    987   }
    988   fclose(f);
    989 }
    990 /* -------------------------------------------------------------------------------------------------------------------- */
    991 IMAGE_EXPORT(void) write_imatrix_number_endline1(int **m,long i0, long i1, long j0, long j1, char *format, char *filename)
    992 /* -------------------------------------------------------------------------------------------------------------------- */
    993 {
    994   int i,j, n;
    995  
    996   FILE *f;
    997 
    998   f = fopen(filename, "wt");
    999   if(f == NULL) {
    1000     nrerror("Can't open file in write_imatrix_number_endline0");
    1001   }
    1002 
    1003   for(i=i0; i<=i1; i++) {
    1004     fprintf(f, "[%3d] ", i);
    1005     n = m[i][j0-1];
    1006     for(j=j0; j<=j0+n-1; j++) {
    1007       fprintf(f, format, m[i][j]);
    1008     }
    1009     fputc('\n', f);
    1010   }
    1011   fclose(f);
    1012 }
     207
     208#undef write_type_matrix_number_endline1
     209#define write_type_matrix_number_endline1(t) \
     210void short_name(t,write_,matrix_number_endline1)(t ** m, int32_t i0, int32_t i1, int32_t j0, int32_t j1, char * format, char * filename) \
     211{                                                                \
     212    FILE * f = fopen(filename, "wt");                            \
     213    if (f == NULL) {                                             \
     214        nrerror("Can't open file %s in %s", filename, __func__); \
     215    }                                                            \
     216    for (int32_t i = i0; i <= i1; i++) {                         \
     217        fprintf(f, "[%3d] ", i);                                 \
     218        int32_t n = (int32_t) m[i][j0 - 1];                      \
     219        for (int32_t j = j0; j <= j0 + n - 1; j++) {             \
     220            fprintf(f, format, m[i][j]);                         \
     221        }                                                        \
     222        fprintf(f, "\n");                                        \
     223    }                                                            \
     224    fprintf(f, "\n");                                            \
     225    fclose(f);                                                   \
     226}
     227
     228write_type_matrix_number_endline1(int8_t);
     229write_type_matrix_number_endline1(uint8_t);
     230write_type_matrix_number_endline1(int16_t);
     231write_type_matrix_number_endline1(uint16_t);
     232write_type_matrix_number_endline1(int32_t);
     233write_type_matrix_number_endline1(uint32_t);
     234write_type_matrix_number_endline1(int64_t);
     235write_type_matrix_number_endline1(uint64_t);
     236write_type_matrix_number_endline1(float);
     237write_type_matrix_number_endline1(double);
     238
     239
    1013240/* ---------------------- */
    1014241/* -- fwrite_trimatrix -- */
    1015242/* ---------------------- */
    1016 /* ---------------------------------------------------------------------------------------------------- */
    1017 IMAGE_EXPORT(void) fwrite_btrimatrix(byte **m,long i0,long i1,long j0, long j1, long step, char *filename)
    1018 /* ---------------------------------------------------------------------------------------------------- */
    1019 {
    1020   long  i, ncol = j1-j0+1;
    1021   FILE *f;
    1022 
    1023   f = fopen(filename, "wb");
    1024   if(f == NULL) nrerror("Can't open file in fwrite_btrimatrix");
    1025 
    1026   for(i=i0; i<=i1; i++) {
    1027     fwrite(m[i]+j0, sizeof(byte), ncol, f);
    1028     ncol += step;
    1029   }
    1030   fclose(f);
    1031 }
    1032 /* ------------------------------------------------------------------------------------------------------- */
    1033 IMAGE_EXPORT(void) fwrite_i16trimatrix(int16 **m,long i0,long i1,long j0, long j1, long step, char *filename)
    1034 /* ------------------------------------------------------------------------------------------------------- */
    1035 {
    1036   long  i, ncol = j1-j0+1;
    1037   FILE *f;
    1038 
    1039   f = fopen(filename, "wb");
    1040   if(f == NULL) nrerror("Can't open file in fwrite_i16trimatrix");
    1041 
    1042   for(i=i0; i<=i1; i++) {
    1043     fwrite(m[i]+j0, sizeof(int16), ncol, f);
    1044     ncol += step;
    1045   }
    1046   fclose(f);
    1047 }
    1048 /* --------------------------------------------------------------------------------------------------------- */
    1049 IMAGE_EXPORT(void) fwrite_ui16trimatrix(uint16 **m,long i0,long i1,long j0, long j1, long step, char *filename)
    1050 /* --------------------------------------------------------------------------------------------------------- */
    1051 {
    1052   long  i, ncol = j1-j0+1;
    1053   FILE *f;
    1054 
    1055   f = fopen(filename, "wb");
    1056   if(f == NULL) nrerror("Can't open file in fwrite_ui16trimatrix");
    1057 
    1058   for(i=i0; i<=i1; i++) {
    1059     fwrite(m[i]+j0, sizeof(uint16), ncol, f);
    1060     ncol += step;
    1061   }
    1062   fclose(f);
    1063 }
    1064 /* ------------------------------------------------------------------------------------------------------- */
    1065 IMAGE_EXPORT(void) fwrite_i32trimatrix(int32 **m,long i0,long i1,long j0, long j1, long step, char *filename)
    1066 /* ------------------------------------------------------------------------------------------------------- */
    1067 {
    1068   long  i, ncol = j1-j0+1;
    1069   FILE *f;
    1070 
    1071   f = fopen(filename, "wb");
    1072   if(f == NULL) nrerror("Can't open file in fwrite_i32trimatrix");
    1073 
    1074   for(i=i0; i<=i1; i++) {
    1075     fwrite(m[i]+j0, sizeof(int32), ncol, f);
    1076     ncol += step;
    1077   }
    1078   fclose(f);
    1079 }
    1080 /* --------------------------------------------------------------------------------------------------------- */
    1081 IMAGE_EXPORT(void) fwrite_f32trimatrix(float32 **m,long i0,long i1,long j0, long j1, long step, char *filename)
    1082 /* --------------------------------------------------------------------------------------------------------- */
    1083 {
    1084   long  i, ncol = j1-j0+1;
    1085   FILE *f;
    1086 
    1087   f = fopen(filename, "wb");
    1088   if(f == NULL) nrerror("Can't open file in fwrite_f32trimatrix");
    1089 
    1090   for(i=i0; i<=i1; i++) {
    1091     fwrite(m[i]+j0, sizeof(float32), ncol, f);
    1092     ncol += step;
    1093   }
    1094   fclose(f);
    1095 }
    1096 /* --------------------------------------------------------------------------------------------------------- */
    1097 IMAGE_EXPORT(void) fwrite_f64trimatrix(float64 **m,long i0,long i1,long j0, long j1, long step, char *filename)
    1098 /* --------------------------------------------------------------------------------------------------------- */
    1099 {
    1100   long  i, ncol = j1-j0+1;
    1101   FILE *f;
    1102 
    1103   f = fopen(filename, "wb");
    1104   if(f == NULL) nrerror("Can't open file in fwrite_f64trimatrix");
    1105 
    1106   for(i=i0; i<=i1; i++) {
    1107     fwrite(m[i]+j0, sizeof(float64), ncol, f);
    1108   }
    1109   fclose(f);
    1110 }
     243
     244#undef fwrite_type_trimatrix
     245#define fwrite_type_trimatrix(t) \
     246void short_name(t,fwrite_,trimatrix)(t ** m, int32_t i0, int32_t i1, int32_t j0, int32_t j1, int32_t step, char * filename) \
     247{                                                                \
     248    int32_t ncol = j1 - j0 + 1;                                  \
     249    FILE * f = fopen(filename, "wb");                            \
     250    if (f == NULL) {                                             \
     251        nrerror("Can't open file %s in %s", filename, __func__); \
     252    }                                                            \
     253    for (int32_t i = i0; i <= i1; i++) {                         \
     254        fwrite(m[i] + j0, sizeof(t), ncol, f);                   \
     255        ncol += step;                                            \
     256    }                                                            \
     257    fclose(f);                                                   \
     258}
     259
     260fwrite_type_trimatrix(int8_t);
     261fwrite_type_trimatrix(uint8_t);
     262fwrite_type_trimatrix(int16_t);
     263fwrite_type_trimatrix(uint16_t);
     264fwrite_type_trimatrix(int32_t);
     265fwrite_type_trimatrix(uint32_t);
     266fwrite_type_trimatrix(int64_t);
     267fwrite_type_trimatrix(uint64_t);
     268fwrite_type_trimatrix(float);
     269fwrite_type_trimatrix(double);
     270
     271
     272
    1111273
    1112274/* --------------------- */
    1113275/* -- fread_trimatrix -- */
    1114276/* --------------------- */
    1115 /* --------------------------------------------------------------------------------------------------- */
    1116 IMAGE_EXPORT(void) fread_btrimatrix(char *filename, byte **m,long i0,long i1,long j0, long j1, long step)
    1117 /* --------------------------------------------------------------------------------------------------- */
    1118 {
    1119   long  i, ncol = j1-j0+1, nread;
    1120   FILE *f;
    1121 
    1122   f = fopen(filename, "rb");
    1123   if(f == NULL) nrerror("Can't open file in fread_btrimatrix");
    1124 
    1125   for(i=i0; i<=i1; i++) {
    1126     nread = fread(m[i]+j0, sizeof(byte), ncol, f);
    1127     if(nread != ncol) nrerror("fread_btrimatrix : can't read data");
    1128     ncol += step;
    1129   }
    1130   fclose(f);
    1131 }
    1132 /* ------------------------------------------------------------------------------------------------------ */
    1133 IMAGE_EXPORT(void) fread_i16trimatrix(char *filename, int16 **m,long i0,long i1,long j0, long j1, long step)
    1134 /* ------------------------------------------------------------------------------------------------------ */
    1135 {
    1136   long  i, ncol = j1-j0+1, nread;
    1137   FILE *f;
    1138 
    1139   f = fopen(filename, "rb");
    1140   if(f == NULL) nrerror("Can't open file in fread_i16trimatrix");
    1141 
    1142   for(i=i0; i<=i1; i++) {
    1143     nread = fread(m[i]+j0, sizeof(int16), ncol, f);
    1144     if(nread != ncol) nrerror("fread_i16trimatrix : can't read data");
    1145     ncol += step;
    1146   }
    1147   fclose(f);
    1148 }
    1149 /* -------------------------------------------------------------------------------------------------------- */
    1150 IMAGE_EXPORT(void) fread_ui16trimatrix(char *filename, uint16 **m,long i0,long i1,long j0, long j1, long step)
    1151 /* -------------------------------------------------------------------------------------------------------- */
    1152 {
    1153   long  i, ncol = j1-j0+1, nread;
    1154   FILE *f;
    1155 
    1156   f = fopen(filename, "rb");
    1157   if(f == NULL) nrerror("Can't open file in fread_ui16trimatrix");
    1158 
    1159   for(i=i0; i<=i1; i++) {
    1160     nread = fread(m[i]+j0, sizeof(uint16), ncol, f);
    1161     if(nread != ncol) nrerror("fread_ui16trimatrix : can't read data");
    1162     ncol += step;
    1163   }
    1164   fclose(f);
    1165 }
    1166 /* -------------------------------------------------------------------------------------------------- */
    1167 IMAGE_EXPORT(void) fread_itrimatrix(char *filename, int **m,long i0,long i1,long j0, long j1, long step)
    1168 /* -------------------------------------------------------------------------------------------------- */
    1169 {
    1170   long  i, ncol = j1-j0+1, nread;
    1171   FILE *f;
    1172 
    1173   f = fopen(filename, "rb");
    1174   if(f == NULL) nrerror("Can't open file in fread_itrimatrix");
    1175 
    1176   for(i=i0; i<=i1; i++) {
    1177     nread = fread(m[i]+j0, sizeof(int), ncol, f);
    1178     if(nread != ncol) nrerror("fread_itrimatrix : can't read data");
    1179     ncol += step;
    1180   }
    1181   fclose(f);
    1182 }
    1183 /* ------------------------------------------------------------------------------------------------------ */
    1184 IMAGE_EXPORT(void) fread_i32trimatrix(char *filename, int32 **m,long i0,long i1,long j0, long j1, long step)
    1185 /* ------------------------------------------------------------------------------------------------------ */
    1186 {
    1187   long  i, ncol = j1-j0+1, nread;
    1188   FILE *f;
    1189 
    1190   f = fopen(filename, "rb");
    1191   if(f == NULL) nrerror("Can't open file in fread_i32trimatrix");
    1192 
    1193   for(i=i0; i<=i1; i++) {
    1194     nread = fread(m[i]+j0, sizeof(byte), ncol, f);
    1195     if(nread != ncol) nrerror("fread_i32trimatrix : can't read data");
    1196     ncol += step;
    1197   }
    1198   fclose(f);
    1199 }
    1200 /* -------------------------------------------------------------------------------------------------------- */
    1201 IMAGE_EXPORT(void) fread_f32trimatrix(char *filename, float32 **m,long i0,long i1,long j0, long j1, long step)
    1202 /* -------------------------------------------------------------------------------------------------------- */
    1203 {
    1204   long  i, ncol = j1-j0+1, nread;
    1205   FILE *f;
    1206 
    1207   f = fopen(filename, "rb");
    1208   if(f == NULL) nrerror("Can't open file in fread_f32trimatrix");
    1209 
    1210   for(i=i0; i<=i1; i++) {
    1211     nread = fread(m[i]+j0, sizeof(byte), ncol, f);
    1212     if(nread != ncol) nrerror("fread_f32trimatrix : can't read data");
    1213     ncol += step;
    1214   }
    1215   fclose(f);
    1216 }
    1217 /* -------------------------------------------------------------------------------------------------------- */
    1218 IMAGE_EXPORT(void) fread_f64trimatrix(char *filename, float64 **m,long i0,long i1,long j0, long j1, long step)
    1219 /* -------------------------------------------------------------------------------------------------------- */
    1220 {
    1221   long  i, ncol = j1-j0+1, nread;
    1222   FILE *f;
    1223 
    1224   f = fopen(filename, "rb");
    1225   if(f == NULL) nrerror("Can't open file in fread_f64trimatrix");
    1226 
    1227   for(i=i0; i<=i1; i++) {
    1228     nread = fread(m[i]+j0, sizeof(byte), ncol, f);
    1229     if(nread != ncol) nrerror("fread_f64trimatrix : can't read data");
    1230     ncol += step;
    1231   }
    1232   fclose(f);
    1233 }
     277
     278#undef fread_type_trimatrix
     279#define fread_type_trimatrix(t) \
     280void short_name(t,fread_,trimatrix)(char * filename, t ** m, int32_t i0, int32_t i1, int32_t j0, int32_t j1, int32_t step) \
     281{                                                                \
     282    int32_t ncol = j1 - j0 + 1;                                  \
     283    FILE * f = fopen(filename, "rb");                            \
     284    if (f == NULL) {                                             \
     285        nrerror("Can't open file %s in %s", filename, __func__); \
     286    }                                                            \
     287    for (int32_t i = i0; i <= i1; i++) {                         \
     288        fread(m[i] + j0, sizeof(t), ncol, f);    \
     289        ncol += step;                                            \
     290    }                                                            \
     291    fclose(f);                                                   \
     292}
     293
     294fread_type_trimatrix(int8_t);
     295fread_type_trimatrix(uint8_t);
     296fread_type_trimatrix(int16_t);
     297fread_type_trimatrix(uint16_t);
     298fread_type_trimatrix(int32_t);
     299fread_type_trimatrix(uint32_t);
     300fread_type_trimatrix(int64_t);
     301fread_type_trimatrix(uint64_t);
     302fread_type_trimatrix(float);
     303fread_type_trimatrix(double);
     304
     305
     306// Local Variables:
     307// tab-width: 4
     308// c-basic-offset: 4
     309// c-file-offsets:((innamespace . 0)(inline-open . 0))
     310// indent-tabs-mode: nil
     311// End:
     312
     313// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4
     314
  • soft/giet_vm/applications/rosenfeld/nrc2/src/nrio3.c

    r772 r823  
    3030/* --- display_cube --- */
    3131/* -------------------- */
    32 /* ------------------------------------------------------------------------------------------------------------------------- */
    33 IMAGE_EXPORT(void) display_i8cube(int8 ***c,long ndl, long ndh, long nrl,long nrh,long ncl, long nch, char *format, char *name)
    34 /* ------------------------------------------------------------------------------------------------------------------------- */
    35 {
    36   long i,j,k;
    3732
    38   if(name != NULL) puts(name);
     33#undef display_type_cube
     34#define display_type_cube(t) \
     35void short_name(t,display_,cube)(t *** c, int32_t ndl, int32_t ndh, int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch, char * format, char * name) \
     36{                                                  \
     37    if (name != NULL) {                            \
     38        printf(name);                              \
     39    }                                              \
     40    for (int32_t k = ndl; k <= ndh; k++) {         \
     41        for (int32_t i = nrl; i <= nrh; i++) {     \
     42            for (int32_t j = ncl; j <= nch; j++) { \
     43                printf(format, c[k][i][j]);        \
     44            }                                      \
     45            printf("\n");                          \
     46        }                                          \
     47        printf("\n");                              \
     48    }                                              \
     49}
    3950
    40   for(k=ndl; k<=ndh; k++) {
    41     for(i=nrl; i<=nrh; i++) {
    42       for(j=ncl; j<=nch; j++) {
    43         printf(format, c[k][i][j]);
    44       }
    45       putchar('\n');
    46     }
    47     putchar('\n');
    48   }
    49 }
    50 /* --------------------------------------------------------------------------------------------------------------------------- */
    51 IMAGE_EXPORT(void) display_i16cube(int16 ***c,long ndl, long ndh, long nrl,long nrh,long ncl, long nch, char *format, char *name)
    52 /* --------------------------------------------------------------------------------------------------------------------------- */
    53 {
    54   long i,j,k;
     51display_type_cube(int8_t);
     52display_type_cube(uint8_t);
     53display_type_cube(int16_t);
     54display_type_cube(uint16_t);
     55display_type_cube(int32_t);
     56display_type_cube(uint32_t);
     57display_type_cube(int64_t);
     58display_type_cube(uint64_t);
     59display_type_cube(float);
     60display_type_cube(double);
    5561
    56   if(name != NULL) puts(name);
    5762
    58   for(k=ndl; k<=ndh; k++) {
    59     for(i=nrl; i<=nrh; i++) {
    60       for(j=ncl; j<=nch; j++) {
    61         printf(format, c[k][i][j]);
    62       }
    63       putchar('\n');
    64     }
    65     putchar('\n');
    66   }
    67 }
    68 /* ----------------------------------------------------------------------------------------------------------------------------- */
    69 IMAGE_EXPORT(void) display_ui16cube(uint16 ***c,long ndl, long ndh, long nrl,long nrh,long ncl, long nch, char *format, char *name)
    70 /* ----------------------------------------------------------------------------------------------------------------------------- */
    71 {
    72   long i,j,k;
    73 
    74   if(name != NULL) puts(name);
    75 
    76   for(k=ndl; k<=ndh; k++) {
    77     for(i=nrl; i<=nrh; i++) {
    78       for(j=ncl; j<=nch; j++) {
    79         printf(format, c[k][i][j]);
    80       }
    81       putchar('\n');
    82     }
    83     putchar('\n');
    84   }
    85 }
    86 /* --------------------------------------------------------------------------------------------------------------------------- */
    87 IMAGE_EXPORT(void) display_i32cube(int32 ***c,long ndl, long ndh, long nrl,long nrh,long ncl, long nch, char *format, char *name)
    88 /* --------------------------------------------------------------------------------------------------------------------------- */
    89 {
    90   long i,j,k;
    91 
    92   if(name != NULL) puts(name);
    93 
    94   for(k=ndl; k<=ndh; k++) {
    95     for(i=nrl; i<=nrh; i++) {
    96       for(j=ncl; j<=nch; j++) {
    97         printf(format, c[k][i][j]);
    98       }
    99       putchar('\n');
    100     }
    101     putchar('\n');
    102   }
    103 }
    104 /* ----------------------------------------------------------------------------------------------------------------------------- */
    105 IMAGE_EXPORT(void) display_ui32cube(uint32 ***c,long ndl, long ndh, long nrl,long nrh,long ncl, long nch, char *format, char *name)
    106 /* ----------------------------------------------------------------------------------------------------------------------------- */
    107 {
    108   long i,j,k;
    109 
    110   if(name != NULL) puts(name);
    111 
    112   for(k=ndl; k<=ndh; k++) {
    113     for(i=nrl; i<=nrh; i++) {
    114       for(j=ncl; j<=nch; j++) {
    115         printf(format, c[k][i][j]);
    116       }
    117       putchar('\n');
    118     }
    119     putchar('\n');
    120   }
    121 }
    122 /* --------------------------------------------------------------------------------------------------------------------------- */
    123 IMAGE_EXPORT(void) display_i64cube(int64 ***c,long ndl, long ndh, long nrl,long nrh,long ncl, long nch, char *format, char *name)
    124 /* --------------------------------------------------------------------------------------------------------------------------- */
    125 {
    126   long i,j,k;
    127 
    128   if(name != NULL) puts(name);
    129 
    130   for(k=ndl; k<=ndh; k++) {
    131     for(i=nrl; i<=nrh; i++) {
    132       for(j=ncl; j<=nch; j++) {
    133         printf(format, c[k][i][j]);
    134       }
    135       putchar('\n');
    136     }
    137     putchar('\n');
    138   }
    139 }
    140 /* ----------------------------------------------------------------------------------------------------------------------------- */
    141 IMAGE_EXPORT(void) display_f32cube(float32 ***c,long ndl, long ndh, long nrl,long nrh,long ncl, long nch, char *format, char *name)
    142 /* ----------------------------------------------------------------------------------------------------------------------------- */
    143 {
    144   long i,j,k;
    145 
    146   if(name != NULL) puts(name);
    147 
    148   for(k=ndl; k<=ndh; k++) {
    149     for(i=nrl; i<=nrh; i++) {
    150       for(j=ncl; j<=nch; j++) {
    151         printf(format, c[k][i][j]);
    152       }
    153       putchar('\n');
    154     }
    155     putchar('\n');
    156   }
    157 }
    15863
    15964/* ---------------- */
    16065/* -- write_cube -- */
    16166/* ---------------- */
    162 /* ------------------------------------------------------------------------------------------------------------------------------ */
    163 IMAGE_EXPORT(void) write_i8cube(int8 ***c, long ndl, long ndh, long nrl, long nrh, long ncl, long nch, char *format, char *filename)
    164 /* ------------------------------------------------------------------------------------------------------------------------------ */
    165 {
    166   int i, j, k;
    16767
    168   FILE *f;
     68#undef write_type_cube
     69#define write_type_cube(t) \
     70void short_name(t,write_,cube)(t *** c, int32_t ndl, int32_t ndh, int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch, char * format, char * filename) \
     71{                                                                \
     72    FILE * f = fopen(filename, "wt");                            \
     73    if (f == NULL) {                                             \
     74        nrerror("Can't open file %s in %s", filename, __func__); \
     75    }                                                            \
     76    for (int32_t k = ndl; k <= ndh; k++) {                       \
     77        for (int32_t i = nrl; i <= nrh; i++) {                   \
     78            for (int32_t j = ncl; j <= nch; j++) {               \
     79                fprintf(f, format, c[k][i][j]);                  \
     80            }                                                    \
     81            fprintf(f, "\n");                                    \
     82        }                                                        \
     83        fprintf(f, "\n");                                        \
     84    }                                                            \
     85    fclose(f);                                                   \
     86}
    16987
    170   f = fopen(filename, "wt");
    171   if(f == NULL) {
    172     nrerror("Can't open file in write_i8cube");
    173   }
     88write_type_cube(int8_t);
     89write_type_cube(uint8_t);
     90write_type_cube(int16_t);
     91write_type_cube(uint16_t);
     92write_type_cube(int32_t);
     93write_type_cube(uint32_t);
     94write_type_cube(int64_t);
     95write_type_cube(uint64_t);
     96write_type_cube(float);
     97write_type_cube(double);
    17498
    175   for(k=ndl; k<=ndh; k++) {
    176     for(i=nrl; i<=nrh; i++) {
    177       for(j=ncl; j<=nch; j++) {
    178         fprintf(f, format, c[k][i][j]);
    179       }
    180       fputc('\n', f);
    181     }
    182     fputc('\n', f);
    183   }
    18499
    185   fclose(f);
    186 }
    187 /* -------------------------------------------------------------------------------------------------------------------------------- */
    188 IMAGE_EXPORT(void) write_i16cube(int16 ***c, long ndl, long ndh, long nrl, long nrh, long ncl, long nch, char *format, char *filename)
    189 /* -------------------------------------------------------------------------------------------------------------------------------- */
    190 {
    191   int i, j, k;
    192 
    193   FILE *f;
    194 
    195   f = fopen(filename, "wt");
    196   if(f == NULL) {
    197     nrerror("Can't open file in write_i16cube");
    198   }
    199 
    200   for(k=ndl; k<=ndh; k++) {
    201     for(i=nrl; i<=nrh; i++) {
    202       for(j=ncl; j<=nch; j++) {
    203         fprintf(f, format, c[k][i][j]);
    204       }
    205       fputc('\n', f);
    206     }
    207     fputc('\n', f);
    208   }
    209 
    210   fclose(f);
    211 }
    212 /* ---------------------------------------------------------------------------------------------------------------------------------- */
    213 IMAGE_EXPORT(void) write_ui16cube(uint16 ***c, long ndl, long ndh, long nrl, long nrh, long ncl, long nch, char *format, char *filename)
    214 /* ---------------------------------------------------------------------------------------------------------------------------------- */
    215 {
    216   int i, j, k;
    217 
    218   FILE *f;
    219 
    220   f = fopen(filename, "wt");
    221   if(f == NULL) {
    222     nrerror("Can't open file in write_ui16cube");
    223   }
    224 
    225   for(k=ndl; k<=ndh; k++) {
    226     for(i=nrl; i<=nrh; i++) {
    227       for(j=ncl; j<=nch; j++) {
    228         fprintf(f, format, c[k][i][j]);
    229       }
    230       fputc('\n', f);
    231     }
    232     fputc('\n', f);
    233   }
    234 
    235   fclose(f);
    236 }
    237 /* -------------------------------------------------------------------------------------------------------------------------------- */
    238 IMAGE_EXPORT(void) write_i32cube(int32 ***c, long ndl, long ndh, long nrl, long nrh, long ncl, long nch, char *format, char *filename)
    239 /* -------------------------------------------------------------------------------------------------------------------------------- */
    240 {
    241   int i, j, k;
    242 
    243   FILE *f;
    244 
    245   f = fopen(filename, "wt");
    246   if(f == NULL) {
    247     nrerror("Can't open file in write_i32cube");
    248   }
    249 
    250   for(k=ndl; k<=ndh; k++) {
    251     for(i=nrl; i<=nrh; i++) {
    252       for(j=ncl; j<=nch; j++) {
    253         fprintf(f, format, c[k][i][j]);
    254       }
    255       fputc('\n', f);
    256     }
    257     fputc('\n', f);
    258   }
    259 
    260   fclose(f);
    261 }
    262 /* ---------------------------------------------------------------------------------------------------------------------------------- */
    263 IMAGE_EXPORT(void) write_ui32cube(uint32 ***c, long ndl, long ndh, long nrl, long nrh, long ncl, long nch, char *format, char *filename)
    264 /* ---------------------------------------------------------------------------------------------------------------------------------- */
    265 {
    266   int i, j, k;
    267 
    268   FILE *f;
    269 
    270   f = fopen(filename, "wt");
    271   if(f == NULL) {
    272     nrerror("Can't open file in write_ui32cube");
    273   }
    274 
    275   for(k=ndl; k<=ndh; k++) {
    276     for(i=nrl; i<=nrh; i++) {
    277       for(j=ncl; j<=nch; j++) {
    278         fprintf(f, format, c[k][i][j]);
    279       }
    280       fputc('\n', f);
    281     }
    282     fputc('\n', f);
    283   }
    284 
    285   fclose(f);
    286 }
    287 /* -------------------------------------------------------------------------------------------------------------------------------- */
    288 IMAGE_EXPORT(void) write_i64cube(int64 ***c, long ndl, long ndh, long nrl, long nrh, long ncl, long nch, char *format, char *filename)
    289 /* -------------------------------------------------------------------------------------------------------------------------------- */
    290 {
    291   int i, j, k;
    292 
    293   FILE *f;
    294 
    295   f = fopen(filename, "wt");
    296   if(f == NULL) {
    297     nrerror("Can't open file in write_i64cube");
    298   }
    299 
    300   for(k=ndl; k<=ndh; k++) {
    301     for(i=nrl; i<=nrh; i++) {
    302       for(j=ncl; j<=nch; j++) {
    303         fprintf(f, format, c[k][i][j]);
    304       }
    305       fputc('\n', f);
    306     }
    307     fputc('\n', f);
    308   }
    309 
    310   fclose(f);
    311 }
    312 /* ---------------------------------------------------------------------------------------------------------------------------------- */
    313 IMAGE_EXPORT(void) write_f32cube(float32 ***c, long ndl, long ndh, long nrl, long nrh, long ncl, long nch, char *format, char *filename)
    314 /* ---------------------------------------------------------------------------------------------------------------------------------- */
    315 {
    316   int i, j, k;
    317 
    318   FILE *f;
    319 
    320   f = fopen(filename, "wt");
    321   if(f == NULL) {
    322     nrerror("Can't open file in write_f32cube");
    323   }
    324 
    325   for(k=ndl; k<=ndh; k++) {
    326     for(i=nrl; i<=nrh; i++) {
    327       for(j=ncl; j<=nch; j++) {
    328         fprintf(f, format, c[k][i][j]);
    329       }
    330       fputc('\n', f);
    331     }
    332     fputc('\n', f);
    333   }
    334 
    335   fclose(f);
    336 }
    337100
    338101/* ---------------- */
    339102/* -- fread_cube -- */
    340103/* ---------------- */
    341 /* ----------------------------------------------------------------------------------------------------------- */
    342 IMAGE_EXPORT(void) fread_i8cube(char *filename, int8 ***c,long ndl,long ndh,long nrl,long nrh,long ncl, long nch)
    343 /* ----------------------------------------------------------------------------------------------------------- */
    344 {
    345   long  i, k;
    346   long ncol = nch-ncl+1, nread;
    347   FILE *f;
    348104
    349   f = fopen(filename, "rb");
    350   if(f == NULL)
    351     nrerror("Can't open file in fread_i8cube");
     105#undef fread_type_cube
     106#define fread_type_cube(t) \
     107void short_name(t,fread_,cube)(t *** c, int32_t ndl, int32_t ndh, int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch, char * format, char * filename) \
     108{                                                                     \
     109    int32_t ncol = nch - ncl + 1;                                     \
     110    FILE * f = fopen(filename, "rb");                                 \
     111    if (f == NULL) {                                                  \
     112        nrerror("Can't open file %s in %s", filename, __func__);      \
     113    }                                                                 \
     114    for (int32_t k = ndl; k <= ndh; k++) {                            \
     115        for (int32_t i = nrl; i <= nrh; i++) {                        \
     116            int32_t nread = fread(&c[k][i][ncl], sizeof(t), ncol, f); \
     117            if (nread != ncol) {                                      \
     118                nrerror("%s: Can't write data", __func__);            \
     119            }                                                         \
     120        }                                                             \
     121    }                                                                 \
     122    fclose(f);                                                        \
     123}
     124
     125fread_type_cube(int8_t);
     126fread_type_cube(uint8_t);
     127fread_type_cube(int16_t);
     128fread_type_cube(uint16_t);
     129fread_type_cube(int32_t);
     130fread_type_cube(uint32_t);
     131fread_type_cube(int64_t);
     132fread_type_cube(uint64_t);
     133fread_type_cube(float);
     134fread_type_cube(double);
    352135
    353136
    354   for(k=ndl; k<=ndh; k++) {
    355     for(i=nrl; i<=nrh; i++) {
    356       nread = fread( &(c[k][i][ncl]), sizeof(int8), ncol, f);
    357       if(nread != ncol) nrerror("fread_i8cube : can't write data");
    358     }
    359   }
    360   fclose(f);
    361 }
    362 /* ------------------------------------------------------------------------------------------------------------- */
    363 IMAGE_EXPORT(void) fread_i16cube(char *filename, int16 ***c,long ndl,long ndh,long nrl,long nrh,long ncl, long nch)
    364 /* ------------------------------------------------------------------------------------------------------------- */
    365 {
    366   long  i, k;
    367   long ncol = nch-ncl+1, nread;
    368   FILE *f;
    369 
    370   f = fopen(filename, "rb");
    371   if(f == NULL)
    372     nrerror("Can't open file in fread_i16cube");
    373 
    374   for(k=ndl; k<=ndh; k++) {
    375     for(i=nrl; i<=nrh; i++) {
    376       nread = fread( &(c[k][i][ncl]), sizeof(int16), ncol, f);
    377       if(nread != ncol) nrerror("fread_i16cube : can't write data");
    378     }
    379   }
    380   fclose(f);
    381 }
    382 /* -------------------------------------------------------------------------------------------------------------------- */
    383 IMAGE_EXPORT(void) fread_ui16cube(char *filename, uint16 ***c, long ndl, long ndh, long nrl, long nrh, long ncl, long nch)
    384 /* -------------------------------------------------------------------------------------------------------------------- */
    385 {
    386   long  i, k;
    387   long ncol = nch-ncl+1, nread;
    388   FILE *f;
    389 
    390   f = fopen(filename, "rb");
    391   if(f == NULL)
    392     nrerror("Can't open file in fread_ui16cube");
    393137
    394138
    395   for(k=ndl; k<=ndh; k++) {
    396     for(i=nrl; i<=nrh; i++) {
    397       nread = fread( &(c[k][i][ncl]), sizeof(uint16), ncol, f);
    398       if(nread != ncol) nrerror("fread_ui16cube : can't write data");
    399     }
    400   }
    401   fclose(f);
    402 }
    403 /* ------------------------------------------------------------------------------------------------------------------ */
    404 IMAGE_EXPORT(void) fread_i32cube(char *filename, int32 ***c, long ndl, long ndh, long nrl, long nrh, long ncl, long nch)
    405 /* ------------------------------------------------------------------------------------------------------------------ */
    406 {
    407   long  i, k;
    408   long ncol = nch-ncl+1, nread;
    409   FILE *f;
    410 
    411   f = fopen(filename, "rb");
    412   if(f == NULL)
    413     nrerror("Can't open file in fread_i32cube");
    414139
    415140
    416   for(k=ndl; k<=ndh; k++) {
    417     for(i=nrl; i<=nrh; i++) {
    418       nread = fread( &(c[k][i][ncl]), sizeof(int32), ncol, f);
    419       if(nread != ncol) nrerror("fread_i32cube : can't write data");
    420     }
    421   }
    422   fclose(f);
    423 }
    424 /* --------------- */
    425 /* --- nrio3.h --- */
    426 /* --------------- */
     141// Local Variables:
     142// tab-width: 4
     143// c-basic-offset: 4
     144// c-file-offsets:((innamespace . 0)(inline-open . 0))
     145// indent-tabs-mode: nil
     146// End:
    427147
    428 #ifndef __NRIO3_H__
    429 #define __NRIO3_H__
     148// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4
    430149
    431 #ifdef __cplusplus
    432 #pragma message ("C++")
    433 extern "C" {
    434 #endif
    435    
    436 /* ------------------ */
    437 /* --- fread_cube --- */
    438 /* ------------------ */
    439 
    440 IMAGE_EXPORT(void) fread_ui32cube(char *filename, uint32  ***c, long ndl, long ndh, long nrl, long nrh, long ncl, long nch);
    441 IMAGE_EXPORT(void) fread_i64cube (char *filename, int64   ***c, long ndl, long ndh, long nrl, long nrh, long ncl, long nch);
    442 IMAGE_EXPORT(void) fread_f32cube (char *filename, float32 ***c, long ndl, long ndh, long nrl, long nrh, long ncl, long nch);
    443 
    444 /* ----------------- */
    445 /* -- fwrite_cube -- */
    446 /* ----------------- */
    447 
    448 IMAGE_EXPORT(void) fwrite_i8cube(int8     ***c, long ndl, long ndh, long nrl, long nrh, long ncl, long nch, char *filename);
    449 IMAGE_EXPORT(void) fwrite_i16cube(int16   ***c, long ndl, long ndh, long nrl, long nrh, long ncl, long nch, char *filename);
    450 IMAGE_EXPORT(void) fwrite_ui16cube(uint16 ***c, long ndl, long ndh, long nrl, long nrh, long ncl, long nch, char *filename);
    451 IMAGE_EXPORT(void) fwrite_i32cube(int32   ***c, long ndl, long ndh, long nrl, long nrh, long ncl, long nch, char *filename);
    452 IMAGE_EXPORT(void) fwrite_ui32cube(uint32 ***c, long ndl, long ndh, long nrl, long nrh, long ncl, long nch, char *filename);
    453 IMAGE_EXPORT(void) fwrite_i64cube(int64   ***c, long ndl, long ndh, long nrl, long nrh, long ncl, long nch, char *filename);
    454 
    455 #ifdef __cplusplus
    456 }
    457 #endif
    458 
    459 #endif /* __NRIO3_H__ */
  • soft/giet_vm/applications/rosenfeld/nrc2/src/nrlinalg.c

    r772 r823  
    2424#include "nrlinalg.h"
    2525
     26#undef transpose_type_matrix
     27#define transpose_type_matrix(t) \
     28void short_name(t,transpose_,matrix)(t ** S, int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch, t ** D) \
     29{                                              \
     30        for (int32_t i = nrl; i <= nch; i++) {     \
     31                for (int32_t j = ncl; j <= nch; j++) { \
     32                        D[j][i] = S[i][j];                 \
     33                }                                      \
     34        }                                          \
     35}
    2636
    27 /* ---------------------------------------------------------------------------------------- */
    28 IMAGE_EXPORT(void) transpose_bmatrix(byte **S, long nrl,long nrh,long ncl, long nch, byte **D)
    29 /* ---------------------------------------------------------------------------------------- */
    30 {
    31         int i, j;
    32        
    33         for(i=nrl; i<=nch; i++) {
    34                 for(j=ncl; j<=nch; j++) {
    35                         D[j][i] = S[i][j];
    36                 }
    37         }
     37transpose_type_matrix(int8_t);
     38transpose_type_matrix(uint8_t);
     39transpose_type_matrix(int16_t);
     40transpose_type_matrix(uint16_t);
     41transpose_type_matrix(int32_t);
     42transpose_type_matrix(uint32_t);
     43transpose_type_matrix(int64_t);
     44transpose_type_matrix(uint64_t);
     45transpose_type_matrix(float);
     46transpose_type_matrix(double);
     47transpose_type_matrix(rgb8);
     48transpose_type_matrix(rgbx8);
     49
     50
     51#undef transpose1_type_matrix
     52#define transpose1_type_matrix(t) \
     53void short_name(t,transpose1_,matrix)(t ** S, int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch) \
     54{                                                \
     55    t tmp;                                       \
     56        for (int32_t i = nrl; i <= nch; i++) {       \
     57                for (int32_t j = i + 1; j <= nch; j++) { \
     58                        tmp = S[j][i];                       \
     59            S[j][i] = S[i][j];                   \
     60            S[i][j] = tmp;                       \
     61                }                                        \
     62        }                                            \
    3863}
    39 /* ------------------------------------------------------------------------------------------- */
    40 IMAGE_EXPORT(void) transpose_si16matrix(sint16 **S, long nrl,long nrh,long ncl, long nch, sint16 **D)
    41 /* ------------------------------------------------------------------------------------------- */
    42 {
    43         int i, j;
    44        
    45         for(i=nrl; i<=nch; i++) {
    46                 for(j=ncl; j<=nch; j++) {
    47                         D[j][i] = S[i][j];
    48                 }
    49         }
    50 }
    51 /* ------------------------------------------------------------------------------------------- */
    52 IMAGE_EXPORT(void) transpose_ui16matrix(uint16 **S, long nrl,long nrh,long ncl, long nch, uint16 **D)
    53 /* ------------------------------------------------------------------------------------------- */
    54 {
    55         int i, j;
    56        
    57         for(i=nrl; i<=nch; i++) {
    58                 for(j=ncl; j<=nch; j++) {
    59                         D[j][i] = S[i][j];
    60                 }
    61         }
    62 }
    63 /* ----------------------------------------------------------------------------------------------- */
    64 IMAGE_EXPORT(void) transpose_si32matrix(sint32 **S, long nrl,long nrh,long ncl, long nch, sint32 **D)
    65 /* ----------------------------------------------------------------------------------------------- */
    66 {
    67         int i, j;
    68        
    69         for(i=nrl; i<=nch; i++) {
    70                 for(j=ncl; j<=nch; j++) {
    71                         D[j][i] = S[i][j];
    72                 }
    73         }
    74 }
    75 /* ----------------------------------------------------------------------------------------------- */
    76 IMAGE_EXPORT(void) transpose_ui32matrix(uint32 **S, long nrl,long nrh,long ncl, long nch, uint32 **D)
    77 /* ----------------------------------------------------------------------------------------------- */
    78 {
    79         int i, j;
    80        
    81         for(i=nrl; i<=nch; i++) {
    82                 for(j=ncl; j<=nch; j++) {
    83                         D[j][i] = S[i][j];
    84                 }
    85         }
    86 }
    87 /* ----------------------------------------------------------------------------------------- */
    88 IMAGE_EXPORT(void) transpose_f32matrix(float32 **S, long nrl,long nrh,long ncl, long nch, float32 **D)
    89 /* ----------------------------------------------------------------------------------------- */
    90 {
    91         int i, j;
    92        
    93         for(i=nrl; i<=nch; i++) {
    94                 for(j=ncl; j<=nch; j++) {
    95                         D[j][i] = S[i][j];
    96                 }
    97         }
    98 }
    99 /* -------------------------------------------------------------------------------------------- */
    100 IMAGE_EXPORT(void) transpose_dmatrix(float64 **S, long nrl,long nrh,long ncl, long nch, float64 **D)
    101 /* -------------------------------------------------------------------------------------------- */
    102 {
    103         int i, j;
    104        
    105         for(i=nrl; i<=nch; i++) {
    106                 for(j=ncl; j<=nch; j++) {
    107                         D[j][i] = S[i][j];
    108                 }
    109         }
    110 }
    111 /* ------------------------------------------------------------------------------------------- */
    112 IMAGE_EXPORT(void) transpose_rgb8matrix(rgb8 **S, long nrl,long nrh,long ncl, long nch, rgb8 **D)
    113 /* ------------------------------------------------------------------------------------------- */
    114 {
    115         int i, j;
    116        
    117         for(i=nrl; i<=nch; i++) {
    118                 for(j=ncl; j<=nch; j++) {
    119                         D[j][i] = S[i][j];
    120                 }
    121         }
    122 }
    123 /* ------------------------------------------------------------------------------- */
    124 IMAGE_EXPORT(void) transpose1_bmatrix(byte **S, long nrl,long nrh,long ncl, long nch)
    125 /* ------------------------------------------------------------------------------- */
    126 {
    127         int i, j;
    128         byte t;
    129        
    130         for(i=nrl; i<=nch; i++) {
    131                 for(j=i+1; j<=nch; j++) {
    132                         t       = S[j][i];
    133                         S[j][i] = S[i][j];
    134                         S[i][j] = t;
    135                 }
    136         }
    137 }
    138 /* ---------------------------------------------------------------------------------- */
    139 IMAGE_EXPORT(void) transpose1_si16matrix(sint16 **S, long nrl,long nrh,long ncl, long nch)
    140 /* ---------------------------------------------------------------------------------- */
    141 {
    142         int i, j;
    143         int16 t;
    144        
    145         for(i=nrl; i<=nch; i++) {
    146                 for(j=i+1; j<=nch; j++) {
    147                         t       = S[j][i];
    148                         S[j][i] = S[i][j];
    149                         S[i][j] = t;
    150                 }
    151         }
    152 }
    153 /* ------------------------------------------------------------------------------------ */
    154 IMAGE_EXPORT(void) transpose1_ui16matrix(uint16 **S, long nrl,long nrh,long ncl, long nch)
    155 /* ------------------------------------------------------------------------------------ */
    156 {
    157         int i, j;
    158         uint16 t;
    159        
    160         for(i=nrl; i<=nch; i++) {
    161                 for(j=i+1; j<=nch; j++) {
    162                         t       = S[j][i];
    163                         S[j][i] = S[i][j];
    164                         S[i][j] = t;
    165                 }
    166         }
    167 }
    168 /* ---------------------------------------------------------------------------------- */
    169 IMAGE_EXPORT(void) transpose1_si32matrix(sint32 **S, long nrl,long nrh,long ncl, long nch)
    170 /* ---------------------------------------------------------------------------------- */
    171 {
    172         int i, j;
    173         int32 t;
    174        
    175         for(i=nrl; i<=nch; i++) {
    176                 for(j=i+1; j<=nch; j++) {
    177                         t       = S[j][i];
    178                         S[j][i] = S[i][j];
    179                         S[i][j] = t;
    180                 }
    181         }
    182 }
    183 /* ------------------------------------------------------------------------------------ */
    184 IMAGE_EXPORT(void) transpose1_ui32matrix(uint32 **S, long nrl,long nrh,long ncl, long nch)
    185 /* ------------------------------------------------------------------------------------ */
    186 {
    187         int i, j;
    188         uint32 t;
    189        
    190         for(i=nrl; i<=nch; i++) {
    191                 for(j=i+1; j<=nch; j++) {
    192                         t       = S[j][i];
    193                         S[j][i] = S[i][j];
    194                         S[i][j] = t;
    195                 }
    196         }
    197 }
    198 /* ------------------------------------------------------------------------------- */
    199 IMAGE_EXPORT(void) transpose1_f32matrix(float32 **S, long nrl,long nrh,long ncl, long nch)
    200 /* ------------------------------------------------------------------------------- */
    201 {
    202         int i, j;
    203         float t;
    204        
    205         for(i=nrl; i<=nch; i++) {
    206                 for(j=i+1; j<=nch; j++) {
    207                         t       = S[j][i];
    208                         S[j][i] = S[i][j];
    209                         S[i][j] = t;
    210                 }
    211         }
    212 }
    213 /* --------------------------------------------------------------------------------- */
    214 IMAGE_EXPORT(void) transpose1_f64matrix(float64 **S, long nrl,long nrh,long ncl, long nch)
    215 /* --------------------------------------------------------------------------------- */
    216 {
    217         int i, j;
    218         double t;
    219        
    220         for(i=nrl; i<=nch; i++) {
    221                 for(j=i+1; j<=nch; j++) {
    222                         t       = S[j][i];
    223                         S[j][i] = S[i][j];
    224                         S[i][j] = t;
    225                 }
    226         }
    227 }
    228 /* ---------------------------------------------------------------------------------- */
    229 IMAGE_EXPORT(void) transpose1_rgb8matrix(rgb8 **S, long nrl,long nrh,long ncl, long nch)
    230 /* ---------------------------------------------------------------------------------- */
    231 {
    232         int i, j;
    233         rgb8 t;
    234        
    235         for(i=nrl; i<=nch; i++) {
    236                 for(j=i+1; j<=nch; j++) {
    237                         t       = S[j][i];
    238                         S[j][i] = S[i][j];
    239                         S[i][j] = t;
    240                 }
    241         }
    242 }
     64
     65transpose1_type_matrix(int8_t);
     66transpose1_type_matrix(uint8_t);
     67transpose1_type_matrix(int16_t);
     68transpose1_type_matrix(uint16_t);
     69transpose1_type_matrix(int32_t);
     70transpose1_type_matrix(uint32_t);
     71transpose1_type_matrix(int64_t);
     72transpose1_type_matrix(uint64_t);
     73transpose1_type_matrix(float);
     74transpose1_type_matrix(double);
     75transpose1_type_matrix(rgb8);
     76transpose1_type_matrix(rgbx8);
     77
     78
     79
     80
     81// Local Variables:
     82// tab-width: 4
     83// c-basic-offset: 4
     84// c-file-offsets:((innamespace . 0)(inline-open . 0))
     85// indent-tabs-mode: nil
     86// End:
     87
     88// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4
     89
  • soft/giet_vm/applications/rosenfeld/nrc2/src/nrlut.c

    r821 r823  
    1313
    1414/*
    15 * 2002/06/11 ajout des fonctions endline
    16 */
     15 * 2002/06/11 ajout des fonctions endline
     16 */
    1717#include <stdio.h>
    1818#include <stddef.h>
     
    2828#include "nrlut.h"
    2929
    30 /* ----------------------------------------------------------------------- */
    31 IMAGE_EXPORT(void) init_blut(byte *v, int nl, int nh, int n0, int n1, byte k)
    32 /* ----------------------------------------------------------------------- */
    33 {
    34         int i;
    35        
    36         if(nl<=nh) {
    37                 // normal case
    38                 for(i=nl;   i< n0; i++) v[i] = 0;
    39                 for(i=n0;   i<=n1; i++) v[i] = k;
    40                 for(i=n1+1; i<nh; i++)  v[i] = 0;
    41         } else {
    42                 for(i=nl;   i< n1; i++) v[i] = k;
    43                 for(i=n1;   i<=n0; i++) v[i] = 0;
    44                 for(i=n1+1; i<nh;  i++) v[i] = k;
    45         }
    46 }
    47 /* ------------------------------------------------------------------------ */
    48 IMAGE_EXPORT(void) init_ui8lut(uint8 *v, int nl, int nh, int n0, int n1, uint8 k)
    49 /* ------------------------------------------------------------------------ */
    50 {
    51         int i;
    52        
    53         if(nl<=nh) {
    54                 // normal case
    55                 for(i=nl;   i< n0; i++) v[i] = 0;
    56                 for(i=n0;   i<=n1; i++) v[i] = k;
    57                 for(i=n1+1; i<nh; i++)  v[i] = 0;
    58         } else {
    59                 for(i=nl;   i< n1; i++) v[i] = k;
    60                 for(i=n1;   i<=n0; i++) v[i] = 0;
    61                 for(i=n1+1; i<nh;  i++) v[i] = k;
    62         }
    63 }
    64 /* --------------------------------------------------------------------------- */
    65 IMAGE_EXPORT(void) init_ui16lut(uint16 *v, int nl, int nh, int n0, int n1, uint16 k)
    66 /* --------------------------------------------------------------------------- */
    67 {
    68         int i;
    69        
    70         if(nl<=nh) {
    71                 // normal case
    72                 for(i=nl;   i< n0; i++) v[i] = 0;
    73                 for(i=n0;   i<=n1; i++) v[i] = k;
    74                 for(i=n1+1; i<=nh; i++) v[i] = 0;
    75         } else {
    76                 for(i=nl;   i< n1; i++) v[i] = k;
    77                 for(i=n1;   i<=n0; i++) v[i] = 0;
    78                 for(i=n1+1; i<=nh; i++) v[i] = k;
    79         }
    80 }
    81 /* --------------------------------------------------------------------------- */
    82 IMAGE_EXPORT(void) init_si16lut(sint16 *v, int nl, int nh, int n0, int n1, sint16 k)
    83 /* --------------------------------------------------------------------------- */
    84 {
    85         int i;
    86        
    87         if(nl<=nh) {
    88                 // normal case
    89                 for(i=nl;   i< n0; i++) v[i] = 0;
    90                 for(i=n0;   i<=n1; i++) v[i] = k;
    91                 for(i=n1+1; i<=nh; i++) v[i] = 0;
    92         } else {
    93                 for(i=nl;   i< n1; i++) v[i] = k;
    94                 for(i=n1;   i<=n0; i++) v[i] = 0;
    95                 for(i=n1+1; i<=nh; i++) v[i] = k;
    96         }
    97 }
    98 /* --------------------------------------------------------------------------- */
    99 IMAGE_EXPORT(void) init_ui32lut(uint32 *v, int nl, int nh, int n0, int n1, uint32 k)
    100 /* --------------------------------------------------------------------------- */
    101 {
    102         int i;
    103        
    104         if(nl<=nh) {
    105                 // normal case
    106                 for(i=nl;   i< n0; i++) v[i] = 0;
    107                 for(i=n0;   i<=n1; i++) v[i] = k;
    108                 for(i=n1+1; i<=nh; i++) v[i] = 0;
    109         } else {
    110                 for(i=nl;   i< n1; i++) v[i] = k;
    111                 for(i=n1;   i<=n0; i++) v[i] = 0;
    112                 for(i=n1+1; i<=nh; i++) v[i] = k;
    113         }
    114 }
    115 /* --------------------------------------------------------------------------- */
    116 IMAGE_EXPORT(void) init_i32lut(sint32 *v, int nl, int nh, int n0, int n1, sint32 k)
    117 /* --------------------------------------------------------------------------- */
    118 {
    119         int i;
    120        
    121         if(nl<=nh) {
    122                 // normal case
    123                 for(i=nl;   i< n0; i++) v[i] = 0;
    124                 for(i=n0;   i<=n1; i++) v[i] = k;
    125                 for(i=n1+1; i<=nh; i++) v[i] = 0;
    126         } else {
    127                 for(i=nl;   i< n1; i++) v[i] = k;
    128                 for(i=n1;   i<=n0; i++) v[i] = 0;
    129                 for(i=n1+1; i<=nh; i++) v[i] = k;
    130         }
    131 }
    132 /* -------------------------------------------------------------------------- */
    133 IMAGE_EXPORT(void) init_rgb8lut(rgb8 *v, int nl, int nh, int n0, int n1, rgb8 k)
    134 /* -------------------------------------------------------------------------- */
    135 {
    136         int i;
    137        
    138         if(nl<=nh) {
    139                 // normal case
    140                 for(i=nl;   i< n0; i++) { v[i].r = 0;   v[i].g = 0;   v[i].b = 0;}
    141                 for(i=n0;   i<=n1; i++) { v[i].r = k.r; v[i].g = k.g; v[i].b = k.b;}
    142                 for(i=n1+1; i<=nh; i++)  { v[i].r = 0;   v[i].g = 0;  v[i].b = 0;}
    143         } else {
    144                 for(i=nl;   i< n1; i++) { v[i].r = k.r; v[i].g = k.g; v[i].b = k.b;}
    145                 for(i=n1;   i<=n0; i++) { v[i].r = 0;   v[i].g = 0;   v[i].b = 0;}
    146                 for(i=n1+1; i<=nh; i++) { v[i].r = k.r; v[i].g = k.g; v[i].b = k.b;}
    147         }
    148 }
    149 /* ------------------------------------------------------------------------------------------- */
    150 IMAGE_EXPORT(void) lut_bmatrix(byte **S, long nrl,long nrh,long ncl, long nch, byte *L, byte **D)
    151 /* ------------------------------------------------------------------------------------------- */
    152 {
    153     int i, j;
    154 
    155     for(i=nrl; i<=nrh; i++) {
    156         for(j=ncl; j<=nch; j++) {
    157             D[i][j] = L[(int)S[i][j]];
    158         }
    159     }
    160 }
    161 /* -------------------------------------------------------------------------------------------- */
    162 IMAGE_EXPORT(void) lut_ui8matrix(uint8 **S, long nrl,long nrh,long ncl, long nch, uint8 *L, uint8 **D)
    163 /* -------------------------------------------------------------------------------------------- */
    164 {
    165     int i, j;
    166    
    167     for(i=nrl; i<=nrh; i++) {
    168         for(j=ncl; j<=nch; j++) {
    169             D[i][j] = L[(int)S[i][j]];
    170         }
    171     }
    172 }
    173 /* -------------------------------------------------------------------------------------------- */
    174 IMAGE_EXPORT(void) lut_si8matrix(sint8 **S, long nrl,long nrh,long ncl, long nch, sint8 *L, sint8 **D)
    175 /* -------------------------------------------------------------------------------------------- */
    176 {
    177     int i, j;
    178    
    179     for(i=nrl; i<=nrh; i++) {
    180         for(j=ncl; j<=nch; j++) {
    181             D[i][j] = L[(int)S[i][j]];
    182         }
    183     }
    184 }
    185 /* -------------------------------------------------------------------------------------------------- */
    186 IMAGE_EXPORT(void) lut_ui16matrix(uint16 **S, long nrl, long nrh, long ncl, long nch, uint16 *L, uint16 **D)
    187 /* -------------------------------------------------------------------------------------------------- */
    188 {
    189     int i, j;
    190    
    191     for(i=nrl; i<=nrh; i++) {
    192         for(j=ncl; j<=nch; j++) {
    193             D[i][j] = L[(int)S[i][j]];
    194         }
    195     }
    196 }
    197 /* -------------------------------------------------------------------------------------------------- */
    198 IMAGE_EXPORT(void) lut_si16matrix(sint16 **S, long nrl, long nrh, long ncl, long nch, sint16 *L, sint16 **D)
    199 /* -------------------------------------------------------------------------------------------------- */
    200 {
    201     int i, j;
    202    
    203     for(i=nrl; i<=nrh; i++) {
    204         for(j=ncl; j<=nch; j++) {
    205             D[i][j] = L[(int)S[i][j]];
    206         }
    207     }
    208 }
    209 /* -------------------------------------------------------------------------------------------------- */
    210 IMAGE_EXPORT(void) lut_ui32matrix(uint32 **S, long nrl, long nrh, long ncl, long nch, uint32 *L, uint32 **D)
    211 /* -------------------------------------------------------------------------------------------------- */
    212 {
    213     int i, j;
    214    
    215     for(i=nrl; i<=nrh; i++) {
    216         for(j=ncl; j<=nch; j++) {
    217             D[i][j] = L[(int)S[i][j]];
    218         }
    219     }
    220 }
    221 /* -------------------------------------------------------------------------------------------------- */
    222 IMAGE_EXPORT(void) lut_si32matrix(sint32 **S, long nrl, long nrh, long ncl, long nch, sint32 *L, sint32 **D)
    223 /* -------------------------------------------------------------------------------------------------- */
    224 {
    225     int i, j;
    226    
    227     for(i=nrl; i<=nrh; i++) {
    228         for(j=ncl; j<=nch; j++) {
    229             D[i][j] = L[(int)S[i][j]];
    230         }
    231     }
    232 }
    233 /* ------------------------------------------------------------------------------------------------ */
    234 IMAGE_EXPORT(void) lut_rgb8matrix(rgb8 **S, long nrl, long nrh, long ncl, long nch, rgb8 *L, rgb8 **D)
    235 /* ------------------------------------------------------------------------------------------------ */
    236 {
    237         int i, j;
    238        
    239         for(i=nrl; i<=nrh; i++) {
    240                 for(j=ncl; j<=nch; j++) {
    241                         D[i][j].r = L[S[i][j].r].r;
    242                         D[i][j].g = L[S[i][j].g].g;
    243                         D[i][j].b = L[S[i][j].b].b;
    244                 }
    245         }
    246 }
    247 /* --------------------------------------------------------------------------------------------------------- */
    248 IMAGE_EXPORT(void) lut_ui16matrix_ui8matrix(uint16 **S, long nrl, long nrh, long ncl, long nch, uint8 *L, uint8 **D)
    249 /* --------------------------------------------------------------------------------------------------------- */
    250 {
    251         int i, j;
    252        
    253         for(i=nrl; i<=nrh; i++) {
    254                 for(j=ncl; j<=nch; j++) {
    255                         D[i][j] = L[(int)S[i][j]];
    256                 }
    257         }
    258 }
    259 /* --------------------------------------------------------------------------------------------------------- */
    260 IMAGE_EXPORT(void) lut_ui32matrix_ui16matrix(uint32 **S, long nrl, long nrh, long ncl, long nch, uint16 *L, uint16 **D)
    261 /* --------------------------------------------------------------------------------------------------------- */
    262 {
    263         int i, j;
    264        
    265         for(i=nrl; i<=nrh; i++) {
    266                 for(j=ncl; j<=nch; j++) {
    267                         D[i][j] = L[(int)S[i][j]];
    268                 }
    269         }
    270 }
    271 /* ---------------------------------------------------------------------------- */
    272 IMAGE_EXPORT(void) histogram_bmatrix(byte **S, long nrl, long nrh, long ncl, long nch, int32 *H)
    273 /* ---------------------------------------------------------------------------- */
    274 {
    275         int i, j;
    276         byte *Si;
    277        
    278         for(i=nrl; i<=nrh; i++) {
    279                 Si = S[i];
    280                 for(j=ncl; j<=nch; j++) {
    281                         H[(int) Si[j]]++;
    282                 }
    283         }
    284 }
    285 /* --------------------------------------------------------------------------------- */
    286 IMAGE_EXPORT(void) histogram_ui16matrix(uint16 **S, long nrl, long nrh, long ncl, long nch, int32 *H)
    287 /* --------------------------------------------------------------------------------- */
    288 {
    289         int i, j;
    290         uint16 *Si;
    291        
    292         for(i=nrl; i<=nrh; i++) {
    293                 Si = S[i];
    294                 for(j=ncl; j<=nch; j++) {
    295                         H[Si[j]]++;
    296                 }
    297         }
    298 }
    299 /* ------------------------------------------------------------------------------- */
    300 IMAGE_EXPORT(void) histogram_rgb8matrix(rgb8 **S, long nrl, long nrh, long ncl, long nch, rgb32 *H)
    301 /* ------------------------------------------------------------------------------- */
    302 {
    303         int i, j;
    304         rgb8 *Si;
    305         int r, b, g;
     30
     31#undef init_type_lut
     32#define init_type_lut(t) \
     33void short_name(t,init_,lut)(t * v, int32_t nl, int32_t nh, int32_t n0, int32_t n1, t k) \
     34{                                                \
     35    if (nl <= nh) {                              \
     36        for (int32_t i = nl; i < n0; i++) {      \
     37            v[i] = 0;                            \
     38        }                                        \
     39        for (int32_t i = n0; i <= n1; i++) {     \
     40            v[i] = k;                            \
     41        }                                        \
     42        for (int32_t i = n1 + 1; i <= nh; i++) { \
     43            v[i] = 0;                            \
     44        }                                        \
     45    }                                            \
     46    else {                                       \
     47        for (int32_t i = nl; i < n1; i++) {      \
     48            v[i] = k;                            \
     49        }                                        \
     50        for (int32_t i = n1; i <= n0; i++) {     \
     51            v[i] = 0;                            \
     52        }                                        \
     53        for (int32_t i = n1 + 1; i <= nh; i++) { \
     54            v[i] = k;                            \
     55        }                                        \
     56    }                                            \
     57}
     58
     59
     60init_type_lut(int8_t);
     61init_type_lut(uint8_t);
     62init_type_lut(int16_t);
     63init_type_lut(uint16_t);
     64init_type_lut(int32_t);
     65init_type_lut(uint32_t);
     66
     67
     68
     69void init_rgb8lut(rgb8 * v, int32_t nl, int32_t nh, int32_t n0, int32_t n1, rgb8 k)
     70{
     71    if (nl <= nh) {
     72        // normal case
     73        for (int32_t i = nl; i < n0; i++) {
     74            v[i].r = 0;
     75            v[i].g = 0;
     76            v[i].b = 0;
     77        }
     78        for (int32_t i = n0; i <= n1; i++) {
     79            v[i].r = k.r;
     80            v[i].g = k.g;
     81            v[i].b = k.b;
     82        }
     83        for (int32_t i = n1 + 1; i <= nh; i++) {
     84            v[i].r = 0;
     85            v[i].g = 0;
     86            v[i].b = 0;
     87        }
     88    }
     89    else {
     90        for (int32_t i = nl; i < n1; i++) {
     91            v[i].r = k.r;
     92            v[i].g = k.g;
     93            v[i].b = k.b;
     94        }
     95        for (int32_t i = n1; i <= n0; i++) {
     96            v[i].r = 0;
     97            v[i].g = 0;
     98            v[i].b = 0;
     99        }
     100        for (int32_t i = n1 + 1; i <= nh; i++) {
     101            v[i].r = k.r;
     102            v[i].g = k.g;
     103            v[i].b = k.b;
     104        }
     105    }
     106}
     107
     108
     109#undef lut_type_matrix
     110#define lut_type_matrix(t) \
     111void short_name(t,lut_,matrix)(t ** S, int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch, t * L, t ** D) \
     112{                                              \
     113    for (int32_t i = nrl; i <= nrh; i++) {     \
     114        for (int32_t j = ncl; j <= nch; j++) { \
     115            D[i][j] = L[(int32_t) S[i][j]];    \
     116        }                                      \
     117    }                                          \
     118}
     119
     120lut_type_matrix(int8_t);
     121lut_type_matrix(uint8_t);
     122lut_type_matrix(int16_t);
     123lut_type_matrix(uint16_t);
     124lut_type_matrix(int32_t);
     125lut_type_matrix(uint32_t);
     126
     127
     128
     129void lut_rgb8matrix(rgb8 ** S, int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch, rgb8 * L, rgb8 ** D)
     130{
     131    for (int32_t i = nrl; i <= nrh; i++) {
     132        for (int32_t j = ncl; j <= nch; j++) {
     133            D[i][j].r = L[S[i][j].r].r;
     134            D[i][j].g = L[S[i][j].g].g;
     135            D[i][j].b = L[S[i][j].b].b;
     136        }
     137    }
     138}
     139
     140
     141void lut_ui16matrix_ui8matrix(uint16_t ** S, int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch, uint8_t * L, uint8_t ** D)
     142{
     143    for (int32_t i = nrl; i <= nrh; i++) {
     144        for (int32_t j = ncl; j <= nch; j++) {
     145            D[i][j] = L[(int32_t) S[i][j]];
     146        }
     147    }
     148}
     149
     150void lut_i16matrix_i8matrix(int16_t ** S, int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch, uint8_t * L, int8_t ** D)
     151{
     152    for (int32_t i = nrl; i <= nrh; i++) {
     153        for (int32_t j = ncl; j <= nch; j++) {
     154            D[i][j] = L[(int32_t) S[i][j]];
     155        }
     156    }
     157}
     158
     159void lut_ui32matrix_ui16matrix(uint32_t ** S, int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch, uint16_t * L, uint16_t ** D)
     160{
     161    for (int32_t i = nrl; i <= nrh; i++) {
     162        for (int32_t j = ncl; j <= nch; j++) {
     163            D[i][j] = L[(int32_t) S[i][j]];
     164        }
     165    }
     166}
     167
     168void lut_i32matrix_i16matrix(int32_t ** S, int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch, uint16_t * L, int16_t ** D)
     169{
     170    for (int32_t i = nrl; i <= nrh; i++) {
     171        for (int32_t j = ncl; j <= nch; j++) {
     172            D[i][j] = L[(int32_t) S[i][j]];
     173        }
     174    }
     175}
     176
     177
     178#undef histogram_type_matrix
     179#define histogram_type_matrix(t) \
     180void short_name(t,histogram_,matrix)(t ** S, int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch, t * H) \
     181{                                              \
     182    t * Si;                                    \
     183    for (int32_t i = nrl; i <= nrh; i++) {     \
     184        Si = S[i];                             \
     185        for (int32_t j = ncl; j <= nch; j++) { \
     186            H[(int32_t) Si[j]]++;              \
     187        }                                      \
     188    }                                          \
     189}
     190
     191histogram_type_matrix(int8_t);
     192histogram_type_matrix(uint8_t);
     193histogram_type_matrix(int16_t);
     194histogram_type_matrix(uint16_t);
     195histogram_type_matrix(int32_t);
     196histogram_type_matrix(uint32_t);
     197
     198
     199
     200void histogram_rgb8matrix(rgb8 ** S, int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch, rgb32 * H)
     201{
     202    rgb8 * Si;
     203    int r, b, g;
    306204    (void) Si;
    307        
    308         //FUNCTION_NAME("Histogram_rgbmatrix");
    309        
    310         for(i=nrl; i<=nrh; i++) {
    311                 Si = S[i];
    312                 //PROGRESS_INFO(function_name, i, nrl, nrh);
    313                 for(j=ncl; j<=nch; j++) {
    314                        
    315                         //H[Si[j].r].r++;
    316                         //H[Si[j].g].g++;
    317                         //H[Si[j].b].b++;
    318                        
    319                         r = S[i][j].r;
    320                         g = S[i][j].g;
    321                         b = S[i][j].b;
    322                        
    323                         H[r].r++;
    324                         H[g].g++;
    325                         H[b].b++;
    326                 }
    327         }
    328        
    329         //END;
    330         return;
    331 }
     205
     206
     207    for (int32_t i = nrl; i <= nrh; i++) {
     208        Si = S[i];
     209        for (int32_t j = ncl; j <= nch; j++) {
     210            r = S[i][j].r;
     211            g = S[i][j].g;
     212            b = S[i][j].b;
     213
     214            H[r].r++;
     215            H[g].g++;
     216            H[b].b++;
     217        }
     218    }
     219    return;
     220}
     221
     222// Local Variables:
     223// tab-width: 4
     224// c-basic-offset: 4
     225// c-file-offsets:((innamespace . 0)(inline-open . 0))
     226// indent-tabs-mode: nil
     227// End:
     228
     229// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4
     230
  • soft/giet_vm/applications/rosenfeld/nrc2/src/nrmem1.c

    r772 r823  
    3030 * -----------
    3131 */
    32 /* ---------------------------------------------------------------- */
    33 IMAGE_EXPORT(void) dup_si8vector(sint8 *X, long nl, long nh, sint8 *Y)
    34 /* ---------------------------------------------------------------- */
    35 {
    36     int i;
    37     for(i=nl; i<=nh; i++) {
    38         Y[i] = X[i];
    39     }
    40 }
    41 /* ---------------------------------------------------------------- */
    42 IMAGE_EXPORT(void) dup_ui8vector(uint8 *X, long nl, long nh, uint8 *Y)
    43 /* ---------------------------------------------------------------- */
    44 {
    45     int i;
    46     for(i=nl; i<=nh; i++) {
    47         Y[i] = X[i];
    48     }
    49 }
    50 /* ------------------------------------------------------------------- */
    51 IMAGE_EXPORT(void) dup_si16vector(sint16 *X, long nl, long nh, sint16 *Y)
    52 /* ------------------------------------------------------------------- */
    53 {
    54     int i;
    55     for(i=nl; i<=nh; i++) {
    56         Y[i] = X[i];
    57     }
    58 }
    59 /* ------------------------------------------------------------------- */
    60 IMAGE_EXPORT(void) dup_ui16vector(uint16 *X, long nl, long nh, uint16 *Y)
    61 /* ------------------------------------------------------------------- */
    62 {
    63     int i;
    64     for(i=nl; i<=nh; i++) {
    65         Y[i] = X[i];
    66     }
    67 }
    68 /* -------------------------------------------------------------------- */
    69 IMAGE_EXPORT(void) dup_si32vector(sint32 *X, long nl, long nh, sint32 *Y)
    70 /* -------------------------------------------------------------------- */
    71 {
    72     int i;
    73     for(i=nl; i<=nh; i++) {
    74         Y[i] = X[i];
    75     }
    76 }
    77 /* ------------------------------------------------------------------- */
    78 IMAGE_EXPORT(void) dup_ui32vector(uint32 *X, long nl, long nh, uint32 *Y)
    79 /* ------------------------------------------------------------------- */
    80 {
    81     int i;
    82     for(i=nl; i<=nh; i++) {
    83         Y[i] = X[i];
    84     }
    85 }
    86 /* -------------------------------------------------------------------- */
    87 IMAGE_EXPORT(void) dup_si64vector(sint64 *X, long nl, long nh, sint64 *Y)
    88 /* -------------------------------------------------------------------- */
    89 {
    90     int i;
    91     for(i=nl; i<=nh; i++) {
    92         Y[i] = X[i];
    93     }
    94 }
    95 /* ------------------------------------------------------------------- */
    96 IMAGE_EXPORT(void) dup_ui64vector(uint64 *X, long nl, long nh, uint64 *Y)
    97 /* ------------------------------------------------------------------- */
    98 {
    99     int i;
    100     for(i=nl; i<=nh; i++) {
    101         Y[i] = X[i];
    102     }
    103 }
    104 /* -------------------------------------------------------------------- */
    105 IMAGE_EXPORT(void) dup_f32vector(float32 *X, long nl, long nh, float32 *Y)
    106 /* -------------------------------------------------------------------- */
    107 {
    108     int i;
    109     for(i=nl; i<=nh; i++) {
    110         Y[i] = X[i];
    111     }
    112 }
    113 /* -------------------------------------------------------------------- */
    114 IMAGE_EXPORT(void) dup_f64vector(float64 *X, long nl, long nh, float64 *Y)
    115 /* -------------------------------------------------------------------- */
    116 {
    117     int i;
    118     for(i=nl; i<=nh; i++) {
    119         Y[i] = X[i];
    120     }
    121 }
    122 /* --------------------------------------------------------------- */
    123 IMAGE_EXPORT(void) dup_rgb8vector(rgb8 *X, long nl, long nh, rgb8 *Y)
    124 /* --------------------------------------------------------------- */
    125 {
    126     int i;
    127     for(i=nl; i<=nh; i++) {
    128         Y[i] = X[i];
    129     }
    130 }
    131 /* ------------------------------------------------------------------ */
    132 IMAGE_EXPORT(void) dup_rgbx8vector(rgbx8 *X, long nl, long nh, rgbx8 *Y)
    133 /* ------------------------------------------------------------------ */
    134 {
    135     int i;
    136     for(i=nl; i<=nh; i++) {
    137         Y[i] = X[i];
    138     }
    139 }
     32
     33
     34#undef dup_type_vector
     35#define dup_type_vector(t) \
     36void short_name(t,dup_,vector)(t * X, int32_t nl, int32_t nh, t * Y) \
     37{                                        \
     38    for (int32_t i = nl; i <= nh; i++) { \
     39        Y[i] = X[i];                     \
     40    }                                    \
     41}
     42
     43dup_type_vector(int8_t);
     44dup_type_vector(uint8_t);
     45dup_type_vector(int16_t);
     46dup_type_vector(uint16_t);
     47dup_type_vector(int32_t);
     48dup_type_vector(uint32_t);
     49dup_type_vector(int64_t);
     50dup_type_vector(uint64_t);
     51dup_type_vector(float);
     52dup_type_vector(double);
     53dup_type_vector(rgb8);
     54dup_type_vector(rgbx8);
     55
     56
    14057/*
    14158 * --------------------
     
    14360 * --------------------
    14461 */
    145 /* -------------------------------------------------------------------------------------- */
    146 IMAGE_EXPORT(void) split_rgb8vector(rgb8 *X, long nl, long nh, uint8 *R, uint8 *G, uint8 *B)
    147 /* -------------------------------------------------------------------------------------- */
    148 {
    149         long i;
    150         rgb8 x;
    151         for(i=nl; i<=nh; i++) {
    152                 x    = X[i];
    153                 R[i] = x.r;
    154                 G[i] = x.g;
    155                 B[i] = x.b;
    156         }
    157 }
    158 /* ------------------------------------------------------------------------------------------- */
    159 IMAGE_EXPORT(void) split_rgb32vector(rgb32 *X, long nl, long nh, uint32 *R, uint32 *G, uint32 *B)
    160 /* ------------------------------------------------------------------------------------------- */
    161 {
    162         long i;
    163         for(i=nl; i<=nh; i++) {
    164                 R[i] = X[i].r;
    165                 G[i] = X[i].g;
    166                 B[i] = X[i].b;
    167         }
    168 }
    169 /* -------------------------------------------------------------------------------------- */
    170 IMAGE_EXPORT(void) merge_rgb8vector(uint8 *R, uint8 *G, uint8 *B, long nl, long nh, rgb8 *X)
    171 /* -------------------------------------------------------------------------------------- */
    172 {
    173         long i;
    174         for(i=nl; i<=nh; i++) {
    175                 X[i].r = R[i];
    176                 X[i].g = G[i];
    177                 X[i].b = B[i];
    178         }
    179 }
    180 /* ------------------------------------------------------------------------------------------- */
    181 IMAGE_EXPORT(void) merge_rgb32vector(uint32 *R, uint32 *G, uint32 *B, long nl, long nh, rgb32 *X)
    182 /* ------------------------------------------------------------------------------------------- */
    183 {
    184         long i;
    185         for(i=nl; i<=nh; i++) {
    186                 X[i].r = R[i];
    187                 X[i].g = G[i];
    188                 X[i].b = B[i];
    189         }
    190 }
    191 
    192 /* ---------------- */
    193 /* -- Convertion -- */
    194 /* ---------------- */
    195 
    196 /* -------------------------------------------------------------------------------- */
    197 IMAGE_EXPORT(void) convert_si8vector_si16vector(sint8 *X, long nl, long nh, sint16 *Y)
    198 /* -------------------------------------------------------------------------------- */
    199 {
    200     long i;
    201     for(i=nl; i<=nh; i++)
    202         Y[i] = (sint16) X[i];
    203 }
    204 /* -------------------------------------------------------------------------------- */
    205 IMAGE_EXPORT(void) convert_si8vector_si32vector(sint8 *X, long nl, long nh, sint32 *Y)
    206 /* -------------------------------------------------------------------------------- */
    207 {
    208     long i;
    209     for(i=nl; i<=nh; i++)
    210         Y[i] = (sint32) X[i];
    211 }
    212 /* -------------------------------------------------------------------------------- */
    213 IMAGE_EXPORT(void) convert_si8vector_f32vector(sint8 *X, long nl, long nh, float32 *Y)
    214 /* -------------------------------------------------------------------------------- */
    215 {
    216     long i;
    217     for(i=nl; i<=nh; i++)
    218         Y[i] = (float32) X[i];
    219 }
    220 /* -------------------------------------------------------------------------------- */
    221 IMAGE_EXPORT(void) convert_si8vector_f64vector(sint8 *X, long nl, long nh, float64 *Y)
    222 /* -------------------------------------------------------------------------------- */
    223 {
    224     long i;
    225     for(i=nl; i<=nh; i++)
    226         Y[i] = (float64) X[i];
    227 }
    228 /* -------------------------------------------------------------------------------- */
    229 IMAGE_EXPORT(void) convert_ui8vector_ui16vector(uint8 *X, long nl, long nh, uint16 *Y)
    230 /* -------------------------------------------------------------------------------- */
    231 {
    232     long i;
    233     for(i=nl; i<=nh; i++)
    234         Y[i] = (uint16) X[i];
    235 }
    236 /* -------------------------------------------------------------------------------- */
    237 IMAGE_EXPORT(void) convert_ui8vector_ui32vector(uint8 *X, long nl, long nh, uint32 *Y)
    238 /* -------------------------------------------------------------------------------- */
    239 {
    240     long i;
    241     for(i=nl; i<=nh; i++)
    242         Y[i] = (uint32) X[i];
    243 }
    244 /* -------------------------------------------------------------------------------- */
    245 IMAGE_EXPORT(void) convert_ui8vector_f32vector(uint8 *X, long nl, long nh, float32 *Y)
    246 /* -------------------------------------------------------------------------------- */
    247 {
    248     long i;
    249     for(i=nl; i<=nh; i++)
    250         Y[i] = (float32) X[i];
    251 }
    252 /* -------------------------------------------------------------------------------- */
    253 IMAGE_EXPORT(void) convert_ui8vector_f64vector(uint8 *X, long nl, long nh, float64 *Y)
    254 /* -------------------------------------------------------------------------------- */
    255 {
    256     long i;
    257     for(i=nl; i<=nh; i++)
    258         Y[i] = (float64) X[i];
    259 }
    260 /* ------------------------------------------------------------------------------ */
    261 IMAGE_EXPORT(void) convert_ui8vector_rgb8vector(uint8 *X, long nl, long nh, rgb8 *Y)
    262 /* ------------------------------------------------------------------------------ */
    263 {
    264     long i;
    265     for(i=nl; i<=nh; i++) {
     62
     63
     64void split_rgb8vector(rgb8 * X, int32_t nl, int32_t nh, uint8_t * R, uint8_t * G, uint8_t * B)
     65{
     66    for (int32_t i = nl; i <= nh; i++) {
     67        R[i] = X[i].r;
     68        G[i] = X[i].g;
     69        B[i] = X[i].b;
     70    }
     71}
     72
     73void split_rgb32vector(rgb32 * X, int32_t nl, int32_t nh, uint32_t * R, uint32_t * G, uint32_t * B)
     74{
     75    for (int32_t i = nl; i <= nh; i++) {
     76        R[i] = X[i].r;
     77        G[i] = X[i].g;
     78        B[i] = X[i].b;
     79    }
     80}
     81
     82void merge_rgb8vector(uint8_t * R, uint8_t * G, uint8_t * B, int32_t nl, int32_t nh, rgb8 * X)
     83{
     84    for (int32_t i = nl; i <= nh; i++) {
     85        X[i].r = R[i];
     86        X[i].g = G[i];
     87        X[i].b = B[i];
     88    }
     89}
     90
     91
     92void merge_rgb32vector(uint32_t * R, uint32_t * G, uint32_t * B, int32_t nl, int32_t nh, rgb32 * X)
     93{
     94    for (int32_t i = nl; i <= nh; i++) {
     95        X[i].r = R[i];
     96        X[i].g = G[i];
     97        X[i].b = B[i];
     98    }
     99}
     100
     101/* ---------------- */
     102/* -- Conversion -- */
     103/* ---------------- */
     104
     105#undef convert_type1_vector_type2_vector
     106#define convert_type1_vector_type2_vector(t1, t2) \
     107void short_name(t1,convert_,short_name(t2,vector_,vector))(t1 * X, int32_t nl, int32_t nh, t2 * Y) \
     108{                                        \
     109    for (int32_t i = nl; i <= nh; i++) { \
     110        Y[i] = (t2) X[i];                \
     111    }                                    \
     112}
     113
     114convert_type1_vector_type2_vector(int8_t,int16_t);
     115convert_type1_vector_type2_vector(int8_t,int32_t);
     116convert_type1_vector_type2_vector(int8_t,float);
     117convert_type1_vector_type2_vector(int8_t,double);
     118convert_type1_vector_type2_vector(uint8_t,uint16_t);
     119convert_type1_vector_type2_vector(uint8_t,uint32_t);
     120convert_type1_vector_type2_vector(uint8_t,float);
     121convert_type1_vector_type2_vector(uint8_t,double);
     122convert_type1_vector_type2_vector(int16_t,int32_t);
     123convert_type1_vector_type2_vector(int16_t,float);
     124convert_type1_vector_type2_vector(int16_t,double);
     125convert_type1_vector_type2_vector(uint16_t,uint32_t);
     126convert_type1_vector_type2_vector(uint16_t,float);
     127convert_type1_vector_type2_vector(uint16_t,double);
     128convert_type1_vector_type2_vector(int32_t,float);
     129convert_type1_vector_type2_vector(int32_t,double);
     130convert_type1_vector_type2_vector(uint32_t,float);
     131convert_type1_vector_type2_vector(uint32_t,double);
     132convert_type1_vector_type2_vector(int16_t,int8_t);
     133convert_type1_vector_type2_vector(uint16_t,uint8_t);
     134convert_type1_vector_type2_vector(int32_t,int8_t);
     135convert_type1_vector_type2_vector(int32_t,int16_t);
     136convert_type1_vector_type2_vector(uint32_t,uint8_t);
     137convert_type1_vector_type2_vector(uint32_t,uint16_t);
     138convert_type1_vector_type2_vector(float,int8_t);
     139convert_type1_vector_type2_vector(float,uint8_t);
     140convert_type1_vector_type2_vector(float,int16_t);
     141convert_type1_vector_type2_vector(float,uint16_t);
     142convert_type1_vector_type2_vector(float,int32_t);
     143convert_type1_vector_type2_vector(float,uint32_t);
     144convert_type1_vector_type2_vector(double,int8_t);
     145convert_type1_vector_type2_vector(double,uint8_t);
     146convert_type1_vector_type2_vector(double,int16_t);
     147convert_type1_vector_type2_vector(double,uint16_t);
     148convert_type1_vector_type2_vector(double,int32_t);
     149convert_type1_vector_type2_vector(double,uint32_t);
     150convert_type1_vector_type2_vector(double,float);
     151
     152
     153
     154
     155
     156
     157
     158void convert_ui8vector_rgb8vector(uint8_t * X, int32_t nl, int32_t nh, rgb8 * Y)
     159{
     160    for (int32_t i = nl; i <= nh; i++) {
    266161        Y[i].r = X[i];
    267162        Y[i].g = X[i];
     
    269164    }
    270165}
    271 /* -------------------------------------------------------------------------------- */
    272 IMAGE_EXPORT(void) convert_ui8vector_rgbx8vector(uint8 *X, long nl, long nh, rgbx8 *Y)
    273 /* -------------------------------------------------------------------------------- */
    274 {
    275     long i;
    276     for(i=nl; i<=nh; i++) {
     166
     167void convert_ui8vector_rgbx8vector(uint8_t * X, int32_t nl, int32_t nh, rgbx8 * Y)
     168{
     169    for (int32_t i = nl; i <= nh; i++) {
    277170        Y[i].r = X[i];
    278171        Y[i].g = X[i];
     
    281174    }
    282175}
    283 /* ---------------------------------------------------------------------------------- */
    284 IMAGE_EXPORT(void) convert_si16vector_si32vector(sint16 *X, long nl, long nh, sint32 *Y)
    285 /* ---------------------------------------------------------------------------------- */
    286 {
    287     long i;
    288     for(i=nl; i<=nh; i++)
    289         Y[i] = (sint32) X[i];
    290 }
    291 /* ---------------------------------------------------------------------------------- */
    292 IMAGE_EXPORT(void) convert_si16vector_f32vector(sint16 *X, long nl, long nh, float32 *Y)
    293 /* ---------------------------------------------------------------------------------- */
    294 {
    295     long i;
    296     for(i=nl; i<=nh; i++)
    297         Y[i] = (float32) X[i];
    298 }
    299 /* ---------------------------------------------------------------------------------- */
    300 IMAGE_EXPORT(void) convert_si16vector_f64vector(sint16 *X, long nl, long nh, float64 *Y)
    301 /* ---------------------------------------------------------------------------------- */
    302 {
    303     long i;
    304     for(i=nl; i<=nh; i++)
    305         Y[i] = (float64) X[i];
    306 }
    307 
    308 /* ---------------------------------------------------------------------------------- */
    309 IMAGE_EXPORT(void) convert_ui16vector_ui32vector(uint16 *X, long nl, long nh, uint32 *Y)
    310 /* ---------------------------------------------------------------------------------- */
    311 {
    312     long i;
    313     for(i=nl; i<=nh; i++)
    314         Y[i] = (uint32) X[i];
    315 }
    316 /* ---------------------------------------------------------------------------------- */
    317 IMAGE_EXPORT(void) convert_ui16vector_f32vector(uint16 *X, long nl, long nh, float32 *Y)
    318 /* ---------------------------------------------------------------------------------- */
    319 {
    320     long i;
    321     for(i=nl; i<=nh; i++)
    322         Y[i] = (float32) X[i];
    323 }
    324 /* ---------------------------------------------------------------------------------- */
    325 IMAGE_EXPORT(void) convert_ui16vector_f64vector(uint16 *X, long nl, long nh, float64 *Y)
    326 /* ---------------------------------------------------------------------------------- */
    327 {
    328     long i;
    329     for(i=nl; i<=nh; i++)
    330         Y[i] = (float64) X[i];
    331 }
    332 /* ---------------------------------------------------------------------------------- */
    333 IMAGE_EXPORT(void) convert_si32vector_f32vector(sint32 *X, long nl, long nh, float32 *Y)
    334 /* ---------------------------------------------------------------------------------- */
    335 {
    336     long i;
    337     for(i=nl; i<=nh; i++)
    338         Y[i] = (float32) X[i];
    339 }
    340 /* ---------------------------------------------------------------------------------- */
    341 IMAGE_EXPORT(void) convert_si32vector_f64vector(sint32 *X, long nl, long nh, float64 *Y)
    342 /* ---------------------------------------------------------------------------------- */
    343 {
    344     long i;
    345     for(i=nl; i<=nh; i++)
    346         Y[i] = (float64) X[i];
    347 }
    348 /* ----------------------------------------------------------------------------------- */
    349 IMAGE_EXPORT(void) convert_ui32vector_f32vector(uint32 *X, long nl, long nh, float32 *Y)
    350 /* ----------------------------------------------------------------------------------- */
    351 {
    352     long i;
    353     for(i=nl; i<=nh; i++)
    354         Y[i] = (float32) X[i];
    355 }
    356 /* ----------------------------------------------------------------------------------- */
    357 IMAGE_EXPORT(void) convert_ui32vector_f64vector(uint32 *X, long nl, long nh, float64 *Y)
    358 /* ----------------------------------------------------------------------------------- */
    359 {
    360     long i;
    361     for(i=nl; i<=nh; i++)
    362         Y[i] = (float64) X[i];
    363 }
    364 // === Down === //
    365 /* ------------------------------------------------------------------------------- */
    366 IMAGE_EXPORT(void) convert_si16vector_si8vector(sint16 *X, long nl, long nh, sint8 *Y)
    367 /* ------------------------------------------------------------------------------- */
    368 {
    369     long i;
    370     for(i=nl; i<=nh; i++)
    371         Y[i] = (sint8) X[i];
    372 }
    373 /* ------------------------------------------------------------------------------- */
    374 IMAGE_EXPORT(void) convert_ui16vector_ui8vector(uint16 *X, long nl, long nh, uint8 *Y)
    375 /* ------------------------------------------------------------------------------- */
    376 {
    377     long i;
    378     for(i=nl; i<=nh; i++)
    379         Y[i] = (uint8) X[i];
    380 }
    381 /* -------------------------------------------------------------------------------- */
    382 IMAGE_EXPORT(void) convert_si32vector_si8vector(sint32 *X, long nl, long nh, sint8 *Y)
    383 /* -------------------------------------------------------------------------------- */
    384 {
    385     long i;
    386     for(i=nl; i<=nh; i++)
    387         Y[i] = (sint8) X[i];
    388 }
    389 /* ---------------------------------------------------------------------------------- */
    390 IMAGE_EXPORT(void) convert_si32vector_si16vector(sint32 *X, long nl, long nh, sint16 *Y)
    391 /* ---------------------------------------------------------------------------------- */
    392 {
    393     long i;
    394     for(i=nl; i<=nh; i++)
    395         Y[i] = (sint16) X[i];
    396 }
    397 /* -------------------------------------------------------------------------------- */
    398 IMAGE_EXPORT(void) convert_ui32vector_ui8vector(uint32 *X, long nl, long nh, uint8 *Y)
    399 /* -------------------------------------------------------------------------------- */
    400 {
    401     long i;
    402     for(i=nl; i<=nh; i++)
    403         Y[i] = (uint8) X[i];
    404 }
    405 /* ---------------------------------------------------------------------------------- */
    406 IMAGE_EXPORT(void) convert_ui32vector_ui16vector(uint32 *X, long nl, long nh, uint16 *Y)
    407 /* ---------------------------------------------------------------------------------- */
    408 {
    409     long i;
    410     for(i=nl; i<=nh; i++)
    411         Y[i] = (uint16) X[i];
    412 }
    413 /* -------------------------------------------------------------------------------- */
    414 IMAGE_EXPORT(void) convert_f32vector_si8vector(float32 *X, long nl, long nh, sint8 *Y)
    415 /* -------------------------------------------------------------------------------- */
    416 {
    417     long i;
    418     for(i=nl; i<=nh; i++)
    419         Y[i] = (sint8) X[i];
    420 }
    421 /* -------------------------------------------------------------------------------- */
    422 IMAGE_EXPORT(void) convert_f32vector_ui8vector(float32 *X, long nl, long nh, uint8 *Y)
    423 /* -------------------------------------------------------------------------------- */
    424 {
    425     long i;
    426     for(i=nl; i<=nh; i++)
    427         Y[i] = (uint8) X[i];
    428 }
    429 /* ---------------------------------------------------------------------------------- */
    430 IMAGE_EXPORT(void) convert_f32vector_si16vector(float32 *X, long nl, long nh, sint16 *Y)
    431 /* ---------------------------------------------------------------------------------- */
    432 {
    433     long i;
    434     for(i=nl; i<=nh; i++)
    435         Y[i] = (sint16) X[i];
    436 }
    437 /* ---------------------------------------------------------------------------------- */
    438 IMAGE_EXPORT(void) convert_f32vector_ui16vector(float32 *X, long nl, long nh, uint16 *Y)
    439 /* ---------------------------------------------------------------------------------- */
    440 {
    441     long i;
    442     for(i=nl; i<=nh; i++)
    443         Y[i] = (uint16) X[i];
    444 }
    445 /* ---------------------------------------------------------------------------------- */
    446 IMAGE_EXPORT(void) convert_f32vector_si32vector(float32 *X, long nl, long nh, sint32 *Y)
    447 /* ---------------------------------------------------------------------------------- */
    448 {
    449     long i;
    450     for(i=nl; i<=nh; i++)
    451         Y[i] = (sint32) X[i];
    452 }
    453 /* ---------------------------------------------------------------------------------- */
    454 IMAGE_EXPORT(void) convert_f32vector_ui32vector(float32 *X, long nl, long nh, uint32 *Y)
    455 /* ---------------------------------------------------------------------------------- */
    456 {
    457     long i;
    458     for(i=nl; i<=nh; i++)
    459         Y[i] = (uint32) X[i];
    460 }
    461 /* -------------------------------------------------------------------------------- */
    462 IMAGE_EXPORT(void) convert_f64vector_si8vector(float64 *X, long nl, long nh, sint8 *Y)
    463 /* -------------------------------------------------------------------------------- */
    464 {
    465     long i;
    466     for(i=nl; i<=nh; i++)
    467         Y[i] = (sint8) X[i];
    468 }
    469 /* -------------------------------------------------------------------------------- */
    470 IMAGE_EXPORT(void) convert_f64vector_ui8vector(float64 *X, long nl, long nh, uint8 *Y)
    471 /* -------------------------------------------------------------------------------- */
    472 {
    473     long i;
    474     for(i=nl; i<=nh; i++)
    475         Y[i] = (uint8) X[i];
    476 }
    477 /* ---------------------------------------------------------------------------------- */
    478 IMAGE_EXPORT(void) convert_f64vector_si16vector(float64 *X, long nl, long nh, sint16 *Y)
    479 /* ---------------------------------------------------------------------------------- */
    480 {
    481     long i;
    482     for(i=nl; i<=nh; i++)
    483         Y[i] = (sint16) X[i];
    484 }
    485 /* ---------------------------------------------------------------------------------- */
    486 IMAGE_EXPORT(void) convert_f64vector_ui16vector(float64 *X, long nl, long nh, uint16 *Y)
    487 /* ---------------------------------------------------------------------------------- */
    488 {
    489     long i;
    490     for(i=nl; i<=nh; i++)
    491         Y[i] = (uint16) X[i];
    492 }
    493 /* ---------------------------------------------------------------------------------- */
    494 IMAGE_EXPORT(void) convert_f64vector_si32vector(float64 *X, long nl, long nh, sint32 *Y)
    495 /* ---------------------------------------------------------------------------------- */
    496 {
    497     long i;
    498     for(i=nl; i<=nh; i++)
    499         Y[i] = (sint32) X[i];
    500 }
    501 /* ---------------------------------------------------------------------------------- */
    502 IMAGE_EXPORT(void) convert_f64vector_ui32vector(float64 *X, long nl, long nh, uint32 *Y)
    503 /* ---------------------------------------------------------------------------------- */
    504 {
    505     long i;
    506     for(i=nl; i<=nh; i++)
    507         Y[i] = (uint32) X[i];
    508 }
    509 /* ---------------------------------------------------------------------------------- */
    510 IMAGE_EXPORT(void) convert_f64vector_f32vector(float64 *X, long nl, long nh, float32 *Y)
    511 /* ---------------------------------------------------------------------------------- */
    512 {
    513     long i;
    514     for(i=nl; i<=nh; i++)
    515         Y[i] = (float32) X[i];
    516 }
    517 /* ------------------------------------------------------------------------------ */
    518 IMAGE_EXPORT(void) convert_rgb8vector_ui8vector(rgb8 *X, long nl, long nh, uint8 *Y)
    519 /* ------------------------------------------------------------------------------ */
    520 {
    521     long i;
    522     for(i=nl; i<=nh; i++) {
     176
     177
     178void convert_rgb8vector_ui8vector(rgb8 * X, int32_t nl, int32_t nh, uint8_t * Y)
     179{
     180    for (int32_t i = nl; i <= nh; i++) {
    523181        Y[i] = (X[i].r + X[i].g + X[i].b) / 3;
    524182    }
    525183}
    526 /* -------------------------------------------------------------------------------- */
    527 IMAGE_EXPORT(void) convert_rgbx8vector_ui8vector(rgbx8 *X, long nl, long nh, uint8 *Y)
    528 /* -------------------------------------------------------------------------------- */
    529 {
    530     long i;
    531     for(i=nl; i<=nh; i++) {
     184
     185void convert_rgbx8vector_ui8vector(rgbx8 * X, int32_t nl, int32_t nh, uint8_t * Y)
     186{
     187    for (int32_t i = nl; i <= nh; i++) {
    532188        Y[i] = (X[i].r + X[i].g + X[i].b) / 3;
    533189    }
    534190}
     191
    535192/*
    536193 * ---------------
     
    538195 * ---------------
    539196 */
    540 /* ------------------------------------------------------------------------------- */
    541 IMAGE_EXPORT(void) lowpart_ui16vector_ui8vector(uint16 *X, long nl,long nh, uint8 *Y)
    542 /* ------------------------------------------------------------------------------- */
    543 {
    544         int i;
    545         for(i=nl; i<=nh; i++) {
    546                 Y[i] = X[i] & 0xff;
    547         }
    548 }
    549 /* ------------------------------------------------------------------------------- */
    550 IMAGE_EXPORT(void) lowpart_ui32vector_ui8vector(uint32 *X, long nl,long nh, uint8 *Y)
    551 /* ------------------------------------------------------------------------------- */
    552 {
    553         int i;
    554         for(i=nl; i<=nh; i++) {
    555                 Y[i] = X[i] & 0xff;
    556         }
    557 }
    558 
    559 
     197
     198void lowpart_ui16vector_ui8vector(uint16_t * X, int32_t nl, int32_t nh, uint8_t * Y)
     199{
     200    for(int32_t i = nl; i <= nh; i++) {
     201        Y[i] = X[i] & 0xff;
     202    }
     203}
     204
     205void lowpart_ui32vector_ui8vector(uint32_t * X, int32_t nl, int32_t nh, uint8_t * Y)
     206{
     207    for (int32_t i = nl; i <= nh; i++) {
     208        Y[i] = X[i] & 0xff;
     209    }
     210}
     211
     212
  • soft/giet_vm/applications/rosenfeld/scripts/create_graph.py

    r822 r823  
    1616import filecmp
    1717import random
     18import math
    1819
    1920from stack import Stack
     
    2324
    2425use_rand_images = True
    25 with_features = True
     26with_features = False
    2627
    27 threads = [1, 2, 4]
    28 nb_step = 0
     28threads = [1, 2, 4, 8, 16, 32, 64]
    2929use_dsk = True
    30 img_size = 1024
     30img_size = 2048
    3131granularity = 1
    3232rand_seed = 7
     
    4242# Each of these configuration must have been run with both features activated and deactivated
    4343configs = [
    44         {'SLOW':'1', 'FAST':'0', 'PARMERGE':'0', 'ARSP':'0'},
    45         {'SLOW':'0', 'FAST':'1', 'PARMERGE':'0', 'ARSP':'0'},
    4644        #{'SLOW':'1', 'FAST':'0', 'PARMERGE':'0', 'ARSP':'0'},
    4745        #{'SLOW':'0', 'FAST':'1', 'PARMERGE':'0', 'ARSP':'0'},
    4846        #{'SLOW':'0', 'FAST':'1', 'PARMERGE':'1', 'ARSP':'0'},
    49         #{'SLOW':'0', 'FAST':'1', 'PARMERGE':'1', 'ARSP':'1'},
     47        {'SLOW':'0', 'FAST':'1', 'PARMERGE':'1', 'ARSP':'1'},
    5048]
    5149
     
    5553    code = compile(f.read(), pyconf_file, 'exec')
    5654    exec(code)
     55
     56nb_step = 0
    5757
    5858if use_dsk:
     
    125125        plotter.add_x(X)
    126126        assert(nb_step == 4)
    127         YPAR1 = [float(exec_time[fconfig][thread]["NF"][density][0]) for density in range(0, 101)] # Parallel Labeling
    128         YPAR2 = [float(exec_time[fconfig][thread]["NF"][density][1]) for density in range(0, 101)] # Merging (Parallel or Pyramidal)
    129         YPTC2 = [float(exec_time[fconfig][thread]["NF"][density][2]) for density in range(0, 101)] # Parallel Transitive Closure
    130         YPAR3 = [float(exec_time[fconfig][thread]["NF"][density][3]) for density in range(0, 101)] # Parallel Relabeling
     127        YPAR1 = [float(int(exec_time[fconfig][thread]["NF"][density][0]) / math.pow(img_size, 2)) for density in range(0, 101)] # Parallel Labeling
     128        YPAR2 = [float(int(exec_time[fconfig][thread]["NF"][density][1]) / math.pow(img_size, 2)) for density in range(0, 101)] # Merging (Parallel or Pyramidal)
     129        YPTC2 = [float(int(exec_time[fconfig][thread]["NF"][density][2]) / math.pow(img_size, 2)) for density in range(0, 101)] # Parallel Transitive Closure
     130        YPAR3 = [float(int(exec_time[fconfig][thread]["NF"][density][3]) / math.pow(img_size, 2)) for density in range(0, 101)] # Parallel Relabeling
    131131
    132132        plotter.add_y(YPAR1)
     
    136136
    137137        if with_features:
    138             YPAR1f = [float(exec_time[fconfig][thread]["FT"][density][0]) for density in range(0, 101)] # Parallel Labeling
    139             YPAR2f = [float(exec_time[fconfig][thread]["FT"][density][1]) for density in range(0, 101)] # Merging (Parallel or Pyramidal)
     138            YPAR1f = [float(int(exec_time[fconfig][thread]["FT"][density][0]) / math.pow(img_size, 2)) for density in range(0, 101)] # Parallel Labeling
     139            YPAR2f = [float(int(exec_time[fconfig][thread]["FT"][density][1]) / math.pow(img_size, 2)) for density in range(0, 101)] # Merging (Parallel or Pyramidal)
    140140            deltaYPAR1 = [max(0, x - y) for x, y in zip (YPAR1f, YPAR1)]
    141141            deltaYPAR2 = [max(0, x - y) for x, y in zip (YPAR2f, YPAR2)]
  • soft/giet_vm/applications/rosenfeld/scripts/run_simus.py

    r822 r823  
    55# python 2 as it will execute on computation servers
    66
     7# TODO:
     8#       Can we do something about assert in perf eval?
    79
    810from __future__ import print_function
     
    3739
    3840# Parameters
    39 num_runs = 10
     41# - with eval_perf, num_internal_runs should be used, as this allows to mitigate the cost of the extra
     42#     run required to have the correct "ne" value (number of labels), and only the times from last application run are taken
     43# - With check_results, num_app_runs should be used, so as to have a number of checks equals to the number of runs,
     44#     because only one check per application run is performed
     45num_app_runs = 1        # Number of times the application is launched per configuration
     46num_internal_runs = 20  # Number of times the image is processed inside the application
    4047check_results = False
    4148eval_perf = True
    4249use_valgrind = False
    4350use_rand_images = True
    44 threads = [1, 2, 4]
     51threads = [1, 2, 4, 8, 16, 32, 64]
     52#threads = [1, 2]
    4553use_dsk = True
    4654# Using dsk will store generated random images, otherwise they are re-generated at each run to save disk space
     
    4856# Configurations
    4957configs = [
    50         {'SLOW':'1', 'FAST':'0', 'FEATURES':'0', 'PARMERGE':'0', 'ARSP':'0'},
    51         {'SLOW':'0', 'FAST':'1', 'FEATURES':'0', 'PARMERGE':'0', 'ARSP':'0'},
    52         {'SLOW':'1', 'FAST':'0', 'FEATURES':'1', 'PARMERGE':'0', 'ARSP':'0'},
    53         {'SLOW':'0', 'FAST':'1', 'FEATURES':'1', 'PARMERGE':'0', 'ARSP':'0'},
     58        #{'SLOW':'1', 'FAST':'0', 'FEATURES':'0', 'PARMERGE':'0', 'ARSP':'0'},
     59        #{'SLOW':'0', 'FAST':'1', 'FEATURES':'0', 'PARMERGE':'0', 'ARSP':'0'},
     60        #{'SLOW':'1', 'FAST':'0', 'FEATURES':'1', 'PARMERGE':'0', 'ARSP':'0'},
     61        #{'SLOW':'0', 'FAST':'1', 'FEATURES':'1', 'PARMERGE':'0', 'ARSP':'0'},
     62        {'SLOW':'0', 'FAST':'1', 'FEATURES':'0', 'PARMERGE':'1', 'ARSP':'0'},
    5463        #{'SLOW':'0', 'FAST':'1', 'FEATURES':'1', 'PARMERGE':'1', 'ARSP':'0'},
    5564        #{'SLOW':'0', 'FAST':'1', 'FEATURES':'0', 'PARMERGE':'1', 'ARSP':'1'},
     
    6069rand_seed = 7
    6170granularity = 1 # constant for now
    62 img_size = 1024
     71img_size = 2048
    6372
    6473check_pyconf_file(pyconf_file)
     
    93102
    94103
     104if check_results and eval_perf:
     105    print("*** Warning: check_results and eval_perf modes are both set\n")
     106if eval_perf and use_valgrind:
     107    print("*** Warning: using valgrind while eval_perf mode is set\n")
     108if eval_perf and num_app_runs != 1:
     109    print("*** Warning: using eval_perf with num_app_runs != 1\n")
     110if check_results and num_internal_runs != 1:
     111    print("*** Warning: using check_results with num_internal_runs != 1\n")
     112
     113
    95114
    96115def gen_random_image(filename, x, y, granularity, density, seed):
     
    136155                    break
    137156            if not line_with_key:
    138                 f.write(line)
     157                if "#define MCA_VERBOSE_LEVEL" in line:
     158                    if eval_perf:
     159                        verb_level = 1
     160                    else:
     161                        verb_level = 2
     162                    f.write("#define MCA_VERBOSE_LEVEL %d\n" % verb_level) 
     163                else:
     164                    f.write(line)
    139165
    140166        f.close()
     
    179205    my_chdir(top_path)
    180206    cmd = ['make']
     207    #if eval_perf:
     208    #    cmd.extend(['IGNORE_ASSERT=true'])
    181209    print_and_call(cmd)
    182210    my_chdir(scripts_path)
     
    205233        for nthreads in threads:
    206234            perf_array[fconfig][img_basename][nthreads] = {}
    207             for run in range(num_runs):
     235            for run in range(num_app_runs):
    208236                if not os.path.exists(ref_bmpfile):
    209237                    bmpfile = ref_bmpfile
     
    223251   
    224252                cmd.extend([short_path(binary_file), '-n', str(nthreads), '-i', short_path(image)])
     253
     254                if num_internal_runs > 1:
     255                    cmd.extend(['-r', str(num_internal_runs)])
    225256               
    226257                if check_results:
     
    236267
    237268                # if performance evaluation, get timing measurements
     269                # Only the last application run is considered
    238270                if eval_perf:
    239271                    for line in outlines:
     
    247279                            step = match.group(1)
    248280                            value = tokens[len(tokens) - 1]
    249                             if step in perf_array[fconfig][img_basename][nthreads]:
    250                                 # Accumulating times over the num_runs runs
    251                                 perf_array[fconfig][img_basename][nthreads][step] += int(value)
    252                             else:
    253                                 perf_array[fconfig][img_basename][nthreads][step] = int(value)
     281                            perf_array[fconfig][img_basename][nthreads][step] = int(value)
    254282
    255283
     
    315343                for step in sorted(perf_array[fconfig][img_basename][nthreads].keys()):
    316344                    # Average time for each step
    317                     file.write("[STEP_%s]   %d\n" % (step, perf_array[fconfig][img_basename][nthreads][step] / num_runs))
     345                    file.write("[STEP_%s]   %d\n" % (step, perf_array[fconfig][img_basename][nthreads][step]))
    318346
    319347        img_idx += 1
  • soft/giet_vm/applications/rosenfeld/src-par/mca.c

    r822 r823  
    9898
    9999
    100 // -----------------------------------------------
     100// ------------------------------------------------
    101101void MCA_Set_Size(MCA * mca, int width, int height)
    102 // -----------------------------------------------
     102// ------------------------------------------------
    103103{
    104104    MCA_Set_Width(mca, width);
     
    107107
    108108
    109 // ----------------------------------------------------
     109// -----------------------------------------------------
    110110void MCA_Set_Dimension(MCA * mca, int width, int height)
    111 // ----------------------------------------------------
     111// -----------------------------------------------------
    112112{
    113113    MCA_Set_Width(mca, width);
     
    116116
    117117
    118 // ------------------------------
     118// -------------------------------
    119119void MCA_Set_NP(MCA * mca, int np)
    120 // ------------------------------
     120// -------------------------------
    121121{
    122122    mca->np = np;
    123123}
     124
     125
     126// -------------------------------
     127void MCA_Set_NR(MCA * mca, int nr)
     128// -------------------------------
     129{
     130    mca->nr = nr;
     131}
     132
    124133
    125134
     
    146155    // input
    147156    int np     = mca->np;
     157    int nr     = mca->nr;
    148158    int width  = mca->width;
    149159    int height = mca->height;
     
    292302        mca_par->e0 = e0_par;
    293303        mca_par->e1 = e1_par;
     304        // à la premiÚre itération, on remet à 0 toute la table T
     305        mca_par->ne_prev = e1_par;
    294306        mca_par->alpha = pw2;
    295307        mca_par->np = np;
     308        mca_par->nr = nr;
    296309        // Pour les barriÚres pyramidales
    297310        mca_par->nb_level = nb_level;
     
    311324        mca_par->E = remote_dist_ui32matrix(i0_par, i1_par, 0, width - 1, x, y); // distributed matrix with border
    312325       
    313         if (p == 0) {
    314             mca_par->T = remote_ui32vector(e0_par - 1, e1_par, x, y); // car e0 = 1, on a besoin que T[0] = 0 pour FindRoot
    315             mca_par->stats = remote_RegionStatsVector(e0_par - 1, e1_par, x, y);
    316         }
    317         else {
    318             mca_par->T = remote_ui32vector(e0_par, e1_par, x, y);
    319             mca_par->stats = remote_RegionStatsVector(e0_par, e1_par, x, y);
    320         }
     326        mca_par->T = remote_ui32vector(e0_par, e1_par, x, y);
     327        mca_par->stats = remote_RegionStatsVector(e0_par, e1_par, x, y);
    321328       
    322329        mca_par->D = (uint32 **) remote_vvector(0, np - 1, x, y);
     
    326333        mca_par->E = dist_ui32matrix(i0_par, i1_par, 0, width - 1); // distributed matrix with border
    327334       
    328         if (p == 0) {
    329             mca_par->T = ui32vector(e0_par - 1, e1_par); // car e0 = 1, on a besoin que T[0] = 0 pour FindRoot
    330             mca_par->stats = RegionStatsVector(e0_par - 1, e1_par);
    331         }
    332         else {
    333             mca_par->T = ui32vector(e0_par, e1_par);
    334             mca_par->stats = RegionStatsVector(e0_par, e1_par);
    335         }
     335        mca_par->T = ui32vector(e0_par, e1_par);
     336        mca_par->stats = RegionStatsVector(e0_par, e1_par);
    336337       
    337338        mca_par->D = (uint32 **) vvector(0, np - 1);
     
    353354   
    354355        MCA_VERBOSE3(printf("p = %d T[%d..%d]\n", p, e0, e1));
    355         if (p == 0) {
    356             set_ui32vector_j(T, e0 - 1, e1); // car e0 = 1, on a besoin que T[0] = 0 pour FindRoot
    357         }
    358         else {
    359             set_ui32vector_j(T, e0, e1);
    360         }
    361         MCA_VERBOSE3(printf("\n"));
     356        set_ui32vector_j(T, e0, e1);
    362357    }
    363358   
     
    371366       
    372367        MCA_VERBOSE3(printf("p = %d T[%d..%d]\n", p, e0, e1));
    373         if (p == 0) {
    374             MCA_VERBOSE3(display_ui32vector_number(T, e0 - 1, e0 + 10, "%5d", "T"));
    375         }
    376         else {
    377             MCA_VERBOSE3(display_ui32vector_number(T, e0, e0 + 10, "%5d", "T"));
    378         }
     368        MCA_VERBOSE3(display_ui32vector_number(T, e0, e0 + 10, "%5d", "T"));
    379369        MCA_VERBOSE3(printf("\n"));
    380370    }
     
    506496        free_dist_ui32matrix(mca_par->E, i0, i1, j0, j1);
    507497       
    508         if (p == 0) {
    509             free_ui32vector(mca_par->T, e0 - 1, e1); // car e0 = 1, on a besoin que T[0] = 0 pour FindRoot
    510             free_RegionStatsVector(mca_par->stats, e0 - 1, e1);
    511         }
    512         else {
    513             free_ui32vector(mca_par->T, e0, e1);
    514             free_RegionStatsVector(mca_par->stats, e0, e1);
    515         }
     498        free_ui32vector(mca_par->T, e0, e1);
     499        free_RegionStatsVector(mca_par->stats, e0, e1);
    516500       
    517501        free_vvector((void **) mca_par->D, 0, np - 1);
  • soft/giet_vm/applications/rosenfeld/src-par/mca_main.c

    r822 r823  
    4343#define MAX_THREADS 256
    4444#define DEFAULT_NTHREADS 1
     45#define DEFAULT_NRUNS 1
    4546#define DEFAULT_IN_FILENAME "/misc/cadastre.pgm"
    4647#define DEFAULT_OUT_FILENAME "out.bmp"
     
    233234
    234235
    235 // -----------------------------------------------------------
    236 void mca_test2(int num_threads, char * infile, char * outfile)
    237 // -----------------------------------------------------------
     236// -------------------------------------------------------------------------
     237void mca_test2(int num_threads, int num_runs, char * infile, char * outfile)
     238// -------------------------------------------------------------------------
    238239{
    239240    int i0, i1, j0, j1;
     
    277278    MCA_Set_ImageL(mca, E);
    278279    MCA_Set_NP(mca, num_threads);
     280    MCA_Set_NR(mca, num_runs);
    279281   
    280282    // -- MCA init
     
    316318
    317319
    318 // --------------------------------------------------------------
    319 int main_test_mca(int num_threads, char * infile, char * outfile)
    320 // --------------------------------------------------------------
     320// ----------------------------------------------------------------------------
     321int main_test_mca(int num_threads, int num_runs, char * infile, char * outfile)
     322// ----------------------------------------------------------------------------
    321323{
    322324    CLOCK_INIT(num_threads, 4); // 4 = Number of steps in body
    323325    CLOCK_APP_START;
    324326
    325     mca_test2(num_threads, infile, outfile);
     327    mca_test2(num_threads, num_runs, infile, outfile);
    326328
    327329    CLOCK_APP_END;
     
    349351    int ch;
    350352    int num_threads = DEFAULT_NTHREADS;
     353    int num_runs = DEFAULT_NRUNS;
    351354
    352355    MCA_VERBOSE1(printf("*** Starting application Rosenfeld ***\n"));
    353356
    354357#if TARGET_OS != GIETVM // @QM I think the giet has some random (uninitialized) values for argc and argv
    355     while ((ch = getopt(argc, argv, "i:o:n:hdg")) != EOF) {
     358    while ((ch = getopt(argc, argv, "i:o:n:r:hdg")) != EOF) {
    356359        switch (ch) {
    357360        case 'i':
     
    363366        case 'n':
    364367            num_threads = atoi(optarg);
     368            break;
     369        case 'r':
     370            num_runs = atoi(optarg);
    365371            break;
    366372        case 'h':
     
    409415    MCA_VERBOSE1(printf("Parameters:\n"));
    410416    MCA_VERBOSE1(printf("- Number of threads: %d\n", num_threads));
     417    MCA_VERBOSE1(printf("- Number of images processed: %d\n", num_runs));
    411418    MCA_VERBOSE1(printf("- Input file: %s\n", infile));
    412419    MCA_VERBOSE1(printf("- Output file: %s\n", outfile));
     
    450457
    451458    pthread_mutex_init(&print_lock, PTHREAD_PROCESS_PRIVATE);
    452     main_test_mca(num_threads, infile, outfile);
     459    main_test_mca(num_threads, num_runs, infile, outfile);
    453460
    454461    return 0;
  • soft/giet_vm/applications/rosenfeld/src-par/mca_rosenfeld.c

    r822 r823  
    142142}
    143143#endif // FEATURES && !PARMERGE
     144
     145
     146#if !FEATURES && PARMERGE
     147// -----------------------------------------------------------------------------------------------------------
     148static bool SetRoot_Parallel_Rosenfeld_Dist(uint32 ** D, uint32 root, uint32 eps, int shift, RegionStats ** F)
     149// -----------------------------------------------------------------------------------------------------------
     150{
     151    assert(root != 0 && eps != 0);
     152
     153    MCA_VERBOSE3(printf("F(%d) += F(%d)\n", eps, root));
     154   
     155    int mask = (1 << shift) - 1;
     156
     157    uint32 r1 = root >> shift;
     158    uint32 r0 = root & mask;
     159   
     160    uint32 e1 = eps >> shift;
     161    uint32 e0 = eps & mask;
     162
     163    // Locking towards the root (first root, then eps)
     164    pthread_spin_lock(&F[r1][r0].lock);
     165    pthread_spin_lock(&F[e1][e0].lock);
     166    if (D[e1][e0] != eps || D[r1][r0] != root) {
     167        // Someone change the root of epsilon or "root", need to find the new root
     168        pthread_spin_unlock(&F[e1][e0].lock);
     169        pthread_spin_unlock(&F[r1][r0].lock);
     170        return false;
     171    }
     172
     173    D[r1][r0] = eps;
     174   
     175    pthread_spin_unlock(&F[e1][e0].lock);
     176    pthread_spin_unlock(&F[r1][r0].lock);
     177    return true;
     178}
     179#endif // !FEATURES && PARMERGE
    144180
    145181
     
    585621
    586622
    587 #if FAST && FEATURES && PARMERGE && !ARSP
     623#if FAST && PARMERGE && !ARSP // Valid for FEATURES and !FEATURES
    588624// ---------------------------------------------------------------------------------------------------------------------------
    589 static void vuse2_Parallel_Features_Rosenfeld_Dist(uint32 ed, uint32 el, uint32 * T, uint32 ** D, int alpha, RegionStats ** F)
     625static void vuse2_Parallel_Rosenfeld_Dist(uint32 ed, uint32 el, uint32 * T, uint32 ** D, int alpha, RegionStats ** F)
    590626// ---------------------------------------------------------------------------------------------------------------------------
    591627{
     
    610646        // qui a fait un test
    611647        if (rd < rl) {
    612             ok = SetRoot_Parallel_Features_Rosenfeld_Dist(D, rl, rd, alpha, F);
     648            // Features or No Features depending on config
     649            ok = SetRoot_Parallel_FNF(D, rl, rd, alpha, F);
    613650        }
    614651        else {
    615             ok = SetRoot_Parallel_Features_Rosenfeld_Dist(D, rd, rl, alpha, F);
     652            ok = SetRoot_Parallel_FNF(D, rd, rl, alpha, F);
    616653        }
    617654    } while (!ok);
    618655}
    619656
    620 // FAST && FEATURES && PARMERGE && !ARSP
     657// FAST && PARMERGE && !ARSP
    621658
    622659// -----------------------------------------------------------------------------------------------------------------------------------------
    623 static void vuse3_Parallel_Features_Rosenfeld_Dist(uint32 ed1, uint32 ed2, uint32 el3, uint32 * T, uint32 ** D, int alpha, RegionStats ** F)
     660static void vuse3_Parallel_Rosenfeld_Dist(uint32 ed1, uint32 ed2, uint32 el3, uint32 * T, uint32 ** D, int alpha, RegionStats ** F)
    624661// -----------------------------------------------------------------------------------------------------------------------------------------
    625662{
     
    649686        ok3 = true;
    650687        if (r1 > eps) {
    651             ok1 = SetRoot_Parallel_Features_Rosenfeld_Dist(D, r1, eps, alpha, F);
     688            ok1 = SetRoot_Parallel_FNF(D, r1, eps, alpha, F);
    652689        }
    653690        if (r2 > eps && r2 != r1) {
    654             ok2 = SetRoot_Parallel_Features_Rosenfeld_Dist(D, r2, eps, alpha, F);
     691            ok2 = SetRoot_Parallel_FNF(D, r2, eps, alpha, F);
    655692        }
    656693        if (r3 > eps && r3 != r2 && r3 != r1) {
    657             ok3 = SetRoot_Parallel_Features_Rosenfeld_Dist(D, r3, eps, alpha, F);
     694            ok3 = SetRoot_Parallel_FNF(D, r3, eps, alpha, F);
    658695        }
    659696    } while (!(ok1 && ok2 && ok3));
    660697}
    661 #endif // FAST && FEATURES && PARMERGE && !ARSP
     698#endif // FAST && PARMERGE && !ARSP
    662699
    663700
     
    13811418    uint32 e0 = mca->e0;
    13821419    uint32 e1 = mca->e1;
     1420    uint32 ne_prev = mca->ne_prev;
    13831421    uint32 ne = e0 - 1;
    13841422    uint32 nr = 0;
     
    13901428    RegionStats * stats = mca->stats;
    13911429
    1392     // reset sous optimal (pour le moment = voir region32)
    1393     if (mca->p == 0) {
    1394         set_ui32vector_j(T, e0 - 1, e1); // car e0 = 1, on a besoin que T[0] = 0 pour FindRoot
     1430    CLOCK_THREAD_START_STEP(mca->p, 0);
     1431
     1432    set_ui32vector_j(T, e0, ne_prev);
    13951433#if FEATURES
    1396         zero_RegionStatsVector(stats, e0 - 1, e1);
     1434    zero_RegionStatsVector(stats, e0, ne_prev);
    13971435#endif
    1398     }
    1399     else {
    1400         set_ui32vector_j(T, e0, e1);
    1401 #if FEATURES
    1402         zero_RegionStatsVector(stats, e0, e1);
    1403 #endif
    1404     }
    14051436
    14061437    if (mca->p == 0) {
     
    14111442    // -- Etiquetage d'une bande -- //
    14121443    // ---------------------------- //
    1413 
    1414     CLOCK_THREAD_START_STEP(mca->p, 0);
    14151444
    14161445    ne = line0Labeling_Rosenfeld(X, i0, width, E, T, ne);
     
    16441673
    16451674    CLOCK_THREAD_START(mca->p);
    1646     CLOCK_THREAD_COMPUTE_START(mca->p);
    1647 
    1648     MCA_Scatter_ImageX(mca);
    1649     pthread_barrier_wait(&main_barrier);
    1650 
    1651     MCA_Label_Rosenfeld_PAR1(mca);
    1652     pthread_barrier_wait(&main_barrier);
    1653    
     1675
     1676    int num_runs = mca->nr;
     1677
     1678    // We always perform one more run than the num_runs
     1679    // value, so as to know "ne", i.e. the number of
     1680    // elements to reset in the T and F tables (labels and stats)
     1681    // After this first extra run, clock times are not accumulated
     1682    // and thus are lost.
     1683    // Note: the CLOCK_THREAD_START will still include this first run,
     1684    // and in case of multiple runs, only averaged times should be
     1685    // considered.
     1686    for (int run = 0; run < num_runs + 1; run++) {
     1687
     1688        CLOCK_THREAD_COMPUTE_START(mca->p);
     1689
     1690        MCA_Scatter_ImageX(mca);
     1691        pthread_barrier_wait(&main_barrier);
     1692
     1693        MCA_Label_Rosenfeld_PAR1(mca);
     1694        pthread_barrier_wait(&main_barrier);
     1695 
    16541696#if PARMERGE
    1655     MCA_Label_Rosenfeld_PAR2(mca);
     1697        MCA_Label_Rosenfeld_PAR2(mca);
    16561698#else
    1657     MCA_Label_Rosenfeld_PYR2(mca);
     1699        MCA_Label_Rosenfeld_PYR2(mca);
    16581700#endif
    1659     pthread_barrier_wait(&main_barrier);
    1660    
    1661     MCA_Label_Rosenfeld_PAR3(mca);
    1662     pthread_barrier_wait(&main_barrier);
    1663 
    1664     MCA_Gather_ImageL(mca);
    1665     pthread_barrier_wait(&main_barrier);
    1666 
    1667     CLOCK_THREAD_COMPUTE_END(mca->p);
     1701        pthread_barrier_wait(&main_barrier);
     1702 
     1703        MCA_Label_Rosenfeld_PAR3(mca);
     1704        pthread_barrier_wait(&main_barrier);
     1705
     1706        MCA_Gather_ImageL(mca);
     1707        pthread_barrier_wait(&main_barrier);
     1708       
     1709        CLOCK_THREAD_COMPUTE_END(mca->p);
     1710
     1711        if (run == 0) {
     1712            // Mise à jour du ne_prev par chaque thread
     1713            mca->ne_prev = mca->ne;
     1714            mca->ne = 0;
     1715        }
     1716        else {
     1717            // Accumulation du temps COMPUTE et de toutes les STEP
     1718            if (mca->p == 0) {
     1719                CLOCK_ACCUMULATE;
     1720            }
     1721            assert(mca->ne == mca->ne_prev);
     1722            // Reinitialisation de "ne" s'il ne s'agit pas du dernier run
     1723            if (run != num_runs) {
     1724                mca->ne = 0;
     1725            }
     1726        }
     1727        pthread_barrier_wait(&main_barrier);
     1728    }
     1729
    16681730 
    16691731#if FEATURES
Note: See TracChangeset for help on using the changeset viewer.