diff --git a/src/palette.cpp b/src/palette.cpp --- a/src/palette.cpp +++ b/src/palette.cpp @@ -23,8 +23,6 @@ Palette _cur_palette; -byte _colour_gradient[COLOUR_END][8]; - static std::recursive_mutex _palette_mutex; ///< To coordinate access to _cur_palette. /** @@ -295,3 +293,38 @@ TextColour GetContrastColour(uint8_t bac /* Compare with threshold brightness which defaults to 128 (50%) */ return sq1000_brightness < ((uint) threshold) * ((uint) threshold) * 1000 ? TC_WHITE : TC_BLACK; } + +/** + * Lookup table of colour shades for all 16 colour gradients. + * 8 colours per gradient from darkest (0) to lightest (7) + */ +struct ColourGradients +{ + using ColourGradient = std::array; + + static inline std::array gradient{}; +}; + +/** + * Get colour gradient palette index. + * @param colour Colour. + * @param shade Shade level from 1 to 7. + * @returns palette index of colour. + */ +byte GetColourGradient(Colours colour, uint8_t shade) +{ + return ColourGradients::gradient[colour % COLOUR_END][shade % 8]; +} + +/** + * Set colour gradient palette index. + * @param colour Colour. + * @param shade Shade level from 1 to 7. + * @param palette_index Palette index to set. + */ +void SetColourGradient(Colours colour, uint8_t shade, byte palette_index) +{ + assert(colour < COLOUR_END); + assert(shade < 8); + ColourGradients::gradient[colour % COLOUR_END][shade % 8] = palette_index; +}