[gimp/gimp-2-10] app: improve gradient color-sampling speed



commit d70aeea5500da26606173634070a8233e3fa57c3
Author: Ell <ell_se yahoo com>
Date:   Thu Dec 20 08:29:33 2018 -0500

    app: improve gradient color-sampling speed
    
    Improve the speed of gimp_gradient_get_color_at(), which is used by
    gimp:gradient during processing when the gradient cache is too big,
    by disabling type checking, and inlining and avoiding some function
    calls.
    
    (cherry picked from commit 93f4b187044acc4cfa32c52589891ba7e3ab3de7)

 app/core/gimpgradient.c | 23 ++++++++++++++++-------
 1 file changed, 16 insertions(+), 7 deletions(-)
---
diff --git a/app/core/gimpgradient.c b/app/core/gimpgradient.c
index b64a19a6a5..8265225c85 100644
--- a/app/core/gimpgradient.c
+++ b/app/core/gimpgradient.c
@@ -70,7 +70,7 @@ static gint          gimp_gradient_compare           (GimpData            *data1
 
 static gchar       * gimp_gradient_get_checksum      (GimpTagged          *tagged);
 
-static GimpGradientSegment *
+static inline GimpGradientSegment *
               gimp_gradient_get_segment_at_internal  (GimpGradient        *gradient,
                                                       GimpGradientSegment *seg,
                                                       gdouble              pos);
@@ -460,7 +460,8 @@ gimp_gradient_get_color_at (GimpGradient                *gradient,
   GimpRGB  right_color;
   GimpRGB  rgb;
 
-  g_return_val_if_fail (GIMP_IS_GRADIENT (gradient), NULL);
+  /* type-check disabled to improve speed */
+  /* g_return_val_if_fail (GIMP_IS_GRADIENT (gradient), NULL); */
   g_return_val_if_fail (color != NULL, NULL);
 
   pos = CLAMP (pos, 0.0, 1.0);
@@ -516,11 +517,19 @@ gimp_gradient_get_color_at (GimpGradient                *gradient,
 
   /* Get left/right colors */
 
-  gimp_gradient_segment_get_left_flat_color (gradient,
-                                             context, seg, &left_color);
+  if (context)
+    {
+      gimp_gradient_segment_get_left_flat_color (gradient,
+                                                 context, seg, &left_color);
 
-  gimp_gradient_segment_get_right_flat_color (gradient,
-                                              context, seg, &right_color);
+      gimp_gradient_segment_get_right_flat_color (gradient,
+                                                  context, seg, &right_color);
+    }
+  else
+    {
+      left_color  = seg->left_color;
+      right_color = seg->right_color;
+    }
 
   /* Calculate color components */
 
@@ -2160,7 +2169,7 @@ gimp_gradient_segment_range_move (GimpGradient        *gradient,
 
 /*  private functions  */
 
-static GimpGradientSegment *
+static inline GimpGradientSegment *
 gimp_gradient_get_segment_at_internal (GimpGradient        *gradient,
                                        GimpGradientSegment *seg,
                                        gdouble              pos)


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