/*
* The 2D Discrete Wavelet Transform. * gse. 2007. */ template <typename TYPE, class FILTER> class dwt1d: public FILTER, public mallok { public: dwt1d(); ~dwt1d(); void analyze(TYPE *signal, int x, int levels); void synthesize(TYPE *signal, int x, int levels); void set_max_line_size(int max_line_size); private: TYPE *line; }; template <typename TYPE, class FILTER> dwt1d<TYPE,FILTER>::dwt1d<TYPE,FILTER>() { line = (TYPE *)mallok::alloc_1d(1,sizeof(TYPE)); #if defined DEBUG if(!iine) { cerr << "dwt1d<TYPE,FILTER>::dwt1d<TYPE,FILTER>: out of memory for \"line\"\n"; abort(); } #endif } template <typename TYPE, class FILTER> dwt1d<TYPE,FILTER>::~dwt1d<TYPE,FILTER>() { mallok::free_1d(line); } template <typename TYPE, class FILTER> void dwt1d<TYPE,FILTER>::set_max_line_size(int max_line_size) { mallok::free_1d(line); line = (TYPE *)mallok::alloc_1d(max_line_size,sizeof(TYPE)); } template <typename TYPE, class FILTER> void dwt1d<TYPE,FILTER>::analyze(TYPE *signal, int x, int levels) { for(int lv=0;lv<levels;lv++) { int nx = x; x >>= 1; if(x == 0) x = 1; if(nx & 1) { /* N’umero impar de elementos */ memcpy(line,signal,nx*sizeof(TYPE)); odd_analyze(line,signal,signal+x+1,nx); } else { /* N’umero par de elementos */ memcpy(line,signal,nx*sizeof(TYPE)); even_analyze(line,signal,signal+x,nx); } } } template <typename TYPE, class FILTER> void dwt1d<TYPE,FILTER>::synthesize(TYPE *signal, int x, int levels) { int nx = x>>levels; for(int lv = levels-1; lv>=0; lv--) { int mx = nx; nx = x>>lv; if(nx==0) nx = 1; if(nx & 1) { /* N’umero impar de elementos */ memcpy(line,signal,nx*sizeof(TYPE)); odd_synthesize(signal,line,line+mx+1,nx); } else { /* N’umero par de columas */ memcpy(line,signal,nx*sizeof(TYPE)); even_synthesize(signal,line,line+mx,nx); } } } |