chore: code and documentation cleanups, renames and fixes (#4607)
This commit is contained in:
@@ -2,29 +2,32 @@
|
||||
Snapshot
|
||||
========
|
||||
|
||||
Snapshot provides APIs to take snapshot image for LVGL object together
|
||||
with its children. The image will look exactly like the object.
|
||||
Snapshot provides API to take snapshot image for LVGL object together
|
||||
with its children. The image will look exactly like the object on display.
|
||||
|
||||
Usage
|
||||
-----
|
||||
|
||||
Simply call API :c:func:`lv_snapshot_take` to generate the image descriptor
|
||||
which can be set as image object src using :c:func:`lv_img_set_src`.
|
||||
which can be set as image object src using :c:func:`lv_image_set_src`.
|
||||
|
||||
Note, only below color formats are supported for now: -
|
||||
LV_IMG_CF_TRUE_COLOR - LV_IMG_CF_TRUE_COLOR_ALPHA - LV_IMG_CF_ALPHA_8BIT
|
||||
Note, only following color formats are supported for now:
|
||||
- LV_COLOR_FORMAT_RGB565
|
||||
- LV_COLOR_FORMAT_RGB888
|
||||
- LV_COLOR_FORMAT_XRGB8888
|
||||
- LV_COLOR_FORMAT_ARGB8888
|
||||
|
||||
Free the Image
|
||||
~~~~~~~~~~~~~~
|
||||
|
||||
The memory :c:func:`lv_snapshot_take` uses are dynamically allocated using
|
||||
:c:func:`lv_mem_alloc`. Use API :c:func:`lv_snapshot_free` to free the memory it
|
||||
:c:func:`lv_malloc`. Use API :c:func:`lv_snapshot_free` to free the memory it
|
||||
takes. This will firstly free memory the image data takes, then the
|
||||
image descriptor.
|
||||
|
||||
Take caution to free the snapshot but not delete the image object.
|
||||
Before free the memory, be sure to firstly unlink it from image object,
|
||||
using :c:expr:`lv_img_set_src(NULL)` and :c:expr:`lv_img_cache_invalidate_src(src)`.
|
||||
using :c:expr:`lv_image_set_src(NULL)` and :c:expr:`lv_cache_invalidate(lv_cache_find(src, LV_CACHE_SRC_TYPE_PTR, 0, 0));`.
|
||||
|
||||
Below code snippet explains usage of this API.
|
||||
|
||||
@@ -32,19 +35,19 @@ Below code snippet explains usage of this API.
|
||||
|
||||
void update_snapshot(lv_obj_t * obj, lv_obj_t * img_snapshot)
|
||||
{
|
||||
lv_img_dsc_t* snapshot = (void*)lv_img_get_src(img_snapshot);
|
||||
lv_image_dsc_t* snapshot = (void*)lv_image_get_src(img_snapshot);
|
||||
if(snapshot) {
|
||||
lv_snapshot_free(snapshot);
|
||||
}
|
||||
snapshot = lv_snapshot_take(obj, LV_IMG_CF_TRUE_COLOR_ALPHA);
|
||||
lv_img_set_src(img_snapshot, snapshot);
|
||||
snapshot = lv_snapshot_take(obj, LV_COLOR_FORMAT_ARGB8888);
|
||||
lv_image_set_src(img_snapshot, snapshot);
|
||||
}
|
||||
|
||||
Use Existing Buffer
|
||||
~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
If the snapshot needs update now and then, or simply caller provides memory, use API
|
||||
``lv_res_t lv_snapshot_take_to_buf(lv_obj_t * obj, lv_img_cf_t cf, lv_img_dsc_t * dsc, void * buf, uint32_t buff_size)``
|
||||
``lv_result_t lv_snapshot_take_to_buf(lv_obj_t * obj, lv_color_format_t cf, lv_image_dsc_t * dsc, void * buf, uint32_t buff_size);``
|
||||
for this case. It's caller's responsibility to alloc/free the memory.
|
||||
|
||||
If snapshot is generated successfully, the image descriptor is updated
|
||||
|
||||
Reference in New Issue
Block a user