pub struct Bitmap<P: Pixel> {
pub width: u32,
pub height: u32,
pub stride: usize,
/* private fields */
}Expand description
A typed, top-down pixel buffer.
P determines the in-memory layout. The row stride is width * P::BYTES
rounded up to the next multiple of row_pad (default 4).
The optional alpha plane is always width * height bytes, one byte per pixel,
top-down. It is stored separately from the colour data (matching SplashBitmap).
Fields§
§width: u32Width of the bitmap in pixels.
height: u32Height of the bitmap in pixels.
stride: usizeByte distance between the start of consecutive rows; always ≥ width * P::BYTES
and a multiple of row_pad.
Implementations§
Source§impl<P: Pixel> Bitmap<P>
impl<P: Pixel> Bitmap<P>
Sourcepub fn new(width: u32, height: u32, row_pad: usize, with_alpha: bool) -> Self
pub fn new(width: u32, height: u32, row_pad: usize, with_alpha: bool) -> Self
Allocate a new zeroed bitmap.
row_pad pads each row to a multiple of that many bytes (pass 1 for no padding).
with_alpha allocates a separate alpha plane initialised to 0.
§Panics
Panics if row_pad is 0.
Sourcepub fn row(&self, y: u32) -> &[P]
pub fn row(&self, y: u32) -> &[P]
Typed read-only access to row y.
Returns a slice of exactly width pixels.
§Panics
Panics if y >= height.
Sourcepub fn row_bytes(&self, y: u32) -> &[u8] ⓘ
pub fn row_bytes(&self, y: u32) -> &[u8] ⓘ
Raw byte read-only access to the full stride of row y (including padding).
§Panics
Panics if y >= height.
Sourcepub fn row_bytes_mut(&mut self, y: u32) -> &mut [u8] ⓘ
pub fn row_bytes_mut(&mut self, y: u32) -> &mut [u8] ⓘ
Sourcepub fn alpha_row(&self, y: u32) -> Option<&[u8]>
pub fn alpha_row(&self, y: u32) -> Option<&[u8]>
Alpha plane row y, if the alpha plane was allocated.
Returns None if this bitmap was created without an alpha plane.
§Panics
Panics if y >= height.
Sourcepub fn alpha_plane(&self) -> Option<&[u8]>
pub fn alpha_plane(&self) -> Option<&[u8]>
Read-only access to the full alpha plane (width × height bytes).
Returns None if this bitmap was created without an alpha plane.
Sourcepub fn alpha_plane_mut(&mut self) -> Option<&mut [u8]>
pub fn alpha_plane_mut(&mut self) -> Option<&mut [u8]>
Mutable access to the full alpha plane (width × height bytes).
Returns None if this bitmap was created without an alpha plane.
Sourcepub fn row_and_alpha_mut(&mut self, y: u32) -> (&mut [u8], Option<&mut [u8]>)
pub fn row_and_alpha_mut(&mut self, y: u32) -> (&mut [u8], Option<&mut [u8]>)
Simultaneous mutable access to the pixel row and the alpha row.
Returns (pixel_row_bytes, Some(alpha_row)) or (pixel_row_bytes, None).
Provided because the borrow checker rejects holding two mutable
references into the same &mut self (pixel data and alpha plane) via
separate accessor calls.
§Panics
Panics if y >= height.
Source§impl<P: Pixel> Bitmap<P>
impl<P: Pixel> Bitmap<P>
Sourcepub fn bands_mut(&mut self, n_bands: usize) -> Vec<BitmapBand<'_, P>>
pub fn bands_mut(&mut self, n_bands: usize) -> Vec<BitmapBand<'_, P>>
Split the bitmap into n_bands horizontal bands of approximately equal height,
returning a Vec<BitmapBand<'_, P>>.
The bands cover the full height of the bitmap with no gaps and no overlaps. Each band borrows a disjoint slice of the underlying pixel data and alpha plane, making it safe to render bands in parallel.
If n_bands == 0 or n_bands > height, the number of bands is clamped so that
each band contains at least one row.
§Panics
Panics if n_bands is 0.