1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00

sys/color: add color_rgb_set_brightness()

Add a function to set the brightness level of a RGB value from 0-255.
This commit is contained in:
Benjamin Valentin 2019-11-16 16:12:41 +01:00
parent 19e8d02715
commit 6d5704307f

View File

@ -150,6 +150,22 @@ static inline void color_rgb_shift(const color_rgb_t *rgb, color_rgb_t *out, int
}
}
/**
* @brief Change the brightness of a RGB color by multiplying it with a set factor.
*
* @pre ((rgb != NULL) && (out != NULL))
*
* @param[in] rgb Input rgb color, that should be multiplied. Must be NOT NULL
* @param[out] out Output rgb color. Must be NOT NULL
* @param[in] level New brightness level. 255 = Full Brightness, 0 = Off.
*/
static inline void color_rgb_set_brightness(const color_rgb_t *rgb, color_rgb_t *out, uint8_t level)
{
out->r = ((unsigned)rgb->r * level + 128) >> 8;
out->g = ((unsigned)rgb->g * level + 128) >> 8;
out->b = ((unsigned)rgb->b * level + 128) >> 8;
}
/**
* @brief Calculate the complementary color of a given rgb color.
*