--- ray/src/common/depthcodec.c 2019/08/14 21:00:14 2.4 +++ ray/src/common/depthcodec.c 2020/01/10 01:02:14 2.6 @@ -1,5 +1,5 @@ #ifndef lint -static const char RCSid[] = "$Id: depthcodec.c,v 2.4 2019/08/14 21:00:14 greg Exp $"; +static const char RCSid[] = "$Id: depthcodec.c,v 2.6 2020/01/10 01:02:14 greg Exp $"; #endif /* * Routines to encode/decoded 16-bit depths @@ -8,7 +8,6 @@ static const char RCSid[] = "$Id: depthcodec.c,v 2.4 2 #include "copyright.h" #include -#include #include #include #include "rtio.h" @@ -42,11 +41,11 @@ code2depth(int c, double dref) if (c >= 32767) return FHUGE; - - if (c < 0) - return dref*(32767.5 + c)*(1./32767.); - - return dref*32768./(32766.5 - c); + + if (c >= 0) + return dref*32768./(32766.5 - c); + + return dref*(32767.5 + c)*(1./32767.); } #endif @@ -59,7 +58,6 @@ set_dc_defaults(DEPTHCODEC *dcp) dcp->finp = stdin; dcp->inpname = ""; dcp->format = 'a'; - dcp->swapped = 0; dcp->refdepth = 1.; dcp->depth_unit[0] = '1'; dcp->vw = stdview; @@ -99,7 +97,9 @@ headline(char *s, void *p) } return -1; } - } else if (isview(s)) /* get view params */ + } else if (!strncmp(s, "SAMP360=", 8)) + dcp->gotview--; + else if (isview(s)) /* get view params */ dcp->gotview += (sscanview(&dcp->vw, s) > 0); if (dcp->hdrflags & HF_HEADOUT) fputs(s, stdout); /* copy to standard output */ @@ -119,6 +119,7 @@ process_dc_header(DEPTHCODEC *dcp, int ac, char *av[]) } return 0; } + dcp->gotview *= (dcp->gotview > 0); if (dcp->hdrflags & HF_HEADOUT) { /* finish header */ if (!(dcp->hdrflags & HF_HEADIN)) newheader("RADIANCE", stdout); @@ -224,11 +225,18 @@ check_decode_worldpos(DEPTHCODEC *dcp) double decode_depth_next(DEPTHCODEC *dcp) { - int c = getint(2, dcp->finp); + int c; + if (dcp->use_last) { + dcp->use_last = 0; + return code2depth(dcp->last_dc, dcp->refdepth); + } + c = getint(2, dcp->finp); + if (c == EOF && feof(dcp->finp)) return -1.; + dcp->last_dc = c; dcp->curpos += 2; return code2depth(c, dcp->refdepth); @@ -296,6 +304,10 @@ seek_dc_pix(DEPTHCODEC *dcp, int x, int y) } seekpos = dcp->dstart + 2*((long)y*scanlen(&dcp->res) + x); + if (seekpos == dcp->curpos-2) { + dcp->use_last++; /* avoids seek/read */ + return 1; + } if (seekpos != dcp->curpos && fseek(dcp->finp, seekpos, SEEK_SET) == EOF) { if (dcp->hdrflags & HF_STDERR) {