image upscale added as lv_img attribute
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
@@ -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,
|
||||
const lv_imgs_t * imgs_p, opa_t opa, const char * fn)
|
||||
{
|
||||
if(fn == NULL) {
|
||||
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");
|
||||
} else {
|
||||
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];
|
||||
uint32_t br;
|
||||
area_t act_area;
|
||||
if(fn == NULL) {
|
||||
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");
|
||||
} else {
|
||||
fs_file_t file;
|
||||
fs_res_t res = fs_open(&file, fn, FS_MODE_RD);
|
||||
if(res == FS_RES_OK) {
|
||||
lv_img_raw_header_t header;
|
||||
uint32_t br;
|
||||
res = fs_read(&file, &header, sizeof(lv_img_raw_header_t), &br);
|
||||
|
||||
area_t mask_sub;
|
||||
bool union_ok;
|
||||
union_ok = area_union(&mask_sub, mask_p, cords_p);
|
||||
if(union_ok == false) {
|
||||
fs_close(&file);
|
||||
return;
|
||||
}
|
||||
lv_img_raw_header_t header;
|
||||
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;
|
||||
|
||||
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*/
|
||||
fs_seek(&file, start_offset);
|
||||
cord_t row;
|
||||
area_t act_area;
|
||||
|
||||
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;
|
||||
|
||||
area_cpy(&act_area, &mask_sub);
|
||||
area_t mask_sub;
|
||||
bool union_ok;
|
||||
union_ok = area_union(&mask_sub, mask_p, cords_p);
|
||||
if(union_ok == false) {
|
||||
fs_close(&file);
|
||||
return;
|
||||
}
|
||||
|
||||
act_area.y2 = act_area.y1;
|
||||
uint32_t act_pos;
|
||||
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;
|
||||
}
|
||||
|
||||
for(row = mask_sub.y1; row <= mask_sub.y2; row ++) {
|
||||
res = fs_read(&file, buf, useful_data, &br);
|
||||
map_fp(&act_area, &mask_sub, buf, opa, header.transp,
|
||||
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 ++;
|
||||
}
|
||||
}
|
||||
fs_close(&file);
|
||||
uint32_t start_offset = sizeof(lv_img_raw_header_t);
|
||||
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);
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
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);
|
||||
|
||||
/* 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;
|
||||
}
|
||||
|
||||
}
|
||||
fs_close(&file);
|
||||
|
||||
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*/
|
||||
|
||||
#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,30 +175,36 @@ 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;
|
||||
bool union_ok;
|
||||
lv_vdb_t * vdb_p = lv_vdb_get();
|
||||
|
||||
|
||||
/*Get the union of map size and mask*/
|
||||
/* The mask is already truncated to the vdb size
|
||||
* in 'lv_refr_area_with_vdb' function */
|
||||
* in 'lv_refr_area_with_vdb' function */
|
||||
union_ok = area_union(&masked_a, cords_p, mask_p);
|
||||
|
||||
|
||||
/*If there are common part of the three area then draw to the vdb*/
|
||||
if(union_ok == false) return;
|
||||
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*/
|
||||
@@ -208,101 +214,126 @@ void lv_vmap(const area_t * cords_p, const area_t * mask_p,
|
||||
masked_a.y2 = masked_a.y2 - vdb_p->vdb_area.y1;
|
||||
|
||||
cord_t vdb_width = area_get_width(&vdb_p->vdb_area);
|
||||
color_t * vdb_buf_tmp = vdb_p->buf;
|
||||
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);
|
||||
|
||||
/*No transparent pixels on the image*/
|
||||
if(transp == false) { /*Simply copy the pixels to the VDB*/
|
||||
cord_t row;
|
||||
|
||||
if(opa == OPA_COVER) { /*no opa */
|
||||
for(row = masked_a.y1; row <= masked_a.y2; row++) {
|
||||
memcpy(&vdb_buf_tmp[masked_a.x1],
|
||||
&map_p[masked_a.x1],
|
||||
area_get_width(&masked_a) * sizeof(color_t));
|
||||
map_p += map_width; /*Next row on the map*/
|
||||
vdb_buf_tmp += vdb_width; /*Next row on the VDB*/
|
||||
}
|
||||
} else {
|
||||
cord_t col;
|
||||
for(row = masked_a.y1; row <= masked_a.y2; row++) {
|
||||
for(col = masked_a.x1; col <= masked_a.x2; col ++) {
|
||||
vdb_buf_tmp[col] = color_mix( map_p[col], vdb_buf_tmp[col], opa);
|
||||
}
|
||||
map_p += map_width; /*Next row on the map*/
|
||||
vdb_buf_tmp += vdb_width; /*Next row on the VDB*/
|
||||
}
|
||||
}
|
||||
|
||||
/*To recolor draw simply a rectangle above the image*/
|
||||
#if LV_VDB_SIZE != 0
|
||||
lv_vfill(cords_p, mask_p, recolor, recolor_opa);
|
||||
#endif
|
||||
|
||||
} else { /*transp == true: Check all pixels */
|
||||
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;
|
||||
|
||||
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 ++) {
|
||||
if(map_p[col].full != transp_color.full) {
|
||||
vdb_buf_tmp[col] = map_p[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;
|
||||
|
||||
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*/
|
||||
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) {
|
||||
vdb_buf_tmp[col] = color_mix( map_p[col], vdb_buf_tmp[col], opa);
|
||||
}
|
||||
}
|
||||
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;
|
||||
|
||||
map_p += map_width; /*Next row on the map*/
|
||||
vdb_buf_tmp += vdb_width; /*Next row on the VDB*/
|
||||
}
|
||||
}
|
||||
} else { /*Recolor needed*/
|
||||
color_t color_tmp;
|
||||
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 ++) {
|
||||
if(map_p[col].full != transp_color.full) {
|
||||
color_tmp = color_mix(recolor, map_p[col], recolor_opa);
|
||||
vdb_buf_tmp[col] = color_tmp;
|
||||
}
|
||||
}
|
||||
if(opa == OPA_COVER) { /*no opa */
|
||||
for(row = masked_a.y1; row <= masked_a.y2; row++) {
|
||||
memcpy(&vdb_buf_tmp[masked_a.x1],
|
||||
&map_p[masked_a.x1],
|
||||
area_get_width(&masked_a) * sizeof(color_t));
|
||||
map_p += map_width; /*Next row on the map*/
|
||||
vdb_buf_tmp += vdb_width; /*Next row on the VDB*/
|
||||
}
|
||||
} else {
|
||||
cord_t col;
|
||||
for(row = masked_a.y1; row <= masked_a.y2; row++) {
|
||||
for(col = masked_a.x1; col <= masked_a.x2; col ++) {
|
||||
vdb_buf_tmp[col] = color_mix( map_p[col], vdb_buf_tmp[col], opa);
|
||||
}
|
||||
map_p += map_width; /*Next row on the map*/
|
||||
vdb_buf_tmp += vdb_width; /*Next row on the VDB*/
|
||||
}
|
||||
}
|
||||
|
||||
map_p += map_width; /*Next row on the map*/
|
||||
vdb_buf_tmp += vdb_width; /*Next row on the VDB*/
|
||||
}
|
||||
} else { /*Image opacity with recolor*/
|
||||
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) {
|
||||
color_tmp = color_mix(recolor, map_p[col], recolor_opa);
|
||||
vdb_buf_tmp[col] = color_mix(color_tmp, vdb_buf_tmp[col], opa);
|
||||
}
|
||||
}
|
||||
/*To recolor draw simply a rectangle above the image*/
|
||||
#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;
|
||||
|
||||
map_p += map_width; /*Next row on the map*/
|
||||
vdb_buf_tmp += vdb_width; /*Next row on the VDB*/
|
||||
}
|
||||
}
|
||||
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 ++) {
|
||||
if(map_p[col].full != transp_color.full) {
|
||||
vdb_buf_tmp[col] = map_p[col];
|
||||
}
|
||||
}
|
||||
|
||||
map_p += map_width; /*Next row on the map*/
|
||||
vdb_buf_tmp += vdb_width; /*Next row on the VDB*/
|
||||
}
|
||||
} 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) {
|
||||
vdb_buf_tmp[col] = color_mix( map_p[col], vdb_buf_tmp[col], opa);
|
||||
}
|
||||
}
|
||||
|
||||
map_p += map_width; /*Next row on the map*/
|
||||
vdb_buf_tmp += vdb_width; /*Next row on the VDB*/
|
||||
}
|
||||
}
|
||||
} else { /*Recolor needed*/
|
||||
color_t color_tmp;
|
||||
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 ++) {
|
||||
if(map_p[col].full != transp_color.full) {
|
||||
color_tmp = color_mix(recolor, map_p[col], recolor_opa);
|
||||
vdb_buf_tmp[col] = color_tmp;
|
||||
}
|
||||
}
|
||||
|
||||
map_p += map_width; /*Next row on the map*/
|
||||
vdb_buf_tmp += vdb_width; /*Next row on the VDB*/
|
||||
}
|
||||
} 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) {
|
||||
color_tmp = color_mix(recolor, map_p[col], recolor_opa);
|
||||
vdb_buf_tmp[col] = color_mix(color_tmp, vdb_buf_tmp[col], opa);
|
||||
}
|
||||
}
|
||||
|
||||
map_p += map_width; /*Next row on the map*/
|
||||
vdb_buf_tmp += vdb_width; /*Next row on the VDB*/
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**********************
|
||||
* 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 autotosize)
|
||||
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 = (autotosize == false ? 0 : 1);
|
||||
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_upscale(lv_obj_t * img, bool en)
|
||||
{
|
||||
lv_img_ext_t * ext = lv_obj_get_ext(img);
|
||||
|
||||
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);
|
||||
|
||||
/**********************
|
||||
|
||||
Reference in New Issue
Block a user