Struct ImageData

Source
pub struct ImageData<'a> { /* private fields */ }
Expand description

The image data representing the pixel data of an image.

Each pixel is represented by 4 bytes in RGBA (Red, Green, Blue, Alpha) format. The pixel data is stored in a linear array of bytes, where each pixel is represented by 4 bytes.

ยงExample

#[cfg(feature = "image")]
{
    use auto_palette::ImageData;

    let pixels = [
        255, 0, 0, 255, // Red
        0, 255, 0, 255, // Green
        0, 0, 255, 255, // Blue
        0, 0, 0, 255, // Black
    ];
    let image_data = ImageData::new(2, 2, &pixels).unwrap();
    assert_eq!(image_data.width(), 2);
    assert_eq!(image_data.height(), 2);
    assert_eq!(image_data.data(), &pixels);
}

Implementationsยง

Sourceยง

impl<'a> ImageData<'a>

Source

pub fn new(width: u32, height: u32, data: &'a [u8]) -> ImageResult<Self>

Creates a new ImageData with the given width, height, and pixel data.

ยงArguments
  • width - The width of the image data.
  • height - The height of the image data.
  • data - The pixel data of the image data.
ยงReturns

The ImageData with the given width, height, and pixel data.

ยงErrors

Returns an error if the length of the pixel data is not equal to width * height * 4.

Source

pub fn load<P>(path: P) -> ImageResult<Self>
where P: AsRef<Path>,

Loads the image data from the given path. The image data is loaded using the image crate.

ยงArguments
  • path - The path to the image file.
ยงReturns

The image data loaded from the given path.

ยงErrors

Returns an error if the image loading process fails. Returns an error if the color type of the image is not supported.

Source

pub fn is_empty(&self) -> bool

Checks whether the image data is empty.

ยงReturns

true if the image data is empty, false otherwise.

Source

pub fn width(&self) -> u32

Returns the width of the image data.

ยงReturns

The width of the image data.

Source

pub fn height(&self) -> u32

Returns the height of the image data.

ยงReturns

The height of the image data.

Source

pub fn area(&self) -> usize

Returns the area of the image data.

ยงReturns

The area of the image data.

Source

pub fn data(&self) -> &[u8] โ“˜

Returns the pixel data of the image data.

Each pixel is represented by 4 bytes in RGBA (Red, Green, Blue, Alpha) format.

ยงReturns

The pixel data of the image data.

Trait Implementationsยง

Sourceยง

impl<'a> Debug for ImageData<'a>

Sourceยง

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

Formats the value using the given formatter. Read more
Sourceยง

impl From<&ImageBuffer<Rgb<u8>, Vec<u8>>> for ImageData<'_>

Sourceยง

fn from(image: &RgbImage) -> Self

Converts to this type from the input type.
Sourceยง

impl From<&ImageBuffer<Rgba<u8>, Vec<u8>>> for ImageData<'_>

Sourceยง

fn from(image: &RgbaImage) -> Self

Converts to this type from the input type.
Sourceยง

impl TryFrom<&DynamicImage> for ImageData<'_>

Sourceยง

type Error = ImageError

The type returned in the event of a conversion error.
Sourceยง

fn try_from(image: &DynamicImage) -> Result<Self, Self::Error>

Performs the conversion.

Auto Trait Implementationsยง

ยง

impl<'a> Freeze for ImageData<'a>

ยง

impl<'a> RefUnwindSafe for ImageData<'a>

ยง

impl<'a> Send for ImageData<'a>

ยง

impl<'a> Sync for ImageData<'a>

ยง

impl<'a> Unpin for ImageData<'a>

ยง

impl<'a> UnwindSafe for ImageData<'a>

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.