27 #ifndef __ETL__BOXBLUR_H
28 #define __ETL__BOXBLUR_H
40 template<
typename T1,
typename T2>
void
41 hbox_blur(T1 pen,
int w,
int h,
int length, T2 outpen)
44 typename T1::iterator_x iter, end;
46 length=std::min(w,length);
47 const float divisor(1.0
f/(length*2+1));
49 for(y=0;y<h;y++,pen.inc_y(),outpen.inc_y())
54 typename T1::accumulator_type tot((
typename T1::accumulator_type)(*iter)*(length+1));
56 for (x=0;x<length && iter!=end;x++,++iter) tot+=*iter;
59 for (x=0;x<w && iter!=end;x++,++iter,outpen.inc_x())
62 (
typename T1::accumulator_type)(iter[-length-1]) :
63 (
typename T1::accumulator_type)(*pen.x());
64 tot += ((x+length)<w) ?
65 (
typename T1::accumulator_type)(iter[length]) :
66 (
typename T1::accumulator_type)(end[-1]);
68 outpen.put_value((
typename T2::value_type)(tot*divisor));
75 template<
typename T1,
typename T2>
void
76 vbox_blur(T1 pen,
const int w,
const int h,
int length, T2 outpen)
79 typename T1::iterator_y iter, end;
81 length=std::min(h,length);
82 const float divisor(1.0
f/(length*2+1));
84 for(x=0;x<w;x++,pen.inc_x(),outpen.inc_x())
89 typename T1::accumulator_type tot((
typename T1::accumulator_type)(*iter)*(length+1));
91 for (y=0;y<length && iter!=end;y++,++iter) tot+=*iter;
94 for (y=0;y<h && iter!=end;y++,++iter,outpen.inc_y())
97 (
typename T1::accumulator_type)(iter[-length-1]) :
98 (
typename T1::accumulator_type)(*pen.y());
99 tot += ((y+length)<h) ?
100 (
typename T1::accumulator_type)(iter[length]) :
101 (
typename T1::accumulator_type)(end[-1]);
103 outpen.put_value((
typename T2::value_type)(tot*divisor));
111 template<
typename T1,
typename T2>
void
112 vbox_blur(T1 pen,
int w,
int h,
int length,T2 outpen)
115 typename T1::iterator_y iter, end, biter,eiter;
132 length=min(h-1,length);
134 const float divisor(1.0f/(length*2+1));
138 for(x=0;x<w;x++,pen.inc_x(),outpen.inc_x())
143 const typename T1::value_type bval = *iter;
144 const typename T1::value_type eval = end[-1];
146 typename T1::accumulator_type tot(bval*(length+1));
152 for (y=0;y<length && iter!=end;y++)
161 biter = iter+(-length-1);
166 for (y=0;y<h && iter!=end;y++,++iter,++biter,++eiter,outpen.inc_y())
172 typename T1::value_type &v = *biter;
187 typename T1::value_type &v = *eiter;
205 outpen.put_value(tot*divisor);
212 template<
typename T1,
typename T2>
void
213 box_blur(T1 pen,
int w,
int h,
int blur_w,
int blur_h, T2 outpen)
216 template<
typename T1,
typename T2>
void
220 template<
typename T1,
typename T2>
void
223 typename T1::difference_type size(end-begin);
224 hbox_blur(begin,size.x,size.y,len,outpen);
227 template<
typename T1,
typename T2>
void
230 typename T1::difference_type size(end-begin);
231 vbox_blur(begin,size.x,size.y,len,outpen);
234 template<
typename T1,
typename T2>
void
235 box_blur(T1 begin,T1 end,
int blur_w,
int blur_h,T2 outpen)
237 typename T1::difference_type size(end-begin);
238 hbox_blur(begin,size.x,size.y,blur_w,outpen);
vbox_blur(begin,size.x,size.y,blur_h,outpen);
241 template<
typename T1,
typename T2>
void
244 typename T1::difference_type size(end-begin);
245 hbox_blur(begin,size.x,size.y,blursize,outpen);
vbox_blur(begin,size.x,size.y,blursize,outpen);