[gegl/wip/rishi/operation-shadhi: 4/4] operations/workshop/shadows-highlights: Optimize the blur



commit 82f2ecfc42a5432757bf48202cbe92c2b863c0d0
Author: Debarshi Ray <debarshir gnome org>
Date:   Thu Nov 9 07:59:56 2017 +0100

    operations/workshop/shadows-highlights: Optimize the blur
    
    The algorithm needs a blurred CIE L channel and there is no need to
    spend time blurring the other components. Therefore, if the input has
    alpha, the blur is performed in "YaA float", else in "Y float".
    
    Bump required Babl version to 0.1.37.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=790111

 configure.ac                                       |    2 +-
 opencl/shadows-highlights-correction.cl            |    2 +-
 opencl/shadows-highlights-correction.cl.h          |    2 +-
 .../workshop/shadows-highlights-correction.c       |    6 +-
 operations/workshop/shadows-highlights.c           |   47 +++++++++++++++++++-
 5 files changed, 51 insertions(+), 8 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 2c7957a..de8a1a6 100644
--- a/configure.ac
+++ b/configure.ac
@@ -37,7 +37,7 @@ m4_define([gegl_stable],
 m4_define([gimp_full_name], [Generic Graphical Library])
 
 # required versions of external libraries
-m4_define([babl_required_version], [0.1.36])
+m4_define([babl_required_version], [0.1.37])
 m4_define([cairo_required_version], [1.12.2])
 m4_define([exiv2_required_version], [0.25])
 m4_define([gdk_pixbuf_required_version], [2.32.0])
diff --git a/opencl/shadows-highlights-correction.cl b/opencl/shadows-highlights-correction.cl
index af7a525..8322c98 100644
--- a/opencl/shadows-highlights-correction.cl
+++ b/opencl/shadows-highlights-correction.cl
@@ -63,7 +63,7 @@ __kernel void shadows_highlights(__global const float4  *in,
     }
 
   /* blurred, inverted and desaturaed mask in m */
-  m.x = 100.0f - aux[3 * gid];
+  m.x = 100.0f - aux[gid];
 
   /* white point adjustment */
   io.x = io.x > 0.0f ? io.x/whitepoint : io.x;
diff --git a/opencl/shadows-highlights-correction.cl.h b/opencl/shadows-highlights-correction.cl.h
index 6b83642..7cc06ad 100644
--- a/opencl/shadows-highlights-correction.cl.h
+++ b/opencl/shadows-highlights-correction.cl.h
@@ -64,7 +64,7 @@ static const char* shadows_highlights_correction_cl_source =
 "    }                                                                         \n"
 "                                                                              \n"
 "  /* blurred, inverted and desaturaed mask in m */                            \n"
-"  m.x = 100.0f - aux[3 * gid];                                                \n"
+"  m.x = 100.0f - aux[gid];                                                    \n"
 "                                                                              \n"
 "  /* white point adjustment */                                                \n"
 "  io.x = io.x > 0.0f ? io.x/whitepoint : io.x;                                \n"
diff --git a/operations/workshop/shadows-highlights-correction.c 
b/operations/workshop/shadows-highlights-correction.c
index 279deb3..713ac5b 100644
--- a/operations/workshop/shadows-highlights-correction.c
+++ b/operations/workshop/shadows-highlights-correction.c
@@ -60,10 +60,10 @@ static void
 prepare (GeglOperation *operation)
 {
   const Babl *cie_laba = babl_format ("CIE Lab alpha float");
-  const Babl *cie_lab  = babl_format ("CIE Lab float");
+  const Babl *cie_l    = babl_format ("CIE L float");
 
   gegl_operation_set_format (operation, "input",  cie_laba);
-  gegl_operation_set_format (operation, "aux",    cie_lab);
+  gegl_operation_set_format (operation, "aux",    cie_l);
   gegl_operation_set_format (operation, "output", cie_laba);
 }
 
@@ -196,7 +196,7 @@ process (GeglOperation       *operation,
 
       src += 4;
       dst += 4;
-      aux += 3;
+      aux += 1;
     }
 
   return TRUE;
diff --git a/operations/workshop/shadows-highlights.c b/operations/workshop/shadows-highlights.c
index 8fa4745..15160b8 100644
--- a/operations/workshop/shadows-highlights.c
+++ b/operations/workshop/shadows-highlights.c
@@ -59,6 +59,8 @@ struct _GeglOp
   GeglOperationMeta parent_instance;
   gpointer          properties;
 
+  const Babl *blur_format;
+  GeglNode *blur_convert;
   GeglNode *input;
   GeglNode *output;
 };
