[gnome-software] screenshot image: Fix HiDPI scale factor calculation



commit 51ac279207e1fd93bc38b5ad4fc105585289c280
Author: Kalev Lember <kalevlember gmail com>
Date:   Thu Mar 12 21:01:38 2015 +0100

    screenshot image: Fix HiDPI scale factor calculation
    
    While at this, also avoid hardcoding scale factor of 2 and use the value
    from gtk_widget_get_scale_factor() instead.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=742335

 src/gs-screenshot-image.c |   23 ++++++++++-------------
 1 files changed, 10 insertions(+), 13 deletions(-)
---
diff --git a/src/gs-screenshot-image.c b/src/gs-screenshot-image.c
index e2018f9..ebf1951 100644
--- a/src/gs-screenshot-image.c
+++ b/src/gs-screenshot-image.c
@@ -143,8 +143,8 @@ as_screenshot_show_image (GsScreenshotImage *ssimg)
        } else {
                /* this is always going to have alpha */
                pixbuf = gdk_pixbuf_new_from_file_at_scale (priv->filename,
-                                                           priv->width,
-                                                           priv->height,
+                                                           priv->width * priv->scale,
+                                                           priv->height * priv->scale,
                                                            FALSE, NULL);
                if (pixbuf != NULL) {
                        if (gs_screenshot_image_use_desktop_background (pixbuf)) {
@@ -368,18 +368,15 @@ gs_screenshot_image_load_async (GsScreenshotImage *ssimg,
        g_return_if_fail (priv->width != 0);
        g_return_if_fail (priv->height != 0);
 
-       /* load the HiDPI image if it exists */
-       priv->scale = 1;
-       if (gtk_widget_get_scale_factor (GTK_WIDGET (ssimg)) > 1) {
-               im = as_screenshot_get_image (priv->screenshot,
-                                             priv->width * 2,
-                                             priv->height * 2);
-               if (im != NULL)
-                       priv->scale = as_image_get_width (im) / priv->width;
-       }
+       /* load an image according to the scale factor */
+       priv->scale = gtk_widget_get_scale_factor (GTK_WIDGET (ssimg));
+       im = as_screenshot_get_image (priv->screenshot,
+                                     priv->width * priv->scale,
+                                     priv->height * priv->scale);
 
-       /* fallback to LoDPI if it exists */
-       if (im == NULL) {
+       /* if we've failed to load a HiDPI image, fallback to LoDPI */
+       if (im == NULL && priv->scale > 1) {
+               priv->scale = 1;
                im = as_screenshot_get_image (priv->screenshot,
                                              priv->width,
                                              priv->height);


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