使用freetype/SDL/SDL_tff进行叠加
编译freetype
下载地址:http://mirror.yongbok.net/nongnu/freetype/freetype-2.10.0.tar.bz2
./configure --prefix=/home/hh/freetype-2.10.0/install/ --host=aarch64-himix100-linux --without-zlib
make
make install
编译SDL
下载地址:http://www.libsdl.org/release/SDL-1.2.15.tar.gz
./configure --prefix=/home/hh/SDL-1.2.15/install --disable-pulseaudio --disable-video-nanox -disable-video-qtopia --disable-static --enable-shared --disable-video-photon --disable-video-ggi --disable-video-svga --disable-video-aalib --disable-video-dummy --disable-video-dga --disable-arts --disable-esd --disable-alsa --disable-video-x11 --disable-nasm --disable-joystick --disable-input-tslib -enable-video-fbcon --build=arm --host=arm-linux CC=aarch64-himix100-linux-gcc
make
make install
编译SDL_tff
下载地址:http://www.libsdl.org/projects/SDL_ttf/release/SDL_ttf-2.0.11.tar.gz
把freetype的 freetype和ft2build.h 复制到SDL_ttf-2.0.11下
LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/home/hh/freetype-2.10.0/install/lib:/home/hh/SDL-1.2.15/install/lib
PATH=$PATH:/home/hh/freetype-2.10.0/install/lib:/home/hh/SDL-1.2.15/install/lib
./configure CC=/opt/hisi-linux/x86-arm/aarch64-himix100-linux/bin/aarch64-himix100-linux-gcc --host=arm-hisiv500-linux --enable-shared=no --enable-static=yes -prefix=/home/hh/SDL_ttf-2.0.11/install --with-freetype-prefix=/home/hh/freetype-2.10.0/install --with-sdl-prefix=/home/hh/SDL-1.2.15/install LDFLAGS="-L/home/hh/freetype-2.10.0/install/lib -lfreetype"
测试
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "SDL.h"
#include "SDL_ttf.h"
#include "time.h"
#define FONT_PATH "./UbuntuMono-BI.ttf"
int string_to_bmp(char *pu8Str);
int cnt = 0;
int main()
{
time_t now;
struct tm *ptm;
char timestr[100] = {0};
while(1)
{
usleep(1000000);
time(&now);
ptm = localtime(&now);
snprintf(timestr,100,"时间%d-%02d-%02d %02d:%02d:%02d",ptm->tm_year+1900,ptm->tm_mon+1,ptm->tm_mday,ptm->tm_hour,ptm->tm_min,ptm->tm_sec);
string_to_bmp(timestr);
memset(timestr,0,100);
if(cnt++ > 5)
{
break;
}
}
return 0;
}
int string_to_bmp(char *pu8Str)
{
SDL_PixelFormat *fmt;
TTF_Font *font;
SDL_Surface *text, *temp;
if (TTF_Init() < 0 )
{
fprintf(stderr, "Couldn't initialize TTF: %s\n",SDL_GetError());
SDL_Quit();
}
font = TTF_OpenFont(FONT_PATH, 80);
if ( font == NULL )
{
fprintf(stderr, "Couldn't load %d pt font from %s: %s\n",18,"ptsize", SDL_GetError());
}
SDL_Color forecol = { 0xff, 0xff, 0xff, 0 };
text = TTF_RenderUTF8_Solid(font, pu8Str, forecol);
fmt = (SDL_PixelFormat*)malloc(sizeof(SDL_PixelFormat));
memset(fmt,0,sizeof(SDL_PixelFormat));
fmt->BitsPerPixel = 16;
fmt->BytesPerPixel = 2;
fmt->colorkey = 0xffffffff;
fmt->alpha = 0xff;
temp = SDL_ConvertSurface(text,fmt,0);
//使用opencv格式
//cv::Mat m(temp->h,temp->w,CV_8UC3,temp->pixels,temp->pitch);
//out_img = m.clone();
//简单存一下图
char savename[10] = {0};
snprintf(savename,10,"%d.bmp",cnt);
printf("savename = %s\n",savename);
SDL_SaveBMP(temp, savename);
SDL_FreeSurface(text);
SDL_FreeSurface(temp);
TTF_CloseFont(font);
TTF_Quit();
return 0;
}
aarch64-himix100-linux-gcc test.c -lpthread -I/opt/arm/include/SDL -L/opt/arm/lib -lSDL -lSDL_ttf -lfreetype
这里是用到的一些字体tff资源