diff --git a/services/gam/src/bitmap.rs b/services/gam/src/bitmap.rs index a4cb16fb1..6dd5665c9 100644 --- a/services/gam/src/bitmap.rs +++ b/services/gam/src/bitmap.rs @@ -5,6 +5,8 @@ use std::convert::TryInto; use std::io::Read; use std::ops::Deref; +mod img; +pub use img::*; mod decode_png; pub use decode_png::*; mod greyscale; @@ -362,71 +364,6 @@ impl<'a> From<&Img> for Bitmap { } } -// ********************************************************************** - -#[derive(Debug, Clone, Copy)] -pub enum PixelType { - U0, // Error - U8, - U8x2, - U8x3, - U8x4, - U16, - U16x2, - U16x3, - U16x4, -} - -/* - * Image as a minimal flat buffer of u8; accessible by (x, y) - * - * author: nworbnhoj - */ - -//#[derive(Debug)] -pub struct Img { - pub pixels: Vec, - pub width: usize, - pub px_type: PixelType, -} - -impl Img { - pub fn new(pixels: Vec, width: usize, px_type: PixelType) -> Self { - Self { - pixels, - width, - px_type, - } - } - pub fn width(&self) -> usize { - self.width - } - pub fn height(&self) -> usize { - match self.px_type { - PixelType::U8 => self.pixels.len() / self.width, - PixelType::U8x2 => self.pixels.len() / (self.width * 2), - PixelType::U8x3 => self.pixels.len() / (self.width * 3), - PixelType::U8x4 => self.pixels.len() / (self.width * 4), - PixelType::U16 => self.pixels.len() / (self.width * 2), - PixelType::U16x2 => self.pixels.len() / (self.width * 4), - PixelType::U16x3 => self.pixels.len() / (self.width * 6), - PixelType::U16x4 => self.pixels.len() / (self.width * 8), - _ => { - log::warn!("PixelType not implemented"); - 0 - } - } - } -} - -impl Deref for Img { - type Target = Vec; - - fn deref(&self) -> &Self::Target { - &self.pixels - } -} - // ********************************************************************** diff --git a/services/gam/src/bitmap/img.rs b/services/gam/src/bitmap/img.rs new file mode 100644 index 000000000..748852a7f --- /dev/null +++ b/services/gam/src/bitmap/img.rs @@ -0,0 +1,70 @@ +/* + * Img is a minimal structure to hold an RGB raster image + * + * author: nworbnhoj + */ + +use std::ops::Deref; + +#[derive(Debug, Clone, Copy)] +pub enum PixelType { + U0, // Error + U8, + U8x2, + U8x3, + U8x4, + U16, + U16x2, + U16x3, + U16x4, +} + +/* + * Image as a minimal flat buffer of u8; accessible by (x, y) + * + * author: nworbnhoj + */ + +//#[derive(Debug)] +pub struct Img { + pub pixels: Vec, + pub width: usize, + pub px_type: PixelType, +} + +impl Img { + pub fn new(pixels: Vec, width: usize, px_type: PixelType) -> Self { + Self { + pixels, + width, + px_type, + } + } + pub fn width(&self) -> usize { + self.width + } + pub fn height(&self) -> usize { + match self.px_type { + PixelType::U8 => self.pixels.len() / self.width, + PixelType::U8x2 => self.pixels.len() / (self.width * 2), + PixelType::U8x3 => self.pixels.len() / (self.width * 3), + PixelType::U8x4 => self.pixels.len() / (self.width * 4), + PixelType::U16 => self.pixels.len() / (self.width * 2), + PixelType::U16x2 => self.pixels.len() / (self.width * 4), + PixelType::U16x3 => self.pixels.len() / (self.width * 6), + PixelType::U16x4 => self.pixels.len() / (self.width * 8), + _ => { + log::warn!("PixelType not implemented"); + 0 + } + } + } +} + +impl Deref for Img { + type Target = Vec; + + fn deref(&self) -> &Self::Target { + &self.pixels + } +}