Struct tiny_skia::alpha_runs::AlphaRuns
source · pub struct AlphaRuns {
pub runs: Vec<Option<NonZeroU16>>,
pub alpha: Vec<u8>,
}
Expand description
Sparse array of run-length-encoded alpha (supersampling coverage) values.
Sparseness allows us to independently compose several paths into the same AlphaRuns buffer.
Fields§
§runs: Vec<Option<NonZeroU16>>
§alpha: Vec<u8>
Implementations§
source§impl AlphaRuns
impl AlphaRuns
pub fn new(width: NonZeroU32) -> Self
sourcepub fn catch_overflow(alpha: u16) -> u8
pub fn catch_overflow(alpha: u16) -> u8
Returns 0-255 given 0-256.
sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Returns true if the scanline contains only a single run, of alpha value 0.
sourcepub fn reset(&mut self, width: NonZeroU32)
pub fn reset(&mut self, width: NonZeroU32)
Reinitialize for a new scanline.
sourcepub fn add(
&mut self,
x: u32,
start_alpha: u8,
middle_count: usize,
stop_alpha: u8,
max_value: u8,
offset_x: usize,
) -> usize
pub fn add( &mut self, x: u32, start_alpha: u8, middle_count: usize, stop_alpha: u8, max_value: u8, offset_x: usize, ) -> usize
Insert into the buffer a run starting at (x-offset_x).
if start_alpha > 0 one pixel with value += start_alpha, max 255 if middle_count > 0 middle_count pixels with value += max_value if stop_alpha > 0 one pixel with value += stop_alpha
Returns the offset_x value that should be passed on the next call, assuming we’re on the same scanline. If the caller is switching scanlines, then offset_x should be 0 when this is called.
sourcefn break_run(
runs: &mut [Option<NonZeroU16>],
alpha: &mut [u8],
x: usize,
count: usize,
)
fn break_run( runs: &mut [Option<NonZeroU16>], alpha: &mut [u8], x: usize, count: usize, )
Break the runs in the buffer at offsets x and x+count, properly updating the runs to the right and left.
i.e. from the state AAAABBBB, run-length encoded as A4B4, break_run(…, 2, 5) would produce AAAABBBB rle as A2A2B3B1. Allows add() to sum another run to some of the new sub-runs. i.e. adding ..CCCCC. would produce AADDEEEB, rle as A2D2E3B1.