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



Author: zhangjb
Date: Mon May 12 05:42:43 2008
New Revision: 2282
URL: http://svn.gnome.org/viewvc/gegl?rev=2282&view=rev

Log:
a raw test (unable to use yet)

Added:
   branches/branch_zhangjb/operations/frequency/
   branches/branch_zhangjb/operations/frequency/Makefile.am
   branches/branch_zhangjb/operations/frequency/dft.c   (contents, props changed)
Modified:
   branches/branch_zhangjb/configure.ac
   branches/branch_zhangjb/operations/Makefile.am

Modified: branches/branch_zhangjb/configure.ac
==============================================================================
--- branches/branch_zhangjb/configure.ac	(original)
+++ branches/branch_zhangjb/configure.ac	Mon May 12 05:42:43 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])
@@ -785,6 +786,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)
+
 
 
 #######################
@@ -822,6 +835,7 @@
 operations/common/Makefile
 operations/common/perlin/Makefile
 operations/external/Makefile
+operations/frequency/Makefile
 operations/generated/Makefile
 operations/workshop/Makefile
 operations/workshop/external/Makefile
@@ -864,4 +878,5 @@
   graphviz:       $have_graphviz
   avcodec:        $have_libavcodec
   avformat:       $have_libavformat
+  FFTW:           $have_fftw3
 ]);

Modified: branches/branch_zhangjb/operations/Makefile.am
==============================================================================
--- branches/branch_zhangjb/operations/Makefile.am	(original)
+++ branches/branch_zhangjb/operations/Makefile.am	Mon May 12 05:42:43 2008
@@ -3,6 +3,7 @@
 	core		\
 	common		\
 	external	\
+	frequency	\
 	generated
 
 if ENABLE_WORKSHOP

Added: branches/branch_zhangjb/operations/frequency/Makefile.am
==============================================================================
--- (empty file)
+++ branches/branch_zhangjb/operations/frequency/Makefile.am	Mon May 12 05:42:43 2008
@@ -0,0 +1,5 @@
+include $(top_srcdir)/operations/Makefile-operations.am
+
+INCLUDES = $(FFTW_CFLAGS)
+
+LDADD = $(FFTW_LIBS)
\ No newline at end of file

Added: branches/branch_zhangjb/operations/frequency/dft.c
==============================================================================
--- (empty file)
+++ branches/branch_zhangjb/operations/frequency/dft.c	Mon May 12 05:42:43 2008
@@ -0,0 +1,112 @@
+/* This file is just for test. This operation can NOT be used in any 
+ * practice case by now. 
+ *   
+ */
+
+#ifdef GEGL_CHANT_PROPERTIES
+
+/* 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)
+{
+	if (x >= FFT_HALF(x)) {
+		if (y == 0)
+			return ELEM_ID_HALF_MATRIX(width-x, y, width);
+		else
+			return ELEM_ID_HALF_MATRIX(width-x, height-y, width);
+	} else
+		return 0;
+}
+
+static void prepare(GeglOperation *operation)
+{
+	Babl *image_format = babl_format("RGB float");
+	Babl *frequency_format = babl_format("Y float"); /* use "Y_float" temporarily */
+
+	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);
+	gfloat *src_buf, *dst_buf;
+	gint i, j;
+	fftw_complex *fft_out;
+	fftw_plan fftplan;
+
+	src_buf = g_new0 (gfloat, gegl_buffer_get_pixel_count (input) * 3);
+	gegl_buffer_get(input, 1.0, NULL, babl_format("RGB float"), src_buf, 
+	GEGL_AUTO_ROWSTRIDE);
+
+	/* fetch R component pixes */
+	dst_buf = g_new0 (gfloat, gegl_buffer_get_pixel_count (input));
+	for (i=0; i<width*height; i++) {
+		dst_buf[i] = src_buf[3 * i];
+	}
+
+	/* take DFT for the 'R' component of a RGB image */
+	fft_out = (fftw_complex*) fftw_malloc(sizeof(fftw_complex) * height
+			* FFT_HALF(width));
+	fftplan = fftw_plan_dft_r2c_2d(height, width, (float *)dst_buf, fft_out,
+									FFTW_ESTIMATE);
+	fftw_execute(fftplan);
+	
+	/* just for 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]/33614026;
+			else
+				dst_buf[ELEM_ID_MATRIX(j, i, width)] =
+					fft_out[fft_complex_get_half_id(i, i, width, height)][0]/33614026;
+		}
+	}
+	gegl_buffer_set(output, NULL, babl_format("Y float"), 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



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