rustic_bitmap

Trait Bitmap

Source
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§

Source

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 pixels
  • height: Image height in pixels
  • bpp: Bits per pixel (commonly 24)
§Returns

A Vec<u8> containing the full BMP file structure, ready to write to disk.

Source

fn point_exists(&self, point: &Point) -> bool

Checks whether a given point is within the bounds of the image and if the buffer has a valid bitmap file signature.

§Arguments
  • point - A reference to a Point to check.
§Returns

true if the point is inside the image bounds, otherwise false.

Source

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 a Point struct representing the (x, y) coordinates of the pixel.
  • color: A reference to an Rgb struct containing the color to set the pixel to.
Source

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.

Source

fn draw_line(&mut self, start: &Point, end: &Point, color: &Rgb)

Draws a straight line between two points using the given color.

Source

fn draw_rectangle(&mut self, point1: &Point, point2: &Point, color: &Rgb)

Draws an empty rectangle defined by two diagonal corner points and a color.

Source

fn draw_char(&mut self, char_index: usize, position: &Point, color: &Rgb)

Draws a character at the specified position.

Source

fn draw_string(&mut self, string: &str, position: &Point, color: &Rgb)

Draws a string of text starting at the specified position.

Source

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.

Source

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.

Implementations on Foreign Types§

Source§

impl Bitmap for Vec<u8>

Source§

fn new_bitmap(width: u32, height: u32, bpp: u16) -> Vec<u8>

Source§

fn draw_point(&mut self, start: &Point, color: &Rgb)

Source§

fn point_exists(&self, point: &Point) -> bool

Source§

fn draw_circle(&mut self, center: &Point, radius: u32, color: &Rgb)

Source§

fn draw_line(&mut self, start: &Point, end: &Point, color: &Rgb)

Source§

fn draw_rectangle(&mut self, point1: &Point, point2: &Point, color: &Rgb)

Source§

fn draw_char(&mut self, char_index: usize, position: &Point, color: &Rgb)

Source§

fn draw_string(&mut self, string: &str, position: &Point, color: &Rgb)

Source§

fn draw_polygon(&mut self, points: &[Point], color: &Rgb)

Source§

fn has_file_signature(&self) -> bool

Implementors§