6#include "png++/png.hpp"
13Result<std::unique_ptr<Image<IndexPixel>>>
17 return std::unexpected{fmt::format(
"file does not exist: {}", path.string())};
22 png::image<png::index_pixel> test{path};
24 catch (std::exception &) {
25 return std::unexpected{fmt::format(
"file not a valid indexed PNG: {}", path.string())};
28 png::image<png::index_pixel> tilesheet_png{path};
29 const auto tilesheet_width = tilesheet_png.get_width();
30 const auto tilesheet_height = tilesheet_png.get_height();
31 const auto tilesheet_size = tilesheet_width * tilesheet_height;
32 auto image = std::make_unique<Image<IndexPixel>>(tilesheet_width, tilesheet_height);
33 for (
unsigned int pixel_index = 0; pixel_index < tilesheet_size; pixel_index++) {
34 const auto row = pixel_index / tilesheet_width;
35 const auto col = pixel_index % tilesheet_width;
37 image->set(pixel_index,
IndexPixel{tilesheet_png[row][col]});
Represents an indexed color pixel.
Result< std::unique_ptr< Image< IndexPixel > > > load_from_file(const std::filesystem::path &path) const