mirror of
https://github.com/lvgl/lvgl.git
synced 2025-01-21 06:53:01 +08:00
use 0.1 degree resolution for image rotation in lv_img and lv_canvas
This commit is contained in:
parent
9d7e9f8cb3
commit
759c4ccb35
@ -389,8 +389,19 @@ void lv_img_buf_transform_init(lv_img_transform_dsc_t * dsc)
|
|||||||
{
|
{
|
||||||
dsc->tmp.pivot_x_256 = dsc->cfg.pivot_x * 256;
|
dsc->tmp.pivot_x_256 = dsc->cfg.pivot_x * 256;
|
||||||
dsc->tmp.pivot_y_256 = dsc->cfg.pivot_y * 256;
|
dsc->tmp.pivot_y_256 = dsc->cfg.pivot_y * 256;
|
||||||
dsc->tmp.sinma = lv_trigo_sin(-dsc->cfg.angle);
|
|
||||||
dsc->tmp.cosma = lv_trigo_sin(-dsc->cfg.angle + 90);
|
int32_t angle_low = dsc->cfg.angle / 10;
|
||||||
|
int32_t angle_hight = angle_low + 1;
|
||||||
|
int32_t angle_rem = dsc->cfg.angle - (angle_low * 10);
|
||||||
|
|
||||||
|
int32_t s1 = lv_trigo_sin(-angle_low);
|
||||||
|
int32_t s2 = lv_trigo_sin(-angle_hight);
|
||||||
|
|
||||||
|
int32_t c1 = lv_trigo_sin(-angle_low + 90);
|
||||||
|
int32_t c2 = lv_trigo_sin(-angle_hight + 90);
|
||||||
|
|
||||||
|
dsc->tmp.sinma = (s1 * (10 - angle_rem) + s2 * angle_rem) / 10;
|
||||||
|
dsc->tmp.cosma = (c1 * (10 - angle_rem) + c2 * angle_rem) / 10;
|
||||||
|
|
||||||
dsc->tmp.chroma_keyed = lv_img_cf_is_chroma_keyed(dsc->cfg.cf) ? 1 : 0;
|
dsc->tmp.chroma_keyed = lv_img_cf_is_chroma_keyed(dsc->cfg.cf) ? 1 : 0;
|
||||||
dsc->tmp.has_alpha = lv_img_cf_has_alpha(dsc->cfg.cf) ? 1 : 0;
|
dsc->tmp.has_alpha = lv_img_cf_has_alpha(dsc->cfg.cf) ? 1 : 0;
|
||||||
@ -507,8 +518,19 @@ bool lv_img_buf_transform(lv_img_transform_dsc_t * dsc, lv_coord_t x, lv_coord_t
|
|||||||
*/
|
*/
|
||||||
void lv_img_buf_get_transformed_area(lv_area_t * res, lv_coord_t w, lv_coord_t h, int16_t angle, uint16_t zoom, lv_point_t * pivot)
|
void lv_img_buf_get_transformed_area(lv_area_t * res, lv_coord_t w, lv_coord_t h, int16_t angle, uint16_t zoom, lv_point_t * pivot)
|
||||||
{
|
{
|
||||||
int16_t sinma = lv_trigo_sin(angle);
|
|
||||||
int16_t cosma = lv_trigo_sin(angle + 90);
|
int32_t angle_low = angle / 10;
|
||||||
|
int32_t angle_hight = angle_low + 1;
|
||||||
|
int32_t angle_rem = angle - (angle_low * 10);
|
||||||
|
|
||||||
|
int32_t s1 = lv_trigo_sin(angle_low);
|
||||||
|
int32_t s2 = lv_trigo_sin(angle_hight);
|
||||||
|
|
||||||
|
int32_t c1 = lv_trigo_sin(angle_low + 90);
|
||||||
|
int32_t c2 = lv_trigo_sin(angle_hight + 90);
|
||||||
|
|
||||||
|
int32_t sinma = (s1 * (10 - angle_rem) + s2 * angle_rem) / 10;
|
||||||
|
int32_t cosma = (c1 * (10 - angle_rem) + c2 * angle_rem) / 10;
|
||||||
|
|
||||||
lv_point_t lt;
|
lv_point_t lt;
|
||||||
lv_point_t rt;
|
lv_point_t rt;
|
||||||
|
@ -135,7 +135,7 @@ void lv_canvas_copy_buf(lv_obj_t * canvas, const void * to_copy, lv_coord_t x, l
|
|||||||
* @param canvas pointer to a canvas object
|
* @param canvas pointer to a canvas object
|
||||||
* @param img pointer to an image descriptor.
|
* @param img pointer to an image descriptor.
|
||||||
* Can be the image descriptor of an other canvas too (`lv_canvas_get_img()`).
|
* Can be the image descriptor of an other canvas too (`lv_canvas_get_img()`).
|
||||||
* @param angle the angle of rotation (0..360);
|
* @param angle the angle of rotation (0..3600), 0.1 deg resolution
|
||||||
* @param zoom zoom factor (256 no zoom);
|
* @param zoom zoom factor (256 no zoom);
|
||||||
* @param offset_x offset X to tell where to put the result data on destination canvas
|
* @param offset_x offset X to tell where to put the result data on destination canvas
|
||||||
* @param offset_y offset X to tell where to put the result data on destination canvas
|
* @param offset_y offset X to tell where to put the result data on destination canvas
|
||||||
|
@ -304,13 +304,13 @@ void lv_img_set_pivot(lv_obj_t * img, lv_coord_t pivot_x, lv_coord_t pivot_y)
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the rotation angle of the image.
|
* Set the rotation angle of the image.
|
||||||
* The image will be rotated around its middle point
|
* The image will be rotated around the set pivot set by `lv_img_set_pivot()`
|
||||||
* @param img pointer to an image object
|
* @param img pointer to an image object
|
||||||
* @param angle rotation angle in degree (> 0: clock wise)
|
* @param angle rotation angle in degree with 0.1 degree resolution (0..3600: clock wise)
|
||||||
*/
|
*/
|
||||||
void lv_img_set_angle(lv_obj_t * img, int16_t angle)
|
void lv_img_set_angle(lv_obj_t * img, int16_t angle)
|
||||||
{
|
{
|
||||||
if(angle < 0 || angle >= 360) angle = angle % 360;
|
if(angle < 0 || angle >= 3600) angle = angle % 3600;
|
||||||
|
|
||||||
lv_img_ext_t * ext = lv_obj_get_ext_attr(img);
|
lv_img_ext_t * ext = lv_obj_get_ext_attr(img);
|
||||||
if(angle == ext->angle) return;
|
if(angle == ext->angle) return;
|
||||||
|
@ -111,9 +111,9 @@ void lv_img_set_pivot(lv_obj_t * img, lv_coord_t pivot_x, lv_coord_t pivot_y);
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the rotation angle of the image.
|
* Set the rotation angle of the image.
|
||||||
* The image will be rotated around its middle point
|
* The image will be rotated around the set pivot set by `lv_img_set_pivot()`
|
||||||
* @param img pointer to an image object
|
* @param img pointer to an image object
|
||||||
* @param angle rotate angle in degree (> 0: clock wise)
|
* @param angle rotation angle in degree with 0.1 degree resolution (0..3600: clock wise)
|
||||||
*/
|
*/
|
||||||
void lv_img_set_angle(lv_obj_t * img, int16_t angle);
|
void lv_img_set_angle(lv_obj_t * img, int16_t angle);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user