1
0
Fork 0
forked from Hartmut/paradiso

Dokumentation ...

This commit is contained in:
Hartmut Seichter 2023-07-01 14:35:14 +02:00
parent d21f526290
commit 1a5287bbc2
4 changed files with 110 additions and 58 deletions
src/lib/include/paradiso

View file

@ -23,44 +23,70 @@
#ifndef PARADISO_BITMAP_HPP
#define PARADISO_BITMAP_HPP
#include <paradiso/globals.hpp>
#include <paradiso/geometry.hpp>
#include <paradiso/globals.hpp>
#include <paradiso/rgba.hpp>
namespace paradiso {
/**
* @brief aggregate to handle bitmap data
*/
struct Bitmap final {
/**
* @brief creates an empty bitmap
* @param[in] size extent of bitmap
* @return an empty bitmap
*/
constexpr static Bitmap empty(Size size) noexcept {
return {.size = size, .data = std::vector<RGBA>{size.area()}};
}
/**
* @brief creates a bitmap from manually adding data
* @param[in] size extent of bitmap
* @param[in] values values to set the bitmap from
* @return bitmap with data from this call
*/
template <typename... Arguments>
static constexpr Bitmap from_data(Size size, Arguments... values) noexcept {
assert(sizeof...(Arguments) == size.height * size.width);
return {
.size = size,
.data = {values...}
};
return {.size = size, .data = {values...}};
}
/**
* @brief fills a bitmap uniformly
* @param[in] color RGBA value of a color
* @return reference to itself
*/
constexpr auto fill(const RGBA& color) noexcept {
std::fill(data.begin(), data.end(), color);
return *this;
}
/**
* @brief access a pixel by position
* @param[in] x x-component of position
* @param[in] y y-component of position
* @return reference to pixel data at position
*/
constexpr RGBA& pixel(std::integral auto x, std::integral auto y) {
return data[y * size.width + x];
}
/**
* @brief access a pixel by position
* @param[in] x x-component of position
* @param[in] y y-component of position
* @return const reference to pixel data at position
*/
constexpr const RGBA& pixel(std::integral auto x,
std::integral auto y) const {
return data[y * size.width + x];
}
Size size{.width = 0, .height = 0};
std::vector<RGBA> data{};
Size size{.width = 0, .height = 0}; //!< extent of bitmap
std::vector<RGBA> data{}; //!< data storage
};
} // namespace paradiso