pub struct Mask { /* private fields */ }Expand description
A 2-D boolean bitmask for a raster region.
Mask uses bit-packed u64 words (64 pixels per word) for memory
efficiency. See the module documentation for the storage and
semantic conventions.
§Examples
use oxigdal_core::buffer::Mask;
let mut mask = Mask::new(10, 10); // all valid (0)
mask.set(3, 3, true); // mark (3,3) as nodata
assert!(mask.get(3, 3));
assert_eq!(mask.count_set(), 1);Implementations§
Source§impl Mask
impl Mask
Sourcepub fn new(width: usize, height: usize) -> Self
pub fn new(width: usize, height: usize) -> Self
Creates a new mask with all bits unset (all pixels valid).
A mask with width == 0 or height == 0 is valid and has no pixels.
Sourcepub fn new_filled(width: usize, height: usize) -> Self
pub fn new_filled(width: usize, height: usize) -> Self
Creates a new mask with all bits set (all pixels invalid/nodata).
The tail-word invariant is enforced — high bits of the last word are always zero even after the fill.
Sourcepub fn from_slice(width: usize, height: usize, values: &[bool]) -> Result<Self>
pub fn from_slice(width: usize, height: usize, values: &[bool]) -> Result<Self>
Constructs a mask from a bool slice.
The slice is interpreted in row-major order: values[y * width + x]
is the mask value for pixel (x, y). true → bit set (nodata).
§Errors
Returns OxiGdalError::InvalidParameter if values.len() != width * height.
Source§impl Mask
impl Mask
Sourcepub fn pixel_count(&self) -> usize
pub fn pixel_count(&self) -> usize
Total number of pixels (width * height).
Source§impl Mask
impl Mask
Source§impl Mask
impl Mask
Sourcepub fn and_assign(&mut self, other: &Mask) -> Result<()>
pub fn and_assign(&mut self, other: &Mask) -> Result<()>
Applies bitwise AND with other in place.
§Errors
Returns OxiGdalError::InvalidParameter if dimensions differ.
Sourcepub fn or_assign(&mut self, other: &Mask) -> Result<()>
pub fn or_assign(&mut self, other: &Mask) -> Result<()>
Applies bitwise OR with other in place.
§Errors
Returns OxiGdalError::InvalidParameter if dimensions differ.
Sourcepub fn not_in_place(&mut self)
pub fn not_in_place(&mut self)
Applies bitwise NOT in place.
The tail-word invariant is re-established after inversion.
Sourcepub fn xor_assign(&mut self, other: &Mask) -> Result<()>
pub fn xor_assign(&mut self, other: &Mask) -> Result<()>
Applies bitwise XOR with other in place.
§Errors
Returns OxiGdalError::InvalidParameter if dimensions differ.
Sourcepub fn and(&self, other: &Mask) -> Result<Mask>
pub fn and(&self, other: &Mask) -> Result<Mask>
Returns a new mask that is the bitwise AND of self and other.
§Errors
Returns OxiGdalError::InvalidParameter if dimensions differ.
Source§impl Mask
impl Mask
Sourcepub fn count_unset(&self) -> usize
pub fn count_unset(&self) -> usize
Number of bits that are unset (pixels that are valid).
Source§impl Mask
impl Mask
Sourcepub fn set_positions(&self) -> impl Iterator<Item = (usize, usize)> + '_
pub fn set_positions(&self) -> impl Iterator<Item = (usize, usize)> + '_
Returns an iterator over (x, y) coordinates of all set bits
(masked/nodata pixels).
Iterates in row-major order.
Source§impl Mask
impl Mask
Sourcepub fn from_nodata_f32(
data: &[f32],
width: usize,
height: usize,
nodata: f32,
) -> Result<Self>
pub fn from_nodata_f32( data: &[f32], width: usize, height: usize, nodata: f32, ) -> Result<Self>
Builds a nodata mask from an f32 slice.
A pixel is marked invalid if its value is NaN or exactly equals
nodata (bitwise-exact comparison after handling NaN).
§Errors
Returns OxiGdalError::InvalidParameter if data.len() != width * height.
Sourcepub fn from_nodata_f64(
data: &[f64],
width: usize,
height: usize,
nodata: f64,
) -> Result<Self>
pub fn from_nodata_f64( data: &[f64], width: usize, height: usize, nodata: f64, ) -> Result<Self>
Builds a nodata mask from an f64 slice.
A pixel is marked invalid if its value is NaN or exactly equals
nodata.
§Errors
Returns OxiGdalError::InvalidParameter if data.len() != width * height.
Sourcepub fn from_nodata_i32(
data: &[i32],
width: usize,
height: usize,
nodata: i32,
) -> Result<Self>
pub fn from_nodata_i32( data: &[i32], width: usize, height: usize, nodata: i32, ) -> Result<Self>
Builds a nodata mask from an i32 slice.
A pixel is marked invalid if its value exactly equals nodata.
§Errors
Returns OxiGdalError::InvalidParameter if data.len() != width * height.
Sourcepub fn from_nodata_u8(
data: &[u8],
width: usize,
height: usize,
nodata: u8,
) -> Result<Self>
pub fn from_nodata_u8( data: &[u8], width: usize, height: usize, nodata: u8, ) -> Result<Self>
Builds a nodata mask from a u8 slice.
A pixel is marked invalid if its value exactly equals nodata.
§Errors
Returns OxiGdalError::InvalidParameter if data.len() != width * height.
Source§impl Mask
impl Mask
Sourcepub fn to_bool_vec(&self) -> Vec<bool>
pub fn to_bool_vec(&self) -> Vec<bool>
Converts the mask to a Vec<bool> in row-major order.
The returned vector has length pixel_count(). true at index
y * width + x means pixel (x, y) is invalid / nodata.
Source§impl Mask
impl Mask
Sourcepub fn apply_to_f32(&self, data: &mut [f32], nodata_value: f32)
pub fn apply_to_f32(&self, data: &mut [f32], nodata_value: f32)
Replaces every masked pixel in data with nodata_value.
Operates on an f32 slice of the same shape as the mask.
Pixels where the mask bit is set (invalid) are written with
nodata_value.
Sourcepub fn apply_to_f64(&self, data: &mut [f64], nodata_value: f64)
pub fn apply_to_f64(&self, data: &mut [f64], nodata_value: f64)
Replaces every masked pixel in data with nodata_value.
Operates on an f64 slice of the same shape as the mask.
Sourcepub fn apply_to_u8(&self, data: &mut [u8], nodata_value: u8)
pub fn apply_to_u8(&self, data: &mut [u8], nodata_value: u8)
Replaces every masked pixel in data with nodata_value.
Operates on a u8 slice of the same shape as the mask.
Sourcepub fn apply_to_i32(&self, data: &mut [i32], nodata_value: i32)
pub fn apply_to_i32(&self, data: &mut [i32], nodata_value: i32)
Replaces every masked pixel in data with nodata_value.
Operates on an i32 slice of the same shape as the mask.