Browse Source

add:添加图片显示

Dozingfiretruck 4 years ago
parent
commit
14cf5ae22d
3 changed files with 40 additions and 4 deletions
  1. 18 3
      components/lcd/luat_lcd.c
  2. 1 1
      components/lcd/luat_lcd.h
  3. 21 0
      components/lcd/luat_lib_lcd.c

+ 18 - 3
components/lcd/luat_lcd.c

@@ -310,11 +310,26 @@ int luat_lcd_draw_circle(luat_lcd_conf_t* conf,uint16_t x0, uint16_t y0, uint8_t
     return 0;
 }
 
-int luat_lcd_show_image(luat_lcd_conf_t* conf,uint16_t x, uint16_t y, uint16_t length, uint16_t wide, const uint8_t *image){
+int luat_lcd_show_image(luat_lcd_conf_t* conf,uint16_t x, uint16_t y, uint16_t length, uint16_t wide, const luat_color_t *image,uint8_t swap){
     if (x + length > conf->w || y + wide > conf->h){
         return -1;
     }
-    luat_lcd_draw(conf, x, y, x + length - 1, y + wide - 1, image);
+    if (swap)
+    {
+        uint32_t size = length * wide;
+        luat_lcd_set_address(conf, x, y, x + length - 1, y + wide - 1);
+        for (size_t i = 0; i < size; i++){
+            char color[2] = {0};
+            color[0] = *(image+i) >> 8;
+            color[1] = *(image+i);
+            if (conf->port == LUAT_LCD_SPI_DEVICE){
+            luat_spi_device_send((luat_spi_device_t*)(conf->lcd_spi_device), (const char*)color, 2);
+            }else{
+                luat_spi_send(conf->port, (const char*)color, 2);
+            }
+        }
+    }else{
+        luat_lcd_draw(conf, x, y, x + length - 1, y + wide - 1, image);
+    }
     return 0;
 }
-

+ 1 - 1
components/lcd/luat_lcd.h

@@ -94,7 +94,7 @@ int luat_lcd_draw_vline(luat_lcd_conf_t* conf, uint16_t x, uint16_t y,uint16_t h
 int luat_lcd_draw_hline(luat_lcd_conf_t* conf, uint16_t x, uint16_t y,uint16_t h, luat_color_t color);
 int luat_lcd_draw_rectangle(luat_lcd_conf_t* conf,uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, luat_color_t color);
 int luat_lcd_draw_circle(luat_lcd_conf_t* conf,uint16_t x0, uint16_t y0, uint8_t r, luat_color_t color);
-int luat_lcd_show_image(luat_lcd_conf_t* conf,uint16_t x, uint16_t y, uint16_t length, uint16_t wide, const uint8_t *image);
+int luat_lcd_show_image(luat_lcd_conf_t* conf,uint16_t x, uint16_t y, uint16_t length, uint16_t wide, const luat_color_t *image,uint8_t swap);
 
 void luat_lcd_execute_cmds(luat_lcd_conf_t* conf, uint32_t* cmds, uint32_t count);
 

+ 21 - 0
components/lcd/luat_lib_lcd.c

@@ -1139,6 +1139,26 @@ static int l_lcd_drawxbm(lua_State *L){
     return 1;
 }
 
+#ifdef LUAT_USE_TJPGD
+#include "luat_tjpgd.h"
+
+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 */
+    }
+    lua_pushboolean(L, 1);
+    return 1;
+}
+#endif
+
 #include "rotable2.h"
 static const rotable_Reg_t reg_lcd[] =
 {
@@ -1167,6 +1187,7 @@ static const rotable_Reg_t reg_lcd[] =
     { "getDefault", ROREG_FUNC(l_lcd_get_default)},
     { "getSize",    ROREG_FUNC(l_lcd_get_size)},
     { "drawXbm",    ROREG_FUNC(l_lcd_drawxbm)},
+    { "showImage",    ROREG_FUNC(l_lcd_showimage)},
 #ifdef LUAT_USE_GTFONT
     { "drawGtfontGb2312", ROREG_FUNC(l_lcd_draw_gtfont_gb2312)},
     { "drawGtfontGb2312Gray", ROREG_FUNC(l_lcd_draw_gtfont_gb2312_gray)},