picture: Fix hi-dpi image handling
authorMatthias Clasen <mclasen@redhat.com>
Sun, 15 Jan 2023 12:59:27 +0000 (07:59 -0500)
committerMatthias Clasen <mclasen@redhat.com>
Mon, 16 Jan 2023 13:48:37 +0000 (08:48 -0500)
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

index df8c542deb9d58606fe18bac01f20cd14d9e11bd..6b29128376d7ea75a26fb422e58d41644c9e64f5 100644 (file)
@@ -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,14 +612,14 @@ 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 ((GdkPaintable *)texture);
+      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);
+      g_object_unref (texture);
+    }
 
   return paintable;
 }