Skip to content

extmod/modframebuf: FrameBuffer text scaling #6263

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

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.

@jonathanhogg jonathanhogg force-pushed the framebuf_text_scaling branch 2 times, most recently from 9922ca1 to 8c976c6 Compare June 11, 2021 11:43
@jonathanhogg jonathanhogg force-pushed the framebuf_text_scaling branch from 8c976c6 to 6274b2a Compare July 1, 2021 10:35
@jonathanhogg jonathanhogg force-pushed the framebuf_text_scaling branch from 6274b2a to 92914ff Compare July 8, 2021 17:56
@mcauser
Copy link
Contributor

mcauser commented Jul 20, 2021

Related PR: #3583 Simple font size scaling for framebuf

@jonathanhogg jonathanhogg force-pushed the framebuf_text_scaling branch from 8d1743e to 77a455f Compare October 18, 2021 12:14
@dpgeorge dpgeorge added the extmod Relates to extmod/ directory in source label Nov 30, 2021
@jonathanhogg jonathanhogg force-pushed the framebuf_text_scaling branch from 77a455f to 3e84862 Compare December 2, 2021 11:59
@jonathanhogg jonathanhogg force-pushed the framebuf_text_scaling branch from dccd690 to 7bcd5fd Compare January 13, 2022 13:26
@jonathanhogg jonathanhogg force-pushed the framebuf_text_scaling branch from 7bcd5fd to 459455c Compare January 21, 2022 12:46
@jonathanhogg jonathanhogg force-pushed the framebuf_text_scaling branch from 4499d80 to ed996ea Compare May 18, 2022 13:07
@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

@jonathanhogg jonathanhogg force-pushed the framebuf_text_scaling branch from ed996ea to 1282929 Compare June 17, 2022 07:00
@graham-mitchell-vcs
Copy link

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

@jonathanhogg jonathanhogg force-pushed the framebuf_text_scaling branch from 1282929 to 41ab1fc Compare August 3, 2022 13:26
@codecov-commenter
Copy link

codecov-commenter commented Aug 3, 2022

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 98.57%. Comparing base (f212bbe) to head (f8d2ace).
Report is 5 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #6263   +/-   ##
=======================================
  Coverage   98.57%   98.57%           
=======================================
  Files         164      164           
  Lines       21345    21349    +4     
=======================================
+ Hits        21040    21044    +4     
  Misses        305      305           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@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 :)

@jonathanhogg jonathanhogg force-pushed the framebuf_text_scaling branch from dfa84e3 to e12f089 Compare December 7, 2022 12:13
@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:  +120 +0.014% standard
      stm32:   +64 +0.016% PYBV10
     mimxrt:   +64 +0.018% TEENSY40
        rp2:   +64 +0.007% RPI_PICO_W
       samd:   +64 +0.024% ADAFRUIT_ITSYBITSY_M4_EXPRESS
  qemu rv32:   +68 +0.017% VIRT_RV32

@jonathanhogg jonathanhogg force-pushed the framebuf_text_scaling branch from e12f089 to 993b6b9 Compare January 30, 2023 15:56
@jonathanhogg jonathanhogg force-pushed the framebuf_text_scaling branch from 993b6b9 to 2e46ddb Compare May 3, 2023 10:43
@jonathanhogg jonathanhogg force-pushed the framebuf_text_scaling branch from 2e46ddb to 7b4236e Compare June 15, 2023 16:04
@flyingzombies
Copy link

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

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

@jonathanhogg jonathanhogg force-pushed the framebuf_text_scaling branch from 98d5e68 to 5652e42 Compare July 18, 2024 16:37
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.
@jonathanhogg jonathanhogg force-pushed the framebuf_text_scaling branch from 5652e42 to f8d2ace Compare October 29, 2024 14:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
extmod Relates to extmod/ directory in source
Projects
None yet
Development

Successfully merging this pull request may close these issues.

framebuf: Support drawing text at different sizes
10 participants