GIF decoder(GIF解码器)

查看原文

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_img_set_src. As source, it also accepts images as variables (lv_img_dsc_t) or files.

GIF解码器让我们可以在 LVGL 中使用 GIF 图像。基于 https://github.com/lecram/gifdec 实现。

如果在 lv_conf.h 中启用了 LV_USE_GIF 后,可以使用 lv_gif_create(parent) 创建 gif 组件,这与 lv_img_create 非常相似。

lv_gif_set_src(obj, src) 的工作方式与 lv_img_set_src 非常相似。作为源,它还接受图像作为变量 (lv_img_dsc_t) 或文件。

Convert GIF files to C array(将 GIF 文件转换为 C 数组)

查看原文

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

要将 GIF 文件转换为字节值的数组,请使用 LVGL 的在线转换器。选择 “RAW” 颜色格式和 “C array” 输出格式。

Use GIF images from file(使用GIF文件)

查看原文

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 here or just enable one in lv_conf.h with LV_USE_FS_...

示例:

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

注意,需要注册文件系统驱动程序才能从文件中打开图像。点击这里阅读关于文件系统的更多信息,或直接在 lv_conf.h 中打开其中一个类似 LV_USE_FS_... 的宏。

Memory requirements(内存要求)

查看原文

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

  • LV_COLOR_DEPTH 8: 3 x image width x image height

  • LV_COLOR_DEPTH 16: 4 x image width x image height

  • LV_COLOR_DEPTH 32: 5 x image width x image height

要解码和显示 GIF 文件,需要以下数量的 RAM (字节):

  • LV_COLOR_DEPTH 8:3 x 图像宽度 x 图像高度

  • LV_COLOR_DEPTH 16:4 x 图像宽度 x 图像高度

  • LV_COLOR_DEPTH 32:5 x 图像宽度 x 图像高度

拓展阅读

Example

Open a GIF image from file and variable

C code  

 GitHub
#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_IMG_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

MicroPython code  

 GitHub Simulator
#!/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
#
img_bulb_gif = lv.img_dsc_t(
    {
        "header": {"always_zero": 0, "w": 0, "h": 0,  "cf": lv.img.CF.RAW},
        "data_size": 0,
        "data": img_bulb_gif_map,
    }
)
img1 = lv.gif(lv.scr_act())
img1.set_src(img_bulb_gif)
img1.align(lv.ALIGN.RIGHT_MID, -150, 0)

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

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

API

Functions

lv_obj_t *lv_gif_create(lv_obj_t *parent)
void lv_gif_set_src(lv_obj_t *obj, const void *src)
void lv_gif_restart(lv_obj_t *gif)

Variables

const lv_obj_class_t lv_gif_class
struct lv_gif_t

Public Members

lv_img_t img
gd_GIF *gif
lv_timer_t *timer
lv_img_dsc_t imgdsc
uint32_t last_call