comparison Meerwald/wm_bruyn_d.c @ 8:f83ef905a63d

fixing many warnings increase capacity for coordinates in bruyn fix some uninit. variables
author Peter Meerwald <pmeerw@cosy.sbg.ac.at>
date Tue, 22 Apr 2008 13:36:05 +0200
parents be303a3f5ea8
children 4987db85cfae
comparison
equal deleted inserted replaced
7:2b350281f8b0 8:f83ef905a63d
35 gray **block; 35 gray **block;
36 gray **zone; 36 gray **zone;
37 gray **category1, **category2; 37 gray **category1, **category2;
38 gray maxval; 38 gray maxval;
39 double *slope; 39 double *slope;
40 int rows, cols, colors, format; 40 int rows, cols, format;
41 int c; 41 int c;
42 int i, j; 42 int i, j;
43 int r;
44 int n; 43 int n;
45 int col, row; 44 int col, row;
46 int bwidth, bheight;
47 int n_block; 45 int n_block;
48 46
49 char signature_name[MAXPATHLEN]; 47 char signature_name[MAXPATHLEN];
50 char input_name[MAXPATHLEN] = "(stdin)"; 48 char input_name[MAXPATHLEN] = "(stdin)";
51 char output_name[MAXPATHLEN] = "(stdout)"; 49 char output_name[MAXPATHLEN] = "(stdout)";
147 usage(); 145 usage();
148 exit(1); 146 exit(1);
149 } 147 }
150 148
151 // open input image file or read from stdin 149 // open input image file or read from stdin
152 if (argc == 1 && *argv[0] != '-') 150 if (argc == 1 && *argv[0] != '-') {
153 if ((in = fopen(argv[0], "rb")) == NULL) { 151 if ((in = fopen(argv[0], "rb")) == NULL) {
154 fprintf(stderr, "%s: unable to open input file %s\n", progname, argv[0]); 152 fprintf(stderr, "%s: unable to open input file %s\n", progname, argv[0]);
155 exit(1); 153 exit(1);
156 } 154 }
157 else 155 else
158 strcpy(input_name, argv[0]); 156 strcpy(input_name, argv[0]);
157 }
159 158
160 // read signature file and set options 159 // read signature file and set options
161 // command line options override signature file options 160 // command line options override signature file options
162 if (sig) { 161 if (sig) {
163 char line[128]; 162 char line[1024];
164 fgets(line, sizeof(line), sig); 163 fgets(line, sizeof(line), sig);
165 if (strspn(line, "BRSG") >= 4) { 164 if (strspn(line, "BRSG") >= 4) {
166 if (nbit_signature == 0) 165 if (nbit_signature == 0)
167 fscanf(sig, "%d\n", &nbit_signature); 166 fscanf(sig, "%d\n", &nbit_signature);
168 else 167 else
212 fprintf(stderr, "%s: signature file not specified, use -s file option\n", progname); 211 fprintf(stderr, "%s: signature file not specified, use -s file option\n", progname);
213 exit(1); 212 exit(1);
214 } 213 }
215 214
216 if (pattern1 <= 0 || pattern2 <= 0 || pattern1 > NPATTERN || pattern2 > NPATTERN) { 215 if (pattern1 <= 0 || pattern2 <= 0 || pattern1 > NPATTERN || pattern2 > NPATTERN) {
217 fprintf(stderr, "%s: invalid pattern type specified\n"); 216 fprintf(stderr, "%s: invalid pattern type specified\n", progname);
218 exit(1); 217 exit(1);
219 } 218 }
220 219
221 // read dimensions of input image file 220 // read dimensions of input image file
222 pgm_readpgminit(in, &cols, &rows, &maxval, &format); 221 pgm_readpgminit(in, &cols, &rows, &maxval, &format);
229 } 228 }
230 n_block = blocksize * blocksize; 229 n_block = blocksize * blocksize;
231 230
232 // allocate structure to remember which blocks we already touched, 231 // allocate structure to remember which blocks we already touched,
233 // allow plenty of room to skip over blocks 232 // allow plenty of room to skip over blocks
234 if ((coords = alloc_coords(nbit_signature * 2)) == NULL) { 233 if ((coords = alloc_coords(nbit_signature * 16)) == NULL) {
235 fprintf(stderr, "%s: unable to allocate memory\n", progname); 234 fprintf(stderr, "%s: unable to allocate memory\n", progname);
236 exit(1); 235 exit(1);
237 } 236 }
238 237
239 // read in input image file 238 // read in input image file
277 int yb; 276 int yb;
278 int blocktype; 277 int blocktype;
279 double smax; 278 double smax;
280 int alpha, beta_minus, beta_plus; 279 int alpha, beta_minus, beta_plus;
281 double mean_1A, mean_1B, mean_2A, mean_2B, mean_1, mean_2; 280 double mean_1A, mean_1B, mean_2A, mean_2B, mean_1, mean_2;
282 double mean__1A, mean__1B, mean__2A, mean__2B;
283 int n_1A, n_1B, n_2A, n_2B, n_1, n_2; 281 int n_1A, n_1B, n_2A, n_2B, n_1, n_2;
284 double sigma, sigma_1, sigma_2; 282 double sigma, sigma_1, sigma_2;
285 int zone1_ok, zone2_ok; 283 int zone1_ok, zone2_ok;
286 284
287 // find an unused block randomly, depending on seed 285 // find an unused block randomly, depending on seed
289 xb = random() % (cols / blocksize); 287 xb = random() % (cols / blocksize);
290 yb = random() % (rows / blocksize); 288 yb = random() % (rows / blocksize);
291 } while (add_coord(coords, xb, yb) < 0); 289 } while (add_coord(coords, xb, yb) < 0);
292 290
293 // copy image block 291 // copy image block
292 fprintf(stderr, "XXX1 %d %d %d\n", xb*blocksize, yb*blocksize, blocksize);
294 copy_grays_to_block(block, image, xb * blocksize, yb * blocksize, blocksize, blocksize); 293 copy_grays_to_block(block, image, xb * blocksize, yb * blocksize, blocksize, blocksize);
295 294 fprintf(stderr, "XXX2\n");
295
296 if (verbose > 0) 296 if (verbose > 0)
297 fprintf(stderr, "detecting bit #%d in block at (%d/%d)\n", n, xb * blocksize, yb * blocksize); 297 fprintf(stderr, "detecting bit #%d in block at (%d/%d)\n", n, xb * blocksize, yb * blocksize);
298 298
299 // sort luminance values in block to represent increasing function F 299 // sort luminance values in block to represent increasing function F
300 sort_grays(block[0], n_block); 300 sort_grays(block[0], n_block);

Repositories maintained by Peter Meerwald, pmeerw@pmeerw.net.