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.9 by greg, Tue Feb 11 18:15:23 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 (strstr(dcp->inpfmt, "ascii") != NULL)
49                          dcp->format = 'a';
50 <                else if (strcasestr(dcp->inpfmt, "float") != NULL)
50 >                else if (strstr(dcp->inpfmt, "float") != NULL)
51                          dcp->format = 'f';
52 <                else if (strcasestr(dcp->inpfmt, "double") != NULL)
52 >                else if (strstr(dcp->inpfmt, "double") != NULL)
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)
61 <                nexpected = (long)dcp->res.xr * dcp->res.yr;
62 >
63          do {
64                  int     ok = 0;
65                  float   f;
# Line 70 | Line 71 | encode_depths(DEPTHCODEC *dcp)
71                          break;
72                  case 'f':
73                          ok = (getbinary(&f, sizeof(f), 1, dcp->finp) == 1);
74 +                        if (dcp->swapped)
75 +                                swap32((char *)&f, 1);
76                          d = f;
77                          break;
78                  case 'd':
79                          ok = (getbinary(&d, sizeof(d), 1, dcp->finp) == 1);
80 +                        if (dcp->swapped)
81 +                                swap64((char *)&d, 1);
82                          break;
83                  }
84                  if (!ok)
85                          break;
86 +
87                  putint(depth2code(d, dcp->refdepth), 2, stdout);
88 +
89          } while (--nexpected);
90  
91          if (nexpected > 0) {
# Line 90 | Line 97 | encode_depths(DEPTHCODEC *dcp)
97   }
98  
99  
100 < /* Convert and output the given depth code to stdout */
100 > /* Convert and output the given depth to stdout */
101   static void
102   output_depth(DEPTHCODEC *dcp, double d)
103   {
# Line 115 | Line 122 | output_depth(DEPTHCODEC *dcp, double d)
122   static int
123   decode_depths(DEPTHCODEC *dcp)
124   {
125 <        long    nexpected = 0;
125 >        long    nexpected = (long)dcp->res.xr * dcp->res.yr;
126  
127          if (!check_decode_depths(dcp))
128                  return 0;
129  
123        if (dcp->hdrflags & HF_RESIN)
124                nexpected = (long)dcp->res.xr * dcp->res.yr;
130          do {
131 <                double  d = decode_depth_next(dcp);            
131 >                double  d = decode_depth_next(dcp);
132                  if (d < -FTINY)
133                          break;
134                  output_depth(dcp, d);
# Line 155 | 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 +
167                  d = decode_depth_pix(dcp, xy[0], xy[1]);
168                  if (d < -FTINY)
169                          return 0;
170 +
171                  output_depth(dcp, d);
172 +
173                  if (unbuf && fflush(stdout) == EOF) {
174                          fputs(progname, stderr);
175                          fputs(": write error on output\n", stderr);
# Line 176 | Line 185 | pixel_depths(DEPTHCODEC *dcp, int unbuf)
185   }
186  
187  
188 < /* Output the given world position */
188 > /* Output the given world position to stdout */
189   static void
190   output_worldpos(DEPTHCODEC *dcp, FVECT wpos)
191   {
192          switch (dcp->format) {
193          case 'a':
194 <                fprintf(stdout, "%.5e %.5e %.5e\n",
186 <                                wpos[0], wpos[1], wpos[2]);
194 >                printf("%.5e %.5e %.5e\n", wpos[0], wpos[1], wpos[2]);
195                  break;
196   #ifdef SMLFLT
197          case 'f':
# Line 273 | Line 281 | pixel_points(DEPTHCODEC *dcp, int unbuf)
281   int
282   main(int argc, char *argv[])
283   {
284 +        int             xres=0, yres=0;
285          int             conversion = CV_FWD;
286          int             bypixel = 0;
287          int             unbuffered = 0;
# Line 346 | Line 355 | main(int argc, char *argv[])
355                                  usage_exit(1);
356                          }
357                          break;
358 +                case 'x':
359 +                        xres = atoi(argv[++a]);
360 +                        break;
361 +                case 'y':
362 +                        yres = atoi(argv[++a]);
363 +                        break;
364                  case 'i':
365                          bypixel++;
366                          break;
# Line 357 | Line 372 | main(int argc, char *argv[])
372                  }
373          dc.hdrflags |= (conversion == CV_FWD) * HF_ENCODE;
374  
375 <        if ((dc.hdrflags & (HF_RESIN|HF_RESOUT)) == HF_RESOUT) {
375 >        if ((xres > 0) & (yres > 0)) {
376 >                dc.hdrflags &= ~HF_RESIN;
377 >                dc.res.rt = PIXSTANDARD;
378 >                dc.res.xr = xres;
379 >                dc.res.yr = yres;
380 >        } else if ((dc.hdrflags & (HF_RESIN|HF_RESOUT)) == HF_RESOUT) {
381                  fputs(progname, stderr);
382                  fputs(": unknown resolution for output\n", stderr);
383                  return 1;
# Line 379 | Line 399 | main(int argc, char *argv[])
399                          fputs(": -i option requires input resolution\n", stderr);
400                          usage_exit(1);
401                  }
402 <                dc.hdrflags &= ~(HF_HEADOUT|HF_RESOUT);
402 >                dc.hdrflags &= ~HF_RESOUT;
403          }
404          if (a < argc-2) {
405                  fputs(progname, stderr);
# Line 397 | Line 417 | main(int argc, char *argv[])
417                  return 1;
418          }
419          SET_FILE_BINARY(dc.finp);
420 <        SET_FILE_BINARY(stdout);
420 >        if ((conversion != CV_FWD) | (dc.format != 'a'))
421 >                SET_FILE_BINARY(stdout);
422   #ifdef getc_unlocked                    /* avoid stupid semaphores */
423          flockfile(dc.finp);
424          flockfile(stdout);
425   #endif
426                                          /* read/copy header */
427 <        if (!process_dc_header(&dc, argc, argv))
427 >        if (!process_dc_header(&dc, a, argv))
428                  return 1;
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