WebP Decoder¶
libwebp is an LVGL interface to the WebP image format — a modern image format that provides superior lossless and lossy compression for images on the web. WebP offers:
Smaller file sizes compared to JPEG and PNG
Lossy compression with transparency
Lossless compression
Animation support (not yet supported in the LVGL integration)
For more information, see: https://developers.google.com/speed/webp
Library source: https://github.com/webmproject/libwebp
Install¶
# Linux
sudo apt install libwebp-dev
# macOS
brew install webp
Adding libwebp to Your Project¶
CMake configuration:
find_package(PkgConfig REQUIRED)
pkg_check_modules(WebP REQUIRED libwebp)
include_directories(${WebP_INCLUDEDIR})
target_link_libraries(main ${WebP_LINK_LIBRARIES})
Usage¶
Set LV_USE_LIBWEBP in lv_conf.h to 1.
Memory requirements for WebP images:
Lossy WebP: width × height × 4 bytes (ARGB8888 format)
Lossless WebP: width × height × 4 bytes (ARGB8888 format)
For optimal memory usage, combine with LVGL's Image caching feature.
Example¶
Open a WEBP image from file and variable¶
C code
View on GitHub#include "../../lv_examples.h"
#if LV_BUILD_EXAMPLES
#if LV_USE_LIBWEBP
/**
* Load a WEBP image
*/
void lv_example_libwebp_1(void)
{
lv_obj_t * img;
img = lv_image_create(lv_screen_active());
/* Assuming a File system is attached to letter 'A'
* E.g. set LV_USE_FS_STDIO 'A' in lv_conf.h */
lv_image_set_src(img, "A:lvgl/examples/libs/libwebp/rose.webp");
lv_obj_center(img);
}
#else
void lv_example_libwebp_1(void)
{
lv_obj_t * label = lv_label_create(lv_screen_active());
lv_label_set_text(label, "Libwebp is not installed");
lv_obj_center(label);
}
#endif
#endif