"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.

posted @   Charles_hui  阅读(269)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 别再用vector<bool>了!Google高级工程师:这可能是STL最大的设计失误
· 单元测试从入门到精通
点击右上角即可分享
微信分享提示