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.4 by greg, Thu Mar 26 13:03:34 1992 UTC vs.
Revision 2.14 by greg, Wed Dec 21 16:59:03 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 12 | Line 12 | static char SCCSid[] = "$SunId$ LBL";
12  
13   #include "standard.h"
14  
15 #include <fcntl.h>
16
15   #include <ctype.h>
16  
17   #include "view.h"
# Line 22 | Line 20 | static char SCCSid[] = "$SunId$ LBL";
20  
21   #include "resolu.h"
22  
25 #ifndef BSD
26 #define vfork           fork
27 #endif
28
23   #define pscan(y)        (ourpict+(y)*hresolu)
24   #define zscan(y)        (ourzbuf+(y)*hresolu)
25  
# Line 161 | Line 155 | char   *argv[];
155                          vresolu = atoi(argv[++i]);
156                          break;
157                  case 'p':                               /* pixel aspect */
158 <                        check(2,"f");
158 >                        if (argv[i][2] != 'a')
159 >                                goto badopt;
160 >                        check(3,"f");
161                          pixaspect = atof(argv[++i]);
162                          break;
163                  case 'v':                               /* view file */
# 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 (ourview.vaft > FTINY)
190 >                err = "no aft clipping plane allowed";
191 >        else
192 >                err = setview(&ourview);
193 >        if (err != NULL) {
194                  fprintf(stderr, "%s: %s\n", progname, err);
195                  exit(1);
196          }
197          normaspect(viewaspect(&ourview), &pixaspect, &hresolu, &vresolu);
198                                                  /* allocate frame */
199 <        ourpict = (COLR *)malloc(hresolu*vresolu*sizeof(COLR));
200 <        ourzbuf = (float *)calloc(hresolu*vresolu,sizeof(float));
199 >        ourpict = (COLR *)bmalloc(hresolu*vresolu*sizeof(COLR));
200 >        ourzbuf = (float *)bmalloc(hresolu*vresolu*sizeof(float));
201          if (ourpict == NULL || ourzbuf == NULL)
202 <                syserror();
202 >                syserror(progname);
203 >        bzero((char *)ourzbuf, hresolu*vresolu*sizeof(float));
204 >                                                        /* new header */
205 >        newheader("RADIANCE", stdout);
206                                                          /* get input */
207          for ( ; i < argc; i += 2)
208                  addpicture(argv[i], argv[i+1]);
# Line 243 | Line 245 | userr:
245   headline(s)                             /* process header string */
246   char    *s;
247   {
246        static char     *altname[] = {VIEWSTR,"rpict","rview","pinterp",NULL};
247        register char   **an;
248          char    fmt[32];
249  
250 <        if (isformat(s)) {
251 <                formatval(fmt, s);
250 >        if (isheadid(s))
251 >                return;
252 >        if (formatval(fmt, s)) {
253                  wrongformat = strcmp(fmt, COLRFMT);
254                  return;
255          }
# Line 259 | Line 260 | char   *s;
260                  theirexp *= exposval(s);
261                  return;
262          }
263 <        for (an = altname; *an != NULL; an++)
264 <                if (!strncmp(*an, s, strlen(*an))) {
264 <                        if (sscanview(&theirview, s+strlen(*an)) > 0)
265 <                                gotview++;
266 <                        break;
267 <                }
263 >        if (isview(s) && sscanview(&theirview, s) > 0)
264 >                gotview++;
265   }
266  
267  
# Line 279 | Line 276 | char   *pfile, *zspec;
276          struct position *plast;
277          int     y;
278                                          /* open picture file */
279 <        if ((pfp = fopen(pfile, "r")) == NULL) {
280 <                perror(pfile);
284 <                exit(1);
285 <        }
279 >        if ((pfp = fopen(pfile, "r")) == NULL)
280 >                syserror(pfile);
281                                          /* get header with exposure and view */
282          theirexp = 1.0;
283          gotview = 0;
# Line 308 | Line 303 | char   *pfile, *zspec;
303          plast = (struct position *)calloc(scanlen(&tresolu),
304                          sizeof(struct position));
305          if (scanin == NULL || zin == NULL || plast == NULL)
306 <                syserror();
306 >                syserror(progname);
307                                          /* get z specification or file */
308          if ((zfd = open(zspec, O_RDONLY)) == -1) {
309                  double  zvalue;
310                  register int    x;
311 <                if (!isfloat(zspec) || (zvalue = atof(zspec)) <= 0.0) {
312 <                        perror(zspec);
318 <                        exit(1);
319 <                }
311 >                if (!isfloat(zspec) || (zvalue = atof(zspec)) <= 0.0)
312 >                        syserror(zspec);
313                  for (x = scanlen(&tresolu); x-- > 0; )
314                          zin[x] = zvalue;
315          }
# Line 391 | Line 384 | COLR   *pline;
384   float   *zline;
385   struct position *lasty;         /* input/output */
386   {
394        extern double   sqrt();
387          FVECT   pos;
388          struct position lastx, newpos;
389          register int    x;
# Line 506 | 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 528 | 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 632 | Line 624 | writepicture()                         /* write out picture */
624          fprtresolu(hresolu, vresolu, stdout);
625          for (y = vresolu-1; y >= 0; y--)
626                  if (fwritecolrs(pscan(y), hresolu, stdout) < 0)
627 <                        syserror();
627 >                        syserror(progname);
628   }
629  
630  
631   writedistance(fname)                    /* write out z file */
632   char    *fname;
633   {
642        extern double   sqrt();
634          int     donorm = normdist && ourview.type == VT_PER;
635          int     fd;
636          int     y;
637          float   *zout;
638  
639 <        if ((fd = open(fname, O_WRONLY|O_CREAT|O_TRUNC, 0666)) == -1) {
640 <                perror(fname);
650 <                exit(1);
651 <        }
639 >        if ((fd = open(fname, O_WRONLY|O_CREAT|O_TRUNC, 0666)) == -1)
640 >                syserror(fname);
641          if (donorm
642          && (zout = (float *)malloc(hresolu*sizeof(float))) == NULL)
643 <                syserror();
643 >                syserror(progname);
644          for (y = vresolu-1; y >= 0; y--) {
645                  if (donorm) {
646                          double  vx, yzn2;
# Line 666 | Line 655 | char   *fname;
655                  } else
656                          zout = zscan(y);
657                  if (write(fd, (char *)zout, hresolu*sizeof(float))
658 <                                < hresolu*sizeof(float)) {
659 <                        perror(fname);
671 <                        exit(1);
672 <                }
658 >                                < hresolu*sizeof(float))
659 >                        syserror(fname);
660          }
661          if (donorm)
662                  free((char *)zout);
# Line 715 | Line 702 | char   *prog, *args;
702          cp = combuf;
703          wp = argv;
704          for ( ; ; ) {
705 <                while (isspace(*cp)) cp++;
706 <                if (!*cp) break;
707 <                *wp++ = cp;
708 <                while (!isspace(*cp))
709 <                        if (!*cp++) goto done;
710 <                *cp++ = '\0';
705 >                while (isspace(*cp))    /* nullify spaces */
706 >                        *cp++ = '\0';
707 >                if (!*cp)               /* all done? */
708 >                        break;
709 >                *wp++ = cp;             /* add argument to list */
710 >                while (*++cp && !isspace(*cp))
711 >                        ;
712          }
725 done:
713          *wp = NULL;
714                                                  /* start process */
715          if ((rval = open_process(PDesc, argv)) < 0)
716 <                syserror();
716 >                syserror(progname);
717          if (rval == 0) {
718                  fprintf(stderr, "%s: command not found\n", argv[0]);
719                  exit(1);
# Line 767 | Line 754 | clearqueue()                           /* process queue */
754          register float  *fbp;
755          register int    i;
756  
757 +        if (queuesiz == 0)
758 +                return;
759          fbp = fbuf;
760          for (i = 0; i < queuesiz; i++) {
761                  viewray(orig, dir, &ourview,
# Line 800 | Line 789 | clearqueue()                           /* process queue */
789   }
790  
791  
792 < syserror()                      /* report error and exit */
792 > syserror(s)                     /* report error and exit */
793 > char    *s;
794   {
795 <        perror(progname);
795 >        perror(s);
796          exit(1);
797   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines