diff options
| author | ailurux <ailuruxx@gmail.com> | 2024-04-02 11:13:50 +1100 |
|---|---|---|
| committer | ailurux <ailuruxx@gmail.com> | 2024-04-02 11:13:50 +1100 |
| commit | e20ebe7574db5aedc73f07b7bb3a0a01eae93c84 (patch) | |
| tree | 34c93ec8a80e282f3ce3e47dd60c41e46de0f8b3 /lib/luavgl/src/imgdata.c | |
| parent | a750af35aa6afda40aadca8f7cf8db75f41a43b2 (diff) | |
| parent | 0d0c4b2307cac8436fea7276956f293262b265ed (diff) | |
| download | tangara-fw-e20ebe7574db5aedc73f07b7bb3a0a01eae93c84.tar.gz | |
Merge branch 'main' into lua-volume
Diffstat (limited to 'lib/luavgl/src/imgdata.c')
| -rw-r--r-- | lib/luavgl/src/imgdata.c | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/lib/luavgl/src/imgdata.c b/lib/luavgl/src/imgdata.c new file mode 100644 index 00000000..9f7a2a01 --- /dev/null +++ b/lib/luavgl/src/imgdata.c @@ -0,0 +1,38 @@ +#include "draw/lv_img_buf.h" +#include "draw/lv_img_decoder.h" +#include "lauxlib.h" +#include "lua.h" +#include "luavgl.h" +#include "misc/lv_color.h" +#include "misc/lv_mem.h" +#include "misc/lv_types.h" +#include "private.h" +#include <stdint.h> +#include <string.h> + +static int luavgl_imgdata_create(lua_State *L) +{ + if (!lua_isstring(L, 1)) { + return luaL_argerror(L, 1, "expect string"); + } + + lv_img_decoder_dsc_t descriptor; + lv_res_t res = + lv_img_decoder_open(&descriptor, lua_tostring(L, 1), lv_color_black(), 0); + if (res != LV_RES_OK) { + return luaL_error(L, "failed to decode image."); + } + + lv_img_dsc_t *data = lv_mem_alloc(sizeof(lv_img_dsc_t)); + data->header = descriptor.header; + data->data_size = data->header.w * data->header.h * sizeof(uint32_t); // ??? + + uint8_t *data_copy = lv_mem_alloc(data->data_size); + memcpy(data_copy, descriptor.img_data, data->data_size); + data->data = data_copy; + + lv_img_decoder_close(&descriptor); + + lua_pushlightuserdata(L, data); + return 1; +} |
