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.2 by greg, Thu Jul 18 19:13:44 2019 UTC vs.
Revision 2.3 by greg, Fri Jul 19 01:24:33 2019 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 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)
# 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 78 | Line 79 | encode_depths(DEPTHCODEC *dcp)
79                  }
80                  if (!ok)
81                          break;
82 +
83                  putint(depth2code(d, dcp->refdepth), 2, stdout);
84 +
85          } while (--nexpected);
86  
87          if (nexpected > 0) {
# Line 90 | Line 93 | encode_depths(DEPTHCODEC *dcp)
93   }
94  
95  
96 < /* Convert and output the given depth code to stdout */
96 > /* Convert and output the given depth to stdout */
97   static void
98   output_depth(DEPTHCODEC *dcp, double d)
99   {
# Line 115 | Line 118 | output_depth(DEPTHCODEC *dcp, double d)
118   static int
119   decode_depths(DEPTHCODEC *dcp)
120   {
121 <        long    nexpected = 0;
121 >        long    nexpected = (long)dcp->res.xr * dcp->res.yr;
122  
123          if (!check_decode_depths(dcp))
124                  return 0;
125  
123        if (dcp->hdrflags & HF_RESIN)
124                nexpected = (long)dcp->res.xr * dcp->res.yr;
126          do {
127 <                double  d = decode_depth_next(dcp);            
127 >                double  d = decode_depth_next(dcp);
128                  if (d < -FTINY)
129                          break;
130                  output_depth(dcp, d);
# Line 155 | Line 156 | pixel_depths(DEPTHCODEC *dcp, int unbuf)
156                  return 0;
157  
158          while (scanf("%d %d", &xy[0], &xy[1]) == 2) {
159 +
160                  loc2pix(xy, &dcp->res,
161                          (xy[0]+.5)/dcp->res.xr, (xy[1]+.5)/dcp->res.yr);
162 +
163                  d = decode_depth_pix(dcp, xy[0], xy[1]);
164                  if (d < -FTINY)
165                          return 0;
166 +
167                  output_depth(dcp, d);
168 +
169                  if (unbuf && fflush(stdout) == EOF) {
170                          fputs(progname, stderr);
171                          fputs(": write error on output\n", stderr);
# Line 176 | Line 181 | pixel_depths(DEPTHCODEC *dcp, int unbuf)
181   }
182  
183  
184 < /* Output the given world position */
184 > /* Output the given world position to stdout */
185   static void
186   output_worldpos(DEPTHCODEC *dcp, FVECT wpos)
187   {
188          switch (dcp->format) {
189          case 'a':
190 <                fprintf(stdout, "%.5e %.5e %.5e\n",
186 <                                wpos[0], wpos[1], wpos[2]);
190 >                printf("%.5e %.5e %.5e\n", wpos[0], wpos[1], wpos[2]);
191                  break;
192   #ifdef SMLFLT
193          case 'f':
# Line 397 | Line 401 | main(int argc, char *argv[])
401                  return 1;
402          }
403          SET_FILE_BINARY(dc.finp);
404 <        SET_FILE_BINARY(stdout);
404 >        if ((conversion != CV_FWD) | (dc.format != 'a'))
405 >                SET_FILE_BINARY(stdout);
406   #ifdef getc_unlocked                    /* avoid stupid semaphores */
407          flockfile(dc.finp);
408          flockfile(stdout);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines