From cd79159420ecd3874c155ee54c0bcb54aaf52913 Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Sun, 15 Jan 2023 07:59:27 -0500 Subject: [PATCH] picture: Fix hi-dpi image handling The idea behind this code was to let scalable images (i.e. mainly SVGs) provide twice as much detail when the scale is 2. But we were also using a scaler for pngs, causing them to be too small on a hidpi screen. Fix that. Note that there are cases where you want scaling for pngs (when you display them scaled down, so the image has 'hidden' detail). But we are not attempting to handle that situation automatically. --- gtk/gdkpixbufutils.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/gtk/gdkpixbufutils.c b/gtk/gdkpixbufutils.c index df8c542deb..6b29128376 100644 --- a/gtk/gdkpixbufutils.c +++ b/gtk/gdkpixbufutils.c @@ -587,10 +587,12 @@ gdk_paintable_new_from_bytes_scaled (GBytes *bytes, if (gdk_texture_can_load (bytes)) { - /* We know these formats can't be scaled */ texture = gdk_texture_new_from_bytes (bytes, NULL); if (texture == NULL) return NULL; + + /* We know these formats can't be scaled */ + paintable = GDK_PAINTABLE (texture); } else { @@ -610,15 +612,15 @@ gdk_paintable_new_from_bytes_scaled (GBytes *bytes, texture = gdk_texture_new_for_pixbuf (gdk_pixbuf_loader_get_pixbuf (loader)); g_object_unref (loader); + + if (loader_data.scale_factor != 1) + paintable = gtk_scaler_new (GDK_PAINTABLE (texture), loader_data.scale_factor); + else + paintable = g_object_ref (GDK_PAINTABLE (texture)); + + g_object_unref (texture); } - if (loader_data.scale_factor != 1) - paintable = gtk_scaler_new (GDK_PAINTABLE (texture), loader_data.scale_factor); - else - paintable = g_object_ref ((GdkPaintable *)texture); - - g_object_unref (texture); - return paintable; }