5#ifndef MODES_COLORS_UTILS_HPP
6#define MODES_COLORS_UTILS_HPP
10#include "src/system/ext/scale8.h"
11#include "src/system/ext/math8.h"
24static constexpr LMBD_INLINE uint32_t
fromRGB(uint8_t r, uint8_t g, uint8_t b)
28 return (rx << 16) | (gx << 8) | b;
35 constexpr LMBD_INLINE
ToRGB(uint32_t color) :
36 r {(uint8_t)((color >> 16) & 0xff)},
37 g {(uint8_t)((color >> 8) & 0xff)},
38 b {(uint8_t)(color & 0xff)}
48static constexpr LMBD_INLINE uint32_t
fromGrey(uint32_t w) {
return fromRGB(w, w, w); }
52 0, 0, 0, 0, 0, 1, 1, 2, 2, 3, 4, 5, 6, 7, 8, 9, 11, 12, 13, 15, 17, 18,
53 20, 22, 24, 26, 28, 30, 32, 35, 37, 39, 42, 44, 47, 49, 52, 55, 58, 60, 63, 66, 69, 72,
54 75, 78, 81, 85, 88, 91, 94, 97, 101, 104, 107, 111, 114, 117, 121, 124, 127, 131, 134, 137, 141, 144,
55 147, 150, 154, 157, 160, 163, 167, 170, 173, 176, 179, 182, 185, 188, 191, 194, 197, 200, 202, 205, 208, 210,
56 213, 215, 217, 220, 222, 224, 226, 229, 231, 232, 234, 236, 238, 239, 241, 242, 244, 245, 246, 248, 249, 250,
57 251, 251, 252, 253, 253, 254, 254, 255, 255, 255, 255, 255, 255, 255, 254, 254, 253, 253, 252, 251, 251, 250,
58 249, 248, 246, 245, 244, 242, 241, 239, 238, 236, 234, 232, 231, 229, 226, 224, 222, 220, 217, 215, 213, 210,
59 208, 205, 202, 200, 197, 194, 191, 188, 185, 182, 179, 176, 173, 170, 167, 163, 160, 157, 154, 150, 147, 144,
60 141, 137, 134, 131, 127, 124, 121, 117, 114, 111, 107, 104, 101, 97, 94, 91, 88, 85, 81, 78, 75, 72,
61 69, 66, 63, 60, 58, 55, 52, 49, 47, 44, 42, 39, 37, 35, 32, 30, 28, 26, 24, 22, 20, 18,
62 17, 15, 13, 12, 11, 9, 8, 7, 6, 5, 4, 3, 2, 2, 1, 1, 0, 0, 0, 0, 0, 0,
63 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
64 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
65 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
66 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
67 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
68 0, 0, 0, 0, 0, 0, 0, 0};
71static constexpr LMBD_INLINE uint32_t
fromAngleHue(uint16_t angleDegrees)
95static uint32_t
blend(uint32_t leftColor, uint32_t rightColor, uint16_t
blend,
bool b16 =
false)
99 uint16_t blendmax = b16 ? 0xFFFF : 0xFF;
100 if (
blend >= blendmax)
102 uint8_t shift = b16 ? 16 : 8;
104 ToRGB left_rgb(leftColor);
105 ToRGB right_rgb(rightColor);
108 ((right_rgb.
g *
blend) + (left_rgb.
g * (blendmax -
blend))) >> shift,
109 ((right_rgb.
b *
blend) + (left_rgb.
b * (blendmax -
blend))) >> shift);
123template<
bool isV
ideoMode = false>
static uint32_t
fade(uint32_t inputColor, uint8_t fadeAmount)
126 ToRGB input_rgb(inputColor);
130 res =
fromRGB(scale8_video(input_rgb.
r, fadeAmount),
131 scale8_video(input_rgb.
g, fadeAmount),
132 scale8_video(input_rgb.
b, fadeAmount));
136 res =
fromRGB(scale8(input_rgb.
r, fadeAmount), scale8(input_rgb.
g, fadeAmount), scale8(input_rgb.
b, fadeAmount));
142template<
bool isFast = false> uint32_t
add(uint32_t c1, uint32_t c2)
144 ToRGB input1_rgb(c1);
145 ToRGB input2_rgb(c2);
150 qadd8(input1_rgb.
r, input2_rgb.
r), qadd8(input1_rgb.
g, input2_rgb.
g), qadd8(input1_rgb.
b, input2_rgb.
b));
154 uint32_t r = input1_rgb.
r + input2_rgb.
r;
155 uint32_t g = input1_rgb.
g + input2_rgb.
g;
156 uint32_t b = input1_rgb.
b + input2_rgb.
b;
Contains shorthand macro definitions.
Tools to manipulate colors and their representation.
Definition: gamma.hpp:10
static uint32_t fade(uint32_t inputColor, uint8_t fadeAmount)
fade the color toward black
Definition: utils.hpp:123
static constexpr uint8_t colorRotation[360]
precompiled table for Hue
Definition: utils.hpp:51
static constexpr LMBD_INLINE uint32_t fromGrey(uint32_t w)
Return color (w, w, w) as a single uint32_t integer.
Definition: utils.hpp:48
static uint32_t blend(uint32_t leftColor, uint32_t rightColor, uint16_t blend, bool b16=false)
blend to two colors
Definition: utils.hpp:95
static constexpr LMBD_INLINE uint32_t fromAngleHue(uint16_t angleDegrees)
Given a 360 degrees angle, return a corresponding color as an integer.
Definition: utils.hpp:71
static constexpr LMBD_INLINE uint32_t fromRGB(uint8_t r, uint8_t g, uint8_t b)
Return color (r, g, b) as a single uint32_t integer.
Definition: utils.hpp:24
uint32_t add(uint32_t c1, uint32_t c2)
Add two colors together.
Definition: utils.hpp:142
static constexpr N max(const N a, const N b)
Maximum of two numbers.
Definition: utils.h:37
Define some useful color palettes, and tools to use them.
Exposes (r, g, b) as uint8_t in struct from a single uint32_t color.
Definition: utils.hpp:33
uint8_t b
blue
Definition: utils.hpp:44
constexpr LMBD_INLINE ToRGB(uint32_t color)
convert color bytes to rgb struct
Definition: utils.hpp:35
uint8_t r
red
Definition: utils.hpp:42
uint8_t g
green
Definition: utils.hpp:43