You.i Engine
CYIBitmap Class Reference

Detailed Description

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< CYIBitmapClone () 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 &region)
 
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< CYIBitmapToColorMode (ColorMode colorMode, DitheringMode ditheringMode=DitheringMode::None) const
 
bool operator== (const CYIBitmap &other) const
 
bool operator!= (const CYIBitmap &other) const
 

Friends

class CYIBitmapPriv
 

Member Enumeration Documentation

◆ ColorMode

enum CYIBitmap::ColorMode
strong

The color modes that this bitmap class supports. By default, bitmaps use CYIBitmap::ColorMode::RGBA8888.

See also
ToColorMode
Enumerator
RGBA8888 

Four channel color with 8 bits per color. The 'red' component is at the lowest bits of the 32 bit words.

RGBA4444 

Four channel color with 4 bits per color. The 'red' component is at the lowest bits of the 16 bit words.

RGB565 

Three channel color with 5 bits for the red channel, 6 bits for the green channel and 5 bits for the blue channel. The 'red' component is at the lowest bits of the 16 bit words.

◆ DitheringMode

The dithering modes that can be used when converting between color modes.

See also
ToColorMode
Enumerator
None 

No dithering.

FloydSteinberg 

Indicates that Floyd-Steinberg dithering should be used.

◆ Ownership

enum CYIBitmap::Ownership
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

Constructor & Destructor Documentation

◆ CYIBitmap()

CYIBitmap::CYIBitmap ( )

◆ ~CYIBitmap()

virtual CYIBitmap::~CYIBitmap ( )
virtual

Member Function Documentation

◆ Clone()

std::unique_ptr<CYIBitmap> CYIBitmap::Clone ( ) const

Create an exact copy of this bitmap.

◆ Create()

virtual bool CYIBitmap::Create ( int32_t  width,
int32_t  height 
)
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.

◆ Draw() [1/3]

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.

Warning
This function has undefined behaviour when the color mode of this bitmap or of the source bitmap is not CYIBitmap::ColorMode::RGBA8888.

◆ Draw() [2/3]

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.

Warning
This function has undefined behaviour when the color mode of this bitmap or of the source bitmap is not CYIBitmap::ColorMode::RGBA8888.

◆ Draw() [3/3]

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.

Warning
This function has undefined behaviour when the color mode of this bitmap or of the source bitmap is not CYIBitmap::ColorMode::RGBA8888.

◆ DrawScale()

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

Warning
This function has undefined behaviour when the color mode of this bitmap or of the source bitmap is not CYIBitmap::ColorMode::RGBA8888.

◆ Fill() [1/2]

void CYIBitmap::Fill ( const CYIColor color)

Fills the buffer with the specified color.

◆ Fill() [2/2]

void CYIBitmap::Fill ( const CYIColor color,
const YI_RECT region 
)

Fills the buffer with the specified color.

◆ FreePixels()

void CYIBitmap::FreePixels ( )

Destroys the buffer of pixels associated with this bitmap.

◆ GetBytesPerPixel()

uint32_t CYIBitmap::GetBytesPerPixel ( ) const

Returns the number of bytes used for a single pixel. Equivalent to GetDepth() / 8.

◆ GetColorMode()

ColorMode CYIBitmap::GetColorMode ( ) const

Returns the color mode of this bitmap. By default, bitmaps use the CYIBitmap::ColorMode::RGBA8888 color mode.

See also
CYIBitmap::ColorMode

◆ GetDepth()

virtual int32_t CYIBitmap::GetDepth ( ) const
virtual

Returns the color depth of the bitmap.

◆ GetHeight()

virtual int32_t CYIBitmap::GetHeight ( ) const
virtual

Returns the height of this buffer in pixels.

◆ GetPixel()

CYIColor CYIBitmap::GetPixel ( int32_t  x,
int32_t  y 
) const

Returns the pixel color at the specified coordinate.

◆ GetPixelPacked()

virtual uint32_t CYIBitmap::GetPixelPacked ( int32_t  x,
int32_t  y 
) const
virtual

Returns the pixel color at the specified coordinate. The returned color is in RGBA packed format.

See also
CYIColor::ByteOrder

◆ GetPixelRaw()

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.

See also
GetColorMode

◆ GetPixels() [1/2]

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.

◆ GetPixels() [2/2]

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.

◆ GetSize()

virtual size_t CYIBitmap::GetSize ( ) const
virtual

Returns the size of the buffer in bytes used to hold the bitmap data.

◆ GetWidth()

virtual int32_t CYIBitmap::GetWidth ( ) const
virtual

Returns the width of this buffer in pixels.

◆ GetXPitch()

int32_t CYIBitmap::GetXPitch ( ) const

Returns the distance, in bytes, between two horizontal pixels. In all cases this is equivalent to GetBytesPerPixel().

See also
GetPixels()

◆ GetYPitch()

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.

See also
GetPixels()

◆ operator!=()

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;

◆ operator==()

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.

◆ ReduceHeightTo()

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.

◆ SetPixel()

void CYIBitmap::SetPixel ( int32_t  x,
int32_t  y,
const CYIColor color 
)

Sets a pixel color at the specified coordinate.

◆ SetPixelPacked()

virtual void CYIBitmap::SetPixelPacked ( int32_t  x,
int32_t  y,
uint32_t  color 
)
virtual

Sets a pixel color at the specified coordinate. The color is expected to be in RGBA packed format.

See also
CYIColor::ByteOrder

◆ SetPixelRaw()

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.

See also
GetColorMode

◆ SetPixels()

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.

Warning
The color format of the provided bits must match that of the bitmap. If the bitmap has a depth of 16 bits, the provided pointer will be reintepreted as a pointer to 16 bit words.
See also
GetColorMode

◆ ToColorMode()

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.

Friends And Related Function Documentation

◆ CYIBitmapPriv

friend class CYIBitmapPriv
friend

The documentation for this class was generated from the following file: