Struct embedded_graphics::image::ImageRaw[][src]

pub struct ImageRaw<'a, C, BO = BigEndian> where
    C: PixelColor + From<<C as PixelColor>::Raw>,
    BO: ByteOrder
{ /* fields omitted */ }
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

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

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

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.

impl<'a> ImageRaw<'a, BinaryColor>[src]

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

Creates a new binary image.

Due to const fn limitations the new method cannot be used in const contexts. This method provides a workaround to create ImageRaws with BinaryColor images.

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.

Panics

This function panics if width == 0.

Trait Implementations

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

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

Returns a copy of the value. Read more

fn clone_from(&mut self, source: &Self)1.0.0[src]

Performs copy-assignment from source. Read more

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

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

Formats the value using the given formatter. Read more

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

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

Feeds this value into the given Hasher. Read more

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

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

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>, 
[src]

type Color = C

The color type.

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

Draws the entire image to the target. Read more

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

Draws a part of the image to the target. Read more

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

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

This method returns an Ordering between self and other. Read more

#[must_use]
fn max(self, other: Self) -> Self
1.21.0[src]

Compares and returns the maximum of two values. Read more

#[must_use]
fn min(self, other: Self) -> Self
1.21.0[src]

Compares and returns the minimum of two values. Read more

#[must_use]
fn clamp(self, min: Self, max: Self) -> Self
1.50.0[src]

Restrict a value to a certain interval. Read more

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

fn size(&self) -> Size[src]

Returns the size of the bounding box.

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

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

This method tests for self and other values to be equal, and is used by ==. Read more

fn ne(&self, other: &ImageRaw<'a, C, BO>) -> bool[src]

This method tests for !=.

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

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

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

#[must_use]
fn lt(&self, other: &Rhs) -> bool
1.0.0[src]

This method tests less than (for self and other) and is used by the < operator. Read more

#[must_use]
fn le(&self, other: &Rhs) -> bool
1.0.0[src]

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

#[must_use]
fn gt(&self, other: &Rhs) -> bool
1.0.0[src]

This method tests greater than (for self and other) and is used by the > operator. Read more

#[must_use]
fn ge(&self, other: &Rhs) -> bool
1.0.0[src]

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

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

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

impl<'a, C, BO> StructuralEq for ImageRaw<'a, C, BO> where
    C: PixelColor + From<<C as PixelColor>::Raw>,
    BO: ByteOrder
[src]

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

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

impl<T> Any for T where
    T: 'static + ?Sized
[src]

pub fn type_id(&self) -> TypeId[src]

Gets the TypeId of self. Read more

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

pub fn borrow(&self) -> &T[src]

Immutably borrows from an owned value. Read more

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

pub fn borrow_mut(&mut self) -> &mut T[src]

Mutably borrows from an owned value. Read more

impl<T> Dimensions for T where
    T: OriginDimensions
[src]

pub fn bounding_box(&self) -> Rectangle[src]

Returns the bounding box.

impl<T> From<T> for T[src]

pub fn from(t: T) -> T[src]

Performs the conversion.

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

pub fn into(self) -> U[src]

Performs the conversion.

impl<Src, Dst> LosslessTryInto<Dst> for Src where
    Dst: LosslessTryFrom<Src>, 
[src]

pub fn lossless_try_into(self) -> Option<Dst>[src]

Performs the conversion.

impl<Src, Dst> LossyInto<Dst> for Src where
    Dst: LossyFrom<Src>, 
[src]

pub fn lossy_into(self) -> Dst[src]

Performs the conversion.

impl<T> Same<T> for T

type Output = T

Should always be Self

impl<T> Scalar for T where
    T: Copy + PartialEq<T> + Debug + Any
[src]

pub fn inlined_clone(&self) -> T[src]

Performance hack: Clone doesn’t get inlined for Copy types in debug mode, so make it inline anyway.

fn is<T>() -> bool where
    T: Scalar
[src]

Tests if Self the same as the type T Read more

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

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

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

pub fn is_in_subset(&self) -> bool

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

pub fn to_subset_unchecked(&self) -> SS

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

pub fn from_subset(element: &SS) -> SP

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

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

pub fn to_owned(&self) -> T[src]

Creates owned data from borrowed data, usually by cloning. Read more

pub fn clone_into(&self, target: &mut T)[src]

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

Uses borrowed data to replace owned data, usually by cloning. Read more

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>[src]

Performs the conversion.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

pub fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>[src]

Performs the conversion.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>, 

pub fn vzip(self) -> V