| 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); |
| 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 |
| 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(); |
| 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 |
|
|
| 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 |
|
} |
| 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]); |
| 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; |
| 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 |
|
|
| 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[]; |
| 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; |
| 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); |
| 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 */ |
| 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 |
|
|
| 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; |
| 443 |
|
/* compute view parameters */ |
| 444 |
< |
copystruct(&pview, &ourview); |
| 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: |
| 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); |
| 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; |
| 506 |
|
int hr, vr; |
| 507 |
|
register int y; |
| 508 |
|
/* check bounds */ |
| 509 |
< |
if (xpos < 0 | ypos < 0 | xpos >= hmult | ypos >= vmult) { |
| 509 |
> |
if ((xpos < 0) | (ypos < 0) | (xpos >= hmult) | (ypos >= vmult)) { |
| 510 |
|
fprintf(stderr, "%s: requested piece (%d,%d) out of range\n", |
| 511 |
|
progname, xpos, ypos); |
| 512 |
|
exit(cleanup(1)); |
| 514 |
|
/* check header from rpict */ |
| 515 |
|
guard_io(); |
| 516 |
|
getheader(fromrp, NULL, NULL); |
| 517 |
< |
if (!fscnresolu(&hr, &vr, fromrp) || hr != hres | vr != vres) { |
| 517 |
> |
if (!fscnresolu(&hr, &vr, fromrp) || (hr != hres) | (vr != vres)) { |
| 518 |
|
fprintf(stderr, "%s: resolution mismatch from %s\n", |
| 519 |
|
progname, rpargv[0]); |
| 520 |
|
exit(cleanup(1)); |
| 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, |
| 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 |
| 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)); |