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

Comparing ray/src/px/pf2.c (file contents):
Revision 2.2 by greg, Mon Sep 21 12:14:08 1992 UTC vs.
Revision 2.6 by greg, Sat Feb 22 02:07:27 2003 UTC

# Line 1 | Line 1
1 /* Copyright (c) 1992 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   *  pf2.c - routines used by pfilt.
9 *
10 *     10/3/85
6   */
7  
8   #include  <stdio.h>
9  
10 + #include  <stdlib.h>
11 +
12 + #include  <math.h>
13 +
14   #include  "random.h"
15  
16   #include  "color.h"
# Line 36 | Line 35 | extern char  *progname;
35  
36   extern COLOR  exposure;         /* exposure for frame */
37  
38 + extern double  (*ourbright)();  /* brightness calculation function */
39 +
40   #define  AVGLVL         0.5     /* target mean brightness */
41  
42   double  avgbrt;                 /* average picture brightness */
43 + long    npix;                   /* # pixels in average */
44  
45   typedef struct  hotpix {        /* structure for avgbrt pixels */
46          struct hotpix  *next;   /* next in list */
# Line 55 | Line 57 | double sprdfact;               /* computed spread factor */
57   pass1init()                     /* prepare for first pass */
58   {
59          avgbrt = 0.0;
60 +        npix = 0;
61          head = NULL;
62   }
63  
64  
65   pass1default()                  /* for single pass */
66   {
67 <        avgbrt = AVGLVL * xres * yres;
67 >        avgbrt = AVGLVL;
68 >        npix = 1;
69          head = NULL;
70   }
71  
# Line 70 | Line 74 | pass1scan(scan, y)             /* process first pass scanline */
74   register COLOR  *scan;
75   int  y;
76   {
73        extern char  *malloc();
74        extern double  tan(), sqrt();
77          double  cbrt;
78          register int  x;
79          register HOTPIX  *hp;
80  
81          for (x = 0; x < xres; x++) {
82          
83 <                cbrt = bright(scan[x]);
83 >                cbrt = (*ourbright)(scan[x]);
84  
85 <                if (avghot || cbrt < hotlvl)
86 <                        avgbrt += cbrt;
85 >                if (cbrt <= 0)
86 >                        continue;
87  
88 +                if (avghot || cbrt < hotlvl) {
89 +                        avgbrt += cbrt;
90 +                        npix++;
91 +                }
92                  if (npts && cbrt >= hotlvl) {
93                          hp = (HOTPIX *)malloc(sizeof(HOTPIX));
94                          if (hp == NULL) {
# Line 103 | Line 109 | int  y;
109  
110   pass2init()                     /* prepare for final pass */
111   {
112 <        avgbrt /= (double)xres * yres;
113 <
114 <        if (avgbrt <= FTINY) {
109 <                fprintf(stderr, "%s: picture too dark\n", progname);
112 >        if (!npix) {
113 >                fprintf(stderr, "%s: picture too dark or too bright\n",
114 >                                progname);
115                  quit(1);
116          }
117 +        avgbrt /= (double)npix;
118  
119          scalecolor(exposure,  AVGLVL/avgbrt);
120          
121 <        sprdfact = spread / (hotlvl * bright(exposure))
121 >        sprdfact = spread / (hotlvl * (*ourbright)(exposure))
122                          * ((double)xres*xres + (double)yres*yres) / 4.0;
123   }
124  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines