24 Load(filesystem, assetPath);
30 Bitmap(
const glm::uvec2& size, uint32_t bytesPerPixel = 4)
32 , bytes_per_pixel_(bytesPerPixel)
34 data_.resize(CalculateLength(size, bytesPerPixel));
41 Bitmap(
const std::vector<uint8_t>& data,
const glm::uvec2& size, uint32_t bytesPerPixel = 4)
44 , bytes_per_pixel_(bytesPerPixel)
60 bool Write(
const std::filesystem::path& path)
const;
64 explicit operator bool() const noexcept
66 return !data_.empty();
75 const std::string& GetFilename()
const
79 void SetFilename(
const std::string& f)
84 const std::vector<uint8_t>& GetData()
const
88 std::vector<uint8_t>& GetData()
92 void SetData(
const std::vector<uint8_t>& d)
96 void SetData(std::vector<uint8_t>&& d)
101 const glm::uvec2& GetSize()
const
105 void SetSize(
const glm::uvec2& s)
110 uint32_t GetBytesPerPixel()
const
112 return bytes_per_pixel_;
114 void SetBytesPerPixel(uint32_t bpp)
116 bytes_per_pixel_ = bpp;
121 static uint32_t CalculateLength(
const glm::uvec2& size, uint32_t bytesPerPixel);
124 std::string filename_;
125 std::vector<uint8_t> data_;
126 glm::uvec2 size_{ 0, 0 };
127 uint32_t bytes_per_pixel_ = 0;
A simple Bitmap class that loads and writes images using lodepng.
Definition bitmap.h:17
uint32_t GetLength() const
Returns the total number of bytes in the image.
Definition bitmap.cc:27
bool Write(const std::filesystem::path &path) const
Writes the bitmap as a PNG to the given filesystem path.
Definition bitmap.cc:75
Bitmap(const glm::uvec2 &size, uint32_t bytesPerPixel=4)
Constructs an empty bitmap of the given size.
Definition bitmap.h:30
Bitmap(const std::vector< uint8_t > &data, const glm::uvec2 &size, uint32_t bytesPerPixel=4)
Constructs a bitmap with preloaded image data.
Definition bitmap.h:41
Bitmap()=default
Default constructor.
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....
Definition bitmap.cc:40
Definition filesystem.h:16
Definition virtual_path.h:10