VSF Documented
vsf_tgui_sv_color.h
Go to the documentation of this file.
1/*****************************************************************************
2 * Copyright(C)2009-2022 by VSF Team *
3 * *
4 * Licensed under the Apache License, Version 2.0 (the "License"); *
5 * you may not use this file except in compliance with the License. *
6 * You may obtain a copy of the License at *
7 * *
8 * http://www.apache.org/licenses/LICENSE-2.0 *
9 * *
10 * Unless required by applicable law or agreed to in writing, software *
11 * distributed under the License is distributed on an "AS IS" BASIS, *
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
13 * See the License for the specific language governing permissions and *
14 * limitations under the License. *
15 * *
16 ****************************************************************************/
17
18#ifndef __VSF_TINY_GUI_COLOR_H__
19#define __VSF_TINY_GUI_COLOR_H__
20
21/*============================ INCLUDES ======================================*/
22#include "../../vsf_tgui_cfg.h"
23
24#if VSF_USE_TINY_GUI == ENABLED
25/*============================ MACROS ========================================*/
26
27#ifndef VSF_TGUI_SV_CFG_COLOR_HAS_ALPHA
28# define VSF_TGUI_SV_CFG_COLOR_HAS_ALPHA ENABLED
29#endif
30
31#if VSF_TGUI_CFG_COLOR_MODE == VSF_TGUI_COLOR_ARGB_8888
32# undef VSF_TGUI_SV_CFG_COLOR_HAS_ALPHA
33# define VSF_TGUI_SV_CFG_COLOR_HAS_ALPHA ENABLED
34#endif
35
36#if VSF_TGUI_SV_CFG_COLOR_HAS_ALPHA == ENABLED
37# define __VSF_TGUI_COLOR_RGBA(__R, __G, __B, __A) ((vsf_tgui_v_color_t){.red = __R, .green = __G, .blue = __B, .alpha = __A})
38#else
39# define __VSF_TGUI_COLOR_RGBA(__R, __G, __B, __A) ((vsf_tgui_v_color_t){.red = __R, .green = __G, .blue = __B,})
40#endif
41
42#if VSF_TGUI_CFG_COLOR_MODE == VSF_TGUI_COLOR_ARGB_8888
43# define VSF_TGUI_COLOR_RGBA(__R, __G, __B, __A) __VSF_TGUI_COLOR_RGBA(__R, __G, __B, __A)
44#elif VSF_TGUI_CFG_COLOR_MODE == VSF_TGUI_COLOR_RGB16_565
45# define VSF_TGUI_COLOR_RGBA(__R, __G, __B, __A) __VSF_TGUI_COLOR_RGBA(__R >> 3, __G >> 2, __B >> 3, __A)
46#else
47# error "TODO: add more color support"
48#endif
49#define VSF_TGUI_COLOR_RGB(__R, __G, __B) VSF_TGUI_COLOR_RGBA(__R, __G, __B, 0xFF)
50
51#if VSF_TGUI_SV_CFG_COLOR_HAS_ALPHA == ENABLED
52# define VSF_TGUI_COLOR_TRANSPARENT VSF_TGUI_COLOR_RGBA(0, 0, 0, 0)
53#endif
54#define VSF_TGUI_COLOR_WHITE VSF_TGUI_COLOR_RGB(0xFF, 0xFF, 0xFF) // Red:100% Green:100% Blue:100%
55#define VSF_TGUI_COLOR_SILVER VSF_TGUI_COLOR_RGB(0xC0, 0xC0, 0xC0) // Red: 75% Green: 75% Blue: 75%
56#define VSF_TGUI_COLOR_GRAY VSF_TGUI_COLOR_RGB(0x80, 0x80, 0x80) // Red: 50% Green: 50% Blue: 50%
57#define VSF_TGUI_COLOR_BLACK VSF_TGUI_COLOR_RGB(0x00, 0x00, 0x00) // Red: 0% Green: 0% Blue: 0%
58#define VSF_TGUI_COLOR_RED VSF_TGUI_COLOR_RGB(0xFF, 0x00, 0x00) // Red:100% Green: 0% Blue: 0%
59#define VSF_TGUI_COLOR_MAROON VSF_TGUI_COLOR_RGB(0x80, 0x00, 0x00) // Red: 50% Green: 0% Blue: 0%
60#define VSF_TGUI_COLOR_YELLOW VSF_TGUI_COLOR_RGB(0xFF, 0xFF, 0x00) // Red:100% Green:100% Blue: 0%
61#define VSF_TGUI_COLOR_OLIVE VSF_TGUI_COLOR_RGB(0x80, 0x80, 0x00) // Red: 50% Green: 50% Blue: 0%
62#define VSF_TGUI_COLOR_LIME VSF_TGUI_COLOR_RGB(0x00, 0xFF, 0x00) // Red: 0% Green:100% Blue: 0%
63#define VSF_TGUI_COLOR_GREEN VSF_TGUI_COLOR_RGB(0x00, 0x80, 0x00) // Red: 0% Green: 50% Blue: 0%
64#define VSF_TGUI_COLOR_AQUA VSF_TGUI_COLOR_RGB(0x00, 0xFF, 0xFF) // Red: 0% Green:100% Blue:100%
65#define VSF_TGUI_COLOR_TEAL VSF_TGUI_COLOR_RGB(0x00, 0x80, 0x80) // Red: 0% Green: 50% Blue: 50%
66#define VSF_TGUI_COLOR_BLUE VSF_TGUI_COLOR_RGB(0x00, 0x00, 0xFF) // Red: 0% Green: 0% Blue:100%
67#define VSF_TGUI_COLOR_NAVY VSF_TGUI_COLOR_RGB(0x00, 0x00, 0x80) // Red: 0% Green: 0% Blue: 50%
68#define VSF_TGUI_COLOR_FUCHSIA VSF_TGUI_COLOR_RGB(0xFF, 0x00, 0xFF) // Red:100% Green: 0% Blue:100%
69#define VSF_TGUI_COLOR_PURPLE VSF_TGUI_COLOR_RGB(0x80, 0x00, 0x80) // Red: 50% Green: 0% Blue: 50%
70
71/*============================ MACROFIED FUNCTIONS ===========================*/
72/*============================ TYPES =========================================*/
74 union {
76 struct {
80 };
81 };
82#if VSF_TGUI_SV_CFG_COLOR_HAS_ALPHA == ENABLED
84#endif
86
88 union {
90 struct {
94 };
95 };
96#if VSF_TGUI_SV_CFG_COLOR_HAS_ALPHA == ENABLED
98#endif
100
103 struct {
108 };
110
111#if VSF_TGUI_CFG_COLOR_MODE == VSF_TGUI_COLOR_BGR_565
113#elif VSF_TGUI_CFG_COLOR_MODE == VSF_TGUI_COLOR_RGB_565
115#elif VSF_TGUI_CFG_COLOR_MODE == VSF_TGUI_COLOR_ARGB_8888
117#else
118typedef VSF_TGUI_CFG_COLOR_TYPE vsf_tgui_v_color_t;
119#endif
120
121/*============================ GLOBAL VARIABLES ==============================*/
122/*============================ PROTOTYPES ====================================*/
123
124#if VSF_TGUI_SV_CFG_MIX_AS_FUNCTION == ENABLED
126#else
127# if VSF_TGUI_SV_CFG_COLOR_HAS_ALPHA == ENABLED
128# define __vsf_tgui_sv_color_mix_alpha() \
129 __vsf_tgui_sv_color_mix_result__.alpha = 0xFF;
130# else
131# define __vsf_tgui_sv_color_mix_alpha()
132# endif
133
134# if VSF_TGUI_CFG_COLOR_MODE == VSF_TGUI_COLOR_ARGB_8888
135# define vsf_tgui_sv_color_mix(__color_0, __color_1, __mix) ({ \
136 uint_fast8_t __vsf_tgui_sv_color_mix__ = (__mix); \
137 vsf_tgui_v_color_t __vsf_tgui_sv_color_mix_result__; \
138 __vsf_tgui_sv_color_mix_result__.value = \
139 (((((__color_0).value >> 8) & 0x00FF00FF) * __vsf_tgui_sv_color_mix__) & 0xFF00FF00)\
140 + (((((__color_0).value & 0x00FF00FF) * __vsf_tgui_sv_color_mix__) >> 8) & 0x00FF00FF);\
141 __vsf_tgui_sv_color_mix__ = __vsf_tgui_sv_color_mix__ ^ 0xFF; \
142 __vsf_tgui_sv_color_mix_result__.value += \
143 (((((__color_1).value >> 8) & 0x00FF00FF) * __vsf_tgui_sv_color_mix__) & 0xFF00FF00) \
144 + (((((__color_1).value & 0x00FF00FF) * __vsf_tgui_sv_color_mix__) >> 8) & 0x00FF00FF); \
145 __vsf_tgui_sv_color_mix_alpha(); \
146 __vsf_tgui_sv_color_mix_result__; \
147 })
148# elif VSF_TGUI_CFG_COLOR_MODE == VSF_TGUI_COLOR_RGB_565
149# define vsf_tgui_sv_color_mix(__color_0, __color_1, __mix) ({ \
150 vsf_tgui_v_color_t __vsf_tgui_sv_color_mix_result__; \
151 uint32_t __vsf_tgui_sv_color_mix0__ = (__color_1).value & 0xF81F; \
152 __vsf_tgui_sv_color_mix0__ += ((((__color_0).value & 0xF81F) - __vsf_tgui_sv_color_mix0__) * (__mix >> 2)) >> 6;\
153 uint32_t __vsf_tgui_sv_color_mix1__ = (__color_1).value & 0x07E0; \
154 __vsf_tgui_sv_color_mix1__ += ((((__color_0).value & 0x07E0) - __vsf_tgui_sv_color_mix1__) * (__mix)) >> 8;\
155 __vsf_tgui_sv_color_mix_result__.value = (__vsf_tgui_sv_color_mix0__ & 0xF81F) | (__vsf_tgui_sv_color_mix1__ & 0x07E0);\
156 __vsf_tgui_sv_color_mix_alpha(); \
157 __vsf_tgui_sv_color_mix_result__; \
158 })
159# else
160# define vsf_tgui_sv_color_mix(__color_0, __color_1, __mix) ({ \
161 vsf_tgui_v_color_t __vsf_tgui_sv_color_mix_result__; \
162 uint_fast8_t __vsf_tgui_sv_color_rmix__ = (__mix) ^ 0xFF; \
163 __vsf_tgui_sv_color_mix_result__.red = ((uint32_t)(__color_0).red * (__mix) + (uint32_t)(__color_1).red * __vsf_tgui_sv_color_rmix__) / 255;\
164 __vsf_tgui_sv_color_mix_result__.green = ((uint32_t)(__color_0).green * (__mix) + (uint32_t)(__color_1).green * __vsf_tgui_sv_color_rmix__) / 255;\
165 __vsf_tgui_sv_color_mix_result__.blue = ((uint32_t)(__color_0).blue * (__mix) + (uint32_t)(__color_1).blue * __vsf_tgui_sv_color_rmix__) / 255;\
166 __vsf_tgui_sv_color_mix_alpha(); \
167 __vsf_tgui_sv_color_mix_result__; \
168 })
169# endif
170#endif
171
172#if VSF_TGUI_SV_CFG_COLOR_HAS_ALPHA == ENABLED
173# define vsf_tgui_sv_color_get_trans_rate(__color) ((__color).alpha)
174# define vsf_tgui_sv_color_set_trans_rate(__color_ptr, __alpha) do { (__color_ptr)->alpha = (__alpha); } while (0)
175# define vsf_tgui_sv_color_is_opaque(__color) ((__color).alpha == 0xFF)
176#else
177# define vsf_tgui_sv_color_get_trans_rate(__color) 0xFF
178# define vsf_tgui_sv_color_set_trans_rate(__color_ptr, __alpha)
179# define vsf_tgui_sv_color_is_opaque(__color) true
180#endif
181
182#if VSF_TGUI_CFG_COLOR_MODE == VSF_TGUI_COLOR_ARGB_8888
183# define vsf_tgui_sv_argb8888_to_color(__color) (__color)
184#else
186#endif
187#if VSF_TGUI_CFG_COLOR_MODE == VSF_TGUI_COLOR_RGB_565
188# define vsf_tgui_sv_rgb565_to_color(__color) (__color)
189#else
191#endif
192#if VSF_TGUI_CFG_COLOR_MODE == VSF_TGUI_COLOR_BGR_565
193# define vsf_tgui_sv_bgr565_to_color(__color) (__color)
194#else
196#endif
197
198#if VSF_TGUI_CFG_COLOR_MODE == VSF_TGUI_COLOR_ARGB_8888
199# define vsf_tgui_sv_color_to_argb8888(__color) (__color)
200#else
202#endif
203#if VSF_TGUI_CFG_COLOR_MODE == VSF_TGUI_COLOR_RGB_565
204# define vsf_tgui_sv_color_to_rgb565(__color) (__color)
205#else
207#endif
208#if VSF_TGUI_CFG_COLOR_MODE == VSF_TGUI_COLOR_BGR_565
209# define vsf_tgui_sv_color_to_bgr565(__color) (__color)
210#else
212#endif
213
214#endif
215
216#endif
217/* EOF */
unsigned short uint16_t
Definition lvgl.h:41
unsigned int uint32_t
Definition lvgl.h:43
unsigned char uint8_t
Definition lvgl.h:40
unsigned char uint_fast8_t
Definition stdint.h:23
Definition vsf_tgui_sv_color.h:87
uint16_t blue
Definition vsf_tgui_sv_color.h:93
uint16_t value
Definition vsf_tgui_sv_color.h:89
uint16_t red
Definition vsf_tgui_sv_color.h:91
uint8_t alpha
Definition vsf_tgui_sv_color.h:97
uint16_t green
Definition vsf_tgui_sv_color.h:92
Definition vsf_tgui_sv_color.h:73
uint16_t blue
Definition vsf_tgui_sv_color.h:77
uint8_t alpha
Definition vsf_tgui_sv_color.h:83
uint16_t value
Definition vsf_tgui_sv_color.h:75
uint16_t red
Definition vsf_tgui_sv_color.h:79
uint16_t green
Definition vsf_tgui_sv_color.h:78
Definition vsf_tgui_sv_color.h:101
uint8_t red
Definition vsf_tgui_sv_color.h:106
uint8_t green
Definition vsf_tgui_sv_color.h:105
uint8_t blue
Definition vsf_tgui_sv_color.h:104
uint32_t value
Definition vsf_tgui_sv_color.h:102
uint8_t alpha
Definition vsf_tgui_sv_color.h:107
uint32_t color
Definition vsf_sdl2_pixelformat.c:31
vsf_tgui_v_color_t vsf_tgui_sv_color_mix(vsf_tgui_v_color_t color_0, vsf_tgui_v_color_t color_1, uint_fast8_t mix)
#define vsf_tgui_sv_color_to_bgr565(__color)
Definition vsf_tgui_sv_color.h:209
#define vsf_tgui_sv_bgr565_to_color(__color)
Definition vsf_tgui_sv_color.h:193
#define vsf_tgui_sv_rgb565_to_color(__color)
Definition vsf_tgui_sv_color.h:188
vsf_tgui_sv_color_bgr565_t vsf_tgui_v_color_t
Definition vsf_tgui_sv_color.h:112
#define vsf_tgui_sv_argb8888_to_color(__color)
Definition vsf_tgui_sv_color.h:183
#define vsf_tgui_sv_color_to_rgb565(__color)
Definition vsf_tgui_sv_color.h:204
#define vsf_tgui_sv_color_to_argb8888(__color)
Definition vsf_tgui_sv_color.h:199