Răsfoiți Sursa

add:默认图片大小

Dozingfiretruck 4 ani în urmă
părinte
comite
067620eb13

+ 6 - 7
components/lcd/luat_lib_lcd.c

@@ -1146,13 +1146,12 @@ static int l_lcd_showimage(lua_State *L){
     size_t size = 0;
     int x = luaL_checkinteger(L, 1);
     int y = luaL_checkinteger(L, 2);
-    int w = luaL_checkinteger(L, 3);
-    int h = luaL_checkinteger(L, 4);
-    const char* input_file = luaL_checklstring(L, 5, &size);
-    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 */
+    const char* input_file = luaL_checklstring(L, 3, &size);
+    luat_tjpgd_data_t* image_data = luat_tjpgd(input_file);
+    if(image_data->fbuf != NULL){
+      luat_lcd_show_image(default_conf,x, y, image_data->width, image_data->height, (luat_color_t *)image_data->fbuf,1);
+      luat_heap_free(image_data->fbuf);    /* Discard frame buffer */
+      luat_heap_free(image_data);
     }
     lua_pushboolean(L, 1);
     return 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
 }