fix(vector): adjust image stride handling in fill pattern and add test case (#8815)

Signed-off-by: wangsimiao1 <wangsimiao1@xiaomi.com>
Co-authored-by: pengyiqiang <pengyiqiang@xiaomi.com>
This commit is contained in:
MickeyMiao
2025-09-23 10:19:56 +08:00
committed by GitHub
parent 5889dd51d6
commit 7171f17fdb
22 changed files with 32 additions and 2 deletions
+14 -2
View File
@@ -299,7 +299,6 @@ static void _set_paint_fill_pattern(Tvg_Paint * obj, Tvg_Canvas * canvas, const
return;
}
const uint8_t * src_buf = decoder_dsc.decoded->data;
const lv_image_header_t * header = &decoder_dsc.decoded->header;
lv_color_format_t cf = header->cf;
@@ -309,8 +308,21 @@ static void _set_paint_fill_pattern(Tvg_Paint * obj, Tvg_Canvas * canvas, const
return;
}
const uint32_t tvg_stride = header->w * sizeof(uint32_t);
if(header->stride != tvg_stride) {
LV_LOG_WARN("img_stride != tvg_stride (%" LV_PRIu32 " != %" LV_PRIu32 "), width = %" LV_PRIu32,
(uint32_t)header->stride,
tvg_stride, (uint32_t)header->w);
lv_result_t result = lv_draw_buf_adjust_stride((lv_draw_buf_t *)decoder_dsc.decoded, tvg_stride);
if(result != LV_RESULT_OK) {
lv_image_decoder_close(&decoder_dsc);
LV_LOG_ERROR("Failed to adjust stride");
return;
}
}
Tvg_Paint * img = tvg_picture_new();
tvg_picture_load_raw(img, (uint32_t *)src_buf, header->w, header->h, true);
tvg_picture_load_raw(img, (uint32_t *)decoder_dsc.decoded->data, header->w, header->h, true);
Tvg_Paint * clip_path = tvg_paint_duplicate(obj);
tvg_paint_set_composite_method(img, clip_path, TVG_COMPOSITE_METHOD_CLIP_PATH);
tvg_paint_set_opacity(img, LV_UDIV255(p->opa * opa));
Binary file not shown.

Before

Width:  |  Height:  |  Size: 30 KiB

After

Width:  |  Height:  |  Size: 35 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 30 KiB

After

Width:  |  Height:  |  Size: 35 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 31 KiB

After

Width:  |  Height:  |  Size: 36 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 31 KiB

After

Width:  |  Height:  |  Size: 36 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 30 KiB

After

Width:  |  Height:  |  Size: 32 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 30 KiB

After

Width:  |  Height:  |  Size: 32 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 31 KiB

After

Width:  |  Height:  |  Size: 36 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 31 KiB

After

Width:  |  Height:  |  Size: 36 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 31 KiB

After

Width:  |  Height:  |  Size: 36 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 31 KiB

After

Width:  |  Height:  |  Size: 36 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 32 KiB

After

Width:  |  Height:  |  Size: 38 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 32 KiB

After

Width:  |  Height:  |  Size: 38 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 28 KiB

After

Width:  |  Height:  |  Size: 32 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 28 KiB

After

Width:  |  Height:  |  Size: 32 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 27 KiB

After

Width:  |  Height:  |  Size: 32 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 27 KiB

After

Width:  |  Height:  |  Size: 32 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 31 KiB

After

Width:  |  Height:  |  Size: 36 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 31 KiB

After

Width:  |  Height:  |  Size: 36 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 28 KiB

After

Width:  |  Height:  |  Size: 31 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 28 KiB

After

Width:  |  Height:  |  Size: 31 KiB

@@ -164,6 +164,24 @@ static void draw_shapes(lv_layer_t * layer, const lv_matrix_t * transform)
lv_vector_path_append_rect(path, &img_area, 0, 0);
lv_vector_dsc_add_path(ctx, path);
/* Test PNG image file */
lv_vector_path_clear(path);
lv_area_t rect3 = {200, 360, 0, 0};
lv_area_set_width(&rect3, 200);
lv_area_set_height(&rect3, 100);
lv_vector_path_append_rect(path, &rect3, 0, 0);
lv_draw_image_dsc_init(&img_dsc);
img_dsc.src = "A:src/test_assets/test_img_lvgl_logo.png";
lv_vector_dsc_set_transform(ctx, transform);
lv_vector_dsc_set_fill_units(ctx, LV_VECTOR_FILL_UNITS_OBJECT_BOUNDING_BOX);
lv_vector_dsc_set_fill_image(ctx, &img_dsc);
lv_vector_dsc_set_fill_opa(ctx, LV_OPA_COVER);
lv_matrix_identity(&mt);
lv_vector_dsc_set_fill_transform(ctx, &mt);
lv_vector_dsc_add_path(ctx, path);
lv_draw_vector(ctx);
lv_vector_path_delete(path);
lv_vector_dsc_delete(ctx);