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 2.8 by greg, Thu Sep 24 21:33:52 1992 UTC vs.
Revision 2.15 by greg, Thu Dec 22 19:11:01 1994 UTC

# Line 1 | Line 1
1 < /* Copyright (c) 1991 Regents of the University of California */
1 > /* Copyright (c) 1994 Regents of the University of California */
2  
3   #ifndef lint
4   static char SCCSid[] = "$SunId$ LBL";
# Line 20 | Line 20 | static char SCCSid[] = "$SunId$ LBL";
20  
21   #include "resolu.h"
22  
23 #ifndef BSD
24 #define vfork           fork
25 #endif
26
23   #define pscan(y)        (ourpict+(y)*hresolu)
24   #define zscan(y)        (ourzbuf+(y)*hresolu)
25  
# Line 169 | Line 165 | char   *argv[];
165                                  goto badopt;
166                          check(3,"s");
167                          gotvfile = viewfile(argv[++i], &ourview, 0, 0);
168 <                        if (gotvfile < 0) {
169 <                                perror(argv[i]);
170 <                                exit(1);
175 <                        } else if (gotvfile == 0) {
168 >                        if (gotvfile < 0)
169 >                                syserror(argv[i]);
170 >                        else if (gotvfile == 0) {
171                                  fprintf(stderr, "%s: bad view file\n",
172                                                  argv[i]);
173                                  exit(1);
# Line 191 | Line 186 | char   *argv[];
186          if (fillsamp == 1)
187                  fillo &= ~F_BACK;
188                                                  /* set view */
189 <        if (err = setview(&ourview)) {
189 >        if ((err = setview(&ourview)) != NULL) {
190                  fprintf(stderr, "%s: %s\n", progname, err);
191                  exit(1);
192          }
# Line 200 | Line 195 | char   *argv[];
195          ourpict = (COLR *)bmalloc(hresolu*vresolu*sizeof(COLR));
196          ourzbuf = (float *)bmalloc(hresolu*vresolu*sizeof(float));
197          if (ourpict == NULL || ourzbuf == NULL)
198 <                syserror();
198 >                syserror(progname);
199          bzero((char *)ourzbuf, hresolu*vresolu*sizeof(float));
200 +                                                        /* new header */
201 +        newheader("RADIANCE", stdout);
202                                                          /* get input */
203          for ( ; i < argc; i += 2)
204                  addpicture(argv[i], argv[i+1]);
# Line 212 | Line 209 | char   *argv[];
209                  fillpicture(fillfunc);
210                                                          /* close calculation */
211          caldone();
212 +                                                        /* aft clipping */
213 +        clipaft();
214                                                          /* add to header */
215          printargs(argc, argv, stdout);
216          if (gotvfile) {
# Line 246 | Line 245 | char   *s;
245   {
246          char    fmt[32];
247  
248 <        if (isformat(s)) {
249 <                formatval(fmt, s);
248 >        if (isheadid(s))
249 >                return;
250 >        if (formatval(fmt, s)) {
251                  wrongformat = strcmp(fmt, COLRFMT);
252                  return;
253          }
# Line 274 | Line 274 | char   *pfile, *zspec;
274          struct position *plast;
275          int     y;
276                                          /* open picture file */
277 <        if ((pfp = fopen(pfile, "r")) == NULL) {
278 <                perror(pfile);
279 <                exit(1);
280 <        }
277 >        if ((pfp = fopen(pfile, "r")) == NULL)
278 >                syserror(pfile);
279                                          /* get header with exposure and view */
280          theirexp = 1.0;
281          gotview = 0;
# Line 303 | Line 301 | char   *pfile, *zspec;
301          plast = (struct position *)calloc(scanlen(&tresolu),
302                          sizeof(struct position));
303          if (scanin == NULL || zin == NULL || plast == NULL)
304 <                syserror();
304 >                syserror(progname);
305                                          /* get z specification or file */
306          if ((zfd = open(zspec, O_RDONLY)) == -1) {
307                  double  zvalue;
308                  register int    x;
309 <                if (!isfloat(zspec) || (zvalue = atof(zspec)) <= 0.0) {
310 <                        perror(zspec);
313 <                        exit(1);
314 <                }
309 >                if (!isfloat(zspec) || (zvalue = atof(zspec)) <= 0.0)
310 >                        syserror(zspec);
311                  for (x = scanlen(&tresolu); x-- > 0; )
312                          zin[x] = zvalue;
313          }
# Line 386 | Line 382 | COLR   *pline;
382   float   *zline;
383   struct position *lasty;         /* input/output */
384   {
389        extern double   sqrt();
385          FVECT   pos;
386          struct position lastx, newpos;
387          register int    x;
# Line 475 | Line 470 | double z;
470   movepixel(pos)                          /* reposition image point */
471   FVECT   pos;
472   {
473 +        double  d0, d1;
474          FVECT   pt, direc;
475          
476          if (pos[2] <= 0)                /* empty pixel */
477                  return(-1);
478 +        if (normdist && theirview.type == VT_PER) {     /* adjust distance */
479 +                d0 = pos[0] + theirview.hoff - .5;
480 +                d1 = pos[1] + theirview.voff - .5;
481 +                pos[2] /= sqrt(1. + d0*d0*theirview.hn2 + d1*d1*theirview.vn2);
482 +        }
483          if (hasmatrix) {
484                  pos[0] += theirview.hoff - .5;
485                  pos[1] += theirview.voff - .5;
486                  if (theirview.type == VT_PER) {
486                        if (normdist)   /* adjust for eye-ray distance */
487                                pos[2] /= sqrt( 1.
488                                        + pos[0]*pos[0]*theirview.hn2
489                                        + pos[1]*pos[1]*theirview.vn2 );
487                          pos[0] *= pos[2];
488                          pos[1] *= pos[2];
489                  }
# Line 501 | Line 498 | FVECT  pos;
498                  pos[1] += .5 - ourview.voff;
499                  return(0);
500          }
501 <        if (viewray(pt, direc, &theirview, pos[0], pos[1]) < 0)
501 >        if (viewray(pt, direc, &theirview, pos[0], pos[1]) < -FTINY)
502                  return(-1);
503          pt[0] += direc[0]*pos[2];
504          pt[1] += direc[1]*pos[2];
# Line 523 | Line 520 | int    samp;
520                                                          /* get back buffer */
521          yback = (int *)malloc(hresolu*sizeof(int));
522          if (yback == NULL)
523 <                syserror();
523 >                syserror(progname);
524          for (x = 0; x < hresolu; x++)
525                  yback[x] = -2;
526          /*
# Line 620 | Line 617 | int    (*fill)();
617   }
618  
619  
620 + clipaft()                       /* perform aft clipping as indicated */
621 + {
622 +        register int    x, y;
623 +        double  tstdist;
624 +        double  yzn2, vx;
625 +
626 +        if (ourview.vaft <= FTINY)
627 +                return;
628 +        tstdist = ourview.vaft;
629 +        for (y = 0; y < vresolu; y++) {
630 +                if (ourview.type == VT_PER) {           /* adjust distance */
631 +                        yzn2 = (y+.5)/vresolu + ourview.voff - .5;
632 +                        yzn2 = 1. + yzn2*yzn2*ourview.vn2;
633 +                        tstdist = ourview.vaft * sqrt(yzn2);
634 +                }
635 +                for (x = 0; x < hresolu; x++)
636 +                        if (zscan(y)[x] > tstdist) {
637 +                                if (ourview.type == VT_PER) {
638 +                                        vx = (x+.5)/hresolu + ourview.hoff - .5;
639 +                                        if (zscan(y)[x] <= ourview.vaft *
640 +                                                sqrt(vx*vx*ourview.hn2 + yzn2))
641 +                                                continue;
642 +                                }
643 +                                bzero(pscan(y)[x], sizeof(COLR));
644 +                                zscan(y)[x] = 0.0;
645 +                        }
646 +        }
647 + }
648 +
649 +
650   writepicture()                          /* write out picture */
651   {
652          int     y;
# Line 627 | Line 654 | writepicture()                         /* write out picture */
654          fprtresolu(hresolu, vresolu, stdout);
655          for (y = vresolu-1; y >= 0; y--)
656                  if (fwritecolrs(pscan(y), hresolu, stdout) < 0)
657 <                        syserror();
657 >                        syserror(progname);
658   }
659  
660  
661   writedistance(fname)                    /* write out z file */
662   char    *fname;
663   {
637        extern double   sqrt();
664          int     donorm = normdist && ourview.type == VT_PER;
665          int     fd;
666          int     y;
667          float   *zout;
668  
669 <        if ((fd = open(fname, O_WRONLY|O_CREAT|O_TRUNC, 0666)) == -1) {
670 <                perror(fname);
645 <                exit(1);
646 <        }
669 >        if ((fd = open(fname, O_WRONLY|O_CREAT|O_TRUNC, 0666)) == -1)
670 >                syserror(fname);
671          if (donorm
672          && (zout = (float *)malloc(hresolu*sizeof(float))) == NULL)
673 <                syserror();
673 >                syserror(progname);
674          for (y = vresolu-1; y >= 0; y--) {
675                  if (donorm) {
676                          double  vx, yzn2;
# Line 661 | Line 685 | char   *fname;
685                  } else
686                          zout = zscan(y);
687                  if (write(fd, (char *)zout, hresolu*sizeof(float))
688 <                                < hresolu*sizeof(float)) {
689 <                        perror(fname);
666 <                        exit(1);
667 <                }
688 >                                < hresolu*sizeof(float))
689 >                        syserror(fname);
690          }
691          if (donorm)
692                  free((char *)zout);
# Line 710 | Line 732 | char   *prog, *args;
732          cp = combuf;
733          wp = argv;
734          for ( ; ; ) {
735 <                while (isspace(*cp)) cp++;
736 <                if (!*cp) break;
737 <                *wp++ = cp;
738 <                while (!isspace(*cp))
739 <                        if (!*cp++) goto done;
740 <                *cp++ = '\0';
735 >                while (isspace(*cp))    /* nullify spaces */
736 >                        *cp++ = '\0';
737 >                if (!*cp)               /* all done? */
738 >                        break;
739 >                *wp++ = cp;             /* add argument to list */
740 >                while (*++cp && !isspace(*cp))
741 >                        ;
742          }
720 done:
743          *wp = NULL;
744                                                  /* start process */
745          if ((rval = open_process(PDesc, argv)) < 0)
746 <                syserror();
746 >                syserror(progname);
747          if (rval == 0) {
748                  fprintf(stderr, "%s: command not found\n", argv[0]);
749                  exit(1);
# Line 762 | Line 784 | clearqueue()                           /* process queue */
784          register float  *fbp;
785          register int    i;
786  
787 +        if (queuesiz == 0)
788 +                return;
789          fbp = fbuf;
790          for (i = 0; i < queuesiz; i++) {
791                  viewray(orig, dir, &ourview,
# Line 795 | Line 819 | clearqueue()                           /* process queue */
819   }
820  
821  
822 < syserror()                      /* report error and exit */
822 > syserror(s)                     /* report error and exit */
823 > char    *s;
824   {
825 <        perror(progname);
825 >        perror(s);
826          exit(1);
827   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines