irplib_fft.c

00001 /* $Id: irplib_fft.c,v 1.1 2008/06/03 15:56:32 lbilbao Exp $
00002  *
00003  * This file is part of the irplib package
00004  * Copyright (C) 2002, 2003 European Southern Observatory
00005  *
00006  * This program is free software; you can redistribute it and/or modify
00007  * it under the terms of the GNU General Public License as published by
00008  * the Free Software Foundation; either version 2 of the License, or
00009  * (at your option) any later version.
00010  *
00011  * This program is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00014  * GNU General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU General Public License
00017  * along with this program; if not, write to the Free Software
00018  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02111-1307 USA
00019  */
00020 
00021 /*
00022  * $Author: lbilbao $
00023  * $Date: 2008/06/03 15:56:32 $
00024  * $Revision: 1.1 $
00025  * $Name: visir-3_2_2 $
00026  */
00027 
00028 #ifdef HAVE_CONFIG_H
00029 #include <config.h>
00030 #endif
00031 
00032 /*----------------------------------------------------------------------------
00033                                   Includes
00034  ----------------------------------------------------------------------------*/
00035 
00036 #include "irplib_fft.h"
00037 
00038 #if HAVE_FFTW == 1
00039 
00040 #include <fftw.h>
00041 #include <rfftw.h>
00042 
00043 #define FFTW_PREC double
00044 #define FFTW_PREC_CODE 0
00045 #define FFTW_PREC_STRING DOUBLE
00046 
00047 #elif HAVE_SFFTW == 1
00048 
00049 #include <sfftw.h>
00050 #include <srfftw.h>
00051 
00052 #define FFTW_PREC float
00053 #define FFTW_PREC_CODE 1
00054 #define FFTW_PREC_STRING FLOAT
00055 
00056 #elif HAVE_DFFTW == 1
00057 
00058 #include <dfftw.h>
00059 #include <drfftw.h>
00060 
00061 #define FFTW_PREC double
00062 #define FFTW_PREC_CODE 0
00063 #define FFTW_PREC_STRING DOUBLE
00064 
00065 #endif
00066 
00067 #include <complex.h>
00068 #include <assert.h>
00069 
00070 #if HAVE_FFTW == 1 || HAVE_SFFTW == 1 || HAVE_DFFTW == 1
00071 
00072 cpl_error_code 
00073 irplib_imagelist_fft_double_double(cpl_imagelist       * real_out,
00074                                    cpl_imagelist       * imag_out,
00075                                    const cpl_imagelist * real_in,
00076                    const cpl_imagelist * imag_in,
00077                                    unsigned              mode);
00078 
00079 cpl_error_code 
00080 irplib_imagelist_fft_double_float(cpl_imagelist       * real_out,
00081                                   cpl_imagelist       * imag_out,
00082                                   const cpl_imagelist * real_in,
00083                   const cpl_imagelist * imag_in,
00084                                   unsigned              mode);
00085 
00086 cpl_error_code 
00087 irplib_imagelist_fft_float_double(cpl_imagelist       * real_out,
00088                                   cpl_imagelist       * imag_out,
00089                                   const cpl_imagelist * real_in,
00090                   const cpl_imagelist * imag_in,
00091                                   unsigned              mode);
00092 
00093 cpl_error_code 
00094 irplib_imagelist_fft_float_float(cpl_imagelist       * real_out,
00095                                  cpl_imagelist       * imag_out,
00096                                  const cpl_imagelist * real_in,
00097                  const cpl_imagelist * imag_in,
00098                                  unsigned              mode);
00099 cpl_error_code 
00100 irplib_imagelist_fft_int_double(cpl_imagelist       * real_out,
00101                                 cpl_imagelist       * imag_out,
00102                                 const cpl_imagelist * real_in,
00103                 const cpl_imagelist * imag_in,
00104                                 unsigned              mode);
00105 
00106 cpl_error_code 
00107 irplib_imagelist_fft_int_float(cpl_imagelist       * real_out,
00108                                cpl_imagelist       * imag_out,
00109                                const cpl_imagelist * real_in,
00110                    const cpl_imagelist * imag_in,
00111                                unsigned              mode);
00112 
00113 cpl_error_code 
00114 irplib_image_fft_double_double(cpl_image       * real_out,
00115                    cpl_image       * imag_out,
00116                    const cpl_image * real_in,
00117                    const cpl_image * imag_in,
00118                    unsigned          mode);
00119 
00120 cpl_error_code 
00121 irplib_image_fft_double_float(cpl_image       * real_out,
00122                   cpl_image       * imag_out,
00123                   const cpl_image * real_in,
00124                   const cpl_image * imag_in,
00125                   unsigned          mode);
00126 
00127 cpl_error_code 
00128 irplib_image_fft_float_double(cpl_image       * real_out,
00129                   cpl_image       * imag_out,
00130                   const cpl_image * real_in,
00131                   const cpl_image * imag_in,
00132                   unsigned          mode);
00133 
00134 cpl_error_code 
00135 irplib_image_fft_float_float(cpl_image       * real_out,
00136                  cpl_image       * imag_out,
00137                  const cpl_image * real_in,
00138                  const cpl_image * imag_in,
00139                  unsigned          mode);
00140 cpl_error_code 
00141 irplib_image_fft_int_double(cpl_image       * real_out,
00142                 cpl_image       * imag_out,
00143                 const cpl_image * real_in,
00144                 const cpl_image * imag_in,
00145                 unsigned          mode);
00146 
00147 cpl_error_code 
00148 irplib_image_fft_int_float(cpl_image       * real_out,
00149                cpl_image       * imag_out,
00150                const cpl_image * real_in,
00151                const cpl_image * imag_in,
00152                unsigned          mode);
00153 
00154 /*---------------------------------------------------------------------------*/
00191 /*---------------------------------------------------------------------------*/
00192 
00193 cpl_error_code irplib_imagelist_fft(cpl_imagelist       * real_out,
00194                     cpl_imagelist       * imag_out,
00195                     const cpl_imagelist * real_in,
00196                     const cpl_imagelist * imag_in,
00197                     unsigned              mode)
00198 {
00199     cpl_type       in_type, out_type;
00200 
00201     cpl_ensure_code(real_out != NULL && real_in != NULL, CPL_ERROR_NULL_INPUT);
00202 
00203     in_type  = cpl_image_get_type(cpl_imagelist_get_const(real_in,  0));
00204     out_type = cpl_image_get_type(cpl_imagelist_get_const(real_out, 0));
00205 
00206     switch (in_type) {
00207     case CPL_TYPE_DOUBLE: {
00208 
00209     switch (out_type) {
00210     case CPL_TYPE_DOUBLE:
00211         irplib_imagelist_fft_double_double(real_out, imag_out,
00212                            real_in, imag_in, mode);
00213         break;
00214     case CPL_TYPE_FLOAT:
00215         irplib_imagelist_fft_double_float(real_out, imag_out,
00216                           real_in, imag_in, mode);
00217         break;
00218     default:
00219         /* It is an error in CPL to reach this point */
00220         assert( 0 );
00221     }
00222 
00223     break;
00224     }
00225     case CPL_TYPE_FLOAT: {
00226 
00227     switch (out_type) {
00228     case CPL_TYPE_DOUBLE:
00229         irplib_imagelist_fft_float_double(real_out, imag_out,
00230                           real_in, imag_in, mode);
00231         break;
00232     case CPL_TYPE_FLOAT:
00233         irplib_imagelist_fft_float_float(real_out, imag_out,
00234                          real_in, imag_in, mode);
00235         break;
00236     default:
00237         /* It is an error in CPL to reach this point */
00238         assert( 0 );
00239     }
00240 
00241     break;
00242     }
00243     case CPL_TYPE_INT: {
00244 
00245     switch (out_type) {
00246     case CPL_TYPE_DOUBLE:
00247         irplib_imagelist_fft_int_double(real_out, imag_out,
00248                         real_in, imag_in, mode);
00249         break;
00250     case CPL_TYPE_FLOAT:
00251         irplib_imagelist_fft_int_float(real_out, imag_out,
00252                        real_in, imag_in, mode);
00253         break;
00254     default:
00255         /* It is an error in CPL to reach this point */
00256         assert( 0 );
00257     }
00258 
00259     break;
00260     }
00261     default:
00262     /* It is an error in CPL to reach this point. */
00263         assert( 0 );
00264     }       
00265 
00266     return cpl_error_get_code();
00267 }
00268 
00269 /*---------------------------------------------------------------------------*/
00306 /*---------------------------------------------------------------------------*/
00307 
00308 cpl_error_code irplib_image_fft(cpl_image       * real_out,
00309                 cpl_image       * imag_out,
00310                 const cpl_image * real_in,
00311                 const cpl_image * imag_in,
00312                 unsigned          mode)
00313 {
00314     cpl_type       in_type, out_type;
00315 
00316     cpl_ensure_code(real_out != NULL && real_in != NULL, CPL_ERROR_NULL_INPUT);
00317 
00318     in_type  = cpl_image_get_type(real_in);
00319     out_type = cpl_image_get_type(real_out);
00320 
00321     switch (in_type) {
00322     case CPL_TYPE_DOUBLE: {
00323 
00324     switch (out_type) {
00325     case CPL_TYPE_DOUBLE:
00326         irplib_image_fft_double_double(real_out, imag_out,
00327                            real_in, imag_in, mode);
00328         break;
00329     case CPL_TYPE_FLOAT:
00330         irplib_image_fft_double_float(real_out, imag_out,
00331                           real_in, imag_in, mode);
00332         break;
00333     default:
00334         /* It is an error in CPL to reach this point */
00335         assert( 0 );
00336     }
00337 
00338     break;
00339     }
00340     case CPL_TYPE_FLOAT: {
00341 
00342     switch (out_type) {
00343     case CPL_TYPE_DOUBLE:
00344         irplib_image_fft_float_double(real_out, imag_out,
00345                       real_in, imag_in, mode);
00346         break;
00347     case CPL_TYPE_FLOAT:
00348         irplib_image_fft_float_float(real_out, imag_out,
00349                      real_in, imag_in, mode);
00350         break;
00351     default:
00352         /* It is an error in CPL to reach this point */
00353         assert( 0 );
00354     }
00355 
00356     break;
00357     }
00358     case CPL_TYPE_INT: {
00359 
00360     switch (out_type) {
00361     case CPL_TYPE_DOUBLE:
00362         irplib_image_fft_int_double(real_out, imag_out,
00363                     real_in, imag_in, mode);
00364         break;
00365     case CPL_TYPE_FLOAT:
00366         irplib_image_fft_int_float(real_out, imag_out,
00367                        real_in, imag_in, mode);
00368         break;
00369     default:
00370         /* It is an error in CPL to reach this point */
00371         assert( 0 );
00372     }
00373 
00374     break;
00375     }
00376     default:
00377     /* It is an error in CPL to reach this point. */
00378         assert( 0 );
00379     }       
00380 
00381     return cpl_error_get_code();
00382 }
00383 
00384 #undef IN_TYPE
00385 #undef OUT_TYPE
00386 #undef IN_TYPE_CODE
00387 #undef OUT_TYPE_CODE
00388 
00389 #define IN_TYPE double
00390 #define IN_TYPE_CODE 0
00391 #define OUT_TYPE double
00392 #define OUT_TYPE_CODE 0
00393 #include "irplib_fft_body.h"
00394 
00395 #undef IN_TYPE
00396 #undef OUT_TYPE
00397 #undef IN_TYPE_CODE
00398 #undef OUT_TYPE_CODE
00399 
00400 #define IN_TYPE double
00401 #define IN_TYPE_CODE 0
00402 #define OUT_TYPE float
00403 #define OUT_TYPE_CODE 1
00404 #include "irplib_fft_body.h"
00405 
00406 #undef IN_TYPE
00407 #undef OUT_TYPE
00408 #undef IN_TYPE_CODE
00409 #undef OUT_TYPE_CODE
00410 
00411 #define IN_TYPE float
00412 #define IN_TYPE_CODE 1
00413 #define OUT_TYPE double
00414 #define OUT_TYPE_CODE 0
00415 #include "irplib_fft_body.h"
00416 
00417 #undef IN_TYPE
00418 #undef OUT_TYPE
00419 #undef IN_TYPE_CODE
00420 #undef OUT_TYPE_CODE
00421 
00422 #define IN_TYPE float
00423 #define IN_TYPE_CODE 1
00424 #define OUT_TYPE float
00425 #define OUT_TYPE_CODE 1
00426 #include "irplib_fft_body.h"
00427 
00428 #undef IN_TYPE
00429 #undef OUT_TYPE
00430 #undef IN_TYPE_CODE
00431 #undef OUT_TYPE_CODE
00432 
00433 #define IN_TYPE int
00434 #define IN_TYPE_CODE 2
00435 #define OUT_TYPE double
00436 #define OUT_TYPE_CODE 0
00437 #include "irplib_fft_body.h"
00438 
00439 #undef IN_TYPE
00440 #undef OUT_TYPE
00441 #undef IN_TYPE_CODE
00442 #undef OUT_TYPE_CODE
00443 
00444 #define IN_TYPE int
00445 #define IN_TYPE_CODE 2
00446 #define OUT_TYPE float
00447 #define OUT_TYPE_CODE 1
00448 #include "irplib_fft_body.h"
00449 
00450 #undef IN_TYPE
00451 #undef OUT_TYPE
00452 #undef IN_TYPE_CODE
00453 #undef OUT_TYPE_CODE
00454 
00455 #endif /* Corresponds to first if HAVE_{FFTW, SFFTW, DFFTW} == 1 */
00456 
00457 #undef FFTW_PREC
00458 #undef FFTW_PREC_CODE
00459 #undef FFTW_PREC_STRING

Generated on Fri Jul 3 11:15:22 2009 for VISIR Pipeline Reference Manual by  doxygen 1.5.8