gegl r2336 - in branches/branch_zhangjb: . operations/frequency operations/frequency/tools tests/frequency
- From: zhangjb svn gnome org
- To: svn-commits-list gnome org
- Subject: gegl r2336 - in branches/branch_zhangjb: . operations/frequency operations/frequency/tools tests/frequency
- Date: Thu, 22 May 2008 13:25:42 +0000 (UTC)
Author: zhangjb
Date: Thu May 22 13:25:42 2008
New Revision: 2336
URL: http://svn.gnome.org/viewvc/gegl?rev=2336&view=rev
Log:
Changed the data struct to storage the frenqucy domain in a single buffer.
* operations/frequency/tools/dft.h: deleted from svn.
* operations/frequency/tools/display.c: modified to fit the new data struct.
* operations/frequency/tools/display.h: deleted from svn.
* operations/frequency/tools/dft.c: used new data struct.
* operations/frequency/dft-grey.c: used new dft function.
* operations/frequency/preview-frequency-grey.c: a new operation to preview frequency image.
* operations/frequency/dft-inverse-grey.c: a new operation to take idft on a grey image.
* tests/frequency/hello-world-fourier.c
Added:
branches/branch_zhangjb/operations/frequency/dft-inverse-grey.c (contents, props changed)
branches/branch_zhangjb/operations/frequency/preview-frequency-grey.c (contents, props changed)
Removed:
branches/branch_zhangjb/operations/frequency/tools/dft.h
branches/branch_zhangjb/operations/frequency/tools/display.h
Modified:
branches/branch_zhangjb/ (props changed)
branches/branch_zhangjb/ChangeLog
branches/branch_zhangjb/operations/frequency/dft-grey.c
branches/branch_zhangjb/operations/frequency/tools/dft.c
branches/branch_zhangjb/operations/frequency/tools/display.c
branches/branch_zhangjb/tests/frequency/hello-world-fourier.c
Modified: branches/branch_zhangjb/operations/frequency/dft-grey.c
==============================================================================
--- branches/branch_zhangjb/operations/frequency/dft-grey.c (original)
+++ branches/branch_zhangjb/operations/frequency/dft-grey.c Thu May 22 13:25:42 2008
@@ -1,6 +1,5 @@
/* This file is just for test. This operation can NOT be used in any
* practice case by now.
- *
*/
#ifdef GEGL_CHANT_PROPERTIES
@@ -13,32 +12,25 @@
#define GEGL_CHANT_C_FILE "dft-grey.c"
#include "gegl-chant.h"
-#include "tools/dft.h"
#include "tools/dft.c"
-#include "tools/display.h"
-#include "tools/display.c"
#include <fftw3.h>
-static GeglRectangle
-get_required_for_output(GeglOperation *operation,
- const gchar *input_pad,
- const GeglRectangle *roi)
+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)
+static GeglRectangle get_cached_region(GeglOperation *operation,
+ const GeglRectangle *roi)
{
- return *gegl_operation_source_get_bounding_box (operation, "input");
+ return *gegl_operation_source_get_bounding_box(operation, "input");
}
-
-static void
-prepare(GeglOperation *operation)
+static void prepare(GeglOperation *operation)
{
Babl *image_format = babl_format_new(babl_model("Y"),
babl_type("double"),
@@ -52,93 +44,37 @@
gegl_operation_set_format(operation, "output", frequency_format);
}
-static gboolean
-process(GeglOperation *operation,
- GeglBuffer *input,
- GeglBuffer *output,
- const GeglRectangle *result)
+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 *dst_imag_buf;
- gint i;
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);
-
- dst_buf = g_new0(gdouble, height*width);
- dst_imag_buf = g_new0(gdouble, height*width);
-
-#if 1
- dft(src_buf, dst_buf, dst_imag_buf, width, height);
- for (i=0; i<width*height; i++)
- {
- dst_buf[i] = sqrt(dst_buf[i]*dst_buf[i]+dst_imag_buf[i]*dst_imag_buf[i]);
- }
- zoomshow(dst_buf, width*height);
- shift_dft(dst_buf, width, height);
-#endif
-
-#if 0
- /* to show how many times this section be executed. */
- printf("@\t");
-#endif
-
-#if 0
- for (i=0; i<width*height; i++)
- {
- dst_buf[i] = src_buf[i];
- }
-#endif
+ 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);
+ dst_buf = g_new0(gdouble, 2*width*FFT_HALF(height));
-#if 0
- gint j;
- gdouble min, max;
- printf("input: width = %d, height = %d\n", width, height);
- for (i=0; i<width; i++)
- {
- for (j=0; j<height; j++)
- {
- printf("%lf\t", src_buf[ELEM_ID_MATRIX(j, i, width)]);
- }
- printf("\n");
- }
- get_min_max(src_buf, &min, &max, width*height);
- printf("min = %lf, max = %lf\n\n", min, max);
- printf("output: width = %d, height = %d\n", width, height);
- for (i=0; i<width; i++)
- {
- for (j=0; j<height; j++)
- {
- printf("%lf\t", dst_buf[ELEM_ID_MATRIX(j, i, width)]);
- }
- printf("\n");
- }
- get_min_max(dst_buf, &min, &max, width*height);
- printf("min = %lf, max = %lf\n", min, max);
-#endif
+ dft(src_buf, (fftw_complex *)dst_buf, width, height);
gegl_buffer_set(output,
- NULL, babl_format_new(babl_model("Y"),
- babl_type("double"),
- babl_component("Y"),
- NULL),
- dst_buf,
- GEGL_AUTO_ROWSTRIDE);
-
+ NULL, babl_format_new(babl_model("Y"),
+ babl_type("double"),
+ babl_component("Y"),
+ NULL), (gdouble *)dst_buf, GEGL_AUTO_ROWSTRIDE);
+ g_free(src_buf);
+ g_free(dst_buf);
return TRUE;
}
-static void
-gegl_chant_class_init(GeglChantClass *klass)
+static void gegl_chant_class_init(GeglChantClass *klass)
{
GeglOperationClass *operation_class;
GeglOperationFilterClass *filter_class;
@@ -154,7 +90,7 @@
operation_class->name = "dft-grey";
operation_class->categories = "frequency";
operation_class->description
- = "Perform 2-D Discrete Fourier Transform for the image.\n"
+ = "Perform 2-D inverse Discrete Fourier Transform .\n"
"Note this operation is just for test, which can NOT be "
"used to do anything by now.";
}
Added: branches/branch_zhangjb/operations/frequency/dft-inverse-grey.c
==============================================================================
--- (empty file)
+++ branches/branch_zhangjb/operations/frequency/dft-inverse-grey.c Thu May 22 13:25:42 2008
@@ -0,0 +1,97 @@
+/* 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
+
+#define GEGL_CHANT_TYPE_POINT_FILTER
+#define GEGL_CHANT_C_FILE "dft-inverse-grey.c"
+
+#include "gegl-chant.h"
+#include "tools/dft.c"
+#include <fftw3.h>
+
+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 *gegl_operation_source_get_bounding_box(operation, "input");
+}
+
+static void prepare(GeglOperation *operation)
+{
+ 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;
+
+ src_buf = g_new0(gdouble, 2*width*FFT_HALF(height));
+ gegl_buffer_get(input, 1.0,
+ NULL, babl_format_new(babl_model("Y"),
+ babl_type("double"),
+ babl_component("Y"),
+ NULL), (gdouble *)src_buf, GEGL_AUTO_ROWSTRIDE);
+ dst_buf = g_new0(gdouble, width*height);
+ idft((fftw_complex *)src_buf, dst_buf, width, height);
+
+ gegl_buffer_set(output,
+ NULL, babl_format_new(babl_model("Y"),
+ babl_type("double"),
+ babl_component("Y"),
+ NULL), dst_buf, GEGL_AUTO_ROWSTRIDE);
+ g_free(src_buf);
+ g_free(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_required_for_output= get_required_for_output;
+ operation_class->get_cached_region = get_cached_region;
+
+ operation_class->name = "dft-inverse-grey";
+ 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/preview-frequency-grey.c
==============================================================================
--- (empty file)
+++ branches/branch_zhangjb/operations/frequency/preview-frequency-grey.c Thu May 22 13:25:42 2008
@@ -0,0 +1,96 @@
+/* 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
+
+#define GEGL_CHANT_TYPE_POINT_FILTER
+#define GEGL_CHANT_C_FILE "preview-frequency-grey.c"
+
+#include "gegl-chant.h"
+#include "tools/display.c"
+#include <fftw3.h>
+
+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 *gegl_operation_source_get_bounding_box(operation, "input");
+}
+
+static void prepare(GeglOperation *operation)
+{
+ 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;
+
+ src_buf = g_new0(gdouble, 2*width*FFT_HALF(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);
+ dst_buf = g_new0(gdouble, 2*width*height);
+
+ fre2img((fftw_complex *)src_buf, dst_buf, width, height);
+
+ gegl_buffer_set(output,
+ NULL, babl_format_new(babl_model("Y"),
+ babl_type("double"),
+ babl_component("Y"),
+ NULL), (gdouble *)dst_buf, GEGL_AUTO_ROWSTRIDE);
+ g_free(src_buf);
+ g_free(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_required_for_output= get_required_for_output;
+ operation_class->get_cached_region = get_cached_region;
+
+ operation_class->name = "preview-frequency-grey";
+ operation_class->categories = "frequency";
+ operation_class->description
+ = "convert the frequency buffer to a diplayable image.";
+}
+
+#endif
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 Thu May 22 13:25:42 2008
@@ -16,91 +16,57 @@
* Copyright 2008 Zhang Junbo <zhangjb svn gnome org>
*/
-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;
-}
+#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
-dft(gdouble *src_buf,
- gdouble *dst_real_buf,
- gdouble *dst_imag_buf,
- gint width,
- gint height)
+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)
{
- gint i, j;
- fftw_complex *fft_out;
fftw_plan fftplan;
- fft_out = (fftw_complex*) fftw_malloc(sizeof(fftw_complex) * height
- * FFT_HALF(width));
- fftplan
- = fftw_plan_dft_r2c_2d(width, height, src_buf, fft_out, FFTW_ESTIMATE);
+ fftplan = fftw_plan_dft_r2c_2d(width,
+ height,
+ src_buf,
+ dst_buf,
+ FFTW_ESTIMATE);
fftw_execute(fftplan);
-
- for (i=0; i<height; i++)
- {
- for (j=0; j<width; j++)
- {
- if (j<FFT_HALF(width))
- {
- 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)] = 0-fft_out[fft_complex_get_half_id(j, i, width, height)][1];
- }
- }
- }
fftw_destroy_plan(fftplan);
- fftw_free(fft_out);
-
return TRUE;
}
gboolean
-idft(gdouble *src_real_buf,
- gdouble *src_imag_buf,
- gdouble *dst_buf,
- gint width,
- gint height)
+idft(fftw_complex *src_buf, gdouble *dst_buf, gint width, gint height)
{
- gint x, y;
- fftw_complex *fft_in;
+ glong i;
fftw_plan fftplan;
- glong samples = height*width;
+ glong samples;
- 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);
+ samples= height*width;
+ fftplan = fftw_plan_dft_c2r_2d(width,
+ height,
+ src_buf,
+ dst_buf,
+ FFTW_ESTIMATE);
fftw_execute(fftplan);
- for (x=0; x<samples; x++)
+ for (i=0; i<samples; i++)
{
- dst_buf[x] /= samples;
+ dst_buf[i] /= samples;
}
fftw_destroy_plan(fftplan);
- fftw_free(fft_in);
-
return TRUE;
}
Modified: branches/branch_zhangjb/operations/frequency/tools/display.c
==============================================================================
--- branches/branch_zhangjb/operations/frequency/tools/display.c (original)
+++ branches/branch_zhangjb/operations/frequency/tools/display.c Thu May 22 13:25:42 2008
@@ -16,8 +16,36 @@
* Copyright 2008 Zhang Junbo <zhangjb svn gnome org>
*/
-gboolean
-shift_dft(gdouble *buf, gint width, gint height)
+#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>
+#include <math.h>
+
+static gint fft_complex_get_half_id(gint x, gint y, gint width, gint height);
+gboolean shift_dft(gdouble *buf, gint width, gint height);
+void get_min_max(gdouble *buf, gdouble *min, gdouble *max, glong samples);
+gboolean zoomshow(gdouble *buf, glong samples);
+gboolean fre2img(fftw_complex *src_buf, gdouble *des_buf, gint width, gint height);
+
+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;
+}
+
+gboolean shift_dft(gdouble *buf, gint width, gint height)
{
gint cx, cy;
gint add_x, add_y;
@@ -44,8 +72,7 @@
return TRUE;
}
-void
-get_min_max (gdouble *buf, gdouble *min, gdouble *max, glong samples)
+void get_min_max(gdouble *buf, gdouble *min, gdouble *max, glong samples)
{
gfloat tmin = 9000000.0;
gfloat tmax =-9000000.0;
@@ -65,14 +92,13 @@
*max = tmax;
}
-gboolean
-zoomshow(gdouble *buf, glong samples)
+gboolean zoomshow(gdouble *buf, glong samples)
{
glong i;
gdouble min, max;
for (i=0; i<samples; i++)
- {
+ {
if (*(buf+i)<1)
*(buf+i) = 0;
else
@@ -80,8 +106,47 @@
}
get_min_max(buf, &min, &max, samples);
for (i=0; i<samples; i++)
- {
- *(buf+i) = (*(buf+i))/max;
- }
+ {
+ *(buf+i) = (*(buf+i))/max;
+ }
+ return TRUE;
+}
+
+gboolean fre2img(fftw_complex *src_buf, gdouble *dst_buf, gint width, gint height)
+{
+ gint i, j;
+ glong samples = width*height;
+ gdouble *dst_real_buf;
+ gdouble *dst_imag_buf;
+
+ dst_real_buf = g_new0(gdouble, 2*width*height);
+ dst_imag_buf = g_new0(gdouble, 2*width*height);
+
+ for (i=0; i<height; i++)
+ {
+ for (j=0; j<width; j++)
+ {
+ if (j<FFT_HALF(width))
+ {
+ dst_real_buf[ELEM_ID_MATRIX(j, i, width)] = src_buf[ELEM_ID_HALF_MATRIX(j, i, width)][0];
+ dst_imag_buf[ELEM_ID_MATRIX(j, i, width)] = src_buf[ELEM_ID_HALF_MATRIX(j, i, width)][1];
+ }
+ else
+ {
+ dst_real_buf[ELEM_ID_MATRIX(j, i, width)] = src_buf[fft_complex_get_half_id(j, i, width, height)][0];
+ dst_imag_buf[ELEM_ID_MATRIX(j, i, width)] = 0-src_buf[fft_complex_get_half_id(j, i, width, height)][1];
+ }
+ }
+ }
+ for (i=0; i<width*height; i++)
+ {
+ dst_buf[i] = sqrt(dst_real_buf[i]*dst_real_buf[i]+dst_imag_buf[i]*dst_imag_buf[i]);
+ }
+ zoomshow(dst_buf, samples);
+ shift_dft(dst_buf, width, height);
+
+ g_free(dst_real_buf);
+ g_free(dst_imag_buf);
return TRUE;
+
}
Modified: branches/branch_zhangjb/tests/frequency/hello-world-fourier.c
==============================================================================
--- branches/branch_zhangjb/tests/frequency/hello-world-fourier.c (original)
+++ branches/branch_zhangjb/tests/frequency/hello-world-fourier.c Thu May 22 13:25:42 2008
@@ -15,7 +15,9 @@
"path",
"docs/images/lena_bw.png",
NULL);
- GeglNode *proc = gegl_node_new_child(gegl, "operation", "dft-grey", NULL);
+ GeglNode *dft = gegl_node_new_child(gegl, "operation", "dft-grey", NULL);
+ GeglNode *idft = gegl_node_new_child(gegl, "operation", "dft-inverse-grey", NULL);
+ GeglNode *preview = gegl_node_new_child(gegl, "operation", "preview-frequency-grey", NULL);
GeglNode *grey = gegl_node_new_child(gegl, "operation", "grey", NULL);
GeglNode *save = gegl_node_new_child(gegl,
"operation",
@@ -29,7 +31,7 @@
gegl_node_process(display);
}*/
- gegl_node_link_many(image, proc, save, NULL);
+ gegl_node_link_many(image, dft, preview, save, NULL);
gegl_node_process(save);
g_object_unref(gegl);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]