[gimp] app: fix leftmost and rightmost gradient colors in GimpOperationBlend



commit 4e2e60caf4919c452689cbae1456c3648dbafdb4
Author: Ell <ell_se yahoo com>
Date:   Mon Oct 9 12:14:54 2017 -0400

    app: fix leftmost and rightmost gradient colors in GimpOperationBlend
    
    When rendering a gradient with a repeat mode of NONE, don't sample
    the gradient at 0.0 and 1.0, for pixels that lie to the left and to
    the right of the gradient, respectively.  Instead, use the left
    color of the leftmost segment directly, and, likewise, the right
    color of the rightmost segment.  This always gives us the right
    color for such pixels, even when there are gradient stops, that may
    use different colors, at 0.0 and 1.0,

 app/operations/gimpoperationblend.c |   25 +++++++++++++++++++------
 1 files changed, 19 insertions(+), 6 deletions(-)
---
diff --git a/app/operations/gimpoperationblend.c b/app/operations/gimpoperationblend.c
index 186d79b..f6be809 100644
--- a/app/operations/gimpoperationblend.c
+++ b/app/operations/gimpoperationblend.c
@@ -75,6 +75,8 @@ typedef struct
   gdouble              dist;
   gdouble              vec[2];
   GimpRepeatMode       repeat;
+  GimpRGB              leftmost_color;
+  GimpRGB              rightmost_color;
   GRand               *seed;
   GeglBuffer          *dist_buffer;
 } RenderBlendData;
@@ -886,10 +888,7 @@ gradient_render_pixel (gdouble   x,
   switch (rbd->repeat)
     {
     case GIMP_REPEAT_TRUNCATE:
-      break;
-
     case GIMP_REPEAT_NONE:
-      factor = CLAMP (factor, 0.0, 1.0);
       break;
 
     case GIMP_REPEAT_SAWTOOTH:
@@ -914,10 +913,13 @@ gradient_render_pixel (gdouble   x,
 
   /* Blend the colors */
 
-  if (factor < 0.0 || factor > 1.0)
+  if (factor < 0.0)
+    {
+      *color = rbd->leftmost_color;
+    }
+  else if (factor > 1.0)
     {
-      color->r = color->g = color->b = 0;
-      color->a = GIMP_OPACITY_TRANSPARENT;
+      *color = rbd->rightmost_color;
     }
   else
     {
@@ -1066,6 +1068,17 @@ gimp_operation_blend_process (GeglOperation       *operation,
   rbd.gradient_type = self->gradient_type;
   rbd.repeat        = self->gradient_repeat;
 
+  if (rbd.repeat == GIMP_REPEAT_NONE)
+    {
+      gimp_gradient_segment_get_left_flat_color  (rbd.gradient, NULL,
+                                                  rbd.gradient->segments,
+                                                  &rbd.leftmost_color);
+      gimp_gradient_segment_get_right_flat_color (rbd.gradient, NULL,
+                                                  gimp_gradient_segment_get_last (
+                                                    rbd.gradient->segments),
+                                                  &rbd.rightmost_color);
+    }
+
   /* Render the gradient! */
 
   if (self->supersample)


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