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

📄 newpb.cpp

📁 这是G.723和G.729的音频编解码的源代码
💻 CPP
📖 第 1 页 / 共 3 页
字号:
						{VectorH=-2*y;
						 ExitFlag=TRUE;
						 break;
						}
					 else if ((y+MB_SIZE)*2+VectorH>Height*2)
						{VectorH=2*(Height-(y+MB_SIZE));
						 ExitFlag=TRUE;
						 break;
						}
					 if (x*2+VectorW<0)
						{VectorW=-2*x;
						 ExitFlag=TRUE;
						 break;
						}
					 else if ((x+MB_SIZE)*2+VectorW>Width*2)
						{VectorW=2*(Width-(x+MB_SIZE));
						 ExitFlag=TRUE;
						 break;
						}
					}

				 LoadMBRefer(PrevInter.Y,&Ref[(k/2*MB_SIZE/2)*MB_SIZE+k%2*MB_SIZE/2],(y+k/2*MB_SIZE/2)*2+VectorH,
					(x+k%2*MB_SIZE/2)*2+VectorW,2*RefWidth,MB_SIZE,(m_pPic->StrPrevInt));
				}
			  if (ExitFlag)
				{vmx=0;
				 vmy=0;
				 break;
				}

			   MAD=CalMADLast(Ref,BCur,Width);
			   if (MAD<MinMAD)
				{MinMAD=MAD;
				 vmx=j;
				 vmy=i;
				}
			  }
			 (m_pPic->MVPB)[Ori].x=vmx/2;
			 (m_pPic->MVPB)[Ori].x_half=vmx%2;
			 (m_pPic->MVPB)[Ori].y=vmy/2;
			 (m_pPic->MVPB)[Ori].y_half=vmy%2;

			 for (k=0;k<4;k++)
				{VectorW=TRB*(2*(m_pPic->MVAP)[Ori][k].x+(m_pPic->MVAP)[Ori][k].x_half)/TRD+vmx;
				 VectorH=TRB*(2*(m_pPic->MVAP)[Ori][k].y+(m_pPic->MVAP)[Ori][k].y_half)/TRD+vmy;
				 LoadRefer(PrevInter.Y,PredData.lum+64*k,(y+k/2*MB_SIZE/2)*2+VectorH,
					(x+k%2*MB_SIZE/2)*2+VectorW,2*RefWidth,MB_SIZE/2,(m_pPic->StrPrevInt));
				}

			 MVB.x=(vmx-2*(m_pPic->MV)[Ori].x-(m_pPic->MV)[Ori].x_half)/2;
			 MVB.x_half=(vmx-2*(m_pPic->MV)[Ori].x-(m_pPic->MV)[Ori].x_half)%2;
			 MVB.y=(vmy-2*(m_pPic->MV)[Ori].y-(m_pPic->MV)[Ori].y_half)/2;
			 MVB.y_half=(vmy-2*(m_pPic->MV)[Ori].y-(m_pPic->MV)[Ori].y_half)%2;

			 pLoss=CurLoss.Y+y*Width+x;
			 for (nv = 0; nv <= 1; nv++) 
			  for (nh = 0; nh <= 1; nh++) 
				{MVB.x=(vmx+(TRB-TRD)*(2*(m_pPic->MVAP)[Ori][nv*2+nh].x+(m_pPic->MVAP)[Ori][nv*2+nh].x_half)/TRD)/2;
				 MVB.x_half=(vmx+(TRB-TRD)*(2*(m_pPic->MVAP)[Ori][nv*2+nh].x+(m_pPic->MVAP)[Ori][nv*2+nh].x_half)/TRD)%2;
				 MVB.y=(vmy+(TRB-TRD)*(2*(m_pPic->MVAP)[Ori][nv*2+nh].y+(m_pPic->MVAP)[Ori][nv*2+nh].y_half)/TRD)/2;
				 MVB.y_half=(vmy+(TRB-TRD)*(2*(m_pPic->MVAP)[Ori][nv*2+nh].y+(m_pPic->MVAP)[Ori][nv*2+nh].y_half)/TRD)%2;
			     ystart=nv*8 + max(0,(-MVB.y*2-MVB.y_half+1)/2-nv*8);
				 ystop=nv*8 + min(7,15-(MVB.y*2+MVB.y_half+1)/2-nv*8);
				 xstart=nh*8 + max(0,(-MVB.x*2-MVB.x_half+1)/2-nh*8);
				 xstop=nh*8 + min(7,15-(MVB.x*2+MVB.x_half+1)/2-nh*8);
				 AP_BiDirLumPred(ystart,ystop,xstart,xstop,pLoss,MVB);
				}

			 BCur=BSrc.Y+y*Width+x;
			 for (k=0;k<4;k++)
				 MMXPredAPBlock(BData.lum+k/2*128+k%2*8,
					BCur+(k/2*MB_SIZE/2)*Width+k%2*MB_SIZE/2,PredData.lum+k*64,Width);

			 VectorW=TRB*(2*(m_pPic->MVAP)[Ori][0].x+(m_pPic->MVAP)[Ori][0].x_half
						+2*(m_pPic->MVAP)[Ori][1].x+(m_pPic->MVAP)[Ori][1].x_half
						+2*(m_pPic->MVAP)[Ori][2].x+(m_pPic->MVAP)[Ori][2].x_half
						+2*(m_pPic->MVAP)[Ori][3].x+(m_pPic->MVAP)[Ori][3].x_half)/TRD+4*vmx;
			 VectorH=TRB*(2*(m_pPic->MVAP)[Ori][0].y+(m_pPic->MVAP)[Ori][0].y_half
						+2*(m_pPic->MVAP)[Ori][1].y+(m_pPic->MVAP)[Ori][1].y_half
						+2*(m_pPic->MVAP)[Ori][2].y+(m_pPic->MVAP)[Ori][2].y_half
						+2*(m_pPic->MVAP)[Ori][3].y+(m_pPic->MVAP)[Ori][3].y_half)/TRD+4*vmy;
			 if (VectorW>=0)
				VectorW=VectorW/16*2+MVCHR[VectorW%16];
			 else
				VectorW=VectorW/16*2-MVCHR[-(VectorW%16)];
			 if (VectorH>=0)
				VectorH=VectorH/16*2+MVCHR[VectorH%16];
			 else
				VectorH=VectorH/16*2-MVCHR[-(VectorH%16)];

			 BCur=BSrc.U+y/2*Width/2+x/2;
			 LoadCBRefer(PrevInter.U,PredData.CB,y+VectorH,x+VectorW,RefWidth,MB_SIZE/2,(m_pPic->StrPrevInt));
			 BCur=BSrc.V+y/2*Width/2+x/2;
			 LoadCRRefer(PrevInter.V,PredData.CR,y+VectorH,x+VectorW,RefWidth,MB_SIZE/2,(m_pPic->StrPrevInt));

			 VectorW=(TRB-TRD)*(2*(m_pPic->MVAP)[Ori][0].x+(m_pPic->MVAP)[Ori][0].x_half+
								2*(m_pPic->MVAP)[Ori][1].x+(m_pPic->MVAP)[Ori][1].x_half+
								2*(m_pPic->MVAP)[Ori][2].x+(m_pPic->MVAP)[Ori][2].x_half+
								2*(m_pPic->MVAP)[Ori][3].x+(m_pPic->MVAP)[Ori][3].x_half)/TRD+4*vmx;
			 VectorH=(TRB-TRD)*(2*(m_pPic->MVAP)[Ori][0].y+(m_pPic->MVAP)[Ori][0].y_half+
								2*(m_pPic->MVAP)[Ori][1].y+(m_pPic->MVAP)[Ori][1].y_half+
								2*(m_pPic->MVAP)[Ori][2].y+(m_pPic->MVAP)[Ori][2].y_half+
								2*(m_pPic->MVAP)[Ori][3].y+(m_pPic->MVAP)[Ori][3].y_half)/TRD+4*vmy;
			 if (VectorW>=0)
				VectorW=VectorW/16*2+MVCHR[VectorW%16];
			 else
				VectorW=VectorW/16*2-MVCHR[-(VectorW%16)];
			 if (VectorH>=0)
				VectorH=VectorH/16*2+MVCHR[VectorH%16];
			 else
				VectorH=VectorH/16*2-MVCHR[-(VectorH%16)];

			 MVB.x=VectorW/2;
			 MVB.x_half=VectorW%2;
			 MVB.y=VectorH/2;
			 MVB.y_half=VectorH%2;

			 pLoss=CurLoss.U+y/2*Width/2+x/2;
			 ystart=max(0,(-MVB.y*2-MVB.y_half+1)/2);
			 ystop=min(7,7-(MVB.y*2+MVB.y_half+1)/2);
			 xstart=max(0,(-MVB.x*2-MVB.x_half+1)/2);
			 xstop=min(7,7-(MVB.x*2+MVB.x_half+1)/2);
			 BiDirCBPred(ystart,ystop,xstart,xstop,pLoss,MVB);

			 BCur=BSrc.U+y/2*Width/2+x/2;
			 MMXPredBlock(BData.CB,BCur,PredData.CB,Width/2);
			 pLoss=CurLoss.V+y/2*Width/2+x/2;
			 BiDirCRPred(ystart,ystop,xstart,xstop,pLoss,MVB);

			 BCur=BSrc.V+y/2*Width/2+x/2;
			 MMXPredBlock(BData.CR,BCur,PredData.CR,Width/2);
			}
		}
}

