mirror of
https://github.com/lvgl/lvgl.git
synced 2025-01-21 06:53:01 +08:00
draw: line mask support all directions
This commit is contained in:
parent
607bd3e31b
commit
0aa19da0c7
@ -98,10 +98,10 @@ static void draw_bg(const lv_area_t * coords, const lv_area_t * clip, const lv_s
|
||||
lv_color_t line_buf[LV_HOR_RES_MAX];
|
||||
lv_opa_t mask_buf[LV_HOR_RES_MAX];
|
||||
lv_mask_line_param_t line_mask_param;
|
||||
line_mask_param.origo.x = 100;
|
||||
line_mask_param.origo.y = 0;
|
||||
line_mask_param.origo.x = 150;
|
||||
line_mask_param.origo.y = 100;
|
||||
line_mask_param.steep = -300;
|
||||
line_mask_param.flat = 0;
|
||||
line_mask_param.flat = 1;
|
||||
|
||||
|
||||
/*Fill with a color line-by-line*/
|
||||
|
@ -51,35 +51,55 @@ void lv_mask_line_left(lv_opa_t * mask_buf, lv_coord_t abs_x, lv_coord_t abs_y,
|
||||
|
||||
if(p->flat) {
|
||||
lv_coord_t y_at_x;
|
||||
|
||||
/* At the beginning of the mask if the limit line is greater then the mask's y.
|
||||
* Then the mask is in the "wrong" area*/
|
||||
y_at_x = (int32_t)((int32_t)p->steep * abs_x) >> 10;
|
||||
if(y_at_x > abs_y) {
|
||||
memset(mask_buf, 0x00, len);
|
||||
return;
|
||||
|
||||
if(p->steep > 0) {
|
||||
if(y_at_x > abs_y) {
|
||||
memset(mask_buf, 0x00, len);
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
if(y_at_x < abs_y) {
|
||||
memset(mask_buf, 0x00, len);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/* At the end of the mask if the limit line is smaller then the mask's y.
|
||||
* Then the mask is in the "good" area*/
|
||||
y_at_x = (int32_t)((int32_t)p->steep * (abs_x + len)) >> 10;
|
||||
if(y_at_x < abs_y) {
|
||||
return;
|
||||
if(p->steep > 0) {
|
||||
if(y_at_x < abs_y) {
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
if(y_at_x > abs_y) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
int32_t xe = ((abs_y << 18) / p->steep);
|
||||
int32_t xe;
|
||||
if(p->steep > 0) xe = ((abs_y << 18) / p->steep);
|
||||
else xe = (((abs_y + 1) << 18) / p->steep);
|
||||
|
||||
int32_t xei = xe >> 8;
|
||||
int32_t xef = xe & 0xFF;
|
||||
|
||||
int32_t sps = p->steep >> 2;
|
||||
int32_t px_h;
|
||||
if(p->steep < 0) sps = -sps;
|
||||
|
||||
int32_t px_h;
|
||||
if(xef == 0) px_h = 255;
|
||||
else px_h = 255 - (((255 - xef) * sps) >> 8);
|
||||
|
||||
int32_t k = xei - abs_x;
|
||||
|
||||
if(xef) {
|
||||
k++;
|
||||
if(p->steep > 0) k++;
|
||||
if(k >= 0) mask_buf[k] = 255 - (((255-xef) * (255 - px_h)) >> 8);
|
||||
if(p->steep < 0) k++;
|
||||
}
|
||||
|
||||
while(px_h > sps) {
|
||||
@ -126,29 +146,74 @@ void lv_mask_line_left(lv_opa_t * mask_buf, lv_coord_t abs_x, lv_coord_t abs_y,
|
||||
|
||||
int32_t k = xei - abs_x;
|
||||
|
||||
|
||||
if(xei != xqi && (p->steep < 0 && xef == 0)) {
|
||||
xef = 0xFF;
|
||||
xei = xqi;
|
||||
k--;
|
||||
}
|
||||
|
||||
if(xei == xqi) {
|
||||
|
||||
if(k >= 0 && k < len) {
|
||||
mask_buf[k] = (xef + xqf) >> 1;
|
||||
k++;
|
||||
}
|
||||
} else {;
|
||||
int32_t y_inters = ((255-xef) << 10) / p->steep;
|
||||
k++;
|
||||
|
||||
if(k >= 0 && k < len ) {
|
||||
memset(&mask_buf[k] ,0x00, len - (k));
|
||||
}
|
||||
|
||||
} else {
|
||||
int32_t y_inters;
|
||||
if(p->steep < 0) {
|
||||
y_inters = (xef << 10) / (-p->steep);
|
||||
if(k >= 0 && k < len ) {
|
||||
mask_buf[k] = (y_inters * xef) >> 8;
|
||||
}
|
||||
k--;
|
||||
|
||||
int32_t x_inters = ((255-y_inters) * (-p->steep)) >> 10;
|
||||
|
||||
if(k >= 0 && k < len ) {
|
||||
mask_buf[k] = 255-(((255-y_inters) * x_inters) >> 9);
|
||||
}
|
||||
|
||||
k+=2;
|
||||
|
||||
|
||||
if(k >= 0 && k < len ) {
|
||||
memset(&mask_buf[k] ,0x00, len - (k));
|
||||
}
|
||||
|
||||
} else {
|
||||
y_inters = ((255-xef) << 10) / p->steep;
|
||||
if(k >= 0 && k < len ) {
|
||||
mask_buf[k] = 255 - ((y_inters * (255-xef)) >> 8);
|
||||
}
|
||||
|
||||
k++;
|
||||
|
||||
int32_t x_inters = ((255-y_inters) * p->steep) >> 10;
|
||||
printf("x_inters: %d\n", x_inters * 100 / 255);
|
||||
|
||||
|
||||
if(k >= 0 && k < len ) {
|
||||
mask_buf[k] = ((255-y_inters) * x_inters) >> 9;
|
||||
}
|
||||
k++;
|
||||
|
||||
if(k >= 0 && k < len )
|
||||
{
|
||||
memset(&mask_buf[k] ,0x00, len - (k));
|
||||
}
|
||||
}
|
||||
printf("y: %d, xef: %d, y_inters: %d, %d\n", abs_y, xef, y_inters * 100 / 255);
|
||||
mask_buf[k] = 255 - ((y_inters * (255-xef)) >> 8);
|
||||
k++;
|
||||
|
||||
int32_t x_inters = ((255-y_inters) * p->steep) >> 10;
|
||||
printf("x_inters: %d\n", x_inters * 100 / 255);
|
||||
|
||||
mask_buf[k] = ((255-y_inters) * x_inters) >> 8;
|
||||
k++;
|
||||
|
||||
}
|
||||
|
||||
if(k >= 0 && k < len )
|
||||
{
|
||||
memset(&mask_buf[k] ,0x00, len - (k));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user