📄 loopfilter.c
字号:
}
else if (ref_p1 == INT64_MIN)
{
StrValue = (byte) (
(iabs( list0_mv[blk_y][blk_x][0] - list0_mv[blk_y2][blk_x2][0]) >= 4) |
(iabs( list0_mv[blk_y][blk_x][1] - list0_mv[blk_y2][blk_x2][1]) >= mvlimit));
}
else
{
StrValue = (byte) (
(iabs( list0_mv[blk_y][blk_x][0] - list0_mv[blk_y2][blk_x2][0]) >= 4) |
(iabs( list0_mv[blk_y][blk_x][1] - list0_mv[blk_y2][blk_x2][1]) >= mvlimit) |
(iabs( list1_mv[blk_y][blk_x][0] - list1_mv[blk_y2][blk_x2][0]) >= 4) |
(iabs( list1_mv[blk_y][blk_x][1] - list1_mv[blk_y2][blk_x2][1]) >= mvlimit));
}
}
else
{
StrValue = (byte) (
(iabs( list0_mv[blk_y][blk_x][0] - list1_mv[blk_y2][blk_x2][0]) >= 4) |
(iabs( list0_mv[blk_y][blk_x][1] - list1_mv[blk_y2][blk_x2][1]) >= mvlimit) |
(iabs( list1_mv[blk_y][blk_x][0] - list0_mv[blk_y2][blk_x2][0]) >= 4) |
(iabs( list1_mv[blk_y][blk_x][1] - list0_mv[blk_y2][blk_x2][1]) >= mvlimit));
}
}
else
{ // L0 and L1 reference pictures of p0 are the same; q0 as well
StrValue = (byte) (
((iabs( list0_mv[blk_y][blk_x][0] - list0_mv[blk_y2][blk_x2][0]) >= 4) |
(iabs( list0_mv[blk_y][blk_x][1] - list0_mv[blk_y2][blk_x2][1]) >= mvlimit ) |
(iabs( list1_mv[blk_y][blk_x][0] - list1_mv[blk_y2][blk_x2][0]) >= 4) |
(iabs( list1_mv[blk_y][blk_x][1] - list1_mv[blk_y2][blk_x2][1]) >= mvlimit))
&&
((iabs( list0_mv[blk_y][blk_x][0] - list1_mv[blk_y2][blk_x2][0]) >= 4) |
(iabs( list0_mv[blk_y][blk_x][1] - list1_mv[blk_y2][blk_x2][1]) >= mvlimit) |
(iabs( list1_mv[blk_y][blk_x][0] - list0_mv[blk_y2][blk_x2][0]) >= 4) |
(iabs( list1_mv[blk_y][blk_x][1] - list0_mv[blk_y2][blk_x2][1]) >= mvlimit)));
}
}
else
{
StrValue = 1;
}
}
memset(&Strength[idx], (byte) StrValue, BLOCK_SIZE * sizeof(byte));
}
}
else
{
// Start with Strength=3. or Strength=4 for Mb-edge
StrValue = (edge == 0 && ((((p->structure==FRAME))) || ((p->structure != FRAME) && !dir))) ? 4 : 3;
memset(&Strength[0], (byte) StrValue, MB_BLOCK_SIZE * sizeof(byte));
}
}
}
/*!
*********************************************************************************************
* \brief
* returns a buffer of 16 Strength values for one stripe in a mb (for MBAFF)
*********************************************************************************************
*/
void GetStrengthMBAff(byte Strength[16], ImageParameters *img, Macroblock *MbQ, int dir, int edge, int mvlimit, StorablePicture *p)
{
int blkP, blkQ, idx;
int blk_x, blk_x2, blk_y, blk_y2 ;
int64 ref_p0,ref_p1,ref_q0,ref_q1;
int xQ, yQ;
int mb_x, mb_y;
PixelPos pixP;
int dir_m1 = (1 - dir);
PicMotionParams *motion = &p->motion;
list0_mv = motion->mv[LIST_0];
list1_mv = motion->mv[LIST_1];
list0_refIdxArr = motion->ref_idx[LIST_0];
list1_refIdxArr = motion->ref_idx[LIST_1];
list0_refPicIdArr = motion->ref_pic_id[LIST_0];
list1_refPicIdArr = motion->ref_pic_id[LIST_1];
for( idx=0 ; idx<16 ; idx++ )
{
xQ = dir ? idx : edge;
yQ = dir ? (edge < MB_BLOCK_SIZE ? edge : 1) : idx;
getNeighbour(MbQ, xQ - dir_m1, yQ - dir, img->mb_size[IS_LUMA], &pixP);
blkQ = (yQ & 0xFFFC) + (xQ >> 2);
blkP = (pixP.y & 0xFFFC) + (pixP.x >> 2);
MbP = &(img->mb_data[pixP.mb_addr]);
mixedModeEdgeFlag = (byte) (MbQ->mb_field != MbP->mb_field);
if ((p->slice_type==SP_SLICE)||(p->slice_type==SI_SLICE) )
{
Strength[idx] = (edge == 0 && (((!p->MbaffFrameFlag && (p->structure==FRAME)) ||
(p->MbaffFrameFlag && !MbP->mb_field && !MbQ->mb_field)) ||
((p->MbaffFrameFlag || (p->structure != FRAME)) && !dir))) ? 4 : 3;
}
else
{
// Start with Strength=3. or Strength=4 for Mb-edge
Strength[idx] = (edge == 0 && (((!p->MbaffFrameFlag && (p->structure==FRAME)) ||
(p->MbaffFrameFlag && !MbP->mb_field && !MbQ->mb_field)) ||
((p->MbaffFrameFlag || (p->structure!=FRAME)) && !dir))) ? 4 : 3;
if( !(MbP->mb_type==I4MB || MbP->mb_type==I16MB || MbP->mb_type==I8MB || MbP->mb_type==IPCM)
&& !(MbQ->mb_type==I4MB || MbQ->mb_type==I16MB || MbQ->mb_type==I8MB || MbQ->mb_type==IPCM) )
{
if( ((MbQ->cbp_blk[0] & ((int64)1 << blkQ )) != 0) || ((MbP->cbp_blk[0] & ((int64)1 << blkP)) != 0) )
Strength[idx] = 2 ;
else
{
// if no coefs, but vector difference >= 1 set Strength=1
// if this is a mixed mode edge then one set of reference pictures will be frame and the
// other will be field
if (mixedModeEdgeFlag)
{
(Strength[idx] = 1);
}
else
{
get_mb_block_pos (MbQ->mbAddrX, &mb_x, &mb_y);
blk_y = (mb_y<<2) + (blkQ >> 2) ;
blk_x = (mb_x<<2) + (blkQ & 3) ;
blk_y2 = pixP.pos_y >> 2;
blk_x2 = pixP.pos_x >> 2;
{
ref_p0 = list0_refIdxArr[blk_y ][blk_x ] < 0 ? INT64_MIN : list0_refPicIdArr[blk_y ][blk_x];
ref_q0 = list0_refIdxArr[blk_y2][blk_x2] < 0 ? INT64_MIN : list0_refPicIdArr[blk_y2][blk_x2];
ref_p1 = list1_refIdxArr[blk_y ][blk_x ] < 0 ? INT64_MIN : list1_refPicIdArr[blk_y ][blk_x];
ref_q1 = list1_refIdxArr[blk_y2][blk_x2]<0 ? INT64_MIN : list1_refPicIdArr[blk_y2][blk_x2];
if ( ((ref_p0==ref_q0) && (ref_p1==ref_q1)) ||
((ref_p0==ref_q1) && (ref_p1==ref_q0)))
{
Strength[idx]=0;
// L0 and L1 reference pictures of p0 are different; q0 as well
if (ref_p0 != ref_p1)
{
// compare MV for the same reference picture
if (ref_p0==ref_q0)
{
Strength[idx] = (byte) (
(iabs( list0_mv[blk_y][blk_x][0] - list0_mv[blk_y2][blk_x2][0]) >= 4) |
(iabs( list0_mv[blk_y][blk_x][1] - list0_mv[blk_y2][blk_x2][1]) >= mvlimit) |
(iabs( list1_mv[blk_y][blk_x][0] - list1_mv[blk_y2][blk_x2][0]) >= 4) |
(iabs( list1_mv[blk_y][blk_x][1] - list1_mv[blk_y2][blk_x2][1]) >= mvlimit));
}
else
{
Strength[idx] = (byte) (
(iabs( list0_mv[blk_y][blk_x][0] - list1_mv[blk_y2][blk_x2][0]) >= 4) |
(iabs( list0_mv[blk_y][blk_x][1] - list1_mv[blk_y2][blk_x2][1]) >= mvlimit) |
(iabs( list1_mv[blk_y][blk_x][0] - list0_mv[blk_y2][blk_x2][0]) >= 4) |
(iabs( list1_mv[blk_y][blk_x][1] - list0_mv[blk_y2][blk_x2][1]) >= mvlimit));
}
}
else
{ // L0 and L1 reference pictures of p0 are the same; q0 as well
Strength[idx] = (byte) (
((iabs( list0_mv[blk_y][blk_x][0] - list0_mv[blk_y2][blk_x2][0]) >= 4) |
(iabs( list0_mv[blk_y][blk_x][1] - list0_mv[blk_y2][blk_x2][1]) >= mvlimit ) |
(iabs( list1_mv[blk_y][blk_x][0] - list1_mv[blk_y2][blk_x2][0]) >= 4) |
(iabs( list1_mv[blk_y][blk_x][1] - list1_mv[blk_y2][blk_x2][1]) >= mvlimit))
&&
((iabs( list0_mv[blk_y][blk_x][0] - list1_mv[blk_y2][blk_x2][0]) >= 4) |
(iabs( list0_mv[blk_y][blk_x][1] - list1_mv[blk_y2][blk_x2][1]) >= mvlimit) |
(iabs( list1_mv[blk_y][blk_x][0] - list0_mv[blk_y2][blk_x2][0]) >= 4) |
(iabs( list1_mv[blk_y][blk_x][1] - list0_mv[blk_y2][blk_x2][1]) >= mvlimit)));
}
}
else
{
Strength[idx] = 1;
}
}
}
}
}
}
}
}
/*!
*****************************************************************************************
* \brief
* Filters 16 pel block edge of Frame or Field coded MBs
*****************************************************************************************
*/
void EdgeLoopLumaNormal(ColorPlane pl, imgpel** Img, byte Strength[16], ImageParameters *img, Macroblock *MbQ,
int dir, int edge, StorablePicture *p)
{
static imgpel L2, L1, L0, R0, R1, R2, L3, R3;
static PixelPos pixP, pixQ, pixMB1, pixMB2;
static int C0, tc0, dif, RL0;
static int pel, ap, aq, Strng;
static int Alpha, Beta, small_gap;
static int indexA, indexB;
static int QP;
static const byte* ClipTab;
static int inc_dim, inc_dim3;
int xQ = dir ? 0 : edge - 1;
int yQ = dir ? (edge < MB_BLOCK_SIZE ? edge - 1: 0) : 0;
getNeighbour(MbQ, xQ, yQ, img->mb_size[IS_LUMA], &pixMB1);
if (pixMB1.available || (MbQ->DFDisableIdc== 0))
{
int AlphaC0Offset = MbQ->DFAlphaC0Offset;
int BetaOffset = MbQ->DFBetaOffset;
int dirM1 = (dir - 1);
int bitdepth_scale = pl ? img->bitdepth_scale[IS_CHROMA] : img->bitdepth_scale[IS_LUMA];
int max_imgpel_value = img->max_imgpel_value_comp[pl];
int width = p->size_x;
pixP = pixMB1;
MbP = &(img->mb_data[pixP.mb_addr]);
inc_dim = dir ? width : 1;
inc_dim3 = inc_dim * 3;
yQ += dir;
xQ -= dirM1;
getNeighbour(MbQ, xQ, yQ, img->mb_size[IS_LUMA], &pixMB2);
pixQ = pixMB2;
// Average QP of the two blocks
QP = pl? ((MbP->qpc[pl-1] + MbQ->qpc[pl-1] + 1) >> 1) : (MbP->qp + MbQ->qp + 1) >> 1;
indexA = iClip3(0, MAX_QP, QP + AlphaC0Offset);
indexB = iClip3(0, MAX_QP, QP + BetaOffset);
Alpha = ALPHA_TABLE[indexA] * bitdepth_scale;
Beta = BETA_TABLE [indexB] * bitdepth_scale;
ClipTab = CLIP_TAB[indexA];
for( pel = 0 ; pel < MB_BLOCK_SIZE ; pel++ )
{
if( (Strng = *(Strength++)) != 0)
{
SrcPtrQ = &(Img[pixQ.pos_y][pixQ.pos_x]);
SrcPtrP = &(Img[pixP.pos_y][pixP.pos_x]);
L3 = *(SrcPtrP -= inc_dim3);
L2 = *(SrcPtrP += inc_dim);
L1 = *(SrcPtrP += inc_dim);
L0 = *(SrcPtrP += inc_dim);
R0 = *SrcPtrQ;
R1 = *(SrcPtrQ += inc_dim);
R2 = *(SrcPtrQ += inc_dim);
R3 = *(SrcPtrQ += inc_dim);
if( iabs( R0 - L0 ) < Alpha )
{
if ((iabs( R0 - R1) < Beta) && (iabs(L0 - L1) < Beta))
{
if(Strng == 4 ) // INTRA strong filtering
{
RL0 = L0 + R0;
small_gap = (iabs( R0 - L0 ) < ((Alpha >> 2) + 2));
aq = ( iabs( R0 - R2) < Beta ) & small_gap;
ap = ( iabs( L0 - L2) < Beta ) & small_gap;
if (ap)
{
*SrcPtrP = (imgpel) (( R1 + ((L1 + RL0) << 1) + L2 + 4) >> 3);
*(SrcPtrP -= inc_dim) = (imgpel) (( L2 + L1 + RL0 + 2) >> 2);
*(SrcPtrP - inc_dim) = (imgpel) ((((L3 + L2) <<1) + L2 + L1 + RL0 + 4) >> 3);
}
else
{
*SrcPtrP = (imgpel) (((L1 << 1) + L0 + R1 + 2) >> 2) ;
}
if (aq)
{
*(SrcPtrQ -= inc_dim3) = (imgpel) (( L1 + ((R1 + RL0) << 1) + R2 + 4) >> 3);
*(SrcPtrQ += inc_dim ) = (imgpel) (( R2 + R0 + L0 + R1 + 2) >> 2);
*(SrcPtrQ + inc_dim ) = (imgpel) ((((R3 + R2) <<1) + R2 + R1 + RL0 + 4) >> 3);
}
else
{
*(SrcPtrQ - inc_dim3) = (imgpel) (((R1 << 1) + R0 + L1 + 2) >> 2);
}
}
else // normal filtering
{
RL0 = (L0 + R0 + 1) >> 1;
aq = (iabs(R0 - R2) < Beta);
ap = (iabs(L0 - L2) < Beta);
C0 = ClipTab[ Strng ] * bitdepth_scale;
tc0 = (C0 + ap + aq) ;
dif = iClip3( -tc0, tc0, (((R0 - L0) << 2) + (L1 - R1) + 4) >> 3 );
if( ap )
*(SrcPtrP - inc_dim) += iClip3( -C0, C0, (L2 + RL0 - (L1<<1)) >> 1 );
*SrcPtrP = (imgpel) iClip1(max_imgpel_value, L0 + dif);
*(SrcPtrQ -= inc_dim3) = (imgpel) iClip1(max_imgpel_value, R0 - dif);
if( aq )
*(SrcPtrQ + inc_dim) += iClip3( -C0, C0, (R2 + RL0 - (R1<<1)) >> 1 );
}
}
}
}
pixP.pos_x += dir;
pixQ.pos_x += dir;
pixP.pos_y -= dirM1;
pixQ.pos_y -= dirM1;
}
}
}
/*!
*****************************************************************************************
* \brief
* Filters 16 pel block edge of Super MB Frame coded MBs
*****************************************************************************************
*/
void EdgeLoopLumaMBAff(ColorPlane pl, imgpel** Img, byte Strength[16], ImageParameters *img, Macroblock *MbQ,
int dir, int edge, StorablePicture *p)
{
int width = p->size_x;
int pel, ap = 0, aq = 0, Strng ;
int incP, incQ;
int C0, tc0, dif;
imgpel L2 = 0, L1, L0, R0, R1, R2 = 0, L3, R3;
int RL0;
int Alpha = 0, Beta = 0 ;
const byte* ClipTab = NULL;
int small_gap;
int indexA, indexB;
int PelNum = pl? pelnum_cr[dir][p->chroma_format_idc] : MB_BLOCK_SIZE;
int QP;
int xQ, yQ;
PixelPos pixP, pixQ;
int dir_m1 = (1 - dir);
int bitdepth_scale = pl? img->bitdepth_scale[IS_CHROMA] : img->bitdepth_scale[IS_LUMA];
int max_imgpel_value = img->max_imgpel_value_comp[pl];
int AlphaC0Offset = MbQ->DFAlphaC0Offset;
int BetaOffset = MbQ->DFBetaOffset;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -