// $Id: dwt.c,v 1.1 2001/02/13 01:06:24 giles Exp $ // // $Log: dwt.c,v $ // Revision 1.1 2001/02/13 01:06:24 giles // Initial revision // #include #include "tarkin.h" void daub4(float a[], unsigned long n, int isign) { float *wksp; unsigned long nh, nh1, i, j; if(n < 4) return; wksp = (float *)malloc(sizeof(float) * n); nh1 = (nh=n>>1)+1; if(isign>=0) { for(i=1,j=1;j<=n-3;j+=2,i++) { wksp[i]=C0*a[j]+C1*a[j+1]+C2*a[j+2]+C3*a[j+3]; wksp[i+nh]=C3*a[j]-C2*a[j+1]+C1*a[j+2]-C0*a[j+3]; } wksp[i]=C0*a[n-1]+C1*a[n]+C2*a[1]+C3*a[2]; wksp[i+nh]=C3*a[n-1]-C2*a[n]+C1*a[1]-C0*a[2]; } else { wksp[1]=C2*a[nh]+C1*a[n]+C0*a[1]+C3*a[nh1]; wksp[2]=C3*a[nh]-C0*a[n]+C1*a[1]-C2*a[nh1]; for(i=1,j=3;i 4) { for(i2=0;i2= 0) for(nt=n;nt>=4;nt>>=1) daub4(wksp,nt,isign); else for(nt=4;nt<=n;nt<<=1) daub4(wksp,nt,isign); for(i3=i1+i2,k=1;k<=n;k++,i3+=nprev) a[i3]=wksp[k]; } } nprev = nnew; } free(wksp); } // Monodimensional DWT/iDWT transform // if isign is positive - Forward DWT // if isign is negative - Inverse DWT // // Originally snagged from Numeric Recipes in C (2nd Ed) // Modified to get around braindeadedness with arrays starting at [1]. void zdaub4(float a[], unsigned long n, int isign) { float *wksp; unsigned long nh, nh1, i, j; if(n < 4) return; wksp = (float *)malloc(sizeof(float) * n); nh = n>>1; nh1 = nh+1; if(isign>=0) { for(i=0,j=0;j 4) { // Cycle through the entire array for(i2=0;i2= 0) { for(nt=n;nt>=4;nt>>=1) zdaub4(wksp,nt,isign); } else { for(nt=4;nt<=n;nt<<=1) zdaub4(wksp,nt,isign); } // Copy the results back from the conversion for(i3=i1+i2,k=0;k