about summary refs log tree commit diff
path: root/gifed/src/block
diff options
context:
space:
mode:
Diffstat (limited to 'gifed/src/block')
-rw-r--r--gifed/src/block/indexedimage.rs4
-rw-r--r--gifed/src/block/packed.rs2
-rw-r--r--gifed/src/block/palette.rs18
3 files changed, 18 insertions, 6 deletions
diff --git a/gifed/src/block/indexedimage.rs b/gifed/src/block/indexedimage.rs
index 261ff38..c98e753 100644
--- a/gifed/src/block/indexedimage.rs
+++ b/gifed/src/block/indexedimage.rs
@@ -17,7 +17,7 @@ impl IndexedImage {
 	}
 
 	pub fn top(&self) -> u16 {
-		self.image_descriptor.left
+		self.image_descriptor.top
 	}
 
 	pub fn width(&self) -> u16 {
@@ -129,7 +129,7 @@ impl CompressedImage {
 			blocks,
 		} = self;
 
-		let data: Vec<u8> = blocks.into_iter().map(<_>::into_iter).flatten().collect();
+		let data: Vec<u8> = blocks.into_iter().flat_map(<_>::into_iter).collect();
 
 		println!("lzw: {lzw_code_size}");
 
diff --git a/gifed/src/block/packed.rs b/gifed/src/block/packed.rs
index 455f43a..0752e39 100644
--- a/gifed/src/block/packed.rs
+++ b/gifed/src/block/packed.rs
@@ -1,3 +1,5 @@
+#![allow(clippy::unusual_byte_groupings)]
+
 #[derive(Clone, Copy, Debug, PartialEq)]
 pub struct GraphicPacked {
 	pub raw: u8,
diff --git a/gifed/src/block/palette.rs b/gifed/src/block/palette.rs
index 67d9ae8..8a06883 100644
--- a/gifed/src/block/palette.rs
+++ b/gifed/src/block/palette.rs
@@ -36,10 +36,14 @@ impl Palette {
 		self.table.len()
 	}
 
+	pub fn is_empty(&self) -> bool {
+		self.len() > 0
+	}
+
 	/// Returns the number of items that the decoder *thinks* is in the palette.
 	/// This is 2^(n + 1) where n = [Palette::packed_len]
 	pub fn computed_len(&self) -> usize {
-		2usize.pow(self.packed_len() as u32 + 1)
+		1 << (self.packed_len() + 1)
 	}
 
 	/// Pushes a color on to the end of the table
@@ -48,7 +52,7 @@ impl Palette {
 	}
 
 	pub fn get(&self, index: u8) -> Option<Color> {
-		self.table.get(index as usize).map(|v| v.clone())
+		self.table.get(index as usize).copied()
 	}
 
 	pub fn from_color<C: AsRef<Color>>(&self, color: C) -> Option<u8> {
@@ -65,7 +69,7 @@ impl Palette {
 	//TODO: gen- better docs
 	fn padding(&self) -> usize {
 		let comp = self.computed_len();
-		(comp as usize - self.len()) * 3
+		(comp - self.len()) * 3
 	}
 
 	/// The palette with padding if required
@@ -81,6 +85,12 @@ impl Palette {
 	}
 }
 
+impl Default for Palette {
+	fn default() -> Self {
+		Self::new()
+	}
+}
+
 impl Deref for Palette {
 	type Target = [Color];
 
@@ -117,7 +127,7 @@ impl TryFrom<&[u8]> for Palette {
 
 	fn try_from(value: &[u8]) -> Result<Self, Self::Error> {
 		if value.len() % 3 != 0 {
-			return Err(());
+			Err(())
 		} else {
 			Ok(Self {
 				table: value