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 lodepng. More...

#include <bitmap.h>

Public Member Functions

 Bitmap ()=default
 Default constructor.
 
 Bitmap (const Filesystem &filesystem, const VirtualPath &assetPath)
 
 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 Filesystem &filesystem, 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 std::filesystem::path &path) const
 Writes the bitmap as a PNG to the given filesystem 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 lodepng.

Constructor & Destructor Documentation

◆ Bitmap() [1/3]

pixelbullet::Bitmap::Bitmap ( )
default

Default constructor.

◆ Bitmap() [2/3]

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() [3/3]

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 Filesystem & filesystem,
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 std::filesystem::path & path) const

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

Parameters
pathThe 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: