From: Timm Bäder Date: Mon, 2 Sep 2019 05:58:20 +0000 (+0200) Subject: pixbufutils: Only get icon size once X-Git-Tag: archive/raspbian/4.4.1+ds1-2+rpi1^2~18^2~20^2~881 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=8eb62f138b573f9ce1af9a6913d45dcde18c2bb0;p=gtk4.git pixbufutils: Only get icon size once load_symbolic_svg was loading the pixbuf just to get its size via gdk_pixbuf_get_{width,height}. However, this function is called in a loop in gtk_make_symbolic_pixbuf_from_data. So, do this only once and pass the icon size along to load_symbolic_svg. --- diff --git a/gtk/tools/gdkpixbufutils.c b/gtk/tools/gdkpixbufutils.c index 0f4b7f09b5..c8a57b64b2 100644 --- a/gtk/tools/gdkpixbufutils.c +++ b/gtk/tools/gdkpixbufutils.c @@ -137,6 +137,8 @@ load_symbolic_svg (const char *file_data, int width, int height, double scale, + int icon_width, + int icon_height, const GdkRGBA *fg, const GdkRGBA *success_color, const GdkRGBA *warning_color, @@ -161,22 +163,13 @@ load_symbolic_svg (const char *file_data, css_error = gdk_rgba_to_string (error_color); css_success = gdk_rgba_to_string (success_color); - /* Fetch size from the original icon */ - stream = g_memory_input_stream_new_from_data (file_data, file_len, NULL); - pixbuf = gdk_pixbuf_new_from_stream (stream, NULL, error); - g_object_unref (stream); - - if (!pixbuf) - return NULL; - if (width == 0) - width = gdk_pixbuf_get_width (pixbuf) * scale; + width = icon_width * scale; if (height == 0) - height = gdk_pixbuf_get_height (pixbuf) * scale; + height = icon_height * scale; - svg_width = g_strdup_printf ("%d", gdk_pixbuf_get_width (pixbuf)); - svg_height = g_strdup_printf ("%d", gdk_pixbuf_get_height (pixbuf)); - g_object_unref (pixbuf); + svg_width = g_strdup_printf ("%d", icon_width); + svg_height = g_strdup_printf ("%d", icon_height); escaped_file_data = g_base64_encode ((guchar *) file_data, file_len); @@ -267,6 +260,22 @@ gtk_make_symbolic_pixbuf_from_data (const char *file_data, GdkPixbuf *loaded; GdkPixbuf *pixbuf = NULL; int plane; + int icon_width, icon_height; + + /* Fetch size from the original icon */ + { + GInputStream *stream = g_memory_input_stream_new_from_data (file_data, file_len, NULL); + GdkPixbuf *reference = gdk_pixbuf_new_from_stream (stream, NULL, error); + + g_object_unref (stream); + + if (!reference) + return NULL; + + icon_width = gdk_pixbuf_get_width (reference); + icon_height = gdk_pixbuf_get_height (reference); + g_object_unref (reference); + } for (plane = 0; plane < 3; plane++) { @@ -283,6 +292,8 @@ gtk_make_symbolic_pixbuf_from_data (const char *file_data, * the "rest", as all color fractions should add up to 1. */ loaded = load_symbolic_svg (file_data, file_len, width, height, scale, + icon_width, + icon_height, &g, plane == 0 ? &r : &g, plane == 1 ? &r : &g,