20 |
|
#define vfork fork |
21 |
|
#endif |
22 |
|
|
23 |
< |
#define MAXSBUF 1023980 /* maximum total size of scanline buffer */ |
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 |
|
|
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 |
|
} |
223 |
|
#endif |
224 |
|
n = 0; |
225 |
|
for (vh = -hsize; vh <= hsize; vh++) { |
226 |
< |
if (compdir(dir, vh, vv) < 0) { /* off viewable region */ |
226 |
> |
if (compdir(dir, vh, vv) < 0) { /* not in view */ |
227 |
|
vb[vh+hsize] = -1.0; |
228 |
|
continue; |
229 |
|
} |
289 |
|
getexpos(s) /* get exposure from header line */ |
290 |
|
char *s; |
291 |
|
{ |
292 |
+ |
char fmt[32]; |
293 |
+ |
|
294 |
|
if (isexpos(s)) |
295 |
|
exposure *= exposval(s); |
296 |
+ |
else if (isformat(s)) { |
297 |
+ |
formatval(fmt, s); |
298 |
+ |
wrongformat = strcmp(fmt, COLRFMT); |
299 |
+ |
} |
300 |
|
} |
301 |
|
|
302 |
|
|
303 |
|
open_pict(fn) /* open picture file */ |
304 |
|
char *fn; |
305 |
|
{ |
292 |
– |
register int i; |
293 |
– |
|
306 |
|
if ((pictfp = fopen(fn, "r")) == NULL) { |
307 |
|
fprintf("%s: cannot open\n", fn); |
308 |
|
exit(1); |
309 |
|
} |
310 |
|
exposure = 1.0; |
311 |
< |
getheader(pictfp, getexpos); |
312 |
< |
if (fgetresolu(&pxsiz, &pysiz, pictfp) != (YMAJOR|YDECR)) { |
313 |
< |
fprintf("%s: bad picture resolution\n", fn); |
311 |
> |
getheader(pictfp, getexpos, NULL); |
312 |
> |
if (wrongformat || |
313 |
> |
fgetresolu(&pxsiz, &pysiz, pictfp) != (YMAJOR|YDECR)) { |
314 |
> |
fprintf("%s: bad picture format\n", fn); |
315 |
|
exit(1); |
316 |
|
} |
317 |
|
initscans(); |
320 |
|
|
321 |
|
close_pict() /* done with picture */ |
322 |
|
{ |
310 |
– |
register int i; |
311 |
– |
|
323 |
|
if (pictfp == NULL) |
324 |
|
return; |
325 |
|
fclose(pictfp); |
421 |
|
scanretire() /* retire old scanlines to free list */ |
422 |
|
{ |
423 |
|
SCAN *sold[NRETIRE]; |
413 |
– |
SCAN head; |
424 |
|
int n; |
425 |
|
int h; |
426 |
|
register SCAN *sl; |
427 |
|
register int i; |
428 |
|
/* grab the NRETIRE oldest scanlines */ |
429 |
|
sold[n = 0] = NULL; |
430 |
< |
for (h = 0; h < HSIZE; h++) { |
431 |
< |
head.next = hashtab[h]; |
432 |
< |
sl = &head; |
433 |
< |
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 */ |
430 |
> |
for (h = 0; h < HSIZE; h++) |
431 |
> |
for (sl = hashtab[h]; sl != NULL; sl = sl->next) { |
432 |
> |
for (i = n; i && sold[i-1]->lused > sl->lused; i--) |
433 |
> |
if (i < NRETIRE) |
434 |
|
sold[i] = sold[i-1]; |
435 |
|
if (i < NRETIRE) { |
436 |
< |
sold[i] = sl->next; |
439 |
< |
sl->next = sl->next->next; |
436 |
> |
sold[i] = sl; |
437 |
|
if (n < NRETIRE) /* grow list */ |
438 |
|
n++; |
439 |
< |
} else |
443 |
< |
sl = sl->next; |
439 |
> |
} |
440 |
|
} |
445 |
– |
hashtab[h] = head.next; |
446 |
– |
} |
441 |
|
/* put scanlines into free list */ |
442 |
< |
for (i = 1; i < n; i++) { |
443 |
< |
sold[i]->next = freelist; |
444 |
< |
freelist = sold[i]; |
442 |
> |
for (i = 0; i < n; i++) { |
443 |
> |
h = shash(sold[i]->y); |
444 |
> |
sl = hashtab[h]; |
445 |
> |
if (sl == sold[i]) |
446 |
> |
hashtab[h] = sl->next; |
447 |
> |
else { |
448 |
> |
while (sl->next != sold[i]) /* IS in list */ |
449 |
> |
sl = sl->next; |
450 |
> |
sl->next = sold[i]->next; |
451 |
> |
} |
452 |
> |
if (i > 0) { /* save oldest as return value */ |
453 |
> |
sold[i]->next = freelist; |
454 |
> |
freelist = sold[i]; |
455 |
> |
} |
456 |
|
} |
457 |
|
return(sold[0]); |
458 |
|
} |