loopfilter.cpp

来自「JMVM MPEG MVC/3DAV 测试平台 国际通用标准」· C++ 代码 · 共 1,794 行 · 第 1/5 页

CPP
1,794
字号
  {
    return xCheckMvDataP_RefIdx( rcMbDataCurrMot, cIdx, rcMbDataAboveMot, cIdx + ABOVE_MB_ABOVE_NEIGHBOUR,
                                 sHorMvThr, sVerMvThr,
                                 *pcRefFrameList0 );
  }
  return   xCheckMvDataB_RefIdx( rcMbDataCurrMot, cIdx, rcMbDataAboveMot, cIdx + ABOVE_MB_ABOVE_NEIGHBOUR,
                                 sHorMvThr, sVerMvThr,
                                 *pcRefFrameList0, *pcRefFrameList1 );

}









UChar LoopFilter::xCheckMvDataP_RefIdx( const MbData& rcQMbData,
                                        const LumaIdx cQIdx,
                                        const MbData& rcPMbData,
                                        const LumaIdx cPIdx,
                                        const Short   sHorMvThr,
                                        const Short   sVerMvThr,
                                        RefFrameList& rcRefFrameList0 )
{
  const MbMotionData& rcMbMotionDataL0Q = rcQMbData.getMbMotionData( LIST_0 );
  const MbMotionData& rcMbMotionDataL0P = rcPMbData.getMbMotionData( LIST_0 );

  IntFrame* pcRefPicL0Q = rcRefFrameList0[ rcMbMotionDataL0Q.getRefIdx( cQIdx ) ];
  IntFrame* pcRefPicL0P = rcRefFrameList0[ rcMbMotionDataL0P.getRefIdx( cPIdx ) ];

  // different reference pictures
  ROTRS( pcRefPicL0Q != pcRefPicL0P, 1 );

  // check the motion vector distance
  const Mv& cMvQ = rcMbMotionDataL0Q.getMv( cQIdx );
  const Mv& cMvP = rcMbMotionDataL0P.getMv( cPIdx );

  ROTRS( cMvP.getAbsHorDiff( cMvQ ) >= sHorMvThr, 1 );
  ROTRS( cMvP.getAbsVerDiff( cMvQ ) >= sVerMvThr, 1 );
  
  //{{SAMSUNG&KHU (JVT-W024)
#if JMVM_ONLY 
  if ((rcQMbData.getMbIcp().getIcAct() && rcPMbData.getMbIcp().getIcAct() && 
      (rcQMbData.getMbIcp().getIcp().getOffset() != rcPMbData.getMbIcp().getIcp().getOffset())) ||
      (rcQMbData.getMbIcp().getIcAct() ^ rcPMbData.getMbIcp().getIcAct()))
  {
    if ( abs(rcQMbData.getMbIcp().getIcp().getOffset() - rcPMbData.getMbIcp().getIcp().getOffset()) >= T)
      return K2;
    else
      return K1;
  }
#endif
  //}}

  return 0;
}





