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

Comparing ray/src/common/depthcodec.c (file contents):
Revision 2.3 by greg, Fri Jul 26 18:52:32 2019 UTC vs.
Revision 2.11 by greg, Tue Jan 26 18:47:25 2021 UTC

# Line 8 | Line 8 | static const char RCSid[] = "$Id$";
8   #include "copyright.h"
9  
10   #include <stdlib.h>
11 #include <string.h>
11   #include <math.h>
12   #include <ctype.h>
13   #include "rtio.h"
# Line 27 | Line 26 | depth2code(double d, double dref)
26          if (d > dref)
27                  return (int)(32768.001 - 32768.*dref/d) - 1;
28  
29 <        return (int)(32767.*d/dref - 32768.);
29 >        return (int)(32767.*d/dref - 32768.999);
30   }
31   #endif
32  
# Line 42 | Line 41 | code2depth(int c, double dref)
41  
42          if (c >= 32767)
43                  return FHUGE;
44 <                
45 <        if (c < 0)
46 <                return dref*(32767.5 + c)*(1./32767.);
47 <        
48 <        return dref*32768./(32766.5 - c);
44 >
45 >        if (c >= -1)
46 >                return dref*32768./(32766.5 - c);
47 >
48 >        return dref*(32768.5 + c)*(1./32767.);
49   }
50   #endif
51  
# Line 72 | Line 71 | static int
71   headline(char *s, void *p)
72   {
73          DEPTHCODEC      *dcp = (DEPTHCODEC *)p;
74 +        int             rv;
75  
76          if (formatval(dcp->inpfmt, s))  /* don't pass format */
77                  return 0;
78 +
79 +        if ((rv = isbigendian(s)) >= 0) {
80 +                dcp->swapped = (nativebigendian() != rv);
81 +                return 0;
82 +        }
83                                          /* check for reference depth */
84          if (!strncmp(s, DEPTHSTR, LDEPTHSTR)) {
85                  char    *cp;
# Line 92 | Line 97 | headline(char *s, void *p)
97                          }
98                          return -1;
99                  }
100 <        } else if (isview(s))           /* get view params */
100 >                if (dcp->hdrflags & HF_ENCODE)
101 >                        return 0;       /* will add this later */
102 >        } else if (!strncmp(s, "SAMP360=", 8))
103 >                dcp->gotview--;
104 >        else if (isview(s))             /* get view params */
105                  dcp->gotview += (sscanview(&dcp->vw, s) > 0);
106          if (dcp->hdrflags & HF_HEADOUT)
107                  fputs(s, stdout);       /* copy to standard output */
# Line 112 | Line 121 | process_dc_header(DEPTHCODEC *dcp, int ac, char *av[])
121                  }
122                  return 0;
123          }
124 +        dcp->gotview *= (dcp->gotview > 0);
125          if (dcp->hdrflags & HF_HEADOUT) {       /* finish header */
126                  if (!(dcp->hdrflags & HF_HEADIN))
127                          newheader("RADIANCE", stdout);
# Line 128 | Line 138 | process_dc_header(DEPTHCODEC *dcp, int ac, char *av[])
138                                  fputformat("ascii", stdout);
139                                  break;
140                          case 'f':
141 +                                fputendian(stdout);
142                                  fputformat("float", stdout);
143                                  break;
144                          case 'd':
145 +                                fputendian(stdout);
146                                  fputformat("double", stdout);
147                                  break;
148                          }
# Line 215 | Line 227 | check_decode_worldpos(DEPTHCODEC *dcp)
227   double
228   decode_depth_next(DEPTHCODEC *dcp)
229   {
230 <        int     c = getint(2, dcp->finp);
230 >        int     c;
231  
232 +        if (dcp->use_last) {
233 +                dcp->use_last = 0;
234 +                return code2depth(dcp->last_dc, dcp->refdepth);
235 +        }
236 +        c = getint(2, dcp->finp);
237 +
238          if (c == EOF && feof(dcp->finp))
239                  return -1.;
240  
241 +        dcp->last_dc = c;
242          dcp->curpos += 2;
243  
244          return code2depth(c, dcp->refdepth);
# Line 233 | Line 252 | compute_worldpos(FVECT wpos, DEPTHCODEC *dcp, int x, i
252          RREAL   loc[2];
253          FVECT   rdir;
254  
255 +        if (d >= FHUGE*.99)
256 +                goto badval;
257 +
258          pix2loc(loc, &dcp->res, x, y);
259  
260 <        if (viewray(wpos, rdir, &dcp->vw, loc[0], loc[1]) < -FTINY) {
261 <                VCOPY(wpos, dcp->vw.vp);
262 <                return 0;
260 >        if (viewray(wpos, rdir, &dcp->vw, loc[0], loc[1]) >= -FTINY) {
261 >                VSUM(wpos, wpos, rdir, d);
262 >                return 1;
263          }
264 <        VSUM(wpos, wpos, rdir, d);
265 <        return 1;
264 > badval:
265 >        VCOPY(wpos, dcp->vw.vp);
266 >        return 0;
267   }
268  
269  
# Line 287 | Line 310 | seek_dc_pix(DEPTHCODEC *dcp, int x, int y)
310          }
311          seekpos = dcp->dstart + 2*((long)y*scanlen(&dcp->res) + x);
312  
313 +        if (seekpos == dcp->curpos-2) {
314 +                dcp->use_last++;        /* avoids seek/read */
315 +                return 1;
316 +        }
317          if (seekpos != dcp->curpos &&
318                          fseek(dcp->finp, seekpos, SEEK_SET) == EOF) {
319                  if (dcp->hdrflags & HF_STDERR) {
# Line 296 | Line 323 | seek_dc_pix(DEPTHCODEC *dcp, int x, int y)
323                  return -1;
324          }
325          dcp->curpos = seekpos;
326 +        dcp->use_last = 0;
327          return 1;
328   }
329  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines