pub struct Mask { /* private fields */ }resvg or tiny-skia only.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<Mask>
pub fn new(width: u32, height: u32) -> Option<Mask>
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) -> Mask
pub fn from_pixmap(pixmap: PixmapRef<'_>, mask_type: MaskType) -> Mask
Creates a new mask from a PixmapRef.
Sourcepub fn from_vec(data: Vec<u8>, size: IntSize) -> Option<Mask>
pub fn from_vec(data: Vec<u8>, size: IntSize) -> Option<Mask>
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<Mask, DecodingError>
pub fn decode_png(data: &[u8]) -> Result<Mask, DecodingError>
Loads a PNG file into a Mask.
Only grayscale images are supported.
Sourcepub fn load_png<P>(path: P) -> Result<Mask, DecodingError>
pub fn load_png<P>(path: P) -> Result<Mask, 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>(&self, path: P) -> Result<(), EncodingError>
pub fn save_png<P>(&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<S, T> CastApprox<T> for Swhere
T: ConvApprox<S>,
impl<S, T> CastApprox<T> for Swhere
T: ConvApprox<S>,
Source§fn try_cast_approx(self) -> Result<T, Error>
fn try_cast_approx(self) -> Result<T, Error>
Source§fn cast_approx(self) -> T
fn cast_approx(self) -> T
Source§impl<S, T> CastFloat<T> for Swhere
T: ConvFloat<S>,
impl<S, T> CastFloat<T> for Swhere
T: ConvFloat<S>,
Source§fn cast_trunc(self) -> T
fn cast_trunc(self) -> T
Source§fn cast_nearest(self) -> T
fn cast_nearest(self) -> T
Source§fn cast_floor(self) -> T
fn cast_floor(self) -> T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more