gegl r2502 - in branches/branch2_zhangjb: . operations/frequency operations/frequency/tools



Author: zhangjb
Date: Thu Jun 26 21:12:12 2008
New Revision: 2502
URL: http://svn.gnome.org/viewvc/gegl?rev=2502&view=rev

Log:
	Restart from trunck. Added dft.c first.

	* AUTHORS:
	* configure.ac:
	* operations/frequency/Makefile.am:
	* operations/frequency/dft.c:
	* operations/frequency/tools/Makefile.am:
	* operations/frequency/tools/component.c:
	* operations/frequency/tools/fourier.c:


Added:
   branches/branch2_zhangjb/operations/frequency/
   branches/branch2_zhangjb/operations/frequency/Makefile.am
   branches/branch2_zhangjb/operations/frequency/dft.c
   branches/branch2_zhangjb/operations/frequency/tools/
   branches/branch2_zhangjb/operations/frequency/tools/Makefile.am
   branches/branch2_zhangjb/operations/frequency/tools/component.c
   branches/branch2_zhangjb/operations/frequency/tools/fourier.c
Modified:
   branches/branch2_zhangjb/AUTHORS
   branches/branch2_zhangjb/ChangeLog
   branches/branch2_zhangjb/configure.ac

Modified: branches/branch2_zhangjb/AUTHORS
==============================================================================
--- branches/branch2_zhangjb/AUTHORS	(original)
+++ branches/branch2_zhangjb/AUTHORS	Thu Jun 26 21:12:12 2008
@@ -6,8 +6,8 @@
 Richard Kralovic, Kevin Cozens, Victor Bogado, Martin Nordholts, Geert
 Jordaens, Michael Schumacher, John Marshall, Ãtienne Bersac, Mark Probst, HÃkon
 Hitland, Tor Lillqvist, Hans Breuer, Deji Akingunola and Bradley Broom,
-Hans Petter Jansson, Jan Heller, dmacks netscpace org, Sven Anders and 
-Hubert Figuiere.
+Hans Petter Jansson, Jan Heller, dmacks netscpace org, Sven Anders, 
+Hubert Figuiere and Zhang Junbo.
 
 Documentation:
 ^^^^^^^^^^^^^^

Modified: branches/branch2_zhangjb/configure.ac
==============================================================================
--- branches/branch2_zhangjb/configure.ac	(original)
+++ branches/branch2_zhangjb/configure.ac	Thu Jun 26 21:12:12 2008
@@ -50,6 +50,7 @@
 m4_define([openexr_required_version], [0.0.0])
 m4_define([sdl_required_version], [0.0.0])
 m4_define([graphviz_required_version], [0.0.0])
+m4_define([fftw3_required_version], [3.0.0])
 
 AC_INIT(gegl, gegl_major_version.gegl_minor_version.gegl_micro_version)
 AC_CONFIG_SRCDIR([gegl/gegl.h.in])
@@ -788,6 +789,18 @@
 #AC_SUBST(LCMS_LIBS)
 
 
+################
+# Check for FFTW
+################
+
+PKG_CHECK_MODULES(FFTW, fftw3,
+  have_fftw3="yes",
+  have_fftw3="no  (usable fftw3 not found)")
+AM_CONDITIONAL(HAVE_FFTW, test "x$have_fftw3" = "xyes")
+
+AC_SUBST(FFTW_CFLAGS) 
+AC_SUBST(FFTW_LIBS)
+
 
 
 #######################
@@ -825,6 +838,8 @@
 operations/common/Makefile
 operations/common/perlin/Makefile
 operations/external/Makefile
+operations/frequency/Makefile
+operations/frequency/tools/Makefile
 operations/generated/Makefile
 operations/workshop/Makefile
 operations/workshop/external/Makefile
@@ -869,5 +884,6 @@
   graphviz:       $have_graphviz
   avcodec:        $have_libavcodec
   avformat:       $have_libavformat
+  FFTW:           $have_fftw3
   V4L:            $have_v4l
 ]);

Added: branches/branch2_zhangjb/operations/frequency/Makefile.am
==============================================================================
--- (empty file)
+++ branches/branch2_zhangjb/operations/frequency/Makefile.am	Thu Jun 26 21:12:12 2008
@@ -0,0 +1,6 @@
+SUBDIRS = tools
+include $(top_srcdir)/operations/Makefile-operations.am
+
+INCLUDES = $(FFTW_CFLAGS)
+
+LDADD = $(FFTW_LIBS)
\ No newline at end of file

Added: branches/branch2_zhangjb/operations/frequency/dft.c
==============================================================================
--- (empty file)
+++ branches/branch2_zhangjb/operations/frequency/dft.c	Thu Jun 26 21:12:12 2008
@@ -0,0 +1,129 @@
+/* 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
+
+/* no properties */
+
+#else
+
+#define GEGL_CHANT_TYPE_FILTER
+#define GEGL_CHANT_C_FILE       "dft.c"
+
+#include "gegl-chant.h"
+#include "tools/fourier.c"
+#include "tools/component.c"
+#include <fftw3.h>
+
+static GeglRectangle
+get_bounding_box (GeglOperation *operation)
+{
+  GeglRectangle *in_rect = gegl_operation_source_get_bounding_box (operation,
+                                                                   "input");
+  GeglRectangle  result  = *in_rect;
+
+  result.width = FFT_HALF(result.width);
+  return result;
+}
+
+static GeglRectangle
+get_required_for_output(GeglOperation *operation,
+                        const gchar *input_pad,
+                        const GeglRectangle *roi)
+{
+  GeglRectangle result = *gegl_operation_source_get_bounding_box(operation,
+                                                                 "input");
+  return result;
+}
+
+static GeglRectangle
+get_cached_region(GeglOperation *operation,
+                  const GeglRectangle *roi)
+{
+  return get_bounding_box(operation);
+}
+
+static void
+prepare(GeglOperation *operation)
+{
+  gegl_operation_set_format(operation, "input", babl_format ("RGBA double"));
+  gegl_operation_set_format(operation, "output",
+                            babl_format ("frequency double"));
+}
+
+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;
+  gdouble *tmp_src_buf;
+  gdouble *tmp_dst_buf;
+  gint i;
+
+  src_buf = g_new0(gdouble, 4*width*height);
+  tmp_src_buf = g_new0(gdouble, width*height);
+  dst_buf = g_new0(gdouble, 8*width*FFT_HALF(width));
+  tmp_dst_buf = g_new0(gdouble, width*FFT_HALF(width));
+
+  gegl_buffer_get(input, 1.0, NULL, babl_format ("RGBA double"), src_buf,
+                  GEGL_AUTO_ROWSTRIDE);
+
+  for (i=0; i<4; i++)
+    {
+      get_rgba_component(src_buf, tmp_src_buf, i, width*height);
+      dft(tmp_src_buf, (fftw_complex *)tmp_dst_buf, width, height);
+      set_freq_component(tmp_dst_buf, dst_buf, i, FFT_HALF(width)*height);
+    }
+  
+  gegl_buffer_set(output, NULL, babl_format ("frequency double"), dst_buf,
+                  GEGL_AUTO_ROWSTRIDE);
+
+  g_free(src_buf);
+  g_free(dst_buf);
+  g_free(tmp_src_buf);
+  g_free(tmp_dst_buf);
+  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->get_bounding_box = get_bounding_box;
+  operation_class->get_required_for_output= get_required_for_output;
+  operation_class->get_cached_region = get_cached_region;
+
+  operation_class->name = "dft";
+  operation_class->categories = "frequency";
+  operation_class->description
+    = "Perform 2-D Discrete Fourier Transform for a RGBA image.";
+}
+
+#endif

