Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

extmod/modframebuf: FrameBuffer text scaling #6263

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

jonathanhogg
Copy link
Contributor

@jonathanhogg jonathanhogg commented Jul 20, 2020

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
Copy link
Contributor Author

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
Copy link
Contributor Author

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 jonathanhogg changed the title FrameBuffer text scaling extmod/modframebuf: FrameBuffer text scaling Jul 21, 2020
@jonathanhogg
Copy link
Contributor Author

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.

@mcauser
Copy link
Contributor

mcauser commented Jul 20, 2021

Related PR: #3583 Simple font size scaling for framebuf

@CoreProduction
Copy link

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.

@jonathanhogg
Copy link
Contributor Author

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.

@CoreProduction
Copy link

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

Watch the video

@graham-mitchell-vcs
Copy link

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

@codecov-commenter
Copy link

codecov-commenter commented Aug 3, 2022

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%.

❗ 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

@peterhinch
Copy link
Contributor

See also #8987. It would be good to see some updates to framebuf.

@jonathanhogg jonathanhogg force-pushed the framebuf_text_scaling branch 2 times, most recently from 9b56b04 to dfa84e3 Compare September 10, 2022 07:18
@jonathanhogg
Copy link
Contributor Author

Rebased to 4903e48 and fixed for renamed function argument.

@allaboutmikey
Copy link

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

@github-actions
Copy link

github-actions bot commented Dec 7, 2022

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

@flyingzombies
Copy link

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

Add a `size` parameter to the `text()` method. This does a fairly simple
scaling of the built-in 8 pixel font for the moment, but could use
different fonts in the future.
Document new optional size parameter for the text method.
@projectgus
Copy link
Contributor

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 #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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

framebuf: Support drawing text at different sizes
10 participants