|
|
|
@ -3,7 +3,6 @@ |
|
|
|
|
|
|
|
|
|
#include "matrix.hpp" |
|
|
|
|
#include <algorithm> |
|
|
|
|
#include <bit> |
|
|
|
|
#include <cmath> |
|
|
|
|
#include <cstddef> |
|
|
|
|
#include <cstdint> |
|
|
|
@ -62,25 +61,18 @@ namespace amt { |
|
|
|
|
constexpr RGBA() noexcept = default; |
|
|
|
|
constexpr RGBA(RGBA const&) noexcept = default; |
|
|
|
|
constexpr RGBA(RGBA &&) noexcept = default; |
|
|
|
|
constexpr RGBA& operator=(RGBA const& other) noexcept { |
|
|
|
|
this->m_data.color = other.m_data.color; |
|
|
|
|
return *this; |
|
|
|
|
} |
|
|
|
|
constexpr RGBA& operator=(RGBA && other) noexcept { |
|
|
|
|
this->m_data.color = other.m_data.color; |
|
|
|
|
return *this; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
constexpr RGBA& operator=(RGBA const&) noexcept = default;
|
|
|
|
|
constexpr RGBA& operator=(RGBA &&) noexcept = default; |
|
|
|
|
constexpr ~RGBA() noexcept = default; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// NOTE: Accepts RRGGBBAA
|
|
|
|
|
explicit constexpr RGBA(pixels_t color) noexcept |
|
|
|
|
: m_data({ .color = color }) |
|
|
|
|
: RGBA((color >> (8 * 3)) & 0xff, (color >> (8 * 2)) & 0xff, (color >> (8 * 1)) & 0xff, (color >> (8 * 0)) & 0xff) |
|
|
|
|
{} |
|
|
|
|
|
|
|
|
|
constexpr RGBA(pixel_t r, pixel_t g, pixel_t b, pixel_t a = 0xff) noexcept |
|
|
|
|
: m_data({ .rgba = { r, g, b, a } }) |
|
|
|
|
: m_data {r, g, b, a} |
|
|
|
|
{} |
|
|
|
|
|
|
|
|
|
constexpr RGBA(pixel_t color, pixel_t a = 0xff) noexcept |
|
|
|
@ -89,26 +81,22 @@ namespace amt { |
|
|
|
|
|
|
|
|
|
// NOTE: Returns RRGGBBAA
|
|
|
|
|
constexpr auto to_hex() const noexcept -> pixels_t { |
|
|
|
|
if constexpr (std::endian::native == std::endian::little) { |
|
|
|
|
auto r = static_cast<pixels_t>(this->r()); |
|
|
|
|
auto b = static_cast<pixels_t>(this->b()); |
|
|
|
|
auto g = static_cast<pixels_t>(this->g()); |
|
|
|
|
auto a = static_cast<pixels_t>(this->a()); |
|
|
|
|
return (r << (8 * 3)) | (g << (8 * 2)) | (b << (8 * 1)) | (a << (8 * 0)); |
|
|
|
|
} else { |
|
|
|
|
return m_data.color; |
|
|
|
|
} |
|
|
|
|
auto r = static_cast<pixels_t>(this->r()); |
|
|
|
|
auto b = static_cast<pixels_t>(this->b()); |
|
|
|
|
auto g = static_cast<pixels_t>(this->g()); |
|
|
|
|
auto a = static_cast<pixels_t>(this->a()); |
|
|
|
|
return (r << (8 * 3)) | (g << (8 * 2)) | (b << (8 * 1)) | (a << (8 * 0)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
constexpr auto r() const noexcept -> pixel_t { return m_data.rgba.r; } |
|
|
|
|
constexpr auto g() const noexcept -> pixel_t { return m_data.rgba.g; } |
|
|
|
|
constexpr auto b() const noexcept -> pixel_t { return m_data.rgba.b; } |
|
|
|
|
constexpr auto a() const noexcept -> pixel_t { return m_data.rgba.a; } |
|
|
|
|
constexpr auto r() const noexcept -> pixel_t { return m_data[0]; } |
|
|
|
|
constexpr auto g() const noexcept -> pixel_t { return m_data[1]; } |
|
|
|
|
constexpr auto b() const noexcept -> pixel_t { return m_data[2]; } |
|
|
|
|
constexpr auto a() const noexcept -> pixel_t { return m_data[3]; } |
|
|
|
|
|
|
|
|
|
constexpr auto r() noexcept -> pixel_t& { return m_data.rgba.r; } |
|
|
|
|
constexpr auto g() noexcept -> pixel_t& { return m_data.rgba.g; } |
|
|
|
|
constexpr auto b() noexcept -> pixel_t& { return m_data.rgba.b; } |
|
|
|
|
constexpr auto a() noexcept -> pixel_t& { return m_data.rgba.a; } |
|
|
|
|
constexpr auto r() noexcept -> pixel_t& { return m_data[0]; } |
|
|
|
|
constexpr auto g() noexcept -> pixel_t& { return m_data[1]; } |
|
|
|
|
constexpr auto b() noexcept -> pixel_t& { return m_data[2]; } |
|
|
|
|
constexpr auto a() noexcept -> pixel_t& { return m_data[3]; } |
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @returns the value is between 0 and 1 |
|
|
|
@ -125,13 +113,10 @@ namespace amt { |
|
|
|
|
requires std::is_arithmetic_v<T> |
|
|
|
|
constexpr auto operator/(T val) const noexcept { |
|
|
|
|
auto d = static_cast<float>(val); |
|
|
|
|
auto tr = float(r()); |
|
|
|
|
auto tg = float(g()); |
|
|
|
|
auto tb = float(b()); |
|
|
|
|
return RGBA( |
|
|
|
|
static_cast<pixel_t>(tr / d), |
|
|
|
|
static_cast<pixel_t>(tg / d), |
|
|
|
|
static_cast<pixel_t>(tb / d), |
|
|
|
|
static_cast<pixel_t>(r() / d), |
|
|
|
|
static_cast<pixel_t>(g() / d), |
|
|
|
|
static_cast<pixel_t>(b() / d), |
|
|
|
|
a() |
|
|
|
|
); |
|
|
|
|
} |
|
|
|
@ -373,15 +358,7 @@ namespace amt { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
private: |
|
|
|
|
union { |
|
|
|
|
struct { |
|
|
|
|
pixel_t r; |
|
|
|
|
pixel_t g; |
|
|
|
|
pixel_t b; |
|
|
|
|
pixel_t a; |
|
|
|
|
} rgba; |
|
|
|
|
pixels_t color; |
|
|
|
|
} m_data {}; |
|
|
|
|
pixel_t m_data[4]{}; |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
struct HSLA { |
|
|
|
|