fix(font): fix stride calculation of fonts (#8887)

This commit is contained in:
Gabor Kiss-Vamosi
2025-09-18 12:25:55 +02:00
committed by GitHub
parent 26079f11f7
commit 16f6693ca1
3 changed files with 15 additions and 5 deletions
+5
View File
@@ -170,6 +170,11 @@ static void LV_ATTRIBUTE_FAST_MEM draw_letter_cb(lv_draw_task_t * t, lv_draw_gly
}
else {
glyph_draw_dsc->glyph_data = lv_font_get_glyph_bitmap(glyph_draw_dsc->g, glyph_draw_dsc->_draw_buf);
if(glyph_draw_dsc->glyph_data == NULL) {
LV_LOG_WARN("Couldn't get the bitmap of a glyph");
break;
}
mask_area.x2 = mask_area.x1 + lv_draw_buf_width_to_stride(lv_area_get_width(&mask_area), LV_COLOR_FORMAT_A8) - 1;
lv_draw_sw_blend_dsc_t blend_dsc;
lv_memzero(&blend_dsc, sizeof(blend_dsc));
+1 -1
View File
@@ -36,7 +36,7 @@ extern "C" {
typedef enum {
LV_FONT_GLYPH_FORMAT_NONE = 0, /**< Maybe not visible*/
/**< Legacy simple formats with no byte padding at end of the lines*/
/**< Legacy simple formats*/
LV_FONT_GLYPH_FORMAT_A1 = 0x01, /**< 1 bit per pixel*/
LV_FONT_GLYPH_FORMAT_A2 = 0x02, /**< 2 bit per pixel*/
LV_FONT_GLYPH_FORMAT_A3 = 0x03, /**< 3 bit per pixel*/
+9 -4
View File
@@ -103,7 +103,8 @@ const void * lv_font_get_bitmap_fmt_txt(lv_font_glyph_dsc_t * g_dsc, lv_draw_buf
int32_t gsize = (int32_t) gdsc->box_w * gdsc->box_h;
if(gsize == 0) return NULL;
uint16_t stride_in = g_dsc->stride;
uint32_t stride_in = g_dsc->stride;
if(fdsc->bitmap_format == LV_FONT_FMT_TXT_PLAIN) {
const uint8_t * bitmap_in = &fdsc->glyph_bitmap[gdsc->bitmap_index];
@@ -139,7 +140,7 @@ const void * lv_font_get_bitmap_fmt_txt(lv_font_glyph_dsc_t * g_dsc, lv_draw_buf
}
else if(fdsc->bpp == 2) {
for(y = 0; y < gdsc->box_h; y ++) {
uint16_t line_rem = stride_in != 0 ? stride_in : gdsc->box_w;
uint32_t line_rem = stride_in != 0 ? stride_in : gdsc->box_w;
for(x = 0; x < gdsc->box_w; x++, i++) {
i = i & 0x3;
if(i == 0) bitmap_out_tmp[x] = opa2_table[(*bitmap_in) >> 6];
@@ -257,9 +258,13 @@ bool lv_font_get_glyph_dsc_fmt_txt(const lv_font_t * font, lv_font_glyph_dsc_t *
if(fdsc->stride == 0) dsc_out->stride = 0;
else {
/*e.g. font_dsc stride == 4 means align to 4 byte boundary.
/*E.g. w = 5, bpp = 2, means 2 bytes/line*/
uint32_t bit_count = dsc_out->box_w * fdsc->bpp;
uint32_t width_in_bytes = (bit_count + 7) >> 3; /*No division round up*/
/*E.g. font_dsc stride == 4 means align to 4 byte boundary.
*In glyph_dsc store the actual line length in bytes*/
dsc_out->stride = LV_ROUND_UP(dsc_out->box_w, fdsc->stride);
dsc_out->stride = LV_ROUND_UP(width_in_bytes, fdsc->stride);
}
dsc_out->format = (uint8_t)fdsc->bpp;