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.13 by greg, Thu Jan 4 16:52:05 1990 UTC vs.
Revision 1.14 by greg, Thu Jan 4 17:47:37 1990 UTC

# Line 39 | Line 39 | VIEW   theirview = STDVIEW(512);       /* input view */
39   int     gotview;                        /* got input view? */
40  
41   int     fill = F_FORE|F_BACK;           /* selected fill algorithm */
42 < extern int      backfill(), calfill();  /* fill functions */
42 > extern int      backfill(), rcalfill(); /* fill functions */
43   int     (*deffill)() = backfill;        /* selected fill function */
44   COLR    backcolr = BLKCOLR;             /* background color */
45   double  backz = 0.0;                    /* background z value */
# Line 47 | Line 47 | double backz = 0.0;                    /* background z value */
47   double  theirs2ours[4][4];              /* transformation matrix */
48   int     normdist = 1;                   /* normalized distance? */
49  
50 + int     childpid = -1;                  /* id of fill process */
51   FILE    *psend, *precv;                 /* pipes to/from fill calculation */
51 int     childpid;                       /* child's process id */
52   int     queue[PACKSIZ][2];              /* pending pixels */
53   int     queuesiz;                       /* number of pixels pending */
54  
# Line 108 | Line 108 | char   *argv[];
108                                  break;
109                          case 'r':                               /* rtrace */
110                                  check(3,1);
111 <                                deffill = calfill;
111 >                                deffill = rcalfill;
112                                  calstart(RTCOM, argv[++i]);
113                                  break;
114                          default:
# Line 205 | Line 205 | char   *argv[];
205          else
206                  fillpicture();
207                                                          /* close calculation */
208 <        if (deffill == calfill)
209 <                caldone();
208 >        caldone();
209                                                          /* add to header */
210          printargs(argc, argv, stdout);
211          if (gotvfile) {
# Line 620 | Line 619 | char   *prog, *args;
619          char    combuf[512];
620          int     p0[2], p1[2];
621  
622 +        if (childpid != -1) {
623 +                fprintf(stderr, "%s: too many calculations\n", progname);
624 +                exit(1);
625 +        }
626          sprintf(combuf, prog, PACKSIZ, args);
627          if (pipe(p0) < 0 || pipe(p1) < 0)
628 <                goto syserr;
628 >                syserror();
629          if ((childpid = vfork()) == 0) {        /* fork calculation */
630                  close(p0[1]);
631                  close(p1[0]);
# Line 638 | Line 641 | char   *prog, *args;
641                  perror("/bin/sh");
642                  _exit(127);
643          }
644 <        if (childpid < 0)
645 <                goto syserr;
644 >        if (childpid == -1)
645 >                syserror();
646          close(p0[0]);
647          close(p1[1]);
648          if ((psend = fdopen(p0[1], "w")) == NULL)
649 <                goto syserr;
649 >                syserror();
650          if ((precv = fdopen(p1[0], "r")) == NULL)
651 <                goto syserr;
651 >                syserror();
652          queuesiz = 0;
650        return;
651 syserr:
652        perror(progname);
653        exit(1);
653   }
654  
655  
# Line 658 | Line 657 | caldone()                              /* done with calculation */
657   {
658          int     pid;
659  
660 <        fclose(psend);
660 >        if (childpid == -1)
661 >                return;
662 >        if (fclose(psend) == EOF)
663 >                syserror();
664          clearqueue();
665          fclose(precv);
666          while ((pid = wait(0)) != -1 && pid != childpid)
667                  ;
668 +        childpid = -1;
669   }
670  
671  
672 < calfill(x, y)                           /* fill with calculated pixel */
672 > rcalfill(x, y)                          /* fill with ray-calculated pixel */
673   int     x, y;
674   {
675          FVECT   orig, dir;
676          float   outbuf[6];
677  
678          if (queuesiz >= PACKSIZ) {      /* flush queue */
679 <                fflush(psend);
679 >                if (fflush(psend) == EOF)
680 >                        syserror();
681                  clearqueue();
682          }
683                                          /* send new ray */
684          rayview(orig, dir, &ourview, x+.5, y+.5);
685          outbuf[0] = orig[0]; outbuf[1] = orig[1]; outbuf[2] = orig[2];
686          outbuf[3] = dir[0]; outbuf[4] = dir[1]; outbuf[5] = dir[2];
687 <        fwrite(outbuf, sizeof(float), 6, psend);
687 >        if (fwrite(outbuf, sizeof(float), 6, psend) < 6)
688 >                syserror();
689                                          /* remember it */
690          queue[queuesiz][0] = x;
691          queue[queuesiz][1] = y;
# Line 694 | Line 699 | clearqueue()                           /* get results from queue */
699          register int    i;
700  
701          for (i = 0; i < queuesiz; i++) {
702 <                fread(inbuf, sizeof(float), 4, precv);
702 >                if (fread(inbuf, sizeof(float), 4, precv) < 4) {
703 >                        fprintf(stderr, "%s: read error in clearqueue\n",
704 >                                        progname);
705 >                        exit(1);
706 >                }
707                  setcolr(pscan(queue[i][1])[queue[i][0]],
708                                  inbuf[0], inbuf[1], inbuf[2]);
709                  zscan(queue[i][1])[queue[i][0]] = inbuf[3];
710          }
711          queuesiz = 0;
712 + }
713 +
714 +
715 + syserror()                      /* report error and exit */
716 + {
717 +        perror(progname);
718 +        exit(1);
719   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines