decoder: Load HEIC/x265 as plugin

Closes #85

Part-of: <https://gitlab.gnome.org/Incubator/loupe/-/merge_requests/123>
This commit is contained in:
Sophie Herold 2023-03-05 21:18:31 +01:00 • committed by Christopher Davis
parent 670c79bc1a
commit ddf4b8c2fa
4 changed files with 57 additions and 7 deletions

View file

@ -7,7 +7,8 @@ use gtk::prelude::*;
use anyhow::Context;
use arc_swap::ArcSwap;
use libheif_rs::{ColorSpace, HeifContext, Plane, RgbChroma};
use libheif_rs::{ColorSpace, HeifContext, LibHeif, Plane, RgbChroma};
use once_cell::sync::Lazy;
use std::path::PathBuf;
use std::sync::Arc;
@ -15,6 +16,9 @@ use std::sync::Arc;
#[derive(Debug)]
pub struct Heif;
/// Loads plugins on first use
static LIBHEIF: Lazy<LibHeif> = Lazy::new(LibHeif::new);
impl Heif {
pub fn new(
path: PathBuf,
@ -55,8 +59,8 @@ impl Heif {
RgbChroma::Rgb
};
let mut image = handle
.decode(ColorSpace::Rgb(rgb_chroma), None)
let mut image = LIBHEIF
.decode(&handle, ColorSpace::Rgb(rgb_chroma), None)
.context(i18n("Failed to decode image"))?;
let plane = image