4758
- 收藏
- 点赞
- 分享
- 举报
Hi351x 通过freetype 显示OSD
1.依赖库 freetype-xxx.tar 从字库中获取字形bitmap
libiconv-xxx.tar.gz 转码,用于显示中文等字符
交叉编译到相应平台
2. freetype 操作详见 附件
3. main 示例
#include "loadfont.h"
#include
#include
#include
#include
#include
static char *font_library_path = "./simsun.ttc";
#define BUFFER_SIZE 4
void printf_font(struct Font_Bitmap *font_bitmap)
{
if(NULL == font_bitmap || NULL == font_bitmap->buffer) {
return;
}
int i = 0;
int j = 0;
int k = 0;
int counter = 0;
for (j = 0; j < (font_bitmap->fontsize * 26) / 32 - font_bitmap->top; j++){
for (i = 0; i < font_bitmap->fontsize; i++){
printf("_");
}
printf("\n");
}
for (; j < font_bitmap->rows + (font_bitmap->fontsize * 26) / 32 - font_bitmap->top; j++){
for (i = 1; i <= font_bitmap->left; i++) {
printf("_");
}
for (k = 0; k < font_bitmap->pitch; k++) {
int tmp = font_bitmap->buffer[font_bitmap->pitch*(j + font_bitmap->top - (font_bitmap->fontsize * 26) / 32) + k];
for (counter = 0; counter < 8; counter++) {
if (tmp & 0x80) {
printf("*");
}
else {
printf("_");
}
tmp <<= 1;
i++;
if (i > font_bitmap->fontsize) {
break;
}
}
}
for(; i <= font_bitmap->fontsize; ++ i){
printf("_");
}
printf("\n");
}
for (; j < font_bitmap->fontsize; j++){
for (i = 0; i < font_bitmap->fontsize; i++){
printf("_");
}
printf("\n");
}
}
void test_load_font(wchar_t testa, int fontsize)
{
struct Font_Bitmap font_bitmap;
int ret = SS_Font_Set_FontSize(fontsize);
if(0 != ret) {
printf("%s:%d-----SS_Font_Set_FontSize failed\n", __func__, __LINE__);
}
ret = SS_Load_FontBitmap(testa, &font_bitmap);
if(0 == ret){
//actually the memory bitmap should be drawed here
printf_font(&font_bitmap);
} else {
printf("%s:%d-----SS_Load_FontBitmap failed\n", __func__, __LINE__);
}
}
unsigned short Get_Unicode(char *utf8)
{ unsigned short unicode;
unicode = utf8[0];
//printf("unicode before:0x%x\n",unicode);
if (unicode >= 0xF0) {
unicode = (unsigned short) (utf8[0] & 0x07) << 18;
unicode |= (unsigned short) (utf8[1] & 0x3F) << 12;
unicode |= (unsigned short) (utf8[2] & 0x3F) << 6;
unicode |= (unsigned short) (utf8[3] & 0x3F);
} else if (unicode >= 0xE0) {
unicode = (unsigned short) (utf8[0] & 0x0F) << 12;
unicode |= (unsigned short) (utf8[1] & 0x3F) << 6;
unicode |= (unsigned short) (utf8[2] & 0x3F);
} else if (unicode >= 0xC0) {
unicode = (unsigned short) (utf8[0] & 0x1F) << 6;
unicode |= (unsigned short) (utf8[1] & 0x3F);
}
return unicode;
}
static unsigned short Get_Unicode_(char *cStr, int *unicode_char_len)
{
unsigned short unicode = 0x00;
if(NULL == cStr){
return unicode;
}
int str_len = strlen(cStr);
if(0 == str_len){
return unicode;
}
int char_len = 0;;
unicode = cStr[0];
if (unicode >= 0xF0 && str_len >=4) {
unicode = (unsigned short) (cStr[0] & 0x07) << 18;
unicode |= (unsigned short) (cStr[1] & 0x3F) << 12;
unicode |= (unsigned short) (cStr[2] & 0x3F) << 6;
unicode |= (unsigned short) (cStr[3] & 0x3F);
char_len = 4;
} else if (unicode >= 0xE0 && str_len >=3) {
unicode = (unsigned short) (cStr[0] & 0x0F) << 12;
unicode |= (unsigned short) (cStr[1] & 0x3F) << 6;
unicode |= (unsigned short) (cStr[2] & 0x3F);
char_len = 3;
} else if (unicode >= 0xC0 && str_len >=2) {
unicode = (unsigned short) (cStr[0] & 0x1F) << 6;
unicode |= (unsigned short) (cStr[1] & 0x3F);
char_len = 2;
} else {
char_len = 1;
}
if(NULL != unicode_char_len) {
*unicode_char_len = char_len;
}
return unicode;
}
int code_convert(char *from_charset, char *to_charset, char *inbuf, size_t inlen, char *outbuf, size_t outlen)
{
iconv_t cd;
char **pin = &inbuf;
char **pout = &outbuf;
cd = iconv_open(to_charset,from_charset);
if (cd == 0){
return -1;
}
if (iconv(cd, pin, &inlen, pout, &outlen) == -1){
iconv_close(cd);
return -1;
}
iconv_close(cd);
return 0;
}
int main()
{
int ret = 0;
ret = SS_Font_Init(font_library_path);
if(ret == 0) {
char *test_ch = "我";
char *utf8_ch = (char *)malloc(strlen(test_ch) * sizeof(char));
memset(utf8_ch, 0, strlen(test_ch) * sizeof(char));
code_convert("gb2312", "utf-8", test_ch, strlen(test_ch), utf8_ch, BUFFER_SIZE);
int str_len = strlen(utf8_ch);
printf("strlen:%d \n", str_len);
int index = 0;
int len = 0;
for(index = 0; index < str_len; index += len){
unsigned short ch_unicode = Get_Unicode_(&utf8_ch[index], &len);
test_load_font(ch_unicode , 64);
}
free(utf8_ch);
} else {
printf("%s:%d-----SS_Font_Init failed\n", __func__, __LINE__);
}
SS_Font_deInit();
return 0;
}
libiconv-xxx.tar.gz 转码,用于显示中文等字符
交叉编译到相应平台
2. freetype 操作详见 附件
3. main 示例
#include "loadfont.h"
#include
#include
#include
#include
#include
static char *font_library_path = "./simsun.ttc";
#define BUFFER_SIZE 4
void printf_font(struct Font_Bitmap *font_bitmap)
{
if(NULL == font_bitmap || NULL == font_bitmap->buffer) {
return;
}
int i = 0;
int j = 0;
int k = 0;
int counter = 0;
for (j = 0; j < (font_bitmap->fontsize * 26) / 32 - font_bitmap->top; j++){
for (i = 0; i < font_bitmap->fontsize; i++){
printf("_");
}
printf("\n");
}
for (; j < font_bitmap->rows + (font_bitmap->fontsize * 26) / 32 - font_bitmap->top; j++){
for (i = 1; i <= font_bitmap->left; i++) {
printf("_");
}
for (k = 0; k < font_bitmap->pitch; k++) {
int tmp = font_bitmap->buffer[font_bitmap->pitch*(j + font_bitmap->top - (font_bitmap->fontsize * 26) / 32) + k];
for (counter = 0; counter < 8; counter++) {
if (tmp & 0x80) {
printf("*");
}
else {
printf("_");
}
tmp <<= 1;
i++;
if (i > font_bitmap->fontsize) {
break;
}
}
}
for(; i <= font_bitmap->fontsize; ++ i){
printf("_");
}
printf("\n");
}
for (; j < font_bitmap->fontsize; j++){
for (i = 0; i < font_bitmap->fontsize; i++){
printf("_");
}
printf("\n");
}
}
void test_load_font(wchar_t testa, int fontsize)
{
struct Font_Bitmap font_bitmap;
int ret = SS_Font_Set_FontSize(fontsize);
if(0 != ret) {
printf("%s:%d-----SS_Font_Set_FontSize failed\n", __func__, __LINE__);
}
ret = SS_Load_FontBitmap(testa, &font_bitmap);
if(0 == ret){
//actually the memory bitmap should be drawed here
printf_font(&font_bitmap);
} else {
printf("%s:%d-----SS_Load_FontBitmap failed\n", __func__, __LINE__);
}
}
unsigned short Get_Unicode(char *utf8)
{ unsigned short unicode;
unicode = utf8[0];
//printf("unicode before:0x%x\n",unicode);
if (unicode >= 0xF0) {
unicode = (unsigned short) (utf8[0] & 0x07) << 18;
unicode |= (unsigned short) (utf8[1] & 0x3F) << 12;
unicode |= (unsigned short) (utf8[2] & 0x3F) << 6;
unicode |= (unsigned short) (utf8[3] & 0x3F);
} else if (unicode >= 0xE0) {
unicode = (unsigned short) (utf8[0] & 0x0F) << 12;
unicode |= (unsigned short) (utf8[1] & 0x3F) << 6;
unicode |= (unsigned short) (utf8[2] & 0x3F);
} else if (unicode >= 0xC0) {
unicode = (unsigned short) (utf8[0] & 0x1F) << 6;
unicode |= (unsigned short) (utf8[1] & 0x3F);
}
return unicode;
}
static unsigned short Get_Unicode_(char *cStr, int *unicode_char_len)
{
unsigned short unicode = 0x00;
if(NULL == cStr){
return unicode;
}
int str_len = strlen(cStr);
if(0 == str_len){
return unicode;
}
int char_len = 0;;
unicode = cStr[0];
if (unicode >= 0xF0 && str_len >=4) {
unicode = (unsigned short) (cStr[0] & 0x07) << 18;
unicode |= (unsigned short) (cStr[1] & 0x3F) << 12;
unicode |= (unsigned short) (cStr[2] & 0x3F) << 6;
unicode |= (unsigned short) (cStr[3] & 0x3F);
char_len = 4;
} else if (unicode >= 0xE0 && str_len >=3) {
unicode = (unsigned short) (cStr[0] & 0x0F) << 12;
unicode |= (unsigned short) (cStr[1] & 0x3F) << 6;
unicode |= (unsigned short) (cStr[2] & 0x3F);
char_len = 3;
} else if (unicode >= 0xC0 && str_len >=2) {
unicode = (unsigned short) (cStr[0] & 0x1F) << 6;
unicode |= (unsigned short) (cStr[1] & 0x3F);
char_len = 2;
} else {
char_len = 1;
}
if(NULL != unicode_char_len) {
*unicode_char_len = char_len;
}
return unicode;
}
int code_convert(char *from_charset, char *to_charset, char *inbuf, size_t inlen, char *outbuf, size_t outlen)
{
iconv_t cd;
char **pin = &inbuf;
char **pout = &outbuf;
cd = iconv_open(to_charset,from_charset);
if (cd == 0){
return -1;
}
if (iconv(cd, pin, &inlen, pout, &outlen) == -1){
iconv_close(cd);
return -1;
}
iconv_close(cd);
return 0;
}
int main()
{
int ret = 0;
ret = SS_Font_Init(font_library_path);
if(ret == 0) {
char *test_ch = "我";
char *utf8_ch = (char *)malloc(strlen(test_ch) * sizeof(char));
memset(utf8_ch, 0, strlen(test_ch) * sizeof(char));
code_convert("gb2312", "utf-8", test_ch, strlen(test_ch), utf8_ch, BUFFER_SIZE);
int str_len = strlen(utf8_ch);
printf("strlen:%d \n", str_len);
int index = 0;
int len = 0;
for(index = 0; index < str_len; index += len){
unsigned short ch_unicode = Get_Unicode_(&utf8_ch[index], &len);
test_load_font(ch_unicode , 64);
}
free(utf8_ch);
} else {
printf("%s:%d-----SS_Font_Init failed\n", __func__, __LINE__);
}
SS_Font_deInit();
return 0;
}
文件: loadfont.7z
下载
我来回答
回答3个
时间排序
认可量排序
认可0
认可0
认可0
或将文件直接拖到这里
悬赏:
E币
网盘
* 网盘链接:
* 提取码:
悬赏:
E币
Markdown 语法
- 加粗**内容**
- 斜体*内容*
- 删除线~~内容~~
- 引用> 引用内容
- 代码`代码`
- 代码块```编程语言↵代码```
- 链接[链接标题](url)
- 无序列表- 内容
- 有序列表1. 内容
- 缩进内容
- 图片![alt](url)
相关问答
-
2015-10-14 00:40:38
-
2021-07-05 16:15:24
-
2022-07-10 15:14:57
-
2020-03-17 21:46:05
-
2014-11-13 10:46:50
-
42020-09-09 08:15:40
-
102015-06-27 10:19:58
-
2019-12-02 12:00:20
-
2019-09-20 16:32:04
-
2022-07-09 08:52:40
-
2020-03-03 17:51:42
-
2016-06-28 12:11:24
-
2016-03-24 16:48:16
-
112016-03-10 11:10:58
-
2013-12-19 21:51:34
-
2020-11-26 11:59:49
-
2016-07-27 16:34:10
-
2015-07-26 17:14:37
-
2016-06-03 16:44:20
无更多相似问答 去提问
点击登录
-- 积分
-- 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币)
取消
确认