嵌入式linux:3520a SDL_tff库做bmp 也就是osd

转自:http://blog.csdn.net/xyyangkun/article/details/8528941

之前用点陈字库做过3515,3520a的字库,现在为新需求,要用矢量字库做osd。决定用SDL_tff库做。

配置freetype:

xy@xy-pc:~/aaa/freetype-2.4.10$ CC=arm-hisiv200-linux-gcc ./configure --prefix=/home/xy/aaa/bin   --host=arm-linux
--prefix 指定编译后,相关库文件存放的路径;

编译安装:make ,make install。

配置SDL:

xy@xy-pc:~/aaa/SDL-1.2.15$ CC=arm-hisiv200-linux-gcc CXX=arm-hisiv200-linux-cpp ./configure --prefix=/home/xy/aaa/bin   --host=arm-linux --disable-alsa  --disable-pulseaudio

编译安装。


配置SDL_tff:

xy@xy-pc:~/aaa/SDL_ttf-2.0.11$CC=arm-hisiv200-linux-gcc ./configure --with-freetype-prefix=/home/xy/aaa/bin --host=arm-linux

编译安装.


  1. /* 
  2.  * main.c 
  3.  * 
  4.  *  Created on: 2013-1-22 
  5.  *      Author: xy 
  6.  */  
  7. #include <stdlib.h>  
  8. #include <string.h>  
  9. #include "SDL/SDL.h"  
  10. #include "SDL/SDL_ttf.h"  
  11.   
  12.   
  13. int main(int argc,char **argv)  
  14. {  
  15.     TTF_Font *font;  
  16.     SDL_Surface *text, *temp;  
  17.   
  18.      /* Initialize the TTF library */  
  19.      if ( TTF_Init() < 0 ) {  
  20.          fprintf(stderr, "Couldn't initialize TTF: %s\n",SDL_GetError());  
  21.          SDL_Quit();  
  22.          return(2);  
  23.      }  
  24.   
  25.   
  26.     font = TTF_OpenFont("cu.ttf", 48);  
  27.     if ( font == NULL ) {  
  28.         fprintf(stderr, "Couldn't load %d pt font from %s: %s\n",  
  29.                     "ptsize", 18, SDL_GetError());  
  30.     }  
  31.   
  32. //  TTF_SetFontStyle(font, 0);  
  33. //  TTF_SetFontOutline(font, 0);  
  34. //  TTF_SetFontKerning(font, 1);  
  35. //  TTF_SetFontHinting(font, 0);  
  36.   
  37.     //SDL_Color forecol=     { 0xFF, 0xFF, 0xFF, 0 };  
  38.     SDL_Color forecol=   { 0x00, 0x00, 0x00, 0 };  
  39.     char *string="你好啊";  
  40.     text = TTF_RenderUTF8_Solid(font, string, forecol);  
  41.   
  42.     //SDL_LoadBMP  
  43.   
  44.     SDL_SaveBMP(text, "1.bmp");  
  45.   
  46.   
  47.   
  48.   
  49.     SDL_FreeSurface(text);  
  50.     TTF_CloseFont(font);  
  51.     TTF_Quit();  
  52.   
  53. }  

就可以保存成1.bmp了。输入了汉字。代码保存的文本格式应该utf-8.



对于海思3520a用的是rgb1555格式,所以应该转成那种格式:

  1. /* Convert to 16 bits per pixel */  
  2. SDL_Surface *temp = SDL_CreateRGBSurface(SDL_SWSURFACE,  
  3.         text->w, text->h, 16,\  
  4.                     0x00FF0000, 0x0000FF00, 0x000000FF,/*0x00FF0000, 0x0000FF00, 0x000000FF*/  
  5.                     0);  
  6. SDL_Rect bounds;  
  7. if (temp != NULL)  
  8. {  
  9.     bounds.x = 0;  
  10.     bounds.y = 0;  
  11.     bounds.w = text->w;  
  12.     bounds.h = text->h;  
  13.     if (SDL_LowerBlit(text, &bounds, temp, &bounds) < 0) {  
  14.         SDL_FreeSurface(text);  
  15.         SDL_SetError("Couldn't convert image to 16 bpp");  
  16.         text = NULL;  
  17.     }  
  18. }  
  19. stBitmap.u32Width = temp->w;  
  20. stBitmap.u32Height = temp->h;  
  21. stBitmap.pData= temp->pixels;  
  22. stBitmap.enPixelFormat= PIXEL_FORMAT_RGB_1555 ;  
  23. SDL_FreeSurface(text);  
  24. SDL_FreeSurface(temp);  

添加以上代码,基本就可以达到了。

因为自己的不细心,调试了大半天。真是不应该啊。其实早知道这样做,但是思维上总是背道而驰。

以后编程应该更细心,至少节省时间啊。。。。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值