use crate::GraphicGroupTable; pub use crate::color::*; use crate::raster_types::{CPU, RasterDataTable}; use crate::vector::VectorDataTable; use std::fmt::Debug; #[cfg(target_arch = "spirv")] use spirv_std::num_traits::float::Float; /// as to not yet rename all references pub mod color { pub use super::*; } pub mod image; pub use self::image::Image; pub trait Bitmap { type Pixel: Pixel; fn width(&self) -> u32; fn height(&self) -> u32; fn dimensions(&self) -> (u32, u32) { (self.width(), self.height()) } fn dim(&self) -> (u32, u32) { self.dimensions() } fn get_pixel(&self, x: u32, y: u32) -> Option; } impl Bitmap for &T { type Pixel = T::Pixel; fn width(&self) -> u32 { (**self).width() } fn height(&self) -> u32 { (**self).height() } fn get_pixel(&self, x: u32, y: u32) -> Option { (**self).get_pixel(x, y) } } impl Bitmap for &mut T { type Pixel = T::Pixel; fn width(&self) -> u32 { (**self).width() } fn height(&self) -> u32 { (**self).height() } fn get_pixel(&self, x: u32, y: u32) -> Option { (**self).get_pixel(x, y) } } pub trait BitmapMut: Bitmap { fn get_pixel_mut(&mut self, x: u32, y: u32) -> Option<&mut Self::Pixel>; fn set_pixel(&mut self, x: u32, y: u32, pixel: Self::Pixel) { *self.get_pixel_mut(x, y).unwrap() = pixel; } fn map_pixels Self::Pixel>(&mut self, map_fn: F) { for y in 0..self.height() { for x in 0..self.width() { let pixel = self.get_pixel(x, y).unwrap(); self.set_pixel(x, y, map_fn(pixel)); } } } } impl BitmapMut for &mut T { fn get_pixel_mut(&mut self, x: u32, y: u32) -> Option<&mut Self::Pixel> { (*self).get_pixel_mut(x, y) } }