BigW Consortium Gitlab

Commit 64b5010b by Gabor Kiss-Vamosi

change 0b.. number to 0x... and add big endian support to LV_COLOR_MAKE

parent 6f43efde
......@@ -147,17 +147,17 @@ 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.red & 0b100) ||
(color.green & 0b100) ||
(color.blue & 0b10)) {
if((color.red & 0x4) ||
(color.green & 0x4) ||
(color.blue & 0x2)) {
return 1;
} else {
return 0;
}
#elif LV_COLOR_DEPTH == 16
if((color.red & 0b10000) ||
(color.green & 0b100000) ||
(color.blue & 0b10000)) {
if((color.red & 0x10) ||
(color.green & 0x20) ||
(color.blue & 0x10)) {
return 1;
} else {
return 0;
......@@ -261,6 +261,9 @@ static inline uint8_t lv_color_brightness(lv_color_t color)
return (uint16_t) bright >> 3;
}
/* The most simple macro to create a color from R,G and B values
* The order of bit field is different on Big-endian and Little-endian machines*/
#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
#if LV_COLOR_DEPTH == 1
#define LV_COLOR_MAKE(r8, g8, b8) ((lv_color_t){(b8 >> 7 | g8 >> 7 | r8 >> 7)})
#elif LV_COLOR_DEPTH == 8
......@@ -270,6 +273,17 @@ static inline uint8_t lv_color_brightness(lv_color_t color)
#elif LV_COLOR_DEPTH == 24
#define LV_COLOR_MAKE(r8, g8, b8) ((lv_color_t){{b8, g8, r8}})
#endif
#else
#if LV_COLOR_DEPTH == 1
#define LV_COLOR_MAKE(r8, g8, b8) ((lv_color_t){(r8 >> 7 | g8 >> 7 | b8 >> 7)})
#elif LV_COLOR_DEPTH == 8
#define LV_COLOR_MAKE(r8, g8, b8) ((lv_color_t){{r8 >> 6, g8 >> 5, b8 >> 5}})
#elif LV_COLOR_DEPTH == 16
#define LV_COLOR_MAKE(r8, g8, b8) ((lv_color_t){{r8 >> 3, g8 >> 2, b8 >> 3}})
#elif LV_COLOR_DEPTH == 24
#define LV_COLOR_MAKE(r8, g8, b8) ((lv_color_t){{r8, g8, b8}})
#endif
#endif
#define LV_COLOR_HEX(c) LV_COLOR_MAKE(((uint32_t)((uint32_t)c >> 16) & 0xFF), \
((uint32_t)((uint32_t)c >> 8) & 0xFF), \
......
......@@ -52,8 +52,8 @@ void lv_ll_init(lv_ll_t * ll_p, uint32_t n_size)
ll_p->head = NULL;
ll_p->tail = NULL;
if(n_size & 0b11) {
n_size &= ~0b11;
if(n_size & 0x3) { /*Round up to 4*/
n_size &= ~0x3;
n_size += 4;
}
......
......@@ -302,10 +302,10 @@ void lv_txt_cut(char * txt, uint32_t pos, uint32_t len)
*/
uint8_t lv_txt_utf8_size(uint8_t c)
{
if((c & 0b10000000) == 0) return 1;
else if((c & 0b11100000) == 0b11000000) return 2;
else if((c & 0b11110000) == 0b11100000) return 3;
else if((c & 0b11111000) == 0b11110000) return 4;
if((c & 0x80) == 0) return 1;
else if((c & 0xE0) == 0xC0) return 2;
else if((c & 0xF0) == 0xE0) return 3;
else if((c & 0xF1) == 0xF0) return 4;
return 0;
}
......@@ -381,41 +381,41 @@ uint32_t lv_txt_utf8_next(const char * txt, uint32_t * i)
/*Real UTF-8 decode*/
else {
/*2 bytes UTF-8 code*/
if((txt[*i] & 0b11100000) == 0b11000000) {
result = (uint32_t)(txt[*i] & 0b00011111) << 6;
if((txt[*i] & 0xE0) == 0xC0) {
result = (uint32_t)(txt[*i] & 0x1F) << 6;
(*i)++;
if((txt[*i] & 0b11000000) != 0b10000000) return 0; /*Invalid UTF-8 code*/
result += (txt[*i] & 0b00111111);
if((txt[*i] & 0xC0) != 0x80) return 0; /*Invalid UTF-8 code*/
result += (txt[*i] & 0x3F);
(*i)++;
}
/*3 bytes UTF-8 code*/
else if((txt[*i] & 0b11110000) == 0b11100000) {
result = (uint32_t)(txt[*i] & 0b00001111) << 12;
else if((txt[*i] & 0xF0) == 0xE0) {
result = (uint32_t)(txt[*i] & 0x0F) << 12;
(*i)++;
if((txt[*i] & 0b11000000) != 0b10000000) return 0; /*Invalid UTF-8 code*/
result += (uint32_t)(txt[*i] & 0b00111111) << 6;
if((txt[*i] & 0xC0) != 0x80) return 0; /*Invalid UTF-8 code*/
result += (uint32_t)(txt[*i] & 0x3F) << 6;
(*i)++;
if((txt[*i] & 0b11000000) != 0b10000000) return 0; /*Invalid UTF-8 code*/
result += (txt[*i] & 0b00111111);
if((txt[*i] & 0xC0) != 0x80) return 0; /*Invalid UTF-8 code*/
result += (txt[*i] & 0x3F);
(*i)++;
}
/*3 bytes UTF-8 code*/
else if((txt[*i] & 0b11111000) == 0b11110000) {
result = (uint32_t)(txt[*i] & 0b00001111) << 18;
/*4 bytes UTF-8 code*/
else if((txt[*i] & 0xF8) == 0xF0) {
result = (uint32_t)(txt[*i] & 0x07) << 18;
(*i)++;
if((txt[*i] & 0b11000000) != 0b10000000) return 0; /*Invalid UTF-8 code*/
result += (uint32_t)(txt[*i] & 0b00111111) << 12;
if((txt[*i] & 0xC0) != 0x80) return 0; /*Invalid UTF-8 code*/
result += (uint32_t)(txt[*i] & 0x3F) << 12;
(*i)++;
if((txt[*i] & 0b11000000) != 0b10000000) return 0; /*Invalid UTF-8 code*/
result += (uint32_t)(txt[*i] & 0b00111111) << 6;
if((txt[*i] & 0xC0) != 0x80) return 0; /*Invalid UTF-8 code*/
result += (uint32_t)(txt[*i] & 0x3F) << 6;
(*i)++;
if((txt[*i] & 0b11000000) != 0b10000000) return 0; /*Invalid UTF-8 code*/
result += (uint32_t)(txt[*i] & 0b00111111) << 6;
if((txt[*i] & 0xC0) != 0x80) return 0; /*Invalid UTF-8 code*/
result += (uint32_t)(txt[*i] & 0x3F) << 6;
(*i)++;
} else {
(*i)++; /*Not UTF-8 char. Go the next.*/
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment