[gimp] app: in GimpIScissorsTool, use sampler object ...



commit 3c95928031294181ac389638204470b09ffa16ac
Author: Ell <ell_se yahoo com>
Date:   Sun May 13 19:08:13 2018 -0400

    app: in GimpIScissorsTool, use sampler object ...
    
    ... instead of gegl_buffer_sample()
    
    Ditto.

 app/core/gimpasync.c          |   22 +++++++++++
 app/core/gimpasync.h          |    3 +-
 app/tools/gimpiscissorstool.c |   85 ++++++++++++++++++++++-------------------
 3 files changed, 70 insertions(+), 40 deletions(-)
---
diff --git a/app/core/gimpasync.c b/app/core/gimpasync.c
index 6b1970c..b4c5c78 100644
--- a/app/core/gimpasync.c
+++ b/app/core/gimpasync.c
@@ -49,6 +49,9 @@
  */
 
 
+/* #define TIME_ASYNC_OPS */
+
+
 typedef struct _GimpAsyncCallbackInfo GimpAsyncCallbackInfo;
 
 
@@ -73,6 +76,11 @@ struct _GimpAsyncPrivate
   gboolean        stopped;
   gboolean        finished;
   gboolean        canceled;
+
+
+#ifdef TIME_ASYNC_OPS
+  guint64         start_time;
+#endif
 };
 
 
@@ -114,6 +122,10 @@ gimp_async_init (GimpAsync *async)
   g_cond_init  (&async->priv->cond);
 
   g_queue_init (&async->priv->callbacks);
+
+#ifdef TIME_ASYNC_OPS
+  async->priv->start_time = g_get_monotonic_time ();
+#endif
 }
 
 static void
