Skip to content

Commit 3cf1090

Browse files
committed
lv_canvas: Use simpler lookups for 90 and 270
1 parent 7e01321 commit 3cf1090

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

lvgl/src/lv_objx/lv_canvas.c

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,9 @@ void lv_canvas_copy_buf(lv_obj_t * canvas, const void * to_copy, lv_coord_t x, l
269269

270270
/**
271271
* Rotate and image and store the result on a canvas.
272+
*
273+
* NOTE: When doing 90, 180 or 270 degree rotations, using pivot point 0,0 will do a perfect rotation.
274+
*
272275
* @param canvas pointer to a canvas object
273276
* @param img pointer to an image descriptor.
274277
* Can be the image descriptor of an other canvas too (`lv_canvas_get_img()`).
@@ -314,6 +317,26 @@ void lv_canvas_rotate(lv_obj_t * canvas, lv_img_dsc_t * img, int16_t angle, lv_c
314317
lv_img_buf_set_px_color(&ext_dst->dsc, x + offset_x, y + offset_y, color_res);
315318
continue;
316319
}
320+
if ((angle == 270 || angle == 90) && pivot_x == 0 && pivot_y == 0) {
321+
int32_t source_x = x + offset_x;
322+
int32_t source_y = y + offset_y;
323+
int32_t dest_x = x + offset_x;
324+
int32_t dest_y = y + offset_y;
325+
326+
if (angle == 90) {
327+
source_x = img_height - 1 - (x + offset_x);
328+
}
329+
else {
330+
source_y = img_width - 1 - (y + offset_y);
331+
}
332+
333+
lv_color_t color_res = lv_img_buf_get_px_color(img, source_y, source_x, style);
334+
335+
lv_img_buf_set_px_color(&ext_dst->dsc, dest_x, dest_y, color_res);
336+
337+
continue;
338+
}
339+
317340
/*Get the target point relative coordinates to the pivot*/
318341
int32_t xt = x - pivot_x;
319342
int32_t yt = y - pivot_y;

0 commit comments

Comments
 (0)