martinberlin / eink-calendar

A very easy, almost zero-configuration, ESP8266/ESP32 E-ink calendar. Caution: UNMAINTAINED Please use CalEPD / Cale-idf
http://cale.es
MIT License
103 stars 9 forks source link

8/9 Implement miniz zlib compression #1

Closed martinberlin closed 4 years ago

martinberlin commented 4 years ago

On a 640*384 one bit BMP is 30866 bytes. This could be reduced significantly if we implement zlib compression:

Mode: c, Level: 9 Input File: "wired.bmp" Output File: "wired.z" Input file size: 30866 Total input bytes: 30866 Total output bytes: 6852 -> That is about 25% of the original 31Kb size so it should load 5 times faster

First two bytes are: 0178 -> generated with miniz DA78 -> with gzcompress PHP

First try compiling this in ESP8266 returns: In file included from src/main.cpp:12:0: lib/miniz/miniz.c:209:93: error: macro "zalloc" passed 3 arguments, but takes just 1 pComp = (tdefl_compressor )pStream->zalloc(pStream->opaque, 1, sizeof(tdefl_compressor)); ^ lib/miniz/miniz.c:378:89: error: macro "zalloc" passed 3 arguments, but takes just 1 pDecomp = (inflate_state )pStream->zalloc(pStream->opaque, 1, sizeof(inflate_state));

This seems to be solved including miniz.h but I don't think is right, since in ESP32 works including miniz.c

And after that is delivering a: last failed alloc call: 40219EE6(40000) When trying to decompress. Will try first to pass existing code to ESP32 and see if that works ^

martinberlin commented 4 years ago

Branch: https://github.com/martinberlin/eink-calendar/tree/feature/compression

Proof-of-concept serial output with 800*480 px Waveshare eink

uncompress_status: 0 Compressed length: 3995 freeHeap: 154636
displayWidth: 800 height: 480 File size:48146
Image Offset:146
Header size:124
Width:800 Height:480 Bit Depth:1
Planes:1 Format:0
buffidx:800
Read 48032 bytes. Sending BMP pixels to display
Eink isRendered: 1 BENCHMARKS:
Download: 908 ms Decompress: 4 ms Rendering: 10 seconds
martinberlin commented 4 years ago

A friendly reminder that this is working correctly for Waveshare V1 & V2 but failing for smaller displays, need to check why, leaving it open till then

martinberlin commented 4 years ago

This is mostly working. But depending on the display sometime I get -3 or -4 errors (Memory / Data input) No idea why, leaving open to research later

martinberlin commented 4 years ago

Is implemented in feature/compression branch I would like to detect Zlib headers and instance decompression automatically (only ESP32 feature) It can make the experience faster and also make cale.es server lighter as is a smaller transport size (up to 10x smaller)

martinberlin commented 4 years ago

This is implemented in the branch on last comment, but it fails 1 every 10 times or so. Needs more research reopening later