2016-06-08 07:25:08 +02:00
|
|
|
/**
|
|
|
|
* @file lv_img.c
|
2018-06-19 09:49:58 +02:00
|
|
|
*
|
2016-06-08 07:25:08 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
/*********************
|
|
|
|
* INCLUDES
|
|
|
|
*********************/
|
2018-07-07 11:53:22 +02:00
|
|
|
#include "lv_img.h"
|
2019-03-07 00:05:16 +01:00
|
|
|
#if LV_USE_IMG != 0
|
2016-06-08 07:25:08 +02:00
|
|
|
|
2018-01-19 15:40:22 +01:00
|
|
|
/*Testing of dependencies*/
|
2019-03-07 00:05:16 +01:00
|
|
|
#if LV_USE_LABEL == 0
|
2020-02-26 19:48:27 +01:00
|
|
|
#error "lv_img: lv_label is required. Enable it in lv_conf.h (LV_USE_LABEL 1) "
|
2018-01-19 15:40:22 +01:00
|
|
|
#endif
|
|
|
|
|
2020-06-08 13:10:43 +02:00
|
|
|
#include "../lv_misc/lv_debug.h"
|
2017-11-16 15:32:33 +01:00
|
|
|
#include "../lv_themes/lv_theme.h"
|
2019-05-15 05:22:03 +02:00
|
|
|
#include "../lv_draw/lv_img_decoder.h"
|
2017-11-23 20:42:14 +01:00
|
|
|
#include "../lv_misc/lv_fs.h"
|
2017-11-26 11:38:28 +01:00
|
|
|
#include "../lv_misc/lv_txt.h"
|
2019-11-02 21:30:51 +01:00
|
|
|
#include "../lv_misc/lv_math.h"
|
2018-10-05 15:15:19 +02:00
|
|
|
#include "../lv_misc/lv_log.h"
|
2017-01-16 12:30:22 +01:00
|
|
|
|
2016-06-08 07:25:08 +02:00
|
|
|
/*********************
|
|
|
|
* DEFINES
|
|
|
|
*********************/
|
2019-09-26 10:51:54 +02:00
|
|
|
#define LV_OBJX_NAME "lv_img"
|
2016-06-08 07:25:08 +02:00
|
|
|
|
|
|
|
/**********************
|
|
|
|
* TYPEDEFS
|
|
|
|
**********************/
|
|
|
|
|
|
|
|
/**********************
|
|
|
|
* STATIC PROTOTYPES
|
|
|
|
**********************/
|
2019-09-06 19:53:39 +02:00
|
|
|
static lv_design_res_t lv_img_design(lv_obj_t * img, const lv_area_t * clip_area, lv_design_mode_t mode);
|
2017-11-13 16:11:05 +01:00
|
|
|
static lv_res_t lv_img_signal(lv_obj_t * img, lv_signal_t sign, void * param);
|
2020-01-16 14:26:36 +01:00
|
|
|
static lv_style_list_t * lv_img_get_style(lv_obj_t * img, uint8_t type);
|
2017-01-16 12:30:22 +01:00
|
|
|
|
2016-06-08 07:25:08 +02:00
|
|
|
/**********************
|
|
|
|
* STATIC VARIABLES
|
|
|
|
**********************/
|
2019-02-26 09:25:46 +01:00
|
|
|
static lv_signal_cb_t ancestor_signal;
|
2016-06-08 07:25:08 +02:00
|
|
|
|
|
|
|
/**********************
|
|
|
|
* MACROS
|
|
|
|
**********************/
|
|
|
|
|
|
|
|
/**********************
|
|
|
|
* GLOBAL FUNCTIONS
|
|
|
|
**********************/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create an image objects
|
2016-10-07 11:15:46 +02:00
|
|
|
* @param par pointer to an object, it will be the parent of the new button
|
2017-04-13 16:12:03 +02:00
|
|
|
* @param copy pointer to a image object, if not NULL then the new object will be copied from it
|
2016-06-08 07:25:08 +02:00
|
|
|
* @return pointer to the created image
|
|
|
|
*/
|
2018-07-30 06:52:29 +02:00
|
|
|
lv_obj_t * lv_img_create(lv_obj_t * par, const lv_obj_t * copy)
|
2016-06-08 07:25:08 +02:00
|
|
|
{
|
2018-09-12 18:55:28 +03:00
|
|
|
LV_LOG_TRACE("image create started");
|
2018-07-25 17:57:08 +02:00
|
|
|
|
2016-06-08 07:25:08 +02:00
|
|
|
/*Create a basic object*/
|
2020-02-25 15:32:35 +01:00
|
|
|
lv_obj_t * img = lv_obj_create(par, copy);
|
2020-02-01 15:02:29 +01:00
|
|
|
LV_ASSERT_MEM(img);
|
|
|
|
if(img == NULL) return NULL;
|
2018-07-25 13:33:53 +02:00
|
|
|
|
2020-02-01 15:02:29 +01:00
|
|
|
if(ancestor_signal == NULL) ancestor_signal = lv_obj_get_signal_cb(img);
|
2018-06-19 09:49:58 +02:00
|
|
|
|
2016-06-08 07:25:08 +02:00
|
|
|
/*Extend the basic object to image object*/
|
2020-02-01 15:02:29 +01:00
|
|
|
lv_img_ext_t * ext = lv_obj_allocate_ext_attr(img, sizeof(lv_img_ext_t));
|
2019-09-24 23:14:17 +02:00
|
|
|
LV_ASSERT_MEM(ext);
|
2019-12-03 18:16:14 +01:00
|
|
|
if(ext == NULL) {
|
2020-02-01 15:02:29 +01:00
|
|
|
lv_obj_del(img);
|
2019-12-03 18:16:14 +01:00
|
|
|
return NULL;
|
|
|
|
}
|
2018-07-25 13:33:53 +02:00
|
|
|
|
2019-04-04 07:15:40 +02:00
|
|
|
ext->src = NULL;
|
|
|
|
ext->src_type = LV_IMG_SRC_UNKNOWN;
|
|
|
|
ext->cf = LV_IMG_CF_UNKNOWN;
|
2020-02-01 15:02:29 +01:00
|
|
|
ext->w = lv_obj_get_width(img);
|
|
|
|
ext->h = lv_obj_get_height(img);
|
2019-11-03 10:08:15 +01:00
|
|
|
ext->angle = 0;
|
2019-11-08 22:43:58 +01:00
|
|
|
ext->zoom = LV_IMG_ZOOM_NONE;
|
|
|
|
ext->antialias = LV_ANTIALIAS ? 1 : 0;
|
2017-04-28 16:12:35 +02:00
|
|
|
ext->auto_size = 1;
|
2019-04-04 07:15:40 +02:00
|
|
|
ext->offset.x = 0;
|
|
|
|
ext->offset.y = 0;
|
2019-11-29 15:36:52 +01:00
|
|
|
ext->pivot.x = 0;
|
|
|
|
ext->pivot.y = 0;
|
2016-06-08 07:25:08 +02:00
|
|
|
|
2018-06-19 09:49:58 +02:00
|
|
|
/*Init the new object*/
|
2020-02-01 15:02:29 +01:00
|
|
|
lv_obj_set_signal_cb(img, lv_img_signal);
|
|
|
|
lv_obj_set_design_cb(img, lv_img_design);
|
2018-06-19 09:49:58 +02:00
|
|
|
|
2016-10-07 11:15:46 +02:00
|
|
|
if(copy == NULL) {
|
2020-02-01 15:02:29 +01:00
|
|
|
lv_theme_apply(img, LV_THEME_IMAGE);
|
|
|
|
lv_obj_set_click(img, false);
|
|
|
|
lv_obj_set_adv_hittest(img, true); /*Images have fast hit-testing*/
|
2018-09-12 18:55:28 +03:00
|
|
|
/* Enable auto size for non screens
|
2018-06-19 09:49:58 +02:00
|
|
|
* because image screens are wallpapers
|
|
|
|
* and must be screen sized*/
|
2018-09-03 14:43:30 +02:00
|
|
|
if(par != NULL) {
|
2018-09-12 18:55:28 +03:00
|
|
|
ext->auto_size = 1;
|
2020-02-26 19:48:27 +01:00
|
|
|
}
|
|
|
|
else {
|
2018-09-12 18:55:28 +03:00
|
|
|
ext->auto_size = 0;
|
2018-09-03 14:43:30 +02:00
|
|
|
}
|
2020-02-26 19:48:27 +01:00
|
|
|
}
|
|
|
|
else {
|
2017-10-20 10:17:02 +02:00
|
|
|
lv_img_ext_t * copy_ext = lv_obj_get_ext_attr(copy);
|
2020-03-01 01:59:42 +01:00
|
|
|
ext->auto_size = copy_ext->auto_size;
|
|
|
|
ext->zoom = copy_ext->zoom;
|
|
|
|
ext->angle = copy_ext->angle;
|
|
|
|
ext->antialias = copy_ext->antialias;
|
|
|
|
ext->offset.x = copy_ext->offset.x;
|
|
|
|
ext->offset.y = copy_ext->offset.y;
|
|
|
|
ext->pivot.x = copy_ext->pivot.x;
|
|
|
|
ext->pivot.y = copy_ext->pivot.y;
|
2020-02-01 15:02:29 +01:00
|
|
|
lv_img_set_src(img, copy_ext->src);
|
2017-01-02 14:10:32 +01:00
|
|
|
|
2020-03-03 15:37:13 +01:00
|
|
|
/*Refresh the style with new signal function*/
|
2020-08-02 11:36:27 +02:00
|
|
|
lv_obj_refresh_style(img, LV_OBJ_PART_ALL, LV_STYLE_PROP_ALL);
|
2016-06-08 07:25:08 +02:00
|
|
|
}
|
|
|
|
|
2018-09-12 18:55:28 +03:00
|
|
|
LV_LOG_INFO("image created");
|
2018-07-25 17:57:08 +02:00
|
|
|
|
2020-02-01 15:02:29 +01:00
|
|
|
return img;
|
2016-06-08 07:25:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*=====================
|
2018-06-19 09:49:58 +02:00
|
|
|
* Setter functions
|
2016-06-08 07:25:08 +02:00
|
|
|
*====================*/
|
|
|
|
|
2018-02-09 12:40:00 +01:00
|
|
|
/**
|
|
|
|
* Set the pixel map to display by the image
|
|
|
|
* @param img pointer to an image object
|
|
|
|
* @param data the image data
|
|
|
|
*/
|
2018-02-23 13:56:04 +01:00
|
|
|
void lv_img_set_src(lv_obj_t * img, const void * src_img)
|
2018-02-09 12:40:00 +01:00
|
|
|
{
|
2019-09-26 12:54:40 +02:00
|
|
|
LV_ASSERT_OBJ(img, LV_OBJX_NAME);
|
|
|
|
|
2018-08-08 09:50:01 +02:00
|
|
|
lv_img_src_t src_type = lv_img_src_get_type(src_img);
|
2019-04-04 07:15:40 +02:00
|
|
|
lv_img_ext_t * ext = lv_obj_get_ext_attr(img);
|
2018-02-09 12:40:00 +01:00
|
|
|
|
2019-03-07 00:05:16 +01:00
|
|
|
#if LV_USE_LOG && LV_LOG_LEVEL >= LV_LOG_LEVEL_INFO
|
2018-09-23 21:24:51 +02:00
|
|
|
switch(src_type) {
|
2020-02-26 19:48:27 +01:00
|
|
|
case LV_IMG_SRC_FILE:
|
|
|
|
LV_LOG_TRACE("lv_img_set_src: `LV_IMG_SRC_FILE` type found");
|
|
|
|
break;
|
|
|
|
case LV_IMG_SRC_VARIABLE:
|
|
|
|
LV_LOG_TRACE("lv_img_set_src: `LV_IMG_SRC_VARIABLE` type found");
|
|
|
|
break;
|
|
|
|
case LV_IMG_SRC_SYMBOL:
|
|
|
|
LV_LOG_TRACE("lv_img_set_src: `LV_IMG_SRC_SYMBOL` type found");
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
LV_LOG_WARN("lv_img_set_src: unknown type");
|
2018-09-23 21:24:51 +02:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2018-08-08 09:50:01 +02:00
|
|
|
/*If the new source type is unknown free the memories of the old source*/
|
2018-02-23 13:56:04 +01:00
|
|
|
if(src_type == LV_IMG_SRC_UNKNOWN) {
|
2018-09-23 21:24:51 +02:00
|
|
|
LV_LOG_WARN("lv_img_set_src: unknown image type");
|
2018-02-23 13:56:04 +01:00
|
|
|
if(ext->src_type == LV_IMG_SRC_SYMBOL || ext->src_type == LV_IMG_SRC_FILE) {
|
|
|
|
lv_mem_free(ext->src);
|
|
|
|
}
|
2019-04-04 07:15:40 +02:00
|
|
|
ext->src = NULL;
|
2018-02-23 13:56:04 +01:00
|
|
|
ext->src_type = LV_IMG_SRC_UNKNOWN;
|
|
|
|
return;
|
|
|
|
}
|
2018-02-09 12:40:00 +01:00
|
|
|
|
2018-08-08 09:50:01 +02:00
|
|
|
lv_img_header_t header;
|
2019-05-14 15:45:03 +02:00
|
|
|
lv_img_decoder_get_info(src_img, &header);
|
2018-02-23 13:56:04 +01:00
|
|
|
|
2018-09-12 18:55:28 +03:00
|
|
|
/*Save the source*/
|
|
|
|
if(src_type == LV_IMG_SRC_VARIABLE) {
|
2018-09-23 21:24:51 +02:00
|
|
|
LV_LOG_INFO("lv_img_set_src: `LV_IMG_SRC_VARIABLE` type found");
|
2018-12-20 22:48:10 +01:00
|
|
|
|
|
|
|
/*If memory was allocated because of the previous `src_type` then free it*/
|
|
|
|
if(ext->src_type == LV_IMG_SRC_FILE || ext->src_type == LV_IMG_SRC_SYMBOL) {
|
|
|
|
lv_mem_free(ext->src);
|
|
|
|
}
|
2018-09-12 18:55:28 +03:00
|
|
|
ext->src = src_img;
|
2020-02-26 19:48:27 +01:00
|
|
|
}
|
|
|
|
else if(src_type == LV_IMG_SRC_FILE || src_type == LV_IMG_SRC_SYMBOL) {
|
2018-02-23 13:56:04 +01:00
|
|
|
/* If the new and the old src are the same then it was only a refresh.*/
|
|
|
|
if(ext->src != src_img) {
|
2019-09-30 06:21:18 +02:00
|
|
|
const void * old_src = NULL;
|
|
|
|
/* If memory was allocated because of the previous `src_type` then save its pointer and free after allocation.
|
|
|
|
* It's important to allocate first to be sure the new data will be on a new address.
|
|
|
|
* Else `img_cache` wouldn't see the change in source.*/
|
2018-12-02 16:48:50 +01:00
|
|
|
if(ext->src_type == LV_IMG_SRC_FILE || ext->src_type == LV_IMG_SRC_SYMBOL) {
|
2019-09-30 06:21:18 +02:00
|
|
|
old_src = ext->src;
|
2018-12-02 16:48:50 +01:00
|
|
|
}
|
2019-04-04 07:15:40 +02:00
|
|
|
char * new_str = lv_mem_alloc(strlen(src_img) + 1);
|
2019-09-24 23:14:17 +02:00
|
|
|
LV_ASSERT_MEM(new_str);
|
2018-08-08 09:50:01 +02:00
|
|
|
if(new_str == NULL) return;
|
|
|
|
strcpy(new_str, src_img);
|
|
|
|
ext->src = new_str;
|
2019-09-30 06:21:18 +02:00
|
|
|
|
|
|
|
if(old_src) lv_mem_free(old_src);
|
2018-02-23 13:56:04 +01:00
|
|
|
}
|
2018-09-14 21:58:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if(src_type == LV_IMG_SRC_SYMBOL) {
|
2018-09-12 18:55:28 +03:00
|
|
|
/*`lv_img_dsc_get_info` couldn't set the with and height of a font so set it here*/
|
2020-02-15 00:33:26 +01:00
|
|
|
const lv_font_t * font = lv_obj_get_style_text_font(img, LV_IMG_PART_MAIN);
|
2020-02-12 08:54:03 +01:00
|
|
|
lv_style_int_t letter_space = lv_obj_get_style_text_letter_space(img, LV_IMG_PART_MAIN);
|
|
|
|
lv_style_int_t line_space = lv_obj_get_style_text_line_space(img, LV_IMG_PART_MAIN);
|
2018-09-12 18:55:28 +03:00
|
|
|
lv_point_t size;
|
2020-05-13 14:11:16 +02:00
|
|
|
_lv_txt_get_size(&size, src_img, font, letter_space, line_space,
|
2020-05-18 16:57:23 +02:00
|
|
|
LV_COORD_MAX, LV_TXT_FLAG_NONE);
|
2018-09-12 18:55:28 +03:00
|
|
|
header.w = size.x;
|
|
|
|
header.h = size.y;
|
|
|
|
}
|
2018-08-16 00:15:19 +02:00
|
|
|
|
2018-08-08 09:50:01 +02:00
|
|
|
ext->src_type = src_type;
|
2019-04-04 07:15:40 +02:00
|
|
|
ext->w = header.w;
|
|
|
|
ext->h = header.h;
|
|
|
|
ext->cf = header.cf;
|
2019-11-29 15:36:52 +01:00
|
|
|
ext->pivot.x = header.w / 2;
|
|
|
|
ext->pivot.y = header.h / 2;
|
2017-01-16 12:30:22 +01:00
|
|
|
|
2016-10-07 11:15:46 +02:00
|
|
|
if(lv_img_get_auto_size(img) != false) {
|
2017-01-16 12:30:22 +01:00
|
|
|
lv_obj_set_size(img, ext->w, ext->h);
|
2016-06-08 07:25:08 +02:00
|
|
|
}
|
2016-12-15 19:47:27 +01:00
|
|
|
|
2019-11-02 21:30:51 +01:00
|
|
|
/*Provide enough room for the rotated corners*/
|
2020-02-14 10:21:38 +01:00
|
|
|
if(ext->angle || ext->zoom != LV_IMG_ZOOM_NONE) lv_obj_refresh_ext_draw_pad(img);
|
2019-11-02 21:30:51 +01:00
|
|
|
|
2017-10-20 10:17:02 +02:00
|
|
|
lv_obj_invalidate(img);
|
2016-06-08 07:25:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2016-10-07 11:15:46 +02:00
|
|
|
* Enable the auto size feature.
|
|
|
|
* If enabled the object size will be same as the picture size.
|
|
|
|
* @param img pointer to an image
|
2018-12-22 19:45:55 +01:00
|
|
|
* @param en true: auto size enable, false: auto size disable
|
2017-01-09 08:50:38 +01:00
|
|
|
*/
|
2018-12-22 19:45:55 +01:00
|
|
|
void lv_img_set_auto_size(lv_obj_t * img, bool en)
|
2017-01-09 08:50:38 +01:00
|
|
|
{
|
2019-09-26 12:54:40 +02:00
|
|
|
LV_ASSERT_OBJ(img, LV_OBJX_NAME);
|
|
|
|
|
2017-10-20 10:17:02 +02:00
|
|
|
lv_img_ext_t * ext = lv_obj_get_ext_attr(img);
|
2017-01-09 08:50:38 +01:00
|
|
|
|
2018-12-22 19:45:55 +01:00
|
|
|
ext->auto_size = (en == false ? 0 : 1);
|
2017-01-09 08:50:38 +01:00
|
|
|
}
|
|
|
|
|
2019-03-06 17:33:14 +03:30
|
|
|
/**
|
|
|
|
* Set an offset for the source of an image.
|
|
|
|
* so the image will be displayed from the new origin.
|
|
|
|
* @param img pointer to an image
|
|
|
|
* @param x: the new offset along x axis.
|
2019-03-04 12:41:28 +03:30
|
|
|
*/
|
2019-04-04 07:15:40 +02:00
|
|
|
void lv_img_set_offset_x(lv_obj_t * img, lv_coord_t x)
|
2019-03-04 12:41:28 +03:30
|
|
|
{
|
2019-09-26 12:54:40 +02:00
|
|
|
LV_ASSERT_OBJ(img, LV_OBJX_NAME);
|
|
|
|
|
2019-03-04 12:41:28 +03:30
|
|
|
lv_img_ext_t * ext = lv_obj_get_ext_attr(img);
|
|
|
|
|
2019-11-21 05:44:43 +01:00
|
|
|
x = x % ext->w;
|
|
|
|
|
|
|
|
ext->offset.x = x;
|
|
|
|
lv_obj_invalidate(img);
|
2019-03-06 17:33:14 +03:30
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set an offset for the source of an image.
|
|
|
|
* so the image will be displayed from the new origin.
|
|
|
|
* @param img pointer to an image
|
|
|
|
* @param y: the new offset along y axis.
|
|
|
|
*/
|
2019-04-04 07:15:40 +02:00
|
|
|
void lv_img_set_offset_y(lv_obj_t * img, lv_coord_t y)
|
2019-03-06 17:33:14 +03:30
|
|
|
{
|
2019-09-26 12:54:40 +02:00
|
|
|
LV_ASSERT_OBJ(img, LV_OBJX_NAME);
|
|
|
|
|
2019-03-06 17:33:14 +03:30
|
|
|
lv_img_ext_t * ext = lv_obj_get_ext_attr(img);
|
|
|
|
|
2019-11-21 05:44:43 +01:00
|
|
|
y = y % ext->h;
|
|
|
|
|
|
|
|
ext->offset.y = y;
|
|
|
|
lv_obj_invalidate(img);
|
2019-03-04 12:41:28 +03:30
|
|
|
}
|
2016-06-08 07:25:08 +02:00
|
|
|
|
2019-11-29 11:32:22 +08:00
|
|
|
/**
|
|
|
|
* Set the rotation center of the image.
|
2019-11-29 15:36:52 +01:00
|
|
|
* The image will be rotated around this point
|
2019-11-29 11:32:22 +08:00
|
|
|
* @param img pointer to an image object
|
2019-11-29 15:36:52 +01:00
|
|
|
* @param pivot_x rotation center x of the image
|
|
|
|
* @param pivot_y rotation center y of the image
|
2019-11-29 11:32:22 +08:00
|
|
|
*/
|
2019-11-29 15:36:52 +01:00
|
|
|
void lv_img_set_pivot(lv_obj_t * img, lv_coord_t pivot_x, lv_coord_t pivot_y)
|
2019-11-29 11:32:22 +08:00
|
|
|
{
|
|
|
|
lv_img_ext_t * ext = lv_obj_get_ext_attr(img);
|
2020-02-26 19:48:27 +01:00
|
|
|
if(ext->pivot.x == pivot_x && ext->pivot.y == pivot_y) return;
|
2019-11-29 11:32:22 +08:00
|
|
|
|
2020-05-01 10:34:52 +02:00
|
|
|
lv_style_int_t transf_zoom = lv_obj_get_style_transform_zoom(img, LV_IMG_PART_MAIN);
|
|
|
|
transf_zoom = (transf_zoom * ext->zoom) >> 8;
|
|
|
|
|
2020-05-01 20:48:16 +02:00
|
|
|
lv_style_int_t transf_angle = lv_obj_get_style_transform_angle(img, LV_IMG_PART_MAIN);
|
2020-05-01 10:34:52 +02:00
|
|
|
transf_angle += ext->angle;
|
|
|
|
|
2020-08-24 09:50:05 +02:00
|
|
|
lv_coord_t w = lv_obj_get_width(img);
|
|
|
|
lv_coord_t h = lv_obj_get_height(img);
|
2020-02-14 10:21:38 +01:00
|
|
|
lv_area_t a;
|
2020-08-24 09:50:05 +02:00
|
|
|
_lv_img_buf_get_transformed_area(&a, w, h, transf_angle, transf_zoom, &ext->pivot);
|
2020-02-14 10:21:38 +01:00
|
|
|
a.x1 += img->coords.x1;
|
|
|
|
a.y1 += img->coords.y1;
|
|
|
|
a.x2 += img->coords.x1;
|
|
|
|
a.y2 += img->coords.y1;
|
|
|
|
lv_obj_invalidate_area(img, &a);
|
|
|
|
|
2019-11-29 15:36:52 +01:00
|
|
|
ext->pivot.x = pivot_x;
|
|
|
|
ext->pivot.y = pivot_y;
|
2019-11-29 11:32:22 +08:00
|
|
|
lv_obj_refresh_ext_draw_pad(img);
|
2020-02-14 10:21:38 +01:00
|
|
|
|
2020-08-24 09:50:05 +02:00
|
|
|
_lv_img_buf_get_transformed_area(&a, w, h, transf_angle, transf_zoom, &ext->pivot);
|
2020-02-14 10:21:38 +01:00
|
|
|
a.x1 += img->coords.x1;
|
|
|
|
a.y1 += img->coords.y1;
|
|
|
|
a.x2 += img->coords.x1;
|
|
|
|
a.y2 += img->coords.y1;
|
|
|
|
lv_obj_invalidate_area(img, &a);
|
2019-11-29 11:32:22 +08:00
|
|
|
}
|
|
|
|
|
2019-11-03 16:21:58 +01:00
|
|
|
/**
|
|
|
|
* Set the rotation angle of the image.
|
2020-02-20 14:31:04 +01:00
|
|
|
* The image will be rotated around the set pivot set by `lv_img_set_pivot()`
|
2019-11-03 16:21:58 +01:00
|
|
|
* @param img pointer to an image object
|
2020-02-20 14:31:04 +01:00
|
|
|
* @param angle rotation angle in degree with 0.1 degree resolution (0..3600: clock wise)
|
2019-11-03 16:21:58 +01:00
|
|
|
*/
|
2019-11-02 21:30:51 +01:00
|
|
|
void lv_img_set_angle(lv_obj_t * img, int16_t angle)
|
|
|
|
{
|
2020-02-20 14:31:04 +01:00
|
|
|
if(angle < 0 || angle >= 3600) angle = angle % 3600;
|
2019-11-02 21:30:51 +01:00
|
|
|
|
|
|
|
lv_img_ext_t * ext = lv_obj_get_ext_attr(img);
|
2019-11-08 22:43:58 +01:00
|
|
|
if(angle == ext->angle) return;
|
|
|
|
|
2020-05-01 10:34:52 +02:00
|
|
|
lv_style_int_t transf_zoom = lv_obj_get_style_transform_zoom(img, LV_IMG_PART_MAIN);
|
|
|
|
transf_zoom = (transf_zoom * ext->zoom) >> 8;
|
|
|
|
|
2020-05-01 20:48:16 +02:00
|
|
|
lv_style_int_t transf_angle = lv_obj_get_style_transform_angle(img, LV_IMG_PART_MAIN);
|
2020-05-01 10:34:52 +02:00
|
|
|
|
2020-08-24 09:50:05 +02:00
|
|
|
lv_coord_t w = lv_obj_get_width(img);
|
|
|
|
lv_coord_t h = lv_obj_get_height(img);
|
2020-02-14 10:21:38 +01:00
|
|
|
lv_area_t a;
|
2020-08-24 09:50:05 +02:00
|
|
|
_lv_img_buf_get_transformed_area(&a, w, h, transf_angle + ext->angle, transf_zoom, &ext->pivot);
|
2020-02-14 10:21:38 +01:00
|
|
|
a.x1 += img->coords.x1;
|
|
|
|
a.y1 += img->coords.y1;
|
|
|
|
a.x2 += img->coords.x1;
|
|
|
|
a.y2 += img->coords.y1;
|
|
|
|
lv_obj_invalidate_area(img, &a);
|
|
|
|
|
2019-11-02 21:30:51 +01:00
|
|
|
ext->angle = angle;
|
|
|
|
lv_obj_refresh_ext_draw_pad(img);
|
2020-02-14 10:21:38 +01:00
|
|
|
|
2020-08-24 09:50:05 +02:00
|
|
|
_lv_img_buf_get_transformed_area(&a, w, h, transf_angle + ext->angle, transf_zoom, &ext->pivot);
|
2020-02-14 10:21:38 +01:00
|
|
|
a.x1 += img->coords.x1;
|
|
|
|
a.y1 += img->coords.y1;
|
|
|
|
a.x2 += img->coords.x1;
|
|
|
|
a.y2 += img->coords.y1;
|
|
|
|
lv_obj_invalidate_area(img, &a);
|
2019-11-08 22:43:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the zoom factor of the image.
|
|
|
|
* @param img pointer to an image object
|
|
|
|
* @param zoom the zoom factor.
|
|
|
|
* - 256 or LV_ZOOM_IMG_NONE for no zoom
|
|
|
|
* - <256: scale down
|
|
|
|
* - >256 scale up
|
|
|
|
* - 128 half size
|
|
|
|
* - 512 double size
|
|
|
|
*/
|
|
|
|
void lv_img_set_zoom(lv_obj_t * img, uint16_t zoom)
|
|
|
|
{
|
|
|
|
lv_img_ext_t * ext = lv_obj_get_ext_attr(img);
|
|
|
|
if(zoom == ext->zoom) return;
|
|
|
|
|
|
|
|
if(zoom == 0) zoom = 1;
|
|
|
|
|
2020-05-01 10:34:52 +02:00
|
|
|
lv_style_int_t transf_zoom = lv_obj_get_style_transform_zoom(img, LV_IMG_PART_MAIN);
|
|
|
|
|
2020-05-01 20:48:16 +02:00
|
|
|
lv_style_int_t transf_angle = lv_obj_get_style_transform_angle(img, LV_IMG_PART_MAIN);
|
2020-05-01 10:34:52 +02:00
|
|
|
transf_angle += ext->angle;
|
|
|
|
|
2020-08-24 09:50:05 +02:00
|
|
|
lv_coord_t w = lv_obj_get_width(img);
|
|
|
|
lv_coord_t h = lv_obj_get_height(img);
|
2020-02-14 10:21:38 +01:00
|
|
|
lv_area_t a;
|
2020-08-24 09:50:05 +02:00
|
|
|
_lv_img_buf_get_transformed_area(&a, w, h, transf_angle, (transf_zoom * ext->zoom) >> 8, &ext->pivot);
|
2020-02-14 10:21:38 +01:00
|
|
|
a.x1 += img->coords.x1;
|
|
|
|
a.y1 += img->coords.y1;
|
|
|
|
a.x2 += img->coords.x1;
|
|
|
|
a.y2 += img->coords.y1;
|
|
|
|
lv_obj_invalidate_area(img, &a);
|
|
|
|
|
2019-11-08 22:43:58 +01:00
|
|
|
ext->zoom = zoom;
|
|
|
|
lv_obj_refresh_ext_draw_pad(img);
|
2020-02-14 10:21:38 +01:00
|
|
|
|
2020-08-24 09:50:05 +02:00
|
|
|
_lv_img_buf_get_transformed_area(&a, w, h, transf_angle, (transf_zoom * ext->zoom) >> 8, &ext->pivot);
|
2020-02-14 10:21:38 +01:00
|
|
|
a.x1 += img->coords.x1;
|
|
|
|
a.y1 += img->coords.y1;
|
|
|
|
a.x2 += img->coords.x1;
|
|
|
|
a.y2 += img->coords.y1;
|
|
|
|
lv_obj_invalidate_area(img, &a);
|
2019-11-08 22:43:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Enable/disable anti-aliasing for the transformations (rotate, zoom) or not
|
|
|
|
* @param img pointer to an image object
|
|
|
|
* @param antialias true: anti-aliased; false: not anti-aliased
|
|
|
|
*/
|
2019-11-12 09:45:40 +01:00
|
|
|
void lv_img_set_antialias(lv_obj_t * img, bool antialias)
|
2019-11-08 22:43:58 +01:00
|
|
|
{
|
|
|
|
lv_img_ext_t * ext = lv_obj_get_ext_attr(img);
|
|
|
|
if(antialias == ext->antialias) return;
|
2019-11-02 21:30:51 +01:00
|
|
|
|
2019-11-08 22:43:58 +01:00
|
|
|
ext->antialias = antialias;
|
|
|
|
lv_obj_invalidate(img);
|
2019-11-02 21:30:51 +01:00
|
|
|
}
|
|
|
|
|
2016-06-08 07:25:08 +02:00
|
|
|
/*=====================
|
2018-06-19 09:49:58 +02:00
|
|
|
* Getter functions
|
2016-06-08 07:25:08 +02:00
|
|
|
*====================*/
|
|
|
|
|
2018-08-04 01:46:00 +02:00
|
|
|
/**
|
|
|
|
* Get the source of the image
|
|
|
|
* @param img pointer to an image object
|
|
|
|
* @return the image source (symbol, file name or C array)
|
|
|
|
*/
|
|
|
|
const void * lv_img_get_src(lv_obj_t * img)
|
|
|
|
{
|
2019-09-26 12:54:40 +02:00
|
|
|
LV_ASSERT_OBJ(img, LV_OBJX_NAME);
|
|
|
|
|
2018-08-04 01:46:00 +02:00
|
|
|
lv_img_ext_t * ext = lv_obj_get_ext_attr(img);
|
|
|
|
|
|
|
|
return ext->src;
|
|
|
|
}
|
|
|
|
|
2017-10-31 16:25:52 +01:00
|
|
|
/**
|
|
|
|
* Get the name of the file set for an image
|
|
|
|
* @param img pointer to an image
|
|
|
|
* @return file name
|
|
|
|
*/
|
2018-07-30 06:52:29 +02:00
|
|
|
const char * lv_img_get_file_name(const lv_obj_t * img)
|
2017-10-31 16:25:52 +01:00
|
|
|
{
|
2019-09-26 12:54:40 +02:00
|
|
|
LV_ASSERT_OBJ(img, LV_OBJX_NAME);
|
|
|
|
|
2017-10-31 16:25:52 +01:00
|
|
|
lv_img_ext_t * ext = lv_obj_get_ext_attr(img);
|
|
|
|
|
2019-04-04 07:15:40 +02:00
|
|
|
if(ext->src_type == LV_IMG_SRC_FILE)
|
|
|
|
return ext->src;
|
|
|
|
else
|
|
|
|
return "";
|
2017-10-31 16:25:52 +01:00
|
|
|
}
|
|
|
|
|
2016-06-08 07:25:08 +02:00
|
|
|
/**
|
|
|
|
* Get the auto size enable attribute
|
2016-10-07 11:15:46 +02:00
|
|
|
* @param img pointer to an image
|
2016-06-08 07:25:08 +02:00
|
|
|
* @return true: auto size is enabled, false: auto size is disabled
|
|
|
|
*/
|
2018-07-30 06:52:29 +02:00
|
|
|
bool lv_img_get_auto_size(const lv_obj_t * img)
|
2016-06-08 07:25:08 +02:00
|
|
|
{
|
2019-09-26 12:54:40 +02:00
|
|
|
LV_ASSERT_OBJ(img, LV_OBJX_NAME);
|
|
|
|
|
2017-10-20 10:17:02 +02:00
|
|
|
lv_img_ext_t * ext = lv_obj_get_ext_attr(img);
|
2016-06-08 07:25:08 +02:00
|
|
|
|
2016-10-07 11:15:46 +02:00
|
|
|
return ext->auto_size == 0 ? false : true;
|
2016-06-08 07:25:08 +02:00
|
|
|
}
|
|
|
|
|
2019-03-08 17:02:56 +03:30
|
|
|
/**
|
|
|
|
* Get the offset.x attribute of the img object.
|
|
|
|
* @param img pointer to an image
|
|
|
|
* @return offset.x value.
|
|
|
|
*/
|
2019-04-04 07:15:40 +02:00
|
|
|
lv_coord_t lv_img_get_offset_x(lv_obj_t * img)
|
2019-03-08 17:02:56 +03:30
|
|
|
{
|
2019-09-26 12:54:40 +02:00
|
|
|
LV_ASSERT_OBJ(img, LV_OBJX_NAME);
|
|
|
|
|
2019-03-08 17:02:56 +03:30
|
|
|
lv_img_ext_t * ext = lv_obj_get_ext_attr(img);
|
|
|
|
|
|
|
|
return ext->offset.x;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the offset.y attribute of the img object.
|
|
|
|
* @param img pointer to an image
|
|
|
|
* @return offset.y value.
|
|
|
|
*/
|
2019-04-04 07:15:40 +02:00
|
|
|
lv_coord_t lv_img_get_offset_y(lv_obj_t * img)
|
2019-03-08 17:02:56 +03:30
|
|
|
{
|
2019-09-26 12:54:40 +02:00
|
|
|
LV_ASSERT_OBJ(img, LV_OBJX_NAME);
|
|
|
|
|
2019-03-08 17:02:56 +03:30
|
|
|
lv_img_ext_t * ext = lv_obj_get_ext_attr(img);
|
|
|
|
|
|
|
|
return ext->offset.y;
|
|
|
|
}
|
|
|
|
|
2019-11-29 11:32:22 +08:00
|
|
|
/**
|
|
|
|
* Get the rotation center of the image.
|
|
|
|
* @param img pointer to an image object
|
|
|
|
* @param center rotation center of the image
|
|
|
|
*/
|
2020-02-26 19:48:27 +01:00
|
|
|
void lv_img_get_pivot(lv_obj_t * img, lv_point_t * pivot)
|
2019-11-29 11:32:22 +08:00
|
|
|
{
|
|
|
|
LV_ASSERT_OBJ(img, LV_OBJX_NAME);
|
|
|
|
|
|
|
|
lv_img_ext_t * ext = lv_obj_get_ext_attr(img);
|
|
|
|
|
2019-11-29 15:36:52 +01:00
|
|
|
*pivot = ext->pivot;
|
2019-11-29 11:32:22 +08:00
|
|
|
}
|
|
|
|
|
2019-11-03 16:21:58 +01:00
|
|
|
/**
|
|
|
|
* Get the rotation angle of the image.
|
|
|
|
* @param img pointer to an image object
|
|
|
|
* @return rotation angle in degree (0..359)
|
|
|
|
*/
|
|
|
|
uint16_t lv_img_get_angle(lv_obj_t * img)
|
|
|
|
{
|
|
|
|
LV_ASSERT_OBJ(img, LV_OBJX_NAME);
|
|
|
|
|
|
|
|
lv_img_ext_t * ext = lv_obj_get_ext_attr(img);
|
|
|
|
|
|
|
|
return ext->angle;
|
|
|
|
}
|
|
|
|
|
2019-11-08 22:43:58 +01:00
|
|
|
/**
|
|
|
|
* Get the zoom factor of the image.
|
|
|
|
* @param img pointer to an image object
|
|
|
|
* @return zoom factor (256: no zoom)
|
|
|
|
*/
|
|
|
|
uint16_t lv_img_get_zoom(lv_obj_t * img)
|
|
|
|
{
|
|
|
|
LV_ASSERT_OBJ(img, LV_OBJX_NAME);
|
|
|
|
|
|
|
|
lv_img_ext_t * ext = lv_obj_get_ext_attr(img);
|
|
|
|
|
|
|
|
return ext->zoom;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get whether the transformations (rotate, zoom) are anti-aliased or not
|
|
|
|
* @param img pointer to an image object
|
|
|
|
* @return true: anti-aliased; false: not anti-aliased
|
|
|
|
*/
|
2019-11-12 09:45:40 +01:00
|
|
|
bool lv_img_get_antialias(lv_obj_t * img)
|
2019-11-08 22:43:58 +01:00
|
|
|
{
|
|
|
|
LV_ASSERT_OBJ(img, LV_OBJX_NAME);
|
|
|
|
|
|
|
|
lv_img_ext_t * ext = lv_obj_get_ext_attr(img);
|
|
|
|
|
|
|
|
return ext->antialias ? true : false;
|
|
|
|
}
|
|
|
|
|
2016-06-08 07:25:08 +02:00
|
|
|
/**********************
|
|
|
|
* STATIC FUNCTIONS
|
|
|
|
**********************/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle the drawing related tasks of the images
|
2016-10-07 11:15:46 +02:00
|
|
|
* @param img pointer to an object
|
2019-09-06 19:53:39 +02:00
|
|
|
* @param clip_area the object will be drawn only in this area
|
2016-06-08 07:25:08 +02:00
|
|
|
* @param mode LV_DESIGN_COVER_CHK: only check if the object fully covers the 'mask_p' area
|
|
|
|
* (return 'true' if yes)
|
|
|
|
* LV_DESIGN_DRAW: draw the object (always return 'true')
|
2016-10-04 09:45:39 +02:00
|
|
|
* LV_DESIGN_DRAW_POST: drawing after every children are drawn
|
2019-09-06 19:53:39 +02:00
|
|
|
* @param return an element of `lv_design_res_t`
|
2016-06-08 07:25:08 +02:00
|
|
|
*/
|
2019-09-06 19:53:39 +02:00
|
|
|
static lv_design_res_t lv_img_design(lv_obj_t * img, const lv_area_t * clip_area, lv_design_mode_t mode)
|
2016-06-08 07:25:08 +02:00
|
|
|
{
|
2019-06-06 06:05:40 +02:00
|
|
|
lv_img_ext_t * ext = lv_obj_get_ext_attr(img);
|
2016-06-15 16:09:24 +02:00
|
|
|
|
2016-06-08 07:25:08 +02:00
|
|
|
if(mode == LV_DESIGN_COVER_CHK) {
|
2020-05-18 16:52:23 +02:00
|
|
|
if(lv_obj_get_style_clip_corner(img, LV_IMG_PART_MAIN)) return LV_DESIGN_RES_MASKED;
|
|
|
|
|
2020-05-21 11:27:52 +02:00
|
|
|
if(ext->src_type == LV_IMG_SRC_UNKNOWN || ext->src_type == LV_IMG_SRC_SYMBOL) return LV_DESIGN_RES_NOT_COVER;
|
2018-02-23 13:56:04 +01:00
|
|
|
|
2020-05-21 11:27:52 +02:00
|
|
|
/*Non true color format might have "holes"*/
|
2020-05-21 11:33:07 +02:00
|
|
|
if(ext->cf != LV_IMG_CF_TRUE_COLOR && ext->cf != LV_IMG_CF_RAW) return LV_DESIGN_RES_NOT_COVER;
|
2020-05-21 11:27:52 +02:00
|
|
|
|
|
|
|
int32_t angle_final = lv_obj_get_style_transform_angle(img, LV_IMG_PART_MAIN);
|
|
|
|
angle_final += ext->angle;
|
|
|
|
|
2020-08-11 10:34:04 +02:00
|
|
|
if(angle_final != 0) return LV_DESIGN_RES_NOT_COVER;
|
2020-05-18 16:52:23 +02:00
|
|
|
|
2020-05-21 11:27:52 +02:00
|
|
|
int32_t zoom_final = lv_obj_get_style_transform_zoom(img, LV_IMG_PART_MAIN);
|
|
|
|
zoom_final = (zoom_final * ext->zoom) >> 8;
|
|
|
|
|
2020-08-24 06:39:57 +02:00
|
|
|
if(zoom_final == LV_IMG_ZOOM_NONE) {
|
2020-05-21 11:27:52 +02:00
|
|
|
if(_lv_area_is_in(clip_area, &img->coords, 0) == false) return LV_DESIGN_RES_NOT_COVER;
|
2020-06-16 13:47:04 +02:00
|
|
|
}
|
|
|
|
else {
|
2020-05-21 11:27:52 +02:00
|
|
|
lv_area_t a;
|
|
|
|
_lv_img_buf_get_transformed_area(&a, lv_obj_get_width(img), lv_obj_get_height(img), 0, zoom_final, &ext->pivot);
|
|
|
|
a.x1 += img->coords.x1;
|
|
|
|
a.y1 += img->coords.y1;
|
|
|
|
a.x2 += img->coords.x1;
|
|
|
|
a.y2 += img->coords.y1;
|
|
|
|
|
|
|
|
if(_lv_area_is_in(clip_area, &a, 0) == false) return LV_DESIGN_RES_NOT_COVER;
|
2019-09-06 19:53:39 +02:00
|
|
|
}
|
2017-04-21 17:11:47 +02:00
|
|
|
|
2020-05-21 11:27:52 +02:00
|
|
|
if(lv_obj_get_style_image_opa(img, LV_IMG_PART_MAIN) != LV_OPA_COVER) return LV_DESIGN_RES_NOT_COVER;
|
2019-12-30 14:25:04 +01:00
|
|
|
|
2020-05-18 16:52:23 +02:00
|
|
|
return LV_DESIGN_RES_COVER;
|
2020-02-26 19:48:27 +01:00
|
|
|
}
|
|
|
|
else if(mode == LV_DESIGN_DRAW_MAIN) {
|
2017-01-10 08:36:12 +01:00
|
|
|
if(ext->h == 0 || ext->w == 0) return true;
|
2020-02-02 10:39:46 +01:00
|
|
|
|
|
|
|
lv_draw_rect_dsc_t bg_dsc;
|
|
|
|
lv_draw_rect_dsc_init(&bg_dsc);
|
|
|
|
lv_obj_init_draw_rect_dsc(img, LV_IMG_PART_MAIN, &bg_dsc);
|
|
|
|
|
|
|
|
/*If the border is drawn later disable loading its properties*/
|
2020-02-02 15:58:08 +01:00
|
|
|
if(lv_obj_get_style_border_post(img, LV_OBJ_PART_MAIN)) {
|
2020-02-02 10:39:46 +01:00
|
|
|
bg_dsc.border_opa = LV_OPA_TRANSP;
|
|
|
|
}
|
2020-05-12 15:00:58 +02:00
|
|
|
|
|
|
|
|
|
|
|
int32_t zoom_final = lv_obj_get_style_transform_zoom(img, LV_IMG_PART_MAIN);
|
|
|
|
zoom_final = (zoom_final * ext->zoom) >> 8;
|
|
|
|
|
|
|
|
int32_t angle_final = lv_obj_get_style_transform_angle(img, LV_IMG_PART_MAIN);
|
|
|
|
angle_final += ext->angle;
|
|
|
|
|
2020-08-24 09:50:05 +02:00
|
|
|
lv_coord_t obj_w = lv_obj_get_width(img);
|
|
|
|
lv_coord_t obj_h = lv_obj_get_height(img);
|
|
|
|
|
2020-02-02 10:39:46 +01:00
|
|
|
lv_area_t bg_coords;
|
2020-08-24 09:50:05 +02:00
|
|
|
_lv_img_buf_get_transformed_area(&bg_coords, obj_w, obj_h,
|
2020-05-18 16:57:23 +02:00
|
|
|
angle_final, zoom_final, &ext->pivot);
|
2020-08-24 09:50:05 +02:00
|
|
|
bg_coords.x1 += img->coords.x1;
|
|
|
|
bg_coords.y1 += img->coords.y1;
|
|
|
|
bg_coords.x2 += img->coords.x1;
|
|
|
|
bg_coords.y2 += img->coords.y1;
|
2020-02-02 15:58:08 +01:00
|
|
|
bg_coords.x1 -= lv_obj_get_style_pad_left(img, LV_IMG_PART_MAIN);
|
|
|
|
bg_coords.x2 += lv_obj_get_style_pad_right(img, LV_IMG_PART_MAIN);
|
|
|
|
bg_coords.y1 -= lv_obj_get_style_pad_top(img, LV_IMG_PART_MAIN);
|
|
|
|
bg_coords.y2 += lv_obj_get_style_pad_bottom(img, LV_IMG_PART_MAIN);
|
2020-02-02 10:39:46 +01:00
|
|
|
|
|
|
|
lv_draw_rect(&bg_coords, clip_area, &bg_dsc);
|
|
|
|
|
2020-08-10 06:17:03 +02:00
|
|
|
if(zoom_final == 0) return LV_DESIGN_RES_OK;
|
|
|
|
|
2020-02-02 15:58:08 +01:00
|
|
|
if(lv_obj_get_style_clip_corner(img, LV_OBJ_PART_MAIN)) {
|
2020-05-13 14:11:16 +02:00
|
|
|
lv_draw_mask_radius_param_t * mp = _lv_mem_buf_get(sizeof(lv_draw_mask_radius_param_t));
|
2020-02-02 10:39:46 +01:00
|
|
|
|
2020-02-02 15:58:08 +01:00
|
|
|
lv_coord_t r = lv_obj_get_style_radius(img, LV_OBJ_PART_MAIN);
|
2020-02-02 10:39:46 +01:00
|
|
|
|
|
|
|
lv_draw_mask_radius_init(mp, &bg_coords, r, false);
|
|
|
|
/*Add the mask and use `img+8` as custom id. Don't use `obj` directly because it might be used by the user*/
|
|
|
|
lv_draw_mask_add(mp, img + 8);
|
|
|
|
}
|
2018-02-23 13:56:04 +01:00
|
|
|
|
2018-06-19 09:49:58 +02:00
|
|
|
if(ext->src_type == LV_IMG_SRC_FILE || ext->src_type == LV_IMG_SRC_VARIABLE) {
|
2018-09-23 21:24:51 +02:00
|
|
|
LV_LOG_TRACE("lv_img_design: start to draw image");
|
2019-12-31 23:02:25 +01:00
|
|
|
|
|
|
|
lv_draw_img_dsc_t img_dsc;
|
|
|
|
lv_draw_img_dsc_init(&img_dsc);
|
|
|
|
lv_obj_init_draw_img_dsc(img, LV_IMG_PART_MAIN, &img_dsc);
|
2020-05-01 10:34:52 +02:00
|
|
|
|
2020-05-12 15:00:58 +02:00
|
|
|
img_dsc.zoom = zoom_final;
|
2020-05-01 10:34:52 +02:00
|
|
|
|
2020-05-06 09:27:38 +02:00
|
|
|
if(img_dsc.zoom == 0) return LV_DESIGN_RES_OK;
|
|
|
|
|
2020-05-18 16:57:23 +02:00
|
|
|
img_dsc.angle = angle_final;
|
2020-05-01 10:34:52 +02:00
|
|
|
|
2020-02-14 08:10:25 +01:00
|
|
|
img_dsc.pivot.x = ext->pivot.x;
|
|
|
|
img_dsc.pivot.y = ext->pivot.y;
|
2020-03-01 01:59:42 +01:00
|
|
|
img_dsc.antialias = ext->antialias;
|
2019-12-31 23:02:25 +01:00
|
|
|
|
2020-08-24 09:50:05 +02:00
|
|
|
lv_coord_t zoomed_src_w = (int32_t)((int32_t)ext->w * zoom_final) >> 8;
|
2020-08-25 11:54:12 +02:00
|
|
|
if(zoomed_src_w <= 0) return LV_DESIGN_RES_OK;
|
2020-08-24 09:50:05 +02:00
|
|
|
lv_coord_t zoomed_src_h = (int32_t)((int32_t)ext->h * zoom_final) >> 8;
|
2020-08-25 11:54:12 +02:00
|
|
|
if(zoomed_src_h <= 0) return LV_DESIGN_RES_OK;
|
2020-08-24 09:50:05 +02:00
|
|
|
lv_area_t zommed_coords;
|
|
|
|
lv_obj_get_coords(img, &zommed_coords);
|
|
|
|
|
|
|
|
zommed_coords.x1 += (int32_t)((int32_t)ext->offset.x * zoom_final) >> 8;
|
|
|
|
zommed_coords.y1 += (int32_t)((int32_t)ext->offset.y * zoom_final) >> 8;
|
|
|
|
zommed_coords.x2 = zommed_coords.x1 + ((int32_t)((int32_t)(obj_w - 1) * zoom_final) >> 8);
|
|
|
|
zommed_coords.y2 = zommed_coords.y1 + ((int32_t)((int32_t)(obj_h - 1) * zoom_final) >> 8);
|
|
|
|
|
|
|
|
if(zommed_coords.x1 > img->coords.x1) zommed_coords.x1 -= ext->w;
|
|
|
|
if(zommed_coords.y1 > img->coords.y1) zommed_coords.y1 -= ext->h;
|
|
|
|
|
|
|
|
lv_area_t clip_real;
|
|
|
|
_lv_img_buf_get_transformed_area(&clip_real, lv_obj_get_width(img), lv_obj_get_height(img), angle_final, zoom_final, &ext->pivot);
|
|
|
|
clip_real.x1 += img->coords.x1;
|
|
|
|
clip_real.x2 += img->coords.x1;
|
|
|
|
clip_real.y1 += img->coords.y1;
|
|
|
|
clip_real.y2 += img->coords.y1;
|
|
|
|
|
|
|
|
if(_lv_area_intersect(&clip_real, &clip_real, clip_area) == false) return LV_DESIGN_RES_OK;
|
|
|
|
|
|
|
|
lv_area_t coords_tmp;
|
|
|
|
coords_tmp.y1 = zommed_coords.y1;
|
|
|
|
coords_tmp.y2 = zommed_coords.y1 + ext->h - 1;
|
|
|
|
|
2020-08-25 11:54:12 +02:00
|
|
|
for(; coords_tmp.y1 < zommed_coords.y2; coords_tmp.y1 += zoomed_src_h, coords_tmp.y2 += zoomed_src_h) {
|
2020-08-24 09:50:05 +02:00
|
|
|
coords_tmp.x1 = zommed_coords.x1;
|
|
|
|
coords_tmp.x2 = zommed_coords.x1 + ext->w - 1;
|
2020-08-25 11:54:12 +02:00
|
|
|
for(; coords_tmp.x1 < zommed_coords.x2; coords_tmp.x1 += zoomed_src_w, coords_tmp.x2 += zoomed_src_w) {
|
2020-08-24 09:50:05 +02:00
|
|
|
lv_draw_img(&coords_tmp, &clip_real, ext->src, &img_dsc);
|
2018-02-23 13:56:04 +01:00
|
|
|
}
|
|
|
|
}
|
2020-02-26 19:48:27 +01:00
|
|
|
}
|
|
|
|
else if(ext->src_type == LV_IMG_SRC_SYMBOL) {
|
2018-09-23 21:24:51 +02:00
|
|
|
LV_LOG_TRACE("lv_img_design: start to draw symbol");
|
2019-12-31 23:02:25 +01:00
|
|
|
lv_draw_label_dsc_t label_dsc;
|
|
|
|
lv_draw_label_dsc_init(&label_dsc);
|
|
|
|
lv_obj_init_draw_label_dsc(img, LV_IMG_PART_MAIN, &label_dsc);
|
|
|
|
|
2020-02-13 06:56:14 +01:00
|
|
|
label_dsc.color = lv_obj_get_style_image_recolor(img, LV_IMG_PART_MAIN);
|
2020-08-24 09:50:05 +02:00
|
|
|
lv_draw_label(&img->coords, clip_area, &label_dsc, ext->src, NULL);
|
2020-02-26 19:48:27 +01:00
|
|
|
}
|
|
|
|
else {
|
2018-06-19 09:49:58 +02:00
|
|
|
/*Trigger the error handler of image drawer*/
|
2018-09-23 21:24:51 +02:00
|
|
|
LV_LOG_WARN("lv_img_design: image source type is unknown");
|
2019-12-31 23:02:25 +01:00
|
|
|
lv_draw_img(&img->coords, clip_area, NULL, NULL);
|
2018-06-19 09:49:58 +02:00
|
|
|
}
|
2020-02-26 19:48:27 +01:00
|
|
|
}
|
|
|
|
else if(mode == LV_DESIGN_DRAW_POST) {
|
2020-02-02 15:58:08 +01:00
|
|
|
if(lv_obj_get_style_clip_corner(img, LV_OBJ_PART_MAIN)) {
|
2020-02-02 10:39:46 +01:00
|
|
|
lv_draw_mask_radius_param_t * param = lv_draw_mask_remove_custom(img + 8);
|
2020-05-13 14:11:16 +02:00
|
|
|
_lv_mem_buf_release(param);
|
2020-02-02 10:39:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*If the border is drawn later disable loading other properties*/
|
2020-02-02 15:58:08 +01:00
|
|
|
if(lv_obj_get_style_border_post(img, LV_OBJ_PART_MAIN)) {
|
2020-08-10 06:17:03 +02:00
|
|
|
lv_draw_rect_dsc_t draw_dsc;
|
|
|
|
lv_draw_rect_dsc_init(&draw_dsc);
|
2020-02-02 10:39:46 +01:00
|
|
|
draw_dsc.bg_opa = LV_OPA_TRANSP;
|
|
|
|
draw_dsc.pattern_opa = LV_OPA_TRANSP;
|
|
|
|
draw_dsc.shadow_opa = LV_OPA_TRANSP;
|
|
|
|
lv_obj_init_draw_rect_dsc(img, LV_OBJ_PART_MAIN, &draw_dsc);
|
2020-08-10 06:17:03 +02:00
|
|
|
|
|
|
|
int32_t zoom_final = lv_obj_get_style_transform_zoom(img, LV_IMG_PART_MAIN);
|
|
|
|
zoom_final = (zoom_final * ext->zoom) >> 8;
|
|
|
|
|
|
|
|
int32_t angle_final = lv_obj_get_style_transform_angle(img, LV_IMG_PART_MAIN);
|
|
|
|
angle_final += ext->angle;
|
|
|
|
|
|
|
|
lv_area_t bg_coords;
|
|
|
|
_lv_img_buf_get_transformed_area(&bg_coords, lv_area_get_width(&img->coords), lv_area_get_height(&img->coords),
|
|
|
|
angle_final, zoom_final, &ext->pivot);
|
|
|
|
bg_coords.x1 += img->coords.x1;
|
|
|
|
bg_coords.y1 += img->coords.y1;
|
|
|
|
bg_coords.x2 += img->coords.x1;
|
|
|
|
bg_coords.y2 += img->coords.y1;
|
|
|
|
bg_coords.x1 -= lv_obj_get_style_pad_left(img, LV_IMG_PART_MAIN);
|
|
|
|
bg_coords.x2 += lv_obj_get_style_pad_right(img, LV_IMG_PART_MAIN);
|
|
|
|
bg_coords.y1 -= lv_obj_get_style_pad_top(img, LV_IMG_PART_MAIN);
|
|
|
|
bg_coords.y2 += lv_obj_get_style_pad_bottom(img, LV_IMG_PART_MAIN);
|
|
|
|
|
2020-02-02 10:39:46 +01:00
|
|
|
lv_draw_rect(&img->coords, clip_area, &draw_dsc);
|
|
|
|
}
|
2016-06-08 07:25:08 +02:00
|
|
|
}
|
2018-06-19 09:49:58 +02:00
|
|
|
|
2020-05-06 09:27:38 +02:00
|
|
|
return LV_DESIGN_RES_OK;
|
2016-06-08 07:25:08 +02:00
|
|
|
}
|
2017-01-16 12:30:22 +01:00
|
|
|
|
2017-11-13 16:11:05 +01:00
|
|
|
/**
|
|
|
|
* Signal function of the image
|
2018-03-01 12:21:49 +01:00
|
|
|
* @param img pointer to an image object
|
2017-11-13 16:11:05 +01:00
|
|
|
* @param sign a signal type from lv_signal_t enum
|
|
|
|
* @param param pointer to a signal specific variable
|
|
|
|
* @return LV_RES_OK: the object is not deleted in the function; LV_RES_INV: the object is deleted
|
|
|
|
*/
|
|
|
|
static lv_res_t lv_img_signal(lv_obj_t * img, lv_signal_t sign, void * param)
|
|
|
|
{
|
|
|
|
lv_res_t res;
|
2019-12-31 23:02:25 +01:00
|
|
|
if(sign == LV_SIGNAL_GET_STYLE) {
|
2020-01-08 21:31:05 +01:00
|
|
|
|
|
|
|
lv_get_style_info_t * info = param;
|
|
|
|
info->result = lv_img_get_style(img, info->part);
|
|
|
|
if(info->result != NULL) return LV_RES_OK;
|
|
|
|
else return ancestor_signal(img, sign, param);
|
2019-12-31 23:02:25 +01:00
|
|
|
}
|
2017-11-13 16:11:05 +01:00
|
|
|
|
|
|
|
/* Include the ancient signal function */
|
|
|
|
res = ancestor_signal(img, sign, param);
|
|
|
|
if(res != LV_RES_OK) return res;
|
|
|
|
|
2019-09-26 12:54:40 +02:00
|
|
|
if(sign == LV_SIGNAL_GET_TYPE) return lv_obj_handle_get_type_signal(param, LV_OBJX_NAME);
|
2019-09-26 10:51:54 +02:00
|
|
|
|
2017-11-13 16:11:05 +01:00
|
|
|
lv_img_ext_t * ext = lv_obj_get_ext_attr(img);
|
|
|
|
if(sign == LV_SIGNAL_CLEANUP) {
|
2018-02-23 13:56:04 +01:00
|
|
|
if(ext->src_type == LV_IMG_SRC_FILE || ext->src_type == LV_IMG_SRC_SYMBOL) {
|
|
|
|
lv_mem_free(ext->src);
|
2019-04-04 07:15:40 +02:00
|
|
|
ext->src = NULL;
|
2018-02-23 13:56:04 +01:00
|
|
|
ext->src_type = LV_IMG_SRC_UNKNOWN;
|
|
|
|
}
|
2020-02-26 19:48:27 +01:00
|
|
|
}
|
|
|
|
else if(sign == LV_SIGNAL_STYLE_CHG) {
|
2017-11-13 16:11:05 +01:00
|
|
|
/*Refresh the file name to refresh the symbol text size*/
|
2018-02-23 13:56:04 +01:00
|
|
|
if(ext->src_type == LV_IMG_SRC_SYMBOL) {
|
|
|
|
lv_img_set_src(img, ext->src);
|
2017-11-13 16:11:05 +01:00
|
|
|
}
|
2020-02-26 19:48:27 +01:00
|
|
|
}
|
|
|
|
else if(sign == LV_SIGNAL_REFR_EXT_DRAW_PAD) {
|
2020-05-01 10:34:52 +02:00
|
|
|
|
|
|
|
lv_style_int_t transf_zoom = lv_obj_get_style_transform_zoom(img, LV_IMG_PART_MAIN);
|
|
|
|
transf_zoom = (transf_zoom * ext->zoom) >> 8;
|
|
|
|
|
2020-05-01 20:48:16 +02:00
|
|
|
lv_style_int_t transf_angle = lv_obj_get_style_transform_angle(img, LV_IMG_PART_MAIN);
|
2020-05-01 10:34:52 +02:00
|
|
|
transf_angle += ext->angle;
|
|
|
|
|
2019-11-02 21:30:51 +01:00
|
|
|
/*If the image has angle provide enough room for the rotated corners */
|
2020-05-01 10:34:52 +02:00
|
|
|
if(transf_angle || transf_zoom != LV_IMG_ZOOM_NONE) {
|
2020-02-14 08:10:25 +01:00
|
|
|
lv_area_t a;
|
2020-08-24 09:50:05 +02:00
|
|
|
lv_coord_t w = lv_obj_get_width(img);
|
|
|
|
lv_coord_t h = lv_obj_get_height(img);
|
|
|
|
_lv_img_buf_get_transformed_area(&a, w, h, transf_angle, transf_zoom, &ext->pivot);
|
2020-05-12 15:00:58 +02:00
|
|
|
lv_coord_t pad_ori = img->ext_draw_pad;
|
|
|
|
img->ext_draw_pad = LV_MATH_MAX(img->ext_draw_pad, pad_ori - a.x1);
|
|
|
|
img->ext_draw_pad = LV_MATH_MAX(img->ext_draw_pad, pad_ori - a.y1);
|
2020-08-24 09:50:05 +02:00
|
|
|
img->ext_draw_pad = LV_MATH_MAX(img->ext_draw_pad, pad_ori + a.x2 - w);
|
|
|
|
img->ext_draw_pad = LV_MATH_MAX(img->ext_draw_pad, pad_ori + a.y2 - h);
|
2019-11-02 21:30:51 +01:00
|
|
|
}
|
2020-02-02 10:39:46 +01:00
|
|
|
|
|
|
|
/*Handle the padding of the background*/
|
2020-02-02 15:58:08 +01:00
|
|
|
lv_style_int_t left = lv_obj_get_style_pad_left(img, LV_IMG_PART_MAIN);
|
|
|
|
lv_style_int_t right = lv_obj_get_style_pad_right(img, LV_IMG_PART_MAIN);
|
|
|
|
lv_style_int_t top = lv_obj_get_style_pad_top(img, LV_IMG_PART_MAIN);
|
|
|
|
lv_style_int_t bottom = lv_obj_get_style_pad_bottom(img, LV_IMG_PART_MAIN);
|
2020-02-02 10:39:46 +01:00
|
|
|
|
|
|
|
img->ext_draw_pad = LV_MATH_MAX(img->ext_draw_pad, left);
|
|
|
|
img->ext_draw_pad = LV_MATH_MAX(img->ext_draw_pad, right);
|
|
|
|
img->ext_draw_pad = LV_MATH_MAX(img->ext_draw_pad, top);
|
|
|
|
img->ext_draw_pad = LV_MATH_MAX(img->ext_draw_pad, bottom);
|
|
|
|
|
|
|
|
|
2020-02-26 19:48:27 +01:00
|
|
|
}
|
|
|
|
else if(sign == LV_SIGNAL_HIT_TEST) {
|
|
|
|
lv_hit_test_info_t * info = param;
|
2020-07-03 14:48:54 +02:00
|
|
|
lv_style_int_t zoom = lv_obj_get_style_transform_zoom(img, LV_IMG_PART_MAIN);
|
|
|
|
zoom = (zoom * ext->zoom) >> 8;
|
2020-01-04 08:48:51 -05:00
|
|
|
|
2020-07-03 14:48:54 +02:00
|
|
|
lv_style_int_t angle = lv_obj_get_style_transform_angle(img, LV_IMG_PART_MAIN);
|
|
|
|
angle += ext->angle;
|
|
|
|
|
|
|
|
/* If the object is exactly image sized (not cropped, not mosaic) and transformed
|
|
|
|
* perform hit test on it's transformed area */
|
|
|
|
if(ext->w == lv_obj_get_width(img) && ext->h == lv_obj_get_height(img) &&
|
|
|
|
(zoom != LV_IMG_ZOOM_NONE || angle != 0 || ext->pivot.x != ext->w / 2 || ext->pivot.y != ext->h / 2)) {
|
2020-01-04 08:48:51 -05:00
|
|
|
|
2020-08-24 09:50:05 +02:00
|
|
|
lv_coord_t w = lv_obj_get_width(img);
|
|
|
|
lv_coord_t h = lv_obj_get_height(img);
|
2020-01-04 08:48:51 -05:00
|
|
|
lv_area_t coords;
|
2020-08-24 09:50:05 +02:00
|
|
|
_lv_img_buf_get_transformed_area(&coords, w, h, angle, zoom, &ext->pivot);
|
2020-07-03 14:48:54 +02:00
|
|
|
coords.x1 += img->coords.x1;
|
|
|
|
coords.y1 += img->coords.y1;
|
|
|
|
coords.x2 += img->coords.x1;
|
|
|
|
coords.y2 += img->coords.y1;
|
|
|
|
|
2020-05-13 14:11:16 +02:00
|
|
|
info->result = _lv_area_is_point_on(&coords, info->point, 0);
|
2020-02-26 19:48:27 +01:00
|
|
|
}
|
|
|
|
else
|
2020-01-04 08:48:51 -05:00
|
|
|
info->result = lv_obj_is_point_on_coords(img, info->point);
|
2018-02-28 15:37:41 +01:00
|
|
|
}
|
2017-11-13 16:11:05 +01:00
|
|
|
|
2017-11-15 15:50:33 +01:00
|
|
|
return res;
|
2017-11-13 16:11:05 +01:00
|
|
|
}
|
|
|
|
|
2019-12-31 23:02:25 +01:00
|
|
|
|
2020-01-16 14:26:36 +01:00
|
|
|
static lv_style_list_t * lv_img_get_style(lv_obj_t * img, uint8_t type)
|
2019-12-31 23:02:25 +01:00
|
|
|
{
|
2020-01-16 14:26:36 +01:00
|
|
|
lv_style_list_t * style_dsc_p;
|
2019-12-31 23:02:25 +01:00
|
|
|
switch(type) {
|
2020-02-26 19:48:27 +01:00
|
|
|
case LV_IMG_PART_MAIN:
|
|
|
|
style_dsc_p = &img->style_list;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
style_dsc_p = NULL;
|
2019-12-31 23:02:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return style_dsc_p;
|
|
|
|
}
|
|
|
|
|
2016-06-08 07:25:08 +02:00
|
|
|
#endif
|