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 (cf=4, RGB565 at the display's native depth) / TRUE_COLOR_ALPHA (cf=5, 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/
# default: a sibling '<input>_preview/' dir next to the input
lvglimg assets/       # → assets_preview/ (sibling of assets/)
# finds assets/*.bin AND assets/**/<sub>/*.bin; mirrors the subdir layout
# in the output dir (avoids name collisions across folders)
# viewable images in the tree (.jpg/.jpeg/.png/.gif/.bmp/.webp) are copied
# to the output as-is — no decoding, the preview dir holds the full asset set
$ lvglimg --version
lvglimg 0.0.3

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 TRUE_COLOR (cf=4, RGB565 at the display's native depth) and TRUE_COLOR_ALPHA (cf=5, 4 B/px BGRA), the layouts real device asset bins use. Other legacy v8 formats raise a clear error rather than silently producing garbage.

Development

pip install -e ".[dev]"
pytest            # 21 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.3

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.3
File Size Uploaded
lvglimg-0.0.3.tar.gz 17.7 kB Details

Built distribution (wheel)

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

Total release size: 31.8 kB

Release files / lvglimg-0.0.3.tar.gz

Download URL lvglimg-0.0.3.tar.gz
Size 17.7 kB
Tags Source
SHA-256 checksum
How to use checksums
53bf528e37c1cfa7d39000b0d4bac2a4d55fd6fc28e4232db44a69a2ada4dc7b
BLAKE2b-256 checksum
How to use checksums
1582a7b6b6105896c8db668afe1a22a99ef119564117bf37b6361c30564b4fe1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.10.12

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

Download URL lvglimg-0.0.3-py3-none-any.whl
Size 14.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a5c23149ab56b6d56749327dfc92e5301edca4e9bf48cd08a413fe835e68d9c8
BLAKE2b-256 checksum
How to use checksums
0ea29bc7ba88a3e349d7742132c564d44338c5cee285c498e6041545795eafcb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.10.12

Release history Release notifications | RSS feed

0.0.4

2 release files

This release

0.0.3 This release

2 release files

0.0.2

2 release files

0.0.1

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