#ifndef CORE_COLOR_HPP #define CORE_COLOR_HPP #include "core/utils/Types.hpp" namespace Core { using ColorChannel = unsigned char; template class Color final { static_assert(N >= 1 && N <= 4, "a color has 1 to 4 channels"); ColorChannel data[N] = {}; public: Color() = default; template Color(OT a, Args&&... args) : data(static_cast(a), static_cast(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