[gnome-software: 9/12] gs-key-colors: Use nearest rather than bilinear scaling for pixbufs




commit a684301386b0e1db86c0ec9b3097bbd028934906
Author: Philip Withnall <pwithnall endlessos org>
Date:   Wed Feb 24 11:14:57 2021 +0000

    gs-key-colors: Use nearest rather than bilinear scaling for pixbufs
    
    While this would produce a visually terrible result, it does OK at
    preserving enough of the colour data that it works for key colour
    extraction, and is significantly faster than bilinear scaling.
    
    Before this change, profiling times with `profile-key-colors` were:
      [204, 751]μs, mean 301±56μs, n = 1038
    now they are:
      [36, 573]μs, mean 129±59μs, n = 1038
    
    Suggested by Richard Hughes.
    
    Signed-off-by: Philip Withnall <pwithnall endlessos org>
    
    Helps: #1148

 lib/gs-key-colors.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
---
diff --git a/lib/gs-key-colors.c b/lib/gs-key-colors.c
index 0cba80c3e..30630e864 100644
--- a/lib/gs-key-colors.c
+++ b/lib/gs-key-colors.c
@@ -287,7 +287,11 @@ gs_calculate_key_colors (GdkPixbuf *pixbuf)
        g_autoptr(GdkPixbuf) pb_small = NULL;
        g_autoptr(GArray) colors = g_array_new (FALSE, FALSE, sizeof (GdkRGBA));
 
-       pb_small = gdk_pixbuf_scale_simple (pixbuf, 32, 32, GDK_INTERP_BILINEAR);
+       /* people almost always use BILINEAR scaling with pixbufs, but we can
+        * use NEAREST here since we only care about the rough colour data, not
+        * whether the edges in the image are smooth and visually appealing;
+        * NEAREST is twice as fast as BILINEAR */
+       pb_small = gdk_pixbuf_scale_simple (pixbuf, 32, 32, GDK_INTERP_NEAREST);
 
        /* require an alpha channel for storing temporary values; most images
         * have one already, about 2% don’t */


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