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.

To draw an ImageRaw object it needs to be wrapped in an Image object.

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::*,
};

/// 12 x 5 pixel image with 1 bit per pixel.
/// 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 image dimensions and the format of the stored raw data must be specified
// when the `new` function is called. The data format can, for example, be specified
// by using the turbofish syntax. For the image dimensions only the width must be
// passed to the `new` function. The image height will be calculated based on the
// length of the image data and the data format.
let raw_image = ImageRaw::<BinaryColor>::new(DATA, 12);

let image = 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>::new(DATA, 8);
// or:
let image2 = ImageRaw::<Rgb888, BigEndian>::new(DATA, 8);

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

Implementations§

source§

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

source

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

Creates a new image.

Only the width of the image needs to be specified. The height of the image will be calculated based on the length of the given image data. If the length of the image data isn’t an integer multiple of the data length for a single row the last partial row will be ignored.

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> Format for ImageRaw<'a, C, BO>where C: PixelColor + From<<C as PixelColor>::Raw> + Format, BO: ByteOrder + Format,

source§

fn format(&self, f: Formatter<'_>)

Writes the defmt representation of self to fmt.
source§

impl<'a, C, BO> GetPixel for ImageRaw<'a, C, BO>where C: PixelColor + From<<C as PixelColor>::Raw>, BO: ByteOrder, RawDataSlice<'a, C::Raw, BO>: IntoIterator<Item = C::Raw>,

§

type Color = C

The color type.
source§

fn pixel(&self, p: Point) -> Option<Self::Color>

Gets the color of a pixel. 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<'a, C, BO> ImageDrawable for ImageRaw<'a, C, BO>where C: PixelColor + From<<C as PixelColor>::Raw>, BO: ByteOrder, RawDataSlice<'a, C::Raw, BO>: IntoIterator<Item = C::Raw>,

§

type Color = C

The color type.
source§

fn draw<D>(&self, target: &mut D) -> Result<(), D::Error>where D: DrawTarget<Color = C>,

Draws the entire image to the target. Read more
source§

fn draw_sub_image<D>( &self, target: &mut D, area: &Rectangle ) -> Result<(), D::Error>where D: DrawTarget<Color = Self::Color>,

Draws a part of the image to the target. Read more
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) -> Selfwhere Self: Sized,

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

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

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

fn clamp(self, min: Self, max: Self) -> Selfwhere Self: Sized + PartialOrd<Self>,

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

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

source§

fn size(&self) -> Size

Returns the size of the bounding box.
source§

impl<'a, C, BO> PartialEq<ImageRaw<'a, C, BO>> 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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

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

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

This method 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

This method 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

This method 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

This method 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> StructuralEq for ImageRaw<'a, C, BO>where C: PixelColor + From<<C as PixelColor>::Raw>, BO: ByteOrder,

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> RefUnwindSafe for ImageRaw<'a, C, BO>where BO: RefUnwindSafe, C: RefUnwindSafe,

§

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

§

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

§

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

§

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

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Az for T

source§

fn az<Dst>(self) -> Dstwhere T: Cast<Dst>,

Casts the value.
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<Src, Dst> CastFrom<Src> for Dstwhere Src: Cast<Dst>,

source§

fn cast_from(src: Src) -> Dst

Casts the value.
source§

impl<T> CheckedAs for T

source§

fn checked_as<Dst>(self) -> Option<Dst>where T: CheckedCast<Dst>,

Casts the value.
source§

impl<Src, Dst> CheckedCastFrom<Src> for Dstwhere Src: CheckedCast<Dst>,

source§

fn checked_cast_from(src: Src) -> Option<Dst>

Casts the value.
source§

impl<T> Dimensions for Twhere T: OriginDimensions,

source§

fn bounding_box(&self) -> Rectangle

Returns the bounding box.
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> ImageDrawableExt for Twhere T: ImageDrawable,

source§

fn sub_image(&self, area: &Rectangle) -> SubImage<'_, T>

Returns a sub image of this image drawable. Read more
source§

impl<T, U> Into<U> for Twhere 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<Src, Dst> LosslessTryInto<Dst> for Srcwhere Dst: LosslessTryFrom<Src>,

source§

fn lossless_try_into(self) -> Option<Dst>

Performs the conversion.
source§

impl<Src, Dst> LossyInto<Dst> for Srcwhere Dst: LossyFrom<Src>,

source§

fn lossy_into(self) -> Dst

Performs the conversion.
source§

impl<T> OverflowingAs for T

source§

fn overflowing_as<Dst>(self) -> (Dst, bool)where T: OverflowingCast<Dst>,

Casts the value.
source§

impl<Src, Dst> OverflowingCastFrom<Src> for Dstwhere Src: OverflowingCast<Dst>,

source§

fn overflowing_cast_from(src: Src) -> (Dst, bool)

Casts the value.
source§

impl<T> Same<T> for T

§

type Output = T

Should always be Self
source§

impl<T> SaturatingAs for T

source§

fn saturating_as<Dst>(self) -> Dstwhere T: SaturatingCast<Dst>,

Casts the value.
source§

impl<Src, Dst> SaturatingCastFrom<Src> for Dstwhere Src: SaturatingCast<Dst>,

source§

fn saturating_cast_from(src: Src) -> Dst

Casts the value.
§

impl<SS, SP> SupersetOf<SS> for SPwhere SS: SubsetOf<SP>,

§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

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 Twhere U: TryFrom<T>,

§

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

impl<T> UnwrappedAs for T

source§

fn unwrapped_as<Dst>(self) -> Dstwhere T: UnwrappedCast<Dst>,

Casts the value.
source§

impl<Src, Dst> UnwrappedCastFrom<Src> for Dstwhere Src: UnwrappedCast<Dst>,

source§

fn unwrapped_cast_from(src: Src) -> Dst

Casts the value.
source§

impl<T> WrappingAs for T

source§

fn wrapping_as<Dst>(self) -> Dstwhere T: WrappingCast<Dst>,

Casts the value.
source§

impl<Src, Dst> WrappingCastFrom<Src> for Dstwhere Src: WrappingCast<Dst>,

source§

fn wrapping_cast_from(src: Src) -> Dst

Casts the value.
source§

impl<T> Scalar for Twhere T: 'static + Clone + PartialEq<T> + Debug,