15 |
|
#include "resolu.h" |
16 |
|
|
17 |
|
/* rpict command */ |
18 |
< |
char *rpargv[128] = {"rpict", "-S", "1", "-x", "512", "-y", "512", }; |
19 |
< |
int rpargc = 7; |
18 |
> |
char *rpargv[128] = {"rpict", "-S", "1", "-x", "512", "-y", "512", "-pa", "1"}; |
19 |
> |
int rpargc = 9; |
20 |
|
int rpd[3]; |
21 |
|
FILE *torp, *fromrp; |
22 |
|
COLR *scanline; |
23 |
|
/* our view parameters */ |
24 |
|
VIEW ourview = STDVIEW; |
25 |
< |
double pixaspect = 0.0; |
25 |
> |
double pixaspect = 1.0; |
26 |
|
int hres = 512, vres = 512, hmult = 2, vmult = 2; |
27 |
|
/* output file */ |
28 |
|
char *outfile = NULL; |
29 |
|
int outfd; |
30 |
|
long scanorig; |
31 |
+ |
int syncfd = -1; /* lock file descriptor */ |
32 |
|
|
33 |
|
char *progname; |
34 |
|
int verbose = 0; |
89 |
|
break; |
90 |
|
vmult = atoi(argv[++i]); |
91 |
|
continue; |
92 |
+ |
case 'F': /* syncronization file */ |
93 |
+ |
if (argv[i][2]) |
94 |
+ |
break; |
95 |
+ |
if ((syncfd = open(argv[++i], O_RDWR)) < 0) { |
96 |
+ |
fprintf(stderr, "%s: cannot open\n", |
97 |
+ |
argv[i]); |
98 |
+ |
exit(1); |
99 |
+ |
} |
100 |
+ |
continue; |
101 |
|
case 'o': /* output file */ |
102 |
|
if (argv[i][2]) |
103 |
|
break; |
131 |
|
fprintf(stderr, "%s: %s\n", progname, err); |
132 |
|
exit(1); |
133 |
|
} |
134 |
+ |
if (syncfd != -1) { |
135 |
+ |
char buf[32]; |
136 |
+ |
buf[read(syncfd, buf, sizeof(buf)-1)] = '\0'; |
137 |
+ |
sscanf(buf, "%d %d", &hmult, &vmult); |
138 |
+ |
} |
139 |
|
normaspect(viewaspect(&ourview)*hmult/vmult, &pixaspect, &hres, &vres); |
140 |
|
/* open output file */ |
141 |
|
if ((outfd = open(outfile, O_WRONLY|O_CREAT|O_EXCL, 0666)) >= 0) { |
152 |
|
putc('\n', fp); |
153 |
|
fprtresolu(hres*hmult, vres*vmult, fp); |
154 |
|
} else if ((outfd = open(outfile, O_RDWR)) >= 0) { |
140 |
– |
sleep(30); /* wait for header */ |
155 |
|
if ((fp = fdopen(dup(outfd), "r+")) == NULL) |
156 |
|
goto filerr; |
157 |
|
getheader(fp, NULL); /* skip header */ |
168 |
|
scanorig = ftell(fp); /* record position of first scanline */ |
169 |
|
if (fclose(fp) == -1) /* done with stream i/o */ |
170 |
|
goto filerr; |
171 |
+ |
sync(); /* avoid NFS buffering */ |
172 |
|
/* start rpict process */ |
173 |
|
if (open_process(rpd, rpargv) <= 0) { |
174 |
< |
fprintf(stderr, "%s: cannot start\n", rpargv[0]); |
174 |
> |
fprintf(stderr, "%s: cannot start %s\n", progname, rpargv[0]); |
175 |
|
exit(1); |
176 |
|
} |
177 |
|
if ((fromrp = fdopen(rpd[0], "r")) == NULL || |
192 |
|
|
193 |
|
|
194 |
|
int |
195 |
+ |
nextpiece(xp, yp) /* get next piece assignment */ |
196 |
+ |
int *xp, *yp; |
197 |
+ |
{ |
198 |
+ |
extern char *fgets(); |
199 |
+ |
struct flock fls; |
200 |
+ |
char buf[64]; |
201 |
+ |
|
202 |
+ |
if (syncfd != -1) { /* using sync file */ |
203 |
+ |
fls.l_type = F_WRLCK; /* gain exclusive access */ |
204 |
+ |
fls.l_whence = 0; |
205 |
+ |
fls.l_start = 0L; |
206 |
+ |
fls.l_len = 0L; |
207 |
+ |
fcntl(syncfd, F_SETLKW, &fls); |
208 |
+ |
lseek(syncfd, 0L, 0); |
209 |
+ |
buf[read(syncfd, buf, sizeof(buf)-1)] = '\0'; |
210 |
+ |
if (sscanf(buf, "%*d %*d %d %d", xp, yp) < 2) { |
211 |
+ |
*xp = hmult; |
212 |
+ |
*yp = vmult-1; |
213 |
+ |
} |
214 |
+ |
if (--(*xp) < 0) { /* decrement position */ |
215 |
+ |
*xp = hmult-1; |
216 |
+ |
if (--(*yp) < 0) { /* all done! */ |
217 |
+ |
close(syncfd); |
218 |
+ |
return(0); |
219 |
+ |
} |
220 |
+ |
} |
221 |
+ |
sprintf(buf, "%d %d\n%d %d\n", hmult, vmult, *xp, *yp); |
222 |
+ |
lseek(syncfd, 0L, 0); /* write new position */ |
223 |
+ |
write(syncfd, buf, strlen(buf)); |
224 |
+ |
fls.l_type = F_UNLCK; /* release sync file */ |
225 |
+ |
fcntl(syncfd, F_SETLKW, &fls); |
226 |
+ |
return(1); |
227 |
+ |
} |
228 |
+ |
if (fgets(buf, sizeof(buf), stdin) == NULL) /* using stdin */ |
229 |
+ |
return(0); |
230 |
+ |
if (sscanf(buf, "%d %d", xp, yp) == 2) |
231 |
+ |
return(1); |
232 |
+ |
fprintf(stderr, "%s: input format error\n", progname); |
233 |
+ |
exit(1); |
234 |
+ |
} |
235 |
+ |
|
236 |
+ |
|
237 |
+ |
int |
238 |
|
cleanup() /* close rpict process and clean up */ |
239 |
|
{ |
240 |
|
register int rpstat; |
251 |
|
|
252 |
|
rpiece() /* render picture piece by piece */ |
253 |
|
{ |
196 |
– |
extern char *gets(), *strcat(); |
254 |
|
VIEW pview; |
198 |
– |
char buf[48]; |
255 |
|
int xorg, yorg; |
256 |
|
|
257 |
< |
while (gets(buf) != NULL) { |
202 |
< |
if (sscanf(buf, "%d %d", &xorg, &yorg) != 2) { |
203 |
< |
fprintf(stderr, "%s: input format error\n", progname); |
204 |
< |
exit(1); |
205 |
< |
} |
257 |
> |
while (nextpiece(&xorg, &yorg)) { |
258 |
|
copystruct(&pview, &ourview); /* compute view for piece */ |
259 |
|
switch (ourview.type) { |
260 |
|
case VT_PER: |
269 |
|
pview.vert = ourview.vert / vmult; |
270 |
|
break; |
271 |
|
case VT_HEM: |
272 |
+ |
pview.horiz = 2.*180./PI*asin( |
273 |
+ |
sin(PI/180./2.*ourview.horiz)/hmult ); |
274 |
+ |
pview.vert = 2.*180./PI*asin( |
275 |
+ |
sin(PI/180./2.*ourview.vert)/vmult ); |
276 |
+ |
break; |
277 |
|
default: |
278 |
|
fprintf(stderr, "%s: unknown view type '-vt%c'\n", |
279 |
|
progname, ourview.type); |
287 |
|
fflush(torp); /* assign piece to rpict */ |
288 |
|
putpiece(xorg, yorg); /* place piece in output */ |
289 |
|
if (verbose) { /* notify caller */ |
290 |
< |
strcat(buf, " done\n"); |
291 |
< |
writebuf(fileno(stdout), buf, strlen(buf)); |
290 |
> |
printf("%d %d done\n", xorg, yorg); |
291 |
> |
fflush(stdout); |
292 |
|
} |
293 |
|
} |
294 |
|
} |
300 |
|
int hr, vr; |
301 |
|
int y; |
302 |
|
|
303 |
+ |
if (xpos < 0 | ypos < 0 | xpos >= hmult | ypos >= vmult) { |
304 |
+ |
fprintf(stderr, "%s: requested piece (%d,%d) out of range\n", |
305 |
+ |
progname, xpos, ypos); |
306 |
+ |
exit(1); |
307 |
+ |
} |
308 |
|
getheader(fromrp, NULL); /* discard header info. */ |
309 |
|
if (fscnresolu(&hr, &vr, fromrp) < 0 || /* check resolution */ |
310 |
|
hr != hres || vr != vres) { |
311 |
< |
fprintf(stderr, "%s: resolution mismatch from rpict\n", |
312 |
< |
progname); |
311 |
> |
fprintf(stderr, "%s: resolution mismatch from %s\n", |
312 |
> |
progname, rpargv[0]); |
313 |
|
exit(1); |
314 |
|
} |
315 |
|
for (y = 0; y < vr; y++) { /* transfer scanlines */ |
316 |
|
if (freadcolrs(scanline, hr, fromrp) < 0) { |
317 |
< |
fprintf(stderr, "%s: read error from rpict\n", |
318 |
< |
progname); |
317 |
> |
fprintf(stderr, "%s: read error from %s\n", |
318 |
> |
progname, rpargv[0]); |
319 |
|
exit(1); |
320 |
|
} |
321 |
|
if ((y == 0 || hmult != 1) && lseek(outfd, |