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)
{
}
+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;
+}
+
#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;
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);
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
}
#ifdef __cplusplus
} /*"C" */
#endif
-
+#if 0
+extern int is_first_make_new ;
+#else
+//int is_first_make_new ;
+#endif
#endif
#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()`)*/
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);
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);
}
lv_coord_t scroll_throw = indev->driver->scroll_throw;
lv_coord_t sum = 0;
+
while(v) {
sum += v;
v = v * (100 - scroll_throw) / 100;
#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
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;
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};
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
{
camconfig.lcdpreheight = lcdpreheight;
camconfig.lcdprewidth = lcdprewidth;
camconfig.prebufcnt = prebufcnt;
- camconfig.saveimg_pro = Helios_SaveImage;
camconfig.decbufcnt = 1;
camconfig.preview = 1;
/****************************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);
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;
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;
#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);
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);
{ 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)},
}
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)
{
{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里面去 */
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")
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