7 |
|
* 8/13/86 |
8 |
|
*/ |
9 |
|
|
10 |
– |
#include "standard.h" |
11 |
– |
|
12 |
– |
#include <string.h> |
13 |
– |
|
14 |
– |
#include "color.h" |
10 |
|
#include "pfilt.h" |
11 |
|
|
12 |
|
#define RSCA 1.13 /* square-radius multiplier: sqrt(4/PI) */ |
78 |
|
|
79 |
|
void |
80 |
|
dobox( /* simple box filter */ |
81 |
< |
COLOR csum, |
81 |
> |
SCOLOR csum, |
82 |
|
int xcent, |
83 |
|
int ycent, |
84 |
|
int c, |
89 |
|
double d; |
90 |
|
int y; |
91 |
|
int x, offs; |
92 |
< |
COLOR *scan; |
92 |
> |
COLORV *scan, *scp; |
93 |
|
|
94 |
|
wsum = 0; |
95 |
< |
setcolor(csum, 0.0, 0.0, 0.0); |
95 |
> |
scolorblack(csum); |
96 |
|
for (y = ycent+1-ybrad; y <= ycent+ybrad; y++) { |
97 |
|
if (y < 0) continue; |
98 |
|
if (y >= yres) break; |
102 |
|
scan = scanin[y%barsize]; |
103 |
|
for (x = xcent+1-xbrad; x <= xcent+xbrad; x++) { |
104 |
|
offs = x < 0 ? xres : x >= xres ? -xres : 0; |
105 |
< |
if (offs && !wrapfilt) |
105 |
> |
if ((offs != 0) & !wrapfilt) |
106 |
|
continue; |
107 |
|
d = x_c < 1.0 ? x_c*x - (c+.5) : (double)(x - xcent); |
108 |
|
if (d < -0.5) continue; |
109 |
|
if (d >= 0.5) break; |
110 |
|
wsum++; |
111 |
< |
addcolor(csum, scan[x+offs]); |
111 |
> |
scp = scan + (x+offs)*NCSAMP; |
112 |
> |
saddscolor(csum, scp); |
113 |
|
} |
114 |
|
} |
115 |
|
if (wsum > 1) { |
116 |
|
d = 1.0/wsum; |
117 |
< |
scalecolor(csum, d); |
117 |
> |
scalescolor(csum, d); |
118 |
|
} |
119 |
|
} |
120 |
|
|
121 |
|
|
122 |
|
void |
123 |
|
dogauss( /* gaussian filter */ |
124 |
< |
COLOR csum, |
124 |
> |
SCOLOR csum, |
125 |
|
int xcent, |
126 |
|
int ycent, |
127 |
|
int c, |
129 |
|
) |
130 |
|
{ |
131 |
|
double dy, dx, weight, wsum; |
132 |
< |
COLOR ctmp; |
132 |
> |
SCOLOR ctmp; |
133 |
|
int y; |
134 |
|
int x, offs; |
135 |
< |
COLOR *scan; |
135 |
> |
COLORV *scan; |
136 |
|
|
137 |
|
wsum = FTINY; |
138 |
< |
setcolor(csum, 0.0, 0.0, 0.0); |
138 |
> |
scolorblack(csum); |
139 |
|
for (y = ycent-yrad; y <= ycent+yrad; y++) { |
140 |
|
if (y < 0) continue; |
141 |
|
if (y >= yres) break; |
143 |
|
scan = scanin[y%barsize]; |
144 |
|
for (x = xcent-xrad; x <= xcent+xrad; x++) { |
145 |
|
offs = x < 0 ? xres : x >= xres ? -xres : 0; |
146 |
< |
if (offs && !wrapfilt) |
146 |
> |
if ((offs != 0) & !wrapfilt) |
147 |
|
continue; |
148 |
|
dx = (x_c*(x+.5) - (c+.5))/rad; |
149 |
|
weight = lookgauss(dx*dx + dy*dy); |
150 |
|
wsum += weight; |
151 |
< |
copycolor(ctmp, scan[x+offs]); |
152 |
< |
scalecolor(ctmp, weight); |
153 |
< |
addcolor(csum, ctmp); |
151 |
> |
copyscolor(ctmp, scan+(x+offs)*NCSAMP); |
152 |
> |
scalescolor(ctmp, weight); |
153 |
> |
saddscolor(csum, ctmp); |
154 |
|
} |
155 |
|
} |
156 |
|
weight = 1.0/wsum; |
157 |
< |
scalecolor(csum, weight); |
157 |
> |
scalescolor(csum, weight); |
158 |
|
} |
159 |
|
|
160 |
|
|
180 |
|
for (c = -orad; c <= orad; c++) { |
181 |
|
offs = ccent+c < 0 ? ncols : |
182 |
|
ccent+c >= ncols ? -ncols : 0; |
183 |
< |
if (offs && !wrapfilt) |
183 |
> |
if ((offs != 0) & !wrapfilt) |
184 |
|
continue; |
185 |
|
x = ringndx[c*c + r*r]; |
186 |
|
if (x < 0) continue; |
197 |
|
if (d >= 0.5) break; |
198 |
|
for (x = xcent+1-xbrad; x <= xcent+xbrad; x++) { |
199 |
|
offs = x < 0 ? xres : x >= xres ? -xres : 0; |
200 |
< |
if (offs && !wrapfilt) |
200 |
> |
if ((offs != 0) & !wrapfilt) |
201 |
|
continue; |
202 |
|
d = x_c < 1.0 ? x_c*x - (ccent+.5) : (double)(x - xcent); |
203 |
|
if (d < -0.5) continue; |
204 |
|
if (d >= 0.5) break; |
205 |
|
sumans(x, y, rcent, ccent, |
206 |
< |
pickfilt((*ourbright)(scanin[y%barsize][x+offs]))); |
206 |
> |
pickfilt((*ourbright)(scanin[y%barsize]+(x+offs)*NCSAMP))); |
207 |
|
} |
208 |
|
} |
209 |
|
} |
280 |
|
) |
281 |
|
{ |
282 |
|
double dy2, dx; |
283 |
< |
COLOR pval, ctmp; |
283 |
> |
SCOLOR pval, ctmp; |
284 |
|
int ksiz, r, offs; |
285 |
|
double pc, pr, norm; |
286 |
|
int i, c; |
287 |
< |
COLOR *scan; |
287 |
> |
COLORV *scan, *scp; |
288 |
|
/* |
289 |
|
* This normalization method fails at the picture borders because |
290 |
|
* a different number of input pixels contribute there. |
291 |
|
*/ |
292 |
< |
scan = scanin[py%barsize] + (px < 0 ? xres : px >= xres ? -xres : 0); |
293 |
< |
copycolor(pval, scan[px]); |
292 |
> |
scan = scanin[py%barsize] + (px < 0 ? xres : px >= xres ? -xres : 0)*NCSAMP; |
293 |
> |
copyscolor(pval, scan+px*NCSAMP); |
294 |
|
pc = x_c*(px+.5); |
295 |
|
pr = y_r*(py+.5); |
296 |
|
ksiz = CHECKRAD*m*rad + 1; |
325 |
|
offs = c < 0 ? ncols : c >= ncols ? -ncols : 0; |
326 |
|
if ((offs != 0) & !wrapfilt) |
327 |
|
continue; |
328 |
< |
copycolor(ctmp, pval); |
328 |
> |
copyscolor(ctmp, pval); |
329 |
|
dx = norm*warr[i++]; |
330 |
< |
scalecolor(ctmp, dx); |
331 |
< |
addcolor(scan[c+offs], ctmp); |
330 |
> |
scalescolor(ctmp, dx); |
331 |
> |
scp = scan + (c+offs)*NCSAMP; |
332 |
> |
saddscolor(scp, ctmp); |
333 |
|
} |
334 |
|
} |
335 |
|
} |