Aegis2D
Modular C++26 2D game engine for networked games
Loading...
Searching...
No Matches
image.hpp
Go to the documentation of this file.
1
3#pragma once
4
6#include <aegis2d/render/export.hpp>
7
8#include <cstdint>
9#include <filesystem>
10#include <stdexcept>
11#include <vector>
12
13namespace aegis2d::render {
14
17class AEGIS2D_RENDER_EXPORT ImageError : public std::runtime_error {
18public:
19 using std::runtime_error::runtime_error;
20};
21
25struct AEGIS2D_RENDER_EXPORT Image {
27 int width = 0;
29 int height = 0;
31 std::vector<std::uint8_t> pixels;
32
39 [[nodiscard]] static Image load(const std::filesystem::path& path);
40
48 [[nodiscard]] static Image from_pixels(int width, int height, std::vector<std::uint8_t> pixels);
49
54 void save_png(const std::filesystem::path& path) const;
55
58 [[nodiscard]] bool empty() const noexcept;
59
65 [[nodiscard]] Color pixel(int x, int y) const;
66};
67
68} // namespace aegis2d::render
Thrown when an image cannot be read, decoded or written.
Definition image.hpp:17
RGBA color used by the renderer.
OpenGL renderer: sprites, text and camera (client only).
Definition bitmap_font.hpp:16
RGBA color with components in [0, 1].
Definition color.hpp:10
RGBA image with 8 bits per channel, ready to become a texture.
Definition image.hpp:25
std::vector< std::uint8_t > pixels
width * height * 4 bytes.
Definition image.hpp:31
void save_png(const std::filesystem::path &path) const
Writes the image as a PNG file, creating its folder.
static Image from_pixels(int width, int height, std::vector< std::uint8_t > pixels)
Wraps pixels generated in memory, such as marker_image().
static Image load(const std::filesystem::path &path)
Reads an image file.
bool empty() const noexcept
Tells whether the image has no pixel.