#pragma once #include #include #include #include #include "intmath.h" constexpr uint32_t kMaxColor = UINT16_MAX; // 32-bit for compiler convenience, but values are 16-bit template struct Color : public std::array { constexpr uint32_t Difference(const Color& other) const; constexpr Color Interpolate(const Color& other, uint32_t mul, uint32_t div) const; }; struct RgbColor : public Color<3> {}; template constexpr uint32_t Color::Difference(const Color& other) const { uint32_t diff = 0; for (uint32_t c = 0; c < C; ++c) { diff += AbsDiff(this->at(c), other.at(c)); } return diff; } template constexpr Color Color::Interpolate(const Color& other, uint32_t mul, uint32_t div) const { Color ret; for (uint32_t c = 0; c < C; ++c) { ret.at(c) = ::Interpolate(this->at(c), other.at(c), mul, div); } return ret; } template std::ostream& operator<<(std::ostream& os, const Color& color) { os << std::hex << std::setfill('0') << "Color("; for (uint32_t c = 0; c < C; ++c) { os << "0x" << std::setw(4) << color.at(0); if (c < C - 1) { os << ", "; } } return os << ")" << std::dec; }