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

Comparing ray/src/util/rcode_depth.c (file contents):
Revision 2.4 by greg, Sat Jul 20 02:07:23 2019 UTC vs.
Revision 2.12 by greg, Thu Jun 30 00:16:49 2022 UTC

# Line 27 | Line 27 | usage_exit(int code)
27          fputs("Usage: ", stderr);
28          fputs(progname, stderr);
29          fputs(
30 <        " [-d ref_depth/unit][-h[io]][-H[io]][-f[afd]] [input [output.dpt]]\n",
30 >        " [-d ref_depth/unit][-h[io]][-H[io]][-f[afd]][-x xr -y yr] [input [output.dpt]]\n",
31                          stderr);
32          fputs("   Or: ", stderr);
33          fputs(progname, stderr);
# Line 45 | Line 45 | encode_depths(DEPTHCODEC *dcp)
45          long    nexpected = (long)dcp->res.xr * dcp->res.yr;
46  
47          if (dcp->inpfmt[0]) {
48 <                if (strcasestr(dcp->inpfmt, "ascii") != NULL)
48 >                if (!strcmp(dcp->inpfmt, "ascii"))
49                          dcp->format = 'a';
50 <                else if (strcasestr(dcp->inpfmt, "float") != NULL)
50 >                else if (!strcmp(dcp->inpfmt, "float"))
51                          dcp->format = 'f';
52 <                else if (strcasestr(dcp->inpfmt, "double") != NULL)
52 >                else if (!strcmp(dcp->inpfmt, "double"))
53                          dcp->format = 'd';
54                  else {
55                          fputs(dcp->inpname, stderr);
# Line 59 | Line 59 | encode_depths(DEPTHCODEC *dcp)
59                          return 0;
60                  }
61          }
62 +        if (dcp->format == 'a')
63 +                SET_FILE_TEXT(dcp->finp);
64  
65          do {
66                  int     ok = 0;
# Line 71 | Line 73 | encode_depths(DEPTHCODEC *dcp)
73                          break;
74                  case 'f':
75                          ok = (getbinary(&f, sizeof(f), 1, dcp->finp) == 1);
76 +                        if (dcp->swapped)
77 +                                swap32((char *)&f, 1);
78                          d = f;
79                          break;
80                  case 'd':
81                          ok = (getbinary(&d, sizeof(d), 1, dcp->finp) == 1);
82 +                        if (dcp->swapped)
83 +                                swap64((char *)&d, 1);
84                          break;
85                  }
86                  if (!ok)
# Line 156 | Line 162 | pixel_depths(DEPTHCODEC *dcp, int unbuf)
162                  return 0;
163  
164          while (scanf("%d %d", &xy[0], &xy[1]) == 2) {
165 <
166 <                loc2pix(xy, &dcp->res,
161 <                        (xy[0]+.5)/dcp->res.xr, (xy[1]+.5)/dcp->res.yr);
162 <
165 >                loc2pix(xy, &dcp->res, xy[0]/(double)dcp->res.xr,
166 >                                xy[1]/(double)dcp->res.yr);
167                  d = decode_depth_pix(dcp, xy[0], xy[1]);
168                  if (d < -FTINY)
169                          return 0;
166
170                  output_depth(dcp, d);
168
171                  if (unbuf && fflush(stdout) == EOF) {
172                          fputs(progname, stderr);
173                          fputs(": write error on output\n", stderr);
# Line 252 | Line 254 | pixel_points(DEPTHCODEC *dcp, int unbuf)
254          }
255          if (!check_decode_worldpos(dcp))
256                  return 0;
257 <        
257 >
258          while (scanf("%d %d", &xy[0], &xy[1]) == 2) {
259 <                loc2pix(xy, &dcp->res,
260 <                        (xy[0]+.5)/dcp->res.xr, (xy[1]+.5)/dcp->res.yr);
259 >                loc2pix(xy, &dcp->res, xy[0]/(double)dcp->res.xr,
260 >                                xy[1]/(double)dcp->res.yr);
261                  if (get_worldpos_pix(wpos, dcp, xy[0], xy[1]) < 0)
262                          return 0;
263                  output_worldpos(dcp, wpos);
# Line 277 | Line 279 | pixel_points(DEPTHCODEC *dcp, int unbuf)
279   int
280   main(int argc, char *argv[])
281   {
282 +        int             xres=0, yres=0;
283          int             conversion = CV_FWD;
284          int             bypixel = 0;
285          int             unbuffered = 0;
# Line 350 | Line 353 | main(int argc, char *argv[])
353                                  usage_exit(1);
354                          }
355                          break;
356 +                case 'x':
357 +                        xres = atoi(argv[++a]);
358 +                        break;
359 +                case 'y':
360 +                        yres = atoi(argv[++a]);
361 +                        break;
362                  case 'i':
363                          bypixel++;
364                          break;
# Line 361 | Line 370 | main(int argc, char *argv[])
370                  }
371          dc.hdrflags |= (conversion == CV_FWD) * HF_ENCODE;
372  
373 <        if ((dc.hdrflags & (HF_RESIN|HF_RESOUT)) == HF_RESOUT) {
373 >        if ((xres > 0) & (yres > 0)) {
374 >                dc.hdrflags &= ~HF_RESIN;
375 >                dc.res.rt = PIXSTANDARD;
376 >                dc.res.xr = xres;
377 >                dc.res.yr = yres;
378 >        } else if ((dc.hdrflags & (HF_RESIN|HF_RESOUT)) == HF_RESOUT) {
379                  fputs(progname, stderr);
380                  fputs(": unknown resolution for output\n", stderr);
381                  return 1;
# Line 400 | Line 414 | main(int argc, char *argv[])
414                  fputs(": cannot open for writing\n", stderr);
415                  return 1;
416          }
417 <        SET_FILE_BINARY(dc.finp);
418 <        if ((conversion != CV_FWD) | (dc.format != 'a'))
405 <                SET_FILE_BINARY(stdout);
417 >        SET_FILE_BINARY(dc.finp);       /* starting assumption */
418 >        SET_FILE_BINARY(stdout);
419   #ifdef getc_unlocked                    /* avoid stupid semaphores */
420          flockfile(dc.finp);
421          flockfile(stdout);
# Line 410 | Line 423 | main(int argc, char *argv[])
423                                          /* read/copy header */
424          if (!process_dc_header(&dc, a, argv))
425                  return 1;
426 +                
427 +        if ((conversion != CV_FWD) & (dc.format == 'a'))
428 +                SET_FILE_TEXT(stdout);
429                                          /* process data */
430          switch (conversion) {
431          case CV_FWD:                    /* distance -> depth code */
432 +                if (!strcmp(dc.depth_unit, "1")) {
433 +                        fputs(progname, stderr);
434 +                        fputs(": warning - using reference depth of 1.0\n",
435 +                                        stderr);
436 +                }
437                  if (!encode_depths(&dc))
438                          return 1;
439                  break;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines