1234567891011121314151617181920212223242526272829303132333435363738394041424344 |
- #ifndef CORE_COLOR_HPP
- #define CORE_COLOR_HPP
- #include "core/utils/Types.hpp"
- namespace Core {
- using ColorChannel = unsigned char;
- template<size_t N>
- class Color final {
- static_assert(N >= 1 && N <= 4, "a color has 1 to 4 channels");
- ColorChannel data[N] = {};
- public:
- Color() = default;
- template<typename OT, typename... Args>
- Color(OT a, Args&&... args)
- : data(static_cast<ColorChannel>(a),
- static_cast<ColorChannel>(args)...) {
- static_assert(sizeof...(args) + 1 == N,
- "color channel parameters do not match its size");
- }
- float asFloat(size_t index) const {
- return data[index] * (1.0f / 255.0f);
- }
- ColorChannel& operator[](size_t index) {
- return data[index];
- }
- const ColorChannel& operator[](size_t index) const {
- return data[index];
- }
- };
- using Color4 = Color<4>;
- using Color3 = Color<3>;
- using Color2 = Color<2>;
- using Color1 = Color<1>;
- }
- #endif
|