Struct tiny_skia::Mask

source ·
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

source

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.

source

pub fn from_pixmap(pixmap: PixmapRef<'_>, mask_type: MaskType) -> Self

Creates a new mask from a PixmapRef.

source

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.

source

pub fn width(&self) -> u32

Returns mask’s width.

source

pub fn height(&self) -> u32

Returns mask’s height.

source

pub fn data(&self) -> &[u8]

Returns the internal data.

source

pub fn data_mut(&mut self) -> &mut [u8]

Returns the mutable internal data.

source

pub fn decode_png(data: &[u8]) -> Result<Self, DecodingError>

Loads a PNG file into a Mask.

Only grayscale images are supported.

source

pub fn load_png<P: AsRef<Path>>(path: P) -> Result<Self, DecodingError>

Loads a PNG file into a Mask.

Only grayscale images are supported.

source

pub fn encode_png(&self) -> Result<Vec<u8>, EncodingError>

Encodes mask into a PNG data.

source

pub fn save_png<P: AsRef<Path>>(&self, path: P) -> Result<(), EncodingError>

Saves mask as a PNG file.

source

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().

source

pub fn intersect_path( &mut self, path: &Path, fill_rule: FillRule, anti_alias: bool, transform: Transform, )

Intersects the provided path with the current clipping path.

A temporary mask with the same size as the current one will be created.

source

pub fn invert(&mut self)

Inverts the mask.

source

pub fn clear(&mut self)

Clears the mask.

Zero-fills the internal data buffer.

Trait Implementations§

source§

impl Clone for Mask

source§

fn clone(&self) -> Mask

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for Mask

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl PartialEq for Mask

source§

fn eq(&self, other: &Mask) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

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> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> CloneToUninit for T
where T: Clone,

source§

default unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.