| 7 |
|
|
| 8 |
|
#include "copyright.h" |
| 9 |
|
|
| 10 |
– |
#include <stdlib.h> |
| 11 |
– |
#include <string.h> |
| 10 |
|
#include <math.h> |
| 11 |
|
#include <ctype.h> |
| 12 |
+ |
#include "paths.h" |
| 13 |
|
#include "rtio.h" |
| 14 |
|
#include "fvect.h" |
| 15 |
|
#include "depthcodec.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 |
|
|
| 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 |
< |
/* check for reference depth */ |
| 78 |
> |
|
| 79 |
> |
if ((rv = isbigendian(s)) >= 0) { |
| 80 |
> |
dcp->swapped = (nativebigendian() != rv); |
| 81 |
> |
return 0; |
| 82 |
> |
} |
| 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); |
| 172 |
|
break; |
| 173 |
|
case 'f': |
| 174 |
+ |
fputendian(stdout); |
| 175 |
|
fputformat("float", stdout); |
| 176 |
|
break; |
| 177 |
|
case 'd': |
| 178 |
+ |
fputendian(stdout); |
| 179 |
|
fputformat("double", stdout); |
| 180 |
|
break; |
| 181 |
|
} |
| 182 |
+ |
} |
| 183 |
|
fputc('\n', stdout); |
| 184 |
|
} |
| 185 |
< |
/* get/put resolution string */ |
| 140 |
< |
if (dcp->hdrflags & HF_RESIN && !fgetsresolu(&dcp->res, dcp->finp)) { |
| 141 |
< |
if (dcp->hdrflags & HF_STDERR) { |
| 142 |
< |
fputs(dcp->inpname, stderr); |
| 143 |
< |
fputs(": bad resolution string\n", stderr); |
| 144 |
< |
} |
| 145 |
< |
return 0; |
| 146 |
< |
} |
| 147 |
< |
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 |
|
|