#include <Ultralight/Bitmap.h>
Bitmap container with basic blitting and conversion routines.
|
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 pixels and configuration.
|
|
static RefPtr< Bitmap > | Create (const Bitmap &bitmap) |
| Create a bitmap from a deep copy of another Bitmap.
|
|
|
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.
|
|
virtual void | AddRef () const =0 |
|
virtual void | Release () const =0 |
|
virtual int | ref_count () const =0 |
|
◆ Bitmap() [1/2]
ultralight::Bitmap::Bitmap |
( |
| ) |
|
|
protected |
◆ ~Bitmap()
virtual ultralight::Bitmap::~Bitmap |
( |
| ) |
|
|
protectedvirtual |
◆ Bitmap() [2/2]
ultralight::Bitmap::Bitmap |
( |
const Bitmap & |
| ) |
|
|
protected |
◆ bounds()
virtual IntRect ultralight::Bitmap::bounds |
( |
| ) |
const |
|
pure virtual |
◆ 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 |
◆ ConvertToStraightAlpha()
virtual void ultralight::Bitmap::ConvertToStraightAlpha |
( |
| ) |
|
|
pure virtual |
◆ Create() [1/5]
Create an empty Bitmap.
No pixels will be allocated.
◆ Create() [2/5]
Create a bitmap from a deep copy of another Bitmap.
◆ Create() [3/5]
Create a Bitmap with a certain configuration.
Pixels will be allocated but not initialized.
- Parameters
-
width | The width in pixels. |
height | The height in pixels. |
format | The 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
-
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. |
- 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
-
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. |
- Returns
- A ref-pointer to a new Bitmap instance.
◆ DrawBitmap()
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_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. |
- 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()
◆ 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()
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
-
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) |
- 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
-
bitmap | The bitmap to copy from. |
◆ size()
virtual size_t ultralight::Bitmap::size |
( |
| ) |
const |
|
pure virtual |
◆ 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 |
◆ width()
virtual uint32_t ultralight::Bitmap::width |
( |
| ) |
const |
|
pure virtual |
◆ 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
-
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. |
- Returns
- Whether or not the operation succeeded.
The documentation for this class was generated from the following file: