Pārlūkot izejas kodu

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

alienwalker 7 mēneši atpakaļ
vecāks
revīzija
214e31ec1f

+ 13 - 2
components/lcd/luat_lcd.h

@@ -113,6 +113,15 @@ typedef struct luat_lcd_conf {
     u8g2_t luat_lcd_u8g2 ;
 } luat_lcd_conf_t;
 
+typedef struct luat_lcd_buff_info {
+	luat_color_t * buff;
+    size_t len;
+    uint32_t width;
+    uint32_t height;
+	// size_t offset;
+	void* userdata;
+}luat_lcd_buff_info_t;
+
 typedef struct luat_lcd_opts {
     const char* name;
     uint8_t sleep_cmd;
@@ -193,9 +202,11 @@ int luat_lcd_draw_hline(luat_lcd_conf_t* conf, int16_t x, int16_t y,int16_t h, l
 int luat_lcd_draw_rectangle(luat_lcd_conf_t* conf, int16_t x1, int16_t y1, int16_t x2, int16_t y2, luat_color_t color);
 int luat_lcd_draw_circle(luat_lcd_conf_t* conf, int16_t x0, int16_t y0, uint8_t r, luat_color_t color);
 int luat_lcd_set_direction(luat_lcd_conf_t* conf, uint8_t direction);
-#ifdef LUAT_USE_TJPGD
+
+// weak函数 可bsp单独适配硬件加速实现
 int lcd_draw_jpeg(luat_lcd_conf_t* conf, const char* path, int16_t x, int16_t y);
-#endif
+int lcd_jpeg_decode(luat_lcd_conf_t* conf, const char* path, luat_lcd_buff_info_t* buff_info);
+
 /*
  * csdk适配用
  */

Failā izmaiņas netiks attēlotas, jo tās ir par lielu
+ 425 - 384
components/lcd/luat_lib_lcd.c


+ 87 - 0
components/lcd/luat_lib_lcd_jpg.c

@@ -122,4 +122,91 @@ LUAT_WEAK int lcd_draw_jpeg(luat_lcd_conf_t* conf, const char* path, int16_t x,
     }
 }
 
+static unsigned int decode_file_in_func (JDEC* jd, uint8_t* buff, unsigned int nbyte){
+    luat_lcd_buff_info_t *buff_info = (luat_lcd_buff_info_t*)jd->device;   /* Device identifier for the session (5th argument of jd_prepare function) */
+    if (buff) {
+        /* Read bytes from input stream */
+        return luat_fs_fread(buff, 1, nbyte, (FILE*)(buff_info->userdata));
+    } else {
+        /* Remove bytes from input stream */
+        return luat_fs_fseek((FILE*)(buff_info->userdata), nbyte, SEEK_CUR) ? 0 : nbyte;
+    }
+}
+
+static int decode_out_func (JDEC* jd, void* bitmap, JRECT* rect){
+    luat_lcd_buff_info_t *buff_info = (luat_lcd_buff_info_t*)jd->device;
+    uint16_t* tmp = (uint16_t*)bitmap;
+
+    // rgb高低位swap
+    // uint16_t count = (rect->right - rect->left + 1) * (rect->bottom - rect->top + 1);
+    // for (size_t i = 0; i < count; i++){
+    //     if (lcd_dft_conf->endianness_swap)
+    //         buff_info->buff[buff_info->offset] = ((tmp[i] >> 8) & 0xFF)+ ((tmp[i] << 8) & 0xFF00);
+    //     else
+    //         buff_info->buff[buff_info->offset] = tmp[i];
+	// 	buff_info->offset++;
+    // }
+	uint16_t idx = 0;
+	for (size_t y = rect->top; y <= rect->bottom; y++){
+		uint16_t offset = y*buff_info->width + rect->left;
+		for (size_t x = rect->left; x <= rect->right; x++){
+			if (lcd_dft_conf->endianness_swap)
+				buff_info->buff[offset] = ((tmp[idx] >> 8) & 0xFF)+ ((tmp[idx] << 8) & 0xFF00);
+			else
+				buff_info->buff[offset] = tmp[idx];
+			offset++;idx++;
+		}
+	}
+	
+    // LLOGD("jpeg seg %dx%d %dx%d", rect->left, rect->top, rect->right, rect->bottom);
+    // LLOGD("jpeg seg size %d %d %d", rect->right - rect->left + 1, rect->bottom - rect->top + 1, (rect->right - rect->left + 1) * (rect->bottom - rect->top + 1));
+    return 1;    /* Continue to decompress */
+}
+LUAT_WEAK int lcd_jpeg_decode(luat_lcd_conf_t* conf, const char* path, luat_lcd_buff_info_t* buff_info){
+    JRESULT res;      /* Result code of TJpgDec API */
+    JDEC jdec;        /* Decompression object */
+    void *work = NULL;       /* Pointer to the decompressor work area */
+#if JD_FASTDECODE == 2
+    size_t sz_work = 3500 * 3; /* Size of work area */
+#else
+    size_t sz_work = 3500; /* Size of work area */
+#endif
+    FILE* fd = luat_fs_fopen(path, "r");
+    if (fd == NULL) {
+        LLOGW("no such file %s", path);
+		goto error;
+    }
+	buff_info->userdata = fd;
+	work = luat_heap_malloc(sz_work);
+	if (work == NULL) {
+		LLOGE("out of memory when malloc jpeg decode workbuff");
+		goto error;
+	}
+    res = jd_prepare(&jdec, decode_file_in_func, work, sz_work, buff_info);
+    if (res != JDR_OK) {
+        LLOGW("jd_prepare file %s error %d", path, res);
+        goto error;
+    }
+    buff_info->width = jdec.width;
+    buff_info->height = jdec.height;
+	buff_info->len = jdec.width*jdec.height*sizeof(luat_color_t);
+	buff_info->buff = luat_heap_malloc(buff_info->len);
+    res = jd_decomp(&jdec, decode_out_func, 0);
+    if (res != JDR_OK) {
+        LLOGW("jd_decomp file %s error %d", path, res);
+        goto error;
+    }
+    luat_heap_free(work);
+    luat_fs_fclose(fd);
+	return 0;
+error:
+	if (work){
+		luat_heap_free(work);
+	}
+	if (fd){
+		luat_fs_fclose(fd);
+	}
+	return -1;
+}
+
 #endif

+ 12 - 15
components/tp/luat_tp.c

@@ -9,8 +9,8 @@
 
 static luat_rtos_task_handle g_s_tp_task_handle = NULL;
 
-uint16_t last_x = 0;
-uint16_t last_y = 0;
+// uint16_t last_x = 0;
+// uint16_t last_y = 0;
 void luat_tp_task_entry(void* param){
     uint32_t message_id = 0;
     luat_tp_config_t *luat_tp_config = NULL;
@@ -35,21 +35,18 @@ void luat_tp_task_entry(void* param){
             tp_data->y_coordinate = coordinate_tmp;
         }
 
-        // 抬起时,坐标为松开前的最后一次的坐标
-        if (tp_data->event == TP_EVENT_TYPE_UP)
-        {
-            tp_data->x_coordinate = last_x;
-            tp_data->y_coordinate = last_y;
-        }
-        else
-        {
-            last_x = tp_data->x_coordinate;
-            last_y = tp_data->y_coordinate;
-        }
+        // // 抬起时,坐标为松开前的最后一次的坐标 !!!不应在此处修改,应在上方实现统一实现,故暂时注释!!!!
+        // if (tp_data->event == TP_EVENT_TYPE_UP) {
+        //     tp_data->x_coordinate = last_x;
+        //     tp_data->y_coordinate = last_y;
+        // } else {
+        //     last_x = tp_data->x_coordinate;
+        //     last_y = tp_data->y_coordinate;
+        // }
         
 
         if (luat_tp_config->callback == NULL){
-        	luat_tp_config->opts->read_done(luat_tp_config);
+            luat_tp_config->opts->read_done(luat_tp_config);
         }else{
             luat_tp_config->callback(luat_tp_config,tp_data);
         }
@@ -60,7 +57,7 @@ int luat_tp_init(luat_tp_config_t* luat_tp_config){
     if (g_s_tp_task_handle == NULL){
         int ret = luat_rtos_task_create(&g_s_tp_task_handle, 4096, 10, "tp", luat_tp_task_entry, NULL, 32);
         if (ret){
-        	g_s_tp_task_handle = NULL;
+            g_s_tp_task_handle = NULL;
             LLOGE("tp task create failed!");
             return -1;
         }

Daži faili netika attēloti, jo izmaiņu fails ir pārāk liels