📄 loopfilter.c
字号:
for( pel = 0 ; pel < PelNum ; pel++ )
{
xQ = dir ? pel : edge;
yQ = dir ? (edge < 16 ? edge : 1) : pel;
getNeighbour(MbQ, xQ - (dir_m1), yQ - dir, img->mb_size[IS_LUMA], &pixP);
if (pixP.available || (MbQ->DFDisableIdc== 0))
{
if( (Strng = Strength[pel]) != 0)
{
getNeighbour(MbQ, xQ, yQ, img->mb_size[IS_LUMA], &pixQ);
MbP = &(img->mb_data[pixP.mb_addr]);
fieldModeFilteringFlag = (byte) (MbQ->mb_field || MbP->mb_field);
incQ = dir ? ((fieldModeFilteringFlag && !MbQ->mb_field) ? 2 * width : width) : 1;
incP = dir ? ((fieldModeFilteringFlag && !MbP->mb_field) ? 2 * width : width) : 1;
SrcPtrQ = &(Img[pixQ.pos_y][pixQ.pos_x]);
SrcPtrP = &(Img[pixP.pos_y][pixP.pos_x]);
// 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];
L3 = SrcPtrP[-incP*3];
L2 = SrcPtrP[-incP*2];
L1 = SrcPtrP[-incP];
L0 = SrcPtrP[0] ;
R0 = SrcPtrQ[0] ;
R1 = SrcPtrQ[ incQ];
R2 = SrcPtrQ[ incQ*2];
R3 = SrcPtrQ[ incQ*3];
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[-incP * 2] = (imgpel) ((((L3 + L2) << 1) + L2 + L1 + RL0 + 4) >> 3);
SrcPtrP[-incP ] = (imgpel) (( L2 + L1 + L0 + R0 + 2) >> 2);
SrcPtrP[ 0 ] = (imgpel) (( R1 + ((L1 + RL0) << 1) + L2 + 4) >> 3);
}
else
{
SrcPtrP[ 0 ] = (imgpel) (((L1 << 1) + L0 + R1 + 2) >> 2) ;
}
if (aq)
{
SrcPtrQ[ 0 ] = (imgpel) (( L1 + ((R1 + RL0) << 1) + R2 + 4) >> 3);
SrcPtrQ[ incQ ] = (imgpel) (( R2 + R0 + R1 + L0 + 2) >> 2);
SrcPtrQ[ incQ * 2 ] = (imgpel) ((((R3 + R2) << 1) + R2 + R1 + RL0 + 4) >> 3);
}
else
{
SrcPtrQ[ 0 ] = (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 - incP) += iClip3( -C0, C0, ( L2 + RL0 - (L1 << 1)) >> 1 ) ;
*SrcPtrP = (imgpel) iClip1 (max_imgpel_value, L0 + dif) ;
*SrcPtrQ = (imgpel) iClip1 (max_imgpel_value, R0 - dif) ;
if( aq )
*(SrcPtrQ + incQ) += iClip3( -C0, C0, ( R2 + RL0 - (R1 << 1)) >> 1 ) ;
}
}
}
}
}
}
}
/*!
*****************************************************************************************
* \brief
* Filters chroma block edge for Frame or Field coded pictures
*****************************************************************************************
*/
void EdgeLoopChromaNormal(imgpel** Img, byte Strength[16], ImageParameters *img, Macroblock *MbQ,
int dir, int edge, int uv, StorablePicture *p)
{
static int pel, Strng ;
static int inc_dim;
static int tc0, dif;
static imgpel L1, L0, R0, R1;
static int Alpha, Beta;
static const byte* ClipTab;
static int indexA, indexB;
static int StrengthIdx;
static PixelPos pixP, pixQ, pixMB1, pixMB2;
static int QP;
int PelNum = pelnum_cr[dir][p->chroma_format_idc];
int bitdepth_scale = img->bitdepth_scale[IS_CHROMA];
int max_imgpel_value = img->max_imgpel_value_comp[uv + 1];
int xQ = dir ? 0 : edge - 1;
int yQ = dir ? (edge < 16 ? edge - 1: 0) : 0;
getNeighbour(MbQ, xQ, yQ, img->mb_size[IS_CHROMA], &pixMB1);
if (pixMB1.available || (MbQ->DFDisableIdc == 0))
{
int AlphaC0Offset = MbQ->DFAlphaC0Offset;
int BetaOffset = MbQ->DFBetaOffset;
int width = p->size_x_cr;
int dirM1 = dir - 1;
pixP = pixMB1;
MbP = &(img->mb_data[pixP.mb_addr]);
yQ += dir;
xQ -= dirM1;
inc_dim = dir ? width : 1;
getNeighbour(MbQ, xQ, yQ, img->mb_size[IS_CHROMA], &pixMB2);
pixQ = pixMB2;
// Average QP of the two blocks
QP = (MbP->qpc[uv] + MbQ->qpc[uv] + 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 < PelNum ; pel++ )
{
StrengthIdx = (PelNum == 8) ? (((pel >> 1) << 2) + (pel & 0x01)) : pel;
if( (Strng = Strength[StrengthIdx]) != 0)
{
SrcPtrP = &(Img[pixP.pos_y][pixP.pos_x]);
L1 = *(SrcPtrP - inc_dim);
L0 = *SrcPtrP;
SrcPtrQ = &(Img[pixQ.pos_y][pixQ.pos_x]);
R0 = *SrcPtrQ;
R1 = *(SrcPtrQ + inc_dim);
if (( iabs( R0 - L0 ) < Alpha ) && ( iabs(R0 - R1) < Beta ) && ( iabs(L0 - L1) < Beta ) )
{
if( Strng == 4 ) // INTRA strong filtering
{
*SrcPtrP = (imgpel) ( ((L1 << 1) + L0 + R1 + 2) >> 2 );
*SrcPtrQ = (imgpel) ( ((R1 << 1) + R0 + L1 + 2) >> 2 );
}
else
{
tc0 = ClipTab[ Strng ] * bitdepth_scale + 1;
dif = iClip3( -tc0, tc0, ( ((R0 - L0) << 2) + (L1 - R1) + 4) >> 3 );
*SrcPtrP = (imgpel) iClip1 ( max_imgpel_value, L0 + dif) ;
*SrcPtrQ = (imgpel) iClip1 ( max_imgpel_value, R0 - dif) ;
}
}
}
pixP.pos_x += dir;
pixQ.pos_x += dir;
pixP.pos_y -= dirM1;
pixQ.pos_y -= dirM1;
}
}
}
/*!
*****************************************************************************************
* \brief
* Filters chroma block edge for MBAFF types
*****************************************************************************************
*/
void EdgeLoopChromaMBAff(imgpel** Img, byte Strength[16], ImageParameters *img, Macroblock *MbQ,
int dir, int edge, int uv, StorablePicture *p)
{
int pel, Strng ;
int incP, incQ;
int C0, tc0, dif;
imgpel L1, L0, R0, R1;
int Alpha = 0, Beta = 0;
const byte* ClipTab = NULL;
int indexA, indexB;
int PelNum = pelnum_cr[dir][p->chroma_format_idc];
int StrengthIdx;
int QP;
int xQ, yQ;
PixelPos pixP, pixQ;
int dir_m1 = 1 - dir;
int bitdepth_scale = img->bitdepth_scale[IS_CHROMA];
int max_imgpel_value = img->max_imgpel_value_comp[uv + 1];
int AlphaC0Offset = MbQ->DFAlphaC0Offset;
int BetaOffset = MbQ->DFBetaOffset;
int width = p->size_x_cr;
for( pel = 0 ; pel < PelNum ; pel++ )
{
xQ = dir ? pel : edge;
yQ = dir ? (edge < 16? edge : 1) : pel;
getNeighbour(MbQ, xQ, yQ, img->mb_size[IS_CHROMA], &pixQ);
getNeighbour(MbQ, xQ - (dir_m1), yQ - dir, img->mb_size[IS_CHROMA], &pixP);
MbP = &(img->mb_data[pixP.mb_addr]);
StrengthIdx = (PelNum == 8) ? ((MbQ->mb_field && !MbP->mb_field) ? pel << 1 :((pel >> 1) << 2) + (pel & 0x01)) : pel;
if (pixP.available || (MbQ->DFDisableIdc == 0))
{
if( (Strng = Strength[StrengthIdx]) != 0)
{
fieldModeFilteringFlag = (byte) (MbQ->mb_field || MbP->mb_field);
incQ = dir ? ((fieldModeFilteringFlag && !MbQ->mb_field) ? 2 * width : width) : 1;
incP = dir ? ((fieldModeFilteringFlag && !MbP->mb_field) ? 2 * width : width) : 1;
SrcPtrQ = &(Img[pixQ.pos_y][pixQ.pos_x]);
SrcPtrP = &(Img[pixP.pos_y][pixP.pos_x]);
// Average QP of the two blocks
QP = (MbP->qpc[uv] + MbQ->qpc[uv] + 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];
L1 = SrcPtrP[-incP];
L0 = SrcPtrP[0] ;
R0 = SrcPtrQ[0] ;
R1 = SrcPtrQ[ incQ];
if( iabs( R0 - L0 ) < Alpha )
{
if( ((iabs( R0 - R1) - Beta ) & (iabs(L0 - L1) - Beta )) < 0 )
{
if( Strng == 4 ) // INTRA strong filtering
{
SrcPtrQ[0] = (imgpel) ( ((R1 << 1) + R0 + L1 + 2) >> 2 );
SrcPtrP[0] = (imgpel) ( ((L1 << 1) + L0 + R1 + 2) >> 2 );
}
else
{
C0 = ClipTab[ Strng ] * bitdepth_scale;
tc0 = (C0 + 1);
dif = iClip3( -tc0, tc0, ( ((R0 - L0) << 2) + (L1 - R1) + 4) >> 3 );
SrcPtrP[0] = (imgpel) iClip1 ( max_imgpel_value, L0 + dif );
SrcPtrQ[0] = (imgpel) iClip1 ( max_imgpel_value, R0 - dif );
}
}
}
}
}
}
}
int compute_deblock_strength(char **list0_refIdxArr,
char **list1_refIdxArr,
int64 **list0_refPicIdArr,
int64 **list1_refPicIdArr,
short ***list0_mv,
short ***list1_mv,
int blk_y, int blk_x,
int blk_y2, int blk_x2,
int mvlimit)
{
static int64 ref_p0, ref_q0, ref_p1, ref_q1;
static byte StrValue;
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)))
{
// 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)
{
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;
}
return StrValue;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -