fix(png): use color rounding like img conv tool (#6626)

This commit is contained in:
Liam 2024-08-29 13:04:15 -04:00 committed by GitHub
parent 7b85f2f623
commit 03e01bdd3e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -28,6 +28,7 @@ static lv_res_t decoder_info(struct _lv_img_decoder_t * decoder, const void * sr
static lv_res_t decoder_open(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);
static void convert_color_depth(uint8_t * img, uint32_t px_cnt);
static inline lv_color_t lv_color_make_rounding(uint8_t r, uint8_t g, uint8_t b);
/**********************
* STATIC VARIABLES
@ -246,7 +247,7 @@ static void convert_color_depth(uint8_t * img, uint32_t px_cnt)
lv_color_t c;
uint32_t 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_rounding(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 + 1] = c.full >> 8;
img[i * 3 + 0] = c.full & 0xFF;
@ -256,7 +257,7 @@ static void convert_color_depth(uint8_t * img, uint32_t px_cnt)
lv_color_t c;
uint32_t 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_rounding(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 + 0] = c.full;
}
@ -272,4 +273,15 @@ static void convert_color_depth(uint8_t * img, uint32_t px_cnt)
#endif
}
static inline lv_color_t lv_color_make_rounding(uint8_t r, uint8_t g, uint8_t b)
{
#if LV_COLOR_DEPTH == 16
if(r <= 251) r += 4;
if(g <= 253) g += 2;
if(b <= 251) b += 4;
#endif
return lv_color_make(r, g, b);
}
#endif /*LV_USE_PNG*/