6#include "png++/png.hpp"
13ChainableResult<std::unique_ptr<Image<Rgba32>>, ImageLoadError>
20 png::image<png::rgba_pixel> png{};
22 png.read(path.string());
24 catch (
const std::exception &e) {
28 const auto width =
static_cast<std::size_t
>(png.get_width());
29 const auto height =
static_cast<std::size_t
>(png.get_height());
33 for (std::size_t row = 0; row < height; ++row) {
34 for (std::size_t col = 0; col < width; ++col) {
35 const auto &pixel = png[row][col];
36 image.
set(row, col,
Rgba32{pixel.
red, pixel.green, pixel.blue, pixel.alpha});
40 return std::make_unique<Image<Rgba32>>(std::move(image));
A template for two-dimensional images with arbitrarily typed pixel values.
void set(std::size_t i, PixelType pixel)
Sets the pixel value at a given one-dimensional pixel index.
ChainableResult< std::unique_ptr< Image< Rgba32 > >, ImageLoadError > load_from_file(const std::filesystem::path &path) const
Represents a 32-bit RGBA color.