信号系统综合实践报告.docx
《信号系统综合实践报告.docx》由会员分享,可在线阅读,更多相关《信号系统综合实践报告.docx(24页珍藏版)》请在冰豆网上搜索。
![信号系统综合实践报告.docx](https://file1.bdocx.com/fileroot1/2023-1/6/8fce4351-28ae-4797-b3ec-8c30c0c808f5/8fce4351-28ae-4797-b3ec-8c30c0c808f51.gif)
信号系统综合实践报告
大连理工大学
本科实验报告
课程名称:
信号综合处理实践
学院(系):
信息与通信工程学院
专业:
电子信息工程(英强)
班级:
电英1401班
学生1:
李帆201483089
学生2:
马壮201483082
学生3:
王瑞明201483133
2017年10月12日
题目:
实验39字幕式文字显示
一、方法的原理
本课题为字幕式文字显示,将提前设定的文字在显示器上动态显示,随着时间逐渐移动,实现弹幕的滚动效果。
主要的方法原理是,对指定文字进行字符化处理,形成32px*32px的汉字阵列,在显示器上对平面坐标进行设定,确定字符的初始位置,并确定字符间的相对位置,设定二维平面内字幕的移动方向和速度,从而实现字幕的动态效果。
同时,对显示器背景和字符的灰度进行调整,实现较好的演示效果。
1、汉语文字的字符点阵处理:
在灰度图像中,文字可以用像素点的形式显示,改变不同像素点位置的灰度值,可以实现文字的正确显示。
我们对汉字进行像素点阵处理,将单个汉字表示成自由设定的大小,计算出汉字占据的像素点,从而显示出汉字的图形。
利用汉字字模软件PCtoLCD2002,可以很简便地得到一般汉字的点阵表示。
在软件中输入汉字内容,调整点阵背景大小和汉字的字体及大小,自动生成像素坐标形式,确定坐标可以进一步实现汉字的正确显示。
我们对示例文字采用宋体,背景和汉字大小均为32px*32px,这样在屏幕上显示效果较好。
在程序中,我们将三名组员的姓名的每个字分别用像素点表示,作为查询表进行显示。
图1生成汉字“李帆”像素点表示示例
2、对显示器进行初始化设定
对显示器参数进行设定,屏幕宽度设为720,高度设为576,帧间隔设为25,最大帧率为25000。
由于是灰度图像显示,所以对显示器背景色和汉字颜色采用灰度级表示,我们设定背景色为纯黑0x00,将汉字设为纯白0xff,便于清楚地显示。
3、字幕文字位置及移动方式设定
对显示器进行二位平面坐标处理后,文字的位置以坐标的形式在显示器显示。
将文字作为整体,实现移动效果。
我们将中心字设为“马”,规定汉字第一个像素点的坐标为place_x和place_y,在(x,y)至(x+32,y+32)内的矩阵将显示汉字“马”。
我们在每一行显示一个成员名字,这样之后每个的汉字只需对x累加32即可实现。
确定行间距也为32px,这样在每一列上只需对中心字分别做处理(y+64)和(y-64)。
由此实现了一个整体操作,改变place_x和place_y的数值,可以实现字幕的滚动。
滚动方式设定为以对角线形式下降,所以在每帧上使横纵坐标均累加,实现语句为place_x+=5;place_y+=5;改变符号和大小,可以引起字幕文字移动的方向和快慢。
显而易见,place_x累加则向右移动,place_x累减则向左移动,place_y累加则向下移动,place_y累减则向上。
如果字幕文字接近边界,我们设定字幕坐标回到初始0点,实现语句为if(place_x>600)place_x=0;这样可以实现往复滚动,这样更符合网站弹幕的设定。
初始位置横纵坐标均设为100,实现语句为提前定义intplace_x=100;intplace_y=100;
经过以上方法的讨论,可以将字幕正确转化为图像像素点,并在显示器上以平面坐标的形式显示,在显示后可以实现字幕的自由移动。
二、代码和效果图
核心代码实现如下:
/*
*========video_encdec.c========
*
*/
/*CodecEngineincludefiles:
*/
#include
#include
#include
#include
#include
/*BIOSincludefiles:
*/
#include
#include
/*RunTimelibincludefiles:
*/
#include
#include
#include
#include
/*PSPincludefiles:
*/
#include
#include
#include
#include
/*BSLincludefiles*/
#include
//#include
/*VideoParamsDefaults*/
#include
/*VideoEncoderinitializationparam:
*/
#defineVE_MAX_BR(4000000)
/*Alignoncache-lineboundarysinceencoderusesDMA*/
#defineBUFALIGN128
/*Numberofbufferstoallocateforvideocapture+display:
*/
#defineFRAME_BUFF_CNT6
/*ThisexamplesupportseitherPALorNTSCdependingonpositionofJP1*/
#defineSTANDARD_PAL0
#defineSTANDARD_NTSC1
/*VideoEncoderparametersforD1,setdependingonPALvsNTSC:
*/
staticintintraFrameInterval;
staticintinputWidth;
staticintinputHeight;
staticintmaxFrameRate;
/*EncoderInput,Encoderoutput,andDecoderOutputFramesizes*/
staticintframesize;
/*VideoFramebuffers:
*/
staticFVID_Frame*frameBuffTable[FRAME_BUFF_CNT];
staticFVID_Frame*frameBuffPtr=NULL;
/*VideoDriverHandles:
*/
staticFVID_HandlehGioVpfeCcdc=NULL;
staticFVID_HandlehGioVpbeVid0=NULL;
staticFVID_HandlehGioVpbeVenc=NULL;
/*Intermediatebufferfortheencodedvideostream:
*/
staticXDAS_Int8*encodedBuf;
/*CodecEngineengineandcodeclabels,definedincfgfile:
*/
staticStringdecoderName="h264dec";
staticStringencoderName="h264enc";
staticStringengineName="encdec";
staticStringprogName="app";
/*Functionprototypes*/
staticVoidinitVE_StaticParams(VIDENC_Params*vencParams);
staticVoidinitVE_DynamicParams(VIDENC_DynamicParams*encDynParams);
staticVoidinitVD_StaticParams(VIDDEC_Params*vdecParams);
staticVoidinitVD_DynamicParams(VIDDEC_DynamicParams*decDynParams);
staticVoidencode_decode(VIDENC_Handleenc,VIDDEC_Handledec);
//staticintread_JP1(void);
/*
*========video_encdec========
*/
/*ARGSUSED*/
Intvideo_encdec(Intargc,Stringargv[])
{
intstatus=0;
intresult;
inti;
Engine_Handlece=NULL;
VIDDEC_Handledec=NULL;
VIDENC_Handleenc=NULL;
VIDENC_StatusencStatus;
VIDENC_ParamsvencParams;
VIDENC_DynamicParamsencDynParams;
VIDDEC_StatusdecStatus;
VIDDEC_ParamsvdecParams;
VIDDEC_DynamicParamsdecDynParams;
intstandard;
/*Setvideodisplay/capturedriverparamstodefaults*/
PSP_VPFE_TVP5146_ConfigParamstvp5146Params=
VID_PARAMS_TVP5146_DEFAULT;
PSP_VPFECcdcConfigParamsvpfeCcdcConfigParams=
VID_PARAMS_CCDC_DEFAULT_D1;
PSP_VPBEOsdConfigParamsvpbeOsdConfigParams=
VID_PARAMS_OSD_DEFAULT_D1;
PSP_VPBEVencConfigParamsvpbeVencConfigParams;
printf("video_encdecstarted.\n");
//standard=read_JP1();
standard=STANDARD_PAL;
/*Updatedisplay/captureparamsbasedonvideostandard(PAL/NTSC)*/
if(standard==STANDARD_PAL){
inputWidth=720;
inputHeight=576;
intraFrameInterval=25;
maxFrameRate=25000;
vpbeVencConfigParams.displayStandard=PSP_VPBE_DISPLAY_PAL_INTERLACED_COMPOSITE;
}
else{
inputWidth=720;
inputHeight=480;
intraFrameInterval=30;
maxFrameRate=30000;
vpbeVencConfigParams.displayStandard=PSP_VPBE_DISPLAY_NTSC_INTERLACED_COMPOSITE;
}
framesize=(inputWidth*inputHeight*2*sizeof(Int8));
vpfeCcdcConfigParams.height=vpbeOsdConfigParams.height=inputHeight;
vpfeCcdcConfigParams.width=vpbeOsdConfigParams.width=inputWidth;
vpfeCcdcConfigParams.pitch=vpbeOsdConfigParams.pitch=inputWidth*2;
/*InitializeVideoDisplayDriver:
*/
/*createvideoinputchannel*/
if(status==0){
PSP_VPFEChannelParamsvpfeChannelParams;
vpfeChannelParams.id=PSP_VPFE_CCDC;
vpfeChannelParams.params=(PSP_VPFECcdcConfigParams*)&vpfeCcdcConfigParams;
hGioVpfeCcdc=FVID_create("/VPFE0",IOM_INOUT,NULL,&vpfeChannelParams,NULL);
status=(hGioVpfeCcdc==NULL?
-1:
0);
}
/*createvideooutputchannel,plane0*/
if(status==0){
PSP_VPBEChannelParamsvpbeChannelParams;
vpbeChannelParams.id=PSP_VPBE_VIDEO_0;
vpbeChannelParams.params=(PSP_VPBEOsdConfigParams*)&vpbeOsdConfigParams;
hGioVpbeVid0=FVID_create("/VPBE0",IOM_INOUT,NULL,&vpbeChannelParams,NULL);
status=(hGioVpbeVid0==NULL?
-1:
0);
}
/*createvideooutputchannel,venc*/
if(status==0){
PSP_VPBEChannelParamsvpbeChannelParams;
vpbeChannelParams.id=PSP_VPBE_VENC;
vpbeChannelParams.params=(PSP_VPBEVencConfigParams*)&vpbeVencConfigParams;
hGioVpbeVenc=FVID_create("/VPBE0",IOM_INOUT,NULL,&vpbeChannelParams,NULL);
status=(hGioVpbeVenc==NULL?
-1:
0);
}
/*configuretheTVP5146videodecoder*/
if(status==0){
result=FVID_control(hGioVpfeCcdc,
VPFE_ExtVD_BASE+PSP_VPSS_EXT_VIDEO_DECODER_CONFIG,&tvp5146Params);
status=(result==IOM_COMPLETED?
0:
-1);
}
/*allocatedisplay/captureframebuffers*/
for(i=0;iframeBuffTable[i]=NULL;
}
if(status==0){
for(i=0;iresult=FVID_allocBuffer(hGioVpfeCcdc,&frameBuffTable[i]);
status=(result==IOM_COMPLETED&&frameBuffTable[i]!
=NULL?
0:
-1);
}
}
/*primeupthevideocapturechannel*/
if(status==0){
FVID_queue(hGioVpfeCcdc,frameBuffTable[0]);
FVID_queue(hGioVpfeCcdc,frameBuffTable[1]);
FVID_queue(hGioVpfeCcdc,frameBuffTable[2]);
}
/*primeupthevideodisplaychannel*/
if(status==0){
FVID_queue(hGioVpbeVid0,frameBuffTable[3]);
FVID_queue(hGioVpbeVid0,frameBuffTable[4]);
FVID_queue(hGioVpbeVid0,frameBuffTable[5]);
}
/*grabfirstbufferfrominputqueue*/
if(status==0){
FVID_dequeue(hGioVpfeCcdc,&frameBuffPtr);
}
if(status!
=0){
gotoend;
}
/*AllocateEncoderoutputbuffer:
*/
/*encodedBuf=(XDAS_Int8*)Memory_contigAlloc(framesize,BUFALIGN);
if(encodedBuf==NULL){
gotoend;
}
else{
Memory_cacheWbInv(encodedBuf,framesize);
}
*/
/*useenginetoencode,thendecodethedata*/
encode_decode(enc,dec);
end:
/*FreeVideoDriverresources:
*/
if(hGioVpfeCcdc){
for(i=0;iFVID_freeBuffer(hGioVpfeCcdc,frameBuffTable[i]);
}
}
/*DeleteChannels*/
if(hGioVpfeCcdc){
FVID_delete(hGioVpfeCcdc);
}
if(hGioVpbeVid0){
FVID_delete(hGioVpbeVid0);
}
if(hGioVpbeVenc){
FVID_delete(hGioVpbeVenc);
}
printf("video_encdecdone.\n");
return(0);
}
/*
*========initVE_StaticParams========
*/
staticVoidinitVE_StaticParams(VIDENC_Params*vencParams)
{
/*SetConstantBitRate,YUV422Interlaced,littleendian:
*/
vencParams->size=sizeof(VIDENC_Params);
vencParams->encodingPreset=XDM_DEFAULT;
vencParams->rateControlPreset=IVIDEO_LOW_DELAY;
vencParams->maxHeight=inputHeight;
vencParams->maxWidth=inputWidth;
vencParams->maxFrameRate=maxFrameRate;
vencParams->maxBitRate=VE_MAX_BR;
vencParams->dataEndianness=XDM_BYTE;
vencParams->maxInterFrameInterval=0;
vencParams->inputChromaFormat=XDM_YUV_422ILE;
vencParams->inputContentType=IVIDEO_PROGRESSIVE;
return;
}
/*
*========initVE_DynamicParams========
*/
staticVoidinitVE_DynamicParams(VIDENC_DynamicParams*encDynParams)
{
encDynParams->inputHeight=inputHeight;
encDynParams->inputWidth=inputWidth;
encDynParams->refFrameRate=maxFrameRate;
encDynParams->targetFrameRate=maxFrameRate;
encDynParams->targetBitRate=VE_MAX_BR;
encDynParams->intraFrameInterval=intraFrameInterval;
encDynParams->generateHeader=XDM_ENCODE_AU;
encDynParams->captureWidth=0;
encDynParams->forceIFrame=0;
return;
}
/*
*========initVD_StaticParams========
*/
staticVoidinitVD_StaticParams(VIDDEC_Params*vdecParams)
{
/*SetConstantBitRate,YUV422Interlaced,littleendian:
*/
vdecParams->size=sizeof(VIDDEC_Params);
vdecParams->maxHeight=inputHeight;
vdecParams->maxWidth=inputWidth;
vdecParams->maxFrameRate=0;
vdecParams->maxBitRate=0;
vdecParams->dataEnd