gempyre  1.7.1
Gempyre::Bitmap Class Reference

Bitmap for Gempyre Graphics. More...

#include <gempyre_bitmap.h>

Public Member Functions

 Bitmap (int width, int height)
 Constructor - uninitialized data. More...
 
 Bitmap (int width, int height, Gempyre::Color::type color)
 Constructor - with a single color data. More...
 
 Bitmap ()
 Constructor - zero size, use. More...
 
 Bitmap (Bitmap &&other)=default
 Move constructor.
 
 Bitmap (const Bitmap &other)=default
 Copy constructor - does not copy the data, for deep copy. More...
 
 ~Bitmap ()
 Destructor.
 
 Bitmap (const std::vector< uint8_t > &image_data)
 Create bitmap from byte array. More...
 
std::vector< uint8_t > png_image () const
 Convert a bitmap to PNG. More...
 
Bitmapoperator= (const Bitmap &other)=default
 Copy operator does only shallow copy, for deep copy. More...
 
Bitmapoperator= (Bitmap &&other)=default
 Move operator.
 
void create (int width, int height)
 Create bitmap bytes. More...
 
Bitmap clone () const
 Deep copy bitmap bytes.
 
void set_pixel (int x, int y, Color::type color)
 Set a single pixel.
 
void set_alpha (int x, int y, Color::type alpha)
 Set a singe pixel's alpha value.
 
Color::type pixel (int x, int y) const
 Get a single pixel.
 
int width () const
 Get width.
 
int height () const
 Get height.
 
void swap (Bitmap &other)
 Swap bitmap data with another.
 
void draw_rect (const Gempyre::Rect &rect, Color::type color)
 Draw a rect with a color in bitmap.
 
void merge (int x, int y, const Bitmap &other)
 Draw a Bitmap on this bitmap - merge alpha.

 
void merge (const Bitmap &other)
 Draw a Bitmap on this bitmap - merge alpha.

 
void tile (int x, int y, const Bitmap &other)
 Draw a Bitmap on this bitmap - replace area.

 
void tile (int x, int y, const Bitmap &other, int width, int height)
 Draw a Bitmap withing extents on this bitmap - replace area.

 
void tile (int x, int y, const Bitmap &other, int other_x, int other_y, int width, int height)
 Draw a Bitmap withing extents on this bitmap - replace area.

 
Bitmap clip (const Gempyre::Rect &rect) const
 Create a new bitmap from part of bitmap.
 
bool empty () const
 return true if there is not data

 
const uint8_t * const_data () const
 underlaying data
 
template<class T , std::enable_if_t< std::is_same_v< typename T::value_type, Color::type >, int > = 0>
bool set_data (const T &bytes, size_t offset=0)
 Copy pixels into bitmap. More...
 

Static Public Member Functions

static constexpr Color::type pix (Color::type r, Color::type g, Color::type b, Color::type a=0xFF)
 Components to pixel type.
 

Friends

class Gempyre::CanvasElement
 

Detailed Description

Bitmap for Gempyre Graphics.

Constructor & Destructor Documentation

◆ Bitmap() [1/5]

Gempyre::Bitmap::Bitmap ( int  width,
int  height 
)

Constructor - uninitialized data.

Parameters
width
height

◆ Bitmap() [2/5]

Gempyre::Bitmap::Bitmap ( int  width,
int  height,
Gempyre::Color::type  color 
)

Constructor - with a single color data.

Parameters
width
height
color

◆ Bitmap() [3/5]

Gempyre::Bitmap::Bitmap ( )

Constructor - zero size, use.

See also
create() to create the actual bitmap.

◆ Bitmap() [4/5]

Gempyre::Bitmap::Bitmap ( const Bitmap other)
default

Copy constructor - does not copy the data, for deep copy.

See also
clone()

◆ Bitmap() [5/5]

Gempyre::Bitmap::Bitmap ( const std::vector< uint8_t > &  image_data)

Create bitmap from byte array.

Parameters
image_dataPNG image in bytes.
Note
const auto bytes = GempyreUtils::slurp<uint8_t>("image.png");
Bitmap bmp(bytes);
Bitmap()
Constructor - zero size, use.

Member Function Documentation

◆ create()

void Gempyre::Bitmap::create ( int  width,
int  height 
)

Create bitmap bytes.

Parameters
width
height

◆ operator=()

Bitmap& Gempyre::Bitmap::operator= ( const Bitmap other)
default

Copy operator does only shallow copy, for deep copy.

See also
clone()

◆ png_image()

std::vector<uint8_t> Gempyre::Bitmap::png_image ( ) const

Convert a bitmap to PNG.

Returns
PNG bytes

◆ set_data()

template<class T , std::enable_if_t< std::is_same_v< typename T::value_type, Color::type >, int > = 0>
bool Gempyre::Bitmap::set_data ( const T &  bytes,
size_t  offset = 0 
)
inline

Copy pixels into bitmap.

Parameters
bytes(TODO will change to std::span when moving to C++20)
offset
Returns
false on overflow, otherwise true

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