Index: soft/giet_vm/applications/rosenfeld/Makefile
===================================================================
--- soft/giet_vm/applications/rosenfeld/Makefile	(revision 820)
+++ soft/giet_vm/applications/rosenfeld/Makefile	(revision 821)
@@ -31,10 +31,10 @@
 C_DEBUG_FLAGS = -O0
 C_OPTIM_FLAGS = -std=c99 -O2 -fstrict-aliasing
-C_OS_FLAGS = -DGTODay -DTARGET_OS=LINUX
+C_OS_FLAGS = -DGTODay -DTARGET_OS=LINUX -D_GNU_SOURCE
 C_CONFIG_FLAGS = -DCLI
 C_INC_FLAGS = -I$(INC_PATH) -Inrc2/include
 CFLAGSCPU = 
 
-LDFLAGS := -Lnrc2 -Wl,--start-group -lnrc2x -lm -Wl,--end-group
+LDFLAGS := -Lnrc2 -Wl,--start-group -lnrc2x -lm -lpthread -Wl,--end-group
 
 endif
@@ -52,5 +52,5 @@
 
 SRC_FILE = $(wildcard $(SRC_PATH)/*.c)
-INC_FILE = $(wildcard $(SRC_PATH)/*.h)
+INC_FILE = $(wildcard $(INC_PATH)/*.h)
 
 #SRC = $(addprefix $(SRC_PATH)/,$(FILE))
@@ -66,5 +66,5 @@
 	$(LD) -o $@ $^ $(LDFLAGS)
 
-$(OBJ_PATH)/%.o: $(SRC_PATH)/%.c $(INC_FILE) nrc2/libnrc2x.a ../../build/libs/libuser.a
+$(OBJ_PATH)/%.o: $(SRC_PATH)/%.c $(INC_FILE) nrc2/libnrc2x.a ../../build/libs/libuser.a nrc2/include/nrc_os_config.h
 	$(CC) -c $(CFLAGS) -o $@ $<
 
Index: soft/giet_vm/applications/rosenfeld/check.py
===================================================================
--- soft/giet_vm/applications/rosenfeld/check.py	(revision 821)
+++ soft/giet_vm/applications/rosenfeld/check.py	(revision 821)
@@ -0,0 +1,241 @@
+#!/usr/bin/python
+# -*- coding: utf-8 -*-
+
+from __future__ import print_function
+import os
+import sys
+import re
+import subprocess
+import shutil
+import filecmp
+
+#images = ['../../images/boulons.pgm', '../../images/cadastre.pgm', '../../images/alea1.pgm', '../../images/alea2.pgm', '../../images/alea3.pgm']
+images = ['../../images/alea1.pgm']
+config_file = "include/config.h"
+
+use_valgrind = False
+infinite_mode = True
+
+threads = [64]
+binary = "./appli.elf"
+outimages_dir = "output_images"
+log_dir = "logs"
+
+configs = [
+#        {
+#            'SLOW':'1',
+#            'FAST':'0',
+#            'FEATURES':'0',
+#            'PARMERGE':'0'
+#        },
+#        {
+#            'SLOW':'0',
+#            'FAST':'1',
+#            'FEATURES':'0',
+#            'PARMERGE':'0'
+#        },
+#        {
+#            'SLOW':'1',
+#            'FAST':'0',
+#            'FEATURES':'1',
+#            'PARMERGE':'0'
+#        },
+#        {
+#            'SLOW':'0',
+#            'FAST':'1',
+#            'FEATURES':'1',
+#            'PARMERGE':'0'
+#        },
+        {
+            'SLOW':'0',
+            'FAST':'1',
+            'FEATURES':'1',
+            'PARMERGE':'1'
+        }
+]
+
+
+
+def my_mkdir(dirname):
+    try:
+        print("mkdir %s" % (dirname))
+        os.mkdir(dirname)
+    except OSError:
+        print("*** Error: impossible to create directory %s" % (dirname), file=sys.stderr)
+        sys.exit(1)
+
+def my_chdir(dirname):
+    print("cd %s" % (dirname));
+    os.chdir(dirname)
+
+def my_cp(src, dst):
+    print("cp %s %s" % (src, dst))
+    shutil.copy(src, dst)
+
+def print_and_call(cmd):
+    print(subprocess.list2cmdline(cmd))
+    retval = subprocess.call(cmd)
+    return retval
+
+def print_and_popen(cmd, outfile):
+    print(subprocess.list2cmdline(cmd), end = "")
+    print(" >", outfile)
+    output = subprocess.Popen(cmd, stdout = subprocess.PIPE, stderr = subprocess.STDOUT).communicate()[0]
+    return output
+
+
+
+
+def update_config_file(config):
+    if os.path.isfile(config_file):
+        print("# Updating file %s" % (config_file))
+        f = open(config_file, "r")
+        lines = f.readlines()
+        f.close()
+
+        f = open(config_file, "w")
+
+        for line in lines:
+            line_with_key = False
+            for key in config.keys():
+                if "#define %s" % (key) in line:
+                    f.write("#define %s %s\n" % (key, config[key]))
+                    line_with_key = True
+                    break
+            if not line_with_key:
+                f.write(line)
+
+        f.close()
+    else:
+        print("# Creating file %s" % (config_file))
+        f = open(config_file, "w")
+        f.write("\n")
+        for key in config.keys():
+            f.write("#define %s %s\n" % (key, config[key]))
+        f.write("\n")
+        f.close()
+
+
+root_dir = os.getcwd()
+
+
+if not os.path.exists(outimages_dir):
+    my_mkdir(outimages_dir)
+
+if not os.path.exists(log_dir):
+    my_mkdir(log_dir)
+
+
+stat_array = {}
+finished = False
+
+for config in configs:
+    update_config_file(config)
+    cmd = ['make']
+    print_and_call(cmd)
+    for image in images:
+        ref_bmpfile = os.path.join(outimages_dir, os.path.splitext(os.path.basename(image))[0] + "_ref.bmp")
+        ref_statfile = os.path.join(outimages_dir, os.path.splitext(os.path.basename(image))[0] + "_ref.txt")
+        for nthreads in threads:
+            while not finished:
+                if not os.path.exists(ref_bmpfile):
+                    bmpfile = ref_bmpfile
+                else:
+                    bmpfile = os.path.join(outimages_dir, os.path.splitext(os.path.basename(image))[0] + ".bmp")
+
+                if not os.path.exists(ref_statfile):
+                    statfile = ref_statfile
+                else:
+                    statfile = os.path.join(outimages_dir, os.path.splitext(os.path.basename(image))[0] + ".txt")
+
+                cmd = []
+                if use_valgrind:
+                    cmd.append('valgrind')
+
+                cmd.extend([binary, '-n', str(nthreads), '-i', image, '-o', bmpfile, '-g'])
+                
+                if config['FEATURES'] == '1':
+                    cmd.append('-d')
+
+                config_keys = config.keys()
+                logfile = os.path.join(log_dir, os.path.splitext(os.path.basename(image))[0] + "_" + str(nthreads) + "_" + "_".join(map(lambda x:'%s_%s' % (x, config[x]), config_keys)) + ".txt")
+                output = print_and_popen(cmd, logfile)
+                
+                # Write simulation results to log file
+                file = open(logfile, 'w')
+                file.write(output)
+                file.close()
+
+                if bmpfile != ref_bmpfile:
+                    if filecmp.cmp(bmpfile, ref_bmpfile):
+                        print("# Files %s and %s are identical" % (bmpfile, ref_bmpfile))
+                    else:
+                        print("*** Error: files %s and %s differ" % (bmpfile, ref_bmpfile))
+                        sys.exit(1)
+
+                if use_valgrind:
+                    if not "== ERROR SUMMARY: 0 errors from 0 contexts" in output:
+                        print("*** Error: Valgrind error")
+                        sys.exit(1)
+                    if not "== All heap blocks were freed -- no leaks are possible" in output:
+                        print("*** Error: Valgrind detected a memory leak")
+                        sys.exit(1)
+
+                if config['FEATURES'] == '1':
+                    stat_array = {}
+                    in_stats = False
+                    outlines = output.splitlines()
+                    index = 0
+                    for line in outlines:
+                        #print("bla i")
+                        #print(line)
+                        if "[STATS]" in line:
+                            in_stats = True
+                            continue
+                        if "[/STATS]" in line:
+                            in_stat = False
+                            break
+                        if in_stats:
+                            tokens = line.split()
+                            #print("#len : %d" % len(tokens))
+                            #print(tokens[0])
+                            assert(len(tokens) == 8)
+                            stat_array[index] = {}
+                            for j in range(len(tokens)):
+                                stat_array[index][j] = tokens[j]
+                            index += 1
+
+
+                    # Dump stat array in stat file
+                    file = open(statfile, 'w')
+                    for i in range(len(stat_array)):
+                        for j in range(8):
+                            file.write("%s " % stat_array[i][j])
+                        file.write("\n");
+                    file.close()
+
+                    # Comparison to reference
+                    if statfile != ref_statfile:
+                        if filecmp.cmp(statfile, ref_statfile):
+                            print("# Feature files %s and %s are identical" % (statfile, ref_statfile))
+                        else:
+                            print("*** Error: feature files %s and %s differ" % (statfile, ref_statfile))
+                            sys.exit(1)
+
+                if not infinite_mode:
+                    finished = True
+                
+
+
+
+
+
+
+
+
+
+
+
+
+
+
Index: soft/giet_vm/applications/rosenfeld/include/clock.h
===================================================================
--- soft/giet_vm/applications/rosenfeld/include/clock.h	(revision 821)
+++ soft/giet_vm/applications/rosenfeld/include/clock.h	(revision 821)
@@ -0,0 +1,222 @@
+
+#ifndef _CLOCK_H_
+#define _CLOCK_H_
+
+#include <stdint.h>
+
+#include "nrc_os_config.h"
+#if TARGET_OS == LINUX
+    #include <sys/time.h>
+#endif
+
+/**
+ * The macros should be called in the following order:
+ * - CLOCK_DEC;
+ * - CLOCK_INIT(num_threads, num_steps);
+ * - CLOCK_APP_START;
+ * - CLOCK_APP_CREATE;
+ * - CLOCK_THREAD_START(thread_id);
+ * - CLOCK_THREAD_COMPUTE_START(thread_id;
+ * - CLOCK_THREAD_START_STEP(thread_id, step_id)
+ * - CLOCK_THREAD_END_STEP(thread_id, step_id)
+ * - (repeat num_steps times)
+ * - CLOCK_THREAD_COMPUTE_END(thread_id);
+ * - CLOCK_THREAD_END(thread_id)
+ * - CLOCK_APP_JOIN;
+ * - CLOCK_APP_END;
+ * - CLOCK_FINALIZE(num_threads);
+ * - PRINT_CLOCK;
+ * - CLOCK_FREE;
+ */
+
+
+static void local_sort_asc(uint32_t tab[], int size) {
+    int tmp;
+    int i, j;
+    for (i = 0; i < size; i++) {
+        uint32_t min = tab[i];
+        int jmin = i;
+        for (j = i + 1; j < size; j++) {
+            if (tab[j] < min) {
+                jmin = j;
+                min = tab[j];
+            }
+        }
+        tmp = tab[i];
+        tab[i] = min;
+        tab[jmin] = tmp;
+    }
+}
+
+
+
+#define CLOCK_DEC uint32_t app_start;                   \
+                  uint32_t app_end;                     \
+                  uint32_t app_create;                  \
+                  uint32_t app_join;                    \
+                  uint32_t * thread_start;              \
+                  uint32_t * thread_end;                \
+                  uint32_t * thread_compute_start;      \
+                  uint32_t * thread_compute_end;        \
+                  int32_t step_number;                  \
+                  int32_t clock_thread_num;             \
+                  uint32_t ** thread_start_step;        \
+                  uint32_t ** thread_end_step;          \
+                  uint32_t global_thread_start;         \
+                  uint32_t global_thread_end;           \
+                  uint32_t global_thread_compute_start; \
+                  uint32_t global_thread_compute_end;   \
+                  uint32_t * global_thread_start_step;  \
+                  uint32_t * global_thread_end_step;    \
+
+#if TARGET_OS == GIETVM
+    #define CLOCK(x)  ({ x = giet_proctime(); })
+#elif TARGET_OS == LINUX
+    #define CLOCK(x)  ({                      \
+            struct timeval full_time;         \
+            gettimeofday(&full_time, NULL);   \
+            x = (unsigned long) ((full_time.tv_usec + full_time.tv_sec * 1000000) / 1000); \
+            })
+#endif
+
+// x = number of threads, y = number of steps
+#define CLOCK_INIT(x, y) ({                                                         \
+    clock_thread_num = (x);                                                         \
+    step_number = (y);                                                              \
+    global_thread_start = 0xFFFFFFFFLLU;                                            \
+    global_thread_end = 0;                                                          \
+    global_thread_compute_start = 0xFFFFFFFFLLU;                                    \
+    global_thread_compute_end = 0;                                                  \
+    if ((x) > 0) {                                                                  \
+        thread_start = (uint32_t *) malloc(sizeof(uint32_t) * (x));                 \
+        thread_end = (uint32_t *) malloc(sizeof(uint32_t) * (x));                   \
+        thread_compute_start = (uint32_t *) malloc(sizeof(uint32_t) * (x));         \
+        thread_compute_end = (uint32_t *) malloc(sizeof(uint32_t) * (x));           \
+        if ((y) > 0) {                                                              \
+            global_thread_start_step = (uint32_t *) malloc(sizeof(uint32_t) * (y)); \
+            global_thread_end_step = (uint32_t *) malloc(sizeof(uint32_t) * (y));   \
+            thread_start_step = (uint32_t **) malloc(sizeof(uint32_t *) * (y));     \
+            thread_end_step = (uint32_t **) malloc(sizeof(uint32_t *) * (y));       \
+            for (int j = 0; j < (y); j++) {                                         \
+                global_thread_start_step[j] = 0xFFFFFFFFLU;                         \
+                global_thread_end_step[j] = 0;                                      \
+                thread_start_step[j] = (uint32_t *) malloc(sizeof(uint32_t) * (x)); \
+                thread_end_step[j] = (uint32_t *) malloc(sizeof(uint32_t) * (x));   \
+            }                                                                       \
+        }                                                                           \
+    }                                                                               \
+})
+
+
+#define CLOCK_APP_START               ({ CLOCK(app_start); })
+#define CLOCK_APP_END                 ({ CLOCK(app_end); })
+#define CLOCK_APP_CREATE              ({ CLOCK(app_create); })
+#define CLOCK_APP_JOIN                ({ CLOCK(app_join); })
+#define CLOCK_THREAD_START(x)         ({ CLOCK(thread_start[x]); })
+#define CLOCK_THREAD_END(x)           ({ CLOCK(thread_end[x]); })
+#define CLOCK_THREAD_COMPUTE_START(x) ({ CLOCK(thread_compute_start[x]); })
+#define CLOCK_THREAD_COMPUTE_END(x)   ({ CLOCK(thread_compute_end[x]); })
+#define CLOCK_THREAD_START_STEP(x, y) ({ CLOCK(thread_start_step[y][x]); })
+#define CLOCK_THREAD_END_STEP(x, y)   ({ CLOCK(thread_end_step[y][x]); })
+
+
+// x = number of threads
+#define CLOCK_FINALIZE ({                                                \
+    for (int i = 0; i < clock_thread_num; i++) {                         \
+        if (thread_start[i] < global_thread_start) {                     \
+            global_thread_start = thread_start[i];                       \
+        }                                                                \
+        if (thread_compute_start[i] < global_thread_compute_start) {     \
+            global_thread_compute_start = thread_compute_start[i];       \
+        }                                                                \
+        if (thread_end[i] > global_thread_end) {                         \
+            global_thread_end = thread_end[i];                           \
+        }                                                                \
+        if (thread_compute_end[i] > global_thread_compute_end) {         \
+            global_thread_compute_end = thread_compute_end[i];           \
+        }                                                                \
+        for (int j = 0; j < step_number; j++) {                          \
+            if (thread_start_step[j][i] < global_thread_start_step[j]) { \
+                global_thread_start_step[j] = thread_start_step[j][i];   \
+            }                                                            \
+            if (thread_end_step[j][i] > global_thread_end_step[j]) {     \
+                global_thread_end_step[j] = thread_end_step[j][i];       \
+            }                                                            \
+        }                                                                \
+    }                                                                    \
+})
+
+#define PRINT_CLOCK ({                                                                                         \
+    printf("Timestamps:\n");                                                                                   \
+    printf("[APP_START]            : %d\n", app_start);                                                        \
+    printf("[APP_CREATE]           : %d\n", app_create);                                                       \
+    printf("[THREAD_START]         : %d\n", global_thread_start);                                              \
+    printf("[THREAD_COMPUTE_START] : %d\n", global_thread_compute_start);                                      \
+    for (int j = 0; j < step_number; j++) {                                                                    \
+        printf("[THREAD_START_STEP_%d]  : %d\n", j, global_thread_start_step[j]);                              \
+        printf("[THREAD_END_STEP_%d]    : %d\n", j, global_thread_end_step[j]);                                \
+    }                                                                                                          \
+    printf("[THREAD_COMPUTE_END]   : %d\n", global_thread_compute_end);                                        \
+    printf("[THREAD_END]           : %d\n", global_thread_end);                                                \
+    printf("[APP_JOIN]             : %d\n", app_join);                                                         \
+    printf("[APP_END]              : %d\n", app_end);                                                          \
+    printf("Durations (in cycles):\n");                                                                        \
+    printf("[TOTAL]                : %d\n", app_end - app_start);                                              \
+    printf("[THREAD]               : %d\n", app_join - app_create);                                            \
+    printf("[PARALLEL]             : %d\n", global_thread_end - global_thread_start);                          \
+    printf("[PARALLEL_COMPUTE]     : %d\n", global_thread_compute_end - global_thread_compute_start);          \
+    for (int j = 0; j < step_number; j++) {                                                                    \
+        printf("[THREAD_STEP_%d]        : %d\n", j, global_thread_end_step[j] - global_thread_start_step[j]);  \
+    }                                                                                                          \
+    printf("\n");                                                                                              \
+    printf("*** All threads times output in a gnuplot data-style ***\n");                                      \
+    local_sort_asc(thread_start, clock_thread_num);                                                            \
+    local_sort_asc(thread_compute_start, clock_thread_num);                                                    \
+    local_sort_asc(thread_compute_end, clock_thread_num);                                                      \
+    local_sort_asc(thread_end, clock_thread_num);                                                              \
+    for (int j = 0; j < step_number; j++) {                                                                    \
+        local_sort_asc(thread_start_step[j], clock_thread_num);                                                \
+        local_sort_asc(thread_end_step[j], clock_thread_num);                                                  \
+    }                                                                                                          \
+    printf("# cycle     thread_id\n");                                                                         \
+    for (int i = 0; i < clock_thread_num; i++) {                                                               \
+        printf("%d\t%d\n", thread_start[i], i);                                                                \
+        printf("%d\t%d\n", thread_compute_start[i], i);                                                        \
+        for (int j = 0; j < step_number; j++) {                                                                \
+            printf("%d\t%d\n", thread_start_step[j][i], i);                                                    \
+            printf("%d\t%d\n", thread_end_step[j][i], i);                                                      \
+        }                                                                                                      \
+        printf("%d\t%d\n", thread_compute_end[i], i);                                                          \
+        printf("%d\t%d\n", thread_end[i], i);                                                                  \
+    }                                                                                                          \
+})
+
+                
+
+
+
+
+#define CLOCK_FREE ({                                                \
+    if (clock_thread_num > 0) {                                      \
+        free(thread_start);                                          \
+        free(thread_end);                                            \
+        free(thread_compute_start);                                  \
+        free(thread_compute_end);                                    \
+        if (step_number > 0) {                                       \
+            free(global_thread_start_step);                          \
+            free(global_thread_end_step);                            \
+            for (int j = 0; j < step_number; j++) {                  \
+                free(thread_start_step[j]);                          \
+                free(thread_end_step[j]);                            \
+            }                                                        \
+            free(thread_start_step);                                 \
+            free(thread_end_step);                                   \
+        }                                                            \
+    }                                                                \
+})
+
+
+
+
+#endif
+
Index: soft/giet_vm/applications/rosenfeld/include/config.h
===================================================================
--- soft/giet_vm/applications/rosenfeld/include/config.h	(revision 821)
+++ soft/giet_vm/applications/rosenfeld/include/config.h	(revision 821)
@@ -0,0 +1,19 @@
+
+#define SLOW 0
+#define FEATURES 1
+#define FAST 1
+#define PYR_BARRIERS 0
+#define PARMERGE 1
+
+#if FAST && SLOW
+#error "FAST and SLOW cannot be defined at the same time"
+#endif
+
+#if PYR_BARRIERS && PARMERGE
+#error "PYR_BARRIERS and PARMERGE are exclusive"
+#endif
+
+#if PARMERGE && (!FEATURES || !FAST)
+#error "PARMERGE is only supported for the FAST version with FEATURES enabled"
+#endif
+
Index: soft/giet_vm/applications/rosenfeld/include/ecc_common.h
===================================================================
--- soft/giet_vm/applications/rosenfeld/include/ecc_common.h	(revision 820)
+++ soft/giet_vm/applications/rosenfeld/include/ecc_common.h	(revision 821)
@@ -6,23 +6,10 @@
 #define _ECC_COMMON_H_
 
-#ifdef __cplusplus
-#pragma message ("C++")
-extern "C" {
-#endif
-
-//#include <stdio.h>
-//#include <stdlib.h>
-//#include <math.h> 
-
-//#include "def.h"
-//#include "nrc.h"
-//#include "util.h"
-//#include "palette.h"
+#include <stdbool.h>
 
 // ------------------------------------------
 // -- valeur des parametres des benchmarks --
 // ------------------------------------------  
-//#define ENABLE_GLOBAL_PARAM
-//#ifdef ENABLE_GLOBAL_PARAM
+
 #define ECC_G0  1
 #define ECC_G1 16
@@ -207,5 +194,5 @@
 uint32 mt19937_uint32(uint32 a, uint32 b);
     
-BOOL strto_Bool(char *str);
+bool strto_Bool(char *str);
 
 void check_no_write(uint32 **T, int i0, int i1, int j0, int j1);
Index: soft/giet_vm/applications/rosenfeld/include/ecc_features.h
===================================================================
--- soft/giet_vm/applications/rosenfeld/include/ecc_features.h	(revision 820)
+++ soft/giet_vm/applications/rosenfeld/include/ecc_features.h	(revision 821)
@@ -16,20 +16,8 @@
 #define __ECC_FEATURES_H__
 
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#ifdef VERBOSE_PRAGMA
-//#pragma message("- include ecc_features.h")
-#endif
-
-#define REGION_STATS1
-
-//#define REGION_STATS2
-//#define REGION_STATS3
-//#define REGION_STATS4
-
-#define Warning 
-#define Error 
+#if PARMERGE
+#include <pthread.h>
+#endif
+
 
 // ------------------------------------------------------------------------
@@ -46,33 +34,10 @@
   uint32  S;
 
-  uint16  x;       // abscisse du centre d'inertie x = Sx / S
-  uint16  y;       // ordonnee du centre d'inertie y = Sy / S
-
   uint32  Sx;
   uint32  Sy;
-
-#ifdef REGION_STATS2
-  //uint64  Sx2;
-  //uint64  Sxy;
-  //uint64  Sy2;
-
-  //uint32  Mx2;
-  //uint32  Mxy;
-  //uint32  My2;
-
-  double teta; // direction principale
-#endif
-
-#ifdef REGION_STATS3
-  //uint64  Sx3;
-  //uint64  Sx2y;
-  //uint64  Sxy2;
-  //uint64  Sy3;
-
-  //uint64  Mx3;
-  //uint64  Mx2y;
-  //uint64  Mxy2;
-  //uint64  My3;
-#endif
+#if PARMERGE
+  pthread_spinlock_t lock;
+#endif
+
 } RegionStats;
 
@@ -112,4 +77,6 @@
  */
 
+
+
 /* ------------------------------ */
 /* --- RegionStats after 2009 --- */
@@ -118,4 +85,7 @@
 
 RegionStats* RegionStatsVector                 (int i0, int i1);
+#if TARGET_OS == GIETVM
+RegionStats * remote_RegionStatsVector         (int i0, int i1, int x, int y);
+#endif
 RegionStats* RegionStatsVector0                (int i0, int i1);
 void    free_RegionStatsVector (RegionStats *v, int i0, int i1);
@@ -219,5 +189,5 @@
    
 void RegionStats_Save_Stats1_Sparse(RegionStats *Stats, uint32 *EQ, uint32 ne0, uint32 ne1, char *filename);
-void RegionStats_DisplayStats_Sparse(uint32 *EQ, uint32 ne0, uint32 ne1, RegionStats *Stats, char *name);
+void RegionStats_DisplayStats_Sparse(uint32 *EQ, uint32 ne0, uint32 ne1, RegionStats *Stats, char *name, int * start_index);
 // affichage des Stats pour les etiquettes roots/ancetres de leur composante (pour algo Suzuki)
 
@@ -235,12 +205,5 @@
 void sortv_ui32matrix_col(uint32 **m, int i0, int i1, int j0, int j1, int col);
 void RegionStats_SortFeatures(RegionStats *Stats, uint32 nemax);
-    
-// version paralleles avec OpenMP2 ou OpenMP4
-void imageFeaturesComputation_omp0(uint32 **E, int height, int width, RegionStats *Stats); // wrong
-void imageFeaturesComputation_omp2(uint32 **E, int height, int width, RegionStats *Stats); // OpenMP 2.0 critical
-void imageFeaturesComputation_omp3(uint32 **E, int height, int width, RegionStats *Stats); // OpenMP 2.0 critical + atomic
-void imageFeaturesComputation_omp4(uint32 **E, int height, int width, RegionStats *Stats); // OpenMP 3.0 task + OpenMP 4.0 depend
-void imageFeaturesComputation_omp5(uint32 **E, int height, int width, uint16* Xmin, uint16* Xmax, uint16* Ymin, uint16* Ymax, uint32* S, uint32* Sx, uint32* Sy);
-    
+
 int RegionStats_Compare(RegionStats *S1, RegionStats *S2);
 int RegionStatsVector_Compare(RegionStats *S1, int i0, int i1, RegionStats *S2);
Index: soft/giet_vm/applications/rosenfeld/include/ecc_features_test.h
===================================================================
--- soft/giet_vm/applications/rosenfeld/include/ecc_features_test.h	(revision 820)
+++ 	(revision )
@@ -1,30 +1,0 @@
-// --------------------------- //
-// --- ecc_features_test.h --- //
-// --------------------------- //
-
-
-/*
- * Copyright (c) 2014 - 2014, Lionel Lacassagne, All rights reserved
- * University of Paris Sud, Laboratoire de Recherche en Informatique 
- */
-
-#ifndef __ECC_FEATURES_TEST_H__
-#define __ECC_FEATURES_TEST_H__
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#ifdef VERBOSE_PRAGMA
-//#pragma message("- include ecc_features.h")
-#endif
-
-void test1_granularit_density_features(void);
-    
- // void main_test_features(int argc, char* argv[]);    
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* __FEATURES_H__ */
Index: soft/giet_vm/applications/rosenfeld/include/mca.h
===================================================================
--- soft/giet_vm/applications/rosenfeld/include/mca.h	(revision 820)
+++ soft/giet_vm/applications/rosenfeld/include/mca.h	(revision 821)
@@ -14,30 +14,54 @@
 #define __MCA_H__
 
-#include <user_lock.h>
+#include "ecc_features.h"
+
+#include "nrc_os_config.h"
+
+#if TARGET_OS == GIETVM
+    #include <user_lock.h>
+    #include <user_barrier.h>
+#elif TARGET_OS == LINUX
+    #include <pthread.h>
+#endif
 
 
-#ifdef __cplusplus
-#ifdef VERBOSE_PRAGMA
-#pragma message ("C++")
-#endif
-extern "C" {
-#endif
+// QM : using mutex lock instead of mutexlock,
+// because apparently mutexlocks cause a bug in valgrind
+// (solved but the installed version is not recent enough)
+// cf. https://bugs.kde.org/show_bug.cgi?id=336435
+pthread_mutex_t print_lock;
 
-user_lock_t print_lock;
-
-#define MCA_VERBOSE0(X) ({         \
-        lock_acquire(&print_lock); \
-        X;                         \
-        lock_release(&print_lock); \
+#define MCA_VERBOSE0(X) ({                 \
+        pthread_mutex_lock(&print_lock);   \
+        X;                                 \
+        pthread_mutex_unlock(&print_lock); \
         })
-#define MCA_VERBOSE1(X) ({         \
-        lock_acquire(&print_lock); \
-        X;                         \
-        lock_release(&print_lock); \
+#define MCA_VERBOSE1(X) ({                 \
+        pthread_mutex_lock(&print_lock);   \
+        X;                                 \
+        pthread_mutex_unlock(&print_lock); \
+        })
+#define MCA_DISPLAY0(X) ({                 \
+        pthread_mutex_lock(&print_lock);   \
+        X;                                 \
+        pthread_mutex_unlock(&print_lock); \
+        })
+#define MCA_DISPLAY1(X) ({                 \
+        pthread_mutex_lock(&print_lock);   \
+        X;                                 \
+        pthread_mutex_unlock(&print_lock); \
         })
 
 
-//#define MCA_VERBOSE2(X) X
-#define MCA_VERBOSE2(X) 
+#define MCA_VERBOSE2(X)
+/*
+#define MCA_VERBOSE2(X) ({                 \
+        pthread_mutex_lock(&print_lock);   \
+        X;                                 \
+        pthread_mutex_unlock(&print_lock); \
+        })
+*/
+
+#define MCA_DISPLAY2(X) 
 
 
@@ -56,17 +80,21 @@
     
     uint32 e0, e1; // indice pour chaque bande
-    uint32 ne; // indice max d'etiquettes utilise par bande
+    uint32 ne;     // indice max d'etiquettes utilise par bande
 
-    int alpha; // puissance de 2 >= a la taille d'un bloc
-    //uint32 *I;
-    uint32  *T; // table d'quivalence table (Rosenfeld) ou d'indices (Warp)
-    uint32 **D; // distributed table (instanciee dans chaque worker)
+    int alpha;     // puissance de 2 >= a la taille d'un bloc
+    uint32  * T;   // table d'quivalence table (Rosenfeld) ou d'indices (Warp)
+    uint32 ** D;   // distributed table (instanciee dans chaque worker)
     
-    //RegionStats *Stats;
+    RegionStats * stats;
+    RegionStats ** F;
     
     struct sMCA * mca;   // pointeur vers le maitre (pour les esclaves)
     struct sMCA ** mcas; // tableau de pointeurs vers les workers
+
+    // For pyramidal barriers
+    int nb_level;
+    pthread_barrier_t * barriers;
 } MCA;
-    
+ 
 void MCA_Error(char * msg);
 
@@ -77,6 +105,6 @@
 void MCA_Set_ImageL(MCA * mca, uint32 ** E);
 
-void   MCA_Set_Size(MCA * mca, int width, int height);
-void   MCA_Set_NP(MCA * mca, int np);
+void MCA_Set_Size(MCA * mca, int width, int height);
+void MCA_Set_NP(MCA * mca, int np);
 
 uint32 MCA_CalcMaxLabels(int connection, uint32 height, uint32 width);
@@ -99,7 +127,4 @@
 void MCA_Warp(MCA * mca);
 
-#ifdef __cplusplus
-}
-#endif
 
 #endif // __MCA_H__
Index: soft/giet_vm/applications/rosenfeld/include/mca_matrix_dist.h
===================================================================
--- soft/giet_vm/applications/rosenfeld/include/mca_matrix_dist.h	(revision 820)
+++ soft/giet_vm/applications/rosenfeld/include/mca_matrix_dist.h	(revision 821)
@@ -13,4 +13,7 @@
 uint32 ** dist_ui32matrix(int i0, int i1, int j0, int j1);
 void free_dist_ui32matrix(uint32 ** m, int i0, int i1, int j0, int j1);
+#if TARGET_OS == GIETVM
+uint32 ** remote_dist_ui32matrix(int i0, int i1, int j0, int j1, int x, int y);
+#endif
 
 #ifdef __cplusplus
Index: soft/giet_vm/applications/rosenfeld/include/mca_rosenfeld.h
===================================================================
--- soft/giet_vm/applications/rosenfeld/include/mca_rosenfeld.h	(revision 820)
+++ soft/giet_vm/applications/rosenfeld/include/mca_rosenfeld.h	(revision 821)
@@ -16,11 +16,4 @@
 #include "mca.h"
 
-#ifdef __cplusplus
-#ifdef VERBOSE_PRAGMA
-#pragma message ("C++")
-#endif
-extern "C" {
-#endif
-
 uint32 line0Labeling_Rosenfeld  (uint8 ** X, int i, int width, uint32 ** E, uint32 * T, uint32 ne);
 uint32 lineLabeling_DT_Rosenfeld(uint8 ** X, int i, int width, uint32 ** E, uint32 * T, uint32 ne);
@@ -29,10 +22,7 @@
 void   solveTable_Range_Rosenfeld(uint32 * T, uint32 e0, uint32 e1);
 
-void MCA_Label_Rosenfeld(MCA * mca);
+void * MCA_Label_Rosenfeld(void * arg);
+void * MCA_Label_Features_Rosenfeld(void * arg);
     
-#ifdef __cplusplus
-}
-#endif
-
 #endif // __MCA_ROSENFELD_H__
 
Index: soft/giet_vm/applications/rosenfeld/include/mca_test.h
===================================================================
--- soft/giet_vm/applications/rosenfeld/include/mca_test.h	(revision 820)
+++ 	(revision )
@@ -1,30 +1,0 @@
-/* ------------------ */
-/* --- mca_test.h --- */
-/* ------------------ */
-
-/*
- * Copyright (c) 2016 Lionel Lacassagne, LIP6, UPMC, CNRS
- * Init  : 2016/03/03
- */
-
-// Multi/Many Cores Connected Component Computation en Analysis
-// extension of pixel-based and run-based algorithm to manycores with distributed memory
-
-#ifndef __MCA_TEST_H__
-#define __MCA_TEST_H__
-
-#ifdef __cplusplus
-#ifdef VERBOSE_PRAGMA
-#pragma message ("C++")
-#endif
-extern "C" {
-#endif
-
-int main_test_mca();
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif // __MCA_TEST_H__
-
Index: soft/giet_vm/applications/rosenfeld/nrc2/Makefile
===================================================================
--- soft/giet_vm/applications/rosenfeld/nrc2/Makefile	(revision 820)
+++ soft/giet_vm/applications/rosenfeld/nrc2/Makefile	(revision 821)
@@ -7,7 +7,8 @@
 
 # -- File list ----------
-FILE = nralloc1.c, nralloc2.c, nralloc2x.c, nrarith0.c, nrarith1.c, nrarith2.c, nrarith2x.c, nrbool1.c, nrbool2.c, nrhisto.c, nrio0.c, nrio1.c, nrio2.c, nrkernel.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
+FILE = nralloc1.c, nralloc2.c, nralloc2x.c, nrarith0.c, nrarith1.c, nrarith2.c, nrarith2x.c, nrbool1.c, nrbool2.c, nrhisto.c, nrio0.c, nrio1.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
 
 
+TARGET ?= linux
 
 # -- Paths ----------
@@ -15,4 +16,15 @@
 OBJ_PATH = obj
 INC_PATH = include
+
+ifeq ($(TARGET),giet-vm)
+
+CC      = mipsel-unknown-elf-gcc
+AR      = mipsel-unknown-elf-ar
+RANLIB  = mipsel-unknown-elf-ranlib
+AS      = mipsel-unknown-elf-as
+OD      = mipsel-unknown-elf-objdump
+OCPY    = mipsel-unknown-elf-objcopy
+LD      = mipsel-unknown-elf-ld
+NM      = mipsel-unknown-elf-nm
 
 
@@ -22,4 +34,23 @@
 C_CONFIG_FLAGS = -DCLI
 C_INC_FLAGS = -I$(INC_PATH) -I../../.. -I../../../giet_libs
+CFLAGSCPU := -mips32 -EL -G0 -mhard-float
+
+endif
+
+ifeq ($(TARGET),linux)
+
+CC = gcc
+LD = gcc
+AR = ar
+RANLIB = ranlib
+
+C_DEBUG_FLAGS = -O0
+C_OPTIMISATION_FLAGS = -std=c99 -O2 -fstrict-aliasing
+C_OS_FLAGS = -DGTODay -DTARGET_OS=LINUX
+C_CONFIG_FLAGS = -DCLI
+C_INC_FLAGS = -I$(INC_PATH)
+
+endif
+
 
 # -- Flags ----------
@@ -30,15 +61,6 @@
 # CC tools and parameters
 #------------------------------------------------------------------------------
-CC      = mipsel-unknown-elf-gcc
-AR      = mipsel-unknown-elf-ar -cr
-RANLIB  = mipsel-unknown-elf-ranlib
-AS      = mipsel-unknown-elf-as
-OD      = mipsel-unknown-elf-objdump
-OCPY    = mipsel-unknown-elf-objcopy
-LD      = mipsel-unknown-elf-ld
-NM      = mipsel-unknown-elf-nm
 
 CFLAGSW := -Wredundant-decls -Wdisabled-optimization -Winline -Wpointer-arith -Wsign-compare -Wendif-labels
-CFLAGSCPU := -mips32 -EL -G0 -mhard-float
 CFLAGS := $(CFLAGS) -g -Wall -fomit-frame-pointer $(CFLAGSW) $(CFLAGSCPU) -fno-builtin -ffreestanding
 
@@ -55,5 +77,5 @@
 
 $(PRODUCT): $(OBJS)
-	$(AR) $@ $^
+	$(AR) -cr $@ $^
 	$(RANLIB) $@ 
 
Index: soft/giet_vm/applications/rosenfeld/nrc2/include/nralloc.h
===================================================================
--- soft/giet_vm/applications/rosenfeld/nrc2/include/nralloc.h	(revision 820)
+++ soft/giet_vm/applications/rosenfeld/nrc2/include/nralloc.h	(revision 821)
@@ -11,12 +11,4 @@
 #define __NRALLOC_H__
 
-#ifdef __cplusplus
-#pragma message ("C++")
-extern "C" {
-#endif
-    
-#ifdef VERBOSE_PRAGMA
-//#pragma message ("- *** include nralloc.h ***")
-#endif
 
 #include "nralloc1.h"
@@ -24,7 +16,4 @@
 #include "nralloc3.h"
 
-#ifdef __cplusplus
-}
-#endif
+#endif /* __NRALLOC_H__ */
 
-#endif /* __NRALLOC_H__ */
Index: soft/giet_vm/applications/rosenfeld/nrc2/include/nralloc1.h
===================================================================
--- soft/giet_vm/applications/rosenfeld/nrc2/include/nralloc1.h	(revision 820)
+++ soft/giet_vm/applications/rosenfeld/nrc2/include/nralloc1.h	(revision 821)
@@ -11,25 +11,8 @@
 #define __NRALLOC1_H__
 
-#ifdef __cplusplus
-#pragma message ("C++")
-extern "C" {
-#endif
-    
-#ifdef VERBOSE_PRAGMA
-//#pragma message ("- *** include nralloc1.h ***")
-#endif
+#include <stdint.h>
 
-
-//NR_END est maintenant defini dans nrutil.h
-
-#define NR_END 0
-#define FREE_ARG char*
-
-//long nr_end = NR_END;
-
-//void nrerror(char error_text[]);
-//void nrerror(char *format, ...);
-//void Error  (char *format, ...);
-//void Warning(char *format, ...);
+#include "nrc_os_config.h"
+#include "nrtype.h"
 
 /*
@@ -39,86 +22,110 @@
  */
 
-// do: allocate a float vector with subscript range v[nl..nh]
+#define type_vector(t) \
+t * short_name(t,,vector)(int32_t nl, int32_t nh)
 
-//IMAGE_EXPORT(byte*)      bvector(long nl, long nh);
-IMAGE_EXPORT(sint8*)   si8vector(long nl, long nh);
-IMAGE_EXPORT(uint8*)   ui8vector(long nl, long nh);
-IMAGE_EXPORT(sint16*) si16vector(long nl, long nh);
-IMAGE_EXPORT(uint16*) ui16vector(long nl, long nh);
-IMAGE_EXPORT(sint32*) si32vector(long nl, long nh);
-IMAGE_EXPORT(uint32*) ui32vector(long nl, long nh);
-IMAGE_EXPORT(sint64*) si64vector(long nl, long nh);
-IMAGE_EXPORT(uint64*) ui64vector(long nl, long nh);
+type_vector(int8_t);
+type_vector(uint8_t);
+type_vector(int16_t);
+type_vector(uint16_t);
+type_vector(int32_t);
+type_vector(uint32_t);
+type_vector(int64_t);
+type_vector(uint64_t);
+type_vector(float);
+type_vector(double);
+type_vector(rgb8);
+type_vector(rgbx8);
+type_vector(rgb32);
+type_vector(void_p);
 
-IMAGE_EXPORT(float32*) f32vector(long nl, long nh);
-IMAGE_EXPORT(float64*) f64vector(long nl, long nh);
 
-IMAGE_EXPORT(rgb8*)   rgb8vector(long nl, long nh);
-IMAGE_EXPORT(rgbx8*) rgbx8vector(long nl, long nh);
-IMAGE_EXPORT(rgb32*) rgb32vector(long nl, long nh);
 
-IMAGE_EXPORT(void**)     vvector(long nl, long nh);
+#if TARGET_OS == GIETVM
+#define remote_type_vector(t) \
+t * short_name(t,remote_,vector)(int32_t nl, int32_t nh, int32_t x, int32_t y)
+
+remote_type_vector(int8_t);
+remote_type_vector(uint8_t);
+remote_type_vector(int16_t);
+remote_type_vector(uint16_t);
+remote_type_vector(int32_t);
+remote_type_vector(uint32_t);
+remote_type_vector(int64_t);
+remote_type_vector(uint64_t);
+remote_type_vector(float);
+remote_type_vector(double);
+remote_type_vector(rgb8);
+remote_type_vector(rgbx8);
+remote_type_vector(rgb32);
+remote_type_vector(void_p);
+
+//void ** remote_vvector(long nl, long nh, int x, int y);
+#endif
+
+#define type_vector0(t) \
+t * short_name(t,,vector0)(int32_t nl, int32_t nh)
+
+type_vector0(int8_t);
+type_vector0(uint8_t);
+type_vector0(int16_t);
+type_vector0(uint16_t);
+type_vector0(int32_t);
+type_vector0(uint32_t);
+type_vector0(int64_t);
+type_vector0(uint64_t);
+type_vector0(float);
+type_vector0(double);
+type_vector0(rgb8);
+type_vector0(rgbx8);
+type_vector0(rgb32);
+type_vector0(void_p);
+
+#define realloc_type_vector(t) \
+t * short_name(t,realloc_,vector)(t * v, int32_t nl, int32_t nh)
+
+realloc_type_vector(int8_t);
+realloc_type_vector(uint8_t);
+realloc_type_vector(int16_t);
+realloc_type_vector(uint16_t);
+realloc_type_vector(int32_t);
+realloc_type_vector(uint32_t);
+realloc_type_vector(int64_t);
+realloc_type_vector(uint64_t);
+realloc_type_vector(float);
+realloc_type_vector(double);
+realloc_type_vector(rgb8);
+realloc_type_vector(rgbx8);
+realloc_type_vector(rgb32);
+realloc_type_vector(void_p);
+
+
+#define free_type_vector(t) \
+void short_name(t,free_,vector)(t * v, long nl, long nh)
+
+free_type_vector(int8_t);
+free_type_vector(uint8_t);
+free_type_vector(int16_t);
+free_type_vector(uint16_t);
+free_type_vector(int32_t);
+free_type_vector(uint32_t);
+free_type_vector(int64_t);
+free_type_vector(uint64_t);
+free_type_vector(float);
+free_type_vector(double);
+free_type_vector(rgb8);
+free_type_vector(rgbx8);
+free_type_vector(rgb32);
+free_type_vector(void_p);
+
+
 
 /*
- * ---------------
- * --- vector0 ---
- * ---------------
- */
-
-// do: allocate a vector and set it to 0
-
-//IMAGE_EXPORT(byte*)       bvector0(long nl, long nh);
-IMAGE_EXPORT(sint8*)    si8vector0(long nl, long nh);
-IMAGE_EXPORT(uint8*)    ui8vector0(long nl, long nh);
-IMAGE_EXPORT(sint16*)  si16vector0(long nl, long nh);
-IMAGE_EXPORT(uint16*)  ui16vector0(long nl, long nh);
-IMAGE_EXPORT(sint32*)  si32vector0(long nl, long nh);
-IMAGE_EXPORT(uint32*)  ui32vector0(long nl, long nh);
-
-IMAGE_EXPORT(float32*) f32vector0(long nl, long nh);
-IMAGE_EXPORT(float64*) f64vector0(long nl, long nh);
-
-IMAGE_EXPORT(rgb8*)   rgb8vector0(long nl, long nh);
-IMAGE_EXPORT(rgbx8*) rgbx8vector0(long nl, long nh);
-IMAGE_EXPORT(rgb32*) rgb32vector0(long nl, long nh);
-
-IMAGE_EXPORT(void**)     vvector0(long nl, long nh);
-/*
- * ----------------------
- * --- realloc_vector ---
- * ----------------------
- */
-
-// realloc a vector to [nl..nh]
-IMAGE_EXPORT(void**)  realloc_vvector(void   **v, long nl, long nh);
-
-/*
- * -------------------
- * --- free_vector ---
- * -------------------
- */
-
-//IMAGE_EXPORT(void) free_bvector    (byte    *v, long nl, long nh);
-IMAGE_EXPORT(void) free_si8vector  (sint8   *v, long nl, long nh);
-IMAGE_EXPORT(void) free_ui8vector  (uint8   *v, long nl, long nh);
-IMAGE_EXPORT(void) free_si16vector (sint16  *v, long nl, long nh);
-IMAGE_EXPORT(void) free_ui16vector (uint16  *v, long nl, long nh);
-IMAGE_EXPORT(void) free_si32vector (sint32  *v, long nl, long nh);
-IMAGE_EXPORT(void) free_ui32vector (uint32  *v, long nl, long nh);
-IMAGE_EXPORT(void) free_si64vector (sint64  *v, long nl, long nh);
-IMAGE_EXPORT(void) free_ui64vector (uint64  *v, long nl, long nh);
-
-IMAGE_EXPORT(void) free_f32vector  (float32 *v, long nl, long nh);
-IMAGE_EXPORT(void) free_f64vector  (float64 *v, long nl, long nh);
-
-IMAGE_EXPORT(void) free_rgb8vector (rgb8    *v, long nl, long nh);
-IMAGE_EXPORT(void) free_rgbx8vector(rgbx8   *v, long nl, long nh);
-IMAGE_EXPORT(void) free_rgb32vector(rgb32   *v, long nl, long nh);
-
-IMAGE_EXPORT(void) free_vvector    (void   **v, long nl, long nh);
-
-#ifdef __cplusplus
-}
-#endif
+void ** vvector(long nl, long nh);
+void ** vvector0(long nl, long nh);
+void ** realloc_vvector(void ** v, long nl, long nh);
+void free_vvector(void ** v, long nl, long nh);
+*/
 
 #endif /* __NRALLOC1_H__ */
+
Index: soft/giet_vm/applications/rosenfeld/nrc2/include/nralloc2.h
===================================================================
--- soft/giet_vm/applications/rosenfeld/nrc2/include/nralloc2.h	(revision 820)
+++ soft/giet_vm/applications/rosenfeld/nrc2/include/nralloc2.h	(revision 821)
@@ -16,12 +16,5 @@
 #define __NRALLOC2_H__
 
-#ifdef __cplusplus
-#pragma message ("C++")
-extern "C" {
-#endif
-    
-#ifdef VERBOSE_PRAGMA
-//#pragma message ("- *** include nralloc2.h ***")
-#endif
+#include "nrc_os_config.h"
 
 /*
@@ -31,74 +24,111 @@
  */
 
-IMAGE_EXPORT(sint8**)     si8matrix(long nrl, long nrh, long ncl, long nch);
-IMAGE_EXPORT(uint8**)     ui8matrix(long nrl, long nrh, long ncl, long nch);
-IMAGE_EXPORT(sint16**)   si16matrix(long nrl, long nrh, long ncl, long nch);
-IMAGE_EXPORT(uint16**)   ui16matrix(long nrl, long nrh, long ncl, long nch);
-IMAGE_EXPORT(sint32**)   si32matrix(long nrl, long nrh, long ncl, long nch);
-IMAGE_EXPORT(uint32**)   ui32matrix(long nrl, long nrh, long ncl, long nch);
-IMAGE_EXPORT(sint64**)   si64matrix(long nrl, long nrh, long ncl, long nch);
-IMAGE_EXPORT(uint64**)   ui64matrix(long nrl, long nrh, long ncl, long nch);
 
-IMAGE_EXPORT(float32**)   f32matrix(long nrl, long nrh, long ncl, long nch);
-IMAGE_EXPORT(float64**)   f64matrix(long nrl, long nrh, long ncl, long nch);
+#undef type_matrix
+#define type_matrix(t) \
+t ** short_name(t,,matrix)(int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch)
 
-IMAGE_EXPORT(complex32**) c32matrix(long nrl, long nrh, long ncl, long nch);
-IMAGE_EXPORT(complex64**) c64matrix(long nrl, long nrh, long ncl, long nch);
 
-IMAGE_EXPORT(rgb8**)     rgb8matrix(long nrl, long nrh, long ncl, long nch);
-IMAGE_EXPORT(rgbx8**)   rgbx8matrix(long nrl, long nrh, long ncl, long nch);
-//IMAGE_EXPORT(rgb32**)   rgb32matrix(long nrl, long nrh, long ncl, long nch);
-//IMAGE_EXPORT(rgbx32**) rgbx32matrix(long nrl, long nrh, long ncl, long nch);
+type_matrix(int8_t);
+type_matrix(uint8_t);
+type_matrix(int16_t);
+type_matrix(uint16_t);
+type_matrix(int32_t);
+type_matrix(uint32_t);
+type_matrix(int64_t);
+type_matrix(uint64_t);
+type_matrix(float);
+type_matrix(double);
+type_matrix(void_p);
+type_matrix(rgb8);
+type_matrix(rgbx8);
+type_matrix(rgb32);
+type_matrix(rgbx32);
+type_matrix(complex32);
+type_matrix(complex64);
 
-/*
- * ---------------
- * --- matrix0 ---
- * ---------------
- */
 
-IMAGE_EXPORT(sint8**)     si8matrix0(long nrl, long nrh, long ncl, long nch);
-IMAGE_EXPORT(uint8**)     ui8matrix0(long nrl, long nrh, long ncl, long nch);
-IMAGE_EXPORT(sint16**)   si16matrix0(long nrl, long nrh, long ncl, long nch);
-IMAGE_EXPORT(uint16**)   ui16matrix0(long nrl, long nrh, long ncl, long nch);
-IMAGE_EXPORT(sint32**)    i32matrix0(long nrl, long nrh, long ncl, long nch);
-IMAGE_EXPORT(uint32**)   ui32matrix0(long nrl, long nrh, long ncl, long nch);
-IMAGE_EXPORT(sint64**)   si64matrix0(long nrl, long nrh, long ncl, long nch);
-IMAGE_EXPORT(uint64**)   ui64matrix0(long nrl, long nrh, long ncl, long nch);
-IMAGE_EXPORT(rgb8**)     rgb8matrix0(long nrl, long nrh, long ncl, long nch);
-IMAGE_EXPORT(rgbx8**)   rgbx8matrix0(long nrl, long nrh, long ncl, long nch);
-IMAGE_EXPORT(rgb32**)   rgb32matrix0(long nrl, long nrh, long ncl, long nch);
-IMAGE_EXPORT(rgbx32**) rgbx32matrix0(long nrl, long nrh, long ncl, long nch);
+#undef type_matrix0
+#define type_matrix0(t) \
+t ** short_name(t,,matrix0)(int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch)
 
-IMAGE_EXPORT(float32**)   f32matrix0(long nrl, long nrh, long ncl, long nch);
-IMAGE_EXPORT(float64**)   f64matrix0(long nrl, long nrh, long ncl, long nch);
 
-/*
- * -------------------
- * --- free_matrix ---
- * -------------------
- */ 
+type_matrix0(int8_t);
+type_matrix0(uint8_t);
+type_matrix0(int16_t);
+type_matrix0(uint16_t);
+type_matrix0(int32_t);
+type_matrix0(uint32_t);
+type_matrix0(int64_t);
+type_matrix0(uint64_t);
+type_matrix0(float);
+type_matrix0(double);
+type_matrix0(void_p);
+type_matrix0(rgb8);
+type_matrix0(rgbx8);
+type_matrix0(rgb32);
+type_matrix0(rgbx32);
+type_matrix0(complex32);
+type_matrix0(complex64);
 
-IMAGE_EXPORT(void) free_si8matrix  (sint8  **m, long nrl, long nrh, long ncl, long nch);
-IMAGE_EXPORT(void) free_ui8matrix  (uint8  **m, long nrl, long nrh, long ncl, long nch);
-IMAGE_EXPORT(void) free_si16matrix (sint16 **m, long nrl, long nrh, long ncl, long nch);
-IMAGE_EXPORT(void) free_ui16matrix (uint16 **m, long nrl, long nrh, long ncl, long nch);
-IMAGE_EXPORT(void) free_si32matrix (sint32 **m, long nrl, long nrh, long ncl, long nch);
-IMAGE_EXPORT(void) free_ui32matrix (uint32 **m, long nrl, long nrh, long ncl, long nch);
-IMAGE_EXPORT(void) free_si64matrix (sint64 **m, long nrl, long nrh, long ncl, long nch);
-IMAGE_EXPORT(void) free_ui64matrix (uint64 **m, long nrl, long nrh, long ncl, long nch);
 
-IMAGE_EXPORT(void) free_f32matrix (float32   **m, long nrl, long nrh, long ncl, long nch);
-IMAGE_EXPORT(void) free_f64matrix (float64   **m, long nrl, long nrh, long ncl, long nch);
-IMAGE_EXPORT(void) free_c32matrix (complex32 **m, long nrl, long nrh, long ncl, long nch);
-IMAGE_EXPORT(void) free_c64matrix (complex64 **m, long nrl, long nrh, long ncl, long nch);
+#if TARGET_OS == GIETVM
 
-IMAGE_EXPORT(void) free_rgb8matrix  (rgb8   **m, long nrl, long nrh, long ncl, long nch);
-IMAGE_EXPORT(void) free_rgbx8matrix (rgbx8  **m, long nrl, long nrh, long ncl, long nch);
-IMAGE_EXPORT(void) free_rgb32matrix (rgb32  **m, long nrl, long nrh, long ncl, long nch);
-IMAGE_EXPORT(void) free_rgbx32matrix(rgbx32 **m, long nrl, long nrh, long ncl, long nch);
+#undef remote_type_matrix
+#define remote_type_matrix(t) \
+t ** short_name(t,remote_,matrix)(int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch)
 
-#ifdef __cplusplus
-}
+remote_type_matrix(int8_t);
+remote_type_matrix(uint8_t);
+remote_type_matrix(int16_t);
+remote_type_matrix(uint16_t);
+remote_type_matrix(int32_t);
+remote_type_matrix(uint32_t);
+remote_type_matrix(int64_t);
+remote_type_matrix(uint64_t);
+remote_type_matrix(float);
+remote_type_matrix(double);
+remote_type_matrix(void_p);
+remote_type_matrix(rgb8);
+remote_type_matrix(rgbx8);
+remote_type_matrix(rgb32);
+remote_type_matrix(rgbx32);
+remote_type_matrix(complex32);
+remote_type_matrix(complex64);
+
 #endif
 
+
+#undef free_type_matrix
+#define free_type_matrix(t) \
+void short_name(t,free_,matrix)(t ** m, int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch)
+
+free_type_matrix(int8_t);
+free_type_matrix(uint8_t);
+free_type_matrix(int16_t);
+free_type_matrix(uint16_t);
+free_type_matrix(int32_t);
+free_type_matrix(uint32_t);
+free_type_matrix(int64_t);
+free_type_matrix(uint64_t);
+free_type_matrix(float);
+free_type_matrix(double);
+free_type_matrix(void_p);
+free_type_matrix(rgb8);
+free_type_matrix(rgbx8);
+free_type_matrix(rgb32);
+free_type_matrix(rgbx32);
+free_type_matrix(complex32);
+free_type_matrix(complex64);
+
+
 #endif /* __NRALLOC2_H__ */
+
+// Local Variables:
+// tab-width: 4
+// c-basic-offset: 4
+// c-file-offsets:((innamespace . 0)(inline-open . 0))
+// indent-tabs-mode: nil
+// End:
+// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4
+
Index: soft/giet_vm/applications/rosenfeld/nrc2/include/nralloc2x.h
===================================================================
--- soft/giet_vm/applications/rosenfeld/nrc2/include/nralloc2x.h	(revision 820)
+++ soft/giet_vm/applications/rosenfeld/nrc2/include/nralloc2x.h	(revision 821)
@@ -16,43 +16,9 @@
 #define __NRALLOC2X_H__
 
-#ifdef __cplusplus
-#pragma message ("C++")
-extern "C" {
-#endif
-    
-#ifdef VERBOSE_PRAGMA
-//#pragma message ("- *** include nralloc2x.h ***")
-#endif
 
+#include "nrc_os_config.h"
 #include "nrtype.h"
 #include "nrtypex.h"
 
-/* ---------------------------------- */
-/* --- composite user type matrix --- */
-/* ---------------------------------- */
-
-IMAGE_EXPORT(si16Point**)   si16Pmatrix(long nrl, long nrh, long ncl, long nch);
-IMAGE_EXPORT(ui16Point**)   ui16Pmatrix(long nrl, long nrh, long ncl, long nch);
-IMAGE_EXPORT(si32Point**)   si32Pmatrix(long nrl, long nrh, long ncl, long nch);
-IMAGE_EXPORT(ui32Point**)   ui32Pmatrix(long nrl, long nrh, long ncl, long nch);
-IMAGE_EXPORT(f32Point**)     f32Pmatrix(long nrl, long nrh, long ncl, long nch);
-
-IMAGE_EXPORT(si16Triplet**) si16Tmatrix(long nrl, long nrh, long ncl, long nch);
-IMAGE_EXPORT(ui16Triplet**) ui16Tmatrix(long nrl, long nrh, long ncl, long nch);
-IMAGE_EXPORT(si32Triplet**) si32Tmatrix(long nrl, long nrh, long ncl, long nch);
-IMAGE_EXPORT(ui32Triplet**) ui32Tmatrix(long nrl, long nrh, long ncl, long nch);
-IMAGE_EXPORT(f32Triplet**)   f32Tmatrix(long nrl, long nrh, long ncl, long nch);
-
-IMAGE_EXPORT(void) free_si16Pmatrix(si16Point **m, long nrl, long nrh, long ncl, long nch);
-IMAGE_EXPORT(void) free_ui16Pmatrix(ui16Point **m, long nrl, long nrh, long ncl, long nch);
-IMAGE_EXPORT(void) free_si32Pmatrix(si32Point **m, long nrl, long nrh, long ncl, long nch);
-IMAGE_EXPORT(void) free_ui32Pmatrix(ui32Point **m, long nrl, long nrh, long ncl, long nch);
-IMAGE_EXPORT(void) free_f32Pmatrix(f32Point   **m, long nrl, long nrh, long ncl, long nch);
-
-IMAGE_EXPORT(void) free_si16Tmatrix(si16Triplet **m, long nrl, long nrh, long ncl, long nch);
-IMAGE_EXPORT(void) free_ui16Tmatrix(ui16Triplet **m, long nrl, long nrh, long ncl, long nch);
-IMAGE_EXPORT(void) free_si32Tmatrix(si32Triplet **m, long nrl, long nrh, long ncl, long nch);
-IMAGE_EXPORT(void) free_ui32Tmatrix(ui32Triplet **m, long nrl, long nrh, long ncl, long nch);
-IMAGE_EXPORT(void) free_f32Tmatrix ( f32Triplet **m, long nrl, long nrh, long ncl, long nch);
 
 /* ----------------- */
@@ -60,15 +26,25 @@
 /* ----------------- */
 
-IMAGE_EXPORT(byte**)      btrimatrix(long nrl, long nrh, long ncl, long nch, long step);
-IMAGE_EXPORT(sint16**) si16trimatrix(long nrl, long nrh, long ncl, long nch, long step);
-IMAGE_EXPORT(uint16**) ui16trimatrix(long nrl, long nrh, long ncl, long nch, long step);
-IMAGE_EXPORT(sint32**) si32trimatrix(long nrl, long nrh, long ncl, long nch, long step);
-IMAGE_EXPORT(uint32**) ui32trimatrix(long nrl, long nrh, long ncl, long nch, long step);
-IMAGE_EXPORT(float32**) f32trimatrix(long nrl, long nrh, long ncl, long nch, long step);
-IMAGE_EXPORT(float64**) f64trimatrix(long nrl, long nrh, long ncl, long nch, long step);
+#define type_trimatrix(t) \
+t ** short_name(t,,trimatrix)(int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch, int32_t step)
 
-#ifdef __cplusplus
-}
-#endif
+type_trimatrix(int8_t);
+type_trimatrix(uint8_t);
+type_trimatrix(int16_t);
+type_trimatrix(uint16_t);
+type_trimatrix(int32_t);
+type_trimatrix(uint32_t);
+type_trimatrix(float);
+type_trimatrix(double);
+
 
 #endif /* __NRALLOC2X_H__ */
+
+// Local Variables:
+// tab-width: 4
+// c-basic-offset: 4
+// c-file-offsets:((innamespace . 0)(inline-open . 0))
+// indent-tabs-mode: nil
+// End:
+// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4
+
Index: soft/giet_vm/applications/rosenfeld/nrc2/include/nralloc3.h
===================================================================
--- soft/giet_vm/applications/rosenfeld/nrc2/include/nralloc3.h	(revision 820)
+++ soft/giet_vm/applications/rosenfeld/nrc2/include/nralloc3.h	(revision 821)
@@ -13,43 +13,52 @@
 #define __NRALLOC3_H__
 
-#ifdef __cplusplus
-#pragma message ("C++")
-extern "C" {
-#endif
-    
-#ifdef VERBOSE_PRAGMA
-//#pragma message ("- *** include nralloc3.h ***")
-#endif
+#include "nrc_os_config.h"
 
-double*** d3tensor(long nrl, long nrh, long ncl, long nch, long ndl, long ndh);
-void free_d3tensor(double  ***t,long nrl,long nrh,long ncl,long nch,long ndl,long ndh);
+//double*** d3tensor(long nrl, long nrh, long ncl, long nch, long ndl, long ndh);
+//void free_d3tensor(double  ***t,long nrl,long nrh,long ncl,long nch,long ndl,long ndh);
+
+#define type_cube(t) \
+t *** short_name(t,,cube)(int32_t ndl, int32_t ndh, int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch) \
 
 
+type_cube(int8_t);
+type_cube(uint8_t);
+type_cube(int16_t);
+type_cube(uint16_t);
+type_cube(int32_t);
+type_cube(uint32_t);
+type_cube(int64_t);
+type_cube(uint64_t);
+type_cube(float);
+type_cube(double);
+type_cube(rgb8);
+type_cube(rgbx8);
 
-IMAGE_EXPORT(sint8***)   si8cube(long ndl, long ndh, long nrl, long nrh, long ncl, long nch);
-IMAGE_EXPORT(uint8***)   ui8cube(long ndl, long ndh, long nrl, long nrh, long ncl, long nch);
-IMAGE_EXPORT(sint16***) si16cube(long ndl, long ndh, long nrl, long nrh, long ncl, long nch);
-IMAGE_EXPORT(uint16***) ui16cube(long ndl, long ndh, long nrl, long nrh, long ncl, long nch);
-IMAGE_EXPORT(sint32***) si32cube(long ndl, long ndh, long nrl, long nrh, long ncl, long nch);
-IMAGE_EXPORT(uint32***) ui32cube(long ndl, long ndh, long nrl, long nrh, long ncl, long nch);
-IMAGE_EXPORT(float32***) f32cube(long ndl, long ndh, long nrl, long nrh, long ncl, long nch);
-IMAGE_EXPORT(float64***) f64cube(long ndl, long ndh, long nrl, long nrh, long ncl, long nch);
-IMAGE_EXPORT(rgb8***)   rgb8cube(long ndl, long ndh, long nrl, long nrh, long ncl, long nch);
-IMAGE_EXPORT(rgbx8***) rgbx8cube(long ndl, long ndh, long nrl, long nrh, long ncl, long nch);
+#define free_type_cube(t) \
+void short_name(t,free_,cube)(t *** c, int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch, int32_t ndl, int32_t ndh) \
 
-IMAGE_EXPORT(void) free_si8cube  (sint8   ***c,long nrl,long nrh,long ncl,long nch,long ndl,long ndh);
-IMAGE_EXPORT(void) free_ui8cube  (uint8   ***c,long nrl,long nrh,long ncl,long nch,long ndl,long ndh);
-IMAGE_EXPORT(void) free_si16cube (sint16  ***c,long nrl,long nrh,long ncl,long nch,long ndl,long ndh);
-IMAGE_EXPORT(void) free_ui16cube (uint16  ***c,long nrl,long nrh,long ncl,long nch,long ndl,long ndh);
-IMAGE_EXPORT(void) free_si32cube (sint32  ***c,long nrl,long nrh,long ncl,long nch,long ndl,long ndh);
-IMAGE_EXPORT(void) free_ui32cube (uint32  ***c,long nrl,long nrh,long ncl,long nch,long ndl,long ndh);
-IMAGE_EXPORT(void) free_f32cube  (float32 ***c,long nrl,long nrh,long ncl,long nch,long ndl,long ndh);
-IMAGE_EXPORT(void) free_f64cube  (float64 ***c,long nrl,long nrh,long ncl,long nch,long ndl,long ndh);
-IMAGE_EXPORT(void) free_rgb8cube (rgb8    ***c,long nrl,long nrh,long ncl,long nch,long ndl,long ndh);
-IMAGE_EXPORT(void) free_rgbx8cube(rgbx8   ***c,long nrl,long nrh,long ncl,long nch,long ndl,long ndh);
+free_type_cube(int8_t);
+free_type_cube(uint8_t);
+free_type_cube(int16_t);
+free_type_cube(uint16_t);
+free_type_cube(int32_t);
+free_type_cube(uint32_t);
+free_type_cube(int64_t);
+free_type_cube(uint64_t);
+free_type_cube(float);
+free_type_cube(double);
+free_type_cube(rgb8);
+free_type_cube(rgbx8);
 
-#ifdef __cplusplus
-}
-#endif
 
 #endif /* __NRALLOC3_H__ */
+
+// Local Variables:
+// tab-width: 4
+// c-basic-offset: 4
+// c-file-offsets:((innamespace . 0)(inline-open . 0))
+// indent-tabs-mode: nil
+// End:
+
+// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4
+
Index: soft/giet_vm/applications/rosenfeld/nrc2/include/nrarith0.h
===================================================================
--- soft/giet_vm/applications/rosenfeld/nrc2/include/nrarith0.h	(revision 820)
+++ soft/giet_vm/applications/rosenfeld/nrc2/include/nrarith0.h	(revision 821)
@@ -11,25 +11,20 @@
 #define __NRARITH0_H__
 
-#ifdef __cplusplus
-#pragma message ("C++")
-extern "C" {
-#endif
-
-#ifdef VERBOSE_PRAGMA
-//#pragma message(" -include nrarith0.h")
-#endif
-
 /* ---------- */
 /* -- Swap -- */
 /* ---------- */
 
-ROUTINE(void)   i8swap(int8    *a, int8    *b);
-ROUTINE(void)  i16swap(int16   *a, int16   *b);
-ROUTINE(void)  i32swap(int32   *a, int32   *b);
-ROUTINE(void)  i64swap(int64   *a, int64   *b);
-ROUTINE(void)  f32swap(float32 *a, float32 *b);
-ROUTINE(void)  f64swap(float64 *a, float64 *b);
-ROUTINE(void)  rgb8swap(rgb8   *a, rgb8    *b);
-ROUTINE(void) rgbx8swap(rgbx8  *a, rgbx8   *b);
+#define type_swap(t)                   \
+void short_name(t,,swap)(t * a, t * b)
+
+type_swap(int8_t);
+type_swap(int16_t);
+type_swap(int32_t);
+type_swap(int64_t);
+type_swap(float);
+type_swap(double);
+type_swap(rgb8);
+type_swap(rgbx8);
+
 
 /* --------- */
@@ -37,78 +32,43 @@
 /* --------- */
 
-ROUTINE(float32) f32min (float32 x1, float32 x2);
-ROUTINE(float32) f32min2(float32 x1, float32 x2);
-ROUTINE(float32) f32min3(float32 x1, float32 x2, float32 x3);
-ROUTINE(float32) f32min4(float32 x1, float32 x2, float32 x3, float32 x4);
-ROUTINE(float32) f32min5(float32 x1, float32 x2, float32 x3, float32 x4, float32 x5);
+#define type_min(t)                                 \
+t short_name(t,,min)(t x1, t x2);                   \
+t short_name(t,,min2)(t x1, t x2);                  \
+t short_name(t,,min3)(t x1, t x2, t x3);            \
+t short_name(t,,min4)(t x1, t x2, t x3, t x4);      \
+t short_name(t,,min5)(t x1, t x2, t x3, t x4, t x5) \
 
-ROUTINE(float64) f64min (float64 x1, float64 x2);
-ROUTINE(float64) f64min2(float64 x1, float64 x2);
-ROUTINE(float64) f64min3(float64 x1, float64 x2, float64 x3);
-ROUTINE(float64) f64min4(float64 x1, float64 x2, float64 x3, float64 x4);
-ROUTINE(float64) f64min5(float64 x1, float64 x2, float64 x3, float64 x4, float64 x5);
+type_min(float);
+type_min(double);
+type_min(int8_t);
+type_min(uint8_t);
+type_min(int16_t);
+type_min(uint16_t);
+type_min(int32_t);
+type_min(uint32_t);
+type_min(rgb8);
 
-ROUTINE(byte)  bmin (byte x1, byte x2);
-ROUTINE(byte)  bmin2(byte x1, byte x2);
-ROUTINE(byte)  bmin3(byte x1, byte x2, byte x3);
-ROUTINE(byte)  bmin4(byte x1, byte x2, byte x3, byte x4);
-ROUTINE(byte)  bmin5(byte x1, byte x2, byte x3, byte x4, byte x5);
-
-ROUTINE(uint16) ui16min (uint16 x1, uint16 x2);
-ROUTINE(uint16) ui16min2(uint16 x1, uint16 x2);
-ROUTINE(uint16) ui16min3(uint16 x1, uint16 x2, uint16 x3);
-ROUTINE(uint16) ui16min4(uint16 x1, uint16 x2, uint16 x3, uint16 x4);
-ROUTINE(uint16) ui16min5(uint16 x1, uint16 x2, uint16 x3, uint16 x4, uint16 x5);
-
-ROUTINE(int32) i32min (int32 x1, int32 x2);
-ROUTINE(int32) i32min2(int32 x1, int32 x2);
-ROUTINE(int32) i32min3(int32 x1, int32 x2, int32 x3);
-ROUTINE(int32) i32min4(int32 x1, int32 x2, int32 x3, int32 x4);
-ROUTINE(int32) i32min5(int32 x1, int32 x2, int32 x3, int32 x4, int32 x5);
-
-ROUTINE(rgb8) rgb8min (rgb8 x1, rgb8 x2);
-ROUTINE(rgb8) rgb8min2(rgb8 x1, rgb8 x2);
-ROUTINE(rgb8) rgb8min3(rgb8 x1, rgb8 x2, rgb8 x3);
-ROUTINE(rgb8) rgb8min4(rgb8 x1, rgb8 x2, rgb8 x3, rgb8 x4);
-ROUTINE(rgb8) rgb8min5(rgb8 x1, rgb8 x2, rgb8 x3, rgb8 x4, rgb8 x5);
 
 /* --------- */
 /* -- Max -- */
 /* --------- */
-ROUTINE(float32) f32max (float32 x1, float32 x2);
-ROUTINE(float32) f32max2(float32 x1, float32 x2);
-ROUTINE(float32) f32max3(float32 x1, float32 x2, float32 x3);
-ROUTINE(float32) f32max4(float32 x1, float32 x2, float32 x3, float32 x4);
-ROUTINE(float32) f32max5(float32 x1, float32 x2, float32 x3, float32 x4, float32 x5);
 
-ROUTINE(float64) f64max (float64 x1, float64 x2);
-ROUTINE(float64) f64max2(float64 x1, float64 x2);
-ROUTINE(float64) f64max3(float64 x1, float64 x2, float64 x3);
-ROUTINE(float64) f64max4(float64 x1, float64 x2, float64 x3, float64 x4);
-ROUTINE(float64) f64max5(float64 x1, float64 x2, float64 x3, float64 x4, float64 x5);
+#define type_max(t)                                 \
+t short_name(t,,max)(t x1, t x2);                   \
+t short_name(t,,max2)(t x1, t x2);                  \
+t short_name(t,,max3)(t x1, t x2, t x3);            \
+t short_name(t,,max4)(t x1, t x2, t x3, t x4);      \
+t short_name(t,,max5)(t x1, t x2, t x3, t x4, t x5) \
 
-ROUTINE(byte)  bmax (byte x1,  byte x2);
-ROUTINE(byte)  bmax2(byte x1,  byte x2);
-ROUTINE(byte)  bmax3(byte x1,  byte x2, byte x3);
-ROUTINE(byte)  bmax4(byte x1,  byte x2, byte x3, byte x4);
-ROUTINE(byte)  bmax5(byte x1,  byte x2, byte x3, byte x4, byte x5);
+type_max(float);
+type_max(double);
+type_max(int8_t);
+type_max(uint8_t);
+type_max(int16_t);
+type_max(uint16_t);
+type_max(int32_t);
+type_max(uint32_t);
+type_max(rgb8);
 
-ROUTINE(uint16) ui16max (uint16 x1, uint16 x2);
-ROUTINE(uint16) ui16max2(uint16 x1, uint16 x2);
-ROUTINE(uint16) ui16max3(uint16 x1, uint16 x2, uint16 x3);
-ROUTINE(uint16) ui16max4(uint16 x1, uint16 x2, uint16 x3, uint16 x4);
-ROUTINE(uint16) ui16max5(uint16 x1, uint16 x2, uint16 x3, uint16 x4, uint16 x5);
-
-ROUTINE(int32) i32max (int32 x1, int32 x2);
-ROUTINE(int32) i32max2(int32 x1, int32 x2);
-ROUTINE(int32) i32max3(int32 x1, int32 x2, int32 x3);
-ROUTINE(int32) i32max4(int32 x1, int32 x2, int32 x3, int32 x4);
-ROUTINE(int32) i32max5(int32 x1, int32 x2, int32 x3, int32 x4, int32 x5);
-
-ROUTINE(rgb8) rgb8max (rgb8 x1, rgb8 x2);
-ROUTINE(rgb8) rgb8max2(rgb8 x1, rgb8 x2);
-ROUTINE(rgb8) rgb8max3(rgb8 x1, rgb8 x2, rgb8 x3);
-ROUTINE(rgb8) rgb8max4(rgb8 x1, rgb8 x2, rgb8 x3, rgb8 x4);
-ROUTINE(rgb8) rgb8max5(rgb8 x1, rgb8 x2, rgb8 x3, rgb8 x4, rgb8 x5);
 
 /* ----------- */
@@ -116,17 +76,20 @@
 /* ----------- */
 
-ROUTINE(byte) ibit(int32 x, int n);
-ROUTINE(int32) sym_int32(int32 x);
-ROUTINE(int) myLog2(int x);
-ROUTINE(int) next_power2(int x);
-ROUTINE(int) myGCD(int u, int v);
-ROUTINE(int) myLCM(int u, int v);
+int32_t i32bit(int32_t x, int32_t n);
+int32_t sym_int32(int32_t x);
+int32_t myLog2(int32_t x);
+int32_t next_power2(int32_t x);
+int32_t myGCD(int32_t u, int32_t v);
+int32_t myLCM(int32_t u, int32_t v);
 
-#ifdef __cplusplus
-}
 #endif
 
-#else
-//#pragma message(" Warning : attempt to re-include nrarith0.h") 
-#endif
+// Local Variables:
+// tab-width: 4
+// c-basic-offset: 4
+// c-file-offsets:((innamespace . 0)(inline-open . 0))
+// indent-tabs-mode: nil
+// End:
 
+// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4
+
Index: soft/giet_vm/applications/rosenfeld/nrc2/include/nrarith1.h
===================================================================
--- soft/giet_vm/applications/rosenfeld/nrc2/include/nrarith1.h	(revision 820)
+++ soft/giet_vm/applications/rosenfeld/nrc2/include/nrarith1.h	(revision 821)
@@ -11,78 +11,98 @@
 #define _NRARITH1_H_
 
-#ifdef __cplusplus
-#ifdef PRAGMA_VERBOSE
-#pragma message ("C++")
-#endif
-extern "C" {
-#endif
-
-#ifdef PRAGMA_VERBOSE
-//#pragma message("- include nrarith1.h")
-#endif
-
-/* ======================================================================== */
-/* === Beta reduction ===================================================== */
-/* ======================================================================== */
-
-IMAGE_EXPORT(int32) sum_bvector (byte  *v, long nl, long nh);
-IMAGE_EXPORT(int32) sum_si16vector (sint16  *v, long nl, long nh);
-IMAGE_EXPORT(int32) sum_si32vector (sint32   *v, long nl, long nh);
-IMAGE_EXPORT(float) sum_f32vector  (float32 *v, long nl, long nh);
-
-// ==================
-// === min_vector ===
-// ==================
-
-IMAGE_EXPORT(sint8)   min_si8vector  (sint8   *v, long nl, long nh);
-IMAGE_EXPORT(uint8)   min_ui8vector  (uint8   *v, long nl, long nh);
-IMAGE_EXPORT(sint16)  min_si16vector (sint16  *v, long nl, long nh);
-IMAGE_EXPORT(uint16)  min_ui16vector (uint16  *v, long nl, long nh);
-IMAGE_EXPORT(sint32)  min_si32vector (sint32  *v, long nl, long nh);
-IMAGE_EXPORT(uint32)  min_ui32vector (uint32  *v, long nl, long nh);
-IMAGE_EXPORT(float32) min_f32vector  (float32 *v, long nl, long nh);
-IMAGE_EXPORT(float64) min_f64vector  (float64 *v, long nl, long nh);
-
-// ==================
-// === max_vector ===
-// ==================
-
-IMAGE_EXPORT(sint8)  max_si8vector  (sint8   *v, long nl, long nh);
-IMAGE_EXPORT(uint8)  max_ui8vector  (uint8   *v, long nl, long nh);
-IMAGE_EXPORT(sint16) max_si16vector (sint16  *v, long nl, long nh);
-IMAGE_EXPORT(uint16) max_ui16vector (uint16  *v, long nl, long nh);
-IMAGE_EXPORT(sint32) max_si32vector (sint32  *v, long nl, long nh);
-IMAGE_EXPORT(uint32) max_ui32vector (uint32  *v, long nl, long nh);
-
-IMAGE_EXPORT(float32) max_f32vector (float32 *v, long nl, long nh);
-IMAGE_EXPORT(float64) max_f64vector (float64 *v, long nl, long nh);
-
-// ======================
-// === min_vector_pos ===
-// ======================
-
-IMAGE_EXPORT(sint8)  min_si8vector_pos  (sint8  *v, long nl, long nh, int *pos);
-IMAGE_EXPORT(uint8)  min_ui8vector_pos  (uint8  *v, long nl, long nh, int *pos);
-IMAGE_EXPORT(sint16) min_si16vector_pos (sint16 *v, long nl, long nh, int *pos);
-IMAGE_EXPORT(uint16) min_ui16vector_pos (uint16 *v, long nl, long nh, int *pos);
-IMAGE_EXPORT(sint32) min_si32vector_pos (sint32 *v, long nl, long nh, int *pos);
-IMAGE_EXPORT(uint32) min_ui32vector_pos (uint32 *v, long nl, long nh, int *pos);
-
-IMAGE_EXPORT(float32)min_f32vector_pos (float32 *v, long nl, long nh, int *pos);
-IMAGE_EXPORT(float64)min_f64vector_pos (float64 *v, long nl, long nh, int *pos);
-
-// ======================
-// === max_vector_pos ===
-// ======================
-
-IMAGE_EXPORT(sint8)  max_si8vector_pos  (sint8  *v, long nl, long nh, int *pos);
-IMAGE_EXPORT(uint8)  max_ui8vector_pos  (uint8  *v, long nl, long nh, int *pos);
-IMAGE_EXPORT(sint16) max_si16vector_pos (sint16 *v, long nl, long nh, int *pos);
-IMAGE_EXPORT(uint16) max_ui16vector_pos (uint16 *v, long nl, long nh, int *pos);
-IMAGE_EXPORT(sint32) max_si32vector_pos (sint32 *v, long nl, long nh, int *pos);
-IMAGE_EXPORT(uint32) max_ui32vector_pos (uint32 *v, long nl, long nh, int *pos);
-
-IMAGE_EXPORT(float32)max_f32vector_pos (float32 *v, long nl, long nh, int *pos);
-IMAGE_EXPORT(float64)max_f64vector_pos (float64 *v, long nl, long nh, int *pos);
+/*
+ * ------------------
+ * --- sum_vector ---
+ * ------------------
+ */
+
+#define sum_type_vector(t,r) \
+r short_name(t,sum_,vector)(t * v, int32_t nl, int32_t nh)
+
+sum_type_vector(int8_t, int32_t);
+sum_type_vector(uint8_t, uint32_t);
+sum_type_vector(int16_t, int32_t);
+sum_type_vector(uint16_t, uint32_t);
+sum_type_vector(int32_t, int32_t);
+sum_type_vector(uint32_t, uint32_t);
+sum_type_vector(float, float);
+sum_type_vector(double, double);
+
+/*
+ * ------------------
+ * --- min_vector ---
+ * ------------------
+ */
+
+#define min_type_vector(t) \
+t short_name(t,min_,vector)(t * v, int32_t nl, int32_t nh)
+
+min_type_vector(int8_t);
+min_type_vector(uint8_t);
+min_type_vector(int16_t);
+min_type_vector(uint16_t);
+min_type_vector(int32_t);
+min_type_vector(uint32_t);
+min_type_vector(float);
+min_type_vector(double);
+
+
+/*
+ * ------------------
+ * --- max_vector ---
+ * ------------------
+ */
+
+#define max_type_vector(t) \
+t short_name(t,max_,vector)(t * v, int32_t nl, int32_t nh)
+
+max_type_vector(int8_t);
+max_type_vector(uint8_t);
+max_type_vector(int16_t);
+max_type_vector(uint16_t);
+max_type_vector(int32_t);
+max_type_vector(uint32_t);
+max_type_vector(float);
+max_type_vector(double);
+
+
+/*
+ * ----------------------
+ * --- min_vector_pos ---
+ * ----------------------
+ */
+
+
+#define min_type_vector_pos(t) \
+t short_name(t,min_,vector_pos)(t * v, int32_t nl, int32_t nh, int32_t * pos)
+
+min_type_vector_pos(int8_t);
+min_type_vector_pos(uint8_t);
+min_type_vector_pos(int16_t);
+min_type_vector_pos(uint16_t);
+min_type_vector_pos(int32_t);
+min_type_vector_pos(uint32_t);
+min_type_vector_pos(float);
+min_type_vector_pos(double);
+
+
+/*
+ * ----------------------
+ * --- max_vector_pos ---
+ * ----------------------
+ */
+
+#define max_type_vector_pos(t) \
+t short_name(t,max_,vector_pos)(t * v, int32_t nl, int32_t nh, int32_t * pos)
+
+max_type_vector_pos(int8_t);
+max_type_vector_pos(uint8_t);
+max_type_vector_pos(int16_t);
+max_type_vector_pos(uint16_t);
+max_type_vector_pos(int32_t);
+max_type_vector_pos(uint32_t);
+max_type_vector_pos(float);
+max_type_vector_pos(double);
+
 
 // =============
@@ -90,27 +110,110 @@
 // =============
 
-IMAGE_EXPORT(void) beta_sum_rgb32vector    (rgb32 *S,long nl,long nh, rgb32 *D);
-IMAGE_EXPORT(void) beta_average_rgb32vector(rgb32 *S,long nl,long nh, rgb32 *D);
-
-IMAGE_EXPORT(void) add_i32vector(int32 *S1, long nl,long nh, int32 *S2, int32 *D);
-IMAGE_EXPORT(void) sub_i32vector(int32 *S1, long nl,long nh, int32 *S2, int32 *D);
-
-IMAGE_EXPORT(void) cumulleft_i32vector  (int32 *S, long nl, long nh, int32 *D);
-IMAGE_EXPORT(void) cumulleft_rgb32vector(rgb32 *S, long nl, long nh, rgb32 *D);
-
-IMAGE_EXPORT(void) cumulright_i32vector  (int32 *S, long nl, long nh, int32 *D);
-IMAGE_EXPORT(void) cumulright_rgb32vector(rgb32 *S, long nl, long nh, rgb32 *D);
-
-IMAGE_EXPORT(void) mulc_i32vector     (int32 *S, long nl, long nh, int32 c, int32 *D);
-IMAGE_EXPORT(void) mulc_rgb32vector   (rgb32 *S, long nl, long nh, int32 c, rgb32 *D);
-IMAGE_EXPORT(void) divc_i32vector     (int32 *S, long nl, long nh, int32 c, int32 *D);
-IMAGE_EXPORT(void) divc_rgb32vector   (rgb32 *S, long nl, long nh, int32 c, rgb32 *D);
-
-IMAGE_EXPORT(void) mulfrac_i32vector  (int32 *S, long nl, long nh, int32 a, int32 b, int32 *D);
-IMAGE_EXPORT(void) mulfrac_rgb32vector(rgb32 *S, long nl, long nh, int32 a, int32 b, rgb32 *D);
-
-#ifdef __cplusplus
-}
-#endif
+#define add_type_vector(t) \
+void short_name(t,add_,vector)(t * S1, int32_t nl, int32_t nh, t * S2, t * D)
+
+add_type_vector(int8_t);
+add_type_vector(uint8_t);
+add_type_vector(int16_t);
+add_type_vector(uint16_t);
+add_type_vector(int32_t);
+add_type_vector(uint32_t);
+add_type_vector(float);
+add_type_vector(double);
+
+#define sub_type_vector(t) \
+void short_name(t,sub_,vector)(t * S1, int32_t nl, int32_t nh, t * S2, t * D)
+
+sub_type_vector(int8_t);
+sub_type_vector(uint8_t);
+sub_type_vector(int16_t);
+sub_type_vector(uint16_t);
+sub_type_vector(int32_t);
+sub_type_vector(uint32_t);
+sub_type_vector(float);
+sub_type_vector(double);
+
+#define mulc_type_vector(t) \
+void short_name(t,mulc_,vector)(t * S, int32_t nl, int32_t nh, int32_t c, t * D)
+
+mulc_type_vector(int8_t);
+mulc_type_vector(uint8_t);
+mulc_type_vector(int16_t);
+mulc_type_vector(uint16_t);
+mulc_type_vector(int32_t);
+mulc_type_vector(uint32_t);
+mulc_type_vector(float);
+mulc_type_vector(double);
+
+#define divc_type_vector(t) \
+void short_name(t,divc_,vector)(t * S, int32_t nl, int32_t nh, int32_t c, t * D)
+
+divc_type_vector(int8_t);
+divc_type_vector(uint8_t);
+divc_type_vector(int16_t);
+divc_type_vector(uint16_t);
+divc_type_vector(int32_t);
+divc_type_vector(uint32_t);
+divc_type_vector(float);
+divc_type_vector(double);
+
+
+#define cumulleft_type_vector(t) \
+void short_name(t,cumulleft_,vector)(t * S, int32_t nl, int32_t nh, int32_t * D)
+
+cumulleft_type_vector(int8_t);
+cumulleft_type_vector(uint8_t);
+cumulleft_type_vector(int16_t);
+cumulleft_type_vector(uint16_t);
+cumulleft_type_vector(int32_t);
+cumulleft_type_vector(uint32_t);
+cumulleft_type_vector(float);
+cumulleft_type_vector(double);
+
+#define cumulright_type_vector(t) \
+void short_name(t,cumulright_,vector)(t * S, int32_t nl, int32_t nh, int32_t * D)
+
+cumulright_type_vector(int8_t);
+cumulright_type_vector(uint8_t);
+cumulright_type_vector(int16_t);
+cumulright_type_vector(uint16_t);
+cumulright_type_vector(int32_t);
+cumulright_type_vector(uint32_t);
+cumulright_type_vector(float);
+cumulright_type_vector(double);
+
+
+#define mulfrac_type_vector(t) \
+void short_name(t,mulfrac_,vector)(t * S, int32_t nl, int32_t nh, int32_t a, int32_t b, t * D)
+
+mulfrac_type_vector(int8_t);
+mulfrac_type_vector(uint8_t);
+mulfrac_type_vector(int16_t);
+mulfrac_type_vector(uint16_t);
+mulfrac_type_vector(int32_t);
+mulfrac_type_vector(uint32_t);
+mulfrac_type_vector(float);
+mulfrac_type_vector(double);
+
+
+
+void beta_sum_rgb32vector    (rgb32 * S, int32_t nl, int32_t nh, rgb32 * D);
+void beta_average_rgb32vector(rgb32 * S, int32_t nl, int32_t nh, rgb32 * D);
+void cumulleft_rgb32vector   (rgb32 * S, int32_t nl, int32_t nh, rgb32 * D);
+void cumulright_rgb32vector  (rgb32 * S, int32_t nl, int32_t nh, rgb32 * D);
+void mulc_rgb32vector        (rgb32 * S, int32_t nl, int32_t nh, int32 c, rgb32 * D);
+void divc_rgb32vector        (rgb32 * S, int32_t nl, int32_t nh, int32 c, rgb32 * D);
+void mulfrac_rgb32vector     (rgb32 * S, int32_t nl, int32_t nh, int32 a, int32 b, rgb32 * D);
+
 
 #endif /* _NRARITH1_H_ */
+
+// Local Variables:
+// tab-width: 4
+// c-basic-offset: 4
+// c-file-offsets:((innamespace . 0)(inline-open . 0))
+// indent-tabs-mode: nil
+// End:
+
+// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4
+
Index: soft/giet_vm/applications/rosenfeld/nrc2/include/nrarith2.h
===================================================================
--- soft/giet_vm/applications/rosenfeld/nrc2/include/nrarith2.h	(revision 820)
+++ soft/giet_vm/applications/rosenfeld/nrc2/include/nrarith2.h	(revision 821)
@@ -11,14 +11,5 @@
 #define _NRARITH2_H_
 
-#ifdef __cplusplus
-#ifdef PRAGMA_VERBOSE
-#pragma message ("C++")
-#endif
-extern "C" {
-#endif
-
-#ifdef PRAGMA_VERBOSE
-//#pragma message("- include nrarith.h")
-#endif
+#include "nrc_os_config.h"
 
 /* ------------------ */
@@ -26,14 +17,18 @@
 /* ------------------ */
 
-IMAGE_EXPORT(sint8)   min_si8matrix  (sint8    **m, long nrl,long nrh,long ncl, long nch);
-IMAGE_EXPORT(uint8)   min_ui8matrix  (uint8    **m, long nrl,long nrh,long ncl, long nch);
-IMAGE_EXPORT(sint16)  min_si16matrix (sint16   **m, long nrl,long nrh,long ncl, long nch);
-IMAGE_EXPORT(uint16)  min_ui16matrix (uint16   **m, long nrl,long nrh,long ncl, long nch);
-IMAGE_EXPORT(sint32)  min_si32matrix (sint32   **m, long nrl,long nrh,long ncl, long nch);
-IMAGE_EXPORT(uint32)  min_ui32matrix (uint32   **m, long nrl,long nrh,long ncl, long nch);
-IMAGE_EXPORT(sint64)  min_si64matrix (sint64   **m, long nrl,long nrh,long ncl, long nch);
-IMAGE_EXPORT(uint64)  min_ui64matrix (uint64   **m, long nrl,long nrh,long ncl, long nch);
-IMAGE_EXPORT(float32) min_f32matrix  (float32  **m, long nrl,long nrh,long ncl, long nch);
-IMAGE_EXPORT(float64) min_f64matrix  (float64  **m, long nrl,long nrh,long ncl, long nch);
+#define min_type_matrix(t) \
+t short_name(t,min_,matrix)(t ** m, int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch)
+
+min_type_matrix(int8_t);
+min_type_matrix(uint8_t);
+min_type_matrix(int16_t);
+min_type_matrix(uint16_t);
+min_type_matrix(int32_t);
+min_type_matrix(uint32_t);
+min_type_matrix(int64_t);
+min_type_matrix(uint64_t);
+min_type_matrix(float);
+min_type_matrix(double);
+
 
 /* ------------------ */
@@ -41,14 +36,18 @@
 /* ------------------ */
 
-IMAGE_EXPORT(sint8)   max_si8matrix  (sint8    **m, long nrl,long nrh,long ncl, long nch);
-IMAGE_EXPORT(uint8)   max_ui8matrix  (uint8    **m, long nrl,long nrh,long ncl, long nch);
-IMAGE_EXPORT(sint16)  max_si16matrix (sint16   **m, long nrl,long nrh,long ncl, long nch);
-IMAGE_EXPORT(uint16)  max_ui16matrix (uint16   **m, long nrl,long nrh,long ncl, long nch);
-IMAGE_EXPORT(sint32)  max_si32matrix (sint32   **m, long nrl,long nrh,long ncl, long nch);
-IMAGE_EXPORT(uint32)  max_ui32matrix (uint32   **m, long nrl,long nrh,long ncl, long nch);
-IMAGE_EXPORT(sint64)  max_si64matrix (sint64   **m, long nrl,long nrh,long ncl, long nch);
-IMAGE_EXPORT(uint64)  max_ui64matrix (uint64   **m, long nrl,long nrh,long ncl, long nch);
-IMAGE_EXPORT(float32) max_f32matrix  (float32  **m, long nrl,long nrh,long ncl, long nch);
-IMAGE_EXPORT(float64) max_f64matrix  (float64  **m, long nrl,long nrh,long ncl, long nch);
+#define max_type_matrix(t) \
+t short_name(t,max_,matrix)(t ** m, int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch)
+
+max_type_matrix(int8_t);
+max_type_matrix(uint8_t);
+max_type_matrix(int16_t);
+max_type_matrix(uint16_t);
+max_type_matrix(int32_t);
+max_type_matrix(uint32_t);
+max_type_matrix(int64_t);
+max_type_matrix(uint64_t);
+max_type_matrix(float);
+max_type_matrix(double);
+
 
 /* ------------------ */
@@ -56,18 +55,21 @@
 /* ------------------ */
 
-IMAGE_EXPORT(void) add_si8matrix  (sint8   **X, long nrl,long nrh,long ncl, long nch, sint8   **Y, sint8   **Z);
-IMAGE_EXPORT(void) add_ui8matrix  (uint8   **X, long nrl,long nrh,long ncl, long nch, uint8   **Y, uint8   **Z);
-IMAGE_EXPORT(void) add_si16matrix (sint16  **X, long nrl,long nrh,long ncl, long nch, sint16  **Y, sint16  **Z);
-IMAGE_EXPORT(void) add_ui16matrix (uint16  **X, long nrl,long nrh,long ncl, long nch, uint16  **Y, uint16  **Z);
-IMAGE_EXPORT(void) add_si32matrix (sint32  **X, long nrl,long nrh,long ncl, long nch, sint32  **Y, sint32  **Z);
-IMAGE_EXPORT(void) add_ui32matrix (uint32  **X, long nrl,long nrh,long ncl, long nch, uint32  **Y, uint32  **Z);
-IMAGE_EXPORT(void) add_si64matrix (sint64  **X, long nrl,long nrh,long ncl, long nch, sint64  **Y, sint64  **Z);
-IMAGE_EXPORT(void) add_ui64matrix (uint64  **X, long nrl,long nrh,long ncl, long nch, uint64  **Y, uint64  **Z);
-
-IMAGE_EXPORT(void) add_f32matrix  (float32 **X, long nrl,long nrh,long ncl, long nch, float32 **Y, float32 **Z);
-IMAGE_EXPORT(void) add_f64matrix  (float64 **X, long nrl,long nrh,long ncl, long nch, float64 **Y, float64 **Z);
-
-IMAGE_EXPORT(void) add_rgb8matrix (rgb8    **X, long nrl,long nrh,long ncl, long nch, rgb8    **Y, rgb8    **Z);
-IMAGE_EXPORT(void) add_rgbx8matrix(rgbx8   **X, long nrl,long nrh,long ncl, long nch, rgbx8   **Y, rgbx8   **Z);
+#define add_type_matrix(t) \
+void short_name(t,add_,matrix)(t ** X, int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch, t ** Y, t ** Z)
+
+add_type_matrix(int8_t);
+add_type_matrix(uint8_t);
+add_type_matrix(int16_t);
+add_type_matrix(uint16_t);
+add_type_matrix(int32_t);
+add_type_matrix(uint32_t);
+add_type_matrix(int64_t);
+add_type_matrix(uint64_t);
+add_type_matrix(float);
+add_type_matrix(double);
+
+void add_rgb8matrix (rgb8  ** X, int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch, rgb8  ** Y, rgb8  ** Z);
+void add_rgbx8matrix(rgbx8 ** X, int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch, rgbx8 ** Y, rgbx8 ** Z);
+
 
 /* -------------------- */
@@ -75,18 +77,21 @@
 /* -------------------- */
 
-IMAGE_EXPORT(void) addc_si8matrix  (sint8   **X, long nrl,long nrh,long ncl, long nch, sint8   y, sint8   **Z);
-IMAGE_EXPORT(void) addc_ui8matrix  (uint8   **X, long nrl,long nrh,long ncl, long nch, uint8   y, uint8   **Z);
-IMAGE_EXPORT(void) addc_si16matrix (sint16  **X, long nrl,long nrh,long ncl, long nch, sint16  y, sint16  **Z);
-IMAGE_EXPORT(void) addc_ui16matrix (uint16  **X, long nrl,long nrh,long ncl, long nch, uint16  y, uint16  **Z);
-IMAGE_EXPORT(void) addc_si32matrix (sint32  **X, long nrl,long nrh,long ncl, long nch, sint32  y, sint32  **Z);
-IMAGE_EXPORT(void) addc_ui32matrix (uint32  **X, long nrl,long nrh,long ncl, long nch, uint32  y, uint32  **Z);
-IMAGE_EXPORT(void) addc_si64matrix (sint64  **X, long nrl,long nrh,long ncl, long nch, sint64  y, sint64  **Z);
-IMAGE_EXPORT(void) addc_ui64matrix (uint64  **X, long nrl,long nrh,long ncl, long nch, uint64  y, uint64  **Z);
-
-IMAGE_EXPORT(void) addc_f32matrix  (float32 **X, long nrl,long nrh,long ncl, long nch, float32 y, float32 **Z);
-IMAGE_EXPORT(void) addc_f64matrix  (float64 **X, long nrl,long nrh,long ncl, long nch, float64 y, float64 **Z);
-
-IMAGE_EXPORT(void) addc_rgb8matrix (rgb8    **X, long nrl,long nrh,long ncl, long nch, rgb8    y, rgb8    **Z);
-IMAGE_EXPORT(void) addc_rgbx8matrix(rgbx8   **X, long nrl,long nrh,long ncl, long nch, rgbx8   y, rgbx8   **Z);
+#define addc_type_matrix(t) \
+void short_name(t,addc_,matrix)(t ** X, int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch, t y, t ** Z)
+
+addc_type_matrix(int8_t);
+addc_type_matrix(uint8_t);
+addc_type_matrix(int16_t);
+addc_type_matrix(uint16_t);
+addc_type_matrix(int32_t);
+addc_type_matrix(uint32_t);
+addc_type_matrix(int64_t);
+addc_type_matrix(uint64_t);
+addc_type_matrix(float);
+addc_type_matrix(double);
+
+void addc_rgb8matrix (rgb8  ** X, int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch, rgb8  y, rgb8  ** Z);
+void addc_rgbx8matrix(rgbx8 ** X, int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch, rgbx8 y, rgbx8 ** Z);
+
 
 /* ----------- */
@@ -94,18 +99,21 @@
 /* ----------- */
 
-IMAGE_EXPORT(void) sub_si8matrix  (sint8   **X, long nrl,long nrh,long ncl, long nch, sint8   **Y, sint8   **Z);
-IMAGE_EXPORT(void) sub_ui8matrix  (uint8   **X, long nrl,long nrh,long ncl, long nch, uint8   **Y, uint8   **Z);
-IMAGE_EXPORT(void) sub_si16matrix (sint16  **X, long nrl,long nrh,long ncl, long nch, sint16  **Y, sint16  **Z);
-IMAGE_EXPORT(void) sub_ui16matrix (uint16  **X, long nrl,long nrh,long ncl, long nch, uint16  **Y, uint16  **Z);
-IMAGE_EXPORT(void) sub_si32matrix (sint32  **X, long nrl,long nrh,long ncl, long nch, sint32  **Y, sint32  **Z);
-IMAGE_EXPORT(void) sub_ui32matrix (uint32  **X, long nrl,long nrh,long ncl, long nch, uint32  **Y, uint32  **Z);
-IMAGE_EXPORT(void) sub_si64matrix (sint64  **X, long nrl,long nrh,long ncl, long nch, sint64  **Y, sint64  **Z);
-IMAGE_EXPORT(void) sub_ui64matrix (uint64  **X, long nrl,long nrh,long ncl, long nch, uint64  **Y, uint64  **Z);
-
-IMAGE_EXPORT(void) sub_f32matrix  (float32 **X, long nrl,long nrh,long ncl, long nch, float32 **Y, float32 **Z);
-IMAGE_EXPORT(void) sub_f64matrix  (float64 **X, long nrl,long nrh,long ncl, long nch, float64 **Y, float64 **Z);
-
-IMAGE_EXPORT(void) sub_rgb8matrix (rgb8    **X, long nrl,long nrh,long ncl, long nch, rgb8    **Y, rgb8    **Z);
-IMAGE_EXPORT(void) sub_rgbx8matrix(rgbx8   **X, long nrl,long nrh,long ncl, long nch, rgbx8   **Y, rgbx8   **Z);
+#define sub_type_matrix(t) \
+void short_name(t,sub_,matrix)(t ** X, int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch, t ** Y, t ** Z)
+
+sub_type_matrix(int8_t);
+sub_type_matrix(uint8_t);
+sub_type_matrix(int16_t);
+sub_type_matrix(uint16_t);
+sub_type_matrix(int32_t);
+sub_type_matrix(uint32_t);
+sub_type_matrix(int64_t);
+sub_type_matrix(uint64_t);
+sub_type_matrix(float);
+sub_type_matrix(double);
+
+void sub_rgb8matrix (rgb8  ** X, int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch, rgb8  ** Y, rgb8  ** Z);
+void sub_rgbx8matrix(rgbx8 ** X, int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch, rgbx8 ** Y, rgbx8 ** Z);
+
 
 /* --------------------- */
@@ -113,75 +121,108 @@
 /* --------------------- */
 
-IMAGE_EXPORT(void) subc_si8matrix  (sint8   **X, long nrl,long nrh,long ncl, long nch, sint8   y, sint8   **Z);
-IMAGE_EXPORT(void) subc_ui8matrix  (uint8   **X, long nrl,long nrh,long ncl, long nch, uint8   y, uint8   **Z);
-IMAGE_EXPORT(void) subc_si16matrix (sint16  **X, long nrl,long nrh,long ncl, long nch, sint16  y, sint16  **Z);
-IMAGE_EXPORT(void) subc_ui16matrix (uint16  **X, long nrl,long nrh,long ncl, long nch, uint16  y, uint16  **Z);
-IMAGE_EXPORT(void) subc_si32matrix (sint32  **X, long nrl,long nrh,long ncl, long nch, sint32  y, sint32  **Z);
-IMAGE_EXPORT(void) subc_ui32matrix (uint32  **X, long nrl,long nrh,long ncl, long nch, uint32  y, uint32  **Z);
-IMAGE_EXPORT(void) subc_si64matrix (sint64  **X, long nrl,long nrh,long ncl, long nch, sint64  y, sint64  **Z);
-IMAGE_EXPORT(void) subc_ui64matrix (uint64  **X, long nrl,long nrh,long ncl, long nch, uint64  y, uint64  **Z);
-
-IMAGE_EXPORT(void) subc_f32matrix  (float32 **X, long nrl,long nrh,long ncl, long nch, float32 y, float32 **Z);
-IMAGE_EXPORT(void) subc_f64matrix  (float64 **X, long nrl,long nrh,long ncl, long nch, float64 y, float64 **Z);
-
-IMAGE_EXPORT(void) subc_rgb8matrix (rgb8    **X, long nrl,long nrh,long ncl, long nch, rgb8    y, rgb8    **Z);
-IMAGE_EXPORT(void) subc_rgbx8matrix(rgbx8   **X, long nrl,long nrh,long ncl, long nch, rgbx8   y, rgbx8   **Z);
-
-/* --------------------- */
-/* --- Sub constante --- */
+#define subc_type_matrix(t) \
+void short_name(t,subc_,matrix)(t ** X, int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch, t y, t ** Z)
+
+subc_type_matrix(int8_t);
+subc_type_matrix(uint8_t);
+subc_type_matrix(int16_t);
+subc_type_matrix(uint16_t);
+subc_type_matrix(int32_t);
+subc_type_matrix(uint32_t);
+subc_type_matrix(int64_t);
+subc_type_matrix(uint64_t);
+subc_type_matrix(float);
+subc_type_matrix(double);
+
+void subc_rgb8matrix (rgb8  ** X, int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch, rgb8  y, rgb8  ** Z);
+void subc_rgbx8matrix(rgbx8 ** X, int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch, rgbx8 y, rgbx8 ** Z);
+
+/* --------------------- */
+/* --- Mul constante --- */
 /* --------------------- */
 
 // Z = X * y
-IMAGE_EXPORT(void) mulc_si8matrix  (sint8   **X, long nrl,long nrh,long ncl, long nch, sint8   y, sint8   **Z);
-IMAGE_EXPORT(void) mulc_ui8matrix  (uint8   **X, long nrl,long nrh,long ncl, long nch, uint8   y, uint8   **Z);
-IMAGE_EXPORT(void) mulc_si16matrix (sint16  **X, long nrl,long nrh,long ncl, long nch, sint16  y, sint16  **Z);
-IMAGE_EXPORT(void) mulc_ui16matrix (uint16  **X, long nrl,long nrh,long ncl, long nch, uint16  y, uint16  **Z);
-IMAGE_EXPORT(void) mulc_si32matrix (sint32  **X, long nrl,long nrh,long ncl, long nch, sint32  y, sint32  **Z);
-IMAGE_EXPORT(void) mulc_ui32matrix (uint32  **X, long nrl,long nrh,long ncl, long nch, uint32  y, uint32  **Z);
-IMAGE_EXPORT(void) mulc_si64matrix (sint64  **X, long nrl,long nrh,long ncl, long nch, sint64  y, sint64  **Z);
-IMAGE_EXPORT(void) mulc_ui64matrix (uint64  **X, long nrl,long nrh,long ncl, long nch, uint64  y, uint64  **Z);
-
-IMAGE_EXPORT(void) mulc_f32matrix  (float32 **X, long nrl,long nrh,long ncl, long nch, float32 y, float32 **Z);
-IMAGE_EXPORT(void) mulc_f64matrix  (float64 **X, long nrl,long nrh,long ncl, long nch, float64 y, float64 **Z);
-
-IMAGE_EXPORT(void) mulc_rgb8matrix (rgb8    **X, long nrl,long nrh,long ncl, long nch, rgb8    y, rgb8    **Z);
-IMAGE_EXPORT(void) mulc_rgbx8matrix(rgbx8   **X, long nrl,long nrh,long ncl, long nch, rgbx8   y, rgbx8   **Z);
+
+#define mulc_type_matrix(t) \
+void short_name(t,mulc_,matrix)(t ** X, int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch, t y, t ** Z)
+
+mulc_type_matrix(int8_t);
+mulc_type_matrix(uint8_t);
+mulc_type_matrix(int16_t);
+mulc_type_matrix(uint16_t);
+mulc_type_matrix(int32_t);
+mulc_type_matrix(uint32_t);
+mulc_type_matrix(int64_t);
+mulc_type_matrix(uint64_t);
+mulc_type_matrix(float);
+mulc_type_matrix(double);
+
+void mulc_rgb8matrix (rgb8  ** X, int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch, rgb8  y, rgb8  ** Z);
+void mulc_rgbx8matrix(rgbx8 ** X, int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch, rgbx8 y, rgbx8 ** Z);
+
 
 /* --------------- */
 /* --- MulFrac --- */
 /* --------------- */
-// m2 = (a*m1)/b
-IMAGE_EXPORT(void) mulfrac_bmatrix    (byte   **m1, long nrl,long nrh,long ncl, long nch, int32  a, int32  b, byte    **m2);
-IMAGE_EXPORT(void) mulfrac_si16matrix (sint16 **m1, long nrl,long nrh,long ncl, long nch, int32  a, int32  b, sint16  **m2);
-IMAGE_EXPORT(void) mulfrac_ui16matrix (uint16 **m1, long nrl,long nrh,long ncl, long nch, int32  a, int32  b, uint16  **m2);
-IMAGE_EXPORT(void) mulfrac_si32matrix (sint32 **m1, long nrl,long nrh,long ncl, long nch, int32  a, int32  b, sint32  **m2);
-IMAGE_EXPORT(void) mulfrac_ui32matrix (uint32 **m1, long nrl,long nrh,long ncl, long nch, int32  a, int32  b, uint32  **m2);
-IMAGE_EXPORT(void) mulfrac_rgb8matrix (rgb8   **m1, long nrl,long nrh,long ncl, long nch, rgb32  a, rgb32  b, rgb8    **m2);
-IMAGE_EXPORT(void) mulfrac_rgbx8matrix(rgbx8  **m1, long nrl,long nrh,long ncl, long nch, rgbx32 a, rgbx32 b, rgbx8   **m2);
-
-IMAGE_EXPORT(void) mulfrack_rgb8matrix (rgb8   **m1, long nrl,long nrh,long ncl, long nch, int32 a, int32 b, rgb8    **m2);
-IMAGE_EXPORT(void) mulfrack_rgbx8matrix(rgbx8  **m1, long nrl,long nrh,long ncl, long nch, int32 a, int32 b, rgbx8   **m2);
+
+// m2 = (a * m1) / b
+
+#define mulfrac_type_matrix(t) \
+void short_name(t,mulfrac_,matrix)(t ** X, int32_t nrl, int32_t nrh, \
+        int32_t ncl, int32_t nch, int32_t a, int32_t b, t ** Y)
+
+mulfrac_type_matrix(int8_t);
+mulfrac_type_matrix(uint8_t);
+mulfrac_type_matrix(int16_t);
+mulfrac_type_matrix(uint16_t);
+mulfrac_type_matrix(int32_t);
+mulfrac_type_matrix(uint32_t);
+mulfrac_type_matrix(int64_t);
+mulfrac_type_matrix(uint64_t);
+mulfrac_type_matrix(float);
+mulfrac_type_matrix(double);
+
+void mulfrack_rgb8matrix (rgb8  ** m1, int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch, int32 a, int32 b, rgb8  ** m2);
+void mulfrack_rgbx8matrix(rgbx8 ** m1, int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch, int32 a, int32 b, rgbx8 ** m2);
+
 
 /* ---------------- */
 /* --- MulShift --- */
 /* ---------------- */
-// m3 = (a*m1)>>s
-IMAGE_EXPORT(void) mulshift_bmatrix    (byte   **m1, long nrl,long nrh,long ncl, long nch, int32  a, int32  s, byte    **m2);
-IMAGE_EXPORT(void) mulshift_i16matrix  (int16  **m1, long nrl,long nrh,long ncl, long nch, int32  a, int32  s, int16   **m2);
-IMAGE_EXPORT(void) mulshift_ui16matrix (uint16 **m1, long nrl,long nrh,long ncl, long nch, int32  a, int32  s, uint16  **m2);
-IMAGE_EXPORT(void) mulshift_i32matrix  (int32  **m1, long nrl,long nrh,long ncl, long nch, int32  a, int32  s, int32   **m2);
-IMAGE_EXPORT(void) mulshift_ui32matrix (uint32 **m1, long nrl,long nrh,long ncl, long nch, int32  a, int32  s, uint32  **m2);
-IMAGE_EXPORT(void) mulshift_rgb8matrix (rgb8   **m1, long nrl,long nrh,long ncl, long nch, rgb32  a, rgb32  s, rgb8    **m2);
-IMAGE_EXPORT(void) mulshift_rgbx8matrix(rgbx8  **m1, long nrl,long nrh,long ncl, long nch, rgbx32 a, rgbx32 s, rgbx8   **m2);
-
-IMAGE_EXPORT(void) mulshiftk_rgb8matrix (rgb8   **m1, long nrl,long nrh,long ncl, long nch, int32 a, int32 s, rgb8    **m2);
-IMAGE_EXPORT(void) mulshiftk_rgbx8matrix(rgbx8  **m1, long nrl,long nrh,long ncl, long nch, int32 a, int32 s, rgbx8   **m2);
-
-IMAGE_EXPORT(void) quadratic_error_si16matrix(sint16 **m1,long nrl,long nrh,long ncl, long nch, sint16 **m2, sint16 **m3);
-
-
-#ifdef __cplusplus
-}
-#endif
+// m3 = (a * m1) >> s
+
+#define mulshift_type_matrix(t) \
+void short_name(t,mulshift_,matrix)(t ** X, int32_t nrl, int32_t nrh, \
+        int32_t ncl, int32_t nch, int32_t a, int32_t s, t ** Y)
+
+mulshift_type_matrix(int8_t);
+mulshift_type_matrix(uint8_t);
+mulshift_type_matrix(int16_t);
+mulshift_type_matrix(uint16_t);
+mulshift_type_matrix(int32_t);
+mulshift_type_matrix(uint32_t);
+mulshift_type_matrix(int64_t);
+mulshift_type_matrix(uint64_t);
+mulshift_type_matrix(float);
+mulshift_type_matrix(double);
+
+void mulshift_rgb8matrix (rgb8  **m1, int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch, rgb32  a, rgb32  s, rgb8  ** m2);
+void mulshift_rgbx8matrix(rgbx8 **m1, int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch, rgbx32 a, rgbx32 s, rgbx8 ** m2);
+
+void mulshiftk_rgb8matrix (rgb8  ** m1, int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch, int32 a, int32 s, rgb8  ** m2);
+void mulshiftk_rgbx8matrix(rgbx8 ** m1, int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch, int32 a, int32 s, rgbx8 ** m2);
+
+void quadratic_error_si16matrix(sint16 ** m1, int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch, sint16 ** m2, sint16 ** m3);
+
 
 #endif /* _NRARITH2_H_ */
+
+// Local Variables:
+// tab-width: 4
+// c-basic-offset: 4
+// c-file-offsets:((innamespace . 0)(inline-open . 0))
+// indent-tabs-mode: nil
+// End:
+
+// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4
+
Index: soft/giet_vm/applications/rosenfeld/nrc2/include/nrarith2x.h
===================================================================
--- soft/giet_vm/applications/rosenfeld/nrc2/include/nrarith2x.h	(revision 820)
+++ soft/giet_vm/applications/rosenfeld/nrc2/include/nrarith2x.h	(revision 821)
@@ -11,35 +11,63 @@
 #define _NRARITH2X_H_
 
-#ifdef __cplusplus
-#ifdef PRAGMA_VERBOSE
-#pragma message ("C++")
-#endif
-extern "C" {
-#endif
+// Add conditionnel
 
-#ifdef PRAGMA_VERBOSE
-#pragma message("- include nrarith2x.h")
-#endif
+#define addcnz_type_matrix(t) \
+void short_name(t,addcnz_,matrix)(t ** src, int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch, t cte, t ** dst)
+
+addcnz_type_matrix(int8_t);
+addcnz_type_matrix(uint8_t);
+addcnz_type_matrix(int16_t);
+addcnz_type_matrix(uint16_t);
+addcnz_type_matrix(int32_t);
+addcnz_type_matrix(uint32_t);
+addcnz_type_matrix(int64_t);
+addcnz_type_matrix(uint64_t);
+addcnz_type_matrix(float);
+addcnz_type_matrix(double);
 
 
-    // Add conditionnel
-IMAGE_EXPORT(void) addc_bmatrix (byte   **src,long nrl,long nrh,long ncl, long nch, byte  cte, byte   **dst);
-IMAGE_EXPORT(void) addc_smatrix (sint16  **src,long nrl,long nrh,long ncl, long nch, short cte, sint16  **dst);
-IMAGE_EXPORT(void) addc_usmatrix(uint16 **src,long nrl,long nrh,long ncl, long nch, short cte, uint16 **dst);
+#define addandc_type_matrix(t) \
+void short_name(t,addandc_,matrix)(t ** src, int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch, t cte, t ** dst)
 
-IMAGE_EXPORT(void) addandc_bmatrix    (byte   **src,long nrl,long nrh,long ncl, long nch, byte  cte, byte   **dst);
-IMAGE_EXPORT(void) addandc_si16matrix (sint16 **src,long nrl,long nrh,long ncl, long nch, short cte, sint16  **dst);
-IMAGE_EXPORT(void) addandc_ui16matrix (uint16 **src,long nrl,long nrh,long ncl, long nch, short cte, uint16 **dst);
+addandc_type_matrix(int8_t);
+addandc_type_matrix(uint8_t);
+addandc_type_matrix(int16_t);
+addandc_type_matrix(uint16_t);
+addandc_type_matrix(int32_t);
+addandc_type_matrix(uint32_t);
+addandc_type_matrix(int64_t);
+addandc_type_matrix(uint64_t);
+addandc_type_matrix(float);
+addandc_type_matrix(double);
 
-IMAGE_EXPORT(void) addcnz_bmatrix(byte  **src,long nrl,long nrh,long ncl, long nch, byte  cte, byte  **dst);
 
-IMAGE_EXPORT(int) count_bmatrix(byte **m, long nrl,long nrh,long ncl, long nch);
-/*
- * renvoie la somme des points de la matrice
- */
+/* renvoie la somme des points de la matrice */
 
-#ifdef __cplusplus
-}
-#endif
+#define sum_type_matrix(t,rt) \
+rt short_name(t,sum_,matrix)(t ** m, int32_t nrl, int32_t nrh,int32_t ncl, int32_t nch)
+
+sum_type_matrix(int8_t, int32_t);
+sum_type_matrix(uint8_t, uint32_t);
+sum_type_matrix(int16_t, int32_t);
+sum_type_matrix(uint16_t, uint32_t);
+sum_type_matrix(int32_t, int64_t);
+sum_type_matrix(uint32_t, uint64_t);
+sum_type_matrix(int64_t, int64_t);
+sum_type_matrix(uint64_t, uint64_t);
+sum_type_matrix(float, float);
+sum_type_matrix(double, double);
+
+
 
 #endif /* _NRUTIL_H_ */
+
+// Local Variables:
+// tab-width: 4
+// c-basic-offset: 4
+// c-file-offsets:((innamespace . 0)(inline-open . 0))
+// indent-tabs-mode: nil
+// End:
+
+// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4
+
Index: soft/giet_vm/applications/rosenfeld/nrc2/include/nrc_os_config.h
===================================================================
--- soft/giet_vm/applications/rosenfeld/nrc2/include/nrc_os_config.h	(revision 820)
+++ soft/giet_vm/applications/rosenfeld/nrc2/include/nrc_os_config.h	(revision 821)
@@ -7,12 +7,26 @@
     #define printf(...)  giet_tty_printf(__VA_ARGS__)
 
-    #define open(x, y)      giet_fat_open(x, y)
-    #define close(x)        giet_fat_close(x)
-    #define read(x, y, z)   giet_fat_read(x, y, z)
-    #define write(x, y, z)  giet_fat_write(x, y, z)
-    #define fprintf(x, ...) giet_fat_fprintf(x, __VA_ARGS__)
-    #define fscanf(x, ...)  ;
-    #define exit(x)         giet_pthread_exit(NULL)
-#else
+    #define open(x, y)         giet_fat_open(x, y)
+    #define close(x)           giet_fat_close(x)
+    #define read(x, y, z)      giet_fat_read(x, y, z)
+    #define write(x, y, z)     giet_fat_write(x, y, z)
+    #define fprintf(x, ...)    giet_fat_fprintf(x, __VA_ARGS__)
+    //#define fscanf(x, ...)  ;
+    #define exit(x)            giet_pthread_exit(NULL)
+
+    #define pthread_barrier_t           giet_barrier_t
+    #define pthread_spinlock_t          user_lock_t
+    #define pthread_spin_lock(x)        lock_acquire(x)
+    #define pthread_spin_unlock(x)      lock_release(x)
+    #define pthread_spin_init(x, y)     lock_init(x)
+    #define pthread_mutexlock_t         user_lock_t
+    #define pthread_mutex_lock(x)       lock_acquire(x)
+    #define pthread_mutex_unlock(x)     lock_release(x)
+    #define pthread_mutex_init(x, y)    lock_init(x)
+    #define pthread_barrier_init(x,y,z) barrier_init(x, z)
+    #define pthread_barrier_wait(x)     barrier_wait(x)
+    #define pthread_barrier_destroy(x)
+    #define pthread_create(x,y,z,t)     giet_pthread_create(x,y,z,t)
+    #define pthread_join(x,y)           giet_pthread_join(x,y)
 #endif
 
Index: soft/giet_vm/applications/rosenfeld/nrc2/include/nrkernel.h
===================================================================
--- soft/giet_vm/applications/rosenfeld/nrc2/include/nrkernel.h	(revision 820)
+++ soft/giet_vm/applications/rosenfeld/nrc2/include/nrkernel.h	(revision 821)
@@ -11,24 +11,21 @@
 #define __NRKERNEL_H__
 
-#ifdef __cplusplus
-#pragma message ("C++")
-extern "C" {
-#endif
-    
-#ifdef VERBOSE_PRAGMA
-//#pragma message ("- *** include nrkernel.h ***")
+
+#if TARGET_OS == GIETVM
+    #define nrerror(...) ({                        \
+            printf("*** NRC Runtime Error:\n   "); \
+            printf(__VA_ARGS__);                   \
+            exit(1);                               \
+    })
+#else
+    #define nrerror(...) ({                                 \
+            fprintf(stderr, "*** NRC Runtime Error:\n   "); \
+            fprintf(stderr, __VA_ARGS__);                   \
+            exit(1);                                        \
+    })
 #endif
 
-void nrerror(char error_text[]);
-void nrerror0(char error_text[]);    
-void nrerror1(char *format, ...);
-    
-void Error  (char *format, ...);
-void Warning(char *format, ...);
 
 
-#ifdef __cplusplus
-}
-#endif
 
 #endif // __NRKERNEL_H__
Index: soft/giet_vm/applications/rosenfeld/nrc2/include/nrtype.h
===================================================================
--- soft/giet_vm/applications/rosenfeld/nrc2/include/nrtype.h	(revision 820)
+++ soft/giet_vm/applications/rosenfeld/nrc2/include/nrtype.h	(revision 821)
@@ -16,14 +16,5 @@
 #define _NRTYPE_H_
 
-#ifdef __cplusplus
-#pragma message ("C++")
-extern "C" {
-#endif
-    
-#define VERBOSE_PRAGMA
-
-#ifdef VERBOSE_PRAGMA
-//#pragma message ("- include nrtype.h")
-#endif
+#include <stdint.h>
 
 // ---------------------------------- //
@@ -31,76 +22,80 @@
 // ---------------------------------- //
 
+
 #include "mypredef.h"
     
-typedef unsigned char BOOLEAN;
-typedef unsigned char boolean;
-typedef          int  BOOL;
-#ifdef VERBOSE_PRAGMA
-//#pragma message("boolean")
-#endif
 
-#ifndef TRUE
-#define TRUE 1
-#else
-#pragma message("  ATTENTION : TRUE  already defined")
-#endif
+// Short names
 
-#ifndef FALSE
-#define FALSE 0
-#else
-#pragma message("  ATTENTION : FALSE  already defined")
-#endif
+#define sn_int8_t(p,s)      p##i8##s
+#define sn_int16_t(p,s)     p##i16##s
+#define sn_int32_t(p,s)     p##i32##s
+#define sn_int64_t(p,s)     p##i64##s
+#define sn_uint8_t(p,s)     p##ui8##s
+#define sn_uint16_t(p,s)    p##ui16##s
+#define sn_uint32_t(p,s)    p##ui32##s
+#define sn_uint64_t(p,s)    p##ui64##s
+#define sn_float(p,s)       p##f32##s
+#define sn_double(p,s)      p##f64##s
+#define sn_void_p(p,s)      p##v##s
+#define sn_rgb8(p,s)        p##rgb8##s
+#define sn_rgbx8(p,s)       p##rgbx8##s
+#define sn_rgb32(p,s)       p##rgb32##s
+#define sn_rgbx32(p,s)      p##rgbx32##s
+#define sn_complex32(p,s)   p##c32##s
+#define sn_complex64(p,s)   p##c64##s
+#define sn_si16Point(p,s)   p##si16P##s
+#define sn_ui16Point(p,s)   p##ui16P##s
+#define sn_si32Point(p,s)   p##si32P##s
+#define sn_ui32Point(p,s)   p##ui32P##s
+#define sn_f32Point(p,s)    p##f32P##s
+#define sn_si16Triplet(p,s) p##si16T##s
+#define sn_ui16Triplet(p,s) p##ui16T##s
+#define sn_si32Triplet(p,s) p##si32T##s
+#define sn_ui32Triplet(p,s) p##ui32T##s
+#define sn_f32Triplet(p,s)  p##f32T##s
+
+#define short_name(t,p,s) sn_##t(p,s)
+
+#define NR_END 0
+#define FREE_ARG char*
+
+
+
 
 /* ------------------------------- */
 /* --- 8, 16, 32, 64 bit types --- */
 /* ------------------------------- */
-// old types to be removed
-//typedef sint16  usint16 ;
-//typedef int uint;
 
-// half-typed types
+typedef void * void_p;
+typedef char    byte;
 
-typedef char  byte;
-//typedef char  usint16 ;
-//typedef char  uint;
-
-typedef char  int8;
-typedef short int16;
-typedef int   int32;
-typedef long long  int64;
+typedef int8_t  int8;
+typedef int16_t int16;
+typedef int32_t int32;
+typedef int64_t int64;
     
-#ifdef LIBCOMP
-#if defined(myCompiler_ICC) || defined (myCompiler_MSC)
-typedef __int64  int64;
-#else
-typedef long long  int64;
-#endif
-#endif
 
 // full-typed types
-typedef   signed char sint8;
-typedef unsigned char uint8;
+typedef int8_t   sint8;
+typedef uint8_t  uint8;
 
-typedef   signed short  sint16;
-typedef unsigned short  uint16;
+typedef int16_t  sint16;
+typedef uint16_t uint16;
 
-typedef   signed int sint32;
-typedef unsigned int uint32;
+typedef int32_t  sint32;
+typedef uint32_t uint32;
 
-#if defined(myCompiler_ICC) || defined (myCompiler_MSC)
-typedef          __int64  int64;
-typedef   signed __int64 sint64;
-typedef unsigned __int64 uint64;
-#else
-typedef   signed long long sint64;
-typedef unsigned long long uint64;
-#endif
+typedef int64_t  sint64;
+typedef uint64_t uint64;
 
-typedef float   float32;
-typedef double  float64;
+typedef float    float32;
+typedef double   float64;
+
 
 /* -------------------- */
 /* --- complex type --- */
 /* -------------------- */
+
 typedef struct { float32 x; float32 y;} complex32;
 typedef struct { float64 x; float64 y;} complex64;
@@ -199,7 +194,5 @@
 } bitfield8;
 
-#ifdef __cplusplus
-}
-#endif
 
 #endif // _NR_TYPE_H_
+
Index: soft/giet_vm/applications/rosenfeld/nrc2/src/nralloc1.c
===================================================================
--- soft/giet_vm/applications/rosenfeld/nrc2/src/nralloc1.c	(revision 820)
+++ soft/giet_vm/applications/rosenfeld/nrc2/src/nralloc1.c	(revision 821)
@@ -29,6 +29,7 @@
 #include <stdlib.h>
 #include <malloc.h>
-#include <math.h> // fabs
+#include <stdint.h>
 
+#include "nrc_os_config.h"
 #include "mypredef.h"
 #include "nrtype.h"
@@ -38,516 +39,156 @@
 
 #include "nralloc1.h"
-#include "nrset1.h" // set 1
 
 
-long nr_end = NR_END;
 
-// ------------------------------------------------------------------
-// -- deprecated type (original NRC type, not enough typed vector) --
-// ------------------------------------------------------------------
-
-/* ---------------------------------------- */
-NRC_EXPORT(sint8*) si8vector(long nl, long nh)
-/* ---------------------------------------- */
-{
-    sint8 *v;
-    
-    v=(sint8 *)malloc((size_t) ((nh-nl+1+NR_END)*sizeof(sint8)));
-    if (!v) nrerror("allocation failure in si8vector()");
-    return v-nl+NR_END;
-}
-/* ---------------------------------------- */
-NRC_EXPORT(uint8*) ui8vector(long nl, long nh)
-/* ---------------------------------------- */
-{
-    uint8 *v;
-    
-    v=(uint8 *)malloc((size_t) ((nh-nl+1+NR_END)*sizeof(uint8)));
-    if (!v) nrerror("allocation failure in ui8vector()");
-    return v-nl+NR_END;
-}
-/* -------------------------------------------- */
-NRC_EXPORT(sint16*) si16vector(long nl, long nh)
-/* -------------------------------------------- */
-{
-    sint16 *v;
-    
-    v=(sint16 *)malloc((size_t) ((nh-nl+1+NR_END)*sizeof(sint16)));
-    if (!v) nrerror("allocation failure in si16vector()");
-    return v-nl+NR_END;
-}
-/* -------------------------------------------- */
-NRC_EXPORT(uint16*) ui16vector(long nl, long nh)
-/* -------------------------------------------- */
-{
-    uint16 *v;
-    
-    v=(uint16 *)malloc((size_t) ((nh-nl+1+NR_END)*sizeof(uint16)));
-    if (!v) nrerror("allocation failure in ui16vector()");
-    return v-nl+NR_END;
-}
-/* -------------------------------------------- */
-IMAGE_EXPORT(sint32*) si32vector(long nl, long nh)
-/* -------------------------------------------- */
-{
-    sint32 *v;
-    
-    v=(sint32 *)malloc((size_t) ((nh-nl+1+NR_END)*sizeof(sint32)));
-    if (!v) nrerror("allocation failure in si32vector()");
-    if(!v) return NULL;
-    return v-nl+NR_END;
-}
-/* -------------------------------------------- */
-IMAGE_EXPORT(uint32*) ui32vector(long nl, long nh)
-/* -------------------------------------------- */
-{
-    uint32 *v;
-    
-    v=(uint32 *)malloc((size_t) ((nh-nl+1+NR_END)*sizeof(uint32)));
-    if (!v) nrerror("allocation failure in ui32vector()");
-    if(!v) return NULL;
-    return v-nl+NR_END;
-}
-/* -------------------------------------------- */
-IMAGE_EXPORT(sint64*) si64vector(long nl, long nh)
-/* -------------------------------------------- */
-{
-    sint64 *v;
-    
-    v=(sint64 *)malloc((size_t) ((nh-nl+1+NR_END)*sizeof(sint64)));
-    if (!v) nrerror("allocation failure in si64vector()");
-    return v-nl+NR_END;
-}
-/* -------------------------------------------- */
-IMAGE_EXPORT(uint64*) ui64vector(long nl, long nh)
-/* -------------------------------------------- */
-{
-    uint64 *v;
-    
-    v=(uint64 *)malloc((size_t) ((nh-nl+1+NR_END)*sizeof(uint64)));
-    if (!v) nrerror("allocation failure in ui64vector()");
-    return v-nl+NR_END;
-}
-/* ------------------------------------------ */
-NRC_EXPORT(float32*) f32vector(long nl, long nh)
-/* ------------------------------------------ */
-{
-    float32 *v;
-    
-    v=(float32 *)malloc((size_t) ((nh-nl+1+NR_END)*sizeof(float32)));
-    if (!v) nrerror("allocation failure in f32vector()");
-    if(!v) return NULL;
-    return v-nl+NR_END;
-}
-/* ------------------------------------------ */
-NRC_EXPORT(float64*) f64vector(long nl, long nh)
-/* ------------------------------------------ */
-{
-    float64 *v;
-    
-    v=(float64 *)malloc((size_t) ((nh-nl+1+NR_END)*sizeof(float64)));
-    if (!v) nrerror("allocation failure in f64vector()");
-    if(!v) return NULL;
-    return v-nl+NR_END;
-}
-/* ------------------------------------------ */
-IMAGE_EXPORT(rgb8*) rgb8vector(long nl, long nh)
-/* ------------------------------------------ */
-{
-    rgb8 *v;
-    
-    v=(rgb8 *)malloc((size_t) ((nh-nl+1+NR_END)*sizeof(rgb8)));
-    if (!v) nrerror("allocation failure in rgb8vector()");
-    return v-nl+NR_END;
-}
-/* -------------------------------------------- */
-IMAGE_EXPORT(rgbx8*) rgbx8vector(long nl, long nh)
-/* -------------------------------------------- */
-{
-    rgbx8 *v;
-    
-    v=(rgbx8 *)malloc((size_t) ((nh-nl+1+NR_END)*sizeof(rgbx8)));
-    if (!v) nrerror("allocation failure in rgbx8vector()");
-    return v-nl+NR_END;
-}
-/* -------------------------------------------- */
-IMAGE_EXPORT(rgb32*) rgb32vector(long nl, long nh)
-/* -------------------------------------------- */
-{
-    rgb32 *v;
-    
-    v=(rgb32 *)malloc((size_t) ((nh-nl+1+NR_END)*sizeof(rgb32)));
-    if (!v) nrerror("allocation failure in rgb32vector()");
-    return v-nl+NR_END;
+#undef type_vector
+#define type_vector(t)                                              \
+t * short_name(t,,vector)(int32_t nl, int32_t nh)                   \
+{                                                                   \
+    t * v;                                                          \
+    v = malloc((nh - nl + 1 + NR_END) * sizeof(t));                 \
+    if (v == NULL) {                                                \
+        nrerror("*** Error: allocation failure in %s\n", __func__); \
+    }                                                               \
+    return v - nl + NR_END;                                         \
 }
 
-/* ---------------------------------------- */
-IMAGE_EXPORT(void**) vvector(long nl, long nh)
-/* ---------------------------------------- */
-{
-    void **v;
-    
-    v=(void**)malloc((size_t) ((nh-nl+1+NR_END)*sizeof(void*)));
-    if (!v) nrerror("allocation failure in vvector()");
-    return v-nl+NR_END;
+type_vector(int8_t);
+type_vector(uint8_t);
+type_vector(int16_t);
+type_vector(uint16_t);
+type_vector(int32_t);
+type_vector(uint32_t);
+type_vector(int64_t);
+type_vector(uint64_t);
+type_vector(float);
+type_vector(double);
+type_vector(void_p);
+type_vector(rgb8);
+type_vector(rgbx8);
+type_vector(rgb32);
+
+
+
+#undef type_vector0
+#define type_vector0(t)                                             \
+t * short_name(t,,vector0)(int32_t nl, int32_t nh)                  \
+{                                                                   \
+    t * v;                                                          \
+    v = calloc((nh - nl + 1 + NR_END), sizeof(t));                  \
+    if (v == NULL) {                                                \
+        nrerror("*** Error: allocation failure in %s\n", __func__); \
+    }                                                               \
+    return v - nl + NR_END;                                         \
 }
-/*
- * ---------------
- * --- vector0 ---
- * ---------------
- */
 
-// do: allocate a vector and set it to 0
+type_vector0(int8_t);
+type_vector0(uint8_t);
+type_vector0(int16_t);
+type_vector0(uint16_t);
+type_vector0(int32_t);
+type_vector0(uint32_t);
+type_vector0(int64_t);
+type_vector0(uint64_t);
+type_vector0(float);
+type_vector0(double);
+type_vector0(void_p);
+type_vector0(rgb8);
+type_vector0(rgbx8);
+type_vector0(rgb32);
 
-// ----------------------
-// --- not deprecated ---
-// ----------------------
-/* ------------------------------------------- */
-IMAGE_EXPORT(sint8*) si8vector0(long nl, long nh)
-/* ------------------------------------------- */
-{
-    sint8 *v;
-    
-    v=(sint8 *)calloc((size_t) ((nh-nl+1+NR_END)), sizeof(sint8));
-    if (!v) nrerror("allocation failure in si8vector0()");
-    return v-nl+NR_END;
+
+#undef realloc_type_vector
+#define realloc_type_vector(t)                                      \
+t * short_name(t,realloc_,vector)(t * v, int32_t nl, int32_t nh)    \
+{                                                                   \
+    v += nl;                                                        \
+    v -= NR_END;                                                    \
+    v = realloc(v, (nh - nl + 1 + NR_END) * sizeof(t));             \
+    if (v == NULL) {                                                \
+        nrerror("*** Error: allocation failure in %s\n", __func__); \
+    }                                                               \
+    return v - nl + NR_END;                                         \
 }
-/* ------------------------------------------- */
-IMAGE_EXPORT(uint8*) ui8vector0(long nl, long nh)
-/* ------------------------------------------- */
-{
-    uint8 *v;
-    
-    v=(uint8 *)calloc((size_t) ((nh-nl+1+NR_END)), sizeof(uint8));
-    if (!v) nrerror("allocation failure in ui8vector0()");
-    return v-nl+NR_END;
+
+
+realloc_type_vector(int8_t);
+realloc_type_vector(uint8_t);
+realloc_type_vector(int16_t);
+realloc_type_vector(uint16_t);
+realloc_type_vector(int32_t);
+realloc_type_vector(uint32_t);
+realloc_type_vector(int64_t);
+realloc_type_vector(uint64_t);
+realloc_type_vector(float);
+realloc_type_vector(double);
+realloc_type_vector(void_p);
+realloc_type_vector(rgb8);
+realloc_type_vector(rgbx8);
+realloc_type_vector(rgb32);
+
+
+#undef free_type_vector
+#define free_type_vector(t)                               \
+void short_name(t,free_,vector)(t * v, long nl, long nh)  \
+{                                                         \
+    free((FREE_ARG) (v + nl - NR_END));                   \
 }
-/* -------------------------------------------- */
-IMAGE_EXPORT(int16*) si16vector0(long nl, long nh)
-/* -------------------------------------------- */
-{
-    sint16 *v;
-    
-    v=(sint16 *)calloc((size_t) ((nh-nl+1+NR_END)), sizeof(sint16));
-    if (!v) nrerror("allocation failure in si16vector0()");
-    return v-nl+NR_END;
+
+free_type_vector(int8_t);
+free_type_vector(uint8_t);
+free_type_vector(int16_t);
+free_type_vector(uint16_t);
+free_type_vector(int32_t);
+free_type_vector(uint32_t);
+free_type_vector(int64_t);
+free_type_vector(uint64_t);
+free_type_vector(float);
+free_type_vector(double);
+free_type_vector(void_p);
+free_type_vector(rgb8);
+free_type_vector(rgbx8);
+free_type_vector(rgb32);
+
+
+
+
+#if TARGET_OS == GIETVM
+#undef remote_type_vector
+#define remote_type_vector(t)                                                   \
+t * short_name(t,remote_,vector)(int32_t nl, int32_t nh, int32_t x, int32_t y) \
+{                                                                               \
+    t * v;                                                                      \
+    v = remote_malloc((nh - nl + 1 + NR_END) * sizeof(t), x, y);                \
+    if (v == NULL) {                                                            \
+        nrerror("*** Error: allocation failure in %s\n", __func__);             \
+    }                                                                           \
+    return v - nl + NR_END;                                                     \
 }
-/* --------------------------------------------- */
-IMAGE_EXPORT(uint16*) ui16vector0(long nl, long nh)
-/* --------------------------------------------- */
-{
-    uint16 *v;
-    
-    v=(uint16 *)calloc((size_t) ((nh-nl+1+NR_END)), sizeof(uint16));
-    if (!v) nrerror("allocation failure in ui16vector0()");
-    return v-nl+NR_END;
-}
-/* --------------------------------------------- */
-IMAGE_EXPORT(sint32*) si32vector0(long nl, long nh)
-/* --------------------------------------------- */
-/* allocate a sint32 vector with subscript range v[nl..nh] */
-{
-    sint32 *v;
-    
-    v=(sint32 *) calloc((size_t) (nh-nl+1+NR_END),sizeof(sint32));
-    if (!v) nrerror("allocation failure in si32vector0()");
-    return v-nl+NR_END;
-}
-/* --------------------------------------------- */
-IMAGE_EXPORT(uint32*) ui32vector0(long nl, long nh)
-/* --------------------------------------------- */
-/* allocate a uint32 vector with subscript range v[nl..nh] */
-{
-    uint32 *v;
-    
-    v=(uint32 *) calloc((size_t) (nh-nl+1+NR_END),sizeof(uint32));
-    if (!v) nrerror("allocation failure in ui32vector0()");
-    return v-nl+NR_END;
-}
-/* --------------------------------------------- */
-IMAGE_EXPORT(float32*) f32vector0(long nl, long nh)
-/* --------------------------------------------- */
-/* allocate a float32 vector with subscript range v[nl..nh] */
-{
-    float32 *v;
-    
-    v=(float32 *) calloc ( (size_t) (nh-nl+1+NR_END), sizeof(float32) );
-    if (!v) nrerror("allocation failure in f32vector0()");
-    if(!v) return NULL;
-    return v-nl+NR_END;
-}
-/* --------------------------------------------- */
-IMAGE_EXPORT(float64*) f64vector0(long nl, long nh)
-/* --------------------------------------------- */
-/* allocate a float vector with subscript range v[nl..nh] */
-{
-    float64 *v;
-    
-    v=(float64 *) calloc ( (size_t) (nh-nl+1+NR_END), sizeof(float64) );
-    if (!v) nrerror("allocation failure in f64vector0()");
-    if(!v) return NULL;
-    return v-nl+NR_END;
-}
-/* ------------------------------------------- */
-IMAGE_EXPORT(rgb8*) rgb8vector0(long nl, long nh)
-/* ------------------------------------------- */
-{
-    rgb8 *v;
-    
-    v=(rgb8 *)calloc((size_t) ((nh-nl+1+NR_END)), sizeof(rgb8));
-    if (!v) nrerror("allocation failure in rgb8vector0()");
-    return v-nl+NR_END;
-}
-/* --------------------------------------------- */
-IMAGE_EXPORT(rgbx8*) rgbx8vector0(long nl, long nh)
-/* --------------------------------------------- */
-{
-    rgbx8 *v;
-    
-    v=(rgbx8 *)calloc((size_t) ((nh-nl+1+NR_END)), sizeof(rgbx8));
-    if (!v) nrerror("allocation failure in rgbx8vector0()");
-    return v-nl+NR_END;
-}
-/* --------------------------------------------- */
-IMAGE_EXPORT(rgb32*) rgb32vector0(long nl, long nh)
-/* --------------------------------------------- */
-{
-    rgb32 *v;
-    
-    v=(rgb32 *)calloc((size_t) ((nh-nl+1+NR_END)), sizeof(rgb32));
-    if (!v) nrerror("allocation failure in rgb32vector0()");
-    return v-nl+NR_END;
-}
-/*
- * ----------------------
- * --- realloc_vector ---
- * ----------------------
- */
 
-/* ------------------------------------------------------------ */
-IMAGE_EXPORT(sint8*) realloc_si8vector(sint8 *v, long nl, long nh)
-/* ------------------------------------------------------------ */
-{
-    v += nl;
-    v -= NR_END;
-    v=(sint8 *)realloc(v, (size_t) ((nh-nl+1+NR_END)*sizeof(sint8)));
-    if (!v) nrerror("allocation failure in realloc_si8vector()");
-    
-    return v-nl+NR_END;
-}
-/* ------------------------------------------------------------ */
-IMAGE_EXPORT(uint8*) realloc_ui8vector(uint8 *v, long nl, long nh)
-/* ------------------------------------------------------------ */
-{
-    v += nl;
-    v -= NR_END;
-    v=(uint8 *)realloc(v, (size_t) ((nh-nl+1+NR_END)*sizeof(uint8)));
-    if (!v) nrerror("allocation failure in realloc_ui8vector()");
-    
-    return v-nl+NR_END;
-}
-/* --------------------------------------------------------------- */
-IMAGE_EXPORT(sint16*) realloc_si16vector(sint16 *v, long nl, long nh)
-/* --------------------------------------------------------------- */
-{
-    v += nl;
-    v -= NR_END;
-    v=(sint16 *)realloc(v, (size_t) ((nh-nl+1+NR_END)*sizeof(sint16)));
-    if (!v) nrerror("allocation failure in realloc_si16vector()");
-    
-    return v-nl+NR_END;
-}
-/* --------------------------------------------------------------- */
-IMAGE_EXPORT(uint16*) realloc_ui16vector(uint16 *v, long nl, long nh)
-/* --------------------------------------------------------------- */
-{
-    v += nl;
-    v -= NR_END;
-    v=(uint16 *)realloc(v, (size_t) ((nh-nl+1+NR_END)*sizeof(uint16)));
-    if (!v) nrerror("allocation failure in realloc_ui16vector()");
-    
-    return v-nl+NR_END;
-}
-/* --------------------------------------------------------------- */
-IMAGE_EXPORT(sint32*) realloc_si32vector(sint32 *v, long nl, long nh)
-/* --------------------------------------------------------------- */
-{
-    v += nl;
-    v -= NR_END;
-    v=(sint32 *)realloc(v, (size_t) ((nh-nl+1+NR_END)*sizeof(sint32)));
-    if (!v) nrerror("allocation failure in realloc_si32vector()");
-    
-    return v-nl+NR_END;
-}
-/* --------------------------------------------------------------- */
-IMAGE_EXPORT(uint32*) realloc_ui32vector(uint32 *v, long nl, long nh)
-/* --------------------------------------------------------------- */
-{
-    v += nl;
-    v -= NR_END;
-    v=(uint32 *)realloc(v, (size_t) ((nh-nl+1+NR_END)*sizeof(uint32)));
-    if (!v) nrerror("allocation failure in realloc_ui32vector()");
-    
-    return v-nl+NR_END;
-}
-/* --------------------------------------------------------------- */
-IMAGE_EXPORT(sint64*) realloc_si64vector(sint64 *v, long nl, long nh)
-/* --------------------------------------------------------------- */
-{
-    v += nl;
-    v -= NR_END;
-    v=(sint64 *)realloc(v, (size_t) ((nh-nl+1+NR_END)*sizeof(sint64)));
-    if (!v) nrerror("allocation failure in realloc_si64vector()");
-    
-    return v-nl+NR_END;
-}
-/* --------------------------------------------------------------- */
-IMAGE_EXPORT(uint64*) realloc_ui64vector(uint64 *v, long nl, long nh)
-/* --------------------------------------------------------------- */
-{
-    v += nl;
-    v -= NR_END;
-    v=(uint64 *)realloc(v, (size_t) ((nh-nl+1+NR_END)*sizeof(uint64)));
-    if (!v) nrerror("allocation failure in realloc_ui64vector()");
-    
-    return v-nl+NR_END;
-}
-/* ---------------------------------------------------------- */
-IMAGE_EXPORT(rgb8*) realloc_rgb8vector(rgb8 *v, long nl, long nh)
-/* ---------------------------------------------------------- */
-{
-    v += nl;
-    v -= NR_END;
-    v=(rgb8 *)realloc(v, (size_t) ((nh-nl+1+NR_END)*sizeof(rgb8)));
-    if (!v) nrerror("allocation failure in realloc_rgb8vector()");
-    
-    return v-nl+NR_END;
-}
-/* -------------------------------------------------------------- */
-IMAGE_EXPORT(rgbx8*) realloc_rgbx8vector(rgbx8 *v, long nl, long nh)
-/* -------------------------------------------------------------- */
-{
-    v += nl;
-    v -= NR_END;
-    v=(rgbx8 *)realloc(v, (size_t) ((nh-nl+1+NR_END)*sizeof(rgbx8)));
-    if (!v) nrerror("allocation failure in realloc_rgbx8vector()");
-    
-    return v-nl+NR_END;
-}
-/* -------------------------------------------------------------- */
-IMAGE_EXPORT(rgb32*) realloc_rgb32vector(rgb32 *v, long nl, long nh)
-/* -------------------------------------------------------------- */
-{
-    v += nl;
-    v -= NR_END;
-    v=(rgb32 *)realloc(v, (size_t) ((nh-nl+1+NR_END)*sizeof(rgb32)));
-    if (!v) nrerror("allocation failure in realloc_rgb32vector()");
-    
-    return v-nl+NR_END;
-}
-/* ---------------------------------------------------------- */
-IMAGE_EXPORT(void**) realloc_vvector(void **v, long nl, long nh)
-/* ---------------------------------------------------------- */
-/*
-* add n item to an void* vector with subscript range
-* fromv[nl..nh] to [nl..nh+n] */
-{
-    v += nl;
-    v -= NR_END;
-    v=(void**)realloc(v, (size_t) ((nh-nl+1+NR_END)*sizeof(void*)));
-    if (!v) nrerror("allocation failure in realloc vvector()");
-    
-    return v-nl+NR_END;
-}
-/*
- * -------------------
- * --- free_vector ---
- * -------------------
- */
+remote_type_vector(int8_t);
+remote_type_vector(uint8_t);
+remote_type_vector(int16_t);
+remote_type_vector(uint16_t);
+remote_type_vector(int32_t);
+remote_type_vector(uint32_t);
+remote_type_vector(int64_t);
+remote_type_vector(uint64_t);
+remote_type_vector(float);
+remote_type_vector(double);
+remote_type_vector(void_p);
+remote_type_vector(rgb8);
+remote_type_vector(rgbx8);
+remote_type_vector(rgb32);
 
-/* free a byte vector allocated with bvector() */
+#endif
 
-/* ------------------------------------------------------- */
-IMAGE_EXPORT(void) free_si8vector(sint8 *v, long nl, long nh)
-/* ------------------------------------------------------- */
-{
-    free((FREE_ARG) (v+nl-NR_END));
-}
-/* ------------------------------------------------------- */
-IMAGE_EXPORT(void) free_ui8vector(uint8 *v, long nl, long nh)
-/* ------------------------------------------------------- */
-{
-    free((FREE_ARG) (v+nl-NR_END));
-}
-/* --------------------------------------------------------- */
-IMAGE_EXPORT(void) free_si16vector(sint16 *v, long nl, long nh)
-/* --------------------------------------------------------- */
-{
-    free((FREE_ARG) (v+nl-NR_END));
-}
-/* ------------------------------------------------------- */
-IMAGE_EXPORT(void) free_ui16vector(uint16 *v, long nl, long nh)
-/* ------------------------------------------------------- */
-{
-    free((FREE_ARG) (v+nl-NR_END));
-}
-/* --------------------------------------------------------- */
-IMAGE_EXPORT(void) free_si32vector(sint32 *v, long nl, long nh)
-/* --------------------------------------------------------- */
-{
-    free((FREE_ARG) (v+nl-NR_END));
-}
-/* --------------------------------------------------------- */
-IMAGE_EXPORT(void) free_ui32vector(uint32 *v, long nl, long nh)
-/* --------------------------------------------------------- */
-{
-    free((FREE_ARG) (v+nl-NR_END));
-}
-/* --------------------------------------------------------- */
-IMAGE_EXPORT(void) free_si64vector(sint64 *v, long nl, long nh)
-/* --------------------------------------------------------- */
-{
-    free((FREE_ARG) (v+nl-NR_END));
-}
-/* --------------------------------------------------------- */
-IMAGE_EXPORT(void) free_ui64vector(uint64 *v, long nl, long nh)
-/* --------------------------------------------------------- */
-{
-    free((FREE_ARG) (v+nl-NR_END));
-}
-/* ---------------------------------------------------- */
-IMAGE_EXPORT(void) free_f32vector(float32 *v, long nl, long nh)
-/* ---------------------------------------------------- */
-{
-    free((FREE_ARG) (v+nl-NR_END));
-}
-/* ---------------------------------------------------- */
-IMAGE_EXPORT(void) free_f64vector(float64 *v, long nl, long nh)
-/* ---------------------------------------------------- */
-{
-    free((FREE_ARG) (v+nl-NR_END));
-}
-/* -------------------------------------------------------- */
-IMAGE_EXPORT(void) free_rgb8vector(rgb8 *v, long nl, long nh)
-/* -------------------------------------------------------- */
-{
-    free((FREE_ARG) (v+nl-NR_END));
-}
-/* --------------------------------------------------------- */
-IMAGE_EXPORT(void) free_rgbx8vector(rgbx8 *v, long nl, long nh)
-/* --------------------------------------------------------- */
-{
-    free((FREE_ARG) (v+nl-NR_END));
-}
-/* ------------------------------------------------------- */
-IMAGE_EXPORT(void) free_rgb32vector(rgb32 *v, long nl, long nh)
-/* ------------------------------------------------------- */
-{
-    free((FREE_ARG) (v+nl-NR_END));
-}
-/* ----------------------------------------------------- */
-IMAGE_EXPORT(void) free_vvector(void **v, long nl, long nh)
-/* ----------------------------------------------------- */
-{
-    free((FREE_ARG) (v+nl-NR_END));
-}
+// Local Variables:
+// tab-width: 4
+// c-basic-offset: 4
+// c-file-offsets:((innamespace . 0)(inline-open . 0))
+// indent-tabs-mode: nil
+// End:
+
+// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4
+
Index: soft/giet_vm/applications/rosenfeld/nrc2/src/nralloc2.c
===================================================================
--- soft/giet_vm/applications/rosenfeld/nrc2/src/nralloc2.c	(revision 820)
+++ soft/giet_vm/applications/rosenfeld/nrc2/src/nralloc2.c	(revision 821)
@@ -30,15 +30,14 @@
 #include <malloc.h>
 #include <math.h> // fabs
-// #include <memory.h> // memcpy
-
+
+#include "nrc_os_config.h"
 #include "mypredef.h"
 #include "nrtype.h"
+#include "nrtypex.h"
 #include "nrdef.h"
 #include "nrmacro.h"
 #include "nrkernel.h"
 
-#include "nralloc1.h"
 #include "nralloc2.h"
-//#include "nrarith.h"
 
 /*
@@ -47,1001 +46,210 @@
  * --------------
  */
-/* ------------------------------------------------ */
-float** matrix(long nrl, long nrh, long ncl, long nch)
-/* ------------------------------------------------ */
-{
-    long i, nrow=nrh-nrl+1,ncol=nch-ncl+1;
-    float **m;
-    
-    /* allocate pointers to rows */
-    m=(float **) malloc((size_t)((nrow+NR_END)*sizeof(float*)));
-    if (!m) nrerror("allocation failure 1 in matrix()");
-    m += NR_END;
-    m -= nrl;
-    
-    
-    /* allocate rows and set pointers to them */
-    m[nrl]=(float *) malloc((size_t)((nrow*ncol+NR_END)*sizeof(float)));
-    if (!m[nrl]) nrerror("allocation failure 2 in matrix()");
-    m[nrl] += NR_END;
-    m[nrl] -= ncl;
-    
-    for(i=nrl+1;i<=nrh;i++) m[i]=m[i-1]+ncol;
-    
-    /* return pointer to array of pointers to rows */
-    return m;
-}
-/* -------------------------------------------------------------- */
-IMAGE_EXPORT(byte**) bmatrix(long nrl, long nrh, long ncl, long nch)
-/* -------------------------------------------------------------- */
-{
-    long i, nrow=nrh-nrl+1,ncol=nch-ncl+1;
-    byte **m;
-    
-    /* allocate pointers to rows */
-    m=(byte **) malloc((size_t)((nrow+NR_END)*sizeof(byte*)));
-    if (!m) nrerror("allocation failure 1 in bmatrix()");
-    m += NR_END;
-    m -= nrl;
-    
-    
-    /* allocate rows and set pointers to them */
-    m[nrl]=(byte *) malloc((size_t)((nrow*ncol+NR_END)*sizeof(byte)));
-    if (!m[nrl]) nrerror("allocation failure 2 in bmatrix()");
-    m[nrl] += NR_END;
-    m[nrl] -= ncl;
-    
-    for(i=nrl+1;i<=nrh;i++) m[i]=m[i-1]+ncol;
-    
-    /* return pointer to array of pointers to rows */
-    return m;
-}/* ---------------------------------------------------------------- */
-IMAGE_EXPORT(sint8**) si8matrix(long nrl, long nrh, long ncl, long nch)
-/* ----------------------------------------------------------------- */
-{
-    long i, nrow=nrh-nrl+1,ncol=nch-ncl+1;
-    sint8 **m;
-    
-    /* allocate pointers to rows */
-    m=(sint8 **) malloc((size_t)((nrow+NR_END)*sizeof(sint8*)));
-    if (!m) nrerror("allocation failure 1 in i8matrix()");
-    m += NR_END;
-    m -= nrl;
-    
-    /* allocate rows and set pointers to them */
-    m[nrl]=(sint8 *) malloc((size_t)((nrow*ncol+NR_END)*sizeof(sint8)));
-    if (!m[nrl]) nrerror("allocation failure 2 in i8matrix()");
-    m[nrl] += NR_END;
-    m[nrl] -= ncl;
-    
-    for(i=nrl+1;i<=nrh;i++) m[i]=m[i-1]+ncol;
-    
-    /* return pointer to array of pointers to rows */
-    return m;
-}
-/* ----------------------------------------------------------------- */
-IMAGE_EXPORT(uint8**) ui8matrix(long nrl, long nrh, long ncl, long nch)
-/* ----------------------------------------------------------------- */
-{
-    long i, nrow=nrh-nrl+1,ncol=nch-ncl+1;
-    uint8 **m;
-    
-    /* allocate pointers to rows */
-    m=(uint8 **) malloc((size_t)((nrow+NR_END)*sizeof(uint8*)));
-    if (!m) nrerror("allocation failure 1 in ui8matrix()");
-    m += NR_END;
-    m -= nrl;
-    
-    /* allocate rows and set pointers to them */
-    m[nrl]=(uint8 *) malloc((size_t)((nrow*ncol+NR_END)*sizeof(uint8)));
-    if (!m[nrl]) nrerror("allocation failure 2 in ui8matrix()");
-    m[nrl] += NR_END;
-    m[nrl] -= ncl;
-    
-    for(i=nrl+1;i<=nrh;i++) m[i]=m[i-1]+ncol;
-    
-    /* return pointer to array of pointers to rows */
-    return m;
-}
-/* ------------------------------------------------------------------- */
-IMAGE_EXPORT(sint16**) si16matrix(long nrl, long nrh, long ncl, long nch)
-/* ------------------------------------------------------------------- */
-{
-    long i, nrow=nrh-nrl+1,ncol=nch-ncl+1;
-    sint16 **m;
-    
-    /* allocate pointers to rows */
-    m=(sint16 **) malloc((size_t)((nrow+NR_END)*sizeof(sint16*)));
-    if (!m) nrerror("allocation failure 1 in si16matrix()");
-    m += NR_END;
-    m -= nrl;
-    
-    /* allocate rows and set pointers to them */
-    m[nrl]=(sint16 *) malloc((size_t)((nrow*ncol+NR_END)*sizeof(sint16)));
-    if (!m[nrl]) nrerror("allocation failure 2 in si16matrix()");
-    m[nrl] += NR_END;
-    m[nrl] -= ncl;
-    
-    for(i=nrl+1;i<=nrh;i++) m[i]=m[i-1]+ncol;
-    
-    /* return pointer to array of pointers to rows */
-    return m;
-}
-/* ------------------------------------------------------------------- */
-IMAGE_EXPORT(uint16**) ui16matrix(long nrl, long nrh, long ncl, long nch)
-/* ------------------------------------------------------------------- */
-{
-    long i, nrow=nrh-nrl+1,ncol=nch-ncl+1;
-    uint16 **m;
-    
-    /* allocate pointers to rows */
-    m=(uint16 **) malloc((size_t)((nrow+NR_END)*sizeof(uint16*)));
-    if (!m) nrerror("allocation failure 1 in ui16matrix()");
-    m += NR_END;
-    m -= nrl;
-    
-    /* allocate rows and set pointers to them */
-    m[nrl]=(uint16 *) malloc((size_t)((nrow*ncol+NR_END)*sizeof(uint16)));
-    if (!m[nrl]) nrerror("allocation failure 2 in ui16matrix()");
-    m[nrl] += NR_END;
-    m[nrl] -= ncl;
-    
-    for(i=nrl+1;i<=nrh;i++)
-        m[i]=m[i-1]+ncol;
-    
-    /* return pointer to array of pointers to rows */
-    return m;
-}
-/* ------------------------------------------------------------------- */
-IMAGE_EXPORT(sint32**) si32matrix(long nrl, long nrh, long ncl, long nch)
-/* ------------------------------------------------------------------- */
-/* allocate a int32 matrix with subscript range m[nrl..nrh][ncl..nch] */
-{
-    long i, nrow=nrh-nrl+1,ncol=nch-ncl+1;
-    sint32 **m;
-    
-    /* allocate pointers to rows */
-    m=(sint32 **) malloc((size_t)((nrow+NR_END)*sizeof(sint32*)));
-    if (!m) nrerror("allocation failure 1 in si32matrix()");
-    m += NR_END;
-    m -= nrl;
-    
-    /* allocate rows and set pointers to them */
-    m[nrl]=(sint32 *) malloc((size_t)((nrow*ncol+NR_END)*sizeof(sint32)));
-    if (!m[nrl]) nrerror("allocation failure 2 in si32matrix()");
-    m[nrl] += NR_END;
-    m[nrl] -= ncl;
-    
-    for(i=nrl+1;i<=nrh;i++) m[i]=m[i-1]+ncol;
-    
-    /* return pointer to array of pointers to rows */
-    return m;
-}
-/* ------------------------------------------------------------------- */
-IMAGE_EXPORT(uint32**) ui32matrix(long nrl, long nrh, long ncl, long nch)
-/* ------------------------------------------------------------------- */
-/* allocate a uint32 matrix with subscript range m[nrl..nrh][ncl..nch] */
-{
-    long i, nrow=nrh-nrl+1,ncol=nch-ncl+1;
-    uint32 **m;
-    
-    /* allocate pointers to rows */
-    m=(uint32 **) malloc((size_t)((nrow+NR_END)*sizeof(uint32*)));
-    if (!m) nrerror("allocation failure 1 in ui32matrix()");
-    m += NR_END;
-    m -= nrl;
-    
-    /* allocate rows and set pointers to them */
-    m[nrl]=(uint32 *) malloc((size_t)((nrow*ncol+NR_END)*sizeof(uint32)));
-    if (!m[nrl]) nrerror("allocation failure 2 in ui32matrix()");
-    m[nrl] += NR_END;
-    m[nrl] -= ncl;
-    
-    for(i=nrl+1;i<=nrh;i++)
-        m[i]=m[i-1]+ncol;
-    
-    /* return pointer to array of pointers to rows */
-    return m;
-}
-/* ------------------------------------------------------------------- */
-IMAGE_EXPORT(sint64**) si64matrix(long nrl, long nrh, long ncl, long nch)
-/* ------------------------------------------------------------------- */
-/* allocate a int64 matrix with subscript range m[nrl..nrh][ncl..nch] */
-{
-    long i, nrow=nrh-nrl+1,ncol=nch-ncl+1;
-    sint64 **m;
-    
-    /* allocate pointers to rows */
-    m=(sint64 **) malloc((size_t)((nrow+NR_END)*sizeof(sint64*)));
-    if (!m) nrerror("allocation failure 1 in si64matrix()");
-    m += NR_END;
-    m -= nrl;
-    
-    /* allocate rows and set pointers to them */
-    m[nrl]=(sint64 *) malloc((size_t)((nrow*ncol+NR_END)*sizeof(sint64)));
-    if (!m[nrl]) nrerror("allocation failure 2 in si64matrix()");
-    m[nrl] += NR_END;
-    m[nrl] -= ncl;
-    
-    for(i=nrl+1;i<=nrh;i++) m[i]=m[i-1]+ncol;
-    
-    /* return pointer to array of pointers to rows */
-    return m;
-}
-/* ------------------------------------------------------------------- */
-IMAGE_EXPORT(uint64**) ui64matrix(long nrl, long nrh, long ncl, long nch)
-/* ------------------------------------------------------------------- */
-/* allocate a int64 matrix with subscript range m[nrl..nrh][ncl..nch] */
-{
-    long i, nrow=nrh-nrl+1,ncol=nch-ncl+1;
-    uint64 **m;
-    
-    /* allocate pointers to rows */
-    m=(uint64 **) malloc((size_t)((nrow+NR_END)*sizeof(uint64*)));
-    if (!m) nrerror("allocation failure 1 in ui64matrix()");
-    m += NR_END;
-    m -= nrl;
-    
-    /* allocate rows and set pointers to them */
-    m[nrl]=(uint64 *) malloc((size_t)((nrow*ncol+NR_END)*sizeof(uint64)));
-    if (!m[nrl]) nrerror("allocation failure 2 in ui64matrix()");
-    m[nrl] += NR_END;
-    m[nrl] -= ncl;
-    
-    for(i=nrl+1;i<=nrh;i++) m[i]=m[i-1]+ncol;
-    
-    /* return pointer to array of pointers to rows */
-    return m;
-}
-/* ------------------------------------------------------------------- */
-IMAGE_EXPORT(float32**) f32matrix(long nrl, long nrh, long ncl, long nch)
-/* ------------------------------------------------------------------- */
-/* allocate a float matrix with subscript range m[nrl..nrh][ncl..nch] */
-{
-    long i, nrow=nrh-nrl+1,ncol=nch-ncl+1;
-    float32 **m;
-    
-    /* allocate pointers to rows */
-    m=(float32 **) malloc((size_t)((nrow+NR_END)*sizeof(float32*)));
-    if (!m) nrerror("allocation failure 1 in f32matrix()");
-    m += NR_END;
-    m -= nrl;
-    
-    /* allocate rows and set pointers to them */
-    m[nrl]=(float32 *) malloc((size_t)((nrow*ncol+NR_END)*sizeof(float32)));
-    if (!m[nrl]) nrerror("allocation failure 2 in f32matrix()");
-    m[nrl] += NR_END;
-    m[nrl] -= ncl;
-    
-    for(i=nrl+1;i<=nrh;i++) m[i]=m[i-1]+ncol;
-    
-    /* return pointer to array of pointers to rows */
-    return m;
-}/* ------------------------------------------------------------------- */
-IMAGE_EXPORT(float64**) f64matrix(long nrl, long nrh, long ncl, long nch)
-/* ------------------------------------------------------------------- */
-
-/* allocate a float matrix with subscript range m[nrl..nrh][ncl..nch] */
-{
-    long i, nrow=nrh-nrl+1,ncol=nch-ncl+1;
-    float64 **m;
-    
-    /* allocate pointers to rows */
-    m=(float64 **) malloc((size_t)((nrow+NR_END)*sizeof(float64*)));
-    if (!m) nrerror("allocation failure 1 in f64matrix()");
-    m += NR_END;
-    m -= nrl;
-    
-    /* allocate rows and set pointers to them */
-    m[nrl]=(float64 *) malloc((size_t)((nrow*ncol+NR_END)*sizeof(float64)));
-    if (!m[nrl]) nrerror("allocation failure 2 in f64matrix()");
-    m[nrl] += NR_END;
-    m[nrl] -= ncl;
-    
-    for(i=nrl+1;i<=nrh;i++) m[i]=m[i-1]+ncol;
-    /* return pointer to array of pointers to rows */
-    return m;
-}
-/* --------------------------------------------------------------------- */
-IMAGE_EXPORT(complex32**) c32matrix(long nrl, long nrh, long ncl, long nch)
-/* --------------------------------------------------------------------- */
-/* allocate a complex32 matrix with subscript range m[nrl..nrh][ncl..nch] */
-{
-    long i, nrow=nrh-nrl+1,ncol=nch-ncl+1;
-    complex32 **m;
-    
-    /* allocate pointers to rows */
-    m=(complex32 **) malloc((size_t)((nrow+NR_END)*sizeof(complex32*)));
-    if (!m) nrerror("allocation failure 1 in c32matrix()");
-    m += NR_END;
-    m -= nrl;
-    
-    /* allocate rows and set pointers to them */
-    m[nrl]=(complex32 *) malloc((size_t)((nrow*ncol+NR_END)*sizeof(complex32)));
-    if (!m[nrl]) nrerror("allocation failure 2 in c32matrix()");
-    m[nrl] += NR_END;
-    m[nrl] -= ncl;
-    
-    for(i=nrl+1;i<=nrh;i++) m[i]=m[i-1]+ncol;
-    
-    /* return pointer to array of pointers to rows */
-    return m;
-}
-/* --------------------------------------------------------------------- */
-IMAGE_EXPORT(complex64**) c64matrix(long nrl, long nrh, long ncl, long nch)
-/* --------------------------------------------------------------------- */
-/* allocate a complex32 matrix with subscript range m[nrl..nrh][ncl..nch] */
-{
-    long i, nrow=nrh-nrl+1,ncol=nch-ncl+1;
-    complex64 **m;
-    
-    /* allocate pointers to rows */
-    m=(complex64 **) malloc((size_t)((nrow+NR_END)*sizeof(complex64*)));
-    if (!m) nrerror("allocation failure 1 in c64matrix()");
-    m += NR_END;
-    m -= nrl;
-    
-    /* allocate rows and set pointers to them */
-    m[nrl]=(complex64 *) malloc((size_t)((nrow*ncol+NR_END)*sizeof(complex64)));
-    if (!m[nrl]) nrerror("allocation failure 2 in c64matrix()");
-    m[nrl] += NR_END;
-    m[nrl] -= ncl;
-    
-    for(i=nrl+1;i<=nrh;i++) m[i]=m[i-1]+ncol;
-    
-    /* return pointer to array of pointers to rows */
-    return m;
-}
-/* ----------------------------------------------------------------- */
-IMAGE_EXPORT(rgb8**) rgb8matrix(long nrl, long nrh, long ncl, long nch)
-/* ----------------------------------------------------------------- */
-/* allocate a sint16  matrix with subscript range m[nrl..nrh][ncl..nch] */
-{
-    long i, nrow=nrh-nrl+1,ncol=nch-ncl+1;
-    rgb8 **m;
-    
-    /* allocate pointers to rows */
-    m=(rgb8**) malloc((size_t)((nrow+NR_END)*sizeof(rgb8*)));
-    if (!m) nrerror("allocation failure 1 in rgb8matrix()");
-    m += NR_END;
-    m -= nrl;
-    
-    /* allocate rows and set pointers to them */
-    m[nrl]=(rgb8*) malloc((size_t)((nrow*ncol+NR_END)*sizeof(rgb8)));
-    if (!m[nrl]) nrerror("allocation failure 2 in rgb8matrix()");
-    m[nrl] += NR_END;
-    m[nrl] -= ncl;
-    
-    for(i=nrl+1;i<=nrh;i++) m[i]=m[i-1]+ncol;
-    
-    /* return pointer to array of pointers to rows */
-    return m;
-}
-/* ------------------------------------------------------------------- */
-IMAGE_EXPORT(rgbx8**) rgbx8matrix(long nrl, long nrh, long ncl, long nch)
-/* ------------------------------------------------------------------- */
-/* allocate a sint16  matrix with subscript range m[nrl..nrh][ncl..nch] */
-{
-    long i, nrow=nrh-nrl+1,ncol=nch-ncl+1;
-    rgbx8 **m;
-    
-    /* allocate pointers to rows */
-    m=(rgbx8**) malloc((size_t)((nrow+NR_END)*sizeof(rgbx8*)));
-    if (!m) nrerror("allocation failure 1 in rgbx8matrix()");
-    m += NR_END;
-    m -= nrl;
-    
-    /* allocate rows and set pointers to them */
-    m[nrl]=(rgbx8*) malloc((size_t)((nrow*ncol+NR_END)*sizeof(rgbx8)));
-    if (!m[nrl]) nrerror("allocation failure 2 in rgbx8matrix()");
-    m[nrl] += NR_END;
-    m[nrl] -= ncl;
-    
-    for(i=nrl+1;i<=nrh;i++) m[i]=m[i-1]+ncol;
-    
-    /* return pointer to array of pointers to rows */
-    return m;
-}
-/* ------------------------------------------------------------------- */
-IMAGE_EXPORT(rgb32**) rgb32matrix(long nrl, long nrh, long ncl, long nch)
-/* ------------------------------------------------------------------- */
-/* allocate a sint16  matrix with subscript range m[nrl..nrh][ncl..nch] */
-{
-    long i, nrow=nrh-nrl+1,ncol=nch-ncl+1;
-    rgb32 **m;
-    
-    /* allocate pointers to rows */
-    m=(rgb32**) malloc((size_t)((nrow+NR_END)*sizeof(rgb32*)));
-    if (!m) nrerror("allocation failure 1 in rgb32matrix()");
-    m += NR_END;
-    m -= nrl;
-    
-    /* allocate rows and set pointers to them */
-    m[nrl]=(rgb32*) malloc((size_t)((nrow*ncol+NR_END)*sizeof(rgb32)));
-    if (!m[nrl]) nrerror("allocation failure 2 in rgb32matrix()");
-    m[nrl] += NR_END;
-    m[nrl] -= ncl;
-    
-    for(i=nrl+1;i<=nrh;i++) m[i]=m[i-1]+ncol;
-    
-    /* return pointer to array of pointers to rows */
-    return m;
-}
-/* --------------------------------------------------------------------- */
-IMAGE_EXPORT(rgbx32**) rgbx32matrix(long nrl, long nrh, long ncl, long nch)
-/* --------------------------------------------------------------------- */
-/* allocate a sint16  matrix with subscript range m[nrl..nrh][ncl..nch] */
-{
-    long i, nrow=nrh-nrl+1,ncol=nch-ncl+1;
-    rgbx32 **m;
-    
-    /* allocate pointers to rows */
-    m=(rgbx32**) malloc((size_t)((nrow+NR_END)*sizeof(rgbx32*)));
-    if (!m) nrerror("allocation failure 1 in rgbx32matrix()");
-    m += NR_END;
-    m -= nrl;
-    
-    /* allocate rows and set pointers to them */
-    m[nrl]=(rgbx32*) malloc((size_t)((nrow*ncol+NR_END)*sizeof(rgbx32)));
-    if (!m[nrl]) nrerror("allocation failure 2 in rgbx32matrix()");
-    m[nrl] += NR_END;
-    m[nrl] -= ncl;
-    
-    for(i=nrl+1;i<=nrh;i++) m[i]=m[i-1]+ncol;
-    
-    /* return pointer to array of pointers to rows */
-    return m;
-}
-
-/*
- * ---------------
- * --- matrix0 ---
- * ---------------
- */
-
-/* --------------------------------------------------------------- */
-IMAGE_EXPORT(byte**) bmatrix0(long nrl, long nrh, long ncl, long nch)
-/* --------------------------------------------------------------- */
-/* allocate a byte matrix with subscript range m[nrl..nrh][ncl..nch] */
-{
-    long i, nrow=nrh-nrl+1,ncol=nch-ncl+1;
-    byte **m;
-    
-    /* allocate pointers to rows */
-    m=(byte **) malloc((size_t)((nrow+NR_END)*sizeof(byte*)));
-    if (!m) nrerror("allocation failure 1 in bmatrix0()");
-    m += NR_END;
-    m -= nrl;
-    
-    /* allocate rows and set pointers to them */
-    m[nrl]=(byte *) calloc((size_t)(nrow*ncol+NR_END),sizeof(byte));
-    if (!m[nrl]) nrerror("allocation failure 2 in bmatrix0()");
-    m[nrl] += NR_END;
-    m[nrl] -= ncl;
-    
-    for(i=nrl+1;i<=nrh;i++) m[i]=m[i-1]+ncol;
-    
-    /* return pointer to array of pointers to rows */
-    return m;
-}
-/* ------------------------------------------------------------------ */
-IMAGE_EXPORT(sint8**) si8matrix0(long nrl, long nrh, long ncl, long nch)
-/* ------------------------------------------------------------------ */
-{
-    long i, nrow=nrh-nrl+1,ncol=nch-ncl+1;
-    sint8 **m;
-    
-    /* allocate pointers to rows */
-    m=(sint8 **) malloc((size_t)((nrow+NR_END)*sizeof(sint8*)));
-    if (!m) nrerror("allocation failure 1 in i8matrix0()");
-    m += NR_END;
-    m -= nrl;
-    
-    /* allocate rows and set pointers to them */
-    m[nrl]=(sint8 *) calloc((size_t)(nrow*ncol+NR_END),sizeof(sint8));
-    if (!m[nrl]) nrerror("allocation failure 2 in imatrix0()");
-    m[nrl] += NR_END;
-    m[nrl] -= ncl;
-    
-    for(i=nrl+1;i<=nrh;i++) m[i]=m[i-1]+ncol;
-    
-    /* return pointer to array of pointers to rows */
-    return m;
-}
-/* ------------------------------------------------------------------ */
-IMAGE_EXPORT(uint8**) ui8matrix0(long nrl, long nrh, long ncl, long nch)
-/* ------------------------------------------------------------------ */
-{
-    long i, nrow=nrh-nrl+1,ncol=nch-ncl+1;
-    uint8 **m;
-    
-    /* allocate pointers to rows */
-    m=(uint8 **) malloc((size_t)((nrow+NR_END)*sizeof(uint8*)));
-    if (!m) nrerror("allocation failure 1 in ui8matrix0()");
-    m += NR_END;
-    m -= nrl;
-    
-    /* allocate rows and set pointers to them */
-    m[nrl]=(uint8 *) calloc((size_t)(nrow*ncol+NR_END),sizeof(uint8));
-    if (!m[nrl]) nrerror("allocation failure 2 in ui8matrix0()");
-    m[nrl] += NR_END;
-    m[nrl] -= ncl;
-    
-    for(i=nrl+1;i<=nrh;i++) m[i]=m[i-1]+ncol;
-    
-    /* return pointer to array of pointers to rows */
-    return m;
-}
-/* -------------------------------------------------------------------- */
-IMAGE_EXPORT(sint16**) si16matrix0(long nrl, long nrh, long ncl, long nch)
-/* -------------------------------------------------------------------- */
-/* allocate a sint16  matrix with subscript range m[nrl..nrh][ncl..nch] */
-{
-    long i, nrow=nrh-nrl+1,ncol=nch-ncl+1;
-    sint16 **m;
-    
-    /* allocate pointers to rows */
-    m=(sint16 **) malloc((size_t)((nrow+NR_END)*sizeof(sint16*)));
-    if (!m) nrerror("allocation failure 1 in si16matrix0()");
-    m += NR_END;
-    m -= nrl;
-    
-    /* allocate rows and set pointers to them */
-    m[nrl]=(sint16 *) calloc(nrow*ncol, sizeof(int16));
-    if (!m[nrl]) nrerror("allocation failure 2 in si16matrix0()");
-    m[nrl] += NR_END;
-    m[nrl] -= ncl;
-    
-    for(i=nrl+1;i<=nrh;i++) m[i]=m[i-1]+ncol;
-    
-    /* return pointer to array of pointers to rows */
-    return m;
-}
-/* -------------------------------------------------------------------- */
-IMAGE_EXPORT(uint16**) ui16matrix0(long nrl, long nrh, long ncl, long nch)
-/* -------------------------------------------------------------------- */
-/* allocate a sint16  matrix with subscript range m[nrl..nrh][ncl..nch] */
-{
-    long i, nrow=nrh-nrl+1,ncol=nch-ncl+1;
-    uint16 **m;
-    
-    /* allocate pointers to rows */
-    m=(uint16 **) malloc((size_t)((nrow+NR_END)*sizeof(uint16*)));
-    if (!m) nrerror("allocation failure 1 in ui16matrix0()");
-    m += NR_END;
-    m -= nrl;
-    
-    /* allocate rows and set pointers to them */
-    m[nrl]=(uint16 *) calloc(nrow*ncol, sizeof(uint16));
-    if (!m[nrl]) nrerror("allocation failure 2 in ui16matrix0()");
-    m[nrl] += NR_END;
-    m[nrl] -= ncl;
-    
-    for(i=nrl+1;i<=nrh;i++) m[i]=m[i-1]+ncol;
-    
-    /* return pointer to array of pointers to rows */
-    return m;
-}
-/* -------------------------------------------------------------------- */
-IMAGE_EXPORT(sint32**) si32matrix0(long nrl, long nrh, long ncl, long nch)
-/* -------------------------------------------------------------------- */
-/* allocate a int32 matrix with subscript range m[nrl..nrh][ncl..nch] */
-{
-    long i, nrow=nrh-nrl+1,ncol=nch-ncl+1;
-    sint32 **m;
-    
-    /* allocate pointers to rows */
-    m=(sint32 **) malloc((size_t)((nrow+NR_END)*sizeof(sint32*)));
-    if (!m) nrerror("allocation failure 1 in si32matrix0()");
-    m += NR_END;
-    m -= nrl;
-    
-    /* allocate rows and set pointers to them */
-    m[nrl]=(sint32 *) calloc((size_t)(nrow*ncol+NR_END),sizeof(sint32));
-    if (!m[nrl]) nrerror("allocation failure 2 in si32matrix0()");
-    m[nrl] += NR_END;
-    m[nrl] -= ncl;
-    
-    for(i=nrl+1;i<=nrh;i++) m[i]=m[i-1]+ncol;
-    
-    /* return pointer to array of pointers to rows */
-    return m;
-}
-/* -------------------------------------------------------------------- */
-IMAGE_EXPORT(uint32**) ui32matrix0(long nrl, long nrh, long ncl, long nch)
-/* -------------------------------------------------------------------- */
-/* allocate a sint16  matrix with subscript range m[nrl..nrh][ncl..nch] */
-{
-    long i, nrow=nrh-nrl+1,ncol=nch-ncl+1;  
-    uint32 **m;
-    /* allocate pointers to rows */
-    m=(uint32 **) malloc((size_t)((nrow+NR_END)*sizeof(uint32*)));
-    if (!m) nrerror("allocation failure 1 in ui32matrix0()");
-    m += NR_END;
-    m -= nrl;
-
-    /* allocate rows and set pointers to them */
-    m[nrl]=(uint32 *) calloc((size_t)(nrow*ncol+NR_END), sizeof(uint32));
-    if (!m[nrl]) nrerror("allocation failure 2 in ui32matrix0()");
-    m[nrl] += NR_END;
-    m[nrl] -= ncl;
-    
-    for(i=nrl+1;i<=nrh;i++) m[i]=m[i-1]+ncol;
-    /* return pointer to array of pointers to rows */
-    return m;    
-}
-/* -------------------------------------------------------------------- */
-IMAGE_EXPORT(sint64**) si64matrix0(long nrl, long nrh, long ncl, long nch)
-/* -------------------------------------------------------------------- */
-{
-    long i, nrow=nrh-nrl+1,ncol=nch-ncl+1;
-    sint64 **m;
-    
-    /* allocate pointers to rows */
-    m=(sint64 **) malloc((size_t)((nrow+NR_END)*sizeof(sint64*)));
-    if (!m) nrerror("allocation failure 1 in si64matrix0()");
-    m += NR_END;
-    m -= nrl;
-    
-    /* allocate rows and set pointers to them */
-    m[nrl]=(sint64 *) calloc((size_t)(nrow*ncol+NR_END),sizeof(sint64));
-    if (!m[nrl]) nrerror("allocation failure 2 in si64matrix0()");
-    m[nrl] += NR_END;
-    m[nrl] -= ncl;
-    
-    for(i=nrl+1;i<=nrh;i++) m[i]=m[i-1]+ncol;
-    
-    /* return pointer to array of pointers to rows */
-    return m;
-}
-/* -------------------------------------------------------------------- */
-IMAGE_EXPORT(uint64**) ui64matrix0(long nrl, long nrh, long ncl, long nch)
-/* -------------------------------------------------------------------- */
-{
-    long i, nrow=nrh-nrl+1,ncol=nch-ncl+1;
-    uint64 **m;
-    
-    /* allocate pointers to rows */
-    m=(uint64 **) malloc((size_t)((nrow+NR_END)*sizeof(uint64*)));
-    if (!m) nrerror("allocation failure 1 in i64matrix0()");
-    m += NR_END;
-    m -= nrl;
-    
-    /* allocate rows and set pointers to them */
-    m[nrl]=(uint64 *) calloc((size_t)(nrow*ncol+NR_END),sizeof(uint64));
-    if (!m[nrl]) nrerror("allocation failure 2 in i64matrix0()");
-    m[nrl] += NR_END;
-    m[nrl] -= ncl;
-    
-    for(i=nrl+1;i<=nrh;i++) m[i]=m[i-1]+ncol;
-    
-    /* return pointer to array of pointers to rows */
-    return m;
-}
-/* -------------------------------------------------------------------- */
-IMAGE_EXPORT(float32**) f32matrix0(long nrl, long nrh, long ncl, long nch)
-/* -------------------------------------------------------------------- */
-{
-    long i, nrow=nrh-nrl+1,ncol=nch-ncl+1;
-    float32 **m;
-    
-    /* allocate pointers to rows */
-    m=(float32 **) malloc((size_t)((nrow+NR_END)*sizeof(float32*)));
-    if (!m) nrerror("allocation failure 1 in f32matrix0()");
-    m += NR_END;
-    m -= nrl;
-    
-    /* allocate rows and set pointers to them */
-    m[nrl]=(float32 *) calloc((size_t)(nrow*ncol+NR_END),sizeof(float32));
-    if (!m[nrl]) nrerror("allocation failure 2 in f32matrix0()");
-    m[nrl] += NR_END;
-    m[nrl] -= ncl;
-    
-    for(i=nrl+1;i<=nrh;i++) m[i]=m[i-1]+ncol;
-    
-    /* return pointer to array of pointers to rows */
-    return m;
-}
-/* -------------------------------------------------------------------- */
-IMAGE_EXPORT(float64**) f64matrix0(long nrl, long nrh, long ncl, long nch)
-/* -------------------------------------------------------------------- */
-{
-    long i, nrow=nrh-nrl+1,ncol=nch-ncl+1;
-    float64 **m;
-    
-    /* allocate pointers to rows */
-    m=(float64 **) malloc((size_t)((nrow+NR_END)*sizeof(float64*)));
-    if (!m) nrerror("allocation failure 1 in f64matrix0()");
-    m += NR_END;
-    m -= nrl;
-    
-    /* allocate rows and set pointers to them */
-    m[nrl]=(float64 *) calloc((size_t)(nrow*ncol+NR_END),sizeof(float64));
-    if (!m[nrl]) nrerror("allocation failure 2 in f64matrix0()");
-    m[nrl] += NR_END;
-    m[nrl] -= ncl;
-    
-    for(i=nrl+1;i<=nrh;i++) m[i]=m[i-1]+ncol;
-    /* return pointer to array of pointers to rows */
-    return m;
-}
-/* ---------------------------------------------------------------------- */
-IMAGE_EXPORT(complex32**) c32matrix0(long nrl, long nrh, long ncl, long nch)
-/* ---------------------------------------------------------------------- */
-{
-    long i, nrow=nrh-nrl+1,ncol=nch-ncl+1;
-    complex32 **m;
-    
-    /* allocate pointers to rows */
-    m=(complex32 **) malloc((size_t)((nrow+NR_END)*sizeof(complex32*)));
-    if (!m) nrerror("allocation failure 1 in c32matrix0()");
-    m += NR_END;
-    m -= nrl;
-    
-    /* allocate rows and set pointers to them */
-    m[nrl]=(complex32 *) calloc((size_t)(nrow*ncol+NR_END),sizeof(complex32));
-    if (!m[nrl]) nrerror("allocation failure 2 in c32matrix0()");
-    m[nrl] += NR_END;
-    m[nrl] -= ncl;
-    
-    for(i=nrl+1;i<=nrh;i++) m[i]=m[i-1]+ncol;
-    
-    /* return pointer to array of pointers to rows */
-    return m;
-}
-/* ---------------------------------------------------------------------- */
-IMAGE_EXPORT(complex64**) c64matrix0(long nrl, long nrh, long ncl, long nch)
-/* ---------------------------------------------------------------------- */
-{
-    long i, nrow=nrh-nrl+1,ncol=nch-ncl+1;
-    complex64 **m;
-    
-    /* allocate pointers to rows */
-    m=(complex64 **) malloc((size_t)((nrow+NR_END)*sizeof(complex64*)));
-    if (!m) nrerror("allocation failure 1 in c64matrix0()");
-    m += NR_END;
-    m -= nrl;
-    
-    /* allocate rows and set pointers to them */
-    m[nrl]=(complex64 *) calloc((size_t)(nrow*ncol+NR_END),sizeof(complex64));
-    if (!m[nrl]) nrerror("allocation failure 2 in c64matrix0()");
-    m[nrl] += NR_END;
-    m[nrl] -= ncl;
-    
-    for(i=nrl+1;i<=nrh;i++) m[i]=m[i-1]+ncol;
-    
-    /* return pointer to array of pointers to rows */
-    return m;
-}
-/* ------------------------------------------------------------------ */
-IMAGE_EXPORT(rgb8**) rgb8matrix0(long nrl, long nrh, long ncl, long nch)
-/* ------------------------------------------------------------------ */
-/* allocate a sint16  matrix with subscript range m[nrl..nrh][ncl..nch] */
-{
-    long i, nrow=nrh-nrl+1,ncol=nch-ncl+1;
-    rgb8 **m;
-    
-    /* allocate pointers to rows */
-    m=(rgb8**) malloc((size_t)((nrow+NR_END)*sizeof(rgb8*)));
-    if (!m) nrerror("allocation failure 1 in rgb8matrix0()");
-    m += NR_END;
-    m -= nrl;
-    
-    /* allocate rows and set pointers to them */
-    m[nrl]=(rgb8*) calloc((size_t)(nrow*ncol+NR_END), sizeof(rgb8));
-    if (!m[nrl]) nrerror("allocation failure 2 in rgb8matrix0()");
-    m[nrl] += NR_END;
-    m[nrl] -= ncl;
-    
-    for(i=nrl+1;i<=nrh;i++) m[i]=m[i-1]+ncol;
-    
-    /* return pointer to array of pointers to rows */
-    return m;
-}
-/* -------------------------------------------------------------------- */
-IMAGE_EXPORT(rgbx8**) rgbx8matrix0(long nrl, long nrh, long ncl, long nch)
-/* -------------------------------------------------------------------- */
-/* allocate a sint16  matrix with subscript range m[nrl..nrh][ncl..nch] */
-{
-    long i, nrow=nrh-nrl+1,ncol=nch-ncl+1;
-    rgbx8 **m;
-    
-    /* allocate pointers to rows */
-    m=(rgbx8**) malloc((size_t)((nrow+NR_END)*sizeof(rgbx8*)));
-    if (!m) nrerror("allocation failure 1 in rgbx8matrix()");
-    m += NR_END;
-    m -= nrl;
-    
-    /* allocate rows and set pointers to them */
-    m[nrl]=(rgbx8*) calloc((size_t)(nrow*ncol+NR_END), sizeof(rgbx8));
-    if (!m[nrl]) nrerror("allocation failure 2 in rgbx8matrix()");
-    m[nrl] += NR_END;
-    m[nrl] -= ncl;
-    
-    for(i=nrl+1;i<=nrh;i++) m[i]=m[i-1]+ncol;
-    
-    /* return pointer to array of pointers to rows */
-    return m;
-}
-/* -------------------------------------------------------------------- */
-IMAGE_EXPORT(rgb32**) rgb32matrix0(long nrl, long nrh, long ncl, long nch)
-/* -------------------------------------------------------------------- */
-/* allocate a rgb32 matrix with subscript range m[nrl..nrh][ncl..nch] */
-{
-    long i, nrow=nrh-nrl+1,ncol=nch-ncl+1;
-    rgb32 **m;
-    
-    /* allocate pointers to rows */
-    m=(rgb32**) malloc((size_t)((nrow+NR_END)*sizeof(rgb32*)));
-    if (!m) nrerror("allocation failure 1 in rgb32matrix0()");
-    m += NR_END;
-    m -= nrl;
-    
-    /* allocate rows and set pointers to them */
-    m[nrl]=(rgb32*) calloc((nrow*ncol+NR_END), sizeof(rgb32));
-    if (!m[nrl]) nrerror("allocation failure 2 in rgb32matrix0()");
-    m[nrl] += NR_END;
-    m[nrl] -= ncl;
-    
-    for(i=nrl+1;i<=nrh;i++) m[i]=m[i-1]+ncol;
-    
-    /* return pointer to array of pointers to rows */
-    return m;
-}
-/* ---------------------------------------------------------------------- */
-IMAGE_EXPORT(rgbx32**) rgbx32matrix0(long nrl, long nrh, long ncl, long nch)
-/* ---------------------------------------------------------------------- */
-/* allocate a rgb32 matrix with subscript range m[nrl..nrh][ncl..nch] */
-{
-    long i, nrow=nrh-nrl+1,ncol=nch-ncl+1;
-    rgbx32 **m;
-    
-    /* allocate pointers to rows */
-    m=(rgbx32**) malloc((size_t)((nrow+NR_END)*sizeof(rgbx32*)));
-    if (!m) nrerror("allocation failure 1 in rgbx32matrix()");
-    m += NR_END;
-    m -= nrl;
-    
-    /* allocate rows and set pointers to them */
-    m[nrl]=(rgbx32*) calloc((size_t)(nrow*ncol+NR_END), sizeof(rgbx32));
-    if (!m[nrl]) nrerror("allocation failure 2 in rgbx32matrix()");
-    m[nrl] += NR_END;
-    m[nrl] -= ncl;
-    
-    for(i=nrl+1;i<=nrh;i++) m[i]=m[i-1]+ncol;
-    
-    /* return pointer to array of pointers to rows */
-    return m;
-}
-/*
- * -------------------
- * --- free_matrix ---
- * -------------------
- */ 
-
-/* ------------------------------------------------------------- */
-void free_matrix(float **m, long nrl, long nrh, long ncl, long nch)
-/* ------------------------------------------------------------- */
-/* free a float matrix allocated by matrix() */
-{
-    free((FREE_ARG) (m[nrl]+ncl-NR_END));
-    free((FREE_ARG) (m+nrl-NR_END));
-}
-/* --------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) free_bmatrix(byte **m, long nrl, long nrh, long ncl, long nch)
-/* --------------------------------------------------------------------------- */
-{
-    free((FREE_ARG) (m[nrl]+ncl-NR_END));
-    free((FREE_ARG) (m+nrl-NR_END));
-}
-/* ------------------------------------------------------------------------------ */
-IMAGE_EXPORT(void) free_si8matrix(sint8 **m, long nrl, long nrh, long ncl, long nch)
-/* ------------------------------------------------------------------------------ */
-{
-    free((FREE_ARG) (m[nrl]+ncl-NR_END));
-    free((FREE_ARG) (m+nrl-NR_END));
-}
-/* ------------------------------------------------------------------------------ */
-IMAGE_EXPORT(void) free_ui8matrix(uint8 **m, long nrl, long nrh, long ncl, long nch)
-/* ------------------------------------------------------------------------------ */
-{
-    free((FREE_ARG) (m[nrl]+ncl-NR_END));
-    free((FREE_ARG) (m+nrl-NR_END));
-}/* -------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) free_si16matrix(sint16 **m, long nrl, long nrh, long ncl, long nch)
-/* -------------------------------------------------------------------------------- */
-{  
-    free((FREE_ARG) (m[nrl]+ncl-NR_END));
-    free((FREE_ARG) (m+nrl-NR_END));
-}
-/* -------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) free_ui16matrix(uint16 **m, long nrl, long nrh, long ncl, long nch)
-/* -------------------------------------------------------------------------------- */
-{  
-    free((FREE_ARG) (m[nrl]+ncl-NR_END));
-    free((FREE_ARG) (m+nrl-NR_END));
-}
-/* -------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) free_si32matrix(sint32 **m, long nrl, long nrh, long ncl, long nch)
-/* -------------------------------------------------------------------------------- */
-{  
-    free((FREE_ARG) (m[nrl]+ncl-NR_END));
-    free((FREE_ARG) (m+nrl-NR_END));
-}
-/* -------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) free_ui32matrix(uint32 **m, long nrl, long nrh, long ncl, long nch)
-/* -------------------------------------------------------------------------------- */
-{  
-    free((FREE_ARG) (m[nrl]+ncl-NR_END));
-    free((FREE_ARG) (m+nrl-NR_END));
-}
-/* -------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) free_si64matrix(sint64 **m, long nrl, long nrh, long ncl, long nch)
-/* -------------------------------------------------------------------------------- */
-{  
-    free((FREE_ARG) (m[nrl]+ncl-NR_END));
-    free((FREE_ARG) (m+nrl-NR_END));
-}
-/* -------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) free_ui64matrix(uint64 **m, long nrl, long nrh, long ncl, long nch)
-/* -------------------------------------------------------------------------------- */
-{  
-    free((FREE_ARG) (m[nrl]+ncl-NR_END));
-    free((FREE_ARG) (m+nrl-NR_END));
-}
-/* -------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) free_f32matrix(float32 **m, long nrl, long nrh, long ncl, long nch)
-/* -------------------------------------------------------------------------------- */
-{
-    free((FREE_ARG) (m[nrl]+ncl-NR_END));
-    free((FREE_ARG) (m+nrl-NR_END));
-}
-/* -------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) free_f64matrix(float64 **m, long nrl, long nrh, long ncl, long nch)
-/* -------------------------------------------------------------------------------- */
-{
-    free((FREE_ARG) (m[nrl]+ncl-NR_END));
-    free((FREE_ARG) (m+nrl-NR_END));
-}
-/* ---------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) free_c32matrix(complex32 **m, long nrl, long nrh, long ncl, long nch)
-/* ---------------------------------------------------------------------------------- */
-{
-    free((FREE_ARG) (m[nrl]+ncl-NR_END));
-    free((FREE_ARG) (m+nrl-NR_END));
-}
-/* ---------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) free_c64matrix(complex64 **m, long nrl, long nrh, long ncl, long nch)
-/* ---------------------------------------------------------------------------------- */
-{
-    free((FREE_ARG) (m[nrl]+ncl-NR_END));
-    free((FREE_ARG) (m+nrl-NR_END));
-}
-/* ------------------------------------------------------------------------------ */
-IMAGE_EXPORT(void) free_rgb8matrix(rgb8 **m, long nrl, long nrh, long ncl, long nch)
-/* ------------------------------------------------------------------------------ */
-{
-    free((FREE_ARG) (m[nrl]+ncl-NR_END));
-    free((FREE_ARG) (m+nrl-NR_END));
-}
-/* -------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) free_rgbx8matrix(rgbx8 **m, long nrl, long nrh, long ncl, long nch)
-/* -------------------------------------------------------------------------------- */
-{
-    free((FREE_ARG) (m[nrl]+ncl-NR_END));
-    free((FREE_ARG) (m+nrl-NR_END));
-}
-/* ------------------------------------------------------------------------------ */
-IMAGE_EXPORT(void) free_rgb32matrix(rgb32 **m, long nrl, long nrh, long ncl, long nch)
-/* ------------------------------------------------------------------------------ */
-{
-    free((FREE_ARG) (m[nrl]+ncl-NR_END));
-    free((FREE_ARG) (m+nrl-NR_END));
-}
-/* ---------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) free_rgbx32matrix(rgbx32 **m, long nrl, long nrh, long ncl, long nch)
-/* ---------------------------------------------------------------------------------- */
-{
-    free((FREE_ARG) (m[nrl]+ncl-NR_END));
-    free((FREE_ARG) (m+nrl-NR_END));
-}
+
+
+#undef type_matrix
+#define type_matrix(t) \
+t ** short_name(t,,matrix)(int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch) \
+{                                                                              \
+    int32_t nrow = nrh - nrl + 1;                                              \
+    int32_t ncol = nch - ncl + 1;                                              \
+    t ** m;                                                                    \
+    /* allocate pointers to row */                                             \
+    m = malloc((nrow + NR_END) * sizeof(t *));                                 \
+    if (m == NULL) {                                                           \
+        nrerror("*** Error: allocation failure in %s\n", __func__);            \
+    }                                                                          \
+    m += NR_END;                                                               \
+    m -= nrl;                                                                  \
+    /* allocate rows and set pointers to them */                               \
+    m[nrl] = malloc((nrow * ncol + NR_END) * sizeof(t));                       \
+    if (m[nrl] == NULL) {                                                      \
+        nrerror("*** Error: allocation failure in %s\n", __func__);            \
+    }                                                                          \
+    m[nrl] += NR_END;                                                          \
+    m[nrl] -= ncl;                                                             \
+    for (int32_t i = nrl + 1; i <= nrh; i++) {                                 \
+        m[i] = m[i - 1] + ncol;                                                \
+    }                                                                          \
+    /* return pointer to array of pointers to rows */                          \
+    return m;                                                                  \
+}
+
+
+type_matrix(int8_t);
+type_matrix(uint8_t);
+type_matrix(int16_t);
+type_matrix(uint16_t);
+type_matrix(int32_t);
+type_matrix(uint32_t);
+type_matrix(int64_t);
+type_matrix(uint64_t);
+type_matrix(float);
+type_matrix(double);
+type_matrix(void_p);
+type_matrix(rgb8);
+type_matrix(rgbx8);
+type_matrix(rgb32);
+type_matrix(rgbx32);
+type_matrix(complex32);
+type_matrix(complex64);
+type_matrix(si16Point);
+type_matrix(ui16Point);
+type_matrix(si32Point);
+type_matrix(ui32Point);
+type_matrix(f32Point);
+type_matrix(si16Triplet);
+type_matrix(ui16Triplet);
+type_matrix(si32Triplet);
+type_matrix(ui32Triplet);
+type_matrix(f32Triplet);
+
+
+
+
+#undef type_matrix0
+#define type_matrix0(t) \
+t ** short_name(t,,matrix0)(int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch) \
+{                                                                               \
+    int32_t nrow = nrh - nrl + 1;                                               \
+    int32_t ncol = nch - ncl + 1;                                               \
+    t ** m;                                                                     \
+    /* allocate pointers to row */                                              \
+    m = malloc((nrow + NR_END) * sizeof(t *));                                  \
+    if (m == NULL) {                                                            \
+        nrerror("*** Error: allocation failure in %s\n", __func__);             \
+    }                                                                           \
+    m += NR_END;                                                                \
+    m -= nrl;                                                                   \
+    /* allocate rows and set pointers to them */                                \
+    m[nrl] = calloc((nrow * ncol + NR_END), sizeof(t));                         \
+    if (m[nrl] == NULL) {                                                       \
+        nrerror("*** Error: allocation failure in %s\n", __func__);             \
+    }                                                                           \
+    m[nrl] += NR_END;                                                           \
+    m[nrl] -= ncl;                                                              \
+    for (int32_t i = nrl + 1; i <= nrh; i++) {                                  \
+        m[i] = m[i - 1] + ncol;                                                 \
+    }                                                                           \
+    /* return pointer to array of pointers to rows */                           \
+    return m;                                                                   \
+}
+
+
+type_matrix0(int8_t);
+type_matrix0(uint8_t);
+type_matrix0(int16_t);
+type_matrix0(uint16_t);
+type_matrix0(int32_t);
+type_matrix0(uint32_t);
+type_matrix0(int64_t);
+type_matrix0(uint64_t);
+type_matrix0(float);
+type_matrix0(double);
+type_matrix0(void_p);
+type_matrix0(rgb8);
+type_matrix0(rgbx8);
+type_matrix0(rgb32);
+type_matrix0(rgbx32);
+type_matrix0(complex32);
+type_matrix0(complex64);
+
+
+#if TARGET_OS == GIETVM
+
+#undef remote_type_matrix
+#define remote_type_matrix(t) \
+t ** short_name(t,remote_,matrix)(int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch) \
+{                                                                              \
+    int32_t nrow = nrh - nrl + 1;                                              \
+    int32_t ncol = nch - ncl + 1;                                              \
+    t ** m;                                                                    \
+    /* allocate pointers to row */                                             \
+    m = malloc((nrow + NR_END) * sizeof(t *));                                 \
+    if (m == NULL) {                                                           \
+        nrerror("*** Error: allocation failure in %s\n", __func__);            \
+    }                                                                          \
+    m += NR_END;                                                               \
+    m -= nrl;                                                                  \
+    /* allocate rows and set pointers to them */                               \
+    m[nrl] = malloc((nrow * ncol + NR_END) * sizeof(t));                       \
+    if (m[nrl] == NULL) {                                                      \
+        nrerror("*** Error: allocation failure in %s\n", __func__);            \
+    }                                                                          \
+    m[nrl] += NR_END;                                                          \
+    m[nrl] -= ncl;                                                             \
+    for (int32_t i = nrl + 1; i <= nrh; i++) {                                 \
+        m[i] = m[i - 1] + ncol;                                                \
+    }                                                                          \
+    /* return pointer to array of pointers to rows */                          \
+    return m;                                                                  \
+}
+
+
+remote_type_matrix(int8_t);
+remote_type_matrix(uint8_t);
+remote_type_matrix(int16_t);
+remote_type_matrix(uint16_t);
+remote_type_matrix(int32_t);
+remote_type_matrix(uint32_t);
+remote_type_matrix(int64_t);
+remote_type_matrix(uint64_t);
+remote_type_matrix(float);
+remote_type_matrix(double);
+remote_type_matrix(void_p);
+remote_type_matrix(rgb8);
+remote_type_matrix(rgbx8);
+remote_type_matrix(rgb32);
+remote_type_matrix(rgbx32);
+remote_type_matrix(complex32);
+remote_type_matrix(complex64);
+
+#endif
+
+
+#undef free_type_matrix
+#define free_type_matrix(t) \
+void short_name(t,free_,matrix)(t ** m, int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch) \
+{ \
+    free((FREE_ARG) (m[nrl] + ncl - NR_END)); \
+    free((FREE_ARG) (m + nrl - NR_END)); \
+}
+
+free_type_matrix(int8_t);
+free_type_matrix(uint8_t);
+free_type_matrix(int16_t);
+free_type_matrix(uint16_t);
+free_type_matrix(int32_t);
+free_type_matrix(uint32_t);
+free_type_matrix(int64_t);
+free_type_matrix(uint64_t);
+free_type_matrix(float);
+free_type_matrix(double);
+free_type_matrix(void_p);
+free_type_matrix(rgb8);
+free_type_matrix(rgbx8);
+free_type_matrix(rgb32);
+free_type_matrix(rgbx32);
+free_type_matrix(complex32);
+free_type_matrix(complex64);
+free_type_matrix(si16Point);
+free_type_matrix(ui16Point);
+free_type_matrix(si32Point);
+free_type_matrix(ui32Point);
+free_type_matrix(f32Point);
+free_type_matrix(si16Triplet);
+free_type_matrix(ui16Triplet);
+free_type_matrix(si32Triplet);
+free_type_matrix(ui32Triplet);
+free_type_matrix(f32Triplet);
+
+
+
+// Local Variables:
+// tab-width: 4
+// c-basic-offset: 4
+// c-file-offsets:((innamespace . 0)(inline-open . 0))
+// indent-tabs-mode: nil
+// End:
+// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4
+
Index: soft/giet_vm/applications/rosenfeld/nrc2/src/nralloc2x.c
===================================================================
--- soft/giet_vm/applications/rosenfeld/nrc2/src/nralloc2x.c	(revision 820)
+++ soft/giet_vm/applications/rosenfeld/nrc2/src/nralloc2x.c	(revision 821)
@@ -17,6 +17,6 @@
 #include <malloc.h>
 #include <math.h> // fabs
-// #include <memory.h> // memcpy
 
+#include "nrc_os_config.h"
 #include "mypredef.h"
 #include "nrtype.h"
@@ -25,516 +25,60 @@
 #include "nrkernel.h"
 
-#include "nralloc1.h"
-#include "nralloc2.h"
 #include "nralloc2x.h"
-//#include "nrarith.h"
 
-/* ----------------------------------------------------------------------- */
-IMAGE_EXPORT(si16Point**) si16Pmatrix(long nrl, long nrh, long ncl, long nch)
-/* ----------------------------------------------------------------------- */
-{
-    long i, nrow=nrh-nrl+1,ncol=nch-ncl+1;
-    si16Point **m;
-    
-    /* allocate pointers to rows */
-    m=(si16Point **) malloc((size_t)((nrow+NR_END)*sizeof(si16Point*)));
-    if (!m) nrerror("allocation failure 1 in si16Pmatrix()");
-    m += NR_END;
-    m -= nrl;
-    
-    /* allocate rows and set pointers to them */
-    m[nrl]=(si16Point *) malloc((size_t)((nrow*ncol+NR_END)*sizeof(si16Point)));
-    if (!m[nrl]) nrerror("allocation failure 2 in si16Pmatrix()");
-    m[nrl] += NR_END;
-    m[nrl] -= ncl;
-    
-    for(i=nrl+1;i<=nrh;i++) m[i]=m[i-1]+ncol;
-    
-    /* return pointer to array of pointers to rows */
-    return m;
-}
-/* ----------------------------------------------------------------------- */
-IMAGE_EXPORT(ui16Point**) ui16Pmatrix(long nrl, long nrh, long ncl, long nch)
-/* ----------------------------------------------------------------------- */
-{
-    long i, nrow=nrh-nrl+1,ncol=nch-ncl+1;
-    ui16Point **m;
-    
-    /* allocate pointers to rows */
-    m=(ui16Point **) malloc((size_t)((nrow+NR_END)*sizeof(ui16Point*)));
-    if (!m) nrerror("allocation failure 1 in ui16Pmatrix()");
-    m += NR_END;
-    m -= nrl;
-    
-    /* allocate rows and set pointers to them */
-    m[nrl]=(ui16Point *) malloc((size_t)((nrow*ncol+NR_END)*sizeof(ui16Point)));
-    if (!m[nrl]) nrerror("allocation failure 2 in ui16Pmatrix()");
-    m[nrl] += NR_END;
-    m[nrl] -= ncl;
-    
-    for(i=nrl+1;i<=nrh;i++) m[i]=m[i-1]+ncol;
-    
-    /* return pointer to array of pointers to rows */
-    return m;
-}
-/* ----------------------------------------------------------------------- */
-IMAGE_EXPORT(si32Point**) si32Pmatrix(long nrl, long nrh, long ncl, long nch)
-/* ----------------------------------------------------------------------- */
-{
-    long i, nrow=nrh-nrl+1,ncol=nch-ncl+1;
-    si32Point **m;
-    
-    /* allocate pointers to rows */
-    m=(si32Point **) malloc((size_t)((nrow+NR_END)*sizeof(si32Point*)));
-    if (!m) nrerror("allocation failure 1 in si32Pmatrix()");
-    m += NR_END;
-    m -= nrl;
-    
-    /* allocate rows and set pointers to them */
-    m[nrl]=(si32Point *) malloc((size_t)((nrow*ncol+NR_END)*sizeof(si32Point)));
-    if (!m[nrl]) nrerror("allocation failure 2 in si32Pmatrix()");
-    m[nrl] += NR_END;
-    m[nrl] -= ncl;
-    
-    for(i=nrl+1;i<=nrh;i++) m[i]=m[i-1]+ncol;
-    
-    /* return pointer to array of pointers to rows */
-    return m;
-}
-/* ----------------------------------------------------------------------- */
-IMAGE_EXPORT(ui32Point**) ui32Pmatrix(long nrl, long nrh, long ncl, long nch)
-/* ----------------------------------------------------------------------- */
-{
-    long i, nrow=nrh-nrl+1,ncol=nch-ncl+1;
-    ui32Point **m;
-    
-    /* allocate pointers to rows */
-    m=(ui32Point **) malloc((size_t)((nrow+NR_END)*sizeof(ui32Point*)));
-    if (!m) nrerror("allocation failure 1 in ui32Pmatrix()");
-    m += NR_END;
-    m -= nrl;
-    
-    /* allocate rows and set pointers to them */
-    m[nrl]=(ui32Point *) malloc((size_t)((nrow*ncol+NR_END)*sizeof(ui32Point)));
-    if (!m[nrl]) nrerror("allocation failure 2 in ui32Pmatrix()");
-    m[nrl] += NR_END;
-    m[nrl] -= ncl;
-    
-    for(i=nrl+1;i<=nrh;i++) m[i]=m[i-1]+ncol;
-    
-    /* return pointer to array of pointers to rows */
-    return m;
-}
-/* ---------------------------------------------------------------------- */
-IMAGE_EXPORT(f32Point**) f32Pmatrix(long nrl, long nrh, long ncl, long nch)
-/* --------------------------------------------------------------------- */
-{
-    long i, nrow=nrh-nrl+1,ncol=nch-ncl+1;
-    f32Point **m;
-    
-    /* allocate pointers to rows */
-    m=(f32Point **) malloc((size_t)((nrow+NR_END)*sizeof(f32Point*)));
-    if (!m) nrerror("allocation failure 1 in f32Pmatrix()");
-    m += NR_END;
-    m -= nrl;
-    
-    /* allocate rows and set pointers to them */
-    m[nrl]=(f32Point *) malloc((size_t)((nrow*ncol+NR_END)*sizeof(f32Point)));
-    if (!m[nrl]) nrerror("allocation failure 2 in f32Pmatrix()");
-    m[nrl] += NR_END;
-    m[nrl] -= ncl;
-    
-    for(i=nrl+1;i<=nrh;i++) m[i]=m[i-1]+ncol;
-    
-    /* return pointer to array of pointers to rows */
-    return m;
-}
-/* ------------------------------------------------------------------------- */
-IMAGE_EXPORT(si16Triplet**) si16Tmatrix(long nrl, long nrh, long ncl, long nch)
-/* ------------------------------------------------------------------------- */
-{
-    long i, nrow=nrh-nrl+1,ncol=nch-ncl+1;
-    si16Triplet **m;
-    
-    /* allocate pointers to rows */
-    m=(si16Triplet **) malloc((size_t)((nrow+NR_END)*sizeof(si16Triplet*)));
-    if (!m) nrerror("allocation failure 1 in si16Tmatrix()");
-    m += NR_END;
-    m -= nrl;
-    
-    /* allocate rows and set pointers to them */
-    m[nrl]=(si16Triplet *) malloc((size_t)((nrow*ncol+NR_END)*sizeof(si16Triplet)));
-    if (!m[nrl]) nrerror("allocation failure 2 in si16Tmatrix()");
-    m[nrl] += NR_END;
-    m[nrl] -= ncl;
-    
-    for(i=nrl+1;i<=nrh;i++) m[i]=m[i-1]+ncol;
-    
-    /* return pointer to array of pointers to rows */
-    return m;
-}
-/* ----------------------------------------------------------------------- */
-IMAGE_EXPORT(ui16Triplet**) ui16Tmatrix(long nrl, long nrh, long ncl, long nch)
-/* ----------------------------------------------------------------------- */
-{
-    long i, nrow=nrh-nrl+1,ncol=nch-ncl+1;
-    ui16Triplet **m;
-    
-    /* allocate pointers to rows */
-    m=(ui16Triplet **) malloc((size_t)((nrow+NR_END)*sizeof(ui16Triplet*)));
-    if (!m) nrerror("allocation failure 1 in ui16Tmatrix()");
-    m += NR_END;
-    m -= nrl;
-    
-    /* allocate rows and set pointers to them */
-    m[nrl]=(ui16Triplet *) malloc((size_t)((nrow*ncol+NR_END)*sizeof(ui16Triplet)));
-    if (!m[nrl]) nrerror("allocation failure 2 in ui16Tmatrix()");
-    m[nrl] += NR_END;
-    m[nrl] -= ncl;
-    
-    for(i=nrl+1;i<=nrh;i++) m[i]=m[i-1]+ncol;
-    
-    /* return pointer to array of pointers to rows */
-    return m;
-}
-/* ----------------------------------------------------------------------- */
-IMAGE_EXPORT(si32Triplet**) si32Tmatrix(long nrl, long nrh, long ncl, long nch)
-/* ----------------------------------------------------------------------- */
-{
-    long i, nrow=nrh-nrl+1,ncol=nch-ncl+1;
-    si32Triplet **m;
-    
-    /* allocate pointers to rows */
-    m=(si32Triplet**) malloc((size_t)((nrow+NR_END)*sizeof(si32Triplet*)));
-    if (!m) nrerror("allocation failure 1 in si32Tmatrix()");
-    m += NR_END;
-    m -= nrl;
-    
-    /* allocate rows and set pointers to them */
-    m[nrl]=(si32Triplet*) malloc((size_t)((nrow*ncol+NR_END)*sizeof(si32Triplet)));
-    if (!m[nrl]) nrerror("allocation failure 2 in si32Tmatrix()");
-    m[nrl] += NR_END;
-    m[nrl] -= ncl;
-    
-    for(i=nrl+1;i<=nrh;i++) m[i]=m[i-1]+ncol;
-    
-    /* return pointer to array of pointers to rows */
-    return m;
-}
-/* ----------------------------------------------------------------------- */
-IMAGE_EXPORT(ui32Triplet**) ui32Tmatrix(long nrl, long nrh, long ncl, long nch)
-/* ----------------------------------------------------------------------- */
-{
-    long i, nrow=nrh-nrl+1,ncol=nch-ncl+1;
-    ui32Triplet **m;
-    
-    /* allocate pointers to rows */
-    m=(ui32Triplet **) malloc((size_t)((nrow+NR_END)*sizeof(ui32Triplet*)));
-    if (!m) nrerror("allocation failure 1 in ui32Tmatrix()");
-    m += NR_END;
-    m -= nrl;
-    
-    /* allocate rows and set pointers to them */
-    m[nrl]=(ui32Triplet *) malloc((size_t)((nrow*ncol+NR_END)*sizeof(ui32Triplet)));
-    if (!m[nrl]) nrerror("allocation failure 2 in ui32Tmatrix()");
-    m[nrl] += NR_END;
-    m[nrl] -= ncl;
-    
-    for(i=nrl+1;i<=nrh;i++) m[i]=m[i-1]+ncol;
-    
-    /* return pointer to array of pointers to rows */
-    return m;
-}
-/* ---------------------------------------------------------------------- */
-IMAGE_EXPORT(f32Triplet**) f32Tmatrix(long nrl, long nrh, long ncl, long nch)
-/* --------------------------------------------------------------------- */
-{
-    long i, nrow=nrh-nrl+1,ncol=nch-ncl+1;
-    f32Triplet **m;
-    
-    /* allocate pointers to rows */
-    m=(f32Triplet **) malloc((size_t)((nrow+NR_END)*sizeof(f32Triplet*)));
-    if (!m) nrerror("allocation failure 1 in f32Tmatrix()");
-    m += NR_END;
-    m -= nrl;
-    
-    /* allocate rows and set pointers to them */
-    m[nrl]=(f32Triplet *) malloc((size_t)((nrow*ncol+NR_END)*sizeof(f32Triplet)));
-    if (!m[nrl]) nrerror("allocation failure 2 in f32Tmatrix()");
-    m[nrl] += NR_END;
-    m[nrl] -= ncl;
-    
-    for(i=nrl+1;i<=nrh;i++) m[i]=m[i-1]+ncol;
-    
-    /* return pointer to array of pointers to rows */
-    return m;
-}
-/* ---------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) free_si16Pmatrix(si16Point **m, long nrl, long nrh, long ncl, long nch)
-/* ---------------------------------------------------------------------------------- */
-/* free an si16Point matrix allocated by si16Pmatrix() */
-{
-    free((FREE_ARG) (m[nrl]+ncl-NR_END));
-    free((FREE_ARG) (m+nrl-NR_END));
-}
-/* ---------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) free_ui16Pmatrix(ui16Point **m, long nrl, long nrh, long ncl, long nch)
-/* ---------------------------------------------------------------------------------- */
-/* free an ui16Point matrix allocated by ui16Pmatrix() */
-{
-    free((FREE_ARG) (m[nrl]+ncl-NR_END));
-    free((FREE_ARG) (m+nrl-NR_END));
-}
-/* ------------------------------------------------------------------------------------ */
-IMAGE_EXPORT(void) free_si32Pmatrix(si32Point **m, long nrl, long nrh, long ncl, long nch)
-/* ------------------------------------------------------------------------------------ */
-{
-    free((FREE_ARG) (m[nrl]+ncl-NR_END));
-    free((FREE_ARG) (m+nrl-NR_END));
-}
-/* ------------------------------------------------------------------------------------ */
-IMAGE_EXPORT(void) free_ui32Pmatrix(ui32Point **m, long nrl, long nrh, long ncl, long nch)
-/* ------------------------------------------------------------------------------------ */
-{
-    free((FREE_ARG) (m[nrl]+ncl-NR_END));
-    free((FREE_ARG) (m+nrl-NR_END));
-}
-/* ---------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) free_f32Pmatrix(f32Point **m, long nrl, long nrh, long ncl, long nch)
-/* ---------------------------------------------------------------------------------- */
-/* free an f32Point matrix allocated by f32Pmatrix() */
-{
-    free((FREE_ARG) (m[nrl]+ncl-NR_END));
-    free((FREE_ARG) (m+nrl-NR_END));
-}
-/* -------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) free_si16Tmatrix(si16Triplet **m, long nrl, long nrh, long ncl, long nch)
-/* -------------------------------------------------------------------------------------- */
-/* free an si16Point matrix allocated by si16Pmatrix() */
-{
-    free((FREE_ARG) (m[nrl]+ncl-NR_END));
-    free((FREE_ARG) (m+nrl-NR_END));
-}
-/* ---------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) free_ui16Tmatrix(ui16Triplet **m, long nrl, long nrh, long ncl, long nch)
-/* ---------------------------------------------------------------------------------- */
-/* free an ui16Point matrix allocated by ui16Pmatrix() */
-{
-    free((FREE_ARG) (m[nrl]+ncl-NR_END));
-    free((FREE_ARG) (m+nrl-NR_END));
-}
-/* ------------------------------------------------------------------------------------ */
-IMAGE_EXPORT(void) free_si32Tmatrix(si32Triplet **m, long nrl, long nrh, long ncl, long nch)
-/* ------------------------------------------------------------------------------------ */
-{
-    free((FREE_ARG) (m[nrl]+ncl-NR_END));
-    free((FREE_ARG) (m+nrl-NR_END));
-}
-/* -------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) free_ui32Tmatrix(ui32Triplet **m, long nrl, long nrh, long ncl, long nch)
-/* -------------------------------------------------------------------------------------- */
-{
-    free((FREE_ARG) (m[nrl]+ncl-NR_END));
-    free((FREE_ARG) (m+nrl-NR_END));
-}
-/* ------------------------------------------------------------------------------------ */
-IMAGE_EXPORT(void) free_f32Tmatrix(f32Triplet **m, long nrl, long nrh, long ncl, long nch)
-/* ------------------------------------------------------------------------------------ */
-/* free an f32Point matrix allocated by f32Pmatrix() */
-{
-    free((FREE_ARG) (m[nrl]+ncl-NR_END));
-    free((FREE_ARG) (m+nrl-NR_END));
-}
 
 /* ----------------- */
 /* --- trimatrix --- */
 /* ----------------- */
-/* ---------------------------------------------------------------------------- */
-IMAGE_EXPORT(byte**) btrimatrix(long nrl, long nrh, long ncl, long nch, long step)
-/* ---------------------------------------------------------------------------- */
-/* allocate an byte triangle-matrix with subscript range m[nrl..nrh][ncl..nch] */
-{
-    long i, nrow=nrh-nrl+1,ncol=nch-ncl+1, n = nrow * ncol + (nrow * (nrow-1) * step) / 2;
-    // Attention, factorisation of n IS NOT PERMITTED : (nrow-1)step/2 is not even!!!
-    byte **m;
-    
-    /* allocate pointers to rows */
-    m=(byte **) malloc((size_t)((nrow+NR_END)*sizeof(byte*)));
-    if (!m) nrerror("allocation failure 1 in btrimatrix()");
-    m += NR_END;
-    m -= nrl;
-    
-    
-    /* allocate rows and set pointers to them */
-    m[nrl]=(byte *) malloc((size_t)((n+NR_END)*sizeof(byte)));
-    if (!m[nrl]) nrerror("allocation failure 2 in btrimatrix()");
-    m[nrl] += NR_END;
-    m[nrl] -= ncl;
-    
-    for(i=nrl+1;i<=nrh;i++) { m[i]=m[i-1]+ncol; ncol += step; }
-    
-    /* return pointer to array of pointers to rows */
-    return m;
+
+
+#undef type_trimatrix
+#define type_trimatrix(t) \
+t ** short_name(t,,trimatrix)(int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch, int32_t step) \
+/* allocate an byte triangle-matrix with subscript range m[nrl..nrh][ncl..nch] */               \
+{                                                                                               \
+    int32_t nrow = nrh - nrl + 1;                                                               \
+    int32_t ncol = nch - ncl + 1;                                                               \
+    int n = nrow * ncol + (nrow * (nrow - 1) * step) / 2;                                       \
+    /* Attention, factorisation of n IS NOT PERMITTED : (nrow - 1) step / 2 is not even!!! */   \
+    t ** m;                                                                                     \
+    /* allocate pointers to rows */                                                             \
+    m = malloc((nrow + NR_END) * sizeof(t *));                                                  \
+    if (m == NULL) {                                                                            \
+        nrerror("*** Error: allocation failure in %s\n", __func__);                             \
+    }                                                                                           \
+    m += NR_END;                                                                                \
+    m -= nrl;                                                                                   \
+    /* allocate rows and set pointers to them */                                                \
+    m[nrl] = malloc(((n + NR_END) * sizeof(t)));                                                \
+    if (m[nrl] == NULL) {                                                                       \
+        nrerror("*** Error: allocation failure in %s\n", __func__);                             \
+    }                                                                                           \
+    m[nrl] += NR_END;                                                                           \
+    m[nrl] -= ncl;                                                                              \
+    for (int32_t i = nrl + 1; i <= nrh;i++) {                                                   \
+        m[i] = m[i - 1] + ncol;                                                                 \
+        ncol += step;                                                                           \
+    }                                                                                           \
+    /* return pointer to array of pointers to rows */                                           \
+    return m;                                                                                   \
 }
-/* --------------------------------------------------------------------------------- */
-IMAGE_EXPORT(sint16**) si16trimatrix(long nrl, long nrh, long ncl, long nch, long step)
-/* --------------------------------------------------------------------------------- */
-/* allocate an i16 triangle-matrix with subscript range m[nrl..nrh][ncl..nch] */
-{
-    long i, nrow=nrh-nrl+1,ncol=nch-ncl+1, n = nrow * ncol + (nrow * (nrow-1) * step) / 2;
-    // Attention, factorisation of n IS NOT PERMITTED : (nrow-1)step/2 is not even!!!
-    sint16 **m;
-    
-    /* allocate pointers to rows */
-    m=(sint16 **) malloc((size_t)((nrow+NR_END)*sizeof(sint16*)));
-    if (!m) nrerror("allocation failure 1 in i16trimatrix()");
-    m += NR_END;
-    m -= nrl;
-    
-    
-    /* allocate rows and set pointers to them */
-    m[nrl]=(int16*) malloc((size_t)((n+NR_END)*sizeof(int16)));
-    if (!m[nrl]) nrerror("allocation failure 2 in i16trimatrix()");
-    m[nrl] += NR_END;
-    m[nrl] -= ncl;
-    
-    for(i=nrl+1;i<=nrh;i++) { m[i]=m[i-1]+ncol; ncol += step; }
-    
-    /* return pointer to array of pointers to rows */
-    return m;
-}
-/* --------------------------------------------------------------------------------- */
-IMAGE_EXPORT(uint16**) ui16trimatrix(long nrl, long nrh, long ncl, long nch, long step)
-/* --------------------------------------------------------------------------------- */
-/* allocate an i16 triangle-matrix with subscript range m[nrl..nrh][ncl..nch] */
-{
-    long i, nrow=nrh-nrl+1,ncol=nch-ncl+1, n = nrow * ncol + (nrow * (nrow-1) * step) / 2;
-    // Attention, factorisation of n IS NOT PERMITTED : (nrow-1)step/2 is not even!!!
-    uint16 **m;
-    
-    /* allocate pointers to rows */
-    m=(uint16 **) malloc((size_t)((nrow+NR_END)*sizeof(uint16*)));
-    if (!m) nrerror("allocation failure 1 in ui16trimatrix()");
-    m += NR_END;
-    m -= nrl;
-    
-    
-    /* allocate rows and set pointers to them */
-    m[nrl]=(uint16*) malloc((size_t)((n+NR_END)*sizeof(uint16)));
-    if (!m[nrl]) nrerror("allocation failure 2 in i16trimatrix()");
-    m[nrl] += NR_END;
-    m[nrl] -= ncl;
-    
-    for(i=nrl+1;i<=nrh;i++) { m[i]=m[i-1]+ncol; ncol += step; }
-    
-    /* return pointer to array of pointers to rows */
-    return m;
-}
-/* --------------------------------------------------------------------------------- */
-IMAGE_EXPORT(sint32**) si32trimatrix(long nrl, long nrh, long ncl, long nch, long step)
-/* --------------------------------------------------------------------------------- */
-/* allocate an i32 triangle-matrix with subscript range m[nrl..nrh][ncl..nch] */
-{
-    long i, nrow=nrh-nrl+1,ncol=nch-ncl+1, n = nrow * ncol + (nrow * (nrow-1) * step) / 2;
-    // Attention, factorisation of n IS NOT PERMITTED : (nrow-1)step/2 is not even!!!
-    sint32 **m;
-    
-    /* allocate pointers to rows */
-    m=(sint32 **) malloc((size_t)((nrow+NR_END)*sizeof(sint32*)));
-    if (!m) nrerror("allocation failure 1 in si32trimatrix()");
-    m += NR_END;
-    m -= nrl;
-    
-    
-    /* allocate rows and set pointers to them */
-    m[nrl]=(sint32*) malloc((size_t)((n+NR_END)*sizeof(sint32)));
-    if (!m[nrl]) nrerror("allocation failure 2 in si32trimatrix()");
-    m[nrl] += NR_END;
-    m[nrl] -= ncl;
-    
-    for(i=nrl+1;i<=nrh;i++) { m[i]=m[i-1]+ncol; ncol += step; }
-    
-    /* return pointer to array of pointers to rows */
-    return m;
-}
-/* -------------------------------------------------------------------------------- */
-IMAGE_EXPORT(uint32**) i32trimatrix(long nrl, long nrh, long ncl, long nch, long step)
-/* -------------------------------------------------------------------------------- */
-/* allocate an i32 triangle-matrix with subscript range m[nrl..nrh][ncl..nch] */
-{
-    long i, nrow=nrh-nrl+1,ncol=nch-ncl+1, n = nrow * ncol + (nrow * (nrow-1) * step) / 2;
-    // Attention, factorisation of n IS NOT PERMITTED : (nrow-1)step/2 is not even!!!
-    uint32 **m;
-    
-    /* allocate pointers to rows */
-    m=(uint32 **) malloc((size_t)((nrow+NR_END)*sizeof(uint32*)));
-    if (!m) nrerror("allocation failure 1 in ui32trimatrix()");
-    m += NR_END;
-    m -= nrl;
-    
-    
-    /* allocate rows and set pointers to them */
-    m[nrl]=(uint32*) malloc((size_t)((n+NR_END)*sizeof(uint32)));
-    if (!m[nrl]) nrerror("allocation failure 2 in i32trimatrix()");
-    m[nrl] += NR_END;
-    m[nrl] -= ncl;
-    
-    for(i=nrl+1;i<=nrh;i++) { m[i]=m[i-1]+ncol; ncol += step; }
-    
-    /* return pointer to array of pointers to rows */
-    return m;
-}
-/* --------------------------------------------------------------------------------- */
-IMAGE_EXPORT(float32**) f32trimatrix(long nrl, long nrh, long ncl, long nch, long step)
-/* --------------------------------------------------------------------------------- */
-/* allocate an f32 triangle-matrix with subscript range m[nrl..nrh][ncl..nch] */
-{
-    long i, nrow=nrh-nrl+1,ncol=nch-ncl+1, n = nrow * ncol + (nrow * (nrow-1) * step) / 2;
-    // Attention, factorisation of n IS NOT PERMITTED : (nrow-1)step/2 is not even!!!
-    float32 **m;
-    
-    /* allocate pointers to rows */
-    m=(float32 **) malloc((size_t)((nrow+NR_END)*sizeof(float32*)));
-    if (!m) nrerror("allocation failure 1 in f32trimatrix()");
-    m += NR_END;
-    m -= nrl;
-    
-    
-    /* allocate rows and set pointers to them */
-    m[nrl]=(float32*) malloc((size_t)((n+NR_END)*sizeof(float32)));
-    if (!m[nrl]) nrerror("allocation failure 2 in f32trimatrix()");
-    m[nrl] += NR_END;
-    m[nrl] -= ncl;
-    
-    for(i=nrl+1;i<=nrh;i++) { m[i]=m[i-1]+ncol; ncol += step; }
-    
-    /* return pointer to array of pointers to rows */
-    return m;
-}
-/* --------------------------------------------------------------------------------- */
-IMAGE_EXPORT(float64**) f64trimatrix(long nrl, long nrh, long ncl, long nch, long step)
-/* --------------------------------------------------------------------------------- */
-/* allocate an f64 triangle-matrix with subscript range m[nrl..nrh][ncl..nch] */
-{
-    long i, nrow=nrh-nrl+1,ncol=nch-ncl+1, n = nrow * ncol + (nrow * (nrow-1) * step) / 2;
-    // Attention, factorisation of n IS NOT PERMITTED : (nrow-1)step/2 is not even!!!
-    float64 **m;
-    
-    /* allocate pointers to rows */
-    m=(float64 **) malloc((size_t)((nrow+NR_END)*sizeof(float64*)));
-    if (!m) nrerror("allocation failure 1 in f64trimatrix()");
-    m += NR_END;
-    m -= nrl;
-    
-    
-    /* allocate rows and set pointers to them */
-    m[nrl]=(float64*) malloc((size_t)((n+NR_END)*sizeof(float64)));
-    if (!m[nrl]) nrerror("allocation failure 2 in f64trimatrix()");
-    m[nrl] += NR_END;
-    m[nrl] -= ncl;
-    
-    for(i=nrl+1;i<=nrh;i++) { m[i]=m[i-1]+ncol; ncol += step; }
-    
-    /* return pointer to array of pointers to rows */
-    return m;
-}
+
+
+type_trimatrix(int8_t);
+type_trimatrix(uint8_t);
+type_trimatrix(int16_t);
+type_trimatrix(uint16_t);
+type_trimatrix(int32_t);
+type_trimatrix(uint32_t);
+type_trimatrix(float);
+type_trimatrix(double);
+
+// Local Variables:
+// tab-width: 4
+// c-basic-offset: 4
+// c-file-offsets:((innamespace . 0)(inline-open . 0))
+// indent-tabs-mode: nil
+// End:
+// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4
+
Index: soft/giet_vm/applications/rosenfeld/nrc2/src/nralloc3.c
===================================================================
--- soft/giet_vm/applications/rosenfeld/nrc2/src/nralloc3.c	(revision 820)
+++ soft/giet_vm/applications/rosenfeld/nrc2/src/nralloc3.c	(revision 821)
@@ -31,6 +31,7 @@
 #include <string.h> // memcpy
 #include <math.h> // fabs
-// #include <memory.h> // memcpy
 
+
+#include "nrc_os_config.h"
 #include "mypredef.h"
 #include "nrtype.h"
@@ -39,7 +40,89 @@
 #include "nrkernel.h"
 
-#include "nralloc1.h"
 #include "nralloc3.h"
 
+
+#undef type_cube
+#define type_cube(t) \
+t *** short_name(t,,cube)(int32_t ndl, int32_t ndh, int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch) \
+{                                                                                                       \
+    int32_t ndep = ndh - ndl + 1;                                                                       \
+    int32_t nrow = nrh - nrl + 1;                                                                       \
+    int32_t nrol = nch - ncl + 1;                                                                       \
+    t *** c;                                                                                            \
+    /* allocate pointers to pointers to rows */                                                         \
+    c = malloc((ndep + NR_END) * sizeof(t **));                                                         \
+    if (c == NULL) {                                                                                    \
+        nrerror("*** Error: allocation failure in %s\n", __func__);                                     \
+    }                                                                                                   \
+    c += NR_END;                                                                                        \
+    c -= ndl;                                                                                           \
+    /* allocate pointers to rows anc set pointers to them */                                            \
+    c[ndl] = malloc((ndep * nrow + NR_END) * sizeof(t *));                                              \
+    if (c[ndl] == NULL) {                                                                               \
+        nrerror("*** Error: allocation failure in %s\n", __func__);                                     \
+    }                                                                                                   \
+    c[ndl] += NR_END;                                                                                   \
+    c[ndl] -= nrl;                                                                                      \
+    /* allocate rows anc set pointers to them */                                                        \
+    c[ndl][nrl] = malloc((ndep * nrow * nrol + NR_END) * sizeof(t));                                    \
+    if (c[ndl][nrl]) {                                                                                  \
+        nrerror("*** Error: allocation failure in %s\n", __func__);                                     \
+    }                                                                                                   \
+    c[ndl][nrl] += NR_END;                                                                              \
+    c[ndl][nrl] -= ncl;                                                                                 \
+                                                                                                        \
+    for(int32_t j = nrl + 1; j <= nrh; j++) {                                                           \
+        c[ndl][j] = c[ndl][j - 1] + nrol;                                                               \
+    }                                                                                                   \
+    for(int32_t i = ndl + 1; i <= ndh; i++) {                                                           \
+        c[i] = c[i - 1] + nrow;                                                                         \
+        c[i][nrl] = c[i - 1][nrl] + nrow * nrol;                                                        \
+        for (int32_t j = nrl + 1; j <= nrh; j++) {                                                      \
+            c[i][j] = c[i][j - 1] + nrol;                                                               \
+        }                                                                                               \
+    }                                                                                                   \
+    /* return pointer to array of pointers to rows */                                                   \
+    return t;                                                                                           \
+}
+
+
+type_cube(int8_t);
+type_cube(uint8_t);
+type_cube(int16_t);
+type_cube(uint16_t);
+type_cube(int32_t);
+type_cube(uint32_t);
+type_cube(int64_t);
+type_cube(uint64_t);
+type_cube(float);
+type_cube(double);
+type_cube(rgb8);
+type_cube(rgbx8);
+
+#undef free_type_cube
+#define free_type_cube(t) \
+void short_name(t,free_,cube)(t *** c, int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch, int32_t ndl, int32_t ndh) \
+{                                                                                                        \
+    free((FREE_ARG) (c[nrl][ncl] + ndl - NR_END));                                                       \
+    free((FREE_ARG) (c[nrl] + ncl - NR_END));                                                            \
+    free((FREE_ARG) (c + nrl - NR_END));                                                                 \
+}
+
+free_type_cube(int8_t);
+free_type_cube(uint8_t);
+free_type_cube(int16_t);
+free_type_cube(uint16_t);
+free_type_cube(int32_t);
+free_type_cube(uint32_t);
+free_type_cube(int64_t);
+free_type_cube(uint64_t);
+free_type_cube(float);
+free_type_cube(double);
+free_type_cube(rgb8);
+free_type_cube(rgbx8);
+
+
+#if 0
 /* ----------------------------------------------------------------------- */
 double*** d3tensor(long nrl, long nrh, long ncl, long nch, long ndl, long ndh)
@@ -78,4 +161,6 @@
     return t;
 }
+
+
 /* ------------------------------------------------------------------------------ */
 void free_d3tensor(double ***t,long nrl,long nrh,long ncl,long nch,long ndl,long ndh)
@@ -87,425 +172,13 @@
     free((FREE_ARG) (t+nrl-NR_END));
 }
+#endif
 
-/* ------------------------------------------------------------------------------------ */
-IMAGE_EXPORT(sint8***) si8cube(long ndl, long ndh, long nrl, long nrh, long ncl, long nch)
-/* ------------------------------------------------------------------------------------ */
-{
-    long i,j,ndep=ndh-ndl+1,nrow=nrh-nrl+1,nrol=nch-ncl+1;
-    sint8 ***t;
-    
-    /* allocate pointers to pointers to rows */
-    t=(sint8***) malloc((size_t)((ndep+NR_END)*sizeof(sint8**)));
-    if (!t) nrerror("allocation failure 1 in si8cube()");
-    t += NR_END;
-    t -= ndl;
-    
-    /* allocate pointers to rows anc set pointers to them */
-    t[ndl]=(sint8**) malloc((size_t)((ndep*nrow+NR_END)*sizeof(sint8*)));
-    if (!t[ndl]) nrerror("allocation failure 2 in si8cube()");
-    t[ndl] += NR_END;
-    t[ndl] -= nrl;
-    
-    /* allocate rows anc set pointers to them */
-    t[ndl][nrl]=(sint8*) malloc((size_t)((ndep*nrow*nrol+NR_END)*sizeof(sint8)));
-    if (!t[ndl][nrl]) nrerror("allocation failure 3 in si8cube()");
-    t[ndl][nrl] += NR_END;
-    t[ndl][nrl] -= ncl;
-    
-    for(j=nrl+1;j<=nrh;j++) t[ndl][j]=t[ndl][j-1]+nrol;
-    for(i=ndl+1;i<=ndh;i++) {
-        t[i]=t[i-1]+nrow;
-        t[i][nrl]=t[i-1][nrl]+nrow*nrol;
-        for(j=nrl+1;j<=nrh;j++) t[i][j]=t[i][j-1]+nrol;
-    }
-    /* return pointer to array of pointers to rows */
-    return t;
-}
-/* ------------------------------------------------------------------------------------ */
-IMAGE_EXPORT(uint8***) ui8cube(long ndl, long ndh, long nrl, long nrh, long ncl, long nch)
-/* ------------------------------------------------------------------------------------ */
-{
-    long i,j,ndep=ndh-ndl+1,nrow=nrh-nrl+1,nrol=nch-ncl+1;
-    uint8 ***t;
-    
-    /* allocate pointers to pointers to rows */
-    t=(uint8***) malloc((size_t)((ndep+NR_END)*sizeof(uint8**)));
-    if (!t) nrerror("allocation failure 1 in ui8cube()");
-    t += NR_END;
-    t -= ndl;
-    
-    /* allocate pointers to rows anc set pointers to them */
-    t[ndl]=(uint8**) malloc((size_t)((ndep*nrow+NR_END)*sizeof(uint8*)));
-    if (!t[ndl]) nrerror("allocation failure 2 in ui8cube()");
-    t[ndl] += NR_END;
-    t[ndl] -= nrl;
-    
-    /* allocate rows anc set pointers to them */
-    t[ndl][nrl]=(uint8*) malloc((size_t)((ndep*nrow*nrol+NR_END)*sizeof(uint8)));
-    if (!t[ndl][nrl]) nrerror("allocation failure 3 in ui8cube()");
-    t[ndl][nrl] += NR_END;
-    t[ndl][nrl] -= ncl;
-    
-    for(j=nrl+1;j<=nrh;j++) t[ndl][j]=t[ndl][j-1]+nrol;
-    for(i=ndl+1;i<=ndh;i++) {
-        t[i]=t[i-1]+nrow;
-        t[i][nrl]=t[i-1][nrl]+nrow*nrol;
-        for(j=nrl+1;j<=nrh;j++) t[i][j]=t[i][j-1]+nrol;
-    }
-    /* return pointer to array of pointers to rows */
-    return t;
-}
-/* -------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(sint16***) si16cube(long ndl, long ndh, long nrl, long nrh, long ncl, long nch)
-/* -------------------------------------------------------------------------------------- */
-{
-    long i,j,ndep=ndh-ndl+1,nrow=nrh-nrl+1,nrol=nch-ncl+1;
-    sint16 ***t;
-    
-    /* allocate pointers to pointers to rows */
-    t=(sint16 ***) malloc((size_t)((ndep+NR_END)*sizeof(sint16**)));
-    if (!t) nrerror("allocation failure 1 in si16cube()");
-    t += NR_END;
-    t -= ndl;
-    
-    /* allocate pointers to rows anc set pointers to them */
-    t[ndl]=(sint16 **) malloc((size_t)((ndep*nrow+NR_END)*sizeof(sint16*)));
-    if (!t[ndl]) nrerror("allocation failure 2 in si16cube()");
-    t[ndl] += NR_END;
-    t[ndl] -= nrl;
-    
-    /* allocate rows anc set pointers to them */
-    t[ndl][nrl]=(sint16 *) malloc((size_t)((ndep*nrow*nrol+NR_END)*sizeof(sint16)));
-    if (!t[ndl][nrl]) nrerror("allocation failure 3 in si16cube()");
-    t[ndl][nrl] += NR_END;
-    t[ndl][nrl] -= ncl;
-    
-    for(j=nrl+1;j<=nrh;j++) t[ndl][j]=t[ndl][j-1]+nrol;
-    for(i=ndl+1;i<=ndh;i++) {
-        t[i]=t[i-1]+nrow;
-        t[i][nrl]=t[i-1][nrl]+nrow*nrol;
-        for(j=nrl+1;j<=nrh;j++) t[i][j]=t[i][j-1]+nrol;
-    }
-    /* return pointer to array of pointers to rows */
-    return t;
-}
-/* -------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(uint16***) ui16cube(long ndl, long ndh, long nrl, long nrh, long ncl, long nch)
-/* -------------------------------------------------------------------------------------- */
-{
-    long i,j,ndep=ndh-ndl+1,nrow=nrh-nrl+1,nrol=nch-ncl+1;
-    uint16 ***t;
-    
-    /* allocate pointers to pointers to rows */
-    t=(uint16***) malloc((size_t)((ndep+NR_END)*sizeof(uint16**)));
-    if (!t) nrerror("allocation failure 1 in ui16cube()");
-    t += NR_END;
-    t -= ndl;
-    
-    /* allocate pointers to rows anc set pointers to them */
-    t[ndl]=(uint16**) malloc((size_t)((ndep*nrow+NR_END)*sizeof(uint16*)));
-    if (!t[ndl]) nrerror("allocation failure 2 in ui16cube()");
-    t[ndl] += NR_END;
-    t[ndl] -= nrl;
-    
-    /* allocate rows anc set pointers to them */
-    t[ndl][nrl]=(uint16*) malloc((size_t)((ndep*nrow*nrol+NR_END)*sizeof(uint16)));
-    if (!t[ndl][nrl]) nrerror("allocation failure 3 in ui16cube()");
-    t[ndl][nrl] += NR_END;
-    t[ndl][nrl] -= ncl;
-    
-    for(j=nrl+1;j<=nrh;j++) t[ndl][j]=t[ndl][j-1]+nrol;
-    for(i=ndl+1;i<=ndh;i++) {
-        t[i]=t[i-1]+nrow;
-        t[i][nrl]=t[i-1][nrl]+nrow*nrol;
-        for(j=nrl+1;j<=nrh;j++) t[i][j]=t[i][j-1]+nrol;
-    }
-    /* return pointer to array of pointers to rows */
-    return t;
-}
-/* ------------------------------------------------------------------------------------ */
-IMAGE_EXPORT(sint32***) si32cube(long ndl, long ndh, long nrl, long nrh, long ncl, long nch)
-/* ------------------------------------------------------------------------------------ */
-{
-    long i,j,ndep=ndh-ndl+1,nrow=nrh-nrl+1,nrol=nch-ncl+1;
-    sint32 ***t;
-    
-    /* allocate pointers to pointers to rows */
-    t=(sint32***) malloc((size_t)((ndep+NR_END)*sizeof(sint32**)));
-    if (!t) nrerror("allocation failure 1 in si32cube()");
-    t += NR_END;
-    t -= ndl;
-    
-    /* allocate pointers to rows anc set pointers to them */
-    t[ndl]=(sint32**) malloc((size_t)((ndep*nrow+NR_END)*sizeof(sint32*)));
-    if (!t[ndl]) nrerror("allocation failure 2 in si32cube()");
-    t[ndl] += NR_END;
-    t[ndl] -= nrl;
-    
-    /* allocate rows anc set pointers to them */
-    t[ndl][nrl]=(sint32*) malloc((size_t)((ndep*nrow*nrol+NR_END)*sizeof(sint32)));
-    if (!t[ndl][nrl]) nrerror("allocation failure 3 in si32cube()");
-    t[ndl][nrl] += NR_END;
-    t[ndl][nrl] -= ncl;
-    
-    for(j=nrl+1;j<=nrh;j++) t[ndl][j]=t[ndl][j-1]+nrol;
-    for(i=ndl+1;i<=ndh;i++) {
-        t[i]=t[i-1]+nrow;
-        t[i][nrl]=t[i-1][nrl]+nrow*nrol;
-        for(j=nrl+1;j<=nrh;j++) t[i][j]=t[i][j-1]+nrol;
-    }
-    /* return pointer to array of pointers to rows */
-    return t;
-}
-/* -------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(uint32***) ui32cube(long ndl, long ndh, long nrl, long nrh, long ncl, long nch)
-/* -------------------------------------------------------------------------------------- */
-{
-    long i,j,ndep=ndh-ndl+1,nrow=nrh-nrl+1,nrol=nch-ncl+1;
-    uint32 ***t;
-    
-    /* allocate pointers to pointers to rows */
-    t=(uint32***) malloc((size_t)((ndep+NR_END)*sizeof(uint32**)));
-    if (!t) nrerror("allocation failure 1 in ui32cube()");
-    t += NR_END;
-    t -= ndl;
-    
-    /* allocate pointers to rows anc set pointers to them */
-    t[ndl]=(uint32**) malloc((size_t)((ndep*nrow+NR_END)*sizeof(uint32*)));
-    if (!t[ndl]) nrerror("allocation failure 2 in ui32cube()");
-    t[ndl] += NR_END;
-    t[ndl] -= nrl;
-    
-    /* allocate rows anc set pointers to them */
-    t[ndl][nrl]=(uint32*) malloc((size_t)((ndep*nrow*nrol+NR_END)*sizeof(uint32)));
-    if (!t[ndl][nrl]) nrerror("allocation failure 3 in ui32cube()");
-    t[ndl][nrl] += NR_END;
-    t[ndl][nrl] -= ncl;
-    
-    for(j=nrl+1;j<=nrh;j++) t[ndl][j]=t[ndl][j-1]+nrol;
-    for(i=ndl+1;i<=ndh;i++) {
-        t[i]=t[i-1]+nrow;
-        t[i][nrl]=t[i-1][nrl]+nrow*nrol;
-        for(j=nrl+1;j<=nrh;j++) t[i][j]=t[i][j-1]+nrol;
-    }
-    /* return pointer to array of pointers to rows */
-    return t;
-}
-/* -------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(float32***) f32cube(long ndl, long ndh, long nrl, long nrh, long ncl, long nch)
-/* -------------------------------------------------------------------------------------- */
-{
-    long i,j,ndep=ndh-ndl+1,nrow=nrh-nrl+1,nrol=nch-ncl+1;
-    float32 ***t;
-    
-    /* allocate pointers to pointers to rows */
-    t=(float32***) malloc((size_t)((ndep+NR_END)*sizeof(float32**)));
-    if (!t) nrerror("allocation failure 1 in f32cube()");
-    t += NR_END;
-    t -= ndl;
-    
-    /* allocate pointers to rows anc set pointers to them */
-    t[ndl]=(float32**) malloc((size_t)((ndep*nrow+NR_END)*sizeof(float32*)));
-    if (!t[ndl]) nrerror("allocation failure 2 in f32cube()");
-    t[ndl] += NR_END;
-    t[ndl] -= nrl;
-    
-    /* allocate rows anc set pointers to them */
-    t[ndl][nrl]=(float32*) malloc((size_t)((ndep*nrow*nrol+NR_END)*sizeof(float32)));
-    if (!t[ndl][nrl]) nrerror("allocation failure 3 in f32cube()");
-    t[ndl][nrl] += NR_END;
-    t[ndl][nrl] -= ncl;
-    
-    for(j=nrl+1;j<=nrh;j++) t[ndl][j]=t[ndl][j-1]+nrol;
-    for(i=ndl+1;i<=ndh;i++) {
-        t[i]=t[i-1]+nrow;
-        t[i][nrl]=t[i-1][nrl]+nrow*nrol;
-        for(j=nrl+1;j<=nrh;j++) t[i][j]=t[i][j-1]+nrol;
-    }
-    /* return pointer to array of pointers to rows */
-    return t;
-}
-/* -------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(float64***) f64cube(long ndl, long ndh, long nrl, long nrh, long ncl, long nch)
-/* -------------------------------------------------------------------------------------- */
-{
-    long i,j,ndep=ndh-ndl+1,nrow=nrh-nrl+1,nrol=nch-ncl+1;
-    float64 ***t;
-    
-    /* allocate pointers to pointers to rows */
-    t=(float64***) malloc((size_t)((ndep+NR_END)*sizeof(float64**)));
-    if (!t) nrerror("allocation failure 1 in f32cube()");
-    t += NR_END;
-    t -= ndl;
-    
-    /* allocate pointers to rows anc set pointers to them */
-    t[ndl]=(float64**) malloc((size_t)((ndep*nrow+NR_END)*sizeof(float64*)));
-    if (!t[ndl]) nrerror("allocation failure 2 in f64cube()");
-    t[ndl] += NR_END;
-    t[ndl] -= nrl;
-    
-    /* allocate rows anc set pointers to them */
-    t[ndl][nrl]=(float64*) malloc((size_t)((ndep*nrow*nrol+NR_END)*sizeof(float64)));
-    if (!t[ndl][nrl]) nrerror("allocation failure 3 in f64cube()");
-    t[ndl][nrl] += NR_END;
-    t[ndl][nrl] -= ncl;
-    
-    for(j=nrl+1;j<=nrh;j++) t[ndl][j]=t[ndl][j-1]+nrol;
-    for(i=ndl+1;i<=ndh;i++) {
-        t[i]=t[i-1]+nrow;
-        t[i][nrl]=t[i-1][nrl]+nrow*nrol;
-        for(j=nrl+1;j<=nrh;j++) t[i][j]=t[i][j-1]+nrol;
-    }
-    /* return pointer to array of pointers to rows */
-    return t;
-}
-/* ------------------------------------------------------------------------------------ */
-IMAGE_EXPORT(rgb8***) rgb8cube(long ndl, long ndh, long nrl, long nrh, long ncl, long nch)
-/* ------------------------------------------------------------------------------------ */
-/* allocate a rgb8 cube with range t[ndl..ndh][nrl..nrh][ncl..nch] */
-{
-    long i,j,ndep=ndh-ndl+1,nrow=nrh-nrl+1,nrol=nch-ncl+1;
-    rgb8 ***t;
-    
-    /* allocate pointers to pointers to rows */
-    t=(rgb8***) malloc((size_t)((ndep+NR_END)*sizeof(rgb8**)));
-    if (!t) nrerror("allocation failure 1 in rgb8cube()");
-    t += NR_END;
-    t -= ndl;
-    
-    /* allocate pointers to rows anc set pointers to them */
-    t[ndl]=(rgb8**) malloc((size_t)((ndep*nrow+NR_END)*sizeof(rgb8*)));
-    if (!t[ndl]) nrerror("allocation failure 2 in rgb8cube()");
-    t[ndl] += NR_END;
-    t[ndl] -= nrl;
-    
-    /* allocate rows anc set pointers to them */
-    t[ndl][nrl]=(rgb8*) malloc((size_t)((ndep*nrow*nrol+NR_END)*sizeof(rgb8)));
-    if (!t[ndl][nrl]) nrerror("allocation failure 3 in rgb8cube()");
-    t[ndl][nrl] += NR_END;
-    t[ndl][nrl] -= ncl;
-    
-    for(j=nrl+1;j<=nrh;j++) t[ndl][j]=t[ndl][j-1]+nrol;
-    for(i=ndl+1;i<=ndh;i++) {
-        t[i]=t[i-1]+nrow;
-        t[i][nrl]=t[i-1][nrl]+nrow*nrol;
-        for(j=nrl+1;j<=nrh;j++) t[i][j]=t[i][j-1]+nrol;
-    }
-    /* return pointer to array of pointers to rows */
-    return t;
-}
-/* -------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(rgbx8***) rgbx8cube(long ndl, long ndh, long nrl, long nrh, long ncl, long nch)
-/* -------------------------------------------------------------------------------------- */
-/* allocate a rgb8 cube with range t[ndl..ndh][nrl..nrh][ncl..nch] */
-{
-    long i,j,ndep=ndh-ndl+1,nrow=nrh-nrl+1,nrol=nch-ncl+1;
-    rgbx8 ***t;
-    
-    /* allocate pointers to pointers to rows */
-    t=(rgbx8***) malloc((size_t)((ndep+NR_END)*sizeof(rgbx8**)));
-    if (!t) nrerror("allocation failure 1 in rgbx8cube()");
-    t += NR_END;
-    t -= ndl;
-    
-    /* allocate pointers to rows anc set pointers to them */
-    t[ndl]=(rgbx8**) malloc((size_t)((ndep*nrow+NR_END)*sizeof(rgbx8*)));
-    if (!t[ndl]) nrerror("allocation failure 2 in rgbx8cube()");
-    t[ndl] += NR_END;
-    t[ndl] -= nrl;
-    
-    /* allocate rows anc set pointers to them */
-    t[ndl][nrl]=(rgbx8*) malloc((size_t)((ndep*nrow*nrol+NR_END)*sizeof(rgbx8)));
-    if (!t[ndl][nrl]) nrerror("allocation failure 3 in rgbx8cube()");
-    t[ndl][nrl] += NR_END;
-    t[ndl][nrl] -= ncl;
-    
-    for(j=nrl+1;j<=nrh;j++) t[ndl][j]=t[ndl][j-1]+nrol;
-    for(i=ndl+1;i<=ndh;i++) {
-        t[i]=t[i-1]+nrow;
-        t[i][nrl]=t[i-1][nrl]+nrow*nrol;
-        for(j=nrl+1;j<=nrh;j++) t[i][j]=t[i][j-1]+nrol;
-    }
-    /* return pointer to array of pointers to rows */
-    return t;
-}
-/* ------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) free_si8cube(sint8 ***c,long nrl,long nrh,long ncl,long nch,long ndl,long ndh)
-/* ------------------------------------------------------------------------------------------- */
-{
-    free((FREE_ARG) (c[nrl][ncl]+ndl-NR_END));
-    free((FREE_ARG) (c[nrl]+ncl-NR_END));
-    free((FREE_ARG) (c+nrl-NR_END));
-}
-/* ------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) free_ui8cube(uint8 ***c,long nrl,long nrh,long ncl,long nch,long ndl,long ndh)
-/* ------------------------------------------------------------------------------------------- */
-{
-    free((FREE_ARG) (c[nrl][ncl]+ndl-NR_END));
-    free((FREE_ARG) (c[nrl]+ncl-NR_END));
-    free((FREE_ARG) (c+nrl-NR_END));
-}
-/* --------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) free_si16cube(sint16 ***c,long nrl,long nrh,long ncl,long nch,long ndl,long ndh)
-/* --------------------------------------------------------------------------------------------- */
-{
-    free((FREE_ARG) (c[nrl][ncl]+ndl-NR_END));
-    free((FREE_ARG) (c[nrl]+ncl-NR_END));
-    free((FREE_ARG) (c+nrl-NR_END));
-}
-/* --------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) free_ui16cube(uint16 ***c,long nrl,long nrh,long ncl,long nch,long ndl,long ndh)
-/* --------------------------------------------------------------------------------------------- */
-{
-    free((FREE_ARG) (c[nrl][ncl]+ndl-NR_END));
-    free((FREE_ARG) (c[nrl]+ncl-NR_END));
-    free((FREE_ARG) (c+nrl-NR_END));
-}
-/* --------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) free_si32cube(sint32 ***c,long nrl,long nrh,long ncl,long nch,long ndl,long ndh)
-/* --------------------------------------------------------------------------------------------- */
-{
-    free((FREE_ARG) (c[nrl][ncl]+ndl-NR_END));
-    free((FREE_ARG) (c[nrl]+ncl-NR_END));
-    free((FREE_ARG) (c+nrl-NR_END));
-}
-/* --------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) free_ui32cube(uint32 ***c,long nrl,long nrh,long ncl,long nch,long ndl,long ndh)
-/* --------------------------------------------------------------------------------------------- */
-{
-    free((FREE_ARG) (c[nrl][ncl]+ndl-NR_END));
-    free((FREE_ARG) (c[nrl]+ncl-NR_END));
-    free((FREE_ARG) (c+nrl-NR_END));
-}
-/* --------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) free_f32cube(float32 ***c,long nrl,long nrh,long ncl,long nch,long ndl,long ndh)
-/* --------------------------------------------------------------------------------------------- */
-{
-    free((FREE_ARG) (c[nrl][ncl]+ndl-NR_END));
-    free((FREE_ARG) (c[nrl]+ncl-NR_END));
-    free((FREE_ARG) (c+nrl-NR_END));
-}
-/* --------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) free_f64cube(float64 ***c,long nrl,long nrh,long ncl,long nch,long ndl,long ndh)
-/* --------------------------------------------------------------------------------------------- */
-{
-    free((FREE_ARG) (c[nrl][ncl]+ndl-NR_END));
-    free((FREE_ARG) (c[nrl]+ncl-NR_END));
-    free((FREE_ARG) (c+nrl-NR_END));
-}
-/* ------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) free_rgb8cube(rgb8 ***c,long nrl,long nrh,long ncl,long nch,long ndl,long ndh)
-/* ------------------------------------------------------------------------------------------- */
-{
-    free((FREE_ARG) (c[nrl][ncl]+ndl-NR_END));
-    free((FREE_ARG) (c[nrl]+ncl-NR_END));
-    free((FREE_ARG) (c+nrl-NR_END));
-}
-/* --------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) free_rgbx8cube(rgbx8 ***c,long nrl,long nrh,long ncl,long nch,long ndl,long ndh)
-/* --------------------------------------------------------------------------------------------- */
-{
-    free((FREE_ARG) (c[nrl][ncl]+ndl-NR_END));
-    free((FREE_ARG) (c[nrl]+ncl-NR_END));
-    free((FREE_ARG) (c+nrl-NR_END));
-}
+// Local Variables:
+// tab-width: 4
+// c-basic-offset: 4
+// c-file-offsets:((innamespace . 0)(inline-open . 0))
+// indent-tabs-mode: nil
+// End:
+
+// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4
+
Index: soft/giet_vm/applications/rosenfeld/nrc2/src/nrarith0.c
===================================================================
--- soft/giet_vm/applications/rosenfeld/nrc2/src/nrarith0.c	(revision 820)
+++ soft/giet_vm/applications/rosenfeld/nrc2/src/nrarith0.c	(revision 821)
@@ -22,4 +22,5 @@
 #include <math.h>
 
+#include "nrc_os_config.h"
 #include "mypredef.h"
 #include "nrtype.h"
@@ -30,12 +31,22 @@
 #include "nrarith0.h"
 
-ROUTINE(void)    i8swap(int8    *a, int8    *b) { int8    *t; t=a; a=b; b=t;}
-ROUTINE(void)   i16swap(int16   *a, int16   *b) { int16   *t; t=a; a=b; b=t;}
-ROUTINE(void)   i32swap(int32   *a, int32   *b) { int32   *t; t=a; a=b; b=t;}
-ROUTINE(void)   i64swap(int64   *a, int64   *b) { int64   *t; t=a; a=b; b=t;}
-ROUTINE(void)   f32swap(float32 *a, float32 *b) { float32 *t; t=a; a=b; b=t;}
-ROUTINE(void)   f64swap(float64 *a, float64 *b) { float64 *t; t=a; a=b; b=t;}
-ROUTINE(void)  rgb8swap(rgb8    *a, rgb8    *b) { rgb8    *t; t=a; a=b; b=t;}
-ROUTINE(void) rgbx8swap(rgbx8   *a, rgbx8   *b) { rgbx8   *t; t=a; a=b; b=t;}
+#undef type_swap
+#define type_swap(t)                   \
+void short_name(t,,swap)(t * a, t * b) \
+{                                      \
+    t c;                               \
+    c = *a;                            \
+    *a = *b;                           \
+    *b = c;                            \
+}
+
+type_swap(int8_t);
+type_swap(int16_t);
+type_swap(int32_t);
+type_swap(int64_t);
+type_swap(float);
+type_swap(double);
+type_swap(rgb8);
+type_swap(rgbx8);
 
 /* --------- */
@@ -43,39 +54,41 @@
 /* --------- */
 
-ROUTINE(float32)  f32min  (float32 x1, float32 x2)                                    {if (x1<x2)  return x1; else  return x2;}
-ROUTINE(float32)  f32min2 (float32 x1, float32 x2)                                     {if (x1<x2)  return x1; else  return x2;}
-ROUTINE(float32)  f32min3 (float32 x1, float32 x2, float32 x3)                         {return f32min2(f32min2(x1, x2), x3);}
-ROUTINE(float32)  f32min4 (float32 x1, float32 x2, float32 x3, float32 x4)             {return f32min2(f32min2(x1, x2), f32min2(x3, x4));}
-ROUTINE(float32)  f32min5 (float32 x1, float32 x2, float32 x3, float32 x4, float32 x5) {return f32min3(f32min2(x1, x2), f32min2(x3, x4), x5);}
-
-ROUTINE(float64)  f64min  (float64 x1, float64 x2)                                     {if (x1<x2)  return x1; else  return x2;}
-ROUTINE(float64)  f64min2 (float64 x1, float64 x2)                                     {if (x1<x2)  return x1; else  return x2;}
-ROUTINE(float64)  f64min3 (float64 x1, float64 x2, float64 x3)                         {return f64min2(f64min2(x1, x2), x3);}
-ROUTINE(float64)  f64min4 (float64 x1, float64 x2, float64 x3, float64 x4)             {return f64min2(f64min2(x1, x2), f64min2(x3, x4));}
-ROUTINE(float64)  f64min5 (float64 x1, float64 x2, float64 x3, float64 x4, float64 x5) {return f64min3(f64min2(x1, x2), f64min2(x3, x4), x5);}
-
-ROUTINE(uint8)  ui8min (uint8 x1, uint8 x2)                               {if (x1<x2)  return x1; else  return x2;}
-ROUTINE(uint8)  ui8min2(uint8 x1, uint8 x2)                               {if (x1<x2)  return x1; else  return x2;}
-ROUTINE(uint8)  ui8min3(uint8 x1, uint8 x2, uint8 x3)                     {return ui8min2(ui8min2(x1, x2), x3);}
-ROUTINE(uint8)  ui8min4(uint8 x1, uint8 x2, uint8 x3, uint8 x4)           {return ui8min2(ui8min2(x1, x2), ui8min2(x3, x4));}
-ROUTINE(uint8)  ui8min5(uint8 x1, uint8 x2, uint8 x3, uint8 x4, uint8 x5) {return ui8min3(ui8min2(x1, x2), ui8min2(x3, x4), x5);}
-
-ROUTINE(uint16) ui16min (uint16 x1, uint16 x2)                                  {if (x1<x2)  return x1; else  return x2;}
-ROUTINE(uint16) ui16min2(uint16 x1, uint16 x2)                                  {if (x1<x2)  return x1; else  return x2;}
-ROUTINE(uint16) ui16min3(uint16 x1, uint16 x2, uint16 x3)                       {return ui16min2(ui16min2(x1, x2), x3);}
-ROUTINE(uint16) ui16min4(uint16 x1, uint16 x2, uint16 x3, uint16 x4)            {return ui16min2(ui16min2(x1, x2), ui16min2(x3, x4));}
-ROUTINE(uint16) ui16min5(uint16 x1, uint16 x2, uint16 x3, uint16 x4, uint16 x5) {return ui16min3(ui16min2(x1, x2), ui16min2(x3, x4), x5);}
-
-ROUTINE(int32) ui32min (uint32 x1, uint32 x2)                                  {if (x1<x2)  return x1; else  return x2;}
-ROUTINE(int32) ui32min2(uint32 x1, uint32 x2)                                  {if (x1<x2)  return x1; else  return x2;}
-ROUTINE(int32) ui32min3(uint32 x1, uint32 x2, uint32 x3)                       {return ui32min2(ui32min2(x1, x2), x3);}
-ROUTINE(int32) ui32min4(uint32 x1, uint32 x2, uint32 x3, uint32 x4)            {return ui32min2(ui32min2(x1, x2), ui32min2(x3, x4));}
-ROUTINE(int32) ui32min5(uint32 x1, uint32 x2, uint32 x3, uint32 x4, uint32 x5) {return ui32min3(ui32min2(x1, x2), ui32min2(x3, x4), x5);}
-
-ROUTINE(rgb8) rgb8min (rgb8 x1, rgb8 x2)                            {rgb8 y; y.r = ui8min2(x1.r,x2.r);y.g=ui8min2(x1.g,x2.g);y.b=ui8min2(x1.b,x2.b);return y;}
-ROUTINE(rgb8) rgb8min2(rgb8 x1, rgb8 x2)                            {rgb8 y; y.r = ui8min2(x1.r,x2.r);y.g=ui8min2(x1.g,x2.g);y.b=ui8min2(x1.b,x2.b);return y;}
-ROUTINE(rgb8) rgb8min3(rgb8 x1, rgb8 x2, rgb8 x3)                   {return rgb8min2(rgb8min2(x1, x2), x3);}
-ROUTINE(rgb8) rgb8min4(rgb8 x1, rgb8 x2, rgb8 x3, rgb8 x4)          {return rgb8min2(rgb8min2(x1, x2), rgb8min2(x3,x4));}
-ROUTINE(rgb8) rgb8min5(rgb8 x1, rgb8 x2, rgb8 x3, rgb8 x4, rgb8 x5) {return rgb8min3(rgb8min2(x1, x2), rgb8min2(x3,x4), x5);}
+#undef type_min
+#define type_min(t)               \
+t short_name(t,,min)(t x1, t x2)  \
+{                                 \
+    return (x1 < x2) ? x1 : x2;   \
+}                                 \
+t short_name(t,,min2)(t x1, t x2) \
+{                                 \
+    return (x1 < x2) ? x1 : x2;   \
+}                                 \
+t short_name(t,,min3)(t x1, t x2, t x3)                          \
+{                                                                \
+    return short_name(t,,min2)(short_name(t,,min2)(x1, x2), x3); \
+}                                                                \
+t short_name(t,,min4)(t x1, t x2, t x3, t x4)                                                 \
+{                                                                                             \
+    return short_name(t,,min2)(short_name(t,,min2)(x1, x2), short_name(t,,min2)(x3, x4));     \
+}                                                                                             \
+t short_name(t,,min5)(t x1, t x2, t x3, t x4, t x5)                                           \
+{                                                                                             \
+    return short_name(t,,min3)(short_name(t,,min2)(x1, x2), short_name(t,,min2)(x3, x4), x5); \
+}
+
+type_min(float);
+type_min(double);
+type_min(int8_t);
+type_min(uint8_t);
+type_min(int16_t);
+type_min(uint16_t);
+type_min(int32_t);
+type_min(uint32_t);
+
+rgb8 rgb8min (rgb8 x1, rgb8 x2)                            {rgb8 y; y.r = ui8min2(x1.r,x2.r);y.g=ui8min2(x1.g,x2.g);y.b=ui8min2(x1.b,x2.b);return y;}
+rgb8 rgb8min2(rgb8 x1, rgb8 x2)                            {rgb8 y; y.r = ui8min2(x1.r,x2.r);y.g=ui8min2(x1.g,x2.g);y.b=ui8min2(x1.b,x2.b);return y;}
+rgb8 rgb8min3(rgb8 x1, rgb8 x2, rgb8 x3)                   {return rgb8min2(rgb8min2(x1, x2), x3);}
+rgb8 rgb8min4(rgb8 x1, rgb8 x2, rgb8 x3, rgb8 x4)          {return rgb8min2(rgb8min2(x1, x2), rgb8min2(x3,x4));}
+rgb8 rgb8min5(rgb8 x1, rgb8 x2, rgb8 x3, rgb8 x4, rgb8 x5) {return rgb8min3(rgb8min2(x1, x2), rgb8min2(x3,x4), x5);}
 
 /* --------- */
@@ -83,33 +96,35 @@
 /* --------- */
 
-ROUTINE(float32) f32max (float32 x1, float32 x2)                                     {if (x1>x2)  return x1; else  return x2;}
-ROUTINE(float32) f32max2(float32 x1, float32 x2)                                     {if (x1>x2)  return x1; else  return x2;}
-ROUTINE(float32) f32max3(float32 x1, float32 x2, float32 x3)                         {return f32max2(f32max2(x1, x2), x3);}
-ROUTINE(float32) f32max4(float32 x1, float32 x2, float32 x3, float32 x4)             {return f32max2(f32max2(x1, x2), f32max2(x3, x4));}
-ROUTINE(float32) f32max5(float32 x1, float32 x2, float32 x3, float32 x4, float32 x5) {return f32max3(f32max2(x1, x2), f32max2(x3, x4), x5);}
-
-ROUTINE(float64)  f64max  (float64 x1, float64 x2)                                     {if (x1>x2)  return x1; else  return x2;}
-ROUTINE(float64)  f64max2 (float64 x1, float64 x2)                                     {if (x1>x2)  return x1; else  return x2;}
-ROUTINE(float64)  f64max3 (float64 x1, float64 x2, float64 x3)                         {return f64max2(f64max2(x1, x2), x3);}
-ROUTINE(float64)  f64max4 (float64 x1, float64 x2, float64 x3, float64 x4)             {return f64max2(f64max2(x1, x2), f64max2(x3, x4));}
-ROUTINE(float64)  f64max5 (float64 x1, float64 x2, float64 x3, float64 x4, float64 x5) {return f64max3(f64max2(x1, x2), f64max2(x3, x4), x5);}
-
-ROUTINE(uint8) ui8max (uint8 x1, uint8 x2)                               {if (x1>x2)  return x1; else  return x2;}
-ROUTINE(uint8) ui8max2(uint8 x1, uint8 x2)                               {if (x1>x2)  return x1; else  return x2;}
-ROUTINE(uint8) ui8max3(uint8 x1, uint8 x2, uint8 x3)                     {return ui8max2(ui8max2(x1, x2), x3);}
-ROUTINE(uint8) ui8max4(uint8 x1, uint8 x2, uint8 x3, uint8 x4)           {return ui8max2(ui8max2(x1, x2), ui8max2(x3, x4));}
-ROUTINE(uint8) ui8max5(uint8 x1, uint8 x2, uint8 x3, uint8 x4, uint8 x5) {return ui8max3(ui8max2(x1, x2), ui8max2(x3, x4), x5);}
-
-ROUTINE(uint16) ui16max (uint16 x1, uint16 x2)                                  {if (x1>x2)  return x1; else  return x2;}
-ROUTINE(uint16) ui16max2(uint16 x1, uint16 x2)                                  {if (x1>x2)  return x1; else  return x2;}
-ROUTINE(uint16) ui16max3(uint16 x1, uint16 x2, uint16 x3)                       {return ui16max2(ui16max2(x1, x2), x3);}
-ROUTINE(uint16) ui16max4(uint16 x1, uint16 x2, uint16 x3, uint16 x4)            {return ui16max2(ui16max2(x1, x2), ui16max2(x3, x4));}
-ROUTINE(uint16) ui16max5(uint16 x1, uint16 x2, uint16 x3, uint16 x4, uint16 x5) {return ui16max3(ui16max2(x1, x2), ui16max2(x3, x4), x5);}
-
-ROUTINE(int32) ui32max (uint32 x1, uint32 x2)                                 {if (x1>x2) return x1; else  return x2;}
-ROUTINE(int32) ui32max2(uint32 x1, uint32 x2)                                 {if (x1>x2) return x1; else  return x2;}
-ROUTINE(int32) ui32max3(uint32 x1, uint32 x2, uint32 x3)                      {return ui32max2(ui32max2(x1, x2), x3);}
-ROUTINE(int32) ui32max4(uint32 x1, uint32 x2, uint32 x3, uint32 x4)           {return ui32max2(ui32max2(x1, x2), ui32max2(x3, x4));}
-ROUTINE(int32) ui32max5(uint32 x1, uint32 x2, uint32 x3, uint32 x4, int32 x5) {return ui32max3(ui32max2(x1, x2), ui32max2(x3, x4), x5);}
+#undef type_max
+#define type_max(t)               \
+t short_name(t,,max)(t x1, t x2)  \
+{                                 \
+    return (x1 > x2) ? x1 : x2;   \
+}                                 \
+t short_name(t,,max2)(t x1, t x2) \
+{                                 \
+    return (x1 > x2) ? x1 : x2;   \
+}                                 \
+t short_name(t,,max3)(t x1, t x2, t x3)                          \
+{                                                                \
+    return short_name(t,,max2)(short_name(t,,max2)(x1, x2), x3); \
+}                                                                \
+t short_name(t,,max4)(t x1, t x2, t x3, t x4)                                                 \
+{                                                                                             \
+    return short_name(t,,max2)(short_name(t,,max2)(x1, x2), short_name(t,,max2)(x3, x4));     \
+}                                                                                             \
+t short_name(t,,max5)(t x1, t x2, t x3, t x4, t x5)                                           \
+{                                                                                             \
+    return short_name(t,,max3)(short_name(t,,max2)(x1, x2), short_name(t,,max2)(x3, x4), x5); \
+}
+
+type_max(float);
+type_max(double);
+type_max(int8_t);
+type_max(uint8_t);
+type_max(int16_t);
+type_max(uint16_t);
+type_max(int32_t);
+type_max(uint32_t);
 
 ROUTINE(rgb8) rgb8max (rgb8 x1, rgb8 x2)                            {rgb8 y; y.r = ui8max2(x1.r,x2.r);y.g=ui8max2(x1.g,x2.g);y.b=ui8max2(x1.b,x2.b);return y;}
@@ -124,63 +139,79 @@
 
 /* ------------------------------- */
-ROUTINE(int32) i32bit(int32 x, int n)
+int32_t i32bit(int32_t x, int32_t n)
 /* ------------------------------- */
 {
-  return ((x>>n)&1);
-}
+    return ((x >> n) & 1);
+}
+
 /* --------------------------- */
-ROUTINE(int32) sym_int32(int32 x)
+int32_t sym_int32(int32_t x)
 /* --------------------------- */
 {
-  int i;
-  int32 y = 0;
-  for(i=0; i<31; i++) {
-    y = y | (x & 1);
-    x = x >> 1;
-  }
-  y = y | x;
-  return y;
+    int32_t y = 0;
+    for (int32_t i = 0; i < 31; i++) {
+        y = y | (x & 1);
+        x = x >> 1;
+    }
+    y = y | x;
+    return y;
 }
 
 
 /* ----------------------- */
-ROUTINE(int) ilog2(int x)
+int32_t ilog2(int32_t x)
 /* ----------------------- */
 {
-  int s = 0;
-  while(x) {
-    x >>= 1;
-    s++;
-  }
-  return s - 1;
-}
+    int32_t s = 0;
+    while (x) {
+        x >>= 1;
+        s++;
+    }
+    return s - 1;
+}
+
 /* ----------------------------- */
-ROUTINE(int) next_power2(int x)
+int32_t next_power2(int32_t x)
 /* ----------------------------- */
 {
-  int s = ilog2(x);
-  int n = 1 << s;
-  
-  if(x != n)
-    return n << 1;
-  else
-    return n;
-}
-/* ---------------------------- */
-ROUTINE(int) gcd(int u, int v)
-/* ---------------------------- */
-{
-  int r;
-  while(v) {
-    r = u % v;
-    u = v;
-    v = r;
-  }
-  return u;
-}
-/* ---------------------------- */
-ROUTINE(int) lcm(int u, int v)
-/* ---------------------------- */
-{
-  return (u*v)/gcd(u,v);
-}
+    int32_t s = ilog2(x);
+    int32_t n = 1 << s;
+
+    if (x != n) {
+        return n << 1;
+    }
+    else {
+        return n;
+    }
+}
+
+/* ---------------------------- */
+int32_t myGCD(int32_t u, int32_t v)
+/* ---------------------------- */
+{
+    int32_t r;
+    while (v != 0) {
+        r = u % v;
+        u = v;
+        v = r;
+    }
+    return u;
+}
+
+/* ---------------------------- */
+int32_t myLCM(int32_t u, int32_t v)
+/* ---------------------------- */
+{
+    return (u * v) / myGCD(u, v);
+}
+
+
+// Local Variables:
+// tab-width: 4
+// c-basic-offset: 4
+// c-file-offsets:((innamespace . 0)(inline-open . 0))
+// indent-tabs-mode: nil
+// End:
+
+// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4
+
Index: soft/giet_vm/applications/rosenfeld/nrc2/src/nrarith1.c
===================================================================
--- soft/giet_vm/applications/rosenfeld/nrc2/src/nrarith1.c	(revision 820)
+++ soft/giet_vm/applications/rosenfeld/nrc2/src/nrarith1.c	(revision 821)
@@ -20,6 +20,6 @@
 #include <malloc.h>
 #include <math.h> // fabs
-// #include <memory.h> // memcpy
-
+
+#include "nrc_os_config.h"
 #include "mypredef.h"
 #include "nrtype.h"
@@ -28,5 +28,4 @@
 #include "nrkernel.h"
 
-//#include "nralloc.h"
 #include "nrarith1.h"
 
@@ -37,92 +36,23 @@
  */
 
-/* -------------------------------------------------------- */
-IMAGE_EXPORT(sint32) sum_si8vector(sint8 *v, long nl, long nh)
-/* -------------------------------------------------------- */
-{
-	int i;
-    sint32 s = 0;
-	for(i=nl; i<=nh; i++) {
-		s += v[i];
-	}
-	return s;
-}
-/* -------------------------------------------------------- */
-IMAGE_EXPORT(uint32) sum_u8ivector(uint8 *v, long nl, long nh)
-/* -------------------------------------------------------- */
-{
-	int i;
-    uint32 s = 0;
-	for(i=nl; i<=nh; i++) {
-		s += v[i];
-	}
-	return s;
-}
-/* ---------------------------------------------------------- */
-IMAGE_EXPORT(sint32) sum_si16vector(sint16 *v, long nl, long nh)
-/* ---------------------------------------------------------- */
-{
-	int i;
-    sint32 s = 0;
-	for(i=nl; i<=nh; i++) {
-		s += v[i];
-	}
-	return s;
-}
-/* ---------------------------------------------------------- */
-IMAGE_EXPORT(uint32) sum_u16ivector(uint16 *v, long nl, long nh)
-/* ---------------------------------------------------------- */
-{
-	int i;
-    uint32 s = 0;
-	for(i=nl; i<=nh; i++) {
-		s += v[i];
-	}
-	return s;
-}
-/* ---------------------------------------------------------- */
-IMAGE_EXPORT(sint32) sum_si32vector(sint32 *v, long nl, long nh)
-/* ---------------------------------------------------------- */
-{
-	int i;
-    sint32 s = 0;
-	for(i=nl; i<=nh; i++) {
-		s += v[i];
-	}
-	return s;
-}
-/* ---------------------------------------------------------- */
-IMAGE_EXPORT(uint32) sum_u32ivector(uint32 *v, long nl, long nh)
-/* ---------------------------------------------------------- */
-{
-	int i;
-    uint32 s = 0;
-	for(i=nl; i<=nh; i++) {
-		s += v[i];
-	}
-	return s;
-}
-/* ----------------------------------------------------------- */
-IMAGE_EXPORT(float32) sum_f32vector(float32 *v, long nl, long nh)
-/* ----------------------------------------------------------- */
-{
-	int i;
-	float32 s = 0.0f;
-	for(i=nl; i<=nh; i++) {
-		s += v[i];
-	}
-	return s;
-}
-/* ----------------------------------------------------------- */
-IMAGE_EXPORT(float64) sum_f64vector(float64 *v, long nl, long nh)
-/* ----------------------------------------------------------- */
-{
-	int i;
-	float64 s = 0.0;
-	for(i=nl; i<=nh; i++) {
-		s += v[i];
-	}
-	return s;
-}
+#undef sum_type_vector
+#define sum_type_vector(t,r)                                     \
+r short_name(t,sum_,vector)(t * v, int32_t nl, int32_t nh)       \
+{                                                                \
+    r s = 0;                                                     \
+    for (int32_t i = nl; i <= nh; i++) {                         \
+        s += v[i];                                               \
+    }                                                            \
+    return s;                                                    \
+}
+
+sum_type_vector(int8_t, int32_t);
+sum_type_vector(uint8_t, uint32_t);
+sum_type_vector(int16_t, int32_t);
+sum_type_vector(uint16_t, uint32_t);
+sum_type_vector(int32_t, int32_t);
+sum_type_vector(uint32_t, uint32_t);
+sum_type_vector(float, float);
+sum_type_vector(double, double);
 
 /*
@@ -132,108 +62,27 @@
  */
 
-/* ------------------------------------------------------- */
-IMAGE_EXPORT(sint8) min_si8vector(sint8 *v, long nl, long nh)
-/* ------------------------------------------------------- */
-{
-	int i;
-	uint8  m;
-	
-	m = v[nl];
-	for(i=nl+1; i<=nh; i++) {
-		if(v[i]<m) m = v[i];
-	}
-	return m;
-}
-/* ------------------------------------------------------- */
-IMAGE_EXPORT(uint8) min_ui8vector(uint8 *v, long nl, long nh)
-/* ------------------------------------------------------- */
-{
-	int i;
-	uint8  m;
-	
-	m = v[nl];
-	for(i=nl+1; i<=nh; i++) {
-		if(v[i]<m) m = v[i];
-	}
-	return m;
-}
-/* ---------------------------------------------------------- */
-IMAGE_EXPORT(sint16) min_si16vector(sint16 *v, long nl, long nh)
-/* ---------------------------------------------------------- */
-{
-	int i;
-	int16 m;
-	
-	m = v[nl];
-	for(i=nl+1; i<=nh; i++) {
-		if(v[i]<m) m = v[i];
-	}
-	return m;
-}
-/* ---------------------------------------------------------- */
-IMAGE_EXPORT(uint16) min_ui16vector(uint16 *v, long nl, long nh)
-/* ---------------------------------------------------------- */
-{
-	int i;
-	uint16 m;
-	
-	m = v[nl];
-	for(i=nl+1; i<=nh; i++) {
-		if(v[i]<m) m = v[i];
-	}
-	return m;
-}
-/* ---------------------------------------------------------- */
-IMAGE_EXPORT(sint32) min_si32vector(sint32 *v, long nl, long nh)
-/* ---------------------------------------------------------- */
-{
-	int i;
-	int16 m;
-	
-	m = v[nl];
-	for(i=nl+1; i<=nh; i++) {
-		if(v[i]<m) m = v[i];
-	}
-	return m;
-}
-/* ---------------------------------------------------------- */
-IMAGE_EXPORT(uint32) min_ui32vector(uint32 *v, long nl, long nh)
-/* ---------------------------------------------------------- */
-{
-	int i;
-	uint32 m;
-	
-	m = v[nl];
-	for(i=nl+1; i<=nh; i++) {
-		if(v[i]<m) m = v[i];
-	}
-	return m;
-}
-/* ----------------------------------------------------------- */
-IMAGE_EXPORT(float32) min_f32vector(float32 *v, long nl, long nh)
-/* ----------------------------------------------------------- */
-{
-	int i;
-	float32 m;
-	
-	m = v[nl];
-	for(i=nl+1; i<=nh; i++) {
-		if(v[i]<m) m = v[i];
-	}
-	return m;
-}
-/* ----------------------------------------------------------- */
-IMAGE_EXPORT(float64) min_f64vector(float64 *v, long nl, long nh)
-/* ----------------------------------------------------------- */
-{
-	int i;
-	float64 m;
-	
-	m = v[nl];
-	for(i=nl+1; i<=nh; i++) {
-		if(v[i]<m) m = v[i];
-	}
-	return m;
-}
+#undef min_type_vector
+#define min_type_vector(t)                                 \
+t short_name(t,min_,vector)(t * v, int32_t nl, int32_t nh) \
+{                                                          \
+    t m = v[nl];                                           \
+    for (int32_t i = nl + 1; i <= nh; i++) {               \
+        if (v[i] < m) {                                    \
+            m = v[i];                                      \
+        }                                                  \
+    }                                                      \
+    return m;                                              \
+}
+
+
+min_type_vector(int8_t);
+min_type_vector(uint8_t);
+min_type_vector(int16_t);
+min_type_vector(uint16_t);
+min_type_vector(int32_t);
+min_type_vector(uint32_t);
+min_type_vector(float);
+min_type_vector(double);
+
 
 /*
@@ -243,108 +92,28 @@
  */
 
-/* ------------------------------------------------------- */
-IMAGE_EXPORT(sint8) max_si8vector(sint8 *v, long nl, long nh)
-/* ------------------------------------------------------- */
-{
-	int i;
-	sint8  m;
-	
-	m = v[nl];
-	for(i=nl+1; i<=nh; i++) {
-		if(v[i]>m) m = v[i];
-	}
-	return m;
-}
-/* ------------------------------------------------------- */
-IMAGE_EXPORT(uint8) max_ui8vector(uint8 *v, long nl, long nh)
-/* ------------------------------------------------------- */
-{
-	int i;
-	uint8  m;
-	
-	m = v[nl];
-	for(i=nl+1; i<=nh; i++) {
-		if(v[i]>m) m = v[i];
-	}
-	return m;
-}
-/* ---------------------------------------------------------- */
-IMAGE_EXPORT(sint16) max_si16vector(sint16 *v, long nl, long nh)
-/* ---------------------------------------------------------- */
-{
-	int i; 
-	sint16 m;
-	
-	m = v[nl];
-	for(i=nl+1; i<=nh; i++) {
-		if(v[i]>m) m = v[i];
-	}
-	return m;
-}
-/* ---------------------------------------------------------- */
-IMAGE_EXPORT(uint16) max_ui16vector(uint16 *v, long nl, long nh)
-/* ---------------------------------------------------------- */
-{
-	int i; 
-	uint16 m;
-	
-	m = v[nl];
-	for(i=nl+1; i<=nh; i++) {
-		if(v[i]>m) m = v[i];
-	}
-	return m;
-}
-/* ---------------------------------------------------------- */
-IMAGE_EXPORT(sint32) max_si32vector(sint32 *v, long nl, long nh)
-/* ---------------------------------------------------------- */
-{
-	int i;
-	sint32 m;
-	
-	m = v[nl];
-	for(i=nl+1; i<=nh; i++) {
-		if(v[i]>m) m = v[i];
-	}
-	return m;
-}
-/* ---------------------------------------------------------- */
-IMAGE_EXPORT(uint32) max_ui32vector(uint32 *v, long nl, long nh)
-/* ---------------------------------------------------------- */
-{
-	int i;
-	uint32 m;
-	
-	m = v[nl];
-	for(i=nl+1; i<=nh; i++) {
-		if(v[i]>m) m = v[i];
-	}
-	return m;
-}
-/* ----------------------------------------------------------- */
-IMAGE_EXPORT(float32) max_f32vector(float32 *v, long nl, long nh)
-/* ----------------------------------------------------------- */
-{
-	int i;
-	float32 m;
-	
-	m = v[nl];
-	for(i=nl+1; i<=nh; i++) {
-		if(v[i]>m) m = v[i];
-	}
-	return m;
-}
-/* ----------------------------------------------------------- */
-IMAGE_EXPORT(float64) max_f64vector(float64 *v, long nl, long nh)
-/* ----------------------------------------------------------- */
-{
-	int i;
-	float64 m;
-	
-	m = v[nl];
-	for(i=nl+1; i<=nh; i++) {
-		if(v[i]>m) m = v[i];
-	}
-	return m;
-}
+#undef max_type_vector
+#define max_type_vector(t)                                 \
+t short_name(t,max_,vector)(t * v, int32_t nl, int32_t nh) \
+{                                                          \
+    t m = v[nl];                                           \
+    for (int32_t i = nl + 1; i <= nh; i++) {               \
+        if (v[i] > m) {                                    \
+            m = v[i];                                      \
+        }                                                  \
+    }                                                      \
+    return m;                                              \
+}
+
+
+max_type_vector(int8_t);
+max_type_vector(uint8_t);
+max_type_vector(int16_t);
+max_type_vector(uint16_t);
+max_type_vector(int32_t);
+max_type_vector(uint32_t);
+max_type_vector(float);
+max_type_vector(double);
+
+
 /*
  * ----------------------
@@ -353,116 +122,31 @@
  */
 
-/* --------------------------------------------------------------------- */
-IMAGE_EXPORT(sint8) min_si8vector_pos(sint8 *v, long nl, long nh, int *pos)
-/* --------------------------------------------------------------------- */
-{
-	int i;
-	sint8  m = v[nl];
-	int  p = nl;
-	
-	for(i=nl+1; i<=nh; i++) {
-		if(v[i]>m) { m = v[i]; p = i;}
-	}
-	*pos = p;
-	return m;
-}
-/* --------------------------------------------------------------------- */
-IMAGE_EXPORT(uint8) min_ui8vector_pos(uint8 *v, long nl, long nh, int *pos)
-/* --------------------------------------------------------------------- */
-{
-	int i;
-	uint8  m = v[nl];
-	int  p = nl;
-	
-	for(i=nl+1; i<=nh; i++) {
-		if(v[i]>m) { m = v[i]; p = i;}
-	}
-	*pos = p;
-	return m;
-}
-/* ------------------------------------------------------------------------ */
-IMAGE_EXPORT(sint16) min_si16vector_pos(sint16 *v, long nl, long nh, int *pos)
-/* ------------------------------------------------------------------------ */
-{
-	int i;
-	sint16 m = v[nl];
-	int  p = nl;
-	
-	for(i=nl+1; i<=nh; i++) {
-		if(v[i]>m) { m = v[i]; p = i;}
-	}
-	*pos = p;
-	return m;
-}
-/* ------------------------------------------------------------------------ */
-IMAGE_EXPORT(uint16) min_ui16vector_pos(uint16 *v, long nl, long nh, int *pos)
-/* ------------------------------------------------------------------------ */
-{
-	int i;
-	uint16 m = v[nl];
-	int  p = nl;
-	
-	for(i=nl+1; i<=nh; i++) {
-		if(v[i]>m) { m = v[i]; p = i;}
-	}
-	*pos = p;
-	return m;
-}
-/* ------------------------------------------------------------------------ */
-IMAGE_EXPORT(sint32) min_si32vector_pos(sint32 *v, long nl, long nh, int *pos)
-/* ------------------------------------------------------------------------ */
-{
-	int i;
-	sint32 m = v[nl];
-	int  p = nl;
-	
-	for(i=nl+1; i<=nh; i++) {
-		if(v[i]>m) { m = v[i]; p = i;}
-	}
-	*pos = p;
-	return m;
-}
-/* ------------------------------------------------------------------------ */
-IMAGE_EXPORT(uint32) min_ui32vector_pos(uint32 *v, long nl, long nh, int *pos)
-/* ------------------------------------------------------------------------ */
-{
-	int i;
-	uint32 m = v[nl];
-	int  p = nl;
-	
-	for(i=nl+1; i<=nh; i++) {
-		if(v[i]>m) { m = v[i]; p = i;}
-	}
-	*pos = p;
-	return m;
-}
-/* ------------------------------------------------------------------------- */
-IMAGE_EXPORT(float32) min_f32vector_pos(float32 *v, long nl, long nh, int *pos)
-/* ------------------------------------------------------------------------- */
-{
-	int i;
-	float32 m = v[nl];
-	int  p = nl;
-	
-	for(i=nl+1; i<=nh; i++) {
-		if(v[i]>m) { m = v[i]; p = i;}
-	}
-	*pos = p;
-	return m;
-}
-/* ------------------------------------------------------------------------- */
-IMAGE_EXPORT(float64) min_f64vector_pos(float64 *v, long nl, long nh, int *pos)
-/* ------------------------------------------------------------------------- */
-{
-	int i;
-	float64 m = v[nl];
-	int  p = nl;
-	
-	for(i=nl+1; i<=nh; i++) {
-		if(v[i]>m) { m = v[i]; p = i;}
-	}
-	*pos = p;
-	return m;
-}
+
+#undef min_type_vector_pos
+#define min_type_vector_pos(t)                                                \
+t short_name(t,min_,vector_pos)(t * v, int32_t nl, int32_t nh, int32_t * pos) \
+{                                                                             \
+    t m = v[nl];                                                              \
+    int32_t p = nl;                                                           \
+    for (int32_t i = nl + 1; i <= nh; i++) {                                  \
+        if (v[i] < m) {                                                       \
+            m = v[i];                                                         \
+            p = i;                                                            \
+        }                                                                     \
+    }                                                                         \
+    *pos = p;                                                                 \
+    return m;                                                                 \
+}
+
+
+min_type_vector_pos(int8_t);
+min_type_vector_pos(uint8_t);
+min_type_vector_pos(int16_t);
+min_type_vector_pos(uint16_t);
+min_type_vector_pos(int32_t);
+min_type_vector_pos(uint32_t);
+min_type_vector_pos(float);
+min_type_vector_pos(double);
+
 
 /*
@@ -472,279 +156,266 @@
  */
 
-/* --------------------------------------------------------------------- */
-IMAGE_EXPORT(sint8) max_si8vector_pos(sint8 *v, long nl, long nh, int *pos)
-/* --------------------------------------------------------------------- */
-{
-	int i;
-	sint8 m = v[nl];
-	int  p = nl;
-	
-	for(i=nl+1; i<=nh; i++) {
-		if(v[i]>m) { m = v[i]; p = i;}
-	}
-	*pos = p;
-	
-	return m;
-}
-/* --------------------------------------------------------------------- */
-IMAGE_EXPORT(uint8) max_ui8vector_pos(uint8 *v, long nl, long nh, int *pos)
-/* --------------------------------------------------------------------- */
-{
-	int i;
-	uint8 m = v[nl];
-	int  p = nl;
-	
-	for(i=nl+1; i<=nh; i++) {
-		if(v[i]>m) { m = v[i]; p = i;}
-	}
-	*pos = p;
-	
-	return m;
-}
+
+#undef max_type_vector_pos
+#define max_type_vector_pos(t)                                                \
+t short_name(t,max_,vector_pos)(t * v, int32_t nl, int32_t nh, int32_t * pos) \
+{                                                                             \
+    t m = v[nl];                                                              \
+    int32_t p = nl;                                                           \
+    for (int32_t i = nl + 1; i <= nh; i++) {                                  \
+        if (v[i] > m) {                                                       \
+            m = v[i];                                                         \
+            p = i;                                                            \
+        }                                                                     \
+    }                                                                         \
+    *pos = p;                                                                 \
+    return m;                                                                 \
+}
+
+
+max_type_vector_pos(int8_t);
+max_type_vector_pos(uint8_t);
+max_type_vector_pos(int16_t);
+max_type_vector_pos(uint16_t);
+max_type_vector_pos(int32_t);
+max_type_vector_pos(uint32_t);
+max_type_vector_pos(float);
+max_type_vector_pos(double);
+
+
+#undef add_type_vector
+#define add_type_vector(t) \
+void short_name(t,add_,vector)(t * S1, int32_t nl, int32_t nh, t * S2, t * D) \
+{                                                                             \
+    for (int32_t i = nl; i <= nh; i++) {                                      \
+        D[i] = S1[i] + S2[i];                                                 \
+    }                                                                         \
+}
+
+add_type_vector(int8_t);
+add_type_vector(uint8_t);
+add_type_vector(int16_t);
+add_type_vector(uint16_t);
+add_type_vector(int32_t);
+add_type_vector(uint32_t);
+add_type_vector(float);
+add_type_vector(double);
+
+
+#undef sub_type_vector
+#define sub_type_vector(t) \
+void short_name(t,sub_,vector)(t * S1, int32_t nl, int32_t nh, t * S2, t * D) \
+{                                                                             \
+    for (int32_t i = nl; i <= nh; i++) {                                      \
+        D[i] = S1[i] - S2[i];                                                 \
+    }                                                                         \
+}
+
+sub_type_vector(int8_t);
+sub_type_vector(uint8_t);
+sub_type_vector(int16_t);
+sub_type_vector(uint16_t);
+sub_type_vector(int32_t);
+sub_type_vector(uint32_t);
+sub_type_vector(float);
+sub_type_vector(double);
+
+
+#undef mulc_type_vector
+#define mulc_type_vector(t) \
+void short_name(t,mulc_,vector)(t * S, int32_t nl, int32_t nh, int32_t c, t * D)  \
+{                                                                                 \
+    for (int32_t i = nl; i <= nh; i++) {                                          \
+        D[i] = S[i] * c;                                                          \
+    }                                                                             \
+}
+
+mulc_type_vector(int8_t);
+mulc_type_vector(uint8_t);
+mulc_type_vector(int16_t);
+mulc_type_vector(uint16_t);
+mulc_type_vector(int32_t);
+mulc_type_vector(uint32_t);
+mulc_type_vector(float);
+mulc_type_vector(double);
+
+
+#undef divc_type_vector
+#define divc_type_vector(t) \
+void short_name(t,divc_,vector)(t * S, int32_t nl, int32_t nh, int32_t c, t * D)  \
+{                                                                                 \
+    for (int32_t i = nl; i <= nh; i++) {                                          \
+        D[i] = S[i] / c;                                                          \
+    }                                                                             \
+}
+
+divc_type_vector(int8_t);
+divc_type_vector(uint8_t);
+divc_type_vector(int16_t);
+divc_type_vector(uint16_t);
+divc_type_vector(int32_t);
+divc_type_vector(uint32_t);
+divc_type_vector(float);
+divc_type_vector(double);
+
+
+#undef cumulleft_type_vector
+#define cumulleft_type_vector(t) \
+void short_name(t,cumulleft_,vector)(t * S, int32_t nl, int32_t nh, int32_t * D) \
+{                                                                                \
+    for (int32_t i = nh - 1; i >= nl; i--) {                                     \
+        D[i] += S[i + 1];                                                        \
+    }                                                                            \
+}
+
+cumulleft_type_vector(int8_t);
+cumulleft_type_vector(uint8_t);
+cumulleft_type_vector(int16_t);
+cumulleft_type_vector(uint16_t);
+cumulleft_type_vector(int32_t);
+cumulleft_type_vector(uint32_t);
+cumulleft_type_vector(float);
+cumulleft_type_vector(double);
+
+
+#undef cumulright_type_vector
+#define cumulright_type_vector(t) \
+void short_name(t,cumulright_,vector)(t * S, int32_t nl, int32_t nh, int32_t * D) \
+{                                                                                 \
+    for (int32_t i = nl + 1; i <= nh; i++) {                                      \
+        D[i] += S[i - 1];                                                         \
+    }                                                                             \
+}
+
+cumulright_type_vector(int8_t);
+cumulright_type_vector(uint8_t);
+cumulright_type_vector(int16_t);
+cumulright_type_vector(uint16_t);
+cumulright_type_vector(int32_t);
+cumulright_type_vector(uint32_t);
+cumulright_type_vector(float);
+cumulright_type_vector(double);
+
+
+#undef mulfrac_type_vector
+#define mulfrac_type_vector(t) \
+void short_name(t,mulfrac_,vector)(t * S, int32_t nl, int32_t nh, int32_t a, int32_t b, t * D) \
+{                                                                                              \
+    for (int32_t i = nl; i <= nh; i++) {                                                       \
+        D[i] = (a * S[i]) / b;                                                                 \
+    }                                                                                          \
+}
+
+
+mulfrac_type_vector(int8_t);
+mulfrac_type_vector(uint8_t);
+mulfrac_type_vector(int16_t);
+mulfrac_type_vector(uint16_t);
+mulfrac_type_vector(int32_t);
+mulfrac_type_vector(uint32_t);
+mulfrac_type_vector(float);
+mulfrac_type_vector(double);
+
+
+/* --------------------------------------------------------------------- */
+void beta_sum_rgb32vector(rgb32 * S, int32_t nl, int32_t nh, rgb32 * D)
+/* --------------------------------------------------------------------- */
+{
+    int32_t r, g, b;
+    int32_t s;
+    for (int32_t i = nl; i <= nh; i++) {
+        r = S[i].r;
+        g = S[i].g;
+        b = S[i].b;
+        s = r + g + b;
+        D[i].r = s;
+        D[i].g = s;
+        D[i].b = s;
+    }
+}
+
+/* ----------------------------------------------------------------------- */
+void beta_average_rgb32vector(rgb32 * S, int32_t nl, int32_t nh, rgb32 * D)
+/* ----------------------------------------------------------------------- */
+{
+    int32_t r, g, b;
+    int32_t s;
+    for (int32_t i = nl; i <= nh; i++) {
+        r = S[i].r;
+        g = S[i].g;
+        b = S[i].b;
+        s = (r + g + b) / 3;
+        D[i].r = s;
+        D[i].g = s;
+        D[i].b = s;
+    }
+}
+
 /* ------------------------------------------------------------------------ */
-IMAGE_EXPORT(sint16) max_si16vector_pos(sint16 *v, long nl, long nh, int *pos)
+void mulc_rgb32vector(rgb32 * S, int32_t nl, int32_t nh, int32_t c, rgb32 * D)
 /* ------------------------------------------------------------------------ */
 {
-	int i; 
-	int16 m = v[nl];
-	int  p = nl;
-	
-	for(i=nl+1; i<=nh; i++) {
-		if(v[i]>m) { m = v[i]; p = i;}
-	}
-	*pos = p;
-	return m;
-}
-/* ----------------------------------------------------------------------- */
-IMAGE_EXPORT(uint16) max_ui16vector_pos(uint16 *v, long nl, long nh, int *pos)
-/* ----------------------------------------------------------------------- */
-{
-	int i; 
-	uint16 m = v[nl];
-	int  p = nl;
-	
-	for(i=nl+1; i<=nh; i++) {
-		if(v[i]>m) { m = v[i]; p = i;}
-	}
-	*pos = p;
-	
-	return m;
-}
-/* --------------------------------------------------------------------- */
-IMAGE_EXPORT(sint32) max_si32vector_pos(sint32 *v, long nl, long nh, int *pos)
-/* --------------------------------------------------------------------- */
-{
-	int i;
-	sint32 m = v[nl];
-	int  p = nl;
-	
-	for(i=nl+1; i<=nh; i++) {
-		if(v[i]>m) { m = v[i]; p = i;}
-	}
-	*pos = p;
-	
-	return m;
-}
-/* ------------------------------------------------------------------------ */
-IMAGE_EXPORT(uint32) max_ui32vector_pos(uint32 *v, long nl, long nh, int *pos)
-/* ------------------------------------------------------------------------ */
-{
-	int i;
-	uint32 m = v[nl];
-	int  p = nl;
-	
-	for(i=nl+1; i<=nh; i++) {
-		if(v[i]>m) { m = v[i]; p = i;}
-	}
-	*pos = p;
-	
-	return m;
-}
-/* ----------------------------------------------------------------------- */
-IMAGE_EXPORT(float32) max_f32vector_pos(float32 *v, long nl, long nh, int *pos)
-/* ----------------------------------------------------------------------- */
-{
-	int i;
-	float32 m = v[nl];
-	int  p = nl;
-	
-	for(i=nl+1; i<=nh; i++) {
-		if(v[i]>m) { m = v[i]; p = i;}
-	}
-	*pos = p;
-	
-	return m;
-}
-/* ------------------------------------------------------------------------- */
-IMAGE_EXPORT(float64) max_f64vector_pos(float64 *v, long nl, long nh, int *pos)
-/* ------------------------------------------------------------------------- */
-{
-	int i;
-	float64 m = v[nl];
-	int  p = nl;
-	
-	for(i=nl+1; i<=nh; i++) {
-		if(v[i]>m) { m = v[i]; p = i;}
-	}
-	*pos = p;
-	
-	return m;
-}
-/* --------------------------------------------------------------------- */
-IMAGE_EXPORT(void) beta_sum_rgb32vector(rgb32 *S,long nl,long nh, rgb32 *D)
-/* --------------------------------------------------------------------- */
-{
-	long i;
-	int32 r, g, b, s;
-	for(i=nl; i<=nh; i++){
-		r = S[i].r;
-		g = S[i].g;
-		b = S[i].b;
-		s = r + g + b;
-		D[i].r = s;
-		D[i].g = s;
-		D[i].b = s;
-	}
-}
-/* ----------------------------------------------------------------------- */
-IMAGE_EXPORT(void) beta_average_rgb32vector(rgb32 *S,long nl,long nh, rgb32 *D)
-/* ----------------------------------------------------------------------- */
-{
-	long i;
-	int32 r, g, b, s;
-	for(i=nl; i<=nh; i++){
-		r = S[i].r;
-		g = S[i].g;
-		b = S[i].b;
-		s = (r + g + b) / 3;
-		D[i].r = s;
-		D[i].g = s;
-		D[i].b = s;
-	}
-}
-/* ------------------------------------------------------------------------ */
-IMAGE_EXPORT(void) add_i32vector(int32 *S1,long nl,long nh, int32 *S2, int32 *D)
-/* ------------------------------------------------------------------------ */
-{
-	long i;
-	for(i=nl; i<=nh; i++) D[i] = S1[i] + S2[i];
-}
-/* ------------------------------------------------------------------------ */
-IMAGE_EXPORT(void) sub_i32vector(int32 *S1,long nl,long nh, int32 *S2, int32 *D)
-/* ------------------------------------------------------------------------ */
-{
-	long i;
-	for(i=nl; i<=nh; i++) D[i] = S1[i] - S2[i];
-}
-/* ---------------------------------------------------------------------- */
-IMAGE_EXPORT(void) mulc_i32vector(int32 *S,long nl,long nh, int32 c, int32 *D)
-/* ---------------------------------------------------------------------- */
-{
-	long i;
-	for(i=nl; i<=nh; i++) D[i] = c * S[i];
-}
-/* ------------------------------------------------------------------------ */
-IMAGE_EXPORT(void) mulc_rgb32vector(rgb32 *S,long nl,long nh, int32 c, rgb32 *D)
-/* ------------------------------------------------------------------------ */
-{
-	long i;
-	
-	for(i=nl; i<=nh; i++) {
-		D[i].r = c * S[i].r;
-		D[i].g = c * S[i].g;
-		D[i].b = c * S[i].b;
-	}
-}
-/* ------------------------------------------------------------------------ */
-IMAGE_EXPORT(void) divc_i32vector(int32 *S,long nl,long nh, int32 c, int32 *D)
-/* ------------------------------------------------------------------------ */
-{
-	long i;
-	for(i=nl; i<=nh; i++) D[i] = S[i]  / c;
-}
-/* -------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) divc_rgb32vector(rgb32 *S,long nl,long nh, int32 c, rgb32 *D)
-/* -------------------------------------------------------------------------- */
-{
-	long i;
-	
-	for(i=nl; i<=nh; i++) {
-		D[i].r = S[i].r / c;
-		D[i].g = S[i].g / c;
-		D[i].b = S[i].b / c;
-	}
-}
-/* -------------------------------------------------------------------- */
-IMAGE_EXPORT(void) cumulleft_i32vector(int32 *S, long nl,long nh, int32 *D)
-/* -------------------------------------------------------------------- */
-{
-	// for histogram
-	long i;
-	
-	for(i=nh-1; i>=nl; i--) {
-		D[i] += S[i+1];
-	}
-}
-/* --------------------------------------------------------------------- */
-IMAGE_EXPORT(void) cumulleft_rgb32vector(rgb32 *S, long nl,long nh, rgb32 *D)
-/* --------------------------------------------------------------------- */
-{
-	// for histogram
-	long i;
-	
-	for(i=nh-1; i>=nl; i--) {
-		D[i].r += S[i+1].r;
-		D[i].g += S[i+1].g;
-		D[i].b += S[i+1].b;
-	}
-}
-/* -------------------------------------------------------------------- */
-IMAGE_EXPORT(void) cumulright_i32vector(int32 *S, long nl,long nh, int32 *D)
-/* -------------------------------------------------------------------- */
-{
-	// for histogram
-	long i;
-	
-	for(i=nl+1; i<=nh; i++) {
-		D[i] += S[i-1];
-	}
-}
-/* ---------------------------------------------------------------------- */
-IMAGE_EXPORT(void) cumulright_rgb32vector(rgb32 *S, long nl,long nh, rgb32 *D)
-/* ---------------------------------------------------------------------- */
-{
-	// for histogram
-	long i;
-	
-	for(i=nl+1; i<=nh; i++) {
-		D[i].r += S[i-1].r;
-		D[i].g += S[i-1].g;
-		D[i].b += S[i-1].b;
-	}
-}
-/* ----------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) mulfrac_i32vector(int32 *S, long nl,long nh, int32 a, int32 b, int32 *D)
-/* ----------------------------------------------------------------------------------- */
-{
-	long i;
-	
-	for(i=nl; i<=nh; i++) {
-		//D[i] = (a * S[i] + b) / b;
-		D[i] = (a * S[i]) / b;
-	}
-}
+    for (int32_t i = nl; i <= nh; i++) {
+        D[i].r = c * S[i].r;
+        D[i].g = c * S[i].g;
+        D[i].b = c * S[i].b;
+    }
+}
+
+/* --------------------------------------------------------------------- */
+void divc_rgb32vector(rgb32 * S, int32_t nl, int32_t nh, int32_t c, rgb32 * D)
+/* --------------------------------------------------------------------- */
+{
+    for (int32_t i = nl; i <= nh; i++) {
+        D[i].r = S[i].r / c;
+        D[i].g = S[i].g / c;
+        D[i].b = S[i].b / c;
+    }
+}
+
+/* --------------------------------------------------------------------- */
+void cumulleft_rgb32vector(rgb32 * S, int32_t nl, int32_t nh, rgb32 * D)
+/* --------------------------------------------------------------------- */
+{
+    // for histogram
+    for (int32_t i = nh - 1; i >= nl; i--) {
+        D[i].r += S[i + 1].r;
+        D[i].g += S[i + 1].g;
+        D[i].b += S[i + 1].b;
+    }
+}
+
+    
+/* --------------------------------------------------------------------- */
+void cumulright_rgb32vector(rgb32 * S, int32_t nl, int32_t nh, rgb32 * D)
+/* --------------------------------------------------------------------- */
+{
+    // for histogram
+    for (int32_t i = nl + 1; i <= nh; i++) {
+        D[i].r += S[i - 1].r;
+        D[i].g += S[i - 1].g;
+        D[i].b += S[i - 1].b;
+    }
+}
+
+
 /* ------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) mulfrac_rgb32vector(rgb32 *S, long nl,long nh, int32 a, int32 b, rgb32 *D)
+void mulfrac_rgb32vector(rgb32 * S, int32_t nl, int32_t nh, int32_t a, int32_t b, rgb32 * D)
 /* ------------------------------------------------------------------------------------- */
 {
-	long i;
-	
-	for(i=nl; i<=nh; i++) {
-		//D[i].r = (a * S[i].r + b) / b;
-		//D[i].g = (a * S[i].g + b) / b;
-		//D[i].b = (a * S[i].b + b) / b;
-		D[i].r = (a * S[i].r) / b;
-		D[i].g = (a * S[i].g) / b;
-		D[i].b = (a * S[i].b) / b;
-	}
-}
+    for (int32_t i = nl; i <= nh; i++) {
+        D[i].r = (a * S[i].r) / b;
+        D[i].g = (a * S[i].g) / b;
+        D[i].b = (a * S[i].b) / b;
+    }
+}
+
+// Local Variables:
+// tab-width: 4
+// c-basic-offset: 4
+// c-file-offsets:((innamespace . 0)(inline-open . 0))
+// indent-tabs-mode: nil
+// End:
+
+// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4
+
Index: soft/giet_vm/applications/rosenfeld/nrc2/src/nrarith2.c
===================================================================
--- soft/giet_vm/applications/rosenfeld/nrc2/src/nrarith2.c	(revision 820)
+++ soft/giet_vm/applications/rosenfeld/nrc2/src/nrarith2.c	(revision 821)
@@ -17,6 +17,6 @@
 #include <malloc.h>
 #include <math.h> // fabs
-// #include <memory.h> // memcpy
-
+
+#include "nrc_os_config.h"
 #include "mypredef.h"
 #include "nrtype.h"
@@ -25,5 +25,4 @@
 #include "nrkernel.h"
 
-#include "nrarith1.h"
 #include "nrarith2.h"
 
@@ -32,144 +31,30 @@
 /* ------------------ */
 
-/* ----------------------------------------------------------------------------- */
-IMAGE_EXPORT(sint8) min_si8matrix(sint8 **m, long nrl, long nrh, long ncl, long nch)
-/* ----------------------------------------------------------------------------- */
-{
-	int i, j;
-	sint8 minimum = m[nrl][ncl];
-	    
-	for(i=nrl; i<=nrh; i++) {
-		for(j=ncl; j<=nch; j++) {
-			if(m[i][j]<minimum) minimum = m[i][j];
-		}
-	}
-	return minimum;
-}
-/* ------------------------------------------------------------------------------ */
-IMAGE_EXPORT(uint8) min_ui8matrix(uint8 **m, long nrl, long nrh, long ncl, long nch)
-/* ------------------------------------------------------------------------------ */
-{
-	int i, j;
-	uint8 minimum = m[nrl][ncl];
-	    
-	for(i=nrl; i<=nrh; i++) {
-		for(j=ncl; j<=nch; j++) {
-			if(m[i][j]<minimum) minimum = m[i][j];
-		}
-	}
-	return minimum;
-}
-/* --------------------------------------------------------------------------------- */
-IMAGE_EXPORT(sint16) min_si16matrix(sint16 **m, long nrl, long nrh, long ncl, long nch)
-/* --------------------------------------------------------------------------------- */
-{
-	int i, j;
-	sint16 minimum = m[nrl][ncl];
-	
-	for(i=nrl; i<=nrh; i++) {
-		for(j=ncl; j<=nch; j++) {
-			if(m[i][j]<minimum) minimum = m[i][j];
-		}
-	}
-	return minimum;
-}
-/* --------------------------------------------------------------------------------- */
-IMAGE_EXPORT(uint16) min_ui16matrix(uint16 **m, long nrl, long nrh, long ncl, long nch)
-/* --------------------------------------------------------------------------------- */
-{
-	int i, j;
-	uint16 minimum = m[nrl][ncl];
-	
-	for(i=nrl; i<=nrh; i++) {
-		for(j=ncl; j<=nch; j++) {
-			if(m[i][j]<minimum) minimum = m[i][j];
-		}
-	}
-	return minimum;
-}
-/* --------------------------------------------------------------------------------- */
-IMAGE_EXPORT(sint32) min_si32matrix(sint32 **m, long nrl, long nrh, long ncl, long nch)
-/* --------------------------------------------------------------------------------- */
-{
-	int i, j;
-	sint32 minimum = m[nrl][ncl];
-	
-	for(i=nrl; i<=nrh; i++) {
-		for(j=ncl; j<=nch; j++) {
-			if(m[i][j]<minimum) minimum = m[i][j];
-		}
-	}
-	return minimum;
-}
-/* --------------------------------------------------------------------------------- */
-IMAGE_EXPORT(uint32) min_ui32matrix(uint32 **m, long nrl, long nrh, long ncl, long nch)
-/* --------------------------------------------------------------------------------- */
-{
-	int i, j;
-	uint32 minimum = m[nrl][ncl];
-	
-	for(i=nrl; i<=nrh; i++) {
-		for(j=ncl; j<=nch; j++) {
-			if(m[i][j]<minimum) minimum = m[i][j];
-		}
-	}
-	return minimum;
-}
-/* --------------------------------------------------------------------------------- */
-IMAGE_EXPORT(sint64) min_si64matrix(sint64 **m, long nrl, long nrh, long ncl, long nch)
-/* --------------------------------------------------------------------------------- */
-{
-	int i, j;
-	sint64 minimum = m[nrl][ncl];
-	
-	for(i=nrl; i<=nrh; i++) {
-		for(j=ncl; j<=nch; j++) {
-			if(m[i][j]<minimum) minimum = m[i][j];
-		}
-	}
-	return minimum;
-}
-/* --------------------------------------------------------------------------------- */
-IMAGE_EXPORT(uint64) min_ui64matrix(uint64 **m, long nrl, long nrh, long ncl, long nch)
-/* --------------------------------------------------------------------------------- */
-{
-	int i, j;
-	uint64 minimum = m[nrl][ncl];
-	
-	for(i=nrl; i<=nrh; i++) {
-		for(j=ncl; j<=nch; j++) {
-			if(m[i][j]<minimum) minimum = m[i][j];
-		}
-	}
-	return minimum;
-}
-/* ---------------------------------------------------------------------------------- */
-IMAGE_EXPORT(float32) min_f32matrix(float32 **m, long nrl, long nrh, long ncl, long nch)
-/* ---------------------------------------------------------------------------------- */
-{
-	int i, j;
-	float32 minimum = m[nrl][ncl];
-	
-	for(i=nrl; i<=nrh; i++) {
-		for(j=ncl; j<=nch; j++) {
-			if(m[i][j]<minimum) minimum = m[i][j];
-		}
-	}
-	return minimum;
-}
-/* ---------------------------------------------------------------------------------- */
-IMAGE_EXPORT(float64) min_f64matrix(float64 **m, long nrl, long nrh, long ncl, long nch)
-/* ---------------------------------------------------------------------------------- */
-{
-	int i, j;
-	float64 minimum = m[nrl][ncl];
-	
-	for(i=nrl; i<=nrh; i++) {
-		for(j=ncl; j<=nch; j++) {
-			if(m[i][j]<minimum) minimum = m[i][j];
-		}
-	}
-	return minimum;
-}
+#undef min_type_matrix
+#define min_type_matrix(t) \
+t short_name(t,min_,matrix)(t ** m, int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch) \
+{                                                                                       \
+    t minimum = m[nrl][nrh];                                                            \
+    for (int32_t i = nrl; i <= nrh; i++) {                                              \
+        for (int32_t j = ncl; j <= nch; j++) {                                          \
+            if (m[i][j] < minimum) {                                                    \
+                minimum = m[i][j];                                                      \
+            }                                                                           \
+        }                                                                               \
+    }                                                                                   \
+    return minimum;                                                                     \
+}
+
+min_type_matrix(int8_t);
+min_type_matrix(uint8_t);
+min_type_matrix(int16_t);
+min_type_matrix(uint16_t);
+min_type_matrix(int32_t);
+min_type_matrix(uint32_t);
+min_type_matrix(int64_t);
+min_type_matrix(uint64_t);
+min_type_matrix(float);
+min_type_matrix(double);
+
 
 /* ------------------ */
@@ -177,157 +62,31 @@
 /* ------------------ */
 
-/* ----------------------------------------------------------------------------- */
-IMAGE_EXPORT(sint8) max_si8matrix(sint8 **m, long nrl, long nrh, long ncl, long nch)
-/* ----------------------------------------------------------------------------- */
-{
-	int i, j;
-	sint8 minimum = m[nrl][ncl];
-	    
-	for(i=nrl; i<=nrh; i++) {
-		for(j=ncl; j<=nch; j++) {
-			if(m[i][j]>minimum) minimum = m[i][j];
-		}
-	}
-	return minimum;
-}
-/* ------------------------------------------------------------------------------ */
-IMAGE_EXPORT(uint8) max_ui8matrix(uint8 **m, long nrl, long nrh, long ncl, long nch)
-/* ------------------------------------------------------------------------------ */
-{
-	int i, j;
-	uint8 minimum = m[nrl][ncl];
-	    
-	for(i=nrl; i<=nrh; i++) {
-		for(j=ncl; j<=nch; j++) {
-			if(m[i][j]>minimum) minimum = m[i][j];
-		}
-	}
-	return minimum;
-}
-/* --------------------------------------------------------------------------------- */
-IMAGE_EXPORT(sint16) max_si16matrix(sint16 **m, long nrl, long nrh, long ncl, long nch)
-/* --------------------------------------------------------------------------------- */
-{
-	int i, j;
-	sint16 minimum = m[nrl][ncl];
-	
-	for(i=nrl; i<=nrh; i++) {
-		for(j=ncl; j<=nch; j++) {
-			if(m[i][j]>minimum) minimum = m[i][j];
-		}
-	}
-	return minimum;
-}
-/* --------------------------------------------------------------------------------- */
-IMAGE_EXPORT(uint16) max_ui16matrix(uint16 **m, long nrl, long nrh, long ncl, long nch)
-/* --------------------------------------------------------------------------------- */
-{
-	int i, j;
-	uint16 minimum = m[nrl][ncl];
-	
-	for(i=nrl; i<=nrh; i++) {
-		for(j=ncl; j<=nch; j++) {
-			if(m[i][j]>minimum) minimum = m[i][j];
-		}
-	}
-	return minimum;
-}
-/* --------------------------------------------------------------------------------- */
-IMAGE_EXPORT(sint32) max_si32matrix(sint32 **m, long nrl, long nrh, long ncl, long nch)
-/* --------------------------------------------------------------------------------- */
-{
-	int i, j;
-	sint32 minimum = m[nrl][ncl];
-	
-	for(i=nrl; i<=nrh; i++) {
-		for(j=ncl; j<=nch; j++) {
-			if(m[i][j]>minimum) minimum = m[i][j];
-		}
-	}
-	return minimum;
-}
-/* --------------------------------------------------------------------------------- */
-IMAGE_EXPORT(uint32) max_ui32matrix(uint32 **m, long nrl, long nrh, long ncl, long nch)
-/* --------------------------------------------------------------------------------- */
-{
-	int i, j;
-	uint32 minimum = m[nrl][ncl];
-	
-	for(i=nrl; i<=nrh; i++) {
-		for(j=ncl; j<=nch; j++) {
-			if(m[i][j]>minimum) minimum = m[i][j];
-		}
-	}
-	return minimum;
-}
-/* --------------------------------------------------------------------------------- */
-IMAGE_EXPORT(sint64) max_si64matrix(sint64 **m, long nrl, long nrh, long ncl, long nch)
-/* --------------------------------------------------------------------------------- */
-{
-	int i, j;
-	sint64 minimum = m[nrl][ncl];
-	
-	for(i=nrl; i<=nrh; i++) {
-		for(j=ncl; j<=nch; j++) {
-			if(m[i][j]>minimum) minimum = m[i][j];
-		}
-	}
-	return minimum;
-}
-/* --------------------------------------------------------------------------------- */
-IMAGE_EXPORT(uint64) max_ui64matrix(uint64 **m, long nrl, long nrh, long ncl, long nch)
-/* --------------------------------------------------------------------------------- */
-{
-	int i, j;
-	uint64 minimum = m[nrl][ncl];
-	
-	for(i=nrl; i<=nrh; i++) {
-		for(j=ncl; j<=nch; j++) {
-			if(m[i][j]>minimum) minimum = m[i][j];
-		}
-	}
-	return minimum;
-}
-/* ---------------------------------------------------------------------------------- */
-IMAGE_EXPORT(float32) max_f32matrix(float32 **m, long nrl, long nrh, long ncl, long nch)
-/* ---------------------------------------------------------------------------------- */
-{
-	int i, j;
-	float32 minimum = m[nrl][ncl];
-	
-	for(i=nrl; i<=nrh; i++) {
-		for(j=ncl; j<=nch; j++) {
-			if(m[i][j]>minimum) minimum = m[i][j];
-		}
-	}
-	return minimum;
-}
-/* ---------------------------------------------------------------------------------- */
-IMAGE_EXPORT(float64) max_f64matrix(float64 **m, long nrl, long nrh, long ncl, long nch)
-/* ---------------------------------------------------------------------------------- */
-{
-	int i, j;
-	float64 minimum = m[nrl][ncl];
-	
-	for(i=nrl; i<=nrh; i++) {
-		for(j=ncl; j<=nch; j++) {
-			if(m[i][j]>minimum) minimum = m[i][j];
-		}
-	}
-	return minimum;
-}
-
-/* -------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) add_si8matrix(sint8 **X, long nrl,long nrh, long ncl, long nch, sint8 **Y, sint8 **Z)
-/* -------------------------------------------------------------------------------------------------- */
-{
-	long i, j;
-	
-	for(i=nrl; i<=nrh; i++) {
-		for(j=ncl; j<=nch; j++) {
-			Z[i][j] = X[i][j] + Y[i][j];
-		}
-	}
-}
+#undef max_type_matrix
+#define max_type_matrix(t) \
+t short_name(t,max_,matrix)(t ** m, int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch) \
+{                                                                                       \
+    t maximum = m[nrl][nrh];                                                            \
+    for (int32_t i = nrl; i <= nrh; i++) {                                              \
+        for (int32_t j = ncl; j <= nch; j++) {                                          \
+            if (m[i][j] > maximum) {                                                    \
+                maximum = m[i][j];                                                      \
+            }                                                                           \
+        }                                                                               \
+    }                                                                                   \
+    return maximum;                                                                     \
+}
+
+max_type_matrix(int8_t);
+max_type_matrix(uint8_t);
+max_type_matrix(int16_t);
+max_type_matrix(uint16_t);
+max_type_matrix(int32_t);
+max_type_matrix(uint32_t);
+max_type_matrix(int64_t);
+max_type_matrix(uint64_t);
+max_type_matrix(float);
+max_type_matrix(double);
+
+
 
 /* ------------------ */
@@ -335,145 +94,50 @@
 /* ------------------ */
 
-/* -------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) add_ui8matrix(uint8 **X, long nrl,long nrh, long ncl, long nch, uint8 **Y, uint8 **Z)
-/* -------------------------------------------------------------------------------------------------- */
-{
-	long i, j;
-	
-	for(i=nrl; i<=nrh; i++) {
-		for(j=ncl; j<=nch; j++) {
-			Z[i][j] = X[i][j] + Y[i][j];
-		}
-	}
-}
-/* ------------------------------------------------------------------------------------------------------ */
-IMAGE_EXPORT(void) add_si16matrix(sint16 **X, long nrl,long nrh, long ncl, long nch, sint16 **Y, sint16 **Z)
-/* ------------------------------------------------------------------------------------------------------ */
-{
-	long i, j;
-	
-	for(i=nrl; i<=nrh; i++) {
-		for(j=ncl; j<=nch; j++) {
-			Z[i][j] = X[i][j] + Y[i][j];
-		}
-	}
-}
-/* ------------------------------------------------------------------------------------------------------ */
-IMAGE_EXPORT(void) add_ui16matrix(uint16 **X, long nrl,long nrh, long ncl, long nch, uint16 **Y, uint16 **Z)
-/* ------------------------------------------------------------------------------------------------------ */
-{
-	long i, j;
-	
-	for(i=nrl; i<=nrh; i++) {
-		for(j=ncl; j<=nch; j++) {
-			Z[i][j] = X[i][j] + Y[i][j];
-		}
-	}
-}
-/* ------------------------------------------------------------------------------------------------------ */
-IMAGE_EXPORT(void) add_si32matrix(sint32 **X, long nrl,long nrh, long ncl, long nch, sint32 **Y, sint32 **Z)
-/* ------------------------------------------------------------------------------------------------------ */
-{
-	long i, j;
-	
-	for(i=nrl; i<=nrh; i++) {
-		for(j=ncl; j<=nch; j++) {
-			Z[i][j] = X[i][j] + Y[i][j];
-		}
-	}
-}
-/* ------------------------------------------------------------------------------------------------------ */
-IMAGE_EXPORT(void) add_ui32matrix(uint32 **X, long nrl,long nrh, long ncl, long nch, uint32 **Y, uint32 **Z)
-/* ------------------------------------------------------------------------------------------------------ */
-{
-	long i, j;
-	
-	for(i=nrl; i<=nrh; i++) {
-		for(j=ncl; j<=nch; j++) {
-			Z[i][j] = X[i][j] + Y[i][j];
-		}
-	}
-}
-/* ------------------------------------------------------------------------------------------------------ */
-IMAGE_EXPORT(void) add_si64matrix(sint64 **X, long nrl,long nrh, long ncl, long nch, sint64 **Y, sint64 **Z)
-/* ------------------------------------------------------------------------------------------------------ */
-{
-	long i, j;
-	
-	for(i=nrl; i<=nrh; i++) {
-		for(j=ncl; j<=nch; j++) {
-			Z[i][j] = X[i][j] + Y[i][j];
-		}
-	}
-}
-/* ------------------------------------------------------------------------------------------------------ */
-IMAGE_EXPORT(void) add_ui64matrix(uint64 **X, long nrl,long nrh, long ncl, long nch, uint64 **Y, uint64 **Z)
-/* ------------------------------------------------------------------------------------------------------ */
-{
-	long i, j;
-	
-	for(i=nrl; i<=nrh; i++) {
-		for(j=ncl; j<=nch; j++) {
-			Z[i][j] = X[i][j] + Y[i][j];
-		}
-	}
-}
-/* -------------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) add_f32matrix(float32 **X, long nrl,long nrh, long ncl, long nch, float32 **Y, float32 **Z)
-/* -------------------------------------------------------------------------------------------------------- */
-{
-	long i, j;
-	
-	for(i=nrl; i<=nrh; i++) {
-		for(j=ncl; j<=nch; j++) {
-			Z[i][j] = X[i][j] + Y[i][j];
-		}
-	}
-}
-/* -------------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) add_f64matrix(float64 **X, long nrl,long nrh, long ncl, long nch, float64 **Y, float64 **Z)
-/* -------------------------------------------------------------------------------------------------------- */
-{
-	long i, j;
-	
-	for(i=nrl; i<=nrh; i++) {
-		for(j=ncl; j<=nch; j++) {
-			Z[i][j] = X[i][j] + Y[i][j];
-		}
-	}
-}
+
+#undef add_type_matrix
+#define add_type_matrix(t) \
+void short_name(t,add_,matrix)(t ** X, int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch, t ** Y, t ** Z) \
+{                                                                                                          \
+    for (int32_t i = nrl; i <= nrh; i++) {                                                                 \
+        for (int32_t j = ncl; j <= nch; j++) {                                                             \
+            Z[i][j] = X[i][j] + Y[i][j];                                                                   \
+        }                                                                                                  \
+    }                                                                                                      \
+}
+
+add_type_matrix(int8_t);
+add_type_matrix(uint8_t);
+add_type_matrix(int16_t);
+add_type_matrix(uint16_t);
+add_type_matrix(int32_t);
+add_type_matrix(uint32_t);
+add_type_matrix(int64_t);
+add_type_matrix(uint64_t);
+add_type_matrix(float);
+add_type_matrix(double);
+
+
 /* ----------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) add_rgb8matrix(rgb8 **X, long nrl,long nrh,long ncl, long nch, rgb8 **Y, rgb8 **Z)
+void add_rgb8matrix(rgb8 ** X, int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch, rgb8 ** Y, rgb8 ** Z)
 /* ----------------------------------------------------------------------------------------------- */
 {
-	long i, j;
-	rgb8 x, y, z;
-	
-	for(i=nrl; i<=nrh; i++) {
-		for(j=ncl; j<=nch; j++) {
-			x = X[i][j];
-			y = Y[i][j];
-			//z = x + y;
-			RGB8_ADD(x,y,z);
-			Z[i][j] = z;
-		}
-	}
-}
+    for (int32_t i = nrl; i <= nrh; i++) {
+        for (int32_t j = ncl; j <= nch; j++) {
+            //z = x + y;
+            RGB8_ADD(X[i][j], Y[i][j], Z[i][j]);
+        }
+    }
+}
+
 /* --------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) add_rgbx8matrix(rgbx8 **X, long nrl,long nrh,long ncl, long nch, rgbx8 **Y, rgbx8 **Z)
+void add_rgbx8matrix(rgbx8 ** X, int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch, rgbx8 ** Y, rgbx8 ** Z)
 /* --------------------------------------------------------------------------------------------------- */
 {
-	long i, j;
-	rgbx8 x, y, z;
-	
-	for(i=nrl; i<=nrh; i++) {
-		for(j=ncl; j<=nch; j++) {
-			x = X[i][j];
-			y = Y[i][j];
-			//z = x + y;
-			RGBX8_ADD(x,y,z);
-			Z[i][j] = z;
-		}
-	}
+    for (int32_t i = nrl; i <= nrh; i++) {
+        for (int32_t j = ncl; j <= nch; j++) {
+            //z = x + y;
+            RGBX8_ADD(X[i][j], Y[i][j], Z[i][j]);
+        }
+    }
 }
 
@@ -482,298 +146,102 @@
 /* -------------------- */
 
-/* ------------------------------------------------------------------------------------------------ */
-IMAGE_EXPORT(void) addc_si8matrix(sint8 **X,long nrl,long nrh, long ncl, long nch, sint8 y, sint8 **Z)
-/* ------------------------------------------------------------------------------------------------ */
-{
-	long i,j;
-	
-	for(i=nrl; i<=nrh; i++) {
-		for(j=ncl; j<=nch; j++) {
-            Z[i][j] = X[i][j] + y;
-		}
-	}
-}
-/* ------------------------------------------------------------------------------------------------ */
-IMAGE_EXPORT(void) addc_ui8matrix(uint8 **X,long nrl,long nrh, long ncl, long nch, uint8 y, uint8 **Z)
-/* ------------------------------------------------------------------------------------------------ */
-{
-	long i,j;
-	
-	for(i=nrl; i<=nrh; i++) {
-		for(j=ncl; j<=nch; j++) {
-            Z[i][j] = X[i][j] + y;
-		}
-	}
-}
-/* ---------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) addc_si16matrix(sint16 **X,long nrl,long nrh, long ncl, long nch, sint16 y, sint16 **Z)
-/* ---------------------------------------------------------------------------------------------------- */
-{
-	long i,j;
-	
-	for(i=nrl; i<=nrh; i++) {
-		for(j=ncl; j<=nch; j++) {
-            Z[i][j] = X[i][j] + y;
-		}
-	}
-}
-/* ---------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) addc_ui16matrix(uint16 **X,long nrl,long nrh, long ncl, long nch, uint16 y, uint16 **Z)
-/* ---------------------------------------------------------------------------------------------------- */
-{
-	long i,j;
-	
-	for(i=nrl; i<=nrh; i++) {
-		for(j=ncl; j<=nch; j++) {
-            Z[i][j] = X[i][j] + y;
-		}
-	}
-}
-/* ---------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) addc_si32matrix(sint32 **X,long nrl,long nrh, long ncl, long nch, sint32 y, sint32 **Z)
-/* ---------------------------------------------------------------------------------------------------- */
-{
-	long i,j;
-	
-	for(i=nrl; i<=nrh; i++) {
-		for(j=ncl; j<=nch; j++) {
-            Z[i][j] = X[i][j] + y;
-		}
-	}
-}
-/* ---------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) addc_ui32matrix(uint32 **X,long nrl,long nrh, long ncl, long nch, uint32 y, uint32 **Z)
-/* ---------------------------------------------------------------------------------------------------- */
-{
-	long i,j;
-	
-	for(i=nrl; i<=nrh; i++) {
-		for(j=ncl; j<=nch; j++) {
-            Z[i][j] = X[i][j] + y;
-		}
-	}
-}
-/* ---------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) addc_si64matrix(sint64 **X,long nrl,long nrh, long ncl, long nch, sint64 y, sint64 **Z)
-/* ---------------------------------------------------------------------------------------------------- */
-{
-	long i,j;
-	
-	for(i=nrl; i<=nrh; i++) {
-		for(j=ncl; j<=nch; j++) {
-            Z[i][j] = X[i][j] + y;
-		}
-	}
-}
-/* ---------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) addc_ui64matrix(uint64 **X,long nrl,long nrh, long ncl, long nch, uint64 y, uint64 **Z)
-/* ---------------------------------------------------------------------------------------------------- */
-{
-	long i,j;
-	
-	for(i=nrl; i<=nrh; i++) {
-		for(j=ncl; j<=nch; j++) {
-            Z[i][j] = X[i][j] + y;
-		}
-	}
-}
-/* ------------------------------------------------------------------------------------------------------ */
-IMAGE_EXPORT(void) addc_f32matrix(float32 **X,long nrl,long nrh, long ncl, long nch, float32 y, float32 **Z)
-/* ------------------------------------------------------------------------------------------------------ */
-{
-	long i,j;
-	
-	for(i=nrl; i<=nrh; i++) {
-		for(j=ncl; j<=nch; j++) {
-            Z[i][j] = X[i][j] + y;
-		}
-	}
-}
-/* ------------------------------------------------------------------------------------------------------ */
-IMAGE_EXPORT(void) addc_f64matrix(float64 **X,long nrl,long nrh, long ncl, long nch, float64 y, float64 **Z)
-/* ------------------------------------------------------------------------------------------------------ */
-{
-	long i,j;
-	
-	for(i=nrl; i<=nrh; i++) {
-		for(j=ncl; j<=nch; j++) {
-            Z[i][j] = X[i][j] + y;
-		}
-	}
-}
-/* ---------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) addc_rgb8matrix(rgb8 **X,long nrl,long nrh, long ncl, long nch, rgb8 y, rgb8 **Z)
-/* ---------------------------------------------------------------------------------------------- */
-{
-	long i,j;
-    rgb8 x, z;
-	
-	for(i=nrl; i<=nrh; i++) {
-		for(j=ncl; j<=nch; j++) {
-            x = X[i][j];
-            RGB8_ADD(x,y,z);
-            Z[i][j] = z;
-		}
-	}
-}
-/* -------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) addc_rgbx8matrix(rgbx8 **X,long nrl,long nrh, long ncl, long nch, rgbx8 y, rgbx8 **Z)
-/* -------------------------------------------------------------------------------------------------- */
-{
-	long i,j;
-    rgbx8 x, z;
-	
-	for(i=nrl; i<=nrh; i++) {
-		for(j=ncl; j<=nch; j++) {
-            x = X[i][j];
-            RGBX8_ADD(x,y,z);
-            Z[i][j] = z;
-		}
-	}
-}
-/* ------------------ */
-/* --- Add Matrix --- */
-/* ------------------ */
-
-/* -------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) sub_ui8matrix(uint8 **X, long nrl,long nrh, long ncl, long nch, uint8 **Y, uint8 **Z)
-/* -------------------------------------------------------------------------------------------------- */
-{
-	long i, j;
-	
-	for(i=nrl; i<=nrh; i++) {
-		for(j=ncl; j<=nch; j++) {
-			Z[i][j] = X[i][j] - Y[i][j];
-		}
-	}
-}
-/* ------------------------------------------------------------------------------------------------------ */
-IMAGE_EXPORT(void) sub_si16matrix(sint16 **X, long nrl,long nrh, long ncl, long nch, sint16 **Y, sint16 **Z)
-/* ------------------------------------------------------------------------------------------------------ */
-{
-	long i, j;
-	
-	for(i=nrl; i<=nrh; i++) {
-		for(j=ncl; j<=nch; j++) {
-			Z[i][j] = X[i][j] - Y[i][j];
-		}
-	}
-}
-/* ------------------------------------------------------------------------------------------------------ */
-IMAGE_EXPORT(void) sub_ui16matrix(uint16 **X, long nrl,long nrh, long ncl, long nch, uint16 **Y, uint16 **Z)
-/* ------------------------------------------------------------------------------------------------------ */
-{
-	long i, j;
-	
-	for(i=nrl; i<=nrh; i++) {
-		for(j=ncl; j<=nch; j++) {
-			Z[i][j] = X[i][j] - Y[i][j];
-		}
-	}
-}
-/* ------------------------------------------------------------------------------------------------------ */
-IMAGE_EXPORT(void) sub_si32matrix(sint32 **X, long nrl,long nrh, long ncl, long nch, sint32 **Y, sint32 **Z)
-/* ------------------------------------------------------------------------------------------------------ */
-{
-	long i, j;
-	
-	for(i=nrl; i<=nrh; i++) {
-		for(j=ncl; j<=nch; j++) {
-			Z[i][j] = X[i][j] - Y[i][j];
-		}
-	}
-}
-/* ------------------------------------------------------------------------------------------------------ */
-IMAGE_EXPORT(void) sub_ui32matrix(uint32 **X, long nrl,long nrh, long ncl, long nch, uint32 **Y, uint32 **Z)
-/* ------------------------------------------------------------------------------------------------------ */
-{
-	long i, j;
-	
-	for(i=nrl; i<=nrh; i++) {
-		for(j=ncl; j<=nch; j++) {
-			Z[i][j] = X[i][j] - Y[i][j];
-		}
-	}
-}
-/* ------------------------------------------------------------------------------------------------------ */
-IMAGE_EXPORT(void) sub_si64matrix(sint64 **X, long nrl,long nrh, long ncl, long nch, sint64 **Y, sint64 **Z)
-/* ------------------------------------------------------------------------------------------------------ */
-{
-	long i, j;
-	
-	for(i=nrl; i<=nrh; i++) {
-		for(j=ncl; j<=nch; j++) {
-			Z[i][j] = X[i][j] - Y[i][j];
-		}
-	}
-}
-/* ------------------------------------------------------------------------------------------------------ */
-IMAGE_EXPORT(void) sub_ui64matrix(uint64 **X, long nrl,long nrh, long ncl, long nch, uint64 **Y, uint64 **Z)
-/* ------------------------------------------------------------------------------------------------------ */
-{
-	long i, j;
-	
-	for(i=nrl; i<=nrh; i++) {
-		for(j=ncl; j<=nch; j++) {
-			Z[i][j] = X[i][j] - Y[i][j];
-		}
-	}
-}
-/* -------------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) sub_f32matrix(float32 **X, long nrl,long nrh, long ncl, long nch, float32 **Y, float32 **Z)
-/* -------------------------------------------------------------------------------------------------------- */
-{
-	long i, j;
-	
-	for(i=nrl; i<=nrh; i++) {
-		for(j=ncl; j<=nch; j++) {
-			Z[i][j] = X[i][j] - Y[i][j];
-		}
-	}
-}
-/* -------------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) sub_f64matrix(float64 **X, long nrl,long nrh, long ncl, long nch, float64 **Y, float64 **Z)
-/* -------------------------------------------------------------------------------------------------------- */
-{
-	long i, j;
-	
-	for(i=nrl; i<=nrh; i++) {
-		for(j=ncl; j<=nch; j++) {
-			Z[i][j] = X[i][j] - Y[i][j];
-		}
-	}
-}
+#undef addc_type_matrix
+#define addc_type_matrix(t) \
+void short_name(t,addc_,matrix)(t ** X, int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch, t y, t ** Z) \
+{                                                                                                        \
+    for (int32_t i = nrl; i <= nrh; i++) {                                                               \
+        for (int32_t j = ncl; j <= nch; j++) {                                                           \
+            Z[i][j] = X[i][j] + y;                                                                       \
+        }                                                                                                \
+    }                                                                                                    \
+}
+
+addc_type_matrix(int8_t);
+addc_type_matrix(uint8_t);
+addc_type_matrix(int16_t);
+addc_type_matrix(uint16_t);
+addc_type_matrix(int32_t);
+addc_type_matrix(uint32_t);
+addc_type_matrix(int64_t);
+addc_type_matrix(uint64_t);
+addc_type_matrix(float);
+addc_type_matrix(double);
+
+
+
+/* ---------------------------------------------------------------------------------------------- */
+void addc_rgb8matrix(rgb8 ** X, int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch, rgb8 y, rgb8 ** Z)
+/* ---------------------------------------------------------------------------------------------- */
+{
+    for (int32_t i = nrl; i <= nrh; i++) {
+        for (int32_t j = ncl; j <= nch; j++) {
+            RGB8_ADD(X[i][j], y, Z[i][j]);
+        }
+    }
+}
+
+/* -------------------------------------------------------------------------------------------------- */
+void addc_rgbx8matrix(rgbx8 ** X, int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch, rgbx8 y, rgbx8 ** Z)
+/* -------------------------------------------------------------------------------------------------- */
+{
+    for (int32_t i = nrl; i <= nrh; i++) {
+        for (int32_t j = ncl; j <= nch; j++) {
+            RGBX8_ADD(X[i][j], y, Z[i][j]);
+        }
+    }
+}
+
+
+/* ------------------ */
+/* --- Sub Matrix --- */
+/* ------------------ */
+
+#undef sub_type_matrix
+#define sub_type_matrix(t) \
+void short_name(t,sub_,matrix)(t ** X, int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch, t ** Y, t ** Z) \
+{                                                                                                          \
+    for (int32_t i = nrl; i <= nrh; i++) {                                                                 \
+        for (int32_t j = ncl; j <= nch; j++) {                                                             \
+            Z[i][j] = X[i][j] - Y[i][j];                                                                   \
+        }                                                                                                  \
+    }                                                                                                      \
+}
+
+sub_type_matrix(int8_t);
+sub_type_matrix(uint8_t);
+sub_type_matrix(int16_t);
+sub_type_matrix(uint16_t);
+sub_type_matrix(int32_t);
+sub_type_matrix(uint32_t);
+sub_type_matrix(int64_t);
+sub_type_matrix(uint64_t);
+sub_type_matrix(float);
+sub_type_matrix(double);
+
+
 /* ----------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) sub_rgb8matrix(rgb8 **X, long nrl,long nrh,long ncl, long nch, rgb8 **Y, rgb8 **Z)
+void sub_rgb8matrix(rgb8 ** X, int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch, rgb8 ** Y, rgb8 ** Z)
 /* ----------------------------------------------------------------------------------------------- */
 {
-	long i, j;
-	rgb8 x, y, z;
-	
-	for(i=nrl; i<=nrh; i++) {
-		for(j=ncl; j<=nch; j++) {
-			x = X[i][j];
-			y = Y[i][j];
-			RGB8_SUB(x,y,z);
-			Z[i][j] = z;
-		}
-	}
-}
+    for (int32_t i = nrl; i <= nrh; i++) {
+        for (int32_t j = ncl; j <= nch; j++) {
+            //z = x + y;
+            RGB8_SUB(X[i][j], Y[i][j], Z[i][j]);
+        }
+    }
+}
+
 /* --------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) sub_rgbx8matrix(rgbx8 **X, long nrl,long nrh,long ncl, long nch, rgbx8 **Y, rgbx8 **Z)
+void sub_rgbx8matrix(rgbx8 ** X, int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch, rgbx8 ** Y, rgbx8 ** Z)
 /* --------------------------------------------------------------------------------------------------- */
 {
-	long i, j;
-	rgbx8 x, y, z;
-	
-	for(i=nrl; i<=nrh; i++) {
-		for(j=ncl; j<=nch; j++) {
-			x = X[i][j];
-			y = Y[i][j];
-			RGBX8_SUB(x,y,z);
-			Z[i][j] = z;
-		}
-	}
-}
+    for (int32_t i = nrl; i <= nrh; i++) {
+        for (int32_t j = ncl; j <= nch; j++) {
+            //z = x + y;
+            RGBX8_SUB(X[i][j], Y[i][j], Z[i][j]);
+        }
+    }
+}
+
 
 /* -------------------- */
@@ -781,469 +249,164 @@
 /* -------------------- */
 
-/* ------------------------------------------------------------------------------------------------ */
-IMAGE_EXPORT(void) subc_si8matrix(sint8 **X,long nrl,long nrh, long ncl, long nch, sint8 y, sint8 **Z)
-/* ------------------------------------------------------------------------------------------------ */
-{
-	long i,j;
-	
-	for(i=nrl; i<=nrh; i++) {
-		for(j=ncl; j<=nch; j++) {
-            Z[i][j] = X[i][j] - y;
-		}
-	}
-}
-/* ------------------------------------------------------------------------------------------------ */
-IMAGE_EXPORT(void) subc_ui8matrix(uint8 **X,long nrl,long nrh, long ncl, long nch, uint8 y, uint8 **Z)
-/* ------------------------------------------------------------------------------------------------ */
-{
-	long i,j;
-	
-	for(i=nrl; i<=nrh; i++) {
-		for(j=ncl; j<=nch; j++) {
-            Z[i][j] = X[i][j] - y;
-		}
-	}
-}
-/* ---------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) subc_si16matrix(sint16 **X,long nrl,long nrh, long ncl, long nch, sint16 y, sint16 **Z)
-/* ---------------------------------------------------------------------------------------------------- */
-{
-	long i,j;
-	
-	for(i=nrl; i<=nrh; i++) {
-		for(j=ncl; j<=nch; j++) {
-            Z[i][j] = X[i][j] - y;
-		}
-	}
-}
-/* ---------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) subc_ui16matrix(uint16 **X,long nrl,long nrh, long ncl, long nch, uint16 y, uint16 **Z)
-/* ---------------------------------------------------------------------------------------------------- */
-{
-	long i,j;
-	
-	for(i=nrl; i<=nrh; i++) {
-		for(j=ncl; j<=nch; j++) {
-            Z[i][j] = X[i][j] - y;
-		}
-	}
-}
-/* ---------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) subc_si32matrix(sint32 **X,long nrl,long nrh, long ncl, long nch, sint32 y, sint32 **Z)
-/* ---------------------------------------------------------------------------------------------------- */
-{
-	long i,j;
-	
-	for(i=nrl; i<=nrh; i++) {
-		for(j=ncl; j<=nch; j++) {
-            Z[i][j] = X[i][j] - y;
-		}
-	}
-}
-/* ---------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) subc_ui32matrix(uint32 **X,long nrl,long nrh, long ncl, long nch, uint32 y, uint32 **Z)
-/* ---------------------------------------------------------------------------------------------------- */
-{
-	long i,j;
-	
-	for(i=nrl; i<=nrh; i++) {
-		for(j=ncl; j<=nch; j++) {
-            Z[i][j] = X[i][j] - y;
-		}
-	}
-}
-/* ---------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) subc_si64matrix(sint64 **X,long nrl,long nrh, long ncl, long nch, sint64 y, sint64 **Z)
-/* ---------------------------------------------------------------------------------------------------- */
-{
-	long i,j;
-	
-	for(i=nrl; i<=nrh; i++) {
-		for(j=ncl; j<=nch; j++) {
-            Z[i][j] = X[i][j] - y;
-		}
-	}
-}
-/* ---------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) subc_ui64matrix(uint64 **X,long nrl,long nrh, long ncl, long nch, uint64 y, uint64 **Z)
-/* ---------------------------------------------------------------------------------------------------- */
-{
-	long i,j;
-	
-	for(i=nrl; i<=nrh; i++) {
-		for(j=ncl; j<=nch; j++) {
-            Z[i][j] = X[i][j] - y;
-		}
-	}
-}
-/* ------------------------------------------------------------------------------------------------------ */
-IMAGE_EXPORT(void) subc_f32matrix(float32 **X,long nrl,long nrh, long ncl, long nch, float32 y, float32 **Z)
-/* ------------------------------------------------------------------------------------------------------ */
-{
-	long i,j;
-	
-	for(i=nrl; i<=nrh; i++) {
-		for(j=ncl; j<=nch; j++) {
-            Z[i][j] = X[i][j] - y;
-		}
-	}
-}
-/* ------------------------------------------------------------------------------------------------------ */
-IMAGE_EXPORT(void) subc_f64matrix(float64 **X,long nrl,long nrh, long ncl, long nch, float64 y, float64 **Z)
-/* ------------------------------------------------------------------------------------------------------ */
-{
-	long i,j;
-	
-	for(i=nrl; i<=nrh; i++) {
-		for(j=ncl; j<=nch; j++) {
-            Z[i][j] = X[i][j] - y;
-		}
-	}
-}
-/* ---------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) subc_rgb8matrix(rgb8 **X,long nrl,long nrh, long ncl, long nch, rgb8 y, rgb8 **Z)
-/* ---------------------------------------------------------------------------------------------- */
-{
-	long i,j;
-    rgb8 x, z;
-	
-	for(i=nrl; i<=nrh; i++) {
-		for(j=ncl; j<=nch; j++) {
-            x = X[i][j];
-            RGB8_SUB(x,y,z);
-            Z[i][j] = z;
-		}
-	}
-}
-/* -------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) subc_rgbx8matrix(rgbx8 **X,long nrl,long nrh, long ncl, long nch, rgbx8 y, rgbx8 **Z)
-/* -------------------------------------------------------------------------------------------------- */
-{
-	long i,j;
-    rgbx8 x, z;
-	
-	for(i=nrl; i<=nrh; i++) {
-		for(j=ncl; j<=nch; j++) {
-            x = X[i][j];
-            RGBX8_SUB(x,y,z);
-            Z[i][j] = z;
-		}
-	}
-}
+#undef subc_type_matrix
+#define subc_type_matrix(t) \
+void short_name(t,subc_,matrix)(t ** X, int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch, t y, t ** Z) \
+{                                                                                                        \
+    for (int32_t i = nrl; i <= nrh; i++) {                                                               \
+        for (int32_t j = ncl; j <= nch; j++) {                                                           \
+            Z[i][j] = X[i][j] - y;                                                                       \
+        }                                                                                                \
+    }                                                                                                    \
+}
+
+subc_type_matrix(int8_t);
+subc_type_matrix(uint8_t);
+subc_type_matrix(int16_t);
+subc_type_matrix(uint16_t);
+subc_type_matrix(int32_t);
+subc_type_matrix(uint32_t);
+subc_type_matrix(int64_t);
+subc_type_matrix(uint64_t);
+subc_type_matrix(float);
+subc_type_matrix(double);
+
+
+
+/* ---------------------------------------------------------------------------------------------- */
+void subc_rgb8matrix(rgb8 ** X, int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch, rgb8 y, rgb8 ** Z)
+/* ---------------------------------------------------------------------------------------------- */
+{
+    for (int32_t i = nrl; i <= nrh; i++) {
+        for (int32_t j = ncl; j <= nch; j++) {
+            RGB8_SUB(X[i][j], y, Z[i][j]);
+        }
+    }
+}
+
+/* -------------------------------------------------------------------------------------------------- */
+void subc_rgbx8matrix(rgbx8 ** X, int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch, rgbx8 y, rgbx8 ** Z)
+/* -------------------------------------------------------------------------------------------------- */
+{
+    for (int32_t i = nrl; i <= nrh; i++) {
+        for (int32_t j = ncl; j <= nch; j++) {
+            RGBX8_SUB(X[i][j], y, Z[i][j]);
+        }
+    }
+}
+
+
 /* -------------------- */
 /* --- Mul constant --- */
 /* -------------------- */
 
-/* ------------------------------------------------------------------------------------------------ */
-IMAGE_EXPORT(void) mulc_si8matrix(sint8 **X,long nrl,long nrh, long ncl, long nch, sint8 y, sint8 **Z)
-/* ------------------------------------------------------------------------------------------------ */
-{
-	long i,j;
-	
-	for(i=nrl; i<=nrh; i++) {
-		for(j=ncl; j<=nch; j++) {
-            Z[i][j] = X[i][j] * y;
-		}
-	}
-}
-/* ------------------------------------------------------------------------------------------------ */
-IMAGE_EXPORT(void) mulc_ui8matrix(uint8 **X,long nrl,long nrh, long ncl, long nch, uint8 y, uint8 **Z)
-/* ------------------------------------------------------------------------------------------------ */
-{
-	long i,j;
-	
-	for(i=nrl; i<=nrh; i++) {
-		for(j=ncl; j<=nch; j++) {
-            Z[i][j] = X[i][j] * y;
-		}
-	}
-}
-/* ---------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) mulc_si16matrix(sint16 **X,long nrl,long nrh, long ncl, long nch, sint16 y, sint16 **Z)
-/* ---------------------------------------------------------------------------------------------------- */
-{
-	long i,j;
-	
-	for(i=nrl; i<=nrh; i++) {
-		for(j=ncl; j<=nch; j++) {
-            Z[i][j] = X[i][j] * y;
-		}
-	}
-}
-/* ---------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) mulc_ui16matrix(uint16 **X,long nrl,long nrh, long ncl, long nch, uint16 y, uint16 **Z)
-/* ---------------------------------------------------------------------------------------------------- */
-{
-	long i,j;
-	
-	for(i=nrl; i<=nrh; i++) {
-		for(j=ncl; j<=nch; j++) {
-            Z[i][j] = X[i][j] * y;
-		}
-	}
-}
-/* ---------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) mulc_si32matrix(sint32 **X,long nrl,long nrh, long ncl, long nch, sint32 y, sint32 **Z)
-/* ---------------------------------------------------------------------------------------------------- */
-{
-	long i,j;
-	
-	for(i=nrl; i<=nrh; i++) {
-		for(j=ncl; j<=nch; j++) {
-            Z[i][j] = X[i][j] * y;
-		}
-	}
-}
-/* ---------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) mulc_ui32matrix(uint32 **X,long nrl,long nrh, long ncl, long nch, uint32 y, uint32 **Z)
-/* ---------------------------------------------------------------------------------------------------- */
-{
-	long i,j;
-	
-	for(i=nrl; i<=nrh; i++) {
-		for(j=ncl; j<=nch; j++) {
-            Z[i][j] = X[i][j] * y;
-		}
-	}
-}
-/* ---------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) mulc_si64matrix(sint64 **X,long nrl,long nrh, long ncl, long nch, sint64 y, sint64 **Z)
-/* ---------------------------------------------------------------------------------------------------- */
-{
-	long i,j;
-	
-	for(i=nrl; i<=nrh; i++) {
-		for(j=ncl; j<=nch; j++) {
-            Z[i][j] = X[i][j] * y;
-		}
-	}
-}
-/* ---------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) mulc_ui64matrix(uint64 **X,long nrl,long nrh, long ncl, long nch, uint64 y, uint64 **Z)
-/* ---------------------------------------------------------------------------------------------------- */
-{
-	long i,j;
-	
-	for(i=nrl; i<=nrh; i++) {
-		for(j=ncl; j<=nch; j++) {
-            Z[i][j] = X[i][j] * y;
-		}
-	}
-}
-/* ------------------------------------------------------------------------------------------------------ */
-IMAGE_EXPORT(void) mulc_f32matrix(float32 **X,long nrl,long nrh, long ncl, long nch, float32 y, float32 **Z)
-/* ------------------------------------------------------------------------------------------------------ */
-{
-	long i,j;
-	
-	for(i=nrl; i<=nrh; i++) {
-		for(j=ncl; j<=nch; j++) {
-            Z[i][j] = X[i][j] * y;
-		}
-	}
-}
-/* ------------------------------------------------------------------------------------------------------ */
-IMAGE_EXPORT(void) mulc_f64matrix(float64 **X,long nrl,long nrh, long ncl, long nch, float64 y, float64 **Z)
-/* ------------------------------------------------------------------------------------------------------ */
-{
-	long i,j;
-	
-	for(i=nrl; i<=nrh; i++) {
-		for(j=ncl; j<=nch; j++) {
-            Z[i][j] = X[i][j] * y;
-		}
-	}
-}
-/* ---------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) mulc_rgb8matrix(rgb8 **X,long nrl,long nrh, long ncl, long nch, rgb8 y, rgb8 **Z)
-/* ---------------------------------------------------------------------------------------------- */
-{
-	long i,j;
-    rgb8 x, z;
-	
-	for(i=nrl; i<=nrh; i++) {
-		for(j=ncl; j<=nch; j++) {
-            x = X[i][j];
-            RGB8_MUL(x,y,z);
-            Z[i][j] = z;
-		}
-	}
-}
-/* -------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) mulc_rgbx8matrix(rgbx8 **X,long nrl,long nrh, long ncl, long nch, rgbx8 y, rgbx8 **Z)
-/* -------------------------------------------------------------------------------------------------- */
-{
-	long i,j;
-    rgbx8 x, z;
-	
-	for(i=nrl; i<=nrh; i++) {
-		for(j=ncl; j<=nch; j++) {
-            x = X[i][j];
-            RGBX8_MUL(x,y,z);
-            Z[i][j] = z;
-		}
-	}
-}
+#undef mulc_type_matrix
+#define mulc_type_matrix(t) \
+void short_name(t,mulc_,matrix)(t ** X, int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch, t y, t ** Z) \
+{                                                                                                        \
+    for (int32_t i = nrl; i <= nrh; i++) {                                                               \
+        for (int32_t j = ncl; j <= nch; j++) {                                                           \
+            Z[i][j] = X[i][j] * y;                                                                       \
+        }                                                                                                \
+    }                                                                                                    \
+}
+
+mulc_type_matrix(int8_t);
+mulc_type_matrix(uint8_t);
+mulc_type_matrix(int16_t);
+mulc_type_matrix(uint16_t);
+mulc_type_matrix(int32_t);
+mulc_type_matrix(uint32_t);
+mulc_type_matrix(int64_t);
+mulc_type_matrix(uint64_t);
+mulc_type_matrix(float);
+mulc_type_matrix(double);
+
+
+
+/* ---------------------------------------------------------------------------------------------- */
+void mulc_rgb8matrix(rgb8 ** X, int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch, rgb8 y, rgb8 ** Z)
+/* ---------------------------------------------------------------------------------------------- */
+{
+    for (int32_t i = nrl; i <= nrh; i++) {
+        for (int32_t j = ncl; j <= nch; j++) {
+            RGB8_MUL(X[i][j], y, Z[i][j]);
+        }
+    }
+}
+
+/* -------------------------------------------------------------------------------------------------- */
+void mulc_rgbx8matrix(rgbx8 ** X, int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch, rgbx8 y, rgbx8 ** Z)
+/* -------------------------------------------------------------------------------------------------- */
+{
+    for (int32_t i = nrl; i <= nrh; i++) {
+        for (int32_t j = ncl; j <= nch; j++) {
+            RGBX8_MUL(X[i][j], y, Z[i][j]);
+        }
+    }
+}
+
+
 /* --------------- */
 /* --- MulFrac --- */
 /* --------------- */
 
-// Y=(a*X)/b
-
-/* -------------------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) mulfrac_si8matrix(sint8 **X, long nrl, long nrh, long ncl, long nch, int32 a, int32 b, sint8 **Y)
-/* -------------------------------------------------------------------------------------------------------------- */
-{
-	int i, j;
-	int32 x, y;
-	
-	for(i=nrl; i<=nrh; i++) {
-		for(j=ncl; j<=nch; j++) {
-			x = X[i][j];
-			y = (a * x) / b;
-            Y[i][j] = (sint8) y;
-		}
-	}
-}
-/* -------------------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) mulfrac_ui8matrix(uint8 **X, long nrl, long nrh, long ncl, long nch, int32 a, int32 b, uint8 **Y)
-/* -------------------------------------------------------------------------------------------------------------- */
-{
-	int i, j;
-	int32 x, y;
-	
-	for(i=nrl; i<=nrh; i++) {
-		for(j=ncl; j<=nch; j++) {
-			x = X[i][j];
-			y = (a * x) / b;
-			Y[i][j] = (uint8) y;
-		}
-	}
-}
+// Y = (a * X) / b
+
+#undef mulfrac_type_matrix
+#define mulfrac_type_matrix(t) \
+void short_name(t,mulfrac_,matrix)(t ** X, int32_t nrl, int32_t nrh, \
+        int32_t ncl, int32_t nch, int32_t a, int32_t b, t ** Y)      \
+{                                                                    \
+    for (int32_t i = nrl; i <= nrh; i++) {                           \
+        for (int32_t j = ncl; j <= nch; j++) {                       \
+            Y[i][j] = (t) ((a * X[i][j]) / b);                       \
+        }                                                            \
+    }                                                                \
+}
+
+mulfrac_type_matrix(int8_t);
+mulfrac_type_matrix(uint8_t);
+mulfrac_type_matrix(int16_t);
+mulfrac_type_matrix(uint16_t);
+mulfrac_type_matrix(int32_t);
+mulfrac_type_matrix(uint32_t);
+mulfrac_type_matrix(int64_t);
+mulfrac_type_matrix(uint64_t);
+mulfrac_type_matrix(float);
+mulfrac_type_matrix(double);
+
+
+/* ------------------------------------------------------------------------------------------------------------ */
+void mulfrac_rgb8matrix(rgb8 ** X, int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch, rgb32 a, rgb32 b, rgb8 ** Y)
+/* ------------------------------------------------------------------------------------------------------------ */
+{
+    rgb32 y32;
+    rgb8 x8, y8;
+    for (int32_t i = nrl; i <= nrh; i++) {
+        for (int32_t j = ncl; j <= nch; j++) {
+            x8 = X[i][j];
+            RGB8_MULFRAC(x8, a, b, y32);
+            RGB32CAST8(y32, y8);
+            Y[i][j] = y8;
+        }
+    }
+}
+
 /* ----------------------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) mulfrac_si16matrix(sint16 **X, long nrl, long nrh, long ncl, long nch, int32 a, int32 b, sint16 **Y)
+void mulfrac_rgb8xmatrix(rgbx8 ** X, int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch, rgbx32 a, rgbx32 b, rgbx8 ** Y)
 /* ----------------------------------------------------------------------------------------------------------------- */
 {
-	int i, j;
-	int32 x, y;
-	
-	for(i=nrl; i<=nrh; i++) {
-		for(j=ncl; j<=nch; j++) {
-			x = X[i][j];
-			y = (a * x) / b;
-            Y[i][j] = (sint16) y;
-		}
-	}
-}
-/* ----------------------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) mulfrac_ui16matrix(uint16 **X, long nrl, long nrh, long ncl, long nch, int32 a, int32 b, uint16 **Y)
-/* ----------------------------------------------------------------------------------------------------------------- */
-{
-	int i, j;
-	int32 x, y;
-	
-	for(i=nrl; i<=nrh; i++) {
-		for(j=ncl; j<=nch; j++) {
-			x = X[i][j];
-			y = (a * x) / b;
-			Y[i][j] = (uint16) y;
-		}
-	}
-}
-/* ------------------------------------------------------------------------------------------------------------------ */
-IMAGE_EXPORT(void) mulfrac_si32matrix(sint32 **X, long nrl, long nrh, long ncl, long nch, int32  a, int32 b, sint32 **Y)
-/* ------------------------------------------------------------------------------------------------------------------ */
-{
-	int i, j;
-	int32 x, y;
-	
-	for(i=nrl; i<=nrh; i++) {
-		for(j=ncl; j<=nch; j++) {
-			x = X[i][j];
-			y = (a * x) / b;
-            Y[i][j] = (sint16) y;
-		}
-	}
-}
-/* ------------------------------------------------------------------------------------------------------------------ */
-IMAGE_EXPORT(void) mulfrac_ui32matrix(uint32 **X, long nrl, long nrh, long ncl, long nch, int32  a, int32 b, uint32 **Y)
-/* ------------------------------------------------------------------------------------------------------------------ */
-{
-	int i, j;
-	int32 x, y;
-	
-	for(i=nrl; i<=nrh; i++) {
-		for(j=ncl; j<=nch; j++) {
-			x = X[i][j];
-			y = (a * x) / b;
-			Y[i][j] = (uint16) y;
-		}
-	}
-}
-/* ----------------------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) mulfrac_si64matrix(sint64 **X, long nrl, long nrh, long ncl, long nch, int32 a, int32 b, sint64 **Y)
-/* ----------------------------------------------------------------------------------------------------------------- */
-{
-	int i, j;
-	sint64 x, y;
-	
-	for(i=nrl; i<=nrh; i++) {
-		for(j=ncl; j<=nch; j++) {
-			x = X[i][j];
-			y = (a * x) / b;
-            Y[i][j] = (sint64) y;
-		}
-	}
-}
-/* ----------------------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) mulfrac_ui64matrix(uint64 **X, long nrl, long nrh, long ncl, long nch, int32 a, int32 b, uint64 **Y)
-/* ----------------------------------------------------------------------------------------------------------------- */
-{
-	int i, j;
-	uint64 x, y;
-	
-	for(i=nrl; i<=nrh; i++) {
-		for(j=ncl; j<=nch; j++) {
-			x = X[i][j];
-			y = (a * x) / b;
-			Y[i][j] = (uint64) y;
-		}
-	}
-}
-/* ------------------------------------------------------------------------------------------------------------ */
-IMAGE_EXPORT(void) mulfrac_rgb8matrix(rgb8 **X, long nrl,long nrh, long ncl, long nch, rgb32 a, rgb32 b, rgb8 **Y)
-/* ------------------------------------------------------------------------------------------------------------ */
-{
-	int i, j;
-	rgb32 y32;
-	rgb8 x8, y8;
-
-	
-	for(i=nrl; i<=nrh; i++) {
-		for(j=ncl; j<=nch; j++) {
-			x8 = X[i][j];
-			RGB8_MULFRAC(x8,a,b,y32);
-			RGB32CAST8(y32,y8);
-			Y[i][j] = y8;
-		}
-	}
-}
-/* ----------------------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) mulfrac_rgb8xmatrix(rgbx8 **X, long nrl,long nrh, long ncl, long nch, rgbx32 a, rgbx32 b, rgbx8 **Y)
-/* ----------------------------------------------------------------------------------------------------------------- */
-{
-	int i, j;
-	rgbx32 y32;
-	rgbx8 x8, y8;
-	
-	for(i=nrl; i<=nrh; i++) {
-		for(j=ncl; j<=nch; j++) {
-			x8 = X[i][j];
-			RGBX8_MULFRAC(x8,a,b,y32);
-			RGBX32CAST8(y32,y8);
-			Y[i][j] = y8;
-		}
-	}
-}
+    rgbx32 y32;
+    rgbx8 x8, y8;
+    for (int32_t i = nrl; i <= nrh; i++) {
+        for (int32_t j = ncl; j <= nch; j++) {
+            x8 = X[i][j];
+            RGBX8_MULFRAC(x8, a, b, y32);
+            RGBX32CAST8(y32, y8);
+            Y[i][j] = y8;
+        }
+    }
+}
+
 
 /* ---------------- */
@@ -1251,128 +414,67 @@
 /* ---------------- */
 
-// m3 = (a*m1)>>s
-
-/* -------------------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) mulshift_si8matrix(sint8 **X, long nrl, long nrh,long ncl, long nch, int32 a, int32 s, sint8 **Y)
-/* -------------------------------------------------------------------------------------------------------------- */
-{
-	int i, j;
-	int32 x, y;
-	
-	for(i=nrl; i<=nrh; i++) {
-		for(j=ncl; j<=nch; j++) {
-			x = X[i][j];
-			y = (a * x) >> s;
-			Y[i][j] = (sint8) y;
-		}
-	}
-}
-/* --------------------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) mulshift_ui8matrix(uint8 **X, long nrl,long nrh,long ncl, long nch, int32  a, int32  s, uint8 **Y)
-/* --------------------------------------------------------------------------------------------------------------- */
-{
-	int i, j;
-	int32 x, y;
-	
-	for(i=nrl; i<=nrh; i++) {
-		for(j=ncl; j<=nch; j++) {
-			x = X[i][j];
-			y = (a * x) >> s;
-			Y[i][j] = (uint8) y;
-		}
-	}
-}
+// m3 = (a * m1) >> s
+
+#undef mulshift_type_matrix
+#define mulshift_type_matrix(t) \
+void short_name(t,mulshift_,matrix)(t ** X, int32_t nrl, int32_t nrh, \
+        int32_t ncl, int32_t nch, int32_t a, int32_t s, t ** Y)      \
+{                                                                    \
+    for (int32_t i = nrl; i <= nrh; i++) {                           \
+        for (int32_t j = ncl; j <= nch; j++) {                       \
+            Y[i][j] = (t) ((a * X[i][j]) >> s);                      \
+        }                                                            \
+    }                                                                \
+}
+
+mulshift_type_matrix(int8_t);
+mulshift_type_matrix(uint8_t);
+mulshift_type_matrix(int16_t);
+mulshift_type_matrix(uint16_t);
+mulshift_type_matrix(int32_t);
+mulshift_type_matrix(uint32_t);
+mulshift_type_matrix(int64_t);
+mulshift_type_matrix(uint64_t);
+
+
+/* ---------------------------------------------------------------------------------------------------------------- */
+void mulshift_rgb8matrix(rgb8 ** X, int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch, rgb32  a, rgb32  s, rgb8 ** Y)
+/* ---------------------------------------------------------------------------------------------------------------- */
+{
+    rgb32 y32;
+    rgb8 x8, y8;
+    for (int32_t i = nrl; i <= nrh; i++) {
+        for (int32_t j = ncl; j <= nch; j++) {
+            x8 = X[i][j];
+            RGB8_MULSHIFT(x8, a, s, y32);
+            RGB32CAST8(y32, y8);
+            Y[i][j] = y8;
+        }
+    }
+}
+
 /* ----------------------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) mulshift_si16matrix(sint16 **X, long nrl, long nrh,long ncl, long nch, int32 a, int32 s, sint16 **Y)
+void mulshift_rgbx8matrix(rgbx8 ** X, int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch, rgbx32 a, rgbx32 s, rgbx8 ** Y)
 /* ----------------------------------------------------------------------------------------------------------------- */
 {
-	int i, j;
-	int32 x, y;
-	
-	for(i=nrl; i<=nrh; i++) {
-		for(j=ncl; j<=nch; j++) {
-			x = X[i][j];
-			y = (a * x) >> s;
-			Y[i][j] = (sint16) y;
-		}
-	}
-}
-/* ------------------------------------------------------------------------------------------------------------------ */
-IMAGE_EXPORT(void) mulshift_ui16matrix(uint16 **X, long nrl,long nrh,long ncl, long nch, int32  a, int32  s, uint16 **Y)
-/* ------------------------------------------------------------------------------------------------------------------ */
-{
-	int i, j;
-	int32 x, y;
-	
-	for(i=nrl; i<=nrh; i++) {
-		for(j=ncl; j<=nch; j++) {
-			x = X[i][j];
-			y = (a * x) >> s;
-			Y[i][j] = (uint16) y;
-		}
-	}
-}
-/* ----------------------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) mulshift_si32matrix(sint32 **X, long nrl, long nrh,long ncl, long nch, int32 a, int32 s, sint32 **Y)
-/* ----------------------------------------------------------------------------------------------------------------- */
-{
-	int i, j;
-	int32 x, y;
-	
-	for(i=nrl; i<=nrh; i++) {
-		for(j=ncl; j<=nch; j++) {
-			x = X[i][j];
-			y = (a * x) >> s;
-			Y[i][j] = (sint32) y;
-		}
-	}
-}
-/* ------------------------------------------------------------------------------------------------------------------ */
-IMAGE_EXPORT(void) mulshift_ui32matrix(uint32 **X, long nrl,long nrh,long ncl, long nch, int32  a, int32  s, uint32 **Y)
-/* ------------------------------------------------------------------------------------------------------------------ */
-{
-	int i, j;
-	int32 x, y;
-	
-	for(i=nrl; i<=nrh; i++) {
-		for(j=ncl; j<=nch; j++) {
-			x = X[i][j];
-			y = (a * x) >> s;
-			Y[i][j] = (uint32) y;
-		}
-	}
-}
-/* ---------------------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) mulshift_rgb8matrix(rgb8 **X, long nrl,long nrh,long ncl, long nch, rgb32  a, rgb32  s, rgb8 **Y)
-/* ---------------------------------------------------------------------------------------------------------------- */
-{
-	int i, j;
-	rgb32 y32;
-	rgb8 x8, y8;
-	
-	for(i=nrl; i<=nrh; i++) {
-		for(j=ncl; j<=nch; j++) {
-			x8 = X[i][j];
-			RGB8_MULSHIFT(x8,a,s,y32);
-			RGB32CAST8(y32,y8);
-			Y[i][j] = y8;
-		}
-	}
-}
-/* ----------------------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) mulshift_rgbx8matrix(rgbx8 **X, long nrl,long nrh,long ncl, long nch, rgbx32 a, rgbx32 s, rgbx8 **Y)
-/* ----------------------------------------------------------------------------------------------------------------- */
-{
-	int i, j;
-	rgbx32 y32;
-	rgbx8 x8, y8;
-	
-	for(i=nrl; i<=nrh; i++) {
-		for(j=ncl; j<=nch; j++) {
-			x8 = X[i][j];
-			RGBX8_MULSHIFT(x8,a,s,y32);
-			RGBX32CAST8(y32,y8);
-			Y[i][j] = y8;
-		}
-	}
-}
+    rgbx32 y32;
+    rgbx8 x8, y8;
+    for (int32_t i = nrl; i <= nrh; i++) {
+        for (int32_t j = ncl; j <= nch; j++) {
+            x8 = X[i][j];
+            RGBX8_MULSHIFT(x8, a, s, y32);
+            RGBX32CAST8(y32, y8);
+            Y[i][j] = y8;
+        }
+    }
+}
+
+// Local Variables:
+// tab-width: 4
+// c-basic-offset: 4
+// c-file-offsets:((innamespace . 0)(inline-open . 0))
+// indent-tabs-mode: nil
+// End:
+
+// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4
+
Index: soft/giet_vm/applications/rosenfeld/nrc2/src/nrarith2x.c
===================================================================
--- soft/giet_vm/applications/rosenfeld/nrc2/src/nrarith2x.c	(revision 820)
+++ soft/giet_vm/applications/rosenfeld/nrc2/src/nrarith2x.c	(revision 821)
@@ -17,6 +17,6 @@
 #include <malloc.h>
 #include <math.h> // fabs
-// #include <memory.h> // memcpy
 
+#include "nrc_os_config.h"
 #include "mypredef.h"
 #include "nrtype.h"
@@ -25,84 +25,101 @@
 #include "nrkernel.h"
 
-/* ------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) addcnz_bmatrix(byte **src,long nrl,long nrh,long ncl, long nch, byte  cte, byte **dst)
-/* ------------------------------------------------------------------------------------- */
-{
-	long i,j;
-	byte *Xi, *Yi;
-	
-	for(i=nrl; i<=nrh; i++) {
-		Xi = src[i];
-		Yi = dst[i];
-		for(j=ncl; j<=nch; j++) {
-			if(Xi[j])
-				Yi[j] = Xi[j] + cte;
-			else
-				Yi[j] = Xi[j];
-		}
-	}
+
+#undef addcnz_type_matrix
+#define addcnz_type_matrix(t) \
+void short_name(t,addcnz_,matrix)(t ** src, int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch, t cte, t ** dst) \
+{                                              \
+	t * Xi;                                    \
+    t * Yi;                                    \
+	for (int32_t i = nrl; i <= nrh; i++) {     \
+		Xi = src[i];                           \
+		Yi = dst[i];                           \
+		for (int32_t j = ncl; j <= nch; j++) { \
+			if (Xi[j] != 0) {                  \
+				Yi[j] = Xi[j] + cte;           \
+            }                                  \
+			else {                             \
+				Yi[j] = Xi[j];                 \
+            }                                  \
+		}                                      \
+	}                                          \
 }
-/* ----------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) addandc_bmatrix(byte **src,long nrl,long nrh,long ncl, long nch, byte  cte, byte **dst)
-/* ----------------------------------------------------------------------------------- */
-{
-	long i,j;
-	byte *Xi, *Yi;
-	
-	for(i=nrl; i<=nrh; i++) {
-		Xi = src[i];
-		Yi = dst[i];
-		for(j=ncl; j<=nch; j++) {
-			if(Xi[j])
-				Yi[j] = Xi[j] + cte;
-			else
-				Yi[j] = Xi[i];
-		}
-	}
+
+addcnz_type_matrix(int8_t);
+addcnz_type_matrix(uint8_t);
+addcnz_type_matrix(int16_t);
+addcnz_type_matrix(uint16_t);
+addcnz_type_matrix(int32_t);
+addcnz_type_matrix(uint32_t);
+addcnz_type_matrix(int64_t);
+addcnz_type_matrix(uint64_t);
+addcnz_type_matrix(float);
+addcnz_type_matrix(double);
+
+
+#undef addandc_type_matrix
+#define addandc_type_matrix(t) \
+void short_name(t,addandc_,matrix)(t ** src, int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch, t cte, t ** dst) \
+{                                              \
+	t * Xi;                                    \
+    t * Yi;                                    \
+	for (int32_t i = nrl; i <= nrh; i++) {     \
+		Xi = src[i];                           \
+		Yi = dst[i];                           \
+		for (int32_t j = ncl; j <= nch; j++) { \
+			if (Xi[j] != 0) {                  \
+                Yi[j] = Xi[j] + cte;           \
+            }                                  \
+		}                                      \
+	}                                          \
 }
-/* ---------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) addandc_si16matrix(sint16 **src,long nrl,long nrh,long ncl, long nch, short cte, sint16 **dst)
-/* ---------------------------------------------------------------------------------------- */
-{
-	long i,j;
-	sint16 *Xi, *Yi;
-	
-	for(i=nrl; i<=nrh; i++) {
-		Xi = src[i];
-		Yi = dst[i];
-		for(j=ncl; j<=nch; j++) {
-			if(Xi[j]) Yi[j] = Xi[j] + cte;
-		}
-	}
+
+addandc_type_matrix(int8_t);
+addandc_type_matrix(uint8_t);
+addandc_type_matrix(int16_t);
+addandc_type_matrix(uint16_t);
+addandc_type_matrix(int32_t);
+addandc_type_matrix(uint32_t);
+addandc_type_matrix(int64_t);
+addandc_type_matrix(uint64_t);
+addandc_type_matrix(float);
+addandc_type_matrix(double);
+
+
+#undef sum_type_matrix
+#define sum_type_matrix(t,rt) \
+rt short_name(t,sum_,matrix)(t ** m, int32_t nrl, int32_t nrh,int32_t ncl, int32_t nch) \
+{                                              \
+	rt s = 0;                                  \
+	t * Xi;                                    \
+	for (int32_t i = nrl; i <= nrh; i++) {     \
+		Xi = m[i];                             \
+		for (int32_t j = ncl; j <= nch; j++) { \
+			s += Xi[j];                        \
+		}                                      \
+    }                                          \
+    return s;                                  \
 }
-/* ------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) addandc_ui16matrix(uint16 **src,long nrl,long nrh,long ncl, long nch, short cte, uint16 **dst)
-/* ------------------------------------------------------------------------------------------ */
-{
-	long i,j;
-	uint16 *Xi, *Yi;
-	
-	for(i=nrl; i<=nrh; i++) {
-		Xi = src[i];
-		Yi = dst[i];
-		for(j=ncl; j<=nch; j++) {
-			if(Xi[j]) Yi[j] = Xi[j] + cte;
-		}
-	}
-}
-/* ----------------------------------------------------------- */
-IMAGE_EXPORT(int) count_bmatrix(byte **m, long nrl,long nrh,long ncl, long nch)
-/* ----------------------------------------------------------- */
-{
-	long i, j;
-	int s = 0;
-	byte *Xi;
-	
-	for(i=nrl; i<=nrh; i++) {
-		Xi = m[i];
-		for(j=ncl; j<=nch; j++) {
-			s += Xi[j];
-		}
-    }
-    return s;
-}
+
+
+sum_type_matrix(int8_t, int32_t);
+sum_type_matrix(uint8_t, uint32_t);
+sum_type_matrix(int16_t, int32_t);
+sum_type_matrix(uint16_t, uint32_t);
+sum_type_matrix(int32_t, int64_t);
+sum_type_matrix(uint32_t, uint64_t);
+sum_type_matrix(int64_t, int64_t);
+sum_type_matrix(uint64_t, uint64_t);
+sum_type_matrix(float, float);
+sum_type_matrix(double, double);
+
+
+// Local Variables:
+// tab-width: 4
+// c-basic-offset: 4
+// c-file-offsets:((innamespace . 0)(inline-open . 0))
+// indent-tabs-mode: nil
+// End:
+
+// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4
+
Index: soft/giet_vm/applications/rosenfeld/nrc2/src/nrio2.c
===================================================================
--- soft/giet_vm/applications/rosenfeld/nrc2/src/nrio2.c	(revision 820)
+++ soft/giet_vm/applications/rosenfeld/nrc2/src/nrio2.c	(revision 821)
@@ -1001,9 +1001,11 @@
     char buffer[80];
     int i;
+    (void) gris;
     
     // open file
     fd = open(filename, O_RDONLY);
     if (fd < 0) {
-        printf("*** Error: Can't open file %s in %s.\n", filename, __func__);
+        printf("\n*** Error: Can't open file %s in %s.\n", filename, __func__);
+        exit(1);
     }
     
@@ -1046,7 +1048,9 @@
     int i;
     
+    //fd = open(filename, O_WRONLY | O_TRUNC | O_CREAT);
     fd = open(filename, O_TRUNC | O_CREAT);
     if (fd < 0) {
-        printf("*** Error: Impossible to open file %s in %s\n", filename, __func__);
+        printf("\n*** Error: Impossible to open file %s in %s\n", filename, __func__);
+        return;
     }
     
Index: soft/giet_vm/applications/rosenfeld/nrc2/src/nrkernel.c
===================================================================
--- soft/giet_vm/applications/rosenfeld/nrc2/src/nrkernel.c	(revision 820)
+++ 	(revision )
@@ -1,181 +1,0 @@
-// ------------------
-// --- nrkernel.c ---
-// ------------------
-
-/*
- * Copyright (c) 2000-2014, Lionel Lacassagne, All rights reserved
- * Univ Paris Sud XI, CNRS
- *
- * Distributed under the Boost Software License, Version 1.0
- * see accompanying file LICENSE.txt or copy it at
- * http://www.boost.org/LICENSE_1_0.txt
- */
-
-/* 
-* 2002/06/11 ajout des fonctions endline
-*/
-#include <stdio.h>
-#include <stddef.h>
-#include <stdlib.h>
-#include <math.h> // fabs
-
-#include "nrc_os_config.h"
-#include "mypredef.h"
-#include "nrtype.h"
-#include "nrdef.h"
-#include "nrmacro.h"
-#include "nrkernel.h"
-
-/* ------------------------- */
-void nrerror0(char error_text[])
-/* ------------------------- */
-/* Numerical Recipes standard error handler */
-{
-    printf("Numerical Recipes run-time error...\n");
-    printf("%s\n",error_text);
-    giet_pthread_exit("...now exiting to system...\n");
-}
-/* ------------------------- */
-void nrerror1(char *format, ...)
-/* ------------------------- */
-/* global error handler */
-{
-	/*va_list pa;
-	int n;
-	char *s, c;
-	float f;
-
-    printf("NRC nrerror: ");
-	va_start(pa, format);
-
-	while (*format != '\0') {
-		if ( *format == '%' ) {
-			switch (*++format) {
-				case '%' : putchar('%'); break;
-				case 'c' :
-					c = va_arg(pa, int); // 'char' is promoted to 'int' when passed through '...'
-					putchar(c);
-					break;
-				case 'd' :
-					n = va_arg(pa, int);
-					printf("%d", n); 
-					break;
-				case 'f' : // affichage d'un float
-					f = (float) va_arg(pa, double);    // 'float' is promoted to 'double' when passed through '...'
-					printf("%f", f); 
-					break;
-				case 's' :
-					s = va_arg(pa, char*);
-					for ( ; *s != '\0'; s++ ) 
-						putchar(*s);
-					break;
-			}
-		}
-		else 
-			putchar( *format);
-		format++;
-	}   
-	va_end(pa);
-	putchar('\n');
-	exit(-1);
-     */
-}
-/* ------------------------- */
-void nrerror(char error_text[])
-/* ------------------------- */
-/* Numerical Recipes standard error handler */
-{
-    nrerror0(error_text);
-}
-// --------------------------
-void Error(char *format, ...)
-// --------------------------
-{
-    giet_pthread_exit("NRC 'Error' with variable length args is currently unavailable\nuse nrerror until 'include <stdarg.h>' issue will be addressed\n");
-    
-	/*va_list pa;
-	int n;
-	char *s, c;
-	float f;
-
-    printf("NRC Error: ");
-	va_start(pa, format);
-
-	while (*format != '\0') {
-		if ( *format == '%' ) {
-			switch (*++format) {
-				case '%' : putchar('%'); break;
-				case 'c' :
-					c = va_arg(pa, int); // 'char' is promoted to 'int' when passed through '...'
-					putchar(c);
-					break;
-				case 'd' :
-					n = va_arg(pa, int);
-					printf("%d", n); 
-					break;
-				case 'f' : // affichage d'un float
-					f = (float) va_arg(pa, double);    // 'float' is promoted to 'double' when passed through '...'
-					printf("%f", f); 
-					break;
-				case 's' :
-					s = va_arg(pa, char*);
-					for ( ; *s != '\0'; s++ ) 
-						putchar(*s);
-					break;
-			}
-		}
-		else 
-			putchar( *format);
-		format++;
-	}   
-	va_end(pa);
-	putchar('\n');
-	exit(-1);
-     */
-}
-// ----------------------------
-void Warning(char *format, ...)
-// ----------------------------
-{
-    giet_pthread_exit("NRC 'Warning' with variable length args is currently unavailable\nuse nrerror until 'include <stdarg.h>' issue will be addressed");
-    
-	/*
-     va_list pa;
-	int n;
-	char *s, c;
-	float f;
-
-	va_start(pa, format);
-
-	while (*format != '\0') {
-		if ( *format == '%' ) {
-			switch (*++format) {
-				case '%' : putchar('%'); break;
-				case 'c' :
-					c = va_arg(pa, int); // 'char' is promoted to 'int' when passed through '...'
-					putchar(c);
-					break;
-				case 'd' :
-					n = va_arg(pa, int);
-					printf("%d", n); 
-					break;
-				case 'f' : // affichage d'un float
-					f = (float) va_arg(pa, double);    // 'float' is promoted to 'double' when passed through '...'
-					printf("%f", f); 
-					break;
-				case 's' :
-					s = va_arg(pa, char*);
-					for ( ; *s != '\0'; s++ ) 
-						putchar(*s);
-					break;
-			}
-		}
-		else 
-			putchar( *format);
-		format++;
-	}   
-	va_end(pa);
-	putchar('\n');
-	//exit(-1);
-     */
-}
Index: soft/giet_vm/applications/rosenfeld/nrc2/src/nrlut.c
===================================================================
--- soft/giet_vm/applications/rosenfeld/nrc2/src/nrlut.c	(revision 820)
+++ soft/giet_vm/applications/rosenfeld/nrc2/src/nrlut.c	(revision 821)
@@ -304,4 +304,5 @@
 	rgb8 *Si;
 	int r, b, g;
+    (void) Si;
 	
 	//FUNCTION_NAME("Histogram_rgbmatrix");
Index: soft/giet_vm/applications/rosenfeld/nrc2/src/nrmem1x.c
===================================================================
--- soft/giet_vm/applications/rosenfeld/nrc2/src/nrmem1x.c	(revision 820)
+++ soft/giet_vm/applications/rosenfeld/nrc2/src/nrmem1x.c	(revision 821)
@@ -11,4 +11,5 @@
 #include <stdio.h>
 #include <stddef.h>
+#include <string.h>
 
 #include "mypredef.h"
Index: soft/giet_vm/applications/rosenfeld/nrc2/src/nrwrap2.c
===================================================================
--- soft/giet_vm/applications/rosenfeld/nrc2/src/nrwrap2.c	(revision 820)
+++ soft/giet_vm/applications/rosenfeld/nrc2/src/nrwrap2.c	(revision 821)
@@ -21,4 +21,5 @@
 #include <math.h> // fabs
 
+#include "nrc_os_config.h"
 #include "mypredef.h"
 #include "nrtype.h"
Index: soft/giet_vm/applications/rosenfeld/rosenfeld.py
===================================================================
--- soft/giet_vm/applications/rosenfeld/rosenfeld.py	(revision 820)
+++ soft/giet_vm/applications/rosenfeld/rosenfeld.py	(revision 821)
@@ -40,9 +40,12 @@
     data_size  = 0x00010000     # 64 Kbytes (non replicated)
 
+    # QM warning: if less than 8M per cluster (i.e. 2M per thread), small pages are required
     stack_base = 0x40000000 
-    stack_size = 0x00800000     # 8 Mbytes (per cluster)
+    stack_size = 0x00080000     # 512K (per cluster) => 128K per thread
+    #stack_size = 0x00400000     # 4M (per cluster) => 1M per thread
 
     heap_base  = 0x60000000 
-    heap_size  = 0x01000000     # 16 Mbytes (per cluster) 
+    #heap_size  = 0x00800000     # 8 Mbytes (per cluster) 
+    heap_size  = 0x10000000     # 256 Mbytes (total) 
 
     # create vspace
@@ -80,5 +83,5 @@
                                      base, size, 'C_WU', vtype = 'BUFFER', 
                                      x = x , y = y , pseg = 'RAM',
-                                     local = True, big = True )
+                                     local = True, big = False )
 
     # heap vsegs: distributed non local (all heap vsegs can be accessed by all tasks)
@@ -87,10 +90,14 @@
             cluster_id = (x * y_size) + y
             if (mapping.clusters[cluster_id].procs):
-                size = heap_size
-                base = heap_base + (cluster_id * size)
-
+                nclusters = x_size * y_size
+                if x == 0 and y == 0:
+                    size = heap_size / 2
+                    base = heap_base
+                else:
+                    size = heap_size / (2 * nclusters)
+                    base = heap_base + heap_size / 2 + ((y * x_size) + x - 1) * size
                 mapping.addVseg(vspace, 'rosen_heap_%d_%d' % (x, y), base, size, 
-                                'C_WU', vtype = 'HEAP', x = x, y = y, pseg = 'RAM',
-                                local = False, big = True )
+                        'C_WU', vtype = 'HEAP', x = x, y = y, pseg = 'RAM',
+                        local = False, big = True )
 
     # distributed tasks / one task per processor
Index: soft/giet_vm/applications/rosenfeld/src-par/ecc_features.c
===================================================================
--- soft/giet_vm/applications/rosenfeld/src-par/ecc_features.c	(revision 821)
+++ soft/giet_vm/applications/rosenfeld/src-par/ecc_features.c	(revision 821)
@@ -0,0 +1,1 @@
+link ../src/ecc_features.c
Index: soft/giet_vm/applications/rosenfeld/src-par/mca.c
===================================================================
--- soft/giet_vm/applications/rosenfeld/src-par/mca.c	(revision 820)
+++ soft/giet_vm/applications/rosenfeld/src-par/mca.c	(revision 821)
@@ -15,12 +15,15 @@
 #include <malloc.h>
 
-#ifdef CLI
 #include "nrc_os_config.h"
+#include "config.h"
 #include "nrc.h"
-#endif
-
+
+#if TARGET_OS == GIETVM
+    #include <giet_config.h>
+#endif
 
 #include "util.h"
 #include "ecc_common.h"
+#include "ecc_features.h"
 #include "mca_matrix_dist.h"
 
@@ -34,18 +37,11 @@
 
 
-// ----------------------
+// -----------------------
 void MCA_Error(char * msg)
-// ----------------------
+// -----------------------
 {
     printf("MCA ERROR: %s\n", msg);
     printf("now exiting to system...\n");
-    exit(1);   
-}
-
-
-// ---------------------
-void MCA_Zero(MCA * mca)
-// ---------------------
-{
+    exit(1);
 }
 
@@ -58,8 +54,5 @@
     mca = (MCA *) malloc(sizeof(MCA));
 
-    if (mca) {
-        MCA_Zero(mca);
-    }
-    else {
+    if (mca == NULL) {
         MCA_Error("allocation failed in MCA_pConstructor_Empty");
     }
@@ -91,5 +84,5 @@
 
     mca->j0 = 0;
-    mca->j1 = width-1;
+    mca->j1 = width - 1;
 }
 
@@ -102,5 +95,5 @@
   
     mca->i0 = 0;
-    mca->i1 = height-1;
+    mca->i1 = height - 1;
 }
 
@@ -161,19 +154,17 @@
     int j0_par, j1_par;
     int height_par, height_mod;
-    
+
     int pw2;
     int32 ne_par;          // quantite par bande
     uint32 nemax_par;      // la puissance de 2 >=
     uint32 e0_par, e1_par; // indice par bande [start..end]
+    int nb_level;
     
     MCA ** mcas;
     MCA *  mca_par;
     
-    MCA_VERBOSE1(printf("====================\n"));
-    MCA_VERBOSE1(printf("== MCA_Initialize ==\n"));
-    MCA_VERBOSE1(printf("====================\n"));
-    
-    MCA_VERBOSE1(printf("height = %d\n", height));
-    MCA_VERBOSE1(printf("width  = %d\n", width));
+    printf("*** %s ***\n", __func__);
+    MCA_VERBOSE1(printf("   height = %d\n", height));
+    MCA_VERBOSE1(printf("   width  = %d\n", width));
     
     // array of pointers to mca workers
@@ -187,16 +178,57 @@
     height_par = height / np;
     height_mod = height % np;
-    //if(height % np) height_par++;
-    MCA_VERBOSE1(printf("height_par = %d x %d + %d\n", height_par, np, height_mod));
-    
-    MCA_VERBOSE1(printf("========================\n"));
+
+    MCA_VERBOSE1(printf("   height_par = %d x %d + %d\n", height_par, np, height_mod));
+    MCA_VERBOSE1(printf("   ========================\n"));
     
     i1_par_previous = 0;
-    
-    for (int p = 0; p < np; p++) {
+
+    // puissance de 2 de chaque bande
+    ne_par = height_par * width + 1;
+    MCA_VERBOSE1(printf("   ne_par    = %d\n", ne_par));
+    pw2 = i32log2(ne_par);
+    if (ne_par > (1 << pw2)) {
+        pw2++;
+    }
+    nemax_par = 1 << pw2;
+
+    MCA_VERBOSE1(printf("   nemax_par = %d\n", nemax_par));
+
+    nb_level = i32log2(np);
+    if ((1 << nb_level) < np) {
+        nb_level++;
+    }
+
+#if PYR_BARRIERS
+    // ------------------------------------------
+    // -- Allocation des barriÃšres pyramidales --
+    // ------------------------------------------
+
+    pthread_barrier_t * barriers = NULL;
+    if (nb_level > 0) {
+        barriers = malloc(sizeof(pthread_barrier_t) * nb_level);
+
+        // Initially all threads are active except thread 0
+        int nb_active = np - 1;
+        pthread_barrier_init(&barriers[0], NULL, nb_active);
+        for (int i = 1; i < nb_level; i++) {
+            // thread 0 never does any merge
+            for (int p = 1; p < np; p++) {
+                if ((p + (1 << (i - 1))) % (1 << i) == 0) {
+                    // thread inactive at level i
+                    nb_active -= 1;
+                }
+            }
+            pthread_barrier_init(&barriers[i], NULL, nb_active);
+        }
+    }
+#endif
+
+    for (int p = 0; p < np; p++) {
+
         // ----------------- //
         // -- constructor -- //
         // ----------------- //
-        MCA_VERBOSE1(printf("-- p = %d ----------------\n", p));
+        MCA_VERBOSE2(printf("-- p = %d ----------------\n", p));
     
         // alloc of mca workers into array of pointers
@@ -208,4 +240,11 @@
         mca_par->p   = p;
         mca_par->mca = mca; // pointer to master
+#if TARGET_OS == GIETVM
+        int x, y; // cluster coordinates
+        // We have p == 4 => x = 0; y = 1
+        x = (p / NB_PROCS_MAX) / Y_SIZE;
+        y = (p / NB_PROCS_MAX) % Y_SIZE;
+        MCA_VERBOSE2(printf("p = %d (x = %d, y = %d)\n", p, x, y));
+#endif
         
         // ------------------------------------- //
@@ -214,7 +253,4 @@
         
         // hauteur de chaque bande
-        
-        //printf("i1_par_previous = %d\n", i1_par_previous);
-        
         if (p == 0) {
             i0_par = 0;
@@ -232,19 +268,6 @@
         i1_par_previous = i1_par;
         
-        MCA_VERBOSE1(printf("i0_par = %d\n", i0_par));
-        MCA_VERBOSE1(printf("i1_par = %d\n", i1_par));
-        
-        // puissance de 2 de chaque bande
-        ne_par = height_par * width + 1;
-        //if (p == 0) {
-        //    ne_par++;
-        //}
-        MCA_VERBOSE1(printf("ne_par    = %d\n", ne_par));
-        pw2 = i32log2(ne_par);
-        if (ne_par > (1 << pw2)) {
-            pw2++;
-        }
-        nemax_par = 1 << pw2;
-        MCA_VERBOSE1(printf("nemax_par = %d\n", nemax_par));
+        MCA_VERBOSE2(printf("i0_par = %d\n", i0_par));
+        MCA_VERBOSE2(printf("i1_par = %d\n", i1_par));
         
         // etiquettes
@@ -260,22 +283,50 @@
         MCA_VERBOSE2(printf("e0_par = %d\n", e0_par));
         MCA_VERBOSE2(printf("e1_par = %d\n", e1_par));
-        
+
         mca_par->width  = width;
         mca_par->height = height_par;
-    
         mca_par->i0 = i0_par;
         mca_par->i1 = i1_par;
         mca_par->j0 = 0;
         mca_par->j1 = width - 1;
-    
         mca_par->e0 = e0_par;
         mca_par->e1 = e1_par;
-        
         mca_par->alpha = pw2;
+        mca_par->np = np;
+        // Pour les barriÃšres pyramidales
+        mca_par->nb_level = nb_level;
+#if PYR_BARRIERS
+        mca_par->barriers = barriers;
+#else
+        mca_par->barriers = NULL;
+#endif
+        mca_par->F = NULL; // default init
+        mca_par->stats = NULL; // default init
  
         // ---------------- //
         // -- allocation -- //
         // ---------------- //
-    
+#if TARGET_OS == GIETVM
+        mca_par->X = remote_ui8matrix(i0_par, i1_par, 0, width - 1, x, y);
+        mca_par->E = remote_dist_ui32matrix(i0_par, i1_par, 0, width - 1, x, y); // distributed matrix with border
+        
+        if (p == 0) {
+            mca_par->T = remote_ui32vector(e0_par - 1, e1_par, x, y); // car e0 = 1, on a besoin que T[0] = 0 pour FindRoot
+#if FEATURES
+            mca_par->stats = remote_RegionStatsVector(e0_par - 1, e1_par, x, y);
+#endif
+        }
+        else {
+            mca_par->T = remote_ui32vector(e0_par, e1_par, x, y);
+#if FEATURES
+            mca_par->stats = remote_RegionStatsVector(e0_par, e1_par, x, y);
+#endif
+        }
+        
+        mca_par->D = (uint32 **) remote_vvector(0, np - 1, x, y);
+#if FEATURES
+        mca_par->F = (RegionStats **) remote_vvector(0, np - 1, x, y);
+#endif
+#else // !GIETVM
         mca_par->X = ui8matrix (i0_par, i1_par, 0, width - 1);
         mca_par->E = dist_ui32matrix(i0_par, i1_par, 0, width - 1); // distributed matrix with border
@@ -283,22 +334,29 @@
         if (p == 0) {
             mca_par->T = ui32vector(e0_par - 1, e1_par); // car e0 = 1, on a besoin que T[0] = 0 pour FindRoot
+#if FEATURES
+            mca_par->stats = RegionStatsVector(e0_par - 1, e1_par);
+
+#endif
         }
         else {
             mca_par->T = ui32vector(e0_par, e1_par);
+#if FEATURES
+            mca_par->stats = RegionStatsVector(e0_par, e1_par);
+#endif
         }
         
         mca_par->D = (uint32 **) vvector(0, np - 1);
-        
+#if FEATURES
+        mca_par->F = (RegionStats **) vvector(0, np - 1);
+#endif
+#endif   
         MCA_VERBOSE2(printf("X = %p\n", mca_par->X));
         MCA_VERBOSE2(printf("E = %p\n", mca_par->E));
         MCA_VERBOSE2(printf("T = %p\n", mca_par->T));
         MCA_VERBOSE2(printf("D = %p\n", mca_par->D));
-    
     } // p
     
-    // pour debug
-    MCA_VERBOSE2(printf("init des tables d'EQ a l'identite\n"));
-    for (int p = 0; p < np; p++) {
-    
+
+    for (int p = 0; p < np; p++) {
         MCA * mca_par = mcas[p];
         
@@ -319,5 +377,4 @@
     MCA_VERBOSE2(printf("display des tables d'EQ\n"));
     for (int p = 0; p < np; p++) {
-        
         MCA * mca_par = mcas[p];
         
@@ -326,10 +383,10 @@
         uint32 e1 = mca_par->e1;
         
-        MCA_VERBOSE1(printf("p = %d T[%d..%d]\n", p, e0, e1));
+        MCA_VERBOSE2(printf("p = %d T[%d..%d]\n", p, e0, e1));
         if (p == 0) {
-            MCA_VERBOSE1(display_ui32vector_number(T, e0 - 1, e0 + 10, "%5d", "T"));
-        }
-        else {
-            MCA_VERBOSE1(display_ui32vector_number(T, e0, e0 + 10, "%5d", "T"));
+            MCA_VERBOSE2(display_ui32vector_number(T, e0 - 1, e0 + 10, "%5d", "T"));
+        }
+        else {
+            MCA_VERBOSE2(display_ui32vector_number(T, e0, e0 + 10, "%5d", "T"));
         }
         MCA_VERBOSE2(printf("\n"));
@@ -343,17 +400,17 @@
     // table d'indirection distribuee D
     MCA_VERBOSE2(printf("nemax_par = %d\n", nemax_par));
-    
-    for (int p = 0; p < np; p++) {
-    
+    for (int p = 0; p < np; p++) {
         MCA * mca_p = mcas[p];
         uint32 ** D = mca_p->D;
+        RegionStats ** F  = mca_p->F;
         
         for (int k = 0; k < np; k++) {
-            //mcas[p]->D[k] = (void*) (&(mcas[k]->T[mcas[k]->e0]))  - mcas[k]->e0; //k * nemax_par;
-            
             MCA * mca_k = mcas[k];
             uint32 * T = mca_k->T;
-            
             D[k] = T + k * nemax_par; // il faut soustraire le "MSB"
+#if FEATURES
+            RegionStats * stat = mca_k->stats;
+            F[k] = stat + k * nemax_par; // il faut soustraire le "MSB"
+#endif
         } // k
     } // p
@@ -376,5 +433,5 @@
             MCA_VERBOSE2(display_ui32vector(D[k], 0, 9, "%5d", "D\n"));
         }
-        printf("\n");
+        MCA_VERBOSE2(printf("\n"));
     }
     
@@ -413,25 +470,24 @@
 // -----------------------------------
 {
-    int p, np = mca->np;
+    int np = mca->np;
     
     MCA ** mcas = mca->mcas;
     MCA *  mca_par;
-    
-    printf("============================\n");
-    printf("== MCA_Display_Parameters ==\n");
-    printf("============================\n");
-    
-    printf("height = %d\n", mca->height);
-    printf("width  = %d\n", mca->width);
-    printf("np     = %d\n", mca->np);
-    
-    for (p = 0; p < np; p++) {
+    (void) mca_par;
+    
+    printf("*** MCA_Display_Parameters ***\n");
+    
+    MCA_VERBOSE1(printf("   height = %d\n", mca->height));
+    MCA_VERBOSE1(printf("   width  = %d\n", mca->width));
+    MCA_VERBOSE1(printf("   np     = %d\n", mca->np));
+    
+    for (int p = 0; p < np; p++) {
         mca_par = mcas[p];
         
-        printf("Display MCA[%d]\n", p);
-        printf("p = %d\n", mca_par->p);
-        printf("i0 = %8d  i1 = %8d\n", mca_par->i0, mca_par->i1);
-        printf("j0 = %8d  j1 = %8d\n", mca_par->j0, mca_par->j1);
-        printf("e0 = %8d  e1 = %8d\n", mca_par->e0, mca_par->e1);
+        MCA_VERBOSE2(printf("Display MCA[%d]\n", p));
+        MCA_VERBOSE2(printf("p = %d\n", mca_par->p));
+        MCA_VERBOSE2(printf("i0 = %8d  i1 = %8d\n", mca_par->i0, mca_par->i1));
+        MCA_VERBOSE2(printf("j0 = %8d  j1 = %8d\n", mca_par->j0, mca_par->j1));
+        MCA_VERBOSE2(printf("e0 = %8d  e1 = %8d\n", mca_par->e0, mca_par->e1));
     }
 }
@@ -442,5 +498,5 @@
 // -------------------------
 {
-    int p, np = mca->np;
+    int np = mca->np;
     
     MCA ** mcas = mca->mcas;
@@ -451,10 +507,11 @@
     uint32 e0, e1;
     
-    printf("==================\n");
-    printf("== MCA_Finalize ==\n");
-    printf("==================\n");
-    
-    for (p = 0; p < np; p++) {
-    
+    printf("*** MCA_Finalize ***\n");
+    
+#if PYR_BARRIERS
+    free(mcas[0]->barriers);
+#endif
+
+    for (int p = 0; p < np; p++) {
         mca_par = mcas[p];
     
@@ -475,21 +532,26 @@
         if (p == 0) {
             free_ui32vector(mca_par->T, e0 - 1, e1); // car e0 = 1, on a besoin que T[0] = 0 pour FindRoot
+#if FEATURES
+            free_RegionStatsVector(mca_par->stats, e0 - 1, e1);
+#endif
         }
         else {
             free_ui32vector(mca_par->T, e0, e1);
+#if FEATURES
+            free_RegionStatsVector(mca_par->stats, e0, e1);
+#endif
         }
         
         free_vvector((void **) mca_par->D, 0, np - 1);
-        
-    }
-    printf("[MCA_Finalize]: fin boucle\n");
+#if FEATURES
+        free_vvector((void **) mca_par->F, 0, np - 1);
+#endif
+        free(mca_par);
+    }
     free(mcas);
-    printf("[MCA_Finalize]: mcas freed\n");
-    free(mca); // plante si free XET, ne plante pas si pas de free ...
-    printf("[MCA_Finalize]: mca freed\n");
-}
-
-
-// @QM check my modifs...
+    free(mca);
+}
+
+
 // -------------------------------
 void MCA_Scatter_ImageX(MCA * mca)
@@ -498,11 +560,9 @@
     // diffusion de l'image binaire source
     
-    int      np = mca->np;
+    int np = mca->np;
     uint8 ** X  = mca->mca->X;
     
     if (mca->p == 0) { 
-        MCA_VERBOSE1(printf("------------------------\n"));
-        MCA_VERBOSE1(printf("-- MCA_Scatter_ImageX --\n"));
-        MCA_VERBOSE1(printf("------------------------\n"));
+        printf("*** MCA_Scatter_ImageX ***\n");
     }
     
@@ -524,5 +584,4 @@
 
 
-// @QM check my modifs...
 // ------------------------------
 void MCA_Gather_ImageL(MCA * mca)
@@ -532,4 +591,8 @@
     int np = mca->np;
     uint32 ** E = mca->mca->E;
+
+    if (mca->p == 0) { 
+        printf("*** MCA_Gather_ImageL ***\n");
+    }
 
     int i0 = mca->i0;
Index: soft/giet_vm/applications/rosenfeld/src-par/mca_main.c
===================================================================
--- soft/giet_vm/applications/rosenfeld/src-par/mca_main.c	(revision 820)
+++ soft/giet_vm/applications/rosenfeld/src-par/mca_main.c	(revision 821)
@@ -1,4 +1,4 @@
 /* ------------------ */
-/* --- mca.c --- */
+/* --- mca_main.c --- */
 /* ------------------ */
 
@@ -12,39 +12,433 @@
 #include <string.h>
 #include <math.h>
-
-#include <user_lock.h>
-
-#ifdef CLI
+#include <malloc.h>
+
 #include "nrc_os_config.h"
+#include "config.h"
 #include "nrc.h"
-#endif
-
+
+#if TARGET_OS == GIETVM
+    #include <user_lock.h>
+    #include <malloc.h>
+    #include <giet_config.h>
+    #include <user_barrier.h>
+#else
+    #include <unistd.h>
+#endif
 
 #include "util.h"
 #include "ecc_common.h"
 #include "ecc_features.h"
-
 #include "palette.h"
 #include "bmpNR.h"
-
+#include "mca_matrix_dist.h"
+#include "mca_rosenfeld.h"
+#include "clock.h"
 #include "str_ext.h"
+
 
 /* -- local -- */
 #include "mca.h"
-#include "mca_test.h"
-
-
+
+#define MAX_THREADS 256
+#define DEFAULT_NTHREADS 1
+#define DEFAULT_IN_FILENAME "/misc/cadastre.pgm"
+#define DEFAULT_OUT_FILENAME "out.bmp"
+
+pthread_t thread_table[MAX_THREADS];
+pthread_barrier_t main_barrier;
+int display_features = 0;
+int generate_output_image = 0;
+
+CLOCK_DEC;
+
+static void usage(char * name) {
+    printf("Usage: %s <options>\n", name);
+    printf("options:\n");
+    printf("  -i <input_file>  : Input file (default = %s)\n", DEFAULT_IN_FILENAME);
+    printf("  -o <output_file> : Output file (default = %s)\n", DEFAULT_OUT_FILENAME);
+    printf("  -nN              : N = number of threads (default = %d).\n", DEFAULT_NTHREADS);
+    printf("  -d               : Display features (default = false, requires features computation).\n");
+    printf("  -g               : Generate output image (default = false).\n");
+    printf("  -h               : Print out command line options.\n\n");
+}
+
+
+
+// --------------------------------------------------------------------------
+void init_forme_boulon1(uint8 *** X0, int * i0, int * i1, int * j0, int * j1)
+// --------------------------------------------------------------------------
+{
+    uint8 ** X;
+    int i =  0;
+    int h =  28;
+    int w =  30;
+    
+    X = ui8matrix(0, h - 1, 0, w - 1);
+    zero_ui8matrix(X, 0, h - 1, 0, w - 1);
+    
+    *X0 = X;
+    *i0 = 0;
+    *i1 = h - 1;
+    *j0 = 0;
+    *j1 = w - 1;
+    
+    //                                 0000000001111111111122222222223
+    //                                 0123456789012345678901234567890
+    set_ui8vector_str(X[i++], 0, w - 1, "                         111  "); // 00
+    set_ui8vector_str(X[i++], 0, w - 1, "                        11111 "); // 01
+    set_ui8vector_str(X[i++], 0, w - 1, "                      1111111 "); // 02
+    set_ui8vector_str(X[i++], 0, w - 1, "                     11111111 "); // 03
+    set_ui8vector_str(X[i++], 0, w - 1, "                    1111111111"); // 04
+    set_ui8vector_str(X[i++], 0, w - 1, "                   11111111111"); // 05
+    set_ui8vector_str(X[i++], 0, w - 1, "                 1111111111111"); // 06
+    set_ui8vector_str(X[i++], 0, w - 1, "               11111111111111 "); // 07
+    set_ui8vector_str(X[i++], 0, w - 1, "              11111111111111  "); // 08
+    set_ui8vector_str(X[i++], 0, w - 1, "             11111111111111   "); // 09
+    set_ui8vector_str(X[i++], 0, w - 1, "     11    11111111111111     "); // 10
+    set_ui8vector_str(X[i++], 0, w - 1, "    111   11111111111111      "); // 11
+    set_ui8vector_str(X[i++], 0, w - 1, "   11111111111111111111       "); // 12
+    set_ui8vector_str(X[i++], 0, w - 1, " 11111111111111111111         "); // 13
+    set_ui8vector_str(X[i++], 0, w - 1, "1111111111111111111           "); // 14
+    set_ui8vector_str(X[i++], 0, w - 1, " 11111111111111111            "); // 15
+    set_ui8vector_str(X[i++], 0, w - 1, " 1111111111111111             "); // 16
+    set_ui8vector_str(X[i++], 0, w - 1, " 111111111111111              "); // 17
+    set_ui8vector_str(X[i++], 0, w - 1, "  111111111111                "); // 18
+    set_ui8vector_str(X[i++], 0, w - 1, "  1111111111                  "); // 29
+    set_ui8vector_str(X[i++], 0, w - 1, "  1111111111                  "); // 20
+    set_ui8vector_str(X[i++], 0, w - 1, "   111111111                  "); // 21
+    set_ui8vector_str(X[i++], 0, w - 1, "   111111111                  "); // 22
+    set_ui8vector_str(X[i++], 0, w - 1, "    11111111                  "); // 23
+    set_ui8vector_str(X[i++], 0, w - 1, "    1111111                   "); // 24
+    set_ui8vector_str(X[i++], 0, w - 1, "     11111                    "); // 25
+    set_ui8vector_str(X[i++], 0, w - 1, "     111                      "); // 26
+    set_ui8vector_str(X[i++], 0, w - 1, "                              "); // 27
+    
+    //printf("[init_forme_boulon1]: h = %d i = %d\n", h, i);
+    if (i != h) {
+        MCA_Error("init_forme_boulon1 i != h");
+    }
+
+    
+    //display_ui8matrix_positive(X, 0, h-1, 0, w-1, 4, "forme_boulon1"); printf("");
+    //write_ui8matrix_positive(  X, 0, h-1, 0, w-1, 4, "forme_boulon1.txt");
+}
+
+
+// QM : The cost of this function is horrible
+// but it is only for testing purpose
+// Renumbers object in a contiguous way, for an image which has already
+// been processed with several threads
+// --------------------------------------------------------------------
+static void renumber_image(uint32 ** E, int i0, int i1, int j0, int j1)
+// --------------------------------------------------------------------
+{
+    int size = 10;
+    int idx = 1; // next label to give, first invalid index in the equiv table
+    uint32 * equiv = malloc(sizeof(uint32) * size);
+    equiv[0] = 0; // unused
+    int found;
+
+    for (int i = i0; i <= i1; i++) {
+        for (int j = j0; j <= j1; j++) {
+            if (E[i][j] != 0) {
+                found = 0;
+                for (int k = 1; k < idx; k++) {
+                    if (equiv[k] == E[i][j]) {
+                        E[i][j] = k;
+                        found = 1;
+                        break;
+                    }
+                }
+                if (found == 0) {
+                    equiv[idx] = E[i][j];
+                    E[i][j] = idx;
+                    idx += 1;
+                    if (idx == size) {
+                        size = size * 2;
+                        equiv = realloc(equiv, sizeof(uint32) * size);
+                    }
+                }
+            }
+        }
+    }
+    free(equiv);
+}
+
+
+// ----------------------------
+void mca_test1(int num_threads)
+// ----------------------------
+{
+    int i0, i1, j0, j1;
+    int height, width;
+    
+    uint8 ** X0;
+    uint32 ** E;
+    MCA * mca;
+
+    pthread_barrier_init(&main_barrier, NULL, num_threads);
+
+    // -- Allocation --
+    init_forme_boulon1(&X0, &i0, &i1, &j0, &j1);
+    
+    height = i1 - i0 + 1;
+    width  = j1 - j0 + 1;
+    
+    E = ui32matrix(i0, i1, j0, j1);
+    
+    zero_ui32matrix(E, i0, i1, j0, j1);
+    
+    mca = MCA_pConstructor_Empty();
+    
+    // -- set param
+    MCA_Set_Size(mca, width, height);
+    MCA_Set_ImageX(mca, X0);
+    MCA_Set_ImageL(mca, E);
+    MCA_Set_NP(mca, num_threads);
+    
+    // -- MCA init
+    MCA_Initialize(mca);
+    MCA_Display_Parameters(mca);
+    
+    display_ui8matrix_positive(mca->X, i0, i1, j0, j1, 5, "X0");
+#if FEATURES
+    for (int i = 1; i < num_threads; i++) {
+        pthread_create(&thread_table[i], NULL, MCA_Label_Features_Rosenfeld, (void *) mca->mcas[i]);
+    }
+    MCA_Label_Features_Rosenfeld(mca->mcas[0]);
+#else
+    for (int i = 1; i < num_threads; i++) {
+        pthread_create(&thread_table[i], NULL, MCA_Label_Rosenfeld, (void *) mca->mcas[i]);
+    }
+    MCA_Label_Rosenfeld(mca->mcas[0]);
+#endif
+    for (int i = 1; i < num_threads; i++) {
+        pthread_join(thread_table[i], NULL);
+    }
+    display_ui32matrix_positive(mca->E, i0, i1, j0, j1, 5, "Efinal");
+
+    
+    // -- free --
+    printf("Finalize\n");
+    MCA_Finalize(mca);
+    
+    printf("Free_matrix\n");
+    free_ui8matrix (X0, i0, i1, j0, j1);
+    free_ui32matrix(E,  i0, i1, j0, j1);
+}
+
+
+
+// -----------------------------------------------------------
+void mca_test2(int num_threads, char * infile, char * outfile)
+// -----------------------------------------------------------
+{
+    int i0, i1, j0, j1;
+    int height, width;
+    
+    uint8 ** X;
+    uint8 ** E8;
+    uint32 ** E;
+    MCA * mca;
+
+    RGBQuad palette[256];
+
+    pthread_barrier_init(&main_barrier, NULL, num_threads);
+
+    Palette_18ColorsBW(palette);
+    
+    printf("Loading file %s... ", infile);
+    X = LoadPGM_ui8matrix(infile, &i0, &i1, &j0, &j1);
+    printf("done.\n");
+
+    printf("Allocating memory... ");
+    height = i1 - i0 + 1;
+    width  = j1 - j0 + 1;
+    
+    E8 = ui8matrix (i0, i1, j0, j1);
+    E  = ui32matrix(i0, i1, j0, j1);
+    
+    zero_ui8matrix(E8, i0, i1, j0, j1);
+    zero_ui32matrix(E, i0, i1, j0, j1);
+
+    // pre-traitements
+    binarisation_ui8matrix(X, i0, i1, j0, j1, 20, 1, X); // pour le traitement
+    printf("done.\n");
+
+    printf("Allocating and initializing MCA... \n");
+    mca = MCA_pConstructor_Empty();
+    
+    // -- set param
+    MCA_Set_Size(mca, width, height);
+    MCA_Set_ImageX(mca, X);
+    MCA_Set_ImageL(mca, E);
+    MCA_Set_NP(mca, num_threads);
+    
+    // -- MCA init
+    MCA_Initialize(mca);
+    MCA_Display_Parameters(mca);
+    printf("End of MCA allocation and initialization.\n");
+    
+    CLOCK_APP_CREATE;
+#if FEATURES
+    for (int i = 1; i < num_threads; i++) {
+        pthread_create(&thread_table[i], NULL, MCA_Label_Features_Rosenfeld, (void *) mca->mcas[i]);
+    }
+    MCA_Label_Features_Rosenfeld(mca->mcas[0]);
+#else
+    for (int i = 1; i < num_threads; i++) {
+        pthread_create(&thread_table[i], NULL, MCA_Label_Rosenfeld, (void *) mca->mcas[i]);
+    }
+    MCA_Label_Rosenfeld(mca->mcas[0]);
+#endif
+    for (int i = 1; i < num_threads; i++) {
+        pthread_join(thread_table[i], NULL);
+    }
+    CLOCK_APP_JOIN;
+
+    if (generate_output_image) {
+#if TARGET_OS != GIETVM
+        renumber_image(mca->E, i0, i1, j0, j1);
+#else
+        printf("Warning: the output image has not been renumbered, it cannot be used as a comparison with the reference\n");
+#endif
+        mod_ui32matrix_ui8matrix(mca->E, i0, i1, j0, j1, E8);
+        printf("Saving file %s for verification... ", outfile);
+        SaveBMP2_ui8matrix(E8, width, height, palette, outfile);
+        printf("done.\n");
+    }
+
+    MCA_Finalize(mca);
+    printf("Deallocating memory...");
+    free_ui8matrix (X,  i0, i1, j0, j1);
+    free_ui8matrix (E8, i0, i1, j0, j1);
+    free_ui32matrix(E,  i0, i1, j0, j1);
+    printf("done.\n");
+}
+
+
+// --------------------------------------------------------------
+int main_test_mca(int num_threads, char * infile, char * outfile)
+// --------------------------------------------------------------
+{
+    CLOCK_INIT(num_threads, 4); // 4 = Number of steps in body
+    CLOCK_APP_START;
+
+    mca_test2(num_threads, infile, outfile);
+
+    CLOCK_APP_END;
+    CLOCK_FINALIZE;
+    PRINT_CLOCK;
+    CLOCK_FREE;
+    
+    return 0;
+}
+
+
+#if TARGET_OS == GIETVM
+// ------------------------------------
+__attribute__((constructor)) int main()
+// ------------------------------------
+#else
 // -----------------------------
-__attribute__((constructor)) void main()
+int main(int argc, char ** argv)
 // -----------------------------
-{
+#endif
+{
+    char * infile = DEFAULT_IN_FILENAME;
+    char * outfile = DEFAULT_OUT_FILENAME;
+
+    int ch;
+    int num_threads = DEFAULT_NTHREADS;
+
+    printf("*** Starting application Rosenfeld ***\n");
+
+#if TARGET_OS != GIETVM // @QM I think the giet has some random (uninitialized) values for argc and argv
+    while ((ch = getopt(argc, argv, "i:o:n:hdg")) != EOF) {
+        switch (ch) {
+        case 'i':
+            infile = optarg;
+            break;
+        case 'o':
+            outfile = optarg;
+            break;
+        case 'n':
+            num_threads = atoi(optarg);
+            break;
+        case 'h':
+            usage(argv[0]);
+            return 0;
+            break;
+        case 'd':
+#if !FEATURES
+            fprintf(stderr, "*** Error: Features display requires features computation\n");
+            return 1;
+#endif
+            display_features = 1;
+            break;
+        case 'g':
+            generate_output_image = 1;
+            break;
+        default:
+            usage(argv[0]);
+            return 1;
+            break;
+        }
+    }
+
+    // Check arguments
+    if (num_threads < 1) {
+        fprintf(stderr, "*** Error: The number of threads must at least be 1\n");
+        usage(argv[0]);
+        return -1;
+    }
+#endif
+
+#if TARGET_OS == GIETVM
+    {
+        unsigned int xsize, ysize, nprocs;
+        giet_procs_number(&xsize, &ysize, &nprocs);
+        num_threads = xsize * ysize * nprocs;
+    }
+#endif
+
+    if (num_threads > MAX_THREADS) {
+        printf("*** Error: The maximum number of threads is %d, i.e. less than the current number of threads.\n", MAX_THREADS);
+        printf("Please recompile with a bigger MAX_THREADS value.\n");
+        exit(1);
+    }
+
+    printf("Parameters:\n");
+    printf("- Number of threads: %d\n", num_threads);
+    printf("- Input file: %s\n", infile);
+    printf("- Output file: %s\n", outfile);
+#if FAST
+    printf("- Using decision trees (fast): yes\n");
+#elif SLOW
+    printf("- Using decision trees (fast): no\n");
+#endif
+#if FEATURES
+    printf("- Computing features: yes\n");
+#else
+    printf("- Computing features: no\n");
+#endif
+
+
 #if TARGET_OS == GIETVM
     giet_tty_alloc(1);
-    heap_init(0, 0);
-#endif
-    lock_init(&print_lock);
-    main_test_mca();
-
-    exit(0);
-}
-
+    printf("Initializing heaps... ");
+    for (int i = 0; i < X_SIZE; i++) {
+        for (int j = 0; j < X_SIZE; j++) {
+            heap_init(i, j);
+        }
+    }
+    printf("done.\n");
+#endif
+
+    pthread_mutex_init(&print_lock, PTHREAD_PROCESS_PRIVATE);
+    main_test_mca(num_threads, infile, outfile);
+
+    return 0;
+}
+
Index: soft/giet_vm/applications/rosenfeld/src-par/mca_matrix_dist.c
===================================================================
--- soft/giet_vm/applications/rosenfeld/src-par/mca_matrix_dist.c	(revision 820)
+++ soft/giet_vm/applications/rosenfeld/src-par/mca_matrix_dist.c	(revision 821)
@@ -14,8 +14,6 @@
 #include <malloc.h>
 
-#ifdef CLI
 #include "nrc_os_config.h"
 #include "nrc.h"
-#endif
 
 
@@ -61,4 +59,42 @@
 }
 
+#if TARGET_OS == GIETVM
+// ---------------------------------------------------------------------------
+uint32 ** remote_dist_ui32matrix(int i0, int i1, int j0, int j1, int x, int y)
+// ---------------------------------------------------------------------------
+{
+    int i;
+    int nrow = i1 - i0 + 1;
+    int ncol = j1 - j0 + 1;
+    uint32 ** m;
+    
+    // allocate pointers to rows
+    m = (uint32 **) remote_malloc((nrow + 2) * sizeof(uint32 *), x, y);
+    if (!m) {
+        nrerror("allocation failure 1 in dist_ui32matrix()");
+    }
+    m -= i0;
+    m += 1;
+    
+    // allocate rows and set pointers to them
+    m[i0] = (uint32 *) remote_malloc((nrow * ncol + 1) * sizeof(uint32), x, y);
+    if (!m[i0]) {
+        nrerror("allocation failure 2 in dist_ui32matrix()");
+    }
+    m[i0] -= j0;
+    
+    for (i = i0 + 1; i <= i1; i++) {
+        m[i] = m[i - 1] + ncol;
+    }
+    
+    // make borders to point to first and last lines
+    m[i0 - 1] = m[i0];
+    m[i1 + 1] = m[i1];
+    
+    return m;
+}
+#endif
+
+
 
 // -------------------------------------------------------------------
@@ -66,6 +102,6 @@
 // -------------------------------------------------------------------
 {
-    free((FREE_ARG) (m[i0] + j0));
-    free((FREE_ARG) (m + i0 - 1));
+    free(m[i0] + j0);
+    free(m + i0 - 1);
 }
 
Index: soft/giet_vm/applications/rosenfeld/src-par/mca_rosenfeld.c
===================================================================
--- soft/giet_vm/applications/rosenfeld/src-par/mca_rosenfeld.c	(revision 820)
+++ soft/giet_vm/applications/rosenfeld/src-par/mca_rosenfeld.c	(revision 821)
@@ -12,19 +12,29 @@
 #include <string.h>
 #include <math.h>
-#include <user_barrier.h>
-#include <user_lock.h>
-
-#ifdef CLI
+#include <assert.h>
+#if PARMERGE
+#include <pthread.h>
+#endif
+
 #include "nrc_os_config.h"
+#include "config.h"
 #include "nrc.h"
+
+#if TARGET_OS == GIETVM
+    #include <user_barrier.h>
+    #include <user_lock.h>
+    #include <giet_config.h>
+#else
+    #include <stdbool.h>
 #endif
+
 
 #include "util.h"
 #include "ecc_common.h"
-
 #include "palette.h"
 #include "bmpNR.h"
-
+#include "clock.h"
 #include "str_ext.h"
+#include "ecc_features.h"
 
 // -----------
@@ -34,31 +44,42 @@
 #include "mca.h"
 
-extern giet_barrier_t main_barrier;
-
-// ----------------------------------
-uint32 FindRoot(uint32 * T, uint32 e)
-// ----------------------------------
+extern pthread_barrier_t main_barrier;
+extern int display_features;
+
+CLOCK_DEC;
+
+
+// -----------------------------------------
+static uint32 FindRoot(uint32 * T, uint32 e)
+// -----------------------------------------
 {
     uint32 r;
     
+    assert(e != 0);
     r = e;
     while (T[r] < r) {
         r = T[r];
     }
+    if (r == 0) {
+        printf("e = %d\n",e);
+        assert(0);
+    }
     return r;
 }
 
 
-// ---------------------------------------------------
-uint32 FindRoot_Dist(uint32 ** D, uint32 r, int shift)
-// ---------------------------------------------------
+// ----------------------------------------------------------
+static uint32 FindRoot_Dist(uint32 ** D, uint32 r, int shift)
+// ----------------------------------------------------------
 {
     uint32 e;
     uint32 e1;
     uint32 e0;
+
+    assert(r != 0);
     
     int mask = (1 << shift) - 1;
     
-    MCA_VERBOSE2(printf("FindRoot_Dist(%d) (alpha = %d) \n", r, shift));
+    MCA_VERBOSE2(printf("%s(%d, %d) \n", __func__, r, shift));
     do {
         e  = r;
@@ -66,290 +87,488 @@
         e0 = r & mask;
         r = D[e1][e0];
-        MCA_VERBOSE2(printf("FindRoot: D(%d) = D[%d,%d] = %d (alpha = %d)\n", e, e1, e0, r, shift));
+        MCA_VERBOSE2(printf("%s: D(%d) = D[%d,%d] = %d (alpha = %d)\n", __func__, e, e1, e0, r, shift));
     } while (r < e);
-    MCA_VERBOSE2(printf("FindRoot_Dist = %d \n\n", r));
+    MCA_VERBOSE2(printf("%s = %d \n\n", __func__, r));
+    assert(r != 0);
     return r;
 }
 
 
-// -----------------------------------------
-void SetRoot(uint32 * T, uint32 e, uint32 r)
-// -----------------------------------------
-{
-    while (T[e] < e) {
-        e = T[e];
-    }
-    T[e] = r;
-}
-
-
-// ----------------------------------------------------------
-void SetRoot_Dist(uint32 ** D, uint32 e, uint32 r, int shift)
-// ----------------------------------------------------------
+#if !FEATURES
+// --------------------------------------------------------------------------------
+static void SetRoot_Rosenfeld_Dist(uint32 ** D, uint32 root, uint32 eps, int shift)
+// --------------------------------------------------------------------------------
 {
     int mask = (1 << shift) - 1;
-    
-    uint32 e1 = e >> shift;
-    uint32 e0 = e & mask;
-    
-    D[e1][e0] = r;
-}
-
-
-// --------------------------------------------
-uint32 Union0(uint32 * T, uint32 ei, uint32 ej)
-// --------------------------------------------
-{
-    // version de la publication
-    // @QM : faut-il tester le cas == 0 ici aussi ?
-    uint32 ri, rj;
-    ri = (ei == 0) ? 0 : FindRoot(T, ei);
-    if (ei != ej) {
-        rj = (ej == 0) ? 0 : FindRoot(T, ej);
-        if (ri > rj) {
-            ri = rj;
-        }
-        SetRoot(T, ej, ri);
-    }
-    SetRoot(T, ei, ri);
-    return ri;
-}
-
-
-// -------------------------------------------------
-uint32 QuickUnion2(uint32 * T, uint32 e1, uint32 e2)
-// -------------------------------------------------
+    assert(root != 0 && eps != 0);
+    
+    uint32 r1 = root >> shift;
+    uint32 r0 = root & mask;
+    
+    D[r1][r0] = eps;
+}
+#endif // !FEATURES
+
+
+#if FEATURES && !PARMERGE
+// ----------------------------------------------------------------------------------------------------
+void SetRoot_Features_Rosenfeld_Dist(uint32 ** D, uint32 root, uint32 eps, int shift, RegionStats ** F)
+// ----------------------------------------------------------------------------------------------------
+{
+    assert(root != 0 && eps != 0);
+
+    MCA_VERBOSE2(printf("F(%d) += F(%d)\n", eps, root));
+    
+    int mask = (1 << shift) - 1;
+
+    // SetRoot_Rosenfeld_Dist
+    uint32 r1 = root >> shift;
+    uint32 r0 = root & mask;
+    
+    D[r1][r0] = eps;
+    
+    uint32 e1 = eps >> shift;
+    uint32 e0 = eps & mask;
+    
+    // version Dist de "RegionStats_Accumulate_Stats1_From_Index"
+    
+    // F(eps) = F(eps) U F(root)
+    
+    F[e1][e0].xmin = ui16min2(F[e1][e0].xmin, F[r1][r0].xmin);
+    F[e1][e0].xmax = ui16max2(F[e1][e0].xmax, F[r1][r0].xmax);
+    F[e1][e0].ymin = ui16min2(F[e1][e0].ymin, F[r1][r0].ymin);
+    F[e1][e0].ymax = ui16max2(F[e1][e0].ymax, F[r1][r0].ymax);
+    
+    F[e1][e0].S  += F[r1][r0].S;
+    F[e1][e0].Sx += F[r1][r0].Sx;
+    F[e1][e0].Sy += F[r1][r0].Sy;
+}
+#endif // FEATURES && !PARMERGE
+
+
+#if FEATURES && PARMERGE
+// -------------------------------------------------------------------------------------------------------------
+bool SetRoot_Parallel_Features_Rosenfeld_Dist(uint32 ** D, uint32 root, uint32 eps, int shift, RegionStats ** F)
+// -------------------------------------------------------------------------------------------------------------
+{
+    assert(root != 0 && eps != 0);
+
+    MCA_VERBOSE2(printf("F(%d) += F(%d)\n", eps, root));
+    
+    int mask = (1 << shift) - 1;
+
+    // SetRoot_Rosenfeld_Dist
+    uint32 r1 = root >> shift;
+    uint32 r0 = root & mask;
+    
+    uint32 e1 = eps >> shift;
+    uint32 e0 = eps & mask;
+
+    // Locking towards the root (first root, then eps)
+    pthread_spin_lock(&F[r1][r0].lock);
+    pthread_spin_lock(&F[e1][e0].lock);
+    // FIXME: merge these conditions later, when they both appear
+    if (D[e1][e0] != eps) {
+        // Someone change the root of epsilon, need to find the new root
+        printf("race cond 1\n");
+        pthread_spin_unlock(&F[e1][e0].lock);
+        pthread_spin_unlock(&F[r1][r0].lock);
+        return false;
+    }
+    if (D[r1][r0] != root) {
+        // Someone change the root of epsilon, need to find the new root
+        printf("race cond 2\n");
+        pthread_spin_unlock(&F[e1][e0].lock);
+        pthread_spin_unlock(&F[r1][r0].lock);
+        return false;
+    }
+
+    D[r1][r0] = eps;
+    
+    // F(eps) = F(eps) U F(root)
+    F[e1][e0].xmin = ui16min2(F[e1][e0].xmin, F[r1][r0].xmin);
+    F[e1][e0].xmax = ui16max2(F[e1][e0].xmax, F[r1][r0].xmax);
+    F[e1][e0].ymin = ui16min2(F[e1][e0].ymin, F[r1][r0].ymin);
+    F[e1][e0].ymax = ui16max2(F[e1][e0].ymax, F[r1][r0].ymax);
+    
+    F[e1][e0].S  += F[r1][r0].S;
+    F[e1][e0].Sx += F[r1][r0].Sx;
+    F[e1][e0].Sy += F[r1][r0].Sy;
+
+    pthread_spin_unlock(&F[e1][e0].lock);
+    pthread_spin_unlock(&F[r1][r0].lock);
+    return true;
+}
+#endif // FEATURES && PARMERGE
+
+
+
+#if FAST
+// --------------------------------------------------------
+static uint32 QuickUnion2(uint32 * T, uint32 e1, uint32 e2)
+// --------------------------------------------------------
 {
     // version QU de Union2
-    uint32 r1, r2, r;
-    
-    r1 = (e1 == 0) ? 0 : FindRoot(T, e1);
-    r2 = (e2 == 0) ? 0 : FindRoot(T, e2);
-    
-    r = ui32Min2(r1, r2);
-    
-    if (r1 != r) {
-        T[r1] = r; // SetRoot
-    }
-    if (r2 != r) {
-        T[r2] = r; // SetRoot
-    }
-    
-    return r;
-}
-
-
-// --------------------------------------------
-uint32 use1_QU_Rosenfeld(uint32 e1, uint32 * T)
-// --------------------------------------------
-{
-    return T[e1];
-}
-
-
-// -------------------------------------------------------
-uint32 use2_QU_Rosenfeld(uint32 e1, uint32 e2, uint32 * T)
-// -------------------------------------------------------
+    uint32 r1 = FindRoot(T, e1);
+    uint32 r2 = FindRoot(T, e2);
+    
+    assert(e1 != 0 && e2 != 0 && r1 != 0 && r2 != 0);
+    uint32 eps = ui32Min2(r1, r2);
+
+    if (r1 > eps) {
+        T[r1] = eps; // SetRoot sans besoin de remonter
+    }
+    if (r2 > eps) {
+        T[r2] = eps; // SetRoot sans besoin de remonter
+    }
+    assert(e1 != 0 && e2 != 0 && r1 != 0 && r2 != 0);
+    
+    return eps;
+}
+#endif // FAST
+
+
+#if FAST
+// ---------------------------------------------------
+static uint32 use1_QU_Rosenfeld(uint32 e1, uint32 * T)
+// ---------------------------------------------------
+{
+    return FindRoot(T, e1);
+}
+#endif // FAST
+
+
+#if FAST
+// --------------------------------------------------------------
+static uint32 use2_QU_Rosenfeld(uint32 e1, uint32 e2, uint32 * T)
+// --------------------------------------------------------------
 {
     return QuickUnion2(T, e1, e2);
 }
-
-
-// ----------------------------------------------------------------
-uint32 updateTable_Rosenfeld(uint32 * T, uint32 e, uint32 epsilon)
-// ----------------------------------------------------------------
-{
-    // notations e == v, epsilon == u avec v > u (v forcement different de u)
-    return Union0(T, e, epsilon); // original
-}
-
-
-// ----------------------------------------------------------------
-void vuse2_Rosenfeld(uint32 e1, uint32 e2, uint32 * T, uint32 ** D)
-// ----------------------------------------------------------------
-{
-    uint32 e;
-    uint32 a1;
-    uint32 a2;
-    
-    a1 = (e1 == 0) ? 0 : FindRoot(T, e1);
-    a2 = (e2 == 0) ? 0 : FindRoot(T, e2);
-    
-    if (a1 == a2) {
+#endif // FAST
+
+
+#if FAST && !FEATURES
+// ---------------------------------------------------------------------------------------
+static void vuse2_Rosenfeld_Dist(uint32 ed, uint32 el, uint32 * T, uint32 ** D, int alpha)
+// ---------------------------------------------------------------------------------------
+{
+    uint32 rd = FindRoot_Dist(D, ed, alpha);
+    
+    uint32 rl = T[el]; // car le premier acces est local
+    rl = FindRoot_Dist(D, rl, alpha);
+    
+    assert(ed != 0 && el != 0 && rd != 0 && rl != 0);
+    if (rd == rl) {
         return; // evite la backdoor
     }
     
-    // forcement positifs car appel depuis optimizedBorder qui a fait un test
-    if (a1 < a2) {
-        e = a1;
-        updateTable_Rosenfeld(T, a2, e);
+    // forcement positifs car appel depuis optimizedBorder
+    // qui a fait un test
+    if (rd < rl) {
+        SetRoot_Rosenfeld_Dist(D, rl, rd, alpha);
     }
     else {
-        e = a2;
-        updateTable_Rosenfeld(T, a1, e);
-    }
-}
-
-
-// ---------------------------------------------------------------------------
-void vuse3_Rosenfeld(uint32 e1, uint32 e2, uint32 e3, uint32 * T, uint32 ** D)
-// ---------------------------------------------------------------------------
-{
-    uint32 e;
-    uint32 a1;
-    uint32 a2;
-    uint32 a3;
-    
-    a1 = (e1 == 0) ? 0 : FindRoot(T, e1);
-    a2 = (e2 == 0) ? 0 : FindRoot(T, e2);
-    a3 = (e3 == 0) ? 0 : FindRoot(T, e3);
-    
-    if (a1 == a2 && a2 == a3) {
+        SetRoot_Rosenfeld_Dist(D, rd, rl, alpha);
+    }
+}
+#endif // FAST && !FEATURES
+
+
+#if FAST && !FEATURES
+// -----------------------------------------------------------------------------------------------------
+static void vuse3_Rosenfeld_Dist(uint32 ed1, uint32 ed2, uint32 el3, uint32 * T, uint32 ** D, int alpha)
+// -----------------------------------------------------------------------------------------------------
+{
+    uint32 r1 = FindRoot_Dist(D, ed1, alpha);
+    uint32 r2 = FindRoot_Dist(D, ed2, alpha);
+    
+    // QM
+    //uint32 r3 = FindRoot(T, el3); // local - distant
+    uint32 r3 = T[el3]; // local - distant
+    r3 = FindRoot_Dist(D, r3, alpha);
+
+    assert(ed1 != 0 && ed2 != 0 && el3 != 0 && r1 != 0 && r2 != 0 && r3 != 0);
+    
+    if (r1 == r2 && r2 == r3) {
         return;
     }
     
-    e = ui32Min3(a1, a2, a3);  // forcement positifs car appel depuis optimizedBorder qui a fait un test
-    
-    if (a1 > e) {
-        updateTable_Rosenfeld(T, a1, e);
-    }
-    a2 = T[a2];
-    if (a2 > e) {
-        updateTable_Rosenfeld(T, a2, e);
-    }
-    a3 = T[a3];
-    if (a3 > e) {
-        updateTable_Rosenfeld(T, a3, e);
-    }
-}
-
-
-// ----------------------------------------------
-uint32 solveTable_Rosenfeld(uint32 * T, uint32 ne)
-// ----------------------------------------------
-{
-    // equivalent a Flatten
-    // fermeture transitive sans pack
-    // (presence de trous dans les numeros d'etiquettes)
-    
-    uint32 e;
-    
-    for (e = 1; e <= ne; e++) {   
-        T[e] = T[T[e]];
-    }
-    return ne;
-}
-
-
-// ----------------------------------------------------------------------------------
-uint32 optimizedAccess_DT_Rosenfeld(uint32 ** E, int i, int j, uint32 * T, uint32 ne)
-// ----------------------------------------------------------------------------------
-{
-    // Decision Tree 8-connexe avec Quick-Union
-    uint32 a, b, c, d, e;
-    
-    b = E[i - 1][j];
-    if (b) {
-        e = use1_QU_Rosenfeld(b, T);
+    uint32 eps = ui32Min3(r1, r2, r3);  // forcement positifs car appel depuis optimizedBorder qui a fait un test
+    
+    if (r1 > eps) {
+        SetRoot_Rosenfeld_Dist(D, r1, eps, alpha);
+    }
+    //r2 = T[r2]; // @QM est-ce indispensable s'il n'y a pas de features ? (cf. slow no features)
+    // comment est-on sur que r2 (ou r3) est local ???
+    if (r2 > eps) {
+        SetRoot_Rosenfeld_Dist(D, r2, eps, alpha);
+    }
+    //r3 = T[r3];
+    if (r3 > eps) {
+        SetRoot_Rosenfeld_Dist(D, r3, eps, alpha);
+    }
+}
+#endif // FAST && !FEATURES
+
+
+#if FAST && FEATURES && !PARMERGE
+// -----------------------------------------------------------------------------------------------------------
+void vuse2_Features_Rosenfeld_Dist(uint32 ed, uint32 el, uint32 * T, uint32 ** D, int alpha, RegionStats ** F)
+// -----------------------------------------------------------------------------------------------------------
+{
+    assert(ed != 0 && el != 0);
+
+    uint32 rd = FindRoot_Dist(D, ed, alpha);
+    
+    uint32 rl = T[el]; // car le premier acces est local
+    assert(rl != 0);
+    rl = FindRoot_Dist(D, rl, alpha);
+    
+    assert(rd != 0 && rl != 0);
+
+    if (rd == rl) {
+        return; // evite la backdoor
+    }
+    
+    // forcement positifs car appel depuis optimizedBorder
+    // qui a fait un test
+    if (rd < rl) {
+        SetRoot_Features_Rosenfeld_Dist(D, rl, rd, alpha, F);
     }
     else {
-        c = E[i - 1][j + 1];
-        if (c) {
-            a = E[i - 1][j - 1];
+        SetRoot_Features_Rosenfeld_Dist(D, rd, rl, alpha, F);
+    }
+}
+#endif // FAST && FEATURES && !PARMERGE
+
+
+#if FAST && FEATURES && !PARMERGE
+// -------------------------------------------------------------------------------------------------------------------------
+void vuse3_Features_Rosenfeld_Dist(uint32 ed1, uint32 ed2, uint32 el3, uint32 * T, uint32 ** D, int alpha, RegionStats ** F)
+// -------------------------------------------------------------------------------------------------------------------------
+{
+    assert(ed1 != 0 && ed2 != 0 && el3 != 0);
+
+    uint32 r1 = FindRoot_Dist(D, ed1, alpha);
+    uint32 r2 = FindRoot_Dist(D, ed2, alpha);
+    
+    //uint32 r3 = FindRoot(T, el3); // local - distant
+    uint32 r3 = T[el3]; // local - distant
+    assert(r3 != 0);
+    r3 = FindRoot_Dist(D, r3, alpha);
+    
+    assert(r1 != 0 && r2 != 0 && r3 != 0);
+
+    if (r1 == r2 && r2 == r3) {
+        return;
+    }
+    
+    uint32 eps = ui32Min3(r1, r2, r3);  // forcement positifs car appel depuis optimizedBorder qui a fait un test
+    
+    if (r1 > eps) {
+        SetRoot_Features_Rosenfeld_Dist(D, r1, eps, alpha, F);
+    }
+    //r2 = T[r2];
+    if (r2 > eps && r2 != r1) {
+        SetRoot_Features_Rosenfeld_Dist(D, r2, eps, alpha, F);
+    }
+    //r3 = T[r3];
+    if (r3 > eps && r3 != r2 && r3 != r1) {
+        SetRoot_Features_Rosenfeld_Dist(D, r3, eps, alpha, F);
+    }
+}
+#endif // FAST && FEATURES && !PARMERGE
+
+
+#if FAST && FEATURES && PARMERGE
+// --------------------------------------------------------------------------------------------------------------------
+void vuse2_Parallel_Features_Rosenfeld_Dist(uint32 ed, uint32 el, uint32 * T, uint32 ** D, int alpha, RegionStats ** F)
+// --------------------------------------------------------------------------------------------------------------------
+{
+    bool ok;
+    assert(ed != 0 && el != 0);
+    uint32 rl = T[el]; // car le premier acces est local
+    assert(rl != 0);
+
+    uint32 rd;
+    
+    do {
+        rd = FindRoot_Dist(D, ed, alpha); // no lock
+        rl = FindRoot_Dist(D, rl, alpha);
+
+        assert(rd != 0 && rl != 0);
+
+        if (rd == rl) {
+            return; // evite la backdoor
+        }
+
+        // forcement positifs car appel depuis optimizedBorder
+        // qui a fait un test
+        if (rd < rl) {
+            ok = SetRoot_Parallel_Features_Rosenfeld_Dist(D, rl, rd, alpha, F);
+        }
+        else {
+            ok = SetRoot_Parallel_Features_Rosenfeld_Dist(D, rd, rl, alpha, F);
+        }
+    } while (!ok);
+}
+#endif // FAST && FEATURES && PARMERGE
+
+
+#if FAST && FEATURES && PARMERGE
+// ----------------------------------------------------------------------------------------------------------------------------------
+void vuse3_Parallel_Features_Rosenfeld_Dist(uint32 ed1, uint32 ed2, uint32 el3, uint32 * T, uint32 ** D, int alpha, RegionStats ** F)
+// ----------------------------------------------------------------------------------------------------------------------------------
+{
+    bool ok1, ok2, ok3;
+    assert(ed1 != 0 && ed2 != 0 && el3 != 0);
+
+    uint32 r1;
+    uint32 r2;
+    uint32 r3 = T[el3]; // local - distant
+    assert(r3 != 0);
+
+    do {
+        r1 = FindRoot_Dist(D, ed1, alpha);
+        r2 = FindRoot_Dist(D, ed2, alpha);
+        r3 = FindRoot_Dist(D, r3, alpha);
+    
+        assert(r1 != 0 && r2 != 0 && r3 != 0);
+
+        if (r1 == r2 && r2 == r3) {
+            return;
+        }
+    
+        uint32 eps = ui32Min3(r1, r2, r3);  // forcement positifs car appel depuis optimizedBorder qui a fait un test
+    
+        ok1 = true;
+        ok2 = true;
+        ok3 = true;
+        if (r1 > eps) {
+            ok1 = SetRoot_Parallel_Features_Rosenfeld_Dist(D, r1, eps, alpha, F);
+        }
+        if (r2 > eps && r2 != r1) {
+            ok2 = SetRoot_Parallel_Features_Rosenfeld_Dist(D, r2, eps, alpha, F);
+        }
+        if (r3 > eps && r3 != r2 && r3 != r1) {
+            ok3 = SetRoot_Parallel_Features_Rosenfeld_Dist(D, r3, eps, alpha, F);
+        }
+    } while (!(ok1 && ok2 && ok3));
+}
+#endif // FAST && FEATURES && PARMERGE
+
+
+
+
+#if FAST && !FEATURES
+// ------------------------------------------------------------------------------------------------------
+static void optimizedBorder_Rosenfeld_Dist(uint32 ** E, int i, int j, uint32 * T, uint32 ** D, int alpha)
+// ------------------------------------------------------------------------------------------------------
+{
+    uint32 a, b, c, x;
+    
+    x = E[i][j];
+    if (x) {
+        b = E[i - 1][j];
+        if (b) {
+            vuse2_Rosenfeld_Dist(b, x, T, D, alpha); // dist, local
+        }
+        else {
+            c = E[i - 1][j + 1];
+            if (c) {
+                a = E[i - 1][j - 1];
+                if (a) {
+                    vuse3_Rosenfeld_Dist(a, c, x, T, D, alpha); // dist, local
+                }
+                else {
+                    vuse2_Rosenfeld_Dist(c, x, T, D, alpha); // dist, local
+                }
+            }
+            else {
+                a = E[i - 1][j - 1];
+                if (a) {
+                    vuse2_Rosenfeld_Dist(a, x, T, D, alpha); // dist, local
+                }
+            }
+        }
+    }
+}
+#endif // FAST && !FEATURES
+
+
+#if FAST && !FEATURES
+// ---------------------------------------------------------------------------------------------------
+static void optimizedBorderLeft_Rosenfeld_Dist(uint32 ** E, int i, int j, uint32 * T, uint32 ** D, int alpha)
+// ---------------------------------------------------------------------------------------------------
+{
+    uint32 x = E[i][j];
+    if (x) {
+        uint32 b = E[i - 1][j];
+        if (b) {
+            vuse2_Rosenfeld_Dist(b, x, T, D, alpha); // dist, local
+        }
+        else {
+            uint32 c = E[i - 1][j + 1];
+            if (c) {
+                vuse2_Rosenfeld_Dist(c, x, T, D, alpha); // dist, local
+            }
+        }
+    }
+}
+#endif // FAST && !FEATURES
+
+
+#if FAST && !FEATURES
+// -----------------------------------------------------------------------------------------------------------
+static void optimizedBorderRight_Rosenfeld_Dist(uint32 ** E, int i, int j, uint32 * T, uint32 ** D, int alpha)
+// -----------------------------------------------------------------------------------------------------------
+{
+    // copie de optimizedBorder_Rosenfeld
+    // test d'existance de ex en local local
+
+    uint32 b = E[i - 1][j];
+    uint32 x = E[i][j];
+    
+    if (x) {
+        if (b) {
+            vuse2_Rosenfeld_Dist(b, x, T, D, alpha); // dist, local
+        }
+        else {
+            uint32 a = E[i - 1][j - 1];
             if (a) {
-                e = use2_QU_Rosenfeld(a, c, T);
-            }
-            else {
-                d = E[i][j - 1];
-                if (d) {
-                    e = use2_QU_Rosenfeld(c, d, T);
-                }
-                else {
-                    e = use1_QU_Rosenfeld(c, T);
-                }
-            }
-        }
-        else {
-            a = E[i - 1][j - 1];
-            if (a) {
-                e = use1_QU_Rosenfeld(a, T);
-            }
-            else {
-                d = E[i][j - 1];
-                if (d) {
-                    e = use1_QU_Rosenfeld(d, T);
-                }
-                else {
-                    e = ++ne;
-                }
-            }
-        }
-    }
-    E[i][j] = e;
-    return ne;
-}
-
-
-// ------------------------------------------------------------------------------------------
-void optimizedBorder_Rosenfeld(uint32 ** E, int i, int j, uint32 * T, uint32 ** D, int alpha)
-// ------------------------------------------------------------------------------------------
-{
-    // copie de optimizedBorder_Rosenfeld
-    uint32 a, b, c, x;
-    
-    b = E[i - 1][j];
-    x = E[i][j];
-    
-    if (b) {
-        //printf("%d = %d\n", b, x);
-        vuse2_Rosenfeld(b, x, T, D);
-    }
-    else {
-        c = E[i - 1][j + 1];
-        if (c) {
-            a = E[i - 1][j - 1];
-            if (a) {
-                //printf("%d = %d = %d\n", a, c, x);
-                vuse3_Rosenfeld(a, c, x, T, D);
-            }
-            else {
-                //printf("%d = %d\n", c, x);
-                vuse2_Rosenfeld(c, x, T, D);
-            }
-        }
-        else {
-            a = E[i - 1][j - 1];
-            if (a) {
-                //printf("%d = %d\n", a, x);
-                vuse2_Rosenfeld(a, x, T, D);
-            }
-        }
-    }
-}
-
-
-// -----------------------------------------------------------------------------------------------------------------
-void borderMerging_Fast_Rosenfeld_Dist(uint8 **X, int i, int width, uint32 ** E, uint32 * T, uint32 ** D, int alpha)
-// -----------------------------------------------------------------------------------------------------------------
-{
-    for (int j = 0; j < width; j++) {
-        if (X[i][j])  {
-            optimizedBorder_Rosenfeld(E, i, j, T, D, alpha);
-        }
-    }
-    return;
-}
-
-
-// ------------------------------------------------------------------------------------------------------------------
-void borderMerging_Slow_Rosenfeld_Dist(uint8 ** X, int i, int width, uint32 ** E, uint32 * T, uint32 ** D, int alpha)
-// ------------------------------------------------------------------------------------------------------------------
-{
-    // copie de borderMerging_Rosenfeld_UF_Fast2_8C
-    
+                vuse2_Rosenfeld_Dist(a, x, T, D, alpha); // dist, local
+            }
+        }
+    }
+}
+#endif // FAST && !FEATURES
+
+
+#if FAST && !FEATURES
+// ------------------------------------------------------------------------------------------------------------------------
+static void borderMerging_Fast_Rosenfeld_Dist(uint8 **X, int i, int width, uint32 ** E, uint32 * T, uint32 ** D, int alpha)
+// ------------------------------------------------------------------------------------------------------------------------
+{
+    // Prologue
+    optimizedBorderLeft_Rosenfeld_Dist(E, i, 0, T, D, alpha);
+    // Boucle principale
+    for (int j = 1; j < width - 1; j++) {
+        optimizedBorder_Rosenfeld_Dist(E, i, j, T, D, alpha);
+    }
+    // Epilogue
+    optimizedBorderRight_Rosenfeld_Dist(E, i, width - 1, T, D, alpha);
+}
+#endif // FAST && !FEATURES
+
+
+#if SLOW && !FEATURES
+// -------------------------------------------------------------------------------------------------------------------------
+static void borderMerging_Slow_Rosenfeld_Dist(uint8 ** X, int i, int width, uint32 ** E, uint32 * T, uint32 ** D, int alpha)
+// -------------------------------------------------------------------------------------------------------------------------
+{
     int j;
     
-    uint32 e;
-    
+    uint32 eps;
     uint32 e1, e2, e3, ex;
     uint32 r1, r2, r3, rx;
@@ -358,5 +577,5 @@
     // -- prologue --
     // --------------
-    MCA_VERBOSE2(printf("[borderMerging_Slow_Rosenfeld_Dist] i = %d\n", i));
+    MCA_VERBOSE2(printf("[%s] i = %d\n", __func__, i));
     
     j = 0;
@@ -365,13 +584,16 @@
     if (ex) {
         
-        MCA_VERBOSE2(printf("[borderMerging_Slow_Rosenfeld_Dist] j = %d\n", j));
+        MCA_VERBOSE2(printf("[%s] j = %d\n", __func__, j));
         
         e2 = E[i - 1][j];
         e3 = E[i - 1][j + 1];
-        
-        r2 = FindRoot_Dist(D, e2, alpha);
-        r3 = FindRoot_Dist(D, e3, alpha);
-        rx = FindRoot(T, ex); // we already tested that ex != 0
-        
+
+        // test pour eviter acces distant
+        r2 = e2 ? FindRoot_Dist(D, e2, alpha) : 0;
+        r3 = e3 ? FindRoot_Dist(D, e3, alpha) : 0;
+
+        rx = T[ex];
+        rx = FindRoot_Dist(D, rx, alpha);
+ 
         MCA_VERBOSE2(printf("\n"));
         MCA_VERBOSE2(printf("e2 = %4d -> %4d\n", e2, r2));
@@ -379,21 +601,20 @@
         MCA_VERBOSE2(printf("ex = %4d -> %4d\n", ex, rx));
         
-        e = ui32MinNonNul3(r2, r3, rx);
+        eps = ui32MinNonNul3(r2, r3, rx);
         
         // Quick-Union
-        if (r2 > e) {
-            SetRoot_Dist(D, r2, e, alpha);
-            MCA_VERBOSE2(printf("D[%4d] <- %d\n", r2, e));
-        }
-        if (r3 > e) {
-            SetRoot_Dist(D, r3, e, alpha);
-            MCA_VERBOSE2(printf("D[%4d] <- %d\n", r3, e));
-        }
-        if (rx > e) {
-            SetRoot(T, rx, e);
-            MCA_VERBOSE2(printf("D[%4d] <- %d\n", rx, e));
+        if (r2 > eps) {
+            SetRoot_Rosenfeld_Dist(D, r2, eps, alpha);
+            MCA_VERBOSE2(printf("D[%4d] <- %d\n", r2, eps));
+        }
+        if (r3 > eps) {
+            SetRoot_Rosenfeld_Dist(D, r3, eps, alpha);
+            MCA_VERBOSE2(printf("D[%4d] <- %d\n", r3, eps));
+        }
+        if (rx > eps) {
+            SetRoot_Rosenfeld_Dist(D, rx, eps, alpha);
+            MCA_VERBOSE2(printf("D[%4d] <- %d\n", rx, eps));
         }
         MCA_VERBOSE2(printf("\n"));
-        // attention SetRoot fait un while inutile
     }
     
@@ -408,5 +629,5 @@
         // que le cas general (pour faire un code simple)
         if (ex) {
-            MCA_VERBOSE2(printf("[borderMerging_Slow_Rosenfeld_Dist] j = %d\n", j));
+            MCA_VERBOSE2(printf("[%s] j = %d\n", __func__, j));
             
             e1 = E[i - 1][j - 1];
@@ -414,9 +635,12 @@
             e3 = E[i - 1][j + 1];
         
-            r1 = FindRoot_Dist(D, e1, alpha);
-            r2 = FindRoot_Dist(D, e2, alpha);
-            r3 = FindRoot_Dist(D, e3, alpha);
-            rx = FindRoot(T, ex); // we already tested that ex != 0
-        
+            // test pour eviter acces distant
+            r1 = e1 ? FindRoot_Dist(D, e1, alpha) : 0;
+            r2 = e2 ? FindRoot_Dist(D, e2, alpha) : 0;
+            r3 = e3 ? FindRoot_Dist(D, e3, alpha) : 0;
+
+            rx = T[ex];
+            rx = FindRoot_Dist(D, rx, alpha);
+
             MCA_VERBOSE2(printf("\n"));
             MCA_VERBOSE2(printf("e1 = %4d -> %4d\n", e1, r1));
@@ -425,24 +649,22 @@
             MCA_VERBOSE2(printf("ex = %4d -> %4d\n", ex, rx));
             
-            e = ui32MinNonNul4(r1, r2, r3, rx);
+            eps = ui32MinNonNul4(r1, r2, r3, rx);
             
             // Quick-Union
-            if (r1 > e) {
-                SetRoot_Dist(D, r1, e, alpha);
-                MCA_VERBOSE2(printf("D[%4d] <- %d\n", r1, e));
-            }
-            if (r2 > e) {
-                SetRoot_Dist(D, r2, e, alpha);
-                MCA_VERBOSE2(printf("D[%4d] <- %d\n", r2, e));
-            }
-            if (r3 > e) {
-                SetRoot_Dist(D, r3, e, alpha);
-                MCA_VERBOSE2(printf("D[%4d] <- %d\n", r3, e));
-            }
-            if (rx > e) {
-                // @QM pourquoi pas T[e] = rx; ?
-                //SetRoot(T, rx, e); 
-                T[e] = rx;
-                MCA_VERBOSE2(printf("D[%4d] <- %d\n", rx, e));
+            if (r1 > eps) {
+                SetRoot_Rosenfeld_Dist(D, r1, eps, alpha);
+                MCA_VERBOSE2(printf("D[%4d] <- %d\n", r1, eps));
+            }
+            if (r2 > eps) {
+                SetRoot_Rosenfeld_Dist(D, r2, eps, alpha);
+                MCA_VERBOSE2(printf("D[%4d] <- %d\n", r2, eps));
+            }
+            if (r3 > eps) {
+                SetRoot_Rosenfeld_Dist(D, r3, eps, alpha);
+                MCA_VERBOSE2(printf("D[%4d] <- %d\n", r3, eps));
+            }
+            if (rx > eps) {
+                SetRoot_Rosenfeld_Dist(D, rx, eps, alpha);
+                MCA_VERBOSE2(printf("D[%4d] <- %d\n", rx, eps));
             }
             MCA_VERBOSE2(printf("\n"));
@@ -460,13 +682,16 @@
     if (ex) {
         
-        MCA_VERBOSE2(printf("[borderMerging_Slow_Rosenfeld_Dist] j = %d\n", j));
+        MCA_VERBOSE2(printf("[%s] j = %d\n", __func__, j));
         
         e1 = E[i - 1][j - 1];
         e2 = E[i - 1][j];
-        
-        r1 = FindRoot_Dist(D, e1, alpha);
-        r2 = FindRoot_Dist(D, e2, alpha);
-        rx = FindRoot(T, ex); // we already tested that ex != 0
-        
+
+        // test pour eviter acces distant
+        r1 = e1 ? FindRoot_Dist(D, e1, alpha) : 0;
+        r2 = e2 ? FindRoot_Dist(D, e2, alpha) : 0;
+
+        rx = T[ex];
+        rx = FindRoot_Dist(D, rx, alpha);
+
         MCA_VERBOSE2(printf("\n"));
         MCA_VERBOSE2(printf("e1 = %4d -> %4d\n", e1, r1));
@@ -474,18 +699,18 @@
         MCA_VERBOSE2(printf("ex = %4d -> %4d\n", ex, rx));
         
-        e = ui32MinNonNul3(r1, r2, rx);
+        eps = ui32MinNonNul3(r1, r2, rx);
         
         // Quick-Union
-        if (r1 > e) {
-            SetRoot_Dist(D, r1, e, alpha);
-            MCA_VERBOSE2(printf("D[%4d] <- %d\n", r1, e));
-        }
-        if (r2 > e) {
-            SetRoot_Dist(D, r2, e, alpha);
-            MCA_VERBOSE2(printf("D[%4d] <- %d\n", r2, e));
-        }
-        if (rx > e) {
-            SetRoot(T, rx, e);
-            MCA_VERBOSE2(printf("D[%4d] <- %d\n", rx, e));
+        if (r1 > eps) {
+            SetRoot_Rosenfeld_Dist(D, r1, eps, alpha);
+            MCA_VERBOSE2(printf("D[%4d] <- %d\n", r1, eps));
+        }
+        if (r2 > eps) {
+            SetRoot_Rosenfeld_Dist(D, r2, eps, alpha);
+            MCA_VERBOSE2(printf("D[%4d] <- %d\n", r2, eps));
+        }
+        if (rx > eps) {
+            SetRoot_Rosenfeld_Dist(D, rx, eps, alpha);
+            MCA_VERBOSE2(printf("D[%4d] <- %d\n", rx, eps));
         }
         MCA_VERBOSE2(printf("\n"));
@@ -493,17 +718,441 @@
     return;
 }
-
-
-// -------------------------------------------------------------------------------------------------------------
-void borderMerging_Rosenfeld_Dist(uint8 ** X, int i, int width, uint32 ** E, uint32 * T, uint32 ** D, int alpha)
-// -------------------------------------------------------------------------------------------------------------
-{
+#endif // SLOW && !FEATURES
+
+
+#if SLOW && FEATURES
+// ----------------------------------------------------------------------------------------------------------------------------------------------------
+static void borderMerging_Slow_Features_Rosenfeld_Dist(uint8 ** X, int i, int width, uint32 ** E, uint32 * T, uint32 ** D, int alpha, RegionStats ** F)
+// ----------------------------------------------------------------------------------------------------------------------------------------------------
+{
+    int j = 0;
+    
+    uint32 eps;
+    
+    uint32 e1, e2, e3, ex;
+    uint32 r1, r2, r3, rx;
+    
+    // --------------
+    // -- prologue --
+    // --------------
+    MCA_VERBOSE2(printf("[%s] i = %d\n", __func__, i));
+    
+    ex = E[i][j];
+    
+    if (ex) {
+        
+        MCA_VERBOSE2(printf("[%s] j = %d\n", __func__, j));
+        
+        e2 = E[i - 1][j];
+        e3 = E[i - 1][j + 1];
+        
+        if (e2 || e3) {
+        
+            // test pour eviter acces distant
+            r2 = e2 ? FindRoot_Dist(D, e2, alpha) : 0;
+            r3 = e3 ? FindRoot_Dist(D, e3, alpha) : 0;
+
+            rx = T[ex];
+            rx = FindRoot_Dist(D, rx, alpha);
+            
+            eps = ui32MinNonNul3(r2, r3, rx);
+            
+            MCA_VERBOSE2(printf("\n"));
+            MCA_VERBOSE2(printf("e2  = %5d -> r2 = %5d\n", e2, r2));
+            MCA_VERBOSE2(printf("e3  = %5d -> r3 = %5d\n", e3, r3));
+            MCA_VERBOSE2(printf("ex  = %5d -> rx = %5d\n", ex, rx));
+            MCA_VERBOSE2(printf("eps = %5d\n", eps));
+            
+            // Quick-Union
+            // @QM
+            if (r2 > eps) {
+                SetRoot_Features_Rosenfeld_Dist(D, r2, eps, alpha, F);
+                MCA_VERBOSE2(printf("D[%5d] <- %d\n", r2, eps));
+            }
+            if (r3 > 0) {
+                r3 = FindRoot_Dist(D, r3, alpha);
+            }
+            // Pour le cas oÃ¹ r2 == r3, il ne faut pas ajouter deux fois les features
+            //if (r3 > eps && r3 != r2) {
+            if (r3 > eps) {
+                SetRoot_Features_Rosenfeld_Dist(D, r3, eps, alpha, F);
+                MCA_VERBOSE2(printf("D[%5d] <- %d\n", r3, eps));
+            }
+            rx = FindRoot_Dist(D, rx, alpha);
+            //if (rx > eps && rx != r3 && rx != r2) {
+            if (rx > eps) {
+                SetRoot_Features_Rosenfeld_Dist(D, rx, eps, alpha, F);
+                MCA_VERBOSE2(printf("D[%5d] <- %d\n", rx, eps));
+            }
+            MCA_VERBOSE2(printf("---------------------------\n"));
+        }
+    }
+    
+    // -----------------------
+    // -- boucle principale --
+    // -----------------------
+    
+    for (j = 0 + 1; j < width - 1; j++) {
+        
+        ex = E[i][j];
+        
+        if (ex) {
+            
+            MCA_VERBOSE2(printf("[%s] j = %d\n", __func__, j));
+            
+            e1 = E[i - 1][j - 1];
+            e2 = E[i - 1][j];
+            e3 = E[i - 1][j + 1];
+            
+            if (e1 || e2 || e3) {
+                // test pour eviter un acces distant
+                r1 = e1 ? FindRoot_Dist(D, e1, alpha) : 0;
+                r2 = e2 ? FindRoot_Dist(D, e2, alpha) : 0;
+                r3 = e3 ? FindRoot_Dist(D, e3, alpha) : 0;
+
+                rx = T[ex];
+                rx = FindRoot_Dist(D, rx, alpha);
+                
+                eps = ui32MinNonNul4(r1, r2, r3, rx);
+
+                MCA_VERBOSE2(printf("\n"));
+                MCA_VERBOSE2(printf("e1  = %5d -> r1 = %5d\n", e1, r1));
+                MCA_VERBOSE2(printf("e2  = %5d -> r2 = %5d\n", e2, r2));
+                MCA_VERBOSE2(printf("e3  = %5d -> r3 = %5d\n", e3, r3));
+                MCA_VERBOSE2(printf("ex  = %5d -> rx = %5d\n", ex, rx));
+                MCA_VERBOSE2(printf("eps = %5d\n", eps));
+                
+                // Quick-Union
+                // @QM
+                if (r1 > eps) {
+                    SetRoot_Features_Rosenfeld_Dist(D, r1, eps, alpha, F);
+                    MCA_VERBOSE2(printf("D[%5d] <- %d\n", r1, eps));
+                }
+                if (r2 > 0) {
+                    r2 = FindRoot_Dist(D, r2, alpha);
+                }
+                //if (r2 > eps && r2 != r1) {
+                if (r2 > eps) {
+                    SetRoot_Features_Rosenfeld_Dist(D, r2, eps, alpha, F);
+                    MCA_VERBOSE2(printf("D[%5d] <- %d\n", r2, eps));
+                }
+                if (r3 > 0) {
+                    r3 = FindRoot_Dist(D, r3, alpha);
+                }
+                //if (r3 > eps && r3 != r2 && r3 != r1) {
+                if (r3 > eps) {
+                    SetRoot_Features_Rosenfeld_Dist(D, r3, eps, alpha, F);
+                    MCA_VERBOSE2(printf("D[%5d] <- %d\n", r3, eps));
+                }
+                rx = FindRoot_Dist(D, rx, alpha);
+                //if (rx > eps && rx != r3 && rx != r2 && rx != r1) {
+                if (rx > eps) {
+                    SetRoot_Features_Rosenfeld_Dist(D, rx, eps, alpha, F);
+                    MCA_VERBOSE2(printf("D[%5d] <- %d\n", rx, eps));
+                }
+                MCA_VERBOSE2(puts("---------------------------\n"));
+                
+                // attention SetRoot fait un while inutile
+            }
+        }
+    }
+    
+    // --------------
+    // -- epilogue --
+    // --------------
+    
+    j = width - 1;
+    ex = E[i][j];
+    
+    if (ex) {
+        
+        MCA_VERBOSE2(printf("[%s] j = %d\n", __func__, j));
+        
+        e1 = E[i - 1][j - 1];
+        e2 = E[i - 1][j];
+        
+        if (e1 || e2) {
+        
+            // test pour eviter acces distant
+            r1 = e1 ? FindRoot_Dist(D, e1, alpha) : 0;
+            r2 = e2 ? FindRoot_Dist(D, e2, alpha) : 0;
+
+            rx = T[ex];
+            rx = FindRoot_Dist(D, rx, alpha);
+            
+            eps = ui32MinNonNul3(r1, r2, rx);
+            
+            MCA_VERBOSE2(printf("\n"));
+            MCA_VERBOSE2(printf("e1  = %5d -> r1 = %5d\n", e1, r1));
+            MCA_VERBOSE2(printf("e2  = %5d -> r2 = %5d\n", e2, r2));
+            MCA_VERBOSE2(printf("ex  = %5d -> rx = %5d\n", ex, rx));
+            MCA_VERBOSE2(printf("eps = %5d\n", eps));
+            
+            // Quick-Union
+            if (r1 > eps) {
+                SetRoot_Features_Rosenfeld_Dist(D, r1, eps, alpha, F);
+                MCA_VERBOSE2(printf("D[%5d] <- %d\n", r1, eps));
+            }
+            if (r2 > 0) {
+                r2 = FindRoot_Dist(D, r2, alpha);
+            }
+            //if (r2 > eps && r2 != r1) {
+            if (r2 > eps) {
+                SetRoot_Features_Rosenfeld_Dist(D, r2, eps, alpha, F);
+                MCA_VERBOSE2(printf("D[%5d] <- %d\n", r2, eps));
+            }
+            rx = FindRoot_Dist(D, rx, alpha);
+            //if (rx > eps && rx != r2 && rx != r1) {
+            if (rx > eps) {
+                SetRoot_Features_Rosenfeld_Dist(D, rx, eps, alpha, F);
+                MCA_VERBOSE2(printf("D[%5d] <- %d\n", rx, eps));
+            }
+            MCA_VERBOSE2(printf("---------------------------\n"));
+        }
+    }
+    return;
+}
+#endif // SLOW && FEATURES
+
+
+#if FAST && FEATURES && !PARMERGE
+// --------------------------------------------------------------------------------------------------------------------------
+void optimizedBorder_Features_Rosenfeld_Dist(uint32 ** E, int i, int j, uint32 * T, uint32 ** D, int alpha, RegionStats ** F)
+// --------------------------------------------------------------------------------------------------------------------------
+{
+    // copie de optimizedBorder_Rosenfeld
+    uint32 a, b, c, x;
+    
+    x = E[i][j];
+    
+    if (x) {
+        b = E[i - 1][j];
+        if (b) {
+            vuse2_Features_Rosenfeld_Dist(b, x, T, D, alpha, F); // dist, local
+        }
+        else {
+            c = E[i - 1][j + 1];
+            if (c) {
+                a = E[i - 1][j - 1];
+                if (a) {
+                    vuse3_Features_Rosenfeld_Dist(a, c, x, T, D, alpha, F); // dist, local
+                }
+                else {
+                    vuse2_Features_Rosenfeld_Dist(c, x, T, D, alpha, F); // dist, local
+                }
+            }
+            else {
+                a = E[i - 1][j - 1];
+                if (a) {
+                    vuse2_Features_Rosenfeld_Dist(a, x, T, D, alpha, F); // dist, local
+                }
+            }
+        }
+    }
+}
+#endif // FAST && FEATURES && !PARMERGE
+
+
+#if FAST && FEATURES && !PARMERGE
+// ------------------------------------------------------------------------------------------------------------------------------
+void optimizedBorderLeft_Features_Rosenfeld_Dist(uint32 ** E, int i, int j, uint32 * T, uint32 ** D, int alpha, RegionStats ** F)
+// ------------------------------------------------------------------------------------------------------------------------------
+{
+    uint32 x = E[i][j];
+    
+    if (x) {
+        uint32 b = E[i - 1][j];
+        if (b) {
+            vuse2_Features_Rosenfeld_Dist(b, x, T, D, alpha, F); // dist, local
+        }
+        else {
+            uint32 c = E[i - 1][j + 1];
+            if (c) {
+                vuse2_Features_Rosenfeld_Dist(c, x, T, D, alpha, F); // dist, local
+            }
+        }
+    }
+}
+#endif // FAST && FEATURES && !PARMERGE
+
+
+#if FAST && FEATURES && !PARMERGE
+// -------------------------------------------------------------------------------------------------------------------------------
+void optimizedBorderRight_Features_Rosenfeld_Dist(uint32 ** E, int i, int j, uint32 * T, uint32 ** D, int alpha, RegionStats ** F)
+// -------------------------------------------------------------------------------------------------------------------------------
+{
+    // copie de optimizedBorder_Rosenfeld
+    // test d'existance de ex en local local
+    
+    uint32 x = E[i][j];
+    
+    if (x) {
+        uint32 b = E[i - 1][j];
+        if (b) {
+            vuse2_Features_Rosenfeld_Dist(b, x, T, D, alpha, F); // dist, local
+        }
+        else {
+            uint32 a = E[i - 1][j - 1];
+            if (a) {
+                vuse2_Features_Rosenfeld_Dist(a, x, T, D, alpha, F); // dist, local
+            }
+        }
+    }
+}
+#endif // FAST && FEATURES && !PARMERGE
+
+
+#if FAST && FEATURES && PARMERGE
+// -----------------------------------------------------------------------------------------------------------------------------------
+void optimizedBorder_Parallel_Features_Rosenfeld_Dist(uint32 ** E, int i, int j, uint32 * T, uint32 ** D, int alpha, RegionStats ** F)
+// -----------------------------------------------------------------------------------------------------------------------------------
+{
+    // copie de optimizedBorder_Rosenfeld
+    uint32 a, b, c, x;
+    
+    x = E[i][j];
+    
+    if (x) {
+        b = E[i - 1][j];
+        if (b) {
+            vuse2_Parallel_Features_Rosenfeld_Dist(b, x, T, D, alpha, F); // dist, local
+        }
+        else {
+            c = E[i - 1][j + 1];
+            if (c) {
+                a = E[i - 1][j - 1];
+                if (a) {
+                    vuse3_Parallel_Features_Rosenfeld_Dist(a, c, x, T, D, alpha, F); // dist, local
+                }
+                else {
+                    vuse2_Parallel_Features_Rosenfeld_Dist(c, x, T, D, alpha, F); // dist, local
+                }
+            }
+            else {
+                a = E[i - 1][j - 1];
+                if (a) {
+                    vuse2_Parallel_Features_Rosenfeld_Dist(a, x, T, D, alpha, F); // dist, local
+                }
+            }
+        }
+    }
+}
+#endif // FAST && FEATURES && PARMERGE
+
+
+#if FAST && FEATURES && PARMERGE
+// ---------------------------------------------------------------------------------------------------------------------------------------
+void optimizedBorderLeft_Parallel_Features_Rosenfeld_Dist(uint32 ** E, int i, int j, uint32 * T, uint32 ** D, int alpha, RegionStats ** F)
+// ---------------------------------------------------------------------------------------------------------------------------------------
+{
+    uint32 x = E[i][j];
+    
+    if (x) {
+        uint32 b = E[i - 1][j];
+        if (b) {
+            vuse2_Parallel_Features_Rosenfeld_Dist(b, x, T, D, alpha, F); // dist, local
+        }
+        else {
+            uint32 c = E[i - 1][j + 1];
+            if (c) {
+                vuse2_Parallel_Features_Rosenfeld_Dist(c, x, T, D, alpha, F); // dist, local
+            }
+        }
+    }
+}
+#endif // FAST && FEATURES && PARMERGE
+
+
+#if FAST && FEATURES && PARMERGE
+// ----------------------------------------------------------------------------------------------------------------------------------------
+void optimizedBorderRight_Parallel_Features_Rosenfeld_Dist(uint32 ** E, int i, int j, uint32 * T, uint32 ** D, int alpha, RegionStats ** F)
+// ----------------------------------------------------------------------------------------------------------------------------------------
+{
+    // copie de optimizedBorder_Rosenfeld
+    // test d'existance de ex en local local
+    
+    uint32 x = E[i][j];
+    
+    if (x) {
+        uint32 b = E[i - 1][j];
+        if (b) {
+            vuse2_Parallel_Features_Rosenfeld_Dist(b, x, T, D, alpha, F); // dist, local
+        }
+        else {
+            uint32 a = E[i - 1][j - 1];
+            if (a) {
+                vuse2_Parallel_Features_Rosenfeld_Dist(a, x, T, D, alpha, F); // dist, local
+            }
+        }
+    }
+}
+#endif // FAST && FEATURES && PARMERGE
+
+
+#if FAST && FEATURES
+// ---------------------------------------------------------------------------------------------------------------------------------------------
+void borderMerging_Fast_Features_Rosenfeld_Dist(uint8 ** X, int i, int width, uint32 ** E, uint32 * T, uint32 ** D, int alpha, RegionStats ** F)
+// ---------------------------------------------------------------------------------------------------------------------------------------------
+{
+    MCA_VERBOSE2(printf("[%s]", __func__));
+    
+#if PARMERGE
+    optimizedBorderLeft_Parallel_Features_Rosenfeld_Dist(E, i, 0, T, D, alpha, F);
+#else
+    optimizedBorderLeft_Features_Rosenfeld_Dist(E, i, 0, T, D, alpha, F);
+#endif
+    
+    for (int j = 1; j < width - 1; j++) {
+#if PARMERGE
+        optimizedBorder_Parallel_Features_Rosenfeld_Dist(E, i, j, T, D, alpha, F);
+#else
+        optimizedBorder_Features_Rosenfeld_Dist(E, i, j, T, D, alpha, F);
+#endif
+    }
+    
+#if PARMERGE
+    optimizedBorderRight_Parallel_Features_Rosenfeld_Dist(E, i, width - 1, T, D, alpha, F);
+#else
+    optimizedBorderRight_Features_Rosenfeld_Dist(E, i, width - 1, T, D, alpha, F);
+#endif
+}
+#endif // FAST && FEATURES
+
+
+#if !FEATURES
+// --------------------------------------------------------------------------------------------------------------------
+static void borderMerging_Rosenfeld_Dist(uint8 ** X, int i, int width, uint32 ** E, uint32 * T, uint32 ** D, int alpha)
+// --------------------------------------------------------------------------------------------------------------------
+{
+#if SLOW
     borderMerging_Slow_Rosenfeld_Dist(X, i, width, E, T, D, alpha);
-}
-
-
-// ---------------------------------------------------------------------------------------------
-uint32 line0Labeling_Rosenfeld(uint8 ** X, int i, int width, uint32 ** E, uint32 * T, uint32 ne)
-// ---------------------------------------------------------------------------------------------
+#elif FAST
+    borderMerging_Fast_Rosenfeld_Dist(X, i, width, E, T, D, alpha);
+#else
+#error "Please define SLOW or FAST for the Rosenfeld version"
+#endif
+}
+#endif // !FEATURES
+
+
+#if FEATURES
+// -----------------------------------------------------------------------------------------------------------------------------------------------
+static void borderMerging_Features_Rosenfeld_Dist(uint8 ** X, int i, int width, uint32 ** E, uint32 * T, uint32 ** D, int alpha, RegionStats ** F)
+// -----------------------------------------------------------------------------------------------------------------------------------------------
+{
+#if SLOW
+    borderMerging_Slow_Features_Rosenfeld_Dist(X, i, width, E, T, D, alpha, F);
+#elif FAST
+    borderMerging_Fast_Features_Rosenfeld_Dist(X, i, width, E, T, D, alpha, F);
+#else
+#error "Please define SLOW or FAST for the Rosenfeld version"
+#endif
+}
+#endif // FEATURES
+
+
+// ----------------------------------------------------------------------------------------------------
+static uint32 line0Labeling_Rosenfeld(uint8 ** X, int i, int width, uint32 ** E, uint32 * T, uint32 ne)
+// ----------------------------------------------------------------------------------------------------
 {
     int j;
@@ -542,7 +1191,8 @@
 
 
-// -------------------------------------------------------------------------------------------------
-uint32 lineLabeling_Slow_Rosenfeld(uint8 ** X, int i, int width, uint32 ** E, uint32 * T, uint32 ne)
-// -------------------------------------------------------------------------------------------------
+#if SLOW
+// --------------------------------------------------------------------------------------------------------
+static uint32 lineLabeling_Slow_Rosenfeld(uint8 ** X, int i, int width, uint32 ** E, uint32 * T, uint32 ne)
+// --------------------------------------------------------------------------------------------------------
 {
     // version lineLabeling_Rosenfeld_UF_QU_8C avec Quick-Union
@@ -633,5 +1283,4 @@
                     
                     e = ui32MinNonNul4(r1, r2, r3, r4);
-                    giet_pthread_assert(e != 0, "e = 0\n");
                     
                     // Quick-Union
@@ -707,16 +1356,137 @@
     return ne;
 }
-
-
-// -------------------------------------------------------------------------------------------------
-uint32 lineLabeling_Fast_Rosenfeld(uint8 ** X, int i, int width, uint32 ** E, uint32 * T, uint32 ne)
-// -------------------------------------------------------------------------------------------------
-{
+#endif // SLOW
+
+
+#if FAST
+// ---------------------------------------------------------------------------------------------
+static uint32 optimizedAccessLeft_DT_Rosenfeld(uint32 ** E, int i, int j, uint32 * T, uint32 ne)
+// ---------------------------------------------------------------------------------------------
+{
+    // Decision Tree 8-connexe avec Quick-Union
+    uint32 b, c, e;
+    
+    b = E[i - 1][j];
+    if (b) {
+        e = use1_QU_Rosenfeld(b, T);
+    }
+    else {
+        c = E[i - 1][j + 1];
+        if (c) {
+            e = use1_QU_Rosenfeld(c, T);
+        }
+        else {
+            e = ++ne;
+        }
+    }
+    E[i][j] = e;
+    return ne;
+}
+#endif // FAST
+
+
+#if FAST
+// ----------------------------------------------------------------------------------------------
+static uint32 optimizedAccessRight_DT_Rosenfeld(uint32 ** E, int i, int j, uint32 * T, uint32 ne)
+// ----------------------------------------------------------------------------------------------
+{
+    // Decision Tree 8-connexe avec Quick-Union
+    uint32 a, b, d, e;
+    
+    b = E[i - 1][j];
+    if (b) {
+        e = use1_QU_Rosenfeld(b, T);
+    }
+    else {
+        a = E[i - 1][j - 1];
+        if (a) {
+            e = use1_QU_Rosenfeld(a, T);
+        }
+        else {
+            d = E[i][j - 1];
+            if (d) {
+                e = use1_QU_Rosenfeld(d, T);
+            }
+            else {
+                e = ++ne;
+            }
+        }
+    }
+    E[i][j] = e;
+    return ne;
+}
+#endif // FAST
+
+
+#if FAST
+// -----------------------------------------------------------------------------------------
+static uint32 optimizedAccess_DT_Rosenfeld(uint32 ** E, int i, int j, uint32 * T, uint32 ne)
+// -----------------------------------------------------------------------------------------
+{
+    // Decision Tree 8-connexe avec Quick-Union
+    uint32 a, b, c, d, e;
+    
+    b = E[i - 1][j];
+    if (b) {
+        e = use1_QU_Rosenfeld(b, T);
+    }
+    else {
+        c = E[i - 1][j + 1];
+        if (c) {
+            a = E[i - 1][j - 1];
+            if (a) {
+                e = use2_QU_Rosenfeld(a, c, T);
+            }
+            else {
+                d = E[i][j - 1];
+                if (d) {
+                    e = use2_QU_Rosenfeld(c, d, T);
+                }
+                else {
+                    e = use1_QU_Rosenfeld(c, T);
+                }
+            }
+        }
+        else {
+            a = E[i - 1][j - 1];
+            if (a) {
+                e = use1_QU_Rosenfeld(a, T);
+            }
+            else {
+                d = E[i][j - 1];
+                if (d) {
+                    e = use1_QU_Rosenfeld(d, T);
+                }
+                else {
+                    e = ++ne;
+                }
+            }
+        }
+    }
+    E[i][j] = e;
+    return ne;
+}
+#endif // FAST
+
+
+
+#if FAST
+// --------------------------------------------------------------------------------------------------------
+static uint32 lineLabeling_Fast_Rosenfeld(uint8 ** X, int i, int width, uint32 ** E, uint32 * T, uint32 ne)
+// --------------------------------------------------------------------------------------------------------
+{
+    uint8 x;
     // avec DT et QU
-    int j;
-    uint8 x;
-    
-    for (j = 0; j < width; j++) {
-        x = X[i][j];
+    // Left Border
+    x = X[i][0];
+    if (x) {
+        ne = optimizedAccessLeft_DT_Rosenfeld(E, i, 0, T, ne);
+    }
+    else {
+        E[i][0] = 0;
+    }
+    // Middle
+    for (int j = 1; j < width - 1; j++) {
+        uint8 x = X[i][j];
         if (x) {
             ne = optimizedAccess_DT_Rosenfeld(E, i, j, T, ne);
@@ -726,20 +1496,34 @@
         }
     }
+    // Right Border
+    x = X[i][width - 1];
+    if (x) {
+        ne = optimizedAccessRight_DT_Rosenfeld(E, i, width - 1, T, ne);
+    }
+    else {
+        E[i][width - 1] = 0;
+    }
     return ne;
 }
-
-
-// --------------------------------------------------------------------------------------------
-uint32 lineLabeling_Rosenfeld(uint8 ** X, int i, int width, uint32 ** E, uint32 * T, uint32 ne)
-// --------------------------------------------------------------------------------------------
-{
+#endif // FAST
+
+
+// ---------------------------------------------------------------------------------------------------
+static uint32 lineLabeling_Rosenfeld(uint8 ** X, int i, int width, uint32 ** E, uint32 * T, uint32 ne)
+// ---------------------------------------------------------------------------------------------------
+{
+#if SLOW
     return lineLabeling_Slow_Rosenfeld(X, i, width, E, T, ne);
-    //return lineLabeling_Fast_Rosenfeld(X, i, width, E, T, ne);
-}
-
-
-// ----------------------------------------------------------------
-uint32 countTable_Range_Rosenfeld(uint32 * T, uint32 e0, uint32 e1)
-// ----------------------------------------------------------------
+#elif FAST
+    return lineLabeling_Fast_Rosenfeld(X, i, width, E, T, ne);
+#else
+#error "Please define SLOW or FAST for the Rosenfeld version"
+#endif
+}
+
+
+// -----------------------------------------------------------------------
+static uint32 countTable_Range_Rosenfeld(uint32 * T, uint32 e0, uint32 e1)
+// -----------------------------------------------------------------------
 {
     uint32 e;
@@ -755,7 +1539,8 @@
 
 
-// --------------------------------------------------------------
-void solveTable_Range_Rosenfeld(uint32 * T, uint32 e0, uint32 e1)
-// --------------------------------------------------------------
+#if !FEATURES
+// ---------------------------------------------------------------------
+static void solveTable_Range_Rosenfeld(uint32 * T, uint32 e0, uint32 e1)
+// ---------------------------------------------------------------------
 {
     uint32 e, r;
@@ -766,8 +1551,29 @@
             T[e] = r; // racine de la classe d'equivalence
         }
-    }    
-}
-
-
+    }
+}
+#endif // !FEATURES
+
+
+#if FEATURES
+// ----------------------------------------------------------------------------------------------------------
+static void solveTable_solveFeatures_Range_Rosenfeld(uint32 * T, uint32 e0, uint32 e1, RegionStats * Stats)
+// ----------------------------------------------------------------------------------------------------------
+{
+    uint32 e, r;
+    
+    for (e = e0; e <= e1; e++) {
+        r = T[T[e]];
+        assert(r != 0);
+        if (r < e) {
+            T[e] = r; // racine de la classe d'equivalence
+            RegionStats_Accumulate_Stats1_From_Index(Stats, r, e);
+        }
+    }
+}
+#endif // FEATURES
+
+
+#if !FEATURES
 // -------------------------------------
 void MCA_Label_Rosenfeld_PAR1(MCA * mca)
@@ -775,9 +1581,9 @@
 {
     if (mca->p == 0) { 
-        MCA_VERBOSE1(printf("------------------------------\n"));
-        MCA_VERBOSE1(printf("-- MCA_Label_Rosenfeld_PAR1 --\n"));
-        MCA_VERBOSE1(printf("------------------------------\n"));
-    }
-    
+        printf("*** %s ***\n", __func__);
+    }
+    
+    CLOCK_THREAD_START_STEP(mca->p, 0);
+
     int i0 = mca->i0;
     int i1 = mca->i1;
@@ -795,5 +1601,4 @@
     if (mca->p == 0) {
         set_ui32vector_j(T, e0 - 1, e1); // car e0 = 1, on a besoin que T[0] = 0 pour FindRoot
-        // @QM : maintenant que c'est testÃ© partout, en a-t-on encore besoin ? A priori non (a tester)
     }
     else {
@@ -809,5 +1614,5 @@
 
     MCA_VERBOSE2(display_ui32matrix_positive(E, i0, i1, 0, width - 1, 5, "Ep"); printf("\n"));
-    if (mca->p == 0) { 
+    if (mca->p == 0) {
         MCA_VERBOSE2(display_ui32vector_number(T, e0, ne, "%5d", "Tp_avant"));
     }
@@ -815,14 +1620,18 @@
     // fermeture transitive sans pack
     solveTable_Range_Rosenfeld(T, e0, ne);
-    nr = countTable_Range_Rosenfeld(T, e0, ne);
     mca->ne = ne; // Plus grande etiquette de l'intervalle [e0..e1]
 
+    MCA_VERBOSE2(nr = countTable_Range_Rosenfeld(T, e0, ne));
     MCA_VERBOSE2(printf("p = %d : e = [%d..%d] -> ne = %d -> nr = %d\n", mca->p, e0, ne, (ne - e0 + 1), nr));
-    if (mca->p == 0) { 
+    if (mca->p == 0) {
         MCA_VERBOSE2(display_ui32vector_number(T, e0, ne, "%5d", "Tp_apres"));
     }
-}
-
-
+    
+    CLOCK_THREAD_END_STEP(mca->p, 0);
+}
+#endif // !FEATURES
+
+
+#if !FEATURES
 // -------------------------------------
 void MCA_Label_Rosenfeld_PYR2(MCA * mca)
@@ -830,17 +1639,9 @@
 {
     // input
-    int np = mca->mca->np;
-    
-    // variables
-    int n = np;
-    int nb_level = i32log2(np);
-    if ((1 << nb_level) < np) {
-        nb_level++; // correction pour traiter n non puissance de 2
-    }
+    int p = mca->p;
+    int nb_level = mca->nb_level;
 
     if (mca->p == 0) {
-        MCA_VERBOSE1(printf("------------------------------\n"));
-        MCA_VERBOSE1(printf("-- MCA_Label_Rosenfeld_PYR2 --\n"));
-        MCA_VERBOSE1(printf("------------------------------\n"));
+        printf("*** %s ***\n", __func__);
     }
     
@@ -862,23 +1663,33 @@
     uint32 ** D = mca->D;
 
-    // @QM
-    // en fait, c'est compliquÃ©.
-    // On pourrait optimiser en faisant faire un "break" aux procs qui n'ont plus jamais
-    // Ã  faire d'itÃ©ration, mais le problÃšme est alors qu'il faut utiliser des barriÃšres avec
-    // un nombre de procs Ã  attendre diffÃ©rent Ã  chaque fois, et qu'il faut les
-    // initialiser => il faut prÃ©calculer toutes ces valeurs et avoir une alloc dynamique
-    // du nombre de barriÃšres.
-    // De plus, le problÃšme est dÃ©cuplÃ© si le nombre de lignes n'est pas une puissance de 2, car
-    // dans ce cas certains threads ne doivent rien faire Ã  une itÃ©ration courante i,
-    // mais doivent Ãªtre actifs Ã  i + 1 => encore plus dur de calculer le nombre
-    // de threads Ã  attendre Ã  chaque barriÃšre + surtout savoir s'il faut break ou continue
+    CLOCK_THREAD_START_STEP(p, 1);
+#if PYR_BARRIERS
+    // Version optimisÃ©e qui fait faire un break aux processeurs qui n'ont plus
+    // Ã  faire de merge.
+    // Implique de prÃ©-calculer le nombre de threads Ã  chaque barriÃšre
+    if (p != 0) { // thread 0 never has any merge to do
+        int been_active = 0;
+        for (int level = 0; level < nb_level; level++) {
+            if ((p + (1 << level)) % (1 << (level + 1)) == 0) {
+                borderMerging_Rosenfeld_Dist(X, i, width, E, T, D, alpha);  // en (i) et (i-1)
+                been_active = 1;
+            }
+            else if (been_active) {
+                break;
+            }
+            pthread_barrier_wait(&mca->barriers[level]);
+        }
+    }
+    pthread_barrier_wait(&main_barrier);
+#else
     for (int level = 1; level <= nb_level; level++) {
-        if ((mca->p + (1 << (level - 1))) % (1 << level) == 0) {
+        if ((p + (1 << (level - 1))) % (1 << level) == 0) {
             // thread actif
-            //MCA_VERBOSE1(printf("### level = %d - p = %d\n", level, mca->p));
             borderMerging_Rosenfeld_Dist(X, i, width, E, T, D, alpha);  // en (i) et (i-1)
         }
-        barrier_wait(&main_barrier);
-    }
+        pthread_barrier_wait(&main_barrier);
+    }
+#endif
+    CLOCK_THREAD_END_STEP(p, 1);
     
 
@@ -887,13 +1698,16 @@
     // ---------------------------------
     
+    CLOCK_THREAD_START_STEP(p, 2);
     for (uint32 e = e0; e <= e1; e++) {
         uint32 r = T[e]; // acces local
         if (r < e) {
             r = FindRoot_Dist(D, e, alpha); // acces distant
-        }
-        T[e] = r;
-        MCA_VERBOSE2(printf("p%d : T[%d] <- %d\n", mca->p, e, r));
-    }
-}
+            T[e] = r; // @QM Ã©tait en dehors du "if" (je pense que dÃ©jÃ  demandÃ©)
+        }
+        MCA_VERBOSE2(printf("p%d : T[%d] <- %d\n", p, e, r));
+    }
+    CLOCK_THREAD_END_STEP(p, 2);
+}
+#endif // !FEATURES
 
 
@@ -904,7 +1718,5 @@
     // input
     if (mca->p == 0) {
-        MCA_VERBOSE1(printf("------------------------------\n"));
-        MCA_VERBOSE1(printf("-- MCA_Label_Rosenfeld_PAR3 --\n"));
-        MCA_VERBOSE1(printf("------------------------------\n"));
+        printf("*** %s ***\n", __func__);
     }
     
@@ -917,4 +1729,5 @@
     uint32 * T = mca->T;
 
+    CLOCK_THREAD_START_STEP(mca->p, 3);
     for (int i = i0; i <= i1; i++) {
         for (int j = j0; j <= j1; j++) {
@@ -925,40 +1738,381 @@
         }
     }
-}
-
-
+    CLOCK_THREAD_END_STEP(mca->p, 3);
+}
+
+
+#if FEATURES
+// -----------------------------------------------------
+static void MCA_Label_Features_Rosenfeld_PAR1(MCA * mca)
+// -----------------------------------------------------
+{
+    if (mca->p == 0) { 
+        printf("*** %s ***\n", __func__);
+    }
+    
+    CLOCK_THREAD_START_STEP(mca->p, 0);
+
+    int i0 = mca->i0;
+    int i1 = mca->i1;
+    int width = mca->width;
+
+    uint32 e0 = mca->e0;
+    uint32 e1 = mca->e1;
+    uint32 ne = e0 - 1;
+    uint32 nr = 0;
+
+    // local memory zones
+    uint8 **  X = mca->X;
+    uint32 ** E = mca->E;
+    uint32 *  T = mca->T;
+
+    RegionStats * stats = mca->stats;
+
+    // reset sous optimal (pour le moment = voir region32)
+    if (mca->p == 0) {
+        set_ui32vector_j(T, e0 - 1, e1); // car e0 = 1, on a besoin que T[0] = 0 pour FindRoot
+        zero_RegionStatsVector(stats, e0 - 1, e1);
+    }
+    else {
+        set_ui32vector_j(T, e0, e1);
+        zero_RegionStatsVector(stats, e0, e1);
+    }
+
+    if (mca->p == 0) {
+        MCA_DISPLAY2(display_ui8matrix_positive(X, i0, i1, 0, width - 1, 5, "Xp"); printf("\n"));
+    }
+
+    // ---------------------------- //
+    // -- Etiquetage d'une bande -- //
+    // ---------------------------- //
+
+    ne = line0Labeling_Rosenfeld(X, i0, width, E, T, ne);
+    lineFeaturesComputation(E, i0, width, stats);
+
+    for (int i = i0 + 1; i <= i1; i++) {
+        ne = lineLabeling_Rosenfeld(X, i, width, E, T, ne); // Slow or Fast
+        lineFeaturesComputation(E, i, width, stats);
+    }
+    mca->ne = ne; //plus grande etiquette de l'intervalle [e0..e1]
+
+    if (mca->p == 0) {
+        MCA_VERBOSE2(printf("ne = %d\n", ne));
+        MCA_DISPLAY2(display_ui32matrix_positive(E, i0, i1, 0, width - 1, 5, "Ep"); printf("\n"));
+        MCA_DISPLAY2(display_ui32vector_number(T, e0, ne, "%5d", "Tp_avant"));
+    }
+
+    // ------------------------------------------------------ //
+    // -- Fermeture transitive sans pack de chaque table T -- //
+    // ------------------------------------------------------ //
+
+    solveTable_solveFeatures_Range_Rosenfeld(T, e0, ne, stats);
+
+    if (mca->p == 0) {
+        MCA_VERBOSE2(nr = countTable_Range_Rosenfeld(T, e0, ne);
+                printf("p = %d : e = [%d..%d] -> ne = %d -> nr = %d\n", mca->p, e0, ne, (ne - e0 + 1), nr));
+        MCA_DISPLAY2(display_ui32vector_number(T, e0, ne, "%5d", "Tp_apres"));
+    }
+    CLOCK_THREAD_END_STEP(mca->p, 0);
+}
+#endif // FEATURES
+
+
+#if FEATURES && !PARMERGE
+// -----------------------------------------------------
+static void MCA_Label_Features_Rosenfeld_PYR2(MCA * mca)
+// -----------------------------------------------------
+{
+    int p = mca->p;
+    int nb_level = mca->nb_level;
+
+    if (mca->p == 0) {
+        printf("*** %s ***\n", __func__);
+    }
+    
+    // ------------------------------
+    // -- pyramidal border merging --
+    // ------------------------------
+    
+    // local variables
+    int i = mca->i0;
+    int width = mca->width;
+    int alpha = mca->alpha;
+    uint32 e0 = mca->e0;
+    uint32 e1 = mca->ne;
+
+    // local memory zones
+    uint8 **  X = mca->X;
+    uint32 ** E = mca->E;
+    uint32 *  T = mca->T;
+    uint32 ** D = mca->D;
+    RegionStats ** F = mca->F;
+
+    CLOCK_THREAD_START_STEP(p, 1);
+#if PYR_BARRIERS
+    // Version optimisÃ©e qui fait faire un break aux processeurs qui n'ont plus
+    // Ã  faire de merge.
+    // Implique de prÃ©-calculer le nombre de threads Ã  chaque barriÃšre
+    if (p != 0) { // thread 0 never has any merge to do
+        int been_active = 0;
+        for (int level = 0; level < nb_level; level++) {
+            if ((p + (1 << level)) % (1 << (level + 1)) == 0) {
+                borderMerging_Features_Rosenfeld_Dist(X, i, width, E, T, D, alpha, F);  // (i) et (i-1)
+                been_active = 1;
+            }
+            else if (been_active) {
+                break;
+            }
+            pthread_barrier_wait(&mca->barriers[level]);
+        }
+    }
+    pthread_barrier_wait(&main_barrier);
+#else
+    for (int level = 1; level <= nb_level; level++) {
+        if ((p + (1 << (level - 1))) % (1 << level) == 0) {
+            // thread actif
+            borderMerging_Features_Rosenfeld_Dist(X, i, width, E, T, D, alpha, F);  // (i) et (i-1)
+        }
+        pthread_barrier_wait(&main_barrier);
+    }
+#endif
+    CLOCK_THREAD_END_STEP(p, 1);
+
+
+    /**
+     * To remove?
+    // -- Affichage de debug
+    if (mca->p == 0) {
+        MCA_VERBOSE1(puts("-----------------------------"));
+        MCA_VERBOSE1(puts("[PYR2]: avant pack sequentiel"));
+        MCA_VERBOSE1(puts("-----------------------------"));
+    
+        for (int p = 0; p < mca->np; p++) {
+    
+            MCA* mca_par = mcas[p];
+            uint32 e0 = mca_par->e0;
+            uint32 e1 = mca_par->ne;
+            
+            uint32*  T = mca_par->T;
+            RegionStats* Stats = mca_par->Stats;
+        
+            RegionStats_DisplayStats_Sparse(T, e0, e1, Stats, NULL);
+            puts("");
+        }
+    }
+    */
+
+    // ---------------------------------
+    // -- parallel transitive closure --
+    // ---------------------------------
+    // identique a la version sans Features
+      
+    CLOCK_THREAD_START_STEP(p, 2);
+    for (uint32 e = e0; e <= e1; e++) {
+        uint32 r = T[e]; // acces local
+        if (r < e) {
+            r = FindRoot_Dist(D, e, alpha); // acces distant
+            T[e] = r;
+        }
+        MCA_VERBOSE2(printf("p%d : T[%d] <- %d\n", p, e, r));
+    }
+    CLOCK_THREAD_END_STEP(p, 2);
+
+    // To avoid uninitialized accesses
+    CLOCK_THREAD_START_STEP(p, 3);
+    CLOCK_THREAD_END_STEP(p, 3);
+}
+#endif // FEATURES && !PARMERGE
+
+
+#if FEATURES && PARMERGE
+// -----------------------------------------------------
+static void MCA_Label_Features_Rosenfeld_PAR2(MCA * mca)
+// -----------------------------------------------------
+{
+    int p = mca->p;
+    int nb_level = mca->nb_level;
+
+    if (mca->p == 0) {
+        printf("*** %s ***\n", __func__);
+    }
+    
+    // ------------------------------
+    // -- parallel border merging --
+    // ------------------------------
+    
+    // local variables
+    int i = mca->i0;
+    int width = mca->width;
+    int alpha = mca->alpha;
+    uint32 e0 = mca->e0;
+    uint32 e1 = mca->ne;
+
+    // local memory zones
+    uint8 **  X = mca->X;
+    uint32 ** E = mca->E;
+    uint32 *  T = mca->T;
+    uint32 ** D = mca->D;
+    RegionStats ** F = mca->F;
+
+    CLOCK_THREAD_START_STEP(p, 1);
+    if (p != 0) { // thread 0 never has any merge to do
+        borderMerging_Features_Rosenfeld_Dist(X, i, width, E, T, D, alpha, F);  // (i) et (i-1)
+    }
+    pthread_barrier_wait(&main_barrier);
+    CLOCK_THREAD_END_STEP(p, 1);
+
+
+    // ---------------------------------
+    // -- parallel transitive closure --
+    // ---------------------------------
+    // identique a la version sans Features
+     
+    CLOCK_THREAD_START_STEP(p, 2);
+    for (uint32 e = e0; e <= e1; e++) {
+        uint32 r = T[e]; // acces local
+        if (r < e) {
+            r = FindRoot_Dist(D, e, alpha); // acces distant
+            T[e] = r;
+        }
+        MCA_VERBOSE2(printf("p%d : T[%d] <- %d\n", p, e, r));
+    }
+    CLOCK_THREAD_END_STEP(p, 2);
+
+    // To avoid uninitialized accesses
+    CLOCK_THREAD_START_STEP(p, 3);
+    CLOCK_THREAD_END_STEP(p, 3);
+}
+#endif // FEATURES
+
+
+
+
+#if !FEATURES
 // =============================================================
+#if TARGET_OS == GIETVM
 __attribute__((constructor)) void MCA_Label_Rosenfeld(MCA * mca)
+#else
+void MCA_Label_Rosenfeld(MCA * mca)
+#endif
 // =============================================================
 {
+#if TARGET_OS == GIETVM
+    unsigned int x, y, lpid;
+    giet_proc_xyp(&x, &y, &lpid);
+    // Mettre Ã  jour mca->p en fonction de x, y, lpid
+    // pour que les allocations faites par le main soient locales,
+    // i.e. 
+    mca->p = (x * Y_SIZE + y) * NB_PROCS_MAX + lpid;
+    // We have :
+    // mca->p = 4 pour (x = 0, y = 1, lpid = 0)
+    // mca->p = 5 pour (x = 0, y = 1, lpid = 1)
+    MCA_VERBOSE2(printf("mca->p = %d pour (x = %d, y = %d, lpid = %d)\n", mca->p, x, y, lpid));
+#endif
+
+    CLOCK_THREAD_START(mca->p);
+    CLOCK_THREAD_COMPUTE_START(mca->p);
+
     MCA_Scatter_ImageX(mca);
-    barrier_wait(&main_barrier);
+    pthread_barrier_wait(&main_barrier);
 
     MCA_Label_Rosenfeld_PAR1(mca);
-    barrier_wait(&main_barrier);
-    
-    //MCA_Gather_ImageL(mca);
-    //barrier_wait(&main_barrier);
-    //MCA_VERBOSE2(display_ui32matrix_positive(mca->E, mca->i0, mca->i1, 0, mca->width - 1, 5, "E2"));
-    //barrier_wait(&main_barrier);
-    
-    //MCA_Label_Rosenfeld_SEQ2(mca);
+    pthread_barrier_wait(&main_barrier);
+    
     MCA_Label_Rosenfeld_PYR2(mca);
-    barrier_wait(&main_barrier);
-    //MCA_VERBOSE2(display_ui32matrix_positive(mca->E, mca->i0, mca->i1, 0, mca->width - 1, 5, "EPYR"));
-    //barrier_wait(&main_barrier);
+    pthread_barrier_wait(&main_barrier);
     
     MCA_Label_Rosenfeld_PAR3(mca);
-    barrier_wait(&main_barrier);
+    pthread_barrier_wait(&main_barrier);
 
     MCA_Gather_ImageL(mca);
-    barrier_wait(&main_barrier);
-    //MCA_VERBOSE2(display_ui32matrix_positive(mca->E, mca->i0, mca->i1, 0, mca->width - 1, 5, "E3"));
-    //barrier_wait(&main_barrier);
-    
+    pthread_barrier_wait(&main_barrier);
+
+    CLOCK_THREAD_COMPUTE_END(mca->p);
+    CLOCK_THREAD_END(mca->p);
+
+#if TARGET_OS == GIETVM
     if (mca->p != 0) {
-        giet_pthread_exit(NULL);
-    }
-}
+        exit(0);
+    }
+#endif
+}
+#endif // !FEATURES
+
+
+#if FEATURES
+// ======================================================================
+#if TARGET_OS == GIETVM
+__attribute__((constructor)) void * MCA_Label_Features_Rosenfeld(void * arg)
+#else
+void * MCA_Label_Features_Rosenfeld(void * arg)
+#endif
+// ======================================================================
+{
+    MCA * mca = (MCA *) arg;
+#if TARGET_OS == GIETVM
+    unsigned int x, y, lpid;
+    giet_proc_xyp(&x, &y, &lpid);
+    // Mettre Ã  jour mca->p en fonction de x, y, lpid
+    // pour que les allocations faites par le main soient locales,
+    // i.e. 
+    mca->p = (x * Y_SIZE + y) * NB_PROCS_MAX + lpid;
+    // We have :
+    // mca->p = 4 pour (x = 0, y = 1, lpid = 0)
+    // mca->p = 5 pour (x = 0, y = 1, lpid = 1)
+    MCA_VERBOSE2(printf("mca->p = %d pour (x = %d, y = %d, lpid = %d)\n", mca->p, x, y, lpid));
+#endif
+
+    CLOCK_THREAD_START(mca->p);
+    CLOCK_THREAD_COMPUTE_START(mca->p);
+
+    MCA_Scatter_ImageX(mca);
+    pthread_barrier_wait(&main_barrier);
+
+    MCA_Label_Features_Rosenfeld_PAR1(mca);
+    pthread_barrier_wait(&main_barrier);
+   
+#if PARMERGE 
+    MCA_Label_Features_Rosenfeld_PAR2(mca);
+#else
+    MCA_Label_Features_Rosenfeld_PYR2(mca);
+#endif
+    pthread_barrier_wait(&main_barrier);
+    
+    MCA_Label_Rosenfeld_PAR3(mca);
+    pthread_barrier_wait(&main_barrier);
+
+    MCA_Gather_ImageL(mca);
+    pthread_barrier_wait(&main_barrier);
+
+    CLOCK_THREAD_COMPUTE_END(mca->p);
+ 
+    if (display_features) {
+        if (mca->p == 0) {
+            int i = 1;
+            printf("[STATS]\n");
+            for (int p = 0; p < mca->np; p++) {
+                MCA * mca_par = mca->mca->mcas[p];
+                uint32 e0 = mca_par->e0;
+                uint32 ne = mca_par->ne - mca_par->e0; // number of elements
+                uint32 * T = mca_par->T;
+                RegionStats * stats = mca_par->stats;
+                RegionStats_DisplayStats_Sparse(T, e0, e0 + ne, stats, NULL, &i);
+            }
+            printf("[/STATS]\n");
+        }
+    }
+
+    CLOCK_THREAD_END(mca->p);
+
+#if TARGET_OS == GIETVM
+    if (mca->p != 0) {
+        exit(0);
+    }
+#endif
+
+    return NULL;
+}
+#endif // FEATURES
+
 
 // Local Variables:
Index: soft/giet_vm/applications/rosenfeld/src-par/mca_test.c
===================================================================
--- soft/giet_vm/applications/rosenfeld/src-par/mca_test.c	(revision 820)
+++ 	(revision )
@@ -1,277 +1,0 @@
-/* ------------------ */
-/* --- mca_test.c --- */
-/* ------------------ */
-
-/*
- * Copyright (c) 2016 Lionel Lacassagne, LIP6, UPMC, CNRS
- * Init  : 2016/03/03
- */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <math.h>
-#include <user_barrier.h>
-
-#ifdef CLI
-#include "nrc_os_config.h"
-#include "nrc.h"
-#endif
-
-
-
-#include "util.h"
-#include "ecc_common.h"
-#include "ecc_features.h"
-#include "palette.h"
-#include "bmpNR.h"
-#include "mca_matrix_dist.h"
-#include "mca_rosenfeld.h"
-
-
-/* -- local -- */
-#include "mca.h"
-#include "mca_test.h"
-
-#define DEFAULT_NTHREADS 4
-#define MAX_THREADS 256
-
-pthread_t thread_table[MAX_THREADS];
-
-giet_barrier_t main_barrier;
-
-int num_threads = DEFAULT_NTHREADS;
-
-// --------------------------------------------------------------------------
-void init_forme_boulon1(uint8 *** X0, int * i0, int * i1, int * j0, int * j1)
-// --------------------------------------------------------------------------
-{
-    uint8 ** X;
-    int i =  0;
-    int h =  28;
-    int w =  30;
-    
-    X = ui8matrix(0, h - 1, 0, w - 1);
-    zero_ui8matrix(X, 0, h - 1, 0, w - 1);
-    
-    *X0 = X;
-    *i0 = 0;
-    *i1 = h - 1;
-    *j0 = 0;
-    *j1 = w - 1;
-    
-    //                                 0000000001111111111122222222223
-    //                                 0123456789012345678901234567890
-    set_ui8vector_str(X[i++], 0, w - 1, "                         111  "); // 00
-    set_ui8vector_str(X[i++], 0, w - 1, "                        11111 "); // 01
-    set_ui8vector_str(X[i++], 0, w - 1, "                      1111111 "); // 02
-    set_ui8vector_str(X[i++], 0, w - 1, "                     11111111 "); // 03
-    set_ui8vector_str(X[i++], 0, w - 1, "                    1111111111"); // 04
-    set_ui8vector_str(X[i++], 0, w - 1, "                   11111111111"); // 05
-    set_ui8vector_str(X[i++], 0, w - 1, "                 1111111111111"); // 06
-    set_ui8vector_str(X[i++], 0, w - 1, "               11111111111111 "); // 07
-    set_ui8vector_str(X[i++], 0, w - 1, "              11111111111111  "); // 08
-    set_ui8vector_str(X[i++], 0, w - 1, "             11111111111111   "); // 09
-    set_ui8vector_str(X[i++], 0, w - 1, "     11    11111111111111     "); // 10
-    set_ui8vector_str(X[i++], 0, w - 1, "    111   11111111111111      "); // 11
-    set_ui8vector_str(X[i++], 0, w - 1, "   11111111111111111111       "); // 12
-    set_ui8vector_str(X[i++], 0, w - 1, " 11111111111111111111         "); // 13
-    set_ui8vector_str(X[i++], 0, w - 1, "1111111111111111111           "); // 14
-    set_ui8vector_str(X[i++], 0, w - 1, " 11111111111111111            "); // 15
-    set_ui8vector_str(X[i++], 0, w - 1, " 1111111111111111             "); // 16
-    set_ui8vector_str(X[i++], 0, w - 1, " 111111111111111              "); // 17
-    set_ui8vector_str(X[i++], 0, w - 1, "  111111111111                "); // 18
-    set_ui8vector_str(X[i++], 0, w - 1, "  1111111111                  "); // 29
-    set_ui8vector_str(X[i++], 0, w - 1, "  1111111111                  "); // 20
-    set_ui8vector_str(X[i++], 0, w - 1, "   111111111                  "); // 21
-    set_ui8vector_str(X[i++], 0, w - 1, "   111111111                  "); // 22
-    set_ui8vector_str(X[i++], 0, w - 1, "    11111111                  "); // 23
-    set_ui8vector_str(X[i++], 0, w - 1, "    1111111                   "); // 24
-    set_ui8vector_str(X[i++], 0, w - 1, "     11111                    "); // 25
-    set_ui8vector_str(X[i++], 0, w - 1, "     111                      "); // 26
-    set_ui8vector_str(X[i++], 0, w - 1, "                              "); // 27
-    
-    //printf("[init_forme_boulon1]: h = %d i = %d\n", h, i);
-    if (i != h) {
-        MCA_Error("init_forme_boulon1 i != h");
-    }
-
-    
-    //display_ui8matrix_positive(X, 0, h-1, 0, w-1, 4, "forme_boulon1"); printf("");
-    //write_ui8matrix_positive(  X, 0, h-1, 0, w-1, 4, "forme_boulon1.txt");
-}
-
-
-// -----------------
-void mca_test1(void)
-// -----------------
-{
-    int i0, i1, j0, j1;
-    int height, width;
-    
-    uint8 ** X0;
-    uint8 ** X;
-    uint32 ** E;
-    MCA * mca;
-
-    barrier_init(&main_barrier, num_threads);
-
-    // -- Allocation --
-    init_forme_boulon1(&X0, &i0, &i1, &j0, &j1);
-    
-    height = i1 - i0 + 1;
-    width  = j1 - j0 + 1;
-    
-    // @QM Ã  quoi sert X ??
-    X = ui8matrix (i0, i1, j0, j1);
-    E = ui32matrix(i0, i1, j0, j1);
-    
-    zero_ui32matrix(E, i0, i1, j0, j1);
-    zero_ui8matrix (X, i0, i1, j0, j1);
-    
-    mca = MCA_pConstructor_Empty();
-    
-    // -- set param
-    MCA_Set_Size(mca, width, height);
-    MCA_Set_ImageX(mca, X0);
-    MCA_Set_ImageL(mca, E);
-    MCA_Set_NP(mca, num_threads);
-    
-    // -- MCA init
-    MCA_Initialize(mca);
-    MCA_Display_Parameters(mca);
-    
-    display_ui8matrix_positive(mca->X, i0, i1, j0, j1, 5, "X0");
-    for (int i = 1; i < num_threads; i++) {
-        giet_pthread_create(&thread_table[i], NULL, MCA_Label_Rosenfeld, (void *) mca->mcas[i]);
-    }
-    MCA_Label_Rosenfeld(mca->mcas[0]);
-    for (int i = 1; i < num_threads; i++) {
-        giet_pthread_join(thread_table[i], NULL);
-    }
-    display_ui32matrix_positive(mca->E, i0, i1, j0, j1, 5, "Efinal");
-
-    
-    // -- free --
-    printf("Finalize\n");
-    MCA_Finalize(mca);
-    
-    printf("Free_matrix\n");
-    free_ui8matrix (X0, i0, i1, j0, j1);
-    free_ui8matrix (X,  i0, i1, j0, j1);
-    free_ui32matrix(E,  i0, i1, j0, j1);
-}
-
-
-
-// -----------------
-void mca_test2(void)
-// -----------------
-{
-    int i0, i1, j0, j1;
-    int height, width;
-    
-    uint8 ** X0;
-    uint8 ** X;
-    uint8 ** E8;
-    uint32 ** E;
-    MCA * mca;
-
-    char * pathSrc = "/misc/";
-    char * pathDst = "";
-    char * filename = "boulons.pgm";
-
-    //RegionStats * Stats = NULL;
-    RGBQuad palette[256];
-    char complete_filename[1024];
-
-    barrier_init(&main_barrier, num_threads);
-
-    Palette_18ColorsBW(palette);
-    generate_path_filename(pathSrc, filename, complete_filename, 1024);
-    
-    printf("Loading file %s... ", filename);
-    X0 = LoadPGM_ui8matrix(complete_filename, &i0, &i1, &j0, &j1);
-    printf("done.\n");
-
-    printf("Allocating memory... ");
-    height = i1 - i0 + 1;
-    width  = j1 - j0 + 1;
-    
-    X  = ui8matrix (i0, i1, j0, j1);
-    E8 = ui8matrix (i0, i1, j0, j1);
-    E  = ui32matrix(i0, i1, j0, j1);
-    
-    zero_ui32matrix(E, i0, i1, j0, j1);
-    zero_ui8matrix(E8, i0, i1, j0, j1);
-    zero_ui8matrix(X,  i0, i1, j0, j1);
-
-    // pre-traitements
-    binarisation_ui8matrix(X0, i0, i1, j0, j1, 20, 1, X); // pour le traitement
-    binarisation_ui8matrix(X0, i0, i1, j0, j1, 20, 255, X0); // pour la verif visuelle
-    printf("done.\n");
-
-    generate_path_filename(pathDst, "verif.pgm", complete_filename, 1024);
-    printf("Saving file %s for verification... ", complete_filename);
-    SavePGM_ui8matrix(X0, i0, i1, j0, j1, complete_filename);
-    printf("done.\n");
-
-
-    printf("Allocating and initializing MCA... \n");
-    mca = MCA_pConstructor_Empty();
-    
-    // -- set param
-    MCA_Set_Size(mca, width, height);
-    MCA_Set_ImageX(mca, X);
-    MCA_Set_ImageL(mca, E);
-    MCA_Set_NP(mca, num_threads);
-    
-    // -- MCA init
-    MCA_Initialize(mca);
-    MCA_Display_Parameters(mca);
-    printf("End of MCA allocation and initialization.\n");
-    
-    //display_ui8matrix_positive(mca->X, i0, i1, j0, j1, 5, "X0");
-    for (int i = 1; i < num_threads; i++) {
-        giet_pthread_create(&thread_table[i], NULL, MCA_Label_Rosenfeld, (void *) mca->mcas[i]);
-    }
-    MCA_Label_Rosenfeld(mca->mcas[0]);
-    for (int i = 1; i < num_threads; i++) {
-        giet_pthread_join(thread_table[i], NULL);
-    }
-    //display_ui32matrix_positive(mca->E, i0, i1, j0, j1, 5, "Efinal");
-    mod_ui32matrix_ui8matrix(mca->E, i0, i1, j0, j1, E8);
-    generate_path_filename(pathDst, "verif_final.bmp", complete_filename, 1024);
-    printf("Saving file %s for verification... ", complete_filename);
-    SaveBMP2_ui8matrix(E8, width, height, palette, complete_filename);
-    printf("done.\n");
-
-
-    
-    // -- free --
-    MCA_Finalize(mca);
-    printf("Deallocating memory...");
-    free_ui8matrix (X0, i0, i1, j0, j1);
-    free_ui8matrix (X,  i0, i1, j0, j1);
-    free_ui32matrix(E,  i0, i1, j0, j1);
-    printf("done.\n");
-
-    //free_RegionStatsVector(Stats, 0, nemax);
-}
-
-
-
-
-// --------------------------------------
-int main_test_mca()
-// --------------------------------------
-{
-    printf("===================\n");
-    printf("== main_test_mca ==\n");
-    printf("===================\n");
-    
-    mca_test2();
-    
-    return 0;
-}
-
Index: soft/giet_vm/applications/rosenfeld/src-par/mca_warp.c
===================================================================
--- soft/giet_vm/applications/rosenfeld/src-par/mca_warp.c	(revision 821)
+++ soft/giet_vm/applications/rosenfeld/src-par/mca_warp.c	(revision 821)
@@ -0,0 +1,68 @@
+/* ------------------ */
+/* --- mca_warp.c --- */
+/* ------------------ */
+
+/*
+ * Copyright (c) 2016 Lionel Lacassagne, LIP6, UPMC, CNRS
+ * Init  : 2016/03/03
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <stddef.h>
+#include <string.h>
+#include <math.h>
+
+
+#include "nrc_os_config.h"
+#include "nrc.h"
+
+#if TARET_OS == GIETVM
+#include <user_barrier.h>
+#endif
+
+#include "util.h"
+#include "ecc_common.h"
+#include "palette.h"
+#include "bmpNR.h"
+#include "mca.h"
+#include "str_ext.h"
+
+
+// ---------------------------------------------------------------
+void line0Labeling_Warp(uint8 ** X, int i, int width, uint32 ** E)
+// ---------------------------------------------------------------
+{
+    int j;
+    uint8 x;
+    uint32 e4;
+    uint32 r4;
+    
+    // prologue
+    x = X[i][0];
+    if (x) {
+        E[i][0] = i * width + 1;
+    }
+    else {
+        E[i][0] = 0;
+    }
+    
+    // boucle et epilogue
+    for (j = 1; j <= width - 1; j++) {
+        x = X[i][j];
+        if (x) {
+            e4 = E[i][j-1];
+            
+            if (e4 == 0) {
+                E[i][j] =  i * width + 1;
+            }
+            else {
+                E[i][j] = e4;
+            }
+        }
+        else {
+            E[i][j] = 0;
+        }
+    }
+}
+
Index: soft/giet_vm/applications/rosenfeld/src/bmpNR.c
===================================================================
--- soft/giet_vm/applications/rosenfeld/src/bmpNR.c	(revision 820)
+++ soft/giet_vm/applications/rosenfeld/src/bmpNR.c	(revision 821)
@@ -11,6 +11,4 @@
 #include <math.h>
 
-/* -- image -- */
-#ifdef CLI
 #include "nrc_os_config.h"
 #include "nrtype.h"
@@ -18,5 +16,4 @@
 #include "nrmacro.h"
 #include "nralloc.h"
-#endif
 
 #if TARGET_OS == LINUX
@@ -37,23 +34,19 @@
 #define BI_RGB 0L
 
-PRIVATE void ReadBMProw  (int fd, long width, uint8 * row);
-PRIVATE void WriteBMProw (uint8 * row, long width, int fd);
-//PRIVATE void SetupPalette (RGBQUAD Palette[]);
-
-#if (!defined(WIN32) && !defined(_WINDOWS_) && !defined(_WINGDI_))
-//#pragma message("bmpio.h no WINDOWS echo")
-PRIVATE void Palette_RGBQuad2RGBQUAD(RGBQuad * src, RGBQUAD dst[]);
-#endif
-
-/* ------------------------------------- */
-uint8 *ui8ArrayAppend(uint8 *ptr, uint8 x)
-    /* ------------------------------------- */
+static void ReadBMProw(int fd, long width, uint8 * row);
+static void WriteBMProw(uint8 * row, long width, int fd);
+static void Palette_RGBQuad2RGBQUAD(RGBQuad * src, RGBQUAD dst[]);
+
+/* --------------------------------------- */
+uint8 * ui8ArrayAppend(uint8 * ptr, uint8 x)
+/* --------------------------------------- */
 {
     *ptr++ = x;
     return ptr;
 }
+
 /* ---------------------------------------- */
-uint8 *ui16ArrayAppend(uint8 *ptr, uint16 x)
-    /* ---------------------------------------- */
+uint8 * ui16ArrayAppend(uint8 * ptr, uint16 x)
+/* ---------------------------------------- */
 {
     uint8 x0, x1;
@@ -67,7 +60,8 @@
     return ptr;
 }
-/* -------------------------------------- */
-uint8 *ui32ArrayAppend(uint8 *ptr, uint32 x)
-    /* -------------------------------------- */
+
+/* ---------------------------------------- */
+uint8 * ui32ArrayAppend(uint8 * ptr, uint32 x)
+/* ---------------------------------------- */
 {
     uint8 x0, x1, x2, x3;
@@ -85,25 +79,26 @@
     return ptr;
 }
+
 // Seul moyen de cache dans la librairie ces putains de types windoze
 
 // --------------------------------------------------------
-PRIVATE void ReadBMProw(int fd, long width, uint8 *row)
-    // --------------------------------------------------------
+static void ReadBMProw(int fd, long width, uint8 * row)
+// --------------------------------------------------------
 {
     // Le fichier est ouvert (en lecture) et ne sera pas ferme a la fin
     read(fd, row, sizeof(uint8) * width);
 }
+
 // ---------------------------------------------------------
-PRIVATE void WriteBMProw(uint8 *row, long width, int fd)
-    // ---------------------------------------------------------
+static void WriteBMProw(uint8 * row, long width, int fd)
+// ---------------------------------------------------------
 {
     // Le fichier est deja ouvert et ne sera pas ferme a la fin
     write(fd, row, sizeof(uint8) * width);
 }
-#if (!defined(WIN32) && !defined(_WINDOWS_) && !defined(_WINGDI_))
-//#pragma message("bmpio.h no WINDOWS echo")
+
 /* ----------------------------------------------------------- */
-PRIVATE void Palette_RGBQuad2RGBQUAD(RGBQuad *src, RGBQUAD dst[])
-    /* ----------------------------------------------------------- */
+static void Palette_RGBQuad2RGBQUAD(RGBQuad * src, RGBQUAD dst[])
+/* ----------------------------------------------------------- */
 {
     int i;
@@ -115,31 +110,20 @@
     }
 }
-#endif
-
-#if (!defined(WIN32) && !defined(_WINDOWS_) && !defined(_WINGDI_))
-//#pragma message("bmpio.h no WINDOWS echo")
-/* --------------------------------------------------------------------------- */
-IMAGE_EXPORT(int) SaveBMP0_ui8matrix(uint8 **m, int width, int height, RGBQuad *palette_RGBQuad, char *filename)
+
+IMAGE_EXPORT(int) SaveBMP0_ui8matrix(uint8 ** m, int width, int height, RGBQuad * palette_RGBQuad, char * filename)
     /* --------------------------------------------------------------------------- */
     /* sauvegarde 'image' au format bmp dans le fichier 'filename' */
 {
-    int rc = 0;
-
     int v_offset = 0; // no more implemented image->v_offset;
     int h_offset = 0; // no more implemented image->h_offset;
     int vmax = height - v_offset;
-    //int hmax = width - h_offset;
-    int height_utile = height - 2*v_offset;
-    int width_utile = width - 2*h_offset;
+    int height_utile = height - 2 * v_offset;
+    int width_utile = width - 2 * h_offset;
     int taille_utile  = height_utile * width_utile;
 
-    //int size;
     int padding_len;
 
     BITMAPFILEHEADER Bitmap_File_Header;
-    /*BITMAPINFO;      Bitmap_Info; */
-
     BITMAPINFOHEADER Bitmap_Info_Header;
-    /*RGBQUAD          RGB_Quad; */
 
     RGBQUAD palette_RGBQUAD[256]; /* Windows */
@@ -156,11 +140,10 @@
 
     /* --- Header --- */
-    Bitmap_File_Header.bfType      = (WORD) BM;   /* BM                            */
-    Bitmap_File_Header.bfSize      = (DWORD) sizeof(BITMAPFILEHEADER)+sizeof(BITMAPINFOHEADER)+256*sizeof(RGBQuad)+taille_utile;    /* taille avec header et palette */
-    Bitmap_File_Header.bfReserved1 = (WORD) 0; /* 0                             */
-    Bitmap_File_Header.bfReserved2 = (WORD) 0; /* 0                             */
-    Bitmap_File_Header.bfOffBits   = (DWORD) sizeof(BITMAPFILEHEADER) +
-        (DWORD) sizeof(BITMAPINFOHEADER) +
-        (DWORD) sizeof(RGBQUAD)*256;   /* */
+    Bitmap_File_Header.bfType      = (WORD) BM;   /* BM */
+    /* taille avec header et palette */
+    Bitmap_File_Header.bfSize      = (DWORD) sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER) + 256 * sizeof(RGBQuad) + taille_utile;
+    Bitmap_File_Header.bfReserved1 = (WORD) 0; /* 0 */
+    Bitmap_File_Header.bfReserved2 = (WORD) 0; /* 0 */
+    Bitmap_File_Header.bfOffBits   = (DWORD) sizeof(BITMAPFILEHEADER) + (DWORD) sizeof(BITMAPINFOHEADER) + (DWORD) sizeof(RGBQUAD)*256;   /* */
 
 
@@ -182,5 +165,6 @@
     fd = open(filename, O_CREAT | O_TRUNC);
     if (fd < 0) {
-        printf("*** Erreur : Ouverture du fichier impossible dans SaveBMP");
+        printf("\n*** Erreur : Ouverture du fichier impossible dans SaveBMP\n");
+        return -1;
     }
 
@@ -215,16 +199,14 @@
     }
     close(fd);
-    return rc;
-
-}
-#endif
-// ------------------------------------------------------------------------------------------------------------
-IMAGE_EXPORT(int) SaveBMP2_ui8matrix(uint8 **m, int width, int height, RGBQuad *palette_RGBQuad, char *filename)
-    // ------------------------------------------------------------------------------------------------------------
-    // sauvegarde 'image' au format bmp dans le fichier 'filename'
+    return 0;
+
+}
+
+// ----------------------------------------------------------------------------------------------------------------
+IMAGE_EXPORT(int) SaveBMP2_ui8matrix(uint8 ** m, int width, int height, RGBQuad * palette_RGBQuad, char * filename)
+// ----------------------------------------------------------------------------------------------------------------
+// sauvegarde 'image' au format bmp dans le fichier 'filename'
 {
     int taille_utile  = height * width;
-
-    //int size;
     int padding_len;
 
@@ -241,7 +223,4 @@
     int fd;
     int  i;
-
-    //#pragma message("BMP warnin' data structure aligment must be 2")
-    //#pragma message("  sizeof( BitmapFileHeader) must = 14, not 16")
 
     //DEBUG(printf("BMP0 : %d %d\n", sizeof( BITMAPFILEHEADER), sizeof( BITMAPINFOHEADER)));
@@ -298,7 +277,12 @@
     //printf("   SaveBMP %s %dx%d\n", filename, width, height);
 
-    fd = open(filename, O_CREAT | O_TRUNC);
+#if TARGET_OS != GIETVM
+    fd = open(filename, O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
+#else
+    fd = open(filename, O_WRONLY | O_CREAT | O_TRUNC);
+#endif
     if (fd < 0) {
-        printf("*** Erreur : ouverture du fichier '%s' impossible dans SaveBMP", filename);
+        printf("\n*** Erreur : ouverture du fichier '%s' impossible dans SaveBMP\n", filename);
+        return -1;
     }
 
@@ -326,5 +310,4 @@
 
 
-    // en 2x car le compilo est trop con ...
     padding_len = width % 4;
     padding_len = (4 - padding_len) % 4;
Index: soft/giet_vm/applications/rosenfeld/src/ecc_common.c
===================================================================
--- soft/giet_vm/applications/rosenfeld/src/ecc_common.c	(revision 820)
+++ soft/giet_vm/applications/rosenfeld/src/ecc_common.c	(revision 821)
@@ -8,8 +8,6 @@
 #include <math.h>
 
-#ifdef CLI
 #include "nrc_os_config.h"
 #include "nrc.h"
-#endif
 
 #if TARGET_OS == LINUX
@@ -44,4 +42,6 @@
     return (a > b ? a : b);
 }
+
+
 // ------------------------------------------
 uint32 ui32Max3(uint32 a, uint32 b, uint32 c)
@@ -50,4 +50,6 @@
     return ui32Max2(ui32Max2(a, b), c);
 }
+
+
 // ----------------------------------------------------
 uint32 ui32Max4(uint32 a, uint32 b, uint32 c, uint32 d)
@@ -56,4 +58,6 @@
     return ui32Max2(ui32Max2(a, b), ui32Max2(c,d));
 }
+
+
 // --------------------------------
 uint32 ui32Min2(uint32 a, uint32 b)
@@ -62,4 +66,6 @@
     return (a < b ? a : b);
 }
+
+
 // ------------------------------------------
 uint32 ui32Min3(uint32 a, uint32 b, uint32 c)
@@ -68,4 +74,6 @@
     return ui32Min2(ui32Min2(a, b), c);
 }
+
+
 // ----------------------------------------------------
 uint32 ui32Min4(uint32 a, uint32 b, uint32 c, uint32 d)
@@ -74,4 +82,6 @@
     return ui32Min2(ui32Min2(a, b), ui32Min2(c,d));
 }
+
+
 /* ----------------------------------- */
 uint32 ui32MinNonNul2(uint32 a, uint32 b)
@@ -84,4 +94,6 @@
     return a;
 }
+
+
 /* --------------------------------------------- */
 uint32 ui32MinNonNul3(uint32 a, uint32 b, uint32 c)
@@ -96,4 +108,6 @@
     return m;
 }
+
+
 /* ---------------------------------------------------- */
 uint32 ui32MinNonNul3Cond(uint32 a0, uint32 a1, uint32 a2)
@@ -105,4 +119,6 @@
     return m;
 }
+
+
 /* ----------------------------------------------------------- */
 uint32 ui32MinNonNul4(uint32 a0, uint32 a1, uint32 a2, uint32 a3)
@@ -118,4 +134,6 @@
     return m;
 }
+
+
 /* ---------------------------------------------------------------------- */
 uint32 ui32MinNonNul5(uint32 a0, uint32 a1, uint32 a2, uint32 a3, uint32 a4)
@@ -132,4 +150,6 @@
     return m;
 }
+
+
 /* -------------------------------------------------------------------------- */
 uint32 ui32MinNonNul5Cond(uint32 a0, uint32 a1, uint32 a2, uint32 a3, uint32 a4)
@@ -141,4 +161,6 @@
     return m;
 }
+
+
 /* ------------------------------------------------------------------------------------------------------- */
 uint32 ui32MinNonNul8(uint32 a0, uint32 a1, uint32 a2, uint32 a3, uint32 a4, uint32 a5, uint32 a6, uint32 a7)
@@ -158,4 +180,6 @@
     return m;
 }
+
+
 /* ------------------------------------------------------------------------------------------------------------------ */
 uint32 ui32MinNonNul9(uint32 a0, uint32 a1, uint32 a2, uint32 a3, uint32 a4, uint32 a5, uint32 a6, uint32 a7, uint32 a8)
@@ -176,4 +200,6 @@
     return m;
 }
+
+
 /* ---------------------------------------------------------------------------------------------------------------------- */
 uint32 ui32MinNonNul9Cond(uint32 a0, uint32 a1, uint32 a2, uint32 a3, uint32 a4, uint32 a5, uint32 a6, uint32 a7, uint32 a8)
@@ -190,7 +216,9 @@
     return m;
 }
-// --------------------------------
-void initT(uint32 *T, uint32 nemax)
-// --------------------------------
+
+
+// ---------------------------------
+void initT(uint32 * T, uint32 nemax)
+// ---------------------------------
 {
     int i;
@@ -199,4 +227,6 @@
     }
 }
+
+
 /* -------------------------- */
 //void initA(uint32 *A, uint32 nemax)
@@ -208,4 +238,6 @@
     }
 }*/
+
+
 // --------------------------------
 void initZ(uint32 *T, uint32 nemax)
@@ -217,4 +249,6 @@
     }
 }
+
+
 // --------------------------------------
 void check_initT(uint32 *T, uint32 nemax)
@@ -223,4 +257,6 @@
     check_initT_range(T, 0, nemax, nemax);
 }
+
+
 // --------------------------------------
 void check_initZ(uint32 *T, uint32 nemax)
@@ -229,4 +265,6 @@
     check_initZ_range(T, 0, nemax, nemax);
 }
+
+
 // ---------------------------------------------------------------
 void check_initT_range(uint32 *T, uint32 i0, uint32 ii, uint32 i1)
@@ -243,4 +281,6 @@
     }
 }
+
+
 // ---------------------------------------------------------------
 void check_initR_range(uint32 *R, uint32 i0, uint32 ii, uint32 i1)
@@ -257,4 +297,6 @@
     }
 }
+
+
 // ---------------------------------------------------------------
 void check_initZ_range(uint32 *T, uint32 i0, uint32 ii, uint32 i1)
@@ -271,4 +313,6 @@
     }
 }
+
+
 /* --------------------------------------------------------------------------------------------------- */
 void binarisation_ui8matrix(uint8 **X, int i0, int i1, int j0, int j1, uint8 seuil, uint8 val, uint8 **Y)
@@ -309,16 +353,16 @@
     }
 }
-/* ------------------------------------------------------------------------------- */
-void graphviz_write_ui8vector(uint8 *v, int i0, int i1, char *format, char *filename)
-/* ------------------------------------------------------------------------------- */
-{
-    int i;
+/* ---------------------------------------------------------------------------------- */
+void graphviz_write_ui8vector(uint8 * v, int i0, int i1, char * format, char * filename)
+/* ---------------------------------------------------------------------------------- */
+{
+    int i;
+    char complete_filename[64];
+    
+    snprintf(complete_filename, 64, "%s.dot", filename);
+    
+#if TARGET_OS == GIETVM
     int fd;
-    char complete_filename[64];
-    
-    snprintf(complete_filename, 64, "%s.dot", filename);
-    
     fd = open(complete_filename, O_CREAT | O_TRUNC);
-    //if(f == NULL) { nrerror("Can't open file in grawrite_bvector"); }
     
     fprintf(fd, "digraph %s {\n", filename);
@@ -328,18 +372,31 @@
     fprintf(fd, "}\n");
     close(fd);
-}
-/* --------------------------------------------------------------------------------- */
-void graphviz_write_ui16vector(uint16 *v, int i0, int i1, char *format, char *filename)
-/* --------------------------------------------------------------------------------- */
-{
-    int i;
+#elif TARGET_OS == LINUX
+    FILE * f;
+    f = fopen(complete_filename, "w");
+    if (f == NULL) {
+        fprintf(stderr, "Can't open file %s in %s\n", complete_filename, __func__);
+    }
+    
+    fprintf(f, "digraph %s {\n", filename);
+    for (i = i0; i <= i1; i++) {
+        fprintf(f, "%3d -> %3d;\n", i, v[i]);
+    }
+    fprintf(f, "}\n");
+    fclose(f);
+#endif
+}
+/* ------------------------------------------------------------------------------------ */
+void graphviz_write_ui16vector(uint16 * v, int i0, int i1, char * format, char * filename)
+/* ------------------------------------------------------------------------------------ */
+{
+    int i;
+    char complete_filename[64];
+    
+    snprintf(complete_filename, 64, "%s.dot", filename);
+    
+#if TARGET_OS == GIETVM
     int fd;
-    char complete_filename[64];
-    
-    snprintf(complete_filename, 64, "%s.dot", filename);
-    
-    
     fd = open(complete_filename, O_CREAT | O_TRUNC);
-    //if(f == NULL) { nrerror("Can't open file in grawrite_bvector"); }
     
     fprintf(fd, "digraph %s {\n", filename);
@@ -349,18 +406,33 @@
     fprintf(fd, "}\n");
     close(fd);
-}
-/* --------------------------------------------------------------------------------- */
-void graphviz_write_ui32vector(uint32 *v, int i0, int i1, char *format, char *filename)
-/* --------------------------------------------------------------------------------- */
-{
-    int i;
+#elif TARGET_OS == LINUX
+    FILE * f;
+    f = fopen(complete_filename, "w");
+    if (f == NULL) {
+        fprintf(stderr, "Can't open file %s in %s\n", complete_filename, __func__);
+    }
+    
+    fprintf(f, "digraph %s {\n", filename);
+    for (i = i0; i <= i1; i++) {
+        fprintf(f, "%3d -> %3d;\n", i, v[i]);
+    }
+    fprintf(f, "}\n");
+    fclose(f);
+#endif
+}
+
+
+/* ------------------------------------------------------------------------------------ */
+void graphviz_write_ui32vector(uint32 * v, int i0, int i1, char * format, char * filename)
+/* ------------------------------------------------------------------------------------ */
+{
+    int i;
+    char complete_filename[64];
+    
+    snprintf(complete_filename, 64, "%s.dot", filename);
+    
+#if TARGET_OS == GIETVM
     int fd;
-    char complete_filename[64];
-    
-    snprintf(complete_filename, 64, "%s.dot", filename);
-    
-    
     fd = open(complete_filename, O_CREAT | O_TRUNC);
-    //if(f == NULL) { nrerror("Can't open file in grawrite_bvector"); }
     
     fprintf(fd, "digraph %s {\n", filename);
@@ -370,8 +442,24 @@
     fprintf(fd, "}\n");
     close(fd);
-}
-/* ------------------------------------------------------------------------------ */
-void mod_ui32matrix_ui8matrix(uint32 **X, int i0, int i1, int j0, int j1, uint8 **Y)
-/* ------------------------------------------------------------------------------ */
+#elif TARGET_OS == LINUX
+    FILE * f;
+    f = fopen(complete_filename, "w");
+    if (f == NULL) {
+        fprintf(stderr, "Can't open file %s in %s\n", complete_filename, __func__);
+    }
+    
+    fprintf(f, "digraph %s {\n", filename);
+    for (i = i0; i <= i1; i++) {
+        fprintf(f, "%3d -> %3d;\n", i, v[i]);
+    }
+    fprintf(f, "}\n");
+    fclose(f);
+#endif
+}
+
+
+/* -------------------------------------------------------------------------------- */
+void mod_ui32matrix_ui8matrix(uint32 ** X, int i0, int i1, int j0, int j1, uint8 ** Y)
+/* -------------------------------------------------------------------------------- */
 {
     int i, j;
@@ -382,7 +470,9 @@
     }
 }
-// ------------------------------------------------------------------------------------------
-void positive_mod_ui32matrix_ui8matrix(uint32 **X, int i0, int i1, int j0, int j1, uint8 **Y)
-// ------------------------------------------------------------------------------------------
+
+
+// --------------------------------------------------------------------------------------------
+void positive_mod_ui32matrix_ui8matrix(uint32 ** X, int i0, int i1, int j0, int j1, uint8 ** Y)
+// --------------------------------------------------------------------------------------------
 {
     int i, j;
@@ -392,8 +482,10 @@
                 if (X[i][j] < 255) {
                     Y[i][j] = X[i][j]; // pour que e=1 reste rouge
-                } else {
+                }
+                else {
                     Y[i][j] = (X[i][j] % 254) + 1;
                 }
-            } else {
+            } 
+            else {
                 Y[i][j] = 0;
             }
@@ -402,17 +494,18 @@
     }
 }
-/* --------------------------------------------------------------------------------- */
-void graphviz_write_ui32vector_par(uint32 *v, int i0, int i1, char *format, char *filename)
-/* --------------------------------------------------------------------------------- */
-{
-    int i;
+
+
+/* ---------------------------------------------------------------------------------------- */
+void graphviz_write_ui32vector_par(uint32 * v, int i0, int i1, char * format, char * filename)
+/* ---------------------------------------------------------------------------------------- */
+{
+    int i;
+    char complete_filename[64];
+    
+    snprintf(complete_filename, 64, "%s.dot", filename);
+    
+#if TARGET_OS == GIETVM 
     int fd;
-    char complete_filename[64];
-    
-    snprintf(complete_filename, 64, "%s.dot", filename);
-    
-    
     fd = open(complete_filename, O_CREAT | O_TRUNC);
-    //if(f == NULL) { nrerror("Can't open file in grawrite_bvector"); }
     
     fprintf(fd, "digraph %s {\n", filename);
@@ -422,5 +515,20 @@
     fprintf(fd, "}\n");
     close(fd);
-}
+#else
+    FILE * f;
+    f = fopen(complete_filename, "w");
+    if (f == NULL) { 
+        fprintf(stderr, "Can't open file %s in %s\n", complete_filename, __func__);
+    }
+    fprintf(f, "digraph %s {\n", filename);
+    for (i = i0; i <= i1; i++) {
+        fprintf(f, "%3d -> %3d;\n", i, v[i]);
+    }
+    fprintf(f, "}\n");
+    fclose(f);
+#endif
+}
+
+
 // --------------------------------------
 uint32 mt19937_uint32(uint32 a, uint32 b)
@@ -431,5 +539,7 @@
     uint32 x32;
 
-    if (b < a) return mt19937_uint32(b, a);
+    if (b < a) {
+        return mt19937_uint32(b, a);
+    }
     
     //printf("a = %u b = %u\n", a, b);
@@ -441,20 +551,24 @@
     return x32;
 }
-// -----------------------
-BOOL strto_Bool(char *str)
-// -----------------------
-{
-    BOOL b = TRUE;
-    if (strcmp(str, "TRUE" ) == 0) b = TRUE;
-    if (strcmp(str, "true" ) == 0) b = TRUE;
-    
-    if (strcmp(str, "FALSE") == 0) b = FALSE;
-    if (strcmp(str, "false") == 0) b = FALSE;
+
+
+// ------------------------
+bool strto_Bool(char * str)
+// ------------------------
+{
+    bool b = true;
+    if (strcmp(str, "TRUE" ) == 0) b = true;
+    if (strcmp(str, "true" ) == 0) b = true;
+    
+    if (strcmp(str, "FALSE") == 0) b = false;
+    if (strcmp(str, "false") == 0) b = false;
     
     return b;
 }
-// ------------------------------------------------------------
-void check_no_write(uint32 **T, int i0, int i1, int j0, int j1)
-// ------------------------------------------------------------
+
+
+// -------------------------------------------------------------
+void check_no_write(uint32 ** T, int i0, int i1, int j0, int j1)
+// -------------------------------------------------------------
 {
     int i, j;
@@ -467,2 +581,4 @@
     }
 }
+
+
Index: soft/giet_vm/applications/rosenfeld/src/ecc_features.c
===================================================================
--- soft/giet_vm/applications/rosenfeld/src/ecc_features.c	(revision 820)
+++ soft/giet_vm/applications/rosenfeld/src/ecc_features.c	(revision 821)
@@ -10,19 +10,14 @@
 // Caracteristiques d'une region / label
 
-//#pragma message("------------------")
-//#pragma message("--- Features.c ---")
-//#pragma message("------------------")
-
 #include <stdio.h>
 #include <stddef.h>
 #include <stdlib.h>
 #include <malloc.h>
-
-
-#ifdef CLI
+#include <string.h>
+
+
 #include "nrc_os_config.h"
+#include "config.h"
 #include "nrc.h"
-#endif
-
 
 
@@ -31,52 +26,60 @@
     #include <sys/stat.h>
     #include <fcntl.h>
+    #include <unistd.h>
 #endif
 
 
-#ifdef OPENMP
-#include <omp.h>
-#endif
-
 #include "ecc_features.h"
-//#include "label.h"
+
+#define BUFF_SIZE 1024 // for snprintf
+
+
+// -------------------------------------------------------------
+void RegionStats_Constructor(RegionStats ** Stats, uint32 nemax)
+// -------------------------------------------------------------
+{
+    *Stats = RegionStats_pConstructor(nemax);
+}
+
+
+// -------------------------------------------------
+RegionStats * RegionStats_pConstructor(uint32 nemax)
+// -------------------------------------------------
+{
+    RegionStats * Stats;
+    
+    Stats = (RegionStats *) malloc((nemax) * sizeof(RegionStats));
+    if (Stats == NULL) {
+        nrerror("allocation failed in RegionStats_pConstructor");
+    }
+    
+    RegionStats_Clear(Stats, nemax);
+    
+    return Stats;
+}
+
 
 // ------------------------------------------------------------
-void RegionStats_Constructor(RegionStats **Stats, uint32 nemax)
+void RegionStats_Destructor(RegionStats ** Stats, uint32 nemax)
 // ------------------------------------------------------------
 {
-    *Stats = RegionStats_pConstructor(nemax);
-}
-// ------------------------------------------------
-RegionStats* RegionStats_pConstructor(uint32 nemax)
-// ------------------------------------------------
-{
-    RegionStats *Stats;
-    
-    Stats = (RegionStats*) malloc((nemax)*sizeof(RegionStats));
-    if(Stats == NULL) nrerror("allocation failed in RegionStats_pConstructor");
-    
-    RegionStats_Clear(Stats, nemax);
-    
-    return Stats;
-}
-// -----------------------------------------------------------
-void RegionStats_Destructor(RegionStats **Stats, uint32 nemax)
-// -----------------------------------------------------------
-{
     RegionStats_pDestructor(*Stats, nemax);
 }
-// -----------------------------------------------------------
-void RegionStats_pDestructor(RegionStats *Stats, uint32 nemax)
-// -----------------------------------------------------------
+
+
+// ------------------------------------------------------------
+void RegionStats_pDestructor(RegionStats * Stats, uint32 nemax)
+// ------------------------------------------------------------
 {
     RegionStats_Clear(Stats, nemax);
     free(Stats);
 }
-// -----------------------------------------------------
-void RegionStats_Clear(RegionStats *Stats, uint32 nemax)
-// -----------------------------------------------------
-{
-    int i;
-    for (i = 0; i < (int) nemax; i++) {
+
+
+// ------------------------------------------------------
+void RegionStats_Clear(RegionStats * Stats, uint32 nemax)
+// ------------------------------------------------------
+{
+    for (int i = 0; i < (int) nemax; i++) {
         Stats[i].xmin = 65535;
         Stats[i].xmax = 0;
@@ -86,20 +89,16 @@
         Stats[i].S = 0;
         
-        Stats[i].x = 0;
-        Stats[i].y = 0;
-        
         Stats[i].Sx = 0;
         Stats[i].Sy = 0;
-        
-#ifdef REGION_STATS2
-        Stats[i].Sx2 = 0;
-        Stats[i].Sxy = 0;
-        Stats[i].Sy2 = 0;
+#if PARMERGE
+        pthread_spin_init(&Stats[i].lock, PTHREAD_PROCESS_PRIVATE);
 #endif
     }
 }
-// ----------------------------------------
-void RegionStats_Clear1(RegionStats *stats)
-// ----------------------------------------
+
+
+// -----------------------------------------
+void RegionStats_Clear1(RegionStats * stats)
+// -----------------------------------------
 {
     stats->xmin = 0;
@@ -110,18 +109,12 @@
     stats->S = 0;
     
-    stats->x = 0;
-    stats->y = 0;
-    
     stats->Sx = 0;
     stats->Sy = 0;
-#ifdef REGION_STATS2
-    stats->Sx2 = 0;
-    stats->Sxy = 0;
-    stats->Sy2 = 0;
-#endif
-}
-// ------------------------------------------
-int RegionStats_Create_File(char *filename)
-// ------------------------------------------
+}
+
+
+// -----------------------------------------
+int RegionStats_Create_File(char * filename)
+// -----------------------------------------
 {
     int fd;
@@ -130,11 +123,13 @@
     if (fd < 0) {
         printf("RegionStats_Open_File : can't create file %s\n", filename);
-        giet_pthread_exit("");
+        exit(1);
     }
     return fd;
 }
-// ----------------------------------------
-int RegionStats_Open_File(char *filename)
-// ----------------------------------------
+
+
+// ---------------------------------------
+int RegionStats_Open_File(char * filename)
+// ---------------------------------------
 {
     int fd;
@@ -143,31 +138,43 @@
     if (fd < 0) {
         printf("RegionStats_Open_File : can't open file %s\n", filename);
-        giet_pthread_exit("");
+        exit(1);
     }
     return fd;
 }
-// ---------------------------------
+
+
+// --------------------------------
 void RegionStats_Close_File(int fd)
-// ---------------------------------
+// --------------------------------
 {
     close(fd);
 }
-// --------------------------------- 
+
+
+#if 0 // pb : fscanf requires manipulating FILE *
+// -------------------------------- 
 int RegionStats_Read_Header(int fd)
-// --------------------------------- 
+// -------------------------------- 
 {
     int ne = 0;
-    // @QM giet
     fscanf(fd, "%d", &ne);
     return ne;
 }
-// ------------------------------------------- 
+#endif
+
+
+// ------------------------------------------ 
 void RegionStats_Write_Header(int ne, int fd)
-// ------------------------------------------- 
-{
-    fprintf(fd, "%d\n", ne);
-}
+// ------------------------------------------ 
+{
+    char buff[BUFF_SIZE];
+    snprintf(buff, BUFF_SIZE, "%d\n", ne);
+    write(fd, buff, strlen(buff) + 1);
+}
+
+
+#if 0
 // -------------------------------------------------------------- 
-void RegionStats_Read_Stats1(int fd, int ne, RegionStats *Stats)
+void RegionStats_Read_Stats1(int fd, int ne, RegionStats * Stats)
 // -------------------------------------------------------------- 
 {
@@ -184,52 +191,17 @@
                &(Stats[i].Sx),
                &(Stats[i].Sy));
-        
-        Stats[i].x = Stats[i].Sx / Stats[i].S;
-        Stats[i].y = Stats[i].Sy / Stats[i].S;
-        
-    }
-}
-// -------------------------------------------------------------- 
-void RegionStats_Read_Stats2(int fd, int ne, RegionStats *Stats)
-// -------------------------------------------------------------- 
-{
-#ifdef REGION_STATS2
-    int i, t;
-    
-    int32 Sx2, Sxy, Sy2;
-    
-    for (i = 1; i <= ne; i++) {
-        fscanf(f, "%d%d%d%d%d%d%d%d%d%d%d\n",
-               &t,
-               &(Stats[i].xmin),
-               &(Stats[i].xmax),
-               &(Stats[i].ymin),
-               &(Stats[i].ymax),
-               &(Stats[i].S),
-               &(Stats[i].Sx),
-               &(Stats[i].Sy),
-               &(Sx2),
-               &(Sxy),
-               &(Sy2));
-        
-        Stats[i].Sx2 = Sx2;
-        Stats[i].Sxy = Sxy;
-        Stats[i].Sy2 = Sy2;
-        
-        Stats[i].x = Stats[i].Sx / Stats[i].S;
-        Stats[i].y = Stats[i].Sy / Stats[i].S;
-    }
-#else
-    nrerror("RegionStats_Read_Stats2 REGION_STAT2 not defined");
+    }
+}
 #endif
-}
+
+
 // ---------------------------------------------------------------
-void RegionStats_Write_Stats1(RegionStats *Stats, int ne, int fd)
+void RegionStats_Write_Stats1(RegionStats * Stats, int ne, int fd)
 // ---------------------------------------------------------------
 {
-    int i;
-    
-    for (i = 1; i <= ne; i++) {
-        fprintf(fd, "%4d %5d %5d %5d %5d %7d %8d %8d\n",
+    char buff[BUFF_SIZE];
+    
+    for (int i = 1; i <= ne; i++) {
+        snprintf(buff, BUFF_SIZE, "%4d %5d %5d %5d %5d %7d %8d %8d\n",
                 i,
                 Stats[i].xmin,
@@ -241,15 +213,19 @@
                 Stats[i].Sx,
                 Stats[i].Sy);
-    }
-}
-// --------------------------------------------------------------------------------------------------
-void RegionStats_Write_Stats1_Sparse(RegionStats *Stats, uint32 *EQ, uint32 ne0, uint32 ne1, int fd)
-// --------------------------------------------------------------------------------------------------
+        write(fd, buff, strlen(buff) + 1);
+    }
+}
+
+
+// ---------------------------------------------------------------------------------------------------
+void RegionStats_Write_Stats1_Sparse(RegionStats * Stats, uint32 * EQ, uint32 ne0, uint32 ne1, int fd)
+// ---------------------------------------------------------------------------------------------------
 {
     uint32 e;
+    char buff[BUFF_SIZE];
     
     for (e = ne0; e <= ne1; e++) {
         if ((e == EQ[e]) && (Stats[e].S > 0)) {
-            fprintf(fd, "%4d %5d %5d %5d %5d %7d %8d %8d\n",
+            snprintf(buff, BUFF_SIZE, "%4d %5d %5d %5d %5d %7d %8d %8d\n",
                     e,
                     Stats[e].xmin,
@@ -261,41 +237,18 @@
                     Stats[e].Sx,
                     Stats[e].Sy);
-        }
-    }
-}
-// ---------------------------------------------------------------
-void RegionStats_Write_Stats2(RegionStats *Stats, int ne, int fd)
-// ---------------------------------------------------------------
-{
-#ifdef REGION_STATS2
-    int i;
-    for (i = 1; i <= ne; i++) {
-        fprintf(fd, "%4d %4d %4d %4d %6d %8d %8d %8d %8d %8d\n",
-                i,
-                Stats[i].xmin,
-                Stats[i].xmax,
-                Stats[i].ymin,
-                Stats[i].ymax,
-                
-                Stats[i].S,
-                Stats[i].Sx,
-                Stats[i].Sy,
-                
-                (int32) Stats[i].Sx2,
-                (int32) Stats[i].Sxy,
-                (int32) Stats[i].Sy2);
-    }
-#else
-    nrerror("RegionStats_Write_Stats2: REGION_STATS2 not defined");
-#endif
-}
+            write(fd, buff, strlen(buff) + 1);
+        }
+    }
+}
+
+
 // -----------------------------------------------------------------
-void RegionStats_Write_pStats1(RegionStats **Stats, int ne, int fd)
+void RegionStats_Write_pStats1(RegionStats ** Stats, int ne, int fd)
 // -----------------------------------------------------------------
 {
-    int i;
-    
-    for (i = 1; i <= ne; i++) {
-        fprintf(fd, "%4d %5d %5d %5d %5d %7d %8d %8d\n",
+    char buff[BUFF_SIZE];
+    
+    for (int i = 1; i <= ne; i++) {
+        snprintf(buff, BUFF_SIZE, "%4d %5d %5d %5d %5d %7d %8d %8d\n",
                 i,
                 Stats[i]->xmin,
@@ -306,34 +259,13 @@
                 Stats[i]->Sx,
                 Stats[i]->Sy);
-    }
-}
-// -----------------------------------------------------------------
-void RegionStats_Write_pStats2(RegionStats **Stats, int ne, int fd)
-// -----------------------------------------------------------------
-{
-#ifdef REGION_STATS2
-    int i;
-    for (i = 1; i <= ne; i++) {
-        fprintf(fd, "%3d %4d %4d %4d %4d %6d %8d %8d %8d %8d %8d\n",
-                i,
-                Stats[i]->xmin,
-                Stats[i]->xmax,
-                Stats[i]->ymin,
-                Stats[i]->ymax,
-                Stats[i]->S,
-                Stats[i]->Sx,
-                Stats[i]->Sy,
-                
-                (int32) Stats[i]->Sx2,
-                (int32) Stats[i]->Sxy,
-                (int32) Stats[i]->Sy2);
-    }
-#else
-    nrerror("RegionStats_Write_Stats2: REGION_STATS2 not defined");
-#endif
-}
-// -----------------------------------------------------------------------
-void RegionStats_Load_Stats1(char *filename, int *ne, RegionStats **Stats)
-// -----------------------------------------------------------------------
+        write(fd, buff, strlen(buff) + 1);
+    }
+}
+
+
+#if 0
+// --------------------------------------------------------------------------
+void RegionStats_Load_Stats1(char * filename, int * ne, RegionStats ** Stats)
+// --------------------------------------------------------------------------
 {
     int fd;
@@ -347,25 +279,9 @@
     RegionStats_Close_File(fd);
 }
-// -----------------------------------------------------------------------
-void RegionStats_Load_Stats2(char *filename, int *ne, RegionStats **Stats)
-// -----------------------------------------------------------------------
-{
-#ifdef REGION_STATS2
-    int fd;
-    
-    fd = RegionStats_Open_File(filename);
-    
-    *ne = RegionStats_Read_Header(fd);
-    
-    RegionStats_Constructor(Stats, *ne);
-    RegionStats_Read_Stats2(fd, *ne, *Stats);
-    RegionStats_Close_File(fd);
-#else
-    nrerror("RegionStats_Load_Stats2 : REGION_STATS2 not defined");
-#endif
-}
-// -----------------------------------------------------------------------
-void RegionStats_MLoad_Stats1(char *filename, int *ne, RegionStats *Stats)
-// -----------------------------------------------------------------------
+
+
+// --------------------------------------------------------------------------
+void RegionStats_MLoad_Stats1(char * filename, int * ne, RegionStats * Stats)
+// --------------------------------------------------------------------------
 {
     int fd;
@@ -377,23 +293,9 @@
     RegionStats_Close_File(fd);
 }
+#endif
+
 // -----------------------------------------------------------------------
-void RegionStats_MLoad_Stats2(char *filename, int *ne, RegionStats *Stats)
+void RegionStats_Save_Stats1(RegionStats * Stats, int ne, char * filename)
 // -----------------------------------------------------------------------
-{
-#ifdef REGION_STATS2
-    int fd
-    
-    fd = RegionStats_Open_File(filename);
-    
-    *ne = RegionStats_Read_Header(fd);
-    RegionStats_Read_Stats2(fd, *ne, Stats);
-    RegionStats_Close_File(fd);
-#else
-    nrerror("RegionStats_MLoad_Stats2 : REGION_STATS2 not defined");
-#endif
-}
-// ---------------------------------------------------------------------
-void RegionStats_Save_Stats1(RegionStats *Stats, int ne, char *filename)
-// ---------------------------------------------------------------------
 {
     int fd;
@@ -405,23 +307,9 @@
     RegionStats_Close_File(fd);
 }
-// ---------------------------------------------------------------------
-void RegionStats_Save_Stats2(RegionStats *Stats, int ne, char *filename)
-// ---------------------------------------------------------------------
-{
-#ifdef REGION_STATS2
-    int fd;
-    
-    fd = RegionStats_Create_File(filename);
-    
-    RegionStats_Write_Header(ne, fd);
-    RegionStats_Write_Stats2(Stats, ne, fd);
-    RegionStats_Close_File(fd);
-#else
-    nrerror("RegionStats_Save_Stats2 : REGION_STATS2 not defined");
-#endif
-}
-// -----------------------------------------------------------------------
-void RegionStats_Save_pStats1(RegionStats **Stats, int ne, char *filename)
-// -----------------------------------------------------------------------
+
+
+// -------------------------------------------------------------------------
+void RegionStats_Save_pStats1(RegionStats ** Stats, int ne, char * filename)
+// -------------------------------------------------------------------------
 {
     int fd;
@@ -433,26 +321,10 @@
     RegionStats_Close_File(fd);
 }
-// -----------------------------------------------------------------------
-void RegionStats_Save_pStats2(RegionStats **Stats, int ne, char *filename)
-// -----------------------------------------------------------------------
-{
-#ifdef REGION_STATS2
-    int fd;
-    
-    fd = RegionStats_Create_File(filename);
-    
-    RegionStats_Write_Header(ne, fd);
-    RegionStats_Write_pStats2(Stats, ne, fd);
-    RegionStats_Close_File(fd);
-#else
-    nrerror("RegionStats_Save_Stats2 : REGION_STATS2 not defined");
-#endif
-}
-// --------------------------------------------------------------------
-void RegionStats_Display_Stats1(RegionStats *Stats, int ne, char *name)
-// --------------------------------------------------------------------
-{
-    int i;
-    
+
+
+// ----------------------------------------------------------------------
+void RegionStats_Display_Stats1(RegionStats * Stats, int ne, char * name)
+// ----------------------------------------------------------------------
+{
     if (name != NULL) {
         printf("%s : %d\n", name, ne);
@@ -461,5 +333,5 @@
         printf("RegionStats : %d\n", ne);
     }
-    for (i = 1; i <= ne; i++) {
+    for (int i = 1; i <= ne; i++) {
         printf("#%3d: %4d %4d %4d %4d %6d %8d %8d\n",
                i,
@@ -473,11 +345,10 @@
     }
 }
-// --------------------------------------------------------------------
-void RegionStats_Display_Stats2(RegionStats *Stats, int ne, char *name)
-// --------------------------------------------------------------------
-{
-#ifdef REGION_STATS2
-    int i;
-    
+
+
+// ------------------------------------------------------------------------
+void RegionStats_Display_pStats1(RegionStats ** Stats, int ne, char * name)
+// ------------------------------------------------------------------------
+{
     if (name != NULL) {
         printf("%s : %d\n", name, ne);
@@ -486,38 +357,5 @@
         printf("RegionStats : %d\n", ne);
     }
-    
-    for (i = 1; i <= ne; i++) {
-        printf("#%3d: %4d %4d %4d %4d %6d %8d %8d %8d %8d %8d\n",
-               i,
-               Stats[i].xmin,
-               Stats[i].xmax,
-               Stats[i].ymin,
-               Stats[i].ymax,
-               Stats[i].S,
-               Stats[i].Sx,
-               Stats[i].Sy,
-               
-               (int32) Stats[i].Sx2,
-               (int32) Stats[i].Sxy,
-               (int32) Stats[i].Sy2);
-        
-    }
-#else
-    nrerror("RegionStats_Display_Stats2 : REGION_STATS2 not defined");
-#endif
-}
-// ----------------------------------------------------------------------
-void RegionStats_Display_pStats1(RegionStats **Stats, int ne, char *name)
-// ----------------------------------------------------------------------
-{
-    int i;
-    
-    if (name != NULL) {
-        printf("%s : %d\n", name, ne);
-    }
-    else {
-        printf("RegionStats : %d\n", ne);
-    }
-    for (i = 1; i <= ne; i++) {
+    for (int i = 1; i <= ne; i++) {
         printf("#%3d: %4d %4d %4d %4d %6d %8d %8d\n",
                i,
@@ -531,40 +369,9 @@
     }
 }
-// ----------------------------------------------------------------------
-void RegionStats_Display_pStats2(RegionStats **Stats, int ne, char *name)
-// ----------------------------------------------------------------------
-{
-#ifdef REGION_STATS2
-    int i;
-    
-    if (name != NULL) {
-        printf("%s : %d\n", name, ne);
-    }
-    else {
-        printf("RegionStats : %d\n", ne);
-    }
-    for (i = 1; i <= ne; i++) {
-        printf("#%3d: %4d %4d %4d %4d %6d %8d %8d %8d %8d %8d\n",
-               i,
-               Stats[i]->xmin,
-               Stats[i]->xmax,
-               Stats[i]->ymin,
-               Stats[i]->ymax,
-               Stats[i]->S,
-               Stats[i]->Sx,
-               Stats[i]->Sy,
-               
-               (int32) Stats[i]->Sx2,
-               (int32) Stats[i]->Sxy,
-               (int32) Stats[i]->Sy2);
-        
-    }
-#else
-    nrerror("RegionStats_Display_Stats2 : REGION_STATS2 not defined");
-#endif
-}
-// ---------------------------------------------------------------------------------------------
-void RegionStats_SetRectangle(RegionStats *Stats, int e, int ymin, int ymax, int xmin, int xmax)
-// ---------------------------------------------------------------------------------------------
+
+
+// ----------------------------------------------------------------------------------------------
+void RegionStats_SetRectangle(RegionStats * Stats, int e, int ymin, int ymax, int xmin, int xmax)
+// ----------------------------------------------------------------------------------------------
 {
     Stats[e].ymin = ymin;
@@ -573,7 +380,9 @@
     Stats[e].xmax = xmax;
 }
-// -------------------------------------------------------
-void RegionStats_Copy1(RegionStats *src, RegionStats *dst)
-// -------------------------------------------------------
+
+
+// ---------------------------------------------------------
+void RegionStats_Copy1(RegionStats * src, RegionStats * dst)
+// ---------------------------------------------------------
 {
     dst->xmin = src->xmin;
@@ -584,40 +393,16 @@
     dst->S    = src->S;
     
-    dst->x    = src->x;
-    dst->y    = src->y;
-    
     dst->Sx   = src->Sx;
     dst->Sy   = src->Sy;
-    
-#ifdef REGION_STATS2
-    dst->Sx2  = src->Sx2;
-    dst->Sxy  = src->Sxy;
-    dst->Sy2  = src->Sy2;
-    dst->teta = src->teta;
-#endif
-    
-#ifdef REGION_STATS3
-    dst->Sx3  = src->Sx3;
-    dst->Sx2y = src->Sx2y;
-    dst->Sxy2 = src->Sxy2;
-    dst->Sy3  = src->Sy3;
-    
-    dst->Mx2  = src->Mx2;
-    dst->Mxy  = src->Mxy;
-    dst->My2  = src->My2;
-    
-    dst->Mx3  = src->Mx3;
-    dst->Mx2y = src->Mx2y;
-    dst->Mxy2 = src->Mxy2;
-    dst->My3  = src->My3;
-#endif
-}
+}
+
+
 // ===============================
 // === nouvelles versions 2009 ===
 // ===============================
 
-// -------------------------------------------
-RegionStats* RegionStatsVector(int i0, int i1)
-// -------------------------------------------
+// --------------------------------------------
+RegionStats * RegionStatsVector(int i0, int i1)
+// --------------------------------------------
 // allocate a float vector with subscript range v[i0..i1]
 {
@@ -625,51 +410,119 @@
     
     v = (RegionStats *) malloc((size_t) ((i1 - i0 + 1 + NR_END) * sizeof(RegionStats)));
-    if (!v) nrerror("allocation failure in RegionStatsVector()");
-    if (!v) return NULL;
+    if (!v) {
+        nrerror("allocation failure in %s()", __func__);
+        return NULL;
+    }
+    RegionStats_Clear(v, i1 - i0 + 1 + NR_END);
     return v - i0 + NR_END;
 }
-// ----------------------------------------------------------
-RegionStats* RegionStatsVector0(int i0, int i1)
-// ----------------------------------------------------------
+
+
+#if TARGET_OS == GIETVM
+// -----------------------------------------------------------------
+RegionStats * remote_RegionStatsVector(int i0, int i1, int x, int y)
+// -----------------------------------------------------------------
 // allocate a float vector with subscript range v[i0..i1]
 {
-    RegionStats *v;
+    RegionStats * v;
+    
+    v = (RegionStats *) remote_malloc((size_t) ((i1 - i0 + 1 + NR_END) * sizeof(RegionStats)), x, y);
+    if (!v) {
+        nrerror("allocation failure in %s()", __func__);
+        return NULL;
+    }
+    RegionStats_Clear(v, i1 - i0 + 1 + NR_END);
+    return v - i0 + NR_END;
+}
+#endif
+
+
+// ---------------------------------------------
+RegionStats * RegionStatsVector0(int i0, int i1)
+// ---------------------------------------------
+// allocate a float vector with subscript range v[i0..i1]
+{
+    RegionStats * v;
     
     v = (RegionStats *) calloc((size_t) (i1 - i0 + 1 + NR_END), sizeof(RegionStats));
-    if (!v) nrerror("allocation failure in RegionStatsVector0()");
-    if (!v) return NULL;
+    if (!v) {
+        nrerror("allocation failure in RegionStatsVector0()");
+        return NULL;
+    }
     return v - i0 + NR_END;
 }
-// ----------------------------------------------------------------------
-void free_RegionStatsVector(RegionStats *v, int i0, int i1)
-// ----------------------------------------------------------
+
+
+// ---------------------------------------------------------
+void free_RegionStatsVector(RegionStats * v, int i0, int i1)
+// ---------------------------------------------------------
 // free a RegionStats vector allocated with vector()
 {
-    free((FREE_ARG) (v + i0 - NR_END));
-}
-// ------------------------------------------------------------
-RegionStats** RegionStatsMatrix(int i0, int i1, int j0, int j1)
-// ------------------------------------------------------------
+    free(v + i0 - NR_END);
+}
+
+
+// -------------------------------------------------------------
+RegionStats ** RegionStatsMatrix(int i0, int i1, int j0, int j1)
+// -------------------------------------------------------------
 
 // allocate a RegionStats matrix with subscript range m[nrl..nrh][ncl..nch]
+{
+    long nrow = i1 - i0 + 1;
+    long ncol = j1 - j0 + 1;
+    RegionStats ** m;
+    
+    // allocate pointers to rows
+    m = (RegionStats **) malloc((size_t) ((nrow + NR_END) * sizeof(RegionStats *)));
+    if (!m) {
+        nrerror("allocation failure 1 in RegionStatsMatrix()");
+    }
+    m += NR_END;
+    m -= i0;
+    
+    // allocate rows and set pointers to them
+    m[i0] = (RegionStats *) malloc((size_t) ((nrow * ncol + NR_END) * sizeof(RegionStats)));
+    if (!m[i0]) {
+        nrerror("allocation failure 2 in RegionStatsMatrix()");
+    }
+    m[i0] += NR_END;
+    m[i0] -= j0;
+    
+    for (int i = i0 + 1; i <= i1; i++) {
+        m[i] = m[i - 1] + ncol;
+    }
+    
+    // return pointer to array of pointers to rows
+    return m;
+}
+
+
+// --------------------------------------------------------------
+RegionStats ** RegionStatsMatrix0(int i0, int i1, int j0, int j1)
+// --------------------------------------------------------------
+// allocate a float matrix with subscript range m[nrl..nrh][ncl..nch]
 {
     long i;
     long nrow = i1 - i0 + 1;
     long ncol = j1 - j0 + 1;
-    RegionStats **m;
+    RegionStats ** m;
     
     // allocate pointers to rows
-    m = (RegionStats **) malloc((size_t) ((nrow + NR_END) * sizeof(RegionStats *)));
-    if (!m) nrerror("allocation failure 1 in RegionStatsMatrix()");
+    m= (RegionStats **) malloc((size_t) ((nrow + NR_END) * sizeof(RegionStats*)));
+    if (!m) {
+        nrerror("allocation failure 1 in RegionStatsMatrix()");
+    }
     m += NR_END;
     m -= i0;
     
     // allocate rows and set pointers to them
-    m[i0] = (RegionStats *) malloc((size_t) ((nrow * ncol + NR_END) * sizeof(RegionStats)));
-    if (!m[i0]) nrerror("allocation failure 2 in RegionStatsMatrix()");
+    m[i0] = (RegionStats *) calloc((size_t) (nrow * ncol + NR_END), sizeof(RegionStats));
+    if (!m[i0]) {
+        nrerror("allocation failure 2 in RegionStatsMatrix()");
+    }
     m[i0] += NR_END;
     m[i0] -= j0;
     
-    for(i = i0 + 1; i <= i1; i++) {
+    for (i = i0 + 1; i <= i1; i++) {
         m[i] = m[i - 1] + ncol;
     }
@@ -678,40 +531,18 @@
     return m;
 }
-// -------------------------------------------------------------
-RegionStats** RegionStatsMatrix0(int i0, int i1, int j0, int j1)
-// -------------------------------------------------------------
-
-// allocate a float matrix with subscript range m[nrl..nrh][ncl..nch]
-{
-    long i, nrow=i1-i0+1,ncol=j1-j0+1;
-    RegionStats **m;
-    
-    // allocate pointers to rows
-    m=(RegionStats**) malloc((size_t)((nrow+NR_END)*sizeof(RegionStats*)));
-    if (!m) nrerror("allocation failure 1 in RegionStatsMatrix()");
-    m += NR_END;
-    m -= i0;
-    
-    // allocate rows and set pointers to them
-    m[i0]=(RegionStats*) calloc((size_t)(nrow*ncol+NR_END), sizeof(RegionStats));
-    if (!m[i0]) nrerror("allocation failure 2 in RegionStatsMatrix()");
-    m[i0] += NR_END;
-    m[i0] -= j0;
-    
-    for(i=i0+1;i<=i1;i++) m[i]=m[i-1]+ncol;
-    
-    // return pointer to array of pointers to rows
-    return m;
-}
-// -------------------------------------------------------------------------
-void free_RegionStatsMatrix(RegionStats **m, int i0, int i1, int j0, int j1)
-// -------------------------------------------------------------------------
-{
-    free((FREE_ARG) (m[i0]+j0-NR_END));
-    free((FREE_ARG) (m+i0-NR_END));
-}
-// ----------------------------------
-void zero_RegionStats(RegionStats *x)
-// ----------------------------------
+
+
+// --------------------------------------------------------------------------
+void free_RegionStatsMatrix(RegionStats ** m, int i0, int i1, int j0, int j1)
+// --------------------------------------------------------------------------
+{
+    free(m[i0] + j0 - NR_END);
+    free(m + i0 - NR_END);
+}
+
+
+// -----------------------------------
+void zero_RegionStats(RegionStats * x)
+// -----------------------------------
 {
     x->xmin = 32767;
@@ -723,38 +554,37 @@
     x->Sx = 0;
     x->Sy = 0;
-    
-#ifdef REGION_STATS2
-    x->Sx2 = 0;
-    x->Sxy = 0;
-    x->Sy2 = 0;
-#endif
-}
-// --------------------------------------------------------
-void zero_RegionStatsVector(RegionStats *v, int i0, int i1)
-// --------------------------------------------------------
-{
-    int i;
-    for(i=i0; i<=i1; i++) {
+}
+
+
+// ---------------------------------------------------------
+void zero_RegionStatsVector(RegionStats * v, int i0, int i1)
+// ---------------------------------------------------------
+{
+    for (int i = i0; i <= i1; i++) {
         zero_RegionStats(&v[i]);
     }
 }
-// -------------------------------------------------------------------------
-void zero_RegionStatsMatrix(RegionStats **m, int i0, int i1, int j0, int j1)
-// -------------------------------------------------------------------------
-{
-    int i, j;
-    for(i=i0; i<=i1; i++) {
-        for(j=j0; j<=j1; j++) {         
+
+
+// --------------------------------------------------------------------------
+void zero_RegionStatsMatrix(RegionStats ** m, int i0, int i1, int j0, int j1)
+// --------------------------------------------------------------------------
+{
+    for (int i = i0; i <= i1; i++) {
+        for (int j = j0; j <= j1; j++) {         
             zero_RegionStats(&(m[i][j]));
         }
     }
 }
-// -------------------------------------------------
-void display_RegionStats(RegionStats *x, char *name)
-// -------------------------------------------------
-{
-    if(name != NULL) printf("%s : \n", name);
-    
-#ifndef REGION_STATS2
+
+
+// ---------------------------------------------------
+void display_RegionStats(RegionStats * x, char * name)
+// ---------------------------------------------------
+{
+    if (name != NULL) {
+        printf("%s : \n", name);
+    }
+ 
     printf("%4d %4d %4d %4d %6d %8d %8d\n",
            x->xmin,
@@ -766,42 +596,37 @@
            x->Sx,
            x->Sy);
-#else
-    printf("%4d %4d %4d %4d %6d %8d %8d %8d %8d %8d\n",
-           x->xmin,
-           x->xmax,
-           x->ymin,
-           x->ymax,
-           
-           x->S,
-           x->Sx,
-           x->Sy,
-           
-           x->Sx2,
-           x->Sxy,
-           x->Sy2);
-#endif  
-}
-// -----------------------------------------------------------------------
-void display_RegionStatsVector(RegionStats *v, int i0, int i1, char *name)
-// -----------------------------------------------------------------------
-{
-    int i;
-    
-    if(name != NULL) printf("%s : [%d..%d]\n", name, i0, i1); else printf("RegionStats : [%d..%d]\n", i0, i1);
-    for(i=i0; i<=i1; i++) {
+}
+
+
+// ------------------------------------------------------------------------
+void display_RegionStatsVector(RegionStats * v, int i0, int i1, char *name)
+// ------------------------------------------------------------------------
+{
+    if (name != NULL) {
+        printf("%s : [%d..%d]\n", name, i0, i1);
+    }
+    else {
+        printf("RegionStats : [%d..%d]\n", i0, i1);
+    }
+    for (int i = i0; i <= i1; i++) {
         printf("#%3d: ", i);
         display_RegionStats(&(v[i]), NULL);
-        //puts("");
-    }
-}
-// ----------------------------------------------------------------------------------------
-void display_RegionStatsMatrix(RegionStats **m, int i0, int i1, int j0, int j1, char *name)
-// ----------------------------------------------------------------------------------------
-{
-    int i, j;
-    
-    if (name != NULL) printf("%s : [%d..%d][%d..%d]\n", name, i0, i1, j0, j1); else printf("RegionStats : [%d..%d][%d..%d]\n", i0, i1, j0, j1);
-    for (i = i0; i <= i1; i++) {
-        for (j = j0; j <= j1; j++) {
+    }
+}
+
+
+// ------------------------------------------------------------------------------------------
+void display_RegionStatsMatrix(RegionStats ** m, int i0, int i1, int j0, int j1, char * name)
+// ------------------------------------------------------------------------------------------
+{
+    
+    if (name != NULL) {
+        printf("%s : [%d..%d][%d..%d]\n", name, i0, i1, j0, j1);
+    }
+    else {
+        printf("RegionStats : [%d..%d][%d..%d]\n", i0, i1, j0, j1);
+    }
+    for (int i = i0; i <= i1; i++) {
+        for (int j = j0; j <= j1; j++) {
             printf("#%3d: ", i);
             display_RegionStats(&(m[i][j]), NULL);
@@ -809,9 +634,12 @@
     }
 }
-// ----------------------------------------------
-void save_RegionStats(RegionStats *x, char *name)
-// ----------------------------------------------
+
+
+// ------------------------------------------------
+void save_RegionStats(RegionStats * x, char * name)
+// ------------------------------------------------
 {
     int fd = -1;
+    char buff[BUFF_SIZE];
     
     if (name == NULL) {
@@ -824,9 +652,6 @@
         printf("*** Erreur : ouverture du fichier %s dans %s\n", name, __func__);
     }
-    fprintf(fd, "%s: ", name);
-    
-#ifndef REGION_STATS2
-    fprintf(fd, "%4d %4d %4d %4d %6d %8d %8d\n",
-            
+    snprintf(buff, BUFF_SIZE, "%s: %4d %4d %4d %4d %6d %8d %8d\n",
+            name,
             x->xmin,
             x->xmax,
@@ -837,20 +662,5 @@
             x->Sx,
             x->Sy);
-#else
-    fprintf(fd, "%4d %4d %4d %4d %6d %8d %8d %8d %8d %8d\n",
-            
-            x->xmin,
-            x->xmax,
-            x->ymin,
-            x->ymax,
-            
-            x->S,
-            x->Sx,
-            x->Sy,
-            
-            x->Sx2,
-            x->Sxy,
-            x->Sy2);
-#endif  
+    write(fd, buff, strlen(buff) + 1);
     
     if (name) {
@@ -858,10 +668,12 @@
     }    
 }
-// --------------------------------------------------------------------
-void save_RegionStatsVector(RegionStats *v, int i0, int i1, char *name)
-// --------------------------------------------------------------------
-{
-    int i;
+
+
+// ----------------------------------------------------------------------
+void save_RegionStatsVector(RegionStats * v, int i0, int i1, char * name)
+// ----------------------------------------------------------------------
+{
     int fd;
+    char buff[BUFF_SIZE];
     
     if (name == NULL) {
@@ -870,19 +682,21 @@
     fd = RegionStats_Create_File(name);
     
-    fprintf(fd, "%s : [%d..%d]\n", name, i0, i1);
-    
-    for (i = i0; i <= i1; i++) {
+    snprintf(buff, BUFF_SIZE, "%s : [%d..%d]\n", name, i0, i1);
+    write(fd, buff, strlen(buff) + 1);
+    
+    for (int i = i0; i <= i1; i++) {
         printf("#%3d: ", i);
         save_RegionStats(&v[i], NULL);
-        printf("");
     }
     RegionStats_Close_File(fd);
 }
-// -------------------------------------------------------------------------------------
-void save_RegionStatsMatrix(RegionStats **m, int i0, int i1, int j0, int j1, char *name)
-// -------------------------------------------------------------------------------------
-{
-    int i, j;
+
+
+// ---------------------------------------------------------------------------------------
+void save_RegionStatsMatrix(RegionStats ** m, int i0, int i1, int j0, int j1, char * name)
+// ---------------------------------------------------------------------------------------
+{
     int fd;
+    char buff[BUFF_SIZE];
     
     if (name == NULL) {
@@ -891,27 +705,38 @@
     fd = RegionStats_Create_File(name);
     
-    fprintf(fd, "%s : [%d..%d]\n", name, i0, i1);
-    
-    for (i = i0; i <= i1; i++) {
-        for (j = j0; j <= j1; j++) {
-            fprintf(fd, "#%3d: ", i);
+    snprintf(buff, BUFF_SIZE, "%s : [%d..%d]\n", name, i0, i1);
+    write(fd, buff, strlen(buff) + 1);
+    
+    for (int i = i0; i <= i1; i++) {
+        for (int j = j0; j <= j1; j++) {
+            snprintf(buff, BUFF_SIZE, "#%3d: ", i);
+            write(fd, buff, strlen(buff) + 1);
             save_RegionStats(&m[i][j], NULL);
         }
-        printf("");
     }
     RegionStats_Close_File(fd);
 }
-// ------------------------------------------------------------------------------
-void RegionStats_Calc1_Features_1Pass(RegionStats *Stats, uint32 e, int i, int j)
-// ------------------------------------------------------------------------------
+
+
+// -------------------------------------------------------------------------------
+void RegionStats_Calc1_Features_1Pass(RegionStats * Stats, uint32 e, int i, int j)
+// -------------------------------------------------------------------------------
 {
     // calcul sur 1 point et non sur toute l'image
 	// Rectangle
 	
-    if (i < Stats[e].ymin) Stats[e].ymin = i;
-	if (i > Stats[e].ymax) Stats[e].ymax = i;
-    
-    if (j < Stats[e].xmin) Stats[e].xmin = j;
-	if (j > Stats[e].xmax) Stats[e].xmax = j;	
+    if (i < Stats[e].ymin) {
+        Stats[e].ymin = i;
+    }
+	if (i > Stats[e].ymax) {
+        Stats[e].ymax = i;
+    }
+    
+    if (j < Stats[e].xmin) {
+        Stats[e].xmin = j;
+    }
+	if (j > Stats[e].xmax) {
+        Stats[e].xmax = j;	
+    }
     
 	// Moment1
@@ -922,29 +747,37 @@
 	return;
 }
+
+
 // --------------------------------
 // --- fonctions de 2013 ----------
 // --------------------------------
-// -------------------------------------------------------------------------------------------
-void RegionStats_Calc_Rectangle_Moment1(uint32 **E, int height, int width, RegionStats *Stats)
-// -------------------------------------------------------------------------------------------
-{
-    int i, j;
+// ---------------------------------------------------------------------------------------------
+void RegionStats_Calc_Rectangle_Moment1(uint32 ** E, int height, int width, RegionStats * Stats)
+// ---------------------------------------------------------------------------------------------
+{
     uint32 x, y;
     uint32 e;
     
-    for (i = 0; i < height; i++) {
-        for (j = 0; j < width; j++) {
+    for (int i = 0; i < height; i++) {
+        for (int j = 0; j < width; j++) {
             
             e = E[i][j];
             if (e) {
-                
                 x = j;
                 y = i;
                 
-                if (i<Stats[e].ymin) Stats[e].ymin = y;
-                if (i>Stats[e].ymax) Stats[e].ymax = y;
+                if (i < Stats[e].ymin) {
+                    Stats[e].ymin = y;
+                }
+                if (i > Stats[e].ymax) {
+                    Stats[e].ymax = y;
+                }
                 
-                if (j<Stats[e].xmin) Stats[e].xmin = x;
-                if (j>Stats[e].xmax) Stats[e].xmax = x;
+                if (j < Stats[e].xmin) {
+                    Stats[e].xmin = x;
+                }
+                if (j > Stats[e].xmax) {
+                    Stats[e].xmax = x;
+                }
                 
                 Stats[e].S  += 1;
@@ -955,7 +788,9 @@
     }
 }
-// -----------------------------------------------------------------------------------------------------------------------------
-void RegionStats_calc_Status(RegionStats *Stats, uint32 ne, uint32 min_height, uint32 min_width, uint32 min_area, uint8 *status)
-// -----------------------------------------------------------------------------------------------------------------------------
+
+
+// -------------------------------------------------------------------------------------------------------------------------------
+void RegionStats_calc_Status(RegionStats * Stats, uint32 ne, uint32 min_height, uint32 min_width, uint32 min_area, uint8 * status)
+// -------------------------------------------------------------------------------------------------------------------------------
 {
     uint16 xmin, xmax, ymin, ymax, xsize, ysize;
@@ -983,7 +818,9 @@
     }
 }
-// --------------------------------------------------------------------------
-uint32 RegionStats_UpdateEQ_with_Status(uint8 *status, uint32 ne, uint32 *EQ)
-// --------------------------------------------------------------------------
+
+
+// ----------------------------------------------------------------------------
+uint32 RegionStats_UpdateEQ_with_Status(uint8 * status, uint32 ne, uint32 * EQ)
+// ----------------------------------------------------------------------------
 {
     uint32 e;
@@ -999,7 +836,9 @@
     return na;
 }
-// ----------------------------------------------------------------------------
-void RegionStats_UpdateStats_with_EQ(uint32 *EQ, uint32 ne, RegionStats *Stats)
-// ----------------------------------------------------------------------------
+
+
+// ------------------------------------------------------------------------------
+void RegionStats_UpdateStats_with_EQ(uint32 * EQ, uint32 ne, RegionStats * Stats)
+// ------------------------------------------------------------------------------
 {
     uint32 e, a;
@@ -1015,21 +854,18 @@
     }
 }
-// ---------------------------------------------------------------------------
-void featuresComputation(uint32 **E, int height,int width, RegionStats *Stats)
-// ---------------------------------------------------------------------------
+
+
+// -----------------------------------------------------------------------------
+void featuresComputation(uint32 ** E, int height,int width, RegionStats * Stats)
+// -----------------------------------------------------------------------------
 {
     //uint32 nemax = height * width /2;   
     RegionStats_Calc_Rectangle_Moment1(E, height, width, Stats);    
 }
-// ------------------------------------------------------------------------------
-void pointFeaturesComputation_Dummy(uint32 **E, int i, int j, RegionStats *Stats)
-// ------------------------------------------------------------------------------
-{
-    // pour pointeur de fonction
-    return;
-}
-// -------------------------------------------------------------------------
-void pointFeaturesComputation( uint32 **E, int i, int j, RegionStats *Stats)
-// -------------------------------------------------------------------------
+
+
+// ---------------------------------------------------------------------------
+void pointFeaturesComputation( uint32 ** E, int i, int j, RegionStats * Stats)
+// ---------------------------------------------------------------------------
 {
     uint32 x, y;
@@ -1042,9 +878,17 @@
         y = i;
         
-        if (i<Stats[e].ymin) Stats[e].ymin = y;
-        if (i>Stats[e].ymax) Stats[e].ymax = y;
-        
-        if (j<Stats[e].xmin) Stats[e].xmin = x;
-        if (j>Stats[e].xmax) Stats[e].xmax = x;
+        if (i < Stats[e].ymin) {
+            Stats[e].ymin = y;
+        }
+        if (i > Stats[e].ymax) {
+            Stats[e].ymax = y;
+        }
+        
+        if (j < Stats[e].xmin) {
+            Stats[e].xmin = x;
+        }
+        if (j > Stats[e].xmax) {
+            Stats[e].xmax = x;
+        }
         
         Stats[e].S  += 1;
@@ -1053,22 +897,16 @@
     }
 }
-// ----------------------------------------------------------------------------------
-void lineFeaturesComputation_Dummy( uint32 **E, int i, int width, RegionStats *Stats)
-// ----------------------------------------------------------------------------------
-{
-    // pour pointeur de fonction
-    return;
-}
-// ----------------------------------------------------------------------------
-void lineFeaturesComputation( uint32 **E, int i, int width, RegionStats *Stats)
-// ----------------------------------------------------------------------------
+
+
+// -----------------------------------------------------------------------------
+void lineFeaturesComputation(uint32 ** E, int i, int width, RegionStats * Stats)
+// -----------------------------------------------------------------------------
 {
     // line RegionStats_Calc_Rectangle_Moment1
-    int j;
     
     uint32 x, y;
     uint32 e;
     
-    for (j = 0; j < width; j++) {
+    for (int j = 0; j < width; j++) {
         
         e = E[i][j];
@@ -1078,9 +916,17 @@
             y = i;
             
-            if (i<Stats[e].ymin) Stats[e].ymin = y;
-            if (i>Stats[e].ymax) Stats[e].ymax = y;
+            if (i < Stats[e].ymin) {
+                Stats[e].ymin = y;
+            }
+            if (i > Stats[e].ymax) {
+                Stats[e].ymax = y;
+            }
             
-            if (j<Stats[e].xmin) Stats[e].xmin = x;
-            if (j>Stats[e].xmax) Stats[e].xmax = x;
+            if (j < Stats[e].xmin) {
+                Stats[e].xmin = x;
+            }
+            if (j > Stats[e].xmax) {
+                Stats[e].xmax = x;
+            }
             
             Stats[e].S  += 1;
@@ -1090,50 +936,43 @@
     }
 }
-// ------------------------------------------------------------------------------------------
-void bandFeaturesComputation_Dummy(uint32 **E, int i0, int i1, int width, RegionStats *Stats)
-// ------------------------------------------------------------------------------------------
-{
-    return;
-}
-// ------------------------------------------------------------------------------------
-void bandFeaturesComputation(uint32 **E, int i0, int i1, int width, RegionStats *Stats)
-// ------------------------------------------------------------------------------------
-{
-    int i;
-    for (i = i0; i <= i1; i++) {
+
+
+// --------------------------------------------------------------------------------------
+void bandFeaturesComputation(uint32 ** E, int i0, int i1, int width, RegionStats * Stats)
+// --------------------------------------------------------------------------------------
+{
+    for (int i = i0; i <= i1; i++) {
         lineFeaturesComputation(E, i, width, Stats);
     }
 }
-// ---------------------------------------------------------------------------------------
-void imageFeaturesComputation_Dummy(uint32 **E, int height, int width, RegionStats *Stats)
-// ---------------------------------------------------------------------------------------
-{
-    // pour pointeur de fonction
-    return;
-}
-// ---------------------------------------------------------------------------------
-void imageFeaturesComputation(uint32 **E, int height, int width, RegionStats *Stats)
-// ---------------------------------------------------------------------------------
+
+
+// -----------------------------------------------------------------------------------
+void imageFeaturesComputation(uint32 ** E, int height, int width, RegionStats * Stats)
+// -----------------------------------------------------------------------------------
 {
     // image RegionStats_Calc_Rectangle_Moment1
-    int i;
-    for (i = 0; i < height; i++) {
+    for (int i = 0; i < height; i++) {
         lineFeaturesComputation(E, i, width, Stats);
     }
 }
+
+
 // ---------------------------------------
 // --- Fonctions 2014 --------------------
 // ---------------------------------------
 
-// --------------------------------------------------------------------------------------
-void RegionStats_Copy_Stats1_From_Index(RegionStats *Stats, int dst_index, int src_index)
-// --------------------------------------------------------------------------------------                                 
+// ---------------------------------------------------------------------------------------
+void RegionStats_Copy_Stats1_From_Index(RegionStats * Stats, int dst_index, int src_index)
+// ---------------------------------------------------------------------------------------                                 
 {
     // R[dst] = R[src]
     RegionStats_Copy1(&Stats[src_index], &Stats[dst_index]);
 }
-// --------------------------------------------------------------------------------------------
-void RegionStats_Accumulate_Stats1_From_Index(RegionStats *Stats, int dst_index, int src_index)
-// --------------------------------------------------------------------------------------------                                 
+
+
+// ---------------------------------------------------------------------------------------------
+void RegionStats_Accumulate_Stats1_From_Index(RegionStats * Stats, int dst_index, int src_index)
+// ---------------------------------------------------------------------------------------------                                 
 {
     // R[dst] += R[src]
@@ -1147,7 +986,9 @@
     Stats[dst_index].Sy += Stats[src_index].Sy;   
 }
-// -----------------------------------------------------------------------------------------------------
-void RegionStats_DisplayStats_Sparse(uint32 *EQ, uint32 ne0, uint32 ne1, RegionStats *Stats, char *name)
-// -----------------------------------------------------------------------------------------------------
+
+
+// ---------------------------------------------------------------------------------------------------------------------------
+void RegionStats_DisplayStats_Sparse(uint32 * EQ, uint32 ne0, uint32 ne1, RegionStats * Stats, char * name, int * start_index)
+// ---------------------------------------------------------------------------------------------------------------------------
 {
     // n'affiche que les racines.
@@ -1156,19 +997,29 @@
     uint32 na; // compteur
     
-    if (name) printf(name);
-    
-    na = RegionStats_Count_Roots_Sparse(Stats, EQ, ne0, ne1);
-    printf("%d\n", na);
+    if (name) {
+        printf(name);
+    }
+    
+    //na = RegionStats_Count_Roots_Sparse(Stats, EQ, ne0, ne1);
+    //printf("%d\n", na);
     
     for (e = ne0; e <= ne1; e++) {
-        if ((e == EQ[e]) && (Stats[e].S > 0)) {
-            printf("%5d ", e);
+        if (e == EQ[e] && Stats[e].S > 0) {
+            if (start_index != NULL) {
+                printf("%5d ", *start_index);
+                *start_index = *start_index + 1;
+            }
+            else {
+                printf("%5d ", e);
+            }
             display_RegionStats(&Stats[e], NULL);
         }
     }
 }
-// ----------------------------------------------------------------------------------------------------
-void RegionStats_DisplayStats_Range(uint32 *EQ, uint32 ne0, uint32 ne1, RegionStats *Stats, char *name)
-// ----------------------------------------------------------------------------------------------------
+
+
+// -------------------------------------------------------------------------------------------------------
+void RegionStats_DisplayStats_Range(uint32 * EQ, uint32 ne0, uint32 ne1, RegionStats * Stats, char * name)
+// -------------------------------------------------------------------------------------------------------
 {
     // affichage dense (apres un pack)
@@ -1176,5 +1027,7 @@
     uint32 e;
     
-    if (name) printf(name);
+    if (name) {
+        printf(name);
+    }
     
     for (e = ne0; e <= ne1; e++) {
@@ -1183,7 +1036,9 @@
     }
 }
-// --------------------------------------------------------------------------------------------------------
-void RegionStats_Save_Stats1_Sparse(RegionStats *Stats, uint32 *EQ, uint32 ne0, uint32 ne1, char *filename)
-// --------------------------------------------------------------------------------------------------------
+
+
+// -----------------------------------------------------------------------------------------------------------
+void RegionStats_Save_Stats1_Sparse(RegionStats * Stats, uint32 * EQ, uint32 ne0, uint32 ne1, char * filename)
+// -----------------------------------------------------------------------------------------------------------
 {
     int fd;
@@ -1197,7 +1052,9 @@
     RegionStats_Close_File(fd);
 }
-// ------------------------------------------------------------------------------------------
-uint32 RegionStats_Count_Roots_Sparse(RegionStats *Stats, uint32 *EQ, uint32 ne0, uint32 ne1)
-// ------------------------------------------------------------------------------------------
+
+
+// --------------------------------------------------------------------------------------------
+uint32 RegionStats_Count_Roots_Sparse(RegionStats * Stats, uint32 * EQ, uint32 ne0, uint32 ne1)
+// --------------------------------------------------------------------------------------------
 {
     uint32 e, c = 0; // compteur
@@ -1210,13 +1067,17 @@
     return c;
 }
-// ---------------------------------------------------------------------------------
-uint32 RegionStats_Count_Roots_Sparse1(RegionStats *Stats, uint32 *EQ, uint32 nemax)
-// ---------------------------------------------------------------------------------
+
+
+// -----------------------------------------------------------------------------------
+uint32 RegionStats_Count_Roots_Sparse1(RegionStats * Stats, uint32 * EQ, uint32 nemax)
+// -----------------------------------------------------------------------------------
 {
     return RegionStats_Count_Roots_Sparse(Stats, EQ, 1, nemax);
 }
-// -------------------------------------------------------------------------------------------
-uint32 RegionStats_Count_Labels_Sparse(RegionStats *Stats, uint32 *EQ, uint32 ne0, uint32 ne1)
-// -------------------------------------------------------------------------------------------
+
+
+// ---------------------------------------------------------------------------------------------
+uint32 RegionStats_Count_Labels_Sparse(RegionStats * Stats, uint32 * EQ, uint32 ne0, uint32 ne1)
+// ---------------------------------------------------------------------------------------------
 {
     uint32 e, c = 0; // compteur
@@ -1229,16 +1090,19 @@
     return c;
 }
-// ----------------------------*-----------------------------------------------------
-uint32 RegionStats_Count_Labels_Sparse1(RegionStats *Stats, uint32 *EQ, uint32 nemax)
-// ---------------------------*------------------------------------------------------
+
+
+// ------------------------------------------------------------------------------------
+uint32 RegionStats_Count_Labels_Sparse1(RegionStats * Stats, uint32 * EQ, uint32 nemax)
+// ------------------------------------------------------------------------------------
 {
     return RegionStats_Count_Labels_Sparse(Stats, EQ, 1, nemax);
 }
-// ---------------------------------------------------------------------
-void copy_features_ui32matrix(RegionStats *Stats, uint32 ne, uint32 **m)
-// ---------------------------------------------------------------------
-{
-    int i;
-    for (i = 0; i <= (int) ne; i++) {
+
+
+// -----------------------------------------------------------------------
+void copy_features_ui32matrix(RegionStats * Stats, uint32 ne, uint32 ** m)
+// -----------------------------------------------------------------------
+{
+    for (int i = 0; i <= (int) ne; i++) {
         
         m[i][0] = i;
@@ -1260,10 +1124,11 @@
     }
 }
-// ---------------------------------------------------------------------
-void copy_ui32matrix_features(uint32 **m, uint32 ne, RegionStats *Stats)
-// ---------------------------------------------------------------------
-{
-    int i;
-    for (i = 0; i <= (int) ne; i++) {
+
+
+// -----------------------------------------------------------------------
+void copy_ui32matrix_features(uint32 ** m, uint32 ne, RegionStats * Stats)
+// -----------------------------------------------------------------------
+{
+    for (int i = 0; i <= (int) ne; i++) {
         
         Stats[i].xmin = m[i][2] >> 16;
@@ -1277,7 +1142,9 @@
     }
 }
-// ---------------------------------------------------------------------------
-void sortv_ui32matrix_col(uint32 **m, int i0, int i1, int j0, int j1, int col)
-// ---------------------------------------------------------------------------
+
+
+// ----------------------------------------------------------------------------
+void sortv_ui32matrix_col(uint32 ** m, int i0, int i1, int j0, int j1, int col)
+// ----------------------------------------------------------------------------
 {
     // nrsort2 for NRC2
@@ -1294,13 +1161,12 @@
      * instead of copying the lines.
      */
-	int i, j;
 	
     uint32 x, min, pos;
 	uint32 * ptr;
 	
-	for (i = nrl; i < nrh; i++) {
+	for (int i = nrl; i < nrh; i++) {
 		min = m[i][nc];
 		pos = i;
-		for (j = i + 1; j <= nrh; j++) {
+		for (int j = i + 1; j <= nrh; j++) {
 			x = m[j][nc];
 			if (x < min) {
@@ -1314,11 +1180,11 @@
 		m[i]   = m[pos];
 		m[pos] = ptr;
-		
 	} // i
-    
-}
-// ------------------------------------------------------------
-void RegionStats_SortFeatures(RegionStats *Stats, uint32 nemax)
-// ------------------------------------------------------------
+}
+
+
+// -------------------------------------------------------------
+void RegionStats_SortFeatures(RegionStats * Stats, uint32 nemax)
+// -------------------------------------------------------------
 {
     uint32 ** m = NULL;
@@ -1330,284 +1196,34 @@
     copy_ui32matrix_features(m, nemax, Stats);
 }
-// --------------------------------------------------------------------------------------
-void imageFeaturesComputation_omp0(uint32 **E, int height, int width, RegionStats *Stats)
-// --------------------------------------------------------------------------------------
-{
-    // version OpenMP 2.0 fausse (sans serialisation de la section critique)
-    // pour evaluer l'impact de la synchro
-    int i, j;
-    
-    uint32 x, y;
-    uint32 e;
-    
-#ifdef OPENMP
-#pragma omp parallel for private(height, width, i, j, x, y, e) shared (E, Stats)
-#endif
-    for (i = 0; i < height; i++) {
-        for (j = 0; j < width; j++) {
-            
-            e = E[i][j];
-            if (e) {
-                
-                x = j;
-                y = i;
-                
-                // min max reduction
-                if (y < Stats[e].ymin) Stats[e].ymin = y;
-                if (y > Stats[e].ymax) Stats[e].ymax = y;
-                
-                if (x < Stats[e].xmin) Stats[e].xmin = x;
-                if (x > Stats[e].xmax) Stats[e].xmax = x;
-                
-                // + reduction
-                Stats[e].S  += 1;
-                Stats[e].Sx += x;
-                Stats[e].Sy += y;
-            }
-        }
-    }
-}
-// --------------------------------------------------------------------------------------
-void imageFeaturesComputation_omp2(uint32** E, int height, int width, RegionStats* Stats)
-// --------------------------------------------------------------------------------------
-{
-    // version OpenMP 2.0 classique avec "critical"
-    
-    int i, j;
-    
-    uint32 x, y;
-    uint32 e;
-    
-    
-    #ifdef OPENMP
-    //#pragma omp parallel for private(height, width, i, j, x, y, e) shared(E, Stats)
-    #pragma omp parallel for shared(E, Stats) private(height, width, i, j, x, y, e) schedule(dynamic)
-    //#pragma omp for private (j)
-    #endif    
-    for (i = 0; i < height; i++) {
-        //printf("i = %d\n", i);
-        //printf("omp_get_num_threads = %d\n", omp_get_num_threads());
-        
-        for (j = 0; j < width; j++) {
-            
-            e = E[i][j];
-            if (e) {
-                
-                x = j;
-                y = i;
-                
-                #ifdef OPENMP
-                #pragma omp critical
-                #endif
-                {
-                    // min max reduction
-                    if (y < Stats[e].ymin) Stats[e].ymin = y;
-                    if (y > Stats[e].ymax) Stats[e].ymax = y;
-                    
-                    if (x < Stats[e].xmin) Stats[e].xmin = x;
-                    if (x > Stats[e].xmax) Stats[e].xmax = x;
-                    
-                    // + reduction
-                    Stats[e].S  += 1;
-                    Stats[e].Sx += x;
-                    Stats[e].Sy += y;
-                } // omp critical
-            } // if e
-        } // j
-    } // i
-}
-// --------------------------------------------------------------------------------------
-void imageFeaturesComputation_omp3(uint32** E, int height, int width, RegionStats* Stats)
-// --------------------------------------------------------------------------------------
-{
-    // version OpenMP 2.0 classique avec "critical" (from Laurent Cabaret with optimal use of critical and atomic)
-
-  int i, j;
-    
-    uint32 x, y;
-    uint32 e;
-
-
-    #ifdef OPENMP
-    //#pragma omp parallel for private(height, width, i, j, x, y, e) shared(E, Stats)
-    #pragma omp parallel for shared(E, Stats) private(height, width, i, j, x, y, e) schedule(dynamic)
-    #endif    
-    for (i = 0; i < height; i++) {
-
-        for (j = 0; j < width; j++) {
-            
-            e = E[i][j];
-            if (e) {
-                
-                x = j;
-                y = i;
-                
-                #ifdef OPENMP
-                #pragma omp critical
-                #endif
-                {
-                    // min max reduction
-                    if (y < Stats[e].ymin) Stats[e].ymin = y;
-                    if (y > Stats[e].ymax) Stats[e].ymax = y;
-                }
-                #ifdef OPENMP
-                #pragma omp critical
-                #endif
-                {
-                    if (x < Stats[e].xmin) Stats[e].xmin = x;
-                    if (x > Stats[e].xmax) Stats[e].xmax = x;
-                }
-                // + reduction
-                #ifdef OPENMP
-                #pragma omp atomic
-                #endif
-                Stats[e].S += 1;
-                
-                #ifdef OPENMP
-                #pragma omp atomic
-                #endif
-                Stats[e].Sx += x;
-                
-                #ifdef OPENMP
-                #pragma omp atomic
-                Stats[e].Sy += y;
-                #endif
-            } // if e
-        } // j
-    } // i
-}
-// --------------------------------------------------------------------------------------------
-void imageFeaturesComputation_range_omp2(uint32** E, int height, int width, RegionStats* Stats)
-// --------------------------------------------------------------------------------------------
-{
-    // version OpenMP 2.0
-    
-    int i, j;
-    
-    uint32 x, y;
-    uint32 e;
-    
-    
-#ifdef OPENMP
-    //#pragma omp parallel for private(height, width, i, j, x, y, e) shared(E, Stats)
-#pragma omp parallel for shared(E, Stats) private(height, width, i, j, x, y, e) schedule(dynamic)
-//#pragma omp for private (j)
-#endif    
-    for (i = 0; i < height; i++) {
-        //printf("i = %d\n", i);
-        //printf("omp_get_num_threads = %d\n", omp_get_num_threads());
-        
-        for (j = 0; j < width; j++) {
-            
-            e = E[i][j];
-            if (e) {
-                
-                x = j;
-                y = i;
-                
-#ifdef OPENMP
-#pragma omp critical
-#endif
-                {
-                    // min max reduction
-                    if (y < Stats[e].ymin)  Stats[e].ymin = y;
-                    if (y > Stats[e].ymax)  Stats[e].ymax = y;
-                    
-                    if (x < Stats[e].xmin)  Stats[e].xmin = x;
-                    if (x > Stats[e].xmax)  Stats[e].xmax = x;
-                    
-                    // + reduction
-                    Stats[e].S  += 1;
-                    Stats[e].Sx += x;
-                    Stats[e].Sy += y;
-                } // omp critical
-            } // if e
-        } // j
-    } // i
-}
-// --------------------------------------------------------------------------------------------------------
-void imageFeaturesComputation_omp4(uint32** restrict E, int height, int width, RegionStats* restrict Stats)
-// --------------------------------------------------------------------------------------------------------
-{
-    // version avec "task" (OpenMP 3.0) et "depend" (OpenMP 4.0)
-#ifdef OPENMP
-#pragma omp parallel private(height,width) shared(E,Stats)
-    {
-#endif // OPENMP
-        int i, j;
-        
-        uint32 x, y;
-        uint32 e;
-        
-#ifdef OPENMP4
-        //#pragma omp task depend ( in:E[0:height-1][0:width-1]) depend( inout: E[1:height*width/4])
-#pragma omp task depend( inout: E[1:height*width/4])    
-#endif
-        for (i = 0; i < height; i++) {
-            for (j = 0; j < width; j++) {
-                
-                e = E[i][j];
-                if (e) {
-                    
-                    x = j;
-                    y = i;
-                    
-                    
-                    // min max reduction
-                    if (y < Stats[e].ymin)  Stats[e].ymin = y;
-                    if (y > Stats[e].ymax)  Stats[e].ymax = y;
-                    
-                    if (x < Stats[e].xmin)  Stats[e].xmin = x;
-                    if (x > Stats[e].xmax)  Stats[e].xmax = x;
-                    
-                    // + reduction
-                    Stats[e].S  += 1;
-                    Stats[e].Sx += x;
-                    Stats[e].Sy += y;
-                }
-            }
-        }
-#ifdef OPENMP
-    }
-#endif // OPENMP
-}
-// ------------------------------------------------------------------------------
-void calc_xmin(uint32** restrict E, int height, int width, uint16* restrict Xmin)
-// ------------------------------------------------------------------------------
-{
-    int i, j;
+
+
+// --------------------------------------------------------------------------------
+void calc_xmin(uint32 ** restrict E, int height, int width, uint16 * restrict Xmin)
+// --------------------------------------------------------------------------------
+{
     uint32 x;
     uint32 e;
-/*    
-#ifdef OPENMP
-#pragma omp critical 
-#endif
-    { printf("calc xmin %d x %d\n", width, height); }
-*/
-    for (i = 0; i < height; i++) {
-        for (j = 0; j < width; j++) {
+    for (int i = 0; i < height; i++) {
+        for (int j = 0; j < width; j++) {
             e = E[i][j];
             if (e) {
                 x = j;
-                if (x < Xmin[e]) Xmin[e] = x;
-            }
-        }
-    }
-}
-// ------------------------------------------------------------------------------
-void calc_xmax(uint32** restrict E, int height, int width, uint16* restrict Xmax)
-// ------------------------------------------------------------------------------
-{
-    int i, j;
+                if (x < Xmin[e]) {
+                    Xmin[e] = x;
+                }
+            }
+        }
+    }
+}
+
+
+// --------------------------------------------------------------------------------
+void calc_xmax(uint32 ** restrict E, int height, int width, uint16 * restrict Xmax)
+// --------------------------------------------------------------------------------
+{
     uint32 x;
     uint32 e;
-/*    
-#ifdef OPENMP
-#pragma omp critical 
-#endif
-    { printf("calc xmax %d x %d\n", width, height); }
- */
-    for (i = 0; i < height; i++) {
-        for (j = 0; j < width; j++) {
+    for (int i = 0; i < height; i++) {
+        for (int j = 0; j < width; j++) {
             e = E[i][j];
             if (e) {
@@ -1618,66 +1234,55 @@
     }
 }
-// ------------------------------------------------------------------------------
-void calc_ymin(uint32** restrict E, int height, int width, uint16* restrict Ymin)
-// ------------------------------------------------------------------------------
-{
-    int i, j;
+
+
+// --------------------------------------------------------------------------------
+void calc_ymin(uint32 ** restrict E, int height, int width, uint16 * restrict Ymin)
+// --------------------------------------------------------------------------------
+{
     uint32 y;
     uint32 e;
-/*    
-#ifdef OPENMP
-#pragma omp critical 
-#endif
-    { printf("calc ymin %d x %d\n", width, height); }
-*/
-    for(i=0; i<height; i++) {
-        for(j=0; j<width; j++) {
+    for (int i = 0; i < height; i++) {
+        for (int j = 0; j < width; j++) {
             e = E[i][j];
-            if(e) {
+            if (e) {
                 y = i;
-                if(y < Ymin[e]) Ymin[e] = y;
-            }
-        }
-    }
-}
-// ------------------------------------------------------------------------------
-void calc_ymax(uint32** restrict E, int height, int width, uint16* restrict Ymax)
-// ------------------------------------------------------------------------------
-{
-    int i, j;
+                if (y < Ymin[e]) {
+                    Ymin[e] = y;
+                }
+            }
+        }
+    }
+}
+
+
+// --------------------------------------------------------------------------------
+void calc_ymax(uint32 ** restrict E, int height, int width, uint16 * restrict Ymax)
+// --------------------------------------------------------------------------------
+{
     uint32 y;
     uint32 e;
-/*
-#ifdef OPENMP
-#pragma omp critical 
-#endif
-    { printf("calc ymax %d x %d\n", width, height); }
-*/
-    for(i=0; i<height; i++) {
-        for(j=0; j<width; j++) {
+    for (int i = 0; i < height; i++) {
+        for (int j = 0; j < width; j++) {
             e = E[i][j];
-            if(e) {
+            if (e) {
                 y = i;
-                if(y > Ymax[e]) Ymax[e] = y;
-            }
-        }
-    }
-}
-// ------------------------------------------------------------------------
-void calc_s(uint32** restrict E, int height, int width, uint32* restrict S)
-// ------------------------------------------------------------------------
-{
-    int i, j;
+                if (y > Ymax[e]) {
+                    Ymax[e] = y;
+                }
+            }
+        }
+    }
+}
+
+
+// --------------------------------------------------------------------------
+void calc_s(uint32 ** restrict E, int height, int width, uint32 * restrict S)
+// --------------------------------------------------------------------------
+{
     uint32 e;
-/*    
-#ifdef OPENMP
-#pragma omp critical 
-#endif  
-    { printf("calc s %d x %d\n", width, height); }
-*/
-    for(i=0; i<height; i++) {
-        for(j=0; j<width; j++) {
+    for (int i = 0; i < height; i++) {
+        for (int j = 0; j < width; j++) {
             e = E[i][j];
-            if(e) {
+            if (e) {
                 S[e] += 1;
             }
@@ -1685,20 +1290,15 @@
     }
 }
-// --------------------------------------------------------------------------
-void calc_sx(uint32** restrict E, int height, int width, uint32* restrict Sx)
-// --------------------------------------------------------------------------
-{
-    int i, j;
+
+
+// ----------------------------------------------------------------------------
+void calc_sx(uint32 ** restrict E, int height, int width, uint32 * restrict Sx)
+// ----------------------------------------------------------------------------
+{
     uint32 e;
-/*    
-#ifdef OPENMP
-#pragma omp critical 
-#endif  
-    { printf("calc sx %d x %d\n", width, height); }
-*/
-    for(i=0; i<height; i++) {
-        for(j=0; j<width; j++) {
+    for (int i = 0; i < height; i++) {
+        for (int j = 0; j < width; j++) {
             e = E[i][j];
-            if(e) {
+            if (e) {
                 Sx[e] += j;
             }
@@ -1706,18 +1306,13 @@
     }
 }
-// --------------------------------------------------------------------------
-void calc_sy(uint32** restrict E, int height, int width, uint32* restrict Sy)
-// --------------------------------------------------------------------------
-{
-    int i, j;
+
+
+// ----------------------------------------------------------------------------
+void calc_sy(uint32 ** restrict E, int height, int width, uint32 * restrict Sy)
+// ----------------------------------------------------------------------------
+{
     uint32 e;
-/*
-#ifdef OPENMP
-#pragma omp critical 
-#endif
-    { printf("calc sy %d x %d\n", width, height); }
- */
-    for (i = 0; i < height; i++) {
-        for (j = 0; j < width; j++) {
+    for (int i = 0; i < height; i++) {
+        for (int j = 0; j < width; j++) {
             e = E[i][j];
             if (e) {
@@ -1727,88 +1322,54 @@
     }
 }
-// ---------------------------------------------------------------------------------------------------------------------------------------------------------------
-void imageFeaturesComputation_omp5(uint32** E, int height, int width, uint16* Xmin, uint16* Xmax, uint16* Ymin, uint16* Ymax, uint32* S, uint32* Sx, uint32* Sy)
-// ---------------------------------------------------------------------------------------------------------------------------------------------------------------
-{
-    // version avec "task" (OpenMP 3.0) et "depend" (OpenMP 4.0)
-#ifdef OPENMP
-#pragma omp parallel shared(E,Xmin,Xmax,Ymin,Ymax,S,Sx,Sy)
-    // ne sourtout pas mettre height et width en private
-    {
-#endif // OPENMP
-
-        int id; // thread number
-        
-#ifdef OPENMP
-        id = omp_get_thread_num();
-#else
-        id = 1;
-#endif
-        
-        //printf("thread id = %d h = %d w = %d\n", id, height, width);
-        
-        if (id == 0) { calc_xmin(E, height, width, Xmin); }
-        if (id == 1) { calc_xmax(E, height, width, Xmax); }
-        if (id == 2) { calc_ymin(E, height, width, Ymin); }
-        if (id == 3) { calc_ymax(E, height, width, Ymax); }
-        
-        if (id == 4) { calc_s (E, height, width, S);  }
-        if (id == 5) { calc_sx(E, height, width, Sx); }
-        if (id == 6) { calc_sy(E, height, width, Sy); }
-#ifdef OPENMP
-    }
-#endif // OPENMP
-}
-// ------------------------------------------------------
-int RegionStats_Compare(RegionStats *S1, RegionStats *S2)
-// ------------------------------------------------------
+
+
+// --------------------------------------------------------
+int RegionStats_Compare(RegionStats * S1, RegionStats * S2)
+// --------------------------------------------------------
 {
     //puts("----------------------------------------");
     //display_RegionStats(S1, "S1");
     //display_RegionStats(S2, "S2");
-    if((S1->xmin == S2->xmin) &&
+    if ((S1->xmin == S2->xmin) &&
        (S1->xmax == S2->xmax) &&
        (S1->ymin == S2->ymin) &&
        (S1->ymax == S2->ymax) &&
-       (S1->S    == S2->S   ) &&
-       (S1->Sx   == S2->Sx  ) &&
-       (S1->Sy   == S2->Sy  ))
+       (S1->S  == S2->S) &&
+       (S1->Sx == S2->Sx) &&
+       (S1->Sy == S2->Sy)) {
         return 1;
-    else 
+    }
+    else {
         return 0;
-}
-// ----------------------------------------------------------------------------
-int RegionStatsVector_Compare(RegionStats *S1, int i0, int i1, RegionStats *S2)
-// ----------------------------------------------------------------------------
-{
-    int i;
+    }
+}
+
+
+// ------------------------------------------------------------------------------
+int RegionStatsVector_Compare(RegionStats * S1, int i0, int i1, RegionStats * S2)
+// ------------------------------------------------------------------------------
+{
     int c; // resultat de la comparaison 0 = identique, 1 = different
     int s = 0; // somme
     
-    for(i=i0; i<=i1; i++) {
+    for (int i = i0; i <= i1; i++) {
         c = RegionStats_Compare(&S1[i], &S2[i]);
         s += c;
-        
-        /*if(c) {
-            puts("---------------------------------------------------");
-            printf("e = %d\n", i);
-            display_RegionStats(&S1[i], NULL);
-            display_RegionStats(&S2[i], NULL);
-        }*/
-            
     }
     return s;
 }
-// ------------------------------------------------------------------------------------------
-int RegionStatsVector_Match(RegionStats *S1, int i0, int i1, RegionStats *S2, int j0, int j1)
-// ------------------------------------------------------------------------------------------
-{
-    int i, j, pos;
+
+
+// --------------------------------------------------------------------------------------------
+int RegionStatsVector_Match(RegionStats * S1, int i0, int i1, RegionStats * S2, int j0, int j1)
+// --------------------------------------------------------------------------------------------
+{
+    int j, pos;
     int c; // resultat de la comparaison 1 = identique, 0 = different
     int a; // accumulateur de c
     int s = 0; // somme
     int perm = 0; // permutation de numero de features
-    int n1 = i1-i0+1;
-    int n2 = j1-j0+1;
+    int n1 = i1 - i0 + 1;
+    int n2 = j1 - j0 + 1;
     
     //printf("[RegionStatsVector_Match]: [%d..%d]=%d vs [%d..%d]=%d\n", i0, i1, n1, j0,j1,n2);
@@ -1818,5 +1379,5 @@
     }
     
-    for (i = i0; i <= i1; i++) {
+    for (int i = i0; i <= i1; i++) {
         a   =  0;
         pos = -1;
@@ -1825,5 +1386,7 @@
             c = RegionStats_Compare(&S1[i], &S2[j]);
             a = a + c;
-            if (c) pos = j;
+            if (c) {
+                pos = j;
+            }
         }
         s += a;
@@ -1833,8 +1396,10 @@
             for (j = j0; j <= j1; j++) {
                 c = RegionStats_Compare(&S1[i], &S2[j]);
-                if (c) printf("S2[%d] ", j);
-            }
-            printf("");
-            giet_pthread_exit("");
+                if (c) {
+                    printf("S2[%d] ", j);
+                }
+            }
+            printf("\n");
+            exit(1);
         }
         
@@ -1855,2 +1420,12 @@
     return n1 - s;
 }
+
+// Local Variables:
+// tab-width: 4
+// c-basic-offset: 4
+// c-file-offsets:((innamespace . 0)(inline-open . 0))
+// indent-tabs-mode: nil
+// End:
+
+// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4
+
Index: soft/giet_vm/applications/rosenfeld/src/mt19937.c
===================================================================
--- soft/giet_vm/applications/rosenfeld/src/mt19937.c	(revision 820)
+++ soft/giet_vm/applications/rosenfeld/src/mt19937.c	(revision 821)
@@ -54,5 +54,5 @@
 
 static unsigned long mt[N]; /* the array for the state vector  */
-static int mti=N+1; /* mti==N+1 means mt[N] is not initialized */
+static int mti = N + 1 ;    /* mti==N+1 means mt[N] is not initialized */
 
 static int global_seed;
@@ -61,9 +61,8 @@
 void init_genrand(unsigned long s)
 {
-    mt[0]= s & 0xffffffffUL;
+    mt[0] = s & 0xffffffffUL;
     global_seed = s; // modif LL
-    for (mti=1; mti<N; mti++) {
-        mt[mti] = 
-            (1812433253UL * (mt[mti-1] ^ (mt[mti-1] >> 30)) + mti); 
+    for (mti = 1; mti < N; mti++) {
+        mt[mti] = (1812433253UL * (mt[mti - 1] ^ (mt[mti - 1] >> 30)) + mti); 
         /* See Knuth TAOCP Vol2. 3rd Ed. P.106 for multiplier. */
         /* In the previous versions, MSBs of the seed affect   */
@@ -84,20 +83,28 @@
     //init_genrand(19650218UL);
     init_genrand(global_seed);
-    i=1; j=0;
-    k = (N>key_length ? N : key_length);
+    i = 1;
+    j = 0;
+    k = (N > key_length ? N : key_length);
     for (; k; k--) {
-        mt[i] = (mt[i] ^ ((mt[i-1] ^ (mt[i-1] >> 30)) * 1664525UL))
-            + init_key[j] + j; /* non linear */
-        mt[i] &= 0xffffffffUL; /* for WORDSIZE > 32 machines */
-        i++; j++;
-        if (i>=N) { mt[0] = mt[N-1]; i=1; }
-        if (j>=key_length) j=0;
-    }
-    for (k=N-1; k; k--) {
-        mt[i] = (mt[i] ^ ((mt[i-1] ^ (mt[i-1] >> 30)) * 1566083941UL))
-            - i; /* non linear */
+        mt[i] = (mt[i] ^ ((mt[i - 1] ^ (mt[i - 1] >> 30)) * 1664525UL)) + init_key[j] + j; /* non linear */
         mt[i] &= 0xffffffffUL; /* for WORDSIZE > 32 machines */
         i++;
-        if (i>=N) { mt[0] = mt[N-1]; i=1; }
+        j++;
+        if (i >= N) {
+            mt[0] = mt[N - 1];
+            i = 1;
+        }
+        if (j >= key_length) {
+            j = 0;
+        }
+    }
+    for (k = N - 1; k; k--) {
+        mt[i] = (mt[i] ^ ((mt[i - 1] ^ (mt[i - 1] >> 30)) * 1566083941UL)) - i; /* non linear */
+        mt[i] &= 0xffffffffUL; /* for WORDSIZE > 32 machines */
+        i++;
+        if (i >= N) {
+            mt[0] = mt[N - 1];
+            i = 1;
+        }
     }
 
@@ -109,5 +116,5 @@
 {
     unsigned long y;
-    static unsigned long mag01[2]={0x0UL, MATRIX_A};
+    static unsigned long mag01[2] = {0x0UL, MATRIX_A};
     /* mag01[x] = x * MATRIX_A  for x=0,1 */
 
@@ -115,18 +122,19 @@
         int kk;
 
-        if (mti == N+1)   /* if init_genrand() has not been called, */
+        if (mti == N + 1) {  /* if init_genrand() has not been called, */
             //init_genrand(5489UL); /* a default initial seed is used */
             init_genrand(global_seed);
-
-        for (kk=0;kk<N-M;kk++) {
-            y = (mt[kk]&UPPER_MASK)|(mt[kk+1]&LOWER_MASK);
-            mt[kk] = mt[kk+M] ^ (y >> 1) ^ mag01[y & 0x1UL];
-        }
-        for (;kk<N-1;kk++) {
-            y = (mt[kk]&UPPER_MASK)|(mt[kk+1]&LOWER_MASK);
-            mt[kk] = mt[kk+(M-N)] ^ (y >> 1) ^ mag01[y & 0x1UL];
-        }
-        y = (mt[N-1]&UPPER_MASK)|(mt[0]&LOWER_MASK);
-        mt[N-1] = mt[M-1] ^ (y >> 1) ^ mag01[y & 0x1UL];
+        }
+
+        for (kk = 0;kk < N - M; kk++) {
+            y = (mt[kk] & UPPER_MASK) | (mt[kk + 1] & LOWER_MASK);
+            mt[kk] = mt[kk + M] ^ (y >> 1) ^ mag01[y & 0x1UL];
+        }
+        for (; kk < N - 1; kk++) {
+            y = (mt[kk] & UPPER_MASK) | (mt[kk + 1] & LOWER_MASK);
+            mt[kk] = mt[kk + (M - N)] ^ (y >> 1) ^ mag01[y & 0x1UL];
+        }
+        y = (mt[N - 1] & UPPER_MASK) | (mt[0] & LOWER_MASK);
+        mt[N - 1] = mt[M - 1] ^ (y >> 1) ^ mag01[y & 0x1UL];
 
         mti = 0;
@@ -147,5 +155,5 @@
 long genrand_int31(void)
 {
-    return (long)(genrand_int32()>>1);
+    return (long) (genrand_int32() >> 1);
 }
 
@@ -153,5 +161,5 @@
 double genrand_real1(void)
 {
-    return genrand_int32()*(1.0/4294967295.0); 
+    return genrand_int32() * (1.0 / 4294967295.0); 
     /* divided by 2^32-1 */ 
 }
@@ -160,5 +168,5 @@
 double genrand_real2(void)
 {
-    return genrand_int32()*(1.0/4294967296.0); 
+    return genrand_int32() * (1.0 / 4294967296.0); 
     /* divided by 2^32 */
 }
@@ -167,5 +175,5 @@
 double genrand_real3(void)
 {
-    return (((double)genrand_int32()) + 0.5)*(1.0/4294967296.0); 
+    return (((double) genrand_int32()) + 0.5) * (1.0 / 4294967296.0); 
     /* divided by 2^32 */
 }
@@ -174,6 +182,6 @@
 double genrand_res53(void) 
 { 
-    unsigned long a=genrand_int32()>>5, b=genrand_int32()>>6; 
-    return(a*67108864.0+b)*(1.0/9007199254740992.0); 
+    unsigned long a = genrand_int32() >> 5, b = genrand_int32() >> 6; 
+    return (a * 67108864.0 + b) * (1.0 / 9007199254740992.0); 
 } 
 /* These real versions are due to Isaku Wada, 2002/01/09 added */
@@ -182,16 +190,31 @@
 {
     int i;
-    unsigned long init[4]={0x123, 0x234, 0x345, 0x456}, length=4;
+    unsigned long init[4] = {0x123, 0x234, 0x345, 0x456}, length = 4;
     init_by_array(init, length);
     printf("1000 outputs of genrand_int32()\n");
-    for (i=0; i<1000; i++) {
+    for (i = 0; i < 1000; i++) {
         printf("%10lu ", genrand_int32());
-        if (i%5==4) printf("\n");
+        if (i % 5 == 4) {
+            printf("\n");
+        }
     }
     printf("\n1000 outputs of genrand_real2()\n");
-    for (i=0; i<1000; i++) {
+    for (i = 0; i < 1000; i++) {
         printf("%10.8f ", genrand_real2());
-        if (i%5==4) printf("\n");
+        if (i % 5 == 4) {
+            printf("\n");
+        }
     }
     return 0;
 }
+
+
+// Local Variables:
+// tab-width: 4
+// c-basic-offset: 4
+// c-file-offsets:((innamespace . 0)(inline-open . 0))
+// indent-tabs-mode: nil
+// End:
+
+// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4
+
Index: soft/giet_vm/applications/rosenfeld/src/palette.c
===================================================================
--- soft/giet_vm/applications/rosenfeld/src/palette.c	(revision 820)
+++ soft/giet_vm/applications/rosenfeld/src/palette.c	(revision 821)
@@ -16,18 +16,13 @@
 
 
-#ifdef CLI
 #include "nrc_os_config.h"
 #include "nrc.h"
-#endif
 
 #include "palette.h"
 
-/*
- * Modif : 98-11-18 ajout de Save
- */
-
-/* ---------------------------------------------- */
-IMAGE_EXPORT(void) Palette_Display(RGBQuad *palette)
-    /* ---------------------------------------------- */
+
+/* --------------------------------- */
+void Palette_Display(RGBQuad * palette)
+/* --------------------------------- */
 {
     int i;
@@ -37,59 +32,18 @@
     }
 }
-/* ----------------------------------------------------------- */
-//IMAGE_EXPORT(void) Palette_Save(RGBQuad *palette, char *filename)
-/* ----------------------------------------------------------- */
-/*{
-  int i, j;
-  int k = 32;
-  int hauteur = k, largeur = k*256;
-  uint8  **X;
-  Image *image;
-
-
-  IConstructor(&image, hauteur, largeur, 0);
-  X = (uint8**) Image_Get_Data(image);
-  for(i=0; i<hauteur; i++) {
-  for(j=0; j<largeur; j++) {
-  X[i][j] = j/k;
-  }
-  }
-//SaveBMP(image, palette, filename);
-IDestructor(&image);
-}*/
-/* --------------------------------------------------------------------- */
-//IMAGE_EXPORT(void) Palette_SaveSub(RGBQuad *palette, int n, char *filename)
-/* --------------------------------------------------------------------- */
-/*{
-  int i, j;
-  int hauteur = 8, largeur = 8*n;
-  uint8  **X;
-  Image *image;
-
-
-  IConstructor(&image, largeur, hauteur, 0);
-  X = (uint8**) Image_Get_Data(image);
-  for(i=0; i<hauteur; i++) {
-  for(j=8; j<=largeur; j++) {
-  X[i][j] = j/8;
-  }
-  }
-//SaveBMP(image, palette, filename);
-IDestructor(&image);
-}*/
+
+
 /* --------------------------------------------------- */
 IMAGE_EXPORT(void) Palette_GrayBlue2Red(RGBQuad *palette)
-    /* --------------------------------------------------- */
-    /* ancien SetupPalette */
-{
-    int i;
-
+/* --------------------------------------------------- */
+/* ancien SetupPalette */
+{
     /*
      * Partie basse : image en niveau de gris
      */
-    for(i=0; i<128; i++) {
-        palette[i].blue     = 2*i;
-        palette[i].green    = 2*i;
-        palette[i].red      = 2*i;
+    for (int i = 0; i < 128; i++) {
+        palette[i].blue     = 2 * i;
+        palette[i].green    = 2 * i;
+        palette[i].red      = 2 * i;
         palette[i].reserved = 0;
     }
@@ -98,9 +52,9 @@
      * degrade de bleus puis degrade de rouges
      */
-    for(i=0; i<128; i++) {
-        palette[i+128].blue     = 255 - 2*i;
-        palette[i+128].green    = 0;
-        palette[i+128].red      = 2*i+1;
-        palette[i+128].reserved = 0;
+    for (int i = 0; i < 128; i++) {
+        palette[i + 128].blue     = 255 - 2 * i;
+        palette[i + 128].green    = 0;
+        palette[i + 128].red      = 2 * i + 1;
+        palette[i + 128].reserved = 0;
     }
     palette[128].blue     = 255;
@@ -113,25 +67,12 @@
     palette[255].red      = 255;
     palette[255].reserved = 0;
-
-    /*for(i=0; i<256; i++) {
-      palette[i].rgbBlue     = i;
-      palette[i].rgbGreen    = i;
-      palette[i].rgbRed      = i;
-      palette[i].rgbReserved = 0;
-      }*/
-
-    /*if(verbose) {
-      for(i=0; i<256; i++) {
-      printf("%d %3d %3d %3d\n", i, Palette[i].rgbRed, Palette[i].rgbGreen, Palette[i].rgbBlue);
-      }
-      }*/
-}
-/* ---------------------------------------------- */
-IMAGE_EXPORT(void) Palette_Classic(RGBQuad *palette)
-    /* ---------------------------------------------- */
-{
-    int i;
-
-    for(i=0; i<256; i++) {
+}
+
+
+/* --------------------------------- */
+void Palette_Classic(RGBQuad * palette)
+/* --------------------------------- */
+{
+    for (int i = 0; i < 256; i++) {
         palette[i].blue     = (uint8) i;
         palette[i].green    = (uint8) i;
@@ -140,11 +81,11 @@
     }
 }
-/* ------------------------------------------- */
-IMAGE_EXPORT(void) Palette_Gray(RGBQuad *palette)
-    /* ------------------------------------------- */
-{
-    int i;
-
-    for(i=0; i<256; i++) {
+
+
+/* ------------------------------ */
+void Palette_Gray(RGBQuad * palette)
+/* ------------------------------ */
+{
+    for (int i = 0; i < 256; i++) {
         palette[i].blue     = (uint8) i;
         palette[i].green    = (uint8) i;
@@ -154,13 +95,13 @@
 }
 
-/* ---------------------------------------------- */
-IMAGE_EXPORT(void) Palette_Pseudo1(RGBQuad *palette)
-    /* ---------------------------------------------- */
-{
-    int i;
-    for(i=0; i<255; i++) {
-        palette[i].blue     = (uint8) ((3*i)%256);
-        palette[i].green    = (uint8) ((87*i)%256);
-        palette[i].red      = (uint8) ((117*i)%256);
+
+/* --------------------------------- */
+void Palette_Pseudo1(RGBQuad * palette)
+/* --------------------------------- */
+{
+    for (int i = 0; i < 255; i++) {
+        palette[i].blue     = (uint8) ((3 * i) % 256);
+        palette[i].green    = (uint8) ((87 * i) % 256);
+        palette[i].red      = (uint8) ((117 * i) % 256);
         palette[i].reserved = 0;
     }
@@ -170,13 +111,15 @@
     palette[255].reserved = (uint8) 0;
 }
-/* ---------------------------------------------- */
-IMAGE_EXPORT(void) Palette_Pseudo2(RGBQuad *palette)
-    /* ---------------------------------------------- */
-{
-    int i;
-    for(i=0; i<255; i++) {
-        palette[i].blue     = (uint8) ((     257*i)%256); /* nextprime(256) */
-        palette[i].green    = (uint8) ((   65537*i)%256); /* nextprime(256^2) */
-        palette[i].red      = (uint8) ((16777259*i)%256); /* nextprime(256^3) */
+
+
+/* --------------------------------- */
+void Palette_Pseudo2(RGBQuad * palette)
+/* --------------------------------- */
+{
+    unsigned int i;
+    for (i = 0; i < 255; i++) {
+        palette[i].blue     = (uint8) ((     257 * i) % 256); /* nextprime(256) */
+        palette[i].green    = (uint8) ((   65537 * i) % 256); /* nextprime(256^2) */
+        palette[i].red      = (uint8) ((16777259 * i) % 256); /* nextprime(256^3) */
         palette[i].reserved = 0;
     }
@@ -186,17 +129,19 @@
     palette[255].reserved = (uint8) 0;
 }
-/* ------------------------------------------ */
-IMAGE_EXPORT(void) Palette_Hue(RGBQuad *palette)
-    /* ------------------------------------------ */
+
+
+/* ----------------------------- */
+void Palette_Hue(RGBQuad * palette)
+/* ----------------------------- */
 {
     int i;
     double k, r, g, b; /* alpha rgb */
-    for(i=0; i<255; i++) {
+    for (i = 0; i < 255; i++) {
 
         k = (double) i / 256;
 
         r = 2.0 * k * PI;
-        g = 2.0 * k * PI - (2.0*PI/3.0);
-        b = 2.0 * k * PI  - (4.0*PI/3.0);
+        g = 2.0 * k * PI - (2.0* PI / 3.0);
+        b = 2.0 * k * PI - (4.0* PI / 3.0);
 
         palette[i].blue     = (uint8) (128.0 * (1.0 + cos(b)));
@@ -206,18 +151,20 @@
     }
 }
-/* ------------------------------------------------ */
-IMAGE_EXPORT(void) Palette_RandomHue(RGBQuad *palette)
-    /* ------------------------------------------------ */
+
+
+/* ----------------------------------- */
+void Palette_RandomHue(RGBQuad * palette)
+/* ----------------------------------- */
 {
     int i, ii;
     double k, r, g, b; /* alpha rgb */
-    for(i=0; i<255; i++) {
-
-        ii = (3*i)%256;
+    for (i = 0; i < 255; i++) {
+
+        ii = (3 * i) % 256;
         k = (double) (ii / 256);
 
         r = 2.0 * k * PI;
-        g = 2.0 * k * PI - (2.0*PI/3.0);
-        b = 2.0 * k * PI  - (4.0*PI/3.0);
+        g = 2.0 * k * PI - (2.0 * PI / 3.0);
+        b = 2.0 * k * PI - (4.0 * PI / 3.0);
 
         palette[i].blue     = (uint8) (128.0 * (1.0 + cos(b)));
@@ -227,17 +174,19 @@
     }
 }
-/* -------------------------------------------- */
-IMAGE_EXPORT(void) Palette_HueBW(RGBQuad *palette)
-    /* -------------------------------------------- */
+
+
+/* ------------------------------- */
+void Palette_HueBW(RGBQuad * palette)
+/* ------------------------------- */
 {
     int i;
     double k, r, g, b; /* alpha rgb */
-    for(i=0; i<255; i++) {
+    for (i = 0; i < 255; i++) {
 
         k = (double) i / 256;
 
         r = 2.0 * k * PI;
-        g = 2.0 * k * PI - (2.0*PI/3.0);
-        b = 2.0 * k * PI  - (4.0*PI/3.0);
+        g = 2.0 * k * PI - (2.0 * PI / 3.0);
+        b = 2.0 * k * PI - (4.0 * PI / 3.0);
 
         palette[i].blue     = (uint8) (128.0 * (1.0 + cos(b)));
@@ -256,20 +205,22 @@
     palette[255].reserved = (uint8) 0;
 }
-/* -------------------------------------------------- */
-IMAGE_EXPORT(void) Palette_RandomHueBW(RGBQuad *palette)
-    /* -------------------------------------------------- */
+
+
+/* ------------------------------------- */
+void Palette_RandomHueBW(RGBQuad * palette)
+/* ------------------------------------- */
 {
     int i, ii, im;
     double k, r, g, b; /* alpha rgb */
-    for(i=0; i<255; i++) {
-
-        ii = (7*i)%256;
+    for (i = 0; i < 255; i++) {
+
+        ii = (7 * i) % 256;
         k = (double) ii / 256;
 
         r = 2.0 * k * PI;
-        g = 2.0 * k * PI - (2.0*PI/3.0);
-        b = 2.0 * k * PI  - (4.0*PI/3.0);
-
-        im = (i-27)%255;
+        g = 2.0 * k * PI - (2.0 * PI / 3.0);
+        b = 2.0 * k * PI - (4.0 * PI / 3.0);
+
+        im = (i - 27) % 255;
         im = i;
         palette[im].blue     = (uint8) (128.0 * (1.0 + cos(b)));
@@ -288,10 +239,11 @@
     palette[255].reserved = (uint8) 0;
 }
-/* ------------------------------------------------ */
-IMAGE_EXPORT(void) Palette_3ColorsBW(RGBQuad *palette)
-    /* ------------------------------------------------ */
-{
-    int i;
-    uint8 rr = 255,gg = 255, bb = 255;
+
+
+/* ----------------------------------- */
+void Palette_3ColorsBW(RGBQuad * palette)
+/* ----------------------------------- */
+{
+    uint8 rr = 255, gg = 255, bb = 255;
     RGBQuad pattern[3];
 
@@ -308,9 +260,9 @@
     pattern[2].blue  = bb;
 
-    for(i=0; i<255; i++) {
-        palette[1+i].red      = pattern[i%3].red;
-        palette[1+i].green    = pattern[i%3].green;
-        palette[1+i].blue     = pattern[i%3].blue;
-        palette[1+i].reserved = (uint8) 0;
+    for (int i = 0; i < 255; i++) {
+        palette[1 + i].red      = pattern[i % 3].red;
+        palette[1 + i].green    = pattern[i % 3].green;
+        palette[1 + i].blue     = pattern[i % 3].blue;
+        palette[1 + i].reserved = (uint8) 0;
     }
     palette[0].blue     = (uint8) 0;
@@ -324,10 +276,12 @@
     palette[255].reserved = (uint8) 0;
 }
-/* ---------------------------------------------- */
-IMAGE_EXPORT(void) Palette_3Colors(RGBQuad *palette)
-    /* ---------------------------------------------- */
+
+
+/* --------------------------------- */
+void Palette_3Colors(RGBQuad * palette)
+/* --------------------------------- */
 {
     int i;
-    uint8 rr = 255,gg = 255, bb = 255;
+    uint8 rr = 255, gg = 255, bb = 255;
     RGBQuad pattern[3];
 
@@ -344,17 +298,18 @@
     pattern[2].blue  = bb;
 
-    for(i=0; i<256; i++) {
-        palette[i].red      = pattern[i%3].red;
-        palette[i].green    = pattern[i%3].green;
-        palette[i].blue     = pattern[i%3].blue;
-        palette[i].reserved = (uint8) 0;
-    }
-}
-/* -------------------------------------------------- */
-IMAGE_EXPORT(void) Palette_3Colors_Red(RGBQuad *palette)
-    /* -------------------------------------------------- */
-{
-    int i;
-    uint8 rr = 255,gg = 255, bb = 255;
+    for (i = 0; i < 256; i++) {
+        palette[i].red      = pattern[i % 3].red;
+        palette[i].green    = pattern[i % 3].green;
+        palette[i].blue     = pattern[i % 3].blue;
+        palette[i].reserved = (uint8) 0;
+    }
+}
+
+
+/* ------------------------------------- */
+void Palette_3Colors_Red(RGBQuad * palette)
+/* ------------------------------------- */
+{
+    uint8 rr = 255, gg = 255, bb = 255;
     RGBQuad pattern[3];
 
@@ -376,17 +331,18 @@
     palette[0].blue  = pattern[0].blue;
 
-    for(i=0; i<255; i++) {
-        palette[1+i].red      = pattern[1+i%2].red;
-        palette[1+i].green    = pattern[1+i%2].green;
-        palette[1+i].blue     = pattern[1+i%2].blue;
-        palette[1+i].reserved = (uint8) 0;
-    }
-}
-/* ------------------------------------------------ */
-IMAGE_EXPORT(void) Palette_6ColorsBW(RGBQuad *palette)
-    /* ------------------------------------------------ */
-{
-    int i;
-    uint8 rr = 255,gg = 255, bb = 255;
+    for (int i = 0; i < 255; i++) {
+        palette[1 + i].red      = pattern[1 + i % 2].red;
+        palette[1 + i].green    = pattern[1 + i % 2].green;
+        palette[1 + i].blue     = pattern[1 + i % 2].blue;
+        palette[1 + i].reserved = (uint8) 0;
+    }
+}
+
+
+/* ----------------------------------- */
+void Palette_6ColorsBW(RGBQuad * palette)
+/* ----------------------------------- */
+{
+    uint8 rr = 255, gg = 255, bb = 255;
     RGBQuad pattern[6];
 
@@ -415,9 +371,9 @@
     pattern[5].blue  = bb;
 
-    for(i=0; i<255; i++) {
-        palette[1+i].red      = pattern[i%6].red;
-        palette[1+i].green    = pattern[i%6].green;
-        palette[1+i].blue     = pattern[i%6].blue;
-        palette[1+i].reserved = (uint8) 0;
+    for (int i = 0; i < 255; i++) {
+        palette[1 + i].red      = pattern[i % 6].red;
+        palette[1 + i].green    = pattern[i % 6].green;
+        palette[1 + i].blue     = pattern[i % 6].blue;
+        palette[1 + i].reserved = (uint8) 0;
     }
     palette[0].blue     = (uint8) 0;
@@ -431,10 +387,11 @@
     palette[255].reserved = (uint8) 0;
 }
-/* ---------------------------------------------- */
-IMAGE_EXPORT(void) Palette_6Colors(RGBQuad *palette)
-    /* ---------------------------------------------- */
-{
-    int i;
-    uint8 rr = 255,gg = 255, bb = 255;
+
+
+/* --------------------------------- */
+void Palette_6Colors(RGBQuad * palette)
+/* --------------------------------- */
+{
+    uint8 rr = 255, gg = 255, bb = 255;
     RGBQuad pattern[6];
 
@@ -463,17 +420,18 @@
     pattern[5].blue  = bb;
 
-    for(i=0; i<256; i++) {
-        palette[i].red      = pattern[i%6].red;
-        palette[i].green    = pattern[i%6].green;
-        palette[i].blue     = pattern[i%6].blue;
-        palette[i].reserved = (uint8) 0;
-    }
-}
-/* -------------------------------------------------- */
-IMAGE_EXPORT(void) Palette_6Colors_Red(RGBQuad *palette)
-    /* -------------------------------------------------- */
-{
-    int i;
-    uint8 rr = 255,gg = 255, bb = 255;
+    for (int i = 0; i < 256; i++) {
+        palette[i].red      = pattern[i % 6].red;
+        palette[i].green    = pattern[i % 6].green;
+        palette[i].blue     = pattern[i % 6].blue;
+        palette[i].reserved = (uint8) 0;
+    }
+}
+
+
+/* ------------------------------------- */
+void Palette_6Colors_Red(RGBQuad * palette)
+/* ------------------------------------- */
+{
+    uint8 rr = 255, gg = 255, bb = 255;
     RGBQuad pattern[6];
 
@@ -507,18 +465,20 @@
     palette[0].blue  = pattern[0].blue;
 
-    for(i=0; i<255; i++) {
-        palette[1+i].red      = pattern[1+i%5].red;
-        palette[1+i].green    = pattern[1+i%5].green;
-        palette[1+i].blue     = pattern[1+i%5].blue;
-        palette[1+i].reserved = (uint8) 0;
-    }
-}
-/* ------------------------------------------------- */
-IMAGE_EXPORT(void) Palette_18ColorsBW(RGBQuad *palette)
-    /* ------------------------------------------------- */
+    for (int i = 0; i < 255; i++) {
+        palette[1 + i].red      = pattern[1 + i % 5].red;
+        palette[1 + i].green    = pattern[1 + i % 5].green;
+        palette[1 + i].blue     = pattern[1 + i % 5].blue;
+        palette[1 + i].reserved = (uint8) 0;
+    }
+}
+
+
+/* ------------------------------------ */
+void Palette_18ColorsBW(RGBQuad * palette)
+/* ------------------------------------ */
 {
     int i;
-    uint8 rr = 255,gg = 255, bb = 255;
-    uint8  r  =127, g = 127,  b = 127;
+    uint8 rr = 255, gg = 255, bb = 255;
+    uint8  r = 127, g = 127,  b = 127;
 
     RGBQuad pattern[18];
@@ -596,9 +556,9 @@
     pattern[17].blue  = bb;
 
-    for(i=0; i<255; i++) {
-        palette[1+i].red      = pattern[i%18].red;
-        palette[1+i].green    = pattern[i%18].green;
-        palette[1+i].blue     = pattern[i%18].blue;
-        palette[1+i].reserved = (uint8) 0;
+    for (int i = 0; i < 255; i++) {
+        palette[1 + i].red      = pattern[i % 18].red;
+        palette[1 + i].green    = pattern[i % 18].green;
+        palette[1 + i].blue     = pattern[i % 18].blue;
+        palette[1 + i].reserved = (uint8) 0;
     }
     palette[0].blue     = (uint8) 0;
@@ -612,11 +572,12 @@
     palette[255].reserved = (uint8) 0;
 }
-/* ----------------------------------------------- */
-IMAGE_EXPORT(void) Palette_18Colors(RGBQuad *palette)
-    /* ----------------------------------------------- */
-{
-    int i;
-    uint8 rr = 255,gg = 255, bb = 255;
-    uint8  r  =127, g = 127,  b = 127;
+
+
+/* ---------------------------------- */
+void Palette_18Colors(RGBQuad * palette)
+/* ---------------------------------- */
+{
+    uint8 rr = 255, gg = 255, bb = 255;
+    uint8  r = 127, g = 127,  b = 127;
 
     RGBQuad pattern[18];
@@ -694,17 +655,18 @@
     pattern[17].blue  = bb;
 
-    for(i=0; i<256; i++) {
-        palette[i].red      = pattern[i%18].red;
-        palette[i].green    = pattern[i%18].green;
-        palette[i].blue     = pattern[i%18].blue;
-        palette[i].reserved = (uint8) 0;
-    }
-}
-/* ------------------------------------------------- */
-IMAGE_EXPORT(void) Palette_64ColorsBW(RGBQuad *palette)
-    /* ------------------------------------------------- */
-{
-    int r, g, b;
-    int i, m;
+    for (int i = 0; i < 256; i++) {
+        palette[i].red      = pattern[i % 18].red;
+        palette[i].green    = pattern[i % 18].green;
+        palette[i].blue     = pattern[i % 18].blue;
+        palette[i].reserved = (uint8) 0;
+    }
+}
+
+
+/* ------------------------------------ */
+void Palette_64ColorsBW(RGBQuad * palette)
+/* ------------------------------------ */
+{
+    int m;
     //uint8 x1 = 64, x2 = 128, x3 = 192, x4 = 255;
     uint8 X[4];
@@ -717,7 +679,7 @@
 
     m = 1;
-    for(r=0; r<4; r++) {
-        for(g=0; g<4; g++) {
-            for(b=0; b<4; b++) {
+    for (int r = 0; r < 4; r++) {
+        for (int g = 0; g < 4; g++) {
+            for (int b = 0; b < 4; b++) {
                 palette[m].red   = X[r];
                 palette[m].green = X[g];
@@ -728,9 +690,9 @@
     }
 
-    for(i=0; i<255-(1+m); i++) {
-        palette[1+m+i].red      = palette[i%m].red;
-        palette[1+m+i].green    = palette[i%m].green;
-        palette[1+m+i].blue     = palette[i%m].blue;
-        palette[1+m+i].reserved = (uint8) 0;
+    for (int i = 0; i < 255 - (1 + m); i++) {
+        palette[1 + m + i].red      = palette[i % m].red;
+        palette[1 + m + i].green    = palette[i % m].green;
+        palette[1 + m + i].blue     = palette[i % m].blue;
+        palette[1 + m + i].reserved = (uint8) 0;
     }
     palette[0].blue     = (uint8) 0;
@@ -744,9 +706,10 @@
     palette[255].reserved = (uint8) 0;
 }
-/* ------------------------------------------------- */
-IMAGE_EXPORT(void) Palette_256ColorsBW(RGBQuad *palette)
-    /* ------------------------------------------------- */
-{
-    int r, g, b;
+
+
+/* ------------------------------------- */
+void Palette_256ColorsBW(RGBQuad * palette)
+/* ------------------------------------- */
+{
     int m;
     //uint8 x1 = 64, x2 = 128, x3 = 192, x4 = 255;
@@ -764,14 +727,14 @@
 
     m = 1;
-    for(r=0; r<8; r++) {
-        for(g=0; g<8; g++) {
-            for(b=0; b<8; b++) {
-                if(m<255) {
+    for (int r = 0; r < 8; r++) {
+        for (int g = 0; g < 8; g++) {
+            for (int b = 0; b < 8; b++) {
+                if (m < 255) {
                     xr = X[r]; xg = X[g]; xb = X[b];
                     palette[m].red   = xr;
                     palette[m].green = xg;
                     palette[m].blue  = xb;
-                    if((xr!=255) && (xg!=255) && (xb!=255)) m++;
-                    if((xr!=000) && (xg!=000) && (xb!=000)) m++;
+                    if ((xr != 255) && (xg != 255) && (xb != 255)) m++;
+                    if ((xr != 000) && (xg != 000) && (xb != 000)) m++;
                 }
             }
@@ -789,11 +752,12 @@
     palette[255].reserved = (uint8) 0;
 }
-/* ----------------------------------------------------- */
-IMAGE_EXPORT(void) Palette_18ColorsBW_Red(RGBQuad *palette)
-    /* ----------------------------------------------------- */
-{
-    int i;
-    uint8 rr = 255,gg = 255, bb = 255;
-    uint8  r  =127, g = 127,  b = 127;
+
+
+/* ---------------------------------------- */
+void Palette_18ColorsBW_Red(RGBQuad * palette)
+/* ---------------------------------------- */
+{
+    uint8 rr = 255, gg = 255, bb = 255;
+    uint8  r = 127, g = 127,  b = 127;
 
     RGBQuad pattern[18];
@@ -871,9 +835,9 @@
     pattern[17].blue  = bb;
 
-    for(i=0; i<254; i++) {
-        palette[2+i].red      = pattern[1+i%17].red;
-        palette[2+i].green    = pattern[1+i%17].green;
-        palette[2+i].blue     = pattern[1+i%17].blue;
-        palette[2+i].reserved = (uint8) 0;
+    for (int i = 0; i < 254; i++) {
+        palette[2 + i].red      = pattern[1 + i % 17].red;
+        palette[2 + i].green    = pattern[1 + i % 17].green;
+        palette[2 + i].blue     = pattern[1 + i % 17].blue;
+        palette[2 + i].reserved = (uint8) 0;
     }
     /* noir en 0 */
@@ -890,9 +854,10 @@
     palette[255].blue  = gg;
 }
-/* -------------------------------------------------------------- */
-IMAGE_EXPORT(void) Palette_18ColorsBW_RedGreenBlue(RGBQuad *palette)
-    /* -------------------------------------------------------------- */
-{
-    int i;
+
+
+/* ------------------------------------------------- */
+void Palette_18ColorsBW_RedGreenBlue(RGBQuad * palette)
+/* ------------------------------------------------- */
+{
     uint8 i0 = 255;
     uint8 i1 = 127;
@@ -965,9 +930,9 @@
     pattern[14].blue  = i0;
 
-    for(i=0; i<=250; i++) {
-        palette[4+i].red      = pattern[i%14].red;
-        palette[4+i].green    = pattern[i%14].green;
-        palette[4+i].blue     = pattern[i%14].blue;
-        palette[4+i].reserved = (uint8) 0;
+    for (int i = 0; i <= 250; i++) {
+        palette[4 + i].red      = pattern[i % 14].red;
+        palette[4 + i].green    = pattern[i % 14].green;
+        palette[4 + i].blue     = pattern[i % 14].blue;
+        palette[4 + i].reserved = (uint8) 0;
     }
 
@@ -997,126 +962,101 @@
     palette[255].blue  = i0;
 }
-/* ---------------------------------------------------- */
-IMAGE_EXPORT(void) Palette_3ColorsGrayBW(RGBQuad *palette)
-    /* ---------------------------------------------------- */
-{
-    int i;
-
+
+
+/* --------------------------------------- */
+void Palette_3ColorsGrayBW(RGBQuad * palette)
+/* --------------------------------------- */
+{
     Palette_3ColorsBW(palette);
 
-    for(i=128; i<256; i++) {
-        palette[i].red      = 1 + 2*(i-128);
-        palette[i].green    = 1 + 2*(i-128);
-        palette[i].blue     = 1 + 2*(i-128);
-        palette[i].reserved = (uint8) 0;
-    }
-    /* palette[255] = blanc <- OK */
-}
-/* -------------------------------------------------- */
-IMAGE_EXPORT(void) Palette_3ColorsGray(RGBQuad *palette)
-    /* -------------------------------------------------- */
-{
-    int i;
-
+    for (int i = 128; i < 256; i++) {
+        palette[i].red      = 1 + 2 * (i - 128);
+        palette[i].green    = 1 + 2 * (i - 128);
+        palette[i].blue     = 1 + 2 * (i - 128);
+        palette[i].reserved = (uint8) 0;
+    }
+}
+
+
+/* ------------------------------------- */
+void Palette_3ColorsGray(RGBQuad * palette)
+/* ------------------------------------- */
+{
     Palette_3Colors(palette);
 
-    for(i=128; i<256; i++) {
-        palette[i].red      = 1 + 2*(i-128);
-        palette[i].green    = 1 + 2*(i-128);
-        palette[i].blue     = 1 + 2*(i-128);
-        palette[i].reserved = (uint8) 0;
-    }
-}
-/* ---------------------------------------------------- */
-IMAGE_EXPORT(void) Palette_6ColorsGrayBW(RGBQuad *palette)
-    /* ---------------------------------------------------- */
-{
-    int i;
-
+    for (int i = 128; i < 256; i++) {
+        palette[i].red      = 1 + 2 * (i - 128);
+        palette[i].green    = 1 + 2 * (i - 128);
+        palette[i].blue     = 1 + 2 * (i - 128);
+        palette[i].reserved = (uint8) 0;
+    }
+}
+
+
+/* --------------------------------------- */
+void Palette_6ColorsGrayBW(RGBQuad * palette)
+/* --------------------------------------- */
+{
     Palette_6ColorsBW(palette);
 
-    for(i=128; i<256; i++) {
-        palette[i].red      = 1 + 2*(i-128);
-        palette[i].green    = 1 + 2*(i-128);
-        palette[i].blue     = 1 + 2*(i-128);
-        palette[i].reserved = (uint8) 0;
-    }
-}
-/* -------------------------------------------------- */
-IMAGE_EXPORT(void) Palette_6ColorsGray(RGBQuad *palette)
-    /* -------------------------------------------------- */
-{
-    int i;
-
+    for (int i = 128; i < 256; i++) {
+        palette[i].red      = 1 + 2 * (i - 128);
+        palette[i].green    = 1 + 2 * (i - 128);
+        palette[i].blue     = 1 + 2 * (i - 128);
+        palette[i].reserved = (uint8) 0;
+    }
+}
+
+
+/* ------------------------------------- */
+void Palette_6ColorsGray(RGBQuad * palette)
+/* ------------------------------------- */
+{
     Palette_6Colors(palette);
 
-    for(i=128; i<256; i++) {
-        palette[i].red      = 1 + 2*(i-128);
-        palette[i].green    = 1 + 2*(i-128);
-        palette[i].blue     = 1 + 2*(i-128);
-        palette[i].reserved = (uint8) 0;
-    }
-}
-/* ----------------------------------------------------- */
-IMAGE_EXPORT(void) Palette_18ColorsGrayBW(RGBQuad *palette)
-    /* ----------------------------------------------------- */
-{
-    int i;
-
+    for (int i = 128; i < 256; i++) {
+        palette[i].red      = 1 + 2 * (i - 128);
+        palette[i].green    = 1 + 2 * (i - 128);
+        palette[i].blue     = 1 + 2 * (i - 128);
+        palette[i].reserved = (uint8) 0;
+    }
+}
+
+
+/* ---------------------------------------- */
+void Palette_18ColorsGrayBW(RGBQuad * palette)
+/* ---------------------------------------- */
+{
     Palette_18ColorsBW(palette);
 
-    for(i=128; i<256; i++) {
-        palette[i].red      = 1 + 2*(i-128);
-        palette[i].green    = 1 + 2*(i-128);
-        palette[i].blue     = 1 + 2*(i-128);
-        palette[i].reserved = (uint8) 0;
-    }
-}
-/* --------------------------------------------------- */
-IMAGE_EXPORT(void) Palette_18ColorsGray(RGBQuad *palette)
-    /* --------------------------------------------------- */
-{
-    int i;
-
+    for (int i = 128; i < 256; i++) {
+        palette[i].red      = 1 + 2 * (i - 128);
+        palette[i].green    = 1 + 2 * (i - 128);
+        palette[i].blue     = 1 + 2 * (i - 128);
+        palette[i].reserved = (uint8) 0;
+    }
+}
+
+
+/* -------------------------------------- */
+void Palette_18ColorsGray(RGBQuad * palette)
+/* -------------------------------------- */
+{
     Palette_18Colors(palette);
 
-    for(i=128; i<256; i++) {
-        palette[i].red      = 1 + 2*(i-128);
-        palette[i].green    = 1 + 2*(i-128);
-        palette[i].blue     = 1 + 2*(i-128);
-        palette[i].reserved = (uint8) 0;
-    }
-}
-/* -------------------------------------------------------------------- */
-//IMAGE_EXPORT(void) Palette_PackGrayLower(Image *src, Lut *lut, Image *dst)
-/* -------------------------------------------------------------------- */
-/*{
-  int k;
-  uint8 *l = (uint8*) Lut_Get_Data(lut);
-
-  for(k=0; k<256; k++) {
-  l[k] = (uint8) (k >> 1);
-  }
-
-  Lut_Apply(src, lut, dst);
-  }*/
-/* -------------------------------------------------------------------- */
-//IMAGE_EXPORT(void) Palette_PackGrayUpper(Image *src, Lut *lut, Image *dst)
-/* -------------------------------------------------------------------- */
-/*{
-  int k;
-  uint8 *l = (uint8*) Lut_Get_Data(lut);
-
-  for(k=0; k<256; k++) {
-  l[k] = (uint8) 128 + (k >> 1);
-  }
-
-  Lut_Apply(src, lut, dst);
-  }*/
-/* ---------------------------------------------- */
-IMAGE_EXPORT(void) Palette_2Colors(RGBQuad *palette)
-    /* ---------------------------------------------- */
-{
-    int i, level;
+    for(int i = 128; i < 256; i++) {
+        palette[i].red      = 1 + 2 * (i - 128);
+        palette[i].green    = 1 + 2 * (i - 128);
+        palette[i].blue     = 1 + 2 * (i - 128);
+        palette[i].reserved = (uint8) 0;
+    }
+}
+
+
+/* --------------------------------- */
+void Palette_2Colors(RGBQuad * palette)
+/* --------------------------------- */
+{
+    int level;
 
     RGBQuad pattern[2];
@@ -1132,21 +1072,23 @@
     pattern[1].blue  = level;
 
-    for(i=0; i<256; i++) {
-        palette[i].red      = pattern[i%2].red;
-        palette[i].green    = pattern[i%2].green;
-        palette[i].blue     = pattern[i%2].blue;
-        palette[i].reserved = (uint8) 0;
-    }
-}
-/* ---------------------------------------------- */
-IMAGE_EXPORT(void) Palette_4Colors(RGBQuad *palette)
-    /* ---------------------------------------------- */
-{
-    int i, level;
+    for (int i = 0; i < 256; i++) {
+        palette[i].red      = pattern[i % 2].red;
+        palette[i].green    = pattern[i % 2].green;
+        palette[i].blue     = pattern[i % 2].blue;
+        palette[i].reserved = (uint8) 0;
+    }
+}
+
+
+/* --------------------------------- */
+void Palette_4Colors(RGBQuad * palette)
+/* --------------------------------- */
+{
+    int level;
 
     RGBQuad pattern[4];
 
-    for(i=0; i<2; i++) {
-        level = (i<<8) - 1;
+    for (int i = 0; i < 2; i++) {
+        level = (i << 8) - 1;
         pattern[i].red   = level;
         pattern[0].green = level;
@@ -1154,21 +1096,23 @@
     }
 
-    for(i=0; i<256; i++) {
-        palette[i].red      = pattern[i%2].red;
-        palette[i].green    = pattern[i%2].green;
-        palette[i].blue     = pattern[i%2].blue;
-        palette[i].reserved = (uint8) 0;
-    }
-}
-/* ---------------------------------------------- */
-IMAGE_EXPORT(void) Palette_16Colors(RGBQuad *palette)
-    /* ---------------------------------------------- */
-{
-    int i, level;
+    for (int i = 0; i < 256; i++) {
+        palette[i].red      = pattern[i % 2].red;
+        palette[i].green    = pattern[i % 2].green;
+        palette[i].blue     = pattern[i % 2].blue;
+        palette[i].reserved = (uint8) 0;
+    }
+}
+
+
+/* ---------------------------------- */
+void Palette_16Colors(RGBQuad * palette)
+/* ---------------------------------- */
+{
+    int level;
 
     RGBQuad pattern[16];
 
-    for(i=0; i<4; i++) {
-        level = (i<<8) - 1;
+    for (int i = 0; i < 4; i++) {
+        level = (i << 8) - 1;
         pattern[i].red   = level;
         pattern[0].green = level;
@@ -1176,9 +1120,20 @@
     }
 
-    for(i=0; i<256; i++) {
-        palette[i].red      = pattern[i%2].red;
-        palette[i].green    = pattern[i%2].green;
-        palette[i].blue     = pattern[i%2].blue;
-        palette[i].reserved = (uint8) 0;
-    }
-}
+    for (int i = 0; i < 256; i++) {
+        palette[i].red      = pattern[i % 2].red;
+        palette[i].green    = pattern[i % 2].green;
+        palette[i].blue     = pattern[i % 2].blue;
+        palette[i].reserved = (uint8) 0;
+    }
+}
+
+
+// Local Variables:
+// tab-width: 4
+// c-basic-offset: 4
+// c-file-offsets:((innamespace . 0)(inline-open . 0))
+// indent-tabs-mode: nil
+// End:
+
+// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4
+
Index: soft/giet_vm/applications/rosenfeld/src/str_ext.c
===================================================================
--- soft/giet_vm/applications/rosenfeld/src/str_ext.c	(revision 820)
+++ soft/giet_vm/applications/rosenfeld/src/str_ext.c	(revision 821)
@@ -13,7 +13,7 @@
 #include "nrc_os_config.h"
 
-// --------------------------------------------
-void str_remove_ext(const char* src, char* dst)
-// --------------------------------------------
+// ----------------------------------------------
+void str_remove_ext(const char * src, char * dst)
+// ----------------------------------------------
 {
     int len;
@@ -47,4 +47,6 @@
     dst[len] = '\0'; // do not forget to add null char, otherwise
 }
+
+
 // -------------------
 int str_len(char * str)
Index: soft/giet_vm/applications/rosenfeld/src/util.c
===================================================================
--- soft/giet_vm/applications/rosenfeld/src/util.c	(revision 820)
+++ soft/giet_vm/applications/rosenfeld/src/util.c	(revision 821)
@@ -39,4 +39,5 @@
 }
 
+
 /* ------------- */
 uint8 ui8rand(void)
@@ -47,4 +48,6 @@
     return  x;
 }
+
+
 /* --------------- */
 uint32 ui32rand(void)
@@ -55,4 +58,6 @@
     return x;
 }
+
+
 /* --------------- */
 float32 f32rand(void)
@@ -63,34 +68,36 @@
     return x ;
 }
+
+
 /* --------------------------------------- */
 void rand_ui8vector(uint8 * X, int i0, int i1)
 /* --------------------------------------- */
 {
-    int i;
-
-    for(i = i0; i <= i1; i++) {
+    for (int i = i0; i <= i1; i++) {
         X[i] = ui8rand();
     }
 }
+
+
 /* ----------------------------------------- */
 void rand_ui32vector(uint32 *X, int i0, int i1)
 /* ----------------------------------------- */
 {
-    int i;
-
-    for (i = i0; i <= i1; i++) {
+    for (int i = i0; i <= i1; i++) {
         X[i] = ui32rand();
     }
 }
+
+
 /* ----------------------------------------- */
 void rand_f32vector(float32 *X, int i0, int i1)
 /* ----------------------------------------- */
 {
-    int i;
-
-    for(i = i0; i <= i1; i++) {
+    for (int i = i0; i <= i1; i++) {
         X[i] = f32rand();
     }
 }
+
+
 /* --------------- */
 int getIter(int size)
@@ -106,4 +113,6 @@
     return 2;
 }
+
+
 /* ----------------- */
 int getIterAV(int size)
@@ -112,4 +121,6 @@
     return 3 * getIter(size);
 }
+
+
 /* --------------------------------- */
 float32 gauss(float32 sigma, float32 x)
@@ -130,4 +141,6 @@
     return cpp;
 }
+
+
 // --------------------------
 void printf_split12(double x)
@@ -160,5 +173,4 @@
         return;
     }
-    printf("");
 }
 
@@ -199,5 +211,4 @@
         return;
     }
-    printf("");
 }
 // --------------------------
@@ -243,6 +254,7 @@
         return;
     }
-    printf("");
-}
+}
+
+
 // ------------------------
 void printf_split(double x)
@@ -253,3 +265,12 @@
     //printf_split18(x);
 }
-    
+ 
+// Local Variables:
+// tab-width: 4
+// c-basic-offset: 4
+// c-file-offsets:((innamespace . 0)(inline-open . 0))
+// indent-tabs-mode: nil
+// End:
+
+// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4
+
