Ignore:
Timestamp:
26 Feb 2015, 00:21:54 (10 years ago)
Author:
seregin
Message:

merge with SHM-upgrade branch

Location:
branches/SHM-dev
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/SHM-dev

  • branches/SHM-dev/source

  • branches/SHM-dev/source/Lib/TLibDecoder/TDecCu.cpp

    r713 r1029  
    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 *
    66 * Copyright (c) 2010-2014, ITU/ISO/IEC
     
    3737
    3838#include "TDecCu.h"
     39#include "TLibCommon/TComTU.h"
    3940#if SVC_EXTENSION
    4041#include "TDecTop.h"
     
    9596 \param    uiMaxHeight   largest CU height
    9697 */
    97 Void TDecCu::create( UInt uiMaxDepth, UInt uiMaxWidth, UInt uiMaxHeight )
     98Void TDecCu::create( UInt uiMaxDepth, UInt uiMaxWidth, UInt uiMaxHeight, ChromaFormat chromaFormatIDC )
    9899{
    99100  m_uiMaxDepth = uiMaxDepth+1;
    100  
     101
    101102  m_ppcYuvResi = new TComYuv*[m_uiMaxDepth-1];
    102103  m_ppcYuvReco = new TComYuv*[m_uiMaxDepth-1];
    103104  m_ppcCU      = new TComDataCU*[m_uiMaxDepth-1];
    104  
     105
    105106  UInt uiNumPartitions;
    106107  for ( UInt ui = 0; ui < m_uiMaxDepth-1; ui++ )
     
    109110    UInt uiWidth  = uiMaxWidth  >> ui;
    110111    UInt uiHeight = uiMaxHeight >> ui;
    111    
    112     m_ppcYuvResi[ui] = new TComYuv;    m_ppcYuvResi[ui]->create( uiWidth, uiHeight );
    113     m_ppcYuvReco[ui] = new TComYuv;    m_ppcYuvReco[ui]->create( uiWidth, uiHeight );
    114     m_ppcCU     [ui] = new TComDataCU; m_ppcCU     [ui]->create( uiNumPartitions, uiWidth, uiHeight, true, uiMaxWidth >> (m_uiMaxDepth - 1) );
    115   }
    116  
     112
     113    m_ppcYuvResi[ui] = new TComYuv;    m_ppcYuvResi[ui]->create( uiWidth, uiHeight, chromaFormatIDC );
     114    m_ppcYuvReco[ui] = new TComYuv;    m_ppcYuvReco[ui]->create( uiWidth, uiHeight, chromaFormatIDC );
     115    m_ppcCU     [ui] = new TComDataCU; m_ppcCU     [ui]->create( chromaFormatIDC, uiNumPartitions, uiWidth, uiHeight, true, uiMaxWidth >> (m_uiMaxDepth - 1) );
     116  }
     117
    117118  m_bDecodeDQP = false;
     119  m_IsChromaQpAdjCoded = false;
    118120
    119121  // initialize partition order.
     
    121123  initZscanToRaster(m_uiMaxDepth, 1, 0, piTmp);
    122124  initRasterToZscan( uiMaxWidth, uiMaxHeight, m_uiMaxDepth );
    123  
     125
    124126  // initialize conversion matrix from partition index to pel
    125127  initRasterToPelXY( uiMaxWidth, uiMaxHeight, m_uiMaxDepth );
     
    134136    m_ppcCU     [ui]->destroy(); delete m_ppcCU     [ui]; m_ppcCU     [ui] = NULL;
    135137  }
    136  
     138
    137139  delete [] m_ppcYuvResi; m_ppcYuvResi = NULL;
    138140  delete [] m_ppcYuvReco; m_ppcYuvReco = NULL;
     
    147149 \param    ruiIsLast   last data?
    148150 */
    149 Void TDecCu::decodeCU( TComDataCU* pcCU, UInt& ruiIsLast )
    150 {
    151   if ( pcCU->getSlice()->getPPS()->getUseDQP() )
     151Void TDecCu::decodeCtu( TComDataCU* pCtu, Bool& isLastCtuOfSliceSegment )
     152{
     153  if ( pCtu->getSlice()->getPPS()->getUseDQP() )
    152154  {
    153155    setdQPFlag(true);
    154156  }
    155157
     158  if ( pCtu->getSlice()->getUseChromaQpAdj() )
     159  {
     160    setIsChromaQpAdjCoded(true);
     161  }
     162
     163#if SVC_EXTENSION
     164  pCtu->setLayerId(m_layerId);
     165#endif
     166
    156167  // start from the top level CU
    157 #if SVC_EXTENSION
    158   pcCU->setLayerId(m_layerId);
    159 #endif
    160   xDecodeCU( pcCU, 0, 0, ruiIsLast);
     168  xDecodeCU( pCtu, 0, 0, isLastCtuOfSliceSegment);
    161169}
    162170
    163171/** \param    pcCU        pointer of CU data
    164172 */
    165 Void TDecCu::decompressCU( TComDataCU* pcCU )
    166 {
    167   xDecompressCU( pcCU, 0,  0 );
     173Void TDecCu::decompressCtu( TComDataCU* pCtu )
     174{
     175  xDecompressCU( pCtu, 0,  0 );
    168176}
    169177
     
    174182/**decode end-of-slice flag
    175183 * \param pcCU
    176  * \param uiAbsPartIdx 
    177  * \param uiDepth 
     184 * \param uiAbsPartIdx
     185 * \param uiDepth
    178186 * \returns Bool
    179187 */
    180 Bool TDecCu::xDecodeSliceEnd( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth)
    181 {
    182   UInt uiIsLast;
    183   TComPic* pcPic = pcCU->getPic();
    184   TComSlice * pcSlice = pcPic->getSlice(pcPic->getCurrSliceIdx());
    185   UInt uiCurNumParts    = pcPic->getNumPartInCU() >> (uiDepth<<1);
    186 #if REPN_FORMAT_IN_VPS
    187   UInt uiWidth  = pcSlice->getPicWidthInLumaSamples();
    188   UInt uiHeight = pcSlice->getPicHeightInLumaSamples();
    189 #else
    190   UInt uiWidth = pcSlice->getSPS()->getPicWidthInLumaSamples();
    191   UInt uiHeight = pcSlice->getSPS()->getPicHeightInLumaSamples();
    192 #endif
    193   UInt uiGranularityWidth = g_uiMaxCUWidth;
    194   UInt uiPosX = pcCU->getCUPelX() + g_auiRasterToPelX[ g_auiZscanToRaster[uiAbsPartIdx] ];
    195   UInt uiPosY = pcCU->getCUPelY() + g_auiRasterToPelY[ g_auiZscanToRaster[uiAbsPartIdx] ];
    196 
    197   if(((uiPosX+pcCU->getWidth(uiAbsPartIdx))%uiGranularityWidth==0||(uiPosX+pcCU->getWidth(uiAbsPartIdx)==uiWidth))
    198     &&((uiPosY+pcCU->getHeight(uiAbsPartIdx))%uiGranularityWidth==0||(uiPosY+pcCU->getHeight(uiAbsPartIdx)==uiHeight)))
    199   {
    200     m_pcEntropyDecoder->decodeTerminatingBit( uiIsLast );
     188Bool TDecCu::xDecodeSliceEnd( TComDataCU* pcCU, UInt uiAbsPartIdx )
     189{
     190  UInt uiIsLastCtuOfSliceSegment;
     191
     192  if (pcCU->isLastSubCUOfCtu(uiAbsPartIdx))
     193  {
     194    m_pcEntropyDecoder->decodeTerminatingBit( uiIsLastCtuOfSliceSegment );
    201195  }
    202196  else
    203197  {
    204     uiIsLast=0;
    205   }
    206  
    207   if(uiIsLast)
    208   {
    209     if(pcSlice->isNextSliceSegment()&&!pcSlice->isNextSlice())
    210     {
    211       pcSlice->setSliceSegmentCurEndCUAddr(pcCU->getSCUAddr()+uiAbsPartIdx+uiCurNumParts);
    212     }
    213     else
    214     {
    215       pcSlice->setSliceCurEndCUAddr(pcCU->getSCUAddr()+uiAbsPartIdx+uiCurNumParts);
    216       pcSlice->setSliceSegmentCurEndCUAddr(pcCU->getSCUAddr()+uiAbsPartIdx+uiCurNumParts);
    217     }
    218   }
    219 
    220   return uiIsLast>0;
     198    uiIsLastCtuOfSliceSegment=0;
     199  }
     200
     201  return uiIsLastCtuOfSliceSegment>0;
    221202}
    222203
    223204/** decode CU block recursively
    224205 * \param pcCU
    225  * \param uiAbsPartIdx 
    226  * \param uiDepth 
     206 * \param uiAbsPartIdx
     207 * \param uiDepth
    227208 * \returns Void
    228209 */
    229210
    230 Void TDecCu::xDecodeCU( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, UInt& ruiIsLast)
     211Void TDecCu::xDecodeCU( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, Bool &isLastCtuOfSliceSegment)
    231212{
    232213  TComPic* pcPic = pcCU->getPic();
    233   UInt uiCurNumParts    = pcPic->getNumPartInCU() >> (uiDepth<<1);
     214  UInt uiCurNumParts    = pcPic->getNumPartitionsInCtu() >> (uiDepth<<1);
    234215  UInt uiQNumParts      = uiCurNumParts>>2;
    235  
     216
    236217  Bool bBoundary = false;
    237218  UInt uiLPelX   = pcCU->getCUPelX() + g_auiRasterToPelX[ g_auiZscanToRaster[uiAbsPartIdx] ];
     
    239220  UInt uiTPelY   = pcCU->getCUPelY() + g_auiRasterToPelY[ g_auiZscanToRaster[uiAbsPartIdx] ];
    240221  UInt uiBPelY   = uiTPelY + (g_uiMaxCUHeight>>uiDepth) - 1;
    241  
     222
    242223  TComSlice * pcSlice = pcCU->getPic()->getSlice(pcCU->getPic()->getCurrSliceIdx());
    243   Bool bStartInCU = pcCU->getSCUAddr()+uiAbsPartIdx+uiCurNumParts>pcSlice->getSliceSegmentCurStartCUAddr()&&pcCU->getSCUAddr()+uiAbsPartIdx<pcSlice->getSliceSegmentCurStartCUAddr();
    244224#if REPN_FORMAT_IN_VPS
    245   if((!bStartInCU) && ( uiRPelX < pcSlice->getPicWidthInLumaSamples()           ) && ( uiBPelY < pcSlice->getPicHeightInLumaSamples()          ) )
     225  if( ( uiRPelX < pcSlice->getPicWidthInLumaSamples() ) && ( uiBPelY < pcSlice->getPicHeightInLumaSamples() ) )
    246226#else
    247   if((!bStartInCU) && ( uiRPelX < pcSlice->getSPS()->getPicWidthInLumaSamples() ) && ( uiBPelY < pcSlice->getSPS()->getPicHeightInLumaSamples() ) )
     227  if( ( uiRPelX < pcSlice->getSPS()->getPicWidthInLumaSamples() ) && ( uiBPelY < pcSlice->getSPS()->getPicHeightInLumaSamples() ) )
    248228#endif
    249229  {
     
    254234    bBoundary = true;
    255235  }
    256  
     236
    257237  if( ( ( uiDepth < pcCU->getDepth( uiAbsPartIdx ) ) && ( uiDepth < g_uiMaxCUDepth - g_uiAddCUDepth ) ) || bBoundary )
    258238  {
     
    264244    }
    265245
     246    if( (g_uiMaxCUWidth>>uiDepth) == pcCU->getSlice()->getPPS()->getMinCuChromaQpAdjSize() && pcCU->getSlice()->getUseChromaQpAdj() )
     247    {
     248      setIsChromaQpAdjCoded(true);
     249    }
     250
    266251    for ( UInt uiPartUnitIdx = 0; uiPartUnitIdx < 4; uiPartUnitIdx++ )
    267252    {
    268253      uiLPelX   = pcCU->getCUPelX() + g_auiRasterToPelX[ g_auiZscanToRaster[uiIdx] ];
    269254      uiTPelY   = pcCU->getCUPelY() + g_auiRasterToPelY[ g_auiZscanToRaster[uiIdx] ];
    270      
    271       Bool bSubInSlice = pcCU->getSCUAddr()+uiIdx+uiQNumParts>pcSlice->getSliceSegmentCurStartCUAddr();
    272       if ( bSubInSlice )
    273       {
     255
    274256#if REPN_FORMAT_IN_VPS
    275         if ( !ruiIsLast && ( uiLPelX < pcCU->getSlice()->getPicWidthInLumaSamples()           ) && ( uiTPelY < pcCU->getSlice()->getPicHeightInLumaSamples()          ) )
     257      if ( !isLastCtuOfSliceSegment && ( uiLPelX < pcCU->getSlice()->getPicWidthInLumaSamples() ) && ( uiTPelY < pcCU->getSlice()->getPicHeightInLumaSamples() ) )
    276258#else
    277         if ( !ruiIsLast && ( uiLPelX < pcCU->getSlice()->getSPS()->getPicWidthInLumaSamples() ) && ( uiTPelY < pcCU->getSlice()->getSPS()->getPicHeightInLumaSamples() ) )
    278 #endif
    279         {
    280           xDecodeCU( pcCU, uiIdx, uiDepth+1, ruiIsLast );
    281         }
    282         else
    283         {
    284           pcCU->setOutsideCUPart( uiIdx, uiDepth+1 );
    285         }
    286       }
    287      
     259      if ( !isLastCtuOfSliceSegment && ( uiLPelX < pcCU->getSlice()->getSPS()->getPicWidthInLumaSamples() ) && ( uiTPelY < pcCU->getSlice()->getSPS()->getPicHeightInLumaSamples() ) )
     260#endif
     261      {
     262        xDecodeCU( pcCU, uiIdx, uiDepth+1, isLastCtuOfSliceSegment );
     263      }
     264      else
     265      {
     266        pcCU->setOutsideCUPart( uiIdx, uiDepth+1 );
     267      }
     268
    288269      uiIdx += uiQNumParts;
    289270    }
     
    292273      if ( getdQPFlag() )
    293274      {
    294         UInt uiQPSrcPartIdx;
    295         if ( pcPic->getCU( pcCU->getAddr() )->getSliceSegmentStartCU(uiAbsPartIdx) != pcSlice->getSliceSegmentCurStartCUAddr() )
    296         {
    297           uiQPSrcPartIdx = pcSlice->getSliceSegmentCurStartCUAddr() % pcPic->getNumPartInCU();
    298         }
    299         else
    300         {
    301           uiQPSrcPartIdx = uiAbsPartIdx;
    302         }
     275        UInt uiQPSrcPartIdx = uiAbsPartIdx;
    303276        pcCU->setQPSubParts( pcCU->getRefQP( uiQPSrcPartIdx ), uiAbsPartIdx, uiDepth ); // set QP to default QP
    304277      }
     
    306279    return;
    307280  }
    308  
     281
    309282  if( (g_uiMaxCUWidth>>uiDepth) >= pcCU->getSlice()->getPPS()->getMinCuDQPSize() && pcCU->getSlice()->getPPS()->getUseDQP())
    310283  {
     
    313286  }
    314287
     288  if( (g_uiMaxCUWidth>>uiDepth) >= pcCU->getSlice()->getPPS()->getMinCuChromaQpAdjSize() && pcCU->getSlice()->getUseChromaQpAdj() )
     289  {
     290    setIsChromaQpAdjCoded(true);
     291  }
     292
    315293  if (pcCU->getSlice()->getPPS()->getTransquantBypassEnableFlag())
    316294  {
    317295    m_pcEntropyDecoder->decodeCUTransquantBypassFlag( pcCU, uiAbsPartIdx, uiDepth );
    318296  }
    319  
     297
    320298  // decode CU mode and the partition size
    321299  if( !pcCU->getSlice()->isIntra())
     
    360338    TComMv cTmpMv( 0, 0 );
    361339    for ( UInt uiRefListIdx = 0; uiRefListIdx < 2; uiRefListIdx++ )
    362     {       
     340    {
    363341      if ( pcCU->getSlice()->getNumRefIdx( RefPicList( uiRefListIdx ) ) > 0 )
    364342      {
     
    369347      }
    370348    }
    371     xFinishDecodeCU( pcCU, uiAbsPartIdx, uiDepth, ruiIsLast );
     349    xFinishDecodeCU( pcCU, uiAbsPartIdx, uiDepth, isLastCtuOfSliceSegment );
    372350    return;
    373351  }
     
    382360    if(pcCU->getIPCMFlag(uiAbsPartIdx))
    383361    {
    384       xFinishDecodeCU( pcCU, uiAbsPartIdx, uiDepth, ruiIsLast );
     362      xFinishDecodeCU( pcCU, uiAbsPartIdx, uiDepth, isLastCtuOfSliceSegment );
    385363      return;
    386364    }
    387365  }
    388366
    389   UInt uiCurrWidth      = pcCU->getWidth ( uiAbsPartIdx );
    390   UInt uiCurrHeight     = pcCU->getHeight( uiAbsPartIdx );
    391  
    392367  // prediction mode ( Intra : direction mode, Inter : Mv, reference idx )
    393368  m_pcEntropyDecoder->decodePredInfo( pcCU, uiAbsPartIdx, uiDepth, m_ppcCU[uiDepth]);
     
    395370  // Coefficient decoding
    396371  Bool bCodeDQP = getdQPFlag();
    397   m_pcEntropyDecoder->decodeCoeff( pcCU, uiAbsPartIdx, uiDepth, uiCurrWidth, uiCurrHeight, bCodeDQP );
     372  Bool isChromaQpAdjCoded = getIsChromaQpAdjCoded();
     373  m_pcEntropyDecoder->decodeCoeff( pcCU, uiAbsPartIdx, uiDepth, bCodeDQP, isChromaQpAdjCoded );
     374  setIsChromaQpAdjCoded( isChromaQpAdjCoded );
    398375  setdQPFlag( bCodeDQP );
    399   xFinishDecodeCU( pcCU, uiAbsPartIdx, uiDepth, ruiIsLast );
    400 }
    401 
    402 Void TDecCu::xFinishDecodeCU( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, UInt& ruiIsLast)
     376  xFinishDecodeCU( pcCU, uiAbsPartIdx, uiDepth, isLastCtuOfSliceSegment );
     377}
     378
     379Void TDecCu::xFinishDecodeCU( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, Bool &isLastCtuOfSliceSegment)
    403380{
    404381  if(  pcCU->getSlice()->getPPS()->getUseDQP())
     
    407384  }
    408385
    409   ruiIsLast = xDecodeSliceEnd( pcCU, uiAbsPartIdx, uiDepth);
    410 }
    411 
    412 Void TDecCu::xDecompressCU( TComDataCU* pcCU, UInt uiAbsPartIdx,  UInt uiDepth )
    413 {
    414   TComPic* pcPic = pcCU->getPic();
    415  
     386  if (pcCU->getSlice()->getUseChromaQpAdj() && !getIsChromaQpAdjCoded())
     387  {
     388    pcCU->setChromaQpAdjSubParts( pcCU->getCodedChromaQpAdj(), uiAbsPartIdx, uiDepth ); // set QP
     389  }
     390
     391  isLastCtuOfSliceSegment = xDecodeSliceEnd( pcCU, uiAbsPartIdx );
     392}
     393
     394Void TDecCu::xDecompressCU( TComDataCU* pCtu, UInt uiAbsPartIdx,  UInt uiDepth )
     395{
     396  TComPic* pcPic = pCtu->getPic();
     397
    416398  Bool bBoundary = false;
    417   UInt uiLPelX   = pcCU->getCUPelX() + g_auiRasterToPelX[ g_auiZscanToRaster[uiAbsPartIdx] ];
     399  UInt uiLPelX   = pCtu->getCUPelX() + g_auiRasterToPelX[ g_auiZscanToRaster[uiAbsPartIdx] ];
    418400  UInt uiRPelX   = uiLPelX + (g_uiMaxCUWidth>>uiDepth)  - 1;
    419   UInt uiTPelY   = pcCU->getCUPelY() + g_auiRasterToPelY[ g_auiZscanToRaster[uiAbsPartIdx] ];
     401  UInt uiTPelY   = pCtu->getCUPelY() + g_auiRasterToPelY[ g_auiZscanToRaster[uiAbsPartIdx] ];
    420402  UInt uiBPelY   = uiTPelY + (g_uiMaxCUHeight>>uiDepth) - 1;
    421  
    422   UInt uiCurNumParts    = pcPic->getNumPartInCU() >> (uiDepth<<1);
    423   TComSlice * pcSlice = pcCU->getPic()->getSlice(pcCU->getPic()->getCurrSliceIdx());
    424   Bool bStartInCU = pcCU->getSCUAddr()+uiAbsPartIdx+uiCurNumParts>pcSlice->getSliceSegmentCurStartCUAddr()&&pcCU->getSCUAddr()+uiAbsPartIdx<pcSlice->getSliceSegmentCurStartCUAddr();
     403
     404  TComSlice * pcSlice = pCtu->getPic()->getSlice(pCtu->getPic()->getCurrSliceIdx());
     405
    425406#if REPN_FORMAT_IN_VPS
    426   if(bStartInCU||( uiRPelX >= pcSlice->getPicWidthInLumaSamples()           ) || ( uiBPelY >= pcSlice->getPicHeightInLumaSamples()           ) )
     407  if( ( uiRPelX >= pcSlice->getPicWidthInLumaSamples() ) || ( uiBPelY >= pcSlice->getPicHeightInLumaSamples() ) )
     408
    427409#else
    428   if(bStartInCU||( uiRPelX >= pcSlice->getSPS()->getPicWidthInLumaSamples() ) || ( uiBPelY >= pcSlice->getSPS()->getPicHeightInLumaSamples() ) )
     410  if( ( uiRPelX >= pcSlice->getSPS()->getPicWidthInLumaSamples() ) || ( uiBPelY >= pcSlice->getSPS()->getPicHeightInLumaSamples() ) )
    429411#endif
    430412  {
    431413    bBoundary = true;
    432414  }
    433  
    434   if( ( ( uiDepth < pcCU->getDepth( uiAbsPartIdx ) ) && ( uiDepth < g_uiMaxCUDepth - g_uiAddCUDepth ) ) || bBoundary )
     415
     416  if( ( ( uiDepth < pCtu->getDepth( uiAbsPartIdx ) ) && ( uiDepth < g_uiMaxCUDepth - g_uiAddCUDepth ) ) || bBoundary )
    435417  {
    436418    UInt uiNextDepth = uiDepth + 1;
    437     UInt uiQNumParts = pcCU->getTotalNumPart() >> (uiNextDepth<<1);
     419    UInt uiQNumParts = pCtu->getTotalNumPart() >> (uiNextDepth<<1);
    438420    UInt uiIdx = uiAbsPartIdx;
    439421    for ( UInt uiPartIdx = 0; uiPartIdx < 4; uiPartIdx++ )
    440422    {
    441       uiLPelX = pcCU->getCUPelX() + g_auiRasterToPelX[ g_auiZscanToRaster[uiIdx] ];
    442       uiTPelY = pcCU->getCUPelY() + g_auiRasterToPelY[ g_auiZscanToRaster[uiIdx] ];
    443      
    444       Bool binSlice = (pcCU->getSCUAddr()+uiIdx+uiQNumParts>pcSlice->getSliceSegmentCurStartCUAddr())&&(pcCU->getSCUAddr()+uiIdx<pcSlice->getSliceSegmentCurEndCUAddr());
     423      uiLPelX = pCtu->getCUPelX() + g_auiRasterToPelX[ g_auiZscanToRaster[uiIdx] ];
     424      uiTPelY = pCtu->getCUPelY() + g_auiRasterToPelY[ g_auiZscanToRaster[uiIdx] ];
     425
    445426#if REPN_FORMAT_IN_VPS
    446       if(binSlice&&( uiLPelX < pcSlice->getPicWidthInLumaSamples()           ) && ( uiTPelY < pcSlice->getPicHeightInLumaSamples()          ) )
     427      if( ( uiLPelX < pcSlice->getPicWidthInLumaSamples() ) && ( uiTPelY < pcSlice->getPicHeightInLumaSamples() ) )
    447428#else
    448       if(binSlice&&( uiLPelX < pcSlice->getSPS()->getPicWidthInLumaSamples() ) && ( uiTPelY < pcSlice->getSPS()->getPicHeightInLumaSamples() ) )
    449 #endif
    450       {
    451         xDecompressCU(pcCU, uiIdx, uiNextDepth );
    452       }
    453      
     429      if( ( uiLPelX < pcSlice->getSPS()->getPicWidthInLumaSamples() ) && ( uiTPelY < pcSlice->getSPS()->getPicHeightInLumaSamples() ) )
     430#endif
     431      {
     432        xDecompressCU(pCtu, uiIdx, uiNextDepth );
     433      }
     434
    454435      uiIdx += uiQNumParts;
    455436    }
    456437    return;
    457438  }
    458  
     439
    459440  // Residual reconstruction
    460441  m_ppcYuvResi[uiDepth]->clear();
    461  
    462   m_ppcCU[uiDepth]->copySubCU( pcCU, uiAbsPartIdx, uiDepth );
    463  
     442
     443  m_ppcCU[uiDepth]->copySubCU( pCtu, uiAbsPartIdx, uiDepth );
     444
    464445  switch( m_ppcCU[uiDepth]->getPredictionMode(0) )
    465446  {
     
    474455      break;
    475456  }
     457
     458#ifdef DEBUG_STRING
     459  const PredMode predMode=m_ppcCU[uiDepth]->getPredictionMode(0);
     460  if (DebugOptionList::DebugString_Structure.getInt()&DebugStringGetPredModeMask(predMode))
     461  {
     462    PartSize eSize=m_ppcCU[uiDepth]->getPartitionSize(0);
     463    std::ostream &ss(std::cout);
     464
     465    ss <<"###: " << (predMode==MODE_INTRA?"Intra   ":"Inter   ") << partSizeToString[eSize] << " CU at " << m_ppcCU[uiDepth]->getCUPelX() << ", " << m_ppcCU[uiDepth]->getCUPelY() << " width=" << UInt(m_ppcCU[uiDepth]->getWidth(0)) << std::endl;
     466  }
     467#endif
     468
    476469  if ( m_ppcCU[uiDepth]->isLosslessCoded(0) && (m_ppcCU[uiDepth]->getIPCMFlag(0) == false))
    477470  {
    478471    xFillPCMBuffer(m_ppcCU[uiDepth], uiDepth);
    479472  }
    480  
     473
    481474  xCopyToPic( m_ppcCU[uiDepth], pcPic, uiAbsPartIdx, uiDepth );
    482475}
     
    484477Void TDecCu::xReconInter( TComDataCU* pcCU, UInt uiDepth )
    485478{
    486  
     479
    487480  // inter prediction
    488481  m_pcPrediction->motionCompensation( pcCU, m_ppcYuvReco[uiDepth] );
    489  
     482
     483#ifdef DEBUG_STRING
     484  const Int debugPredModeMask=DebugStringGetPredModeMask(MODE_INTER);
     485  if (DebugOptionList::DebugString_Pred.getInt()&debugPredModeMask) printBlockToStream(std::cout, "###inter-pred: ", *(m_ppcYuvReco[uiDepth]));
     486#endif
     487
    490488  // inter recon
    491   xDecodeInterTexture( pcCU, 0, uiDepth );
    492  
     489  xDecodeInterTexture( pcCU, uiDepth );
     490
     491#ifdef DEBUG_STRING
     492  if (DebugOptionList::DebugString_Resi.getInt()&debugPredModeMask) printBlockToStream(std::cout, "###inter-resi: ", *(m_ppcYuvResi[uiDepth]));
     493#endif
     494
    493495  // clip for only non-zero cbp case
    494   if  ( ( pcCU->getCbf( 0, TEXT_LUMA ) ) || ( pcCU->getCbf( 0, TEXT_CHROMA_U ) ) || ( pcCU->getCbf(0, TEXT_CHROMA_V ) ) )
     496  if  ( pcCU->getQtRootCbf( 0) )
    495497  {
    496498    m_ppcYuvReco[uiDepth]->addClip( m_ppcYuvReco[uiDepth], m_ppcYuvResi[uiDepth], 0, pcCU->getWidth( 0 ) );
     
    500502    m_ppcYuvReco[uiDepth]->copyPartToPartYuv( m_ppcYuvReco[uiDepth],0, pcCU->getWidth( 0 ),pcCU->getHeight( 0 ));
    501503  }
    502 }
     504#ifdef DEBUG_STRING
     505  if (DebugOptionList::DebugString_Reco.getInt()&debugPredModeMask) printBlockToStream(std::cout, "###inter-reco: ", *(m_ppcYuvReco[uiDepth]));
     506#endif
     507
     508}
     509
    503510
    504511Void
    505 TDecCu::xIntraRecLumaBlk( TComDataCU* pcCU,
    506                          UInt        uiTrDepth,
    507                          UInt        uiAbsPartIdx,
    508                          TComYuv*    pcRecoYuv,
    509                          TComYuv*    pcPredYuv,
    510                          TComYuv*    pcResiYuv )
    511 {
    512   UInt    uiWidth           = pcCU     ->getWidth   ( 0 ) >> uiTrDepth;
    513   UInt    uiHeight          = pcCU     ->getHeight  ( 0 ) >> uiTrDepth;
    514   UInt    uiStride          = pcRecoYuv->getStride  ();
    515   Pel*    piReco            = pcRecoYuv->getLumaAddr( uiAbsPartIdx );
    516   Pel*    piPred            = pcPredYuv->getLumaAddr( uiAbsPartIdx );
    517   Pel*    piResi            = pcResiYuv->getLumaAddr( uiAbsPartIdx );
    518  
    519   UInt    uiNumCoeffInc     = ( pcCU->getSlice()->getSPS()->getMaxCUWidth() * pcCU->getSlice()->getSPS()->getMaxCUHeight() ) >> ( pcCU->getSlice()->getSPS()->getMaxCUDepth() << 1 );
    520   TCoeff* pcCoeff           = pcCU->getCoeffY() + ( uiNumCoeffInc * uiAbsPartIdx );
    521  
    522   UInt    uiLumaPredMode    = pcCU->getLumaIntraDir     ( uiAbsPartIdx );
    523  
    524   UInt    uiZOrder          = pcCU->getZorderIdxInCU() + uiAbsPartIdx;
    525   Pel*    piRecIPred        = pcCU->getPic()->getPicYuvRec()->getLumaAddr( pcCU->getAddr(), uiZOrder );
    526   UInt    uiRecIPredStride  = pcCU->getPic()->getPicYuvRec()->getStride  ();
    527   Bool    useTransformSkip  = pcCU->getTransformSkip(uiAbsPartIdx, TEXT_LUMA);
     512TDecCu::xIntraRecBlk(       TComYuv*    pcRecoYuv,
     513                            TComYuv*    pcPredYuv,
     514                            TComYuv*    pcResiYuv,
     515                      const ComponentID compID,
     516                            TComTU     &rTu)
     517{
     518  if (!rTu.ProcessComponentSection(compID)) return;
     519  const Bool       bIsLuma = isLuma(compID);
     520
     521
     522  TComDataCU *pcCU = rTu.getCU();
     523  const UInt uiAbsPartIdx=rTu.GetAbsPartIdxTU();
     524
     525  const TComRectangle &tuRect  =rTu.getRect(compID);
     526  const UInt uiWidth           = tuRect.width;
     527  const UInt uiHeight          = tuRect.height;
     528  const UInt uiStride          = pcRecoYuv->getStride (compID);
     529        Pel* piPred            = pcPredYuv->getAddr( compID, uiAbsPartIdx );
     530  const ChromaFormat chFmt     = rTu.GetChromaFormat();
     531
     532  if (uiWidth != uiHeight)
     533  {
     534    //------------------------------------------------
     535
     536    //split at current level if dividing into square sub-TUs
     537
     538    TComTURecurse subTURecurse(rTu, false, TComTU::VERTICAL_SPLIT, true, compID);
     539
     540    //recurse further
     541    do
     542    {
     543      xIntraRecBlk(pcRecoYuv, pcPredYuv, pcResiYuv, compID, subTURecurse);
     544    }
     545    while (subTURecurse.nextSection(rTu));
     546
     547    //------------------------------------------------
     548
     549    return;
     550  }
     551
     552  const UInt uiChPredMode  = pcCU->getIntraDir( toChannelType(compID), uiAbsPartIdx );
     553  const UInt uiChCodedMode = (uiChPredMode==DM_CHROMA_IDX && !bIsLuma) ? pcCU->getIntraDir(CHANNEL_TYPE_LUMA, getChromasCorrespondingPULumaIdx(uiAbsPartIdx, chFmt)) : uiChPredMode;
     554  const UInt uiChFinalMode = ((chFmt == CHROMA_422)       && !bIsLuma) ? g_chroma422IntraAngleMappingTable[uiChCodedMode] : uiChCodedMode;
     555
    528556  //===== init availability pattern =====
    529557  Bool  bAboveAvail = false;
    530558  Bool  bLeftAvail  = false;
    531   pcCU->getPattern()->initPattern   ( pcCU, uiTrDepth, uiAbsPartIdx );
    532   pcCU->getPattern()->initAdiPattern( pcCU, uiAbsPartIdx, uiTrDepth,
    533                                      m_pcPrediction->getPredicBuf       (),
    534                                      m_pcPrediction->getPredicBufWidth  (),
    535                                      m_pcPrediction->getPredicBufHeight (),
    536                                      bAboveAvail, bLeftAvail );
    537  
     559
     560  const Bool bUseFilteredPredictions=TComPrediction::filteringIntraReferenceSamples(compID, uiChFinalMode, uiWidth, uiHeight, chFmt, pcCU->getSlice()->getSPS()->getDisableIntraReferenceSmoothing());
     561
     562#ifdef DEBUG_STRING
     563  std::ostream &ss(std::cout);
     564#endif
     565
     566  DEBUG_STRING_NEW(sTemp)
     567  m_pcPrediction->initAdiPatternChType( rTu, bAboveAvail, bLeftAvail, compID, bUseFilteredPredictions  DEBUG_STRING_PASS_INTO(sTemp) );
     568
     569
    538570  //===== get prediction signal =====
    539   m_pcPrediction->predIntraLumaAng( pcCU->getPattern(), uiLumaPredMode, piPred, uiStride, uiWidth, uiHeight, bAboveAvail, bLeftAvail );
    540  
    541   if ( pcCU->getCbf( uiAbsPartIdx, TEXT_LUMA, uiTrDepth ) )
    542   {
     571
     572  m_pcPrediction->predIntraAng( compID,   uiChFinalMode, 0 /* Decoder does not have an original image */, 0, piPred, uiStride, rTu, bAboveAvail, bLeftAvail, bUseFilteredPredictions );
     573
     574#ifdef DEBUG_STRING
     575  ss << sTemp;
     576#endif
     577
    543578  //===== inverse transform =====
    544 #if REPN_FORMAT_IN_VPS
    545   m_pcTrQuant->setQPforQuant  ( pcCU->getQP(0), TEXT_LUMA, pcCU->getSlice()->getQpBDOffsetY(), 0 );
     579  Pel*      piResi            = pcResiYuv->getAddr( compID, uiAbsPartIdx );
     580  TCoeff*   pcCoeff           = pcCU->getCoeff(compID) + rTu.getCoefficientOffset(compID);//( uiNumCoeffInc * uiAbsPartIdx );
     581
     582  const QpParam cQP(*pcCU, compID);
     583
     584
     585  DEBUG_STRING_NEW(sDebug);
     586#ifdef DEBUG_STRING
     587  const Int debugPredModeMask=DebugStringGetPredModeMask(MODE_INTRA);
     588  std::string *psDebug=(DebugOptionList::DebugString_InvTran.getInt()&debugPredModeMask) ? &sDebug : 0;
     589#endif
     590
     591  if (pcCU->getCbf(uiAbsPartIdx, compID, rTu.GetTransformDepthRel()) != 0)
     592  {
     593    m_pcTrQuant->invTransformNxN( rTu, compID, piResi, uiStride, pcCoeff, cQP DEBUG_STRING_PASS_INTO(psDebug) );
     594  }
     595  else
     596  {
     597    for (UInt y = 0; y < uiHeight; y++)
     598      for (UInt x = 0; x < uiWidth; x++)
     599      {
     600        piResi[(y * uiStride) + x] = 0;
     601      }
     602  }
     603
     604#ifdef DEBUG_STRING
     605  if (psDebug)
     606    ss << (*psDebug);
     607#endif
     608
     609  //===== reconstruction =====
     610  const UInt uiRecIPredStride  = pcCU->getPic()->getPicYuvRec()->getStride(compID);
     611
     612  const Bool useCrossComponentPrediction = isChroma(compID) && (pcCU->getCrossComponentPredictionAlpha(uiAbsPartIdx, compID) != 0);
     613  const Pel* pResiLuma  = pcResiYuv->getAddr( COMPONENT_Y, uiAbsPartIdx );
     614  const Int  strideLuma = pcResiYuv->getStride( COMPONENT_Y );
     615
     616        Pel* pPred      = piPred;
     617        Pel* pResi      = piResi;
     618        Pel* pReco      = pcRecoYuv->getAddr( compID, uiAbsPartIdx );
     619        Pel* pRecIPred  = pcCU->getPic()->getPicYuvRec()->getAddr( compID, pcCU->getCtuRsAddr(), pcCU->getZorderIdxInCtu() + uiAbsPartIdx );
     620
     621
     622#ifdef DEBUG_STRING
     623  const Bool bDebugPred=((DebugOptionList::DebugString_Pred.getInt()&debugPredModeMask) && DEBUG_STRING_CHANNEL_CONDITION(compID));
     624  const Bool bDebugResi=((DebugOptionList::DebugString_Resi.getInt()&debugPredModeMask) && DEBUG_STRING_CHANNEL_CONDITION(compID));
     625  const Bool bDebugReco=((DebugOptionList::DebugString_Reco.getInt()&debugPredModeMask) && DEBUG_STRING_CHANNEL_CONDITION(compID));
     626  if (bDebugPred || bDebugResi || bDebugReco)
     627    ss << "###: " << "CompID: " << compID << " pred mode (ch/fin): " << uiChPredMode << "/" << uiChFinalMode << " absPartIdx: " << rTu.GetAbsPartIdxTU() << std::endl;
     628#endif
     629
     630#if O0043_BEST_EFFORT_DECODING
     631  const Int bitDepthDelta = g_bitDepthInStream[toChannelType(compID)] - g_bitDepth[toChannelType(compID)];
     632#endif
     633  const Int clipbd = g_bitDepth[toChannelType(compID)];
     634
     635  if( useCrossComponentPrediction )
     636  {
     637    TComTrQuant::crossComponentPrediction( rTu, compID, pResiLuma, piResi, piResi, uiWidth, uiHeight, strideLuma, uiStride, uiStride, true );
     638  }
     639
     640  for( UInt uiY = 0; uiY < uiHeight; uiY++ )
     641  {
     642#ifdef DEBUG_STRING
     643    if (bDebugPred || bDebugResi || bDebugReco) ss << "###: ";
     644
     645    if (bDebugPred)
     646    {
     647      ss << " - pred: ";
     648      for( UInt uiX = 0; uiX < uiWidth; uiX++ )
     649      {
     650        ss << pPred[ uiX ] << ", ";
     651      }
     652    }
     653    if (bDebugResi) ss << " - resi: ";
     654#endif
     655
     656    for( UInt uiX = 0; uiX < uiWidth; uiX++ )
     657    {
     658#ifdef DEBUG_STRING
     659      if (bDebugResi)
     660        ss << pResi[ uiX ] << ", ";
     661#endif
     662#if O0043_BEST_EFFORT_DECODING
     663      pReco    [ uiX ] = ClipBD( rightShiftEvenRounding<Pel>(pPred[ uiX ] + pResi[ uiX ], bitDepthDelta), clipbd );
    546664#else
    547   m_pcTrQuant->setQPforQuant  ( pcCU->getQP(0), TEXT_LUMA, pcCU->getSlice()->getSPS()->getQpBDOffsetY(), 0 );
    548 #endif
    549 
    550   Int scalingListType = (pcCU->isIntra(uiAbsPartIdx) ? 0 : 3) + g_eTTable[(Int)TEXT_LUMA];
    551     assert(scalingListType < SCALING_LIST_NUM);
    552   m_pcTrQuant->invtransformNxN( pcCU->getCUTransquantBypass(uiAbsPartIdx), TEXT_LUMA, pcCU->getLumaIntraDir( uiAbsPartIdx ), piResi, uiStride, pcCoeff, uiWidth, uiHeight, scalingListType, useTransformSkip );
    553 
    554  
    555   //===== reconstruction =====
    556   Pel* pPred      = piPred;
    557   Pel* pResi      = piResi;
    558   Pel* pReco      = piReco;
    559   Pel* pRecIPred  = piRecIPred;
    560   for( UInt uiY = 0; uiY < uiHeight; uiY++ )
    561   {
    562     for( UInt uiX = 0; uiX < uiWidth; uiX++ )
    563     {
    564       pReco    [ uiX ] = ClipY( pPred[ uiX ] + pResi[ uiX ] );
     665      pReco    [ uiX ] = ClipBD( pPred[ uiX ] + pResi[ uiX ], clipbd );
     666#endif
    565667      pRecIPred[ uiX ] = pReco[ uiX ];
    566668    }
     669#ifdef DEBUG_STRING
     670    if (bDebugReco)
     671    {
     672      ss << " - reco: ";
     673      for( UInt uiX = 0; uiX < uiWidth; uiX++ )
     674      {
     675        ss << pReco[ uiX ] << ", ";
     676      }
     677    }
     678
     679    if (bDebugPred || bDebugResi || bDebugReco)
     680      ss << "\n";
     681#endif
    567682    pPred     += uiStride;
    568683    pResi     += uiStride;
     
    570685    pRecIPred += uiRecIPredStride;
    571686  }
    572   }
    573   else
    574   {
    575     //===== reconstruction =====
    576     Pel* pPred      = piPred;
    577     Pel* pReco      = piReco;
    578     Pel* pRecIPred  = piRecIPred;
    579     for ( Int y = 0; y < uiHeight; y++ )
    580     {
    581       for ( Int x = 0; x < uiWidth; x++ )
    582       {
    583         pReco    [ x ] = pPred[ x ];
    584         pRecIPred[ x ] = pReco[ x ];
    585       }
    586       pPred     += uiStride;
    587       pReco     += uiStride;
    588       pRecIPred += uiRecIPredStride;
    589     }
    590   }
    591 }
    592 
    593 
    594 Void
    595 TDecCu::xIntraRecChromaBlk( TComDataCU* pcCU,
    596                            UInt        uiTrDepth,
    597                            UInt        uiAbsPartIdx,
    598                            TComYuv*    pcRecoYuv,
    599                            TComYuv*    pcPredYuv,
    600                            TComYuv*    pcResiYuv,
    601                            UInt        uiChromaId )
    602 {
    603   UInt uiFullDepth  = pcCU->getDepth( 0 ) + uiTrDepth;
    604   UInt uiLog2TrSize = g_aucConvertToBit[ pcCU->getSlice()->getSPS()->getMaxCUWidth() >> uiFullDepth ] + 2;
    605 
    606   if( uiLog2TrSize == 2 )
    607   {
    608     assert( uiTrDepth > 0 );
    609     uiTrDepth--;
    610     UInt uiQPDiv = pcCU->getPic()->getNumPartInCU() >> ( ( pcCU->getDepth( 0 ) + uiTrDepth ) << 1 );
    611     Bool bFirstQ = ( ( uiAbsPartIdx % uiQPDiv ) == 0 );
    612     if( !bFirstQ )
    613     {
    614       return;
    615     }
    616   }
    617  
    618   TextType  eText             = ( uiChromaId > 0 ? TEXT_CHROMA_V : TEXT_CHROMA_U );
    619   UInt      uiWidth           = pcCU     ->getWidth   ( 0 ) >> ( uiTrDepth + 1 );
    620   UInt      uiHeight          = pcCU     ->getHeight  ( 0 ) >> ( uiTrDepth + 1 );
    621   UInt      uiStride          = pcRecoYuv->getCStride ();
    622   Pel*      piReco            = ( uiChromaId > 0 ? pcRecoYuv->getCrAddr( uiAbsPartIdx ) : pcRecoYuv->getCbAddr( uiAbsPartIdx ) );
    623   Pel*      piPred            = ( uiChromaId > 0 ? pcPredYuv->getCrAddr( uiAbsPartIdx ) : pcPredYuv->getCbAddr( uiAbsPartIdx ) );
    624   Pel*      piResi            = ( uiChromaId > 0 ? pcResiYuv->getCrAddr( uiAbsPartIdx ) : pcResiYuv->getCbAddr( uiAbsPartIdx ) );
    625  
    626   UInt      uiNumCoeffInc     = ( ( pcCU->getSlice()->getSPS()->getMaxCUWidth() * pcCU->getSlice()->getSPS()->getMaxCUHeight() ) >> ( pcCU->getSlice()->getSPS()->getMaxCUDepth() << 1 ) ) >> 2;
    627   TCoeff*   pcCoeff           = ( uiChromaId > 0 ? pcCU->getCoeffCr() : pcCU->getCoeffCb() ) + ( uiNumCoeffInc * uiAbsPartIdx );
    628  
    629   UInt      uiChromaPredMode  = pcCU->getChromaIntraDir( 0 );
    630  
    631   UInt      uiZOrder          = pcCU->getZorderIdxInCU() + uiAbsPartIdx;
    632   Pel*      piRecIPred        = ( uiChromaId > 0 ? pcCU->getPic()->getPicYuvRec()->getCrAddr( pcCU->getAddr(), uiZOrder ) : pcCU->getPic()->getPicYuvRec()->getCbAddr( pcCU->getAddr(), uiZOrder ) );
    633   UInt      uiRecIPredStride  = pcCU->getPic()->getPicYuvRec()->getCStride();
    634   Bool      useTransformSkipChroma = pcCU->getTransformSkip(uiAbsPartIdx,eText);
    635   //===== init availability pattern =====
    636   Bool  bAboveAvail = false;
    637   Bool  bLeftAvail  = false;
    638   pcCU->getPattern()->initPattern         ( pcCU, uiTrDepth, uiAbsPartIdx );
    639 
    640   pcCU->getPattern()->initAdiPatternChroma( pcCU, uiAbsPartIdx, uiTrDepth,
    641                                            m_pcPrediction->getPredicBuf       (),
    642                                            m_pcPrediction->getPredicBufWidth  (),
    643                                            m_pcPrediction->getPredicBufHeight (),
    644                                            bAboveAvail, bLeftAvail );
    645   Int* pPatChroma   = ( uiChromaId > 0 ? pcCU->getPattern()->getAdiCrBuf( uiWidth, uiHeight, m_pcPrediction->getPredicBuf() ) : pcCU->getPattern()->getAdiCbBuf( uiWidth, uiHeight, m_pcPrediction->getPredicBuf() ) );
    646  
    647   //===== get prediction signal =====
    648   if( uiChromaPredMode == DM_CHROMA_IDX )
    649   {
    650     uiChromaPredMode = pcCU->getLumaIntraDir( 0 );
    651   }
    652   m_pcPrediction->predIntraChromaAng( pPatChroma, uiChromaPredMode, piPred, uiStride, uiWidth, uiHeight, bAboveAvail, bLeftAvail ); 
    653 
    654   if ( pcCU->getCbf( uiAbsPartIdx, eText, uiTrDepth ) )
    655   {
    656   //===== inverse transform =====
    657   Int curChromaQpOffset;
    658   if(eText == TEXT_CHROMA_U)
    659   {
    660     curChromaQpOffset = pcCU->getSlice()->getPPS()->getChromaCbQpOffset() + pcCU->getSlice()->getSliceQpDeltaCb();
    661   }
    662   else
    663   {
    664     curChromaQpOffset = pcCU->getSlice()->getPPS()->getChromaCrQpOffset() + pcCU->getSlice()->getSliceQpDeltaCr();
    665   }
    666 #if O0194_DIFFERENT_BITDEPTH_EL_BL
    667   // Bug-fix
    668 #if REPN_FORMAT_IN_VPS
    669   m_pcTrQuant->setQPforQuant  ( pcCU->getQP(0), eText, pcCU->getSlice()->getQpBDOffsetC(), curChromaQpOffset );
    670 #else
    671   m_pcTrQuant->setQPforQuant  ( pcCU->getQP(0), eText, pcCU->getSlice()->getSPS()->getQpBDOffsetC(), curChromaQpOffset );
    672 #endif
    673 #else
    674   m_pcTrQuant->setQPforQuant  ( pcCU->getQP(0), eText, pcCU->getSlice()->getSPS()->getQpBDOffsetC(), curChromaQpOffset );
    675 #endif
    676 
    677   Int scalingListType = (pcCU->isIntra(uiAbsPartIdx) ? 0 : 3) + g_eTTable[(Int)eText];
    678     assert(scalingListType < SCALING_LIST_NUM);
    679   m_pcTrQuant->invtransformNxN( pcCU->getCUTransquantBypass(uiAbsPartIdx), eText, REG_DCT, piResi, uiStride, pcCoeff, uiWidth, uiHeight, scalingListType, useTransformSkipChroma );
    680 
    681   //===== reconstruction =====
    682   Pel* pPred      = piPred;
    683   Pel* pResi      = piResi;
    684   Pel* pReco      = piReco;
    685   Pel* pRecIPred  = piRecIPred;
    686   for( UInt uiY = 0; uiY < uiHeight; uiY++ )
    687   {
    688     for( UInt uiX = 0; uiX < uiWidth; uiX++ )
    689     {
    690       pReco    [ uiX ] = ClipC( pPred[ uiX ] + pResi[ uiX ] );
    691       pRecIPred[ uiX ] = pReco[ uiX ];
    692     }
    693     pPred     += uiStride;
    694     pResi     += uiStride;
    695     pReco     += uiStride;
    696     pRecIPred += uiRecIPredStride;
    697   }
    698   }
    699   else
    700   {
    701     //===== reconstruction =====
    702     Pel* pPred      = piPred;
    703     Pel* pReco      = piReco;
    704     Pel* pRecIPred  = piRecIPred;
    705     for ( Int y = 0; y < uiHeight; y++ )
    706     {
    707       for ( Int x = 0; x < uiWidth; x++ )
    708       {
    709         pReco    [ x ] = pPred[ x ];
    710         pRecIPred[ x ] = pReco[ x ];
    711       }
    712       pPred     += uiStride;
    713       pReco     += uiStride;
    714       pRecIPred += uiRecIPredStride;
    715     }   
    716   }
    717687}
    718688
     
    721691TDecCu::xReconIntraQT( TComDataCU* pcCU, UInt uiDepth )
    722692{
    723   UInt  uiInitTrDepth = ( pcCU->getPartitionSize(0) == SIZE_2Nx2N ? 0 : 1 );
    724   UInt  uiNumPart     = pcCU->getNumPartitions();
    725   UInt  uiNumQParts   = pcCU->getTotalNumPart() >> 2;
    726  
    727693  if (pcCU->getIPCMFlag(0))
    728694  {
     
    730696    return;
    731697  }
    732 
    733   for( UInt uiPU = 0; uiPU < uiNumPart; uiPU++ )
    734   {
    735     xIntraLumaRecQT( pcCU, uiInitTrDepth, uiPU * uiNumQParts, m_ppcYuvReco[uiDepth], m_ppcYuvReco[uiDepth], m_ppcYuvResi[uiDepth] );
    736   } 
    737 
    738   for( UInt uiPU = 0; uiPU < uiNumPart; uiPU++ )
    739   {
    740     xIntraChromaRecQT( pcCU, uiInitTrDepth, uiPU * uiNumQParts, m_ppcYuvReco[uiDepth], m_ppcYuvReco[uiDepth], m_ppcYuvResi[uiDepth] );
    741   }
    742 
    743 }
    744 
    745 /** Function for deriving recontructed PU/CU Luma sample with QTree structure
    746  * \param pcCU pointer of current CU
    747  * \param uiTrDepth current tranform split depth
    748  * \param uiAbsPartIdx  part index
    749  * \param pcRecoYuv pointer to reconstructed sample arrays
    750  * \param pcPredYuv pointer to prediction sample arrays
    751  * \param pcResiYuv pointer to residue sample arrays
    752  *
    753  \ This function dervies recontructed PU/CU Luma sample with recursive QTree structure
    754  */
    755 Void
    756 TDecCu::xIntraLumaRecQT( TComDataCU* pcCU,
    757                      UInt        uiTrDepth,
    758                      UInt        uiAbsPartIdx,
    759                      TComYuv*    pcRecoYuv,
    760                      TComYuv*    pcPredYuv,
    761                      TComYuv*    pcResiYuv )
    762 {
    763   UInt uiFullDepth  = pcCU->getDepth(0) + uiTrDepth;
    764   UInt uiTrMode     = pcCU->getTransformIdx( uiAbsPartIdx );
    765   if( uiTrMode == uiTrDepth )
    766   {
    767     xIntraRecLumaBlk  ( pcCU, uiTrDepth, uiAbsPartIdx, pcRecoYuv, pcPredYuv, pcResiYuv );
    768   }
    769   else
    770   {
    771     UInt uiNumQPart  = pcCU->getPic()->getNumPartInCU() >> ( ( uiFullDepth + 1 ) << 1 );
    772     for( UInt uiPart = 0; uiPart < 4; uiPart++ )
    773     {
    774       xIntraLumaRecQT( pcCU, uiTrDepth + 1, uiAbsPartIdx + uiPart * uiNumQPart, pcRecoYuv, pcPredYuv, pcResiYuv );
    775     }
    776   }
    777 }
     698  const UInt numChType = pcCU->getPic()->getChromaFormat()!=CHROMA_400 ? 2 : 1;
     699  for (UInt chType=CHANNEL_TYPE_LUMA; chType<numChType; chType++)
     700  {
     701    const ChannelType chanType=ChannelType(chType);
     702    const Bool NxNPUHas4Parts = ::isChroma(chanType) ? enable4ChromaPUsInIntraNxNCU(pcCU->getPic()->getChromaFormat()) : true;
     703    const UInt uiInitTrDepth = ( pcCU->getPartitionSize(0) != SIZE_2Nx2N && NxNPUHas4Parts ? 1 : 0 );
     704
     705    TComTURecurse tuRecurseCU(pcCU, 0);
     706    TComTURecurse tuRecurseWithPU(tuRecurseCU, false, (uiInitTrDepth==0)?TComTU::DONT_SPLIT : TComTU::QUAD_SPLIT);
     707
     708    do
     709    {
     710      xIntraRecQT( m_ppcYuvReco[uiDepth], m_ppcYuvReco[uiDepth], m_ppcYuvResi[uiDepth], chanType, tuRecurseWithPU );
     711    } while (tuRecurseWithPU.nextSection(tuRecurseCU));
     712  }
     713}
     714
     715
    778716
    779717/** Function for deriving recontructed PU/CU chroma samples with QTree structure
     
    784722 * \param pcPredYuv pointer to prediction sample arrays
    785723 * \param pcResiYuv pointer to residue sample arrays
    786  * 
     724 *
    787725 \ This function dervies recontructed PU/CU chroma samples with QTree recursive structure
    788726 */
     727
    789728Void
    790 TDecCu::xIntraChromaRecQT( TComDataCU* pcCU,
    791                      UInt        uiTrDepth,
    792                      UInt        uiAbsPartIdx,
    793                      TComYuv*    pcRecoYuv,
    794                      TComYuv*    pcPredYuv,
    795                      TComYuv*    pcResiYuv )
    796 {
    797   UInt uiFullDepth  = pcCU->getDepth(0) + uiTrDepth;
     729TDecCu::xIntraRecQT(TComYuv*    pcRecoYuv,
     730                    TComYuv*    pcPredYuv,
     731                    TComYuv*    pcResiYuv,
     732                    const ChannelType chType,
     733                    TComTU     &rTu)
     734{
     735  UInt uiTrDepth    = rTu.GetTransformDepthRel();
     736  TComDataCU *pcCU  = rTu.getCU();
     737  UInt uiAbsPartIdx = rTu.GetAbsPartIdxTU();
    798738  UInt uiTrMode     = pcCU->getTransformIdx( uiAbsPartIdx );
    799739  if( uiTrMode == uiTrDepth )
    800740  {
    801     xIntraRecChromaBlk( pcCU, uiTrDepth, uiAbsPartIdx, pcRecoYuv, pcPredYuv, pcResiYuv, 0 );
    802     xIntraRecChromaBlk( pcCU, uiTrDepth, uiAbsPartIdx, pcRecoYuv, pcPredYuv, pcResiYuv, 1 );
     741    if (isLuma(chType))
     742      xIntraRecBlk( pcRecoYuv, pcPredYuv, pcResiYuv, COMPONENT_Y,  rTu );
     743    else
     744    {
     745      const UInt numValidComp=getNumberValidComponents(rTu.GetChromaFormat());
     746      for(UInt compID=COMPONENT_Cb; compID<numValidComp; compID++)
     747      {
     748        xIntraRecBlk( pcRecoYuv, pcPredYuv, pcResiYuv, ComponentID(compID), rTu );
     749      }
     750    }
    803751  }
    804752  else
    805753  {
    806     UInt uiNumQPart  = pcCU->getPic()->getNumPartInCU() >> ( ( uiFullDepth + 1 ) << 1 );
    807     for( UInt uiPart = 0; uiPart < 4; uiPart++ )
    808     {
    809       xIntraChromaRecQT( pcCU, uiTrDepth + 1, uiAbsPartIdx + uiPart * uiNumQPart, pcRecoYuv, pcPredYuv, pcResiYuv );
    810     }
     754    TComTURecurse tuRecurseChild(rTu, false);
     755    do
     756    {
     757      xIntraRecQT( pcRecoYuv, pcPredYuv, pcResiYuv, chType, tuRecurseChild );
     758    } while (tuRecurseChild.nextSection(rTu));
    811759  }
    812760}
     
    814762Void TDecCu::xCopyToPic( TComDataCU* pcCU, TComPic* pcPic, UInt uiZorderIdx, UInt uiDepth )
    815763{
    816   UInt uiCUAddr = pcCU->getAddr();
    817  
    818   m_ppcYuvReco[uiDepth]->copyToPicYuv  ( pcPic->getPicYuvRec (), uiCUAddr, uiZorderIdx );
    819  
     764  UInt uiCtuRsAddr = pcCU->getCtuRsAddr();
     765
     766  m_ppcYuvReco[uiDepth]->copyToPicYuv  ( pcPic->getPicYuvRec (), uiCtuRsAddr, uiZorderIdx );
     767
    820768  return;
    821769}
    822770
    823 Void TDecCu::xDecodeInterTexture ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
    824 {
    825   UInt    uiWidth    = pcCU->getWidth ( uiAbsPartIdx );
    826   UInt    uiHeight   = pcCU->getHeight( uiAbsPartIdx );
    827   TCoeff* piCoeff;
    828  
    829   Pel*    pResi;
    830   UInt    trMode = pcCU->getTransformIdx( uiAbsPartIdx );
    831  
    832   // Y
    833   piCoeff = pcCU->getCoeffY();
    834   pResi = m_ppcYuvResi[uiDepth]->getLumaAddr();
    835 
    836 #if REPN_FORMAT_IN_VPS
    837   m_pcTrQuant->setQPforQuant( pcCU->getQP( uiAbsPartIdx ), TEXT_LUMA, pcCU->getSlice()->getQpBDOffsetY(), 0 );
    838 #else
    839   m_pcTrQuant->setQPforQuant( pcCU->getQP( uiAbsPartIdx ), TEXT_LUMA, pcCU->getSlice()->getSPS()->getQpBDOffsetY(), 0 );
    840 #endif
    841 
    842   m_pcTrQuant->invRecurTransformNxN ( pcCU, 0, TEXT_LUMA, pResi, 0, m_ppcYuvResi[uiDepth]->getStride(), uiWidth, uiHeight, trMode, 0, piCoeff );
    843  
    844   // Cb and Cr
    845   Int curChromaQpOffset = pcCU->getSlice()->getPPS()->getChromaCbQpOffset() + pcCU->getSlice()->getSliceQpDeltaCb();
    846 #if O0194_DIFFERENT_BITDEPTH_EL_BL
    847   // Bug-fix
    848 #if REPN_FORMAT_IN_VPS
    849   m_pcTrQuant->setQPforQuant( pcCU->getQP( uiAbsPartIdx ), TEXT_CHROMA, pcCU->getSlice()->getQpBDOffsetC(), curChromaQpOffset );
    850 #else
    851   m_pcTrQuant->setQPforQuant( pcCU->getQP( uiAbsPartIdx ), TEXT_CHROMA, pcCU->getSlice()->getSPS()->getQpBDOffsetC(), curChromaQpOffset );
    852 #endif
    853 #else
    854   m_pcTrQuant->setQPforQuant( pcCU->getQP( uiAbsPartIdx ), TEXT_CHROMA, pcCU->getSlice()->getSPS()->getQpBDOffsetC(), curChromaQpOffset );
    855 #endif
    856 
    857   uiWidth  >>= 1;
    858   uiHeight >>= 1;
    859   piCoeff = pcCU->getCoeffCb(); pResi = m_ppcYuvResi[uiDepth]->getCbAddr();
    860   m_pcTrQuant->invRecurTransformNxN ( pcCU, 0, TEXT_CHROMA_U, pResi, 0, m_ppcYuvResi[uiDepth]->getCStride(), uiWidth, uiHeight, trMode, 0, piCoeff );
    861 
    862   curChromaQpOffset = pcCU->getSlice()->getPPS()->getChromaCrQpOffset() + pcCU->getSlice()->getSliceQpDeltaCr();
    863 #if O0194_DIFFERENT_BITDEPTH_EL_BL
    864   // Bug-fix
    865 #if REPN_FORMAT_IN_VPS
    866   m_pcTrQuant->setQPforQuant( pcCU->getQP( uiAbsPartIdx ), TEXT_CHROMA, pcCU->getSlice()->getQpBDOffsetC(), curChromaQpOffset );
    867 #else
    868   m_pcTrQuant->setQPforQuant( pcCU->getQP( uiAbsPartIdx ), TEXT_CHROMA, pcCU->getSlice()->getSPS()->getQpBDOffsetC(), curChromaQpOffset );
    869 #endif
    870 #else
    871   m_pcTrQuant->setQPforQuant( pcCU->getQP( uiAbsPartIdx ), TEXT_CHROMA, pcCU->getSlice()->getSPS()->getQpBDOffsetC(), curChromaQpOffset );
    872 #endif
    873 
    874   piCoeff = pcCU->getCoeffCr(); pResi = m_ppcYuvResi[uiDepth]->getCrAddr();
    875   m_pcTrQuant->invRecurTransformNxN ( pcCU, 0, TEXT_CHROMA_V, pResi, 0, m_ppcYuvResi[uiDepth]->getCStride(), uiWidth, uiHeight, trMode, 0, piCoeff );
     771Void TDecCu::xDecodeInterTexture ( TComDataCU* pcCU, UInt uiDepth )
     772{
     773
     774  TComTURecurse tuRecur(pcCU, 0, uiDepth);
     775
     776  for(UInt ch=0; ch<pcCU->getPic()->getNumberValidComponents(); ch++)
     777  {
     778    const ComponentID compID=ComponentID(ch);
     779    DEBUG_STRING_OUTPUT(std::cout, debug_reorder_data_inter_token[compID])
     780
     781    m_pcTrQuant->invRecurTransformNxN ( compID, m_ppcYuvResi[uiDepth], tuRecur );
     782  }
     783
     784  DEBUG_STRING_OUTPUT(std::cout, debug_reorder_data_inter_token[MAX_NUM_COMPONENT])
    876785}
    877786
     
    887796 * \returns Void
    888797 */
    889 Void TDecCu::xDecodePCMTexture( TComDataCU* pcCU, UInt uiPartIdx, Pel *piPCM, Pel* piReco, UInt uiStride, UInt uiWidth, UInt uiHeight, TextType ttText)
    890 {
    891   UInt uiX, uiY;
    892   Pel* piPicReco;
    893   UInt uiPicStride;
    894   UInt uiPcmLeftShiftBit;
    895 
    896   if( ttText == TEXT_LUMA )
    897   {
    898     uiPicStride   = pcCU->getPic()->getPicYuvRec()->getStride();
    899     piPicReco = pcCU->getPic()->getPicYuvRec()->getLumaAddr(pcCU->getAddr(), pcCU->getZorderIdxInCU()+uiPartIdx);
    900     uiPcmLeftShiftBit = g_bitDepthY - pcCU->getSlice()->getSPS()->getPCMBitDepthLuma();
    901   }
    902   else
    903   {
    904     uiPicStride = pcCU->getPic()->getPicYuvRec()->getCStride();
    905 
    906     if( ttText == TEXT_CHROMA_U )
    907     {
    908       piPicReco = pcCU->getPic()->getPicYuvRec()->getCbAddr(pcCU->getAddr(), pcCU->getZorderIdxInCU()+uiPartIdx);
    909     }
    910     else
    911     {
    912       piPicReco = pcCU->getPic()->getPicYuvRec()->getCrAddr(pcCU->getAddr(), pcCU->getZorderIdxInCU()+uiPartIdx);
    913     }
    914     uiPcmLeftShiftBit = g_bitDepthC - pcCU->getSlice()->getSPS()->getPCMBitDepthChroma();
    915   }
    916 
    917   for( uiY = 0; uiY < uiHeight; uiY++ )
    918   {
    919     for( uiX = 0; uiX < uiWidth; uiX++ )
     798Void TDecCu::xDecodePCMTexture( TComDataCU* pcCU, const UInt uiPartIdx, const Pel *piPCM, Pel* piReco, const UInt uiStride, const UInt uiWidth, const UInt uiHeight, const ComponentID compID)
     799{
     800        Pel* piPicReco         = pcCU->getPic()->getPicYuvRec()->getAddr(compID, pcCU->getCtuRsAddr(), pcCU->getZorderIdxInCtu()+uiPartIdx);
     801  const UInt uiPicStride       = pcCU->getPic()->getPicYuvRec()->getStride(compID);
     802  const UInt uiPcmLeftShiftBit = g_bitDepth[toChannelType(compID)] - pcCU->getSlice()->getSPS()->getPCMBitDepth(toChannelType(compID));
     803
     804  for(UInt uiY = 0; uiY < uiHeight; uiY++ )
     805  {
     806    for(UInt uiX = 0; uiX < uiWidth; uiX++ )
    920807    {
    921808      piReco[uiX] = (piPCM[uiX] << uiPcmLeftShiftBit);
     
    935822Void TDecCu::xReconPCM( TComDataCU* pcCU, UInt uiDepth )
    936823{
    937   // Luma
    938   UInt uiWidth  = (g_uiMaxCUWidth >> uiDepth);
    939   UInt uiHeight = (g_uiMaxCUHeight >> uiDepth);
    940 
    941   Pel* piPcmY = pcCU->getPCMSampleY();
    942   Pel* piRecoY = m_ppcYuvReco[uiDepth]->getLumaAddr(0, uiWidth);
    943 
    944   UInt uiStride = m_ppcYuvResi[uiDepth]->getStride();
    945 
    946   xDecodePCMTexture( pcCU, 0, piPcmY, piRecoY, uiStride, uiWidth, uiHeight, TEXT_LUMA);
    947 
    948   // Cb and Cr
    949   UInt uiCWidth  = (uiWidth>>1);
    950   UInt uiCHeight = (uiHeight>>1);
    951 
    952   Pel* piPcmCb = pcCU->getPCMSampleCb();
    953   Pel* piPcmCr = pcCU->getPCMSampleCr();
    954   Pel* pRecoCb = m_ppcYuvReco[uiDepth]->getCbAddr();
    955   Pel* pRecoCr = m_ppcYuvReco[uiDepth]->getCrAddr();
    956 
    957   UInt uiCStride = m_ppcYuvReco[uiDepth]->getCStride();
    958 
    959   xDecodePCMTexture( pcCU, 0, piPcmCb, pRecoCb, uiCStride, uiCWidth, uiCHeight, TEXT_CHROMA_U);
    960   xDecodePCMTexture( pcCU, 0, piPcmCr, pRecoCr, uiCStride, uiCWidth, uiCHeight, TEXT_CHROMA_V);
    961 }
    962 
    963 /** Function for filling the PCM buffer of a CU using its reconstructed sample array
     824  for (UInt ch=0; ch < pcCU->getPic()->getNumberValidComponents(); ch++)
     825  {
     826    const ComponentID compID = ComponentID(ch);
     827    const UInt width  = (g_uiMaxCUWidth >>(uiDepth+m_ppcYuvResi[uiDepth]->getComponentScaleX(compID)));
     828    const UInt height = (g_uiMaxCUHeight>>(uiDepth+m_ppcYuvResi[uiDepth]->getComponentScaleY(compID)));
     829    const UInt stride = m_ppcYuvResi[uiDepth]->getStride(compID);
     830    Pel * pPCMChannel = pcCU->getPCMSample(compID);
     831    Pel * pRecChannel = m_ppcYuvReco[uiDepth]->getAddr(compID);
     832    xDecodePCMTexture( pcCU, 0, pPCMChannel, pRecChannel, stride, width, height, compID );
     833  }
     834}
     835
     836/** Function for filling the PCM buffer of a CU using its reconstructed sample array
    964837 * \param pcCU pointer to current CU
    965838 * \param uiDepth CU Depth
     
    968841Void TDecCu::xFillPCMBuffer(TComDataCU* pCU, UInt depth)
    969842{
    970   // Luma
    971   UInt width  = (g_uiMaxCUWidth >> depth);
    972   UInt height = (g_uiMaxCUHeight >> depth);
    973 
    974   Pel* pPcmY = pCU->getPCMSampleY();
    975   Pel* pRecoY = m_ppcYuvReco[depth]->getLumaAddr(0, width);
    976 
    977   UInt stride = m_ppcYuvReco[depth]->getStride();
    978 
    979   for(Int y = 0; y < height; y++ )
    980   {
    981     for(Int x = 0; x < width; x++ )
    982     {
    983       pPcmY[x] = pRecoY[x];
    984     }
    985     pPcmY += width;
    986     pRecoY += stride;
    987   }
    988 
    989   // Cb and Cr
    990   UInt widthC  = (width>>1);
    991   UInt heightC = (height>>1);
    992 
    993   Pel* pPcmCb = pCU->getPCMSampleCb();
    994   Pel* pPcmCr = pCU->getPCMSampleCr();
    995   Pel* pRecoCb = m_ppcYuvReco[depth]->getCbAddr();
    996   Pel* pRecoCr = m_ppcYuvReco[depth]->getCrAddr();
    997 
    998   UInt strideC = m_ppcYuvReco[depth]->getCStride();
    999 
    1000   for(Int y = 0; y < heightC; y++ )
    1001   {
    1002     for(Int x = 0; x < widthC; x++ )
    1003     {
    1004       pPcmCb[x] = pRecoCb[x];
    1005       pPcmCr[x] = pRecoCr[x];
    1006     }
    1007     pPcmCr += widthC;
    1008     pPcmCb += widthC;
    1009     pRecoCb += strideC;
    1010     pRecoCr += strideC;
    1011   }
    1012 
     843  const ChromaFormat format = pCU->getPic()->getChromaFormat();
     844  const UInt numValidComp=getNumberValidComponents(format);
     845
     846  for (UInt componentIndex = 0; componentIndex < numValidComp; componentIndex++)
     847  {
     848    const ComponentID component = ComponentID(componentIndex);
     849
     850    const UInt width  = g_uiMaxCUWidth  >> (depth + getComponentScaleX(component, format));
     851    const UInt height = g_uiMaxCUHeight >> (depth + getComponentScaleY(component, format));
     852
     853    Pel *source      = m_ppcYuvReco[depth]->getAddr(component, 0, width);
     854    Pel *destination = pCU->getPCMSample(component);
     855
     856    const UInt sourceStride = m_ppcYuvReco[depth]->getStride(component);
     857
     858    for (Int line = 0; line < height; line++)
     859    {
     860      for (Int column = 0; column < width; column++)
     861      {
     862        destination[column] = source[column];
     863      }
     864
     865      source      += sourceStride;
     866      destination += width;
     867    }
     868  }
    1013869}
    1014870
Note: See TracChangeset for help on using the changeset viewer.