2066
- 收藏
- 点赞
- 分享
- 举报
关于freetype在rgn在做OSD的问题。
本帖最后由 490428261 于 2020-3-17 21:47 编辑
各位前辈小弟用freeType加载字库在rgn canvas上面打点的方式做OSD,但是发现做出来的效果有隔一行一行的。同样的方法在framebuffer上面没问题,请问这是怎么回事呢。下面是代码
[code]void showString(const OSDTTF_st *_pstOsdTTF, uint32_t _u32Color)
{
RGN_CANVAS_INFO_S stCanvasInfo;
/* 1.get current osd info */
HI_S32 s32Ret = HI_MPI_RGN_GetCanvasInfo(m_rgnHandle, &stCanvasInfo);
if (HI_SUCCESS != s32Ret)
{
printf("HI_MPI_RGN_GetCanvasInfo fail! s32Ret: 0x%x.\n", s32Ret);
return ;
}
// printf("%d %d %d\n", stCanvasInfo.stSize.u32Width, stCanvasInfo.stSize.u32Height, stCanvasInfo.u32Stride);
// 这里 stCanvasInfo.stSize.u32Width = 360; stCanvasInfo.stSize.u32Height = 100; stCanvasInfo.u32Stride=768;
HI_U32 *pen = (HI_U32 *)stCanvasInfo.u32VirtAddr;
memset(pen, 0, stCanvasInfo.u32Stride * stCanvasInfo.stSize.u32Height);
#if 0
uint16_t *ptr = (uint16_t *)stCanvasInfo.u32VirtAddr;
for (uint32_t i = 0; i< stCanvasInfo.stSize.u32Height ; ++i)
{
for (uint32_t j = 0; j < stCanvasInfo.u32Stride ; ++j)
{
ptr[i*stCanvasInfo.u32Stride + j] = 0xFFE0;
}
}
#else
freeTypeToRgn(&stCanvasInfo, _pstOsdTTF, _u32Color);
#endif
s32Ret = HI_MPI_RGN_UpdateCanvas(m_rgnHandle);
if (HI_SUCCESS != s32Ret)
{
printf("HI_MPI_RGN_UpdateCanvas fail! s32Ret: 0x%x.\n", s32Ret);
return ;
}
}
void freeTypeToRgn(const RGN_CANVAS_INFO_S *_pstCanvasInfo, const OSDTTF_st *_pstOsdTTF, uint32_t _u32Color)
{
FT_Library library;
FT_Face face;
FT_GlyphSlot slot;
FT_Matrix matrix; /* transformation matrix */
FT_Vector pen; /* untransformed origin */
FT_Error error;
int num_chars = strlen(_pstOsdTTF->m_szString);
int n;
int canvasHeight = _pstCanvasInfo->stSize.u32Height;
error = FT_Init_FreeType( &library ); /* initialize library */
if(error)
{
library = 0;
printf("FT_Init_FreeType err\n");
return;
}
error = FT_New_Face( library, _pstOsdTTF->m_szFont, 0, &face ); /* create face object */
if(error)
{
FT_Done_Face( face );
FT_Done_FreeType( library );
printf("FT_New_Face err\n");
return;
}
#if 0
/* use 50pt at 100dpi */
error = FT_Set_Char_Size( face, _pstOsdTTF->m_iFontSize * 64, 0, 0, 0 ); /* set character size */
#else
error = FT_Set_Pixel_Sizes(face, _pstOsdTTF->m_iFontSize, 0);
#endif
if(error)
{
FT_Done_Face( face );
FT_Done_FreeType( library );
printf("FT_Set_Pixel_Sizes err\n");
return;
}
slot = face->glyph;
/* 字体旋转 */
int angle = ( 0.0 / 360 ) * 3.14159 * 2; /* use 0 degrees */
/* set up matrix */
matrix.xx = (FT_Fixed)( cos( angle ) * 0x10000L );
matrix.xy = (FT_Fixed)(-sin( angle ) * 0x10000L );
matrix.yx = (FT_Fixed)( sin( angle ) * 0x10000L );
matrix.yy = (FT_Fixed)( cos( angle ) * 0x10000L );
/* 设置绘图起点 */
pen.x = _pstOsdTTF->m_x * 64;
pen.y = (canvasHeight - _pstOsdTTF->m_iFontSize + 6 - _pstOsdTTF->m_y) * 64;
for ( n = 0; n < num_chars; n++ )
{
/* 设置好绘图格式 */
FT_Set_Transform( face, &matrix, &pen );
/* 解码文字编码 */
error = FT_Load_Char( face, _pstOsdTTF->m_szString[n], FT_LOAD_FORCE_AUTOHINT | FT_LOAD_RENDER ); //就会设置face->glyph,转换的位图又保存在哪里?
if ( error ) //位图点阵应该是保存在face->glyph.bitmap中。
{
continue; /* ignore errors */
}
/* 开始绘制 */
rgnDraw(_pstCanvasInfo, &slot->bitmap,
slot->bitmap_left,
canvasHeight - slot->bitmap_top, _u32Color);
/* increment pen position */
pen.x += slot->advance.x;
pen.y += slot->advance.y;
}
FT_Done_Face( face );
FT_Done_FreeType( library );
}
void rgnDraw(const RGN_CANVAS_INFO_S *_pstCanvasInfo, FT_Bitmap * bitmap, FT_Int x, FT_Int y, uint32_t _u32Color)
{
uint16_t *pen16 = (uint16_t *)(_pstCanvasInfo->u32VirtAddr);
uint32_t i, j, p, q;
uint32_t x_max = x + bitmap->width;
uint32_t y_max = y + bitmap->rows;
// printf("1===================%d %d %d %d\n", x_max, y_max, _pstCanvasInfo->stSize.u32Width, _pstCanvasInfo->u32Stride);
for ( j = y, q = 0; j < y_max; ++j, ++q )
{
for ( i = x, p = 0; i < x_max; ++i, ++p )
{
if ( i<0 || j<0 || i>_pstCanvasInfo->stSize.u32Width|| j>=_pstCanvasInfo->stSize.u32Height )
continue;
if(bitmap->buffer[q * bitmap->width + p] != 0)
{
*(pen16 + j * _pstCanvasInfo->u32Stride + i) = RGB888ToRGB565(_u32Color);
}
else
{
*(pen16 + j * _pstCanvasInfo->u32Stride + i) = 0x0000;
}
}
}
}[/code]
各位前辈小弟用freeType加载字库在rgn canvas上面打点的方式做OSD,但是发现做出来的效果有隔一行一行的。同样的方法在framebuffer上面没问题,请问这是怎么回事呢。下面是代码
[code]void showString(const OSDTTF_st *_pstOsdTTF, uint32_t _u32Color)
{
RGN_CANVAS_INFO_S stCanvasInfo;
/* 1.get current osd info */
HI_S32 s32Ret = HI_MPI_RGN_GetCanvasInfo(m_rgnHandle, &stCanvasInfo);
if (HI_SUCCESS != s32Ret)
{
printf("HI_MPI_RGN_GetCanvasInfo fail! s32Ret: 0x%x.\n", s32Ret);
return ;
}
// printf("%d %d %d\n", stCanvasInfo.stSize.u32Width, stCanvasInfo.stSize.u32Height, stCanvasInfo.u32Stride);
// 这里 stCanvasInfo.stSize.u32Width = 360; stCanvasInfo.stSize.u32Height = 100; stCanvasInfo.u32Stride=768;
HI_U32 *pen = (HI_U32 *)stCanvasInfo.u32VirtAddr;
memset(pen, 0, stCanvasInfo.u32Stride * stCanvasInfo.stSize.u32Height);
#if 0
uint16_t *ptr = (uint16_t *)stCanvasInfo.u32VirtAddr;
for (uint32_t i = 0; i< stCanvasInfo.stSize.u32Height ; ++i)
{
for (uint32_t j = 0; j < stCanvasInfo.u32Stride ; ++j)
{
ptr[i*stCanvasInfo.u32Stride + j] = 0xFFE0;
}
}
#else
freeTypeToRgn(&stCanvasInfo, _pstOsdTTF, _u32Color);
#endif
s32Ret = HI_MPI_RGN_UpdateCanvas(m_rgnHandle);
if (HI_SUCCESS != s32Ret)
{
printf("HI_MPI_RGN_UpdateCanvas fail! s32Ret: 0x%x.\n", s32Ret);
return ;
}
}
void freeTypeToRgn(const RGN_CANVAS_INFO_S *_pstCanvasInfo, const OSDTTF_st *_pstOsdTTF, uint32_t _u32Color)
{
FT_Library library;
FT_Face face;
FT_GlyphSlot slot;
FT_Matrix matrix; /* transformation matrix */
FT_Vector pen; /* untransformed origin */
FT_Error error;
int num_chars = strlen(_pstOsdTTF->m_szString);
int n;
int canvasHeight = _pstCanvasInfo->stSize.u32Height;
error = FT_Init_FreeType( &library ); /* initialize library */
if(error)
{
library = 0;
printf("FT_Init_FreeType err\n");
return;
}
error = FT_New_Face( library, _pstOsdTTF->m_szFont, 0, &face ); /* create face object */
if(error)
{
FT_Done_Face( face );
FT_Done_FreeType( library );
printf("FT_New_Face err\n");
return;
}
#if 0
/* use 50pt at 100dpi */
error = FT_Set_Char_Size( face, _pstOsdTTF->m_iFontSize * 64, 0, 0, 0 ); /* set character size */
#else
error = FT_Set_Pixel_Sizes(face, _pstOsdTTF->m_iFontSize, 0);
#endif
if(error)
{
FT_Done_Face( face );
FT_Done_FreeType( library );
printf("FT_Set_Pixel_Sizes err\n");
return;
}
slot = face->glyph;
/* 字体旋转 */
int angle = ( 0.0 / 360 ) * 3.14159 * 2; /* use 0 degrees */
/* set up matrix */
matrix.xx = (FT_Fixed)( cos( angle ) * 0x10000L );
matrix.xy = (FT_Fixed)(-sin( angle ) * 0x10000L );
matrix.yx = (FT_Fixed)( sin( angle ) * 0x10000L );
matrix.yy = (FT_Fixed)( cos( angle ) * 0x10000L );
/* 设置绘图起点 */
pen.x = _pstOsdTTF->m_x * 64;
pen.y = (canvasHeight - _pstOsdTTF->m_iFontSize + 6 - _pstOsdTTF->m_y) * 64;
for ( n = 0; n < num_chars; n++ )
{
/* 设置好绘图格式 */
FT_Set_Transform( face, &matrix, &pen );
/* 解码文字编码 */
error = FT_Load_Char( face, _pstOsdTTF->m_szString[n], FT_LOAD_FORCE_AUTOHINT | FT_LOAD_RENDER ); //就会设置face->glyph,转换的位图又保存在哪里?
if ( error ) //位图点阵应该是保存在face->glyph.bitmap中。
{
continue; /* ignore errors */
}
/* 开始绘制 */
rgnDraw(_pstCanvasInfo, &slot->bitmap,
slot->bitmap_left,
canvasHeight - slot->bitmap_top, _u32Color);
/* increment pen position */
pen.x += slot->advance.x;
pen.y += slot->advance.y;
}
FT_Done_Face( face );
FT_Done_FreeType( library );
}
void rgnDraw(const RGN_CANVAS_INFO_S *_pstCanvasInfo, FT_Bitmap * bitmap, FT_Int x, FT_Int y, uint32_t _u32Color)
{
uint16_t *pen16 = (uint16_t *)(_pstCanvasInfo->u32VirtAddr);
uint32_t i, j, p, q;
uint32_t x_max = x + bitmap->width;
uint32_t y_max = y + bitmap->rows;
// printf("1===================%d %d %d %d\n", x_max, y_max, _pstCanvasInfo->stSize.u32Width, _pstCanvasInfo->u32Stride);
for ( j = y, q = 0; j < y_max; ++j, ++q )
{
for ( i = x, p = 0; i < x_max; ++i, ++p )
{
if ( i<0 || j<0 || i>_pstCanvasInfo->stSize.u32Width|| j>=_pstCanvasInfo->stSize.u32Height )
continue;
if(bitmap->buffer[q * bitmap->width + p] != 0)
{
*(pen16 + j * _pstCanvasInfo->u32Stride + i) = RGB888ToRGB565(_u32Color);
}
else
{
*(pen16 + j * _pstCanvasInfo->u32Stride + i) = 0x0000;
}
}
}
}[/code]
我来回答
回答0个
时间排序
认可量排序
暂无数据
或将文件直接拖到这里
悬赏:
E币
网盘
* 网盘链接:
* 提取码:
悬赏:
E币
Markdown 语法
- 加粗**内容**
- 斜体*内容*
- 删除线~~内容~~
- 引用> 引用内容
- 代码`代码`
- 代码块```编程语言↵代码```
- 链接[链接标题](url)
- 无序列表- 内容
- 有序列表1. 内容
- 缩进内容
- 图片![alt](url)
相关问答
-
42020-09-09 08:15:40
-
2022-07-10 15:14:57
-
2016-05-04 15:39:48
-
2017-05-06 16:21:26
-
172014-10-05 18:05:46
-
2018-05-24 18:07:19
-
152015-05-25 10:46:27
-
2015-05-21 15:41:04
-
2019-08-14 13:52:03
-
2017-07-06 11:19:02
-
2016-03-14 17:14:53
-
2023-02-10 16:11:44
-
2019-07-23 09:59:21
-
2019-01-12 11:27:38
-
52019-04-01 17:59:14
-
2023-07-12 13:46:47
-
12019-04-17 16:37:10
-
2018-09-16 09:36:41
-
2018-11-04 08:24:34
无更多相似问答 去提问
点击登录
-- 积分
-- E币
提问
—
收益
—
被采纳
—
我要提问
切换马甲
上一页
下一页
悬赏问答
-
5Hi3516CV610 如何使用SD卡升级固件
-
5cat /dev/logmpp 报错 <3>[ vi] [func]:vi_send_frame_node [line]:99 [info]:vi pic queue is full!
-
50如何获取vpss chn的图像修改后发送至vo
-
5FPGA通过Bt1120传YUV422数据过来,vi接收不到数据——3516dv500
-
50SS928 运行PQtools 拼接 推到设备里有一半画面会异常
-
53536AV100的sample_vdec输出到CVBS显示
-
10海思板子mpp怎么在vi阶段改变视频数据尺寸
-
10HI3559AV100 多摄像头同步模式
-
9海思ss928单路摄像头vio中加入opencv处理并显示
-
10EB-RV1126-BC-191板子运行自己编码的程序
举报反馈
举报类型
- 内容涉黄/赌/毒
- 内容侵权/抄袭
- 政治相关
- 涉嫌广告
- 侮辱谩骂
- 其他
详细说明
提醒
你的问题还没有最佳答案,是否结题,结题后将扣除20%的悬赏金
取消
确认
提醒
你的问题还没有最佳答案,是否结题,结题后将根据回答情况扣除相应悬赏金(1回答=1E币)
取消
确认