菊风视频通话和相机画面旋转接口添加
authorp15692025051 <846603105@qq.com>
Thu, 14 Dec 2023 01:54:41 +0000 (09:54 +0800)
committerp15692025051 <846603105@qq.com>
Thu, 14 Dec 2023 01:54:41 +0000 (09:54 +0800)
K01滑动效果优化

2.sdk/Helios_SDK/components/jpeg/jpeg_operation.c
2.sdk/Helios_SDK/components/jpeg/jpeg_operation.h
2.sdk/Helios_SDK/peripheral/helios_lcd.h
2.sdk/Helios_SDK/services/microPython/lib/lvgl/lv_conf.h
2.sdk/Helios_SDK/services/microPython/lib/lvgl/src/core/lv_indev_scroll.c
2.sdk/Helios_SDK/services/microPython/lib/lvgl/src/hal/lv_hal_indev.h
2.sdk/Helios_SDK/services/microPython/ports/quectel/core/source/camera_capture.c
2.sdk/Helios_SDK/services/microPython/ports/quectel/core/source/modVideoCall_juphoon.c
2.sdk/project/K01/sdk/services/microPython/ports/quectel/core/ui.py

index 94a870b..8223694 100644 (file)
@@ -369,62 +369,62 @@ int  JPEG2RGB565(const char* jpeg_file, rgb_struct *rgb565, unsigned char* temp,
     return 0;
 }
 
+int rgb565_to_jpeg(const char* filename, int width, int height, uint_16* rgb565_data) {
+    HeliosFILE *fp = Helios_fopen(filename, "wb");
+    if (!fp) {
+        JPEG_LOG("Error opening output file");
+        return -1;
+    }
 
-
-
-//RGB 压缩成jpeg
-int RGB5652JPEG(const char* jpeg_file, unsigned char* rgb_buffer, int width, int height, int quality)
-{
     struct jpeg_compress_struct cinfo;
     struct jpeg_error_mgr jerr;
-    int row_stride = 0;
-    HeliosFILE* fp = NULL;
-    JSAMPROW row_pointer[1];
 
     cinfo.err = jpeg_std_error(&jerr);
-
     jpeg_create_compress(&cinfo);
-    fp = Helios_fopen(jpeg_file, "wb");
-    if (fp == NULL)
-    {
-        JPEG_LOG("open HeliosFILE %s failed.\n", jpeg_file);
-        return -1;
-    }
     jpeg_stdio_dest(&cinfo, fp);
+
     cinfo.image_width = width;
     cinfo.image_height = height;
-    cinfo.input_components = 3;
-    cinfo.in_color_space = JCS_RGB;//设置输入格式
-    cinfo.dct_method = JDCT_FLOAT;
+    cinfo.input_components = 3; // RGB图像
+    cinfo.in_color_space = JCS_RGB;
 
     jpeg_set_defaults(&cinfo);
-    jpeg_set_quality(&cinfo, quality, 1);  // todo 1 == true
+       jpeg_set_quality(&cinfo, 80, 1);  // todo 1 == true
     jpeg_start_compress(&cinfo, TRUE);
-    row_stride = width * cinfo.input_components;
 
-    while (cinfo.next_scanline < cinfo.image_height)
-    {
-        row_pointer[0] = &rgb_buffer[cinfo.next_scanline * row_stride];
+    JSAMPROW row_pointer[1];
+    uint8_t* row_buffer = malloc(3 * width);
+
+    while (cinfo.next_scanline < cinfo.image_height) {
+        int row = cinfo.next_scanline;
+
+        // 将RGB565数据转换为RGB888
+        for (int i = 0; i < width; ++i) {
+            uint16_t pixel = rgb565_data[row * width + i];
+            uint8_t r = ((pixel >> 11) & 0x1F) << 3;
+            uint8_t g = ((pixel >> 5) & 0x3F) << 2;
+            uint8_t b = (pixel & 0x1F) << 3;
+
+            row_buffer[i * 3] = r;
+            row_buffer[i * 3 + 1] = g;
+            row_buffer[i * 3 + 2] = b;
+        }
+
+        row_pointer[0] = row_buffer;
         jpeg_write_scanlines(&cinfo, row_pointer, 1);
     }
 
+    free(row_buffer);
+
     jpeg_finish_compress(&cinfo);
     jpeg_destroy_compress(&cinfo);
-       
     if(0 != Helios_fclose(fp)) {
                JPEG_LOG("fs close failed\n");
                return -1;
        }
-
-    return 0;
+       return 0;
 }
 
-
-
-
-
-
-
 int yuv420_NV12_to_jpg(char *filename, int img_width, int img_height, unsigned char *pYUVBuffer, int width, int height)
 {
        
@@ -578,3 +578,53 @@ int yuv422_UYVY_to_jpg(char *filename, int img_width, int img_height, unsigned c
 }
 
 
+int CamSWRgb565Rotate(uint_8 *des, uint_8 *src, int srcWidth, int srcHeight, int rotate)
+{
+    int n = 0;
+    int bitDepth = 2;
+    int i,j;
+    int pix = srcWidth*srcHeight;
+
+    if ( (!des) || (!src) || (pix <= 0) || (rotate > CAM_SW_ROTATE_270) )
+    {
+        return -1;
+    }
+
+    if (CAM_SW_ROTATE_90 == rotate)
+    {
+        for (j=0; j<srcWidth; j++)
+        {
+            for (i=srcHeight; i>0; i--)
+            {
+                memcpy(&des[n], &src[(srcWidth*(i-1) + j/* - 1*/)*bitDepth], bitDepth);
+                n += bitDepth;
+            }
+        }
+    }
+    else if (CAM_SW_ROTATE_180 == rotate)
+    {
+        for (i=0; i<pix; i++)
+        {
+            memcpy(&des[n], &src[(pix - i)*bitDepth], bitDepth);
+            n += bitDepth;
+        }
+    }
+    else if (CAM_SW_ROTATE_270 == rotate)
+    {
+        for (j=srcWidth; j>0; j--)
+        {
+            for (i=0; i<srcHeight; i++)
+            {
+                memcpy(&des[n], &src[(srcWidth*i + j - 1)*bitDepth], bitDepth);
+                n += bitDepth;
+            }
+        }
+    }
+    else /* if (CAM_SW_ROTATE_0 == rotate) */
+    {
+        memcpy(&des[0], &src[0], srcWidth*srcHeight*bitDepth);
+    }
+
+    return 0;
+}
+
index 184114d..b8aca91 100644 (file)
@@ -10,6 +10,10 @@ extern "C" {
 #define uint_8 unsigned char
 #define uint_16 unsigned short
 
+#define CAM_SW_ROTATE_0    (0)
+#define CAM_SW_ROTATE_90   (1)
+#define CAM_SW_ROTATE_180  (2)
+#define CAM_SW_ROTATE_270  (3)
 
 typedef struct _rgb_struct{
        int width;
@@ -22,8 +26,6 @@ void rgb5652bgr888(short *src, char *dest, int size);
 
 int  JPEG2RGB565(const char* jpeg_file, rgb_struct *rgb565, unsigned char* temp, unsigned short width_set, unsigned short height_set);
 
-int RGB5652JPEG(const char* jpeg_file, unsigned char* rgb_buffer, int width, int height, int quality);
-
 int yuv420_to_jpg(char *filename, int width, int height, unsigned char *pYUVBuffer);
 
 int yuv420_nv12_to_rgb565_zoom_out(uint_16 *pRgbData, uint_32 rgbWidth, uint_32 rgbHeight, uint_8 *pYuvData, uint_32 yuvWidth, uint_32 yuvHeight);
@@ -34,6 +36,9 @@ int yuv420_NV12_to_jpg(char *filename, int img_width, int img_height, unsigned c
 
 int yuv422_UYVY_to_jpg(char *filename, int img_width, int img_height, unsigned char *pYUVBuffer, int width, int height);
 
+int CamSWRgb565Rotate(uint_8 *des, uint_8 *src, int srcWidth, int srcHeight, int rotate);
+
+int rgb565_to_jpeg(const char* filename, int width, int height, uint_16* rgb565_data);
 
 #ifdef __cplusplus
 }
index c7803c2..7ac09fd 100644 (file)
@@ -176,7 +176,11 @@ int Helios_SPI_LCD_Brightness(uint32_t light_level);
 #ifdef __cplusplus
  } /*"C" */
 #endif
- 
+#if 0
+extern int is_first_make_new ;
+#else
+//int is_first_make_new ;
+#endif
 #endif
  
  
index e46fc58..1f69028 100644 (file)
 #define LV_DISP_DEF_REFR_PERIOD     30      /*[ms]*/
 
 /*Input device read period in milliseconds*/
-#define LV_INDEV_DEF_READ_PERIOD    30      /*[ms]*/
+#define LV_INDEV_DEF_READ_PERIOD    10      /*[ms]*/
 
 /*Use a custom tick source that tells the elapsed time in milliseconds.
  *It removes the need to manually update the tick with `lv_tick_inc()`)*/
index 8a36ab3..0e53557 100644 (file)
@@ -132,7 +132,6 @@ void _lv_indev_scroll_throw_handler(_lv_indev_proc_t * proc)
         if(align_y == LV_SCROLL_SNAP_NONE) {
             proc->types.pointer.scroll_throw_vect.y =
                 proc->types.pointer.scroll_throw_vect.y * (100 - scroll_throw) / 100;
-
             lv_coord_t sb = lv_obj_get_scroll_bottom(scroll_obj);
             lv_coord_t st = lv_obj_get_scroll_top(scroll_obj);
 
@@ -170,6 +169,16 @@ void _lv_indev_scroll_throw_handler(_lv_indev_proc_t * proc)
             lv_coord_t diff_x = scroll_throw_predict_x(proc);
             proc->types.pointer.scroll_throw_vect.x = 0;
             scroll_limit_diff(proc, &diff_x, NULL);
+            #if LV_INDEV_DEF_X_SLIDING_SPEED
+                if(diff_x>0)
+                {
+                    diff_x += LV_INDEV_DEF_X_SLIDING_SPEED;
+                }else if(diff_x<0)
+                {
+                    diff_x -= LV_INDEV_DEF_X_SLIDING_SPEED;
+                }
+            #endif
+            printf("_lv_indev_scroll_throw_handler:%d",diff_x);
             lv_coord_t x = find_snap_point_x(scroll_obj, LV_COORD_MIN, LV_COORD_MAX, diff_x);
             lv_obj_scroll_by(scroll_obj, x + diff_x, 0, LV_ANIM_ON);
         }
@@ -237,6 +246,7 @@ lv_coord_t lv_indev_scroll_throw_predict(lv_indev_t * indev, lv_dir_t dir)
 
     lv_coord_t scroll_throw = indev->driver->scroll_throw;
     lv_coord_t sum = 0;
+    
     while(v) {
         sum += v;
         v = v * (100 - scroll_throw) / 100;
index 450ad9c..48d5853 100644 (file)
@@ -30,8 +30,12 @@ extern "C" {
 #define LV_INDEV_DEF_SCROLL_LIMIT         10
 
 /*Drag throw slow-down in [%]. Greater value -> faster slow-down*/
-#define LV_INDEV_DEF_SCROLL_THROW         10
+#define LV_INDEV_DEF_SCROLL_THROW         2
 
+//x轴滑动补偿,值越大越快,尽量不超过分辨率的一半
+#if PROJECT_NAME_G3_K01 
+#define LV_INDEV_DEF_X_SLIDING_SPEED 50
+#endif
 /*Long press time in milliseconds.
  *Time to send `LV_EVENT_LONG_PRESSSED`)*/
 #define LV_INDEV_DEF_LONG_PRESS_TIME      400
index 4852001..7173329 100644 (file)
@@ -58,6 +58,7 @@ WHEN          WHO                     WHAT,WHERE,WHY
 const mp_obj_type_t camera_capture_type;
 
 static c_callback_t *callback_cur = NULL;
+void cam_decode(unsigned char* raw, int width, int height);
 
 typedef struct _preview_obj_t {
     mp_obj_base_t base;
@@ -100,7 +101,7 @@ typedef struct img_info_struct{
 
 static img_info_s image_info = {0};
 
-void Helios_SaveImage(unsigned char* pYUVBuffer, int width, int height) {
+void Helios_SaveImage(unsigned char* pBuffer, int width, int height) {
        int result = -1;
        char name[256] = {0};
 
@@ -108,14 +109,13 @@ void Helios_SaveImage(unsigned char* pYUVBuffer, int width, int height) {
        sprintf(name, "U:/%s.jpg",image_info.image_name);
        CAPTURE_LOG("SaveImage %d %d %d %d\n", width, height, image_info.img_width, image_info.img_height);
 
-       if(image_info.img_width <= width && image_info.img_height <= height && pYUVBuffer != NULL) {
+       if(image_info.img_width <= width && image_info.img_height <= height && pBuffer != NULL) {
                
 #if defined(PLAT_ASR) || defined(PLAT_ASR_1606) || defined(PLAT_ASR_1609) || defined(PLAT_ASR_1602)
-               if(0 != yuv420_NV12_to_jpg(name, image_info.img_width, image_info.img_height, pYUVBuffer, width, height))
+               if(0 != rgb565_to_jpeg(name, width, height, (uint16_t*)pBuffer))
 #elif defined(PLAT_Unisoc) || defined(PLAT_Unisoc_8910_R05)
-               if(0 != yuv422_UYVY_to_jpg(name, image_info.img_width, image_info.img_height, pYUVBuffer, width, height))
+               if(0 != yuv422_UYVY_to_jpg(name, image_info.img_width, image_info.img_height, pBuffer, width, height))
 #else
-               // error("Helios_SaveImage:Uncertain picture format");
                CAPTURE_LOG("Helios_SaveImage:Uncertain picture format\n");
 #endif
                {
@@ -200,7 +200,6 @@ STATIC mp_obj_t caputre_make_new(const mp_obj_type_t *type, size_t n_args, size_
        camconfig.lcdpreheight = lcdpreheight;
        camconfig.lcdprewidth = lcdprewidth;
        camconfig.prebufcnt = prebufcnt;
-       camconfig.saveimg_pro = Helios_SaveImage;
        camconfig.decbufcnt = 1;
        camconfig.preview = 1;
        
@@ -217,18 +216,28 @@ STATIC mp_obj_t caputre_make_new(const mp_obj_type_t *type, size_t n_args, size_
 
 
 /****************************add by elian.wang**************************/
-#if MICROPY_QPY_CAMERA_LVGL_PREVIEW
+
 static Helios_MsgQ_t get_picture_q = 0;
 static Helios_Thread_t rgb565_decode_task_id = 0;
 uint16_t rgb_buffer[128*128] = {0};
+#if MICROPY_QPY_CAMERA_LVGL_PREVIEW
 lv_obj_t *camera_img = NULL;
+int open_capture = 0;
+#endif
 
-
-
+char CAM_rotate = 1;  
+STATIC mp_obj_t camera_set_rotate(mp_obj_t self_in,mp_obj_t val1)
+{
+       preview_obj_t *self  = MP_OBJ_TO_PTR(self_in);
+       CAM_rotate = mp_obj_get_int(val1);
+    return mp_obj_new_int(1);
+}
+STATIC MP_DEFINE_CONST_FUN_OBJ_2(camera_set_rotate_obj, camera_set_rotate);
 lv_img_dsc_t camera_img_dsc;
 void rgb565_decode_handle(void * argv) {
     uint8_t *buff_addr = NULL;
     int ret = -1;
+       uint8_t * rgb_buffer_tmp = NULL;
 
     while (1) {
         ret = Helios_MsgQ_Get(get_picture_q, (void *)&buff_addr, sizeof(uint32_t), HELIOS_WAIT_FOREVER);
@@ -238,12 +247,46 @@ void rgb565_decode_handle(void * argv) {
                        continue;
                }
 
-               if (camera_img == NULL) {
+               rgb_buffer_tmp = (uint8_t *)malloc(128*128*2);
+               if (rgb_buffer_tmp == NULL) {
+                       CAPTURE_LOG("rgb_buffer_tmp malloc fail\n");
                        continue;
                }
-               CAPTURE_LOG("get get_picture_q !!!\n");
-               yuv420_nv12_to_rgb565_zoom_out((uint16_t*)rgb_buffer, camconfig.lcdprewidth, camconfig.lcdpreheight, (unsigned char *)buff_addr, camconfig.camwidth, camconfig.camheight);
+               yuv420_nv12_to_rgb565_zoom_out((uint16_t*)rgb_buffer_tmp, camconfig.lcdprewidth, camconfig.lcdpreheight, (unsigned char *)buff_addr, camconfig.camwidth, camconfig.camheight);
+               if( CAM_rotate == 0)
+               {
+                       CamSWRgb565Rotate((uint8_t*)rgb_buffer, rgb_buffer_tmp, 128, 128, CAM_SW_ROTATE_0);
+               }else if( CAM_rotate == 1)
+               {
+                       CamSWRgb565Rotate((uint8_t*)rgb_buffer, rgb_buffer_tmp, 128, 128, CAM_SW_ROTATE_90);
+               }else if( CAM_rotate == 2)
+               {
+                       CamSWRgb565Rotate((uint8_t*)rgb_buffer, rgb_buffer_tmp, 128, 128, CAM_SW_ROTATE_180);
+               }else if( CAM_rotate == 3)
+               {
+                       CamSWRgb565Rotate((uint8_t*)rgb_buffer, rgb_buffer_tmp, 128, 128, CAM_SW_ROTATE_270);
+               }
+               else
+               {
+                       // 旋转90°
+                       CamSWRgb565Rotate((uint8_t*)rgb_buffer, rgb_buffer_tmp, 128, 128, CAM_SW_ROTATE_90);
+               }
+               
+               free(rgb_buffer_tmp);
+               rgb_buffer_tmp = NULL;
+#if MICROPY_QPY_CAMERA_LVGL_PREVIEW
+               if (open_capture) {
+                       Helios_SaveImage((uint8_t*)rgb_buffer, 128, 128);
+                       open_capture = 0;
+               }
+#else
+               Helios_SaveImage((uint8_t*)rgb_buffer, 128, 128);
+#endif
 
+#if MICROPY_QPY_CAMERA_LVGL_PREVIEW
+               if (camera_img == NULL) {
+                       continue;
+               }
                camera_img_dsc.header.always_zero = 0;
                camera_img_dsc.header.w = camconfig.lcdprewidth;
                camera_img_dsc.header.h = camconfig.lcdpreheight;
@@ -251,16 +294,19 @@ void rgb565_decode_handle(void * argv) {
                camera_img_dsc.header.cf = LV_IMG_CF_TRUE_COLOR;
                camera_img_dsc.data = (uint8_t *)rgb_buffer;
                lv_img_set_src(camera_img, &camera_img_dsc);
+#endif
+
+
+
        }
 }
 
  void cam_decode(unsigned char* raw, int width, int height) {
        Helios_MsgQ_Put(get_picture_q, (const void *)&raw, sizeof(uint32_t), HELIOS_NO_WAIT);
-       CAPTURE_LOG("send get_picture_q !!!\n");
  }
 
 
-
+#if MICROPY_QPY_CAMERA_LVGL_PREVIEW
 typedef struct mp_lv_obj_t {
     mp_obj_base_t base;
     lv_obj_t *lv_obj;
@@ -315,6 +361,8 @@ STATIC mp_obj_t camera_open(mp_obj_t self_in)
 #if MICROPY_QPY_CAMERA_LVGL_PREVIEW
        camconfig.preview = 0;
        camconfig.decode_pro = cam_decode;
+#else
+       camconfig.saveimg_pro = cam_decode;
 #endif
        preview_obj_t *self = MP_OBJ_TO_PTR(self_in);
        CAPTURE_LOG("open %d,%d,%d,%d,%d\n",camconfig.camheight,camconfig.camwidth,camconfig.lcdpreheight,camconfig.lcdprewidth,camconfig.prebufcnt);
@@ -405,9 +453,13 @@ STATIC mp_obj_t camera_capture_start(size_t n_args, const mp_obj_t *pos_args, mp
        memcpy(image_info.image_name, picname, strlen(picname));
 
        CAPTURE_LOG("capture para %d,%d,%s\n",image_w,image_h,picname);
-
+#if MICROPY_QPY_CAMERA_LVGL_PREVIEW
+       open_capture = 1;
+       return mp_obj_new_int(1);
+#else
        int ret = Helios_camera_capture();
        return mp_obj_new_int(ret);
+#endif
     
 }
 STATIC MP_DEFINE_CONST_FUN_OBJ_KW(camera_capture_start_obj,1, camera_capture_start);
@@ -445,6 +497,8 @@ STATIC const mp_rom_map_elem_t Preview_locals_dict_table[] = {
     { MP_ROM_QSTR(MP_QSTR_close), MP_ROM_PTR(&camera_capture_close_obj) },
     { MP_ROM_QSTR(MP_QSTR_start), MP_ROM_PTR(&camera_capture_start_obj) },
        { MP_ROM_QSTR(MP_QSTR_callback), MP_ROM_PTR(&camera_capture_callback_obj) },
+       { MP_ROM_QSTR(MP_QSTR_set_rotate), MP_ROM_PTR(&camera_set_rotate_obj) },
+       
 #if MICROPY_QPY_CAMERA_LVGL_PREVIEW
        {MP_ROM_QSTR(MP_QSTR_set_img), MP_ROM_PTR(&set_img_obj)},
     {MP_ROM_QSTR(MP_QSTR_remove_img), MP_ROM_PTR(&remove_img_obj)},
index 7f419b4..d2026d8 100644 (file)
@@ -311,6 +311,14 @@ STATIC mp_obj_t mp_jrtc_config (size_t n_args, const mp_obj_t *args, mp_map_t *k
 }
 STATIC MP_DEFINE_CONST_FUN_OBJ_KW(mp_jrtc_config_obj, 4 ,mp_jrtc_config);
 
+ 
+STATIC mp_obj_t mp_jrtc_set_rotate(mp_obj_t val1)
+{
+       //HX3918_obj_t *self = MP_OBJ_TO_PTR(self_in);
+       _jrtc_cam_angle = mp_obj_get_int(val1);
+    return mp_obj_new_int(1);
+}
+STATIC MP_DEFINE_CONST_FUN_OBJ_1(mp_jrtc_set_rotate_obj, mp_jrtc_set_rotate);
 
 STATIC mp_obj_t mp_jrtc_open (size_t n_args, const mp_obj_t *args, mp_map_t *kw_args)
 {
@@ -409,6 +417,7 @@ STATIC const mp_rom_map_elem_t jrtc_globals_table[] = {
     {MP_ROM_QSTR(MP_QSTR_set_img), MP_ROM_PTR(&set_img_obj)},
     {MP_ROM_QSTR(MP_QSTR_remove_img), MP_ROM_PTR(&remove_img_obj)},
     {MP_ROM_QSTR(MP_QSTR_get_state), MP_ROM_PTR(&mp_jrtc_get_state_obj)},
+    {MP_ROM_QSTR(MP_QSTR_set_rotate), MP_ROM_PTR(&mp_jrtc_set_rotate_obj)},
 };
 
 /* 把modjrtc_globals_table注册到 mp_module_modjrtc_globals里面去 */
index 242220d..af78ed2 100644 (file)
@@ -7603,6 +7603,7 @@ class cameraScreen(Screen):#相机拍照二级界面
         global camera_popup_screen ,camera_popup_label
         
         state = dec.open()
+        dec.set_rotate(1)
         if camera_popup_screen == None:
             camera_popup_screen = lv.obj()
             print("Lowpower_screen")
@@ -8146,6 +8147,7 @@ class VedioShowScreen(Screen):#正在视频通话中
         ticket = str(meet_id)
         
         print("uid ",uid,ticket,tokens)
+        #jrtc.set_rotate(0)
         jrtc.open(uid,ticket,[15,120,240,320],[15,129,128,128])
         
         pass