--- ray/src/common/depthcodec.h 2019/07/26 17:04:12 2.2 +++ ray/src/common/depthcodec.h 2019/11/07 23:20:28 2.5 @@ -1,8 +1,8 @@ -/* RCSid $Id: depthcodec.h,v 2.2 2019/07/26 17:04:12 greg Exp $ */ +/* RCSid $Id: depthcodec.h,v 2.5 2019/11/07 23:20:28 greg Exp $ */ /* * Definitions and declarations for 16-bit depth encode/decode * - * Include after stdio.h and fvect.h + * Include after rtio.h and fvect.h * Includes view.h */ @@ -31,25 +31,39 @@ extern "C" { typedef struct { FILE *finp; /* input stream */ const char *inpname; /* input name */ - int format; /* decoded format */ + short format; /* decoded format */ + short swapped; /* byte-swapped input */ + short last_dc; /* last depth-code read */ + short use_last; /* use last depth-code next */ long dstart; /* start of data */ long curpos; /* current input position */ double refdepth; /* reference depth */ char depth_unit[32]; /* string including units */ - int hdrflags; /* header i/o flags */ + short hdrflags; /* header i/o flags */ char inpfmt[MAXFMTLEN]; /* format from header */ + short gotview; /* got input view? */ VIEW vw; /* input view parameters */ - int gotview; /* got input view? */ RESOLU res; /* input resolution */ } DEPTHCODEC; /* Encode depth as 16-bit signed integer */ +#if 1 #define depth2code(d, dref) \ ( (d) > (dref) ? (int)(32768.001 - 32768.*(dref)/(d))-1 : \ (d) > .0 ? (int)(32767.*(d)/(dref) - 32768.) : -32768 ) +#else +extern int depth2code(double d, double dref); +#endif /* Decode depth from 16-bit signed integer */ +#if 1 +#define code2depth(c, dref) \ + ( (c) <= -32768 ? .0 : (c) >= 32767 ? FHUGE : \ + (c) < 0 ? (dref)*(32767.5 + (c))*(1./32767.) : \ + (dref)*32768./(32766.5 - (c)) ) +#else extern double code2depth(int c, double dref); +#endif /* Set codec defaults */ extern void set_dc_defaults(DEPTHCODEC *dcp);