lv_img: make possible to disabel palette and alpha index support
This commit is contained in:
@@ -193,6 +193,10 @@
|
|||||||
|
|
||||||
/*Image (dependencies: lv_label*/
|
/*Image (dependencies: lv_label*/
|
||||||
#define USE_LV_IMG 1
|
#define USE_LV_IMG 1
|
||||||
|
#if USE_LV_IMG != 0
|
||||||
|
#define LV_IMG_CF_INDEXED 1 /*Enable indexed (palette) images*/
|
||||||
|
#define LV_IMG_CF_ALPHA 1 /*Enable alpha indexed images*/
|
||||||
|
#endif
|
||||||
|
|
||||||
/*Line (dependencies: -*/
|
/*Line (dependencies: -*/
|
||||||
#define USE_LV_LINE 1
|
#define USE_LV_LINE 1
|
||||||
|
|||||||
@@ -425,7 +425,7 @@ static void indev_encoder_proc(lv_indev_t * i, lv_indev_data_t * data)
|
|||||||
focused->signal_func(focused, LV_SIGNAL_GET_EDITABLE, &editable);
|
focused->signal_func(focused, LV_SIGNAL_GET_EDITABLE, &editable);
|
||||||
/*In edit mode send LEFT/RIGHT keys*/
|
/*In edit mode send LEFT/RIGHT keys*/
|
||||||
if(lv_group_get_editing(i->group)) {
|
if(lv_group_get_editing(i->group)) {
|
||||||
uint32_t s;
|
int32_t s;
|
||||||
if(data->enc_diff < 0) {
|
if(data->enc_diff < 0) {
|
||||||
for(s = 0; s < -data->enc_diff; s++) lv_group_send_data(i->group, LV_GROUP_KEY_LEFT);
|
for(s = 0; s < -data->enc_diff; s++) lv_group_send_data(i->group, LV_GROUP_KEY_LEFT);
|
||||||
} else if(data->enc_diff > 0) {
|
} else if(data->enc_diff > 0) {
|
||||||
@@ -433,7 +433,8 @@ static void indev_encoder_proc(lv_indev_t * i, lv_indev_data_t * data)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
/*In navigate mode focus on the next/prev objects*/
|
/*In navigate mode focus on the next/prev objects*/
|
||||||
else {uint32_t s;
|
else {
|
||||||
|
int32_t s;
|
||||||
if(data->enc_diff < 0) {
|
if(data->enc_diff < 0) {
|
||||||
for(s = 0; s < -data->enc_diff; s++) lv_group_focus_prev(i->group);
|
for(s = 0; s < -data->enc_diff; s++) lv_group_focus_prev(i->group);
|
||||||
} else if(data->enc_diff > 0) {
|
} else if(data->enc_diff > 0) {
|
||||||
|
|||||||
@@ -301,7 +301,7 @@ static void lv_refr_area_with_vdb(const lv_area_t * area_p)
|
|||||||
lv_coord_t h = lv_area_get_height(area_p);
|
lv_coord_t h = lv_area_get_height(area_p);
|
||||||
lv_coord_t y2 = area_p->y2 >= LV_VER_RES ? y2 = LV_VER_RES - 1 : area_p->y2;
|
lv_coord_t y2 = area_p->y2 >= LV_VER_RES ? y2 = LV_VER_RES - 1 : area_p->y2;
|
||||||
|
|
||||||
uint32_t max_row = (uint32_t) LV_VDB_SIZE / w;
|
lv_coord_t max_row = (uint32_t) LV_VDB_SIZE / w;
|
||||||
|
|
||||||
if(max_row > h) max_row = h;
|
if(max_row > h) max_row = h;
|
||||||
|
|
||||||
@@ -330,7 +330,7 @@ static void lv_refr_area_with_vdb(const lv_area_t * area_p)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*Always use the full row*/
|
/*Always use the full row*/
|
||||||
uint32_t row;
|
lv_coord_t row;
|
||||||
lv_coord_t row_last = 0;
|
lv_coord_t row_last = 0;
|
||||||
for(row = area_p->y1; row + max_row - 1 <= y2; row += max_row) {
|
for(row = area_p->y1; row + max_row - 1 <= y2; row += max_row) {
|
||||||
lv_vdb_t * vdb_p = lv_vdb_get();
|
lv_vdb_t * vdb_p = lv_vdb_get();
|
||||||
|
|||||||
@@ -141,6 +141,7 @@ void lv_vdb_flush(void)
|
|||||||
void lv_vdb_set_adr(void * buf1, void * buf2)
|
void lv_vdb_set_adr(void * buf1, void * buf2)
|
||||||
{
|
{
|
||||||
#if LV_VDB_DOUBLE == 0
|
#if LV_VDB_DOUBLE == 0
|
||||||
|
(void) buf2; /*unused*/
|
||||||
vdb.buf = buf1;
|
vdb.buf = buf1;
|
||||||
#else
|
#else
|
||||||
vdb[0].buf = buf1;
|
vdb[0].buf = buf1;
|
||||||
|
|||||||
@@ -38,7 +38,9 @@ static lv_img_src_t decoder_src_type;
|
|||||||
static lv_img_header_t decoder_header;
|
static lv_img_header_t decoder_header;
|
||||||
static const lv_style_t * decoder_style;
|
static const lv_style_t * decoder_style;
|
||||||
static lv_fs_file_t decoder_file;
|
static lv_fs_file_t decoder_file;
|
||||||
|
#if LV_IMG_CF_INDEXED
|
||||||
static lv_color_t decoder_index_map[256];
|
static lv_color_t decoder_index_map[256];
|
||||||
|
#endif
|
||||||
|
|
||||||
static lv_img_decoder_info_f_t lv_img_decoder_info_custom;
|
static lv_img_decoder_info_f_t lv_img_decoder_info_custom;
|
||||||
static lv_img_decoder_open_f_t lv_img_decoder_open_custom;
|
static lv_img_decoder_open_f_t lv_img_decoder_open_custom;
|
||||||
@@ -394,6 +396,8 @@ static const uint8_t * lv_img_decoder_open(const void * src, const lv_style_t *
|
|||||||
cf == LV_IMG_CF_INDEXED_2BIT ||
|
cf == LV_IMG_CF_INDEXED_2BIT ||
|
||||||
cf == LV_IMG_CF_INDEXED_4BIT ||
|
cf == LV_IMG_CF_INDEXED_4BIT ||
|
||||||
cf == LV_IMG_CF_INDEXED_8BIT) {
|
cf == LV_IMG_CF_INDEXED_8BIT) {
|
||||||
|
|
||||||
|
#if LV_IMG_CF_INDEXED
|
||||||
lv_color32_t palette_file[256];
|
lv_color32_t palette_file[256];
|
||||||
lv_color32_t * palette_p = NULL;
|
lv_color32_t * palette_p = NULL;
|
||||||
uint8_t px_size = lv_img_color_format_get_px_size(cf);
|
uint8_t px_size = lv_img_color_format_get_px_size(cf);
|
||||||
@@ -416,11 +420,20 @@ static const uint8_t * lv_img_decoder_open(const void * src, const lv_style_t *
|
|||||||
decoder_index_map[i] = LV_COLOR_MAKE(palette_p[i].red, palette_p[i].green, palette_p[i].blue);
|
decoder_index_map[i] = LV_COLOR_MAKE(palette_p[i].red, palette_p[i].green, palette_p[i].blue);
|
||||||
}
|
}
|
||||||
return NULL;
|
return NULL;
|
||||||
|
#else
|
||||||
|
LV_LOG_WARN("Indexed (palette) images are not enabled in lv_conf.h. See LV_IMG_CF_INDEXED");
|
||||||
|
return LV_IMG_DECODER_OPEN_FAIL;
|
||||||
|
#endif
|
||||||
} else if(cf == LV_IMG_CF_ALPHA_1BIT ||
|
} else if(cf == LV_IMG_CF_ALPHA_1BIT ||
|
||||||
cf == LV_IMG_CF_ALPHA_2BIT ||
|
cf == LV_IMG_CF_ALPHA_2BIT ||
|
||||||
cf == LV_IMG_CF_ALPHA_4BIT ||
|
cf == LV_IMG_CF_ALPHA_4BIT ||
|
||||||
cf == LV_IMG_CF_ALPHA_8BIT) {
|
cf == LV_IMG_CF_ALPHA_8BIT) {
|
||||||
|
#if LV_IMG_CF_ALPHA
|
||||||
return NULL; /*Nothing to process*/
|
return NULL; /*Nothing to process*/
|
||||||
|
#else
|
||||||
|
LV_LOG_WARN("Alpha indexed images are not enabled in lv_conf.h. See LV_IMG_CF_ALPHA");
|
||||||
|
return LV_IMG_DECODER_OPEN_FAIL;
|
||||||
|
#endif
|
||||||
} else {
|
} else {
|
||||||
LV_LOG_WARN("Image decoder open: unknown color format")
|
LV_LOG_WARN("Image decoder open: unknown color format")
|
||||||
return LV_IMG_DECODER_OPEN_FAIL;
|
return LV_IMG_DECODER_OPEN_FAIL;
|
||||||
@@ -468,6 +481,7 @@ static lv_res_t lv_img_decoder_read_line(lv_coord_t x, lv_coord_t y, lv_coord_t
|
|||||||
decoder_header.cf == LV_IMG_CF_ALPHA_2BIT ||
|
decoder_header.cf == LV_IMG_CF_ALPHA_2BIT ||
|
||||||
decoder_header.cf == LV_IMG_CF_ALPHA_4BIT ||
|
decoder_header.cf == LV_IMG_CF_ALPHA_4BIT ||
|
||||||
decoder_header.cf == LV_IMG_CF_ALPHA_8BIT) {
|
decoder_header.cf == LV_IMG_CF_ALPHA_8BIT) {
|
||||||
|
|
||||||
lv_img_built_in_decoder_line_alpha(x, y, len, buf);
|
lv_img_built_in_decoder_line_alpha(x, y, len, buf);
|
||||||
} else if(decoder_header.cf == LV_IMG_CF_INDEXED_1BIT ||
|
} else if(decoder_header.cf == LV_IMG_CF_INDEXED_1BIT ||
|
||||||
decoder_header.cf == LV_IMG_CF_INDEXED_2BIT ||
|
decoder_header.cf == LV_IMG_CF_INDEXED_2BIT ||
|
||||||
@@ -522,9 +536,10 @@ static void lv_img_decoder_close(void)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static lv_res_t lv_img_built_in_decoder_line_alpha(lv_coord_t x, lv_coord_t y, lv_coord_t len, uint8_t * buf)
|
static lv_res_t lv_img_built_in_decoder_line_alpha(lv_coord_t x, lv_coord_t y, lv_coord_t len, uint8_t * buf)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
#if LV_IMG_CF_ALPHA
|
||||||
const lv_opa_t alpha1_opa_table[2] = {0, 255}; /*Opacity mapping with bpp = 1 (Just for compatibility)*/
|
const lv_opa_t alpha1_opa_table[2] = {0, 255}; /*Opacity mapping with bpp = 1 (Just for compatibility)*/
|
||||||
const lv_opa_t alpha2_opa_table[4] = {0, 85, 170, 255}; /*Opacity mapping with bpp = 2*/
|
const lv_opa_t alpha2_opa_table[4] = {0, 85, 170, 255}; /*Opacity mapping with bpp = 2*/
|
||||||
const lv_opa_t alpha4_opa_table[16] = {0, 17, 34, 51, /*Opacity mapping with bpp = 4*/
|
const lv_opa_t alpha4_opa_table[16] = {0, 17, 34, 51, /*Opacity mapping with bpp = 4*/
|
||||||
@@ -537,7 +552,7 @@ static lv_res_t lv_img_built_in_decoder_line_alpha(lv_coord_t x, lv_coord_t y, l
|
|||||||
lv_color_t bg_color = decoder_style->image.color;
|
lv_color_t bg_color = decoder_style->image.color;
|
||||||
lv_coord_t i;
|
lv_coord_t i;
|
||||||
for(i = 0; i < len; i++) {
|
for(i = 0; i < len; i++) {
|
||||||
#if LV_COLOR_DEPTH == 8
|
#if LV_COLOR_DEPTH == 8 || LV_COLOR_DEPTH == 1
|
||||||
buf[i * LV_IMG_PX_SIZE_ALPHA_BYTE] = bg_color.full;
|
buf[i * LV_IMG_PX_SIZE_ALPHA_BYTE] = bg_color.full;
|
||||||
#elif LV_COLOR_DEPTH == 16
|
#elif LV_COLOR_DEPTH == 16
|
||||||
/*Because of Alpha byte 16 bit color can start on odd address which can cause crash*/
|
/*Because of Alpha byte 16 bit color can start on odd address which can cause crash*/
|
||||||
@@ -607,7 +622,7 @@ static lv_res_t lv_img_built_in_decoder_line_alpha(lv_coord_t x, lv_coord_t y, l
|
|||||||
lv_fs_read(&decoder_file, fs_buf, w, NULL);
|
lv_fs_read(&decoder_file, fs_buf, w, NULL);
|
||||||
data_tmp = fs_buf;
|
data_tmp = fs_buf;
|
||||||
#else
|
#else
|
||||||
LV_LOG_WARN("Image built-in indexed line reader can't read file because USE_LV_FILESYSTEM = 0");
|
LV_LOG_WARN("Image built-in alpha line reader can't read file because USE_LV_FILESYSTEM = 0");
|
||||||
data_tmp = NULL; /*To avoid warnings*/
|
data_tmp = NULL; /*To avoid warnings*/
|
||||||
return LV_RES_INV;
|
return LV_RES_INV;
|
||||||
#endif
|
#endif
|
||||||
@@ -630,11 +645,17 @@ static lv_res_t lv_img_built_in_decoder_line_alpha(lv_coord_t x, lv_coord_t y, l
|
|||||||
}
|
}
|
||||||
|
|
||||||
return LV_RES_OK;
|
return LV_RES_OK;
|
||||||
|
|
||||||
|
#else
|
||||||
|
LV_LOG_WARN("Image built-in alpha line reader failed because LV_IMG_CF_ALPHA is 0 in lv_conf.h");
|
||||||
|
return LV_RES_INV;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
static lv_res_t lv_img_built_in_decoder_line_indexed(lv_coord_t x, lv_coord_t y, lv_coord_t len, uint8_t * buf)
|
static lv_res_t lv_img_built_in_decoder_line_indexed(lv_coord_t x, lv_coord_t y, lv_coord_t len, uint8_t * buf)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
#if LV_IMG_CF_INDEXED
|
||||||
uint8_t px_size = lv_img_color_format_get_px_size(decoder_header.cf);
|
uint8_t px_size = lv_img_color_format_get_px_size(decoder_header.cf);
|
||||||
uint16_t mask = (1 << px_size) - 1; /*E.g. px_size = 2; mask = 0x03*/
|
uint16_t mask = (1 << px_size) - 1; /*E.g. px_size = 2; mask = 0x03*/
|
||||||
|
|
||||||
@@ -700,7 +721,7 @@ static lv_res_t lv_img_built_in_decoder_line_indexed(lv_coord_t x, lv_coord_t y,
|
|||||||
|
|
||||||
uint8_t byte_act = 0;
|
uint8_t byte_act = 0;
|
||||||
uint8_t val_act;
|
uint8_t val_act;
|
||||||
uint32_t i;
|
lv_coord_t i;
|
||||||
lv_color_t * cbuf = (lv_color_t *) buf;
|
lv_color_t * cbuf = (lv_color_t *) buf;
|
||||||
for(i = 0; i < len; i ++) {
|
for(i = 0; i < len; i ++) {
|
||||||
val_act = (data_tmp[byte_act] & (mask << pos)) >> pos;
|
val_act = (data_tmp[byte_act] & (mask << pos)) >> pos;
|
||||||
@@ -714,5 +735,8 @@ static lv_res_t lv_img_built_in_decoder_line_indexed(lv_coord_t x, lv_coord_t y,
|
|||||||
}
|
}
|
||||||
|
|
||||||
return LV_RES_OK;
|
return LV_RES_OK;
|
||||||
|
#else
|
||||||
|
LV_LOG_WARN("Image built-in indexed line reader failed because LV_IMG_CF_INDEXED is 0 in lv_conf.h");
|
||||||
|
return LV_RES_INV;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -235,12 +235,12 @@ static void line_draw_skew(line_draw_t * main_line, const lv_area_t * mask, cons
|
|||||||
|
|
||||||
uint32_t width_sqr = width * width;
|
uint32_t width_sqr = width * width;
|
||||||
/* Run for a lot of times. Meanwhile the real width will be determined as well */
|
/* Run for a lot of times. Meanwhile the real width will be determined as well */
|
||||||
for(i = 0; i < sizeof(pattern); i ++) {
|
for(i = 0; i < (uint32_t)sizeof(pattern); i ++) {
|
||||||
pattern[i].x = pattern_line.p_act.x;
|
pattern[i].x = pattern_line.p_act.x;
|
||||||
pattern[i].y = pattern_line.p_act.y;
|
pattern[i].y = pattern_line.p_act.y;
|
||||||
|
|
||||||
/*Finish the pattern line if it's length equal to the desired width (Use Pythagoras theorem)*/
|
/*Finish the pattern line if it's length equal to the desired width (Use Pythagoras theorem)*/
|
||||||
int32_t sqr = pattern_line.p_act.x * pattern_line.p_act.x + pattern_line.p_act.y * pattern_line.p_act.y;
|
uint32_t sqr = pattern_line.p_act.x * pattern_line.p_act.x + pattern_line.p_act.y * pattern_line.p_act.y;
|
||||||
if(sqr >= width_sqr) {
|
if(sqr >= width_sqr) {
|
||||||
width = i;
|
width = i;
|
||||||
#if LV_ANTIALIAS
|
#if LV_ANTIALIAS
|
||||||
|
|||||||
Reference in New Issue
Block a user