TJPGD decoder

Allow the use of JPG images in LVGL. Besides that it also allows the use of a custom format, called Split JPG (SJPG), which can be decoded in more optimal way on embedded systems.

Overview

  • Supports both normal JPG and the custom SJPG formats.

  • Decoding normal JPG consumes RAM with the size of the whole uncompressed image (recommended only for devices with more RAM)

  • SJPG is a custom format based on "normal" JPG and specially made for LVGL.

  • SJPG is 'split-jpeg' which is a bundle of small jpeg fragments with an sjpg header.

  • SJPG size will be almost comparable to the jpg file or might be a slightly larger.

  • File read from file and c-array are implemented.

  • SJPEG frame fragment cache enables fast fetching of lines if available in cache.

  • By default the sjpg image cache will be image width * 2 * 16 bytes (can be modified)

  • Currently only 16 bit image format is supported (TODO)

  • Only the required portion of the JPG and SJPG images are decoded, therefore they can't be zoomed or rotated.

Usage

If enabled in lv_conf.h by LV_USE_TJPGD LVGL will register a new image decoder automatically so JPG and SJPG files can be used directly as image sources. For example:

lv_image_set_src(my_img, "S:path/to/picture.jpg");

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

Converter

Converting JPG to C array

Converting JPG to SJPG

python3 and the PIL library required. (PIL can be installed with pip3 install pillow)

To create SJPG from JPG: - Copy the image to convert into lvgl/scripts - cd lvgl/scripts - python3 jpg_to_sjpg.py image_to_convert.jpg. It creates both a C files and an SJPG image.

The expected result is:

Conversion started...

Input:
        image_to_convert.jpg
        RES = 640 x 480

Output:
        Time taken = 1.66 sec
        bin size = 77.1 KB
        walpaper.sjpg           (bin file)
        walpaper.c              (c array)

All good!

Example

Load an SJPG image

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

/**
 * Load a JPG image
 */
void lv_example_tjpgd_1(void)
{
    lv_obj_t * wp;

    wp = 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(wp, "A:lvgl/examples/libs/tjpgd/img_lvgl_logo.jpg");
    lv_obj_center(wp);
}

#endif
#!/opt/bin/lv_micropython -i
import lvgl as lv
import display_driver
import fs_driver

fs_drv = lv.fs_drv_t()
fs_driver.fs_register(fs_drv, 'S')

wp = lv.image(lv.screen_active())
# The File system is attached to letter 'S'

wp.set_src("S:img_lvgl_logo.jpg")
wp.center()

API

lv_tjpgd.h

tjpgd.h

tjpgdcnf.h