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.6 by greg, Wed Jul 24 00:25:51 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 87 | Line 91 | create_index(const char *fname, int hdrflags, int ndxb
91          char    **idmap;
92          int     idmlen;
93          int     nextID = 0;
94 <        LUTAB   hashtab = LU_SINIT(free,NULL);
94 >        LUTAB   hashtab;
95          RESOLU  rs;
96          long    n;
97          int     ndx;
# Line 130 | Line 134 | create_index(const char *fname, int hdrflags, int ndxb
134                  fputs(": unsupported bits/pixel\n", stderr);
135                  return 0;
136          }
137 +        memset(&hashtab, 0, sizeof(hashtab));
138 +        hashtab.hashf = lu_shash;
139 +        hashtab.keycmp = strcmp;
140 +        hashtab.freek = free;
141          if (!idmap || !lu_init(&hashtab, idmlen))
142                  goto memerr;
143          fputc('\n', stdout);            /* end of info header */
# Line 206 | Line 214 | memerr:
214   }
215  
216  
217 + /* print out ID table */
218 + void
219 + print_IDs(IDMAP *idmp)
220 + {
221 +        int     i;
222 +
223 +        printf("============ %d IDs ============\n", idmp->nids);
224 +
225 +        for (i = 0; i < idmp->nids; i++)
226 +                puts(mapID(idmp, i));
227 +
228 +        puts("============= END =============");
229 + }
230 +
231 +
232   /* Load selected pixels from identifier index file */
233   int
234   decode_select(const char *fname, int hdrflags)
235   {
236          IDMAP   *idmp = idmap_ropen(fname, hdrflags);
237 <        int     x, y;
237 >        int     i, j;
238  
239          if (!idmp)
240                  return 0;
241  
242 +        if (hdrflags & HF_TABLOUT)
243 +                print_IDs(idmp);
244 +
245          if (idmp->res.rt != PIXSTANDARD) {
246                  fputs(progname, stderr);
247                  fputs(": can only handle standard pixel ordering\n", stderr);
248                  idmap_close(idmp);
249                  return 0;
250          }
251 <        while (scanf("%d %d", &x, &y) == 2) {
252 <                const char      *id;
253 <
228 <                if ((x < 0) | (y < 0) |
229 <                                (x >= idmp->res.xr) | (y >= idmp->res.yr)) {
251 >        while (scanf("%d %d", &i, &j) == 2) {
252 >                i = idmap_seek(idmp, i, idmp->res.yr-1 - j);
253 >                if (!i) {
254                          fputs(progname, stderr);
255                          fputs(": warning - pixel index is off map\n", stderr);
256                          continue;
257                  }
258 <                y = idmp->res.yr-1 - y;
259 <
260 <                if (!(id = idmap_pix(idmp, x, y))) {
258 >                if (i > 0)
259 >                        i = idmap_next_i(idmp);
260 >                if (i < 0) {
261 >                        fputs(fname, stderr);
262 >                        fputs(": read/seek error in decode_select()\n", stderr);
263                          idmap_close(idmp);
264                          return 0;
265                  }
266 <                fputs(id, stdout);
266 >                if (numeric) {
267 >                        printf("%d", i);
268 >                } else {
269 >                        const char      *id = mapID(idmp, i);
270 >                        if (!id) {
271 >                                fputs(fname, stderr);
272 >                                fputs(": bad ID index in file\n", stderr);
273 >                                idmap_close(idmp);
274 >                                return 0;
275 >                        }
276 >                        fputs(id, stdout);
277 >                }
278                  putchar(sepc);
279                  if (unbuffered && fflush(stdout) == EOF) {
280                          fputs(progname, stderr);
# Line 267 | Line 304 | decode_all(const char *fname, int hdrflags)
304          if (!idmp)
305                  return 0;
306  
307 +        if (hdrflags & HF_TABLOUT)
308 +                print_IDs(idmp);
309 +
310          for (n = idmp->res.xr*idmp->res.yr; n-- > 0; ) {
311 <                const char      *id = idmap_next(idmp);
312 <                if (!id) {
311 >                const int       ndx = idmap_next_i(idmp);
312 >                if (ndx < 0) {
313                          fputs(fname, stderr);
314                          fputs(": unexpected EOF\n", stderr);
315                          idmap_close(idmp);
316                          return 0;
317                  }
318 <                fputs(id, stdout);
318 >                if (numeric) {
319 >                        printf("%d", ndx);
320 >                } else {
321 >                        const char      *id = mapID(idmp, ndx);
322 >                        if (!id) {
323 >                                fputs(fname, stderr);
324 >                                fputs(": bad ID index in file\n", stderr);
325 >                                idmap_close(idmp);
326 >                                return 0;
327 >                        }
328 >                        fputs(id, stdout);
329 >                }
330                  putchar(sepc);
331          }
332          idmap_close(idmp);
# Line 305 | Line 356 | main(int argc, char *argv[])
356                          break;
357                  case 'u':
358                          unbuffered++;
359 +                        break;
360 +                case 'n':
361 +                        numeric++;
362 +                        break;
363 +                case 'l':
364 +                        hdrflags |= HF_TABLOUT;
365                          break;
366                  case 'h':
367                          hdrflags &= ~HF_HEADOUT;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines