📄 newpb.cpp
字号:
TempMV.x=VectorW/2;
TempMV.x_half=VectorW%2;
TempMV.y=VectorH/2;
TempMV.y_half=VectorH%2;
if (TempMV.x_half)
{if (VectorW>=0)
VectorW=TempMV.x+1-TempMV.x%2;
else
VectorW=TempMV.x-1-TempMV.x%2;
}
else
VectorW=TempMV.x;
if (TempMV.y_half)
{if (VectorH>=0)
VectorH=TempMV.y+1-TempMV.y%2;
else
VectorH=TempMV.y-1-TempMV.y%2;
}
else
VectorH=TempMV.y;
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));
//CHR component Bi-Directional Prediction
VectorW=2*MVB.x+MVB.x_half;
VectorH=2*MVB.y+MVB.y_half;
if (MVB.x_half)
{if (VectorW>=0)
{MVB.x=(MVB.x+1-MVB.x%2)/2;
MVB.x_half=(MVB.x+1-MVB.x%2)%2;
}
else
{MVB.x=(MVB.x-1-MVB.x%2)/2;
MVB.x_half=(MVB.x-1-MVB.x%2)%2;
}
}
else
{MVB.x=MVB.x/2;
MVB.x_half=MVB.x%2;
}
if (MVB.y_half)
{if (VectorH>=0)
{MVB.y=(MVB.y+1-MVB.y%2)/2;
MVB.y_half=(MVB.y+1-MVB.y%2)%2;
}
else
{MVB.y=(MVB.y-1-MVB.y%2)/2;
MVB.y_half=(MVB.y-1-MVB.y%2)%2;
}
}
else
{MVB.y=MVB.y/2;
MVB.y_half=MVB.y%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);
}
else
{vmyl=VectorH-2;
vmyh=VectorH+2;
vmxl=VectorW-2;
vmxh=VectorW+2;
if (vmyl<-32)
vmyl=-32;
if (vmyh>31)
vmyh=31;
if (vmxl<-32)
vmxl=-32;
if (vmxh>31)
vmxh=31;
if (!Pic.UMVMode)
{if (y*2+vmyl<0)
vmyl=-2*y;
if ((y+MB_SIZE)*2+vmyh>Height*2)
vmyh=2*(Height-(y+MB_SIZE));
if (x*2+vmxl<0)
vmxl=-2*x;
if ((x+MB_SIZE)*2+vmxh>Width*2)
vmxh=2*(Width-(x+MB_SIZE));
}
vmx=VectorW;
vmy=VectorH;
for (i=vmyl;i<=vmyh;i++)
for (j=vmxl;j<=vmxh;j++)
{LoadRefer(PrevInter.Y,PredData.lum,y*2+i,x*2+j,2*RefWidth,MB_SIZE,(m_pPic->StrPrevInt));
MAD=CalMADLast(PredData.lum,BCur,Width);
if (MAD<MinMAD)
{MinMAD=MAD;
vmx=j;
vmy=i;
}
}
(m_pPic->MVPB)[Ori].x=(vmx-VectorW)/2;
(m_pPic->MVPB)[Ori].x_half=(vmx-VectorW)%2;
(m_pPic->MVPB)[Ori].y=(vmy-VectorH)/2;
(m_pPic->MVPB)[Ori].y_half=(vmy-VectorH)%2;
//Luminance component Bi-directional prediction
LoadRefer(PrevInter.Y,PredData.lum,y*2+vmy,x*2+vmx,2*RefWidth,MB_SIZE,(m_pPic->StrPrevInt));
pLoss=CurLoss.Y+y*Width+x;
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;
for (nv = 0; nv <= 1; nv++)
for (nh = 0; nh <= 1; nh++)
{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);
BiDirLumPred(ystart,ystop,xstart,xstop,pLoss,MVB);
}
MMXPredMB(BData.lum,BCur,PredData.lum,Width);
//CHR component Forward directional prediction
TempMV.x=vmx/2;
TempMV.x_half=vmx%2;
TempMV.y=vmy/2;
TempMV.y_half=vmy%2;
if (TempMV.x_half)
{if (vmx>=0)
VectorW=TempMV.x+1-TempMV.x%2;
else
VectorW=TempMV.x-1-TempMV.x%2;
}
else
VectorW=TempMV.x;
if (TempMV.y_half)
{if (vmy>=0)
VectorH=TempMV.y+1-TempMV.y%2;
else
VectorH=TempMV.y-1-TempMV.y%2;
}
else
VectorH=TempMV.y;
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=2*MVB.x+MVB.x_half;
VectorH=2*MVB.y+MVB.y_half;
if (MVB.x_half)
{if (VectorW>=0)
{MVB.x=(MVB.x+1-MVB.x%2)/2;
MVB.x_half=(MVB.x+1-MVB.x%2)%2;
}
else
{MVB.x=(MVB.x-1-MVB.x%2)/2;
MVB.x_half=(MVB.x-1-MVB.x%2)%2;
}
}
else
{MVB.x=MVB.x/2;
MVB.x_half=MVB.x%2;
}
if (MVB.y_half)
{if (VectorH>=0)
{MVB.y=(MVB.y+1-MVB.y%2)/2;
MVB.y_half=(MVB.y+1-MVB.y%2)%2;
}
else
{MVB.y=(MVB.y-1-MVB.y%2)/2;
MVB.y_half=(MVB.y-1-MVB.y%2)%2;
}
}
else
{MVB.y=MVB.y/2;
MVB.y_half=MVB.y%2;
}
//CHR component bi-directional prediction
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);
//CR Component Bi-directional prediction
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);
}
}
else
{MinMAD=0;
for (k=0;k<4;k++)
{VectorW=TRB*(2*(m_pPic->MVAP)[Ori][k].x+(m_pPic->MVAP)[Ori][k].x_half)/TRD;
VectorH=TRB*(2*(m_pPic->MVAP)[Ori][k].y+(m_pPic->MVAP)[Ori][k].y_half)/TRD;
BCur=BSrc.Y+(y+k/2*MB_SIZE/2)*Width+x+k%2*MB_SIZE/2;
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));
MinMAD+=CalMADSub(PredData.lum+64*k,BCur,MB_SIZE/2,Width);
}
if (MinMAD<=500)
{ZeroVec((m_pPic->MVPB)[Ori]);
//Luminance Bi-directional prediction
pLoss=CurLoss.Y+y*Width+x;
for (nv = 0; nv <= 1; nv++)
for (nh = 0; nh <= 1; nh++)
{MVB.x=(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=(TRB-TRD)*(2*(m_pPic->MVAP)[Ori][nv*2+nh].x+(m_pPic->MVAP)[Ori][nv*2+nh].x_half)/TRD%2;
MVB.y=(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=(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);
//CHR component Forward directional prediction
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;
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;
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));
//CHR component bi-directional prediction
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;
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;
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);
}
else
{BYTE Ref[MB_SIZE*MB_SIZE];
BOOL ExitFlag;
BCur=BSrc.Y+y*Width+x;
vmx=0;
vmy=0;
for (i=-2;i<2;i++)
for (j=-2;j<2;j++)
{ExitFlag=FALSE;
for (k=0;k<4;k++)
{VectorW=TRB*(2*(m_pPic->MVAP)[Ori][k].x+(m_pPic->MVAP)[Ori][k].x_half)/TRD+j;
VectorH=TRB*(2*(m_pPic->MVAP)[Ori][k].y+(m_pPic->MVAP)[Ori][k].y_half)/TRD+i;
if (VectorH<-32)
{VectorH=-32;
ExitFlag=TRUE;
break;
}
else if (VectorH>31)
{VectorH=31;
ExitFlag=TRUE;
break;
}
if (VectorW<-32)
{VectorW=-32;
ExitFlag=TRUE;
break;
}
else if (VectorW>31)
{VectorW=31;
ExitFlag=TRUE;
break;
}
if (!Pic.UMVMode)
{if (y*2+VectorH<0)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -