I'm working on an "info-station" project: an e-ink display attached to a microcontroller (ESP32-C3) showing weather and local transport info. One of the challenges is to translate "smart symbol" code (e.g., 24) returned from a weather provider API into an image.
I found a repo with all the images in SVG format, and spent some time setting up building scripts in Rust to create an automated conversion pipeline.
Rendering an SVG into raster turns out to be surprisingly difficult. Luckily, there's the `resvg`crate, which handles it nicely. A quote from its README is worth mentioning:
> SVG is a very complicated format with a large specification (SVG 1.1 is almost 900 pages). You basically need a web browser to handle all of it. But the truth is that even browsers fail at this.
Then, an e-ink screen only supports black and white colors, no shades of gray. To emulate "grayish" color Floyd-Steinberg dithering can be applied. Luckily, the `image` create ships with the implementation, so the whole pipeline is tiny in terms of LoC written by me. Thank you, Rust community <3
On the screenshot:
0: original SVG image
1: SVG rendered into 40×40 raster image
2: Alpha channel replaced with white
3: BMP conversion (useless)
4: Luma8 conversion
5: Dithering