2 |
|
static const char RCSid[] = "$Id$"; |
3 |
|
#endif |
4 |
|
/* |
5 |
< |
* Encode and decode depth values using 16-bit integers |
5 |
> |
* Encode and decode depth map using 16-bit integers |
6 |
|
*/ |
7 |
|
|
8 |
|
#include "copyright.h" |
15 |
|
#include "fvect.h" |
16 |
|
#include "depthcodec.h" |
17 |
|
|
18 |
+ |
char *progname; /* set in main() */ |
19 |
+ |
|
20 |
|
enum {CV_FWD, CV_REV, CV_PTS}; |
21 |
|
|
22 |
|
|
27 |
|
fputs("Usage: ", stderr); |
28 |
|
fputs(progname, stderr); |
29 |
|
fputs( |
30 |
< |
" [-d ref_depth/unit][-h[io]][-H[io]][-f[afd]] [input [output]]\n", |
30 |
> |
" [-d ref_depth/unit][-h[io]][-H[io]][-f[afd]] [input [output.dpt]]\n", |
31 |
|
stderr); |
32 |
|
fputs(" Or: ", stderr); |
33 |
|
fputs(progname, stderr); |
34 |
|
fputs( |
35 |
< |
" {-r|-p} [-i][-u][-h[io]][-H[io]][-f[afd]] [input [output]]\n", |
35 |
> |
" {-r|-p} [-i][-u][-h[io]][-H[io]][-f[afd]] [input.dpt [output]]\n", |
36 |
|
stderr); |
37 |
|
exit(code); |
38 |
|
} |
42 |
|
static int |
43 |
|
encode_depths(DEPTHCODEC *dcp) |
44 |
|
{ |
45 |
< |
long nexpected = 0; |
45 |
> |
long nexpected = (long)dcp->res.xr * dcp->res.yr; |
46 |
|
|
47 |
|
if (dcp->inpfmt[0]) { |
48 |
|
if (strcasestr(dcp->inpfmt, "ascii") != NULL) |
59 |
|
return 0; |
60 |
|
} |
61 |
|
} |
62 |
< |
if (dcp->hdrflags & HF_RESIN) |
61 |
< |
nexpected = (long)dcp->res.xr * dcp->res.yr; |
62 |
> |
|
63 |
|
do { |
64 |
|
int ok = 0; |
65 |
|
float f; |
79 |
|
} |
80 |
|
if (!ok) |
81 |
|
break; |
82 |
+ |
|
83 |
|
putint(depth2code(d, dcp->refdepth), 2, stdout); |
84 |
+ |
|
85 |
|
} while (--nexpected); |
86 |
|
|
87 |
|
if (nexpected > 0) { |
93 |
|
} |
94 |
|
|
95 |
|
|
96 |
< |
/* Convert and output the given depth code to stdout */ |
96 |
> |
/* Convert and output the given depth to stdout */ |
97 |
|
static void |
98 |
|
output_depth(DEPTHCODEC *dcp, double d) |
99 |
|
{ |
118 |
|
static int |
119 |
|
decode_depths(DEPTHCODEC *dcp) |
120 |
|
{ |
121 |
< |
long nexpected = 0; |
121 |
> |
long nexpected = (long)dcp->res.xr * dcp->res.yr; |
122 |
|
|
123 |
|
if (!check_decode_depths(dcp)) |
124 |
|
return 0; |
125 |
|
|
123 |
– |
if (dcp->hdrflags & HF_RESIN) |
124 |
– |
nexpected = (long)dcp->res.xr * dcp->res.yr; |
126 |
|
do { |
127 |
< |
double d = decode_depth_next(dcp); |
127 |
> |
double d = decode_depth_next(dcp); |
128 |
|
if (d < -FTINY) |
129 |
|
break; |
130 |
|
output_depth(dcp, d); |
156 |
|
return 0; |
157 |
|
|
158 |
|
while (scanf("%d %d", &xy[0], &xy[1]) == 2) { |
159 |
+ |
|
160 |
|
loc2pix(xy, &dcp->res, |
161 |
|
(xy[0]+.5)/dcp->res.xr, (xy[1]+.5)/dcp->res.yr); |
162 |
+ |
|
163 |
|
d = decode_depth_pix(dcp, xy[0], xy[1]); |
164 |
|
if (d < -FTINY) |
165 |
|
return 0; |
166 |
+ |
|
167 |
|
output_depth(dcp, d); |
168 |
+ |
|
169 |
|
if (unbuf && fflush(stdout) == EOF) { |
170 |
|
fputs(progname, stderr); |
171 |
|
fputs(": write error on output\n", stderr); |
181 |
|
} |
182 |
|
|
183 |
|
|
184 |
< |
/* Output the given world position */ |
184 |
> |
/* Output the given world position to stdout */ |
185 |
|
static void |
186 |
|
output_worldpos(DEPTHCODEC *dcp, FVECT wpos) |
187 |
|
{ |
188 |
|
switch (dcp->format) { |
189 |
|
case 'a': |
190 |
< |
fprintf(stdout, "%.5e %.5e %.5e\n", |
186 |
< |
wpos[0], wpos[1], wpos[2]); |
190 |
> |
printf("%.5e %.5e %.5e\n", wpos[0], wpos[1], wpos[2]); |
191 |
|
break; |
192 |
|
#ifdef SMLFLT |
193 |
|
case 'f': |
383 |
|
fputs(": -i option requires input resolution\n", stderr); |
384 |
|
usage_exit(1); |
385 |
|
} |
386 |
< |
dc.hdrflags &= ~(HF_HEADOUT|HF_RESOUT); |
386 |
> |
dc.hdrflags &= ~HF_RESOUT; |
387 |
|
} |
388 |
|
if (a < argc-2) { |
389 |
|
fputs(progname, stderr); |
401 |
|
return 1; |
402 |
|
} |
403 |
|
SET_FILE_BINARY(dc.finp); |
404 |
< |
SET_FILE_BINARY(stdout); |
404 |
> |
if ((conversion != CV_FWD) | (dc.format != 'a')) |
405 |
> |
SET_FILE_BINARY(stdout); |
406 |
|
#ifdef getc_unlocked /* avoid stupid semaphores */ |
407 |
|
flockfile(dc.finp); |
408 |
|
flockfile(stdout); |
409 |
|
#endif |
410 |
|
/* read/copy header */ |
411 |
< |
if (!process_dc_header(&dc, argc, argv)) |
411 |
> |
if (!process_dc_header(&dc, a, argv)) |
412 |
|
return 1; |
413 |
|
/* process data */ |
414 |
|
switch (conversion) { |