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.18 by greg, Tue Jan 9 11:39:17 1990 UTC vs.
Revision 1.23 by greg, Thu Jan 18 23:58:29 1990 UTC

# Line 10 | Line 10 | static char SCCSid[] = "$SunId$ LBL";
10  
11   #include "standard.h"
12  
13 + #include <sys/fcntl.h>
14 +
15   #include "view.h"
16  
17   #include "color.h"
18  
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  
# Line 147 | Line 153 | char   *argv[];
153                          if (argv[i][2] != 'f')
154                                  goto badopt;
155                          check(3,1);
156 <                        gotvfile = viewfile(argv[++i], &ourview);
156 >                        gotvfile = viewfile(argv[++i], &ourview, 0, 0);
157                          if (gotvfile < 0) {
158                                  perror(argv[i]);
159                                  exit(1);
# Line 241 | 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 279 | Line 286 | char   *pfile, *zspec;
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) {
# Line 295 | Line 302 | char   *pfile, *zspec;
302                          fprintf(stderr, "%s: read error\n", pfile);
303                          exit(1);
304                  }
305 <                if (zfp != NULL
306 <                        && fread(zin,sizeof(float),thresolu,zfp) < thresolu) {
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 307 | 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 359 | Line 366 | struct position        *lasty;         /* input/output */
366          struct position lastx, newpos;
367          register int    x;
368  
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;
# Line 560 | 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          }
# Line 584 | Line 592 | char   *fname;
592                          }
593                  } else
594                          zout = zscan(y);
595 <                if (fwrite(zout, sizeof(float), hresolu, fp) < 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 662 | Line 671 | caldone()                              /* done with calculation */
671  
672          if (childpid == -1)
673                  return;
674 <        if (fclose(psend) == EOF)
666 <                syserror();
667 <        clearqueue();
668 <        fclose(precv);
674 >        clearqueue(1);
675          while ((pid = wait(0)) != -1 && pid != childpid)
676                  ;
677          childpid = -1;
# Line 675 | 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 <
681 <        if (queuesiz >= PACKSIZ) {      /* flush queue */
682 <                if (fflush(psend) == EOF)
683 <                        syserror();
684 <                clearqueue();
685 <        }
686 <                                        /* send new ray */
687 <        viewray(orig, dir, &ourview, (x+.5)/hresolu, (y+.5)/vresolu);
688 <        outbuf[0] = orig[0]; outbuf[1] = orig[1]; outbuf[2] = orig[2];
689 <        outbuf[3] = dir[0]; outbuf[4] = dir[1]; outbuf[5] = dir[2];
690 <        if (fwrite(outbuf, sizeof(float), 6, psend) < 6)
691 <                syserror();
692 <                                        /* 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 <                        inbuf[0] *= ourexp;
718 <                        inbuf[1] *= ourexp;
719 <                        inbuf[2] *= ourexp;
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