Struct BitMap

Source
pub struct BitMap { /* private fields */ }
Expand description

In memory representation of a bitmap allowing for easier editing

Implementations§

Source§

impl BitMap

This block deals with constructors, and getters and setters

Source

pub fn read(filename: &str) -> Result<BitMap, String>

Create a bitmap by reading in a .bmp file

Fails if filename doesn’t end with “.bmp”

Source

pub fn new(width: u32, height: u32) -> BitMap

Create a new bitmap image in memory

Fill all the pixels as white

Source

pub fn create( width: u32, height: u32, pixels: Vec<Rgba>, ) -> Result<BitMap, &'static str>

Create a new image from a list of pixels

Source

pub fn get_pixel(&self, x: u32, y: u32) -> Option<&Rgba>

Get a pixel at a specific x and y coordinate

Source

pub fn get_pixels(&self) -> &Vec<Rgba>

Get a reference to the collection of all the pixels inside of the image

Source

pub fn get_width(&self) -> u32

Get the width of the image

Source

pub fn get_height(&self) -> u32

Get the height of the image

Source

pub fn get_size(&self) -> u32

Get the area of the image in pixels

Source

pub fn get_estimated_file_size_in_bytes(&self) -> u32

Get the estimated file size in bytes

Source

pub fn get_filename(&self) -> Option<&String>

Get a reference to the file name of the bitmap if it exists

Source

pub fn get_all_unique_colors(&self) -> Vec<Rgba>

Get all the unique colors from pixels, remove any duplicates

Source

pub fn is_image_transparent(&self) -> bool

Check if there is at least one pixel that it translucent

Source§

impl BitMap

This block deals with saving the image

Source

pub fn save(&self) -> Result<(), String>

Save the image to its original location

Fail if no original location is linked to the current bitmap

Source

pub fn save_as(&self, filename: &str) -> Result<(), String>

Save the image to a new location on disk

Source

pub fn simplify_and_save(&self) -> Result<(), String>

Analyze the currently recorded pixels and try and find the lowest bit count possible to save the images at.

The bit depth will be: if there are at most 2 colors present, 2 bit if there are at most 16 colors present, 4 bit if there are at most 256 colors present, 8 bit if there are more then 256 colors and all alphas are 100, 24 bit if there are more then 256 colors and at least one alpha is not 100, 32 bit

Source

pub fn simplify_and_save_as(&self, filename: &str) -> Result<(), String>

Analyze the currently recorded pixels and try and find the lowest bit count possible to save the images at.

The bit depth will be: if there are at most 2 colors present, 2 bit if there are at most 16 colors present, 4 bit if there are at most 256 colors present, 8 bit if there are more then 256 colors and all alphas are 100, 24 bit if there are more then 256 colors and at least one alpha is not 100, 32 bit

Source§

impl BitMap

This block deals with creating a new bitmap from an existing one and manipulating bit maps using other bitmaps

Source

pub fn crop( &self, from_x: u32, from_y: u32, to_x: u32, to_y: u32, ) -> Result<BitMap, &'static str>

Crop a given area of the current image

@param {u32} starting x position @param {u32} starting y position @param {u32} ending x position @param {u32} ending y position

@exception {&’static str} error message if the starting x and ending x or starting y and ending y is out of the image with height or width, throw an error

Source

pub fn paste( &mut self, bitmap: &BitMap, start_at_x: u32, start_at_y: u32, ) -> Result<(), &'static str>

Paste and entire bitmap into the current bitmap.

Source§

impl BitMap

This block deals with coloring the image

Source

pub fn set_pixel( &mut self, x: u32, y: u32, color: Rgba, ) -> Result<(), &'static str>

Set the color of a pixel

@param {u32} x position @param {u32} y position @param {Rgba} color to set pixel

Source

pub fn color_to_gray(&mut self)

Convert image from a colored image to gray

Source

pub fn replace_all_color(&mut self, from: Rgba, to: Rgba)

Find all the pixels that are the same as the from color and convert them all to the “to” color.

@param {Rgba} from color @param {Rgba} to color

Source

pub fn fill_region( &mut self, x: u32, y: u32, color: Rgba, ) -> Result<(), &'static str>

Fill a region of an image with a color. The only colors that get changed are those that are the same as the pixel found at the given x and y value

@param {u32} x position @param {u32} y position @param {Rgba} color to use to replace the other color

Source§

impl BitMap

This block is only meant for resizing images using one of the 3 (so far only 2 implemented) algorithms (nearest neighbor, bilinear, bicubic) as well as rotating the image left or right by 90 degrees

Source

pub fn fast_resize_by(&mut self, factor: f32) -> Result<(), &'static str>

Resize the current image by using nearest neighbor algorithm. Scale image to image size * the factor

Source

pub fn fast_resize_to(&mut self, width: u32, height: u32)

Resize the current image by using nearest neighbor algorithm. Scale image to specified width and height

Source

pub fn resize_by(&mut self, factor: f32) -> Result<(), &'static str>

Resize the current image by using bilinear interpolation algorithm. Scale image to image size * the factor

Source

pub fn resize_to(&mut self, width: u32, height: u32)

Resize the current image by using bilinear interpolation algorithm. Scale image to specified width and height

Source

pub fn slow_resize_by(&mut self, factor: f32) -> Result<(), &'static str>

Resize the current image by using bicubic interpolation algorithm. Scale image to image size * the factor

Source

pub fn slow_resize_to(&mut self, width: u32, height: u32)

Resize the current image by using bicubic interpolation algorithm. Scale image to specified width and height

Source

pub fn slow_resize(&mut self, width: u32, height: u32)

Resize the current image by using bicubic interpolation algorithm

Source

pub fn rotate_right(&mut self)

Rotate the entire image right by 90 degrees

Source

pub fn rotate_left(&mut self)

Rotate the entire image left by 90 degrees

Trait Implementations§

Source§

impl Debug for BitMap

Source§

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

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

impl Display for BitMap

Source§

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

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

impl PartialEq for BitMap

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.

Auto Trait Implementations§

§

impl Freeze for BitMap

§

impl RefUnwindSafe for BitMap

§

impl Send for BitMap

§

impl Sync for BitMap

§

impl Unpin for BitMap

§

impl UnwindSafe for BitMap

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where 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 T
where 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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

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

Source§

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 T
where U: TryFrom<T>,

Source§

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.