GIF Decoder

GIF Decoder is an LVGL extension that enables you to use GIF images in your LVGL UI.

For a detailed introduction, see: https://github.com/lecram/gifdec .

Usage

Once enabled in lv_conf.h by setting LV_USE_GIF to 1, lv_gif_create(parent) can be used to create a gif widget.

lv_gif_set_src(widget, src) works very similarly to lv_image_set_src(). As source, it also accepts images as variables (lv_image_dsc_t) or files.

Converting GIF Files to C Arrays

To convert a GIF file to an array of bytes, use LVGL's online converter. Select "Raw" color format and "C array" Output format.

Using GIF Images from Files

Example:

lv_gif_set_src(widget, "S:path/to/example.gif");

Note that, a file system driver needs to be registered to open images from files. To do so, follow the instructions in File System (lv_fs_drv).

Memory Requirements

To decode and display a GIF animation the following amount of RAM (in bytes) is required for each of the following color depths:

  • LV_COLOR_DEPTH 8: 3 × image width × image height

  • LV_COLOR_DEPTH 16: 4 × image width × image height

  • LV_COLOR_DEPTH 32: 5 × image width × image height

Example

Open a GIF image from file and variable

#include "../../lv_examples.h"
#if LV_USE_GIF && LV_BUILD_EXAMPLES

/**
 * Open a GIF image from a file and a variable
 */
void lv_example_gif_1(void)
{
    LV_IMAGE_DECLARE(img_bulb_gif);
    lv_obj_t * img;

    img = lv_gif_create(lv_screen_active());
    lv_gif_set_src(img, &img_bulb_gif);
    lv_obj_align(img, LV_ALIGN_LEFT_MID, 20, 0);

    img = lv_gif_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_gif_set_src(img, "A:lvgl/examples/libs/gif/bulb.gif");
    lv_obj_align(img, LV_ALIGN_RIGHT_MID, -20, 0);
}

#endif

API

gifdec.h

lv_types.h

lv_gif.h