[gimp] app: add offset support to shaped gradients



commit 6bd5deea893bbe150e84c5f6f7e2e7fe33945a9a
Author: Ell <ell_se yahoo com>
Date:   Sun Sep 22 21:57:30 2019 +0300

    app: add offset support to shaped gradients
    
    In gimp:gradient, handle the "offset" property in shaped gradients.

 app/operations/gimpoperationgradient.c | 36 ++++++++++++++++++++++++++++++++++
 1 file changed, 36 insertions(+)
---
diff --git a/app/operations/gimpoperationgradient.c b/app/operations/gimpoperationgradient.c
index cc5251820c..9bbc294e1b 100644
--- a/app/operations/gimpoperationgradient.c
+++ b/app/operations/gimpoperationgradient.c
@@ -139,12 +139,15 @@ static gdouble         gradient_calc_spiral_factor               (gdouble
                                                                   gboolean               clockwise);
 
 static gdouble         gradient_calc_shapeburst_angular_factor   (GeglSampler           *dist_sampler,
+                                                                  gdouble                offset,
                                                                   gdouble                x,
                                                                   gdouble                y);
 static gdouble         gradient_calc_shapeburst_spherical_factor (GeglSampler           *dist_sampler,
+                                                                  gdouble                offset,
                                                                   gdouble                x,
                                                                   gdouble                y);
 static gdouble         gradient_calc_shapeburst_dimpled_factor   (GeglSampler           *dist_sampler,
+                                                                  gdouble                offset,
                                                                   gdouble                x,
                                                                   gdouble                y);
 
@@ -797,28 +800,48 @@ gradient_calc_spiral_factor (gdouble   dist,
 
 static gdouble
 gradient_calc_shapeburst_angular_factor (GeglSampler *dist_sampler,
+                                         gdouble      offset,
                                          gdouble      x,
                                          gdouble      y)
 {
   gfloat value;
 
+  offset = offset / 100.0;
+
   gegl_sampler_get (dist_sampler, x, y, NULL, &value, GEGL_ABYSS_NONE);
 
   value = 1.0 - value;
 
+  if (value < offset)
+    value = 0.0;
+  else if (offset == 1.0)
+    value = (value >= 1.0) ? 1.0 : 0.0;
+  else
+    value = (value - offset) / (1.0 - offset);
+
   return value;
 }
 
 
 static gdouble
 gradient_calc_shapeburst_spherical_factor (GeglSampler *dist_sampler,
+                                           gdouble      offset,
                                            gdouble      x,
                                            gdouble      y)
 {
   gfloat value;
 
+  offset = 1.0 - offset / 100.0;
+
   gegl_sampler_get (dist_sampler, x, y, NULL, &value, GEGL_ABYSS_NONE);
 
+  if (value > offset)
+    value = 1.0;
+  else if (offset == 0.0)
+    value = (value <= 0.0) ? 0.0 : 1.0;
+  else
+    value = value / offset;
+
   value = 1.0 - sin (0.5 * G_PI * value);
 
   return value;
@@ -827,13 +850,23 @@ gradient_calc_shapeburst_spherical_factor (GeglSampler *dist_sampler,
 
 static gdouble
 gradient_calc_shapeburst_dimpled_factor (GeglSampler *dist_sampler,
+                                         gdouble      offset,
                                          gdouble      x,
                                          gdouble      y)
 {
   gfloat value;
 
+  offset = 1.0 - offset / 100.0;
+
   gegl_sampler_get (dist_sampler, x, y, NULL, &value, GEGL_ABYSS_NONE);
 
+  if (value > offset)
+    value = 1.0;
+  else if (offset == 0.0)
+    value = (value <= 0.0) ? 0.0 : 1.0;
+  else
+    value = value / offset;
+
   value = cos (0.5 * G_PI * value);
 
   return value;
@@ -893,16 +926,19 @@ gradient_render_pixel (gdouble   x,
 
     case GIMP_GRADIENT_SHAPEBURST_ANGULAR:
       factor = gradient_calc_shapeburst_angular_factor (rbd->dist_sampler,
+                                                        rbd->offset,
                                                         x, y);
       break;
 
     case GIMP_GRADIENT_SHAPEBURST_SPHERICAL:
       factor = gradient_calc_shapeburst_spherical_factor (rbd->dist_sampler,
+                                                          rbd->offset,
                                                           x, y);
       break;
 
     case GIMP_GRADIENT_SHAPEBURST_DIMPLED:
       factor = gradient_calc_shapeburst_dimpled_factor (rbd->dist_sampler,
+                                                        rbd->offset,
                                                         x, y);
       break;
 


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