image
| Type | Class |
| Namespace | conjure::core |
| Include File Path | engine/include/conjure/core/image.h |
| Source File Path | engine/src/core/system/image.cpp |
| API ↗ | Processes, libraries and images |
Syntax
Constructors
| Access | Signature | Description |
|---|---|---|
| public | image(); | |
| public | image(
u32 width,
u32 height); | A zero-filled image (transparent black). A zero width or height yields the empty image. Dimensions above MAX_DIMENSION, or whose pixel data would exceed MAX_PIXEL_BYTES, are a programmer error and yield the empty image too. |
| public | image(
const image &) = default; | |
| public | image(
image &&) noexcept = default; |
Destructors
| Access | Signature | Description |
|---|---|---|
| public | ~image(); |
Variables
| Access | Name | Type | Default | Description |
|---|---|---|---|---|
| public | BYTES_ | static constexpr u32 | 4 | Size of one pixel in bytes. |
| public | MAX_ | static constexpr u32 | 1u << 24 | Largest width or height accepted; the PNG codec rejects anything larger. |
| public | MAX_ | static constexpr usize | 0x7FFFFFFF | Largest value of width * height * BYTES_PER_PIXEL + height that encode_png() accepts (the PNG encoder works in 32-bit signed arithmetic). |
| public | MAX_ | static constexpr usize | MAX_ | Largest pixel buffer (width * height * BYTES_PER_PIXEL) the constructor accepts; the PNG codecs work in 32-bit signed sizes. |
| private | mHeight | u32 | 0 | |
| private | mPixels | std::vector<std::byte> | {} | |
| private | mWidth | u32 | 0 |
Functions
Public
compare
compareMean absolute difference over every channel of every pixel, normalised to 0 (identical) .. 1 (every byte differs by 255). Images of different dimensions compare as 1. Two empty images compare as 0. Used by golden-image tests.
encode_png
encode_png[[nodiscard]] result<std::vector<std::byte>> encode_png() const;Encodes the image as PNG. Fails with INVALID_STATE for an empty image and UNSUPPORTED for one whose pixel data (plus one filter byte per row) exceeds MAX_ENCODED_BYTES, the limit of the encoder's 32-bit arithmetic.
flip_vertical
flip_verticalvoid flip_vertical() noexcept;Reverses the order of the rows in place (top becomes bottom).
load_file
load_fileReads a PNG file. Fails with NOT_FOUND when the file does not exist, IO_FAILURE when it cannot be read and PARSE_FAILURE when it is not a PNG.
load_png
load_pngDecodes a PNG held in memory. Grey, grey + alpha and RGB files are expanded to RGBA8 (alpha 255 when absent). Fails with INVALID_ARGUMENT for empty data and PARSE_FAILURE for anything that is not a well-formed PNG.
pixel
pixelThe pixel at (x, y). Out-of-range coordinates assert and return a default rgba8.
pixels
pixels[[nodiscard]] std::span<std::byte> pixels() noexcept;The pixel bytes, width * height * 4 of them: for pixel (x, y) the red byte is at index (y * width + x) * 4, followed by green, blue and alpha.
[[nodiscard]] std::span<const std::byte> pixels() const noexcept;save_png
save_png[[nodiscard]] result<void> save_png(
const std::filesystem::path &path) const;Writes the image as a PNG file, replacing any existing file. Same failures as encode_png() plus IO_FAILURE when the file cannot be written.
set_pixel
set_pixelSets the pixel at (x, y). Out-of-range coordinates assert and change nothing.
Operator Overloads
Public
operator=
operator=