Skip to main content

Image

Struct Image 

Source
pub struct Image {
    pub width: usize,
    pub height: usize,
    /* private fields */
}
Expand description

A row-major RGB image stored in memory.

Fields§

§width: usize

Width of the image in pixels.

§height: usize

Height of the image in pixels.

Implementations§

Source§

impl Image

Source

pub fn new(width: usize, height: usize) -> Self

Creates a new image filled with a black pixel color.

Source

pub fn new_black(width: usize, height: usize) -> Self

Creates a new image filled with black.

Source

pub fn new_white(width: usize, height: usize) -> Self

Creates a new image filled with white.

Source

pub fn from_color(width: usize, height: usize, color: Pixel) -> Self

Creates an image filled with a single color.

Source

pub fn from_pixels(width: usize, height: usize, pixels: Vec<Pixel>) -> Self

Creates an image from a flat pixel buffer.

Source

pub fn from_pixel_fn( width: usize, height: usize, pixel_fn: impl FnMut(usize, usize) -> Pixel, ) -> Self

Builds an image by evaluating a callback for every (x, y) pixel coordinate.

Source

pub fn open(path: impl AsRef<Path>) -> Result<Self>

Opens an image from the given path using the binary P6 PPM format.

Source

pub fn save(&self, path: impl AsRef<Path>) -> Result<()>

Saves the image to the given path as a binary P6 PPM file.

Source

pub fn from_file(filename: &str) -> Result<Self>

Loads an image from a file using the file name string.

Source

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

Saves this image to a file using the file name string.

Source

pub fn from_image(image: &Self) -> Self

Clones an image from an existing one.

Source

pub fn pixels(&self) -> &[Pixel]

Returns the backing pixel storage.

Source

pub fn get_pixel(&self, x: usize, y: usize) -> Option<&Pixel>

Reads a pixel from the image at (x, y).

Source

pub fn set_pixel(&mut self, x: usize, y: usize, pixel: Pixel)

Sets a pixel in the image at (x, y).

Trait Implementations§

Source§

impl Clone for Image

Source§

fn clone(&self) -> Image

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for Image

Source§

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

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

impl Eq for Image

Source§

impl PartialEq for Image

Source§

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for Image

Auto Trait Implementations§

§

impl Freeze for Image

§

impl RefUnwindSafe for Image

§

impl Send for Image

§

impl Sync for Image

§

impl Unpin for Image

§

impl UnsafeUnpin for Image

§

impl UnwindSafe for Image

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

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