chore(format): run code-format.sh (#2822)

* fix(format): run code-format.sh

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>

* fix(astyle): add the 3rd party source file to exclude list

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
This commit is contained in:
Xiang Xiao
2021-11-22 06:32:48 -06:00
committed by GitHub
parent 77287ca7d9
commit 3a0069adf8
49 changed files with 598 additions and 543 deletions

View File

@@ -84,5 +84,5 @@ print("\nGenerating 16 px unscii")
os.system("lv_font_conv --no-compress --no-prefilter --bpp 1 --size 16 --font unscii-8.ttf -r 0x20-0x7F --format lvgl -o lv_font_unscii_16.c --force-fast-kern-format") os.system("lv_font_conv --no-compress --no-prefilter --bpp 1 --size 16 --font unscii-8.ttf -r 0x20-0x7F --format lvgl -o lv_font_unscii_16.c --force-fast-kern-format")
os.system('sed -i \'s|#include "lvgl/lvgl.h"|#include "../../lvgl.h"|\' lv_font_*.c') os.system('sed -i \'s|#include "lvgl/lvgl.h"|#include "../../lvgl.h"|\' lv_font_*.c')
os.system('astyle --options=../code-format.cfg "lv_font_*.c"') os.system('astyle --ignore-exclude-errors --options=../code-format.cfg "lv_font_*.c"')
os.system('mv lv_font_*.c ../../src/font/') os.system('mv lv_font_*.c ../../src/font/')

View File

@@ -23,3 +23,12 @@
--suffix=none --suffix=none
--preserve-date --preserve-date
--formatted --formatted
--exclude=../src/extra/libs/gif/gifdec.c
--exclude=../src/extra/libs/gif/gifdec.h
--exclude=../src/extra/libs/png/lodepng.c
--exclude=../src/extra/libs/png/lodepng.h
--exclude=../src/extra/libs/qrcode/qrcodegen.c
--exclude=../src/extra/libs/qrcode/qrcodegen.h
--exclude=../src/extra/libs/sjpg/tjpgd.c
--exclude=../src/extra/libs/sjpg/tjpgd.h
--exclude=../src/extra/libs/sjpg/tjpgdcnf.h

View File

@@ -429,11 +429,10 @@ static lv_res_t event_send_core(lv_event_t * e)
event_dsc = lv_obj_get_event_dsc(e->current_target, i); event_dsc = lv_obj_get_event_dsc(e->current_target, i);
} }
if(res == LV_RES_OK && e->current_target->parent && event_is_bubbled(e)) if(res == LV_RES_OK && e->current_target->parent && event_is_bubbled(e)) {
{ e->current_target = e->current_target->parent;
e->current_target = e->current_target->parent; res = event_send_core(e);
res = event_send_core(e); if(res != LV_RES_OK) return LV_RES_INV;
if(res != LV_RES_OK) return LV_RES_INV;
} }

View File

@@ -994,8 +994,7 @@ static void indev_click_focus(_lv_indev_proc_t * proc)
{ {
/*Handle click focus*/ /*Handle click focus*/
if(lv_obj_has_flag(indev_obj_act, LV_OBJ_FLAG_CLICK_FOCUSABLE) == false || if(lv_obj_has_flag(indev_obj_act, LV_OBJ_FLAG_CLICK_FOCUSABLE) == false ||
proc->types.pointer.last_pressed == indev_obj_act) proc->types.pointer.last_pressed == indev_obj_act) {
{
return; return;
} }

View File

@@ -966,13 +966,14 @@ static lv_coord_t calc_content_width(lv_obj_t * obj)
child_res = LV_MAX(child_res, obj->coords.x2 - child->coords.x1 + 1); child_res = LV_MAX(child_res, obj->coords.x2 - child->coords.x1 + 1);
break; break;
default: default:
/* Consider other cases only if x=0 and use the width of the object. /* Consider other cases only if x=0 and use the width of the object.
* With x!=0 circular dependency could occur. */ * With x!=0 circular dependency could occur. */
if(lv_obj_get_style_y(child, 0) == 0) { if(lv_obj_get_style_y(child, 0) == 0) {
child_res = LV_MAX(child_res, lv_area_get_width(&child->coords)); child_res = LV_MAX(child_res, lv_area_get_width(&child->coords));
} }
} }
} else { }
else {
child_res = LV_MAX(child_res, obj->coords.x2 - child->coords.x1 + 1); child_res = LV_MAX(child_res, obj->coords.x2 - child->coords.x1 + 1);
} }
} }
@@ -997,13 +998,14 @@ static lv_coord_t calc_content_width(lv_obj_t * obj)
child_res = LV_MAX(child_res, child->coords.x2 - obj->coords.x1 + 1); child_res = LV_MAX(child_res, child->coords.x2 - obj->coords.x1 + 1);
break; break;
default: default:
/* Consider other cases only if x=0 and use the width of the object. /* Consider other cases only if x=0 and use the width of the object.
* With x!=0 circular dependency could occur. */ * With x!=0 circular dependency could occur. */
if(lv_obj_get_style_y(child, 0) == 0) { if(lv_obj_get_style_y(child, 0) == 0) {
child_res = LV_MAX(child_res, lv_area_get_width(&child->coords)); child_res = LV_MAX(child_res, lv_area_get_width(&child->coords));
} }
} }
} else { }
else {
child_res = LV_MAX(child_res, child->coords.x2 - obj->coords.x1 + 1); child_res = LV_MAX(child_res, child->coords.x2 - obj->coords.x1 + 1);
} }
} }
@@ -1047,14 +1049,15 @@ static lv_coord_t calc_content_height(lv_obj_t * obj)
child_res = LV_MAX(child_res, child->coords.y2 - obj->coords.y1 + 1); child_res = LV_MAX(child_res, child->coords.y2 - obj->coords.y1 + 1);
break; break;
default: default:
/* Consider other cases only if y=0 and use the height of the object. /* Consider other cases only if y=0 and use the height of the object.
* With y!=0 circular dependency could occur. */ * With y!=0 circular dependency could occur. */
if(lv_obj_get_style_y(child, 0) == 0) { if(lv_obj_get_style_y(child, 0) == 0) {
child_res = LV_MAX(child_res, lv_area_get_height(&child->coords)); child_res = LV_MAX(child_res, lv_area_get_height(&child->coords));
} }
break; break;
} }
} else { }
else {
child_res = LV_MAX(child_res, child->coords.y2 - obj->coords.y1 + 1); child_res = LV_MAX(child_res, child->coords.y2 - obj->coords.y1 + 1);
} }
} }
@@ -1062,7 +1065,8 @@ static lv_coord_t calc_content_height(lv_obj_t * obj)
if(child_res != LV_COORD_MIN) { if(child_res != LV_COORD_MIN) {
child_res += pad_bottom; child_res += pad_bottom;
return LV_MAX(child_res, self_h); return LV_MAX(child_res, self_h);
} else { }
else {
return self_h; return self_h;
} }

View File

@@ -648,7 +648,8 @@ void lv_obj_set_style_opa(struct _lv_obj_t * obj, lv_opa_t value, lv_style_selec
lv_obj_set_local_style_prop(obj, LV_STYLE_OPA, v, selector); lv_obj_set_local_style_prop(obj, LV_STYLE_OPA, v, selector);
} }
void lv_obj_set_style_color_filter_dsc(struct _lv_obj_t * obj, const lv_color_filter_dsc_t * value, lv_style_selector_t selector) void lv_obj_set_style_color_filter_dsc(struct _lv_obj_t * obj, const lv_color_filter_dsc_t * value,
lv_style_selector_t selector)
{ {
lv_style_value_t v = { lv_style_value_t v = {
.ptr = value .ptr = value
@@ -680,7 +681,8 @@ void lv_obj_set_style_anim_speed(struct _lv_obj_t * obj, uint32_t value, lv_styl
lv_obj_set_local_style_prop(obj, LV_STYLE_ANIM_SPEED, v, selector); lv_obj_set_local_style_prop(obj, LV_STYLE_ANIM_SPEED, v, selector);
} }
void lv_obj_set_style_transition(struct _lv_obj_t * obj, const lv_style_transition_dsc_t * value, lv_style_selector_t selector) void lv_obj_set_style_transition(struct _lv_obj_t * obj, const lv_style_transition_dsc_t * value,
lv_style_selector_t selector)
{ {
lv_style_value_t v = { lv_style_value_t v = {
.ptr = value .ptr = value

View File

@@ -484,7 +484,8 @@ static inline lv_opa_t lv_obj_get_style_opa(const struct _lv_obj_t * obj, uint32
return (lv_opa_t)v.num; return (lv_opa_t)v.num;
} }
static inline const lv_color_filter_dsc_t * lv_obj_get_style_color_filter_dsc(const struct _lv_obj_t * obj, uint32_t part) static inline const lv_color_filter_dsc_t * lv_obj_get_style_color_filter_dsc(const struct _lv_obj_t * obj,
uint32_t part)
{ {
lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_COLOR_FILTER_DSC); lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_COLOR_FILTER_DSC);
return (const lv_color_filter_dsc_t *)v.ptr; return (const lv_color_filter_dsc_t *)v.ptr;
@@ -613,11 +614,13 @@ void lv_obj_set_style_text_align(struct _lv_obj_t * obj, lv_text_align_t value,
void lv_obj_set_style_radius(struct _lv_obj_t * obj, lv_coord_t value, lv_style_selector_t selector); void lv_obj_set_style_radius(struct _lv_obj_t * obj, lv_coord_t value, lv_style_selector_t selector);
void lv_obj_set_style_clip_corner(struct _lv_obj_t * obj, bool value, lv_style_selector_t selector); void lv_obj_set_style_clip_corner(struct _lv_obj_t * obj, bool value, lv_style_selector_t selector);
void lv_obj_set_style_opa(struct _lv_obj_t * obj, lv_opa_t value, lv_style_selector_t selector); void lv_obj_set_style_opa(struct _lv_obj_t * obj, lv_opa_t value, lv_style_selector_t selector);
void lv_obj_set_style_color_filter_dsc(struct _lv_obj_t * obj, const lv_color_filter_dsc_t * value, lv_style_selector_t selector); void lv_obj_set_style_color_filter_dsc(struct _lv_obj_t * obj, const lv_color_filter_dsc_t * value,
lv_style_selector_t selector);
void lv_obj_set_style_color_filter_opa(struct _lv_obj_t * obj, lv_opa_t value, lv_style_selector_t selector); void lv_obj_set_style_color_filter_opa(struct _lv_obj_t * obj, lv_opa_t value, lv_style_selector_t selector);
void lv_obj_set_style_anim_time(struct _lv_obj_t * obj, uint32_t value, lv_style_selector_t selector); void lv_obj_set_style_anim_time(struct _lv_obj_t * obj, uint32_t value, lv_style_selector_t selector);
void lv_obj_set_style_anim_speed(struct _lv_obj_t * obj, uint32_t value, lv_style_selector_t selector); void lv_obj_set_style_anim_speed(struct _lv_obj_t * obj, uint32_t value, lv_style_selector_t selector);
void lv_obj_set_style_transition(struct _lv_obj_t * obj, const lv_style_transition_dsc_t * value, lv_style_selector_t selector); void lv_obj_set_style_transition(struct _lv_obj_t * obj, const lv_style_transition_dsc_t * value,
lv_style_selector_t selector);
void lv_obj_set_style_blend_mode(struct _lv_obj_t * obj, lv_blend_mode_t value, lv_style_selector_t selector); void lv_obj_set_style_blend_mode(struct _lv_obj_t * obj, lv_blend_mode_t value, lv_style_selector_t selector);
void lv_obj_set_style_layout(struct _lv_obj_t * obj, uint16_t value, lv_style_selector_t selector); void lv_obj_set_style_layout(struct _lv_obj_t * obj, uint16_t value, lv_style_selector_t selector);
void lv_obj_set_style_base_dir(struct _lv_obj_t * obj, lv_base_dir_t value, lv_style_selector_t selector); void lv_obj_set_style_base_dir(struct _lv_obj_t * obj, lv_base_dir_t value, lv_style_selector_t selector);

View File

@@ -536,7 +536,8 @@ static void lv_refr_area_part(const lv_area_t * area_p)
if(top_act_scr == NULL && top_prev_scr == NULL) { if(top_act_scr == NULL && top_prev_scr == NULL) {
if(disp_refr->bg_fn) { if(disp_refr->bg_fn) {
disp_refr->bg_fn(&start_mask); disp_refr->bg_fn(&start_mask);
} else if(disp_refr->bg_img) { }
else if(disp_refr->bg_img) {
lv_draw_img_dsc_t dsc; lv_draw_img_dsc_t dsc;
lv_draw_img_dsc_init(&dsc); lv_draw_img_dsc_init(&dsc);
dsc.opa = disp_refr->bg_opa; dsc.opa = disp_refr->bg_opa;

View File

@@ -449,7 +449,7 @@ LV_ATTRIBUTE_FAST_MEM void lv_draw_letter(const lv_point_t * pos_p, const lv_are
return; return;
} }
if (g.resolved_font) { if(g.resolved_font) {
font_p = g.resolved_font; font_p = g.resolved_font;
} }
const uint8_t * map_p = lv_font_get_glyph_bitmap(font_p, letter); const uint8_t * map_p = lv_font_get_glyph_bitmap(font_p, letter);

View File

@@ -140,16 +140,16 @@ LV_ATTRIBUTE_FAST_MEM lv_draw_mask_res_t lv_draw_mask_apply(lv_opa_t * mask_buf,
* - `LV_DRAW_MASK_RES_CHANGED`: `mask_buf` has changed, it shows the desired opacity of each pixel in the given line * - `LV_DRAW_MASK_RES_CHANGED`: `mask_buf` has changed, it shows the desired opacity of each pixel in the given line
*/ */
LV_ATTRIBUTE_FAST_MEM lv_draw_mask_res_t lv_draw_mask_apply_ids(lv_opa_t * mask_buf, lv_coord_t abs_x, lv_coord_t abs_y, LV_ATTRIBUTE_FAST_MEM lv_draw_mask_res_t lv_draw_mask_apply_ids(lv_opa_t * mask_buf, lv_coord_t abs_x, lv_coord_t abs_y,
lv_coord_t len, const int16_t *ids, int16_t ids_count) lv_coord_t len, const int16_t * ids, int16_t ids_count)
{ {
bool changed = false; bool changed = false;
_lv_draw_mask_common_dsc_t * dsc; _lv_draw_mask_common_dsc_t * dsc;
for (int i = 0; i < ids_count; i++) { for(int i = 0; i < ids_count; i++) {
int16_t id = ids[i]; int16_t id = ids[i];
if (id == LV_MASK_ID_INV) continue; if(id == LV_MASK_ID_INV) continue;
dsc = LV_GC_ROOT(_lv_draw_mask_list[id]).param; dsc = LV_GC_ROOT(_lv_draw_mask_list[id]).param;
if (!dsc) continue; if(!dsc) continue;
lv_draw_mask_res_t res = LV_DRAW_MASK_RES_FULL_COVER; lv_draw_mask_res_t res = LV_DRAW_MASK_RES_FULL_COVER;
res = dsc->cb(mask_buf, abs_x, abs_y, len, dsc); res = dsc->cb(mask_buf, abs_x, abs_y, len, dsc);
if(res == LV_DRAW_MASK_RES_TRANSP) return LV_DRAW_MASK_RES_TRANSP; if(res == LV_DRAW_MASK_RES_TRANSP) return LV_DRAW_MASK_RES_TRANSP;

View File

@@ -250,7 +250,7 @@ LV_ATTRIBUTE_FAST_MEM lv_draw_mask_res_t lv_draw_mask_apply(lv_opa_t * mask_buf,
* - `LV_DRAW_MASK_RES_CHANGED`: `mask_buf` has changed, it shows the desired opacity of each pixel in the given line * - `LV_DRAW_MASK_RES_CHANGED`: `mask_buf` has changed, it shows the desired opacity of each pixel in the given line
*/ */
LV_ATTRIBUTE_FAST_MEM lv_draw_mask_res_t lv_draw_mask_apply_ids(lv_opa_t * mask_buf, lv_coord_t abs_x, lv_coord_t abs_y, LV_ATTRIBUTE_FAST_MEM lv_draw_mask_res_t lv_draw_mask_apply_ids(lv_opa_t * mask_buf, lv_coord_t abs_x, lv_coord_t abs_y,
lv_coord_t len, const int16_t *ids, int16_t ids_count); lv_coord_t len, const int16_t * ids, int16_t ids_count);
//! @endcond //! @endcond

View File

@@ -36,7 +36,7 @@ static lv_res_t decoder_open(lv_img_decoder_t * dec, lv_img_decoder_dsc_t * dsc)
static lv_res_t decoder_read_line(lv_img_decoder_t * decoder, lv_img_decoder_dsc_t * dsc, static lv_res_t decoder_read_line(lv_img_decoder_t * decoder, lv_img_decoder_dsc_t * dsc,
lv_coord_t x, lv_coord_t y, lv_coord_t len, uint8_t * buf); lv_coord_t x, lv_coord_t y, lv_coord_t len, uint8_t * buf);
static void decoder_close(lv_img_decoder_t * dec, lv_img_decoder_dsc_t * dsc); static void decoder_close(lv_img_decoder_t * dec, lv_img_decoder_dsc_t * dsc);
@@ -140,7 +140,7 @@ static lv_res_t decoder_open(lv_img_decoder_t * decoder, lv_img_decoder_dsc_t *
uint8_t header[54]; uint8_t header[54];
lv_fs_read(&b.f, header, 54, NULL); lv_fs_read(&b.f, header, 54, NULL);
if (0x42 != header[0] || 0x4d != header[1]) { if(0x42 != header[0] || 0x4d != header[1]) {
return LV_RES_INV; return LV_RES_INV;
} }
@@ -169,7 +169,7 @@ static lv_res_t decoder_open(lv_img_decoder_t * decoder, lv_img_decoder_dsc_t *
static lv_res_t decoder_read_line(lv_img_decoder_t * decoder, lv_img_decoder_dsc_t * dsc, static lv_res_t decoder_read_line(lv_img_decoder_t * decoder, lv_img_decoder_dsc_t * dsc,
lv_coord_t x, lv_coord_t y, lv_coord_t len, uint8_t * buf) lv_coord_t x, lv_coord_t y, lv_coord_t len, uint8_t * buf)
{ {
LV_UNUSED(decoder); LV_UNUSED(decoder);
@@ -188,7 +188,7 @@ static lv_res_t decoder_read_line(lv_img_decoder_t * decoder, lv_img_decoder_dsc
uint8_t b1 = buf[i * 4 + 1]; uint8_t b1 = buf[i * 4 + 1];
uint8_t b2 = buf[i * 4 + 2]; uint8_t b2 = buf[i * 4 + 2];
uint8_t b3 = buf[i * 4 + 3]; uint8_t b3 = buf[i * 4 + 3];
lv_color32_t *c = (lv_color32_t*)&buf[i*4]; lv_color32_t * c = (lv_color32_t *)&buf[i * 4];
c->ch.red = b2; c->ch.red = b2;
c->ch.green = b1; c->ch.green = b1;
c->ch.blue = b0; c->ch.blue = b0;
@@ -200,7 +200,7 @@ static lv_res_t decoder_read_line(lv_img_decoder_t * decoder, lv_img_decoder_dsc
for(i = len - 1; i >= 0; i--) { for(i = len - 1; i >= 0; i--) {
uint8_t * t = &buf[i * 3]; uint8_t * t = &buf[i * 3];
lv_color32_t *c = (lv_color32_t*)&buf[i*4]; lv_color32_t * c = (lv_color32_t *)&buf[i * 4];
c->ch.red = t[2]; c->ch.red = t[2];
c->ch.green = t[1]; c->ch.green = t[1];
c->ch.blue = t[0]; c->ch.blue = t[0];

View File

@@ -617,7 +617,7 @@ static int ffmpeg_get_frame_refr_period(struct ffmpeg_context_s * ffmpeg_ctx)
int avg_frame_rate_num = ffmpeg_ctx->video_stream->avg_frame_rate.num; int avg_frame_rate_num = ffmpeg_ctx->video_stream->avg_frame_rate.num;
if(avg_frame_rate_num > 0) { if(avg_frame_rate_num > 0) {
int period = 1000 * (int64_t)ffmpeg_ctx->video_stream->avg_frame_rate.den int period = 1000 * (int64_t)ffmpeg_ctx->video_stream->avg_frame_rate.den
/ avg_frame_rate_num; / avg_frame_rate_num;
return period; return period;
} }

View File

@@ -163,9 +163,10 @@ static FT_Error font_face_requester(FTC_FaceID face_id,
lv_face_info_t * info = (lv_face_info_t *)face_id; lv_face_info_t * info = (lv_face_info_t *)face_id;
FT_Error error; FT_Error error;
if (info->mem) { if(info->mem) {
error = FT_New_Memory_Face(library, info->mem, info->size, 0, aface); error = FT_New_Memory_Face(library, info->mem, info->size, 0, aface);
} else { }
else {
error = FT_New_Face(library, info->name, 0, aface); error = FT_New_Face(library, info->name, 0, aface);
} }
if(error) { if(error) {
@@ -423,9 +424,10 @@ static bool lv_ft_font_init_nocache(lv_ft_info_t * info)
goto Fail; goto Fail;
} }
FT_Error error; FT_Error error;
if (info->mem) { if(info->mem) {
error = FT_New_Memory_Face(library, info->mem, (FT_Long) info->mem_size, 0, &face); error = FT_New_Memory_Face(library, info->mem, (FT_Long) info->mem_size, 0, &face);
} else { }
else {
error = FT_New_Face(library, info->name, 0, &face); error = FT_New_Face(library, info->name, 0, &face);
} }
if(error) { if(error) {

View File

@@ -110,7 +110,8 @@ static void * fs_open(lv_fs_drv_t * drv, const char * path, lv_fs_mode_t mode)
FRESULT res = f_open(f, path, flags); FRESULT res = f_open(f, path, flags);
if(res == FR_OK) { if(res == FR_OK) {
return f; return f;
} else { }
else {
lv_mem_free(f); lv_mem_free(f);
return NULL; return NULL;
} }
@@ -178,18 +179,18 @@ static lv_fs_res_t fs_write(lv_fs_drv_t * drv, void * file_p, const void * buf,
static lv_fs_res_t fs_seek(lv_fs_drv_t * drv, void * file_p, uint32_t pos, lv_fs_whence_t whence) static lv_fs_res_t fs_seek(lv_fs_drv_t * drv, void * file_p, uint32_t pos, lv_fs_whence_t whence)
{ {
LV_UNUSED(drv); LV_UNUSED(drv);
switch (whence) { switch(whence) {
case LV_FS_SEEK_SET: case LV_FS_SEEK_SET:
f_lseek(file_p, pos); f_lseek(file_p, pos);
break; break;
case LV_FS_SEEK_CUR: case LV_FS_SEEK_CUR:
f_lseek(file_p, f_tell(file_p) + pos); f_lseek(file_p, f_tell(file_p) + pos);
break; break;
case LV_FS_SEEK_END: case LV_FS_SEEK_END:
f_lseek(file_p, f_size(file_p) + pos); f_lseek(file_p, f_size(file_p) + pos);
break; break;
default: default:
break; break;
} }
return LV_FS_RES_OK; return LV_FS_RES_OK;
} }

View File

@@ -13,10 +13,10 @@
#include <fcntl.h> #include <fcntl.h>
#include <stdio.h> #include <stdio.h>
#ifndef WIN32 #ifndef WIN32
#include <dirent.h> #include <dirent.h>
#include <unistd.h> #include <unistd.h>
#else #else
#include <windows.h> #include <windows.h>
#endif #endif
/********************* /*********************
@@ -143,7 +143,7 @@ static lv_fs_res_t fs_read(lv_fs_drv_t * drv, void * file_p, void * buf, uint32_
{ {
LV_UNUSED(drv); LV_UNUSED(drv);
*br = read((lv_uintptr_t)file_p, buf, btr); *br = read((lv_uintptr_t)file_p, buf, btr);
return (int32_t)*br < 0 ? LV_FS_RES_UNKNOWN : LV_FS_RES_OK; return (int32_t)(*br) < 0 ? LV_FS_RES_UNKNOWN : LV_FS_RES_OK;
} }
/** /**
@@ -159,7 +159,7 @@ static lv_fs_res_t fs_write(lv_fs_drv_t * drv, void * file_p, const void * buf,
{ {
LV_UNUSED(drv); LV_UNUSED(drv);
*bw = write((lv_uintptr_t)file_p, buf, btw); *bw = write((lv_uintptr_t)file_p, buf, btw);
return (int32_t)*bw < 0 ? LV_FS_RES_UNKNOWN : LV_FS_RES_OK; return (int32_t)(*bw) < 0 ? LV_FS_RES_UNKNOWN : LV_FS_RES_OK;
} }
/** /**
@@ -193,7 +193,7 @@ static lv_fs_res_t fs_tell(lv_fs_drv_t * drv, void * file_p, uint32_t * pos_p)
} }
#ifdef WIN32 #ifdef WIN32
static char next_fn[256]; static char next_fn[256];
#endif #endif
/** /**
@@ -230,12 +230,14 @@ static void * fs_dir_open(lv_fs_drv_t * drv, const char * path)
strcpy(next_fn, ""); strcpy(next_fn, "");
d = FindFirstFile(buf, &fdata); d = FindFirstFile(buf, &fdata);
do { do {
if (strcmp(fdata.cFileName, ".") == 0 || strcmp(fdata.cFileName, "..") == 0) { if(strcmp(fdata.cFileName, ".") == 0 || strcmp(fdata.cFileName, "..") == 0) {
continue; continue;
} else { }
if (fdata.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) { else {
if(fdata.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
sprintf(next_fn, "/%s", fdata.cFileName); sprintf(next_fn, "/%s", fdata.cFileName);
} else { }
else {
sprintf(next_fn, "%s", fdata.cFileName); sprintf(next_fn, "%s", fdata.cFileName);
} }
break; break;
@@ -259,13 +261,14 @@ static lv_fs_res_t fs_dir_read(lv_fs_drv_t * drv, void * dir_p, char * fn)
LV_UNUSED(drv); LV_UNUSED(drv);
#ifndef WIN32 #ifndef WIN32
struct dirent *entry; struct dirent * entry;
do { do {
entry = readdir(dir_p); entry = readdir(dir_p);
if(entry) { if(entry) {
if(entry->d_type == DT_DIR) sprintf(fn, "/%s", entry->d_name); if(entry->d_type == DT_DIR) sprintf(fn, "/%s", entry->d_name);
else strcpy(fn, entry->d_name); else strcpy(fn, entry->d_name);
} else { }
else {
strcpy(fn, ""); strcpy(fn, "");
} }
} while(strcmp(fn, "/.") == 0 || strcmp(fn, "/..") == 0); } while(strcmp(fn, "/.") == 0 || strcmp(fn, "/..") == 0);
@@ -277,12 +280,14 @@ static lv_fs_res_t fs_dir_read(lv_fs_drv_t * drv, void * dir_p, char * fn)
if(FindNextFile(dir_p, &fdata) == false) return LV_FS_RES_OK; if(FindNextFile(dir_p, &fdata) == false) return LV_FS_RES_OK;
do { do {
if (strcmp(fdata.cFileName, ".") == 0 || strcmp(fdata.cFileName, "..") == 0) { if(strcmp(fdata.cFileName, ".") == 0 || strcmp(fdata.cFileName, "..") == 0) {
continue; continue;
} else { }
if (fdata.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) { else {
if(fdata.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
sprintf(next_fn, "/%s", fdata.cFileName); sprintf(next_fn, "/%s", fdata.cFileName);
} else { }
else {
sprintf(next_fn, "%s", fdata.cFileName); sprintf(next_fn, "%s", fdata.cFileName);
} }
break; break;

View File

@@ -12,10 +12,10 @@
#include <stdio.h> #include <stdio.h>
#ifndef WIN32 #ifndef WIN32
#include <dirent.h> #include <dirent.h>
#include <unistd.h> #include <unistd.h>
#else #else
#include <windows.h> #include <windows.h>
#endif #endif
/********************* /*********************
@@ -141,7 +141,7 @@ static lv_fs_res_t fs_read(lv_fs_drv_t * drv, void * file_p, void * buf, uint32_
{ {
LV_UNUSED(drv); LV_UNUSED(drv);
*br = fread(buf, 1, btr, file_p); *br = fread(buf, 1, btr, file_p);
return (int32_t)*br < 0 ? LV_FS_RES_UNKNOWN : LV_FS_RES_OK; return (int32_t)(*br) < 0 ? LV_FS_RES_UNKNOWN : LV_FS_RES_OK;
} }
/** /**
@@ -157,7 +157,7 @@ static lv_fs_res_t fs_write(lv_fs_drv_t * drv, void * file_p, const void * buf,
{ {
LV_UNUSED(drv); LV_UNUSED(drv);
*bw = fwrite(buf, 1, btw, file_p); *bw = fwrite(buf, 1, btw, file_p);
return (int32_t)*bw < 0 ? LV_FS_RES_UNKNOWN : LV_FS_RES_OK; return (int32_t)(*bw) < 0 ? LV_FS_RES_UNKNOWN : LV_FS_RES_OK;
} }
/** /**
@@ -191,7 +191,7 @@ static lv_fs_res_t fs_tell(lv_fs_drv_t * drv, void * file_p, uint32_t * pos_p)
} }
#ifdef WIN32 #ifdef WIN32
static char next_fn[256]; static char next_fn[256];
#endif #endif
/** /**
@@ -227,12 +227,14 @@ static void * fs_dir_open(lv_fs_drv_t * drv, const char * path)
strcpy(next_fn, ""); strcpy(next_fn, "");
d = FindFirstFile(buf, &fdata); d = FindFirstFile(buf, &fdata);
do { do {
if (strcmp(fdata.cFileName, ".") == 0 || strcmp(fdata.cFileName, "..") == 0) { if(strcmp(fdata.cFileName, ".") == 0 || strcmp(fdata.cFileName, "..") == 0) {
continue; continue;
} else { }
if (fdata.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) { else {
if(fdata.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
sprintf(next_fn, "/%s", fdata.cFileName); sprintf(next_fn, "/%s", fdata.cFileName);
} else { }
else {
sprintf(next_fn, "%s", fdata.cFileName); sprintf(next_fn, "%s", fdata.cFileName);
} }
break; break;
@@ -256,13 +258,14 @@ static lv_fs_res_t fs_dir_read(lv_fs_drv_t * drv, void * dir_p, char * fn)
LV_UNUSED(drv); LV_UNUSED(drv);
#ifndef WIN32 #ifndef WIN32
struct dirent *entry; struct dirent * entry;
do { do {
entry = readdir(dir_p); entry = readdir(dir_p);
if(entry) { if(entry) {
if(entry->d_type == DT_DIR) sprintf(fn, "/%s", entry->d_name); if(entry->d_type == DT_DIR) sprintf(fn, "/%s", entry->d_name);
else strcpy(fn, entry->d_name); else strcpy(fn, entry->d_name);
} else { }
else {
strcpy(fn, ""); strcpy(fn, "");
} }
} while(strcmp(fn, "/.") == 0 || strcmp(fn, "/..") == 0); } while(strcmp(fn, "/.") == 0 || strcmp(fn, "/..") == 0);
@@ -274,12 +277,14 @@ static lv_fs_res_t fs_dir_read(lv_fs_drv_t * drv, void * dir_p, char * fn)
if(FindNextFile(dir_p, &fdata) == false) return LV_FS_RES_OK; if(FindNextFile(dir_p, &fdata) == false) return LV_FS_RES_OK;
do { do {
if (strcmp(fdata.cFileName, ".") == 0 || strcmp(fdata.cFileName, "..") == 0) { if(strcmp(fdata.cFileName, ".") == 0 || strcmp(fdata.cFileName, "..") == 0) {
continue; continue;
} else { }
if (fdata.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) { else {
if(fdata.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
sprintf(next_fn, "/%s", fdata.cFileName); sprintf(next_fn, "/%s", fdata.cFileName);
} else { }
else {
sprintf(next_fn, "%s", fdata.cFileName); sprintf(next_fn, "%s", fdata.cFileName);
} }
break; break;

View File

@@ -101,7 +101,7 @@ static lv_fs_res_t fs_error_from_win32(DWORD error)
{ {
lv_fs_res_t res; lv_fs_res_t res;
switch (error) { switch(error) {
case ERROR_SUCCESS: case ERROR_SUCCESS:
res = LV_FS_RES_OK; res = LV_FS_RES_OK;
break; break;
@@ -199,11 +199,11 @@ static void * fs_open(lv_fs_drv_t * drv, const char * path, lv_fs_mode_t mode)
DWORD desired_access = 0; DWORD desired_access = 0;
if (mode & LV_FS_MODE_RD) { if(mode & LV_FS_MODE_RD) {
desired_access |= GENERIC_READ; desired_access |= GENERIC_READ;
} }
if (mode & LV_FS_MODE_WR) { if(mode & LV_FS_MODE_WR) {
desired_access |= GENERIC_WRITE; desired_access |= GENERIC_WRITE;
} }
@@ -214,18 +214,18 @@ static void * fs_open(lv_fs_drv_t * drv, const char * path, lv_fs_mode_t mode)
sprintf(buf, LV_FS_WIN32_PATH "%s", path); sprintf(buf, LV_FS_WIN32_PATH "%s", path);
#endif #endif
return (void*)CreateFileA( return (void *)CreateFileA(
#ifdef LV_FS_WIN32_PATH #ifdef LV_FS_WIN32_PATH
buf, buf,
#else #else
path, path,
#endif #endif
desired_access, desired_access,
FILE_SHARE_READ, FILE_SHARE_READ,
NULL, NULL,
OPEN_EXISTING, OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL, FILE_ATTRIBUTE_NORMAL,
NULL); NULL);
} }
/** /**
@@ -239,8 +239,8 @@ static lv_fs_res_t fs_close(lv_fs_drv_t * drv, void * file_p)
{ {
LV_UNUSED(drv); LV_UNUSED(drv);
return CloseHandle((HANDLE)file_p) return CloseHandle((HANDLE)file_p)
? LV_FS_RES_OK ? LV_FS_RES_OK
: fs_error_from_win32(GetLastError()); : fs_error_from_win32(GetLastError());
} }
/** /**
@@ -257,8 +257,8 @@ static lv_fs_res_t fs_read(lv_fs_drv_t * drv, void * file_p, void * buf, uint32_
{ {
LV_UNUSED(drv); LV_UNUSED(drv);
return ReadFile((HANDLE)file_p, buf, btr, (LPDWORD)br, NULL) return ReadFile((HANDLE)file_p, buf, btr, (LPDWORD)br, NULL)
? LV_FS_RES_OK ? LV_FS_RES_OK
: fs_error_from_win32(GetLastError()); : fs_error_from_win32(GetLastError());
} }
/** /**
@@ -274,8 +274,8 @@ static lv_fs_res_t fs_write(lv_fs_drv_t * drv, void * file_p, const void * buf,
{ {
LV_UNUSED(drv); LV_UNUSED(drv);
return WriteFile((HANDLE)file_p, buf, btw, (LPDWORD)bw, NULL) return WriteFile((HANDLE)file_p, buf, btw, (LPDWORD)bw, NULL)
? LV_FS_RES_OK ? LV_FS_RES_OK
: fs_error_from_win32(GetLastError()); : fs_error_from_win32(GetLastError());
} }
/** /**
@@ -290,8 +290,8 @@ static lv_fs_res_t fs_seek(lv_fs_drv_t * drv, void * file_p, uint32_t pos, lv_fs
{ {
LV_UNUSED(drv); LV_UNUSED(drv);
DWORD move_method = (DWORD)-1; DWORD move_method = (DWORD) -1;
if (whence == LV_FS_SEEK_SET) { if(whence == LV_FS_SEEK_SET) {
move_method = FILE_BEGIN; move_method = FILE_BEGIN;
} }
else if(whence == LV_FS_SEEK_CUR) { else if(whence == LV_FS_SEEK_CUR) {
@@ -304,8 +304,8 @@ static lv_fs_res_t fs_seek(lv_fs_drv_t * drv, void * file_p, uint32_t pos, lv_fs
LARGE_INTEGER distance_to_move; LARGE_INTEGER distance_to_move;
distance_to_move.QuadPart = pos; distance_to_move.QuadPart = pos;
return SetFilePointerEx((HANDLE)file_p, distance_to_move, NULL, move_method) return SetFilePointerEx((HANDLE)file_p, distance_to_move, NULL, move_method)
? LV_FS_RES_OK ? LV_FS_RES_OK
: fs_error_from_win32(GetLastError()); : fs_error_from_win32(GetLastError());
} }
/** /**
@@ -320,7 +320,7 @@ static lv_fs_res_t fs_tell(lv_fs_drv_t * drv, void * file_p, uint32_t * pos_p)
{ {
LV_UNUSED(drv); LV_UNUSED(drv);
if (!pos_p) { if(!pos_p) {
return LV_FS_RES_INV_PARAM; return LV_FS_RES_INV_PARAM;
} }
@@ -329,12 +329,12 @@ static lv_fs_res_t fs_tell(lv_fs_drv_t * drv, void * file_p, uint32_t * pos_p)
LARGE_INTEGER distance_to_move; LARGE_INTEGER distance_to_move;
distance_to_move.QuadPart = 0; distance_to_move.QuadPart = 0;
if (SetFilePointerEx( if(SetFilePointerEx(
(HANDLE)file_p, (HANDLE)file_p,
distance_to_move, distance_to_move,
&file_pointer, &file_pointer,
FILE_CURRENT)) { FILE_CURRENT)) {
if (file_pointer.QuadPart > LONG_MAX) { if(file_pointer.QuadPart > LONG_MAX) {
return LV_FS_RES_INV_PARAM; return LV_FS_RES_INV_PARAM;
} }
else { else {
@@ -374,11 +374,11 @@ static void * fs_dir_open(lv_fs_drv_t * drv, const char * path)
strcpy(next_fn, ""); strcpy(next_fn, "");
d = FindFirstFileA(buf, &fdata); d = FindFirstFileA(buf, &fdata);
do { do {
if (is_dots_name(fdata.cFileName)) { if(is_dots_name(fdata.cFileName)) {
continue; continue;
} }
else { else {
if (fdata.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) { if(fdata.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
sprintf(next_fn, "/%s", fdata.cFileName); sprintf(next_fn, "/%s", fdata.cFileName);
} }
else { else {
@@ -387,7 +387,7 @@ static void * fs_dir_open(lv_fs_drv_t * drv, const char * path)
break; break;
} }
} while (FindNextFileA(d, &fdata)); } while(FindNextFileA(d, &fdata));
next_error = fs_error_from_win32(GetLastError()); next_error = fs_error_from_win32(GetLastError());
return d; return d;
@@ -412,12 +412,12 @@ static lv_fs_res_t fs_dir_read(lv_fs_drv_t * drv, void * dir_p, char * fn)
strcpy(next_fn, ""); strcpy(next_fn, "");
WIN32_FIND_DATAA fdata; WIN32_FIND_DATAA fdata;
while (FindNextFileA(dir_p, &fdata)) { while(FindNextFileA(dir_p, &fdata)) {
if (is_dots_name(fdata.cFileName)) { if(is_dots_name(fdata.cFileName)) {
continue; continue;
} }
else { else {
if (fdata.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) { if(fdata.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
sprintf(next_fn, "/%s", fdata.cFileName); sprintf(next_fn, "/%s", fdata.cFileName);
} }
else { else {
@@ -427,7 +427,7 @@ static lv_fs_res_t fs_dir_read(lv_fs_drv_t * drv, void * dir_p, char * fn)
} }
} }
if (next_fn[0] == '\0') { if(next_fn[0] == '\0') {
next_error = fs_error_from_win32(GetLastError()); next_error = fs_error_from_win32(GetLastError());
} }
@@ -444,8 +444,8 @@ static lv_fs_res_t fs_dir_close(lv_fs_drv_t * drv, void * dir_p)
{ {
LV_UNUSED(drv); LV_UNUSED(drv);
return FindClose((HANDLE)dir_p) return FindClose((HANDLE)dir_p)
? LV_FS_RES_OK ? LV_FS_RES_OK
: fs_error_from_win32(GetLastError()); : fs_error_from_win32(GetLastError());
} }
#endif /*LV_USE_FS_WIN32*/ #endif /*LV_USE_FS_WIN32*/

View File

@@ -28,19 +28,19 @@ extern "C" {
**********************/ **********************/
#if LV_USE_FS_FATFS != '\0' #if LV_USE_FS_FATFS != '\0'
void lv_fs_fatfs_init(void); void lv_fs_fatfs_init(void);
#endif #endif
#if LV_USE_FS_STDIO != '\0' #if LV_USE_FS_STDIO != '\0'
void lv_fs_stdio_init(void); void lv_fs_stdio_init(void);
#endif #endif
#if LV_USE_FS_POSIX != '\0' #if LV_USE_FS_POSIX != '\0'
void lv_fs_posix_init(void); void lv_fs_posix_init(void);
#endif #endif
#if LV_USE_FS_WIN32 != '\0' #if LV_USE_FS_WIN32 != '\0'
void lv_fs_win32_init(void); void lv_fs_win32_init(void);
#endif #endif
/********************** /**********************

View File

@@ -69,29 +69,29 @@ void lv_gif_set_src(lv_obj_t * obj, const void * src)
if(lv_img_src_get_type(src) == LV_IMG_SRC_VARIABLE) { if(lv_img_src_get_type(src) == LV_IMG_SRC_VARIABLE) {
const lv_img_dsc_t * img_dsc = src; const lv_img_dsc_t * img_dsc = src;
gifobj->gif = gd_open_gif_data(img_dsc->data); gifobj->gif = gd_open_gif_data(img_dsc->data);
} }
else if(lv_img_src_get_type(src) == LV_IMG_SRC_FILE) { else if(lv_img_src_get_type(src) == LV_IMG_SRC_FILE) {
gifobj->gif = gd_open_gif_file(src); gifobj->gif = gd_open_gif_file(src);
} }
if(gifobj->gif == NULL) { if(gifobj->gif == NULL) {
LV_LOG_WARN("Could't load the source"); LV_LOG_WARN("Could't load the source");
return; return;
} }
gifobj->imgdsc.data = gifobj->gif->canvas; gifobj->imgdsc.data = gifobj->gif->canvas;
gifobj->imgdsc.header.always_zero = 0; gifobj->imgdsc.header.always_zero = 0;
gifobj->imgdsc.header.cf = LV_IMG_CF_TRUE_COLOR_ALPHA; gifobj->imgdsc.header.cf = LV_IMG_CF_TRUE_COLOR_ALPHA;
gifobj->imgdsc.header.h = gifobj->gif->height; gifobj->imgdsc.header.h = gifobj->gif->height;
gifobj->imgdsc.header.w = gifobj->gif->width; gifobj->imgdsc.header.w = gifobj->gif->width;
gifobj->last_call = lv_tick_get(); gifobj->last_call = lv_tick_get();
lv_img_set_src(obj, &gifobj->imgdsc); lv_img_set_src(obj, &gifobj->imgdsc);
lv_timer_resume(gifobj->timer); lv_timer_resume(gifobj->timer);
lv_timer_reset(gifobj->timer); lv_timer_reset(gifobj->timer);
next_frame_task_cb(gifobj->timer); next_frame_task_cb(gifobj->timer);
} }
@@ -139,7 +139,8 @@ static void next_frame_task_cb(lv_timer_t * t)
if(gifobj->gif->loop_count == 1) { if(gifobj->gif->loop_count == 1) {
lv_res_t res = lv_event_send(obj, LV_EVENT_READY, NULL); lv_res_t res = lv_event_send(obj, LV_EVENT_READY, NULL);
if(res != LV_FS_RES_OK) return; if(res != LV_FS_RES_OK) return;
} else { }
else {
if(gifobj->gif->loop_count > 1) gifobj->gif->loop_count--; if(gifobj->gif->loop_count > 1) gifobj->gif->loop_count--;
gd_rewind(gifobj->gif); gd_rewind(gifobj->gif);
} }

View File

@@ -29,11 +29,11 @@ extern "C" {
typedef struct { typedef struct {
lv_img_t img; lv_img_t img;
gd_GIF *gif; gd_GIF * gif;
lv_timer_t * timer; lv_timer_t * timer;
lv_img_dsc_t imgdsc; lv_img_dsc_t imgdsc;
uint32_t last_call; uint32_t last_call;
}lv_gif_t; } lv_gif_t;
extern const lv_obj_class_t lv_gif_class; extern const lv_obj_class_t lv_gif_class;

View File

@@ -65,47 +65,47 @@ void lv_png_init(void)
static lv_res_t decoder_info(struct _lv_img_decoder_t * decoder, const void * src, lv_img_header_t * header) static lv_res_t decoder_info(struct _lv_img_decoder_t * decoder, const void * src, lv_img_header_t * header)
{ {
(void) decoder; /*Unused*/ (void) decoder; /*Unused*/
lv_img_src_t src_type = lv_img_src_get_type(src); /*Get the source type*/ lv_img_src_t src_type = lv_img_src_get_type(src); /*Get the source type*/
/*If it's a PNG file...*/ /*If it's a PNG file...*/
if(src_type == LV_IMG_SRC_FILE) { if(src_type == LV_IMG_SRC_FILE) {
const char * fn = src; const char * fn = src;
if(!strcmp(&fn[strlen(fn) - 3], "png")) { /*Check the extension*/ if(!strcmp(&fn[strlen(fn) - 3], "png")) { /*Check the extension*/
/* Read the width and height from the file. They have a constant location: /* Read the width and height from the file. They have a constant location:
* [16..23]: width * [16..23]: width
* [24..27]: height * [24..27]: height
*/ */
uint32_t size[2]; uint32_t size[2];
lv_fs_file_t f; lv_fs_file_t f;
lv_fs_res_t res = lv_fs_open(&f, fn, LV_FS_MODE_RD); lv_fs_res_t res = lv_fs_open(&f, fn, LV_FS_MODE_RD);
if(res != LV_FS_RES_OK) return LV_RES_INV; if(res != LV_FS_RES_OK) return LV_RES_INV;
lv_fs_seek(&f, 16, LV_FS_SEEK_SET); lv_fs_seek(&f, 16, LV_FS_SEEK_SET);
uint32_t rn; uint32_t rn;
lv_fs_read(&f, &size, 8, &rn); lv_fs_read(&f, &size, 8, &rn);
if(rn != 8) return LV_RES_INV; if(rn != 8) return LV_RES_INV;
lv_fs_close(&f); lv_fs_close(&f);
/*Save the data in the header*/ /*Save the data in the header*/
header->always_zero = 0; header->always_zero = 0;
header->cf = LV_IMG_CF_RAW_ALPHA; header->cf = LV_IMG_CF_RAW_ALPHA;
/*The width and height are stored in Big endian format so convert them to little endian*/ /*The width and height are stored in Big endian format so convert them to little endian*/
header->w = (lv_coord_t) ((size[0] & 0xff000000) >> 24) + ((size[0] & 0x00ff0000) >> 8); header->w = (lv_coord_t)((size[0] & 0xff000000) >> 24) + ((size[0] & 0x00ff0000) >> 8);
header->h = (lv_coord_t) ((size[1] & 0xff000000) >> 24) + ((size[1] & 0x00ff0000) >> 8); header->h = (lv_coord_t)((size[1] & 0xff000000) >> 24) + ((size[1] & 0x00ff0000) >> 8);
return LV_RES_OK; return LV_RES_OK;
} }
} }
/*If it's a PNG file in a C array...*/ /*If it's a PNG file in a C array...*/
else if(src_type == LV_IMG_SRC_VARIABLE) { else if(src_type == LV_IMG_SRC_VARIABLE) {
const lv_img_dsc_t * img_dsc = src; const lv_img_dsc_t * img_dsc = src;
header->always_zero = 0; header->always_zero = 0;
header->cf = img_dsc->header.cf; /*Save the color format*/ header->cf = img_dsc->header.cf; /*Save the color format*/
header->w = img_dsc->header.w; /*Save the color width*/ header->w = img_dsc->header.w; /*Save the color width*/
header->h = img_dsc->header.h; /*Save the color height*/ header->h = img_dsc->header.h; /*Save the color height*/
return LV_RES_OK; return LV_RES_OK;
} }
return LV_RES_INV; /*If didn't succeeded earlier then it's an error*/ return LV_RES_INV; /*If didn't succeeded earlier then it's an error*/
} }
@@ -183,10 +183,10 @@ static lv_res_t decoder_open(lv_img_decoder_t * decoder, lv_img_decoder_dsc_t *
/** /**
* Free the allocated resources * Free the allocated resources
*/ */
static void decoder_close(lv_img_decoder_t *decoder, lv_img_decoder_dsc_t *dsc) static void decoder_close(lv_img_decoder_t * decoder, lv_img_decoder_dsc_t * dsc)
{ {
LV_UNUSED(decoder); /*Unused*/ LV_UNUSED(decoder); /*Unused*/
if (dsc->img_data) { if(dsc->img_data) {
lv_mem_free((uint8_t *)dsc->img_data); lv_mem_free((uint8_t *)dsc->img_data);
dsc->img_data = NULL; dsc->img_data = NULL;
} }
@@ -200,7 +200,7 @@ static void decoder_close(lv_img_decoder_t *decoder, lv_img_decoder_dsc_t *dsc)
static void convert_color_depth(uint8_t * img, uint32_t px_cnt) static void convert_color_depth(uint8_t * img, uint32_t px_cnt)
{ {
#if LV_COLOR_DEPTH == 32 #if LV_COLOR_DEPTH == 32
lv_color32_t * img_argb = (lv_color32_t*)img; lv_color32_t * img_argb = (lv_color32_t *)img;
lv_color_t c; lv_color_t c;
lv_color_t * img_c = (lv_color_t *) img; lv_color_t * img_c = (lv_color_t *) img;
uint32_t i; uint32_t i;
@@ -210,32 +210,32 @@ static void convert_color_depth(uint8_t * img, uint32_t px_cnt)
img_c[i].ch.blue = c.ch.red; img_c[i].ch.blue = c.ch.red;
} }
#elif LV_COLOR_DEPTH == 16 #elif LV_COLOR_DEPTH == 16
lv_color32_t * img_argb = (lv_color32_t*)img; lv_color32_t * img_argb = (lv_color32_t *)img;
lv_color_t c; lv_color_t c;
uint32_t i; uint32_t i;
for(i = 0; i < px_cnt; i++) { for(i = 0; i < px_cnt; i++) {
c = lv_color_make(img_argb[i].ch.blue, img_argb[i].ch.green, img_argb[i].ch.red); c = lv_color_make(img_argb[i].ch.blue, img_argb[i].ch.green, img_argb[i].ch.red);
img[i*3 + 2] = img_argb[i].ch.alpha; img[i * 3 + 2] = img_argb[i].ch.alpha;
img[i*3 + 1] = c.full >> 8; img[i * 3 + 1] = c.full >> 8;
img[i*3 + 0] = c.full & 0xFF; img[i * 3 + 0] = c.full & 0xFF;
} }
#elif LV_COLOR_DEPTH == 8 #elif LV_COLOR_DEPTH == 8
lv_color32_t * img_argb = (lv_color32_t*)img; lv_color32_t * img_argb = (lv_color32_t *)img;
lv_color_t c; lv_color_t c;
uint32_t i; uint32_t i;
for(i = 0; i < px_cnt; i++) { for(i = 0; i < px_cnt; i++) {
c = lv_color_make(img_argb[i].ch.red, img_argb[i].ch.green, img_argb[i].ch.blue); c = lv_color_make(img_argb[i].ch.red, img_argb[i].ch.green, img_argb[i].ch.blue);
img[i*2 + 1] = img_argb[i].ch.alpha; img[i * 2 + 1] = img_argb[i].ch.alpha;
img[i*2 + 0] = c.full; img[i * 2 + 0] = c.full;
} }
#elif LV_COLOR_DEPTH == 1 #elif LV_COLOR_DEPTH == 1
lv_color32_t * img_argb = (lv_color32_t*)img; lv_color32_t * img_argb = (lv_color32_t *)img;
uint8_t b; uint8_t b;
uint32_t i; uint32_t i;
for(i = 0; i < px_cnt; i++) { for(i = 0; i < px_cnt; i++) {
b = img_argb[i].ch.red | img_argb[i].ch.green | img_argb[i].ch.blue; b = img_argb[i].ch.red | img_argb[i].ch.green | img_argb[i].ch.blue;
img[i*2 + 1] = img_argb[i].ch.alpha; img[i * 2 + 1] = img_argb[i].ch.alpha;
img[i*2 + 0] = b > 128 ? 1 : 0; img[i * 2 + 0] = b > 128 ? 1 : 0;
} }
#endif #endif
} }

View File

@@ -88,18 +88,18 @@ lv_res_t lv_qrcode_update(lv_obj_t * qrcode, const void * data, uint32_t data_le
lv_img_dsc_t * imgdsc = lv_canvas_get_img(qrcode); lv_img_dsc_t * imgdsc = lv_canvas_get_img(qrcode);
int32_t qr_version = qrcodegen_getMinFitVersion(qrcodegen_Ecc_MEDIUM, data_len); int32_t qr_version = qrcodegen_getMinFitVersion(qrcodegen_Ecc_MEDIUM, data_len);
if (qr_version <= 0) return LV_RES_INV; if(qr_version <= 0) return LV_RES_INV;
int32_t qr_size = qrcodegen_version2size(qr_version); int32_t qr_size = qrcodegen_version2size(qr_version);
if (qr_size <= 0) return LV_RES_INV; if(qr_size <= 0) return LV_RES_INV;
int32_t scale = imgdsc->header.w / qr_size; int32_t scale = imgdsc->header.w / qr_size;
if (scale <= 0) return LV_RES_INV; if(scale <= 0) return LV_RES_INV;
int32_t remain = imgdsc->header.w % qr_size; int32_t remain = imgdsc->header.w % qr_size;
/* The qr version is incremented by four point */ /* The qr version is incremented by four point */
uint32_t version_extend = remain / (scale << 2); uint32_t version_extend = remain / (scale << 2);
if (version_extend && qr_version < qrcodegen_VERSION_MAX) { if(version_extend && qr_version < qrcodegen_VERSION_MAX) {
qr_version = qr_version + version_extend > qrcodegen_VERSION_MAX ? qr_version = qr_version + version_extend > qrcodegen_VERSION_MAX ?
qrcodegen_VERSION_MAX : qr_version + version_extend; qrcodegen_VERSION_MAX : qr_version + version_extend;
} }
uint8_t * qr0 = lv_mem_alloc(qrcodegen_BUFFER_LEN_FOR_VERSION(qr_version)); uint8_t * qr0 = lv_mem_alloc(qrcodegen_BUFFER_LEN_FOR_VERSION(qr_version));
@@ -109,11 +109,11 @@ lv_res_t lv_qrcode_update(lv_obj_t * qrcode, const void * data, uint32_t data_le
memcpy(data_tmp, data, data_len); memcpy(data_tmp, data, data_len);
bool ok = qrcodegen_encodeBinary(data_tmp, data_len, bool ok = qrcodegen_encodeBinary(data_tmp, data_len,
qr0, qrcodegen_Ecc_MEDIUM, qr0, qrcodegen_Ecc_MEDIUM,
qr_version, qr_version, qr_version, qr_version,
qrcodegen_Mask_AUTO, true); qrcodegen_Mask_AUTO, true);
if (!ok) { if(!ok) {
lv_mem_free(qr0); lv_mem_free(qr0);
lv_mem_free(data_tmp); lv_mem_free(data_tmp);
return LV_RES_INV; return LV_RES_INV;
@@ -131,12 +131,12 @@ lv_res_t lv_qrcode_update(lv_obj_t * qrcode, const void * data, uint32_t data_le
* So buffer 1 byte (8 px) from the qr code and set it in the canvas image */ * So buffer 1 byte (8 px) from the qr code and set it in the canvas image */
uint32_t row_byte_cnt = (imgdsc->header.w + 7) >> 3; uint32_t row_byte_cnt = (imgdsc->header.w + 7) >> 3;
int y; int y;
for (y = margin; y < scaled + margin; y+=scale) { for(y = margin; y < scaled + margin; y += scale) {
uint8_t b = 0; uint8_t b = 0;
uint8_t p = 0; uint8_t p = 0;
bool aligned = false; bool aligned = false;
int x; int x;
for (x = margin; x < scaled + margin; x++) { for(x = margin; x < scaled + margin; x++) {
bool a = qrcodegen_getModule(qr0, (x - margin) / scale, (y - margin) / scale); bool a = qrcodegen_getModule(qr0, (x - margin) / scale, (y - margin) / scale);
if(aligned == false && (x & 0x7) == 0) aligned = true; if(aligned == false && (x & 0x7) == 0) aligned = true;
@@ -144,7 +144,8 @@ lv_res_t lv_qrcode_update(lv_obj_t * qrcode, const void * data, uint32_t data_le
if(aligned == false) { if(aligned == false) {
c.full = a ? 0 : 1; c.full = a ? 0 : 1;
lv_canvas_set_px_color(qrcode, x, y, c); lv_canvas_set_px_color(qrcode, x, y, c);
} else { }
else {
if(!a) b |= (1 << (7 - p)); if(!a) b |= (1 << (7 - p));
p++; p++;
if(p == 8) { if(p == 8) {
@@ -165,12 +166,12 @@ lv_res_t lv_qrcode_update(lv_obj_t * qrcode, const void * data, uint32_t data_le
buf_u8[px] = b; buf_u8[px] = b;
} }
/*The Qr is probably scaled so simply to the repeated rows*/ /*The Qr is probably scaled so simply to the repeated rows*/
int s; int s;
const uint8_t * row_ori = buf_u8 + row_byte_cnt * y; const uint8_t * row_ori = buf_u8 + row_byte_cnt * y;
for(s = 1; s < scale; s++) { for(s = 1; s < scale; s++) {
memcpy((uint8_t*)buf_u8 + row_byte_cnt * (y + s), row_ori, row_byte_cnt); memcpy((uint8_t *)buf_u8 + row_byte_cnt * (y + s), row_ori, row_byte_cnt);
} }
} }
lv_mem_free(qr0); lv_mem_free(qr0);
@@ -210,7 +211,7 @@ static void lv_qrcode_destructor(const lv_obj_class_t * class_p, lv_obj_t * obj)
lv_img_dsc_t * img = lv_canvas_get_img(obj); lv_img_dsc_t * img = lv_canvas_get_img(obj);
lv_img_cache_invalidate_src(img); lv_img_cache_invalidate_src(img);
lv_mem_free((void*)img->data); lv_mem_free((void *)img->data);
img->data = NULL; img->data = NULL;
} }

View File

@@ -3,9 +3,9 @@
* *
*/ */
/********************* /*********************
* INCLUDES * INCLUDES
*********************/ *********************/
#include "lv_rlottie.h" #include "lv_rlottie.h"
#if LV_USE_RLOTTIE #if LV_USE_RLOTTIE
@@ -24,7 +24,7 @@
**********************/ **********************/
static void lv_rlottie_constructor(const lv_obj_class_t * class_p, lv_obj_t * obj); static void lv_rlottie_constructor(const lv_obj_class_t * class_p, lv_obj_t * obj);
static void lv_rlottie_destructor(const lv_obj_class_t * class_p, lv_obj_t * obj); static void lv_rlottie_destructor(const lv_obj_class_t * class_p, lv_obj_t * obj);
static void next_frame_task_cb(lv_timer_t* t); static void next_frame_task_cb(lv_timer_t * t);
/********************** /**********************
* STATIC VARIABLES * STATIC VARIABLES
@@ -38,18 +38,18 @@ const lv_obj_class_t lv_rlottie_class = {
static lv_coord_t create_width; static lv_coord_t create_width;
static lv_coord_t create_height; static lv_coord_t create_height;
static const char* rlottie_desc_create; static const char * rlottie_desc_create;
static const char* path_create; static const char * path_create;
/********************** /**********************
* MACROS * MACROS
**********************/ **********************/
/********************** /**********************
* GLOBAL FUNCTIONS * GLOBAL FUNCTIONS
**********************/ **********************/
lv_obj_t* lv_rlottie_create_from_file(lv_obj_t* parent, lv_coord_t width, lv_coord_t height, const char* path) lv_obj_t * lv_rlottie_create_from_file(lv_obj_t * parent, lv_coord_t width, lv_coord_t height, const char * path)
{ {
create_width = width; create_width = width;
@@ -65,7 +65,7 @@ lv_obj_t* lv_rlottie_create_from_file(lv_obj_t* parent, lv_coord_t width, lv_coo
} }
lv_obj_t* lv_rlottie_create_from_raw(lv_obj_t* parent, lv_coord_t width, lv_coord_t height, const char* rlottie_desc) lv_obj_t * lv_rlottie_create_from_raw(lv_obj_t * parent, lv_coord_t width, lv_coord_t height, const char * rlottie_desc)
{ {
create_width = width; create_width = width;
@@ -90,12 +90,12 @@ static void lv_rlottie_constructor(const lv_obj_class_t * class_p, lv_obj_t * ob
lv_rlottie_t * rlottie = (lv_rlottie_t *) obj; lv_rlottie_t * rlottie = (lv_rlottie_t *) obj;
if(rlottie_desc_create) { if(rlottie_desc_create) {
rlottie->animation = lottie_animation_from_data(rlottie_desc_create, rlottie_desc_create,""); rlottie->animation = lottie_animation_from_data(rlottie_desc_create, rlottie_desc_create, "");
} }
else if(path_create) { else if(path_create) {
rlottie->animation = lottie_animation_from_file(path_create); rlottie->animation = lottie_animation_from_file(path_create);
} }
if (rlottie->animation == NULL) { if(rlottie->animation == NULL) {
LV_LOG_WARN("The aniamtion can't be opened"); LV_LOG_WARN("The aniamtion can't be opened");
return; return;
} }
@@ -108,8 +108,7 @@ static void lv_rlottie_constructor(const lv_obj_class_t * class_p, lv_obj_t * ob
size_t allocaled_buf_size = (create_width * create_height * LV_COLOR_DEPTH / 8); size_t allocaled_buf_size = (create_width * create_height * LV_COLOR_DEPTH / 8);
rlottie->allocated_buf = lv_mem_alloc(allocaled_buf_size); rlottie->allocated_buf = lv_mem_alloc(allocaled_buf_size);
if (rlottie->allocated_buf != NULL) if(rlottie->allocated_buf != NULL) {
{
rlottie->allocated_buffer_size = allocaled_buf_size; rlottie->allocated_buffer_size = allocaled_buf_size;
memset(rlottie->allocated_buf, 0, allocaled_buf_size); memset(rlottie->allocated_buf, 0, allocaled_buf_size);
} }
@@ -118,7 +117,7 @@ static void lv_rlottie_constructor(const lv_obj_class_t * class_p, lv_obj_t * ob
rlottie->imgdsc.header.cf = LV_IMG_CF_TRUE_COLOR_ALPHA; rlottie->imgdsc.header.cf = LV_IMG_CF_TRUE_COLOR_ALPHA;
rlottie->imgdsc.header.h = create_height; rlottie->imgdsc.header.h = create_height;
rlottie->imgdsc.header.w = create_width; rlottie->imgdsc.header.w = create_width;
rlottie->imgdsc.data = (void*)rlottie->allocated_buf; rlottie->imgdsc.data = (void *)rlottie->allocated_buf;
rlottie->imgdsc.data_size = allocaled_buf_size; rlottie->imgdsc.data_size = allocaled_buf_size;
lv_img_set_src(obj, &rlottie->imgdsc); lv_img_set_src(obj, &rlottie->imgdsc);
@@ -129,12 +128,12 @@ static void lv_rlottie_constructor(const lv_obj_class_t * class_p, lv_obj_t * ob
} }
static void lv_rlottie_destructor(const lv_obj_class_t * class_p, lv_obj_t* obj) static void lv_rlottie_destructor(const lv_obj_class_t * class_p, lv_obj_t * obj)
{ {
lv_rlottie_t * rlottie = (lv_rlottie_t *) obj; lv_rlottie_t * rlottie = (lv_rlottie_t *) obj;
if (rlottie->animation) { if(rlottie->animation) {
lottie_animation_destroy(rlottie->animation); lottie_animation_destroy(rlottie->animation);
rlottie->animation = 0; rlottie->animation = 0;
rlottie->current_frame = 0; rlottie->current_frame = 0;
@@ -143,12 +142,12 @@ static void lv_rlottie_destructor(const lv_obj_class_t * class_p, lv_obj_t* obj)
rlottie->total_frames = 0; rlottie->total_frames = 0;
} }
if (rlottie->task){ if(rlottie->task) {
lv_timer_del(rlottie->task); lv_timer_del(rlottie->task);
rlottie->task = NULL; rlottie->task = NULL;
} }
if (rlottie->allocated_buf) { if(rlottie->allocated_buf) {
lv_mem_free(rlottie->allocated_buf); lv_mem_free(rlottie->allocated_buf);
rlottie->allocated_buf = NULL; rlottie->allocated_buf = NULL;
rlottie->allocated_buffer_size = 0; rlottie->allocated_buffer_size = 0;
@@ -156,22 +155,22 @@ static void lv_rlottie_destructor(const lv_obj_class_t * class_p, lv_obj_t* obj)
} }
static void next_frame_task_cb(lv_timer_t* t) static void next_frame_task_cb(lv_timer_t * t)
{ {
lv_obj_t* obj = t->user_data; lv_obj_t * obj = t->user_data;
lv_rlottie_t * rlottie = (lv_rlottie_t *) obj; lv_rlottie_t * rlottie = (lv_rlottie_t *) obj;
if (rlottie->current_frame == rlottie->total_frames) if(rlottie->current_frame == rlottie->total_frames)
rlottie->current_frame = 0; rlottie->current_frame = 0;
else else
++rlottie->current_frame; ++rlottie->current_frame;
lottie_animation_render( lottie_animation_render(
rlottie->animation, rlottie->animation,
rlottie->current_frame, rlottie->current_frame,
rlottie->allocated_buf, rlottie->allocated_buf,
rlottie->imgdsc.header.w, rlottie->imgdsc.header.w,
rlottie->imgdsc.header.h, rlottie->imgdsc.header.h,
rlottie->scanline_width rlottie->scanline_width
); );
lv_obj_invalidate(obj); lv_obj_invalidate(obj);

View File

@@ -27,16 +27,16 @@ extern "C" {
**********************/ **********************/
typedef struct { typedef struct {
lv_img_t img_ext; lv_img_t img_ext;
Lottie_Animation* animation; Lottie_Animation * animation;
lv_timer_t* task; lv_timer_t * task;
lv_img_dsc_t imgdsc; lv_img_dsc_t imgdsc;
size_t total_frames; size_t total_frames;
size_t current_frame; size_t current_frame;
size_t framerate; size_t framerate;
uint32_t* allocated_buf; uint32_t * allocated_buf;
size_t allocated_buffer_size; size_t allocated_buffer_size;
size_t scanline_width; size_t scanline_width;
}lv_rlottie_t; } lv_rlottie_t;
extern const lv_obj_class_t lv_rlottie_class; extern const lv_obj_class_t lv_rlottie_class;
@@ -44,9 +44,10 @@ extern const lv_obj_class_t lv_rlottie_class;
* GLOBAL PROTOTYPES * GLOBAL PROTOTYPES
**********************/ **********************/
lv_obj_t * lv_rlottie_create_from_file(lv_obj_t * parent,lv_coord_t width, lv_coord_t height, const char * path); lv_obj_t * lv_rlottie_create_from_file(lv_obj_t * parent, lv_coord_t width, lv_coord_t height, const char * path);
lv_obj_t* lv_rlottie_create_from_raw(lv_obj_t* parent, lv_coord_t width, lv_coord_t height, const char* rlottie_desc); lv_obj_t * lv_rlottie_create_from_raw(lv_obj_t * parent, lv_coord_t width, lv_coord_t height,
const char * rlottie_desc);
/********************** /**********************
* MACROS * MACROS

View File

@@ -36,9 +36,9 @@
/---------------------------------------------------------------------------------------------------------------------------------- /----------------------------------------------------------------------------------------------------------------------------------
/ JPEG DECODER / JPEG DECODER
/ ------------ / ------------
/ We are using TJpgDec - Tiny JPEG Decompressor library from ELM-CHAN for decoding each split-jpeg fragments. / We are using TJpgDec - Tiny JPEG Decompressor library from ELM-CHAN for decoding each split-jpeg fragments.
/ The tjpgd.c and tjpgd.h is not modified and those are used as it is. So if any update comes for the tiny-jpeg, / The tjpgd.c and tjpgd.h is not modified and those are used as it is. So if any update comes for the tiny-jpeg,
/ just replace those files with updated files. / just replace those files with updated files.
/---------------------------------------------------------------------------------------------------------------------------------*/ /---------------------------------------------------------------------------------------------------------------------------------*/
/********************* /*********************
@@ -77,42 +77,43 @@ enum io_source_type {
typedef struct { typedef struct {
enum io_source_type type; enum io_source_type type;
lv_fs_file_t lv_file; lv_fs_file_t lv_file;
uint8_t* img_cache_buff; uint8_t * img_cache_buff;
int img_cache_x_res; int img_cache_x_res;
int img_cache_y_res; int img_cache_y_res;
uint8_t *raw_sjpg_data; //Used when type==SJPEG_IO_SOURCE_C_ARRAY. uint8_t * raw_sjpg_data; //Used when type==SJPEG_IO_SOURCE_C_ARRAY.
uint32_t raw_sjpg_data_size; //Num bytes pointed to by raw_sjpg_data. uint32_t raw_sjpg_data_size; //Num bytes pointed to by raw_sjpg_data.
uint32_t raw_sjpg_data_next_read_pos; //Used for all types. uint32_t raw_sjpg_data_next_read_pos; //Used for all types.
} io_source_t; } io_source_t;
typedef struct { typedef struct {
uint8_t *sjpeg_data; uint8_t * sjpeg_data;
uint32_t sjpeg_data_size; uint32_t sjpeg_data_size;
int sjpeg_x_res; int sjpeg_x_res;
int sjpeg_y_res; int sjpeg_y_res;
int sjpeg_total_frames; int sjpeg_total_frames;
int sjpeg_single_frame_height; int sjpeg_single_frame_height;
int sjpeg_cache_frame_index; int sjpeg_cache_frame_index;
uint8_t **frame_base_array; //to save base address of each split frames upto sjpeg_total_frames. uint8_t ** frame_base_array; //to save base address of each split frames upto sjpeg_total_frames.
int *frame_base_offset; //to save base offset for fseek int * frame_base_offset; //to save base offset for fseek
uint8_t *frame_cache; uint8_t * frame_cache;
uint8_t* workb; //JPG work buffer for jpeg library uint8_t * workb; //JPG work buffer for jpeg library
JDEC *tjpeg_jd; JDEC * tjpeg_jd;
io_source_t io; io_source_t io;
} SJPEG; } SJPEG;
/********************** /**********************
* STATIC PROTOTYPES * STATIC PROTOTYPES
**********************/ **********************/
static lv_res_t decoder_info( lv_img_decoder_t * decoder, const void * src, lv_img_header_t * header ); static lv_res_t decoder_info(lv_img_decoder_t * decoder, const void * src, lv_img_header_t * header);
static lv_res_t decoder_open( lv_img_decoder_t * decoder, lv_img_decoder_dsc_t * dsc ); static lv_res_t decoder_open(lv_img_decoder_t * decoder, lv_img_decoder_dsc_t * dsc);
static lv_res_t decoder_read_line( lv_img_decoder_t * decoder, lv_img_decoder_dsc_t * dsc, lv_coord_t x,lv_coord_t y, lv_coord_t len, uint8_t * buf ); static lv_res_t decoder_read_line(lv_img_decoder_t * decoder, lv_img_decoder_dsc_t * dsc, lv_coord_t x, lv_coord_t y,
static void decoder_close( lv_img_decoder_t * decoder, lv_img_decoder_dsc_t * dsc ); lv_coord_t len, uint8_t * buf);
static size_t input_func ( JDEC* jd, uint8_t* buff, size_t ndata ); static void decoder_close(lv_img_decoder_t * decoder, lv_img_decoder_dsc_t * dsc);
static int is_jpg( const uint8_t *raw_data ); static size_t input_func(JDEC * jd, uint8_t * buff, size_t ndata);
static void lv_sjpg_cleanup( SJPEG* sjpeg ); static int is_jpg(const uint8_t * raw_data);
static void lv_sjpg_free( SJPEG* sjpeg ); static void lv_sjpg_cleanup(SJPEG * sjpeg);
static void lv_sjpg_free(SJPEG * sjpeg);
/********************** /**********************
* STATIC VARIABLES * STATIC VARIABLES
@@ -125,13 +126,13 @@ static void lv_sjpg_free( SJPEG* sjpeg );
/********************** /**********************
* GLOBAL FUNCTIONS * GLOBAL FUNCTIONS
**********************/ **********************/
void lv_split_jpeg_init( void ) void lv_split_jpeg_init(void)
{ {
lv_img_decoder_t* dec = lv_img_decoder_create( ); lv_img_decoder_t * dec = lv_img_decoder_create();
lv_img_decoder_set_info_cb( dec, decoder_info ); lv_img_decoder_set_info_cb(dec, decoder_info);
lv_img_decoder_set_open_cb( dec, decoder_open ); lv_img_decoder_set_open_cb(dec, decoder_open);
lv_img_decoder_set_close_cb( dec, decoder_close ); lv_img_decoder_set_close_cb(dec, decoder_close);
lv_img_decoder_set_read_line_cb( dec, decoder_read_line ); lv_img_decoder_set_read_line_cb(dec, decoder_read_line);
} }
/********************** /**********************
@@ -144,7 +145,7 @@ void lv_split_jpeg_init( void )
* @param header store the info here * @param header store the info here
* @return LV_RES_OK: no error; LV_RES_INV: can't get the info * @return LV_RES_OK: no error; LV_RES_INV: can't get the info
*/ */
static lv_res_t decoder_info( lv_img_decoder_t * decoder, const void * src, lv_img_header_t * header ) static lv_res_t decoder_info(lv_img_decoder_t * decoder, const void * src, lv_img_header_t * header)
{ {
LV_UNUSED(decoder); LV_UNUSED(decoder);
@@ -156,10 +157,10 @@ static lv_res_t decoder_info( lv_img_decoder_t * decoder, const void * src, lv_i
lv_res_t ret = LV_RES_OK; lv_res_t ret = LV_RES_OK;
if(src_type == LV_IMG_SRC_VARIABLE) { if(src_type == LV_IMG_SRC_VARIABLE) {
uint8_t *raw_sjpeg_data = (uint8_t *)((lv_img_dsc_t * )src)->data; uint8_t * raw_sjpeg_data = (uint8_t *)((lv_img_dsc_t *)src)->data;
const uint32_t raw_sjpeg_data_size = ((lv_img_dsc_t *)src)->data_size; const uint32_t raw_sjpeg_data_size = ((lv_img_dsc_t *)src)->data_size;
if(!strncmp((char *)raw_sjpeg_data, "_SJPG__", strlen("_SJPG__") )) { if(!strncmp((char *)raw_sjpeg_data, "_SJPG__", strlen("_SJPG__"))) {
raw_sjpeg_data += 14; //seek to res info ... refer sjpeg format raw_sjpeg_data += 14; //seek to res info ... refer sjpeg format
header->always_zero = 0; header->always_zero = 0;
@@ -173,11 +174,12 @@ static lv_res_t decoder_info( lv_img_decoder_t * decoder, const void * src, lv_i
return ret; return ret;
} else if( is_jpg( raw_sjpeg_data ) == true ) { }
else if(is_jpg(raw_sjpeg_data) == true) {
header->always_zero = 0; header->always_zero = 0;
header->cf = LV_IMG_CF_RAW; header->cf = LV_IMG_CF_RAW;
uint8_t *workb_temp = lv_mem_alloc( TJPGD_WORKBUFF_SIZE ); uint8_t * workb_temp = lv_mem_alloc(TJPGD_WORKBUFF_SIZE);
if(!workb_temp) return LV_RES_INV; if(!workb_temp) return LV_RES_INV;
io_source_t io_source_temp; io_source_t io_source_temp;
@@ -188,24 +190,25 @@ static lv_res_t decoder_info( lv_img_decoder_t * decoder, const void * src, lv_i
JDEC jd_tmp; JDEC jd_tmp;
JRESULT rc = jd_prepare( &jd_tmp, input_func, workb_temp, (size_t)TJPGD_WORKBUFF_SIZE, &io_source_temp); JRESULT rc = jd_prepare(&jd_tmp, input_func, workb_temp, (size_t)TJPGD_WORKBUFF_SIZE, &io_source_temp);
if(rc == JDR_OK ) { if(rc == JDR_OK) {
header->w = jd_tmp.width; header->w = jd_tmp.width;
header->h = jd_tmp.height; header->h = jd_tmp.height;
} else { }
else {
ret = LV_RES_INV; ret = LV_RES_INV;
goto end; goto end;
} }
end: end:
lv_mem_free(workb_temp); lv_mem_free(workb_temp);
return ret; return ret;
} }
} }
else if( src_type == LV_IMG_SRC_FILE ) { else if(src_type == LV_IMG_SRC_FILE) {
const char * fn = src; const char * fn = src;
if(!strcmp(&fn[strlen(fn) - 5], ".sjpg")) { if(!strcmp(&fn[strlen(fn) - 5], ".sjpg")) {
@@ -213,7 +216,7 @@ static lv_res_t decoder_info( lv_img_decoder_t * decoder, const void * src, lv_i
memset(buff, 0, sizeof(buff)); memset(buff, 0, sizeof(buff));
lv_fs_file_t file; lv_fs_file_t file;
lv_fs_res_t res = lv_fs_open(&file , fn, LV_FS_MODE_RD); lv_fs_res_t res = lv_fs_open(&file, fn, LV_FS_MODE_RD);
if(res != LV_FS_RES_OK) return 78; if(res != LV_FS_RES_OK) return 78;
uint32_t rn; uint32_t rn;
@@ -223,16 +226,16 @@ static lv_res_t decoder_info( lv_img_decoder_t * decoder, const void * src, lv_i
return LV_RES_INV; return LV_RES_INV;
} }
if(strcmp((char *)buff, "_SJPG__") == 0 ) { if(strcmp((char *)buff, "_SJPG__") == 0) {
lv_fs_seek(&file, 14, LV_FS_SEEK_SET); lv_fs_seek(&file, 14, LV_FS_SEEK_SET);
res = lv_fs_read(&file, buff, 4, &rn); res = lv_fs_read(&file, buff, 4, &rn);
if(res != LV_FS_RES_OK || rn != 4 ) { if(res != LV_FS_RES_OK || rn != 4) {
lv_fs_close(&file); lv_fs_close(&file);
return LV_RES_INV; return LV_RES_INV;
} }
header->always_zero = 0; header->always_zero = 0;
header->cf = LV_IMG_CF_RAW; header->cf = LV_IMG_CF_RAW;
uint8_t *raw_sjpeg_data = buff; uint8_t * raw_sjpeg_data = buff;
header->w = *raw_sjpeg_data++; header->w = *raw_sjpeg_data++;
header->w |= *raw_sjpeg_data++ << 8; header->w |= *raw_sjpeg_data++ << 8;
header->h = *raw_sjpeg_data++; header->h = *raw_sjpeg_data++;
@@ -241,12 +244,13 @@ static lv_res_t decoder_info( lv_img_decoder_t * decoder, const void * src, lv_i
return LV_RES_OK; return LV_RES_OK;
} }
} else if(!strcmp(&fn[strlen(fn) - 4], ".jpg")) { }
else if(!strcmp(&fn[strlen(fn) - 4], ".jpg")) {
lv_fs_file_t file; lv_fs_file_t file;
lv_fs_res_t res = lv_fs_open(&file , fn, LV_FS_MODE_RD); lv_fs_res_t res = lv_fs_open(&file, fn, LV_FS_MODE_RD);
if(res != LV_FS_RES_OK) return 78; if(res != LV_FS_RES_OK) return 78;
uint8_t *workb_temp = lv_mem_alloc( TJPGD_WORKBUFF_SIZE ); uint8_t * workb_temp = lv_mem_alloc(TJPGD_WORKBUFF_SIZE);
if(!workb_temp) { if(!workb_temp) {
lv_fs_close(&file); lv_fs_close(&file);
return LV_RES_INV; return LV_RES_INV;
@@ -259,11 +263,11 @@ static lv_res_t decoder_info( lv_img_decoder_t * decoder, const void * src, lv_i
io_source_temp.lv_file = file; io_source_temp.lv_file = file;
JDEC jd_tmp; JDEC jd_tmp;
JRESULT rc = jd_prepare( &jd_tmp, input_func, workb_temp, (size_t)TJPGD_WORKBUFF_SIZE, &io_source_temp); JRESULT rc = jd_prepare(&jd_tmp, input_func, workb_temp, (size_t)TJPGD_WORKBUFF_SIZE, &io_source_temp);
lv_mem_free(workb_temp); lv_mem_free(workb_temp);
lv_fs_close(&file); lv_fs_close(&file);
if(rc == JDR_OK ) { if(rc == JDR_OK) {
header->always_zero = 0; header->always_zero = 0;
header->cf = LV_IMG_CF_RAW; header->cf = LV_IMG_CF_RAW;
header->w = jd_tmp.width; header->w = jd_tmp.width;
@@ -275,35 +279,35 @@ static lv_res_t decoder_info( lv_img_decoder_t * decoder, const void * src, lv_i
return LV_RES_INV; return LV_RES_INV;
} }
static int img_data_cb( JDEC* jd, void* data, JRECT* rect ) static int img_data_cb(JDEC * jd, void * data, JRECT * rect)
{ {
io_source_t *io = jd->device; io_source_t * io = jd->device;
uint8_t *cache = io->img_cache_buff; uint8_t * cache = io->img_cache_buff;
const int xres = io->img_cache_x_res; const int xres = io->img_cache_x_res;
uint8_t *buf = data; uint8_t * buf = data;
const int INPUT_PIXEL_SIZE = 3; const int INPUT_PIXEL_SIZE = 3;
const int row_width = rect->right - rect->left + 1; // Row width in pixels. const int row_width = rect->right - rect->left + 1; // Row width in pixels.
const int row_size = row_width * INPUT_PIXEL_SIZE; // Row size (bytes). const int row_size = row_width * INPUT_PIXEL_SIZE; // Row size (bytes).
for( int y = rect->top; y <= rect->bottom; y++ ) { for(int y = rect->top; y <= rect->bottom; y++) {
int row_offset = y * xres * INPUT_PIXEL_SIZE + rect->left * INPUT_PIXEL_SIZE; int row_offset = y * xres * INPUT_PIXEL_SIZE + rect->left * INPUT_PIXEL_SIZE;
memcpy( cache + row_offset, buf, row_size ); memcpy(cache + row_offset, buf, row_size);
buf += row_size; buf += row_size;
} }
return 1; return 1;
} }
static size_t input_func ( JDEC* jd, uint8_t* buff, size_t ndata ) static size_t input_func(JDEC * jd, uint8_t * buff, size_t ndata)
{ {
io_source_t *io = jd->device; io_source_t * io = jd->device;
if(!io) return 0; if(!io) return 0;
if(io->type == SJPEG_IO_SOURCE_C_ARRAY) { if(io->type == SJPEG_IO_SOURCE_C_ARRAY) {
const uint32_t bytes_left = io->raw_sjpg_data_size - io->raw_sjpg_data_next_read_pos; const uint32_t bytes_left = io->raw_sjpg_data_size - io->raw_sjpg_data_next_read_pos;
const uint32_t to_read = ndata <= bytes_left ? (uint32_t)ndata : bytes_left; const uint32_t to_read = ndata <= bytes_left ? (uint32_t)ndata : bytes_left;
if (to_read == 0) if(to_read == 0)
return 0; return 0;
if(buff) { if(buff) {
memcpy(buff, io->raw_sjpg_data + io->raw_sjpg_data_next_read_pos, to_read); memcpy(buff, io->raw_sjpg_data + io->raw_sjpg_data_next_read_pos, to_read);
@@ -313,13 +317,14 @@ static size_t input_func ( JDEC* jd, uint8_t* buff, size_t ndata )
} }
else if(io->type == SJPEG_IO_SOURCE_DISK) { else if(io->type == SJPEG_IO_SOURCE_DISK) {
lv_fs_file_t* lv_file_p = &(io->lv_file); lv_fs_file_t * lv_file_p = &(io->lv_file);
if( buff ) { if(buff) {
uint32_t rn = 0; uint32_t rn = 0;
lv_fs_read(lv_file_p, buff, (uint32_t)ndata, &rn); lv_fs_read(lv_file_p, buff, (uint32_t)ndata, &rn);
return rn; return rn;
} else { }
else {
uint32_t pos; uint32_t pos;
lv_fs_tell(lv_file_p, &pos); lv_fs_tell(lv_file_p, &pos);
lv_fs_seek(lv_file_p, (uint32_t)(ndata + pos), LV_FS_SEEK_SET); lv_fs_seek(lv_file_p, (uint32_t)(ndata + pos), LV_FS_SEEK_SET);
@@ -335,26 +340,26 @@ static size_t input_func ( JDEC* jd, uint8_t* buff, size_t ndata )
* @param dsc pointer to a descriptor which describes this decoding session * @param dsc pointer to a descriptor which describes this decoding session
* @return LV_RES_OK: no error; LV_RES_INV: can't get the info * @return LV_RES_OK: no error; LV_RES_INV: can't get the info
*/ */
static lv_res_t decoder_open( lv_img_decoder_t * decoder, lv_img_decoder_dsc_t * dsc ) static lv_res_t decoder_open(lv_img_decoder_t * decoder, lv_img_decoder_dsc_t * dsc)
{ {
LV_UNUSED(decoder); LV_UNUSED(decoder);
lv_res_t lv_ret = LV_RES_OK; lv_res_t lv_ret = LV_RES_OK;
if(dsc->src_type == LV_IMG_SRC_VARIABLE) { if(dsc->src_type == LV_IMG_SRC_VARIABLE) {
uint8_t *data; uint8_t * data;
SJPEG* sjpeg = ( SJPEG* ) dsc->user_data; SJPEG * sjpeg = (SJPEG *) dsc->user_data;
if( sjpeg == NULL ) { if(sjpeg == NULL) {
sjpeg = lv_mem_alloc( sizeof( SJPEG ) ); sjpeg = lv_mem_alloc(sizeof(SJPEG));
if( !sjpeg ) return LV_RES_INV; if(!sjpeg) return LV_RES_INV;
memset(sjpeg, 0, sizeof(SJPEG)); memset(sjpeg, 0, sizeof(SJPEG));
dsc->user_data = sjpeg; dsc->user_data = sjpeg;
sjpeg->sjpeg_data = (uint8_t *)( ( lv_img_dsc_t* )(dsc->src) )->data; sjpeg->sjpeg_data = (uint8_t *)((lv_img_dsc_t *)(dsc->src))->data;
sjpeg->sjpeg_data_size = ( ( lv_img_dsc_t* )(dsc->src) )->data_size; sjpeg->sjpeg_data_size = ((lv_img_dsc_t *)(dsc->src))->data_size;
} }
if( !strncmp( ( char * ) sjpeg->sjpeg_data, "_SJPG__", strlen("_SJPG__") ) ) { if(!strncmp((char *) sjpeg->sjpeg_data, "_SJPG__", strlen("_SJPG__"))) {
data = sjpeg->sjpeg_data; data = sjpeg->sjpeg_data;
data += 14; data += 14;
@@ -371,42 +376,42 @@ static lv_res_t decoder_open( lv_img_decoder_t * decoder, lv_img_decoder_dsc_t *
sjpeg->sjpeg_single_frame_height = *data++; sjpeg->sjpeg_single_frame_height = *data++;
sjpeg->sjpeg_single_frame_height |= *data++ << 8; sjpeg->sjpeg_single_frame_height |= *data++ << 8;
sjpeg->frame_base_array = lv_mem_alloc( sizeof(uint8_t *) * sjpeg->sjpeg_total_frames ); sjpeg->frame_base_array = lv_mem_alloc(sizeof(uint8_t *) * sjpeg->sjpeg_total_frames);
if( ! sjpeg->frame_base_array ) { if(! sjpeg->frame_base_array) {
lv_sjpg_cleanup( sjpeg ); lv_sjpg_cleanup(sjpeg);
sjpeg = NULL; sjpeg = NULL;
return LV_RES_INV; return LV_RES_INV;
} }
sjpeg->frame_base_offset = NULL; sjpeg->frame_base_offset = NULL;
uint8_t *img_frame_base = data + sjpeg->sjpeg_total_frames *2; uint8_t * img_frame_base = data + sjpeg->sjpeg_total_frames * 2;
sjpeg->frame_base_array[0] = img_frame_base; sjpeg->frame_base_array[0] = img_frame_base;
for( int i = 1; i < sjpeg->sjpeg_total_frames; i++ ) { for(int i = 1; i < sjpeg->sjpeg_total_frames; i++) {
int offset = *data++; int offset = *data++;
offset |= *data++ <<8; offset |= *data++ << 8;
sjpeg->frame_base_array[i] = sjpeg->frame_base_array[i-1] + offset; sjpeg->frame_base_array[i] = sjpeg->frame_base_array[i - 1] + offset;
} }
sjpeg->sjpeg_cache_frame_index = -1; sjpeg->sjpeg_cache_frame_index = -1;
sjpeg->frame_cache = (void *)lv_mem_alloc( sjpeg->sjpeg_x_res * sjpeg->sjpeg_single_frame_height * 3/*2*/ ); sjpeg->frame_cache = (void *)lv_mem_alloc(sjpeg->sjpeg_x_res * sjpeg->sjpeg_single_frame_height * 3/*2*/);
if( ! sjpeg->frame_cache ) { if(! sjpeg->frame_cache) {
lv_sjpg_cleanup( sjpeg ); lv_sjpg_cleanup(sjpeg);
sjpeg = NULL; sjpeg = NULL;
return LV_RES_INV; return LV_RES_INV;
} }
sjpeg->io.img_cache_buff = sjpeg->frame_cache; sjpeg->io.img_cache_buff = sjpeg->frame_cache;
sjpeg->io.img_cache_x_res = sjpeg->sjpeg_x_res; sjpeg->io.img_cache_x_res = sjpeg->sjpeg_x_res;
sjpeg->workb = lv_mem_alloc( TJPGD_WORKBUFF_SIZE ); sjpeg->workb = lv_mem_alloc(TJPGD_WORKBUFF_SIZE);
if( ! sjpeg->workb ) { if(! sjpeg->workb) {
lv_sjpg_cleanup( sjpeg ); lv_sjpg_cleanup(sjpeg);
sjpeg = NULL; sjpeg = NULL;
return LV_RES_INV; return LV_RES_INV;
} }
sjpeg->tjpeg_jd = lv_mem_alloc( sizeof( JDEC ) ); sjpeg->tjpeg_jd = lv_mem_alloc(sizeof(JDEC));
if( ! sjpeg->tjpeg_jd ) { if(! sjpeg->tjpeg_jd) {
lv_sjpg_cleanup( sjpeg ); lv_sjpg_cleanup(sjpeg);
sjpeg = NULL; sjpeg = NULL;
return LV_RES_INV; return LV_RES_INV;
} }
@@ -416,11 +421,11 @@ static lv_res_t decoder_open( lv_img_decoder_t * decoder, lv_img_decoder_dsc_t *
return lv_ret; return lv_ret;
} }
else if( is_jpg( sjpeg->sjpeg_data ) == true ) { else if(is_jpg(sjpeg->sjpeg_data) == true) {
uint8_t *workb_temp = lv_mem_alloc( TJPGD_WORKBUFF_SIZE ); uint8_t * workb_temp = lv_mem_alloc(TJPGD_WORKBUFF_SIZE);
if( ! workb_temp ) { if(! workb_temp) {
lv_sjpg_cleanup( sjpeg ); lv_sjpg_cleanup(sjpeg);
sjpeg = NULL; sjpeg = NULL;
return LV_RES_INV; return LV_RES_INV;
} }
@@ -431,47 +436,47 @@ static lv_res_t decoder_open( lv_img_decoder_t * decoder, lv_img_decoder_dsc_t *
io_source_temp.raw_sjpg_data_next_read_pos = 0; io_source_temp.raw_sjpg_data_next_read_pos = 0;
JDEC jd_tmp; JDEC jd_tmp;
JRESULT rc = jd_prepare( &jd_tmp, input_func, workb_temp, (size_t)TJPGD_WORKBUFF_SIZE, &io_source_temp); JRESULT rc = jd_prepare(&jd_tmp, input_func, workb_temp, (size_t)TJPGD_WORKBUFF_SIZE, &io_source_temp);
lv_mem_free(workb_temp); lv_mem_free(workb_temp);
if(rc == JDR_OK ) { if(rc == JDR_OK) {
sjpeg->sjpeg_x_res = jd_tmp.width; sjpeg->sjpeg_x_res = jd_tmp.width;
sjpeg->sjpeg_y_res = jd_tmp.height; sjpeg->sjpeg_y_res = jd_tmp.height;
sjpeg->sjpeg_total_frames = 1; sjpeg->sjpeg_total_frames = 1;
sjpeg->sjpeg_single_frame_height = jd_tmp.height; sjpeg->sjpeg_single_frame_height = jd_tmp.height;
sjpeg->frame_base_array = lv_mem_alloc( sizeof(uint8_t *) * sjpeg->sjpeg_total_frames ); sjpeg->frame_base_array = lv_mem_alloc(sizeof(uint8_t *) * sjpeg->sjpeg_total_frames);
if( ! sjpeg->frame_base_array ) { if(! sjpeg->frame_base_array) {
lv_sjpg_cleanup( sjpeg ); lv_sjpg_cleanup(sjpeg);
sjpeg = NULL; sjpeg = NULL;
return LV_RES_INV; return LV_RES_INV;
} }
sjpeg->frame_base_offset = NULL; sjpeg->frame_base_offset = NULL;
uint8_t *img_frame_base = sjpeg->sjpeg_data; uint8_t * img_frame_base = sjpeg->sjpeg_data;
sjpeg->frame_base_array[0] = img_frame_base; sjpeg->frame_base_array[0] = img_frame_base;
sjpeg->sjpeg_cache_frame_index = -1; sjpeg->sjpeg_cache_frame_index = -1;
sjpeg->frame_cache = (void *)lv_mem_alloc( sjpeg->sjpeg_x_res * sjpeg->sjpeg_single_frame_height * 3 ); sjpeg->frame_cache = (void *)lv_mem_alloc(sjpeg->sjpeg_x_res * sjpeg->sjpeg_single_frame_height * 3);
if( ! sjpeg->frame_cache ) { if(! sjpeg->frame_cache) {
lv_sjpg_cleanup( sjpeg ); lv_sjpg_cleanup(sjpeg);
sjpeg = NULL; sjpeg = NULL;
return LV_RES_INV; return LV_RES_INV;
} }
sjpeg->io.img_cache_buff = sjpeg->frame_cache; sjpeg->io.img_cache_buff = sjpeg->frame_cache;
sjpeg->io.img_cache_x_res = sjpeg->sjpeg_x_res; sjpeg->io.img_cache_x_res = sjpeg->sjpeg_x_res;
sjpeg->workb = lv_mem_alloc( TJPGD_WORKBUFF_SIZE ); sjpeg->workb = lv_mem_alloc(TJPGD_WORKBUFF_SIZE);
if( ! sjpeg->workb ) { if(! sjpeg->workb) {
lv_sjpg_cleanup( sjpeg ); lv_sjpg_cleanup(sjpeg);
sjpeg = NULL; sjpeg = NULL;
return LV_RES_INV; return LV_RES_INV;
} }
sjpeg->tjpeg_jd = lv_mem_alloc( sizeof( JDEC ) ); sjpeg->tjpeg_jd = lv_mem_alloc(sizeof(JDEC));
if( ! sjpeg->tjpeg_jd ) { if(! sjpeg->tjpeg_jd) {
lv_sjpg_cleanup( sjpeg ); lv_sjpg_cleanup(sjpeg);
sjpeg = NULL; sjpeg = NULL;
return LV_RES_INV; return LV_RES_INV;
} }
@@ -480,12 +485,13 @@ static lv_res_t decoder_open( lv_img_decoder_t * decoder, lv_img_decoder_dsc_t *
sjpeg->io.lv_file.file_d = NULL; sjpeg->io.lv_file.file_d = NULL;
dsc->img_data = NULL; dsc->img_data = NULL;
return lv_ret; return lv_ret;
} else { }
else {
lv_ret = LV_RES_INV; lv_ret = LV_RES_INV;
goto end; goto end;
} }
end: end:
lv_mem_free(workb_temp); lv_mem_free(workb_temp);
return lv_ret; return lv_ret;
@@ -494,7 +500,7 @@ static lv_res_t decoder_open( lv_img_decoder_t * decoder, lv_img_decoder_dsc_t *
else if(dsc->src_type == LV_IMG_SRC_FILE) { else if(dsc->src_type == LV_IMG_SRC_FILE) {
/* If all fine, then the file will be kept open */ /* If all fine, then the file will be kept open */
const char * fn = dsc->src; const char * fn = dsc->src;
uint8_t *data; uint8_t * data;
if(!strcmp(&fn[strlen(fn) - 5], ".sjpg")) { if(!strcmp(&fn[strlen(fn) - 5], ".sjpg")) {
@@ -503,7 +509,7 @@ static lv_res_t decoder_open( lv_img_decoder_t * decoder, lv_img_decoder_dsc_t *
lv_fs_file_t lv_file; lv_fs_file_t lv_file;
lv_fs_res_t res = lv_fs_open(&lv_file , fn, LV_FS_MODE_RD); lv_fs_res_t res = lv_fs_open(&lv_file, fn, LV_FS_MODE_RD);
if(res != LV_FS_RES_OK) { if(res != LV_FS_RES_OK) {
return 78; return 78;
} }
@@ -511,26 +517,26 @@ static lv_res_t decoder_open( lv_img_decoder_t * decoder, lv_img_decoder_dsc_t *
uint32_t rn; uint32_t rn;
res = lv_fs_read(&lv_file, buff, 22, &rn); res = lv_fs_read(&lv_file, buff, 22, &rn);
if(res != LV_FS_RES_OK || rn != 22 ) { if(res != LV_FS_RES_OK || rn != 22) {
lv_fs_close(&lv_file); lv_fs_close(&lv_file);
return LV_RES_INV; return LV_RES_INV;
} }
if(strcmp((char *)buff, "_SJPG__") == 0 ) { if(strcmp((char *)buff, "_SJPG__") == 0) {
SJPEG* sjpeg = ( SJPEG* ) dsc->user_data; SJPEG * sjpeg = (SJPEG *) dsc->user_data;
if(sjpeg == NULL) { if(sjpeg == NULL) {
sjpeg = lv_mem_alloc(sizeof(SJPEG)); sjpeg = lv_mem_alloc(sizeof(SJPEG));
if( ! sjpeg ) { if(! sjpeg) {
lv_fs_close(&lv_file); lv_fs_close(&lv_file);
return LV_RES_INV; return LV_RES_INV;
} }
memset(sjpeg, 0, sizeof(SJPEG)); memset(sjpeg, 0, sizeof(SJPEG));
dsc->user_data = sjpeg; dsc->user_data = sjpeg;
sjpeg->sjpeg_data = (uint8_t *)( (lv_img_dsc_t* )(dsc->src) )->data; sjpeg->sjpeg_data = (uint8_t *)((lv_img_dsc_t *)(dsc->src))->data;
sjpeg->sjpeg_data_size = ( (lv_img_dsc_t* )(dsc->src) )->data_size; sjpeg->sjpeg_data_size = ((lv_img_dsc_t *)(dsc->src))->data_size;
} }
data = buff; data = buff;
data += 14; data += 14;
@@ -548,46 +554,46 @@ static lv_res_t decoder_open( lv_img_decoder_t * decoder, lv_img_decoder_dsc_t *
sjpeg->sjpeg_single_frame_height |= *data++ << 8; sjpeg->sjpeg_single_frame_height |= *data++ << 8;
sjpeg->frame_base_array = NULL;//lv_mem_alloc( sizeof(uint8_t *) * sjpeg->sjpeg_total_frames ); sjpeg->frame_base_array = NULL;//lv_mem_alloc( sizeof(uint8_t *) * sjpeg->sjpeg_total_frames );
sjpeg->frame_base_offset = lv_mem_alloc( sizeof(int) * sjpeg->sjpeg_total_frames ); sjpeg->frame_base_offset = lv_mem_alloc(sizeof(int) * sjpeg->sjpeg_total_frames);
if( ! sjpeg->frame_base_offset ) { if(! sjpeg->frame_base_offset) {
lv_fs_close(&lv_file); lv_fs_close(&lv_file);
lv_sjpg_cleanup(sjpeg); lv_sjpg_cleanup(sjpeg);
return LV_RES_INV; return LV_RES_INV;
} }
int img_frame_start_offset = (SJPEG_FRAME_INFO_ARRAY_OFFSET + sjpeg->sjpeg_total_frames *2); int img_frame_start_offset = (SJPEG_FRAME_INFO_ARRAY_OFFSET + sjpeg->sjpeg_total_frames * 2);
sjpeg->frame_base_offset[0] = img_frame_start_offset; //pointer used to save integer for now... sjpeg->frame_base_offset[0] = img_frame_start_offset; //pointer used to save integer for now...
for( int i = 1; i < sjpeg->sjpeg_total_frames; i++ ) { for(int i = 1; i < sjpeg->sjpeg_total_frames; i++) {
res = lv_fs_read(&lv_file, buff, 2, &rn); res = lv_fs_read(&lv_file, buff, 2, &rn);
if(res != LV_FS_RES_OK || rn != 2 ) { if(res != LV_FS_RES_OK || rn != 2) {
lv_fs_close(&lv_file); lv_fs_close(&lv_file);
return LV_RES_INV; return LV_RES_INV;
} }
data = buff; data = buff;
int offset = *data++; int offset = *data++;
offset |= *data++ <<8; offset |= *data++ << 8;
sjpeg->frame_base_offset[i] = sjpeg->frame_base_offset[i-1] + offset; sjpeg->frame_base_offset[i] = sjpeg->frame_base_offset[i - 1] + offset;
} }
sjpeg->sjpeg_cache_frame_index = -1; //INVALID AT BEGINNING for a forced compare mismatch at first time. sjpeg->sjpeg_cache_frame_index = -1; //INVALID AT BEGINNING for a forced compare mismatch at first time.
sjpeg->frame_cache = (void *)lv_mem_alloc( sjpeg->sjpeg_x_res * sjpeg->sjpeg_single_frame_height * 3 ); sjpeg->frame_cache = (void *)lv_mem_alloc(sjpeg->sjpeg_x_res * sjpeg->sjpeg_single_frame_height * 3);
if( ! sjpeg->frame_cache ) { if(! sjpeg->frame_cache) {
lv_fs_close(&lv_file); lv_fs_close(&lv_file);
lv_sjpg_cleanup(sjpeg); lv_sjpg_cleanup(sjpeg);
return LV_RES_INV; return LV_RES_INV;
} }
sjpeg->io.img_cache_buff = sjpeg->frame_cache; sjpeg->io.img_cache_buff = sjpeg->frame_cache;
sjpeg->io.img_cache_x_res = sjpeg->sjpeg_x_res; sjpeg->io.img_cache_x_res = sjpeg->sjpeg_x_res;
sjpeg->workb = lv_mem_alloc( TJPGD_WORKBUFF_SIZE ); sjpeg->workb = lv_mem_alloc(TJPGD_WORKBUFF_SIZE);
if( ! sjpeg->workb ) { if(! sjpeg->workb) {
lv_fs_close(&lv_file); lv_fs_close(&lv_file);
lv_sjpg_cleanup(sjpeg); lv_sjpg_cleanup(sjpeg);
return LV_RES_INV; return LV_RES_INV;
} }
sjpeg->tjpeg_jd = lv_mem_alloc( sizeof( JDEC ) ); sjpeg->tjpeg_jd = lv_mem_alloc(sizeof(JDEC));
if( ! sjpeg->tjpeg_jd ) { if(! sjpeg->tjpeg_jd) {
lv_fs_close(&lv_file); lv_fs_close(&lv_file);
lv_sjpg_cleanup(sjpeg); lv_sjpg_cleanup(sjpeg);
return LV_RES_INV; return LV_RES_INV;
@@ -599,30 +605,30 @@ static lv_res_t decoder_open( lv_img_decoder_t * decoder, lv_img_decoder_dsc_t *
return LV_RES_OK; return LV_RES_OK;
} }
} }
else if( !strcmp(&fn[strlen(fn) - 4], ".jpg" ) ) { else if(!strcmp(&fn[strlen(fn) - 4], ".jpg")) {
lv_fs_file_t lv_file; lv_fs_file_t lv_file;
lv_fs_res_t res = lv_fs_open( &lv_file , fn, LV_FS_MODE_RD ); lv_fs_res_t res = lv_fs_open(&lv_file, fn, LV_FS_MODE_RD);
if(res != LV_FS_RES_OK) { if(res != LV_FS_RES_OK) {
return LV_RES_INV; return LV_RES_INV;
} }
SJPEG* sjpeg = ( SJPEG* ) dsc->user_data; SJPEG * sjpeg = (SJPEG *) dsc->user_data;
if(sjpeg == NULL) { if(sjpeg == NULL) {
sjpeg = lv_mem_alloc( sizeof( SJPEG ) ); sjpeg = lv_mem_alloc(sizeof(SJPEG));
if( ! sjpeg ) { if(! sjpeg) {
lv_fs_close( &lv_file ); lv_fs_close(&lv_file);
return LV_RES_INV; return LV_RES_INV;
} }
memset(sjpeg, 0, sizeof(SJPEG)); memset(sjpeg, 0, sizeof(SJPEG));
dsc->user_data = sjpeg; dsc->user_data = sjpeg;
sjpeg->sjpeg_data = (uint8_t *)( (lv_img_dsc_t* )(dsc->src) )->data; sjpeg->sjpeg_data = (uint8_t *)((lv_img_dsc_t *)(dsc->src))->data;
sjpeg->sjpeg_data_size = ( (lv_img_dsc_t *)(dsc->src) )->data_size; sjpeg->sjpeg_data_size = ((lv_img_dsc_t *)(dsc->src))->data_size;
} }
uint8_t *workb_temp = lv_mem_alloc( TJPGD_WORKBUFF_SIZE ); uint8_t * workb_temp = lv_mem_alloc(TJPGD_WORKBUFF_SIZE);
if( ! workb_temp ) { if(! workb_temp) {
lv_fs_close(&lv_file); lv_fs_close(&lv_file);
lv_sjpg_cleanup(sjpeg); lv_sjpg_cleanup(sjpeg);
return LV_RES_INV; return LV_RES_INV;
@@ -636,20 +642,20 @@ static lv_res_t decoder_open( lv_img_decoder_t * decoder, lv_img_decoder_dsc_t *
JDEC jd_tmp; JDEC jd_tmp;
JRESULT rc = jd_prepare( &jd_tmp, input_func, workb_temp, (size_t)TJPGD_WORKBUFF_SIZE, &io_source_temp); JRESULT rc = jd_prepare(&jd_tmp, input_func, workb_temp, (size_t)TJPGD_WORKBUFF_SIZE, &io_source_temp);
lv_mem_free(workb_temp); lv_mem_free(workb_temp);
if(rc == JDR_OK ) { if(rc == JDR_OK) {
sjpeg->sjpeg_x_res = jd_tmp.width; sjpeg->sjpeg_x_res = jd_tmp.width;
sjpeg->sjpeg_y_res = jd_tmp.height; sjpeg->sjpeg_y_res = jd_tmp.height;
sjpeg->sjpeg_total_frames = 1; sjpeg->sjpeg_total_frames = 1;
sjpeg->sjpeg_single_frame_height = jd_tmp.height; sjpeg->sjpeg_single_frame_height = jd_tmp.height;
sjpeg->frame_base_array = NULL; sjpeg->frame_base_array = NULL;
sjpeg->frame_base_offset = lv_mem_alloc( sizeof(uint8_t *) * sjpeg->sjpeg_total_frames ); sjpeg->frame_base_offset = lv_mem_alloc(sizeof(uint8_t *) * sjpeg->sjpeg_total_frames);
if( ! sjpeg->frame_base_offset ) { if(! sjpeg->frame_base_offset) {
lv_fs_close(&lv_file); lv_fs_close(&lv_file);
lv_sjpg_cleanup(sjpeg); lv_sjpg_cleanup(sjpeg);
return LV_RES_INV; return LV_RES_INV;
@@ -659,8 +665,8 @@ static lv_res_t decoder_open( lv_img_decoder_t * decoder, lv_img_decoder_dsc_t *
sjpeg->frame_base_offset[0] = img_frame_start_offset; sjpeg->frame_base_offset[0] = img_frame_start_offset;
sjpeg->sjpeg_cache_frame_index = -1; sjpeg->sjpeg_cache_frame_index = -1;
sjpeg->frame_cache = (void *)lv_mem_alloc( sjpeg->sjpeg_x_res * sjpeg->sjpeg_single_frame_height * 3 ); sjpeg->frame_cache = (void *)lv_mem_alloc(sjpeg->sjpeg_x_res * sjpeg->sjpeg_single_frame_height * 3);
if( ! sjpeg->frame_cache ) { if(! sjpeg->frame_cache) {
lv_fs_close(&lv_file); lv_fs_close(&lv_file);
lv_sjpg_cleanup(sjpeg); lv_sjpg_cleanup(sjpeg);
return LV_RES_INV; return LV_RES_INV;
@@ -668,15 +674,15 @@ static lv_res_t decoder_open( lv_img_decoder_t * decoder, lv_img_decoder_dsc_t *
sjpeg->io.img_cache_buff = sjpeg->frame_cache; sjpeg->io.img_cache_buff = sjpeg->frame_cache;
sjpeg->io.img_cache_x_res = sjpeg->sjpeg_x_res; sjpeg->io.img_cache_x_res = sjpeg->sjpeg_x_res;
sjpeg->workb = lv_mem_alloc( TJPGD_WORKBUFF_SIZE ); sjpeg->workb = lv_mem_alloc(TJPGD_WORKBUFF_SIZE);
if( ! sjpeg->workb ) { if(! sjpeg->workb) {
lv_fs_close(&lv_file); lv_fs_close(&lv_file);
lv_sjpg_cleanup(sjpeg); lv_sjpg_cleanup(sjpeg);
return LV_RES_INV; return LV_RES_INV;
} }
sjpeg->tjpeg_jd = lv_mem_alloc( sizeof( JDEC ) ); sjpeg->tjpeg_jd = lv_mem_alloc(sizeof(JDEC));
if( ! sjpeg->tjpeg_jd ) { if(! sjpeg->tjpeg_jd) {
lv_fs_close(&lv_file); lv_fs_close(&lv_file);
lv_sjpg_cleanup(sjpeg); lv_sjpg_cleanup(sjpeg);
return LV_RES_INV; return LV_RES_INV;
@@ -687,7 +693,8 @@ static lv_res_t decoder_open( lv_img_decoder_t * decoder, lv_img_decoder_dsc_t *
dsc->img_data = NULL; dsc->img_data = NULL;
return LV_RES_OK; return LV_RES_OK;
} else { }
else {
if(dsc->user_data) lv_mem_free(dsc->user_data); if(dsc->user_data) lv_mem_free(dsc->user_data);
lv_fs_close(&lv_file); lv_fs_close(&lv_file);
return LV_RES_INV; return LV_RES_INV;
@@ -710,11 +717,12 @@ static lv_res_t decoder_open( lv_img_decoder_t * decoder, lv_img_decoder_dsc_t *
* @return LV_RES_OK: ok; LV_RES_INV: failed * @return LV_RES_OK: ok; LV_RES_INV: failed
*/ */
static lv_res_t decoder_read_line( lv_img_decoder_t * decoder, lv_img_decoder_dsc_t * dsc, lv_coord_t x, lv_coord_t y, lv_coord_t len, uint8_t * buf ) static lv_res_t decoder_read_line(lv_img_decoder_t * decoder, lv_img_decoder_dsc_t * dsc, lv_coord_t x, lv_coord_t y,
lv_coord_t len, uint8_t * buf)
{ {
LV_UNUSED(decoder); LV_UNUSED(decoder);
if(dsc->src_type == LV_IMG_SRC_VARIABLE) { if(dsc->src_type == LV_IMG_SRC_VARIABLE) {
SJPEG* sjpeg = ( SJPEG* ) dsc->user_data; SJPEG * sjpeg = (SJPEG *) dsc->user_data;
JRESULT rc; JRESULT rc;
int sjpeg_req_frame_index = y / sjpeg->sjpeg_single_frame_height; int sjpeg_req_frame_index = y / sjpeg->sjpeg_single_frame_height;
@@ -722,27 +730,29 @@ static lv_res_t decoder_read_line( lv_img_decoder_t * decoder, lv_img_decoder_ds
/*If line not from cache, refresh cache */ /*If line not from cache, refresh cache */
if(sjpeg_req_frame_index != sjpeg->sjpeg_cache_frame_index) { if(sjpeg_req_frame_index != sjpeg->sjpeg_cache_frame_index) {
sjpeg->io.raw_sjpg_data = sjpeg->frame_base_array[ sjpeg_req_frame_index ]; sjpeg->io.raw_sjpg_data = sjpeg->frame_base_array[ sjpeg_req_frame_index ];
if (sjpeg_req_frame_index == (sjpeg->sjpeg_total_frames - 1)) { if(sjpeg_req_frame_index == (sjpeg->sjpeg_total_frames - 1)) {
/*This is the last frame. */ /*This is the last frame. */
const uint32_t frame_offset = (uint32_t)(sjpeg->io.raw_sjpg_data - sjpeg->sjpeg_data); const uint32_t frame_offset = (uint32_t)(sjpeg->io.raw_sjpg_data - sjpeg->sjpeg_data);
sjpeg->io.raw_sjpg_data_size = sjpeg->sjpeg_data_size - frame_offset; sjpeg->io.raw_sjpg_data_size = sjpeg->sjpeg_data_size - frame_offset;
} else { }
else {
sjpeg->io.raw_sjpg_data_size = sjpeg->io.raw_sjpg_data_size =
(uint32_t)(sjpeg->frame_base_array[sjpeg_req_frame_index + 1] - sjpeg->io.raw_sjpg_data); (uint32_t)(sjpeg->frame_base_array[sjpeg_req_frame_index + 1] - sjpeg->io.raw_sjpg_data);
} }
sjpeg->io.raw_sjpg_data_next_read_pos = 0; sjpeg->io.raw_sjpg_data_next_read_pos = 0;
rc = jd_prepare( sjpeg->tjpeg_jd, input_func, sjpeg->workb, (size_t)TJPGD_WORKBUFF_SIZE, &(sjpeg->io)); rc = jd_prepare(sjpeg->tjpeg_jd, input_func, sjpeg->workb, (size_t)TJPGD_WORKBUFF_SIZE, &(sjpeg->io));
if(rc != JDR_OK ) return LV_RES_INV; if(rc != JDR_OK) return LV_RES_INV;
rc = jd_decomp ( sjpeg->tjpeg_jd, img_data_cb, 0); rc = jd_decomp(sjpeg->tjpeg_jd, img_data_cb, 0);
if(rc != JDR_OK ) return LV_RES_INV; if(rc != JDR_OK) return LV_RES_INV;
sjpeg->sjpeg_cache_frame_index = sjpeg_req_frame_index; sjpeg->sjpeg_cache_frame_index = sjpeg_req_frame_index;
} }
int offset = 0; int offset = 0;
uint8_t *cache = (uint8_t *)sjpeg->frame_cache + x*3 + ( y % sjpeg->sjpeg_single_frame_height ) * sjpeg->sjpeg_x_res*3; uint8_t * cache = (uint8_t *)sjpeg->frame_cache + x * 3 + (y % sjpeg->sjpeg_single_frame_height) * sjpeg->sjpeg_x_res *
3;
#if LV_COLOR_DEPTH == 32 #if LV_COLOR_DEPTH == 32
for( int i = 0; i < len; i++ ) { for(int i = 0; i < len; i++) {
buf[offset + 3] = 0xff; buf[offset + 3] = 0xff;
buf[offset + 2] = *cache++; buf[offset + 2] = *cache++;
buf[offset + 1] = *cache++; buf[offset + 1] = *cache++;
@@ -752,7 +762,7 @@ static lv_res_t decoder_read_line( lv_img_decoder_t * decoder, lv_img_decoder_ds
#elif LV_COLOR_DEPTH == 16 #elif LV_COLOR_DEPTH == 16
for( int i = 0; i < len; i++ ) { for(int i = 0; i < len; i++) {
uint16_t col_16bit = (*cache++ & 0xf8) << 8; uint16_t col_16bit = (*cache++ & 0xf8) << 8;
col_16bit |= (*cache++ & 0xFC) << 3; col_16bit |= (*cache++ & 0xFC) << 3;
col_16bit |= (*cache++ >> 3); col_16bit |= (*cache++ >> 3);
@@ -767,7 +777,7 @@ static lv_res_t decoder_read_line( lv_img_decoder_t * decoder, lv_img_decoder_ds
#elif LV_COLOR_DEPTH == 8 #elif LV_COLOR_DEPTH == 8
for( int i = 0; i < len; i++ ) { for(int i = 0; i < len; i++) {
uint8_t col_8bit = (*cache++ & 0xC0); uint8_t col_8bit = (*cache++ & 0xC0);
col_8bit |= (*cache++ & 0xe0) >> 2; col_8bit |= (*cache++ & 0xe0) >> 2;
col_8bit |= (*cache++ & 0xe0) >> 5; col_8bit |= (*cache++ & 0xe0) >> 5;
@@ -781,32 +791,33 @@ static lv_res_t decoder_read_line( lv_img_decoder_t * decoder, lv_img_decoder_ds
return LV_RES_OK; return LV_RES_OK;
} }
else if(dsc->src_type == LV_IMG_SRC_FILE) { else if(dsc->src_type == LV_IMG_SRC_FILE) {
SJPEG* sjpeg = ( SJPEG* ) dsc->user_data; SJPEG * sjpeg = (SJPEG *) dsc->user_data;
JRESULT rc; JRESULT rc;
int sjpeg_req_frame_index = y / sjpeg->sjpeg_single_frame_height; int sjpeg_req_frame_index = y / sjpeg->sjpeg_single_frame_height;
lv_fs_file_t* lv_file_p = &(sjpeg->io.lv_file); lv_fs_file_t * lv_file_p = &(sjpeg->io.lv_file);
if(!lv_file_p) goto end; if(!lv_file_p) goto end;
/*If line not from cache, refresh cache */ /*If line not from cache, refresh cache */
if(sjpeg_req_frame_index != sjpeg->sjpeg_cache_frame_index) { if(sjpeg_req_frame_index != sjpeg->sjpeg_cache_frame_index) {
sjpeg->io.raw_sjpg_data_next_read_pos = (int)(sjpeg->frame_base_offset [ sjpeg_req_frame_index ]); sjpeg->io.raw_sjpg_data_next_read_pos = (int)(sjpeg->frame_base_offset [ sjpeg_req_frame_index ]);
lv_fs_seek( &(sjpeg->io.lv_file), sjpeg->io.raw_sjpg_data_next_read_pos, LV_FS_SEEK_SET); lv_fs_seek(&(sjpeg->io.lv_file), sjpeg->io.raw_sjpg_data_next_read_pos, LV_FS_SEEK_SET);
rc = jd_prepare( sjpeg->tjpeg_jd, input_func, sjpeg->workb, (size_t)TJPGD_WORKBUFF_SIZE, &(sjpeg->io)); rc = jd_prepare(sjpeg->tjpeg_jd, input_func, sjpeg->workb, (size_t)TJPGD_WORKBUFF_SIZE, &(sjpeg->io));
if(rc != JDR_OK ) return LV_RES_INV; if(rc != JDR_OK) return LV_RES_INV;
rc = jd_decomp ( sjpeg->tjpeg_jd, img_data_cb, 0); rc = jd_decomp(sjpeg->tjpeg_jd, img_data_cb, 0);
if(rc != JDR_OK ) return LV_RES_INV; if(rc != JDR_OK) return LV_RES_INV;
sjpeg->sjpeg_cache_frame_index = sjpeg_req_frame_index; sjpeg->sjpeg_cache_frame_index = sjpeg_req_frame_index;
} }
int offset = 0; int offset = 0;
uint8_t *cache = (uint8_t *)sjpeg->frame_cache + x*3 + ( y % sjpeg->sjpeg_single_frame_height ) * sjpeg->sjpeg_x_res*3; uint8_t * cache = (uint8_t *)sjpeg->frame_cache + x * 3 + (y % sjpeg->sjpeg_single_frame_height) * sjpeg->sjpeg_x_res *
3;
#if LV_COLOR_DEPTH == 32 #if LV_COLOR_DEPTH == 32
for( int i = 0; i < len; i++ ) { for(int i = 0; i < len; i++) {
buf[offset + 3] = 0xff; buf[offset + 3] = 0xff;
buf[offset + 2] = *cache++; buf[offset + 2] = *cache++;
buf[offset + 1] = *cache++; buf[offset + 1] = *cache++;
@@ -815,7 +826,7 @@ static lv_res_t decoder_read_line( lv_img_decoder_t * decoder, lv_img_decoder_ds
} }
#elif LV_COLOR_DEPTH == 16 #elif LV_COLOR_DEPTH == 16
for( int i = 0; i < len; i++ ) { for(int i = 0; i < len; i++) {
uint16_t col_8bit = (*cache++ & 0xf8) << 8; uint16_t col_8bit = (*cache++ & 0xf8) << 8;
col_8bit |= (*cache++ & 0xFC) << 3; col_8bit |= (*cache++ & 0xFC) << 3;
col_8bit |= (*cache++ >> 3); col_8bit |= (*cache++ >> 3);
@@ -830,7 +841,7 @@ static lv_res_t decoder_read_line( lv_img_decoder_t * decoder, lv_img_decoder_ds
#elif LV_COLOR_DEPTH == 8 #elif LV_COLOR_DEPTH == 8
for( int i = 0; i < len; i++ ) { for(int i = 0; i < len; i++) {
uint8_t col_8bit = (*cache++ & 0xC0); uint8_t col_8bit = (*cache++ & 0xC0);
col_8bit |= (*cache++ & 0xe0) >> 2; col_8bit |= (*cache++ & 0xe0) >> 2;
col_8bit |= (*cache++ & 0xe0) >> 5; col_8bit |= (*cache++ & 0xe0) >> 5;
@@ -845,7 +856,7 @@ static lv_res_t decoder_read_line( lv_img_decoder_t * decoder, lv_img_decoder_ds
return LV_RES_OK; return LV_RES_OK;
} }
end: end:
return LV_RES_INV; return LV_RES_INV;
} }
@@ -854,37 +865,37 @@ static lv_res_t decoder_read_line( lv_img_decoder_t * decoder, lv_img_decoder_ds
* @param decoder pointer to the decoder where this function belongs * @param decoder pointer to the decoder where this function belongs
* @param dsc pointer to a descriptor which describes this decoding session * @param dsc pointer to a descriptor which describes this decoding session
*/ */
static void decoder_close( lv_img_decoder_t * decoder, lv_img_decoder_dsc_t * dsc ) static void decoder_close(lv_img_decoder_t * decoder, lv_img_decoder_dsc_t * dsc)
{ {
LV_UNUSED(decoder); LV_UNUSED(decoder);
/*Free all allocated data*/ /*Free all allocated data*/
SJPEG* sjpeg = ( SJPEG* ) dsc->user_data; SJPEG * sjpeg = (SJPEG *) dsc->user_data;
if(!sjpeg) return; if(!sjpeg) return;
switch(dsc->src_type) { switch(dsc->src_type) {
case LV_IMG_SRC_FILE: case LV_IMG_SRC_FILE:
if(sjpeg->io.lv_file.file_d) { if(sjpeg->io.lv_file.file_d) {
lv_fs_close(&(sjpeg->io.lv_file)); lv_fs_close(&(sjpeg->io.lv_file));
} }
lv_sjpg_cleanup(sjpeg); lv_sjpg_cleanup(sjpeg);
break; break;
case LV_IMG_SRC_VARIABLE: case LV_IMG_SRC_VARIABLE:
lv_sjpg_cleanup(sjpeg); lv_sjpg_cleanup(sjpeg);
break; break;
default: default:
; ;
} }
} }
static int is_jpg( const uint8_t *raw_data ) static int is_jpg(const uint8_t * raw_data)
{ {
const uint8_t jpg_signature[] = {0xFF, 0xD8, 0xFF, 0xE0, 0x00, 0x10, 0x4A, 0x46, 0x49, 0x46}; const uint8_t jpg_signature[] = {0xFF, 0xD8, 0xFF, 0xE0, 0x00, 0x10, 0x4A, 0x46, 0x49, 0x46};
return memcmp( jpg_signature, raw_data, sizeof( jpg_signature ) ) == 0; return memcmp(jpg_signature, raw_data, sizeof(jpg_signature)) == 0;
} }
static void lv_sjpg_free( SJPEG* sjpeg ) static void lv_sjpg_free(SJPEG * sjpeg)
{ {
if(sjpeg->frame_cache) lv_mem_free(sjpeg->frame_cache); if(sjpeg->frame_cache) lv_mem_free(sjpeg->frame_cache);
if(sjpeg->frame_base_array) lv_mem_free(sjpeg->frame_base_array); if(sjpeg->frame_base_array) lv_mem_free(sjpeg->frame_base_array);
@@ -893,12 +904,12 @@ static void lv_sjpg_free( SJPEG* sjpeg )
if(sjpeg->workb) lv_mem_free(sjpeg->workb); if(sjpeg->workb) lv_mem_free(sjpeg->workb);
} }
static void lv_sjpg_cleanup( SJPEG* sjpeg ) static void lv_sjpg_cleanup(SJPEG * sjpeg)
{ {
if(! sjpeg ) return; if(! sjpeg) return;
lv_sjpg_free( sjpeg ); lv_sjpg_free(sjpeg);
lv_mem_free( sjpeg ); lv_mem_free(sjpeg);
} }
#endif /*LV_USE_SJPG*/ #endif /*LV_USE_SJPG*/

View File

@@ -388,7 +388,8 @@ static void highlight_update(lv_obj_t * obj)
for(i = 0; i < calendar->highlighted_dates_num; i++) { for(i = 0; i < calendar->highlighted_dates_num; i++) {
if(calendar->highlighted_dates[i].year == calendar->showed_date.year && if(calendar->highlighted_dates[i].year == calendar->showed_date.year &&
calendar->highlighted_dates[i].month == calendar->showed_date.month) { calendar->highlighted_dates[i].month == calendar->showed_date.month) {
lv_btnmatrix_set_btn_ctrl(calendar->btnm, calendar->highlighted_dates[i].day - 1 + day_first + 7, LV_CALENDAR_CTRL_HIGHLIGHT); lv_btnmatrix_set_btn_ctrl(calendar->btnm, calendar->highlighted_dates[i].day - 1 + day_first + 7,
LV_CALENDAR_CTRL_HIGHLIGHT);
} }
} }
} }

View File

@@ -92,19 +92,20 @@ void lv_imgbtn_set_src(lv_obj_t * obj, lv_imgbtn_state_t state, const void * src
void lv_imgbtn_set_state(lv_obj_t * obj, lv_imgbtn_state_t state) void lv_imgbtn_set_state(lv_obj_t * obj, lv_imgbtn_state_t state)
{ {
LV_ASSERT_OBJ(obj, MY_CLASS); LV_ASSERT_OBJ(obj, MY_CLASS);
lv_state_t obj_state = LV_STATE_DEFAULT; lv_state_t obj_state = LV_STATE_DEFAULT;
if(state == LV_IMGBTN_STATE_PRESSED || state == LV_IMGBTN_STATE_CHECKED_PRESSED) obj_state |= LV_STATE_PRESSED; if(state == LV_IMGBTN_STATE_PRESSED || state == LV_IMGBTN_STATE_CHECKED_PRESSED) obj_state |= LV_STATE_PRESSED;
if(state == LV_IMGBTN_STATE_DISABLED || state == LV_IMGBTN_STATE_CHECKED_DISABLED) obj_state |= LV_STATE_DISABLED; if(state == LV_IMGBTN_STATE_DISABLED || state == LV_IMGBTN_STATE_CHECKED_DISABLED) obj_state |= LV_STATE_DISABLED;
if(state == LV_IMGBTN_STATE_CHECKED_DISABLED || state == LV_IMGBTN_STATE_CHECKED_PRESSED || state == LV_IMGBTN_STATE_CHECKED_RELEASED) { if(state == LV_IMGBTN_STATE_CHECKED_DISABLED || state == LV_IMGBTN_STATE_CHECKED_PRESSED ||
obj_state |= LV_STATE_CHECKED; state == LV_IMGBTN_STATE_CHECKED_RELEASED) {
} obj_state |= LV_STATE_CHECKED;
}
lv_obj_clear_state(obj, LV_STATE_CHECKED | LV_STATE_PRESSED | LV_STATE_DISABLED); lv_obj_clear_state(obj, LV_STATE_CHECKED | LV_STATE_PRESSED | LV_STATE_DISABLED);
lv_obj_add_state(obj, obj_state); lv_obj_add_state(obj, obj_state);
refr_img(obj); refr_img(obj);
} }
/*===================== /*=====================

View File

@@ -197,7 +197,7 @@ void lv_keyboard_set_popovers(lv_obj_t * obj, bool en)
{ {
lv_keyboard_t * keyboard = (lv_keyboard_t *)obj; lv_keyboard_t * keyboard = (lv_keyboard_t *)obj;
if (keyboard->popovers == en) { if(keyboard->popovers == en) {
return; return;
} }
@@ -406,10 +406,11 @@ static void lv_keyboard_update_ctrl_map(lv_obj_t * obj)
{ {
lv_keyboard_t * keyboard = (lv_keyboard_t *)obj; lv_keyboard_t * keyboard = (lv_keyboard_t *)obj;
if (keyboard->popovers) { if(keyboard->popovers) {
/*Apply the current control map (already includes LV_BTNMATRIX_CTRL_POPOVER flags)*/ /*Apply the current control map (already includes LV_BTNMATRIX_CTRL_POPOVER flags)*/
lv_btnmatrix_set_ctrl_map(obj, kb_ctrl[keyboard->mode]); lv_btnmatrix_set_ctrl_map(obj, kb_ctrl[keyboard->mode]);
} else { }
else {
/*Make a copy of the current control map*/ /*Make a copy of the current control map*/
lv_btnmatrix_t * btnm = (lv_btnmatrix_t *)obj; lv_btnmatrix_t * btnm = (lv_btnmatrix_t *)obj;
lv_btnmatrix_ctrl_t * ctrl_map = lv_mem_alloc(btnm->btn_cnt * sizeof(lv_btnmatrix_ctrl_t)); lv_btnmatrix_ctrl_t * ctrl_map = lv_mem_alloc(btnm->btn_cnt * sizeof(lv_btnmatrix_ctrl_t));

View File

@@ -30,24 +30,24 @@ static void msgbox_close_click_event_cb(lv_event_t * e);
* STATIC VARIABLES * STATIC VARIABLES
**********************/ **********************/
const lv_obj_class_t lv_msgbox_class = { const lv_obj_class_t lv_msgbox_class = {
.base_class = &lv_obj_class, .base_class = &lv_obj_class,
.width_def = LV_DPI_DEF * 2, .width_def = LV_DPI_DEF * 2,
.height_def = LV_SIZE_CONTENT, .height_def = LV_SIZE_CONTENT,
.instance_size = sizeof(lv_msgbox_t) .instance_size = sizeof(lv_msgbox_t)
}; };
const lv_obj_class_t lv_msgbox_content_class = { const lv_obj_class_t lv_msgbox_content_class = {
.base_class = &lv_obj_class, .base_class = &lv_obj_class,
.width_def = LV_PCT(100), .width_def = LV_PCT(100),
.height_def = LV_SIZE_CONTENT, .height_def = LV_SIZE_CONTENT,
.instance_size = sizeof(lv_obj_t) .instance_size = sizeof(lv_obj_t)
}; };
const lv_obj_class_t lv_msgbox_backdrop_class = { const lv_obj_class_t lv_msgbox_backdrop_class = {
.base_class = &lv_obj_class, .base_class = &lv_obj_class,
.width_def = LV_PCT(100), .width_def = LV_PCT(100),
.height_def = LV_PCT(100), .height_def = LV_PCT(100),
.instance_size = sizeof(lv_obj_t) .instance_size = sizeof(lv_obj_t)
}; };
/********************** /**********************
@@ -85,7 +85,7 @@ lv_obj_t * lv_msgbox_create(lv_obj_t * parent, const char * title, const char *
bool has_title = title && strlen(title) > 0; bool has_title = title && strlen(title) > 0;
/*When a close button is required, we need the empty label as spacer to push the button to the right*/ /*When a close button is required, we need the empty label as spacer to push the button to the right*/
if (add_close_btn || has_title) { if(add_close_btn || has_title) {
mbox->title = lv_label_create(obj); mbox->title = lv_label_create(obj);
lv_label_set_text(mbox->title, has_title ? title : ""); lv_label_set_text(mbox->title, has_title ? title : "");
lv_label_set_long_mode(mbox->title, LV_LABEL_LONG_SCROLL_CIRCULAR); lv_label_set_long_mode(mbox->title, LV_LABEL_LONG_SCROLL_CIRCULAR);
@@ -108,7 +108,7 @@ lv_obj_t * lv_msgbox_create(lv_obj_t * parent, const char * title, const char *
mbox->content = lv_obj_class_create_obj(&lv_msgbox_content_class, obj); mbox->content = lv_obj_class_create_obj(&lv_msgbox_content_class, obj);
bool has_txt = txt && strlen(txt) > 0; bool has_txt = txt && strlen(txt) > 0;
if (has_txt) { if(has_txt) {
mbox->text = lv_label_create(mbox->content); mbox->text = lv_label_create(mbox->content);
lv_label_set_text(mbox->text, txt); lv_label_set_text(mbox->text, txt);
lv_label_set_long_mode(mbox->text, LV_LABEL_LONG_WRAP); lv_label_set_long_mode(mbox->text, LV_LABEL_LONG_WRAP);

View File

@@ -175,7 +175,7 @@ void lv_spinbox_set_pos(lv_obj_t * obj, uint8_t pos)
* @param spinbox pointer to spinbox * @param spinbox pointer to spinbox
* @param direction the direction (LV_DIR_RIGHT or LV_DIR_LEFT) * @param direction the direction (LV_DIR_RIGHT or LV_DIR_LEFT)
*/ */
void lv_spinbox_set_digit_step_direction(lv_obj_t *obj, lv_dir_t direction) void lv_spinbox_set_digit_step_direction(lv_obj_t * obj, lv_dir_t direction)
{ {
LV_ASSERT_OBJ(obj, MY_CLASS); LV_ASSERT_OBJ(obj, MY_CLASS);
lv_spinbox_t * spinbox = (lv_spinbox_t *)obj; lv_spinbox_t * spinbox = (lv_spinbox_t *)obj;
@@ -360,10 +360,10 @@ static void lv_spinbox_event(const lv_obj_class_t * class_p, lv_event_t * e)
lv_indev_t * indev = lv_indev_get_act(); lv_indev_t * indev = lv_indev_get_act();
if(lv_indev_get_type(indev) == LV_INDEV_TYPE_ENCODER) { if(lv_indev_get_type(indev) == LV_INDEV_TYPE_ENCODER) {
if(lv_group_get_editing(lv_obj_get_group(obj))) { if(lv_group_get_editing(lv_obj_get_group(obj))) {
if (spinbox->digit_count > 1) { if(spinbox->digit_count > 1) {
if (spinbox->digit_step_dir == LV_DIR_RIGHT) { if(spinbox->digit_step_dir == LV_DIR_RIGHT) {
if(spinbox->step > 1) { if(spinbox->step > 1) {
lv_spinbox_step_next(obj); lv_spinbox_step_next(obj);
} }
else { else {
/*Restart from the MSB*/ /*Restart from the MSB*/

View File

@@ -122,7 +122,7 @@ void lv_spinbox_set_digit_step_direction(lv_obj_t * obj, lv_dir_t direction);
* Get spinbox rollover function status * Get spinbox rollover function status
* @param spinbox pointer to spinbox * @param spinbox pointer to spinbox
*/ */
bool lv_spinbox_get_rollover(lv_obj_t *obj); bool lv_spinbox_get_rollover(lv_obj_t * obj);
/** /**
* Get the spinbox numeral value (user has to convert to float according to its digit format) * Get the spinbox numeral value (user has to convert to float according to its digit format)

View File

@@ -71,7 +71,7 @@ bool lv_font_get_glyph_dsc(const lv_font_t * font_p, lv_font_glyph_dsc_t * dsc_o
bool found = false; bool found = false;
while(f) { while(f) {
found = f->get_glyph_dsc(f, dsc_out, letter, letter_next); found = f->get_glyph_dsc(f, dsc_out, letter, letter_next);
if (found && !dsc_out->is_placeholder) { if(found && !dsc_out->is_placeholder) {
dsc_out->resolved_font = f; dsc_out->resolved_font = f;
break; break;
} }

View File

@@ -36,14 +36,15 @@ extern "C" {
struct _lv_font_t; struct _lv_font_t;
/** Describes the properties of a glyph.*/ /** Describes the properties of a glyph.*/
typedef struct { typedef struct {
const struct _lv_font_t *resolved_font; /**< Pointer to a font where the gylph was actually found after handling fallbacks*/ const struct _lv_font_t *
resolved_font; /**< Pointer to a font where the gylph was actually found after handling fallbacks*/
uint16_t adv_w; /**< The glyph needs this space. Draw the next glyph after this width.*/ uint16_t adv_w; /**< The glyph needs this space. Draw the next glyph after this width.*/
uint16_t box_w; /**< Width of the glyph's bounding box*/ uint16_t box_w; /**< Width of the glyph's bounding box*/
uint16_t box_h; /**< Height of the glyph's bounding box*/ uint16_t box_h; /**< Height of the glyph's bounding box*/
int16_t ofs_x; /**< x offset of the bounding box*/ int16_t ofs_x; /**< x offset of the bounding box*/
int16_t ofs_y; /**< y offset of the bounding box*/ int16_t ofs_y; /**< y offset of the bounding box*/
uint8_t bpp:4; /**< Bit-per-pixel: 1, 2, 4, 8*/ uint8_t bpp: 4; /**< Bit-per-pixel: 1, 2, 4, 8*/
uint8_t is_placeholder:1; /** Glyph is missing. But placeholder will still be displayed */ uint8_t is_placeholder: 1; /** Glyph is missing. But placeholder will still be displayed */
} lv_font_glyph_dsc_t; } lv_font_glyph_dsc_t;
/** The bitmaps might be upscaled by 3 to achieve subpixel rendering.*/ /** The bitmaps might be upscaled by 3 to achieve subpixel rendering.*/

View File

@@ -40,7 +40,7 @@ void lv_gpu_sdl_init();
/** /**
* @brief Free caches * @brief Free caches
* *
*/ */
void lv_gpu_sdl_deinit(); void lv_gpu_sdl_deinit();

View File

@@ -102,13 +102,13 @@ void lv_draw_letter(const lv_point_t * pos_p, const lv_area_t * clip_area,
lv_font_glyph_key_t glyph_key = font_key_glyph_create(font_p, letter); lv_font_glyph_key_t glyph_key = font_key_glyph_create(font_p, letter);
bool glyph_found = false; bool glyph_found = false;
SDL_Texture *texture = lv_gpu_draw_cache_get(&glyph_key, sizeof(glyph_key), &glyph_found); SDL_Texture * texture = lv_gpu_draw_cache_get(&glyph_key, sizeof(glyph_key), &glyph_found);
if (!glyph_found) { if(!glyph_found) {
if (g.resolved_font) { if(g.resolved_font) {
font_p = g.resolved_font; font_p = g.resolved_font;
} }
const uint8_t *bmp = lv_font_get_glyph_bitmap(font_p, letter); const uint8_t * bmp = lv_font_get_glyph_bitmap(font_p, letter);
uint8_t *buf = lv_mem_alloc(g.box_w * g.box_h); uint8_t * buf = lv_mem_alloc(g.box_w * g.box_h);
lv_sdl_to_8bpp(buf, bmp, g.box_w, g.box_h, g.box_w, g.bpp); lv_sdl_to_8bpp(buf, bmp, g.box_w, g.box_h, g.box_w, g.bpp);
SDL_Surface * mask = lv_sdl_create_mask_surface(buf, g.box_w, g.box_h, g.box_w); SDL_Surface * mask = lv_sdl_create_mask_surface(buf, g.box_w, g.box_h, g.box_w);
texture = SDL_CreateTextureFromSurface(renderer, mask); texture = SDL_CreateTextureFromSurface(renderer, mask);
@@ -116,7 +116,7 @@ void lv_draw_letter(const lv_point_t * pos_p, const lv_area_t * clip_area,
lv_mem_free(buf); lv_mem_free(buf);
lv_gpu_draw_cache_put(&glyph_key, sizeof(glyph_key), texture); lv_gpu_draw_cache_put(&glyph_key, sizeof(glyph_key), texture);
} }
if (!texture) { if(!texture) {
return; return;
} }
lv_area_t dst = {pos_x, pos_y, pos_x + g.box_w - 1, pos_y + g.box_h - 1}; lv_area_t dst = {pos_x, pos_y, pos_x + g.box_w - 1, pos_y + g.box_h - 1};

View File

@@ -294,7 +294,7 @@ static uint32_t lv_lru_hash(lv_lru_t * cache, const void * key, uint32_t key_len
case 1: case 1:
h ^= data[0]; h ^= data[0];
h *= m; h *= m;
break; break;
}; };
h ^= h >> 13; h ^= h >> 13;

View File

@@ -157,7 +157,8 @@ lv_disp_t * lv_disp_drv_register(lv_disp_drv_t * driver)
if(lv_theme_default_is_inited() == false) { if(lv_theme_default_is_inited() == false) {
disp->theme = lv_theme_default_init(disp, lv_palette_main(LV_PALETTE_BLUE), lv_palette_main(LV_PALETTE_RED), disp->theme = lv_theme_default_init(disp, lv_palette_main(LV_PALETTE_BLUE), lv_palette_main(LV_PALETTE_RED),
LV_THEME_DEFAULT_DARK, LV_FONT_DEFAULT); LV_THEME_DEFAULT_DARK, LV_FONT_DEFAULT);
} else { }
else {
disp->theme = lv_theme_default_get(); disp->theme = lv_theme_default_get();
} }
#endif #endif

View File

@@ -80,9 +80,12 @@ typedef struct _lv_disp_drv_t {
lv_coord_t hor_res; /**< Horizontal resolution.*/ lv_coord_t hor_res; /**< Horizontal resolution.*/
lv_coord_t ver_res; /**< Vertical resolution.*/ lv_coord_t ver_res; /**< Vertical resolution.*/
lv_coord_t physical_hor_res; /**< Horizontal resolution of the full / physical display. Set to -1 for fullscreen mode.*/ lv_coord_t
lv_coord_t physical_ver_res; /**< Vertical resolution of the full / physical display. Set to -1 for fullscreen mode.*/ physical_hor_res; /**< Horizontal resolution of the full / physical display. Set to -1 for fullscreen mode.*/
lv_coord_t offset_x; /**< Horizontal offset from the full / physical display. Set to 0 for fullscreen mode.*/ lv_coord_t
physical_ver_res; /**< Vertical resolution of the full / physical display. Set to -1 for fullscreen mode.*/
lv_coord_t
offset_x; /**< Horizontal offset from the full / physical display. Set to 0 for fullscreen mode.*/
lv_coord_t offset_y; /**< Vertical offset from the full / physical display. Set to 0 for fullscreen mode.*/ lv_coord_t offset_y; /**< Vertical offset from the full / physical display. Set to 0 for fullscreen mode.*/
/** Pointer to a buffer initialized with `lv_disp_draw_buf_init()`. /** Pointer to a buffer initialized with `lv_disp_draw_buf_init()`.
@@ -173,7 +176,7 @@ uint8_t del_prev :
lv_opa_t bg_opa; /**<Opacity of the background color or wallpaper*/ lv_opa_t bg_opa; /**<Opacity of the background color or wallpaper*/
lv_color_t bg_color; /**< Default display color when screens are transparent*/ lv_color_t bg_color; /**< Default display color when screens are transparent*/
const void * bg_img; /**< An image source to display as wallpaper*/ const void * bg_img; /**< An image source to display as wallpaper*/
void (*bg_fn)(lv_area_t*);/**< A function to handle drawing*/ void (*bg_fn)(lv_area_t *); /**< A function to handle drawing*/
/** Invalidated (marked to redraw) areas*/ /** Invalidated (marked to redraw) areas*/
lv_area_t inv_areas[LV_INV_BUF_SIZE]; lv_area_t inv_areas[LV_INV_BUF_SIZE];

View File

@@ -29,8 +29,8 @@
* STATIC VARIABLES * STATIC VARIABLES
**********************/ **********************/
#if !LV_TICK_CUSTOM #if !LV_TICK_CUSTOM
static uint32_t sys_time = 0; static uint32_t sys_time = 0;
static volatile uint8_t tick_irq_flag; static volatile uint8_t tick_irq_flag;
#endif #endif
/********************** /**********************

View File

@@ -170,7 +170,7 @@ uint32_t lv_anim_timeline_get_playtime(lv_anim_timeline_t * at)
uint32_t playtime = 0; uint32_t playtime = 0;
for(uint32_t i = 0; i < at->anim_dsc_cnt; i++) { for(uint32_t i = 0; i < at->anim_dsc_cnt; i++) {
uint32_t end = lv_anim_get_playtime(&at->anim_dsc[i].anim); uint32_t end = lv_anim_get_playtime(&at->anim_dsc[i].anim);
if (end == LV_ANIM_PLAYTIME_INFINITE) if(end == LV_ANIM_PLAYTIME_INFINITE)
return end; return end;
end += at->anim_dsc[i].start_time; end += at->anim_dsc[i].start_time;
if(end > playtime) { if(end > playtime) {

View File

@@ -440,13 +440,13 @@ static lv_base_dir_t get_next_run(const char * txt, lv_base_dir_t base_dir, uint
/*Find the first strong char. Skip the neutrals*/ /*Find the first strong char. Skip the neutrals*/
while(dir == LV_BASE_DIR_NEUTRAL || dir == LV_BASE_DIR_WEAK) { while(dir == LV_BASE_DIR_NEUTRAL || dir == LV_BASE_DIR_WEAK) {
letter = _lv_txt_encoded_next(txt, &i); letter = _lv_txt_encoded_next(txt, &i);
pos_conv_i++; pos_conv_i++;
dir = lv_bidi_get_letter_dir(letter); dir = lv_bidi_get_letter_dir(letter);
if(dir == LV_BASE_DIR_NEUTRAL) dir = bracket_process(txt, i, max_len, letter, base_dir); if(dir == LV_BASE_DIR_NEUTRAL) dir = bracket_process(txt, i, max_len, letter, base_dir);
if(dir==LV_BASE_DIR_LTR || dir==LV_BASE_DIR_RTL) break; if(dir == LV_BASE_DIR_LTR || dir == LV_BASE_DIR_RTL) break;
if(i >= max_len || txt[i] == '\0' || txt[i] == '\n' || txt[i] == '\r') { if(i >= max_len || txt[i] == '\0' || txt[i] == '\n' || txt[i] == '\r') {
*len = i; *len = i;
*pos_conv_len = pos_conv_i; *pos_conv_len = pos_conv_i;
@@ -468,14 +468,14 @@ static lv_base_dir_t get_next_run(const char * txt, lv_base_dir_t base_dir, uint
pos_conv_i++; pos_conv_i++;
next_dir = lv_bidi_get_letter_dir(letter); next_dir = lv_bidi_get_letter_dir(letter);
if(next_dir == LV_BASE_DIR_NEUTRAL) next_dir = bracket_process(txt, i, max_len, letter, base_dir); if(next_dir == LV_BASE_DIR_NEUTRAL) next_dir = bracket_process(txt, i, max_len, letter, base_dir);
if(next_dir == LV_BASE_DIR_WEAK){ if(next_dir == LV_BASE_DIR_WEAK) {
if(run_dir == LV_BASE_DIR_RTL){ if(run_dir == LV_BASE_DIR_RTL) {
if(base_dir == LV_BASE_DIR_RTL){ if(base_dir == LV_BASE_DIR_RTL) {
next_dir = LV_BASE_DIR_LTR; next_dir = LV_BASE_DIR_LTR;
} }
} }
} }
/*New dir found?*/ /*New dir found?*/
if((next_dir == LV_BASE_DIR_RTL || next_dir == LV_BASE_DIR_LTR) && next_dir != run_dir) { if((next_dir == LV_BASE_DIR_RTL || next_dir == LV_BASE_DIR_LTR) && next_dir != run_dir) {

View File

@@ -91,7 +91,7 @@ void _lv_log_add(lv_log_level_t level, const char * file, int line, const char *
vprintf(format, args); vprintf(format, args);
printf(" \t(in %s line #%d)\n", &file[p], line); printf(" \t(in %s line #%d)\n", &file[p], line);
#else #else
if (custom_print_cb) { if(custom_print_cb) {
char buf[512]; char buf[512];
#if LV_SPRINTF_CUSTOM #if LV_SPRINTF_CUSTOM
char msg[256]; char msg[256];

View File

@@ -749,7 +749,7 @@ static int _vsnprintf(out_fct_type out, char * buffer, const size_t maxlen, cons
width, flags); width, flags);
} }
} }
else if (*format == 'V') { else if(*format == 'V') {
lv_vaformat_t * vaf = va_arg(va, lv_vaformat_t *); lv_vaformat_t * vaf = va_arg(va, lv_vaformat_t *);
va_list copy; va_list copy;

View File

@@ -35,19 +35,19 @@
#define _LV_PRINTF_H_ #define _LV_PRINTF_H_
#if defined(__has_include) #if defined(__has_include)
# if __has_include(<inttypes.h>) #if __has_include(<inttypes.h>)
# include <inttypes.h> #include <inttypes.h>
/* platform-specific printf format for int32_t, usually "d" or "ld" */ /* platform-specific printf format for int32_t, usually "d" or "ld" */
# define LV_PRId32 PRId32 #define LV_PRId32 PRId32
# define LV_PRIu32 PRIu32 #define LV_PRIu32 PRIu32
# else #else
# define LV_PRId32 "d" #define LV_PRId32 "d"
# define LV_PRIu32 "u" #define LV_PRIu32 "u"
# endif #endif
#else #else
/* hope this is correct for ports without __has_include or without inttypes.h */ /* hope this is correct for ports without __has_include or without inttypes.h */
# define LV_PRId32 "d" #define LV_PRId32 "d"
# define LV_PRIu32 "u" #define LV_PRIu32 "u"
#endif #endif
#ifdef __cplusplus #ifdef __cplusplus
@@ -64,8 +64,8 @@ extern "C" {
#include "lv_types.h" #include "lv_types.h"
typedef struct { typedef struct {
const char * fmt; const char * fmt;
va_list * va; va_list * va;
} lv_vaformat_t; } lv_vaformat_t;
/** /**

View File

@@ -88,7 +88,7 @@ typedef uint32_t lv_uintptr_t;
#endif #endif
#ifdef __cplusplus #ifdef __cplusplus
} /*extern "C"*/ } /*extern "C"*/
#endif #endif
#endif /*LV_TYPES_H*/ #endif /*LV_TYPES_H*/

View File

@@ -384,7 +384,8 @@ static void lv_arc_event(const lv_obj_class_t * class_p, lv_event_t * e)
if(lv_obj_has_flag(obj, LV_OBJ_FLAG_ADV_HITTEST)) { if(lv_obj_has_flag(obj, LV_OBJ_FLAG_ADV_HITTEST)) {
r -= indic_width; r -= indic_width;
} else { }
else {
r -= LV_MAX(r / 4, indic_width); r -= LV_MAX(r / 4, indic_width);
} }
if(r < 1) r = 1; if(r < 1) r = 1;
@@ -515,7 +516,7 @@ static void lv_arc_event(const lv_obj_class_t * class_p, lv_event_t * e)
lv_area_set(&a, p.x - r, p.y - r, p.x + r, p.y + r); lv_area_set(&a, p.x - r, p.y - r, p.x + r, p.y + r);
if(_lv_area_is_point_on(&a, info->point, LV_RADIUS_CIRCLE)) { if(_lv_area_is_point_on(&a, info->point, LV_RADIUS_CIRCLE)) {
info->res = false; info->res = false;
return; return;
} }
/*Valid if no clicked outside*/ /*Valid if no clicked outside*/

View File

@@ -219,7 +219,7 @@ void lv_btnmatrix_set_btn_ctrl(lv_obj_t * obj, uint16_t btn_id, lv_btnmatrix_ctr
btnm->ctrl_bits[btn_id] |= ctrl; btnm->ctrl_bits[btn_id] |= ctrl;
invalidate_button_area(obj, btn_id); invalidate_button_area(obj, btn_id);
if (ctrl & LV_BTNMATRIX_CTRL_POPOVER) { if(ctrl & LV_BTNMATRIX_CTRL_POPOVER) {
lv_obj_refresh_ext_draw_size(obj); lv_obj_refresh_ext_draw_size(obj);
} }
} }
@@ -235,7 +235,7 @@ void lv_btnmatrix_clear_btn_ctrl(lv_obj_t * obj, uint16_t btn_id, lv_btnmatrix_c
btnm->ctrl_bits[btn_id] &= (~ctrl); btnm->ctrl_bits[btn_id] &= (~ctrl);
invalidate_button_area(obj, btn_id); invalidate_button_area(obj, btn_id);
if (ctrl & LV_BTNMATRIX_CTRL_POPOVER) { if(ctrl & LV_BTNMATRIX_CTRL_POPOVER) {
lv_obj_refresh_ext_draw_size(obj); lv_obj_refresh_ext_draw_size(obj);
} }
} }
@@ -400,10 +400,11 @@ static void lv_btnmatrix_event(const lv_obj_class_t * class_p, lv_event_t * e)
if(code == LV_EVENT_REFR_EXT_DRAW_SIZE) { if(code == LV_EVENT_REFR_EXT_DRAW_SIZE) {
lv_coord_t * s = lv_event_get_param(e); lv_coord_t * s = lv_event_get_param(e);
if (has_popovers_in_top_row(obj)) { if(has_popovers_in_top_row(obj)) {
/*reserve one row worth of extra space to account for popovers in the top row*/ /*reserve one row worth of extra space to account for popovers in the top row*/
*s = btnm->row_cnt > 0 ? lv_obj_get_content_height(obj) / btnm->row_cnt : 0; *s = btnm->row_cnt > 0 ? lv_obj_get_content_height(obj) / btnm->row_cnt : 0;
} else { }
else {
*s = 0; *s = 0;
} }
} }
@@ -765,7 +766,7 @@ static void draw_main(lv_event_t * e)
lv_coord_t btn_height = lv_area_get_height(&btn_area); lv_coord_t btn_height = lv_area_get_height(&btn_area);
if ((btn_state & LV_STATE_PRESSED) && (btnm->ctrl_bits[btn_i] & LV_BTNMATRIX_CTRL_POPOVER)) { if((btn_state & LV_STATE_PRESSED) && (btnm->ctrl_bits[btn_i] & LV_BTNMATRIX_CTRL_POPOVER)) {
/*Push up the upper boundary of the btn area to create the popover*/ /*Push up the upper boundary of the btn area to create the popover*/
btn_area.y1 -= btn_height; btn_area.y1 -= btn_height;
} }
@@ -796,7 +797,7 @@ static void draw_main(lv_event_t * e)
btn_area.x2 = btn_area.x1 + txt_size.x; btn_area.x2 = btn_area.x1 + txt_size.x;
btn_area.y2 = btn_area.y1 + txt_size.y; btn_area.y2 = btn_area.y1 + txt_size.y;
if ((btn_state & LV_STATE_PRESSED) && (btnm->ctrl_bits[btn_i] & LV_BTNMATRIX_CTRL_POPOVER)) { if((btn_state & LV_STATE_PRESSED) && (btnm->ctrl_bits[btn_i] & LV_BTNMATRIX_CTRL_POPOVER)) {
/*Push up the button text into the popover*/ /*Push up the button text into the popover*/
btn_area.y1 -= btn_height / 2; btn_area.y1 -= btn_height / 2;
btn_area.y2 -= btn_height / 2; btn_area.y2 -= btn_height / 2;
@@ -828,7 +829,8 @@ static void allocate_btn_areas_and_controls(const lv_obj_t * obj, const char **
while(map[i] && map[i][0] != '\0') { while(map[i] && map[i][0] != '\0') {
if(strcmp(map[i], "\n") != 0) { /*Do not count line breaks*/ if(strcmp(map[i], "\n") != 0) { /*Do not count line breaks*/
btn_cnt++; btn_cnt++;
} else { }
else {
btnm->row_cnt++; btnm->row_cnt++;
} }
i++; i++;
@@ -998,7 +1000,7 @@ static void invalidate_button_area(const lv_obj_t * obj, uint16_t btn_idx)
btn_area.x2 += obj_area.x1 + row_gap; btn_area.x2 += obj_area.x1 + row_gap;
btn_area.y2 += obj_area.y1 + col_gap; btn_area.y2 += obj_area.y1 + col_gap;
if ((btn_idx == btnm->btn_id_sel) && (btnm->ctrl_bits[btn_idx] & LV_BTNMATRIX_CTRL_POPOVER)) { if((btn_idx == btnm->btn_id_sel) && (btnm->ctrl_bits[btn_idx] & LV_BTNMATRIX_CTRL_POPOVER)) {
/*Push up the upper boundary of the btn area to also invalidate the popover*/ /*Push up the upper boundary of the btn area to also invalidate the popover*/
btn_area.y1 -= lv_area_get_height(&btn_area); btn_area.y1 -= lv_area_get_height(&btn_area);
} }
@@ -1031,15 +1033,15 @@ static bool has_popovers_in_top_row(lv_obj_t * obj)
{ {
lv_btnmatrix_t * btnm = (lv_btnmatrix_t *)obj; lv_btnmatrix_t * btnm = (lv_btnmatrix_t *)obj;
if (btnm->row_cnt <= 0) { if(btnm->row_cnt <= 0) {
return false; return false;
} }
const char ** map_row = btnm->map_p; const char ** map_row = btnm->map_p;
uint16_t btn_cnt = 0; uint16_t btn_cnt = 0;
while (map_row[btn_cnt] && strcmp(map_row[btn_cnt], "\n") != 0 && map_row[btn_cnt][0] != '\0') { while(map_row[btn_cnt] && strcmp(map_row[btn_cnt], "\n") != 0 && map_row[btn_cnt][0] != '\0') {
if (button_is_popover(btnm->ctrl_bits[btn_cnt])) { if(button_is_popover(btnm->ctrl_bits[btn_cnt])) {
return true; return true;
} }
btn_cnt++; btn_cnt++;

View File

@@ -852,7 +852,8 @@ static void draw_main(lv_event_t * e)
if(label->long_mode == LV_LABEL_LONG_SCROLL || label->long_mode == LV_LABEL_LONG_SCROLL_CIRCULAR) { if(label->long_mode == LV_LABEL_LONG_SCROLL || label->long_mode == LV_LABEL_LONG_SCROLL_CIRCULAR) {
lv_draw_label(&txt_coords, &txt_clip, &label_draw_dsc, label->text, hint); lv_draw_label(&txt_coords, &txt_clip, &label_draw_dsc, label->text, hint);
} else { }
else {
lv_draw_label(&txt_coords, clip_area, &label_draw_dsc, label->text, hint); lv_draw_label(&txt_coords, clip_area, &label_draw_dsc, label->text, hint);
} }
@@ -1123,7 +1124,7 @@ static void lv_label_refr_text(lv_obj_t * obj)
for(i = 0; i <= LV_LABEL_DOT_NUM; i++) { for(i = 0; i <= LV_LABEL_DOT_NUM; i++) {
len += _lv_txt_encoded_size(&label->text[byte_id]); len += _lv_txt_encoded_size(&label->text[byte_id]);
_lv_txt_encoded_next(label->text, &byte_id); _lv_txt_encoded_next(label->text, &byte_id);
if (len > LV_LABEL_DOT_NUM || byte_id > txt_len) { if(len > LV_LABEL_DOT_NUM || byte_id > txt_len) {
break; break;
} }
} }