1 |
< |
/* Copyright (c) 1993 Regents of the University of California */ |
1 |
> |
/* Copyright (c) 1995 Regents of the University of California */ |
2 |
|
|
3 |
|
#ifndef lint |
4 |
|
static char SCCSid[] = "$SunId$ LBL"; |
47 |
|
#define guard_io() 0 |
48 |
|
#define unguard() 0 |
49 |
|
#endif |
50 |
+ |
|
51 |
+ |
#ifndef linux |
52 |
+ |
extern char *sys_errlist[]; |
53 |
+ |
#endif |
54 |
+ |
|
55 |
|
/* rpict command */ |
56 |
|
char *rpargv[128] = {"rpict", "-S", "1"}; |
57 |
|
int rpargc = 3; |
74 |
|
|
75 |
|
char *progname; |
76 |
|
int verbose = 0; |
77 |
+ |
unsigned timelim = 0; |
78 |
|
int rvrlim = -1; |
79 |
|
|
74 |
– |
extern long lseek(), ftell(); |
75 |
– |
|
80 |
|
int gotalrm = 0; |
81 |
|
int onalrm() { gotalrm++; } |
82 |
|
|
122 |
|
case 'p': /* pixel aspect ratio? */ |
123 |
|
if (argv[i][2] != 'a' || argv[i][3]) |
124 |
|
break; |
125 |
< |
pixaspect = atof(argv[i+1]); |
125 |
> |
pixaspect = atof(argv[++i]); |
126 |
|
continue; |
127 |
+ |
case 'T': /* time limit (hours) */ |
128 |
+ |
if (argv[i][2]) |
129 |
+ |
break; |
130 |
+ |
timelim = atof(argv[++i])*3600. + .5; |
131 |
+ |
break; |
132 |
|
case 'x': /* overall x resolution */ |
133 |
|
if (argv[i][2]) |
134 |
|
break; |
157 |
|
case 'F': /* syncronization file */ |
158 |
|
if (argv[i][2]) |
159 |
|
break; |
160 |
< |
if ((syncfp = fopen(argv[++i],"r+")) == NULL) { |
160 |
> |
if ((syncfp = |
161 |
> |
fdopen(open(argv[++i],O_RDWR|O_CREAT,0666),"r+")) == NULL) { |
162 |
|
fprintf(stderr, "%s: cannot open\n", |
163 |
|
argv[i]); |
164 |
|
exit(1); |
199 |
|
|
200 |
|
fls.l_type = ltyp; |
201 |
|
if (fcntl(fd, F_SETLKW, &fls) < 0) { |
202 |
< |
fprintf(stderr, "%s: cannot lock/unlock file\n", progname); |
202 |
> |
fprintf(stderr, "%s: cannot lock/unlock file: %s\n", |
203 |
> |
progname, sys_errlist[errno]); |
204 |
|
exit(1); |
205 |
|
} |
206 |
|
} |
241 |
|
dolock(outfd, F_WRLCK); |
242 |
|
if ((fp = fdopen(dup(outfd), "w")) == NULL) |
243 |
|
goto filerr; |
244 |
< |
printargs(ac, av, fp); /* write header */ |
244 |
> |
newheader("RADIANCE", fp); /* create header */ |
245 |
> |
printargs(ac, av, fp); |
246 |
|
fprintf(fp, "SOFTWARE= %s\n", VersionID); |
247 |
|
fputs(VIEWSTR, fp); |
248 |
|
fprintview(&ourview, fp); |
288 |
|
exit(1); |
289 |
|
} |
290 |
|
signal(SIGALRM, onalrm); |
291 |
+ |
if (timelim) |
292 |
+ |
alarm(timelim); |
293 |
|
return; |
294 |
|
filerr: |
295 |
|
fprintf(stderr, "%s: i/o error on file \"%s\"\n", progname, outfile); |
355 |
|
return(0); /* only check if asked */ |
356 |
|
if (pdone == NULL) /* first call */ |
357 |
|
pdone = calloc(hmult*vmult, sizeof(char)); |
358 |
+ |
if (pdone == NULL) { |
359 |
+ |
fprintf(stderr, "%s: out of memory\n", progname); |
360 |
+ |
exit(1); |
361 |
+ |
} |
362 |
|
if (readpos != -1) /* mark what's been done */ |
363 |
|
fseek(syncfp, readpos, 0); |
364 |
|
while (fscanf(syncfp, "%d %d", xp, yp) == 2) |
417 |
|
pview.horiz = ourview.horiz / hmult; |
418 |
|
pview.vert = ourview.vert / vmult; |
419 |
|
break; |
420 |
+ |
case VT_CYL: |
421 |
+ |
pview.horiz = ourview.horiz / hmult; |
422 |
+ |
pview.vert = 2.*180./PI*atan( |
423 |
+ |
tan(PI/180./2.*ourview.vert)/vmult ); |
424 |
+ |
break; |
425 |
|
case VT_HEM: |
426 |
|
pview.horiz = 2.*180./PI*asin( |
427 |
|
sin(PI/180./2.*ourview.horiz)/hmult ); |
435 |
|
} |
436 |
|
/* render each piece */ |
437 |
|
while (nextpiece(&xorg, &yorg)) { |
438 |
< |
pview.hoff = ourview.hoff + xorg - 0.5*(hmult-1); |
439 |
< |
pview.voff = ourview.voff + yorg - 0.5*(vmult-1); |
438 |
> |
pview.hoff = ourview.hoff*hmult + xorg - 0.5*(hmult-1); |
439 |
> |
pview.voff = ourview.voff*vmult + yorg - 0.5*(vmult-1); |
440 |
|
fputs(VIEWSTR, torp); |
441 |
|
fprintview(&pview, torp); |
442 |
|
putc('\n', torp); |
508 |
|
filerr("lock"); |
509 |
|
#endif |
510 |
|
/* write new piece to file */ |
511 |
< |
if (lseek(outfd, fls.l_start, 0) == -1) |
511 |
> |
if (lseek(outfd, fls.l_start, 0) < 0) |
512 |
|
filerr("seek"); |
513 |
|
if (hmult == 1) { |
514 |
|
if (writebuf(outfd, (char *)pbuf, |
521 |
|
filerr("write"); |
522 |
|
if (y < vr-1 && lseek(outfd, |
523 |
|
(long)(hmult-1)*hr*sizeof(COLR), |
524 |
< |
1) == -1) |
524 |
> |
1) < 0) |
525 |
|
filerr("seek"); |
526 |
|
} |
527 |
|
#if NFS |
529 |
|
if (fcntl(outfd, F_SETLKW, &fls) < 0) |
530 |
|
filerr("lock"); |
531 |
|
#endif |
532 |
+ |
if (verbose) { /* notify caller */ |
533 |
+ |
printf("%d %d done\n", xpos, ypos); |
534 |
+ |
fflush(stdout); |
535 |
+ |
} |
536 |
|
if (syncfp != NULL) { /* record what's been done */ |
537 |
|
sflock(F_WRLCK); |
538 |
|
fseek(syncfp, 0L, 2); /* append index */ |
541 |
|
/*** Unlock not necessary, since |
542 |
|
sflock(F_UNLCK); _exit() or nextpiece() is next ***/ |
543 |
|
} |
517 |
– |
if (verbose) { /* notify caller */ |
518 |
– |
printf("%d %d done\n", xpos, ypos); |
519 |
– |
fflush(stdout); |
520 |
– |
} |
544 |
|
if (pid == -1) /* didn't fork or fork failed */ |
545 |
|
return(0); |
546 |
|
_exit(0); /* else exit child process (releasing locks) */ |
550 |
|
filerr(t) /* report file error and exit */ |
551 |
|
char *t; |
552 |
|
{ |
530 |
– |
extern char *sys_errlist[]; |
531 |
– |
|
553 |
|
fprintf(stderr, "%s: %s error on file \"%s\": %s\n", |
554 |
|
progname, t, outfile, sys_errlist[errno]); |
555 |
|
_exit(1); |