[fractal/wip/christopherdavis/load-avatar-once] avatar: Only load pixbuf once
- From: Christopher Davis <christopherdavis src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [fractal/wip/christopherdavis/load-avatar-once] avatar: Only load pixbuf once
- Date: Tue, 6 Oct 2020 22:18:46 +0000 (UTC)
commit bd35d7bb9779adc844a39e625ea689aa53a6d432
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 | 18 +++++++-----------
1 file changed, 7 insertions(+), 11 deletions(-)
---
diff --git a/fractal-gtk/src/widgets/avatar.rs b/fractal-gtk/src/widgets/avatar.rs
index 449d2725..3eb85935 100644
--- a/fractal-gtk/src/widgets/avatar.rs
+++ b/fractal-gtk/src/widgets/avatar.rs
@@ -133,16 +133,12 @@ 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() {
- Pixbuf::from_file_at_scale(&path, -1, size, true).ok()
- } else {
- Pixbuf::from_file_at_scale(&path, size, -1, true).ok()
- }
+ let (_, width, height) = Pixbuf::get_file_info(&path)?;
+ let pb = if width > height {
+ Pixbuf::from_file_at_scale(&path, -1, size, true).ok()?
} else {
- None
- }
+ Pixbuf::from_file_at_scale(&path, size, -1, true).ok()?
+ };
+
+ Some(pb)
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]