📄 adaptive_filter.c
字号:
{
// Count correlation functions only for diagonal NW-SE
if (!((equation==5)||(equation==10)||(equation==15)||
(equation==20)||(equation==25)||(equation==30)))
continue;
}
else if (IsDiagonal1D[sub_pos]==3)//NW-SE & NE-SW
{
if (!((equation==0)||(equation==7)||(equation==14)||
(equation== 5)||(equation==10)||(equation==15)||
(equation==20)||(equation==25)||(equation==30)||
(equation==21)||(equation==28)||(equation==35)))
continue;
}
#endif
ReorderPosition(new_filter_pos, new_eq, new_sub_pos,
1, equation, sub_pos); // 1 is not important
N_Vector[*new_sub_pos][*new_eq] += b_scaling*imgY_org[y+yi][x+xj]*
RecY[filter_pos_y1][filter_pos_x1];
}
#ifdef E_DAIF
if(input->UseAdaptiveFilter == FILTER_TYPE_EDAIF)
{
// one more coefficient to solve to get filter offset
if(number_equation == SQR(FILTER_SIZE)) // 2-D case
{
int N = POS_EQUATION_NUMBER[sub_pos];
{
for(i = 0; i < FILTER_SIZE; i++)
for(j = 0; j < FILTER_SIZE; j++)
{
if(!UseEquation[IsDiagonal1D[sub_pos]-1][FILTER_SIZE*i+j])
continue;
filter_pos_x2 = FindPosition(img->width, x+xj,j,mvx);
filter_pos_y2 = FindPosition(img->height,y+yi,i,mvy);
*new_sub_pos = FILTER_NEW_SUB_POS[sub_pos];
*new_eq = N;
*new_filter_pos = TwoDEquationPattern[sub_pos][FILTER_SIZE*i+j];
NxN_Matrix[*new_sub_pos][*new_eq][*new_filter_pos] += b_scaling*
RecY[filter_pos_y2][filter_pos_x2];
NxN_Matrix[*new_sub_pos][*new_filter_pos][*new_eq] += b_scaling*
RecY[filter_pos_y2][filter_pos_x2];
}
}
*new_sub_pos = FILTER_NEW_SUB_POS[sub_pos];
NxN_Matrix[*new_sub_pos][N][N] += 1.;
N_Vector[*new_sub_pos][N] += b_scaling*imgY_org[y+yi][x+xj];
}
else // 1-D case
{
int N = POS_EQUATION_NUMBER[sub_pos];
if((sub_pos+1) / 4 == 0) // horizontal
{
for(i = 0; i < FILTER_SIZE; i++)
{
filter_pos_x2 = FindPosition(img->width, x+xj, i,mvx);
filter_pos_y2 = FindPosition(img->height,y+yi, FILTER_OFFSET,mvy);
*new_sub_pos = FILTER_NEW_SUB_POS[sub_pos];
*new_eq = N;
*new_filter_pos = TwoDEquationPattern[sub_pos][i];
NxN_Matrix[*new_sub_pos][*new_eq][*new_filter_pos] += b_scaling*
RecY[filter_pos_y2][filter_pos_x2];
NxN_Matrix[*new_sub_pos][*new_filter_pos][*new_eq] += b_scaling*
RecY[filter_pos_y2][filter_pos_x2];
}
}
else // vertical
{
for(i = 0; i < FILTER_SIZE; i++)
{
filter_pos_x2 = FindPosition(img->width, x+xj, FILTER_OFFSET,mvx);
filter_pos_y2 = FindPosition(img->height,y+yi, i,mvy);
*new_sub_pos = FILTER_NEW_SUB_POS[sub_pos];
*new_eq = N;
*new_filter_pos = TwoDEquationPattern[sub_pos][i];
NxN_Matrix[*new_sub_pos][*new_eq][*new_filter_pos] += b_scaling*
RecY[filter_pos_y2][filter_pos_x2];
NxN_Matrix[*new_sub_pos][*new_filter_pos][*new_eq] += b_scaling*
RecY[filter_pos_y2][filter_pos_x2];
}
}
*new_sub_pos = FILTER_NEW_SUB_POS[sub_pos];
NxN_Matrix[*new_sub_pos][N][N] += 1.;
N_Vector[*new_sub_pos][N] += b_scaling*imgY_org[y+yi][x+xj];
}
}
#endif
}
}
}
#ifdef E_DAIF
else if((input->UseAdaptiveFilter == FILTER_TYPE_EDAIF)&&(ref_frame != -1))
// full-pel position
{
number_equation = SQR(FILTER_SIZE_INT);
for(yi = 0; yi < 4; yi++) //y
{
for(xj = 0; xj < 4; xj++) //x
{
for(equation = 0; equation < number_equation; equation++)
{
filter_pos_x1 = FindPositionInt(img->width, x+xj,equation%FILTER_SIZE_INT,mvx); //current derivation (h_ij)
filter_pos_y1 = FindPositionInt(img->height,y+yi,equation/FILTER_SIZE_INT,mvy); //current derivation (h_ij)
for(i = 0; i < FILTER_SIZE_INT; i++)
{
for(j = 0; j < FILTER_SIZE_INT; j++)
{
filter_pos_x2 = FindPositionInt(img->width, x+xj,j,mvx);
filter_pos_y2 = FindPositionInt(img->height,y+yi,i,mvy);
*new_eq = equation;
*new_filter_pos = FILTER_SIZE_INT*i+j;
NxN_Matrix_Int[*new_eq][*new_filter_pos] += b_scaling *
RecY[filter_pos_y1][filter_pos_x1] *
RecY[filter_pos_y2][filter_pos_x2];
}
}
*new_eq = equation;
N_Vector_Int[*new_eq] += b_scaling * imgY_org[y+yi][x+xj] *
RecY[filter_pos_y1][filter_pos_x1];
} // equation loop
// one more coefficient for offset
// equation = SQR(FILTER_SIZE_INT)
{
int N;
for(i = 0; i < FILTER_SIZE_INT; i++)
{
for(j = 0; j < FILTER_SIZE_INT; j++)
{
filter_pos_x2 = FindPositionInt(img->width, x+xj,j,mvx);
filter_pos_y2 = FindPositionInt(img->height,y+yi,i,mvy);
*new_eq = equation;
*new_filter_pos = FILTER_SIZE_INT*i+j;
NxN_Matrix_Int[*new_eq][*new_filter_pos] += b_scaling *
RecY[filter_pos_y2][filter_pos_x2];
NxN_Matrix_Int[*new_filter_pos][*new_eq] += b_scaling *
RecY[filter_pos_y2][filter_pos_x2];
}
}
N = SQR(FILTER_SIZE_INT);
NxN_Matrix_Int[N][N] += 1.;
N_Vector_Int[N] += b_scaling * imgY_org[y+yi][x+xj];
}
}
}
}
#endif // E_DAIF
}
}
}
// separable aif (BEGIN)
/*!
************************************************************************
* \brief
* sets necessary horizontal filter data for current macroblock
************************************************************************
*/
void SetAdaptiveFilterHor(void)
{
Macroblock *currMB = &img->mb_data[img->current_mb_nr];
int i, x, y, xj, yi;
float b_scaling=1.0;
int run=0, rerun=0;
int equation=0, eq_new = 0, i_new = 0;
int mvx_subF=0, mvy_subF=0;
int mvx_subB=0, mvy_subB=0;
int mvx=0, mvy=0;
int mvxF=0, mvyF=0;
int mvxB=0, mvyB=0;
int sub_pos=0;
int sub_posF=0;
int sub_posB=0;
int ref_frame=0;
int ref_frameF=-1;
int ref_frameB=-1;
int subblock=0;
int filter_pos_x1, filter_pos_y1, filter_pos_x2;
int x_orig, y_orig; // absolute distances from current macroblock
int number_equation;
imgpel **RecY=NULL;
imgpel **RecYF=NULL;
imgpel **RecYB=NULL;
#ifdef EIGHTH_PEL
if(img->mv_res)
{
SetAdaptiveFilterEighthpelHor();
return;
}
#endif
if(IS_INTRA(currMB)) //intra macroblocks are not used for calculation of the filter coeffs.
return;
x_orig = MB_BLOCK_SIZE*(img->block_x/4);
y_orig = MB_BLOCK_SIZE*(img->block_y/4);
for(subblock = 0; subblock < 16; subblock++)
{
x = x_orig+4*(subblock%4);
y = y_orig+4*(subblock/4);
mvxF = enc_picture->mv[LIST_0][y/4][x/4][0];
mvyF = enc_picture->mv[LIST_0][y/4][x/4][1];
if(mvxF >= 0)
mvx_subF = mvxF%4; // x-sub-coordinate in a 4x4block
else
mvx_subF = (4-abs(mvxF)%4)%4;
if(mvyF >= 0)
mvy_subF = mvyF%4; // y-sub-coordinate in a 4x4block
else
mvy_subF = (4-abs(mvyF)%4)%4;
sub_posF = mvx_subF + 4*mvy_subF-1; // pos 0..14 in a 4x4 block
ref_frameF = enc_picture->ref_idx[LIST_0][y/4][x/4];
if(ref_frameF != -1)
RecYF = listX[LIST_0][ref_frameF]->imgY;
if(img->type == B_SLICE)
{
mvxB= enc_picture->mv[LIST_1][y/4][x/4][0];
mvyB= enc_picture->mv[LIST_1][y/4][x/4][1];
if(mvxB >= 0)
mvx_subB = mvxB%4; // x-sub-coordinate in a 4x4block
else
mvx_subB = (4-abs(mvxB)%4)%4;
if(mvyB >= 0)
mvy_subB = mvyB%4; // y-sub-coordinate in a 4x4block
else
mvy_subB = (4-abs(mvyB)%4)%4;
sub_posB = mvx_subB + 4*mvy_subB-1; // pos 0..14 in a 4x4 block
ref_frameB = enc_picture->ref_idx[LIST_1][y/4][x/4];
if(ref_frameB != -1)
RecYB = listX[LIST_1][ref_frameB]->imgY;
rerun = 1;
}
else
rerun = 0;
if(ref_frameB != -1 && ref_frameF != -1)
b_scaling = 0.5;
else
b_scaling = 1.0;
for(run = 0; run <= rerun; run++)
{
if(run == 0)
{
sub_pos = sub_posF;
mvx = mvxF;
mvy = mvyF;
RecY = RecYF;
ref_frame = ref_frameF;
}
else
{
sub_pos = sub_posB;
mvx = mvxB;
mvy = mvyB;
RecY = RecYB;
ref_frame = ref_frameB;
}
if(sub_pos != -1 && ref_frame != -1 && sub_pos < d_pos)
{
number_equation = FILTER_SIZE;
for(yi = 0; yi < 4; yi++) //y
{
filter_pos_y1 = FindPosition(img->height,y+yi,FILTER_OFFSET,mvy);
for(xj = 0; xj < 4; xj++) //x
{
for(equation = 0; equation < number_equation; equation++)
{
if(sub_pos == a_pos || sub_pos == c_pos)
{
filter_pos_x1 = FindPosition(img->width, x+xj,equation,mvx);
for(i = 0; i < FILTER_SIZE; i++)
{
filter_pos_x2 = FindPosition(img->width, x+xj, i,mvx);
NxN_Matrix[sub_pos][equation][i] += b_scaling*
RecY[filter_pos_y1][filter_pos_x1]*
RecY[filter_pos_y1][filter_pos_x2];
}
N_Vector[sub_pos][equation] += b_scaling*imgY_org[y+yi][x+xj]*
RecY[filter_pos_y1][filter_pos_x1];
}
else // b_pos
{
filter_pos_x1 = FindPosition(img->width, x+xj,equation,mvx);
eq_new = TwoDEquationPattern[b_pos][equation];
for(i = 0; i < FILTER_SIZE; i++)
{
filter_pos_x2 = FindPosition(img->width, x+xj, i,mvx);
i_new = TwoDEquationPattern[b_pos][i];
NxN_Matrix[sub_pos][eq_new][i_new] += b_scaling*
RecY[filter_pos_y1][filter_pos_x1]*
RecY[filter_pos_y1][filter_pos_x2];
}
N_Vector[sub_pos][eq_new] += b_scaling*imgY_org[y+yi][x+xj]*
RecY[filter_pos_y1][filter_pos_x1];
}
}
}
}
}
}
}
}
/*!
************************************************************************
* \brief
* sets necessary vertical filter data for current macroblock
************************************************************************
*/
void SetAdaptiveFilterVer(void)
{
Macroblock *currMB = &img->mb_data[img->current_mb_nr];
int i, x, y, xj, yi;
float b_scaling=1.0;
int run=0, rerun=0;
int equation=0, eq_new = 0, i_new = 0;
int mvx_subF=0, mvy_subF=0;
int mvx_subB=0, mvy_subB=0;
int mvx=0, mvy=0;
int mvxF=0, mvyF=0;
int mvxB=0, mvyB=0;
int sub_pos=0;
int sub_posF=0;
int sub_posB=0;
int ref_frame=0;
int ref_frameF=-1;
int ref_frameB=-1;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -