| 5 |
|
* Copy data into a holodeck file |
| 6 |
|
*/ |
| 7 |
|
|
| 8 |
– |
#include "holo.h" |
| 8 |
|
#include "platform.h" |
| 9 |
+ |
#include "rterror.h" |
| 10 |
+ |
#include "holo.h" |
| 11 |
|
#include "view.h" |
| 12 |
|
|
| 13 |
|
#ifndef BKBSIZE |
| 22 |
|
|
| 23 |
|
char *progname; /* global argv[0] */ |
| 24 |
|
|
| 25 |
+ |
struct phead { |
| 26 |
+ |
VIEW vw; |
| 27 |
+ |
double expos; |
| 28 |
+ |
short gotview; |
| 29 |
+ |
short badfmt; |
| 30 |
+ |
short altprims; |
| 31 |
+ |
}; |
| 32 |
+ |
static int openholo(char *fname, int append); |
| 33 |
+ |
static void addray(FVECT ro, FVECT rd, double d, COLR cv); |
| 34 |
+ |
static gethfunc holheadline; |
| 35 |
+ |
static int bpcmp(const void *b1p, const void *b2p); |
| 36 |
+ |
static int addclump(HOLO *hp, int *bq, int nb); |
| 37 |
+ |
static void addholo(char *hdf); |
| 38 |
+ |
static gethfunc picheadline; |
| 39 |
+ |
static void addpicz(char *pcf, char *zbf); |
| 40 |
|
|
| 41 |
< |
main(argc, argv) |
| 42 |
< |
int argc; |
| 43 |
< |
char *argv[]; |
| 41 |
> |
|
| 42 |
> |
|
| 43 |
> |
int |
| 44 |
> |
main( |
| 45 |
> |
int argc, |
| 46 |
> |
char *argv[] |
| 47 |
> |
) |
| 48 |
|
{ |
| 49 |
|
int i; |
| 50 |
|
|
| 85 |
|
userr: |
| 86 |
|
fprintf(stderr, "Usage: %s output.hdk [-u][-d] -h inp1.hdk ..\n", |
| 87 |
|
progname); |
| 88 |
< |
fprintf(stderr, " Or: %s output.hdk [-u][-d] -p inp1.pic inp1.zbf ..\n", |
| 88 |
> |
fprintf(stderr, " Or: %s output.hdk [-u][-d] -p inp1.hdr inp1.zbf ..\n", |
| 89 |
|
progname); |
| 90 |
|
exit(1); |
| 91 |
|
} |
| 95 |
|
#define H_OBST 02 |
| 96 |
|
#define H_OBSF 04 |
| 97 |
|
|
| 98 |
< |
int |
| 99 |
< |
holheadline(s, hf) /* check holodeck header line */ |
| 100 |
< |
register char *s; |
| 101 |
< |
int *hf; |
| 98 |
> |
static int |
| 99 |
> |
holheadline( /* check holodeck header line */ |
| 100 |
> |
char *s, |
| 101 |
> |
void *vhf |
| 102 |
> |
) |
| 103 |
|
{ |
| 104 |
< |
char fmt[32]; |
| 104 |
> |
char fmt[MAXFMTLEN]; |
| 105 |
> |
int *hf = vhf; |
| 106 |
|
|
| 107 |
|
if (formatval(fmt, s)) { |
| 108 |
|
if (strcmp(fmt, HOLOFMT)) |
| 126 |
|
} |
| 127 |
|
|
| 128 |
|
int |
| 129 |
< |
openholo(fname, append) /* open existing holodeck file for i/o */ |
| 130 |
< |
char *fname; |
| 131 |
< |
int append; |
| 129 |
> |
openholo( /* open existing holodeck file for i/o */ |
| 130 |
> |
char *fname, |
| 131 |
> |
int append |
| 132 |
> |
) |
| 133 |
|
{ |
| 134 |
|
FILE *fp; |
| 135 |
|
int fd; |
| 136 |
|
int hflags = 0; |
| 137 |
< |
long nextloc; |
| 137 |
> |
off_t nextloc; |
| 138 |
|
int n; |
| 139 |
|
/* open holodeck file */ |
| 140 |
|
if ((fp = fopen(fname, append ? "r+" : "r")) == NULL) { |
| 143 |
|
error(SYSTEM, errmsg); |
| 144 |
|
} |
| 145 |
|
/* check header and magic number */ |
| 146 |
< |
if (getheader(fp, holheadline, (char *)&hflags) < 0 || |
| 146 |
> |
if (getheader(fp, holheadline, &hflags) < 0 || |
| 147 |
|
hflags&H_BADF || getw(fp) != HOLOMAGIC) { |
| 148 |
|
sprintf(errmsg, "file \"%s\" not in holodeck format", fname); |
| 149 |
|
error(USER, errmsg); |
| 152 |
|
nextloc = ftell(fp); /* get stdio position */ |
| 153 |
|
fclose(fp); /* done with stdio */ |
| 154 |
|
for (n = 0; nextloc > 0L; n++) { /* initialize each section */ |
| 155 |
< |
lseek(fd, (off_t)nextloc, SEEK_SET); |
| 155 |
> |
lseek(fd, nextloc, SEEK_SET); |
| 156 |
|
read(fd, (char *)&nextloc, sizeof(nextloc)); |
| 157 |
|
hdinit(fd, NULL)->priv = hflags&H_OBST ? &obstr : |
| 158 |
|
hflags&H_OBSF ? &unobstr : (char *)NULL; |
| 165 |
|
#undef H_OBSF |
| 166 |
|
|
| 167 |
|
|
| 168 |
< |
addray(ro, rd, d, cv) /* add a ray to our output holodeck */ |
| 169 |
< |
FVECT ro, rd; |
| 170 |
< |
double d; |
| 171 |
< |
COLR cv; |
| 168 |
> |
void |
| 169 |
> |
addray( /* add a ray to our output holodeck */ |
| 170 |
> |
FVECT ro, |
| 171 |
> |
FVECT rd, |
| 172 |
> |
double d, |
| 173 |
> |
COLR cv |
| 174 |
> |
) |
| 175 |
|
{ |
| 176 |
|
int sn, bi, n; |
| 177 |
< |
register HOLO *hp; |
| 177 |
> |
HOLO *hp; |
| 178 |
|
GCOORD gc[2]; |
| 179 |
< |
BYTE rr[2][2]; |
| 179 |
> |
uby8 rr[2][2]; |
| 180 |
|
BEAM *bp; |
| 181 |
|
double d0, d1; |
| 182 |
|
unsigned dc; |
| 183 |
< |
register RAYVAL *rv; |
| 183 |
> |
RAYVAL *rv; |
| 184 |
|
/* check each output section */ |
| 185 |
|
for (sn = noutsects; sn--; ) { |
| 186 |
|
hp = hdlist[sn]; |
| 218 |
|
static BEAMI *beamdir; |
| 219 |
|
|
| 220 |
|
static int |
| 221 |
< |
bpcmp(b1p, b2p) /* compare beam positions on disk */ |
| 222 |
< |
int *b1p, *b2p; |
| 221 |
> |
bpcmp( /* compare beam positions on disk */ |
| 222 |
> |
const void *b1p, |
| 223 |
> |
const void *b2p |
| 224 |
> |
) |
| 225 |
|
{ |
| 226 |
< |
register off_t pdif = beamdir[*b1p].fo - beamdir[*b2p].fo; |
| 226 |
> |
off_t pdif = beamdir[*(int*)b1p].fo - beamdir[*(int*)b2p].fo; |
| 227 |
|
|
| 228 |
|
if (pdif > 0L) return(1); |
| 229 |
|
if (pdif < 0L) return(-1); |
| 231 |
|
} |
| 232 |
|
|
| 233 |
|
static int |
| 234 |
< |
addclump(hp, bq, nb) /* transfer the given clump and free */ |
| 235 |
< |
HOLO *hp; |
| 236 |
< |
int *bq, nb; |
| 234 |
> |
addclump( /* transfer the given clump and free */ |
| 235 |
> |
HOLO *hp, |
| 236 |
> |
int *bq, |
| 237 |
> |
int nb |
| 238 |
> |
) |
| 239 |
|
{ |
| 240 |
|
GCOORD gc[2]; |
| 241 |
|
FVECT ro, rd; |
| 242 |
|
double d; |
| 243 |
|
int i; |
| 244 |
< |
register int k; |
| 245 |
< |
register BEAM *bp; |
| 244 |
> |
int k; |
| 245 |
> |
BEAM *bp; |
| 246 |
|
/* sort based on file position */ |
| 247 |
|
beamdir = hp->bi; |
| 248 |
|
qsort((char *)bq, nb, sizeof(*bq), bpcmp); |
| 265 |
|
return(0); |
| 266 |
|
} |
| 267 |
|
|
| 268 |
< |
addholo(hdf) /* add a holodeck file */ |
| 269 |
< |
char *hdf; |
| 268 |
> |
|
| 269 |
> |
void |
| 270 |
> |
addholo( /* add a holodeck file */ |
| 271 |
> |
char *hdf |
| 272 |
> |
) |
| 273 |
|
{ |
| 274 |
|
int fd; |
| 275 |
|
/* open the holodeck for reading */ |
| 285 |
|
} |
| 286 |
|
|
| 287 |
|
|
| 255 |
– |
struct phead { |
| 256 |
– |
VIEW vw; |
| 257 |
– |
double expos; |
| 258 |
– |
short gotview; |
| 259 |
– |
short badfmt; |
| 260 |
– |
short altprims; |
| 261 |
– |
}; |
| 288 |
|
|
| 289 |
< |
|
| 290 |
< |
int |
| 291 |
< |
picheadline(s, ph) /* process picture header line */ |
| 292 |
< |
char *s; |
| 293 |
< |
struct phead *ph; |
| 289 |
> |
static int |
| 290 |
> |
picheadline( /* process picture header line */ |
| 291 |
> |
char *s, |
| 292 |
> |
void *vph |
| 293 |
> |
) |
| 294 |
|
{ |
| 295 |
|
char fmt[32]; |
| 296 |
+ |
struct phead *ph = vph; |
| 297 |
|
|
| 298 |
|
if (formatval(fmt, s)) { |
| 299 |
|
ph->badfmt = strcmp(fmt, COLRFMT); |
| 315 |
|
} |
| 316 |
|
|
| 317 |
|
|
| 318 |
< |
addpicz(pcf, zbf) /* add a picture + depth-buffer */ |
| 319 |
< |
char *pcf, *zbf; |
| 318 |
> |
void |
| 319 |
> |
addpicz( /* add a picture + depth-buffer */ |
| 320 |
> |
char *pcf, |
| 321 |
> |
char *zbf |
| 322 |
> |
) |
| 323 |
|
{ |
| 324 |
|
FILE *pfp; |
| 325 |
|
int zfd; |
| 334 |
|
double aftd; |
| 335 |
|
COLOR ctmp; |
| 336 |
|
int j; |
| 337 |
< |
register int i; |
| 337 |
> |
int i; |
| 338 |
|
/* open files */ |
| 339 |
|
if ((pfp = fopen(pcf, "r")) == NULL) { |
| 340 |
|
sprintf(errmsg, "cannot open picture file \"%s\"", pcf); |
| 348 |
|
phd.vw = stdview; |
| 349 |
|
phd.expos = 1.0; |
| 350 |
|
phd.badfmt = phd.gotview = phd.altprims = 0; |
| 351 |
< |
if (getheader(pfp, picheadline, (char *)&phd) < 0 || |
| 351 |
> |
if (getheader(pfp, picheadline, &phd) < 0 || |
| 352 |
|
phd.badfmt || !fgetsresolu(&prs, pfp)) { |
| 353 |
|
sprintf(errmsg, "bad format for picture file \"%s\"", pcf); |
| 354 |
|
error(USER, errmsg); |
| 359 |
|
error(USER, errmsg); |
| 360 |
|
} |
| 361 |
|
if (phd.altprims) { |
| 362 |
< |
sprintf(errmsg, "ignoring primary values in picture \"%s\"", |
| 362 |
> |
sprintf(errmsg, "ignoring color primaries in picture \"%s\"", |
| 363 |
|
pcf); |
| 364 |
|
error(WARNING, errmsg); |
| 365 |
|
} |
| 398 |
|
error(USER, errmsg); |
| 399 |
|
} |
| 400 |
|
for (i = scanlen(&prs); i--; ) { /* do each pixel */ |
| 401 |
+ |
if (zscn[i] <= 0.0) |
| 402 |
+ |
continue; /* illegal depth */ |
| 403 |
|
pix2loc(vl, &prs, i, j); |
| 404 |
|
aftd = viewray(ro, rd, &phd.vw, vl[0], vl[1]); |
| 405 |
|
if (aftd < -FTINY) |
| 426 |
|
|
| 427 |
|
|
| 428 |
|
void |
| 429 |
< |
eputs(s) /* put error message to stderr */ |
| 430 |
< |
register char *s; |
| 429 |
> |
eputs( /* put error message to stderr */ |
| 430 |
> |
char *s |
| 431 |
> |
) |
| 432 |
|
{ |
| 433 |
|
static int midline = 0; |
| 434 |
|
|
| 447 |
|
|
| 448 |
|
|
| 449 |
|
void |
| 450 |
< |
quit(code) /* exit the program gracefully */ |
| 451 |
< |
int code; |
| 450 |
> |
quit( /* exit the program gracefully */ |
| 451 |
> |
int code |
| 452 |
> |
) |
| 453 |
|
{ |
| 454 |
|
hdsync(NULL, 1); /* write out any buffered data */ |
| 455 |
|
exit(code); |