📄 diamond_search.c
字号:
i = 0;
j = 0;
xPos=tss_inout->mv_x>>1;
yPos=tss_inout->mv_y>>1;
if (((xPos-1) >=-15) && ((yPos-1) >=-15) &&((xPos-1) <=15) && ((yPos-1) <=15) ) {
xhSAD8x8_8u32s_C1R_C(pCur, 384, pRef-48-1, 48, &cSAD, 12);
// ippiSAD16x16_8u32s(pCur, step, pRef+(yPos-1)*step+xPos-1, step, &cSAD, IPPVC_MC_APX_HH);
if (cSAD < bSAD) {
i = -1;
j = -1;
bSAD = cSAD;
}
}
if (((xPos+1) >=-15) && ((yPos-1) >=-15) &&((xPos+1) <=15) && ((yPos-1) <=15) ) {
xhSAD8x8_8u32s_C1R_C(pCur, 384, pRef-48+1, 48, &cSAD, 12);
// ippiSAD16x16_8u32s(pCur, step, pRef+(yPos-1)*step+xPos-1, step, &cSAD, IPPVC_MC_APX_HH);
if (cSAD < bSAD) {
i = 1;
j = -1;
bSAD = cSAD;
}
}
if (((xPos-1) >=-15) && ((yPos+1) >=-15) &&((xPos-1) <=15) && ((yPos+1) <=15) ) {
xhSAD8x8_8u32s_C1R_C(pCur, 384, pRef+48-1, 48, &cSAD, 12);
// ippiSAD16x16_8u32s(pCur, step, pRef+(yPos-1)*step+xPos-1, step, &cSAD, IPPVC_MC_APX_HH);
if (cSAD < bSAD) {
i = -1;
j = 1;
bSAD = cSAD;
}
}
if (((xPos+1) >=-15) && ((yPos+1) >=-15) &&((xPos+1) <=15) && ((yPos+1) <=15) ) {
xhSAD8x8_8u32s_C1R_C(pCur, 384, pRef+48+1, 48, &cSAD, 12);
// ippiSAD16x16_8u32s(pCur, step, pRef+(yPos-1)*step+xPos-1, step, &cSAD, IPPVC_MC_APX_HH);
if (cSAD < bSAD) {
i = 1;
j = 1;
bSAD = cSAD;
}
}
//Left or Right
if (((xPos-1) >=-15) && ((yPos) >=-15) &&((xPos-1) <=15) && ((yPos) <=15) ) {
xhSAD8x8_8u32s_C1R_C(pCur, 384, pRef-1, 48, &cSAD, 8);
// ippiSAD16x16_8u32s(pCur, step, pRef+(yPos-1)*step+xPos-1, step, &cSAD, IPPVC_MC_APX_HH);
if (cSAD < bSAD) {
i = -1;
j = 0;
bSAD = cSAD;
}
}
if (((xPos+1) >=-15) && ((yPos) >=-15) &&((xPos+1) <=15) && ((yPos) <=15) ) {
xhSAD8x8_8u32s_C1R_C(pCur, 384, pRef+1, 48, &cSAD, 8);
// ippiSAD16x16_8u32s(pCur, step, pRef+(yPos-1)*step+xPos-1, step, &cSAD, IPPVC_MC_APX_HH);
if (cSAD < bSAD) {
i = 1;
j = 0;
bSAD = cSAD;
}
}
//Top or Bottom
if (((xPos) >=-15) && ((yPos-1) >=-15) &&((xPos) <=15) && ((yPos-1) <=15) ) {
xhSAD8x8_8u32s_C1R_C(pCur, 384, pRef-48, 48, &cSAD, 4);
// ippiSAD16x16_8u32s(pCur, step, pRef+(yPos-1)*step+xPos-1, step, &cSAD, IPPVC_MC_APX_HH);
if (cSAD < bSAD) {
i = 0;
j = -1;
bSAD = cSAD;
}
}
if (((xPos) >=-15) && ((yPos+1) >=-15) &&((xPos-1) <=15) && ((yPos+1) <=15) ) {
xhSAD8x8_8u32s_C1R_C(pCur, 384, pRef+48, 48, &cSAD, 4);
// ippiSAD16x16_8u32s(pCur, step, pRef+(yPos-1)*step+xPos-1, step, &cSAD, IPPVC_MC_APX_HH);
if (cSAD < bSAD) {
i = 0;
j = 1;
bSAD = cSAD;
}
}
tss_inout->sad=bSAD;
tss_inout->mv_x+=i;
tss_inout->mv_y+=j;
}
*/
static int Diamond16_MainSearch(Ipp8u *pCur,Ipp8u* ptr_ref,
Ipp16s start_x,Ipp16s start_y,int iMinSAD,
struct IppMotionVector *currMV, int refwin_step)
{
Ipp32s iDirection = 0;
Ipp32s iSAD;
struct IppMotionVector backupMV;
int iFound;
int iDiamondSize = 1;
backupMV.dx = start_x;
backupMV.dy = start_y;
iFound = 0;
/* It's one search with full Diamond pattern, and only 3 of 4 for all following diamonds */
CHECK_MV16_CANDIDATE_DIR(backupMV.dx - iDiamondSize, backupMV.dy, 1);
CHECK_MV16_CANDIDATE_DIR(backupMV.dx + iDiamondSize, backupMV.dy, 2);
CHECK_MV16_CANDIDATE_DIR(backupMV.dx, backupMV.dy - iDiamondSize, 3);
CHECK_MV16_CANDIDATE_DIR(backupMV.dx, backupMV.dy + iDiamondSize, 4);
if (iDirection)
while (!iFound) {
iFound = 1;
backupMV = *currMV;
if (iDirection != 2)
CHECK_MV16_CANDIDATE_FOUND(backupMV.dx - iDiamondSize,
backupMV.dy, 1);
if (iDirection != 1)
CHECK_MV16_CANDIDATE_FOUND(backupMV.dx + iDiamondSize,
backupMV.dy, 2);
if (iDirection != 4)
CHECK_MV16_CANDIDATE_FOUND(backupMV.dx,
backupMV.dy - iDiamondSize, 3);
if (iDirection != 3)
CHECK_MV16_CANDIDATE_FOUND(backupMV.dx,
backupMV.dy + iDiamondSize, 4);
}
else {
currMV->dx = start_x;
currMV->dy = start_y;
}
return iMinSAD;
}
int Diamond8_MainSearch(unsigned char *pCur,unsigned char* ptr_ref,
Ipp16s start_x,Ipp16s start_y,int iMinSAD,
struct IppMotionVector *currMV)
{
Ipp32s iDirection = 0;
Ipp32s iSAD;
struct IppMotionVector backupMV;
int iFound;
int iDiamondSize = 1;
backupMV.dx = start_x;
backupMV.dy = start_y;
iFound = 0;
/* It's one search with full Diamond pattern, and only 3 of 4 for all following diamonds */
CHECK_MV8_CANDIDATE_DIR(backupMV.dx - iDiamondSize, backupMV.dy, 1);
CHECK_MV8_CANDIDATE_DIR(backupMV.dx + iDiamondSize, backupMV.dy, 2);
CHECK_MV8_CANDIDATE_DIR(backupMV.dx, backupMV.dy - iDiamondSize, 3);
CHECK_MV8_CANDIDATE_DIR(backupMV.dx, backupMV.dy + iDiamondSize, 4);
if (iDirection)
while (!iFound) {
iFound = 1;
backupMV = *currMV;
if (iDirection != 2)
CHECK_MV8_CANDIDATE_FOUND(backupMV.dx - iDiamondSize,
backupMV.dy, 1);
if (iDirection != 1)
CHECK_MV8_CANDIDATE_FOUND(backupMV.dx + iDiamondSize,
backupMV.dy, 2);
if (iDirection != 4)
CHECK_MV8_CANDIDATE_FOUND(backupMV.dx,
backupMV.dy - iDiamondSize, 3);
if (iDirection != 3)
CHECK_MV8_CANDIDATE_FOUND(backupMV.dx,
backupMV.dy + iDiamondSize, 4);
} else {
currMV->dx = start_x;
currMV->dy = start_y;
}
return iMinSAD;
}
//int fast_diamond_Search(FRAMEINFO * const current,MBParam * const pParam,MACROBLOCK *pCurrMB,
// int x,int y,unsigned char *pMBy_cur,unsigned char* ref_window)
//void mp4_ME_16x16_C(Ipp8u *pCur, Ipp8u *ref_window, int *bestSAD,struct IppMotionVector *mv)
void mp4_ME_16x16_C(Ipp8u *pCur, Ipp8u *ref_window, int *bestSAD,struct IppMotionVector *mv, int refwin_step)
{//f_code == 16 情况
//static const VECTOR zeroMV = { 0, 0 };
struct IppMotionVector CurrMV,newMV;
Ipp32s iMinSAD,iSAD,sum_sad_8x8;
Ipp8u *ptr_ref_colocate ;
// ptr_ref_colocate = ref_window + 16*WINWIDTH_3step+16;
ptr_ref_colocate = ref_window + 16*refwin_step +16;
// tss_in_out.winwidth = WINWIDTH_3step; //48
tss_in_out.winwidth = refwin_step;
//tss_in_out.rounding_type =current->rounding_type;
//predMV = get_pmv2(current->mbs,pParam->mb_width, 0, x, y, 0);
CurrMV.dx = mv->dx>>1;
CurrMV.dy = mv->dy>>1;
if((CurrMV.dx < -15)||(CurrMV.dx > 15)||(CurrMV.dy < -15)||(CurrMV.dy > 15))
{
CurrMV.dx = 0;
CurrMV.dy = 0;
}
// iMinSAD = _sad16x16_asm( pCur, ptr_ref_colocate + WINWIDTH_3step*CurrMV.dy + CurrMV.dx,WINWIDTH_3step, MV_MAX_ERROR);
iMinSAD = _sad16x16_asm( pCur, ptr_ref_colocate + refwin_step*CurrMV.dy + CurrMV.dx,refwin_step, MV_MAX_ERROR);
iSAD = Diamond16_MainSearch(pCur,ptr_ref_colocate,CurrMV.dx,CurrMV.dy,iMinSAD,&newMV, refwin_step);
if (iSAD < iMinSAD) {
CurrMV.dx = newMV.dx;
CurrMV.dy = newMV.dy;
iMinSAD = iSAD;
}
tss_in_out.ptr_target = pCur;
tss_in_out.mv_x = CurrMV.dx<<1;
tss_in_out.mv_y = CurrMV.dy<<1;
tss_in_out.sad = iMinSAD;
tss_in_out.ptr_reference = ptr_ref_colocate+ refwin_step*CurrMV.dy + CurrMV.dx;
tss_in_out.ptr_match = MBy_match_16x16;
//if(((CurrMV.dy-1)>=-15)&&((CurrMV.dy+1)<=15)&&((CurrMV.dx-1)>=-15)&&((CurrMV.dx+1) <=15))
_Halfpel16_Refine(&tss_in_out);
//else
// MBCopy_ref_to_match(tss_in_out.ptr_reference,tss_in_out.ptr_match,tss_in_out.winwidth);
*bestSAD = tss_in_out.sad;
mv->dx = tss_in_out.mv_x ;
mv->dy = tss_in_out.mv_y ;
}
#if 0
void mp4_ME_8x8_C(Ipp8u *pCur, Ipp8u *ref_window, int *bestSAD,struct IppMotionVector *mv,struct IppMotionVector *mv4)
{
struct IppMotionVector CurrMV,newMV,CurrMV_backup;
Ipp32s iMinSAD,iSAD,n,bsad[4],pOff[4],refwinOff[4],matchOff[4];
Ipp8u *ptr_ref_colocate ;
ptr_ref_colocate = ref_window + 16*WINWIDTH_3step+16;
tss_in_out.winwidth = WINWIDTH_3step; //48
CurrMV.dx=mv->dx>>1;
CurrMV.dy=mv->dy>>1;
if((CurrMV.dx < -15)||(CurrMV.dx > 15)||(CurrMV.dy < -15)||(CurrMV.dy > 15)) {
CurrMV.dx = 0;
CurrMV.dy = 0;
}
CurrMV_backup = CurrMV;
pOff[0] = 0;
pOff[1] = 8;
pOff[2] = 16 * 8;
pOff[3] = 16 * 8 + 8;
refwinOff[0] = 0;
refwinOff[1] = 8;
refwinOff[2] = WINWIDTH_3step*8;
refwinOff[3] = WINWIDTH_3step*8 + 8;
matchOff[0] = 0;
matchOff[1] = 8;
matchOff[2] = 8*16;
matchOff[3] = 8*16 + 8;
for(n=0;n<4;n++){
iMinSAD=_sad8x8_asm(pCur+pOff[n],ptr_ref_colocate+refwinOff[n]+WINWIDTH_3step*CurrMV.dy + CurrMV.dx,WINWIDTH_3step);
iSAD = Diamond8_MainSearch(pCur+pOff[n],ptr_ref_colocate+refwinOff[n],CurrMV.dx,CurrMV.dy,iMinSAD,&newMV);
if (iSAD < iMinSAD) {
CurrMV_backup.dx = newMV.dx;
CurrMV_backup.dy = newMV.dy;
iMinSAD = iSAD;
}
tss_in_out.ptr_target = pCur + pOff[n];
tss_in_out.mv_x = CurrMV_backup.dx<<1;
tss_in_out.mv_y = CurrMV_backup.dy<<1;
tss_in_out.sad = iMinSAD;
tss_in_out.ptr_reference = ptr_ref_colocate + refwinOff[n] + WINWIDTH_3step*CurrMV.dy + CurrMV.dx;
tss_in_out.ptr_match = MBy_match_4x8x8+matchOff[n];
_Halfpel8_Refine(&tss_in_out);
bsad[n] = tss_in_out.sad;
mv4[n].dx = tss_in_out.mv_x ;
mv4[n].dy = tss_in_out.mv_y ;
}
*bestSAD=bsad[0]+bsad[1]+bsad[2]+bsad[3];
}
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -