ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/px/pf3.c
Revision: 1.2
Committed: Wed Jun 5 12:15:34 1991 UTC (32 years, 11 months ago) by greg
Content type: text/plain
Branch: MAIN
Changes since 1.1: +4 -4 lines
Log Message:
improved gaussian filtering

File Contents

# Content
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 * pf3.c - routines for gaussian and box filtering
9 *
10 * 8/13/86
11 */
12
13 #include <stdio.h>
14
15 #include "color.h"
16
17 #define FTINY 1e-7
18
19 extern double rad; /* output pixel radius for filtering */
20
21 extern int nrows; /* number of rows for output */
22 extern int ncols; /* number of columns for output */
23
24 extern int boxfilt; /* do box filtering? */
25
26 extern int xres, yres; /* resolution of input */
27
28 extern double x_c, y_r; /* conversion factors */
29
30 extern int xrad; /* x window size */
31 extern int yrad; /* y window size */
32
33 extern int barsize; /* size of input scan bar */
34 extern COLOR **scanin; /* input scan bar */
35 extern COLOR *scanout; /* output scan line */
36
37 extern char *progname;
38
39 float *exptable; /* exponent table */
40
41 #define lookexp(x) exptable[(int)(-10.*(x)+.5)]
42
43
44 initmask() /* initialize gaussian lookup table */
45 {
46 extern char *malloc();
47 extern double exp();
48 register int x;
49
50 exptable = (float *)malloc(100*sizeof(float));
51 if (exptable == NULL) {
52 fprintf(stderr, "%s: out of memory in initmask\n", progname);
53 quit(1);
54 }
55 for (x = 0; x < 100; x++)
56 exptable[x] = exp(-x*0.1);
57 }
58
59
60 dobox(csum, xcent, ycent, c, r) /* simple box filter */
61 COLOR csum;
62 int xcent, ycent;
63 int c, r;
64 {
65 static int wsum;
66 static double d;
67 static int y;
68 register int x;
69 register COLOR *scan;
70
71 wsum = 0;
72 setcolor(csum, 0.0, 0.0, 0.0);
73 for (y = ycent+1-yrad; y <= ycent+yrad; y++) {
74 if (y < 0 || y >= yres)
75 continue;
76 d = y_r < 1.0 ? y_r*y - r : y - ycent;
77 if (d > 0.5+FTINY || d < -0.5-FTINY)
78 continue;
79 scan = scanin[y%barsize];
80 for (x = xcent+1-xrad; x <= xcent+xrad; x++) {
81 if (x < 0 || x >= xres)
82 continue;
83 d = x_c < 1.0 ? x_c*x - c : x - xcent;
84 if (d > 0.5+FTINY || d < -0.5-FTINY)
85 continue;
86 wsum++;
87 addcolor(csum, scan[x]);
88 }
89 }
90 if (wsum > 1)
91 scalecolor(csum, 1.0/wsum);
92 }
93
94
95 dogauss(csum, xcent, ycent, c, r) /* gaussian filter */
96 COLOR csum;
97 int xcent, ycent;
98 int c, r;
99 {
100 static double dy, dx, weight, wsum;
101 static COLOR ctmp;
102 static int y;
103 register int x;
104 register COLOR *scan;
105
106 wsum = FTINY;
107 setcolor(csum, 0.0, 0.0, 0.0);
108 for (y = ycent-yrad; y <= ycent+yrad; y++) {
109 if (y < 0 || y >= yres)
110 continue;
111 dy = (y_r*(y+.5) - (r+.5))/rad;
112 scan = scanin[y%barsize];
113 for (x = xcent-xrad; x <= xcent+xrad; x++) {
114 if (x < 0 || x >= xres)
115 continue;
116 dx = (x_c*(x+.5) - (c+.5))/rad;
117 weight = lookexp(-(dx*dx + dy*dy));
118 wsum += weight;
119 copycolor(ctmp, scan[x]);
120 scalecolor(ctmp, weight);
121 addcolor(csum, ctmp);
122 }
123 }
124 scalecolor(csum, 1.0/wsum);
125 }