[gnome-photos/wip/rishi/thumbnailer: 1/15] utils: Short-circuit larger GdkPixbufs when centering



commit 86c47dfb8bac6764093159cc7ccfeecbb70fd286
Author: Debarshi Ray <debarshir gnome org>
Date:   Tue Feb 21 12:09:37 2017 +0100

    utils: Short-circuit larger GdkPixbufs when centering
    
    https://bugzilla.gnome.org/show_bug.cgi?id=740417
    https://bugzilla.gnome.org/show_bug.cgi?id=777869

 src/photos-utils.c |   15 ++++++++++++---
 1 files changed, 12 insertions(+), 3 deletions(-)
---
diff --git a/src/photos-utils.c b/src/photos-utils.c
index c268c1b..5f6e303 100644
--- a/src/photos-utils.c
+++ b/src/photos-utils.c
@@ -132,15 +132,24 @@ photos_utils_center_pixbuf (GdkPixbuf *pixbuf, gint size)
 {
   GdkPixbuf *ret_val;
   gint height;
+  gint pixbuf_size;
   gint width;
 
-  ret_val = gdk_pixbuf_new (GDK_COLORSPACE_RGB, TRUE, 8, size, size);
-  gdk_pixbuf_fill (ret_val, 0x00000000);
-
   height = gdk_pixbuf_get_height (pixbuf);
   width = gdk_pixbuf_get_width (pixbuf);
+
+  pixbuf_size = MAX (height, width);
+  if (pixbuf_size >= size)
+    {
+      ret_val = g_object_ref (pixbuf);
+      goto out;
+    }
+
+  ret_val = gdk_pixbuf_new (GDK_COLORSPACE_RGB, TRUE, 8, size, size);
+  gdk_pixbuf_fill (ret_val, 0x00000000);
   gdk_pixbuf_copy_area (pixbuf, 0, 0, width, height, ret_val, (size - width) / 2, (size - height) / 2);
 
+ out:
   return ret_val;
 }
 


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