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

5
Cargo.lock generated
View file

@ -1801,12 +1801,13 @@ dependencies = [
[[package]]
name = "libheif-rs"
version = "0.18.0"
version = "0.19.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "37d09b0d2d69da084eeeda9534662bc6b6096fbce3f307149750c0e572ad0ccd"
checksum = "7fcb2c12bbd85e40a36c704003f353f193f99476985fe89251423b6d0778f5c4"
dependencies = [
"enumn",
"four-cc",
"libc",
"libheif-sys",
]

View file

@ -29,7 +29,7 @@ url = "2.3.1"
# decoders
image-rs = { package = "image", version = "*", git = "https://github.com/image-rs/image.git" }
libheif-rs = "0.18.0"
libheif-rs = "0.19.0"
librsvg = { git = "https://gitlab.gnome.org/GNOME/librsvg.git" }
[dependencies.ashpd]

View file

@ -44,6 +44,19 @@
"*.la",
"*.a"
],
"add-extensions": {
/* Exile HEIC (x265) codec into extension */
"org.gnome.Loupe.Devel.HEIC" : {
/* Relative to app dir */
"directory" : "lib/libheif-heic",
/* Relative to directory above */
"add-ld-path" : "lib",
/* Remove extension data from main flatpak package */
"bundle" : true,
/* Remove this extension when Loupe is deinstalled */
"autodelete" : true
}
},
"modules" : [
{
"name": "geocode-glib",
@ -91,10 +104,42 @@
]
},
{
/* HEIC (x265) decoder */
"name" : "libde265",
"buildsystem" : "cmake",
"config-opts": [
/* Install into folder for extension */
"-DCMAKE_INSTALL_PREFIX=/app/lib/libheif-heic",
"-DENABLE_SDL=Off"
],
"sources" : [
{
"type" : "git",
"url" : "https://github.com/strukturag/libde265.git",
"tag" : "v1.0.11"
}
]
},
{
"name" : "libheif",
"buildsystem" : "cmake",
"config-opts": [
/* Build HEIC (x265) as plugin */
"-DWITH_LIBDE265_PLUGIN=On",
"-DPLUGIN_DIRECTORY=/app/lib/libheif-heic/lib",
"-DLIBDE265_INCLUDE_DIR=/app/lib/libheif-heic/include",
"-DLIBDE265_PKGCONF_LIBRARY_DIRS=/app/lib/libheif-heic/lib",
/* Turn all encoders off */
"-DWITH_X265=Off",
"-DWITH_SvtEnc=Off",
"-DWITH_SvtEnc_PLUGIN=Off",
"-DWITH_AOM_ENCODER=Off",
/* Turn off plugins for AV1 */
"-DWITH_RAV1E_PLUGIN=Off",
/* Turn off unused AV1 decoders */
"-DWITH_RAV1E=Off",
/* No need for examples */
"-DWITH_EXAMPLES=Off"
],
"sources" : [
{

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