Skip to main content

AlphaMask

Struct AlphaMask 

Source
pub struct AlphaMask { /* private fields */ }
Expand description

An 8-bit coverage plane: one byte per pixel, 255 fully opaque.

This is both a soft mask (ISO 32000 §11.6.5) and a clip mask. It is always sized and aligned to the device it applies to, because a mismatched mask is silently ignored by vello_cpu and merely warned about by tiny-skia — it fails open.

use pdfrum_render::AlphaMask;

let mask = AlphaMask::filled(2, 2, 128);
assert_eq!((mask.width(), mask.height()), (2, 2));
// One byte per pixel; 255 is fully opaque.
assert_eq!(mask.data(), &[128; 4]);

Implementations§

Source§

impl AlphaMask

Source

pub fn new(width: u32, height: u32) -> Self

A fully transparent (all-zero) mask.

use pdfrum_render::AlphaMask;

// Fully transparent: all zero.
assert_eq!(AlphaMask::new(2, 1).data(), &[0, 0]);
Source

pub fn filled(width: u32, height: u32, value: u8) -> Self

A mask with every byte set to value.

use pdfrum_render::AlphaMask;

assert_eq!(AlphaMask::filled(2, 1, 255).data(), &[255, 255]);
Source

pub fn from_vec(width: u32, height: u32, data: Vec<u8>) -> Option<Self>

Wrap an existing coverage plane, or None on a size mismatch.

use pdfrum_render::AlphaMask;

assert!(AlphaMask::from_vec(2, 1, vec![0, 255]).is_some());
// Not exactly `width * height` bytes.
assert!(AlphaMask::from_vec(2, 1, vec![0]).is_none());
Source

pub fn width(&self) -> u32

The mask’s width in pixels.

use pdfrum_render::AlphaMask;

assert_eq!(AlphaMask::new(3, 2).width(), 3);
Source

pub fn height(&self) -> u32

The mask’s height in pixels.

use pdfrum_render::AlphaMask;

assert_eq!(AlphaMask::new(3, 2).height(), 2);
Source

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

The coverage bytes, row-major.

use pdfrum_render::AlphaMask;

// One byte per pixel, row-major.
assert_eq!(AlphaMask::new(2, 2).data().len(), 4);
Source

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

The coverage bytes, mutably.

use pdfrum_render::AlphaMask;

let mut mask = AlphaMask::new(1, 1);
mask.data_mut()[0] = 255;
assert_eq!(mask.data(), &[255]);
Source

pub fn into_data(self) -> Vec<u8> ⓘ

Consume the mask, yielding its coverage bytes.

use pdfrum_render::AlphaMask;

assert_eq!(AlphaMask::filled(1, 1, 200).into_data(), vec![200]);
Source

pub fn intersect(&mut self, other: &Self)

Intersect with another mask of the same size: the truncating integer product old * new / 255.

use pdfrum_render::AlphaMask;

let mut mask = AlphaMask::filled(1, 1, 255);
// The truncating integer product `old * new / 255`.
mask.intersect(&AlphaMask::filled(1, 1, 128));
assert_eq!(mask.data(), &[128]);
Source

pub fn apply_transfer(&mut self, table: &[u8; 256])

Map every byte through a 256-entry lookup — a soft mask’s /TR.

use pdfrum_render::AlphaMask;

let mut mask = AlphaMask::filled(1, 1, 10);
// A soft mask's `/TR`, as a 256-entry lookup.
let mut table = [0u8; 256];
table[10] = 200;
mask.apply_transfer(&table);
assert_eq!(mask.data(), &[200]);
Source

pub fn placed_in(&self, width: u32, height: u32, x: i32, y: i32) -> Self

Place src at (x, y) in a device-sized mask, zero everywhere else.

This is E8’s padding: a soft mask is produced at the clip rect’s size and must be handed to push_layer device-sized.

use pdfrum_render::AlphaMask;

// A mask produced at a clip rect's size, padded out to the device.
let small = AlphaMask::filled(1, 1, 255);
let placed = small.placed_in(2, 2, 1, 1);
assert_eq!(placed.data(), &[0, 0, 0, 255]);

Trait Implementations§

Source§

impl Clone for AlphaMask

Source§

fn clone(&self) -> AlphaMask

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for AlphaMask

Source§

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

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

impl Eq for AlphaMask

Source§

impl PartialEq for AlphaMask

Source§

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for AlphaMask

Auto Trait Implementations§

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§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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,

Source§

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>,

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

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

Source§

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.