pub struct mask8x8 { /* private fields */ }Expand description
Implementations§
Source§impl mask8x8
impl mask8x8
Sourcepub const fn from_array(a: [bool; 8]) -> Self
pub const fn from_array(a: [bool; 8]) -> Self
Converts the given array into a mask8x8.
Sourcepub const fn from_bitmask_le(mask: u8) -> Self
pub const fn from_bitmask_le(mask: u8) -> Self
Converts the given bitmask into a mask8x8 by treating a set bit
as true and an unset bit as false. The least significant bit
appears in the first element.
let mask = mask8x8::from_bitmask_le(0b11001010);
assert_eq!(mask.to_array(), [false, true, false, true, false, false, true, true]);Sourcepub const fn from_bitmask_be(mask: u8) -> Self
pub const fn from_bitmask_be(mask: u8) -> Self
Converts the given bitmask into a mask8x8 by treating a set bit
as true and an unset bit as false. The least significant bit
appears in the last element.
let mask = mask8x8::from_bitmask_be(0b11001010);
assert_eq!(mask.to_array(), [true, true, false, false, true, false, true, false]);Sourcepub const fn to_array(self) -> [bool; 8]
pub const fn to_array(self) -> [bool; 8]
Converts the vector into an array of eight bool values.
Sourcepub const fn to_bitmask_le(self) -> u8
pub const fn to_bitmask_le(self) -> u8
Converts the vector into a bitmask where the first element is in the least significant bit.
Sourcepub const fn to_bitmask_be(self) -> u8
pub const fn to_bitmask_be(self) -> u8
Converts the vector into a bitmask where the first element is in the most significant bit.
Sourcepub const fn to_u8x8(self) -> u8x8
pub const fn to_u8x8(self) -> u8x8
Returns a u8x8 representation of the mask where true elements
are represented as 0x01 and false elements are represented as 0x00.
Sourcepub const fn to_u8x8_with(self, v: u8) -> u8x8
pub const fn to_u8x8_with(self, v: u8) -> u8x8
Returns a u8x8 representation of the mask where true elements
are represented as v and false elements are represented as 0x00.
Sourcepub const fn or(self, other: Self) -> Self
pub const fn or(self, other: Self) -> Self
Computes a logical OR result for each element across both vectors.
Sourcepub const fn and(self, other: Self) -> Self
pub const fn and(self, other: Self) -> Self
Computes a logical AND result for each element across both vectors.
Sourcepub const fn select(self, true_value: u8, false_value: u8) -> u8x8
pub const fn select(self, true_value: u8, false_value: u8) -> u8x8
Builds a u8x8 by selecting one of the two given values for each
element corresponding to the elements in the mask.
For example, this can be useful when expanding a one-bit-per-pixel
bitmap into eight palette indices represented as u8, as part of
rendering an indexed-color pixmap:
let bitmap = 0b10101100;
let mask = mask8x8::from_bitmask_be(bitmap);
let fg_color = 0xff;
let bg_color = 0x01;
let pixels = mask.select(fg_color, bg_color);
assert_eq!(pixels.to_array(), [0xff, 0x01, 0xff, 0x01, 0xff, 0xff, 0x01, 0x01]);Sourcepub const fn count_true(self) -> u32
pub const fn count_true(self) -> u32
Returns the number of elements in the mask that are set to true.
Sourcepub const fn count_false(self) -> u32
pub const fn count_false(self) -> u32
Returns the number of elements in the mask that are set to false.
Trait Implementations§
Source§impl BitAndAssign for mask8x8
impl BitAndAssign for mask8x8
Source§fn bitand_assign(&mut self, rhs: Self)
fn bitand_assign(&mut self, rhs: Self)
Implements the &= operator using Self::and.
Source§impl BitOrAssign for mask8x8
impl BitOrAssign for mask8x8
Source§fn bitor_assign(&mut self, rhs: Self)
fn bitor_assign(&mut self, rhs: Self)
Implements the |= operator using Self::or.