diff options
author | Genny <gen@nyble.dev> | 2021-10-11 03:36:38 -0500 |
---|---|---|
committer | Genny <gen@nyble.dev> | 2021-10-11 03:36:38 -0500 |
commit | 757eab88d67a425728b87286c763387f52367196 (patch) | |
tree | f1d61edb0a838787f6984accdd92df68a69d567a /src/colorimage.rs | |
parent | 9b7bd5696a21496fa0c38a17e69c5c0658acfe73 (diff) | |
download | gifed-757eab88d67a425728b87286c763387f52367196.tar.gz gifed-757eab88d67a425728b87286c763387f52367196.zip |
Run rustfmt
Diffstat (limited to 'src/colorimage.rs')
-rw-r--r-- | src/colorimage.rs | 90 |
1 files changed, 45 insertions, 45 deletions
diff --git a/src/colorimage.rs b/src/colorimage.rs index 1bdb273..69dac1e 100644 --- a/src/colorimage.rs +++ b/src/colorimage.rs @@ -3,59 +3,59 @@ use std::convert::TryFrom; use crate::{block::ColorTable, gif::Image, reader::DecodingError, Color}; pub struct ColorImage { - width: u16, - height: u16, - data: Vec<Pixel>, + width: u16, + height: u16, + data: Vec<Pixel>, } impl ColorImage { - pub(crate) fn from_indicies( - width: u16, - height: u16, - indicies: &[u8], - table: &ColorTable, - transindex: Option<u8>, - ) -> Result<Self, DecodingError> { - let mut data = vec![Pixel::Transparent; (width * height) as usize]; - - for (image_index, color_index) in indicies.into_iter().enumerate() { - if let Some(trans) = transindex { - if trans == *color_index { - data[image_index] = Pixel::Transparent; - } - } else { - data[image_index] = Pixel::Color( - table - .get(*color_index) - .ok_or(DecodingError::ColorIndexOutOfBounds)?, - ); - } - } - - Ok(ColorImage { - width, - height, - data, - }) - } + pub(crate) fn from_indicies( + width: u16, + height: u16, + indicies: &[u8], + table: &ColorTable, + transindex: Option<u8>, + ) -> Result<Self, DecodingError> { + let mut data = vec![Pixel::Transparent; (width * height) as usize]; + + for (image_index, color_index) in indicies.into_iter().enumerate() { + if let Some(trans) = transindex { + if trans == *color_index { + data[image_index] = Pixel::Transparent; + } + } else { + data[image_index] = Pixel::Color( + table + .get(*color_index) + .ok_or(DecodingError::ColorIndexOutOfBounds)?, + ); + } + } + + Ok(ColorImage { + width, + height, + data, + }) + } } impl<'a> TryFrom<Image<'a>> for ColorImage { - type Error = DecodingError; - - fn try_from(img: Image<'a>) -> Result<Self, Self::Error> { - ColorImage::from_indicies( - img.width, - img.height, - img.indicies, - img.palette, - img.transparent_index, - ) - } + type Error = DecodingError; + + fn try_from(img: Image<'a>) -> Result<Self, Self::Error> { + ColorImage::from_indicies( + img.width, + img.height, + img.indicies, + img.palette, + img.transparent_index, + ) + } } #[derive(Copy, Clone, Debug, PartialEq)] pub enum Pixel { - Color(Color), - Transparent, + Color(Color), + Transparent, } |