gegl r2331 - in branches/branch_zhangjb: . operations/frequency/tools



Author: zhangjb
Date: Wed May 21 20:04:54 2008
New Revision: 2331
URL: http://svn.gnome.org/viewvc/gegl?rev=2331&view=rev

Log:
* operations/frequency/tools/dft.c: added the function idft.

Modified:
   branches/branch_zhangjb/ChangeLog
   branches/branch_zhangjb/operations/frequency/tools/dft.c

Modified: branches/branch_zhangjb/operations/frequency/tools/dft.c
==============================================================================
--- branches/branch_zhangjb/operations/frequency/tools/dft.c	(original)
+++ branches/branch_zhangjb/operations/frequency/tools/dft.c	Wed May 21 20:04:54 2008
@@ -16,7 +16,7 @@
  * Copyright 2008 Zhang Junbo  <zhangjb svn gnome org>
  */
 
-static gint
+static gint 
 fft_complex_get_half_id(gint x, gint y, gint width, gint height)
 {
   if (x >= FFT_HALF(x))
@@ -32,10 +32,10 @@
 
 gboolean 
 dft(gdouble *src_buf,
-             gdouble *dst_real_buf,
-             gdouble *dst_imag_buf,
-             gint width,
-             gint height)
+    gdouble *dst_real_buf,
+    gdouble *dst_imag_buf,
+    gint width,
+    gint height)
 {
   gint i, j;
   fftw_complex *fft_out;
@@ -44,7 +44,7 @@
   fft_out = (fftw_complex*) fftw_malloc(sizeof(fftw_complex) * height
       * FFT_HALF(width));
   fftplan
-      = fftw_plan_dft_r2c_2d(height, width, src_buf, fft_out, FFTW_ESTIMATE);
+      = fftw_plan_dft_r2c_2d(width, height, src_buf, fft_out, FFTW_ESTIMATE);
   fftw_execute(fftplan);
 
   for (i=0; i<height; i++)
@@ -59,7 +59,7 @@
           else
             {
               dst_real_buf[ELEM_ID_MATRIX(j, i, width)] = fft_out[fft_complex_get_half_id(j, i, width, height)][0];
-              dst_imag_buf[ELEM_ID_MATRIX(j, i, width)] = fft_out[fft_complex_get_half_id(j, i, width, height)][1];
+              dst_imag_buf[ELEM_ID_MATRIX(j, i, width)] = 0-fft_out[fft_complex_get_half_id(j, i, width, height)][1];
             }
         }
     }
@@ -68,3 +68,39 @@
 
   return TRUE;
 }
+
+gboolean 
+idft(gdouble *src_real_buf,
+     gdouble *src_imag_buf,
+     gdouble *dst_buf,
+     gint width,
+     gint height)
+{
+  gint x, y;
+  fftw_complex *fft_in;
+  fftw_plan fftplan;
+  glong samples = height*width;
+
+  fft_in = (fftw_complex*) fftw_malloc(sizeof(fftw_complex) * height
+      * FFT_HALF(width));
+  for (y=0; y<height; y++)
+    {
+      for (x=0; x<FFT_HALF(width); x++)
+        {
+          fft_in[ELEM_ID_HALF_MATRIX(x, y, width)][0] = src_real_buf[ELEM_ID_MATRIX(x, y, width)];
+          fft_in[ELEM_ID_HALF_MATRIX(x, y, width)][1] = src_imag_buf[ELEM_ID_MATRIX(x, y, width)];
+        }
+    }
+
+  fftplan = fftw_plan_dft_c2r_2d(width, height, fft_in, dst_buf, FFTW_ESTIMATE);
+  fftw_execute(fftplan);
+  for (x=0; x<samples; x++)
+    {
+      dst_buf[x] /= samples;
+    }
+
+  fftw_destroy_plan(fftplan);
+  fftw_free(fft_in);
+
+  return TRUE;
+}



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]