Changeset 822 for soft/giet_vm/applications/rosenfeld/src
- Timestamp:
- Jun 1, 2016, 10:25:43 AM (9 years ago)
- Location:
- soft/giet_vm/applications/rosenfeld/src
- Files:
-
- 1 deleted
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
soft/giet_vm/applications/rosenfeld/src/ecc_features.c
r821 r822 35 35 36 36 37 // ----------------------------------------------------- 38 void RegionStats_Init(RegionStats * Stats, uint32 nemax) 39 // ----------------------------------------------------- 40 { 41 for (int i = 0; i < (int) nemax; i++) { 42 #if PARMERGE 43 pthread_spin_init(&Stats[i].lock, PTHREAD_PROCESS_PRIVATE); 44 #endif 45 } 46 } 47 48 37 49 // ------------------------------------------------------------- 38 50 void RegionStats_Constructor(RegionStats ** Stats, uint32 nemax) … … 54 66 } 55 67 56 RegionStats_ Clear(Stats, nemax);68 RegionStats_Init(Stats, nemax); 57 69 58 70 return Stats; … … 72 84 // ------------------------------------------------------------ 73 85 { 74 RegionStats_Clear(Stats, nemax);86 //RegionStats_Clear(Stats, nemax); 75 87 free(Stats); 76 88 } 77 78 89 79 90 // ------------------------------------------------------ … … 82 93 { 83 94 for (int i = 0; i < (int) nemax; i++) { 95 #if FEATURES 84 96 Stats[i].xmin = 65535; 85 97 Stats[i].xmax = 0; … … 91 103 Stats[i].Sx = 0; 92 104 Stats[i].Sy = 0; 93 #if PARMERGE94 pthread_spin_init(&Stats[i].lock, PTHREAD_PROCESS_PRIVATE);95 105 #endif 96 106 } 97 107 } 98 108 99 109 #if FEATURES 100 110 // ----------------------------------------- 101 111 void RegionStats_Clear1(RegionStats * stats) … … 396 406 dst->Sy = src->Sy; 397 407 } 398 408 #endif 399 409 400 410 // =============================== … … 414 424 return NULL; 415 425 } 416 RegionStats_ Clear(v, i1 - i0 + 1 + NR_END);426 RegionStats_Init(v, i1 - i0 + 1 + NR_END); 417 427 return v - i0 + NR_END; 418 428 } … … 432 442 return NULL; 433 443 } 434 RegionStats_ Clear(v, i1 - i0 + 1 + NR_END);444 RegionStats_Init(v, i1 - i0 + 1 + NR_END); 435 445 return v - i0 + NR_END; 436 446 } … … 542 552 543 553 554 #if FEATURES 544 555 // ----------------------------------- 545 556 void zero_RegionStats(RegionStats * x) … … 1420 1431 return n1 - s; 1421 1432 } 1433 #endif // FEATURES 1422 1434 1423 1435 // Local Variables: -
soft/giet_vm/applications/rosenfeld/src/ecc_generation.c
r791 r822 23 23 24 24 25 // ------------------------------------------------------------------------------------------------------------------------- 26 void generate_granularity_density_float(uint8 ** X, int i0, int i1, int j0, int j1, int granularity, float density, int seed)27 // ------------------------------------------------------------------------------------------------------------------------- 25 // -------------------------------------------------------------------------------------------------------------------------- 26 void generate_granularity_density_float(uint8 ** X, int i0, int i1, int j0, int j1, int granularity, float density, int seed) 27 // -------------------------------------------------------------------------------------------------------------------------- 28 28 { 29 29 uint8 x; 30 int i, j;31 int di, dj;32 33 30 double r; 34 31 … … 36 33 init_genrand(seed); 37 34 38 for (i=i0; i<=i1; i+=granularity) {39 for (j=j0; j<=j1; j+=granularity) {35 for (int i = i0; i <= i1; i += granularity) { 36 for (int j = j0; j <= j1; j += granularity) { 40 37 41 38 //r = 100.0*(double)rand() / rmax; 42 39 //r = 100.0*(double)rand() / rmax; 43 r = 100.0*(double)genrand_real2(); 44 if(r <= density) x = 1; else x = 0; 45 46 for(di=0; di<granularity; di++) { 47 for(dj=0; dj<granularity; dj++) { 48 if ((i+di<=i1) && (j+dj<=j1)) X[i+di][j+dj] = x; 40 r = 100.0 * (double) genrand_real2(); 41 if (r <= density) { 42 x = 1; 43 } 44 else { 45 x = 0; 46 } 47 48 for (int di = 0; di < granularity; di++) { 49 for (int dj = 0; dj < granularity; dj++) { 50 if ((i + di <= i1) && (j + dj <= j1)) { 51 X[i + di][j + dj] = x; 52 } 49 53 } // dj 50 54 } // di 51 52 } //j 55 } // j 53 56 } // i 54 57 } 55 // --------------------------------------------------------------------------------------------------------------------- 56 void generate_granularity_density_int(uint8 **X, int i0, int i1, int j0, int j1, int granularity, int density, int seed) 57 // --------------------------------------------------------------------------------------------------------------------- 58 59 // ---------------------------------------------------------------------------------------------------------------------- 60 void generate_granularity_density_int(uint8 ** X, int i0, int i1, int j0, int j1, int granularity, int density, int seed) 61 // ---------------------------------------------------------------------------------------------------------------------- 58 62 { 59 63 generate_granularity_density_float(X, i0, i1, j0, j1, granularity, (float) density, seed); 60 64 } 61 // --------------------------------------------------------------------------------------------------------- 62 void generate_granularity_density_name(char *name, int granularity, int density, char *filename, int maxlen) 63 // --------------------------------------------------------------------------------------------------------- 65 66 // ----------------------------------------------------------------------------------------------------------- 67 void generate_granularity_density_name(char * name, int granularity, int density, char * filename, int maxlen) 68 // ----------------------------------------------------------------------------------------------------------- 64 69 { 65 70 snprintf(filename, maxlen, "%s_%02d_%03d.pgm", name, granularity, density); 66 71 } 67 // ------------------------------------------------------------------------------------------------------------------------------ 68 void generate_granularity_density_ext_name(char *name, int granularity, int density, char *extension, char *filename, int maxlen) 69 // ------------------------------------------------------------------------------------------------------------------------------ 72 73 // --------------------------------------------------------------------------------------------------------------------------------- 74 void generate_granularity_density_ext_name(char * name, int granularity, int density, char * extension, char * filename, int maxlen) 75 // --------------------------------------------------------------------------------------------------------------------------------- 70 76 { 71 77 snprintf(filename, maxlen, "%s_%02d_%03d.%s", name, granularity, density, extension); 72 78 } 73 // ------------------------------------------------------------------------------------------------------------------------ 74 void generate_size_granularity_density_name(char * name, int size, int granularity, int density, char *filename, int maxlen)75 // ------------------------------------------------------------------------------------------------------------------------ 79 // -------------------------------------------------------------------------------------------------------------------------- 80 void generate_size_granularity_density_name(char * name, int size, int granularity, int density, char * filename, int maxlen) 81 // -------------------------------------------------------------------------------------------------------------------------- 76 82 { 77 83 snprintf(filename, maxlen, "%s_%d_%02d_%03d.pgm", name, size, granularity, density); 78 84 } 79 // --------------------------------------------------------------------------------------------------------------------------------------------- 80 void generate_size_granularity_density_ext_name(char * name, int size, int granularity, int density, char *extension, char *filename, int maxlen)81 // --------------------------------------------------------------------------------------------------------------------------------------------- 85 // ----------------------------------------------------------------------------------------------------------------------------------------------- 86 void generate_size_granularity_density_ext_name(char * name, int size, int granularity, int density, char *extension, char * filename, int maxlen) 87 // ----------------------------------------------------------------------------------------------------------------------------------------------- 82 88 { 83 89 snprintf(filename, maxlen, "%s_%d_%02d_%03d.%s", name, size, granularity, density, extension); 84 90 } 85 // --------------------------------------------------------------------------------------------------- 86 void generate_size_granularity_name(char * name, int size, int granularity, char *filename, int maxlen)87 // --------------------------------------------------------------------------------------------------- 91 // ----------------------------------------------------------------------------------------------------- 92 void generate_size_granularity_name(char * name, int size, int granularity, char * filename, int maxlen) 93 // ----------------------------------------------------------------------------------------------------- 88 94 { 89 95 snprintf(filename, maxlen, "%s_%d_%02d.pgm", name, size, granularity); 90 }// ----------------------------------------------------------------------------------------- 91 void generate_name100(char * name, int granularity, float density, char *filename, int maxlen)92 // ------------------------------------------------------------------------------------------ 96 }// ------------------------------------------------------------------------------------------ 97 void generate_name100(char * name, int granularity, float density, char *filename, int maxlen) 98 // ------------------------------------------------------------------------------------------- 93 99 { 94 100 // density en pourcentage: 0:100 … … 98 104 } 99 105 // ---------------------------------------- 100 int test_generation(int argc, char * argv[])106 int test_generation(int argc, char * argv[]) 101 107 // ---------------------------------------- 102 108 { 103 uint8 ** X;104 uint8 ** X255;109 uint8 ** X; 110 uint8 ** X255; 105 111 char filename[32]; 106 112 … … 123 129 n = 4096; 124 130 125 X = ui8matrix(0 -border, n-1+border, 0-border, n-1+border);126 X255 = ui8matrix(0 -border, n-1+border, 0-border, n-1+border);127 128 for (g=gmin; g<=gmax; g*=2) {129 for (d=dmin; d<=dmax; d+=dstep) {130 generate_granularity_density_int(X, 0, n -1, 0, n-1, g, d, seed);131 X = ui8matrix(0 - border, n - 1 + border, 0 - border, n - 1 + border); 132 X255 = ui8matrix(0 - border, n - 1 + border, 0 - border, n - 1 + border); 133 134 for (g = gmin; g <= gmax; g *= 2) { 135 for (d = dmin; d <= dmax; d += dstep) { 136 generate_granularity_density_int(X, 0, n - 1, 0, n - 1, g, d, seed); 131 137 generate_granularity_density_name("I", g, d, filename, 32); 132 138 printf(filename); 133 bin2gray_ui8matrix(X, 0, n -1, 0, n-1, X255);134 SavePGM_ui8matrix(X255, 0, n -1, 0, n-1, filename);135 } 136 } 137 free_ui8matrix(X, 0 -border, n-1+border, 0-border, n-1+border);138 free_ui8matrix(X255, 0 -border, n-1+border, 0-border, n-1+border);139 bin2gray_ui8matrix(X, 0, n - 1, 0, n - 1, X255); 140 SavePGM_ui8matrix(X255, 0, n - 1, 0, n - 1, filename); 141 } 142 } 143 free_ui8matrix(X, 0 - border, n - 1 + border, 0 - border, n - 1 + border); 144 free_ui8matrix(X255, 0 - border, n - 1 + border, 0 - border, n - 1 + border); 139 145 140 146 return 0; 141 147 } 142 // ----------------------------------------- 143 void hline(uint8 **X, int i, int j0, int j1) 144 // ----------------------------------------- 145 { 146 int j; 147 for(j=j0; j<=j1; j++) X[i][j] = 1; 148 } 149 // ----------------------------------------- 150 void vline(uint8 **X, int i0, int i1, int j) 151 // ----------------------------------------- 152 { 153 int i; 154 for(i=i0; i<=i1; i++) X[i][j] = 1; 155 } 156 // ----------------------------------------------------------- 157 void draw_rectangle(uint8 **X, int i0, int i1, int j0, int j1) 158 // ----------------------------------------------------------- 148 149 // ------------------------------------------ 150 void hline(uint8 ** X, int i, int j0, int j1) 151 // ------------------------------------------ 152 { 153 for (int j = j0; j <= j1; j++) { 154 X[i][j] = 1; 155 } 156 } 157 // ------------------------------------------ 158 void vline(uint8 ** X, int i0, int i1, int j) 159 // ------------------------------------------ 160 { 161 for (int i = i0; i <= i1; i++) { 162 X[i][j] = 1; 163 } 164 } 165 166 // ------------------------------------------------------------ 167 void draw_rectangle(uint8 ** X, int i0, int i1, int j0, int j1) 168 // ------------------------------------------------------------ 159 169 { 160 170 hline(X, i0, j0, j1); … … 163 173 hline(X, i1, j0, j1); 164 174 } 165 // -------------------------------------------------- 166 void spirale_simple(uint8 **X, int height, int width) 167 // -------------------------------------------------- 175 176 // --------------------------------------------------- 177 void spirale_simple(uint8 ** X, int height, int width) 178 // --------------------------------------------------- 168 179 { 169 180 int i0, j0; // point de depart haut … … 172 183 int n; //min(height, width) 173 184 174 zero_ui8matrix(X, 0, height -1, 0, width-1);175 176 if (height<width) {185 zero_ui8matrix(X, 0, height - 1, 0, width - 1); 186 187 if (height < width) { 177 188 n = height; 178 } else { 189 } 190 else { 179 191 n = width; 180 192 } … … 184 196 185 197 // avec correction 186 i0 = 0; i1 = 2*(n/2)-1; 187 j0 = 0; j1 = 2*(n/2)-1; 198 i0 = 0; 199 i1 = 2 * (n / 2) - 1; 200 j0 = 0; 201 j1 = 2 * (n / 2) - 1; 188 202 189 203 nc = n / 4; 190 204 191 for (c=0; c<nc; c++) {192 draw_rectangle(X, i0 +2*c, i1-2*c, j0+2*c, j1-2*c);193 X[1 +2*c ][0+2*c] = 0;194 X[1 +2*c+1][0+2*c+1] = 1;205 for (c = 0; c < nc; c++) { 206 draw_rectangle(X, i0 + 2 * c, i1 - 2 * c, j0 + 2 * c, j1 - 2 * c); 207 X[1 + 2 * c ][0 + 2 * c ] = 0; 208 X[1 + 2 * c + 1][0 + 2 * c + 1] = 1; 195 209 } 196 210 197 211 // centre 198 212 //X[n/2][n/2] = 1; 199 for(c=i0+2*nc; c<=i1-2*nc; c++) { 200 hline(X, c, j0+2*nc, j1-2*nc); 201 } 202 } 213 for (c = i0 + 2 * nc; c <= i1 - 2 * nc; c++) { 214 hline(X, c, j0 + 2 * nc, j1 - 2 * nc); 215 } 216 } 217 203 218 // -------------------------------------------------- 204 219 void spirale_double(uint8 **X, int height, int width) … … 212 227 zero_ui8matrix(X, 0, height-1, 0, width-1); 213 228 214 if (height<width) {229 if (height < width) { 215 230 n = height; 216 } else { 231 } 232 else { 217 233 n = width; 218 234 } … … 221 237 //n = ((n-1) & (~0x3))+1; 222 238 223 i0 = 0; i1 = 2*(n/2)-1; 224 j0 = 0; j1 = 2*(n/2)-1; 239 i0 = 0; 240 i1 = 2 * (n / 2) - 1; 241 j0 = 0; 242 j1 = 2 * (n / 2) - 1; 225 243 226 244 nc = n / 4; 227 245 228 for (c=0; c<nc; c++) {229 draw_rectangle(X, i0 +2*c, i1-2*c, j0+2*c, j1-2*c);230 } 231 for (c=0; c<nc; c++) {232 X[(i0 +1)+(2*c )][(j0)+(2*c)] = 0;233 X[(i0 +1)+(2*c+1)][(j0)+(2*c+1)] = 1;246 for (c = 0; c < nc; c++) { 247 draw_rectangle(X, i0 + 2 * c, i1 - 2 * c, j0 + 2 * c, j1 - 2 * c); 248 } 249 for (c = 0; c < nc; c++) { 250 X[(i0 + 1) + (2 * c )][(j0) + (2 * c )] = 0; 251 X[(i0 + 1) + (2 * c + 1)][(j0) + (2 * c + 1)] = 1; 234 252 235 X[(i1 -1)-(2*c )][(j1)-(2*c)] = 0;236 X[(i1 -1)-(2*c+1)][(j1)-(2*c+1)] = 1;253 X[(i1 - 1) - (2 * c )][(j1) - (2 * c )] = 0; 254 X[(i1 - 1) - (2 * c + 1)][(j1) - (2 * c + 1)] = 1; 237 255 } 238 256 // centre 239 257 //X[n/2][n/2] = 1; 240 for (c=i0+2*nc; c<=i1-2*nc; c++) {241 hline(X, c, j0 +2*nc, j1-2*nc);258 for (c = i0 + 2 * nc; c <= i1 - 2 * nc; c++) { 259 hline(X, c, j0 + 2 * nc, j1 - 2 * nc); 242 260 } 243 261 } … … 246 264 // ------------------------ 247 265 { 248 uint8 ** X;249 uint8 ** X255;266 uint8 ** X; 267 uint8 ** X255; 250 268 char filename[128]; 251 269 //char *ptr = (char*) filename; … … 254 272 h = w = n; 255 273 256 X = ui8matrix(0, h -1, 0, w-1);257 X255 = ui8matrix(0, h -1, 0, w-1);274 X = ui8matrix(0, h - 1, 0, w - 1); 275 X255 = ui8matrix(0, h - 1, 0, w - 1); 258 276 259 277 snprintf(filename, 128, "spirale_simple_%d.pgm", n); 260 278 spirale_simple(X, h, w); 261 bin2gray_ui8matrix(X, 0, h -1, 0, w-1, X255);262 SavePGM_ui8matrix(X255, 0, h -1, 0, w-1, filename);279 bin2gray_ui8matrix(X, 0, h - 1, 0, w - 1, X255); 280 SavePGM_ui8matrix(X255, 0, h - 1, 0, w - 1, filename); 263 281 264 282 snprintf(filename, 128, "spirale_double_%d.pgm", n); 265 283 spirale_double(X, h, w); 266 bin2gray_ui8matrix(X, 0, h-1, 0, w-1, X255); 267 SavePGM_ui8matrix(X255, 0, h-1, 0, w-1, filename);/**/ 268 269 free_ui8matrix(X, 0, h-1, 0, w-1); 270 free_ui8matrix(X255, 0, h-1, 0, w-1); 271 } 272 // -------------------------------------- 273 void test_spirale(int argc, char* argv[]) 274 // -------------------------------------- 284 bin2gray_ui8matrix(X, 0, h - 1, 0, w - 1, X255); 285 SavePGM_ui8matrix(X255, 0, h - 1, 0, w - 1, filename);/**/ 286 287 free_ui8matrix(X, 0, h - 1, 0, w - 1); 288 free_ui8matrix(X255, 0, h - 1, 0, w - 1); 289 } 290 291 // --------------------------------------- 292 void test_spirale(int argc, char * argv[]) 293 // --------------------------------------- 275 294 { 276 295 routine_spirale(128); … … 283 302 routine_spirale(1024); 284 303 } 285 // -------------------------------------------- 286 int test_generation_HGH(int argc, char* argv[]) 287 // -------------------------------------------- 288 { 289 uint8 **X; 290 uint8 **X255; 304 305 // --------------------------------------------- 306 int test_generation_HGH(int argc, char * argv[]) 307 // --------------------------------------------- 308 { 309 uint8 ** X; 310 uint8 ** X255; 291 311 char filename[32]; 292 312 293 313 int h = 1280; 294 int w = 90 *1024;314 int w = 90 * 1024; 295 315 296 316 int border = 2; … … 303 323 //w = h; 304 324 305 X = ui8matrix(0 -border, h-1+border, 0-border, w-1+border);306 X255 = ui8matrix(0 -border, h-1+border, 0-border, w-1+border);307 308 generate_granularity_density_float(X, 0, h -1, 0, w-1, g, d, seed);325 X = ui8matrix(0 - border, h - 1 + border, 0 - border, w - 1 + border); 326 X255 = ui8matrix(0 - border, h - 1 + border, 0 - border, w - 1 + border); 327 328 generate_granularity_density_float(X, 0, h - 1, 0, w - 1, g, d, seed); 309 329 generate_granularity_density_name("HGH", g, d, filename, 32); 310 330 printf(filename); 311 bin2gray_ui8matrix(X, 0, h -1, 0, w-1, X255);312 SavePGM_ui8matrix(X255, 0, h -1, 0, w-1, filename);313 314 free_ui8matrix(X, 0 -border, h-1+border, 0-border, w-1+border);315 free_ui8matrix(X255, 0 -border, h-1+border, 0-border, w-1+border);331 bin2gray_ui8matrix(X, 0, h - 1, 0, w - 1, X255); 332 SavePGM_ui8matrix(X255, 0, h - 1, 0, w - 1, filename); 333 334 free_ui8matrix(X, 0 - border, h - 1 + border, 0 - border, w - 1 + border); 335 free_ui8matrix(X255, 0 - border, h - 1 + border, 0 - border, w - 1 + border); 316 336 317 337 return 0; 318 338 } 319 // -------------------------------------------- 320 int image_analysis_2014(int argc, char* argv[]) 321 // -------------------------------------------- 339 340 // --------------------------------------------- 341 int image_analysis_2014(int argc, char * argv[]) 342 // --------------------------------------------- 322 343 { 323 344 // uint8 **X; … … 466 487 // -------------------------- 467 488 { 468 int i,n = 32;489 int n = 32; 469 490 470 491 printf("---------------------------"); … … 474 495 475 496 init_genrand(0); 476 for (i=0; i<n; i++) {497 for (int i = 0; i < n; i++) { 477 498 printf("%10lu ", genrand_int32()); 478 if (i%8==7) printf("\n"); 499 if (i % 8 == 7) { 500 printf("\n"); 501 } 479 502 } 480 503 printf("\n---"); 481 504 482 505 init_genrand(1); 483 for (i=0; i<n; i++) {506 for (int i = 0; i < n; i++) { 484 507 printf("%10lu ", genrand_int32()); 485 if (i%8==7) printf("\n"); 508 if (i % 8== 7) { 509 printf("\n"); 510 } 486 511 } 487 512 printf("\n---"); 488 513 489 514 init_genrand(0); 490 for (i=0; i<n; i++) {515 for (int i = 0; i < n; i++) { 491 516 printf("%10lu ", genrand_int32()); 492 if (i%8==7) printf("\n"); 517 if (i % 8== 7) { 518 printf("\n"); 519 } 493 520 } 494 521 printf("\n---"); 495 522 496 523 init_genrand(1); 497 for (i=0; i<n; i++) {524 for (int i = 0; i < n; i++) { 498 525 printf("%10lu ", genrand_int32()); 499 if (i%8==7) printf("\n"); 500 } 501 } 502 // ------------------------------------- 503 void image_zoom2(int argc, char *argv[]) 504 // ------------------------------------- 505 { 506 uint8 x, **X, **Y; 507 int i, j, i0, i1, j0, j1; 526 if (i % 8 == 7) { 527 printf("\n"); 528 } 529 } 530 } 531 532 // -------------------------------------- 533 void image_zoom2(int argc, char * argv[]) 534 // -------------------------------------- 535 { 536 uint8 x, ** X, ** Y; 537 int i0, i1, j0, j1; 508 538 int height, width; 509 char *src_filename; 510 char *dst_filename; 511 512 if(argc<3) { 513 printf("too few arguments"); 514 printf("%s src.pgm dst.pgm\n", argv[0]); 515 return; 516 } 517 518 src_filename = argv[1]; 519 dst_filename = argv[2]; 520 521 X = LoadPGM_ui8matrix(src_filename, &i0, &i1, &j0, &j1); 522 523 height = i1-i0+1; 524 width = j1-j0+1; 525 526 printf("width = %d height = %d\n", width, height); 527 528 Y = ui8matrix(0, 2*height-1, 0, 2*width-1); 529 530 for(i=0; i<=height-1; i++) { 531 for(j=0; j<=width-1; j++) { 532 x = X[i][j]; 533 Y[2*i+0][2*j+0] = x; Y[2*i+0][2*j+1] = x; 534 Y[2*i+1][2*j+0] = x; Y[2*i+1][2*j+1] = x; 535 } 536 } 537 SavePGM_ui8matrix(Y, 0, 2*height-1, 0, 2*width-1, dst_filename); 538 539 free_ui8matrix(X, 0, height-1, 0, width-1); 540 free_ui8matrix(Y, 0, 2*height-1, 0, 2*width-1); 541 } 542 // -------------------------------------------- 543 void image_duplication2(int argc, char *argv[]) 544 // -------------------------------------------- 545 { 546 uint8 x, **X, **Y; 547 int i, j, i0, i1, j0, j1; 548 int height, width; 549 char *src_filename; 550 char *dst_filename; 539 char * src_filename; 540 char * dst_filename; 551 541 552 542 if (argc < 3) { … … 561 551 X = LoadPGM_ui8matrix(src_filename, &i0, &i1, &j0, &j1); 562 552 563 height = i1 -i0+1;564 width = j1 -j0+1;553 height = i1 - i0 + 1; 554 width = j1 - j0 + 1; 565 555 566 556 printf("width = %d height = %d\n", width, height); 567 557 568 Y = ui8matrix(0, 2*height-1, 0, 2*width-1); 558 Y = ui8matrix(0, 2 * height - 1, 0, 2 * width - 1); 559 560 for (int i = 0; i <= height - 1; i++) { 561 for (int j = 0; j <= width - 1; j++) { 562 x = X[i][j]; 563 Y[2 * i + 0][2 * j + 0] = x; 564 Y[2 * i + 0][2 * j + 1] = x; 565 Y[2 * i + 1][2 * j + 0] = x; 566 Y[2 * i + 1][2 * j + 1] = x; 567 } 568 } 569 SavePGM_ui8matrix(Y, 0, 2 * height - 1, 0, 2 * width - 1, dst_filename); 570 571 free_ui8matrix(X, 0, height - 1, 0, width - 1); 572 free_ui8matrix(Y, 0, 2 * height - 1, 0, 2 * width - 1); 573 } 574 575 576 // --------------------------------------------- 577 void image_duplication2(int argc, char * argv[]) 578 // --------------------------------------------- 579 { 580 uint8 x, ** X, ** Y; 581 int i0, i1, j0, j1; 582 int height, width; 583 char * src_filename; 584 char * dst_filename; 585 586 if (argc < 3) { 587 printf("too few arguments"); 588 printf("%s src.pgm dst.pgm\n", argv[0]); 589 return; 590 } 591 592 src_filename = argv[1]; 593 dst_filename = argv[2]; 594 595 X = LoadPGM_ui8matrix(src_filename, &i0, &i1, &j0, &j1); 596 597 height = i1 - i0 + 1; 598 width = j1 - j0 + 1; 599 600 printf("width = %d height = %d\n", width, height); 601 602 Y = ui8matrix(0, 2 * height - 1, 0, 2 * width - 1); 569 603 570 604 // horizontal duplication 571 for (i=0; i<=height-1; i++) {572 for (j=0; j<=width-1; j++) {605 for (int i = 0; i <= height - 1; i++) { 606 for (int j = 0; j <= width - 1; j++) { 573 607 x = X[i][j]; 574 Y[i][width +j] = x;608 Y[i][width + j] = x; 575 609 } 576 610 } 577 611 578 612 // vertical duplication 579 for (i=0; i<=height-1; i++) {580 for (j=0; j<=2*width-1; j++) {613 for (int i = 0; i <= height - 1; i++) { 614 for (int j = 0; j <= 2 * width - 1; j++) { 581 615 x = X[i][j]; 582 Y[height+i][j] = x; 583 } 584 } 585 SavePGM_ui8matrix(Y, 0, 2*height-1, 0, 2*width-1, dst_filename); 586 587 free_ui8matrix(X, 0, height-1, 0, width-1); 588 free_ui8matrix(Y, 0, 2*height-1, 0, 2*width-1); 589 } 616 Y[height + i][j] = x; 617 } 618 } 619 SavePGM_ui8matrix(Y, 0, 2 * height - 1, 0, 2 * width - 1, dst_filename); 620 621 free_ui8matrix(X, 0, height - 1, 0, width - 1); 622 free_ui8matrix(Y, 0, 2 * height - 1, 0, 2 * width - 1); 623 } 624 625 626 627
Note: See TracChangeset
for help on using the changeset viewer.