1、source_code
main.c中实现了函数draw_Font_Func(),这个函数可以直接移植到C程序中使用。
zimo.h里面放的是字模转码后的数据。

2、data_yuv
测试用的yuv420数据(352*288) CIF格式,测试前后的数据。

3、zimo_gr.zip
取字幕的软件

 /*
* Copyright(C), 2008-2013, Ubuntu Inc.
* File name: main.c
* Author: xubinbin 徐彬彬 (Beijing China)
* Version: 1.0
* Date: 2013.06.09
* Description:
* Function List: char *draw_Font_Func(char *ptr_frame,const unsigned char font[],int startx,int starty,int color)
* Email: [email protected]
*/ #include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <string.h> #include "zimo.h" #define FRAME_WIDTH (352)
#define FRAME_HEIGHT (288)
#define FRAME_SIZE (FRAME_WIDTH*FRAME_HEIGHT*3/2)
#define IN_FILENAME "in.raw"
#define OUT_FILENAME "out.raw" const unsigned char table[] = { /*-- 文字: 陈 --*/
/*-- 楷体_GB231212; 此字体下对应的点阵为:宽x高=16x16 --*/
0x00,0x40,0x78,0x40,0x48,0x40,0x57,0xFE,0x50,0x80,0x61,0x20,0x51,0x20,0x4A,0x20,
0x4B,0xFC,0x48,0x20,0x69,0x28,0x51,0x24,0x42,0x22,0x44,0x22,0x40,0xA0,0x40,0x40, /*-- 文字: 桂 --*/
/*-- 楷体_GB231212; 此字体下对应的点阵为:宽x高=16x16 --*/
0x10,0x20,0x10,0x20,0x11,0xFC,0x10,0x20,0xFC,0x20,0x10,0x20,0x33,0xFE,0x38,0x00,
0x54,0x20,0x54,0x20,0x91,0xFC,0x10,0x20,0x10,0x20,0x10,0x20,0x13,0xFE,0x10,0x00, /*-- 文字: 芳 --*/
/*-- 楷体_GB231212; 此字体下对应的点阵为:宽x高=16x16 --*/
0x08,0x20,0x08,0x20,0xFF,0xFE,0x08,0x20,0x0A,0x20,0x01,0x00,0xFF,0xFE,0x04,0x00,
0x04,0x00,0x07,0xF0,0x04,0x10,0x08,0x10,0x08,0x10,0x10,0x10,0x20,0xA0,0x40,0x40, }; /*
* Function: draw_Font_Func
* Description: 实现在yuv420图片上面画字
* Input: char *ptr_frame 一帧视频的首地址
* const unsigned char font[] 画的字模
* int startx 写字的起点坐标x
* int starty 写字的起点坐标y
* int color 字颜色的选择,具体颜色在程序代码
* Return: 这里会把传进来的一帧视频的地址返回,可以不调用
*/
char *draw_Font_Func(char *ptr_frame,const unsigned char font[],int startx,int starty,int color)
{ assert( ptr_frame != NULL ); int tagY=,tagU=,tagV=;
char *offsetY=NULL,*offsetU=NULL,*offsetV=NULL;
unsigned short p16, mask16; // for reading hzk16 dots /*yuv 地址的设置 */
offsetY = ptr_frame;
offsetU = offsetY + FRAME_WIDTH * FRAME_HEIGHT;
offsetV = offsetU + FRAME_WIDTH * FRAME_HEIGHT/; switch (color)
{
case : // Yellow
tagY = ;tagU = ;tagV = ;
break;
case : // Red
tagY = ;tagU = ;tagV = ;
break;
case : // Green
tagY = ;tagU = ;tagV = ;
break;
case : // Blue
tagY = ;tagU = ;tagV = ;
break;
default: // White
tagY = ;tagU = ;tagV = ;
} int x=,y=,i=,j=,k=;
for(i = ; i < ; i++)
{
#if 0
for (j = , y = starty; j < && y < FRAME_HEIGHT - ; j++, y+=) // line dots per char
{
p16 = *(unsigned short *)(font + j* + i*);/*取字模数据*/
mask16 = 0x0080; /* 二进制 1000 0000 */
for (k = , x = startx +i*; k < && x < FRAME_WIDTH - ; k++, x+=) // dots in a line
{
if (p16 & mask16)
{
*(offsetY + y*FRAME_WIDTH + x) = *(offsetY + y*FRAME_WIDTH + x+) = tagY;
*(offsetY + (y+)*FRAME_WIDTH + x) = *(offsetY + (y+)*FRAME_WIDTH + x+) = tagY;
*(offsetU + y * FRAME_WIDTH/ + x/) =tagU;
*(offsetV + y * FRAME_WIDTH/ + x/) = tagV;
}
mask16 = mask16 >> ; /* 循环移位取数据 */
if (mask16 == )
mask16 = 0x8000;
}
}
#else
for (j = , y = starty; j < && y < FRAME_HEIGHT - ; j++, y++) // line dots per char
{
p16 = *(unsigned short *)(font + j* + i*);/*取字模数据*/
mask16 = 0x0080; /* 二进制 1000 0000 */
for (k = , x = startx +i*; k < && x < FRAME_WIDTH - ; k++, x++) // dots in a line
{
if (p16 & mask16)
{
*(offsetY + y*FRAME_WIDTH + x) = ;
// *(offsetU + y * FRAME_WIDTH/4 + x/2) = 85;
// *(offsetV + y * FRAME_WIDTH/4 + x/2) = 255;
}
mask16 = mask16 >> ; /* 循环移位取数据 */
if (mask16 == )
mask16 = 0x8000;
}
}
#endif
} return (char *)ptr_frame;
} int main(int argc,char * argv[])
{
int ret = ;
FILE *in_file,*out_file; char *frame_buffer = NULL;
frame_buffer = (char*)malloc(FRAME_SIZE); //read frame file 读原来的一帧数据
in_file = fopen(IN_FILENAME,"r");
if (in_file == NULL)
{
printf("open in file error!\n");
} ret = fread(frame_buffer,FRAME_SIZE,,in_file);
if (ret != )
{
printf("ret = %d\n");
printf("fread file error!\n");
}
fclose(in_file); //数据转换
draw_Font_Func(frame_buffer,table,,,); //write frame file 把数据写回
out_file = fopen(OUT_FILENAME,"w");
if (out_file == NULL)
{
printf("open in file error!\n");
} ret = fwrite(frame_buffer,FRAME_SIZE,,out_file);
if (ret != )
{
printf("ret = %d\n");
printf("fwrite file error!\n");
}
fclose(out_file);
free(frame_buffer); printf("Done!\n");
return ;
}
05-17 04:49