Struct Image

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

A struct that provides image handling functionality

§Examples

// Open and display an image
use glance_core::img::Image;

if let Ok(img) = Image::open("path/to/image.jpg") {
    let _ = img.display("Example Image");
}

Implementations§

Source§

impl Image

Source

pub fn pixels(&self) -> PixelIter<'_>

Source

pub fn pixels_mut(&mut self) -> PixelIterMut<'_>

Source

pub fn par_pixels( &self, ) -> impl ParallelIterator<Item = (usize, usize, [u8; 4])>

Source

pub fn par_pixels_mut( &mut self, ) -> impl ParallelIterator<Item = (usize, usize, &mut [u8; 4])>

Source§

impl Image

Source

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

Opens an image from the given path.

Returns an error if the file does not exist or cannot be decoded. Supports all formats recognized by the image crate.

Source

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

Saves an image to the given path

Returns an error if the file cannot be created or buffer is invalid. Format is recognized from file extension (see image::ImageBuffer::save for more info).

Source

pub fn new(width: u32, height: u32, data: Vec<u8>) -> Result<Self>

Creates a new Image from width, height, and a data buffer (must be RGBA, widthheight4 bytes).

Source

pub fn display(&self, title: &str) -> Result<()>

Displays the image (as RGBA8) in a window until Escape is pressed. Returns an error if the window cannot be created. The window runs at 1 FPS to minimize CPU usage. Uses minifb for cross-platform windowing.

Source

pub fn get_pixel(&self, position: [u32; 2]) -> Result<[u8; 4]>

Gets the color of a pixel. Top left is treated as origin. Right is positive x, down is positive y.

Source

pub fn set_pixel(&mut self, position: [u32; 2], color: [u8; 4]) -> Result<()>

Sets a pixel to the given color. Top left is treated as origin, x-axis goes horizontally.

Source

pub fn alpha_blend_pixel( &mut self, position: [u32; 2], color: [u8; 4], ) -> Result<()>

Linearly interpolate a pixel color with the given color

Source

pub fn draw<D: Drawable>(&mut self, shape: D) -> Result<()>

Draw a shape (any struct that implements the [drawing::traits::Drawable] trait)

Source

pub fn is_empty(&self) -> bool

Returns true if the image contains no pixel data.

Source

pub fn dimensions(&self) -> [u32; 2]

Returns the image dimensions as (width, height).

Auto Trait Implementations§

§

impl Freeze for Image

§

impl RefUnwindSafe for Image

§

impl Send for Image

§

impl Sync for Image

§

impl Unpin 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> 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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. 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.