Bitmap

Struct Bitmap 

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

Ultralight Bitmap container.

Implementations§

Source§

impl Bitmap

Source

pub fn create_empty(lib: Arc<Library>) -> Result<Self, BitmapError>

Create an empty Bitmap. No pixels will be allocated.

Source

pub fn create( lib: Arc<Library>, width: usize, height: usize, format: BitmapFormat, ) -> Result<Self, BitmapError>

Create an aligned Bitmap with a certain configuration. Pixels will be allocated but not initialized.

§Arguments
  • lib - The ultralight library.
  • width - The width of the bitmap.
  • height - The height of the bitmap.
  • format - The format of the bitmap.
Source

pub fn create_from_pixels( lib: Arc<Library>, width: u32, height: u32, format: BitmapFormat, pixels: &[u8], ) -> Result<Self, BitmapError>

Create a Bitmap with existing pixels

§Arguments
  • lib - The ultralight library.
  • width - The width of the bitmap.
  • height - The height of the bitmap.
  • format - The format of the bitmap.
  • pixels - The raw pixels of the bitmap.

The length of the pixels slice must be equal to width * height * format.bytes_per_pixel().

Source

pub fn copy(&self) -> Result<Self, BitmapError>

Create a bitmap from a deep copy of another Bitmap.

Source§

impl Bitmap

Source

pub fn width(&self) -> u32

Get the width in pixels.

Source

pub fn height(&self) -> u32

Get the height in pixels.

Source

pub fn format(&self) -> BitmapFormat

Get the pixel format.

Source

pub fn bpp(&self) -> u32

Get the number of bytes per pixel.

Source

pub fn row_bytes(&self) -> u32

Get the number of bytes between each row of pixels.

This value is usually calculated as width() * bytes_per_pixel() (bpp) but it may be larger due to alignment rules in the allocator.

Source

pub fn bytes_size(&self) -> usize

Get the size in bytes of the pixel buffer.

bytes_size is calculated as row_bytes() * height().

Source

pub fn lock_pixels(&mut self) -> Option<PixelsGuard<'_>>

Lock the pixel buffer for reading/writing.

An RAII guard is returned that will unlock the buffer when dropped.

Source

pub fn is_empty(&self) -> bool

Whether or not this bitmap is empty (no pixels allocated).

Source

pub fn erase(&self)

Reset bitmap pixels to 0.

Source

pub fn write_to_png<P: AsRef<Path>>(&self, path: P) -> Result<(), BitmapError>

Write bitmap to a PNG on disk.

Source

pub fn swap_red_blue_channels(&self) -> Result<(), BitmapError>

This converts a BGRA bitmap to RGBA bitmap and vice-versa by swapping the red and blue channels.

Only valid if the format is BitmapFormat::BGRA8_UNORM_SRGB

Trait Implementations§

Source§

impl Drop for Bitmap

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

impl Freeze for Bitmap

§

impl RefUnwindSafe for Bitmap

§

impl !Send for Bitmap

§

impl !Sync for Bitmap

§

impl Unpin for Bitmap

§

impl UnwindSafe for Bitmap

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.