diff options
-rw-r--r-- | gifed/src/videogif.rs | 22 |
1 files changed, 20 insertions, 2 deletions
diff --git a/gifed/src/videogif.rs b/gifed/src/videogif.rs index a5475cc..d066019 100644 --- a/gifed/src/videogif.rs +++ b/gifed/src/videogif.rs @@ -1,15 +1,23 @@ -use crate::{block::Palette, writer::ImageBuilder, Color, EncodeError, Gif}; +use crate::{ + block::{LoopCount, Palette}, + writer::ImageBuilder, + Color, EncodeError, Gif, +}; use color_quant::NeuQuant; use rgb::{ComponentBytes, FromSlice}; use std::convert::TryFrom; +/// A Video-like GIF. +/// +/// All images must have the same dimensions. pub struct VideoGif { width: u16, height: u16, framerate: Option<u16>, frames: Vec<Frame>, + looping: LoopCount, } impl VideoGif { @@ -19,6 +27,7 @@ impl VideoGif { height, framerate: None, frames: vec![], + looping: LoopCount::Forever, } } @@ -30,6 +39,13 @@ impl VideoGif { self.framerate = Some(100 / framerate); } + /// Set the number of times this gif should loop. Defaults to forever. + /// + /// See [LoopCount] + pub fn set_looping(&mut self, count: LoopCount) { + self.looping = count; + } + /// Adds a frame to the gif. /// /// # Panic @@ -53,10 +69,12 @@ impl VideoGif { #[rustfmt::skip] // it was doing things i did not like pub fn build(self) -> Result<Gif, EncodeError> { - let Self { width, height, framerate, frames } = self; + let Self { width, height, framerate, frames, looping } = self; let mut gif = Gif::new(width, height); + gif.push(looping); + for Frame { image_indices, interval, palette } in frames { //TODO: return error instead of defaulting to 10? or print warning? // printing in a library is bad but perhaps so is assuming 10 fps? |