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

Comparing ray/src/util/rpiece.c (file contents):
Revision 2.41 by schorsch, Sun Jul 27 22:12:04 2003 UTC vs.
Revision 2.51 by greg, Mon May 17 17:03:53 2010 UTC

# Line 5 | Line 5 | static const char      RCSid[] = "$Id$";
5   * Generate sections of a picture.
6   */
7  
8 +
9 + #include <stdio.h>
10 + #include <signal.h>
11 + #include <sys/types.h>
12 +
13 + #include "platform.h"
14 + #ifndef NON_POSIX /* XXX need abstraction for process management */
15 + #include <sys/wait.h>
16 + #endif
17 +
18   #include "standard.h"
19 + #include "color.h"
20 + #include "view.h"
21 + #include "rtprocess.h"
22  
23   #ifndef F_SETLKW
24  
25 < main(argc, argv)
26 < int argc;
27 < char *argv[];
25 > int
26 > main(
27 >        int argc,
28 >        char *argv[]
29 > )
30   {
31          fprintf(stderr, "%s: no NFS lock manager on this machine\n", argv[0]);
32          exit(1);
# Line 19 | Line 34 | char *argv[];
34  
35   #else
36  
22 #include <signal.h>
23
24 #include "color.h"
25 #include "view.h"
26 #include "rtprocess.h"
27
37   #ifndef NFS
38   #define  NFS                    1
39   #endif
# Line 42 | Line 51 | char *argv[];
51   #define unguard()       sigrelse(SIGALRM)
52   #endif
53   #ifndef guard_io
54 < #define guard_io()      0
55 < #define unguard()       0
54 > #define guard_io()      
55 > #define unguard()      
56   #endif
57  
58   extern char  *strerror();
# Line 75 | Line 84 | int  rvrlim = -1;
84   int  gotalrm = 0;
85   void  onalrm(int i) { gotalrm++; }
86  
87 + static void dolock(int  fd, int  ltyp);
88 + static void init(int  ac, char  **av);
89 + static int nextpiece(int        *xp, int        *yp);
90 + static int rvrpiece(int *xp, int        *yp);
91 + static int cleanup(int  rstat);
92 + static void rpiece(void);
93 + static int putpiece(int xpos, int       ypos);
94 + static void filerr(char  *t);
95  
96 < main(argc, argv)
97 < int  argc;
98 < char  *argv[];
96 >
97 > int
98 > main(
99 >        int  argc,
100 >        char  *argv[]
101 > )
102   {
103          register int  i, rval;
104          
# Line 88 | Line 108 | char  *argv[];
108                  while ((rval = expandarg(&argc, &argv, i)) > 0)
109                          ;
110                  if (rval < 0) {
111 <                        fprintf(stderr, "%s: cannot expand '%s'",
111 >                        fprintf(stderr, "%s: cannot expand '%s'\n",
112                                          argv[0], argv[i]);
113                          exit(1);
114                  }
# Line 116 | Line 136 | char  *argv[];
136                                  }
137                                  break;
138                          case 'p':               /* pixel aspect ratio? */
139 +                                if (argv[i][2] == 'm') {
140 +                                        fprintf(stderr, "%s: -pm unsupported\n",
141 +                                                argv[0]);
142 +                                        ++i;
143 +                                        continue;
144 +                                }
145                                  if (argv[i][2] != 'a' || argv[i][3])
146                                          break;
147                                  pixaspect = atof(argv[++i]);
# Line 124 | Line 150 | char  *argv[];
150                                  if (argv[i][2])
151                                          break;
152                                  timelim = atof(argv[++i])*3600. + .5;
153 <                                break;
153 >                                continue;
154                          case 'x':               /* overall x resolution */
155                                  if (argv[i][2])
156                                          break;
# Line 187 | Line 213 | char  *argv[];
213   }
214  
215  
216 < dolock(fd, ltyp)                /* lock or unlock a file */
217 < int  fd;
218 < int  ltyp;
216 > static void
217 > dolock(         /* lock or unlock a file */
218 >        int  fd,
219 >        int  ltyp
220 > )
221   {
222          static struct flock  fls;       /* static so initialized to zeroes */
223  
# Line 202 | Line 230 | int  ltyp;
230   }
231  
232  
233 < init(ac, av)                    /* set up output file and start rpict */
234 < int  ac;
235 < char  **av;
233 > static void
234 > init(                   /* set up output file and start rpict */
235 >        int  ac,
236 >        char  **av
237 > )
238   {
239          static char  hrbuf[16], vrbuf[16];
240          extern char  VersionID[];
# Line 225 | Line 255 | char  **av;
255                                          /* compute piece size */
256          hres /= hmult;
257          vres /= vmult;
258 +        if (hres <= 0 || vres <= 0) {
259 +                fprintf(stderr, "%s: illegal resolution/subdivision\n", progname);
260 +                exit(1);
261 +        }
262          normaspect(viewaspect(&ourview)*hmult/vmult, &pixaspect, &hres, &vres);
263          sprintf(hrbuf, "%d", hres);
264          rpargv[rpargc++] = "-x"; rpargv[rpargc++] = hrbuf;
# Line 294 | Line 328 | filerr:
328   }
329  
330  
331 < int
332 < nextpiece(xp, yp)               /* get next piece assignment */
333 < int  *xp, *yp;
331 > static int
332 > nextpiece(              /* get next piece assignment */
333 >        int     *xp,
334 >        int     *yp
335 > )
336   {
337          if (gotalrm)                    /* someone wants us to quit */
338                  return(0);
# Line 336 | Line 372 | int  *xp, *yp;
372   }
373  
374  
375 < int
376 < rvrpiece(xp, yp)                /* check for recoverable pieces */
377 < register int  *xp, *yp;
375 > static int
376 > rvrpiece(               /* check for recoverable pieces */
377 >        register int    *xp,
378 >        register int    *yp
379 > )
380   {
381          static char  *pdone = NULL;     /* which pieces are done */
382          static long  readpos = -1;      /* how far we've read */
# Line 380 | Line 418 | register int  *xp, *yp;
418   }
419  
420  
421 < int
422 < cleanup(rstat)                  /* close rpict process and clean up */
423 < int  rstat;
421 > static int
422 > cleanup(                        /* close rpict process and clean up */
423 >        int  rstat
424 > )
425   {
426          int  status;
427  
# Line 396 | Line 435 | int  rstat;
435   }
436  
437  
438 < rpiece()                        /* render picture piece by piece */
438 > static void
439 > rpiece(void)                    /* render picture piece by piece */
440   {
441          VIEW  pview;
442          int  xorg, yorg;
# Line 404 | Line 444 | rpiece()                       /* render picture piece by piece */
444          pview = ourview;
445          switch (ourview.type) {
446          case VT_PER:
447 <                pview.horiz = 2.*180./PI*atan(
448 <                                tan(PI/180./2.*ourview.horiz)/hmult );
449 <                pview.vert = 2.*180./PI*atan(
450 <                                tan(PI/180./2.*ourview.vert)/vmult );
447 >                pview.horiz = (2.*180./PI)*atan(
448 >                                tan((PI/180./2.)*ourview.horiz)/hmult );
449 >                pview.vert = (2.*180./PI)*atan(
450 >                                tan((PI/180./2.)*ourview.vert)/vmult );
451                  break;
452          case VT_PAR:
453          case VT_ANG:
# Line 416 | Line 456 | rpiece()                       /* render picture piece by piece */
456                  break;
457          case VT_CYL:
458                  pview.horiz = ourview.horiz / hmult;
459 <                pview.vert = 2.*180./PI*atan(
460 <                                tan(PI/180./2.*ourview.vert)/vmult );
459 >                pview.vert = (2.*180./PI)*atan(
460 >                                tan((PI/180./2.)*ourview.vert)/vmult );
461                  break;
462          case VT_HEM:
463 <                pview.horiz = 2.*180./PI*asin(
464 <                                sin(PI/180./2.*ourview.horiz)/hmult );
465 <                pview.vert = 2.*180./PI*asin(
466 <                                sin(PI/180./2.*ourview.vert)/vmult );
463 >                pview.horiz = (2.*180./PI)*asin(
464 >                                sin((PI/180./2.)*ourview.horiz)/hmult );
465 >                pview.vert = (2.*180./PI)*asin(
466 >                                sin((PI/180./2.)*ourview.vert)/vmult );
467                  break;
468 +        case VT_PLS:
469 +                pview.horiz = sin((PI/180./2.)*ourview.horiz) /
470 +                                (1.0 + cos((PI/180./2.)*ourview.horiz)) / hmult;
471 +                pview.horiz *= pview.horiz;
472 +                pview.horiz = (2.*180./PI)*acos((1. - pview.horiz) /
473 +                                                (1. + pview.horiz));
474 +                pview.vert = sin((PI/180./2.)*ourview.vert) /
475 +                                (1.0 + cos((PI/180./2.)*ourview.vert)) / vmult;
476 +                pview.vert *= pview.vert;
477 +                pview.vert = (2.*180./PI)*acos((1. - pview.vert) /
478 +                                                (1. + pview.vert));
479 +                break;
480          default:
481                  fprintf(stderr, "%s: unknown view type '-vt%c'\n",
482                                  progname, ourview.type);
# Line 443 | Line 495 | rpiece()                       /* render picture piece by piece */
495   }
496  
497  
498 < int
499 < putpiece(xpos, ypos)            /* get next piece from rpict */
500 < int  xpos, ypos;
498 > static int
499 > putpiece(               /* get next piece from rpict */
500 > int     xpos,
501 > int     ypos
502 > )
503   {
504          struct flock  fls;
505          int  pid, status;
# Line 505 | Line 559 | int  xpos, ypos;
559                  filerr("lock");
560   #endif
561                                  /* write new piece to file */
562 <        if (lseek(outfd, (off_t)fls.l_start, 0) < 0)
562 >        if (lseek(outfd, (off_t)fls.l_start, SEEK_SET) < 0)
563                  filerr("seek");
564          if (hmult == 1) {
565                  if (writebuf(outfd, (char *)pbuf,
# Line 518 | Line 572 | int  xpos, ypos;
572                                  filerr("write");
573                          if (y < vr-1 && lseek(outfd,
574                                          (off_t)(hmult-1)*hr*sizeof(COLR),
575 <                                        1) < 0)
575 >                                        SEEK_CUR) < 0)
576                                  filerr("seek");
577                  }
578   #if NFS
# Line 544 | Line 598 | int  xpos, ypos;
598   }
599  
600  
601 < filerr(t)                       /* report file error and exit */
602 < char  *t;
601 > static void
602 > filerr(                 /* report file error and exit */
603 >        char  *t
604 > )
605   {
606          fprintf(stderr, "%s: %s error on file \"%s\": %s\n",
607                          progname, t, outfile, strerror(errno));

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines