--- ray/src/util/rpiece.c 2003/10/20 16:01:55 2.42 +++ ray/src/util/rpiece.c 2008/04/24 10:28:25 2.49 @@ -1,18 +1,32 @@ #ifndef lint -static const char RCSid[] = "$Id: rpiece.c,v 2.42 2003/10/20 16:01:55 greg Exp $"; +static const char RCSid[] = "$Id: rpiece.c,v 2.49 2008/04/24 10:28:25 schorsch Exp $"; #endif /* * Generate sections of a picture. */ + +#include +#include +#include + #include "platform.h" +#ifndef NON_POSIX /* XXX need abstraction for process management */ + #include +#endif + #include "standard.h" +#include "color.h" +#include "view.h" +#include "rtprocess.h" #ifndef F_SETLKW -main(argc, argv) -int argc; -char *argv[]; +int +main( + int argc, + char *argv[] +) { fprintf(stderr, "%s: no NFS lock manager on this machine\n", argv[0]); exit(1); @@ -20,12 +34,6 @@ char *argv[]; #else -#include - -#include "color.h" -#include "view.h" -#include "rtprocess.h" - #ifndef NFS #define NFS 1 #endif @@ -43,8 +51,8 @@ char *argv[]; #define unguard() sigrelse(SIGALRM) #endif #ifndef guard_io -#define guard_io() 0 -#define unguard() 0 +#define guard_io() +#define unguard() #endif extern char *strerror(); @@ -76,10 +84,21 @@ int rvrlim = -1; int gotalrm = 0; void onalrm(int i) { gotalrm++; } +static void dolock(int fd, int ltyp); +static void init(int ac, char **av); +static int nextpiece(int *xp, int *yp); +static int rvrpiece(int *xp, int *yp); +static int cleanup(int rstat); +static void rpiece(void); +static int putpiece(int xpos, int ypos); +static void filerr(char *t); -main(argc, argv) -int argc; -char *argv[]; + +int +main( + int argc, + char *argv[] +) { register int i, rval; @@ -188,9 +207,11 @@ char *argv[]; } -dolock(fd, ltyp) /* lock or unlock a file */ -int fd; -int ltyp; +static void +dolock( /* lock or unlock a file */ + int fd, + int ltyp +) { static struct flock fls; /* static so initialized to zeroes */ @@ -203,9 +224,11 @@ int ltyp; } -init(ac, av) /* set up output file and start rpict */ -int ac; -char **av; +static void +init( /* set up output file and start rpict */ + int ac, + char **av +) { static char hrbuf[16], vrbuf[16]; extern char VersionID[]; @@ -226,6 +249,10 @@ char **av; /* compute piece size */ hres /= hmult; vres /= vmult; + if (hres <= 0 || vres <= 0) { + fprintf(stderr, "%s: illegal resolution/subdivision\n", progname); + exit(1); + } normaspect(viewaspect(&ourview)*hmult/vmult, &pixaspect, &hres, &vres); sprintf(hrbuf, "%d", hres); rpargv[rpargc++] = "-x"; rpargv[rpargc++] = hrbuf; @@ -295,9 +322,11 @@ filerr: } -int -nextpiece(xp, yp) /* get next piece assignment */ -int *xp, *yp; +static int +nextpiece( /* get next piece assignment */ + int *xp, + int *yp +) { if (gotalrm) /* someone wants us to quit */ return(0); @@ -337,9 +366,11 @@ int *xp, *yp; } -int -rvrpiece(xp, yp) /* check for recoverable pieces */ -register int *xp, *yp; +static int +rvrpiece( /* check for recoverable pieces */ + register int *xp, + register int *yp +) { static char *pdone = NULL; /* which pieces are done */ static long readpos = -1; /* how far we've read */ @@ -381,9 +412,10 @@ register int *xp, *yp; } -int -cleanup(rstat) /* close rpict process and clean up */ -int rstat; +static int +cleanup( /* close rpict process and clean up */ + int rstat +) { int status; @@ -397,7 +429,8 @@ int rstat; } -rpiece() /* render picture piece by piece */ +static void +rpiece(void) /* render picture piece by piece */ { VIEW pview; int xorg, yorg; @@ -405,10 +438,10 @@ rpiece() /* render picture piece by piece */ pview = ourview; switch (ourview.type) { case VT_PER: - pview.horiz = 2.*180./PI*atan( - tan(PI/180./2.*ourview.horiz)/hmult ); - pview.vert = 2.*180./PI*atan( - tan(PI/180./2.*ourview.vert)/vmult ); + pview.horiz = (2.*180./PI)*atan( + tan((PI/180./2.)*ourview.horiz)/hmult ); + pview.vert = (2.*180./PI)*atan( + tan((PI/180./2.)*ourview.vert)/vmult ); break; case VT_PAR: case VT_ANG: @@ -417,15 +450,27 @@ rpiece() /* render picture piece by piece */ break; case VT_CYL: pview.horiz = ourview.horiz / hmult; - pview.vert = 2.*180./PI*atan( - tan(PI/180./2.*ourview.vert)/vmult ); + pview.vert = (2.*180./PI)*atan( + tan((PI/180./2.)*ourview.vert)/vmult ); break; case VT_HEM: - pview.horiz = 2.*180./PI*asin( - sin(PI/180./2.*ourview.horiz)/hmult ); - pview.vert = 2.*180./PI*asin( - sin(PI/180./2.*ourview.vert)/vmult ); + pview.horiz = (2.*180./PI)*asin( + sin((PI/180./2.)*ourview.horiz)/hmult ); + pview.vert = (2.*180./PI)*asin( + sin((PI/180./2.)*ourview.vert)/vmult ); break; + case VT_PLS: + pview.horiz = sin((PI/180./2.)*ourview.horiz) / + (1.0 + cos((PI/180./2.)*ourview.horiz)) / hmult; + pview.horiz *= pview.horiz; + pview.horiz = (2.*180./PI)*acos((1. - pview.horiz) / + (1. + pview.horiz)); + pview.vert = sin((PI/180./2.)*ourview.vert) / + (1.0 + cos((PI/180./2.)*ourview.vert)) / vmult; + pview.vert *= pview.vert; + pview.vert = (2.*180./PI)*acos((1. - pview.vert) / + (1. + pview.vert)); + break; default: fprintf(stderr, "%s: unknown view type '-vt%c'\n", progname, ourview.type); @@ -444,9 +489,11 @@ rpiece() /* render picture piece by piece */ } -int -putpiece(xpos, ypos) /* get next piece from rpict */ -int xpos, ypos; +static int +putpiece( /* get next piece from rpict */ +int xpos, +int ypos +) { struct flock fls; int pid, status; @@ -545,8 +592,10 @@ int xpos, ypos; } -filerr(t) /* report file error and exit */ -char *t; +static void +filerr( /* report file error and exit */ + char *t +) { fprintf(stderr, "%s: %s error on file \"%s\": %s\n", progname, t, outfile, strerror(errno));