📄 adaptive_filter.c
字号:
}
else if(!(dmvx&1) && dmvy&1) // horizontal 1/4 and vertical 1/8
{
GetBlockWith2DAIF_quarter_pel(ref_idx, list, x_pos, y_pos, mvx/2, (mvy+1)/2, img_width,img_height, block);
GetBlockWith2DAIF_quarter_pel(ref_idx, list, x_pos, y_pos, mvx/2, (mvy-1)/2, img_width,img_height, block2);
average_block(block, block2);
}
else if((dmvx+dmvy)%4)// diagonal positions upper left - down right interpolation
{
GetBlockWith2DAIF_quarter_pel(ref_idx, list, x_pos, y_pos, (mvx-1)/2, (mvy-1)/2, img_width,img_height, block);
GetBlockWith2DAIF_quarter_pel(ref_idx, list, x_pos, y_pos, (mvx+1)/2, (mvy+1)/2, img_width,img_height, block2);
GetBlockWith2DAIF_quarter_pel(ref_idx, list, x_pos, y_pos, (mvx+1)/2, (mvy-1)/2, img_width,img_height, block3);
GetBlockWith2DAIF_quarter_pel(ref_idx, list, x_pos, y_pos, (mvx-1)/2, (mvy+1)/2, img_width,img_height, block4);
average_block4(block, block2, block3, block4);
}
else // diagonal positions upper right - down left interpolation
{
GetBlockWith2DAIF_quarter_pel(ref_idx, list, x_pos, y_pos, (mvx+1)/2, (mvy-1)/2, img_width,img_height, block);
GetBlockWith2DAIF_quarter_pel(ref_idx, list, x_pos, y_pos, (mvx-1)/2, (mvy+1)/2, img_width,img_height, block2);
GetBlockWith2DAIF_quarter_pel(ref_idx, list, x_pos, y_pos, (mvx+1)/2, (mvy+1)/2, img_width,img_height, block3);
GetBlockWith2DAIF_quarter_pel(ref_idx, list, x_pos, y_pos, (mvx-1)/2, (mvy-1)/2, img_width,img_height, block4);
average_block4(block, block2, block3, block4);
}
// average_block(block, block2);
}
}
// separable aif (BEGIN)
void GetBlockWithSepAIF_eighth_pel(int ref_idx,
StorablePicture **list,
int x_pos,
int y_pos,
int xoff4x4,
int yoff4x4,
int mvx,
int mvy,
int img_width,
int img_height,
int block_size_x,
int block_size_y,
int block[MB_BLOCK_SIZE][MB_BLOCK_SIZE])
{
int block2[MB_BLOCK_SIZE][MB_BLOCK_SIZE];
int block3[MB_BLOCK_SIZE][MB_BLOCK_SIZE];
int block4[MB_BLOCK_SIZE][MB_BLOCK_SIZE];
int dmvx = (mvx%8+8)%8;
int dmvy = (mvy%8+8)%8;
if(!(dmvx&1) && !(dmvy&1)) // 1/4-pel
GetBlockWithSepAIF_quarter_pel(ref_idx, list, x_pos, y_pos, xoff4x4, yoff4x4, mvx/2, mvy/2, img_width,img_height, block_size_x, block_size_y, block);
else // 1/$
{
if(dmvx&1 && !(dmvy&1)) // horizontal 1/8 and vertical 1/4
{
GetBlockWithSepAIF_quarter_pel(ref_idx, list, x_pos, y_pos, xoff4x4, yoff4x4, (mvx+1)/2, mvy/2, img_width,img_height, block_size_x, block_size_y, block);
GetBlockWithSepAIF_quarter_pel(ref_idx, list, x_pos, y_pos, xoff4x4, yoff4x4, (mvx-1)/2, mvy/2, img_width,img_height, block_size_x, block_size_y, block2);
average_block_2(block, block2);
}
else if(!(dmvx&1) && dmvy&1) // horizontal 1/4 and vertical 1/8
{
GetBlockWithSepAIF_quarter_pel(ref_idx, list, x_pos, y_pos, xoff4x4, yoff4x4, mvx/2, (mvy+1)/2, img_width,img_height, block_size_x, block_size_y, block);
GetBlockWithSepAIF_quarter_pel(ref_idx, list, x_pos, y_pos, xoff4x4, yoff4x4, mvx/2, (mvy-1)/2, img_width,img_height, block_size_x, block_size_y, block2);
average_block_2(block, block2);
}
else if((dmvx+dmvy)%4)// diagonal positions upper left - down right interpolation
{
GetBlockWithSepAIF_quarter_pel(ref_idx, list, x_pos, y_pos, xoff4x4, yoff4x4, (mvx-1)/2, (mvy-1)/2, img_width,img_height, block_size_x, block_size_y, block);
GetBlockWithSepAIF_quarter_pel(ref_idx, list, x_pos, y_pos, xoff4x4, yoff4x4, (mvx+1)/2, (mvy+1)/2, img_width,img_height, block_size_x, block_size_y, block2);
GetBlockWithSepAIF_quarter_pel(ref_idx, list, x_pos, y_pos, xoff4x4, yoff4x4, (mvx+1)/2, (mvy-1)/2, img_width,img_height, block_size_x, block_size_y, block3);
GetBlockWithSepAIF_quarter_pel(ref_idx, list, x_pos, y_pos, xoff4x4, yoff4x4, (mvx-1)/2, (mvy+1)/2, img_width,img_height, block_size_x, block_size_y, block4);
average_block4_2(block, block2, block3, block4);
}
else // diagonal positions upper right - down left interpolation
{
GetBlockWithSepAIF_quarter_pel(ref_idx, list, x_pos, y_pos, xoff4x4, yoff4x4, (mvx+1)/2, (mvy-1)/2, img_width,img_height, block_size_x, block_size_y, block);
GetBlockWithSepAIF_quarter_pel(ref_idx, list, x_pos, y_pos, xoff4x4, yoff4x4, (mvx-1)/2, (mvy+1)/2, img_width,img_height, block_size_x, block_size_y, block2);
GetBlockWithSepAIF_quarter_pel(ref_idx, list, x_pos, y_pos, xoff4x4, yoff4x4, (mvx+1)/2, (mvy+1)/2, img_width,img_height, block_size_x, block_size_y, block3);
GetBlockWithSepAIF_quarter_pel(ref_idx, list, x_pos, y_pos, xoff4x4, yoff4x4, (mvx-1)/2, (mvy-1)/2, img_width,img_height, block_size_x, block_size_y, block4);
average_block4_2(block, block2, block3, block4);
}
// average_block(block, block2);
}
}
// separable aif (END)
void GetBlockWith2DAIF(int ref_idx,
StorablePicture **list,
int x_pos,
int y_pos,
int mvx,
int mvy,
int img_width,
int img_height,
int block[BLOCK_SIZE][BLOCK_SIZE])
{
if(img->mv_res)
GetBlockWith2DAIF_eighth_pel (ref_idx, list, x_pos, y_pos, mvx, mvy, img_width,img_height, block);
else
GetBlockWith2DAIF_quarter_pel(ref_idx, list, x_pos, y_pos, mvx, mvy, img_width,img_height, block);
}
// separable aif (BEGIN)
void GetBlockWithSepAIF(int ref_idx,
StorablePicture **list,
int x_pos,
int y_pos,
int xoff4x4,
int yoff4x4,
int mvx,
int mvy,
int img_width,
int img_height,
int block_size_x,
int block_size_y,
int block[MB_BLOCK_SIZE][MB_BLOCK_SIZE])
{
if(img->mv_res)
GetBlockWithSepAIF_eighth_pel (ref_idx, list, x_pos, y_pos, xoff4x4, yoff4x4, mvx, mvy, img_width,img_height, block_size_x, block_size_y, block);
else
GetBlockWithSepAIF_quarter_pel(ref_idx, list, x_pos, y_pos, xoff4x4, yoff4x4, mvx, mvy, img_width,img_height, block_size_x, block_size_y, block);
}
// separable aif (END)
/*!
************************************************************************
* \brief
* Interpolation of 1/4 subpixel with 2D adaptive filter
************************************************************************
*/
void GetBlockWith2DAIF_quarter_pel(int ref_idx,
StorablePicture **list,
int x_pos,
int y_pos,
int mvx,
int mvy,
int img_width,
int img_height,
int block[BLOCK_SIZE][BLOCK_SIZE])
#else
void GetBlockWith2DAIF(int ref_idx,
StorablePicture **list,
int x_pos,
int y_pos,
int mvx,
int mvy,
int img_width,
int img_height,
int block[BLOCK_SIZE][BLOCK_SIZE])
#endif
{
int i,j, fi, fj;
int fpos_x, fpos_y;
double result;
int is;
int sub_pos, mvx_sub, mvy_sub;
if(mvx >= 0)
mvx_sub = mvx%4; // x-sub-coordinate in a 4x4block
else
mvx_sub = (4-abs(mvx)%4)%4;
if(mvy >= 0)
mvy_sub = mvy%4; // y-sub-coordinate in a 4x4block
else
mvy_sub = (4-abs(mvy)%4)%4;
sub_pos = mvx_sub + 4*mvy_sub-1; // pos 0..14 in a 4x4 block
for(i = 0; i < BLOCK_SIZE; i++)
for(j = 0; j < BLOCK_SIZE; j++)
{
if(sub_pos != -1)
{
result = 0.0;
for(fi = 0; fi < FILTER_SIZE; fi++)
for(fj = 0; fj < FILTER_SIZE; fj++)
{
fpos_x = FindPosition(img_width, i+x_pos, fi,mvx);
fpos_y = FindPosition(img_height, j+y_pos, fj,mvy);
result += FilterCoef[sub_pos][FILTER_SIZE*fj+fi]*list[ref_idx]->imgY[fpos_y][fpos_x];
}
#ifdef E_DAIF
result += FilterCoef[sub_pos][SQR_FILTER-1];
#endif // E_DAIF
is = (int)(0.5+result);
}
#ifdef E_DAIF
else if(FilterFlagInt) // full-pel position w/ filtering
{
result = 0.0;
for(fi = 0; fi < FILTER_SIZE_INT; fi++)
for(fj = 0; fj < FILTER_SIZE_INT; fj++)
{
fpos_x = FindPositionInt(img_width, i+x_pos, fi,mvx);
fpos_y = FindPositionInt(img_height, j+y_pos, fj,mvy);
result += FilterCoefInt[FILTER_SIZE_INT*fj+fi]*list[ref_idx]->imgY[fpos_y][fpos_x];
}
result += FilterCoefInt[SQR_FILTER_INT-1];
is = (int)(0.5+result);
}
#endif
else
{
is = list[ref_idx]->imgY[max(0, min(img_height-1,j+y_pos+mvy/4))]
[max(0, min(img_width -1,i+x_pos+mvx/4))];
}
#ifdef INTERNAL_BIT_DEPTH_INCREASE
block[i][j] = max(0, min(((1<<img->bitdepth_luma)-1),is));
#else
block[i][j] = max(0, min(255,is));
#endif
}
}
#ifdef DIRECTIONAL_FILTER
void GetBlockWith1DAIF( int ref_idx,
StorablePicture **list,
int x_pos,
int y_pos,
int mvx,
int mvy,
int img_width,
int img_height,
int block[BLOCK_SIZE][BLOCK_SIZE])
{
#ifdef EIGHTH_PEL
if(img->mv_res)
//GetBlockWith2DAIF_Sep_eighth_pel (ref_idx, list, x_pos, y_pos, mvx, mvy, img_width,img_height, block);
printf("There is no 1D-AIF interpolation for decoder yet!\n");
else
#endif
{
if (img->ImpType == IMP_FLOAT32)
GetBlockWith1DAIF_quarter_pel(ref_idx, list, x_pos, y_pos, mvx, mvy, img_width,img_height, block);
else if (img->ImpType == IMP_INT16)
GetBlockWith1DAIF_16bits__quarter_pel(ref_idx, list, x_pos, y_pos, mvx, mvy, img_width,img_height, block);
}
}
#endif
// separable aif (END)
/*!
************************************************************************
* \brief
* Interpolation of 1/4 subpixel with 1D adaptive filter
************************************************************************
*/
#ifdef DIRECTIONAL_FILTER
void GetBlockWith1DAIF_quarter_pel(int ref_idx,
StorablePicture **list,
int x_pos,
int y_pos,
int mvx,
int mvy,
int img_width,
int img_height,
int block[BLOCK_SIZE][BLOCK_SIZE])
{
int i,j, fi, fj;
int fpos_x, fpos_y;
int sub_pos, mvx_sub, mvy_sub;
double result;
if(mvx >= 0)
mvx_sub = mvx%4; // x-sub-coordinate in a 4x4block
else
mvx_sub = (4-abs(mvx)%4)%4;
if(mvy >= 0)
mvy_sub = mvy%4; // y-sub-coordinate in a 4x4block
else
mvy_sub = (4-abs(mvy)%4)%4;
sub_pos = mvx_sub + 4*mvy_sub-1; // pos 0..14 in a 4x4 block
for(i = 0; i < BLOCK_SIZE; i++)
for(j = 0; j < BLOCK_SIZE; j++)
{
if(sub_pos != -1)
{
result = 0;
if((sub_pos==a_pos)||(sub_pos==b_pos)||(sub_pos==c_pos))
// horizontal filtering
{
fj = FILTER_OFFSET;
fpos_y = FindPosition(img_height, j+y_pos, fj,mvy);
for(fi = 0; fi < FILTER_SIZE; fi++)
{
fpos_x = FindPosition(img_width, i+x_pos, fi,mvx);
result += (FilterCoef[sub_pos][FILTER_SIZE*fj+fi]*list[ref_idx]->imgY[fpos_y][fpos_x]);
}
}
else if((sub_pos==d_pos)||(sub_pos==h_pos)||(sub_pos==l_pos))
// vertical filtering
{
fi = FILTER_OFFSET;
fpos_x = FindPosition(img_width, i+x_pos, fi,mvx);
for(fj = 0; fj < FILTER_SIZE; fj++)
{
fpos_y = FindPosition(img_height, j+y_pos, fj,mvy);
result += (FilterCoef[sub_pos][FILTER_SIZE*fj+fi]*list[ref_idx]->imgY[fpos_y][fpos_x]);
}
}
else if ((sub_pos==e_pos)||(sub_pos==o_pos))
{
for(fj = 0; fj < FILTER_SIZE; fj++) // horizontal.
{
fi = fj;
fpos_x = FindPosition(img_width, i+x_pos, fi,mvx);
fpos_y = FindPosition(img_height, j+y_pos, fj,mvy);
result += (FilterCoef[sub_pos][FILTER_SIZE*fj+fi]*list[ref_idx]->imgY[fpos_y][fpos_x]);
}
}
else if ((sub_pos==g_pos)||(sub_pos==m_pos))
{
for(fi = 0; fi < FILTER_SIZE; fi++) // horizontal.
{
fj = FILTER_SIZE-1 - fi;
fpos_x = FindPosition(img_width, i+x_pos, fi,mvx);
fpos_y = FindPosition(img_height, j+y_pos, fj,mvy);
result += (FilterCoef[sub_pos][FILTER_SIZE*fj+fi]*list[ref_idx]->imgY[fpos_y][fpos_x]);
}
}
else if ((sub_pos==f_pos)||(sub_pos==n_pos)||(sub_pos==i_pos)||(sub_pos==k_pos)||(sub_pos==j_pos))
{
for(fi = 0; fi < FILTER_SIZE; fi++)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -