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



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

Log:


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

Added: branches/branch2_zhangjb/operations/frequency/highpass-gaussian.c
==============================================================================
--- (empty file)
+++ branches/branch2_zhangjb/operations/frequency/highpass-gaussian.c	Sun Aug  3 02:34:26 2008
@@ -0,0 +1,110 @@
+/* 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.")
+
+#else
+
+#define GEGL_CHANT_TYPE_FILTER
+#define GEGL_CHANT_C_FILE       "highpass-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;
+  gint i;
+  
+  Hr = g_new0(gdouble, FFT_HALF(width)*height);
+  Hi = g_new0(gdouble, FFT_HALF(width)*height);
+  getH_highpass_gaussian(Hr, Hi, width, height, cutoff);
+  
+  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 = "highpass-gaussian";
+  operation_class->categories = "frequency";
+  operation_class->description = "Highpass 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:34:26 2008
@@ -25,6 +25,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
 freq_multiply(gdouble *Xr, gdouble *Xi, gdouble *Hr,
@@ -47,12 +48,12 @@
           Xr[index] = Yr;
           Xi[index] = Yi;
         }
-      
+
       for(y=height/2;y<height;y++)
         {
           index = (y*max_x)+x;
           h_index = (3*height/2-y-1)*max_x+width/2-x-1;
-          
+
           Yr= Xr[index]*Hr[h_index] - Xi[index]*Hi[h_index];
           Yi= Xi[index]*Hr[h_index] + Xr[index]*Hi[h_index];
           Xr[index] = Yr;
@@ -83,3 +84,24 @@
   return TRUE;
 }
 
+gboolean
+getH_highpass_gaussian(gdouble *Hr, gdouble *Hi, gint width, gint height,
+                      gint cutoff)
+{
+  gint x, y;
+  gint max_x = FFT_HALF(width);
+  gint index;
+
+  for (y=0; y<height; y++){
+    for (x=0; x<max_x; x++)
+      {
+        index = ELEM_ID_HALF_MATRIX(x, y, width);
+        Hi[index] = 0;
+        Hr[index] = 1 - exp( -((gdouble)(x+1-width/2)*(x+1-width/2)
+                                   +(y+1-height/2)*(y+1-height/2))/(2*cutoff*cutoff) );
+      }
+  }
+
+  return TRUE;
+}
+



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