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 2.5 by gwlarson, Tue Oct 27 08:47:18 1998 UTC vs.
Revision 2.14 by greg, Wed Oct 10 21:41:02 2012 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 "copyright.h"
9 +
10 + #include <stdlib.h>
11 + #include <string.h>
12 +
13 + #include "platform.h"
14 + #include "rtprocess.h" /* Windows: must come first because of conflicts */
15   #include "glare.h"
16 < #include "resolu.h"
16 >
17                                          /* maximum rtrace buffer size */
18   #define MAXPIX          (4096/(6*sizeof(float)))
19  
# Line 17 | Line 21 | static char SCCSid[] = "$SunId$ LBL";
21   #define HSIZE           317     /* size of scanline hash table */
22   #define NRETIRE         16      /* number of scanlines to retire at once */
23  
24 < int     rt_pd[3] = {-1,-1,-1};  /* process id & descriptors for rtrace */
24 > static SUBPROC  rt_pd = SP_INACTIVE; /* process id & descriptors for rtrace */
25  
26   FILE    *pictfp = NULL;         /* picture file pointer */
27   double  exposure;               /* picture exposure */
# Line 49 | Line 53 | static long    nrecl = 0L;     /* number of scanlines reclaim
53  
54   static int      wrongformat = 0;
55  
56 < SCAN    *scanretire();
56 > static SCAN * claimscan(int     y);
57 > static COLR * getpictscan(int   y);
58 > static double pict_val(FVECT    vd);
59 > static void rt_compute(float    *pb, int        np);
60 > static gethfunc getexpos;
61 > static SCAN * scanretire(void);
62 > static void initscans(void);
63 > static void donescans(void);
64  
54 extern long     ftell();
65  
66 <
67 < SCAN *
68 < claimscan(y)                    /* claim scanline from buffers */
69 < int     y;
66 > static SCAN *
67 > claimscan(                      /* claim scanline from buffers */
68 >        int     y
69 > )
70   {
71          int     hi = shash(y);
72          SCAN    *slast;
# Line 82 | Line 92 | int    y;
92   }
93  
94  
95 < COLR *
96 < getpictscan(y)                  /* get picture scanline */
97 < int     y;
95 > static COLR *
96 > getpictscan(                    /* get picture scanline */
97 >        int     y
98 > )
99   {
100          register SCAN   *sl;
101          register int    i;
# Line 134 | Line 145 | seekerr:
145  
146  
147   #ifdef DEBUG
148 < pict_stats()                    /* print out picture read statistics */
148 > void
149 > pict_stats(void)                        /* print out picture read statistics */
150   {
151          static long     lastcall = 0L;  /* ncall at last report */
152          static long     lastread = 0L;  /* nread at last report */
# Line 151 | Line 163 | pict_stats()                   /* print out picture read statistics */
163   #endif
164  
165  
166 < double
167 < pict_val(vd)                    /* find picture value for view direction */
168 < FVECT   vd;
166 > static double
167 > pict_val(                       /* find picture value for view direction */
168 >        FVECT   vd
169 > )
170   {
171          FVECT   pp;
172          FVECT   ip;
# Line 173 | Line 186 | FVECT  vd;
186   }
187  
188  
189 < double
190 < getviewpix(vh, vv)              /* compute single view pixel */
191 < int     vh, vv;
189 > extern double
190 > getviewpix(             /* compute single view pixel */
191 >        int     vh,
192 >        int     vv
193 > )
194   {
195          FVECT   dir;
196          float   rt_buf[12];
# Line 186 | Line 201 | int    vh, vv;
201          npixinvw++;
202          if ((res = pict_val(dir)) >= 0.0)
203                  return(res);
204 <        if (rt_pd[0] == -1) {
204 >        if (rt_pd.r == -1) {
205                  npixmiss++;
206                  return(-1.0);
207          }
# Line 201 | Line 216 | int    vh, vv;
216   }
217  
218  
219 < getviewspan(vv, vb)             /* compute a span of view pixels */
220 < int     vv;
221 < float   *vb;
219 > extern void
220 > getviewspan(            /* compute a span of view pixels */
221 >        int     vv,
222 >        float   *vb
223 > )
224   {
225          float   rt_buf[6*MAXPIX];       /* rtrace send/receive buffer */
226          register int    n;              /* number of pixels in buffer */
# Line 225 | Line 242 | float  *vb;
242                  npixinvw++;
243                  if ((vb[vh+hsize] = pict_val(dir)) >= 0.0)
244                          continue;
245 <                if (rt_pd[0] == -1) {           /* missing information */
245 >                if (rt_pd.r == -1) {            /* missing information */
246                          npixmiss++;
247                          continue;
248                  }
249                                                  /* send to rtrace */
250                  if (n >= maxpix) {                      /* flush */
251                          rt_compute(rt_buf, n);
252 <                        while (n-- > 0)
252 >                        while (n > 0) {
253 >                                --n;
254                                  vb[buf_vh[n]+hsize] = luminance(rt_buf+3*n);
255 +                        }
256                  }
257                  rt_buf[6*n] = ourview.vp[0];
258                  rt_buf[6*n+1] = ourview.vp[1];
# Line 255 | Line 274 | float  *vb;
274   }
275  
276  
277 < rt_compute(pb, np)              /* process buffer through rtrace */
278 < float   *pb;
279 < int     np;
277 > static void
278 > rt_compute(             /* process buffer through rtrace */
279 >        float   *pb,
280 >        int     np
281 > )
282   {
283   #ifdef DEBUG
284          if (verbose && np > 1)
285                  fprintf(stderr, "%s: sending %d samples to rtrace...\n",
286                                  progname, np);
287   #endif
288 <        bzero(pb+6*np, 6*sizeof(float));
289 <        if (process(rt_pd, pb, pb, 3*sizeof(float)*(np+1),
288 >        memset(pb+6*np, '\0', 6*sizeof(float));
289 >        if (process(&rt_pd, (char *)pb, (char *)pb, 3*sizeof(float)*(np+1),
290                          6*sizeof(float)*(np+1)) < 3*sizeof(float)*(np+1)) {
291                  fprintf(stderr, "%s: rtrace communication error\n",
292                                  progname);
# Line 274 | Line 295 | int    np;
295   }
296  
297  
298 < int
299 < getexpos(s)                     /* get exposure from header line */
300 < char    *s;
298 > static int
299 > getexpos(                       /* get exposure from header line */
300 >        char    *s,
301 >        void    *p
302 > )
303   {
304          char    fmt[32];
305  
# Line 290 | Line 313 | char   *s;
313   }
314  
315  
316 < open_pict(fn)                   /* open picture file */
317 < char    *fn;
316 > extern void
317 > open_pict(                      /* open picture file */
318 >        char    *fn
319 > )
320   {
321          if ((pictfp = fopen(fn, "r")) == NULL) {
322                  fprintf(stderr, "%s: cannot open\n", fn);
323                  exit(1);
324          }
325 +        SET_FILE_BINARY(pictfp);
326          exposure = 1.0;
327          getheader(pictfp, getexpos, NULL);
328          if (wrongformat || !fscnresolu(&pxsiz, &pysiz, pictfp)) {
# Line 307 | Line 333 | char   *fn;
333   }
334  
335  
336 < close_pict()                    /* done with picture */
336 > extern void
337 > close_pict(void)                        /* done with picture */
338   {
339          if (pictfp == NULL)
340                  return;
# Line 317 | Line 344 | close_pict()                   /* done with picture */
344   }
345  
346  
347 < fork_rtrace(av)                 /* open pipe and start rtrace */
348 < char    *av[];
347 > extern void
348 > fork_rtrace(                    /* open pipe and start rtrace */
349 >        char    *av[]
350 > )
351   {
352          int     rval;
353  
354 <        rval = open_process(rt_pd, av);
354 >        rval = open_process(&rt_pd, av);
355          if (rval < 0) {
356                  perror(progname);
357                  exit(1);
# Line 338 | Line 367 | char   *av[];
367   }
368  
369  
370 < done_rtrace()                   /* wait for rtrace to finish */
370 > extern void
371 > done_rtrace(void)                       /* wait for rtrace to finish */
372   {
373          int     status;
374  
375 <        status = close_process(rt_pd);
375 >        status = close_process(&rt_pd);
376          if (status > 0) {
377                  fprintf(stderr, "%s: bad status (%d) from rtrace\n",
378                                  progname, status);
379                  exit(1);
380          }
381 <        rt_pd[0] = -1;
381 >        rt_pd.r = -1;
382   }
383  
384  
385 < SCAN *
386 < scanretire()                    /* retire old scanlines to free list */
385 > static SCAN *
386 > scanretire(void)                        /* retire old scanlines to free list */
387   {
388          SCAN    *sold[NRETIRE];
389          int     n;
# Line 396 | Line 426 | scanretire()                   /* retire old scanlines to free list */
426   static char     *scan_buf;
427  
428  
429 < initscans()                             /* initialize scanline buffers */
429 > static void
430 > initscans(void)                         /* initialize scanline buffers */
431   {
432          int     scansize;
433          register SCAN   *ptr;
# Line 413 | Line 444 | initscans()                            /* initialize scanline buffers */
444                  hashtab[i] = NULL;
445                                          /* allocate scanline buffers */
446          scansize = sizeof(SCAN) + pxsiz*sizeof(COLR);
447 < #ifdef ALIGN
448 <        scansize = scansize+(sizeof(ALIGN)-1) & ~(sizeof(ALIGN)-1);
447 > #ifdef ALIGNT
448 >        scansize = scansize+(sizeof(ALIGNT)-1) & ~(sizeof(ALIGNT)-1);
449   #endif
450          i = MAXSBUF / scansize;         /* compute number to allocate */
451          if (i > HSIZE)
# Line 435 | Line 466 | initscans()                            /* initialize scanline buffers */
466   }
467  
468  
469 < donescans()                             /* free up scanlines */
469 > static void
470 > donescans(void)                         /* free up scanlines */
471   {
472          bfree(scan_buf, scanbufsiz);
473          bfree((char *)scanpos, pysiz*sizeof(long));

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines