gegl r2317 - in branches/branch_zhangjb: . operations/frequency



Author: zhangjb
Date: Sun May 18 15:36:53 2008
New Revision: 2317
URL: http://svn.gnome.org/viewvc/gegl?rev=2317&view=rev

Log:
	* operations/frequency/dft.c: changed completely. this file is as
	the implement of dft.h now.
	* operations/frequency/dft.h: new tool sets for fourier transform.


Added:
   branches/branch_zhangjb/operations/frequency/dft.h
Modified:
   branches/branch_zhangjb/ChangeLog
   branches/branch_zhangjb/operations/frequency/dft.c

Modified: branches/branch_zhangjb/operations/frequency/dft.c
==============================================================================
--- branches/branch_zhangjb/operations/frequency/dft.c	(original)
+++ branches/branch_zhangjb/operations/frequency/dft.c	Sun May 18 15:36:53 2008
@@ -1,27 +1,25 @@
-/* This file is just for test. This operation can NOT be used in any 
- * practice case by now. 
- *   
+/* This file is a part of GEGL
+ *
+ * GEGL is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * GEGL is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with GEGL; if not, see <http://www.gnu.org/licenses/>.
+ *
+ * Copyright 2008 Zhang Junbo  <zhangjb svn gnome org>
  */
 
-#ifdef GEGL_CHANT_PROPERTIES
+#include "dft.h"
 
-/* no properties */
-
-#else
-
-#ifndef FFT_HALF
-#define FFT_HALF(n) (gint)((n)/2+1)
-#define ELEM_ID_MATRIX(x, y, c) ((y)*(c)+(x)) 
-#define ELEM_ID_HALF_MATRIX(x, y, c) ((y)*(FFT_HALF(c))+(x))
-#endif
-
-#define GEGL_CHANT_TYPE_POINT_FILTER
-#define GEGL_CHANT_C_FILE       "dft.c"
-
-#include "gegl-chant.h"
-#include <fftw3.h>
-
-static gint fft_complex_get_half_id(gint x, gint y, gint width, gint height)
+static gint
+fft_complex_get_half_id(gint x, gint y, gint width, gint height)
 {
   if (x >= FFT_HALF(x))
     {
@@ -34,123 +32,43 @@
     return 0;
 }
 
-static void
-prepare(GeglOperation *operation)
+gboolean
+dft (gdouble *src_buf,
+	 gdouble *dst_real_buf,
+	 gdouble *dst_imag_buf,
+	 gint width,
+	 gint height)
 {
-  Babl *image_format = babl_format_new(babl_model("Y"),
-                                       babl_type("double"),
-                                       babl_component("Y"),
-                                        NULL);
-  Babl *frequency_format = babl_format_new(babl_model("Y"),
-                                           babl_type("double"),
-                                           babl_component("Y"),
-                                            NULL);
-  gegl_operation_set_format(operation, "input", image_format);
-  gegl_operation_set_format(operation, "output", frequency_format);
-}
-
-static gboolean 
-process(GeglOperation *operation,
-                        GeglBuffer *input,
-                        GeglBuffer *output,
-                        const GeglRectangle *result)
-{
-  gint width= gegl_buffer_get_width(input);
-  gint height= gegl_buffer_get_height(input);
-  gdouble *src_buf;
-  gdouble *dst_buf;
   gint i, j;
   fftw_complex *fft_out;
   fftw_plan fftplan;
 
-  src_buf = g_new0(gdouble, width*height);
-  gegl_buffer_get(input, 1.0, 
-  NULL, babl_format_new(babl_model("Y"),
-                        babl_type("double"),
-                        babl_component("Y"),
-                         NULL), src_buf, GEGL_AUTO_ROWSTRIDE);
-
-#if 0
-  printf("width = %d, height = %d\n", width, height);
-  for (i=0; i<height; i++)
-    {
-      for (j=0; j<width; j++)
-        {
-          printf("%f\t", src_buf[ELEM_ID_MATRIX(j, i, width)]);
-        }
-      printf("\n");
-    }
-#endif
-
-  dst_buf = g_new0(gdouble, height*width);
-  for (i=0; i<width*height; i++)
-    {
-      dst_buf[i] = src_buf[i];
-    }
-
-  fft_out = (fftw_complex*) fftw_malloc(sizeof(fftw_complex) * height
-      * FFT_HALF(width));
-  fftplan = fftw_plan_dft_r2c_2d(height, width, (gdouble *)dst_buf, fft_out, 
-  FFTW_ESTIMATE);
+  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_execute(fftplan);
 
-  /* test: output the real component of the frequncy domain */
   for (i=0; i<height; i++)
     {
       for (j=0; j<width; j++)
         {
           if (j<FFT_HALF(width))
-            dst_buf[ELEM_ID_MATRIX(j, i, width)] = fft_out[ELEM_ID_HALF_MATRIX(j, i, width)][0];
-          else
-            dst_buf[ELEM_ID_MATRIX(j, i, width)] = fft_out[fft_complex_get_half_id(j, i, width, height)][0];
-        }
-    }
-
-#if 0
-  printf("output: width = %d, height = %d\n", width, height);
-  for (i=0; i<height; i++)
-    {
-      for (j=0; j<width; j++)
-        {
-          printf("%lf\t", dst_buf[ELEM_ID_MATRIX(j, i, width)]);
-        }
-      printf("\n");
+			{
+			  dst_real_buf[ELEM_ID_MATRIX(j, i, width)] =
+				fft_out[ELEM_ID_HALF_MATRIX(j, i, width)][0];
+			  dst_imag_buf[ELEM_ID_MATRIX(j, i, width)] =
+				fft_out[ELEM_ID_HALF_MATRIX(j, i, width)][1];
+			}
+		  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];
+			}
+		}
     }
