Changeset 608 in 3DVCSoftware for trunk/source/Lib/TLibCommon/TComLoopFilter.cpp


Ignore:
Timestamp:
1 Sep 2013, 22:47:26 (11 years ago)
Author:
tech
Message:

Merged DEV-2.0-dev0@604.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/source/Lib/TLibCommon/TComLoopFilter.cpp

    r443 r608  
    44 * granted under this license. 
    55 *
    6  * Copyright (c) 2010-2012, ITU/ISO/IEC
     6 * Copyright (c) 2010-2013, ITU/ISO/IEC
    77 * All rights reserved.
    88 *
     
    4949#define   EDGE_VER    0
    5050#define   EDGE_HOR    1
    51 #define   QpUV(iQpY)  ( g_aucChromaScale[ max( min( (iQpY), MAX_QP ), MIN_QP ) ] )
     51#define   QpUV(iQpY)  ( ((iQpY) < 0) ? (iQpY) : (((iQpY) > 57) ? ((iQpY)-6) : g_aucChromaScale[(iQpY)]) )
    5252
    5353#define DEFAULT_INTRA_TC_OFFSET 2 ///< Default intra TC offset
     
    5757// ====================================================================================================================
    5858
    59 const UChar tctable_8x8[56] =
    60 {
    61   0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,5,5,6,6,7,8,9,9,10,10,11,11,12,12,13,13,14,14
     59const UChar TComLoopFilter::sm_tcTable[54] =
     60{
     61  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,5,5,6,6,7,8,9,10,11,13,14,16,18,20,22,24
    6262};
    6363
    64 const UChar betatable_8x8[52] =
     64const UChar TComLoopFilter::sm_betaTable[52] =
    6565{
    6666  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,6,7,8,9,10,11,12,13,14,15,16,17,18,20,22,24,26,28,30,32,34,36,38,40,42,44,46,48,50,52,54,56,58,60,62,64
     
    7272
    7373TComLoopFilter::TComLoopFilter()
    74 : m_uiNumPartitions( 0 )
    75 {
    76   m_uiDisableDeblockingFilterIdc = 0;
    77   m_bLFCrossTileBoundary = true;
     74: m_uiNumPartitions(0)
     75, m_bLFCrossTileBoundary(true)
     76{
     77  for( UInt uiDir = 0; uiDir < 2; uiDir++ )
     78  {
     79    m_aapucBS       [uiDir] = NULL;
     80    m_aapbEdgeFilter[uiDir] = NULL;
     81  }
    7882}
    7983
     
    8589// Public member functions
    8690// ====================================================================================================================
    87 Void TComLoopFilter::setCfg( Bool DeblockingFilterControlPresent, UInt uiDisableDblkIdc, Int iBetaOffset_div2, Int iTcOffset_div2, Bool bLFCrossTileBoundary)
     91Void TComLoopFilter::setCfg( Bool bLFCrossTileBoundary )
    8892{
    8993  m_bLFCrossTileBoundary = bLFCrossTileBoundary;
    90 
    91   if (DeblockingFilterControlPresent)
    92   {
    93     m_uiDisableDeblockingFilterIdc  = uiDisableDblkIdc;
    94     m_betaOffsetDiv2 = iBetaOffset_div2;
    95     m_tcOffsetDiv2 = iTcOffset_div2;
    96   }
    97   else // use default values
    98   {
    99     m_uiDisableDeblockingFilterIdc = 0;
    100     m_betaOffsetDiv2 = 0;
    101     m_tcOffsetDiv2 = 0;
    102   }
    10394}
    10495
    10596Void TComLoopFilter::create( UInt uiMaxCUDepth )
    10697{
     98  destroy();
    10799  m_uiNumPartitions = 1 << ( uiMaxCUDepth<<1 );
    108100  for( UInt uiDir = 0; uiDir < 2; uiDir++ )
    109101  {
    110102    m_aapucBS       [uiDir] = new UChar[m_uiNumPartitions];
    111     for( UInt uiPlane = 0; uiPlane < 3; uiPlane++ )
    112     {
    113       m_aapbEdgeFilter[uiDir][uiPlane] = new Bool [m_uiNumPartitions];
    114     }
     103    m_aapbEdgeFilter[uiDir] = new Bool [m_uiNumPartitions];
    115104  }
    116105}
     
    120109  for( UInt uiDir = 0; uiDir < 2; uiDir++ )
    121110  {
    122     delete [] m_aapucBS       [uiDir];
    123     for( UInt uiPlane = 0; uiPlane < 3; uiPlane++ )
    124     {
    125       delete [] m_aapbEdgeFilter[uiDir][uiPlane];
     111    if (m_aapucBS)
     112    {
     113      delete [] m_aapucBS       [uiDir];
     114      m_aapucBS [uiDir] = NULL;
     115    }
     116    if (m_aapbEdgeFilter[uiDir])
     117    {
     118      delete [] m_aapbEdgeFilter[uiDir];
     119      m_aapbEdgeFilter[uiDir] = NULL;
    126120    }
    127121  }
     
    135129Void TComLoopFilter::loopFilterPic( TComPic* pcPic )
    136130{
    137   if (m_uiDisableDeblockingFilterIdc == 1)
    138   {
    139     return;
    140   }
    141  
    142131  // Horizontal filtering
    143132  for ( UInt uiCUAddr = 0; uiCUAddr < pcPic->getNumCUsInFrame(); uiCUAddr++ )
     
    146135
    147136    ::memset( m_aapucBS       [EDGE_VER], 0, sizeof( UChar ) * m_uiNumPartitions );
    148     for( Int iPlane = 0; iPlane < 3; iPlane++ )
    149     {
    150       ::memset( m_aapbEdgeFilter[EDGE_VER][iPlane], 0, sizeof( bool  ) * m_uiNumPartitions );
    151     }
     137    ::memset( m_aapbEdgeFilter[EDGE_VER], 0, sizeof( Bool  ) * m_uiNumPartitions );
    152138
    153139    // CU-based deblocking
     
    160146    TComDataCU* pcCU = pcPic->getCU( uiCUAddr );
    161147
    162       ::memset( m_aapucBS       [EDGE_HOR], 0, sizeof( UChar ) * m_uiNumPartitions );
    163     for( Int iPlane = 0; iPlane < 3; iPlane++ )
    164     {
    165       ::memset( m_aapbEdgeFilter[EDGE_HOR][iPlane], 0, sizeof( bool  ) * m_uiNumPartitions );
    166     }
     148    ::memset( m_aapucBS       [EDGE_HOR], 0, sizeof( UChar ) * m_uiNumPartitions );
     149    ::memset( m_aapbEdgeFilter[EDGE_HOR], 0, sizeof( Bool  ) * m_uiNumPartitions );
    167150
    168151    // CU-based deblocking
     
    213196  for( UInt uiPartIdx = uiAbsZorderIdx; uiPartIdx < uiAbsZorderIdx + uiCurNumParts; uiPartIdx++ )
    214197  {
    215     UInt uiBSCheck = ((iDir == EDGE_VER && uiPartIdx%2 == 0) || (iDir == EDGE_HOR && (uiPartIdx-((uiPartIdx>>2)<<2))/2 == 0));
    216     if ( m_aapbEdgeFilter[iDir][0][uiPartIdx] && uiBSCheck )
    217     {
    218       xGetBoundaryStrengthSingle ( pcCU, uiAbsZorderIdx, iDir, uiPartIdx );
     198    UInt uiBSCheck;
     199    if( (g_uiMaxCUWidth >> g_uiMaxCUDepth) == 4 )
     200    {
     201      uiBSCheck = (iDir == EDGE_VER && uiPartIdx%2 == 0) || (iDir == EDGE_HOR && (uiPartIdx-((uiPartIdx>>2)<<2))/2 == 0);
     202    }
     203    else
     204    {
     205      uiBSCheck = 1;
     206    }
     207   
     208    if ( m_aapbEdgeFilter[iDir][uiPartIdx] && uiBSCheck )
     209    {
     210      xGetBoundaryStrengthSingle ( pcCU, iDir, uiPartIdx );
    219211    }
    220212  }
     
    228220  {
    229221    xEdgeFilterLuma     ( pcCU, uiAbsZorderIdx, uiDepth, iDir, iEdge );
    230     if ( (iEdge % ( (DEBLOCK_SMALLEST_BLOCK<<1)/uiPelsInPart ) ) == 0 )
     222    if ( (uiPelsInPart>DEBLOCK_SMALLEST_BLOCK) || (iEdge % ( (DEBLOCK_SMALLEST_BLOCK<<1)/uiPelsInPart ) ) == 0 )
    231223    {
    232224      xEdgeFilterChroma   ( pcCU, uiAbsZorderIdx, uiDepth, iDir, iEdge );
     
    235227}
    236228
    237 Void TComLoopFilter::xSetEdgefilterMultiple( TComDataCU* pcCU, UInt uiScanIdx, UInt uiDepth, Int iDir, Int iEdgeIdx, Bool bValue,UInt uiWidthInBaseUnits, UInt uiHeightInBaseUnits, Bool nonSquare )
     229Void TComLoopFilter::xSetEdgefilterMultiple( TComDataCU* pcCU, UInt uiScanIdx, UInt uiDepth, Int iDir, Int iEdgeIdx, Bool bValue,UInt uiWidthInBaseUnits, UInt uiHeightInBaseUnits )
    238230
    239231  if ( uiWidthInBaseUnits == 0 )
     
    252244  {
    253245    const UInt uiBsIdx = xCalcBsIdx( pcCU, uiScanIdx, iDir, iEdgeIdx, ui );
    254     m_aapbEdgeFilter[iDir][0][uiBsIdx] = bValue;
    255     m_aapbEdgeFilter[iDir][1][uiBsIdx] = bValue;
    256     m_aapbEdgeFilter[iDir][2][uiBsIdx] = bValue;
     246    m_aapbEdgeFilter[iDir][uiBsIdx] = bValue;
    257247    if (iEdgeIdx == 0)
    258248    {
     
    268258    const UInt uiCurNumParts = pcCU->getPic()->getNumPartInCU() >> (uiDepth<<1);
    269259    const UInt uiQNumParts   = uiCurNumParts>>2;
    270     const UInt uiLog2TrSize = g_aucConvertToBit[ pcCU->getSlice()->getSPS()->getMaxCUWidth() >> uiDepth ] + 2;
    271260    for ( UInt uiPartIdx = 0; uiPartIdx < 4; uiPartIdx++, uiAbsZorderIdx+=uiQNumParts )
    272261    {
    273       UInt nsAddr = 0;
    274       nsAddr = pcCU->getNSAbsPartIdx( uiLog2TrSize - 1, uiAbsZorderIdx, absTUPartIdx, uiPartIdx, uiDepth + 1 - pcCU->getDepth( uiAbsZorderIdx ) );
     262      UInt nsAddr = uiAbsZorderIdx;
    275263      xSetEdgefilterTU( pcCU,nsAddr, uiAbsZorderIdx, uiDepth + 1 );
    276264    }
     
    280268  Int trWidth  = pcCU->getWidth( uiAbsZorderIdx ) >> pcCU->getTransformIdx( uiAbsZorderIdx );
    281269  Int trHeight = pcCU->getHeight( uiAbsZorderIdx ) >> pcCU->getTransformIdx( uiAbsZorderIdx );
    282   pcCU->getNSQTSize( uiDepth - pcCU->getDepth( uiAbsZorderIdx ), uiAbsZorderIdx, trWidth, trHeight );
    283 
    284   UInt uiWidthInBaseUnits  = trWidth >> 2;
    285   UInt uiHeightInBaseUnits = trHeight >> 2;
     270 
     271  UInt uiWidthInBaseUnits  = trWidth / (g_uiMaxCUWidth >> g_uiMaxCUDepth);
     272  UInt uiHeightInBaseUnits = trHeight / (g_uiMaxCUWidth >> g_uiMaxCUDepth);
    286273
    287274  xSetEdgefilterMultiple( pcCU, absTUPartIdx, uiDepth, EDGE_VER, 0, m_stLFCUParam.bInternalEdge, uiWidthInBaseUnits, uiHeightInBaseUnits );
     
    360347  UInt        uiTempPartIdx;
    361348
    362   m_stLFCUParam.bInternalEdge = m_uiDisableDeblockingFilterIdc ? false : true ;
    363  
    364   if ( (uiX == 0) || (m_uiDisableDeblockingFilterIdc == 1) )
     349  m_stLFCUParam.bInternalEdge = ! pcCU->getSlice()->getDeblockingFilterDisable();
     350 
     351  if ( (uiX == 0) || pcCU->getSlice()->getDeblockingFilterDisable() )
    365352  {
    366353    m_stLFCUParam.bLeftEdge = false;
     
    372359  if ( m_stLFCUParam.bLeftEdge )
    373360  {
    374     pcTempCU = pcCU->getPULeft( uiTempPartIdx, uiAbsZorderIdx, !pcCU->getSlice()->getSPS()->getLFCrossSliceBoundaryFlag(), false, !m_bLFCrossTileBoundary);
     361    pcTempCU = pcCU->getPULeft( uiTempPartIdx, uiAbsZorderIdx, !pcCU->getSlice()->getLFCrossSliceBoundaryFlag(), !m_bLFCrossTileBoundary);
    375362    if ( pcTempCU )
    376363    {
     
    383370  }
    384371 
    385   if ( (uiY == 0 ) || (m_uiDisableDeblockingFilterIdc == 1) )
     372  if ( (uiY == 0 ) || pcCU->getSlice()->getDeblockingFilterDisable() )
    386373  {
    387374    m_stLFCUParam.bTopEdge = false;
     
    393380  if ( m_stLFCUParam.bTopEdge )
    394381  {
    395     pcTempCU = pcCU->getPUAbove( uiTempPartIdx, uiAbsZorderIdx, !pcCU->getSlice()->getSPS()->getLFCrossSliceBoundaryFlag(), false , false, false, !m_bLFCrossTileBoundary);
     382    pcTempCU = pcCU->getPUAbove( uiTempPartIdx, uiAbsZorderIdx, !pcCU->getSlice()->getLFCrossSliceBoundaryFlag(), false, !m_bLFCrossTileBoundary);
     383
    396384    if ( pcTempCU )
    397385    {
     
    405393}
    406394
    407 Void TComLoopFilter::xGetBoundaryStrengthSingle ( TComDataCU* pcCU, UInt uiAbsZorderIdx, Int iDir, UInt uiAbsPartIdx )
     395Void TComLoopFilter::xGetBoundaryStrengthSingle ( TComDataCU* pcCU, Int iDir, UInt uiAbsPartIdx )
    408396{
    409397  TComSlice* const pcSlice = pcCU->getSlice();
     
    419407  if (iDir == EDGE_VER)
    420408  {
    421     pcCUP = pcCUQ->getPULeft(uiPartP, uiPartQ, !pcCU->getSlice()->getSPS()->getLFCrossSliceBoundaryFlag(), false, !m_bLFCrossTileBoundary);
     409    pcCUP = pcCUQ->getPULeft(uiPartP, uiPartQ, !pcCU->getSlice()->getLFCrossSliceBoundaryFlag(), !m_bLFCrossTileBoundary);
    422410  }
    423411  else  // (iDir == EDGE_HOR)
    424412  {
    425     pcCUP = pcCUQ->getPUAbove(uiPartP, uiPartQ, !pcCU->getSlice()->getSPS()->getLFCrossSliceBoundaryFlag(), false, false, false, !m_bLFCrossTileBoundary);
     413    pcCUP = pcCUQ->getPUAbove(uiPartP, uiPartQ, !pcCU->getSlice()->getLFCrossSliceBoundaryFlag(), false, !m_bLFCrossTileBoundary);
    426414  }
    427415 
    428416  //-- Set BS for Intra MB : BS = 4 or 3
    429   if ( pcCUP->isIntra(uiPartP) || pcCUQ->isIntra(uiPartQ)
    430 #if MERL_VSP_C0152 & !QC_BVSP_CleanUP_D0191
    431     || pcCUP->getVSPIndex(uiPartP) || pcCUQ->getVSPIndex(uiPartQ)
    432 #endif
    433      )
     417  if ( pcCUP->isIntra(uiPartP) || pcCUQ->isIntra(uiPartQ) )
    434418  {
    435419    uiBs = 2;
     
    437421 
    438422  //-- Set BS for not Intra MB : BS = 2 or 1 or 0
    439   if ( !pcCUP->isIntra(uiPartP) && !pcCUQ->isIntra(uiPartQ)
    440 #if MERL_VSP_C0152 & !QC_BVSP_CleanUP_D0191
    441     && !pcCUP->getVSPIndex(uiPartP) && !pcCUQ->getVSPIndex(uiPartQ)
    442 #endif
    443   )
     423  if ( !pcCUP->isIntra(uiPartP) && !pcCUQ->isIntra(uiPartQ) )
    444424  {
    445425    UInt nsPartQ = uiPartQ;
    446426    UInt nsPartP = uiPartP;
    447     if(pcCUQ->getPredictionMode(uiPartQ) == MODE_INTER && pcCUQ->useNonSquarePU(uiPartQ))
    448     {
    449       nsPartQ = pcCUQ->getNSQTPartIdx( uiAbsPartIdx );
    450     }
    451     if(pcCUP->getPredictionMode(uiPartP) == MODE_INTER && pcCUP->useNonSquarePU(uiPartP))
    452     {
    453       nsPartP = pcCUP->getNSQTPartIdx( uiPartP );
    454     }
    455 
     427   
    456428    if ( m_aapucBS[iDir][uiAbsPartIdx] && (pcCUQ->getCbf( nsPartQ, TEXT_LUMA, pcCUQ->getTransformIdx(nsPartQ)) != 0 || pcCUP->getCbf( nsPartP, TEXT_LUMA, pcCUP->getTransformIdx(nsPartP) ) != 0) )
    457429    {
     
    462434      if (iDir == EDGE_HOR)
    463435      {
    464         pcCUP = pcCUQ->getPUAbove(uiPartP, uiPartQ, !pcCU->getSlice()->getSPS()->getLFCrossSliceBoundaryFlag(), false, true, false, !m_bLFCrossTileBoundary);
    465       }
    466       if (pcSlice->isInterB())
     436        pcCUP = pcCUQ->getPUAbove(uiPartP, uiPartQ, !pcCU->getSlice()->getLFCrossSliceBoundaryFlag(), false, !m_bLFCrossTileBoundary);
     437      }
     438      if (pcSlice->isInterB() || pcCUP->getSlice()->isInterB())
    467439      {
    468440        Int iRefIdx;
    469         Int *piRefP0, *piRefP1, *piRefQ0, *piRefQ1;
     441        TComPic *piRefP0, *piRefP1, *piRefQ0, *piRefQ1;
    470442        iRefIdx = pcCUP->getCUMvField(REF_PIC_LIST_0)->getRefIdx(uiPartP);
    471         piRefP0 = (iRefIdx < 0) ? NULL :  (Int*) pcSlice->getRefPic(REF_PIC_LIST_0, iRefIdx);
     443        piRefP0 = (iRefIdx < 0) ? NULL : pcCUP->getSlice()->getRefPic(REF_PIC_LIST_0, iRefIdx);
    472444        iRefIdx = pcCUP->getCUMvField(REF_PIC_LIST_1)->getRefIdx(uiPartP);
    473         piRefP1 = (iRefIdx < 0) ? NULL :  (Int*) pcSlice->getRefPic(REF_PIC_LIST_1, iRefIdx);
     445        piRefP1 = (iRefIdx < 0) ? NULL : pcCUP->getSlice()->getRefPic(REF_PIC_LIST_1, iRefIdx);
    474446        iRefIdx = pcCUQ->getCUMvField(REF_PIC_LIST_0)->getRefIdx(uiPartQ);
    475         piRefQ0 = (iRefIdx < 0) ? NULL :  (Int*) pcSlice->getRefPic(REF_PIC_LIST_0, iRefIdx);
     447        piRefQ0 = (iRefIdx < 0) ? NULL : pcSlice->getRefPic(REF_PIC_LIST_0, iRefIdx);
    476448        iRefIdx = pcCUQ->getCUMvField(REF_PIC_LIST_1)->getRefIdx(uiPartQ);
    477         piRefQ1 = (iRefIdx < 0) ? NULL :  (Int*) pcSlice->getRefPic(REF_PIC_LIST_1, iRefIdx);
    478        
     449        piRefQ1 = (iRefIdx < 0) ? NULL : pcSlice->getRefPic(REF_PIC_LIST_1, iRefIdx);
    479450       
    480451        TComMv pcMvP0 = pcCUP->getCUMvField(REF_PIC_LIST_0)->getMv(uiPartP);
     
    482453        TComMv pcMvQ0 = pcCUQ->getCUMvField(REF_PIC_LIST_0)->getMv(uiPartQ);
    483454        TComMv pcMvQ1 = pcCUQ->getCUMvField(REF_PIC_LIST_1)->getMv(uiPartQ);
    484        
     455
     456        if (piRefP0 == NULL) pcMvP0.setZero();
     457        if (piRefP1 == NULL) pcMvP1.setZero();
     458        if (piRefQ0 == NULL) pcMvQ0.setZero();
     459        if (piRefQ1 == NULL) pcMvQ1.setZero();
     460
    485461        if ( ((piRefP0==piRefQ0)&&(piRefP1==piRefQ1)) || ((piRefP0==piRefQ1)&&(piRefP1==piRefQ0)) )
    486462        {
    487           uiBs = 0;
    488463          if ( piRefP0 != piRefP1 )   // Different L0 & L1
    489464          {
    490465            if ( piRefP0 == piRefQ0 )
    491466            {
    492               pcMvP0 -= pcMvQ0;   pcMvP1 -= pcMvQ1;
    493               uiBs = (pcMvP0.getAbsHor() >= 4) | (pcMvP0.getAbsVer() >= 4) |
    494               (pcMvP1.getAbsHor() >= 4) | (pcMvP1.getAbsVer() >= 4);
     467              uiBs  = ((abs(pcMvQ0.getHor() - pcMvP0.getHor()) >= 4) ||
     468                       (abs(pcMvQ0.getVer() - pcMvP0.getVer()) >= 4) ||
     469                       (abs(pcMvQ1.getHor() - pcMvP1.getHor()) >= 4) ||
     470                       (abs(pcMvQ1.getVer() - pcMvP1.getVer()) >= 4)) ? 1 : 0;
    495471            }
    496472            else
    497473            {
    498               pcMvP0 -= pcMvQ1;   pcMvP1 -= pcMvQ0;
    499               uiBs = (pcMvP0.getAbsHor() >= 4) | (pcMvP0.getAbsVer() >= 4) |
    500               (pcMvP1.getAbsHor() >= 4) | (pcMvP1.getAbsVer() >= 4);
     474              uiBs  = ((abs(pcMvQ1.getHor() - pcMvP0.getHor()) >= 4) ||
     475                       (abs(pcMvQ1.getVer() - pcMvP0.getVer()) >= 4) ||
     476                       (abs(pcMvQ0.getHor() - pcMvP1.getHor()) >= 4) ||
     477                       (abs(pcMvQ0.getVer() - pcMvP1.getVer()) >= 4)) ? 1 : 0;
    501478            }
    502479          }
    503480          else    // Same L0 & L1
    504481          {
    505             TComMv pcMvSub0 = pcMvP0 - pcMvQ0;
    506             TComMv pcMvSub1 = pcMvP1 - pcMvQ1;
    507             pcMvP0 -= pcMvQ1;   pcMvP1 -= pcMvQ0;
    508             uiBs = ( (pcMvP0.getAbsHor() >= 4) | (pcMvP0.getAbsVer() >= 4) |
    509                     (pcMvP1.getAbsHor() >= 4) | (pcMvP1.getAbsVer() >= 4) ) &&
    510             ( (pcMvSub0.getAbsHor() >= 4) | (pcMvSub0.getAbsVer() >= 4) |
    511              (pcMvSub1.getAbsHor() >= 4) | (pcMvSub1.getAbsVer() >= 4) );
     482            uiBs  = ((abs(pcMvQ0.getHor() - pcMvP0.getHor()) >= 4) ||
     483                     (abs(pcMvQ0.getVer() - pcMvP0.getVer()) >= 4) ||
     484                     (abs(pcMvQ1.getHor() - pcMvP1.getHor()) >= 4) ||
     485                     (abs(pcMvQ1.getVer() - pcMvP1.getVer()) >= 4)) &&
     486                    ((abs(pcMvQ1.getHor() - pcMvP0.getHor()) >= 4) ||
     487                     (abs(pcMvQ1.getVer() - pcMvP0.getVer()) >= 4) ||
     488                     (abs(pcMvQ0.getHor() - pcMvP1.getHor()) >= 4) ||
     489                     (abs(pcMvQ0.getVer() - pcMvP1.getVer()) >= 4)) ? 1 : 0;
    512490          }
    513491        }
     
    520498      {
    521499        Int iRefIdx;
    522         Int *piRefP0, *piRefQ0;
     500        TComPic *piRefP0, *piRefQ0;
    523501        iRefIdx = pcCUP->getCUMvField(REF_PIC_LIST_0)->getRefIdx(uiPartP);
    524         piRefP0 = (iRefIdx < 0) ? NULL :  (Int*) pcSlice->getRefPic(REF_PIC_LIST_0, iRefIdx);
     502        piRefP0 = (iRefIdx < 0) ? NULL : pcCUP->getSlice()->getRefPic(REF_PIC_LIST_0, iRefIdx);
    525503        iRefIdx = pcCUQ->getCUMvField(REF_PIC_LIST_0)->getRefIdx(uiPartQ);
    526         piRefQ0 = (iRefIdx < 0) ? NULL :  (Int*) pcSlice->getRefPic(REF_PIC_LIST_0, iRefIdx);
     504        piRefQ0 = (iRefIdx < 0) ? NULL : pcSlice->getRefPic(REF_PIC_LIST_0, iRefIdx);
    527505        TComMv pcMvP0 = pcCUP->getCUMvField(REF_PIC_LIST_0)->getMv(uiPartP);
    528506        TComMv pcMvQ0 = pcCUQ->getCUMvField(REF_PIC_LIST_0)->getMv(uiPartQ);
     507
     508        if (piRefP0 == NULL) pcMvP0.setZero();
     509        if (piRefQ0 == NULL) pcMvQ0.setZero();
    529510       
    530         pcMvP0 -= pcMvQ0;
    531         uiBs = (piRefP0 != piRefQ0) | (pcMvP0.getAbsHor() >= 4) | (pcMvP0.getAbsVer() >= 4);
     511        uiBs  = ((piRefP0 != piRefQ0) ||
     512                 (abs(pcMvQ0.getHor() - pcMvP0.getHor()) >= 4) ||
     513                 (abs(pcMvQ0.getVer() - pcMvP0.getVer()) >= 4)) ? 1 : 0;
    532514      }
    533515    }   // enf of "if( one of BCBP == 0 )"
    534516  }   // enf of "if( not Intra )"
    535517 
    536 #if MERL_VSP_C0152 & !QC_BVSP_CleanUP_D0191
    537   if ( pcCUP->getVSPIndex(uiPartP) || pcCUQ->getVSPIndex(uiPartQ))
    538   {
    539     uiBs = 0;
    540   }
    541 #endif
    542 
    543518  m_aapucBS[iDir][uiAbsPartIdx] = uiBs;
    544519}
     
    568543  TComDataCU* pcCUP = pcCU;
    569544  TComDataCU* pcCUQ = pcCU;
    570  
     545  Int  betaOffsetDiv2 = pcCUQ->getSlice()->getDeblockingFilterBetaOffsetDiv2();
     546  Int  tcOffsetDiv2 = pcCUQ->getSlice()->getDeblockingFilterTcOffsetDiv2();
     547
    571548  if (iDir == EDGE_VER)
    572549  {
     
    593570      if (iDir == EDGE_VER)
    594571      {
    595         pcCUP = pcCUQ->getPULeft (uiPartPIdx, uiPartQIdx,!pcCU->getSlice()->getSPS()->getLFCrossSliceBoundaryFlag(), false, !m_bLFCrossTileBoundary);
     572        pcCUP = pcCUQ->getPULeft (uiPartPIdx, uiPartQIdx,!pcCU->getSlice()->getLFCrossSliceBoundaryFlag(), !m_bLFCrossTileBoundary);
    596573      }
    597574      else  // (iDir == EDGE_HOR)
    598575      {
    599         pcCUP = pcCUQ->getPUAbove(uiPartPIdx, uiPartQIdx,!pcCU->getSlice()->getSPS()->getLFCrossSliceBoundaryFlag(), false, false, false, !m_bLFCrossTileBoundary);
     576        pcCUP = pcCUQ->getPUAbove(uiPartPIdx, uiPartQIdx,!pcCU->getSlice()->getLFCrossSliceBoundaryFlag(), false, !m_bLFCrossTileBoundary);
    600577      }
    601578
    602579      iQP_P = pcCUP->getQP(uiPartPIdx);
     580      iQP = (iQP_P + iQP_Q + 1) >> 1;
     581      Int iBitdepthScale = 1 << (g_bitDepthY-8);
    603582     
    604       if(pcCU->getIPCMFlag(uiPartQIdx))
    605       {
    606         iQP_Q = 0;
    607       }
    608       if(pcCUP->getIPCMFlag(uiPartPIdx))
    609       {
    610         iQP_P = 0;
    611       }
     583      Int iIndexTC = Clip3(0, MAX_QP+DEFAULT_INTRA_TC_OFFSET, Int(iQP + DEFAULT_INTRA_TC_OFFSET*(uiBs-1) + (tcOffsetDiv2 << 1)));
     584      Int iIndexB = Clip3(0, MAX_QP, iQP + (betaOffsetDiv2 << 1));
    612585     
    613       iQP = (iQP_P + iQP_Q + 1) >> 1;
    614       Int iBitdepthScale = (1<<(g_uiBitIncrement+g_uiBitDepth-8));
    615      
    616       Int iIndexTC = Clip3(0, MAX_QP+DEFAULT_INTRA_TC_OFFSET, Int(iQP + DEFAULT_INTRA_TC_OFFSET*(uiBs-1) + (m_tcOffsetDiv2 << 1)));
    617       Int iIndexB = Clip3(0, MAX_QP, iQP + (m_betaOffsetDiv2 << 1));
    618      
    619       Int iTc =  tctable_8x8[iIndexTC]*iBitdepthScale;
    620       Int iBeta = betatable_8x8[iIndexB]*iBitdepthScale;
     586      Int iTc =  sm_tcTable[iIndexTC]*iBitdepthScale;
     587      Int iBeta = sm_betaTable[iIndexB]*iBitdepthScale;
    621588      Int iSideThreshold = (iBeta+(iBeta>>1))>>3;
    622589      Int iThrCut = iTc*10;
    623      
    624      
    625         Int dp0 = xCalcDP( piTmpSrc+iSrcStep*(iIdx*uiPelsInPart+0), iOffset);
    626         Int dq0 = xCalcDQ( piTmpSrc+iSrcStep*(iIdx*uiPelsInPart+0), iOffset);
    627         Int dp3 = xCalcDP( piTmpSrc+iSrcStep*(iIdx*uiPelsInPart+3), iOffset);
    628         Int dq3 = xCalcDQ( piTmpSrc+iSrcStep*(iIdx*uiPelsInPart+3), iOffset);
     590
     591      UInt  uiBlocksInPart = uiPelsInPart / 4 ? uiPelsInPart / 4 : 1;
     592      for (UInt iBlkIdx = 0; iBlkIdx<uiBlocksInPart; iBlkIdx ++)
     593      {
     594        Int dp0 = xCalcDP( piTmpSrc+iSrcStep*(iIdx*uiPelsInPart+iBlkIdx*4+0), iOffset);
     595        Int dq0 = xCalcDQ( piTmpSrc+iSrcStep*(iIdx*uiPelsInPart+iBlkIdx*4+0), iOffset);
     596        Int dp3 = xCalcDP( piTmpSrc+iSrcStep*(iIdx*uiPelsInPart+iBlkIdx*4+3), iOffset);
     597        Int dq3 = xCalcDQ( piTmpSrc+iSrcStep*(iIdx*uiPelsInPart+iBlkIdx*4+3), iOffset);
    629598        Int d0 = dp0 + dq0;
    630599        Int d3 = dp3 + dq3;
    631 
     600       
    632601        Int dp = dp0 + dp3;
    633602        Int dq = dq0 + dq3;
    634603        Int d =  d0 + d3;
    635604       
    636         if (bPCMFilter)
     605        if (bPCMFilter || pcCU->getSlice()->getPPS()->getTransquantBypassEnableFlag())
    637606        {
    638           // Check if each of PUs is I_PCM
    639           bPartPNoFilter = (pcCUP->getIPCMFlag(uiPartPIdx));
    640           bPartQNoFilter = (pcCUQ->getIPCMFlag(uiPartQIdx));
     607          // Check if each of PUs is I_PCM with LF disabling
     608          bPartPNoFilter = (bPCMFilter && pcCUP->getIPCMFlag(uiPartPIdx));
     609          bPartQNoFilter = (bPCMFilter && pcCUQ->getIPCMFlag(uiPartQIdx));
     610
     611          // check if each of PUs is lossless coded
     612          bPartPNoFilter = bPartPNoFilter || (pcCUP->isLosslessCoded(uiPartPIdx) );
     613          bPartQNoFilter = bPartQNoFilter || (pcCUQ->isLosslessCoded(uiPartQIdx) );
    641614        }
    642 #if LOSSLESS_CODING
    643         // check if each of PUs is lossless coded
    644         bPartPNoFilter = bPartPNoFilter || (pcCU->isLosslessCoded(uiAbsZorderIdx) );
    645         bPartQNoFilter = bPartQNoFilter || (pcCU->isLosslessCoded(uiAbsZorderIdx) );
    646 #endif
     615
    647616        if (d < iBeta)
    648617        {
    649618          Bool bFilterP = (dp < iSideThreshold);
    650619          Bool bFilterQ = (dq < iSideThreshold);
    651 
    652           Bool sw =  xUseStrongFiltering( iOffset, 2*d0, iBeta, iTc, piTmpSrc+iSrcStep*(iIdx*uiPelsInPart+0))
    653                   && xUseStrongFiltering( iOffset, 2*d3, iBeta, iTc, piTmpSrc+iSrcStep*(iIdx*uiPelsInPart+3));
    654 
     620         
     621          Bool sw =  xUseStrongFiltering( iOffset, 2*d0, iBeta, iTc, piTmpSrc+iSrcStep*(iIdx*uiPelsInPart+iBlkIdx*4+0))
     622          && xUseStrongFiltering( iOffset, 2*d3, iBeta, iTc, piTmpSrc+iSrcStep*(iIdx*uiPelsInPart+iBlkIdx*4+3));
     623         
    655624          for ( Int i = 0; i < DEBLOCK_SMALLEST_BLOCK/2; i++)
    656625          {
    657             xPelFilterLuma( piTmpSrc+iSrcStep*(iIdx*uiPelsInPart+i), iOffset, d, iBeta, iTc, sw, bPartPNoFilter, bPartQNoFilter, iThrCut, bFilterP, bFilterQ);
    658 
     626            xPelFilterLuma( piTmpSrc+iSrcStep*(iIdx*uiPelsInPart+iBlkIdx*4+i), iOffset, iTc, sw, bPartPNoFilter, bPartQNoFilter, iThrCut, bFilterP, bFilterQ);
    659627          }
    660628        }
     629      }
    661630    }
    662631  }
     
    687656  TComDataCU* pcCUP;
    688657  TComDataCU* pcCUQ = pcCU;
     658  Int tcOffsetDiv2 = pcCU->getSlice()->getDeblockingFilterTcOffsetDiv2();
    689659 
    690660  // Vertical Position
     
    692662  UInt uiEdgeNumInLCUHor = g_auiZscanToRaster[uiAbsZorderIdx]/uiLCUWidthInBaseUnits + iEdge;
    693663 
    694   if ( ( (uiEdgeNumInLCUVert%(DEBLOCK_SMALLEST_BLOCK/uiPelsInPartChroma))&&(iDir==0) ) || ( (uiEdgeNumInLCUHor%(DEBLOCK_SMALLEST_BLOCK/uiPelsInPartChroma))&& iDir ) )
     664  if ( (uiPelsInPartChroma < DEBLOCK_SMALLEST_BLOCK) && (( (uiEdgeNumInLCUVert%(DEBLOCK_SMALLEST_BLOCK/uiPelsInPartChroma))&&(iDir==0) ) || ( (uiEdgeNumInLCUHor%(DEBLOCK_SMALLEST_BLOCK/uiPelsInPartChroma))&& iDir ) ))
    695665  {
    696666    return;
     
    723693  for ( UInt iIdx = 0; iIdx < uiNumParts; iIdx++ )
    724694  {
    725     ucBs = 0;
    726    
    727695    uiBsAbsIdx = xCalcBsIdx( pcCU, uiAbsZorderIdx, iDir, iEdge, iIdx);
    728696    ucBs = m_aapucBS[iDir][uiBsAbsIdx];
     
    735703      if (iDir == EDGE_VER)
    736704      {
    737         pcCUP = pcCUQ->getPULeft (uiPartPIdx, uiPartQIdx,!pcCU->getSlice()->getSPS()->getLFCrossSliceBoundaryFlag(), false, !m_bLFCrossTileBoundary);
     705        pcCUP = pcCUQ->getPULeft (uiPartPIdx, uiPartQIdx,!pcCU->getSlice()->getLFCrossSliceBoundaryFlag(), !m_bLFCrossTileBoundary);
    738706      }
    739707      else  // (iDir == EDGE_HOR)
    740708      {
    741         pcCUP = pcCUQ->getPUAbove(uiPartPIdx, uiPartQIdx,!pcCU->getSlice()->getSPS()->getLFCrossSliceBoundaryFlag(), false, false, false, !m_bLFCrossTileBoundary);
     709        pcCUP = pcCUQ->getPUAbove(uiPartPIdx, uiPartQIdx,!pcCU->getSlice()->getLFCrossSliceBoundaryFlag(), false, !m_bLFCrossTileBoundary);
    742710      }
    743711
    744712      iQP_P = pcCUP->getQP(uiPartPIdx);
    745713     
    746       if(pcCU->getIPCMFlag(uiPartQIdx))
    747       {
    748         iQP_Q = 0;
    749       }
    750       if(pcCUP->getIPCMFlag(uiPartPIdx))
    751       {
    752         iQP_P = 0;
     714      if (bPCMFilter || pcCU->getSlice()->getPPS()->getTransquantBypassEnableFlag())
     715      {
     716        // Check if each of PUs is I_PCM with LF disabling
     717        bPartPNoFilter = (bPCMFilter && pcCUP->getIPCMFlag(uiPartPIdx));
     718        bPartQNoFilter = (bPCMFilter && pcCUQ->getIPCMFlag(uiPartQIdx));
     719
     720        // check if each of PUs is lossless coded
     721        bPartPNoFilter = bPartPNoFilter || (pcCUP->isLosslessCoded(uiPartPIdx));
     722        bPartQNoFilter = bPartQNoFilter || (pcCUQ->isLosslessCoded(uiPartQIdx));
    753723      }
    754724     
    755       iQP = QpUV((iQP_P + iQP_Q + 1) >> 1);
    756       Int iBitdepthScale = (1<<(g_uiBitIncrement+g_uiBitDepth-8));
    757      
    758       Int iIndexTC = Clip3(0, MAX_QP+DEFAULT_INTRA_TC_OFFSET, iQP + DEFAULT_INTRA_TC_OFFSET*(ucBs - 1) + (m_tcOffsetDiv2 << 1));
    759       Int iTc =  tctable_8x8[iIndexTC]*iBitdepthScale;
    760      
    761       if(bPCMFilter)
    762       {
    763         // Check if each of PUs is IPCM
    764         bPartPNoFilter = (pcCUP->getIPCMFlag(uiPartPIdx));
    765         bPartQNoFilter = (pcCUQ->getIPCMFlag(uiPartQIdx));
    766       }
    767      
    768 #if LOSSLESS_CODING
    769       // check if each of PUs is lossless coded
    770       bPartPNoFilter = bPartPNoFilter || (pcCU->isLosslessCoded(uiAbsZorderIdx) );
    771       bPartQNoFilter = bPartQNoFilter || (pcCU->isLosslessCoded(uiAbsZorderIdx) );
    772 #endif
    773       for ( UInt uiStep = 0; uiStep < uiPelsInPartChroma; uiStep++ )
    774       {
    775         xPelFilterChroma( piTmpSrcCb + iSrcStep*(uiStep+iIdx*uiPelsInPartChroma), iOffset, iTc , bPartPNoFilter, bPartQNoFilter);
    776         xPelFilterChroma( piTmpSrcCr + iSrcStep*(uiStep+iIdx*uiPelsInPartChroma), iOffset, iTc , bPartPNoFilter, bPartQNoFilter);
     725      for ( UInt chromaIdx = 0; chromaIdx < 2; chromaIdx++ )
     726      {
     727        Int chromaQPOffset  = (chromaIdx == 0) ? pcCU->getSlice()->getPPS()->getChromaCbQpOffset() : pcCU->getSlice()->getPPS()->getChromaCrQpOffset();
     728        Pel* piTmpSrcChroma = (chromaIdx == 0) ? piTmpSrcCb : piTmpSrcCr;
     729
     730        iQP = QpUV( ((iQP_P + iQP_Q + 1) >> 1) + chromaQPOffset );
     731        Int iBitdepthScale = 1 << (g_bitDepthC-8);
     732
     733        Int iIndexTC = Clip3(0, MAX_QP+DEFAULT_INTRA_TC_OFFSET, iQP + DEFAULT_INTRA_TC_OFFSET*(ucBs - 1) + (tcOffsetDiv2 << 1));
     734        Int iTc =  sm_tcTable[iIndexTC]*iBitdepthScale;
     735
     736        for ( UInt uiStep = 0; uiStep < uiPelsInPartChroma; uiStep++ )
     737        {
     738          xPelFilterChroma( piTmpSrcChroma + iSrcStep*(uiStep+iIdx*uiPelsInPartChroma), iOffset, iTc , bPartPNoFilter, bPartQNoFilter);
     739        }
    777740      }
    778741    }
     
    785748 \param piSrc           pointer to picture data
    786749 \param iOffset         offset value for picture data
    787  \param d               d value
    788  \param beta            beta value
    789750 \param tc              tc value
    790751 \param sw              decision strong/weak filter
     
    795756 \param bFilterSecondQ  decision weak filter/no filter for partQ
    796757*/
    797 __inline Void TComLoopFilter::xPelFilterLuma( Pel* piSrc, Int iOffset, Int d, Int beta, Int tc , Bool sw, Bool bPartPNoFilter, Bool bPartQNoFilter, Int iThrCut, Bool bFilterSecondP, Bool bFilterSecondQ)
     758__inline Void TComLoopFilter::xPelFilterLuma( Pel* piSrc, Int iOffset, Int tc , Bool sw, Bool bPartPNoFilter, Bool bPartQNoFilter, Int iThrCut, Bool bFilterSecondP, Bool bFilterSecondQ)
    798759{
    799760  Int delta;
     
    825786    {
    826787      delta = Clip3(-tc, tc, delta);       
    827       piSrc[-iOffset] = Clip((m3+delta));
    828       piSrc[0] = Clip((m4-delta));
     788      piSrc[-iOffset] = ClipY((m3+delta));
     789      piSrc[0] = ClipY((m4-delta));
    829790
    830791      Int tc2 = tc>>1;
     
    832793      {
    833794        Int delta1 = Clip3(-tc2, tc2, (( ((m1+m3+1)>>1)- m2+delta)>>1));
    834         piSrc[-iOffset*2] = Clip((m2+delta1));
     795        piSrc[-iOffset*2] = ClipY((m2+delta1));
    835796      }
    836797      if(bFilterSecondQ)
    837798      {
    838799        Int delta2 = Clip3(-tc2, tc2, (( ((m6+m4+1)>>1)- m5-delta)>>1));
    839         piSrc[ iOffset] = Clip((m5+delta2));
     800        piSrc[ iOffset] = ClipY((m5+delta2));
    840801      }
    841802    }
     
    867828__inline Void TComLoopFilter::xPelFilterChroma( Pel* piSrc, Int iOffset, Int tc, Bool bPartPNoFilter, Bool bPartQNoFilter)
    868829{
    869   int delta;
     830  Int delta;
    870831 
    871832  Pel m4  = piSrc[0];
     
    875836 
    876837  delta = Clip3(-tc,tc, (((( m4 - m3 ) << 2 ) + m2 - m5 + 4 ) >> 3) );
    877   piSrc[-iOffset] = Clip(m3+delta);
    878   piSrc[0] = Clip(m4-delta);
     838  piSrc[-iOffset] = ClipC(m3+delta);
     839  piSrc[0] = ClipC(m4-delta);
    879840
    880841  if(bPartPNoFilter)
Note: See TracChangeset for help on using the changeset viewer.