diff --git a/ggdt/src/graphics/bitmap/indexed/mod.rs b/ggdt/src/graphics/bitmap/indexed/mod.rs index 25c62b7..0d12b44 100644 --- a/ggdt/src/graphics/bitmap/indexed/mod.rs +++ b/ggdt/src/graphics/bitmap/indexed/mod.rs @@ -9,6 +9,17 @@ pub mod primitives; pub type IndexedBitmap = Bitmap; impl IndexedBitmap { + /// Creates a new Bitmap with the specified dimensions. + /// + /// # Arguments + /// + /// * `width`: the width of the bitmap in pixels + /// * `height`: the height of the bitmap in pixels + /// + /// returns: `Result` + pub fn new(width: u32, height: u32) -> Result { + Self::internal_new(width, height) + } pub fn load_file(path: &Path) -> Result<(Self, Palette), BitmapError> { if let Some(extension) = path.extension() { diff --git a/ggdt/src/graphics/bitmap/mod.rs b/ggdt/src/graphics/bitmap/mod.rs index 29fc8f0..c42e4b2 100644 --- a/ggdt/src/graphics/bitmap/mod.rs +++ b/ggdt/src/graphics/bitmap/mod.rs @@ -60,15 +60,9 @@ impl std::fmt::Debug for Bitmap { impl Bitmap { pub const PIXEL_SIZE: usize = std::mem::size_of::(); - /// Creates a new Bitmap with the specified dimensions. - /// - /// # Arguments - /// - /// * `width`: the width of the bitmap in pixels - /// * `height`: the height of the bitmap in pixels - /// - /// returns: `Result` - pub fn new(width: u32, height: u32) -> Result { + // not public to force creation via one of the concrete types (even though this + // would technically work and be fine-ish) + fn internal_new(width: u32, height: u32) -> Result { if width == 0 || height == 0 { return Err(BitmapError::InvalidDimensions); } @@ -100,7 +94,7 @@ impl Bitmap { return Err(BitmapError::OutOfBounds); } - let mut bmp = Self::new(region.width, region.height)?; + let mut bmp = Self::internal_new(region.width, region.height)?; unsafe { bmp.solid_blit(source, region, 0, 0) }; Ok(bmp) } diff --git a/ggdt/src/graphics/bitmap/rgb/mod.rs b/ggdt/src/graphics/bitmap/rgb/mod.rs index 9206b9f..f3be96a 100644 --- a/ggdt/src/graphics/bitmap/rgb/mod.rs +++ b/ggdt/src/graphics/bitmap/rgb/mod.rs @@ -1,9 +1,19 @@ -use crate::graphics::bitmap::Bitmap; +use crate::graphics::bitmap::{Bitmap, BitmapError}; pub mod blit; pub type RgbaBitmap = Bitmap; impl RgbaBitmap { - + /// Creates a new Bitmap with the specified dimensions. + /// + /// # Arguments + /// + /// * `width`: the width of the bitmap in pixels + /// * `height`: the height of the bitmap in pixels + /// + /// returns: `Result` + pub fn new(width: u32, height: u32) -> Result { + Self::internal_new(width, height) + } } diff --git a/ggdt/tests/graphics_indexed.rs b/ggdt/tests/graphics_indexed.rs index a0b09e7..d809e02 100644 --- a/ggdt/tests/graphics_indexed.rs +++ b/ggdt/tests/graphics_indexed.rs @@ -6,7 +6,7 @@ use ggdt::prelude::*; fn setup() -> (IndexedBitmap, Palette) { let palette = Palette::new_vga_palette().unwrap(); - let screen = Bitmap::new(SCREEN_WIDTH, SCREEN_HEIGHT).unwrap(); + let screen = IndexedBitmap::new(SCREEN_WIDTH, SCREEN_HEIGHT).unwrap(); (screen, palette) } @@ -523,7 +523,7 @@ fn generate_bitmap(width: i32, height: i32) -> IndexedBitmap { let x_third = width / 3; let y_third = height / 3; - let mut bitmap = Bitmap::new(width as u32, height as u32).unwrap(); + let mut bitmap = IndexedBitmap::new(width as u32, height as u32).unwrap(); bitmap.filled_rect(0, 0, x_third, y_third, 1); bitmap.filled_rect(x_third * 2 + 1, y_third * 2 + 1, width - 1, height - 1, 2);