ImageRGB8

Struct ImageRGB8 

Source
pub struct ImageRGB8 {
    pub width: usize,
    pub height: usize,
    pub image_data: Vec<[u8; 3]>,
    /* private fields */
}
Expand description

A struct that holds an RGB image with bit depth of 8

Fields§

§width: usize

The width of the image

§height: usize

The height of the image

§image_data: Vec<[u8; 3]>

The image pixel data

Implementations§

Source§

impl ImageRGB8

Source

pub fn new(width: usize, height: usize, background: [u8; 3]) -> Self

Returns a new ImageRGB8. width, height are image dimensions. background is image’s color.

Source

pub fn from_png(path: &str) -> Result<Self, &'static str>

Reads the image from a PNG file. Returns Result which holds new ImageRGB8 or Err with informative message. path is the path to the PNG file. The PNG file should be RGB or RGBA with bit depth of 8.

Source

pub fn from_bytes( width: usize, height: usize, bytes: &[u8], ) -> Result<Self, &'static str>

Returns Result with new ImageRGB8 or Err with informative message. It is constructed from width, height and bytes

Source

pub fn to_png(&self, path: &str) -> Result<(), &'static str>

Saves the image as PNG. path is a path + filename where it will be saved. Returns Ok if everything goes well, or Err with description of the error.

Source

pub fn to_bytes(&self) -> &[u8]

Returns a slice of bytes of the image_data

Source

pub fn get_pixel(&self, x: usize, y: usize) -> Result<[u8; 3], &'static str>

Returns an RGB value of the specified pixel if that pixel exists.

Source

pub fn set_pixel(&mut self, x: usize, y: usize, color: [u8; 3])

Changes the specified pixel to the given color. If the pixel doesn’t exist, does nothing.

Source

pub fn clear(&mut self)

Clears image_data of any drawings (resets it to the state it was in when ImageRGB8 was created, unless ImageRGB8::set_background_color() was used).

Source

pub fn set_background_color(&mut self, color: [u8; 3])

Sets a new color that will be used as background. This only changes internal background data, if you want to apply this to image, call ImageRGB8::clear() after this.

Source

pub fn draw_line( &mut self, x1: usize, y1: usize, x2: usize, y2: usize, color: [u8; 3], thickness: usize, opacity: f64, )

Draws a new line. x1, y1 are coordinates of the starting point. x2, y2 are coordinates of the ending point. color defines the color of the line. thickness defines how thick the line will be. (currently doesn’t do anything). If set to 0, nothing will be drawn. opacity sets the transparency of the line. <= 0.0 means the line will be completely transparent, while >= 1.0 means the line won’t be transparent.

Source

pub fn draw_rectangle( &mut self, x1: usize, y1: usize, x2: usize, y2: usize, color: [u8; 3], thickness: usize, opacity: f64, )

Draws a new rectangle. x1, y1 are the coordinates of the first corner, and x2, y2 are the coordinates of the opposite corner. color defines the color of the rectangle. thickness defines how thick the rectangle will be. (thickness is added to the inside of the rectangle). If set to 0, the rectangle will be filled. opacity sets the transparency of the rectangle. <= 0.0 means the rectangle will be completely transparent, while >= 1.0 means the rectangle won’t be transparent.

Source

pub fn draw_circle( &mut self, x: usize, y: usize, radius: usize, color: [u8; 3], thickness: usize, opacity: f64, )

Draws a new circle. x, y are the coordinates of the center of the circle. radius defines the radius of the circle. color defines the color of the circle. thickness defines how thick the circle will be. (currently doesn’t do anything). If set to 0, the circle will be filled. opacity sets the transparency of the circle. <= 0.0 means the circle will be completely transparent, while >= 1.0 means the circle won’t be transparent.

Source

pub fn draw_ellipse( &mut self, x: usize, y: usize, horizontal_axis: usize, vertical_axis: usize, color: [u8; 3], thickness: usize, opacity: f64, )

Draws a new ellipse. x, y are the coordinates of the center of the ellipse. horizontal_axis defines the half length of the horizontal axis. vertical_axis defines the half length of the vertical axis. color defines the color of the ellipse. thickness defines how thick the ellipse will be. (currently doesn’t do anything). If set to 0, the ellipse will be filled. opacity sets the transparency of the ellipse. <= 0.0 means the ellipse will be completely transparent, while >= 1.0 means the ellipse won’t be transparent.

Auto Trait Implementations§

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, 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.