diff options
author | Timm Bäder <mail@baedert.org> | 2019-09-02 07:58:20 +0200 |
---|---|---|
committer | Timm Bäder <mail@baedert.org> | 2019-09-09 17:36:27 +0200 |
commit | 8eb62f138b573f9ce1af9a6913d45dcde18c2bb0 (patch) | |
tree | 7463191440f4e4f57ee05c4564bd3441025ce736 /gtk/tools | |
parent | 6a8921ec6ba68aae270f407dcaa4bfa80d6c2bb2 (diff) | |
download | gtk+-8eb62f138b573f9ce1af9a6913d45dcde18c2bb0.tar.gz |
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.
Diffstat (limited to 'gtk/tools')
-rw-r--r-- | gtk/tools/gdkpixbufutils.c | 37 |
1 files changed, 24 insertions, 13 deletions
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, |