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.1 by greg, Tue Nov 12 16:05:24 1991 UTC vs.
Revision 2.5 by greg, Tue Apr 2 10:32:29 1996 UTC

# Line 1 | Line 1
1 < /* Copyright (c) 1986 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"
18  
19 < #define  PI             3.14159265359
19 > #define  PI             3.14159265359
20  
21 < #define  FTINY          (1e-6)
21 > #define  FTINY          (1e-6)
22  
23   extern int  nrows, ncols;       /* number of rows and columns for output */
24  
# Line 36 | Line 36 | extern char  *progname;
36  
37   extern COLOR  exposure;         /* exposure for frame */
38  
39 < #define  AVGLVL         0.5     /* target mean brightness */
39 > extern double  (*ourbright)();  /* brightness calculation function */
40  
41 < double  avgbrt;                 /* average picture brightness */
41 > #define  AVGLVL         0.5     /* target mean brightness */
42  
43 < typedef struct  hotpix {        /* structure for avgbrt pixels */
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 */
48          COLOR  val;             /* pixel color */
49          short  x, y;            /* pixel position */
50          float  slope;           /* random slope for diffraction */
51   }  HOTPIX;
52  
53 < HOTPIX  *head;                  /* head of avgbrt pixel list */
53 > HOTPIX  *head;                  /* head of avgbrt pixel list */
54  
55 < double  sprdfact;               /* computed spread factor */
55 > double  sprdfact;               /* computed spread factor */
56  
57  
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  
73  
74   pass1scan(scan, y)              /* process first pass scanline */
75 < register COLOR  *scan;
75 > register COLOR  *scan;
76   int  y;
77   {
78          extern char  *malloc();
79 <        extern double  tan(), sqrt();
75 <        double  cbrt;
79 >        double  cbrt;
80          register int  x;
81 <        register HOTPIX  *hp;
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  
127  
128   pass2scan(scan, y)              /* process final pass scanline */
129 < register COLOR  *scan;
129 > register COLOR  *scan;
130   int  y;
131   {
132          int  xmin, xmax;
133          register int  x;
134 <        register HOTPIX  *hp;
134 >        register HOTPIX  *hp;
135          
136          for (hp = head; hp != NULL; hp = hp->next) {
137                  if (hp->slope > FTINY) {
# Line 154 | Line 162 | int  y;
162   starpoint(fcol, x, y, hp)               /* pixel is on the star's point */
163   COLOR  fcol;
164   int  x, y;
165 < register HOTPIX  *hp;
165 > register HOTPIX  *hp;
166   {
167          COLOR  ctmp;
168 <        double  d2;
168 >        double  d2;
169          
170          d2 = (double)(x - hp->x)*(x - hp->x) + (double)(y - hp->y)*(y - hp->y);
171          if (d2 > sprdfact) {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines