20 |
|
#define vfork fork |
21 |
|
#endif |
22 |
|
|
23 |
< |
#define MAXSBUF 1023980 /* maximum total size of scanline buffer */ |
23 |
> |
#define MAXSBUF 786432 /* 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 |
|
|
49 |
|
|
50 |
|
static long ncall = 0L; /* number of calls to getpictscan */ |
51 |
|
static long nread = 0L; /* number of scanlines read */ |
52 |
+ |
static long nrecl = 0L; /* number of scanlines reclaimed */ |
53 |
|
|
54 |
+ |
static int wrongformat = 0; |
55 |
+ |
|
56 |
|
SCAN *scanretire(); |
57 |
|
|
58 |
|
extern long ftell(); |
78 |
|
if (sl->y == y) { /* reclaim */ |
79 |
|
sl->next = hashtab[hi]; |
80 |
|
hashtab[hi] = sl; |
81 |
+ |
nrecl++; |
82 |
|
} |
83 |
|
return(sl); |
84 |
|
} |
142 |
|
{ |
143 |
|
static long lastcall = 0L; /* ncall at last report */ |
144 |
|
static long lastread = 0L; /* nread at last report */ |
145 |
+ |
static long lastrecl = 0L; /* nrecl at last report */ |
146 |
|
|
147 |
|
if (ncall == lastcall) |
148 |
|
return; |
149 |
< |
fprintf(stderr, "%s: %ld scanlines read in %ld calls\n", |
150 |
< |
progname, nread-lastread, ncall-lastcall); |
149 |
> |
fprintf(stderr, "%s: %ld scanlines read (%ld reclaimed) in %ld calls\n", |
150 |
> |
progname, nread-lastread, nrecl-lastrecl, ncall-lastcall); |
151 |
|
lastcall = ncall; |
152 |
|
lastread = nread; |
153 |
+ |
lastrecl = nrecl; |
154 |
|
} |
155 |
|
#endif |
156 |
|
|
221 |
|
#endif |
222 |
|
n = 0; |
223 |
|
for (vh = -hsize; vh <= hsize; vh++) { |
224 |
< |
if (compdir(dir, vh, vv) < 0) { /* off viewable region */ |
224 |
> |
if (compdir(dir, vh, vv) < 0) { /* not in view */ |
225 |
|
vb[vh+hsize] = -1.0; |
226 |
|
continue; |
227 |
|
} |
287 |
|
getexpos(s) /* get exposure from header line */ |
288 |
|
char *s; |
289 |
|
{ |
290 |
+ |
char fmt[32]; |
291 |
+ |
|
292 |
|
if (isexpos(s)) |
293 |
|
exposure *= exposval(s); |
294 |
+ |
else if (isformat(s)) { |
295 |
+ |
formatval(fmt, s); |
296 |
+ |
wrongformat = strcmp(fmt, COLRFMT); |
297 |
+ |
} |
298 |
|
} |
299 |
|
|
300 |
|
|
301 |
|
open_pict(fn) /* open picture file */ |
302 |
|
char *fn; |
303 |
|
{ |
292 |
– |
register int i; |
293 |
– |
|
304 |
|
if ((pictfp = fopen(fn, "r")) == NULL) { |
305 |
|
fprintf("%s: cannot open\n", fn); |
306 |
|
exit(1); |
307 |
|
} |
308 |
|
exposure = 1.0; |
309 |
< |
getheader(pictfp, getexpos); |
310 |
< |
if (fgetresolu(&pxsiz, &pysiz, pictfp) != (YMAJOR|YDECR)) { |
311 |
< |
fprintf("%s: bad picture resolution\n", fn); |
309 |
> |
getheader(pictfp, getexpos, NULL); |
310 |
> |
if (wrongformat || |
311 |
> |
fgetresolu(&pxsiz, &pysiz, pictfp) != (YMAJOR|YDECR)) { |
312 |
> |
fprintf("%s: bad picture format\n", fn); |
313 |
|
exit(1); |
314 |
|
} |
315 |
|
initscans(); |
318 |
|
|
319 |
|
close_pict() /* done with picture */ |
320 |
|
{ |
310 |
– |
register int i; |
311 |
– |
|
321 |
|
if (pictfp == NULL) |
322 |
|
return; |
323 |
|
fclose(pictfp); |
419 |
|
scanretire() /* retire old scanlines to free list */ |
420 |
|
{ |
421 |
|
SCAN *sold[NRETIRE]; |
413 |
– |
SCAN head; |
422 |
|
int n; |
423 |
|
int h; |
424 |
|
register SCAN *sl; |
425 |
|
register int i; |
426 |
|
/* grab the NRETIRE oldest scanlines */ |
427 |
|
sold[n = 0] = NULL; |
428 |
< |
for (h = 0; h < HSIZE; h++) { |
429 |
< |
head.next = hashtab[h]; |
430 |
< |
sl = &head; |
431 |
< |
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) { |
430 |
< |
head.next = sold[NRETIRE-1]; |
431 |
< |
if (sl == &head) |
432 |
< |
sl = head.next; |
433 |
< |
} else |
434 |
< |
hashtab[oh] = sold[NRETIRE-1]; |
435 |
< |
} else /* else bubble up */ |
428 |
> |
for (h = 0; h < HSIZE; h++) |
429 |
> |
for (sl = hashtab[h]; sl != NULL; sl = sl->next) { |
430 |
> |
for (i = n; i && sold[i-1]->lused > sl->lused; i--) |
431 |
> |
if (i < NRETIRE) |
432 |
|
sold[i] = sold[i-1]; |
433 |
|
if (i < NRETIRE) { |
434 |
< |
sold[i] = sl->next; |
439 |
< |
sl->next = sl->next->next; |
434 |
> |
sold[i] = sl; |
435 |
|
if (n < NRETIRE) /* grow list */ |
436 |
|
n++; |
437 |
< |
} else |
443 |
< |
sl = sl->next; |
437 |
> |
} |
438 |
|
} |
445 |
– |
hashtab[h] = head.next; |
446 |
– |
} |
439 |
|
/* put scanlines into free list */ |
440 |
< |
for (i = 1; i < n; i++) { |
441 |
< |
sold[i]->next = freelist; |
442 |
< |
freelist = sold[i]; |
440 |
> |
for (i = 0; i < n; i++) { |
441 |
> |
h = shash(sold[i]->y); |
442 |
> |
sl = hashtab[h]; |
443 |
> |
if (sl == sold[i]) |
444 |
> |
hashtab[h] = sl->next; |
445 |
> |
else { |
446 |
> |
while (sl->next != sold[i]) /* IS in list */ |
447 |
> |
sl = sl->next; |
448 |
> |
sl->next = sold[i]->next; |
449 |
> |
} |
450 |
> |
if (i > 0) { /* save oldest as return value */ |
451 |
> |
sold[i]->next = freelist; |
452 |
> |
freelist = sold[i]; |
453 |
> |
} |
454 |
|
} |
455 |
|
return(sold[0]); |
456 |
|
} |