[nautilus] nautilus-file.c: Add transparent padding to thumbnails



commit 26d33d74f468a8ab10b4a1c3c8aa66b66205e112
Author: Chris Billington <chrisjbillington gmail com>
Date:   Sat Aug 3 20:56:21 2019 +0000

    nautilus-file.c: Add transparent padding to thumbnails
    
    Pad thumbnails with transparency such that the resulting image is
    square. This ensures that the pixmap has room for emblems even when the
    image has an extreme aspect ratio.
    
    Closes #912

 src/nautilus-file.c | 24 +++++++++++++++++++++++-
 1 file changed, 23 insertions(+), 1 deletion(-)
---
diff --git a/src/nautilus-file.c b/src/nautilus-file.c
index 0a76d64e3..8d1fbb54c 100644
--- a/src/nautilus-file.c
+++ b/src/nautilus-file.c
@@ -5173,6 +5173,9 @@ nautilus_file_get_thumbnail_icon (NautilusFile          *file,
         }
         else
         {
+            GdkPixbuf *bg_pixbuf;
+            int bg_size;
+
             pixbuf = gdk_pixbuf_scale_simple (file->details->thumbnail,
                                               MAX (w * thumb_scale, 1),
                                               MAX (h * thumb_scale, 1),
@@ -5198,13 +5201,32 @@ nautilus_file_get_thumbnail_icon (NautilusFile          *file,
                 }
             }
 
+            /* Copy to a transparent square pixbuf, aligned to the bottom edge */
+            bg_size = MAX (gdk_pixbuf_get_width (pixbuf), gdk_pixbuf_get_height (pixbuf));
+            bg_pixbuf = gdk_pixbuf_new (gdk_pixbuf_get_colorspace (pixbuf),
+                                        TRUE,
+                                        gdk_pixbuf_get_bits_per_sample (pixbuf),
+                                        bg_size,
+                                        bg_size);
+            gdk_pixbuf_fill (bg_pixbuf, 0);
+            gdk_pixbuf_copy_area (pixbuf,
+                                  0,
+                                  0,
+                                  gdk_pixbuf_get_width (pixbuf),
+                                  gdk_pixbuf_get_height (pixbuf),
+                                  bg_pixbuf,
+                                  (bg_size - gdk_pixbuf_get_width (pixbuf)) / 2,
+                                  (bg_size - gdk_pixbuf_get_height (pixbuf)));
+            g_clear_object (&pixbuf);
+            pixbuf = bg_pixbuf;
+
             g_clear_object (&file->details->scaled_thumbnail);
             file->details->scaled_thumbnail = pixbuf;
             file->details->thumbnail_scale = thumb_scale;
         }
 
         DEBUG ("Returning thumbnailed image, at size %d %d",
-               (int) (w * thumb_scale), (int) (h * thumb_scale));
+               gdk_pixbuf_get_width (pixbuf), gdk_pixbuf_get_height (pixbuf));
     }
     else if (file->details->thumbnail_path == NULL &&
              file->details->can_read &&


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