decoder: Use image-rs, libheif-rs, librsvg
This adds proper support for a lot of image formats including SVGs.
It will be the basis for many features to come. The technical core
is an asynchronous renderer that can arrange textures in smaller tiles
which might be generated on demand.
Closes #34, #40, #41, #49
Basis for fixing the following issues #7, #27, #36, #43, #68, #71
2023-03-04 03:14:52 +01:00
|
|
|
mod heif;
|
|
|
|
|
mod image_rs_other;
|
|
|
|
|
mod svg;
|
|
|
|
|
|
|
|
|
|
pub use heif::Heif;
|
|
|
|
|
pub use image_rs_other::ImageRsOther;
|
2023-03-09 21:27:51 +01:00
|
|
|
pub use svg::{Svg, RSVG_MAX_SIZE};
|
decoder: Use image-rs, libheif-rs, librsvg
This adds proper support for a lot of image formats including SVGs.
It will be the basis for many features to come. The technical core
is an asynchronous renderer that can arrange textures in smaller tiles
which might be generated on demand.
Closes #34, #40, #41, #49
Basis for fixing the following issues #7, #27, #36, #43, #68, #71
2023-03-04 03:14:52 +01:00
|
|
|
|
2023-03-15 22:35:59 +01:00
|
|
|
use super::{Decoder, DecoderUpdate, UpdateSender};
|
|
|
|
|
use crate::i18n::*;
|
2023-03-09 22:10:08 +01:00
|
|
|
|
|
|
|
|
#[derive(Clone, Copy, Debug)]
|
|
|
|
|
pub enum ImageFormat {
|
|
|
|
|
ImageRs(image_rs::ImageFormat),
|
2023-03-15 22:35:59 +01:00
|
|
|
AnimatedGif,
|
|
|
|
|
AnimatedWebP,
|
|
|
|
|
AnimatedPng,
|
2023-03-09 22:10:08 +01:00
|
|
|
// TODO: Add details about contained format
|
|
|
|
|
Heif,
|
|
|
|
|
Svg,
|
|
|
|
|
}
|
|
|
|
|
|
2023-03-15 22:35:59 +01:00
|
|
|
impl ImageFormat {
|
|
|
|
|
pub fn is_animated(&self) -> bool {
|
|
|
|
|
matches!(
|
|
|
|
|
self,
|
|
|
|
|
ImageFormat::AnimatedGif | ImageFormat::AnimatedWebP | ImageFormat::AnimatedPng
|
|
|
|
|
)
|
|
|
|
|
}
|
2023-03-07 00:44:07 +01:00
|
|
|
|
|
|
|
|
pub fn is_svg(&self) -> bool {
|
|
|
|
|
matches!(self, Self::Svg)
|
|
|
|
|
}
|
2023-03-15 22:35:59 +01:00
|
|
|
}
|
|
|
|
|
|
2023-03-09 22:10:08 +01:00
|
|
|
impl std::fmt::Display for ImageFormat {
|
|
|
|
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> Result<(), std::fmt::Error> {
|
|
|
|
|
match self {
|
|
|
|
|
Self::ImageRs(format) => {
|
|
|
|
|
let debug = format!("{:?}", format);
|
|
|
|
|
if debug.len() <= 4 {
|
|
|
|
|
// uppercase abbreviations
|
|
|
|
|
write!(f, "{}", debug.to_uppercase())
|
|
|
|
|
} else {
|
|
|
|
|
write!(f, "{}", debug)
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-03-15 22:35:59 +01:00
|
|
|
Self::AnimatedGif => write!(f, "{}", i18n("Animated GIF")),
|
|
|
|
|
Self::AnimatedWebP => write!(f, "{}", i18n("Animated WebP")),
|
|
|
|
|
Self::AnimatedPng => write!(f, "{}", i18n("Animated PNG")),
|
2023-03-09 22:10:08 +01:00
|
|
|
Self::Heif => write!(f, "HEIF Container"),
|
|
|
|
|
Self::Svg => write!(f, "SVG"),
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-03-10 19:08:26 +01:00
|
|
|
|
|
|
|
|
#[derive(Clone, Debug, Default)]
|
|
|
|
|
pub enum ImageDimensionDetails {
|
|
|
|
|
Svg((rsvg::Length, rsvg::Length)),
|
|
|
|
|
#[default]
|
|
|
|
|
None,
|
|
|
|
|
}
|