void CH263MB::MB_Recon_B(YUVData BLoss,int x, int y)
{	int k;
	BYTE *BCur;
	
	//Note:The following program of PB-Frame Mode is
	//designed only for the condition when TRD=2&TRB=1.
	//That is only one frame is skipped as B-frame.
	if (Mode!=MODE_INTER4V)
		{BCur=BLoss.Y+y*Width+x;
	 	 MMXReconMB(BCur,PredData.lum,BData.lum,Width);
		 BCur=BLoss.U+y/2*Width/2+x/2;
		 MMXReconBlock(BCur,PredData.CB,BData.CB,Width/2);
		 BCur=BLoss.V+y/2*Width/2+x/2;
		 MMXReconBlock(BCur,PredData.CR,BData.CR,Width/2);
		}
	else
		{//PB mode prediction for INTER4V mode
		 BCur=BLoss.Y+y*Width+x;
		 for (k=0;k<4;k++)
			MMXReconAPBlock(BCur+k/2*MB_SIZE/2*Width+k%2*MB_SIZE/2,
				PredData.lum+k*64,
				BData.lum+k/2*128+k%2*8,
				Width);
		 BCur=BLoss.U+y/2*Width/2+x/2;
		 MMXReconBlock(BCur,PredData.CB,BData.CB,Width/2);
		 BCur=BLoss.V+y/2*Width/2+x/2;
		 MMXReconBlock(BCur,PredData.CR,BData.CR,Width/2);
		}

}

