pub struct Mask { /* private fields */ }
Expand description
A mask.
During drawing over Pixmap
, mask’s black (0) “pixels” would block rendering
and white (255) will allow it.
Anything in between is used for gradual masking and anti-aliasing.
Unlike Skia, we’re using just a simple 8bit alpha mask. It’s way slower, but easier to implement.
Implementations§
source§impl Mask
impl Mask
sourcepub fn new(width: u32, height: u32) -> Option<Self>
pub fn new(width: u32, height: u32) -> Option<Self>
Creates a new mask by taking ownership over a mask buffer.
The size needs to match the data provided.
sourcepub fn from_pixmap(pixmap: PixmapRef<'_>, mask_type: MaskType) -> Self
pub fn from_pixmap(pixmap: PixmapRef<'_>, mask_type: MaskType) -> Self
Creates a new mask from a PixmapRef
.
sourcepub fn from_vec(data: Vec<u8>, size: IntSize) -> Option<Self>
pub fn from_vec(data: Vec<u8>, size: IntSize) -> Option<Self>
Creates a new mask by taking ownership over a mask buffer.
The size needs to match the data provided.
sourcepub fn decode_png(data: &[u8]) -> Result<Self, DecodingError>
pub fn decode_png(data: &[u8]) -> Result<Self, DecodingError>
Loads a PNG file into a Mask
.
Only grayscale images are supported.
sourcepub fn load_png<P: AsRef<Path>>(path: P) -> Result<Self, DecodingError>
pub fn load_png<P: AsRef<Path>>(path: P) -> Result<Self, DecodingError>
Loads a PNG file into a Mask
.
Only grayscale images are supported.
sourcepub fn encode_png(&self) -> Result<Vec<u8>, EncodingError>
pub fn encode_png(&self) -> Result<Vec<u8>, EncodingError>
Encodes mask into a PNG data.
sourcepub fn save_png<P: AsRef<Path>>(&self, path: P) -> Result<(), EncodingError>
pub fn save_png<P: AsRef<Path>>(&self, path: P) -> Result<(), EncodingError>
Saves mask as a PNG file.
sourcepub fn fill_path(
&mut self,
path: &Path,
fill_rule: FillRule,
anti_alias: bool,
transform: Transform,
)
pub fn fill_path( &mut self, path: &Path, fill_rule: FillRule, anti_alias: bool, transform: Transform, )
Draws a filled path onto the mask.
In terms of RGB (no alpha) image, draws a white path on top of black mask.
Doesn’t reset the existing mask content and draws the path on top of existing data.
If the above behavior is undesired, Mask::clear()
should be called first.
This method is intended to be used for simple cases. For more complex masks
prefer Mask::from_pixmap()
.
Trait Implementations§
impl StructuralPartialEq for Mask
Auto Trait Implementations§
impl Freeze for Mask
impl RefUnwindSafe for Mask
impl Send for Mask
impl Sync for Mask
impl Unpin for Mask
impl UnwindSafe for Mask
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)