forked from Hartmut/paradiso
reorganized repo to show clear module boundaries
This commit is contained in:
parent
8e00b668ea
commit
536a639bfd
396 changed files with 355 additions and 391 deletions
63
src/lib/include/paradiso/rgba.hpp
Normal file
63
src/lib/include/paradiso/rgba.hpp
Normal file
|
@ -0,0 +1,63 @@
|
|||
#ifndef PARADISO_RGBA_HPP
|
||||
#define PARADISO_RGBA_HPP
|
||||
|
||||
#include "globals.hpp"
|
||||
|
||||
namespace paradiso {
|
||||
struct RGBA final {
|
||||
using value_type = std::uint32_t;
|
||||
value_type pixel{0x0};
|
||||
|
||||
static constexpr RGBA from_rgb(uint8_t red, uint8_t green,
|
||||
uint8_t blue) noexcept {
|
||||
return from_rgba(red, green, blue, 0xFF);
|
||||
}
|
||||
|
||||
static constexpr RGBA from_rgba(uint8_t red, uint8_t green, uint8_t blue,
|
||||
uint8_t alpha) noexcept {
|
||||
return {.pixel =
|
||||
(value_type)(((((red << 8) | green) << 8) | blue) << 8) |
|
||||
alpha};
|
||||
}
|
||||
|
||||
constexpr void to_float(float rgba_f[4]) const noexcept {
|
||||
rgba_f[0] = static_cast<float>(this->red()) / 0xFF;
|
||||
rgba_f[1] = static_cast<float>(this->green()) / 0xFF;
|
||||
rgba_f[2] = static_cast<float>(this->blue()) / 0xFF;
|
||||
rgba_f[3] = static_cast<float>(this->alpha()) / 0xFF;
|
||||
}
|
||||
|
||||
constexpr uint8_t red() const noexcept {
|
||||
return (pixel & 0xFF000000) >> 24;
|
||||
}
|
||||
constexpr uint8_t green() const noexcept {
|
||||
return uint8_t((pixel & 0xFF0000) >> 16);
|
||||
}
|
||||
constexpr uint8_t blue() const noexcept {
|
||||
return uint8_t((pixel & 0xFF00) >> 8);
|
||||
}
|
||||
constexpr uint8_t alpha() const noexcept { return uint8_t(pixel & 0xFF); }
|
||||
|
||||
constexpr RGBA& set_red(uint8_t v) noexcept {
|
||||
pixel = (pixel & 0x00FFFFFF) | (v << 24);
|
||||
return *this;
|
||||
}
|
||||
|
||||
constexpr RGBA& set_green(uint8_t v) noexcept {
|
||||
pixel = (pixel & 0xFF00FFFF) | (v << 16);
|
||||
return *this;
|
||||
}
|
||||
|
||||
constexpr RGBA& set_blue(uint8_t v) noexcept {
|
||||
pixel = (pixel & 0xFFFF00FF) | (v << 8);
|
||||
return *this;
|
||||
}
|
||||
|
||||
constexpr RGBA& set_alpha(uint8_t v) noexcept {
|
||||
pixel = (pixel & 0xFFFFFF00) | v;
|
||||
return *this;
|
||||
}
|
||||
};
|
||||
} // namespace paradiso
|
||||
|
||||
#endif
|
Loading…
Add table
Add a link
Reference in a new issue