| 1 |
greg |
2.8 |
/* RCSid $Id: depthcodec.h,v 2.7 2020/01/25 05:35:34 greg Exp $ */
|
| 2 |
greg |
2.1 |
/*
|
| 3 |
|
|
* Definitions and declarations for 16-bit depth encode/decode
|
| 4 |
|
|
*
|
| 5 |
greg |
2.5 |
* Include after rtio.h and fvect.h
|
| 6 |
greg |
2.1 |
* Includes view.h
|
| 7 |
|
|
*/
|
| 8 |
|
|
|
| 9 |
|
|
#ifndef _RAD_DEPTHCODEC_H_
|
| 10 |
|
|
#define _RAD_DEPTHCODEC_H_
|
| 11 |
|
|
|
| 12 |
|
|
#include "view.h"
|
| 13 |
|
|
|
| 14 |
|
|
#ifdef __cplusplus
|
| 15 |
|
|
extern "C" {
|
| 16 |
|
|
#endif
|
| 17 |
|
|
|
| 18 |
|
|
#define DEPTHSTR "REFDEPTH="
|
| 19 |
|
|
#define LDEPTHSTR 9
|
| 20 |
|
|
#define DEPTH16FMT "16-bit_encoded_depth"
|
| 21 |
|
|
|
| 22 |
greg |
2.2 |
#define HF_HEADIN 0x1 /* expect input header */
|
| 23 |
|
|
#define HF_HEADOUT 0x2 /* write header to stdout */
|
| 24 |
|
|
#define HF_RESIN 0x4 /* expect resolution string */
|
| 25 |
|
|
#define HF_RESOUT 0x8 /* write resolution to stdout */
|
| 26 |
|
|
#define HF_STDERR 0x10 /* report errors to stderr */
|
| 27 |
|
|
#define HF_ALL 0x1f /* all flags above */
|
| 28 |
|
|
#define HF_ENCODE 0x20 /* we are encoding */
|
| 29 |
greg |
2.1 |
|
| 30 |
|
|
/* Structure for encoding/decoding depths and world points */
|
| 31 |
|
|
typedef struct {
|
| 32 |
|
|
FILE *finp; /* input stream */
|
| 33 |
|
|
const char *inpname; /* input name */
|
| 34 |
greg |
2.4 |
short format; /* decoded format */
|
| 35 |
|
|
short swapped; /* byte-swapped input */
|
| 36 |
greg |
2.5 |
short last_dc; /* last depth-code read */
|
| 37 |
|
|
short use_last; /* use last depth-code next */
|
| 38 |
greg |
2.1 |
long dstart; /* start of data */
|
| 39 |
|
|
long curpos; /* current input position */
|
| 40 |
|
|
double refdepth; /* reference depth */
|
| 41 |
|
|
char depth_unit[32]; /* string including units */
|
| 42 |
greg |
2.5 |
short hdrflags; /* header i/o flags */
|
| 43 |
greg |
2.1 |
char inpfmt[MAXFMTLEN]; /* format from header */
|
| 44 |
greg |
2.5 |
short gotview; /* got input view? */
|
| 45 |
greg |
2.1 |
VIEW vw; /* input view parameters */
|
| 46 |
|
|
RESOLU res; /* input resolution */
|
| 47 |
|
|
} DEPTHCODEC;
|
| 48 |
|
|
|
| 49 |
|
|
/* Encode depth as 16-bit signed integer */
|
| 50 |
greg |
2.3 |
#if 1
|
| 51 |
greg |
2.1 |
#define depth2code(d, dref) \
|
| 52 |
|
|
( (d) > (dref) ? (int)(32768.001 - 32768.*(dref)/(d))-1 : \
|
| 53 |
greg |
2.7 |
(d) > .0 ? (int)(32767.*(d)/(dref) - 32768.999) : -32768 )
|
| 54 |
greg |
2.3 |
#else
|
| 55 |
|
|
extern int depth2code(double d, double dref);
|
| 56 |
|
|
#endif
|
| 57 |
greg |
2.1 |
|
| 58 |
|
|
/* Decode depth from 16-bit signed integer */
|
| 59 |
greg |
2.3 |
#if 1
|
| 60 |
|
|
#define code2depth(c, dref) \
|
| 61 |
|
|
( (c) <= -32768 ? .0 : (c) >= 32767 ? FHUGE : \
|
| 62 |
greg |
2.6 |
(c) < -1 ? (dref)*(32768.5 + (c))*(1./32767.) : \
|
| 63 |
greg |
2.3 |
(dref)*32768./(32766.5 - (c)) )
|
| 64 |
|
|
#else
|
| 65 |
greg |
2.1 |
extern double code2depth(int c, double dref);
|
| 66 |
greg |
2.3 |
#endif
|
| 67 |
greg |
2.1 |
|
| 68 |
|
|
/* Set codec defaults */
|
| 69 |
|
|
extern void set_dc_defaults(DEPTHCODEC *dcp);
|
| 70 |
|
|
|
| 71 |
|
|
/* Load/copy header */
|
| 72 |
|
|
extern int process_dc_header(DEPTHCODEC *dcp, int ac, char *av[]);
|
| 73 |
|
|
|
| 74 |
|
|
/* Check that we have what we need to decode depths */
|
| 75 |
|
|
extern int check_decode_depths(DEPTHCODEC *dcp);
|
| 76 |
|
|
|
| 77 |
|
|
/* Decode next depth pixel from input */
|
| 78 |
|
|
extern double decode_depth_next(DEPTHCODEC *dcp);
|
| 79 |
|
|
|
| 80 |
|
|
/* Seek to the indicated pixel position */
|
| 81 |
|
|
extern int seek_dc_pix(DEPTHCODEC *dcp, int x, int y);
|
| 82 |
|
|
|
| 83 |
|
|
/* Read and decode depth for the given pixel */
|
| 84 |
|
|
extern double decode_depth_pix(DEPTHCODEC *dcp, int x, int y);
|
| 85 |
|
|
|
| 86 |
|
|
/* Check that we have what we need to decode world positions */
|
| 87 |
|
|
extern int check_decode_worldpos(DEPTHCODEC *dcp);
|
| 88 |
|
|
|
| 89 |
|
|
/* Compute world position from pixel position and depth */
|
| 90 |
|
|
extern int compute_worldpos(FVECT wpos, DEPTHCODEC *dcp,
|
| 91 |
|
|
int x, int y, double d);
|
| 92 |
|
|
|
| 93 |
|
|
/* Decode the next world position from input */
|
| 94 |
|
|
int decode_worldpos_next(FVECT wpos, DEPTHCODEC *dcp);
|
| 95 |
|
|
|
| 96 |
|
|
/* Decode depth and compute world position for the given pixel */
|
| 97 |
|
|
extern int get_worldpos_pix(FVECT wpos, DEPTHCODEC *dcp, int x, int y);
|
| 98 |
|
|
|
| 99 |
|
|
#ifdef __cplusplus
|
| 100 |
|
|
}
|
| 101 |
|
|
#endif
|
| 102 |
|
|
#endif /* _RAD_DEPTHCODEC_H_ */
|