pub struct RasterBuf {
pub width: u32,
pub height: u32,
pub pixels: Vec<u8>,
}Expand description
RGBA8 raster, sRGB color space, premultiplied alpha. Layout is
row-major, four bytes per pixel [R, G, B, A].
Fields§
§width: u32§height: u32§pixels: Vec<u8>Implementations§
Source§impl RasterBuf
impl RasterBuf
pub fn new(width: u32, height: u32) -> Self
pub fn filled(width: u32, height: u32, rgba: [u8; 4]) -> Self
Sourcepub fn is_blank(&self) -> bool
pub fn is_blank(&self) -> bool
Whether every byte is zero — i.e. fully transparent everywhere.
For premultiplied RGBA this means no coverage and no color at all
(a valid premultiplied pixel with a == 0 also has rgb == 0).
Scans in u128-wide chunks, so a canvas-sized buffer costs only
tens of microseconds.
A shared all-zero raster of the given size.
A style with dozens of layers produces dozens of fully transparent rasters on any tile that lacks those features — every one of them identical, and each otherwise costing a full padded canvas. Handing out one interned buffer per size collapses them into a single allocation. The pool keeps at most one buffer per distinct canvas size, which in practice means one.
Callers must treat the result as immutable; RasterBuf is Clone,
so any consumer needing to write copies first.
Sourcepub fn is_interned_blank(buf: &Arc<RasterBuf>) -> bool
pub fn is_interned_blank(buf: &Arc<RasterBuf>) -> bool
Whether buf is the interned blank for its size — i.e. holding
it costs nothing, because every other holder points at the same
allocation. Memory accounting uses this to avoid charging one
buffer’s worth of bytes to each of its dozens of holders.