BigW Consortium Gitlab

Commit 9a1b8d07 by Kiss-Vamosi Gabor

image upscale added as lv_img attribute

parent b5feee60
...@@ -45,11 +45,11 @@ static uint16_t lv_draw_rect_radius_corr(uint16_t r, cord_t w, cord_t h); ...@@ -45,11 +45,11 @@ static uint16_t lv_draw_rect_radius_corr(uint16_t r, cord_t w, cord_t h);
#if LV_VDB_SIZE != 0 #if LV_VDB_SIZE != 0
static void (*fill_fp)(const area_t * cords_p, const area_t * mask_p, color_t color, opa_t opa) = lv_vfill; static void (*fill_fp)(const area_t * cords_p, const area_t * mask_p, color_t color, opa_t opa) = lv_vfill;
static void (*letter_fp)(const point_t * pos_p, const area_t * mask_p, const font_t * font_p, uint8_t letter, color_t color, opa_t opa) = lv_vletter; static void (*letter_fp)(const point_t * pos_p, const area_t * mask_p, const font_t * font_p, uint8_t letter, color_t color, opa_t opa) = lv_vletter;
static void (*map_fp)(const area_t * cords_p, const area_t * mask_p, const color_t * map_p, opa_t opa, bool transp, color_t recolor, opa_t recolor_opa) = lv_vmap; static void (*map_fp)(const area_t * cords_p, const area_t * mask_p, const color_t * map_p, opa_t opa, bool transp, bool upscale, color_t recolor, opa_t recolor_opa) = lv_vmap;
#else #else
static void (*fill_fp)(const area_t * cords_p, const area_t * mask_p, color_t color, opa_t opa) = lv_rfill; static void (*fill_fp)(const area_t * cords_p, const area_t * mask_p, color_t color, opa_t opa) = lv_rfill;
static void (*letter_fp)(const point_t * pos_p, const area_t * mask_p, const font_t * font_p, uint8_t letter, color_t color, opa_t opa) = lv_rletter; static void (*letter_fp)(const point_t * pos_p, const area_t * mask_p, const font_t * font_p, uint8_t letter, color_t color, opa_t opa) = lv_rletter;
static void (*map_fp)(const area_t * cords_p, const area_t * mask_p, const color_t * map_p, opa_t opa, bool transp, color_t recolor, opa_t recolor_opa) = lv_rmap; static void (*map_fp)(const area_t * cords_p, const area_t * mask_p, const color_t * map_p, opa_t opa, bool transp, bool upscale, color_t recolor, opa_t recolor_opa) = lv_rmap;
#endif #endif
...@@ -177,61 +177,86 @@ void lv_draw_label(const area_t * cords_p,const area_t * mask_p, ...@@ -177,61 +177,86 @@ void lv_draw_label(const area_t * cords_p,const area_t * mask_p,
void lv_draw_img(const area_t * cords_p, const area_t * mask_p, void lv_draw_img(const area_t * cords_p, const area_t * mask_p,
const lv_imgs_t * imgs_p, opa_t opa, const char * fn) const lv_imgs_t * imgs_p, opa_t opa, const char * fn)
{ {
if(fn == NULL) { if(fn == NULL) {
lv_draw_rect(cords_p, mask_p, &lv_img_no_pic_rects, opa); lv_draw_rect(cords_p, mask_p, &lv_img_no_pic_rects, opa);
lv_draw_label(cords_p, mask_p,&lv_img_no_pic_labels, opa, "No data"); lv_draw_label(cords_p, mask_p,&lv_img_no_pic_labels, opa, "No data");
} else { } else {
fs_file_t file; fs_file_t file;
fs_res_t res = fs_open(&file, fn, FS_MODE_RD); fs_res_t res = fs_open(&file, fn, FS_MODE_RD);
if(res == FS_RES_OK) { if(res == FS_RES_OK) {
cord_t row; lv_img_raw_header_t header;
color_t buf[LV_HOR_RES]; uint32_t br;
uint32_t br; res = fs_read(&file, &header, sizeof(lv_img_raw_header_t), &br);
area_t act_area;
/*If the width is greater then map width then it is upscaled */
area_t mask_sub; bool upscale = false;
bool union_ok; if(area_get_width(cords_p) > header.w) upscale = true;
union_ok = area_union(&mask_sub, mask_p, cords_p);
if(union_ok == false) { cord_t row;
fs_close(&file); area_t act_area;
return;
}
lv_img_raw_header_t header; area_t mask_sub;
res = fs_read(&file, &header, sizeof(lv_img_raw_header_t), &br); bool union_ok;
union_ok = area_union(&mask_sub, mask_p, cords_p);
uint32_t start_offset = sizeof(lv_img_raw_header_t); if(union_ok == false) {
start_offset += area_get_width(cords_p) * fs_close(&file);
(mask_sub.y1 - cords_p->y1) * sizeof(color_t); /*First row*/ return;
start_offset += (mask_sub.x1 - cords_p->x1) * sizeof(color_t); /*First col*/ }
fs_seek(&file, start_offset);
uint8_t ds_shift = 0;
uint32_t useful_data = area_get_width(&mask_sub) * sizeof(color_t); uint8_t ds_num = 1;
uint32_t next_row = area_get_width(cords_p) * sizeof(color_t) - useful_data; /*Set some values if upscale enabled*/
if(upscale != false) {
area_cpy(&act_area, &mask_sub); ds_shift = 1;
ds_num = 2;
act_area.y2 = act_area.y1; }
uint32_t act_pos;
uint32_t start_offset = sizeof(lv_img_raw_header_t);
for(row = mask_sub.y1; row <= mask_sub.y2; row ++) { start_offset += (area_get_width(cords_p) >> ds_shift) *
res = fs_read(&file, buf, useful_data, &br); ((mask_sub.y1 - cords_p->y1) >> ds_shift) * sizeof(color_t); /*First row*/
map_fp(&act_area, &mask_sub, buf, opa, header.transp, start_offset += ((mask_sub.x1 - cords_p->x1) >> ds_shift) * sizeof(color_t); /*First col*/
imgs_p->objs.color, imgs_p->recolor_opa); fs_seek(&file, start_offset);
fs_tell(&file, &act_pos);
fs_seek(&file, act_pos + next_row); uint32_t useful_data = (area_get_width(&mask_sub) >> ds_shift) * sizeof(color_t);
act_area.y1 ++; uint32_t next_row = (area_get_width(cords_p) >> ds_shift) * sizeof(color_t) - useful_data;
act_area.y2 ++;
}
} /*Round the coordinates with upscale*/
fs_close(&file); if(upscale != false) {
if((mask_sub.x1 & 0x1) != 0) mask_sub.x1 -= 1; /*Can be only even*/
if((mask_sub.x2 & 0x1) == 0) mask_sub.x2 -= 1; /*Can be only odd*/
}
area_cpy(&act_area, &mask_sub);
/* Round down the start coordinate, because the upscaled images
* can start only LV_DOWNSCALE 'y' coordinates */
act_area.y1 &= ~(cord_t)(ds_num - 1) ;
act_area.y2 = act_area.y1 + ds_num - 1;
uint32_t act_pos;
color_t buf[LV_HOR_RES];
for(row = mask_sub.y1; row <= mask_sub.y2; row += ds_num) {
res = fs_read(&file, buf, useful_data, &br);
map_fp(&act_area, &mask_sub, buf, opa, header.transp, upscale,
imgs_p->objs.color, imgs_p->recolor_opa);
fs_tell(&file, &act_pos);
fs_seek(&file, act_pos + next_row);
act_area.y1 += ds_num;
act_area.y2 += ds_num;
}
if(res != FS_RES_OK) { }
lv_draw_rect(cords_p, mask_p, &lv_img_no_pic_rects, opa); fs_close(&file);
lv_draw_label(cords_p, mask_p,&lv_img_no_pic_labels, opa, fn);
} if(res != FS_RES_OK) {
} lv_draw_rect(cords_p, mask_p, &lv_img_no_pic_rects, opa);
lv_draw_label(cords_p, mask_p,&lv_img_no_pic_labels, opa, fn);
}
}
} }
#endif /*USE_LV_IMG != 0 && USE_FSINT != 0 && USE_UFS != 0*/ #endif /*USE_LV_IMG != 0 && USE_FSINT != 0 && USE_UFS != 0*/
#if USE_LV_LINE != 0 #if USE_LV_LINE != 0
......
...@@ -108,9 +108,12 @@ void lv_rletter(const point_t * pos_p, const area_t * mask_p, ...@@ -108,9 +108,12 @@ void lv_rletter(const point_t * pos_p, const area_t * mask_p,
* @param map_p pointer to a color_t array * @param map_p pointer to a color_t array
* @param opa opacity of the map (ignored, only for compatibility with lv_vmap) * @param opa opacity of the map (ignored, only for compatibility with lv_vmap)
* @param transp true: enable transparency of LV_IMG_COLOR_TRANSP color pixels * @param transp true: enable transparency of LV_IMG_COLOR_TRANSP color pixels
* @param upscale true: upscale to double size (not supported)
* @param recolor mix the pixels with this color (not supported)
* @param recolor_opa the intense of recoloring (not supported)
*/ */
void lv_rmap(const area_t * cords_p, const area_t * mask_p, void lv_rmap(const area_t * cords_p, const area_t * mask_p,
const color_t * map_p, opa_t opa, bool transp, const color_t * map_p, opa_t opa, bool transp, bool upscale,
color_t recolor, opa_t recolor_opa) color_t recolor, opa_t recolor_opa)
{ {
area_t masked_a; area_t masked_a;
......
...@@ -30,7 +30,7 @@ void lv_rletter(const point_t * pos_p, const area_t * mask_p, ...@@ -30,7 +30,7 @@ void lv_rletter(const point_t * pos_p, const area_t * mask_p,
const font_t * font_p, uint8_t letter, const font_t * font_p, uint8_t letter,
color_t color, opa_t opa); color_t color, opa_t opa);
void lv_rmap(const area_t * cords_p, const area_t * mask_p, void lv_rmap(const area_t * cords_p, const area_t * mask_p,
const color_t * map_p, opa_t opa, bool transp, const color_t * map_p, opa_t opa, bool transp, bool upscale,
color_t recolor, opa_t recolor_opa); color_t recolor, opa_t recolor_opa);
/********************** /**********************
* MACROS * MACROS
......
...@@ -36,7 +36,7 @@ void lv_vletter(const point_t * pos_p, const area_t * mask_p, ...@@ -36,7 +36,7 @@ void lv_vletter(const point_t * pos_p, const area_t * mask_p,
color_t color, opa_t opa); color_t color, opa_t opa);
void lv_vmap(const area_t * cords_p, const area_t * mask_p, void lv_vmap(const area_t * cords_p, const area_t * mask_p,
const color_t * map_p, opa_t opa, bool transp, const color_t * map_p, opa_t opa, bool transp, bool upscale,
color_t recolor, opa_t recolor_opa); color_t recolor, opa_t recolor_opa);
......
...@@ -28,8 +28,8 @@ ...@@ -28,8 +28,8 @@
#error "LV: LV_DOWNSCALE can be only 1 or 2" #error "LV: LV_DOWNSCALE can be only 1 or 2"
#endif #endif
#if LV_VDB_SIZE == 0 && LV_DOWNSCALE != 1 #if LV_VDB_SIZE == 0 && LV_ANTIALIAS != 0
#error "LV: If LV_VDB_SIZE == 0 then LV_DOWNSCALE must be 1, LV_UPSCALE_MAP 0, LV_UPSCALE_STYLE 0" #error "LV: If LV_VDB_SIZE == 0 the antialaissing is not enabled"
#endif #endif
/*New defines*/ /*New defines*/
......
...@@ -65,6 +65,7 @@ lv_obj_t * lv_img_create(lv_obj_t * par, lv_obj_t * copy) ...@@ -65,6 +65,7 @@ lv_obj_t * lv_img_create(lv_obj_t * par, lv_obj_t * copy)
ext->w = lv_obj_get_width(new_img); ext->w = lv_obj_get_width(new_img);
ext->h = lv_obj_get_height(new_img); ext->h = lv_obj_get_height(new_img);
ext->transp = 0; ext->transp = 0;
ext->upscale = 0;
/*Init the new object*/ /*Init the new object*/
lv_obj_set_signal_f(new_img, lv_img_signal); lv_obj_set_signal_f(new_img, lv_img_signal);
...@@ -195,8 +196,8 @@ void lv_img_set_file(lv_obj_t * img, const char * fn) ...@@ -195,8 +196,8 @@ void lv_img_set_file(lv_obj_t * img, const char * fn)
res = fs_read(&file, &header, sizeof(header), &rn); res = fs_read(&file, &header, sizeof(header), &rn);
} }
/*Create a dummy header on fs error*/
if(res != FS_RES_OK || rn != sizeof(header)) { if(res != FS_RES_OK || rn != sizeof(header)) {
/*Create a dummy header*/
header.w = lv_obj_get_width(img); header.w = lv_obj_get_width(img);
header.h = lv_obj_get_height(img); header.h = lv_obj_get_height(img);
header.transp = 0; header.transp = 0;
...@@ -208,6 +209,11 @@ void lv_img_set_file(lv_obj_t * img, const char * fn) ...@@ -208,6 +209,11 @@ void lv_img_set_file(lv_obj_t * img, const char * fn)
ext->h = header.h; ext->h = header.h;
ext->transp = header.transp; ext->transp = header.transp;
if(ext->upscale != 0) {
ext->w *= 2;
ext->h *= 2;
}
if(fn != NULL) { if(fn != NULL) {
ext->fn = dm_realloc(ext->fn, strlen(fn) + 1); ext->fn = dm_realloc(ext->fn, strlen(fn) + 1);
strcpy(ext->fn, fn); strcpy(ext->fn, fn);
...@@ -226,13 +232,26 @@ void lv_img_set_file(lv_obj_t * img, const char * fn) ...@@ -226,13 +232,26 @@ void lv_img_set_file(lv_obj_t * img, const char * fn)
* Enable the auto size feature. * Enable the auto size feature.
* If enabled the object size will be same as the picture size. * If enabled the object size will be same as the picture size.
* @param img pointer to an image * @param img pointer to an image
* @param autotosize true: auto size enable, false: auto size disable * @param en true: auto size enable, false: auto size disable
*/
void lv_img_set_auto_size(lv_obj_t * img, bool en)
{
lv_img_ext_t * ext = lv_obj_get_ext(img);
ext->auto_size = (en == false ? 0 : 1);
}
/**
* Enable the upscaling with LV_DOWNSCALE.
* If enabled the object size will be same as the picture size.
* @param img pointer to an image
* @param en true: upscale enable, false: upscale disable
*/ */
void lv_img_set_auto_size(lv_obj_t * img, bool autotosize) void lv_img_set_upscale(lv_obj_t * img, bool en)
{ {
lv_img_ext_t * ext = lv_obj_get_ext(img); lv_img_ext_t * ext = lv_obj_get_ext(img);
ext->auto_size = (autotosize == false ? 0 : 1); ext->upscale = (en == false ? 0 : 1);
} }
/*===================== /*=====================
...@@ -251,6 +270,17 @@ bool lv_img_get_auto_size(lv_obj_t * img) ...@@ -251,6 +270,17 @@ bool lv_img_get_auto_size(lv_obj_t * img)
return ext->auto_size == 0 ? false : true; return ext->auto_size == 0 ? false : true;
} }
/**
* Get the upscale enable attribute
* @param img pointer to an image
* @return true: upscale is enabled, false: upscale is disabled
*/
bool lv_img_get_upscale(lv_obj_t * img)
{
lv_img_ext_t * ext = lv_obj_get_ext(img);
return ext->upscale == 0 ? false : true;
}
/********************** /**********************
* STATIC FUNCTIONS * STATIC FUNCTIONS
**********************/ **********************/
......
...@@ -46,9 +46,10 @@ typedef struct ...@@ -46,9 +46,10 @@ typedef struct
/*No ext. because inherited from the base object*/ /*Ext. of ancestor*/ /*No ext. because inherited from the base object*/ /*Ext. of ancestor*/
/*New data for this type */ /*New data for this type */
char* fn; /*Image file name. E.g. "U:/my_image"*/ char* fn; /*Image file name. E.g. "U:/my_image"*/
cord_t w; /*Width of the image (if LV_UPSCALE_MAP != 0 then multiplied by LV_DOWNSCALE)*/ cord_t w; /*Width of the image (doubled when upscaled)*/
cord_t h; /*Height of the image (if LV_UPSCALE_MAP != 0 then multiplied by LV_DOWNSCALE)*/ cord_t h; /*Height of the image (doubled when upscaled)*/
uint8_t auto_size :1; /*1: automatically set the object size to the image size*/ uint8_t auto_size :1; /*1: automatically set the object size to the image size*/
uint8_t upscale :1; /*1: upscale to double size*/
uint8_t transp :1; /*Transp. bit in the images header (library handles this)*/ uint8_t transp :1; /*Transp. bit in the images header (library handles this)*/
}lv_img_ext_t; }lv_img_ext_t;
...@@ -71,10 +72,11 @@ lv_obj_t * lv_img_create(lv_obj_t * par, lv_obj_t * copy); ...@@ -71,10 +72,11 @@ lv_obj_t * lv_img_create(lv_obj_t * par, lv_obj_t * copy);
bool lv_img_signal(lv_obj_t * img, lv_signal_t sign, void * param); bool lv_img_signal(lv_obj_t * img, lv_signal_t sign, void * param);
void lv_img_set_file(lv_obj_t * img, const char * fn); void lv_img_set_file(lv_obj_t * img, const char * fn);
fs_res_t lv_img_create_file(const char * fn, const color_int_t * data_p); fs_res_t lv_img_create_file(const char * fn, const color_int_t * data_p);
void lv_img_set_auto_size(lv_obj_t * img, bool autotosize); void lv_img_set_auto_size(lv_obj_t * img, bool en);
void lv_img_set_upscale(lv_obj_t * img, bool en);
bool lv_img_get_auto_size(lv_obj_t * img); bool lv_img_get_auto_size(lv_obj_t * img);
bool lv_img_get_upscale(lv_obj_t * img);
lv_imgs_t * lv_imgs_get(lv_imgs_builtin_t style, lv_imgs_t * copy); lv_imgs_t * lv_imgs_get(lv_imgs_builtin_t style, lv_imgs_t * copy);
/********************** /**********************
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment