--- ray/src/util/rpiece.c 2004/06/08 19:48:31 2.44 +++ ray/src/util/rpiece.c 2012/06/01 22:55:14 2.54 @@ -1,5 +1,5 @@ #ifndef lint -static const char RCSid[] = "$Id: rpiece.c,v 2.44 2004/06/08 19:48:31 greg Exp $"; +static const char RCSid[] = "$Id: rpiece.c,v 2.54 2012/06/01 22:55:14 greg Exp $"; #endif /* * Generate sections of a picture. @@ -9,9 +9,12 @@ static const char RCSid[] = "$Id: rpiece.c,v 2.44 2004 #include #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" @@ -75,6 +78,7 @@ int nforked = 0; char *progname; int verbose = 0; +int nowarn = 0; unsigned timelim = 0; int rvrlim = -1; @@ -105,12 +109,20 @@ main( while ((rval = expandarg(&argc, &argv, i)) > 0) ; if (rval < 0) { - fprintf(stderr, "%s: cannot expand '%s'", + fprintf(stderr, "%s: cannot expand '%s'\n", argv[0], argv[i]); exit(1); } if (argv[i][0] == '-') switch (argv[i][1]) { + case 'w': + if (!argv[i][2]) + nowarn = !nowarn; + else if (argv[i][2] == '+') + nowarn = 0; + else if (argv[i][2] == '-') + nowarn = 1; + break; case 'v': switch (argv[i][2]) { case '\0': /* verbose option */ @@ -133,6 +145,12 @@ main( } break; case 'p': /* pixel aspect ratio? */ + if (argv[i][2] == 'm') { + fprintf(stderr, "%s: -pm unsupported\n", + argv[0]); + ++i; + continue; + } if (argv[i][2] != 'a' || argv[i][3]) break; pixaspect = atof(argv[++i]); @@ -141,7 +159,7 @@ main( if (argv[i][2]) break; timelim = atof(argv[++i])*3600. + .5; - break; + continue; case 'x': /* overall x resolution */ if (argv[i][2]) break; @@ -186,8 +204,9 @@ main( break; outfile = argv[++i]; continue; - } else if (i >= argc-1) - break; + } + else if (i >= argc-1) + break; rpargv[rpargc++] = argv[i]; } if (i >= argc) { @@ -216,7 +235,7 @@ dolock( /* lock or unlock a file */ if (fcntl(fd, F_SETLKW, &fls) < 0) { fprintf(stderr, "%s: cannot lock/unlock file: %s\n", progname, strerror(errno)); - exit(1); + _exit(1); } } @@ -244,9 +263,20 @@ init( /* set up output file and start rpict */ sflock(F_UNLCK); } /* compute piece size */ + hr = hres; vr = vres; + if (pixaspect > FTINY) + normaspect(viewaspect(&ourview), &pixaspect, &hr, &vr); 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); + if (!nowarn && (hr != hres*hmult) | (vr != vres*vmult)) + fprintf(stderr, + "%s: warning - resolution changed from %dx%d to %dx%d\n", + progname, hr, vr, hres*hmult, vres*vmult); sprintf(hrbuf, "%d", hres); rpargv[rpargc++] = "-x"; rpargv[rpargc++] = hrbuf; sprintf(vrbuf, "%d", vres); @@ -265,6 +295,7 @@ init( /* set up output file and start rpict */ fputs(VIEWSTR, fp); fprintview(&ourview, fp); putc('\n', fp); + fputnow(fp); if (pixaspect < .99 || pixaspect > 1.01) fputaspect(pixaspect, fp); fputformat(COLRFMT, fp); @@ -431,10 +462,10 @@ rpiece(void) /* 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: @@ -443,15 +474,27 @@ rpiece(void) /* 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); @@ -530,9 +573,13 @@ int ypos /* lock file section so NFS doesn't mess up */ fls.l_whence = 0; fls.l_type = F_WRLCK; +#if 0 if (fcntl(outfd, F_SETLKW, &fls) < 0) filerr("lock"); +#else + dolock(outfd, F_WRLCK); #endif +#endif /* write new piece to file */ if (lseek(outfd, (off_t)fls.l_start, SEEK_SET) < 0) filerr("seek"); @@ -552,8 +599,12 @@ int ypos } #if NFS fls.l_type = F_UNLCK; /* release lock */ +#if 0 if (fcntl(outfd, F_SETLKW, &fls) < 0) filerr("lock"); +#else + dolock(outfd, F_UNLCK); +#endif #endif if (verbose) { /* notify caller */ printf("%d %d done\n", xpos, ypos);