pub use imgref::ImgVec;
pub use rgb::{RGB8, RGBA8};
use crate::error::GifResult;
use crossbeam_channel::Sender;
#[cfg(feature = "png")]
use std::path::PathBuf;
pub(crate) enum FrameSource {
Pixels(ImgVec<RGBA8>),
#[cfg(feature = "png")]
PngData(Vec<u8>),
#[cfg(all(feature = "png", not(target_arch = "wasm32")))]
Path(PathBuf),
}
pub(crate) struct InputFrame {
pub frame: FrameSource,
pub presentation_timestamp: f64,
pub frame_index: usize,
}
pub(crate) struct InputFrameResized {
pub frame: ImgVec<RGBA8>,
pub frame_blurred: ImgVec<RGB8>,
pub presentation_timestamp: f64,
pub original_index: usize,
}
pub struct Collector {
pub(crate) queue: Sender<InputFrame>,
}
impl Collector {
#[cfg_attr(debug_assertions, track_caller)]
pub fn add_frame_rgba(&self, frame_index: usize, frame: ImgVec<RGBA8>, presentation_timestamp: f64) -> GifResult<()> {
debug_assert!(frame_index == 0 || presentation_timestamp > 0.);
self.queue.send(InputFrame {
frame_index,
frame: FrameSource::Pixels(frame),
presentation_timestamp,
})?;
Ok(())
}
#[cfg(feature = "png")]
#[inline]
pub fn add_frame_png_data(&self, frame_index: usize, png_data: Vec<u8>, presentation_timestamp: f64) -> GifResult<()> {
self.queue.send(InputFrame {
frame: FrameSource::PngData(png_data),
presentation_timestamp,
frame_index,
})?;
Ok(())
}
#[cfg(feature = "png")]
pub fn add_frame_png_file(&self, frame_index: usize, path: PathBuf, presentation_timestamp: f64) -> GifResult<()> {
self.queue.send(InputFrame {
frame: FrameSource::Path(path),
presentation_timestamp,
frame_index,
})?;
Ok(())
}
}