Aegis2D
Modular C++26 2D game engine for networked games
Loading...
Searching...
No Matches
aegis2d::render::Image Struct Reference

RGBA image with 8 bits per channel, ready to become a texture. More...

#include <aegis2d/render/image.hpp>

Public Member Functions

void save_png (const std::filesystem::path &path) const
 Writes the image as a PNG file, creating its folder.
 
bool empty () const noexcept
 Tells whether the image has no pixel.
 
Color pixel (int x, int y) const
 Color of one pixel.
 

Static Public Member Functions

static Image load (const std::filesystem::path &path)
 Reads an image file.
 
static Image from_pixels (int width, int height, std::vector< std::uint8_t > pixels)
 Wraps pixels generated in memory, such as marker_image().
 

Public Attributes

int width = 0
 Width in pixels.
 
int height = 0
 Height in pixels.
 
std::vector< std::uint8_t > pixels
 width * height * 4 bytes.
 

Detailed Description

RGBA image with 8 bits per channel, ready to become a texture.

Pixels are stored row by row from the top-left corner, 4 bytes each (red, green, blue, alpha), alpha not premultiplied.

Member Function Documentation

◆ empty()

bool aegis2d::render::Image::empty ( ) const
noexcept

Tells whether the image has no pixel.

Returns
true for a default-constructed image.

◆ from_pixels()

static Image aegis2d::render::Image::from_pixels ( int  width,
int  height,
std::vector< std::uint8_t >  pixels 
)
static

Wraps pixels generated in memory, such as marker_image().

Parameters
widthWidth in pixels, more than 0.
heightHeight in pixels, more than 0.
pixelswidth * height * 4 bytes of RGBA, row by row from the top.
Returns
The image.
Exceptions
std::invalid_argumentif a size is not positive or pixels has another length.

◆ load()

static Image aegis2d::render::Image::load ( const std::filesystem::path &  path)
static

Reads an image file.

Parameters
pathPNG, JPEG, BMP, TGA, GIF (first frame), PSD, HDR or PNM file; any channel count is converted to RGBA.
Returns
The image.
Exceptions
ImageErrorif the file cannot be read or decoded; the message starts with the path.

◆ pixel()

Color aegis2d::render::Image::pixel ( int  x,
int  y 
) const

Color of one pixel.

Parameters
xColumn, from 0 at the left.
yRow, from 0 at the top.
Returns
The pixel, each channel divided by 255.
Exceptions
std::out_of_rangeif the pixel is outside the image.

◆ save_png()

void aegis2d::render::Image::save_png ( const std::filesystem::path &  path) const

Writes the image as a PNG file, creating its folder.

Parameters
pathFile to write.
Exceptions
ImageErrorif the image is empty or the file cannot be written; the message starts with the path.

Member Data Documentation

◆ height

int aegis2d::render::Image::height = 0

Height in pixels.

◆ pixels

std::vector<std::uint8_t> aegis2d::render::Image::pixels

width * height * 4 bytes.

◆ width

int aegis2d::render::Image::width = 0

Width in pixels.


The documentation for this struct was generated from the following file: