"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 @ 2024-10-16 17:22  Charles_hui  阅读(749)  评论(0)    收藏  举报