22#if LV_COLOR_DEPTH == 24
23#error "LV_COLOR_DEPTH 24 is deprecated. Use LV_COLOR_DEPTH 32 instead (lv_conf.h)"
26#if LV_COLOR_DEPTH != 16 && LV_COLOR_16_SWAP != 0
27#error "LV_COLOR_16_SWAP requires LV_COLOR_DEPTH == 16. Set it in lv_conf.h"
35LV_EXPORT_CONST_INT(LV_COLOR_DEPTH);
36LV_EXPORT_CONST_INT(LV_COLOR_16_SWAP);
60#if LV_COLOR_DEPTH == 1
61#define LV_COLOR_SIZE 8
62#elif LV_COLOR_DEPTH == 8
63#define LV_COLOR_SIZE 8
64#elif LV_COLOR_DEPTH == 16
65#define LV_COLOR_SIZE 16
66#elif LV_COLOR_DEPTH == 32
67#define LV_COLOR_SIZE 32
69#error "Invalid LV_COLOR_DEPTH in lv_conf.h! Set it to 1, 8, 16 or 32!"
72#if defined(__cplusplus) && !defined(_LV_COLOR_HAS_MODERN_CPP)
80#define _LV_COLOR_HAS_MODERN_CPP 1
83#if __cplusplus >= 201103L
84#define _LV_COLOR_HAS_MODERN_CPP 1
89#ifndef _LV_COLOR_HAS_MODERN_CPP
90#define _LV_COLOR_HAS_MODERN_CPP 0
93#if _LV_COLOR_HAS_MODERN_CPP
95#define _LV_COLOR_MAKE_TYPE_HELPER lv_color_t
97#define _LV_COLOR_MAKE_TYPE_HELPER (lv_color_t)
104# define LV_COLOR_SET_R1(c, v) (c).ch.red = (uint8_t)((v) & 0x1)
105# define LV_COLOR_SET_G1(c, v) (c).ch.green = (uint8_t)((v) & 0x1)
106# define LV_COLOR_SET_B1(c, v) (c).ch.blue = (uint8_t)((v) & 0x1)
107# define LV_COLOR_SET_A1(c, v) do {} while(0)
109# define LV_COLOR_GET_R1(c) (c).ch.red
110# define LV_COLOR_GET_G1(c) (c).ch.green
111# define LV_COLOR_GET_B1(c) (c).ch.blue
112# define LV_COLOR_GET_A1(c) 0xFF
114# define _LV_COLOR_ZERO_INITIALIZER1 {0x00}
115# define LV_COLOR_MAKE1(r8, g8, b8) {(uint8_t)((b8 >> 7) | (g8 >> 7) | (r8 >> 7))}
117# define LV_COLOR_SET_R8(c, v) (c).ch.red = (uint8_t)((v) & 0x7U)
118# define LV_COLOR_SET_G8(c, v) (c).ch.green = (uint8_t)((v) & 0x7U)
119# define LV_COLOR_SET_B8(c, v) (c).ch.blue = (uint8_t)((v) & 0x3U)
120# define LV_COLOR_SET_A8(c, v) do {} while(0)
122# define LV_COLOR_GET_R8(c) (c).ch.red
123# define LV_COLOR_GET_G8(c) (c).ch.green
124# define LV_COLOR_GET_B8(c) (c).ch.blue
125# define LV_COLOR_GET_A8(c) 0xFF
127# define _LV_COLOR_ZERO_INITIALIZER8 {{0x00, 0x00, 0x00}}
128# define LV_COLOR_MAKE8(r8, g8, b8) {{(uint8_t)((b8 >> 6) & 0x3U), (uint8_t)((g8 >> 5) & 0x7U), (uint8_t)((r8 >> 5) & 0x7U)}}
130# define LV_COLOR_SET_R16(c, v) (c).ch.red = (uint8_t)((v) & 0x1FU)
131#if LV_COLOR_16_SWAP == 0
132# define LV_COLOR_SET_G16(c, v) (c).ch.green = (uint8_t)((v) & 0x3FU)
134# define LV_COLOR_SET_G16(c, v) {(c).ch.green_h = (uint8_t)(((v) >> 3) & 0x7); (c).ch.green_l = (uint8_t)((v) & 0x7);}
136# define LV_COLOR_SET_B16(c, v) (c).ch.blue = (uint8_t)((v) & 0x1FU)
137# define LV_COLOR_SET_A16(c, v) do {} while(0)
139# define LV_COLOR_GET_R16(c) (c).ch.red
140#if LV_COLOR_16_SWAP == 0
141# define LV_COLOR_GET_G16(c) (c).ch.green
143# define LV_COLOR_GET_G16(c) (((c).ch.green_h << 3) + (c).ch.green_l)
145# define LV_COLOR_GET_B16(c) (c).ch.blue
146# define LV_COLOR_GET_A16(c) 0xFF
148#if LV_COLOR_16_SWAP == 0
149# define _LV_COLOR_ZERO_INITIALIZER16 {{0x00, 0x00, 0x00}}
150# define LV_COLOR_MAKE16(r8, g8, b8) {{(uint8_t)((b8 >> 3) & 0x1FU), (uint8_t)((g8 >> 2) & 0x3FU), (uint8_t)((r8 >> 3) & 0x1FU)}}
152# define _LV_COLOR_ZERO_INITIALIZER16 {{0x00, 0x00, 0x00, 0x00}}
153# define LV_COLOR_MAKE16(r8, g8, b8) {{(uint8_t)((g8 >> 5) & 0x7U), (uint8_t)((r8 >> 3) & 0x1FU), (uint8_t)((b8 >> 3) & 0x1FU), (uint8_t)((g8 >> 2) & 0x7U)}}
156# define LV_COLOR_SET_R32(c, v) (c).ch.red = (uint8_t)((v) & 0xFF)
157# define LV_COLOR_SET_G32(c, v) (c).ch.green = (uint8_t)((v) & 0xFF)
158# define LV_COLOR_SET_B32(c, v) (c).ch.blue = (uint8_t)((v) & 0xFF)
159# define LV_COLOR_SET_A32(c, v) (c).ch.alpha = (uint8_t)((v) & 0xFF)
161# define LV_COLOR_GET_R32(c) (c).ch.red
162# define LV_COLOR_GET_G32(c) (c).ch.green
163# define LV_COLOR_GET_B32(c) (c).ch.blue
164# define LV_COLOR_GET_A32(c) (c).ch.alpha
166# define _LV_COLOR_ZERO_INITIALIZER32 {{0x00, 0x00, 0x00, 0x00}}
167# define LV_COLOR_MAKE32(r8, g8, b8) {{b8, g8, r8, 0xff}}
173#define LV_COLOR_SET_R(c, v) LV_CONCAT(LV_COLOR_SET_R, LV_COLOR_DEPTH)(c, v)
174#define LV_COLOR_SET_G(c, v) LV_CONCAT(LV_COLOR_SET_G, LV_COLOR_DEPTH)(c, v)
175#define LV_COLOR_SET_B(c, v) LV_CONCAT(LV_COLOR_SET_B, LV_COLOR_DEPTH)(c, v)
176#define LV_COLOR_SET_A(c, v) LV_CONCAT(LV_COLOR_SET_A, LV_COLOR_DEPTH)(c, v)
178#define LV_COLOR_GET_R(c) LV_CONCAT(LV_COLOR_GET_R, LV_COLOR_DEPTH)(c)
179#define LV_COLOR_GET_G(c) LV_CONCAT(LV_COLOR_GET_G, LV_COLOR_DEPTH)(c)
180#define LV_COLOR_GET_B(c) LV_CONCAT(LV_COLOR_GET_B, LV_COLOR_DEPTH)(c)
181#define LV_COLOR_GET_A(c) LV_CONCAT(LV_COLOR_GET_A, LV_COLOR_DEPTH)(c)
183#define _LV_COLOR_ZERO_INITIALIZER LV_CONCAT(_LV_COLOR_ZERO_INITIALIZER, LV_COLOR_DEPTH)
184#define LV_COLOR_MAKE(r8, g8, b8) LV_CONCAT(LV_COLOR_MAKE, LV_COLOR_DEPTH)(r8, g8, b8)
210#if LV_COLOR_16_SWAP == 0
215 uint16_t green_h : 3;
218 uint16_t green_l : 3;
234typedef LV_CONCAT3(uint, LV_COLOR_SIZE, _t) lv_color_int_t;
235typedef LV_CONCAT3(lv_color, LV_COLOR_DEPTH, _t) lv_color_t;
245typedef uint8_t lv_opa_t;
253 lv_color_filter_cb_t filter_cb;
262 LV_PALETTE_DEEP_PURPLE,
265 LV_PALETTE_LIGHT_BLUE,
269 LV_PALETTE_LIGHT_GREEN,
274 LV_PALETTE_DEEP_ORANGE,
276 LV_PALETTE_BLUE_GREY,
279 LV_PALETTE_NONE = 0xff,
299static inline uint8_t lv_color_to1(lv_color_t color)
301#if LV_COLOR_DEPTH == 1
303#elif LV_COLOR_DEPTH == 8
304 if((LV_COLOR_GET_R(color) & 0x4) || (LV_COLOR_GET_G(color) & 0x4) || (LV_COLOR_GET_B(color) & 0x2)) {
310#elif LV_COLOR_DEPTH == 16
311 if((LV_COLOR_GET_R(color) & 0x10) || (LV_COLOR_GET_G(color) & 0x20) || (LV_COLOR_GET_B(color) & 0x10)) {
317#elif LV_COLOR_DEPTH == 32
318 if((LV_COLOR_GET_R(color) & 0x80) || (LV_COLOR_GET_G(color) & 0x80) || (LV_COLOR_GET_B(color) & 0x80)) {
327static inline uint8_t lv_color_to8(lv_color_t color)
329#if LV_COLOR_DEPTH == 1
334#elif LV_COLOR_DEPTH == 8
336#elif LV_COLOR_DEPTH == 16
338 LV_COLOR_SET_R8(ret, LV_COLOR_GET_R(color) >> 2);
339 LV_COLOR_SET_G8(ret, LV_COLOR_GET_G(color) >> 3);
340 LV_COLOR_SET_B8(ret, LV_COLOR_GET_B(color) >> 3);
342#elif LV_COLOR_DEPTH == 32
344 LV_COLOR_SET_R8(ret, LV_COLOR_GET_R(color) >> 5);
345 LV_COLOR_SET_G8(ret, LV_COLOR_GET_G(color) >> 5);
346 LV_COLOR_SET_B8(ret, LV_COLOR_GET_B(color) >> 6);
351static inline uint16_t lv_color_to16(lv_color_t color)
353#if LV_COLOR_DEPTH == 1
358#elif LV_COLOR_DEPTH == 8
360 LV_COLOR_SET_R16(ret, LV_COLOR_GET_R(color) * 4);
361 LV_COLOR_SET_G16(ret, LV_COLOR_GET_G(color) * 9);
362 LV_COLOR_SET_B16(ret, LV_COLOR_GET_B(color) * 10);
364#elif LV_COLOR_DEPTH == 16
366#elif LV_COLOR_DEPTH == 32
368 LV_COLOR_SET_R16(ret, LV_COLOR_GET_R(color) >> 3);
369 LV_COLOR_SET_G16(ret, LV_COLOR_GET_G(color) >> 2);
370 LV_COLOR_SET_B16(ret, LV_COLOR_GET_B(color) >> 3);
375static inline uint32_t lv_color_to32(lv_color_t color)
377#if LV_COLOR_DEPTH == 1
382#elif LV_COLOR_DEPTH == 8
384 LV_COLOR_SET_R32(ret, LV_COLOR_GET_R(color) * 36);
385 LV_COLOR_SET_G32(ret, LV_COLOR_GET_G(color) * 36);
386 LV_COLOR_SET_B32(ret, LV_COLOR_GET_B(color) * 85);
387 LV_COLOR_SET_A32(ret, 0xFF);
389#elif LV_COLOR_DEPTH == 16
420 LV_COLOR_SET_R32(ret, (LV_COLOR_GET_R(color) * 263 + 7) >> 5);
421 LV_COLOR_SET_G32(ret, (LV_COLOR_GET_G(color) * 259 + 3) >> 6);
422 LV_COLOR_SET_B32(ret, (LV_COLOR_GET_B(color) * 263 + 7) >> 5);
423 LV_COLOR_SET_A32(ret, 0xFF);
425#elif LV_COLOR_DEPTH == 32
439LV_ATTRIBUTE_FAST_MEM
static inline lv_color_t lv_color_mix(lv_color_t c1, lv_color_t c2, uint8_t mix)
443#if LV_COLOR_DEPTH == 16 && LV_COLOR_16_SWAP == 0 && LV_COLOR_MIX_ROUND_OFS == 0
445 mix = (uint32_t)((uint32_t)mix + 4) >> 3;
446 uint32_t bg = (uint32_t)((uint32_t)c2.full | ((uint32_t)c2.full << 16)) &
448 uint32_t fg = (uint32_t)((uint32_t)c1.full | ((uint32_t)c1.full << 16)) & 0x7E0F81F;
449 uint32_t result = ((((fg - bg) * mix) >> 5) + bg) & 0x7E0F81F;
450 ret.full = (uint16_t)((result >> 16) | result);
451#elif LV_COLOR_DEPTH != 1
453 LV_COLOR_SET_R(ret, LV_UDIV255((uint16_t)LV_COLOR_GET_R(c1) * mix + LV_COLOR_GET_R(c2) *
454 (255 - mix) + LV_COLOR_MIX_ROUND_OFS));
455 LV_COLOR_SET_G(ret, LV_UDIV255((uint16_t)LV_COLOR_GET_G(c1) * mix + LV_COLOR_GET_G(c2) *
456 (255 - mix) + LV_COLOR_MIX_ROUND_OFS));
457 LV_COLOR_SET_B(ret, LV_UDIV255((uint16_t)LV_COLOR_GET_B(c1) * mix + LV_COLOR_GET_B(c2) *
458 (255 - mix) + LV_COLOR_MIX_ROUND_OFS));
459 LV_COLOR_SET_A(ret, 0xFF);
462 ret.full = mix > LV_OPA_50 ? c1.full : c2.full;
468LV_ATTRIBUTE_FAST_MEM
static inline void lv_color_premult(lv_color_t c, uint8_t mix, uint16_t * out)
470#if LV_COLOR_DEPTH != 1
471 out[0] = (uint16_t)LV_COLOR_GET_R(c) * mix;
472 out[1] = (uint16_t)LV_COLOR_GET_G(c) * mix;
473 out[2] = (uint16_t)LV_COLOR_GET_B(c) * mix;
477 out[0] = LV_COLOR_GET_R(c);
478 out[1] = LV_COLOR_GET_G(c);
479 out[2] = LV_COLOR_GET_B(c);
493LV_ATTRIBUTE_FAST_MEM
static inline lv_color_t lv_color_mix_premult(uint16_t * premult_c1, lv_color_t c2, uint8_t mix)
496#if LV_COLOR_DEPTH != 1
498 LV_COLOR_SET_R(ret, LV_UDIV255(premult_c1[0] + LV_COLOR_GET_R(c2) * mix + LV_COLOR_MIX_ROUND_OFS));
499 LV_COLOR_SET_G(ret, LV_UDIV255(premult_c1[1] + LV_COLOR_GET_G(c2) * mix + LV_COLOR_MIX_ROUND_OFS));
500 LV_COLOR_SET_B(ret, LV_UDIV255(premult_c1[2] + LV_COLOR_GET_B(c2) * mix + LV_COLOR_MIX_ROUND_OFS));
501 LV_COLOR_SET_A(ret, 0xFF);
506 LV_COLOR_SET_R(c1, premult_c1[0]);
507 LV_COLOR_SET_G(c1, premult_c1[1]);
508 LV_COLOR_SET_B(c1, premult_c1[2]);
509 ret.full = mix > LV_OPA_50 ? c2.full : c1.full;
524LV_ATTRIBUTE_FAST_MEM
static inline void lv_color_mix_with_alpha(lv_color_t bg_color, lv_opa_t bg_opa,
525 lv_color_t fg_color, lv_opa_t fg_opa,
526 lv_color_t * res_color, lv_opa_t * res_opa)
529 if(fg_opa >= LV_OPA_MAX || bg_opa <= LV_OPA_MIN) {
530 res_color->full = fg_color.full;
534 else if(fg_opa <= LV_OPA_MIN) {
535 res_color->full = bg_color.full;
539 else if(bg_opa >= LV_OPA_MAX) {
540 *res_color = lv_color_mix(fg_color, bg_color, fg_opa);
541 *res_opa = LV_OPA_COVER;
546 static lv_opa_t fg_opa_save = 0;
547 static lv_opa_t bg_opa_save = 0;
548 static lv_color_t fg_color_save = _LV_COLOR_ZERO_INITIALIZER;
549 static lv_color_t bg_color_save = _LV_COLOR_ZERO_INITIALIZER;
550 static lv_color_t res_color_saved = _LV_COLOR_ZERO_INITIALIZER;
551 static lv_opa_t res_opa_saved = 0;
553 if(fg_opa != fg_opa_save || bg_opa != bg_opa_save || fg_color.full != fg_color_save.full ||
554 bg_color.full != bg_color_save.full) {
555 fg_opa_save = fg_opa;
556 bg_opa_save = bg_opa;
557 fg_color_save.full = fg_color.full;
558 bg_color_save.full = bg_color.full;
561 res_opa_saved = 255 - ((uint16_t)((uint16_t)(255 - fg_opa) * (255 - bg_opa)) >> 8);
562 LV_ASSERT(res_opa_saved != 0);
563 lv_opa_t ratio = (uint16_t)((uint16_t)fg_opa * 255) / res_opa_saved;
564 res_color_saved = lv_color_mix(fg_color, bg_color, ratio);
568 res_color->full = res_color_saved.full;
569 *res_opa = res_opa_saved;
580static inline uint8_t lv_color_brightness(lv_color_t color)
583 c32.full = lv_color_to32(color);
584 uint16_t bright = (uint16_t)(3u * LV_COLOR_GET_R32(c32) + LV_COLOR_GET_B32(c32) + 4u * LV_COLOR_GET_G32(c32));
585 return (uint8_t)(bright >> 3);
588static inline lv_color_t lv_color_make(uint8_t r, uint8_t g, uint8_t b)
590 return _LV_COLOR_MAKE_TYPE_HELPER LV_COLOR_MAKE(r, g, b);
593static inline lv_color_t lv_color_hex(uint32_t c)
595#if LV_COLOR_DEPTH == 16
597#if LV_COLOR_16_SWAP == 0
612 r.full = (uint16_t)(((c & 0xF80000) >> 8) | ((c & 0xFC00) >> 5) | ((c & 0xFF) >> 3));
615 r.full = (uint16_t)(((c & 0xF80000) >> 16) | ((c & 0xFC00) >> 13) | ((c & 0x1C00) << 3) | ((c & 0xF8) << 5));
618#elif LV_COLOR_DEPTH == 32
620 r.full = c | 0xFF000000;
623 return lv_color_make((uint8_t)((c >> 16) & 0xFF), (uint8_t)((c >> 8) & 0xFF), (uint8_t)(c & 0xFF));
627static inline lv_color_t lv_color_hex3(uint32_t c)
629 return lv_color_make((uint8_t)(((c >> 4) & 0xF0) | ((c >> 8) & 0xF)), (uint8_t)((c & 0xF0) | ((c & 0xF0) >> 4)),
630 (uint8_t)((c & 0xF) | ((c & 0xF) << 4)));
640LV_ATTRIBUTE_FAST_MEM
void lv_color_fill(lv_color_t * buf, lv_color_t color, uint32_t px_num);
643lv_color_t lv_color_lighten(lv_color_t c, lv_opa_t lvl);
645lv_color_t lv_color_darken(lv_color_t c, lv_opa_t lvl);
647lv_color_t lv_color_change_lightness(lv_color_t c, lv_opa_t lvl);
678static inline lv_color_t lv_color_chroma_key(
void)
680 return LV_COLOR_CHROMA_KEY;
688lv_color_t lv_palette_main(lv_palette_t p);
689static inline lv_color_t lv_color_white(
void)
691 return lv_color_make(0xff, 0xff, 0xff);
693static inline lv_color_t lv_color_black(
void)
695 return lv_color_make(0x00, 0x0, 0x00);
697lv_color_t lv_palette_lighten(lv_palette_t p, uint8_t lvl);
698lv_color_t lv_palette_darken(lv_palette_t p, uint8_t lvl);
lv_color_t lv_color_hsv_to_rgb(uint16_t h, uint8_t s, uint8_t v)
lv_color_hsv_t lv_color_to_hsv(lv_color_t color)
lv_color_hsv_t lv_color_rgb_to_hsv(uint8_t r8, uint8_t g8, uint8_t b8)
Definition lv_color.h:252
Definition lv_color.h:237
Definition lv_color.h:208
Definition lv_color.h:190
Definition lv_color.h:224
Definition lv_color.h:199