diff options
Diffstat (limited to 'gifed/src/block')
-rw-r--r-- | gifed/src/block/indexedimage.rs | 6 | ||||
-rw-r--r-- | gifed/src/block/packed.rs | 2 | ||||
-rw-r--r-- | gifed/src/block/palette.rs | 18 |
3 files changed, 19 insertions, 7 deletions
diff --git a/gifed/src/block/indexedimage.rs b/gifed/src/block/indexedimage.rs index 1868382..03c2119 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 { @@ -86,7 +86,7 @@ impl CompressedImage { } pub fn top(&self) -> u16 { - self.image_descriptor.left + self.image_descriptor.top } pub fn width(&self) -> u16 { @@ -126,7 +126,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(); //TODO: remove unwrap let mut decompressor = weezl::decode::Decoder::new(weezl::BitOrder::Msb, 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 d5cc696..9c4a5a9 100644 --- a/gifed/src/block/palette.rs +++ b/gifed/src/block/palette.rs @@ -35,10 +35,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 @@ -47,7 +51,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> { @@ -64,7 +68,7 @@ impl Palette { //TODO: gen- better docs pub fn padding(&self) -> usize { let comp = self.computed_len(); - (comp as usize - self.len()) * 3 + (comp - self.len()) * 3 } pub fn as_bytes(&self) -> Vec<u8> { @@ -77,6 +81,12 @@ impl Palette { } } +impl Default for Palette { + fn default() -> Self { + Self::new() + } +} + impl Deref for Palette { type Target = [Color]; @@ -97,7 +107,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 |