42#define GetBytesPerPixel(x) (x == BitmapFormat::A8_UNORM ? 1 : 4)
144 uint32_t row_bytes,
const void* pixels,
size_t size,
145 bool should_copy =
true);
172 uint32_t row_bytes,
const void* pixels,
size_t size,
173 void* user_data, DestroyBitmapCallback destruction_callback);
203 virtual uint32_t
bpp()
const = 0;
218 virtual size_t size()
const = 0;
317 bool convert_to_straight_alpha =
true)
const = 0;
333 virtual bool WritePNG(
const char* path,
bool convert_to_rgba =
true,
334 bool convert_to_straight_alpha =
true)
const = 0;
384 explicit LockedPixels(T& lockable) : lockable_(lockable), data_(nullptr), size_(0) { lock(); }
388 lockable_->UnlockPixels();
399 size_t size() {
return size_; }
401 explicit operator bool()
const {
return !!lockable_; }
405 other.lockable_ =
nullptr;
406 other.data_ =
nullptr;
412 lockable_->UnlockPixels();
413 lockable_ = other.lockable_;
416 other.lockable_ =
nullptr;
417 other.data_ =
nullptr;
425 data_ = lockable_->LockPixels();
426 size_ = lockable_->size();
#define UExport
Definition Exports.h:25
A thread-safe container for pixel data.
Definition Bitmap.h:82
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 owns_pixels() const =0
Whether or not this Bitmap owns the pixel buffer and will destroy it at the end of its lifetime.
static RefPtr< Bitmap > Create()
Create an empty Bitmap.
virtual bool DrawBitmap(IntRect src_rect, IntRect dest_rect, RefPtr< Bitmap > src, bool pad_repeat)=0
Draw another bitmap to this bitmap.
void operator=(const Bitmap &)
virtual uint32_t height() const =0
Get the height in pixels.
virtual bool IsEmpty() const =0
Whether or not this Bitmap is empty (no pixels allocated).
static RefPtr< Bitmap > Create(const Bitmap &bitmap)
Create a bitmap from a deep copy of another Bitmap.
virtual uint32_t row_bytes() const =0
Get the number of bytes between each row of pixels.
virtual void Set(RefPtr< Bitmap > bitmap)=0
Assign another bitmap to this one.
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 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 wh...
virtual uint32_t width() const =0
Get the width in pixels.
static RefPtr< Bitmap > Create(uint32_t width, uint32_t height, BitmapFormat format, uint32_t alignment)
Create an aligned Bitmap with a certain configuration.
virtual void SwapRedBlueChannels()=0
Convert a BGRA bitmap to RGBA bitmap and vice-versa by swapping the red and blue channels.
virtual void Erase()=0
Erase the Bitmap (set all pixels to 0).
virtual void * LockPixels()=0
Lock the pixel buffer for reading/writing.
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 IntRect bounds() const =0
Get the bounds as an IntRect.
virtual void ConvertToPremultipliedAlpha()=0
Convert a BGRA bitmap from straight alpha to premultiplied alpha.
virtual void UnlockPixels()=0
Unlock the pixel buffer.
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.
virtual uint32_t bpp() const =0
Get the number of bytes per pixel.
virtual LockedPixels< RefPtr< Bitmap > > LockPixelsSafe() const =0
Lock the pixel buffer for reading/writing (safe version, automatically unlocks).
virtual const void * LockPixels() const =0
Lock the pixel buffer for reading/writing.
virtual void UnlockPixels() const =0
Unlock the pixel buffer.
virtual size_t size() const =0
Get the size in bytes of the pixel buffer.
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 ConvertToStraightAlpha()=0
Convert a BGRA bitmap from premultiplied alpha (the default) to straight alpha.
virtual BitmapFormat format() const =0
Get the pixel format.
virtual void * raw_pixels()=0
Get the raw pixel buffer.
Forward declaration for the LockedPixels class.
Definition Bitmap.h:379
void * data()
Access the locked pixel data.
Definition Bitmap.h:394
size_t size()
Access the size of the locked pixel data.
Definition Bitmap.h:399
~LockedPixels()
Definition Bitmap.h:386
LockedPixels(const LockedPixels &)=delete
LockedPixels & operator=(LockedPixels &&other)
Definition Bitmap.h:410
LockedPixels & operator=(const LockedPixels &)=delete
LockedPixels(T &lockable)
Definition Bitmap.h:384
LockedPixels(LockedPixels &&other)
Definition Bitmap.h:403
Interface for all ref-counted objects that will be managed using the RefPtr<> smart pointer.
Definition RefPtr.h:47
A nullable smart pointer.
Definition RefPtr.h:79
void(* DestroyBitmapCallback)(void *user_data, void *data)
Function signature for a user-defined destruction callback to be optionally called when the Bitmap is...
Definition Bitmap.h:59
BitmapFormat
The various Bitmap formats.
Definition Bitmap.h:19
@ A8_UNORM
Alpha channel only, 8-bits per pixel.
@ BGRA8_UNORM_SRGB
Blue Green Red Alpha channels, 32-bits per pixel.
Integer Rectangle Helper.
Definition Geometry.h:529