lv_color.h use 1 common lv_color_make

This commit is contained in:
Gabor Kiss-Vamosi
2019-11-25 06:42:11 +01:00
parent 12fa1ac788
commit 0422e662d9

View File

@@ -465,23 +465,8 @@ static inline uint8_t lv_color_brightness(lv_color_t color)
/* The most simple macro to create a color from R,G and B values */
#if LV_COLOR_DEPTH == 1
#define LV_COLOR_MAKE(r8, g8, b8) ((lv_color_t){.full = (b8 >> 7 | g8 >> 7 | r8 >> 7)})
static inline lv_color_t lv_color_make(int r8, int g8, int b8)
{
lv_color_t color = { 0 };
color.full = (b8 >> 7 | g8 >> 7 | r8 >> 7);
return color;
}
#elif LV_COLOR_DEPTH == 8
#define LV_COLOR_MAKE(r8, g8, b8) ((lv_color_t){{b8 >> 6, g8 >> 5, r8 >> 5}})
static inline lv_color_t lv_color_make(uint8_t r8, int g8, int b8)
{
lv_color_t color;
LV_COLOR_SET_B(color, b8 >> 6);
LV_COLOR_SET_G(color, g8 >> 5);
LV_COLOR_SET_R(color, r8 >> 5);
LV_COLOR_SET_A(color, 0xFF);
return color;
}
#elif LV_COLOR_DEPTH == 16
#if LV_COLOR_16_SWAP == 0
#define LV_COLOR_MAKE(r8, g8, b8) ((lv_color_t){{b8 >> 3, g8 >> 2, r8 >> 3}})
@@ -489,27 +474,15 @@ static inline lv_color_t lv_color_make(uint8_t r8, int g8, int b8)
#define LV_COLOR_MAKE(r8, g8, b8) ((lv_color_t){{g8 >> 5, r8 >> 3, b8 >> 3, (g8 >> 2) & 0x7}})
#endif
static inline lv_color_t lv_color_make(uint8_t r8, uint8_t g8, uint8_t b8)
{
lv_color_t color;
LV_COLOR_SET_B(color, b8 >> 3);
LV_COLOR_SET_G(color, g8 >> 2);
LV_COLOR_SET_R(color, r8 >> 3);
LV_COLOR_SET_A(color, 0xFF);
return color;
}
#elif LV_COLOR_DEPTH == 32
#define LV_COLOR_MAKE(r8, g8, b8) ((lv_color_t){{b8, g8, r8, 0xff}}) /*Fix 0xff alpha*/
static inline lv_color_t lv_color_make(uint8_t r8, uint8_t g8, uint8_t b8)
{
lv_color_t color;
LV_COLOR_SET_B(color, b8);
LV_COLOR_SET_G(color, g8);
LV_COLOR_SET_R(color, r8);
LV_COLOR_SET_A(color, 0xFF);
return color;
}
#endif
static inline lv_color_t lv_color_make(uint8_t r, uint8_t g, uint8_t b)
{
return LV_COLOR_MAKE(r, g, b);
}
static inline lv_color_t lv_color_hex(uint32_t c)
{
return lv_color_make((uint8_t)((c >> 16) & 0xFF), (uint8_t)((c >> 8) & 0xFF), (uint8_t)(c & 0xFF));