@@ -92,6 +94,8 @@ do_setup (GeglOperation *operation)
   g_return_if_fail (GEGL_IS_NODE (self->input));
   g_return_if_fail (GEGL_IS_NODE (self->output));
 
+  self->blur_convert = NULL;
+
   children = gegl_node_get_children (operation->node);
   for (l = children; l != NULL; l = l->next)
     {
@@ -117,11 +121,19 @@ do_setup (GeglOperation *operation)
                                   "abyss-policy", 1,
                                   NULL);
 
+      if (self->blur_format == NULL)
+        self->blur_format = babl_format ("YaA float");
+
+      self->blur_convert = gegl_node_new_child (operation->node,
+                                                "operation", "gegl:convert-format",
+                                                "format",    self->blur_format,
+                                                NULL);
+
       shprocess = gegl_node_new_child (operation->node,
                                        "operation", "gegl:shadows-highlights-correction",
                                        NULL);
 
-      gegl_node_link (self->input, blur);
+      gegl_node_link_many (self->input, self->blur_convert, blur, NULL);
       gegl_node_link_many (self->input, shprocess, self->output, NULL);
 
       gegl_node_connect_to (blur, "output", shprocess, "aux");
@@ -135,7 +147,7 @@ do_setup (GeglOperation *operation)
       gegl_operation_meta_redirect (operation, "shadows-ccorrect", shprocess, "shadows-ccorrect");
       gegl_operation_meta_redirect (operation, "highlights-ccorrect", shprocess, "highlights-ccorrect");
 
-      gegl_operation_meta_watch_nodes (operation, blur, shprocess, NULL);
+      gegl_operation_meta_watch_nodes (operation, blur, self->blur_convert, shprocess, NULL);
     }
 
   g_slist_free (children);
@@ -155,6 +167,36 @@ attach (GeglOperation *operation)
 }
 
 static void
+prepare (GeglOperation *operation)
+{
+  GeglOp *self = GEGL_OP (operation);
+  const Babl *blur_format = NULL;
+  const Babl *input_format;
+
+  input_format = gegl_operation_get_source_format (operation, "input");
+  if (input_format == NULL)
+    {
+      blur_format = babl_format ("YaA float");
+      goto out;
+    }
+
+  if (babl_format_has_alpha (input_format))
+    blur_format = babl_format ("YaA float");
+  else
+    blur_format = babl_format ("Y float");
+
+ out:
+  g_return_if_fail (blur_format != NULL);
+
+  if (self->blur_format != blur_format)
+    {
+      self->blur_format = blur_format;
+      if (self->blur_convert != NULL)
+        gegl_node_set (self->blur_convert, "format", self->blur_format, NULL);
+    }
+}
+
+static void
 my_set_property (GObject      *gobject,
                  guint         property_id,
                  const GValue *value,
@@ -188,6 +230,7 @@ gegl_op_class_init (GeglOpClass *klass)
   object_class->set_property = my_set_property;
 
   operation_class->attach = attach;
+  operation_class->prepare = prepare;
 
   gegl_operation_class_set_keys (operation_class,
     "name",        "gegl:shadows-highlights",


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