6#include "png++/png.hpp"
14ChainableResult<std::unique_ptr<Image<IndexPixel>>>
18 return FormattableError{std::format(
"file does not exist: {}", path.string())};
23 png::image<png::index_pixel> test{path};
25 catch (std::exception &) {
29 png::image<png::index_pixel> png{path};
30 const auto tilesheet_width = png.get_width();
31 const auto tilesheet_height = png.get_height();
32 const auto tilesheet_size = tilesheet_width * tilesheet_height;
35 const auto &png_pal = png.get_palette();
36 std::vector<Rgba32> rgba_pal;
37 rgba_pal.reserve(png_pal.size());
38 for (
const auto &color : png_pal) {
42 auto image = std::make_unique<Image<IndexPixel>>(tilesheet_width, tilesheet_height, std::move(rgba_pal));
43 for (std::size_t pixel_index = 0; pixel_index < tilesheet_size; pixel_index++) {
44 const auto row = pixel_index / tilesheet_width;
45 const auto col = pixel_index % tilesheet_width;
46 image->set(pixel_index,
IndexPixel{png[row][col]});
Represents an indexed color pixel.
ChainableResult< std::unique_ptr< Image< IndexPixel > > > load_from_file(const std::filesystem::path &path) const
static constexpr std::uint8_t alpha_opaque
static const Style bold
Bold text formatting.