--- ray/src/common/depthcodec.c 2020/01/10 01:02:14 2.6 +++ ray/src/common/depthcodec.c 2021/01/26 18:47:25 2.11 @@ -1,5 +1,5 @@ #ifndef lint -static const char RCSid[] = "$Id: depthcodec.c,v 2.6 2020/01/10 01:02:14 greg Exp $"; +static const char RCSid[] = "$Id: depthcodec.c,v 2.11 2021/01/26 18:47:25 greg Exp $"; #endif /* * Routines to encode/decoded 16-bit depths @@ -26,7 +26,7 @@ depth2code(double d, double dref) if (d > dref) return (int)(32768.001 - 32768.*dref/d) - 1; - return (int)(32767.*d/dref - 32768.); + return (int)(32767.*d/dref - 32768.999); } #endif @@ -42,10 +42,10 @@ code2depth(int c, double dref) if (c >= 32767) return FHUGE; - if (c >= 0) + if (c >= -1) return dref*32768./(32766.5 - c); - return dref*(32767.5 + c)*(1./32767.); + return dref*(32768.5 + c)*(1./32767.); } #endif @@ -97,6 +97,8 @@ headline(char *s, void *p) } return -1; } + if (dcp->hdrflags & HF_ENCODE) + return 0; /* will add this later */ } else if (!strncmp(s, "SAMP360=", 8)) dcp->gotview--; else if (isview(s)) /* get view params */ @@ -250,14 +252,18 @@ compute_worldpos(FVECT wpos, DEPTHCODEC *dcp, int x, i RREAL loc[2]; FVECT rdir; + if (d >= FHUGE*.99) + goto badval; + pix2loc(loc, &dcp->res, x, y); - if (viewray(wpos, rdir, &dcp->vw, loc[0], loc[1]) < -FTINY) { - VCOPY(wpos, dcp->vw.vp); - return 0; + if (viewray(wpos, rdir, &dcp->vw, loc[0], loc[1]) >= -FTINY) { + VSUM(wpos, wpos, rdir, d); + return 1; } - VSUM(wpos, wpos, rdir, d); - return 1; +badval: + VCOPY(wpos, dcp->vw.vp); + return 0; } @@ -317,6 +323,7 @@ seek_dc_pix(DEPTHCODEC *dcp, int x, int y) return -1; } dcp->curpos = seekpos; + dcp->use_last = 0; return 1; }