ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/px/pf2.c
Revision: 2.1
Committed: Tue Nov 12 16:05:24 1991 UTC (32 years, 5 months ago) by greg
Content type: text/plain
Branch: MAIN
Changes since 1.1: +0 -0 lines
Log Message:
updated revision number for release 2.0

File Contents

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