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.1 by greg, Thu Jul 18 18:51:56 2019 UTC vs.
Revision 2.11 by greg, Mon Jul 20 15:53:30 2020 UTC

# Line 2 | Line 2
2   static const char RCSid[] = "$Id$";
3   #endif
4   /*
5 < * Encode and decode depth values using 16-bit integers
5 > * Encode and decode depth map using 16-bit integers
6   */
7  
8   #include "copyright.h"
# 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 +
20   enum {CV_FWD, CV_REV, CV_PTS};
21  
22  
# Line 25 | 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]]\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);
34          fputs(
35 <        " {-r|-p} [-i][-u][-h[io]][-H[io]][-f[afd]] [input [output]]\n",
35 >        " {-r|-p} [-i][-u][-h[io]][-H[io]][-f[afd]] [input.dpt [output]]\n",
36                          stderr);
37          exit(code);
38   }
# Line 40 | Line 42 | usage_exit(int code)
42   static int
43   encode_depths(DEPTHCODEC *dcp)
44   {
45 <        long    nexpected = 0;
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 57 | Line 59 | encode_depths(DEPTHCODEC *dcp)
59                          return 0;
60                  }
61          }
62 <        if (dcp->hdrflags & HF_RESIN)
63 <                nexpected = (long)dcp->res.xr * dcp->res.yr;
62 >        if (dcp->format == 'a')
63 >                SET_FILE_TEXT(dcp->finp);
64 >
65          do {
66                  int     ok = 0;
67                  float   f;
# Line 70 | 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)
87                          break;
88 +
89                  putint(depth2code(d, dcp->refdepth), 2, stdout);
90 +
91          } while (--nexpected);
92  
93          if (nexpected > 0) {
# Line 90 | Line 99 | encode_depths(DEPTHCODEC *dcp)
99   }
100  
101  
102 < /* Convert and output the given depth code to stdout */
102 > /* Convert and output the given depth to stdout */
103   static void
104   output_depth(DEPTHCODEC *dcp, double d)
105   {
# Line 115 | Line 124 | output_depth(DEPTHCODEC *dcp, double d)
124   static int
125   decode_depths(DEPTHCODEC *dcp)
126   {
127 <        long    nexpected = 0;
127 >        long    nexpected = (long)dcp->res.xr * dcp->res.yr;
128  
129          if (!check_decode_depths(dcp))
130                  return 0;
131  
123        if (dcp->hdrflags & HF_RESIN)
124                nexpected = (long)dcp->res.xr * dcp->res.yr;
132          do {
133 <                double  d = decode_depth_next(dcp);            
133 >                double  d = decode_depth_next(dcp);
134                  if (d < -FTINY)
135                          break;
136                  output_depth(dcp, d);
# Line 155 | 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,
167                          (xy[0]+.5)/dcp->res.xr, (xy[1]+.5)/dcp->res.yr);
168 +
169                  d = decode_depth_pix(dcp, xy[0], xy[1]);
170                  if (d < -FTINY)
171                          return 0;
172 +
173                  output_depth(dcp, d);
174 +
175                  if (unbuf && fflush(stdout) == EOF) {
176                          fputs(progname, stderr);
177                          fputs(": write error on output\n", stderr);
# Line 176 | Line 187 | pixel_depths(DEPTHCODEC *dcp, int unbuf)
187   }
188  
189  
190 < /* Output the given world position */
190 > /* Output the given world position to stdout */
191   static void
192   output_worldpos(DEPTHCODEC *dcp, FVECT wpos)
193   {
194          switch (dcp->format) {
195          case 'a':
196 <                fprintf(stdout, "%.5e %.5e %.5e\n",
186 <                                wpos[0], wpos[1], wpos[2]);
196 >                printf("%.5e %.5e %.5e\n", wpos[0], wpos[1], wpos[2]);
197                  break;
198   #ifdef SMLFLT
199          case 'f':
# Line 248 | Line 258 | pixel_points(DEPTHCODEC *dcp, int unbuf)
258          }
259          if (!check_decode_worldpos(dcp))
260                  return 0;
261 <        
261 >
262          while (scanf("%d %d", &xy[0], &xy[1]) == 2) {
263                  loc2pix(xy, &dcp->res,
264                          (xy[0]+.5)/dcp->res.xr, (xy[1]+.5)/dcp->res.yr);
# Line 273 | Line 283 | pixel_points(DEPTHCODEC *dcp, int unbuf)
283   int
284   main(int argc, char *argv[])
285   {
286 +        int             xres=0, yres=0;
287          int             conversion = CV_FWD;
288          int             bypixel = 0;
289          int             unbuffered = 0;
# Line 346 | Line 357 | main(int argc, char *argv[])
357                                  usage_exit(1);
358                          }
359                          break;
360 +                case 'x':
361 +                        xres = atoi(argv[++a]);
362 +                        break;
363 +                case 'y':
364 +                        yres = atoi(argv[++a]);
365 +                        break;
366                  case 'i':
367                          bypixel++;
368                          break;
# Line 357 | Line 374 | main(int argc, char *argv[])
374                  }
375          dc.hdrflags |= (conversion == CV_FWD) * HF_ENCODE;
376  
377 <        if ((dc.hdrflags & (HF_RESIN|HF_RESOUT)) == HF_RESOUT) {
377 >        if ((xres > 0) & (yres > 0)) {
378 >                dc.hdrflags &= ~HF_RESIN;
379 >                dc.res.rt = PIXSTANDARD;
380 >                dc.res.xr = xres;
381 >                dc.res.yr = yres;
382 >        } else if ((dc.hdrflags & (HF_RESIN|HF_RESOUT)) == HF_RESOUT) {
383                  fputs(progname, stderr);
384                  fputs(": unknown resolution for output\n", stderr);
385                  return 1;
# Line 379 | Line 401 | main(int argc, char *argv[])
401                          fputs(": -i option requires input resolution\n", stderr);
402                          usage_exit(1);
403                  }
404 <                dc.hdrflags &= ~(HF_HEADOUT|HF_RESOUT);
404 >                dc.hdrflags &= ~HF_RESOUT;
405          }
406          if (a < argc-2) {
407                  fputs(progname, stderr);
# Line 396 | Line 418 | main(int argc, char *argv[])
418                  fputs(": cannot open for writing\n", stderr);
419                  return 1;
420          }
421 <        SET_FILE_BINARY(dc.finp);
421 >        SET_FILE_BINARY(dc.finp);       /* starting assumption */
422          SET_FILE_BINARY(stdout);
423   #ifdef getc_unlocked                    /* avoid stupid semaphores */
424          flockfile(dc.finp);
425          flockfile(stdout);
426   #endif
427                                          /* read/copy header */
428 <        if (!process_dc_header(&dc, argc, argv))
428 >        if (!process_dc_header(&dc, a, argv))
429                  return 1;
430 +                
431 +        if ((conversion != CV_FWD) & (dc.format == 'a'))
432 +                SET_FILE_TEXT(stdout);
433                                          /* process data */
434          switch (conversion) {
435          case CV_FWD:                    /* distance -> depth code */
436 +                if (!strcmp(dc.depth_unit, "1")) {
437 +                        fputs(progname, stderr);
438 +                        fputs(": warning - using reference depth of 1.0\n",
439 +                                        stderr);
440 +                }
441                  if (!encode_depths(&dc))
442                          return 1;
443                  break;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines