Repository navigation
feat(lua): add lvgl.bitmap object - #7971
Closed
thomaskistler wants to merge 2 commits into
Closed
thomaskistler wants to merge 2 commits into
thomaskistler wants to merge 2 commits into
Conversation
StaticBitmap always loaded images as ARGB4444, which reduces every channel to 4 bits and then expands the result to RGB565 plus an 8-bit alpha channel (3 bytes per pixel). For opaque images such as JPEG that loses colour precision and costs 50% more memory than the 2 bytes per pixel of RGB565. Mirror BitmapBuffer::loadBitmap: setSource(filename) now chooses the format from the file (RGB565 for opaque images, ARGB4444 for images with alpha), and setSource(filename, fmt) forces one. The constructor takes the same optional format. RGB565 images are scaled to fit the frame like the ARGB4444 path does, and displayed without an alpha channel. Existing callers (model select, file preview, model bitmap widget) pass BMP_ARGB4444 explicitly, so their rendering does not change. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Add lvgl.bitmap([parent, ]params), a separate object from lvgl.image whose decoded pixels are owned by the object instead of the shared LVGL image cache, which holds only 8 entries. A widget that needs a set of images to stay decoded, such as map tiles, can keep one object per image and only decode when the file changes. - `file` accepts a string or a function, like lvgl.image - the image is decoded and scaled to fit the frame when the source changes; resizing the frame reloads it - hidden objects keep their pixels - opaque images keep full RGB565 colour (2 bytes per pixel); images with alpha use ARGB4444 (3 bytes per pixel) - lvgl.image is not modified Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes: N/A (feature; no linked issue). Alternative to #7947, which adds a
bitmapsource tolvgl.image.Summary of changes:
Adds
lvgl.bitmap([parent, ]params), a separate Lua LVGL object (alsolvgl.BITMAPforlvgl.build) that wrapsStaticBitmap.lvgl.imageis not modified.Motivation
lvgl.imagedecodes through LVGL's shared image cache, which has 8 entries (LV_IMG_CACHE_DEF_SIZE). A Lua widget that shows more images than that, for example a map made of 256x256 JPEG tiles, keeps evicting images that are still visible and decodes them again on redraw.lvgl.bitmapdecodes once when itsfilechanges and the object owns the pixels, so a widget can keep one object per image and decide for itself which ones stay decoded.Details
fileis a string or a function, likelvgl.image. The file is only decoded when it changes. A function is only called while the object is visible. Setting a string replaces a previous function.w/hreloads it. Hidden objects keep their pixels.StaticBitmap::setSource(filename)now chooses the format from the file likeBitmapBuffer::loadBitmap: RGB565 for opaque images, ARGB4444 for images with alpha.setSource(filename, fmt)forces a format, and the constructor takes the same optional format. Existing callers (model select, file preview, model bitmap widget) passBMP_ARGB4444explicitly, so their rendering does not change.StaticBitmapalways used ARGB4444, which keeps 4 bits per channel and stores 3 bytes per pixel. For an opaque JPEG tile, an ad-hoc host measurement gave 192 KB and 31.1 dB against the 8-bit decode, versus 128 KB and 39.9 dB for RGB565. With the format chosen from the file, opaque images are byte-identical to whatBitmap.openproduces.LUA_MEM_EXTRA_MAX).ETX_BITMAPis inserted afterETX_QRCODE, so the numeric values of laterlvgl.*type constants shift by one.lvgl.bitmapluadoc block. It is marked as introduced in 3.0.0.Validation
Built and tested the native TX16S target on macOS:
cmake -DCMAKE_BUILD_TYPE=Debug -DPCB=X10 -DPCBREV=TX16S ..inbuild/, thencmake --build . --target native-configureandcmake --build native --target gtests-radionative/gtests-radio: 259 tests passed, including 17 newLuaLvglBitmaptestsNot done: ARM firmware and Companion builds, and testing on a radio.