gegl r2351 - in branches/branch_zhangjb: . docs/images operations/frequency operations/frequency/tools tests/frequency



Author: zhangjb
Date: Sun May 25 13:05:42 2008
New Revision: 2351
URL: http://svn.gnome.org/viewvc/gegl?rev=2351&view=rev

Log:
reviewed by: <delete if not using a buddy>
* operations/frequency/dft-grey.c: used built-in "Y double" for input/output.
* operations/frequency/dft-rgba.c: a new operation that take DFT for an RGBA image.
* operations/frequency/tools/Makefile.am: added file component.c
* operations/frequency/tools/component.c: a new function that deal with thing between grey and color components.
* tests/frequency/hello-world-fourier.c: used test image "lena_rgba.png"
* docs/images/lena_rgba.png: a new testing image.
* docs/images/test_rgba.png: a new testing image.


Added:
   branches/branch_zhangjb/docs/images/lena_rgba.png   (contents, props changed)
   branches/branch_zhangjb/docs/images/test_rgba.png   (contents, props changed)
   branches/branch_zhangjb/operations/frequency/dft-rgba.c
   branches/branch_zhangjb/operations/frequency/tools/component.c
Modified:
   branches/branch_zhangjb/ChangeLog
   branches/branch_zhangjb/operations/frequency/dft-grey.c
   branches/branch_zhangjb/operations/frequency/tools/Makefile.am
   branches/branch_zhangjb/tests/frequency/hello-world-fourier.c

Added: branches/branch_zhangjb/docs/images/lena_rgba.png
==============================================================================
Binary file. No diff available.

Added: branches/branch_zhangjb/docs/images/test_rgba.png
==============================================================================
Binary file. No diff available.

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	Sun May 25 13:05:42 2008
@@ -63,16 +63,9 @@
 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);
+  Babl *format = babl_format ("Y double");
+  gegl_operation_set_format(operation, "input", format);
+  gegl_operation_set_format(operation, "output", format);
 }
 
 static gboolean
@@ -88,19 +81,12 @@
 
   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);
+                  NULL, babl_format ("Y double"), src_buf, GEGL_AUTO_ROWSTRIDE);
   dst_buf = g_new0(gdouble, 2*width*FFT_HALF(height));
 
   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);
+  gegl_buffer_set(output, NULL, babl_format ("Y double"), dst_buf, GEGL_AUTO_ROWSTRIDE);
 
   g_free(src_buf);
   g_free(dst_buf);

Added: branches/branch_zhangjb/operations/frequency/dft-rgba.c
==============================================================================
--- (empty file)
+++ branches/branch_zhangjb/operations/frequency/dft-rgba.c	Sun May 25 13:05:42 2008
@@ -0,0 +1,132 @@
+/* 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_POINT_FILTER
+#define GEGL_CHANT_C_FILE       "dft-rgba.c"
+
+#include "gegl-chant.h"
+#include "tools/dft.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  += 2;
+  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)
+{
+  GeglRectangle *in_rect = gegl_operation_source_get_bounding_box (operation, "input");
+  GeglRectangle  result  = *in_rect;
+
+  result.width  += 2;
+  return result;
+}
+
+static void
+prepare(GeglOperation *operation)
+{
+  Babl *format = babl_format ("RGBA double");
+  gegl_operation_set_format(operation, "input", format);
+  gegl_operation_set_format(operation, "output", 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;
+  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, 4*2*width*FFT_HALF(height));
+  tmp_dst_buf = g_new0(gdouble, 2*width*FFT_HALF(height));
+
+  gegl_buffer_get(input, 1.0, NULL, babl_format ("RGBA double"), src_buf, GEGL_AUTO_ROWSTRIDE);
+
+  for (i=0; i<4; i++)
+    {
+      get_component(src_buf, tmp_src_buf, i, width*height);
+      dft(tmp_src_buf, (fftw_complex *)tmp_dst_buf, width, height);
+      set_component(tmp_dst_buf, dst_buf, i, (width+2)*height);
+    }
+  get_component(src_buf, tmp_src_buf, 3, width*height);
+  set_component(tmp_dst_buf, dst_buf, 3, (width+2)*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 = "dft-rgba";
+  operation_class->categories = "frequency";
+  operation_class->description
+    = "Perform 2-D Discrete Fourier Transform for a RGBA image.";
+}
+
+#endif

Modified: branches/branch_zhangjb/operations/frequency/tools/Makefile.am
==============================================================================
--- branches/branch_zhangjb/operations/frequency/tools/Makefile.am	(original)
+++ branches/branch_zhangjb/operations/frequency/tools/Makefile.am	Sun May 25 13:05:42 2008
@@ -1,5 +1,4 @@
 EXTRA_DIST = \
 	dft.c	\
-	dft.h	\
 	display.c	\
-	display.h
\ No newline at end of file
+	component.c
\ No newline at end of file

Added: branches/branch_zhangjb/operations/frequency/tools/component.c
==============================================================================
--- (empty file)
+++ branches/branch_zhangjb/operations/frequency/tools/component.c	Sun May 25 13:05:42 2008
@@ -0,0 +1,45 @@
+/* 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_component(gdouble* src_buf, gdouble* comp_buf, gint place, gint samples);
+gboolean set_component(gdouble* comp_buf, gdouble* dst_buf, gint place, gint samples);
+
+gboolean
+get_component(gdouble* src_buf, gdouble *comp_buf, gint place, gint samples)
+{
+  src_buf += place;
+  while (samples--)
+    {
+      *(comp_buf++) = *src_buf;
+      src_buf += 4;
+    }
+  return TRUE;
+}
+
+  
+gboolean
+set_component(gdouble* comp_buf, gdouble* dst_buf, gint place, gint samples)
+{
+  dst_buf += place;
+  while (samples--)
+    {
+      *dst_buf = *(comp_buf++);
+      dst_buf += 4;
+    }
+  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	Sun May 25 13:05:42 2008
@@ -13,9 +13,9 @@
                                   "operation",
                                   "load",
                                   "path",
-                                  "docs/images/lena_bw.png",
+                                  "docs/images/lena_rgba.png",
                                   NULL);
-      GeglNode *dft = gegl_node_new_child(gegl, "operation", "dft-grey", NULL);
+      GeglNode *dft = gegl_node_new_child(gegl, "operation", "dft-rgba", 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);



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