diff options
author | Genny <gen@nyble.dev> | 2021-11-21 18:35:57 -0600 |
---|---|---|
committer | Genny <gen@nyble.dev> | 2021-11-21 18:35:57 -0600 |
commit | 1de64a3818875947f7f1044b1d4cfdf271b04fd3 (patch) | |
tree | 3a5bfbb237d67832dfa1beeb3d28566173484b63 /src/colorimage.rs | |
parent | f35e18cb0531e7d6a3544560746d592aa47ed555 (diff) | |
download | gifed-1de64a3818875947f7f1044b1d4cfdf271b04fd3.tar.gz gifed-1de64a3818875947f7f1044b1d4cfdf271b04fd3.zip |
Bring gifprobe into this repository
Diffstat (limited to 'src/colorimage.rs')
-rw-r--r-- | src/colorimage.rs | 61 |
1 files changed, 0 insertions, 61 deletions
diff --git a/src/colorimage.rs b/src/colorimage.rs deleted file mode 100644 index 69dac1e..0000000 --- a/src/colorimage.rs +++ /dev/null @@ -1,61 +0,0 @@ -use std::convert::TryFrom; - -use crate::{block::ColorTable, gif::Image, reader::DecodingError, Color}; - -pub struct ColorImage { - 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, - }) - } -} - -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, - ) - } -} - -#[derive(Copy, Clone, Debug, PartialEq)] -pub enum Pixel { - Color(Color), - Transparent, -} |