pub struct Image {
pub width: usize,
pub height: usize,
/* private fields */
}Expand description
A row-major RGB image stored in memory.
Fields§
§width: usizeWidth of the image in pixels.
height: usizeHeight of the image in pixels.
Implementations§
Source§impl Image
impl Image
Sourcepub fn new(width: usize, height: usize) -> Self
pub fn new(width: usize, height: usize) -> Self
Creates a new image filled with a black pixel color.
Sourcepub fn from_color(width: usize, height: usize, color: Pixel) -> Self
pub fn from_color(width: usize, height: usize, color: Pixel) -> Self
Creates an image filled with a single color.
Sourcepub fn from_pixels(width: usize, height: usize, pixels: Vec<Pixel>) -> Self
pub fn from_pixels(width: usize, height: usize, pixels: Vec<Pixel>) -> Self
Creates an image from a flat pixel buffer.
Sourcepub fn from_pixel_fn(
width: usize,
height: usize,
pixel_fn: impl FnMut(usize, usize) -> Pixel,
) -> Self
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.
Sourcepub fn open(path: impl AsRef<Path>) -> Result<Self>
pub fn open(path: impl AsRef<Path>) -> Result<Self>
Opens an image from the given path using the binary P6 PPM format.
Sourcepub fn save(&self, path: impl AsRef<Path>) -> Result<()>
pub fn save(&self, path: impl AsRef<Path>) -> Result<()>
Saves the image to the given path as a binary P6 PPM file.
Sourcepub fn from_file(filename: &str) -> Result<Self>
pub fn from_file(filename: &str) -> Result<Self>
Loads an image from a file using the file name string.
Sourcepub fn to_file(&self, filename: &str) -> Result<()>
pub fn to_file(&self, filename: &str) -> Result<()>
Saves this image to a file using the file name string.
Sourcepub fn from_image(image: &Self) -> Self
pub fn from_image(image: &Self) -> Self
Clones an image from an existing one.
Trait Implementations§
impl Eq for Image
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more