00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifdef HAVE_CONFIG_H
00022 #include <config.h>
00023 #endif
00024
00025
00026
00027
00028
00029 #include <irplib_fft.h>
00030
00031 #include <cpl.h>
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042 #ifndef IMAGESIZE
00043 #define IMAGESIZE 128
00044 #endif
00045
00046 #ifndef IMLISTSIZE
00047 #define IMLISTSIZE 10
00048 #endif
00049
00050
00051
00052
00053
00054 static void irplib_fft_tests(void);
00055
00056 #if HAVE_FFTW == 1 || HAVE_SFFTW == 1 || HAVE_DFFTW == 1
00057
00058 void test_type(cpl_type intype, cpl_type outtype);
00059
00060 void test_real(cpl_type intype, cpl_type outtype);
00061
00062 void test_inplace(cpl_type type);
00063
00064 #endif
00065
00066
00067
00068
00069
00070
00071 int main(void)
00072 {
00073
00074 cpl_test_init(PACKAGE_BUGREPORT, CPL_MSG_WARNING);
00075
00076 irplib_fft_tests();
00077
00078 return cpl_test_end(0);
00079 }
00080
00081 static void irplib_fft_tests(void)
00082 {
00083 #if HAVE_FFTW == 1 || HAVE_SFFTW == 1 || HAVE_DFFTW == 1
00084
00085 test_type(CPL_TYPE_DOUBLE, CPL_TYPE_FLOAT);
00086 test_type(CPL_TYPE_DOUBLE, CPL_TYPE_DOUBLE);
00087
00088 test_type(CPL_TYPE_FLOAT, CPL_TYPE_FLOAT);
00089 test_type(CPL_TYPE_FLOAT, CPL_TYPE_DOUBLE);
00090
00091 test_type(CPL_TYPE_INT, CPL_TYPE_FLOAT);
00092 test_type(CPL_TYPE_INT, CPL_TYPE_DOUBLE);
00093
00094
00095 test_real(CPL_TYPE_FLOAT, CPL_TYPE_FLOAT);
00096 test_real(CPL_TYPE_FLOAT, CPL_TYPE_DOUBLE);
00097
00098 test_real(CPL_TYPE_INT, CPL_TYPE_FLOAT);
00099 test_real(CPL_TYPE_INT, CPL_TYPE_DOUBLE);
00100
00101 test_real(CPL_TYPE_DOUBLE, CPL_TYPE_FLOAT);
00102 test_real(CPL_TYPE_DOUBLE, CPL_TYPE_DOUBLE);
00103
00104 test_inplace(CPL_TYPE_DOUBLE);
00105 test_inplace(CPL_TYPE_FLOAT);
00106
00107 #endif
00108 }
00109
00110 #if HAVE_FFTW == 1 || HAVE_SFFTW == 1 || HAVE_DFFTW == 1
00111
00112 void test_type(cpl_type intype,
00113 cpl_type outtype)
00114 {
00115 cpl_imagelist * real_in = cpl_imagelist_new();
00116 cpl_imagelist * imag_in = cpl_imagelist_new();
00117 cpl_imagelist * real_out = cpl_imagelist_new();
00118 cpl_imagelist * imag_out = cpl_imagelist_new();
00119
00120 cpl_image * imreal_in = cpl_image_new(IMAGESIZE, IMAGESIZE, intype);
00121 cpl_image * imimag_in = cpl_image_new(IMAGESIZE, IMAGESIZE, intype);
00122 cpl_image * imreal_out = cpl_image_new(IMAGESIZE, IMAGESIZE, outtype);
00123 cpl_image * imimag_out = cpl_image_new(IMAGESIZE, IMAGESIZE, outtype);
00124
00125 cpl_image_add_scalar(imreal_in, 100);
00126
00127 int status;
00128 double flux, constant;
00129
00130 int i;
00131
00132 for (i = 0; i < IMLISTSIZE; i++) {
00133 cpl_image * im_real_in = cpl_image_new(IMAGESIZE, IMAGESIZE, intype);
00134 cpl_image * im_imag_in = cpl_image_new(IMAGESIZE, IMAGESIZE, intype);
00135 cpl_image * im_real_out = cpl_image_new(IMAGESIZE, IMAGESIZE, outtype);
00136 cpl_image * im_imag_out = cpl_image_new(IMAGESIZE, IMAGESIZE, outtype);
00137
00138
00139 cpl_image_add_scalar(im_real_in, i * 100);
00140
00141 cpl_imagelist_set(real_in, im_real_in, i);
00142 cpl_imagelist_set(imag_in, im_imag_in, i);
00143 cpl_imagelist_set(real_out, im_real_out, i);
00144 cpl_imagelist_set(imag_out, im_imag_out, i);
00145 }
00146
00147 irplib_imagelist_fft(real_out, imag_out,
00148 real_in, imag_in, IRPLIB_FFT_DEFAULT);
00149
00150 cpl_test_error(CPL_ERROR_NONE);
00151
00152 flux = cpl_image_get_flux(cpl_imagelist_get(real_out, 1));
00153 constant = cpl_image_get(cpl_imagelist_get(real_out, 1), 1, 1, &status);
00154
00155 cpl_test(flux == constant);
00156
00157 irplib_image_fft(imreal_out, imimag_out,
00158 imreal_in, imimag_in, IRPLIB_FFT_DEFAULT);
00159
00160 cpl_test_error(CPL_ERROR_NONE);
00161
00162 flux = cpl_image_get_flux(imreal_out);
00163 constant = cpl_image_get(imreal_out, 1, 1, &status);
00164
00165 cpl_test(flux == constant);
00166
00167 cpl_imagelist_delete(real_in);
00168 cpl_imagelist_delete(imag_in);
00169 cpl_imagelist_delete(real_out);
00170 cpl_imagelist_delete(imag_out);
00171
00172 cpl_image_delete(imreal_in);
00173 cpl_image_delete(imimag_in);
00174 cpl_image_delete(imreal_out);
00175 cpl_image_delete(imimag_out);
00176 }
00177
00178 void test_real(cpl_type intype,
00179 cpl_type outtype)
00180 {
00181 cpl_imagelist * real_in = cpl_imagelist_new();
00182
00183 cpl_imagelist * real_in_back = cpl_imagelist_new();
00184
00185 cpl_imagelist * real_out = cpl_imagelist_new();
00186 cpl_imagelist * imag_out = cpl_imagelist_new();
00187
00188 cpl_image * imreal_in = cpl_image_new(IMAGESIZE, IMAGESIZE, intype);
00189
00190 cpl_image * imreal_in_back = cpl_image_new(IMAGESIZE, IMAGESIZE, outtype);
00191
00192 cpl_image * imreal_out = cpl_image_new(IMAGESIZE, IMAGESIZE, outtype);
00193 cpl_image * imimag_out = cpl_image_new(IMAGESIZE, IMAGESIZE, outtype);
00194
00195 cpl_image_add_scalar(imreal_in, 100);
00196
00197 int status;
00198 double flux, constant, stdev;
00199
00200 int i;
00201
00202 for (i = 0; i < IMLISTSIZE; i++) {
00203 cpl_image * im_real_in = cpl_image_new(IMAGESIZE, IMAGESIZE, intype);
00204
00205 cpl_image * im_real_in_back =
00206 cpl_image_new(IMAGESIZE, IMAGESIZE, outtype);
00207
00208 cpl_image * im_real_out = cpl_image_new(IMAGESIZE, IMAGESIZE, outtype);
00209 cpl_image * im_imag_out = cpl_image_new(IMAGESIZE, IMAGESIZE, outtype);
00210
00211
00212 cpl_image_add_scalar(im_real_in, i * 100);
00213
00214 cpl_imagelist_set(real_in, im_real_in, i);
00215
00216 cpl_imagelist_set(real_in_back, im_real_in_back, i);
00217
00218 cpl_imagelist_set(real_out, im_real_out, i);
00219 cpl_imagelist_set(imag_out, im_imag_out, i);
00220 }
00221
00222 irplib_imagelist_fft(real_out, imag_out,
00223 real_in, NULL, IRPLIB_FFT_DEFAULT);
00224
00225 cpl_test_error(CPL_ERROR_NONE);
00226
00227 flux = cpl_image_get_flux(cpl_imagelist_get(real_out, 1));
00228 constant = cpl_image_get(cpl_imagelist_get(real_out, 1), 1, 1, &status);
00229
00230 cpl_test(flux == constant);
00231
00232 irplib_image_fft(imreal_out, imimag_out,
00233 imreal_in, NULL, IRPLIB_FFT_DEFAULT);
00234
00235 cpl_test_error(CPL_ERROR_NONE);
00236
00237 flux = cpl_image_get_flux(imreal_out);
00238 constant = cpl_image_get(imreal_out, 1, 1, &status);
00239
00240 cpl_test(flux == constant);
00241
00242 irplib_imagelist_fft(real_in_back, NULL,
00243 real_out, imag_out, IRPLIB_FFT_INVERSE);
00244
00245 cpl_test_error(CPL_ERROR_NONE);
00246
00247 stdev = cpl_image_get_stdev(cpl_imagelist_get(real_in_back, 1));
00248
00249 irplib_image_fft(imreal_in_back, NULL,
00250 imreal_out, imimag_out, IRPLIB_FFT_INVERSE);
00251
00252 cpl_test_error(CPL_ERROR_NONE);
00253
00254 stdev = cpl_image_get_stdev(imreal_in_back);
00255
00256 cpl_test_zero(stdev);
00257
00258 cpl_imagelist_delete(real_in);
00259
00260 cpl_imagelist_delete(real_in_back);
00261
00262 cpl_imagelist_delete(real_out);
00263 cpl_imagelist_delete(imag_out);
00264
00265 cpl_image_delete(imreal_in);
00266
00267 cpl_image_delete(imreal_in_back);
00268
00269 cpl_image_delete(imreal_out);
00270 cpl_image_delete(imimag_out);
00271 }
00272
00273 void test_inplace(cpl_type type)
00274 {
00275 cpl_imagelist * real_in = cpl_imagelist_new();
00276 cpl_imagelist * imag_in = cpl_imagelist_new();
00277
00278 int status;
00279 double flux, constant;
00280
00281 int i;
00282
00283 for (i = 0; i < IMLISTSIZE; i++) {
00284 cpl_image * im_real_in = cpl_image_new(IMAGESIZE, IMAGESIZE, type);
00285 cpl_image * im_imag_in = cpl_image_new(IMAGESIZE, IMAGESIZE, type);
00286
00287
00288 cpl_image_add_scalar(im_real_in, i * 100);
00289
00290 cpl_imagelist_set(real_in, im_real_in, i);
00291 cpl_imagelist_set(imag_in, im_imag_in, i);
00292 }
00293
00294 irplib_imagelist_fft(real_in, imag_in,
00295 real_in, imag_in, IRPLIB_FFT_DEFAULT);
00296
00297 cpl_test_error(CPL_ERROR_NONE);
00298
00299 flux = cpl_image_get_flux(cpl_imagelist_get(real_in, 1));
00300 constant = cpl_image_get(cpl_imagelist_get(real_in, 1), 1, 1, &status);
00301
00302 cpl_test(flux == constant);
00303
00304 cpl_imagelist_delete(real_in);
00305 cpl_imagelist_delete(imag_in);
00306 }
00307
00308 #endif