ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/util/rcode_ident.c
(Generate patch)

Comparing ray/src/util/rcode_ident.c (file contents):
Revision 2.2 by greg, Fri Jul 19 22:57:12 2019 UTC vs.
Revision 2.3 by greg, Tue Jul 23 17:20:20 2019 UTC

# Line 17 | Line 17 | static const char RCSid[] = "$Id$";
17   #define MAXIDLEN        256             /* longest ID length supported */
18   #endif
19  
20 + #define HF_TABLOUT      0x100           /* output ID table after header */
21 +
22   char            *progname;              /* global argv[0] */
23  
24   static int      unbuffered = 0;
25 + static int      numeric = 0;
26   static int      sepc = '\n';
27  
28  
# Line 33 | Line 36 | usage_exit(int code)
36                          stderr);
37          fputs("   Or: ", stderr);
38          fputs(progname, stderr);
39 <        fputs(" -r [-i][-u][-h][-H][-tS] input.idx [output.txt]\n", stderr);
39 >        fputs(" -r [-i][-u][-h][-H][-l][-n][-tS] input.idx [output.txt]\n",
40 >                        stderr);
41          exit(code);
42   }
43  
# Line 206 | Line 210 | memerr:
210   }
211  
212  
213 + /* print out table IDs */
214 + void
215 + print_IDs(IDMAP *idmp)
216 + {
217 +        int     i;
218 +
219 +        printf("============ %d IDs ============\n", idmp->nids);
220 +
221 +        for (i = 0; i < idmp->nids; i++)
222 +                puts(mapID(idmp, i));
223 +
224 +        puts("============= END =============");
225 + }
226 +
227 +
228   /* Load selected pixels from identifier index file */
229   int
230   decode_select(const char *fname, int hdrflags)
# Line 216 | Line 235 | decode_select(const char *fname, int hdrflags)
235          if (!idmp)
236                  return 0;
237  
238 +        if (hdrflags & HF_TABLOUT)
239 +                print_IDs(idmp);
240 +
241          if (idmp->res.rt != PIXSTANDARD) {
242                  fputs(progname, stderr);
243                  fputs(": can only handle standard pixel ordering\n", stderr);
# Line 223 | Line 245 | decode_select(const char *fname, int hdrflags)
245                  return 0;
246          }
247          while (scanf("%d %d", &x, &y) == 2) {
248 <                const char      *id;
249 <
228 <                if ((x < 0) | (y < 0) |
229 <                                (x >= idmp->res.xr) | (y >= idmp->res.yr)) {
248 >                x = idmap_seek(idmp, x, idmp->res.yr-1 - y);
249 >                if (!x) {
250                          fputs(progname, stderr);
251                          fputs(": warning - pixel index is off map\n", stderr);
252                          continue;
253                  }
254 <                y = idmp->res.yr-1 - y;
255 <
256 <                if (!(id = idmap_pix(idmp, x, y))) {
254 >                if (x > 0)
255 >                        x = idmap_next_i(idmp);
256 >                if (x < 0) {
257 >                        fputs(fname, stderr);
258 >                        fputs(": read/seek error in decode_select()\n", stderr);
259                          idmap_close(idmp);
260                          return 0;
261                  }
262 <                fputs(id, stdout);
262 >                if (numeric) {
263 >                        printf("%d", x);
264 >                } else {
265 >                        const char      *id = mapID(idmp, x);
266 >                        if (!id) {
267 >                                fputs(fname, stderr);
268 >                                fputs(": bad ID index in file\n", stderr);
269 >                                idmap_close(idmp);
270 >                                return 0;
271 >                        }
272 >                        fputs(id, stdout);
273 >                }
274                  putchar(sepc);
275                  if (unbuffered && fflush(stdout) == EOF) {
276                          fputs(progname, stderr);
# Line 267 | Line 300 | decode_all(const char *fname, int hdrflags)
300          if (!idmp)
301                  return 0;
302  
303 +        if (hdrflags & HF_TABLOUT)
304 +                print_IDs(idmp);
305 +
306          for (n = idmp->res.xr*idmp->res.yr; n-- > 0; ) {
307 <                const char      *id = idmap_next(idmp);
308 <                if (!id) {
307 >                int     ndx = idmap_next_i(idmp);
308 >                if (ndx < 0) {
309                          fputs(fname, stderr);
310                          fputs(": unexpected EOF\n", stderr);
311                          idmap_close(idmp);
312                          return 0;
313                  }
314 <                fputs(id, stdout);
314 >                if (numeric) {
315 >                        printf("%d", ndx);
316 >                } else {
317 >                        const char      *id = idmap_next(idmp);
318 >                        if (!id) {
319 >                                fputs(fname, stderr);
320 >                                fputs(": bad ID index in file\n", stderr);
321 >                                idmap_close(idmp);
322 >                                return 0;
323 >                        }
324 >                        fputs(id, stdout);
325 >                }
326                  putchar(sepc);
327          }
328          idmap_close(idmp);
# Line 305 | Line 352 | main(int argc, char *argv[])
352                          break;
353                  case 'u':
354                          unbuffered++;
355 +                        break;
356 +                case 'n':
357 +                        numeric++;
358 +                        break;
359 +                case 'l':
360 +                        hdrflags |= HF_TABLOUT;
361                          break;
362                  case 'h':
363                          hdrflags &= ~HF_HEADOUT;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines