Ultralight C++ API 1.3.0
Loading...
Searching...
No Matches
ultralight::Bitmap Class Referenceabstract

#include <Ultralight/Bitmap.h>

Details

Bitmap container with basic blitting and conversion routines.

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

Static Public Member Functions

static RefPtr< BitmapCreate ()
 Create an empty Bitmap.
 
static RefPtr< BitmapCreate (uint32_t width, uint32_t height, BitmapFormat format)
 Create a Bitmap with a certain configuration.
 
static RefPtr< BitmapCreate (uint32_t width, uint32_t height, BitmapFormat format, uint32_t alignment)
 Create an aligned Bitmap with a certain configuration.
 
static RefPtr< 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.
 
static RefPtr< BitmapCreate (const Bitmap &bitmap)
 Create a bitmap from a deep copy of another Bitmap.
 

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 of pixels.
 
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 LockedPixels< RefPtr< Bitmap > > LockPixelsSafe () const =0
 Lock the pixel buffer for reading/writing (safe version, automatically unlocks).
 
virtual void * LockPixels ()=0
 Lock the pixel buffer for reading/writing.
 
virtual void UnlockPixels ()=0
 Unlock the pixel buffer.
 
virtual const void * LockPixels () const =0
 Lock the pixel buffer for reading/writing.
 
virtual void UnlockPixels () const =0
 Unlock the pixel buffer.
 
virtual void * raw_pixels ()=0
 Get the raw pixel buffer.
 
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 (RefPtr< Bitmap > bitmap)=0
 Assign another bitmap to this one.
 
virtual bool DrawBitmap (IntRect src_rect, IntRect dest_rect, RefPtr< Bitmap > src, bool pad_repeat)=0
 Draw another bitmap to this bitmap.
 
virtual bool WritePNG (const char *path, bool convert_to_rgba=true, bool convert_to_straight_alpha=true) const =0
 Write this Bitmap out to a PNG image.
 
virtual bool Resample (RefPtr< Bitmap > destination, bool high_quality)=0
 Make a resized copy of this bitmap by writing to a pre-allocated destination bitmap.
 
virtual void SwapRedBlueChannels ()=0
 Convert a BGRA bitmap to RGBA bitmap and vice-versa by swapping the red and blue channels.
 
virtual void ConvertToStraightAlpha ()=0
 Convert a BGRA bitmap from premultiplied alpha (the default) to straight alpha.
 
virtual void ConvertToPremultipliedAlpha ()=0
 Convert a BGRA bitmap from straight alpha to premultiplied alpha.
 
- Public Member Functions inherited from ultralight::RefCounted
virtual void AddRef () const =0
 
virtual void Release () const =0
 
virtual int ref_count () const =0
 

Protected Member Functions

 Bitmap ()
 
virtual ~Bitmap ()
 
 Bitmap (const Bitmap &)
 
void operator= (const Bitmap &)
 
- Protected Member Functions inherited from ultralight::RefCounted
virtual ~RefCounted ()
 

Constructor & Destructor Documentation

◆ Bitmap() [1/2]

ultralight::Bitmap::Bitmap ( )
protected

◆ ~Bitmap()

virtual ultralight::Bitmap::~Bitmap ( )
protectedvirtual

◆ Bitmap() [2/2]

ultralight::Bitmap::Bitmap ( const Bitmap )
protected

Member Function Documentation

◆ bounds()

virtual IntRect ultralight::Bitmap::bounds ( ) const
pure virtual

Get the bounds as an IntRect.

◆ bpp()

virtual uint32_t ultralight::Bitmap::bpp ( ) const
pure virtual

Get the number of bytes per pixel.

◆ ConvertToPremultipliedAlpha()

virtual void ultralight::Bitmap::ConvertToPremultipliedAlpha ( )
pure virtual

Convert a BGRA bitmap from straight alpha to premultiplied alpha.

Note
Only valid if the format is BitmapFormat::BGRA8_UNORM_SRGB

◆ ConvertToStraightAlpha()

virtual void ultralight::Bitmap::ConvertToStraightAlpha ( )
pure virtual

Convert a BGRA bitmap from premultiplied alpha (the default) to straight alpha.

Note
Only valid if the format is BitmapFormat::BGRA8_UNORM_SRGB

◆ Create() [1/5]

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

Create an empty Bitmap.

No pixels will be allocated.

◆ Create() [2/5]

