diff options
-rw-r--r-- | gifed/src/reader/mod.rs | 28 |
1 files changed, 25 insertions, 3 deletions
diff --git a/gifed/src/reader/mod.rs b/gifed/src/reader/mod.rs index b4d892a..d81961c 100644 --- a/gifed/src/reader/mod.rs +++ b/gifed/src/reader/mod.rs @@ -8,9 +8,12 @@ use std::{ path::Path, }; -use crate::block::{ - extension::{Application, GraphicControl}, - Block, CompressedImage, ImageDescriptor, Palette, ScreenDescriptor, Version, +use crate::{ + block::{ + extension::{Application, GraphicControl}, + Block, CompressedImage, ImageDescriptor, Palette, ScreenDescriptor, Version, + }, + Gif, }; pub struct Decoder<R: Read> { @@ -54,6 +57,25 @@ impl<R: Read> Decoder<R> { }) } + pub fn read_all(self) -> Result<Gif, DecodeError> { + let mut decoder = self.read()?; + + let mut blocks = vec![]; + loop { + match decoder.block()? { + Some(block) => blocks.push(block.block), + None => break, + } + } + + Ok(Gif { + header: decoder.version, + screen_descriptor: decoder.screen_descriptor, + global_color_table: decoder.palette, + blocks, + }) + } + fn read_version(&mut self) -> Result<Version, DecodeError> { let mut buf = [0; 6]; self.reader.read_exact(&mut buf)?; |