|
|
|
|
@@ -90,6 +90,55 @@ enum {
|
|
|
|
|
#error "Invalid LV_COLOR_DEPTH in lv_conf.h! Set it to 1, 8, 16 or 32!"
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
/*-----------------------
|
|
|
|
|
* Macros to set/get values
|
|
|
|
|
* of the color channels
|
|
|
|
|
*-----------------------*/
|
|
|
|
|
#if LV_COLOR_DEPTH == 1
|
|
|
|
|
# define LV_COLOR_SET_R(c, v) (c).ch.red = v & 0x1;
|
|
|
|
|
# define LV_COLOR_SET_G(c, v) (c).ch.green = v & 0x1;
|
|
|
|
|
# define LV_COLOR_SET_B(c, v) (c).ch.blue = v & 0x1;
|
|
|
|
|
|
|
|
|
|
# define LV_COLOR_GET_R(c) (c).ch.red
|
|
|
|
|
# define LV_COLOR_GET_G(c) (c).ch.green
|
|
|
|
|
# define LV_COLOR_GET_B(c) (c).ch.blue
|
|
|
|
|
|
|
|
|
|
#elif LV_COLOR_DEPTH == 8
|
|
|
|
|
# define LV_COLOR_SET_R(c, v) (c).ch.red = v & 0x7;
|
|
|
|
|
# define LV_COLOR_SET_G(c, v) (c).ch.green = v & 0x7;
|
|
|
|
|
# define LV_COLOR_SET_B(c, v) c(c).ch.blue = v & 0x3;
|
|
|
|
|
|
|
|
|
|
# define LV_COLOR_GET_R(c) (c).ch.red
|
|
|
|
|
# define LV_COLOR_GET_G(c) (c).ch.green
|
|
|
|
|
# define LV_COLOR_GET_B(c) (c).ch.blue
|
|
|
|
|
|
|
|
|
|
#elif LV_COLOR_DEPTH == 16
|
|
|
|
|
# define LV_COLOR_SET_R(c, v) (c).ch.red = v & 0x1F;
|
|
|
|
|
# if LV_COLOR_16_SWAP == 0
|
|
|
|
|
# define LV_COLOR_SET_G(c, v) (c).ch.green = v & 0x3F;
|
|
|
|
|
# else
|
|
|
|
|
# define LV_COLOR_SET_G(c, v) {(c).ch.green_h = ((v) >> 3) & 0x3; (c).ch.green_l = (v) & 0x3;}
|
|
|
|
|
# endif
|
|
|
|
|
# define LV_COLOR_SET_B(c, v) (c).ch.blue= v & 0x1F;
|
|
|
|
|
|
|
|
|
|
# define LV_COLOR_GET_R(c) (c).ch.red
|
|
|
|
|
# if LV_COLOR_16_SWAP == 0
|
|
|
|
|
# define LV_COLOR_GET_G(c) (c).ch.green
|
|
|
|
|
# else
|
|
|
|
|
# define LV_COLOR_GET_G(c) (((c).ch.green_h << 3) + (c).ch.green_l)
|
|
|
|
|
# endif
|
|
|
|
|
# define LV_COLOR_GET_B(c) (c).ch.blue
|
|
|
|
|
|
|
|
|
|
#elif LV_COLOR_DEPTH == 32
|
|
|
|
|
# define LV_COLOR_SET_R(c, v) (c).ch.red = v & 0xFF;
|
|
|
|
|
# define LV_COLOR_SET_G(c, v) (c).ch.green = v & 0xFF;
|
|
|
|
|
# define LV_COLOR_SET_B(c, v) (c).ch.blue = v & 0xFF;
|
|
|
|
|
|
|
|
|
|
# define LV_COLOR_GET_R(c) (c).ch.red
|
|
|
|
|
# define LV_COLOR_GET_G(c) (c).ch.green
|
|
|
|
|
# define LV_COLOR_GET_B(c) (c).ch.blue
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
/**********************
|
|
|
|
|
* TYPEDEFS
|
|
|
|
|
**********************/
|
|
|
|
|
@@ -194,24 +243,19 @@ static inline uint8_t lv_color_to1(lv_color_t color)
|
|
|
|
|
#if LV_COLOR_DEPTH == 1
|
|
|
|
|
return color.full;
|
|
|
|
|
#elif LV_COLOR_DEPTH == 8
|
|
|
|
|
if((color.ch.red & 0x4) || (color.ch.green & 0x4) || (color.ch.blue & 0x2)) {
|
|
|
|
|
if((LV_COLOR_GET_R(color) & 0x4) || (LV_COLOR_GET_G(color) & 0x4) || (LV_COLOR_GET_B(color) & 0x2)) {
|
|
|
|
|
return 1;
|
|
|
|
|
} else {
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
#elif LV_COLOR_DEPTH == 16
|
|
|
|
|
#if LV_COLOR_16_SWAP == 0
|
|
|
|
|
if((color.ch.red & 0x10) || (color.ch.green & 0x20) || (color.ch.blue & 0x10)) {
|
|
|
|
|
if((LV_COLOR_GET_R(color) & 0x10) || (LV_COLOR_GET_G(color) & 0x20) || (LV_COLOR_GET_B(color) & 0x10)) {
|
|
|
|
|
return 1;
|
|
|
|
|
#else
|
|
|
|
|
if((color.ch.red & 0x10) || (color.ch.green_h & 0x20) || (color.ch.blue & 0x10)) {
|
|
|
|
|
return 1;
|
|
|
|
|
#endif
|
|
|
|
|
} else {
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
#elif LV_COLOR_DEPTH == 32
|
|
|
|
|
if((color.ch.red & 0x80) || (color.ch.green & 0x80) || (color.ch.blue & 0x80)) {
|
|
|
|
|
if((cLV_COLOR_GET_R(color) & 0x80) || (LV_COLOR_GET_G(color) & 0x80) || (LV_COLOR_GET_B(color) & 0x80)) {
|
|
|
|
|
return 1;
|
|
|
|
|
} else {
|
|
|
|
|
return 0;
|
|
|
|
|
@@ -229,25 +273,16 @@ static inline uint8_t lv_color_to8(lv_color_t color)
|
|
|
|
|
#elif LV_COLOR_DEPTH == 8
|
|
|
|
|
return color.full;
|
|
|
|
|
#elif LV_COLOR_DEPTH == 16
|
|
|
|
|
|
|
|
|
|
#if LV_COLOR_16_SWAP == 0
|
|
|
|
|
lv_color8_t ret;
|
|
|
|
|
ret.ch.red = color.ch.red >> 2; /* 5 - 3 = 2*/
|
|
|
|
|
ret.ch.green = color.ch.green >> 3; /* 6 - 3 = 3*/
|
|
|
|
|
ret.ch.blue = color.ch.blue >> 3; /* 5 - 2 = 3*/
|
|
|
|
|
ret.ch.red = LV_COLOR_GET_R(color) >> 2; /* 5 - 3 = 2*/
|
|
|
|
|
ret.ch.green = LV_COLOR_GET_G(color) >> 3; /* 6 - 3 = 3*/
|
|
|
|
|
ret.ch.blue = LV_COLOR_GET_B(color) >> 3; /* 5 - 2 = 3*/
|
|
|
|
|
return ret.full;
|
|
|
|
|
#else
|
|
|
|
|
lv_color8_t ret;
|
|
|
|
|
ret.ch.red = color.ch.red >> 2; /* 5 - 3 = 2*/
|
|
|
|
|
ret.ch.green = color.ch.green_h; /* 6 - 3 = 3*/
|
|
|
|
|
ret.ch.blue = color.ch.blue >> 3; /* 5 - 2 = 3*/
|
|
|
|
|
return ret.full;
|
|
|
|
|
#endif
|
|
|
|
|
#elif LV_COLOR_DEPTH == 32
|
|
|
|
|
lv_color8_t ret;
|
|
|
|
|
ret.ch.red = color.ch.red >> 5; /* 8 - 3 = 5*/
|
|
|
|
|
ret.ch.green = color.ch.green >> 5; /* 8 - 3 = 5*/
|
|
|
|
|
ret.ch.blue = color.ch.blue >> 6; /* 8 - 2 = 6*/
|
|
|
|
|
ret.ch.red = LV_COLOR_GET_R(color) >> 5; /* 8 - 3 = 5*/
|
|
|
|
|
ret.ch.green = LV_COLOR_GET_G(color) >> 5; /* 8 - 3 = 5*/
|
|
|
|
|
ret.ch.blue = LV_COLOR_GET_B(color) >> 6; /* 8 - 2 = 6*/
|
|
|
|
|
return ret.full;
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
@@ -261,32 +296,29 @@ static inline uint16_t lv_color_to16(lv_color_t color)
|
|
|
|
|
return 0xFFFF;
|
|
|
|
|
#elif LV_COLOR_DEPTH == 8
|
|
|
|
|
lv_color16_t ret;
|
|
|
|
|
ret.ch.red = LV_COLOR_GET_R(color) * 4; /*(2^5 - 1)/(2^3 - 1) = 31/7 = 4*/
|
|
|
|
|
#if LV_COLOR_16_SWAP == 0
|
|
|
|
|
ret.ch.red = color.ch.red * 4; /*(2^5 - 1)/(2^3 - 1) = 31/7 = 4*/
|
|
|
|
|
ret.ch.green = color.ch.green * 9; /*(2^6 - 1)/(2^3 - 1) = 63/7 = 9*/
|
|
|
|
|
ret.ch.blue = color.ch.blue * 10; /*(2^5 - 1)/(2^2 - 1) = 31/3 = 10*/
|
|
|
|
|
ret.ch.green = LV_COLOR_GET_G(color) * 9; /*(2^6 - 1)/(2^3 - 1) = 63/7 = 9*/
|
|
|
|
|
#else
|
|
|
|
|
ret.red = color.ch.red * 4;
|
|
|
|
|
uint8_t g_tmp = color.ch.green * 9;
|
|
|
|
|
ret.ch.green_h = (g_tmp & 0x1F) >> 3;
|
|
|
|
|
ret.ch.green_l = g_tmp & 0x07;
|
|
|
|
|
ret.ch.blue = color.ch.blue * 10;
|
|
|
|
|
ret.ch.green_h = (LV_COLOR_GET_G(color) * 9) >> 3; /*(2^6 - 1)/(2^3 - 1) = 63/7 = 9*/
|
|
|
|
|
ret.ch.green_l = (LV_COLOR_GET_G(color) * 9) & 0x7;
|
|
|
|
|
#endif
|
|
|
|
|
ret.ch.blue = LV_COLOR_GET_B(color) * 10; /*(2^5 - 1)/(2^2 - 1) = 31/3 = 10*/
|
|
|
|
|
return ret.full;
|
|
|
|
|
#elif LV_COLOR_DEPTH == 16
|
|
|
|
|
return color.full;
|
|
|
|
|
#elif LV_COLOR_DEPTH == 32
|
|
|
|
|
lv_color16_t ret;
|
|
|
|
|
ret.ch.red = LV_COLOR_GET_R(color) >> 3; /* 8 - 5 = 3*/
|
|
|
|
|
|
|
|
|
|
#if LV_COLOR_16_SWAP == 0
|
|
|
|
|
ret.ch.red = color.ch.red >> 3; /* 8 - 5 = 3*/
|
|
|
|
|
ret.ch.green = color.ch.green >> 2; /* 8 - 6 = 2*/
|
|
|
|
|
ret.ch.blue = color.ch.blue >> 3; /* 8 - 5 = 3*/
|
|
|
|
|
ret.ch.green = LV_COLOR_GET_G(color) >> 2; /* 8 - 6 = 2*/
|
|
|
|
|
#else
|
|
|
|
|
ret.ch.red = color.ch.red >> 3;
|
|
|
|
|
ret.ch.green_h = (color.ch.green & 0xE0) >> 5;
|
|
|
|
|
ret.ch.green_l = (color.ch.green & 0x1C) >> 2;
|
|
|
|
|
ret.ch.blue = color.ch.blue >> 3;
|
|
|
|
|
ret.ch.green_h = (LV_COLOR_GET_G(color) >> 5; /*(2^6 - 1)/(2^3 - 1) = 63/7 = 9*/
|
|
|
|
|
ret.ch.green_l = (LV_COLOR_GET_G(color) >> 2) & 0x7;
|
|
|
|
|
#endif
|
|
|
|
|
ret.ch.green = LV_COLOR_GET_G(color) >> 2; /* 8 - 6 = 2*/
|
|
|
|
|
ret.ch.blue = LV_COLOR_GET_B(color) >> 3; /* 8 - 5 = 3*/
|
|
|
|
|
return ret.full;
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
@@ -300,9 +332,9 @@ static inline uint32_t lv_color_to32(lv_color_t color)
|
|
|
|
|
return 0xFFFFFFFF;
|
|
|
|
|
#elif LV_COLOR_DEPTH == 8
|
|
|
|
|
lv_color32_t ret;
|
|
|
|
|
ret.ch.red = color.ch.red * 36; /*(2^8 - 1)/(2^3 - 1) = 255/7 = 36*/
|
|
|
|
|
ret.ch.green = color.ch.green * 36; /*(2^8 - 1)/(2^3 - 1) = 255/7 = 36*/
|
|
|
|
|
ret.ch.blue = color.ch.blue * 85; /*(2^8 - 1)/(2^2 - 1) = 255/3 = 85*/
|
|
|
|
|
ret.ch.red = LV_COLOR_GET_R(color) * 36; /*(2^8 - 1)/(2^3 - 1) = 255/7 = 36*/
|
|
|
|
|
ret.ch.green = LV_COLOR_GET_G(color) * 36; /*(2^8 - 1)/(2^3 - 1) = 255/7 = 36*/
|
|
|
|
|
ret.ch.blue = LV_COLOR_GET_B(color) * 85; /*(2^8 - 1)/(2^2 - 1) = 255/3 = 85*/
|
|
|
|
|
ret.ch.alpha = 0xFF;
|
|
|
|
|
return ret.full;
|
|
|
|
|
#elif LV_COLOR_DEPTH == 16
|
|
|
|
|
@@ -335,13 +367,9 @@ static inline uint32_t lv_color_to32(lv_color_t color)
|
|
|
|
|
* 6 259 3 0 255
|
|
|
|
|
*/
|
|
|
|
|
lv_color32_t ret;
|
|
|
|
|
ret.ch.red = ( color.ch.red * 263 + 7 ) >> 5;
|
|
|
|
|
#if LV_COLOR_16_SWAP == 0
|
|
|
|
|
ret.ch.green = ( color.ch.green * 259 + 3 ) >> 6;
|
|
|
|
|
#else
|
|
|
|
|
ret.ch.green = (((color.ch.green_h << 3) + color.ch.green_l) * 259 + 3 ) >> 6;
|
|
|
|
|
#endif
|
|
|
|
|
ret.ch.blue = ( color.ch.blue * 263 + 7 ) >> 5;
|
|
|
|
|
ret.ch.red = (LV_COLOR_GET_R(color) * 263 + 7 ) >> 5;
|
|
|
|
|
ret.ch.green = (LV_COLOR_GET_G(color) * 259 + 3 ) >> 6;
|
|
|
|
|
ret.ch.blue = (LV_COLOR_GET_B(color) * 263 + 7 ) >> 5;
|
|
|
|
|
ret.ch.alpha = 0xFF;
|
|
|
|
|
return ret.full;
|
|
|
|
|
#elif LV_COLOR_DEPTH == 32
|
|
|
|
|
@@ -354,18 +382,9 @@ static inline lv_color_t lv_color_mix(lv_color_t c1, lv_color_t c2, uint8_t mix)
|
|
|
|
|
lv_color_t ret;
|
|
|
|
|
#if LV_COLOR_DEPTH != 1
|
|
|
|
|
/*LV_COLOR_DEPTH == 8, 16 or 32*/
|
|
|
|
|
ret.ch.red = (uint16_t)((uint16_t)c1.ch.red * mix + (c2.ch.red * (255 - mix))) >> 8;
|
|
|
|
|
#if LV_COLOR_DEPTH == 16 && LV_COLOR_16_SWAP
|
|
|
|
|
/*If swapped Green is in 2 parts*/
|
|
|
|
|
uint16_t g_1 = (c1.ch.green_h << 3) + c1.ch.green_l;
|
|
|
|
|
uint16_t g_2 = (c2.ch.green_h << 3) + c2.ch.green_l;
|
|
|
|
|
uint16_t g_out = (uint16_t)((uint16_t)g_1 * mix + (g_2 * (255 - mix))) >> 8;
|
|
|
|
|
ret.ch.green_h = g_out >> 3;
|
|
|
|
|
ret.ch.green_l = g_out & 0x7;
|
|
|
|
|
#else
|
|
|
|
|
ret.ch.green = (uint16_t)((uint16_t)c1.ch.green * mix + (c2.ch.green * (255 - mix))) >> 8;
|
|
|
|
|
#endif
|
|
|
|
|
ret.ch.blue = (uint16_t)((uint16_t)c1.ch.blue * mix + (c2.ch.blue * (255 - mix))) >> 8;
|
|
|
|
|
LV_COLOR_SET_R(ret, (uint16_t)((uint16_t) LV_COLOR_GET_R(c1) * mix + LV_COLOR_GET_R(c2) * (255 - mix)) >> 8);
|
|
|
|
|
LV_COLOR_SET_G(ret, (uint16_t)((uint16_t) LV_COLOR_GET_G(c1) * mix + LV_COLOR_GET_G(c2) * (255 - mix)) >> 8);
|
|
|
|
|
LV_COLOR_SET_B(ret, (uint16_t)((uint16_t) LV_COLOR_GET_B(c1) * mix + LV_COLOR_GET_B(c2) * (255 - mix)) >> 8);
|
|
|
|
|
#if LV_COLOR_DEPTH == 32
|
|
|
|
|
ret.ch.alpha = 0xFF;
|
|
|
|
|
#endif
|
|
|
|
|
@@ -386,7 +405,7 @@ static inline uint8_t lv_color_brightness(lv_color_t color)
|
|
|
|
|
{
|
|
|
|
|
lv_color32_t c32;
|
|
|
|
|
c32.full = lv_color_to32(color);
|
|
|
|
|
uint16_t bright = 3 * c32.ch.red + c32.ch.blue + 4 * c32.ch.green;
|
|
|
|
|
uint16_t bright = 3 * LV_COLOR_GET_R(c32) + LV_COLOR_GET_B(c32) + 4 * LV_COLOR_GET_G(c32);
|
|
|
|
|
return (uint16_t)bright >> 3;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|