fix(img): possible divide by 0 exception (lvgl#3988) (#3991)

Co-authored-by: fvanroie <cpt_jack@msn.com>
This commit is contained in:
fvanroie 2023-02-15 20:57:41 +01:00 committed by GitHub
parent b0fa0e286c
commit 7c583ac8d6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -166,8 +166,6 @@ void lv_img_set_offset_x(lv_obj_t * obj, lv_coord_t x)
lv_img_t * img = (lv_img_t *)obj;
x = x % img->w;
img->offset.x = x;
lv_obj_invalidate(obj);
}
@ -178,8 +176,6 @@ void lv_img_set_offset_y(lv_obj_t * obj, lv_coord_t y)
lv_img_t * img = (lv_img_t *)obj;
y = y % img->h;
img->offset.y = y;
lv_obj_invalidate(obj);
}
@ -660,12 +656,14 @@ static void draw_img(lv_event_t * e)
draw_ctx->clip_area = &img_clip_area;
lv_area_t coords_tmp;
coords_tmp.y1 = img_max_area.y1 + img->offset.y;
lv_coord_t offset_x = img->offset.x % img->w;
lv_coord_t offset_y = img->offset.y % img->h;
coords_tmp.y1 = img_max_area.y1 + offset_y;
if(coords_tmp.y1 > img_max_area.y1) coords_tmp.y1 -= img->h;
coords_tmp.y2 = coords_tmp.y1 + img->h - 1;
for(; coords_tmp.y1 < img_max_area.y2; coords_tmp.y1 += img_size_final.y, coords_tmp.y2 += img_size_final.y) {
coords_tmp.x1 = img_max_area.x1 + img->offset.x;
coords_tmp.x1 = img_max_area.x1 + offset_x;
if(coords_tmp.x1 > img_max_area.x1) coords_tmp.x1 -= img->w;
coords_tmp.x2 = coords_tmp.x1 + img->w - 1;