GIF decoder

Allow using GIF images in LVGL. Based on https://github.com/lecram/gifdec

When enabled in lv_conf.h with LV_USE_GIF lv_gif_create(parent) can be used to create a gif widget.

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

Convert GIF files to C array

To convert a GIF file to byte values array use LVGL's online converter. Select "Raw" color format and "C array" Output format.

Use GIF images from file

For example:

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

Note that, a file system driver needs to be registered to open images from files. Read more about it File system or just enable one in lv_conf.h with LV_USE_FS_...

Memory requirements

To decode and display a GIF animation the following amount of RAM is required:

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_scr_act());
    lv_gif_set_src(img, &img_bulb_gif);
    lv_obj_align(img, LV_ALIGN_LEFT_MID, 20, 0);

    img = lv_gif_create(lv_scr_act());
    /* 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
#!/opt/bin/lv_micropython -i
import lvgl as lv
import display_driver
import fs_driver
from img_bulb_gif import img_bulb_gif_map

fs_drv = lv.fs_drv_t()
fs_driver.fs_register(fs_drv, 'S')
#
# Open a GIF image from a file and a variable
#
image_bulb_gif = lv.image_dsc_t(
    {
        "header": {"always_zero": 0, "w": 0, "h": 0,  "cf": lv.COLOR_FORMAT.RAW},
        "data_size": 0,
        "data": img_bulb_gif_map,
    }
)
image1 = lv.gif(lv.scr_act())
image1.set_src(image_bulb_gif)
image1.align(lv.ALIGN.RIGHT_MID, -150, 0)

image2 = lv.gif(lv.scr_act())
# The File system is attached to letter 'S'

image2.set_src("S:bulb.gif")
image2.align(lv.ALIGN.RIGHT_MID, -250, 0)

API

gifdec.h