gegl r2560 - in branches/branch2_zhangjb: . operations/frequency operations/frequency/tools



Author: zhangjb
Date: Sun Aug  3 02:57:29 2008
New Revision: 2560
URL: http://svn.gnome.org/viewvc/gegl?rev=2560&view=rev

Log:


Added:
   branches/branch2_zhangjb/operations/frequency/bandpass-gaussian.c
Modified:
   branches/branch2_zhangjb/ChangeLog
   branches/branch2_zhangjb/operations/frequency/tools/filters.c

Added: branches/branch2_zhangjb/operations/frequency/bandpass-gaussian.c
==============================================================================
--- (empty file)
+++ branches/branch2_zhangjb/operations/frequency/bandpass-gaussian.c	Sun Aug  3 02:57:29 2008
@@ -0,0 +1,113 @@
+/* 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
+
+gegl_chant_int(cutoff, "Cutoff", 0, G_MAXINT, 0, "The cut off frequncy.")
+gegl_chant_int(flag, "Flag", 0, 15, 14,
+               "Decide which componet need to process. Example: if flag=14, "
+               "14==0b1110, so we filter on componets RGB, do not filter on A.")
+gegl_chant_double(bandwidth, "Bandwidth", 0, G_MAXDOUBLE, 1.0,
+                  "The width of band")
+
+#else
+
+#define GEGL_CHANT_TYPE_FILTER
+#define GEGL_CHANT_C_FILE       "bandpass-gaussian.c"
+
+#include "gegl-chant.h"
+#include "tools/component.c"
+#include "tools/filters.c"
+
+static void
+prepare(GeglOperation *operation)
+{
+  Babl *format = babl_format ("frequency 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);
+  GeglChantO *o = GEGL_CHANT_PROPERTIES (operation);
+  gdouble *src_buf;
+  gdouble *dst_buf;
+  gdouble *comp_real;
+  gdouble *comp_imag;
+  gdouble *Hr;
+  gdouble *Hi;
+  gint flag = o->flag;
+  gint cutoff = o->cutoff;
+  gdouble bandwidth = o->bandwidth;
+  gint i;
+  
+  Hr = g_new0(gdouble, FFT_HALF(width)*height);
+  Hi = g_new0(gdouble, FFT_HALF(width)*height);
+  getH_bandpass_gaussian(Hr, Hi, width, height, cutoff, bandwidth);
+  
+  src_buf = g_new0(gdouble, 8*width*height);
+  dst_buf = g_new0(gdouble, 8*width*height);
+  comp_real = g_new0(gdouble, FFT_HALF(width)*height);
+  comp_imag = g_new0(gdouble,FFT_HALF(width)*height);  
+  gegl_buffer_get(input, 1.0, NULL, babl_format ("frequency double"), src_buf,
+                  GEGL_AUTO_ROWSTRIDE);  
+  for (i=0; i<4; i++)
+    {
+      get_freq_component(src_buf, comp_real, i, FFT_HALF(width)*height);
+      get_freq_component(src_buf, comp_imag, 4+i, FFT_HALF(width)*height);
+
+      if ((8>>i)&flag)
+        {
+          freq_multiply(comp_real, comp_imag, Hr, Hi, width, height);
+        }
+
+      set_freq_component(comp_real, dst_buf, i, FFT_HALF(width)*height);
+      set_freq_component(comp_imag, dst_buf, 4+i, 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);
+  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 = "bandpass-gaussian";
+  operation_class->categories = "frequency";
+  operation_class->description = "Bandpass Gaussian Filter.";
+}
+
+#endif

Modified: branches/branch2_zhangjb/operations/frequency/tools/filters.c
==============================================================================
--- branches/branch2_zhangjb/operations/frequency/tools/filters.c	(original)
+++ branches/branch2_zhangjb/operations/frequency/tools/filters.c	Sun Aug  3 02:57:29 2008
@@ -26,6 +26,7 @@
 gboolean freq_multiply(gdouble *, gdouble *, gdouble *, gdouble *, gint, gint);
 gboolean getH_lowpass_gaussian(gdouble *, gdouble *, gint, gint, gint);
 gboolean getH_highpass_gaussian(gdouble *, gdouble *, gint, gint, gint);
+gboolean getH_bandpass_gaussian(gdouble *, gdouble *, gint, gint, gint, gdouble);
 
 gboolean
 freq_multiply(gdouble *Xr, gdouble *Xi, gdouble *Hr,
@@ -105,3 +106,24 @@
   return TRUE;
 }
 
+gboolean
+getH_bandpass_gaussian(gdouble *Hr, gdouble *Hi, gint width, gint height,
+                       gint cutoff, gdouble bandwidth )
+{
+  gint x, y;
+  gint max_x = FFT_HALF(width);
+  gint index;
+  gdouble dist;
+
+  for (y=0; y<height; y++){
+    for (x=0; x<max_x; x++)
+      {
+        index = ELEM_ID_HALF_MATRIX(x, y, width);
+        dist = sqrt((x+1-width/2)*(x+1-width/2)+(y+1-height/2)*(y+1-height/2));
+        Hi[index] = 0;
+        Hr[index] = exp(-pow((dist*dist-cutoff*cutoff)/dist/bandwidth,2)/2);
+      }
+  }
+
+  return TRUE;
+}



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