--- ray/src/util/glareval.c 1991/11/11 15:09:42 1.21 +++ ray/src/util/glareval.c 2003/07/03 22:41:45 2.10 @@ -1,15 +1,18 @@ -/* Copyright (c) 1991 Regents of the University of California */ - #ifndef lint -static char SCCSid[] = "$SunId$ LBL"; +static const char RCSid[] = "$Id: glareval.c,v 2.10 2003/07/03 22:41:45 schorsch Exp $"; #endif - /* * Compute pixels for glare calculation */ +#include "copyright.h" + +#include +#include + +#include "rtprocess.h" /* Windows: must come first because of conflicts */ #include "glare.h" -#include "resolu.h" + /* maximum rtrace buffer size */ #define MAXPIX (4096/(6*sizeof(float))) @@ -17,7 +20,7 @@ static char SCCSid[] = "$SunId$ LBL"; #define HSIZE 317 /* size of scanline hash table */ #define NRETIRE 16 /* number of scanlines to retire at once */ -int rt_pd[3] = {-1,-1,-1}; /* process id & descriptors for rtrace */ +static SUBPROC rt_pd = SP_INACTIVE; /* process id & descriptors for rtrace */ FILE *pictfp = NULL; /* picture file pointer */ double exposure; /* picture exposure */ @@ -41,6 +44,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 */ @@ -184,7 +189,7 @@ int vh, vv; npixinvw++; if ((res = pict_val(dir)) >= 0.0) return(res); - if (rt_pd[0] == -1) { + if (rt_pd.r == -1) { npixmiss++; return(-1.0); } @@ -223,7 +228,7 @@ float *vb; npixinvw++; if ((vb[vh+hsize] = pict_val(dir)) >= 0.0) continue; - if (rt_pd[0] == -1) { /* missing information */ + if (rt_pd.r == -1) { /* missing information */ npixmiss++; continue; } @@ -262,9 +267,9 @@ int np; fprintf(stderr, "%s: sending %d samples to rtrace...\n", 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) { + memset(pb+6*np, '\0', 6*sizeof(float)); + if (process(&rt_pd, (char *)pb, (char *)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); @@ -272,6 +277,7 @@ int np; } +int getexpos(s) /* get exposure from header line */ char *s; { @@ -283,6 +289,7 @@ char *s; formatval(fmt, s); wrongformat = strcmp(fmt, COLRFMT); } + return(0); } @@ -290,7 +297,7 @@ 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; @@ -318,7 +325,7 @@ char *av[]; { int rval; - rval = open_process(rt_pd, av); + rval = open_process(&rt_pd, av); if (rval < 0) { perror(progname); exit(1); @@ -338,13 +345,13 @@ done_rtrace() /* wait for rtrace to finish */ { int status; - status = close_process(rt_pd); + status = close_process(&rt_pd); if (status > 0) { fprintf(stderr, "%s: bad status (%d) from rtrace\n", progname, status); exit(1); } - rt_pd[0] = -1; + rt_pd.r = -1; } @@ -398,7 +405,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--) @@ -409,13 +416,14 @@ initscans() /* initialize scanline buffers */ hashtab[i] = NULL; /* allocate scanline buffers */ scansize = sizeof(SCAN) + pxsiz*sizeof(COLR); -#ifdef ALIGN - scansize = scansize+(sizeof(ALIGN)-1) & ~(sizeof(ALIGN)-1); +#ifdef ALIGNT + scansize = scansize+(sizeof(ALIGNT)-1) & ~(sizeof(ALIGNT)-1); #endif 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; @@ -432,6 +440,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)); }