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; |
80 |
|
dcp->swapped = (nativebigendian() != rv); |
81 |
|
return 0; |
82 |
|
} |
83 |
< |
/* check for reference depth */ |
83 |
> |
if (!strncmp(s, "NCOMP=", 6)) { |
84 |
> |
if (atoi(s+6) != 1) { |
85 |
> |
if (dcp->hdrflags & HF_STDERR) { |
86 |
> |
fputs(dcp->inpname, stderr); |
87 |
> |
fputs(": NCOMP must equal 1\n", stderr); |
88 |
> |
} |
89 |
> |
return -1; |
90 |
> |
} |
91 |
> |
return 0; |
92 |
> |
} |
93 |
> |
if (!strncmp(s, "NROWS=", 6)) { |
94 |
> |
dcp->res.yr = atoi(s+6); |
95 |
> |
return 0; |
96 |
> |
} |
97 |
> |
if (!strncmp(s, "NCOLS=", 6)) { |
98 |
> |
dcp->res.xr = atoi(s+6); |
99 |
> |
return 0; |
100 |
> |
} |
101 |
> |
/* check for reference depth */ |
102 |
|
if (!strncmp(s, DEPTHSTR, LDEPTHSTR)) { |
103 |
|
char *cp; |
104 |
|
strlcpy(dcp->depth_unit, s+LDEPTHSTR, sizeof(dcp->depth_unit)); |
115 |
|
} |
116 |
|
return -1; |
117 |
|
} |
118 |
< |
} else if (isview(s)) /* get view params */ |
118 |
> |
if (dcp->hdrflags & HF_ENCODE) |
119 |
> |
return 0; /* will add this later */ |
120 |
> |
} else if (!strncmp(s, "SAMP360=", 8)) |
121 |
> |
dcp->gotview--; |
122 |
> |
else if (isview(s)) /* get view params */ |
123 |
|
dcp->gotview += (sscanview(&dcp->vw, s) > 0); |
124 |
|
if (dcp->hdrflags & HF_HEADOUT) |
125 |
|
fputs(s, stdout); /* copy to standard output */ |
139 |
|
} |
140 |
|
return 0; |
141 |
|
} |
142 |
+ |
dcp->gotview *= (dcp->gotview > 0); |
143 |
+ |
/* get resolution string? */ |
144 |
+ |
if (dcp->hdrflags & HF_RESIN && |
145 |
+ |
(dcp->res.xr <= 0) | (dcp->res.yr <= 0) && |
146 |
+ |
!fgetsresolu(&dcp->res, dcp->finp)) { |
147 |
+ |
if (dcp->hdrflags & HF_STDERR) { |
148 |
+ |
fputs(dcp->inpname, stderr); |
149 |
+ |
fputs(": bad resolution string\n", stderr); |
150 |
+ |
} |
151 |
+ |
return 0; |
152 |
+ |
} |
153 |
|
if (dcp->hdrflags & HF_HEADOUT) { /* finish header */ |
154 |
|
if (!(dcp->hdrflags & HF_HEADIN)) |
155 |
|
newheader("RADIANCE", stdout); |
160 |
|
fputs(dcp->depth_unit, stdout); |
161 |
|
fputc('\n', stdout); |
162 |
|
fputformat(DEPTH16FMT, stdout); |
163 |
< |
} else |
163 |
> |
} else { |
164 |
> |
fputs("NCOMP=1\n", stdout); |
165 |
> |
if ((dcp->hdrflags & (HF_RESIN|HF_RESOUT)) == HF_RESIN) |
166 |
> |
printf("NCOLS=%d\nNROWS=%d\n", |
167 |
> |
scanlen(&dcp->res), |
168 |
> |
numscans(&dcp->res)); |
169 |
|
switch (dcp->format) { |
170 |
|
case 'a': |
171 |
|
fputformat("ascii", stdout); |
179 |
|
fputformat("double", stdout); |
180 |
|
break; |
181 |
|
} |
182 |
+ |
} |
183 |
|
fputc('\n', stdout); |
184 |
|
} |
185 |
< |
/* 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) |
185 |
> |
if (dcp->hdrflags & HF_RESOUT) /* put resolution string? */ |
186 |
|
fputsresolu(&dcp->res, stdout); |
187 |
|
|
188 |
|
dcp->dstart = dcp->curpos = ftell(dcp->finp); |
253 |
|
double |
254 |
|
decode_depth_next(DEPTHCODEC *dcp) |
255 |
|
{ |
256 |
< |
int c = getint(2, dcp->finp); |
256 |
> |
int c; |
257 |
|
|
258 |
+ |
if (dcp->use_last) { |
259 |
+ |
dcp->use_last = 0; |
260 |
+ |
return code2depth(dcp->last_dc, dcp->refdepth); |
261 |
+ |
} |
262 |
+ |
c = getint(2, dcp->finp); |
263 |
+ |
|
264 |
|
if (c == EOF && feof(dcp->finp)) |
265 |
|
return -1.; |
266 |
|
|
267 |
+ |
dcp->last_dc = c; |
268 |
|
dcp->curpos += 2; |
269 |
|
|
270 |
|
return code2depth(c, dcp->refdepth); |
278 |
|
RREAL loc[2]; |
279 |
|
FVECT rdir; |
280 |
|
|
281 |
+ |
if (d >= FHUGE*.99) |
282 |
+ |
goto badval; |
283 |
+ |
|
284 |
|
pix2loc(loc, &dcp->res, x, y); |
285 |
|
|
286 |
< |
if (viewray(wpos, rdir, &dcp->vw, loc[0], loc[1]) < -FTINY) { |
287 |
< |
VCOPY(wpos, dcp->vw.vp); |
288 |
< |
return 0; |
286 |
> |
if (viewray(wpos, rdir, &dcp->vw, loc[0], loc[1]) >= -FTINY) { |
287 |
> |
VSUM(wpos, wpos, rdir, d); |
288 |
> |
return 1; |
289 |
|
} |
290 |
< |
VSUM(wpos, wpos, rdir, d); |
291 |
< |
return 1; |
290 |
> |
badval: |
291 |
> |
VCOPY(wpos, dcp->vw.vp); |
292 |
> |
return 0; |
293 |
|
} |
294 |
|
|
295 |
|
|
336 |
|
} |
337 |
|
seekpos = dcp->dstart + 2*((long)y*scanlen(&dcp->res) + x); |
338 |
|
|
339 |
+ |
if (seekpos == dcp->curpos-2) { |
340 |
+ |
dcp->use_last++; /* avoids seek/read */ |
341 |
+ |
return 1; |
342 |
+ |
} |
343 |
|
if (seekpos != dcp->curpos && |
344 |
|
fseek(dcp->finp, seekpos, SEEK_SET) == EOF) { |
345 |
|
if (dcp->hdrflags & HF_STDERR) { |
349 |
|
return -1; |
350 |
|
} |
351 |
|
dcp->curpos = seekpos; |
352 |
+ |
dcp->use_last = 0; |
353 |
|
return 1; |
354 |
|
} |
355 |
|
|