gegl r2316 - in branches/branch_zhangjb: . operations/common operations/frequency tests/frequency
- From: zhangjb svn gnome org
- To: svn-commits-list gnome org
- Subject: gegl r2316 - in branches/branch_zhangjb: . operations/common operations/frequency tests/frequency
- Date: Sun, 18 May 2008 06:54:47 +0000 (UTC)
Author: zhangjb
Date: Sun May 18 06:54:47 2008
New Revision: 2316
URL: http://svn.gnome.org/viewvc/gegl?rev=2316&view=rev
Log:
* operations/freqency/dft.c: very raw, but has have correct result.
* operations/common/grey.c: fix the bug cause by geglbuffer updating.
* tests/frequency/hello-world-fourier.c: modified this test case.
Modified:
branches/branch_zhangjb/ChangeLog
branches/branch_zhangjb/operations/common/grey.c
branches/branch_zhangjb/operations/frequency/dft.c
branches/branch_zhangjb/tests/frequency/hello-world-fourier.c
Modified: branches/branch_zhangjb/operations/common/grey.c
==============================================================================
--- branches/branch_zhangjb/operations/common/grey.c (original)
+++ branches/branch_zhangjb/operations/common/grey.c Sun May 18 06:54:47 2008
@@ -40,6 +40,14 @@
void *out_buf,
glong samples)
{
+ glong i;
+ gfloat *in = in_buf;
+ gfloat *out = out_buf;
+
+ for (i=0; i<2*samples; i++)
+ {
+ out[i]=in[i];
+ }
return TRUE;
}
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 06:54:47 2008
@@ -23,95 +23,134 @@
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;
+ 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)
+static void
+prepare(GeglOperation *operation)
{
- Babl *image_format = babl_format_new(babl_model("RGB"),
- babl_type("double"),
- babl_component("R"),
- babl_component("G"),
- babl_component("B"),
+ 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);
- 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);
+ gegl_operation_set_format(operation, "input", image_format);
+ gegl_operation_set_format(operation, "output", frequency_format);
}
-static gboolean process(GeglOperation *operation,
+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, *dst_buf;
- gint i, j;
- fftw_complex *fft_out;
- fftw_plan fftplan;
-
- src_buf = g_new0(gdouble, gegl_buffer_get_pixel_count(input) * 3);
- gegl_buffer_get(input, 1.0, NULL, NULL, src_buf, GEGL_AUTO_ROWSTRIDE);
-
- /* fetch R component pixes */
- dst_buf = g_new0(gdouble, height*width);
- for (i=0; i<width*height; i++) {
- dst_buf[i] = src_buf[3 * i];
+ 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];
}
- /* 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, (double *)dst_buf, fft_out,
- FFTW_ESTIMATE);
- fftw_execute(fftplan);
-#if 1
-
- /* 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;
+ 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);
+ 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");
+ }
#endif
- gegl_buffer_set(output, NULL, NULL, dst_buf, GEGL_AUTO_ROWSTRIDE);
- fftw_destroy_plan(fftplan);
- fftw_free(fft_out);
+ 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;
+ return TRUE;
}
-static void gegl_chant_class_init(GeglChantClass *klass)
+static void
+gegl_chant_class_init(GeglChantClass *klass)
{
- GeglOperationClass *operation_class;
- GeglOperationFilterClass *filter_class;
+ GeglOperationClass *operation_class;
+ GeglOperationFilterClass *filter_class;
- operation_class = GEGL_OPERATION_CLASS(klass);
- filter_class = GEGL_OPERATION_FILTER_CLASS(klass);
+ operation_class = GEGL_OPERATION_CLASS(klass);
+ filter_class = GEGL_OPERATION_FILTER_CLASS(klass);
- filter_class->process = process;
- operation_class->prepare = prepare;
+ 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.";
+ 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
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 Sun May 18 06:54:47 2008
@@ -2,41 +2,41 @@
gint main(gint argc, gchar **argv)
{
- gegl_init(&argc, &argv);
-
- {
- GeglNode *gegl = gegl_node_new();
- gint frame;
-
- GeglNode *display = gegl_node_create_child(gegl, "display");
- GeglNode *image = gegl_node_new_child(
- gegl,
- "operation",
- "load",
- "path",
- "/home/bear/GSoC2008/workspace/images/lena.png",
- NULL);
- GeglNode *proc = gegl_node_new_child(gegl, "operation", "dft", NULL);
- GeglNode *grey = gegl_node_new_child(gegl, "operation", "grey", NULL);
- GeglNode *save = gegl_node_new_child(
- gegl,
- "operation",
- "png-save",
- "path",
- "/home/bear/GSoC2008/workspace/images/forSave/test.png",
- NULL);
-
- gegl_node_link_many(image, proc, display, NULL);
- // gegl_node_link_many(image, grey, save, NULL);
-
- // gegl_node_process(save);
- for (frame=0; frame<10; frame++) {
- gegl_node_process(display);
- }
+ gegl_init(&argc, &argv);
- g_object_unref(gegl);
- }
+ {
+ GeglNode *gegl = gegl_node_new();
+ gint frame;
- gegl_exit();
- return 0;
+ GeglNode *display = gegl_node_create_child(gegl, "display");
+ GeglNode *image =
+ gegl_node_new_child(gegl,
+ "operation",
+ "load",
+ "path",
+ "/home/bear/GSoC2008/workspace/images/lena.png",
+ NULL);
+ GeglNode *proc = gegl_node_new_child(gegl, "operation", "dft", NULL);
+ GeglNode *grey = gegl_node_new_child(gegl, "operation", "grey", NULL);
+ GeglNode *save =
+ gegl_node_new_child(gegl,
+ "operation",
+ "png-save",
+ "path",
+ "/home/bear/GSoC2008/workspace/images/forSave/test.png",
+ NULL);
+
+ /* gegl_node_link_many(image, proc, display, NULL);
+ for (frame=0; frame<50; frame++) {
+ gegl_node_process(display);
+ }*/
+
+ gegl_node_link_many(image, proc, save, NULL);
+ gegl_node_process(save);
+
+ g_object_unref(gegl);
+ }
+
+ gegl_exit();
+ return 0;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]