about summary refs log tree commit diff
path: root/src/writer/gifbuilder.rs
diff options
context:
space:
mode:
authorGenny <gen@nyble.dev>2021-03-10 01:26:24 -0600
committerGenny <gen@nyble.dev>2021-03-10 01:26:24 -0600
commit743888ae0c1038a92f4a0b64709a313eba70c887 (patch)
tree3b1f6e9fbe2524d3177a4ed12e3486a4fb009460 /src/writer/gifbuilder.rs
parenta368be4dfb3c1f75f6bcfdc297fe0372fb5f6092 (diff)
downloadgifed-743888ae0c1038a92f4a0b64709a313eba70c887.tar.gz
gifed-743888ae0c1038a92f4a0b64709a313eba70c887.zip
Refactor code and get ready for extension blocks
Diffstat (limited to 'src/writer/gifbuilder.rs')
-rw-r--r--src/writer/gifbuilder.rs19
1 files changed, 7 insertions, 12 deletions
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<ColorTable>,
 	background_color_index: u8,
-	imagebuilders: Vec<ImageBuilder>
+	global_color_table: Option<ColorTable>,
+	blocks: Vec<Block>
 }
 
 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