Skip to main content

Bitmap

Struct Bitmap 

Source
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: u32

Width of the bitmap in pixels.

§height: u32

Height of the bitmap in pixels.

§stride: usize

Byte distance between the start of consecutive rows; always ≥ width * P::BYTES and a multiple of row_pad.

Implementations§

Source§

impl<P: Pixel> Bitmap<P>

Source

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.

Source

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.

Source

pub fn row_mut(&mut self, y: u32) -> &mut [P]

Typed mutable access to row y.

§Panics

Panics if y >= height.

Source

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.

Source

pub fn row_bytes_mut(&mut self, y: u32) -> &mut [u8]

Raw byte mutable access to the full stride of row y.

§Panics

Panics if y >= height.

Source

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.

Source

pub const fn has_alpha(&self) -> bool

Returns true if this bitmap has a separate alpha plane.

Source

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.

Source

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.

Source

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

pub fn clear(&mut self, color: P, alpha: u8)

Fill the entire bitmap with a solid colour and an alpha value.

alpha is ignored if the bitmap has no alpha plane.

Source

pub const fn data_len(&self) -> usize

Total byte size of the colour data buffer.

Source

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

Access the full colour data buffer as a flat byte slice.

Source

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

Mutable access to the full colour data buffer as a flat byte slice.

Source§

impl<P: Pixel> Bitmap<P>

Source

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.

Auto Trait Implementations§

§

impl<P> Freeze for Bitmap<P>

§

impl<P> RefUnwindSafe for Bitmap<P>
where P: RefUnwindSafe,

§

impl<P> Send for Bitmap<P>

§

impl<P> Sync for Bitmap<P>

§

impl<P> Unpin for Bitmap<P>
where P: Unpin,

§

impl<P> UnsafeUnpin for Bitmap<P>

§

impl<P> UnwindSafe for Bitmap<P>
where P: UnwindSafe,

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> 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, U> TryFrom<U> for T
where U: Into<T>,

Source§

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

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.