Changeset 56 in 3DVCSoftware for trunk/source/Lib/TLibDecoder/TDecCAVLC.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/TLibDecoder/TDecCAVLC.cpp

    r42 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     TDecCAVLC.cpp
    3735    \brief    CAVLC decoder class
     
    4038#include "TDecCAVLC.h"
    4139#include "SEIread.h"
     40#include "TDecSlice.h"
     41
     42//! \ingroup TLibDecoder
     43//! \{
     44
     45#if ENC_DEC_TRACE
     46
     47#define READ_CODE(length, code, name)     xReadCodeTr ( length, code, name )
     48#define READ_UVLC(        code, name)     xReadUvlcTr (         code, name )
     49#define READ_SVLC(        code, name)     xReadSvlcTr (         code, name )
     50#define READ_FLAG(        code, name)     xReadFlagTr (         code, name )
     51
     52Void  xTraceSPSHeader (TComSPS *pSPS)
     53{
     54  fprintf( g_hTrace, "=========== Sequence Parameter Set ID: %d ===========\n", pSPS->getSPSId() );
     55}
     56
     57Void  xTracePPSHeader (TComPPS *pPPS)
     58{
     59  fprintf( g_hTrace, "=========== Picture Parameter Set ID: %d ===========\n", pPPS->getPPSId() );
     60}
     61
     62Void  xTraceAPSHeader (TComAPS *pAPS)
     63{
     64  fprintf( g_hTrace, "=========== Adaptation Parameter Set ===========\n");
     65}
     66
     67Void  xTraceSliceHeader (TComSlice *pSlice)
     68{
     69  fprintf( g_hTrace, "=========== Slice ===========\n");
     70}
     71
     72
     73Void  TDecCavlc::xReadCodeTr           (UInt length, UInt& rValue, const Char *pSymbolName)
     74{
     75  xReadCode (length, rValue);
     76  fprintf( g_hTrace, "%8lld  ", g_nSymbolCounter++ );
     77  fprintf( g_hTrace, "%-40s u(%d) : %d\n", pSymbolName, length, rValue );
     78  fflush ( g_hTrace );
     79}
     80
     81Void  TDecCavlc::xReadUvlcTr           (UInt& rValue, const Char *pSymbolName)
     82{
     83  xReadUvlc (rValue);
     84  fprintf( g_hTrace, "%8lld  ", g_nSymbolCounter++ );
     85  fprintf( g_hTrace, "%-40s u(v) : %d\n", pSymbolName, rValue );
     86  fflush ( g_hTrace );
     87}
     88
     89Void  TDecCavlc::xReadSvlcTr           (Int& rValue, const Char *pSymbolName)
     90{
     91  xReadSvlc(rValue);
     92  fprintf( g_hTrace, "%8lld  ", g_nSymbolCounter++ );
     93  fprintf( g_hTrace, "%-40s s(v) : %d\n", pSymbolName, rValue );
     94  fflush ( g_hTrace );
     95}
     96
     97Void  TDecCavlc::xReadFlagTr           (UInt& rValue, const Char *pSymbolName)
     98{
     99  xReadFlag(rValue);
     100  fprintf( g_hTrace, "%8lld  ", g_nSymbolCounter++ );
     101  fprintf( g_hTrace, "%-40s u(1) : %d\n", pSymbolName, rValue );
     102  fflush ( g_hTrace );
     103}
     104
     105#else
     106
     107#define READ_CODE(length, code, name)     xReadCode ( length, code )
     108#define READ_UVLC(        code, name)     xReadUvlc (         code )
     109#define READ_SVLC(        code, name)     xReadSvlc (         code )
     110#define READ_FLAG(        code, name)     xReadFlag (         code )
     111
     112#endif
     113
     114
    42115
    43116// ====================================================================================================================
     
    47120TDecCavlc::TDecCavlc()
    48121{
    49   m_bAlfCtrl = false;
    50   m_uiMaxAlfCtrlDepth = 0;
    51 
    52   m_aaiTempScale            = new Int* [ MAX_NUMBER_VIEWS ];
    53   m_aaiTempOffset           = new Int* [ MAX_NUMBER_VIEWS ];
    54   m_aaiTempPdmScaleNomDelta = new Int* [ MAX_NUMBER_VIEWS ];
    55   m_aaiTempPdmOffset        = new Int* [ MAX_NUMBER_VIEWS ];
    56   for( UInt uiVId = 0; uiVId < MAX_NUMBER_VIEWS; uiVId++ )
    57   {
    58     m_aaiTempScale            [ uiVId ] = new Int [ MAX_NUMBER_VIEWS ];
    59     m_aaiTempOffset           [ uiVId ] = new Int [ MAX_NUMBER_VIEWS ];
    60     m_aaiTempPdmScaleNomDelta [ uiVId ] = new Int [ MAX_NUMBER_VIEWS ];
    61     m_aaiTempPdmOffset        [ uiVId ] = new Int [ MAX_NUMBER_VIEWS ];
     122  m_iSliceGranularity = 0;
     123
     124  m_aaiTempScale            = new Int* [ MAX_VIEW_NUM ];
     125  m_aaiTempOffset           = new Int* [ MAX_VIEW_NUM ];
     126  m_aaiTempPdmScaleNomDelta = new Int* [ MAX_VIEW_NUM ];
     127  m_aaiTempPdmOffset        = new Int* [ MAX_VIEW_NUM ];
     128  for( UInt uiVId = 0; uiVId < MAX_VIEW_NUM; uiVId++ )
     129  {
     130    m_aaiTempScale            [ uiVId ] = new Int [ MAX_VIEW_NUM ];
     131    m_aaiTempOffset           [ uiVId ] = new Int [ MAX_VIEW_NUM ];
     132    m_aaiTempPdmScaleNomDelta [ uiVId ] = new Int [ MAX_VIEW_NUM ];
     133    m_aaiTempPdmOffset        [ uiVId ] = new Int [ MAX_VIEW_NUM ];
    62134  }
    63135}
     
    65137TDecCavlc::~TDecCavlc()
    66138{
    67   for( UInt uiVId = 0; uiVId < MAX_NUMBER_VIEWS; uiVId++ )
     139  for( UInt uiVId = 0; uiVId < MAX_VIEW_NUM; uiVId++ )
    68140  {
    69141    delete [] m_aaiTempScale            [ uiVId ];
     
    82154// ====================================================================================================================
    83155
    84 #if BITSTREAM_EXTRACTION
    85 Void  TDecCavlc::parseNalUnitHeader ( NalUnitType& eNalUnitType, UInt& TemporalId, UInt& uiLayerId )
    86 {
    87   UInt  uiCode;
    88 
    89   xReadCode ( 1, uiCode ); assert( 0 == uiCode); // forbidden_zero_bit
    90   xReadCode ( 1, uiCode );                       // nal_ref_flag
    91   xReadCode ( 6, uiCode );                       // nal_unit_type
    92   eNalUnitType = (NalUnitType) uiCode;
    93 
    94   xReadCode(3, uiCode); // temporal_id
    95   TemporalId = uiCode;
    96   xReadCode(5, uiCode); // layer_id_plus1
    97   assert( 1 <= uiCode );
    98   uiLayerId = uiCode - 1;
    99 }
    100 #else
    101 Void  TDecCavlc::parseNalUnitHeader ( NalUnitType& eNalUnitType, UInt& TemporalId, Bool& bOutputFlag )
    102 {
    103   UInt  uiCode;
    104 
    105   xReadCode ( 1, uiCode ); assert( 0 == uiCode); // forbidden_zero_bit
    106   xReadCode ( 2, uiCode );                       // nal_ref_idc
    107   xReadCode ( 5, uiCode );                       // nal_unit_type
    108   eNalUnitType = (NalUnitType) uiCode;
    109 
    110   if ( (eNalUnitType == NAL_UNIT_CODED_SLICE) || (eNalUnitType == NAL_UNIT_CODED_SLICE_IDR) || (eNalUnitType == NAL_UNIT_CODED_SLICE_CDR) )
    111   {
    112     xReadCode(3, uiCode); // temporal_id
    113     TemporalId = uiCode;
    114     xReadFlag(uiCode);    // output_flag
    115     bOutputFlag = (0!=uiCode);
    116     xReadCode(4, uiCode); // reserved_one_4bits
    117   }
    118   else
    119   {
    120     TemporalId = 0;
    121     bOutputFlag = true;
    122   }
    123 }
    124 #endif
    125 
    126156/**
    127157 * unmarshal a sequence of SEI messages from bitstream.
     
    129159void TDecCavlc::parseSEI(SEImessages& seis)
    130160{
    131   assert(!m_pcBitstream->getBitsUntilByteAligned());
    132   do {
     161  assert(!m_pcBitstream->getNumBitsUntilByteAligned());
     162  do
     163  {
    133164    parseSEImessage(*m_pcBitstream, seis);
    134165    /* SEI messages are an integer number of bytes, something has failed
    135166     * in the parsing if bitstream not byte-aligned */
    136     assert(!m_pcBitstream->getBitsUntilByteAligned());
     167    assert(!m_pcBitstream->getNumBitsUntilByteAligned());
    137168  } while (0x80 != m_pcBitstream->peekBits(8));
    138   assert(m_pcBitstream->getBitsLeft() == 8); /* rsbp_trailing_bits */
    139 }
    140 
     169  assert(m_pcBitstream->getNumBitsLeft() == 8); /* rsbp_trailing_bits */
     170}
     171#if RPS_IN_SPS
     172void TDecCavlc::parseShortTermRefPicSet( TComSPS* sps, TComReferencePictureSet* rps, Int idx )
     173#else
     174void TDecCavlc::parseShortTermRefPicSet( TComPPS* pcPPS, TComReferencePictureSet* rps, Int idx )
     175#endif
     176{
     177  UInt code;
     178  UInt interRPSPred;
     179  READ_FLAG(interRPSPred, "inter_ref_pic_set_prediction_flag");  rps->setInterRPSPrediction(interRPSPred);
     180  if (interRPSPred)
     181  {
     182    UInt bit;
     183    READ_UVLC(code, "delta_idx_minus1" ); // delta index of the Reference Picture Set used for prediction minus 1
     184    Int rIdx =  idx - 1 - code;
     185    assert (rIdx <= idx && rIdx >= 0);
     186#if RPS_IN_SPS
     187    TComReferencePictureSet*   rpsRef = sps->getRPSList()->getReferencePictureSet(rIdx);
     188#else
     189    TComReferencePictureSet*   rpsRef = pcPPS->getRPSList()->getReferencePictureSet(rIdx);
     190#endif
     191    Int k = 0, k0 = 0, k1 = 0;
     192    READ_CODE(1, bit, "delta_rps_sign"); // delta_RPS_sign
     193    READ_UVLC(code, "abs_delta_rps_minus1");  // absolute delta RPS minus 1
     194    Int deltaRPS = (1 - (bit<<1)) * (code + 1); // delta_RPS
     195    for(Int j=0 ; j <= rpsRef->getNumberOfPictures(); j++)
     196    {
     197      READ_CODE(1, bit, "used_by_curr_pic_flag" ); //first bit is "1" if Idc is 1
     198      Int refIdc = bit;
     199      if (refIdc == 0)
     200      {
     201        READ_CODE(1, bit, "use_delta_flag" ); //second bit is "1" if Idc is 2, "0" otherwise.
     202        refIdc = bit<<1; //second bit is "1" if refIdc is 2, "0" if refIdc = 0.
     203      }
     204      if (refIdc == 1 || refIdc == 2)
     205      {
     206        Int deltaPOC = deltaRPS + ((j < rpsRef->getNumberOfPictures())? rpsRef->getDeltaPOC(j) : 0);
     207        rps->setDeltaPOC(k, deltaPOC);
     208        rps->setUsed(k, (refIdc == 1));
     209
     210        if (deltaPOC < 0) {
     211          k0++;
     212        }
     213        else
     214        {
     215          k1++;
     216        }
     217        k++;
     218      } 
     219      rps->setRefIdc(j,refIdc); 
     220    }
     221    rps->setNumRefIdc(rpsRef->getNumberOfPictures()+1); 
     222    rps->setNumberOfPictures(k);
     223    rps->setNumberOfNegativePictures(k0);
     224    rps->setNumberOfPositivePictures(k1);
     225    rps->sortDeltaPOC();
     226  }
     227  else
     228  {
     229    READ_UVLC(code, "num_negative_pics");           rps->setNumberOfNegativePictures(code);
     230    READ_UVLC(code, "num_positive_pics");           rps->setNumberOfPositivePictures(code);
     231    Int prev = 0;
     232    Int poc;
     233    for(Int j=0 ; j < rps->getNumberOfNegativePictures(); j++)
     234    {
     235      READ_UVLC(code, "delta_poc_s0_minus1");
     236      poc = prev-code-1;
     237      prev = poc;
     238      rps->setDeltaPOC(j,poc);
     239      READ_FLAG(code, "used_by_curr_pic_s0_flag");  rps->setUsed(j,code);
     240    }
     241    prev = 0;
     242    for(Int j=rps->getNumberOfNegativePictures(); j < rps->getNumberOfNegativePictures()+rps->getNumberOfPositivePictures(); j++)
     243    {
     244      READ_UVLC(code, "delta_poc_s1_minus1");
     245      poc = prev+code+1;
     246      prev = poc;
     247      rps->setDeltaPOC(j,poc);
     248      READ_FLAG(code, "used_by_curr_pic_s1_flag");  rps->setUsed(j,code);
     249    }
     250    rps->setNumberOfPictures(rps->getNumberOfNegativePictures()+rps->getNumberOfPositivePictures());
     251  }
     252#if PRINT_RPS_INFO
     253  rps->printDeltaPOC();
     254#endif
     255}
     256
     257Void TDecCavlc::parseAPS(TComAPS* aps)
     258{
     259#if ENC_DEC_TRACE 
     260  xTraceAPSHeader(aps);
     261#endif
     262
     263  UInt uiCode;
     264  READ_UVLC(uiCode, "aps_id");                             aps->setAPSID(uiCode);
     265  READ_FLAG(uiCode, "aps_scaling_list_data_present_flag"); aps->setScalingListEnabled( (uiCode==1)?true:false );
     266  READ_FLAG(uiCode, "aps_deblocking_filter_flag");         aps->setLoopFilterOffsetInAPS( (uiCode==1)?true:false );
     267#if !SAO_UNIT_INTERLEAVING
     268  READ_FLAG(uiCode, "aps_sample_adaptive_offset_flag");    aps->setSaoEnabled( (uiCode==1)?true:false );
     269#endif
     270#if !LCU_SYNTAX_ALF
     271  READ_FLAG(uiCode, "aps_adaptive_loop_filter_flag");      aps->setAlfEnabled( (uiCode==1)?true:false );
     272#endif
     273  if(aps->getScalingListEnabled())
     274  {
     275    parseScalingList( aps->getScalingList() );
     276  }
     277#if DBL_CONTROL
     278  if(aps->getLoopFilterOffsetInAPS())
     279  {
     280    xParseDblParam( aps );   
     281  }
     282#endif
     283#if SAO_UNIT_INTERLEAVING
     284  READ_FLAG(uiCode, "aps_sao_interleaving_flag");      aps->setSaoInterleavingFlag( (uiCode==1)?true:false );
     285  if(!aps->getSaoInterleavingFlag())
     286  {
     287    READ_FLAG(uiCode, "aps_sample_adaptive_offset_flag");      aps->setSaoEnabled( (uiCode==1)?true:false );
     288#endif
     289  if(aps->getSaoEnabled())
     290  {
     291    aps->getSaoParam()->bSaoFlag[0] = true;
     292    xParseSaoParam( aps->getSaoParam() );
     293  }
     294#if SAO_UNIT_INTERLEAVING
     295  }
     296#endif
     297#if LCU_SYNTAX_ALF
     298  READ_FLAG(uiCode, "aps_adaptive_loop_filter_flag");      aps->setAlfEnabled( (uiCode==1)?true:false );
     299#endif
     300  if(aps->getAlfEnabled())
     301  {
     302#if !LCU_SYNTAX_ALF
     303    aps->getAlfParam()->alf_flag = 1;
     304#endif
     305    xParseAlfParam( aps->getAlfParam());
     306  }
     307  READ_FLAG( uiCode, "aps_extension_flag");
     308  if (uiCode)
     309  {
     310    while ( xMoreRbspData() )
     311    {
     312      READ_FLAG( uiCode, "aps_extension_data_flag");
     313    }
     314  }
     315
     316}
     317
     318#if DBL_CONTROL
     319Void  TDecCavlc::xParseDblParam       ( TComAPS* aps )
     320{
     321  UInt uiSymbol;
     322  Int iSymbol;
     323
     324  parseDFFlag(uiSymbol, "loop_filter_disable");
     325  aps->setLoopFilterDisable(uiSymbol?true:false);
     326
     327  if (!aps->getLoopFilterDisable())
     328  {
     329    parseDFSvlc(iSymbol, "beta_offset_div2");
     330    aps->setLoopFilterBetaOffset(iSymbol);
     331    parseDFSvlc(iSymbol, "tc_offset_div2");
     332    aps->setLoopFilterTcOffset(iSymbol);
     333  }
     334}
     335#endif
     336/** parse SAO parameters
     337 * \param pSaoParam
     338 */
     339Void TDecCavlc::xParseSaoParam(SAOParam* pSaoParam)
     340{
     341  UInt uiSymbol;
     342
     343#if SAO_UNIT_INTERLEAVING
     344  int i,j, compIdx;
     345  int numCuInWidth;
     346  int numCuInHeight;
     347  Bool repeatedRow[3];
     348  if (pSaoParam->bSaoFlag[0])                                                                   
     349  {     
     350    READ_FLAG (uiSymbol, "sao_cb_enable_flag");            pSaoParam->bSaoFlag[1]   = uiSymbol? true:false; 
     351    READ_FLAG (uiSymbol, "sao_cr_enable_flag");            pSaoParam->bSaoFlag[2]   = uiSymbol? true:false; 
     352    READ_UVLC (uiSymbol, "sao_num_lcu_in_width_minus1");   pSaoParam->numCuInWidth  = uiSymbol + 1;                         
     353    READ_UVLC (uiSymbol, "sao_num_lcu_in_height_minus1");  pSaoParam->numCuInHeight = uiSymbol + 1;                         
     354    numCuInWidth  = pSaoParam->numCuInWidth;
     355    numCuInHeight = pSaoParam->numCuInHeight;
     356
     357    READ_FLAG (uiSymbol, "sao_one_luma_unit_flag");  pSaoParam->oneUnitFlag[0] = uiSymbol? true:false; 
     358    if (pSaoParam->oneUnitFlag[0] )
     359      xParseSaoOffset(&(pSaoParam->saoLcuParam[0][0]));
     360
     361    if (pSaoParam->bSaoFlag[1])
     362    {
     363      READ_FLAG (uiSymbol, "sao_one_cb_unit_flag");  pSaoParam->oneUnitFlag[1] = uiSymbol? true:false; 
     364      if (pSaoParam->oneUnitFlag[1] )
     365        xParseSaoOffset(&(pSaoParam->saoLcuParam[1][0]));
     366    }
     367    if (pSaoParam->bSaoFlag[2])
     368    {
     369      READ_FLAG (uiSymbol, "sao_one_cr_unit_flag");  pSaoParam->oneUnitFlag[2] = uiSymbol? true:false; 
     370      if (pSaoParam->oneUnitFlag[2] )
     371        xParseSaoOffset(&(pSaoParam->saoLcuParam[2][0]));
     372    }
     373    for (j=0;j<numCuInHeight;j++)
     374    {
     375      for (compIdx=0;compIdx<3;compIdx++)
     376      {
     377        repeatedRow[compIdx] = 0;
     378      }
     379      for (i=0;i<numCuInWidth;i++)
     380      {
     381        for (compIdx=0; compIdx<3; compIdx++)
     382        {
     383          if (pSaoParam->bSaoFlag[compIdx]  && !pSaoParam->oneUnitFlag[compIdx])
     384          {
     385            if (j>0 && i==0)
     386            {
     387              READ_FLAG (uiSymbol, "sao_repeat_row_flag");  repeatedRow[compIdx] = uiSymbol? true:false;
     388            }
     389            xParseSaoUnit (i,j, compIdx, pSaoParam, repeatedRow[compIdx]);
     390          }
     391        }
     392      }
     393    }
     394  }
     395#else
     396  if (pSaoParam->bSaoFlag[0])
     397  {
     398    xParseSaoSplitParam (pSaoParam, 0, 0);
     399    xParseSaoOffsetParam(pSaoParam, 0, 0);
     400    READ_FLAG (uiSymbol, "sao_flag_cb");
     401    pSaoParam->bSaoFlag[1] = uiSymbol? true:false;
     402    if (pSaoParam->bSaoFlag[1])
     403    {
     404      xParseSaoSplitParam (pSaoParam, 0, 1);
     405      xParseSaoOffsetParam(pSaoParam, 0, 1);
     406    }
     407
     408    READ_FLAG (uiSymbol, "sao_flag_cr");
     409    pSaoParam->bSaoFlag[2] = uiSymbol? true:false;
     410    if (pSaoParam->bSaoFlag[2])
     411    {
     412      xParseSaoSplitParam (pSaoParam, 0, 2);
     413      xParseSaoOffsetParam(pSaoParam, 0, 2);
     414    }
     415  }
     416#endif
     417}
     418#if SAO_UNIT_INTERLEAVING
     419/** copy SAO parameter
     420 * \param dst 
     421 * \param src
     422 */
     423inline Void copySaoOneLcuParam(SaoLcuParam* dst,  SaoLcuParam* src)
     424{
     425  Int i;
     426  dst->partIdx = src->partIdx;
     427  dst->typeIdx = src->typeIdx;
     428  if (dst->typeIdx != -1)
     429  {
     430    if (dst->typeIdx == SAO_BO)
     431    {
     432      dst->bandPosition = src->bandPosition ;
     433    }
     434    else
     435    {
     436      dst->bandPosition = 0;
     437    }
     438    dst->length  = src->length;
     439    for (i=0;i<dst->length;i++)
     440    {
     441      dst->offset[i] = src->offset[i];
     442    }
     443  }
     444  else
     445  {
     446    dst->length  = 0;
     447    for (i=0;i<SAO_BO_LEN;i++)
     448    {
     449      dst->offset[i] = 0;
     450    }
     451  }
     452}
     453/** parse SAO offset
     454 * \param saoLcuParam SAO LCU parameters
     455 */
     456Void TDecCavlc::xParseSaoOffset(SaoLcuParam* saoLcuParam)
     457{
     458  UInt uiSymbol;
     459  Int iSymbol;
     460  static Int typeLength[MAX_NUM_SAO_TYPE] = {
     461    SAO_EO_LEN,
     462    SAO_EO_LEN,
     463    SAO_EO_LEN,
     464    SAO_EO_LEN,
     465    SAO_BO_LEN
     466  };
     467
     468  READ_UVLC (uiSymbol, "sao_type_idx");   saoLcuParam->typeIdx = (Int)uiSymbol - 1;       
     469  if (uiSymbol)
     470  {
     471    saoLcuParam->length = typeLength[saoLcuParam->typeIdx];
     472    if( saoLcuParam->typeIdx == SAO_BO )
     473    {
     474      READ_CODE( 5, uiSymbol, "sao_band_position"); saoLcuParam->bandPosition = uiSymbol;
     475      for(Int i=0; i< saoLcuParam->length; i++)
     476      {
     477        READ_SVLC (iSymbol, "sao_offset");    saoLcuParam->offset[i] = iSymbol;   
     478      }   
     479    }
     480    else if( saoLcuParam->typeIdx < 4 )
     481    {
     482      READ_UVLC (uiSymbol, "sao_offset");  saoLcuParam->offset[0] = uiSymbol;
     483      READ_UVLC (uiSymbol, "sao_offset");  saoLcuParam->offset[1] = uiSymbol;
     484      READ_UVLC (uiSymbol, "sao_offset");  saoLcuParam->offset[2] = -(Int)uiSymbol;
     485      READ_UVLC (uiSymbol, "sao_offset");  saoLcuParam->offset[3] = -(Int)uiSymbol;
     486    }
     487  }
     488  else
     489  {
     490    saoLcuParam->length = 0;
     491  }
     492}
     493
     494/** parse SAO unit
     495 * \param rx x-axis location
     496 * \param ry y-axis location
     497 * \param compIdx color component index
     498 * \param saoParam SAO parameters
     499 * \param repeatedRow repeat row flag
     500 */
     501void TDecCavlc::xParseSaoUnit(Int rx, Int ry, Int compIdx, SAOParam* saoParam, Bool& repeatedRow )
     502{
     503  int addr, addrUp, addrLeft;
     504  int numCuInWidth  = saoParam->numCuInWidth;
     505  SaoLcuParam* saoOneLcu;
     506  SaoLcuParam* saoOneLcuUp;
     507  SaoLcuParam* saoOneLcuLeft;
     508  UInt uiSymbol;
     509  Int  iSymbol;
     510  Int  runLeft;
     511  UInt maxValue;
     512
     513  addr      =  rx + ry*numCuInWidth;
     514  addrLeft  =  (addr%numCuInWidth == 0) ? -1 : addr - 1;
     515  addrUp    =  (addr<numCuInWidth)      ? -1 : addr - numCuInWidth;
     516
     517  saoOneLcu = &(saoParam->saoLcuParam[compIdx][addr]);     
     518  if (!repeatedRow)
     519  {
     520    runLeft = (addrLeft>=0 )  ? saoParam->saoLcuParam[compIdx][addrLeft].run : -1;
     521    if (rx == 0 || runLeft==0)
     522    {
     523      saoOneLcu->mergeLeftFlag = 0;
     524      if (ry == 0)
     525      {
     526        maxValue = numCuInWidth-rx-1;
     527        UInt length = 0;
     528        UInt val = 0;
     529        if (maxValue)
     530        {
     531          for(UInt i=0; i<32; i++)
     532          {
     533            if(maxValue&0x1)
     534            {
     535              length = i+1;
     536            }
     537            maxValue = (maxValue >> 1);
     538          }
     539          if(length)
     540          {
     541            READ_CODE(length, val, "sao_run_diff");
     542          }
     543        }
     544        uiSymbol = val;
     545        saoOneLcu->runDiff = uiSymbol;
     546        xParseSaoOffset(saoOneLcu);
     547        saoOneLcu->run = saoOneLcu->runDiff;
     548      }
     549      else
     550      {
     551        saoOneLcuUp = &(saoParam->saoLcuParam[compIdx][addrUp]);
     552        READ_SVLC (iSymbol , "sao_run_diff"     );  saoOneLcu->runDiff = iSymbol;
     553        READ_FLAG (uiSymbol, "sao_merge_up_flag");  saoOneLcu->mergeUpFlag   = uiSymbol? true:false;
     554        if (!saoOneLcu->mergeUpFlag)
     555        {
     556          xParseSaoOffset(saoOneLcu);
     557        }
     558        else
     559        {
     560          saoOneLcuUp = &(saoParam->saoLcuParam[compIdx][addrUp]);
     561          copySaoOneLcuParam(saoOneLcu, saoOneLcuUp);
     562        }
     563        saoOneLcu->run = saoOneLcu->runDiff + saoOneLcuUp->run;
     564      }
     565    }
     566    else
     567    {
     568      saoOneLcuLeft = &(saoParam->saoLcuParam[compIdx][addrLeft]);
     569      copySaoOneLcuParam(saoOneLcu, saoOneLcuLeft);
     570      saoOneLcu->mergeLeftFlag = 1;
     571      saoOneLcu->run = saoOneLcuLeft->run-1;
     572    }
     573  }
     574  else
     575  {
     576    if (ry > 0)
     577    {
     578      saoOneLcuUp = &(saoParam->saoLcuParam[compIdx][addrUp]);
     579      copySaoOneLcuParam(saoOneLcu, saoOneLcuUp);
     580      saoOneLcu->mergeLeftFlag = 0;
     581      saoOneLcu->run = saoOneLcuUp->run;
     582    }
     583  }
     584}
     585
     586#else
     587/** Decode quadtree split flag
     588 * \param  pSaoParam, iPartIdx
     589 */
     590Void TDecCavlc::xParseSaoSplitParam(SAOParam* pSaoParam, Int iPartIdx, Int iYCbCr)
     591{
     592  UInt uiSymbol;
     593  SAOQTPart*  pSaoPart = NULL;
     594  pSaoPart= &(pSaoParam->psSaoPart[iYCbCr][iPartIdx]);
     595
     596  if(pSaoPart->PartLevel < pSaoParam->iMaxSplitLevel)
     597  {
     598    READ_FLAG (uiSymbol, "sao_split_flag");
     599    pSaoPart->bSplit = uiSymbol? true:false;
     600    if(pSaoPart->bSplit)
     601    {
     602      for (Int i=0;i<NUM_DOWN_PART;i++)
     603      {
     604        xParseSaoSplitParam(pSaoParam, pSaoPart->DownPartsIdx[i], iYCbCr);
     605      }
     606    }
     607  }
     608  else
     609  {
     610    pSaoPart->bSplit = false;
     611  }
     612}
     613
     614/** Decode SAO for one partition
     615 * \param  pSaoParam, iPartIdx
     616 */
     617Void TDecCavlc::xParseSaoOffsetParam(SAOParam* pSaoParam, Int iPartIdx, Int iYCbCr)
     618{
     619  UInt uiSymbol;
     620  Int iSymbol; 
     621  SAOQTPart*  pSaoPart = NULL;
     622  pSaoPart = &(pSaoParam->psSaoPart[iYCbCr][iPartIdx]);
     623
     624  static Int iTypeLength[MAX_NUM_SAO_TYPE] = {
     625    SAO_EO_LEN,
     626    SAO_EO_LEN,
     627    SAO_EO_LEN,
     628    SAO_EO_LEN,
     629    SAO_BO_LEN,
     630    SAO_BO_LEN
     631  }; 
     632  if(!pSaoPart->bSplit)
     633  {
     634    READ_UVLC (uiSymbol, "sao_type_idx");
     635    if (uiSymbol)
     636    {
     637      pSaoPart->iBestType = uiSymbol-1;
     638      pSaoPart->bEnableFlag = true;
     639    }
     640    else
     641    {
     642      pSaoPart->iBestType = -1;
     643      pSaoPart->bEnableFlag = false;
     644    }
     645
     646    if (pSaoPart->bEnableFlag)
     647    {
     648      pSaoPart->iLength = iTypeLength[pSaoPart->iBestType];
     649      for(Int i=0; i< pSaoPart->iLength; i++)
     650      {
     651        READ_SVLC (iSymbol, "sao_offset");
     652        pSaoPart->iOffset[i] = iSymbol;
     653      }
     654    }
     655    return;
     656  }
     657
     658  //split
     659  if (pSaoPart->PartLevel < pSaoParam->iMaxSplitLevel)
     660  {
     661    for(Int i=0;i<NUM_DOWN_PART;i++)
     662    {
     663      xParseSaoOffsetParam(pSaoParam, pSaoPart->DownPartsIdx[i], iYCbCr);
     664    }
     665  }
     666}
     667#endif
     668
     669#if LCU_SYNTAX_ALF
     670Void TDecCavlc::xParseAlfParam(AlfParamSet* pAlfParamSet, Bool bSentInAPS, Int firstLCUAddr, Bool acrossSlice, Int numLCUInWidth, Int numLCUInHeight)
     671{
     672  Int  numLCU;
     673  UInt uiSymbol;
     674  Bool isEnabled[NUM_ALF_COMPONENT];
     675  Bool isUniParam[NUM_ALF_COMPONENT];
     676 
     677  isEnabled[ALF_Y] = true;
     678  READ_FLAG(uiSymbol, "alf_cb_enable_flag");  isEnabled[ALF_Cb] = ((uiSymbol ==1)?true:false);
     679  READ_FLAG(uiSymbol, "alf_cr_enable_flag");  isEnabled[ALF_Cr] = ((uiSymbol ==1)?true:false);
     680  READ_FLAG(uiSymbol, "alf_one_luma_unit_per_slice_flag");   isUniParam[ALF_Y] = ((uiSymbol ==1)?true:false);
     681 
     682  isUniParam[ALF_Cb] = true;
     683  if (isEnabled[ALF_Cb])
     684  {
     685    READ_FLAG(uiSymbol, "alf_one_cb_unit_per_slice_flag");   isUniParam[ALF_Cb] = ((uiSymbol ==1)?true:false);
     686  }
     687 
     688  isUniParam[ALF_Cr] = true;
     689  if (isEnabled[ALF_Cr])
     690  {
     691    READ_FLAG(uiSymbol, "alf_one_cr_unit_per_slice_flag");   isUniParam[ALF_Cr] = ((uiSymbol ==1)?true:false);
     692  }
     693 
     694  if(bSentInAPS)
     695  {
     696    READ_UVLC(uiSymbol, "alf_num_lcu_in_width_minus1");  numLCUInWidth = uiSymbol+1;
     697    READ_UVLC(uiSymbol, "alf_num_lcu_in_height_minus1");  numLCUInHeight = uiSymbol+1;
     698    numLCU = numLCUInWidth*numLCUInHeight;
     699  }
     700  else //sent in slice header
     701  {
     702    READ_UVLC(uiSymbol, "alf_num_lcu_in_slice_minus1");  numLCU = uiSymbol+1;
     703  }
     704 
     705  assert(pAlfParamSet != NULL);
     706 
     707  pAlfParamSet->create(numLCUInWidth, numLCUInHeight, numLCU);
     708  for(Int compIdx = 0; compIdx < NUM_ALF_COMPONENT; compIdx++)
     709  {
     710    pAlfParamSet->isEnabled[compIdx] = isEnabled[compIdx];
     711    pAlfParamSet->isUniParam[compIdx]= isUniParam[compIdx];
     712  }
     713 
     714  parseAlfParamSet(pAlfParamSet, firstLCUAddr, acrossSlice);
     715}
     716
     717
     718Void TDecCavlc::parseAlfParamSet(AlfParamSet* pAlfParamSet, Int firstLCUAddr, Bool alfAcrossSlice)
     719{
     720  Int numLCUInWidth = pAlfParamSet->numLCUInWidth;
     721  Int numLCU        = pAlfParamSet->numLCU;
     722 
     723  static Bool isRepeatedRow   [NUM_ALF_COMPONENT];
     724  static Int  numStoredFilters[NUM_ALF_COMPONENT];
     725  static Int* run             [NUM_ALF_COMPONENT];
     726 
     727  for(Int compIdx =0; compIdx < NUM_ALF_COMPONENT; compIdx++)
     728  {
     729    isRepeatedRow[compIdx]    = false;
     730    numStoredFilters[compIdx] = 0;
     731   
     732    run[compIdx] = new Int[numLCU+1];
     733    run[compIdx][0] = -1;
     734  }
     735 
     736  UInt uiSymbol;
     737  Int  iSymbol, ry, rx, addrUp;
     738 
     739  for(Int i=0; i< numLCU; i++)
     740  {
     741    rx    = (i+ firstLCUAddr)% numLCUInWidth;
     742    ry    = (i+ firstLCUAddr)/ numLCUInWidth;
     743   
     744    for(Int compIdx =0; compIdx < NUM_ALF_COMPONENT; compIdx++)
     745    {
     746      AlfUnitParam& alfUnitParam = pAlfParamSet->alfUnitParam[compIdx][i];
     747     
     748      if(pAlfParamSet->isEnabled[compIdx])
     749      {
     750        if(!pAlfParamSet->isUniParam[compIdx])
     751        {
     752          addrUp = i-numLCUInWidth;
     753          if(rx ==0 && addrUp >=0)
     754          {
     755            READ_FLAG(uiSymbol, "alf_repeat_row _flag"); isRepeatedRow[compIdx] = ((uiSymbol ==1)?true:false);
     756          }
     757         
     758          if(isRepeatedRow[compIdx])
     759          {
     760            alfUnitParam.mergeType = ALF_MERGE_UP;
     761            assert(addrUp >=0);
     762            run[compIdx][i] = run[compIdx][addrUp];
     763          }
     764          else
     765          {
     766            if(rx == 0 || run[compIdx][i] < 0)
     767            {             
     768              if(addrUp < 0)
     769              {
     770                //alf_run_diff u(v)
     771                parseAlfFixedLengthRun(uiSymbol, rx, numLCUInWidth);
     772                run[compIdx][i] = uiSymbol;
     773              }
     774              else
     775              {
     776                //alf_run_diff s(v)
     777                READ_SVLC(iSymbol, "alf_run_diff");
     778                run[compIdx][i] = run[compIdx][addrUp] + iSymbol;
     779                assert(run[compIdx][i] >= 0);
     780              }
     781             
     782              if(ry > 0 && (addrUp >=0 || alfAcrossSlice))
     783              {
     784                //alf_merge_up_flag
     785                READ_FLAG(uiSymbol, "alf_merge_up_flag");  alfUnitParam.mergeType = ((uiSymbol ==1)?ALF_MERGE_UP:ALF_MERGE_DISABLED);
     786              }
     787              else
     788              {
     789                alfUnitParam.mergeType = ALF_MERGE_DISABLED;
     790              }
     791             
     792              if(alfUnitParam.mergeType != ALF_MERGE_UP)
     793              {
     794                //alf_lcu_enable_flag
     795                READ_FLAG(uiSymbol, "alf_lcu_enable_flag");  alfUnitParam.isEnabled = ((uiSymbol ==1)?true:false);
     796               
     797                if(alfUnitParam.isEnabled)
     798                {
     799                  if(numStoredFilters[compIdx] > 0)
     800                  {
     801                    //alf_new_filter_set_flag
     802                    READ_FLAG(uiSymbol, "alf_new_filter_set_flag");  alfUnitParam.isNewFilt = ((uiSymbol ==1)?true:false);
     803                   
     804                    if(!alfUnitParam.isNewFilt)
     805                    {
     806                      //alf_stored_filter_set_idx
     807                      parseAlfStoredFilterIdx(uiSymbol, numStoredFilters[compIdx]);
     808                     
     809                      alfUnitParam.storedFiltIdx = uiSymbol;
     810                     
     811                      assert( alfUnitParam.storedFiltIdx < numStoredFilters[compIdx]);
     812                    }
     813                  }
     814                  else
     815                  {
     816                    alfUnitParam.isNewFilt = true;
     817                  }
     818                 
     819                  if(alfUnitParam.isNewFilt)
     820                  {
     821                    alfUnitParam.alfFiltParam = new ALFParam(compIdx);
     822                    xParseAlfParam(alfUnitParam.alfFiltParam);
     823                    alfUnitParam.alfFiltParam->alf_flag = 1;
     824                   
     825                    numStoredFilters[compIdx]++;
     826                  }
     827                }
     828               
     829              }
     830            }
     831            else
     832            {
     833              alfUnitParam.mergeType = ALF_MERGE_LEFT;
     834            }
     835           
     836            run[compIdx][i+1] = run[compIdx][i] -1;
     837          }
     838         
     839        }
     840        else // uni-param
     841        {
     842          if(i == 0)
     843          {
     844            alfUnitParam.mergeType = ALF_MERGE_DISABLED;
     845           
     846            //alf_lcu_enable_flag
     847            READ_FLAG(uiSymbol, "alf_lcu_enable_flag");  alfUnitParam.isEnabled = ((uiSymbol ==1)?true:false);
     848            if(alfUnitParam.isEnabled)
     849            {
     850              alfUnitParam.isNewFilt = true;
     851              alfUnitParam.alfFiltParam = new ALFParam(compIdx);
     852              xParseAlfParam(alfUnitParam.alfFiltParam);
     853              alfUnitParam.alfFiltParam->alf_flag = 1;
     854            }
     855          }
     856          else
     857          {
     858            alfUnitParam.mergeType = ALF_MERGE_FIRST;
     859          }
     860         
     861        }
     862      }
     863      else
     864      {
     865        alfUnitParam.mergeType = ALF_MERGE_DISABLED;
     866        alfUnitParam.isEnabled = false;
     867      }
     868    }
     869  }
     870 
     871  for(Int compIdx =0; compIdx < NUM_ALF_COMPONENT; compIdx++)
     872  {
     873    delete[] run[compIdx];
     874  }
     875}
     876
     877
     878Void TDecCavlc::parseAlfFixedLengthRun( UInt& idx, UInt rx, UInt numLCUInWidth )
     879{
     880  assert(numLCUInWidth > rx);
     881 
     882  UInt length = 0; 
     883  UInt maxNumRun = numLCUInWidth - rx - 1;
     884 
     885  for(UInt i=0; i<32; i++)
     886  {
     887    if(maxNumRun&0x1)
     888    {
     889      length = i+1;
     890    }
     891    maxNumRun = (maxNumRun >> 1);
     892  }
     893 
     894  idx = 0;
     895  if(length)
     896  {
     897    READ_CODE( length, idx, "alf_run_diff" );
     898  }
     899  else
     900  {
     901    idx = 0;
     902  }
     903}
     904
     905
     906Void TDecCavlc::parseAlfStoredFilterIdx( UInt& idx, UInt numFilterSetsInBuffer )
     907{
     908  assert(numFilterSetsInBuffer > 0);
     909 
     910  UInt length = 0; 
     911  UInt maxValue = numFilterSetsInBuffer - 1;
     912 
     913  for(UInt i=0; i<32; i++)
     914  {
     915    if(maxValue&0x1)
     916    {
     917      length = i+1;
     918    }
     919    maxValue = (maxValue >> 1);
     920  }
     921 
     922  idx = 0;
     923  if(length)
     924  {
     925    READ_CODE( length, idx, "alf_stored_filter_set_idx" );
     926  }
     927  else
     928  {
     929    idx = 0;
     930  }
     931}
     932
     933#endif
     934
     935Void TDecCavlc::xParseAlfParam(ALFParam* pAlfParam)
     936{
     937  UInt uiSymbol;
     938  Int iSymbol;
     939#if ALF_SINGLE_FILTER_SHAPE
     940  Int sqrFiltLengthTab[NUM_ALF_FILTER_SHAPE] = {ALF_FILTER_LEN};
     941#else
     942  Int sqrFiltLengthTab[2] = { 9, 9};
     943#endif
     944
     945#if LCU_SYNTAX_ALF
     946  switch(pAlfParam->componentID)
     947  {
     948  case ALF_Cb:
     949  case ALF_Cr:
     950    {
     951      pAlfParam->filter_shape = ALF_CROSS9x7_SQUARE3x3;
     952      pAlfParam->num_coeff = sqrFiltLengthTab[pAlfParam->filter_shape];
     953      pAlfParam->filters_per_group = 1;
     954      for(Int pos=0; pos< pAlfParam->num_coeff; pos++)
     955      {
     956        READ_SVLC(iSymbol, "alf_filt_coeff");
     957        pAlfParam->coeffmulti[0][pos] = iSymbol;
     958      }
     959    }
     960    break;
     961  case ALF_Y:
     962    {
     963#endif
     964  pAlfParam->filters_per_group = 0;
     965  memset (pAlfParam->filterPattern, 0 , sizeof(Int)*NO_VAR_BINS);
     966#if !LCU_SYNTAX_ALF
     967  READ_FLAG (uiSymbol, "alf_region_adaptation_flag");
     968  pAlfParam->alf_pcr_region_flag = uiSymbol; 
     969#endif
     970#if ALF_SINGLE_FILTER_SHAPE 
     971  pAlfParam->filter_shape = 0;
     972#else
     973  READ_UVLC (uiSymbol, "alf_length_luma_minus_5_div2");
     974  pAlfParam->filter_shape = uiSymbol;
     975#endif
     976  pAlfParam->num_coeff = sqrFiltLengthTab[pAlfParam->filter_shape];
     977
     978  // filters_per_fr
     979  READ_UVLC (uiSymbol, "alf_no_filters_minus1");
     980  pAlfParam->filters_per_group = uiSymbol + 1;
     981
     982  if(uiSymbol == 1) // filters_per_group == 2
     983  {
     984    READ_UVLC (uiSymbol, "alf_start_second_filter");
     985    pAlfParam->startSecondFilter = uiSymbol;
     986    pAlfParam->filterPattern [uiSymbol] = 1;
     987  }
     988  else if (uiSymbol > 1) // filters_per_group > 2
     989  {
     990    pAlfParam->filters_per_group = 1;
     991#if LCU_SYNTAX_ALF
     992#if ALF_16_BA_GROUPS
     993    Int numMergeFlags = 16;
     994#else
     995    Int numMergeFlags = 15;
     996#endif
     997#else
     998#if ALF_16_BA_GROUPS
     999    Int numMergeFlags = 16;
     1000#else
     1001    Int numMergeFlags = pAlfParam->alf_pcr_region_flag ? 16 : 15;
     1002#endif
     1003#endif
     1004    for (Int i=1; i<numMergeFlags; i++)
     1005    {
     1006      READ_FLAG (uiSymbol,  "alf_filter_pattern");
     1007      pAlfParam->filterPattern[i] = uiSymbol;
     1008      pAlfParam->filters_per_group += uiSymbol;
     1009    }
     1010  }
     1011
     1012  if (pAlfParam->filters_per_group > 1)
     1013  {
     1014    READ_FLAG (uiSymbol, "alf_pred_method");
     1015    pAlfParam->predMethod = uiSymbol;
     1016  }
     1017  for(Int idx = 0; idx < pAlfParam->filters_per_group; ++idx)
     1018  {
     1019    READ_FLAG (uiSymbol,"alf_nb_pred_luma");
     1020    pAlfParam->nbSPred[idx] = uiSymbol;
     1021  }
     1022
     1023#if ALF_SINGLE_FILTER_SHAPE
     1024  Int minScanVal = MIN_SCAN_POS_CROSS;
     1025#else
     1026  Int minScanVal = (pAlfParam->filter_shape == ALF_STAR5x5) ? 0: MIN_SCAN_POS_CROSS;
     1027#endif
     1028
     1029  // Determine maxScanVal
     1030  Int maxScanVal = 0;
     1031  Int *pDepthInt = pDepthIntTabShapes[pAlfParam->filter_shape];
     1032  for(Int idx = 0; idx < pAlfParam->num_coeff; idx++)
     1033  {
     1034    maxScanVal = max(maxScanVal, pDepthInt[idx]);
     1035  }
     1036
     1037  // Golomb parameters
     1038#if LCU_SYNTAX_ALF
     1039  if( pAlfParam->filters_per_group > 1 )
     1040  {
     1041#endif
     1042  READ_UVLC (uiSymbol, "alf_min_kstart_minus1");
     1043  pAlfParam->minKStart = 1 + uiSymbol;
     1044
     1045  Int kMin = pAlfParam->minKStart;
     1046
     1047  for(Int scanPos = minScanVal; scanPos < maxScanVal; scanPos++)
     1048  {
     1049    READ_FLAG (uiSymbol, "alf_golomb_index_bit");
     1050    pAlfParam->kMinTab[scanPos] = kMin + uiSymbol;
     1051    kMin = pAlfParam->kMinTab[scanPos];
     1052  }
     1053#if LCU_SYNTAX_ALF
     1054  }
     1055#endif
     1056
     1057  Int scanPos;
     1058  for(Int idx = 0; idx < pAlfParam->filters_per_group; ++idx)
     1059  {
     1060    for(Int i = 0; i < pAlfParam->num_coeff; i++)
     1061    {
     1062      scanPos = pDepthInt[i] - 1;
     1063#if LCU_SYNTAX_ALF
     1064      Int k = (pAlfParam->filters_per_group == 1) ? kTableTabShapes[ALF_CROSS9x7_SQUARE3x3][i] : pAlfParam->kMinTab[scanPos];
     1065      pAlfParam->coeffmulti[idx][i] = xGolombDecode(k);
     1066#else
     1067      pAlfParam->coeffmulti[idx][i] = xGolombDecode(pAlfParam->kMinTab[scanPos]);
     1068#endif
     1069    }
     1070  }
     1071#if LCU_SYNTAX_ALF
     1072    }
     1073    break;
     1074  default:
     1075    {
     1076      printf("Not a legal component ID for ALF\n");
     1077      assert(0);
     1078      exit(-1);
     1079    }
     1080  }
     1081#else
     1082  // filter parameters for chroma
     1083  READ_UVLC (uiSymbol, "alf_chroma_idc");
     1084  pAlfParam->chroma_idc = uiSymbol;
     1085
     1086  if(pAlfParam->chroma_idc)
     1087  {
     1088
     1089#if ALF_SINGLE_FILTER_SHAPE
     1090    pAlfParam->filter_shape_chroma  = 0;
     1091#else
     1092    READ_UVLC (uiSymbol, "alf_length_chroma_minus_5_div2");
     1093
     1094    pAlfParam->filter_shape_chroma = uiSymbol;
     1095#endif
     1096    pAlfParam->num_coeff_chroma = sqrFiltLengthTab[pAlfParam->filter_shape_chroma];
     1097    // filter coefficients for chroma
     1098    for(Int pos=0; pos<pAlfParam->num_coeff_chroma; pos++)
     1099    {
     1100      READ_SVLC (iSymbol, "alf_coeff_chroma");
     1101      pAlfParam->coeff_chroma[pos] = iSymbol;
     1102    }
     1103  }
     1104#endif
     1105}
     1106
     1107Int TDecCavlc::xGolombDecode(Int k)
     1108{
     1109  UInt uiSymbol;
     1110  Int q = -1;
     1111  Int nr = 0;
     1112  Int a;
     1113
     1114  uiSymbol = 1;
     1115  while (uiSymbol)
     1116  {
     1117    xReadFlag(uiSymbol);
     1118    q++;
     1119  }
     1120  for(a = 0; a < k; ++a)          // read out the sequential log2(M) bits
     1121  {
     1122    xReadFlag(uiSymbol);
     1123    if(uiSymbol)
     1124      nr += 1 << a;
     1125  }
     1126  nr += q << k;
     1127  if(nr != 0)
     1128  {
     1129    xReadFlag(uiSymbol);
     1130    nr = (uiSymbol)? nr: -nr;
     1131  }
     1132#if ENC_DEC_TRACE
     1133  fprintf( g_hTrace, "%8lld  ", g_nSymbolCounter++ );
     1134  fprintf( g_hTrace, "%-40s ge(v) : %d\n", "alf_coeff_luma", nr );
     1135#endif
     1136  return nr;
     1137}
     1138
     1139#if TILES_OR_ENTROPY_SYNC_IDC
     1140Void TDecCavlc::parsePPS(TComPPS* pcPPS, ParameterSetManagerDecoder *parameterSet)
     1141#else
    1411142Void TDecCavlc::parsePPS(TComPPS* pcPPS)
    142 {
     1143#endif
     1144{
     1145#if ENC_DEC_TRACE 
     1146  xTracePPSHeader (pcPPS);
     1147#endif
    1431148  UInt  uiCode;
    1441149
    145   xReadUvlc( uiCode ); pcPPS->setPPSId( uiCode );
    146   xReadUvlc( uiCode ); pcPPS->setSPSId( uiCode );
    147 #if CONSTRAINED_INTRA_PRED
    148   xReadFlag ( uiCode ); pcPPS->setConstrainedIntraPred( uiCode ? true : false );
    149 #endif
    150 
    151 #ifdef WEIGHT_PRED
    152   xReadCode( 1, uiCode );           // Use of Weighting Prediction (P_SLICE)
     1150  Int   iCode;
     1151
     1152#if !RPS_IN_SPS
     1153  TComRPSList* rpsList = pcPPS->getRPSList();
     1154#endif
     1155  READ_UVLC( uiCode, "pic_parameter_set_id");                      pcPPS->setPPSId (uiCode);
     1156  READ_UVLC( uiCode, "seq_parameter_set_id");                      pcPPS->setSPSId (uiCode);
     1157
     1158#if MULTIBITS_DATA_HIDING
     1159  READ_FLAG ( uiCode, "sign_data_hiding_flag" ); pcPPS->setSignHideFlag( uiCode );
     1160  if( pcPPS->getSignHideFlag() )
     1161  {
     1162    READ_CODE( 4, uiCode, "sign_hiding_threshold"); pcPPS->setTSIG(uiCode);
     1163  }
     1164#endif
     1165
     1166#if CABAC_INIT_FLAG
     1167  READ_FLAG( uiCode,   "cabac_init_present_flag" );            pcPPS->setCabacInitPresentFlag( uiCode ? true : false );
     1168#endif
     1169#if !RPS_IN_SPS
     1170  // RPS is put before entropy_coding_mode_flag
     1171  // since entropy_coding_mode_flag will probably be removed from the WD
     1172  TComReferencePictureSet*      pcRPS;
     1173
     1174  READ_UVLC( uiCode, "num_short_term_ref_pic_sets" );
     1175  rpsList->create(uiCode);
     1176
     1177  for(Int i=0; i< rpsList->getNumberOfReferencePictureSets(); i++)
     1178  {
     1179    pcRPS = rpsList->getReferencePictureSet(i);
     1180    parseShortTermRefPicSet(pcPPS,pcRPS,i);
     1181  }
     1182  READ_FLAG( uiCode, "long_term_ref_pics_present_flag" );          pcPPS->setLongTermRefsPresent(uiCode);
     1183#endif
     1184  // entropy_coding_mode_flag
     1185  // We code the entropy_coding_mode_flag, it's needed for tests.
     1186  READ_FLAG( uiCode, "entropy_coding_mode_flag" );                 pcPPS->setEntropyCodingMode( uiCode ? true : false );
     1187  if (pcPPS->getEntropyCodingMode())
     1188  {
     1189#if !WPP_SIMPLIFICATION
     1190    READ_UVLC( uiCode, "entropy_coding_synchro" );                 pcPPS->setEntropyCodingSynchro( uiCode );
     1191    READ_FLAG( uiCode, "cabac_istate_reset" );                     pcPPS->setCabacIstateReset( uiCode ? true : false );
     1192#endif
     1193#if !TILES_OR_ENTROPY_SYNC_IDC
     1194#if !WPP_SIMPLIFICATION
     1195    if ( pcPPS->getEntropyCodingSynchro() )
     1196#endif
     1197    {
     1198      READ_UVLC( uiCode, "num_substreams_minus1" );                pcPPS->setNumSubstreams(uiCode+1);
     1199    }
     1200#endif
     1201  }
     1202#if !H0566_TLA
     1203  READ_UVLC( uiCode, "num_temporal_layer_switching_point_flags" ); pcPPS->setNumTLayerSwitchingFlags( uiCode );
     1204  for ( UInt i = 0; i < pcPPS->getNumTLayerSwitchingFlags(); i++ )
     1205  {
     1206    READ_FLAG( uiCode, "temporal_layer_switching_point_flag" );    pcPPS->setTLayerSwitchingFlag( i, uiCode > 0 ? true : false );
     1207  }
     1208#endif
     1209 
     1210  // num_ref_idx_l0_default_active_minus1
     1211  // num_ref_idx_l1_default_active_minus1
     1212  READ_SVLC(iCode, "pic_init_qp_minus26" );                        pcPPS->setPicInitQPMinus26(iCode);
     1213  READ_FLAG( uiCode, "constrained_intra_pred_flag" );              pcPPS->setConstrainedIntraPred( uiCode ? true : false );
     1214  READ_FLAG( uiCode, "enable_temporal_mvp_flag" );                 pcPPS->setEnableTMVPFlag( uiCode ? true : false );
     1215  READ_CODE( 2, uiCode, "slice_granularity" );                     pcPPS->setSliceGranularity(uiCode);
     1216
     1217  // alf_param() ?
     1218
     1219  READ_UVLC( uiCode, "max_cu_qp_delta_depth");
     1220  if(uiCode == 0)
     1221  {
     1222    pcPPS->setUseDQP (false);
     1223    pcPPS->setMaxCuDQPDepth( 0 );
     1224  }
     1225  else
     1226  {
     1227    pcPPS->setUseDQP (true);
     1228    pcPPS->setMaxCuDQPDepth(uiCode - 1);
     1229  }
     1230
     1231  READ_SVLC( iCode, "chroma_qp_offset");
     1232  pcPPS->setChromaQpOffset(iCode);
     1233
     1234  READ_SVLC( iCode, "chroma_qp_offset_2nd");
     1235  pcPPS->setChromaQpOffset2nd(iCode);
     1236
     1237  READ_FLAG( uiCode, "weighted_pred_flag" );          // Use of Weighting Prediction (P_SLICE)
    1531238  pcPPS->setUseWP( uiCode==1 );
    154   xReadCode( 2, uiCode );           // Use of Bi-Directional Weighting Prediction (B_SLICE)
     1239  READ_CODE( 2, uiCode, "weighted_bipred_idc" );      // Use of Bi-Directional Weighting Prediction (B_SLICE)
    1551240  pcPPS->setWPBiPredIdc( uiCode );
    156   printf("TDecCavlc::parsePPS():\tm_bUseWeightPred=%d\tm_uiBiPredIdc=%d\n", pcPPS->getUseWP(), pcPPS->getWPBiPredIdc());
    157 #endif
    158   return;
    159 }
    160 
     1241//printf("TDecCavlc::parsePPS():\tm_bUseWeightPred=%d\tm_uiBiPredIdc=%d\n", pcPPS->getUseWP(), pcPPS->getWPBiPredIdc());
     1242
     1243#if H0388
     1244  READ_FLAG( uiCode, "output_flag_present_flag" );
     1245  pcPPS->setOutputFlagPresentFlag( uiCode==1 );
     1246#endif
     1247
     1248#if TILES_OR_ENTROPY_SYNC_IDC
     1249  if(parameterSet->getPrefetchedSPS(pcPPS->getSPSId())->getTilesOrEntropyCodingSyncIdc()==1)
     1250  {
     1251#endif
     1252    READ_FLAG ( uiCode, "tile_info_present_flag" );
     1253    pcPPS->setColumnRowInfoPresent(uiCode);
     1254    READ_FLAG ( uiCode, "tile_control_present_flag" );
     1255    pcPPS->setTileBehaviorControlPresentFlag(uiCode);
     1256    if( pcPPS->getColumnRowInfoPresent() == 1 )
     1257    {
     1258      READ_UVLC ( uiCode, "num_tile_columns_minus1" );   
     1259      pcPPS->setNumColumnsMinus1( uiCode ); 
     1260      READ_UVLC ( uiCode, "num_tile_rows_minus1" ); 
     1261      pcPPS->setNumRowsMinus1( uiCode ); 
     1262      READ_FLAG ( uiCode, "uniform_spacing_flag" ); 
     1263      pcPPS->setUniformSpacingIdr( uiCode );
     1264
     1265      if( pcPPS->getUniformSpacingIdr() == 0 )
     1266      {
     1267        UInt* columnWidth = (UInt*)malloc(pcPPS->getNumColumnsMinus1()*sizeof(UInt));
     1268        for(UInt i=0; i<pcPPS->getNumColumnsMinus1(); i++)
     1269        {
     1270          READ_UVLC( uiCode, "column_width" ); 
     1271          columnWidth[i] = uiCode; 
     1272        }
     1273        pcPPS->setColumnWidth(columnWidth);
     1274        free(columnWidth);
     1275
     1276        UInt* rowHeight = (UInt*)malloc(pcPPS->getNumRowsMinus1()*sizeof(UInt));
     1277        for(UInt i=0; i<pcPPS->getNumRowsMinus1(); i++)
     1278        {
     1279          READ_UVLC( uiCode, "row_height" ); 
     1280          rowHeight[i] = uiCode; 
     1281        }
     1282        pcPPS->setRowHeight(rowHeight);
     1283        free(rowHeight); 
     1284      }
     1285    }
     1286
     1287
     1288    if(pcPPS->getTileBehaviorControlPresentFlag() == 1)
     1289    {
     1290      Int iNumColTilesMinus1 = (pcPPS->getColumnRowInfoPresent() == 1)?(pcPPS->getNumColumnsMinus1()):(pcPPS->getSPS()->getNumColumnsMinus1());
     1291      Int iNumRowTilesMinus1 = (pcPPS->getColumnRowInfoPresent() == 1)?(pcPPS->getNumColumnsMinus1()):(pcPPS->getSPS()->getNumRowsMinus1());
     1292#if !REMOVE_TILE_DEPENDENCE
     1293      pcPPS->setTileBoundaryIndependenceIdr( 1 ); //default
     1294#endif
     1295      pcPPS->setLFCrossTileBoundaryFlag(true); //default
     1296
     1297      if(iNumColTilesMinus1 !=0 || iNumRowTilesMinus1 !=0)
     1298      {
     1299#if !REMOVE_TILE_DEPENDENCE
     1300        READ_FLAG ( uiCode, "tile_boundary_independence_flag" ); 
     1301        pcPPS->setTileBoundaryIndependenceIdr( uiCode );
     1302
     1303        if(pcPPS->getTileBoundaryIndependenceIdr() == 1)
     1304        {
     1305#endif
     1306          READ_FLAG ( uiCode, "loop_filter_across_tile_flag" ); 
     1307          pcPPS->setLFCrossTileBoundaryFlag( (uiCode == 1)?true:false );
     1308#if !REMOVE_TILE_DEPENDENCE
     1309        }
     1310#endif
     1311      }
     1312    }
     1313#if TILES_OR_ENTROPY_SYNC_IDC
     1314  }
     1315  else if(parameterSet->getPrefetchedSPS(pcPPS->getSPSId())->getTilesOrEntropyCodingSyncIdc()==2)
     1316  {
     1317    READ_UVLC( uiCode, "num_substreams_minus1" );                pcPPS->setNumSubstreams(uiCode+1);
     1318  }
     1319#endif
     1320
     1321#if DBL_CONTROL
     1322  READ_FLAG( uiCode, "deblocking_filter_control_present_flag" );
     1323  pcPPS->setDeblockingFilterControlPresent( uiCode ? true : false);
     1324#endif
     1325#if PARALLEL_MERGE
     1326  READ_UVLC( uiCode, "log2_parallel_merge_level_minus2");
     1327  assert(uiCode == LOG2_PARALLEL_MERGE_LEVEL_MINUS2);
     1328  pcPPS->setLog2ParallelMergeLevelMinus2 (uiCode);
     1329#endif
     1330
     1331  READ_FLAG( uiCode, "pps_extension_flag");
     1332  if (uiCode)
     1333  {
     1334    while ( xMoreRbspData() )
     1335    {
     1336      READ_FLAG( uiCode, "pps_extension_data_flag");
     1337    }
     1338  }
     1339}
     1340
     1341#if HHI_MPI
     1342Void TDecCavlc::parseSPS(TComSPS* pcSPS, Bool bIsDepth)
     1343#else
    1611344Void TDecCavlc::parseSPS(TComSPS* pcSPS)
    162 {
     1345#endif
     1346{
     1347#if ENC_DEC_TRACE 
     1348  xTraceSPSHeader (pcSPS);
     1349#endif
     1350 
    1631351  UInt  uiCode;
    1641352  Int   iCode;
    1651353
    166   // Structure
    167   xReadUvlc ( uiCode ); pcSPS->setSPSId       ( uiCode    );
    168   xReadUvlc ( uiCode ); pcSPS->setWidth       ( uiCode    );
    169   xReadUvlc ( uiCode ); pcSPS->setHeight      ( uiCode    );
    170   xReadUvlc ( uiCode ); pcSPS->setPadX        ( uiCode    );
    171   xReadUvlc ( uiCode ); pcSPS->setPadY        ( uiCode    );
    172 
    173   xReadUvlc ( uiCode );
    174   pcSPS->setMaxCUWidth  ( uiCode    ); g_uiMaxCUWidth  = uiCode;
    175   pcSPS->setMaxCUHeight ( uiCode    ); g_uiMaxCUHeight = uiCode;
    176 
    177   xReadUvlc ( uiCode );
    178   pcSPS->setMaxCUDepth  ( uiCode+1  ); g_uiMaxCUDepth  = uiCode + 1;
    179   UInt uiMaxCUDepthCorrect = uiCode;
    180 
    181   xReadUvlc( uiCode ); pcSPS->setQuadtreeTULog2MinSize( uiCode + 2 );
    182   xReadUvlc( uiCode ); pcSPS->setQuadtreeTULog2MaxSize( uiCode + pcSPS->getQuadtreeTULog2MinSize() );
    183   pcSPS->setMaxTrSize( 1<<(uiCode + pcSPS->getQuadtreeTULog2MinSize()) );
    184   xReadUvlc ( uiCode ); pcSPS->setQuadtreeTUMaxDepthInter( uiCode+1 );
    185   xReadUvlc ( uiCode ); pcSPS->setQuadtreeTUMaxDepthIntra( uiCode+1 );
    186   g_uiAddCUDepth = 0;
    187   while( ( pcSPS->getMaxCUWidth() >> uiMaxCUDepthCorrect ) > ( 1 << ( pcSPS->getQuadtreeTULog2MinSize() + g_uiAddCUDepth )  ) ) g_uiAddCUDepth++;
    188   pcSPS->setMaxCUDepth( uiMaxCUDepthCorrect+g_uiAddCUDepth  ); g_uiMaxCUDepth  = uiMaxCUDepthCorrect+g_uiAddCUDepth;
    189   // BB: these parameters may be removed completly and replaced by the fixed values
    190   pcSPS->setMinTrDepth( 0 );
    191   pcSPS->setMaxTrDepth( 1 );
    192 
    193   xReadUvlc( uiCode ); pcSPS->setCodedPictureBufferSize( uiCode );
    194 
    195   // Tool on/off
    196   xReadFlag( uiCode ); pcSPS->setUseALF ( uiCode ? true : false );
    197   xReadFlag( uiCode ); pcSPS->setUseDQP ( uiCode ? true : false );
    198 #if !HHI_NO_LowDelayCoding
    199   xReadFlag( uiCode ); pcSPS->setUseLDC ( uiCode ? true : false );
    200 #endif
    201   xReadFlag( uiCode ); pcSPS->setUseMRG ( uiCode ? true : false ); // SOPH:
    202 
    203 #if LM_CHROMA
    204   xReadFlag( uiCode ); pcSPS->setUseLMChroma ( uiCode ? true : false );
    205 #endif
    206 
    207 #if HHI_RMP_SWITCH
    208   xReadFlag( uiCode ); pcSPS->setUseRMP( uiCode ? true : false );
    209 #endif
    210 
    211   // AMVP mode for each depth (AM_NONE or AM_EXPL)
    212   for (Int i = 0; i < pcSPS->getMaxCUDepth(); i++)
    213   {
    214     xReadFlag( uiCode );
    215     pcSPS->setAMVPMode( i, (AMVP_MODE)uiCode );
    216   }
    217 
    218   // Bit-depth information
     1354  READ_CODE( 8,  uiCode, "profile_idc" );                        pcSPS->setProfileIdc( uiCode );
     1355  READ_CODE( 8,  uiCode, "reserved_zero_8bits" );
     1356  READ_CODE( 8,  uiCode, "level_idc" );                          pcSPS->setLevelIdc( uiCode );
     1357  READ_UVLC(     uiCode, "seq_parameter_set_id" );               pcSPS->setSPSId( uiCode );
     1358  READ_UVLC(     uiCode, "chroma_format_idc" );                  pcSPS->setChromaFormatIdc( uiCode );
     1359  READ_CODE( 3,  uiCode, "max_temporal_layers_minus1" );         pcSPS->setMaxTLayers( uiCode+1 );
     1360  READ_UVLC (    uiCode, "pic_width_in_luma_samples" );          pcSPS->setPicWidthInLumaSamples ( uiCode    );
     1361  READ_UVLC (    uiCode, "pic_height_in_luma_samples" );         pcSPS->setPicHeightInLumaSamples( uiCode    );
     1362#if PIC_CROPPING
     1363  READ_FLAG(     uiCode, "pic_cropping_flag");                   pcSPS->setPicCroppingFlag ( uiCode ? true : false );
     1364  if (uiCode != 0)
     1365  {
     1366    READ_UVLC(   uiCode, "pic_crop_left_offset" );               pcSPS->setPicCropLeftOffset( uiCode );
     1367    READ_UVLC(   uiCode, "pic_crop_right_offset" );              pcSPS->setPicCropRightOffset( uiCode );
     1368    READ_UVLC(   uiCode, "pic_crop_top_offset" );                pcSPS->setPicCropTopOffset( uiCode );
     1369    READ_UVLC(   uiCode, "pic_crop_bottom_offset" );             pcSPS->setPicCropBottomOffset( uiCode );
     1370  }
     1371#endif
     1372
    2191373#if FULL_NBIT
    220   xReadUvlc( uiCode );
     1374  READ_UVLC(     uiCode, "bit_depth_luma_minus8" );
    2211375  g_uiBitDepth = 8 + uiCode;
    2221376  g_uiBitIncrement = 0;
     
    2241378  pcSPS->setBitIncrement(g_uiBitIncrement);
    2251379#else
    226 #if ENABLE_IBDI
    227   xReadUvlc( uiCode ); pcSPS->setBitDepth     ( uiCode+8 ); g_uiBitDepth     = uiCode + 8;
    228   xReadUvlc( uiCode ); pcSPS->setBitIncrement ( uiCode   ); g_uiBitIncrement = uiCode;
    229 #else
    230   xReadUvlc( uiCode );
     1380  READ_UVLC(     uiCode, "bit_depth_luma_minus8" );
    2311381  g_uiBitDepth = 8;
    2321382  g_uiBitIncrement = uiCode;
     
    2341384  pcSPS->setBitIncrement(g_uiBitIncrement);
    2351385#endif
     1386 
     1387#if HHI_DMM_WEDGE_INTRA || HHI_DMM_PRED_TEX
     1388  g_iDeltaDCsQuantOffset = g_uiBitIncrement - 2;
     1389#endif
     1390
     1391#if H0736_AVC_STYLE_QP_RANGE
     1392  pcSPS->setQpBDOffsetY( (Int) (6*uiCode) );
    2361393#endif
    2371394
    2381395  g_uiBASE_MAX  = ((1<<(g_uiBitDepth))-1);
    239 
     1396 
    2401397#if IBDI_NOCLIP_RANGE
    2411398  g_uiIBDI_MAX  = g_uiBASE_MAX << g_uiBitIncrement;
     
    2431400  g_uiIBDI_MAX  = ((1<<(g_uiBitDepth+g_uiBitIncrement))-1);
    2441401#endif
     1402  READ_UVLC( uiCode,    "bit_depth_chroma_minus8" );
     1403#if H0736_AVC_STYLE_QP_RANGE
     1404  pcSPS->setQpBDOffsetC( (Int) (6*uiCode) );
     1405#endif
     1406
     1407  READ_FLAG( uiCode, "pcm_enabled_flag" ); pcSPS->setUsePCM( uiCode ? true : false );
     1408
     1409  if( pcSPS->getUsePCM() )
     1410  {
     1411    READ_CODE( 4, uiCode, "pcm_bit_depth_luma_minus1" );           pcSPS->setPCMBitDepthLuma   ( 1 + uiCode );
     1412    READ_CODE( 4, uiCode, "pcm_bit_depth_chroma_minus1" );         pcSPS->setPCMBitDepthChroma ( 1 + uiCode );
     1413  }
     1414
     1415#if LOSSLESS_CODING
     1416  READ_FLAG( uiCode, "qpprime_y_zero_transquant_bypass_flag" );    pcSPS->setUseLossless ( uiCode ? true : false );
     1417#endif
     1418
     1419  READ_UVLC( uiCode,    "log2_max_pic_order_cnt_lsb_minus4" );   pcSPS->setBitsForPOC( 4 + uiCode );
     1420#if H0567_DPB_PARAMETERS_PER_TEMPORAL_LAYER
     1421  for(UInt i=0; i <= pcSPS->getMaxTLayers()-1; i++)
     1422  {
     1423    READ_UVLC ( uiCode, "max_dec_pic_buffering");
     1424    pcSPS->setMaxDecPicBuffering( uiCode, i);
     1425    READ_UVLC ( uiCode, "num_reorder_pics" );
     1426    pcSPS->setNumReorderPics(uiCode, i);
     1427    READ_UVLC ( uiCode, "max_latency_increase");
     1428    pcSPS->setMaxLatencyIncrease( uiCode, i );
     1429  }
     1430#else
     1431  READ_UVLC( uiCode,    "max_num_ref_pics" );                    pcSPS->setMaxNumberOfReferencePictures(uiCode);
     1432  READ_UVLC( uiCode,    "num_reorder_frames" );                  pcSPS->setNumReorderFrames(uiCode);
     1433  READ_UVLC ( uiCode, "max_dec_frame_buffering");
     1434  pcSPS->setMaxDecFrameBuffering( uiCode );
     1435  READ_UVLC ( uiCode, "max_latency_increase");
     1436  pcSPS->setMaxLatencyIncrease( uiCode );
     1437#endif
     1438
     1439#if H0412_REF_PIC_LIST_RESTRICTION
     1440  READ_FLAG( uiCode, "restricted_ref_pic_lists_flag" );
     1441  pcSPS->setRestrictedRefPicListsFlag( uiCode );
     1442  if( pcSPS->getRestrictedRefPicListsFlag() )
     1443  {
     1444    READ_FLAG( uiCode, "lists_modification_present_flag" );
     1445    pcSPS->setListsModificationPresentFlag(uiCode);
     1446  }
     1447  else
     1448  {
     1449    pcSPS->setListsModificationPresentFlag(true);
     1450  }
     1451#endif
     1452  READ_UVLC( uiCode, "log2_min_coding_block_size_minus3" );
     1453  UInt log2MinCUSize = uiCode + 3;
     1454  READ_UVLC( uiCode, "log2_diff_max_min_coding_block_size" );
     1455  UInt uiMaxCUDepthCorrect = uiCode;
     1456  pcSPS->setMaxCUWidth  ( 1<<(log2MinCUSize + uiMaxCUDepthCorrect) ); g_uiMaxCUWidth  = 1<<(log2MinCUSize + uiMaxCUDepthCorrect);
     1457  pcSPS->setMaxCUHeight ( 1<<(log2MinCUSize + uiMaxCUDepthCorrect) ); g_uiMaxCUHeight = 1<<(log2MinCUSize + uiMaxCUDepthCorrect);
     1458  READ_UVLC( uiCode, "log2_min_transform_block_size_minus2" );   pcSPS->setQuadtreeTULog2MinSize( uiCode + 2 );
     1459
     1460  READ_UVLC( uiCode, "log2_diff_max_min_transform_block_size" ); pcSPS->setQuadtreeTULog2MaxSize( uiCode + pcSPS->getQuadtreeTULog2MinSize() );
     1461  pcSPS->setMaxTrSize( 1<<(uiCode + pcSPS->getQuadtreeTULog2MinSize()) );
     1462
     1463  if(log2MinCUSize == 3)
     1464  {
     1465    xReadFlag( uiCode ); pcSPS->setDisInter4x4( uiCode ? true : false );
     1466  }
     1467
     1468  if( pcSPS->getUsePCM() )
     1469  {
     1470    READ_UVLC( uiCode, "log2_min_pcm_coding_block_size_minus3" );  pcSPS->setPCMLog2MinSize (uiCode+3);
     1471    READ_UVLC( uiCode, "log2_diff_max_min_pcm_coding_block_size" ); pcSPS->setPCMLog2MaxSize ( uiCode+pcSPS->getPCMLog2MinSize() );
     1472  }
     1473
     1474  READ_UVLC( uiCode, "max_transform_hierarchy_depth_inter" );    pcSPS->setQuadtreeTUMaxDepthInter( uiCode+1 );
     1475  READ_UVLC( uiCode, "max_transform_hierarchy_depth_intra" );    pcSPS->setQuadtreeTUMaxDepthIntra( uiCode+1 );
     1476  g_uiAddCUDepth = 0;
     1477  while( ( pcSPS->getMaxCUWidth() >> uiMaxCUDepthCorrect ) > ( 1 << ( pcSPS->getQuadtreeTULog2MinSize() + g_uiAddCUDepth )  ) )
     1478  {
     1479    g_uiAddCUDepth++;
     1480  }
     1481  pcSPS->setMaxCUDepth( uiMaxCUDepthCorrect+g_uiAddCUDepth  );
     1482  g_uiMaxCUDepth  = uiMaxCUDepthCorrect+g_uiAddCUDepth;
     1483  // BB: these parameters may be removed completly and replaced by the fixed values
     1484  pcSPS->setMinTrDepth( 0 );
     1485  pcSPS->setMaxTrDepth( 1 );
     1486  READ_FLAG( uiCode, "scaling_list_enabled_flag" );                 pcSPS->setScalingListFlag ( uiCode );
     1487  READ_FLAG( uiCode, "chroma_pred_from_luma_enabled_flag" );        pcSPS->setUseLMChroma ( uiCode ? true : false );
     1488  READ_FLAG( uiCode, "deblocking_filter_in_aps_enabled_flag" );     pcSPS->setUseDF ( uiCode ? true : false ); 
     1489  READ_FLAG( uiCode, "loop_filter_across_slice_flag" );             pcSPS->setLFCrossSliceBoundaryFlag( uiCode ? true : false);
     1490  READ_FLAG( uiCode, "asymmetric_motion_partitions_enabled_flag" ); pcSPS->setUseAMP( uiCode );
     1491  READ_FLAG( uiCode, "non_square_quadtree_enabled_flag" );          pcSPS->setUseNSQT( uiCode );
     1492  READ_FLAG( uiCode, "sample_adaptive_offset_enabled_flag" );       pcSPS->setUseSAO ( uiCode ? true : false ); 
     1493  READ_FLAG( uiCode, "adaptive_loop_filter_enabled_flag" );         pcSPS->setUseALF ( uiCode ? true : false );
     1494#if LCU_SYNTAX_ALF
     1495  if(pcSPS->getUseALF())
     1496  {
     1497    READ_FLAG( uiCode, "alf_coef_in_slice_flag" );      pcSPS->setUseALFCoefInSlice ( uiCode ? true : false );
     1498  }
     1499#endif
     1500  if( pcSPS->getUsePCM() )
     1501  {
     1502    READ_FLAG( uiCode, "pcm_loop_filter_disable_flag" );           pcSPS->setPCMFilterDisableFlag ( uiCode ? true : false );
     1503  }
     1504
     1505  READ_FLAG( uiCode, "temporal_id_nesting_flag" );               pcSPS->setTemporalIdNestingFlag ( uiCode > 0 ? true : false );
     1506
     1507
     1508#if RPS_IN_SPS
     1509  TComRPSList* rpsList = pcSPS->getRPSList();
     1510  TComReferencePictureSet* rps;
     1511
     1512  READ_UVLC( uiCode, "num_short_term_ref_pic_sets" );
     1513  rpsList->create(uiCode);
     1514
     1515  for(UInt i=0; i< rpsList->getNumberOfReferencePictureSets(); i++)
     1516  {
     1517    rps = rpsList->getReferencePictureSet(i);
     1518    parseShortTermRefPicSet(pcSPS,rps,i);
     1519  }
     1520  READ_FLAG( uiCode, "long_term_ref_pics_present_flag" );          pcSPS->setLongTermRefsPresent(uiCode);
     1521#endif
     1522#if !PIC_CROPPING
     1523  //!!!KS: Syntax not in WD !!!
     1524
     1525  xReadUvlc ( uiCode ); pcSPS->setPadX        ( uiCode    );
     1526  xReadUvlc ( uiCode ); pcSPS->setPadY        ( uiCode    );
     1527#endif
     1528 
     1529  // AMVP mode for each depth (AM_NONE or AM_EXPL)
     1530  for (Int i = 0; i < pcSPS->getMaxCUDepth(); i++)
     1531  {
     1532    xReadFlag( uiCode );
     1533    pcSPS->setAMVPMode( i, (AMVP_MODE)uiCode );
     1534  }
     1535
     1536#if TILES_WPP_ENTRY_POINT_SIGNALLING
     1537  READ_CODE(2, uiCode, "tiles_or_entropy_coding_sync_idc");         pcSPS->setTilesOrEntropyCodingSyncIdc(uiCode);
     1538#endif
     1539
     1540#if TILES_OR_ENTROPY_SYNC_IDC
     1541  if(pcSPS->getTilesOrEntropyCodingSyncIdc() == 1)
     1542  {
     1543#endif
     1544    READ_UVLC ( uiCode, "num_tile_columns_minus1" );
     1545    pcSPS->setNumColumnsMinus1( uiCode ); 
     1546    READ_UVLC ( uiCode, "num_tile_rows_minus1" );
     1547    pcSPS->setNumRowsMinus1( uiCode );
     1548    READ_FLAG ( uiCode, "uniform_spacing_flag" );
     1549    pcSPS->setUniformSpacingIdr( uiCode );
     1550    if( pcSPS->getUniformSpacingIdr() == 0 )
     1551    {
     1552      UInt* columnWidth = (UInt*)malloc(pcSPS->getNumColumnsMinus1()*sizeof(UInt));
     1553      for(UInt i=0; i<pcSPS->getNumColumnsMinus1(); i++)
     1554      {
     1555        READ_UVLC( uiCode, "column_width" );
     1556        columnWidth[i] = uiCode; 
     1557      }
     1558      pcSPS->setColumnWidth(columnWidth);
     1559      free(columnWidth);
     1560
     1561      UInt* rowHeight = (UInt*)malloc(pcSPS->getNumRowsMinus1()*sizeof(UInt));
     1562      for(UInt i=0; i<pcSPS->getNumRowsMinus1(); i++)
     1563      {
     1564        READ_UVLC( uiCode, "row_height" );
     1565        rowHeight[i] = uiCode; 
     1566      }
     1567      pcSPS->setRowHeight(rowHeight);
     1568      free(rowHeight); 
     1569    }
     1570#if !REMOVE_TILE_DEPENDENCE
     1571    pcSPS->setTileBoundaryIndependenceIdr( 1 ); //default
     1572#endif
     1573    pcSPS->setLFCrossTileBoundaryFlag(true); //default
     1574
     1575    if( pcSPS->getNumColumnsMinus1() !=0 || pcSPS->getNumRowsMinus1() != 0)
     1576    {
     1577#if !REMOVE_TILE_DEPENDENCE
     1578      READ_FLAG ( uiCode, "tile_boundary_independence_flag" ); 
     1579      pcSPS->setTileBoundaryIndependenceIdr( uiCode );
     1580      if(pcSPS->getTileBoundaryIndependenceIdr() == 1)
     1581      {
     1582#endif
     1583        READ_FLAG ( uiCode, "loop_filter_across_tile_flag" ); 
     1584        pcSPS->setLFCrossTileBoundaryFlag( (uiCode==1)?true:false);
     1585#if !REMOVE_TILE_DEPENDENCE
     1586      }
     1587#endif
     1588    }
     1589#if TILES_OR_ENTROPY_SYNC_IDC
     1590  }
     1591#endif
     1592  READ_FLAG( uiCode, "sps_extension_flag");
     1593  if(uiCode)
     1594  {
     1595    READ_FLAG( uiCode, "interview_refs_present_flag");
     1596    if(uiCode)
     1597    {
     1598      READ_UVLC( uiCode, "num_usable_interview_refs_minus1" );
     1599      pcSPS->setNumberOfUsableInterViewRefs( uiCode + 1 );
     1600
     1601      Int prev = 0;
     1602      for( Int j = 0 ; j < pcSPS->getNumberOfUsableInterViewRefs(); j++ )
     1603      {
     1604        READ_UVLC(uiCode, "delta_usable_interview_ref_minus1");
     1605        pcSPS->setUsableInterViewRef( j, (prev - uiCode - 1) );
     1606        prev = pcSPS->getUsableInterViewRef( j );
     1607      }
     1608    }
    2451609
    2461610#if HHI_DMM_WEDGE_INTRA || HHI_DMM_PRED_TEX
    247   g_dDeltaDCsQuantOffset = Double(g_uiBitIncrement) -  2.0;
    248 #endif
    249 
    250 #if MTK_NONCROSS_INLOOP_FILTER
    251   xReadFlag( uiCode );
    252   pcSPS->setLFCrossSliceBoundaryFlag( uiCode ? true : false);
    253 #endif
    254 #if MTK_SAO
    255   xReadFlag( uiCode ); pcSPS->setUseSAO       ( uiCode ? true : false );
    256 #endif
    257 
    258   xReadFlag( uiCode ); // SPS base view flag
    259   if( uiCode )
    260   { // baseview SPS -> set standard values
    261     pcSPS->initMultiviewSPS         ( 0 );
     1611    READ_FLAG( uiCode, "enable_dmm_flag" );
     1612    pcSPS->setUseDMM( uiCode );
     1613#endif
     1614
     1615#if HHI_MPI
     1616    if( bIsDepth )
     1617    {
     1618      READ_FLAG( uiCode, "use_mvi_flag" );
     1619      pcSPS->setUseMVI( uiCode );
     1620    }
     1621#endif
     1622
     1623    READ_FLAG( uiCode, "base_view_flag" );
     1624    if( uiCode )
     1625    { // baseview SPS -> set standard values
     1626      pcSPS->initMultiviewSPS         ( 0 );
    2621627#if DEPTH_MAP_GENERATION
    263     pcSPS->setPredDepthMapGeneration( 0, false );
     1628      pcSPS->setPredDepthMapGeneration( 0, false );
    2641629#endif
    2651630#if HHI_INTER_VIEW_RESIDUAL_PRED
    2661631    pcSPS->setMultiviewResPredMode  ( 0 );
    2671632#endif
    268   }
    269   else
    270   {
    271     xReadFlag  ( uiCode ); // depth flag
    272     if( uiCode )
    273     {
    274       xReadUvlc( uiCode ); // view id
    275       xReadSvlc(  iCode ); // view order index
    276       pcSPS->initMultiviewSPSDepth    ( uiCode, iCode );
     1633    }
     1634    else
     1635    {
     1636      READ_FLAG( uiCode, "depth_flag" );
     1637      if( uiCode )
     1638      {
     1639        READ_UVLC( uiCode, "view_id" );
     1640        READ_SVLC(  iCode, "view_order_idx" );
     1641        pcSPS->initMultiviewSPSDepth    ( uiCode, iCode );
    2771642#if DEPTH_MAP_GENERATION
    278       pcSPS->setPredDepthMapGeneration( uiCode, true );
     1643        pcSPS->setPredDepthMapGeneration( uiCode, true );
    2791644#endif
    2801645#if HHI_INTER_VIEW_RESIDUAL_PRED
    2811646      pcSPS->setMultiviewResPredMode  ( 0 );
    2821647#endif
    283 #if HHI_DMM_WEDGE_INTRA || HHI_DMM_PRED_TEX
    284       xReadFlag( uiCode );
    285       pcSPS->setUseDMM( uiCode ? true : false );
    286 #endif
    287 #if HHI_MPI
    288       xReadFlag( uiCode );
    289       pcSPS->setUseMVI( uiCode ? true : false );
    290 #endif
    291     }
    292     else
    293     {
    294       UInt  uiViewId, uiCamParPrecision;
    295       Int   iVOI;
    296       Bool  bCamParSlice;
    297       xReadUvlc( uiViewId );  uiViewId++;
    298       xReadSvlc( iVOI );
    299       xReadUvlc( uiCamParPrecision );
    300       xReadFlag( uiCode );    bCamParSlice = ( uiCode == 1 );
    301       if( !bCamParSlice )
    302       {
    303         for( UInt uiBaseId = 0; uiBaseId < uiViewId; uiBaseId++ )
    304         {
    305           xReadSvlc( iCode );   m_aaiTempScale [ uiBaseId ][ uiViewId ] = iCode;
    306           xReadSvlc( iCode );   m_aaiTempOffset[ uiBaseId ][ uiViewId ] = iCode;
    307           xReadSvlc( iCode );   m_aaiTempScale [ uiViewId ][ uiBaseId ] = iCode - m_aaiTempScale [ uiBaseId ][ uiViewId ];
    308           xReadSvlc( iCode );   m_aaiTempOffset[ uiViewId ][ uiBaseId ] = iCode - m_aaiTempOffset[ uiBaseId ][ uiViewId ];
    309         }
    310       }
    311       pcSPS->initMultiviewSPS( uiViewId, iVOI, uiCamParPrecision, bCamParSlice, m_aaiTempScale, m_aaiTempOffset );
    312      
     1648      }
     1649      else
     1650      {
     1651        UInt  uiViewId, uiCamParPrecision;
     1652        Int   iVOI;
     1653        Bool  bCamParSlice;
     1654        READ_UVLC( uiViewId, "view_id" );  uiViewId++;
     1655        READ_SVLC( iVOI, "view_order_idx" );
     1656        READ_UVLC( uiCamParPrecision, "camera_parameter_precision" );
     1657        READ_FLAG( uiCode, "camera_parameter_in_slice_header" );    bCamParSlice = ( uiCode == 1 );
     1658        if( !bCamParSlice )
     1659        {
     1660          for( UInt uiBaseId = 0; uiBaseId < uiViewId; uiBaseId++ )
     1661          {
     1662            READ_SVLC( iCode, "coded_scale" );   m_aaiTempScale [ uiBaseId ][ uiViewId ] = iCode;
     1663            READ_SVLC( iCode, "coded_offset" );   m_aaiTempOffset[ uiBaseId ][ uiViewId ] = iCode;
     1664            READ_SVLC( iCode, "inverse_coded_scale_plus_coded_scale" );   m_aaiTempScale [ uiViewId ][ uiBaseId ] = iCode - m_aaiTempScale [ uiBaseId ][ uiViewId ];
     1665            READ_SVLC( iCode, "inverse_coded_offset_plus_coded_offset" );   m_aaiTempOffset[ uiViewId ][ uiBaseId ] = iCode - m_aaiTempOffset[ uiBaseId ][ uiViewId ];
     1666          }
     1667        }
     1668        pcSPS->initMultiviewSPS( uiViewId, iVOI, uiCamParPrecision, bCamParSlice, m_aaiTempScale, m_aaiTempOffset );
     1669
    3131670#if DEPTH_MAP_GENERATION
    314       UInt uiPredDepthMapGeneration = 0, uiPdmPrecision = 0;
     1671        UInt uiPredDepthMapGeneration = 0, uiPdmPrecision = 0;
    3151672#if HHI_INTER_VIEW_MOTION_PRED
    316       UInt uiMultiviewMvPredMode = 0;
     1673        UInt uiMultiviewMvPredMode = 0;
    3171674#endif
    3181675#if HHI_INTER_VIEW_RESIDUAL_PRED
    3191676      UInt uiMultiviewResPredMode = 0;
    3201677#endif
    321       xReadUvlc( uiPredDepthMapGeneration );
    322       if( uiPredDepthMapGeneration )
    323       {
    324         xReadUvlc  ( uiPdmPrecision );
    325         for( UInt uiBaseId = 0; uiBaseId < uiViewId; uiBaseId++ )
    326         {
    327           xReadSvlc( iCode );   m_aaiTempPdmScaleNomDelta[ uiViewId ][ uiBaseId ] = iCode;
    328           xReadSvlc( iCode );   m_aaiTempPdmOffset       [ uiViewId ][ uiBaseId ] = iCode;
    329         }
     1678        READ_UVLC( uiPredDepthMapGeneration, "Pdm_generation" );
     1679        if( uiPredDepthMapGeneration )
     1680        {
     1681          READ_UVLC( uiPdmPrecision, "Pdm_precision" );
     1682          for( UInt uiBaseId = 0; uiBaseId < uiViewId; uiBaseId++ )
     1683          {
     1684            READ_SVLC( iCode, "Pdm_scale_nom_delta" );   m_aaiTempPdmScaleNomDelta[ uiViewId ][ uiBaseId ] = iCode;
     1685            READ_SVLC( iCode, "Pdm_offset" );   m_aaiTempPdmOffset       [ uiViewId ][ uiBaseId ] = iCode;
     1686          }
    3301687#if HHI_INTER_VIEW_MOTION_PRED
    331         xReadUvlc  ( uiMultiviewMvPredMode );
     1688          READ_UVLC( uiMultiviewMvPredMode, "multi_view_mv_pred_mode" );
    3321689#endif
    3331690#if HHI_INTER_VIEW_RESIDUAL_PRED
    334         xReadFlag  ( uiMultiviewResPredMode );
    335 #endif
    336       }
     1691          READ_FLAG( uiMultiviewResPredMode, "multi_view_residual_pred_mode" );
     1692#endif
     1693        }
    3371694#if HHI_INTER_VIEW_MOTION_PRED
    338       pcSPS->setPredDepthMapGeneration( uiViewId, false, uiPredDepthMapGeneration, uiMultiviewMvPredMode, uiPdmPrecision, m_aaiTempPdmScaleNomDelta, m_aaiTempPdmOffset );
    339 #else
    340       pcSPS->setPredDepthMapGeneration( uiViewId, false, uiPredDepthMapGeneration, 0, uiPdmPrecision, m_aaiTempPdmScaleNomDelta, m_aaiTempPdmOffset );
     1695        pcSPS->setPredDepthMapGeneration( uiViewId, false, uiPredDepthMapGeneration, uiMultiviewMvPredMode, uiPdmPrecision, m_aaiTempPdmScaleNomDelta, m_aaiTempPdmOffset );
     1696#else
     1697        pcSPS->setPredDepthMapGeneration( uiViewId, false, uiPredDepthMapGeneration, 0, uiPdmPrecision, m_aaiTempPdmScaleNomDelta, m_aaiTempPdmOffset );
     1698#endif
    3411699#endif
    3421700#if HHI_INTER_VIEW_RESIDUAL_PRED
    3431701      pcSPS->setMultiviewResPredMode  ( uiMultiviewResPredMode );
    3441702#endif
    345 #endif
    346 #if HHI_MPI
    347       pcSPS->setUseMVI( false );
    348 #endif
    349     }
    350   }
    351 
    352   return;
    353 }
    354 
    355 Void TDecCavlc::parseSliceHeader (TComSlice*& rpcSlice)
     1703      }
     1704    }
     1705    READ_FLAG( uiCode, "sps_extension2_flag");
     1706    if (uiCode)
     1707    {
     1708      while ( xMoreRbspData() )
     1709      {
     1710        READ_FLAG( uiCode, "sps_extension2_data_flag");
     1711      }
     1712    }
     1713  }
     1714}
     1715
     1716Void TDecCavlc::readTileMarker   ( UInt& uiTileIdx, UInt uiBitsUsed )
     1717{
     1718  xReadCode ( uiBitsUsed, uiTileIdx );
     1719}
     1720
     1721#if LCU_SYNTAX_ALF
     1722Void TDecCavlc::parseSliceHeader (TComSlice*& rpcSlice, ParameterSetManagerDecoder *parameterSetManager, AlfCUCtrlInfo &alfCUCtrl, AlfParamSet& alfParamSet)
     1723#else
     1724Void TDecCavlc::parseSliceHeader (TComSlice*& rpcSlice, ParameterSetManagerDecoder *parameterSetManager, AlfCUCtrlInfo &alfCUCtrl)
     1725#endif
    3561726{
    3571727  UInt  uiCode;
    3581728  Int   iCode;
    359 
    360   xReadFlag ( uiCode );
     1729 
     1730#if ENC_DEC_TRACE
     1731  xTraceSliceHeader(rpcSlice);
     1732#endif
     1733  Int numCUs = ((rpcSlice->getSPS()->getPicWidthInLumaSamples()+rpcSlice->getSPS()->getMaxCUWidth()-1)/rpcSlice->getSPS()->getMaxCUWidth())*((rpcSlice->getSPS()->getPicHeightInLumaSamples()+rpcSlice->getSPS()->getMaxCUHeight()-1)/rpcSlice->getSPS()->getMaxCUHeight());
     1734  Int maxParts = (1<<(rpcSlice->getSPS()->getMaxCUDepth()<<1));
     1735  Int numParts = (1<<(rpcSlice->getPPS()->getSliceGranularity()<<1));
     1736  UInt lCUAddress = 0;
     1737  Int reqBitsOuter = 0;
     1738  while(numCUs>(1<<reqBitsOuter))
     1739  {
     1740    reqBitsOuter++;
     1741  }
     1742  Int reqBitsInner = 0;
     1743  while((numParts)>(1<<reqBitsInner))
     1744  {
     1745    reqBitsInner++;
     1746  }
     1747
     1748  READ_FLAG( uiCode, "first_slice_in_pic_flag" );
     1749  UInt address;
     1750  UInt innerAddress = 0;
     1751  if(!uiCode)
     1752  {
     1753    READ_CODE( reqBitsOuter+reqBitsInner, address, "slice_address" );
     1754    lCUAddress = address >> reqBitsInner;
     1755    innerAddress = address - (lCUAddress<<reqBitsInner);
     1756  }
     1757  //set uiCode to equal slice start address (or entropy slice start address)
     1758  uiCode=(maxParts*lCUAddress)+(innerAddress*(maxParts>>(rpcSlice->getPPS()->getSliceGranularity()<<1)));
     1759 
     1760  rpcSlice->setEntropySliceCurStartCUAddr( uiCode );
     1761  rpcSlice->setEntropySliceCurEndCUAddr(numCUs*maxParts);
     1762
     1763  //   slice_type
     1764  READ_UVLC (    uiCode, "slice_type" );            rpcSlice->setSliceType((SliceType)uiCode);
     1765  // lightweight_slice_flag
     1766  READ_FLAG( uiCode, "entropy_slice_flag" );
    3611767  Bool bEntropySlice = uiCode ? true : false;
    362   if (!bEntropySlice)
    363   {
    364     xReadUvlc ( uiCode ); rpcSlice->setPPSId( uiCode );
    365     xReadCode (10, uiCode);  rpcSlice->setPOC              (uiCode);             // 9 == SPS->Log2MaxFrameNum()
    366     xReadUvlc (   uiCode);  rpcSlice->setSliceType        ((SliceType)uiCode);
    367     xReadSvlc (    iCode);  rpcSlice->setSliceQp          (iCode);
    368   }
     1768
    3691769  if (bEntropySlice)
    3701770  {
    3711771    rpcSlice->setNextSlice        ( false );
    3721772    rpcSlice->setNextEntropySlice ( true  );
    373 
    374     xReadUvlc(uiCode);
    375     rpcSlice->setEntropySliceCurStartCUAddr( uiCode ); // start CU addr for entropy slice
    3761773  }
    3771774  else
     
    3791776    rpcSlice->setNextSlice        ( true  );
    3801777    rpcSlice->setNextEntropySlice ( false );
    381 
    382     xReadUvlc(uiCode);
    383     rpcSlice->setSliceCurStartCUAddr( uiCode );        // start CU addr for slice
    384     rpcSlice->setEntropySliceCurStartCUAddr( uiCode ); // start CU addr for entropy slice
    385 
    386     xReadFlag ( uiCode );
    387     rpcSlice->setSymbolMode( uiCode );
    388 
     1778   
     1779    uiCode=(maxParts*lCUAddress)+(innerAddress*(maxParts>>(rpcSlice->getPPS()->getSliceGranularity()<<1)));
     1780    rpcSlice->setSliceCurStartCUAddr(uiCode);
     1781    rpcSlice->setSliceCurEndCUAddr(numCUs*maxParts);
     1782  }
     1783  TComPPS* pps = NULL;
     1784  TComSPS* sps = NULL;
     1785
     1786  if (!bEntropySlice)
     1787  {
     1788    READ_UVLC (    uiCode, "pic_parameter_set_id" );  rpcSlice->setPPSId(uiCode);
     1789    pps = parameterSetManager->getPrefetchedPPS(uiCode);
     1790    sps = parameterSetManager->getPrefetchedSPS(pps->getSPSId());
     1791    rpcSlice->setSPS(sps);
     1792    rpcSlice->setPPS(pps);
     1793#if H0388
     1794    if( pps->getOutputFlagPresentFlag() )
     1795    {
     1796      READ_FLAG( uiCode, "pic_output_flag" );
     1797      rpcSlice->setPicOutputFlag( uiCode ? true : false );
     1798    }
     1799    else
     1800    {
     1801      rpcSlice->setPicOutputFlag( true );
     1802    }
     1803#endif
     1804    if(rpcSlice->getNalUnitType()==NAL_UNIT_CODED_SLICE_IDR)
     1805    {
     1806      READ_UVLC( uiCode, "idr_pic_id" );  //ignored
     1807      READ_FLAG( uiCode, "no_output_of_prior_pics_flag" );  //ignored
     1808      rpcSlice->setPOC(0);
     1809      TComReferencePictureSet* rps = rpcSlice->getLocalRPS();
     1810      rps->setNumberOfNegativePictures(0);
     1811      rps->setNumberOfPositivePictures(0);
     1812      rps->setNumberOfLongtermPictures(0);
     1813      rps->setNumberOfPictures(0);
     1814      rpcSlice->setRPS(rps);
     1815    }
     1816    else
     1817    {
     1818      READ_CODE(sps->getBitsForPOC(), uiCode, "pic_order_cnt_lsb"); 
     1819      Int iPOClsb = uiCode;
     1820      Int iPrevPOC = rpcSlice->getPrevPOC();
     1821      Int iMaxPOClsb = 1<< sps->getBitsForPOC();
     1822      Int iPrevPOClsb = iPrevPOC%iMaxPOClsb;
     1823      Int iPrevPOCmsb = iPrevPOC-iPrevPOClsb;
     1824      Int iPOCmsb;
     1825      if( ( iPOClsb  <  iPrevPOClsb ) && ( ( iPrevPOClsb - iPOClsb )  >=  ( iMaxPOClsb / 2 ) ) )
     1826      {
     1827        iPOCmsb = iPrevPOCmsb + iMaxPOClsb;
     1828      }
     1829      else if( (iPOClsb  >  iPrevPOClsb )  && ( (iPOClsb - iPrevPOClsb )  >  ( iMaxPOClsb / 2 ) ) )
     1830      {
     1831        iPOCmsb = iPrevPOCmsb - iMaxPOClsb;
     1832      }
     1833      else
     1834      {
     1835        iPOCmsb = iPrevPOCmsb;
     1836      }
     1837      rpcSlice->setPOC( iPOCmsb+iPOClsb );
     1838
     1839      if( rpcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDV )
     1840      {
     1841        TComReferencePictureSet* rps = rpcSlice->getLocalRPS();
     1842        rps->setNumberOfNegativePictures(0);
     1843        rps->setNumberOfPositivePictures(0);
     1844        rps->setNumberOfLongtermPictures(0);
     1845        rps->setNumberOfPictures(0);
     1846        rpcSlice->setRPS(rps);
     1847      }
     1848      else
     1849      {
     1850        TComReferencePictureSet* rps;
     1851        READ_FLAG( uiCode, "short_term_ref_pic_set_sps_flag" );
     1852        if(uiCode == 0) // use short-term reference picture set explicitly signalled in slice header
     1853        {
     1854          rps = rpcSlice->getLocalRPS();
     1855#if RPS_IN_SPS
     1856          parseShortTermRefPicSet(sps,rps, sps->getRPSList()->getNumberOfReferencePictureSets());
     1857#else
     1858          parseShortTermRefPicSet(pps,rps, pps->getRPSList()->getNumberOfReferencePictureSets());
     1859#endif
     1860          rpcSlice->setRPS(rps);
     1861        }
     1862        else // use reference to short-term reference picture set in PPS
     1863        {
     1864#if RPS_IN_SPS
     1865          READ_UVLC( uiCode, "short_term_ref_pic_set_idx"); rpcSlice->setRPS(sps->getRPSList()->getReferencePictureSet(uiCode));
     1866#else
     1867          READ_UVLC( uiCode, "short_term_ref_pic_set_idx"); rpcSlice->setRPS(pps->getRPSList()->getReferencePictureSet(uiCode));
     1868#endif
     1869          rps = rpcSlice->getRPS();
     1870        }
     1871#if RPS_IN_SPS
     1872        if(sps->getLongTermRefsPresent())
     1873#else
     1874        if(pps->getLongTermRefsPresent())
     1875#endif
     1876        {
     1877          Int offset = rps->getNumberOfNegativePictures()+rps->getNumberOfPositivePictures();
     1878          READ_UVLC( uiCode, "num_long_term_pics");             rps->setNumberOfLongtermPictures(uiCode);
     1879          Int prev = 0;
     1880#if LTRP_MULT
     1881          Int prevMsb=0;
     1882          Int prevDeltaPocLt=0;
     1883#endif
     1884          for(Int j=rps->getNumberOfLongtermPictures()+offset-1 ; j > offset-1; j--)
     1885          {
     1886            READ_UVLC(uiCode,"delta_poc_lsb_lt");
     1887            prev += uiCode;
     1888
     1889#if LTRP_MULT
     1890            READ_FLAG(uiCode,"delta_poc_msb_present_flag");
     1891            Int decDeltaPOCMsbPresent=uiCode;
     1892
     1893            if(decDeltaPOCMsbPresent==1)
     1894            {
     1895              READ_UVLC(uiCode, "delta_poc_msb_cycle_lt_minus1");
     1896              if(  (j==(rps->getNumberOfLongtermPictures()+offset-1)) || (prev!=prevDeltaPocLt) )
     1897              {
     1898                prevMsb=(1+uiCode);
     1899              }
     1900              else
     1901              {
     1902                prevMsb+=(1+uiCode);
     1903              }
     1904              Int decMaxPocLsb = 1<<rpcSlice->getSPS()->getBitsForPOC();
     1905              rps->setPOC(j,rpcSlice->getPOC()-prev-(prevMsb)*decMaxPocLsb);
     1906              rps->setDeltaPOC(j,-(Int)(prev+(prevMsb)*decMaxPocLsb));
     1907            }
     1908            else
     1909            {
     1910#endif
     1911              rps->setPOC(j,rpcSlice->getPOC()-prev);         
     1912              rps->setDeltaPOC(j,-(Int)prev);
     1913#if LTRP_MULT
     1914            }
     1915            prevDeltaPocLt=prev;
     1916#endif
     1917            READ_FLAG( uiCode, "used_by_curr_pic_lt_flag");     rps->setUsed(j,uiCode);
     1918          }
     1919          offset += rps->getNumberOfLongtermPictures();
     1920          rps->setNumberOfPictures(offset);       
     1921        } 
     1922      }
     1923    }
     1924
     1925    if(sps->getUseSAO() || sps->getUseALF() || sps->getScalingListFlag() || sps->getUseDF())
     1926    {
     1927      //!!!KS: order is different in WD5!
     1928      if (sps->getUseALF())
     1929      {
     1930        READ_FLAG(uiCode, "slice_adaptive_loop_filter_flag");
     1931        rpcSlice->setAlfEnabledFlag((Bool)uiCode);
     1932      }
     1933      if (sps->getUseSAO())
     1934      {
     1935#if SAO_UNIT_INTERLEAVING
     1936        READ_FLAG(uiCode, "slice_sao_interleaving_flag");        rpcSlice->setSaoInterleavingFlag(uiCode);
     1937#endif
     1938        READ_FLAG(uiCode, "slice_sample_adaptive_offset_flag");  rpcSlice->setSaoEnabledFlag((Bool)uiCode);
     1939#if SAO_UNIT_INTERLEAVING
     1940        if (rpcSlice->getSaoEnabledFlag() && rpcSlice->getSaoInterleavingFlag())
     1941        {
     1942          READ_FLAG(uiCode, "sao_cb_enable_flag");  rpcSlice->setSaoEnabledFlagCb((Bool)uiCode);
     1943          READ_FLAG(uiCode, "sao_cr_enable_flag");  rpcSlice->setSaoEnabledFlagCr((Bool)uiCode);
     1944        }
     1945        else
     1946        {
     1947          rpcSlice->setSaoEnabledFlagCb(0);
     1948          rpcSlice->setSaoEnabledFlagCr(0);
     1949        }
     1950#endif
     1951      }
     1952      READ_UVLC (    uiCode, "aps_id" );  rpcSlice->setAPSId(uiCode);
     1953    }
    3891954    if (!rpcSlice->isIntra())
    390       xReadFlag (   uiCode);
     1955    {
     1956      READ_FLAG( uiCode, "num_ref_idx_active_override_flag");
     1957      if (uiCode)
     1958      {
     1959        READ_CODE (3, uiCode, "num_ref_idx_l0_active_minus1" );  rpcSlice->setNumRefIdx( REF_PIC_LIST_0, uiCode + 1 );
     1960        if (rpcSlice->isInterB())
     1961        {
     1962          READ_CODE (3, uiCode, "num_ref_idx_l1_active_minus1" );  rpcSlice->setNumRefIdx( REF_PIC_LIST_1, uiCode + 1 );
     1963        }
     1964        else
     1965        {
     1966          rpcSlice->setNumRefIdx(REF_PIC_LIST_1, 0);
     1967        }
     1968      }
     1969      else
     1970      {
     1971        rpcSlice->setNumRefIdx(REF_PIC_LIST_0, 0);
     1972        rpcSlice->setNumRefIdx(REF_PIC_LIST_1, 0);
     1973      }
     1974    }
     1975    TComRefPicListModification* refPicListModification = rpcSlice->getRefPicListModification();
     1976    if( !rpcSlice->isIntra() )
     1977    {
     1978#if H0412_REF_PIC_LIST_RESTRICTION
     1979      if( !rpcSlice->getSPS()->getListsModificationPresentFlag() )
     1980      {
     1981        refPicListModification->setRefPicListModificationFlagL0( 0 );
     1982      }
     1983      else
     1984      {
     1985#endif
     1986        READ_FLAG( uiCode, "ref_pic_list_modification_flag_l0" ); refPicListModification->setRefPicListModificationFlagL0( uiCode ? 1 : 0 );
     1987#if H0412_REF_PIC_LIST_RESTRICTION
     1988      }
     1989#endif
     1990     
     1991      if(refPicListModification->getRefPicListModificationFlagL0())
     1992      {
     1993        uiCode = 0;
     1994        Int i = 0;
     1995#if H0137_0138_LIST_MODIFICATION
     1996        Int NumPocTotalCurr = rpcSlice->getNumPocTotalCurrMvc();
     1997        if ( NumPocTotalCurr > 1 )
     1998        {
     1999          Int length = 1;
     2000          NumPocTotalCurr --;
     2001          while ( NumPocTotalCurr >>= 1)
     2002          {
     2003            length ++;
     2004          }
     2005          for (i = 0; i < rpcSlice->getNumRefIdx(REF_PIC_LIST_0); i ++)
     2006          {
     2007            READ_CODE( length, uiCode, "list_entry_l0" );
     2008            refPicListModification->setRefPicSetIdxL0(i, uiCode );
     2009          }
     2010        }
     2011        else
     2012        {
     2013          for (i = 0; i < rpcSlice->getNumRefIdx(REF_PIC_LIST_0); i ++)
     2014          {
     2015            refPicListModification->setRefPicSetIdxL0(i, 0 );
     2016          }
     2017        }
     2018#else
     2019        Int list_modification_idc = 0;
     2020        while(list_modification_idc != 3) 
     2021        {
     2022          READ_UVLC( uiCode, "list_modification_idc" ); refPicListModification->setListIdcL0(i, uiCode );
     2023          list_modification_idc = uiCode;
     2024          if(uiCode != 3)
     2025          {
     2026            READ_UVLC( uiCode, "ref_pic_set_idx" ); refPicListModification->setRefPicSetIdxL0(i, uiCode );
     2027          }
     2028          i++;
     2029        }
     2030        refPicListModification->setNumberOfRefPicListModificationsL0(i-1);
     2031#endif
     2032      }
     2033#if !H0137_0138_LIST_MODIFICATION
     2034      else
     2035      {
     2036        refPicListModification->setNumberOfRefPicListModificationsL0(0);
     2037      }
     2038#endif
     2039    }
    3912040    else
    392       uiCode = 1;
    393 
    394     rpcSlice->setReferenced       (uiCode ? true : false);
    395 
    396 #if !HIGH_ACCURACY_BI
    397 #ifdef ROUNDING_CONTROL_BIPRED
    398     if(!rpcSlice->isIntra())
    399     {
    400       xReadFlag( uiCode );
    401       Bool b = (uiCode != 0);
    402       rpcSlice->setRounding(b);
    403     }
    404 #endif
    405 #else
    406 #if !HIGH_ACCURACY_BI
    407     if(!rpcSlice->isIntra())
    408     {
    409       rpcSlice->setRounding(false);
    410     }
    411 #endif
    412 #endif
    413 
    414     xReadFlag (   uiCode);  rpcSlice->setLoopFilterDisable(uiCode ? 1 : 0);
    415 
    416     if (!rpcSlice->isIntra())
    417     {
    418       xReadCode (3, uiCode);  rpcSlice->setNumRefIdx      (REF_PIC_LIST_0, uiCode);
    419     }
     2041    {
     2042      refPicListModification->setRefPicListModificationFlagL0(0);
     2043#if !H0137_0138_LIST_MODIFICATION
     2044      refPicListModification->setNumberOfRefPicListModificationsL0(0);
     2045#endif
     2046    }
     2047    if(rpcSlice->isInterB())
     2048    {
     2049#if H0412_REF_PIC_LIST_RESTRICTION
     2050      if( !rpcSlice->getSPS()->getListsModificationPresentFlag() )
     2051      {
     2052        refPicListModification->setRefPicListModificationFlagL1( 0 );
     2053      }
     2054      else
     2055      {
     2056#endif
     2057        READ_FLAG( uiCode, "ref_pic_list_modification_flag_l1" ); refPicListModification->setRefPicListModificationFlagL1( uiCode ? 1 : 0 );
     2058#if H0412_REF_PIC_LIST_RESTRICTION
     2059      }
     2060#endif
     2061      if(refPicListModification->getRefPicListModificationFlagL1())
     2062      {
     2063        uiCode = 0;
     2064        Int i = 0;
     2065#if H0137_0138_LIST_MODIFICATION
     2066        Int NumPocTotalCurr = rpcSlice->getNumPocTotalCurrMvc();
     2067        if ( NumPocTotalCurr > 1 )
     2068        {
     2069          Int length = 1;
     2070          NumPocTotalCurr --;
     2071          while ( NumPocTotalCurr >>= 1)
     2072          {
     2073            length ++;
     2074          }
     2075          for (i = 0; i < rpcSlice->getNumRefIdx(REF_PIC_LIST_1); i ++)
     2076          {
     2077            READ_CODE( length, uiCode, "list_entry_l1" );
     2078            refPicListModification->setRefPicSetIdxL1(i, uiCode );
     2079          }
     2080        }
     2081        else
     2082        {
     2083          for (i = 0; i < rpcSlice->getNumRefIdx(REF_PIC_LIST_1); i ++)
     2084          {
     2085            refPicListModification->setRefPicSetIdxL1(i, 0 );
     2086          }
     2087        }
     2088#else
     2089        Int list_modification_idc = 0;
     2090        while(list_modification_idc != 3) 
     2091        {
     2092          READ_UVLC( uiCode, "list_modification_idc" ); refPicListModification->setListIdcL1(i, uiCode );
     2093          list_modification_idc = uiCode;
     2094          if(uiCode != 3)
     2095          {
     2096            READ_UVLC( uiCode, "ref_pic_set_idx" ); refPicListModification->setRefPicSetIdxL1(i, uiCode );
     2097          }
     2098          i++;
     2099        }
     2100        refPicListModification->setNumberOfRefPicListModificationsL1(i-1);
     2101#endif
     2102      }
     2103#if !H0137_0138_LIST_MODIFICATION
     2104      else
     2105      {
     2106        refPicListModification->setNumberOfRefPicListModificationsL1(0);
     2107      }
     2108#endif
     2109    } 
    4202110    else
    4212111    {
    422       rpcSlice->setNumRefIdx(REF_PIC_LIST_0, 0);
    423     }
    424     if (rpcSlice->isInterB())
    425     {
    426       xReadCode (3, uiCode);  rpcSlice->setNumRefIdx      (REF_PIC_LIST_1, uiCode);
    427     }
    428     else
    429     {
    430       rpcSlice->setNumRefIdx(REF_PIC_LIST_1, 0);
    431     }
    432 
    433     if (!rpcSlice->isIntra())
    434     {
    435       for(Int i = 0; i<rpcSlice->getNumRefIdx(REF_PIC_LIST_0);i++)
    436       {
    437         xReadFlag( uiCode ) ;
    438         if( uiCode ) // interview
    439         {
    440           xReadUvlc( uiCode ) ;
    441           rpcSlice->setRefViewIdx(uiCode, REF_PIC_LIST_0, i) ;
    442           rpcSlice->setRefPOC(rpcSlice->getPOC(), REF_PIC_LIST_0, i) ;
    443         }
    444         else
    445         {
    446           xReadSvlc( iCode ) ;
    447           rpcSlice->setRefPOC(rpcSlice->getPOC()-iCode, REF_PIC_LIST_0, i) ;
    448           rpcSlice->setRefViewIdx(rpcSlice->getViewIdx(), REF_PIC_LIST_0, i) ;
    449         }
    450       }
    451     }
    452     else
    453     {
    454       rpcSlice->setNumRefIdx(REF_PIC_LIST_0, 0);
    455     }
    456     if( rpcSlice->isInterB())
    457     {
    458       for(Int i = 0; i<rpcSlice->getNumRefIdx(REF_PIC_LIST_1);i++)
    459       {
    460         xReadFlag( uiCode ) ;
    461         if( uiCode ) // interview
    462         {
    463           xReadUvlc( uiCode ) ;
    464           rpcSlice->setRefViewIdx(uiCode, REF_PIC_LIST_1, i) ;
    465           rpcSlice->setRefPOC(rpcSlice->getPOC(), REF_PIC_LIST_1, i) ;
    466         }
    467         else
    468         {
    469           xReadSvlc( iCode ) ;
    470           rpcSlice->setRefPOC(rpcSlice->getPOC()-iCode, REF_PIC_LIST_1, i) ;
    471           rpcSlice->setRefViewIdx(rpcSlice->getViewIdx(), REF_PIC_LIST_1, i) ;
    472         }
    473       }
    474     }
    475     else
    476     {
    477       rpcSlice->setNumRefIdx(REF_PIC_LIST_1, 0);
    478     }
    479 
    480 #if DCM_COMB_LIST
    481     if (rpcSlice->isInterB())
    482     {
    483       xReadFlag (uiCode);      rpcSlice->setRefPicListCombinationFlag(uiCode ? 1 : 0);
    484       if(uiCode)
    485       {
    486         xReadUvlc(uiCode);      rpcSlice->setNumRefIdx      (REF_PIC_LIST_C, uiCode+1);
    487 
    488         xReadFlag (uiCode);     rpcSlice->setRefPicListModificationFlagLC(uiCode ? 1 : 0);
     2112      refPicListModification->setRefPicListModificationFlagL1(0);
     2113#if !H0137_0138_LIST_MODIFICATION
     2114      refPicListModification->setNumberOfRefPicListModificationsL1(0);
     2115#endif
     2116    }
     2117  }
     2118  else
     2119  {
     2120    // initialize from previous slice
     2121    pps = rpcSlice->getPPS();
     2122    sps = rpcSlice->getSPS();
     2123  }
     2124  // ref_pic_list_combination( )
     2125  //!!!KS: ref_pic_list_combination() should be conditioned on entropy_slice_flag
     2126  if (rpcSlice->isInterB())
     2127  {
     2128    READ_FLAG( uiCode, "ref_pic_list_combination_flag" );       rpcSlice->setRefPicListCombinationFlag( uiCode ? 1 : 0 );
     2129    if(uiCode)
     2130    {
     2131      READ_UVLC( uiCode, "num_ref_idx_lc_active_minus1" );      rpcSlice->setNumRefIdx( REF_PIC_LIST_C, uiCode + 1 );
     2132     
     2133#if H0412_REF_PIC_LIST_RESTRICTION
     2134      if(rpcSlice->getSPS()->getListsModificationPresentFlag() )
     2135      {
     2136#endif
     2137        READ_FLAG( uiCode, "ref_pic_list_modification_flag_lc" ); rpcSlice->setRefPicListModificationFlagLC( uiCode ? 1 : 0 );
    4892138        if(uiCode)
    4902139        {
    4912140          for (UInt i=0;i<rpcSlice->getNumRefIdx(REF_PIC_LIST_C);i++)
    4922141          {
    493             xReadFlag(uiCode);
     2142            READ_FLAG( uiCode, "pic_from_list_0_flag" );
    4942143            rpcSlice->setListIdFromIdxOfLC(i, uiCode);
    495             xReadUvlc(uiCode);
     2144#if H0137_0138_LIST_MODIFICATION
     2145          if (((rpcSlice->getListIdFromIdxOfLC(i) == REF_PIC_LIST_0) && (rpcSlice->getNumRefIdx( REF_PIC_LIST_0 ) == 1)) || ((rpcSlice->getListIdFromIdxOfLC(i) == REF_PIC_LIST_1) && (rpcSlice->getNumRefIdx( REF_PIC_LIST_1 ) == 1)) )
     2146          {
     2147            uiCode = 0;
     2148          }
     2149          else
     2150          {
     2151            READ_UVLC( uiCode, "ref_idx_list_curr" );
     2152          }
     2153#else
     2154            READ_UVLC( uiCode, "ref_idx_list_curr" );
     2155#endif
    4962156            rpcSlice->setRefIdxFromIdxOfLC(i, uiCode);
    4972157            rpcSlice->setRefIdxOfLC((RefPicList)rpcSlice->getListIdFromIdxOfLC(i), rpcSlice->getRefIdxFromIdxOfLC(i), i);
    4982158          }
    4992159        }
     2160#if H0412_REF_PIC_LIST_RESTRICTION
    5002161      }
    5012162      else
    5022163      {
    503         rpcSlice->setRefPicListCombinationFlag(false);
    5042164        rpcSlice->setRefPicListModificationFlagLC(false);
    505         rpcSlice->setNumRefIdx(REF_PIC_LIST_C, -1);
    506       }
    507     }
    508 #endif
    509 
    510 #if AMVP_NEIGH_COL
     2165      }
     2166#endif
     2167    }
     2168    else
     2169    {
     2170      rpcSlice->setRefPicListModificationFlagLC(false);
     2171      rpcSlice->setNumRefIdx(REF_PIC_LIST_C, 0);
     2172    }
     2173  }
     2174  else
     2175  {
     2176    rpcSlice->setRefPicListCombinationFlag(false);     
     2177  }
     2178 
     2179#if H0111_MVD_L1_ZERO
     2180  if (rpcSlice->isInterB())
     2181  {
     2182    READ_FLAG( uiCode, "mvd_l1_zero_flag" );       rpcSlice->setMvdL1ZeroFlag( (uiCode ? true : false) );
     2183  }
     2184#endif
     2185
     2186#if CABAC_INIT_FLAG
     2187  rpcSlice->setCabacInitFlag( false ); // default
     2188  if(pps->getCabacInitPresentFlag() && !rpcSlice->isIntra())
     2189  {
     2190    READ_FLAG(uiCode, "cabac_init_flag");
     2191    rpcSlice->setCabacInitFlag( uiCode ? true : false );
     2192  }
     2193#else
     2194  if(pps->getEntropyCodingMode() && !rpcSlice->isIntra())
     2195  {
     2196    READ_UVLC(uiCode, "cabac_init_idc");
     2197    rpcSlice->setCABACinitIDC(uiCode);
     2198  }
     2199  else if (pps->getEntropyCodingMode() && rpcSlice->isIntra())
     2200  {
     2201    rpcSlice->setCABACinitIDC(0);
     2202  }
     2203#endif
     2204
     2205  if(!bEntropySlice)
     2206  {
     2207    READ_SVLC( iCode, "slice_qp_delta" );
     2208    rpcSlice->setSliceQp (26 + pps->getPicInitQPMinus26() + iCode);
     2209
     2210#if H0736_AVC_STYLE_QP_RANGE
     2211    assert( rpcSlice->getSliceQp() >= -sps->getQpBDOffsetY() );
     2212    assert( rpcSlice->getSliceQp() <=  51 );
     2213#endif
     2214
     2215#if DBL_CONTROL
     2216    if (rpcSlice->getPPS()->getDeblockingFilterControlPresent())
     2217    {
     2218      if ( rpcSlice->getSPS()->getUseDF() )
     2219      {
     2220        READ_FLAG ( uiCode, "inherit_dbl_param_from_APS_flag" ); rpcSlice->setInheritDblParamFromAPS(uiCode ? 1 : 0);
     2221      } else
     2222      {
     2223        rpcSlice->setInheritDblParamFromAPS(0);
     2224      }
     2225#else
     2226    READ_FLAG ( uiCode, "inherit_dbl_param_from_APS_flag" ); rpcSlice->setInheritDblParamFromAPS(uiCode ? 1 : 0);
     2227#endif
     2228      if(!rpcSlice->getInheritDblParamFromAPS())
     2229      {
     2230        READ_FLAG ( uiCode, "disable_deblocking_filter_flag" );  rpcSlice->setLoopFilterDisable(uiCode ? 1 : 0);
     2231        if(!rpcSlice->getLoopFilterDisable())
     2232        {
     2233          READ_SVLC( iCode, "beta_offset_div2" ); rpcSlice->setLoopFilterBetaOffset(iCode);
     2234          READ_SVLC( iCode, "tc_offset_div2" ); rpcSlice->setLoopFilterTcOffset(iCode);
     2235        }
     2236      }
     2237#if DBL_CONTROL
     2238   }
     2239#endif
    5112240    if ( rpcSlice->getSliceType() == B_SLICE )
    5122241    {
    513       xReadFlag (uiCode);
     2242      READ_FLAG( uiCode, "collocated_from_l0_flag" );
    5142243      rpcSlice->setColDir(uiCode);
    5152244    }
    516 #endif
    517 
    518 #ifdef WEIGHT_PRED
    519     if ( (rpcSlice->getPPS()->getUseWP() && rpcSlice->getSliceType()==P_SLICE) || (rpcSlice->getPPS()->getWPBiPredIdc() && rpcSlice->getSliceType()==B_SLICE) )
    520     {
    521       parseWeightPredTable(rpcSlice);
     2245
     2246#if COLLOCATED_REF_IDX
     2247    if ( rpcSlice->getSliceType() != I_SLICE &&
     2248      ((rpcSlice->getColDir()==0 && rpcSlice->getNumRefIdx(REF_PIC_LIST_0)>1)||
     2249      (rpcSlice->getColDir() ==1 && rpcSlice->getNumRefIdx(REF_PIC_LIST_1)>1)))
     2250    {
     2251      READ_UVLC( uiCode, "collocated_ref_idx" );
     2252      rpcSlice->setColRefIdx(uiCode);
     2253    }
     2254#endif
     2255   
     2256    if ( (pps->getUseWP() && rpcSlice->getSliceType()==P_SLICE) || (pps->getWPBiPredIdc() && rpcSlice->getSliceType()==B_SLICE) )
     2257    {
     2258      xParsePredWeightTable(rpcSlice);
    5222259      rpcSlice->initWpScaling();
    523       rpcSlice->displayWpScaling();
    524     }
    525 #endif
    526     if( rpcSlice->getPPS()->getPPSId() != rpcSlice->getPPSId() )
    527     {
    528       return;
    529     }
    530 
    531 
     2260    }
     2261  }
     2262 
     2263  if (!bEntropySlice)
     2264  {
    5322265    if( rpcSlice->getSPS()->hasCamParInSliceHeader() )
    5332266    {
     
    5352268      for( UInt uiBaseId = 0; uiBaseId < uiViewId; uiBaseId++ )
    5362269      {
    537         xReadSvlc( iCode );   m_aaiTempScale [ uiBaseId ][ uiViewId ] = iCode;
    538         xReadSvlc( iCode );   m_aaiTempOffset[ uiBaseId ][ uiViewId ] = iCode;
    539         xReadSvlc( iCode );   m_aaiTempScale [ uiViewId ][ uiBaseId ] = iCode - m_aaiTempScale [ uiBaseId ][ uiViewId ];
    540         xReadSvlc( iCode );   m_aaiTempOffset[ uiViewId ][ uiBaseId ] = iCode - m_aaiTempOffset[ uiBaseId ][ uiViewId ];
     2270        READ_SVLC( iCode, "coded_scale" );   m_aaiTempScale [ uiBaseId ][ uiViewId ] = iCode;
     2271        READ_SVLC( iCode, "coded_offset" );   m_aaiTempOffset[ uiBaseId ][ uiViewId ] = iCode;
     2272        READ_SVLC( iCode, "inverse_coded_scale_plus_coded_scale" );   m_aaiTempScale [ uiViewId ][ uiBaseId ] = iCode - m_aaiTempScale [ uiBaseId ][ uiViewId ];
     2273        READ_SVLC( iCode, "inverse_coded_offset_plus_coded_offset" );   m_aaiTempOffset[ uiViewId ][ uiBaseId ] = iCode - m_aaiTempOffset[ uiBaseId ][ uiViewId ];
    5412274      }
    5422275      rpcSlice->initMultiviewSlice( m_aaiTempScale, m_aaiTempOffset );
    5432276    }
    5442277  }
     2278
     2279#if ( HHI_MPI || HHI_INTER_VIEW_MOTION_PRED )
     2280  #if ( HHI_MPI && HHI_INTER_VIEW_MOTION_PRED )
     2281  const int iExtraMergeCandidates = ( sps->getUseMVI() || sps->getMultiviewMvPredMode() ) ? 1 : 0;
     2282  #elif HHI_MPI
     2283  const int iExtraMergeCandidates = sps->getUseMVI() ? 1 : 0;
     2284  #else
     2285  const int iExtraMergeCandidates = sps->getMultiviewMvPredMode() ? 1 : 0;
     2286  #endif
     2287  READ_UVLC( uiCode, "5_minus_max_num_merge_cand");
     2288  rpcSlice->setMaxNumMergeCand(MRG_MAX_NUM_CANDS + iExtraMergeCandidates - uiCode);
     2289  assert(rpcSlice->getMaxNumMergeCand()==(MRG_MAX_NUM_CANDS_SIGNALED+iExtraMergeCandidates));
     2290#else
     2291  READ_UVLC( uiCode, "5_minus_max_num_merge_cand");
     2292  rpcSlice->setMaxNumMergeCand(MRG_MAX_NUM_CANDS - uiCode);
     2293  assert(rpcSlice->getMaxNumMergeCand()==MRG_MAX_NUM_CANDS_SIGNALED);
     2294#endif
     2295
     2296  if (!bEntropySlice)
     2297  {
     2298    if(sps->getUseALF() && rpcSlice->getAlfEnabledFlag())
     2299    {
     2300      UInt uiNumLCUsInWidth   = sps->getPicWidthInLumaSamples()  / g_uiMaxCUWidth;
     2301      UInt uiNumLCUsInHeight  = sps->getPicHeightInLumaSamples() / g_uiMaxCUHeight;
     2302
     2303      uiNumLCUsInWidth  += ( sps->getPicWidthInLumaSamples() % g_uiMaxCUWidth ) ? 1 : 0;
     2304      uiNumLCUsInHeight += ( sps->getPicHeightInLumaSamples() % g_uiMaxCUHeight ) ? 1 : 0;
     2305
     2306      Int uiNumCUsInFrame = uiNumLCUsInWidth* uiNumLCUsInHeight;
     2307#if LCU_SYNTAX_ALF
     2308      if(sps->getUseALFCoefInSlice())
     2309      {
     2310        alfParamSet.releaseALFParam();
     2311        alfParamSet.init();
     2312        Bool isAcrossSlice = sps->getLFCrossSliceBoundaryFlag();   
     2313        Int numSUinLCU    = 1<< (g_uiMaxCUDepth << 1);
     2314        Int firstLCUAddr   = rpcSlice->getSliceCurStartCUAddr() / numSUinLCU; 
     2315        xParseAlfParam(&alfParamSet, false, firstLCUAddr, isAcrossSlice, uiNumLCUsInWidth, uiNumLCUsInHeight);
     2316      }
     2317
     2318      if(!sps->getUseALFCoefInSlice())
     2319      {
     2320#endif
     2321      xParseAlfCuControlParam(alfCUCtrl, uiNumCUsInFrame);
     2322#if LCU_SYNTAX_ALF
     2323      }
     2324#endif
     2325
     2326    }
     2327  }
     2328 
     2329  //!!!KS: The following syntax is not aligned with the working draft, TRACE support needs to be added
     2330  rpcSlice->setTileMarkerFlag ( 0 ); // default
     2331  if (!bEntropySlice)
     2332  {
     2333#if !REMOVE_TILE_DEPENDENCE
     2334    if (sps->getTileBoundaryIndependenceIdr())
     2335    {   
     2336#endif
     2337    xReadCode(1, uiCode); // read flag indicating if tile markers transmitted
     2338    rpcSlice->setTileMarkerFlag( uiCode );
     2339#if !REMOVE_TILE_DEPENDENCE
     2340    }
     2341#endif
     2342  }
     2343
     2344#if TILES_WPP_ENTRY_POINT_SIGNALLING
     2345  Int tilesOrEntropyCodingSyncIdc = rpcSlice->getSPS()->getTilesOrEntropyCodingSyncIdc();
     2346  UInt *entryPointOffset          = NULL;
     2347  UInt numEntryPointOffsets, offsetLenMinus1;
     2348
     2349  rpcSlice->setNumEntryPointOffsets ( 0 ); // default
     2350 
     2351  if (tilesOrEntropyCodingSyncIdc>0)
     2352  {
     2353    READ_UVLC(numEntryPointOffsets, "num_entry_point_offsets"); rpcSlice->setNumEntryPointOffsets ( numEntryPointOffsets );
     2354    if (numEntryPointOffsets>0)
     2355    {
     2356      READ_UVLC(offsetLenMinus1, "offset_len_minus1");
     2357    }
     2358    entryPointOffset = new UInt[numEntryPointOffsets];
     2359    for (UInt idx=0; idx<numEntryPointOffsets; idx++)
     2360    {
     2361      Int bitsRead = m_pcBitstream->getNumBitsRead();
     2362      READ_CODE(offsetLenMinus1+1, uiCode, "entry_point_offset");
     2363      entryPointOffset[ idx ] = uiCode;
     2364      if ( idx == 0 && tilesOrEntropyCodingSyncIdc == 2 )
     2365      {
     2366        // Subtract distance from NALU header start to provide WPP 0-th substream the correct size.
     2367        entryPointOffset[ idx ] -= ( bitsRead + numEntryPointOffsets*(offsetLenMinus1+1) ) >> 3;
     2368      }
     2369    }
     2370  }
     2371
     2372  if ( tilesOrEntropyCodingSyncIdc == 1 ) // tiles
     2373  {
     2374    rpcSlice->setTileLocationCount( numEntryPointOffsets );
     2375
     2376    UInt prevPos = 0;
     2377    for (Int idx=0; idx<rpcSlice->getTileLocationCount(); idx++)
     2378    {
     2379      rpcSlice->setTileLocation( idx, prevPos + entryPointOffset [ idx ] );
     2380      prevPos += entryPointOffset[ idx ];
     2381    }
     2382  }
     2383  else if ( tilesOrEntropyCodingSyncIdc == 2 ) // wavefront
     2384  {
     2385    Int numSubstreams = pps->getNumSubstreams();
     2386    rpcSlice->allocSubstreamSizes(numSubstreams);
     2387    UInt *pSubstreamSizes       = rpcSlice->getSubstreamSizes();
     2388    for (Int idx=0; idx<numSubstreams-1; idx++)
     2389    {
     2390      if ( idx < numEntryPointOffsets )
     2391      {
     2392        pSubstreamSizes[ idx ] = ( entryPointOffset[ idx ] << 3 ) ;
     2393      }
     2394      else
     2395      {
     2396        pSubstreamSizes[ idx ] = 0;
     2397      }
     2398    }
     2399  }
     2400
     2401  if (entryPointOffset)
     2402  {
     2403    delete [] entryPointOffset;
     2404  }
     2405#else
     2406#if WPP_SIMPLIFICATION
     2407  if (pps->getNumSubstreams() > 1)
     2408#else
     2409  if (pps->getEntropyCodingSynchro())
     2410#endif
     2411  {
     2412    UInt uiNumSubstreams = pps->getNumSubstreams();
     2413    rpcSlice->allocSubstreamSizes(uiNumSubstreams);
     2414    UInt *puiSubstreamSizes = rpcSlice->getSubstreamSizes();
     2415
     2416    for (UInt ui = 0; ui+1 < uiNumSubstreams; ui++)
     2417    {
     2418      xReadCode(2, uiCode);
     2419     
     2420      switch ( uiCode )
     2421      {
     2422      case 0:
     2423        xReadCode(8,  uiCode);
     2424        break;
     2425      case 1:
     2426        xReadCode(16, uiCode);
     2427        break;
     2428      case 2:
     2429        xReadCode(24, uiCode);
     2430        break;
     2431      case 3:
     2432        xReadCode(32, uiCode);
     2433        break;
     2434      default:
     2435        printf("Error in parseSliceHeader\n");
     2436        exit(-1);
     2437        break;
     2438      }
     2439      puiSubstreamSizes[ui] = uiCode;
     2440    }
     2441  }
     2442#endif
     2443
     2444  if (!bEntropySlice)
     2445  {
     2446    // Reading location information
     2447#if !REMOVE_TILE_DEPENDENCE
     2448    if (sps->getTileBoundaryIndependenceIdr())
     2449    {   
     2450#endif
     2451#if !TILES_WPP_ENTRY_POINT_SIGNALLING
     2452      xReadCode(1, uiCode); // read flag indicating if location information signaled in slice header
     2453      Bool bTileLocationInformationInSliceHeaderFlag = (uiCode)? true : false;
     2454
     2455      if (bTileLocationInformationInSliceHeaderFlag)
     2456      {
     2457        // location count
     2458        xReadCode(5, uiCode); // number of tiles for which location information signaled
     2459        rpcSlice->setTileLocationCount ( uiCode + 1 );
     2460
     2461        xReadCode(5, uiCode); // number of bits used by diff
     2462        Int iBitsUsedByDiff = uiCode + 1;
     2463
     2464        // read out tile start location
     2465        Int iLastSize = 0;
     2466        for (UInt uiIdx=0; uiIdx<rpcSlice->getTileLocationCount(); uiIdx++)
     2467        {
     2468          Int iAbsDiff, iCurSize, iCurDiff;
     2469          if (uiIdx==0)
     2470          {
     2471            xReadCode(iBitsUsedByDiff-1, uiCode); iAbsDiff  = uiCode;
     2472            rpcSlice->setTileLocation( uiIdx, iAbsDiff );
     2473            iCurDiff  = iAbsDiff;
     2474            iLastSize = iAbsDiff;
     2475          }
     2476          else
     2477          {
     2478            xReadCode(1, uiCode); // read sign
     2479            Int iSign = (uiCode) ? -1 : +1;
     2480
     2481            xReadCode(iBitsUsedByDiff-1, uiCode); iAbsDiff  = uiCode;
     2482            iCurDiff  = (iSign) * iAbsDiff;
     2483            iCurSize  = iLastSize + iCurDiff;
     2484            iLastSize = iCurSize;
     2485            rpcSlice->setTileLocation( uiIdx, rpcSlice->getTileLocation( uiIdx-1 ) + iCurSize ); // calculate byte location
     2486          }
     2487        }
     2488      }
     2489#endif
     2490
     2491      // read out trailing bits
     2492    m_pcBitstream->readOutTrailingBits();
     2493#if !REMOVE_TILE_DEPENDENCE
     2494    }
     2495#endif
     2496  }
    5452497  return;
    5462498}
    5472499
     2500Void TDecCavlc::xParseAlfCuControlParam(AlfCUCtrlInfo& cAlfParam, Int iNumCUsInPic)
     2501{
     2502  UInt uiSymbol;
     2503  Int iSymbol;
     2504
     2505  READ_FLAG (uiSymbol, "alf_cu_control_flag");
     2506  cAlfParam.cu_control_flag = uiSymbol;
     2507  if (cAlfParam.cu_control_flag)
     2508  {
     2509    READ_UVLC (uiSymbol, "alf_cu_control_max_depth");
     2510    cAlfParam.alf_max_depth = uiSymbol;
     2511
     2512    READ_SVLC (iSymbol, "alf_length_cu_control_info");
     2513    cAlfParam.num_alf_cu_flag = (UInt)(iSymbol + iNumCUsInPic);
     2514
     2515    cAlfParam.alf_cu_flag.resize(cAlfParam.num_alf_cu_flag);
     2516
     2517    for(UInt i=0; i< cAlfParam.num_alf_cu_flag; i++)
     2518    {
     2519      READ_FLAG (cAlfParam.alf_cu_flag[i], "alf_cu_flag");
     2520    }
     2521  }
     2522}
     2523
     2524#if !CABAC_INIT_FLAG
    5482525Void TDecCavlc::resetEntropy          (TComSlice* pcSlice)
    5492526{
    550   m_bRunLengthCoding = ! pcSlice->isIntra();
    551   m_uiRun = 0;
    552 
    553 #if !CAVLC_COEF_LRG_BLK
    554   ::memcpy(m_uiLPTableD8,        g_auiLPTableD8,        10*128*sizeof(UInt));
    555 #endif
    556   ::memcpy(m_uiLPTableD4,        g_auiLPTableD4,        3*32*sizeof(UInt));
    557   ::memcpy(m_uiLastPosVlcIndex,  g_auiLastPosVlcIndex,  10*sizeof(UInt));
    558 
    559 #if CAVLC_RQT_CBP
    560   ::memcpy(m_uiCBP_YUV_TableD, g_auiCBP_YUV_TableD, 4*8*sizeof(UInt));
    561   ::memcpy(m_uiCBP_YS_TableD,  g_auiCBP_YS_TableD,  2*4*sizeof(UInt));
    562   ::memcpy(m_uiCBP_YCS_TableD, g_auiCBP_YCS_TableD, 2*8*sizeof(UInt));
    563   ::memcpy(m_uiCBP_4Y_TableD,  g_auiCBP_4Y_TableD,  2*15*sizeof(UInt));
    564   m_uiCBP_4Y_VlcIdx = 0;
    565 #else
    566   m_uiCbpVlcIdx[0] = 0;
    567   m_uiCbpVlcIdx[1] = 0;
    568   ::memcpy(m_uiCBPTableD,        g_auiCBPTableD,        2*8*sizeof(UInt));
    569   ::memcpy(m_uiBlkCBPTableD,     g_auiBlkCBPTableD,     2*15*sizeof(UInt));
    570   m_uiBlkCbpVlcIdx = 0;
    571 #endif
    572 
    573 #if UNIFY_INTER_TABLE
    574   ::memcpy(m_uiMI1TableD, g_auiComMI1TableD, 9*sizeof(UInt));
    575 #else
    576   ::memcpy(m_uiMI1TableD,        g_auiMI1TableD,        8*sizeof(UInt));
    577   ::memcpy(m_uiMI2TableD,        g_auiMI2TableD,        15*sizeof(UInt));
    578 
    579 #if DCM_COMB_LIST
    580   if ( pcSlice->getNoBackPredFlag() || pcSlice->getNumRefIdx(REF_PIC_LIST_C)>0)
    581 #else
    582   if ( pcSlice->getNoBackPredFlag() )
    583 #endif
    584   {
    585     ::memcpy(m_uiMI1TableD,        g_auiMI1TableDNoL1,        8*sizeof(UInt));
    586     ::memcpy(m_uiMI2TableD,        g_auiMI2TableDNoL1,        15*sizeof(UInt));
    587   }
    588 
    589 #if MS_LCEC_ONE_FRAME
    590   if ( pcSlice->getNumRefIdx(REF_PIC_LIST_0) <= 1 && pcSlice->getNumRefIdx(REF_PIC_LIST_1) <= 1 )
    591   {
    592     if ( pcSlice->getNoBackPredFlag() || ( pcSlice->getNumRefIdx(REF_PIC_LIST_C) > 0 && pcSlice->getNumRefIdx(REF_PIC_LIST_C) <= 1 ) )
    593     {
    594       ::memcpy(m_uiMI1TableD,        g_auiMI1TableDOnly1RefNoL1,        8*sizeof(UInt));
    595     }
    596     else
    597     {
    598       ::memcpy(m_uiMI1TableD,        g_auiMI1TableDOnly1Ref,        8*sizeof(UInt));
    599     }
    600   }
    601 #endif
    602 #if MS_LCEC_LOOKUP_TABLE_EXCEPTION
    603   if (pcSlice->getNumRefIdx(REF_PIC_LIST_C)>0)
    604   {
    605     m_uiMI1TableD[8] = 8;
    606   }
    607   else  // GPB case
    608   {
    609     m_uiMI1TableD[8] = m_uiMI1TableD[6];
    610     m_uiMI1TableD[6] = 8;
    611   }
    612 #endif
    613 #endif
    614 
    615 #if LCEC_INTRA_MODE
    616 #if MTK_DCM_MPM
    617   ::memcpy(m_uiIntraModeTableD17[0], g_auiIntraModeTableD17[0], 16*sizeof(UInt));
    618   ::memcpy(m_uiIntraModeTableD34[0], g_auiIntraModeTableD34[0], 33*sizeof(UInt));
    619   ::memcpy(m_uiIntraModeTableD17[1], g_auiIntraModeTableD17[1], 16*sizeof(UInt));
    620   ::memcpy(m_uiIntraModeTableD34[1], g_auiIntraModeTableD34[1], 33*sizeof(UInt));
    621 #else
    622   ::memcpy(m_uiIntraModeTableD17, g_auiIntraModeTableD17, 16*sizeof(UInt));
    623   ::memcpy(m_uiIntraModeTableD34, g_auiIntraModeTableD34, 33*sizeof(UInt));
    624 #endif
    625 #endif
    626 #if QC_LCEC_INTER_MODE
    627   ::memcpy(m_uiSplitTableD, g_auiInterModeTableD, 4*7*sizeof(UInt));
    628 #endif
    629   m_uiMITableVlcIdx = 0;
    630 
    631 #if CAVLC_COUNTER_ADAPT
    632 #if CAVLC_RQT_CBP
    633   ::memset(m_ucCBP_YUV_TableCounter, 0, 4*4*sizeof(UChar));
    634   ::memset(m_ucCBP_4Y_TableCounter,  0, 2*2*sizeof(UChar));
    635   ::memset(m_ucCBP_YCS_TableCounter, 0, 2*4*sizeof(UChar));
    636   ::memset(m_ucCBP_YS_TableCounter,  0, 2*3*sizeof(UChar));
    637 #else
    638   ::memset(m_ucCBFTableCounter,        0,        2*4*sizeof(UChar));
    639   ::memset(m_ucBlkCBPTableCounter,     0,        2*2*sizeof(UChar));
    640 #endif
    641 
    642   ::memset(m_ucMI1TableCounter,        0,          4*sizeof(UChar));
    643   ::memset(m_ucSplitTableCounter,      0,        4*4*sizeof(UChar));
    644 
    645 #if CAVLC_RQT_CBP
    646   m_ucCBP_YUV_TableCounterSum[0] = m_ucCBP_YUV_TableCounterSum[1] = m_ucCBP_YUV_TableCounterSum[2] = m_ucCBP_YUV_TableCounterSum[3] = 0;
    647   m_ucCBP_4Y_TableCounterSum[0] = m_ucCBP_4Y_TableCounterSum[1] = 0;
    648   m_ucCBP_YCS_TableCounterSum[0] = m_ucCBP_YCS_TableCounterSum[1] = 0;
    649   m_ucCBP_YS_TableCounterSum[0] = m_ucCBP_YS_TableCounterSum[1] = 0;
    650 #else
    651   m_ucCBFTableCounterSum[0] = m_ucCBFTableCounterSum[1] = 0;
    652   m_ucBlkCBPTableCounterSum[0] = m_ucBlkCBPTableCounterSum[1] = 0;
    653 #endif
    654 
    655   m_ucSplitTableCounterSum[0] = m_ucSplitTableCounterSum[1] = m_ucSplitTableCounterSum[2]= m_ucSplitTableCounterSum[3] = 0;
    656   m_ucMI1TableCounterSum = 0;
    657 #endif
    658 }
     2527}
     2528#endif
    6592529
    6602530Void TDecCavlc::parseTerminatingBit( UInt& ruiBit )
    6612531{
    6622532  ruiBit = false;
    663   Int iBitsLeft = m_pcBitstream->getBitsLeft();
     2533  Int iBitsLeft = m_pcBitstream->getNumBitsLeft();
    6642534  if(iBitsLeft <= 8)
    6652535  {
    6662536    UInt uiPeekValue = m_pcBitstream->peekBits(iBitsLeft);
    6672537    if (uiPeekValue == (1<<(iBitsLeft-1)))
     2538    {
    6682539      ruiBit = true;
    669   }
    670 }
    671 
    672 Void TDecCavlc::parseAlfCtrlDepth              ( UInt& ruiAlfCtrlDepth )
    673 {
    674   UInt uiSymbol;
    675   xReadUnaryMaxSymbol(uiSymbol, g_uiMaxCUDepth-1);
    676   ruiAlfCtrlDepth = uiSymbol;
    677 }
    678 
    679 Void TDecCavlc::parseAlfCtrlFlag( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
    680 {
    681   if (!m_bAlfCtrl)
    682     return;
    683 
    684   if( uiDepth > m_uiMaxAlfCtrlDepth && !pcCU->isFirstAbsZorderIdxInDepth(uiAbsPartIdx, m_uiMaxAlfCtrlDepth))
    685   {
    686     return;
    687   }
    688 
    689   UInt uiSymbol;
    690   xReadFlag( uiSymbol );
    691 
    692   if (uiDepth > m_uiMaxAlfCtrlDepth)
    693   {
    694     pcCU->setAlfCtrlFlagSubParts( uiSymbol, uiAbsPartIdx, m_uiMaxAlfCtrlDepth);
    695   }
    696   else
    697   {
    698     pcCU->setAlfCtrlFlagSubParts( uiSymbol, uiAbsPartIdx, uiDepth );
     2540    }
    6992541  }
    7002542}
     
    7022544Void TDecCavlc::parseSkipFlag( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
    7032545{
    704 #if QC_LCEC_INTER_MODE
    705   return;
    706 #else
    707 
    708   if( pcCU->getSlice()->isIntra() )
    709   {
    710     return;
    711   }
    712 
    713   UInt uiSymbol = 0;
    714   xReadFlag( uiSymbol );
    715 
    716   if( uiSymbol )
    717   {
    718     pcCU->setPredModeSubParts( MODE_SKIP,  uiAbsPartIdx, uiDepth );
    719     pcCU->setPartSizeSubParts( SIZE_2Nx2N, uiAbsPartIdx, uiDepth );
    720     pcCU->setSizeSubParts( g_uiMaxCUWidth>>uiDepth, g_uiMaxCUHeight>>uiDepth, uiAbsPartIdx, uiDepth );
    721 #if HHI_MRG_SKIP
    722     pcCU->setMergeFlagSubParts( true , uiAbsPartIdx, 0, uiDepth );
    723 #else
    724     TComMv cZeroMv(0,0);
    725     pcCU->getCUMvField( REF_PIC_LIST_0 )->setAllMvd    ( cZeroMv, SIZE_2Nx2N, uiAbsPartIdx, 0, uiDepth );
    726     pcCU->getCUMvField( REF_PIC_LIST_1 )->setAllMvd    ( cZeroMv, SIZE_2Nx2N, uiAbsPartIdx, 0, uiDepth );
    727 
    728     pcCU->setTrIdxSubParts( 0, uiAbsPartIdx, uiDepth );
    729     pcCU->setCbfSubParts  ( 0, 0, 0, uiAbsPartIdx, uiDepth );
    730 
    731     if ( pcCU->getSlice()->isInterP() )
    732     {
    733       pcCU->setInterDirSubParts( 1, uiAbsPartIdx, 0, uiDepth );
    734 
    735       if ( pcCU->getSlice()->getNumRefIdx( REF_PIC_LIST_0 ) > 0 )
    736         pcCU->getCUMvField( REF_PIC_LIST_0 )->setAllRefIdx(  0, SIZE_2Nx2N, uiAbsPartIdx, 0, uiDepth );
    737       if ( pcCU->getSlice()->getNumRefIdx( REF_PIC_LIST_1 ) > 0 )
    738         pcCU->getCUMvField( REF_PIC_LIST_1 )->setAllRefIdx( NOT_VALID, SIZE_2Nx2N, uiAbsPartIdx, 0, uiDepth );
    739     }
    740     else
    741     {
    742       pcCU->setInterDirSubParts( 3, uiAbsPartIdx, 0, uiDepth );
    743 
    744       if ( pcCU->getSlice()->getNumRefIdx( REF_PIC_LIST_0 ) > 0 )
    745         pcCU->getCUMvField( REF_PIC_LIST_0 )->setAllRefIdx(  0, SIZE_2Nx2N, uiAbsPartIdx, 0, uiDepth );
    746       if ( pcCU->getSlice()->getNumRefIdx( REF_PIC_LIST_1 ) > 0 )
    747         pcCU->getCUMvField( REF_PIC_LIST_1 )->setAllRefIdx( 0, SIZE_2Nx2N, uiAbsPartIdx, 0, uiDepth );
    748     }
    749   }
    750 #endif // HHI_MRG_SKIP
    751 #endif // QC_LCEC_INTER_MODE
    752 }
    753 
    754 /** parse the motion vector predictor index
    755  * \param pcCU
    756  * \param riMVPIdx
    757  * \param iMVPNum
    758  * \param uiAbsPartIdx
    759  * \param uiDepth
    760  * \param eRefList
    761  * \returns Void
    762  */
    763 Void TDecCavlc::parseMVPIdx( TComDataCU* pcCU, Int& riMVPIdx, Int iMVPNum, UInt uiAbsPartIdx, UInt uiDepth, RefPicList eRefList )
    764 {
    765   UInt uiSymbol;
    766   xReadUnaryMaxSymbol(uiSymbol, iMVPNum-1);
    767   riMVPIdx = uiSymbol;
    768 }
    769 
    770 Void TDecCavlc::parseViewIdx(Int& riViewIdx)
    771 {
    772   UInt uiSymbol;
    773   xReadUnaryMaxSymbol(uiSymbol, MAX_NUMBER_VIEWS);
    774   riViewIdx = uiSymbol;
    775 }
    776 
    777 #if QC_LCEC_INTER_MODE
    778 /** parse the split flag
    779  * \param pcCU
    780  * \param uiAbsPartIdx
    781  * \param uiDepth
    782  * \returns Void
    783  */
     2546  assert(0);
     2547}
     2548
     2549#if HHI_INTER_VIEW_MOTION_PRED
     2550Void TDecCavlc::parseMVPIdx( Int& riMVPIdx, Int iAMVPCands )
     2551#else
     2552Void TDecCavlc::parseMVPIdx( Int& riMVPIdx )
     2553#endif
     2554{
     2555  assert(0);
     2556}
     2557
    7842558Void TDecCavlc::parseSplitFlag     ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
    7852559{
    786   if (pcCU->getSlice()->isIntra())
    787   {
    788     if( uiDepth == g_uiMaxCUDepth - g_uiAddCUDepth )
    789     {
    790       pcCU->setDepthSubParts( uiDepth, uiAbsPartIdx );
    791       return ;
    792     }
    793 
    794     UInt uiSymbol;
    795     xReadFlag( uiSymbol );
    796     pcCU->setDepthSubParts( uiDepth + uiSymbol, uiAbsPartIdx );
    797 
    798     return ;
    799   }
    800   UInt tmp=0;
    801   UInt cx=0;
    802   UInt uiMode ;
    803   {
    804     UInt iMaxLen= (uiDepth == g_uiMaxCUDepth - g_uiAddCUDepth)?5:6;
    805     while (tmp==0 && cx<iMaxLen)
    806     {
    807       xReadFlag( tmp );
    808       cx++;
    809     };
    810     if(tmp!=0)
    811       cx--;
    812 
    813     UInt uiDepthRemember = uiDepth;
    814     if ( uiDepth == g_uiMaxCUDepth - g_uiAddCUDepth )
    815     {
    816       uiDepth = 3;
    817     }
    818     UInt x = m_uiSplitTableD[uiDepth][cx];
    819     /* Adapt table */
    820     uiMode = x;
    821 #if CAVLC_COUNTER_ADAPT
    822     adaptCodeword(cx, m_ucSplitTableCounter[uiDepth],  m_ucSplitTableCounterSum[uiDepth],   m_uiSplitTableD[uiDepth],  NULL, 4 );
    823 #else
    824     if (cx>0)
    825     {
    826       UInt cy = Max(0,cx-1);
    827       UInt y = m_uiSplitTableD[uiDepth][cy];
    828       m_uiSplitTableD[uiDepth][cy] = x;
    829       m_uiSplitTableD[uiDepth][cx] = y;
    830     }
    831 #endif
    832     uiDepth = uiDepthRemember;
    833   }
    834   if (uiMode==0)
    835   {
    836     pcCU->setDepthSubParts( uiDepth + 1, uiAbsPartIdx );
    837   }
    838   else
    839   {
    840     pcCU->setPartSizeSubParts( SIZE_2Nx2N, uiAbsPartIdx, uiDepth );
    841     pcCU->setMergeFlagSubParts(false, uiAbsPartIdx,0, uiDepth );
    842     pcCU->setDepthSubParts( uiDepth    , uiAbsPartIdx );
    843     if (uiMode ==1)
    844     {
    845       TComMv cZeroMv(0,0);
    846       pcCU->setPredModeSubParts( MODE_SKIP,  uiAbsPartIdx, uiDepth );
    847       pcCU->setPartSizeSubParts( SIZE_2Nx2N, uiAbsPartIdx, uiDepth );
    848       pcCU->setSizeSubParts( g_uiMaxCUWidth>>uiDepth, g_uiMaxCUHeight>>uiDepth, uiAbsPartIdx, uiDepth );
    849       pcCU->getCUMvField( REF_PIC_LIST_0 )->setAllMvd    ( cZeroMv, SIZE_2Nx2N, uiAbsPartIdx, 0, uiDepth );
    850       pcCU->getCUMvField( REF_PIC_LIST_1 )->setAllMvd    ( cZeroMv, SIZE_2Nx2N, uiAbsPartIdx, 0, uiDepth );
    851       pcCU->setTrIdxSubParts( 0, uiAbsPartIdx, uiDepth );
    852       pcCU->setCbfSubParts  ( 0, 0, 0, uiAbsPartIdx, uiDepth );
    853 
    854 #if HHI_MRG_SKIP
    855       pcCU->setMergeFlagSubParts( true, uiAbsPartIdx, 0, uiDepth );
    856 #else
    857       if ( pcCU->getSlice()->isInterP() )
    858       {
    859         pcCU->setInterDirSubParts( 1, uiAbsPartIdx, 0, uiDepth );
    860 
    861         if ( pcCU->getSlice()->getNumRefIdx( REF_PIC_LIST_0 ) > 0 )
    862           pcCU->getCUMvField( REF_PIC_LIST_0 )->setAllRefIdx(  0, SIZE_2Nx2N, uiAbsPartIdx, 0, uiDepth );
    863         if ( pcCU->getSlice()->getNumRefIdx( REF_PIC_LIST_1 ) > 0 )
    864           pcCU->getCUMvField( REF_PIC_LIST_1 )->setAllRefIdx( NOT_VALID, SIZE_2Nx2N, uiAbsPartIdx, 0, uiDepth );
    865       }
    866       else
    867       {
    868         pcCU->setInterDirSubParts( 3, uiAbsPartIdx, 0, uiDepth );
    869 
    870         if ( pcCU->getSlice()->getNumRefIdx( REF_PIC_LIST_0 ) > 0 )
    871           pcCU->getCUMvField( REF_PIC_LIST_0 )->setAllRefIdx(  0, SIZE_2Nx2N, uiAbsPartIdx, 0, uiDepth );
    872         if ( pcCU->getSlice()->getNumRefIdx( REF_PIC_LIST_1 ) > 0 )
    873           pcCU->getCUMvField( REF_PIC_LIST_1 )->setAllRefIdx( 0, SIZE_2Nx2N, uiAbsPartIdx, 0, uiDepth );
    874       }
    875 #endif
    876     }
    877     else if (uiMode==2)
    878     {
    879       pcCU->setPredModeSubParts( MODE_INTER, uiAbsPartIdx, uiDepth );
    880       pcCU->setPartSizeSubParts( SIZE_2Nx2N, uiAbsPartIdx, uiDepth );
    881       pcCU->setMergeFlagSubParts(true, uiAbsPartIdx,0, uiDepth );
    882       pcCU->setSizeSubParts( g_uiMaxCUWidth>>uiDepth, g_uiMaxCUHeight>>uiDepth, uiAbsPartIdx, uiDepth );
    883     }
    884     else if (uiMode==6)
    885     {
    886 #if MTK_DISABLE_INTRA_NxN_SPLIT && HHI_DISABLE_INTER_NxN_SPLIT
    887       if (uiDepth != g_uiMaxCUDepth - g_uiAddCUDepth)
    888       {
    889         pcCU->setPredModeSubParts( MODE_INTRA, uiAbsPartIdx, uiDepth );
    890         pcCU->setPartSizeSubParts( SIZE_2Nx2N, uiAbsPartIdx, uiDepth );
    891         pcCU->setSizeSubParts( g_uiMaxCUWidth>>uiDepth, g_uiMaxCUHeight>>uiDepth, uiAbsPartIdx, uiDepth );
    892         UInt uiTrLevel = 0;
    893         UInt uiWidthInBit  = g_aucConvertToBit[pcCU->getWidth(uiAbsPartIdx)]+2;
    894         UInt uiTrSizeInBit = g_aucConvertToBit[pcCU->getSlice()->getSPS()->getMaxTrSize()]+2;
    895         uiTrLevel          = uiWidthInBit >= uiTrSizeInBit ? uiWidthInBit - uiTrSizeInBit : 0;
    896         pcCU->setTrIdxSubParts( uiTrLevel, uiAbsPartIdx, uiDepth );
    897       }
    898       else
    899 #endif
    900       {
    901         pcCU->setPredModeSubParts( MODE_INTER, uiAbsPartIdx, uiDepth );
    902         pcCU->setPartSizeSubParts( SIZE_NxN, uiAbsPartIdx, uiDepth );
    903       }
    904     }
    905     else
    906     {
    907       pcCU->setPredModeSubParts( MODE_INTER, uiAbsPartIdx, uiDepth );
    908       pcCU->setPartSizeSubParts( PartSize(uiMode-3), uiAbsPartIdx, uiDepth );
    909       pcCU->setSizeSubParts( g_uiMaxCUWidth>>uiDepth, g_uiMaxCUHeight>>uiDepth, uiAbsPartIdx, uiDepth );
    910     }
    911   }
    912 }
    913 #else
    914 Void TDecCavlc::parseSplitFlag( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
    915 {
    916   if( uiDepth == g_uiMaxCUDepth - g_uiAddCUDepth )
    917   {
    918     pcCU->setDepthSubParts( uiDepth, uiAbsPartIdx );
    919     return ;
    920   }
    921 
    922   UInt uiSymbol;
    923   xReadFlag( uiSymbol );
    924   pcCU->setDepthSubParts( uiDepth + uiSymbol, uiAbsPartIdx );
    925 
    926   return ;
    927 }
    928 #endif
    929 
    930 #if QC_LCEC_INTER_MODE
    931 
    932 /** parse partition size
    933  * \param pcCU
    934  * \param uiAbsPartIdx
    935  * \param uiDepth
    936  * \returns Void
    937  */
     2560  assert(0);
     2561}
     2562
    9382563Void TDecCavlc::parsePartSize( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
    9392564{
    940   UInt uiMode=0;
    941   if ( pcCU->getSlice()->isIntra()&& pcCU->isIntra( uiAbsPartIdx ) )
    942   {
    943 #if MTK_DISABLE_INTRA_NxN_SPLIT
    944     uiMode = 1;
    945     if ( uiDepth == (g_uiMaxCUDepth - g_uiAddCUDepth ))
    946 #endif
    947     {
    948       UInt uiSymbol;
    949       xReadFlag( uiSymbol );
    950       uiMode = uiSymbol ? 1 : 2;
    951     }
    952   }
    953 #if MTK_DISABLE_INTRA_NxN_SPLIT && HHI_DISABLE_INTER_NxN_SPLIT
    954   else if (uiDepth != (g_uiMaxCUDepth - g_uiAddCUDepth ) || pcCU->getPartitionSize(uiAbsPartIdx ) != SIZE_NxN)
    955 #else
    956   else if (pcCU->getPartitionSize(uiAbsPartIdx ) != SIZE_NxN)
    957 #endif
    958   {
    959     return;
    960   }
    961   else
    962   {
    963     UInt uiSymbol;
    964     xReadFlag( uiSymbol );
    965     if(uiSymbol)
    966     {
    967       uiMode = 1;
    968     }
    969     else
    970     {
    971 #if (MTK_DISABLE_INTRA_NxN_SPLIT && !HHI_DISABLE_INTER_NxN_SPLIT) || (!MTK_DISABLE_INTRA_NxN_SPLIT && HHI_DISABLE_INTER_NxN_SPLIT )
    972       if ( uiDepth != (g_uiMaxCUDepth - g_uiAddCUDepth ))
    973       {
    974 #if MTK_DISABLE_INTRA_NxN_SPLIT && !HHI_DISABLE_INTER_NxN_SPLIT
    975         uiMode = 0;
    976 #elif !MTK_DISABLE_INTRA_NxN_SPLIT && HHI_DISABLE_INTER_NxN_SPLIT
    977         uiMode = 2;
    978 #endif
    979       }
    980       else
    981 #endif
    982       {
    983         xReadFlag( uiSymbol );
    984         uiMode = uiSymbol ? 2 : 0;
    985       }
    986     }
    987   }
    988   PartSize ePartSize;
    989   PredMode eMode;
    990   if (uiMode > 0)
    991   {
    992     eMode = MODE_INTRA;
    993     ePartSize = (uiMode==1) ? SIZE_2Nx2N:SIZE_NxN;
    994   }
    995   else
    996   {
    997     eMode = MODE_INTER;
    998     ePartSize = SIZE_NxN;
    999   }
    1000   pcCU->setPredModeSubParts( eMode    , uiAbsPartIdx, uiDepth );
    1001   pcCU->setPartSizeSubParts( ePartSize, uiAbsPartIdx, uiDepth );
    1002   pcCU->setSizeSubParts( g_uiMaxCUWidth>>uiDepth, g_uiMaxCUHeight>>uiDepth, uiAbsPartIdx, uiDepth );
    1003 
    1004   if( pcCU->getPredictionMode(uiAbsPartIdx) == MODE_INTRA )
    1005   {
    1006     UInt uiTrLevel = 0;
    1007     UInt uiWidthInBit  = g_aucConvertToBit[pcCU->getWidth(uiAbsPartIdx)] + 2;
    1008     UInt uiTrSizeInBit = g_aucConvertToBit[pcCU->getSlice()->getSPS()->getMaxTrSize()] + 2;
    1009     uiTrLevel          = uiWidthInBit >= uiTrSizeInBit ? uiWidthInBit - uiTrSizeInBit : 0;
    1010     if( pcCU->getPartitionSize( uiAbsPartIdx ) == SIZE_NxN )
    1011     {
    1012       pcCU->setTrIdxSubParts( 1 + uiTrLevel, uiAbsPartIdx, uiDepth );
    1013     }
    1014     else
    1015     {
    1016       pcCU->setTrIdxSubParts( uiTrLevel, uiAbsPartIdx, uiDepth );
    1017     }
    1018   }
    1019 }
    1020 #else
    1021 Void TDecCavlc::parsePartSize( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
    1022 {
    1023   UInt uiSymbol, uiMode = 0;
    1024   PartSize eMode;
    1025 
    1026   if ( pcCU->isIntra( uiAbsPartIdx ) )
    1027   {
    1028 #if MTK_DISABLE_INTRA_NxN_SPLIT
    1029     eMode = SIZE_2Nx2N;
    1030     if( uiDepth == g_uiMaxCUDepth - g_uiAddCUDepth )
    1031 #endif
    1032     {
    1033       xReadFlag( uiSymbol );
    1034       eMode = uiSymbol ? SIZE_2Nx2N : SIZE_NxN;
    1035     }
    1036   }
    1037   else
    1038   {
    1039 #if HHI_RMP_SWITCH
    1040     if ( !pcCU->getSlice()->getSPS()->getUseRMP())
    1041     {
    1042       xReadFlag( uiSymbol );
    1043       if( uiSymbol )
    1044         uiMode = 0;
    1045       else
    1046         uiMode = 3;
    1047     }
    1048     else
    1049 #endif
    1050     {
    1051       UInt uiMaxNumBits = 3;
    1052       for ( UInt ui = 0; ui < uiMaxNumBits; ui++ )
    1053       {
    1054         xReadFlag( uiSymbol );
    1055         if ( uiSymbol )
    1056         {
    1057           break;
    1058         }
    1059         uiMode++;
    1060       }
    1061     }
    1062     eMode = (PartSize) uiMode;
    1063 
    1064     if (pcCU->getSlice()->isInterB() && uiMode == 3)
    1065     {
    1066 #if HHI_DISABLE_INTER_NxN_SPLIT
    1067       uiSymbol = 0;
    1068       if( uiDepth == g_uiMaxCUDepth - g_uiAddCUDepth )
    1069 #endif
    1070       {
    1071         xReadFlag( uiSymbol );
    1072       }
    1073 
    1074       if (uiSymbol == 0)
    1075       {
    1076         pcCU->setPredModeSubParts( MODE_INTRA, uiAbsPartIdx, uiDepth );
    1077 #if MTK_DISABLE_INTRA_NxN_SPLIT
    1078         if( uiDepth == g_uiMaxCUDepth - g_uiAddCUDepth )
    1079 #endif
    1080         {
    1081           xReadFlag( uiSymbol );
    1082         }
    1083         if (uiSymbol == 0)
    1084           eMode = SIZE_2Nx2N;
    1085       }
    1086     }
    1087 
    1088   }
    1089 
    1090   pcCU->setPartSizeSubParts( eMode, uiAbsPartIdx, uiDepth );
    1091   pcCU->setSizeSubParts( g_uiMaxCUWidth>>uiDepth, g_uiMaxCUHeight>>uiDepth, uiAbsPartIdx, uiDepth );
    1092 
    1093   UInt uiTrLevel = 0;
    1094 
    1095   UInt uiWidthInBit  = g_aucConvertToBit[pcCU->getWidth(uiAbsPartIdx)]+2;
    1096   UInt uiTrSizeInBit = g_aucConvertToBit[pcCU->getSlice()->getSPS()->getMaxTrSize()]+2;
    1097   uiTrLevel          = uiWidthInBit >= uiTrSizeInBit ? uiWidthInBit - uiTrSizeInBit : 0;
    1098 
    1099   if( pcCU->getPredictionMode(uiAbsPartIdx) == MODE_INTRA )
    1100   {
    1101     if( pcCU->getPartitionSize( uiAbsPartIdx ) == SIZE_NxN )
    1102     {
    1103       pcCU->setTrIdxSubParts( 1+uiTrLevel, uiAbsPartIdx, uiDepth );
    1104     }
    1105     else
    1106     {
    1107       pcCU->setTrIdxSubParts( uiTrLevel, uiAbsPartIdx, uiDepth );
    1108     }
    1109   }
    1110 }
    1111 #endif
    1112 
    1113 /** parse prediction mode
    1114  * \param pcCU
    1115  * \param uiAbsPartIdx
    1116  * \param uiDepth
    1117  * \returns Void
    1118  */
     2565  assert(0);
     2566}
     2567
    11192568Void TDecCavlc::parsePredMode( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
    11202569{
    1121   if( pcCU->getSlice()->isIntra() )
    1122   {
    1123     pcCU->setPredModeSubParts( MODE_INTRA, uiAbsPartIdx, uiDepth );
    1124     return ;
    1125   }
    1126 #if !QC_LCEC_INTER_MODE
    1127   UInt uiSymbol;
    1128   Int  iPredMode = MODE_INTER;
    1129 
    1130   if ( pcCU->getSlice()->isInterB() )
    1131   {
    1132     pcCU->setPredModeSubParts( (PredMode)iPredMode, uiAbsPartIdx, uiDepth );
    1133     return;
    1134   }
    1135   xReadFlag( uiSymbol );
    1136   iPredMode += uiSymbol;
    1137 
    1138   pcCU->setPredModeSubParts( (PredMode)iPredMode, uiAbsPartIdx, uiDepth );
    1139 #endif
    1140 }
    1141 
    1142 #if LCEC_INTRA_MODE
    1143 #if MTK_DCM_MPM
    1144 Void TDecCavlc::parseIntraDirLumaAng  ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
    1145 {
    1146   Int  uiIPredMode = 0;
    1147   Int  iIntraIdx = pcCU->getIntraSizeIdx(uiAbsPartIdx);
    1148 
    1149   Int uiPreds[2] = {-1, -1};
    1150   Int uiPredNum = pcCU->getIntraDirLumaPredictor(uiAbsPartIdx, uiPreds);
    1151 
    1152   if ( g_aucIntraModeBitsAng[iIntraIdx] < 5 )
    1153   {
    1154      UInt uiSymbol;
    1155      xReadFlag( uiSymbol );
    1156      if ( uiSymbol )
    1157      {
    1158        if(uiPredNum == 1)
    1159        {
    1160         uiIPredMode = uiPreds[0];
    1161        }
    1162        else
    1163        {
    1164         xReadFlag( uiSymbol );
    1165         uiIPredMode = uiPreds[uiSymbol];
    1166        }
    1167      }
    1168      else
    1169      {
    1170       xReadFlag( uiSymbol ); uiIPredMode  = uiSymbol;
    1171       if ( g_aucIntraModeBitsAng[iIntraIdx] > 2 ) { xReadFlag( uiSymbol ); uiIPredMode |= uiSymbol << 1; }
    1172       if ( g_aucIntraModeBitsAng[iIntraIdx] > 3 ) { xReadFlag( uiSymbol ); uiIPredMode |= uiSymbol << 2; }
    1173 
    1174       for(UInt i = 0; i < uiPredNum; i++)
    1175       {
    1176         if(uiIPredMode >= uiPreds[i]) { uiIPredMode ++;}
    1177       }
    1178 
    1179     }
    1180   }
    1181   else
    1182   {
    1183   Int  iDir, iDirLarger, iRankIntraMode, iRankIntraModeLarger;
    1184 
    1185   const UInt *huff;
    1186   const UInt *lengthHuff;
    1187   UInt  totMode;
    1188   UInt  *m_uiIntraModeTableD;
    1189 
    1190   if ( g_aucIntraModeBitsAng[iIntraIdx] == 5 )
    1191   {
    1192   totMode = (uiPredNum == 1)? 17: 16;
    1193   huff = huff17_2[uiPredNum - 1];
    1194   lengthHuff = lengthHuff17_2[uiPredNum - 1];
    1195   m_uiIntraModeTableD = m_uiIntraModeTableD17[uiPredNum - 1];
    1196   }
    1197   else
    1198   {
    1199   totMode = (uiPredNum == 1)? 34: 33;
    1200   huff = huff34_2[uiPredNum - 1];
    1201   lengthHuff = lengthHuff34_2[uiPredNum - 1];
    1202   m_uiIntraModeTableD = m_uiIntraModeTableD34[uiPredNum - 1];
    1203   }
    1204 
    1205   UInt uiCode;
    1206   UInt uiLength = lengthHuff[totMode - 1];
    1207 
    1208   m_pcBitstream->pseudoRead(uiLength,uiCode);
    1209   if ((uiCode>>(uiLength- lengthHuff[0])) == huff[0])
    1210   {
    1211       m_pcBitstream->read(lengthHuff[0],uiCode);
    1212 
    1213      if(uiPredNum == 1)
    1214      {
    1215         uiIPredMode = uiPreds[0];
    1216      }
    1217      else if(uiPredNum == 2)
    1218      {
    1219         UInt uiPredIdx= 0;
    1220         xReadFlag( uiPredIdx );
    1221         uiIPredMode = uiPreds[uiPredIdx];
    1222      }
    1223 
    1224   }
    1225   else
    1226   {
    1227       iRankIntraMode = 0;
    1228 
    1229       for(Int i = 1; i < totMode; i++)
    1230      {
    1231         if( (uiCode>>(uiLength- lengthHuff[i])) == huff[i])
    1232         {
    1233           m_pcBitstream->read(lengthHuff[i], uiCode);
    1234           iRankIntraMode = i;
    1235           break;
    1236         }
    1237       }
    1238 
    1239      iRankIntraMode --;
    1240      iDir = m_uiIntraModeTableD[iRankIntraMode];
    1241      iRankIntraModeLarger = Max(0,iRankIntraMode-1);
    1242      iDirLarger = m_uiIntraModeTableD[iRankIntraModeLarger];
    1243      m_uiIntraModeTableD[iRankIntraModeLarger] = iDir;
    1244      m_uiIntraModeTableD[iRankIntraMode] = iDirLarger;
    1245 
    1246      for(UInt i = 0; i < uiPredNum; i++)
    1247      {
    1248        if(iDir >= uiPreds[i])
    1249        {
    1250          iDir ++;
    1251        }
    1252      }
    1253 
    1254      uiIPredMode = iDir;
    1255 
    1256 
    1257     }
    1258   }
    1259 #if ADD_PLANAR_MODE
    1260   if (uiIPredMode == 2)
    1261   {
    1262     UInt planarFlag;
    1263     xReadFlag( planarFlag );
    1264     if ( planarFlag )
    1265     {
    1266       uiIPredMode = PLANAR_IDX;
    1267     }
    1268   }
    1269 #endif
    1270 
    1271   pcCU->setLumaIntraDirSubParts( (UChar)uiIPredMode, uiAbsPartIdx, uiDepth );
    1272 }
    1273 #else
    1274 Void TDecCavlc::parseIntraDirLumaAng  ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
    1275 {
    1276   UInt uiSymbol;
    1277   Int  uiIPredMode;
    1278   Int  iMostProbable = pcCU->getMostProbableIntraDirLuma( uiAbsPartIdx );
    1279   Int  iIntraIdx = pcCU->getIntraSizeIdx(uiAbsPartIdx);
    1280   Int  iDir, iDirLarger, iRankIntraMode, iRankIntraModeLarger;
    1281 
    1282   Int  iLeft          = pcCU->getLeftIntraDirLuma( uiAbsPartIdx );
    1283   Int  iAbove         = pcCU->getAboveIntraDirLuma( uiAbsPartIdx );
    1284   UInt ind=(iLeft==iAbove)? 0 : 1;
    1285 
    1286   const UInt *huff17=huff17_2[ind];
    1287   const UInt *lengthHuff17=lengthHuff17_2[ind];
    1288   const UInt *huff34=huff34_2[ind];
    1289   const UInt *lengthHuff34=lengthHuff34_2[ind];
    1290 
    1291   if ( g_aucIntraModeBitsAng[iIntraIdx] < 5 )
    1292   {
    1293     xReadFlag( uiSymbol );
    1294     if ( uiSymbol )
    1295       uiIPredMode = iMostProbable;
    1296     else
    1297     {
    1298       xReadFlag( uiSymbol ); uiIPredMode  = uiSymbol;
    1299       if ( g_aucIntraModeBitsAng[iIntraIdx] > 2 ) { xReadFlag( uiSymbol ); uiIPredMode |= uiSymbol << 1; }
    1300       if ( g_aucIntraModeBitsAng[iIntraIdx] > 3 ) { xReadFlag( uiSymbol ); uiIPredMode |= uiSymbol << 2; }
    1301       if(uiIPredMode >= iMostProbable)
    1302         uiIPredMode ++;
    1303     }
    1304   }
    1305   else if ( g_aucIntraModeBitsAng[iIntraIdx] == 5 )
    1306   {
    1307     UInt uiCode;
    1308     UInt uiLength = lengthHuff17[15];
    1309     m_pcBitstream->pseudoRead(uiLength,uiCode);
    1310     if ((uiCode>>(uiLength- lengthHuff17[0])) == huff17[0])
    1311     {
    1312       m_pcBitstream->read(lengthHuff17[0],uiCode);
    1313       uiIPredMode = iMostProbable;
    1314     }
    1315     else
    1316     {
    1317       iRankIntraMode = 0;
    1318       for (Int i=1;i<17;i++)
    1319       {
    1320         if( (uiCode>>(uiLength- lengthHuff17[i])) == huff17[i])
    1321         {
    1322           m_pcBitstream->read(lengthHuff17[i], uiCode);
    1323           iRankIntraMode = i;
    1324           break;
    1325         }
    1326       }
    1327 
    1328       if ( iRankIntraMode > 0 )
    1329         iRankIntraMode --;
    1330       iDir = m_uiIntraModeTableD17[iRankIntraMode];
    1331 
    1332       iRankIntraModeLarger = Max(0,iRankIntraMode-1);
    1333       iDirLarger = m_uiIntraModeTableD17[iRankIntraModeLarger];
    1334 
    1335       m_uiIntraModeTableD17[iRankIntraModeLarger] = iDir;
    1336       m_uiIntraModeTableD17[iRankIntraMode] = iDirLarger;
    1337 
    1338       uiIPredMode = (iDir>=iMostProbable? iDir+1: iDir);
    1339     }
    1340   }
    1341   else
    1342   {
    1343     UInt uiCode;
    1344     UInt uiLength = lengthHuff34[32];
    1345     m_pcBitstream->pseudoRead(uiLength,uiCode);
    1346     if ((uiCode>>(uiLength- lengthHuff34[0])) == huff34[0])
    1347     {
    1348       m_pcBitstream->read(lengthHuff34[0],uiCode);
    1349       uiIPredMode = iMostProbable;
    1350     }
    1351     else
    1352     {
    1353       iRankIntraMode = 0;
    1354       for (Int i=1;i<34;i++)
    1355       {
    1356         if( (uiCode>>(uiLength- lengthHuff34[i])) == huff34[i])
    1357         {
    1358           m_pcBitstream->read(lengthHuff34[i], uiCode);
    1359           iRankIntraMode = i;
    1360           break;
    1361         }
    1362       }
    1363 
    1364       if ( iRankIntraMode > 0 )
    1365         iRankIntraMode --;
    1366       iDir = m_uiIntraModeTableD34[iRankIntraMode];
    1367 
    1368       iRankIntraModeLarger = Max(0,iRankIntraMode-1);
    1369       iDirLarger = m_uiIntraModeTableD34[iRankIntraModeLarger];
    1370 
    1371       m_uiIntraModeTableD34[iRankIntraModeLarger] = iDir;
    1372       m_uiIntraModeTableD34[iRankIntraMode] = iDirLarger;
    1373 
    1374       uiIPredMode = (iDir>=iMostProbable? iDir+1: iDir);
    1375     }
    1376   }
    1377 
    1378 #if ADD_PLANAR_MODE
    1379   if (uiIPredMode == 2)
    1380   {
    1381     UInt planarFlag;
    1382     xReadFlag( planarFlag );
    1383     if ( planarFlag )
    1384     {
    1385       uiIPredMode = PLANAR_IDX;
    1386     }
    1387   }
    1388 #endif
    1389   pcCU->setLumaIntraDirSubParts( (UChar)uiIPredMode, uiAbsPartIdx, uiDepth );
    1390 }
    1391 #endif
    1392 #else
    1393 Void TDecCavlc::parseIntraDirLumaAng  ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
    1394 {
    1395   UInt uiSymbol;
    1396   Int  uiIPredMode;
    1397   Int  iMostProbable = pcCU->getMostProbableIntraDirLuma( uiAbsPartIdx );
    1398 
    1399   xReadFlag( uiSymbol );
    1400 
    1401   if ( uiSymbol )
    1402     uiIPredMode = iMostProbable;
    1403   else
    1404   {
    1405     Int iIntraIdx = pcCU->getIntraSizeIdx(uiAbsPartIdx);
    1406     if ( g_aucIntraModeBitsAng[iIntraIdx] < 6 )
    1407     {
    1408       xReadFlag( uiSymbol ); uiIPredMode  = uiSymbol;
    1409       if ( g_aucIntraModeBitsAng[iIntraIdx] > 2 ) { xReadFlag( uiSymbol ); uiIPredMode |= uiSymbol << 1; }
    1410       if ( g_aucIntraModeBitsAng[iIntraIdx] > 3 ) { xReadFlag( uiSymbol ); uiIPredMode |= uiSymbol << 2; }
    1411       if ( g_aucIntraModeBitsAng[iIntraIdx] > 4 ) { xReadFlag( uiSymbol ); uiIPredMode |= uiSymbol << 3; }
    1412     }
    1413     else
    1414     {
    1415       xReadFlag( uiSymbol ); uiIPredMode  = uiSymbol;
    1416       xReadFlag( uiSymbol ); uiIPredMode |= uiSymbol << 1;
    1417       xReadFlag( uiSymbol ); uiIPredMode |= uiSymbol << 2;
    1418       xReadFlag( uiSymbol ); uiIPredMode |= uiSymbol << 3;
    1419       xReadFlag( uiSymbol ); uiIPredMode |= uiSymbol << 4;
    1420 
    1421       if (uiIPredMode == 31)
    1422       { // Escape coding for the last two modes
    1423         xReadFlag( uiSymbol );
    1424         uiIPredMode = uiSymbol ? 32 : 31;
    1425       }
    1426     }
    1427 
    1428     if (uiIPredMode >= iMostProbable)
    1429       uiIPredMode++;
    1430   }
    1431 
    1432 #if ADD_PLANAR_MODE
    1433   if (uiIPredMode == 2)
    1434   {
    1435     UInt planarFlag;
    1436     xReadFlag( planarFlag );
    1437     if ( planarFlag )
    1438     {
    1439       uiIPredMode = PLANAR_IDX;
    1440     }
    1441   }
    1442 #endif
    1443   pcCU->setLumaIntraDirSubParts( (UChar)uiIPredMode, uiAbsPartIdx, uiDepth );
    1444 }
    1445 #endif
    1446 
    1447 Void TDecCavlc::parseIntraDirChroma( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
    1448 {
    1449   UInt uiSymbol;
    1450 #if CHROMA_CODEWORD
    1451   UInt uiMode = pcCU->getLumaIntraDir(uiAbsPartIdx);
    1452 #if ADD_PLANAR_MODE
    1453   if ( (uiMode == 2 ) || (uiMode == PLANAR_IDX) )
    1454   {
    1455     uiMode = 4;
    1456   }
    1457 #endif
    1458 #if LM_CHROMA
    1459   Int  iMaxMode = pcCU->getSlice()->getSPS()->getUseLMChroma() ? 3 : 4;
    1460 
    1461   Int  iMax = uiMode < iMaxMode ? 3 : 4;
    1462 
    1463   xReadUnaryMaxSymbol( uiSymbol, iMax );
    1464 
    1465   //switch codeword
    1466   if (uiSymbol == 0)
    1467   {
    1468     uiSymbol = 4;
    1469   }
    1470   else if (uiSymbol == 1 && pcCU->getSlice()->getSPS()->getUseLMChroma())
    1471   {
    1472     uiSymbol = 3;
    1473   }
    1474   else
    1475   {
    1476 #if CHROMA_CODEWORD_SWITCH
    1477     uiSymbol = ChromaMapping[iMax-3][uiSymbol];
    1478 #endif
    1479 
    1480     if (pcCU->getSlice()->getSPS()->getUseLMChroma())
    1481        uiSymbol --;
    1482 
    1483     if (uiSymbol <= uiMode)
    1484        uiSymbol --;
    1485   }
    1486 
    1487 #else // -- LM_CHROMA
    1488 
    1489   Int  iMax = uiMode < 4 ? 3 : 4;
    1490   xReadUnaryMaxSymbol( uiSymbol, iMax );
    1491 
    1492   //switch codeword
    1493   if (uiSymbol == 0)
    1494   {
    1495     uiSymbol = 4;
    1496   }
    1497 #if CHROMA_CODEWORD_SWITCH
    1498   else
    1499   {
    1500     uiSymbol = ChromaMapping[iMax-3][uiSymbol];
    1501     if (uiSymbol <= uiMode)
    1502     {
    1503       uiSymbol --;
    1504     }
    1505   }
    1506 #else
    1507   else if (uiSymbol <= uiMode)
    1508   {
    1509     uiSymbol --;
    1510   }
    1511 #endif
    1512 #endif // --> LM_CHROMA
    1513 
    1514   //printf("uiMode %d, chroma %d, codeword %d, imax %d\n", uiMode, uiSymbol, uiRead, iMax);
    1515 #else
    1516   xReadFlag( uiSymbol );
    1517 
    1518   if ( uiSymbol )
    1519   {
    1520     xReadUnaryMaxSymbol( uiSymbol, 3 );
    1521     uiSymbol++;
    1522   }
    1523 #endif
    1524 
    1525 #if ADD_PLANAR_MODE
    1526   if (uiSymbol == 2)
    1527   {
    1528 #if CHROMA_CODEWORD
    1529     uiMode = pcCU->getLumaIntraDir(uiAbsPartIdx);
    1530     if (uiMode == 2)
    1531     {
    1532       uiSymbol = PLANAR_IDX;
    1533     }
    1534     else if (uiMode != PLANAR_IDX)
    1535 #endif
    1536     {
    1537       UInt planarFlag;
    1538       xReadFlag( planarFlag );
    1539       if ( planarFlag )
    1540       {
    1541         uiSymbol = PLANAR_IDX;
    1542       }
    1543     }
    1544   }
    1545 #endif
    1546   pcCU->setChromIntraDirSubParts( uiSymbol, uiAbsPartIdx, uiDepth );
    1547 
    1548   return ;
    1549 }
    1550 
    1551 Void TDecCavlc::parseInterDir( TComDataCU* pcCU, UInt& ruiInterDir, UInt uiAbsPartIdx, UInt uiDepth )
    1552 {
    1553   UInt uiSymbol;
    1554 
    1555 #if UNIFY_INTER_TABLE
    1556 #if DCM_COMB_LIST
    1557   UInt uiNumRefIdxOfLC = pcCU->getSlice()->getNumRefIdx(REF_PIC_LIST_C);
    1558 #endif
    1559   #define min(a, b) (((a) < (b)) ? (a) : (b))
    1560 #if DCM_COMB_LIST
    1561   UInt uiValNumRefIdxOfLC = min(4,pcCU->getSlice()->getNumRefIdx(REF_PIC_LIST_C));
    1562 #endif
    1563   UInt uiValNumRefIdxOfL0 = min(2,pcCU->getSlice()->getNumRefIdx(REF_PIC_LIST_0));
    1564   UInt uiValNumRefIdxOfL1 = min(2,pcCU->getSlice()->getNumRefIdx(REF_PIC_LIST_1));
    1565 
    1566   if ( pcCU->getSlice()->getRefIdxCombineCoding() )
    1567   {
    1568     UInt uiIndex,tmp;
    1569 #if CAVLC_COUNTER_ADAPT
    1570     Int x,cx;
    1571 #else
    1572     Int x,cx,y,cy;
    1573 #endif
    1574 
    1575     UInt *m_uiMITableD = m_uiMI1TableD;
    1576 
    1577     UInt uiMaxVal;
    1578 #if DCM_COMB_LIST
    1579     if (uiNumRefIdxOfLC > 0)
    1580     {
    1581       uiMaxVal = uiValNumRefIdxOfLC + uiValNumRefIdxOfL0*uiValNumRefIdxOfL1;
    1582     }
    1583     else
    1584 #endif
    1585     if (pcCU->getSlice()->getNoBackPredFlag())
    1586     {
    1587       uiMaxVal = uiValNumRefIdxOfL0 + uiValNumRefIdxOfL0*uiValNumRefIdxOfL1;
    1588     }
    1589     else
    1590     {
    1591       uiMaxVal = uiValNumRefIdxOfL0 + uiValNumRefIdxOfL1 + uiValNumRefIdxOfL0*uiValNumRefIdxOfL1;
    1592     }
    1593 
    1594     xReadUnaryMaxSymbol( tmp, uiMaxVal );
    1595 
    1596     x = m_uiMITableD[tmp];
    1597     uiIndex = x;
    1598 
    1599     /* Adapt table */
    1600 
    1601     cx = tmp;
    1602 #if CAVLC_COUNTER_ADAPT
    1603     adaptCodeword(cx, m_ucMI1TableCounter,  m_ucMI1TableCounterSum,  m_uiMITableD,  NULL, 4 );
    1604 #else
    1605     cy = Max(0,cx-1);
    1606     y = m_uiMITableD[cy];
    1607     m_uiMITableD[cy] = x;
    1608     m_uiMITableD[cx] = y;
    1609     m_uiMITableVlcIdx += cx == m_uiMITableVlcIdx ? 0 : (cx < m_uiMITableVlcIdx ? -1 : 1);
    1610 #endif
    1611 
    1612     if (uiIndex < uiMaxVal)
    1613     {
    1614 #if DCM_COMB_LIST
    1615       if (uiNumRefIdxOfLC > 0)
    1616       {
    1617         if (uiIndex < uiValNumRefIdxOfLC)
    1618         {
    1619           ruiInterDir = 1;
    1620           m_iRefFrame0[uiAbsPartIdx] = uiIndex;
    1621         }
    1622         else
    1623         {
    1624           UInt uiTmp = uiIndex-uiValNumRefIdxOfLC;
    1625           ruiInterDir = 3;
    1626 
    1627           m_iRefFrame0[uiAbsPartIdx] = uiTmp/uiValNumRefIdxOfL1; //uiValNumRefIdxOfL1 == 1 or 2, so division can be converted to shift op
    1628           m_iRefFrame1[uiAbsPartIdx] = uiTmp%uiValNumRefIdxOfL1;
    1629         }
    1630       }
    1631       else
    1632 #endif
    1633       if (pcCU->getSlice()->getNoBackPredFlag())
    1634       {
    1635         if (uiIndex < uiValNumRefIdxOfL0)
    1636         {
    1637           ruiInterDir = 1;
    1638           m_iRefFrame0[uiAbsPartIdx] = uiIndex;
    1639         }
    1640         else
    1641         {
    1642           UInt uiTmp = uiIndex-uiValNumRefIdxOfL0;
    1643           ruiInterDir = 3;
    1644 
    1645           m_iRefFrame0[uiAbsPartIdx] = uiTmp/uiValNumRefIdxOfL1; //uiValNumRefIdxOfL1 == 1 or 2, so division can be converted to shift op
    1646           m_iRefFrame1[uiAbsPartIdx] = uiTmp%uiValNumRefIdxOfL1;
    1647         }
    1648       }
    1649       else
    1650       {
    1651         if (uiIndex < uiValNumRefIdxOfL0)
    1652         {
    1653           ruiInterDir = 1;
    1654           m_iRefFrame0[uiAbsPartIdx] = uiIndex;
    1655         }
    1656         else if (uiIndex < uiValNumRefIdxOfL1)
    1657         {
    1658           ruiInterDir = 2;
    1659           m_iRefFrame1[uiAbsPartIdx] = uiIndex-uiValNumRefIdxOfL0;
    1660         }
    1661         else
    1662         {
    1663           UInt uiTmp = uiIndex-uiValNumRefIdxOfL0-uiValNumRefIdxOfL1;
    1664           ruiInterDir = 3;
    1665 
    1666           m_iRefFrame0[uiAbsPartIdx] = uiTmp/uiValNumRefIdxOfL1; //uiValNumRefIdxOfL1 == 1 or 2, so division can be converted to shift op
    1667           m_iRefFrame1[uiAbsPartIdx] = uiTmp%uiValNumRefIdxOfL1;
    1668         }
    1669       }
    1670 
    1671       return;
    1672     }
    1673   }
    1674 #else  //UNIFY_INTER_TABLE
    1675 #if MS_LCEC_LOOKUP_TABLE_EXCEPTION
    1676   if ( pcCU->getSlice()->getRefIdxCombineCoding() )
    1677 #else
    1678   if(pcCU->getSlice()->getNumRefIdx( REF_PIC_LIST_0 ) <= 2 && pcCU->getSlice()->getNumRefIdx( REF_PIC_LIST_1 ) <= 2)
    1679 #endif
    1680   {
    1681     UInt uiIndex,uiInterDir,tmp;
    1682 
    1683 #if CAVLC_COUNTER_ADAPT
    1684     Int x,cx;
    1685 #else
    1686     Int x,cx,y,cy;
    1687 #endif
    1688 
    1689 #if MS_LCEC_LOOKUP_TABLE_MAX_VALUE
    1690     UInt uiMaxVal = 7;
    1691 #if MS_LCEC_LOOKUP_TABLE_EXCEPTION
    1692     uiMaxVal = 8;
    1693 #endif
    1694     if ( pcCU->getSlice()->getNumRefIdx( REF_PIC_LIST_0 ) <= 1 && pcCU->getSlice()->getNumRefIdx( REF_PIC_LIST_1 ) <= 1 )
    1695     {
    1696       if ( pcCU->getSlice()->getNoBackPredFlag() || ( pcCU->getSlice()->getNumRefIdx(REF_PIC_LIST_C) > 0 && pcCU->getSlice()->getNumRefIdx(REF_PIC_LIST_C) <= 1 ) )
    1697       {
    1698         uiMaxVal = 1;
    1699       }
    1700       else
    1701       {
    1702         uiMaxVal = 2;
    1703       }
    1704     }
    1705     else if ( pcCU->getSlice()->getNumRefIdx( REF_PIC_LIST_0 ) <= 2 && pcCU->getSlice()->getNumRefIdx( REF_PIC_LIST_1 ) <= 2 )
    1706     {
    1707       if ( pcCU->getSlice()->getNoBackPredFlag() || ( pcCU->getSlice()->getNumRefIdx(REF_PIC_LIST_C) > 0 && pcCU->getSlice()->getNumRefIdx(REF_PIC_LIST_C) <= 2 ) )
    1708       {
    1709         uiMaxVal = 5;
    1710       }
    1711       else
    1712       {
    1713         uiMaxVal = 7;
    1714       }
    1715     }
    1716     else if ( pcCU->getSlice()->getNumRefIdx(REF_PIC_LIST_C) <= 0 )
    1717     {
    1718       uiMaxVal = 4+1+MS_LCEC_UNI_EXCEPTION_THRES;
    1719     }
    1720 
    1721     xReadUnaryMaxSymbol( tmp, uiMaxVal );
    1722 #else
    1723     UInt vlcn = g_auiMITableVlcNum[m_uiMITableVlcIdx];
    1724     tmp = xReadVlc( vlcn );
    1725 #endif
    1726 
    1727     UInt *m_uiMITableD = m_uiMI1TableD;
    1728     x = m_uiMITableD[tmp];
    1729     uiIndex = x;
    1730 
    1731     /* Adapt table */
    1732 
    1733     cx = tmp;
    1734 
    1735 #if CAVLC_COUNTER_ADAPT
    1736     adaptCodeword(cx, m_ucMI1TableCounter,  m_ucMI1TableCounterSum,  m_uiMITableD,  NULL, 4 );
    1737 #else
    1738     cy = Max(0,cx-1);
    1739     y = m_uiMITableD[cy];
    1740     m_uiMITableD[cy] = x;
    1741     m_uiMITableD[cx] = y;
    1742     m_uiMITableVlcIdx += cx == m_uiMITableVlcIdx ? 0 : (cx < m_uiMITableVlcIdx ? -1 : 1);
    1743 #endif
    1744     {
    1745       uiInterDir = Min(2,uiIndex>>1);
    1746 #if MS_LCEC_LOOKUP_TABLE_EXCEPTION
    1747       if ( uiIndex >=4 )
    1748       {
    1749         uiInterDir = 2;
    1750       }
    1751       else
    1752       {
    1753         uiInterDir = 0;
    1754       }
    1755 #endif
    1756 #if DCM_COMB_LIST
    1757       if(uiInterDir!=2 && pcCU->getSlice()->getNumRefIdx(REF_PIC_LIST_C)>0)
    1758       {
    1759         uiInterDir = 0;
    1760         m_iRefFrame0[uiAbsPartIdx] = uiIndex;
    1761       }
    1762       else
    1763 #endif
    1764       if (uiInterDir==0)
    1765       {
    1766 #if MS_LCEC_LOOKUP_TABLE_EXCEPTION
    1767         m_iRefFrame0[uiAbsPartIdx] = uiIndex;
    1768 #else
    1769         m_iRefFrame0[uiAbsPartIdx] = uiIndex&1;
    1770 #endif
    1771       }
    1772       else if (uiInterDir==1)
    1773         m_iRefFrame1[uiAbsPartIdx] = uiIndex&1;
    1774       else
    1775       {
    1776         m_iRefFrame0[uiAbsPartIdx] = (uiIndex>>1)&1;
    1777         m_iRefFrame1[uiAbsPartIdx] = (uiIndex>>0)&1;
    1778       }
    1779     }
    1780     ruiInterDir = uiInterDir+1;
    1781 #if MS_LCEC_LOOKUP_TABLE_EXCEPTION
    1782     if ( x < 8 )
    1783 #endif
    1784     {
    1785       return;
    1786     }
    1787   }
    1788 #endif //UNIFY_INTER_TABLE
    1789 
    1790 #if MS_LCEC_LOOKUP_TABLE_EXCEPTION
    1791   m_iRefFrame0[uiAbsPartIdx] = 1000;
    1792   m_iRefFrame1[uiAbsPartIdx] = 1000;
    1793 #endif
    1794 
    1795   xReadFlag( uiSymbol );
    1796 
    1797   if ( uiSymbol )
    1798   {
    1799     uiSymbol = 2;
    1800   }
    1801 #if DCM_COMB_LIST
    1802   else if(pcCU->getSlice()->getNumRefIdx(REF_PIC_LIST_C) > 0)
    1803   {
    1804     uiSymbol = 0;
    1805   }
    1806 #endif
    1807   else if ( pcCU->getSlice()->getNoBackPredFlag() )
    1808   {
    1809     uiSymbol = 0;
    1810   }
    1811   else
    1812   {
    1813     xReadFlag( uiSymbol );
    1814   }
    1815   uiSymbol++;
    1816   ruiInterDir = uiSymbol;
    1817   return;
    1818 }
    1819 
    1820 Void TDecCavlc::parseRefFrmIdx( TComDataCU* pcCU, Int& riRefFrmIdx, UInt uiAbsPartIdx, UInt uiDepth, RefPicList eRefList )
    1821 {
    1822   UInt uiSymbol;
    1823 
    1824   if (pcCU->getSlice()->getNumRefIdx( REF_PIC_LIST_0 ) <= 2 && pcCU->getSlice()->getNumRefIdx( REF_PIC_LIST_1 ) <= 2 && pcCU->getSlice()->isInterB())
    1825   {
    1826 #if DCM_COMB_LIST
    1827     if(pcCU->getSlice()->getNumRefIdx(REF_PIC_LIST_C ) > 0 && eRefList==REF_PIC_LIST_C)
    1828     {
    1829       riRefFrmIdx = m_iRefFrame0[uiAbsPartIdx];
    1830     }
    1831     else
    1832 #endif
    1833     if (eRefList==REF_PIC_LIST_0)
    1834     {
    1835       riRefFrmIdx = m_iRefFrame0[uiAbsPartIdx];
    1836     }
    1837     if (eRefList==REF_PIC_LIST_1)
    1838     {
    1839       riRefFrmIdx = m_iRefFrame1[uiAbsPartIdx];
    1840     }
    1841     return;
    1842   }
    1843 
    1844 #if MS_LCEC_LOOKUP_TABLE_EXCEPTION
    1845   if ( ( m_iRefFrame0[uiAbsPartIdx] != 1000 || m_iRefFrame1[uiAbsPartIdx] != 1000 ) &&
    1846       pcCU->getSlice()->getRefIdxCombineCoding() )
    1847   {
    1848     if(pcCU->getSlice()->getNumRefIdx(REF_PIC_LIST_C ) > 0 && eRefList==REF_PIC_LIST_C )
    1849     {
    1850       riRefFrmIdx = m_iRefFrame0[uiAbsPartIdx];
    1851     }
    1852     else if (eRefList==REF_PIC_LIST_0)
    1853     {
    1854       riRefFrmIdx = m_iRefFrame0[uiAbsPartIdx];
    1855     }
    1856     else if (eRefList==REF_PIC_LIST_1)
    1857     {
    1858       riRefFrmIdx = m_iRefFrame1[uiAbsPartIdx];
    1859     }
    1860     return;
    1861   }
    1862 
    1863   UInt uiRefFrmIdxMinus = 0;
    1864   if ( pcCU->getSlice()->getRefIdxCombineCoding() )
    1865   {
    1866     if ( pcCU->getInterDir( uiAbsPartIdx ) != 3 )
    1867     {
    1868       if ( pcCU->getSlice()->getNumRefIdx(REF_PIC_LIST_C) > 0 )
    1869       {
    1870         uiRefFrmIdxMinus = 4;
    1871       }
    1872       else
    1873       {
    1874         uiRefFrmIdxMinus = MS_LCEC_UNI_EXCEPTION_THRES+1;
    1875       }
    1876     }
    1877     else if ( eRefList == REF_PIC_LIST_1 && pcCU->getCUMvField( REF_PIC_LIST_0 )->getRefIdx( uiAbsPartIdx ) < 2 )
    1878     {
    1879       uiRefFrmIdxMinus = 2;
    1880     }
    1881   }
    1882   if ( pcCU->getSlice()->getNumRefIdx( eRefList ) - uiRefFrmIdxMinus <= 1 )
    1883   {
    1884     uiSymbol = 0;
    1885     riRefFrmIdx = uiSymbol;
    1886     riRefFrmIdx += uiRefFrmIdxMinus;
    1887     return;
    1888   }
    1889 #endif
    1890 
    1891   xReadFlag ( uiSymbol );
    1892   if ( uiSymbol )
    1893   {
    1894 #if MS_LCEC_LOOKUP_TABLE_EXCEPTION
    1895     xReadUnaryMaxSymbol( uiSymbol, pcCU->getSlice()->getNumRefIdx( eRefList )-2 - uiRefFrmIdxMinus );
    1896 #else
    1897     xReadUnaryMaxSymbol( uiSymbol, pcCU->getSlice()->getNumRefIdx( eRefList )-2 );
    1898 #endif
    1899 
    1900     uiSymbol++;
    1901   }
    1902   riRefFrmIdx = uiSymbol;
    1903 #if MS_LCEC_LOOKUP_TABLE_EXCEPTION
    1904   riRefFrmIdx += uiRefFrmIdxMinus;
    1905 #endif
    1906 
    1907   return;
    1908 }
    1909 
    1910 Void TDecCavlc::parseMvd( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiPartIdx, UInt uiDepth, RefPicList eRefList )
    1911 {
    1912   Int iHor, iVer;
    1913   UInt uiAbsPartIdxL, uiAbsPartIdxA;
    1914   Int iHorPred, iVerPred;
    1915 
    1916   TComDataCU* pcCUL   = pcCU->getPULeft ( uiAbsPartIdxL, pcCU->getZorderIdxInCU() + uiAbsPartIdx );
    1917   TComDataCU* pcCUA   = pcCU->getPUAbove( uiAbsPartIdxA, pcCU->getZorderIdxInCU() + uiAbsPartIdx );
    1918 
    1919   TComCUMvField* pcCUMvFieldL = ( pcCUL == NULL || pcCUL->isIntra( uiAbsPartIdxL ) ) ? NULL : pcCUL->getCUMvField( eRefList );
    1920   TComCUMvField* pcCUMvFieldA = ( pcCUA == NULL || pcCUA->isIntra( uiAbsPartIdxA ) ) ? NULL : pcCUA->getCUMvField( eRefList );
    1921 
    1922   iHorPred = ( (pcCUMvFieldL == NULL) ? 0 : pcCUMvFieldL->getMvd( uiAbsPartIdxL ).getAbsHor() ) +
    1923   ( (pcCUMvFieldA == NULL) ? 0 : pcCUMvFieldA->getMvd( uiAbsPartIdxA ).getAbsHor() );
    1924   iVerPred = ( (pcCUMvFieldL == NULL) ? 0 : pcCUMvFieldL->getMvd( uiAbsPartIdxL ).getAbsVer() ) +
    1925   ( (pcCUMvFieldA == NULL) ? 0 : pcCUMvFieldA->getMvd( uiAbsPartIdxA ).getAbsVer() );
    1926 
    1927   TComMv cTmpMv( 0, 0 );
    1928   pcCU->getCUMvField( eRefList )->setAllMv( cTmpMv, pcCU->getPartitionSize( uiAbsPartIdx ), uiAbsPartIdx, uiPartIdx, uiDepth );
    1929 
    1930   xReadSvlc( iHor );
    1931   xReadSvlc( iVer );
    1932 
    1933   // set mvd
    1934   TComMv cMv( iHor, iVer );
    1935   pcCU->getCUMvField( eRefList )->setAllMvd( cMv, pcCU->getPartitionSize( uiAbsPartIdx ), uiAbsPartIdx, uiPartIdx, uiDepth );
    1936 
    1937   return;
    1938 }
    1939 
    1940 Void TDecCavlc::parseDeltaQP( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
    1941 {
    1942   UInt uiDQp;
    1943   Int  iDQp;
    1944 
    1945   xReadFlag( uiDQp );
    1946 
    1947   if ( uiDQp == 0 )
    1948   {
    1949     uiDQp = pcCU->getSlice()->getSliceQp();
    1950   }
    1951   else
    1952   {
    1953     xReadSvlc( iDQp );
    1954     uiDQp = pcCU->getSlice()->getSliceQp() + iDQp;
    1955   }
    1956 
    1957   pcCU->setQPSubParts( uiDQp, uiAbsPartIdx, uiDepth );
    1958 }
    1959 
    1960 #if CAVLC_RQT_CBP
    1961 /** Function for parsing cbf and split
     2570  assert(0);
     2571}
     2572
     2573/** Parse I_PCM information.
    19622574 * \param pcCU pointer to CU
    19632575 * \param uiAbsPartIdx CU index
    1964  * \param uiTrDepth Transform depth
    1965  * \param uiDepth CU Depth
    1966  * \param uiSubdiv split flag
    1967  * \returns
    1968  * This function performs parsing for cbf and split flag
     2576 * \param uiDepth CU depth
     2577 * \returns Void
     2578 *
     2579 * If I_PCM flag indicates that the CU is I_PCM, parse its PCM alignment bits and codes. 
    19692580 */
    1970 Void TDecCavlc::parseCbfTrdiv( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiTrDepth, UInt uiDepth, UInt& uiSubdiv )
    1971 {
    1972   UInt uiCbf,tmp;
    1973   UInt uiCBP,uiCbfY,uiCbfU,uiCbfV;
    1974   UInt n,cx;
    1975   UInt uiLog2TrSize = g_aucConvertToBit[ pcCU->getSlice()->getSPS()->getMaxCUWidth() >> uiDepth ] + 2;
    1976   UInt uiQPartNumParent  = pcCU->getPic()->getNumPartInCU() >> ((uiDepth-1) << 1);
    1977   UInt uiQPartNumCurr    = pcCU->getPic()->getNumPartInCU() >> ((uiDepth) << 1);
    1978 
    1979   UInt uiFlagPattern = xGetFlagPattern( pcCU, uiAbsPartIdx, uiDepth, uiSubdiv );
    1980 
    1981   n = pcCU->isIntra( uiAbsPartIdx ) ? 0 : 1;
    1982   uiCbfY = uiCbfU = uiCbfV = 0;
    1983 
    1984   if(uiFlagPattern < 8)
    1985   {
    1986     if( uiLog2TrSize > pcCU->getSlice()->getSPS()->getQuadtreeTULog2MinSize() )
    1987     {
    1988       if(uiFlagPattern & 0x04)
    1989       {
    1990         xReadFlag(uiCbfU);
    1991       }
    1992       if(uiFlagPattern & 0x02)
    1993       {
    1994         xReadFlag(uiCbfV);
    1995       }
    1996     }
    1997     else
    1998     {
    1999       uiCbfU = pcCU->getCbf(uiAbsPartIdx, TEXT_CHROMA_U, uiTrDepth - 1)?1:0;
    2000       uiCbfV = pcCU->getCbf(uiAbsPartIdx, TEXT_CHROMA_V, uiTrDepth - 1)?1:0;
    2001     }
    2002     if(uiFlagPattern & 0x01)
    2003     {
    2004       parseTransformSubdivFlag( uiSubdiv, 0);
    2005     }
    2006   }
    2007   else
    2008   {
    2009     if(uiFlagPattern == 8)
    2010     {
    2011       if (uiAbsPartIdx % uiQPartNumParent ==0)
    2012       {
    2013         parseBlockCbf(pcCU, uiAbsPartIdx, TEXT_LUMA, uiTrDepth,uiDepth, uiQPartNumCurr);
    2014       }
    2015       uiCbfY = ( pcCU->getCbf( uiAbsPartIdx, TEXT_LUMA ) >> uiTrDepth) & 0x1;
    2016       if( uiLog2TrSize <= pcCU->getSlice()->getSPS()->getQuadtreeTULog2MinSize() )
    2017       {
    2018         uiCbfU = pcCU->getCbf(uiAbsPartIdx, TEXT_CHROMA_U, uiTrDepth - 1)?1:0;
    2019         uiCbfV = pcCU->getCbf(uiAbsPartIdx, TEXT_CHROMA_V, uiTrDepth - 1)?1:0;
    2020       }
    2021     }
    2022     else if(uiFlagPattern == 9)
    2023     {
    2024       bool bNeedToDecode = true;
    2025       if ( n==1 && (uiAbsPartIdx%uiQPartNumParent) / uiQPartNumCurr == 3 )  // last one
    2026       {
    2027         UInt uiTempAbsPartIdx = uiAbsPartIdx/uiQPartNumParent*uiQPartNumParent;
    2028         if ( pcCU->getCbf( uiTempAbsPartIdx + uiQPartNumCurr*0, TEXT_LUMA, uiTrDepth ) ||
    2029           pcCU->getCbf( uiTempAbsPartIdx + uiQPartNumCurr*1, TEXT_LUMA, uiTrDepth ) ||
    2030           pcCU->getCbf( uiTempAbsPartIdx + uiQPartNumCurr*2, TEXT_LUMA, uiTrDepth ) )
    2031         {
    2032           bNeedToDecode = true;
    2033         }
    2034         else
    2035         {
    2036           bNeedToDecode = false;
    2037           xReadFlag( uiSubdiv );
    2038           uiCbfY = 1;
    2039         }
    2040       }
    2041       if ( bNeedToDecode )
    2042       {
    2043         UInt uiSymbol;
    2044         xReadUnaryMaxSymbol(cx, n?2:3);
    2045         uiSymbol = m_uiCBP_YS_TableD[n][cx];
    2046         uiCbfY = uiSymbol >> 1;
    2047         uiSubdiv = uiSymbol & 0x01;
    2048         adaptCodeword(cx, m_ucCBP_YS_TableCounter[n],  m_ucCBP_YS_TableCounterSum[n],  m_uiCBP_YS_TableD[n],  NULL, 3);
    2049       }
    2050     }
    2051     else if (uiFlagPattern == 14)
    2052     {
    2053       UInt  uiIdx = uiTrDepth? (2 + n) : n;
    2054       xReadUnaryMaxSymbol(cx, 7);
    2055       uiCBP = m_uiCBP_YUV_TableD[uiIdx][cx];
    2056       adaptCodeword(cx,  m_ucCBP_YUV_TableCounter[uiIdx],  m_ucCBP_YUV_TableCounterSum[uiIdx],  m_uiCBP_YUV_TableD[uiIdx],  NULL, 4);
    2057       uiCbfY = (uiCBP>>2)&1;
    2058       uiCbfU = (uiCBP>>1)&1;
    2059       uiCbfV = (uiCBP>>0)&1;
    2060     }
    2061     else if ( uiFlagPattern == 11 || uiFlagPattern == 13 || uiFlagPattern == 15)
    2062     {
    2063       UInt uiSymbol, i;
    2064       m_pcBitstream->pseudoRead(6, uiSymbol);
    2065       for (i=0;i<8;i++)
    2066       {
    2067         if( (uiSymbol>>(6 - g_auiCBP_YCS_TableLen[n][i])) == g_auiCBP_YCS_Table[n][i] && g_auiCBP_YCS_TableLen[n][i])
    2068         {
    2069           m_pcBitstream->read(g_auiCBP_YCS_TableLen[n][i],uiSymbol);
    2070           uiSymbol =i;
    2071           break;
    2072         }
    2073       }
    2074 
    2075       uiCBP = m_uiCBP_YCS_TableD[n][uiSymbol];
    2076       adaptCodeword(uiSymbol, m_ucCBP_YCS_TableCounter[n], m_ucCBP_YCS_TableCounterSum[n],  m_uiCBP_YCS_TableD[n],  NULL, 4);
    2077       uiCbfY = uiCBP >> 2;
    2078       UInt uiCbfUV = (uiCBP >> 1)& 0x01;
    2079       uiSubdiv = uiCBP & 0x01;
    2080 
    2081       uiCbfU = 0; uiCbfV = 0;
    2082       if (uiFlagPattern == 15)
    2083       {
    2084         if(uiCbfUV)
    2085         {
    2086           xReadUnaryMaxSymbol( uiSymbol , 2);
    2087           uiSymbol = n? (uiSymbol + 1): (3 - uiSymbol);
    2088           uiCbfU = uiSymbol >> 1;
    2089           uiCbfV = uiSymbol & 0x01;
    2090         }
    2091       }
    2092       else
    2093       {
    2094         uiCbfU = (uiFlagPattern & 0x04) ?  uiCbfUV: 0;
    2095         uiCbfV = (uiFlagPattern & 0x02) ?  uiCbfUV: 0;
    2096       }
    2097     }
    2098     else if (uiFlagPattern == 10 || uiFlagPattern == 12)
    2099     {
    2100       UInt uiSymbol;
    2101       xReadUnaryMaxSymbol(tmp, 3);
    2102       uiSymbol = g_auiCBP_YC_TableD[n][tmp];
    2103       uiCbfY = uiSymbol >> 1;
    2104 
    2105       uiCbfU = uiCbfV = 0;
    2106       if(uiSymbol & 0x01)
    2107       {
    2108         uiCbfU = (uiFlagPattern & 0x04)? 1 : 0;
    2109         uiCbfV = (uiFlagPattern & 0x02)? 1 : 0;
    2110       }
    2111     }
    2112   }
    2113 
    2114   uiCbf = pcCU->getCbf( uiAbsPartIdx, TEXT_LUMA );
    2115   pcCU->setCbfSubParts( uiCbf | ( uiCbfY << uiTrDepth ), TEXT_LUMA, uiAbsPartIdx, uiDepth );
    2116 
    2117   uiCbf = pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_U );
    2118   pcCU->setCbfSubParts( uiCbf | ( uiCbfU << uiTrDepth ), TEXT_CHROMA_U, uiAbsPartIdx, uiDepth );
    2119 
    2120   uiCbf = pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_V );
    2121   pcCU->setCbfSubParts( uiCbf | ( uiCbfV << uiTrDepth ), TEXT_CHROMA_V, uiAbsPartIdx, uiDepth );
    2122 
    2123   if(!pcCU->isIntra(uiAbsPartIdx) && uiCbfY == 0 && uiCbfU == 0 && uiCbfV == 0)
    2124   {
    2125     uiSubdiv = 0;
    2126   }
    2127 
    2128   return;
    2129 }
    2130 
    2131 /** Function for parsing cbf and split
    2132  * \param pcCU pointer to CU
    2133  * \param uiAbsPartIdx CU index
    2134  * \param uiDepth CU Depth
    2135  * \param uiSubdiv split flag
    2136  * \returns flag pattern
    2137  * This function gets flagpattern for cbf and split flag
    2138  */
    2139 UInt TDecCavlc::xGetFlagPattern( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, UInt& uiSubdiv )
    2140 {
    2141   const UInt uiLog2TrafoSize = g_aucConvertToBit[pcCU->getSlice()->getSPS()->getMaxCUWidth()]+2 - uiDepth;
    2142   UInt uiTrDepth =  uiDepth - pcCU->getDepth( uiAbsPartIdx );
    2143   UInt patternYUV, patternDiv;
    2144   UInt bY, bU, bV;
    2145 
    2146 
    2147   UInt uiFullDepth = pcCU->getDepth(uiAbsPartIdx) + uiTrDepth;
    2148   UInt uiLog2TrSize = g_aucConvertToBit[ pcCU->getSlice()->getSPS()->getMaxCUWidth() >> uiFullDepth ] + 2;
    2149   if(uiTrDepth == 0)
    2150   {
    2151     patternYUV = 7;
    2152   }
    2153   else if( uiLog2TrSize > pcCU->getSlice()->getSPS()->getQuadtreeTULog2MinSize() )
    2154   {
    2155     bY = pcCU->getCbf(uiAbsPartIdx, TEXT_LUMA, uiTrDepth - 1)?1:0;
    2156     bU = pcCU->getCbf(uiAbsPartIdx, TEXT_CHROMA_U, uiTrDepth - 1)?1:0;
    2157     bV = pcCU->getCbf(uiAbsPartIdx, TEXT_CHROMA_V, uiTrDepth - 1)?1:0;
    2158     patternYUV = (bY<<2) + (bU<<1) + bV;
    2159   }
    2160   else
    2161   {
    2162     bY = pcCU->getCbf(uiAbsPartIdx, TEXT_LUMA, uiTrDepth - 1)?1:0;
    2163     patternYUV = bY<<2;
    2164   }
    2165 
    2166 
    2167   if( pcCU->getPredictionMode(uiAbsPartIdx) == MODE_INTRA && pcCU->getPartitionSize(uiAbsPartIdx) == SIZE_NxN && uiDepth == pcCU->getDepth(uiAbsPartIdx) )
    2168   {
    2169     patternDiv = 0; uiSubdiv = 1;
    2170   }
    2171   else if( uiLog2TrafoSize > pcCU->getSlice()->getSPS()->getQuadtreeTULog2MaxSize() )
    2172   {
    2173     patternDiv = 0; uiSubdiv = 1;
    2174   }
    2175   else if( uiLog2TrafoSize == pcCU->getSlice()->getSPS()->getQuadtreeTULog2MinSize() )
    2176   {
    2177     patternDiv = 0; uiSubdiv = 0;
    2178   }
    2179   else if( uiLog2TrafoSize == pcCU->getQuadtreeTULog2MinSizeInCU(uiAbsPartIdx) )
    2180   {
    2181     patternDiv = 0; uiSubdiv = 0;
    2182   }
    2183   else
    2184   {
    2185     patternDiv = 1;
    2186   }
    2187 
    2188   return ((patternYUV<<1)+patternDiv);
    2189 }
    2190 #endif
    2191 Void TDecCavlc::parseCbf( TComDataCU* pcCU, UInt uiAbsPartIdx, TextType eType, UInt uiTrDepth, UInt uiDepth )
    2192 {
    2193   if (eType == TEXT_ALL)
    2194   {
    2195     UInt uiCbf,tmp;
    2196     UInt uiCBP,uiCbfY,uiCbfU,uiCbfV;
    2197 
    2198 #if CAVLC_COUNTER_ADAPT
    2199     Int n, cx;
    2200 #else
    2201     Int n,x,cx,y,cy;
    2202 #endif
    2203 
    2204     /* Start adaptation */
    2205     n = pcCU->isIntra( uiAbsPartIdx ) ? 0 : 1;
    2206 #if CAVLC_RQT_CBP
    2207     UInt vlcn = 0;
    2208 #else
    2209     UInt vlcn = g_auiCbpVlcNum[n][m_uiCbpVlcIdx[n]];
    2210 #endif
    2211     tmp = xReadVlc( vlcn );
    2212 #if CAVLC_RQT_CBP
    2213     uiCBP = m_uiCBP_YUV_TableD[n][tmp];
    2214 #else
    2215     uiCBP = m_uiCBPTableD[n][tmp];
    2216 #endif
    2217 
    2218     /* Adapt LP table */
    2219     cx = tmp;
    2220 
    2221 #if CAVLC_COUNTER_ADAPT
    2222 #if CAVLC_RQT_CBP
    2223     adaptCodeword(cx, m_ucCBP_YUV_TableCounter[n],  m_ucCBP_YUV_TableCounterSum[n],  m_uiCBP_YUV_TableD[n],  NULL, 4);
    2224 #else
    2225     adaptCodeword(cx, m_ucCBFTableCounter[n],  m_ucCBFTableCounterSum[n],  m_uiCBPTableD[n],  NULL, 4);
    2226 #endif
    2227 #else
    2228     cy = Max(0,cx-1);
    2229     x = uiCBP;
    2230     y = m_uiCBPTableD[n][cy];
    2231     m_uiCBPTableD[n][cy] = x;
    2232     m_uiCBPTableD[n][cx] = y;
    2233     m_uiCbpVlcIdx[n] += cx == m_uiCbpVlcIdx[n] ? 0 : (cx < m_uiCbpVlcIdx[n] ? -1 : 1);
    2234 #endif
    2235 
    2236     uiCbfY = (uiCBP>>0)&1;
    2237     uiCbfU = (uiCBP>>1)&1;
    2238     uiCbfV = (uiCBP>>2)&1;
    2239 
    2240     uiCbf = pcCU->getCbf( uiAbsPartIdx, TEXT_LUMA );
    2241     pcCU->setCbfSubParts( uiCbf | ( uiCbfY << uiTrDepth ), TEXT_LUMA, uiAbsPartIdx, uiDepth );
    2242 
    2243     uiCbf = pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_U );
    2244     pcCU->setCbfSubParts( uiCbf | ( uiCbfU << uiTrDepth ), TEXT_CHROMA_U, uiAbsPartIdx, uiDepth );
    2245 
    2246     uiCbf = pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_V );
    2247     pcCU->setCbfSubParts( uiCbf | ( uiCbfV << uiTrDepth ), TEXT_CHROMA_V, uiAbsPartIdx, uiDepth );
    2248   }
    2249 }
    2250 
    2251 Void TDecCavlc::parseBlockCbf( TComDataCU* pcCU, UInt uiAbsPartIdx, TextType eType, UInt uiTrDepth, UInt uiDepth, UInt uiQPartNum )
    2252 {
    2253   assert(uiTrDepth > 0);
    2254   UInt uiCbf4, uiCbf;
    2255 
    2256 #if CAVLC_COUNTER_ADAPT
    2257   Int cx;
    2258 #else
    2259   Int x,cx,y,cy;
    2260 #endif
    2261 
    2262   UInt tmp;
    2263 
    2264   UInt n = (pcCU->isIntra(uiAbsPartIdx) && eType == TEXT_LUMA)? 0:1;
    2265 #if CAVLC_RQT_CBP
    2266   UInt vlcn = (n==0)?g_auiCBP_4Y_VlcNum[m_uiCBP_4Y_VlcIdx]:11;
    2267 #else
    2268   UInt vlcn = (n==0)?g_auiBlkCbpVlcNum[m_uiBlkCbpVlcIdx]:11;
    2269 #endif
    2270   tmp = xReadVlc( vlcn );
    2271 #if CAVLC_RQT_CBP
    2272   uiCbf4 = m_uiCBP_4Y_TableD[n][tmp];
    2273 #else
    2274   uiCbf4 = m_uiBlkCBPTableD[n][tmp];
    2275 #endif
    2276 
    2277   cx = tmp;
    2278 
    2279 #if CAVLC_COUNTER_ADAPT
    2280 #if CAVLC_RQT_CBP
    2281   adaptCodeword(cx, m_ucCBP_4Y_TableCounter[n], m_ucCBP_4Y_TableCounterSum[n], m_uiCBP_4Y_TableD[n], NULL, 2);
    2282 #else
    2283   adaptCodeword(cx, m_ucBlkCBPTableCounter[n],  m_ucBlkCBPTableCounterSum[n],  m_uiBlkCBPTableD[n],  NULL, 2);
    2284 #endif
    2285 #else
    2286   cy = Max(0,cx-1);
    2287   x = uiCbf4;
    2288   y = m_uiBlkCBPTableD[n][cy];
    2289   m_uiBlkCBPTableD[n][cy] = x;
    2290   m_uiBlkCBPTableD[n][cx] = y;
    2291 #endif
    2292 
    2293 #if CAVLC_RQT_CBP
    2294   if(n==0)
    2295     m_uiCBP_4Y_VlcIdx += cx == m_uiCBP_4Y_VlcIdx ? 0 : (cx < m_uiCBP_4Y_VlcIdx ? -1 : 1);
    2296 #else
    2297   if(n==0)
    2298     m_uiBlkCbpVlcIdx += cx == m_uiBlkCbpVlcIdx ? 0 : (cx < m_uiBlkCbpVlcIdx ? -1 : 1);
    2299 #endif
    2300 
    2301   uiCbf4++;
    2302   uiCbf = pcCU->getCbf( uiAbsPartIdx, eType );
    2303   pcCU->setCbfSubParts( uiCbf | ( ((uiCbf4>>3)&0x01) << uiTrDepth ), eType, uiAbsPartIdx, uiDepth ); uiAbsPartIdx += uiQPartNum;
    2304   uiCbf = pcCU->getCbf( uiAbsPartIdx, eType );
    2305   pcCU->setCbfSubParts( uiCbf | ( ((uiCbf4>>2)&0x01) << uiTrDepth ), eType, uiAbsPartIdx, uiDepth ); uiAbsPartIdx += uiQPartNum;
    2306   uiCbf = pcCU->getCbf( uiAbsPartIdx, eType );
    2307   pcCU->setCbfSubParts( uiCbf | ( ((uiCbf4>>1)&0x01) << uiTrDepth ), eType, uiAbsPartIdx, uiDepth ); uiAbsPartIdx += uiQPartNum;
    2308   uiCbf = pcCU->getCbf( uiAbsPartIdx, eType );
    2309   pcCU->setCbfSubParts( uiCbf | ( (uiCbf4&0x01) << uiTrDepth ), eType, uiAbsPartIdx, uiDepth );
    2310 
    2311   return;
     2581Void TDecCavlc::parseIPCMInfo( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
     2582{
     2583#if BURST_IPCM
     2584  assert(0);
     2585#else
     2586  UInt uiSymbol;
     2587
     2588  xReadFlag( uiSymbol );
     2589
     2590  if ( uiSymbol )
     2591  {
     2592    Bool bIpcmFlag   = true;
     2593
     2594    xReadPCMAlignZero();
     2595
     2596    pcCU->setPartSizeSubParts  ( SIZE_2Nx2N, uiAbsPartIdx, uiDepth );
     2597    pcCU->setSizeSubParts      ( g_uiMaxCUWidth>>uiDepth, g_uiMaxCUHeight>>uiDepth, uiAbsPartIdx, uiDepth );
     2598    pcCU->setIPCMFlagSubParts  ( bIpcmFlag, uiAbsPartIdx, uiDepth );
     2599
     2600    UInt uiMinCoeffSize = pcCU->getPic()->getMinCUWidth()*pcCU->getPic()->getMinCUHeight();
     2601    UInt uiLumaOffset   = uiMinCoeffSize*uiAbsPartIdx;
     2602    UInt uiChromaOffset = uiLumaOffset>>2;
     2603
     2604    Pel* piPCMSample;
     2605    UInt uiWidth;
     2606    UInt uiHeight;
     2607    UInt uiSampleBits;
     2608    UInt uiX, uiY;
     2609
     2610    piPCMSample = pcCU->getPCMSampleY() + uiLumaOffset;
     2611    uiWidth = pcCU->getWidth(uiAbsPartIdx);
     2612    uiHeight = pcCU->getHeight(uiAbsPartIdx);
     2613    uiSampleBits = pcCU->getSlice()->getSPS()->getPCMBitDepthLuma();
     2614
     2615    for(uiY = 0; uiY < uiHeight; uiY++)
     2616    {
     2617      for(uiX = 0; uiX < uiWidth; uiX++)
     2618      {
     2619        UInt uiSample;
     2620        xReadCode(uiSampleBits, uiSample);
     2621
     2622        piPCMSample[uiX] = uiSample;
     2623      }
     2624      piPCMSample += uiWidth;
     2625    }
     2626
     2627    piPCMSample = pcCU->getPCMSampleCb() + uiChromaOffset;
     2628    uiWidth = pcCU->getWidth(uiAbsPartIdx)/2;
     2629    uiHeight = pcCU->getHeight(uiAbsPartIdx)/2;
     2630    uiSampleBits = pcCU->getSlice()->getSPS()->getPCMBitDepthChroma();
     2631
     2632    for(uiY = 0; uiY < uiHeight; uiY++)
     2633    {
     2634      for(uiX = 0; uiX < uiWidth; uiX++)
     2635      {
     2636        UInt uiSample;
     2637        xReadCode(uiSampleBits, uiSample);
     2638        piPCMSample[uiX] = uiSample;
     2639      }
     2640      piPCMSample += uiWidth;
     2641    }
     2642
     2643    piPCMSample = pcCU->getPCMSampleCr() + uiChromaOffset;
     2644    uiWidth = pcCU->getWidth(uiAbsPartIdx)/2;
     2645    uiHeight = pcCU->getHeight(uiAbsPartIdx)/2;
     2646    uiSampleBits = pcCU->getSlice()->getSPS()->getPCMBitDepthChroma();
     2647
     2648    for(uiY = 0; uiY < uiHeight; uiY++)
     2649    {
     2650      for(uiX = 0; uiX < uiWidth; uiX++)
     2651      {
     2652        UInt uiSample;
     2653        xReadCode(uiSampleBits, uiSample);
     2654        piPCMSample[uiX] = uiSample;
     2655      }
     2656      piPCMSample += uiWidth;
     2657    }
     2658  }
     2659#endif
     2660}
     2661
     2662Void TDecCavlc::parseIntraDirLumaAng  ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
     2663{
     2664  assert(0);
     2665}
     2666
     2667Void TDecCavlc::parseIntraDirChroma( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
     2668{
     2669  assert(0);
     2670}
     2671
     2672Void TDecCavlc::parseInterDir( TComDataCU* pcCU, UInt& ruiInterDir, UInt uiAbsPartIdx, UInt uiDepth )
     2673{
     2674  assert(0);
     2675}
     2676
     2677Void TDecCavlc::parseRefFrmIdx( TComDataCU* pcCU, Int& riRefFrmIdx, UInt uiAbsPartIdx, UInt uiDepth, RefPicList eRefList )
     2678{
     2679  assert(0);
     2680}
     2681
     2682Void TDecCavlc::parseMvd( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiPartIdx, UInt uiDepth, RefPicList eRefList )
     2683{
     2684  assert(0);
     2685}
     2686
     2687Void TDecCavlc::parseDeltaQP( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
     2688{
     2689#if H0736_AVC_STYLE_QP_RANGE
     2690  Int qp;
     2691#else
     2692  UInt uiQp;
     2693#endif
     2694  Int  iDQp;
     2695 
     2696  xReadSvlc( iDQp );
     2697
     2698#if H0736_AVC_STYLE_QP_RANGE
     2699  Int qpBdOffsetY = pcCU->getSlice()->getSPS()->getQpBDOffsetY();
     2700  qp = (((Int) pcCU->getRefQP( uiAbsPartIdx ) + iDQp + 52 + 2*qpBdOffsetY )%(52+ qpBdOffsetY)) -  qpBdOffsetY;
     2701#else
     2702  uiQp = pcCU->getRefQP( uiAbsPartIdx ) + iDQp;
     2703#endif
     2704
     2705  UInt uiAbsQpCUPartIdx = (uiAbsPartIdx>>(8-(pcCU->getSlice()->getPPS()->getMaxCuDQPDepth()<<1)))<<(8-(pcCU->getSlice()->getPPS()->getMaxCuDQPDepth()<<1)) ;
     2706  UInt uiQpCUDepth =   min(uiDepth,pcCU->getSlice()->getPPS()->getMaxCuDQPDepth()) ;
     2707
     2708#if H0736_AVC_STYLE_QP_RANGE
     2709  pcCU->setQPSubParts( qp, uiAbsQpCUPartIdx, uiQpCUDepth );
     2710#else
     2711  pcCU->setQPSubParts( uiQp, uiAbsQpCUPartIdx, uiQpCUDepth );
     2712#endif
    23122713}
    23132714
    23142715Void TDecCavlc::parseCoeffNxN( TComDataCU* pcCU, TCoeff* pcCoef, UInt uiAbsPartIdx, UInt uiWidth, UInt uiHeight, UInt uiDepth, TextType eTType )
    23152716{
    2316 
    2317   if ( uiWidth > pcCU->getSlice()->getSPS()->getMaxTrSize() )
    2318   {
    2319     uiWidth  = pcCU->getSlice()->getSPS()->getMaxTrSize();
    2320     uiHeight = pcCU->getSlice()->getSPS()->getMaxTrSize();
    2321   }
    2322   UInt uiSize   = uiWidth*uiHeight;
    2323 
    2324   // point to coefficient
    2325   TCoeff* piCoeff = pcCoef;
    2326 
    2327   // initialize scan
    2328   const UInt*  pucScan;
    2329 
    2330 #if CAVLC_COEF_LRG_BLK
    2331   UInt maxBlSize = (eTType==TEXT_LUMA)? 32:8;
    2332   UInt uiBlSize = Min(maxBlSize,uiWidth);
    2333   UInt uiConvBit = g_aucConvertToBit[ pcCU->isIntra( uiAbsPartIdx ) ? uiWidth : uiBlSize];
    2334   UInt uiNoCoeff = uiBlSize*uiBlSize;
    2335 #else
    2336   //UInt uiConvBit = g_aucConvertToBit[ Min(8,uiWidth) ];
    2337   UInt uiConvBit = g_aucConvertToBit[ pcCU->isIntra( uiAbsPartIdx ) ? uiWidth : Min(8,uiWidth)    ];
    2338 #endif
    2339   pucScan        = g_auiFrameScanXY  [ uiConvBit + 1 ];
    2340 
    2341 #if QC_MDCS
    2342   UInt uiBlkPos;
    2343 #if CAVLC_COEF_LRG_BLK
    2344   UInt uiLog2BlkSize = g_aucConvertToBit[ pcCU->isIntra( uiAbsPartIdx ) ? uiWidth : uiBlSize] + 2;
    2345 #else
    2346   UInt uiLog2BlkSize = g_aucConvertToBit[ pcCU->isIntra( uiAbsPartIdx ) ? uiWidth : Min(8,uiWidth)    ] + 2;
    2347 #endif
    2348   const UInt uiScanIdx = pcCU->getCoefScanIdx(uiAbsPartIdx, uiWidth, eTType==TEXT_LUMA, pcCU->isIntra(uiAbsPartIdx));
    2349 #endif //QC_MDCS
    2350 
    2351   UInt uiDecodeDCCoeff = 0;
    2352   Int dcCoeff = 0;
    2353   if (pcCU->isIntra(uiAbsPartIdx))
    2354   {
    2355     UInt uiAbsPartIdxL, uiAbsPartIdxA;
    2356     TComDataCU* pcCUL   = pcCU->getPULeft (uiAbsPartIdxL, pcCU->getZorderIdxInCU() + uiAbsPartIdx);
    2357     TComDataCU* pcCUA   = pcCU->getPUAbove(uiAbsPartIdxA, pcCU->getZorderIdxInCU() + uiAbsPartIdx);
    2358     if (pcCUL == NULL && pcCUA == NULL)
    2359     {
    2360       uiDecodeDCCoeff = 1;
    2361       dcCoeff = xReadVlc(eTType == TEXT_LUMA ? 3 : 1);
    2362       if (dcCoeff)
    2363       {
    2364         UInt sign;
    2365         xReadFlag(sign);
    2366         if (sign)
    2367         {
    2368           dcCoeff = -dcCoeff;
    2369         }
    2370       }
    2371     }
    2372   }
    2373 
    2374   UInt uiScanning;
    2375 
    2376 #if CAVLC_COEF_LRG_BLK
    2377   static TCoeff scoeff[1024];
    2378 #else
    2379   TCoeff scoeff[64];
    2380 #endif
    2381   Int iBlockType;
    2382   if( uiSize == 2*2 )
    2383   {
    2384     // hack: re-use 4x4 coding
    2385 #if QC_MOD_LCEC
    2386     if (eTType==TEXT_CHROMA_U || eTType==TEXT_CHROMA_V)
    2387       iBlockType = eTType-2;
    2388     else
    2389       iBlockType = 2 + ( pcCU->isIntra(uiAbsPartIdx) ? 0 : pcCU->getSlice()->getSliceType() );
    2390 #else
    2391     iBlockType = pcCU->isIntra(uiAbsPartIdx) ? 0 : pcCU->getSlice()->getSliceType();
    2392 #endif
    2393 
    2394 #if CAVLC_COEF_LRG_BLK
    2395     xParseCoeff( scoeff, iBlockType, 4 );
    2396 #else
    2397     xParseCoeff4x4( scoeff, iBlockType );
    2398 #endif
    2399 
    2400     for (uiScanning=0; uiScanning<4; uiScanning++)
    2401     {
    2402 #if QC_MDCS
    2403       uiBlkPos = g_auiSigLastScan[uiScanIdx][uiLog2BlkSize-1][uiScanning];
    2404       piCoeff[ uiBlkPos ] =  scoeff[15-uiScanning];
    2405 #else
    2406       piCoeff[ pucScan[ uiScanning ] ] = scoeff[15-uiScanning];
    2407 #endif //QC_MDCS
    2408     }
    2409   }
    2410   else if ( uiSize == 4*4 )
    2411   {
    2412 #if QC_MOD_LCEC
    2413     if (eTType==TEXT_CHROMA_U || eTType==TEXT_CHROMA_V)
    2414       iBlockType = eTType-2;
    2415     else
    2416       iBlockType = 2 + ( pcCU->isIntra(uiAbsPartIdx) ? 0 : pcCU->getSlice()->getSliceType() );
    2417 #else
    2418     iBlockType = pcCU->isIntra(uiAbsPartIdx) ? 0 : pcCU->getSlice()->getSliceType();
    2419 #endif
    2420 #if CAVLC_COEF_LRG_BLK
    2421     xParseCoeff( scoeff, iBlockType, 4 );
    2422 #else
    2423     xParseCoeff4x4( scoeff, iBlockType );
    2424 #endif
    2425 
    2426     for (uiScanning=0; uiScanning<16; uiScanning++)
    2427     {
    2428 #if QC_MDCS
    2429       uiBlkPos = g_auiSigLastScan[uiScanIdx][uiLog2BlkSize-1][uiScanning];
    2430       piCoeff[ uiBlkPos ] =  scoeff[15-uiScanning];
    2431 #else
    2432       piCoeff[ pucScan[ uiScanning ] ] = scoeff[15-uiScanning];
    2433 #endif //QC_MDCS
    2434     }
    2435   }
    2436   else if ( uiSize == 8*8 )
    2437   {
    2438     if (eTType==TEXT_CHROMA_U || eTType==TEXT_CHROMA_V) //8x8 specific
    2439       iBlockType = eTType-2;
    2440     else
    2441       iBlockType = 2 + ( pcCU->isIntra(uiAbsPartIdx) ? 0 : pcCU->getSlice()->getSliceType() );
    2442 #if CAVLC_COEF_LRG_BLK
    2443     xParseCoeff( scoeff, iBlockType, 8 );
    2444 #else
    2445     xParseCoeff8x8( scoeff, iBlockType );
    2446 #endif
    2447 
    2448     for (uiScanning=0; uiScanning<64; uiScanning++)
    2449     {
    2450 #if QC_MDCS
    2451       uiBlkPos = g_auiSigLastScan[uiScanIdx][uiLog2BlkSize-1][uiScanning];
    2452       piCoeff[ uiBlkPos ] =  scoeff[63-uiScanning];
    2453 #else
    2454       piCoeff[ pucScan[ uiScanning ] ] = scoeff[63-uiScanning];
    2455 #endif //QC_MDCS
    2456     }
    2457 
    2458   }
    2459   else
    2460   {
    2461     if (!pcCU->isIntra( uiAbsPartIdx ))
    2462     {
    2463       memset(piCoeff,0,sizeof(TCoeff)*uiSize);
    2464       if (eTType==TEXT_CHROMA_U || eTType==TEXT_CHROMA_V)
    2465         iBlockType = eTType-2;
    2466       else
    2467         iBlockType = 5 + ( pcCU->isIntra(uiAbsPartIdx) ? 0 : pcCU->getSlice()->getSliceType() );
    2468 #if CAVLC_COEF_LRG_BLK
    2469       xParseCoeff( scoeff, iBlockType, uiBlSize );
    2470 #else
    2471       xParseCoeff8x8( scoeff, iBlockType );
    2472 #endif
    2473 
    2474 #if CAVLC_COEF_LRG_BLK
    2475       for (uiScanning=0; uiScanning<uiNoCoeff; uiScanning++)
    2476       {
    2477 #if QC_MDCS
    2478         uiBlkPos = g_auiSigLastScan[uiScanIdx][uiLog2BlkSize-1][uiScanning];
    2479         uiBlkPos = (uiBlkPos/uiBlSize)* uiWidth + (uiBlkPos&(uiBlSize-1));
    2480         piCoeff[ uiBlkPos ] =  scoeff[uiNoCoeff-uiScanning-1];
    2481 #else
    2482         piCoeff[(pucScan[uiScanning]/uiBlSize)*uiWidth + (pucScan[uiScanning]&(uiBlSize-1))]=scoeff[uiNoCoeff-uiScanning-1];
    2483 #endif
    2484       }
    2485 #else
    2486       for (uiScanning=0; uiScanning<64; uiScanning++)
    2487       {
    2488 #if QC_MDCS
    2489         uiBlkPos = g_auiSigLastScan[uiScanIdx][uiLog2BlkSize-1][uiScanning];
    2490         uiBlkPos = (uiBlkPos/8)* uiWidth + uiBlkPos%8;
    2491         piCoeff[ uiBlkPos ] =  scoeff[63-uiScanning];
    2492 #else
    2493         piCoeff[(pucScan[uiScanning]/8)*uiWidth + (pucScan[uiScanning]%8)] = scoeff[63-uiScanning];
    2494 #endif //QC_MDCS
    2495       }
    2496 #endif
    2497       return;
    2498     }
    2499 
    2500     if(pcCU->isIntra( uiAbsPartIdx ))
    2501     {
    2502       memset(piCoeff,0,sizeof(TCoeff)*uiSize);
    2503 
    2504       if (eTType==TEXT_CHROMA_U || eTType==TEXT_CHROMA_V)
    2505         iBlockType = eTType-2;
    2506       else
    2507         iBlockType = 5 + ( pcCU->isIntra(uiAbsPartIdx) ? 0 : pcCU->getSlice()->getSliceType() );
    2508 
    2509 #if CAVLC_COEF_LRG_BLK
    2510       xParseCoeff( scoeff, iBlockType, uiBlSize );
    2511       for (uiScanning=0; uiScanning<uiNoCoeff; uiScanning++)
    2512       {
    2513 #if QC_MDCS
    2514         uiBlkPos = g_auiSigLastScan[uiScanIdx][uiLog2BlkSize-1][uiScanning];
    2515         piCoeff[ uiBlkPos ] =  scoeff[uiNoCoeff - uiScanning - 1];
    2516 #else
    2517         piCoeff[ pucScan[ uiScanning ] ] = scoeff[uiNoCoeff - uiScanning - 1];
    2518 #endif //QC_MDCS
    2519       }
    2520 #else
    2521       xParseCoeff8x8( scoeff, iBlockType );
    2522 
    2523       for (uiScanning=0; uiScanning<64; uiScanning++)
    2524       {
    2525 #if QC_MDCS
    2526         uiBlkPos = g_auiSigLastScan[uiScanIdx][uiLog2BlkSize-1][uiScanning];
    2527         piCoeff[ uiBlkPos ] =  scoeff[63-uiScanning];
    2528 #else
    2529         piCoeff[ pucScan[ uiScanning ] ] = scoeff[63-uiScanning];
    2530 #endif //QC_MDCS
    2531       }
    2532 #endif
    2533     }
    2534   }
    2535 
    2536   if (uiDecodeDCCoeff == 1)
    2537   {
    2538     piCoeff[0] = dcCoeff;
    2539   }
    2540 
    2541   return ;
     2717  assert(0);
    25422718}
    25432719
    25442720Void TDecCavlc::parseTransformSubdivFlag( UInt& ruiSubdivFlag, UInt uiLog2TransformBlockSize )
    25452721{
    2546   xReadFlag( ruiSubdivFlag );
     2722  assert(0);
    25472723}
    25482724
    25492725Void TDecCavlc::parseQtCbf( TComDataCU* pcCU, UInt uiAbsPartIdx, TextType eType, UInt uiTrDepth, UInt uiDepth )
    25502726{
    2551   UInt uiSymbol;
    2552   xReadFlag( uiSymbol );
    2553   pcCU->setCbfSubParts( uiSymbol << uiTrDepth, eType, uiAbsPartIdx, uiDepth );
     2727  assert(0);
    25542728}
    25552729
    25562730Void TDecCavlc::parseQtRootCbf( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, UInt& uiQtRootCbf )
    25572731{
    2558   UInt uiSymbol;
    2559   xReadFlag( uiSymbol );
    2560   uiQtRootCbf = uiSymbol;
    2561 }
    2562 
    2563 Void TDecCavlc::parseAlfFlag (UInt& ruiVal)
    2564 {
    2565   xReadFlag( ruiVal );
    2566 }
    2567 
    2568 #if TSB_ALF_HEADER
    2569 Void TDecCavlc::parseAlfFlagNum( UInt& ruiVal, UInt minValue, UInt depth )
    2570 {
    2571   UInt uiLength = 0;
    2572   UInt maxValue = (minValue << (depth*2));
    2573   UInt temp = maxValue - minValue;
    2574   for(UInt i=0; i<32; i++)
    2575   {
    2576     if(temp&0x1)
    2577     {
    2578       uiLength = i+1;
    2579     }
    2580     temp = (temp >> 1);
    2581   }
    2582   if(uiLength)
    2583   {
    2584     xReadCode( uiLength, ruiVal );
    2585   }
    2586   else
    2587   {
    2588     ruiVal = 0;
    2589   }
    2590   ruiVal += minValue;
    2591 }
    2592 
    2593 Void TDecCavlc::parseAlfCtrlFlag( UInt &ruiAlfCtrlFlag )
    2594 {
    2595   UInt uiSymbol;
    2596   xReadFlag( uiSymbol );
    2597   ruiAlfCtrlFlag = uiSymbol;
    2598 }
    2599 #endif
    2600 
    2601 Void TDecCavlc::parseAlfUvlc (UInt& ruiVal)
    2602 {
    2603   xReadUvlc( ruiVal );
    2604 }
    2605 
    2606 Void TDecCavlc::parseAlfSvlc (Int&  riVal)
    2607 {
    2608   xReadSvlc( riVal );
    2609 }
    2610 
    2611 
    2612 
    2613 #if MTK_SAO
    2614 Void TDecCavlc::parseAoFlag (UInt& ruiVal)
    2615 {
    2616   xReadFlag( ruiVal );
    2617 }
    2618 Void TDecCavlc::parseAoUvlc (UInt& ruiVal)
    2619 {
    2620   xReadUvlc( ruiVal );
    2621 }
    2622 
    2623 Void TDecCavlc::parseAoSvlc (Int&  riVal)
    2624 {
    2625   xReadSvlc( riVal );
    2626 }
    2627 #endif
     2732  assert(0);
     2733}
     2734
    26282735
    26292736Void TDecCavlc::parseMergeFlag ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, UInt uiPUIdx )
    26302737{
    2631 #if QC_LCEC_INTER_MODE
    2632   if (pcCU->getPartitionSize(uiAbsPartIdx) == SIZE_2Nx2N )
    2633     return;
    2634 #endif
    2635   UInt uiSymbol;
    2636   xReadFlag( uiSymbol );
    2637   pcCU->setMergeFlagSubParts( uiSymbol ? true : false, uiAbsPartIdx, uiPUIdx, uiDepth );
    2638 }
    2639 
    2640 
    2641 #if HHI_INTER_VIEW_MOTION_PRED || HHI_MPI
    2642 Void
    2643 TDecCavlc::parseMergeIndexMV( TComDataCU* pcCU, UInt& ruiMergeIndex, UInt uiAbsPartIdx, UInt uiDepth )
    2644 {
    2645   UInt  uiNumCand = 0;
    2646 #if HHI_MPI
    2647   const Bool bMVIAvailable = pcCU->getSlice()->getSPS()->getUseMVI() && pcCU->getSlice()->getSliceType() != I_SLICE;
    2648   const UInt uiMviMergePos = bMVIAvailable ? HHI_MPI_MERGE_POS : MRG_MAX_NUM_CANDS;
    2649   if( bMVIAvailable )
    2650     uiNumCand++;
    2651 #endif
    2652   for( UInt uiIdx = 0; uiIdx < MRG_MAX_NUM_CANDS; uiIdx++ )
    2653   {
    2654     if( pcCU->getNeighbourCandIdx( uiIdx, uiAbsPartIdx ) == uiIdx + 1 )
    2655     {
    2656       uiNumCand++;
    2657     }
    2658   }
    2659   AOF( uiNumCand > 1 );
    2660   UInt uiUnaryIdx = 0;
    2661   for( ; uiUnaryIdx < uiNumCand - 1; uiUnaryIdx++ )
    2662   {
    2663     UInt uiSymbol = 0;
    2664     xReadFlag( uiSymbol );
    2665     if( uiSymbol == 0 )
    2666     {
    2667       break;
    2668     }
    2669   }
    2670   ruiMergeIndex = uiUnaryIdx;
    2671   for( UInt uiIdx = 0; uiIdx <= ruiMergeIndex; uiIdx++ )
    2672   {
    2673 #if HHI_MPI
    2674     if( uiIdx > uiMviMergePos )
    2675     {
    2676       if( pcCU->getNeighbourCandIdx( uiIdx - 1, uiAbsPartIdx ) != uiIdx )
    2677       {
    2678         ruiMergeIndex++;
    2679       }
    2680     }
    2681     else if( uiIdx < uiMviMergePos )
    2682 #endif
    2683     if( pcCU->getNeighbourCandIdx( uiIdx, uiAbsPartIdx ) != uiIdx + 1 )
    2684     {
    2685       ruiMergeIndex++;
    2686     }
    2687   }
    2688 #if HHI_MPI
    2689   if( ruiMergeIndex > uiMviMergePos )
    2690   {
    2691     ruiMergeIndex--;
    2692   }
    2693   else if( ruiMergeIndex == uiMviMergePos )
    2694   {
    2695     pcCU->setTextureModeDepthSubParts( uiDepth, uiAbsPartIdx, uiDepth );
    2696   }
    2697 #endif
    2698 }
    2699 #endif
    2700 
    2701 
    2702 /** parse merge index
    2703  * \param pcCU
    2704  * \param ruiMergeIndex
    2705  * \param uiAbsPartIdx
    2706  * \param uiDepth
    2707  * \returns Void
    2708  */
     2738  assert(0);
     2739}
     2740
    27092741Void TDecCavlc::parseMergeIndex ( TComDataCU* pcCU, UInt& ruiMergeIndex, UInt uiAbsPartIdx, UInt uiDepth )
    27102742{
    2711 #if HHI_INTER_VIEW_MOTION_PRED || HHI_MPI
    2712   if(
    2713 #if HHI_INTER_VIEW_MOTION_PRED
    2714       ( pcCU->getSlice()->getSPS()->getViewId() > 0 && ( pcCU->getSlice()->getSPS()->getMultiviewMvPredMode() & PDM_USE_FOR_MERGE ) == PDM_USE_FOR_MERGE ) ||
    2715 #endif
    2716 #if HHI_MPI
    2717       ( pcCU->getSlice()->getSPS()->getUseMVI() && pcCU->getSlice()->getSliceType() != I_SLICE && pcCU->getPartitionSize( uiAbsPartIdx ) == SIZE_2Nx2N ) ||
    2718 #endif
    2719       0
    2720     )
    2721   {
    2722     parseMergeIndexMV( pcCU, ruiMergeIndex, uiAbsPartIdx, uiDepth );
    2723     return;
    2724   }
    2725 #endif
    2726 
    2727   Bool bLeftInvolved = false;
    2728   Bool bAboveInvolved = false;
    2729   Bool bCollocatedInvolved = false;
    2730   Bool bCornerInvolved = false;
    2731   UInt uiNumCand = 0;
    2732   for( UInt uiIter = 0; uiIter < MRG_MAX_NUM_CANDS; ++uiIter )
    2733   {
    2734     if( pcCU->getNeighbourCandIdx( uiIter, uiAbsPartIdx ) == uiIter + 1 )
    2735     {
    2736       uiNumCand++;
    2737       if( uiIter == 0 )
    2738       {
    2739         bLeftInvolved = true;
    2740       }
    2741       else if( uiIter == 1 )
    2742       {
    2743         bAboveInvolved = true;
    2744       }
    2745       else if( uiIter == 2 )
    2746       {
    2747         bCollocatedInvolved = true;
    2748       }
    2749       else if( uiIter == 3 )
    2750       {
    2751         bCornerInvolved = true;
    2752       }
    2753     }
    2754   }
    2755   assert( uiNumCand > 1 );
    2756   UInt uiUnaryIdx = 0;
    2757   for( ; uiUnaryIdx < uiNumCand - 1; ++uiUnaryIdx )
    2758   {
    2759     UInt uiSymbol = 0;
    2760     xReadFlag( uiSymbol );
    2761     if( uiSymbol == 0 )
    2762     {
    2763       break;
    2764     }
    2765   }
    2766   if( !bLeftInvolved )
    2767   {
    2768     ++uiUnaryIdx;
    2769   }
    2770   if( !bAboveInvolved && uiUnaryIdx >= 1 )
    2771   {
    2772     ++uiUnaryIdx;
    2773   }
    2774   if( !bCollocatedInvolved && uiUnaryIdx >= 2 )
    2775   {
    2776     ++uiUnaryIdx;
    2777   }
    2778   if( !bCornerInvolved && uiUnaryIdx >= 3 )
    2779   {
    2780     ++uiUnaryIdx;
    2781   }
    2782   ruiMergeIndex = uiUnaryIdx;
    2783 }
    2784 
    2785 
     2743  assert(0);
     2744}
     2745
     2746#if HHI_INTER_VIEW_RESIDUAL_PRED
    27862747Void
    27872748TDecCavlc::parseResPredFlag( TComDataCU* pcCU, Bool& rbResPredFlag, UInt uiAbsPartIdx, UInt uiDepth )
    27882749{
    2789   UInt uiSymbol = 0;
    2790   xReadFlag( uiSymbol );
    2791   rbResPredFlag = ( uiSymbol != 0 );
    2792 }
    2793 
     2750  assert(0);
     2751}
     2752#endif
    27942753
    27952754// ====================================================================================================================
     
    28092768  UInt uiLength;
    28102769  m_pcBitstream->read( 1, uiCode );
    2811 
     2770 
    28122771  if( 0 == uiCode )
    28132772  {
    28142773    uiLength = 0;
    2815 
     2774   
    28162775    while( ! ( uiCode & 1 ))
    28172776    {
     
    28192778      uiLength++;
    28202779    }
    2821 
     2780   
    28222781    m_pcBitstream->read( uiLength, uiVal );
    2823 
     2782   
    28242783    uiVal += (1 << uiLength)-1;
    28252784  }
    2826 
     2785 
    28272786  ruiVal = uiVal;
    28282787}
     
    28352794  {
    28362795    UInt uiLength = 0;
    2837 
     2796   
    28382797    while( ! ( uiBits & 1 ))
    28392798    {
     
    28412800      uiLength++;
    28422801    }
    2843 
     2802   
    28442803    m_pcBitstream->read( uiLength, uiBits );
    2845 
     2804   
    28462805    uiBits += (1 << uiLength);
    28472806    riVal = ( uiBits & 1) ? -(Int)(uiBits>>1) : (Int)(uiBits>>1);
     
    28582817}
    28592818
     2819/** Parse PCM alignment zero bits.
     2820 * \returns Void
     2821 */
     2822Void TDecCavlc::xReadPCMAlignZero( )
     2823{
     2824  UInt uiNumberOfBits = m_pcBitstream->getNumBitsUntilByteAligned();
     2825
     2826  if(uiNumberOfBits)
     2827  {
     2828    UInt uiBits;
     2829    UInt uiSymbol;
     2830
     2831    for(uiBits = 0; uiBits < uiNumberOfBits; uiBits++)
     2832    {
     2833      xReadFlag( uiSymbol );
     2834
     2835      if(uiSymbol)
     2836      {
     2837        printf("\nWarning! pcm_align_zero include a non-zero value.\n");
     2838      }
     2839    }
     2840  }
     2841}
     2842
    28602843Void TDecCavlc::xReadUnaryMaxSymbol( UInt& ruiSymbol, UInt uiMaxSymbol )
    28612844{
     
    28652848    return;
    28662849  }
    2867 
     2850 
    28682851  xReadFlag( ruiSymbol );
    2869 
     2852 
    28702853  if (ruiSymbol == 0 || uiMaxSymbol == 1)
    28712854  {
    28722855    return;
    28732856  }
    2874 
     2857 
    28752858  UInt uiSymbol = 0;
    28762859  UInt uiCont;
    2877 
     2860 
    28782861  do
    28792862  {
     
    28822865  }
    28832866  while( uiCont && (uiSymbol < uiMaxSymbol-1) );
    2884 
     2867 
    28852868  if( uiCont && (uiSymbol == uiMaxSymbol-1) )
    28862869  {
    28872870    uiSymbol++;
    28882871  }
    2889 
     2872 
    28902873  ruiSymbol = uiSymbol;
    28912874}
     
    29012884  }
    29022885  while( uiSymbol && (uiCount != 13));
    2903 
     2886 
    29042887  ruiSymbol = uiCount-1;
    2905 
     2888 
    29062889  if( uiSymbol )
    29072890  {
     
    29092892    ruiSymbol += uiSymbol+1;
    29102893  }
    2911 
     2894 
    29122895  return;
    29132896}
     
    29172900  UInt uiSymbol = 0;
    29182901  UInt uiBit = 1;
    2919 
    2920 
     2902 
     2903 
    29212904  while( uiBit )
    29222905  {
     
    29242907    uiSymbol += uiBit << uiCount++;
    29252908  }
    2926 
     2909 
    29272910  uiCount--;
    29282911  while( uiCount-- )
     
    29312914    uiSymbol += uiBit << uiCount;
    29322915  }
    2933 
     2916 
    29342917  ruiSymbol = uiSymbol;
    2935 
     2918 
    29362919  return;
    29372920}
     
    29442927}
    29452928
    2946 Int TDecCavlc::xReadVlc( Int n )
    2947 {
    2948 #if CAVLC_COEF_LRG_BLK
    2949   assert( n>=0 && n<=13 );
    2950 #else
    2951   assert( n>=0 && n<=11 );
    2952 #endif
    2953 
    2954   UInt zeroes=0, done=0, tmp;
    2955   UInt cw, bit;
    2956   UInt val = 0;
    2957   UInt first;
    2958   UInt lead = 0;
    2959 
    2960   if (n < 5)
    2961   {
    2962     while (!done && zeroes < 6)
    2963     {
    2964       xReadFlag( bit );
    2965       if (bit)
    2966       {
    2967         if (n)
    2968         {
    2969           xReadCode( n, cw );
    2970         }
    2971         else
    2972         {
    2973           cw = 0;
    2974         }
    2975         done = 1;
    2976       }
    2977       else
    2978       {
    2979         zeroes++;
    2980       }
    2981     }
    2982     if ( done )
    2983     {
    2984       val = (zeroes<<n)+cw;
    2985     }
    2986     else
    2987     {
    2988       lead = n;
    2989       while (!done)
    2990       {
    2991         xReadFlag( first );
    2992         if ( !first )
    2993         {
    2994           lead++;
    2995         }
    2996         else
    2997         {
    2998           if ( lead )
    2999           {
    3000             xReadCode( lead, tmp );
    3001           }
    3002           else
    3003           {
    3004             tmp = 0;
    3005           }
    3006           val = 6 * (1 << n) + (1 << lead) + tmp - (1 << n);
    3007           done = 1;
    3008         }
    3009       }
    3010     }
    3011   }
    3012   else if (n < 8)
    3013   {
    3014     while (!done)
    3015     {
    3016       xReadFlag( bit );
    3017       if ( bit )
    3018       {
    3019         xReadCode( n-4, cw );
    3020         done = 1;
    3021       }
    3022       else
    3023       {
    3024         zeroes++;
    3025       }
    3026     }
    3027     val = (zeroes<<(n-4))+cw;
    3028   }
    3029   else if (n == 8)
    3030   {
    3031     if ( xGetBit() )
    3032     {
    3033       val = 0;
    3034     }
    3035     else if ( xGetBit() )
    3036     {
    3037       val = 1;
    3038     }
    3039     else
    3040     {
    3041       val = 2;
    3042     }
    3043   }
    3044   else if (n == 9)
    3045   {
    3046     if ( xGetBit() )
    3047     {
    3048       if ( xGetBit() )
    3049       {
    3050         xReadCode(3, val);
    3051         val += 3;
    3052       }
    3053       else if ( xGetBit() )
    3054       {
    3055         val = xGetBit() + 1;
    3056       }
    3057       else
    3058       {
    3059         val = 0;
    3060       }
    3061     }
    3062     else
    3063     {
    3064       while (!done)
    3065       {
    3066         xReadFlag( bit );
    3067         if ( bit )
    3068         {
    3069           xReadCode(4, cw);
    3070           done = 1;
    3071         }
    3072         else
    3073         {
    3074           zeroes++;
    3075         }
    3076       }
    3077       val = (zeroes<<4)+cw+11;
    3078     }
    3079   }
    3080   else if (n == 10)
    3081   {
    3082     while (!done)
    3083     {
    3084       xReadFlag( first );
    3085       if ( !first )
    3086       {
    3087         lead++;
    3088       }
    3089       else
    3090       {
    3091         if ( !lead )
    3092         {
    3093           val = 0;
    3094         }
    3095         else
    3096         {
    3097           xReadCode(lead, val);
    3098           val += (1<<lead);
    3099           val--;
    3100         }
    3101         done = 1;
    3102       }
    3103     }
    3104   }
    3105   else if (n == 11)
    3106   {
    3107     UInt code;
    3108     xReadCode(3, val);
    3109     if(val)
    3110     {
    3111       xReadCode(1, code);
    3112       val = (val<<1)|code;
    3113       val--;
    3114     }
    3115   }
    3116 #if CAVLC_COEF_LRG_BLK
    3117   else if (n == 12)
    3118   {
    3119     while (!done)
    3120     {
    3121       m_pcBitstream->pseudoRead(32,val);
    3122       if (val)
    3123       {
    3124         tmp = 31;
    3125         while(!done)
    3126         {
    3127           if( val>>tmp )
    3128           {
    3129             xReadCode(32-tmp, val);
    3130             lead += 31-tmp;
    3131             xReadCode(6, val);
    3132             val += (lead<<6);
    3133             done = 1;
    3134           }
    3135           tmp--;
    3136         }
    3137       }
    3138       else
    3139       {
    3140         xReadCode(32, val);
    3141         lead += 32;
    3142       }
    3143     }
    3144   }
    3145   else if (n == 13)
    3146   {
    3147     while (!done)
    3148     {
    3149       m_pcBitstream->pseudoRead(32,val);
    3150       if (val)
    3151       {
    3152         tmp = 31;
    3153         while(!done)
    3154         {
    3155           if(val>>tmp)
    3156           {
    3157             xReadCode(32-tmp, cw);
    3158             zeroes += 31-tmp;
    3159             xReadCode(4, cw);
    3160             done = 1;
    3161           }
    3162           tmp--;
    3163         }
    3164       }
    3165       else
    3166       {
    3167         xReadCode(32, val);
    3168         zeroes += 32;
    3169       }
    3170     }
    3171     val = (zeroes<<4)+cw;
    3172   }
    3173 #endif
    3174 
    3175   return val;
    3176 }
    3177 
    3178 #if !CAVLC_COEF_LRG_BLK
    3179 Void TDecCavlc::xParseCoeff4x4( TCoeff* scoeff, Int n )
    3180 {
    3181   Int i;
    3182   UInt sign;
    3183   Int tmp;
    3184   Int vlc,cn,this_pos;
    3185   Int maxrun;
    3186   Int last_position;
    3187   Int atable[5] = {4,6,14,28,0xfffffff};
    3188   Int vlc_adaptive=0;
    3189   Int done;
    3190   LastCoeffStruct combo;
    3191 
    3192 #if QC_MOD_LCEC
    3193   Int nTab;
    3194   Int tr1;
    3195   nTab=max(0,n-2);
    3196 #endif
    3197 
    3198   for (i = 0; i < 16; i++)
    3199   {
    3200     scoeff[i] = 0;
    3201   }
    3202 
    3203   {
    3204     /* Get the last nonzero coeff */
    3205     Int x,y,cx,cy,vlcNum;
    3206     Int vlcTable[8] = {2,2,2};
    3207 
    3208     /* Decode according to current LP table */
    3209 #if QC_MOD_LCEC
    3210     vlcNum = vlcTable[nTab];
    3211     tmp = xReadVlc( vlcNum );
    3212     cn = m_uiLPTableD4[nTab][tmp];
    3213 #else
    3214     vlcNum = vlcTable[n];
    3215 
    3216     tmp = xReadVlc( vlcNum );
    3217     cn = m_uiLPTableD4[n][tmp];
    3218 #endif
    3219     combo.level = (cn>15);
    3220     combo.last_pos = cn&0x0f;
    3221 
    3222     /* Adapt LP table */
    3223     cx = tmp;
    3224     cy = Max( 0, cx-1 );
    3225     x = cn;
    3226 #if QC_MOD_LCEC
    3227     y = m_uiLPTableD4[nTab][cy];
    3228     m_uiLPTableD4[nTab][cy] = x;
    3229     m_uiLPTableD4[nTab][cx] = y;
    3230 #else
    3231     y = m_uiLPTableD4[n][cy];
    3232     m_uiLPTableD4[n][cy] = x;
    3233     m_uiLPTableD4[n][cx] = y;
    3234 #endif
    3235   }
    3236 
    3237   if ( combo.level == 1 )
    3238   {
    3239     tmp = xReadVlc( 0 );
    3240     sign = tmp&1;
    3241     tmp = (tmp>>1)+2;
    3242   }
    3243   else
    3244   {
    3245     tmp = 1;
    3246     xReadFlag( sign );
    3247   }
    3248 
    3249 #if QC_MOD_LCEC
    3250   if (tmp>1)
    3251   {
    3252     tr1=0;
    3253   }
    3254   else
    3255   {
    3256     tr1=1;
    3257   }
    3258 #endif
    3259 
    3260   if ( sign )
    3261   {
    3262     tmp = -tmp;
    3263   }
    3264 
    3265   last_position = combo.last_pos;
    3266   this_pos = 15 - last_position;
    3267   scoeff[this_pos] = tmp;
    3268   i = this_pos;
    3269   i++;
    3270 
    3271   done = 0;
    3272   {
    3273     while (!done && i < 16)
    3274     {
    3275       maxrun = 15-i;
    3276 #if QC_MOD_LCEC
    3277       if(n==2)
    3278         vlc = g_auiVlcTable8x8Intra[maxrun];
    3279       else
    3280         vlc = g_auiVlcTable8x8Inter[maxrun];
    3281 #else
    3282       if (maxrun > 27)
    3283       {
    3284         maxrun = 28;
    3285         vlc = 3;
    3286       }
    3287       else
    3288       {
    3289         vlc = g_auiVlcTable8x8[maxrun];
    3290       }
    3291 #endif
    3292 
    3293       /* Go into run mode */
    3294       cn = xReadVlc( vlc );
    3295 #if QC_MOD_LCEC
    3296       if(n==2)
    3297       {
    3298         xRunLevelIndInv(&combo, maxrun, g_auiLumaRunTr14x4[tr1][maxrun], cn);
    3299       }
    3300       else
    3301 #endif
    3302       {
    3303 #if RUNLEVEL_TABLE_CUT
    3304         xRunLevelIndInterInv(&combo, maxrun, cn);
    3305 #else
    3306         combo = g_acstructLumaRun8x8[maxrun][cn];
    3307 #endif
    3308       }
    3309       i += combo.last_pos;
    3310       /* No sign for last zeroes */
    3311       if (i < 16)
    3312       {
    3313         if (combo.level == 1)
    3314         {
    3315           tmp = xReadVlc( 0 );
    3316           sign = tmp&1;
    3317           tmp = (tmp>>1)+2;
    3318           done = 1;
    3319         }
    3320         else
    3321         {
    3322           tmp = 1;
    3323           xReadFlag( sign );
    3324         }
    3325         if ( sign )
    3326         {
    3327           tmp = -tmp;
    3328         }
    3329         scoeff[i] = tmp;
    3330       }
    3331       i++;
    3332 #if QC_MOD_LCEC
    3333       if (tr1>0 && tr1<MAX_TR1)
    3334       {
    3335         tr1++;
    3336       }
    3337 #endif
    3338     }
    3339   }
    3340   if (i < 16)
    3341   {
    3342     /* Get the rest in level mode */
    3343     while ( i < 16 )
    3344     {
    3345       tmp = xReadVlc( vlc_adaptive );
    3346       if ( tmp > atable[vlc_adaptive] )
    3347       {
    3348         vlc_adaptive++;
    3349       }
    3350       if ( tmp )
    3351       {
    3352         xReadFlag( sign );
    3353         if ( sign )
    3354         {
    3355           tmp = -tmp;
    3356         }
    3357       }
    3358       scoeff[i] = tmp;
    3359       i++;
    3360     }
    3361   }
    3362 
    3363   return;
    3364 }
    3365 #endif
    3366 
    3367 #if QC_MOD_LCEC
    3368 
    3369 Void TDecCavlc::xRunLevelIndInv(LastCoeffStruct *combo, Int maxrun, UInt lrg1Pos, UInt cn)
    3370 {
    3371   int lev, run;
    3372   if (lrg1Pos>0)
    3373   {
    3374     if(cn < min(lrg1Pos, maxrun+2))
    3375     {
    3376       lev = 0;
    3377       run = cn;
    3378     }
    3379     else if(cn < (maxrun<<1) + 4 - (Int)lrg1Pos)
    3380     {
    3381       if((cn+lrg1Pos)&1)
    3382       {
    3383         lev = 0;
    3384         run = (cn + lrg1Pos - 1) >> 1;
    3385       }
    3386       else
    3387       {
    3388         lev = 1;
    3389         run = (cn - lrg1Pos)>>1;
    3390       }
    3391     }
    3392     else
    3393     {
    3394       lev = 1;
    3395       run = cn - maxrun - 2;
    3396     }
    3397   }
    3398   else
    3399   {
    3400     if( cn & 1 )
    3401     {
    3402       lev = 0; run = (cn-1)>>1;
    3403     }
    3404     else
    3405     {
    3406       run = cn >> 1;
    3407       lev = (run <= maxrun)?1:0;
    3408     }
    3409   }
    3410   combo->level = lev;
    3411   combo->last_pos = run;
    3412 }
    3413 
    3414 #if RUNLEVEL_TABLE_CUT
    3415 /** Function for deriving run and level value in CAVLC run-level coding
    3416  * \param combo pointer to a struct of run and level
    3417  * \param maxrun maximum length of run for a given coefficient location
    3418  * \param cn codeword index
    3419  * \returns
    3420  * This function derives run and level value in CAVLC run-level coding based on codeword index and maximum run value.
     2929
     2930/** parse explicit wp tables
     2931 * \param TComSlice* pcSlice
     2932 * \returns Void
    34212933 */
    3422 Void TDecCavlc::xRunLevelIndInterInv(LastCoeffStruct *combo, Int maxrun, UInt cn)
    3423 {
    3424   if (maxrun<28)
    3425   {
    3426     if(cn > maxrun+1)
    3427     {
    3428       combo->level = 1;
    3429       combo->last_pos = g_acstructLumaRun8x8[maxrun][cn-maxrun-1];
    3430     }
    3431     else
    3432     {
    3433       combo->level = 0;
    3434       combo->last_pos = g_acstructLumaRun8x8[maxrun][cn];
    3435     }
    3436   }
    3437   else
    3438   {
    3439     if(cn<maxrun+2)
    3440     {
    3441       combo->level = 0;
    3442       combo->last_pos = cn;
    3443     }
    3444     else
    3445     {
    3446       combo->level = 1;
    3447       combo->last_pos = cn-maxrun-2;
    3448     }
    3449   }
    3450 }
    3451 #endif
    3452 #endif
    3453 
    3454 
    3455 #if !CAVLC_COEF_LRG_BLK
    3456 Void TDecCavlc::xParseCoeff8x8(TCoeff* scoeff, int n)
    3457 {
    3458   Int i;
    3459   UInt sign;
    3460   Int tmp;
    3461   LastCoeffStruct combo;
    3462   Int vlc,cn,this_pos;
    3463   Int maxrun;
    3464   Int last_position;
    3465   Int atable[5] = {4,6,14,28,0xfffffff};
    3466   Int vlc_adaptive=0;
    3467   Int done;
    3468 #if QC_MOD_LCEC
    3469   Int tr1;
    3470 #endif
    3471 
    3472   static const Int switch_thr[10] = {49,49,0,49,49,0,49,49,49,49};
    3473   Int sum_big_coef = 0;
    3474 
    3475   for (i = 0; i < 64; i++)
    3476   {
    3477     scoeff[i] = 0;
    3478   }
    3479 
    3480   /* Get the last nonzero coeff */
    3481   {
    3482     Int x,y,cx,cy,vlcNum;
    3483 
    3484     /* Decode according to current LP table */
    3485     // ADAPT_VLC_NUM
    3486     vlcNum = g_auiLastPosVlcNum[n][Min(16,m_uiLastPosVlcIndex[n])];
    3487     tmp = xReadVlc( vlcNum );
    3488     cn = m_uiLPTableD8[n][tmp];
    3489     combo.level = (cn>63);
    3490     combo.last_pos = cn&0x3f;
    3491 
    3492     /* Adapt LP table */
    3493     cx = tmp;
    3494     cy = Max(0,cx-1);
    3495     x = cn;
    3496     y = m_uiLPTableD8[n][cy];
    3497     m_uiLPTableD8[n][cy] = x;
    3498     m_uiLPTableD8[n][cx] = y;
    3499 
    3500     // ADAPT_VLC_NUM
    3501     m_uiLastPosVlcIndex[n] += cx == m_uiLastPosVlcIndex[n] ? 0 : (cx < m_uiLastPosVlcIndex[n] ? -1 : 1);
    3502   }
    3503 
    3504   if (combo.level == 1)
    3505   {
    3506     tmp = xReadVlc( 0 );
    3507     sign = tmp&1;
    3508     tmp = (tmp>>1)+2;
    3509   }
    3510   else
    3511   {
    3512     tmp = 1;
    3513     xReadFlag( sign );
    3514   }
    3515 
    3516 #if QC_MOD_LCEC
    3517   if (tmp>1)
    3518   {
    3519     tr1=0;
    3520   }
    3521   else
    3522   {
    3523     tr1=1;
    3524   }
    3525 #endif
    3526 
    3527   if ( sign )
    3528   {
    3529     tmp = -tmp;
    3530   }
    3531 
    3532   last_position = combo.last_pos;
    3533   this_pos = 63 - last_position;
    3534   scoeff[this_pos] = tmp;
    3535   i = this_pos;
    3536   i++;
    3537 
    3538   done = 0;
    3539   {
    3540     while (!done && i < 64)
    3541     {
    3542       maxrun = 63-i;
    3543 #if QC_MOD_LCEC
    3544       if (n == 2 || n == 5)
    3545         vlc = g_auiVlcTable8x8Intra[Min(maxrun,28)];
    3546       else
    3547         vlc = g_auiVlcTable8x8Inter[Min(maxrun,28)];
    3548 #else
    3549       if (maxrun > 27)
    3550       {
    3551         maxrun = 28;
    3552         vlc = 3;
    3553       }
    3554       else
    3555       {
    3556         vlc = g_auiVlcTable8x8[maxrun];
    3557       }
    3558 #endif
    3559 
    3560       /* Go into run mode */
    3561       cn = xReadVlc( vlc );
    3562 #if QC_MOD_LCEC
    3563       if (n == 2 || n == 5)
    3564         xRunLevelIndInv(&combo, maxrun, g_auiLumaRunTr18x8[tr1][min(maxrun,28)], cn);
    3565       else
    3566 #if RUNLEVEL_TABLE_CUT
    3567         xRunLevelIndInterInv(&combo, maxrun, cn);
    3568 #else
    3569         combo = g_acstructLumaRun8x8[Min(maxrun,28)][cn];
    3570 #endif
    3571 #else
    3572       combo = g_acstructLumaRun8x8[maxrun][cn];
    3573 #endif
    3574       i += combo.last_pos;
    3575       /* No sign for last zeroes */
    3576       if (i < 64)
    3577       {
    3578         if (combo.level == 1)
    3579         {
    3580           tmp = xReadVlc( 0 );
    3581           sign = tmp&1;
    3582           tmp = (tmp>>1)+2;
    3583 
    3584           sum_big_coef += tmp;
    3585           if (i > switch_thr[n] || sum_big_coef > 2)
    3586           {
    3587             done = 1;
    3588           }
    3589         }
    3590         else
    3591         {
    3592           tmp = 1;
    3593           xReadFlag( sign );
    3594         }
    3595         if ( sign )
    3596         {
    3597           tmp = -tmp;
    3598         }
    3599         scoeff[i] = tmp;
    3600       }
    3601       i++;
    3602 #if QC_MOD_LCEC
    3603       if (tr1==0 || combo.level != 0)
    3604       {
    3605         tr1=0;
    3606       }
    3607       else if( tr1 < MAX_TR1)
    3608       {
    3609         tr1++;
    3610       }
    3611 #endif
    3612     }
    3613   }
    3614   if (i < 64)
    3615   {
    3616     /* Get the rest in level mode */
    3617     while (i<64)
    3618     {
    3619       tmp = xReadVlc( vlc_adaptive );
    3620 
    3621       if (tmp>atable[vlc_adaptive])
    3622       {
    3623         vlc_adaptive++;
    3624       }
    3625       if (tmp)
    3626       {
    3627         xReadFlag( sign );
    3628         if ( sign )
    3629         {
    3630           tmp = -tmp;
    3631         }
    3632       }
    3633       scoeff[i] = tmp;
    3634       i++;
    3635     }
    3636   }
    3637   return;
    3638 }
    3639 #endif
    3640 
    3641 
    3642 #if CAVLC_COEF_LRG_BLK
    3643 /** Function for parsing a block of transform coeffcients in CAVLC.
    3644  * \param scoeff pointer to transform coefficient buffer
    3645  * \param n block type information, e.g. luma, chroma, intra, inter, etc.
    3646  * \param blSize block size
    3647  * \returns
    3648  * This function performs parsing for a block of transform coefficient in CAVLC.
    3649  */
    3650 Void TDecCavlc::xParseCoeff(TCoeff* scoeff, int n, Int blSize)
    3651 {
    3652   static const Int switch_thr[10] = {49,49,0,49,49,0,49,49,49,49};
    3653   Int i, noCoeff=blSize*blSize;;
    3654   UInt sign;
    3655   LastCoeffStruct combo;
    3656   Int cn, maxrun, tmprun;
    3657   Int atable[5] = {4,6,14,28,0xfffffff};
    3658   Int done, tr1, tmp;
    3659   Int sum_big_coef = 0;
    3660 
    3661   memset(scoeff,0,sizeof(TCoeff)*noCoeff);
    3662 
    3663   /* Get the last nonzero coeff */
    3664   if(blSize >=8 )
    3665   {
    3666     /* Decode according to current LP table */
    3667     // ADAPT_VLC_NUM
    3668     tmp = g_auiLastPosVlcNum[n][Min(16,m_uiLastPosVlcIndex[n])];
    3669     cn = xReadVlc( tmp );
    3670     xLastLevelIndInv(combo.level, combo.last_pos, blSize, cn);
    3671 
    3672     /* Adapt LP table */
    3673     cn = (blSize==8)?cn:(cn>>2);
    3674     // ADAPT_VLC_NUM
    3675     m_uiLastPosVlcIndex[n] += cn == m_uiLastPosVlcIndex[n] ? 0 : (cn < m_uiLastPosVlcIndex[n] ? -1 : 1);
    3676   }
    3677   else
    3678   {
    3679     /* Get the last nonzero coeff */
    3680     Int y,cy;
    3681     Int nTab = max(0,n-2);
    3682 
    3683     /* Decode according to current LP table */
    3684     tmp = xReadVlc( 2 );
    3685     cn = m_uiLPTableD4[nTab][tmp];
    3686     combo.level = (cn>15)?1:0;
    3687     combo.last_pos = cn&0x0f;
    3688 
    3689     /* Adapt LP table */
    3690     cy = Max( 0, tmp-1 );
    3691     y = m_uiLPTableD4[nTab][cy];
    3692     m_uiLPTableD4[nTab][cy] = cn;
    3693     m_uiLPTableD4[nTab][tmp] = y;
    3694   }
    3695 
    3696   if (combo.level == 1)
    3697   {
    3698     tmp = xReadVlc( 0 );
    3699     sign = tmp&1;
    3700     tmp = (tmp>>1)+2;
    3701     tr1=0;
    3702   }
    3703   else
    3704   {
    3705     tmp = 1;
    3706     xReadFlag( sign );
    3707     tr1=1;
    3708   }
    3709 
    3710   i = noCoeff - 1 - combo.last_pos;
    3711   scoeff[i++] = sign? -tmp:tmp;
    3712 
    3713   done = 0;
    3714   const UInt *vlcTable = (n == 2||n == 5)? ((blSize<=8)? g_auiVlcTable8x8Intra:g_auiVlcTable16x16Intra):
    3715     ((blSize<=8)? g_auiVlcTable8x8Inter:g_auiVlcTable16x16Inter);
    3716   const UInt **pLumaRunTr1 = (blSize==4)? g_pLumaRunTr14x4:g_pLumaRunTr18x8;
    3717   while (!done && i < noCoeff)
    3718   {
    3719     maxrun = noCoeff - 1 -i;
    3720     tmprun = min(maxrun,28);
    3721     tmp = vlcTable[tmprun];
    3722 
    3723     /* Go into run mode */
    3724     cn = xReadVlc( tmp );
    3725     if (n == 2 || n == 5)
    3726     {
    3727       xRunLevelIndInv(&combo, maxrun, pLumaRunTr1[tr1][tmprun], cn);
    3728     }
    3729     else
    3730     {
    3731       xRunLevelIndInterInv(&combo, maxrun, cn);
    3732     }
    3733 
    3734     i += combo.last_pos;
    3735     if (i < noCoeff)
    3736     {
    3737       if (combo.level == 1)
    3738       {
    3739         tmp = xReadVlc( 0 );
    3740         sign = tmp&1;
    3741         tmp = (tmp>>1)+2;
    3742 
    3743         sum_big_coef += tmp;
    3744         if (blSize==4 ||i > switch_thr[n] || sum_big_coef > 2)
    3745         {
    3746           done = 1;
    3747         }
    3748       }
    3749       else
    3750       {
    3751         tmp = 1;
    3752         xReadFlag( sign );
    3753       }
    3754       scoeff[i++] = sign? -tmp:tmp;
    3755     }
    3756 
    3757     if (tr1==0 || combo.level != 0)
    3758     {
    3759       tr1=0;
    3760     }
    3761     else if( tr1 < MAX_TR1)
    3762     {
    3763       tr1++;
    3764     }
    3765   }
    3766 
    3767   if (i < noCoeff)
    3768   {
    3769     /* Get the rest in level mode */
    3770     Int vlc_adaptive = 0;
    3771     while (i < noCoeff)
    3772     {
    3773       tmp = xReadVlc( vlc_adaptive );
    3774 
    3775       if (tmp)
    3776       {
    3777         xReadFlag( sign );
    3778         scoeff[i] = sign?-tmp:tmp;
    3779         if (tmp > atable[vlc_adaptive])
    3780         {
    3781           vlc_adaptive++;
    3782         }
    3783       }
    3784       i++;
    3785     }
    3786   }
    3787 
    3788   return;
    3789 }
    3790 
    3791 #endif
    3792 
    3793 #ifdef WEIGHT_PRED
    3794 Void TDecCavlc::parseWeightPredTable( TComSlice* pcSlice )
     2934Void TDecCavlc::xParsePredWeightTable( TComSlice* pcSlice )
    37952935{
    37962936  wpScalingParam  *wp;
     
    37982938  TComPPS*        pps         = pcSlice->getPPS();
    37992939  SliceType       eSliceType  = pcSlice->getSliceType();
    3800   Int             nbRef       = (eSliceType == B_SLICE ) ? (2) : (1);
     2940  Int             iNbRef       = (eSliceType == B_SLICE ) ? (2) : (1);
    38012941  UInt            uiLog2WeightDenomLuma, uiLog2WeightDenomChroma;
    38022942  UInt            uiMode      = 0;
    38032943
    3804   if ( (eSliceType==P_SLICE && pps->getUseWP()) || (eSliceType==B_SLICE && pps->getWPBiPredIdc()==1) )
    3805     uiMode = 1;
     2944  if ( (eSliceType==P_SLICE && pps->getUseWP()) || (eSliceType==B_SLICE && pps->getWPBiPredIdc()==1 && pcSlice->getRefPicListCombinationFlag()==0) )
     2945    uiMode = 1; // explicit
    38062946  else if ( eSliceType==B_SLICE && pps->getWPBiPredIdc()==2 )
    3807     uiMode = 2;
     2947    uiMode = 2; // implicit
     2948  else if (eSliceType==B_SLICE && pps->getWPBiPredIdc()==1 && pcSlice->getRefPicListCombinationFlag())
     2949    uiMode = 3; // combined explicit
    38082950
    38092951  if ( uiMode == 1 )  // explicit
    38102952  {
    3811     printf("\nTDecCavlc::parseWeightPredTable(poc=%d) explicit...\n", pcSlice->getPOC());
    3812 
    3813     // decode luma_log2_weight_denom :
    3814     xReadUvlc( uiLog2WeightDenomLuma );     // ue(v): luma_log2_weight_denom
    3815     if( bChroma ) {                         // color always present in HEVC ?
    3816       xReadUvlc( uiLog2WeightDenomChroma ); // ue(v): chroma_log2_weight_denom
    3817     }
    3818 
    3819     for ( Int numRef=0 ; numRef<nbRef ; numRef++ ) {
    3820       RefPicList  eRefPicList = ( numRef ? REF_PIC_LIST_1 : REF_PIC_LIST_0 );
    3821       for ( Int iRefIdx=0 ; iRefIdx<pcSlice->getNumRefIdx(eRefPicList) ; iRefIdx++ ) {
     2953    printf("\nTDecCavlc::xParsePredWeightTable(poc=%d) explicit...\n", pcSlice->getPOC());
     2954    Int iDeltaDenom;
     2955    // decode delta_luma_log2_weight_denom :
     2956    READ_UVLC( uiLog2WeightDenomLuma, "luma_log2_weight_denom" );     // ue(v): luma_log2_weight_denom
     2957    if( bChroma )
     2958    {
     2959      READ_SVLC( iDeltaDenom, "delta_chroma_log2_weight_denom" );     // se(v): delta_chroma_log2_weight_denom
     2960      assert((iDeltaDenom + (Int)uiLog2WeightDenomLuma)>=0);
     2961      uiLog2WeightDenomChroma = (UInt)(iDeltaDenom + uiLog2WeightDenomLuma);
     2962    }
     2963
     2964    for ( Int iNumRef=0 ; iNumRef<iNbRef ; iNumRef++ )
     2965    {
     2966      RefPicList  eRefPicList = ( iNumRef ? REF_PIC_LIST_1 : REF_PIC_LIST_0 );
     2967      for ( Int iRefIdx=0 ; iRefIdx<pcSlice->getNumRefIdx(eRefPicList) ; iRefIdx++ )
     2968      {
    38222969        pcSlice->getWpScaling(eRefPicList, iRefIdx, wp);
    38232970
     
    38272974
    38282975        UInt  uiCode;
    3829         xReadFlag( uiCode );           // u(1): luma_weight_l0_flag
     2976        READ_FLAG( uiCode, "luma_weight_lX_flag" );           // u(1): luma_weight_l0_flag
    38302977        wp[0].bPresentFlag = ( uiCode == 1 );
    3831         if ( wp[0].bPresentFlag ) {
    3832           xReadSvlc( wp[0].iWeight ); // se(v): luma_weight_l0[i]
    3833           xReadSvlc( wp[0].iOffset ); // se(v): luma_offset_l0[i]
    3834         }
    3835         else {
     2978        if ( wp[0].bPresentFlag )
     2979        {
     2980          Int iDeltaWeight;
     2981          READ_SVLC( iDeltaWeight, "delta_luma_weight_lX" );  // se(v): delta_luma_weight_l0[i]
     2982          wp[0].iWeight = (iDeltaWeight + (1<<wp[0].uiLog2WeightDenom));
     2983          READ_SVLC( wp[0].iOffset, "luma_offset_lX" );       // se(v): luma_offset_l0[i]
     2984        }
     2985        else
     2986        {
    38362987          wp[0].iWeight = (1 << wp[0].uiLog2WeightDenom);
    38372988          wp[0].iOffset = 0;
    38382989        }
    3839         if ( bChroma ) {
    3840           xReadFlag( uiCode );           // u(1): chroma_weight_l0_flag
     2990        if ( bChroma )
     2991        {
     2992          READ_FLAG( uiCode, "chroma_weight_lX_flag" );      // u(1): chroma_weight_l0_flag
    38412993          wp[1].bPresentFlag = ( uiCode == 1 );
    38422994          wp[2].bPresentFlag = ( uiCode == 1 );
    3843           if ( wp[1].bPresentFlag ) {
    3844             for ( Int j=1 ; j<3 ; j++ ) {
    3845               xReadSvlc( wp[j].iWeight ); // se(v): chroma_weight_l0[i][j]
    3846               xReadSvlc( wp[j].iOffset ); // se(v): chroma_offset_l0[i][j]
     2995          if ( wp[1].bPresentFlag )
     2996          {
     2997            for ( Int j=1 ; j<3 ; j++ )
     2998            {
     2999              Int iDeltaWeight;
     3000              READ_SVLC( iDeltaWeight, "delta_chroma_weight_lX" );  // se(v): chroma_weight_l0[i][j]
     3001              wp[j].iWeight = (iDeltaWeight + (1<<wp[1].uiLog2WeightDenom));
     3002
     3003              Int iDeltaChroma;
     3004              READ_SVLC( iDeltaChroma, "delta_chroma_offset_lX" );  // se(v): delta_chroma_offset_l0[i][j]
     3005              wp[j].iOffset = iDeltaChroma - ( ( (g_uiIBDI_MAX>>1)*wp[j].iWeight)>>(wp[j].uiLog2WeightDenom) ) + (g_uiIBDI_MAX>>1);
    38473006            }
    38483007          }
    3849           else {
    3850             for ( Int j=1 ; j<3 ; j++ ) {
     3008          else
     3009          {
     3010            for ( Int j=1 ; j<3 ; j++ )
     3011            {
    38513012              wp[j].iWeight = (1 << wp[j].uiLog2WeightDenom);
    38523013              wp[j].iOffset = 0;
     
    38563017      }
    38573018
    3858       // Just for displayWpScaling():
    3859       for ( Int iRefIdx=pcSlice->getNumRefIdx(eRefPicList) ; iRefIdx<MAX_NUM_REF ; iRefIdx++ ) {
     3019      for ( Int iRefIdx=pcSlice->getNumRefIdx(eRefPicList) ; iRefIdx<MAX_NUM_REF ; iRefIdx++ )
     3020      {
    38603021        pcSlice->getWpScaling(eRefPicList, iRefIdx, wp);
    38613022
     
    38643025        wp[2].bPresentFlag = false;
    38653026      }
    3866 
    3867     }
    3868 
     3027    }
    38693028  }
    38703029  else if ( uiMode == 2 )  // implicit
    38713030  {
    3872     printf("\nTDecCavlc::parseWeightPredTable(poc=%d) implicit...\n", pcSlice->getPOC());
     3031    printf("\nTDecCavlc::xParsePredWeightTable(poc=%d) implicit...\n", pcSlice->getPOC());
     3032  }
     3033  else if ( uiMode == 3 )  // combined explicit
     3034  {
     3035    printf("\nTDecCavlc::xParsePredWeightTable(poc=%d) combined explicit...\n", pcSlice->getPOC());
     3036    Int iDeltaDenom;
     3037    // decode delta_luma_log2_weight_denom :
     3038    READ_UVLC ( uiLog2WeightDenomLuma, "luma_log2_weight_denom" );     // ue(v): luma_log2_weight_denom
     3039    if( bChroma )
     3040    {
     3041      READ_SVLC( iDeltaDenom, "delta_chroma_log2_weight_denom" );      // ue(v): delta_chroma_log2_weight_denom
     3042      assert((iDeltaDenom + (Int)uiLog2WeightDenomLuma)>=0);
     3043      uiLog2WeightDenomChroma = (UInt)(iDeltaDenom + uiLog2WeightDenomLuma);
     3044    }
     3045
     3046    for ( Int iRefIdx=0 ; iRefIdx<pcSlice->getNumRefIdx(REF_PIC_LIST_C) ; iRefIdx++ )
     3047    {
     3048      pcSlice->getWpScalingLC(iRefIdx, wp);
     3049
     3050      wp[0].uiLog2WeightDenom = uiLog2WeightDenomLuma;
     3051      wp[1].uiLog2WeightDenom = uiLog2WeightDenomChroma;
     3052      wp[2].uiLog2WeightDenom = uiLog2WeightDenomChroma;
     3053
     3054      UInt  uiCode;
     3055      READ_FLAG( uiCode, "luma_weight_lc_flag" );                  // u(1): luma_weight_lc_flag
     3056      wp[0].bPresentFlag = ( uiCode == 1 );
     3057      if ( wp[0].bPresentFlag )
     3058      {
     3059        Int iDeltaWeight;
     3060        READ_SVLC( iDeltaWeight, "delta_luma_weight_lc" );          // se(v): delta_luma_weight_lc
     3061        wp[0].iWeight = (iDeltaWeight + (1<<wp[0].uiLog2WeightDenom));
     3062        READ_SVLC( wp[0].iOffset, "luma_offset_lc" );               // se(v): luma_offset_lc
     3063      }
     3064      else
     3065      {
     3066        wp[0].iWeight = (1 << wp[0].uiLog2WeightDenom);
     3067        wp[0].iOffset = 0;
     3068      }
     3069      if ( bChroma )
     3070      {
     3071        READ_FLAG( uiCode, "chroma_weight_lc_flag" );                // u(1): chroma_weight_lc_flag
     3072        wp[1].bPresentFlag = ( uiCode == 1 );
     3073        wp[2].bPresentFlag = ( uiCode == 1 );
     3074        if ( wp[1].bPresentFlag )
     3075        {
     3076          for ( Int j=1 ; j<3 ; j++ )
     3077          {
     3078            Int iDeltaWeight;
     3079            READ_SVLC( iDeltaWeight, "delta_chroma_weight_lc" );      // se(v): delta_chroma_weight_lc
     3080            wp[j].iWeight = (iDeltaWeight + (1<<wp[1].uiLog2WeightDenom));
     3081
     3082            Int iDeltaChroma;
     3083            READ_SVLC( iDeltaChroma, "delta_chroma_offset_lc" );      // se(v): delta_chroma_offset_lc
     3084            wp[j].iOffset = iDeltaChroma - ( ( (g_uiIBDI_MAX>>1)*wp[j].iWeight)>>(wp[j].uiLog2WeightDenom) ) + (g_uiIBDI_MAX>>1);
     3085          }
     3086        }
     3087        else
     3088        {
     3089          for ( Int j=1 ; j<3 ; j++ )
     3090          {
     3091            wp[j].iWeight = (1 << wp[j].uiLog2WeightDenom);
     3092            wp[j].iOffset = 0;
     3093          }
     3094        }
     3095      }
     3096    }
     3097
     3098    for ( Int iRefIdx=pcSlice->getNumRefIdx(REF_PIC_LIST_C) ; iRefIdx<2*MAX_NUM_REF ; iRefIdx++ )
     3099    {
     3100      pcSlice->getWpScalingLC(iRefIdx, wp);
     3101
     3102      wp[0].bPresentFlag = false;
     3103      wp[1].bPresentFlag = false;
     3104      wp[2].bPresentFlag = false;
     3105    }
    38733106  }
    38743107  else
     3108  {
     3109    printf("\n wrong weight pred table syntax \n ");
    38753110    assert(0);
    3876 }
    3877 #endif
     3111  }
     3112}
     3113
     3114/** decode quantization matrix
     3115 * \param scalingList quantization matrix information
     3116 */
     3117Void TDecCavlc::parseScalingList(TComScalingList* scalingList)
     3118{
     3119  UInt  code, sizeId, listId;
     3120  Bool scalingListPredModeFlag;
     3121  READ_FLAG( code, "scaling_list_present_flag" );
     3122  scalingList->setScalingListPresentFlag ( (code==1)?true:false );
     3123  if(scalingList->getScalingListPresentFlag() == false)
     3124  {
     3125      //for each size
     3126    for(sizeId = 0; sizeId < SCALING_LIST_SIZE_NUM; sizeId++)
     3127    {
     3128      for(listId = 0; listId <  g_scalingListNum[sizeId]; listId++)
     3129      {
     3130        READ_FLAG( code, "scaling_list_pred_mode_flag");
     3131        scalingListPredModeFlag = (code) ? true : false;
     3132        if(!scalingListPredModeFlag) //Copy Mode
     3133        {
     3134          READ_UVLC( code, "scaling_list_pred_matrix_id_delta");
     3135          scalingList->setRefMatrixId (sizeId,listId,(UInt)((Int)(listId)-(code+1)));
     3136#if SCALING_LIST
     3137          if( sizeId > SCALING_LIST_8x8 )
     3138          {
     3139            scalingList->setScalingListDC(sizeId,listId,scalingList->getScalingListDC(sizeId, scalingList->getRefMatrixId (sizeId,listId)));
     3140          }
     3141#endif
     3142          scalingList->processRefMatrix( sizeId, listId, scalingList->getRefMatrixId (sizeId,listId));
     3143         
     3144        }
     3145        else //DPCM Mode
     3146        {
     3147          xDecodeScalingList(scalingList, sizeId, listId);
     3148        }
     3149      }
     3150    }
     3151  }
     3152
     3153  return;
     3154}
     3155/** decode DPCM
     3156 * \param scalingList  quantization matrix information
     3157 * \param sizeId size index
     3158 * \param listId list index
     3159 */
     3160Void TDecCavlc::xDecodeScalingList(TComScalingList *scalingList, UInt sizeId, UInt listId)
     3161{
     3162#if SCALING_LIST
     3163  Int i,coefNum = min(MAX_MATRIX_COEF_NUM,(Int)g_scalingListSize[sizeId]);
     3164  Int data;
     3165  Int scalingListDcCoefMinus8 = 0;
     3166  Int nextCoef = SCALING_LIST_START_VALUE;
     3167  UInt* scan  = g_auiFrameScanXY [ (sizeId == 0)? 1 : 2 ];
     3168  Bool stopNow = false;
     3169  Int *dst = scalingList->getScalingListAddress(sizeId, listId);
     3170
     3171  scalingList->setUseDefaultScalingMatrixFlag(sizeId,listId,false);
     3172  if( sizeId > SCALING_LIST_8x8 )
     3173  {
     3174    READ_SVLC( scalingListDcCoefMinus8, "scaling_list_dc_coef_minus8");
     3175    scalingList->setScalingListDC(sizeId,listId,scalingListDcCoefMinus8 + 8);
     3176    if(scalingListDcCoefMinus8 == -8)
     3177    {
     3178      scalingList->processDefaultMarix(sizeId,listId);
     3179    }
     3180  }
     3181
     3182  if( !scalingList->getUseDefaultScalingMatrixFlag(sizeId,listId))
     3183  {
     3184    for(i = 0; i < coefNum && !stopNow ; i++)
     3185    {
     3186      READ_SVLC( data, "scaling_list_delta_coef");
     3187      nextCoef = (nextCoef + data + 256 ) % 256;
     3188      if(sizeId < SCALING_LIST_16x16)
     3189      {
     3190        if( i == 0 && nextCoef == 0 )
     3191        {
     3192          scalingList->processDefaultMarix(sizeId,listId);
     3193          stopNow = true;
     3194        }
     3195      }
     3196      if(!stopNow)
     3197      {
     3198        dst[scan[i]] = nextCoef;
     3199      }
     3200    }
     3201  }
     3202#else
     3203  Int i,coefNum = g_scalingListSize[sizeId];
     3204  Int data;
     3205  Int nextCoef = SCALING_LIST_START_VALUE;
     3206  UInt* scan  = g_auiFrameScanXY [ sizeId + 1 ];
     3207  Int *dst = scalingList->getScalingListAddress(sizeId, listId);
     3208
     3209  for(i = 0; i < coefNum; i++)
     3210  {
     3211    READ_SVLC( data, "scaling_list_delta_coef");
     3212    nextCoef = (nextCoef + data + 256 ) % 256;
     3213    dst[scan[i]] = nextCoef;
     3214  }
     3215#endif
     3216}
     3217
     3218Void TDecCavlc::parseDFFlag(UInt& ruiVal, const Char *pSymbolName)
     3219{
     3220  READ_FLAG(ruiVal, pSymbolName);
     3221}
     3222Void TDecCavlc::parseDFSvlc(Int&  riVal, const Char *pSymbolName)
     3223{
     3224  READ_SVLC(riVal, pSymbolName);
     3225}
     3226
     3227Bool TDecCavlc::xMoreRbspData()
     3228{
     3229  Int bitsLeft = m_pcBitstream->getNumBitsLeft();
     3230
     3231  // if there are more than 8 bits, it cannot be rbsp_trailing_bits
     3232  if (bitsLeft > 8)
     3233  {
     3234    return true;
     3235  }
     3236
     3237  UChar lastByte = m_pcBitstream->peekBits(bitsLeft);
     3238  Int cnt = bitsLeft;
     3239
     3240  // remove trailing bits equal to zero
     3241  while ((cnt>0) && ((lastByte & 1) == 0))
     3242  {
     3243    lastByte >>= 1;
     3244    cnt--;
     3245  }
     3246  // remove bit equal to one
     3247  cnt--;
     3248
     3249  // we should not have a negative number of bits
     3250  assert (cnt>=0);
     3251
     3252  // we have more data, if cnt is not zero
     3253  return (cnt>0);
     3254}
     3255
     3256//! \}
Note: See TracChangeset for help on using the changeset viewer.