"lv_color_t"---LVGL像素点位数的类型定义
一.前言
- lvgl有一个像素点类型定义"lv_color_t",可以用表示多种颜色格式,RGB565、RGB888、RGB111等。
二.代码分析
1.对于不同颜色使用联合体、结构体、位域进行类型定义。
点击查看代码
typedef union
{
uint8_t full; /*must be declared first to set all bits of byte via initializer list*/
union
{
uint8_t blue : 1;
uint8_t green : 1;
uint8_t red : 1;
} ch;
} lv_color1_t;
typedef union
{
struct
{
uint8_t blue : 2;
uint8_t green : 3;
uint8_t red : 3;
} ch;
uint8_t full;
} lv_color8_t;
typedef union
{
struct
{
#if LV_COLOR_16_SWAP == 0
uint16_t blue : 5;
uint16_t green : 6;
uint16_t red : 5;
#else
uint16_t green_h : 3;
uint16_t red : 5;
uint16_t blue : 5;
uint16_t green_l : 3;
#endif
} ch;
uint16_t full;
} lv_color16_t;
typedef union
{
struct
{
uint8_t blue;
uint8_t green;
uint8_t red;
uint8_t alpha;
} ch;
uint32_t full;
} lv_color32_t;
2.使用拼接功能宏定义“LV_CONCAT3”定义颜色类型"lv_color_t"
点击查看代码
typedef LV_CONCAT3(lv_color, LV_COLOR_DEPTH, _t) lv_color_t;
3.其中LV_CONCAT3是一个宏定义的字符拼接
点击查看代码
#define _LV_CONCAT3(x, y, z) x ## y ## z
#define LV_CONCAT3(x, y, z) _LV_CONCAT3(x, y, z)
4.若“#define LV_COLOR_DEPTH 16”,则lv_color_t相当于lv_color16_t.
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 别再用vector<bool>了!Google高级工程师:这可能是STL最大的设计失误
· 单元测试从入门到精通