Ultralight  1.0.0
A fast, lightweight, HTML UI engine for native apps.
ultralight::Bitmap Class Referenceabstract

Bitmap container with basic blitting and conversion routines. More...

#include <Bitmap.h>

Inheritance diagram for ultralight::Bitmap:
ultralight::RefCounted

Public Member Functions

virtual uint32_t width () const =0
 Get the width in pixels.
 
virtual uint32_t height () const =0
 Get the height in pixels.
 
virtual IntRect bounds () const =0
 Get the bounds as an IntRect.
 
virtual BitmapFormat format () const =0
 Get the pixel format.
 
virtual uint32_t bpp () const =0
 Get the number of bytes per pixel.
 
virtual uint32_t row_bytes () const =0
 Get the number of bytes between each row (this is always >= width * bpp)
 
virtual size_t size () const =0
 Get the size in bytes of the pixel buffer.
 
virtual bool owns_pixels () const =0
 Whether or not this Bitmap owns the pixel buffer and will destroy it at the end of its lifetime.
 
virtual void * LockPixels ()=0
 Lock the pixel buffer for reading/writing. More...
 
virtual void UnlockPixels ()=0
 Unlock the pixel buffer.
 
virtual const void * LockPixels () const =0
 Lock the pixel buffer for reading/writing. More...
 
virtual void UnlockPixels () const =0
 Unlock the pixel buffer. More...
 
virtual void * raw_pixels ()=0
 Get the raw pixel buffer. More...
 
virtual bool IsEmpty () const =0
 Whether or not this Bitmap is empty (no pixels allocated).
 
virtual void Erase ()=0
 Erase the Bitmap (set all pixels to 0).
 
virtual void Set (Ref< Bitmap > bitmap)=0
 Assign another bitmap to this one. More...
 
virtual bool DrawBitmap (IntRect src_rect, IntRect dest_rect, Ref< Bitmap > src, bool pad_repeat)=0
 Draw another bitmap to this bitmap. More...
 
virtual bool WritePNG (const char *path)=0
 Write this Bitmap out to a PNG image. More...
 

Static Public Member Functions

static Ref< BitmapCreate ()
 Create an empty Bitmap. More...
 
static Ref< BitmapCreate (uint32_t width, uint32_t height, BitmapFormat format)
 Create a Bitmap with a certain configuration. More...
 
static Ref< BitmapCreate (uint32_t width, uint32_t height, BitmapFormat format, uint32_t row_bytes, const void *pixels, size_t size, bool should_copy=true)
 Create a Bitmap with existing pixels and configuration. More...
 
static Ref< BitmapCreate (const Bitmap &bitmap)
 Create a bitmap from a deep copy of another Bitmap.
 

Detailed Description

Bitmap container with basic blitting and conversion routines.

Definition at line 42 of file Bitmap.h.

Member Function Documentation

◆ Create() [1/3]

static Ref<Bitmap> ultralight::Bitmap::Create ( )
static

Create an empty Bitmap.

No pixels will be allocated.

◆ Create() [2/3]

static Ref<Bitmap> ultralight::Bitmap::Create ( uint32_t  width,
uint32_t  height,
BitmapFormat  format 
)
static

Create a Bitmap with a certain configuration.

Pixels will be allocated but not initialized.

Parameters
widthThe width in pixels.
heightThe height in pixels.
formatThe pixel format to use.
Returns
A ref-pointer to a new Bitmap instance.

◆ Create() [3/3]

static Ref<Bitmap> ultralight::Bitmap::Create ( uint32_t  width,
uint32_t  height,
BitmapFormat  format,
uint32_t  row_bytes,
const void *  pixels,
size_t  size,
bool  should_copy = true 
)
static

Create a Bitmap with existing pixels and configuration.

Parameters
widthThe width in pixels.
heightThe height in pixels.
formatThe pixel format to use.
row_bytesThe number of bytes between each row (note that this value should be >= width * bytes_per_pixel).
pixelsPointer to raw pixel buffer.
sizeSize of the raw pixel buffer.
should_copyWhether or not a copy should be made of the pixels. If this is false, the returned Bitmap will use the raw pixels passed in as its own, but you are still responsible for destroying your buffer afterwards.
Returns
A ref-pointer to a new Bitmap instance.

◆ DrawBitmap()

virtual bool ultralight::Bitmap::DrawBitmap ( IntRect  src_rect,
IntRect  dest_rect,
Ref< Bitmap src,
bool  pad_repeat 
)
pure virtual

Draw another bitmap to this bitmap.

Note
Formats do not need to match. Bitmap formats will be converted to one another automatically. Note that when converting from RGBA8 to A8, only the Red channel will be used.
Parameters
src_rectThe source rectangle, relative to src bitmap.
dest_rectThe destination rectangle, relative to this bitmap.
srcThe source bitmap.
pad_repeatWhether or not we should pad the drawn bitmap by one pixel of repeated edge pixels from the source bitmap.
Returns
Whether or not the operation succeeded (this can fail if the src_rect and/or dest_rect are invalid, or if their total dimensions do not match).

◆ LockPixels() [1/2]

virtual void* ultralight::Bitmap::LockPixels ( )
pure virtual

Lock the pixel buffer for reading/writing.

Returns
A pointer to the pixel buffer.

◆ LockPixels() [2/2]

virtual const void* ultralight::Bitmap::LockPixels ( ) const
pure virtual

Lock the pixel buffer for reading/writing.

(const)

Returns
A const pointer to the pixel buffer.

◆ raw_pixels()

virtual void* ultralight::Bitmap::raw_pixels ( )
pure virtual

Get the raw pixel buffer.

Note
You should only call this if pixels are already locked.

◆ Set()

virtual void ultralight::Bitmap::Set ( Ref< Bitmap bitmap)
pure virtual

Assign another bitmap to this one.

Parameters
bitmapThe bitmap to copy from.

◆ UnlockPixels()

virtual void ultralight::Bitmap::UnlockPixels ( ) const
pure virtual

Unlock the pixel buffer.

(const)

◆ WritePNG()

virtual bool ultralight::Bitmap::WritePNG ( const char *  path)
pure virtual

Write this Bitmap out to a PNG image.

(mainly used for Debug)

Parameters
pathThe filepath to write to (opened with fopen())
Returns
Whether or not the operation succeeded.

The documentation for this class was generated from the following file: