ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/px/pf2.c
Revision: 2.3
Committed: Fri Oct 2 16:23:20 1992 UTC (31 years, 7 months ago) by greg
Content type: text/plain
Branch: MAIN
Changes since 2.2: +2 -1 lines
Log Message:
Removed problematic math function declarations

File Contents

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