png2lvgl
Convert PNG images to LVGL C arrays with support for multiple color formats.
Features
- 🎨 Multiple color format support (True Color, Indexed, Alpha)
- 🚀 Fast and efficient Rust implementation
- 📦 Zero runtime dependencies in generated C code
- 🔧 Automatic format detection
- 💾 Safe file handling (no accidental overwrites)
Installation
Cargo (Recommended)
Homebrew (macOS)
# Add the tap
# Install png2lvgl
Pre-built Binaries
Download the latest release for your platform from GitHub Releases.
From Source
Usage
# Basic usage (auto-detects format, defaults to LVGL 9.0)
# Target LVGL 8.x
# Specify output file
# Use 4-bit indexed grayscale (16 colors)
# Generate big-endian RGB565 (for big-endian systems)
# Overwrite existing file
LVGL Version Compatibility
png2lvgl supports both LVGL 8.x and 9.x APIs:
| Flag | LVGL Version | Format Constants |
|---|---|---|
--lvgl-v9 (default) |
LVGL 9.x | LV_COLOR_FORMAT_RGB565, LV_COLOR_FORMAT_I4, LV_COLOR_FORMAT_A8 |
--lvgl-v8 |
LVGL 8.x | LV_IMG_CF_TRUE_COLOR, LV_IMG_CF_INDEXED_4BIT, LV_IMG_CF_ALPHA_8BIT |
Default: LVGL 9.x format constants are used if no flag is specified.
Example:
# For LVGL 9.x projects (default)
# For LVGL 8.x projects
Supported Formats
| Format | Description | Use Case | Status |
|---|---|---|---|
true-color |
RGB565 | Full color images | ✅ |
true-color-alpha |
RGB565 + Alpha | Images with transparency | ✅ |
true-color-chroma |
RGB565 + Chroma key | Transparent color key | ❌ Not implemented |
indexed1/2/4/8 |
Palette (2/4/16/256 colors) | Small images, icons | ✅ |
alpha1/2/4/8 |
Alpha only (1/2/4/8 bit) | Masks, monochrome icons | ✅ |
Endianness
RGB565 formats (true-color and true-color-alpha) are generated in little-endian byte order by default, which matches most embedded systems (ARM Cortex-M, ESP32, etc.).
For big-endian systems (some PowerPC, MIPS, older ARM), use the --big-endian flag:
Note: Indexed and alpha-only formats are not affected by endianness as they don't use RGB565 encoding.
Output Format
Generated C files are compatible with LVGL and include:
- Proper header guards
- Memory alignment attributes
- Color palette (for indexed formats)
- Image descriptor structure
Example output:
const lv_img_dsc_t my_image = ;
Building from Source
License
This project is licensed under the GNU General Public License v3.0 - see the LICENSE file for details.