static RefPtr< Bitmap > ultralight::Bitmap::Create ( const Bitmap bitmap)
static

Create a bitmap from a deep copy of another Bitmap.

◆ Create() [3/5]

static RefPtr< 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() [4/5]

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

Create an aligned Bitmap with a certain configuration.

Pixels will be allocated but not initialized. Row bytes will be padded to reach the specified alignment.

Parameters
widthThe width in pixels.
heightThe height in pixels.
formatThe pixel format to use.
alignmentThe alignment (in bytes) to use. Row bytes will be padded to reach a multiple of this value and the underlying storage will be allocated with this alignment.
Returns
A ref-pointer to a new Bitmap instance.

◆ Create() [5/5]

static RefPtr< 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,
RefPtr< 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 BGRA8 to A8, only the Blue 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).

◆ Erase()

virtual void ultralight::Bitmap::Erase ( )
pure virtual

Erase the Bitmap (set all pixels to 0).

◆ format()

virtual BitmapFormat ultralight::Bitmap::format ( ) const
pure virtual

Get the pixel format.

◆ height()

virtual uint32_t ultralight::Bitmap::height ( ) const
pure virtual

Get the height in pixels.

◆ IsEmpty()

virtual bool ultralight::Bitmap::IsEmpty ( ) const
pure virtual

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

◆ LockPixels() [1/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.

◆ LockPixels() [2/2]

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

Lock the pixel buffer for reading/writing.

Returns
A pointer to the pixel buffer.

◆ LockPixelsSafe()

virtual LockedPixels< RefPtr< Bitmap > > ultralight::Bitmap::LockPixelsSafe ( ) const
pure virtual

Lock the pixel buffer for reading/writing (safe version, automatically unlocks).

Returns
A managed container that can be used to access the pixels (LockedPixels::data()). This container will automatically unlock the pixels when it goes out of scope.

◆ operator=()

void ultralight::Bitmap::operator= ( const Bitmap )
protected

◆ owns_pixels()

virtual bool ultralight::Bitmap::owns_pixels ( ) const
pure virtual

Whether or not this Bitmap owns the pixel buffer and will destroy it at the end of its lifetime.

◆ 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.

◆ Resample()

virtual bool ultralight::Bitmap::Resample ( RefPtr< Bitmap destination,
bool  high_quality 
)
pure virtual

Make a resized copy of this bitmap by writing to a pre-allocated destination bitmap.

Parameters
destinationThe bitmap to store the result in, the width and height of the destination will be used.
high_qualityWhether or not a high quality resampling will be used during the resize. (Otherwise, just uses fast nearest-neighbor sampling)
Returns
Whether or not the operation succeeded. This operation is only valid if both formats are BitmapFormat::BGRA8_UNORM_SRGB and the source and destination are non-empty.

◆ row_bytes()

virtual uint32_t ultralight::Bitmap::row_bytes ( ) const
pure virtual

Get the number of bytes between each row of pixels.

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

◆ Set()

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

Assign another bitmap to this one.

Parameters
bitmapThe bitmap to copy from.

◆ size()

virtual size_t ultralight::Bitmap::size ( ) const
pure virtual

Get the size in bytes of the pixel buffer.

Note
Size is calculated as row_bytes() * height().

◆ SwapRedBlueChannels()

virtual void ultralight::Bitmap::SwapRedBlueChannels ( )
pure virtual

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

Note
Only valid if the format is BitmapFormat::BGRA8_UNORM_SRGB

◆ UnlockPixels() [1/2]

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

Unlock the pixel buffer.

(const)

◆ UnlockPixels() [2/2]

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

Unlock the pixel buffer.

◆ width()

virtual uint32_t ultralight::Bitmap::width ( ) const
pure virtual

Get the width in pixels.

◆ WritePNG()

virtual bool ultralight::Bitmap::WritePNG ( const char *  path,
bool  convert_to_rgba = true,
bool  convert_to_straight_alpha = true 
) const
pure virtual

Write this Bitmap out to a PNG image.

Parameters
pathThe filepath to write to (opened with fopen())
convert_to_rgbaThe PNG format expects RGBA format but our bitmap is stored as BGRA, set this to true to perform the conversion automatically.
convert_to_straight_alphaThe PNG format expects semi-transparent values to be stored as straight alpha instead of premultiplied alpha, set this to true to perform the conversion automatically.
Returns
Whether or not the operation succeeded.

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