gegl r2524 - in branches/branch2_zhangjb: . operations/frequency operations/frequency/tools
- From: zhangjb svn gnome org
- To: svn-commits-list gnome org
- Subject: gegl r2524 - in branches/branch2_zhangjb: . operations/frequency operations/frequency/tools
- Date: Mon, 7 Jul 2008 09:39:14 +0000 (UTC)
Author: zhangjb
Date: Mon Jul 7 09:39:13 2008
New Revision: 2524
URL: http://svn.gnome.org/viewvc/gegl?rev=2524&view=rev
Log:
* operations/frequency/homo-dft.c: new.
* operations/frequency/homo-idft.c: new.
* operations/frequency/tools/fourier.c: added homo_dft(), homo_idft().
Added:
branches/branch2_zhangjb/operations/frequency/homo-dft.c
branches/branch2_zhangjb/operations/frequency/homo-idft.c
Modified:
branches/branch2_zhangjb/ChangeLog
branches/branch2_zhangjb/operations/frequency/tools/fourier.c
Added: branches/branch2_zhangjb/operations/frequency/homo-dft.c
==============================================================================
--- (empty file)
+++ branches/branch2_zhangjb/operations/frequency/homo-dft.c Mon Jul 7 09:39:13 2008
@@ -0,0 +1,121 @@
+/* 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 "homo-dft.c"
+
+#include "gegl-chant.h"
+#include "tools/fourier.c"
+#include "tools/component.c"
+
+static GeglRectangle
+get_bounding_box (GeglOperation *operation)
+{
+ return *gegl_operation_source_get_bounding_box (operation, "input");
+}
+
+static GeglRectangle
+get_required_for_output(GeglOperation *operation,
+ const gchar *input_pad,
+ const GeglRectangle *roi)
+{
+ return *gegl_operation_source_get_bounding_box(operation, "input");
+}
+
+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*height*width);
+ tmp_dst_buf = g_new0(gdouble, 2*height*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);
+ homo_dft(tmp_src_buf, (fftw_complex *)tmp_dst_buf, width, height);
+ set_rgba_component(tmp_dst_buf, dst_buf, i, 2*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 = "homo-dft";
+ operation_class->categories = "frequency";
+ operation_class->description
+ = "Perform 2-D homomorphic Discrete Fourier Transform for a RGBA image.";
+}
+
+#endif
Added: branches/branch2_zhangjb/operations/frequency/homo-idft.c
==============================================================================
--- (empty file)
+++ branches/branch2_zhangjb/operations/frequency/homo-idft.c Mon Jul 7 09:39:13 2008
@@ -0,0 +1,120 @@
+/* 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 "homo-idft.c"
+
+#include "gegl-chant.h"
+#include "tools/fourier.c"
+#include "tools/component.c"
+
+static GeglRectangle
+get_bounding_box (GeglOperation *operation)
+{
+ return *gegl_operation_source_get_bounding_box (operation, "input");
+}
+
+static GeglRectangle
+get_cached_region(GeglOperation *operation,
+ const GeglRectangle *roi)
+{
+ return get_bounding_box(operation);
+}
+
+static GeglRectangle
+get_required_for_output(GeglOperation *operation,
+ const gchar *input_pad,
+ const GeglRectangle *roi)
+{
+ return *gegl_operation_source_get_bounding_box(operation, "input");
+}
+
+static void
+prepare(GeglOperation *operation)
+{
+ gegl_operation_set_format(operation, "input",
+ babl_format("frequency double"));
+ gegl_operation_set_format(operation, "output", babl_format("RGBA 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, 8*height*width);
+ dst_buf = g_new0(gdouble, 4*width*height);
+ tmp_src_buf = g_new0(gdouble, 2*height*FFT_HALF(width));
+ tmp_dst_buf = g_new0(gdouble, width*height);
+
+ gegl_buffer_get(input, 1.0, NULL, babl_format("frequency double"),
+ (gdouble *)src_buf, GEGL_AUTO_ROWSTRIDE);
+ for (i=0; i<4; i++)
+ {
+ get_rgba_component(src_buf, tmp_src_buf, i, 2*height*FFT_HALF(width));
+ homo_idft((fftw_complex *)tmp_src_buf, tmp_dst_buf, width, height);
+ set_rgba_component(tmp_dst_buf, dst_buf, i, width*height);
+ }
+
+ gegl_buffer_set(output, NULL, babl_format("RGBA 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 = "homo-idft";
+ operation_class->categories = "frequency";
+ operation_class->description
+ = "Perform 2-D homomorphic inverse Discrete Fourier Transform for the image.\n";
+}
+
+#endif
Modified: branches/branch2_zhangjb/operations/frequency/tools/fourier.c
==============================================================================
--- branches/branch2_zhangjb/operations/frequency/tools/fourier.c (original)
+++ branches/branch2_zhangjb/operations/frequency/tools/fourier.c Mon Jul 7 09:39:13 2008
@@ -23,10 +23,13 @@
#endif
#include "gegl.h"
+#include <math.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 homo_dft(gdouble *src_buf, fftw_complex *dst_buf_pointer, gint width, gint height);
+gboolean homo_idft(fftw_complex *src_buf, gdouble *dst_buf, gint width, gint height);
gboolean encode(gdouble *, gint);
gint decode(gdouble *);
@@ -109,3 +112,29 @@
}
}
+gboolean
+homo_dft(gdouble *src_buf, fftw_complex *dst_buf, gint width, gint height)
+{
+ glong i;
+
+ for (i=0; i<FFT_HALF(width)*height; i++)
+ {
+ src_buf[i] = log(src_buf[i]);
+ }
+ dft(src_buf, dst_buf, width, height);
+ return TRUE;
+}
+
+gboolean
+homo_idft(fftw_complex *src_buf, gdouble *dst_buf, gint width, gint height)
+{
+ glong i;
+
+ for (i=0; i<FFT_HALF(width)*height; i++)
+ {
+ src_buf[i][0] = exp(src_buf[i][0]);
+ src_buf[i][1] = exp(src_buf[i][1]);
+ }
+ idft(src_buf, dst_buf, width, height);
+ return TRUE;
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]