Description
Base on Lvgl6.0,test transparent background function.
What MCU/Processor/Board and compiler are you using?
I use xilinx zynq platfrom,custorm board. ARM cortex-A9.
What do you want to achieve?
I would like to draw some object above on live video from camera.
What have you tried so far?
setting “lv_style_scr.body.opa= LV_OPA_TRANSP” in lv_style.c.
setting “lv_style_scr.body.opa= LV_OPA_COVER” in lv_style.c.
resolution is 1024 x 768
When use LV_OPA_TRANSP param, the circle was not drew successfully.
So,is this a bug? Draws an arc can not use body.opa= LV_OPA_TRANSP function.
Code to reproduce
//#define DDR
#ifdef DDR
#define DISP_BUF_SIZE 1024*768
#else
#define DISP_BUF_SIZE (80*LV_HOR_RES_MAX)
#endif
static char *fbp1 = 0;
static char *fbp2 = 0;
bool first;
lv_obj_t * scr;
lv_obj_t * label1;
lv_obj_t * line_obj;
void Memalloc(void) {
int fd;
unsigned long phyaddr = 0x32000000;
if((fd = open("/dev/mem", O_RDWR | O_SYNC)) == -1)
printf("/dev/mem faild opene.\n");
fbp1 = mmap((void *)phyaddr, 1024*768*4, PROT_READ | PROT_WRITE, MAP_SHARED, fd, phyaddr);
if(fbp1 == NULL)
printf("mmap faild\n");
else
printf("Memory mapped at address %p.\n", fbp1);
phyaddr = 0x32300000;
fbp2 = mmap((void *)phyaddr, 1024*768*4, PROT_READ | PROT_WRITE, MAP_SHARED, fd, phyaddr);
if(fbp1 == NULL)
printf("mmap faild\n");
else
printf("Memory mapped at address %p.\n", fbp2);
memset(fbp1,0x00,1024*768*4);
memset(fbp2,0x00,1024*768*4);
}
void fbdev_flush_user(lv_disp_drv_t * drv, const lv_area_t * area, lv_color_t * color_p)
{
#ifndef DDR
if(fbp1 == NULL ||
area->x2 < 0 ||
area->y2 < 0 ||
area->x1 > (int32_t)1024 - 1 ||
area->y1 > (int32_t)768 - 1) {
lv_disp_flush_ready(drv);
return;
}
int32_t act_x1 = area->x1 < 0 ? 0 : area->x1;
int32_t act_y1 = area->y1 < 0 ? 0 : area->y1;
int32_t act_x2 = area->x2 > 1024 - 1 ? 1024 - 1 : area->x2;
int32_t act_y2 = area->y2 > 768 - 1 ? 768 - 1 : area->y2;
lv_coord_t w = lv_area_get_width(area);
long int location = 0;
uint32_t * fbp32 = (uint32_t *)fbp1;
uint32_t * fbp32_i = (uint32_t *)fbp2;
int32_t y;
for(y = act_y1; y <= act_y2; y++) {
location = (act_x1) + (y) * 1024;
memcpy(&fbp32[location], (uint32_t *)color_p, (act_x2 - act_x1 + 1) * 4);
memcpy(&fbp32_i[location], (uint32_t *)color_p, (act_x2 - act_x1 + 1) * 4);
color_p += w;
}
#endif
lv_disp_flush_ready(drv);
}
void lv_tutorial_hello_world(lv_task_t * task)
{
if(first) {
scr = lv_disp_get_scr_act(NULL); /*Get the current screen*/
/*Create a Label on the currently active screen*/
label1 = lv_label_create(scr, NULL);
/*Modify the Label's text*/
lv_label_set_text(label1, "Hello world!");
/* Align the Label to the center
* NULL means align on parent (which is the screen now)
* 0, 0 at the end means an x, y offset after alignment*/
lv_obj_align(label1, NULL, LV_ALIGN_IN_TOP_LEFT, 0, 0);
first = false;
}
lv_coord_t x = lv_obj_get_x(label1);
lv_coord_t y = lv_obj_get_x(label1);
if(x < 1023)
x++;
else
x = 0;
if(y < 767)
y++;
else
y = 0;
lv_obj_set_pos(label1,x,y);
}
void lv_ex_arc_1(lv_task_t * task_arc)
{
/*Create style for the Arcs*/
static lv_style_t style;
lv_style_copy(&style, &lv_style_plain);
style.line.color = LV_COLOR_RED; /*Arc color*/
style.line.width = 2; /*Arc width*/
style.line.rounded = 0;
/*Create an Arc*/
scr = lv_disp_get_scr_act(NULL);
lv_obj_t * arc = lv_arc_create(src, NULL);
lv_arc_set_style(arc, LV_ARC_STYLE_MAIN, &style); /*Use the new style*/
lv_arc_set_angles(arc, 0, 360);
lv_obj_set_size(arc,150, 150);
lv_obj_align(arc, NULL, LV_ALIGN_CENTER, 0, 0);
}
void lv_tutorial_line(lv_task_t * task_line)
{
/*Create an array for the points of the line*/
static lv_point_t line_points[] = { {5, 5}, {70, 70}, {120, 10}, {180, 60}};
/*Create new style (thick dark blue)*/
static lv_style_t style_line;
lv_style_copy(&style_line, &lv_style_plain);
style_line.line.color = LV_COLOR_MAKE(0x00, 0x3b, 0x75);
style_line.line.width = 3;
style_line.line.rounded = 0;
/*Copy the previous line and apply the new style*/
lv_obj_t * line1;
line1 = lv_line_create(lv_scr_act(), NULL);
lv_line_set_points(line1, line_points, 5); /*Set the points*/
lv_line_set_style(line1, LV_LINE_STYLE_MAIN, &style_line);
lv_obj_align(line1, NULL, LV_ALIGN_CENTER, 0, 0);
}
void* tick_thread(void * data)
{
(void)data;
while(1) {
usleep(17000);
lv_tick_inc(17); /*Tell LittelvGL that 5 milliseconds were elapsed*/
}
return 0;
}
int main(void) {
pthread_t pth_tick;
pthread_create(&pth_tick, NULL, tick_thread, NULL);
pthread_detach(pth_tick);
first = true;
Memalloc();
/*LittlevGL init*/
lv_init();
static lv_disp_buf_t disp_buf;
#ifndef DDR
static lv_color_t buf[DISP_BUF_SIZE];
lv_disp_buf_init(&disp_buf, buf, NULL,DISP_BUF_SIZE);
#else
lv_disp_buf_init(&disp_buf, fbp1, fbp2,DISP_BUF_SIZE);
#endif
lv_disp_drv_t disp_drv;
lv_disp_drv_init(&disp_drv);
disp_drv.buffer = &disp_buf;
disp_drv.flush_cb = fbdev_flush_user;
lv_disp_drv_register(&disp_drv);
static uint32_t user_data = 10;
//lv_task_t * task = lv_task_create(lv_tutorial_hello_world,
// 17, LV_TASK_PRIO_MID, &user_data);
lv_task_t * task_line = lv_task_create(lv_tutorial_line,
15, LV_TASK_PRIO_MID, &user_data);
lv_task_t * task_arc = lv_task_create(lv_ex_arc_1,
17, LV_TASK_PRIO_MID, &user_data);
while(1) {
lv_task_handler();
usleep(17000);
}
return 0;
}