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: boolImplementations§
Source§impl<'a> Mask<'a>
impl<'a> Mask<'a>
Sourcepub fn new(
data: &'a [u8],
width: u32,
height: u32,
bits_per_pixel: u8,
packed: bool,
) -> Option<Mask<'a>>
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.
Sourcepub fn bits_per_pixel(&self) -> u8
pub fn bits_per_pixel(&self) -> u8
Returns the number of bits per pixel: 1, 2, 4 or 8.
Sourcepub fn decoded_len(&self) -> usize
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.
Sourcepub fn pixel(&self, x: u32, y: u32) -> Option<u8>
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.
Sourcepub fn pixels(&self) -> impl Iterator<Item = u8> + 'a
pub fn pixels(&self) -> impl Iterator<Item = u8> + 'a
Returns an iterator over the coverage of each pixel, row by row.
Sourcepub fn rows(&self) -> impl Iterator<Item = MaskRow<'a>> + 'a
pub fn rows(&self) -> impl Iterator<Item = MaskRow<'a>> + 'a
Returns an iterator over the rows, from top to bottom.
Sourcepub fn decode_into(&self, dst: &mut [u8]) -> bool
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.