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

Comparing ray/src/px/pinterp.c (file contents):
Revision 1.15 by greg, Fri Jan 5 11:34:27 1990 UTC vs.
Revision 1.24 by greg, Mon Feb 26 14:01:44 1990 UTC

# Line 10 | Line 10 | static char SCCSid[] = "$SunId$ LBL";
10  
11   #include "standard.h"
12  
13 + #include <fcntl.h>
14 +
15   #include "view.h"
16  
17   #include "color.h"
18  
19 < #define pscan(y)        (ourpict+(y)*ourview.hresolu)
20 < #define zscan(y)        (ourzbuf+(y)*ourview.hresolu)
19 > #ifndef BSD
20 > #define vfork           fork
21 > #endif
22  
23 + #define pscan(y)        (ourpict+(y)*hresolu)
24 + #define zscan(y)        (ourzbuf+(y)*hresolu)
25 +
26   #define F_FORE          1               /* fill foreground */
27   #define F_BACK          2               /* fill background */
28  
# Line 28 | Line 34 | static char SCCSid[] = "$SunId$ LBL";
34  
35   struct position {int x,y; float z;};
36  
37 < VIEW    ourview = STDVIEW(512);         /* desired view */
37 > VIEW    ourview = STDVIEW;              /* desired view */
38 > int     hresolu = 512;                  /* horizontal resolution */
39 > int     vresolu = 512;                  /* vertical resolution */
40 > double  pixaspect = 1.0;                /* pixel aspect ratio */
41  
42   double  zeps = .02;                     /* allowed z epsilon */
43  
# Line 37 | Line 46 | float  *ourzbuf;                       /* corresponding z-buffer */
46  
47   char    *progname;
48  
40 VIEW    theirview = STDVIEW(512);       /* input view */
41 int     gotview;                        /* got input view? */
42
49   int     fill = F_FORE|F_BACK;           /* selected fill algorithm */
50   extern int      backfill(), rcalfill(); /* fill functions */
51   int     (*deffill)() = backfill;        /* selected fill function */
52   COLR    backcolr = BLKCOLR;             /* background color */
53   double  backz = 0.0;                    /* background z value */
54 + int     normdist = 1;                   /* normalized distance? */
55 + double  ourexp = -1;                    /* output picture exposure */
56  
57 + VIEW    theirview = STDVIEW;            /* input view */
58 + int     gotview;                        /* got input view? */
59 + int     thresolu, tvresolu;             /* input resolution */
60 + double  theirexp;                       /* input picture exposure */
61   double  theirs2ours[4][4];              /* transformation matrix */
50 int     normdist = 1;                   /* normalized distance? */
62  
63   int     childpid = -1;                  /* id of fill process */
64   FILE    *psend, *precv;                 /* pipes to/from fill calculation */
# Line 64 | Line 75 | char   *argv[];
75          int     gotvfile = 0;
76          char    *zfile = NULL;
77          char    *err;
78 <        int     i;
78 >        int     i, rval;
79  
80          progname = argv[0];
81  
82 <        for (i = 1; i < argc && argv[i][0] == '-'; i++)
82 >        for (i = 1; i < argc && argv[i][0] == '-'; i++) {
83 >                rval = getviewopt(&ourview, argc-i, argv+i);
84 >                if (rval >= 0) {
85 >                        i += rval;
86 >                        continue;
87 >                }
88                  switch (argv[i][1]) {
89                  case 't':                               /* threshold */
90                          check(2,1);
# Line 123 | Line 139 | char   *argv[];
139                          break;
140                  case 'x':                               /* x resolution */
141                          check(2,1);
142 <                        ourview.hresolu = atoi(argv[++i]);
142 >                        hresolu = atoi(argv[++i]);
143                          break;
144                  case 'y':                               /* y resolution */
145                          check(2,1);
146 <                        ourview.vresolu = atoi(argv[++i]);
146 >                        vresolu = atoi(argv[++i]);
147                          break;
148 <                case 'v':                               /* view */
149 <                        switch (argv[i][2]) {
150 <                        case 't':                               /* type */
151 <                                check(4,0);
152 <                                ourview.type = argv[i][3];
153 <                                break;
138 <                        case 'p':                               /* point */
139 <                                check(3,3);
140 <                                ourview.vp[0] = atof(argv[++i]);
141 <                                ourview.vp[1] = atof(argv[++i]);
142 <                                ourview.vp[2] = atof(argv[++i]);
143 <                                break;
144 <                        case 'd':                               /* direction */
145 <                                check(3,3);
146 <                                ourview.vdir[0] = atof(argv[++i]);
147 <                                ourview.vdir[1] = atof(argv[++i]);
148 <                                ourview.vdir[2] = atof(argv[++i]);
149 <                                break;
150 <                        case 'u':                               /* up */
151 <                                check(3,3);
152 <                                ourview.vup[0] = atof(argv[++i]);
153 <                                ourview.vup[1] = atof(argv[++i]);
154 <                                ourview.vup[2] = atof(argv[++i]);
155 <                                break;
156 <                        case 'h':                               /* horizontal */
157 <                                check(3,1);
158 <                                ourview.horiz = atof(argv[++i]);
159 <                                break;
160 <                        case 'v':                               /* vertical */
161 <                                check(3,1);
162 <                                ourview.vert = atof(argv[++i]);
163 <                                break;
164 <                        case 'f':                               /* file */
165 <                                check(3,1);
166 <                                gotvfile = viewfile(argv[++i], &ourview);
167 <                                if (gotvfile < 0) {
168 <                                        perror(argv[i]);
169 <                                        exit(1);
170 <                                } else if (gotvfile == 0) {
171 <                                        fprintf(stderr, "%s: bad view file\n",
172 <                                                        argv[i]);
173 <                                        exit(1);
174 <                                }
175 <                                break;
176 <                        default:
148 >                case 'p':                               /* pixel aspect */
149 >                        check(2,1);
150 >                        pixaspect = atof(argv[++i]);
151 >                        break;
152 >                case 'v':                               /* view file */
153 >                        if (argv[i][2] != 'f')
154                                  goto badopt;
155 +                        check(3,1);
156 +                        gotvfile = viewfile(argv[++i], &ourview, 0, 0);
157 +                        if (gotvfile < 0) {
158 +                                perror(argv[i]);
159 +                                exit(1);
160 +                        } else if (gotvfile == 0) {
161 +                                fprintf(stderr, "%s: bad view file\n",
162 +                                                argv[i]);
163 +                                exit(1);
164                          }
165                          break;
166                  default:
# Line 183 | Line 169 | char   *argv[];
169                                          progname, argv[i]);
170                          goto userr;
171                  }
172 +        }
173                                                  /* check arguments */
174          if ((argc-i)%2)
175                  goto userr;
# Line 191 | Line 178 | char   *argv[];
178                  fprintf(stderr, "%s: %s\n", progname, err);
179                  exit(1);
180          }
181 +        normaspect(viewaspect(&ourview), &pixaspect, &hresolu, &vresolu);
182                                                  /* allocate frame */
183 <        ourpict = (COLR *)malloc(ourview.hresolu*ourview.vresolu*sizeof(COLR));
184 <        ourzbuf = (float *)calloc(ourview.hresolu*ourview.vresolu,sizeof(float));
183 >        ourpict = (COLR *)malloc(hresolu*vresolu*sizeof(COLR));
184 >        ourzbuf = (float *)calloc(hresolu*vresolu,sizeof(float));
185          if (ourpict == NULL || ourzbuf == NULL)
186                  syserror();
187                                                          /* get input */
# Line 213 | Line 201 | char   *argv[];
201                  fprintview(&ourview, stdout);
202                  printf("\n");
203          }
204 +        if (pixaspect < .99 || pixaspect > 1.01)
205 +                fputaspect(pixaspect, stdout);
206 +        if (ourexp > 0 && (ourexp < .995 || ourexp > 1.005))
207 +                fputexpos(ourexp, stdout);
208          printf("\n");
209                                                          /* write picture */
210          writepicture();
# Line 223 | Line 215 | char   *argv[];
215          exit(0);
216   userr:
217          fprintf(stderr,
218 <        "Usage: %s [view opts][-t zthresh][-z zout][-fT][-n] pfile zspec ..\n",
218 >        "Usage: %s [view opts][-t eps][-z zout][-fT][-n] pfile zspec ..\n",
219                          progname);
220          exit(1);
221   #undef check
# Line 238 | Line 230 | char   *s;
230  
231          printf("\t%s", s);
232  
233 +        if (isexpos(s)) {
234 +                theirexp *= exposval(s);
235 +                return;
236 +        }
237          for (an = altname; *an != NULL; an++)
238                  if (!strncmp(*an, s, strlen(*an))) {
239 <                        if (sscanview(&theirview, s+strlen(*an)) == 0)
239 >                        if (sscanview(&theirview, s+strlen(*an)) > 0)
240                                  gotview++;
241                          break;
242                  }
# Line 251 | Line 247 | addpicture(pfile, zspec)               /* add picture to output */
247   char    *pfile, *zspec;
248   {
249          extern double   atof();
250 <        FILE    *pfp, *zfp;
250 >        FILE    *pfp;
251 >        int     zfd;
252          char    *err;
253          COLR    *scanin;
254          float   *zin;
# Line 262 | Line 259 | char   *pfile, *zspec;
259                  perror(pfile);
260                  exit(1);
261          }
262 <                                        /* get header and view */
263 <        printf("%s:\n", pfile);
262 >                                        /* get header with exposure and view */
263 >        theirexp = 1.0;
264          gotview = 0;
265 +        printf("%s:\n", pfile);
266          getheader(pfp, headline);
267 <        if (!gotview || fgetresolu(&theirview.hresolu, &theirview.vresolu, pfp)
267 >        if (!gotview || fgetresolu(&thresolu, &tvresolu, pfp)
268                          != (YMAJOR|YDECR)) {
269                  fprintf(stderr, "%s: picture view error\n", pfile);
270                  exit(1);
271          }
272 +        if (ourexp <= 0)
273 +                ourexp = theirexp;
274 +        else if (ABS(theirexp-ourexp) > .01*ourexp)
275 +                fprintf(stderr, "%s: different exposure (warning)\n", pfile);
276          if (err = setview(&theirview)) {
277                  fprintf(stderr, "%s: %s\n", pfile, err);
278                  exit(1);
# Line 278 | Line 280 | char   *pfile, *zspec;
280                                          /* compute transformation */
281          pixform(theirs2ours, &theirview, &ourview);
282                                          /* allocate scanlines */
283 <        scanin = (COLR *)malloc(theirview.hresolu*sizeof(COLR));
284 <        zin = (float *)malloc(theirview.hresolu*sizeof(float));
285 <        plast = (struct position *)calloc(theirview.hresolu,
284 <                                                sizeof(struct position));
283 >        scanin = (COLR *)malloc(thresolu*sizeof(COLR));
284 >        zin = (float *)malloc(thresolu*sizeof(float));
285 >        plast = (struct position *)calloc(thresolu, sizeof(struct position));
286          if (scanin == NULL || zin == NULL || plast == NULL)
287                  syserror();
288                                          /* get z specification or file */
289 <        if ((zfp = fopen(zspec, "r")) == NULL) {
289 >        if ((zfd = open(zspec, O_RDONLY)) == -1) {
290                  double  zvalue;
291                  register int    x;
292                  if (!isfloat(zspec) || (zvalue = atof(zspec)) <= 0.0) {
293                          perror(zspec);
294                          exit(1);
295                  }
296 <                for (x = 0; x < theirview.hresolu; x++)
296 >                for (x = 0; x < thresolu; x++)
297                          zin[x] = zvalue;
298          }
299                                          /* load image */
300 <        for (y = theirview.vresolu-1; y >= 0; y--) {
301 <                if (freadcolrs(scanin, theirview.hresolu, pfp) < 0) {
300 >        for (y = tvresolu-1; y >= 0; y--) {
301 >                if (freadcolrs(scanin, thresolu, pfp) < 0) {
302                          fprintf(stderr, "%s: read error\n", pfile);
303                          exit(1);
304                  }
305 <                if (zfp != NULL
306 <                        && fread(zin,sizeof(float),theirview.hresolu,zfp)
306 <                                < theirview.hresolu) {
305 >                if (zfd != -1 && read(zfd,(char *)zin,thresolu*sizeof(float))
306 >                                < thresolu*sizeof(float)) {
307                          fprintf(stderr, "%s: read error\n", zspec);
308                          exit(1);
309                  }
# Line 314 | Line 314 | char   *pfile, *zspec;
314          free((char *)zin);
315          free((char *)plast);
316          fclose(pfp);
317 <        if (zfp != NULL)
318 <                fclose(zfp);
317 >        if (zfd != -1)
318 >                close(zfd);
319   }
320  
321  
# Line 326 | Line 326 | register VIEW  *vw1, *vw2;
326          double  m4t[4][4];
327  
328          setident4(xfmat);
329 <        xfmat[0][0] = vw1->vhinc[0];
330 <        xfmat[0][1] = vw1->vhinc[1];
331 <        xfmat[0][2] = vw1->vhinc[2];
332 <        xfmat[1][0] = vw1->vvinc[0];
333 <        xfmat[1][1] = vw1->vvinc[1];
334 <        xfmat[1][2] = vw1->vvinc[2];
329 >        xfmat[0][0] = vw1->hvec[0];
330 >        xfmat[0][1] = vw1->hvec[1];
331 >        xfmat[0][2] = vw1->hvec[2];
332 >        xfmat[1][0] = vw1->vvec[0];
333 >        xfmat[1][1] = vw1->vvec[1];
334 >        xfmat[1][2] = vw1->vvec[2];
335          xfmat[2][0] = vw1->vdir[0];
336          xfmat[2][1] = vw1->vdir[1];
337          xfmat[2][2] = vw1->vdir[2];
# Line 339 | Line 339 | register VIEW  *vw1, *vw2;
339          xfmat[3][1] = vw1->vp[1];
340          xfmat[3][2] = vw1->vp[2];
341          setident4(m4t);
342 <        m4t[0][0] = vw2->vhinc[0]/vw2->vhn2;
343 <        m4t[1][0] = vw2->vhinc[1]/vw2->vhn2;
344 <        m4t[2][0] = vw2->vhinc[2]/vw2->vhn2;
345 <        m4t[3][0] = -DOT(vw2->vp,vw2->vhinc)/vw2->vhn2;
346 <        m4t[0][1] = vw2->vvinc[0]/vw2->vvn2;
347 <        m4t[1][1] = vw2->vvinc[1]/vw2->vvn2;
348 <        m4t[2][1] = vw2->vvinc[2]/vw2->vvn2;
349 <        m4t[3][1] = -DOT(vw2->vp,vw2->vvinc)/vw2->vvn2;
342 >        m4t[0][0] = vw2->hvec[0]/vw2->hn2;
343 >        m4t[1][0] = vw2->hvec[1]/vw2->hn2;
344 >        m4t[2][0] = vw2->hvec[2]/vw2->hn2;
345 >        m4t[3][0] = -DOT(vw2->vp,vw2->hvec)/vw2->hn2;
346 >        m4t[0][1] = vw2->vvec[0]/vw2->vn2;
347 >        m4t[1][1] = vw2->vvec[1]/vw2->vn2;
348 >        m4t[2][1] = vw2->vvec[2]/vw2->vn2;
349 >        m4t[3][1] = -DOT(vw2->vp,vw2->vvec)/vw2->vn2;
350          m4t[0][2] = vw2->vdir[0];
351          m4t[1][2] = vw2->vdir[1];
352          m4t[2][2] = vw2->vdir[2];
# Line 366 | Line 366 | struct position        *lasty;         /* input/output */
366          struct position lastx, newpos;
367          register int    x;
368  
369 <        for (x = theirview.hresolu-1; x >= 0; x--) {
370 <                pos[0] = x - .5*(theirview.hresolu-1);
371 <                pos[1] = y - .5*(theirview.vresolu-1);
369 >        lastx.z = 0;
370 >        for (x = thresolu-1; x >= 0; x--) {
371 >                pos[0] = (x+.5)/thresolu + theirview.hoff - .5;
372 >                pos[1] = (y+.5)/tvresolu + theirview.voff - .5;
373                  pos[2] = zline[x];
374                  if (theirview.type == VT_PER) {
375                          if (normdist)   /* adjust for eye-ray distance */
376                                  pos[2] /= sqrt( 1.
377 <                                        + pos[0]*pos[0]*theirview.vhn2
378 <                                        + pos[1]*pos[1]*theirview.vvn2 );
377 >                                        + pos[0]*pos[0]*theirview.hn2
378 >                                        + pos[1]*pos[1]*theirview.vn2 );
379                          pos[0] *= pos[2];
380                          pos[1] *= pos[2];
381                  }
# Line 387 | Line 388 | struct position        *lasty;         /* input/output */
388                          pos[0] /= pos[2];
389                          pos[1] /= pos[2];
390                  }
391 <                pos[0] += .5*ourview.hresolu;
392 <                pos[1] += .5*ourview.vresolu;
393 <                newpos.x = pos[0];
394 <                newpos.y = pos[1];
391 >                pos[0] += .5 - ourview.hoff;
392 >                pos[1] += .5 - ourview.voff;
393 >                newpos.x = pos[0] * hresolu;
394 >                newpos.y = pos[1] * vresolu;
395                  newpos.z = zline[x];
396                                          /* add pixel to our image */
397 <                if (pos[0] >= 0 && newpos.x < ourview.hresolu
398 <                                && pos[1] >= 0 && newpos.y < ourview.vresolu) {
397 >                if (pos[0] >= 0 && newpos.x < hresolu
398 >                                && pos[1] >= 0 && newpos.y < vresolu) {
399                          addpixel(&newpos, &lastx, &lasty[x], pline[x], pos[2]);
400                          lasty[x].x = lastx.x = newpos.x;
401                          lasty[x].y = lastx.y = newpos.y;
# Line 465 | Line 466 | backpicture()                          /* background fill algorithm */
466          COLR    pfill;
467          register int    x, i;
468                                                          /* get back buffer */
469 <        yback = (int *)malloc(ourview.hresolu*sizeof(int));
469 >        yback = (int *)malloc(hresolu*sizeof(int));
470          if (yback == NULL)
471                  syserror();
472 <        for (x = 0; x < ourview.hresolu; x++)
472 >        for (x = 0; x < hresolu; x++)
473                  yback[x] = -2;
474          /*
475           * Xback and yback are the pixel locations of suitable
# Line 477 | Line 478 | backpicture()                          /* background fill algorithm */
478           * that there is no suitable background in this direction.
479           */
480                                                          /* fill image */
481 <        for (y = 0; y < ourview.vresolu; y++) {
481 >        for (y = 0; y < vresolu; y++) {
482                  xback = -2;
483 <                for (x = 0; x < ourview.hresolu; x++)
483 >                for (x = 0; x < hresolu; x++)
484                          if (zscan(y)[x] <= 0) {         /* empty pixel */
485                                  /*
486                                   * First, find background from above or below.
487                                   * (farthest assigned pixel)
488                                   */
489                                  if (yback[x] == -2) {
490 <                                        for (i = y+1; i < ourview.vresolu; i++)
490 >                                        for (i = y+1; i < vresolu; i++)
491                                                  if (zscan(i)[x] > 0)
492                                                          break;
493 <                                        if (i < ourview.vresolu
493 >                                        if (i < vresolu
494                                  && (y <= 0 || zscan(y-1)[x] < zscan(i)[x]))
495                                                  yback[x] = i;
496                                          else
# Line 499 | Line 500 | backpicture()                          /* background fill algorithm */
500                                   * Next, find background from left or right.
501                                   */
502                                  if (xback == -2) {
503 <                                        for (i = x+1; i < ourview.hresolu; i++)
503 >                                        for (i = x+1; i < hresolu; i++)
504                                                  if (zscan(y)[i] > 0)
505                                                          break;
506 <                                        if (i < ourview.hresolu
506 >                                        if (i < hresolu
507                                  && (x <= 0 || zscan(y)[x-1] < zscan(y)[i]))
508                                                  xback = i;
509                                          else
# Line 544 | Line 545 | fillpicture()                          /* paint in empty pixels with default
545   {
546          register int    x, y;
547  
548 <        for (y = 0; y < ourview.vresolu; y++)
549 <                for (x = 0; x < ourview.hresolu; x++)
548 >        for (y = 0; y < vresolu; y++)
549 >                for (x = 0; x < hresolu; x++)
550                          if (zscan(y)[x] <= 0)
551                                  (*deffill)(x,y);
552   }
# Line 555 | Line 556 | writepicture()                         /* write out picture */
556   {
557          int     y;
558  
559 <        fputresolu(YMAJOR|YDECR, ourview.hresolu, ourview.vresolu, stdout);
560 <        for (y = ourview.vresolu-1; y >= 0; y--)
561 <                if (fwritecolrs(pscan(y), ourview.hresolu, stdout) < 0)
559 >        fputresolu(YMAJOR|YDECR, hresolu, vresolu, stdout);
560 >        for (y = vresolu-1; y >= 0; y--)
561 >                if (fwritecolrs(pscan(y), hresolu, stdout) < 0)
562                          syserror();
563   }
564  
# Line 567 | Line 568 | char   *fname;
568   {
569          extern double   sqrt();
570          int     donorm = normdist && ourview.type == VT_PER;
571 <        FILE    *fp;
571 >        int     fd;
572          int     y;
573          float   *zout;
574  
575 <        if ((fp = fopen(fname, "w")) == NULL) {
575 >        if ((fd = open(fname, O_WRONLY|O_CREAT|O_TRUNC, 0666)) == -1) {
576                  perror(fname);
577                  exit(1);
578          }
579          if (donorm
580 <        && (zout = (float *)malloc(ourview.hresolu*sizeof(float))) == NULL)
580 >        && (zout = (float *)malloc(hresolu*sizeof(float))) == NULL)
581                  syserror();
582 <        for (y = ourview.vresolu-1; y >= 0; y--) {
582 >        for (y = vresolu-1; y >= 0; y--) {
583                  if (donorm) {
584                          double  vx, yzn2;
585                          register int    x;
586 <                        yzn2 = y - .5*(ourview.vresolu-1);
587 <                        yzn2 = 1. + yzn2*yzn2*ourview.vvn2;
588 <                        for (x = 0; x < ourview.hresolu; x++) {
589 <                                vx = x - .5*(ourview.hresolu-1);
586 >                        yzn2 = y - .5*(vresolu-1);
587 >                        yzn2 = 1. + yzn2*yzn2*ourview.vn2;
588 >                        for (x = 0; x < hresolu; x++) {
589 >                                vx = x - .5*(hresolu-1);
590                                  zout[x] = zscan(y)[x]
591 <                                        * sqrt(vx*vx*ourview.vhn2 + yzn2);
591 >                                        * sqrt(vx*vx*ourview.hn2 + yzn2);
592                          }
593                  } else
594                          zout = zscan(y);
595 <                if (fwrite(zout, sizeof(float), ourview.hresolu, fp)
596 <                                < ourview.hresolu) {
595 >                if (write(fd, (char *)zout, hresolu*sizeof(float))
596 >                                < hresolu*sizeof(float)) {
597                          perror(fname);
598                          exit(1);
599                  }
600          }
601          if (donorm)
602                  free((char *)zout);
603 <        fclose(fp);
603 >        close(fd);
604   }
605  
606  
# Line 670 | Line 671 | caldone()                              /* done with calculation */
671  
672          if (childpid == -1)
673                  return;
674 <        if (fclose(psend) == EOF)
674 <                syserror();
675 <        clearqueue();
676 <        fclose(precv);
674 >        clearqueue(1);
675          while ((pid = wait(0)) != -1 && pid != childpid)
676                  ;
677          childpid = -1;
# Line 683 | Line 681 | caldone()                              /* done with calculation */
681   rcalfill(x, y)                          /* fill with ray-calculated pixel */
682   int     x, y;
683   {
684 <        FVECT   orig, dir;
685 <        float   outbuf[6];
686 <
689 <        if (queuesiz >= PACKSIZ) {      /* flush queue */
690 <                if (fflush(psend) == EOF)
691 <                        syserror();
692 <                clearqueue();
693 <        }
694 <                                        /* send new ray */
695 <        rayview(orig, dir, &ourview, x+.5, y+.5);
696 <        outbuf[0] = orig[0]; outbuf[1] = orig[1]; outbuf[2] = orig[2];
697 <        outbuf[3] = dir[0]; outbuf[4] = dir[1]; outbuf[5] = dir[2];
698 <        if (fwrite(outbuf, sizeof(float), 6, psend) < 6)
699 <                syserror();
700 <                                        /* remember it */
684 >        if (queuesiz >= PACKSIZ)        /* flush queue if needed */
685 >                clearqueue(0);
686 >                                        /* add position to queue */
687          queue[queuesiz][0] = x;
688          queue[queuesiz][1] = y;
689          queuesiz++;
690   }
691  
692  
693 < clearqueue()                            /* get results from queue */
693 > clearqueue(done)                        /* process queue */
694 > int     done;
695   {
696 <        float   inbuf[4];
696 >        FVECT   orig, dir;
697 >        float   fbuf[6];
698          register int    i;
699  
700          for (i = 0; i < queuesiz; i++) {
701 <                if (fread(inbuf, sizeof(float), 4, precv) < 4) {
701 >                viewray(orig, dir, &ourview,
702 >                                (queue[i][0]+.5)/hresolu,
703 >                                (queue[i][1]+.5)/vresolu);
704 >                fbuf[0] = orig[0]; fbuf[1] = orig[1]; fbuf[2] = orig[2];
705 >                fbuf[3] = dir[0]; fbuf[4] = dir[1]; fbuf[5] = dir[2];
706 >                fwrite((char *)fbuf, sizeof(float), 6, psend);
707 >        }
708 >        if ((done ? fclose(psend) : fflush(psend)) == EOF)
709 >                syserror();
710 >        for (i = 0; i < queuesiz; i++) {
711 >                if (fread((char *)fbuf, sizeof(float), 4, precv) < 4) {
712                          fprintf(stderr, "%s: read error in clearqueue\n",
713                                          progname);
714                          exit(1);
715                  }
716 +                if (ourexp > 0 && ourexp != 1.0) {
717 +                        fbuf[0] *= ourexp;
718 +                        fbuf[1] *= ourexp;
719 +                        fbuf[2] *= ourexp;
720 +                }
721                  setcolr(pscan(queue[i][1])[queue[i][0]],
722 <                                inbuf[0], inbuf[1], inbuf[2]);
723 <                zscan(queue[i][1])[queue[i][0]] = inbuf[3];
722 >                                fbuf[0], fbuf[1], fbuf[2]);
723 >                zscan(queue[i][1])[queue[i][0]] = fbuf[3];
724          }
725 +        if (done)
726 +                fclose(precv);
727          queuesiz = 0;
728   }
729  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines