The core bitmap container class used by You.i Engine.
#include <graphics/YiBitmap.h>
Public Types | |
enum | Ownership { Ownership::Shared, Ownership::Private } |
enum | ColorMode { ColorMode::RGBA8888, ColorMode::RGBA4444, ColorMode::RGB565 } |
enum | DitheringMode { DitheringMode::None = 0, DitheringMode::FloydSteinberg } |
Public Member Functions | |
CYIBitmap () | |
virtual | ~CYIBitmap () |
std::unique_ptr< CYIBitmap > | Clone () const |
virtual bool | Create (int32_t width, int32_t height) |
void | Draw (const CYIBitmap &srcImage, int32_t destX, int32_t destY) |
void | Draw (const CYIBitmap &srcImage, int32_t destX, int32_t destY, const YI_RECT_REL &clipRegion) |
void | Draw (const CYIBitmap &srcImage, int32_t destX, int32_t destY, int32_t clipWidth, int32_t clipHeight) |
void | DrawScale (const CYIBitmap &srcImage, const YI_RECT_REL *pDest, const YI_RECT_REL *pSrc) |
void | Fill (const CYIColor &color) |
void | Fill (const CYIColor &color, const YI_RECT ®ion) |
const uint32_t * | GetPixels () const |
uint32_t * | GetPixels () |
void | FreePixels () |
virtual int32_t | GetHeight () const |
void | ReduceHeightTo (int32_t newHeight) |
virtual int32_t | GetWidth () const |
int32_t | GetXPitch () const |
int32_t | GetYPitch () const |
virtual int32_t | GetDepth () const |
uint32_t | GetBytesPerPixel () const |
virtual size_t | GetSize () const |
void | SetPixels (uint32_t *pBits, int32_t width, int32_t height, Ownership ownership=Ownership::Private) |
void | SetPixel (int32_t x, int32_t y, const CYIColor &color) |
virtual void | SetPixelPacked (int32_t x, int32_t y, uint32_t color) |
void | SetPixelRaw (int32_t x, int32_t y, uint32_t color) |
CYIColor | GetPixel (int32_t x, int32_t y) const |
virtual uint32_t | GetPixelPacked (int32_t x, int32_t y) const |
uint32_t | GetPixelRaw (int32_t x, int32_t y) const |
ColorMode | GetColorMode () const |
std::unique_ptr< CYIBitmap > | ToColorMode (ColorMode colorMode, DitheringMode ditheringMode=DitheringMode::None) const |
bool | operator== (const CYIBitmap &other) const |
bool | operator!= (const CYIBitmap &other) const |
Friends | |
class | CYIBitmapPriv |
|
strong |
The color modes that this bitmap class supports. By default, bitmaps use CYIBitmap::ColorMode::RGBA8888.
|
strong |
The dithering modes that can be used when converting between color modes.
Enumerator | |
---|---|
None | No dithering. |
FloydSteinberg | Indicates that Floyd-Steinberg dithering should be used. |
|
strong |
Enumerator | |
---|---|
Shared | Memory is managed by the application and it is responsible for deleting it |
Private | Memory is managed by CYIBitmap and must not be deleted |
CYIBitmap::CYIBitmap | ( | ) |
|
virtual |
std::unique_ptr<CYIBitmap> CYIBitmap::Clone | ( | ) | const |
Create an exact copy of this bitmap.
|
virtual |
Creates an bitmap image of the specified size. The created image uses a 32 bit ABGR (high to low byte packed) color encoding format.
void CYIBitmap::Draw | ( | const CYIBitmap & | srcImage, |
int32_t | destX, | ||
int32_t | destY | ||
) |
Draw the source image at the specified coordinates. The source image will be clipped if its dimensions exceed the boundaries of this bitmap.
void CYIBitmap::Draw | ( | const CYIBitmap & | srcImage, |
int32_t | destX, | ||
int32_t | destY, | ||
const YI_RECT_REL & | clipRegion | ||
) |
Draw the source image at the destination coordinates and clip it against the specified clipping region. The region defaults to a zero width and height and will be ignored by default.
void CYIBitmap::Draw | ( | const CYIBitmap & | srcImage, |
int32_t | destX, | ||
int32_t | destY, | ||
int32_t | clipWidth, | ||
int32_t | clipHeight | ||
) |
The following method is a convenience method for the above function. It assumes the clipping region begins at (0, 0) of the source image.
void CYIBitmap::DrawScale | ( | const CYIBitmap & | srcImage, |
const YI_RECT_REL * | pDest, | ||
const YI_RECT_REL * | pSrc | ||
) |
Draw a source image region, onto a destination image region, scaling up or down into destination and not preserving aspect ratios. If source or destination regions are ommitted, entire image regions are uses
void CYIBitmap::Fill | ( | const CYIColor & | color | ) |
Fills the buffer with the specified color.
Fills the buffer with the specified color.
void CYIBitmap::FreePixels | ( | ) |
Destroys the buffer of pixels associated with this bitmap.
uint32_t CYIBitmap::GetBytesPerPixel | ( | ) | const |
Returns the number of bytes used for a single pixel. Equivalent to GetDepth() / 8
.
ColorMode CYIBitmap::GetColorMode | ( | ) | const |
Returns the color mode of this bitmap. By default, bitmaps use the CYIBitmap::ColorMode::RGBA8888 color mode.
|
virtual |
Returns the color depth of the bitmap.
|
virtual |
Returns the height of this buffer in pixels.
CYIColor CYIBitmap::GetPixel | ( | int32_t | x, |
int32_t | y | ||
) | const |
Returns the pixel color at the specified coordinate.
|
virtual |
Returns the pixel color at the specified coordinate. The returned color is in RGBA packed format.
uint32_t CYIBitmap::GetPixelRaw | ( | int32_t | x, |
int32_t | y | ||
) | const |
Returns the pixel color at the specified coordinate. The format of the returned color depends on the color mode of this bitmap.
const uint32_t* CYIBitmap::GetPixels | ( | ) | const |
Returns the pixels representing this image; the pixel format used by the bitmap class is ABGR. Do not delete these pixels and do not attempt to use them if new pixels are set.
uint32_t* CYIBitmap::GetPixels | ( | ) |
Returns the pixels representing this image; the pixel format used by the bitmap class is ABGR. Do not delete these pixels and do not attempt to use them if new pixels are set.
|
virtual |
Returns the size of the buffer in bytes used to hold the bitmap data.
|
virtual |
Returns the width of this buffer in pixels.
int32_t CYIBitmap::GetXPitch | ( | ) | const |
Returns the distance, in bytes, between two horizontal pixels. In all cases this is equivalent to GetBytesPerPixel()
.
int32_t CYIBitmap::GetYPitch | ( | ) | const |
Returns the distance, in bytes, between two vertical pixels. In most cases this is equal to GetWidth() * GetBytesPerPixel()
, but for some color modes rows are required to be aligned to 4 bytes and the Y pitch can be different. Use this value when reading from the raw pixels pointer and incrementing by one row.
bool CYIBitmap::operator!= | ( | const CYIBitmap & | other | ) | const |
Returns true if other contains different pixel data or has a different configuration than this bitmap. Returns false otherwise;
bool CYIBitmap::operator== | ( | const CYIBitmap & | other | ) | const |
Returns true if other contains the same pixel data and has the same configuration as this bitmap. Returns false otherwise.
void CYIBitmap::ReduceHeightTo | ( | int32_t | newHeight | ) |
Crops the image by discarding the bottom lines such that the final height is newHeight Does not cause a memory reallocation, but memory used by the discarded lines is wasted. No effect if newHeight is greater than the current height.
void CYIBitmap::SetPixel | ( | int32_t | x, |
int32_t | y, | ||
const CYIColor & | color | ||
) |
Sets a pixel color at the specified coordinate.
|
virtual |
Sets a pixel color at the specified coordinate. The color is expected to be in RGBA packed format.
void CYIBitmap::SetPixelRaw | ( | int32_t | x, |
int32_t | y, | ||
uint32_t | color | ||
) |
Sets a pixel color at the specified coordinate. The format of the color needs to match the format used by the color mode of this bitmap.
void CYIBitmap::SetPixels | ( | uint32_t * | pBits, |
int32_t | width, | ||
int32_t | height, | ||
Ownership | ownership = Ownership::Private |
||
) |
Set the bits used by this bitmap. The old bitmap will be deleted. If the ownership is Private, pBits has to have been allocated using YI_MALLOC.
std::unique_ptr<CYIBitmap> CYIBitmap::ToColorMode | ( | ColorMode | colorMode, |
DitheringMode | ditheringMode = DitheringMode::None |
||
) | const |
Creates and returns a new CYIBitmap with the specified color mode. When converting to a non-32bit color mode, a dithering mode can be specified.
|
friend |