00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include <stdio.h>
00023 #include <stdlib.h>
00024 #include <string.h>
00025 #include <flgrCoreCopy.h>
00026 #include <flgrCoreMalloc.h>
00027 #include <flgrCoreDispatch.h>
00028 #include "flgrLinearFFT.h"
00029
00039 FILE *flgr1d_fft_create_fftw_wisdom_file(int size_x, int DorInv,
00040 FLGR_Type type, char *transformtype) {
00041 char fname[1024];
00042
00043
00044
00045 sprintf(fname,".fftw_wisdom_%dd_%d_%d_%s_%s",1,size_x,DorInv,
00046 flgr_get_type_string(type),transformtype);
00047
00048 return fopen(fname,"wb");
00049 }
00050
00051 FILE *flgr1d_fft_look_for_fftw_wisdom_file(int size_x, int DorInv,
00052 FLGR_Type type, char *transformtype) {
00053 char fname[1024];
00054
00055
00056
00057 sprintf(fname,".fftw_wisdom_%dd_%d_%d_%s_%s",1,size_x,DorInv,
00058 flgr_get_type_string(type),transformtype);
00059
00060 return fopen(fname,"rb");
00061 }
00062
00063
00064
00065 FILE *flgr2d_fft_create_fftw_wisdom_file(int size_x, int size_y, int DorInv,
00066 FLGR_Type type, char *transformtype) {
00067 char fname[1024];
00068
00069
00070
00071 sprintf(fname,".fftw_wisdom_%dd_%dx%d_%d_%s_%s",2,size_x,size_y,DorInv,
00072 flgr_get_type_string(type),transformtype);
00073
00074 return fopen(fname,"wb");
00075 }
00076
00077 FILE *flgr2d_fft_look_for_fftw_wisdom_file(int size_x, int size_y, int DorInv,
00078 FLGR_Type type, char *transformtype) {
00079 char fname[1024];
00080
00081
00082
00083 sprintf(fname,".fftw_wisdom_%dd_%dx%d_%d_%s_%s",2,size_x,size_y,DorInv,
00084 flgr_get_type_string(type),transformtype);
00085
00086 return fopen(fname,"rb");
00087 }
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00108
00110 #define FLGR_FORWARD_COMPLEX_FFT_1D(dtype,dtypename,prefix) \
00111 FILE *wisdom_file=NULL; \
00112 void *bufsrc,*buffft; \
00113 prefix##_plan p_forw; \
00114 int nx=dat->length; \
00115 \
00116 \
00117 \
00118 bufsrc = fftw_malloc(nx*sizeof(prefix##_complex)); \
00119 buffft = fftw_malloc(nx*sizeof(prefix##_complex)); \
00120 \
00121 flgr1d_export_raw_##dtype(bufsrc,dat); \
00122 \
00123 wisdom_file=flgr1d_fft_look_for_fftw_wisdom_file(nx,1,dtypename, \
00124 "forward_c2c"); \
00125 if(wisdom_file!=NULL) prefix##_import_wisdom_from_file(wisdom_file); \
00126 \
00127 p_forw = prefix##_plan_dft_1d(nx, bufsrc, buffft, \
00128 FFTW_FORWARD,FFTW_MEASURE); \
00129 \
00130 if(wisdom_file==NULL) { \
00131 wisdom_file=flgr1d_fft_create_fftw_wisdom_file(nx,1,dtypename, \
00132 "forward_c2c"); \
00133 prefix##_export_wisdom_to_file(wisdom_file); \
00134 POST_INFO("fftw wisdom created\n"); \
00135 } \
00136 \
00137 prefix##_execute(p_forw); \
00138 \
00139 prefix##_destroy_plan(p_forw); \
00140 \
00141 fclose(wisdom_file); \
00142 \
00143 flgr1d_import_raw_##dtype(datfft,buffft); \
00144 \
00145 fftw_free(bufsrc); \
00146 fftw_free(buffft)
00147
00148
00149 void flgr1d_fft_forward_cplx_fgBIT(FLGR_Data1D *datfft, FLGR_Data1D *dat) {
00150 flgr_no_define_type_function(FLGR_BIT);
00151 }
00152 void flgr1d_fft_forward_cplx_fgUINT8(FLGR_Data1D *datfft, FLGR_Data1D *dat) {
00153 flgr_no_define_type_function(FLGR_UINT8);
00154 }
00155 void flgr1d_fft_forward_cplx_fgUINT16(FLGR_Data1D *datfft, FLGR_Data1D *dat) {
00156 flgr_no_define_type_function(FLGR_UINT16);
00157 }
00158 void flgr1d_fft_forward_cplx_fgUINT32(FLGR_Data1D *datfft, FLGR_Data1D *dat) {
00159 flgr_no_define_type_function(FLGR_UINT32);
00160 }
00161 void flgr1d_fft_forward_cplx_fgINT8(FLGR_Data1D *datfft, FLGR_Data1D *dat) {
00162 flgr_no_define_type_function(FLGR_INT8);
00163 }
00164 void flgr1d_fft_forward_cplx_fgINT16(FLGR_Data1D *datfft, FLGR_Data1D *dat) {
00165 flgr_no_define_type_function(FLGR_INT16);
00166 }
00167 void flgr1d_fft_forward_cplx_fgINT32(FLGR_Data1D *datfft, FLGR_Data1D *dat) {
00168 flgr_no_define_type_function(FLGR_INT32);
00169 }
00170 void flgr1d_fft_forward_cplx_fgFLOAT32(FLGR_Data1D *datfft, FLGR_Data1D *dat) {
00171 FLGR_FORWARD_COMPLEX_FFT_1D(fgFLOAT32,FLGR_FLOAT32,fftwf);
00172 }
00173 void flgr1d_fft_forward_cplx_fgFLOAT64(FLGR_Data1D *datfft, FLGR_Data1D *dat) {
00174 FLGR_FORWARD_COMPLEX_FFT_1D(fgFLOAT64,FLGR_FLOAT64,fftw);
00175 }
00176
00178
00183
00184 FLGR_Ret flgr1d_fft_forward_cplx(FLGR_Data1D *datfft, FLGR_Data1D *datsrc) {
00185 FLGR_Ret ret;
00186
00187
00188
00189 if((datsrc == NULL) || (datfft == NULL)) {
00190 POST_ERROR("Null objects!\n");
00191 return FLGR_RET_NULL_OBJECT;
00192 }
00193
00194 if(datsrc->spp!=2) {
00195 POST_ERROR("Only complex images are supported\n");
00196 return FLGR_RET_NULL_OBJECT;
00197 }
00198
00199 if((ret=flgr1d_is_data_same_attributes(datsrc,datfft,__FUNCTION__)) != FLGR_RET_OK) return ret;
00200
00201 FLGR_DISPATCH_PROCEDURE(datsrc->type, flgr1d_fft_forward_cplx, datfft,datsrc);
00202 }
00203
00204
00205
00206
00208
00210 #define FLGR_BACKWARD_COMPLEX_FFT_1D(dtype,dtypename,prefix) \
00211 FILE *wisdom_file=NULL; \
00212 void *bufdest, *buffft; \
00213 prefix##_plan p_back; \
00214 int nx=datfft->length; \
00215 \
00216 \
00217 \
00218 bufdest = fftw_malloc(nx*sizeof(prefix##_complex)); \
00219 buffft = fftw_malloc(nx*sizeof(prefix##_complex)); \
00220 \
00221 flgr1d_export_raw_##dtype(buffft,datfft); \
00222 \
00223 wisdom_file=flgr1d_fft_look_for_fftw_wisdom_file(nx,0,dtypename, \
00224 "backward_c2c"); \
00225 if(wisdom_file!=NULL) prefix##_import_wisdom_from_file(wisdom_file); \
00226 \
00227 p_back = prefix##_plan_dft_1d(nx, buffft, bufdest, \
00228 FFTW_BACKWARD,FFTW_MEASURE); \
00229 \
00230 if(wisdom_file==NULL) { \
00231 wisdom_file=flgr1d_fft_create_fftw_wisdom_file(nx,0,dtypename, \
00232 "backward_c2c"); \
00233 prefix##_export_wisdom_to_file(wisdom_file); \
00234 POST_INFO("fftw wisdom created\n"); \
00235 } \
00236 \
00237 prefix##_execute(p_back); \
00238 \
00239 prefix##_destroy_plan(p_back); \
00240 \
00241 fclose(wisdom_file); \
00242 \
00243 flgr1d_import_raw_##dtype(datdest,bufdest); \
00244 \
00245 fftw_free(bufdest); \
00246 fftw_free(buffft); \
00247 \
00248 return
00249
00250
00251 void flgr1d_fft_backward_cplx_fgBIT(FLGR_Data1D *datdest, FLGR_Data1D *datfft) {
00252 flgr_no_define_type_function(FLGR_BIT);
00253 }
00254 void flgr1d_fft_backward_cplx_fgUINT8(FLGR_Data1D *datdest, FLGR_Data1D *datfft) {
00255 flgr_no_define_type_function(FLGR_UINT8);
00256 }
00257 void flgr1d_fft_backward_cplx_fgUINT16(FLGR_Data1D *datdest, FLGR_Data1D *datfft) {
00258 flgr_no_define_type_function(FLGR_UINT16);
00259 }
00260 void flgr1d_fft_backward_cplx_fgUINT32(FLGR_Data1D *datdest, FLGR_Data1D *datfft) {
00261 flgr_no_define_type_function(FLGR_UINT32);
00262 }
00263 void flgr1d_fft_backward_cplx_fgINT8(FLGR_Data1D *datdest, FLGR_Data1D *datfft) {
00264 flgr_no_define_type_function(FLGR_INT8);
00265 }
00266 void flgr1d_fft_backward_cplx_fgINT16(FLGR_Data1D *datdest, FLGR_Data1D *datfft) {
00267 flgr_no_define_type_function(FLGR_INT16);
00268 }
00269 void flgr1d_fft_backward_cplx_fgINT32(FLGR_Data1D *datdest, FLGR_Data1D *datfft) {
00270 flgr_no_define_type_function(FLGR_INT32);
00271 }
00272 void flgr1d_fft_backward_cplx_fgFLOAT32(FLGR_Data1D *datdest, FLGR_Data1D *datfft) {
00273 FLGR_BACKWARD_COMPLEX_FFT_1D(fgFLOAT32,FLGR_FLOAT32,fftwf);
00274 }
00275 void flgr1d_fft_backward_cplx_fgFLOAT64(FLGR_Data1D *datdest, FLGR_Data1D *datfft) {
00276 FLGR_BACKWARD_COMPLEX_FFT_1D(fgFLOAT64,FLGR_FLOAT64,fftw);
00277 }
00278
00280
00285
00286 FLGR_Ret flgr1d_fft_backward_cplx(FLGR_Data1D *datdest, FLGR_Data1D *datfft) {
00287 FLGR_Ret ret;
00288
00289
00290
00291 if((datfft==NULL) || (datdest==NULL)) {
00292 POST_ERROR("Null objects!\n");
00293 return FLGR_RET_NULL_OBJECT;
00294 }
00295
00296 if(datdest->spp!=2) {
00297 POST_ERROR("images must be complex (spp=2)\n");
00298 return FLGR_RET_UNDEFINED_ERROR;
00299 }
00300
00301 if(datfft->spp!=2) {
00302 POST_ERROR("images must be complex (spp=2)\n");
00303 return FLGR_RET_UNDEFINED_ERROR;
00304 }
00305
00306 if((ret=flgr1d_is_data_same_attributes(datdest,datfft,__FUNCTION__)) != FLGR_RET_OK) return ret;
00307
00308 FLGR_DISPATCH_PROCEDURE(datdest->type, flgr1d_fft_backward_cplx, datdest, datfft);
00309
00310 return FLGR_RET_OK;
00311 }
00312
00313
00314
00316
00318 #define FLGR_MACRO_FFT_FORWARD_REAL_1D(dtype,dtypename,prefix) \
00319 FILE *wisdom_file=NULL; \
00320 void *bufsrc,*buffft; \
00321 prefix##_plan p_forw; \
00322 int nx=datsrc->length; \
00323 \
00324 \
00325 \
00326 bufsrc = flgr_malloc_align(nx*sizeof(dtype),16); \
00327 buffft = flgr_malloc_align((nx/2+1)*sizeof(dtype)*2,16); \
00328 \
00329 flgr1d_export_raw_ptr(bufsrc,datsrc); \
00330 \
00331 wisdom_file=flgr1d_fft_look_for_fftw_wisdom_file(nx,1,dtypename, \
00332 "forward_r2c"); \
00333 if(wisdom_file!=NULL) prefix##_import_wisdom_from_file(wisdom_file); \
00334 \
00335 p_forw = prefix##_plan_dft_r2c_1d(nx,bufsrc,buffft,FFTW_MEASURE); \
00336 \
00337 if(wisdom_file==NULL) { \
00338 wisdom_file=flgr1d_fft_create_fftw_wisdom_file(nx,1,dtypename, \
00339 "forward_r2c"); \
00340 prefix##_export_wisdom_to_file(wisdom_file); \
00341 POST_INFO("fftw wisdom created\n"); \
00342 } \
00343 \
00344 prefix##_execute(p_forw); \
00345 \
00346 prefix##_destroy_plan(p_forw); \
00347 \
00348 fclose(wisdom_file); \
00349 \
00350 flgr1d_import_raw_##dtype(datfft,buffft); \
00351 \
00352 flgr_free_align(bufsrc); \
00353 flgr_free_align(buffft)
00354
00355
00356 void flgr1d_fft_forward_real_fgBIT(FLGR_Data1D *datfft, FLGR_Data1D *datsrc) {
00357 flgr_no_define_type_function(FLGR_BIT);
00358 }
00359 void flgr1d_fft_forward_real_fgUINT8(FLGR_Data1D *datfft, FLGR_Data1D *datsrc) {
00360 flgr_no_define_type_function(FLGR_UINT8);
00361 }
00362 void flgr1d_fft_forward_real_fgUINT16(FLGR_Data1D *datfft, FLGR_Data1D *datsrc) {
00363 flgr_no_define_type_function(FLGR_UINT16);
00364 }
00365 void flgr1d_fft_forward_real_fgUINT32(FLGR_Data1D *datfft, FLGR_Data1D *datsrc) {
00366 flgr_no_define_type_function(FLGR_UINT32);
00367 }
00368 void flgr1d_fft_forward_real_fgINT8(FLGR_Data1D *datfft, FLGR_Data1D *datsrc) {
00369 flgr_no_define_type_function(FLGR_INT8);
00370 }
00371 void flgr1d_fft_forward_real_fgINT16(FLGR_Data1D *datfft, FLGR_Data1D *datsrc) {
00372 flgr_no_define_type_function(FLGR_INT16);
00373 }
00374 void flgr1d_fft_forward_real_fgINT32(FLGR_Data1D *datfft, FLGR_Data1D *datsrc) {
00375 flgr_no_define_type_function(FLGR_INT32);
00376 }
00377 void flgr1d_fft_forward_real_fgFLOAT32(FLGR_Data1D *datfft, FLGR_Data1D *datsrc) {
00378 FLGR_MACRO_FFT_FORWARD_REAL_1D(fgFLOAT32,FLGR_FLOAT32,fftwf);
00379 }
00380 void flgr1d_fft_forward_real_fgFLOAT64(FLGR_Data1D *datfft, FLGR_Data1D *datsrc) {
00381 FLGR_MACRO_FFT_FORWARD_REAL_1D(fgFLOAT64,FLGR_FLOAT64,fftw);
00382 }
00383
00385
00390
00391 FLGR_Ret flgr1d_fft_forward_real(FLGR_Data1D *datfft, FLGR_Data1D *datsrc) {
00392 FLGR_Ret ret;
00393 int nx;
00394
00395
00396
00397 if((datsrc==NULL) || (datfft==NULL)){
00398 POST_ERROR("Null objects!\n");
00399 return FLGR_RET_NULL_OBJECT;
00400 }
00401
00402 nx = datsrc->length;
00403
00404 if(datsrc->spp!=1) {
00405 POST_ERROR("Multi Sample Per Pixel not supported\n");
00406 return FLGR_RET_NULL_OBJECT;
00407 }
00408
00409 if(datfft->spp!=2) {
00410 POST_ERROR("data containing fft must be declared as complex (spp=2)\n");
00411 return FLGR_RET_NULL_OBJECT;
00412 }
00413
00414 if((ret=flgr1d_is_data_same_type(datsrc,datfft)) != FLGR_RET_OK) return ret;
00415
00416 if((nx/2+1) != datfft->length) {
00417 POST_ERROR("data containing fft must have a size equal to %d\n",nx/2+1);
00418 return FLGR_RET_SIZE_ERROR;
00419 }
00420
00421 FLGR_DISPATCH_PROCEDURE(datsrc->type, flgr1d_fft_forward_real, datfft,datsrc);
00422 }
00423
00424
00426
00428 #define FLGR_MACRO_FFT_BACKWARD_REAL_1D(dtype,dtypename,prefix) \
00429 FILE *wisdom_file=NULL; \
00430 void *bufdest, *buffft; \
00431 prefix##_plan p_back; \
00432 int nx=datdest->length; \
00433 \
00434 \
00435 \
00436 bufdest = flgr_malloc_align(nx*sizeof(dtype),16); \
00437 buffft = flgr_malloc_align((nx/2+1)*sizeof(dtype)*2,16); \
00438 \
00439 flgr1d_export_raw_##dtype(buffft,datfft); \
00440 \
00441 wisdom_file=flgr1d_fft_look_for_fftw_wisdom_file(nx,0,dtypename, \
00442 "backward_c2r"); \
00443 if(wisdom_file!=NULL) prefix##_import_wisdom_from_file(wisdom_file); \
00444 \
00445 p_back = prefix##_plan_dft_c2r_1d(nx,buffft,bufdest,FFTW_MEASURE); \
00446 \
00447 if(wisdom_file==NULL) { \
00448 wisdom_file=flgr1d_fft_create_fftw_wisdom_file(nx,0,dtypename, \
00449 "backward_c2r"); \
00450 prefix##_export_wisdom_to_file(wisdom_file); \
00451 POST_INFO("fftw wisdom created\n"); \
00452 } \
00453 \
00454 prefix##_execute(p_back); \
00455 \
00456 prefix##_destroy_plan(p_back); \
00457 \
00458 fclose(wisdom_file); \
00459 \
00460 flgr1d_import_raw_##dtype(datdest,bufdest); \
00461 \
00462 flgr_free_align(bufdest); \
00463 flgr_free_align(buffft)
00464
00465
00466 void flgr1d_fft_backward_real_fgBIT(FLGR_Data1D *datdest, FLGR_Data1D *datfft) {
00467 flgr_no_define_type_function(FLGR_BIT);
00468 }
00469 void flgr1d_fft_backward_real_fgUINT8(FLGR_Data1D *datdest, FLGR_Data1D *datfft) {
00470 flgr_no_define_type_function(FLGR_UINT8);
00471 }
00472 void flgr1d_fft_backward_real_fgUINT16(FLGR_Data1D *datdest, FLGR_Data1D *datfft) {
00473 flgr_no_define_type_function(FLGR_UINT16);
00474 }
00475 void flgr1d_fft_backward_real_fgUINT32(FLGR_Data1D *datdest, FLGR_Data1D *datfft) {
00476 flgr_no_define_type_function(FLGR_UINT32);
00477 }
00478 void flgr1d_fft_backward_real_fgINT8(FLGR_Data1D *datdest, FLGR_Data1D *datfft) {
00479 flgr_no_define_type_function(FLGR_INT8);
00480 }
00481 void flgr1d_fft_backward_real_fgINT16(FLGR_Data1D *datdest, FLGR_Data1D *datfft) {
00482 flgr_no_define_type_function(FLGR_INT16);
00483 }
00484 void flgr1d_fft_backward_real_fgINT32(FLGR_Data1D *datdest, FLGR_Data1D *datfft) {
00485 flgr_no_define_type_function(FLGR_INT32);
00486 }
00487 void flgr1d_fft_backward_real_fgFLOAT32(FLGR_Data1D *datdest, FLGR_Data1D *datfft) {
00488 FLGR_MACRO_FFT_BACKWARD_REAL_1D(fgFLOAT32,FLGR_FLOAT32,fftwf);
00489 }
00490 void flgr1d_fft_backward_real_fgFLOAT64(FLGR_Data1D *datdest, FLGR_Data1D *datfft) {
00491 FLGR_MACRO_FFT_BACKWARD_REAL_1D(fgFLOAT64,FLGR_FLOAT64,fftw);
00492 }
00493
00494
00496
00501
00502 FLGR_Ret flgr1d_fft_backward_real(FLGR_Data1D *datdest, FLGR_Data1D *datfft) {
00503 FLGR_Ret ret;
00504 int nx;
00505
00506
00507
00508 if((datdest==NULL) || (datfft==NULL)){
00509 POST_ERROR("Null objects!\n");
00510 return FLGR_RET_NULL_OBJECT;
00511 }
00512
00513 nx = datdest->length;
00514
00515 if(datdest->spp!=1) {
00516 POST_ERROR("Multi Sample Per Pixel not supported\n");
00517 return FLGR_RET_UNDEFINED_ERROR;
00518 }
00519
00520 if(datfft->spp!=2) {
00521 POST_ERROR("data containing fft must be declared as complex (spp=2)\n");
00522 return FLGR_RET_NULL_OBJECT;
00523 }
00524
00525 if((ret=flgr1d_is_data_same_type(datdest,datfft)) != FLGR_RET_OK) return ret;
00526
00527 if((nx/2+1) != datfft->length) {
00528 POST_ERROR("data containing fft must have a size equal to %d\n",nx/2+1);
00529 return FLGR_RET_SIZE_ERROR;
00530 }
00531
00532 FLGR_DISPATCH_PROCEDURE(datdest->type, flgr1d_fft_backward_real, datdest,datfft);
00533
00534 return FLGR_RET_OK;
00535 }
00536
00537
00538
00539
00540
00541
00542
00543
00544
00545
00546
00547
00548
00549
00550
00551
00552
00553
00554
00555
00556
00557
00558
00559
00560
00561
00562
00563
00564
00565
00566
00567
00568
00569
00570
00571
00572
00573
00574
00575
00576
00578
00580 #define FLGR_FORWARD_COMPLEX_FFT_2D(dtype,dtypename,prefix) \
00581 FILE *wisdom_file=NULL; \
00582 void *bufsrc,*buffft; \
00583 prefix##_plan p_forw; \
00584 int nx=dat->size_x; \
00585 int ny=dat->size_y; \
00586 \
00587 \
00588 \
00589 bufsrc = fftw_malloc(nx*ny*sizeof(prefix##_complex)); \
00590 buffft = fftw_malloc(nx*ny*sizeof(prefix##_complex)); \
00591 \
00592 flgr2d_export_raw_##dtype(bufsrc,dat); \
00593 \
00594 wisdom_file=flgr2d_fft_look_for_fftw_wisdom_file(ny,nx,1,dtypename, \
00595 "forward_c2c"); \
00596 if(wisdom_file!=NULL) prefix##_import_wisdom_from_file(wisdom_file); \
00597 \
00598 p_forw = prefix##_plan_dft_2d(ny, nx, bufsrc, buffft, \
00599 FFTW_FORWARD,FFTW_MEASURE); \
00600 \
00601 if(wisdom_file==NULL) { \
00602 wisdom_file=flgr2d_fft_create_fftw_wisdom_file(ny,nx,1,dtypename, \
00603 "forward_c2c"); \
00604 prefix##_export_wisdom_to_file(wisdom_file); \
00605 POST_INFO("fftw wisdom created\n"); \
00606 } \
00607 \
00608 prefix##_execute(p_forw); \
00609 \
00610 prefix##_destroy_plan(p_forw); \
00611 \
00612 fclose(wisdom_file); \
00613 \
00614 flgr2d_import_raw_##dtype(datfft,buffft); \
00615 \
00616 fftw_free(bufsrc); \
00617 fftw_free(buffft)
00618
00619
00620 void flgr2d_fft_forward_cplx_fgBIT(FLGR_Data2D *datfft, FLGR_Data2D *dat) {
00621 flgr_no_define_type_function(FLGR_BIT);
00622 }
00623 void flgr2d_fft_forward_cplx_fgUINT8(FLGR_Data2D *datfft, FLGR_Data2D *dat) {
00624 flgr_no_define_type_function(FLGR_UINT8);
00625 }
00626 void flgr2d_fft_forward_cplx_fgUINT16(FLGR_Data2D *datfft, FLGR_Data2D *dat) {
00627 flgr_no_define_type_function(FLGR_UINT16);
00628 }
00629 void flgr2d_fft_forward_cplx_fgUINT32(FLGR_Data2D *datfft, FLGR_Data2D *dat) {
00630 flgr_no_define_type_function(FLGR_UINT32);
00631 }
00632 void flgr2d_fft_forward_cplx_fgINT8(FLGR_Data2D *datfft, FLGR_Data2D *dat) {
00633 flgr_no_define_type_function(FLGR_INT8);
00634 }
00635 void flgr2d_fft_forward_cplx_fgINT16(FLGR_Data2D *datfft, FLGR_Data2D *dat) {
00636 flgr_no_define_type_function(FLGR_INT16);
00637 }
00638 void flgr2d_fft_forward_cplx_fgINT32(FLGR_Data2D *datfft, FLGR_Data2D *dat) {
00639 flgr_no_define_type_function(FLGR_INT32);
00640 }
00641 void flgr2d_fft_forward_cplx_fgFLOAT32(FLGR_Data2D *datfft, FLGR_Data2D *dat) {
00642 FLGR_FORWARD_COMPLEX_FFT_2D(fgFLOAT32,FLGR_FLOAT32,fftwf);
00643 }
00644 void flgr2d_fft_forward_cplx_fgFLOAT64(FLGR_Data2D *datfft, FLGR_Data2D *dat) {
00645 FLGR_FORWARD_COMPLEX_FFT_2D(fgFLOAT64,FLGR_FLOAT64,fftw);
00646 }
00647
00649
00654
00655 FLGR_Ret flgr2d_fft_forward_cplx(FLGR_Data2D *datfft, FLGR_Data2D *datsrc) {
00656 FLGR_Ret ret;
00657
00658
00659
00660 if((datsrc == NULL) || (datfft == NULL)) {
00661 POST_ERROR("Null objects!\n");
00662 return FLGR_RET_NULL_OBJECT;
00663 }
00664
00665 if(datsrc->spp!=2) {
00666 POST_ERROR("Only complex images are supported\n");
00667 return FLGR_RET_NULL_OBJECT;
00668 }
00669
00670 if((ret=flgr2d_is_data_same_attributes(datsrc,datfft,__FUNCTION__)) != FLGR_RET_OK) return ret;
00671
00672 FLGR_DISPATCH_PROCEDURE(datsrc->type, flgr2d_fft_forward_cplx, datfft,datsrc);
00673 }
00674
00675
00676
00677
00679
00681 #define FLGR_BACKWARD_COMPLEX_FFT_2D(dtype,dtypename,prefix) \
00682 FILE *wisdom_file=NULL; \
00683 void *bufdest, *buffft; \
00684 prefix##_plan p_back; \
00685 int nx=datfft->size_x; \
00686 int ny=datfft->size_y; \
00687 \
00688 \
00689 \
00690 bufdest = fftw_malloc(nx*ny*sizeof(prefix##_complex)); \
00691 buffft = fftw_malloc(nx*ny*sizeof(prefix##_complex)); \
00692 \
00693 flgr2d_export_raw_##dtype(buffft,datfft); \
00694 \
00695 wisdom_file=flgr2d_fft_look_for_fftw_wisdom_file(ny,nx,0,dtypename, \
00696 "backward_c2c"); \
00697 if(wisdom_file!=NULL) prefix##_import_wisdom_from_file(wisdom_file); \
00698 \
00699 p_back = prefix##_plan_dft_2d(ny, nx, buffft, bufdest, \
00700 FFTW_BACKWARD,FFTW_MEASURE); \
00701 \
00702 if(wisdom_file==NULL) { \
00703 wisdom_file=flgr2d_fft_create_fftw_wisdom_file(ny,nx,0,dtypename, \
00704 "backward_c2c"); \
00705 prefix##_export_wisdom_to_file(wisdom_file); \
00706 POST_INFO("fftw wisdom created\n"); \
00707 } \
00708 \
00709 prefix##_execute(p_back); \
00710 \
00711 prefix##_destroy_plan(p_back); \
00712 \
00713 fclose(wisdom_file); \
00714 \
00715 flgr2d_import_raw_##dtype(datdest,bufdest); \
00716 \
00717 fftw_free(bufdest); \
00718 fftw_free(buffft); \
00719 \
00720 return
00721
00722
00723 void flgr2d_fft_backward_cplx_fgBIT(FLGR_Data2D *datdest, FLGR_Data2D *datfft) {
00724 flgr_no_define_type_function(FLGR_BIT);
00725 }
00726 void flgr2d_fft_backward_cplx_fgUINT8(FLGR_Data2D *datdest, FLGR_Data2D *datfft) {
00727 flgr_no_define_type_function(FLGR_UINT8);
00728 }
00729 void flgr2d_fft_backward_cplx_fgUINT16(FLGR_Data2D *datdest, FLGR_Data2D *datfft) {
00730 flgr_no_define_type_function(FLGR_UINT16);
00731 }
00732 void flgr2d_fft_backward_cplx_fgUINT32(FLGR_Data2D *datdest, FLGR_Data2D *datfft) {
00733 flgr_no_define_type_function(FLGR_UINT32);
00734 }
00735 void flgr2d_fft_backward_cplx_fgINT8(FLGR_Data2D *datdest, FLGR_Data2D *datfft) {
00736 flgr_no_define_type_function(FLGR_INT8);
00737 }
00738 void flgr2d_fft_backward_cplx_fgINT16(FLGR_Data2D *datdest, FLGR_Data2D *datfft) {
00739 flgr_no_define_type_function(FLGR_INT16);
00740 }
00741 void flgr2d_fft_backward_cplx_fgINT32(FLGR_Data2D *datdest, FLGR_Data2D *datfft) {
00742 flgr_no_define_type_function(FLGR_INT32);
00743 }
00744 void flgr2d_fft_backward_cplx_fgFLOAT32(FLGR_Data2D *datdest, FLGR_Data2D *datfft) {
00745 FLGR_BACKWARD_COMPLEX_FFT_2D(fgFLOAT32,FLGR_FLOAT32,fftwf);
00746 }
00747 void flgr2d_fft_backward_cplx_fgFLOAT64(FLGR_Data2D *datdest, FLGR_Data2D *datfft) {
00748 FLGR_BACKWARD_COMPLEX_FFT_2D(fgFLOAT64,FLGR_FLOAT64,fftw);
00749 }
00750
00752
00757
00758 FLGR_Ret flgr2d_fft_backward_cplx(FLGR_Data2D *datdest, FLGR_Data2D *datfft) {
00759 FLGR_Ret ret;
00760
00761
00762
00763 if((datfft==NULL) || (datdest==NULL)) {
00764 POST_ERROR("Null objects!\n");
00765 return FLGR_RET_NULL_OBJECT;
00766 }
00767
00768 if(datdest->spp!=2) {
00769 POST_ERROR("images must be complex (spp=2)\n");
00770 return FLGR_RET_UNDEFINED_ERROR;
00771 }
00772
00773 if(datfft->spp!=2) {
00774 POST_ERROR("images must be complex (spp=2)\n");
00775 return FLGR_RET_UNDEFINED_ERROR;
00776 }
00777
00778 if((ret=flgr2d_is_data_same_attributes(datdest,datfft,__FUNCTION__)) != FLGR_RET_OK) return ret;
00779
00780 FLGR_DISPATCH_PROCEDURE(datdest->type, flgr2d_fft_backward_cplx, datdest, datfft);
00781
00782 return FLGR_RET_OK;
00783 }
00784
00785
00786
00788
00790 #define FLGR_MACRO_FFT_FORWARD_REAL_2D(dtype,dtypename,prefix) \
00791 FILE *wisdom_file=NULL; \
00792 void *bufsrc,*buffft; \
00793 prefix##_plan p_forw; \
00794 int nx=datsrc->size_x; \
00795 int ny=datsrc->size_y; \
00796 \
00797 \
00798 \
00799 bufsrc = flgr_malloc_align(nx*ny*sizeof(dtype),16); \
00800 buffft = flgr_malloc_align((nx/2+1)*ny*sizeof(dtype)*2,16); \
00801 \
00802 flgr2d_export_raw_ptr(bufsrc,datsrc); \
00803 \
00804 wisdom_file=flgr2d_fft_look_for_fftw_wisdom_file(ny,nx,1,dtypename, \
00805 "forward_r2c"); \
00806 if(wisdom_file!=NULL) prefix##_import_wisdom_from_file(wisdom_file); \
00807 \
00808 p_forw = prefix##_plan_dft_r2c_2d(ny, nx,bufsrc,buffft,FFTW_MEASURE); \
00809 \
00810 if(wisdom_file==NULL) { \
00811 wisdom_file=flgr2d_fft_create_fftw_wisdom_file(ny,nx,1,dtypename, \
00812 "forward_r2c"); \
00813 prefix##_export_wisdom_to_file(wisdom_file); \
00814 POST_INFO("fftw wisdom created\n"); \
00815 } \
00816 \
00817 prefix##_execute(p_forw); \
00818 \
00819 prefix##_destroy_plan(p_forw); \
00820 \
00821 fclose(wisdom_file); \
00822 \
00823 flgr2d_import_raw_##dtype(datfft,buffft); \
00824 \
00825 fftw_free(bufsrc); \
00826 fftw_free(buffft)
00827
00828
00829 void flgr2d_fft_forward_real_fgBIT(FLGR_Data2D *datfft, FLGR_Data2D *datsrc) {
00830 flgr_no_define_type_function(FLGR_BIT);
00831 }
00832 void flgr2d_fft_forward_real_fgUINT8(FLGR_Data2D *datfft, FLGR_Data2D *datsrc) {
00833 flgr_no_define_type_function(FLGR_UINT8);
00834 }
00835 void flgr2d_fft_forward_real_fgUINT16(FLGR_Data2D *datfft, FLGR_Data2D *datsrc) {
00836 flgr_no_define_type_function(FLGR_UINT16);
00837 }
00838 void flgr2d_fft_forward_real_fgUINT32(FLGR_Data2D *datfft, FLGR_Data2D *datsrc) {
00839 flgr_no_define_type_function(FLGR_UINT32);
00840 }
00841 void flgr2d_fft_forward_real_fgINT8(FLGR_Data2D *datfft, FLGR_Data2D *datsrc) {
00842 flgr_no_define_type_function(FLGR_INT8);
00843 }
00844 void flgr2d_fft_forward_real_fgINT16(FLGR_Data2D *datfft, FLGR_Data2D *datsrc) {
00845 flgr_no_define_type_function(FLGR_INT16);
00846 }
00847 void flgr2d_fft_forward_real_fgINT32(FLGR_Data2D *datfft, FLGR_Data2D *datsrc) {
00848 flgr_no_define_type_function(FLGR_INT32);
00849 }
00850 void flgr2d_fft_forward_real_fgFLOAT32(FLGR_Data2D *datfft, FLGR_Data2D *datsrc) {
00851 FLGR_MACRO_FFT_FORWARD_REAL_2D(fgFLOAT32,FLGR_FLOAT32,fftwf);
00852 }
00853 void flgr2d_fft_forward_real_fgFLOAT64(FLGR_Data2D *datfft, FLGR_Data2D *datsrc) {
00854 FLGR_MACRO_FFT_FORWARD_REAL_2D(fgFLOAT64,FLGR_FLOAT64,fftw);
00855 }
00856
00858
00863
00864 FLGR_Ret flgr2d_fft_forward_real(FLGR_Data2D *datfft, FLGR_Data2D *datsrc) {
00865 FLGR_Ret ret;
00866 int nx;
00867
00868
00869
00870 if((datsrc==NULL) || (datfft==NULL)){
00871 POST_ERROR("Null objects!\n");
00872 return FLGR_RET_NULL_OBJECT;
00873 }
00874
00875 nx = datsrc->size_x;
00876
00877 if(datsrc->spp!=1) {
00878 POST_ERROR("Multi Sample Per Pixel not supported\n");
00879 return FLGR_RET_NULL_OBJECT;
00880 }
00881
00882 if(datfft->spp!=2) {
00883 POST_ERROR("data containing fft must be complex (spp=2)\n");
00884 return FLGR_RET_NULL_OBJECT;
00885 }
00886
00887 if((ret=flgr2d_is_data_same_type(datsrc,datfft)) != FLGR_RET_OK) return ret;
00888
00889 if((nx/2+1) != datfft->size_x) {
00890 POST_ERROR("data containing fft must have a width equal to %d\n",nx/2+1);
00891 return FLGR_RET_SIZE_ERROR;
00892 }
00893
00894
00895 FLGR_DISPATCH_PROCEDURE(datsrc->type, flgr2d_fft_forward_real, datfft,datsrc);
00896 }
00897
00898
00900
00902 #define FLGR_MACRO_FFT_BACKWARD_REAL_2D(dtype,dtypename,prefix) \
00903 FILE *wisdom_file=NULL; \
00904 void *bufdest, *buffft; \
00905 prefix##_plan p_back; \
00906 int nx=datdest->size_x; \
00907 int ny=datdest->size_y; \
00908 \
00909 \
00910 \
00911 bufdest = flgr_malloc_align(nx*ny*sizeof(dtype),16); \
00912 buffft = flgr_malloc_align((nx/2+1)*ny*sizeof(dtype)*2,16); \
00913 \
00914 flgr2d_export_raw_##dtype(buffft,datfft); \
00915 \
00916 wisdom_file=flgr2d_fft_look_for_fftw_wisdom_file(ny,nx,0,dtypename, \
00917 "backward_c2r"); \
00918 if(wisdom_file!=NULL) prefix##_import_wisdom_from_file(wisdom_file); \
00919 \
00920 p_back = prefix##_plan_dft_c2r_2d(ny,nx,buffft,bufdest,FFTW_MEASURE); \
00921 \
00922 if(wisdom_file==NULL) { \
00923 wisdom_file=flgr2d_fft_create_fftw_wisdom_file(ny,nx,0,dtypename, \
00924 "backward_c2r"); \
00925 prefix##_export_wisdom_to_file(wisdom_file); \
00926 POST_INFO("fftw wisdom created\n"); \
00927 } \
00928 \
00929 prefix##_execute(p_back); \
00930 \
00931 prefix##_destroy_plan(p_back); \
00932 \
00933 fclose(wisdom_file); \
00934 \
00935 flgr2d_import_raw_##dtype(datdest,bufdest); \
00936 \
00937 flgr_free_align(bufdest); \
00938 flgr_free_align(buffft)
00939
00940
00941 void flgr2d_fft_backward_real_fgBIT(FLGR_Data2D *datdest, FLGR_Data2D *datfft) {
00942 flgr_no_define_type_function(FLGR_BIT);
00943 }
00944 void flgr2d_fft_backward_real_fgUINT8(FLGR_Data2D *datdest, FLGR_Data2D *datfft) {
00945 flgr_no_define_type_function(FLGR_UINT8);
00946 }
00947 void flgr2d_fft_backward_real_fgUINT16(FLGR_Data2D *datdest, FLGR_Data2D *datfft) {
00948 flgr_no_define_type_function(FLGR_UINT16);
00949 }
00950 void flgr2d_fft_backward_real_fgUINT32(FLGR_Data2D *datdest, FLGR_Data2D *datfft) {
00951 flgr_no_define_type_function(FLGR_UINT32);
00952 }
00953 void flgr2d_fft_backward_real_fgINT8(FLGR_Data2D *datdest, FLGR_Data2D *datfft) {
00954 flgr_no_define_type_function(FLGR_INT8);
00955 }
00956 void flgr2d_fft_backward_real_fgINT16(FLGR_Data2D *datdest, FLGR_Data2D *datfft) {
00957 flgr_no_define_type_function(FLGR_INT16);
00958 }
00959 void flgr2d_fft_backward_real_fgINT32(FLGR_Data2D *datdest, FLGR_Data2D *datfft) {
00960 flgr_no_define_type_function(FLGR_INT32);
00961 }
00962 void flgr2d_fft_backward_real_fgFLOAT32(FLGR_Data2D *datdest, FLGR_Data2D *datfft) {
00963 FLGR_MACRO_FFT_BACKWARD_REAL_2D(fgFLOAT32,FLGR_FLOAT32,fftwf);
00964 }
00965 void flgr2d_fft_backward_real_fgFLOAT64(FLGR_Data2D *datdest, FLGR_Data2D *datfft) {
00966 FLGR_MACRO_FFT_BACKWARD_REAL_2D(fgFLOAT64,FLGR_FLOAT64,fftw);
00967 }
00968
00969
00971
00976
00977 FLGR_Ret flgr2d_fft_backward_real(FLGR_Data2D *datdest, FLGR_Data2D *datfft) {
00978 FLGR_Ret ret;
00979 int nx;
00980
00981
00982
00983 if((datdest==NULL) || (datfft==NULL)){
00984 POST_ERROR("Null objects!\n");
00985 return FLGR_RET_NULL_OBJECT;
00986 }
00987
00988 nx = datdest->size_x;
00989
00990 if(datdest->spp!=1) {
00991 POST_ERROR("Multi Sample Per Pixel not supported\n");
00992 return FLGR_RET_UNDEFINED_ERROR;
00993 }
00994
00995
00996 if(datfft->spp!=2) {
00997 POST_ERROR("data containing fft must be complex (spp=2)\n");
00998 return FLGR_RET_NULL_OBJECT;
00999 }
01000
01001 if((ret=flgr2d_is_data_same_type(datdest,datfft)) != FLGR_RET_OK) return ret;
01002
01003 if((nx/2+1) != datfft->size_x) {
01004 POST_ERROR("data containing fft must have a width equal to %d\n",nx/2+1);
01005 return FLGR_RET_SIZE_ERROR;
01006 }
01007
01008 FLGR_DISPATCH_PROCEDURE(datdest->type, flgr2d_fft_backward_real, datdest,datfft);
01009
01010 return FLGR_RET_OK;
01011 }
01012
01013
01014
01015
01016
01017
01018
01019
01021
01023 #define FLGR_MACRO_SWITCH_CORNER_2D(dtype) \
01024 dtype *pdestA,*pdestB,*pdestC,*pdestD; \
01025 dtype *psrcA,*psrcB,*psrcC,*psrcD; \
01026 int i; \
01027 int spp = datdest->spp; \
01028 int h2 = datdest->size_y>>1; \
01029 int w2 = (datdest->size_x>>1)*spp; \
01030 \
01031 \
01032 \
01033 for(i=0 ; i < h2 ; i++) { \
01034 psrcA = (dtype *) datsrc->array[i]; \
01035 psrcB = psrcA+w2; \
01036 psrcC = (dtype *) datsrc->array[i+h2]; \
01037 psrcD = psrcC+w2; \
01038 \
01039 pdestB = (dtype *) datdest->array[i+h2]; \
01040 pdestA = pdestB+w2; \
01041 pdestD = (dtype *) datdest->array[i]; \
01042 pdestC = pdestD+w2; \
01043 \
01044 memcpy(pdestA,psrcA,sizeof(dtype)*w2); \
01045 memcpy(pdestB,psrcB,sizeof(dtype)*w2); \
01046 memcpy(pdestC,psrcC,sizeof(dtype)*w2); \
01047 memcpy(pdestD,psrcD,sizeof(dtype)*w2); \
01048 \
01049 } \
01050 \
01051 return
01052
01053
01054
01055 void flgr2d_fft_switch_corner_fgBIT(FLGR_Data2D *datdest, FLGR_Data2D *datsrc) {
01056 flgr_no_define_type_function(FLGR_BIT);
01057 }
01058 void flgr2d_fft_switch_corner_fgUINT8(FLGR_Data2D *datdest, FLGR_Data2D *datsrc) {
01059 FLGR_MACRO_SWITCH_CORNER_2D(fgUINT8);
01060 }
01061 void flgr2d_fft_switch_corner_fgUINT16(FLGR_Data2D *datdest, FLGR_Data2D *datsrc) {
01062 FLGR_MACRO_SWITCH_CORNER_2D(fgUINT16);
01063 }
01064 void flgr2d_fft_switch_corner_fgUINT32(FLGR_Data2D *datdest, FLGR_Data2D *datsrc) {
01065 FLGR_MACRO_SWITCH_CORNER_2D(fgUINT32);
01066 }
01067 void flgr2d_fft_switch_corner_fgINT8(FLGR_Data2D *datdest, FLGR_Data2D *datsrc) {
01068 FLGR_MACRO_SWITCH_CORNER_2D(fgINT8);
01069 }
01070 void flgr2d_fft_switch_corner_fgINT16(FLGR_Data2D *datdest, FLGR_Data2D *datsrc) {
01071 FLGR_MACRO_SWITCH_CORNER_2D(fgINT16);
01072 }
01073 void flgr2d_fft_switch_corner_fgINT32(FLGR_Data2D *datdest, FLGR_Data2D *datsrc) {
01074 FLGR_MACRO_SWITCH_CORNER_2D(fgINT32);
01075 }
01076 void flgr2d_fft_switch_corner_fgFLOAT32(FLGR_Data2D *datdest, FLGR_Data2D *datsrc) {
01077 FLGR_MACRO_SWITCH_CORNER_2D(fgFLOAT32);
01078 }
01079 void flgr2d_fft_switch_corner_fgFLOAT64(FLGR_Data2D *datdest, FLGR_Data2D *datsrc) {
01080 FLGR_MACRO_SWITCH_CORNER_2D(fgFLOAT64);
01081 }
01083
01088
01089 FLGR_Ret flgr2d_fft_switch_corner(FLGR_Data2D *datdest, FLGR_Data2D *datsrc) {
01090 FLGR_Ret ret;
01091
01092
01093
01094 if((datdest==NULL) || (datsrc==NULL)){
01095 POST_ERROR("Null objects!\n");
01096 return FLGR_RET_NULL_OBJECT;
01097 }
01098
01099 if((ret=flgr2d_is_data_same_attributes(datdest,datsrc,__FUNCTION__)) != FLGR_RET_OK) return ret;
01100
01101 FLGR_DISPATCH_PROCEDURE(datdest->type, flgr2d_fft_switch_corner, datdest,datsrc);
01102
01103 }
01104
01105
01106