fast font rendering on graphical displays
Posted: Mon Jan 14, 2019 8:58 pm
Hi all,
I would like to refer to two postings on this board, related to efficiently using graphical displays, and in particular, rendering fonts. One of them is quite old, in which @pythoncoder was circulating his idea of storing fonts in the flash viewtopic.php?f=3&t=2667&. He also presented a python implementation, which, however, suffered from the fact that it is interpreted, therefore, relatively slow. I mentioned some weeks ago that this issue can be alleviated in a C module, and set out to implement it. I wanted to retain the elegance of Peter's font description, so the C code is really nothing else than an almost literal translation of the relevant parts of https://github.com/peterhinch/micropyth ... /writer.py This also means that the font generator routine in https://github.com/peterhinch/micropyth ... t_to_py.py should still be applicable.
I have dumped my code onto https://github.com/v923z/ufont-micropython. If someone doesn't want to compile the code, I can upload the binary firmware to dropbox or something similar.
Since one of the typical uses of a microcontroller is to display the results of measurements, the module contains a scalable set of seven-segment fonts for numbers. These can be rendered by calling
and then sending the content of memview to the display. Typical rendering times are 50 us for a 20-pixel digit, plus 800 us for data transfer. (I had 21 MHz clock rate on the SPI bus.) The foreground and background colours are arbitrary, the only restriction is that they should fit into 16 bits.
By calling the render method, arbitrary fonts can also be generated, if one passes the font description to the method as
(get_character_from is essentially get_ch in https://github.com/peterhinch/micropyth ... esans20.py)
Typical rendering times are 200 us for a 20-point font, thus one should be able to display a single character in less than a ms. As far as I remember, Peter mentioned 10 ms rendering times for colour displays.
A complete high-level implementation of the driver, as well as detailed speed test can be found under https://github.com/v923z/micropython-te ... test.ipynb
I would appreciate any comments or recommendations.
Best,
Zoltán
I would like to refer to two postings on this board, related to efficiently using graphical displays, and in particular, rendering fonts. One of them is quite old, in which @pythoncoder was circulating his idea of storing fonts in the flash viewtopic.php?f=3&t=2667&. He also presented a python implementation, which, however, suffered from the fact that it is interpreted, therefore, relatively slow. I mentioned some weeks ago that this issue can be alleviated in a C module, and set out to implement it. I wanted to retain the elegance of Peter's font description, so the C code is really nothing else than an almost literal translation of the relevant parts of https://github.com/peterhinch/micropyth ... /writer.py This also means that the font generator routine in https://github.com/peterhinch/micropyth ... t_to_py.py should still be applicable.
I have dumped my code onto https://github.com/v923z/ufont-micropython. If someone doesn't want to compile the code, I can upload the binary firmware to dropbox or something similar.
Since one of the typical uses of a microcontroller is to display the results of measurements, the module contains a scalable set of seven-segment fonts for numbers. These can be rendered by calling
Code: Select all
from ufont import seven_segment
buffer = bytearray(1000)
memview = memoryview(buffer)
foreground = bytearray([200, 200])
background = bytearray([0, 0])
size, weight = 20, 3
seven_segment(memview, '1', size, weight, foreground, background)
By calling the render method, arbitrary fonts can also be generated, if one passes the font description to the method as
Code: Select all
from ufont import render
buffer = bytearray(1000)
memview = memoryview(buffer)
pattern = get_character_from(character, font_descriptor)
height = 20
foreground = bytearray([200, 200])
background = bytearray([0, 0])
render(memview, pattern, height, foreground, background)
Typical rendering times are 200 us for a 20-point font, thus one should be able to display a single character in less than a ms. As far as I remember, Peter mentioned 10 ms rendering times for colour displays.
A complete high-level implementation of the driver, as well as detailed speed test can be found under https://github.com/v923z/micropython-te ... test.ipynb
I would appreciate any comments or recommendations.
Best,
Zoltán