31 Bitmap(
const glm::uvec2& size, uint32_t bytesPerPixel = 4)
33 , m_BytesPerPixel(bytesPerPixel)
35 m_Data.resize(CalculateLength(size, bytesPerPixel));
42 Bitmap(
const std::vector<uint8_t>& data,
const glm::uvec2& size, uint32_t bytesPerPixel = 4)
45 , m_BytesPerPixel(bytesPerPixel)
65 explicit operator bool() const noexcept
67 return !m_Data.empty();
76 const std::string& GetFilename()
const
80 void SetFilename(
const std::string& f)
85 const std::vector<uint8_t>& GetData()
const
89 std::vector<uint8_t>& GetData()
93 void SetData(
const std::vector<uint8_t>& d)
97 void SetData(std::vector<uint8_t>&& d)
99 m_Data = std::move(d);
102 const glm::uvec2& GetSize()
const
106 void SetSize(
const glm::uvec2& s)
111 uint32_t GetBytesPerPixel()
const
113 return m_BytesPerPixel;
115 void SetBytesPerPixel(uint32_t bpp)
117 m_BytesPerPixel = bpp;
122 static uint32_t CalculateLength(
const glm::uvec2& size, uint32_t bytesPerPixel);
125 std::string m_Filename;
126 std::vector<uint8_t> m_Data;
127 glm::uvec2 m_Size{ 0, 0 };
128 uint32_t m_BytesPerPixel = 0;
A simple Bitmap class that loads and writes images using stb.
Definition Bitmap.hpp:16
Bitmap(const std::vector< uint8_t > &data, const glm::uvec2 &size, uint32_t bytesPerPixel=4)
Constructs a bitmap with preloaded image data.
Definition Bitmap.hpp:42
Bitmap()=default
Default constructor.
uint32_t GetLength() const
Returns the total number of bytes in the image.
Definition Bitmap.cpp:18
Bitmap(const glm::uvec2 &size, uint32_t bytesPerPixel=4)
Constructs an empty bitmap of the given size.
Definition Bitmap.hpp:31
bool Write(const VirtualPath &assetPath) const
Writes the bitmap as a PNG to the given asset path.
Definition Bitmap.cpp:71
bool Load(const VirtualPath &assetPath)
Loads an image from the given asset path. This function uses stb_image to load an image from memory....
Definition Bitmap.cpp:31
Bitmap(const VirtualPath &assetPath)
Constructs a bitmap from an asset path.
Definition Bitmap.hpp:23
Definition VirtualPath.hpp:11