two small patches

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

 



Two patches attached. I've made the below comments in a more suitable ChangeLog format:

[gegl_buffer.diff]

Patch from Henrik Akesson:
- Extracted duplicated code from pset/pget into a separate function gegl_buffer_in_abyss to improve readability of code and maintainability.
- Renamed pset/pget to gegl_buffer_pixel_set and gegl_buffer_pixel_get in order to improve readability of code and to be conformant to gegl coding standards.
* gegl/buffer/gegl_buffer_access.c
* gegl/buffer/gegl_buffer_private.h


[gegl_utils.diff]

Patch from Henrik Akesson that adds a gegl_rectangle_as string function for retreiving a rectangle as a debug string. Log statements has been changed to use this said function as well as using GEGL_NOTE (see gegl-debug.h).
* gegl/gegl_utils.c
* gegl/gegl_utils.h
* gegl/process/gegl_processor.c


/Henrik
Index: gegl/buffer/gegl-buffer-access.c
===================================================================
--- gegl/buffer/gegl-buffer-access.c	(revision 2967)
+++ gegl/buffer/gegl-buffer-access.c	(working copy)
@@ -50,11 +50,11 @@
 
 #if 0
 static inline void
-pset (GeglBuffer *buffer,
-      gint        x,
-      gint        y,
-      const Babl *format,
-      guchar     *buf)
+gegl_buffer_pixel_set (GeglBuffer *buffer,
+                       gint        x,
+                       gint        y,
+                       const Babl *format,
+                       guchar     *buf)
 {
   gint  tile_width  = buffer->tile_storage->tile_width;
   gint  tile_height  = buffer->tile_storage->tile_width;
@@ -115,12 +115,34 @@
 }
 #endif
 
+static gboolean
+gegl_buffer_in_abyss( GeglBuffer *buffer,
+                      gint        x,
+                      gint        y )
+{
+  gint  buffer_shift_x = buffer->shift_x;
+  gint  buffer_shift_y = buffer->shift_y;
+  gint  buffer_abyss_x = buffer->abyss.x + buffer_shift_x;
+  gint  buffer_abyss_y = buffer->abyss.y + buffer_shift_y;
+  gint  abyss_x_total  = buffer_abyss_x + buffer->abyss.width;
+  gint  abyss_y_total  = buffer_abyss_y + buffer->abyss.height;
+
+
+  gint tiledy = y + buffer_shift_y;
+  gint tiledx = x + buffer_shift_x;
+
+  return !(tiledy >= buffer_abyss_y &&
+           tiledy <  abyss_y_total  &&
+           tiledx >= buffer_abyss_x &&
+           tiledx <  abyss_x_total);
+}
+
 static inline void
-pset (GeglBuffer *buffer,
-      gint        x,
-      gint        y,
-      const Babl *format,
-      gpointer    data)
+gegl_buffer_set_pixel (GeglBuffer *buffer,
+                       gint        x,
+                       gint        y,
+                       const Babl *format,
+                       gpointer    data)
 {
   guchar *buf         = data;
   gint    tile_width  = buffer->tile_storage->tile_width;
@@ -130,10 +152,6 @@
 
   gint  buffer_shift_x = buffer->shift_x;
   gint  buffer_shift_y = buffer->shift_y;
-  gint  buffer_abyss_x = buffer->abyss.x + buffer_shift_x;
-  gint  buffer_abyss_y = buffer->abyss.y + buffer_shift_y;
-  gint  abyss_x_total  = buffer_abyss_x + buffer->abyss.width;
-  gint  abyss_y_total  = buffer_abyss_y + buffer->abyss.height;
   gint  px_size        = babl_format_get_bytes_per_pixel (buffer->format);
 
   if (format != buffer->format)
@@ -146,10 +164,7 @@
     gint tiledy   = y + buffer_shift_y;
     gint tiledx   = x + buffer_shift_x;
 
-    if (!(tiledy >= buffer_abyss_y &&
-          tiledy  < abyss_y_total &&
-          tiledx >= buffer_abyss_x &&
-          tiledx  < abyss_x_total))
+    if (gegl_buffer_in_abyss( buffer, x, y))
       { /* in abyss */
         return;
       }
@@ -200,11 +215,11 @@
 }
 
 static inline void
-pget (GeglBuffer *buffer,
-      gint        x,
-      gint        y,
-      const Babl *format,
-      gpointer    data)
+gegl_buffer_get_pixel (GeglBuffer *buffer,
+                       gint        x,
+                       gint        y,
+                       const Babl *format,
+                       gpointer    data)
 {
   guchar *buf         = data;
   gint    tile_width  = buffer->tile_storage->tile_width;
@@ -214,10 +229,6 @@
 
   gint  buffer_shift_x = buffer->shift_x;
   gint  buffer_shift_y = buffer->shift_y;
-  gint  buffer_abyss_x = buffer->abyss.x + buffer_shift_x;
-  gint  buffer_abyss_y = buffer->abyss.y + buffer_shift_y;
-  gint  abyss_x_total  = buffer_abyss_x + buffer->abyss.width;
-  gint  abyss_y_total  = buffer_abyss_y + buffer->abyss.height;
   gint  px_size        = babl_format_get_bytes_per_pixel (buffer->format);
 
   if (format != buffer->format)
@@ -230,10 +241,7 @@
     gint tiledy = y + buffer_shift_y;
     gint tiledx = x + buffer_shift_x;
 
-    if (!(tiledy >= buffer_abyss_y &&
-          tiledy <  abyss_y_total  &&
-          tiledx >= buffer_abyss_x &&
-          tiledx <  abyss_x_total))
+    if (gegl_buffer_in_abyss (buffer, x, y))
       { /* in abyss */
         memset (buf, 0x00, bpx_size);
         return;
@@ -316,9 +324,6 @@
                      const Babl          *format,
                      gint                 level)
 {
-  gint  width       = buffer->extent.width;
-  gint  height      = buffer->extent.height;
-
   gint  tile_width  = buffer->tile_storage->tile_width;
   gint  tile_height = buffer->tile_storage->tile_height;
   gint  px_size     = babl_format_get_bytes_per_pixel (buffer->format);
@@ -331,6 +336,8 @@
   gint  buffer_shift_x = buffer->shift_x;
   gint  buffer_shift_y = buffer->shift_y;
 
+  gint  width          = buffer->extent.width;
+  gint  height         = buffer->extent.height;
   gint  buffer_x       = buffer->extent.x + buffer_shift_x;
   gint  buffer_y       = buffer->extent.y + buffer_shift_y;
 
@@ -341,6 +348,15 @@
   gint  i;
   gint  factor = 1;
 
+  /*
+  g_debug ("{%s:%d} shift_x=%d shift_y=%d buffer_x=%d buffer_y=%d",
+          __FILE__, __LINE__,
+          buffer_shift_x, buffer_shift_y,
+          buffer_x, buffer_y);
+
+  g_debug ("{%s:%d} abyss=[%s] extent=[%s]", __FILE__, __LINE__,
+          gegl_rectangle_as_string (&buffer->abyss));
+          */
   /* roi specified, override buffers extent */
   if (roi)
     {
@@ -595,7 +611,7 @@
 
   if (rect && rect->width == 1 && rect->height == 1) /* fast path */
     {
-      pset (buffer, rect->x, rect->y, format, src);
+      gegl_buffer_set_pixel (buffer, rect->x, rect->y, format, src);
     }
   else
     {
@@ -949,7 +965,7 @@
       rect->width == 1 &&
       rect->height == 1)  /* fast path */
     {
-      pget (buffer, rect->x, rect->y, format, dest_buf);
+      gegl_buffer_get_pixel (buffer, rect->x, rect->y, format, dest_buf);
 #if ENABLE_MP
       g_static_rec_mutex_unlock (&mutex);
 #endif
@@ -1084,7 +1100,7 @@
 
 /*#define USE_WORKING_SHORTCUT*/
 #ifdef USE_WORKING_SHORTCUT
-  pget (buffer, x, y, format, dest);
+  gegl_buffer_get_pixel (buffer, x, y, format, dest);
   return;
 #endif
 
Index: gegl/buffer/gegl-buffer-private.h
===================================================================
--- gegl/buffer/gegl-buffer-private.h	(revision 2967)
+++ gegl/buffer/gegl-buffer-private.h	(working copy)
@@ -47,8 +47,8 @@
 
   GeglRectangle     abyss;
 
-  GeglTile         *hot_tile; /* cached tile for speeding up pget/pset (1x1
-                                 sized gets/sets)*/
+  GeglTile         *hot_tile; /* cached tile for speeding up gegl_buffer_get_pixel
+                                 and gegl_buffer_set_pixel (1x1 sized gets/sets)*/
 
   GeglSampler      *sampler; /* cached sampler for speeding up random
                                 access interpolated fetches from the
Index: gegl/gegl-utils.c
===================================================================
--- gegl/gegl-utils.c	(revision 2967)
+++ gegl/gegl-utils.c	(working copy)
@@ -53,6 +53,23 @@
   r->height = h;
 }
 
+gchar *
+gegl_rectangle_as_string (GeglRectangle *rect)
+{
+    GString * string = g_string_new ("");
+
+    if (rect)
+      {
+        g_string_append_printf (string, "%p -> x=%d, y=%d, h=%d, w=%d",
+                       rect, rect->x, rect->y, rect->height, rect->width);
+      }
+    else
+      {
+        g_string_append_printf (string, "%p -> NULL", rect);
+      }
+    return g_string_free (string, NULL);
+}
+
 void
 gegl_rectangle_bounding_box (GeglRectangle       *dest,
                              const GeglRectangle *src1,
Index: gegl/gegl-utils.h
===================================================================
--- gegl/gegl-utils.h	(revision 2967)
+++ gegl/gegl-utils.h	(working copy)
@@ -41,6 +41,10 @@
  *
  */
 
+/* Returns a string representation of a rectangle. This is used
+ * for debugging output */
+gchar *     gegl_rectangle_as_string     (GeglRectangle *rect);
+
 /**
  * gegl_rectangle_set:
  * @rectangle: a #GeglRectangle
Index: gegl/process/gegl-processor.c
===================================================================
--- gegl/process/gegl-processor.c	(revision 2986)
+++ gegl/process/gegl-processor.c	(working copy)
@@ -30,6 +30,7 @@
 #include "gegl-processor.h"
 #include "gegl-types-internal.h"
 #include "gegl-utils.h"
+#include "gegl-debug.h"
 
 
 enum
@@ -418,8 +419,7 @@
         {
           gint band_size;
 
-          g_debug( "{%s:%u} rectangle (%ux%u) too big (> %u)",
-                  __FILE__, __LINE__, dr->height, dr->width, max_area );
+          GEGL_NOTE ( PROCESSOR, "rectangle [%s] too big (> %u)",gegl_rectangle_as_string (dr), max_area );
 
           {
             GeglRectangle *fragment;
@@ -445,9 +445,9 @@
               }
             processor->dirty_rectangles = g_slist_prepend (processor->dirty_rectangles, fragment);
 
-            g_debug ("{%s:%u} rectangle split to (%ux%u) and (%ux%u)\n",
-                    __FILE__, __LINE__, dr->height, dr->width,
-                    fragment->height, fragment->width);
+            GEGL_NOTE ( PROCESSOR, "rectangle split to [%s] and [%s]\n",
+                    gegl_rectangle_as_string (dr),
+                    gegl_rectangle_as_string (&fragment) );
           }
           return TRUE;
         }
_______________________________________________
Gegl-developer mailing list
Gegl-developer@xxxxxxxxxxxxxxxxxxxxxx
https://lists.XCF.Berkeley.EDU/mailman/listinfo/gegl-developer

[Index of Archives]     [Yosemite News]     [Yosemite Photos]     [gtk]     [GIMP Users]     [KDE]     [Gimp's Home]     [Gimp on Windows]     [Steve's Art]

  Powered by Linux