-#endif
-
-  gegl_buffer_set(output,
-                  NULL,
-                  babl_format_new(babl_model("Y"),
-                                  babl_type("double"),
-                                  babl_component("Y"),
-                                   NULL),
-                  dst_buf,
-                  GEGL_AUTO_ROWSTRIDE);
-
   fftw_destroy_plan(fftplan);
   fftw_free(fft_out);
 
   return TRUE;
 }
-
-static void
-gegl_chant_class_init(GeglChantClass *klass)
-{
-  GeglOperationClass *operation_class;
-  GeglOperationFilterClass *filter_class;
-
-  operation_class = GEGL_OPERATION_CLASS(klass);
-  filter_class = GEGL_OPERATION_FILTER_CLASS(klass);
-
-  filter_class->process = process;
-  operation_class->prepare = prepare;
-
-  operation_class->name = "dft";
-  operation_class->categories = "frequency";
-  operation_class->description
-      = "Perform 2-D Discrete Fourier Transform for the image.\n"
-        "Note this operation is just for test, which can NOT be "
-        "used to do anything by now.";
-}
-
-#endif

Added: branches/branch_zhangjb/operations/frequency/dft.h
==============================================================================
--- (empty file)
+++ branches/branch_zhangjb/operations/frequency/dft.h	Sun May 18 15:36:53 2008
@@ -0,0 +1,45 @@
+/* This file is a part of GEGL
+ *
+ * GEGL is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * GEGL is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with GEGL; if not, see <http://www.gnu.org/licenses/>.
+ *
+ * Copyright 2008 Zhang Junbo  <zhangjb svn gnome org>
+ */
+
+#ifndef FFT_HALF
+#define FFT_HALF(n) (gint)((n)/2+1)
+#define ELEM_ID_MATRIX(x, y, c) ((y)*(c)+(x)) 
+#define ELEM_ID_HALF_MATRIX(x, y, c) ((y)*(FFT_HALF(c))+(x))
+#endif
+
+#include "gegl.h"
+#include <fftw3.h>
+
+gboolean
+dft (gdouble *src_buf,
+	 gdouble *dst_real_buf,
+	 gdouble *dst_imag_buf,
+	 gint width,
+	 gint height);
+
+gboolean
+idft (gdouble *src_real_buf,
+	  gdouble *src_imag_buf,
+	  gdouble *dst_buf,
+	  gint width,
+	  gint height);
+
+gboolean
+shift_dft (gdouble *buf,
+		   gint width,
+		   gint height);



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