39 constexpr color(
color const &)
noexcept =
default;
41 constexpr color &operator=(
color const &)
noexcept =
default;
42 constexpr color &operator=(
color &&)
noexcept =
default;
44 [[nodiscard]]
constexpr explicit color(
f16x4 const &other) noexcept : _v(other)
46 hi_axiom(holds_invariant());
49 [[nodiscard]]
constexpr explicit color(
f32x4 const &other) noexcept :
color(
static_cast<f16x4>(other)) {}
51 [[nodiscard]]
constexpr explicit operator f16x4()
const noexcept
56 [[nodiscard]]
constexpr explicit operator f32x4()
const noexcept
58 return static_cast<f32x4>(_v);
61 [[nodiscard]]
constexpr color(
float r,
float g,
float b,
float a = 1.0f) noexcept :
color(
f32x4{r, g, b, a}) {}
65 [[nodiscard]]
static constexpr color transparent()
noexcept
67 return {0.0f, 0.0f, 0.0f, 0.0f};
70 [[nodiscard]]
static constexpr color white()
noexcept
72 return {1.0f, 1.0f, 1.0f, 1.0f};
75 [[nodiscard]]
static constexpr color black()
noexcept
77 return {0.0f, 0.0f, 0.0f, 1.0f};
80 [[nodiscard]]
constexpr float16 &r()
noexcept
85 [[nodiscard]]
constexpr float16 &g()
noexcept
90 [[nodiscard]]
constexpr float16 &b()
noexcept
95 [[nodiscard]]
constexpr float16 &a()
noexcept
100 [[nodiscard]]
constexpr float16 const &r()
const noexcept
105 [[nodiscard]]
constexpr float16 const &g()
const noexcept
110 [[nodiscard]]
constexpr float16 const &b()
const noexcept
115 [[nodiscard]]
constexpr float16 const &a()
const noexcept
120 [[nodiscard]]
constexpr bool holds_invariant()
const noexcept
122 return _v.w() >= 0.0 && _v.w() <= 1.0;
125 [[nodiscard]]
constexpr friend bool operator==(
color const &lhs,
color const &rhs)
noexcept =
default;
127 [[nodiscard]]
constexpr friend color operator*(
color const &lhs,
color const &rhs)
noexcept
129 return color{lhs._v * rhs._v};
132 [[nodiscard]]
constexpr friend color composit(
color const &lhs,
color const &rhs)
noexcept
134 return color{composit(lhs._v, rhs._v)};
137 [[nodiscard]]
constexpr friend color desaturate(
color const &rhs)
noexcept
139 auto rhs_ =
f32x4{rhs};
141 auto Y = 0.2126f * rhs_.r() + 0.7152f * rhs_.g() + 0.0722f * rhs_.b();
143 return color{Y, Y, Y, rhs_.a()};