X-Git-Url: https://hackdaworld.org/gitweb/?p=physik%2Fnlsop.git;a=blobdiff_plain;f=dft.c;h=5c1e9068c28c90d141e7720d37445a1824852036;hp=3c6470084c0fbecfcbc5356d583488c786427e48;hb=HEAD;hpb=db268eab69af21ab1eecdeeeeb8b8932ef5ebd71 diff --git a/dft.c b/dft.c index 3c64700..5c1e906 100644 --- a/dft.c +++ b/dft.c @@ -5,17 +5,25 @@ * */ +#define USE_FFTW3 + #include "dft.h" int main(int argc,char **argv) { +#ifdef USE_FFTW3 + fftw_plan plan; + fftw_complex *in,*out; +#else t_fourier fourier; +#endif t_bmp src; t_bmp dst; t_bmp cut; int x,y; int offy,offt; - int scale; + double scale; + int size; double max; double *mag; @@ -24,54 +32,77 @@ int main(int argc,char **argv) { bmp_init(&cut,1); src.mode=READ; dst.mode=WRITE; - cut.mode=WRITE; strcpy(src.file,argv[1]); strcpy(dst.file,argv[2]); - strcpy(cut.file,argv[3]); +#ifndef USE_FFTW3 fourier_init(&fourier,1); fourier.type=DFT|FWD; fourier.dim=2; +#endif bmp_read_file(&src); - bmp_cut_bottom(&cut,&src,150); - bmp_write_file(&cut); - dst.width=src.info.width; - dst.height=src.info.height; + bmp_cut_grab_bottom(&cut,&src,src.info.width,GRAB); + + dst.width=cut.width; + dst.height=cut.height; bmp_alloc_map(&dst); - fourier.data_len[0]=src.info.width; - fourier.data_len[1]=src.info.height; + size=cut.width*cut.height; + +#ifndef USE_FFTW3 + fourier.data_len[0]=cut.width; + fourier.data_len[1]=cut.height; fourier_alloc_data(&fourier); +#else + in=fftw_malloc(sizeof(fftw_complex)*size); + memset(in,0,size*sizeof(fftw_complex)); + out=fftw_malloc(sizeof(fftw_complex)*size); + memset(out,0,size*sizeof(fftw_complex)); + if(in==NULL||out==NULL) { + printf("fftw alloc error!\n"); + return -23; + } + plan=fftw_plan_dft_2d(cut.width,cut.height,in,out,FFTW_FORWARD,FFTW_ESTIMATE); +#endif - mag=(double *)malloc(fourier.data_len[0]*fourier.data_len[1]*sizeof(double)); + mag=(double *)malloc(size*sizeof(double)); if(mag==NULL) { printf("unable to alloc mag memory\n"); return -1; } // copy the data - offy=0; - for(y=0;ymax) max=mag[offt]; offt+=1; } @@ -79,17 +110,19 @@ int main(int argc,char **argv) { printf("found max: %f\n",max); - if(max!=0) scale=(int)255/max; + if(max!=0) scale=255.0/max; else scale=0; if(scale!=0) { - printf("scaling image intensity: %d\n",scale); + printf("scaling image intensity: %f\n",scale); offt=0; for(y=0;y