Skip to main content

Mask

Struct Mask 

Source
pub struct Mask<'a> {
    data: &'a [u8],
    width: u32,
    height: u32,
    bits_per_pixel: u8,
    packed: bool,
}
Expand description

A single channel coverage mask of 1, 2, 4 or 8 bits per pixel.

The data is kept in the table’s packing. The accessors decode it, so a caller does not need to know the bit depth or whether rows are padded.

Fields§

§data: &'a [u8]§width: u32§height: u32§bits_per_pixel: u8§packed: bool

Implementations§

Source§

impl<'a> Mask<'a>

Source

pub fn new( data: &'a [u8], width: u32, height: u32, bits_per_pixel: u8, packed: bool, ) -> Option<Mask<'a>>

Creates a view of data as width by height pixels of bits_per_pixel each.

In a packed mask, each row begins at the bit that follows the previous row. In an unpacked mask, each row is padded to a whole byte.

Returns None if the bit depth is not 1, 2, 4 or 8, or if data is too short.

Source

pub fn width(&self) -> u32

Returns the width in pixels.

Source

pub fn height(&self) -> u32

Returns the height in pixels.

Source

pub fn bits_per_pixel(&self) -> u8

Returns the number of bits per pixel: 1, 2, 4 or 8.

Source

pub fn is_packed(&self) -> bool

Returns true if rows are not padded to a whole byte.

Source

pub fn data(&self) -> &'a [u8] ⓘ

Returns the raw pixel data from the table.

Source

pub fn decoded_len(&self) -> usize

Returns the size in bytes of the decoded mask, one byte per pixel.

This is the length decode_into writes.

Source

pub fn is_empty(&self) -> bool

Returns true if there are no pixels.

Source

pub fn pixel(&self, x: u32, y: u32) -> Option<u8>

Returns the coverage of the pixel at column x of row y.

The value ranges from 0 to 255 for any bit depth.

Source

pub fn pixels(&self) -> impl Iterator<Item = u8> + 'a

Returns an iterator over the coverage of each pixel, row by row.

Source

pub fn rows(&self) -> impl Iterator<Item = MaskRow<'a>> + 'a

Returns an iterator over the rows, from top to bottom.

Source

pub fn decode_into(&self, dst: &mut [u8]) -> bool

Writes the coverage of each pixel to dst, row by row, one byte per pixel.

dst must hold at least decoded_len bytes, and any bytes past that are left as they were. Returns false, writing nothing, if dst is shorter.

Trait Implementations§

Source§

impl<'a> Clone for Mask<'a>

Source§

fn clone(&self) -> Mask<'a>

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl<'a> Copy for Mask<'a>

Auto Trait Implementations§

§

impl<'a> Freeze for Mask<'a>

§

impl<'a> RefUnwindSafe for Mask<'a>

§

impl<'a> Send for Mask<'a>

§

impl<'a> Sync for Mask<'a>

§

impl<'a> Unpin for Mask<'a>

§

impl<'a> UnsafeUnpin for Mask<'a>

§

impl<'a> UnwindSafe for Mask<'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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> ErasedDestructor for T
where T: 'static,

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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

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

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.