+ fourier.data_len[0]=cut.width;
+ fourier.data_len[1]=cut.height;
+ fourier_alloc_data(&fourier);
+
+ mag=(double *)malloc(fourier.data_len[0]*fourier.data_len[1]*sizeof(double));
+ if(mag==NULL) {
+ printf("unable to alloc mag memory\n");
+ return -1;
+ }
+
+ // copy the data
+ offy=0;
+ for(y=0;y<fourier.data_len[1];y++) {
+ for(x=0;x<fourier.data_len[0];x++) {
+ offt=offy+x;
+ fourier.data[offt].r=(src.map[offt].r+src.map[offt].g+src.map[offt].b)/3;
+ }
+ offy+=fourier.data_len[0];
+ }
+
+ // do the fourier trafo
+ fourier_dft_2d(&fourier);
+
+ printf("fourier done!\n");
+
+ // copy back the data, intensity = sqrt(r^2+i^2)
+ max=0;
+ offt=0;
+ for(y=0;y<fourier.data_len[1];y++) {
+ for(x=0;x<fourier.data_len[0];x++) {
+ mag[offt]=sqrt(fourier.ftdata[offt].r*fourier.ftdata[offt].r+fourier.ftdata[offt].i*fourier.ftdata[offt].i);
+ if(mag[offt]>max) max=mag[offt];
+ offt+=1;
+ }
+ }
+
+ printf("found max: %f\n",max);
+
+ if(max!=0) scale=(int)255/max;
+ else scale=0;
+
+ if(scale!=0) {
+ printf("scaling image intensity: %d\n",scale);
+ offt=0;
+ for(y=0;y<dst.height;y++) {
+ for(x=0;x<dst.width;x++) {
+ // usual image processing order
+ offy=((y<dst.height/2)?y+dst.height/2:y-dst.height/2);
+ offy*=dst.width;
+ offy+=((x<dst.width/2)?x+dst.width/2:x-dst.width/2);
+ //offy=offt;
+ dst.map[offy].r=scale*mag[offt];
+ dst.map[offy].g=dst.map[offy].r;
+ dst.map[offy].b=dst.map[offy].r;
+ offt+=1;
+ }
+ }
+ }
+
+ free(mag);