[gimp] app: add a boolean "normalize" property to gimp:shapeburst



commit 16819917f56124ebe64ee9b1a94dd1849f2ebf03
Author: Michael Natterer <mitch gimp org>
Date:   Thu May 1 20:40:55 2014 +0200

    app: add a boolean "normalize" property to gimp:shapeburst
    
    and do the normalization in the op, instead of exporting the
    max_iterations via a property and doing the normalization outside.

 app/core/gimpdrawable-blend.c            |   25 +-----------------
 app/operations/gimpoperationshapeburst.c |   42 ++++++++++++++++++++----------
 app/operations/gimpoperationshapeburst.h |    2 +-
 3 files changed, 30 insertions(+), 39 deletions(-)
---
diff --git a/app/core/gimpdrawable-blend.c b/app/core/gimpdrawable-blend.c
index 24bf184..5c9fa91 100644
--- a/app/core/gimpdrawable-blend.c
+++ b/app/core/gimpdrawable-blend.c
@@ -539,8 +539,6 @@ gradient_precalc_shapeburst (GimpImage           *image,
   GeglBuffer  *dist_buffer;
   GeglBuffer  *temp_buffer;
   GeglNode    *shapeburst;
-  gdouble      max;
-  gfloat       max_iteration;
 
   gimp_progress_set_text (progress, _("Calculating distance map"));
 
@@ -602,6 +600,7 @@ gradient_precalc_shapeburst (GimpImage           *image,
 
   shapeburst = gegl_node_new_child (NULL,
                                     "operation", "gimp:shapeburst",
+                                    "normalize", TRUE,
                                     NULL);
 
   gimp_gegl_progress_connect (shapeburst, progress, NULL);
@@ -610,32 +609,10 @@ gradient_precalc_shapeburst (GimpImage           *image,
                              shapeburst,
                              dist_buffer, NULL);
 
-  gegl_node_get (shapeburst, "max-iterations", &max, NULL);
-
   g_object_unref (shapeburst);
 
-  max_iteration = max;
-
   g_object_unref (temp_buffer);
 
-  /*  normalize the shapeburst with the max iteration  */
-  if (max_iteration > 0)
-    {
-      GeglBufferIterator *iter;
-
-      iter = gegl_buffer_iterator_new (dist_buffer, NULL, 0, NULL,
-                                       GEGL_BUFFER_READWRITE, GEGL_ABYSS_NONE);
-
-      while (gegl_buffer_iterator_next (iter))
-        {
-          gint    count = iter->length;
-          gfloat *data  = iter->data[0];
-
-          while (count--)
-            *data++ /= max_iteration;
-        }
-    }
-
   return dist_buffer;
 }
 
diff --git a/app/operations/gimpoperationshapeburst.c b/app/operations/gimpoperationshapeburst.c
index 11fdea5..456993b 100644
--- a/app/operations/gimpoperationshapeburst.c
+++ b/app/operations/gimpoperationshapeburst.c
@@ -35,7 +35,7 @@
 enum
 {
   PROP_0,
-  PROP_MAX_ITERATIONS,
+  PROP_NORMALIZE,
   PROP_PROGRESS
 };
 
@@ -92,12 +92,12 @@ gimp_operation_shapeburst_class_init (GimpOperationShapeburstClass *klass)
 
   filter_class->process                    = gimp_operation_shapeburst_process;
 
-  g_object_class_install_property (object_class, PROP_MAX_ITERATIONS,
-                                   g_param_spec_double ("max-iterations",
-                                                        "Max Iterations",
-                                                        "Max Iterations",
-                                                        0.0, G_MAXFLOAT, 0.0,
-                                                        G_PARAM_READWRITE));
+  g_object_class_install_property (object_class, PROP_NORMALIZE,
+                                   g_param_spec_boolean ("normalize",
+                                                         "Normalize",
+                                                         "Normalize",
+                                                         FALSE,
+                                                         G_PARAM_READWRITE));
 
   g_object_class_install_property (object_class, PROP_PROGRESS,
                                    g_param_spec_double ("progress",
@@ -122,8 +122,8 @@ gimp_operation_shapeburst_get_property (GObject    *object,
 
   switch (property_id)
     {
-    case PROP_MAX_ITERATIONS:
-      g_value_set_double (value, self->max_iterations);
+    case PROP_NORMALIZE:
+      g_value_set_boolean (value, self->normalize);
       break;
 
     case PROP_PROGRESS:
@@ -146,8 +146,8 @@ gimp_operation_shapeburst_set_property (GObject      *object,
 
   switch (property_id)
     {
-    case PROP_MAX_ITERATIONS:
-      self->max_iterations = g_value_get_double (value);
+    case PROP_NORMALIZE:
+      self->normalize = g_value_get_boolean (value);
       break;
 
     case PROP_PROGRESS:
@@ -312,9 +312,23 @@ gimp_operation_shapeburst_process (GeglOperation       *operation,
 
   g_free (memory);
 
-  g_object_set (operation,
-                "max-iterations", (gdouble) max_iterations,
-                NULL);
+  if (GIMP_OPERATION_SHAPEBURST (operation)->normalize &&
+      max_iterations > 0.0)
+    {
+      GeglBufferIterator *iter;
+
+      iter = gegl_buffer_iterator_new (output, NULL, 0, NULL,
+                                       GEGL_BUFFER_READWRITE, GEGL_ABYSS_NONE);
+
+      while (gegl_buffer_iterator_next (iter))
+        {
+          gint    count = iter->length;
+          gfloat *data  = iter->data[0];
+
+          while (count--)
+            *data++ /= max_iterations;
+        }
+    }
 
   return TRUE;
 }
diff --git a/app/operations/gimpoperationshapeburst.h b/app/operations/gimpoperationshapeburst.h
index 362b159..31906b7 100644
--- a/app/operations/gimpoperationshapeburst.h
+++ b/app/operations/gimpoperationshapeburst.h
@@ -40,7 +40,7 @@ struct _GimpOperationShapeburst
 {
   GeglOperationFilter  parent_instance;
 
-  gdouble              max_iterations;
+  gboolean             normalize;
   gdouble              progress;
 };
 


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