Changeset 56 in 3DVCSoftware for trunk/source/Lib/TLibEncoder/TEncEntropy.cpp


Ignore:
Timestamp:
11 May 2012, 21:20:17 (13 years ago)
Author:
hschwarz
Message:

updated trunk (move to HM6.1)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/source/Lib/TLibEncoder/TEncEntropy.cpp

    r5 r56  
    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-2011, ISO/IEC
     6 * Copyright (c) 2010-2012, ITU/ISO/IEC
    77 * All rights reserved.
    88 *
     
    1515 *    this list of conditions and the following disclaimer in the documentation
    1616 *    and/or other materials provided with the distribution.
    17  *  * Neither the name of the ISO/IEC nor the names of its contributors may
     17 *  * Neither the name of the ITU/ISO/IEC nor the names of its contributors may
    1818 *    be used to endorse or promote products derived from this software without
    1919 *    specific prior written permission.
     
    3232 */
    3333
    34 
    35 
    3634/** \file     TEncEntropy.cpp
    3735    \brief    entropy encoder class
     
    3937
    4038#include "TEncEntropy.h"
     39#include "TLibCommon/TypeDef.h"
     40#include "TLibCommon/TComAdaptiveLoopFilter.h"
     41#include "TLibCommon/TComSampleAdaptiveOffset.h"
     42
     43//! \ingroup TLibEncoder
     44//! \{
    4145
    4246Void TEncEntropy::setEntropyCoder ( TEncEntropyIf* e, TComSlice* pcSlice )
     
    4852Void TEncEntropy::encodeSliceHeader ( TComSlice* pcSlice )
    4953{
     54#if SAO_UNIT_INTERLEAVING
     55  if (pcSlice->getSPS()->getUseSAO())
     56  {
     57    pcSlice->setSaoInterleavingFlag(pcSlice->getAPS()->getSaoInterleavingFlag());
     58    pcSlice->setSaoEnabledFlag     (pcSlice->getAPS()->getSaoParam()->bSaoFlag[0]);
     59    if (pcSlice->getAPS()->getSaoInterleavingFlag())
     60    {
     61      pcSlice->setSaoEnabledFlagCb   (pcSlice->getAPS()->getSaoParam()->bSaoFlag[1]);
     62      pcSlice->setSaoEnabledFlagCr   (pcSlice->getAPS()->getSaoParam()->bSaoFlag[2]);
     63    }
     64    else
     65    {
     66      pcSlice->setSaoEnabledFlagCb   (0);
     67      pcSlice->setSaoEnabledFlagCr   (0);
     68    }
     69  }
     70#endif
     71
    5072  m_pcEntropyCoderIf->codeSliceHeader( pcSlice );
    5173  return;
    5274}
    5375
     76#if TILES_WPP_ENTRY_POINT_SIGNALLING
     77Void  TEncEntropy::encodeTilesWPPEntryPoint( TComSlice* pSlice )
     78{
     79  m_pcEntropyCoderIf->codeTilesWPPEntryPoint( pSlice );
     80}
     81#else
     82Void TEncEntropy::encodeSliceHeaderSubstreamTable( TComSlice* pcSlice )
     83{
     84  m_pcEntropyCoderIf->codeSliceHeaderSubstreamTable( pcSlice );
     85}
     86#endif
     87
    5488Void TEncEntropy::encodeTerminatingBit      ( UInt uiIsLast )
    5589{
     
    6498}
    6599
    66 void TEncEntropy::encodeSEI(const SEI& sei)
     100#if OL_FLUSH
     101Void TEncEntropy::encodeFlush()
     102{
     103  m_pcEntropyCoderIf->codeFlush();
     104}
     105Void TEncEntropy::encodeStart()
     106{
     107  m_pcEntropyCoderIf->encodeStart();
     108}
     109#endif
     110
     111Void TEncEntropy::encodeSEI(const SEI& sei)
    67112{
    68113  m_pcEntropyCoderIf->codeSEI(sei);
     
    76121}
    77122
     123#if HHI_MPI
     124Void TEncEntropy::encodeSPS( TComSPS* pcSPS, Bool bIsDepth )
     125{
     126  m_pcEntropyCoderIf->codeSPS( pcSPS, bIsDepth );
     127  return;
     128}
     129#else
    78130Void TEncEntropy::encodeSPS( TComSPS* pcSPS )
    79131{
     
    81133  return;
    82134}
     135#endif
    83136
    84137Void TEncEntropy::encodeSkipFlag( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool bRD )
     
    89142  }
    90143  if( bRD )
     144  {
    91145    uiAbsPartIdx = 0;
     146  }
     147#if BURST_IPCM
     148  if( !bRD )
     149  {
     150    if( pcCU->getLastCUSucIPCMFlag() && pcCU->getIPCMFlag(uiAbsPartIdx) )
     151    {
     152      return;
     153    }
     154  }
     155#endif
    92156  m_pcEntropyCoderIf->codeSkipFlag( pcCU, uiAbsPartIdx );
    93157}
    94158
    95 #include "../TLibCommon/TypeDef.h"
    96 #include "../TLibCommon/TComAdaptiveLoopFilter.h"
    97159Void TEncEntropy::codeFiltCountBit(ALFParam* pAlfParam, Int64* ruiRate)
    98160{
     
    117179Void TEncEntropy::codeAux(ALFParam* pAlfParam)
    118180{
    119 #if ENABLE_FORCECOEFF0
    120   if (pAlfParam->filtNo>=0) m_pcEntropyCoderIf->codeAlfFlag(1);
    121   else m_pcEntropyCoderIf->codeAlfFlag(0);
    122 #endif
    123   Int FiltTab[3] = {9, 7, 5};
    124   Int Tab = FiltTab[pAlfParam->realfiltNo];
    125181  //  m_pcEntropyCoderIf->codeAlfUvlc(pAlfParam->realfiltNo);
    126182
    127 #if MQT_BA_RA 
     183#if !LCU_SYNTAX_ALF
    128184  m_pcEntropyCoderIf->codeAlfFlag(pAlfParam->alf_pcr_region_flag);
    129185#endif
    130 
    131   m_pcEntropyCoderIf->codeAlfUvlc((Tab-5)/2);
    132  
    133   if (pAlfParam->filtNo>=0)
    134   {
    135     if(pAlfParam->realfiltNo >= 0)
    136     {
    137       // filters_per_fr
    138       m_pcEntropyCoderIf->codeAlfUvlc(pAlfParam->noFilters);
    139 
    140       if(pAlfParam->noFilters == 1)
    141       {
    142         m_pcEntropyCoderIf->codeAlfUvlc(pAlfParam->startSecondFilter);
    143       }
    144       else if (pAlfParam->noFilters == 2)
    145       {
    146         for (int i=1; i<NO_VAR_BINS; i++) m_pcEntropyCoderIf->codeAlfFlag (pAlfParam->filterPattern[i]);
    147       }
     186#if !ALF_SINGLE_FILTER_SHAPE
     187  m_pcEntropyCoderIf->codeAlfUvlc(pAlfParam->filter_shape);
     188#endif
     189  Int noFilters = min(pAlfParam->filters_per_group-1, 2);
     190  m_pcEntropyCoderIf->codeAlfUvlc(noFilters);
     191
     192  if(noFilters == 1)
     193  {
     194    m_pcEntropyCoderIf->codeAlfUvlc(pAlfParam->startSecondFilter);
     195  }
     196  else if (noFilters == 2)
     197  {
     198#if LCU_SYNTAX_ALF
     199#if ALF_16_BA_GROUPS
     200    Int numMergeFlags = 16;
     201#else
     202    Int numMergeFlags = 15;
     203#endif
     204#else
     205#if ALF_16_BA_GROUPS
     206    Int numMergeFlags = 16;
     207#else
     208    Int numMergeFlags = pAlfParam->alf_pcr_region_flag ? 16 : 15;
     209#endif
     210#endif
     211    for (Int i=1; i<numMergeFlags; i++)
     212    {
     213      m_pcEntropyCoderIf->codeAlfFlag (pAlfParam->filterPattern[i]);
    148214    }
    149215  }
     
    155221  int q = coeffVal / m;
    156222  if(coeffVal != 0)
     223  {
    157224    return(q + 2 + k);
     225  }
    158226  else
     227  {
    159228    return(q + 1 + k);
     229  }
    160230}
    161231
    162232Int TEncEntropy::codeFilterCoeff(ALFParam* ALFp)
    163233{
    164   int filters_per_group = ALFp->filters_per_group_diff;
     234  Int filters_per_group = ALFp->filters_per_group;
    165235  int sqrFiltLength = ALFp->num_coeff;
    166   int filtNo = ALFp->realfiltNo;
    167   int flTab[]={9/2, 7/2, 5/2};
    168   int fl = flTab[filtNo];
    169236  int i, k, kMin, kStart, minBits, ind, scanPos, maxScanVal, coeffVal, len = 0,
    170   *pDepthInt=NULL, kMinTab[MAX_SQR_FILT_LENGTH], bitsCoeffScan[MAX_SCAN_VAL][MAX_EXP_GOLOMB],
    171   minKStart, minBitsKStart, bitsKStart;
    172  
    173   pDepthInt = pDepthIntTab[fl-2];
    174  
     237    *pDepthInt=NULL, kMinTab[MAX_SCAN_VAL], bitsCoeffScan[MAX_SCAN_VAL][MAX_EXP_GOLOMB],
     238    minKStart, minBitsKStart, bitsKStart;
     239 
     240  pDepthInt = pDepthIntTabShapes[ALFp->filter_shape];
    175241  maxScanVal = 0;
     242#if ALF_SINGLE_FILTER_SHAPE
     243  int minScanVal = MIN_SCAN_POS_CROSS;
     244#else
     245  int minScanVal = ( ALFp->filter_shape==ALF_STAR5x5 ) ? 0 : MIN_SCAN_POS_CROSS;
     246#endif
     247
    176248  for(i = 0; i < sqrFiltLength; i++)
     249  {
    177250    maxScanVal = max(maxScanVal, pDepthInt[i]);
     251  }
    178252 
    179253  // vlc for all
     
    198272    bitsKStart = 0;
    199273    kStart = k;
    200     for(scanPos = 0; scanPos < maxScanVal; scanPos++)
     274    for(scanPos = minScanVal; scanPos < maxScanVal; scanPos++)
    201275    {
    202276      kMin = kStart;
     
    219293 
    220294  kStart = minKStart;
    221   for(scanPos = 0; scanPos < maxScanVal; scanPos++)
     295  for(scanPos = minScanVal; scanPos < maxScanVal; scanPos++)
    222296  {
    223297    kMin = kStart;
     
    236310  // Coding parameters
    237311  ALFp->minKStart = minKStart;
     312#if !LCU_SYNTAX_ALF 
    238313  ALFp->maxScanVal = maxScanVal;
    239   for(scanPos = 0; scanPos < maxScanVal; scanPos++)
     314#endif
     315  for(scanPos = minScanVal; scanPos < maxScanVal; scanPos++)
    240316  {
    241317    ALFp->kMinTab[scanPos] = kMinTab[scanPos];
    242318  }
    243   len += writeFilterCodingParams(minKStart, maxScanVal, kMinTab);
    244  
     319
     320#if LCU_SYNTAX_ALF
     321  if (ALFp->filters_per_group == 1)
     322  {
     323    len += writeFilterCoeffs(sqrFiltLength, filters_per_group, pDepthInt, ALFp->coeffmulti, kTableTabShapes[ALF_CROSS9x7_SQUARE3x3]);
     324  }
     325  else
     326  {
     327#endif
     328  len += writeFilterCodingParams(minKStart, minScanVal, maxScanVal, kMinTab);
     329
    245330  // Filter coefficients
    246331  len += writeFilterCoeffs(sqrFiltLength, filters_per_group, pDepthInt, ALFp->coeffmulti, kMinTab);
     332#if LCU_SYNTAX_ALF
     333  }
     334#endif
    247335 
    248336  return len;
    249337}
    250338
    251 Int TEncEntropy::writeFilterCodingParams(int minKStart, int maxScanVal, int kMinTab[])
     339Int TEncEntropy::writeFilterCodingParams(int minKStart, int minScanVal, int maxScanVal, int kMinTab[])
    252340{
    253341  int scanPos;
    254342  int golombIndexBit;
    255343  int kMin;
    256  
     344
    257345  // Golomb parameters
    258346  m_pcEntropyCoderIf->codeAlfUvlc(minKStart - 1);
    259347 
    260348  kMin = minKStart;
    261   for(scanPos = 0; scanPos < maxScanVal; scanPos++)
     349  for(scanPos = minScanVal; scanPos < maxScanVal; scanPos++)
    262350  {
    263351    golombIndexBit = (kMinTab[scanPos] != kMin)? 1: 0;
     
    282370    {
    283371      scanPos = pDepthInt[i] - 1;
     372#if LCU_SYNTAX_ALF
     373      Int k = (filters_per_group == 1) ? kMinTab[i] : kMinTab[scanPos];
     374      golombEncode(FilterCoeff[ind][i], k);
     375#else
    284376      golombEncode(FilterCoeff[ind][i], kMinTab[scanPos]);
     377#endif
    285378    }
    286379  }
     
    290383Int TEncEntropy::golombEncode(int coeff, int k)
    291384{
    292   int q, i, m;
     385  int q, i;
    293386  int symbol = abs(coeff);
    294387 
    295   m = (int)pow(2.0, k);
    296   q = symbol / m;
     388  q = symbol >> k;
    297389 
    298390  for (i = 0; i < q; i++)
     391  {
    299392    m_pcEntropyCoderIf->codeAlfFlag(1);
     393  }
    300394  m_pcEntropyCoderIf->codeAlfFlag(0);
    301395  // write one zero
     
    319413  if(pAlfParam->filters_per_group > 1)
    320414  {
    321 #if ENABLE_FORCECOEFF0
    322     m_pcEntropyCoderIf->codeAlfFlag (pAlfParam->forceCoeff0);
    323     if (pAlfParam->forceCoeff0)
    324     {
    325       for (int i=0; i<pAlfParam->filters_per_group; i++) m_pcEntropyCoderIf->codeAlfFlag (pAlfParam->codedVarBins[i]);
    326     }
    327 #endif
    328415    m_pcEntropyCoderIf->codeAlfFlag (pAlfParam->predMethod);
    329416  }
     417  for(Int ind = 0; ind < pAlfParam->filters_per_group; ++ind)
     418  {
     419    m_pcEntropyCoderIf->codeAlfFlag (pAlfParam->nbSPred[ind]);
     420  }
    330421  codeFilterCoeff (pAlfParam);
    331 }
    332 
    333 Void  print(ALFParam* pAlfParam)
    334 {
    335   Int i=0;
    336   Int ind=0;
    337   Int FiltLengthTab[] = {22, 14, 8}; //0:9tap
    338   Int FiltLength = FiltLengthTab[pAlfParam->realfiltNo];
    339  
    340   printf("set of params\n");
    341   printf("realfiltNo:%d\n", pAlfParam->realfiltNo);
    342   printf("filtNo:%d\n", pAlfParam->filtNo);
    343   printf("filterPattern:");
    344   for (i=0; i<NO_VAR_BINS; i++) printf("%d ", pAlfParam->filterPattern[i]);
    345   printf("\n");
    346  
    347   printf("startSecondFilter:%d\n", pAlfParam->startSecondFilter);
    348   printf("noFilters:%d\n", pAlfParam->noFilters);
    349   printf("varIndTab:");
    350   for (i=0; i<NO_VAR_BINS; i++) printf("%d ", pAlfParam->varIndTab[i]);
    351   printf("\n");
    352   printf("filters_per_group_diff:%d\n", pAlfParam->filters_per_group_diff);
    353   printf("filters_per_group:%d\n", pAlfParam->filters_per_group);
    354   printf("codedVarBins:");
    355   for (i=0; i<NO_VAR_BINS; i++) printf("%d ", pAlfParam->codedVarBins[i]);
    356   printf("\n");
    357   printf("forceCoeff0:%d\n", pAlfParam->forceCoeff0);
    358   printf("predMethod:%d\n", pAlfParam->predMethod);
    359  
    360   for (ind=0; ind<pAlfParam->filters_per_group_diff; ind++)
    361   {
    362     printf("coeffmulti(%d):", ind);
    363     for (i=0; i<FiltLength; i++) printf("%d ", pAlfParam->coeffmulti[ind][i]);
    364     printf("\n");
    365   }
    366  
    367   printf("minKStart:%d\n", pAlfParam->minKStart); 
    368   printf("maxScanVal:%d\n", pAlfParam->maxScanVal); 
    369   printf("kMinTab:");
    370   for(Int scanPos = 0; scanPos < pAlfParam->maxScanVal; scanPos++)
    371   {
    372     printf("%d ", pAlfParam->kMinTab[scanPos]);
    373   }
    374   printf("\n");
    375  
    376   printf("chroma_idc:%d\n", pAlfParam->chroma_idc); 
    377   printf("tap_chroma:%d\n", pAlfParam->tap_chroma); 
    378   printf("chroma_coeff:");
    379   for(Int scanPos = 0; scanPos < pAlfParam->num_coeff_chroma; scanPos++)
    380   {
    381     printf("%d ", pAlfParam->coeff_chroma[scanPos]);
    382   }
    383   printf("\n");
    384422}
    385423
     
    392430Void TEncEntropy::encodeMergeFlag( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiPUIdx )
    393431{
    394   UInt uiNumCand = 0;
    395   for(UInt uiIter = 0; uiIter < MRG_MAX_NUM_CANDS; uiIter++ )
    396   {
    397     if( pcCU->getNeighbourCandIdx( uiIter, uiAbsPartIdx ) == uiIter + 1 )
    398     {
    399       uiNumCand++;
    400       break;
    401     }
    402   }
    403   if ( uiNumCand )
    404   {
    405     // at least one merge candidate exists
    406     m_pcEntropyCoderIf->codeMergeFlag( pcCU, uiAbsPartIdx );
    407   }
    408   else
    409   {
    410     assert( !pcCU->getMergeFlag( uiAbsPartIdx ) );
    411   }
    412 }
    413 
    414 #if HHI_MRG_SKIP
     432  // at least one merge candidate exists
     433  m_pcEntropyCoderIf->codeMergeFlag( pcCU, uiAbsPartIdx );
     434}
     435
    415436/** encode merge index
    416437 * \param pcCU
     
    421442 */
    422443Void TEncEntropy::encodeMergeIndex( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiPUIdx, Bool bRD )
    423 #else
    424 Void TEncEntropy::encodeMergeIndex( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiPUIdx )
    425 #endif
    426 {
    427 #if HHI_MRG_SKIP
     444{
    428445  if( bRD )
    429446  {
     
    431448    assert( pcCU->getPartitionSize(uiAbsPartIdx) == SIZE_2Nx2N );
    432449  }
    433 #endif
    434 
    435   UInt uiNumCand = 0;
    436   for(UInt uiIter = 0; uiIter < MRG_MAX_NUM_CANDS; uiIter++ )
    437   {
    438     if( pcCU->getNeighbourCandIdx( uiIter, uiAbsPartIdx ) == uiIter + 1 )
    439     {
    440       uiNumCand++;
    441     }
    442   }
    443 #if HHI_MPI
    444   if( pcCU->getSlice()->getSPS()->getUseMVI() && pcCU->getSlice()->getSliceType() != I_SLICE && pcCU->getPartitionSize( uiAbsPartIdx ) == SIZE_2Nx2N )
    445     uiNumCand++;
    446 #endif
     450
     451  UInt uiNumCand = MRG_MAX_NUM_CANDS;
    447452  if ( uiNumCand > 1 )
    448453  {
     
    451456}
    452457
    453 
    454458#if HHI_INTER_VIEW_RESIDUAL_PRED
    455 Void 
     459Void
    456460TEncEntropy::encodeResPredFlag( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiPUIdx, Bool bRD )
    457461{
     
    473477#endif
    474478
     479#if LCU_SYNTAX_ALF
     480/** parse the fixed length code (smaller than one max value) in ALF
     481 * \param run: coded value
     482 * \param rx: cur addr
     483 * \param numLCUInWidth: # of LCU in one LCU
     484 * \returns Void
     485 */
     486Void TEncEntropy::encodeAlfFixedLengthRun(UInt run, UInt rx, UInt numLCUInWidth)
     487{
     488  assert(numLCUInWidth > rx);
     489  UInt maxValue = numLCUInWidth - rx - 1;
     490  m_pcEntropyCoderIf->codeAlfFixedLengthIdx(run, maxValue);
     491}
     492
     493/** parse the fixed length code (smaller than one max value) in ALF
     494 * \param idx: coded value
     495 * \param numFilterSetsInBuffer: max value
     496 * \returns Void
     497 */
     498Void TEncEntropy::encodeAlfStoredFilterSetIdx(UInt idx, UInt numFilterSetsInBuffer)
     499{
     500  assert(numFilterSetsInBuffer > 0);
     501  UInt maxValue = numFilterSetsInBuffer - 1;
     502  m_pcEntropyCoderIf->codeAlfFixedLengthIdx(idx, maxValue);
     503}
     504
     505Void TEncEntropy::encodeAlfParam(AlfParamSet* pAlfParamSet, Bool bSentInAPS, Int firstLCUAddr, Bool alfAcrossSlice)
     506{
     507  Bool isEnabled[NUM_ALF_COMPONENT];
     508  Bool isUniParam[NUM_ALF_COMPONENT];
     509
     510  isEnabled[ALF_Y] = true;
     511  isEnabled[ALF_Cb]= pAlfParamSet->isEnabled[ALF_Cb];
     512  isEnabled[ALF_Cr]= pAlfParamSet->isEnabled[ALF_Cr];
     513
     514  isUniParam[ALF_Y]= pAlfParamSet->isUniParam[ALF_Y];
     515  isUniParam[ALF_Cb]= pAlfParamSet->isUniParam[ALF_Cb];
     516  isUniParam[ALF_Cr]= pAlfParamSet->isUniParam[ALF_Cr];
     517
     518
     519  //alf_cb_enable_flag
     520  m_pcEntropyCoderIf->codeAlfFlag(isEnabled[ALF_Cb]?1:0);
     521  //alf_cr_enable_flag
     522  m_pcEntropyCoderIf->codeAlfFlag(isEnabled[ALF_Cr]?1:0); 
     523
     524  for(Int compIdx = 0; compIdx< NUM_ALF_COMPONENT; compIdx++)
     525  {
     526    if(isEnabled[compIdx])
     527    {
     528      //alf_one_{luma, cb, cr}_unit_per_slice_flag
     529      m_pcEntropyCoderIf->codeAlfFlag(isUniParam[compIdx]?1:0);
     530    }
     531  }
     532  if(bSentInAPS)
     533  {
     534    //alf_num_lcu_in_width_minus1
     535    m_pcEntropyCoderIf->codeAlfUvlc(pAlfParamSet->numLCUInWidth-1);
     536    //alf_num_lcu_in_height_minus1
     537    m_pcEntropyCoderIf->codeAlfUvlc(pAlfParamSet->numLCUInHeight-1);
     538  }
     539  else //sent in slice header
     540  {
     541    //alf_num_lcu_in_slice_minus1
     542    m_pcEntropyCoderIf->codeAlfUvlc(pAlfParamSet->numLCU-1);
     543  }
     544
     545
     546  encodeAlfParamSet(pAlfParamSet, pAlfParamSet->numLCUInWidth, pAlfParamSet->numLCU, firstLCUAddr, alfAcrossSlice, 0, (Int)NUM_ALF_COMPONENT-1);
     547
     548}
     549
     550Bool TEncEntropy::getAlfRepeatRowFlag(Int compIdx, AlfParamSet* pAlfParamSet
     551                                    , Int lcuIdxInSlice, Int lcuPos
     552                                    , Int startlcuPosX, Int endlcuPosX
     553                                    , Int numLCUInWidth
     554                                    )
     555{
     556  assert(startlcuPosX == 0); //only the beginning of one LCU row needs to send repeat_row_flag
     557 
     558  Int len = endlcuPosX - startlcuPosX +1;
     559  Bool isRepeatRow = true;
     560  Int curPos;
     561
     562  for(Int i= 0; i < len; i++)
     563  {
     564    curPos = lcuIdxInSlice +i;
     565    AlfUnitParam& alfUnitParam = pAlfParamSet->alfUnitParam[compIdx][curPos];
     566    AlfUnitParam& alfUpUnitParam = pAlfParamSet->alfUnitParam[compIdx][curPos-numLCUInWidth];
     567
     568    if ( !(alfUnitParam == alfUpUnitParam) )
     569    {
     570      isRepeatRow = false;
     571      break;
     572    }
     573  }
     574
     575  return isRepeatRow;
     576}
     577
     578
     579Int TEncEntropy::getAlfRun(Int compIdx, AlfParamSet* pAlfParamSet
     580                          , Int lcuIdxInSlice, Int lcuPos
     581                          , Int startlcuPosX, Int endlcuPosX
     582                          )
     583{
     584  Int alfRun = 0;
     585  Int len = endlcuPosX - startlcuPosX +1;
     586  AlfUnitParam& alfLeftUnitParam = pAlfParamSet->alfUnitParam[compIdx][lcuIdxInSlice];
     587
     588
     589
     590  for(Int i= 1; i < len; i++)
     591  {
     592    AlfUnitParam& alfUnitParam = pAlfParamSet->alfUnitParam[compIdx][lcuIdxInSlice+ i];
     593
     594    if (alfUnitParam == alfLeftUnitParam)
     595    {
     596      alfRun++;
     597    }
     598    else
     599    {
     600      break;
     601    }
     602  }
     603
     604  return alfRun;
     605
     606}
     607
     608
     609
     610Void TEncEntropy::encodeAlfParamSet(AlfParamSet* pAlfParamSet, Int numLCUInWidth, Int numLCU, Int firstLCUAddr, Bool alfAcrossSlice, Int startCompIdx, Int endCompIdx)
     611{
     612  Int endLCUY       = (numLCU -1 + firstLCUAddr)/numLCUInWidth;
     613  Int endLCUX       = (numLCU -1 + firstLCUAddr)%numLCUInWidth;
     614
     615  static Bool isRepeatedRow   [NUM_ALF_COMPONENT];
     616  static Int  numStoredFilters[NUM_ALF_COMPONENT];
     617  static Int* run             [NUM_ALF_COMPONENT];
     618
     619  for(Int compIdx =startCompIdx; compIdx <= endCompIdx; compIdx++)
     620  {
     621    isRepeatedRow[compIdx]    = false;
     622    numStoredFilters[compIdx] = 0;
     623
     624    run[compIdx] = new Int[numLCU+1];
     625    run[compIdx][0] = -1;
     626  }
     627
     628  Int  ry, rx, addrUp, endrX, lcuPos;
     629
     630  for(Int i=0; i< numLCU; i++)
     631  {
     632    lcuPos= firstLCUAddr+ i;
     633    rx    = lcuPos% numLCUInWidth;
     634    ry    = lcuPos/ numLCUInWidth;
     635    endrX = ( ry == endLCUY)?( endLCUX ):(numLCUInWidth-1);
     636
     637    for(Int compIdx =startCompIdx; compIdx <= endCompIdx; compIdx++)
     638    {
     639      AlfUnitParam& alfUnitParam = pAlfParamSet->alfUnitParam[compIdx][i];
     640      if(pAlfParamSet->isEnabled[compIdx])
     641      {
     642        if(!pAlfParamSet->isUniParam[compIdx])
     643        {
     644          addrUp = i-numLCUInWidth;
     645          if(rx ==0 && addrUp >=0)
     646          {
     647            isRepeatedRow[compIdx] = getAlfRepeatRowFlag(compIdx, pAlfParamSet, i, lcuPos, rx, endrX, numLCUInWidth);
     648
     649            //alf_repeat_row_flag
     650            m_pcEntropyCoderIf->codeAlfFlag(isRepeatedRow[compIdx]?1:0);
     651          }
     652
     653          if(isRepeatedRow[compIdx])
     654          {
     655            assert(addrUp >=0);
     656            run[compIdx][i] = run[compIdx][addrUp];
     657          }
     658          else
     659          {
     660            if(rx == 0 || run[compIdx][i] < 0)
     661            {             
     662              run[compIdx][i] = getAlfRun(compIdx, pAlfParamSet, i, lcuPos, rx, endrX);
     663
     664              if(addrUp < 0)
     665              {
     666                //alf_run_diff u(v)
     667                encodeAlfFixedLengthRun(run[compIdx][i], rx, numLCUInWidth);               
     668              }
     669              else
     670              {
     671                //alf_run_diff s(v)
     672                m_pcEntropyCoderIf->codeAlfSvlc(run[compIdx][i]- run[compIdx][addrUp]);
     673
     674              }
     675
     676              if(ry > 0 && (addrUp >=0 || alfAcrossSlice))
     677              {
     678                //alf_merge_up_flag
     679                m_pcEntropyCoderIf->codeAlfFlag(  (alfUnitParam.mergeType == ALF_MERGE_UP)?1:0   ); 
     680              }
     681
     682              if(alfUnitParam.mergeType != ALF_MERGE_UP)
     683              {
     684                assert(alfUnitParam.mergeType == ALF_MERGE_DISABLED);
     685
     686                //alf_lcu_enable_flag
     687                m_pcEntropyCoderIf->codeAlfFlag(alfUnitParam.isEnabled ? 1 : 0);
     688
     689                if(alfUnitParam.isEnabled)
     690                {
     691                  if(numStoredFilters[compIdx] > 0)
     692                  {
     693                    //alf_new_filter_set_flag
     694                    m_pcEntropyCoderIf->codeAlfFlag(alfUnitParam.isNewFilt ? 1:0);
     695
     696                    if(!alfUnitParam.isNewFilt)
     697                    {
     698                      //alf_stored_filter_set_idx
     699                      encodeAlfStoredFilterSetIdx(alfUnitParam.storedFiltIdx, numStoredFilters[compIdx]);
     700
     701                    }
     702                  }
     703                  else
     704                  {
     705                    assert(alfUnitParam.isNewFilt);
     706                  }
     707
     708                  if(alfUnitParam.isNewFilt)
     709                  {
     710                    assert(alfUnitParam.alfFiltParam->alf_flag == 1);
     711                    encodeAlfParam(alfUnitParam.alfFiltParam);
     712                    numStoredFilters[compIdx]++;
     713                  }
     714                }
     715
     716              }
     717            }
     718
     719            run[compIdx][i+1] = run[compIdx][i] -1;
     720          }
     721
     722        }
     723        else // uni-param
     724        {
     725          if(i == 0)
     726          {
     727            //alf_lcu_enable_flag
     728            m_pcEntropyCoderIf->codeAlfFlag(alfUnitParam.isEnabled?1:0);
     729            if(alfUnitParam.isEnabled)
     730            {
     731              encodeAlfParam(alfUnitParam.alfFiltParam);
     732            }
     733          }
     734        }
     735      } // component enabled/disable
     736    } //comp
     737
     738  }
     739
     740  for(Int compIdx =startCompIdx; compIdx <= endCompIdx; compIdx++)
     741  {
     742    delete[] run[compIdx];
     743  }
     744
     745}
     746#endif
     747
    475748
    476749Void TEncEntropy::encodeAlfParam(ALFParam* pAlfParam)
    477750{
    478   m_pcEntropyCoderIf->codeAlfFlag(pAlfParam->alf_flag);
     751#if LCU_SYNTAX_ALF
     752  const Int numCoeff = (Int)ALF_MAX_NUM_COEF;
     753
     754  switch(pAlfParam->componentID)
     755  {
     756  case ALF_Cb:
     757  case ALF_Cr:
     758    {
     759      for(Int pos=0; pos< numCoeff; pos++)
     760      {
     761        m_pcEntropyCoderIf->codeAlfSvlc(  pAlfParam->coeffmulti[0][pos]);
     762
     763      }
     764    }
     765    break;
     766  case ALF_Y:
     767    {
     768      codeAux(pAlfParam);
     769      codeFilt(pAlfParam);
     770    }
     771    break;
     772  default:
     773    {
     774      printf("Not a legal component ID\n");
     775      assert(0);
     776      exit(-1);
     777    }
     778  }
     779#else
    479780  if (!pAlfParam->alf_flag)
     781  {
    480782    return;
     783  }
    481784  Int pos;
    482785  codeAux(pAlfParam);
     
    487790  if(pAlfParam->chroma_idc)
    488791  {
    489     m_pcEntropyCoderIf->codeAlfUvlc((pAlfParam->tap_chroma-5)/2);
    490    
     792#if !ALF_SINGLE_FILTER_SHAPE
     793    m_pcEntropyCoderIf->codeAlfUvlc(pAlfParam->filter_shape_chroma);
     794#endif
    491795    // filter coefficients for chroma
    492796    for(pos=0; pos<pAlfParam->num_coeff_chroma; pos++)
     
    495799    }
    496800  }
    497  
     801#endif
     802}
     803
     804Void TEncEntropy::encodeAlfCtrlFlag( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool bRD )
     805{
     806  if( bRD )
     807  {
     808    uiAbsPartIdx = 0;
     809  }
     810  m_pcEntropyCoderIf->codeAlfCtrlFlag( pcCU, uiAbsPartIdx );
     811}
     812
     813
     814/** Encode ALF CU control flag
     815 * \param uiFlag ALF CU control flag: 0 or 1
     816 */
     817Void TEncEntropy::encodeAlfCtrlFlag(UInt uiFlag)
     818{
     819  assert(uiFlag == 0 || uiFlag == 1);
     820  m_pcEntropyCoderIf->codeAlfCtrlFlag( uiFlag );
     821}
     822
     823
     824/** Encode ALF CU control flag parameters
     825 * \param pAlfParam ALF parameters
     826 */
     827Void TEncEntropy::encodeAlfCtrlParam(AlfCUCtrlInfo& cAlfParam, Int iNumCUsInPic)
     828{
    498829  // region control parameters for luma
    499   m_pcEntropyCoderIf->codeAlfFlag(pAlfParam->cu_control_flag);
    500   if (pAlfParam->cu_control_flag)
    501   {
    502     assert( (pAlfParam->cu_control_flag && m_pcEntropyCoderIf->getAlfCtrl()) || (!pAlfParam->cu_control_flag && !m_pcEntropyCoderIf->getAlfCtrl()));
    503     m_pcEntropyCoderIf->codeAlfCtrlDepth();
    504   }
    505 }
    506 
    507 Void TEncEntropy::encodeAlfCtrlFlag( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool bRD )
    508 {
    509   if( bRD )
    510     uiAbsPartIdx = 0;
    511  
    512   m_pcEntropyCoderIf->codeAlfCtrlFlag( pcCU, uiAbsPartIdx );
    513 }
    514 
    515 #if TSB_ALF_HEADER
    516 Void TEncEntropy::encodeAlfCtrlParam( ALFParam* pAlfParam )
    517 {
    518   m_pcEntropyCoderIf->codeAlfFlagNum( pAlfParam->num_alf_cu_flag, pAlfParam->num_cus_in_frame );
    519  
    520   for(UInt i=0; i<pAlfParam->num_alf_cu_flag; i++)
    521   {
    522     m_pcEntropyCoderIf->codeAlfCtrlFlag( pAlfParam->alf_cu_flag[i] );
    523   }
    524 }
    525 #endif
     830  m_pcEntropyCoderIf->codeAlfFlag(cAlfParam.cu_control_flag);
     831
     832  if (cAlfParam.cu_control_flag == 0)
     833  {
     834    return;
     835  }
     836
     837  m_pcEntropyCoderIf->codeAlfCtrlDepth();
     838
     839  Int iSymbol    = ((Int)cAlfParam.num_alf_cu_flag - iNumCUsInPic);
     840  m_pcEntropyCoderIf->codeAlfSvlc(iSymbol);
     841
     842  for(UInt i=0; i< cAlfParam.num_alf_cu_flag; i++)
     843  {
     844    m_pcEntropyCoderIf->codeAlfCtrlFlag( cAlfParam.alf_cu_flag[i] );
     845  }
     846}
    526847
    527848/** encode prediction mode
     
    534855{
    535856  if( bRD )
     857  {
    536858    uiAbsPartIdx = 0;
    537  
     859  }
     860#if BURST_IPCM
     861  if( !bRD )
     862  {
     863    if( pcCU->getLastCUSucIPCMFlag() && pcCU->getIPCMFlag(uiAbsPartIdx) )
     864    {
     865      return;
     866    }
     867  }
     868#endif
     869
    538870  if ( pcCU->getSlice()->isIntra() )
    539871  {
    540872    return;
    541873  }
    542  
     874
    543875  m_pcEntropyCoderIf->codePredMode( pcCU, uiAbsPartIdx );
    544876}
     
    548880{
    549881  if( bRD )
     882  {
    550883    uiAbsPartIdx = 0;
    551  
     884  }
     885#if BURST_IPCM
     886  if( !bRD )
     887  {
     888    if( pcCU->getLastCUSucIPCMFlag() && pcCU->getIPCMFlag(uiAbsPartIdx) )
     889    {
     890      return;
     891    }
     892  }
     893#endif
     894
    552895  m_pcEntropyCoderIf->codeSplitFlag( pcCU, uiAbsPartIdx, uiDepth );
    553896}
     
    563906{
    564907  if( bRD )
     908  {
    565909    uiAbsPartIdx = 0;
    566  
     910  }
     911#if BURST_IPCM
     912  if( !bRD )
     913  {
     914    if( pcCU->getLastCUSucIPCMFlag() && pcCU->getIPCMFlag(uiAbsPartIdx) )
     915    {
     916      return;
     917    }
     918  }
     919#endif 
    567920  m_pcEntropyCoderIf->codePartSize( pcCU, uiAbsPartIdx, uiDepth );
    568921}
    569922
    570 Void TEncEntropy::xEncodeTransformSubdiv( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, UInt uiInnerQuadIdx, UInt& uiYCbfFront3, UInt& uiUCbfFront3, UInt& uiVCbfFront3 )
     923/** Encode I_PCM information.
     924 * \param pcCU pointer to CU
     925 * \param uiAbsPartIdx CU index
     926 * \param bRD flag indicating estimation or encoding
     927 * \returns Void
     928 */
     929Void TEncEntropy::encodeIPCMInfo( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool bRD )
     930{
     931  if(!pcCU->getSlice()->getSPS()->getUsePCM()
     932    || pcCU->getWidth(uiAbsPartIdx) > (1<<pcCU->getSlice()->getSPS()->getPCMLog2MaxSize())
     933    || pcCU->getWidth(uiAbsPartIdx) < (1<<pcCU->getSlice()->getSPS()->getPCMLog2MinSize()))
     934  {
     935    return;
     936  }
     937 
     938  if( bRD )
     939  {
     940    uiAbsPartIdx = 0;
     941  }
     942 
     943#if BURST_IPCM
     944  Int numIPCM = 0;
     945  Bool firstIPCMFlag = false;
     946
     947  if( pcCU->getIPCMFlag(uiAbsPartIdx) )
     948  {
     949    numIPCM = 1;
     950    firstIPCMFlag = true;
     951
     952    if( !bRD )
     953    {
     954      numIPCM = pcCU->getNumSucIPCM();
     955      firstIPCMFlag = !pcCU->getLastCUSucIPCMFlag();
     956    }
     957  }
     958  m_pcEntropyCoderIf->codeIPCMInfo ( pcCU, uiAbsPartIdx, numIPCM, firstIPCMFlag);
     959#else
     960  m_pcEntropyCoderIf->codeIPCMInfo ( pcCU, uiAbsPartIdx );
     961#endif
     962
     963}
     964
     965#if UNIFIED_TRANSFORM_TREE
     966Void TEncEntropy::xEncodeTransform( TComDataCU* pcCU,UInt offsetLuma, UInt offsetChroma, UInt uiAbsPartIdx, UInt absTUPartIdx, UInt uiDepth, UInt width, UInt height, UInt uiTrIdx, UInt uiInnerQuadIdx, UInt& uiYCbfFront3, UInt& uiUCbfFront3, UInt& uiVCbfFront3, Bool& bCodeDQP )
     967#else
     968Void TEncEntropy::xEncodeTransformSubdiv( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt absTUPartIdx, UInt uiDepth, UInt uiInnerQuadIdx, UInt& uiYCbfFront3, UInt& uiUCbfFront3, UInt& uiVCbfFront3 )
     969#endif
    571970{
    572971  const UInt uiSubdiv = pcCU->getTransformIdx( uiAbsPartIdx ) + pcCU->getDepth( uiAbsPartIdx ) > uiDepth;
    573972  const UInt uiLog2TrafoSize = g_aucConvertToBit[pcCU->getSlice()->getSPS()->getMaxCUWidth()]+2 - uiDepth;
    574 #if CAVLC_RQT_CBP
    575   if(pcCU->getSlice()->getSymbolMode() == 0)
    576   {
    577     m_pcEntropyCoderIf->codeCbfTrdiv( pcCU, uiAbsPartIdx, uiDepth );
    578   }
    579   else
     973#if UNIFIED_TRANSFORM_TREE
     974  UInt cbfY = pcCU->getCbf( uiAbsPartIdx, TEXT_LUMA    , uiTrIdx );
     975  UInt cbfU = pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_U, uiTrIdx );
     976  UInt cbfV = pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_V, uiTrIdx );
     977
     978  if(uiTrIdx==0)
     979  {
     980    m_bakAbsPartIdxCU = uiAbsPartIdx;
     981  }
     982  if( uiLog2TrafoSize == 2 )
     983  {
     984    UInt partNum = pcCU->getPic()->getNumPartInCU() >> ( ( uiDepth - 1 ) << 1 );
     985    if( ( uiAbsPartIdx % partNum ) == 0 )
     986    {
     987      m_uiBakAbsPartIdx   = uiAbsPartIdx;
     988      m_uiBakChromaOffset = offsetChroma;
     989    }
     990    else if( ( uiAbsPartIdx % partNum ) == (partNum - 1) )
     991    {
     992      cbfU = pcCU->getCbf( m_uiBakAbsPartIdx, TEXT_CHROMA_U, uiTrIdx );
     993      cbfV = pcCU->getCbf( m_uiBakAbsPartIdx, TEXT_CHROMA_V, uiTrIdx );
     994    }
     995  }
     996#endif // UNIFIED_TRANSFORM_TREE
    580997  {//CABAC
    581 #endif
    582   if( pcCU->getPredictionMode(uiAbsPartIdx) == MODE_INTRA && pcCU->getPartitionSize(uiAbsPartIdx) == SIZE_NxN && uiDepth == pcCU->getDepth(uiAbsPartIdx) )
    583   {
    584     assert( uiSubdiv );
    585   }
    586   else
    587     if( uiLog2TrafoSize > pcCU->getSlice()->getSPS()->getQuadtreeTULog2MaxSize() )
     998    if( pcCU->getPredictionMode(uiAbsPartIdx) == MODE_INTRA && pcCU->getPartitionSize(uiAbsPartIdx) == SIZE_NxN && uiDepth == pcCU->getDepth(uiAbsPartIdx) )
    588999    {
    5891000      assert( uiSubdiv );
    5901001    }
     1002    else if( pcCU->getPredictionMode(uiAbsPartIdx) == MODE_INTER && (pcCU->getPartitionSize(uiAbsPartIdx) != SIZE_2Nx2N) && uiDepth == pcCU->getDepth(uiAbsPartIdx) &&  (pcCU->getSlice()->getSPS()->getQuadtreeTUMaxDepthInter() == 1) )
     1003    {
     1004      if ( uiLog2TrafoSize > pcCU->getQuadtreeTULog2MinSizeInCU(uiAbsPartIdx) )
     1005      {
     1006        assert( uiSubdiv );
     1007      }
     1008      else
     1009      {
     1010        assert(!uiSubdiv );
     1011      }
     1012    }
     1013    else if( uiLog2TrafoSize > pcCU->getSlice()->getSPS()->getQuadtreeTULog2MaxSize() )
     1014    {
     1015      assert( uiSubdiv );
     1016    }
    5911017    else if( uiLog2TrafoSize == pcCU->getSlice()->getSPS()->getQuadtreeTULog2MinSize() )
    5921018    {
     
    6001026    {
    6011027      assert( uiLog2TrafoSize > pcCU->getQuadtreeTULog2MinSizeInCU(uiAbsPartIdx) );
    602 #if HHI_RQT_FORCE_SPLIT_ACC2_PU
    603       UInt uiCtx = uiDepth;
    604       const UInt uiTrMode = uiDepth - pcCU->getDepth( uiAbsPartIdx );
    605 #if HHI_RQT_FORCE_SPLIT_NxN
    606       const Bool bNxNOK         = pcCU->getPartitionSize( uiAbsPartIdx ) == SIZE_NxN && uiTrMode > 0;
    607 #else
    608       const Bool bNxNOK         = pcCU->getPartitionSize( uiAbsPartIdx ) == SIZE_NxN;
    609 #endif
    610 #if HHI_RQT_FORCE_SPLIT_RECT
    611       const Bool bSymmetricOK   = pcCU->getPartitionSize( uiAbsPartIdx ) >= SIZE_2NxN  && pcCU->getPartitionSize( uiAbsPartIdx ) < SIZE_NxN   && uiTrMode > 0;
    612 #else
    613       const Bool bSymmetricOK   = pcCU->getPartitionSize( uiAbsPartIdx ) >= SIZE_2NxN  && pcCU->getPartitionSize( uiAbsPartIdx ) < SIZE_NxN;
    614 #endif
    615       const Bool bNeedSubdivFlag = pcCU->getPartitionSize( uiAbsPartIdx ) == SIZE_2Nx2N || pcCU->getPredictionMode( uiAbsPartIdx ) == MODE_INTRA ||
    616       bNxNOK || bSymmetricOK;
    617       if( bNeedSubdivFlag )
    618       {
    619         m_pcEntropyCoderIf->codeTransformSubdivFlag( uiSubdiv, uiCtx );
    620       }
    621 #else
    6221028      m_pcEntropyCoderIf->codeTransformSubdivFlag( uiSubdiv, uiDepth );
    623 #endif
    624     }
    625 #if CAVLC_RQT_CBP
    626   }
    627 #endif
    628  
    629   if(pcCU->getSlice()->getSymbolMode() == 0)
    630   {
    631     if( uiSubdiv )
    632     {
    633       ++uiDepth;
    634       const UInt uiQPartNum = pcCU->getPic()->getNumPartInCU() >> (uiDepth << 1);
    635       UInt uiDummyCbfY = 0;
    636       UInt uiDummyCbfU = 0;
    637       UInt uiDummyCbfV = 0;
    638       xEncodeTransformSubdiv( pcCU, uiAbsPartIdx, uiDepth, 0, uiDummyCbfY, uiDummyCbfU, uiDummyCbfV );
    639       uiAbsPartIdx += uiQPartNum;
    640       xEncodeTransformSubdiv( pcCU, uiAbsPartIdx, uiDepth, 1, uiDummyCbfY, uiDummyCbfU, uiDummyCbfV );
    641       uiAbsPartIdx += uiQPartNum;
    642       xEncodeTransformSubdiv( pcCU, uiAbsPartIdx, uiDepth, 2, uiDummyCbfY, uiDummyCbfU, uiDummyCbfV );
    643       uiAbsPartIdx += uiQPartNum;
    644       xEncodeTransformSubdiv( pcCU, uiAbsPartIdx, uiDepth, 3, uiDummyCbfY, uiDummyCbfU, uiDummyCbfV );
    645     }
    646   }
    647   else
    648   {
    649     if( pcCU->getPredictionMode(uiAbsPartIdx) != MODE_INTRA && uiLog2TrafoSize <= pcCU->getSlice()->getSPS()->getQuadtreeTULog2MaxSize() )
     1029    }
     1030  }
     1031
     1032  {
     1033    if( uiLog2TrafoSize <= pcCU->getSlice()->getSPS()->getQuadtreeTULog2MaxSize() )
    6501034    {
    6511035      const UInt uiTrDepthCurr = uiDepth - pcCU->getDepth( uiAbsPartIdx );
    6521036      const Bool bFirstCbfOfCU = uiLog2TrafoSize == pcCU->getSlice()->getSPS()->getQuadtreeTULog2MaxSize() || uiTrDepthCurr == 0;
    653       if( bFirstCbfOfCU || uiLog2TrafoSize > pcCU->getSlice()->getSPS()->getQuadtreeTULog2MinSize() )
     1037      if( bFirstCbfOfCU || uiLog2TrafoSize > 2 )
    6541038      {
    6551039        if( bFirstCbfOfCU || pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_U, uiTrDepthCurr - 1 ) )
     
    6781062        }
    6791063      }
    680       else if( uiLog2TrafoSize == pcCU->getSlice()->getSPS()->getQuadtreeTULog2MinSize() )
     1064      else if( uiLog2TrafoSize == 2 )
    6811065      {
    6821066        assert( pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_U, uiTrDepthCurr ) == pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_U, uiTrDepthCurr - 1 ) );
     
    6901074    if( uiSubdiv )
    6911075    {
     1076#if UNIFIED_TRANSFORM_TREE
     1077      UInt size;
     1078      width  >>= 1;
     1079      height >>= 1;
     1080      size = width*height;
     1081      uiTrIdx++;
     1082#endif // UNIFIED_TRANSFORM_TREE
    6921083      ++uiDepth;
     1084#if UNIFIED_TRANSFORM_TREE
     1085      const UInt partNum = pcCU->getPic()->getNumPartInCU() >> (uiDepth << 1);
     1086#else
    6931087      const UInt uiQPartNum = pcCU->getPic()->getNumPartInCU() >> (uiDepth << 1);
     1088#endif
    6941089     
    6951090      UInt uiCurrentCbfY = 0;
     
    6971092      UInt uiCurrentCbfV = 0;
    6981093     
    699       xEncodeTransformSubdiv( pcCU, uiAbsPartIdx, uiDepth, 0, uiCurrentCbfY, uiCurrentCbfU, uiCurrentCbfV );
     1094#if UNIFIED_TRANSFORM_TREE
     1095      UInt nsAddr = 0;
     1096      nsAddr = pcCU->getNSAbsPartIdx( uiLog2TrafoSize-1, uiAbsPartIdx, absTUPartIdx, 0, uiDepth - pcCU->getDepth( uiAbsPartIdx ) );
     1097      xEncodeTransform( pcCU, offsetLuma, offsetChroma, uiAbsPartIdx, nsAddr, uiDepth, width, height, uiTrIdx, 0, uiCurrentCbfY, uiCurrentCbfU, uiCurrentCbfV, bCodeDQP );
     1098
     1099      uiAbsPartIdx += partNum;  offsetLuma += size;  offsetChroma += (size>>2);
     1100      nsAddr = pcCU->getNSAbsPartIdx( uiLog2TrafoSize-1, uiAbsPartIdx, absTUPartIdx, 1, uiDepth - pcCU->getDepth( uiAbsPartIdx ) );
     1101      xEncodeTransform( pcCU, offsetLuma, offsetChroma, uiAbsPartIdx, nsAddr, uiDepth, width, height, uiTrIdx, 1, uiCurrentCbfY, uiCurrentCbfU, uiCurrentCbfV, bCodeDQP );
     1102
     1103      uiAbsPartIdx += partNum;  offsetLuma += size;  offsetChroma += (size>>2);
     1104      nsAddr = pcCU->getNSAbsPartIdx( uiLog2TrafoSize-1, uiAbsPartIdx, absTUPartIdx, 2, uiDepth - pcCU->getDepth( uiAbsPartIdx ) );
     1105      xEncodeTransform( pcCU, offsetLuma, offsetChroma, uiAbsPartIdx, nsAddr, uiDepth, width, height, uiTrIdx, 2, uiCurrentCbfY, uiCurrentCbfU, uiCurrentCbfV, bCodeDQP );
     1106
     1107      uiAbsPartIdx += partNum;  offsetLuma += size;  offsetChroma += (size>>2);
     1108      nsAddr = pcCU->getNSAbsPartIdx( uiLog2TrafoSize-1, uiAbsPartIdx, absTUPartIdx, 3, uiDepth - pcCU->getDepth( uiAbsPartIdx ) );
     1109      xEncodeTransform( pcCU, offsetLuma, offsetChroma, uiAbsPartIdx, nsAddr, uiDepth, width, height, uiTrIdx, 3, uiCurrentCbfY, uiCurrentCbfU, uiCurrentCbfV, bCodeDQP );     
     1110#else // UNIFIED_TRANSFORM_TREE
     1111      UInt nsAddr = 0;
     1112      nsAddr = pcCU->getNSAbsPartIdx( uiLog2TrafoSize-1, uiAbsPartIdx, absTUPartIdx, 0, uiDepth - pcCU->getDepth( uiAbsPartIdx ) );
     1113      xEncodeTransformSubdiv( pcCU, uiAbsPartIdx, nsAddr, uiDepth, 0, uiCurrentCbfY, uiCurrentCbfU, uiCurrentCbfV );
     1114
    7001115      uiAbsPartIdx += uiQPartNum;
    701       xEncodeTransformSubdiv( pcCU, uiAbsPartIdx, uiDepth, 1, uiCurrentCbfY, uiCurrentCbfU, uiCurrentCbfV );
     1116      nsAddr = pcCU->getNSAbsPartIdx( uiLog2TrafoSize-1, uiAbsPartIdx, absTUPartIdx, 1, uiDepth - pcCU->getDepth( uiAbsPartIdx ) );
     1117      xEncodeTransformSubdiv( pcCU, uiAbsPartIdx, nsAddr, uiDepth, 1, uiCurrentCbfY, uiCurrentCbfU, uiCurrentCbfV );
     1118
    7021119      uiAbsPartIdx += uiQPartNum;
    703       xEncodeTransformSubdiv( pcCU, uiAbsPartIdx, uiDepth, 2, uiCurrentCbfY, uiCurrentCbfU, uiCurrentCbfV );
     1120      nsAddr = pcCU->getNSAbsPartIdx( uiLog2TrafoSize-1, uiAbsPartIdx, absTUPartIdx, 2, uiDepth - pcCU->getDepth( uiAbsPartIdx ) );
     1121      xEncodeTransformSubdiv( pcCU, uiAbsPartIdx, nsAddr, uiDepth, 2, uiCurrentCbfY, uiCurrentCbfU, uiCurrentCbfV );
     1122
    7041123      uiAbsPartIdx += uiQPartNum;
    705       xEncodeTransformSubdiv( pcCU, uiAbsPartIdx, uiDepth, 3, uiCurrentCbfY, uiCurrentCbfU, uiCurrentCbfV );
     1124      nsAddr = pcCU->getNSAbsPartIdx( uiLog2TrafoSize-1, uiAbsPartIdx, absTUPartIdx, 3, uiDepth - pcCU->getDepth( uiAbsPartIdx ) );
     1125      xEncodeTransformSubdiv( pcCU, uiAbsPartIdx, nsAddr, uiDepth, 3, uiCurrentCbfY, uiCurrentCbfU, uiCurrentCbfV );
     1126#endif // UNIFIED_TRANSFORM_TREE
    7061127     
    7071128      uiYCbfFront3 += uiCurrentCbfY;
     
    7121133    {
    7131134      {
    714         DTRACE_CABAC_V( g_nSymbolCounter++ );
     1135        DTRACE_CABAC_VL( g_nSymbolCounter++ );
    7151136        DTRACE_CABAC_T( "\tTrIdx: abspart=" );
    7161137        DTRACE_CABAC_V( uiAbsPartIdx );
     
    7231144      UInt uiLumaTrMode, uiChromaTrMode;
    7241145      pcCU->convertTransIdx( uiAbsPartIdx, pcCU->getTransformIdx( uiAbsPartIdx ), uiLumaTrMode, uiChromaTrMode );
     1146      if(pcCU->getPredictionMode( uiAbsPartIdx ) == MODE_INTER && pcCU->useNonSquarePU( uiAbsPartIdx ) )
     1147      {
     1148        pcCU->setNSQTIdxSubParts( uiLog2TrafoSize, uiAbsPartIdx, absTUPartIdx, uiLumaTrMode );
     1149      }
    7251150      if( pcCU->getPredictionMode(uiAbsPartIdx) != MODE_INTRA && uiDepth == pcCU->getDepth( uiAbsPartIdx ) && !pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_U, 0 ) && !pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_V, 0 ) )
    7261151      {
     
    7301155      else
    7311156      {
     1157        const UInt uiLog2CUSize = g_aucConvertToBit[pcCU->getSlice()->getSPS()->getMaxCUWidth()] + 2 - pcCU->getDepth( uiAbsPartIdx );
    7321158        if ( pcCU->getPredictionMode( uiAbsPartIdx ) != MODE_INTRA && uiInnerQuadIdx == 3 && uiYCbfFront3 == 0 && uiUCbfFront3 == 0 && uiVCbfFront3 == 0
    733             && uiLog2TrafoSize < pcCU->getSlice()->getSPS()->getQuadtreeTULog2MaxSize() && pcCU->getCbf( uiAbsPartIdx, TEXT_LUMA, uiLumaTrMode ) )
     1159            && ( uiLog2CUSize <= pcCU->getSlice()->getSPS()->getQuadtreeTULog2MaxSize() + 1 || uiLog2TrafoSize < pcCU->getSlice()->getSPS()->getQuadtreeTULog2MaxSize() ) )
    7341160        {     
    7351161          uiYCbfFront3++;
     
    7421168      }
    7431169     
    744       if( pcCU->getPredictionMode(uiAbsPartIdx) == MODE_INTRA )
    745       {
    746         Bool bCodeChroma = true;
    747         if( uiLog2TrafoSize == pcCU->getSlice()->getSPS()->getQuadtreeTULog2MinSize() )
     1170#if UNIFIED_TRANSFORM_TREE
     1171      if ( cbfY || cbfU || cbfV )
     1172      {
     1173        // dQP: only for LCU once
     1174        if ( pcCU->getSlice()->getPPS()->getUseDQP() )
    7481175        {
    749           UInt uiQPDiv = pcCU->getPic()->getNumPartInCU() >> ( ( uiDepth - 1 ) << 1 );
    750           bCodeChroma  = ( ( uiAbsPartIdx % uiQPDiv ) == 0 );
     1176          if ( bCodeDQP )
     1177          {
     1178            encodeQP( pcCU, m_bakAbsPartIdxCU );
     1179            bCodeDQP = false;
     1180          }
    7511181        }
    752         if( bCodeChroma )
     1182      }
     1183      if( cbfY )
     1184      {
     1185        Int trWidth = width;
     1186        Int trHeight = height;
     1187        pcCU->getNSQTSize( uiTrIdx, uiAbsPartIdx, trWidth, trHeight );
     1188        m_pcEntropyCoderIf->codeCoeffNxN( pcCU, (pcCU->getCoeffY()+offsetLuma), uiAbsPartIdx, trWidth, trHeight, uiDepth, TEXT_LUMA );
     1189      }
     1190      if( uiLog2TrafoSize > 2 )
     1191      {
     1192        Int trWidth = width >> 1;
     1193        Int trHeight = height >> 1;
     1194        pcCU->getNSQTSize( uiTrIdx, uiAbsPartIdx, trWidth, trHeight );
     1195        if( cbfU )
    7531196        {
    754           m_pcEntropyCoderIf->codeQtCbf( pcCU, uiAbsPartIdx, TEXT_CHROMA_U, uiChromaTrMode );
    755           m_pcEntropyCoderIf->codeQtCbf( pcCU, uiAbsPartIdx, TEXT_CHROMA_V, uiChromaTrMode );
     1197          m_pcEntropyCoderIf->codeCoeffNxN( pcCU, (pcCU->getCoeffCb()+offsetChroma), uiAbsPartIdx, trWidth, trHeight, uiDepth, TEXT_CHROMA_U );
    7561198        }
    757       }
    758     }
    759   }
    760 }
    761 
     1199        if( cbfV )
     1200        {
     1201          m_pcEntropyCoderIf->codeCoeffNxN( pcCU, (pcCU->getCoeffCr()+offsetChroma), uiAbsPartIdx, trWidth, trHeight, uiDepth, TEXT_CHROMA_V );
     1202        }
     1203      }
     1204      else
     1205      {
     1206        UInt partNum = pcCU->getPic()->getNumPartInCU() >> ( ( uiDepth - 1 ) << 1 );
     1207        if( ( uiAbsPartIdx % partNum ) == (partNum - 1) )
     1208        {
     1209          Int trWidth = width;
     1210          Int trHeight = height;
     1211          pcCU->getNSQTSize( uiTrIdx - 1, uiAbsPartIdx, trWidth, trHeight );
     1212          if( cbfU )
     1213          {
     1214            m_pcEntropyCoderIf->codeCoeffNxN( pcCU, (pcCU->getCoeffCb()+m_uiBakChromaOffset), m_uiBakAbsPartIdx, trWidth, trHeight, uiDepth, TEXT_CHROMA_U );
     1215          }
     1216          if( cbfV )
     1217          {
     1218            m_pcEntropyCoderIf->codeCoeffNxN( pcCU, (pcCU->getCoeffCr()+m_uiBakChromaOffset), m_uiBakAbsPartIdx, trWidth, trHeight, uiDepth, TEXT_CHROMA_V );
     1219          }
     1220        }
     1221      }
     1222#endif // UNIFIED_TRANSFORM_TREE
     1223    }
     1224  }
     1225}
     1226
     1227#if !UNIFIED_TRANSFORM_TREE
    7621228// transform index
    7631229Void TEncEntropy::encodeTransformIdx( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, Bool bRD )
     
    7651231  assert( !bRD ); // parameter bRD can be removed
    7661232  if( bRD )
     1233  {
    7671234    uiAbsPartIdx = 0;
    768  
    769   DTRACE_CABAC_V( g_nSymbolCounter++ )
     1235  }
     1236 
     1237  DTRACE_CABAC_VL( g_nSymbolCounter++ )
    7701238  DTRACE_CABAC_T( "\tdecodeTransformIdx()\tCUDepth=" )
    7711239  DTRACE_CABAC_V( uiDepth )
     
    7741242  UInt temp1 = 0;
    7751243  UInt temp2 = 0;
    776   xEncodeTransformSubdiv( pcCU, uiAbsPartIdx, uiDepth, 0, temp, temp1, temp2 );
    777 }
     1244  xEncodeTransformSubdiv( pcCU, uiAbsPartIdx, uiAbsPartIdx, uiDepth, 0, temp, temp1, temp2 );
     1245}
     1246#endif // !UNIFIED_TRANSFORM_TREE
    7781247
    7791248// Intra direction for Luma
     
    7871256{
    7881257  if( bRD )
     1258  {
    7891259    uiAbsPartIdx = 0;
     1260  }
    7901261 
    7911262  m_pcEntropyCoderIf->codeIntraDirChroma( pcCU, uiAbsPartIdx );
     
    7951266{
    7961267  if( bRD )
     1268  {
    7971269    uiAbsPartIdx = 0;
     1270  }
    7981271 
    7991272  PartSize eSize = pcCU->getPartitionSize( uiAbsPartIdx );
     
    8191292  else                                                                // if it is Inter mode, encode motion vector and reference index
    8201293  {
    821     if ( pcCU->getSlice()->getSPS()->getUseMRG() )
    822     {
    823       encodePUWise( pcCU, uiAbsPartIdx, bRD );
    824     }
    825     else
    826     {
    827 #if MS_LCEC_LOOKUP_TABLE_EXCEPTION
    828       if ( pcCU->getSlice()->getSymbolMode() == 0 )
    829       {
    830         if ( pcCU->isSuroundingRefIdxException( uiAbsPartIdx ) )
    831         {
    832           pcCU->getSlice()->setRefIdxCombineCoding( false );
    833         }
    834         else
    835         {
    836           pcCU->getSlice()->setRefIdxCombineCoding( true );
    837         }
    838       }
    839 #endif
    840       encodeInterDir( pcCU, uiAbsPartIdx, bRD );
    841      
    842       {
    843         if ( pcCU->getSlice()->getNumRefIdx( REF_PIC_LIST_0 ) > 0 )       // if ( ref. frame list0 has at least 1 entry )
    844         {
    845           encodeRefFrmIdx ( pcCU, uiAbsPartIdx, REF_PIC_LIST_0, bRD );
    846           encodeMvd       ( pcCU, uiAbsPartIdx, REF_PIC_LIST_0, bRD );
    847           encodeMVPIdx    ( pcCU, uiAbsPartIdx, REF_PIC_LIST_0      );
    848         }
    849        
    850         if ( pcCU->getSlice()->getNumRefIdx( REF_PIC_LIST_1 ) > 0 )       // if ( ref. frame list1 has at least 1 entry )
    851         {
    852           encodeRefFrmIdx ( pcCU, uiAbsPartIdx, REF_PIC_LIST_1, bRD );
    853           encodeMvd       ( pcCU, uiAbsPartIdx, REF_PIC_LIST_1, bRD );
    854           encodeMVPIdx    ( pcCU, uiAbsPartIdx, REF_PIC_LIST_1      );
    855         }
    856       }
    857     }
    858   }
    859 }
    860 
    861 /** encode inter direction
    862  * \param pcCU
    863  * \param uiAbsPartIdx
    864  * \param bRD
    865  * \returns Void
    866  */
    867 Void TEncEntropy::encodeInterDir( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool bRD )
    868 {
    869   assert( !pcCU->isIntra( uiAbsPartIdx ) );
    870   assert( pcCU->getSlice()->isInterB());
    871 
    872   if( bRD )
    873     uiAbsPartIdx = 0;
    874  
    875   if ( !pcCU->getSlice()->isInterB() )
    876   {
    877     return;
    878   }
    879  
    880   UInt uiPartOffset = ( pcCU->getPic()->getNumPartInCU() >> ( pcCU->getDepth(uiAbsPartIdx) << 1 ) ) >> 2;
    881  
    882   switch ( pcCU->getPartitionSize( uiAbsPartIdx ) )
    883   {
    884     case SIZE_2Nx2N:
    885     {
    886       m_pcEntropyCoderIf->codeInterDir( pcCU, uiAbsPartIdx );
    887       break;
    888     }
    889      
    890     case SIZE_2NxN:
    891     {
    892       m_pcEntropyCoderIf->codeInterDir( pcCU, uiAbsPartIdx );
    893       uiAbsPartIdx += uiPartOffset << 1;
    894       m_pcEntropyCoderIf->codeInterDir( pcCU, uiAbsPartIdx );
    895       break;
    896     }
    897      
    898     case SIZE_Nx2N:
    899     {
    900       m_pcEntropyCoderIf->codeInterDir( pcCU, uiAbsPartIdx );
    901       uiAbsPartIdx += uiPartOffset;
    902       m_pcEntropyCoderIf->codeInterDir( pcCU, uiAbsPartIdx );
    903       break;
    904     }
    905      
    906     case SIZE_NxN:
    907     {
    908       for ( Int iPartIdx = 0; iPartIdx < 4; iPartIdx++ )
    909       {
    910         m_pcEntropyCoderIf->codeInterDir( pcCU, uiAbsPartIdx );
    911         uiAbsPartIdx += uiPartOffset;
    912       }
    913       break;
    914     }
    915     default:
    916       break;
    917   }
    918  
    919   return;
     1294    encodePUWise( pcCU, uiAbsPartIdx, bRD );
     1295  }
    9201296}
    9211297
     
    9251301 * \param bRD
    9261302 * \returns Void
    927  * This function is called only if merge is enabled.
    9281303 */
    9291304Void TEncEntropy::encodePUWise( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool bRD )
    9301305{
    9311306  if ( bRD )
     1307  {
    9321308    uiAbsPartIdx = 0;
    933 
     1309  }
     1310 
    9341311  PartSize ePartSize = pcCU->getPartitionSize( uiAbsPartIdx );
    9351312  UInt uiNumPU = ( ePartSize == SIZE_2Nx2N ? 1 : ( ePartSize == SIZE_NxN ? 4 : 2 ) );
     
    9391316  for ( UInt uiPartIdx = 0, uiSubPartIdx = uiAbsPartIdx; uiPartIdx < uiNumPU; uiPartIdx++, uiSubPartIdx += uiPUOffset )
    9401317  {
    941 #if PART_MRG
    942     if (pcCU->getWidth( uiAbsPartIdx ) <= 8 || uiNumPU != 2 || uiPartIdx != 0)
    943 #endif
    9441318    encodeMergeFlag( pcCU, uiSubPartIdx, uiPartIdx );
    9451319    if ( pcCU->getMergeFlag( uiSubPartIdx ) )
     
    9491323    else
    9501324    {
    951 #if MS_LCEC_LOOKUP_TABLE_EXCEPTION
    952       if ( pcCU->getSlice()->getSymbolMode() == 0 )
    953       {
    954         if ( pcCU->isSuroundingRefIdxException( uiAbsPartIdx ) )
    955         {
    956           pcCU->getSlice()->setRefIdxCombineCoding( false );
    957         }
    958         else
    959         {
    960           pcCU->getSlice()->setRefIdxCombineCoding( true );
    961         }
    962       }
    963 #endif
    9641325      encodeInterDirPU( pcCU, uiSubPartIdx );
    9651326      for ( UInt uiRefListIdx = 0; uiRefListIdx < 2; uiRefListIdx++ )
     
    9991360  assert( !pcCU->isIntra( uiAbsPartIdx ) );
    10001361
    1001 #if DCM_COMB_LIST
    10021362  if(pcCU->getSlice()->getNumRefIdx(REF_PIC_LIST_C)>0 && pcCU->getInterDir( uiAbsPartIdx ) != 3)
    10031363  {
     
    10151375  else
    10161376  {
    1017 #endif
    1018 
    1019   if ( ( pcCU->getSlice()->getNumRefIdx( eRefList ) == 1 ) )
    1020   {
    1021     return;
    1022   }
    1023 
    1024   if ( pcCU->getInterDir( uiAbsPartIdx ) & ( 1 << eRefList ) )
    1025   {
    1026     m_pcEntropyCoderIf->codeRefFrmIdx( pcCU, uiAbsPartIdx, eRefList );
    1027   }
    1028 
    1029 #if DCM_COMB_LIST
    1030   }
    1031 #endif
     1377    if ( ( pcCU->getSlice()->getNumRefIdx( eRefList ) == 1 ) )
     1378    {
     1379      return;
     1380    }
     1381
     1382    if ( pcCU->getInterDir( uiAbsPartIdx ) & ( 1 << eRefList ) )
     1383    {
     1384      m_pcEntropyCoderIf->codeRefFrmIdx( pcCU, uiAbsPartIdx, eRefList );
     1385    }
     1386  }
    10321387
    10331388  return;
     
    10531408Void TEncEntropy::encodeMVPIdxPU( TComDataCU* pcCU, UInt uiAbsPartIdx, RefPicList eRefList )
    10541409{
    1055   if ( (pcCU->getInterDir( uiAbsPartIdx ) & ( 1 << eRefList )) && (pcCU->getMVPNum(eRefList, uiAbsPartIdx)> 1) && (pcCU->getAMVPMode(uiAbsPartIdx) == AM_EXPL) )
    1056   {
     1410  if ( (pcCU->getInterDir( uiAbsPartIdx ) & ( 1 << eRefList )) && (pcCU->getAMVPMode(uiAbsPartIdx) == AM_EXPL) )
     1411  {
     1412#if HHI_INTER_VIEW_MOTION_PRED
     1413    const Int iNumCands = AMVP_MAX_NUM_CANDS + ( pcCU->getSlice()->getSPS()->getMultiviewMvPredMode() ? 1 : 0 );
     1414    m_pcEntropyCoderIf->codeMVPIdx( pcCU, uiAbsPartIdx, eRefList, iNumCands );
     1415#else
    10571416    m_pcEntropyCoderIf->codeMVPIdx( pcCU, uiAbsPartIdx, eRefList );
     1417#endif
    10581418  }
    10591419
    10601420  return;
    10611421}
    1062 
    1063 Void TEncEntropy::encodeMVPIdx( TComDataCU* pcCU, UInt uiAbsPartIdx, RefPicList eRefList, Bool bRD )
    1064 {
    1065   if( bRD )
    1066     uiAbsPartIdx = 0;
    1067  
    1068   UInt uiPartOffset = ( pcCU->getPic()->getNumPartInCU() >> ( pcCU->getDepth(uiAbsPartIdx) << 1 ) ) >> 2;
    1069  
    1070   switch ( pcCU->getPartitionSize( uiAbsPartIdx ) )
    1071   {
    1072     case SIZE_2Nx2N:
    1073     {
    1074       if ( (pcCU->getInterDir( uiAbsPartIdx ) & ( 1 << eRefList )) && (pcCU->getMVPNum(eRefList, uiAbsPartIdx)> 1) && (pcCU->getAMVPMode(uiAbsPartIdx) == AM_EXPL) )
    1075       {
    1076         m_pcEntropyCoderIf->codeMVPIdx( pcCU, uiAbsPartIdx, eRefList );
    1077       }
    1078       break;
    1079     }
    1080      
    1081     case SIZE_2NxN:
    1082     {
    1083       if ( (pcCU->getInterDir( uiAbsPartIdx ) & ( 1 << eRefList )) && (pcCU->getMVPNum(eRefList, uiAbsPartIdx)> 1) && (pcCU->getAMVPMode(uiAbsPartIdx) == AM_EXPL) )
    1084       {
    1085         m_pcEntropyCoderIf->codeMVPIdx( pcCU, uiAbsPartIdx, eRefList );
    1086       }
    1087       uiAbsPartIdx += uiPartOffset << 1;
    1088       if ( (pcCU->getInterDir( uiAbsPartIdx ) & ( 1 << eRefList )) && (pcCU->getMVPNum(eRefList, uiAbsPartIdx)> 1) && (pcCU->getAMVPMode(uiAbsPartIdx) == AM_EXPL) )
    1089       {
    1090         m_pcEntropyCoderIf->codeMVPIdx( pcCU, uiAbsPartIdx, eRefList );
    1091       }
    1092       break;
    1093     }
    1094      
    1095     case SIZE_Nx2N:
    1096     {
    1097       if ( (pcCU->getInterDir( uiAbsPartIdx ) & ( 1 << eRefList )) && (pcCU->getMVPNum(eRefList, uiAbsPartIdx)> 1) && (pcCU->getAMVPMode(uiAbsPartIdx) == AM_EXPL) )
    1098       {
    1099         m_pcEntropyCoderIf->codeMVPIdx( pcCU, uiAbsPartIdx, eRefList );
    1100       }
    1101      
    1102       uiAbsPartIdx += uiPartOffset;
    1103       if ( (pcCU->getInterDir( uiAbsPartIdx ) & ( 1 << eRefList )) && (pcCU->getMVPNum(eRefList, uiAbsPartIdx)> 1) && (pcCU->getAMVPMode(uiAbsPartIdx) == AM_EXPL) )
    1104       {
    1105         m_pcEntropyCoderIf->codeMVPIdx( pcCU, uiAbsPartIdx, eRefList );
    1106       }
    1107      
    1108       break;
    1109     }
    1110      
    1111     case SIZE_NxN:
    1112     {
    1113       for ( Int iPartIdx = 0; iPartIdx < 4; iPartIdx++ )
    1114       {
    1115         if ( (pcCU->getInterDir( uiAbsPartIdx ) & ( 1 << eRefList )) && (pcCU->getMVPNum(eRefList, uiAbsPartIdx)> 1) && (pcCU->getAMVPMode(uiAbsPartIdx) == AM_EXPL) )
    1116         {
    1117           m_pcEntropyCoderIf->codeMVPIdx( pcCU, uiAbsPartIdx, eRefList );
    1118         }
    1119         uiAbsPartIdx += uiPartOffset;
    1120       }
    1121       break;
    1122     }
    1123     default:
    1124       break;
    1125   }
    1126  
    1127   return;
    1128  
    1129 }
    1130 
    1131 Void TEncEntropy::encodeViewIdx(Int iViewIdx )
    1132 {
    1133   m_pcEntropyCoderIf->codeViewIdx(iViewIdx);
    1134 }
    1135 
    1136 /** encode reference frame index
    1137  * \param pcCU
    1138  * \param uiAbsPartIdx
    1139  * \param eRefList
    1140  * \param bRD
    1141  * \returns Void
    1142  */
    1143 Void TEncEntropy::encodeRefFrmIdx( TComDataCU* pcCU, UInt uiAbsPartIdx, RefPicList eRefList, Bool bRD )
    1144 {
    1145   assert( !pcCU->isIntra( uiAbsPartIdx ) );
    1146  
    1147   if( bRD )
    1148     uiAbsPartIdx = 0;
    1149  
    1150 #if DCM_COMB_LIST
    1151   if(pcCU->getSlice()->getNumRefIdx(REF_PIC_LIST_C) > 0)
    1152   {
    1153     UInt uiPartOffset = ( pcCU->getPic()->getNumPartInCU() >> ( pcCU->getDepth(uiAbsPartIdx) << 1 ) ) >> 2;
    1154 
    1155     switch ( pcCU->getPartitionSize( uiAbsPartIdx ) )
    1156     {
    1157       case SIZE_2Nx2N:
    1158       {
    1159         if ( pcCU->getInterDir( uiAbsPartIdx ) != 3 && eRefList== REF_PIC_LIST_0 && pcCU->getSlice()->getNumRefIdx( REF_PIC_LIST_C ) > 1)
    1160         {
    1161           if ( pcCU->getSlice()->getNumRefIdx ( REF_PIC_LIST_C ) > 1 )
    1162           {
    1163             m_pcEntropyCoderIf->codeRefFrmIdx( pcCU, uiAbsPartIdx, RefPicList(pcCU->getInterDir( uiAbsPartIdx )-1) );
    1164           }
    1165         }
    1166         else if (pcCU->getInterDir( uiAbsPartIdx ) == 3 &&  pcCU->getSlice()->getNumRefIdx( eRefList ) > 1)
    1167         {
    1168           if ( pcCU->getInterDir( uiAbsPartIdx ) & ( 1 << eRefList ) )
    1169           {
    1170             m_pcEntropyCoderIf->codeRefFrmIdx( pcCU, uiAbsPartIdx, eRefList );
    1171           }
    1172         }
    1173         break;
    1174       }
    1175       case SIZE_2NxN:
    1176       {
    1177         if ( pcCU->getInterDir( uiAbsPartIdx ) != 3 && eRefList== REF_PIC_LIST_0 && pcCU->getSlice()->getNumRefIdx( REF_PIC_LIST_C ) > 1)
    1178         {
    1179           if ( pcCU->getSlice()->getNumRefIdx ( REF_PIC_LIST_C ) > 1 )
    1180           {
    1181             m_pcEntropyCoderIf->codeRefFrmIdx( pcCU, uiAbsPartIdx, RefPicList(pcCU->getInterDir( uiAbsPartIdx )-1) );
    1182           }
    1183         }
    1184         else if (pcCU->getInterDir( uiAbsPartIdx ) == 3 &&  pcCU->getSlice()->getNumRefIdx( eRefList ) > 1)
    1185         {
    1186           if ( pcCU->getInterDir( uiAbsPartIdx ) & ( 1 << eRefList ) )
    1187           {
    1188             m_pcEntropyCoderIf->codeRefFrmIdx( pcCU, uiAbsPartIdx, eRefList );
    1189           }
    1190         }
    1191 
    1192         uiAbsPartIdx += uiPartOffset << 1;
    1193 
    1194         if ( pcCU->getInterDir( uiAbsPartIdx ) != 3 && eRefList== REF_PIC_LIST_0 && pcCU->getSlice()->getNumRefIdx( REF_PIC_LIST_C ) > 1)
    1195         {
    1196           if ( pcCU->getSlice()->getNumRefIdx ( REF_PIC_LIST_C ) > 1 )
    1197           {
    1198             m_pcEntropyCoderIf->codeRefFrmIdx( pcCU, uiAbsPartIdx, RefPicList(pcCU->getInterDir( uiAbsPartIdx )-1) );
    1199           }
    1200         }
    1201         else if (pcCU->getInterDir( uiAbsPartIdx ) == 3 &&  pcCU->getSlice()->getNumRefIdx( eRefList ) > 1)
    1202         {
    1203           if ( pcCU->getInterDir( uiAbsPartIdx ) & ( 1 << eRefList ) )
    1204           {
    1205             m_pcEntropyCoderIf->codeRefFrmIdx( pcCU, uiAbsPartIdx, eRefList );
    1206           }
    1207         }
    1208         break;
    1209       }
    1210       case SIZE_Nx2N:
    1211       {
    1212         if ( pcCU->getInterDir( uiAbsPartIdx ) != 3 && eRefList== REF_PIC_LIST_0 && pcCU->getSlice()->getNumRefIdx( REF_PIC_LIST_C ) > 1)
    1213         {
    1214           if ( pcCU->getSlice()->getNumRefIdx ( REF_PIC_LIST_C ) > 1 )
    1215           {
    1216             m_pcEntropyCoderIf->codeRefFrmIdx( pcCU, uiAbsPartIdx, RefPicList(pcCU->getInterDir( uiAbsPartIdx )-1) );
    1217           }
    1218         }
    1219         else if (pcCU->getInterDir( uiAbsPartIdx ) == 3 &&  pcCU->getSlice()->getNumRefIdx( eRefList ) > 1)
    1220         {
    1221           if ( pcCU->getInterDir( uiAbsPartIdx ) & ( 1 << eRefList ) )
    1222           {
    1223             m_pcEntropyCoderIf->codeRefFrmIdx( pcCU, uiAbsPartIdx, eRefList );
    1224           }
    1225         }
    1226 
    1227         uiAbsPartIdx += uiPartOffset;
    1228 
    1229         if ( pcCU->getInterDir( uiAbsPartIdx ) != 3 && eRefList== REF_PIC_LIST_0 && pcCU->getSlice()->getNumRefIdx( REF_PIC_LIST_C ) > 1)
    1230         {
    1231           if ( pcCU->getSlice()->getNumRefIdx ( REF_PIC_LIST_C ) > 1 )
    1232           {
    1233             m_pcEntropyCoderIf->codeRefFrmIdx( pcCU, uiAbsPartIdx, RefPicList(pcCU->getInterDir( uiAbsPartIdx )-1) );
    1234           }
    1235         }
    1236         else if (pcCU->getInterDir( uiAbsPartIdx ) == 3 &&  pcCU->getSlice()->getNumRefIdx( eRefList ) > 1)
    1237         {
    1238           if ( pcCU->getInterDir( uiAbsPartIdx ) & ( 1 << eRefList ) )
    1239           {
    1240             m_pcEntropyCoderIf->codeRefFrmIdx( pcCU, uiAbsPartIdx, eRefList );
    1241           }
    1242         }
    1243         break;
    1244       }
    1245       case SIZE_NxN:
    1246       {
    1247         for ( Int iPartIdx = 0; iPartIdx < 4; iPartIdx++ )
    1248         {
    1249           if ( pcCU->getInterDir( uiAbsPartIdx ) != 3 && eRefList== REF_PIC_LIST_0 && pcCU->getSlice()->getNumRefIdx( REF_PIC_LIST_C ) > 1)
    1250           {
    1251             if ( pcCU->getSlice()->getNumRefIdx ( REF_PIC_LIST_C ) > 1 )
    1252             {
    1253               m_pcEntropyCoderIf->codeRefFrmIdx( pcCU, uiAbsPartIdx, RefPicList(pcCU->getInterDir( uiAbsPartIdx )-1) );
    1254             }
    1255           }
    1256           else if (pcCU->getInterDir( uiAbsPartIdx ) == 3 &&  pcCU->getSlice()->getNumRefIdx( eRefList ) > 1)
    1257           {
    1258             if ( pcCU->getInterDir( uiAbsPartIdx ) & ( 1 << eRefList ) )
    1259             {
    1260               m_pcEntropyCoderIf->codeRefFrmIdx( pcCU, uiAbsPartIdx, eRefList );
    1261             }
    1262           }
    1263 
    1264           uiAbsPartIdx += uiPartOffset;
    1265         }
    1266         break;
    1267       }
    1268       default:
    1269         break;
    1270     }
    1271   }
    1272   else
    1273   {
    1274 #endif
    1275     if ( pcCU->getSlice()->getNumRefIdx( eRefList ) == 1 )
    1276     {
    1277       return;
    1278     }
    1279 
    1280     UInt uiPartOffset = ( pcCU->getPic()->getNumPartInCU() >> ( pcCU->getDepth(uiAbsPartIdx) << 1 ) ) >> 2;
    1281 
    1282     switch ( pcCU->getPartitionSize( uiAbsPartIdx ) )
    1283     {
    1284       case SIZE_2Nx2N:
    1285       {
    1286         if ( pcCU->getInterDir( uiAbsPartIdx ) & ( 1 << eRefList ) )
    1287         {
    1288           m_pcEntropyCoderIf->codeRefFrmIdx( pcCU, uiAbsPartIdx, eRefList );
    1289         }
    1290         break;
    1291       }
    1292       case SIZE_2NxN:
    1293       {
    1294         if ( pcCU->getInterDir( uiAbsPartIdx ) & ( 1 << eRefList ) )
    1295         {
    1296           m_pcEntropyCoderIf->codeRefFrmIdx( pcCU, uiAbsPartIdx, eRefList );
    1297         }
    1298 
    1299         uiAbsPartIdx += uiPartOffset << 1;
    1300         if ( pcCU->getInterDir( uiAbsPartIdx ) & ( 1 << eRefList ) )
    1301         {
    1302           m_pcEntropyCoderIf->codeRefFrmIdx( pcCU, uiAbsPartIdx, eRefList );
    1303         }
    1304         break;
    1305       }
    1306       case SIZE_Nx2N:
    1307       {
    1308         if ( pcCU->getInterDir( uiAbsPartIdx ) & ( 1 << eRefList ) )
    1309         {
    1310           m_pcEntropyCoderIf->codeRefFrmIdx( pcCU, uiAbsPartIdx, eRefList );
    1311         }
    1312 
    1313         uiAbsPartIdx += uiPartOffset;
    1314         if ( pcCU->getInterDir( uiAbsPartIdx ) & ( 1 << eRefList ) )
    1315         {
    1316           m_pcEntropyCoderIf->codeRefFrmIdx( pcCU, uiAbsPartIdx, eRefList );
    1317         }
    1318         break;
    1319       }
    1320       case SIZE_NxN:
    1321       {
    1322         for ( Int iPartIdx = 0; iPartIdx < 4; iPartIdx++ )
    1323         {
    1324           if ( pcCU->getInterDir( uiAbsPartIdx ) & ( 1 << eRefList ) )
    1325           {
    1326             m_pcEntropyCoderIf->codeRefFrmIdx( pcCU, uiAbsPartIdx, eRefList );
    1327           }
    1328           uiAbsPartIdx += uiPartOffset;
    1329         }
    1330         break;
    1331       }
    1332       default:
    1333         break;
    1334     }
    1335 
    1336 #if DCM_COMB_LIST
    1337   }
    1338 #endif
    1339 
    1340   return;
    1341 }
    1342 
    1343 /** encode motion vector difference
    1344  * \param pcCU
    1345  * \param uiAbsPartIdx
    1346  * \param eRefList
    1347  * \param bRD
    1348  * \returns Void
    1349  */
    1350 Void TEncEntropy::encodeMvd( TComDataCU* pcCU, UInt uiAbsPartIdx, RefPicList eRefList, Bool bRD )
    1351 {
    1352   assert( !pcCU->isIntra( uiAbsPartIdx ) );
    1353  
    1354   if( bRD )
    1355     uiAbsPartIdx = 0;
    1356  
    1357   UInt uiPartOffset = ( pcCU->getPic()->getNumPartInCU() >> ( pcCU->getDepth(uiAbsPartIdx) << 1 ) ) >> 2;
    1358  
    1359   switch ( pcCU->getPartitionSize( uiAbsPartIdx ) )
    1360   {
    1361     case SIZE_2Nx2N:
    1362     {
    1363       if ( pcCU->getInterDir( uiAbsPartIdx ) & ( 1 << eRefList ) )
    1364       {
    1365         m_pcEntropyCoderIf->codeMvd( pcCU, uiAbsPartIdx, eRefList );
    1366       }
    1367       break;
    1368     }
    1369      
    1370     case SIZE_2NxN:
    1371     {
    1372       if ( pcCU->getInterDir( uiAbsPartIdx ) & ( 1 << eRefList ) )
    1373       {
    1374         m_pcEntropyCoderIf->codeMvd( pcCU, uiAbsPartIdx, eRefList );
    1375       }
    1376      
    1377       uiAbsPartIdx += uiPartOffset << 1;
    1378       if ( pcCU->getInterDir( uiAbsPartIdx ) & ( 1 << eRefList ) )
    1379       {
    1380         m_pcEntropyCoderIf->codeMvd( pcCU, uiAbsPartIdx, eRefList );
    1381       }
    1382       break;
    1383     }
    1384      
    1385     case SIZE_Nx2N:
    1386     {
    1387       if ( pcCU->getInterDir( uiAbsPartIdx ) & ( 1 << eRefList ) )
    1388       {
    1389         m_pcEntropyCoderIf->codeMvd( pcCU, uiAbsPartIdx, eRefList );
    1390       }
    1391      
    1392       uiAbsPartIdx += uiPartOffset;
    1393       if ( pcCU->getInterDir( uiAbsPartIdx ) & ( 1 << eRefList ) )
    1394       {
    1395         m_pcEntropyCoderIf->codeMvd( pcCU, uiAbsPartIdx, eRefList );
    1396       }
    1397       break;
    1398     }
    1399      
    1400     case SIZE_NxN:
    1401     {
    1402       for ( Int iPartIdx = 0; iPartIdx < 4; iPartIdx++ )
    1403       {
    1404         if ( pcCU->getInterDir( uiAbsPartIdx ) & ( 1 << eRefList ) )
    1405         {
    1406           m_pcEntropyCoderIf->codeMvd( pcCU, uiAbsPartIdx, eRefList );
    1407         }
    1408         uiAbsPartIdx += uiPartOffset;
    1409       }
    1410       break;
    1411     }
    1412     default:
    1413       break;
    1414   }
    1415  
    1416   return;
    1417 }
    1418 
    14191422
    14201423Void TEncEntropy::encodeQtCbf( TComDataCU* pcCU, UInt uiAbsPartIdx, TextType eType, UInt uiTrDepth )
     
    14371440{
    14381441  if( bRD )
     1442  {
    14391443    uiAbsPartIdx = 0;
    1440  
    1441   if ( pcCU->getSlice()->getSPS()->getUseDQP() )
     1444  }
     1445 
     1446  if ( pcCU->getSlice()->getPPS()->getUseDQP() )
    14421447  {
    14431448    m_pcEntropyCoderIf->codeDeltaQP( pcCU, uiAbsPartIdx );
     
    14471452
    14481453// texture
    1449 Void TEncEntropy::xEncodeCoeff( TComDataCU* pcCU, TCoeff* pcCoeff, UInt uiAbsPartIdx, UInt uiDepth, UInt uiWidth, UInt uiHeight, UInt uiTrIdx, UInt uiCurrTrIdx, TextType eType, Bool bRD )
    1450 {
    1451   if ( pcCU->getCbf( uiAbsPartIdx, eType, uiTrIdx ) )
    1452   {
    1453 #if SNY_DQP
     1454#if !UNIFIED_TRANSFORM_TREE
     1455Void TEncEntropy::xEncodeCoeff( TComDataCU* pcCU, UInt uiLumaOffset, UInt uiChromaOffset, UInt uiAbsPartIdx, UInt uiDepth, UInt uiWidth, UInt uiHeight, UInt uiTrIdx, UInt uiCurrTrIdx, Bool& bCodeDQP )
     1456{
     1457  UInt uiLog2TrSize = g_aucConvertToBit[ pcCU->getSlice()->getSPS()->getMaxCUWidth() >> uiDepth ] + 2;
     1458  UInt uiCbfY = pcCU->getCbf( uiAbsPartIdx, TEXT_LUMA, uiTrIdx );
     1459  UInt uiCbfU = pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_U, uiTrIdx );
     1460  UInt uiCbfV = pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_V, uiTrIdx );
     1461
     1462  if( uiLog2TrSize == 2 )
     1463  {
     1464    UInt uiQPDiv = pcCU->getPic()->getNumPartInCU() >> ( ( uiDepth - 1 ) << 1 );
     1465    if( ( uiAbsPartIdx % uiQPDiv ) == 0 )
     1466    {
     1467      m_uiBakAbsPartIdx   = uiAbsPartIdx;
     1468      m_uiBakChromaOffset = uiChromaOffset;
     1469    }
     1470    else if( ( uiAbsPartIdx % uiQPDiv ) == (uiQPDiv - 1) )
     1471    {
     1472      uiCbfU = pcCU->getCbf( m_uiBakAbsPartIdx, TEXT_CHROMA_U, uiTrIdx );
     1473      uiCbfV = pcCU->getCbf( m_uiBakAbsPartIdx, TEXT_CHROMA_V, uiTrIdx );
     1474    }
     1475  }
     1476
     1477  if ( uiCbfY || uiCbfU || uiCbfV )
     1478  {
    14541479    // dQP: only for LCU once
    1455     if ( pcCU->getSlice()->getSPS()->getUseDQP() )
    1456     {
    1457       if ( pcCU->getdQPFlag())// non-skip
    1458       {
    1459         encodeQP( pcCU, 0 );
    1460         pcCU->setdQPFlag(false);
    1461       }
    1462     }
    1463 #endif//SNY_DQP
     1480    if ( pcCU->getSlice()->getPPS()->getUseDQP() )
     1481    {
     1482      if ( bCodeDQP )
     1483      {
     1484        encodeQP( pcCU, uiAbsPartIdx );
     1485        bCodeDQP = false;
     1486      }
     1487    }
    14641488    UInt uiLumaTrMode, uiChromaTrMode;
    14651489    pcCU->convertTransIdx( uiAbsPartIdx, pcCU->getTransformIdx( uiAbsPartIdx ), uiLumaTrMode, uiChromaTrMode );
    1466     const UInt uiStopTrMode = eType == TEXT_LUMA ? uiLumaTrMode : uiChromaTrMode;
     1490    const UInt uiStopTrMode = uiLumaTrMode;
    14671491   
    14681492    assert(1); // as long as quadtrees are not used for residual transform
     
    14701494    if( uiTrIdx == uiStopTrMode )
    14711495    {
    1472       assert( !bRD ); // parameter bRD can be removed
    1473      
    1474       UInt uiLog2TrSize = g_aucConvertToBit[ pcCU->getSlice()->getSPS()->getMaxCUWidth() >> uiDepth ] + 2;
    1475       if( eType != TEXT_LUMA && uiLog2TrSize == pcCU->getSlice()->getSPS()->getQuadtreeTULog2MinSize() )
     1496      if( pcCU->getCbf( uiAbsPartIdx, TEXT_LUMA, uiTrIdx ) )
     1497      {
     1498        Int trWidth = uiWidth;
     1499        Int trHeight = uiHeight;
     1500        pcCU->getNSQTSize( uiTrIdx, uiAbsPartIdx, trWidth, trHeight );
     1501        m_pcEntropyCoderIf->codeCoeffNxN( pcCU, (pcCU->getCoeffY()+uiLumaOffset), uiAbsPartIdx, trWidth, trHeight, uiDepth, TEXT_LUMA );
     1502      }
     1503
     1504      uiWidth  >>= 1;
     1505      uiHeight >>= 1;
     1506
     1507      if( uiLog2TrSize == 2 )
    14761508      {
    14771509        UInt uiQPDiv = pcCU->getPic()->getNumPartInCU() >> ( ( uiDepth - 1 ) << 1 );
    1478         if( ( uiAbsPartIdx % uiQPDiv ) != 0 )
     1510        if( ( uiAbsPartIdx % uiQPDiv ) == (uiQPDiv - 1) )
    14791511        {
    1480           return;
     1512          uiWidth  <<= 1;
     1513          uiHeight <<= 1;
     1514          Int trWidth = uiWidth;
     1515          Int trHeight = uiHeight;
     1516          pcCU->getNSQTSize( uiTrIdx-1, uiAbsPartIdx, trWidth, trHeight );
     1517          if( pcCU->getCbf( m_uiBakAbsPartIdx, TEXT_CHROMA_U, uiTrIdx ) )
     1518          {
     1519            m_pcEntropyCoderIf->codeCoeffNxN( pcCU, (pcCU->getCoeffCb()+m_uiBakChromaOffset), m_uiBakAbsPartIdx, trWidth, trHeight, uiDepth, TEXT_CHROMA_U );
     1520          }
     1521          if( pcCU->getCbf( m_uiBakAbsPartIdx, TEXT_CHROMA_V, uiTrIdx ) )
     1522          {
     1523            m_pcEntropyCoderIf->codeCoeffNxN( pcCU, (pcCU->getCoeffCr()+m_uiBakChromaOffset), m_uiBakAbsPartIdx, trWidth, trHeight, uiDepth, TEXT_CHROMA_V );
     1524          }
    14811525        }
    1482         uiWidth  <<= 1;
    1483         uiHeight <<= 1;
    1484       }
    1485       m_pcEntropyCoderIf->codeCoeffNxN( pcCU, pcCoeff, uiAbsPartIdx, uiWidth, uiHeight, uiDepth, eType, bRD );
     1526      }
     1527      else
     1528      {
     1529        Int trWidth = uiWidth;
     1530        Int trHeight = uiHeight;
     1531        pcCU->getNSQTSize( uiTrIdx, uiAbsPartIdx, trWidth, trHeight );
     1532        if( pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_U, uiTrIdx ) )
     1533        {
     1534          m_pcEntropyCoderIf->codeCoeffNxN( pcCU, (pcCU->getCoeffCb()+uiChromaOffset), uiAbsPartIdx, trWidth, trHeight, uiDepth, TEXT_CHROMA_U );
     1535        }
     1536        if( pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_V, uiTrIdx ) )
     1537        {
     1538          m_pcEntropyCoderIf->codeCoeffNxN( pcCU, (pcCU->getCoeffCr()+uiChromaOffset), uiAbsPartIdx, trWidth, trHeight, uiDepth, TEXT_CHROMA_V );
     1539        }
     1540      }
    14861541    }
    14871542    else
    14881543    {
    14891544      {
    1490         DTRACE_CABAC_V( g_nSymbolCounter++ );
     1545        DTRACE_CABAC_VL( g_nSymbolCounter++ );
    14911546        DTRACE_CABAC_T( "\tgoing down\tdepth=" );
    14921547        DTRACE_CABAC_V( uiDepth );
     
    15081563      UInt uiIdx      = uiAbsPartIdx;
    15091564     
    1510 #if !CAVLC_RQT_CBP
    1511       if(pcCU->getSlice()->getSymbolMode() == 0)
    1512       {
    1513         UInt uiLog2TrSize = g_aucConvertToBit[ pcCU->getSlice()->getSPS()->getMaxCUWidth() >> uiDepth ] + 2;
    1514         if( eType == TEXT_LUMA || uiLog2TrSize > pcCU->getSlice()->getSPS()->getQuadtreeTULog2MinSize() )
    1515           m_pcEntropyCoderIf->codeBlockCbf(pcCU, uiIdx, eType, uiTrIdx, uiQPartNum);
    1516         xEncodeCoeff( pcCU, pcCoeff, uiIdx, uiDepth, uiWidth, uiHeight, uiTrIdx, uiCurrTrIdx, eType, bRD ); pcCoeff += uiSize; uiIdx += uiQPartNum;
    1517         xEncodeCoeff( pcCU, pcCoeff, uiIdx, uiDepth, uiWidth, uiHeight, uiTrIdx, uiCurrTrIdx, eType, bRD ); pcCoeff += uiSize; uiIdx += uiQPartNum;
    1518         xEncodeCoeff( pcCU, pcCoeff, uiIdx, uiDepth, uiWidth, uiHeight, uiTrIdx, uiCurrTrIdx, eType, bRD ); pcCoeff += uiSize; uiIdx += uiQPartNum;
    1519         xEncodeCoeff( pcCU, pcCoeff, uiIdx, uiDepth, uiWidth, uiHeight, uiTrIdx, uiCurrTrIdx, eType, bRD );
    1520       }
    1521       else
    1522       {
    1523 #endif
    1524         xEncodeCoeff( pcCU, pcCoeff, uiIdx, uiDepth, uiWidth, uiHeight, uiTrIdx, uiCurrTrIdx, eType, bRD ); pcCoeff += uiSize; uiIdx += uiQPartNum;
    1525         xEncodeCoeff( pcCU, pcCoeff, uiIdx, uiDepth, uiWidth, uiHeight, uiTrIdx, uiCurrTrIdx, eType, bRD ); pcCoeff += uiSize; uiIdx += uiQPartNum;
    1526         xEncodeCoeff( pcCU, pcCoeff, uiIdx, uiDepth, uiWidth, uiHeight, uiTrIdx, uiCurrTrIdx, eType, bRD ); pcCoeff += uiSize; uiIdx += uiQPartNum;
    1527         xEncodeCoeff( pcCU, pcCoeff, uiIdx, uiDepth, uiWidth, uiHeight, uiTrIdx, uiCurrTrIdx, eType, bRD );
    1528 #if !CAVLC_RQT_CBP
    1529       }
    1530 #endif
    1531       {
    1532         DTRACE_CABAC_V( g_nSymbolCounter++ );
     1565      {
     1566        xEncodeCoeff( pcCU, uiLumaOffset, uiChromaOffset, uiIdx, uiDepth, uiWidth, uiHeight, uiTrIdx, uiCurrTrIdx, bCodeDQP );
     1567        uiLumaOffset += uiSize;  uiChromaOffset += (uiSize>>2);  uiIdx += uiQPartNum;
     1568
     1569        xEncodeCoeff( pcCU, uiLumaOffset, uiChromaOffset, uiIdx, uiDepth, uiWidth, uiHeight, uiTrIdx, uiCurrTrIdx, bCodeDQP );
     1570        uiLumaOffset += uiSize;  uiChromaOffset += (uiSize>>2);  uiIdx += uiQPartNum;
     1571
     1572        xEncodeCoeff( pcCU, uiLumaOffset, uiChromaOffset, uiIdx, uiDepth, uiWidth, uiHeight, uiTrIdx, uiCurrTrIdx, bCodeDQP );
     1573        uiLumaOffset += uiSize;  uiChromaOffset += (uiSize>>2);  uiIdx += uiQPartNum;
     1574
     1575        xEncodeCoeff( pcCU, uiLumaOffset, uiChromaOffset, uiIdx, uiDepth, uiWidth, uiHeight, uiTrIdx, uiCurrTrIdx, bCodeDQP );
     1576      }
     1577      {
     1578        DTRACE_CABAC_VL( g_nSymbolCounter++ );
    15331579        DTRACE_CABAC_T( "\tgoing up\n" );
    15341580      }
     
    15361582  }
    15371583}
    1538 
    1539 Void TEncEntropy::encodeCoeff( TComDataCU* pcCU, TCoeff* pCoeff, UInt uiAbsPartIdx, UInt uiDepth, UInt uiWidth, UInt uiHeight, UInt uiMaxTrMode, UInt uiTrMode, TextType eType, Bool bRD )
    1540 {
    1541   xEncodeCoeff( pcCU, pCoeff, uiAbsPartIdx, uiDepth, uiWidth, uiHeight, uiTrMode, uiMaxTrMode, eType, bRD );
    1542 }
     1584#endif // !UNIFIED_TRANSFORM_TREE
    15431585
    15441586/** encode coefficients
     
    15481590 * \param uiWidth
    15491591 * \param uiHeight
    1550  * \returns Void
    1551  */
    1552 Void TEncEntropy::encodeCoeff( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, UInt uiWidth, UInt uiHeight )
     1592 */
     1593Void TEncEntropy::encodeCoeff( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, UInt uiWidth, UInt uiHeight, Bool& bCodeDQP )
    15531594{
    15541595  UInt uiMinCoeffSize = pcCU->getPic()->getMinCUWidth()*pcCU->getPic()->getMinCUHeight();
     
    15611602  if( pcCU->isIntra(uiAbsPartIdx) )
    15621603  {
    1563     DTRACE_CABAC_V( g_nSymbolCounter++ )
     1604    DTRACE_CABAC_VL( g_nSymbolCounter++ )
    15641605    DTRACE_CABAC_T( "\tdecodeTransformIdx()\tCUDepth=" )
    15651606    DTRACE_CABAC_V( uiDepth )
    15661607    DTRACE_CABAC_T( "\n" )
     1608#if !UNIFIED_TRANSFORM_TREE
    15671609    UInt temp = 0;
    15681610    UInt temp1 = 0;
    15691611    UInt temp2 = 0;
    1570     xEncodeTransformSubdiv( pcCU, uiAbsPartIdx, uiDepth, 0, temp, temp1, temp2 );
    1571    
    1572 #if !CAVLC_RQT_CBP
    1573     if (pcCU->getSlice()->getSymbolMode() == 0)
    1574     {
    1575       m_pcEntropyCoderIf->codeCbf( pcCU, uiAbsPartIdx, TEXT_ALL, 0 );
    1576       if(pcCU->getCbf(uiAbsPartIdx, TEXT_LUMA, 0)==0 && pcCU->getCbf(uiAbsPartIdx, TEXT_CHROMA_U, 0)==0
    1577          && pcCU->getCbf(uiAbsPartIdx, TEXT_CHROMA_V, 0)==0)
    1578         return;
    1579     }
    1580 #endif
     1612    xEncodeTransformSubdiv( pcCU, uiAbsPartIdx, uiAbsPartIdx, uiDepth, 0, temp, temp1, temp2 );
     1613#endif // !UNIFIED_TRANSFORM_TREE
    15811614  }
    15821615  else
    15831616  {
    1584     if (pcCU->getSlice()->getSymbolMode()==0)
    1585     {
    1586 #if !CAVLC_RQT_CBP
    1587       m_pcEntropyCoderIf->codeCbf( pcCU, uiAbsPartIdx, TEXT_ALL, 0 );
    1588       if(pcCU->getCbf(uiAbsPartIdx, TEXT_LUMA, 0)==0 && pcCU->getCbf(uiAbsPartIdx, TEXT_CHROMA_U, 0)==0
    1589          && pcCU->getCbf(uiAbsPartIdx, TEXT_CHROMA_V, 0)==0)
    1590         return;
    1591 #endif
    1592     }
    1593     else
    1594     {
    1595 #if  HHI_MRG_SKIP
     1617    {
    15961618#if HHI_MPI
    15971619      if( !(pcCU->getMergeFlag( uiAbsPartIdx ) && pcCU->getPartitionSize(uiAbsPartIdx) == SIZE_2Nx2N &&
     
    16031625        m_pcEntropyCoderIf->codeQtRootCbf( pcCU, uiAbsPartIdx );
    16041626      }
     1627      if ( !pcCU->getQtRootCbf( uiAbsPartIdx ) )
     1628      {
     1629#if 1 // MW Bug Fix
     1630        pcCU->setCbfSubParts( 0, 0, 0, uiAbsPartIdx, uiDepth );
     1631        pcCU->setTrIdxSubParts( 0 , uiAbsPartIdx, uiDepth );
     1632#endif
     1633        pcCU->setNSQTIdxSubParts( uiAbsPartIdx, uiDepth );
     1634        return;
     1635      }
     1636    }
     1637#if !UNIFIED_TRANSFORM_TREE
     1638    encodeTransformIdx( pcCU, uiAbsPartIdx, pcCU->getDepth(uiAbsPartIdx) );
     1639#endif
     1640  }
     1641 
     1642#if UNIFIED_TRANSFORM_TREE
     1643  UInt temp = 0;
     1644  UInt temp1 = 0;
     1645  UInt temp2 = 0;
     1646  xEncodeTransform( pcCU, uiLumaOffset, uiChromaOffset, uiAbsPartIdx, uiAbsPartIdx, uiDepth, uiWidth, uiHeight, 0, 0, temp, temp1, temp2, bCodeDQP );
     1647#else // UNIFIED_TRANSFORM_TREE
     1648  xEncodeCoeff( pcCU, uiLumaOffset, uiChromaOffset, uiAbsPartIdx, uiDepth, uiWidth, uiHeight, 0, uiLumaTrMode, bCodeDQP );
     1649#endif // UNIFIED_TRANSFORM_TREE
     1650}
     1651
     1652Void TEncEntropy::encodeCoeffNxN( TComDataCU* pcCU, TCoeff* pcCoeff, UInt uiAbsPartIdx, UInt uiTrWidth, UInt uiTrHeight, UInt uiDepth, TextType eType )
     1653{ // This is for Transform unit processing. This may be used at mode selection stage for Inter.
     1654  m_pcEntropyCoderIf->codeCoeffNxN( pcCU, pcCoeff, uiAbsPartIdx, uiTrWidth, uiTrHeight, uiDepth, eType );
     1655}
     1656
     1657Void TEncEntropy::estimateBit (estBitsSbacStruct* pcEstBitsSbac, Int width, Int height, TextType eTType)
     1658
     1659  eTType = eTType == TEXT_LUMA ? TEXT_LUMA : TEXT_CHROMA;
     1660 
     1661  m_pcEntropyCoderIf->estBit ( pcEstBitsSbac, width, height, eTType );
     1662}
     1663
     1664#if SAO_UNIT_INTERLEAVING
     1665/** Encode SAO Offset
     1666 * \param  saoLcuParam SAO LCU paramters
     1667 */
     1668Void TEncEntropy::encodeSaoOffset(SaoLcuParam* saoLcuParam)
     1669{
     1670  UInt uiSymbol;
     1671  Int i;
     1672
     1673  uiSymbol = saoLcuParam->typeIdx + 1;
     1674  m_pcEntropyCoderIf->codeSaoTypeIdx(uiSymbol);
     1675  if (uiSymbol)
     1676  {
     1677    if( saoLcuParam->typeIdx == SAO_BO )
     1678    {
     1679      // Code Left Band Index
     1680      uiSymbol = (UInt) (saoLcuParam->bandPosition);
     1681      m_pcEntropyCoderIf->codeSaoUflc(uiSymbol);
     1682      for( i=0; i< saoLcuParam->length; i++)
     1683      {
     1684        m_pcEntropyCoderIf->codeSaoSvlc(saoLcuParam->offset[i]);
     1685      } 
     1686    }
     1687    else
     1688      if( saoLcuParam->typeIdx < 4 )
     1689      {
     1690        m_pcEntropyCoderIf->codeSaoUvlc( saoLcuParam->offset[0]);
     1691        m_pcEntropyCoderIf->codeSaoUvlc( saoLcuParam->offset[1]);
     1692        m_pcEntropyCoderIf->codeSaoUvlc(-saoLcuParam->offset[2]);
     1693        m_pcEntropyCoderIf->codeSaoUvlc(-saoLcuParam->offset[3]);
     1694      }
     1695  }
     1696}
     1697/** Encode SAO unit
     1698* \param  rx
     1699* \param  ry
     1700* \param  iCompIdx
     1701* \param  pSaoParam
     1702* \param  bRepeatedRow
     1703 */
     1704Void TEncEntropy::encodeSaoUnit(Int rx, Int ry, Int compIdx, SAOParam* saoParam, Int repeatedRow )
     1705{
     1706  int addr, addrLeft;
     1707  int numCuInWidth  = saoParam->numCuInWidth;
     1708  SaoLcuParam* saoOneLcu;
     1709  Int runLeft;
     1710
     1711  addr      =  rx + ry*numCuInWidth;
     1712  addrLeft  =  (addr%numCuInWidth == 0) ? -1 : addr - 1;
     1713
     1714  if (!repeatedRow)
     1715  {
     1716    saoOneLcu = &(saoParam->saoLcuParam[compIdx][addr]);   
     1717    runLeft = (addrLeft>=0 ) ? saoParam->saoLcuParam[compIdx][addrLeft].run : -1;
     1718    if (rx == 0 || runLeft==0)
     1719    {
     1720      if (ry == 0)
     1721      {
     1722        m_pcEntropyCoderIf->codeSaoRun(saoOneLcu->runDiff, numCuInWidth-rx-1);
     1723        saoOneLcu->mergeUpFlag = 0;
     1724      }
     1725      else
     1726      {
     1727        m_pcEntropyCoderIf->codeSaoSvlc(saoOneLcu->runDiff);
     1728        m_pcEntropyCoderIf->codeSaoFlag(saoOneLcu->mergeUpFlag); 
     1729      }
     1730      if (!saoOneLcu->mergeUpFlag)
     1731      {
     1732        encodeSaoOffset(saoOneLcu);
     1733      }
     1734    }
     1735  }
     1736}
     1737
     1738/** Encode SAO unit interleaving
     1739* \param  rx
     1740* \param  ry
     1741* \param  pSaoParam
     1742* \param  pcCU
     1743* \param  iCUAddrInSlice
     1744* \param  iCUAddrUpInSlice
     1745* \param  bLFCrossSliceBoundaryFlag
     1746 */
     1747Void TEncEntropy::encodeSaoUnitInterleaving(Int rx, Int ry, SAOParam* saoParam, TComDataCU* cu, Int cuAddrInSlice, Int cuAddrUpInSlice, Bool lfCrossSliceBoundaryFlag)
     1748{
     1749  Int addr = cu->getAddr();
     1750  for (Int compIdx=0; compIdx<3; compIdx++)
     1751  {
     1752    if (saoParam->bSaoFlag[compIdx])
     1753    {
     1754      if (rx>0 && cuAddrInSlice!=0)
     1755      {
     1756      m_pcEntropyCoderIf->codeSaoMergeLeft(saoParam->saoLcuParam[compIdx][addr].mergeLeftFlag,compIdx);
     1757      }
     1758      else
     1759      {
     1760        saoParam->saoLcuParam[compIdx][addr].mergeLeftFlag = 0;
     1761      }
     1762      if (saoParam->saoLcuParam[compIdx][addr].mergeLeftFlag == 0)
     1763      {
     1764        if ( (ry > 0) && (cuAddrUpInSlice>0||lfCrossSliceBoundaryFlag))
     1765        {
     1766          m_pcEntropyCoderIf->codeSaoMergeUp(saoParam->saoLcuParam[compIdx][addr].mergeUpFlag);
     1767        }
     1768        else
     1769        {
     1770          saoParam->saoLcuParam[compIdx][addr].mergeUpFlag = 0;
     1771        }
     1772        if (!saoParam->saoLcuParam[compIdx][addr].mergeUpFlag)
     1773        {
     1774          encodeSaoOffset(&(saoParam->saoLcuParam[compIdx][addr]));
     1775        }
     1776      }
     1777    }
     1778  }
     1779}
     1780
     1781/** Encode SAO parameter
     1782* \param  pcAPS
     1783 */
     1784Void TEncEntropy::encodeSaoParam(TComAPS* aps)
     1785{
     1786  SaoLcuParam* psSaoOneLcu;
     1787  int i,j,k, compIdx;
     1788  int numCuInWidth  ;
     1789  int numCuInHeight ;
     1790  Bool repeatedRow[3];
     1791  Int addr;
     1792  m_pcEntropyCoderIf->codeSaoFlag(aps->getSaoInterleavingFlag()); 
     1793  if(!aps->getSaoInterleavingFlag())
     1794  {
     1795    m_pcEntropyCoderIf->codeSaoFlag(aps->getSaoEnabled()); 
     1796    if (aps->getSaoEnabled())
     1797    {
     1798      SAOParam* pSaoParam = aps->getSaoParam();
     1799      numCuInWidth  = pSaoParam->numCuInWidth;
     1800      numCuInHeight = pSaoParam->numCuInHeight;
     1801      m_pcEntropyCoderIf->codeSaoFlag(pSaoParam->bSaoFlag[1]);
     1802      m_pcEntropyCoderIf->codeSaoFlag(pSaoParam->bSaoFlag[2]);
     1803      m_pcEntropyCoderIf->codeSaoUvlc(numCuInWidth-1);
     1804      m_pcEntropyCoderIf->codeSaoUvlc(numCuInHeight-1);
     1805      for (compIdx=0;compIdx<3;compIdx++)
     1806      {
     1807        if (pSaoParam->bSaoFlag[compIdx])
     1808        {
     1809          m_pcEntropyCoderIf->codeSaoFlag(pSaoParam->oneUnitFlag[compIdx]);
     1810          if (pSaoParam->oneUnitFlag[compIdx])
     1811          {
     1812            psSaoOneLcu = &(pSaoParam->saoLcuParam[compIdx][0]);   
     1813            encodeSaoOffset(psSaoOneLcu);
     1814          }
     1815        }
     1816      }
     1817
     1818      for (j=0;j<numCuInHeight;j++)
     1819      {
     1820        for (compIdx=0; compIdx<3; compIdx++)
     1821        {
     1822          repeatedRow[compIdx] = true;
     1823          for (k=0;k<numCuInWidth;k++)
     1824          {
     1825            addr       =  k + j*numCuInWidth;
     1826            psSaoOneLcu = &(pSaoParam->saoLcuParam[compIdx][addr]);   
     1827            if (!psSaoOneLcu->mergeUpFlag || psSaoOneLcu->runDiff)
     1828            {
     1829              repeatedRow[compIdx] = false;
     1830              break;
     1831            }
     1832          }
     1833        }
     1834        for (i=0;i<numCuInWidth;i++)
     1835        {
     1836          for (compIdx=0; compIdx<3; compIdx++)
     1837          {
     1838            if (pSaoParam->bSaoFlag[compIdx]  && !pSaoParam->oneUnitFlag[compIdx])
     1839            {
     1840              if (j>0 && i==0)
     1841              {
     1842                m_pcEntropyCoderIf->codeSaoFlag(repeatedRow[compIdx]);
     1843              }
     1844              encodeSaoUnit (i,j, compIdx, pSaoParam, repeatedRow[compIdx]);
     1845            }
     1846          }
     1847        }
     1848      }
     1849    }
     1850  }
     1851}
    16051852#else
    1606       m_pcEntropyCoderIf->codeQtRootCbf( pcCU, uiAbsPartIdx );
    1607 #endif
    1608       if ( !pcCU->getQtRootCbf( uiAbsPartIdx ) )
    1609       {
    1610         pcCU->setTrIdxSubParts( 0 , uiAbsPartIdx, uiDepth );
    1611         return;
    1612       }
     1853/** Encode SAO for one partition
     1854 * \param  pSaoParam, iPartIdx
     1855 */
     1856Void TEncEntropy::encodeSaoOnePart(SAOParam* pSaoParam, Int iPartIdx, Int iYCbCr)
     1857{
     1858  SAOQTPart*  pAlfPart = NULL;
     1859  pAlfPart = &(pSaoParam->psSaoPart[iYCbCr][iPartIdx]);
     1860
     1861  UInt uiSymbol;
     1862
     1863  if(!pAlfPart->bSplit)
     1864  {
     1865    if (pAlfPart->bEnableFlag)
     1866    {
     1867      uiSymbol = pAlfPart->iBestType + 1;
     1868    }
     1869    else
     1870    {
     1871      uiSymbol = 0;
    16131872    }
    16141873   
    1615     encodeTransformIdx( pcCU, uiAbsPartIdx, pcCU->getDepth(uiAbsPartIdx) );
    1616   }
    1617  
    1618   xEncodeCoeff( pcCU, pcCU->getCoeffY()  + uiLumaOffset,   uiAbsPartIdx, uiDepth, uiWidth,    uiHeight,    0, uiLumaTrMode,   TEXT_LUMA     );
    1619   xEncodeCoeff( pcCU, pcCU->getCoeffCb() + uiChromaOffset, uiAbsPartIdx, uiDepth, uiWidth>>1, uiHeight>>1, 0, uiChromaTrMode, TEXT_CHROMA_U );
    1620   xEncodeCoeff( pcCU, pcCU->getCoeffCr() + uiChromaOffset, uiAbsPartIdx, uiDepth, uiWidth>>1, uiHeight>>1, 0, uiChromaTrMode, TEXT_CHROMA_V );
    1621 }
    1622 
    1623 Void TEncEntropy::encodeCoeffNxN( TComDataCU* pcCU, TCoeff* pcCoeff, UInt uiAbsPartIdx, UInt uiTrWidth, UInt uiTrHeight, UInt uiDepth, TextType eType, Bool bRD )
    1624 { // This is for Transform unit processing. This may be used at mode selection stage for Inter.
    1625   m_pcEntropyCoderIf->codeCoeffNxN( pcCU, pcCoeff, uiAbsPartIdx, uiTrWidth, uiTrHeight, uiDepth, eType, bRD );
    1626 }
    1627 
    1628 Void TEncEntropy::estimateBit (estBitsSbacStruct* pcEstBitsSbac, UInt uiWidth, TextType eTType)
    1629 {
    1630   UInt uiCTXIdx;
    1631  
    1632   switch(uiWidth)
    1633   {
    1634     case  2: uiCTXIdx = 6; break;
    1635     case  4: uiCTXIdx = 5; break;
    1636     case  8: uiCTXIdx = 4; break;
    1637     case 16: uiCTXIdx = 3; break;
    1638     case 32: uiCTXIdx = 2; break;
    1639     case 64: uiCTXIdx = 1; break;
    1640     default: uiCTXIdx = 0; break;
    1641   }
    1642  
    1643   eTType = eTType == TEXT_LUMA ? TEXT_LUMA : TEXT_CHROMA;
    1644  
    1645   m_pcEntropyCoderIf->estBit ( pcEstBitsSbac, uiCTXIdx, eTType );
    1646 }
    1647 
    1648 #if MTK_SAO
    1649 /** encode QAO One Part
    1650  * \param  pQaoParam, iPartIdx
    1651  */
    1652 Void TEncEntropy::encodeQAOOnePart(SAOParam* pQaoParam, Int iPartIdx )
    1653 {
    1654   SAOQTPart*  pAlfPart = &(pQaoParam->psSaoPart[iPartIdx]);
    1655   UInt uiSymbol;
    1656 
    1657   if(!pAlfPart->bSplit)
    1658   {
     1874    m_pcEntropyCoderIf->codeSaoUvlc(uiSymbol);
     1875
    16591876    if (pAlfPart->bEnableFlag)
    1660       uiSymbol = pAlfPart->iBestType + 1;
    1661     else
    1662       uiSymbol = 0;
    1663 
    1664     m_pcEntropyCoderIf->codeAoUvlc(uiSymbol);
    1665     if (pAlfPart->bEnableFlag)
    16661877    {
    16671878      for(Int i=0; i< pAlfPart->iLength; i++)
    16681879      {
    1669         m_pcEntropyCoderIf->codeAoSvlc(pAlfPart->iOffset[i]);
     1880        m_pcEntropyCoderIf->codeSaoSvlc(pAlfPart->iOffset[i]);
    16701881      }   
    16711882    }
     
    16741885
    16751886  //split
    1676   if (pAlfPart->PartLevel < pQaoParam->iMaxSplitLevel)
     1887  if (pAlfPart->PartLevel < pSaoParam->iMaxSplitLevel)
    16771888  {
    16781889    for (Int i=0;i<NUM_DOWN_PART;i++)
    16791890    {
    1680       encodeQAOOnePart(pQaoParam, pAlfPart->DownPartsIdx[i]);
    1681     }
    1682   }
    1683 }
    1684 /** encode QuadTree Split Flag
    1685  * \param  pQaoParam, iPartIdx
    1686  */
    1687 Void TEncEntropy::encodeQuadTreeSplitFlag(SAOParam* pSaoParam, Int iPartIdx)
    1688 {
    1689 
    1690   SAOQTPart*  pSaoPart = &(pSaoParam->psSaoPart[iPartIdx]);
     1891      encodeSaoOnePart(pSaoParam, pAlfPart->DownPartsIdx[i], iYCbCr);
     1892    }
     1893  }
     1894}
     1895
     1896/** Encode quadtree split flag
     1897 * \param  pSaoParam, iPartIdx
     1898 */
     1899Void TEncEntropy::encodeQuadTreeSplitFlag(SAOParam* pSaoParam, Int iPartIdx, Int iYCbCr)
     1900{
     1901  SAOQTPart*  pSaoPart = NULL;
     1902  pSaoPart = &(pSaoParam->psSaoPart[iYCbCr][iPartIdx]);
    16911903
    16921904  if(pSaoPart->PartLevel < pSaoParam->iMaxSplitLevel)
    16931905  {
    1694 
    16951906    //send one flag
    1696     m_pcEntropyCoderIf->codeAoFlag( (pSaoPart->bSplit)?(1):(0)  );
     1907    m_pcEntropyCoderIf->codeSaoFlag( (pSaoPart->bSplit)?(1):(0)  );
     1908
    16971909    if(pSaoPart->bSplit)
    16981910    {
    16991911      for (Int i=0;i<NUM_DOWN_PART;i++)
    17001912      {
    1701         encodeQuadTreeSplitFlag(pSaoParam, pSaoPart->DownPartsIdx[i]);
     1913        encodeQuadTreeSplitFlag(pSaoParam, pSaoPart->DownPartsIdx[i], iYCbCr);
    17021914      }
    17031915    }
    17041916  }
    1705 
    1706 }
    1707 
    1708 /** encode Sao Param
    1709  * \param  pQaoParam
     1917}
     1918/** Encode SAO parameters
     1919 * \param  pSaoParam
    17101920 */
    17111921Void TEncEntropy::encodeSaoParam(SAOParam* pSaoParam)
    17121922{
    1713 
    1714   m_pcEntropyCoderIf->codeAoFlag(pSaoParam->bSaoFlag);
    1715   if (pSaoParam->bSaoFlag)
    1716   {
    1717     encodeQuadTreeSplitFlag(pSaoParam, 0);
    1718     encodeQAOOnePart(pSaoParam, 0);
    1719   }
    1720 
    1721 }
    1722 
    1723 
    1724 
    1725 #endif
     1923  if (pSaoParam->bSaoFlag[0])
     1924  {
     1925    encodeQuadTreeSplitFlag(pSaoParam, 0, 0);
     1926    encodeSaoOnePart(pSaoParam, 0, 0);
     1927    m_pcEntropyCoderIf->codeSaoFlag(pSaoParam->bSaoFlag[1]);
     1928    if (pSaoParam->bSaoFlag[1])
     1929    {
     1930      encodeQuadTreeSplitFlag(pSaoParam, 0, 1);
     1931      encodeSaoOnePart(pSaoParam, 0, 1);
     1932    }
     1933    m_pcEntropyCoderIf->codeSaoFlag(pSaoParam->bSaoFlag[2]);
     1934    if (pSaoParam->bSaoFlag[2])
     1935    {
     1936      encodeQuadTreeSplitFlag(pSaoParam, 0, 2);
     1937      encodeSaoOnePart(pSaoParam, 0, 2);
     1938    }
     1939  }
     1940}
     1941#endif
     1942
     1943Int TEncEntropy::countNonZeroCoeffs( TCoeff* pcCoef, UInt uiSize )
     1944{
     1945  Int count = 0;
     1946 
     1947  for ( Int i = 0; i < uiSize; i++ )
     1948  {
     1949    count += pcCoef[i] != 0;
     1950  }
     1951 
     1952  return count;
     1953}
     1954
     1955/** encode quantization matrix
     1956 * \param scalingList quantization matrix information
     1957 */
     1958Void TEncEntropy::encodeScalingList( TComScalingList* scalingList )
     1959{
     1960  m_pcEntropyCoderIf->codeScalingList( scalingList );
     1961}
     1962
     1963Void TEncEntropy::encodeDFParams(TComAPS* pcAPS)
     1964{
     1965  m_pcEntropyCoderIf->codeDFFlag(pcAPS->getLoopFilterDisable(), "loop_filter_disable");
     1966
     1967  if (!pcAPS->getLoopFilterDisable())
     1968  {
     1969    m_pcEntropyCoderIf->codeDFSvlc(pcAPS->getLoopFilterBetaOffset(), "beta_offset_div2");
     1970    m_pcEntropyCoderIf->codeDFSvlc(pcAPS->getLoopFilterTcOffset(), "tc_offset_div2");
     1971  }
     1972}
     1973
     1974//! \}
Note: See TracChangeset for help on using the changeset viewer.