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.7 by greg, Wed Jul 24 17:50:32 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 +                fputs(mapID(idmp, i), stdout);
227 +                putchar(sepc);
228 +        }
229 +        if (sepc != '\n')
230 +                fputc('\n', stdout);
231 +        puts("============= END =============");
232 + }
233 +
234 +
235   /* Load selected pixels from identifier index file */
236   int
237   decode_select(const char *fname, int hdrflags)
238   {
239          IDMAP   *idmp = idmap_ropen(fname, hdrflags);
240 <        int     x, y;
240 >        int     i, j;
241  
242          if (!idmp)
243                  return 0;
244  
245 +        if (hdrflags & HF_TABLOUT)
246 +                print_IDs(idmp);
247 +
248          if (idmp->res.rt != PIXSTANDARD) {
249                  fputs(progname, stderr);
250                  fputs(": can only handle standard pixel ordering\n", stderr);
251                  idmap_close(idmp);
252                  return 0;
253          }
254 <        while (scanf("%d %d", &x, &y) == 2) {
255 <                const char      *id;
256 <
228 <                if ((x < 0) | (y < 0) |
229 <                                (x >= idmp->res.xr) | (y >= idmp->res.yr)) {
254 >        while (scanf("%d %d", &i, &j) == 2) {
255 >                i = idmap_seek(idmp, i, idmp->res.yr-1 - j);
256 >                if (!i) {
257                          fputs(progname, stderr);
258                          fputs(": warning - pixel index is off map\n", stderr);
259                          continue;
260                  }
261 <                y = idmp->res.yr-1 - y;
262 <
263 <                if (!(id = idmap_pix(idmp, x, y))) {
261 >                if (i > 0)
262 >                        i = idmap_next_i(idmp);
263 >                if (i < 0) {
264 >                        fputs(fname, stderr);
265 >                        fputs(": read/seek error in decode_select()\n", stderr);
266                          idmap_close(idmp);
267                          return 0;
268                  }
269 <                fputs(id, stdout);
269 >                if (numeric) {
270 >                        printf("%d", i);
271 >                } else {
272 >                        const char      *id = mapID(idmp, i);
273 >                        if (!id) {
274 >                                fputs(fname, stderr);
275 >                                fputs(": bad ID index in file\n", stderr);
276 >                                idmap_close(idmp);
277 >                                return 0;
278 >                        }
279 >                        fputs(id, stdout);
280 >                }
281                  putchar(sepc);
282                  if (unbuffered && fflush(stdout) == EOF) {
283                          fputs(progname, stderr);
# Line 267 | Line 307 | decode_all(const char *fname, int hdrflags)
307          if (!idmp)
308                  return 0;
309  
310 +        if (hdrflags & HF_TABLOUT)
311 +                print_IDs(idmp);
312 +
313          for (n = idmp->res.xr*idmp->res.yr; n-- > 0; ) {
314 <                const char      *id = idmap_next(idmp);
315 <                if (!id) {
314 >                const int       ndx = idmap_next_i(idmp);
315 >                if (ndx < 0) {
316                          fputs(fname, stderr);
317                          fputs(": unexpected EOF\n", stderr);
318                          idmap_close(idmp);
319                          return 0;
320                  }
321 <                fputs(id, stdout);
321 >                if (numeric) {
322 >                        printf("%d", ndx);
323 >                } else {
324 >                        const char      *id = mapID(idmp, ndx);
325 >                        if (!id) {
326 >                                fputs(fname, stderr);
327 >                                fputs(": bad ID index in file\n", stderr);
328 >                                idmap_close(idmp);
329 >                                return 0;
330 >                        }
331 >                        fputs(id, stdout);
332 >                }
333                  putchar(sepc);
334          }
335          idmap_close(idmp);
# Line 305 | Line 359 | main(int argc, char *argv[])
359                          break;
360                  case 'u':
361                          unbuffered++;
362 +                        break;
363 +                case 'n':
364 +                        numeric++;
365 +                        break;
366 +                case 'l':
367 +                        hdrflags |= HF_TABLOUT;
368                          break;
369                  case 'h':
370                          hdrflags &= ~HF_HEADOUT;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines