⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 h263inter.cpp

📁 这是G.723和G.729的音频编解码的源代码
💻 CPP
字号:

#include "stdafx.h"
#include "color.h"
#include "DBitstream.h"
#include "sactable.h"
#include "sad.h"
#include "Dh263class.h"

extern "C"
	{void MMXInterColorP(BYTE *Src,BYTE *Dst,int pixels,int lines,int ImgSize);
	 void MMXInterLumP(BYTE *Src,BYTE *Dst,int pixels,int lines,int ImgSize);
	}

int DH263Picture::DecodeINTERPicture(YUVData CurLoss,YUVData PrevRec,DBitStream *DecodeStream)
{	YUVData PrevInter,EdgeRec;
	int GN=0,i,j;
	BOOL GOBFlag=TRUE;
	SAD *SADeco;
	if (PictureInfo.SACMode)
		SADeco=new SAD(DecodeStream);

	if (PictureInfo.UMVMode)
		{PrevInter.hImage=GlobalAlloc(GHND,6*(Height+32)*(Width+32)+8);
		 PrevInter.Image=(BYTE *)GlobalLock(PrevInter.hImage);
		 if ((int)PrevInter.Image%8)
			PrevInter.Image+=(8-(int)PrevInter.Image%8);

		 PrevInter.Y=PrevInter.Image;
		 PrevInter.U=PrevInter.Image+4*(Width+32)*(Height+32);
		 PrevInter.V=PrevInter.Image+5*(Width+32)*(Height+32);

		 EdgeRec.hImage=GlobalAlloc(GHND,(Height+32)*(Width+32)+(Height+32)*(Width+32)/2+8);
		 EdgeRec.Image=(BYTE *)GlobalLock(EdgeRec.hImage);
		 if ((int)EdgeRec.Image%8)
			EdgeRec.Image+=(8-(int)EdgeRec.Image%8);

		 EdgeRec.Y=EdgeRec.Image;
		 EdgeRec.U=EdgeRec.Image+(Width+32)*(Height+32);
		 EdgeRec.V=EdgeRec.Image+(Width+32)*(Height+32)+(Width+32)*(Height+32)/4;
		 
		 MakeEdgeData(PrevRec,EdgeRec,Width,Height,16);
		 InterpolateImage(EdgeRec,PrevInter,Width+32,Height+32);

		 PrevInter.Y=PrevInter.Image+16*(Width+32)+16;
		 PrevInter.U=PrevInter.Image+4*(Width+32)*(Height+32)+8*(Width/2+16)+8;
		 PrevInter.V=PrevInter.Image+5*(Width+32)*(Height+32)+8*(Width/2+16)+8;

		 StrPrevInt.LumIntPel=EdgeRec.Y+16*(Width+32)+16;
		 StrPrevInt.CBIntPel=EdgeRec.U+8*(Width/2+16)+8;
		 StrPrevInt.CRIntPel=EdgeRec.V+8*(Width/2+16)+8;
		}
	else
		{PrevInter.hImage=GlobalAlloc(GHND,6*ImageSize+8);
		 PrevInter.Image=(BYTE *)GlobalLock(PrevInter.hImage);
		 if ((int)PrevInter.Image%8)
			PrevInter.Image+=(8-(int)PrevInter.Image%8);
		 PrevInter.Y=PrevInter.Image;
		 PrevInter.U=PrevInter.Image+4*ImageSize;
		 PrevInter.V=PrevInter.Image+5*ImageSize;
		 InterpolateImage(PrevRec,PrevInter,Width,Height);
		}

	MB->MBBits.DQUANTBits=2;
	memset(MB->QCoeff,0,384*sizeof(short));

	MB->QP=PictureInfo.PQUANT;
  	for (i=0;i<HMB;i++)
		{if (i&&GOBFlag)
			 {GN=Group->DecodeGOBHeader(PictureInfo.CPM,DecodeStream);
			  MB->QP=Group->GOBInfo.GQUANT;
			 }
		 if (GN!=i)
			{GOBFlag=FALSE;
			 continue;
			}
		 else
			GOBFlag=TRUE;
		 if (PictureInfo.SACMode)
			SADeco->DecodeReset();

		 for (j=0;j<WMB;j++)
			{MB->CBP=0;
			 if (!PictureInfo.SACMode)
				MB->DecodeMBHeader(DecodeStream,j,i);
			 else
				MB->SACDecodeMBHeader(SADeco,j,i);
			 if (MB->CBP==0&&(MB->Mode==MODE_INTER||MB->Mode == MODE_INTER_Q||MB->Mode==MODE_INTER4V))
				{memset(MB->MBData.lum,0,sizeof(short)*MB_SIZE*MB_SIZE);
				 memset(MB->MBData.CB,0,sizeof(short)*MB_SIZE*MB_SIZE/4);
				 memset(MB->MBData.CR,0,sizeof(short)*MB_SIZE*MB_SIZE/4);
				}
			 else
				{if (!PictureInfo.SACMode)
					MB->DecodeCoeff(DecodeStream);
				 else
					MB->SACDecodeCoeff(SADeco);
				 MB->DecodeMBData();
				 memset(MB->QCoeff,0,384*sizeof(short));
				}
			 
			 if (MB->Mode==MODE_INTER4V)
				MB->MB_Recon_P4V(CurLoss,PrevInter,
					j*MB_SIZE,i*MB_SIZE);
			 else if (MB->Mode==MODE_INTRA||MB->Mode==MODE_INTRA_Q)
				MB->FillRecon(CurLoss,i*MB_SIZE,j*MB_SIZE);
			 else
				MB->MB_Recon_P(CurLoss,PrevInter,
					j*MB_SIZE,i*MB_SIZE);
			}
		}
	DecodeStream->FlushBits(PictureBits.EOSBits);

	GlobalUnlock(PrevInter.hImage);
	GlobalFree(PrevInter.hImage);
	if (PictureInfo.UMVMode)
		{GlobalUnlock(EdgeRec.hImage);
		 GlobalFree(EdgeRec.hImage);
		}
	if (PictureInfo.SACMode) 
		delete SADeco;
	
	return TRUE;
}

