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

chore(color): Reduce font FLASH storage. #3881

Merged
merged 6 commits into from
Oct 29, 2023

Conversation

philmoz
Copy link
Collaborator

@philmoz philmoz commented Jul 30, 2023

Enabling RLE compression and reducing the font to 3 BPP (from 4 BPP) saves a chunk of FLASH.

For EN it saves 39096 bytes.
For TW it saves 143144 bytes.

I don't think there is any noticeable degradation in quality.

EN - current font:
en curr

EN - 3 BPP font:
en 3bpp

TW - current font:
tw curr

TW - 3 BPP font:
tw 3bpp

@philmoz
Copy link
Collaborator Author

philmoz commented Jul 30, 2023

I tried 2 BPP as well.
While this would save another 106584 bytes for the TW fonts, I think there is a noticeable degrading of the image.

tw 2bpp

@raphaelcoeffic
Copy link
Member

The main downside is that it is slower to draw, but maybe it's not that bad. Possibly this can be enabled only for the bigger fonts?

@philmoz
Copy link
Collaborator Author

philmoz commented Jul 31, 2023

Do you know which has more impact on performance - RLE compression or bit depth?

@raphaelcoeffic
Copy link
Member

Probably bit depth, but I did not try it out.

@philmoz
Copy link
Collaborator Author

philmoz commented Jul 31, 2023

The main downside is that it is slower to draw, but maybe it's not that bad. Possibly this can be enabled only for the bigger fonts?

Unfortunately RLE compression slows down text rendering a lot. Should have tested this, thanks for the heads up.
And RLE compression is required to use 3BPP so that's a bust as well.

Back to the drawing board.

@philmoz philmoz changed the title chore(color): Turn on compression and reduce fonts to 3 BPP to reduce FLASH storage. chore(color): Reduce font FLASH storage. Jul 31, 2023
@philmoz
Copy link
Collaborator Author

philmoz commented Jul 31, 2023

Attempt 2.

STD, BOLD, XS and XXS fonts reverted to original settings.
L, XL and XXL fonts changed to 2 BPP.

The difference is not noticeable to me on the TX16S screen.

Space saving on TX16S:

  • EN - 34448 bytes
  • TW - 132424 bytes

I've also removed a bunch of unused font files.

@philmoz
Copy link
Collaborator Author

philmoz commented Jul 31, 2023

Comparison images from TX16S.

L 4 BPP
24 4bpp

L 2 BPP
24 2bpp

XL 4 BPP
32 4bpp

XL 2 BPP
32 2bpp

XXL 4 BPP
64 4bpp

XXL 2 BPP
64 2bpp

@gagarinlg
Copy link
Member

The larger fonts look a bit rougher at the edges, but I do not think that that is an issue.
The biggest issues are obviously with the asian fonts. When they are still readable, the latin alphabet + language specific charcters should be OK

@philmoz
Copy link
Collaborator Author

philmoz commented Jul 31, 2023

CN comparison images:

L 4BPP
CN L 4BPP

L 2 BPP
CN L 2BPP

XL 4 BPP
CN XL 4BPP

XL 2 BPP
CN XL 2BPP

CN XXL font does not contain language characters.

@gagarinlg
Copy link
Member

CN XXL font does not contain language characters.

Yes, because it would too much flash memory

@philmoz
Copy link
Collaborator Author

philmoz commented Jul 31, 2023

Is the XXL font actually used by anything?
I can't see any usage of it in the code.

@3djc
Copy link
Collaborator

3djc commented Jul 31, 2023

Ins't it accessible to LUA ?

@raphaelcoeffic
Copy link
Member

Ins't it accessible to LUA ?

That's it. I had it removed at first, but then folks started to complain because of the Battery/Timer LUA widget using the font.

@JimB40
Copy link
Collaborator

JimB40 commented Jul 31, 2023

Maybe then XXL should have numbers and special chars only

@philmoz
Copy link
Collaborator Author

philmoz commented Jul 31, 2023

Version 3.

This removes the L, XL and XXL fonts from the firmware and loads them from SD card files instead.

Benefits:

  • All fonts are stored uncompressed. Compressed fonts take more than twice as long to render so this gives a performance boost when using these fonts.
  • L, XL and XXL fonts contain all the same language and special characters as the STD font.
  • FLASH space saving - 93K for EN, 325K for TW.
  • All fonts are 4BPP so no change in rendering quality.

@philmoz
Copy link
Collaborator Author

philmoz commented Aug 1, 2023

Storing fonts on the SD card might open up the possibility of having all languages built into the firmware.

If we move all but a basic STD font out of the firmware there might be room for all the language translation strings.
Users could then select their language and the language specific fonts could be loaded from the SD card.

@pfeerick
Copy link
Member

pfeerick commented Aug 1, 2023

