mirror of
https://github.com/lvgl/lvgl.git
synced 2025-01-14 06:42:58 +08:00
lv_draw: make anti aliasing function public
This commit is contained in:
parent
e4a12b22b4
commit
c092fb3303
@ -78,7 +78,15 @@ static void (*map_fp)(const lv_area_t * cords_p, const lv_area_t * mask_p,
|
|||||||
**********************/
|
**********************/
|
||||||
|
|
||||||
#if LV_ANTIALIAS != 0
|
#if LV_ANTIALIAS != 0
|
||||||
lv_opa_t antialias_get_opa(lv_coord_t seg, lv_coord_t px_id, lv_opa_t line_opa)
|
|
||||||
|
/**
|
||||||
|
* Get the opacity of a pixel based it's position in a line segment
|
||||||
|
* @param seg segment length
|
||||||
|
* @param px_id position of of a pixel which opacity should be get [0..seg-1]
|
||||||
|
* @param base_opa the base opacity
|
||||||
|
* @return the opacity of the given pixel
|
||||||
|
*/
|
||||||
|
lv_opa_t lv_draw_aa_get_opa(lv_coord_t seg, lv_coord_t px_id, lv_opa_t base_opa)
|
||||||
{
|
{
|
||||||
/* How to calculate the opacity of pixels on the edges which makes the anti-aliasing?
|
/* How to calculate the opacity of pixels on the edges which makes the anti-aliasing?
|
||||||
* For example we have a line like this (y = -0.5 * x):
|
* For example we have a line like this (y = -0.5 * x):
|
||||||
@ -111,11 +119,61 @@ static void (*map_fp)(const lv_area_t * cords_p, const lv_area_t * mask_p,
|
|||||||
seg5, seg6, seg7, seg8};
|
seg5, seg6, seg7, seg8};
|
||||||
|
|
||||||
if(seg == 0) return LV_OPA_TRANSP;
|
if(seg == 0) return LV_OPA_TRANSP;
|
||||||
else if(seg < 8) return (uint32_t)((uint32_t)seg_map[seg - 1][px_id] * line_opa) >> 8;
|
else if(seg < 8) return (uint32_t)((uint32_t)seg_map[seg - 1][px_id] * base_opa) >> 8;
|
||||||
else {
|
else {
|
||||||
return ((px_id * 2 + 1) * line_opa) / (2 * seg);
|
return ((px_id * 2 + 1) * base_opa) / (2 * seg);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add a vertical anti-aliasing segment (pixels with decreasing opacity)
|
||||||
|
* @param x start point x coordinate
|
||||||
|
* @param y start point y coordinate
|
||||||
|
* @param length length of segment (negative value to start from 0 opacity)
|
||||||
|
* @param mask draw only in this area
|
||||||
|
* @param color color of pixels
|
||||||
|
* @param opa maximum opacity
|
||||||
|
*/
|
||||||
|
void lv_draw_aa_ver_seg(lv_coord_t x, lv_coord_t y, lv_coord_t length, const lv_area_t * mask, lv_color_t color, lv_opa_t opa)
|
||||||
|
{
|
||||||
|
bool aa_inv = false;
|
||||||
|
if(length < 0) {
|
||||||
|
aa_inv = true;
|
||||||
|
length = -length;
|
||||||
|
}
|
||||||
|
|
||||||
|
lv_coord_t i;
|
||||||
|
for(i = 0; i < length; i++) {
|
||||||
|
lv_opa_t px_opa = lv_draw_aa_get_opa(length, i, opa);
|
||||||
|
if(aa_inv) px_opa = opa - px_opa;
|
||||||
|
px_fp(x, y + i, mask, color, px_opa);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add a horizontal anti-aliasing segment (pixels with decreasing opacity)
|
||||||
|
* @param x start point x coordinate
|
||||||
|
* @param y start point y coordinate
|
||||||
|
* @param length length of segment (negative value to start from 0 opacity)
|
||||||
|
* @param mask draw only in this area
|
||||||
|
* @param color color of pixels
|
||||||
|
* @param opa maximum opacity
|
||||||
|
*/
|
||||||
|
void lv_draw_aa_hor_seg(lv_coord_t x, lv_coord_t y, lv_coord_t length, const lv_area_t * mask, lv_color_t color, lv_opa_t opa)
|
||||||
|
{
|
||||||
|
bool aa_inv = false;
|
||||||
|
if(length < 0) {
|
||||||
|
aa_inv = true;
|
||||||
|
length = -length;
|
||||||
|
}
|
||||||
|
|
||||||
|
lv_coord_t i;
|
||||||
|
for(i = 0; i < length; i++) {
|
||||||
|
lv_opa_t px_opa = lv_draw_aa_get_opa(length, i, opa);
|
||||||
|
if(aa_inv) px_opa = opa - px_opa;
|
||||||
|
px_fp(x + i, y, mask, color, px_opa);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -75,7 +75,37 @@ typedef enum {
|
|||||||
**********************/
|
**********************/
|
||||||
|
|
||||||
#if LV_ANTIALIAS != 0
|
#if LV_ANTIALIAS != 0
|
||||||
lv_opa_t antialias_get_opa(lv_coord_t seg, lv_coord_t px_id, lv_opa_t line_opa);
|
|
||||||
|
/**
|
||||||
|
* Get the opacity of a pixel based it's position in a line segment
|
||||||
|
* @param seg segment length
|
||||||
|
* @param px_id position of of a pixel which opacity should be get [0..seg-1]
|
||||||
|
* @param base_opa the base opacity
|
||||||
|
* @return the opacity of the given pixel
|
||||||
|
*/
|
||||||
|
lv_opa_t lv_draw_aa_get_opa(lv_coord_t seg, lv_coord_t px_id, lv_opa_t base_opa);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add a vertical anti-aliasing segment (pixels with decreasing opacity)
|
||||||
|
* @param x start point x coordinate
|
||||||
|
* @param y start point y coordinate
|
||||||
|
* @param length length of segment (negative value to start from 0 opacity)
|
||||||
|
* @param mask draw only in this area
|
||||||
|
* @param color color of pixels
|
||||||
|
* @param opa maximum opacity
|
||||||
|
*/
|
||||||
|
void lv_draw_aa_ver_seg(lv_coord_t x, lv_coord_t y, lv_coord_t length, const lv_area_t * mask, lv_color_t color, lv_opa_t opa);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add a horizontal anti-aliasing segment (pixels with decreasing opacity)
|
||||||
|
* @param x start point x coordinate
|
||||||
|
* @param y start point y coordinate
|
||||||
|
* @param length length of segment (negative value to start from 0 opacity)
|
||||||
|
* @param mask draw only in this area
|
||||||
|
* @param color color of pixels
|
||||||
|
* @param opa maximum opacity
|
||||||
|
*/
|
||||||
|
void lv_draw_aa_hor_seg(lv_coord_t x, lv_coord_t y, lv_coord_t length, const lv_area_t * mask, lv_color_t color, lv_opa_t opa);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/**********************
|
/**********************
|
||||||
|
@ -76,6 +76,8 @@ void lv_draw_arc(lv_coord_t center_x, lv_coord_t center_y, uint16_t radius, cons
|
|||||||
if (deg_test(180, start_angle, end_angle)) ver_line(center_x, center_y - r_out + 1, mask, thickness - 1, color, opa); // Top Middle
|
if (deg_test(180, start_angle, end_angle)) ver_line(center_x, center_y - r_out + 1, mask, thickness - 1, color, opa); // Top Middle
|
||||||
if (deg_test(0, start_angle, end_angle)) ver_line(center_x, center_y + r_in, mask, thickness - 1, color, opa); // Bottom middle
|
if (deg_test(0, start_angle, end_angle)) ver_line(center_x, center_y + r_in, mask, thickness - 1, color, opa); // Bottom middle
|
||||||
|
|
||||||
|
|
||||||
|
lv_point_t last_corner_out = {-r_out, -r_out};
|
||||||
uint32_t r_out_sqr = r_out * r_out;
|
uint32_t r_out_sqr = r_out * r_out;
|
||||||
uint32_t r_in_sqr = r_in * r_in;
|
uint32_t r_in_sqr = r_in * r_in;
|
||||||
int16_t xi;
|
int16_t xi;
|
||||||
@ -148,6 +150,12 @@ void lv_draw_arc(lv_coord_t center_x, lv_coord_t center_y, uint16_t radius, cons
|
|||||||
hor_line(center_x-x_end[3], center_y-yi, mask, LV_MATH_ABS(x_end[3] - x_start[3]), color, opa);
|
hor_line(center_x-x_end[3], center_y-yi, mask, LV_MATH_ABS(x_end[3] - x_start[3]), color, opa);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#if LV_ANTIALIAS
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -52,8 +52,6 @@ static void line_init(line_draw_t * line, const lv_point_t * p1, const lv_point_
|
|||||||
static bool line_next(line_draw_t * line);
|
static bool line_next(line_draw_t * line);
|
||||||
static bool line_next_y(line_draw_t * line);
|
static bool line_next_y(line_draw_t * line);
|
||||||
static bool line_next_x(line_draw_t * line);
|
static bool line_next_x(line_draw_t * line);
|
||||||
static void line_ver_aa(lv_coord_t x, lv_coord_t y, lv_coord_t length, const lv_area_t * mask, lv_color_t color, lv_opa_t opa);
|
|
||||||
static void line_hor_aa(lv_coord_t x, lv_coord_t y, lv_coord_t length, const lv_area_t * mask, lv_color_t color, lv_opa_t opa);
|
|
||||||
|
|
||||||
/**********************
|
/**********************
|
||||||
* STATIC VARIABLES
|
* STATIC VARIABLES
|
||||||
@ -258,16 +256,16 @@ static void line_draw_skew(line_draw_t * main_line, const lv_area_t * mask, cons
|
|||||||
if(pattern[i - 1].x != pattern[i].x) {
|
if(pattern[i - 1].x != pattern[i].x) {
|
||||||
lv_coord_t seg_w = pattern[i].y - pattern[aa_last_corner].y;
|
lv_coord_t seg_w = pattern[i].y - pattern[aa_last_corner].y;
|
||||||
if(main_line->sy < 0) {
|
if(main_line->sy < 0) {
|
||||||
line_ver_aa(main_line->p1.x + pattern[aa_last_corner].x - 1, main_line->p1.y + pattern[aa_last_corner].y + seg_w + 1,
|
lv_draw_aa_ver_seg(main_line->p1.x + pattern[aa_last_corner].x - 1, main_line->p1.y + pattern[aa_last_corner].y + seg_w + 1,
|
||||||
seg_w, mask, style->line.color, LV_OPA_50);
|
seg_w, mask, style->line.color, LV_OPA_50);
|
||||||
|
|
||||||
line_ver_aa(main_line->p2.x + pattern[aa_last_corner].x + 1, main_line->p2.y + pattern[aa_last_corner].y + seg_w + 1,
|
lv_draw_aa_ver_seg(main_line->p2.x + pattern[aa_last_corner].x + 1, main_line->p2.y + pattern[aa_last_corner].y + seg_w + 1,
|
||||||
-seg_w, mask, style->line.color, LV_OPA_50);
|
-seg_w, mask, style->line.color, LV_OPA_50);
|
||||||
} else {
|
} else {
|
||||||
line_ver_aa(main_line->p1.x + pattern[aa_last_corner].x - 1, main_line->p1.y + pattern[aa_last_corner].y,
|
lv_draw_aa_ver_seg(main_line->p1.x + pattern[aa_last_corner].x - 1, main_line->p1.y + pattern[aa_last_corner].y,
|
||||||
seg_w, mask, style->line.color, LV_OPA_50);
|
seg_w, mask, style->line.color, LV_OPA_50);
|
||||||
|
|
||||||
line_ver_aa(main_line->p2.x + pattern[aa_last_corner].x + 1, main_line->p2.y + pattern[aa_last_corner].y,
|
lv_draw_aa_ver_seg(main_line->p2.x + pattern[aa_last_corner].x + 1, main_line->p2.y + pattern[aa_last_corner].y,
|
||||||
-seg_w, mask, style->line.color, LV_OPA_50);
|
-seg_w, mask, style->line.color, LV_OPA_50);
|
||||||
}
|
}
|
||||||
aa_last_corner = i;
|
aa_last_corner = i;
|
||||||
@ -276,16 +274,16 @@ static void line_draw_skew(line_draw_t * main_line, const lv_area_t * mask, cons
|
|||||||
if(pattern[i - 1].y != pattern[i].y) {
|
if(pattern[i - 1].y != pattern[i].y) {
|
||||||
lv_coord_t seg_w = pattern[i].x - pattern[aa_last_corner].x;
|
lv_coord_t seg_w = pattern[i].x - pattern[aa_last_corner].x;
|
||||||
if(main_line->sx < 0) {
|
if(main_line->sx < 0) {
|
||||||
line_hor_aa(main_line->p1.x + pattern[aa_last_corner].x + seg_w + 1, main_line->p1.y + pattern[aa_last_corner].y - 1,
|
lv_draw_aa_hor_seg(main_line->p1.x + pattern[aa_last_corner].x + seg_w + 1, main_line->p1.y + pattern[aa_last_corner].y - 1,
|
||||||
seg_w, mask, style->line.color, LV_OPA_50);
|
seg_w, mask, style->line.color, LV_OPA_50);
|
||||||
|
|
||||||
line_hor_aa(main_line->p2.x + pattern[aa_last_corner].x + seg_w + 1, main_line->p2.y + pattern[aa_last_corner].y + 1,
|
lv_draw_aa_hor_seg(main_line->p2.x + pattern[aa_last_corner].x + seg_w + 1, main_line->p2.y + pattern[aa_last_corner].y + 1,
|
||||||
-seg_w, mask, style->line.color, LV_OPA_50);
|
-seg_w, mask, style->line.color, LV_OPA_50);
|
||||||
} else {
|
} else {
|
||||||
line_hor_aa(main_line->p1.x + pattern[aa_last_corner].x, main_line->p1.y + pattern[aa_last_corner].y - 1,
|
lv_draw_aa_hor_seg(main_line->p1.x + pattern[aa_last_corner].x, main_line->p1.y + pattern[aa_last_corner].y - 1,
|
||||||
seg_w, mask, style->line.color, LV_OPA_50);
|
seg_w, mask, style->line.color, LV_OPA_50);
|
||||||
|
|
||||||
line_hor_aa(main_line->p2.x + pattern[aa_last_corner].x, main_line->p2.y + pattern[aa_last_corner].y + 1,
|
lv_draw_aa_hor_seg(main_line->p2.x + pattern[aa_last_corner].x, main_line->p2.y + pattern[aa_last_corner].y + 1,
|
||||||
-seg_w, mask, style->line.color, LV_OPA_50);
|
-seg_w, mask, style->line.color, LV_OPA_50);
|
||||||
}
|
}
|
||||||
aa_last_corner = i;
|
aa_last_corner = i;
|
||||||
@ -303,33 +301,33 @@ static void line_draw_skew(line_draw_t * main_line, const lv_area_t * mask, cons
|
|||||||
if(main_line->hor) {
|
if(main_line->hor) {
|
||||||
lv_coord_t seg_w = pattern[width_safe - 1].y - pattern[aa_last_corner].y;
|
lv_coord_t seg_w = pattern[width_safe - 1].y - pattern[aa_last_corner].y;
|
||||||
if(main_line->sy < 0) {
|
if(main_line->sy < 0) {
|
||||||
line_ver_aa(main_line->p1.x + pattern[aa_last_corner].x - 1, main_line->p1.y + pattern[aa_last_corner].y + seg_w,
|
lv_draw_aa_ver_seg(main_line->p1.x + pattern[aa_last_corner].x - 1, main_line->p1.y + pattern[aa_last_corner].y + seg_w,
|
||||||
seg_w + main_line->sy, mask, style->line.color, LV_OPA_50);
|
seg_w + main_line->sy, mask, style->line.color, LV_OPA_50);
|
||||||
|
|
||||||
line_ver_aa(main_line->p2.x + pattern[aa_last_corner].x + 1, main_line->p2.y + pattern[aa_last_corner].y + seg_w,
|
lv_draw_aa_ver_seg(main_line->p2.x + pattern[aa_last_corner].x + 1, main_line->p2.y + pattern[aa_last_corner].y + seg_w,
|
||||||
-(seg_w + main_line->sy), mask, style->line.color, LV_OPA_50);
|
-(seg_w + main_line->sy), mask, style->line.color, LV_OPA_50);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
line_ver_aa(main_line->p1.x + pattern[aa_last_corner].x - 1, main_line->p1.y + pattern[aa_last_corner].y,
|
lv_draw_aa_ver_seg(main_line->p1.x + pattern[aa_last_corner].x - 1, main_line->p1.y + pattern[aa_last_corner].y,
|
||||||
seg_w + main_line->sy, mask, style->line.color, LV_OPA_50);
|
seg_w + main_line->sy, mask, style->line.color, LV_OPA_50);
|
||||||
|
|
||||||
line_ver_aa(main_line->p2.x + pattern[aa_last_corner].x + 1, main_line->p2.y + pattern[aa_last_corner].y,
|
lv_draw_aa_ver_seg(main_line->p2.x + pattern[aa_last_corner].x + 1, main_line->p2.y + pattern[aa_last_corner].y,
|
||||||
-(seg_w + main_line->sy), mask, style->line.color, LV_OPA_50);
|
-(seg_w + main_line->sy), mask, style->line.color, LV_OPA_50);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
lv_coord_t seg_w = pattern[width_safe - 1].x - pattern[aa_last_corner].x;
|
lv_coord_t seg_w = pattern[width_safe - 1].x - pattern[aa_last_corner].x;
|
||||||
if(main_line->sx < 0) {
|
if(main_line->sx < 0) {
|
||||||
line_hor_aa(main_line->p1.x + pattern[aa_last_corner].x + seg_w, main_line->p1.y + pattern[aa_last_corner].y - 1,
|
lv_draw_aa_hor_seg(main_line->p1.x + pattern[aa_last_corner].x + seg_w, main_line->p1.y + pattern[aa_last_corner].y - 1,
|
||||||
seg_w + main_line->sx, mask, style->line.color, LV_OPA_50);
|
seg_w + main_line->sx, mask, style->line.color, LV_OPA_50);
|
||||||
|
|
||||||
line_hor_aa(main_line->p2.x + pattern[aa_last_corner].x + seg_w, main_line->p2.y + pattern[aa_last_corner].y + 1,
|
lv_draw_aa_hor_seg(main_line->p2.x + pattern[aa_last_corner].x + seg_w, main_line->p2.y + pattern[aa_last_corner].y + 1,
|
||||||
-(seg_w + main_line->sx), mask, style->line.color, LV_OPA_50);
|
-(seg_w + main_line->sx), mask, style->line.color, LV_OPA_50);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
line_hor_aa(main_line->p1.x + pattern[aa_last_corner].x, main_line->p1.y + pattern[aa_last_corner].y - 1,
|
lv_draw_aa_hor_seg(main_line->p1.x + pattern[aa_last_corner].x, main_line->p1.y + pattern[aa_last_corner].y - 1,
|
||||||
seg_w + main_line->sx, mask, style->line.color, LV_OPA_50);
|
seg_w + main_line->sx, mask, style->line.color, LV_OPA_50);
|
||||||
|
|
||||||
line_hor_aa(main_line->p2.x + pattern[aa_last_corner].x , main_line->p2.y + pattern[aa_last_corner].y + 1,
|
lv_draw_aa_hor_seg(main_line->p2.x + pattern[aa_last_corner].x , main_line->p2.y + pattern[aa_last_corner].y + 1,
|
||||||
-(seg_w + main_line->sx), mask, style->line.color, LV_OPA_50);
|
-(seg_w + main_line->sx), mask, style->line.color, LV_OPA_50);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -389,9 +387,9 @@ static void line_draw_skew(line_draw_t * main_line, const lv_area_t * mask, cons
|
|||||||
}
|
}
|
||||||
|
|
||||||
#if LV_ANTIALIAS
|
#if LV_ANTIALIAS
|
||||||
line_hor_aa(prev_p.x + pattern[0].x, prev_p.y + pattern[0].y - aa_shift1,
|
lv_draw_aa_hor_seg(prev_p.x + pattern[0].x, prev_p.y + pattern[0].y - aa_shift1,
|
||||||
-(main_line->p_act.x - prev_p.x), mask, style->line.color, style->line.opa);
|
-(main_line->p_act.x - prev_p.x), mask, style->line.color, style->line.opa);
|
||||||
line_hor_aa(prev_p.x + pattern[width_safe - 1].x, prev_p.y + pattern[width_safe - 1].y + aa_shift2,
|
lv_draw_aa_hor_seg(prev_p.x + pattern[width_safe - 1].x, prev_p.y + pattern[width_safe - 1].y + aa_shift2,
|
||||||
main_line->p_act.x - prev_p.x, mask, style->line.color, style->line.opa);
|
main_line->p_act.x - prev_p.x, mask, style->line.color, style->line.opa);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -416,9 +414,9 @@ static void line_draw_skew(line_draw_t * main_line, const lv_area_t * mask, cons
|
|||||||
}
|
}
|
||||||
|
|
||||||
#if LV_ANTIALIAS
|
#if LV_ANTIALIAS
|
||||||
line_hor_aa(prev_p.x + pattern[0].x, prev_p.y + pattern[0].y - aa_shift1,
|
lv_draw_aa_hor_seg(prev_p.x + pattern[0].x, prev_p.y + pattern[0].y - aa_shift1,
|
||||||
-(main_line->p_act.x - prev_p.x + 1), mask, style->line.color, style->line.opa);
|
-(main_line->p_act.x - prev_p.x + 1), mask, style->line.color, style->line.opa);
|
||||||
line_hor_aa(prev_p.x + pattern[width_safe - 1].x, prev_p.y + pattern[width_safe - 1].y + aa_shift2,
|
lv_draw_aa_hor_seg(prev_p.x + pattern[width_safe - 1].x, prev_p.y + pattern[width_safe - 1].y + aa_shift2,
|
||||||
main_line->p_act.x - prev_p.x + 1, mask, style->line.color, style->line.opa);
|
main_line->p_act.x - prev_p.x + 1, mask, style->line.color, style->line.opa);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
@ -443,9 +441,9 @@ static void line_draw_skew(line_draw_t * main_line, const lv_area_t * mask, cons
|
|||||||
}
|
}
|
||||||
|
|
||||||
#if LV_ANTIALIAS
|
#if LV_ANTIALIAS
|
||||||
line_ver_aa(prev_p.x + pattern[0].x - aa_shift1, prev_p.y + pattern[0].y,
|
lv_draw_aa_ver_seg(prev_p.x + pattern[0].x - aa_shift1, prev_p.y + pattern[0].y,
|
||||||
-(main_line->p_act.y - prev_p.y), mask, style->line.color, style->line.opa);
|
-(main_line->p_act.y - prev_p.y), mask, style->line.color, style->line.opa);
|
||||||
line_ver_aa(prev_p.x + pattern[width_safe - 1].x + aa_shift2, prev_p.y + pattern[width_safe - 1].y,
|
lv_draw_aa_ver_seg(prev_p.x + pattern[width_safe - 1].x + aa_shift2, prev_p.y + pattern[width_safe - 1].y,
|
||||||
main_line->p_act.y - prev_p.y, mask, style->line.color, style->line.opa);
|
main_line->p_act.y - prev_p.y, mask, style->line.color, style->line.opa);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -472,9 +470,9 @@ static void line_draw_skew(line_draw_t * main_line, const lv_area_t * mask, cons
|
|||||||
}
|
}
|
||||||
|
|
||||||
#if LV_ANTIALIAS
|
#if LV_ANTIALIAS
|
||||||
line_ver_aa(prev_p.x + pattern[0].x - aa_shift1, prev_p.y + pattern[0].y,
|
lv_draw_aa_ver_seg(prev_p.x + pattern[0].x - aa_shift1, prev_p.y + pattern[0].y,
|
||||||
-(main_line->p_act.y - prev_p.y + 1), mask, style->line.color, style->line.opa);
|
-(main_line->p_act.y - prev_p.y + 1), mask, style->line.color, style->line.opa);
|
||||||
line_ver_aa(prev_p.x + pattern[width_safe - 1].x + aa_shift2, prev_p.y + pattern[width_safe - 1].y,
|
lv_draw_aa_ver_seg(prev_p.x + pattern[width_safe - 1].x + aa_shift2, prev_p.y + pattern[width_safe - 1].y,
|
||||||
main_line->p_act.y - prev_p.y + 1, mask, style->line.color, style->line.opa);
|
main_line->p_act.y - prev_p.y + 1, mask, style->line.color, style->line.opa);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
@ -549,52 +547,3 @@ static bool line_next_x(line_draw_t * line)
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Add a vertical anti-aliasing segment (pixels with decreasing opacity)
|
|
||||||
* @param x start point x coordinate
|
|
||||||
* @param y start point y coordinate
|
|
||||||
* @param length length of segment (negative value to start from 0 opacity)
|
|
||||||
* @param mask draw only in this area
|
|
||||||
* @param color color of pixels
|
|
||||||
* @param opa maximum opacity
|
|
||||||
*/
|
|
||||||
static void line_ver_aa(lv_coord_t x, lv_coord_t y, lv_coord_t length, const lv_area_t * mask, lv_color_t color, lv_opa_t opa)
|
|
||||||
{
|
|
||||||
bool aa_inv = false;
|
|
||||||
if(length < 0) {
|
|
||||||
aa_inv = true;
|
|
||||||
length = -length;
|
|
||||||
}
|
|
||||||
|
|
||||||
lv_coord_t i;
|
|
||||||
for(i = 0; i < length; i++) {
|
|
||||||
lv_opa_t px_opa = antialias_get_opa(length, i, opa);
|
|
||||||
if(aa_inv) px_opa = opa - px_opa;
|
|
||||||
px_fp(x, y + i, mask, color, px_opa);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Add a horizontal anti-aliasing segment (pixels with decreasing opacity)
|
|
||||||
* @param x start point x coordinate
|
|
||||||
* @param y start point y coordinate
|
|
||||||
* @param length length of segment (negative value to start from 0 opacity)
|
|
||||||
* @param mask draw only in this area
|
|
||||||
* @param color color of pixels
|
|
||||||
* @param opa maximum opacity
|
|
||||||
*/
|
|
||||||
static void line_hor_aa(lv_coord_t x, lv_coord_t y, lv_coord_t length, const lv_area_t * mask, lv_color_t color, lv_opa_t opa)
|
|
||||||
{
|
|
||||||
bool aa_inv = false;
|
|
||||||
if(length < 0) {
|
|
||||||
aa_inv = true;
|
|
||||||
length = -length;
|
|
||||||
}
|
|
||||||
|
|
||||||
lv_coord_t i;
|
|
||||||
for(i = 0; i < length; i++) {
|
|
||||||
lv_opa_t px_opa = antialias_get_opa(length, i, opa);
|
|
||||||
if(aa_inv) px_opa = opa - px_opa;
|
|
||||||
px_fp(x + i, y, mask, color, px_opa);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
@ -253,7 +253,7 @@ static void lv_draw_rect_main_corner(const lv_area_t * coords, const lv_area_t *
|
|||||||
if(seg_size > CIRCLE_AA_NON_LINEAR_OPA_THRESHOLD) { /*Use non-linear opa mapping on the first segment*/
|
if(seg_size > CIRCLE_AA_NON_LINEAR_OPA_THRESHOLD) { /*Use non-linear opa mapping on the first segment*/
|
||||||
aa_opa = antialias_get_opa_circ(seg_size, i, style->body.opa);
|
aa_opa = antialias_get_opa_circ(seg_size, i, style->body.opa);
|
||||||
} else {
|
} else {
|
||||||
aa_opa = opa - antialias_get_opa(seg_size, i, style->body.opa);
|
aa_opa = opa - lv_draw_aa_get_opa(seg_size, i, style->body.opa);
|
||||||
}
|
}
|
||||||
|
|
||||||
px_fp(rb_origo.x + LV_CIRC_OCT2_X(aa_p) + i, rb_origo.y + LV_CIRC_OCT2_Y(aa_p) + 1, mask, aa_color_hor_bottom, aa_opa);
|
px_fp(rb_origo.x + LV_CIRC_OCT2_X(aa_p) + i, rb_origo.y + LV_CIRC_OCT2_Y(aa_p) + 1, mask, aa_color_hor_bottom, aa_opa);
|
||||||
@ -413,7 +413,7 @@ static void lv_draw_rect_main_corner(const lv_area_t * coords, const lv_area_t *
|
|||||||
|
|
||||||
lv_coord_t i;
|
lv_coord_t i;
|
||||||
for(i = 0; i < seg_size; i++) {
|
for(i = 0; i < seg_size; i++) {
|
||||||
lv_opa_t aa_opa = opa - antialias_get_opa(seg_size, i, opa);
|
lv_opa_t aa_opa = opa - lv_draw_aa_get_opa(seg_size, i, opa);
|
||||||
px_fp(rb_origo.x + LV_CIRC_OCT2_X(aa_p) + i, rb_origo.y + LV_CIRC_OCT2_Y(aa_p) + 1, mask, aa_color_hor_top, aa_opa);
|
px_fp(rb_origo.x + LV_CIRC_OCT2_X(aa_p) + i, rb_origo.y + LV_CIRC_OCT2_Y(aa_p) + 1, mask, aa_color_hor_top, aa_opa);
|
||||||
px_fp(lb_origo.x + LV_CIRC_OCT3_X(aa_p) - i, lb_origo.y + LV_CIRC_OCT3_Y(aa_p) + 1, mask, aa_color_hor_top, aa_opa);
|
px_fp(lb_origo.x + LV_CIRC_OCT3_X(aa_p) - i, lb_origo.y + LV_CIRC_OCT3_Y(aa_p) + 1, mask, aa_color_hor_top, aa_opa);
|
||||||
px_fp(lt_origo.x + LV_CIRC_OCT6_X(aa_p) - i, lt_origo.y + LV_CIRC_OCT6_Y(aa_p) - 1, mask, aa_color_hor_bottom, aa_opa);
|
px_fp(lt_origo.x + LV_CIRC_OCT6_X(aa_p) - i, lt_origo.y + LV_CIRC_OCT6_Y(aa_p) - 1, mask, aa_color_hor_bottom, aa_opa);
|
||||||
@ -745,7 +745,7 @@ static void lv_draw_rect_border_corner(const lv_area_t * coords, const lv_area_t
|
|||||||
if(seg_size > CIRCLE_AA_NON_LINEAR_OPA_THRESHOLD) { /*Use non-linear opa mapping on the first segment*/
|
if(seg_size > CIRCLE_AA_NON_LINEAR_OPA_THRESHOLD) { /*Use non-linear opa mapping on the first segment*/
|
||||||
aa_opa = antialias_get_opa_circ(seg_size, i, style->body.border.opa);
|
aa_opa = antialias_get_opa_circ(seg_size, i, style->body.border.opa);
|
||||||
} else {
|
} else {
|
||||||
aa_opa = style->body.border.opa - antialias_get_opa(seg_size, i, style->body.border.opa);
|
aa_opa = style->body.border.opa - lv_draw_aa_get_opa(seg_size, i, style->body.border.opa);
|
||||||
}
|
}
|
||||||
|
|
||||||
if((part & LV_BORDER_BOTTOM) && (part & LV_BORDER_RIGHT)) {
|
if((part & LV_BORDER_BOTTOM) && (part & LV_BORDER_RIGHT)) {
|
||||||
@ -790,7 +790,7 @@ static void lv_draw_rect_border_corner(const lv_area_t * coords, const lv_area_t
|
|||||||
if(seg_size > CIRCLE_AA_NON_LINEAR_OPA_THRESHOLD) { /*Use non-linear opa mapping on the first segment*/
|
if(seg_size > CIRCLE_AA_NON_LINEAR_OPA_THRESHOLD) { /*Use non-linear opa mapping on the first segment*/
|
||||||
aa_opa = style->body.border.opa - antialias_get_opa_circ(seg_size, i, style->body.border.opa);
|
aa_opa = style->body.border.opa - antialias_get_opa_circ(seg_size, i, style->body.border.opa);
|
||||||
} else {
|
} else {
|
||||||
aa_opa = antialias_get_opa(seg_size, i, style->body.border.opa);
|
aa_opa = lv_draw_aa_get_opa(seg_size, i, style->body.border.opa);
|
||||||
}
|
}
|
||||||
|
|
||||||
if((part & LV_BORDER_BOTTOM) && (part & LV_BORDER_RIGHT)) {
|
if((part & LV_BORDER_BOTTOM) && (part & LV_BORDER_RIGHT)) {
|
||||||
@ -925,7 +925,7 @@ static void lv_draw_rect_border_corner(const lv_area_t * coords, const lv_area_t
|
|||||||
|
|
||||||
lv_coord_t i;
|
lv_coord_t i;
|
||||||
for(i = 0; i < seg_size; i++) {
|
for(i = 0; i < seg_size; i++) {
|
||||||
lv_opa_t aa_opa = style->body.border.opa - antialias_get_opa(seg_size, i, style->body.border.opa);
|
lv_opa_t aa_opa = style->body.border.opa - lv_draw_aa_get_opa(seg_size, i, style->body.border.opa);
|
||||||
if((part & LV_BORDER_BOTTOM) && (part & LV_BORDER_RIGHT)) {
|
if((part & LV_BORDER_BOTTOM) && (part & LV_BORDER_RIGHT)) {
|
||||||
px_fp(rb_origo.x + LV_CIRC_OCT1_X(aa_p) + 1, rb_origo.y + LV_CIRC_OCT1_Y(aa_p) + i, mask, style->body.border.color, aa_opa);
|
px_fp(rb_origo.x + LV_CIRC_OCT1_X(aa_p) + 1, rb_origo.y + LV_CIRC_OCT1_Y(aa_p) + i, mask, style->body.border.color, aa_opa);
|
||||||
px_fp(rb_origo.x + LV_CIRC_OCT2_X(aa_p) + i, rb_origo.y + LV_CIRC_OCT2_Y(aa_p) + 1, mask, style->body.border.color, aa_opa);
|
px_fp(rb_origo.x + LV_CIRC_OCT2_X(aa_p) + i, rb_origo.y + LV_CIRC_OCT2_Y(aa_p) + 1, mask, style->body.border.color, aa_opa);
|
||||||
@ -978,7 +978,7 @@ static void lv_draw_rect_border_corner(const lv_area_t * coords, const lv_area_t
|
|||||||
seg_size = in_y_seg_end - in_y_seg_start;
|
seg_size = in_y_seg_end - in_y_seg_start;
|
||||||
|
|
||||||
for(i = 0; i < seg_size; i++) {
|
for(i = 0; i < seg_size; i++) {
|
||||||
lv_opa_t aa_opa = antialias_get_opa(seg_size, i, style->body.border.opa);
|
lv_opa_t aa_opa = lv_draw_aa_get_opa(seg_size, i, style->body.border.opa);
|
||||||
if((part & LV_BORDER_BOTTOM) && (part & LV_BORDER_RIGHT)) {
|
if((part & LV_BORDER_BOTTOM) && (part & LV_BORDER_RIGHT)) {
|
||||||
px_fp(rb_origo.x + LV_CIRC_OCT1_X(aa_p) - 1, rb_origo.y + LV_CIRC_OCT1_Y(aa_p) + i, mask, style->body.border.color, aa_opa);
|
px_fp(rb_origo.x + LV_CIRC_OCT1_X(aa_p) - 1, rb_origo.y + LV_CIRC_OCT1_Y(aa_p) + i, mask, style->body.border.color, aa_opa);
|
||||||
}
|
}
|
||||||
|
@ -221,8 +221,33 @@ static bool lv_arc_design(lv_obj_t * arc, const lv_area_t * mask, lv_design_mode
|
|||||||
lv_coord_t x = arc->coords.x1 + lv_obj_get_width(arc) / 2;
|
lv_coord_t x = arc->coords.x1 + lv_obj_get_width(arc) / 2;
|
||||||
lv_coord_t y = arc->coords.y1 + lv_obj_get_height(arc) / 2;
|
lv_coord_t y = arc->coords.y1 + lv_obj_get_height(arc) / 2;
|
||||||
|
|
||||||
|
|
||||||
lv_draw_arc(x, y, r, mask, ext->angle_start, ext->angle_end, style);
|
lv_draw_arc(x, y, r, mask, ext->angle_start, ext->angle_end, style);
|
||||||
|
|
||||||
|
lv_coord_t thick_2 = style->body.thickness / 2;
|
||||||
|
lv_coord_t cir_x = ((r - thick_2) * lv_trigo_sin(ext->angle_start) >> LV_TRIGO_SHIFT);
|
||||||
|
lv_coord_t cir_y = ((r - thick_2) * lv_trigo_sin(ext->angle_start + 90) >> LV_TRIGO_SHIFT);
|
||||||
|
|
||||||
|
if(style->body.radius == LV_RADIUS_CIRCLE) {
|
||||||
|
lv_area_t cir_area;
|
||||||
|
cir_area.x1 = cir_x + x - thick_2;
|
||||||
|
cir_area.y1 = cir_y + y - thick_2;
|
||||||
|
cir_area.x2 = cir_x + x + thick_2;
|
||||||
|
cir_area.y2 = cir_y + y + thick_2;
|
||||||
|
|
||||||
|
lv_draw_rect(&cir_area, mask, &style);
|
||||||
|
|
||||||
|
cir_x = ((r - thick_2) * lv_trigo_sin(ext->angle_end) >> LV_TRIGO_SHIFT);
|
||||||
|
cir_y = ((r - thick_2) * lv_trigo_sin(ext->angle_end + 90) >> LV_TRIGO_SHIFT);
|
||||||
|
|
||||||
|
cir_area.x1 = cir_x + x - thick_2;
|
||||||
|
cir_area.y1 = cir_y + y - thick_2;
|
||||||
|
cir_area.x2 = cir_x + x + thick_2;
|
||||||
|
cir_area.y2 = cir_y + y + thick_2;
|
||||||
|
|
||||||
|
lv_draw_rect(&cir_area, mask, &style);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
/*Post draw when the children are drawn*/
|
/*Post draw when the children are drawn*/
|
||||||
else if(mode == LV_DESIGN_DRAW_POST) {
|
else if(mode == LV_DESIGN_DRAW_POST) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user