gegl r2329 - in branches/branch_zhangjb: . operations/frequency operations/frequency/tools



Author: zhangjb
Date: Wed May 21 16:33:29 2008
New Revision: 2329
URL: http://svn.gnome.org/viewvc/gegl?rev=2329&view=rev

Log:
	* operations/frequency/tools/display.h: add function get_min_max.
	* operations/frequency/tools/display.c: has been able to display a perfect output.
	* operations/frequency/dft-grey.c: output abs instead of real part.


Modified:
   branches/branch_zhangjb/ChangeLog
   branches/branch_zhangjb/operations/frequency/dft-grey.c
   branches/branch_zhangjb/operations/frequency/tools/display.c
   branches/branch_zhangjb/operations/frequency/tools/display.h

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	Wed May 21 16:33:29 2008
@@ -63,6 +63,7 @@
   gdouble *src_buf;
   gdouble *dst_buf;
   gdouble *dst_imag_buf;
+  gint i;
 
   src_buf = g_new0(gdouble, width*height);
   gegl_buffer_get(input, 1.0, 
@@ -76,6 +77,10 @@
 
 #if 1 
   dft(src_buf, dst_buf, dst_imag_buf, width, height);
+  for (i=0; i<width*height; i++)
+    {
+      dst_buf[i] = sqrt(dst_buf[i]*dst_buf[i]+dst_imag_buf[i]*dst_imag_buf[i]);
+    }
   zoomshow(dst_buf, width*height);
   shift_dft(dst_buf, width, height);
 #endif
@@ -86,7 +91,6 @@
 #endif
   
 #if 0  
-  int i;
   for (i=0; i<width*height; i++)
     {
       dst_buf[i] = src_buf[i];
@@ -94,7 +98,8 @@
 #endif
 
 #if 0
-  int i, j;
+  gint j;
+  gdouble min, max;
   printf("input: width = %d, height = %d\n", width, height);
   for (i=0; i<width; i++)
     {
@@ -104,6 +109,8 @@
         }
       printf("\n");
     }
+  get_min_max(src_buf, &min, &max, width*height);
+  printf("min = %lf, max = %lf\n\n", min, max);
   printf("output: width = %d, height = %d\n", width, height);
   for (i=0; i<width; i++)
     {
@@ -113,13 +120,17 @@
         }
       printf("\n");
     }
+  get_min_max(dst_buf, &min, &max, width*height);
+  printf("min = %lf, max = %lf\n", min, max);
 #endif
 
   gegl_buffer_set(output, 
-  NULL, babl_format_new(babl_model("Y"),
-                        babl_type("double"),
-                        babl_component("Y"),
-                         NULL), dst_buf, GEGL_AUTO_ROWSTRIDE);
+                  NULL, babl_format_new(babl_model("Y"),
+                                        babl_type("double"),
+                                        babl_component("Y"),
+                                        NULL), 
+                  dst_buf, 
+                  GEGL_AUTO_ROWSTRIDE);
 
   return TRUE;
 }

Modified: branches/branch_zhangjb/operations/frequency/tools/display.c
==============================================================================
--- branches/branch_zhangjb/operations/frequency/tools/display.c	(original)
+++ branches/branch_zhangjb/operations/frequency/tools/display.c	Wed May 21 16:33:29 2008
@@ -16,18 +16,6 @@
  * Copyright 2008 Zhang Junbo  <zhangjb svn gnome org>
  */
 
-gboolean 
-zoomshow(gdouble *buf, glong samples)
-{
-  glong i;
-
-  for (i=0; i<samples; i++)
-    {
-      *(buf+i) = log(*(buf+i))/log(2);
-    }
-  return TRUE;
-}
-
 gboolean
 shift_dft(gdouble *buf, gint width, gint height)
 {
@@ -55,3 +43,45 @@
 
   return TRUE;
 }
+
+void
+get_min_max (gdouble *buf, gdouble *min, gdouble *max, glong samples)
+{
+  gfloat tmin = 9000000.0;
+  gfloat tmax =-9000000.0;
+
+  gint i;
+  for (i=0; i<samples; i++)
+    {
+      gfloat val = buf[i];
+      if (val<tmin)
+        tmin=val;
+      if (val>tmax)
+        tmax=val;
+    }
+  if (min)
+    *min = tmin;
+  if (max)
+    *max = tmax;
+}
+
+gboolean 
+zoomshow(gdouble *buf, glong samples)
+{
+  glong i;
+  gdouble min, max;
+
+  for (i=0; i<samples; i++)
+    {      
+      if (*(buf+i)<1)
+        *(buf+i) = 0;
+      else
+        *(buf+i) = log(*(buf+i));
+    }
+  get_min_max(buf, &min, &max, samples);
+  for (i=0; i<samples; i++)
+      {      
+        *(buf+i) = (*(buf+i))/max;
+      }
+  return TRUE;
+}

Modified: branches/branch_zhangjb/operations/frequency/tools/display.h
==============================================================================
--- branches/branch_zhangjb/operations/frequency/tools/display.h	(original)
+++ branches/branch_zhangjb/operations/frequency/tools/display.h	Wed May 21 16:33:29 2008
@@ -31,6 +31,8 @@
 gboolean
 i_shift_dft(gdouble *buf, gint width, gint height);
 
-gboolean 
+gboolean
 zoomshow(gdouble *buf, glong samples);
 
+void
+get_min_max(gdouble *buffer, gdouble *min, gdouble *max, glong samples);



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