[gimp/wip/gradient-edit: 42/42] app: cache last-sampled gradient segment in GimpOperationBlend



commit f929c548d1f53978d8e81873024b24f4ef6b9ba9
Author: Ell <ell_se yahoo com>
Date:   Sat Aug 12 11:15:21 2017 -0400

    app: cache last-sampled gradient segment in GimpOperationBlend
    
    Remember the gradient segment at which the most-recent sample lies,
    and pass it to gimp_gradient_get_color_at() as a seed for segement
    lookup on the next sample.  This improves the performance
    marginally.

 app/operations/gimpoperationblend.c |   40 +++++++++++++++++++---------------
 1 files changed, 22 insertions(+), 18 deletions(-)
---
diff --git a/app/operations/gimpoperationblend.c b/app/operations/gimpoperationblend.c
index a294d32..186d79b 100644
--- a/app/operations/gimpoperationblend.c
+++ b/app/operations/gimpoperationblend.c
@@ -61,20 +61,22 @@ enum
 
 typedef struct
 {
-  GimpGradient     *gradient;
-  gboolean          reverse;
+  GimpGradient        *gradient;
+  gboolean             reverse;
 #ifdef USE_GRADIENT_CACHE
-  GimpRGB          *gradient_cache;
-  gint              gradient_cache_size;
+  GimpRGB             *gradient_cache;
+  gint                 gradient_cache_size;
+#else
+  GimpGradientSegment *last_seg;
 #endif
-  gdouble           offset;
-  gdouble           sx, sy;
-  GimpGradientType  gradient_type;
-  gdouble           dist;
-  gdouble           vec[2];
-  GimpRepeatMode    repeat;
-  GRand            *seed;
-  GeglBuffer       *dist_buffer;
+  gdouble              offset;
+  gdouble              sx, sy;
+  GimpGradientType     gradient_type;
+  gdouble              dist;
+  gdouble              vec[2];
+  GimpRepeatMode       repeat;
+  GRand               *seed;
+  GeglBuffer          *dist_buffer;
 } RenderBlendData;
 
 
@@ -922,8 +924,9 @@ gradient_render_pixel (gdouble   x,
 #ifdef USE_GRADIENT_CACHE
       *color = rbd->gradient_cache[(gint) (factor * (rbd->gradient_cache_size - 1))];
 #else
-      gimp_gradient_get_color_at (rbd->gradient, NULL, NULL,
-                                  factor, rbd->reverse, color);
+      rbd->last_seg = gimp_gradient_get_color_at (rbd->gradient, NULL,
+                                                  rbd->last_seg, factor,
+                                                  rbd->reverse, color);
 #endif
     }
 }
@@ -998,7 +1001,8 @@ gimp_operation_blend_process (GeglOperation       *operation,
 
 #ifdef USE_GRADIENT_CACHE
   {
-    gint i;
+    GimpGradientSegment *last_seg = NULL;
+    gint                 i;
 
     rbd.gradient_cache_size = ceil (sqrt (SQR (sx - ex) + SQR (sy - ey)));
     rbd.gradient_cache      = g_new0 (GimpRGB, rbd.gradient_cache_size);
@@ -1007,9 +1011,9 @@ gimp_operation_blend_process (GeglOperation       *operation,
       {
         gdouble factor = (gdouble) i / (gdouble) (rbd.gradient_cache_size - 1);
 
-        gimp_gradient_get_color_at (rbd.gradient, NULL, NULL,
-                                    factor, rbd.reverse,
-                                    rbd.gradient_cache + i);
+        last_seg = gimp_gradient_get_color_at (rbd.gradient, NULL, last_seg,
+                                               factor, rbd.reverse,
+                                               rbd.gradient_cache + i);
       }
   }
 #endif


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