pub struct Bitmap { /* private fields */ }Expand description
Ultralight Bitmap container.
Implementations§
Source§impl Bitmap
impl Bitmap
Sourcepub fn create_empty(lib: Arc<Library>) -> Result<Self, BitmapError>
pub fn create_empty(lib: Arc<Library>) -> Result<Self, BitmapError>
Create an empty Bitmap. No pixels will be allocated.
Sourcepub fn create(
lib: Arc<Library>,
width: usize,
height: usize,
format: BitmapFormat,
) -> Result<Self, BitmapError>
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.
Sourcepub fn create_from_pixels(
lib: Arc<Library>,
width: u32,
height: u32,
format: BitmapFormat,
pixels: &[u8],
) -> Result<Self, BitmapError>
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().
Sourcepub fn copy(&self) -> Result<Self, BitmapError>
pub fn copy(&self) -> Result<Self, BitmapError>
Create a bitmap from a deep copy of another Bitmap.
Source§impl Bitmap
impl Bitmap
Sourcepub fn format(&self) -> BitmapFormat
pub fn format(&self) -> BitmapFormat
Get the pixel format.
Sourcepub fn row_bytes(&self) -> u32
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.
Sourcepub fn bytes_size(&self) -> usize
pub fn bytes_size(&self) -> usize
Get the size in bytes of the pixel buffer.
bytes_size is calculated as row_bytes() * height().
Sourcepub fn lock_pixels(&mut self) -> Option<PixelsGuard<'_>>
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.
Sourcepub fn write_to_png<P: AsRef<Path>>(&self, path: P) -> Result<(), BitmapError>
pub fn write_to_png<P: AsRef<Path>>(&self, path: P) -> Result<(), BitmapError>
Write bitmap to a PNG on disk.
Sourcepub fn swap_red_blue_channels(&self) -> Result<(), BitmapError>
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