Title: lv.image.set_src() silently fails on 8-bit RGBA PNGs (LV_COLOR_DEPTH=16, lodepng) · Issue #140 · MicroPythonOS/MicroPythonOS · GitHub
Open Graph Title: lv.image.set_src() silently fails on 8-bit RGBA PNGs (LV_COLOR_DEPTH=16, lodepng) · Issue #140 · MicroPythonOS/MicroPythonOS
X Title: lv.image.set_src() silently fails on 8-bit RGBA PNGs (LV_COLOR_DEPTH=16, lodepng) · Issue #140 · MicroPythonOS/MicroPythonOS
Description: Summary lv.image.set_src() called with an 8-bit RGBA PNG (PNG color type 6) succeeds without raising and prints no error, but the image widget stays at 0×0 pixels and nothing renders on screen. The same code path works correctly with ind...
Open Graph Description: Summary lv.image.set_src() called with an 8-bit RGBA PNG (PNG color type 6) succeeds without raising and prints no error, but the image widget stays at 0×0 pixels and nothing renders on screen. The...
X Description: Summary lv.image.set_src() called with an 8-bit RGBA PNG (PNG color type 6) succeeds without raising and prints no error, but the image widget stays at 0×0 pixels and nothing renders on screen. The...
Opengraph URL: https://github.com/MicroPythonOS/MicroPythonOS/issues/140
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"lv.image.set_src() silently fails on 8-bit RGBA PNGs (LV_COLOR_DEPTH=16, lodepng)","articleBody":"## Summary\n\n`lv.image.set_src()` called with an 8-bit **RGBA** PNG (PNG color type 6) succeeds without raising and prints no error, but the image widget stays at 0×0 pixels and nothing renders on screen. The same code path works correctly with **indexed-palette** PNGs (color type 3). Hit this developing Lightning Piggy (com.lightningpiggy.displaywallet) on MPOS 0.10.0 — hero / icon / confetti graphics were all silently invisible until I converted them.\n\n## Environment\n\n- MicroPythonOS **0.10.0**\n- Board: Waveshare ESP32-S3 Touch LCD 2 (`waveshare_esp32_s3_touch_lcd_2`)\n- LVGL: bundled lvgl-micropython\n- `lv_conf.h` settings:\n - `LV_COLOR_DEPTH 16` (via `MICROPY_COLOR_DEPTH = 16` → RGB565)\n - `LV_USE_LODEPNG 1`\n - `LV_USE_LIBPNG 0` (commented as `lv_libpng.c:14:10: fatal error: png.h: No such file or directory`)\n\n## Reproduction\n\nMinimal Python in any Activity:\n\n```python\nimg = lv.image(lv.screen_active())\nimg.set_src(\"M:path/to/some_rgba.png\") # 8-bit RGBA, color type 6\nimg.set_size(80, 100)\nimg.center()\n# Result: widget is positioned correctly and not HIDDEN, but renders no pixels.\n# img.get_width() / get_height() return 0 before the explicit set_size, and\n# even after set_size the image content area is blank.\n```\n\nThe exact same code with an indexed-palette PNG renders correctly:\n\n```python\nimg.set_src(\"M:builtin/res/mipmap-mdpi/MicroPythonOS-logo-white-long-w296.png\")\n# (this file is color type 3 — renders fine)\n```\n\n## Reproducer PNGs\n\n| File | `file(1)` reports | Renders? |\n|---|---|---|\n| `M:builtin/res/mipmap-mdpi/MicroPythonOS-logo-white-long-w296.png` | `4-bit colormap, non-interlaced` (color type 3) | ✓ |\n| LP `hero_lightningpiggy.png` (80×100) | `8-bit/color RGBA, non-interlaced` (color type 6) | ✗ |\n| LP `hero_lightningpenguin.png` (78×100) | `8-bit/color RGBA, non-interlaced` (color type 6) | ✗ |\n| Same penguin/piggy after `Image.quantize(method=2)` → color type 3 | `8-bit colormap, non-interlaced` | ✓ |\n\nFiles I had problems with are pure 80×100 RGBA cartoons, ~8 KB. The PNG itself parses fine (valid IHDR, declared dims, valid magic bytes) — both `open(path, 'rb')` from MicroPython AND host-side decoders read them without complaint. It's only `lv.image.set_src()` that produces no output.\n\n## Diagnostics performed\n\n- Verified the FS driver works — `open()` from Python on the device reads the file fine via the `M:` driver path\n- Verified `lv.lodepng_init()` is exposed and callable; calling it from app `onCreate` doesn't change behaviour (suggests it's already inited, or it's not the missing piece)\n- `hero_image.get_width() / get_height()` return 0 after `set_src()` on RGBA PNGs (suggests the decoder isn't producing image header dims). `set_size(80,100)` forces non-zero bounds but the area still draws empty (suggests decoder doesn't produce pixel data either).\n- Painted a solid `bg_color` on the same widget instead — that renders correctly, ruling out z-order / overlay / clip issues\n- Used the MPOS-bundled indexed PNG (the launcher logo) as the src in the LP context — that renders fine, ruling out a path-prefix or filesystem-context issue\n- Converted my RGBA PNGs to indexed-palette via Pillow (`Image.quantize(colors=255, method=2, dither=FLOYDSTEINBERG)`) — those then render correctly on the same device, without code changes\n\n## Expected behaviour\n\n`lv.image.set_src()` with a valid 8-bit RGBA PNG should either render the image (preferred) or raise / print an error indicating the decoder rejected the format. Silent 0×0 is the worst-of-both: code looks like it succeeded.\n\n## Workaround\n\nConvert all 8-bit RGBA PNGs to indexed-palette before shipping. PIL one-liner:\n\n```python\nfrom PIL import Image\nImage.open(\"foo.png\").quantize(colors=255, method=2,\n dither=Image.Dither.FLOYDSTEINBERG).save(\"foo.png\", optimize=True)\n```\n\nLightning Piggy added a `scripts/check_png_format.py` validator that walks `res/` and fails CI on any RGBA PNG, plus a `docs/assets.md` write-up of the constraint. Happy to upstream the validator if useful for other LP-style apps.\n\n## Likely root cause (speculation)\n\nThe combination `LV_COLOR_DEPTH=16` (RGB565 framebuffer) + lodepng + 8-bit RGBA source is a known interaction point in lvgl — the decoder needs to convert RGBA → RGB565 and the alpha-blending path may not be wired up correctly in this build. Indexed-palette PNGs go through a simpler code path (palette lookup with optional `tRNS` transparency) that doesn't hit the same code, which is consistent with what we observe. Probably worth a sanity check that the lvgl-micropython build is enabling the right `LV_DRAW_BUF_*` / colour-conversion flags for RGBA-on-RGB565.","author":{"url":"https://github.com/bitcoin3us","@type":"Person","name":"bitcoin3us"},"datePublished":"2026-05-20T15:34:20.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":5},"url":"https://github.com/140/MicroPythonOS/issues/140"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:4eb21443-1c1a-d3f6-06d8-6e09ff10e743 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | A42A:53234:41631D0:5C6DBFA:6A4FB44D |
| html-safe-nonce | cf8beb8725ad629d277d94909abdddb9adbc582a099341c6ea50a9abeadd3351 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBNDJBOjUzMjM0OjQxNjMxRDA6NUM2REJGQTo2QTRGQjQ0RCIsInZpc2l0b3JfaWQiOiIzMDY0MjA3NjU4NDg5NzIxOTMzIiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | a1b813e9fad6e6094633263e1ea4fd63e3a640c81713eb4a6435196f9dfdcb99 |
| hovercard-subject-tag | issue:4487812091 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/MicroPythonOS/MicroPythonOS/140/issue_layout |
| twitter:image | https://opengraph.githubassets.com/b84f5ee63b40d6006934f0cfc9305bd8dacd013c749c784a8d697c062a74c824/MicroPythonOS/MicroPythonOS/issues/140 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/b84f5ee63b40d6006934f0cfc9305bd8dacd013c749c784a8d697c062a74c824/MicroPythonOS/MicroPythonOS/issues/140 |
| og:image:alt | Summary lv.image.set_src() called with an 8-bit RGBA PNG (PNG color type 6) succeeds without raising and prints no error, but the image widget stays at 0×0 pixels and nothing renders on screen. The... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | bitcoin3us |
| hostname | github.com |
| expected-hostname | github.com |
| None | b92d11c0aa4a77d54ef4af1078b6a15fb5a70a215b30c4ecf28889d5a8e656d9 |
| turbo-cache-control | no-preview |
| go-import | github.com/MicroPythonOS/MicroPythonOS git https://github.com/MicroPythonOS/MicroPythonOS.git |
| octolytics-dimension-user_id | 213598128 |
| octolytics-dimension-user_login | MicroPythonOS |
| octolytics-dimension-repository_id | 975472483 |
| octolytics-dimension-repository_nwo | MicroPythonOS/MicroPythonOS |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 975472483 |
| octolytics-dimension-repository_network_root_nwo | MicroPythonOS/MicroPythonOS |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 4b249b445842943ed31549e027f57a8ade9881ed |
| ui-target | canary-1 |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width