use crate::{DecodeError, DecodeOptions, ImageInfo};
use std::sync::Arc;
use std::time::Duration;
use valo::PixelBuffer;
pub trait Decoder: Send + Sync {
fn name(&self) -> &'static str;
fn open(&self, request: &OpenRequest) -> Result<Box<dyn FrameReader>, OpenError>;
}
#[derive(Clone)]
pub struct OpenRequest {
pub encoded: Arc<[u8]>,
pub options: DecodeOptions,
pub device: wgpu::Device,
}
#[derive(Clone, Debug, PartialEq, Eq)]
pub enum OpenError {
Unsupported(String),
Failed(DecodeError),
}
impl From<DecodeError> for OpenError {
fn from(error: DecodeError) -> Self {
Self::Failed(error)
}
}
pub trait FrameReader {
fn info(&self) -> ImageInfo;
fn next_frame(&mut self) -> Result<DecodedFrame, DecodeError>;
}
pub struct DecodedFrame {
pub pixels: FramePixels,
pub duration: Duration,
}
pub enum FramePixels {
Cpu(PixelBuffer),
Gpu(wgpu::Texture),
}
impl DecodedFrame {
pub fn still(pixels: FramePixels) -> Self {
Self {
pixels,
duration: Duration::ZERO,
}
}
}