📄 adaptive_filter.c
字号:
int subblock=0;
int filter_pos_x1, filter_pos_y1, filter_pos_y2;
int x_orig, y_orig; // absolute distances from current macroblock
int number_equation;
double **RecY=NULL;
double **RecYF=NULL;
double **RecYB=NULL;
imgpel **RecY_FullPel = NULL;
imgpel **RecYF_FullPel = NULL;
imgpel **RecYB_FullPel = NULL;
#ifdef EIGHTH_PEL
if(img->mv_res)
{
SetAdaptiveFilterEighthpelVer();
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_ups_aif_hor;
RecYF_FullPel = 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_ups_aif_hor;
RecYB_FullPel = 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;
RecY_FullPel = RecYF_FullPel;
ref_frame = ref_frameF;
}
else
{
sub_pos = sub_posB;
mvx = mvxB;
mvy = mvyB;
RecY = RecYB;
RecY_FullPel = RecYB_FullPel;
ref_frame = ref_frameB;
}
if(sub_pos != -1 && ref_frame != -1 ) // if no full-pel motion
{
number_equation = FILTER_SIZE;
if (sub_pos == d_pos)
{
for (xj = 0; xj < 4; xj++)
{
filter_pos_x1 = FindPosition (img->width, x + xj, FILTER_OFFSET, mvx);
for (yi = 0; yi < 4; yi++)
{
for (equation = 0; equation < number_equation; equation++)
{
filter_pos_y1 = FindPosition (img->height, y + yi, equation, mvy);
for (i = 0; i < FILTER_SIZE; i++)
{
filter_pos_y2 = FindPosition (img->height, y + yi, i, mvy);
NxN_Matrix[sub_pos][equation][i] +=
b_scaling * RecY_FullPel[filter_pos_y1][filter_pos_x1] * RecY_FullPel[filter_pos_y2][filter_pos_x1];
}
N_Vector[sub_pos][equation] += b_scaling * imgY_org[y + yi][x + xj] * RecY_FullPel[filter_pos_y1][filter_pos_x1];
}
}
}
}
else if (sub_pos == h_pos)
{
for (xj = 0; xj < 4; xj++)
{
filter_pos_x1 = FindPosition (img->width, x + xj, FILTER_OFFSET, mvx);
for (yi = 0; yi < 4; yi++)
{
for (equation = 0; equation < number_equation; equation++)
{
filter_pos_y1 = FindPosition (img->height, y + yi, equation, mvy);
eq_new = TwoDEquationPattern[b_pos][equation];
for (i = 0; i < FILTER_SIZE; i++)
{
filter_pos_y2 = FindPosition (img->height, y + yi, i, mvy);
i_new = TwoDEquationPattern[b_pos][i];
NxN_Matrix[sub_pos][eq_new][i_new] +=
b_scaling * RecY_FullPel[filter_pos_y1][filter_pos_x1] * RecY_FullPel[filter_pos_y2][filter_pos_x1];
}
N_Vector[sub_pos][eq_new] += b_scaling * imgY_org[y + yi][x + xj] * RecY_FullPel[filter_pos_y1][filter_pos_x1];
}
}
}
}
else if (sub_pos == l_pos)
{
for (xj = 0; xj < 4; xj++)
{
filter_pos_x1 = FindPosition (img->width, x + xj, FILTER_OFFSET, mvx);
for (yi = 0; yi < 4; yi++)
{
for (equation = 0; equation < number_equation; equation++)
{
filter_pos_y1 = FindPosition (img->height, y + yi, equation, mvy);
for (i = 0; i < FILTER_SIZE; i++)
{
filter_pos_y2 = FindPosition (img->height, y + yi, i, mvy);
NxN_Matrix[d_pos][number_equation-equation-1][FILTER_SIZE-i-1] +=
b_scaling * RecY_FullPel[filter_pos_y1][filter_pos_x1] * RecY_FullPel[filter_pos_y2][filter_pos_x1];
}
N_Vector[d_pos][number_equation-equation-1] += b_scaling * imgY_org[y + yi][x + xj] * RecY_FullPel[filter_pos_y1][filter_pos_x1];
}
}
}
}
else if (sub_pos > l_pos)
{
for (xj = 0; xj < 4; xj++)
{
filter_pos_x1 = FindPosition (img->width, x + xj, FILTER_OFFSET, mvx);
filter_pos_x1 = (filter_pos_x1 << 2) + ((sub_pos + 1) % 4);
for (yi = 0; yi < 4; yi++)
{
for (equation = 0; equation < number_equation; equation++)
{
filter_pos_y1 = FindPosition (img->height, y + yi, equation, mvy);
for (i = 0; i < FILTER_SIZE; i++)
{
filter_pos_y2 = FindPosition (img->height, y + yi, i, mvy);
NxN_Matrix[sub_pos-8][number_equation-equation-1][FILTER_SIZE-i-1] +=
b_scaling * RecY[filter_pos_y1 + IMG_PAD_SIZE][filter_pos_x1 + IMG_PAD_SIZE * 4] *
RecY[filter_pos_y2 + IMG_PAD_SIZE][filter_pos_x1 + IMG_PAD_SIZE * 4];
}
N_Vector[sub_pos-8][number_equation-equation-1] +=
b_scaling * imgY_org[y + yi][x + xj] * RecY[filter_pos_y1 + IMG_PAD_SIZE][filter_pos_x1 + IMG_PAD_SIZE * 4];
}
}
}
}
else if (sub_pos == i_pos || sub_pos == j_pos || sub_pos == k_pos)
{
for (xj = 0; xj < 4; xj++)
{
filter_pos_x1 = FindPosition (img->width, x + xj, FILTER_OFFSET, mvx);
filter_pos_x1 = (filter_pos_x1 << 2) + ((sub_pos + 1) % 4);
for (yi = 0; yi < 4; yi++)
{
for (equation = 0; equation < number_equation; equation++)
{
filter_pos_y1 = FindPosition (img->height, y + yi, equation, mvy);
eq_new = TwoDEquationPattern[b_pos][equation];
for (i = 0; i < FILTER_SIZE; i++)
{
filter_pos_y2 = FindPosition (img->height, y + yi, i, mvy);
i_new = TwoDEquationPattern[b_pos][i];
NxN_Matrix[sub_pos][eq_new][i_new] +=
b_scaling * RecY[filter_pos_y1 + IMG_PAD_SIZE][filter_pos_x1 + IMG_PAD_SIZE * 4] *
RecY[filter_pos_y2 + IMG_PAD_SIZE][filter_pos_x1 + IMG_PAD_SIZE * 4];
}
N_Vector[sub_pos][eq_new] +=
b_scaling * imgY_org[y + yi][x + xj] * RecY[filter_pos_y1 + IMG_PAD_SIZE][filter_pos_x1 + IMG_PAD_SIZE * 4];
}
}
}
}
else
{
for (xj = 0; xj < 4; xj++)
{
filter_pos_x1 = FindPosition (img->width, x + xj, FILTER_OFFSET, mvx);
filter_pos_x1 = (filter_pos_x1 << 2) + ((sub_pos + 1) % 4);
for (yi = 0; yi < 4; yi++)
{
for (equation = 0; equation < number_equation; equation++)
{
filter_pos_y1 = FindPosition (img->height, y + yi, equation, mvy);
for (i = 0; i < FILTER_SIZE; i++)
{
filter_pos_y2 = FindPosition (img->height, y + yi, i, mvy);
NxN_Matrix[sub_pos][equation][i] +=
b_scaling * RecY[filter_pos_y1 + IMG_PAD_SIZE][filter_pos_x1 + IMG_PAD_SIZE * 4] *
RecY[filter_pos_y2 + IMG_PAD_SIZE][filter_pos_x1 + IMG_PAD_SIZE * 4];
}
N_Vector[sub_pos][equation] +=
b_scaling * imgY_org[y + yi][x + xj] * RecY[filter_pos_y1 + IMG_PAD_SIZE][filter_pos_x1 + IMG_PAD_SIZE * 4];
}
}
}
}
}
}
}
}
// separable aif (END)
/*!
************************************************************************
* \brief
* sets necessary filter data for current macroblock in 1/8-pel case
************************************************************************
*/
void SetAdaptiveFilterEighthpel(void)
{
Macroblock *currMB = &img->mb_data[img->current_mb_nr];
int i, j, x, y, xj, yi;
float b_scaling=1.0;
int run=0, rerun=0;
int run8=0, rerun8 = 1;
int equation=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 mvxF8, mvyF8, mvxB8, mvyB8;
int tmp_x_f, tmp_y_f, tmp_x_b, tmp_y_b;
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, filter_pos_y2;
int x_orig, y_orig; // absolute distances from current macroblock
int h1, h2, h3;
int *new_filter_pos, *new_eq, *new_sub_pos;
int number_equation;
imgpel **RecY=NULL;
imgpel **RecYF=NULL;
imgpel **RecYB=NULL;
new_filter_pos = &h1;
new_eq = &h2;
new_sub_pos = &h3;
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(run8=0;run8<rerun8;run8++)
{
for(subblock = 0; subblock < 16; subblock++)
{
x = x_orig+4*(subblock%4);
y = y_orig+4*(subblock/4);
mvxF8 = enc_picture->mv[LIST_0][y/4][x/4][0];
mvyF8 = enc_picture->mv[LIST_0][y/4][x/4][1];
if(mvxF8>=0)
tmp_x_f = mvxF8%8;
else
tmp_x_f = 8-(abs(mvxF8)%8);
if(mvyF8>=0)
tmp_y_f = mvyF8%8;
else
tmp_y_f = 8-(abs(mvyF8)%8);
if(run8 == 0)
{
if( abs(mvxF8)%2 == 0 && abs(mvyF8)%2 == 0 ) // quarter-pel
{
mvxF = mvxF8/2;
mvyF = mvyF8/2;
}
else if(abs(mvxF8)%2 == 0) // quarter-pel in x
{
mvxF = mvxF8/2;
mvyF = (mvyF8-1)/2;
}
else if(abs(mvyF8)%2 == 0) // quarter-pel in y
{
mvxF = (mvxF8-1)/2;
mvyF = mvyF8/2;
}
else // upper right - down left
// or upper left - down right interpolation
{
if((tmp_x_f+tmp_y_f)%4 == 0) // upper right-down left
{
mvxF = (mvxF8+1)/2;
mvyF = (mvyF8-1)/2;
}
else // upper left - down right
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -