--- ray/src/util/glareval.c 1991/07/30 12:56:36 1.20 +++ ray/src/util/glareval.c 1998/10/27 08:47:18 2.5 @@ -9,6 +9,7 @@ static char SCCSid[] = "$SunId$ LBL"; */ #include "glare.h" +#include "resolu.h" /* maximum rtrace buffer size */ #define MAXPIX (4096/(6*sizeof(float))) @@ -40,6 +41,8 @@ static int maxpix; /* maximum number of pixels to buf static SCAN *freelist; /* scanline free list */ static SCAN *hashtab[HSIZE]; /* scanline hash table */ +static long scanbufsiz; /* size of allocated scanline buffer */ + 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 */ @@ -153,7 +156,7 @@ pict_val(vd) /* find picture value for view directio FVECT vd; { FVECT pp; - double vpx, vpy, vpz; + FVECT ip; COLOR res; if (pictfp == NULL) @@ -161,10 +164,11 @@ FVECT vd; pp[0] = pictview.vp[0] + vd[0]; pp[1] = pictview.vp[1] + vd[1]; pp[2] = pictview.vp[2] + vd[2]; - viewpixel(&vpx, &vpy, &vpz, &pictview, pp); - if (vpz <= FTINY || vpx < 0. || vpx >= 1. || vpy < 0. || vpy >= 1.) + viewloc(ip, &pictview, pp); + if (ip[2] <= FTINY || ip[0] < 0. || ip[0] >= 1. || + ip[1] < 0. || ip[1] >= 1.) return(-1.0); - colr_color(res, getpictscan((int)(vpy*pysiz))[(int)(vpx*pxsiz)]); + colr_color(res, getpictscan((int)(ip[1]*pysiz))[(int)(ip[0]*pxsiz)]); return(luminance(res)/exposure); } @@ -261,8 +265,8 @@ int np; progname, np); #endif bzero(pb+6*np, 6*sizeof(float)); - if (process(rt_pd, pb, pb, 3*sizeof(float)*np, - 6*sizeof(float)*(np+1)) < 3*sizeof(float)*np) { + if (process(rt_pd, pb, pb, 3*sizeof(float)*(np+1), + 6*sizeof(float)*(np+1)) < 3*sizeof(float)*(np+1)) { fprintf(stderr, "%s: rtrace communication error\n", progname); exit(1); @@ -270,6 +274,7 @@ int np; } +int getexpos(s) /* get exposure from header line */ char *s; { @@ -281,6 +286,7 @@ char *s; formatval(fmt, s); wrongformat = strcmp(fmt, COLRFMT); } + return(0); } @@ -288,14 +294,13 @@ open_pict(fn) /* open picture file */ char *fn; { if ((pictfp = fopen(fn, "r")) == NULL) { - fprintf("%s: cannot open\n", fn); + fprintf(stderr, "%s: cannot open\n", fn); exit(1); } exposure = 1.0; getheader(pictfp, getexpos, NULL); - if (wrongformat || - fgetresolu(&pxsiz, &pysiz, pictfp) != (YMAJOR|YDECR)) { - fprintf("%s: bad picture format\n", fn); + if (wrongformat || !fscnresolu(&pxsiz, &pysiz, pictfp)) { + fprintf(stderr, "%s: incompatible picture format\n", fn); exit(1); } initscans(); @@ -397,7 +402,7 @@ initscans() /* initialize scanline buffers */ register SCAN *ptr; register int i; /* initialize positions */ - scanpos = (long *)malloc(pysiz*sizeof(long)); + scanpos = (long *)bmalloc(pysiz*sizeof(long)); if (scanpos == NULL) memerr("scanline positions"); for (i = pysiz-1; i >= 0; i--) @@ -414,7 +419,8 @@ initscans() /* initialize scanline buffers */ i = MAXSBUF / scansize; /* compute number to allocate */ if (i > HSIZE) i = HSIZE; - scan_buf = malloc(i*scansize); /* get in one big chunk */ + scanbufsiz = i*scansize; + scan_buf = bmalloc(scanbufsiz); /* get in one big chunk */ if (scan_buf == NULL) memerr("scanline buffers"); ptr = (SCAN *)scan_buf; @@ -431,6 +437,6 @@ initscans() /* initialize scanline buffers */ donescans() /* free up scanlines */ { - free(scan_buf); - free((char *)scanpos); + bfree(scan_buf, scanbufsiz); + bfree((char *)scanpos, pysiz*sizeof(long)); }