about summary refs log tree commit diff
path: root/src/writer
diff options
context:
space:
mode:
authorGenny <gen@nyble.dev>2021-10-11 03:36:38 -0500
committerGenny <gen@nyble.dev>2021-10-11 03:36:38 -0500
commit757eab88d67a425728b87286c763387f52367196 (patch)
treef1d61edb0a838787f6984accdd92df68a69d567a /src/writer
parent9b7bd5696a21496fa0c38a17e69c5c0658acfe73 (diff)
downloadgifed-757eab88d67a425728b87286c763387f52367196.tar.gz
gifed-757eab88d67a425728b87286c763387f52367196.zip
Run rustfmt
Diffstat (limited to 'src/writer')
-rw-r--r--src/writer/gifbuilder.rs190
-rw-r--r--src/writer/imagebuilder.rs246
2 files changed, 218 insertions, 218 deletions
diff --git a/src/writer/gifbuilder.rs b/src/writer/gifbuilder.rs
index 1466f76..57a62e3 100644
--- a/src/writer/gifbuilder.rs
+++ b/src/writer/gifbuilder.rs
@@ -5,102 +5,102 @@ use crate::writer::ImageBuilder;
 use crate::{EncodingError, Gif};
 
 pub struct GifBuilder {
-    version: Version,
-    width: u16,
-    height: u16,
-    background_color_index: u8,
-    global_color_table: Option<ColorTable>,
-    blocks: Vec<Block>,
-    error: Option<EncodingError>,
+	version: Version,
+	width: u16,
+	height: u16,
+	background_color_index: u8,
+	global_color_table: Option<ColorTable>,
+	blocks: Vec<Block>,
+	error: Option<EncodingError>,
 }
 
 impl GifBuilder {
-    pub fn new(width: u16, height: u16) -> Self {
-        Self {
-            version: Version::Gif87a,
-            width,
-            height,
-            background_color_index: 0,
-            global_color_table: None,
-            blocks: vec![],
-            error: None,
-        }
-    }
-
-    pub fn palette(mut self, palette: ColorTable) -> Self {
-        self.global_color_table = Some(palette);
-        self
-    }
-
-    pub fn background_index(mut self, ind: u8) -> Self {
-        if self.error.is_some() {
-            return self;
-        }
-
-        if self.global_color_table.is_none() {
-            self.error = Some(EncodingError::NoColorTable);
-        } else {
-            self.background_color_index = ind;
-        }
-        self
-    }
-
-    pub fn image(mut self, ib: ImageBuilder) -> Self {
-        if self.error.is_some() {
-            return self;
-        }
-
-        if ib.required_version() == Version::Gif89a {
-            self.version = Version::Gif89a;
-        }
-
-        if let Some(gce) = ib.get_graphic_control() {
-            self.blocks.push(Block::Extension(gce.into()));
-        }
-
-        match ib.build() {
-            Ok(image) => self.blocks.push(Block::IndexedImage(image)),
-            Err(e) => self.error = Some(e),
-        }
-
-        self
-    }
-
-    /*pub fn extension(mut self, ext: Extension) -> Self {
-        self.blocks.push(Block::Extension(ext));
-        self
-    }*/
-
-    pub fn repeat(mut self, count: u16) -> Self {
-        self.blocks
-            .push(Block::Extension(Extension::Looping(count)));
-        self
-    }
-
-    pub fn build(self) -> Result<Gif, EncodingError> {
-        if let Some(error) = self.error {
-            return Err(error);
-        }
-
-        let mut lsd = ScreenDescriptor {
-            width: self.width,
-            height: self.height,
-            packed: 0, // Set later
-            background_color_index: self.background_color_index,
-            pixel_aspect_ratio: 0, //TODO: Allow configuring
-        };
-
-        if let Some(gct) = &self.global_color_table {
-            println!("build {}", gct.len());
-            lsd.set_color_table_present(true);
-            lsd.set_color_table_size((gct.len() - 1) as u8);
-        }
-
-        Ok(Gif {
-            header: self.version,
-            screen_descriptor: lsd,
-            global_color_table: self.global_color_table,
-            blocks: self.blocks,
-        })
-    }
+	pub fn new(width: u16, height: u16) -> Self {
+		Self {
+			version: Version::Gif87a,
+			width,
+			height,
+			background_color_index: 0,
+			global_color_table: None,
+			blocks: vec![],
+			error: None,
+		}
+	}
+
+	pub fn palette(mut self, palette: ColorTable) -> Self {
+		self.global_color_table = Some(palette);
+		self
+	}
+
+	pub fn background_index(mut self, ind: u8) -> Self {
+		if self.error.is_some() {
+			return self;
+		}
+
+		if self.global_color_table.is_none() {
+			self.error = Some(EncodingError::NoColorTable);
+		} else {
+			self.background_color_index = ind;
+		}
+		self
+	}
+
+	pub fn image(mut self, ib: ImageBuilder) -> Self {
+		if self.error.is_some() {
+			return self;
+		}
+
+		if ib.required_version() == Version::Gif89a {
+			self.version = Version::Gif89a;
+		}
+
+		if let Some(gce) = ib.get_graphic_control() {
+			self.blocks.push(Block::Extension(gce.into()));
+		}
+
+		match ib.build() {
+			Ok(image) => self.blocks.push(Block::IndexedImage(image)),
+			Err(e) => self.error = Some(e),
+		}
+
+		self
+	}
+
+	/*pub fn extension(mut self, ext: Extension) -> Self {
+		self.blocks.push(Block::Extension(ext));
+		self
+	}*/
+
+	pub fn repeat(mut self, count: u16) -> Self {
+		self.blocks
+			.push(Block::Extension(Extension::Looping(count)));
+		self
+	}
+
+	pub fn build(self) -> Result<Gif, EncodingError> {
+		if let Some(error) = self.error {
+			return Err(error);
+		}
+
+		let mut lsd = ScreenDescriptor {
+			width: self.width,
+			height: self.height,
+			packed: 0, // Set later
+			background_color_index: self.background_color_index,
+			pixel_aspect_ratio: 0, //TODO: Allow configuring
+		};
+
+		if let Some(gct) = &self.global_color_table {
+			println!("build {}", gct.len());
+			lsd.set_color_table_present(true);
+			lsd.set_color_table_size((gct.len() - 1) as u8);
+		}
+
+		Ok(Gif {
+			header: self.version,
+			screen_descriptor: lsd,
+			global_color_table: self.global_color_table,
+			blocks: self.blocks,
+		})
+	}
 }
diff --git a/src/writer/imagebuilder.rs b/src/writer/imagebuilder.rs
index 42c94f8..f5c9e2b 100644
--- a/src/writer/imagebuilder.rs
+++ b/src/writer/imagebuilder.rs
@@ -1,133 +1,133 @@
 use crate::{
-    block::{
-        extension::{DisposalMethod, GraphicControl},
-        ColorTable, ImageDescriptor, IndexedImage, Version,
-    },
-    EncodingError,
+	block::{
+		extension::{DisposalMethod, GraphicControl},
+		ColorTable, ImageDescriptor, IndexedImage, Version,
+	},
+	EncodingError,
 };
 
 pub struct ImageBuilder {
-    left_offset: u16,
-    top_offset: u16,
-    width: u16,
-    height: u16,
-    color_table: Option<ColorTable>,
+	left_offset: u16,
+	top_offset: u16,
+	width: u16,
+	height: u16,
+	color_table: Option<ColorTable>,
 
-    delay: u16,
-    disposal_method: DisposalMethod,
-    transparent_index: Option<u8>,
+	delay: u16,
+	disposal_method: DisposalMethod,
+	transparent_index: Option<u8>,
 
-    indicies: Vec<u8>,
+	indicies: Vec<u8>,
 }
 
 impl ImageBuilder {
-    pub fn new(width: u16, height: u16) -> Self {
-        Self {
-            left_offset: 0,
-            top_offset: 0,
-            width,
-            height,
-            color_table: None,
-            delay: 0,
-            disposal_method: DisposalMethod::NoAction,
-            transparent_index: None,
-            indicies: vec![],
-        }
-    }
-
-    pub fn offset(mut self, left: u16, top: u16) -> Self {
-        self.left_offset = left;
-        self.top_offset = top;
-        self
-    }
-
-    pub fn palette(mut self, table: ColorTable) -> Self {
-        self.color_table = Some(table);
-        self
-    }
-
-    /// Time to wait, in hundreths of a second, before this image is drawn
-    pub fn delay(mut self, hundreths: u16) -> Self {
-        self.delay = hundreths;
-        self
-    }
-
-    pub fn disposal_method(mut self, method: DisposalMethod) -> Self {
-        self.disposal_method = method;
-        self
-    }
-
-    pub fn transparent_index(mut self, index: Option<u8>) -> Self {
-        self.transparent_index = index;
-        self
-    }
-
-    pub fn required_version(&self) -> Version {
-        if self.delay > 0
-            || self.disposal_method != DisposalMethod::NoAction
-            || self.transparent_index.is_some()
-        {
-            Version::Gif89a
-        } else {
-            Version::Gif87a
-        }
-    }
-
-    pub fn get_graphic_control(&self) -> Option<GraphicControl> {
-        if self.required_version() == Version::Gif89a {
-            if let Some(transindex) = self.transparent_index {
-                Some(GraphicControl::new(
-                    self.disposal_method,
-                    false,
-                    true,
-                    self.delay,
-                    transindex,
-                ))
-            } else {
-                Some(GraphicControl::new(
-                    self.disposal_method,
-                    false,
-                    false,
-                    self.delay,
-                    0,
-                ))
-            }
-        } else {
-            None
-        }
-    }
-
-    pub fn indicies(mut self, indicies: &[u8]) -> Self {
-        self.indicies = indicies.to_vec();
-        self
-    }
-
-    pub fn build(self) -> Result<IndexedImage, EncodingError> {
-        let expected_len = self.width as usize * self.height as usize;
-        if self.indicies.len() != expected_len {
-            return Err(EncodingError::IndicieSizeMismatch {
-                expected: expected_len,
-                got: self.indicies.len(),
-            });
-        }
-
-        let mut imgdesc = ImageDescriptor {
-            left: self.left_offset,
-            top: self.top_offset,
-            width: self.width,
-            height: self.height,
-            packed: 0, // Set later
-        };
-
-        if let Some(lct) = &self.color_table {
-            imgdesc.set_color_table_present(true);
-            imgdesc.set_color_table_size(lct.packed_len());
-        }
-
-        Ok(IndexedImage {
-            image_descriptor: imgdesc,
-            local_color_table: self.color_table,
-            indicies: self.indicies,
-        })
-    }
+	pub fn new(width: u16, height: u16) -> Self {
+		Self {
+			left_offset: 0,
+			top_offset: 0,
+			width,
+			height,
+			color_table: None,
+			delay: 0,
+			disposal_method: DisposalMethod::NoAction,
+			transparent_index: None,
+			indicies: vec![],
+		}
+	}
+
+	pub fn offset(mut self, left: u16, top: u16) -> Self {
+		self.left_offset = left;
+		self.top_offset = top;
+		self
+	}
+
+	pub fn palette(mut self, table: ColorTable) -> Self {
+		self.color_table = Some(table);
+		self
+	}
+
+	/// Time to wait, in hundreths of a second, before this image is drawn
+	pub fn delay(mut self, hundreths: u16) -> Self {
+		self.delay = hundreths;
+		self
+	}
+
+	pub fn disposal_method(mut self, method: DisposalMethod) -> Self {
+		self.disposal_method = method;
+		self
+	}
+
+	pub fn transparent_index(mut self, index: Option<u8>) -> Self {
+		self.transparent_index = index;
+		self
+	}
+
+	pub fn required_version(&self) -> Version {
+		if self.delay > 0
+			|| self.disposal_method != DisposalMethod::NoAction
+			|| self.transparent_index.is_some()
+		{
+			Version::Gif89a
+		} else {
+			Version::Gif87a
+		}
+	}
+
+	pub fn get_graphic_control(&self) -> Option<GraphicControl> {
+		if self.required_version() == Version::Gif89a {
+			if let Some(transindex) = self.transparent_index {
+				Some(GraphicControl::new(
+					self.disposal_method,
+					false,
+					true,
+					self.delay,
+					transindex,
+				))
+			} else {
+				Some(GraphicControl::new(
+					self.disposal_method,
+					false,
+					false,
+					self.delay,
+					0,
+				))
+			}
+		} else {
+			None
+		}
+	}
+
+	pub fn indicies(mut self, indicies: &[u8]) -> Self {
+		self.indicies = indicies.to_vec();
+		self
+	}
+
+	pub fn build(self) -> Result<IndexedImage, EncodingError> {
+		let expected_len = self.width as usize * self.height as usize;
+		if self.indicies.len() != expected_len {
+			return Err(EncodingError::IndicieSizeMismatch {
+				expected: expected_len,
+				got: self.indicies.len(),
+			});
+		}
+
+		let mut imgdesc = ImageDescriptor {
+			left: self.left_offset,
+			top: self.top_offset,
+			width: self.width,
+			height: self.height,
+			packed: 0, // Set later
+		};
+
+		if let Some(lct) = &self.color_table {
+			imgdesc.set_color_table_present(true);
+			imgdesc.set_color_table_size(lct.packed_len());
+		}
+
+		Ok(IndexedImage {
+			image_descriptor: imgdesc,
+			local_color_table: self.color_table,
+			indicies: self.indicies,
+		})
+	}
 }