gegl r1931 - in trunk: . operations/blur operations/color



Author: neo
Date: Mon Jan 28 21:52:30 2008
New Revision: 1931
URL: http://svn.gnome.org/viewvc/gegl?rev=1931&view=rev

Log:
2008-01-28  Sven Neumann  <sven gimp org>

	* operations/blur/box-blur.c
	* operations/blur/gaussian-blur.c
	* operations/color/mono-mixer.c
	* operations/color/remap.c
	* operations/color/stretch-contrast.c: use g_new() instead of
	g_malloc() for readability and type safety.



Modified:
   trunk/ChangeLog
   trunk/operations/blur/box-blur.c
   trunk/operations/blur/gaussian-blur.c
   trunk/operations/color/mono-mixer.c
   trunk/operations/color/remap.c
   trunk/operations/color/stretch-contrast.c

Modified: trunk/operations/blur/box-blur.c
==============================================================================
--- trunk/operations/blur/box-blur.c	(original)
+++ trunk/operations/blur/box-blur.c	Mon Jan 28 21:52:30 2008
@@ -132,8 +132,8 @@
   gfloat *dst_buf;
 
   /* src == dst for hor blur */
-  src_buf = g_malloc0 (gegl_buffer_get_pixel_count (src) * 4 * 4);
-  dst_buf = g_malloc0 (gegl_buffer_get_pixel_count (dst) * 4 * 4);
+  src_buf = g_new0 (gfloat, gegl_buffer_get_pixel_count (src) * 4);
+  dst_buf = g_new0 (gfloat, gegl_buffer_get_pixel_count (dst) * 4);
 
   gegl_buffer_get (src, 1.0, NULL, babl_format ("RaGaBaA float"), src_buf, GEGL_AUTO_ROWSTRIDE);
 
@@ -174,8 +174,8 @@
   gfloat *src_buf;
   gfloat *dst_buf;
 
-  src_buf = g_malloc0 (gegl_buffer_get_pixel_count (src) * 4 * 4);
-  dst_buf = g_malloc0 (gegl_buffer_get_pixel_count (dst) * 4 * 4);
+  src_buf = g_new0 (gfloat, gegl_buffer_get_pixel_count (src) * 4);
+  dst_buf = g_new0 (gfloat, gegl_buffer_get_pixel_count (dst) * 4);
 
   gegl_buffer_get (src, 1.0, NULL, babl_format ("RaGaBaA float"), src_buf, GEGL_AUTO_ROWSTRIDE);
 

Modified: trunk/operations/blur/gaussian-blur.c
==============================================================================
--- trunk/operations/blur/gaussian-blur.c	(original)
+++ trunk/operations/blur/gaussian-blur.c	Mon Jan 28 21:52:30 2008
@@ -166,8 +166,8 @@
   gfloat *buf;
   gfloat *w;
 
-  buf = g_malloc0 (gegl_buffer_get_pixel_count (src) * 4 * 4);
-  w   = g_malloc0 (gegl_buffer_get_width (src) * 4);
+  buf = g_new0 (gfloat, gegl_buffer_get_pixel_count (src) * 4);
+  w   = g_new0 (gfloat, gegl_buffer_get_width (src));
 
   gegl_buffer_get (src, 1.0, NULL, babl_format ("RaGaBaA float"), buf, GEGL_AUTO_ROWSTRIDE);
 
@@ -204,8 +204,8 @@
   gfloat *buf;
   gfloat *w;
 
-  buf = g_malloc0 (gegl_buffer_get_pixel_count (src) * 4 * 4);
-  w   = g_malloc0 (gegl_buffer_get_height (src) * 4);
+  buf = g_new0 (gfloat, gegl_buffer_get_pixel_count (src) * 4);
+  w   = g_new0 (gfloat, gegl_buffer_get_height (src));
 
   gegl_buffer_get (src, 1.0, NULL, babl_format ("RaGaBaA float"), buf, GEGL_AUTO_ROWSTRIDE);
 

Modified: trunk/operations/color/mono-mixer.c
==============================================================================
--- trunk/operations/color/mono-mixer.c	(original)
+++ trunk/operations/color/mono-mixer.c	Mon Jan 28 21:52:30 2008
@@ -55,8 +55,8 @@
      gint i;
      gfloat *in_pixel, *out_pixel;
 
-     in_buf = g_malloc (4 * sizeof (gfloat) * num_pixels);
-     out_buf = g_malloc (2 * sizeof(gfloat) * num_pixels);
+     in_buf = g_new (gfloat, 4 * num_pixels);
+     out_buf = g_new (gfloat, 2 * num_pixels);
 
      gegl_buffer_get (input, 1.0, result, babl_format ("RGBA float"), in_buf, GEGL_AUTO_ROWSTRIDE);
 

