Struct bmp_monochrome::Bmp
source · pub struct Bmp { /* private fields */ }
Expand description
The Bmp
struct contains the data as a vector of vectors of booleans.
Each boolean represent a pixel.
In rows
the first element is the upper row, inside the first vector there are the pixel
from left to right, thus rows[0][0]
is the upper-left element.
Max len of the vetors (both rows and colums) is u16::MAX`
Note in the serialized format the first element is the lower-left pixel
see BMP file format
Implementations§
source§impl Bmp
impl Bmp
sourcepub fn new(rows: Vec<Vec<bool>>) -> Result<Bmp, BmpError>
pub fn new(rows: Vec<Vec<bool>>) -> Result<Bmp, BmpError>
Creates a new Bmp, failing if rows
is empty or it’s first element is empty
or it’s elements has different len
sourcepub fn get(&self, i: u16, j: u16) -> bool
pub fn get(&self, i: u16, j: u16) -> bool
return the pixel situated at (i,j), where (0,0) is the upper-left corner could panic if i > self.height() || j > self.width()
sourcepub fn mul(&self, mul: u8) -> Result<Bmp, BmpError>
pub fn mul(&self, mul: u8) -> Result<Bmp, BmpError>
return a new Bmp where every pixel is multiplied by mul
, erroring if mul is 0 or 1 or the
resulting image would be bigger than limits enforced by [crate::check_size]
sourcepub fn div(&self, div: u8) -> Result<Bmp, BmpError>
pub fn div(&self, div: u8) -> Result<Bmp, BmpError>
return a new Bmp where every square is divided by div
if all the square is not of the same color it errors
sourcepub fn normalize(&self) -> Bmp
pub fn normalize(&self) -> Bmp
normalize
removes the white border if any, and reduce the module pixel size to 1
(the module must be smaller than 10x10 pixel)
sourcepub fn add_white_border(&self, border_size: u8) -> Result<Bmp, BmpError>
pub fn add_white_border(&self, border_size: u8) -> Result<Bmp, BmpError>
return a new Bmp with border_size
pixels around
sourcepub fn remove_white_border(&self) -> Bmp
pub fn remove_white_border(&self) -> Bmp
remove all the white border, if any
sourcepub fn display(&self) -> StringOutput<'_>
pub fn display(&self) -> StringOutput<'_>
Return a struct implementing Display to visualize in terminal or in tests