Ultralight C++ API 1.4.0
|
#include <Ultralight/Bitmap.h>
A thread-safe container for pixel data.
The bitmap class is used to store pixel data in a variety of formats. It intelligently manages the lifetime of the pixel buffer and provides thread-safe access to the pixel data.
You can access the underlying pixel data by using the LockPixelsSafe() method. An example follows:
Static Public Member Functions | |
static RefPtr< Bitmap > | Create () |
Create an empty Bitmap. | |
static RefPtr< Bitmap > | Create (uint32_t width, uint32_t height, BitmapFormat format) |
Create a Bitmap with a certain configuration. | |
static RefPtr< Bitmap > | Create (uint32_t width, uint32_t height, BitmapFormat format, uint32_t alignment) |
Create an aligned Bitmap with a certain configuration. | |
static RefPtr< Bitmap > | Create (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 pixel data, a copy will be made unless should_copy is false. | |
static RefPtr< Bitmap > | Create (uint32_t width, uint32_t height, BitmapFormat format, uint32_t row_bytes, const void *pixels, size_t size, void *user_data, DestroyBitmapCallback destruction_callback) |
Create a Bitmap that wraps existing pixel data, a user-defined destruction callback will be called when the Bitmap wants to destroy the data. | |
static RefPtr< Bitmap > | Create (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 RefPtr< Buffer > | EncodePNG (bool convert_to_rgba=true, bool convert_to_straight_alpha=true) const =0 |
Encode this Bitmap as a PNG image and store the encoded bytes in a Buffer. | |
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 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 RefCounted | |
virtual | ~RefCounted () |
|
protected |
|
protectedvirtual |
|
pure virtual |
Get the number of bytes per pixel.
|
pure virtual |
Convert a BGRA bitmap from straight alpha to premultiplied alpha.
|
pure virtual |
Convert a BGRA bitmap from premultiplied alpha (the default) to straight alpha.
Create a bitmap from a deep copy of another Bitmap.
|
static |
|
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.
width | The width in pixels. |
height | The height in pixels. |
format | The pixel format to use. |
alignment | The 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. |
|
static |
Create a Bitmap with existing pixel data, a copy will be made unless should_copy is false.
width | The width in pixels. |
height | The height in pixels. |
format | The pixel format to use. |
row_bytes | The number of bytes between each row (note that this value should be >= width * bytes_per_pixel). |
pixels | Pointer to raw pixel buffer. |
size | Size of the raw pixel buffer. |
should_copy | Whether 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. |
|
static |
Create a Bitmap that wraps existing pixel data, a user-defined destruction callback will be called when the Bitmap wants to destroy the data.
width | The width in pixels. |
height | The height in pixels. |
format | The pixel format to use. |
row_bytes | The number of bytes between each row (note that this value should be >= width * bytes_per_pixel). |
pixels | Pointer to raw pixel buffer. |
size | Size of the raw pixel buffer. |
user_data | Optional user data that will be passed to destruction_callback when the Bitmap wants to destroy the pixel data. (Pass nullptr to ignore) |
destruction_callback | Callback that will be called upon destruction. |
|
pure virtual |
Draw another bitmap to this bitmap.
src_rect | The source rectangle, relative to src bitmap. |
dest_rect | The destination rectangle, relative to this bitmap. |
src | The source bitmap. |
pad_repeat | Whether or not we should pad the drawn bitmap by one pixel of repeated edge pixels from the source bitmap. |
|
pure virtual |
Encode this Bitmap as a PNG image and store the encoded bytes in a Buffer.
convert_to_rgba | The PNG format expects RGBA format but our bitmap is stored as BGRA, set this to true to perform the conversion automatically. |
convert_to_straight_alpha | The 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. |
|
pure virtual |
Erase the Bitmap (set all pixels to 0).
|
pure virtual |
Get the pixel format.
|
pure virtual |
Get the height in pixels.
|
pure virtual |
Whether or not this Bitmap is empty (no pixels allocated).
|
pure virtual |
|
pure virtual |
Lock the pixel buffer for reading/writing.
|
pure virtual |
Lock the pixel buffer for reading/writing (safe version, automatically unlocks).
|
protected |
|
pure virtual |
Whether or not this Bitmap owns the pixel buffer and will destroy it at the end of its lifetime.
|
pure virtual |
Get the raw pixel buffer.
Make a resized copy of this bitmap by writing to a pre-allocated destination bitmap.
destination | The bitmap to store the result in, the width and height of the destination will be used. |
high_quality | Whether or not a high quality resampling will be used during the resize. (Otherwise, just uses fast nearest-neighbor sampling) |
|
pure virtual |
Get the number of bytes between each row of pixels.
Assign another bitmap to this one.
bitmap | The bitmap to copy from. |
|
pure virtual |
Get the size in bytes of the pixel buffer.
|
pure virtual |
Convert a BGRA bitmap to RGBA bitmap and vice-versa by swapping the red and blue channels.
|
pure virtual |
Unlock the pixel buffer.
(const)
|
pure virtual |
Unlock the pixel buffer.
|
pure virtual |
Get the width in pixels.
|
pure virtual |
Write this Bitmap out to a PNG image.
path | The filepath to write to (opened with fopen()) |
convert_to_rgba | The PNG format expects RGBA format but our bitmap is stored as BGRA, set this to true to perform the conversion automatically. |
convert_to_straight_alpha | The 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. |