Modified: trunk/operations/color/remap.c
==============================================================================
--- trunk/operations/color/remap.c	(original)
+++ trunk/operations/color/remap.c	Mon Jan 28 21:52:30 2008
@@ -243,9 +243,9 @@
       gint pixels = result->width  * result->height;
       gint i;
 
-      buf = g_malloc (pixels * sizeof (gfloat) * 4);
-      min = g_malloc (pixels * sizeof (gfloat) * 3);
-      max = g_malloc (pixels * sizeof (gfloat) * 3);
+      buf = g_new (gfloat, pixels * 4);
+      min = g_new (gfloat, pixels * 3);
+      max = g_new (gfloat, pixels * 3);
 
       gegl_buffer_get (input, 1.0, result, babl_format ("RGBA float"), buf, GEGL_AUTO_ROWSTRIDE);
       gegl_buffer_get (low,   1.0, result, babl_format ("RGB float"), min, GEGL_AUTO_ROWSTRIDE);
@@ -253,19 +253,21 @@
 
       output = gegl_node_context_get_target (context, "output");
 
-      for (i=0;i<pixels;i++)
+      for (i = 0; i < pixels; i++)
         {
           gint c;
-          for (c=0;c<3;c++) 
+
+          for (c = 0; c < 3; c++)
             {
               gfloat delta = max[i*3+c]-min[i*3+c];
+
               if (delta > 0.0001 || delta < -0.0001)
                 {
                   buf[i*4+c] = (buf[i*4+c]-min[i*3+c]) / delta;
                 }
               /*else
                 buf[i*4+c] = buf[i*4+c];*/
-            } 
+            }
         }
 
       gegl_buffer_set (output, result, babl_format ("RGBA float"), buf,

Modified: trunk/operations/color/stretch-contrast.c
==============================================================================
--- trunk/operations/color/stretch-contrast.c	(original)
+++ trunk/operations/color/stretch-contrast.c	Mon Jan 28 21:52:30 2008
@@ -25,20 +25,22 @@
 #include "gegl-chant.h"
 
 static gboolean
-inner_process (gdouble        min,
-                gdouble        max,
-                guchar        *buf,
-                gint           n_pixels)
+inner_process (gdouble  min,
+               gdouble  max,
+               gfloat  *buf,
+               gint     n_pixels)
 {
   gint o;
-  gfloat *p = (gfloat*) (buf);
 
   for (o=0; o<n_pixels; o++)
     {
-      gint i;
-      for (i=0;i<3;i++)
-        p[i] = (p[i] - min) / (max-min);
-      p+=4;
+      buf[0] = (buf[0] - min) / (max-min);
+      buf[1] = (buf[1] - min) / (max-min);
+      buf[2] = (buf[2] - min) / (max-min);
+      /* FIXME: really stretch the alpha channel?? */
+      buf[3] = (buf[3] - min) / (max-min);
+
+      buf += 4;
     }
   return TRUE;
 }
@@ -51,7 +53,7 @@
   gfloat tmin = 9000000.0;
   gfloat tmax =-9000000.0;
 
-  gfloat *buf = g_malloc0 (sizeof (gfloat) * 4 * gegl_buffer_get_pixel_count (buffer));
+  gfloat *buf = g_new0 (gfloat, 4 * gegl_buffer_get_pixel_count (buffer));
   gint i;
   gegl_buffer_get (buffer, 1.0, NULL, babl_format ("RGBA float"), buf, GEGL_AUTO_ROWSTRIDE);
   for (i=0;i< gegl_buffer_get_pixel_count (buffer);i++)
@@ -95,18 +97,18 @@
          GeglBuffer          *output,
          const GeglRectangle *result)
 {
-  gdouble              min, max;
+  gdouble  min, max;
 
   buffer_get_min_max (input, &min, &max);
   {
     gint row;
-    guchar *buf;
+    gfloat *buf;
     gint chunk_size=128;
     gint consumed=0;
 
-    buf = g_malloc0 (sizeof (gfloat) * 4 * result->width  * chunk_size);
+    buf = g_new0 (gfloat, 4 * result->width  * chunk_size);
 
-    for (row=0;row<result->height;row=consumed)
+    for (row = 0; row < result->height; row = consumed)
       {
         gint chunk = consumed+chunk_size<result->height?chunk_size:result->height-consumed;
         GeglRectangle line = { result->x,



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