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



Author: zhangjb
Date: Fri Aug  1 12:47:11 2008
New Revision: 2549
URL: http://svn.gnome.org/viewvc/gegl?rev=2549&view=rev

Log:


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

Modified: branches/branch2_zhangjb/operations/frequency/lowpass-gaussian.c
==============================================================================
--- branches/branch2_zhangjb/operations/frequency/lowpass-gaussian.c	(original)
+++ branches/branch2_zhangjb/operations/frequency/lowpass-gaussian.c	Fri Aug  1 12:47:11 2008
@@ -15,7 +15,7 @@
  *
  * 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.")
@@ -51,26 +51,24 @@
   GeglChantO *o = GEGL_CHANT_PROPERTIES (operation);
   gdouble *src_buf;
   gdouble *dst_buf;
-  gdouble *comp_real;//The most general filer in frequency domain. What it does is just "
-  //"multiplying a matrix on the freqeuncy image.";
+  gdouble *comp_real;
   gdouble *comp_imag;
-  gdouble *Hr_buf;
-  gdouble *Hi_buf;
+  gdouble *Hr;
+  gdouble *Hi;
   gint flag = o->flag;
   gint cutoff = o->cutoff;
   gint i;
   
-  Hr_buf = (gdouble, FFT_HALF(width)*height);
-  Hi_buf = (gdouble, FFT_HALF(width)*height);
+  Hr = g_new0(gdouble, FFT_HALF(width)*height);
+  Hi = g_new0(gdouble, FFT_HALF(width)*height);
   getH_lowpass_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);  
+  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); 
-     
+                  GEGL_AUTO_ROWSTRIDE);  
   for (i=0; i<4; i++)
     {
       get_freq_component(src_buf, comp_real, i, FFT_HALF(width)*height);
@@ -78,7 +76,7 @@
 
       if ((8>>i)&flag)
         {
-          freq_multiply(comp_real, comp_imag, Hr_buf, Hi_buf, width, height);
+          freq_multiply(comp_real, comp_imag, Hr, Hi, width, height);
         }
 
       set_freq_component(comp_real, dst_buf, i, FFT_HALF(width)*height);
@@ -110,4 +108,3 @@
 }
 
 #endif
-*/
\ No newline at end of file

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	Fri Aug  1 12:47:11 2008
@@ -31,24 +31,17 @@
               gdouble *Hi, gint width, gint height)
 {
   gint x, y;
-  gint yc = 0;
   gdouble Yr,Yi;
+  gint index;
   
   for(y=0;y<height;y++)
     for(x=0;x<(width/2+1);x++)
       {
-        Yr=
-          Xr[ELEM_ID_HALF_MATRIX(x, y, width)] *
-          Hr[ELEM_ID_HALF_MATRIX(x, y, width)] -
-          Xi[ELEM_ID_HALF_MATRIX(x, y, width)] *
-          Hi[ELEM_ID_HALF_MATRIX(x, y, width)];
-        Yi=
-          Xi[ELEM_ID_HALF_MATRIX(x, y, width)] *
-          Hr[ELEM_ID_HALF_MATRIX(x, y, width)] +
-          Xr[ELEM_ID_HALF_MATRIX(x, y, width)] *
-          Hi[ELEM_ID_HALF_MATRIX(x, y, width)];
-        Xr[ELEM_ID_HALF_MATRIX(x, y, width)] = Yr;
-        Xi[ELEM_ID_HALF_MATRIX(x, y, width)] = Yi;
+        index = ELEM_ID_HALF_MATRIX(x, y, width);
+        Yr= Xr[index]*Hr[index] - Xi[index]*Hi[index];
+        Yi= Xi[index]*Hr[index] + Xr[index]*Hi[index];
+        Xr[index] = Yr;
+        Xi[index] = Yi;
       }
   return TRUE;
 }
@@ -58,16 +51,29 @@
                       gint cutoff)
 {
   gint x, y;
-  gint x0, y0, xd;
-  
-  for (x=0; x<FFT_HALF(width); x++)
-    {
-      for (y=0; y<height; y++)
+  gint max_x = FFT_HALF(width);
+  gint index;
+
+      for (y=0; y<height/2; y++){
+        for (x=0; x<max_x; x++)
+          {
+            index = ELEM_ID_HALF_MATRIX(x, y, width);
+            Hi[index] = 0;
+            Hr[index] = exp( -((double)(x+1)*(x+1)+(y+1)*(y+1))/(2*cutoff*cutoff) );
+          }
+      }
+
+      for(y=height/2; y<height; y++)
         {
-          Hi[ELEM_ID_HALF_MATRIX(x, y, width)] = 0;
-          Hr[ELEM_ID_HALF_MATRIX(x, y, width)]
-            = exp(0 - ((x)*(x)+(y-height/2)*(y-height/2)/2*(cutoff*cutoff)));
+          for (x=0; x<max_x; x++)
+            {
+              index = ELEM_ID_HALF_MATRIX(x, y, width);
+              Hi[index] = 0;
+              Hr[index] = 
+                exp(-((double)(x+1)*(x+1)+(y-height+1)*(y-height+1))/(2*cutoff*cutoff) );
+            }
         }
-    }
+
   return TRUE;
 }
+



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