micropython icon indicating copy to clipboard operation
micropython copied to clipboard

extmod/modframebuf: FrameBuffer text scaling

Open jonathanhogg opened this issue 4 years ago • 11 comments

This adds the ability to scale-up the standard 8x8 font when drawing text. This is useful with tiny OLED screens (such as on the Heltec WiFi Kit 32) where you need to display something important a bit more clearly. This does not provide any new, larger fonts so the text will look increasingly blocky as it is scaled.

I'm not wedded to the additional positional argument here – it was just simplest and matched the way color is provided. I'm happy to go back and switch this to being a keyword optional argument instead.

(Fixes #7384)

jonathanhogg avatar Jul 20 '20 15:07 jonathanhogg

Ugh. qemu-arm port build and tests failing:

CC test_main.c
CC ../../lib/tinytest/tinytest.c
In file included from test_main.c:20:0:
build/genhdr/tests.h: In function 'test_extmod_framebuf1_py_fn':
build/genhdr/tests.h:45181:50: error: trigraph ??' ignored, use -trigraphs to enable [-Werror=trigraphs]
 "bytearray(b'\\x00\\x00\\xff\\xff\\xff\\x00\\x00???')\n"
                                                   
CC build/frozen_content.c
cc1: all warnings being treated as errors
../../py/mkrules.mk:63: recipe for target 'build/test_main.o' failed
make: *** [build/test_main.o] Error 1
make: Leaving directory '/home/travis/build/micropython/micropython/ports/qemu-arm'
The command "make ${MAKEOPTS} -C ports/qemu-arm -f Makefile.test test" exited with 2.

Trigraphs? Seriously? The 1970s are calling and they want to force us to accommodate their crazy keyboards.

Will alter test to not generate output that contains repeated question marks...

jonathanhogg avatar Jul 21 '20 11:07 jonathanhogg

If anyone wants to know what the result of this is. It looks like this:

IMG_8214

This screen is seriously tiny, so doubled-up text allows it to be read from a distance instead of having to squint at it up close.

jonathanhogg avatar Jul 21 '20 11:07 jonathanhogg

Made this patch more flexible by switching to specifying the font size (in pixels) instead of an integer scaling factor. This both allows for drawing text at effective non-integer scales, but also means that a future version could select an alternative built-in font for drawing larger text. Drawing text will be slightly slower with this version due to increased bit twiddling and less scope for short-cutting out of the Y loop.

jonathanhogg avatar Aug 26 '20 12:08 jonathanhogg

Related PR: https://github.com/micropython/micropython/pull/3583 Simple font size scaling for framebuf

mcauser avatar Jul 20 '21 07:07 mcauser

How is this PR coming along? We love the idea of increasing accessibility and usability for small displays. If we're taking votes, I'd vote for a keyword size argument.

As an aside, we've received interest in our forums (thread) at Core Electronics for variable font sizes.

CoreProduction avatar Jun 14 '22 06:06 CoreProduction

At the moment this PR doesn't seem to have generated sufficient interest to get mainline attention.

Since I always build my own MicroPython these days, I just roll this patch into my production branch; so I'm committed to continuing to support it for the foreseeable future.

jonathanhogg avatar Jun 14 '22 06:06 jonathanhogg

We featured this PR in this week's episode of The Factory - our fortnightly engineering catchup.

Watch the video

CoreProduction avatar Jun 17 '22 02:06 CoreProduction

+1 to see this implemented. Great work @jonathanhogg and hopefully @dpgeorge can assist,

graham-mitchell-vcs avatar Jun 23 '22 03:06 graham-mitchell-vcs

Codecov Report

Merging #6263 (993b6b9) into master (91674c4) will increase coverage by 0.11%. Report is 21 commits behind head on master. The diff coverage is 100.00%.

:exclamation: Current head 993b6b9 differs from pull request most recent head 98d5e68. Consider uploading reports for the commit 98d5e68 to get more accurate results

@@            Coverage Diff             @@
##           master    #6263      +/-   ##
==========================================
+ Coverage   98.38%   98.50%   +0.11%     
==========================================
  Files         158      155       -3     
  Lines       20900    20544     -356     
==========================================
- Hits        20563    20236     -327     
+ Misses        337      308      -29     
Files Changed Coverage Δ
extmod/modframebuf.c 100.00% <100.00%> (ø)

... and 75 files with indirect coverage changes

codecov-commenter avatar Aug 03 '22 13:08 codecov-commenter

See also https://github.com/micropython/micropython/pull/8987. It would be good to see some updates to framebuf.

peterhinch avatar Aug 03 '22 16:08 peterhinch

Rebased to 4903e48e340bd9741577f30cacb31605cc70cf20 and fixed for renamed function argument.

jonathanhogg avatar Sep 10 '22 07:09 jonathanhogg

This is a "Good Idea". +1 from me :)

allaboutmikey avatar Oct 24 '22 03:10 allaboutmikey

Code size report:

   bare-arm:    +0 +0.000% 
minimal x86:    +0 +0.000% 
   unix x64:  +112 +0.014% standard
      stm32:   +48 +0.012% PYBV10
     mimxrt:   +48 +0.013% TEENSY40
        rp2:   +48 +0.015% PICO
       samd:   +48 +0.018% ADAFRUIT_ITSYBITSY_M4_EXPRESS

github-actions[bot] avatar Dec 07 '22 12:12 github-actions[bot]

Any news on whether the sizing feature is going to be present in the upcoming micropython version?

flyingzombies avatar Jun 28 '23 21:06 flyingzombies

This is an automated heads-up that we've just merged a Pull Request that removes the STATIC macro from MicroPython's C API.

See https://github.com/micropython/micropython/pull/13763

A search suggests this PR might apply the STATIC macro to some C code. If it does, then next time you rebase the PR (or merge from master) then you should please replace all the STATIC keywords with static.

Although this is an automated message, feel free to @-reply to me directly if you have any questions about this.

projectgus avatar Mar 07 '24 23:03 projectgus