Skip to main content

lvglimg

License: Apache 2.0 Python 3.10+ CI PyPI

Decode LVGL .bin image files to PNG — including v8 + v9 headers and NONE / RLE / LZ4 / LZ4_HC compression.

LVGL's own LVGLImage.py is a one-way encoder: it can write compressed bins, but from_bin ignores the flags field and cannot decompress them back. lvglimg fills that gap, producing pixel-accurate PNGs from real device asset bins.

  • Self-contained — depends only on Pillow + lz4. No LVGL source tree, no LVGLImage.py on disk.
  • All v9 color formats — L8, indexed (I1/2/4/8), alpha-only (A1/2/4/8), RGB565, RGB888, ARGB8888, XRGB8888, ARGB8565, RGB565A8.
  • v8 true-color — TRUE_COLOR / TRUE_COLOR_ALPHA (BGRA).
  • CLI + library — use it on the command line or import the decoder.

Install

pip install lvglimg

CLI

# single file → sibling .png
lvglimg image.bin

# explicit output path
lvglimg image.bin out.png

# batch a directory (recursive) → out/<same subdirs>/*.png
lvglimg assets/ out/
# finds assets/*.bin AND assets/**/<sub>/*.bin; mirrors the subdir layout
# in the output dir (avoids name collisions across folders)
$ lvglimg --version
lvglimg 0.0.1

Library

from lvglimg.decoder import decode, decode_file

# from bytes
img = decode(bin_bytes)
img.save("out.png")

# from a file path
img = decode_file("image.bin")

decode() returns a PIL.Image.Image (mode RGBA, RGB, or L depending on the source format), so you can inspect, transform, or re-encode it however you like.

How it works

The LVGL v9 on-disk layout is a 12-byte header followed by a body that may be a compress block:

header: magic(0x19) cf flags w h stride reserved
body  : [method u32][clen u32][raw_len u32][payload]   # iff flags & 0x08

lvglimg reads the flags field to detect compression (the same bit LVGL sets when encoding), decompresses RLE / LZ4 / LZ4_HC, then unpacks pixels to RGBA using the same channel layout and bit_extend upscaling LVGL renders on-device — so output matches the display. v8 files (no magic byte) are dispatched to the 4-byte bitfield header path.

Note — v8 support covers the true-color BGRA layouts (cf=4/5) used by miwear assets. Other legacy v8 formats raise a clear error rather than silently producing garbage.

Development

pip install -e ".[dev]"
pytest            # 14 tests, runs against src/ with no install
ruff check src tests main.py
mypy
./main.py image.bin   # run from source, no install

License

This project is licensed under the Apache License, Version 2.0. See LICENSE or https://www.apache.org/licenses/LICENSE-2.0 for the full text.

Release files for lvglimg 0.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for lvglimg 0.0.1
File Size Uploaded
lvglimg-0.0.1.tar.gz 16.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for lvglimg 0.0.1
File Interpreter ABI Platform
lvglimg-0.0.1-py3-none-any.whl Python 3 none any Details

Total release size: 29.0 kB

Release files / lvglimg-0.0.1.tar.gz

Download URL lvglimg-0.0.1.tar.gz
Size 16.1 kB
Tags Source
SHA-256 checksum
How to use checksums
31ce93b536f57ebecde63bbd1871f4ceb46bc7f9983ebb8d498f6b30442de6ec
BLAKE2b-256 checksum
How to use checksums
52b06d4a12083bc9ef14d9944ce97b63a66cfaff35314224ea0b4b50aa52289d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.11.9

Release files / lvglimg-0.0.1-py3-none-any.whl

Download URL lvglimg-0.0.1-py3-none-any.whl
Size 12.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
5174403b5a9a0638335065a29fa7676b9324b33a3bd1a540585a7991b562ec86
BLAKE2b-256 checksum
How to use checksums
ec5cc5311cef88ecea541e50d0fb39d70af19b14d88e0b62a78128f04f73adc9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.11.9

Release history Release notifications | RSS feed

0.0.4

2 release files

0.0.3

2 release files

0.0.2

2 release files

This release

0.0.1 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page