16 |
|
#include "depthcodec.h" |
17 |
|
|
18 |
|
|
19 |
< |
#if 0 /* defined as macro in depthcodec.h */ |
19 |
> |
#ifndef depth2code |
20 |
|
/* Encode depth as 16-bit signed integer */ |
21 |
|
int |
22 |
|
depth2code(double d, double dref) |
25 |
|
return -32768; |
26 |
|
|
27 |
|
if (d > dref) |
28 |
< |
return (int)(32768 - 32768*dref/d) - 1; |
28 |
> |
return (int)(32768.001 - 32768.*dref/d) - 1; |
29 |
|
|
30 |
< |
return (int)(32767*d/dref - 32768); |
30 |
> |
return (int)(32767.*d/dref - 32768.); |
31 |
|
} |
32 |
|
#endif |
33 |
|
|
34 |
|
|
35 |
+ |
#ifndef code2depth |
36 |
|
/* Decode depth from 16-bit signed integer */ |
37 |
|
double |
38 |
|
code2depth(int c, double dref) |
48 |
|
|
49 |
|
return dref*32768./(32766.5 - c); |
50 |
|
} |
51 |
+ |
#endif |
52 |
|
|
53 |
|
|
54 |
|
/* Set codec defaults */ |
59 |
|
dcp->finp = stdin; |
60 |
|
dcp->inpname = "<stdin>"; |
61 |
|
dcp->format = 'a'; |
62 |
+ |
dcp->swapped = 0; |
63 |
|
dcp->refdepth = 1.; |
64 |
|
dcp->depth_unit[0] = '1'; |
65 |
|
dcp->vw = stdview; |
73 |
|
headline(char *s, void *p) |
74 |
|
{ |
75 |
|
DEPTHCODEC *dcp = (DEPTHCODEC *)p; |
76 |
+ |
int rv; |
77 |
|
|
78 |
|
if (formatval(dcp->inpfmt, s)) /* don't pass format */ |
79 |
|
return 0; |
80 |
+ |
|
81 |
+ |
if ((rv = isbigendian(s)) >= 0) { |
82 |
+ |
dcp->swapped = (nativebigendian() != rv); |
83 |
+ |
return 0; |
84 |
+ |
} |
85 |
|
/* check for reference depth */ |
86 |
|
if (!strncmp(s, DEPTHSTR, LDEPTHSTR)) { |
87 |
|
char *cp; |
135 |
|
fputformat("ascii", stdout); |
136 |
|
break; |
137 |
|
case 'f': |
138 |
+ |
fputendian(stdout); |
139 |
|
fputformat("float", stdout); |
140 |
|
break; |
141 |
|
case 'd': |
142 |
+ |
fputendian(stdout); |
143 |
|
fputformat("double", stdout); |
144 |
|
break; |
145 |
|
} |