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 |
|
|
16 |
– |
#include "platform.h" |
18 |
|
#include "standard.h" |
19 |
|
#include "color.h" |
20 |
|
#include "view.h" |
78 |
|
|
79 |
|
char *progname; |
80 |
|
int verbose = 0; |
81 |
+ |
int nowarn = 0; |
82 |
|
unsigned timelim = 0; |
83 |
|
int rvrlim = -1; |
84 |
|
|
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) { |
235 |
|
if (fcntl(fd, F_SETLKW, &fls) < 0) { |
236 |
|
fprintf(stderr, "%s: cannot lock/unlock file: %s\n", |
237 |
|
progname, strerror(errno)); |
238 |
< |
exit(1); |
238 |
> |
_exit(1); |
239 |
|
} |
240 |
|
} |
241 |
|
|
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); |
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); |
573 |
|
/* lock file section so NFS doesn't mess up */ |
574 |
|
fls.l_whence = 0; |
575 |
|
fls.l_type = F_WRLCK; |
576 |
+ |
#if 0 |
577 |
|
if (fcntl(outfd, F_SETLKW, &fls) < 0) |
578 |
|
filerr("lock"); |
579 |
+ |
#else |
580 |
+ |
dolock(outfd, F_WRLCK); |
581 |
|
#endif |
582 |
+ |
#endif |
583 |
|
/* write new piece to file */ |
584 |
|
if (lseek(outfd, (off_t)fls.l_start, SEEK_SET) < 0) |
585 |
|
filerr("seek"); |
599 |
|
} |
600 |
|
#if NFS |
601 |
|
fls.l_type = F_UNLCK; /* release lock */ |
602 |
+ |
#if 0 |
603 |
|
if (fcntl(outfd, F_SETLKW, &fls) < 0) |
604 |
|
filerr("lock"); |
605 |
+ |
#else |
606 |
+ |
dolock(outfd, F_UNLCK); |
607 |
+ |
#endif |
608 |
|
#endif |
609 |
|
if (verbose) { /* notify caller */ |
610 |
|
printf("%d %d done\n", xpos, ypos); |