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

📄 expandyuv411.cpp

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

#include "stdafx.h"
#include "expandyuv411.h"

CExpandYUV411::CExpandYUV411(int nMaxLength)
{
	m_nMaxLength=nMaxLength;
	m_pbyExpandedPicture=new BYTE[nMaxLength];
}

CExpandYUV411::~CExpandYUV411(void)
{
	if(m_pbyExpandedPicture)
		delete m_pbyExpandedPicture;
}

void CExpandYUV411::CaculateBoundary(BYTE* pbyPicture,BYTE* pbyExpandedPic,int nWidth,int nHeight)
{
	int i;
	int nExpandedWidth=nWidth+nWidth;
	int nExpandedHeight=nHeight+nHeight;

	//corn
	pbyExpandedPic[0]=pbyPicture[0];//Topleft
	pbyExpandedPic[nExpandedWidth-1]=pbyPicture[nWidth-1];//Topright
	pbyExpandedPic[nExpandedWidth*(nExpandedHeight-1)]=pbyPicture[nWidth*(nHeight-1)];//Bottomleft
	pbyExpandedPic[nExpandedWidth*nExpandedHeight-1]=pbyPicture[nWidth*nHeight-1];//Bottomright

	BYTE* pbyExpanded=pbyExpandedPic+1;
	BYTE* pbyPic=pbyPicture;
	//top line
	for(i=1;i<nWidth;i++)
	{
		*pbyExpanded++=(3*pbyPic[i-1]+pbyPic[i]+2)/4;
		*pbyExpanded++=(pbyPic[i-1]+pbyPic[i]*3+2)/4;
	}
	//bottom line
	pbyExpanded=pbyExpandedPic+nExpandedWidth*(nExpandedHeight-1)+1;
	pbyPic=pbyPicture+nWidth*(nHeight-1);
	for(i=1;i<nWidth;i++)
	{
		*pbyExpanded++=(3*pbyPic[i-1]+pbyPic[i]+2)/4;
		*pbyExpanded++=(pbyPic[i-1]+pbyPic[i]*3+2)/4;
	}

	//left column	
	pbyExpanded=pbyExpandedPic+nExpandedWidth;
	pbyPic=pbyPicture+nWidth;
	for(i=1;i<nHeight;i++)
	{
		*pbyExpanded=((*(pbyPic-nWidth))*3+(*pbyPic)+2)/4;
		pbyExpanded+=nExpandedWidth;
		*pbyExpanded=((*(pbyPic-nWidth))+(*pbyPic)*3+2)/4;
		pbyExpanded+=nExpandedWidth;
		pbyPic+=nWidth;
	}

	//right column
	pbyExpanded=pbyExpandedPic+nExpandedWidth*2-1;
	pbyPic=pbyPicture+nWidth*2-1;
	for(i=1;i<nHeight;i++)
	{
		*pbyExpanded=((*(pbyPic-nWidth))*3+(*pbyPic)+2)/4;
		pbyExpanded+=nExpandedWidth;
		*pbyExpanded=((*(pbyPic-nWidth))+(*pbyPic)*3+2)/4;
		pbyExpanded+=nExpandedWidth;
		pbyPic+=nWidth;
	}
}

void CExpandYUV411::CaculateInterior(BYTE* pbyPicture,BYTE* pbyExpandedPic,int nWidth,int nHeight)
{
	int nExpandedWidth=nWidth+nWidth;
	int nExpandedHeight=nHeight+nHeight;
	int i,j;	

	BYTE* pbyExpanded=pbyExpandedPic+nExpandedWidth+1;
	BYTE* pbyPic=pbyPicture;
	
	for(i=1;i<nHeight;i++)
	{
		for(j=1;j<nWidth;j++)
		{
			*pbyExpanded=(9*(*pbyPic)+3*(*(pbyPic+1))+3*(*(pbyPic+nWidth))+(*(pbyPic+nWidth+1))+8)/16;
			*(pbyExpanded+1)=(3*(*pbyPic)+9*(*(pbyPic+1))+(*(pbyPic+nWidth))+3*(*(pbyPic+nWidth+1))+8)/16;
			*(pbyExpanded+nExpandedWidth)=(3*(*pbyPic)+(*(pbyPic+1))+9*(*(pbyPic+nWidth))+3*(*(pbyPic+nWidth+1))+8)/16;
			*(pbyExpanded+nExpandedWidth+1)=((*pbyPic)+3*(*(pbyPic+1))+3*(*(pbyPic+nWidth))+9*(*(pbyPic+nWidth+1))+8)/16;
			pbyExpanded+=2;
			pbyPic++;
		}
		pbyPic++;
		pbyExpanded+=(2+nExpandedWidth);
	}
}

BYTE* CExpandYUV411::ExpandYUV411(BYTE* pbyPicture,int nWidth,int nHeight)//input picture width and height
{
	if(nWidth*nHeight*6>m_nMaxLength)return NULL;
	BYTE* pbyExpandedY=m_pbyExpandedPicture;
	BYTE* pbyExpandedU=m_pbyExpandedPicture+nWidth*nHeight*4;
	BYTE* pbyExpandedV=m_pbyExpandedPicture+nWidth*nHeight*4+nWidth*nHeight;
	BYTE* pbyY=pbyPicture;
	BYTE* pbyU=pbyPicture+nWidth*nHeight;
	BYTE* pbyV=pbyPicture+nWidth*nHeight+nWidth*nHeight/4;
	CaculateBoundary(pbyY,pbyExpandedY,nWidth,nHeight);
	CaculateInterior(pbyY,pbyExpandedY,nWidth,nHeight);

	CaculateBoundary(pbyU,pbyExpandedU,nWidth/2,nHeight/2);
	CaculateInterior(pbyU,pbyExpandedU,nWidth/2,nHeight/2);

	CaculateBoundary(pbyV,pbyExpandedV,nWidth/2,nHeight/2);
	CaculateInterior(pbyV,pbyExpandedV,nWidth/2,nHeight/2);
	return m_pbyExpandedPicture;
}

⌨️ 快捷键说明

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