fix(vg_lite): fixed clip_radius image cropping error (#6780)
Signed-off-by: pengyiqiang <pengyiqiang@xiaomi.com> Co-authored-by: pengyiqiang <pengyiqiang@xiaomi.com>
@ -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);
|
lv_vg_lite_path_t * path = lv_vg_lite_path_get(u, VG_LITE_FP32);
|
||||||
|
|
||||||
if(dsc->clip_radius) {
|
if(dsc->clip_radius) {
|
||||||
int32_t width = lv_area_get_width(coords);
|
/* apply the image transform to the path */
|
||||||
int32_t height = lv_area_get_height(coords);
|
lv_vg_lite_path_set_transform(path, &matrix);
|
||||||
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
|
|
||||||
*/
|
|
||||||
lv_vg_lite_path_append_rect(
|
lv_vg_lite_path_append_rect(
|
||||||
path,
|
path,
|
||||||
coords->x1, coords->y1,
|
0, 0,
|
||||||
width, height,
|
lv_area_get_width(coords), lv_area_get_height(coords),
|
||||||
radius);
|
dsc->clip_radius);
|
||||||
|
lv_vg_lite_path_set_transform(path, NULL);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
/* append normal rect to the path */
|
||||||
lv_vg_lite_path_append_rect(
|
lv_vg_lite_path_append_rect(
|
||||||
path,
|
path,
|
||||||
clip_area.x1, clip_area.y1,
|
clip_area.x1, clip_area.y1,
|
||||||
|
@ -36,8 +36,10 @@
|
|||||||
|
|
||||||
struct lv_vg_lite_path_t {
|
struct lv_vg_lite_path_t {
|
||||||
vg_lite_path_t base;
|
vg_lite_path_t base;
|
||||||
|
vg_lite_matrix_t matrix;
|
||||||
size_t mem_size;
|
size_t mem_size;
|
||||||
uint8_t format_len;
|
uint8_t format_len;
|
||||||
|
bool has_transform;
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef struct {
|
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.quality = VG_LITE_MEDIUM;
|
||||||
path->base.path_type = VG_LITE_DRAW_ZERO;
|
path->base.path_type = VG_LITE_DRAW_ZERO;
|
||||||
path->format_len = lv_vg_lite_path_format_len(data_format);
|
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)
|
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;
|
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)
|
void lv_vg_lite_path_set_quality(lv_vg_lite_path_t * path, vg_lite_quality_t quality)
|
||||||
{
|
{
|
||||||
LV_ASSERT_NULL(path);
|
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)
|
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) {
|
if(path->base.format == VG_LITE_FP32) {
|
||||||
lv_vg_lite_path_append_data(path, &x, sizeof(x));
|
lv_vg_lite_path_append_data(path, &x, sizeof(x));
|
||||||
lv_vg_lite_path_append_data(path, &y, sizeof(y));
|
lv_vg_lite_path_append_data(path, &y, sizeof(y));
|
||||||
|
@ -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);
|
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);
|
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);
|
vg_lite_path_t * lv_vg_lite_path_get_path(lv_vg_lite_path_t * path);
|
||||||
|
Before Width: | Height: | Size: 8.5 KiB After Width: | Height: | Size: 8.6 KiB |
Before Width: | Height: | Size: 8.5 KiB After Width: | Height: | Size: 8.6 KiB |
After Width: | Height: | Size: 13 KiB |
Before Width: | Height: | Size: 8.9 KiB After Width: | Height: | Size: 8.9 KiB |
Before Width: | Height: | Size: 9.0 KiB After Width: | Height: | Size: 9.0 KiB |
After Width: | Height: | Size: 10 KiB |
@ -365,7 +365,12 @@ void test_image_ignore_transformation_settings_when_tiled(void)
|
|||||||
|
|
||||||
void test_image_clip_radius(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_image_set_src(img, &test_arc_bg);
|
||||||
lv_obj_center(img);
|
lv_obj_center(img);
|
||||||
|
|
||||||
@ -374,6 +379,12 @@ void test_image_clip_radius(void)
|
|||||||
|
|
||||||
lv_obj_set_style_radius(img, LV_RADIUS_CIRCLE, 0);
|
lv_obj_set_style_radius(img, LV_RADIUS_CIRCLE, 0);
|
||||||
TEST_ASSERT_EQUAL_SCREENSHOT("widgets/image_clip_radius_circle.png");
|
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)
|
void test_image_properties(void)
|
||||||
|