🤣 Damn you! I had literally just written a comment saying that IMO this was looking to be opening the door up to a long-term goal of having all the translations on the SD card - i.e. single language firmware. i.e. yes, keep just one core font in the firmware to guarantee the ability to show text on screen if the SD content is missing for any reason, and then everything else is on the SD. Were you looking over my shoulder or ears burning just then? 🤣 🤣

@philmoz
Copy link
Collaborator Author

philmoz commented Aug 1, 2023

Great minds think alike :)

@gagarinlg
Copy link
Member

This is something Raphael and I were already planning a few months ago. We should start to write down those ideas somewhere.
The idea was to implement something that is able to use gettext files.
For the B&W radios the gettext run could be done at compile time and for the quicker radios at runtime.
If the 429 is quick enough or if we have to wait for 7 series MCU has to be tested.

@pfeerick
Copy link
Member

pfeerick commented Aug 1, 2023

We should start to write down those ideas somewhere.

Indeed... the Projects tab would be an excellent place to start... one of these days🤭

@gagarinlg
Copy link
Member

gagarinlg commented Aug 1, 2023

I should add that this was before @philmoz was as involved as he is now, so there were less people wotking on this kind of changes.

@pfeerick pfeerick self-requested a review September 24, 2023 05:58
@pfeerick pfeerick added this to the 2.10 milestone Oct 3, 2023
@pfeerick pfeerick added enhancement ✨ New feature or request color Related generally to color LCD radios labels Oct 9, 2023
@pfeerick
Copy link
Member

pfeerick commented Oct 9, 2023

This is looking really good on TX16S just for EN (~93k reduction in FLASH usage), let alone a more complex symbol set like CN...

Totals         KB    usage  of ttl      KB free
  Flash:  1483.18   72.42%    2048       564.82 (rebased PR)
  Flash:  1389.87   67.86%    2048       658.13 (main)

with negligible increase in SRAM usage. Will be poking and prodding tomorrow.

@philmoz
Copy link
Collaborator Author

philmoz commented Oct 9, 2023

One thing this might affect is the EM display. As the XL font won't be in FLASH it may fall back to the STD font size.

Have not tested this.

Copy link
Member

@pfeerick pfeerick left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It falls back to STD font size. Generally, this seems to work just fine. Obviously not going to get the larger fonts if the FONTS folder is missing. Yappu Telemetry and iNav Lua widgets and scripts were working just fine with this on TX16S. As far as I'm concerned, the tradeoff of 100kb vs EM screen large print is worth it...

However, I'd like @raphaelcoeffic and/or @gagarinlg's second opinions.

@raphaelcoeffic
Copy link
Member

One thing this might affect is the EM display. As the XL font won't be in FLASH it may fall back to the STD font size.

Would be probably better to test it ;-) You should be able to setup a custom function that triggers EM (basically an empty endless loop that triggers the watchdog).

@pfeerick
Copy link
Member

Would be probably better to test it ;-) You should be able to setup a custom function that triggers EM (basically an empty endless loop that triggers the watchdog).

lol... I did that... that's why I said

It falls back to STD font size.

😛

@pfeerick
Copy link
Member

Damn camera wouldn't focus ...

image

@philmoz
Copy link
Collaborator Author

philmoz commented Oct 20, 2023

Added RU.

Updated FONTS.zip file - contents must be in the FONTS folder on the SD card.

FONTS.zip

@pfeerick
Copy link
Member

pfeerick commented Oct 20, 2023

Barring any voices of dissent, this will be merged tonight. Thank you for the updated fonts folder :)

pfeerick added a commit to EdgeTX/edgetx-sdcard that referenced this pull request Oct 27, 2023
@pfeerick pfeerick added the rn: warning Warning needed in release notes label Oct 29, 2023
@pfeerick
Copy link
Member

Fonts are in the SD card repo now.

@pfeerick pfeerick merged commit 58573d3 into EdgeTX:main Oct 29, 2023
37 checks passed
@HThuren
Copy link
Contributor

HThuren commented Oct 29, 2023

@pfeerick @raphaelcoeffic @philmoz - Any consideration regarding DA ?

@philmoz
Copy link
Collaborator Author

philmoz commented Oct 29, 2023

@pfeerick @raphaelcoeffic @philmoz - Any consideration regarding DA ?

What considerations are you concerned about? Are there any issues?

@HThuren
Copy link
Contributor

HThuren commented Oct 29, 2023

no issues, don't fully understand the compression, maybe same to be done for other languages, like DA.
if no, don't bother.

@philmoz
Copy link
Collaborator Author

philmoz commented Oct 29, 2023

no issues, don't fully understand the compression, maybe same to be done for other languages, like DA. if no, don't bother.

I tried compression of the fonts initially to save space; but it was too slow.
All fonts are now stored uncompressed. The space saving comes from moving the large fonts to the SD card and loading into RAM at runtime.

@philmoz philmoz deleted the reduce-font-storage branch January 24, 2024 22:46
@pfeerick pfeerick removed the rn: warning Warning needed in release notes label Apr 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
color Related generally to color LCD radios enhancement ✨ New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants