PixelBullet  0.0.1
A C++ game engine
Loading...
Searching...
No Matches
PixelBullet::Bitmap Class Reference

A simple Bitmap class that loads and writes images using stb. More...

#include <Bitmap.hpp>

Public Member Functions

 Bitmap ()=default
 Default constructor.
 
 Bitmap (const VirtualPath &assetPath)
 Constructs a bitmap from an asset path.
 
 Bitmap (const glm::uvec2 &size, uint32_t bytesPerPixel=4)
 Constructs an empty bitmap of the given size.
 
 Bitmap (const std::vector< uint8_t > &data, const glm::uvec2 &size, uint32_t bytesPerPixel=4)
 Constructs a bitmap with preloaded image data.
 
bool Load (const VirtualPath &assetPath)
 Loads an image from the given asset path. This function uses stb_image to load an image from memory. The asset path should have been resolved already (via your asset system).
 
bool Write (const VirtualPath &assetPath) const
 Writes the bitmap as a PNG to the given asset path.
 
 operator bool () const noexcept
 Implicit conversion to bool. Returns true if the bitmap contains valid data.
 
uint32_t GetLength () const
 Returns the total number of bytes in the image.
 
void Clear ()
 
const std::string & GetFilename () const
 
void SetFilename (const std::string &f)
 
const std::vector< uint8_t > & GetData () const
 
std::vector< uint8_t > & GetData ()
 
void SetData (const std::vector< uint8_t > &d)
 
void SetData (std::vector< uint8_t > &&d)
 
const glm::uvec2 & GetSize () const
 
void SetSize (const glm::uvec2 &s)
 
uint32_t GetBytesPerPixel () const
 
void SetBytesPerPixel (uint32_t bpp)
 

Detailed Description

A simple Bitmap class that loads and writes images using stb.

Constructor & Destructor Documentation

◆ Bitmap() [1/4]

PixelBullet::Bitmap::Bitmap ( )
default

Default constructor.

◆ Bitmap() [2/4]

PixelBullet::Bitmap::Bitmap ( const VirtualPath & assetPath)
inlineexplicit

Constructs a bitmap from an asset path.

Parameters
assetPathA fully resolved path to the image asset.

◆ Bitmap() [3/4]

PixelBullet::Bitmap::Bitmap ( const glm::uvec2 & size,
uint32_t bytesPerPixel = 4 )
inline

Constructs an empty bitmap of the given size.

Parameters
sizeThe image dimensions.
bytesPerPixelThe number of bytes per pixel (default is 4 for RGBA).

◆ Bitmap() [4/4]

PixelBullet::Bitmap::Bitmap ( const std::vector< uint8_t > & data,
const glm::uvec2 & size,
uint32_t bytesPerPixel = 4 )
inline

Constructs a bitmap with preloaded image data.

Parameters
dataThe raw image data.
sizeThe image dimensions.
bytesPerPixelThe number of bytes per pixel.

Member Function Documentation

◆ GetLength()

uint32_t PixelBullet::Bitmap::GetLength ( ) const

Returns the total number of bytes in the image.

◆ Load()

bool PixelBullet::Bitmap::Load ( const VirtualPath & assetPath)

Loads an image from the given asset path. This function uses stb_image to load an image from memory. The asset path should have been resolved already (via your asset system).

Parameters
assetPathThe path to the image file.
Returns
True on success, false otherwise.

◆ operator bool()

PixelBullet::Bitmap::operator bool ( ) const
inlineexplicitnoexcept

Implicit conversion to bool. Returns true if the bitmap contains valid data.

◆ Write()

bool PixelBullet::Bitmap::Write ( const VirtualPath & assetPath) const

Writes the bitmap as a PNG to the given asset path.

Parameters
assetPathThe output path (directories will be created if needed).
Returns
True on success, false otherwise.

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