--- ray/src/util/glareval.c 1991/04/03 15:20:35 1.8 +++ ray/src/util/glareval.c 1991/06/26 13:35:16 1.18 @@ -20,8 +20,8 @@ static char SCCSid[] = "$SunId$ LBL"; #define vfork fork #endif -#define MAXSBUF 409580 /* maximum total size of scanline buffer */ -#define HSIZE 227 /* size of scanline hash table */ +#define MAXSBUF 786432 /* maximum total size of scanline buffer */ +#define HSIZE 317 /* size of scanline hash table */ #define NRETIRE 16 /* number of scanlines to retire at once */ int rt_pid = -1; /* process id for rtrace */ @@ -49,7 +49,10 @@ static SCAN *hashtab[HSIZE]; /* scanline hash table */ static long ncall = 0L; /* number of calls to getpictscan */ static long nread = 0L; /* number of scanlines read */ +static long nrecl = 0L; /* number of scanlines reclaimed */ +static int wrongformat = 0; + SCAN *scanretire(); extern long ftell(); @@ -75,6 +78,7 @@ int y; if (sl->y == y) { /* reclaim */ sl->next = hashtab[hi]; hashtab[hi] = sl; + nrecl++; } return(sl); } @@ -138,13 +142,15 @@ pict_stats() /* print out picture read statistics */ { static long lastcall = 0L; /* ncall at last report */ static long lastread = 0L; /* nread at last report */ + static long lastrecl = 0L; /* nrecl at last report */ if (ncall == lastcall) return; - fprintf(stderr, "%s: %ld scanlines read in %ld calls\n", - progname, nread-lastread, ncall-lastcall); + fprintf(stderr, "%s: %ld scanlines read (%ld reclaimed) in %ld calls\n", + progname, nread-lastread, nrecl-lastrecl, ncall-lastcall); lastcall = ncall; lastread = nread; + lastrecl = nrecl; } #endif @@ -215,7 +221,7 @@ float *vb; #endif n = 0; for (vh = -hsize; vh <= hsize; vh++) { - if (compdir(dir, vh, vv) < 0) { /* off viewable region */ + if (compdir(dir, vh, vv) < 0) { /* not in view */ vb[vh+hsize] = -1.0; continue; } @@ -281,24 +287,29 @@ int np; getexpos(s) /* get exposure from header line */ char *s; { + char fmt[32]; + if (isexpos(s)) exposure *= exposval(s); + else if (isformat(s)) { + formatval(fmt, s); + wrongformat = strcmp(fmt, COLRFMT); + } } open_pict(fn) /* open picture file */ char *fn; { - register int i; - if ((pictfp = fopen(fn, "r")) == NULL) { fprintf("%s: cannot open\n", fn); exit(1); } exposure = 1.0; - getheader(pictfp, getexpos); - if (fgetresolu(&pxsiz, &pysiz, pictfp) != (YMAJOR|YDECR)) { - fprintf("%s: bad picture resolution\n", fn); + getheader(pictfp, getexpos, NULL); + if (wrongformat || + fgetresolu(&pxsiz, &pysiz, pictfp) != (YMAJOR|YDECR)) { + fprintf("%s: bad picture format\n", fn); exit(1); } initscans(); @@ -307,8 +318,6 @@ char *fn; close_pict() /* done with picture */ { - register int i; - if (pictfp == NULL) return; fclose(pictfp); @@ -333,7 +342,7 @@ char *av[]; dup2(p0[0], 0); close(p0[0]); } - if (p1[1] != 0) { /* connect p1 to stdout */ + if (p1[1] != 1) { /* connect p1 to stdout */ dup2(p1[1], 1); close(p1[1]); } @@ -410,43 +419,39 @@ SCAN * scanretire() /* retire old scanlines to free list */ { SCAN *sold[NRETIRE]; - SCAN head; int n; int h; register SCAN *sl; register int i; /* grab the NRETIRE oldest scanlines */ sold[n = 0] = NULL; - for (h = 0; h < HSIZE; h++) { - head.next = hashtab[h]; - sl = &head; - while (sl->next != NULL) { - for (i = n; i && sold[i-1]->lused > sl->next->lused; i--) - if (i == NRETIRE) { /* reallocate */ - register int oh; - oh = shash(sold[NRETIRE-1]->y); - sold[NRETIRE-1]->next = hashtab[oh]; - if (h == oh && sl == &head) - head.next = sl = sold[NRETIRE-1]; - else - hashtab[oh] = sold[NRETIRE-1]; - } else /* else bubble up */ + for (h = 0; h < HSIZE; h++) + for (sl = hashtab[h]; sl != NULL; sl = sl->next) { + for (i = n; i && sold[i-1]->lused > sl->lused; i--) + if (i < NRETIRE) sold[i] = sold[i-1]; if (i < NRETIRE) { - sold[i] = sl->next; - sl->next = sl->next->next; + sold[i] = sl; if (n < NRETIRE) /* grow list */ n++; - } else + } + } + /* put scanlines into free list */ + for (i = 0; i < n; i++) { + h = shash(sold[i]->y); + sl = hashtab[h]; + if (sl == sold[i]) + hashtab[h] = sl->next; + else { + while (sl->next != sold[i]) /* IS in list */ sl = sl->next; + sl->next = sold[i]->next; } - hashtab[h] = head.next; + if (i > 0) { /* save oldest as return value */ + sold[i]->next = freelist; + freelist = sold[i]; + } } - /* put scanlines into free list */ - for (i = 1; i < n; i++) { - sold[i]->next = freelist; - freelist = sold[i]; - } return(sold[0]); } @@ -472,7 +477,7 @@ initscans() /* initialize scanline buffers */ /* allocate scanline buffers */ scansize = sizeof(SCAN) + pxsiz*sizeof(COLR); #ifdef ALIGN - scansize = scansize+(sizeof(ALIGN)-1)) & ~(sizeof(ALIGN)-1); + scansize = scansize+(sizeof(ALIGN)-1) & ~(sizeof(ALIGN)-1); #endif i = MAXSBUF / scansize; /* compute number to allocate */ if (i > HSIZE)