void CH263MB::BiDirLumPred(int ystart,int ystop,int xstart,int xstop,BYTE *CurLossPtr,MotionVector MVB)
{	register int i,j;

	if ((!MVB.x_half)&&(!MVB.y_half))
		{for (i=ystart;i<=ystop;i++)
			for (j=xstart;j<=xstop;j++)
				{PredData.lum[i*MB_SIZE+j]=(PredData.lum[i*MB_SIZE+j]+
					 CurLossPtr[(i+MVB.y)*Width+(j+MVB.x)])/2;
				}
		}
	else if ((!MVB.x_half)&&(MVB.y_half))
		{for (i=ystart;i<=ystop;i++)
			for (j=xstart;j<=xstop;j++)
				{PredData.lum[i*MB_SIZE+j]=((CurLossPtr[(i+MVB.y)*Width+(j+MVB.x)]+
					 CurLossPtr[(i+MVB.y+MVB.y_half)*Width+(j+MVB.x)])/2+
					 PredData.lum[i*MB_SIZE+j])/2;
				}
		}
	else if ((MVB.x_half)&&(!MVB.y_half))
		{for (i=ystart;i<=ystop;i++)
			for (j=xstart;j<=xstop;j++)
				{PredData.lum[i*MB_SIZE+j]=((CurLossPtr[(i+MVB.y)*Width+(j+MVB.x)]+
					CurLossPtr[(i+MVB.y)*Width+(j+MVB.x+MVB.x_half)])/2+
					PredData.lum[i*MB_SIZE+j])/2;
				}
		}
	else
		{for (i=ystart;i<=ystop;i++)
			for (j=xstart;j<=xstop;j++)
				{PredData.lum[i*MB_SIZE+j]=((CurLossPtr[(i+MVB.y)*Width+(j+MVB.x)]+
					  CurLossPtr[(i+MVB.y)*Width+(j+MVB.x+MVB.x_half)]+
					  CurLossPtr[(i+MVB.y+MVB.y_half)*Width+(j+MVB.x)]+
					  CurLossPtr[(i+MVB.y+MVB.y_half)*Width+(j+MVB.x+MVB.x_half)]+
					  2)/4+PredData.lum[i*MB_SIZE+j])/2;
				}
		}
					
}