@@ -151,6 +163,16 @@ gimp_async_idle (GimpAsync *async)
 static void
 gimp_async_stop (GimpAsync *async)
 {
+#ifdef TIME_ASYNC_OPS
+  {
+    guint64 time = g_get_monotonic_time ();
+
+    g_printerr ("Asynchronous operation took %g seconds%s\n",
+                (time - async->priv->start_time) / 1000000.0,
+                async->priv->finished ? "" : " (aborted)");
+  }
+#endif
+
   if (! g_queue_is_empty (&async->priv->callbacks))
     {
       g_object_ref (async);
diff --git a/app/core/gimpasync.h b/app/core/gimpasync.h
index 73be6f7..245aa70 100644
--- a/app/core/gimpasync.h
+++ b/app/core/gimpasync.h
@@ -69,9 +69,10 @@ void        gimp_async_finish_full  (GimpAsync         *async,
 gboolean    gimp_async_is_finished  (GimpAsync         *async);
 gpointer    gimp_async_get_result   (GimpAsync         *async);
 
+void        gimp_async_abort        (GimpAsync         *async);
+
 void        gimp_async_cancel       (GimpAsync         *async);
 gboolean    gimp_async_is_canceled  (GimpAsync         *async);
-void        gimp_async_abort        (GimpAsync         *async);
 
 
 #endif /* __GIMP_ASYNC_H__ */
diff --git a/app/tools/gimpiscissorstool.c b/app/tools/gimpiscissorstool.c
index 7a7afd1..52d8cb8 100644
--- a/app/tools/gimpiscissorstool.c
+++ b/app/tools/gimpiscissorstool.c
@@ -1579,25 +1579,21 @@ calculate_segment (GimpIscissorsTool *iscissors,
 
 /* badly need to get a replacement - this is _way_ too expensive */
 static gboolean
-gradient_map_value (GeglBuffer *map,
-                    gint        x,
-                    gint        y,
-                    guint8     *grad,
-                    guint8     *dir)
+gradient_map_value (GeglSampler         *map_sampler,
+                    const GeglRectangle *map_extent,
+                    gint                 x,
+                    gint                 y,
+                    guint8              *grad,
+                    guint8              *dir)
 {
-  const GeglRectangle *extents;
-
-  extents = gegl_buffer_get_extent (map);
-
-  if (x >= extents->x     &&
-      y >= extents->y     &&
-      x <  extents->width &&
-      y <  extents->height)
+  if (x >= map_extent->x     &&
+      y >= map_extent->y     &&
+      x <  map_extent->width &&
+      y <  map_extent->height)
     {
       guint8 sample[2];
 
-      gegl_buffer_sample (map, x, y, NULL, sample, NULL,
-                          GEGL_SAMPLER_NEAREST, GEGL_ABYSS_NONE);
+      gegl_sampler_get (map_sampler, x, y, NULL, sample, GEGL_ABYSS_NONE);
 
       *grad = sample[0];
       *dir  = sample[1];
@@ -1609,16 +1605,17 @@ gradient_map_value (GeglBuffer *map,
 }
 
 static gint
-calculate_link (GeglBuffer *gradient_map,
-                gint        x,
-                gint        y,
-                guint32     pixel,
-                gint        link)
+calculate_link (GeglSampler         *map_sampler,
+                const GeglRectangle *map_extent,
+                gint                 x,
+                gint                 y,
+                guint32              pixel,
+                gint                 link)
 {
   gint   value = 0;
   guint8 grad1, dir1, grad2, dir2;
 
-  if (! gradient_map_value (gradient_map, x, y, &grad1, &dir1))
+  if (! gradient_map_value (map_sampler, map_extent, x, y, &grad1, &dir1))
     {
       grad1 = 0;
       dir1 = 255;
@@ -1638,7 +1635,7 @@ calculate_link (GeglBuffer *gradient_map,
   x += (gint8)(pixel & 0xff);
   y += (gint8)((pixel & 0xff00) >> 8);
 
-  if (! gradient_map_value (gradient_map, x, y, &grad2, &dir2))
+  if (! gradient_map_value (map_sampler, map_extent, x, y, &grad2, &dir2))
     {
       grad2 = 0;
       dir2 = 255;
@@ -1709,22 +1706,30 @@ find_optimal_path (GeglBuffer  *gradient_map,
                    gint         xs,
                    gint         ys)
 {
-  gint     i, j, k;
-  gint     x, y;
-  gint     link;
-  gint     linkdir;
-  gint     dirx, diry;
-  gint     min_cost;
-  gint     new_cost;
-  gint     offset;
-  gint     cum_cost[8];
-  gint     link_cost[8];
-  gint     pixel_cost[8];
-  guint32  pixel[8];
-  guint32 *data;
-  guint32 *d;
-  gint     dp_buf_width  = gimp_temp_buf_get_width  (dp_buf);
-  gint     dp_buf_height = gimp_temp_buf_get_height (dp_buf);
+  GeglSampler         *map_sampler;
+  const GeglRectangle *map_extent;
+  gint                 i, j, k;
+  gint                 x, y;
+  gint                 link;
+  gint                 linkdir;
+  gint                 dirx, diry;
+  gint                 min_cost;
+  gint                 new_cost;
+  gint                 offset;
+  gint                 cum_cost[8];
+  gint                 link_cost[8];
+  gint                 pixel_cost[8];
+  guint32              pixel[8];
+  guint32             *data;
+  guint32             *d;
+  gint                 dp_buf_width  = gimp_temp_buf_get_width  (dp_buf);
+  gint                 dp_buf_height = gimp_temp_buf_get_height (dp_buf);
+
+  /*  initialize the gradient map sampler and extent  */
+  map_sampler = gegl_buffer_sampler_new (gradient_map,
+                                         gegl_buffer_get_format (gradient_map),
+                                         GEGL_SAMPLER_NEAREST);
+  map_extent  = gegl_buffer_get_extent (gradient_map);
 
   /*  initialize the dynamic programming buffer  */
   data = (guint32 *) gimp_temp_buf_data_clear (dp_buf);
@@ -1780,7 +1785,7 @@ find_optimal_path (GeglBuffer  *gradient_map,
           for (k = 0; k < 8; k ++)
             if (pixel[k])
               {
-                link_cost[k] = calculate_link (gradient_map,
+                link_cost[k] = calculate_link (map_sampler, map_extent,
                                                xs + j*dirx, ys + i*diry,
                                                pixel [k],
                                                ((k > 3) ? k - 4 : k));
@@ -1835,6 +1840,8 @@ find_optimal_path (GeglBuffer  *gradient_map,
       /*  increment the y counter  */
       y += diry;
     }
+
+  g_object_unref (map_sampler);
 }
 
 static GeglBuffer *


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