--- ray/src/util/rpiece.c 2007/08/22 18:46:36 2.47 +++ ray/src/util/rpiece.c 2023/07/11 02:22:30 2.60 @@ -1,5 +1,5 @@ #ifndef lint -static const char RCSid[] = "$Id: rpiece.c,v 2.47 2007/08/22 18:46:36 greg Exp $"; +static const char RCSid[] = "$Id: rpiece.c,v 2.60 2023/07/11 02:22:30 greg Exp $"; #endif /* * Generate sections of a picture. @@ -9,11 +9,12 @@ static const char RCSid[] = "$Id: rpiece.c,v 2.47 2007 #include #include #include + +#include "platform.h" #ifndef NON_POSIX /* XXX need abstraction for process management */ #include #endif -#include "platform.h" #include "standard.h" #include "color.h" #include "view.h" @@ -36,7 +37,11 @@ main( #ifndef NFS #define NFS 1 #endif - /* set the following to 0 to forgo forking */ + +#ifndef RHAS_FORK_EXEC +#undef MAXFORK +#define MAXFORK 0 +#endif #ifndef MAXFORK #if NFS #define MAXFORK 3 /* allotment of duped processes */ @@ -77,6 +82,7 @@ int nforked = 0; char *progname; int verbose = 0; +int nowarn = 0; unsigned timelim = 0; int rvrlim = -1; @@ -99,7 +105,7 @@ main( char *argv[] ) { - register int i, rval; + int i, rval; progname = argv[0]; for (i = 1; i < argc; i++) { @@ -107,12 +113,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 */ @@ -135,6 +149,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]); @@ -143,7 +163,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; @@ -188,8 +208,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) { @@ -218,7 +239,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); } } @@ -246,6 +267,9 @@ 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) { @@ -253,6 +277,10 @@ init( /* set up output file and start rpict */ exit(1); } normaspect(viewaspect(&ourview)*hmult/vmult, &pixaspect, &hres, &vres); + if (!nowarn && (hr != hres*hmult) | (vr != vres*vmult)) + fprintf(stderr, + "%s: warning - changed resolution 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); @@ -270,11 +298,13 @@ init( /* set up output file and start rpict */ fprintf(fp, "SOFTWARE= %s\n", VersionID); fputs(VIEWSTR, fp); fprintview(&ourview, fp); - putc('\n', fp); + fputc('\n', fp); + fputnow(fp); if (pixaspect < .99 || pixaspect > 1.01) fputaspect(pixaspect, fp); + fputprims(stdprims, fp); fputformat(COLRFMT, fp); - putc('\n', fp); + fputc('\n', fp); fprtresolu(hres*hmult, vres*vmult, fp); } else if ((outfd = open(outfile, O_RDWR)) >= 0) { dolock(outfd, F_RDLCK); @@ -297,6 +327,7 @@ init( /* set up output file and start rpict */ goto filerr; dolock(outfd, F_UNLCK); /* start rpict process */ + rpd = sp_inactive; if (open_process(&rpd, rpargv) <= 0) { fprintf(stderr, "%s: cannot start %s\n", progname, rpargv[0]); exit(1); @@ -367,13 +398,13 @@ nextpiece( /* get next piece assignment */ static int rvrpiece( /* check for recoverable pieces */ - register int *xp, - register int *yp + int *xp, + int *yp ) { static char *pdone = NULL; /* which pieces are done */ static long readpos = -1; /* how far we've read */ - register int i; + int px, py, i; /* * This routine is called by nextpiece() with an * exclusive lock on syncfp and the file pointer at the @@ -382,15 +413,15 @@ rvrpiece( /* check for recoverable pieces */ if (rvrlim < 0) return(0); /* only check if asked */ if (pdone == NULL) /* first call */ - pdone = calloc(hmult*vmult, sizeof(char)); + pdone = (char *)calloc(hmult*vmult, sizeof(char)); if (pdone == NULL) { fprintf(stderr, "%s: out of memory\n", progname); exit(1); } if (readpos != -1) /* mark what's been done */ fseek(syncfp, readpos, 0); - while (fscanf(syncfp, "%d %d", xp, yp) == 2) - pdone[*xp*vmult+*yp] = 1; + while (fscanf(syncfp, "%d %d", &px, &py) == 2) + pdone[px*vmult+py] = 1; if (!feof(syncfp)) { fprintf(stderr, "%s: format error in sync file\n", progname); exit(1); @@ -431,45 +462,21 @@ cleanup( /* close rpict process and clean up */ static void rpiece(void) /* render picture piece by piece */ { + char *err; VIEW pview; int xorg, yorg; - /* compute view parameters */ - 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 ); - break; - case VT_PAR: - case VT_ANG: - pview.horiz = ourview.horiz / hmult; - pview.vert = ourview.vert / vmult; - break; - case VT_CYL: - pview.horiz = ourview.horiz / hmult; - 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 ); - break; - default: - fprintf(stderr, "%s: unknown view type '-vt%c'\n", - progname, ourview.type); - exit(cleanup(1)); - } /* render each piece */ while (nextpiece(&xorg, &yorg)) { - pview.hoff = ourview.hoff*hmult + xorg - 0.5*(hmult-1); - pview.voff = ourview.voff*vmult + yorg - 0.5*(vmult-1); + pview = ourview; + err = cropview(&pview, (double)xorg/hmult, (double)yorg/vmult, + (xorg+1.)/hmult, (yorg+1.)/vmult); + if (err != NULL) { + fprintf(stderr, "%s: %s\n", progname, err); + exit(cleanup(1)); + } fputs(VIEWSTR, torp); fprintview(&pview, torp); - putc('\n', torp); + fputc('\n', torp); fflush(torp); /* assigns piece to rpict */ putpiece(xorg, yorg); /* place piece in output */ } @@ -485,7 +492,7 @@ int ypos struct flock fls; int pid, status; int hr, vr; - register int y; + int y; /* check bounds */ if ((xpos < 0) | (ypos < 0) | (xpos >= hmult) | (ypos >= vmult)) { fprintf(stderr, "%s: requested piece (%d,%d) out of range\n", @@ -536,9 +543,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"); @@ -558,8 +569,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);