ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/util/glareval.c
(Generate patch)

Comparing ray/src/util/glareval.c (file contents):
Revision 1.20 by greg, Tue Jul 30 12:56:36 1991 UTC vs.
Revision 2.8 by greg, Fri Jun 27 06:53:23 2003 UTC

# Line 1 | Line 1
1 /* Copyright (c) 1991 Regents of the University of California */
2
1   #ifndef lint
2 < static char SCCSid[] = "$SunId$ LBL";
2 > static const char       RCSid[] = "$Id$";
3   #endif
6
4   /*
5   * Compute pixels for glare calculation
6   */
7  
8 + #include "rtprocess.h" /* Windows: must come first because of conflicts */
9   #include "glare.h"
10 +
11                                          /* maximum rtrace buffer size */
12   #define MAXPIX          (4096/(6*sizeof(float)))
13  
# Line 16 | Line 15 | static char SCCSid[] = "$SunId$ LBL";
15   #define HSIZE           317     /* size of scanline hash table */
16   #define NRETIRE         16      /* number of scanlines to retire at once */
17  
18 < int     rt_pd[3] = {-1,-1,-1};  /* process id & descriptors for rtrace */
18 > static SUBPROC  rt_pd = SP_INACTIVE; /* process id & descriptors for rtrace */
19  
20   FILE    *pictfp = NULL;         /* picture file pointer */
21   double  exposure;               /* picture exposure */
# Line 40 | Line 39 | static int     maxpix;         /* maximum number of pixels to buf
39   static SCAN     *freelist;              /* scanline free list */
40   static SCAN     *hashtab[HSIZE];        /* scanline hash table */
41  
42 + static long     scanbufsiz;             /* size of allocated scanline buffer */
43 +
44   static long     ncall = 0L;     /* number of calls to getpictscan */
45   static long     nread = 0L;     /* number of scanlines read */
46   static long     nrecl = 0L;     /* number of scanlines reclaimed */
# Line 153 | Line 154 | pict_val(vd)                   /* find picture value for view directio
154   FVECT   vd;
155   {
156          FVECT   pp;
157 <        double  vpx, vpy, vpz;
157 >        FVECT   ip;
158          COLOR   res;
159  
160          if (pictfp == NULL)
# Line 161 | Line 162 | FVECT  vd;
162          pp[0] = pictview.vp[0] + vd[0];
163          pp[1] = pictview.vp[1] + vd[1];
164          pp[2] = pictview.vp[2] + vd[2];
165 <        viewpixel(&vpx, &vpy, &vpz, &pictview, pp);
166 <        if (vpz <= FTINY || vpx < 0. || vpx >= 1. || vpy < 0. || vpy >= 1.)
165 >        viewloc(ip, &pictview, pp);
166 >        if (ip[2] <= FTINY || ip[0] < 0. || ip[0] >= 1. ||
167 >                        ip[1] < 0. || ip[1] >= 1.)
168                  return(-1.0);
169 <        colr_color(res, getpictscan((int)(vpy*pysiz))[(int)(vpx*pxsiz)]);
169 >        colr_color(res, getpictscan((int)(ip[1]*pysiz))[(int)(ip[0]*pxsiz)]);
170          return(luminance(res)/exposure);
171   }
172  
# Line 182 | Line 184 | int    vh, vv;
184          npixinvw++;
185          if ((res = pict_val(dir)) >= 0.0)
186                  return(res);
187 <        if (rt_pd[0] == -1) {
187 >        if (rt_pd.r == -1) {
188                  npixmiss++;
189                  return(-1.0);
190          }
# Line 221 | Line 223 | float  *vb;
223                  npixinvw++;
224                  if ((vb[vh+hsize] = pict_val(dir)) >= 0.0)
225                          continue;
226 <                if (rt_pd[0] == -1) {           /* missing information */
226 >                if (rt_pd.r == -1) {            /* missing information */
227                          npixmiss++;
228                          continue;
229                  }
# Line 261 | Line 263 | int    np;
263                                  progname, np);
264   #endif
265          bzero(pb+6*np, 6*sizeof(float));
266 <        if (process(rt_pd, pb, pb, 3*sizeof(float)*np,
267 <                        6*sizeof(float)*(np+1)) < 3*sizeof(float)*np) {
266 >        if (process(&rt_pd, (char *)pb, (char *)pb, 3*sizeof(float)*(np+1),
267 >                        6*sizeof(float)*(np+1)) < 3*sizeof(float)*(np+1)) {
268                  fprintf(stderr, "%s: rtrace communication error\n",
269                                  progname);
270                  exit(1);
# Line 270 | Line 272 | int    np;
272   }
273  
274  
275 + int
276   getexpos(s)                     /* get exposure from header line */
277   char    *s;
278   {
# Line 281 | Line 284 | char   *s;
284                  formatval(fmt, s);
285                  wrongformat = strcmp(fmt, COLRFMT);
286          }
287 +        return(0);
288   }
289  
290  
# Line 288 | Line 292 | open_pict(fn)                  /* open picture file */
292   char    *fn;
293   {
294          if ((pictfp = fopen(fn, "r")) == NULL) {
295 <                fprintf("%s: cannot open\n", fn);
295 >                fprintf(stderr, "%s: cannot open\n", fn);
296                  exit(1);
297          }
298          exposure = 1.0;
299          getheader(pictfp, getexpos, NULL);
300 <        if (wrongformat ||
301 <                        fgetresolu(&pxsiz, &pysiz, pictfp) != (YMAJOR|YDECR)) {
298 <                fprintf("%s: bad picture format\n", fn);
300 >        if (wrongformat || !fscnresolu(&pxsiz, &pysiz, pictfp)) {
301 >                fprintf(stderr, "%s: incompatible picture format\n", fn);
302                  exit(1);
303          }
304          initscans();
# Line 317 | Line 320 | char   *av[];
320   {
321          int     rval;
322  
323 <        rval = open_process(rt_pd, av);
323 >        rval = open_process(&rt_pd, av);
324          if (rval < 0) {
325                  perror(progname);
326                  exit(1);
# Line 337 | Line 340 | done_rtrace()                  /* wait for rtrace to finish */
340   {
341          int     status;
342  
343 <        status = close_process(rt_pd);
343 >        status = close_process(&rt_pd);
344          if (status > 0) {
345                  fprintf(stderr, "%s: bad status (%d) from rtrace\n",
346                                  progname, status);
347                  exit(1);
348          }
349 <        rt_pd[0] = -1;
349 >        rt_pd.r = -1;
350   }
351  
352  
# Line 397 | Line 400 | initscans()                            /* initialize scanline buffers */
400          register SCAN   *ptr;
401          register int    i;
402                                          /* initialize positions */
403 <        scanpos = (long *)malloc(pysiz*sizeof(long));
403 >        scanpos = (long *)bmalloc(pysiz*sizeof(long));
404          if (scanpos == NULL)
405                  memerr("scanline positions");
406          for (i = pysiz-1; i >= 0; i--)
# Line 408 | Line 411 | initscans()                            /* initialize scanline buffers */
411                  hashtab[i] = NULL;
412                                          /* allocate scanline buffers */
413          scansize = sizeof(SCAN) + pxsiz*sizeof(COLR);
414 < #ifdef ALIGN
415 <        scansize = scansize+(sizeof(ALIGN)-1) & ~(sizeof(ALIGN)-1);
414 > #ifdef ALIGNT
415 >        scansize = scansize+(sizeof(ALIGNT)-1) & ~(sizeof(ALIGNT)-1);
416   #endif
417          i = MAXSBUF / scansize;         /* compute number to allocate */
418          if (i > HSIZE)
419                  i = HSIZE;
420 <        scan_buf = malloc(i*scansize);  /* get in one big chunk */
420 >        scanbufsiz = i*scansize;
421 >        scan_buf = bmalloc(scanbufsiz); /* get in one big chunk */
422          if (scan_buf == NULL)
423                  memerr("scanline buffers");
424          ptr = (SCAN *)scan_buf;
# Line 431 | Line 435 | initscans()                            /* initialize scanline buffers */
435  
436   donescans()                             /* free up scanlines */
437   {
438 <        free(scan_buf);
439 <        free((char *)scanpos);
438 >        bfree(scan_buf, scanbufsiz);
439 >        bfree((char *)scanpos, pysiz*sizeof(long));
440   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines