diff options
-rw-r--r-- | src/block/block.rs | 8 | ||||
-rw-r--r-- | src/block/indexedimage.rs (renamed from src/block/image.rs) | 6 | ||||
-rw-r--r-- | src/block/mod.rs | 4 | ||||
-rw-r--r-- | src/gif.rs | 15 | ||||
-rw-r--r-- | src/writer/gifbuilder.rs | 19 | ||||
-rw-r--r-- | src/writer/imagebuilder.rs | 6 |
6 files changed, 25 insertions, 33 deletions
diff --git a/src/block/block.rs b/src/block/block.rs index 95ff12e..329361f 100644 --- a/src/block/block.rs +++ b/src/block/block.rs @@ -1,9 +1,5 @@ -use crate::block::Version; - -use super::ScreenDescriptor; - +use super::IndexedImage; pub enum Block { - Version(Version), - LogicalScreenDescriptor(ScreenDescriptor) + IndexedImage(IndexedImage) } \ No newline at end of file diff --git a/src/block/image.rs b/src/block/indexedimage.rs index 07f9555..ae2da06 100644 --- a/src/block/image.rs +++ b/src/block/indexedimage.rs @@ -1,21 +1,19 @@ use crate::LZW; use super::{ColorTable, ImageDescriptor}; -pub struct Image { +pub struct IndexedImage { pub image_descriptor: ImageDescriptor, pub local_color_table: Option<ColorTable>, pub indicies: Vec<u8> } -impl Image { +impl IndexedImage { pub fn as_boxed_slice(&self, minimum_code_size: u8) -> Box<[u8]> { let mut out = vec![]; let mut boxed: Box<[u8]> = (&self.image_descriptor).into(); out.extend_from_slice(&*boxed); - // Table based image data // - // Get the mcs while we write out the color table let mut mcs = if let Some(lct) = &self.local_color_table { boxed = lct.into(); diff --git a/src/block/mod.rs b/src/block/mod.rs index 049b39a..a0c2454 100644 --- a/src/block/mod.rs +++ b/src/block/mod.rs @@ -1,13 +1,13 @@ mod block; mod colortable; -mod image; +mod indexedimage; mod imagedescriptor; mod screendescriptor; mod version; pub use block::Block; pub use colortable::ColorTable; -pub use image::Image; +pub use indexedimage::IndexedImage; pub use imagedescriptor::ImageDescriptor; pub use screendescriptor::ScreenDescriptor; pub use version::Version; \ No newline at end of file diff --git a/src/gif.rs b/src/gif.rs index c3ef56b..f6ff345 100644 --- a/src/gif.rs +++ b/src/gif.rs @@ -1,10 +1,9 @@ -use crate::block::{ColorTable, Image, ScreenDescriptor, Version}; - +use crate::block::{Block, ColorTable, ScreenDescriptor, Version}; pub struct Gif { pub header: Version, pub screen_descriptor: ScreenDescriptor, pub global_color_table: Option<ColorTable>, - pub images: Vec<Image> + pub blocks: Vec<Block> // Trailer at the end of this struct is 0x3B // } @@ -28,9 +27,13 @@ impl Gif { 0 }; - for image in self.images.iter() { - boxed = image.as_boxed_slice(mcs); - out.extend_from_slice(&*boxed); + for block in self.blocks.iter() { + match block { + Block::IndexedImage(image) => { + boxed = image.as_boxed_slice(mcs); + out.extend_from_slice(&*boxed); + } + } } // Write Trailer 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 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 |