30 lines
874 B
C++
30 lines
874 B
C++
#pragma once
|
|
|
|
#include <stddef.h>
|
|
#include <stdint.h>
|
|
|
|
namespace palette {
|
|
|
|
constexpr uint16_t rgb565(uint8_t red, uint8_t green, uint8_t blue) {
|
|
return (static_cast<uint16_t>(red & 0xF8) << 8) |
|
|
(static_cast<uint16_t>(green & 0xFC) << 3) | (blue >> 3);
|
|
}
|
|
|
|
constexpr uint16_t kOtherGrey = rgb565(176, 176, 176);
|
|
|
|
constexpr uint16_t kHues[] = {0, 30, 60, 120, 180, 225, 270, 300, 330};
|
|
constexpr uint16_t kColors[] = {
|
|
rgb565(255, 128, 128), rgb565(255, 191, 128), rgb565(255, 255, 128),
|
|
rgb565(128, 255, 128), rgb565(128, 255, 255), rgb565(128, 159, 255),
|
|
rgb565(191, 128, 255), rgb565(255, 128, 255), rgb565(255, 128, 191),
|
|
};
|
|
|
|
inline int indexForHue(uint16_t hue) {
|
|
for (size_t index = 0; index < sizeof(kHues) / sizeof(kHues[0]); ++index) {
|
|
if (kHues[index] == hue) return static_cast<int>(index);
|
|
}
|
|
return -1;
|
|
}
|
|
|
|
} // namespace palette
|