// Copyright (c) 2023 Sophie Herold
// Copyright (c) 2023 Julian Hofer
//
// 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 .
//
// SPDX-License-Identifier: GPL-3.0-or-later
//! Decodes several image formats
pub mod formats;
pub mod tiling;
use std::sync::Arc;
use anyhow::Result;
use formats::*;
pub use formats::{ImageDimensionDetails, RSVG_MAX_SIZE};
use futures_channel::mpsc;
use self::tiling::SharedFrameBuffer;
use crate::deps::*;
use crate::metadata::{ImageFormat, Metadata};
#[derive(Clone, Copy, Debug)]
/// Renderer requests new tiles
///
/// This happens for initial loading or when zoom level or viewing area changes.
pub struct TileRequest {
pub viewport: graphene::Rect,
pub area: graphene::Rect,
pub zoom: f64,
}
#[derive(Debug, Clone)]
/// Signals update to the renderer
pub struct UpdateSender {
sender: mpsc::UnboundedSender,
}
#[derive(Debug)]
/// Signals for renderer (LpImage)
pub enum DecoderUpdate {
/// Dimensions of image in `TilingSore` available/updated
Dimensions(ImageDimensionDetails),
/// Metadata available
Metadata(Metadata),
/// Image format determined
Format(ImageFormat),
/// Image format not supported or unknown
UnsupportedFormat,
/// New image data available, redraw
Redraw,
/// Start animation
Animated,
/// And error occurred during decoding
Error(anyhow::Error),
}
impl UpdateSender {
pub fn send(&self, update: DecoderUpdate) {
let result = self.sender.unbounded_send(update);
if let Err(err) = result {
log::error!("Failed to send update: {err}");
}
}
/// Send occurring errors to renderer
pub fn spawn_error_handled(&self, f: F) -> glib::JoinHandle<()>
where
F: std::future::Future