UChar LoopFilter::xCheckMvDataB_RefIdx( const MbData& rcQMbData,
                                        const LumaIdx cQIdx,
                                        const MbData& rcPMbData,
                                        const LumaIdx cPIdx,
                                        const Short   sHorMvThr,
                                        const Short   sVerMvThr,
                                        RefFrameList& rcRefFrameList0,
                                        RefFrameList& rcRefFrameList1 )
{
  const MbMotionData& rcMbMotionDataL0Q = rcQMbData.getMbMotionData( LIST_0 );
  const MbMotionData& rcMbMotionDataL1Q = rcQMbData.getMbMotionData( LIST_1 );
  const MbMotionData& rcMbMotionDataL0P = rcPMbData.getMbMotionData( LIST_0 );
  const MbMotionData& rcMbMotionDataL1P = rcPMbData.getMbMotionData( LIST_1 );

  IntFrame* pcRefPicL0Q = rcRefFrameList0[ rcMbMotionDataL0Q.getRefIdx( cQIdx ) ];
  IntFrame* pcRefPicL1Q = rcRefFrameList1[ rcMbMotionDataL1Q.getRefIdx( cQIdx ) ];
  IntFrame* pcRefPicL0P = rcRefFrameList0[ rcMbMotionDataL0P.getRefIdx( cPIdx ) ];
  IntFrame* pcRefPicL1P = rcRefFrameList1[ rcMbMotionDataL1P.getRefIdx( cPIdx ) ];

  UInt uiNumberOfUsedPic;
  {
    // check the number of used ref frames
    UInt uiQNumberOfUsedPic = ( pcRefPicL0Q ? 1 : 0 ) + ( pcRefPicL1Q ? 1 : 0 );
    UInt uiPNumberOfUsedPic = ( pcRefPicL0P ? 1 : 0 ) + ( pcRefPicL1P ? 1 : 0 );
    ROTRS( uiPNumberOfUsedPic != uiQNumberOfUsedPic, 1 );
    uiNumberOfUsedPic = uiPNumberOfUsedPic;
  }

  if( 1 == uiNumberOfUsedPic )
  {
    // this is the easy part
    // check whether they ref diff ref pic or not
    IntFrame* pcRefPicQ = ( pcRefPicL0Q ? pcRefPicL0Q : pcRefPicL1Q );
    IntFrame* pcRefPicP = ( pcRefPicL0P ? pcRefPicL0P : pcRefPicL1P );
    ROTRS( pcRefPicQ != pcRefPicP, 1 );

    // check the motion vector distance
    const Mv& cMvQ = ( pcRefPicL0Q ? rcMbMotionDataL0Q.getMv( cQIdx ) : rcMbMotionDataL1Q.getMv( cQIdx ) );
    const Mv& cMvP = ( pcRefPicL0P ? rcMbMotionDataL0P.getMv( cPIdx ) : rcMbMotionDataL1P.getMv( cPIdx ) );

    ROTRS( cMvP.getAbsHorDiff( cMvQ ) >= sHorMvThr, 1 );
    ROTRS( cMvP.getAbsVerDiff( cMvQ ) >= sVerMvThr, 1 );
    
  //{{SAMSUNG&KHU (JVT-W024)
#if JMVM_ONLY 
  if ((rcQMbData.getMbIcp().getIcAct() && rcPMbData.getMbIcp().getIcAct() && 
      (rcQMbData.getMbIcp().getIcp().getOffset() != rcPMbData.getMbIcp().getIcp().getOffset())) ||
      (rcQMbData.getMbIcp().getIcAct() ^ rcPMbData.getMbIcp().getIcAct()))
  {
    if ( abs(rcQMbData.getMbIcp().getIcp().getOffset() - rcPMbData.getMbIcp().getIcp().getOffset()) >= T)
      return K2;
    else
      return K1;
  }
#endif
  //}}

    return 0;
  }


  // both ref pic are used for both blocks
  if( pcRefPicL1P != pcRefPicL0P )
  {
    // at least two diff ref pic are in use
    if( pcRefPicL1P != pcRefPicL1Q )
    {
      ROTRS( pcRefPicL1P != pcRefPicL0Q, 1 );
      ROTRS( pcRefPicL0P != pcRefPicL1Q, 1 );

      // rcRefPicL0P == rcRefPicL1Q && rcRefPicL1P == rcRefPicL0Q
      // check the motion vector distance
      const Mv& cMvQ0 = rcMbMotionDataL0Q.getMv( cQIdx );
      const Mv& cMvP0 = rcMbMotionDataL0P.getMv( cPIdx );
      const Mv& cMvQ1 = rcMbMotionDataL1Q.getMv( cQIdx );
      const Mv& cMvP1 = rcMbMotionDataL1P.getMv( cPIdx );

      ROTRS( cMvP0.getAbsHorDiff( cMvQ1 ) >= sHorMvThr, 1 );
      ROTRS( cMvP0.getAbsVerDiff( cMvQ1 ) >= sVerMvThr, 1 );
      ROTRS( cMvP1.getAbsHorDiff( cMvQ0 ) >= sHorMvThr, 1 );
      ROTRS( cMvP1.getAbsVerDiff( cMvQ0 ) >= sVerMvThr, 1 );

      //{{SAMSUNG&KHU (JVT-W024)
#if JMVM_ONLY 
      if ((rcQMbData.getMbIcp().getIcAct() && rcPMbData.getMbIcp().getIcAct() && 
          (rcQMbData.getMbIcp().getIcp().getOffset() != rcPMbData.getMbIcp().getIcp().getOffset())) ||
          (rcQMbData.getMbIcp().getIcAct() ^ rcPMbData.getMbIcp().getIcAct()))
      {
        if ( abs(rcQMbData.getMbIcp().getIcp().getOffset() - rcPMbData.getMbIcp().getIcp().getOffset()) >= T)
          return K2;
        else
          return K1;
      }
#endif
      //}}

      return 0;
    }

    // rcRefPicL1P == rcRefPicL1Q
    ROTRS( pcRefPicL0P != pcRefPicL0Q, 1 );

    // rcRefPicL0P == rcRefPicL0Q && rcRefPicL1P == rcRefPicL1Q
    // check the motion vector distance
    const Mv& cMvQ0 = rcMbMotionDataL0Q.getMv( cQIdx );
    const Mv& cMvP0 = rcMbMotionDataL0P.getMv( cPIdx );
    const Mv& cMvQ1 = rcMbMotionDataL1Q.getMv( cQIdx );
    const Mv& cMvP1 = rcMbMotionDataL1P.getMv( cPIdx );

    ROTRS( cMvP0.getAbsHorDiff( cMvQ0 ) >= sHorMvThr, 1 );
    ROTRS( cMvP0.getAbsVerDiff( cMvQ0 ) >= sVerMvThr, 1 );
    ROTRS( cMvP1.getAbsHorDiff( cMvQ1 ) >= sHorMvThr, 1 );
    ROTRS( cMvP1.getAbsVerDiff( cMvQ1 ) >= sVerMvThr, 1 );

    //{{SAMSUNG&KHU (JVT-W024)
#if JMVM_ONLY 
    if ((rcQMbData.getMbIcp().getIcAct() && rcPMbData.getMbIcp().getIcAct() && 
        (rcQMbData.getMbIcp().getIcp().getOffset() != rcPMbData.getMbIcp().getIcp().getOffset())) ||
        (rcQMbData.getMbIcp().getIcAct() ^ rcPMbData.getMbIcp().getIcAct()))
    {
      if ( abs(rcQMbData.getMbIcp().getIcp().getOffset() - rcPMbData.getMbIcp().getIcp().getOffset()) >= T)
        return K2;
      else
        return K1;
    }
#endif
    //}}

    return 0;
  }
 
  //  rcRefPicL1P == rcRefPicL0P
  ROTRS( pcRefPicL1Q != pcRefPicL0Q, 1 ) ;
  ROTRS( pcRefPicL0P != pcRefPicL0Q, 1 ) ;

  // rcRefPicL0P == rcRefPicL0Q == rcRefPicL1P == rcRefPicL1Q
  // check the motion vector distance
  const Mv& cMvQ0 = rcMbMotionDataL0Q.getMv( cQIdx );
  const Mv& cMvP0 = rcMbMotionDataL0P.getMv( cPIdx );
  const Mv& cMvQ1 = rcMbMotionDataL1Q.getMv( cQIdx );
  const Mv& cMvP1 = rcMbMotionDataL1P.getMv( cPIdx );

  Bool              bSameListCond  = ( (cMvP0.getAbsHorDiff( cMvQ0 ) >= sHorMvThr) );
  bSameListCond = ( bSameListCond || ( (cMvP0.getAbsVerDiff( cMvQ0 ) >= sVerMvThr) ) );
  bSameListCond = ( bSameListCond || ( (cMvP1.getAbsHorDiff( cMvQ1 ) >= sHorMvThr) ) );
  bSameListCond = ( bSameListCond || ( (cMvP1.getAbsVerDiff( cMvQ1 ) >= sVerMvThr) ) );
  Bool              bDiffListCond  = ( (cMvP0.getAbsHorDiff( cMvQ1 ) >= sHorMvThr) );
  bDiffListCond = ( bDiffListCond || ( (cMvP0.getAbsVerDiff( cMvQ1 ) >= sVerMvThr) ) );
  bDiffListCond = ( bDiffListCond || ( (cMvP1.getAbsHorDiff( cMvQ0 ) >= sHorMvThr) ) );
  bDiffListCond = ( bDiffListCond || ( (cMvP1.getAbsVerDiff( cMvQ0 ) >= sVerMvThr) ) );

  ROTRS( bSameListCond && bDiffListCond, 1 );

  //{{SAMSUNG&KHU (JVT-W024)
#if JMVM_ONLY 
  if ((rcQMbData.getMbIcp().getIcAct() && rcPMbData.getMbIcp().getIcAct() && 
      (rcQMbData.getMbIcp().getIcp().getOffset() != rcPMbData.getMbIcp().getIcp().getOffset())) ||
      (rcQMbData.getMbIcp().getIcAct() ^ rcPMbData.getMbIcp().getIcAct()))
  {
    if ( abs(rcQMbData.getMbIcp().getIcp().getOffset() - rcPMbData.getMbIcp().getIcp().getOffset()) >= T)
      return K2;
    else
      return K1;
  }
#endif
  //}}

  return 0;
}




