ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/px/pf2.c
Revision: 2.5
Committed: Tue Apr 2 10:32:29 1996 UTC (28 years, 1 month ago) by greg
Content type: text/plain
Branch: MAIN
Changes since 2.4: +4 -2 lines
Log Message:
changed bright() to (*ourbright)() for CIE scanlines

File Contents

# User Rev Content
1 greg 2.4 /* Copyright (c) 1994 Regents of the University of California */
2 greg 1.1
3     #ifndef lint
4     static char SCCSid[] = "$SunId$ LBL";
5     #endif
6    
7     /*
8     * pf2.c - routines used by pfilt.
9     */
10    
11     #include <stdio.h>
12    
13 greg 2.3 #include <math.h>
14    
15 greg 1.1 #include "random.h"
16    
17     #include "color.h"
18    
19 greg 2.2 #define PI 3.14159265359
20 greg 1.1
21 greg 2.2 #define FTINY (1e-6)
22 greg 1.1
23     extern int nrows, ncols; /* number of rows and columns for output */
24    
25     extern int xres, yres; /* x and y resolution */
26    
27     extern int avghot; /* true means average in avgbrt spots */
28    
29     extern double hotlvl; /* brightness considered "hot" */
30    
31     extern int npts; /* # of points for stars */
32    
33     extern double spread; /* spread for star points */
34    
35     extern char *progname;
36    
37     extern COLOR exposure; /* exposure for frame */
38    
39 greg 2.5 extern double (*ourbright)(); /* brightness calculation function */
40    
41 greg 2.2 #define AVGLVL 0.5 /* target mean brightness */
42 greg 1.1
43 greg 2.2 double avgbrt; /* average picture brightness */
44 greg 2.4 long npix; /* # pixels in average */
45 greg 1.1
46 greg 2.2 typedef struct hotpix { /* structure for avgbrt pixels */
47 greg 1.1 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 greg 2.2 HOTPIX *head; /* head of avgbrt pixel list */
54 greg 1.1
55 greg 2.2 double sprdfact; /* computed spread factor */
56 greg 1.1
57    
58     pass1init() /* prepare for first pass */
59     {
60     avgbrt = 0.0;
61 greg 2.4 npix = 0;
62 greg 1.1 head = NULL;
63     }
64    
65    
66     pass1default() /* for single pass */
67     {
68 greg 2.4 avgbrt = AVGLVL;
69     npix = 1;
70 greg 1.1 head = NULL;
71     }
72    
73    
74     pass1scan(scan, y) /* process first pass scanline */
75 greg 2.2 register COLOR *scan;
76 greg 1.1 int y;
77     {
78     extern char *malloc();
79 greg 2.2 double cbrt;
80 greg 1.1 register int x;
81 greg 2.2 register HOTPIX *hp;
82 greg 1.1
83     for (x = 0; x < xres; x++) {
84    
85 greg 2.5 cbrt = (*ourbright)(scan[x]);
86 greg 1.1
87 greg 2.4 if (cbrt <= 0)
88     continue;
89    
90     if (avghot || cbrt < hotlvl) {
91 greg 1.1 avgbrt += cbrt;
92 greg 2.4 npix++;
93     }
94 greg 1.1 if (npts && cbrt >= hotlvl) {
95     hp = (HOTPIX *)malloc(sizeof(HOTPIX));
96     if (hp == NULL) {
97     fprintf(stderr, "%s: out of memory\n",
98     progname);
99     quit(1);
100     }
101     copycolor(hp->val, scan[x]);
102     hp->x = x;
103     hp->y = y;
104     hp->slope = tan(PI*(0.5-(random()%npts+0.5)/npts));
105     hp->next = head;
106     head = hp;
107     }
108     }
109     }
110    
111    
112     pass2init() /* prepare for final pass */
113     {
114 greg 2.4 if (!npix) {
115     fprintf(stderr, "%s: picture too dark or too bright\n",
116     progname);
117 greg 1.1 quit(1);
118     }
119 greg 2.4 avgbrt /= (double)npix;
120 greg 1.1
121     scalecolor(exposure, AVGLVL/avgbrt);
122    
123 greg 2.5 sprdfact = spread / (hotlvl * (*ourbright)(exposure))
124 greg 1.1 * ((double)xres*xres + (double)yres*yres) / 4.0;
125     }
126    
127    
128     pass2scan(scan, y) /* process final pass scanline */
129 greg 2.2 register COLOR *scan;
130 greg 1.1 int y;
131     {
132     int xmin, xmax;
133     register int x;
134 greg 2.2 register HOTPIX *hp;
135 greg 1.1
136     for (hp = head; hp != NULL; hp = hp->next) {
137     if (hp->slope > FTINY) {
138     xmin = (y - hp->y - 0.5)/hp->slope + hp->x;
139     xmax = (y - hp->y + 0.5)/hp->slope + hp->x;
140     } else if (hp->slope < -FTINY) {
141     xmin = (y - hp->y + 0.5)/hp->slope + hp->x;
142     xmax = (y - hp->y - 0.5)/hp->slope + hp->x;
143     } else if (y == hp->y) {
144     xmin = 0;
145     xmax = xres-1;
146     } else {
147     xmin = 1;
148     xmax = 0;
149     }
150     if (xmin < 0)
151     xmin = 0;
152     if (xmax >= xres)
153     xmax = xres-1;
154     for (x = xmin; x <= xmax; x++)
155     starpoint(scan[x], x, y, hp);
156     }
157     for (x = 0; x < xres; x++)
158     multcolor(scan[x], exposure);
159     }
160    
161    
162     starpoint(fcol, x, y, hp) /* pixel is on the star's point */
163     COLOR fcol;
164     int x, y;
165 greg 2.2 register HOTPIX *hp;
166 greg 1.1 {
167     COLOR ctmp;
168 greg 2.2 double d2;
169 greg 1.1
170     d2 = (double)(x - hp->x)*(x - hp->x) + (double)(y - hp->y)*(y - hp->y);
171     if (d2 > sprdfact) {
172     d2 = sprdfact / d2;
173     if (d2 < FTINY)
174     return;
175     copycolor(ctmp, hp->val);
176     scalecolor(ctmp, d2);
177     addcolor(fcol, ctmp);
178     } else if (d2 > FTINY) {
179     addcolor(fcol, hp->val);
180     }
181     }