Geometrize 1.0
C++ library for geometrizing images into geometric primitives
Public Member Functions | Private Attributes | List of all members
geometrize::Bitmap Class Reference

The Bitmap class is a helper class for working with bitmap data. More...

#include <bitmap.h>

Public Member Functions

 Bitmap (std::uint32_t width, std::uint32_t height, geometrize::rgba color)
 Bitmap Creates a new bitmap. More...
 
 Bitmap (std::uint32_t width, std::uint32_t height, const std::vector< std::uint8_t > &data)
 Bitmap Creates a new bitmap from the supplied byte data. More...
 
 ~Bitmap ()=default
 
Bitmapoperator= (const geometrize::Bitmap &)=default
 
 Bitmap (const geometrize::Bitmap &)=default
 
std::uint32_t getWidth () const
 getWidth Gets the width of the bitmap. More...
 
std::uint32_t getHeight () const
 getHeight Gets the height of the bitmap. More...
 
std::vector< std::uint8_t > copyData () const
 copyData Gets a copy of the raw bitmap data. More...
 
const std::vector< std::uint8_t > & getDataRef () const
 getDataRef Gets a reference to the raw bitmap data. More...
 
geometrize::rgba getPixel (std::uint32_t x, std::uint32_t y) const
 getPixel Gets a pixel color value. More...
 
void setPixel (std::uint32_t x, std::uint32_t y, geometrize::rgba color)
 setPixel Sets a pixel color value. More...
 
void fill (geometrize::rgba color)
 fill Fills the bitmap with the given color. More...
 

Private Attributes

std::uint32_t m_width
 The width of the bitmap. More...
 
std::uint32_t m_height
 The height of the bitmap. More...
 
std::vector< std::uint8_t > m_data
 The bitmap data. More...
 

Detailed Description

The Bitmap class is a helper class for working with bitmap data.

Author
Sam Twidale (https://samcodes.co.uk/)

Constructor & Destructor Documentation

◆ Bitmap() [1/3]

geometrize::Bitmap::Bitmap ( std::uint32_t  width,
std::uint32_t  height,
geometrize::rgba  color 
)

Bitmap Creates a new bitmap.

Parameters
widthThe width of the bitmap.
heightThe height of the bitmap.
colorThe starting color of the bitmap (RGBA format).
10 : m_width{width}, m_height{height}, m_data(width * height * 4U)
11{
12 fill(color);
13}
std::vector< std::uint8_t > m_data
The bitmap data.
Definition: bitmap.h:85
void fill(geometrize::rgba color)
fill Fills the bitmap with the given color.
Definition: bitmap.cpp:55
std::uint32_t m_height
The height of the bitmap.
Definition: bitmap.h:84
std::uint32_t m_width
The width of the bitmap.
Definition: bitmap.h:83
Here is the call graph for this function:

◆ Bitmap() [2/3]

geometrize::Bitmap::Bitmap ( std::uint32_t  width,
std::uint32_t  height,
const std::vector< std::uint8_t > &  data 
)

Bitmap Creates a new bitmap from the supplied byte data.

Parameters
widthThe width of the bitmap.
heightThe height of the bitmap.
dataThe byte data to fill the bitmap with, must be width * height * depth (4) long.
15 : m_width{width}, m_height{height}, m_data{data}
16{
17 assert((width * height * 4U) == data.size());
18}

◆ ~Bitmap()

geometrize::Bitmap::~Bitmap ( )
default

◆ Bitmap() [3/3]

geometrize::Bitmap::Bitmap ( const geometrize::Bitmap )
default

Member Function Documentation

◆ copyData()

std::vector< std::uint8_t > geometrize::Bitmap::copyData ( ) const

copyData Gets a copy of the raw bitmap data.

Returns
The bitmap data.
31{
32 return m_data;
33}

◆ fill()

void geometrize::Bitmap::fill ( geometrize::rgba  color)

fill Fills the bitmap with the given color.

Parameters
colorThe color to fill the bitmap with.
56{
57 for(std::size_t i = 0; i < m_data.size(); i += 4U) {
58 m_data[i] = color.r;
59 m_data[i + 1U] = color.g;
60 m_data[i + 2U] = color.b;
61 m_data[i + 3U] = color.a;
62 }
63}
std::uint8_t a
‍The blue component (0-255).
Definition: rgba.h:17
std::uint8_t g
‍The red component (0-255).
Definition: rgba.h:15
std::uint8_t r
Definition: rgba.h:14
std::uint8_t b
‍The green component (0-255).
Definition: rgba.h:16
Here is the caller graph for this function:

◆ getDataRef()

const std::vector< std::uint8_t > & geometrize::Bitmap::getDataRef ( ) const

getDataRef Gets a reference to the raw bitmap data.

Returns
The bitmap data.
36{
37 return m_data;
38}
Here is the caller graph for this function:

◆ getHeight()

std::uint32_t geometrize::Bitmap::getHeight ( ) const

getHeight Gets the height of the bitmap.

26{
27 return m_height;
28}
Here is the caller graph for this function:

◆ getPixel()

geometrize::rgba geometrize::Bitmap::getPixel ( std::uint32_t  x,
std::uint32_t  y 
) const

getPixel Gets a pixel color value.

Parameters
xThe x-coordinate of the pixel.
yThe y-coordinate of the pixel.
Returns
The pixel RGBA color value.
41{
42 const std::size_t index{(m_width * y + x) * 4U};
43 return geometrize::rgba{m_data[index], m_data[index + 1U], m_data[index + 2U], m_data[index + 3U]};
44}
The rgba struct is a helper for manipulating RGBA8888 color data.
Definition: rgba.h:13
Here is the caller graph for this function:

◆ getWidth()

std::uint32_t geometrize::Bitmap::getWidth ( ) const

getWidth Gets the width of the bitmap.

21{
22 return m_width;
23}
Here is the caller graph for this function:

◆ operator=()

Bitmap & geometrize::Bitmap::operator= ( const geometrize::Bitmap )
default

◆ setPixel()

void geometrize::Bitmap::setPixel ( std::uint32_t  x,
std::uint32_t  y,
geometrize::rgba  color 
)

setPixel Sets a pixel color value.

Parameters
xThe x-coordinate of the pixel.
yThe y-coordinate of the pixel.
colorThe pixel RGBA color value.
47{
48 const std::uint32_t index{(m_width * y + x) * 4U};
49 m_data[index] = color.r;
50 m_data[index + 1U] = color.g;
51 m_data[index + 2U] = color.b;
52 m_data[index + 3U] = color.a;
53}
Here is the caller graph for this function:

Member Data Documentation

◆ m_data

std::vector<std::uint8_t> geometrize::Bitmap::m_data
private

The bitmap data.

◆ m_height

std::uint32_t geometrize::Bitmap::m_height
private

The height of the bitmap.

◆ m_width

std::uint32_t geometrize::Bitmap::m_width
private

The width of the bitmap.


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