Codechange: Remove direct access to _colour_gradient.
Access is now through GetColourGradient, which ensures parameters are in range.
This commit is contained in:

committed by
Peter Nelson

parent
56cf89d189
commit
0463d4c198
@@ -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 background, uint8_t threshold)
|
||||
/* 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<byte, 8>;
|
||||
|
||||
static inline std::array<ColourGradient, COLOUR_END> 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;
|
||||
}
|
||||
|
Reference in New Issue
Block a user