41#define GetBytesPerPixel(x) (x == BitmapFormat::A8_UNORM ? 1 : 4)
114 uint32_t row_bytes,
const void* pixels,
size_t size,
115 bool should_copy =
true);
145 virtual uint32_t
bpp()
const = 0;
160 virtual size_t size()
const = 0;
260 virtual bool WritePNG(
const char* path,
bool convert_to_rgba =
true,
261 bool convert_to_straight_alpha =
true)
const = 0;
311 explicit LockedPixels(T& lockable) : lockable_(lockable), data_(nullptr), size_(0) { lock(); }
315 lockable_->UnlockPixels();
326 size_t size() {
return size_; }
328 explicit operator bool()
const {
return !!lockable_; }
332 other.lockable_ =
nullptr;
333 other.data_ =
nullptr;
339 lockable_->UnlockPixels();
340 lockable_ = other.lockable_;
343 other.lockable_ =
nullptr;
344 other.data_ =
nullptr;
352 data_ = lockable_->LockPixels();
353 size_ = lockable_->size();
#define UExport
Definition Defines.h:65
Bitmap container with basic blitting and conversion routines.
Definition Bitmap.h:52
virtual void ConvertToPremultipliedAlpha()=0
Convert a BGRA bitmap from straight alpha to premultiplied alpha.
void operator=(const Bitmap &)
virtual void UnlockPixels()=0
Unlock the pixel buffer.
virtual size_t size() const =0
Get the size in bytes of the pixel buffer.
virtual void UnlockPixels() const =0
Unlock the pixel buffer.
virtual void Erase()=0
Erase the Bitmap (set all pixels to 0).
virtual uint32_t bpp() const =0
Get the number of bytes per pixel.
virtual bool DrawBitmap(IntRect src_rect, IntRect dest_rect, RefPtr< Bitmap > src, bool pad_repeat)=0
Draw another bitmap to this bitmap.
virtual void ConvertToStraightAlpha()=0
Convert a BGRA bitmap from premultiplied alpha (the default) to straight alpha.
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.
virtual IntRect bounds() const =0
Get the bounds as an IntRect.
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 const void * LockPixels() const =0
Lock the pixel buffer for reading/writing.
virtual bool IsEmpty() const =0
Whether or not this Bitmap is empty (no pixels allocated).
virtual LockedPixels< RefPtr< Bitmap > > LockPixelsSafe() const =0
Lock the pixel buffer for reading/writing (safe version, automatically unlocks).
virtual uint32_t row_bytes() const =0
Get the number of bytes between each row of pixels.
virtual BitmapFormat format() const =0
Get the pixel format.
virtual void * LockPixels()=0
Lock the pixel buffer for reading/writing.
static RefPtr< Bitmap > Create()
Create an empty Bitmap.
virtual uint32_t height() const =0
Get the height in pixels.
virtual void Set(RefPtr< Bitmap > bitmap)=0
Assign another bitmap to this one.
virtual uint32_t width() const =0
Get the width in pixels.
virtual void SwapRedBlueChannels()=0
Convert a BGRA bitmap to RGBA bitmap and vice-versa by swapping the red and blue channels.
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 * raw_pixels()=0
Get the raw pixel buffer.
static RefPtr< Bitmap > Create(uint32_t width, uint32_t height, BitmapFormat format)
Create a Bitmap with a certain configuration.
static RefPtr< Bitmap > Create(const Bitmap &bitmap)
Create a bitmap from a deep copy of another Bitmap.
static RefPtr< Bitmap > Create(uint32_t width, uint32_t height, BitmapFormat format, uint32_t alignment)
Create an aligned Bitmap with a certain configuration.
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.
Forward declaration for the LockedPixels class.
Definition Bitmap.h:306
~LockedPixels()
Definition Bitmap.h:313
LockedPixels & operator=(LockedPixels &&other)
Definition Bitmap.h:337
LockedPixels(LockedPixels &&other)
Definition Bitmap.h:330
void * data()
Access the locked pixel data.
Definition Bitmap.h:321
LockedPixels(const LockedPixels &)=delete
LockedPixels(T &lockable)
Definition Bitmap.h:311
LockedPixels & operator=(const LockedPixels &)=delete
size_t size()
Access the size of the locked pixel data.
Definition Bitmap.h:326
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
BitmapFormat
The various Bitmap formats.
Definition Bitmap.h:18
@ 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