| 94 |
|
#define H_BADF 01 |
| 95 |
|
#define H_OBST 02 |
| 96 |
|
#define H_OBSF 04 |
| 97 |
+ |
#define H_SWAP 010 |
| 98 |
|
|
| 99 |
|
static int |
| 100 |
|
holheadline( /* check holodeck header line */ |
| 102 |
|
void *vhf |
| 103 |
|
) |
| 104 |
|
{ |
| 105 |
+ |
int be; |
| 106 |
|
char fmt[MAXFMTLEN]; |
| 107 |
|
int *hf = vhf; |
| 108 |
|
|
| 124 |
|
error(WARNING, "bad OBSTRUCTIONS value in holodeck"); |
| 125 |
|
return(0); |
| 126 |
|
} |
| 127 |
+ |
if ((be = isbigendian(s)) >= 0) { |
| 128 |
+ |
if (be != nativebigendian()) |
| 129 |
+ |
*hf |= H_SWAP; |
| 130 |
+ |
} |
| 131 |
|
return(0); |
| 132 |
|
} |
| 133 |
|
|
| 143 |
|
off_t nextloc; |
| 144 |
|
int n; |
| 145 |
|
/* open holodeck file */ |
| 146 |
< |
if ((fp = fopen(fname, append ? "r+" : "r")) == NULL) { |
| 146 |
> |
if ((fp = fopen(fname, append ? "rb+" : "rb")) == NULL) { |
| 147 |
|
sprintf(errmsg, "cannot open \"%s\" for %s", fname, |
| 148 |
|
append ? "appending" : "reading"); |
| 149 |
|
error(SYSTEM, errmsg); |
| 150 |
|
} |
| 151 |
|
/* check header and magic number */ |
| 152 |
|
if (getheader(fp, holheadline, &hflags) < 0 || |
| 153 |
< |
hflags&H_BADF || getw(fp) != HOLOMAGIC) { |
| 154 |
< |
sprintf(errmsg, "file \"%s\" not in holodeck format", fname); |
| 153 |
> |
hflags&(H_BADF|H_SWAP) || getw(fp) != HOLOMAGIC) { |
| 154 |
> |
sprintf(errmsg, "holodeck \"%s\" not in expected format", fname); |
| 155 |
|
error(USER, errmsg); |
| 156 |
|
} |
| 157 |
|
fd = dup(fileno(fp)); /* dup file handle */ |
| 342 |
|
int j; |
| 343 |
|
int i; |
| 344 |
|
/* open files */ |
| 345 |
< |
if ((pfp = fopen(pcf, "r")) == NULL) { |
| 345 |
> |
if ((pfp = fopen(pcf, "rb")) == NULL) { |
| 346 |
|
sprintf(errmsg, "cannot open picture file \"%s\"", pcf); |
| 347 |
|
error(SYSTEM, pcf); |
| 348 |
|
} |
| 350 |
|
sprintf(errmsg, "cannot open depth file \"%s\"", zbf); |
| 351 |
|
error(SYSTEM, pcf); |
| 352 |
|
} |
| 353 |
+ |
SET_FD_BINARY(zfd); |
| 354 |
|
/* load picture header */ |
| 355 |
|
phd.vw = stdview; |
| 356 |
|
phd.expos = 1.0; |
| 399 |
|
} |
| 400 |
|
if (eshft) /* shift exposure */ |
| 401 |
|
shiftcolrs(cscn, i, eshft); |
| 402 |
< |
i *= sizeof(float); /* read depth */ |
| 403 |
< |
if (read(zfd, (char *)zscn, i) != i) { |
| 402 |
> |
/* read depth */ |
| 403 |
> |
if (read(zfd, zscn, i*sizeof(float)) != i*sizeof(float)) { |
| 404 |
|
sprintf(errmsg, "error reading depth file \"%s\"", zbf); |
| 405 |
|
error(USER, errmsg); |
| 406 |
|
} |
| 407 |
< |
for (i = scanlen(&prs); i--; ) { /* do each pixel */ |
| 407 |
> |
while (i--) { /* process each pixel */ |
| 408 |
|
if (zscn[i] <= 0.0) |
| 409 |
|
continue; /* illegal depth */ |
| 410 |
|
pix2loc(vl, &prs, i, j); |