From 6809f6646aa4f5bf165d60261ee391bfe2ab5b52 Mon Sep 17 00:00:00 2001 From: payton Date: Mon, 4 Dec 2023 14:30:36 +0800 Subject: [PATCH] =?UTF-8?q?1.Linux=E4=BF=AE=E6=94=B9=EF=BC=9A=E8=A7=86?= =?UTF-8?q?=E9=A2=91=E6=B0=B4=E5=8D=B0=E6=94=B9=E4=B8=BA=E4=B8=8E=E5=9B=BE?= =?UTF-8?q?=E7=89=87=E6=B0=B4=E5=8D=B0=E4=B8=80=E6=A0=B7=EF=BC=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cardv/SrcCode/PrjCfg_HUNTING_S550.h | 3 +- .../SrcCode/UIApp/MovieStamp/MovieStamp.c | 361 +++++++++++++++++- .../lv_user_font_conv/lv_user_font_conv.c | 5 +- 3 files changed, 361 insertions(+), 8 deletions(-) diff --git a/code/application/source/cardv/SrcCode/PrjCfg_HUNTING_S550.h b/code/application/source/cardv/SrcCode/PrjCfg_HUNTING_S550.h index 35159d3c1..a3673210e 100755 --- a/code/application/source/cardv/SrcCode/PrjCfg_HUNTING_S550.h +++ b/code/application/source/cardv/SrcCode/PrjCfg_HUNTING_S550.h @@ -1052,8 +1052,9 @@ /* please always fill ARGB8888, alpha channel will be discarded if output format is yuv (Photo UIDateImprint) */ #define LV_USER_CFG_STAMP_COLOR_TEXT 0xFFFFFFFF /* text color */ #define LV_USER_CFG_STAMP_COLOR_BACKGROUND 0XFF000000 /* background color: black */ -#define LV_USER_CFG_MOVIE_DATESTAMP_COLOR_BACKGROUND 0X00000000 /* background color: none */ +#define LV_USER_CFG_MOVIE_DATESTAMP_COLOR_BACKGROUND 0XFF000000 /* background color: none */ #define LV_USER_CFG_STAMP_COLOR_FRAME 0x00000000 /* frame color */ +#define LV_USER_CFG_MOVIE_STAMP_COLOR_BACKGROUND 0XF000 /* background color: black */ /******************************************************************************************* * Enable LVGL rotate depend on VDO_USE_ROTATE_BUFFER (LV_USE_GPU_NVT_DMA2D in the lv_conf.h should be enabled) diff --git a/code/application/source/cardv/SrcCode/UIApp/MovieStamp/MovieStamp.c b/code/application/source/cardv/SrcCode/UIApp/MovieStamp/MovieStamp.c index 192681cdf..06098bcc9 100755 --- a/code/application/source/cardv/SrcCode/UIApp/MovieStamp/MovieStamp.c +++ b/code/application/source/cardv/SrcCode/UIApp/MovieStamp/MovieStamp.c @@ -18,6 +18,8 @@ #include "ImageApp/ImageApp_MovieMulti.h" #include "vf_gfx.h" #include "GxTime.h" +#include "sf_common.h" +#include "UIApp/Photo/UIDateImprint.h" #if MOVIE_ISP_LOG #include "vendor_isp.h" @@ -132,6 +134,7 @@ static WATERLOGO_BUFFER g_sMultiWaterLogo[VIDEO_IN_MAX][MOVIE_MULTI_WATERLOG #define LV_USER_FONT_CONV_ALIGN_W 8 #define LV_USER_FONT_CONV_ALIGN_H 2 +#define LV_USER_ICON_CONV_ALIGN_W 2 static inline uint32_t lv_color4444_to32(lv_user_color4444_t color) { @@ -534,7 +537,11 @@ void MovieStamp_Setup(UINT32 uiVEncOutPortId, UINT32 uiFlag, UINT32 uiImageWidth // break; // } - if (uiImageWidth >= 4608) + if(uiImageWidth >= 5632) + { + red_id = LV_USER_CFG_STAMP_FONT_ID_24M; + } + else if(uiImageWidth >= 4608) { red_id = LV_USER_CFG_STAMP_FONT_ID_16M; } @@ -1002,15 +1009,289 @@ UINT32 MovieStamp_CalcBufSize(UINT32 Width, UINT32 Height, WATERLOGO_BUFFER *pWa return BufSize; } +/* YUV color key */ +#define CKEY_Y 0x0 +#define CKEY_U 0x88 +#define CKEY_V 0x88 + +void MovieStamp_SelStampFont(UINT32 uiImageWidth, lv_font_t** font) +{ + lv_plugin_res_id red_id; + + if(uiImageWidth >= 5632) + { + red_id = LV_USER_CFG_STAMP_FONT_ID_24M; + } + else if(uiImageWidth >= 4608) + { + red_id = LV_USER_CFG_STAMP_FONT_ID_16M; + } + else if(uiImageWidth >= 4032) + { + red_id = LV_USER_CFG_STAMP_FONT_ID_12M; + } + else if(uiImageWidth >= 3264) + { + red_id = LV_USER_CFG_STAMP_FONT_ID_8M; + } + else if(uiImageWidth >= 1920) + { + red_id = LV_USER_CFG_STAMP_FONT_ID_LARGE; + } + else if(uiImageWidth >= 1080) + { + red_id = LV_USER_CFG_STAMP_FONT_ID_MEDIUM; + } + else if(uiImageWidth >= 1024) + { + red_id = LV_USER_CFG_STAMP_FONT_ID_SMALL_PIC; + } + else if(uiImageWidth >= 640) + { + red_id = LV_USER_CFG_STAMP_FONT_ID_SMALL; + } + else + { + red_id = LV_USER_CFG_STAMP_FONT_ID_XS; + } + + //printf("[%s:%d]uiImageWidth=%d,red_id=%d\n", __FUNCTION__, __LINE__, uiImageWidth, red_id); + + *font = (lv_font_t*)lv_plugin_get_font(red_id)->font; +} + +void MovieStamp_AttachString( + UINT32 stamp_height, + HD_VIDEO_FRAME* Img, + char* name, + lv_font_t* font, + bool enable_ckey, + UINT32 padding, + UINT32* x_curr_ofs) +{ + VF_GFX_SCALE param_img = {0}; + HD_VIDEO_FRAME src_img; + HD_VIDEO_PXLFMT out_fmt = HD_VIDEO_PXLFMT_ARGB4444; + void *va; + UINT32 pa; + HD_RESULT ret; + HD_COMMON_MEM_DDR_ID ddr_id = DDR_ID0; + + /****************************************************************************** + * Stamp image + ******************************************************************************/ + lv_user_font_conv_draw_cfg draw_cfg = {0}; + lv_user_font_conv_calc_buffer_size_result buff_size = {0}; + lv_user_font_conv_mem_cfg mem_cfg = {0}; + lv_color32_t color32; + + draw_cfg.align_w = LV_USER_FONT_CONV_ALIGN_W; + draw_cfg.align_h = LV_USER_FONT_CONV_ALIGN_H; + draw_cfg.fmt = out_fmt; + draw_cfg.mode = LV_USER_FONT_CONV_DRAW_TEXT; + draw_cfg.radius = LV_USER_CFG_STAMP_RADIUS; + draw_cfg.string.letter_space = LV_USER_CFG_STAMP_LETTER_SPACE; + draw_cfg.string.align = LV_USER_CFG_STAMP_TEXT_ALIGN; + draw_cfg.string.text = name; + draw_cfg.string.font = font; + + draw_cfg.ext_w = LV_USER_CFG_STAMP_EXT_WIDTH; + draw_cfg.ext_h = LV_USER_CFG_STAMP_EXT_HEIGHT; + draw_cfg.border.width = LV_USER_CFG_STAMP_BORDER_WIDTH; + + /* text color */ + color32.full = LV_USER_CFG_STAMP_COLOR_TEXT; + draw_cfg.string.color = LV_COLOR_MAKE(color32.ch.red, color32.ch.green, color32.ch.blue); + draw_cfg.string.opa = LV_COLOR_GET_A32(color32); + + /* bg color */ + color32.full = LV_USER_CFG_STAMP_COLOR_BACKGROUND; + draw_cfg.bg.color = LV_COLOR_MAKE(color32.ch.red, color32.ch.green, color32.ch.blue); + draw_cfg.bg.opa = LV_COLOR_GET_A32(color32); + + /* border color */ + color32.full = LV_USER_CFG_STAMP_COLOR_FRAME; + draw_cfg.border.color = LV_COLOR_MAKE(color32.ch.red, color32.ch.green, color32.ch.blue); + draw_cfg.border.opa = LV_COLOR_GET_A32(color32); + draw_cfg.border.width = LV_USER_CFG_STAMP_BORDER_WIDTH; + + draw_cfg.enable_ckey = enable_ckey; + draw_cfg.key_y = CKEY_Y; + draw_cfg.key_u = CKEY_U; + draw_cfg.key_v = CKEY_V; + lv_user_font_conv_calc_buffer_size(&draw_cfg, &buff_size); + + ret = hd_common_mem_alloc("stamp_string", &pa, (void **)&va, buff_size.output_buffer_size, ddr_id); + if (ret != HD_OK) { + DBG_ERR("custom_stamp_buffer allocate failed\n\r"); + } + else { + mem_cfg.output_buffer = va; + mem_cfg.output_buffer_size = buff_size.output_buffer_size; + } + + lv_user_font_conv(&draw_cfg, &mem_cfg); + lv_user_font_conv_cfg_to_hd_frame( + &draw_cfg, + &mem_cfg, + buff_size.width, + buff_size.height, + &src_img + ); + + memset(¶m_img, 0, sizeof(param_img)); + param_img.quality = HD_GFX_SCALE_QUALITY_NULL; + param_img.src_img = src_img; + param_img.src_region.x = 0; + param_img.src_region.y = 0; + param_img.src_region.w = src_img.dim.w; + param_img.src_region.h = src_img.dim.h; + param_img.engine = 0; + param_img.dst_img = *Img; + param_img.dst_region.w = (src_img.dim.w / src_img.dim.h) * stamp_height; + param_img.dst_region.h = stamp_height; + param_img.dst_region.x = (*x_curr_ofs - padding - param_img.dst_region.w); + param_img.dst_region.y = param_img.dst_img.dim.h - param_img.dst_region.h; + vf_gfx_scale(¶m_img, 1); + + *x_curr_ofs = param_img.dst_region.x; + hd_common_mem_free(pa, va); +} + +void MovieStamp_AttachICON( + UINT32 stamp_height, + UINT32 stamp_pos_y, + HD_VIDEO_FRAME* Img, + lv_plugin_res_id res_id, + bool enable_ckey, + UINT32 padding, + UINT32* x_curr_ofs) +{ + HD_VIDEO_PXLFMT out_fmt = HD_VIDEO_PXLFMT_ARGB4444; + HD_VIDEO_FRAME src_img; + void *va; + UINT32 pa; + HD_RESULT ret; + HD_COMMON_MEM_DDR_ID ddr_id = DDR_ID0; + + /****************************************************************************** + * Stamp image + ******************************************************************************/ + + lv_user_font_conv_draw_cfg draw_cfg = {0}; + lv_user_font_conv_calc_buffer_size_result buff_size = {0}; + lv_user_font_conv_mem_cfg mem_cfg = {0}; + + lv_user_font_conv_draw_cfg_init(&draw_cfg); + + draw_cfg.align_w = LV_USER_ICON_CONV_ALIGN_W; + draw_cfg.align_h = LV_USER_FONT_CONV_ALIGN_H; + draw_cfg.fmt = out_fmt; + draw_cfg.mode = LV_USER_FONT_CONV_DRAW_IMG; +#if LV_COLOR_DEPTH == 8 + extern uint32_t palette_define[]; + draw_cfg.img.palette = palette_define; +#else + draw_cfg.img.palette = NULL; +#endif + draw_cfg.img.id = res_id; + + draw_cfg.enable_ckey = enable_ckey; + draw_cfg.key_y = CKEY_Y; + draw_cfg.key_u = CKEY_U; + draw_cfg.key_v = CKEY_V; + + lv_user_font_conv_calc_buffer_size(&draw_cfg, &buff_size); + + ret = hd_common_mem_alloc("stamp_icon", &pa, (void **)&va, buff_size.output_buffer_size, ddr_id); + if (ret != HD_OK) { + DBG_ERR("custom_stamp_buffer allocate failed\n\r"); + } + else { + mem_cfg.output_buffer = va; + mem_cfg.output_buffer_size = buff_size.output_buffer_size; + } + + /*********************************************************** + * draw image + **********************************************************/ + + VF_GFX_SCALE param_img = {0}; + + lv_user_font_conv(&draw_cfg, &mem_cfg); + + lv_user_font_conv_cfg_to_hd_frame( + &draw_cfg, + &mem_cfg, + buff_size.width, + buff_size.height, + &src_img + ); + + hd_common_mem_flush_cache(mem_cfg.output_buffer, mem_cfg.output_buffer_size); + + memset(¶m_img, 0, sizeof(param_img)); + param_img.quality = HD_GFX_SCALE_QUALITY_NULL; + param_img.src_img = src_img; + param_img.src_region.x = 0; + param_img.src_region.y = 0; + param_img.src_region.w = src_img.dim.w; + param_img.src_region.h = src_img.dim.h; + param_img.engine = 0; + param_img.dst_img = *Img; + param_img.dst_region.w = (src_img.dim.w * stamp_height/ src_img.dim.h); + param_img.dst_region.h = stamp_height; + param_img.dst_region.x = (*x_curr_ofs - padding - param_img.dst_region.w); + param_img.dst_region.y = stamp_pos_y; + vf_gfx_scale(¶m_img, 1); + hd_common_mem_free(pa, va); + + *x_curr_ofs = param_img.dst_region.x; +} + +void sf_get_movie_resolution_ratio_str(char *movieRatioStr) +{ + UIMenuStoreInfo *puiPara = sf_ui_para_get(); + + if(puiPara->VideoSize == MOVIE_SIZE_FRONT_1920x1080P30) + { + sprintf((char *)movieRatioStr, "1080P"); + } + else if(puiPara->VideoSize == MOVIE_SIZE_FRONT_1280x720P30) + { + sprintf((char *)movieRatioStr, "720P"); + } + else if(puiPara->VideoSize == MOVIE_SIZE_FRONT_848x480P30) + { + sprintf((char *)movieRatioStr, "WVGA"); + } + else + { + sprintf((char *)movieRatioStr, "WVGA"); + } +} + void MovieStamp_CombineStamp(UINT32 vid_in, UINT32 bg_color) { UINT32 size; UINT32 combined_stamp_w = g_ImageSize[vid_in].w; UINT32 combined_stamp_h = g_VsOsdHight[vid_in]; + UINT32 combined_stamp_pos_y = 0; size = combined_stamp_w * combined_stamp_h * 2; /* ARGB4444 */ HD_COMMON_MEM_VIRT_INFO vir_info = {0}; + UINT32 padding = 20; + UINT32 x_curr_ofs = 0; /* start from date stamp */ + HD_VIDEO_FRAME Img = {0}; + UINT32 lineoff[HD_VIDEO_MAX_PLANE] = {0}; + UINT32 addr[HD_VIDEO_MAX_PLANE] = {0}; char name[16]; + INT16 cTemper = 0; + INT16 fTemper = 0; + char customString[32] = {0}; + INT32 year = 0, month = 0, day = 0; + UINT8 moonday = 0; + UINT8 batValue = 0; sprintf(name, "mov_stamp%lu", vid_in); @@ -1025,7 +1306,11 @@ void MovieStamp_CombineStamp(UINT32 vid_in, UINT32 bg_color) memset((void *)combined_stamp_addr[vid_in].pool_va, 0, size); - /* draw bg */ + lineoff[0] = combined_stamp_w * 2; + addr[0] = combined_stamp_addr[vid_in].pool_pa; + vf_init_ex(&Img, combined_stamp_w, combined_stamp_h, HD_VIDEO_PXLFMT_ARGB4444, lineoff, addr); + + //draw stamp background. HD_GFX_DRAW_RECT rect = {0}; rect.color = bg_color; @@ -1039,7 +1324,7 @@ void MovieStamp_CombineStamp(UINT32 vid_in, UINT32 bg_color) rect.dst_img.p_phy_addr[0] = combined_stamp_addr[vid_in].pool_pa; /* argb4444 accept virtual address */ hd_gfx_draw_rect(&rect); - /* copy date stamp to bg */ + /*date stamp*/ HD_GFX_COPY copy = {0}; copy.alpha = 255; copy.colorkey = 0; @@ -1061,7 +1346,7 @@ void MovieStamp_CombineStamp(UINT32 vid_in, UINT32 bg_color) copy.src_region = (HD_IRECT) {0, 0, copy.src_img.dim.w, copy.src_img.dim.h}; hd_gfx_copy(©); - /* copy water logo to bg */ + /*water logo*/ UINT32 water_size = g_MovieWaterInfo[vid_in].uiWidth * g_MovieWaterInfo[vid_in].uiHeight * 2; if(water_logo_addr[vid_in].pool_va == 0){ @@ -1096,6 +1381,72 @@ void MovieStamp_CombineStamp(UINT32 vid_in, UINT32 bg_color) scale.dst_region.y = 0; hd_gfx_scale(&scale); + x_curr_ofs = combined_stamp_w - g_VsFontOut[vid_in].GenImg.dim.w; + + /*temperature stamp*/ + lv_font_t* font = NULL; + MovieStamp_SelStampFont(combined_stamp_w, &font); + sf_stamp_temperature_get(&fTemper, &cTemper); + snprintf((char *)customString, sizeof(customString), "%d%c%cF %d%c%cC", fTemper, 0xC2, 0xB0, cTemper, 0xC2, 0xB0); + //printf("[%s:%d]customString=%s\n", __FUNCTION__, __LINE__, customString); + MovieStamp_AttachString(combined_stamp_h, &Img, customString, font, false, padding, &x_curr_ofs); + + /*moon stamp*/ + year = DateTime_Get(DATETIME_YEAR); + month = DateTime_Get(DATETIME_MONTH); + day = DateTime_Get(DATETIME_DAY); + //printf("[%s:%d]get date time:%04d %02d %02d\n", __FUNCTION__, __LINE__, year, month, day); + moonday = (sf_solar_to_Lunar(year, month, day)) - 1; + MovieStamp_AttachICON(combined_stamp_h, combined_stamp_pos_y, &Img, LV_PLUGIN_IMG_ID_ICON_10200_MOON + moonday, false, padding, &x_curr_ofs); + + //battery stamp + batValue = sf_cardv_battery_level_get(); + if(batValue < SF_BATT_LEVEL_1) + { + batValue = 1; + } + else + { + batValue -= 1; + } + + MovieStamp_AttachICON( + combined_stamp_h, + combined_stamp_pos_y, + &Img, + LV_PLUGIN_IMG_ID_ICON_10230_BATTERT + batValue, + false, + padding, + &x_curr_ofs); + + /*printf("[%s:%d]moon id=%d,battery id=%d\n", __FUNCTION__, __LINE__, + (LV_PLUGIN_IMG_ID_ICON_10200_MOON + moonday), (LV_PLUGIN_IMG_ID_ICON_10230_BATTERT + batValue));*/ + + //ratio stamp + //sf_get_movie_resolution_ratio_str(customString); + //printf("[%s:%d]customString=%s\n", __FUNCTION__, __LINE__, customString); + //MovieStamp_AttachString(combined_stamp_h, &Img, customString, font, false, padding, &x_curr_ofs); + + //gps stamp + //sprintf((char *)puiPara->Latitude, "3458.3100N"); + //sprintf((char *)puiPara->Longitude, "12294.4200E"); + // sf_get_gps_info_str((UINT8*)customString, 1); + // if((puiPara->GpsSwitch == SF_ON) && (customString[0] != '\0')) + // { + // //snprintf((char *)customString, sizeof(customString), "N22%c%c34'57\" E113%c%c55'19\"", 0xC2, 0xB0, 0xC2, 0xB0); + // //printf("[%s:%d]customString=%s\n", __FUNCTION__, __LINE__, customString); + // MovieStamp_AttachString(combined_stamp_h, &Img, customString, font, false, padding, &x_curr_ofs); + + // MovieStamp_AttachICON( + // combined_stamp_h, + // combined_stamp_pos_y, + // &Img, + // LV_PLUGIN_IMG_ID_ICON_10235_GPS, + // false, + // padding, + // &x_curr_ofs); + // } + hd_common_mem_flush_cache((void *)combined_stamp_addr[vid_in].pool_va, size); } @@ -1216,7 +1567,7 @@ void MovieStamp_UpdateData(void) //DBG_DUMP("i=%d, w=%d, %d, %d\r\n", i,g_VsOsdWidth[i], g_VsOsdHight[i],g_VsFontOut[i].GenImg.loff[0]); //MovieStamp_VsUpdateOsd(i, TRUE, 1, g_MovieStampPos[i].uiX, g_MovieStampPos[i].uiY, g_VsOsdWidth[i], g_VsOsdHight[i], (void*)g_pVsFontDataAddr[i]); - MovieStamp_CombineStamp(i, 0x0); + MovieStamp_CombineStamp(i, LV_USER_CFG_MOVIE_STAMP_COLOR_BACKGROUND); // update 1st stamp // if(MovieStamp_VsUpdateOsd(g_VEncHDPathId[i], TRUE, MOVIE_STAMP_LAYER1, VS_DATESTAMP_REGION, g_MovieStampPos[i].uiX, g_MovieStampPos[i].uiY, g_VsOsdWidth[i], g_VsOsdHight[i], (void*)g_pVsFontDataAddr[i])){ diff --git a/code/application/source/cardv/SrcCode/UIApp/lv_user_font_conv/lv_user_font_conv.c b/code/application/source/cardv/SrcCode/UIApp/lv_user_font_conv/lv_user_font_conv.c index 92e7fe7ae..0616812bb 100755 --- a/code/application/source/cardv/SrcCode/UIApp/lv_user_font_conv/lv_user_font_conv.c +++ b/code/application/source/cardv/SrcCode/UIApp/lv_user_font_conv/lv_user_font_conv.c @@ -481,7 +481,7 @@ ER lv_user_font_conv_cfg_to_hd_frame( switch(cfg->fmt) { case HD_VIDEO_PXLFMT_ARGB4444: - loff[0] = (width * height * HD_VIDEO_PXLFMT_BPP(cfg->fmt)) / 8; + loff[0] = width * 2; loff[1] = 0; break; @@ -609,7 +609,7 @@ ER lv_user_font_conv( } if(mem_cfg->output_buffer_size < result.output_buffer_size){ - DBG_ERR("output buffer size(%lx) not enough!\r\n"); + DBG_ERR("output buffer size(%lx) not enough(%lx needed)!\r\n", mem_cfg->output_buffer_size, result.output_buffer_size); return -1; } @@ -656,6 +656,7 @@ ER lv_user_font_conv( lv_obj_t* canvas = lv_canvas_create(NULL, NULL); /* if img_dsc.header.cf = LV_IMG_CF_TRUE_COLOR_CHROMA_KEYED , canvas will output alpha channel = 0 for pixel which color is LV_COLOR_TRANSP */ + lv_img_cache_invalidate_src(NULL); lv_canvas_set_buffer(canvas, working_buffer, result.width, result.height, LV_IMG_CF_TRUE_COLOR_ALPHA); draw_img_dsc = _lv_user_font_conv_get_draw_img_dsc(draw_cfg);