summaryrefslogtreecommitdiff
path: root/lib/luavgl/src/imgdata.c
diff options
context:
space:
mode:
authorjacqueline <me@jacqueline.id.au>2024-03-20 18:23:33 +1100
committerjacqueline <me@jacqueline.id.au>2024-03-20 18:23:33 +1100
commit654dcb34d61bc8313ff0d3a62e73bdf945c231ad (patch)
treee8c2ad1d22f38fa4748d8ebb46d77c8f14115f8d /lib/luavgl/src/imgdata.c
parenta05d93a1e26181237a76da5ce398c6b08497d591 (diff)
downloadtangara-fw-654dcb34d61bc8313ff0d3a62e73bdf945c231ad.tar.gz
Support pinning decoded images to RAM
Diffstat (limited to 'lib/luavgl/src/imgdata.c')
-rw-r--r--lib/luavgl/src/imgdata.c38
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;
+}