Index: soft/giet_vm/applications/rosenfeld/src/ecc_generation.c
===================================================================
--- soft/giet_vm/applications/rosenfeld/src/ecc_generation.c	(revision 791)
+++ soft/giet_vm/applications/rosenfeld/src/ecc_generation.c	(revision 822)
@@ -23,12 +23,9 @@
 
 
-// -------------------------------------------------------------------------------------------------------------------------
-void generate_granularity_density_float(uint8 **X, int i0, int i1, int j0, int j1, int granularity, float density, int seed)
-// -------------------------------------------------------------------------------------------------------------------------
+// --------------------------------------------------------------------------------------------------------------------------
+void generate_granularity_density_float(uint8 ** X, int i0, int i1, int j0, int j1, int granularity, float density, int seed)
+// --------------------------------------------------------------------------------------------------------------------------
 {
     uint8 x;
-    int i, j;
-    int di, dj;
-    
     double r;
 
@@ -36,59 +33,68 @@
     init_genrand(seed);
 
-    for(i=i0; i<=i1; i+=granularity) {
-        for(j=j0; j<=j1; j+=granularity) {
+    for (int i = i0; i <= i1; i += granularity) {
+        for (int j = j0; j <= j1; j += granularity) {
 
             //r = 100.0*(double)rand() / rmax;
             //r = 100.0*(double)rand() / rmax;
-            r = 100.0*(double)genrand_real2();
-            if(r <= density) x = 1; else x = 0;
-
-            for(di=0; di<granularity; di++) {
-                for(dj=0; dj<granularity; dj++) {
-                    if ((i+di<=i1) && (j+dj<=j1)) X[i+di][j+dj] = x;
+            r = 100.0 * (double) genrand_real2();
+            if (r <= density) {
+                x = 1;
+            }
+            else {
+                x = 0;
+            }
+
+            for (int di = 0; di < granularity; di++) {
+                for (int dj = 0; dj < granularity; dj++) {
+                    if ((i + di <= i1) && (j + dj <= j1)) {
+                        X[i + di][j + dj] = x;
+                    }
                 } // dj
             } // di
-
-        } //j
+        } // j
     } // i
 }
-// ---------------------------------------------------------------------------------------------------------------------
-void generate_granularity_density_int(uint8 **X, int i0, int i1, int j0, int j1, int granularity, int density, int seed)
-// ---------------------------------------------------------------------------------------------------------------------
+
+// ----------------------------------------------------------------------------------------------------------------------
+void generate_granularity_density_int(uint8 ** X, int i0, int i1, int j0, int j1, int granularity, int density, int seed)
+// ----------------------------------------------------------------------------------------------------------------------
 {
     generate_granularity_density_float(X, i0, i1, j0, j1, granularity, (float) density, seed);
 }
-// ---------------------------------------------------------------------------------------------------------
-void generate_granularity_density_name(char *name, int granularity, int density, char *filename, int maxlen)
-// ---------------------------------------------------------------------------------------------------------
+
+// -----------------------------------------------------------------------------------------------------------
+void generate_granularity_density_name(char * name, int granularity, int density, char * filename, int maxlen)
+// -----------------------------------------------------------------------------------------------------------
 {
     snprintf(filename, maxlen, "%s_%02d_%03d.pgm", name, granularity, density);
 }
-// ------------------------------------------------------------------------------------------------------------------------------
-void generate_granularity_density_ext_name(char *name, int granularity, int density, char *extension, char *filename, int maxlen)
-// ------------------------------------------------------------------------------------------------------------------------------
+
+// ---------------------------------------------------------------------------------------------------------------------------------
+void generate_granularity_density_ext_name(char * name, int granularity, int density, char * extension, char * filename, int maxlen)
+// ---------------------------------------------------------------------------------------------------------------------------------
 {
     snprintf(filename, maxlen, "%s_%02d_%03d.%s", name, granularity, density, extension);
 }
-// ------------------------------------------------------------------------------------------------------------------------
-void generate_size_granularity_density_name(char *name, int size, int granularity, int density, char *filename, int maxlen)
-// ------------------------------------------------------------------------------------------------------------------------
+// --------------------------------------------------------------------------------------------------------------------------
+void generate_size_granularity_density_name(char * name, int size, int granularity, int density, char * filename, int maxlen)
+// --------------------------------------------------------------------------------------------------------------------------
 {
     snprintf(filename, maxlen, "%s_%d_%02d_%03d.pgm", name, size, granularity, density);
 }
-// ---------------------------------------------------------------------------------------------------------------------------------------------
-void generate_size_granularity_density_ext_name(char *name, int size, int granularity, int density, char *extension, char *filename, int maxlen)
-// ---------------------------------------------------------------------------------------------------------------------------------------------
+// -----------------------------------------------------------------------------------------------------------------------------------------------
+void generate_size_granularity_density_ext_name(char * name, int size, int granularity, int density, char *extension, char * filename, int maxlen)
+// -----------------------------------------------------------------------------------------------------------------------------------------------
 {
     snprintf(filename, maxlen, "%s_%d_%02d_%03d.%s", name, size, granularity, density, extension);
 }
-// ---------------------------------------------------------------------------------------------------
-void generate_size_granularity_name(char *name, int size, int granularity, char *filename, int maxlen)
-// ---------------------------------------------------------------------------------------------------
+// -----------------------------------------------------------------------------------------------------
+void generate_size_granularity_name(char * name, int size, int granularity, char * filename, int maxlen)
+// -----------------------------------------------------------------------------------------------------
 {
     snprintf(filename, maxlen, "%s_%d_%02d.pgm", name, size, granularity);
-}// -----------------------------------------------------------------------------------------
-void generate_name100(char *name, int granularity, float density, char *filename, int maxlen)
-// ------------------------------------------------------------------------------------------
+}// ------------------------------------------------------------------------------------------
+void generate_name100(char * name, int granularity, float density, char *filename, int maxlen)
+// -------------------------------------------------------------------------------------------
 {
     // density en pourcentage: 0:100
@@ -98,9 +104,9 @@
 }
 // ----------------------------------------
-int test_generation(int argc, char* argv[])
+int test_generation(int argc, char * argv[])
 // ----------------------------------------
 {
-    uint8 **X;
-    uint8 **X255;
+    uint8 ** X;
+    uint8 ** X255;
     char filename[32];
 
@@ -123,38 +129,42 @@
     n = 4096;
     
-    X    = ui8matrix(0-border, n-1+border, 0-border, n-1+border);
-    X255 = ui8matrix(0-border, n-1+border, 0-border, n-1+border);
-
-    for(g=gmin; g<=gmax; g*=2) {
-        for(d=dmin; d<=dmax; d+=dstep) {
-            generate_granularity_density_int(X, 0, n-1, 0, n-1, g, d, seed);
+    X    = ui8matrix(0 - border, n - 1 + border, 0 - border, n - 1 + border);
+    X255 = ui8matrix(0 - border, n - 1 + border, 0 - border, n - 1 + border);
+
+    for (g = gmin; g <= gmax; g *= 2) {
+        for (d = dmin; d <= dmax; d += dstep) {
+            generate_granularity_density_int(X, 0, n - 1, 0, n - 1, g, d, seed);
             generate_granularity_density_name("I", g, d, filename, 32);
             printf(filename);
-            bin2gray_ui8matrix(X, 0, n-1, 0, n-1, X255);
-            SavePGM_ui8matrix(X255, 0, n-1, 0, n-1, filename); 
-        }
-    }
-    free_ui8matrix(X,    0-border, n-1+border, 0-border, n-1+border);
-    free_ui8matrix(X255, 0-border, n-1+border, 0-border, n-1+border);
+            bin2gray_ui8matrix(X, 0, n - 1, 0, n - 1, X255);
+            SavePGM_ui8matrix(X255, 0, n - 1, 0, n - 1, filename); 
+        }
+    }
+    free_ui8matrix(X,    0 - border, n - 1 + border, 0 - border, n - 1 + border);
+    free_ui8matrix(X255, 0 - border, n - 1 + border, 0 - border, n - 1 + border);
 
     return 0;
 }
-// -----------------------------------------
-void hline(uint8 **X, int i, int j0, int j1)
-// -----------------------------------------
-{
-    int j;
-    for(j=j0; j<=j1; j++) X[i][j] = 1;
-}
-// -----------------------------------------
-void vline(uint8 **X, int i0, int i1, int j)
-// -----------------------------------------
-{
-    int i;
-    for(i=i0; i<=i1; i++) X[i][j] = 1;
-}
-// -----------------------------------------------------------
-void draw_rectangle(uint8 **X, int i0, int i1, int j0, int j1)
-// -----------------------------------------------------------
+
+// ------------------------------------------
+void hline(uint8 ** X, int i, int j0, int j1)
+// ------------------------------------------
+{
+    for (int j = j0; j <= j1; j++) {
+        X[i][j] = 1;
+    }
+}
+// ------------------------------------------
+void vline(uint8 ** X, int i0, int i1, int j)
+// ------------------------------------------
+{
+    for (int i = i0; i <= i1; i++) {
+        X[i][j] = 1;
+    }
+}
+
+// ------------------------------------------------------------
+void draw_rectangle(uint8 ** X, int i0, int i1, int j0, int j1)
+// ------------------------------------------------------------
 {
     hline(X, i0, j0, j1);
@@ -163,7 +173,8 @@
     hline(X, i1, j0, j1);
 }
-// --------------------------------------------------
-void spirale_simple(uint8 **X, int height, int width)
-// --------------------------------------------------
+
+// ---------------------------------------------------
+void spirale_simple(uint8 ** X, int height, int width)
+// ---------------------------------------------------
 {
     int i0, j0; // point de depart haut
@@ -172,9 +183,10 @@
     int n;      //min(height, width)
     
-    zero_ui8matrix(X, 0, height-1, 0, width-1);
-    
-    if(height<width) {
+    zero_ui8matrix(X, 0, height - 1, 0, width - 1);
+    
+    if (height < width) {
         n = height;
-    } else {
+    }
+    else {
         n = width;
     }
@@ -184,21 +196,24 @@
     
     // avec correction
-    i0 = 0; i1 = 2*(n/2)-1;
-    j0 = 0; j1 = 2*(n/2)-1;
+    i0 = 0;
+    i1 = 2 * (n / 2) - 1;
+    j0 = 0;
+    j1 = 2 * (n / 2) - 1;
     
     nc = n / 4;
     
-    for(c=0; c<nc; c++) {
-        draw_rectangle(X, i0+2*c, i1-2*c, j0+2*c, j1-2*c);
-        X[1+2*c  ][0+2*c  ] = 0;
-        X[1+2*c+1][0+2*c+1] = 1;
+    for (c = 0; c < nc; c++) {
+        draw_rectangle(X, i0 + 2 * c, i1 - 2 * c, j0 + 2 * c, j1 - 2 * c);
+        X[1 + 2 * c    ][0 + 2 * c    ] = 0;
+        X[1 + 2 * c + 1][0 + 2 * c + 1] = 1;
     }
     
     // centre
     //X[n/2][n/2] = 1;
-    for(c=i0+2*nc; c<=i1-2*nc; c++) {
-        hline(X, c, j0+2*nc, j1-2*nc);
-    }
-}
+    for (c = i0 + 2 * nc; c <= i1 - 2 * nc; c++) {
+        hline(X, c, j0 + 2 * nc, j1 - 2 * nc);
+    }
+}
+
 // --------------------------------------------------
 void spirale_double(uint8 **X, int height, int width)
@@ -212,7 +227,8 @@
     zero_ui8matrix(X, 0, height-1, 0, width-1);
     
-    if(height<width) {
+    if (height < width) {
         n = height;
-    } else {
+    }
+    else {
         n = width;
     }
@@ -221,23 +237,25 @@
     //n = ((n-1) & (~0x3))+1;
     
-    i0 = 0; i1 = 2*(n/2)-1;
-    j0 = 0; j1 = 2*(n/2)-1;
+    i0 = 0;
+    i1 = 2 * (n / 2) - 1;
+    j0 = 0;
+    j1 = 2 * (n / 2) - 1;
     
     nc = n / 4;
     
-    for(c=0; c<nc; c++) {
-        draw_rectangle(X, i0+2*c, i1-2*c, j0+2*c, j1-2*c);
-    }
-    for(c=0; c<nc; c++) {
-        X[(i0+1)+(2*c  )][(j0)+(2*c  )] = 0;
-        X[(i0+1)+(2*c+1)][(j0)+(2*c+1)] = 1;
+    for (c = 0; c < nc; c++) {
+        draw_rectangle(X, i0 + 2 * c, i1 - 2 * c, j0 + 2 * c, j1 - 2 * c);
+    }
+    for (c = 0; c < nc; c++) {
+        X[(i0 + 1) + (2 * c    )][(j0) + (2 * c    )] = 0;
+        X[(i0 + 1) + (2 * c + 1)][(j0) + (2 * c + 1)] = 1;
         
-        X[(i1-1)-(2*c  )][(j1)-(2*c  )] = 0;
-        X[(i1-1)-(2*c+1)][(j1)-(2*c+1)] = 1;
+        X[(i1 - 1) - (2 * c    )][(j1) - (2 * c    )] = 0;
+        X[(i1 - 1) - (2 * c + 1)][(j1) - (2 * c + 1)] = 1;
     }
     // centre
     //X[n/2][n/2] = 1;
-    for(c=i0+2*nc; c<=i1-2*nc; c++) {
-        hline(X, c, j0+2*nc, j1-2*nc);
+    for (c = i0 + 2 * nc; c <= i1 - 2 * nc; c++) {
+        hline(X, c, j0 + 2 * nc, j1 - 2 * nc);
     }
 }
@@ -246,6 +264,6 @@
 // ------------------------
 {
-    uint8 **X;
-    uint8 **X255;
+    uint8 ** X;
+    uint8 ** X255;
     char filename[128];
     //char *ptr = (char*) filename;
@@ -254,23 +272,24 @@
     h = w = n;
     
-    X    = ui8matrix(0, h-1, 0, w-1);
-    X255 = ui8matrix(0, h-1, 0, w-1);
+    X    = ui8matrix(0, h - 1, 0, w - 1);
+    X255 = ui8matrix(0, h - 1, 0, w - 1);
     
     snprintf(filename, 128, "spirale_simple_%d.pgm", n);
     spirale_simple(X, h, w);
-    bin2gray_ui8matrix(X,   0, h-1, 0, w-1, X255);
-    SavePGM_ui8matrix(X255, 0, h-1, 0, w-1, filename); 
+    bin2gray_ui8matrix(X,   0, h - 1, 0, w - 1, X255);
+    SavePGM_ui8matrix(X255, 0, h - 1, 0, w - 1, filename); 
     
     snprintf(filename, 128, "spirale_double_%d.pgm", n);
     spirale_double(X, h, w);
-    bin2gray_ui8matrix(X,   0, h-1, 0, w-1, X255);
-    SavePGM_ui8matrix(X255, 0, h-1, 0, w-1, filename);/**/
-    
-    free_ui8matrix(X,    0, h-1, 0, w-1);
-    free_ui8matrix(X255, 0, h-1, 0, w-1);
-}
-// --------------------------------------
-void test_spirale(int argc, char* argv[])
-// --------------------------------------
+    bin2gray_ui8matrix(X,   0, h - 1, 0, w - 1, X255);
+    SavePGM_ui8matrix(X255, 0, h - 1, 0, w - 1, filename);/**/
+    
+    free_ui8matrix(X,    0, h - 1, 0, w - 1);
+    free_ui8matrix(X255, 0, h - 1, 0, w - 1);
+}
+
+// ---------------------------------------
+void test_spirale(int argc, char * argv[])
+// ---------------------------------------
 {
     routine_spirale(128);
@@ -283,14 +302,15 @@
     routine_spirale(1024);
 }
-// --------------------------------------------
-int test_generation_HGH(int argc, char* argv[])
-// --------------------------------------------
-{
-    uint8 **X;
-    uint8 **X255;
+
+// ---------------------------------------------
+int test_generation_HGH(int argc, char * argv[])
+// ---------------------------------------------
+{
+    uint8 ** X;
+    uint8 ** X255;
     char filename[32];
 
     int h = 1280;
-    int w = 90*1024;
+    int w = 90 * 1024;
 
     int border = 2;
@@ -303,21 +323,22 @@
     //w = h;
 
-    X    = ui8matrix(0-border, h-1+border, 0-border, w-1+border);
-    X255 = ui8matrix(0-border, h-1+border, 0-border, w-1+border);
-
-    generate_granularity_density_float(X, 0, h-1, 0, w-1, g, d, seed);
+    X    = ui8matrix(0 - border, h - 1 + border, 0 - border, w - 1 + border);
+    X255 = ui8matrix(0 - border, h - 1 + border, 0 - border, w - 1 + border);
+
+    generate_granularity_density_float(X, 0, h - 1, 0, w - 1, g, d, seed);
     generate_granularity_density_name("HGH", g, d, filename, 32);
     printf(filename);
-    bin2gray_ui8matrix(X,   0, h-1, 0, w-1, X255);
-    SavePGM_ui8matrix(X255, 0, h-1, 0, w-1, filename); 
-
-    free_ui8matrix(X,    0-border, h-1+border, 0-border, w-1+border);
-    free_ui8matrix(X255, 0-border, h-1+border, 0-border, w-1+border);
+    bin2gray_ui8matrix(X,   0, h - 1, 0, w - 1, X255);
+    SavePGM_ui8matrix(X255, 0, h - 1, 0, w - 1, filename); 
+
+    free_ui8matrix(X,    0 - border, h - 1 + border, 0 - border, w - 1 + border);
+    free_ui8matrix(X255, 0 - border, h - 1 + border, 0 - border, w - 1 + border);
 
     return 0;
 }
-// --------------------------------------------
-int image_analysis_2014(int argc, char* argv[])
-// --------------------------------------------
+
+// ---------------------------------------------
+int image_analysis_2014(int argc, char * argv[])
+// ---------------------------------------------
 {
     // uint8 **X;
@@ -466,5 +487,5 @@
 // --------------------------
 {
-    int i, n = 32;
+    int n = 32;
     
     printf("---------------------------");
@@ -474,79 +495,48 @@
     
     init_genrand(0);
-    for(i=0; i<n; i++) {
+    for (int i = 0; i < n; i++) {
         printf("%10lu ", genrand_int32());
-        if (i%8==7) printf("\n");
+        if (i % 8 == 7) {
+            printf("\n");
+        }
     }
     printf("\n---");
     
     init_genrand(1);
-    for(i=0; i<n; i++) {
+    for (int i = 0; i < n; i++) {
         printf("%10lu ", genrand_int32());
-        if (i%8==7) printf("\n");
+        if (i % 8== 7) {
+            printf("\n");
+        }
     }
     printf("\n---");
     
     init_genrand(0);
-    for(i=0; i<n; i++) {
+    for (int i = 0; i < n; i++) {
         printf("%10lu ", genrand_int32());
-        if (i%8==7) printf("\n");
+        if (i % 8== 7) {
+            printf("\n");
+        }
     }
     printf("\n---");
     
     init_genrand(1);
-    for(i=0; i<n; i++) {
+    for (int i = 0; i < n; i++) {
         printf("%10lu ", genrand_int32());
-        if (i%8==7) printf("\n");
-    }
-}
-// -------------------------------------
-void image_zoom2(int argc, char *argv[])
-// -------------------------------------
-{
-    uint8 x, **X, **Y;
-    int i, j, i0, i1, j0, j1;
+        if (i % 8 == 7) {
+            printf("\n");
+        }
+    }
+}
+
+// --------------------------------------
+void image_zoom2(int argc, char * argv[])
+// --------------------------------------
+{
+    uint8 x, ** X, ** Y;
+    int i0, i1, j0, j1;
     int height, width;
-    char *src_filename;
-    char *dst_filename;
-    
-    if(argc<3) {
-        printf("too few arguments");
-        printf("%s src.pgm dst.pgm\n", argv[0]);
-        return;
-    }
-    
-    src_filename = argv[1];
-    dst_filename = argv[2];
-    
-    X = LoadPGM_ui8matrix(src_filename, &i0, &i1, &j0, &j1);
-    
-    height = i1-i0+1;
-    width  = j1-j0+1;
-    
-    printf("width = %d height = %d\n", width, height);
-    
-    Y = ui8matrix(0, 2*height-1, 0, 2*width-1);
-    
-    for(i=0; i<=height-1; i++) {
-        for(j=0; j<=width-1; j++) {
-            x = X[i][j];
-            Y[2*i+0][2*j+0] = x; Y[2*i+0][2*j+1] = x;
-            Y[2*i+1][2*j+0] = x; Y[2*i+1][2*j+1] = x;
-        }
-    }
-    SavePGM_ui8matrix(Y, 0, 2*height-1, 0, 2*width-1, dst_filename);
-    
-    free_ui8matrix(X, 0,   height-1, 0,   width-1);
-    free_ui8matrix(Y, 0, 2*height-1, 0, 2*width-1);
-}
-// --------------------------------------------
-void image_duplication2(int argc, char *argv[])
-// --------------------------------------------
-{
-    uint8 x, **X, **Y;
-    int i, j, i0, i1, j0, j1;
-    int height, width;
-    char *src_filename;
-    char *dst_filename;
+    char * src_filename;
+    char * dst_filename;
     
     if (argc < 3) {
@@ -561,29 +551,77 @@
     X = LoadPGM_ui8matrix(src_filename, &i0, &i1, &j0, &j1);
     
-    height = i1-i0+1;
-    width  = j1-j0+1;
+    height = i1 - i0 + 1;
+    width  = j1 - j0 + 1;
     
     printf("width = %d height = %d\n", width, height);
     
-    Y = ui8matrix(0, 2*height-1, 0, 2*width-1);
+    Y = ui8matrix(0, 2 * height - 1, 0, 2 * width - 1);
+    
+    for (int i = 0; i <= height - 1; i++) {
+        for (int j = 0; j <= width - 1; j++) {
+            x = X[i][j];
+            Y[2 * i + 0][2 * j + 0] = x;
+            Y[2 * i + 0][2 * j + 1] = x;
+            Y[2 * i + 1][2 * j + 0] = x;
+            Y[2 * i + 1][2 * j + 1] = x;
+        }
+    }
+    SavePGM_ui8matrix(Y, 0, 2 * height - 1, 0, 2 * width - 1, dst_filename);
+    
+    free_ui8matrix(X, 0,     height - 1, 0,     width - 1);
+    free_ui8matrix(Y, 0, 2 * height - 1, 0, 2 * width - 1);
+}
+
+
+// ---------------------------------------------
+void image_duplication2(int argc, char * argv[])
+// ---------------------------------------------
+{
+    uint8 x, ** X, ** Y;
+    int i0, i1, j0, j1;
+    int height, width;
+    char * src_filename;
+    char * dst_filename;
+    
+    if (argc < 3) {
+        printf("too few arguments");
+        printf("%s src.pgm dst.pgm\n", argv[0]);
+        return;
+    }
+    
+    src_filename = argv[1];
+    dst_filename = argv[2];
+    
+    X = LoadPGM_ui8matrix(src_filename, &i0, &i1, &j0, &j1);
+    
+    height = i1 - i0 + 1;
+    width  = j1 - j0 + 1;
+    
+    printf("width = %d height = %d\n", width, height);
+    
+    Y = ui8matrix(0, 2 * height - 1, 0, 2 * width - 1);
     
     // horizontal duplication
-    for(i=0; i<=height-1; i++) {
-        for(j=0; j<=width-1; j++) {
+    for (int i = 0; i <= height - 1; i++) {
+        for (int j = 0; j <= width - 1; j++) {
             x = X[i][j];
-            Y[i][width+j] = x;
+            Y[i][width + j] = x;
         }
     }
     
     // vertical duplication
-    for(i=0; i<=height-1; i++) {
-        for(j=0; j<=2*width-1; j++) {
+    for (int i = 0; i <= height - 1; i++) {
+        for (int j = 0; j <= 2 * width - 1; j++) {
             x = X[i][j];
-            Y[height+i][j] = x;
-        }
-    }
-    SavePGM_ui8matrix(Y, 0, 2*height-1, 0, 2*width-1, dst_filename);
-    
-    free_ui8matrix(X, 0,   height-1, 0,   width-1);
-    free_ui8matrix(Y, 0, 2*height-1, 0, 2*width-1);
-}
+            Y[height + i][j] = x;
+        }
+    }
+    SavePGM_ui8matrix(Y, 0, 2 * height - 1, 0, 2 * width - 1, dst_filename);
+    
+    free_ui8matrix(X, 0,     height - 1, 0,     width - 1);
+    free_ui8matrix(Y, 0, 2 * height - 1, 0, 2 * width - 1);
+}
+
+
+
+
