basics image decoder interface impemented (wip)
This commit is contained in:
@@ -38,36 +38,6 @@ extern "C" {
|
||||
* TYPEDEFS
|
||||
**********************/
|
||||
|
||||
/* Image header it is compatible with
|
||||
* the result image converter utility*/
|
||||
typedef struct
|
||||
{
|
||||
union {
|
||||
struct {
|
||||
uint32_t chroma_keyed:1; /*1: The image contains transparent pixels with LV_COLOR_TRANSP color*/
|
||||
uint32_t alpha_byte :1; /*Every pixel is extended with a 8 bit alpha channel*/
|
||||
uint32_t format :6; /*See: lv_img_px_format*/
|
||||
uint32_t w:12; /*Width of the image map*/
|
||||
uint32_t h:12; /*Height of the image map*/
|
||||
} header;
|
||||
uint8_t src_type;
|
||||
};
|
||||
|
||||
union {
|
||||
const uint8_t * pixel_map; /*For internal images (c arrays) pointer to the pixels array*/
|
||||
uint8_t first_pixel; /*For external images (binary) the first byte of the pixels (just for convenient)*/
|
||||
};
|
||||
} lv_img_t;
|
||||
|
||||
typedef enum {
|
||||
LV_IMG_FORMAT_UNKOWN = 0,
|
||||
LV_IMG_FORMAT_INTERNAL_RAW, /*'lv_img_t' variable compiled with the code*/
|
||||
LV_IMG_FORMAT_FILE_RAW_RGB332, /*8 bit*/
|
||||
LV_IMG_FORMAT_FILE_RAW_RGB565, /*16 bit*/
|
||||
LV_IMG_FORMAT_FILE_RAW_RGB888, /*24 bit (stored on 32 bit)*/
|
||||
} lv_img_format_t;
|
||||
|
||||
|
||||
typedef enum {
|
||||
LV_IMG_SRC_VARIABLE,
|
||||
LV_IMG_SRC_FILE,
|
||||
|
||||
@@ -20,6 +20,9 @@
|
||||
/**********************
|
||||
* STATIC PROTOTYPES
|
||||
**********************/
|
||||
static bool lv_img_draw_built_in(const lv_area_t * coords, const lv_area_t * mask,
|
||||
const void * src, const lv_style_t * style, lv_opa_t opa_scale);
|
||||
static bool lv_img_dsc_get_info_built_in(const char * src, lv_img_header_t * header, const lv_style_t * style);
|
||||
|
||||
/**********************
|
||||
* STATIC VARIABLES
|
||||
@@ -44,55 +47,210 @@
|
||||
void lv_draw_img(const lv_area_t * coords, const lv_area_t * mask,
|
||||
const void * src, const lv_style_t * style, lv_opa_t opa_scale)
|
||||
{
|
||||
|
||||
if(src == NULL) {
|
||||
lv_draw_rect(coords, mask, &lv_style_plain, LV_OPA_COVER);
|
||||
lv_draw_label(coords, mask, &lv_style_plain, LV_OPA_COVER, "No\ndata", LV_TXT_FLAG_NONE, NULL);
|
||||
return;
|
||||
}
|
||||
|
||||
lv_img_draw_built_in(coords, mask, src, style, opa_scale);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @param src
|
||||
* @param header
|
||||
* @param style
|
||||
* @return
|
||||
*/
|
||||
bool lv_img_dsc_get_info(const char * src, lv_img_header_t * header, const lv_style_t * style)
|
||||
{
|
||||
header->always_zero = 0;
|
||||
|
||||
return lv_img_dsc_get_info_built_in(src, header, style);
|
||||
|
||||
}
|
||||
|
||||
uint8_t lv_img_color_format_get_px_size(lv_img_color_format_t cf)
|
||||
{
|
||||
switch(cf) {
|
||||
case LV_IMG_FORMAT_UNKOWN:
|
||||
case LV_IMG_FORMAT_RAW:
|
||||
return 0;
|
||||
case LV_IMG_FORMAT_TRUE_COLOR:
|
||||
case LV_IMG_FORMAT_TRUE_COLOR_CHROMA_KEYED:
|
||||
return LV_COLOR_SIZE;
|
||||
case LV_IMG_FORMAT_TRUE_COLOR_ALPHA:
|
||||
#if LV_COLOR_DEPTH != 24
|
||||
return LV_COLOR_SIZE;
|
||||
#else
|
||||
return LV_COLOR_SIZE + 1;
|
||||
#endif
|
||||
case LV_IMG_FORMAT_INDEXED_1BIT:
|
||||
case LV_IMG_FORMAT_ALPHA_1BIT:
|
||||
return 1;
|
||||
|
||||
case LV_IMG_FORMAT_INDEXED_2BIT:
|
||||
case LV_IMG_FORMAT_ALPHA_2BIT:
|
||||
case LV_IMG_FORMAT_INDEXED_ALPHA_2BIT:
|
||||
return 2;
|
||||
|
||||
case LV_IMG_FORMAT_INDEXED_4BIT:
|
||||
case LV_IMG_FORMAT_ALPHA_4BIT:
|
||||
case LV_IMG_FORMAT_INDEXED_ALPHA_4BIT:
|
||||
return 4;
|
||||
|
||||
case LV_IMG_FORMAT_INDEXED_8BIT:
|
||||
case LV_IMG_FORMAT_ALPHA_8BIT:
|
||||
case LV_IMG_FORMAT_INDEXED_ALPHA_8BIT:
|
||||
return 8;
|
||||
|
||||
case LV_IMG_FORMAT_INDEXED_ALPHA_16BIT:
|
||||
return 16;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool lv_img_color_format_is_chroma_key(lv_img_color_format_t cf)
|
||||
{
|
||||
switch(cf) {
|
||||
case LV_IMG_FORMAT_TRUE_COLOR_CHROMA_KEYED:
|
||||
case LV_IMG_FORMAT_INDEXED_1BIT:
|
||||
case LV_IMG_FORMAT_INDEXED_2BIT:
|
||||
case LV_IMG_FORMAT_INDEXED_4BIT:
|
||||
case LV_IMG_FORMAT_INDEXED_8BIT:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
bool lv_img_color_format_has_alpha(lv_img_color_format_t cf)
|
||||
{
|
||||
switch(cf) {
|
||||
case LV_IMG_FORMAT_TRUE_COLOR_ALPHA:
|
||||
case LV_IMG_FORMAT_ALPHA_1BIT:
|
||||
case LV_IMG_FORMAT_ALPHA_2BIT:
|
||||
case LV_IMG_FORMAT_ALPHA_4BIT:
|
||||
case LV_IMG_FORMAT_ALPHA_8BIT:
|
||||
case LV_IMG_FORMAT_INDEXED_ALPHA_2BIT:
|
||||
case LV_IMG_FORMAT_INDEXED_ALPHA_4BIT:
|
||||
case LV_IMG_FORMAT_INDEXED_ALPHA_8BIT:
|
||||
case LV_IMG_FORMAT_INDEXED_ALPHA_16BIT:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the type of an image source
|
||||
* @param src pointer to an image source:
|
||||
* - pointer to an 'lv_img_t' variable (image stored internally and compiled into the code)
|
||||
* - a path to a file (e.g. "S:/folder/image.bin")
|
||||
* - or a symbol (e.g. SYMBOL_CLOSE)
|
||||
* @return type of the image source LV_IMG_SRC_VARIABLE/FILE/SYMBOL/UNKOWN
|
||||
*/
|
||||
lv_img_src_t lv_img_src_get_type(const void * src)
|
||||
{
|
||||
if(src == NULL) return LV_IMG_SRC_UNKNOWN;
|
||||
const uint8_t * u8_p = src;
|
||||
|
||||
/*The first byte shows the type of the image source*/
|
||||
if(u8_p[0] >= 0x20 && u8_p[0] <= 0x7F) return LV_IMG_SRC_FILE; /*If it's an ASCII character then it's file name*/
|
||||
else if(u8_p[0] >= 0x80) return LV_IMG_SRC_SYMBOL; /*Symbols begins after 0x7F*/
|
||||
else return LV_IMG_SRC_VARIABLE; /*`lv_img_dsc_t` is design to the first byte < 0x20*/
|
||||
|
||||
return LV_IMG_SRC_UNKNOWN;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**********************
|
||||
* STATIC FUNCTIONS
|
||||
**********************/
|
||||
|
||||
static bool lv_img_dsc_get_info_built_in(const char * src, lv_img_header_t * header, const lv_style_t * style)
|
||||
{
|
||||
lv_img_src_t src_type = lv_img_src_get_type(src);
|
||||
if(src_type == LV_IMG_SRC_VARIABLE) {
|
||||
header->color_format =
|
||||
header->w = ((lv_img_dsc_t *)src)->header.w;
|
||||
header->h = ((lv_img_dsc_t *)src)->header.h;
|
||||
header->color_format = ((lv_img_dsc_t *)src)->header.color_format;
|
||||
}
|
||||
#if USE_LV_FILESYSTEM
|
||||
else if(src_type == LV_IMG_SRC_FILE) {
|
||||
lv_fs_file_t file;
|
||||
lv_fs_res_t res;
|
||||
uint32_t rn;
|
||||
res = lv_fs_open(&file, src, LV_FS_MODE_RD);
|
||||
if(res == LV_FS_RES_OK) {
|
||||
res = lv_fs_read(&file, header, sizeof(lv_img_header_t), &rn);
|
||||
}
|
||||
|
||||
/*Create a dummy header on fs error*/
|
||||
if(res != LV_FS_RES_OK || rn != sizeof(lv_img_header_t)) {
|
||||
header->w = LV_DPI;
|
||||
header->h = LV_DPI;
|
||||
header->color_format = LV_IMG_FORMAT_UNKOWN;
|
||||
}
|
||||
|
||||
lv_fs_close(&file);
|
||||
}
|
||||
#endif
|
||||
else if(src_type == LV_IMG_SRC_SYMBOL) {
|
||||
lv_point_t size;
|
||||
lv_txt_get_size(&size, src, style->text.font, style->text.letter_space, style->text.line_space, LV_COORD_MAX, LV_TXT_FLAG_NONE);
|
||||
header->w = size.x;
|
||||
header->h = size.y;
|
||||
header->color_format = LV_IMG_FORMAT_ALPHA_1BIT; /*Symbols always have transparent parts, Important because of cover check in the design function*/
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
static bool lv_img_draw_built_in(const lv_area_t * coords, const lv_area_t * mask,
|
||||
const void * src, const lv_style_t * style, lv_opa_t opa_scale)
|
||||
{
|
||||
lv_opa_t opa = opa_scale == LV_OPA_COVER ? style->image.opa : (uint16_t)((uint16_t) style->image.opa * opa_scale) >> 8;
|
||||
|
||||
const uint8_t * u8_p = (uint8_t *) src;
|
||||
if(u8_p[0] >= 'A' && u8_p[0] <= 'Z') { /*It will be a path of a file*/
|
||||
lv_img_src_t src_type = lv_img_src_get_type(src);
|
||||
|
||||
if(src_type == LV_IMG_SRC_FILE) { /*It will be a path to a file*/
|
||||
#if USE_LV_FILESYSTEM
|
||||
lv_fs_file_t file;
|
||||
lv_fs_res_t res = lv_fs_open(&file, src, LV_FS_MODE_RD);
|
||||
if(res == LV_FS_RES_OK) {
|
||||
lv_img_t img_data;
|
||||
uint32_t br;
|
||||
res = lv_fs_read(&file, &img_data, sizeof(lv_img_t), &br);
|
||||
if(res != LV_FS_RES_OK ) return false;
|
||||
|
||||
lv_area_t mask_com; /*Common area of mask and cords*/
|
||||
lv_img_header_t header;
|
||||
uint32_t br;
|
||||
res = lv_fs_read(&file, &header, sizeof(header), &br);
|
||||
|
||||
lv_area_t mask_com; /*Common area of mask and cords. Only these pixels are required now.*/
|
||||
bool union_ok;
|
||||
union_ok = lv_area_intersect(&mask_com, mask, coords);
|
||||
if(union_ok == false) {
|
||||
lv_fs_close(&file);
|
||||
return;
|
||||
}
|
||||
|
||||
uint8_t px_size = 0;
|
||||
switch(img_data.header.format) {
|
||||
case LV_IMG_FORMAT_FILE_RAW_RGB332:
|
||||
px_size = 1;
|
||||
break;
|
||||
case LV_IMG_FORMAT_FILE_RAW_RGB565:
|
||||
px_size = 2;
|
||||
break;
|
||||
case LV_IMG_FORMAT_FILE_RAW_RGB888:
|
||||
px_size = 4;
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
|
||||
if(img_data.header.alpha_byte) { /*Correction with the alpha byte*/
|
||||
px_size++;
|
||||
if(img_data.header.format == LV_IMG_FORMAT_FILE_RAW_RGB888) px_size--; /*Stored in the 4 byte anyway*/
|
||||
return true; /*Out of mask. There is nothing to draw so the image is drawn successfully.*/
|
||||
}
|
||||
|
||||
uint8_t px_size = lv_img_color_format_get_px_size(header.color_format);
|
||||
if(px_size == 0) return false;
|
||||
|
||||
/* Move the file pointer to the start address according to mask*/
|
||||
uint32_t start_offset = sizeof(img_data.header);
|
||||
uint32_t start_offset = sizeof(lv_img_header_t);
|
||||
start_offset += (lv_area_get_width(coords)) * (mask_com.y1 - coords->y1) * px_size; /*First row*/
|
||||
start_offset += (mask_com.x1 - coords->x1) * px_size; /*First col*/
|
||||
lv_fs_seek(&file, start_offset);
|
||||
@@ -116,10 +274,14 @@ void lv_draw_img(const lv_area_t * coords, const lv_area_t * mask,
|
||||
uint8_t buf[LV_VER_RES * ((LV_COLOR_DEPTH >> 8) + 1)];
|
||||
# endif
|
||||
#endif
|
||||
|
||||
bool chroma_keyed = lv_img_color_format_is_chroma_key(header.color_format);
|
||||
bool alpha_byte = lv_img_color_format_has_alpha(header.color_format);
|
||||
|
||||
for(row = mask_com.y1; row <= mask_com.y2; row ++) {
|
||||
res = lv_fs_read(&file, buf, useful_data, &br);
|
||||
|
||||
map_fp(&line, &mask_com, (uint8_t *)buf, opa, img_data.header.chroma_keyed, img_data.header.alpha_byte,
|
||||
map_fp(&line, &mask_com, (uint8_t *)buf, opa, chroma_keyed, alpha_byte,
|
||||
style->image.color, style->image.intense);
|
||||
|
||||
lv_fs_tell(&file, &act_pos);
|
||||
@@ -129,26 +291,19 @@ void lv_draw_img(const lv_area_t * coords, const lv_area_t * mask,
|
||||
}
|
||||
|
||||
lv_fs_close(&file);
|
||||
|
||||
if(res != LV_FS_RES_OK) {
|
||||
lv_draw_rect(coords, mask, &lv_style_plain, LV_OPA_COVER);
|
||||
lv_draw_label(coords, mask, &lv_style_plain, LV_OPA_COVER, "No data", LV_TXT_FLAG_NONE, NULL);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
} else {
|
||||
const lv_img_t * img_var = src;
|
||||
const lv_img_dsc_t * img_var = src;
|
||||
lv_area_t mask_com; /*Common area of mask and coords*/
|
||||
bool union_ok;
|
||||
union_ok = lv_area_intersect(&mask_com, mask, coords);
|
||||
if(union_ok == false) {
|
||||
return; /*Out of mask*/
|
||||
return true; /*Out of mask. There is nothing to draw so the image is drawn successfully.*/
|
||||
}
|
||||
|
||||
map_fp(coords, mask, img_var->pixel_map, opa, img_var->header.chroma_keyed, img_var->header.alpha_byte, style->image.color, style->image.intense);
|
||||
}
|
||||
}
|
||||
bool chroma_keyed = lv_img_color_format_is_chroma_key(img_var->header.color_format);
|
||||
bool alpha_byte = lv_img_color_format_has_alpha(img_var->header.color_format);
|
||||
|
||||
/**********************
|
||||
* STATIC FUNCTIONS
|
||||
**********************/
|
||||
map_fp(coords, mask, img_var->data, opa, chroma_keyed, alpha_byte, style->image.color, style->image.intense);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,6 +22,61 @@ extern "C" {
|
||||
/**********************
|
||||
* TYPEDEFS
|
||||
**********************/
|
||||
struct _lv_img_t;
|
||||
|
||||
typedef struct {
|
||||
|
||||
/* The first 8 bit is very important to distinguish the different source types.
|
||||
* For more info see `lv_img_get_src_type()` in lv_img.c */
|
||||
uint32_t color_format :5; /*See: lv_img_px_format*/
|
||||
uint32_t always_zero :3; /*It the upper bits of the first byte*/
|
||||
|
||||
uint32_t compression :2;
|
||||
|
||||
uint32_t w:11; /*Width of the image map*/
|
||||
uint32_t h:11; /*Height of the image map*/
|
||||
}lv_img_header_t;
|
||||
|
||||
|
||||
typedef enum {
|
||||
LV_IMG_COMPRESSION_NONE,
|
||||
LV_IMG_COMPRESSION_RLE, /*Run length encoded*/
|
||||
LV_IMG_COMPRESSION_RESERVED1,
|
||||
LV_IMG_COMPRESSION_RESERVED2
|
||||
}lv_img_compression_t;
|
||||
|
||||
typedef enum {
|
||||
LV_IMG_FORMAT_UNKOWN = 0,
|
||||
|
||||
LV_IMG_FORMAT_RAW, /*Contains the file's as it is. Needs custom decoder function*/
|
||||
|
||||
LV_IMG_FORMAT_TRUE_COLOR, /*Color format and depth should match with LV_COLOR settings*/
|
||||
LV_IMG_FORMAT_TRUE_COLOR_ALPHA, /*Same as `LV_IMG_FORMAT_TRUE_COLOR` but every pixel has an alpha byte*/
|
||||
LV_IMG_FORMAT_TRUE_COLOR_CHROMA_KEYED, /*Same as `LV_IMG_FORMAT_TRUE_COLOR` but LV_COLOR_TRANSP pixels will be transparent*/
|
||||
|
||||
LV_IMG_FORMAT_INDEXED_1BIT, /*Can have 2 different colors in a palette (always chroma keyed)*/
|
||||
LV_IMG_FORMAT_INDEXED_2BIT, /*Can have 4 different colors in a palette (always chroma keyed)*/
|
||||
LV_IMG_FORMAT_INDEXED_4BIT, /*Can have 16 different colors in a palette (always chroma keyed)*/
|
||||
LV_IMG_FORMAT_INDEXED_8BIT, /*Can have 256 different colors in a palette (always chroma keyed)*/
|
||||
|
||||
LV_IMG_FORMAT_ALPHA_1BIT, /*Can have one color and it can be drawn or not*/
|
||||
LV_IMG_FORMAT_ALPHA_2BIT, /*Can have one color but 4 different alpha value*/
|
||||
LV_IMG_FORMAT_ALPHA_4BIT, /*Can have one color but 16 different alpha value*/
|
||||
LV_IMG_FORMAT_ALPHA_8BIT, /*Can have one color but 256 different alpha value*/
|
||||
|
||||
LV_IMG_FORMAT_INDEXED_ALPHA_2BIT, /*Can have 2 different colors which are drawn or not*/
|
||||
LV_IMG_FORMAT_INDEXED_ALPHA_4BIT, /*Can have 4 different colors but 4 different alpha value*/
|
||||
LV_IMG_FORMAT_INDEXED_ALPHA_8BIT, /*Can have 16 different colors but 16 different alpha value*/
|
||||
LV_IMG_FORMAT_INDEXED_ALPHA_16BIT, /*Can have 256 different colors but 256 different alpha value*/
|
||||
} lv_img_color_format_t;
|
||||
|
||||
/* Image header it is compatible with
|
||||
* the result image converter utility*/
|
||||
typedef struct
|
||||
{
|
||||
lv_img_header_t header;
|
||||
const uint8_t * data;
|
||||
} lv_img_dsc_t;
|
||||
|
||||
/**********************
|
||||
* GLOBAL PROTOTYPES
|
||||
@@ -38,6 +93,27 @@ extern "C" {
|
||||
void lv_draw_img(const lv_area_t * coords, const lv_area_t * mask,
|
||||
const void * src, const lv_style_t * style, lv_opa_t opa_scale);
|
||||
|
||||
|
||||
|
||||
bool lv_img_dsc_get_info(const char * src, lv_img_header_t * header, const lv_style_t * style);
|
||||
|
||||
uint8_t lv_img_color_format_get_px_size(lv_img_color_format_t cf);
|
||||
|
||||
bool lv_img_color_format_is_chroma_key(lv_img_color_format_t cf);
|
||||
|
||||
bool lv_img_color_format_has_alpha(lv_img_color_format_t cf);
|
||||
|
||||
/**
|
||||
* Get the type of an image source
|
||||
* @param src pointer to an image source:
|
||||
* - pointer to an 'lv_img_t' variable (image stored internally and compiled into the code)
|
||||
* - a path to a file (e.g. "S:/folder/image.bin")
|
||||
* - or a symbol (e.g. SYMBOL_CLOSE)
|
||||
* @return type of the image source LV_IMG_SRC_VARIABLE/FILE/SYMBOL/UNKOWN
|
||||
*/
|
||||
lv_img_src_t lv_img_get_src_type(const void * src);
|
||||
|
||||
|
||||
/**********************
|
||||
* MACROS
|
||||
**********************/
|
||||
|
||||
@@ -62,6 +62,9 @@ static void sw_color_fill(lv_area_t * mem_area, lv_color_t * mem, const lv_area_
|
||||
*/
|
||||
void lv_vpx(lv_coord_t x, lv_coord_t y, const lv_area_t * mask_p, lv_color_t color, lv_opa_t opa)
|
||||
{
|
||||
if(opa < LV_OPA_MIN) return;
|
||||
if(opa > LV_OPA_MAX) opa = LV_OPA_COVER;
|
||||
|
||||
lv_vdb_t * vdb_p = lv_vdb_get();
|
||||
|
||||
/*Pixel out of the mask*/
|
||||
@@ -100,6 +103,10 @@ void lv_vpx(lv_coord_t x, lv_coord_t y, const lv_area_t * mask_p, lv_color_t col
|
||||
void lv_vfill(const lv_area_t * cords_p, const lv_area_t * mask_p,
|
||||
lv_color_t color, lv_opa_t opa)
|
||||
{
|
||||
|
||||
if(opa < LV_OPA_MIN) return;
|
||||
if(opa > LV_OPA_MAX) opa = LV_OPA_COVER;
|
||||
|
||||
lv_area_t res_a;
|
||||
bool union_ok;
|
||||
lv_vdb_t * vdb_p = lv_vdb_get();
|
||||
@@ -220,6 +227,9 @@ void lv_vletter(const lv_point_t * pos_p, const lv_area_t * mask_p,
|
||||
204, 221, 238, 255
|
||||
};
|
||||
|
||||
if(opa < LV_OPA_MIN) return;
|
||||
if(opa > LV_OPA_MAX) opa = LV_OPA_COVER;
|
||||
|
||||
if(font_p == NULL) {
|
||||
LV_LOG_WARN("Font: character's bitmap not found");
|
||||
return;
|
||||
@@ -357,6 +367,9 @@ void lv_vmap(const lv_area_t * cords_p, const lv_area_t * mask_p,
|
||||
lv_color_t recolor, lv_opa_t recolor_opa)
|
||||
{
|
||||
|
||||
if(opa < LV_OPA_MIN) return;
|
||||
if(opa > LV_OPA_MAX) opa = LV_OPA_COVER;
|
||||
|
||||
lv_area_t masked_a;
|
||||
bool union_ok;
|
||||
lv_vdb_t * vdb_p = lv_vdb_get();
|
||||
|
||||
@@ -57,6 +57,9 @@ extern "C" {
|
||||
#define LV_OPA_100 255
|
||||
#define LV_OPA_COVER 255
|
||||
|
||||
#define LV_OPA_MIN 0 /*Opacities below this will be transparent*/
|
||||
#define LV_OPA_MAX 255 /*Opacities above this will fully cover*/
|
||||
|
||||
#if LV_COLOR_DEPTH == 1
|
||||
#define LV_COLOR_SIZE 8
|
||||
#elif LV_COLOR_DEPTH == 8
|
||||
|
||||
103
lv_objx/lv_img.c
103
lv_objx/lv_img.c
@@ -72,10 +72,9 @@ lv_obj_t * lv_img_create(lv_obj_t * par, const lv_obj_t * copy)
|
||||
|
||||
ext->src = NULL;
|
||||
ext->src_type = LV_IMG_SRC_UNKNOWN;
|
||||
ext->cf = LV_IMG_FORMAT_UNKOWN;
|
||||
ext->w = lv_obj_get_width(new_img);
|
||||
ext->h = lv_obj_get_height(new_img);
|
||||
ext->chroma_keyed = 0;
|
||||
ext->alpha_byte = 0;
|
||||
ext->auto_size = 1;
|
||||
|
||||
/*Init the new object*/
|
||||
@@ -118,7 +117,7 @@ lv_obj_t * lv_img_create(lv_obj_t * par, const lv_obj_t * copy)
|
||||
*/
|
||||
void lv_img_set_src(lv_obj_t * img, const void * src_img)
|
||||
{
|
||||
lv_img_src_t src_type = lv_img_get_src_type(src_img);
|
||||
lv_img_src_t src_type = lv_img_src_get_type(src_img);
|
||||
lv_img_ext_t * ext = lv_obj_get_ext_attr(img);
|
||||
|
||||
|
||||
@@ -127,6 +126,7 @@ void lv_img_set_src(lv_obj_t * img, const void * src_img)
|
||||
#endif
|
||||
|
||||
|
||||
/*If the new source type is unknown free the memories of the old source*/
|
||||
if(src_type == LV_IMG_SRC_UNKNOWN) {
|
||||
if(ext->src_type == LV_IMG_SRC_SYMBOL || ext->src_type == LV_IMG_SRC_FILE) {
|
||||
lv_mem_free(ext->src);
|
||||
@@ -136,72 +136,29 @@ void lv_img_set_src(lv_obj_t * img, const void * src_img)
|
||||
return;
|
||||
}
|
||||
|
||||
ext->src_type = src_type;
|
||||
lv_img_header_t header;
|
||||
lv_img_dsc_get_info(src_img, &header, lv_img_get_style(img));
|
||||
|
||||
/*Save the source*/
|
||||
if(src_type == LV_IMG_SRC_VARIABLE) {
|
||||
ext->src = src_img;
|
||||
ext->w = ((lv_img_t *)src_img)->header.w;
|
||||
ext->h = ((lv_img_t *)src_img)->header.h;
|
||||
ext->chroma_keyed = ((lv_img_t *)src_img)->header.chroma_keyed;
|
||||
ext->alpha_byte = ((lv_img_t *)src_img)->header.alpha_byte;
|
||||
lv_obj_set_size(img, ext->w, ext->h);
|
||||
}
|
||||
#if USE_LV_FILESYSTEM
|
||||
else if(src_type == LV_IMG_SRC_FILE) {
|
||||
lv_fs_file_t file;
|
||||
lv_fs_res_t res;
|
||||
lv_img_t img_file_data;
|
||||
uint32_t rn;
|
||||
res = lv_fs_open(&file, src_img, LV_FS_MODE_RD);
|
||||
if(res == LV_FS_RES_OK) {
|
||||
res = lv_fs_read(&file, &img_file_data, sizeof(img_file_data), &rn);
|
||||
}
|
||||
|
||||
/*Create a dummy header on fs error*/
|
||||
if(res != LV_FS_RES_OK || rn != sizeof(img_file_data)) {
|
||||
img_file_data.header.w = lv_obj_get_width(img);
|
||||
img_file_data.header.h = lv_obj_get_height(img);
|
||||
img_file_data.header.chroma_keyed = 0;
|
||||
img_file_data.header.alpha_byte = 0;
|
||||
}
|
||||
|
||||
lv_fs_close(&file);
|
||||
|
||||
ext->w = img_file_data.header.w;
|
||||
ext->h = img_file_data.header.h;
|
||||
ext->chroma_keyed = img_file_data.header.chroma_keyed;
|
||||
ext->alpha_byte = img_file_data.header.alpha_byte;
|
||||
|
||||
else if(src_type == LV_IMG_SRC_FILE || src_type == LV_IMG_SRC_SYMBOL) {
|
||||
/* If the new and the old src are the same then it was only a refresh.*/
|
||||
if(ext->src != src_img) {
|
||||
lv_mem_free(ext->src);
|
||||
char * new_fn = lv_mem_alloc(strlen(src_img) + 1);
|
||||
lv_mem_assert(new_fn);
|
||||
if(new_fn == NULL) return;
|
||||
strcpy(new_fn, src_img);
|
||||
ext->src = new_fn;
|
||||
char * new_str = lv_mem_alloc(strlen(src_img) + 1);
|
||||
lv_mem_assert(new_str);
|
||||
if(new_str == NULL) return;
|
||||
strcpy(new_str, src_img);
|
||||
ext->src = new_str;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
#endif
|
||||
else if(src_type == LV_IMG_SRC_SYMBOL) {
|
||||
lv_style_t * style = lv_obj_get_style(img);
|
||||
lv_point_t size;
|
||||
lv_txt_get_size(&size, src_img, style->text.font, style->text.letter_space, style->text.line_space, LV_COORD_MAX, LV_TXT_FLAG_NONE);
|
||||
ext->w = size.x;
|
||||
ext->h = size.y;
|
||||
ext->chroma_keyed = 1; /*Symbols always have transparent parts, Important because of cover check in the design function*/
|
||||
|
||||
/* If the new and the old src are the same then it was only a refresh.*/
|
||||
if(ext->src != src_img) {
|
||||
lv_mem_free(ext->src);
|
||||
char * new_txt = lv_mem_alloc(strlen(src_img) + 1);
|
||||
lv_mem_assert(new_txt);
|
||||
if(new_txt == NULL) return;
|
||||
strcpy(new_txt, src_img);
|
||||
ext->src = new_txt;
|
||||
}
|
||||
}
|
||||
ext->src_type = src_type;
|
||||
ext->w = header.w;
|
||||
ext->h = header.h;
|
||||
ext->cf = header.color_format;
|
||||
|
||||
if(lv_img_get_auto_size(img) != false) {
|
||||
lv_obj_set_size(img, ext->w, ext->h);
|
||||
@@ -228,26 +185,6 @@ void lv_img_set_auto_size(lv_obj_t * img, bool autosize_en)
|
||||
* Getter functions
|
||||
*====================*/
|
||||
|
||||
/**
|
||||
* Get the type of an image source
|
||||
* @param src pointer to an image source:
|
||||
* - pointer to an 'lv_img_t' variable (image stored internally and compiled into the code)
|
||||
* - a path to an file (e.g. "S:/folder/image.bin")
|
||||
* - or a symbol (e.g. SYMBOL_CLOSE)
|
||||
* @return type of the image source LV_IMG_SRC_VARIABLE/FILE/SYMBOL/UNKOWN
|
||||
*/
|
||||
lv_img_src_t lv_img_get_src_type(const void * src)
|
||||
{
|
||||
if(src == NULL) return LV_IMG_SRC_UNKNOWN;
|
||||
const uint8_t * u8_p = src;
|
||||
|
||||
/*The first byte shows the type of the image source*/
|
||||
if(u8_p[0] >= 'A' && u8_p[0] <= 'Z') return LV_IMG_SRC_FILE; /*It's a driver letter*/
|
||||
else if(((u8_p[0] & 0xFC) >> 2) == LV_IMG_FORMAT_INTERNAL_RAW) return LV_IMG_SRC_VARIABLE; /*Mask the file format part og of lv_img_t header. IT should be 0 which means C array */
|
||||
else if(u8_p[0] >= ' ') return LV_IMG_SRC_SYMBOL; /*Other printable characters are considered symbols*/
|
||||
|
||||
else return LV_IMG_SRC_UNKNOWN;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the source of the image
|
||||
@@ -310,9 +247,9 @@ static bool lv_img_design(lv_obj_t * img, const lv_area_t * mask, lv_design_mode
|
||||
bool cover = false;
|
||||
if(ext->src_type == LV_IMG_SRC_UNKNOWN || ext->src_type == LV_IMG_SRC_SYMBOL) return false;
|
||||
|
||||
if(ext->chroma_keyed == 0 && ext->alpha_byte == 0) cover = lv_area_is_in(mask, &img->coords);
|
||||
return cover;
|
||||
if(ext->cf == LV_IMG_FORMAT_TRUE_COLOR) cover = lv_area_is_in(mask, &img->coords);
|
||||
|
||||
return cover;
|
||||
} else if(mode == LV_DESIGN_DRAW_MAIN) {
|
||||
if(ext->h == 0 || ext->w == 0) return true;
|
||||
lv_area_t coords;
|
||||
|
||||
@@ -45,8 +45,7 @@ typedef struct
|
||||
lv_coord_t h; /*Height of the image (Handled by the library)*/
|
||||
uint8_t src_type :2; /*See: lv_img_src_t*/
|
||||
uint8_t auto_size :1; /*1: automatically set the object size to the image size*/
|
||||
uint8_t chroma_keyed :1; /*1: Chroma keyed image, LV_COLOR_TRANSP (lv_conf.h) pixels will be transparent (Handled by the library)*/
|
||||
uint8_t alpha_byte :1; /*1: Extra byte for every pixel to define opacity*/
|
||||
uint8_t cf :5; /*Color format from `lv_img_color_format_t`*/
|
||||
} lv_img_ext_t;
|
||||
|
||||
/**********************
|
||||
@@ -115,16 +114,6 @@ static inline void lv_img_set_upscale(lv_obj_t * img, bool upcale)
|
||||
* Getter functions
|
||||
*====================*/
|
||||
|
||||
/**
|
||||
* Get the type of an image source
|
||||
* @param src pointer to an image source:
|
||||
* - pointer to an 'lv_img_t' variable (image stored internally and compiled into the code)
|
||||
* - a path to an file (e.g. "S:/folder/image.bin")
|
||||
* - or a symbol (e.g. SYMBOL_CLOSE)
|
||||
* @return type of the image source LV_IMG_SRC_VARIABLE/FILE/SYMBOL/UNKOWN
|
||||
*/
|
||||
lv_img_src_t lv_img_get_src_type(const void * src);
|
||||
|
||||
/**
|
||||
* Get the source of the image
|
||||
* @param img pointer to an image object
|
||||
@@ -171,7 +160,7 @@ static inline bool lv_img_get_upscale(const lv_obj_t * img)
|
||||
**********************/
|
||||
|
||||
/*Use this macro to declare an image in a c file*/
|
||||
#define LV_IMG_DECLARE(var_name) extern const lv_img_t var_name;
|
||||
#define LV_IMG_DECLARE(var_name) extern const lv_img_dsc_t var_name;
|
||||
|
||||
#endif /*USE_LV_IMG*/
|
||||
|
||||
|
||||
Reference in New Issue
Block a user