I am trying to reduce the memory usage for storing fonts. Most of my fonts are small pixel fonts, so it should be relatively easy to double the size in all dimensions at runtime, not arbitrary scaling.
Does anyone have ideas on the best way to attempt this?
What MCU/Processor/Board and compiler are you using?
Imxrt1052
What do you want to achieve?
Runtime doubling of font sizes.
What have you tried so far?
Not much, seeing if there are recommendations on where to start.
My hope is that there would be a way to simply multiply all of the dimensions by a scale factor during render, which for a pixelated font should be fine. I am not looking for vector based calculation to give smooth scaling.
Otherwise you could create a new font render engine with an option for pixel size. 1 being default. Then you could render the fonts based on that value. For bonus points you could add antialiasing. Honestly that sounds like a fun project
The more I think about this, the more I like it. If you could balance speed and size, dynamic sizing with antialiasing would be fantastic. You could define a 12 or 14 point font and dynamically size it for substantial savings in memory
3bpp is not supported in v6.0. It will be supported in v6.1 and then the online converter will be updated too. Until that you can use the latest version of the converter offline.
Lvgl now has functions to transform (scale and/or rotate) images. I’ve tried to apply them on glyphs but it gave quite bad quality for letters. I think it’d be reasonable to add a dedicated algorithm which scale 8 bit fonts in 0.5 … 2 range. Above 2 things gets trickier because some pixels will be skipped.
Could you contribute with algorithm like this? If so I’d integrate it to lvgl.
It’s prototype could look like:
My use case may not be typical, but my fonts are pixel fonts, with no antialiasing… so scaling up by whole number factors should always look perfect.
In some cases, scaling down may be possible, but my plan is to have a pixel based font in the smallest possible size to save memory space, and then scale up during runtime to the needed size.
In LittlevGL I’d like to integrate a more general solution but of course locally you can add this improvement. All you need to do is to modify lv_font_get_bitmap_fmt_txt and lv_font_get_glyph_dsc_fmt_txt to returned the upscaled bitmap and coordinates.
By the way, I’ve just come across the Hqx algorithm which designed for 1 bit images. It might be useful.