X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=ETL%2FETL%2F_boxblur.h;fp=ETL%2FETL%2F_boxblur.h;h=c043dc3c121290b7e907f562cad94ecbba618cf1;hb=a095981e18cc37a8ecc7cd237cc22b9c10329264;hp=0000000000000000000000000000000000000000;hpb=9459638ad6797b8139f1e9f0715c96076dbf0890;p=synfig.git diff --git a/ETL/ETL/_boxblur.h b/ETL/ETL/_boxblur.h new file mode 100644 index 0000000..c043dc3 --- /dev/null +++ b/ETL/ETL/_boxblur.h @@ -0,0 +1,246 @@ +/*! ======================================================================== +** Extended Template Library +** Box Blur Template Implementation +** $Id$ +** +** Copyright (c) 2002 Robert B. Quattlebaum Jr. +** +** This package is free software; you can redistribute it and/or +** modify it under the terms of the GNU General Public License as +** published by the Free Software Foundation; either version 2 of +** the License, or (at your option) any later version. +** +** This package is distributed in the hope that it will be useful, +** but WITHOUT ANY WARRANTY; without even the implied warranty of +** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +** General Public License for more details. +** +** === N O T E S =========================================================== +** +** This is an internal header file, included by other ETL headers. +** You should not attempt to use it directly. +** +** ========================================================================= */ + +/* === S T A R T =========================================================== */ + +#ifndef __ETL__BOXBLUR_H +#define __ETL__BOXBLUR_H + +/* === H E A D E R S ======================================================= */ + +/* === M A C R O S ========================================================= */ + +/* === T Y P E D E F S ===================================================== */ + +/* === C L A S S E S & S T R U C T S ======================================= */ + +_ETL_BEGIN_NAMESPACE + +template void +hbox_blur(T1 pen,int w, int h, int length, T2 outpen) +{ + int x,y; + typename T1::iterator_x iter, end; + + length=std::min(w,length); + const float divisor(1.0f/(length*2+1)); + + for(y=0;ylength) ? iter[-length-1] : *pen.x(); + tot += ((x+length) void +vbox_blur(T1 pen,const int w, const int h, int length, T2 outpen) +{ + int x,y; + typename T1::iterator_y iter, end; + + length=std::min(h,length); + const float divisor(1.0f/(length*2+1)); + + for(x=0;xlength) ? iter[-length-1] : *pen.y(); + tot += ((y+length) void +vbox_blur(T1 pen,int w, int h, int length,T2 outpen) +{ + int x,y; + typename T1::iterator_y iter, end, biter,eiter; + + //print out the info I need to figure out if this is somehow a buffer overrun... + /*char *beginptr=0,*endptr=0; + { + T1 ypen = pen; + T1 endpen = pen; + endpen.move(w,h); + ypen.inc_y(); + + T2 open = outpen, + oepen = outpen; + oepen.move(w,h); + printf("V Blur (%d,%d,s-%d) in(%p,%p,st %d) out(%p,%p)\n", + w,h,length,(char*)pen.x(),(char*)endpen.x(),(char*)ypen.x()-(char*)pen.x(), + (char*)open.x(),(char*)oepen.x()); + }*/ + length=min(h-1,length); + + const float divisor(1.0f/(length*2+1)); + //const int div = (length*2+1); + + //since the filter range is 2*length+1 we need h-1 + for(x=0;x%.3f),",y,&iter[y],iter[y],tot); + } + iter=pen.y(); + + //printf(" tot=%.3f\n",tot); + + biter = iter+(-length-1); //get the first one... + eiter = iter+length; + + //y will always be > length + //T2 open = outpen; + for (y=0;ylength) + { + typename T1::value_type &v = *biter; + /*if( (char*)&v < beginptr || + (char*)&v >= endptr) + printf("crap! %d (%p off %p)\n",y,(char*)&v,(char*)&*iter);*/ + tot -= v; + //printf("[%.3f,",v); + } + else + { + tot -= bval; + //printf("[%.3f,",bval); + } + + if (y+length= endptr) + printf("crap! %d (%p off %p)\n",y,(char*)&v,(char*)&*iter);*/ + tot += v; + //printf("%.3f]",v); + } + else + { + tot += eval; + //printf("%.3f]",eval); + } + + //test handled in the previous case... + //tot -= (y>length) ? *biter : bval; + //tot += (y+length void +box_blur(T1 pen,int w, int h, int blur_w, int blur_h, T2 outpen) + { hbox_blur(pen,w,h,blur_w,outpen); vbox_blur(pen,w,h,blur_h,outpen); } + +template void +box_blur(T1 pen,int w, int h, int size, T2 outpen) + { hbox_blur(pen,w,h,size,outpen); vbox_blur(pen,w,h,size,outpen); } + +template void +hbox_blur(T1 begin,T1 end, int len,T2 outpen) +{ + typename T1::difference_type size(end-begin); + hbox_blur(begin,size.x,size.y,len,outpen); +} + +template void +vbox_blur(T1 begin,T1 end, int len,T2 outpen) +{ + typename T1::difference_type size(end-begin); + vbox_blur(begin,size.x,size.y,len,outpen); +} + +template void +box_blur(T1 begin,T1 end, int blur_w, int blur_h,T2 outpen) +{ + typename T1::difference_type size(end-begin); + hbox_blur(begin,size.x,size.y,blur_w,outpen); vbox_blur(begin,size.x,size.y,blur_h,outpen); +} + +template void +box_blur(T1 begin,T1 end, int blursize,T2 outpen) +{ + typename T1::difference_type size(end-begin); + hbox_blur(begin,size.x,size.y,blursize,outpen); vbox_blur(begin,size.x,size.y,blursize,outpen); +} + +_ETL_END_NAMESPACE + +/* === E X T E R N S ======================================================= */ + +/* === E N D =============================================================== */ + +#endif