📄 diamond_search.c
字号:
/*predictive motion estimation using diamond fast search algorithm
parameters:
*/
#include "ippdefs.h"
#include "tss.h"
extern Ipp8u MBy_match_16x16[256];
extern Ipp8u MBy_match_4x8x8[256];
//void _Halfpel16_Refine_C(struct tss_par *tss_inout);
//void _Halfpel8_Refine_C(struct tss_par *tss_inout);
extern void _Halfpel16_Refine(struct tss_par *tss_inout);
extern void _Halfpel8_Refine(struct tss_par *tss_inout);
extern int _sad16x16_asm(Ipp8u *pCur,Ipp8u *pYr,int ref_step,int MinSAD);
extern int _sad8x8_asm(Ipp8u *pCur,Ipp8u *pYr,int ref_step);
//extern void xhSAD16x16_8u32s( const Ipp8u* pSrc,
// Ipp32s srcStep,
// const Ipp8u* pRef,
// Ipp32s refStep,
// Ipp32s* pSAD,
// Ipp32s mcType
// );
//extern void xhSAD8x8_8u32s_C1R( const Ipp8u* pSrc,
// Ipp32s srcStep,
// const Ipp8u* pRef,
// Ipp32s refStep,
// Ipp32s* pSAD,
// Ipp32s mcType
// );
//extern Ipp8u refwin[48*48];
struct IppMotionVector
{
Ipp16s dx;
Ipp16s dy;
} ;
segment("L1_data_b") struct tss_par tss_in_out; //36B
#define MV_MAX_ERROR (4096 * 256)
#if 0
#define CHECK_MV16_CANDIDATE_DIR(X,Y,D) { \
if ( ((X) <= 15) && ((X) >= -15) \
&& ((Y) <= 15) && ((Y) >= -15) ) \
{ \
iSAD = _sad16x16_asm( pCur, ptr_ref + 48*(Y) + (X),48, iMinSAD); \
if (iSAD < iMinSAD) \
{ iMinSAD=iSAD; currMV->dx=(X); currMV->dy=(Y); iDirection=(D); } } \
}
#else
#define CHECK_MV16_CANDIDATE_DIR(X,Y,D) { \
if ( ((X) <= 15) && ((X) >= -15) \
&& ((Y) <= 15) && ((Y) >= -15) ) \
{ \
iSAD = _sad16x16_asm( pCur, ptr_ref + refwin_step*(Y) + (X),refwin_step, iMinSAD); \
if (iSAD < iMinSAD) \
{ iMinSAD=iSAD; currMV->dx=(X); currMV->dy=(Y); iDirection=(D); } } \
}
#endif
#if 0
#define CHECK_MV16_CANDIDATE_FOUND(X,Y,D) { \
if ( ((X) < 15) && ((X) >= -15) \
&& ((Y) <= 15) && ((Y) >= -15) ) \
{ \
iSAD = _sad16x16_asm( pCur, ptr_ref + 48*(Y) + (X),48, iMinSAD); \
if (iSAD < iMinSAD) \
{ iMinSAD=iSAD; currMV->dx=(X); currMV->dy=(Y); iDirection=(D); iFound=0; } } \
}
#else
#define CHECK_MV16_CANDIDATE_FOUND(X,Y,D) { \
if ( ((X) < 15) && ((X) >= -15) \
&& ((Y) <= 15) && ((Y) >= -15) ) \
{ \
iSAD = _sad16x16_asm( pCur, ptr_ref + refwin_step*(Y) + (X),refwin_step, iMinSAD); \
if (iSAD < iMinSAD) \
{ iMinSAD=iSAD; currMV->dx=(X); currMV->dy=(Y); iDirection=(D); iFound=0; } } \
}
#endif
#define CHECK_MV8_CANDIDATE_DIR(X,Y,D) { \
if ( ((X) <= 15) && ((X) >= -15) \
&& ((Y) <= 15) && ((Y) >= -15) ) \
{ \
iSAD = _sad8x8_asm( pCur, ptr_ref + 48*(Y) + (X),48); \
if (iSAD < iMinSAD) \
{ iMinSAD=iSAD; currMV->dx=(X); currMV->dy=(Y); iDirection=(D); } } \
}
#define CHECK_MV8_CANDIDATE_FOUND(X,Y,D) { \
if ( ((X) <= 15) && ((X) >= -15) \
&& ((Y) <= 15) && ((Y) >= -15) ) \
{ \
iSAD = _sad8x8_asm( pCur, ptr_ref + 48*(Y) + (X),48); \
if (iSAD < iMinSAD) \
{ iMinSAD=iSAD; currMV->dx=(X); currMV->dy=(Y); iDirection=(D); iFound=0; } } \
}
/*
int _sad8x8_asm_C(Ipp8u *pCur,Ipp8u *pYr,int ref_step,int step)
{
int min_sad=0;
int i;
for(i=0;i<8;i++)
{
min_sad+=abs(pCur[0]-pYr[0]);
min_sad+=abs(pCur[1]-pYr[1]);
min_sad+=abs(pCur[2]-pYr[2]);
min_sad+=abs(pCur[3]-pYr[3]);
min_sad+=abs(pCur[4]-pYr[4]);
min_sad+=abs(pCur[5]-pYr[5]);
min_sad+=abs(pCur[6]-pYr[6]);
min_sad+=abs(pCur[7]-pYr[7]);
pCur += step;
pYr += ref_step;
}
return min_sad;
}
void _Halfpel16_Refine_C(struct tss_par *tss_inout)
{
int i,j,cSAD,bSAD,xPos,yPos;
Ipp8u *pCur,*pRef;
pCur=tss_inout->ptr_target;
pRef=tss_inout->ptr_reference;
bSAD = tss_inout->sad;
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) ) {
xhSAD16x16_8u32s(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) ) {
xhSAD16x16_8u32s(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) ) {
xhSAD16x16_8u32s(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) ) {
xhSAD16x16_8u32s(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) ) {
xhSAD16x16_8u32s(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) ) {
xhSAD16x16_8u32s(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) ) {
xhSAD16x16_8u32s(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) ) {
xhSAD16x16_8u32s(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;
}
void xhSAD8x8_8u32s_C1R_C( const Ipp8u* pSrcCur,
int srcCurStep,
const Ipp8u* pSrcRef,
int srcRefStep,
Ipp32s* pDst,
Ipp32s mcType
)
{
Ipp8u interpolate[64];
Ipp8u* intp = interpolate;
int i,j;
Ipp32s sad = 0;
//interploate, average but not filter
switch(mcType) {
case 0:
for(i = 0; i < 8; i++)
for(j = 0; j < 8; j++)
interpolate[i*8+j] = pSrcRef[i*srcRefStep+j];
break;
case 4:
for(i = 0; i < 8; i++)
for(j = 0; j < 8; j++)
interpolate[i*8+j] = (Ipp8u)((pSrcRef[i*srcRefStep+j] + pSrcRef[(i+1)*srcRefStep+j] + 1)>>1);//需不需要加这个1呢?
break;
case 8:
for(i = 0; i < 8; i++)
for(j = 0; j < 8; j++)
interpolate[i*8+j] = (Ipp8u)((pSrcRef[i*srcRefStep+j] + pSrcRef[i*srcRefStep+j+1] + 1)>>1);
break;
case 12:
for(i = 0; i < 8; i++)
for(j = 0; j < 8; j++)
interpolate[i*8+j] = (Ipp8u)((pSrcRef[i*srcRefStep+j] + pSrcRef[i*srcRefStep+j+1] + pSrcRef[(i+1)*srcRefStep+j] + pSrcRef[(i+1)*srcRefStep+j+1] + 2)>>2);
break;
default:
printf("wrong mc type\n");
//return(0);
break;
}
for(i = 0; i < 8; i++)
{
sad += abs(pSrcCur[0] - intp[0]);
sad += abs(pSrcCur[1] - intp[1]);
sad += abs(pSrcCur[2] - intp[2]);
sad += abs(pSrcCur[3] - intp[3]);
sad += abs(pSrcCur[4] - intp[4]);
sad += abs(pSrcCur[5] - intp[5]);
sad += abs(pSrcCur[6] - intp[6]);
sad += abs(pSrcCur[7] - intp[7]);
pSrcCur += srcCurStep;
intp += 8;
}
*pDst = sad;
}
void _Halfpel8_Refine_C(struct tss_par *tss_inout)
{ int i,j,cSAD,bSAD,xPos,yPos;
Ipp8u *pCur,*pRef;
// for(i=0;i<16;i++)
// for(j=0;j<16;j++)
// tss_inout->ptr_match[16*i+j]=tss_inout->ptr_reference[48*i+j];
pCur=tss_inout->ptr_target;
pRef=tss_inout->ptr_reference;
bSAD = tss_inout->sad;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -