2023-04-19 20:02:01 +02:00
|
|
|
// Copyright (c) 2023 Sophie Herold
|
|
|
|
|
//
|
|
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
// (at your option) any later version.
|
|
|
|
|
//
|
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
|
//
|
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
//
|
|
|
|
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
|
|
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-04-10 17:53:15 +02:00
|
|
|
use super::{DecoderUpdate, UpdateSender};
|
2023-04-11 00:02:28 +02:00
|
|
|
use crate::util::gettext::*;
|
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-04-03 17:39:02 +02:00
|
|
|
|
|
|
|
|
pub fn is_potentially_transparent(&self) -> bool {
|
|
|
|
|
!matches!(
|
|
|
|
|
self,
|
|
|
|
|
Self::ImageRs(image_rs::ImageFormat::Bmp) | Self::ImageRs(image_rs::ImageFormat::Jpeg)
|
|
|
|
|
)
|
|
|
|
|
}
|
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-04-11 00:02:28 +02:00
|
|
|
Self::AnimatedGif => write!(f, "{}", gettext("Animated GIF")),
|
|
|
|
|
Self::AnimatedWebP => write!(f, "{}", gettext("Animated WebP")),
|
|
|
|
|
Self::AnimatedPng => write!(f, "{}", gettext("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,
|
|
|
|
|
}
|