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

source

pub fn read<T: Read>(from: T) -> Result<Self, BmpError>

Read the monochrome bitmap from a Read type, such a File note that File read are not buffered and may be slow, see Read Trait

source§

impl Bmp

source

pub fn write<T: Write>(&self, to: T) -> Result<(), BmpError>

Write the monochrome bitmap to a Write type, such a File

source§

impl Bmp

source

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

source

pub fn height(&self) -> u16

return the Bmp height in pixel

source

pub fn width(&self) -> u16

return the Bmp width in pixel

source

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()

source

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]

source

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

source

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)

source

pub fn add_white_border(&self, border_size: u8) -> Result<Bmp, BmpError>

return a new Bmp with border_size pixels around

source

pub fn remove_white_border(&self) -> Bmp

remove all the white border, if any

source

pub fn display(&self) -> StringOutput<'_>

Return a struct implementing Display to visualize in terminal or in tests

source

pub fn inverse(&self) -> Bmp

Return inverted bitmap, black pixels become white and viceversa.

Trait Implementations§

source§

impl Clone for Bmp

source§

fn clone(&self) -> Bmp

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for Bmp

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl PartialEq<Bmp> for Bmp

source§

fn eq(&self, other: &Bmp) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl Eq for Bmp

source§

impl StructuralEq for Bmp

source§

impl StructuralPartialEq for Bmp

Auto Trait Implementations§

§

impl RefUnwindSafe for Bmp

§

impl Send for Bmp

§

impl Sync for Bmp

§

impl Unpin for Bmp

§

impl UnwindSafe for Bmp

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.