1
0
mirror of https://github.com/lvgl/lvgl.git synced 2025-01-28 07:03:00 +08:00

fix(vg_lite): fixed clip_radius image cropping error (#6780)

Signed-off-by: pengyiqiang <pengyiqiang@xiaomi.com>
Co-authored-by: pengyiqiang <pengyiqiang@xiaomi.com>
This commit is contained in:
VIFEX 2024-09-03 14:07:16 +08:00 committed by GitHub
parent d057c5c405
commit 837b560231
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
10 changed files with 43 additions and 13 deletions

View File

@ -134,22 +134,17 @@ void lv_draw_vg_lite_img(lv_draw_unit_t * draw_unit, const lv_draw_image_dsc_t *
lv_vg_lite_path_t * path = lv_vg_lite_path_get(u, VG_LITE_FP32);
if(dsc->clip_radius) {
int32_t width = lv_area_get_width(coords);
int32_t height = lv_area_get_height(coords);
float r_short = LV_MIN(width, height) / 2.0f;
float radius = LV_MIN(dsc->clip_radius, r_short);
/**
* When clip_radius is enabled, the clipping edges
* are aligned with the image edges
*/
/* apply the image transform to the path */
lv_vg_lite_path_set_transform(path, &matrix);
lv_vg_lite_path_append_rect(
path,
coords->x1, coords->y1,
width, height,
radius);
0, 0,
lv_area_get_width(coords), lv_area_get_height(coords),
dsc->clip_radius);
lv_vg_lite_path_set_transform(path, NULL);
}
else {
/* append normal rect to the path */
lv_vg_lite_path_append_rect(
path,
clip_area.x1, clip_area.y1,

View File

@ -36,8 +36,10 @@
struct lv_vg_lite_path_t {
vg_lite_path_t base;
vg_lite_matrix_t matrix;
size_t mem_size;
uint8_t format_len;
bool has_transform;
};
typedef struct {
@ -138,6 +140,7 @@ void lv_vg_lite_path_reset(lv_vg_lite_path_t * path, vg_lite_format_t data_forma
path->base.quality = VG_LITE_MEDIUM;
path->base.path_type = VG_LITE_DRAW_ZERO;
path->format_len = lv_vg_lite_path_format_len(data_format);
path->has_transform = false;
}
vg_lite_path_t * lv_vg_lite_path_get_path(lv_vg_lite_path_t * path)
@ -234,6 +237,16 @@ bool lv_vg_lite_path_update_bonding_box(lv_vg_lite_path_t * path)
return true;
}
void lv_vg_lite_path_set_transform(lv_vg_lite_path_t * path, const vg_lite_matrix_t * matrix)
{
LV_ASSERT_NULL(path);
if(matrix) {
path->matrix = *matrix;
}
path->has_transform = matrix ? true : false;
}
void lv_vg_lite_path_set_quality(lv_vg_lite_path_t * path, vg_lite_quality_t quality)
{
LV_ASSERT_NULL(path);
@ -267,6 +280,15 @@ static void lv_vg_lite_path_append_op(lv_vg_lite_path_t * path, uint32_t op)
static void lv_vg_lite_path_append_point(lv_vg_lite_path_t * path, float x, float y)
{
if(path->has_transform) {
LV_VG_LITE_ASSERT_MATRIX(&path->matrix);
/* transform point */
float ori_x = x;
float ori_y = y;
x = ori_x * path->matrix.m[0][0] + ori_y * path->matrix.m[0][1] + path->matrix.m[0][2];
y = ori_x * path->matrix.m[1][0] + ori_y * path->matrix.m[1][1] + path->matrix.m[1][2];
}
if(path->base.format == VG_LITE_FP32) {
lv_vg_lite_path_append_data(path, &x, sizeof(x));
lv_vg_lite_path_append_data(path, &y, sizeof(y));

View File

@ -61,6 +61,8 @@ void lv_vg_lite_path_get_bonding_box(lv_vg_lite_path_t * path,
bool lv_vg_lite_path_update_bonding_box(lv_vg_lite_path_t * path);
void lv_vg_lite_path_set_transform(lv_vg_lite_path_t * path, const vg_lite_matrix_t * matrix);
void lv_vg_lite_path_set_quality(lv_vg_lite_path_t * path, vg_lite_quality_t quality);
vg_lite_path_t * lv_vg_lite_path_get_path(lv_vg_lite_path_t * path);

Binary file not shown.

Before

Width:  |  Height:  |  Size: 8.5 KiB

After

Width:  |  Height:  |  Size: 8.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 8.5 KiB

After

Width:  |  Height:  |  Size: 8.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 8.9 KiB

After

Width:  |  Height:  |  Size: 8.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 9.0 KiB

After

Width:  |  Height:  |  Size: 9.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 10 KiB

View File

@ -365,7 +365,12 @@ void test_image_ignore_transformation_settings_when_tiled(void)
void test_image_clip_radius(void)
{
lv_obj_t * img = lv_img_create(lv_screen_active());
lv_obj_t * par = lv_obj_create(lv_screen_active());
lv_obj_set_scrollbar_mode(par, LV_SCROLLBAR_MODE_OFF);
lv_obj_set_style_radius(par, 0, 0);
lv_obj_center(par);
lv_obj_t * img = lv_img_create(par);
lv_image_set_src(img, &test_arc_bg);
lv_obj_center(img);
@ -374,6 +379,12 @@ void test_image_clip_radius(void)
lv_obj_set_style_radius(img, LV_RADIUS_CIRCLE, 0);
TEST_ASSERT_EQUAL_SCREENSHOT("widgets/image_clip_radius_circle.png");
/* parent cliped */
lv_obj_set_pos(img, -50, -20);
lv_image_set_scale(img, LV_SCALE_NONE * 2);
lv_image_set_rotation(img, 450);
TEST_ASSERT_EQUAL_SCREENSHOT("widgets/image_clip_radius_circle_scaled_rotated.png");
}
void test_image_properties(void)