void CH263MB::BiDirCBPred(int ystart,int ystop,int xstart,int xstop,BYTE *CurLossPtr,MotionVector MVB)
{	register int i,j;

	if ((!MVB.x_half)&&(!MVB.y_half))
		{for (i=ystart;i<=ystop;i++)
			for (j=xstart;j<=xstop;j++)
				{PredData.CB[i*MB_SIZE/2+j]=
					(PredData.CB[i*MB_SIZE/2+j]+
					 CurLossPtr[(i+MVB.y)*Width/2+(j+MVB.x)])/2;
				}
		}
	else if ((!MVB.x_half)&&(MVB.y_half))
		{for (i=ystart;i<=ystop;i++)
			for (j=xstart;j<=xstop;j++)
				{PredData.CB[i*MB_SIZE/2+j]=
					(PredData.CB[i*MB_SIZE/2+j]+
					 (CurLossPtr[(i+MVB.y)*Width/2+(j+MVB.x)]+
					  CurLossPtr[(i+MVB.y+MVB.y_half)*Width/2+(j+MVB.x)])/2)/2;
				}
		}
	else if ((MVB.x_half)&&(!MVB.y_half))
		{for (i=ystart;i<=ystop;i++)
			for (j=xstart;j<=xstop;j++)
				{PredData.CB[i*MB_SIZE/2+j]=
					(PredData.CB[i*MB_SIZE/2+j]+
					 (CurLossPtr[(i+MVB.y)*Width/2+(j+MVB.x)]+
					  CurLossPtr[(i+MVB.y)*Width/2+(j+MVB.x+MVB.x_half)])/2)/2;
				}
		}
	else
		{for (i=ystart;i<=ystop;i++)
			for (j=xstart;j<=xstop;j++)
				{PredData.CB[i*MB_SIZE/2+j]=
					(PredData.CB[i*MB_SIZE/2+j]+
					 (CurLossPtr[(i+MVB.y)*Width/2+(j+MVB.x)]+
					  CurLossPtr[(i+MVB.y)*Width/2+(j+MVB.x+MVB.x_half)]+
					  CurLossPtr[(i+MVB.y+MVB.y_half)*Width/2+(j+MVB.x)]+
					  CurLossPtr[(i+MVB.y+MVB.y_half)*Width/2+(j+MVB.x+MVB.x_half)]+
					  2)/4)/2;
				}
		}
}

