embedded_graphics::image

Struct ImageRaw

Source
pub struct ImageRaw<'a, C, BO = BigEndian>
where C: PixelColor + From<<C as PixelColor>::Raw>, BO: ByteOrder,
{ /* private fields */ }
Expand description

An image constructed from a slice of raw pixel data.

The ImageRaw struct can be used to construct an image from a slice of raw image data. The storage format is determined by the PixelColor type C and the ByteOrder BO. The byteorder doesn’t need to be specified for colors which aren’t stored in multiple bytes.

For color types with less than 8 bits per pixels the start of each row is aligned to the next whole byte.

Details about the conversion of raw data to color types are explained in the raw module documentation.

As ImageRaw does not implement [Drawable], it cannot be directly drawn to a supported display. The Image struct should be used to wrap an ImageRaw to make it drawable.

§Examples

§Draw a 1BPP image

This example creates an image from 1 bit per pixel data.

use embedded_graphics::{
    image::{Image, ImageRaw},
    pixelcolor::BinaryColor,
    prelude::*,
};

/// Image data with 12 x 5 pixels.
/// The data for each row is 12 bits long and is padded with zeros on the
/// end because each row needs to contain a whole number of bytes.
#[rustfmt::skip]
const DATA: &[u8] = &[
    0b11101111, 0b0101_0000,
    0b10001000, 0b0101_0000,
    0b11101011, 0b0101_0000,
    0b10001001, 0b0101_0000,
    0b11101111, 0b0101_0000,
];

// The type annotation `ImageRaw<BinaryColor>` is used to specify the format
// of the stored raw data (`PixelColor::Raw`) and which color type the
// raw data gets converted into.
let raw_image: ImageRaw<BinaryColor> = ImageRaw::new(DATA, 12, 5);

let image: Image<_, BinaryColor> = Image::new(&raw_image, Point::zero());

let mut display = Display::default();

image.draw(&mut display)?;

§Draw an image that uses multibyte pixel encoding

Colors with more than one byte per pixel need an additional type annotation for the byte order. For convenience, the ImageRawBE and ImageRawLE type aliases can be used to abbreviate the type.

use embedded_graphics::{
    image::{Image, ImageRaw, ImageRawBE, ImageRawLE},
    pixelcolor::{
        raw::{BigEndian, LittleEndian},
        Rgb565, Rgb888,
    },
    prelude::*,
};

// Rgb888 image with 24 bits per pixel and big endian byte order
let image1: ImageRawBE<Rgb888> = ImageRaw::new(DATA, 8, 8);
// or:
let image2: ImageRaw<Rgb888, BigEndian> = ImageRaw::new(DATA, 8, 8);

// Rgb565 image with 16 bits per pixel and little endian byte order
let image1: ImageRawLE<Rgb565> = ImageRaw::new(DATA, 16, 6);
// or:
let image2: ImageRaw<Rgb565, LittleEndian> = ImageRaw::new(DATA, 16, 6);

Implementations§

Source§

impl<'a, C, BO> ImageRaw<'a, C, BO>
where C: PixelColor + From<<C as PixelColor>::Raw>, BO: ByteOrder,

Source

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

Creates a new image.

§Panics

If data doesn’t have the correct length.

Trait Implementations§

Source§

impl<'a, C, BO> Clone for ImageRaw<'a, C, BO>
where C: PixelColor + From<<C as PixelColor>::Raw> + Clone, BO: ByteOrder + Clone,

Source§

fn clone(&self) -> ImageRaw<'a, C, BO>

Returns a copy of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl<'a, C, BO> Debug for ImageRaw<'a, C, BO>
where C: PixelColor + From<<C as PixelColor>::Raw> + Debug, BO: ByteOrder + Debug,

Source§

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

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

impl<'a, C, BO> Hash for ImageRaw<'a, C, BO>
where C: PixelColor + From<<C as PixelColor>::Raw> + Hash, BO: ByteOrder + Hash,

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl<C, BO> ImageDimensions for ImageRaw<'_, C, BO>
where C: PixelColor + From<<C as PixelColor>::Raw>, BO: ByteOrder,

Source§

fn width(&self) -> u32

Get the width in pixels of an image
Source§

fn height(&self) -> u32

Get the height in pixels of an image
Source§

impl<'a, 'b, C, BO> IntoIterator for &'a ImageRaw<'b, C, BO>
where C: PixelColor + From<<C as PixelColor>::Raw>, BO: ByteOrder, RawDataIter<'b, C::Raw, BO>: Iterator<Item = C::Raw>,

Source§

type Item = Pixel<C>

The type of the elements being iterated over.
Source§

type IntoIter = ImageRawIterator<'a, 'b, C, BO>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl<'a, 'b, C, BO> IntoPixelIter<C> for &'a ImageRaw<'b, C, BO>
where C: PixelColor + From<<C as PixelColor>::Raw>, BO: ByteOrder, RawDataIter<'b, C::Raw, BO>: Iterator<Item = C::Raw>,

Source§

type PixelIterator = ImageRawIterator<'a, 'b, C, BO>

Iterator over pixels in the image
Source§

fn pixel_iter(self) -> Self::PixelIterator

Get an iterator over the pixels of the image
Source§

impl<'a, C, BO> Ord for ImageRaw<'a, C, BO>
where C: PixelColor + From<<C as PixelColor>::Raw> + Ord, BO: ByteOrder + Ord,

Source§

fn cmp(&self, other: &ImageRaw<'a, C, BO>) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl<'a, C, BO> PartialEq for ImageRaw<'a, C, BO>
where C: PixelColor + From<<C as PixelColor>::Raw> + PartialEq, BO: ByteOrder + PartialEq,

Source§

fn eq(&self, other: &ImageRaw<'a, C, BO>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<'a, C, BO> PartialOrd for ImageRaw<'a, C, BO>

Source§

fn partial_cmp(&self, other: &ImageRaw<'a, C, BO>) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

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

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

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

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

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

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

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

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl<'a, C, BO> Copy for ImageRaw<'a, C, BO>
where C: PixelColor + From<<C as PixelColor>::Raw> + Copy, BO: ByteOrder + Copy,

Source§

impl<'a, C, BO> Eq for ImageRaw<'a, C, BO>
where C: PixelColor + From<<C as PixelColor>::Raw> + Eq, BO: ByteOrder + Eq,

Source§

impl<'a, C, BO> StructuralPartialEq for ImageRaw<'a, C, BO>
where C: PixelColor + From<<C as PixelColor>::Raw>, BO: ByteOrder,

Auto Trait Implementations§

§

impl<'a, C, BO> Freeze for ImageRaw<'a, C, BO>

§

impl<'a, C, BO> RefUnwindSafe for ImageRaw<'a, C, BO>

§

impl<'a, C, BO> Send for ImageRaw<'a, C, BO>
where C: Send, BO: Send,

§

impl<'a, C, BO> Sync for ImageRaw<'a, C, BO>
where C: Sync, BO: Sync,

§

impl<'a, C, BO> Unpin for ImageRaw<'a, C, BO>
where C: Unpin, BO: Unpin,

§

impl<'a, C, BO> UnwindSafe for ImageRaw<'a, C, BO>
where C: UnwindSafe, BO: UnwindSafe,

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, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. 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.

Layout§

Note: Most layout information is completely unstable and may even differ between compilations. The only exception is types with certain repr(...) attributes. Please see the Rust Reference's “Type Layout” chapter for details on type layout guarantees.

Size: 16 bytes