| 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(); |
| 78 |
|
|
| 79 |
|
char *progname; |
| 80 |
|
int verbose = 0; |
| 81 |
+ |
int nowarn = 0; |
| 82 |
|
unsigned timelim = 0; |
| 83 |
|
int rvrlim = -1; |
| 84 |
|
|
| 85 |
|
int gotalrm = 0; |
| 86 |
|
void onalrm(int i) { gotalrm++; } |
| 87 |
|
|
| 88 |
+ |
static void dolock(int fd, int ltyp); |
| 89 |
+ |
static void init(int ac, char **av); |
| 90 |
+ |
static int nextpiece(int *xp, int *yp); |
| 91 |
+ |
static int rvrpiece(int *xp, int *yp); |
| 92 |
+ |
static int cleanup(int rstat); |
| 93 |
+ |
static void rpiece(void); |
| 94 |
+ |
static int putpiece(int xpos, int ypos); |
| 95 |
+ |
static void filerr(char *t); |
| 96 |
|
|
| 97 |
< |
main(argc, argv) |
| 98 |
< |
int argc; |
| 99 |
< |
char *argv[]; |
| 97 |
> |
|
| 98 |
> |
int |
| 99 |
> |
main( |
| 100 |
> |
int argc, |
| 101 |
> |
char *argv[] |
| 102 |
> |
) |
| 103 |
|
{ |
| 104 |
|
register int i, rval; |
| 105 |
|
|
| 109 |
|
while ((rval = expandarg(&argc, &argv, i)) > 0) |
| 110 |
|
; |
| 111 |
|
if (rval < 0) { |
| 112 |
< |
fprintf(stderr, "%s: cannot expand '%s'", |
| 112 |
> |
fprintf(stderr, "%s: cannot expand '%s'\n", |
| 113 |
|
argv[0], argv[i]); |
| 114 |
|
exit(1); |
| 115 |
|
} |
| 116 |
|
if (argv[i][0] == '-') |
| 117 |
|
switch (argv[i][1]) { |
| 118 |
+ |
case 'w': |
| 119 |
+ |
if (!argv[i][2]) |
| 120 |
+ |
nowarn = !nowarn; |
| 121 |
+ |
else if (argv[i][2] == '+') |
| 122 |
+ |
nowarn = 0; |
| 123 |
+ |
else if (argv[i][2] == '-') |
| 124 |
+ |
nowarn = 1; |
| 125 |
+ |
break; |
| 126 |
|
case 'v': |
| 127 |
|
switch (argv[i][2]) { |
| 128 |
|
case '\0': /* verbose option */ |
| 145 |
|
} |
| 146 |
|
break; |
| 147 |
|
case 'p': /* pixel aspect ratio? */ |
| 148 |
+ |
if (argv[i][2] == 'm') { |
| 149 |
+ |
fprintf(stderr, "%s: -pm unsupported\n", |
| 150 |
+ |
argv[0]); |
| 151 |
+ |
++i; |
| 152 |
+ |
continue; |
| 153 |
+ |
} |
| 154 |
|
if (argv[i][2] != 'a' || argv[i][3]) |
| 155 |
|
break; |
| 156 |
|
pixaspect = atof(argv[++i]); |
| 159 |
|
if (argv[i][2]) |
| 160 |
|
break; |
| 161 |
|
timelim = atof(argv[++i])*3600. + .5; |
| 162 |
< |
break; |
| 162 |
> |
continue; |
| 163 |
|
case 'x': /* overall x resolution */ |
| 164 |
|
if (argv[i][2]) |
| 165 |
|
break; |
| 204 |
|
break; |
| 205 |
|
outfile = argv[++i]; |
| 206 |
|
continue; |
| 207 |
< |
} else if (i >= argc-1) |
| 208 |
< |
break; |
| 207 |
> |
} |
| 208 |
> |
else if (i >= argc-1) |
| 209 |
> |
break; |
| 210 |
|
rpargv[rpargc++] = argv[i]; |
| 211 |
|
} |
| 212 |
|
if (i >= argc) { |
| 223 |
|
} |
| 224 |
|
|
| 225 |
|
|
| 226 |
< |
dolock(fd, ltyp) /* lock or unlock a file */ |
| 227 |
< |
int fd; |
| 228 |
< |
int ltyp; |
| 226 |
> |
static void |
| 227 |
> |
dolock( /* lock or unlock a file */ |
| 228 |
> |
int fd, |
| 229 |
> |
int ltyp |
| 230 |
> |
) |
| 231 |
|
{ |
| 232 |
|
static struct flock fls; /* static so initialized to zeroes */ |
| 233 |
|
|
| 240 |
|
} |
| 241 |
|
|
| 242 |
|
|
| 243 |
< |
init(ac, av) /* set up output file and start rpict */ |
| 244 |
< |
int ac; |
| 245 |
< |
char **av; |
| 243 |
> |
static void |
| 244 |
> |
init( /* set up output file and start rpict */ |
| 245 |
> |
int ac, |
| 246 |
> |
char **av |
| 247 |
> |
) |
| 248 |
|
{ |
| 249 |
|
static char hrbuf[16], vrbuf[16]; |
| 250 |
|
extern char VersionID[]; |
| 263 |
|
sflock(F_UNLCK); |
| 264 |
|
} |
| 265 |
|
/* compute piece size */ |
| 266 |
+ |
hr = hres; vr = vres; |
| 267 |
+ |
if (pixaspect > FTINY) |
| 268 |
+ |
normaspect(viewaspect(&ourview), &pixaspect, &hr, &vr); |
| 269 |
|
hres /= hmult; |
| 270 |
|
vres /= vmult; |
| 271 |
+ |
if (hres <= 0 || vres <= 0) { |
| 272 |
+ |
fprintf(stderr, "%s: illegal resolution/subdivision\n", progname); |
| 273 |
+ |
exit(1); |
| 274 |
+ |
} |
| 275 |
|
normaspect(viewaspect(&ourview)*hmult/vmult, &pixaspect, &hres, &vres); |
| 276 |
+ |
if (!nowarn && (hr != hres*hmult) | (vr != vres*vmult)) |
| 277 |
+ |
fprintf(stderr, |
| 278 |
+ |
"%s: warning - resolution changed from %dx%d to %dx%d\n", |
| 279 |
+ |
progname, hr, vr, hres*hmult, vres*vmult); |
| 280 |
|
sprintf(hrbuf, "%d", hres); |
| 281 |
|
rpargv[rpargc++] = "-x"; rpargv[rpargc++] = hrbuf; |
| 282 |
|
sprintf(vrbuf, "%d", vres); |
| 295 |
|
fputs(VIEWSTR, fp); |
| 296 |
|
fprintview(&ourview, fp); |
| 297 |
|
putc('\n', fp); |
| 298 |
+ |
fputnow(fp); |
| 299 |
|
if (pixaspect < .99 || pixaspect > 1.01) |
| 300 |
|
fputaspect(pixaspect, fp); |
| 301 |
|
fputformat(COLRFMT, fp); |
| 346 |
|
} |
| 347 |
|
|
| 348 |
|
|
| 349 |
< |
int |
| 350 |
< |
nextpiece(xp, yp) /* get next piece assignment */ |
| 351 |
< |
int *xp, *yp; |
| 349 |
> |
static int |
| 350 |
> |
nextpiece( /* get next piece assignment */ |
| 351 |
> |
int *xp, |
| 352 |
> |
int *yp |
| 353 |
> |
) |
| 354 |
|
{ |
| 355 |
|
if (gotalrm) /* someone wants us to quit */ |
| 356 |
|
return(0); |
| 390 |
|
} |
| 391 |
|
|
| 392 |
|
|
| 393 |
< |
int |
| 394 |
< |
rvrpiece(xp, yp) /* check for recoverable pieces */ |
| 395 |
< |
register int *xp, *yp; |
| 393 |
> |
static int |
| 394 |
> |
rvrpiece( /* check for recoverable pieces */ |
| 395 |
> |
register int *xp, |
| 396 |
> |
register int *yp |
| 397 |
> |
) |
| 398 |
|
{ |
| 399 |
|
static char *pdone = NULL; /* which pieces are done */ |
| 400 |
|
static long readpos = -1; /* how far we've read */ |
| 436 |
|
} |
| 437 |
|
|
| 438 |
|
|
| 439 |
< |
int |
| 440 |
< |
cleanup(rstat) /* close rpict process and clean up */ |
| 441 |
< |
int rstat; |
| 439 |
> |
static int |
| 440 |
> |
cleanup( /* close rpict process and clean up */ |
| 441 |
> |
int rstat |
| 442 |
> |
) |
| 443 |
|
{ |
| 444 |
|
int status; |
| 445 |
|
|
| 453 |
|
} |
| 454 |
|
|
| 455 |
|
|
| 456 |
< |
rpiece() /* render picture piece by piece */ |
| 456 |
> |
static void |
| 457 |
> |
rpiece(void) /* render picture piece by piece */ |
| 458 |
|
{ |
| 459 |
|
VIEW pview; |
| 460 |
|
int xorg, yorg; |
| 462 |
|
pview = ourview; |
| 463 |
|
switch (ourview.type) { |
| 464 |
|
case VT_PER: |
| 465 |
< |
pview.horiz = 2.*180./PI*atan( |
| 466 |
< |
tan(PI/180./2.*ourview.horiz)/hmult ); |
| 467 |
< |
pview.vert = 2.*180./PI*atan( |
| 468 |
< |
tan(PI/180./2.*ourview.vert)/vmult ); |
| 465 |
> |
pview.horiz = (2.*180./PI)*atan( |
| 466 |
> |
tan((PI/180./2.)*ourview.horiz)/hmult ); |
| 467 |
> |
pview.vert = (2.*180./PI)*atan( |
| 468 |
> |
tan((PI/180./2.)*ourview.vert)/vmult ); |
| 469 |
|
break; |
| 470 |
|
case VT_PAR: |
| 471 |
|
case VT_ANG: |
| 474 |
|
break; |
| 475 |
|
case VT_CYL: |
| 476 |
|
pview.horiz = ourview.horiz / hmult; |
| 477 |
< |
pview.vert = 2.*180./PI*atan( |
| 478 |
< |
tan(PI/180./2.*ourview.vert)/vmult ); |
| 477 |
> |
pview.vert = (2.*180./PI)*atan( |
| 478 |
> |
tan((PI/180./2.)*ourview.vert)/vmult ); |
| 479 |
|
break; |
| 480 |
|
case VT_HEM: |
| 481 |
< |
pview.horiz = 2.*180./PI*asin( |
| 482 |
< |
sin(PI/180./2.*ourview.horiz)/hmult ); |
| 483 |
< |
pview.vert = 2.*180./PI*asin( |
| 484 |
< |
sin(PI/180./2.*ourview.vert)/vmult ); |
| 481 |
> |
pview.horiz = (2.*180./PI)*asin( |
| 482 |
> |
sin((PI/180./2.)*ourview.horiz)/hmult ); |
| 483 |
> |
pview.vert = (2.*180./PI)*asin( |
| 484 |
> |
sin((PI/180./2.)*ourview.vert)/vmult ); |
| 485 |
|
break; |
| 486 |
+ |
case VT_PLS: |
| 487 |
+ |
pview.horiz = sin((PI/180./2.)*ourview.horiz) / |
| 488 |
+ |
(1.0 + cos((PI/180./2.)*ourview.horiz)) / hmult; |
| 489 |
+ |
pview.horiz *= pview.horiz; |
| 490 |
+ |
pview.horiz = (2.*180./PI)*acos((1. - pview.horiz) / |
| 491 |
+ |
(1. + pview.horiz)); |
| 492 |
+ |
pview.vert = sin((PI/180./2.)*ourview.vert) / |
| 493 |
+ |
(1.0 + cos((PI/180./2.)*ourview.vert)) / vmult; |
| 494 |
+ |
pview.vert *= pview.vert; |
| 495 |
+ |
pview.vert = (2.*180./PI)*acos((1. - pview.vert) / |
| 496 |
+ |
(1. + pview.vert)); |
| 497 |
+ |
break; |
| 498 |
|
default: |
| 499 |
|
fprintf(stderr, "%s: unknown view type '-vt%c'\n", |
| 500 |
|
progname, ourview.type); |
| 513 |
|
} |
| 514 |
|
|
| 515 |
|
|
| 516 |
< |
int |
| 517 |
< |
putpiece(xpos, ypos) /* get next piece from rpict */ |
| 518 |
< |
int xpos, ypos; |
| 516 |
> |
static int |
| 517 |
> |
putpiece( /* get next piece from rpict */ |
| 518 |
> |
int xpos, |
| 519 |
> |
int ypos |
| 520 |
> |
) |
| 521 |
|
{ |
| 522 |
|
struct flock fls; |
| 523 |
|
int pid, status; |
| 577 |
|
filerr("lock"); |
| 578 |
|
#endif |
| 579 |
|
/* write new piece to file */ |
| 580 |
< |
if (lseek(outfd, (off_t)fls.l_start, 0) < 0) |
| 580 |
> |
if (lseek(outfd, (off_t)fls.l_start, SEEK_SET) < 0) |
| 581 |
|
filerr("seek"); |
| 582 |
|
if (hmult == 1) { |
| 583 |
|
if (writebuf(outfd, (char *)pbuf, |
| 590 |
|
filerr("write"); |
| 591 |
|
if (y < vr-1 && lseek(outfd, |
| 592 |
|
(off_t)(hmult-1)*hr*sizeof(COLR), |
| 593 |
< |
1) < 0) |
| 593 |
> |
SEEK_CUR) < 0) |
| 594 |
|
filerr("seek"); |
| 595 |
|
} |
| 596 |
|
#if NFS |
| 616 |
|
} |
| 617 |
|
|
| 618 |
|
|
| 619 |
< |
filerr(t) /* report file error and exit */ |
| 620 |
< |
char *t; |
| 619 |
> |
static void |
| 620 |
> |
filerr( /* report file error and exit */ |
| 621 |
> |
char *t |
| 622 |
> |
) |
| 623 |
|
{ |
| 624 |
|
fprintf(stderr, "%s: %s error on file \"%s\": %s\n", |
| 625 |
|
progname, t, outfile, strerror(errno)); |