Toot

Written by ­ on 2024-10-03 at 17:30

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 resvgcrate, 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

[#]rustlang #diy #microelectronics #embedded

=> View attached media

=> More informations about this toot | View the thread | More toots from bemyak@lor.sh

Mentions

Tags

=> View rustlang tag | View diy tag | View microelectronics tag | View embedded tag

Proxy Information
Original URL
gemini://mastogem.picasoft.net/toot/113244678097592250
Status Code
Success (20)
Meta
text/gemini
Capsule Response Time
223.507993 milliseconds
Gemini-to-HTML Time
0.781179 milliseconds

This content has been proxied by September (3851b).