image: Load Texture directly

`gdk::Texture::from_file ()` automatically falls back to
GdkPixbuf for file types Texture doesn't support natively.
This commit is contained in:
Christopher Davis 2023-01-22 13:52:50 -05:00 • committed by Sophie Herold
parent 469e721d2b
commit 6c59e21264

View file

@ -593,14 +593,14 @@ impl LpImage {
log::debug!("Loading complete image");
let texture = util::spawn(
"image-load-image",
glib::clone!(@strong path => move || {
let pixbuf = gdk_pixbuf::Pixbuf::from_file(&path)?;
glib::clone!(@weak file => @default-return Err(anyhow::Error::msg(i18n("File does not exist"))), move || {
log::debug!("Creating texture");
Ok::<_,anyhow::Error>(gdk::Texture::for_pixbuf(&pixbuf))
let texture = gdk::Texture::from_file(&file)?;
Ok::<_,anyhow::Error>(texture)
}),
)
.await?
.context(i18n("Failed to load image size"))?;
.context(i18n("Failed to load image"))?;
imp.texture.replace(Some(texture));