void DH263Picture::MakeEdgeData(YUVData src,YUVData dst, int width,
		   int height, int edge)
{	int j,UVHeight,UVWidth,UVEdge;
	BYTE *p1,*p2,*o1;
		
	p1 = dst.Y+edge*(width+2*edge)+edge;
	o1 = src.Y;
	for (j = 0; j < height;j++)
		{memcpy(p1,o1,width);
		 p1 +=( width + edge*2);
		 o1 += width;
		}

	p1=dst.Y+edge;
	o1=src.Y;
	for (j=0;j<edge;j++)
		{memcpy(p1,o1,width);
		 p1+=(width+edge*2);
		}
	p1=dst.Y+(width+edge*2)*(height+edge)+edge;
	o1=src.Y+width*(height-1);
	for (j=0;j<edge;j++)
		{memcpy(p1,o1,width);
		 p1+=(width+edge*2);
		}

	p1=dst.Y;
	p2=dst.Y+width+edge;
	for (j=0;j<height+2*edge;j++)
		{memset(p1,*(p1+edge),edge);
		 memset(p2,*(p2-1),edge);
		 p1+=(width+edge*2);
		 p2+=(width+edge*2);
		}

	UVHeight=height/2;
	UVWidth=width/2;
	UVEdge=edge/2;

	p1 = dst.U+UVEdge*(UVWidth+2*UVEdge)+UVEdge;
	o1 = src.U;
	for (j = 0; j < UVHeight;j++)
		{memcpy(p1,o1,UVWidth);
		 p1 +=(UVWidth + UVEdge*2);
		 o1 += UVWidth;
		}

	p1=dst.U+UVEdge;
	o1=src.U;
	for (j=0;j<UVEdge;j++)
		{memcpy(p1,o1,UVWidth);
		 p1+=(UVWidth+UVEdge*2);
		}
	p1=dst.U+(UVWidth+UVEdge*2)*(UVHeight+UVEdge)+UVEdge;
	o1=src.U+UVWidth*(UVHeight-1);
	for (j=0;j<UVEdge;j++)
		{memcpy(p1,o1,UVWidth);
		 p1+=(UVWidth+UVEdge*2);
		}

	p1=dst.U;
	p2=dst.U+UVWidth+UVEdge;
	for (j=0;j<UVHeight+2*UVEdge;j++)
		{memset(p1,*(p1+UVEdge),UVEdge);
		 memset(p2,*(p2-1),UVEdge);
		 p1+=(UVWidth+UVEdge*2);
		 p2+=(UVWidth+UVEdge*2);
		}


	p1 = dst.V+UVEdge*(UVWidth+2*UVEdge)+UVEdge;
	o1 = src.V;
	for (j = 0; j < UVHeight;j++)
		{memcpy(p1,o1,UVWidth);
		 p1 +=(UVWidth + UVEdge*2);
		 o1 += UVWidth;
		}

	p1=dst.V+UVEdge;
	o1=src.V;
	for (j=0;j<UVEdge;j++)
		{memcpy(p1,o1,UVWidth);
		 p1+=(UVWidth+UVEdge*2);
		}
	p1=dst.V+(UVWidth+UVEdge*2)*(UVHeight+UVEdge)+UVEdge;
	o1=src.V+UVWidth*(UVHeight-1);
	for (j=0;j<UVEdge;j++)
		{memcpy(p1,o1,UVWidth);
		 p1+=(UVWidth+UVEdge*2);
		}

	p1=dst.V;
	p2=dst.V+UVWidth+UVEdge;
	for (j=0;j<UVHeight+2*UVEdge;j++)
		{memset(p1,*(p1+UVEdge),UVEdge);
		 memset(p2,*(p2-1),UVEdge);
		 p1+=(UVWidth+UVEdge*2);
		 p2+=(UVWidth+UVEdge*2);
		}

}

void DH263Picture::InterpolateImage(YUVData Reference,YUVData InterFrame,
					int pixels,int lines)
{	BYTE *Src,*Dst;
	int ImgSize;

	StrPrevInt.Lines=lines;
	StrPrevInt.Pixels=pixels;
	StrPrevInt.LumIntPel=Reference.Y;
	StrPrevInt.CBIntPel=Reference.U;
	StrPrevInt.CRIntPel=Reference.V;

	ImgSize=pixels*lines;
	Src=Reference.Y+ImgSize-16;
	Dst=InterFrame.Y+4*ImgSize-16;
	
	MMXInterLumP(Src,Dst,pixels,lines,-ImgSize);

	pixels/=2;
	lines/=2;

	ImgSize=pixels*lines;
	Src=Reference.U+ImgSize-8;
	Dst=InterFrame.U+4*ImgSize-8;

	MMXInterColorP(Src,Dst,pixels,lines,-ImgSize);

	Src=Reference.V+ImgSize-8;
	Dst=InterFrame.V+4*ImgSize-8;

	MMXInterColorP(Src,Dst,pixels,lines,-ImgSize);
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -