[gegl/soc-2011-seamless-clone: 26/35] Don't do the preprocessing twice if the aux buffer hasn't changed



commit 2b6516becdfcaa2abf3447d575c2408abdafb337
Author: Barak Itkin <lightningismyname gmail com>
Date:   Sat Jun 2 16:07:03 2012 +0300

    Don't do the preprocessing twice if the aux buffer hasn't changed

 operations/common/seamless-clone/seamless-clone.c |   56 ++++++++++++++++++--
 1 files changed, 50 insertions(+), 6 deletions(-)
---
diff --git a/operations/common/seamless-clone/seamless-clone.c b/operations/common/seamless-clone/seamless-clone.c
index a8cac17..541eef5 100644
--- a/operations/common/seamless-clone/seamless-clone.c
+++ b/operations/common/seamless-clone/seamless-clone.c
@@ -37,6 +37,13 @@ gegl_chant_int (max_refine_steps, _("Refinement Steps"), 0, 100000.0, 2000,
 #include <poly2tri-c/render/mesh-render.h>
 #include "seamless-clone-common.h"
 
+typedef struct SCProps_
+{
+  GMutex mutex;
+  GeglBuffer *aux;
+  ScCache *preprocess;
+} SCProps;
+
 static GeglRectangle
 get_required_for_output (GeglOperation       *operation,
                          const gchar         *input_pad,
@@ -64,12 +71,37 @@ static void
 prepare (GeglOperation *operation)
 {
   const Babl *format = babl_format ("R'G'B'A float");
+  GeglChantO *o = GEGL_CHANT_PROPERTIES (operation);
 
+  if (o->chant_data == NULL)
+    {
+      SCProps *props = g_slice_new (SCProps);
+      g_mutex_init (&props->mutex);
+      props->aux = NULL;
+      props->preprocess = NULL;
+      o->chant_data = props;
+    }
   gegl_operation_set_format (operation, "input",  format);
   gegl_operation_set_format (operation, "aux",    format);
   gegl_operation_set_format (operation, "output", format);
 }
 
+static void finalize (GObject *object)
+{
+  GeglOperation *op = (void*) object;
+  GeglChantO *o = GEGL_CHANT_PROPERTIES (op);
+  if (o->chant_data)
+    {
+      SCProps *props = (SCProps*) o->chant_data;
+      g_mutex_clear (&props->mutex);
+      props->aux = NULL;
+      if (props->preprocess)
+        sc_cache_free (props->preprocess);
+      o->chant_data = NULL;
+    }
+  G_OBJECT_CLASS (gegl_chant_parent_class)->finalize (object);
+}
+
 static gboolean
 process (GeglOperation       *operation,
          GeglBuffer          *input,
@@ -79,11 +111,22 @@ process (GeglOperation       *operation,
          gint                 level)
 {
   gboolean  return_val;
-  ScCache  *cache;
+  GeglChantO *o = GEGL_CHANT_PROPERTIES (operation);
+  SCProps *props;
+
+  g_assert (o->chant_data != NULL);
+
+  props = (SCProps*) o->chant_data;
+  g_mutex_lock (&props->mutex);
+  if (props->aux != aux)
+    {
+      props->aux = aux;
+      props->preprocess = NULL;
+      props->preprocess = sc_generate_cache (aux, gegl_operation_source_get_bounding_box (operation, "aux"), o -> max_refine_steps);
+    }
+  g_mutex_unlock (&props->mutex);
 
-  cache = sc_generate_cache (aux, gegl_operation_source_get_bounding_box (operation, "aux"), GEGL_CHANT_PROPERTIES (operation) -> max_refine_steps);
-  return_val = sc_render_seamless (input, aux, 0, 0, output, result, cache);
-  sc_cache_free (cache);
+  return_val = sc_render_seamless (input, aux, 0, 0, output, result, props->preprocess);
   
   return  return_val;
 }
@@ -94,8 +137,9 @@ gegl_chant_class_init (GeglChantClass *klass)
   GeglOperationClass         *operation_class = GEGL_OPERATION_CLASS (klass);
   GeglOperationComposerClass *composer_class  = GEGL_OPERATION_COMPOSER_CLASS (klass);
 
-  operation_class->prepare     = prepare;
-  composer_class->process      = process;
+  G_OBJECT_CLASS (klass)->finalize = finalize;
+  operation_class->prepare         = prepare;
+  composer_class->process          = process;
 
   operation_class->opencl_support = FALSE;
   gegl_operation_class_set_keys (operation_class,



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