lvgl: Subpix text rendering does not work properly when using compact draw buffers
Perform all steps below and tick them with [x]
- Check the related part of the Documentation
- Update lvgl to the latest version
Describe the bug
Labels render with glitches when subpixel rendering is enabled and your draw buffers do not map 1-to-1 to the display.
Context
Initial report in the LVGL forum
I am using LVGL to drive a display with the SH1122 driver. The display has 256x64 4-bit grayscale pixels. In order to use memory efficiently, I use the set_px_cb()
function in order to set pixels in the buffer.
I am currently using two buffers and I have the full refresh option enabled.
I have tracked the issue down and the problem is in these lines:
The problem is that LVGL is assuming that it can just read colors as they are, directly from the buffers. In my particular setup, this is not the case. The coordinates are not even right: coordinate (2, 0) is at buf[1]
in my case, since I’m storing two 4-bit pixels per byte.
I presume the same issue exists anywhere else where LVGL needs to read data from the draw buffer. I have fixed this issue by adding a get_px_cb()
function to the display driver and using that function in the rendering code instead of having direct reads from the draw buffer.
I don’t know if that’s the best way to fix the issue, but it worked for me.
Basically I made this change:
+ lv_coord_t bg_px_x = next_index_in_draw_buffer % lv_disp_get_hor_res(disp);
+ lv_coord_t bg_px_y = next_index_in_draw_buffer / lv_disp_get_hor_res(disp);
+ lv_color_t bg_color = disp->driver->get_px_cb(draw_buf->buf_act, bg_px_x, bg_px_y);
+ uint8_t bg_rgb[3] = {bg_color.ch.red, bg_color.ch.green, bg_color.ch.blue};
- uint8_t bg_rgb[3] = {disp_buf_buf_tmp->ch.red, disp_buf_buf_tmp->ch.green, disp_buf_buf_tmp->ch.blue};
I changed the variable disp_buf_buf_tmp
to next_index_in_draw_buffer
and instead of it being a pointer to a pixel, I made it an index in the draw buffer.
I hope this helps, and I hope it can be fixed upstream soon.
Expected behavior
Labels with subpixel rendering should look smooth.
Screenshots or video
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Comments: 17 (17 by maintainers)
I’ve added links to the docs here: https://lvgl.io/tools/fontconverter