Smooth Big Text For Little Graphics Displays
David Johnson-Davies explains how to efficiently and accurately smooth characters for small displays.
When using very small displays – e.g. the abundant SSD1306 0.96” 128x64 pixel OLEDs – characters are typically defined as 6x8 pixels, with lines being a single pixel wide. Directly scale characters up to 12x16, however, and you have a situation where things are unnecessarily blocky. Even though lines are now two pixels wide, transitions aren’t optimally filled in.
One solution, as David Johnson-Davies notes in his Smooth Big Text with Hints Technoblogy writeup, is to define a custom 12x16 character set. The drawback is that while a 6x8 character definition takes 576 bytes, the equivalent character defined specifically for 12x16 usage requires 2304 bytes. This might not be a big deal for modern computing systems, but when dealing with low processing-power microcontrollers, every bit counts.
His initial solution, first discussed here, was to use a routine to programmatically smooth out corners. This adds two “filler pixels” when blocks of four pixels – in the scaled-up 6x8 pixel-format touch each other only on a corner as shown below.
However, this doesn’t work well for some characters, such as the top corner of 4, where the left bit should really be filled in, but the simple edge-only condition isn’t satisfied. In this case, Johnson-Davies adds hinting functionality to his code, defining up to two extra bits that aren't programmatically generated. This does make the character requirements slightly larger at 672 bytes, but this is still far below the 2304 bytes needed for a full 12x16 character definition.
Code and more info are available in Johnson-Davies' blog post, which could be very useful for optimizing your microcontroller projects. More broadly, this is a great reminder to consider how you might be able to optimize something with a few clever tricks and out-of-the-box thinking!
Engineer, maker of random contraptions, love learning about tech. Write for various publications, including Hackster!