Skip to main content

MaskFixed

Struct MaskFixed 

Source
pub struct MaskFixed<const W: usize, const H: usize, const MASK_N: usize> {
    pub bits: [u8; MASK_N],
}
Expand description

A packed binary visibility mask with one bit per image pixel.

Set bits are drawn and clear bits are transparent. Create a mask from an Image888Fixed with Image888Fixed::to_mask_magenta, then pass it to MaskedDrawable::draw_masked.

§Example

use device_envoy_core::{
    UnwrapInfallible,
    cyd::{
        Cyd, CydDisplay,
        display::{
            CydFrame, Image565Fixed, Image888Fixed, MaskFixed, MaskedDrawable,
            mask_byte_count, tga,
        },
    },
};
use embedded_graphics::{Drawable, prelude::Point};

const SOURCE: Image888Fixed<45, 73, { 45 * 73 }> = tga!(concat!(
    env!("CARGO_MANIFEST_DIR"),
    "/docs/assets/cyd_fill_contiguous.tga"
));
const IMAGE: Image565Fixed<45, 73, { 45 * 73 }> = SOURCE.to_565();
const MASK: MaskFixed<45, 73, { mask_byte_count(45, 73) }> =
    SOURCE.to_mask_magenta();

async fn draw<C: Cyd>(cyd: &mut C) -> Result<(), C::Error> {
    let display = cyd.display();
    let mut frame = display.full_frame_mut();
    IMAGE
        .at(Point::new(80, 84))
        .draw(&mut frame)
        .unwrap_infallible();
    IMAGE
        .at(Point::new(200, 84))
        .draw_masked(&MASK, &mut frame)
        .unwrap_infallible();
    frame.flush().await
}

assert!(!MASK.is_set(0));

The opaque RGB565 image is on the left. The masked drawing on the right skips the magenta background:

An opaque RGB565 image beside the same image drawn with a transparency mask

Fields§

§bits: [u8; MASK_N]

Row-major visibility bits, least-significant bit first within each byte.

Implementations§

Source§

impl<const W: usize, const H: usize, const MASK_N: usize> MaskFixed<W, H, MASK_N>

Source

pub const fn is_set(&self, index: usize) -> bool

Returns whether the row-major pixel at index is visible.

See the MaskFixed example.

Auto Trait Implementations§

§

impl<const W: usize, const H: usize, const MASK_N: usize> Freeze for MaskFixed<W, H, MASK_N>
where [u8; MASK_N]: Freeze,

§

impl<const W: usize, const H: usize, const MASK_N: usize> RefUnwindSafe for MaskFixed<W, H, MASK_N>

§

impl<const W: usize, const H: usize, const MASK_N: usize> Send for MaskFixed<W, H, MASK_N>
where [u8; MASK_N]: Send,

§

impl<const W: usize, const H: usize, const MASK_N: usize> Sync for MaskFixed<W, H, MASK_N>
where [u8; MASK_N]: Sync,

§

impl<const W: usize, const H: usize, const MASK_N: usize> Unpin for MaskFixed<W, H, MASK_N>
where [u8; MASK_N]: Unpin,

§

impl<const W: usize, const H: usize, const MASK_N: usize> UnsafeUnpin for MaskFixed<W, H, MASK_N>
where [u8; MASK_N]: UnsafeUnpin,

§

impl<const W: usize, const H: usize, const MASK_N: usize> UnwindSafe for MaskFixed<W, H, MASK_N>
where [u8; MASK_N]: 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> Az for T

Source§

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

Casts the value.
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<Src, Dst> CastFrom<Src> for Dst
where 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 Dst
where Src: CheckedCast<Dst>,

Source§

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

Casts the value.
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> 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 Dst
where Src: OverflowingCast<Dst>,

Source§

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

Casts the value.
Source§

impl<T> SaturatingAs for T

Source§

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

Casts the value.
Source§

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

Source§

fn saturating_cast_from(src: Src) -> Dst

Casts the value.
Source§

impl<T> StrictAs for T

Source§

fn strict_as<Dst>(self) -> Dst
where T: StrictCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> StrictCastFrom<Src> for Dst
where Src: StrictCast<Dst>,

Source§

fn strict_cast_from(src: Src) -> Dst

Casts the value.
Source§

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

Source§

type Error = !

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

impl<T> UnwrappedAs for T

Source§

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

Casts the value.
Source§

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

Source§

fn unwrapped_cast_from(src: Src) -> Dst

Casts the value.
Source§

impl<S, T> Upcast<T> for S
where T: UpcastFrom<S> + ?Sized, S: ?Sized,

Source§

fn upcast(&self) -> &T
where Self: ErasableGeneric, T: Sized + ErasableGeneric<Repr = Self::Repr>,

Perform a zero-cost type-safe upcast to a wider ref type within the Wasm bindgen generics type system. Read more
Source§

fn upcast_into(self) -> T
where Self: Sized + ErasableGeneric, T: Sized + ErasableGeneric<Repr = Self::Repr>,

Perform a zero-cost type-safe upcast to a wider type within the Wasm bindgen generics type system. Read more
Source§

impl<T> WrappingAs for T

Source§

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

Casts the value.
Source§

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

Source§

fn wrapping_cast_from(src: Src) -> Dst

Casts the value.