[fractal/wip/christopherdavis/load-avatar-once] avatar: Only load pixbuf once




commit 228be66f1d977c3fb5961abc2dd6856fbee47eca
Author: Christopher Davis <brainblasted disroot org>
Date:   Tue Oct 6 15:12:34 2020 -0700

    avatar: Only load pixbuf once
    
    We don't need to load the pixbuf twice since get_file_info()
    exists.

 fractal-gtk/src/widgets/avatar.rs | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)
---
diff --git a/fractal-gtk/src/widgets/avatar.rs b/fractal-gtk/src/widgets/avatar.rs
index 449d2725..8c21ca7c 100644
--- a/fractal-gtk/src/widgets/avatar.rs
+++ b/fractal-gtk/src/widgets/avatar.rs
@@ -133,11 +133,8 @@ impl AvatarExt for gtk::Overlay {
 }
 
 fn load_pixbuf(path: &Path, size: i32) -> Option<Pixbuf> {
-    if let Ok(pixbuf) = Pixbuf::from_file(&path) {
-        // FIXME: We end up loading the file twice but we need to load the file first to find out its 
dimensions to be
-        // able to decide wether to scale by width or height and gdk doesn't provide simple API to scale a 
loaded
-        // pixbuf while preserving aspect ratio.
-        if pixbuf.get_width() > pixbuf.get_height() {
+    if let Some((_, width, height)) = Pixbuf::get_file_info(&path) {
+        if width > height {
             Pixbuf::from_file_at_scale(&path, -1, size, true).ok()
         } else {
             Pixbuf::from_file_at_scale(&path, size, -1, true).ok()


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