Ignore:
Timestamp:
13 Aug 2015, 17:38:13 (9 years ago)
Author:
tech
Message:

Merged 14.1-update-dev1@1312.

File:
1 edited

Legend:

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

    r1179 r1313  
    22 * License, included below. This software may be subject to other third party
    33 * and contributor rights, including patent rights, and no such rights are
    4  * granted under this license. 
     4 * granted under this license.
    55 *
    6 * Copyright (c) 2010-2015, ITU/ISO/IEC
     6 * Copyright (c) 2010-2015, ITU/ISO/IEC
    77 * All rights reserved.
    88 *
     
    3939#include "TComSlice.h"
    4040#include "TComMv.h"
     41#include "TComTU.h"
    4142
    4243//! \ingroup TLibCommon
     
    4748// ====================================================================================================================
    4849
    49 #define   EDGE_VER    0
    50 #define   EDGE_HOR    1
    51 #define   QpUV(iQpY)  ( ((iQpY) < 0) ? (iQpY) : (((iQpY) > 57) ? ((iQpY)-6) : g_aucChromaScale[(iQpY)]) )
     50//#define   EDGE_VER    0
     51//#define   EDGE_HOR    1
    5252
    5353#define DEFAULT_INTRA_TC_OFFSET 2 ///< Default intra TC offset
     
    5757// ====================================================================================================================
    5858
    59 const UChar TComLoopFilter::sm_tcTable[54] =
     59const UChar TComLoopFilter::sm_tcTable[MAX_QP + 1 + DEFAULT_INTRA_TC_OFFSET] =
    6060{
    6161  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 TComLoopFilter::sm_betaTable[52] =
     64const UChar TComLoopFilter::sm_betaTable[MAX_QP + 1] =
    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
     
    7575, m_bLFCrossTileBoundary(true)
    7676{
    77   for( UInt uiDir = 0; uiDir < 2; uiDir++ )
    78   {
    79     m_aapucBS       [uiDir] = NULL;
    80     m_aapbEdgeFilter[uiDir] = NULL;
     77  for( Int edgeDir = 0; edgeDir < NUM_EDGE_DIR; edgeDir++ )
     78  {
     79    m_aapucBS       [edgeDir] = NULL;
     80    m_aapbEdgeFilter[edgeDir] = NULL;
    8181  }
    8282}
     
    9898  destroy();
    9999  m_uiNumPartitions = 1 << ( uiMaxCUDepth<<1 );
    100   for( UInt uiDir = 0; uiDir < 2; uiDir++ )
    101   {
    102     m_aapucBS       [uiDir] = new UChar[m_uiNumPartitions];
    103     m_aapbEdgeFilter[uiDir] = new Bool [m_uiNumPartitions];
     100  for( Int edgeDir = 0; edgeDir < NUM_EDGE_DIR; edgeDir++ )
     101  {
     102    m_aapucBS       [edgeDir] = new UChar[m_uiNumPartitions];
     103    m_aapbEdgeFilter[edgeDir] = new Bool [m_uiNumPartitions];
    104104  }
    105105}
     
    107107Void TComLoopFilter::destroy()
    108108{
    109   for( UInt uiDir = 0; uiDir < 2; uiDir++ )
    110   {
    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;
     109  for( Int edgeDir = 0; edgeDir < NUM_EDGE_DIR; edgeDir++ )
     110  {
     111    if (m_aapucBS[edgeDir] != NULL)
     112    {
     113      delete [] m_aapucBS[edgeDir];
     114      m_aapucBS[edgeDir] = NULL;
     115    }
     116
     117    if (m_aapbEdgeFilter[edgeDir])
     118    {
     119      delete [] m_aapbEdgeFilter[edgeDir];
     120      m_aapbEdgeFilter[edgeDir] = NULL;
    120121    }
    121122  }
     
    130131{
    131132  // Horizontal filtering
    132   for ( UInt uiCUAddr = 0; uiCUAddr < pcPic->getNumCUsInFrame(); uiCUAddr++ )
    133   {
    134     TComDataCU* pcCU = pcPic->getCU( uiCUAddr );
     133  for ( UInt ctuRsAddr = 0; ctuRsAddr < pcPic->getNumberOfCtusInFrame(); ctuRsAddr++ )
     134  {
     135    TComDataCU* pCtu = pcPic->getCtu( ctuRsAddr );
    135136
    136137    ::memset( m_aapucBS       [EDGE_VER], 0, sizeof( UChar ) * m_uiNumPartitions );
     
    138139
    139140    // CU-based deblocking
    140     xDeblockCU( pcCU, 0, 0, EDGE_VER );
     141    xDeblockCU( pCtu, 0, 0, EDGE_VER );
    141142  }
    142143
    143144  // Vertical filtering
    144   for ( UInt uiCUAddr = 0; uiCUAddr < pcPic->getNumCUsInFrame(); uiCUAddr++ )
    145   {
    146     TComDataCU* pcCU = pcPic->getCU( uiCUAddr );
     145  for ( UInt ctuRsAddr = 0; ctuRsAddr < pcPic->getNumberOfCtusInFrame(); ctuRsAddr++ )
     146  {
     147    TComDataCU* pCtu = pcPic->getCtu( ctuRsAddr );
    147148
    148149    ::memset( m_aapucBS       [EDGE_HOR], 0, sizeof( UChar ) * m_uiNumPartitions );
     
    150151
    151152    // CU-based deblocking
    152     xDeblockCU( pcCU, 0, 0, EDGE_HOR );
     153    xDeblockCU( pCtu, 0, 0, EDGE_HOR );
    153154  }
    154155}
     
    160161
    161162/**
    162  - Deblocking filter process in CU-based (the same function as conventional's)
    163  .
    164  \param Edge          the direction of the edge in block boundary (horizonta/vertical), which is added newly
     163 Deblocking filter process in CU-based (the same function as conventional's)
     164
     165 \param pcCU             Pointer to CTU/CU structure
     166 \param uiAbsZorderIdx   Position in CU
     167 \param uiDepth          Depth in CU
     168 \param edgeDir          the direction of the edge in block boundary (horizontal/vertical), which is added newly
    165169*/
    166 Void TComLoopFilter::xDeblockCU( TComDataCU* pcCU, UInt uiAbsZorderIdx, UInt uiDepth, Int Edge )
    167 {
    168   if(pcCU->getPic()==0||pcCU->getPartitionSize(uiAbsZorderIdx)==SIZE_NONE)
     170Void TComLoopFilter::xDeblockCU( TComDataCU* pcCU, UInt uiAbsZorderIdx, UInt uiDepth, DeblockEdgeDir edgeDir )
     171{
     172  if(pcCU->getPic()==0||pcCU->getPartitionSize(uiAbsZorderIdx)==NUMBER_OF_PART_SIZES)
    169173  {
    170174    return;
    171175  }
    172176  TComPic* pcPic     = pcCU->getPic();
    173   UInt uiCurNumParts = pcPic->getNumPartInCU() >> (uiDepth<<1);
     177  UInt uiCurNumParts = pcPic->getNumPartitionsInCtu() >> (uiDepth<<1);
    174178  UInt uiQNumParts   = uiCurNumParts>>2;
    175  
     179  const TComSPS &sps = *(pcCU->getSlice()->getSPS());
     180
    176181  if( pcCU->getDepth(uiAbsZorderIdx) > uiDepth )
    177182  {
     
    180185      UInt uiLPelX   = pcCU->getCUPelX() + g_auiRasterToPelX[ g_auiZscanToRaster[uiAbsZorderIdx] ];
    181186      UInt uiTPelY   = pcCU->getCUPelY() + g_auiRasterToPelY[ g_auiZscanToRaster[uiAbsZorderIdx] ];
    182       if( ( uiLPelX < pcCU->getSlice()->getSPS()->getPicWidthInLumaSamples() ) && ( uiTPelY < pcCU->getSlice()->getSPS()->getPicHeightInLumaSamples() ) )
    183       {
    184         xDeblockCU( pcCU, uiAbsZorderIdx, uiDepth+1, Edge );
     187      if( ( uiLPelX < sps.getPicWidthInLumaSamples() ) && ( uiTPelY < sps.getPicHeightInLumaSamples() ) )
     188      {
     189        xDeblockCU( pcCU, uiAbsZorderIdx, uiDepth+1, edgeDir );
    185190      }
    186191    }
    187192    return;
    188193  }
    189  
     194
    190195  xSetLoopfilterParam( pcCU, uiAbsZorderIdx );
    191  
    192   xSetEdgefilterTU   ( pcCU, uiAbsZorderIdx , uiAbsZorderIdx, uiDepth );
     196  TComTURecurse tuRecurse(pcCU, uiAbsZorderIdx);
     197  xSetEdgefilterTU   ( tuRecurse );
    193198  xSetEdgefilterPU   ( pcCU, uiAbsZorderIdx );
    194  
    195   Int iDir = Edge;
     199
     200  const UInt uiPelsInPart = sps.getMaxCUWidth() >> sps.getMaxTotalCUDepth();
     201
    196202  for( UInt uiPartIdx = uiAbsZorderIdx; uiPartIdx < uiAbsZorderIdx + uiCurNumParts; uiPartIdx++ )
    197203  {
    198204    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);
     205    if( uiPelsInPart == 4 )
     206    {
     207      uiBSCheck = (edgeDir == EDGE_VER && uiPartIdx%2 == 0) || (edgeDir == EDGE_HOR && (uiPartIdx-((uiPartIdx>>2)<<2))/2 == 0);
    202208    }
    203209    else
     
    205211      uiBSCheck = 1;
    206212    }
    207    
    208     if ( m_aapbEdgeFilter[iDir][uiPartIdx] && uiBSCheck )
    209     {
    210       xGetBoundaryStrengthSingle ( pcCU, iDir, uiPartIdx );
    211     }
    212   }
    213  
    214   UInt uiPelsInPart = g_uiMaxCUWidth >> g_uiMaxCUDepth;
     213
     214    if ( m_aapbEdgeFilter[edgeDir][uiPartIdx] && uiBSCheck )
     215    {
     216      xGetBoundaryStrengthSingle ( pcCU, edgeDir, uiPartIdx );
     217    }
     218  }
     219
    215220  UInt PartIdxIncr = DEBLOCK_SMALLEST_BLOCK / uiPelsInPart ? DEBLOCK_SMALLEST_BLOCK / uiPelsInPart : 1 ;
    216  
    217   UInt uiSizeInPU = pcPic->getNumPartInWidth()>>(uiDepth);
    218  
    219   for ( UInt iEdge = 0; iEdge < uiSizeInPU ; iEdge+=PartIdxIncr)
    220   {
    221     xEdgeFilterLuma     ( pcCU, uiAbsZorderIdx, uiDepth, iDir, iEdge );
    222     if ( (uiPelsInPart>DEBLOCK_SMALLEST_BLOCK) || (iEdge % ( (DEBLOCK_SMALLEST_BLOCK<<1)/uiPelsInPart ) ) == 0 )
    223     {
    224       xEdgeFilterChroma   ( pcCU, uiAbsZorderIdx, uiDepth, iDir, iEdge );
    225     }
    226   }
    227 }
    228 
    229 Void TComLoopFilter::xSetEdgefilterMultiple( TComDataCU* pcCU, UInt uiScanIdx, UInt uiDepth, Int iDir, Int iEdgeIdx, Bool bValue,UInt uiWidthInBaseUnits, UInt uiHeightInBaseUnits )
    230 
     221
     222  UInt uiSizeInPU = pcPic->getNumPartInCtuWidth()>>(uiDepth);
     223  const ChromaFormat chFmt=pcPic->getChromaFormat();
     224  const UInt shiftFactor  = edgeDir == EDGE_VER ? pcPic->getComponentScaleX(COMPONENT_Cb) : pcPic->getComponentScaleY(COMPONENT_Cb);
     225  const Bool bAlwaysDoChroma=chFmt==CHROMA_444;
     226
     227  for ( Int iEdge = 0; iEdge < uiSizeInPU ; iEdge+=PartIdxIncr)
     228  {
     229    xEdgeFilterLuma     ( pcCU, uiAbsZorderIdx, uiDepth, edgeDir, iEdge );
     230    if ( chFmt!=CHROMA_400 && (bAlwaysDoChroma ||
     231                               (uiPelsInPart>DEBLOCK_SMALLEST_BLOCK) ||
     232                               (iEdge % ( (DEBLOCK_SMALLEST_BLOCK<<shiftFactor)/uiPelsInPart ) ) == 0
     233                              )
     234       )
     235    {
     236      xEdgeFilterChroma   ( pcCU, uiAbsZorderIdx, uiDepth, edgeDir, iEdge );
     237    }
     238  }
     239}
     240
     241Void TComLoopFilter::xSetEdgefilterMultiple( TComDataCU*    pcCU,
     242                                             UInt           uiAbsZorderIdx,
     243                                             UInt           uiDepth,
     244                                             DeblockEdgeDir edgeDir,
     245                                             Int            iEdgeIdx,
     246                                             Bool           bValue,
     247                                             UInt           uiWidthInBaseUnits,
     248                                             UInt           uiHeightInBaseUnits,
     249                                             const TComRectangle *rect)
     250{
    231251  if ( uiWidthInBaseUnits == 0 )
    232252  {
    233     uiWidthInBaseUnits  = pcCU->getPic()->getNumPartInWidth () >> uiDepth;
     253    uiWidthInBaseUnits  = pcCU->getPic()->getNumPartInCtuWidth () >> uiDepth;
    234254  }
    235255  if ( uiHeightInBaseUnits == 0 )
    236256  {
    237     uiHeightInBaseUnits = pcCU->getPic()->getNumPartInHeight() >> uiDepth;
    238   }
    239   const UInt uiNumElem = iDir == 0 ? uiHeightInBaseUnits : uiWidthInBaseUnits;
     257    uiHeightInBaseUnits = pcCU->getPic()->getNumPartInCtuHeight() >> uiDepth;
     258  }
     259  const UInt uiNumElem = edgeDir == EDGE_VER ? uiHeightInBaseUnits : uiWidthInBaseUnits;
    240260  assert( uiNumElem > 0 );
    241261  assert( uiWidthInBaseUnits > 0 );
     
    243263  for( UInt ui = 0; ui < uiNumElem; ui++ )
    244264  {
    245     const UInt uiBsIdx = xCalcBsIdx( pcCU, uiScanIdx, iDir, iEdgeIdx, ui );
    246     m_aapbEdgeFilter[iDir][uiBsIdx] = bValue;
     265    const UInt uiBsIdx = xCalcBsIdx( pcCU, uiAbsZorderIdx, edgeDir, iEdgeIdx, ui, rect );
     266    m_aapbEdgeFilter[edgeDir][uiBsIdx] = bValue;
    247267    if (iEdgeIdx == 0)
    248268    {
    249       m_aapucBS[iDir][uiBsIdx] = bValue;
    250     }
    251   }
    252 }
    253 
    254 Void TComLoopFilter::xSetEdgefilterTU( TComDataCU* pcCU, UInt absTUPartIdx, UInt uiAbsZorderIdx, UInt uiDepth )
    255 {
    256   if( pcCU->getTransformIdx( uiAbsZorderIdx ) + pcCU->getDepth( uiAbsZorderIdx) > uiDepth )
    257   {
    258     const UInt uiCurNumParts = pcCU->getPic()->getNumPartInCU() >> (uiDepth<<1);
    259     const UInt uiQNumParts   = uiCurNumParts>>2;
    260     for ( UInt uiPartIdx = 0; uiPartIdx < 4; uiPartIdx++, uiAbsZorderIdx+=uiQNumParts )
    261     {
    262       UInt nsAddr = uiAbsZorderIdx;
    263       xSetEdgefilterTU( pcCU,nsAddr, uiAbsZorderIdx, uiDepth + 1 );
    264     }
     269      m_aapucBS[edgeDir][uiBsIdx] = bValue;
     270    }
     271  }
     272}
     273
     274Void TComLoopFilter::xSetEdgefilterTU(  TComTU &rTu )
     275{
     276  TComDataCU* pcCU  = rTu.getCU();
     277  UInt uiTransDepthTotal = rTu.GetTransformDepthTotal();
     278
     279  if( pcCU->getTransformIdx( rTu.GetAbsPartIdxTU() ) + pcCU->getDepth( rTu.GetAbsPartIdxTU()) > uiTransDepthTotal )
     280  {
     281    TComTURecurse tuChild(rTu, false);
     282    do
     283    {
     284      xSetEdgefilterTU( tuChild );
     285    } while (tuChild.nextSection(rTu));
    265286    return;
    266287  }
    267288
    268   Int trWidth  = pcCU->getWidth( uiAbsZorderIdx ) >> pcCU->getTransformIdx( uiAbsZorderIdx );
    269   Int trHeight = pcCU->getHeight( uiAbsZorderIdx ) >> pcCU->getTransformIdx( uiAbsZorderIdx );
    270  
    271   UInt uiWidthInBaseUnits  = trWidth / (g_uiMaxCUWidth >> g_uiMaxCUDepth);
    272   UInt uiHeightInBaseUnits = trHeight / (g_uiMaxCUWidth >> g_uiMaxCUDepth);
    273 
    274   xSetEdgefilterMultiple( pcCU, absTUPartIdx, uiDepth, EDGE_VER, 0, m_stLFCUParam.bInternalEdge, uiWidthInBaseUnits, uiHeightInBaseUnits );
    275   xSetEdgefilterMultiple( pcCU, absTUPartIdx, uiDepth, EDGE_HOR, 0, m_stLFCUParam.bInternalEdge, uiWidthInBaseUnits, uiHeightInBaseUnits );
     289  const TComRectangle &rect = rTu.getRect(COMPONENT_Y);
     290  const TComSPS &sps=*(pcCU->getSlice()->getSPS());
     291
     292  const UInt uiWidthInBaseUnits  = rect.width  / (sps.getMaxCUWidth()  >> sps.getMaxTotalCUDepth());
     293  const UInt uiHeightInBaseUnits = rect.height / (sps.getMaxCUHeight() >> sps.getMaxTotalCUDepth());
     294
     295  xSetEdgefilterMultiple( pcCU, rTu.GetAbsPartIdxCU(), uiTransDepthTotal, EDGE_VER, 0, m_stLFCUParam.bInternalEdge, uiWidthInBaseUnits, uiHeightInBaseUnits, &rect );
     296  xSetEdgefilterMultiple( pcCU, rTu.GetAbsPartIdxCU(), uiTransDepthTotal, EDGE_HOR, 0, m_stLFCUParam.bInternalEdge, uiWidthInBaseUnits, uiHeightInBaseUnits, &rect );
    276297}
    277298
     
    279300{
    280301  const UInt uiDepth = pcCU->getDepth( uiAbsZorderIdx );
    281   const UInt uiWidthInBaseUnits  = pcCU->getPic()->getNumPartInWidth () >> uiDepth;
    282   const UInt uiHeightInBaseUnits = pcCU->getPic()->getNumPartInHeight() >> uiDepth;
     302  const UInt uiWidthInBaseUnits  = pcCU->getPic()->getNumPartInCtuWidth () >> uiDepth;
     303  const UInt uiHeightInBaseUnits = pcCU->getPic()->getNumPartInCtuHeight() >> uiDepth;
    283304  const UInt uiHWidthInBaseUnits  = uiWidthInBaseUnits  >> 1;
    284305  const UInt uiHHeightInBaseUnits = uiHeightInBaseUnits >> 1;
    285306  const UInt uiQWidthInBaseUnits  = uiWidthInBaseUnits  >> 2;
    286307  const UInt uiQHeightInBaseUnits = uiHeightInBaseUnits >> 2;
    287  
     308
    288309  xSetEdgefilterMultiple( pcCU, uiAbsZorderIdx, uiDepth, EDGE_VER, 0, m_stLFCUParam.bLeftEdge );
    289310  xSetEdgefilterMultiple( pcCU, uiAbsZorderIdx, uiDepth, EDGE_HOR, 0, m_stLFCUParam.bTopEdge );
    290  
     311
    291312  switch ( pcCU->getPartitionSize( uiAbsZorderIdx ) )
    292313  {
     
    343364  UInt uiX           = pcCU->getCUPelX() + g_auiRasterToPelX[ g_auiZscanToRaster[ uiAbsZorderIdx ] ];
    344365  UInt uiY           = pcCU->getCUPelY() + g_auiRasterToPelY[ g_auiZscanToRaster[ uiAbsZorderIdx ] ];
    345  
     366
    346367  TComDataCU* pcTempCU;
    347368  UInt        uiTempPartIdx;
    348369
    349370  m_stLFCUParam.bInternalEdge = ! pcCU->getSlice()->getDeblockingFilterDisable();
    350  
     371
    351372  if ( (uiX == 0) || pcCU->getSlice()->getDeblockingFilterDisable() )
    352373  {
     
    360381  {
    361382    pcTempCU = pcCU->getPULeft( uiTempPartIdx, uiAbsZorderIdx, !pcCU->getSlice()->getLFCrossSliceBoundaryFlag(), !m_bLFCrossTileBoundary);
    362     if ( pcTempCU )
     383
     384    if ( pcTempCU != NULL )
    363385    {
    364386      m_stLFCUParam.bLeftEdge = true;
     
    369391    }
    370392  }
    371  
     393
    372394  if ( (uiY == 0 ) || pcCU->getSlice()->getDeblockingFilterDisable() )
    373395  {
     
    382404    pcTempCU = pcCU->getPUAbove( uiTempPartIdx, uiAbsZorderIdx, !pcCU->getSlice()->getLFCrossSliceBoundaryFlag(), false, !m_bLFCrossTileBoundary);
    383405
    384     if ( pcTempCU )
     406    if ( pcTempCU != NULL )
    385407    {
    386408      m_stLFCUParam.bTopEdge = true;
     
    393415}
    394416
    395 Void TComLoopFilter::xGetBoundaryStrengthSingle ( TComDataCU* pcCU, Int iDir, UInt uiAbsPartIdx )
    396 {
    397   TComSlice* const pcSlice = pcCU->getSlice();
    398  
    399   const UInt uiPartQ = uiAbsPartIdx;
    400   TComDataCU* const pcCUQ = pcCU;
    401  
     417Void TComLoopFilter::xGetBoundaryStrengthSingle ( TComDataCU* pCtu, DeblockEdgeDir edgeDir, UInt uiAbsPartIdx4x4BlockWithinCtu )
     418{
     419  TComSlice * const pcSlice = pCtu->getSlice();
     420
     421  const Bool lfCrossSliceBoundaryFlag=pCtu->getSlice()->getLFCrossSliceBoundaryFlag();
     422
     423  const UInt uiPartQ = uiAbsPartIdx4x4BlockWithinCtu;
     424  TComDataCU* const pcCUQ = pCtu;
     425
    402426  UInt uiPartP;
    403427  TComDataCU* pcCUP;
    404428  UInt uiBs = 0;
    405  
     429
    406430  //-- Calculate Block Index
    407   if (iDir == EDGE_VER)
    408   {
    409     pcCUP = pcCUQ->getPULeft(uiPartP, uiPartQ, !pcCU->getSlice()->getLFCrossSliceBoundaryFlag(), !m_bLFCrossTileBoundary);
    410   }
    411   else  // (iDir == EDGE_HOR)
    412   {
    413     pcCUP = pcCUQ->getPUAbove(uiPartP, uiPartQ, !pcCU->getSlice()->getLFCrossSliceBoundaryFlag(), false, !m_bLFCrossTileBoundary);
    414   }
    415  
     431  if (edgeDir == EDGE_VER)
     432  {
     433    pcCUP = pcCUQ->getPULeft(uiPartP, uiPartQ, !lfCrossSliceBoundaryFlag, !m_bLFCrossTileBoundary);
     434  }
     435  else  // (edgeDir == EDGE_HOR)
     436  {
     437    pcCUP = pcCUQ->getPUAbove(uiPartP, uiPartQ, !pCtu->getSlice()->getLFCrossSliceBoundaryFlag(), false, !m_bLFCrossTileBoundary);
     438  }
     439
    416440  //-- Set BS for Intra MB : BS = 4 or 3
    417441  if ( pcCUP->isIntra(uiPartP) || pcCUQ->isIntra(uiPartQ) )
     
    419443    uiBs = 2;
    420444  }
    421  
     445
    422446  //-- Set BS for not Intra MB : BS = 2 or 1 or 0
    423447  if ( !pcCUP->isIntra(uiPartP) && !pcCUQ->isIntra(uiPartQ) )
     
    425449    UInt nsPartQ = uiPartQ;
    426450    UInt nsPartP = uiPartP;
    427    
    428     if ( m_aapucBS[iDir][uiAbsPartIdx] && (pcCUQ->getCbf( nsPartQ, TEXT_LUMA, pcCUQ->getTransformIdx(nsPartQ)) != 0 || pcCUP->getCbf( nsPartP, TEXT_LUMA, pcCUP->getTransformIdx(nsPartP) ) != 0) )
     451
     452    if ( m_aapucBS[edgeDir][uiAbsPartIdx4x4BlockWithinCtu] && (pcCUQ->getCbf( nsPartQ, COMPONENT_Y, pcCUQ->getTransformIdx(nsPartQ)) != 0 || pcCUP->getCbf( nsPartP, COMPONENT_Y, pcCUP->getTransformIdx(nsPartP) ) != 0) )
    429453    {
    430454      uiBs = 1;
     
    432456    else
    433457    {
    434       if (iDir == EDGE_HOR)
    435       {
    436         pcCUP = pcCUQ->getPUAbove(uiPartP, uiPartQ, !pcCU->getSlice()->getLFCrossSliceBoundaryFlag(), false, !m_bLFCrossTileBoundary);
    437       }
    438458      if (pcSlice->isInterB() || pcCUP->getSlice()->isInterB())
    439459      {
     
    448468        iRefIdx = pcCUQ->getCUMvField(REF_PIC_LIST_1)->getRefIdx(uiPartQ);
    449469        piRefQ1 = (iRefIdx < 0) ? NULL : pcSlice->getRefPic(REF_PIC_LIST_1, iRefIdx);
    450        
     470
    451471        TComMv pcMvP0 = pcCUP->getCUMvField(REF_PIC_LIST_0)->getMv(uiPartP);
    452472        TComMv pcMvP1 = pcCUP->getCUMvField(REF_PIC_LIST_1)->getMv(uiPartP);
     
    454474        TComMv pcMvQ1 = pcCUQ->getCUMvField(REF_PIC_LIST_1)->getMv(uiPartQ);
    455475
    456         if (piRefP0 == NULL) pcMvP0.setZero();
    457         if (piRefP1 == NULL) pcMvP1.setZero();
    458         if (piRefQ0 == NULL) pcMvQ0.setZero();
    459         if (piRefQ1 == NULL) pcMvQ1.setZero();
     476        if (piRefP0 == NULL)
     477        {
     478          pcMvP0.setZero();
     479        }
     480        if (piRefP1 == NULL)
     481        {
     482          pcMvP1.setZero();
     483        }
     484        if (piRefQ0 == NULL)
     485        {
     486          pcMvQ0.setZero();
     487        }
     488        if (piRefQ1 == NULL)
     489        {
     490          pcMvQ1.setZero();
     491        }
    460492
    461493        if ( ((piRefP0==piRefQ0)&&(piRefP1==piRefQ1)) || ((piRefP0==piRefQ1)&&(piRefP1==piRefQ0)) )
     
    506538        TComMv pcMvQ0 = pcCUQ->getCUMvField(REF_PIC_LIST_0)->getMv(uiPartQ);
    507539
    508         if (piRefP0 == NULL) pcMvP0.setZero();
    509         if (piRefQ0 == NULL) pcMvQ0.setZero();
    510        
     540        if (piRefP0 == NULL)
     541        {
     542          pcMvP0.setZero();
     543        }
     544        if (piRefQ0 == NULL)
     545        {
     546          pcMvQ0.setZero();
     547        }
     548
    511549        uiBs  = ((piRefP0 != piRefQ0) ||
    512550                 (abs(pcMvQ0.getHor() - pcMvP0.getHor()) >= 4) ||
     
    515553    }   // enf of "if( one of BCBP == 0 )"
    516554  }   // enf of "if( not Intra )"
    517  
    518   m_aapucBS[iDir][uiAbsPartIdx] = uiBs;
    519 }
    520 
    521 
    522 Void TComLoopFilter::xEdgeFilterLuma( TComDataCU* pcCU, UInt uiAbsZorderIdx, UInt uiDepth, Int iDir, Int iEdge  )
    523 {
    524   TComPicYuv* pcPicYuvRec = pcCU->getPic()->getPicYuvRec();
    525   Pel* piSrc    = pcPicYuvRec->getLumaAddr( pcCU->getAddr(), uiAbsZorderIdx );
    526   Pel* piTmpSrc = piSrc;
    527  
    528   Int  iStride = pcPicYuvRec->getStride();
     555
     556  m_aapucBS[edgeDir][uiAbsPartIdx4x4BlockWithinCtu] = uiBs;
     557}
     558
     559
     560Void TComLoopFilter::xEdgeFilterLuma( TComDataCU* const pcCU, const UInt uiAbsZorderIdx, const UInt uiDepth, const DeblockEdgeDir edgeDir, const Int iEdge  )
     561{
     562        TComPicYuv *pcPicYuvRec                   = pcCU->getPic()->getPicYuvRec();
     563        Pel        *piSrc                         = pcPicYuvRec->getAddr(COMPONENT_Y, pcCU->getCtuRsAddr(), uiAbsZorderIdx );
     564        Pel        *piTmpSrc                      = piSrc;
     565  const TComSPS    &sps                           = *(pcCU->getSlice()->getSPS());
     566  const Bool        ppsTransquantBypassEnableFlag = pcCU->getSlice()->getPPS()->getTransquantBypassEnableFlag();
     567  const Int         bitDepthLuma                  = sps.getBitDepth(CHANNEL_TYPE_LUMA);
     568  const Bool        lfCrossSliceBoundaryFlag      = pcCU->getSlice()->getLFCrossSliceBoundaryFlag();
     569
     570  Int  iStride = pcPicYuvRec->getStride(COMPONENT_Y);
    529571  Int iQP = 0;
    530572  Int iQP_P = 0;
    531573  Int iQP_Q = 0;
    532   UInt uiNumParts = pcCU->getPic()->getNumPartInWidth()>>uiDepth;
    533  
    534   UInt  uiPelsInPart = g_uiMaxCUWidth >> g_uiMaxCUDepth;
     574  UInt uiNumParts = pcCU->getPic()->getNumPartInCtuWidth()>>uiDepth;
     575
     576  UInt  uiPelsInPart = sps.getMaxCUWidth() >> sps.getMaxTotalCUDepth();
    535577  UInt  uiBsAbsIdx = 0, uiBs = 0;
    536578  Int   iOffset, iSrcStep;
    537  
    538   Bool  bPCMFilter = (pcCU->getSlice()->getSPS()->getUsePCM() && pcCU->getSlice()->getSPS()->getPCMFilterDisableFlag())? true : false;
     579
     580  Bool  bPCMFilter = (sps.getUsePCM() && sps.getPCMFilterDisableFlag())? true : false;
    539581  Bool  bPartPNoFilter = false;
    540   Bool  bPartQNoFilter = false; 
     582  Bool  bPartQNoFilter = false;
    541583  UInt  uiPartPIdx = 0;
    542584  UInt  uiPartQIdx = 0;
    543   TComDataCU* pcCUP = pcCU; 
     585  TComDataCU* pcCUP = pcCU;
    544586  TComDataCU* pcCUQ = pcCU;
    545587  Int  betaOffsetDiv2 = pcCUQ->getSlice()->getDeblockingFilterBetaOffsetDiv2();
    546588  Int  tcOffsetDiv2 = pcCUQ->getSlice()->getDeblockingFilterTcOffsetDiv2();
    547589
    548   if (iDir == EDGE_VER)
     590  if (edgeDir == EDGE_VER)
    549591  {
    550592    iOffset = 1;
     
    552594    piTmpSrc += iEdge*uiPelsInPart;
    553595  }
    554   else  // (iDir == EDGE_HOR)
     596  else  // (edgeDir == EDGE_HOR)
    555597  {
    556598    iOffset = iStride;
     
    558600    piTmpSrc += iEdge*uiPelsInPart*iStride;
    559601  }
    560  
     602
     603  const Int iBitdepthScale = 1 << (bitDepthLuma-8);
     604
    561605  for ( UInt iIdx = 0; iIdx < uiNumParts; iIdx++ )
    562606  {
    563     uiBsAbsIdx = xCalcBsIdx( pcCU, uiAbsZorderIdx, iDir, iEdge, iIdx);
    564     uiBs = m_aapucBS[iDir][uiBsAbsIdx];
     607    uiBsAbsIdx = xCalcBsIdx( pcCU, uiAbsZorderIdx, edgeDir, iEdge, iIdx);
     608    uiBs = m_aapucBS[edgeDir][uiBsAbsIdx];
    565609    if ( uiBs )
    566610    {
     
    568612      uiPartQIdx = uiBsAbsIdx;
    569613      // Derive neighboring PU index
    570       if (iDir == EDGE_VER)
    571       {
    572         pcCUP = pcCUQ->getPULeft (uiPartPIdx, uiPartQIdx,!pcCU->getSlice()->getLFCrossSliceBoundaryFlag(), !m_bLFCrossTileBoundary);
     614      if (edgeDir == EDGE_VER)
     615      {
     616        pcCUP = pcCUQ->getPULeft (uiPartPIdx, uiPartQIdx,!lfCrossSliceBoundaryFlag, !m_bLFCrossTileBoundary);
    573617      }
    574618      else  // (iDir == EDGE_HOR)
    575619      {
    576         pcCUP = pcCUQ->getPUAbove(uiPartPIdx, uiPartQIdx,!pcCU->getSlice()->getLFCrossSliceBoundaryFlag(), false, !m_bLFCrossTileBoundary);
     620        pcCUP = pcCUQ->getPUAbove(uiPartPIdx, uiPartQIdx,!lfCrossSliceBoundaryFlag, false, !m_bLFCrossTileBoundary);
    577621      }
    578622
    579623      iQP_P = pcCUP->getQP(uiPartPIdx);
    580624      iQP = (iQP_P + iQP_Q + 1) >> 1;
    581       Int iBitdepthScale = 1 << (g_bitDepthY-8);
    582      
     625
    583626      Int iIndexTC = Clip3(0, MAX_QP+DEFAULT_INTRA_TC_OFFSET, Int(iQP + DEFAULT_INTRA_TC_OFFSET*(uiBs-1) + (tcOffsetDiv2 << 1)));
    584627      Int iIndexB = Clip3(0, MAX_QP, iQP + (betaOffsetDiv2 << 1));
    585      
     628
    586629      Int iTc =  sm_tcTable[iIndexTC]*iBitdepthScale;
    587630      Int iBeta = sm_betaTable[iIndexB]*iBitdepthScale;
    588631      Int iSideThreshold = (iBeta+(iBeta>>1))>>3;
    589632      Int iThrCut = iTc*10;
     633
    590634
    591635      UInt  uiBlocksInPart = uiPelsInPart / 4 ? uiPelsInPart / 4 : 1;
     
    598642        Int d0 = dp0 + dq0;
    599643        Int d3 = dp3 + dq3;
    600        
     644
    601645        Int dp = dp0 + dp3;
    602646        Int dq = dq0 + dq3;
    603647        Int d =  d0 + d3;
    604        
    605         if (bPCMFilter || pcCU->getSlice()->getPPS()->getTransquantBypassEnableFlag())
     648
     649        if (bPCMFilter || ppsTransquantBypassEnableFlag)
    606650        {
    607651          // Check if each of PUs is I_PCM with LF disabling
     
    615659
    616660        if (d < iBeta)
    617         { 
     661        {
    618662          Bool bFilterP = (dp < iSideThreshold);
    619663          Bool bFilterQ = (dq < iSideThreshold);
    620          
     664
    621665          Bool sw =  xUseStrongFiltering( iOffset, 2*d0, iBeta, iTc, piTmpSrc+iSrcStep*(iIdx*uiPelsInPart+iBlkIdx*4+0))
    622666          && xUseStrongFiltering( iOffset, 2*d3, iBeta, iTc, piTmpSrc+iSrcStep*(iIdx*uiPelsInPart+iBlkIdx*4+3));
    623          
     667
    624668          for ( Int i = 0; i < DEBLOCK_SMALLEST_BLOCK/2; i++)
    625669          {
    626             xPelFilterLuma( piTmpSrc+iSrcStep*(iIdx*uiPelsInPart+iBlkIdx*4+i), iOffset, iTc, sw, bPartPNoFilter, bPartQNoFilter, iThrCut, bFilterP, bFilterQ);
     670            xPelFilterLuma( piTmpSrc+iSrcStep*(iIdx*uiPelsInPart+iBlkIdx*4+i), iOffset, iTc, sw, bPartPNoFilter, bPartQNoFilter, iThrCut, bFilterP, bFilterQ, bitDepthLuma);
    627671          }
    628672        }
     
    633677
    634678
    635 Void TComLoopFilter::xEdgeFilterChroma( TComDataCU* pcCU, UInt uiAbsZorderIdx, UInt uiDepth, Int iDir, Int iEdge )
    636 {
    637   TComPicYuv* pcPicYuvRec = pcCU->getPic()->getPicYuvRec();
    638   Int         iStride     = pcPicYuvRec->getCStride();
    639   Pel*        piSrcCb     = pcPicYuvRec->getCbAddr( pcCU->getAddr(), uiAbsZorderIdx );
    640   Pel*        piSrcCr     = pcPicYuvRec->getCrAddr( pcCU->getAddr(), uiAbsZorderIdx );
     679Void TComLoopFilter::xEdgeFilterChroma( TComDataCU* const pcCU, const UInt uiAbsZorderIdx, const UInt uiDepth, const DeblockEdgeDir edgeDir, const Int iEdge )
     680{
     681        TComPicYuv *pcPicYuvRec    = pcCU->getPic()->getPicYuvRec();
     682        Int         iStride        = pcPicYuvRec->getStride(COMPONENT_Cb);
     683        Pel        *piSrcCb        = pcPicYuvRec->getAddr( COMPONENT_Cb, pcCU->getCtuRsAddr(), uiAbsZorderIdx );
     684        Pel        *piSrcCr        = pcPicYuvRec->getAddr( COMPONENT_Cr, pcCU->getCtuRsAddr(), uiAbsZorderIdx );
     685  const TComSPS    &sps            = *(pcCU->getSlice()->getSPS());
     686  const Int         bitDepthChroma = sps.getBitDepth(CHANNEL_TYPE_CHROMA);
     687
     688  const UInt  uiPelsInPartChromaH = sps.getMaxCUWidth() >> (sps.getMaxTotalCUDepth()+pcPicYuvRec->getComponentScaleX(COMPONENT_Cb));
     689  const UInt  uiPelsInPartChromaV = sps.getMaxCUHeight() >> (sps.getMaxTotalCUDepth()+pcPicYuvRec->getComponentScaleY(COMPONENT_Cb));
     690
    641691  Int iQP = 0;
    642692  Int iQP_P = 0;
    643693  Int iQP_Q = 0;
    644  
    645   UInt  uiPelsInPartChroma = g_uiMaxCUWidth >> (g_uiMaxCUDepth+1);
    646  
     694
    647695  Int   iOffset, iSrcStep;
    648  
    649   const UInt uiLCUWidthInBaseUnits = pcCU->getPic()->getNumPartInWidth();
    650  
     696  UInt  uiLoopLength;
     697
     698  const UInt uiCtuWidthInBaseUnits = pcCU->getPic()->getNumPartInCtuWidth();
     699
    651700  Bool  bPCMFilter = (pcCU->getSlice()->getSPS()->getUsePCM() && pcCU->getSlice()->getSPS()->getPCMFilterDisableFlag())? true : false;
    652701  Bool  bPartPNoFilter = false;
    653   Bool  bPartQNoFilter = false;
    654   UInt  uiPartPIdx;
    655   UInt  uiPartQIdx;
    656   TComDataCU* pcCUP;
     702  Bool  bPartQNoFilter = false;
    657703  TComDataCU* pcCUQ = pcCU;
    658704  Int tcOffsetDiv2 = pcCU->getSlice()->getDeblockingFilterTcOffsetDiv2();
    659  
     705
    660706  // Vertical Position
    661   UInt uiEdgeNumInLCUVert = g_auiZscanToRaster[uiAbsZorderIdx]%uiLCUWidthInBaseUnits + iEdge;
    662   UInt uiEdgeNumInLCUHor = g_auiZscanToRaster[uiAbsZorderIdx]/uiLCUWidthInBaseUnits + iEdge;
    663  
    664   if ( (uiPelsInPartChroma < DEBLOCK_SMALLEST_BLOCK) && (( (uiEdgeNumInLCUVert%(DEBLOCK_SMALLEST_BLOCK/uiPelsInPartChroma))&&(iDir==0) ) || ( (uiEdgeNumInLCUHor%(DEBLOCK_SMALLEST_BLOCK/uiPelsInPartChroma))&& iDir ) ))
     707  UInt uiEdgeNumInCtuVert = g_auiZscanToRaster[uiAbsZorderIdx]%uiCtuWidthInBaseUnits + iEdge;
     708  UInt uiEdgeNumInCtuHor = g_auiZscanToRaster[uiAbsZorderIdx]/uiCtuWidthInBaseUnits + iEdge;
     709
     710  if ( (uiPelsInPartChromaH < DEBLOCK_SMALLEST_BLOCK) && (uiPelsInPartChromaV < DEBLOCK_SMALLEST_BLOCK) &&
     711       (
     712         ( (uiEdgeNumInCtuVert%(DEBLOCK_SMALLEST_BLOCK/uiPelsInPartChromaH)) && (edgeDir==EDGE_VER) ) ||
     713         ( (uiEdgeNumInCtuHor %(DEBLOCK_SMALLEST_BLOCK/uiPelsInPartChromaV)) && (edgeDir==EDGE_HOR) )
     714       )
     715     )
    665716  {
    666717    return;
    667718  }
    668  
    669   UInt  uiNumParts = pcCU->getPic()->getNumPartInWidth()>>uiDepth;
    670  
     719
     720
     721  const Bool lfCrossSliceBoundaryFlag=pcCU->getSlice()->getLFCrossSliceBoundaryFlag();
     722
     723  UInt  uiNumParts = pcCU->getPic()->getNumPartInCtuWidth()>>uiDepth;
     724
    671725  UInt  uiBsAbsIdx;
    672726  UChar ucBs;
    673  
     727
    674728  Pel* piTmpSrcCb = piSrcCb;
    675729  Pel* piTmpSrcCr = piSrcCr;
    676  
    677  
    678   if (iDir == EDGE_VER)
     730
     731  if (edgeDir == EDGE_VER)
    679732  {
    680733    iOffset   = 1;
    681734    iSrcStep  = iStride;
    682     piTmpSrcCb += iEdge*uiPelsInPartChroma;
    683     piTmpSrcCr += iEdge*uiPelsInPartChroma;
    684   }
    685   else  // (iDir == EDGE_HOR)
     735    piTmpSrcCb += iEdge*uiPelsInPartChromaH;
     736    piTmpSrcCr += iEdge*uiPelsInPartChromaH;
     737    uiLoopLength=uiPelsInPartChromaV;
     738  }
     739  else  // (edgeDir == EDGE_HOR)
    686740  {
    687741    iOffset   = iStride;
    688742    iSrcStep  = 1;
    689     piTmpSrcCb += iEdge*iStride*uiPelsInPartChroma;
    690     piTmpSrcCr += iEdge*iStride*uiPelsInPartChroma;
    691   }
    692  
     743    piTmpSrcCb += iEdge*iStride*uiPelsInPartChromaV;
     744    piTmpSrcCr += iEdge*iStride*uiPelsInPartChromaV;
     745    uiLoopLength=uiPelsInPartChromaH;
     746  }
     747
     748  const Int iBitdepthScale = 1 << (pcCU->getSlice()->getSPS()->getBitDepth(CHANNEL_TYPE_CHROMA)-8);
     749
    693750  for ( UInt iIdx = 0; iIdx < uiNumParts; iIdx++ )
    694751  {
    695     uiBsAbsIdx = xCalcBsIdx( pcCU, uiAbsZorderIdx, iDir, iEdge, iIdx);
    696     ucBs = m_aapucBS[iDir][uiBsAbsIdx];
    697    
     752    uiBsAbsIdx = xCalcBsIdx( pcCU, uiAbsZorderIdx, edgeDir, iEdge, iIdx);
     753    ucBs = m_aapucBS[edgeDir][uiBsAbsIdx];
     754
    698755    if ( ucBs > 1)
    699756    {
    700757      iQP_Q = pcCU->getQP( uiBsAbsIdx );
    701       uiPartQIdx = uiBsAbsIdx;
     758      UInt  uiPartQIdx = uiBsAbsIdx;
    702759      // Derive neighboring PU index
    703       if (iDir == EDGE_VER)
    704       {
    705         pcCUP = pcCUQ->getPULeft (uiPartPIdx, uiPartQIdx,!pcCU->getSlice()->getLFCrossSliceBoundaryFlag(), !m_bLFCrossTileBoundary);
    706       }
    707       else  // (iDir == EDGE_HOR)
    708       {
    709         pcCUP = pcCUQ->getPUAbove(uiPartPIdx, uiPartQIdx,!pcCU->getSlice()->getLFCrossSliceBoundaryFlag(), false, !m_bLFCrossTileBoundary);
     760      TComDataCU* pcCUP;
     761      UInt  uiPartPIdx;
     762
     763      if (edgeDir == EDGE_VER)
     764      {
     765        pcCUP = pcCUQ->getPULeft (uiPartPIdx, uiPartQIdx,!lfCrossSliceBoundaryFlag, !m_bLFCrossTileBoundary);
     766      }
     767      else  // (edgeDir == EDGE_HOR)
     768      {
     769        pcCUP = pcCUQ->getPUAbove(uiPartPIdx, uiPartQIdx,!lfCrossSliceBoundaryFlag, false, !m_bLFCrossTileBoundary);
    710770      }
    711771
    712772      iQP_P = pcCUP->getQP(uiPartPIdx);
    713      
     773
    714774      if (bPCMFilter || pcCU->getSlice()->getPPS()->getTransquantBypassEnableFlag())
    715775      {
     
    722782        bPartQNoFilter = bPartQNoFilter || (pcCUQ->isLosslessCoded(uiPartQIdx));
    723783      }
    724      
     784
    725785      for ( UInt chromaIdx = 0; chromaIdx < 2; chromaIdx++ )
    726786      {
    727         Int chromaQPOffset  = (chromaIdx == 0) ? pcCU->getSlice()->getPPS()->getChromaCbQpOffset() : pcCU->getSlice()->getPPS()->getChromaCrQpOffset();
     787        Int chromaQPOffset  = pcCU->getSlice()->getPPS()->getQpOffset(ComponentID(chromaIdx + 1));
    728788        Pel* piTmpSrcChroma = (chromaIdx == 0) ? piTmpSrcCb : piTmpSrcCr;
    729789
    730         iQP = QpUV( ((iQP_P + iQP_Q + 1) >> 1) + chromaQPOffset );
    731         Int iBitdepthScale = 1 << (g_bitDepthC-8);
     790        iQP = ((iQP_P + iQP_Q + 1) >> 1) + chromaQPOffset;
     791        if (iQP >= chromaQPMappingTableSize)
     792        {
     793          if (pcPicYuvRec->getChromaFormat()==CHROMA_420)
     794          {
     795            iQP -=6;
     796          }
     797          else if (iQP>51)
     798          {
     799            iQP=51;
     800          }
     801        }
     802        else if (iQP >= 0 )
     803        {
     804          iQP = getScaledChromaQP(iQP, pcPicYuvRec->getChromaFormat());
     805        }
    732806
    733807        Int iIndexTC = Clip3(0, MAX_QP+DEFAULT_INTRA_TC_OFFSET, iQP + DEFAULT_INTRA_TC_OFFSET*(ucBs - 1) + (tcOffsetDiv2 << 1));
    734808        Int iTc =  sm_tcTable[iIndexTC]*iBitdepthScale;
    735809
    736         for ( UInt uiStep = 0; uiStep < uiPelsInPartChroma; uiStep++ )
    737         {
    738           xPelFilterChroma( piTmpSrcChroma + iSrcStep*(uiStep+iIdx*uiPelsInPartChroma), iOffset, iTc , bPartPNoFilter, bPartQNoFilter);
     810        for ( UInt uiStep = 0; uiStep < uiLoopLength; uiStep++ )
     811        {
     812          xPelFilterChroma( piTmpSrcChroma + iSrcStep*(uiStep+iIdx*uiLoopLength), iOffset, iTc , bPartPNoFilter, bPartQNoFilter, bitDepthChroma);
    739813        }
    740814      }
     
    755829 \param bFilterSecondP  decision weak filter/no filter for partP
    756830 \param bFilterSecondQ  decision weak filter/no filter for partQ
     831 \param bitDepthLuma    luma bit depth
    757832*/
    758 __inline Void TComLoopFilter::xPelFilterLuma( Pel* piSrc, Int iOffset, Int tc , Bool sw, Bool bPartPNoFilter, Bool bPartQNoFilter, Int iThrCut, Bool bFilterSecondP, Bool bFilterSecondQ)
     833__inline Void TComLoopFilter::xPelFilterLuma( Pel* piSrc, Int iOffset, Int tc, Bool sw, Bool bPartPNoFilter, Bool bPartQNoFilter, Int iThrCut, Bool bFilterSecondP, Bool bFilterSecondQ, const Int bitDepthLuma)
    759834{
    760835  Int delta;
    761  
     836
    762837  Pel m4  = piSrc[0];
    763838  Pel m3  = piSrc[-iOffset];
     
    785860    if ( abs(delta) < iThrCut )
    786861    {
    787       delta = Clip3(-tc, tc, delta);       
    788       piSrc[-iOffset] = ClipY((m3+delta));
    789       piSrc[0] = ClipY((m4-delta));
     862      delta = Clip3(-tc, tc, delta);
     863      piSrc[-iOffset] = ClipBD((m3+delta), bitDepthLuma);
     864      piSrc[0] = ClipBD((m4-delta), bitDepthLuma);
    790865
    791866      Int tc2 = tc>>1;
     
    793868      {
    794869        Int delta1 = Clip3(-tc2, tc2, (( ((m1+m3+1)>>1)- m2+delta)>>1));
    795         piSrc[-iOffset*2] = ClipY((m2+delta1));
     870        piSrc[-iOffset*2] = ClipBD((m2+delta1), bitDepthLuma);
    796871      }
    797872      if(bFilterSecondQ)
    798873      {
    799874        Int delta2 = Clip3(-tc2, tc2, (( ((m6+m4+1)>>1)- m5-delta)>>1));
    800         piSrc[ iOffset] = ClipY((m5+delta2));
     875        piSrc[ iOffset] = ClipBD((m5+delta2), bitDepthLuma);
    801876      }
    802877    }
     
    825900 \param bPartPNoFilter  indicator to disable filtering on partP
    826901 \param bPartQNoFilter  indicator to disable filtering on partQ
     902 \param bitDepthChroma  chroma bit depth
    827903 */
    828 __inline Void TComLoopFilter::xPelFilterChroma( Pel* piSrc, Int iOffset, Int tc, Bool bPartPNoFilter, Bool bPartQNoFilter)
     904__inline Void TComLoopFilter::xPelFilterChroma( Pel* piSrc, Int iOffset, Int tc, Bool bPartPNoFilter, Bool bPartQNoFilter, const Int bitDepthChroma)
    829905{
    830906  Int delta;
    831  
     907
    832908  Pel m4  = piSrc[0];
    833909  Pel m3  = piSrc[-iOffset];
    834910  Pel m5  = piSrc[ iOffset];
    835911  Pel m2  = piSrc[-iOffset*2];
    836  
     912
    837913  delta = Clip3(-tc,tc, (((( m4 - m3 ) << 2 ) + m2 - m5 + 4 ) >> 3) );
    838   piSrc[-iOffset] = ClipC(m3+delta);
    839   piSrc[0] = ClipC(m4-delta);
     914  piSrc[-iOffset] = ClipBD((m3+delta), bitDepthChroma);
     915  piSrc[0] = ClipBD((m4-delta), bitDepthChroma);
    840916
    841917  if(bPartPNoFilter)
     
    874950  return abs( piSrc[-iOffset*3] - 2*piSrc[-iOffset*2] + piSrc[-iOffset] ) ;
    875951}
    876  
     952
    877953__inline Int TComLoopFilter::xCalcDQ( Pel* piSrc, Int iOffset)
    878954{
Note: See TracChangeset for help on using the changeset viewer.