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" |
26 |
|
if (d > dref) |
27 |
|
return (int)(32768.001 - 32768.*dref/d) - 1; |
28 |
|
|
29 |
< |
return (int)(32767.*d/dref - 32768.); |
29 |
> |
return (int)(32767.*d/dref - 32768.999); |
30 |
|
} |
31 |
|
#endif |
32 |
|
|
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 >= -1) |
46 |
> |
return dref*32768./(32766.5 - c); |
47 |
> |
|
48 |
> |
return dref*(32768.5 + c)*(1./32767.); |
49 |
|
} |
50 |
|
#endif |
51 |
|
|
58 |
|
dcp->finp = stdin; |
59 |
|
dcp->inpname = "<stdin>"; |
60 |
|
dcp->format = 'a'; |
62 |
– |
dcp->swapped = 0; |
61 |
|
dcp->refdepth = 1.; |
62 |
|
dcp->depth_unit[0] = '1'; |
63 |
|
dcp->vw = stdview; |
97 |
|
} |
98 |
|
return -1; |
99 |
|
} |
100 |
< |
} else if (isview(s)) /* get view params */ |
100 |
> |
if (dcp->hdrflags & HF_ENCODE) |
101 |
> |
return 0; /* will add this later */ |
102 |
> |
} else if (!strncmp(s, "SAMP360=", 8)) |
103 |
> |
dcp->gotview--; |
104 |
> |
else if (isview(s)) /* get view params */ |
105 |
|
dcp->gotview += (sscanview(&dcp->vw, s) > 0); |
106 |
|
if (dcp->hdrflags & HF_HEADOUT) |
107 |
|
fputs(s, stdout); /* copy to standard output */ |
121 |
|
} |
122 |
|
return 0; |
123 |
|
} |
124 |
+ |
dcp->gotview *= (dcp->gotview > 0); |
125 |
+ |
/* get resolution string? */ |
126 |
+ |
if (dcp->hdrflags & HF_RESIN && !fgetsresolu(&dcp->res, dcp->finp)) { |
127 |
+ |
if (dcp->hdrflags & HF_STDERR) { |
128 |
+ |
fputs(dcp->inpname, stderr); |
129 |
+ |
fputs(": bad resolution string\n", stderr); |
130 |
+ |
} |
131 |
+ |
return 0; |
132 |
+ |
} |
133 |
|
if (dcp->hdrflags & HF_HEADOUT) { /* finish header */ |
134 |
|
if (!(dcp->hdrflags & HF_HEADIN)) |
135 |
|
newheader("RADIANCE", stdout); |
140 |
|
fputs(dcp->depth_unit, stdout); |
141 |
|
fputc('\n', stdout); |
142 |
|
fputformat(DEPTH16FMT, stdout); |
143 |
< |
} else |
143 |
> |
} else { |
144 |
> |
fputs("NCOMP=1\n", stdout); |
145 |
> |
if ((dcp->hdrflags & (HF_RESIN|HF_RESOUT)) == HF_RESIN) |
146 |
> |
printf("NCOLS=%d\nNROWS=%d\n", |
147 |
> |
scanlen(&dcp->res), |
148 |
> |
numscans(&dcp->res)); |
149 |
|
switch (dcp->format) { |
150 |
|
case 'a': |
151 |
|
fputformat("ascii", stdout); |
159 |
|
fputformat("double", stdout); |
160 |
|
break; |
161 |
|
} |
162 |
+ |
} |
163 |
|
fputc('\n', stdout); |
164 |
|
} |
165 |
< |
/* get/put resolution string */ |
149 |
< |
if (dcp->hdrflags & HF_RESIN && !fgetsresolu(&dcp->res, dcp->finp)) { |
150 |
< |
if (dcp->hdrflags & HF_STDERR) { |
151 |
< |
fputs(dcp->inpname, stderr); |
152 |
< |
fputs(": bad resolution string\n", stderr); |
153 |
< |
} |
154 |
< |
return 0; |
155 |
< |
} |
156 |
< |
if (dcp->hdrflags & HF_RESOUT) |
165 |
> |
if (dcp->hdrflags & HF_RESOUT) /* put resolution string? */ |
166 |
|
fputsresolu(&dcp->res, stdout); |
167 |
|
|
168 |
|
dcp->dstart = dcp->curpos = ftell(dcp->finp); |
233 |
|
double |
234 |
|
decode_depth_next(DEPTHCODEC *dcp) |
235 |
|
{ |
236 |
< |
int c = getint(2, dcp->finp); |
236 |
> |
int c; |
237 |
|
|
238 |
+ |
if (dcp->use_last) { |
239 |
+ |
dcp->use_last = 0; |
240 |
+ |
return code2depth(dcp->last_dc, dcp->refdepth); |
241 |
+ |
} |
242 |
+ |
c = getint(2, dcp->finp); |
243 |
+ |
|
244 |
|
if (c == EOF && feof(dcp->finp)) |
245 |
|
return -1.; |
246 |
|
|
247 |
+ |
dcp->last_dc = c; |
248 |
|
dcp->curpos += 2; |
249 |
|
|
250 |
|
return code2depth(c, dcp->refdepth); |
258 |
|
RREAL loc[2]; |
259 |
|
FVECT rdir; |
260 |
|
|
261 |
+ |
if (d >= FHUGE*.99) |
262 |
+ |
goto badval; |
263 |
+ |
|
264 |
|
pix2loc(loc, &dcp->res, x, y); |
265 |
|
|
266 |
< |
if (viewray(wpos, rdir, &dcp->vw, loc[0], loc[1]) < -FTINY) { |
267 |
< |
VCOPY(wpos, dcp->vw.vp); |
268 |
< |
return 0; |
266 |
> |
if (viewray(wpos, rdir, &dcp->vw, loc[0], loc[1]) >= -FTINY) { |
267 |
> |
VSUM(wpos, wpos, rdir, d); |
268 |
> |
return 1; |
269 |
|
} |
270 |
< |
VSUM(wpos, wpos, rdir, d); |
271 |
< |
return 1; |
270 |
> |
badval: |
271 |
> |
VCOPY(wpos, dcp->vw.vp); |
272 |
> |
return 0; |
273 |
|
} |
274 |
|
|
275 |
|
|
316 |
|
} |
317 |
|
seekpos = dcp->dstart + 2*((long)y*scanlen(&dcp->res) + x); |
318 |
|
|
319 |
+ |
if (seekpos == dcp->curpos-2) { |
320 |
+ |
dcp->use_last++; /* avoids seek/read */ |
321 |
+ |
return 1; |
322 |
+ |
} |
323 |
|
if (seekpos != dcp->curpos && |
324 |
|
fseek(dcp->finp, seekpos, SEEK_SET) == EOF) { |
325 |
|
if (dcp->hdrflags & HF_STDERR) { |
329 |
|
return -1; |
330 |
|
} |
331 |
|
dcp->curpos = seekpos; |
332 |
+ |
dcp->use_last = 0; |
333 |
|
return 1; |
334 |
|
} |
335 |
|
|