1 |
< |
/* Copyright (c) 1986 Regents of the University of California */ |
1 |
> |
/* Copyright (c) 1992 Regents of the University of California */ |
2 |
|
|
3 |
|
#ifndef lint |
4 |
|
static char SCCSid[] = "$SunId$ LBL"; |
12 |
|
|
13 |
|
#include <stdio.h> |
14 |
|
|
15 |
+ |
#include <math.h> |
16 |
+ |
|
17 |
|
#include "color.h" |
18 |
|
|
19 |
< |
#define FTINY 1e-7 |
19 |
> |
#define FTINY 1e-7 |
20 |
|
|
21 |
|
extern double rad; /* output pixel radius for filtering */ |
22 |
|
|
38 |
|
|
39 |
|
extern char *progname; |
40 |
|
|
41 |
< |
float *exptable; /* exponent table */ |
41 |
> |
float *gausstable; /* gauss lookup table */ |
42 |
|
|
43 |
< |
#define lookexp(x) exptable[(int)(-10.*(x)+.5)] |
43 |
> |
#define lookgauss(x) gausstable[(int)(-10.*(x)+.5)] |
44 |
|
|
45 |
|
|
46 |
|
initmask() /* initialize gaussian lookup table */ |
47 |
|
{ |
48 |
|
extern char *malloc(); |
49 |
< |
extern double exp(); |
49 |
> |
double d; |
50 |
|
register int x; |
51 |
|
|
52 |
< |
exptable = (float *)malloc(100*sizeof(float)); |
53 |
< |
if (exptable == NULL) { |
52 |
> |
gausstable = (float *)malloc(100*sizeof(float)); |
53 |
> |
if (gausstable == NULL) { |
54 |
|
fprintf(stderr, "%s: out of memory in initmask\n", progname); |
55 |
|
quit(1); |
56 |
|
} |
57 |
< |
for (x = 0; x < 100; x++) |
58 |
< |
exptable[x] = exp(-x*0.1); |
57 |
> |
d = x_c*y_r*0.25/rad/rad; |
58 |
> |
gausstable[0] = exp(-d)/sqrt(d); |
59 |
> |
for (x = 1; x < 100; x++) |
60 |
> |
if ((gausstable[x] = exp(-x*0.1)/sqrt(x*0.1)) > gausstable[0]) |
61 |
> |
gausstable[x] = gausstable[0]; |
62 |
|
} |
63 |
|
|
64 |
|
|
71 |
|
static double d; |
72 |
|
static int y; |
73 |
|
register int x; |
74 |
< |
register COLOR *scan; |
74 |
> |
register COLOR *scan; |
75 |
|
|
76 |
|
wsum = 0; |
77 |
|
setcolor(csum, 0.0, 0.0, 0.0); |
78 |
|
for (y = ycent+1-yrad; y <= ycent+yrad; y++) { |
79 |
< |
if (y < 0 || y >= yres) |
80 |
< |
continue; |
81 |
< |
d = y_r < 1.0 ? y_r*y - r : y - ycent; |
79 |
> |
if (y < 0) continue; |
80 |
> |
if (y >= yres) break; |
81 |
> |
d = y_r < 1.0 ? y_r*y - r : (double)(y - ycent); |
82 |
|
if (d > 0.5+FTINY || d < -0.5-FTINY) |
83 |
|
continue; |
84 |
|
scan = scanin[y%barsize]; |
85 |
|
for (x = xcent+1-xrad; x <= xcent+xrad; x++) { |
86 |
< |
if (x < 0 || x >= xres) |
87 |
< |
continue; |
88 |
< |
d = x_c < 1.0 ? x_c*x - c : x - xcent; |
86 |
> |
if (x < 0) continue; |
87 |
> |
if (x >= xres) break; |
88 |
> |
d = x_c < 1.0 ? x_c*x - c : (double)(x - xcent); |
89 |
|
if (d > 0.5+FTINY || d < -0.5-FTINY) |
90 |
|
continue; |
91 |
|
wsum++; |
106 |
|
static COLOR ctmp; |
107 |
|
static int y; |
108 |
|
register int x; |
109 |
< |
register COLOR *scan; |
109 |
> |
register COLOR *scan; |
110 |
|
|
111 |
|
wsum = FTINY; |
112 |
|
setcolor(csum, 0.0, 0.0, 0.0); |
113 |
< |
for (y = ycent+1-yrad; y <= ycent+yrad; y++) { |
114 |
< |
if (y < 0 || y >= yres) |
115 |
< |
continue; |
116 |
< |
dy = (y_r*y - r)/rad; |
113 |
> |
for (y = ycent-yrad; y <= ycent+yrad; y++) { |
114 |
> |
if (y < 0) continue; |
115 |
> |
if (y >= yres) break; |
116 |
> |
dy = (y_r*(y+.5) - (r+.5))/rad; |
117 |
|
scan = scanin[y%barsize]; |
118 |
< |
for (x = xcent+1-xrad; x <= xcent+xrad; x++) { |
119 |
< |
if (x < 0 || x >= xres) |
120 |
< |
continue; |
121 |
< |
dx = (x_c*x - c)/rad; |
122 |
< |
weight = lookexp(-(dx*dx + dy*dy)); |
118 |
> |
for (x = xcent-xrad; x <= xcent+xrad; x++) { |
119 |
> |
if (x < 0) continue; |
120 |
> |
if (x >= xres) break; |
121 |
> |
dx = (x_c*(x+.5) - (c+.5))/rad; |
122 |
> |
weight = lookgauss(-(dx*dx + dy*dy)); |
123 |
|
wsum += weight; |
124 |
|
copycolor(ctmp, scan[x]); |
125 |
|
scalecolor(ctmp, weight); |