8 |
|
#include "copyright.h" |
9 |
|
|
10 |
|
#include <stdlib.h> |
11 |
– |
#include <string.h> |
11 |
|
#include <math.h> |
12 |
|
#include <ctype.h> |
13 |
|
#include "rtio.h" |
15 |
|
#include "depthcodec.h" |
16 |
|
|
17 |
|
|
18 |
< |
#if 0 /* defined as macro in depthcodec.h */ |
18 |
> |
#ifndef depth2code |
19 |
|
/* Encode depth as 16-bit signed integer */ |
20 |
|
int |
21 |
|
depth2code(double d, double dref) |
24 |
|
return -32768; |
25 |
|
|
26 |
|
if (d > dref) |
27 |
< |
return (int)(32768 - 32768*dref/d) - 1; |
27 |
> |
return (int)(32768.001 - 32768.*dref/d) - 1; |
28 |
|
|
29 |
< |
return (int)(32767*d/dref - 32768); |
29 |
> |
return (int)(32767.*d/dref - 32768.); |
30 |
|
} |
31 |
|
#endif |
32 |
|
|
33 |
|
|
34 |
+ |
#ifndef code2depth |
35 |
|
/* Decode depth from 16-bit signed integer */ |
36 |
|
double |
37 |
|
code2depth(int c, double dref) |
41 |
|
|
42 |
|
if (c >= 32767) |
43 |
|
return FHUGE; |
44 |
< |
|
45 |
< |
if (c < 0) |
46 |
< |
return dref*(32767.5 + c)*(1./32767.); |
47 |
< |
|
48 |
< |
return dref*32768./(32766.5 - c); |
44 |
> |
|
45 |
> |
if (c >= 0) |
46 |
> |
return dref*32768./(32766.5 - c); |
47 |
> |
|
48 |
> |
return dref*(32767.5 + c)*(1./32767.); |
49 |
|
} |
50 |
+ |
#endif |
51 |
|
|
52 |
|
|
53 |
|
/* Set codec defaults */ |
71 |
|
headline(char *s, void *p) |
72 |
|
{ |
73 |
|
DEPTHCODEC *dcp = (DEPTHCODEC *)p; |
74 |
+ |
int rv; |
75 |
|
|
76 |
|
if (formatval(dcp->inpfmt, s)) /* don't pass format */ |
77 |
|
return 0; |
78 |
+ |
|
79 |
+ |
if ((rv = isbigendian(s)) >= 0) { |
80 |
+ |
dcp->swapped = (nativebigendian() != rv); |
81 |
+ |
return 0; |
82 |
+ |
} |
83 |
|
/* check for reference depth */ |
84 |
|
if (!strncmp(s, DEPTHSTR, LDEPTHSTR)) { |
85 |
|
char *cp; |
133 |
|
fputformat("ascii", stdout); |
134 |
|
break; |
135 |
|
case 'f': |
136 |
+ |
fputendian(stdout); |
137 |
|
fputformat("float", stdout); |
138 |
|
break; |
139 |
|
case 'd': |
140 |
+ |
fputendian(stdout); |
141 |
|
fputformat("double", stdout); |
142 |
|
break; |
143 |
|
} |
222 |
|
double |
223 |
|
decode_depth_next(DEPTHCODEC *dcp) |
224 |
|
{ |
225 |
< |
int c = getint(2, dcp->finp); |
225 |
> |
int c; |
226 |
|
|
227 |
+ |
if (dcp->use_last) { |
228 |
+ |
dcp->use_last = 0; |
229 |
+ |
return code2depth(dcp->last_dc, dcp->refdepth); |
230 |
+ |
} |
231 |
+ |
c = getint(2, dcp->finp); |
232 |
+ |
|
233 |
|
if (c == EOF && feof(dcp->finp)) |
234 |
|
return -1.; |
235 |
|
|
236 |
+ |
dcp->last_dc = c; |
237 |
|
dcp->curpos += 2; |
238 |
|
|
239 |
|
return code2depth(c, dcp->refdepth); |
301 |
|
} |
302 |
|
seekpos = dcp->dstart + 2*((long)y*scanlen(&dcp->res) + x); |
303 |
|
|
304 |
+ |
if (seekpos == dcp->curpos-2) { |
305 |
+ |
dcp->use_last++; /* avoids seek/read */ |
306 |
+ |
return 1; |
307 |
+ |
} |
308 |
|
if (seekpos != dcp->curpos && |
309 |
|
fseek(dcp->finp, seekpos, SEEK_SET) == EOF) { |
310 |
|
if (dcp->hdrflags & HF_STDERR) { |