Эх сурвалжийг харах

Merge branch 'master' of gitee.com:openLuat/LuatOS

# Conflicts:
#	components/lcd/luat_lib_lcd.c
Wendal Chen 4 жил өмнө
parent
commit
7ea2c4aded

+ 11 - 2
components/lcd/luat_lib_lcd.c

@@ -1167,7 +1167,15 @@ static int l_lcd_drawxbm(lua_State *L){
 
 #ifdef LUAT_USE_TJPGD
 #include "luat_tjpgd.h"
-
+/*
+显示图片,当前只支持jpg,jpeg
+@api lcd.showImage(x, y, file)
+@int X坐标
+@int y坐标
+@string 文件路径
+@usage
+lcd.showImage(0,0,"/luadb/logo.jpg")
+*/
 static int l_lcd_showimage(lua_State *L){
     size_t size = 0;
     int x = luaL_checkinteger(L, 1);
@@ -1178,7 +1186,8 @@ static int l_lcd_showimage(lua_State *L){
     uint8_t* image_data = luat_tjpgd(input_file);
     if(image_data != NULL){
       luat_lcd_show_image(default_conf,x, y, w, h, (luat_color_t *)image_data,1);
-      luat_heap_free(image_data);    /* Discard frame buffer */
+      luat_heap_free(image_data->fbuf);    /* Discard frame buffer */
+      luat_heap_free(image_data);          /* Discard frame buffer */
       lcd_auto_flush(default_conf);
       lua_pushboolean(L, 1);
     }

+ 9 - 2
components/tjpgd/luat_lib_tjpgd.c

@@ -69,13 +69,15 @@ int out_func (JDEC* jd, void* bitmap, JRECT* rect){
 /* Program Jpeg_Dec             */
 /*------------------------------*/
 
-uint8_t * luat_tjpgd(const char* input_file){
+luat_tjpgd_data_t * luat_tjpgd(const char* input_file){
     JRESULT res;      /* Result code of TJpgDec API */
     JDEC jdec;        /* Decompression object */
     void *work;       /* Pointer to the decompressor work area */
     size_t sz_work = 3500; /* Size of work area */
     IODEV devid;      /* User defined device identifier */
 
+    luat_tjpgd_data_t* tjpgd_data = luat_heap_malloc(sizeof(luat_tjpgd_data_t));
+
     devid.fp = luat_fs_fopen(input_file, "rb");
     if (!devid.fp){
         LLOGI("Jpeg_Dec open the file failed...");
@@ -93,6 +95,8 @@ uint8_t * luat_tjpgd(const char* input_file){
     if (res == JDR_OK){
         /* It is ready to dcompress and image info is available here */
         LLOGI("Image size is %u x %u.\n%u bytes of work ares is used.\n", jdec.width, jdec.height, sz_work - jdec.sz_pool);
+        tjpgd_data->width = jdec.width;
+        tjpgd_data->height = jdec.height;
         devid.fbuf = luat_heap_malloc(N_BPP * jdec.width * jdec.height); /* Frame buffer for output image */
         if(devid.fbuf == NULL)
         {
@@ -104,7 +108,10 @@ uint8_t * luat_tjpgd(const char* input_file){
         res = jd_decomp(&jdec, out_func, 0);   /* Start to decompress with 1/1 scaling */
         if (res == JDR_OK) {
             /* Decompression succeeded. You have the decompressed image in the frame buffer here. */
-            return devid.fbuf;
+            tjpgd_data->fbuf = devid.fbuf;
+            luat_heap_free(work);
+            luat_fs_fclose(devid.fp);
+            return tjpgd_data;
             LLOGI("Decompression succeeded.");
         }
         else{

+ 8 - 1
components/tjpgd/luat_tjpgd.h

@@ -8,7 +8,14 @@
 extern "C" {
 #endif
 
-uint8_t * luat_tjpgd(const char* input_file);
+
+typedef struct {
+    uint16_t width;
+	uint16_t height;
+    uint8_t *fbuf;
+} luat_tjpgd_data_t;
+
+luat_tjpgd_data_t * luat_tjpgd(const char* input_file);
 
 #ifdef __cplusplus
 }