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.5 by greg, Tue Apr 2 10:32:29 1996 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines