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.6 by greg, Wed Aug 14 21:00:14 2019 UTC vs.
Revision 2.13 by greg, Tue Jun 3 21:31:51 2025 UTC

# Line 15 | Line 15 | static const char RCSid[] = "$Id$";
15   #include "fvect.h"
16   #include "depthcodec.h"
17  
18 char            *progname;              /* set in main() */
19
18   enum {CV_FWD, CV_REV, CV_PTS};
19  
20  
# Line 27 | Line 25 | usage_exit(int code)
25          fputs("Usage: ", stderr);
26          fputs(progname, stderr);
27          fputs(
28 <        " [-d ref_depth/unit][-h[io]][-H[io]][-f[afd]] [input [output.dpt]]\n",
28 >        " [-d ref_depth/unit][-h[io]][-H[io]][-f[afd]][-x xr -y yr] [input [output.dpt]]\n",
29                          stderr);
30          fputs("   Or: ", stderr);
31          fputs(progname, stderr);
# Line 45 | Line 43 | encode_depths(DEPTHCODEC *dcp)
43          long    nexpected = (long)dcp->res.xr * dcp->res.yr;
44  
45          if (dcp->inpfmt[0]) {
46 <                if (strstr(dcp->inpfmt, "ascii") != NULL)
46 >                if (!strcmp(dcp->inpfmt, "ascii"))
47                          dcp->format = 'a';
48 <                else if (strstr(dcp->inpfmt, "float") != NULL)
48 >                else if (!strcmp(dcp->inpfmt, "float"))
49                          dcp->format = 'f';
50 <                else if (strstr(dcp->inpfmt, "double") != NULL)
50 >                else if (!strcmp(dcp->inpfmt, "double"))
51                          dcp->format = 'd';
52                  else {
53                          fputs(dcp->inpname, stderr);
# Line 59 | Line 57 | encode_depths(DEPTHCODEC *dcp)
57                          return 0;
58                  }
59          }
60 +        if (dcp->format == 'a')
61 +                SET_FILE_TEXT(dcp->finp);
62  
63          do {
64                  int     ok = 0;
# Line 160 | Line 160 | pixel_depths(DEPTHCODEC *dcp, int unbuf)
160                  return 0;
161  
162          while (scanf("%d %d", &xy[0], &xy[1]) == 2) {
163 <
164 <                loc2pix(xy, &dcp->res,
165 <                        (xy[0]+.5)/dcp->res.xr, (xy[1]+.5)/dcp->res.yr);
166 <
163 >                loc2pix(xy, &dcp->res, xy[0]/(double)dcp->res.xr,
164 >                                xy[1]/(double)dcp->res.yr);
165                  d = decode_depth_pix(dcp, xy[0], xy[1]);
166                  if (d < -FTINY)
167                          return 0;
170
168                  output_depth(dcp, d);
172
169                  if (unbuf && fflush(stdout) == EOF) {
170                          fputs(progname, stderr);
171                          fputs(": write error on output\n", stderr);
# Line 256 | Line 252 | pixel_points(DEPTHCODEC *dcp, int unbuf)
252          }
253          if (!check_decode_worldpos(dcp))
254                  return 0;
255 <        
255 >
256          while (scanf("%d %d", &xy[0], &xy[1]) == 2) {
257 <                loc2pix(xy, &dcp->res,
258 <                        (xy[0]+.5)/dcp->res.xr, (xy[1]+.5)/dcp->res.yr);
257 >                loc2pix(xy, &dcp->res, xy[0]/(double)dcp->res.xr,
258 >                                xy[1]/(double)dcp->res.yr);
259                  if (get_worldpos_pix(wpos, dcp, xy[0], xy[1]) < 0)
260                          return 0;
261                  output_worldpos(dcp, wpos);
# Line 281 | Line 277 | pixel_points(DEPTHCODEC *dcp, int unbuf)
277   int
278   main(int argc, char *argv[])
279   {
280 +        int             xres=0, yres=0;
281          int             conversion = CV_FWD;
282          int             bypixel = 0;
283          int             unbuffered = 0;
284          DEPTHCODEC      dc;
285          int             a;
286 <
287 <        progname = argv[0];
286 >                                        /* set global progname */
287 >        fixargv0(argv[0]);
288          set_dc_defaults(&dc);
289          dc.hdrflags = HF_ALL;
290          for (a = 1; a < argc && argv[a][0] == '-'; a++)
# Line 354 | Line 351 | main(int argc, char *argv[])
351                                  usage_exit(1);
352                          }
353                          break;
354 +                case 'x':
355 +                        xres = atoi(argv[++a]);
356 +                        break;
357 +                case 'y':
358 +                        yres = atoi(argv[++a]);
359 +                        break;
360                  case 'i':
361                          bypixel++;
362                          break;
# Line 365 | Line 368 | main(int argc, char *argv[])
368                  }
369          dc.hdrflags |= (conversion == CV_FWD) * HF_ENCODE;
370  
371 <        if ((dc.hdrflags & (HF_RESIN|HF_RESOUT)) == HF_RESOUT) {
371 >        if ((xres > 0) & (yres > 0)) {
372 >                dc.hdrflags &= ~HF_RESIN;
373 >                dc.res.rt = PIXSTANDARD;
374 >                dc.res.xr = xres;
375 >                dc.res.yr = yres;
376 >        } else if ((dc.hdrflags & (HF_RESIN|HF_RESOUT)) == HF_RESOUT) {
377                  fputs(progname, stderr);
378                  fputs(": unknown resolution for output\n", stderr);
379                  return 1;
# Line 404 | Line 412 | main(int argc, char *argv[])
412                  fputs(": cannot open for writing\n", stderr);
413                  return 1;
414          }
415 <        SET_FILE_BINARY(dc.finp);
416 <        if ((conversion != CV_FWD) | (dc.format != 'a'))
409 <                SET_FILE_BINARY(stdout);
415 >        SET_FILE_BINARY(dc.finp);       /* starting assumption */
416 >        SET_FILE_BINARY(stdout);
417   #ifdef getc_unlocked                    /* avoid stupid semaphores */
418          flockfile(dc.finp);
419          flockfile(stdout);
# Line 414 | Line 421 | main(int argc, char *argv[])
421                                          /* read/copy header */
422          if (!process_dc_header(&dc, a, argv))
423                  return 1;
424 +                
425 +        if ((conversion != CV_FWD) & (dc.format == 'a'))
426 +                SET_FILE_TEXT(stdout);
427                                          /* process data */
428          switch (conversion) {
429          case CV_FWD:                    /* distance -> depth code */
430 +                if (!strcmp(dc.depth_unit, "1")) {
431 +                        fputs(progname, stderr);
432 +                        fputs(": warning - using reference depth of 1.0\n",
433 +                                        stderr);
434 +                }
435                  if (!encode_depths(&dc))
436                          return 1;
437                  break;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines