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);
#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 (*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
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 (*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
......@@ -184,11 +184,18 @@ void lv_draw_img(const area_t * cords_p, const area_t * mask_p,
fs_file_t file;
fs_res_t res = fs_open(&file, fn, FS_MODE_RD);
if(res == FS_RES_OK) {
cord_t row;
color_t buf[LV_HOR_RES];
lv_img_raw_header_t header;
uint32_t br;
res = fs_read(&file, &header, sizeof(lv_img_raw_header_t), &br);
/*If the width is greater then map width then it is upscaled */
bool upscale = false;
if(area_get_width(cords_p) > header.w) upscale = true;
cord_t row;
area_t act_area;
area_t mask_sub;
bool union_ok;
union_ok = area_union(&mask_sub, mask_p, cords_p);
......@@ -196,32 +203,49 @@ void lv_draw_img(const area_t * cords_p, const area_t * mask_p,
fs_close(&file);
return;
}
lv_img_raw_header_t header;
res = fs_read(&file, &header, sizeof(lv_img_raw_header_t), &br);
uint8_t ds_shift = 0;
uint8_t ds_num = 1;
/*Set some values if upscale enabled*/
if(upscale != false) {
ds_shift = 1;
ds_num = 2;
}
uint32_t start_offset = sizeof(lv_img_raw_header_t);
start_offset += area_get_width(cords_p) *
(mask_sub.y1 - cords_p->y1) * sizeof(color_t); /*First row*/
start_offset += (mask_sub.x1 - cords_p->x1) * sizeof(color_t); /*First col*/
start_offset += (area_get_width(cords_p) >> ds_shift) *
((mask_sub.y1 - cords_p->y1) >> ds_shift) * sizeof(color_t); /*First row*/
start_offset += ((mask_sub.x1 - cords_p->x1) >> ds_shift) * sizeof(color_t); /*First col*/
fs_seek(&file, start_offset);
uint32_t useful_data = area_get_width(&mask_sub) * sizeof(color_t);
uint32_t next_row = area_get_width(cords_p) * sizeof(color_t) - useful_data;
uint32_t useful_data = (area_get_width(&mask_sub) >> ds_shift) * sizeof(color_t);
uint32_t next_row = (area_get_width(cords_p) >> ds_shift) * sizeof(color_t) - useful_data;
/*Round the coordinates with upscale*/
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);
act_area.y2 = act_area.y1;
/* 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;
for(row = mask_sub.y1; row <= mask_sub.y2; row ++) {
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,
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 ++;
act_area.y2 ++;
act_area.y1 += ds_num;
act_area.y2 += ds_num;
}
}
fs_close(&file);
......@@ -232,6 +256,7 @@ void lv_draw_img(const area_t * cords_p, const area_t * mask_p,
}
}
#endif /*USE_LV_IMG != 0 && USE_FSINT != 0 && USE_UFS != 0*/
#if USE_LV_LINE != 0
......
......@@ -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 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 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,
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)
{
area_t masked_a;
......
......@@ -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,
color_t color, opa_t opa);
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);
/**********************
* MACROS
......
......@@ -175,9 +175,12 @@ void lv_vletter(const point_t * pos_p, const area_t * mask_p,
* @param map_p pointer to a color_t array
* @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 upscale true: upscale to double size
* @param recolor mix the pixels with this color
* @param recolor_opa the intense of recoloring
*/
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)
{
area_t masked_a;
......@@ -192,13 +195,16 @@ void lv_vmap(const area_t * cords_p, const area_t * mask_p,
/*If there are common part of the three area then draw to the vdb*/
if(union_ok == false) return;
uint8_t ds_shift = 0;
if(upscale != false) ds_shift = 1;
/*If the map starts OUT of the masked area then calc. the first pixel*/
cord_t map_width = area_get_width(cords_p);
cord_t map_width = area_get_width(cords_p) >> ds_shift;
if(cords_p->y1 < masked_a.y1) {
map_p += (uint32_t) map_width * (masked_a.y1 - cords_p->y1);
map_p += (uint32_t) map_width * ((masked_a.y1 - cords_p->y1) >> ds_shift);
}
if(cords_p->x1 < masked_a.x1) {
map_p += (masked_a.x1 - cords_p->x1);
map_p += (masked_a.x1 - cords_p->x1) >> ds_shift;
}
/*Stores coordinates relative to the act vdb*/
......@@ -211,9 +217,34 @@ void lv_vmap(const area_t * cords_p, const area_t * mask_p,
color_t * vdb_buf_tmp = vdb_p->buf;
vdb_buf_tmp += (uint32_t) vdb_width * masked_a.y1; /*Move to the first row*/
map_p -= masked_a.x1;
map_p -= (masked_a.x1 >> ds_shift);
if(upscale != false) {
cord_t row;
cord_t col;
color_t transp_color = LV_COLOR_TRANSP;
color_t color_tmp;
color_t prev_color = COLOR_BLACK;
cord_t map_col;
color_tmp = color_mix(recolor, prev_color, recolor_opa);
for(row = masked_a.y1; row <= masked_a.y2; row++) {
for(col = masked_a.x1; col <= masked_a.x2; col ++) {
map_col = col >> 1;
/*No transparent pixels on the image*/
if(map_p[map_col].full != prev_color.full) {
prev_color.full = map_p[map_col].full;
color_tmp = color_mix(recolor, prev_color, recolor_opa);
}
if(transp == false || map_p[map_col].full != transp_color.full) {
vdb_buf_tmp[col] = color_mix( color_tmp, vdb_buf_tmp[col], opa);
}
}
if((row & 0x1) != 0) map_p += map_width; /*Next row on the map*/
vdb_buf_tmp += vdb_width ; /*Next row on the VDB*/
}
}
else {
if(transp == false) { /*Simply copy the pixels to the VDB*/
cord_t row;
......@@ -240,14 +271,12 @@ void lv_vmap(const area_t * cords_p, const area_t * mask_p,
#if LV_VDB_SIZE != 0
lv_vfill(cords_p, mask_p, recolor, recolor_opa);
#endif
} else { /*transp == true: Check all pixels */
cord_t row;
cord_t col;
color_t transp_color = LV_COLOR_TRANSP;
if(recolor_opa == OPA_TRANSP)/*No recolor*/
{
if(recolor_opa == OPA_TRANSP) {/*No recolor*/
if(opa == OPA_COVER) { /*no opa */
for(row = masked_a.y1; row <= masked_a.y2; row++) {
for(col = masked_a.x1; col <= masked_a.x2; col ++) {
......@@ -259,7 +288,7 @@ void lv_vmap(const area_t * cords_p, const area_t * mask_p,
map_p += map_width; /*Next row on the map*/
vdb_buf_tmp += vdb_width; /*Next row on the VDB*/
}
} else { /*Image opacity ut no recolor*/
} else {
for(row = masked_a.y1; row <= masked_a.y2; row++) {
for(col = masked_a.x1; col <= masked_a.x2; col ++) {
if(map_p[col].full != transp_color.full) {
......@@ -285,7 +314,7 @@ void lv_vmap(const area_t * cords_p, const area_t * mask_p,
map_p += map_width; /*Next row on the map*/
vdb_buf_tmp += vdb_width; /*Next row on the VDB*/
}
} else { /*Image opacity with recolor*/
} else {
for(row = masked_a.y1; row <= masked_a.y2; row++) {
for(col = masked_a.x1; col <= masked_a.x2; col ++) {
if(map_p[col].full != transp_color.full) {
......@@ -300,9 +329,11 @@ void lv_vmap(const area_t * cords_p, const area_t * mask_p,
}
}
}
}
}
/**********************
* STATIC FUNCTIONS
**********************/
......
......@@ -36,7 +36,7 @@ void lv_vletter(const point_t * pos_p, const area_t * mask_p,
color_t color, opa_t opa);
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);
......
......@@ -28,8 +28,8 @@
#error "LV: LV_DOWNSCALE can be only 1 or 2"
#endif
#if LV_VDB_SIZE == 0 && LV_DOWNSCALE != 1
#error "LV: If LV_VDB_SIZE == 0 then LV_DOWNSCALE must be 1, LV_UPSCALE_MAP 0, LV_UPSCALE_STYLE 0"
#if LV_VDB_SIZE == 0 && LV_ANTIALIAS != 0
#error "LV: If LV_VDB_SIZE == 0 the antialaissing is not enabled"
#endif
/*New defines*/
......
......@@ -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->h = lv_obj_get_height(new_img);
ext->transp = 0;
ext->upscale = 0;
/*Init the new object*/
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)
res = fs_read(&file, &header, sizeof(header), &rn);
}
/*Create a dummy header on fs error*/
if(res != FS_RES_OK || rn != sizeof(header)) {
/*Create a dummy header*/
header.w = lv_obj_get_width(img);
header.h = lv_obj_get_height(img);
header.transp = 0;
......@@ -208,6 +209,11 @@ void lv_img_set_file(lv_obj_t * img, const char * fn)
ext->h = header.h;
ext->transp = header.transp;
if(ext->upscale != 0) {
ext->w *= 2;
ext->h *= 2;
}
if(fn != NULL) {
ext->fn = dm_realloc(ext->fn, strlen(fn) + 1);
strcpy(ext->fn, fn);
......@@ -226,13 +232,26 @@ void lv_img_set_file(lv_obj_t * img, const char * fn)
* Enable the auto size feature.
* If enabled the object size will be same as the picture size.
* @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);
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)
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
**********************/
......
......@@ -46,9 +46,10 @@ typedef struct
/*No ext. because inherited from the base object*/ /*Ext. of ancestor*/
/*New data for this type */
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 h; /*Height 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 (doubled when upscaled)*/
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)*/
}lv_img_ext_t;
......@@ -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);
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);
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_upscale(lv_obj_t * img);
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