[gegl] color-to-alpha-plus: add compress-threshold-range property



commit 2c612f7d65349a021ed91ed07aad5a21c55bc3c4
Author: Ell <ell_se yahoo com>
Date:   Sun Oct 22 14:11:46 2017 -0400

    color-to-alpha-plus: add compress-threshold-range property
    
    Add a boolean compress-threshold-range property.  When unset, the
    transparency and opacity thresholds are interpreted as absolute
    distances from the selected color (using a chessboard metric); when
    set, the threshold range is compressed so that a threshold of 1 maps
    to the greatest distance from the selected color to any of the faces
    of the RGB cube, so that each threshold value produces a
    (potentially) different result (assuming all colors are clipped).
    
    Previously, the threshold range was always compressed, although now
    we default the property to FALSE (when the transparency threshold
    is 0, and the opacity threshold is 1, the result is still the same
    as color-to-alpha, regardless of the value of this proeprty.)
    
    This property is added mostly for experimentation, and will most
    likely not make it back to color-to-alpha.

 operations/workshop/color-to-alpha-plus.c |   47 ++++++++++++++++------------
 1 files changed, 27 insertions(+), 20 deletions(-)
---
diff --git a/operations/workshop/color-to-alpha-plus.c b/operations/workshop/color-to-alpha-plus.c
index 11a6e51..e7f6f02 100644
--- a/operations/workshop/color-to-alpha-plus.c
+++ b/operations/workshop/color-to-alpha-plus.c
@@ -37,6 +37,9 @@ property_double (opacity_threshold, _("Opacity threshold"), 1.0)
     description(_("The limit above which colors remain opaque."))
     value_range (0.0, 1.0)
 
+property_boolean (compress_threshold_range, _("Compress threshold range"), FALSE)
+    description(_("Compress the threshold range to the minimal extent that would produce different 
results."))
+
 #else
 
 #define GEGL_OP_POINT_FILTER
@@ -95,8 +98,8 @@ static void
 color_to_alpha (const gfloat *color,
                 const gfloat *src,
                 gfloat       *dst,
-                gfloat        transparency_radius,
-                gfloat        opacity_radius)
+                gfloat        transparency_threshold,
+                gfloat        opacity_threshold)
 {
   gint   i;
   gfloat dist  = 0.0f;
@@ -112,14 +115,14 @@ color_to_alpha (const gfloat *color,
 
       d = fabsf (dst[i] - color[i]);
 
-      if (d < transparency_radius + EPSILON)
+      if (d < transparency_threshold + EPSILON)
         a = 0.0f;
-      else if (d > opacity_radius - EPSILON)
+      else if (d > opacity_threshold - EPSILON)
         a = 1.0f;
       else if (dst[i] < color[i])
-        a = (d - transparency_radius) / (MIN (opacity_radius,        color[i]) - transparency_radius);
+        a = (d - transparency_threshold) / (MIN (opacity_threshold,        color[i]) - 
transparency_threshold);
       else
-        a = (d - transparency_radius) / (MIN (opacity_radius, 1.0f - color[i]) - transparency_radius);
+        a = (d - transparency_threshold) / (MIN (opacity_threshold, 1.0f - color[i]) - 
transparency_threshold);
 
       if (a > alpha)
         {
@@ -130,7 +133,7 @@ color_to_alpha (const gfloat *color,
 
   if (alpha > EPSILON)
     {
-      gfloat ratio     = transparency_radius / dist;
+      gfloat ratio     = transparency_threshold / dist;
       gfloat alpha_inv = 1.0f / alpha;
 
       for (i = 0; i < 3; i++)
@@ -154,30 +157,34 @@ process (GeglOperation       *operation,
          const GeglRectangle *roi,
          gint                 level)
 {
-  GeglProperties *o      = GEGL_PROPERTIES (operation);
-  const Babl *format = babl_format ("R'G'B'A float");
-  gfloat      color[4];
-  gfloat      radius = 0.0;
-  gfloat      transparency_radius;
-  gfloat      opacity_radius;
-  gint        i;
-  gint        x;
+  GeglProperties *o                      = GEGL_PROPERTIES (operation);
+  const Babl     *format                 = babl_format ("R'G'B'A float");
+  gfloat          color[4];
+  gfloat          max_extent = 0.0;
+  gfloat          transparency_threshold = o->transparency_threshold;
+  gfloat          opacity_threshold      = o->opacity_threshold;
+  gint            x;
 
   gfloat *in_buff = in_buf;
   gfloat *out_buff = out_buf;
 
   gegl_color_get_pixel (o->color, format, color);
 
-  for (i = 0; i < 3; i++)
-    radius = MAX (radius, MAX (color[i], 1.0 - color[i]));
+  if (o->compress_threshold_range)
+    {
+      gint i;
 
-  transparency_radius = radius * o->transparency_threshold;
-  opacity_radius      = radius * o->opacity_threshold;
+      for (i = 0; i < 3; i++)
+        max_extent = MAX (max_extent, MAX (color[i], 1.0 - color[i]));
+
+      transparency_threshold *= max_extent;
+      opacity_threshold      *= max_extent;
+    }
 
   for (x = 0; x < n_pixels; x++)
     {
       color_to_alpha (color, in_buff, out_buff,
-                      transparency_radius, opacity_radius);
+                      transparency_threshold, opacity_threshold);
       in_buff  += 4;
       out_buff += 4;
     }


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