Blending
D21x,D13x 系列的显示引擎 (Display Engine) 支持一个 UI 图层和一个 Video 图层。UI 图层在 Video 图层顶部,UI 图层和 Video 图层重叠的区域进行 Color Key 操作和 Alpha 叠加操作,Color Key 操作优先于 Alpha 叠加。
Alpha Blending
UI alpha 有三种模式:pixel alpha 模式、全局 alpha 模式、混合 alpha 模式:
1、 pixels alpha 模式: ui_alpha = pixel_alpha, 当 pixel alpha 不存在时,ui_alpha = 255 2、 全局 alpha 模式: ui_alpha = G_ALPHA,G_ALPHA 为设置的全局 alpha 值,取值范围为 0~255 3、 混合 alpha 模式: ui_alpha = pixels alpha * G_ALPHA / 255
UI 图层和 Video 图层透明度混合计算:
bash
r_out = (r_ui * alpha_ui + r_video * (255 - alpha_ui))/255
g_out = (g_ui * alpha_ui + g_video * (255 - alpha_ui))/255
b_out = (b_ui * alpha_ui + b_video * (255 - alpha_ui))/255
1
2
3
2
3
数据结构
bash
#define AICFB_PIXEL_ALPHA_MODE 0
#define AICFB_GLOBAL_ALPHA_MODE 1
#define AICFB_MIXDER_ALPHA_MODE 2
/**
* struct aicfb_alpha_config - aicfb layer alpha blending config
*
* @layer_id: the layer id
*
* @enable
* 0: disable alpha
* 1: enable alpha
*
* @mode: alpha mode
* 0: pixel alpha mode
* 1: global alpha mode
* 2: mixder alpha mode(alpha = pixel alpha * global alpha / 255)
*
* @value: global alpha value (0~255)
* used by global alpha mode and mixer alpha mode
*
*/
struct aicfb_alpha_config {
unsigned int layer_id;
unsigned int enable;
unsigned int mode;
unsigned int value;
};
/** get layer alpha blendig config */
#define AICFB_GET_ALPHA_CONFIG _IOWR(IOC_TYPE_FB, 0x26, \
struct aicfb_alpha_config)
/** update layer alpha blendig config */
#define AICFB_UPDATE_ALPHA_CONFIG _IOW(IOC_TYPE_FB, 0x27, \
struct aicfb_alpha_config)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
使用例程
bash
static int set_ui_layer_alpha(int val)
{
int ret = 0;
struct aicfb_alpha_config alpha = {0};
alpha.layer_id = AICFB_LAYER_TYPE_UI;
alpha.mode = AICFB_GLOBAL_ALPHA_MODE;
alpha.enable = 1;
alpha.value = val;
ret = mpp_fb_ioctl(g_mpp_fb, AICFB_UPDATE_ALPHA_CONFIG, &alpha);
if (ret < 0)
ERR("ioctl update alpha config failed!\n");
return ret;
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
2
3
4
5
6
7
8
9
10
11
12
13
14
15
注解
Video 图层不支持配置 Alpha
常见问题
1、默认配置下 Video 图层不显示
Luban Lite SDK UI alpha 默认 pixel alpha 模式
pixel alpha 为 0xFF
framebuffer 缺失 alpha 分量,详见问题二
2、framebuffer RGB565/RGB888 格式设置 UI pixel alpha 模式不生效
framebuffer 16/24 bit RGB 格式缺失 pixel alpha,ui_alpha 默认为 255,UI 图层不透明,Video 图层不可见。
Color Key
通过设置 8 bit R,G,B 三原色进行 Color Key 操作
数据结构
bash
/**
* struct aicfb_ck_config - aicfb layer color key blending config
*
* @layer_id: the layer id
*
* @ck_enable
* 0: disable color key
* 1: enable color key
*
*
* @ck_value: color key rgb value to match the layer pixels
* bit[31:24]: reserved
* bit[23:16]: R value
* bit[15:8]: G value
* bit[7:0]: B value
*
*/
struct aicfb_ck_config {
unsigned int layer_id;
unsigned int enable;
unsigned int value;
};
/** get layer color key config */
#define AICFB_GET_CK_CONFIG _IOWR(IOC_TYPE_FB, 0x28, struct aicfb_ck_config)
/** update layer color key config */
#define AICFB_UPDATE_CK_CONFIG _IOW(IOC_TYPE_FB, 0x29, struct aicfb_ck_config)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
使用例程
bash
static int set_ui_color_key(unsigned char r, unsigned char g, unsigned char b)
{
struct aicfb_ck_config ck = {0};
int ret = 0;
unsigned int val;
val = (r << 16) | (g << 8) | (b << 0);
ck.layer_id = AICFB_LAYER_TYPE_UI;
ck.enable = 1;
ck.value = val;
ret = mpp_fb_ioctl(g_fb_fd, AICFB_UPDATE_CK_CONFIG, &ck);
if (ret < 0)
printf("ioctl() failed! errno: %d[%s]\n", errno, strerror(errno));
return ret;
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
注解
Video 图层不支持配置 Color Key
Color Key 操作在 UI 图层和 Video 图层的重叠区域进行
RGB565 Color Key
缺失的 bit 需要 循环移位 补齐,比如 G 只有 6 bit,缺失的低 2 bit 用高位来补齐:
bash
0b101111 > 0b10111110
0b10111 > 0b10111101
1
2
2