20 |
|
#define vfork fork |
21 |
|
#endif |
22 |
|
|
23 |
< |
#define MAXSBUF 409580 /* maximum total size of scanline buffer */ |
24 |
< |
#define HSIZE 227 /* size of scanline hash table */ |
23 |
> |
#define MAXSBUF 524268 /* maximum total size of scanline buffer */ |
24 |
> |
#define HSIZE 317 /* size of scanline hash table */ |
25 |
|
#define NRETIRE 16 /* number of scanlines to retire at once */ |
26 |
|
|
27 |
|
int rt_pid = -1; /* process id for rtrace */ |
50 |
|
static long ncall = 0L; /* number of calls to getpictscan */ |
51 |
|
static long nread = 0L; /* number of scanlines read */ |
52 |
|
|
53 |
+ |
static int wrongformat = 0; |
54 |
+ |
|
55 |
|
SCAN *scanretire(); |
56 |
|
|
57 |
|
extern long ftell(); |
77 |
|
if (sl->y == y) { /* reclaim */ |
78 |
|
sl->next = hashtab[hi]; |
79 |
|
hashtab[hi] = sl; |
80 |
+ |
#ifdef DEBUG |
81 |
+ |
if (verbose) |
82 |
+ |
fprintf(stderr, |
83 |
+ |
"%s: scanline %d reclaimed\n", |
84 |
+ |
progname, y); |
85 |
+ |
#endif |
86 |
|
} |
87 |
|
return(sl); |
88 |
|
} |
179 |
|
|
180 |
|
|
181 |
|
double |
182 |
< |
getviewpix(vh, vv) /* compute single view pixel */ |
182 |
> |
getviewpix(vh, vv, se) /* compute single view pixel */ |
183 |
|
int vh, vv; |
184 |
+ |
SPANERR *se; |
185 |
|
{ |
186 |
|
FVECT dir; |
187 |
|
float rt_buf[6]; |
188 |
|
double res; |
189 |
|
|
190 |
< |
if (compdir(dir, vh, vv) < 0) |
190 |
> |
if (compdir(dir, vh, vv, se) < 0) |
191 |
|
return(-1.0); |
192 |
|
npixinvw++; |
193 |
|
if ((res = pict_val(dir)) >= 0.0) |
214 |
|
float rt_buf[6*MAXPIX]; /* rtrace send/receive buffer */ |
215 |
|
register int n; /* number of pixels in buffer */ |
216 |
|
short buf_vh[MAXPIX]; /* pixel positions */ |
217 |
+ |
SPANERR sperr; |
218 |
|
FVECT dir; |
219 |
|
register int vh; |
220 |
|
|
223 |
|
fprintf(stderr, "%s: computing view span at %d...\n", |
224 |
|
progname, vv); |
225 |
|
#endif |
226 |
+ |
setspanerr(&sperr, vv); |
227 |
|
n = 0; |
228 |
|
for (vh = -hsize; vh <= hsize; vh++) { |
229 |
< |
if (compdir(dir, vh, vv) < 0) { /* off viewable region */ |
229 |
> |
if (compdir(dir, vh, vv, &sperr) < 0) { /* not in view */ |
230 |
|
vb[vh+hsize] = -1.0; |
231 |
|
continue; |
232 |
|
} |
292 |
|
getexpos(s) /* get exposure from header line */ |
293 |
|
char *s; |
294 |
|
{ |
295 |
+ |
char fmt[32]; |
296 |
+ |
|
297 |
|
if (isexpos(s)) |
298 |
|
exposure *= exposval(s); |
299 |
+ |
else if (isformat(s)) { |
300 |
+ |
formatval(fmt, s); |
301 |
+ |
wrongformat = strcmp(fmt, COLRFMT); |
302 |
+ |
} |
303 |
|
} |
304 |
|
|
305 |
|
|
306 |
|
open_pict(fn) /* open picture file */ |
307 |
|
char *fn; |
308 |
|
{ |
292 |
– |
register int i; |
293 |
– |
|
309 |
|
if ((pictfp = fopen(fn, "r")) == NULL) { |
310 |
|
fprintf("%s: cannot open\n", fn); |
311 |
|
exit(1); |
312 |
|
} |
313 |
|
exposure = 1.0; |
314 |
< |
getheader(pictfp, getexpos); |
315 |
< |
if (fgetresolu(&pxsiz, &pysiz, pictfp) != (YMAJOR|YDECR)) { |
316 |
< |
fprintf("%s: bad picture resolution\n", fn); |
314 |
> |
getheader(pictfp, getexpos, NULL); |
315 |
> |
if (wrongformat || |
316 |
> |
fgetresolu(&pxsiz, &pysiz, pictfp) != (YMAJOR|YDECR)) { |
317 |
> |
fprintf("%s: bad picture format\n", fn); |
318 |
|
exit(1); |
319 |
|
} |
320 |
|
initscans(); |
323 |
|
|
324 |
|
close_pict() /* done with picture */ |
325 |
|
{ |
310 |
– |
register int i; |
311 |
– |
|
326 |
|
if (pictfp == NULL) |
327 |
|
return; |
328 |
|
fclose(pictfp); |
424 |
|
scanretire() /* retire old scanlines to free list */ |
425 |
|
{ |
426 |
|
SCAN *sold[NRETIRE]; |
413 |
– |
SCAN head; |
427 |
|
int n; |
428 |
|
int h; |
429 |
|
register SCAN *sl; |
430 |
|
register int i; |
431 |
|
/* grab the NRETIRE oldest scanlines */ |
432 |
|
sold[n = 0] = NULL; |
433 |
< |
for (h = 0; h < HSIZE; h++) { |
434 |
< |
head.next = hashtab[h]; |
435 |
< |
sl = &head; |
436 |
< |
while (sl->next != NULL) { |
424 |
< |
for (i = n; i && sold[i-1]->lused > sl->next->lused; i--) |
425 |
< |
if (i == NRETIRE) { /* reallocate */ |
426 |
< |
register int oh; |
427 |
< |
oh = shash(sold[NRETIRE-1]->y); |
428 |
< |
sold[NRETIRE-1]->next = hashtab[oh]; |
429 |
< |
if (h == oh && sl == &head) |
430 |
< |
head.next = sl = sold[NRETIRE-1]; |
431 |
< |
else |
432 |
< |
hashtab[oh] = sold[NRETIRE-1]; |
433 |
< |
} else /* else bubble up */ |
433 |
> |
for (h = 0; h < HSIZE; h++) |
434 |
> |
for (sl = hashtab[h]; sl != NULL; sl = sl->next) { |
435 |
> |
for (i = n; i && sold[i-1]->lused > sl->lused; i--) |
436 |
> |
if (i < NRETIRE) |
437 |
|
sold[i] = sold[i-1]; |
438 |
|
if (i < NRETIRE) { |
439 |
< |
sold[i] = sl->next; |
437 |
< |
sl->next = sl->next->next; |
439 |
> |
sold[i] = sl; |
440 |
|
if (n < NRETIRE) /* grow list */ |
441 |
|
n++; |
442 |
< |
} else |
441 |
< |
sl = sl->next; |
442 |
> |
} |
443 |
|
} |
443 |
– |
hashtab[h] = head.next; |
444 |
– |
} |
444 |
|
/* put scanlines into free list */ |
445 |
< |
for (i = 1; i < n; i++) { |
446 |
< |
sold[i]->next = freelist; |
447 |
< |
freelist = sold[i]; |
445 |
> |
for (i = 0; i < n; i++) { |
446 |
> |
h = shash(sold[i]->y); |
447 |
> |
sl = hashtab[h]; |
448 |
> |
if (sl == sold[i]) |
449 |
> |
hashtab[h] = sl->next; |
450 |
> |
else { |
451 |
> |
while (sl->next != sold[i]) /* IS in list */ |
452 |
> |
sl = sl->next; |
453 |
> |
sl->next = sold[i]->next; |
454 |
> |
} |
455 |
> |
if (i > 0) { /* save oldest as return value */ |
456 |
> |
sold[i]->next = freelist; |
457 |
> |
freelist = sold[i]; |
458 |
> |
} |
459 |
|
} |
460 |
|
return(sold[0]); |
461 |
|
} |