__inline Void LoopFilter::xFilter( XPel* pFlt, const Int& iOffset, const Int& iIndexA, const Int& iIndexB, const UChar& ucBs, const Bool& bLum )
{
  const Int iAlpha = g_acAlphaClip[ iIndexA ].ucAlpha;

  Int P0 = pFlt[-iOffset];
  Int Q0 = pFlt[       0];

  Int iDelta = Q0 - P0;
  Int iAbsDelta  = abs( iDelta  );

  AOF_DBG( ucBs );

  ROFVS( iAbsDelta < iAlpha );


  const Int iBeta = g_aucBetaTab [ iIndexB ];

  Int P1  = pFlt[-2*iOffset];
  Int Q1  = pFlt[   iOffset];

  ROFVS( (abs(P0 - P1) < iBeta) && (abs(Q0 - Q1) < iBeta) );

  if( ucBs < 4 )
  {
    Int C0 = g_acAlphaClip[ iIndexA ].aucClip[ucBs];

    if( bLum )
    {
      Int P2 = pFlt[-3*iOffset] ;
      Int Q2 = pFlt[ 2*iOffset] ;
      Int aq = (( abs( Q2 - Q0 ) < iBeta ) ? 1 : 0 );
      Int ap = (( abs( P2 - P0 ) < iBeta ) ? 1 : 0 );

      if( ap )
      {
        pFlt[-2*iOffset] = P1 + gClipMinMax((P2 + ((P0 + Q0 + 1)>>1) - (P1<<1)) >> 1, -C0, C0 );
      }

      if( aq  )
      {
        pFlt[   iOffset] = Q1 + gClipMinMax((Q2 + ((P0 + Q0 + 1)>>1) - (Q1<<1)) >> 1, -C0, C0 );
      }

      C0 += ap + aq -1;
    }

    C0++;
    Int iDiff      = gClipMinMax(((iDelta << 2) + (P1 - Q1) + 4) >> 3, -C0, C0 ) ;
    pFlt[-iOffset] = gClip( P0 + iDiff );
    pFlt[       0] = gClip( Q0 - iDiff );
    return;
  }


  if( ! bLum )
  {
    pFlt[         0] = ((Q1 << 1) + Q0 + P1 + 2) >> 2;
    pFlt[  -iOffset] = ((P1 << 1) + P0 + Q1 + 2) >> 2;
  }
  else
  {
    Int P2 = pFlt[-3*iOffset] ;
    Int Q2 = pFlt[ 2*iOffset] ;
    Bool bEnable  = (iAbsDelta < ((iAlpha >> 2) + 2));
    Bool aq       = bEnable & ( abs( Q2 - Q0 ) < iBeta );
    Bool ap       = bEnable & ( abs( P2 - P0 ) < iBeta );
    Int PQ0 = P0 + Q0;

    if( aq )
    {
      pFlt[         0] = (P1 + ((Q1 + PQ0) << 1) +  Q2 + 4) >> 3;
      pFlt[   iOffset] = (PQ0 +Q1 + Q2 + 2) >> 2;
      pFlt[ 2*iOffset] = (((pFlt[ 3*iOffset] + Q2) <<1) + Q2 + Q1 + PQ0 + 4) >> 3;
    }
    else
    {
      pFlt[         0] = ((Q1 << 1) + Q0 + P1 + 2) >> 2;
    }

    if( ap )
    {
      pFlt[  -iOffset] = (Q1 + ((P1 + PQ0) << 1) +  P2 + 4) >> 3;
      pFlt[-2*iOffset] = (PQ0 +P1 + P2 + 2) >> 2;
      pFlt[-3*iOffset] = (((pFlt[-4*iOffset] + P2) <<1) + pFlt[-3*iOffset] + P1 + PQ0 + 4) >> 3;
    }
    else
    {
      pFlt[  -iOffset] = ((P1 << 1) + P0 + Q1 + 2) >> 2;
    }
  }
}









__inline ErrVal LoopFilter::xLumaVerFiltering( const MbDataAccess& rcMbDataAccess, const DFP& rcDFP, IntYuvPicBuffer* pcYuvBuffer )
{
  Int   iStride = pcYuvBuffer->getLStride();
  XPel* pPelLum = pcYuvBuffer->getMbLumAddr();
  Int   iCurrQp = rcMbDataAccess.getMbData().getQpLF();

  //===== filtering of left macroblock edge =====
  {
    Int iLeftQp = rcMbDataAccess.getMbDataLeft().getQpLF();
    Int iQp     = ( iLeftQp + iCurrQp + 1) >> 1;

    //-----  curr == FRM && left == FRM  or  curr == FLD && left == FLD  -----
    Int iIndexA = gClipMinMax( rcDFP.getSliceAlphaC0Offset() + iQp, 0, 51);
    Int iIndexB = gClipMinMax( rcDFP.getSliceBetaOffset()    + iQp, 0, 51);

    for( Int yBlk = 0; yBlk < 4; yBlk++)
    {
      const UChar ucBs = m_aaaucBs[VER][0][yBlk];
      if( 0 != ucBs )
      {
       

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?