Added: branches/branch2_zhangjb/operations/frequency/tools/Makefile.am
==============================================================================
--- (empty file)
+++ branches/branch2_zhangjb/operations/frequency/tools/Makefile.am	Thu Jun 26 21:12:12 2008
@@ -0,0 +1,4 @@
+EXTRA_DIST = \
+	fourier.c	\
+	display.c	\
+	component.c
\ No newline at end of file

Added: branches/branch2_zhangjb/operations/frequency/tools/component.c
==============================================================================
--- (empty file)
+++ branches/branch2_zhangjb/operations/frequency/tools/component.c	Thu Jun 26 21:12:12 2008
@@ -0,0 +1,79 @@
+/* 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>
+ */
+
+gboolean get_rgba_component(gdouble* src_buf, gdouble* comp_buf, gint place,
+                            glong samples);
+gboolean set_rgba_component(gdouble* comp_buf, gdouble* dst_buf, gint place,
+                            glong samples);
+gboolean get_freq_component(gdouble* src_buf, gdouble* comp_buf, gint place,
+                            glong samples);
+gboolean set_freq_component(gdouble* comp_buf, gdouble* dst_buf, gint place,
+                            glong samples);
+
+gboolean
+get_rgba_component(gdouble* src_buf, gdouble *comp_buf, gint place,
+                   glong samples)
+{
+  src_buf += place;
+  while (samples--)
+    {
+      *(comp_buf++) = *src_buf;
+      src_buf += 4;
+    }
+  return TRUE;
+}
+  
+gboolean
+set_rgba_component(gdouble* comp_buf, gdouble* dst_buf, gint place, glong samples)
+{
+  dst_buf += place;
+  while (samples--)
+    {
+      *dst_buf = *(comp_buf++);
+      dst_buf += 4;
+    }
+  return TRUE;
+}
+
+gboolean
+get_freq_component(gdouble* src_buf, gdouble *comp_buf, gint place,
+                   glong samples)
+{
+  src_buf += place*2;
+  while (samples--)
+    {
+      *(comp_buf++) = *src_buf;
+      *(comp_buf++) = *(src_buf+1);
+      src_buf += 8;
+    }
+  return TRUE;
+}
+  
+gboolean
+set_freq_component(gdouble* comp_buf, gdouble* dst_buf, gint place,
+                   glong samples)
+{
+  dst_buf += place*2;
+  while (samples--)
+    {
+      *dst_buf = *(comp_buf++);
+      *(dst_buf+1) = *(comp_buf++);
+      dst_buf += 8;
+    }
+  return TRUE;
+}

Added: branches/branch2_zhangjb/operations/frequency/tools/fourier.c
==============================================================================
--- (empty file)
+++ branches/branch2_zhangjb/operations/frequency/tools/fourier.c	Thu Jun 26 21:12:12 2008
@@ -0,0 +1,67 @@
+/* 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, fftw_complex *dst_buf_pointer, gint width, gint height);
+gboolean idft(fftw_complex *src_buf, gdouble *dst_buf, gint width, gint height);
+
+gboolean
+dft(gdouble *src_buf, fftw_complex *dst_buf, gint width, gint height)
+{
+  fftw_plan fftplan;
+
+  fftplan = fftw_plan_dft_r2c_2d(height,
+                                 width,
+                                 src_buf,
+                                 dst_buf,
+                                 FFTW_ESTIMATE);
+  fftw_execute(fftplan);
+  fftw_destroy_plan(fftplan);
+  return TRUE;
+}
+
+gboolean 
+idft(fftw_complex *src_buf, gdouble *dst_buf, gint width, gint height)
+{
+  glong i;
+  fftw_plan fftplan;
+  glong samples;
+
+  samples= height*width;
+  fftplan = fftw_plan_dft_c2r_2d(height,
+                                 width,
+                                 src_buf,
+                                 dst_buf,
+                                  FFTW_ESTIMATE);
+  fftw_execute(fftplan);
+  for (i=0; i<samples; i++)
+    {
+      dst_buf[i] /= samples;
+    }
+
+  fftw_destroy_plan(fftplan);
+  return TRUE;
+}



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