From 743888ae0c1038a92f4a0b64709a313eba70c887 Mon Sep 17 00:00:00 2001 From: Genny Date: Wed, 10 Mar 2021 01:26:24 -0600 Subject: Refactor code and get ready for extension blocks --- src/writer/gifbuilder.rs | 19 +++++++------------ src/writer/imagebuilder.rs | 6 +++--- 2 files changed, 10 insertions(+), 15 deletions(-) (limited to 'src/writer') diff --git a/src/writer/gifbuilder.rs b/src/writer/gifbuilder.rs index 415ebf6..2cdc52c 100644 --- a/src/writer/gifbuilder.rs +++ b/src/writer/gifbuilder.rs @@ -1,4 +1,4 @@ -use crate::block::{ColorTable, ScreenDescriptor, Version}; +use crate::block::{Block, ColorTable, ScreenDescriptor, Version}; use crate::writer::ImageBuilder; use crate::Gif; @@ -6,9 +6,9 @@ pub struct GifBuilder { version: Version, width: u16, height: u16, - global_color_table: Option, background_color_index: u8, - imagebuilders: Vec + global_color_table: Option, + blocks: Vec } impl GifBuilder { @@ -17,9 +17,9 @@ impl GifBuilder { version, width, height, - global_color_table: None, background_color_index: 0, - imagebuilders: vec![] + global_color_table: None, + blocks: vec![] } } @@ -40,7 +40,7 @@ impl GifBuilder { } pub fn image(mut self, ib: ImageBuilder) -> Self { - self.imagebuilders.push(ib); + self.blocks.push(Block::IndexedImage(ib.build())); self } @@ -58,16 +58,11 @@ impl GifBuilder { lsd.color_table_size(gct.len() as u8); } - let mut images = vec![]; - for builder in self.imagebuilders.into_iter() { - images.push(builder.build()); - } - Gif { header: self.version, screen_descriptor: lsd, global_color_table: self.global_color_table, - images + blocks: self.blocks } } } \ No newline at end of file diff --git a/src/writer/imagebuilder.rs b/src/writer/imagebuilder.rs index d8b9900..f2156ac 100644 --- a/src/writer/imagebuilder.rs +++ b/src/writer/imagebuilder.rs @@ -1,4 +1,4 @@ -use crate::block::{ColorTable, Image, ImageDescriptor}; +use crate::block::{ColorTable, IndexedImage, ImageDescriptor}; pub struct ImageBuilder { left_offset: u16, @@ -48,7 +48,7 @@ impl ImageBuilder { self } - pub fn build(self) -> Image { + pub fn build(self) -> IndexedImage { let mut imgdesc = ImageDescriptor { left: self.left_offset, top: self.top_offset, @@ -62,7 +62,7 @@ impl ImageBuilder { imgdesc.color_table_size(lct.packed_len()); } - Image { + IndexedImage { image_descriptor: imgdesc, local_color_table: self.color_table, indicies: self.indicies -- cgit 1.4.1-3-g733a5