void CH263MB::BiDirCRPred(int ystart,int ystop,int xstart,int xstop,BYTE *CurLossPtr,MotionVector MVB)
{	int i,j;

	if ((!MVB.x_half)&&(!MVB.y_half))
		{for (i=ystart;i<=ystop;i++)
			for (j=xstart;j<=xstop;j++)
				{PredData.CR[i*MB_SIZE/2+j]=
					(PredData.CR[i*MB_SIZE/2+j]+
					 CurLossPtr[(i+MVB.y)*Width/2+(j+MVB.x)])/2;
				}
		}
	else if ((!MVB.x_half)&&(MVB.y_half))
		{for (i=ystart;i<=ystop;i++)
			for (j=xstart;j<=xstop;j++)
				{PredData.CR[i*MB_SIZE/2+j]=
					(PredData.CR[i*MB_SIZE/2+j]+
					 (CurLossPtr[(i+MVB.y)*Width/2+(j+MVB.x)]+
					  CurLossPtr[(i+MVB.y+MVB.y_half)*Width/2+(j+MVB.x)])/2)/2;
				}
		}
	else if ((MVB.x_half)&&(!MVB.y_half))
		{for (i=ystart;i<=ystop;i++)
			for (j=xstart;j<=xstop;j++)
				{PredData.CR[i*MB_SIZE/2+j]=
					(PredData.CR[i*MB_SIZE/2+j]+
					 (CurLossPtr[(i+MVB.y)*Width/2+(j+MVB.x)]+
					  CurLossPtr[(i+MVB.y)*Width/2+(j+MVB.x+MVB.x_half)])/2)/2;
				}
		}
	else
		{for (i=ystart;i<=ystop;i++)
			for (j=xstart;j<=xstop;j++)
				{PredData.CR[i*MB_SIZE/2+j]=
					(PredData.CR[i*MB_SIZE/2+j]+
					 (CurLossPtr[(i+MVB.y)*Width/2+(j+MVB.x)]+
					  CurLossPtr[(i+MVB.y)*Width/2+(j+MVB.x+MVB.x_half)]+
					  CurLossPtr[(i+MVB.y+MVB.y_half)*Width/2+(j+MVB.x)]+
					  CurLossPtr[(i+MVB.y+MVB.y_half)*Width/2+(j+MVB.x+MVB.x_half)]+
					  2)/4)/2;
				}
		}
}

void CH263MB::AP_BiDirLumPred(int ystart,int ystop,int xstart,int xstop,BYTE *CurLossPtr,MotionVector MVB)
{	int i,j,BackPred,k,Ori;

	if ((!MVB.x_half)&&(!MVB.y_half))
		{for (i=ystart;i<=ystop;i++)
			for (j=xstart;j<=xstop;j++)
				{BackPred=CurLossPtr[(i+MVB.y)*Width+(j+MVB.x)];
				 k=i/8*2+j/8;
				 Ori=(i%8)*MB_SIZE/2+(j%8);
				 PredData.lum[k*64+Ori]=(PredData.lum[k*64+Ori]+BackPred)/2;
				}
		}
	else if ((!MVB.x_half)&&(MVB.y_half))
		{for (i=ystart;i<=ystop;i++)
			for (j=xstart;j<=xstop;j++)
				{BackPred=(CurLossPtr[(i+MVB.y)*Width+(j+MVB.x)]+
						  CurLossPtr[(i+MVB.y+MVB.y_half)*Width+(j+MVB.x)])/2;
				 k=i/8*2+j/8;
				 Ori=(i%8)*MB_SIZE/2+(j%8);
				 PredData.lum[k*64+Ori]=(PredData.lum[k*64+Ori]+BackPred)/2;
				}
		}
	else if ((MVB.x_half)&&(!MVB.y_half))
		{for (i=ystart;i<=ystop;i++)
			for (j=xstart;j<=xstop;j++)
				{BackPred=(CurLossPtr[(i+MVB.y)*Width+(j+MVB.x)]+
						  CurLossPtr[(i+MVB.y)*Width+(j+MVB.x+MVB.x_half)])/2;
				 k=i/8*2+j/8;
				 Ori=(i%8)*MB_SIZE/2+(j%8);
				 PredData.lum[k*64+Ori]=(PredData.lum[k*64+Ori]+BackPred)/2;
				}
		}
	else
		{for (i=ystart;i<=ystop;i++)
			for (j=xstart;j<=xstop;j++)
				{BackPred=(CurLossPtr[(i+MVB.y)*Width+(j+MVB.x)]+
						   CurLossPtr[(i+MVB.y)*Width+(j+MVB.x+MVB.x_half)]+
						   CurLossPtr[(i+MVB.y+MVB.y_half)*Width+(j+MVB.x)]+
						   CurLossPtr[(i+MVB.y+MVB.y_half)*Width+(j+MVB.x+MVB.x_half)]+
						   2)/4;

				 k=i/8*2+j/8;
				 Ori=(i%8)*MB_SIZE/2+(j%8);
				 PredData.lum[k*64+Ori]=(PredData.lum[k*64+Ori]+BackPred)/2;
				}
		}
}

⌨️ 快捷键说明

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