ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/hd/rhcopy.c
(Generate patch)

Comparing ray/src/hd/rhcopy.c (file contents):
Revision 3.32 by greg, Mon Oct 21 18:19:32 2019 UTC vs.
Revision 3.41 by greg, Thu Jun 5 19:10:31 2025 UTC

# Line 13 | Line 13 | static const char      RCSid[] = "$Id$";
13   #ifndef BKBSIZE
14   #define BKBSIZE         256             /* beam clump size (kilobytes) */
15   #endif
16 +                                /* possible operations */
17 + #define FROM_HOLO       1               /* copy between holodecks */
18 + #define FROM_PICZ       2               /* copy from HDR + depth to holodeck */
19 + #define FROM_STDIN      3               /* copy from stdin to holodeck */
20 + #define TO_STDOUT       4               /* copy rays from holodeck to stdout */
21  
22 + int     operation = 0;          /* what we are doing */
23 + char    *rspec = "";            /* ray details for i/o */
24   int     checkdepth = 1;         /* check depth (!-d option)? */
25   int     checkrepeats = 0;       /* check for repeats (-u option)? */
26 < int     frompicz;               /* input from pictures & depth-buffers? */
27 < int     noutsects;              /* number of output sections */
21 < char    obstr, unobstr;         /* flag pointer values */
26 > int     nholosects;             /* number of original holodeck sections */
27 > int     iofmt = 'a';            /* input/output format for rays */
28  
29 < char    *progname;              /* global argv[0] */
29 >                                /* holodeck flags */
30 > #define H_BADF          01              /* bad format */
31 > #define H_OBST          02              /* OBSTRUCTIONS= True */
32 > #define H_OBSF          04              /* OBSTRUCTIONS= False */
33 > #define H_VDST          010             /* VDISTANCE= True */
34 > #define H_SWAP          020             /* byte order is different */
35  
36   struct phead {
37          VIEW    vw;
# Line 29 | Line 40 | struct phead {
40          short   badfmt;
41          short   altprims;
42   };
43 +
44 + typedef struct {
45 +        FVECT   ro;
46 +        FVECT   rd;
47 +        RREAL   d;
48 +        COLR    cv;
49 + } RAYPAR;
50 +
51   static int openholo(char *fname, int append);
52 < static void addray(FVECT ro, FVECT rd, double d, COLR cv);
52 > static int addray(RAYPAR *rp);
53 > static int readval(RREAL *v, int n, FILE *fp);
54 > static void readrays(FILE *fp);
55 > static int writeval(RREAL *v, int n, FILE *fp);
56 > static int write_ray(RAYPAR *rp, FILE *fp);
57 > static void writerays(FILE *fp);
58   static gethfunc holheadline;
59   static int bpcmp(const void *b1p, const void *b2p);
60   static int addclump(HOLO *hp, int *bq, int nb);
# Line 39 | Line 63 | static gethfunc picheadline;
63   static void addpicz(char *pcf, char *zbf);
64  
65  
42
66   int
67   main(
68          int     argc,
# Line 48 | Line 71 | main(
71   {
72          int     i;
73  
74 <        progname = argv[0];
52 <        frompicz = -1;
74 >        fixargv0(argv[0]);
75          for (i = 2; i < argc && argv[i][0] == '-'; i++)
76                  switch (argv[i][1]) {
77                  case 'u':
# Line 58 | Line 80 | main(
80                  case 'd':
81                          checkdepth = 0;
82                          break;
83 +                case 'f':
84 +                        iofmt = argv[i][2];
85 +                        if (!strchr("afd", iofmt))
86 +                                error(USER, "-f? i/o format must be 'a', 'f', or 'd'");
87 +                        break;
88                  case 'h':
89 <                        frompicz = 0;
89 >                        operation = FROM_HOLO;
90                          break;
91                  case 'p':
92 <                        frompicz = 1;
92 >                        operation = FROM_PICZ;
93                          break;
94 +                case 'i':
95 +                        operation = FROM_STDIN;
96 +                        rspec = argv[i]+2;
97 +                        break;
98 +                case 'o':
99 +                        operation = TO_STDOUT;
100 +                        rspec = argv[i]+2;
101 +                        break;
102                  default:
103                          goto userr;
104                  }
105 <        if (i >= argc || frompicz < 0)
105 >        if (!operation | (i > argc-((operation==FROM_HOLO)|(operation==FROM_PICZ))))
106                  goto userr;
107 <        if (frompicz && (argc-i)%2)
107 >        if (operation == FROM_PICZ && (argc-i)%2)
108                  goto userr;
109 <        noutsects = openholo(argv[1], 1);
110 <        if (frompicz) {
109 >        nholosects = openholo(argv[1], (operation != TO_STDOUT));
110 >                                        /* check requested i/o is compatible */
111 >        if (strchr(rspec, 'l') && !(*(int *)hdlist[0]->priv & H_VDST))
112 >                error(USER, "i/o parameter 'l' incompatible with VDISTANCE=False");
113 >        if (strchr(rspec, 'L') && *(int *)hdlist[0]->priv & H_VDST)
114 >                error(USER, "i/o parameter 'L' incompatible with VDISTANCE=True");
115 >
116 >        switch (operation) {            /* perform requested operation */
117 >        case FROM_PICZ:
118                  for ( ; i < argc; i += 2)
119                          addpicz(argv[i], argv[i+1]);
120 <        } else {
120 >                break;
121 >        case FROM_HOLO:
122                  if (BKBSIZE*1024*1.5 > hdcachesize)
123                          hdcachesize = BKBSIZE*1024*1.5;
124                  for ( ; i < argc; i++)
125                          addholo(argv[i]);
126 +                break;
127 +        case FROM_STDIN:
128 +                readrays(stdin);
129 +                break;
130 +        case TO_STDOUT:
131 +                writerays(stdout);
132 +                break;
133          }
134          quit(0);
135   userr:
136 <        fprintf(stderr, "Usage: %s output.hdk [-u][-d] -h inp1.hdk ..\n",
136 >        fprintf(stderr, "Usage: %s dest.hdk [-u][-d] -h inp1.hdk ..\n",
137                          progname);
138 <        fprintf(stderr, "   Or: %s output.hdk [-u][-d] -p inp1.hdr inp1.zbf ..\n",
138 >        fprintf(stderr, "   Or: %s dest.hdk [-u][-d] -p inp1.hdr inp1.zbf ..\n",
139                          progname);
140 +        fprintf(stderr, "   Or: %s dest.hdk [-f{a|f|d}][-u][-d] -i[odplLv]\n",
141 +                        progname);
142 +        fprintf(stderr, "   Or: %s src.hdk [-f{a|f|d}] -o[odplLv] ..\n",
143 +                        progname);
144          exit(1);
145   }
146  
93
94 #define H_BADF  01
95 #define H_OBST  02
96 #define H_OBSF  04
97
147   static int
148   holheadline(            /* check holodeck header line */
149          char    *s,
150          void    *vhf
151   )
152   {
153 +        int     be;
154          char    fmt[MAXFMTLEN];
155 <        int     *hf = vhf;
155 >        int     *hf = (int *)vhf;
156  
157          if (formatval(fmt, s)) {
158                  if (strcmp(fmt, HOLOFMT))
# Line 122 | Line 172 | holheadline(           /* check holodeck header line */
172                          error(WARNING, "bad OBSTRUCTIONS value in holodeck");
173                  return(0);
174          }
175 +        if (!strncmp(s, "VDISTANCE=", 10)) {
176 +                s += 10;
177 +                while (*s == ' ') s++;
178 +                if ((*s == 't') | (*s == 'T'))
179 +                        *hf |= H_VDST;
180 +                else if ((*s != 'f') % (*s != 'F'))
181 +                        error(WARNING, "bad VDISTANCE value in holodeck");
182 +                return(0);
183 +        }
184 +        if ((be = isbigendian(s)) >= 0) {
185 +                if (be != nativebigendian())
186 +                        *hf |= H_SWAP;
187 +                return(0);
188 +        }
189          return(0);
190   }
191  
# Line 134 | Line 198 | openholo(              /* open existing holodeck file for i/o */
198          FILE    *fp;
199          int     fd;
200          int     hflags = 0;
201 +        int     *hfstore;
202          off_t   nextloc;
203          int     n;
204                                          /* open holodeck file */
# Line 144 | Line 209 | openholo(              /* open existing holodeck file for i/o */
209          }
210                                          /* check header and magic number */
211          if (getheader(fp, holheadline, &hflags) < 0 ||
212 <                        hflags&H_BADF || getw(fp) != HOLOMAGIC) {
213 <                sprintf(errmsg, "file \"%s\" not in holodeck format", fname);
212 >                        hflags&(H_BADF|H_SWAP) || getw(fp) != HOLOMAGIC) {
213 >                sprintf(errmsg, "holodeck \"%s\" not in expected format", fname);
214                  error(USER, errmsg);
215          }
216          fd = dup(fileno(fp));                   /* dup file handle */
217          nextloc = ftell(fp);                    /* get stdio position */
218          fclose(fp);                             /* done with stdio */
219 +        hfstore = (int *)malloc(sizeof(int));   /* tiny memory leak but who cares? */
220 +        *hfstore = hflags;
221          for (n = 0; nextloc > 0L; n++) {        /* initialize each section */
222                  lseek(fd, nextloc, SEEK_SET);
223                  read(fd, (char *)&nextloc, sizeof(nextloc));
224 <                hdinit(fd, NULL)->priv = hflags&H_OBST ? &obstr :
158 <                                hflags&H_OBSF ? &unobstr : (char *)NULL;
224 >                hdinit(fd, NULL)->priv = hfstore;
225          }
226          return(n);
227   }
228  
229 < #undef H_BADF
164 < #undef H_OBST
165 < #undef H_OBSF
166 <
167 <
168 < void
229 > int
230   addray(         /* add a ray to our output holodeck */
231 <        FVECT   ro,
171 <        FVECT   rd,
172 <        double  d,
173 <        COLR    cv
231 >        RAYPAR *rp
232   )
233   {
234          int     sn, bi, n;
# Line 181 | Line 239 | addray(                /* add a ray to our output holodeck */
239          double  d0, d1;
240          unsigned        dc;
241          RAYVAL  *rv;
242 +        int     nsects = 0;
243                                  /* check each output section */
244 <        for (sn = noutsects; sn--; ) {
244 >        for (sn = nholosects; sn--; ) {
245                  hp = hdlist[sn];
246 <                d0 = hdinter(gc, rr, &d1, hp, ro, rd);
247 <                if (d <= d0 || d1 < -0.001)
246 >                d0 = hdinter(gc, rr, &d1, hp, rp->ro, rp->rd);
247 >                if (rp->d <= d0 || d1 < -0.001)
248                          continue;       /* missed section */
249                  if (checkdepth) {               /* check depth */
250 <                        if (hp->priv == &obstr && d0 < -0.001)
250 >                        if (*(int *)hp->priv & H_OBST && d0 < -0.001)
251                                  continue;       /* ray starts too late */
252 <                        if (hp->priv == &unobstr && d < 0.999*d1)
252 >                        if (*(int *)hp->priv & H_OBSF && rp->d < 0.999*d1)
253                                  continue;       /* ray ends too soon */
254                  }
255 <                dc = hdcode(hp, d-d0);
255 >                dc = hdcode(hp, rp->d-d0);
256                  bi = hdbindex(hp, gc);          /* check for duplicates */
257                  if (checkrepeats && (bp = hdgetbeam(hp, bi)) != NULL) {
258                          for (n = bp->nrm, rv = hdbray(bp); n--; rv++)
259 <                                if ((hp->priv != NULL || rv->d == dc) &&
259 >                                if ((rv->d == dc || *(int *)hp->priv & (H_OBST|H_OBSF)) &&
260                                                  rv->r[0][0] == rr[0][0] &&
261                                                  rv->r[0][1] == rr[0][1] &&
262                                                  rv->r[1][0] == rr[1][0] &&
# Line 210 | Line 269 | addray(                /* add a ray to our output holodeck */
269                  rv->d = dc;
270                  rv->r[0][0] = rr[0][0]; rv->r[0][1] = rr[0][1];
271                  rv->r[1][0] = rr[1][0]; rv->r[1][1] = rr[1][1];
272 <                copycolr(rv->v, cv);
272 >                copycolr(rv->v, rp->cv);
273 >                ++nsects;
274          }
275 +        return nsects;
276   }
277  
278 + /* Read n-vector from file stream */
279 + static int
280 + readval(RREAL *v, int n, FILE *fp)
281 + {
282 +        int     i;
283 + #ifdef SMLFLT
284 +        double  vd[3];
285 +        switch (iofmt) {
286 +        case 'f':
287 +                return getbinary(v, sizeof(float), n, fp);
288 +        case 'd':
289 +                n = getbinary(vd, sizeof(double), n, fp);
290 +                for (i = n; i-- > 0; ) v[i] = vd[i];
291 +                return n;
292 +        case 'a':
293 +                for (i = 0; i < n; i++)
294 +                        if (fscanf(fp, "%f ", &v[i]) != 1)
295 +                                break;
296 +                return i;
297 +        }
298 + #else
299 +        float   vf[3];
300 +        switch (iofmt) {
301 +        case 'd':
302 +                return getbinary(v, sizeof(double), n, fp);
303 +        case 'f':
304 +                n = getbinary(vf, sizeof(float), n, fp);
305 +                for (i = n; i-- > 0; ) v[i] = vf[i];
306 +                return n;
307 +        case 'a':
308 +                for (i = 0; i < n; i++)
309 +                        if (fscanf(fp, "%lf ", &v[i]) != 1)
310 +                                break;
311 +                return i;
312 +        }
313 + #endif
314 +        return -1;
315 + }
316  
317 + #define GOT_ORG         0x01
318 + #define GOT_DIR         0x02
319 + #define GOT_LEN         0x04
320 + #define GOT_VAL         0x10
321 + #define ALSO_POS        0x20
322 + #define BAD_DIR         0x40
323 + #define BAD_LEN         0x80
324 +
325 + /* Read rays from stream and add to holodeck */
326 + static void
327 + readrays(FILE *fp)
328 + {
329 +        unsigned long   nread=0, ngood=0;
330 +
331 +        if (iofmt != 'a')
332 +                SET_FILE_BINARY(fp);
333 + #ifdef getc_unlocked
334 +        flockfile(fp);
335 + #endif
336 +        while (!feof(fp)) {             /* read entirety of input */
337 +                RAYPAR  ryp;
338 +                FVECT   pos;
339 +                FVECT   col;
340 +                int     flags = 0;
341 +                int     i;
342 +                for (i = 0; rspec[i]; i++) {
343 +                        switch (rspec[i]) {
344 +                        case 'o':               /* ray origin */
345 +                                if (readval(ryp.ro, 3, fp) < 3)
346 +                                        break;
347 +                                flags |= GOT_ORG;
348 +                                continue;
349 +                        case 'd':               /* ray direction */
350 +                                if (readval(ryp.rd, 3, fp) < 3)
351 +                                        break;
352 +                                if (normalize(ryp.rd) == 0)
353 +                                        flags |= BAD_DIR;
354 +                                else
355 +                                        flags |= GOT_DIR;
356 +                                continue;
357 +                        case 'p':               /* ray intersection */
358 +                                if (readval(pos, 3, fp) < 3)
359 +                                        break;
360 +                                flags |= ALSO_POS;
361 +                                continue;
362 +                        case 'L':               /* ray first length */
363 +                        case 'l':               /* ray virtual length */
364 +                                if (readval(&ryp.d, 1, fp) < 1)
365 +                                        break;
366 +                                if (ryp.d <= FTINY)
367 +                                        flags |= BAD_LEN;
368 +                                else
369 +                                        flags |= GOT_LEN;
370 +                                continue;
371 +                        case 'v':               /* ray value */
372 +                                if (readval(col, 3, fp) < 3)
373 +                                        break;
374 +                                setcolr(ryp.cv, col[0], col[1], col[2]);
375 +                                flags |= GOT_VAL;
376 +                                continue;
377 +                        default:
378 +                                sprintf(errmsg, "unsupported parameter '%c' in -i%s",
379 +                                                rspec[i], rspec);
380 +                                error(USER, errmsg);
381 +                        }
382 +                        if (!flags)     /* got nothing, so may be normal EOF */
383 +                                return;
384 +                }
385 +                ++nread;
386 +                if (flags & (BAD_DIR|BAD_LEN))
387 +                        continue;       /* just a bad ray is all -- skip */
388 +                if (!(flags & GOT_VAL))
389 +                        goto missingData;
390 +                if ((flags & (GOT_ORG|GOT_DIR|GOT_LEN)) != (GOT_ORG|GOT_DIR|GOT_LEN)) {
391 +                        if (!(flags & ALSO_POS))
392 +                                goto missingData;
393 +                        if (flags & GOT_ORG) {
394 +                                VSUB(ryp.rd, pos, ryp.ro);
395 +                                ryp.d = normalize(ryp.rd);
396 +                                if (ryp.d == 0)
397 +                                        continue;
398 +                        } else if ((flags & (GOT_DIR|GOT_LEN)) == (GOT_DIR|GOT_LEN)) {
399 +                                VSUM(ryp.ro, pos, ryp.rd, -ryp.d);
400 +                        } else
401 +                                goto missingData;
402 +                }
403 +                ngood += (addray(&ryp) > 0);    /* add our ray to holodeck */
404 +        }
405 +        return;
406 + missingData:
407 +        sprintf(errmsg, "insufficient data or read error with -i%s after %lu rays read (%lu used)",
408 +                        rspec, nread, ngood);
409 +        error(USER, errmsg);
410 + }
411 +
412 + /* Write vector value to file stream */
413 + static int
414 + writeval(RREAL *v, int n, FILE *fp)
415 + {
416 +        int     i;
417 +
418 +        if (iofmt == 'a') {
419 +                for (i = 0; i < n; i++)
420 +                        if (fprintf(fp, "\t%.4e", v[i]) < 0)
421 +                                break;
422 +                return i;
423 +        }
424 + #ifdef SMLFLT
425 +        if (iofmt == 'd') {
426 +                double  vd[3];
427 +                for (i = n; i--; ) vd[i] = v[i];
428 +                return putbinary(vd, sizeof(double), n, fp);
429 +        }
430 + #else
431 +        if (iofmt == 'f') {
432 +                float   vf[3];
433 +                for (i = n; i--; ) vf[i] = v[i];
434 +                return putbinary(vf, sizeof(float), n, fp);
435 +        }
436 + #endif
437 +        return putbinary(v, sizeof(*v), n, fp);
438 + }
439 +
440 + /* Write out an individual ray as requested */
441 + static int
442 + write_ray(RAYPAR *rp, FILE *fp)
443 + {
444 +        COLOR   cval;
445 +        FVECT   v3;
446 +        char    *typ = rspec;
447 +
448 +        for ( ; ; ) {
449 +                switch (*typ++) {
450 +                case 'o':               /* ray origin */
451 +                        if (writeval(rp->ro, 3, fp) < 3)
452 +                                break;
453 +                        continue;
454 +                case 'd':               /* ray direction */
455 +                        if (writeval(rp->rd, 3, fp) < 3)
456 +                                break;
457 +                        continue;
458 +                case 'p':               /* ray intersection */
459 +                        VSUM(v3, rp->ro, rp->rd, rp->d);
460 +                        if (writeval(v3, 3, fp) < 3)
461 +                                break;
462 +                        continue;
463 +                case 'L':               /* ray first length */
464 +                case 'l':               /* ray virtual length */
465 +                        if (writeval(&rp->d, 1, fp) < 1)
466 +                                break;
467 +                        continue;
468 +                case 'v':               /* ray value */
469 +                        colr_color(cval, rp->cv);
470 +                        VCOPY(v3, cval);
471 +                        if (writeval(v3, 3, fp) < 3)
472 +                                break;
473 +                        continue;
474 +                case '\0':              /* end of spec -- success */
475 +                        if (iofmt == 'a')
476 +                                fputc('\n', fp);
477 +                        return(1);
478 +                default:
479 +                        sprintf(errmsg, "unsupported parameter '%c' in -o%s", typ[-1], rspec);
480 +                }
481 +                break;                  /* land here on error */
482 +        }
483 +        return 0;                       /* write error? */
484 + }
485 +
486   static BEAMI    *beamdir;
487  
488   static int
# Line 223 | Line 491 | bpcmp(                 /* compare beam positions on disk */
491          const void      *b2p
492   )
493   {
494 <        off_t   pdif = beamdir[*(int*)b1p].fo - beamdir[*(int*)b2p].fo;
494 >        off_t   pdif = beamdir[*(int *)b1p].fo - beamdir[*(int *)b2p].fo;
495  
496          if (pdif > 0L) return(1);
497          if (pdif < 0L) return(-1);
498          return(0);
499   }
500  
501 + /* Write all rays from holodeck to stream */
502 + static void
503 + writerays(FILE *fp)
504 + {
505 +        int     sn, bi, k;
506 +        GCOORD  gc[2];
507 +        RAYVAL  *rv;
508 +        RAYPAR  ryp;
509 +
510 +        if (!*rspec) {
511 +                error(WARNING, "empty -o* output spec, quitting");
512 +                return;
513 +        }
514 +        if (iofmt != 'a')
515 +                SET_FILE_BINARY(fp);
516 + #ifdef getc_unlocked
517 +        flockfile(fp);
518 + #endif
519 +        for (sn = 0; sn < nholosects; sn++) {   /* write each holodeck section */
520 +                HOLO    *hp = hdlist[sn];
521 +                int     nb = nbeams(hp);        /* sort beams by file location */
522 +                int     *bq = (int *)malloc(nb*sizeof(int));
523 +                if (!bq)
524 +                        error(SYSTEM, "out of memory in writerays()");
525 +                for (bi = nb; bi--; ) bq[bi] = bi+1;
526 +                beamdir = hp->bi;
527 +                qsort(bq, nb, sizeof(*bq), bpcmp);
528 +                for (bi = 0; bi < nb; bi++) {
529 +                        BEAM    *bp = hdgetbeam(hp, bq[bi]);
530 +                        if (!bp)                /* empty beam? */
531 +                                continue;
532 +                        hdbcoord(gc, hp, bq[bi]);
533 +                        rv = hdbray(bp);
534 +                        for (k = bp->nrm; k--; rv++) {
535 +                                RREAL   hitd = hddepth(hp, rv->d);
536 +                                ryp.d = hdray(ryp.ro, ryp.rd, hp, gc, rv->r);
537 +                                if (*(int *)hp->priv & H_OBST) {
538 +                                        ryp.d = 0;
539 +                                } else {
540 +                                        if (ryp.d > 0.97*hitd)
541 +                                                ryp.d = 0.97*hitd;
542 +                                        VSUM(ryp.ro, ryp.ro, ryp.rd, ryp.d);
543 +                                }
544 +                                ryp.d = hitd - ryp.d;
545 +                                copycolr(ryp.cv, rv->v);
546 +                                if (!write_ray(&ryp, fp)) {
547 +                                        free(bq);
548 +                                        goto writError;
549 +                                }
550 +                        }
551 +                        hdfreebeam(hp, bq[bi]);
552 +                }
553 +                free(bq);
554 +        }
555 +        if (fflush(fp) != EOF)
556 +                return;
557 + writError:
558 +        error(SYSTEM, "error writing holodeck rays");
559 + }
560 +
561   static int
562   addclump(               /* transfer the given clump and free */
563          HOLO    *hp,
# Line 238 | Line 566 | addclump(              /* transfer the given clump and free */
566   )
567   {
568          GCOORD  gc[2];
569 <        FVECT   ro, rd;
570 <        double  d;
569 >        RAYPAR  ryp;
570 >        RAYVAL  *rv;
571          int     i;
572          int     k;
573          BEAM    *bp;
574                                          /* sort based on file position */
575          beamdir = hp->bi;
576 <        qsort((char *)bq, nb, sizeof(*bq), bpcmp);
576 >        qsort(bq, nb, sizeof(*bq), bpcmp);
577                                          /* transfer each beam */
578          for (i = 0; i < nb; i++) {
579                  bp = hdgetbeam(hp, bq[i]);
580                  hdbcoord(gc, hp, bq[i]);
581 <                                                /* add each ray to output */
582 <                for (k = bp->nrm; k--; ) {
583 <                        d = hdray(ro, rd, hp, gc, hdbray(bp)[k].r);
584 <                        if (hp->priv == &unobstr)
585 <                                VSUM(ro, ro, rd, d);
581 >                rv = hdbray(bp);                        /* add each ray to output */
582 >                for (k = bp->nrm; k--; rv++) {
583 >                        ryp.d = hdray(ryp.ro, ryp.rd, hp, gc, rv->r);
584 >                        if (*(int *)hp->priv & H_OBSF)
585 >                                VSUM(ryp.ro, ryp.ro, ryp.rd, ryp.d);
586                          else
587 <                                d = 0.;
588 <                        d = hddepth(hp, hdbray(bp)[k].d) - d;
589 <                        addray(ro, rd, d, hdbray(bp)[k].v);
587 >                                ryp.d = 0.;
588 >                        ryp.d = hddepth(hp, rv->d) - ryp.d;
589 >                        copycolr(ryp.cv, rv->v);
590 >                        addray(&ryp);
591                  }
592                  hdfreebeam(hp, bq[i]);          /* free the beam */
593          }
# Line 274 | Line 603 | addholo(                       /* add a holodeck file */
603          int     fd;
604                                          /* open the holodeck for reading */
605          openholo(hdf, 0);
606 <        fd = hdlist[noutsects]->fd;     /* remember the file handle */
607 <        while (hdlist[noutsects] != NULL) {     /* load each section */
606 >        fd = hdlist[nholosects]->fd;    /* remember the file handle */
607 >        while (hdlist[nholosects] != NULL) {    /* load each section */
608                                                          /* clump the beams */
609 <                clumpbeams(hdlist[noutsects], 0, BKBSIZE*1024, addclump);
610 <                hddone(hdlist[noutsects]);              /* free the section */
609 >                clumpbeams(hdlist[nholosects], 0, BKBSIZE*1024, addclump);
610 >                hddone(hdlist[nholosects]);             /* free the section */
611          }
612          close(fd);                      /* close input file */
613          hdflush(NULL);                  /* flush output */
# Line 293 | Line 622 | picheadline(           /* process picture header line */
622   )
623   {
624          char    fmt[32];
625 <        struct phead *ph = vph;
625 >        struct phead *ph = (struct phead *)vph;
626  
627          if (formatval(fmt, s)) {
628                  ph->badfmt = strcmp(fmt, COLRFMT);
# Line 330 | Line 659 | addpicz(               /* add a picture + depth-buffer */
659          double  emult;
660          RESOLU  prs;
661          RREAL   vl[2];
662 <        FVECT   ro, rd;
662 >        RAYPAR  ryp;
663          double  aftd;
664 <        COLOR   ctmp;
665 <        int     j;
337 <        int     i;
338 <                                /* open files */
664 >        int     j, i;
665 >                                /* open picture & get header */
666          if ((pfp = fopen(pcf, "rb")) == NULL) {
667                  sprintf(errmsg, "cannot open picture file \"%s\"", pcf);
668                  error(SYSTEM, pcf);
669          }
343        if ((zfd = open(zbf, O_RDONLY)) < 0) {
344                sprintf(errmsg, "cannot open depth file \"%s\"", zbf);
345                error(SYSTEM, pcf);
346        }
347        SET_FD_BINARY(zfd);
348                                /* load picture header */
670          phd.vw = stdview;
671          phd.expos = 1.0;
672          phd.badfmt = phd.gotview = phd.altprims = 0;
# Line 364 | Line 685 | addpicz(               /* add a picture + depth-buffer */
685                                  pcf);
686                  error(WARNING, errmsg);
687          }
688 +                                /* open depth buffer */
689 +        if ((zfd = open_float_depth(zbf, prs.xr*prs.yr)) < 0)
690 +                quit(1);
691                                  /* figure out what to do about exposure */
692          if ((phd.expos < 0.99) | (phd.expos > 1.01)) {
693                  emult = -log(phd.expos)/log(2.);
# Line 402 | Line 726 | addpicz(               /* add a picture + depth-buffer */
726                          if (zscn[i] <= 0.0)
727                                  continue;               /* illegal depth */
728                          pix2loc(vl, &prs, i, j);
729 <                        aftd = viewray(ro, rd, &phd.vw, vl[0], vl[1]);
729 >                        aftd = viewray(ryp.ro, ryp.rd, &phd.vw, vl[0], vl[1]);
730                          if (aftd < -FTINY)
731                                  continue;               /* off view */
732                          if (aftd > FTINY && zscn[i] > aftd)
733                                  continue;               /* aft clipped */
734 +                        ryp.d = (RREAL)zscn[i];
735 +                        copycolr(ryp.cv, cscn[i]);
736                          if (emult > 0.) {               /* whatta pain */
737 <                                colr_color(ctmp, cscn[i]);
737 >                                COLOR   ctmp;
738 >                                colr_color(ctmp, ryp.cv);
739                                  scalecolor(ctmp, emult);
740 <                                setcolr(cscn[i], colval(ctmp,RED),
740 >                                setcolr(ryp.cv, colval(ctmp,RED),
741                                          colval(ctmp,GRN), colval(ctmp,BLU));
742                          }
743 <                        addray(ro, rd, (double)zscn[i], cscn[i]);
743 >                        addray(&ryp);
744                  }
745          }
746                                  /* write output and free beams */
# Line 428 | Line 755 | addpicz(               /* add a picture + depth-buffer */
755  
756   void
757   eputs(                  /* put error message to stderr */
758 <        char  *s
758 >        const char  *s
759   )
760   {
761          static int  midline = 0;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines