Changeset 821 for soft/giet_vm/applications/rosenfeld/src
- Timestamp:
- May 6, 2016, 3:06:29 PM (9 years ago)
- Location:
- soft/giet_vm/applications/rosenfeld/src
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
soft/giet_vm/applications/rosenfeld/src/bmpNR.c
r798 r821 11 11 #include <math.h> 12 12 13 /* -- image -- */14 #ifdef CLI15 13 #include "nrc_os_config.h" 16 14 #include "nrtype.h" … … 18 16 #include "nrmacro.h" 19 17 #include "nralloc.h" 20 #endif21 18 22 19 #if TARGET_OS == LINUX … … 37 34 #define BI_RGB 0L 38 35 39 PRIVATE void ReadBMProw (int fd, long width, uint8 * row); 40 PRIVATE void WriteBMProw (uint8 * row, long width, int fd); 41 //PRIVATE void SetupPalette (RGBQUAD Palette[]); 42 43 #if (!defined(WIN32) && !defined(_WINDOWS_) && !defined(_WINGDI_)) 44 //#pragma message("bmpio.h no WINDOWS echo") 45 PRIVATE void Palette_RGBQuad2RGBQUAD(RGBQuad * src, RGBQUAD dst[]); 46 #endif 47 48 /* ------------------------------------- */ 49 uint8 *ui8ArrayAppend(uint8 *ptr, uint8 x) 50 /* ------------------------------------- */ 36 static void ReadBMProw(int fd, long width, uint8 * row); 37 static void WriteBMProw(uint8 * row, long width, int fd); 38 static void Palette_RGBQuad2RGBQUAD(RGBQuad * src, RGBQUAD dst[]); 39 40 /* --------------------------------------- */ 41 uint8 * ui8ArrayAppend(uint8 * ptr, uint8 x) 42 /* --------------------------------------- */ 51 43 { 52 44 *ptr++ = x; 53 45 return ptr; 54 46 } 47 55 48 /* ---------------------------------------- */ 56 uint8 * ui16ArrayAppend(uint8 *ptr, uint16 x)57 49 uint8 * ui16ArrayAppend(uint8 * ptr, uint16 x) 50 /* ---------------------------------------- */ 58 51 { 59 52 uint8 x0, x1; … … 67 60 return ptr; 68 61 } 69 /* -------------------------------------- */ 70 uint8 *ui32ArrayAppend(uint8 *ptr, uint32 x) 71 /* -------------------------------------- */ 62 63 /* ---------------------------------------- */ 64 uint8 * ui32ArrayAppend(uint8 * ptr, uint32 x) 65 /* ---------------------------------------- */ 72 66 { 73 67 uint8 x0, x1, x2, x3; … … 85 79 return ptr; 86 80 } 81 87 82 // Seul moyen de cache dans la librairie ces putains de types windoze 88 83 89 84 // -------------------------------------------------------- 90 PRIVATE void ReadBMProw(int fd, long width, uint8 *row)91 85 static void ReadBMProw(int fd, long width, uint8 * row) 86 // -------------------------------------------------------- 92 87 { 93 88 // Le fichier est ouvert (en lecture) et ne sera pas ferme a la fin 94 89 read(fd, row, sizeof(uint8) * width); 95 90 } 91 96 92 // --------------------------------------------------------- 97 PRIVATE void WriteBMProw(uint8 *row, long width, int fd)98 93 static void WriteBMProw(uint8 * row, long width, int fd) 94 // --------------------------------------------------------- 99 95 { 100 96 // Le fichier est deja ouvert et ne sera pas ferme a la fin 101 97 write(fd, row, sizeof(uint8) * width); 102 98 } 103 #if (!defined(WIN32) && !defined(_WINDOWS_) && !defined(_WINGDI_)) 104 //#pragma message("bmpio.h no WINDOWS echo") 99 105 100 /* ----------------------------------------------------------- */ 106 PRIVATE void Palette_RGBQuad2RGBQUAD(RGBQuad *src, RGBQUAD dst[])107 101 static void Palette_RGBQuad2RGBQUAD(RGBQuad * src, RGBQUAD dst[]) 102 /* ----------------------------------------------------------- */ 108 103 { 109 104 int i; … … 115 110 } 116 111 } 117 #endif 118 119 #if (!defined(WIN32) && !defined(_WINDOWS_) && !defined(_WINGDI_)) 120 //#pragma message("bmpio.h no WINDOWS echo") 121 /* --------------------------------------------------------------------------- */ 122 IMAGE_EXPORT(int) SaveBMP0_ui8matrix(uint8 **m, int width, int height, RGBQuad *palette_RGBQuad, char *filename) 112 113 IMAGE_EXPORT(int) SaveBMP0_ui8matrix(uint8 ** m, int width, int height, RGBQuad * palette_RGBQuad, char * filename) 123 114 /* --------------------------------------------------------------------------- */ 124 115 /* sauvegarde 'image' au format bmp dans le fichier 'filename' */ 125 116 { 126 int rc = 0;127 128 117 int v_offset = 0; // no more implemented image->v_offset; 129 118 int h_offset = 0; // no more implemented image->h_offset; 130 119 int vmax = height - v_offset; 131 //int hmax = width - h_offset; 132 int height_utile = height - 2*v_offset; 133 int width_utile = width - 2*h_offset; 120 int height_utile = height - 2 * v_offset; 121 int width_utile = width - 2 * h_offset; 134 122 int taille_utile = height_utile * width_utile; 135 123 136 //int size;137 124 int padding_len; 138 125 139 126 BITMAPFILEHEADER Bitmap_File_Header; 140 /*BITMAPINFO; Bitmap_Info; */141 142 127 BITMAPINFOHEADER Bitmap_Info_Header; 143 /*RGBQUAD RGB_Quad; */144 128 145 129 RGBQUAD palette_RGBQUAD[256]; /* Windows */ … … 156 140 157 141 /* --- Header --- */ 158 Bitmap_File_Header.bfType = (WORD) BM; /* BM */ 159 Bitmap_File_Header.bfSize = (DWORD) sizeof(BITMAPFILEHEADER)+sizeof(BITMAPINFOHEADER)+256*sizeof(RGBQuad)+taille_utile; /* taille avec header et palette */ 160 Bitmap_File_Header.bfReserved1 = (WORD) 0; /* 0 */ 161 Bitmap_File_Header.bfReserved2 = (WORD) 0; /* 0 */ 162 Bitmap_File_Header.bfOffBits = (DWORD) sizeof(BITMAPFILEHEADER) + 163 (DWORD) sizeof(BITMAPINFOHEADER) + 164 (DWORD) sizeof(RGBQUAD)*256; /* */ 142 Bitmap_File_Header.bfType = (WORD) BM; /* BM */ 143 /* taille avec header et palette */ 144 Bitmap_File_Header.bfSize = (DWORD) sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER) + 256 * sizeof(RGBQuad) + taille_utile; 145 Bitmap_File_Header.bfReserved1 = (WORD) 0; /* 0 */ 146 Bitmap_File_Header.bfReserved2 = (WORD) 0; /* 0 */ 147 Bitmap_File_Header.bfOffBits = (DWORD) sizeof(BITMAPFILEHEADER) + (DWORD) sizeof(BITMAPINFOHEADER) + (DWORD) sizeof(RGBQUAD)*256; /* */ 165 148 166 149 … … 182 165 fd = open(filename, O_CREAT | O_TRUNC); 183 166 if (fd < 0) { 184 printf("*** Erreur : Ouverture du fichier impossible dans SaveBMP"); 167 printf("\n*** Erreur : Ouverture du fichier impossible dans SaveBMP\n"); 168 return -1; 185 169 } 186 170 … … 215 199 } 216 200 close(fd); 217 return rc;218 219 } 220 #endif 221 // ------------------------------------------------------------------------------------------------------------ 222 IMAGE_EXPORT(int) SaveBMP2_ui8matrix(uint8 ** m, int width, int height, RGBQuad *palette_RGBQuad, char *filename)223 //------------------------------------------------------------------------------------------------------------224 201 return 0; 202 203 } 204 205 // ---------------------------------------------------------------------------------------------------------------- 206 IMAGE_EXPORT(int) SaveBMP2_ui8matrix(uint8 ** m, int width, int height, RGBQuad * palette_RGBQuad, char * filename) 207 // ---------------------------------------------------------------------------------------------------------------- 208 // sauvegarde 'image' au format bmp dans le fichier 'filename' 225 209 { 226 210 int taille_utile = height * width; 227 228 //int size;229 211 int padding_len; 230 212 … … 241 223 int fd; 242 224 int i; 243 244 //#pragma message("BMP warnin' data structure aligment must be 2")245 //#pragma message(" sizeof( BitmapFileHeader) must = 14, not 16")246 225 247 226 //DEBUG(printf("BMP0 : %d %d\n", sizeof( BITMAPFILEHEADER), sizeof( BITMAPINFOHEADER))); … … 298 277 //printf(" SaveBMP %s %dx%d\n", filename, width, height); 299 278 300 fd = open(filename, O_CREAT | O_TRUNC); 279 #if TARGET_OS != GIETVM 280 fd = open(filename, O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); 281 #else 282 fd = open(filename, O_WRONLY | O_CREAT | O_TRUNC); 283 #endif 301 284 if (fd < 0) { 302 printf("*** Erreur : ouverture du fichier '%s' impossible dans SaveBMP", filename); 285 printf("\n*** Erreur : ouverture du fichier '%s' impossible dans SaveBMP\n", filename); 286 return -1; 303 287 } 304 288 … … 326 310 327 311 328 // en 2x car le compilo est trop con ...329 312 padding_len = width % 4; 330 313 padding_len = (4 - padding_len) % 4; -
soft/giet_vm/applications/rosenfeld/src/ecc_common.c
r798 r821 8 8 #include <math.h> 9 9 10 #ifdef CLI11 10 #include "nrc_os_config.h" 12 11 #include "nrc.h" 13 #endif14 12 15 13 #if TARGET_OS == LINUX … … 44 42 return (a > b ? a : b); 45 43 } 44 45 46 46 // ------------------------------------------ 47 47 uint32 ui32Max3(uint32 a, uint32 b, uint32 c) … … 50 50 return ui32Max2(ui32Max2(a, b), c); 51 51 } 52 53 52 54 // ---------------------------------------------------- 53 55 uint32 ui32Max4(uint32 a, uint32 b, uint32 c, uint32 d) … … 56 58 return ui32Max2(ui32Max2(a, b), ui32Max2(c,d)); 57 59 } 60 61 58 62 // -------------------------------- 59 63 uint32 ui32Min2(uint32 a, uint32 b) … … 62 66 return (a < b ? a : b); 63 67 } 68 69 64 70 // ------------------------------------------ 65 71 uint32 ui32Min3(uint32 a, uint32 b, uint32 c) … … 68 74 return ui32Min2(ui32Min2(a, b), c); 69 75 } 76 77 70 78 // ---------------------------------------------------- 71 79 uint32 ui32Min4(uint32 a, uint32 b, uint32 c, uint32 d) … … 74 82 return ui32Min2(ui32Min2(a, b), ui32Min2(c,d)); 75 83 } 84 85 76 86 /* ----------------------------------- */ 77 87 uint32 ui32MinNonNul2(uint32 a, uint32 b) … … 84 94 return a; 85 95 } 96 97 86 98 /* --------------------------------------------- */ 87 99 uint32 ui32MinNonNul3(uint32 a, uint32 b, uint32 c) … … 96 108 return m; 97 109 } 110 111 98 112 /* ---------------------------------------------------- */ 99 113 uint32 ui32MinNonNul3Cond(uint32 a0, uint32 a1, uint32 a2) … … 105 119 return m; 106 120 } 121 122 107 123 /* ----------------------------------------------------------- */ 108 124 uint32 ui32MinNonNul4(uint32 a0, uint32 a1, uint32 a2, uint32 a3) … … 118 134 return m; 119 135 } 136 137 120 138 /* ---------------------------------------------------------------------- */ 121 139 uint32 ui32MinNonNul5(uint32 a0, uint32 a1, uint32 a2, uint32 a3, uint32 a4) … … 132 150 return m; 133 151 } 152 153 134 154 /* -------------------------------------------------------------------------- */ 135 155 uint32 ui32MinNonNul5Cond(uint32 a0, uint32 a1, uint32 a2, uint32 a3, uint32 a4) … … 141 161 return m; 142 162 } 163 164 143 165 /* ------------------------------------------------------------------------------------------------------- */ 144 166 uint32 ui32MinNonNul8(uint32 a0, uint32 a1, uint32 a2, uint32 a3, uint32 a4, uint32 a5, uint32 a6, uint32 a7) … … 158 180 return m; 159 181 } 182 183 160 184 /* ------------------------------------------------------------------------------------------------------------------ */ 161 185 uint32 ui32MinNonNul9(uint32 a0, uint32 a1, uint32 a2, uint32 a3, uint32 a4, uint32 a5, uint32 a6, uint32 a7, uint32 a8) … … 176 200 return m; 177 201 } 202 203 178 204 /* ---------------------------------------------------------------------------------------------------------------------- */ 179 205 uint32 ui32MinNonNul9Cond(uint32 a0, uint32 a1, uint32 a2, uint32 a3, uint32 a4, uint32 a5, uint32 a6, uint32 a7, uint32 a8) … … 190 216 return m; 191 217 } 192 // -------------------------------- 193 void initT(uint32 *T, uint32 nemax) 194 // -------------------------------- 218 219 220 // --------------------------------- 221 void initT(uint32 * T, uint32 nemax) 222 // --------------------------------- 195 223 { 196 224 int i; … … 199 227 } 200 228 } 229 230 201 231 /* -------------------------- */ 202 232 //void initA(uint32 *A, uint32 nemax) … … 208 238 } 209 239 }*/ 240 241 210 242 // -------------------------------- 211 243 void initZ(uint32 *T, uint32 nemax) … … 217 249 } 218 250 } 251 252 219 253 // -------------------------------------- 220 254 void check_initT(uint32 *T, uint32 nemax) … … 223 257 check_initT_range(T, 0, nemax, nemax); 224 258 } 259 260 225 261 // -------------------------------------- 226 262 void check_initZ(uint32 *T, uint32 nemax) … … 229 265 check_initZ_range(T, 0, nemax, nemax); 230 266 } 267 268 231 269 // --------------------------------------------------------------- 232 270 void check_initT_range(uint32 *T, uint32 i0, uint32 ii, uint32 i1) … … 243 281 } 244 282 } 283 284 245 285 // --------------------------------------------------------------- 246 286 void check_initR_range(uint32 *R, uint32 i0, uint32 ii, uint32 i1) … … 257 297 } 258 298 } 299 300 259 301 // --------------------------------------------------------------- 260 302 void check_initZ_range(uint32 *T, uint32 i0, uint32 ii, uint32 i1) … … 271 313 } 272 314 } 315 316 273 317 /* --------------------------------------------------------------------------------------------------- */ 274 318 void binarisation_ui8matrix(uint8 **X, int i0, int i1, int j0, int j1, uint8 seuil, uint8 val, uint8 **Y) … … 309 353 } 310 354 } 311 /* ------------------------------------------------------------------------------- */ 312 void graphviz_write_ui8vector(uint8 *v, int i0, int i1, char *format, char *filename) 313 /* ------------------------------------------------------------------------------- */ 314 { 315 int i; 355 /* ---------------------------------------------------------------------------------- */ 356 void graphviz_write_ui8vector(uint8 * v, int i0, int i1, char * format, char * filename) 357 /* ---------------------------------------------------------------------------------- */ 358 { 359 int i; 360 char complete_filename[64]; 361 362 snprintf(complete_filename, 64, "%s.dot", filename); 363 364 #if TARGET_OS == GIETVM 316 365 int fd; 317 char complete_filename[64];318 319 snprintf(complete_filename, 64, "%s.dot", filename);320 321 366 fd = open(complete_filename, O_CREAT | O_TRUNC); 322 //if(f == NULL) { nrerror("Can't open file in grawrite_bvector"); }323 367 324 368 fprintf(fd, "digraph %s {\n", filename); … … 328 372 fprintf(fd, "}\n"); 329 373 close(fd); 330 } 331 /* --------------------------------------------------------------------------------- */ 332 void graphviz_write_ui16vector(uint16 *v, int i0, int i1, char *format, char *filename) 333 /* --------------------------------------------------------------------------------- */ 334 { 335 int i; 374 #elif TARGET_OS == LINUX 375 FILE * f; 376 f = fopen(complete_filename, "w"); 377 if (f == NULL) { 378 fprintf(stderr, "Can't open file %s in %s\n", complete_filename, __func__); 379 } 380 381 fprintf(f, "digraph %s {\n", filename); 382 for (i = i0; i <= i1; i++) { 383 fprintf(f, "%3d -> %3d;\n", i, v[i]); 384 } 385 fprintf(f, "}\n"); 386 fclose(f); 387 #endif 388 } 389 /* ------------------------------------------------------------------------------------ */ 390 void graphviz_write_ui16vector(uint16 * v, int i0, int i1, char * format, char * filename) 391 /* ------------------------------------------------------------------------------------ */ 392 { 393 int i; 394 char complete_filename[64]; 395 396 snprintf(complete_filename, 64, "%s.dot", filename); 397 398 #if TARGET_OS == GIETVM 336 399 int fd; 337 char complete_filename[64];338 339 snprintf(complete_filename, 64, "%s.dot", filename);340 341 342 400 fd = open(complete_filename, O_CREAT | O_TRUNC); 343 //if(f == NULL) { nrerror("Can't open file in grawrite_bvector"); }344 401 345 402 fprintf(fd, "digraph %s {\n", filename); … … 349 406 fprintf(fd, "}\n"); 350 407 close(fd); 351 } 352 /* --------------------------------------------------------------------------------- */ 353 void graphviz_write_ui32vector(uint32 *v, int i0, int i1, char *format, char *filename) 354 /* --------------------------------------------------------------------------------- */ 355 { 356 int i; 408 #elif TARGET_OS == LINUX 409 FILE * f; 410 f = fopen(complete_filename, "w"); 411 if (f == NULL) { 412 fprintf(stderr, "Can't open file %s in %s\n", complete_filename, __func__); 413 } 414 415 fprintf(f, "digraph %s {\n", filename); 416 for (i = i0; i <= i1; i++) { 417 fprintf(f, "%3d -> %3d;\n", i, v[i]); 418 } 419 fprintf(f, "}\n"); 420 fclose(f); 421 #endif 422 } 423 424 425 /* ------------------------------------------------------------------------------------ */ 426 void graphviz_write_ui32vector(uint32 * v, int i0, int i1, char * format, char * filename) 427 /* ------------------------------------------------------------------------------------ */ 428 { 429 int i; 430 char complete_filename[64]; 431 432 snprintf(complete_filename, 64, "%s.dot", filename); 433 434 #if TARGET_OS == GIETVM 357 435 int fd; 358 char complete_filename[64];359 360 snprintf(complete_filename, 64, "%s.dot", filename);361 362 363 436 fd = open(complete_filename, O_CREAT | O_TRUNC); 364 //if(f == NULL) { nrerror("Can't open file in grawrite_bvector"); }365 437 366 438 fprintf(fd, "digraph %s {\n", filename); … … 370 442 fprintf(fd, "}\n"); 371 443 close(fd); 372 } 373 /* ------------------------------------------------------------------------------ */ 374 void mod_ui32matrix_ui8matrix(uint32 **X, int i0, int i1, int j0, int j1, uint8 **Y) 375 /* ------------------------------------------------------------------------------ */ 444 #elif TARGET_OS == LINUX 445 FILE * f; 446 f = fopen(complete_filename, "w"); 447 if (f == NULL) { 448 fprintf(stderr, "Can't open file %s in %s\n", complete_filename, __func__); 449 } 450 451 fprintf(f, "digraph %s {\n", filename); 452 for (i = i0; i <= i1; i++) { 453 fprintf(f, "%3d -> %3d;\n", i, v[i]); 454 } 455 fprintf(f, "}\n"); 456 fclose(f); 457 #endif 458 } 459 460 461 /* -------------------------------------------------------------------------------- */ 462 void mod_ui32matrix_ui8matrix(uint32 ** X, int i0, int i1, int j0, int j1, uint8 ** Y) 463 /* -------------------------------------------------------------------------------- */ 376 464 { 377 465 int i, j; … … 382 470 } 383 471 } 384 // ------------------------------------------------------------------------------------------ 385 void positive_mod_ui32matrix_ui8matrix(uint32 **X, int i0, int i1, int j0, int j1, uint8 **Y) 386 // ------------------------------------------------------------------------------------------ 472 473 474 // -------------------------------------------------------------------------------------------- 475 void positive_mod_ui32matrix_ui8matrix(uint32 ** X, int i0, int i1, int j0, int j1, uint8 ** Y) 476 // -------------------------------------------------------------------------------------------- 387 477 { 388 478 int i, j; … … 392 482 if (X[i][j] < 255) { 393 483 Y[i][j] = X[i][j]; // pour que e=1 reste rouge 394 } else { 484 } 485 else { 395 486 Y[i][j] = (X[i][j] % 254) + 1; 396 487 } 397 } else { 488 } 489 else { 398 490 Y[i][j] = 0; 399 491 } … … 402 494 } 403 495 } 404 /* --------------------------------------------------------------------------------- */ 405 void graphviz_write_ui32vector_par(uint32 *v, int i0, int i1, char *format, char *filename) 406 /* --------------------------------------------------------------------------------- */ 407 { 408 int i; 496 497 498 /* ---------------------------------------------------------------------------------------- */ 499 void graphviz_write_ui32vector_par(uint32 * v, int i0, int i1, char * format, char * filename) 500 /* ---------------------------------------------------------------------------------------- */ 501 { 502 int i; 503 char complete_filename[64]; 504 505 snprintf(complete_filename, 64, "%s.dot", filename); 506 507 #if TARGET_OS == GIETVM 409 508 int fd; 410 char complete_filename[64];411 412 snprintf(complete_filename, 64, "%s.dot", filename);413 414 415 509 fd = open(complete_filename, O_CREAT | O_TRUNC); 416 //if(f == NULL) { nrerror("Can't open file in grawrite_bvector"); }417 510 418 511 fprintf(fd, "digraph %s {\n", filename); … … 422 515 fprintf(fd, "}\n"); 423 516 close(fd); 424 } 517 #else 518 FILE * f; 519 f = fopen(complete_filename, "w"); 520 if (f == NULL) { 521 fprintf(stderr, "Can't open file %s in %s\n", complete_filename, __func__); 522 } 523 fprintf(f, "digraph %s {\n", filename); 524 for (i = i0; i <= i1; i++) { 525 fprintf(f, "%3d -> %3d;\n", i, v[i]); 526 } 527 fprintf(f, "}\n"); 528 fclose(f); 529 #endif 530 } 531 532 425 533 // -------------------------------------- 426 534 uint32 mt19937_uint32(uint32 a, uint32 b) … … 431 539 uint32 x32; 432 540 433 if (b < a) return mt19937_uint32(b, a); 541 if (b < a) { 542 return mt19937_uint32(b, a); 543 } 434 544 435 545 //printf("a = %u b = %u\n", a, b); … … 441 551 return x32; 442 552 } 443 // ----------------------- 444 BOOL strto_Bool(char *str) 445 // ----------------------- 446 { 447 BOOL b = TRUE; 448 if (strcmp(str, "TRUE" ) == 0) b = TRUE; 449 if (strcmp(str, "true" ) == 0) b = TRUE; 450 451 if (strcmp(str, "FALSE") == 0) b = FALSE; 452 if (strcmp(str, "false") == 0) b = FALSE; 553 554 555 // ------------------------ 556 bool strto_Bool(char * str) 557 // ------------------------ 558 { 559 bool b = true; 560 if (strcmp(str, "TRUE" ) == 0) b = true; 561 if (strcmp(str, "true" ) == 0) b = true; 562 563 if (strcmp(str, "FALSE") == 0) b = false; 564 if (strcmp(str, "false") == 0) b = false; 453 565 454 566 return b; 455 567 } 456 // ------------------------------------------------------------ 457 void check_no_write(uint32 **T, int i0, int i1, int j0, int j1) 458 // ------------------------------------------------------------ 568 569 570 // ------------------------------------------------------------- 571 void check_no_write(uint32 ** T, int i0, int i1, int j0, int j1) 572 // ------------------------------------------------------------- 459 573 { 460 574 int i, j; … … 467 581 } 468 582 } 583 584 -
soft/giet_vm/applications/rosenfeld/src/ecc_features.c
r798 r821 10 10 // Caracteristiques d'une region / label 11 11 12 //#pragma message("------------------")13 //#pragma message("--- Features.c ---")14 //#pragma message("------------------")15 16 12 #include <stdio.h> 17 13 #include <stddef.h> 18 14 #include <stdlib.h> 19 15 #include <malloc.h> 20 21 22 #ifdef CLI 16 #include <string.h> 17 18 23 19 #include "nrc_os_config.h" 20 #include "config.h" 24 21 #include "nrc.h" 25 #endif26 27 22 28 23 … … 31 26 #include <sys/stat.h> 32 27 #include <fcntl.h> 28 #include <unistd.h> 33 29 #endif 34 30 35 31 36 #ifdef OPENMP37 #include <omp.h>38 #endif39 40 32 #include "ecc_features.h" 41 //#include "label.h" 33 34 #define BUFF_SIZE 1024 // for snprintf 35 36 37 // ------------------------------------------------------------- 38 void RegionStats_Constructor(RegionStats ** Stats, uint32 nemax) 39 // ------------------------------------------------------------- 40 { 41 *Stats = RegionStats_pConstructor(nemax); 42 } 43 44 45 // ------------------------------------------------- 46 RegionStats * RegionStats_pConstructor(uint32 nemax) 47 // ------------------------------------------------- 48 { 49 RegionStats * Stats; 50 51 Stats = (RegionStats *) malloc((nemax) * sizeof(RegionStats)); 52 if (Stats == NULL) { 53 nrerror("allocation failed in RegionStats_pConstructor"); 54 } 55 56 RegionStats_Clear(Stats, nemax); 57 58 return Stats; 59 } 60 42 61 43 62 // ------------------------------------------------------------ 44 void RegionStats_ Constructor(RegionStats **Stats, uint32 nemax)63 void RegionStats_Destructor(RegionStats ** Stats, uint32 nemax) 45 64 // ------------------------------------------------------------ 46 65 { 47 *Stats = RegionStats_pConstructor(nemax);48 }49 // ------------------------------------------------50 RegionStats* RegionStats_pConstructor(uint32 nemax)51 // ------------------------------------------------52 {53 RegionStats *Stats;54 55 Stats = (RegionStats*) malloc((nemax)*sizeof(RegionStats));56 if(Stats == NULL) nrerror("allocation failed in RegionStats_pConstructor");57 58 RegionStats_Clear(Stats, nemax);59 60 return Stats;61 }62 // -----------------------------------------------------------63 void RegionStats_Destructor(RegionStats **Stats, uint32 nemax)64 // -----------------------------------------------------------65 {66 66 RegionStats_pDestructor(*Stats, nemax); 67 67 } 68 // ----------------------------------------------------------- 69 void RegionStats_pDestructor(RegionStats *Stats, uint32 nemax) 70 // ----------------------------------------------------------- 68 69 70 // ------------------------------------------------------------ 71 void RegionStats_pDestructor(RegionStats * Stats, uint32 nemax) 72 // ------------------------------------------------------------ 71 73 { 72 74 RegionStats_Clear(Stats, nemax); 73 75 free(Stats); 74 76 } 75 // ----------------------------------------------------- 76 void RegionStats_Clear(RegionStats *Stats, uint32 nemax) 77 // ----------------------------------------------------- 78 { 79 int i; 80 for (i = 0; i < (int) nemax; i++) { 77 78 79 // ------------------------------------------------------ 80 void RegionStats_Clear(RegionStats * Stats, uint32 nemax) 81 // ------------------------------------------------------ 82 { 83 for (int i = 0; i < (int) nemax; i++) { 81 84 Stats[i].xmin = 65535; 82 85 Stats[i].xmax = 0; … … 86 89 Stats[i].S = 0; 87 90 88 Stats[i].x = 0;89 Stats[i].y = 0;90 91 91 Stats[i].Sx = 0; 92 92 Stats[i].Sy = 0; 93 94 #ifdef REGION_STATS2 95 Stats[i].Sx2 = 0; 96 Stats[i].Sxy = 0; 97 Stats[i].Sy2 = 0; 93 #if PARMERGE 94 pthread_spin_init(&Stats[i].lock, PTHREAD_PROCESS_PRIVATE); 98 95 #endif 99 96 } 100 97 } 101 // ---------------------------------------- 102 void RegionStats_Clear1(RegionStats *stats) 103 // ---------------------------------------- 98 99 100 // ----------------------------------------- 101 void RegionStats_Clear1(RegionStats * stats) 102 // ----------------------------------------- 104 103 { 105 104 stats->xmin = 0; … … 110 109 stats->S = 0; 111 110 112 stats->x = 0;113 stats->y = 0;114 115 111 stats->Sx = 0; 116 112 stats->Sy = 0; 117 #ifdef REGION_STATS2 118 stats->Sx2 = 0; 119 stats->Sxy = 0; 120 stats->Sy2 = 0; 121 #endif 122 } 123 // ------------------------------------------ 124 int RegionStats_Create_File(char *filename) 125 // ------------------------------------------ 113 } 114 115 116 // ----------------------------------------- 117 int RegionStats_Create_File(char * filename) 118 // ----------------------------------------- 126 119 { 127 120 int fd; … … 130 123 if (fd < 0) { 131 124 printf("RegionStats_Open_File : can't create file %s\n", filename); 132 giet_pthread_exit("");125 exit(1); 133 126 } 134 127 return fd; 135 128 } 136 // ---------------------------------------- 137 int RegionStats_Open_File(char *filename) 138 // ---------------------------------------- 129 130 131 // --------------------------------------- 132 int RegionStats_Open_File(char * filename) 133 // --------------------------------------- 139 134 { 140 135 int fd; … … 143 138 if (fd < 0) { 144 139 printf("RegionStats_Open_File : can't open file %s\n", filename); 145 giet_pthread_exit("");140 exit(1); 146 141 } 147 142 return fd; 148 143 } 149 // --------------------------------- 144 145 146 // -------------------------------- 150 147 void RegionStats_Close_File(int fd) 151 // -------------------------------- -148 // -------------------------------- 152 149 { 153 150 close(fd); 154 151 } 155 // --------------------------------- 152 153 154 #if 0 // pb : fscanf requires manipulating FILE * 155 // -------------------------------- 156 156 int RegionStats_Read_Header(int fd) 157 // -------------------------------- -157 // -------------------------------- 158 158 { 159 159 int ne = 0; 160 // @QM giet161 160 fscanf(fd, "%d", &ne); 162 161 return ne; 163 162 } 164 // ------------------------------------------- 163 #endif 164 165 166 // ------------------------------------------ 165 167 void RegionStats_Write_Header(int ne, int fd) 166 // ------------------------------------------- 167 { 168 fprintf(fd, "%d\n", ne); 169 } 168 // ------------------------------------------ 169 { 170 char buff[BUFF_SIZE]; 171 snprintf(buff, BUFF_SIZE, "%d\n", ne); 172 write(fd, buff, strlen(buff) + 1); 173 } 174 175 176 #if 0 170 177 // -------------------------------------------------------------- 171 void RegionStats_Read_Stats1(int fd, int ne, RegionStats * Stats)178 void RegionStats_Read_Stats1(int fd, int ne, RegionStats * Stats) 172 179 // -------------------------------------------------------------- 173 180 { … … 184 191 &(Stats[i].Sx), 185 192 &(Stats[i].Sy)); 186 187 Stats[i].x = Stats[i].Sx / Stats[i].S; 188 Stats[i].y = Stats[i].Sy / Stats[i].S; 189 190 } 191 } 192 // -------------------------------------------------------------- 193 void RegionStats_Read_Stats2(int fd, int ne, RegionStats *Stats) 194 // -------------------------------------------------------------- 195 { 196 #ifdef REGION_STATS2 197 int i, t; 198 199 int32 Sx2, Sxy, Sy2; 200 201 for (i = 1; i <= ne; i++) { 202 fscanf(f, "%d%d%d%d%d%d%d%d%d%d%d\n", 203 &t, 204 &(Stats[i].xmin), 205 &(Stats[i].xmax), 206 &(Stats[i].ymin), 207 &(Stats[i].ymax), 208 &(Stats[i].S), 209 &(Stats[i].Sx), 210 &(Stats[i].Sy), 211 &(Sx2), 212 &(Sxy), 213 &(Sy2)); 214 215 Stats[i].Sx2 = Sx2; 216 Stats[i].Sxy = Sxy; 217 Stats[i].Sy2 = Sy2; 218 219 Stats[i].x = Stats[i].Sx / Stats[i].S; 220 Stats[i].y = Stats[i].Sy / Stats[i].S; 221 } 222 #else 223 nrerror("RegionStats_Read_Stats2 REGION_STAT2 not defined"); 193 } 194 } 224 195 #endif 225 } 196 197 226 198 // --------------------------------------------------------------- 227 void RegionStats_Write_Stats1(RegionStats * Stats, int ne, int fd)199 void RegionStats_Write_Stats1(RegionStats * Stats, int ne, int fd) 228 200 // --------------------------------------------------------------- 229 201 { 230 int i;231 232 for (i = 1; i <= ne; i++) {233 fprintf(fd, "%4d %5d %5d %5d %5d %7d %8d %8d\n",202 char buff[BUFF_SIZE]; 203 204 for (int i = 1; i <= ne; i++) { 205 snprintf(buff, BUFF_SIZE, "%4d %5d %5d %5d %5d %7d %8d %8d\n", 234 206 i, 235 207 Stats[i].xmin, … … 241 213 Stats[i].Sx, 242 214 Stats[i].Sy); 243 } 244 } 245 // -------------------------------------------------------------------------------------------------- 246 void RegionStats_Write_Stats1_Sparse(RegionStats *Stats, uint32 *EQ, uint32 ne0, uint32 ne1, int fd) 247 // -------------------------------------------------------------------------------------------------- 215 write(fd, buff, strlen(buff) + 1); 216 } 217 } 218 219 220 // --------------------------------------------------------------------------------------------------- 221 void RegionStats_Write_Stats1_Sparse(RegionStats * Stats, uint32 * EQ, uint32 ne0, uint32 ne1, int fd) 222 // --------------------------------------------------------------------------------------------------- 248 223 { 249 224 uint32 e; 225 char buff[BUFF_SIZE]; 250 226 251 227 for (e = ne0; e <= ne1; e++) { 252 228 if ((e == EQ[e]) && (Stats[e].S > 0)) { 253 fprintf(fd, "%4d %5d %5d %5d %5d %7d %8d %8d\n",229 snprintf(buff, BUFF_SIZE, "%4d %5d %5d %5d %5d %7d %8d %8d\n", 254 230 e, 255 231 Stats[e].xmin, … … 261 237 Stats[e].Sx, 262 238 Stats[e].Sy); 263 } 264 } 265 } 266 // --------------------------------------------------------------- 267 void RegionStats_Write_Stats2(RegionStats *Stats, int ne, int fd) 268 // --------------------------------------------------------------- 269 { 270 #ifdef REGION_STATS2 271 int i; 272 for (i = 1; i <= ne; i++) { 273 fprintf(fd, "%4d %4d %4d %4d %6d %8d %8d %8d %8d %8d\n", 274 i, 275 Stats[i].xmin, 276 Stats[i].xmax, 277 Stats[i].ymin, 278 Stats[i].ymax, 279 280 Stats[i].S, 281 Stats[i].Sx, 282 Stats[i].Sy, 283 284 (int32) Stats[i].Sx2, 285 (int32) Stats[i].Sxy, 286 (int32) Stats[i].Sy2); 287 } 288 #else 289 nrerror("RegionStats_Write_Stats2: REGION_STATS2 not defined"); 290 #endif 291 } 239 write(fd, buff, strlen(buff) + 1); 240 } 241 } 242 } 243 244 292 245 // ----------------------------------------------------------------- 293 void RegionStats_Write_pStats1(RegionStats ** Stats, int ne, int fd)246 void RegionStats_Write_pStats1(RegionStats ** Stats, int ne, int fd) 294 247 // ----------------------------------------------------------------- 295 248 { 296 int i;297 298 for (i = 1; i <= ne; i++) {299 fprintf(fd, "%4d %5d %5d %5d %5d %7d %8d %8d\n",249 char buff[BUFF_SIZE]; 250 251 for (int i = 1; i <= ne; i++) { 252 snprintf(buff, BUFF_SIZE, "%4d %5d %5d %5d %5d %7d %8d %8d\n", 300 253 i, 301 254 Stats[i]->xmin, … … 306 259 Stats[i]->Sx, 307 260 Stats[i]->Sy); 308 } 309 } 310 // ----------------------------------------------------------------- 311 void RegionStats_Write_pStats2(RegionStats **Stats, int ne, int fd) 312 // ----------------------------------------------------------------- 313 { 314 #ifdef REGION_STATS2 315 int i; 316 for (i = 1; i <= ne; i++) { 317 fprintf(fd, "%3d %4d %4d %4d %4d %6d %8d %8d %8d %8d %8d\n", 318 i, 319 Stats[i]->xmin, 320 Stats[i]->xmax, 321 Stats[i]->ymin, 322 Stats[i]->ymax, 323 Stats[i]->S, 324 Stats[i]->Sx, 325 Stats[i]->Sy, 326 327 (int32) Stats[i]->Sx2, 328 (int32) Stats[i]->Sxy, 329 (int32) Stats[i]->Sy2); 330 } 331 #else 332 nrerror("RegionStats_Write_Stats2: REGION_STATS2 not defined"); 333 #endif 334 } 335 // ----------------------------------------------------------------------- 336 void RegionStats_Load_Stats1(char *filename, int *ne, RegionStats **Stats) 337 // ----------------------------------------------------------------------- 261 write(fd, buff, strlen(buff) + 1); 262 } 263 } 264 265 266 #if 0 267 // -------------------------------------------------------------------------- 268 void RegionStats_Load_Stats1(char * filename, int * ne, RegionStats ** Stats) 269 // -------------------------------------------------------------------------- 338 270 { 339 271 int fd; … … 347 279 RegionStats_Close_File(fd); 348 280 } 349 // ----------------------------------------------------------------------- 350 void RegionStats_Load_Stats2(char *filename, int *ne, RegionStats **Stats) 351 // ----------------------------------------------------------------------- 352 { 353 #ifdef REGION_STATS2 354 int fd; 355 356 fd = RegionStats_Open_File(filename); 357 358 *ne = RegionStats_Read_Header(fd); 359 360 RegionStats_Constructor(Stats, *ne); 361 RegionStats_Read_Stats2(fd, *ne, *Stats); 362 RegionStats_Close_File(fd); 363 #else 364 nrerror("RegionStats_Load_Stats2 : REGION_STATS2 not defined"); 365 #endif 366 } 367 // ----------------------------------------------------------------------- 368 void RegionStats_MLoad_Stats1(char *filename, int *ne, RegionStats *Stats) 369 // ----------------------------------------------------------------------- 281 282 283 // -------------------------------------------------------------------------- 284 void RegionStats_MLoad_Stats1(char * filename, int * ne, RegionStats * Stats) 285 // -------------------------------------------------------------------------- 370 286 { 371 287 int fd; … … 377 293 RegionStats_Close_File(fd); 378 294 } 295 #endif 296 379 297 // ----------------------------------------------------------------------- 380 void RegionStats_ MLoad_Stats2(char *filename, int *ne, RegionStats *Stats)298 void RegionStats_Save_Stats1(RegionStats * Stats, int ne, char * filename) 381 299 // ----------------------------------------------------------------------- 382 {383 #ifdef REGION_STATS2384 int fd385 386 fd = RegionStats_Open_File(filename);387 388 *ne = RegionStats_Read_Header(fd);389 RegionStats_Read_Stats2(fd, *ne, Stats);390 RegionStats_Close_File(fd);391 #else392 nrerror("RegionStats_MLoad_Stats2 : REGION_STATS2 not defined");393 #endif394 }395 // ---------------------------------------------------------------------396 void RegionStats_Save_Stats1(RegionStats *Stats, int ne, char *filename)397 // ---------------------------------------------------------------------398 300 { 399 301 int fd; … … 405 307 RegionStats_Close_File(fd); 406 308 } 407 // --------------------------------------------------------------------- 408 void RegionStats_Save_Stats2(RegionStats *Stats, int ne, char *filename) 409 // --------------------------------------------------------------------- 410 { 411 #ifdef REGION_STATS2 412 int fd; 413 414 fd = RegionStats_Create_File(filename); 415 416 RegionStats_Write_Header(ne, fd); 417 RegionStats_Write_Stats2(Stats, ne, fd); 418 RegionStats_Close_File(fd); 419 #else 420 nrerror("RegionStats_Save_Stats2 : REGION_STATS2 not defined"); 421 #endif 422 } 423 // ----------------------------------------------------------------------- 424 void RegionStats_Save_pStats1(RegionStats **Stats, int ne, char *filename) 425 // ----------------------------------------------------------------------- 309 310 311 // ------------------------------------------------------------------------- 312 void RegionStats_Save_pStats1(RegionStats ** Stats, int ne, char * filename) 313 // ------------------------------------------------------------------------- 426 314 { 427 315 int fd; … … 433 321 RegionStats_Close_File(fd); 434 322 } 435 // ----------------------------------------------------------------------- 436 void RegionStats_Save_pStats2(RegionStats **Stats, int ne, char *filename) 437 // ----------------------------------------------------------------------- 438 { 439 #ifdef REGION_STATS2 440 int fd; 441 442 fd = RegionStats_Create_File(filename); 443 444 RegionStats_Write_Header(ne, fd); 445 RegionStats_Write_pStats2(Stats, ne, fd); 446 RegionStats_Close_File(fd); 447 #else 448 nrerror("RegionStats_Save_Stats2 : REGION_STATS2 not defined"); 449 #endif 450 } 451 // -------------------------------------------------------------------- 452 void RegionStats_Display_Stats1(RegionStats *Stats, int ne, char *name) 453 // -------------------------------------------------------------------- 454 { 455 int i; 456 323 324 325 // ---------------------------------------------------------------------- 326 void RegionStats_Display_Stats1(RegionStats * Stats, int ne, char * name) 327 // ---------------------------------------------------------------------- 328 { 457 329 if (name != NULL) { 458 330 printf("%s : %d\n", name, ne); … … 461 333 printf("RegionStats : %d\n", ne); 462 334 } 463 for (i = 1; i <= ne; i++) {335 for (int i = 1; i <= ne; i++) { 464 336 printf("#%3d: %4d %4d %4d %4d %6d %8d %8d\n", 465 337 i, … … 473 345 } 474 346 } 475 // -------------------------------------------------------------------- 476 void RegionStats_Display_Stats2(RegionStats *Stats, int ne, char *name) 477 // -------------------------------------------------------------------- 478 { 479 #ifdef REGION_STATS2 480 int i; 481 347 348 349 // ------------------------------------------------------------------------ 350 void RegionStats_Display_pStats1(RegionStats ** Stats, int ne, char * name) 351 // ------------------------------------------------------------------------ 352 { 482 353 if (name != NULL) { 483 354 printf("%s : %d\n", name, ne); … … 486 357 printf("RegionStats : %d\n", ne); 487 358 } 488 489 for (i = 1; i <= ne; i++) { 490 printf("#%3d: %4d %4d %4d %4d %6d %8d %8d %8d %8d %8d\n", 491 i, 492 Stats[i].xmin, 493 Stats[i].xmax, 494 Stats[i].ymin, 495 Stats[i].ymax, 496 Stats[i].S, 497 Stats[i].Sx, 498 Stats[i].Sy, 499 500 (int32) Stats[i].Sx2, 501 (int32) Stats[i].Sxy, 502 (int32) Stats[i].Sy2); 503 504 } 505 #else 506 nrerror("RegionStats_Display_Stats2 : REGION_STATS2 not defined"); 507 #endif 508 } 509 // ---------------------------------------------------------------------- 510 void RegionStats_Display_pStats1(RegionStats **Stats, int ne, char *name) 511 // ---------------------------------------------------------------------- 512 { 513 int i; 514 515 if (name != NULL) { 516 printf("%s : %d\n", name, ne); 517 } 518 else { 519 printf("RegionStats : %d\n", ne); 520 } 521 for (i = 1; i <= ne; i++) { 359 for (int i = 1; i <= ne; i++) { 522 360 printf("#%3d: %4d %4d %4d %4d %6d %8d %8d\n", 523 361 i, … … 531 369 } 532 370 } 533 // ---------------------------------------------------------------------- 534 void RegionStats_Display_pStats2(RegionStats **Stats, int ne, char *name) 535 // ---------------------------------------------------------------------- 536 { 537 #ifdef REGION_STATS2 538 int i; 539 540 if (name != NULL) { 541 printf("%s : %d\n", name, ne); 542 } 543 else { 544 printf("RegionStats : %d\n", ne); 545 } 546 for (i = 1; i <= ne; i++) { 547 printf("#%3d: %4d %4d %4d %4d %6d %8d %8d %8d %8d %8d\n", 548 i, 549 Stats[i]->xmin, 550 Stats[i]->xmax, 551 Stats[i]->ymin, 552 Stats[i]->ymax, 553 Stats[i]->S, 554 Stats[i]->Sx, 555 Stats[i]->Sy, 556 557 (int32) Stats[i]->Sx2, 558 (int32) Stats[i]->Sxy, 559 (int32) Stats[i]->Sy2); 560 561 } 562 #else 563 nrerror("RegionStats_Display_Stats2 : REGION_STATS2 not defined"); 564 #endif 565 } 566 // --------------------------------------------------------------------------------------------- 567 void RegionStats_SetRectangle(RegionStats *Stats, int e, int ymin, int ymax, int xmin, int xmax) 568 // --------------------------------------------------------------------------------------------- 371 372 373 // ---------------------------------------------------------------------------------------------- 374 void RegionStats_SetRectangle(RegionStats * Stats, int e, int ymin, int ymax, int xmin, int xmax) 375 // ---------------------------------------------------------------------------------------------- 569 376 { 570 377 Stats[e].ymin = ymin; … … 573 380 Stats[e].xmax = xmax; 574 381 } 575 // ------------------------------------------------------- 576 void RegionStats_Copy1(RegionStats *src, RegionStats *dst) 577 // ------------------------------------------------------- 382 383 384 // --------------------------------------------------------- 385 void RegionStats_Copy1(RegionStats * src, RegionStats * dst) 386 // --------------------------------------------------------- 578 387 { 579 388 dst->xmin = src->xmin; … … 584 393 dst->S = src->S; 585 394 586 dst->x = src->x;587 dst->y = src->y;588 589 395 dst->Sx = src->Sx; 590 396 dst->Sy = src->Sy; 591 592 #ifdef REGION_STATS2 593 dst->Sx2 = src->Sx2; 594 dst->Sxy = src->Sxy; 595 dst->Sy2 = src->Sy2; 596 dst->teta = src->teta; 597 #endif 598 599 #ifdef REGION_STATS3 600 dst->Sx3 = src->Sx3; 601 dst->Sx2y = src->Sx2y; 602 dst->Sxy2 = src->Sxy2; 603 dst->Sy3 = src->Sy3; 604 605 dst->Mx2 = src->Mx2; 606 dst->Mxy = src->Mxy; 607 dst->My2 = src->My2; 608 609 dst->Mx3 = src->Mx3; 610 dst->Mx2y = src->Mx2y; 611 dst->Mxy2 = src->Mxy2; 612 dst->My3 = src->My3; 613 #endif 614 } 397 } 398 399 615 400 // =============================== 616 401 // === nouvelles versions 2009 === 617 402 // =============================== 618 403 619 // ------------------------------------------- 620 RegionStats * RegionStatsVector(int i0, int i1)621 // ------------------------------------------- 404 // -------------------------------------------- 405 RegionStats * RegionStatsVector(int i0, int i1) 406 // -------------------------------------------- 622 407 // allocate a float vector with subscript range v[i0..i1] 623 408 { … … 625 410 626 411 v = (RegionStats *) malloc((size_t) ((i1 - i0 + 1 + NR_END) * sizeof(RegionStats))); 627 if (!v) nrerror("allocation failure in RegionStatsVector()"); 628 if (!v) return NULL; 412 if (!v) { 413 nrerror("allocation failure in %s()", __func__); 414 return NULL; 415 } 416 RegionStats_Clear(v, i1 - i0 + 1 + NR_END); 629 417 return v - i0 + NR_END; 630 418 } 631 // ---------------------------------------------------------- 632 RegionStats* RegionStatsVector0(int i0, int i1) 633 // ---------------------------------------------------------- 419 420 421 #if TARGET_OS == GIETVM 422 // ----------------------------------------------------------------- 423 RegionStats * remote_RegionStatsVector(int i0, int i1, int x, int y) 424 // ----------------------------------------------------------------- 634 425 // allocate a float vector with subscript range v[i0..i1] 635 426 { 636 RegionStats *v; 427 RegionStats * v; 428 429 v = (RegionStats *) remote_malloc((size_t) ((i1 - i0 + 1 + NR_END) * sizeof(RegionStats)), x, y); 430 if (!v) { 431 nrerror("allocation failure in %s()", __func__); 432 return NULL; 433 } 434 RegionStats_Clear(v, i1 - i0 + 1 + NR_END); 435 return v - i0 + NR_END; 436 } 437 #endif 438 439 440 // --------------------------------------------- 441 RegionStats * RegionStatsVector0(int i0, int i1) 442 // --------------------------------------------- 443 // allocate a float vector with subscript range v[i0..i1] 444 { 445 RegionStats * v; 637 446 638 447 v = (RegionStats *) calloc((size_t) (i1 - i0 + 1 + NR_END), sizeof(RegionStats)); 639 if (!v) nrerror("allocation failure in RegionStatsVector0()"); 640 if (!v) return NULL; 448 if (!v) { 449 nrerror("allocation failure in RegionStatsVector0()"); 450 return NULL; 451 } 641 452 return v - i0 + NR_END; 642 453 } 643 // ---------------------------------------------------------------------- 644 void free_RegionStatsVector(RegionStats *v, int i0, int i1) 645 // ---------------------------------------------------------- 454 455 456 // --------------------------------------------------------- 457 void free_RegionStatsVector(RegionStats * v, int i0, int i1) 458 // --------------------------------------------------------- 646 459 // free a RegionStats vector allocated with vector() 647 460 { 648 free((FREE_ARG) (v + i0 - NR_END)); 649 } 650 // ------------------------------------------------------------ 651 RegionStats** RegionStatsMatrix(int i0, int i1, int j0, int j1) 652 // ------------------------------------------------------------ 461 free(v + i0 - NR_END); 462 } 463 464 465 // ------------------------------------------------------------- 466 RegionStats ** RegionStatsMatrix(int i0, int i1, int j0, int j1) 467 // ------------------------------------------------------------- 653 468 654 469 // allocate a RegionStats matrix with subscript range m[nrl..nrh][ncl..nch] 470 { 471 long nrow = i1 - i0 + 1; 472 long ncol = j1 - j0 + 1; 473 RegionStats ** m; 474 475 // allocate pointers to rows 476 m = (RegionStats **) malloc((size_t) ((nrow + NR_END) * sizeof(RegionStats *))); 477 if (!m) { 478 nrerror("allocation failure 1 in RegionStatsMatrix()"); 479 } 480 m += NR_END; 481 m -= i0; 482 483 // allocate rows and set pointers to them 484 m[i0] = (RegionStats *) malloc((size_t) ((nrow * ncol + NR_END) * sizeof(RegionStats))); 485 if (!m[i0]) { 486 nrerror("allocation failure 2 in RegionStatsMatrix()"); 487 } 488 m[i0] += NR_END; 489 m[i0] -= j0; 490 491 for (int i = i0 + 1; i <= i1; i++) { 492 m[i] = m[i - 1] + ncol; 493 } 494 495 // return pointer to array of pointers to rows 496 return m; 497 } 498 499 500 // -------------------------------------------------------------- 501 RegionStats ** RegionStatsMatrix0(int i0, int i1, int j0, int j1) 502 // -------------------------------------------------------------- 503 // allocate a float matrix with subscript range m[nrl..nrh][ncl..nch] 655 504 { 656 505 long i; 657 506 long nrow = i1 - i0 + 1; 658 507 long ncol = j1 - j0 + 1; 659 RegionStats ** m;508 RegionStats ** m; 660 509 661 510 // allocate pointers to rows 662 m = (RegionStats **) malloc((size_t) ((nrow + NR_END) * sizeof(RegionStats *))); 663 if (!m) nrerror("allocation failure 1 in RegionStatsMatrix()"); 511 m= (RegionStats **) malloc((size_t) ((nrow + NR_END) * sizeof(RegionStats*))); 512 if (!m) { 513 nrerror("allocation failure 1 in RegionStatsMatrix()"); 514 } 664 515 m += NR_END; 665 516 m -= i0; 666 517 667 518 // allocate rows and set pointers to them 668 m[i0] = (RegionStats *) malloc((size_t) ((nrow * ncol + NR_END) * sizeof(RegionStats))); 669 if (!m[i0]) nrerror("allocation failure 2 in RegionStatsMatrix()"); 519 m[i0] = (RegionStats *) calloc((size_t) (nrow * ncol + NR_END), sizeof(RegionStats)); 520 if (!m[i0]) { 521 nrerror("allocation failure 2 in RegionStatsMatrix()"); 522 } 670 523 m[i0] += NR_END; 671 524 m[i0] -= j0; 672 525 673 for (i = i0 + 1; i <= i1; i++) {526 for (i = i0 + 1; i <= i1; i++) { 674 527 m[i] = m[i - 1] + ncol; 675 528 } … … 678 531 return m; 679 532 } 680 // ------------------------------------------------------------- 681 RegionStats** RegionStatsMatrix0(int i0, int i1, int j0, int j1) 682 // ------------------------------------------------------------- 683 684 // allocate a float matrix with subscript range m[nrl..nrh][ncl..nch] 685 { 686 long i, nrow=i1-i0+1,ncol=j1-j0+1; 687 RegionStats **m; 688 689 // allocate pointers to rows 690 m=(RegionStats**) malloc((size_t)((nrow+NR_END)*sizeof(RegionStats*))); 691 if (!m) nrerror("allocation failure 1 in RegionStatsMatrix()"); 692 m += NR_END; 693 m -= i0; 694 695 // allocate rows and set pointers to them 696 m[i0]=(RegionStats*) calloc((size_t)(nrow*ncol+NR_END), sizeof(RegionStats)); 697 if (!m[i0]) nrerror("allocation failure 2 in RegionStatsMatrix()"); 698 m[i0] += NR_END; 699 m[i0] -= j0; 700 701 for(i=i0+1;i<=i1;i++) m[i]=m[i-1]+ncol; 702 703 // return pointer to array of pointers to rows 704 return m; 705 } 706 // ------------------------------------------------------------------------- 707 void free_RegionStatsMatrix(RegionStats **m, int i0, int i1, int j0, int j1) 708 // ------------------------------------------------------------------------- 709 { 710 free((FREE_ARG) (m[i0]+j0-NR_END)); 711 free((FREE_ARG) (m+i0-NR_END)); 712 } 713 // ---------------------------------- 714 void zero_RegionStats(RegionStats *x) 715 // ---------------------------------- 533 534 535 // -------------------------------------------------------------------------- 536 void free_RegionStatsMatrix(RegionStats ** m, int i0, int i1, int j0, int j1) 537 // -------------------------------------------------------------------------- 538 { 539 free(m[i0] + j0 - NR_END); 540 free(m + i0 - NR_END); 541 } 542 543 544 // ----------------------------------- 545 void zero_RegionStats(RegionStats * x) 546 // ----------------------------------- 716 547 { 717 548 x->xmin = 32767; … … 723 554 x->Sx = 0; 724 555 x->Sy = 0; 725 726 #ifdef REGION_STATS2 727 x->Sx2 = 0; 728 x->Sxy = 0; 729 x->Sy2 = 0; 730 #endif 731 } 732 // -------------------------------------------------------- 733 void zero_RegionStatsVector(RegionStats *v, int i0, int i1) 734 // -------------------------------------------------------- 735 { 736 int i; 737 for(i=i0; i<=i1; i++) { 556 } 557 558 559 // --------------------------------------------------------- 560 void zero_RegionStatsVector(RegionStats * v, int i0, int i1) 561 // --------------------------------------------------------- 562 { 563 for (int i = i0; i <= i1; i++) { 738 564 zero_RegionStats(&v[i]); 739 565 } 740 566 } 741 // ------------------------------------------------------------------------- 742 void zero_RegionStatsMatrix(RegionStats **m, int i0, int i1, int j0, int j1) 743 // ------------------------------------------------------------------------- 744 { 745 int i, j; 746 for(i=i0; i<=i1; i++) { 747 for(j=j0; j<=j1; j++) { 567 568 569 // -------------------------------------------------------------------------- 570 void zero_RegionStatsMatrix(RegionStats ** m, int i0, int i1, int j0, int j1) 571 // -------------------------------------------------------------------------- 572 { 573 for (int i = i0; i <= i1; i++) { 574 for (int j = j0; j <= j1; j++) { 748 575 zero_RegionStats(&(m[i][j])); 749 576 } 750 577 } 751 578 } 752 // ------------------------------------------------- 753 void display_RegionStats(RegionStats *x, char *name) 754 // ------------------------------------------------- 755 { 756 if(name != NULL) printf("%s : \n", name); 757 758 #ifndef REGION_STATS2 579 580 581 // --------------------------------------------------- 582 void display_RegionStats(RegionStats * x, char * name) 583 // --------------------------------------------------- 584 { 585 if (name != NULL) { 586 printf("%s : \n", name); 587 } 588 759 589 printf("%4d %4d %4d %4d %6d %8d %8d\n", 760 590 x->xmin, … … 766 596 x->Sx, 767 597 x->Sy); 768 #else 769 printf("%4d %4d %4d %4d %6d %8d %8d %8d %8d %8d\n", 770 x->xmin, 771 x->xmax, 772 x->ymin, 773 x->ymax, 774 775 x->S, 776 x->Sx, 777 x->Sy, 778 779 x->Sx2, 780 x->Sxy, 781 x->Sy2); 782 #endif 783 } 784 // ----------------------------------------------------------------------- 785 void display_RegionStatsVector(RegionStats *v, int i0, int i1, char *name) 786 // ----------------------------------------------------------------------- 787 { 788 int i; 789 790 if(name != NULL) printf("%s : [%d..%d]\n", name, i0, i1); else printf("RegionStats : [%d..%d]\n", i0, i1); 791 for(i=i0; i<=i1; i++) { 598 } 599 600 601 // ------------------------------------------------------------------------ 602 void display_RegionStatsVector(RegionStats * v, int i0, int i1, char *name) 603 // ------------------------------------------------------------------------ 604 { 605 if (name != NULL) { 606 printf("%s : [%d..%d]\n", name, i0, i1); 607 } 608 else { 609 printf("RegionStats : [%d..%d]\n", i0, i1); 610 } 611 for (int i = i0; i <= i1; i++) { 792 612 printf("#%3d: ", i); 793 613 display_RegionStats(&(v[i]), NULL); 794 //puts(""); 795 } 796 } 797 // ---------------------------------------------------------------------------------------- 798 void display_RegionStatsMatrix(RegionStats **m, int i0, int i1, int j0, int j1, char *name) 799 // ---------------------------------------------------------------------------------------- 800 { 801 int i, j; 802 803 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); 804 for (i = i0; i <= i1; i++) { 805 for (j = j0; j <= j1; j++) { 614 } 615 } 616 617 618 // ------------------------------------------------------------------------------------------ 619 void display_RegionStatsMatrix(RegionStats ** m, int i0, int i1, int j0, int j1, char * name) 620 // ------------------------------------------------------------------------------------------ 621 { 622 623 if (name != NULL) { 624 printf("%s : [%d..%d][%d..%d]\n", name, i0, i1, j0, j1); 625 } 626 else { 627 printf("RegionStats : [%d..%d][%d..%d]\n", i0, i1, j0, j1); 628 } 629 for (int i = i0; i <= i1; i++) { 630 for (int j = j0; j <= j1; j++) { 806 631 printf("#%3d: ", i); 807 632 display_RegionStats(&(m[i][j]), NULL); … … 809 634 } 810 635 } 811 // ---------------------------------------------- 812 void save_RegionStats(RegionStats *x, char *name) 813 // ---------------------------------------------- 636 637 638 // ------------------------------------------------ 639 void save_RegionStats(RegionStats * x, char * name) 640 // ------------------------------------------------ 814 641 { 815 642 int fd = -1; 643 char buff[BUFF_SIZE]; 816 644 817 645 if (name == NULL) { … … 824 652 printf("*** Erreur : ouverture du fichier %s dans %s\n", name, __func__); 825 653 } 826 fprintf(fd, "%s: ", name); 827 828 #ifndef REGION_STATS2 829 fprintf(fd, "%4d %4d %4d %4d %6d %8d %8d\n", 830 654 snprintf(buff, BUFF_SIZE, "%s: %4d %4d %4d %4d %6d %8d %8d\n", 655 name, 831 656 x->xmin, 832 657 x->xmax, … … 837 662 x->Sx, 838 663 x->Sy); 839 #else 840 fprintf(fd, "%4d %4d %4d %4d %6d %8d %8d %8d %8d %8d\n", 841 842 x->xmin, 843 x->xmax, 844 x->ymin, 845 x->ymax, 846 847 x->S, 848 x->Sx, 849 x->Sy, 850 851 x->Sx2, 852 x->Sxy, 853 x->Sy2); 854 #endif 664 write(fd, buff, strlen(buff) + 1); 855 665 856 666 if (name) { … … 858 668 } 859 669 } 860 // -------------------------------------------------------------------- 861 void save_RegionStatsVector(RegionStats *v, int i0, int i1, char *name) 862 // -------------------------------------------------------------------- 863 { 864 int i; 670 671 672 // ---------------------------------------------------------------------- 673 void save_RegionStatsVector(RegionStats * v, int i0, int i1, char * name) 674 // ---------------------------------------------------------------------- 675 { 865 676 int fd; 677 char buff[BUFF_SIZE]; 866 678 867 679 if (name == NULL) { … … 870 682 fd = RegionStats_Create_File(name); 871 683 872 fprintf(fd, "%s : [%d..%d]\n", name, i0, i1); 873 874 for (i = i0; i <= i1; i++) { 684 snprintf(buff, BUFF_SIZE, "%s : [%d..%d]\n", name, i0, i1); 685 write(fd, buff, strlen(buff) + 1); 686 687 for (int i = i0; i <= i1; i++) { 875 688 printf("#%3d: ", i); 876 689 save_RegionStats(&v[i], NULL); 877 printf("");878 690 } 879 691 RegionStats_Close_File(fd); 880 692 } 881 // ------------------------------------------------------------------------------------- 882 void save_RegionStatsMatrix(RegionStats **m, int i0, int i1, int j0, int j1, char *name) 883 // ------------------------------------------------------------------------------------- 884 { 885 int i, j; 693 694 695 // --------------------------------------------------------------------------------------- 696 void save_RegionStatsMatrix(RegionStats ** m, int i0, int i1, int j0, int j1, char * name) 697 // --------------------------------------------------------------------------------------- 698 { 886 699 int fd; 700 char buff[BUFF_SIZE]; 887 701 888 702 if (name == NULL) { … … 891 705 fd = RegionStats_Create_File(name); 892 706 893 fprintf(fd, "%s : [%d..%d]\n", name, i0, i1); 894 895 for (i = i0; i <= i1; i++) { 896 for (j = j0; j <= j1; j++) { 897 fprintf(fd, "#%3d: ", i); 707 snprintf(buff, BUFF_SIZE, "%s : [%d..%d]\n", name, i0, i1); 708 write(fd, buff, strlen(buff) + 1); 709 710 for (int i = i0; i <= i1; i++) { 711 for (int j = j0; j <= j1; j++) { 712 snprintf(buff, BUFF_SIZE, "#%3d: ", i); 713 write(fd, buff, strlen(buff) + 1); 898 714 save_RegionStats(&m[i][j], NULL); 899 715 } 900 printf("");901 716 } 902 717 RegionStats_Close_File(fd); 903 718 } 904 // ------------------------------------------------------------------------------ 905 void RegionStats_Calc1_Features_1Pass(RegionStats *Stats, uint32 e, int i, int j) 906 // ------------------------------------------------------------------------------ 719 720 721 // ------------------------------------------------------------------------------- 722 void RegionStats_Calc1_Features_1Pass(RegionStats * Stats, uint32 e, int i, int j) 723 // ------------------------------------------------------------------------------- 907 724 { 908 725 // calcul sur 1 point et non sur toute l'image 909 726 // Rectangle 910 727 911 if (i < Stats[e].ymin) Stats[e].ymin = i; 912 if (i > Stats[e].ymax) Stats[e].ymax = i; 913 914 if (j < Stats[e].xmin) Stats[e].xmin = j; 915 if (j > Stats[e].xmax) Stats[e].xmax = j; 728 if (i < Stats[e].ymin) { 729 Stats[e].ymin = i; 730 } 731 if (i > Stats[e].ymax) { 732 Stats[e].ymax = i; 733 } 734 735 if (j < Stats[e].xmin) { 736 Stats[e].xmin = j; 737 } 738 if (j > Stats[e].xmax) { 739 Stats[e].xmax = j; 740 } 916 741 917 742 // Moment1 … … 922 747 return; 923 748 } 749 750 924 751 // -------------------------------- 925 752 // --- fonctions de 2013 ---------- 926 753 // -------------------------------- 927 // ------------------------------------------------------------------------------------------- 928 void RegionStats_Calc_Rectangle_Moment1(uint32 **E, int height, int width, RegionStats *Stats) 929 // ------------------------------------------------------------------------------------------- 930 { 931 int i, j; 754 // --------------------------------------------------------------------------------------------- 755 void RegionStats_Calc_Rectangle_Moment1(uint32 ** E, int height, int width, RegionStats * Stats) 756 // --------------------------------------------------------------------------------------------- 757 { 932 758 uint32 x, y; 933 759 uint32 e; 934 760 935 for (i = 0; i < height; i++) {936 for ( j = 0; j < width; j++) {761 for (int i = 0; i < height; i++) { 762 for (int j = 0; j < width; j++) { 937 763 938 764 e = E[i][j]; 939 765 if (e) { 940 941 766 x = j; 942 767 y = i; 943 768 944 if (i<Stats[e].ymin) Stats[e].ymin = y; 945 if (i>Stats[e].ymax) Stats[e].ymax = y; 769 if (i < Stats[e].ymin) { 770 Stats[e].ymin = y; 771 } 772 if (i > Stats[e].ymax) { 773 Stats[e].ymax = y; 774 } 946 775 947 if (j<Stats[e].xmin) Stats[e].xmin = x; 948 if (j>Stats[e].xmax) Stats[e].xmax = x; 776 if (j < Stats[e].xmin) { 777 Stats[e].xmin = x; 778 } 779 if (j > Stats[e].xmax) { 780 Stats[e].xmax = x; 781 } 949 782 950 783 Stats[e].S += 1; … … 955 788 } 956 789 } 957 // ----------------------------------------------------------------------------------------------------------------------------- 958 void RegionStats_calc_Status(RegionStats *Stats, uint32 ne, uint32 min_height, uint32 min_width, uint32 min_area, uint8 *status) 959 // ----------------------------------------------------------------------------------------------------------------------------- 790 791 792 // ------------------------------------------------------------------------------------------------------------------------------- 793 void RegionStats_calc_Status(RegionStats * Stats, uint32 ne, uint32 min_height, uint32 min_width, uint32 min_area, uint8 * status) 794 // ------------------------------------------------------------------------------------------------------------------------------- 960 795 { 961 796 uint16 xmin, xmax, ymin, ymax, xsize, ysize; … … 983 818 } 984 819 } 985 // -------------------------------------------------------------------------- 986 uint32 RegionStats_UpdateEQ_with_Status(uint8 *status, uint32 ne, uint32 *EQ) 987 // -------------------------------------------------------------------------- 820 821 822 // ---------------------------------------------------------------------------- 823 uint32 RegionStats_UpdateEQ_with_Status(uint8 * status, uint32 ne, uint32 * EQ) 824 // ---------------------------------------------------------------------------- 988 825 { 989 826 uint32 e; … … 999 836 return na; 1000 837 } 1001 // ---------------------------------------------------------------------------- 1002 void RegionStats_UpdateStats_with_EQ(uint32 *EQ, uint32 ne, RegionStats *Stats) 1003 // ---------------------------------------------------------------------------- 838 839 840 // ------------------------------------------------------------------------------ 841 void RegionStats_UpdateStats_with_EQ(uint32 * EQ, uint32 ne, RegionStats * Stats) 842 // ------------------------------------------------------------------------------ 1004 843 { 1005 844 uint32 e, a; … … 1015 854 } 1016 855 } 1017 // --------------------------------------------------------------------------- 1018 void featuresComputation(uint32 **E, int height,int width, RegionStats *Stats) 1019 // --------------------------------------------------------------------------- 856 857 858 // ----------------------------------------------------------------------------- 859 void featuresComputation(uint32 ** E, int height,int width, RegionStats * Stats) 860 // ----------------------------------------------------------------------------- 1020 861 { 1021 862 //uint32 nemax = height * width /2; 1022 863 RegionStats_Calc_Rectangle_Moment1(E, height, width, Stats); 1023 864 } 1024 // ------------------------------------------------------------------------------ 1025 void pointFeaturesComputation_Dummy(uint32 **E, int i, int j, RegionStats *Stats) 1026 // ------------------------------------------------------------------------------ 1027 { 1028 // pour pointeur de fonction 1029 return; 1030 } 1031 // ------------------------------------------------------------------------- 1032 void pointFeaturesComputation( uint32 **E, int i, int j, RegionStats *Stats) 1033 // ------------------------------------------------------------------------- 865 866 867 // --------------------------------------------------------------------------- 868 void pointFeaturesComputation( uint32 ** E, int i, int j, RegionStats * Stats) 869 // --------------------------------------------------------------------------- 1034 870 { 1035 871 uint32 x, y; … … 1042 878 y = i; 1043 879 1044 if (i<Stats[e].ymin) Stats[e].ymin = y; 1045 if (i>Stats[e].ymax) Stats[e].ymax = y; 1046 1047 if (j<Stats[e].xmin) Stats[e].xmin = x; 1048 if (j>Stats[e].xmax) Stats[e].xmax = x; 880 if (i < Stats[e].ymin) { 881 Stats[e].ymin = y; 882 } 883 if (i > Stats[e].ymax) { 884 Stats[e].ymax = y; 885 } 886 887 if (j < Stats[e].xmin) { 888 Stats[e].xmin = x; 889 } 890 if (j > Stats[e].xmax) { 891 Stats[e].xmax = x; 892 } 1049 893 1050 894 Stats[e].S += 1; … … 1053 897 } 1054 898 } 1055 // ---------------------------------------------------------------------------------- 1056 void lineFeaturesComputation_Dummy( uint32 **E, int i, int width, RegionStats *Stats) 1057 // ---------------------------------------------------------------------------------- 1058 { 1059 // pour pointeur de fonction 1060 return; 1061 } 1062 // ---------------------------------------------------------------------------- 1063 void lineFeaturesComputation( uint32 **E, int i, int width, RegionStats *Stats) 1064 // ---------------------------------------------------------------------------- 899 900 901 // ----------------------------------------------------------------------------- 902 void lineFeaturesComputation(uint32 ** E, int i, int width, RegionStats * Stats) 903 // ----------------------------------------------------------------------------- 1065 904 { 1066 905 // line RegionStats_Calc_Rectangle_Moment1 1067 int j;1068 906 1069 907 uint32 x, y; 1070 908 uint32 e; 1071 909 1072 for ( j = 0; j < width; j++) {910 for (int j = 0; j < width; j++) { 1073 911 1074 912 e = E[i][j]; … … 1078 916 y = i; 1079 917 1080 if (i<Stats[e].ymin) Stats[e].ymin = y; 1081 if (i>Stats[e].ymax) Stats[e].ymax = y; 918 if (i < Stats[e].ymin) { 919 Stats[e].ymin = y; 920 } 921 if (i > Stats[e].ymax) { 922 Stats[e].ymax = y; 923 } 1082 924 1083 if (j<Stats[e].xmin) Stats[e].xmin = x; 1084 if (j>Stats[e].xmax) Stats[e].xmax = x; 925 if (j < Stats[e].xmin) { 926 Stats[e].xmin = x; 927 } 928 if (j > Stats[e].xmax) { 929 Stats[e].xmax = x; 930 } 1085 931 1086 932 Stats[e].S += 1; … … 1090 936 } 1091 937 } 1092 // ------------------------------------------------------------------------------------------ 1093 void bandFeaturesComputation_Dummy(uint32 **E, int i0, int i1, int width, RegionStats *Stats) 1094 // ------------------------------------------------------------------------------------------ 1095 { 1096 return; 1097 } 1098 // ------------------------------------------------------------------------------------ 1099 void bandFeaturesComputation(uint32 **E, int i0, int i1, int width, RegionStats *Stats) 1100 // ------------------------------------------------------------------------------------ 1101 { 1102 int i; 1103 for (i = i0; i <= i1; i++) { 938 939 940 // -------------------------------------------------------------------------------------- 941 void bandFeaturesComputation(uint32 ** E, int i0, int i1, int width, RegionStats * Stats) 942 // -------------------------------------------------------------------------------------- 943 { 944 for (int i = i0; i <= i1; i++) { 1104 945 lineFeaturesComputation(E, i, width, Stats); 1105 946 } 1106 947 } 1107 // --------------------------------------------------------------------------------------- 1108 void imageFeaturesComputation_Dummy(uint32 **E, int height, int width, RegionStats *Stats) 1109 // --------------------------------------------------------------------------------------- 1110 { 1111 // pour pointeur de fonction 1112 return; 1113 } 1114 // --------------------------------------------------------------------------------- 1115 void imageFeaturesComputation(uint32 **E, int height, int width, RegionStats *Stats) 1116 // --------------------------------------------------------------------------------- 948 949 950 // ----------------------------------------------------------------------------------- 951 void imageFeaturesComputation(uint32 ** E, int height, int width, RegionStats * Stats) 952 // ----------------------------------------------------------------------------------- 1117 953 { 1118 954 // image RegionStats_Calc_Rectangle_Moment1 1119 int i; 1120 for (i = 0; i < height; i++) { 955 for (int i = 0; i < height; i++) { 1121 956 lineFeaturesComputation(E, i, width, Stats); 1122 957 } 1123 958 } 959 960 1124 961 // --------------------------------------- 1125 962 // --- Fonctions 2014 -------------------- 1126 963 // --------------------------------------- 1127 964 1128 // -------------------------------------------------------------------------------------- 1129 void RegionStats_Copy_Stats1_From_Index(RegionStats * Stats, int dst_index, int src_index)1130 // -------------------------------------------------------------------------------------- 965 // --------------------------------------------------------------------------------------- 966 void RegionStats_Copy_Stats1_From_Index(RegionStats * Stats, int dst_index, int src_index) 967 // --------------------------------------------------------------------------------------- 1131 968 { 1132 969 // R[dst] = R[src] 1133 970 RegionStats_Copy1(&Stats[src_index], &Stats[dst_index]); 1134 971 } 1135 // -------------------------------------------------------------------------------------------- 1136 void RegionStats_Accumulate_Stats1_From_Index(RegionStats *Stats, int dst_index, int src_index) 1137 // -------------------------------------------------------------------------------------------- 972 973 974 // --------------------------------------------------------------------------------------------- 975 void RegionStats_Accumulate_Stats1_From_Index(RegionStats * Stats, int dst_index, int src_index) 976 // --------------------------------------------------------------------------------------------- 1138 977 { 1139 978 // R[dst] += R[src] … … 1147 986 Stats[dst_index].Sy += Stats[src_index].Sy; 1148 987 } 1149 // ----------------------------------------------------------------------------------------------------- 1150 void RegionStats_DisplayStats_Sparse(uint32 *EQ, uint32 ne0, uint32 ne1, RegionStats *Stats, char *name) 1151 // ----------------------------------------------------------------------------------------------------- 988 989 990 // --------------------------------------------------------------------------------------------------------------------------- 991 void RegionStats_DisplayStats_Sparse(uint32 * EQ, uint32 ne0, uint32 ne1, RegionStats * Stats, char * name, int * start_index) 992 // --------------------------------------------------------------------------------------------------------------------------- 1152 993 { 1153 994 // n'affiche que les racines. … … 1156 997 uint32 na; // compteur 1157 998 1158 if (name) printf(name); 1159 1160 na = RegionStats_Count_Roots_Sparse(Stats, EQ, ne0, ne1); 1161 printf("%d\n", na); 999 if (name) { 1000 printf(name); 1001 } 1002 1003 //na = RegionStats_Count_Roots_Sparse(Stats, EQ, ne0, ne1); 1004 //printf("%d\n", na); 1162 1005 1163 1006 for (e = ne0; e <= ne1; e++) { 1164 if ((e == EQ[e]) && (Stats[e].S > 0)) { 1165 printf("%5d ", e); 1007 if (e == EQ[e] && Stats[e].S > 0) { 1008 if (start_index != NULL) { 1009 printf("%5d ", *start_index); 1010 *start_index = *start_index + 1; 1011 } 1012 else { 1013 printf("%5d ", e); 1014 } 1166 1015 display_RegionStats(&Stats[e], NULL); 1167 1016 } 1168 1017 } 1169 1018 } 1170 // ---------------------------------------------------------------------------------------------------- 1171 void RegionStats_DisplayStats_Range(uint32 *EQ, uint32 ne0, uint32 ne1, RegionStats *Stats, char *name) 1172 // ---------------------------------------------------------------------------------------------------- 1019 1020 1021 // ------------------------------------------------------------------------------------------------------- 1022 void RegionStats_DisplayStats_Range(uint32 * EQ, uint32 ne0, uint32 ne1, RegionStats * Stats, char * name) 1023 // ------------------------------------------------------------------------------------------------------- 1173 1024 { 1174 1025 // affichage dense (apres un pack) … … 1176 1027 uint32 e; 1177 1028 1178 if (name) printf(name); 1029 if (name) { 1030 printf(name); 1031 } 1179 1032 1180 1033 for (e = ne0; e <= ne1; e++) { … … 1183 1036 } 1184 1037 } 1185 // -------------------------------------------------------------------------------------------------------- 1186 void RegionStats_Save_Stats1_Sparse(RegionStats *Stats, uint32 *EQ, uint32 ne0, uint32 ne1, char *filename) 1187 // -------------------------------------------------------------------------------------------------------- 1038 1039 1040 // ----------------------------------------------------------------------------------------------------------- 1041 void RegionStats_Save_Stats1_Sparse(RegionStats * Stats, uint32 * EQ, uint32 ne0, uint32 ne1, char * filename) 1042 // ----------------------------------------------------------------------------------------------------------- 1188 1043 { 1189 1044 int fd; … … 1197 1052 RegionStats_Close_File(fd); 1198 1053 } 1199 // ------------------------------------------------------------------------------------------ 1200 uint32 RegionStats_Count_Roots_Sparse(RegionStats *Stats, uint32 *EQ, uint32 ne0, uint32 ne1) 1201 // ------------------------------------------------------------------------------------------ 1054 1055 1056 // -------------------------------------------------------------------------------------------- 1057 uint32 RegionStats_Count_Roots_Sparse(RegionStats * Stats, uint32 * EQ, uint32 ne0, uint32 ne1) 1058 // -------------------------------------------------------------------------------------------- 1202 1059 { 1203 1060 uint32 e, c = 0; // compteur … … 1210 1067 return c; 1211 1068 } 1212 // --------------------------------------------------------------------------------- 1213 uint32 RegionStats_Count_Roots_Sparse1(RegionStats *Stats, uint32 *EQ, uint32 nemax) 1214 // --------------------------------------------------------------------------------- 1069 1070 1071 // ----------------------------------------------------------------------------------- 1072 uint32 RegionStats_Count_Roots_Sparse1(RegionStats * Stats, uint32 * EQ, uint32 nemax) 1073 // ----------------------------------------------------------------------------------- 1215 1074 { 1216 1075 return RegionStats_Count_Roots_Sparse(Stats, EQ, 1, nemax); 1217 1076 } 1218 // ------------------------------------------------------------------------------------------- 1219 uint32 RegionStats_Count_Labels_Sparse(RegionStats *Stats, uint32 *EQ, uint32 ne0, uint32 ne1) 1220 // ------------------------------------------------------------------------------------------- 1077 1078 1079 // --------------------------------------------------------------------------------------------- 1080 uint32 RegionStats_Count_Labels_Sparse(RegionStats * Stats, uint32 * EQ, uint32 ne0, uint32 ne1) 1081 // --------------------------------------------------------------------------------------------- 1221 1082 { 1222 1083 uint32 e, c = 0; // compteur … … 1229 1090 return c; 1230 1091 } 1231 // ----------------------------*----------------------------------------------------- 1232 uint32 RegionStats_Count_Labels_Sparse1(RegionStats *Stats, uint32 *EQ, uint32 nemax) 1233 // ---------------------------*------------------------------------------------------ 1092 1093 1094 // ------------------------------------------------------------------------------------ 1095 uint32 RegionStats_Count_Labels_Sparse1(RegionStats * Stats, uint32 * EQ, uint32 nemax) 1096 // ------------------------------------------------------------------------------------ 1234 1097 { 1235 1098 return RegionStats_Count_Labels_Sparse(Stats, EQ, 1, nemax); 1236 1099 } 1237 // --------------------------------------------------------------------- 1238 void copy_features_ui32matrix(RegionStats *Stats, uint32 ne, uint32 **m) 1239 // --------------------------------------------------------------------- 1240 { 1241 int i; 1242 for (i = 0; i <= (int) ne; i++) { 1100 1101 1102 // ----------------------------------------------------------------------- 1103 void copy_features_ui32matrix(RegionStats * Stats, uint32 ne, uint32 ** m) 1104 // ----------------------------------------------------------------------- 1105 { 1106 for (int i = 0; i <= (int) ne; i++) { 1243 1107 1244 1108 m[i][0] = i; … … 1260 1124 } 1261 1125 } 1262 // --------------------------------------------------------------------- 1263 void copy_ui32matrix_features(uint32 **m, uint32 ne, RegionStats *Stats) 1264 // --------------------------------------------------------------------- 1265 { 1266 int i; 1267 for (i = 0; i <= (int) ne; i++) { 1126 1127 1128 // ----------------------------------------------------------------------- 1129 void copy_ui32matrix_features(uint32 ** m, uint32 ne, RegionStats * Stats) 1130 // ----------------------------------------------------------------------- 1131 { 1132 for (int i = 0; i <= (int) ne; i++) { 1268 1133 1269 1134 Stats[i].xmin = m[i][2] >> 16; … … 1277 1142 } 1278 1143 } 1279 // --------------------------------------------------------------------------- 1280 void sortv_ui32matrix_col(uint32 **m, int i0, int i1, int j0, int j1, int col) 1281 // --------------------------------------------------------------------------- 1144 1145 1146 // ---------------------------------------------------------------------------- 1147 void sortv_ui32matrix_col(uint32 ** m, int i0, int i1, int j0, int j1, int col) 1148 // ---------------------------------------------------------------------------- 1282 1149 { 1283 1150 // nrsort2 for NRC2 … … 1294 1161 * instead of copying the lines. 1295 1162 */ 1296 int i, j;1297 1163 1298 1164 uint32 x, min, pos; 1299 1165 uint32 * ptr; 1300 1166 1301 for (i = nrl; i < nrh; i++) {1167 for (int i = nrl; i < nrh; i++) { 1302 1168 min = m[i][nc]; 1303 1169 pos = i; 1304 for ( j = i + 1; j <= nrh; j++) {1170 for (int j = i + 1; j <= nrh; j++) { 1305 1171 x = m[j][nc]; 1306 1172 if (x < min) { … … 1314 1180 m[i] = m[pos]; 1315 1181 m[pos] = ptr; 1316 1317 1182 } // i 1318 1319 } 1320 // ------------------------------------------------------------ 1321 void RegionStats_SortFeatures(RegionStats *Stats, uint32 nemax) 1322 // ------------------------------------------------------------ 1183 } 1184 1185 1186 // ------------------------------------------------------------- 1187 void RegionStats_SortFeatures(RegionStats * Stats, uint32 nemax) 1188 // ------------------------------------------------------------- 1323 1189 { 1324 1190 uint32 ** m = NULL; … … 1330 1196 copy_ui32matrix_features(m, nemax, Stats); 1331 1197 } 1332 // -------------------------------------------------------------------------------------- 1333 void imageFeaturesComputation_omp0(uint32 **E, int height, int width, RegionStats *Stats) 1334 // -------------------------------------------------------------------------------------- 1335 { 1336 // version OpenMP 2.0 fausse (sans serialisation de la section critique) 1337 // pour evaluer l'impact de la synchro 1338 int i, j; 1339 1340 uint32 x, y; 1341 uint32 e; 1342 1343 #ifdef OPENMP 1344 #pragma omp parallel for private(height, width, i, j, x, y, e) shared (E, Stats) 1345 #endif 1346 for (i = 0; i < height; i++) { 1347 for (j = 0; j < width; j++) { 1348 1349 e = E[i][j]; 1350 if (e) { 1351 1352 x = j; 1353 y = i; 1354 1355 // min max reduction 1356 if (y < Stats[e].ymin) Stats[e].ymin = y; 1357 if (y > Stats[e].ymax) Stats[e].ymax = y; 1358 1359 if (x < Stats[e].xmin) Stats[e].xmin = x; 1360 if (x > Stats[e].xmax) Stats[e].xmax = x; 1361 1362 // + reduction 1363 Stats[e].S += 1; 1364 Stats[e].Sx += x; 1365 Stats[e].Sy += y; 1366 } 1367 } 1368 } 1369 } 1370 // -------------------------------------------------------------------------------------- 1371 void imageFeaturesComputation_omp2(uint32** E, int height, int width, RegionStats* Stats) 1372 // -------------------------------------------------------------------------------------- 1373 { 1374 // version OpenMP 2.0 classique avec "critical" 1375 1376 int i, j; 1377 1378 uint32 x, y; 1379 uint32 e; 1380 1381 1382 #ifdef OPENMP 1383 //#pragma omp parallel for private(height, width, i, j, x, y, e) shared(E, Stats) 1384 #pragma omp parallel for shared(E, Stats) private(height, width, i, j, x, y, e) schedule(dynamic) 1385 //#pragma omp for private (j) 1386 #endif 1387 for (i = 0; i < height; i++) { 1388 //printf("i = %d\n", i); 1389 //printf("omp_get_num_threads = %d\n", omp_get_num_threads()); 1390 1391 for (j = 0; j < width; j++) { 1392 1393 e = E[i][j]; 1394 if (e) { 1395 1396 x = j; 1397 y = i; 1398 1399 #ifdef OPENMP 1400 #pragma omp critical 1401 #endif 1402 { 1403 // min max reduction 1404 if (y < Stats[e].ymin) Stats[e].ymin = y; 1405 if (y > Stats[e].ymax) Stats[e].ymax = y; 1406 1407 if (x < Stats[e].xmin) Stats[e].xmin = x; 1408 if (x > Stats[e].xmax) Stats[e].xmax = x; 1409 1410 // + reduction 1411 Stats[e].S += 1; 1412 Stats[e].Sx += x; 1413 Stats[e].Sy += y; 1414 } // omp critical 1415 } // if e 1416 } // j 1417 } // i 1418 } 1419 // -------------------------------------------------------------------------------------- 1420 void imageFeaturesComputation_omp3(uint32** E, int height, int width, RegionStats* Stats) 1421 // -------------------------------------------------------------------------------------- 1422 { 1423 // version OpenMP 2.0 classique avec "critical" (from Laurent Cabaret with optimal use of critical and atomic) 1424 1425 int i, j; 1426 1427 uint32 x, y; 1428 uint32 e; 1429 1430 1431 #ifdef OPENMP 1432 //#pragma omp parallel for private(height, width, i, j, x, y, e) shared(E, Stats) 1433 #pragma omp parallel for shared(E, Stats) private(height, width, i, j, x, y, e) schedule(dynamic) 1434 #endif 1435 for (i = 0; i < height; i++) { 1436 1437 for (j = 0; j < width; j++) { 1438 1439 e = E[i][j]; 1440 if (e) { 1441 1442 x = j; 1443 y = i; 1444 1445 #ifdef OPENMP 1446 #pragma omp critical 1447 #endif 1448 { 1449 // min max reduction 1450 if (y < Stats[e].ymin) Stats[e].ymin = y; 1451 if (y > Stats[e].ymax) Stats[e].ymax = y; 1452 } 1453 #ifdef OPENMP 1454 #pragma omp critical 1455 #endif 1456 { 1457 if (x < Stats[e].xmin) Stats[e].xmin = x; 1458 if (x > Stats[e].xmax) Stats[e].xmax = x; 1459 } 1460 // + reduction 1461 #ifdef OPENMP 1462 #pragma omp atomic 1463 #endif 1464 Stats[e].S += 1; 1465 1466 #ifdef OPENMP 1467 #pragma omp atomic 1468 #endif 1469 Stats[e].Sx += x; 1470 1471 #ifdef OPENMP 1472 #pragma omp atomic 1473 Stats[e].Sy += y; 1474 #endif 1475 } // if e 1476 } // j 1477 } // i 1478 } 1479 // -------------------------------------------------------------------------------------------- 1480 void imageFeaturesComputation_range_omp2(uint32** E, int height, int width, RegionStats* Stats) 1481 // -------------------------------------------------------------------------------------------- 1482 { 1483 // version OpenMP 2.0 1484 1485 int i, j; 1486 1487 uint32 x, y; 1488 uint32 e; 1489 1490 1491 #ifdef OPENMP 1492 //#pragma omp parallel for private(height, width, i, j, x, y, e) shared(E, Stats) 1493 #pragma omp parallel for shared(E, Stats) private(height, width, i, j, x, y, e) schedule(dynamic) 1494 //#pragma omp for private (j) 1495 #endif 1496 for (i = 0; i < height; i++) { 1497 //printf("i = %d\n", i); 1498 //printf("omp_get_num_threads = %d\n", omp_get_num_threads()); 1499 1500 for (j = 0; j < width; j++) { 1501 1502 e = E[i][j]; 1503 if (e) { 1504 1505 x = j; 1506 y = i; 1507 1508 #ifdef OPENMP 1509 #pragma omp critical 1510 #endif 1511 { 1512 // min max reduction 1513 if (y < Stats[e].ymin) Stats[e].ymin = y; 1514 if (y > Stats[e].ymax) Stats[e].ymax = y; 1515 1516 if (x < Stats[e].xmin) Stats[e].xmin = x; 1517 if (x > Stats[e].xmax) Stats[e].xmax = x; 1518 1519 // + reduction 1520 Stats[e].S += 1; 1521 Stats[e].Sx += x; 1522 Stats[e].Sy += y; 1523 } // omp critical 1524 } // if e 1525 } // j 1526 } // i 1527 } 1528 // -------------------------------------------------------------------------------------------------------- 1529 void imageFeaturesComputation_omp4(uint32** restrict E, int height, int width, RegionStats* restrict Stats) 1530 // -------------------------------------------------------------------------------------------------------- 1531 { 1532 // version avec "task" (OpenMP 3.0) et "depend" (OpenMP 4.0) 1533 #ifdef OPENMP 1534 #pragma omp parallel private(height,width) shared(E,Stats) 1535 { 1536 #endif // OPENMP 1537 int i, j; 1538 1539 uint32 x, y; 1540 uint32 e; 1541 1542 #ifdef OPENMP4 1543 //#pragma omp task depend ( in:E[0:height-1][0:width-1]) depend( inout: E[1:height*width/4]) 1544 #pragma omp task depend( inout: E[1:height*width/4]) 1545 #endif 1546 for (i = 0; i < height; i++) { 1547 for (j = 0; j < width; j++) { 1548 1549 e = E[i][j]; 1550 if (e) { 1551 1552 x = j; 1553 y = i; 1554 1555 1556 // min max reduction 1557 if (y < Stats[e].ymin) Stats[e].ymin = y; 1558 if (y > Stats[e].ymax) Stats[e].ymax = y; 1559 1560 if (x < Stats[e].xmin) Stats[e].xmin = x; 1561 if (x > Stats[e].xmax) Stats[e].xmax = x; 1562 1563 // + reduction 1564 Stats[e].S += 1; 1565 Stats[e].Sx += x; 1566 Stats[e].Sy += y; 1567 } 1568 } 1569 } 1570 #ifdef OPENMP 1571 } 1572 #endif // OPENMP 1573 } 1574 // ------------------------------------------------------------------------------ 1575 void calc_xmin(uint32** restrict E, int height, int width, uint16* restrict Xmin) 1576 // ------------------------------------------------------------------------------ 1577 { 1578 int i, j; 1198 1199 1200 // -------------------------------------------------------------------------------- 1201 void calc_xmin(uint32 ** restrict E, int height, int width, uint16 * restrict Xmin) 1202 // -------------------------------------------------------------------------------- 1203 { 1579 1204 uint32 x; 1580 1205 uint32 e; 1581 /* 1582 #ifdef OPENMP 1583 #pragma omp critical 1584 #endif 1585 { printf("calc xmin %d x %d\n", width, height); } 1586 */ 1587 for (i = 0; i < height; i++) { 1588 for (j = 0; j < width; j++) { 1206 for (int i = 0; i < height; i++) { 1207 for (int j = 0; j < width; j++) { 1589 1208 e = E[i][j]; 1590 1209 if (e) { 1591 1210 x = j; 1592 if (x < Xmin[e]) Xmin[e] = x; 1593 } 1594 } 1595 } 1596 } 1597 // ------------------------------------------------------------------------------ 1598 void calc_xmax(uint32** restrict E, int height, int width, uint16* restrict Xmax) 1599 // ------------------------------------------------------------------------------ 1600 { 1601 int i, j; 1211 if (x < Xmin[e]) { 1212 Xmin[e] = x; 1213 } 1214 } 1215 } 1216 } 1217 } 1218 1219 1220 // -------------------------------------------------------------------------------- 1221 void calc_xmax(uint32 ** restrict E, int height, int width, uint16 * restrict Xmax) 1222 // -------------------------------------------------------------------------------- 1223 { 1602 1224 uint32 x; 1603 1225 uint32 e; 1604 /* 1605 #ifdef OPENMP 1606 #pragma omp critical 1607 #endif 1608 { printf("calc xmax %d x %d\n", width, height); } 1609 */ 1610 for (i = 0; i < height; i++) { 1611 for (j = 0; j < width; j++) { 1226 for (int i = 0; i < height; i++) { 1227 for (int j = 0; j < width; j++) { 1612 1228 e = E[i][j]; 1613 1229 if (e) { … … 1618 1234 } 1619 1235 } 1620 // ------------------------------------------------------------------------------ 1621 void calc_ymin(uint32** restrict E, int height, int width, uint16* restrict Ymin) 1622 // ------------------------------------------------------------------------------ 1623 { 1624 int i, j; 1236 1237 1238 // -------------------------------------------------------------------------------- 1239 void calc_ymin(uint32 ** restrict E, int height, int width, uint16 * restrict Ymin) 1240 // -------------------------------------------------------------------------------- 1241 { 1625 1242 uint32 y; 1626 1243 uint32 e; 1627 /* 1628 #ifdef OPENMP 1629 #pragma omp critical 1630 #endif 1631 { printf("calc ymin %d x %d\n", width, height); } 1632 */ 1633 for(i=0; i<height; i++) { 1634 for(j=0; j<width; j++) { 1244 for (int i = 0; i < height; i++) { 1245 for (int j = 0; j < width; j++) { 1635 1246 e = E[i][j]; 1636 if (e) {1247 if (e) { 1637 1248 y = i; 1638 if(y < Ymin[e]) Ymin[e] = y; 1639 } 1640 } 1641 } 1642 } 1643 // ------------------------------------------------------------------------------ 1644 void calc_ymax(uint32** restrict E, int height, int width, uint16* restrict Ymax) 1645 // ------------------------------------------------------------------------------ 1646 { 1647 int i, j; 1249 if (y < Ymin[e]) { 1250 Ymin[e] = y; 1251 } 1252 } 1253 } 1254 } 1255 } 1256 1257 1258 // -------------------------------------------------------------------------------- 1259 void calc_ymax(uint32 ** restrict E, int height, int width, uint16 * restrict Ymax) 1260 // -------------------------------------------------------------------------------- 1261 { 1648 1262 uint32 y; 1649 1263 uint32 e; 1650 /* 1651 #ifdef OPENMP 1652 #pragma omp critical 1653 #endif 1654 { printf("calc ymax %d x %d\n", width, height); } 1655 */ 1656 for(i=0; i<height; i++) { 1657 for(j=0; j<width; j++) { 1264 for (int i = 0; i < height; i++) { 1265 for (int j = 0; j < width; j++) { 1658 1266 e = E[i][j]; 1659 if (e) {1267 if (e) { 1660 1268 y = i; 1661 if(y > Ymax[e]) Ymax[e] = y; 1662 } 1663 } 1664 } 1665 } 1666 // ------------------------------------------------------------------------ 1667 void calc_s(uint32** restrict E, int height, int width, uint32* restrict S) 1668 // ------------------------------------------------------------------------ 1669 { 1670 int i, j; 1269 if (y > Ymax[e]) { 1270 Ymax[e] = y; 1271 } 1272 } 1273 } 1274 } 1275 } 1276 1277 1278 // -------------------------------------------------------------------------- 1279 void calc_s(uint32 ** restrict E, int height, int width, uint32 * restrict S) 1280 // -------------------------------------------------------------------------- 1281 { 1671 1282 uint32 e; 1672 /* 1673 #ifdef OPENMP 1674 #pragma omp critical 1675 #endif 1676 { printf("calc s %d x %d\n", width, height); } 1677 */ 1678 for(i=0; i<height; i++) { 1679 for(j=0; j<width; j++) { 1283 for (int i = 0; i < height; i++) { 1284 for (int j = 0; j < width; j++) { 1680 1285 e = E[i][j]; 1681 if (e) {1286 if (e) { 1682 1287 S[e] += 1; 1683 1288 } … … 1685 1290 } 1686 1291 } 1687 // -------------------------------------------------------------------------- 1688 void calc_sx(uint32** restrict E, int height, int width, uint32* restrict Sx) 1689 // -------------------------------------------------------------------------- 1690 { 1691 int i, j; 1292 1293 1294 // ---------------------------------------------------------------------------- 1295 void calc_sx(uint32 ** restrict E, int height, int width, uint32 * restrict Sx) 1296 // ---------------------------------------------------------------------------- 1297 { 1692 1298 uint32 e; 1693 /* 1694 #ifdef OPENMP 1695 #pragma omp critical 1696 #endif 1697 { printf("calc sx %d x %d\n", width, height); } 1698 */ 1699 for(i=0; i<height; i++) { 1700 for(j=0; j<width; j++) { 1299 for (int i = 0; i < height; i++) { 1300 for (int j = 0; j < width; j++) { 1701 1301 e = E[i][j]; 1702 if (e) {1302 if (e) { 1703 1303 Sx[e] += j; 1704 1304 } … … 1706 1306 } 1707 1307 } 1708 // -------------------------------------------------------------------------- 1709 void calc_sy(uint32** restrict E, int height, int width, uint32* restrict Sy) 1710 // -------------------------------------------------------------------------- 1711 { 1712 int i, j; 1308 1309 1310 // ---------------------------------------------------------------------------- 1311 void calc_sy(uint32 ** restrict E, int height, int width, uint32 * restrict Sy) 1312 // ---------------------------------------------------------------------------- 1313 { 1713 1314 uint32 e; 1714 /* 1715 #ifdef OPENMP 1716 #pragma omp critical 1717 #endif 1718 { printf("calc sy %d x %d\n", width, height); } 1719 */ 1720 for (i = 0; i < height; i++) { 1721 for (j = 0; j < width; j++) { 1315 for (int i = 0; i < height; i++) { 1316 for (int j = 0; j < width; j++) { 1722 1317 e = E[i][j]; 1723 1318 if (e) { … … 1727 1322 } 1728 1323 } 1729 // --------------------------------------------------------------------------------------------------------------------------------------------------------------- 1730 void imageFeaturesComputation_omp5(uint32** E, int height, int width, uint16* Xmin, uint16* Xmax, uint16* Ymin, uint16* Ymax, uint32* S, uint32* Sx, uint32* Sy) 1731 // --------------------------------------------------------------------------------------------------------------------------------------------------------------- 1732 { 1733 // version avec "task" (OpenMP 3.0) et "depend" (OpenMP 4.0) 1734 #ifdef OPENMP 1735 #pragma omp parallel shared(E,Xmin,Xmax,Ymin,Ymax,S,Sx,Sy) 1736 // ne sourtout pas mettre height et width en private 1737 { 1738 #endif // OPENMP 1739 1740 int id; // thread number 1741 1742 #ifdef OPENMP 1743 id = omp_get_thread_num(); 1744 #else 1745 id = 1; 1746 #endif 1747 1748 //printf("thread id = %d h = %d w = %d\n", id, height, width); 1749 1750 if (id == 0) { calc_xmin(E, height, width, Xmin); } 1751 if (id == 1) { calc_xmax(E, height, width, Xmax); } 1752 if (id == 2) { calc_ymin(E, height, width, Ymin); } 1753 if (id == 3) { calc_ymax(E, height, width, Ymax); } 1754 1755 if (id == 4) { calc_s (E, height, width, S); } 1756 if (id == 5) { calc_sx(E, height, width, Sx); } 1757 if (id == 6) { calc_sy(E, height, width, Sy); } 1758 #ifdef OPENMP 1759 } 1760 #endif // OPENMP 1761 } 1762 // ------------------------------------------------------ 1763 int RegionStats_Compare(RegionStats *S1, RegionStats *S2) 1764 // ------------------------------------------------------ 1324 1325 1326 // -------------------------------------------------------- 1327 int RegionStats_Compare(RegionStats * S1, RegionStats * S2) 1328 // -------------------------------------------------------- 1765 1329 { 1766 1330 //puts("----------------------------------------"); 1767 1331 //display_RegionStats(S1, "S1"); 1768 1332 //display_RegionStats(S2, "S2"); 1769 if ((S1->xmin == S2->xmin) &&1333 if ((S1->xmin == S2->xmin) && 1770 1334 (S1->xmax == S2->xmax) && 1771 1335 (S1->ymin == S2->ymin) && 1772 1336 (S1->ymax == S2->ymax) && 1773 (S1->S == S2->S) &&1774 (S1->Sx == S2->Sx) &&1775 (S1->Sy == S2->Sy ))1337 (S1->S == S2->S) && 1338 (S1->Sx == S2->Sx) && 1339 (S1->Sy == S2->Sy)) { 1776 1340 return 1; 1777 else 1341 } 1342 else { 1778 1343 return 0; 1779 } 1780 // ---------------------------------------------------------------------------- 1781 int RegionStatsVector_Compare(RegionStats *S1, int i0, int i1, RegionStats *S2) 1782 // ---------------------------------------------------------------------------- 1783 { 1784 int i; 1344 } 1345 } 1346 1347 1348 // ------------------------------------------------------------------------------ 1349 int RegionStatsVector_Compare(RegionStats * S1, int i0, int i1, RegionStats * S2) 1350 // ------------------------------------------------------------------------------ 1351 { 1785 1352 int c; // resultat de la comparaison 0 = identique, 1 = different 1786 1353 int s = 0; // somme 1787 1354 1788 for (i=i0; i<=i1; i++) {1355 for (int i = i0; i <= i1; i++) { 1789 1356 c = RegionStats_Compare(&S1[i], &S2[i]); 1790 1357 s += c; 1791 1792 /*if(c) {1793 puts("---------------------------------------------------");1794 printf("e = %d\n", i);1795 display_RegionStats(&S1[i], NULL);1796 display_RegionStats(&S2[i], NULL);1797 }*/1798 1799 1358 } 1800 1359 return s; 1801 1360 } 1802 // ------------------------------------------------------------------------------------------ 1803 int RegionStatsVector_Match(RegionStats *S1, int i0, int i1, RegionStats *S2, int j0, int j1) 1804 // ------------------------------------------------------------------------------------------ 1805 { 1806 int i, j, pos; 1361 1362 1363 // -------------------------------------------------------------------------------------------- 1364 int RegionStatsVector_Match(RegionStats * S1, int i0, int i1, RegionStats * S2, int j0, int j1) 1365 // -------------------------------------------------------------------------------------------- 1366 { 1367 int j, pos; 1807 1368 int c; // resultat de la comparaison 1 = identique, 0 = different 1808 1369 int a; // accumulateur de c 1809 1370 int s = 0; // somme 1810 1371 int perm = 0; // permutation de numero de features 1811 int n1 = i1 -i0+1;1812 int n2 = j1 -j0+1;1372 int n1 = i1 - i0 + 1; 1373 int n2 = j1 - j0 + 1; 1813 1374 1814 1375 //printf("[RegionStatsVector_Match]: [%d..%d]=%d vs [%d..%d]=%d\n", i0, i1, n1, j0,j1,n2); … … 1818 1379 } 1819 1380 1820 for (i = i0; i <= i1; i++) {1381 for (int i = i0; i <= i1; i++) { 1821 1382 a = 0; 1822 1383 pos = -1; … … 1825 1386 c = RegionStats_Compare(&S1[i], &S2[j]); 1826 1387 a = a + c; 1827 if (c) pos = j; 1388 if (c) { 1389 pos = j; 1390 } 1828 1391 } 1829 1392 s += a; … … 1833 1396 for (j = j0; j <= j1; j++) { 1834 1397 c = RegionStats_Compare(&S1[i], &S2[j]); 1835 if (c) printf("S2[%d] ", j); 1836 } 1837 printf(""); 1838 giet_pthread_exit(""); 1398 if (c) { 1399 printf("S2[%d] ", j); 1400 } 1401 } 1402 printf("\n"); 1403 exit(1); 1839 1404 } 1840 1405 … … 1855 1420 return n1 - s; 1856 1421 } 1422 1423 // Local Variables: 1424 // tab-width: 4 1425 // c-basic-offset: 4 1426 // c-file-offsets:((innamespace . 0)(inline-open . 0)) 1427 // indent-tabs-mode: nil 1428 // End: 1429 1430 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 1431 -
soft/giet_vm/applications/rosenfeld/src/mt19937.c
r772 r821 54 54 55 55 static unsigned long mt[N]; /* the array for the state vector */ 56 static int mti =N+1;/* mti==N+1 means mt[N] is not initialized */56 static int mti = N + 1 ; /* mti==N+1 means mt[N] is not initialized */ 57 57 58 58 static int global_seed; … … 61 61 void init_genrand(unsigned long s) 62 62 { 63 mt[0] = s & 0xffffffffUL;63 mt[0] = s & 0xffffffffUL; 64 64 global_seed = s; // modif LL 65 for (mti=1; mti<N; mti++) { 66 mt[mti] = 67 (1812433253UL * (mt[mti-1] ^ (mt[mti-1] >> 30)) + mti); 65 for (mti = 1; mti < N; mti++) { 66 mt[mti] = (1812433253UL * (mt[mti - 1] ^ (mt[mti - 1] >> 30)) + mti); 68 67 /* See Knuth TAOCP Vol2. 3rd Ed. P.106 for multiplier. */ 69 68 /* In the previous versions, MSBs of the seed affect */ … … 84 83 //init_genrand(19650218UL); 85 84 init_genrand(global_seed); 86 i=1; j=0; 87 k = (N>key_length ? N : key_length); 85 i = 1; 86 j = 0; 87 k = (N > key_length ? N : key_length); 88 88 for (; k; k--) { 89 mt[i] = (mt[i] ^ ((mt[i-1] ^ (mt[i-1] >> 30)) * 1664525UL)) 90 + init_key[j] + j; /* non linear */ 91 mt[i] &= 0xffffffffUL; /* for WORDSIZE > 32 machines */ 92 i++; j++; 93 if (i>=N) { mt[0] = mt[N-1]; i=1; } 94 if (j>=key_length) j=0; 95 } 96 for (k=N-1; k; k--) { 97 mt[i] = (mt[i] ^ ((mt[i-1] ^ (mt[i-1] >> 30)) * 1566083941UL)) 98 - i; /* non linear */ 89 mt[i] = (mt[i] ^ ((mt[i - 1] ^ (mt[i - 1] >> 30)) * 1664525UL)) + init_key[j] + j; /* non linear */ 99 90 mt[i] &= 0xffffffffUL; /* for WORDSIZE > 32 machines */ 100 91 i++; 101 if (i>=N) { mt[0] = mt[N-1]; i=1; } 92 j++; 93 if (i >= N) { 94 mt[0] = mt[N - 1]; 95 i = 1; 96 } 97 if (j >= key_length) { 98 j = 0; 99 } 100 } 101 for (k = N - 1; k; k--) { 102 mt[i] = (mt[i] ^ ((mt[i - 1] ^ (mt[i - 1] >> 30)) * 1566083941UL)) - i; /* non linear */ 103 mt[i] &= 0xffffffffUL; /* for WORDSIZE > 32 machines */ 104 i++; 105 if (i >= N) { 106 mt[0] = mt[N - 1]; 107 i = 1; 108 } 102 109 } 103 110 … … 109 116 { 110 117 unsigned long y; 111 static unsigned long mag01[2] ={0x0UL, MATRIX_A};118 static unsigned long mag01[2] = {0x0UL, MATRIX_A}; 112 119 /* mag01[x] = x * MATRIX_A for x=0,1 */ 113 120 … … 115 122 int kk; 116 123 117 if (mti == N +1)/* if init_genrand() has not been called, */124 if (mti == N + 1) { /* if init_genrand() has not been called, */ 118 125 //init_genrand(5489UL); /* a default initial seed is used */ 119 126 init_genrand(global_seed); 120 121 for (kk=0;kk<N-M;kk++) { 122 y = (mt[kk]&UPPER_MASK)|(mt[kk+1]&LOWER_MASK); 123 mt[kk] = mt[kk+M] ^ (y >> 1) ^ mag01[y & 0x1UL]; 124 } 125 for (;kk<N-1;kk++) { 126 y = (mt[kk]&UPPER_MASK)|(mt[kk+1]&LOWER_MASK); 127 mt[kk] = mt[kk+(M-N)] ^ (y >> 1) ^ mag01[y & 0x1UL]; 128 } 129 y = (mt[N-1]&UPPER_MASK)|(mt[0]&LOWER_MASK); 130 mt[N-1] = mt[M-1] ^ (y >> 1) ^ mag01[y & 0x1UL]; 127 } 128 129 for (kk = 0;kk < N - M; kk++) { 130 y = (mt[kk] & UPPER_MASK) | (mt[kk + 1] & LOWER_MASK); 131 mt[kk] = mt[kk + M] ^ (y >> 1) ^ mag01[y & 0x1UL]; 132 } 133 for (; kk < N - 1; kk++) { 134 y = (mt[kk] & UPPER_MASK) | (mt[kk + 1] & LOWER_MASK); 135 mt[kk] = mt[kk + (M - N)] ^ (y >> 1) ^ mag01[y & 0x1UL]; 136 } 137 y = (mt[N - 1] & UPPER_MASK) | (mt[0] & LOWER_MASK); 138 mt[N - 1] = mt[M - 1] ^ (y >> 1) ^ mag01[y & 0x1UL]; 131 139 132 140 mti = 0; … … 147 155 long genrand_int31(void) 148 156 { 149 return (long) (genrand_int32()>>1);157 return (long) (genrand_int32() >> 1); 150 158 } 151 159 … … 153 161 double genrand_real1(void) 154 162 { 155 return genrand_int32() *(1.0/4294967295.0);163 return genrand_int32() * (1.0 / 4294967295.0); 156 164 /* divided by 2^32-1 */ 157 165 } … … 160 168 double genrand_real2(void) 161 169 { 162 return genrand_int32() *(1.0/4294967296.0);170 return genrand_int32() * (1.0 / 4294967296.0); 163 171 /* divided by 2^32 */ 164 172 } … … 167 175 double genrand_real3(void) 168 176 { 169 return (((double) genrand_int32()) + 0.5)*(1.0/4294967296.0);177 return (((double) genrand_int32()) + 0.5) * (1.0 / 4294967296.0); 170 178 /* divided by 2^32 */ 171 179 } … … 174 182 double genrand_res53(void) 175 183 { 176 unsigned long a =genrand_int32()>>5, b=genrand_int32()>>6;177 return (a*67108864.0+b)*(1.0/9007199254740992.0);184 unsigned long a = genrand_int32() >> 5, b = genrand_int32() >> 6; 185 return (a * 67108864.0 + b) * (1.0 / 9007199254740992.0); 178 186 } 179 187 /* These real versions are due to Isaku Wada, 2002/01/09 added */ … … 182 190 { 183 191 int i; 184 unsigned long init[4] ={0x123, 0x234, 0x345, 0x456}, length=4;192 unsigned long init[4] = {0x123, 0x234, 0x345, 0x456}, length = 4; 185 193 init_by_array(init, length); 186 194 printf("1000 outputs of genrand_int32()\n"); 187 for (i =0; i<1000; i++) {195 for (i = 0; i < 1000; i++) { 188 196 printf("%10lu ", genrand_int32()); 189 if (i%5==4) printf("\n"); 197 if (i % 5 == 4) { 198 printf("\n"); 199 } 190 200 } 191 201 printf("\n1000 outputs of genrand_real2()\n"); 192 for (i =0; i<1000; i++) {202 for (i = 0; i < 1000; i++) { 193 203 printf("%10.8f ", genrand_real2()); 194 if (i%5==4) printf("\n"); 204 if (i % 5 == 4) { 205 printf("\n"); 206 } 195 207 } 196 208 return 0; 197 209 } 210 211 212 // Local Variables: 213 // tab-width: 4 214 // c-basic-offset: 4 215 // c-file-offsets:((innamespace . 0)(inline-open . 0)) 216 // indent-tabs-mode: nil 217 // End: 218 219 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 220 -
soft/giet_vm/applications/rosenfeld/src/palette.c
r772 r821 16 16 17 17 18 #ifdef CLI19 18 #include "nrc_os_config.h" 20 19 #include "nrc.h" 21 #endif22 20 23 21 #include "palette.h" 24 22 25 /* 26 * Modif : 98-11-18 ajout de Save 27 */ 28 29 /* ---------------------------------------------- */ 30 IMAGE_EXPORT(void) Palette_Display(RGBQuad *palette) 31 /* ---------------------------------------------- */ 23 24 /* --------------------------------- */ 25 void Palette_Display(RGBQuad * palette) 26 /* --------------------------------- */ 32 27 { 33 28 int i; … … 37 32 } 38 33 } 39 /* ----------------------------------------------------------- */ 40 //IMAGE_EXPORT(void) Palette_Save(RGBQuad *palette, char *filename) 41 /* ----------------------------------------------------------- */ 42 /*{ 43 int i, j; 44 int k = 32; 45 int hauteur = k, largeur = k*256; 46 uint8 **X; 47 Image *image; 48 49 50 IConstructor(&image, hauteur, largeur, 0); 51 X = (uint8**) Image_Get_Data(image); 52 for(i=0; i<hauteur; i++) { 53 for(j=0; j<largeur; j++) { 54 X[i][j] = j/k; 55 } 56 } 57 //SaveBMP(image, palette, filename); 58 IDestructor(&image); 59 }*/ 60 /* --------------------------------------------------------------------- */ 61 //IMAGE_EXPORT(void) Palette_SaveSub(RGBQuad *palette, int n, char *filename) 62 /* --------------------------------------------------------------------- */ 63 /*{ 64 int i, j; 65 int hauteur = 8, largeur = 8*n; 66 uint8 **X; 67 Image *image; 68 69 70 IConstructor(&image, largeur, hauteur, 0); 71 X = (uint8**) Image_Get_Data(image); 72 for(i=0; i<hauteur; i++) { 73 for(j=8; j<=largeur; j++) { 74 X[i][j] = j/8; 75 } 76 } 77 //SaveBMP(image, palette, filename); 78 IDestructor(&image); 79 }*/ 34 35 80 36 /* --------------------------------------------------- */ 81 37 IMAGE_EXPORT(void) Palette_GrayBlue2Red(RGBQuad *palette) 82 /* --------------------------------------------------- */ 83 /* ancien SetupPalette */ 84 { 85 int i; 86 38 /* --------------------------------------------------- */ 39 /* ancien SetupPalette */ 40 { 87 41 /* 88 42 * Partie basse : image en niveau de gris 89 43 */ 90 for (i=0; i<128; i++) {91 palette[i].blue = 2 *i;92 palette[i].green = 2 *i;93 palette[i].red = 2 *i;44 for (int i = 0; i < 128; i++) { 45 palette[i].blue = 2 * i; 46 palette[i].green = 2 * i; 47 palette[i].red = 2 * i; 94 48 palette[i].reserved = 0; 95 49 } … … 98 52 * degrade de bleus puis degrade de rouges 99 53 */ 100 for (i=0; i<128; i++) {101 palette[i +128].blue = 255 - 2*i;102 palette[i +128].green = 0;103 palette[i +128].red = 2*i+1;104 palette[i +128].reserved = 0;54 for (int i = 0; i < 128; i++) { 55 palette[i + 128].blue = 255 - 2 * i; 56 palette[i + 128].green = 0; 57 palette[i + 128].red = 2 * i + 1; 58 palette[i + 128].reserved = 0; 105 59 } 106 60 palette[128].blue = 255; … … 113 67 palette[255].red = 255; 114 68 palette[255].reserved = 0; 115 116 /*for(i=0; i<256; i++) { 117 palette[i].rgbBlue = i; 118 palette[i].rgbGreen = i; 119 palette[i].rgbRed = i; 120 palette[i].rgbReserved = 0; 121 }*/ 122 123 /*if(verbose) { 124 for(i=0; i<256; i++) { 125 printf("%d %3d %3d %3d\n", i, Palette[i].rgbRed, Palette[i].rgbGreen, Palette[i].rgbBlue); 126 } 127 }*/ 128 } 129 /* ---------------------------------------------- */ 130 IMAGE_EXPORT(void) Palette_Classic(RGBQuad *palette) 131 /* ---------------------------------------------- */ 132 { 133 int i; 134 135 for(i=0; i<256; i++) { 69 } 70 71 72 /* --------------------------------- */ 73 void Palette_Classic(RGBQuad * palette) 74 /* --------------------------------- */ 75 { 76 for (int i = 0; i < 256; i++) { 136 77 palette[i].blue = (uint8) i; 137 78 palette[i].green = (uint8) i; … … 140 81 } 141 82 } 142 /* ------------------------------------------- */ 143 IMAGE_EXPORT(void) Palette_Gray(RGBQuad *palette) 144 /* ------------------------------------------- */145 { 146 int i; 147 148 for (i=0; i<256; i++) {83 84 85 /* ------------------------------ */ 86 void Palette_Gray(RGBQuad * palette) 87 /* ------------------------------ */ 88 { 89 for (int i = 0; i < 256; i++) { 149 90 palette[i].blue = (uint8) i; 150 91 palette[i].green = (uint8) i; … … 154 95 } 155 96 156 /* ---------------------------------------------- */ 157 IMAGE_EXPORT(void) Palette_Pseudo1(RGBQuad *palette) 158 /* ---------------------------------------------- */ 159 { 160 int i; 161 for (i=0; i<255; i++) {162 palette[i].blue = (uint8) ((3 *i)%256);163 palette[i].green = (uint8) ((87 *i)%256);164 palette[i].red = (uint8) ((117 *i)%256);97 98 /* --------------------------------- */ 99 void Palette_Pseudo1(RGBQuad * palette) 100 /* --------------------------------- */ 101 { 102 for (int i = 0; i < 255; i++) { 103 palette[i].blue = (uint8) ((3 * i) % 256); 104 palette[i].green = (uint8) ((87 * i) % 256); 105 palette[i].red = (uint8) ((117 * i) % 256); 165 106 palette[i].reserved = 0; 166 107 } … … 170 111 palette[255].reserved = (uint8) 0; 171 112 } 172 /* ---------------------------------------------- */ 173 IMAGE_EXPORT(void) Palette_Pseudo2(RGBQuad *palette) 174 /* ---------------------------------------------- */ 175 { 176 int i; 177 for(i=0; i<255; i++) { 178 palette[i].blue = (uint8) (( 257*i)%256); /* nextprime(256) */ 179 palette[i].green = (uint8) (( 65537*i)%256); /* nextprime(256^2) */ 180 palette[i].red = (uint8) ((16777259*i)%256); /* nextprime(256^3) */ 113 114 115 /* --------------------------------- */ 116 void Palette_Pseudo2(RGBQuad * palette) 117 /* --------------------------------- */ 118 { 119 unsigned int i; 120 for (i = 0; i < 255; i++) { 121 palette[i].blue = (uint8) (( 257 * i) % 256); /* nextprime(256) */ 122 palette[i].green = (uint8) (( 65537 * i) % 256); /* nextprime(256^2) */ 123 palette[i].red = (uint8) ((16777259 * i) % 256); /* nextprime(256^3) */ 181 124 palette[i].reserved = 0; 182 125 } … … 186 129 palette[255].reserved = (uint8) 0; 187 130 } 188 /* ------------------------------------------ */ 189 IMAGE_EXPORT(void) Palette_Hue(RGBQuad *palette) 190 /* ------------------------------------------ */ 131 132 133 /* ----------------------------- */ 134 void Palette_Hue(RGBQuad * palette) 135 /* ----------------------------- */ 191 136 { 192 137 int i; 193 138 double k, r, g, b; /* alpha rgb */ 194 for (i=0; i<255; i++) {139 for (i = 0; i < 255; i++) { 195 140 196 141 k = (double) i / 256; 197 142 198 143 r = 2.0 * k * PI; 199 g = 2.0 * k * PI - (2.0* PI/3.0);200 b = 2.0 * k * PI - (4.0*PI/3.0);144 g = 2.0 * k * PI - (2.0* PI / 3.0); 145 b = 2.0 * k * PI - (4.0* PI / 3.0); 201 146 202 147 palette[i].blue = (uint8) (128.0 * (1.0 + cos(b))); … … 206 151 } 207 152 } 208 /* ------------------------------------------------ */ 209 IMAGE_EXPORT(void) Palette_RandomHue(RGBQuad *palette) 210 /* ------------------------------------------------ */ 153 154 155 /* ----------------------------------- */ 156 void Palette_RandomHue(RGBQuad * palette) 157 /* ----------------------------------- */ 211 158 { 212 159 int i, ii; 213 160 double k, r, g, b; /* alpha rgb */ 214 for (i=0; i<255; i++) {215 216 ii = (3 *i)%256;161 for (i = 0; i < 255; i++) { 162 163 ii = (3 * i) % 256; 217 164 k = (double) (ii / 256); 218 165 219 166 r = 2.0 * k * PI; 220 g = 2.0 * k * PI - (2.0 *PI/3.0);221 b = 2.0 * k * PI - (4.0*PI/3.0);167 g = 2.0 * k * PI - (2.0 * PI / 3.0); 168 b = 2.0 * k * PI - (4.0 * PI / 3.0); 222 169 223 170 palette[i].blue = (uint8) (128.0 * (1.0 + cos(b))); … … 227 174 } 228 175 } 229 /* -------------------------------------------- */ 230 IMAGE_EXPORT(void) Palette_HueBW(RGBQuad *palette) 231 /* -------------------------------------------- */ 176 177 178 /* ------------------------------- */ 179 void Palette_HueBW(RGBQuad * palette) 180 /* ------------------------------- */ 232 181 { 233 182 int i; 234 183 double k, r, g, b; /* alpha rgb */ 235 for (i=0; i<255; i++) {184 for (i = 0; i < 255; i++) { 236 185 237 186 k = (double) i / 256; 238 187 239 188 r = 2.0 * k * PI; 240 g = 2.0 * k * PI - (2.0 *PI/3.0);241 b = 2.0 * k * PI - (4.0*PI/3.0);189 g = 2.0 * k * PI - (2.0 * PI / 3.0); 190 b = 2.0 * k * PI - (4.0 * PI / 3.0); 242 191 243 192 palette[i].blue = (uint8) (128.0 * (1.0 + cos(b))); … … 256 205 palette[255].reserved = (uint8) 0; 257 206 } 258 /* -------------------------------------------------- */ 259 IMAGE_EXPORT(void) Palette_RandomHueBW(RGBQuad *palette) 260 /* -------------------------------------------------- */ 207 208 209 /* ------------------------------------- */ 210 void Palette_RandomHueBW(RGBQuad * palette) 211 /* ------------------------------------- */ 261 212 { 262 213 int i, ii, im; 263 214 double k, r, g, b; /* alpha rgb */ 264 for (i=0; i<255; i++) {265 266 ii = (7 *i)%256;215 for (i = 0; i < 255; i++) { 216 217 ii = (7 * i) % 256; 267 218 k = (double) ii / 256; 268 219 269 220 r = 2.0 * k * PI; 270 g = 2.0 * k * PI - (2.0 *PI/3.0);271 b = 2.0 * k * PI - (4.0*PI/3.0);272 273 im = (i -27)%255;221 g = 2.0 * k * PI - (2.0 * PI / 3.0); 222 b = 2.0 * k * PI - (4.0 * PI / 3.0); 223 224 im = (i - 27) % 255; 274 225 im = i; 275 226 palette[im].blue = (uint8) (128.0 * (1.0 + cos(b))); … … 288 239 palette[255].reserved = (uint8) 0; 289 240 } 290 /* ------------------------------------------------ */ 291 IMAGE_EXPORT(void) Palette_3ColorsBW(RGBQuad *palette) 292 /* ------------------------------------------------ */ 293 { 294 int i; 295 uint8 rr = 255,gg = 255, bb = 255; 241 242 243 /* ----------------------------------- */ 244 void Palette_3ColorsBW(RGBQuad * palette) 245 /* ----------------------------------- */ 246 { 247 uint8 rr = 255, gg = 255, bb = 255; 296 248 RGBQuad pattern[3]; 297 249 … … 308 260 pattern[2].blue = bb; 309 261 310 for (i=0; i<255; i++) {311 palette[1 +i].red = pattern[i%3].red;312 palette[1 +i].green = pattern[i%3].green;313 palette[1 +i].blue = pattern[i%3].blue;314 palette[1 +i].reserved = (uint8) 0;262 for (int i = 0; i < 255; i++) { 263 palette[1 + i].red = pattern[i % 3].red; 264 palette[1 + i].green = pattern[i % 3].green; 265 palette[1 + i].blue = pattern[i % 3].blue; 266 palette[1 + i].reserved = (uint8) 0; 315 267 } 316 268 palette[0].blue = (uint8) 0; … … 324 276 palette[255].reserved = (uint8) 0; 325 277 } 326 /* ---------------------------------------------- */ 327 IMAGE_EXPORT(void) Palette_3Colors(RGBQuad *palette) 328 /* ---------------------------------------------- */ 278 279 280 /* --------------------------------- */ 281 void Palette_3Colors(RGBQuad * palette) 282 /* --------------------------------- */ 329 283 { 330 284 int i; 331 uint8 rr = 255, gg = 255, bb = 255;285 uint8 rr = 255, gg = 255, bb = 255; 332 286 RGBQuad pattern[3]; 333 287 … … 344 298 pattern[2].blue = bb; 345 299 346 for(i=0; i<256; i++) { 347 palette[i].red = pattern[i%3].red; 348 palette[i].green = pattern[i%3].green; 349 palette[i].blue = pattern[i%3].blue; 350 palette[i].reserved = (uint8) 0; 351 } 352 } 353 /* -------------------------------------------------- */ 354 IMAGE_EXPORT(void) Palette_3Colors_Red(RGBQuad *palette) 355 /* -------------------------------------------------- */ 356 { 357 int i; 358 uint8 rr = 255,gg = 255, bb = 255; 300 for (i = 0; i < 256; i++) { 301 palette[i].red = pattern[i % 3].red; 302 palette[i].green = pattern[i % 3].green; 303 palette[i].blue = pattern[i % 3].blue; 304 palette[i].reserved = (uint8) 0; 305 } 306 } 307 308 309 /* ------------------------------------- */ 310 void Palette_3Colors_Red(RGBQuad * palette) 311 /* ------------------------------------- */ 312 { 313 uint8 rr = 255, gg = 255, bb = 255; 359 314 RGBQuad pattern[3]; 360 315 … … 376 331 palette[0].blue = pattern[0].blue; 377 332 378 for(i=0; i<255; i++) { 379 palette[1+i].red = pattern[1+i%2].red; 380 palette[1+i].green = pattern[1+i%2].green; 381 palette[1+i].blue = pattern[1+i%2].blue; 382 palette[1+i].reserved = (uint8) 0; 383 } 384 } 385 /* ------------------------------------------------ */ 386 IMAGE_EXPORT(void) Palette_6ColorsBW(RGBQuad *palette) 387 /* ------------------------------------------------ */ 388 { 389 int i; 390 uint8 rr = 255,gg = 255, bb = 255; 333 for (int i = 0; i < 255; i++) { 334 palette[1 + i].red = pattern[1 + i % 2].red; 335 palette[1 + i].green = pattern[1 + i % 2].green; 336 palette[1 + i].blue = pattern[1 + i % 2].blue; 337 palette[1 + i].reserved = (uint8) 0; 338 } 339 } 340 341 342 /* ----------------------------------- */ 343 void Palette_6ColorsBW(RGBQuad * palette) 344 /* ----------------------------------- */ 345 { 346 uint8 rr = 255, gg = 255, bb = 255; 391 347 RGBQuad pattern[6]; 392 348 … … 415 371 pattern[5].blue = bb; 416 372 417 for (i=0; i<255; i++) {418 palette[1 +i].red = pattern[i%6].red;419 palette[1 +i].green = pattern[i%6].green;420 palette[1 +i].blue = pattern[i%6].blue;421 palette[1 +i].reserved = (uint8) 0;373 for (int i = 0; i < 255; i++) { 374 palette[1 + i].red = pattern[i % 6].red; 375 palette[1 + i].green = pattern[i % 6].green; 376 palette[1 + i].blue = pattern[i % 6].blue; 377 palette[1 + i].reserved = (uint8) 0; 422 378 } 423 379 palette[0].blue = (uint8) 0; … … 431 387 palette[255].reserved = (uint8) 0; 432 388 } 433 /* ---------------------------------------------- */ 434 IMAGE_EXPORT(void) Palette_6Colors(RGBQuad *palette) 435 /* ---------------------------------------------- */ 436 { 437 int i; 438 uint8 rr = 255,gg = 255, bb = 255; 389 390 391 /* --------------------------------- */ 392 void Palette_6Colors(RGBQuad * palette) 393 /* --------------------------------- */ 394 { 395 uint8 rr = 255, gg = 255, bb = 255; 439 396 RGBQuad pattern[6]; 440 397 … … 463 420 pattern[5].blue = bb; 464 421 465 for(i=0; i<256; i++) { 466 palette[i].red = pattern[i%6].red; 467 palette[i].green = pattern[i%6].green; 468 palette[i].blue = pattern[i%6].blue; 469 palette[i].reserved = (uint8) 0; 470 } 471 } 472 /* -------------------------------------------------- */ 473 IMAGE_EXPORT(void) Palette_6Colors_Red(RGBQuad *palette) 474 /* -------------------------------------------------- */ 475 { 476 int i; 477 uint8 rr = 255,gg = 255, bb = 255; 422 for (int i = 0; i < 256; i++) { 423 palette[i].red = pattern[i % 6].red; 424 palette[i].green = pattern[i % 6].green; 425 palette[i].blue = pattern[i % 6].blue; 426 palette[i].reserved = (uint8) 0; 427 } 428 } 429 430 431 /* ------------------------------------- */ 432 void Palette_6Colors_Red(RGBQuad * palette) 433 /* ------------------------------------- */ 434 { 435 uint8 rr = 255, gg = 255, bb = 255; 478 436 RGBQuad pattern[6]; 479 437 … … 507 465 palette[0].blue = pattern[0].blue; 508 466 509 for(i=0; i<255; i++) { 510 palette[1+i].red = pattern[1+i%5].red; 511 palette[1+i].green = pattern[1+i%5].green; 512 palette[1+i].blue = pattern[1+i%5].blue; 513 palette[1+i].reserved = (uint8) 0; 514 } 515 } 516 /* ------------------------------------------------- */ 517 IMAGE_EXPORT(void) Palette_18ColorsBW(RGBQuad *palette) 518 /* ------------------------------------------------- */ 467 for (int i = 0; i < 255; i++) { 468 palette[1 + i].red = pattern[1 + i % 5].red; 469 palette[1 + i].green = pattern[1 + i % 5].green; 470 palette[1 + i].blue = pattern[1 + i % 5].blue; 471 palette[1 + i].reserved = (uint8) 0; 472 } 473 } 474 475 476 /* ------------------------------------ */ 477 void Palette_18ColorsBW(RGBQuad * palette) 478 /* ------------------------------------ */ 519 479 { 520 480 int i; 521 uint8 rr = 255, gg = 255, bb = 255;522 uint8 r =127, g = 127, b = 127;481 uint8 rr = 255, gg = 255, bb = 255; 482 uint8 r = 127, g = 127, b = 127; 523 483 524 484 RGBQuad pattern[18]; … … 596 556 pattern[17].blue = bb; 597 557 598 for (i=0; i<255; i++) {599 palette[1 +i].red = pattern[i%18].red;600 palette[1 +i].green = pattern[i%18].green;601 palette[1 +i].blue = pattern[i%18].blue;602 palette[1 +i].reserved = (uint8) 0;558 for (int i = 0; i < 255; i++) { 559 palette[1 + i].red = pattern[i % 18].red; 560 palette[1 + i].green = pattern[i % 18].green; 561 palette[1 + i].blue = pattern[i % 18].blue; 562 palette[1 + i].reserved = (uint8) 0; 603 563 } 604 564 palette[0].blue = (uint8) 0; … … 612 572 palette[255].reserved = (uint8) 0; 613 573 } 614 /* ----------------------------------------------- */ 615 IMAGE_EXPORT(void) Palette_18Colors(RGBQuad *palette) 616 /* ----------------------------------------------- */ 617 { 618 int i; 619 uint8 rr = 255,gg = 255, bb = 255; 620 uint8 r =127, g = 127, b = 127; 574 575 576 /* ---------------------------------- */ 577 void Palette_18Colors(RGBQuad * palette) 578 /* ---------------------------------- */ 579 { 580 uint8 rr = 255, gg = 255, bb = 255; 581 uint8 r = 127, g = 127, b = 127; 621 582 622 583 RGBQuad pattern[18]; … … 694 655 pattern[17].blue = bb; 695 656 696 for(i=0; i<256; i++) { 697 palette[i].red = pattern[i%18].red; 698 palette[i].green = pattern[i%18].green; 699 palette[i].blue = pattern[i%18].blue; 700 palette[i].reserved = (uint8) 0; 701 } 702 } 703 /* ------------------------------------------------- */ 704 IMAGE_EXPORT(void) Palette_64ColorsBW(RGBQuad *palette) 705 /* ------------------------------------------------- */ 706 { 707 int r, g, b; 708 int i, m; 657 for (int i = 0; i < 256; i++) { 658 palette[i].red = pattern[i % 18].red; 659 palette[i].green = pattern[i % 18].green; 660 palette[i].blue = pattern[i % 18].blue; 661 palette[i].reserved = (uint8) 0; 662 } 663 } 664 665 666 /* ------------------------------------ */ 667 void Palette_64ColorsBW(RGBQuad * palette) 668 /* ------------------------------------ */ 669 { 670 int m; 709 671 //uint8 x1 = 64, x2 = 128, x3 = 192, x4 = 255; 710 672 uint8 X[4]; … … 717 679 718 680 m = 1; 719 for (r=0; r<4; r++) {720 for (g=0; g<4; g++) {721 for (b=0; b<4; b++) {681 for (int r = 0; r < 4; r++) { 682 for (int g = 0; g < 4; g++) { 683 for (int b = 0; b < 4; b++) { 722 684 palette[m].red = X[r]; 723 685 palette[m].green = X[g]; … … 728 690 } 729 691 730 for (i=0; i<255-(1+m); i++) {731 palette[1 +m+i].red = palette[i%m].red;732 palette[1 +m+i].green = palette[i%m].green;733 palette[1 +m+i].blue = palette[i%m].blue;734 palette[1 +m+i].reserved = (uint8) 0;692 for (int i = 0; i < 255 - (1 + m); i++) { 693 palette[1 + m + i].red = palette[i % m].red; 694 palette[1 + m + i].green = palette[i % m].green; 695 palette[1 + m + i].blue = palette[i % m].blue; 696 palette[1 + m + i].reserved = (uint8) 0; 735 697 } 736 698 palette[0].blue = (uint8) 0; … … 744 706 palette[255].reserved = (uint8) 0; 745 707 } 746 /* ------------------------------------------------- */ 747 IMAGE_EXPORT(void) Palette_256ColorsBW(RGBQuad *palette) 748 /* ------------------------------------------------- */ 749 { 750 int r, g, b; 708 709 710 /* ------------------------------------- */ 711 void Palette_256ColorsBW(RGBQuad * palette) 712 /* ------------------------------------- */ 713 { 751 714 int m; 752 715 //uint8 x1 = 64, x2 = 128, x3 = 192, x4 = 255; … … 764 727 765 728 m = 1; 766 for (r=0; r<8; r++) {767 for (g=0; g<8; g++) {768 for (b=0; b<8; b++) {769 if (m<255) {729 for (int r = 0; r < 8; r++) { 730 for (int g = 0; g < 8; g++) { 731 for (int b = 0; b < 8; b++) { 732 if (m < 255) { 770 733 xr = X[r]; xg = X[g]; xb = X[b]; 771 734 palette[m].red = xr; 772 735 palette[m].green = xg; 773 736 palette[m].blue = xb; 774 if ((xr!=255) && (xg!=255) && (xb!=255)) m++;775 if ((xr!=000) && (xg!=000) && (xb!=000)) m++;737 if ((xr != 255) && (xg != 255) && (xb != 255)) m++; 738 if ((xr != 000) && (xg != 000) && (xb != 000)) m++; 776 739 } 777 740 } … … 789 752 palette[255].reserved = (uint8) 0; 790 753 } 791 /* ----------------------------------------------------- */ 792 IMAGE_EXPORT(void) Palette_18ColorsBW_Red(RGBQuad *palette) 793 /* ----------------------------------------------------- */ 794 { 795 int i; 796 uint8 rr = 255,gg = 255, bb = 255; 797 uint8 r =127, g = 127, b = 127; 754 755 756 /* ---------------------------------------- */ 757 void Palette_18ColorsBW_Red(RGBQuad * palette) 758 /* ---------------------------------------- */ 759 { 760 uint8 rr = 255, gg = 255, bb = 255; 761 uint8 r = 127, g = 127, b = 127; 798 762 799 763 RGBQuad pattern[18]; … … 871 835 pattern[17].blue = bb; 872 836 873 for (i=0; i<254; i++) {874 palette[2 +i].red = pattern[1+i%17].red;875 palette[2 +i].green = pattern[1+i%17].green;876 palette[2 +i].blue = pattern[1+i%17].blue;877 palette[2 +i].reserved = (uint8) 0;837 for (int i = 0; i < 254; i++) { 838 palette[2 + i].red = pattern[1 + i % 17].red; 839 palette[2 + i].green = pattern[1 + i % 17].green; 840 palette[2 + i].blue = pattern[1 + i % 17].blue; 841 palette[2 + i].reserved = (uint8) 0; 878 842 } 879 843 /* noir en 0 */ … … 890 854 palette[255].blue = gg; 891 855 } 892 /* -------------------------------------------------------------- */ 893 IMAGE_EXPORT(void) Palette_18ColorsBW_RedGreenBlue(RGBQuad *palette) 894 /* -------------------------------------------------------------- */ 895 { 896 int i; 856 857 858 /* ------------------------------------------------- */ 859 void Palette_18ColorsBW_RedGreenBlue(RGBQuad * palette) 860 /* ------------------------------------------------- */ 861 { 897 862 uint8 i0 = 255; 898 863 uint8 i1 = 127; … … 965 930 pattern[14].blue = i0; 966 931 967 for (i=0; i<=250; i++) {968 palette[4 +i].red = pattern[i%14].red;969 palette[4 +i].green = pattern[i%14].green;970 palette[4 +i].blue = pattern[i%14].blue;971 palette[4 +i].reserved = (uint8) 0;932 for (int i = 0; i <= 250; i++) { 933 palette[4 + i].red = pattern[i % 14].red; 934 palette[4 + i].green = pattern[i % 14].green; 935 palette[4 + i].blue = pattern[i % 14].blue; 936 palette[4 + i].reserved = (uint8) 0; 972 937 } 973 938 … … 997 962 palette[255].blue = i0; 998 963 } 999 /* ---------------------------------------------------- */ 1000 IMAGE_EXPORT(void) Palette_3ColorsGrayBW(RGBQuad *palette) 1001 /* ---------------------------------------------------- */1002 { 1003 int i; 1004 964 965 966 /* --------------------------------------- */ 967 void Palette_3ColorsGrayBW(RGBQuad * palette) 968 /* --------------------------------------- */ 969 { 1005 970 Palette_3ColorsBW(palette); 1006 971 1007 for(i=128; i<256; i++) { 1008 palette[i].red = 1 + 2*(i-128); 1009 palette[i].green = 1 + 2*(i-128); 1010 palette[i].blue = 1 + 2*(i-128); 1011 palette[i].reserved = (uint8) 0; 1012 } 1013 /* palette[255] = blanc <- OK */ 1014 } 1015 /* -------------------------------------------------- */ 1016 IMAGE_EXPORT(void) Palette_3ColorsGray(RGBQuad *palette) 1017 /* -------------------------------------------------- */ 1018 { 1019 int i; 1020 972 for (int i = 128; i < 256; i++) { 973 palette[i].red = 1 + 2 * (i - 128); 974 palette[i].green = 1 + 2 * (i - 128); 975 palette[i].blue = 1 + 2 * (i - 128); 976 palette[i].reserved = (uint8) 0; 977 } 978 } 979 980 981 /* ------------------------------------- */ 982 void Palette_3ColorsGray(RGBQuad * palette) 983 /* ------------------------------------- */ 984 { 1021 985 Palette_3Colors(palette); 1022 986 1023 for (i=128; i<256; i++) {1024 palette[i].red = 1 + 2 *(i-128);1025 palette[i].green = 1 + 2 *(i-128);1026 palette[i].blue = 1 + 2 *(i-128);1027 palette[i].reserved = (uint8) 0; 1028 } 1029 } 1030 /* ---------------------------------------------------- */ 1031 IMAGE_EXPORT(void) Palette_6ColorsGrayBW(RGBQuad *palette) 1032 /* ---------------------------------------------------- */1033 { 1034 int i; 1035 987 for (int i = 128; i < 256; i++) { 988 palette[i].red = 1 + 2 * (i - 128); 989 palette[i].green = 1 + 2 * (i - 128); 990 palette[i].blue = 1 + 2 * (i - 128); 991 palette[i].reserved = (uint8) 0; 992 } 993 } 994 995 996 /* --------------------------------------- */ 997 void Palette_6ColorsGrayBW(RGBQuad * palette) 998 /* --------------------------------------- */ 999 { 1036 1000 Palette_6ColorsBW(palette); 1037 1001 1038 for (i=128; i<256; i++) {1039 palette[i].red = 1 + 2 *(i-128);1040 palette[i].green = 1 + 2 *(i-128);1041 palette[i].blue = 1 + 2 *(i-128);1042 palette[i].reserved = (uint8) 0; 1043 } 1044 } 1045 /* -------------------------------------------------- */ 1046 IMAGE_EXPORT(void) Palette_6ColorsGray(RGBQuad *palette) 1047 /* -------------------------------------------------- */1048 { 1049 int i; 1050 1002 for (int i = 128; i < 256; i++) { 1003 palette[i].red = 1 + 2 * (i - 128); 1004 palette[i].green = 1 + 2 * (i - 128); 1005 palette[i].blue = 1 + 2 * (i - 128); 1006 palette[i].reserved = (uint8) 0; 1007 } 1008 } 1009 1010 1011 /* ------------------------------------- */ 1012 void Palette_6ColorsGray(RGBQuad * palette) 1013 /* ------------------------------------- */ 1014 { 1051 1015 Palette_6Colors(palette); 1052 1016 1053 for (i=128; i<256; i++) {1054 palette[i].red = 1 + 2 *(i-128);1055 palette[i].green = 1 + 2 *(i-128);1056 palette[i].blue = 1 + 2 *(i-128);1057 palette[i].reserved = (uint8) 0; 1058 } 1059 } 1060 /* ----------------------------------------------------- */ 1061 IMAGE_EXPORT(void) Palette_18ColorsGrayBW(RGBQuad *palette) 1062 /* ----------------------------------------------------- */1063 { 1064 int i; 1065 1017 for (int i = 128; i < 256; i++) { 1018 palette[i].red = 1 + 2 * (i - 128); 1019 palette[i].green = 1 + 2 * (i - 128); 1020 palette[i].blue = 1 + 2 * (i - 128); 1021 palette[i].reserved = (uint8) 0; 1022 } 1023 } 1024 1025 1026 /* ---------------------------------------- */ 1027 void Palette_18ColorsGrayBW(RGBQuad * palette) 1028 /* ---------------------------------------- */ 1029 { 1066 1030 Palette_18ColorsBW(palette); 1067 1031 1068 for (i=128; i<256; i++) {1069 palette[i].red = 1 + 2 *(i-128);1070 palette[i].green = 1 + 2 *(i-128);1071 palette[i].blue = 1 + 2 *(i-128);1072 palette[i].reserved = (uint8) 0; 1073 } 1074 } 1075 /* --------------------------------------------------- */ 1076 IMAGE_EXPORT(void) Palette_18ColorsGray(RGBQuad *palette) 1077 /* --------------------------------------------------- */1078 { 1079 int i; 1080 1032 for (int i = 128; i < 256; i++) { 1033 palette[i].red = 1 + 2 * (i - 128); 1034 palette[i].green = 1 + 2 * (i - 128); 1035 palette[i].blue = 1 + 2 * (i - 128); 1036 palette[i].reserved = (uint8) 0; 1037 } 1038 } 1039 1040 1041 /* -------------------------------------- */ 1042 void Palette_18ColorsGray(RGBQuad * palette) 1043 /* -------------------------------------- */ 1044 { 1081 1045 Palette_18Colors(palette); 1082 1046 1083 for(i=128; i<256; i++) { 1084 palette[i].red = 1 + 2*(i-128); 1085 palette[i].green = 1 + 2*(i-128); 1086 palette[i].blue = 1 + 2*(i-128); 1087 palette[i].reserved = (uint8) 0; 1088 } 1089 } 1090 /* -------------------------------------------------------------------- */ 1091 //IMAGE_EXPORT(void) Palette_PackGrayLower(Image *src, Lut *lut, Image *dst) 1092 /* -------------------------------------------------------------------- */ 1093 /*{ 1094 int k; 1095 uint8 *l = (uint8*) Lut_Get_Data(lut); 1096 1097 for(k=0; k<256; k++) { 1098 l[k] = (uint8) (k >> 1); 1099 } 1100 1101 Lut_Apply(src, lut, dst); 1102 }*/ 1103 /* -------------------------------------------------------------------- */ 1104 //IMAGE_EXPORT(void) Palette_PackGrayUpper(Image *src, Lut *lut, Image *dst) 1105 /* -------------------------------------------------------------------- */ 1106 /*{ 1107 int k; 1108 uint8 *l = (uint8*) Lut_Get_Data(lut); 1109 1110 for(k=0; k<256; k++) { 1111 l[k] = (uint8) 128 + (k >> 1); 1112 } 1113 1114 Lut_Apply(src, lut, dst); 1115 }*/ 1116 /* ---------------------------------------------- */ 1117 IMAGE_EXPORT(void) Palette_2Colors(RGBQuad *palette) 1118 /* ---------------------------------------------- */ 1119 { 1120 int i, level; 1047 for(int i = 128; i < 256; i++) { 1048 palette[i].red = 1 + 2 * (i - 128); 1049 palette[i].green = 1 + 2 * (i - 128); 1050 palette[i].blue = 1 + 2 * (i - 128); 1051 palette[i].reserved = (uint8) 0; 1052 } 1053 } 1054 1055 1056 /* --------------------------------- */ 1057 void Palette_2Colors(RGBQuad * palette) 1058 /* --------------------------------- */ 1059 { 1060 int level; 1121 1061 1122 1062 RGBQuad pattern[2]; … … 1132 1072 pattern[1].blue = level; 1133 1073 1134 for(i=0; i<256; i++) { 1135 palette[i].red = pattern[i%2].red; 1136 palette[i].green = pattern[i%2].green; 1137 palette[i].blue = pattern[i%2].blue; 1138 palette[i].reserved = (uint8) 0; 1139 } 1140 } 1141 /* ---------------------------------------------- */ 1142 IMAGE_EXPORT(void) Palette_4Colors(RGBQuad *palette) 1143 /* ---------------------------------------------- */ 1144 { 1145 int i, level; 1074 for (int i = 0; i < 256; i++) { 1075 palette[i].red = pattern[i % 2].red; 1076 palette[i].green = pattern[i % 2].green; 1077 palette[i].blue = pattern[i % 2].blue; 1078 palette[i].reserved = (uint8) 0; 1079 } 1080 } 1081 1082 1083 /* --------------------------------- */ 1084 void Palette_4Colors(RGBQuad * palette) 1085 /* --------------------------------- */ 1086 { 1087 int level; 1146 1088 1147 1089 RGBQuad pattern[4]; 1148 1090 1149 for (i=0; i<2; i++) {1150 level = (i <<8) - 1;1091 for (int i = 0; i < 2; i++) { 1092 level = (i << 8) - 1; 1151 1093 pattern[i].red = level; 1152 1094 pattern[0].green = level; … … 1154 1096 } 1155 1097 1156 for(i=0; i<256; i++) { 1157 palette[i].red = pattern[i%2].red; 1158 palette[i].green = pattern[i%2].green; 1159 palette[i].blue = pattern[i%2].blue; 1160 palette[i].reserved = (uint8) 0; 1161 } 1162 } 1163 /* ---------------------------------------------- */ 1164 IMAGE_EXPORT(void) Palette_16Colors(RGBQuad *palette) 1165 /* ---------------------------------------------- */ 1166 { 1167 int i, level; 1098 for (int i = 0; i < 256; i++) { 1099 palette[i].red = pattern[i % 2].red; 1100 palette[i].green = pattern[i % 2].green; 1101 palette[i].blue = pattern[i % 2].blue; 1102 palette[i].reserved = (uint8) 0; 1103 } 1104 } 1105 1106 1107 /* ---------------------------------- */ 1108 void Palette_16Colors(RGBQuad * palette) 1109 /* ---------------------------------- */ 1110 { 1111 int level; 1168 1112 1169 1113 RGBQuad pattern[16]; 1170 1114 1171 for (i=0; i<4; i++) {1172 level = (i <<8) - 1;1115 for (int i = 0; i < 4; i++) { 1116 level = (i << 8) - 1; 1173 1117 pattern[i].red = level; 1174 1118 pattern[0].green = level; … … 1176 1120 } 1177 1121 1178 for(i=0; i<256; i++) { 1179 palette[i].red = pattern[i%2].red; 1180 palette[i].green = pattern[i%2].green; 1181 palette[i].blue = pattern[i%2].blue; 1182 palette[i].reserved = (uint8) 0; 1183 } 1184 } 1122 for (int i = 0; i < 256; i++) { 1123 palette[i].red = pattern[i % 2].red; 1124 palette[i].green = pattern[i % 2].green; 1125 palette[i].blue = pattern[i % 2].blue; 1126 palette[i].reserved = (uint8) 0; 1127 } 1128 } 1129 1130 1131 // Local Variables: 1132 // tab-width: 4 1133 // c-basic-offset: 4 1134 // c-file-offsets:((innamespace . 0)(inline-open . 0)) 1135 // indent-tabs-mode: nil 1136 // End: 1137 1138 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 1139 -
soft/giet_vm/applications/rosenfeld/src/str_ext.c
r777 r821 13 13 #include "nrc_os_config.h" 14 14 15 // -------------------------------------------- 16 void str_remove_ext(const char * src, char* dst)17 // -------------------------------------------- 15 // ---------------------------------------------- 16 void str_remove_ext(const char * src, char * dst) 17 // ---------------------------------------------- 18 18 { 19 19 int len; … … 47 47 dst[len] = '\0'; // do not forget to add null char, otherwise 48 48 } 49 50 49 51 // ------------------- 50 52 int str_len(char * str) -
soft/giet_vm/applications/rosenfeld/src/util.c
r772 r821 39 39 } 40 40 41 41 42 /* ------------- */ 42 43 uint8 ui8rand(void) … … 47 48 return x; 48 49 } 50 51 49 52 /* --------------- */ 50 53 uint32 ui32rand(void) … … 55 58 return x; 56 59 } 60 61 57 62 /* --------------- */ 58 63 float32 f32rand(void) … … 63 68 return x ; 64 69 } 70 71 65 72 /* --------------------------------------- */ 66 73 void rand_ui8vector(uint8 * X, int i0, int i1) 67 74 /* --------------------------------------- */ 68 75 { 69 int i; 70 71 for(i = i0; i <= i1; i++) { 76 for (int i = i0; i <= i1; i++) { 72 77 X[i] = ui8rand(); 73 78 } 74 79 } 80 81 75 82 /* ----------------------------------------- */ 76 83 void rand_ui32vector(uint32 *X, int i0, int i1) 77 84 /* ----------------------------------------- */ 78 85 { 79 int i; 80 81 for (i = i0; i <= i1; i++) { 86 for (int i = i0; i <= i1; i++) { 82 87 X[i] = ui32rand(); 83 88 } 84 89 } 90 91 85 92 /* ----------------------------------------- */ 86 93 void rand_f32vector(float32 *X, int i0, int i1) 87 94 /* ----------------------------------------- */ 88 95 { 89 int i; 90 91 for(i = i0; i <= i1; i++) { 96 for (int i = i0; i <= i1; i++) { 92 97 X[i] = f32rand(); 93 98 } 94 99 } 100 101 95 102 /* --------------- */ 96 103 int getIter(int size) … … 106 113 return 2; 107 114 } 115 116 108 117 /* ----------------- */ 109 118 int getIterAV(int size) … … 112 121 return 3 * getIter(size); 113 122 } 123 124 114 125 /* --------------------------------- */ 115 126 float32 gauss(float32 sigma, float32 x) … … 130 141 return cpp; 131 142 } 143 144 132 145 // -------------------------- 133 146 void printf_split12(double x) … … 160 173 return; 161 174 } 162 printf("");163 175 } 164 176 … … 199 211 return; 200 212 } 201 printf("");202 213 } 203 214 // -------------------------- … … 243 254 return; 244 255 } 245 printf(""); 246 } 256 } 257 258 247 259 // ------------------------ 248 260 void printf_split(double x) … … 253 265 //printf_split18(x); 254 266 } 255 267 268 // Local Variables: 269 // tab-width: 4 270 // c-basic-offset: 4 271 // c-file-offsets:((innamespace . 0)(inline-open . 0)) 272 // indent-tabs-mode: nil 273 // End: 274 275 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 276
Note: See TracChangeset
for help on using the changeset viewer.