tchapi / Adafruit-GFX-Font-Customiser

A little utility to customise pixel fonts for the Adafruit GFX library
https://tchapi.github.io/Adafruit-GFX-Font-Customiser/
MIT License
91 stars 47 forks source link

Compress fonts down to 50-70% and speed-up LCD prints ?? #39

Open eltomjan opened 5 months ago

eltomjan commented 5 months ago

What do you think about XOR compression ?

Real font example with graphics in comments (v1, now there is improved v2). https://github.com/eltomjan/ETEhomeTools/blob/master/ArduinoSimulator/Font_big.h PR for original LCD https://github.com/adafruit/Adafruit_ILI9340/pull/19 Here graphical demo showing these blocks inside real font https://eltomjan.github.io/JStoolsSPAdemos/FontPacker/webLog.htm

Log created by a demo C processing text font https://github.com/eltomjan/ETEhomeTools/tree/master/TextFontPackerDemo

I can create PR, but page is quite complex and not sure if there are any "global" changes already ? Also do not know where to add it to UI - options could be checkbox(-es), new buttons, auto import of packed/plain, etc. ?

PC simulation https://github.com/eltomjan/ETEhomeTools/tree/master/ArduinoSimulator

Old C# packer to generate fonts (now updated to improved v2) https://github.com/eltomjan/ETEhomeTools/tree/master/CSharp/GFXpack

Some older generator / list of compression results https://github.com/eltomjan/ETEhomeTools/blob/02c368e44a83ed0c4cb7ae59315b8c681f98fe11/gfxXorPacker.cpp#L332

tchapi commented 5 months ago

Hi @eltomjan and thanks for the issue

I need to get my head around what you propose, which is not easy as I'm not versed into XOR compression. I have limited bandwidth right now.

About the UI: a simple checkbox when exporting would do, if you get motivated to propose a PR?

eltomjan commented 5 months ago

PR is prepared (import with default, but optional UnXor). Now whole font is a bitmap, last byte is size of block, offset in glyphs point to bit (but also substracted by supposed average position to fit in I16 in case). And nice is even tiny fonts are compressed a bit (no increase), but checked only 3 added to test. C# version would need refactor or start again from scratch and should be possibly translated to JS to work inside page too(?) As there is optimisation - array holding sum of (1) bits so that you can just compare 2 sums instead of checking all bits for each block size... And block size is same for whole font (char is indexed by glyphs to bit level and changing block size for each char may not bring big benefit except more complex code).

Also Arduino version is not updated yet (works with previous where each char has own block size and glyph index is replaced by char size, that needs to be summed to get right position).

It is funny - there is smalles font which have 179B bitmap and it is shrinked to 170B also :-) In case there should be probably working a compression in C# and import here.