pub trait Bitmap {
// Required methods
fn new_bitmap(width: u32, height: u32, bpp: u16) -> Vec<u8>;
fn point_exists(&self, point: &Point) -> bool;
fn draw_point(&mut self, start: &Point, color: &Rgb);
fn draw_circle(&mut self, center: &Point, radius: u32, color: &Rgb);
fn draw_line(&mut self, start: &Point, end: &Point, color: &Rgb);
fn draw_rectangle(&mut self, point1: &Point, point2: &Point, color: &Rgb);
fn draw_char(&mut self, char_index: usize, position: &Point, color: &Rgb);
fn draw_string(&mut self, string: &str, position: &Point, color: &Rgb);
fn draw_polygon(&mut self, points: &[Point], color: &Rgb);
fn has_file_signature(&self) -> bool;
}
Expand description
A trait for low-level bitmap operations such as drawing shapes and text.
This trait defines the basic functions for rendering onto a bitmap, including methods for drawing pixels, lines, rectangles, circles, and text. It also includes helper functions for validation and bitmap construction.
Required Methods§
Sourcefn new_bitmap(width: u32, height: u32, bpp: u16) -> Vec<u8>
fn new_bitmap(width: u32, height: u32, bpp: u16) -> Vec<u8>
Creates a BMP image file in memory with the given width, height, and bit depth.
This function generates both the BMP file header and the DIB (info) header, allocates zeroed pixel data, and applies correct padding per BMP format rules.
§Parameters
width
: Image width in pixelsheight
: Image height in pixelsbpp
: Bits per pixel (commonly 24)
§Returns
A Vec<u8>
containing the full BMP file structure, ready to write to disk.
Sourcefn point_exists(&self, point: &Point) -> bool
fn point_exists(&self, point: &Point) -> bool
Sourcefn draw_point(&mut self, start: &Point, color: &Rgb)
fn draw_point(&mut self, start: &Point, color: &Rgb)
Draws a single pixel at the specified coordinates (start
) with the given color (Rgb
).
§Parameters
start
: A reference to aPoint
struct representing the (x, y) coordinates of the pixel.color
: A reference to anRgb
struct containing the color to set the pixel to.
Sourcefn draw_circle(&mut self, center: &Point, radius: u32, color: &Rgb)
fn draw_circle(&mut self, center: &Point, radius: u32, color: &Rgb)
Draws a circle centered at the given point with the specified radius and color.
Sourcefn draw_line(&mut self, start: &Point, end: &Point, color: &Rgb)
fn draw_line(&mut self, start: &Point, end: &Point, color: &Rgb)
Draws a straight line between two points using the given color.
Sourcefn draw_rectangle(&mut self, point1: &Point, point2: &Point, color: &Rgb)
fn draw_rectangle(&mut self, point1: &Point, point2: &Point, color: &Rgb)
Draws an empty rectangle defined by two diagonal corner points and a color.
Sourcefn draw_char(&mut self, char_index: usize, position: &Point, color: &Rgb)
fn draw_char(&mut self, char_index: usize, position: &Point, color: &Rgb)
Draws a character at the specified position.
Sourcefn draw_string(&mut self, string: &str, position: &Point, color: &Rgb)
fn draw_string(&mut self, string: &str, position: &Point, color: &Rgb)
Draws a string of text starting at the specified position.
Sourcefn draw_polygon(&mut self, points: &[Point], color: &Rgb)
fn draw_polygon(&mut self, points: &[Point], color: &Rgb)
Draws a polygon using an array of points.
Points will be connected in the given order, and the shape is closed automatically.
Sourcefn has_file_signature(&self) -> bool
fn has_file_signature(&self) -> bool
Checks whether the bitmap data contains a valid file signature (“BM” for BMP files).
Useful for verifying the file format before parsing or writing.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.