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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines