Changeset 1313 in 3DVCSoftware for trunk/source/Lib/TLibDecoder/TDecSbac.cpp


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

Merged 14.1-update-dev1@1312.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/source/Lib/TLibDecoder/TDecSbac.cpp

    r1196 r1313  
    22 * License, included below. This software may be subject to other third party
    33 * and contributor rights, including patent rights, and no such rights are
    4  * granted under this license. 
     4 * granted under this license.
    55 *
    6 * Copyright (c) 2010-2015, ITU/ISO/IEC
     6 * Copyright (c) 2010-2015, ITU/ISO/IEC
    77 * All rights reserved.
    88 *
     
    3737
    3838#include "TDecSbac.h"
     39#include "TLibCommon/TComTU.h"
     40#include "TLibCommon/TComTrQuant.h"
     41
     42#if RExt__DECODER_DEBUG_BIT_STATISTICS
     43#include "TLibCommon/TComCodingStatistics.h"
     44//
     45#define RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(a) , a
     46#else
     47#define RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(a)
     48#endif
    3949
    4050//! \ingroup TLibDecoder
    4151//! \{
     52
     53#if ENVIRONMENT_VARIABLE_DEBUG_AND_TEST
     54#include "../TLibCommon/Debug.h"
     55#endif
     56
    4257
    4358//////////////////////////////////////////////////////////////////////
     
    4560//////////////////////////////////////////////////////////////////////
    4661
    47 TDecSbac::TDecSbac() 
     62TDecSbac::TDecSbac()
    4863// new structure here
    49 : m_pcBitstream               ( 0 )
    50 , m_pcTDecBinIf               ( NULL )
    51 , m_numContextModels          ( 0 )
    52 , m_cCUSplitFlagSCModel       ( 1,             1,               NUM_SPLIT_FLAG_CTX            , m_contextModels + m_numContextModels, m_numContextModels )
    53 , m_cCUSkipFlagSCModel        ( 1,             1,               NUM_SKIP_FLAG_CTX             , m_contextModels + m_numContextModels, m_numContextModels)
    54 #if H_3D
    55 , m_cCUDISFlagSCModel         ( 1,             1,               NUM_DIS_FLAG_CTX             , m_contextModels + m_numContextModels, m_numContextModels)
    56 , m_cCUDISTypeSCModel         ( 1,             1,               NUM_DIS_TYPE_CTX             , m_contextModels + m_numContextModels, m_numContextModels)
    57 #endif
    58 , m_cCUMergeFlagExtSCModel    ( 1,             1,               NUM_MERGE_FLAG_EXT_CTX        , m_contextModels + m_numContextModels, m_numContextModels)
    59 , m_cCUMergeIdxExtSCModel     ( 1,             1,               NUM_MERGE_IDX_EXT_CTX         , m_contextModels + m_numContextModels, m_numContextModels)
    60 #if H_3D_ARP
     64: m_pcBitstream                              ( 0 )
     65, m_pcTDecBinIf                              ( NULL )
     66, m_numContextModels                         ( 0 )
     67, m_cCUSplitFlagSCModel                      ( 1,             1,                      NUM_SPLIT_FLAG_CTX                   , m_contextModels + m_numContextModels, m_numContextModels)
     68, m_cCUSkipFlagSCModel                       ( 1,             1,                      NUM_SKIP_FLAG_CTX                    , m_contextModels + m_numContextModels, m_numContextModels)
     69#if NH_3D_DIS
     70, m_cCUDISFlagSCModel                        ( 1,             1,                      NUM_DIS_FLAG_CTX                     , m_contextModels + m_numContextModels, m_numContextModels)
     71, m_cCUDISTypeSCModel                        ( 1,             1,                      NUM_DIS_TYPE_CTX                     , m_contextModels + m_numContextModels, m_numContextModels)
     72#endif
     73, m_cCUMergeFlagExtSCModel                   ( 1,             1,                      NUM_MERGE_FLAG_EXT_CTX               , m_contextModels + m_numContextModels, m_numContextModels)
     74, m_cCUMergeIdxExtSCModel                    ( 1,             1,                      NUM_MERGE_IDX_EXT_CTX                , m_contextModels + m_numContextModels, m_numContextModels)
     75#if NH_3D_ARP
    6176, m_cCUPUARPWSCModel          ( 1,             1,               NUM_ARPW_CTX                  , m_contextModels + m_numContextModels, m_numContextModels)
    6277#endif
    63 #if H_3D_IC
     78#if NH_3D_IC
    6479, m_cCUICFlagSCModel          ( 1,             1,               NUM_IC_FLAG_CTX               , m_contextModels + m_numContextModels, m_numContextModels)
    6580#endif
    66 , m_cCUPartSizeSCModel        ( 1,             1,               NUM_PART_SIZE_CTX             , m_contextModels + m_numContextModels, m_numContextModels)
    67 , m_cCUPredModeSCModel        ( 1,             1,               NUM_PRED_MODE_CTX             , m_contextModels + m_numContextModels, m_numContextModels)
    68 , m_cCUIntraPredSCModel       ( 1,             1,               NUM_ADI_CTX                   , m_contextModels + m_numContextModels, m_numContextModels)
    69 , m_cCUChromaPredSCModel      ( 1,             1,               NUM_CHROMA_PRED_CTX           , m_contextModels + m_numContextModels, m_numContextModels)
    70 , m_cCUDeltaQpSCModel         ( 1,             1,               NUM_DELTA_QP_CTX              , m_contextModels + m_numContextModels, m_numContextModels)
    71 , m_cCUInterDirSCModel        ( 1,             1,               NUM_INTER_DIR_CTX             , m_contextModels + m_numContextModels, m_numContextModels)
    72 , m_cCURefPicSCModel          ( 1,             1,               NUM_REF_NO_CTX                , m_contextModels + m_numContextModels, m_numContextModels)
    73 , m_cCUMvdSCModel             ( 1,             1,               NUM_MV_RES_CTX                , m_contextModels + m_numContextModels, m_numContextModels)
    74 , m_cCUQtCbfSCModel           ( 1,             2,               NUM_QT_CBF_CTX                , m_contextModels + m_numContextModels, m_numContextModels)
    75 , m_cCUTransSubdivFlagSCModel ( 1,             1,               NUM_TRANS_SUBDIV_FLAG_CTX     , m_contextModels + m_numContextModels, m_numContextModels)
    76 , m_cCUQtRootCbfSCModel       ( 1,             1,               NUM_QT_ROOT_CBF_CTX           , m_contextModels + m_numContextModels, m_numContextModels)
    77 , m_cCUSigCoeffGroupSCModel   ( 1,             2,               NUM_SIG_CG_FLAG_CTX           , m_contextModels + m_numContextModels, m_numContextModels)
    78 , m_cCUSigSCModel             ( 1,             1,               NUM_SIG_FLAG_CTX              , m_contextModels + m_numContextModels, m_numContextModels)
    79 , m_cCuCtxLastX               ( 1,             2,               NUM_CTX_LAST_FLAG_XY          , m_contextModels + m_numContextModels, m_numContextModels)
    80 , m_cCuCtxLastY               ( 1,             2,               NUM_CTX_LAST_FLAG_XY          , m_contextModels + m_numContextModels, m_numContextModels)
    81 , m_cCUOneSCModel             ( 1,             1,               NUM_ONE_FLAG_CTX              , m_contextModels + m_numContextModels, m_numContextModels)
    82 , m_cCUAbsSCModel             ( 1,             1,               NUM_ABS_FLAG_CTX              , m_contextModels + m_numContextModels, m_numContextModels)
    83 , m_cMVPIdxSCModel            ( 1,             1,               NUM_MVP_IDX_CTX               , m_contextModels + m_numContextModels, m_numContextModels)
    84 , m_cSaoMergeSCModel      ( 1,             1,               NUM_SAO_MERGE_FLAG_CTX   , m_contextModels + m_numContextModels, m_numContextModels)
    85 , m_cSaoTypeIdxSCModel        ( 1,             1,               NUM_SAO_TYPE_IDX_CTX          , m_contextModels + m_numContextModels, m_numContextModels)
    86 , m_cTransformSkipSCModel     ( 1,             2,               NUM_TRANSFORMSKIP_FLAG_CTX    , m_contextModels + m_numContextModels, m_numContextModels)
    87 , m_CUTransquantBypassFlagSCModel( 1,          1,               NUM_CU_TRANSQUANT_BYPASS_FLAG_CTX, m_contextModels + m_numContextModels, m_numContextModels)
    88 #if H_3D_DIM
    89 , m_cDepthIntraModeSCModel    ( 1,             1,               NUM_DEPTH_INTRA_MODE_CTX      , m_contextModels + m_numContextModels, m_numContextModels)
    90 , m_cDdcFlagSCModel           ( 1,             1,               NUM_DDC_FLAG_CTX              , m_contextModels + m_numContextModels, m_numContextModels)
    91 , m_cDdcDataSCModel           ( 1,             1,               NUM_DDC_DATA_CTX              , m_contextModels + m_numContextModels, m_numContextModels)
    92 , m_cAngleFlagSCModel         ( 1,             1,               NUM_ANGLE_FLAG_CTX            , m_contextModels + m_numContextModels, m_numContextModels)
    93 #if H_3D_DIM_SDC
    94 , m_cSDCResidualFlagSCModel     ( 1,             1,             SDC_NUM_RESIDUAL_FLAG_CTX     , m_contextModels + m_numContextModels, m_numContextModels)
    95 , m_cSDCResidualSCModel         ( 1,             1,             SDC_NUM_RESIDUAL_CTX          , m_contextModels + m_numContextModels, m_numContextModels)
    96 #endif
    97 #endif
    98 #if H_3D_DIM_SDC
    99 , m_cSDCFlagSCModel                  ( 1,             1,  NUM_SDC_FLAG_CTX                 , m_contextModels + m_numContextModels, m_numContextModels)
    100 #endif
    101 #if H_3D_DBBP
    102 , m_cDBBPFlagSCModel             ( 1,             1,                 DBBP_NUM_FLAG_CTX           , m_contextModels + m_numContextModels, m_numContextModels)
    103 #endif
     81, m_cCUPartSizeSCModel                       ( 1,             1,                      NUM_PART_SIZE_CTX                    , m_contextModels + m_numContextModels, m_numContextModels)
     82, m_cCUPredModeSCModel                       ( 1,             1,                      NUM_PRED_MODE_CTX                    , m_contextModels + m_numContextModels, m_numContextModels)
     83, m_cCUIntraPredSCModel                      ( 1,             1,                      NUM_INTRA_PREDICT_CTX                , m_contextModels + m_numContextModels, m_numContextModels)
     84, m_cCUChromaPredSCModel                     ( 1,             1,                      NUM_CHROMA_PRED_CTX                  , m_contextModels + m_numContextModels, m_numContextModels)
     85, m_cCUDeltaQpSCModel                        ( 1,             1,                      NUM_DELTA_QP_CTX                     , m_contextModels + m_numContextModels, m_numContextModels)
     86, m_cCUInterDirSCModel                       ( 1,             1,                      NUM_INTER_DIR_CTX                    , m_contextModels + m_numContextModels, m_numContextModels)
     87, m_cCURefPicSCModel                         ( 1,             1,                      NUM_REF_NO_CTX                       , m_contextModels + m_numContextModels, m_numContextModels)
     88, m_cCUMvdSCModel                            ( 1,             1,                      NUM_MV_RES_CTX                       , m_contextModels + m_numContextModels, m_numContextModels)
     89, m_cCUQtCbfSCModel                          ( 1,             NUM_QT_CBF_CTX_SETS,    NUM_QT_CBF_CTX_PER_SET               , m_contextModels + m_numContextModels, m_numContextModels)
     90, m_cCUTransSubdivFlagSCModel                ( 1,             1,                      NUM_TRANS_SUBDIV_FLAG_CTX            , m_contextModels + m_numContextModels, m_numContextModels)
     91, m_cCUQtRootCbfSCModel                      ( 1,             1,                      NUM_QT_ROOT_CBF_CTX                  , m_contextModels + m_numContextModels, m_numContextModels)
     92, m_cCUSigCoeffGroupSCModel                  ( 1,             2,                      NUM_SIG_CG_FLAG_CTX                  , m_contextModels + m_numContextModels, m_numContextModels)
     93, m_cCUSigSCModel                            ( 1,             1,                      NUM_SIG_FLAG_CTX                     , m_contextModels + m_numContextModels, m_numContextModels)
     94, m_cCuCtxLastX                              ( 1,             NUM_CTX_LAST_FLAG_SETS, NUM_CTX_LAST_FLAG_XY                 , m_contextModels + m_numContextModels, m_numContextModels)
     95, m_cCuCtxLastY                              ( 1,             NUM_CTX_LAST_FLAG_SETS, NUM_CTX_LAST_FLAG_XY                 , m_contextModels + m_numContextModels, m_numContextModels)
     96, m_cCUOneSCModel                            ( 1,             1,                      NUM_ONE_FLAG_CTX                     , m_contextModels + m_numContextModels, m_numContextModels)
     97, m_cCUAbsSCModel                            ( 1,             1,                      NUM_ABS_FLAG_CTX                     , m_contextModels + m_numContextModels, m_numContextModels)
     98, m_cMVPIdxSCModel                           ( 1,             1,                      NUM_MVP_IDX_CTX                      , m_contextModels + m_numContextModels, m_numContextModels)
     99, m_cSaoMergeSCModel                         ( 1,             1,                      NUM_SAO_MERGE_FLAG_CTX               , m_contextModels + m_numContextModels, m_numContextModels)
     100, m_cSaoTypeIdxSCModel                       ( 1,             1,                      NUM_SAO_TYPE_IDX_CTX                 , m_contextModels + m_numContextModels, m_numContextModels)
     101, m_cTransformSkipSCModel                    ( 1,             MAX_NUM_CHANNEL_TYPE,   NUM_TRANSFORMSKIP_FLAG_CTX           , m_contextModels + m_numContextModels, m_numContextModels)
     102, m_CUTransquantBypassFlagSCModel            ( 1,             1,                      NUM_CU_TRANSQUANT_BYPASS_FLAG_CTX    , m_contextModels + m_numContextModels, m_numContextModels)
     103, m_explicitRdpcmFlagSCModel                 ( 1,             MAX_NUM_CHANNEL_TYPE,   NUM_EXPLICIT_RDPCM_FLAG_CTX          , m_contextModels + m_numContextModels, m_numContextModels)
     104, m_explicitRdpcmDirSCModel                  ( 1,             MAX_NUM_CHANNEL_TYPE,   NUM_EXPLICIT_RDPCM_DIR_CTX           , m_contextModels + m_numContextModels, m_numContextModels)
     105, m_cCrossComponentPredictionSCModel         ( 1,             1,                      NUM_CROSS_COMPONENT_PREDICTION_CTX   , m_contextModels + m_numContextModels, m_numContextModels)
     106, m_ChromaQpAdjFlagSCModel                   ( 1,             1,                      NUM_CHROMA_QP_ADJ_FLAG_CTX           , m_contextModels + m_numContextModels, m_numContextModels)
     107, m_ChromaQpAdjIdcSCModel                    ( 1,             1,                      NUM_CHROMA_QP_ADJ_IDC_CTX            , m_contextModels + m_numContextModels, m_numContextModels)
     108
     109#if NH_3D_DMM
     110, m_cNotDmmFlagSCModel                       ( 1,             1,                      NUM_NOTDMM_FLAG_CTX                  , m_contextModels + m_numContextModels, m_numContextModels)
     111, m_cDmmModeSCModel                          ( 1,             1,                      NUM_DMM_MODE_CTX                     , m_contextModels + m_numContextModels, m_numContextModels)
     112#endif
     113#if NH_3D_DMM || NH_3D_SDC_INTRA || NH_3D_SDC_INTER
     114, m_cDdcDataSCModel                          ( 1,             1,                      NUM_DDC_DATA_CTX                     , m_contextModels + m_numContextModels, m_numContextModels)
     115, m_cSDCFlagSCModel                          ( 1,             1,                     NUM_SDC_FLAG_CTX                      , m_contextModels + m_numContextModels, m_numContextModels)
     116#endif
     117#if NH_3D_SDC_INTRA
     118, m_cSDCResidualFlagSCModel                  ( 1,             1,                     SDC_NUM_RESIDUAL_FLAG_CTX             , m_contextModels + m_numContextModels, m_numContextModels)
     119, m_cSDCResidualSCModel                      ( 1,             1,                     SDC_NUM_RESIDUAL_CTX                  , m_contextModels + m_numContextModels, m_numContextModels)
     120, m_cDdcFlagSCModel                          ( 1,             1,                     NUM_DDC_FLAG_CTX                      , m_contextModels + m_numContextModels, m_numContextModels)
     121#endif
     122#if NH_3D_DBBP
     123, m_cDBBPFlagSCModel                         ( 1,             1,                     DBBP_NUM_FLAG_CTX                     , m_contextModels + m_numContextModels, m_numContextModels)
     124#endif
     125
    104126{
    105127  assert( m_numContextModels <= MAX_NUM_CTX_MOD );
     
    124146    {
    125147    case P_SLICE:           // change initialization table to B_SLICE initialization
    126       sliceType = B_SLICE; 
     148      sliceType = B_SLICE;
    127149      break;
    128150    case B_SLICE:           // change initialization table to P_SLICE initialization
    129       sliceType = P_SLICE; 
     151      sliceType = P_SLICE;
    130152      break;
    131153    default     :           // should not occur
    132154      assert(0);
    133     }
    134   }
    135 
    136   m_cCUSplitFlagSCModel.initBuffer       ( sliceType, qp, (UChar*)INIT_SPLIT_FLAG );
    137   m_cCUSkipFlagSCModel.initBuffer        ( sliceType, qp, (UChar*)INIT_SKIP_FLAG );
    138 #if H_3D
    139   m_cCUDISFlagSCModel.initBuffer         ( sliceType, qp, (UChar*)INIT_DIS_FLAG );
    140   m_cCUDISTypeSCModel.initBuffer         ( sliceType, qp, (UChar*)INIT_DIS_TYPE );
    141 #endif
    142   m_cCUMergeFlagExtSCModel.initBuffer    ( sliceType, qp, (UChar*)INIT_MERGE_FLAG_EXT );
    143   m_cCUMergeIdxExtSCModel.initBuffer     ( sliceType, qp, (UChar*)INIT_MERGE_IDX_EXT );
    144 #if H_3D_ARP
     155      break;
     156    }
     157  }
     158
     159  m_cCUSplitFlagSCModel.initBuffer                ( sliceType, qp, (UChar*)INIT_SPLIT_FLAG );
     160  m_cCUSkipFlagSCModel.initBuffer                 ( sliceType, qp, (UChar*)INIT_SKIP_FLAG );
     161#if NH_3D_DIS
     162  m_cCUDISFlagSCModel.initBuffer                  ( sliceType, qp, (UChar*)INIT_DIS_FLAG );
     163  m_cCUDISTypeSCModel.initBuffer                  ( sliceType, qp, (UChar*)INIT_DIS_TYPE );
     164#endif
     165  m_cCUMergeFlagExtSCModel.initBuffer             ( sliceType, qp, (UChar*)INIT_MERGE_FLAG_EXT );
     166  m_cCUMergeIdxExtSCModel.initBuffer              ( sliceType, qp, (UChar*)INIT_MERGE_IDX_EXT );
     167#if NH_3D_ARP
    145168  m_cCUPUARPWSCModel.initBuffer          ( sliceType, qp, (UChar*)INIT_ARPW );
    146169#endif
    147 #if H_3D_IC
     170#if NH_3D_IC
    148171  m_cCUICFlagSCModel.initBuffer          ( sliceType, qp, (UChar*)INIT_IC_FLAG );
    149172#endif
    150   m_cCUPartSizeSCModel.initBuffer        ( sliceType, qp, (UChar*)INIT_PART_SIZE );
    151   m_cCUPredModeSCModel.initBuffer        ( sliceType, qp, (UChar*)INIT_PRED_MODE );
    152   m_cCUIntraPredSCModel.initBuffer       ( sliceType, qp, (UChar*)INIT_INTRA_PRED_MODE );
    153   m_cCUChromaPredSCModel.initBuffer      ( sliceType, qp, (UChar*)INIT_CHROMA_PRED_MODE );
    154   m_cCUInterDirSCModel.initBuffer        ( sliceType, qp, (UChar*)INIT_INTER_DIR );
    155   m_cCUMvdSCModel.initBuffer             ( sliceType, qp, (UChar*)INIT_MVD );
    156   m_cCURefPicSCModel.initBuffer          ( sliceType, qp, (UChar*)INIT_REF_PIC );
    157   m_cCUDeltaQpSCModel.initBuffer         ( sliceType, qp, (UChar*)INIT_DQP );
    158   m_cCUQtCbfSCModel.initBuffer           ( sliceType, qp, (UChar*)INIT_QT_CBF );
    159   m_cCUQtRootCbfSCModel.initBuffer       ( sliceType, qp, (UChar*)INIT_QT_ROOT_CBF );
    160   m_cCUSigCoeffGroupSCModel.initBuffer   ( sliceType, qp, (UChar*)INIT_SIG_CG_FLAG );
    161   m_cCUSigSCModel.initBuffer             ( sliceType, qp, (UChar*)INIT_SIG_FLAG );
    162   m_cCuCtxLastX.initBuffer               ( sliceType, qp, (UChar*)INIT_LAST );
    163   m_cCuCtxLastY.initBuffer               ( sliceType, qp, (UChar*)INIT_LAST );
    164   m_cCUOneSCModel.initBuffer             ( sliceType, qp, (UChar*)INIT_ONE_FLAG );
    165   m_cCUAbsSCModel.initBuffer             ( sliceType, qp, (UChar*)INIT_ABS_FLAG );
    166   m_cMVPIdxSCModel.initBuffer            ( sliceType, qp, (UChar*)INIT_MVP_IDX );
    167   m_cSaoMergeSCModel.initBuffer      ( sliceType, qp, (UChar*)INIT_SAO_MERGE_FLAG );
    168   m_cSaoTypeIdxSCModel.initBuffer        ( sliceType, qp, (UChar*)INIT_SAO_TYPE_IDX );
    169 
    170   m_cCUTransSubdivFlagSCModel.initBuffer ( sliceType, qp, (UChar*)INIT_TRANS_SUBDIV_FLAG );
    171   m_cTransformSkipSCModel.initBuffer     ( sliceType, qp, (UChar*)INIT_TRANSFORMSKIP_FLAG );
    172   m_CUTransquantBypassFlagSCModel.initBuffer( sliceType, qp, (UChar*)INIT_CU_TRANSQUANT_BYPASS_FLAG );
    173 #if H_3D_DIM
    174   m_cDepthIntraModeSCModel.initBuffer    ( sliceType, qp, (UChar*)INIT_DEPTH_INTRA_MODE );
    175   m_cDdcFlagSCModel.initBuffer           ( sliceType, qp, (UChar*)INIT_DDC_FLAG );
    176   m_cDdcDataSCModel.initBuffer           ( sliceType, qp, (UChar*)INIT_DDC_DATA );
    177   m_cAngleFlagSCModel.initBuffer         ( sliceType, qp, (UChar*)INIT_ANGLE_FLAG );
    178 #if H_3D_DIM_SDC
    179   m_cSDCResidualFlagSCModel.initBuffer    ( sliceType, qp, (UChar*)INIT_SDC_RESIDUAL_FLAG );
    180   m_cSDCResidualSCModel.initBuffer        ( sliceType, qp, (UChar*)INIT_SDC_RESIDUAL );
    181 #endif
    182 #endif
    183 #if H_3D_DIM_SDC
    184   m_cSDCFlagSCModel.initBuffer            ( sliceType, qp, (UChar*)INIT_SDC_FLAG );
    185 #endif
    186 #if H_3D_DBBP
    187   m_cDBBPFlagSCModel.initBuffer              ( sliceType, qp, (UChar*)INIT_DBBP_FLAG );
    188 #endif
    189   m_uiLastDQpNonZero  = 0;
    190  
    191   // new structure
    192   m_uiLastQp          = qp;
    193  
     173  m_cCUPartSizeSCModel.initBuffer                 ( sliceType, qp, (UChar*)INIT_PART_SIZE );
     174  m_cCUPredModeSCModel.initBuffer                 ( sliceType, qp, (UChar*)INIT_PRED_MODE );
     175  m_cCUIntraPredSCModel.initBuffer                ( sliceType, qp, (UChar*)INIT_INTRA_PRED_MODE );
     176  m_cCUChromaPredSCModel.initBuffer               ( sliceType, qp, (UChar*)INIT_CHROMA_PRED_MODE );
     177  m_cCUInterDirSCModel.initBuffer                 ( sliceType, qp, (UChar*)INIT_INTER_DIR );
     178  m_cCUMvdSCModel.initBuffer                      ( sliceType, qp, (UChar*)INIT_MVD );
     179  m_cCURefPicSCModel.initBuffer                   ( sliceType, qp, (UChar*)INIT_REF_PIC );
     180  m_cCUDeltaQpSCModel.initBuffer                  ( sliceType, qp, (UChar*)INIT_DQP );
     181  m_cCUQtCbfSCModel.initBuffer                    ( sliceType, qp, (UChar*)INIT_QT_CBF );
     182  m_cCUQtRootCbfSCModel.initBuffer                ( sliceType, qp, (UChar*)INIT_QT_ROOT_CBF );
     183  m_cCUSigCoeffGroupSCModel.initBuffer            ( sliceType, qp, (UChar*)INIT_SIG_CG_FLAG );
     184  m_cCUSigSCModel.initBuffer                      ( sliceType, qp, (UChar*)INIT_SIG_FLAG );
     185  m_cCuCtxLastX.initBuffer                        ( sliceType, qp, (UChar*)INIT_LAST );
     186  m_cCuCtxLastY.initBuffer                        ( sliceType, qp, (UChar*)INIT_LAST );
     187  m_cCUOneSCModel.initBuffer                      ( sliceType, qp, (UChar*)INIT_ONE_FLAG );
     188  m_cCUAbsSCModel.initBuffer                      ( sliceType, qp, (UChar*)INIT_ABS_FLAG );
     189  m_cMVPIdxSCModel.initBuffer                     ( sliceType, qp, (UChar*)INIT_MVP_IDX );
     190  m_cSaoMergeSCModel.initBuffer                   ( sliceType, qp, (UChar*)INIT_SAO_MERGE_FLAG );
     191  m_cSaoTypeIdxSCModel.initBuffer                 ( sliceType, qp, (UChar*)INIT_SAO_TYPE_IDX );
     192  m_cCUTransSubdivFlagSCModel.initBuffer          ( sliceType, qp, (UChar*)INIT_TRANS_SUBDIV_FLAG );
     193  m_cTransformSkipSCModel.initBuffer              ( sliceType, qp, (UChar*)INIT_TRANSFORMSKIP_FLAG );
     194  m_CUTransquantBypassFlagSCModel.initBuffer      ( sliceType, qp, (UChar*)INIT_CU_TRANSQUANT_BYPASS_FLAG );
     195  m_explicitRdpcmFlagSCModel.initBuffer           ( sliceType, qp, (UChar*)INIT_EXPLICIT_RDPCM_FLAG);
     196  m_explicitRdpcmDirSCModel.initBuffer            ( sliceType, qp, (UChar*)INIT_EXPLICIT_RDPCM_DIR);
     197  m_cCrossComponentPredictionSCModel.initBuffer   ( sliceType, qp, (UChar*)INIT_CROSS_COMPONENT_PREDICTION );
     198  m_ChromaQpAdjFlagSCModel.initBuffer             ( sliceType, qp, (UChar*)INIT_CHROMA_QP_ADJ_FLAG );
     199  m_ChromaQpAdjIdcSCModel.initBuffer              ( sliceType, qp, (UChar*)INIT_CHROMA_QP_ADJ_IDC );
     200#if NH_3D_DMM
     201  m_cNotDmmFlagSCModel.initBuffer                 ( sliceType, qp, (UChar*)INIT_NOTDMM_FLAG );
     202  m_cDmmModeSCModel.initBuffer                    ( sliceType, qp, (UChar*)INIT_DMM_MODE );
     203#endif
     204#if NH_3D_DMM || NH_3D_SDC_INTRA || NH_3D_SDC_INTER
     205  m_cDdcDataSCModel.initBuffer                    ( sliceType, qp, (UChar*)INIT_DDC_DATA );
     206  m_cSDCFlagSCModel.initBuffer                    ( sliceType, qp, (UChar*)INIT_SDC_FLAG );
     207#endif
     208#if NH_3D_SDC_INTRA
     209  m_cSDCResidualFlagSCModel.initBuffer            ( sliceType, qp, (UChar*)INIT_SDC_RESIDUAL_FLAG );
     210  m_cSDCResidualSCModel.initBuffer                ( sliceType, qp, (UChar*)INIT_SDC_RESIDUAL );
     211  m_cDdcFlagSCModel.initBuffer                    ( sliceType, qp, (UChar*)INIT_DDC_FLAG );
     212#endif
     213#if NH_3D_DBBP
     214  m_cDBBPFlagSCModel.initBuffer                   ( sliceType, qp, (UChar*)INIT_DBBP_FLAG );
     215#endif
     216
     217  for (UInt statisticIndex = 0; statisticIndex < RExt__GOLOMB_RICE_ADAPTATION_STATISTICS_SETS ; statisticIndex++)
     218  {
     219    m_golombRiceAdaptationStatistics[statisticIndex] = 0;
     220  }
     221
    194222  m_pcTDecBinIf->start();
    195223}
    196224
    197 /** The function does the following: Read out terminate bit. Flush CABAC. Byte-align for next tile.
    198  *  Intialize CABAC states. Start CABAC.
    199  */
    200 Void TDecSbac::updateContextTables( SliceType eSliceType, Int iQp )
    201 {
    202   UInt uiBit;
    203   m_pcTDecBinIf->decodeBinTrm(uiBit);
    204   assert(uiBit); // end_of_sub_stream_one_bit must be equal to 1
    205   m_pcTDecBinIf->finish(); 
    206   m_pcBitstream->readOutTrailingBits();
    207   m_cCUSplitFlagSCModel.initBuffer       ( eSliceType, iQp, (UChar*)INIT_SPLIT_FLAG );
    208   m_cCUSkipFlagSCModel.initBuffer        ( eSliceType, iQp, (UChar*)INIT_SKIP_FLAG );
    209 #if H_3D
    210   m_cCUDISFlagSCModel.initBuffer         ( eSliceType, iQp, (UChar*)INIT_DIS_FLAG );
    211   m_cCUDISTypeSCModel.initBuffer         ( eSliceType, iQp, (UChar*)INIT_DIS_TYPE );
    212 #endif
    213   m_cCUMergeFlagExtSCModel.initBuffer    ( eSliceType, iQp, (UChar*)INIT_MERGE_FLAG_EXT );
    214   m_cCUMergeIdxExtSCModel.initBuffer     ( eSliceType, iQp, (UChar*)INIT_MERGE_IDX_EXT );
    215 #if H_3D_ARP
    216   m_cCUPUARPWSCModel.initBuffer          ( eSliceType, iQp, (UChar*)INIT_ARPW );
    217 #endif
    218 #if H_3D_IC
    219   m_cCUICFlagSCModel.initBuffer          ( eSliceType, iQp, (UChar*)INIT_IC_FLAG );
    220 #endif
    221   m_cCUPartSizeSCModel.initBuffer        ( eSliceType, iQp, (UChar*)INIT_PART_SIZE );
    222   m_cCUPredModeSCModel.initBuffer        ( eSliceType, iQp, (UChar*)INIT_PRED_MODE );
    223   m_cCUIntraPredSCModel.initBuffer       ( eSliceType, iQp, (UChar*)INIT_INTRA_PRED_MODE );
    224   m_cCUChromaPredSCModel.initBuffer      ( eSliceType, iQp, (UChar*)INIT_CHROMA_PRED_MODE );
    225   m_cCUInterDirSCModel.initBuffer        ( eSliceType, iQp, (UChar*)INIT_INTER_DIR );
    226   m_cCUMvdSCModel.initBuffer             ( eSliceType, iQp, (UChar*)INIT_MVD );
    227   m_cCURefPicSCModel.initBuffer          ( eSliceType, iQp, (UChar*)INIT_REF_PIC );
    228   m_cCUDeltaQpSCModel.initBuffer         ( eSliceType, iQp, (UChar*)INIT_DQP );
    229   m_cCUQtCbfSCModel.initBuffer           ( eSliceType, iQp, (UChar*)INIT_QT_CBF );
    230   m_cCUQtRootCbfSCModel.initBuffer       ( eSliceType, iQp, (UChar*)INIT_QT_ROOT_CBF );
    231   m_cCUSigCoeffGroupSCModel.initBuffer   ( eSliceType, iQp, (UChar*)INIT_SIG_CG_FLAG );
    232   m_cCUSigSCModel.initBuffer             ( eSliceType, iQp, (UChar*)INIT_SIG_FLAG );
    233   m_cCuCtxLastX.initBuffer               ( eSliceType, iQp, (UChar*)INIT_LAST );
    234   m_cCuCtxLastY.initBuffer               ( eSliceType, iQp, (UChar*)INIT_LAST );
    235   m_cCUOneSCModel.initBuffer             ( eSliceType, iQp, (UChar*)INIT_ONE_FLAG );
    236   m_cCUAbsSCModel.initBuffer             ( eSliceType, iQp, (UChar*)INIT_ABS_FLAG );
    237   m_cMVPIdxSCModel.initBuffer            ( eSliceType, iQp, (UChar*)INIT_MVP_IDX );
    238   m_cSaoMergeSCModel.initBuffer      ( eSliceType, iQp, (UChar*)INIT_SAO_MERGE_FLAG );
    239   m_cSaoTypeIdxSCModel.initBuffer        ( eSliceType, iQp, (UChar*)INIT_SAO_TYPE_IDX );
    240   m_cCUTransSubdivFlagSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_TRANS_SUBDIV_FLAG );
    241   m_cTransformSkipSCModel.initBuffer     ( eSliceType, iQp, (UChar*)INIT_TRANSFORMSKIP_FLAG );
    242   m_CUTransquantBypassFlagSCModel.initBuffer( eSliceType, iQp, (UChar*)INIT_CU_TRANSQUANT_BYPASS_FLAG );
    243 
    244 #if H_3D_DIM
    245   m_cDepthIntraModeSCModel.initBuffer    ( eSliceType, iQp, (UChar*)INIT_DEPTH_INTRA_MODE );
    246   m_cDdcFlagSCModel.initBuffer           ( eSliceType, iQp, (UChar*)INIT_DDC_FLAG );
    247   m_cDdcDataSCModel.initBuffer           ( eSliceType, iQp, (UChar*)INIT_DDC_DATA );
    248   m_cAngleFlagSCModel.initBuffer         ( eSliceType, iQp, (UChar*)INIT_ANGLE_FLAG );
    249 #if H_3D_DIM_SDC
    250   m_cSDCResidualFlagSCModel.initBuffer    ( eSliceType, iQp, (UChar*)INIT_SDC_RESIDUAL_FLAG );
    251   m_cSDCResidualSCModel.initBuffer        ( eSliceType, iQp, (UChar*)INIT_SDC_RESIDUAL );
    252 #endif
    253 #endif
    254 #if H_3D_DIM_SDC
    255   m_cSDCFlagSCModel.initBuffer            ( eSliceType, iQp, (UChar*)INIT_SDC_FLAG );
    256 #endif
    257 #if H_3D_DBBP
    258   m_cDBBPFlagSCModel.initBuffer              ( eSliceType, iQp, (UChar*)INIT_DBBP_FLAG );
    259 #endif
    260   m_pcTDecBinIf->start();
    261 }
    262 
    263225Void TDecSbac::parseTerminatingBit( UInt& ruiBit )
    264226{
    265227  m_pcTDecBinIf->decodeBinTrm( ruiBit );
    266   if ( ruiBit )
     228  if ( ruiBit == 1 )
    267229  {
    268230    m_pcTDecBinIf->finish();
    269   }
    270 }
    271 
    272 
     231
     232#if RExt__DECODER_DEBUG_BIT_STATISTICS
     233    TComCodingStatistics::IncrementStatisticEP(STATS__TRAILING_BITS, m_pcBitstream->readOutTrailingBits(),0);
     234#else
     235    m_pcBitstream->readOutTrailingBits();
     236#endif
     237  }
     238}
     239
     240
     241
     242Void TDecSbac::parseRemainingBytes( Bool noTrailingBytesExpected )
     243{
     244  if (noTrailingBytesExpected)
     245  {
     246    const UInt numberOfRemainingSubstreamBytes=m_pcBitstream->getNumBitsLeft();
     247    assert (numberOfRemainingSubstreamBytes == 0);
     248  }
     249  else
     250  {
     251    while (m_pcBitstream->getNumBitsLeft())
     252    {
     253      UInt trailingNullByte=m_pcBitstream->readByte();
     254      if (trailingNullByte!=0)
     255      {
     256        printf("Trailing byte should be 0, but has value %02x\n", trailingNullByte);
     257        assert(trailingNullByte==0);
     258      }
     259    }
     260  }
     261}
     262
     263#if RExt__DECODER_DEBUG_BIT_STATISTICS
     264Void TDecSbac::xReadUnaryMaxSymbol( UInt& ruiSymbol, ContextModel* pcSCModel, Int iOffset, UInt uiMaxSymbol, const class TComCodingStatisticsClassType &whichStat )
     265#else
    273266Void TDecSbac::xReadUnaryMaxSymbol( UInt& ruiSymbol, ContextModel* pcSCModel, Int iOffset, UInt uiMaxSymbol )
     267#endif
    274268{
    275269  if (uiMaxSymbol == 0)
     
    278272    return;
    279273  }
    280  
    281   m_pcTDecBinIf->decodeBin( ruiSymbol, pcSCModel[0] );
    282  
     274
     275  m_pcTDecBinIf->decodeBin( ruiSymbol, pcSCModel[0] RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(whichStat) );
     276
    283277  if( ruiSymbol == 0 || uiMaxSymbol == 1 )
    284278  {
    285279    return;
    286280  }
    287  
     281
    288282  UInt uiSymbol = 0;
    289283  UInt uiCont;
    290  
     284
    291285  do
    292286  {
    293     m_pcTDecBinIf->decodeBin( uiCont, pcSCModel[ iOffset ] );
     287    m_pcTDecBinIf->decodeBin( uiCont, pcSCModel[ iOffset ] RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(whichStat) );
    294288    uiSymbol++;
    295   }
    296   while( uiCont && ( uiSymbol < uiMaxSymbol - 1 ) );
    297  
     289  } while( uiCont && ( uiSymbol < uiMaxSymbol - 1 ) );
     290
    298291  if( uiCont && ( uiSymbol == uiMaxSymbol - 1 ) )
    299292  {
    300293    uiSymbol++;
    301294  }
    302  
     295
    303296  ruiSymbol = uiSymbol;
    304297}
    305298
     299#if RExt__DECODER_DEBUG_BIT_STATISTICS
     300Void TDecSbac::xReadEpExGolomb( UInt& ruiSymbol, UInt uiCount, const class TComCodingStatisticsClassType &whichStat )
     301#else
    306302Void TDecSbac::xReadEpExGolomb( UInt& ruiSymbol, UInt uiCount )
     303#endif
    307304{
    308305  UInt uiSymbol = 0;
    309306  UInt uiBit = 1;
    310  
     307
    311308  while( uiBit )
    312309  {
    313     m_pcTDecBinIf->decodeBinEP( uiBit );
     310    m_pcTDecBinIf->decodeBinEP( uiBit RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(whichStat) );
    314311    uiSymbol += uiBit << uiCount++;
    315312  }
    316  
     313
    317314  if ( --uiCount )
    318315  {
    319316    UInt bins;
    320     m_pcTDecBinIf->decodeBinsEP( bins, uiCount );
     317    m_pcTDecBinIf->decodeBinsEP( bins, uiCount RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(whichStat) );
    321318    uiSymbol += bins;
    322319  }
    323  
     320
    324321  ruiSymbol = uiSymbol;
    325322}
    326323
     324#if RExt__DECODER_DEBUG_BIT_STATISTICS
     325Void TDecSbac::xReadUnarySymbol( UInt& ruiSymbol, ContextModel* pcSCModel, Int iOffset, const class TComCodingStatisticsClassType &whichStat )
     326#else
    327327Void TDecSbac::xReadUnarySymbol( UInt& ruiSymbol, ContextModel* pcSCModel, Int iOffset )
    328 {
    329   m_pcTDecBinIf->decodeBin( ruiSymbol, pcSCModel[0] );
    330  
     328#endif
     329{
     330  m_pcTDecBinIf->decodeBin( ruiSymbol, pcSCModel[0] RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(whichStat));
     331
    331332  if( !ruiSymbol )
    332333  {
    333334    return;
    334335  }
    335  
     336
    336337  UInt uiSymbol = 0;
    337338  UInt uiCont;
    338  
     339
    339340  do
    340341  {
    341     m_pcTDecBinIf->decodeBin( uiCont, pcSCModel[ iOffset ] );
     342    m_pcTDecBinIf->decodeBin( uiCont, pcSCModel[ iOffset ] RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(whichStat));
    342343    uiSymbol++;
    343   }
    344   while( uiCont );
    345  
     344  } while( uiCont );
     345
    346346  ruiSymbol = uiSymbol;
    347347}
     
    349349
    350350/** Parsing of coeff_abs_level_remaing
    351  * \param ruiSymbol reference to coeff_abs_level_remaing
    352  * \param ruiParam reference to parameter
    353  * \returns Void
     351 * \param rSymbol                 reference to coeff_abs_level_remaing
     352 * \param rParam                  reference to parameter
     353 * \param useLimitedPrefixLength
     354 * \param maxLog2TrDynamicRange
    354355 */
    355 Void TDecSbac::xReadCoefRemainExGolomb ( UInt &rSymbol, UInt &rParam )
    356 {
    357 
     356#if RExt__DECODER_DEBUG_BIT_STATISTICS
     357Void TDecSbac::xReadCoefRemainExGolomb ( UInt &rSymbol, UInt &rParam, const Bool useLimitedPrefixLength, const Int maxLog2TrDynamicRange, const class TComCodingStatisticsClassType &whichStat )
     358#else
     359Void TDecSbac::xReadCoefRemainExGolomb ( UInt &rSymbol, UInt &rParam, const Bool useLimitedPrefixLength, const Int maxLog2TrDynamicRange )
     360#endif
     361{
    358362  UInt prefix   = 0;
    359363  UInt codeWord = 0;
    360   do
    361   {
    362     prefix++;
    363     m_pcTDecBinIf->decodeBinEP( codeWord );
    364   }
    365   while( codeWord);
     364
     365  if (useLimitedPrefixLength)
     366  {
     367    const UInt longestPossiblePrefix = (32 - (COEF_REMAIN_BIN_REDUCTION + maxLog2TrDynamicRange)) + COEF_REMAIN_BIN_REDUCTION;
     368
     369    do
     370    {
     371      prefix++;
     372      m_pcTDecBinIf->decodeBinEP( codeWord RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(whichStat) );
     373    } while((codeWord != 0) && (prefix < longestPossiblePrefix));
     374  }
     375  else
     376  {
     377    do
     378    {
     379      prefix++;
     380      m_pcTDecBinIf->decodeBinEP( codeWord RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(whichStat) );
     381    } while( codeWord);
     382  }
     383
    366384  codeWord  = 1 - codeWord;
    367385  prefix -= codeWord;
    368386  codeWord=0;
     387
    369388  if (prefix < COEF_REMAIN_BIN_REDUCTION )
    370389  {
    371     m_pcTDecBinIf->decodeBinsEP(codeWord,rParam);
     390    m_pcTDecBinIf->decodeBinsEP(codeWord,rParam RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(whichStat));
    372391    rSymbol = (prefix<<rParam) + codeWord;
    373392  }
     393  else if (useLimitedPrefixLength)
     394  {
     395    const UInt maximumPrefixLength = (32 - (COEF_REMAIN_BIN_REDUCTION + maxLog2TrDynamicRange));
     396
     397    const UInt prefixLength = prefix - COEF_REMAIN_BIN_REDUCTION;
     398    const UInt suffixLength = (prefixLength == maximumPrefixLength) ? (maxLog2TrDynamicRange - rParam) : prefixLength;
     399
     400    m_pcTDecBinIf->decodeBinsEP(codeWord, (suffixLength + rParam) RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(whichStat));
     401
     402    rSymbol = codeWord + ((((1 << prefixLength) - 1) + COEF_REMAIN_BIN_REDUCTION) << rParam);
     403  }
    374404  else
    375405  {
    376     m_pcTDecBinIf->decodeBinsEP(codeWord,prefix-COEF_REMAIN_BIN_REDUCTION+rParam);
     406    m_pcTDecBinIf->decodeBinsEP(codeWord,prefix-COEF_REMAIN_BIN_REDUCTION+rParam RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(whichStat));
    377407    rSymbol = (((1<<(prefix-COEF_REMAIN_BIN_REDUCTION))+COEF_REMAIN_BIN_REDUCTION-1)<<rParam)+codeWord;
    378408  }
    379409}
    380410
    381 #if H_3D_DIM
    382 Void TDecSbac::xReadExGolombLevel( UInt& ruiSymbol, ContextModel& rcSCModel  )
    383 {
    384   UInt uiSymbol;
    385   UInt uiCount = 0;
    386   do
    387   {
    388     m_pcTDecBinIf->decodeBin( uiSymbol, rcSCModel );
    389     uiCount++;
    390   }
    391   while( uiSymbol && ( uiCount != 3 ) );
    392   ruiSymbol = uiCount - 1;
    393 
    394   if( uiSymbol )
    395   {
    396     xReadEpExGolomb( uiSymbol, 0 );
    397     ruiSymbol += uiSymbol + 1;
    398   }
    399 
    400   return;
    401 }
    402 
    403 Void TDecSbac::xParseDimDeltaDC( Pel& rValDeltaDC, UInt uiNumSeg )
    404 {
    405   UInt absValDeltaDC = 0;
    406   xReadExGolombLevel( absValDeltaDC, m_cDdcDataSCModel.get(0, 0, 0) );
    407   rValDeltaDC = (Pel)absValDeltaDC + ( uiNumSeg > 1 ? 0 : 1 );
    408 
    409   if( rValDeltaDC != 0 )
    410   {
    411     UInt uiSign;
    412     m_pcTDecBinIf->decodeBinEP( uiSign );
    413     if ( uiSign )
    414     {
    415       rValDeltaDC = -rValDeltaDC;
    416     }
    417   }
    418 }
    419 
    420 
    421 #if H_3D_DIM_DMM
    422 Void TDecSbac::xParseDmm1WedgeIdx( UInt& ruiTabIdx, Int iNumBit )
    423 {
    424   UInt uiSymbol, uiIdx = 0;
    425   for( Int i = 0; i < iNumBit; i++ )
    426   {
    427     m_pcTDecBinIf->decodeBinEP( uiSymbol );
    428     uiIdx += uiSymbol << i;
    429   }
    430   ruiTabIdx = uiIdx;
    431 }
    432 #endif
    433 
    434 
    435 #endif
    436 /** Parse I_PCM information.
     411/** Parse I_PCM information.
    437412 * \param pcCU
    438  * \param uiAbsPartIdx 
     413 * \param uiAbsPartIdx
    439414 * \param uiDepth
    440415 * \returns Void
    441416 *
    442  * If I_PCM flag indicates that the CU is I_PCM, parse its PCM alignment bits and codes. 
     417 * If I_PCM flag indicates that the CU is I_PCM, parse its PCM alignment bits and codes.
    443418 */
    444419Void TDecSbac::parseIPCMInfo ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
     
    451426  DTRACE_CU("pcm_flag", uiSymbol)
    452427#endif
    453   if (uiSymbol)
     428
     429
     430  if (uiSymbol == 1)
    454431  {
    455432    Bool bIpcmFlag = true;
     433    const TComSPS &sps=*(pcCU->getSlice()->getSPS());
    456434
    457435    pcCU->setPartSizeSubParts  ( SIZE_2Nx2N, uiAbsPartIdx, uiDepth );
    458     pcCU->setSizeSubParts      ( g_uiMaxCUWidth>>uiDepth, g_uiMaxCUHeight>>uiDepth, uiAbsPartIdx, uiDepth );
     436    pcCU->setSizeSubParts      ( sps.getMaxCUWidth()>>uiDepth, sps.getMaxCUHeight()>>uiDepth, uiAbsPartIdx, uiDepth );
    459437    pcCU->setTrIdxSubParts     ( 0, uiAbsPartIdx, uiDepth );
    460438    pcCU->setIPCMFlagSubParts  ( bIpcmFlag, uiAbsPartIdx, uiDepth );
    461439
    462     UInt uiMinCoeffSize = pcCU->getPic()->getMinCUWidth()*pcCU->getPic()->getMinCUHeight();
    463     UInt uiLumaOffset   = uiMinCoeffSize*uiAbsPartIdx;
    464     UInt uiChromaOffset = uiLumaOffset>>2;
    465 
    466     Pel* piPCMSample;
    467     UInt uiWidth;
    468     UInt uiHeight;
    469     UInt uiSampleBits;
    470     UInt uiX, uiY;
    471 
    472     piPCMSample = pcCU->getPCMSampleY() + uiLumaOffset;
    473     uiWidth = pcCU->getWidth(uiAbsPartIdx);
    474     uiHeight = pcCU->getHeight(uiAbsPartIdx);
    475     uiSampleBits = pcCU->getSlice()->getSPS()->getPCMBitDepthLuma();
    476 
    477     for(uiY = 0; uiY < uiHeight; uiY++)
    478     {
    479       for(uiX = 0; uiX < uiWidth; uiX++)
    480       {
    481         UInt uiSample;
    482         m_pcTDecBinIf->xReadPCMCode(uiSampleBits, uiSample);
    483         piPCMSample[uiX] = uiSample;
    484       }
    485       piPCMSample += uiWidth;
    486     }
    487 #if H_3D_DISABLE_CHROMA
    488     if( pcCU->getSlice()->getSPS()->getChromaFormatIdc() != 0 )
    489     {   
    490 #endif
    491       piPCMSample = pcCU->getPCMSampleCb() + uiChromaOffset;
    492       uiWidth = pcCU->getWidth(uiAbsPartIdx)/2;
    493       uiHeight = pcCU->getHeight(uiAbsPartIdx)/2;
    494       uiSampleBits = pcCU->getSlice()->getSPS()->getPCMBitDepthChroma();
    495 
    496       for(uiY = 0; uiY < uiHeight; uiY++)
    497       {
    498         for(uiX = 0; uiX < uiWidth; uiX++)
    499         {
    500           UInt uiSample;
    501           m_pcTDecBinIf->xReadPCMCode(uiSampleBits, uiSample);
    502           piPCMSample[uiX] = uiSample;
    503         }
    504         piPCMSample += uiWidth;
    505       }
    506 
    507       piPCMSample = pcCU->getPCMSampleCr() + uiChromaOffset;
    508       uiWidth = pcCU->getWidth(uiAbsPartIdx)/2;
    509       uiHeight = pcCU->getHeight(uiAbsPartIdx)/2;
    510       uiSampleBits = pcCU->getSlice()->getSPS()->getPCMBitDepthChroma();
    511 
    512       for(uiY = 0; uiY < uiHeight; uiY++)
    513       {
    514         for(uiX = 0; uiX < uiWidth; uiX++)
    515         {
    516           UInt uiSample;
    517           m_pcTDecBinIf->xReadPCMCode(uiSampleBits, uiSample);
    518           piPCMSample[uiX] = uiSample;
    519         }
    520         piPCMSample += uiWidth;
    521       }
    522 #if H_3D_DISABLE_CHROMA
    523     }
    524 #endif
     440    const UInt minCoeffSizeY = pcCU->getPic()->getMinCUWidth() * pcCU->getPic()->getMinCUHeight();
     441    const UInt offsetY       = minCoeffSizeY * uiAbsPartIdx;
     442    for (UInt ch=0; ch < pcCU->getPic()->getNumberValidComponents(); ch++)
     443    {
     444      const ComponentID compID = ComponentID(ch);
     445      const UInt offset = offsetY >> (pcCU->getPic()->getComponentScaleX(compID) + pcCU->getPic()->getComponentScaleY(compID));
     446      Pel * pPCMSample  = pcCU->getPCMSample(compID) + offset;
     447      const UInt width  = pcCU->getWidth (uiAbsPartIdx) >> pcCU->getPic()->getComponentScaleX(compID);
     448      const UInt height = pcCU->getHeight(uiAbsPartIdx) >> pcCU->getPic()->getComponentScaleY(compID);
     449      const UInt sampleBits = pcCU->getSlice()->getSPS()->getPCMBitDepth(toChannelType(compID));
     450      for (UInt y=0; y<height; y++)
     451      {
     452        for (UInt x=0; x<width; x++)
     453        {
     454          UInt sample;
     455          m_pcTDecBinIf->xReadPCMCode(sampleBits, sample);
     456          pPCMSample[x] = sample;
     457        }
     458        pPCMSample += width;
     459      }
     460    }
    525461    m_pcTDecBinIf->start();
    526462  }
     
    530466{
    531467  UInt uiSymbol;
    532   m_pcTDecBinIf->decodeBin( uiSymbol, m_CUTransquantBypassFlagSCModel.get( 0, 0, 0 ) );
     468  m_pcTDecBinIf->decodeBin( uiSymbol, m_CUTransquantBypassFlagSCModel.get( 0, 0, 0 ) RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(STATS__CABAC_BITS__TQ_BYPASS_FLAG) );
    533469#if H_MV_ENC_DEC_TRAC
    534470  DTRACE_CU("cu_transquant_bypass_flag", uiSymbol);
    535471#endif
     472
    536473  pcCU->setCUTransquantBypassSubParts(uiSymbol ? true : false, uiAbsPartIdx, uiDepth);
    537474}
     
    539476/** parse skip flag
    540477 * \param pcCU
    541  * \param uiAbsPartIdx 
     478 * \param uiAbsPartIdx
    542479 * \param uiDepth
    543480 * \returns Void
     
    549486    return;
    550487  }
    551  
     488
    552489  UInt uiSymbol = 0;
    553490  UInt uiCtxSkip = pcCU->getCtxSkipFlag( uiAbsPartIdx );
    554   m_pcTDecBinIf->decodeBin( uiSymbol, m_cCUSkipFlagSCModel.get( 0, 0, uiCtxSkip ) );
     491  m_pcTDecBinIf->decodeBin( uiSymbol, m_cCUSkipFlagSCModel.get( 0, 0, uiCtxSkip ) RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(STATS__CABAC_BITS__SKIP_FLAG) );
    555492#if !H_MV_ENC_DEC_TRAC
    556493  DTRACE_CABAC_VL( g_nSymbolCounter++ );
     
    562499  DTRACE_CABAC_T( "\n");
    563500#endif
    564  
    565501  if( uiSymbol )
    566502  {
     
    568504    pcCU->setPredModeSubParts( MODE_INTER,  uiAbsPartIdx, uiDepth );
    569505    pcCU->setPartSizeSubParts( SIZE_2Nx2N, uiAbsPartIdx, uiDepth );
    570     pcCU->setSizeSubParts( g_uiMaxCUWidth>>uiDepth, g_uiMaxCUHeight>>uiDepth, uiAbsPartIdx, uiDepth );
     506    pcCU->setSizeSubParts( pcCU->getSlice()->getSPS()->getMaxCUWidth()>>uiDepth, pcCU->getSlice()->getSPS()->getMaxCUHeight()>>uiDepth, uiAbsPartIdx, uiDepth );
    571507    pcCU->setMergeFlagSubParts( true , uiAbsPartIdx, 0, uiDepth );
    572508  }
     
    574510  DTRACE_CU("cu_skip_flag", uiSymbol);
    575511#endif
    576 }
    577 #if H_3D
     512
     513}
     514#if NH_3D_DIS
    578515Void TDecSbac::parseDIS( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
    579516{
    580517  pcCU->setDISFlagSubParts( false,        uiAbsPartIdx, uiDepth );
    581518  UInt uiSymbol = 0;
    582   m_pcTDecBinIf->decodeBin( uiSymbol, m_cCUDISFlagSCModel.get( 0, 0, 0 ) );
     519  m_pcTDecBinIf->decodeBin( uiSymbol, m_cCUDISFlagSCModel.get( 0, 0, 0 ) RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(STATS__CABAC_BITS__SKIP_FLAG) );
    583520  if( uiSymbol )
    584521  {
     
    588525    pcCU->setPredModeSubParts( MODE_INTRA,  uiAbsPartIdx, uiDepth );
    589526    pcCU->setPartSizeSubParts( SIZE_2Nx2N, uiAbsPartIdx, uiDepth );
    590     pcCU->setLumaIntraDirSubParts (DC_IDX, uiAbsPartIdx, uiDepth );
    591     pcCU->setSizeSubParts( g_uiMaxCUWidth>>uiDepth, g_uiMaxCUHeight>>uiDepth, uiAbsPartIdx, uiDepth );
     527    pcCU->setIntraDirSubParts(CHANNEL_TYPE_LUMA, DC_IDX, uiAbsPartIdx, uiDepth );
     528    pcCU->setSizeSubParts( pcCU->getSlice()->getSPS()->getMaxCUWidth()>>uiDepth, pcCU->getSlice()->getSPS()->getMaxCUHeight()>>uiDepth, uiAbsPartIdx, uiDepth );
    592529    pcCU->setMergeFlagSubParts( false , uiAbsPartIdx, 0, uiDepth );
    593530    pcCU->setTrIdxSubParts(0, uiAbsPartIdx, uiDepth);
    594     pcCU->setCbfSubParts(0, 1, 1, uiAbsPartIdx, uiDepth);
     531    pcCU->setCbfSubParts(0, COMPONENT_Y, uiAbsPartIdx, uiDepth);
    595532
    596533    UInt uiUnaryIdx = 0;
     
    604541        if ( uiUnaryIdx==0 )
    605542        {
    606           m_pcTDecBinIf->decodeBin( uiSymbol2, m_cCUDISTypeSCModel.get( 0, 0, 0 ) );
     543          m_pcTDecBinIf->decodeBin( uiSymbol2, m_cCUDISTypeSCModel.get( 0, 0, 0 ) RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(STATS__CABAC_BITS__SKIP_FLAG) );
    607544        }
    608545        else
    609546        {
    610           m_pcTDecBinIf->decodeBinEP( uiSymbol2);
     547          m_pcTDecBinIf->decodeBinEP( uiSymbol2 RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(STATS__CABAC_BITS__SKIP_FLAG));
    611548        }
    612549        if( uiSymbol2 == 0 )
     
    616553      }
    617554    }
    618     pcCU->setDISTypeSubParts(uiUnaryIdx, uiAbsPartIdx, 0, uiDepth);
    619   }
    620 }
    621 #endif
     555    pcCU->setDISTypeSubParts((UChar)uiUnaryIdx, uiAbsPartIdx, uiDepth);
     556  }
     557}
     558#endif
     559
     560
    622561/** parse merge flag
    623562 * \param pcCU
    624  * \param uiAbsPartIdx 
     563 * \param uiAbsPartIdx
    625564 * \param uiDepth
    626565 * \param uiPUIdx
     
    630569{
    631570  UInt uiSymbol;
    632   m_pcTDecBinIf->decodeBin( uiSymbol, *m_cCUMergeFlagExtSCModel.get( 0 ) );
     571  m_pcTDecBinIf->decodeBin( uiSymbol, *m_cCUMergeFlagExtSCModel.get( 0 ) RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(STATS__CABAC_BITS__MERGE_FLAG) );
    633572#if H_MV_ENC_DEC_TRAC
    634573  DTRACE_PU("merge_flag", uiSymbol)
    635574#endif
    636575  pcCU->setMergeFlagSubParts( uiSymbol ? true : false, uiAbsPartIdx, uiPUIdx, uiDepth );
    637 
    638576#if !H_MV_ENC_DEC_TRAC
    639577  DTRACE_CABAC_VL( g_nSymbolCounter++ );
     
    641579  DTRACE_CABAC_V( uiSymbol );
    642580  DTRACE_CABAC_T( "\tAddress: " );
    643   DTRACE_CABAC_V( pcCU->getAddr() );
     581  DTRACE_CABAC_V( pcCU->getCtuRsAddr() );
    644582  DTRACE_CABAC_T( "\tuiAbsPartIdx: " );
    645583  DTRACE_CABAC_V( uiAbsPartIdx );
     
    659597      if ( uiUnaryIdx==0 )
    660598      {
    661         m_pcTDecBinIf->decodeBin( uiSymbol, m_cCUMergeIdxExtSCModel.get( 0, 0, 0 ) );
     599        m_pcTDecBinIf->decodeBin( uiSymbol, m_cCUMergeIdxExtSCModel.get( 0, 0, 0 ) RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(STATS__CABAC_BITS__MERGE_INDEX) );
    662600      }
    663601      else
    664602      {
    665         m_pcTDecBinIf->decodeBinEP( uiSymbol );
     603        m_pcTDecBinIf->decodeBinEP( uiSymbol RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(STATS__CABAC_BITS__MERGE_INDEX) );
    666604      }
    667605      if( uiSymbol == 0 )
     
    688626{
    689627  UInt uiSymbol;
    690   xReadUnaryMaxSymbol(uiSymbol, m_cMVPIdxSCModel.get(0), 1, AMVP_MAX_NUM_CANDS-1);
     628  xReadUnaryMaxSymbol(uiSymbol, m_cMVPIdxSCModel.get(0), 1, AMVP_MAX_NUM_CANDS-1 RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(STATS__CABAC_BITS__MVP_IDX) );
    691629  riMVPIdx = uiSymbol;
    692630}
     
    694632Void TDecSbac::parseSplitFlag     ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
    695633{
    696   if( uiDepth == g_uiMaxCUDepth - g_uiAddCUDepth )
     634  if( uiDepth == pcCU->getSlice()->getSPS()->getLog2DiffMaxMinCodingBlockSize() )
    697635  {
    698636    pcCU->setDepthSubParts( uiDepth, uiAbsPartIdx );
    699637    return;
    700638  }
     639#if RExt__DECODER_DEBUG_BIT_STATISTICS
     640  const TComCodingStatisticsClassType ctype(STATS__CABAC_BITS__SPLIT_FLAG, g_aucConvertToBit[pcCU->getSlice()->getSPS()->getMaxCUWidth()>>uiDepth]+2);
     641#endif
    701642
    702643  UInt uiSymbol;
    703 #if H_3D_QTLPC
     644#if NH_3D_QTLPC
    704645  Bool bParseSplitFlag    = true;
    705646  Bool    bLimQtPredFlag = pcCU->getPic()->getSlice(0)->getQtPredFlag();
     
    716657#endif
    717658  {
    718     TComDataCU *pcTextureCU = pcTexture->getCU(pcCU->getAddr());
     659    TComDataCU *pcTextureCU = pcTexture->getCtu(pcCU->getCtuRsAddr());
    719660    assert(pcTextureCU->getDepth(uiAbsPartIdx) >= uiDepth);
    720661    bParseSplitFlag         = (pcTextureCU->getDepth(uiAbsPartIdx) > uiDepth);
     
    724665  {
    725666#endif
    726     m_pcTDecBinIf->decodeBin( uiSymbol, m_cCUSplitFlagSCModel.get( 0, 0, pcCU->getCtxSplitFlag( uiAbsPartIdx, uiDepth ) ) );
     667  m_pcTDecBinIf->decodeBin( uiSymbol, m_cCUSplitFlagSCModel.get( 0, 0, pcCU->getCtxSplitFlag( uiAbsPartIdx, uiDepth ) ) RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(ctype) );
    727668#if H_MV_ENC_DEC_TRAC
    728669    DTRACE_CU("split_cu_flag", uiSymbol);
    729670#else
    730     DTRACE_CABAC_VL( g_nSymbolCounter++ )
    731     DTRACE_CABAC_T( "\tSplitFlag\n" )
    732 #endif
    733 #if H_3D_QTLPC
     671  DTRACE_CABAC_VL( g_nSymbolCounter++ )
     672  DTRACE_CABAC_T( "\tSplitFlag\n" )
     673#endif
     674#if NH_3D_QTLPC
    734675  }
    735676  else
     
    745686/** parse partition size
    746687 * \param pcCU
    747  * \param uiAbsPartIdx 
     688 * \param uiAbsPartIdx
    748689 * \param uiDepth
    749690 * \returns Void
     
    753694  UInt uiSymbol, uiMode = 0;
    754695  PartSize eMode;
    755 
    756 #if H_3D_QTLPC
     696  const UChar cuWidth =UChar(pcCU->getSlice()->getSPS()->getMaxCUWidth()>>uiDepth);
     697  const UChar cuHeight=UChar(pcCU->getSlice()->getSPS()->getMaxCUHeight()>>uiDepth);
     698  const Int log2DiffMaxMinCodingBlockSize = pcCU->getSlice()->getSPS()->getLog2DiffMaxMinCodingBlockSize();
     699
     700#if RExt__DECODER_DEBUG_BIT_STATISTICS
     701  const TComCodingStatisticsClassType ctype(STATS__CABAC_BITS__PART_SIZE, g_aucConvertToBit[cuWidth]+2);
     702#endif
     703
     704  assert ( pcCU->getSlice()->getSPS()->getLog2DiffMaxMinCodingBlockSize() == log2DiffMaxMinCodingBlockSize);
     705
     706#if NH_3D_QTLPC
    757707  Bool bParsePartSize    = true;
    758708
     
    773723#endif
    774724  {
    775     TComDataCU *pcTextureCU = pcTexture->getCU(pcCU->getAddr());
     725    TComDataCU *pcTextureCU = pcTexture->getCtu(pcCU->getCtuRsAddr());
    776726    assert(pcTextureCU->getDepth(uiAbsPartIdx) >= uiDepth);
    777727    if(pcTextureCU->getDepth(uiAbsPartIdx) == uiDepth )
     
    788738#endif
    789739
    790 
    791740  if ( pcCU->isIntra( uiAbsPartIdx ) )
    792741  {
    793 #if H_3D_QTLPC
     742#if NH_3D_QTLPC
    794743    if(bParsePartSize)
    795744    {
    796745#endif
    797       uiSymbol = 1;
    798       if( uiDepth == g_uiMaxCUDepth - g_uiAddCUDepth )
    799       {
    800         m_pcTDecBinIf->decodeBin( uiSymbol, m_cCUPartSizeSCModel.get( 0, 0, 0) );
     746    uiSymbol = 1;
     747    if( uiDepth == log2DiffMaxMinCodingBlockSize )
     748    {
     749      m_pcTDecBinIf->decodeBin( uiSymbol, m_cCUPartSizeSCModel.get( 0, 0, 0) RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(ctype) );
    801750#if H_MV_ENC_DEC_TRAC         
    802751        DTRACE_CU("part_mode", uiSymbol)
    803752#endif       
    804       }
    805       eMode = uiSymbol ? SIZE_2Nx2N : SIZE_NxN;
    806 #if H_3D_QTLPC
    807     }
    808 #endif
    809     UInt uiTrLevel = 0;   
     753    }
     754    eMode = uiSymbol ? SIZE_2Nx2N : SIZE_NxN;
     755#if NH_3D_QTLPC
     756    }
     757#endif
     758    UInt uiTrLevel = 0;
    810759    UInt uiWidthInBit  = g_aucConvertToBit[pcCU->getWidth(uiAbsPartIdx)]+2;
    811760    UInt uiTrSizeInBit = g_aucConvertToBit[pcCU->getSlice()->getSPS()->getMaxTrSize()]+2;
     
    822771  else
    823772  {
    824 #if H_3D_QTLPC
     773#if NH_3D_QTLPC
    825774    if(bParsePartSize)
    826775    {
     
    828777      {
    829778#endif
    830         UInt uiMaxNumBits = 2;
    831         if( uiDepth == g_uiMaxCUDepth - g_uiAddCUDepth && !( (g_uiMaxCUWidth>>uiDepth) == 8 && (g_uiMaxCUHeight>>uiDepth) == 8 ) )
     779    UInt uiMaxNumBits = 2;
     780
     781    if( uiDepth == log2DiffMaxMinCodingBlockSize && !( cuWidth == 8 && cuHeight == 8 ) )
     782    {
     783      uiMaxNumBits ++;
     784    }
     785
     786    for ( UInt ui = 0; ui < uiMaxNumBits; ui++ )
     787    {
     788      m_pcTDecBinIf->decodeBin( uiSymbol, m_cCUPartSizeSCModel.get( 0, 0, ui) RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(ctype) );
     789      if ( uiSymbol )
     790      {
     791        break;
     792      }
     793      uiMode++;
     794    }
     795    eMode = (PartSize) uiMode;
     796    if ( pcCU->getSlice()->getSPS()->getUseAMP() && uiDepth < log2DiffMaxMinCodingBlockSize )
     797    {
     798      if (eMode == SIZE_2NxN)
     799      {
     800        m_pcTDecBinIf->decodeBin(uiSymbol, m_cCUPartSizeSCModel.get( 0, 0, 3 ) RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(ctype));
     801        if (uiSymbol == 0)
     802        {
     803          m_pcTDecBinIf->decodeBinEP(uiSymbol RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(ctype) );
     804          eMode = (uiSymbol == 0? SIZE_2NxnU : SIZE_2NxnD);
     805        }
     806      }
     807      else if (eMode == SIZE_Nx2N)
     808      {
     809        m_pcTDecBinIf->decodeBin(uiSymbol, m_cCUPartSizeSCModel.get( 0, 0, 3 ) RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(ctype) );
     810        if (uiSymbol == 0)
     811        {
     812          m_pcTDecBinIf->decodeBinEP(uiSymbol RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(ctype) );
     813          eMode = (uiSymbol == 0? SIZE_nLx2N : SIZE_nRx2N);
     814        }
     815      }
     816    }
     817#if NH_3D_QTLPC
     818      }
     819      else if(uiTexturePart == SIZE_2NxN || uiTexturePart == SIZE_2NxnU || uiTexturePart == SIZE_2NxnD)
     820      {
     821        UInt uiMaxNumBits = 1;
     822        if ( ( pcCU->getSlice()->getSPS()->getUseAMP() && uiDepth < log2DiffMaxMinCodingBlockSize ) && uiDepth < log2DiffMaxMinCodingBlockSize )
    832823        {
    833824          uiMaxNumBits ++;
     
    835826        for ( UInt ui = 0; ui < uiMaxNumBits; ui++ )
    836827        {
    837           m_pcTDecBinIf->decodeBin( uiSymbol, m_cCUPartSizeSCModel.get( 0, 0, ui) );
     828          m_pcTDecBinIf->decodeBin( uiSymbol, m_cCUPartSizeSCModel.get( 0, 0, ui) RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(ctype) );
    838829          if ( uiSymbol )
    839830          {
     
    843834        }
    844835        eMode = (PartSize) uiMode;
    845         if ( pcCU->getSlice()->getSPS()->getAMPAcc( uiDepth ) )
    846         {
    847           if (eMode == SIZE_2NxN)
    848           {
    849             m_pcTDecBinIf->decodeBin(uiSymbol, m_cCUPartSizeSCModel.get( 0, 0, 3 ));
    850             if (uiSymbol == 0)
    851             {
    852               m_pcTDecBinIf->decodeBinEP(uiSymbol);
    853               eMode = (uiSymbol == 0? SIZE_2NxnU : SIZE_2NxnD);
    854             }
    855           }
    856           else if (eMode == SIZE_Nx2N)
    857           {
    858             m_pcTDecBinIf->decodeBin(uiSymbol, m_cCUPartSizeSCModel.get( 0, 0, 3 ));
    859             if (uiSymbol == 0)
    860             {
    861               m_pcTDecBinIf->decodeBinEP(uiSymbol);
    862               eMode = (uiSymbol == 0? SIZE_nLx2N : SIZE_nRx2N);
    863             }
    864           }
    865         }
    866 #if H_3D_QTLPC
    867       }
    868       else if(uiTexturePart == SIZE_2NxN || uiTexturePart == SIZE_2NxnU || uiTexturePart == SIZE_2NxnD)
     836        if(uiMode && ( ( pcCU->getSlice()->getSPS()->getUseAMP() && uiDepth < log2DiffMaxMinCodingBlockSize ) && uiDepth < log2DiffMaxMinCodingBlockSize ) && uiSymbol==1 )
     837        {
     838          eMode = SIZE_2NxN;
     839        }
     840        else if (uiMode && (( ( pcCU->getSlice()->getSPS()->getUseAMP() && uiDepth < log2DiffMaxMinCodingBlockSize ) && uiDepth < log2DiffMaxMinCodingBlockSize )==0)  && uiSymbol==0)
     841        {
     842          eMode = SIZE_2NxN;
     843        }
     844        else if (uiMode && ( ( pcCU->getSlice()->getSPS()->getUseAMP() && uiDepth < log2DiffMaxMinCodingBlockSize ) && uiDepth < log2DiffMaxMinCodingBlockSize ) && uiSymbol==0)
     845        {
     846          m_pcTDecBinIf->decodeBinEP(uiSymbol RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(ctype));
     847          eMode = (uiSymbol == 0? SIZE_2NxnU : SIZE_2NxnD);
     848        }
     849      }
     850      else if(uiTexturePart == SIZE_Nx2N|| uiTexturePart==SIZE_nLx2N || uiTexturePart==SIZE_nRx2N)
    869851      {
    870852        UInt uiMaxNumBits = 1;
    871         if ( pcCU->getSlice()->getSPS()->getAMPAcc( uiDepth ) )
     853        if (  ( pcCU->getSlice()->getSPS()->getUseAMP() && uiDepth < log2DiffMaxMinCodingBlockSize ) && uiDepth < log2DiffMaxMinCodingBlockSize )
    872854        {
    873855          uiMaxNumBits ++;
     
    875857        for ( UInt ui = 0; ui < uiMaxNumBits; ui++ )
    876858        {
    877           m_pcTDecBinIf->decodeBin( uiSymbol, m_cCUPartSizeSCModel.get( 0, 0, ui) );
     859          m_pcTDecBinIf->decodeBin( uiSymbol, m_cCUPartSizeSCModel.get( 0, 0, ui) RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(ctype));
    878860          if ( uiSymbol )
    879861          {
     
    883865        }
    884866        eMode = (PartSize) uiMode;
    885         if(uiMode && pcCU->getSlice()->getSPS()->getAMPAcc( uiDepth ) && uiSymbol==1 )
    886         {
    887           eMode = SIZE_2NxN;
    888         }
    889         else if (uiMode && pcCU->getSlice()->getSPS()->getAMPAcc( uiDepth )==0  && uiSymbol==0)
    890         {
    891           eMode = SIZE_2NxN;
    892         }
    893         else if (uiMode && pcCU->getSlice()->getSPS()->getAMPAcc( uiDepth ) && uiSymbol==0)
    894         {
    895           m_pcTDecBinIf->decodeBinEP(uiSymbol);
    896           eMode = (uiSymbol == 0? SIZE_2NxnU : SIZE_2NxnD);
    897         }
    898       }
    899       else if(uiTexturePart == SIZE_Nx2N|| uiTexturePart==SIZE_nLx2N || uiTexturePart==SIZE_nRx2N)
    900       {
    901         UInt uiMaxNumBits = 1;
    902         if ( pcCU->getSlice()->getSPS()->getAMPAcc( uiDepth ) )
    903         {
    904           uiMaxNumBits ++;
    905         }
    906         for ( UInt ui = 0; ui < uiMaxNumBits; ui++ )
    907         {
    908           m_pcTDecBinIf->decodeBin( uiSymbol, m_cCUPartSizeSCModel.get( 0, 0, ui) );
    909           if ( uiSymbol )
    910           {
    911             break;
    912           }
    913           uiMode++;
    914         }
    915         eMode = (PartSize) uiMode;
    916         if(uiMode && pcCU->getSlice()->getSPS()->getAMPAcc( uiDepth ) && uiSymbol==1 )
     867        if(uiMode && ( ( pcCU->getSlice()->getSPS()->getUseAMP() && uiDepth < log2DiffMaxMinCodingBlockSize ) && uiDepth < log2DiffMaxMinCodingBlockSize ) && uiSymbol==1 )
    917868        {
    918869          eMode = SIZE_Nx2N;
    919870        }
    920         else if (uiMode && pcCU->getSlice()->getSPS()->getAMPAcc( uiDepth )==0  && uiSymbol==0)
     871        else if (uiMode && (( ( pcCU->getSlice()->getSPS()->getUseAMP() && uiDepth < log2DiffMaxMinCodingBlockSize ) && uiDepth < log2DiffMaxMinCodingBlockSize )==0)  && uiSymbol==0)
    921872        {
    922873          eMode = SIZE_Nx2N;
    923874        }
    924         else if (uiMode && pcCU->getSlice()->getSPS()->getAMPAcc( uiDepth ) && uiSymbol==0)
    925         {
    926           m_pcTDecBinIf->decodeBinEP(uiSymbol);
     875        else if (uiMode && ( ( pcCU->getSlice()->getSPS()->getUseAMP() && uiDepth < log2DiffMaxMinCodingBlockSize ) && uiDepth < log2DiffMaxMinCodingBlockSize ) && uiSymbol==0)
     876        {
     877          m_pcTDecBinIf->decodeBinEP(uiSymbol RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(ctype));
    927878          eMode = (uiSymbol == 0? SIZE_nLx2N : SIZE_nRx2N);
    928879        }
     
    936887      DTRACE_CU("part_mode", eMode )
    937888#endif
    938 #if H_3D_QTLPC
     889#if NH_3D_QTLPC
    939890    }
    940891#endif
    941892  }
    942893  pcCU->setPartSizeSubParts( eMode, uiAbsPartIdx, uiDepth );
    943   pcCU->setSizeSubParts( g_uiMaxCUWidth>>uiDepth, g_uiMaxCUHeight>>uiDepth, uiAbsPartIdx, uiDepth );
    944 }
     894  pcCU->setSizeSubParts( cuWidth, cuHeight, uiAbsPartIdx, uiDepth );
     895}
     896
    945897
    946898/** parse prediction mode
    947899 * \param pcCU
    948  * \param uiAbsPartIdx 
     900 * \param uiAbsPartIdx
    949901 * \param uiDepth
    950902 * \returns Void
     
    957909    return;
    958910  }
    959  
     911
    960912  UInt uiSymbol;
    961913  Int  iPredMode = MODE_INTER;
    962   m_pcTDecBinIf->decodeBin( uiSymbol, m_cCUPredModeSCModel.get( 0, 0, 0 ) );
     914  m_pcTDecBinIf->decodeBin( uiSymbol, m_cCUPredModeSCModel.get( 0, 0, 0 ) RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(STATS__CABAC_BITS__PRED_MODE) );
    963915  iPredMode += uiSymbol;
    964916#if H_MV_ENC_DEC_TRAC         
     
    968920}
    969921
     922
    970923Void TDecSbac::parseIntraDirLumaAng  ( TComDataCU* pcCU, UInt absPartIdx, UInt depth )
    971924{
    972925  PartSize mode = pcCU->getPartitionSize( absPartIdx );
    973926  UInt partNum = mode==SIZE_NxN?4:1;
    974   UInt partOffset = ( pcCU->getPic()->getNumPartInCU() >> ( pcCU->getDepth(absPartIdx) << 1 ) ) >> 2;
     927  UInt partOffset = ( pcCU->getPic()->getNumPartitionsInCtu() >> ( pcCU->getDepth(absPartIdx) << 1 ) ) >> 2;
    975928  UInt mpmPred[4],symbol;
    976   Int j,intraPredMode;   
     929  Int j,intraPredMode;
    977930  if (mode==SIZE_NxN)
    978931  {
    979932    depth++;
    980933  }
     934#if RExt__DECODER_DEBUG_BIT_STATISTICS
     935  const TComCodingStatisticsClassType ctype(STATS__CABAC_BITS__INTRA_DIR_ANG, g_aucConvertToBit[pcCU->getSlice()->getSPS()->getMaxCUWidth()>>depth]+2, CHANNEL_TYPE_LUMA);
     936#endif
    981937  for (j=0;j<partNum;j++)
    982938  {
    983 #if H_3D_DIM
     939#if NH_3D_DMM
    984940    if( pcCU->getSlice()->getIntraSdcWedgeFlag() || pcCU->getSlice()->getIntraContourFlag() )
    985941    {
    986       parseIntraDepth( pcCU, absPartIdx+partOffset*j, depth );
    987     }
    988     if( pcCU->getLumaIntraDir( absPartIdx+partOffset*j ) < NUM_INTRA_MODE )
    989     {
    990 #endif
    991       m_pcTDecBinIf->decodeBin( symbol, m_cCUIntraPredSCModel.get( 0, 0, 0) );
    992       mpmPred[j] = symbol;
     942      xParseIntraDepthMode( pcCU, absPartIdx+partOffset*j, depth );
     943      xParseDmmData       ( pcCU, absPartIdx+partOffset*j, depth );
     944    }
     945    if( pcCU->getIntraDir( CHANNEL_TYPE_LUMA, absPartIdx+partOffset*j ) < NUM_INTRA_MODE )
     946    {
     947#endif
     948    m_pcTDecBinIf->decodeBin( symbol, m_cCUIntraPredSCModel.get( 0, 0, 0) RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(ctype) );
     949    mpmPred[j] = symbol;
    993950#if H_MV_ENC_DEC_TRAC         
    994951      DTRACE_CU("prev_intra_luma_pred_flag", symbol)
    995952#endif
    996 #if H_3D_DIM
     953#if NH_3D_DMM
    997954    }
    998955#endif
     
    1000957  for (j=0;j<partNum;j++)
    1001958  {
    1002 #if H_3D_DIM
    1003     if( pcCU->getLumaIntraDir( absPartIdx+partOffset*j ) < NUM_INTRA_MODE )
    1004     {
    1005 #endif
    1006       Int preds[3] = {-1, -1, -1};
    1007       Int predNum = pcCU->getIntraDirLumaPredictor(absPartIdx+partOffset*j, preds); 
    1008       if (mpmPred[j])
    1009       {
    1010         m_pcTDecBinIf->decodeBinEP( symbol );
    1011         if (symbol)
    1012         {
    1013           m_pcTDecBinIf->decodeBinEP( symbol );
    1014           symbol++;
    1015         }
     959#if NH_3D_DMM
     960    if( pcCU->getIntraDir( CHANNEL_TYPE_LUMA, absPartIdx+partOffset*j ) < NUM_INTRA_MODE )
     961    {
     962#endif
     963    Int preds[NUM_MOST_PROBABLE_MODES] = {-1, -1, -1};
     964    pcCU->getIntraDirPredictor(absPartIdx+partOffset*j, preds, COMPONENT_Y);
     965    if (mpmPred[j])
     966    {
     967      m_pcTDecBinIf->decodeBinEP( symbol RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(ctype) );
     968      if (symbol)
     969      {
     970        m_pcTDecBinIf->decodeBinEP( symbol RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(ctype) );
     971        symbol++;
     972      }
    1016973#if H_MV_ENC_DEC_TRAC         
    1017974        DTRACE_CU("mpm_idx", symbol)
    1018975#endif
    1019           intraPredMode = preds[symbol];
    1020       }
    1021       else
    1022       {
    1023         m_pcTDecBinIf->decodeBinsEP( symbol, 5 );
    1024         intraPredMode = symbol;
     976      intraPredMode = preds[symbol];
     977    }
     978    else
     979    {
     980      m_pcTDecBinIf->decodeBinsEP( symbol, 5 RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(ctype) );
     981      intraPredMode = symbol;
    1025982#if H_MV_ENC_DEC_TRAC         
    1026983        DTRACE_CU("rem_intra_luma_pred_mode", symbol)
    1027984#endif       
    1028           //postponed sorting of MPMs (only in remaining branch)
    1029           if (preds[0] > preds[1])
    1030           {
    1031             std::swap(preds[0], preds[1]);
    1032           }
    1033           if (preds[0] > preds[2])
    1034           {
    1035             std::swap(preds[0], preds[2]);
    1036           }
    1037           if (preds[1] > preds[2])
    1038           {
    1039             std::swap(preds[1], preds[2]);
    1040           }
    1041           for ( Int i = 0; i < predNum; i++ )
    1042           {
    1043             intraPredMode += ( intraPredMode >= preds[i] );
    1044           }
    1045       }
    1046       pcCU->setLumaIntraDirSubParts( (UChar)intraPredMode, absPartIdx+partOffset*j, depth );
    1047 #if H_3D_DIM
    1048     }
    1049 #endif
    1050   }
    1051 }
     985
     986      //postponed sorting of MPMs (only in remaining branch)
     987      if (preds[0] > preds[1])
     988      {
     989        std::swap(preds[0], preds[1]);
     990      }
     991      if (preds[0] > preds[2])
     992      {
     993        std::swap(preds[0], preds[2]);
     994      }
     995      if (preds[1] > preds[2])
     996      {
     997        std::swap(preds[1], preds[2]);
     998      }
     999      for ( UInt i = 0; i < NUM_MOST_PROBABLE_MODES; i++ )
     1000      {
     1001        intraPredMode += ( intraPredMode >= preds[i] );
     1002      }
     1003    }
     1004    pcCU->setIntraDirSubParts(CHANNEL_TYPE_LUMA, (UChar)intraPredMode, absPartIdx+partOffset*j, depth );
     1005#if NH_3D_DMM
     1006    }
     1007#endif
     1008  }
     1009}
     1010
    10521011
    10531012Void TDecSbac::parseIntraDirChroma( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
    10541013{
    10551014  UInt uiSymbol;
    1056 
    1057   m_pcTDecBinIf->decodeBin( uiSymbol, m_cCUChromaPredSCModel.get( 0, 0, 0 ) );
    1058 
     1015#if RExt__DECODER_DEBUG_BIT_STATISTICS
     1016  const TComCodingStatisticsClassType ctype(STATS__CABAC_BITS__INTRA_DIR_ANG, g_aucConvertToBit[pcCU->getSlice()->getSPS()->getMaxCUWidth()>>uiDepth]+2, CHANNEL_TYPE_CHROMA);
     1017#endif
     1018
     1019  m_pcTDecBinIf->decodeBin( uiSymbol, m_cCUChromaPredSCModel.get( 0, 0, 0 ) RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(ctype) );
    10591020  if( uiSymbol == 0 )
    10601021  {
     
    10621023    DTRACE_CU("intra_chroma_pred_mode", uiSymbol )
    10631024#endif       
    1064       uiSymbol = DM_CHROMA_IDX;
    1065   }
    1066   else
    1067   {
    1068     {
    1069       UInt uiIPredMode;
    1070       m_pcTDecBinIf->decodeBinsEP( uiIPredMode, 2 );
     1025    uiSymbol = DM_CHROMA_IDX;
     1026  }
     1027  else
     1028  {
     1029    UInt uiIPredMode;
     1030    m_pcTDecBinIf->decodeBinsEP( uiIPredMode, 2 RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(ctype) );
    10711031#if H_MV_ENC_DEC_TRAC         
    10721032      DTRACE_CU("intra_chroma_pred_mode", uiIPredMode )
    10731033#endif       
    1074         UInt uiAllowedChromaDir[ NUM_CHROMA_MODE ];
    1075       pcCU->getAllowedChromaDir( uiAbsPartIdx, uiAllowedChromaDir );
    1076       uiSymbol = uiAllowedChromaDir[ uiIPredMode ];
    1077     }
    1078   }
    1079   pcCU->setChromIntraDirSubParts( uiSymbol, uiAbsPartIdx, uiDepth );
    1080   return;
    1081 }
    1082 
    1083 #if H_3D_DIM
    1084 Void TDecSbac::parseIntraDepth( TComDataCU* pcCU, UInt absPartIdx, UInt depth )
    1085 {
    1086   parseIntraDepthMode( pcCU, absPartIdx, depth );
    1087 
    1088   UInt dir     = pcCU->getLumaIntraDir( absPartIdx );
    1089   UInt dimType = getDimType( dir );
    1090 
    1091   switch( dimType )
    1092   {
    1093 #if H_3D_DIM_DMM
    1094   case( DMM1_IDX ):
    1095     {
    1096       UInt uiTabIdx = 0;
    1097       xParseDmm1WedgeIdx( uiTabIdx, g_dmm1TabIdxBits[pcCU->getIntraSizeIdx(absPartIdx)] );
    1098 
    1099       assert( uiTabIdx < g_dmmWedgeLists[ g_aucConvertToBit[ pcCU->getDMM1BasePatternWidth( pcCU->getWidth( absPartIdx ) )]].size());
    1100 
    1101       pcCU->setDmmWedgeTabIdxSubParts( uiTabIdx, dimType, absPartIdx, depth );
    1102     } break;
    1103   case( DMM4_IDX ): break;
    1104 #endif
    1105   default: break;
    1106   }
    1107 
    1108   pcCU->setLumaIntraDirSubParts( (UChar)dir, absPartIdx, depth );
    1109 }
    1110 
    1111 Void TDecSbac::parseIntraDepthMode( TComDataCU* pcCU, UInt absPartIdx, UInt depth )
    1112 {
    1113   UInt uiSymbol, uiIsDimMode;
    1114 
    1115   if( ( pcCU->getSlice()->getSPS()->getMaxCUWidth() >> pcCU->getDepth( absPartIdx ) ) < 64 ) //DMM and HEVC intra modes are both allowed
    1116   {
    1117     m_pcTDecBinIf->decodeBin( uiSymbol, m_cAngleFlagSCModel.get( 0, 0, 0 ) );
    1118   }
    1119   else
    1120   {
    1121     uiSymbol = 1;
    1122   }
    1123   uiIsDimMode = uiSymbol ? 0 : 1;
    1124   pcCU->setLumaIntraDirSubParts( 0, absPartIdx, depth );
    1125 
    1126   //decode DMM index
    1127   if( uiIsDimMode )
    1128   {
    1129     if( pcCU->getSlice()->getIntraSdcWedgeFlag() && pcCU->getSlice()->getIntraContourFlag() )
    1130     {
    1131       m_pcTDecBinIf->decodeBin( uiSymbol, m_cDepthIntraModeSCModel.get( 0, 0, 0 ) );
    1132       if( !uiSymbol )
    1133       {
    1134         pcCU->setLumaIntraDirSubParts( DIM_OFFSET, absPartIdx, depth );
    1135       }
    1136       else
    1137       {
    1138         pcCU->setLumaIntraDirSubParts( ( 1+ DIM_OFFSET ), absPartIdx, depth );
    1139       }
    1140     }
    1141     else if ( pcCU->getSlice()->getIntraSdcWedgeFlag() )
    1142     {
    1143       pcCU->setLumaIntraDirSubParts( DIM_OFFSET, absPartIdx, depth );
    1144     }
    1145     else if( pcCU->getSlice()->getIntraContourFlag() )
    1146     {
    1147       pcCU->setLumaIntraDirSubParts( ( 1+ DIM_OFFSET ), absPartIdx, depth );
    1148     }
    1149   }
    1150 }
    1151 #endif
     1034    UInt uiAllowedChromaDir[ NUM_CHROMA_MODE ];
     1035    pcCU->getAllowedChromaDir( uiAbsPartIdx, uiAllowedChromaDir );
     1036    uiSymbol = uiAllowedChromaDir[ uiIPredMode ];
     1037  }
     1038
     1039  pcCU->setIntraDirSubParts( CHANNEL_TYPE_CHROMA, uiSymbol, uiAbsPartIdx, uiDepth );
     1040}
    11521041
    11531042Void TDecSbac::parseInterDir( TComDataCU* pcCU, UInt& ruiInterDir, UInt uiAbsPartIdx )
     
    11561045  const UInt uiCtx = pcCU->getCtxInterDir( uiAbsPartIdx );
    11571046  ContextModel *pCtx = m_cCUInterDirSCModel.get( 0 );
     1047
    11581048  uiSymbol = 0;
    11591049  if (pcCU->getPartitionSize(uiAbsPartIdx) == SIZE_2Nx2N || pcCU->getHeight(uiAbsPartIdx) != 8 )
    11601050  {
    1161     m_pcTDecBinIf->decodeBin( uiSymbol, *( pCtx + uiCtx ) );
     1051    m_pcTDecBinIf->decodeBin( uiSymbol, *( pCtx + uiCtx ) RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(STATS__CABAC_BITS__INTER_DIR) );
    11621052  }
    11631053
     
    11681058  else
    11691059  {
    1170     m_pcTDecBinIf->decodeBin( uiSymbol, *( pCtx + 4 ) );
     1060    m_pcTDecBinIf->decodeBin( uiSymbol, *( pCtx + 4 ) RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(STATS__CABAC_BITS__INTER_DIR) );
    11711061    assert(uiSymbol == 0 || uiSymbol == 1);
    11721062  }
     
    11841074{
    11851075  UInt uiSymbol;
    1186   {
    1187     ContextModel *pCtx = m_cCURefPicSCModel.get( 0 );
    1188     m_pcTDecBinIf->decodeBin( uiSymbol, *pCtx );
    1189 
    1190     if( uiSymbol )
    1191     {
    1192       UInt uiRefNum = pcCU->getSlice()->getNumRefIdx( eRefList ) - 2;
    1193       pCtx++;
    1194       UInt ui;
    1195       for( ui = 0; ui < uiRefNum; ++ui )
    1196       {
    1197         if( ui == 0 )
    1198         {
    1199           m_pcTDecBinIf->decodeBin( uiSymbol, *pCtx );
    1200         }
    1201         else
    1202         {
    1203           m_pcTDecBinIf->decodeBinEP( uiSymbol );
    1204         }
    1205         if( uiSymbol == 0 )
    1206         {
    1207           break;
    1208         }
    1209       }
    1210       uiSymbol = ui + 1;
    1211     }
    1212     riRefFrmIdx = uiSymbol;
    1213   }
    1214 
     1076
     1077  ContextModel *pCtx = m_cCURefPicSCModel.get( 0 );
     1078  m_pcTDecBinIf->decodeBin( uiSymbol, *pCtx RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(STATS__CABAC_BITS__REF_FRM_IDX) );
     1079
     1080  if( uiSymbol )
     1081  {
     1082    UInt uiRefNum = pcCU->getSlice()->getNumRefIdx( eRefList ) - 2;
     1083    pCtx++;
     1084    UInt ui;
     1085    for( ui = 0; ui < uiRefNum; ++ui )
     1086    {
     1087      if( ui == 0 )
     1088      {
     1089        m_pcTDecBinIf->decodeBin( uiSymbol, *pCtx RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(STATS__CABAC_BITS__REF_FRM_IDX) );
     1090      }
     1091      else
     1092      {
     1093        m_pcTDecBinIf->decodeBinEP( uiSymbol RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(STATS__CABAC_BITS__REF_FRM_IDX) );
     1094      }
     1095      if( uiSymbol == 0 )
     1096      {
     1097        break;
     1098      }
     1099    }
     1100    uiSymbol = ui + 1;
     1101  }
     1102  riRefFrmIdx = uiSymbol;
    12151103#if H_MV_ENC_DEC_TRAC
    12161104#if ENC_DEC_TRACE
     
    12251113#endif
    12261114#endif
     1115
    12271116  return;
    12281117}
     
    12441133  else
    12451134  {
    1246     m_pcTDecBinIf->decodeBin( uiHorAbs, *pCtx );
    1247     m_pcTDecBinIf->decodeBin( uiVerAbs, *pCtx );
     1135    m_pcTDecBinIf->decodeBin( uiHorAbs, *pCtx RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(STATS__CABAC_BITS__MVD) );
     1136    m_pcTDecBinIf->decodeBin( uiVerAbs, *pCtx RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(STATS__CABAC_BITS__MVD) );
    12481137
    12491138    const Bool bHorAbsGr0 = uiHorAbs != 0;
     
    12531142    if( bHorAbsGr0 )
    12541143    {
    1255       m_pcTDecBinIf->decodeBin( uiSymbol, *pCtx );
     1144      m_pcTDecBinIf->decodeBin( uiSymbol, *pCtx RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(STATS__CABAC_BITS__MVD) );
    12561145      uiHorAbs += uiSymbol;
    12571146    }
     
    12591148    if( bVerAbsGr0 )
    12601149    {
    1261       m_pcTDecBinIf->decodeBin( uiSymbol, *pCtx );
     1150      m_pcTDecBinIf->decodeBin( uiSymbol, *pCtx RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(STATS__CABAC_BITS__MVD) );
    12621151      uiVerAbs += uiSymbol;
    12631152    }
     
    12671156      if( 2 == uiHorAbs )
    12681157      {
    1269         xReadEpExGolomb( uiSymbol, 1 );
     1158        xReadEpExGolomb( uiSymbol, 1 RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(STATS__CABAC_BITS__MVD_EP) );
    12701159        uiHorAbs += uiSymbol;
    12711160      }
    12721161
    1273       m_pcTDecBinIf->decodeBinEP( uiHorSign );
     1162      m_pcTDecBinIf->decodeBinEP( uiHorSign RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(STATS__CABAC_BITS__MVD_EP) );
    12741163    }
    12751164
     
    12781167      if( 2 == uiVerAbs )
    12791168      {
    1280         xReadEpExGolomb( uiSymbol, 1 );
     1169        xReadEpExGolomb( uiSymbol, 1 RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(STATS__CABAC_BITS__MVD_EP) );
    12811170        uiVerAbs += uiSymbol;
    12821171      }
    12831172
    1284       m_pcTDecBinIf->decodeBinEP( uiVerSign );
     1173      m_pcTDecBinIf->decodeBinEP( uiVerSign RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(STATS__CABAC_BITS__MVD_EP) );
    12851174    }
    12861175
     
    12921181}
    12931182
     1183Void TDecSbac::parseCrossComponentPrediction( TComTU &rTu, ComponentID compID )
     1184{
     1185  TComDataCU *pcCU = rTu.getCU();
     1186
     1187  if( isLuma(compID) || !pcCU->getSlice()->getPPS()->getPpsRangeExtension().getCrossComponentPredictionEnabledFlag() )
     1188  {
     1189    return;
     1190  }
     1191
     1192  const UInt uiAbsPartIdx = rTu.GetAbsPartIdxTU();
     1193
     1194  if (!pcCU->isIntra(uiAbsPartIdx) || (pcCU->getIntraDir( CHANNEL_TYPE_CHROMA, uiAbsPartIdx ) == DM_CHROMA_IDX))
     1195  {
     1196    Char alpha  = 0;
     1197    UInt symbol = 0;
     1198
     1199    DTRACE_CABAC_VL( g_nSymbolCounter++ )
     1200    DTRACE_CABAC_T("\tparseCrossComponentPrediction()")
     1201    DTRACE_CABAC_T( "\tAddr=" )
     1202    DTRACE_CABAC_V( compID )
     1203    DTRACE_CABAC_T( "\tuiAbsPartIdx=" )
     1204    DTRACE_CABAC_V( uiAbsPartIdx )
     1205#if RExt__DECODER_DEBUG_BIT_STATISTICS
     1206    TComCodingStatisticsClassType ctype(STATS__CABAC_BITS__CROSS_COMPONENT_PREDICTION, (g_aucConvertToBit[rTu.getRect(compID).width] + 2), compID);
     1207#endif
     1208    ContextModel *pCtx = m_cCrossComponentPredictionSCModel.get(0, 0) + ((compID == COMPONENT_Cr) ? (NUM_CROSS_COMPONENT_PREDICTION_CTX >> 1) : 0);
     1209    m_pcTDecBinIf->decodeBin( symbol, pCtx[0] RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(ctype) );
     1210
     1211    if(symbol != 0)
     1212    {
     1213      // Cross-component prediction alpha is non-zero.
     1214      UInt sign = 0;
     1215      m_pcTDecBinIf->decodeBin( symbol, pCtx[1] RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(ctype) );
     1216
     1217      if (symbol != 0)
     1218      {
     1219        // alpha is 2 (symbol=1), 4(symbol=2) or 8(symbol=3).
     1220        // Read up to two more bits
     1221        xReadUnaryMaxSymbol( symbol, (pCtx + 2), 1, 2 RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(ctype) );
     1222        symbol += 1;
     1223      }
     1224      m_pcTDecBinIf->decodeBin( sign, pCtx[4] RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(ctype) );
     1225
     1226      alpha = (sign != 0) ? -(1 << symbol) : (1 << symbol);
     1227    }
     1228    DTRACE_CABAC_T( "\tAlpha=" )
     1229    DTRACE_CABAC_V( alpha )
     1230    DTRACE_CABAC_T( "\n" )
     1231
     1232    pcCU->setCrossComponentPredictionAlphaPartRange( alpha, compID, uiAbsPartIdx, rTu.GetAbsPartIdxNumParts( compID ) );
     1233  }
     1234}
    12941235
    12951236Void TDecSbac::parseTransformSubdivFlag( UInt& ruiSubdivFlag, UInt uiLog2TransformBlockSize )
    12961237{
    1297   m_pcTDecBinIf->decodeBin( ruiSubdivFlag, m_cCUTransSubdivFlagSCModel.get( 0, 0, uiLog2TransformBlockSize ) );
     1238  m_pcTDecBinIf->decodeBin( ruiSubdivFlag, m_cCUTransSubdivFlagSCModel.get( 0, 0, uiLog2TransformBlockSize )
     1239      RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(TComCodingStatisticsClassType(STATS__CABAC_BITS__TRANSFORM_SUBDIV_FLAG, 5-uiLog2TransformBlockSize))
     1240                          );
    12981241#if !H_MV_ENC_DEC_TRAC
    12991242  DTRACE_CABAC_VL( g_nSymbolCounter++ )
     
    13071250  DTRACE_TU("split_transform_flag", ruiSubdivFlag )
    13081251#endif
     1252
    13091253}
    13101254
     
    13131257  UInt uiSymbol;
    13141258  const UInt uiCtx = 0;
    1315   m_pcTDecBinIf->decodeBin( uiSymbol , m_cCUQtRootCbfSCModel.get( 0, 0, uiCtx ) );
     1259  m_pcTDecBinIf->decodeBin( uiSymbol , m_cCUQtRootCbfSCModel.get( 0, 0, uiCtx ) RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(STATS__CABAC_BITS__QT_ROOT_CBF) );
    13161260#if !H_MV_ENC_DEC_TRAC
    13171261  DTRACE_CABAC_VL( g_nSymbolCounter++ )
     
    13271271  DTRACE_CU( "rqt_root_cbf", uiSymbol )
    13281272#endif
    1329  
     1273
    13301274  uiQtRootCbf = uiSymbol;
    13311275}
     
    13361280  UInt uiDQp;
    13371281  Int  iDQp;
    1338  
     1282
    13391283  UInt uiSymbol;
    13401284
    1341   xReadUnaryMaxSymbol (uiDQp,  &m_cCUDeltaQpSCModel.get( 0, 0, 0 ), 1, CU_DQP_TU_CMAX);
     1285  xReadUnaryMaxSymbol (uiDQp,  &m_cCUDeltaQpSCModel.get( 0, 0, 0 ), 1, CU_DQP_TU_CMAX RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(STATS__CABAC_BITS__DELTA_QP_EP) );
    13421286
    13431287  if( uiDQp >= CU_DQP_TU_CMAX)
    13441288  {
    1345     xReadEpExGolomb( uiSymbol, CU_DQP_EG_k );
     1289    xReadEpExGolomb( uiSymbol, CU_DQP_EG_k RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(STATS__CABAC_BITS__DELTA_QP_EP));
    13461290    uiDQp+=uiSymbol;
    13471291  }
     
    13501294  {
    13511295    UInt uiSign;
    1352     Int qpBdOffsetY = pcCU->getSlice()->getSPS()->getQpBDOffsetY();
    1353     m_pcTDecBinIf->decodeBinEP(uiSign);
     1296    Int qpBdOffsetY = pcCU->getSlice()->getSPS()->getQpBDOffset(CHANNEL_TYPE_LUMA);
     1297    m_pcTDecBinIf->decodeBinEP(uiSign RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(STATS__CABAC_BITS__DELTA_QP_EP));
    13541298    iDQp = uiDQp;
    13551299    if(uiSign)
     
    13591303    qp = (((Int) pcCU->getRefQP( uiAbsPartIdx ) + iDQp + 52 + 2*qpBdOffsetY )%(52+qpBdOffsetY)) - qpBdOffsetY;
    13601304  }
    1361   else 
     1305  else
    13621306  {
    13631307    qp = pcCU->getRefQP(uiAbsPartIdx);
    13641308  }
    1365   pcCU->setQPSubParts(qp, uiAbsPartIdx, uiDepth); 
     1309
     1310  pcCU->setQPSubParts(qp, uiAbsPartIdx, uiDepth);
    13661311  pcCU->setCodedQP(qp);
    13671312}
    13681313
    1369 Void TDecSbac::parseQtCbf( TComDataCU* pcCU, UInt uiAbsPartIdx, TextType eType, UInt uiTrDepth, UInt uiDepth )
    1370 {
    1371   UInt uiSymbol;
    1372   const UInt uiCtx = pcCU->getCtxQtCbf( eType, uiTrDepth );
    1373   m_pcTDecBinIf->decodeBin( uiSymbol , m_cCUQtCbfSCModel.get( 0, eType ? TEXT_CHROMA: eType, uiCtx ) );
     1314/** parse chroma qp adjustment, converting to the internal table representation.
     1315 * \returns Void
     1316 */
     1317Void TDecSbac::parseChromaQpAdjustment( TComDataCU* cu, UInt absPartIdx, UInt depth )
     1318{
     1319  UInt symbol;
     1320#if RExt__DECODER_DEBUG_BIT_STATISTICS
     1321  const TComCodingStatisticsClassType ctype(STATS__CABAC_BITS__CHROMA_QP_ADJUSTMENT, g_aucConvertToBit[cu->getSlice()->getSPS()->getMaxCUWidth()>>depth]+2, CHANNEL_TYPE_CHROMA);
     1322#endif
     1323
     1324  Int chromaQpOffsetListLen = cu->getSlice()->getPPS()->getPpsRangeExtension().getChromaQpOffsetListLen();
     1325
     1326  // cu_chroma_qp_offset_flag
     1327  m_pcTDecBinIf->decodeBin( symbol, m_ChromaQpAdjFlagSCModel.get( 0, 0, 0 ) RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(ctype) );
     1328
     1329  if (symbol && chromaQpOffsetListLen > 1)
     1330  {
     1331    // cu_chroma_qp_offset_idx
     1332    xReadUnaryMaxSymbol( symbol,  &m_ChromaQpAdjIdcSCModel.get( 0, 0, 0 ), 0, chromaQpOffsetListLen - 1 RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(ctype) );
     1333    symbol++;
     1334  }
     1335  /* NB, symbol = 0 if outer flag is not set,
     1336   *              1 if outer flag is set and there is no inner flag
     1337   *              1+ otherwise */
     1338  cu->setChromaQpAdjSubParts( symbol, absPartIdx, depth );
     1339  cu->setCodedChromaQpAdj(symbol);
     1340}
     1341
     1342Void TDecSbac::parseQtCbf( TComTU &rTu, const ComponentID compID, const Bool lowestLevel )
     1343{
     1344  TComDataCU* pcCU = rTu.getCU();
     1345
     1346  const UInt absPartIdx       = rTu.GetAbsPartIdxTU(compID);
     1347  const UInt TUDepth          = rTu.GetTransformDepthRel();
     1348  const UInt uiCtx            = pcCU->getCtxQtCbf( rTu, toChannelType(compID) );
     1349  const UInt contextSet       = toChannelType(compID);
     1350
     1351  const UInt width            = rTu.getRect(compID).width;
     1352  const UInt height           = rTu.getRect(compID).height;
     1353  const Bool canQuadSplit     = (width >= (MIN_TU_SIZE * 2)) && (height >= (MIN_TU_SIZE * 2));
     1354  const UInt coveredPartIdxes = rTu.GetAbsPartIdxNumParts(compID);
     1355
     1356  //             Since the CBF for chroma is coded at the highest level possible, if sub-TUs are
     1357  //             to be coded for a 4x8 chroma TU, their CBFs must be coded at the highest 4x8 level
     1358  //             (i.e. where luma TUs are 8x8 rather than 4x4)
     1359  //    ___ ___
     1360  //   |   |   | <- 4 x (8x8 luma + 4x8 4:2:2 chroma)
     1361  //   |___|___|    each quadrant has its own chroma CBF
     1362  //   |   |   | _ _ _ _
     1363  //   |___|___|        |
     1364  //   <--16--->        V
     1365  //                   _ _
     1366  //                  |_|_| <- 4 x 4x4 luma + 1 x 4x8 4:2:2 chroma
     1367  //                  |_|_|    no chroma CBF is coded - instead the parent CBF is inherited
     1368  //                  <-8->    if sub-TUs are present, their CBFs had to be coded at the parent level
     1369
     1370  const UInt lowestTUDepth = TUDepth + ((!lowestLevel && !canQuadSplit) ? 1 : 0); //unsplittable TUs inherit their parent's CBF
     1371        UInt lowestTUCBF   = 0;
     1372
     1373  if ((width != height) && (lowestLevel || !canQuadSplit)) //if sub-TUs are present
     1374  {
     1375    const UInt subTUDepth        = lowestTUDepth + 1;
     1376    const UInt partIdxesPerSubTU = rTu.GetAbsPartIdxNumParts(compID) >> 1;
     1377
     1378    UInt combinedSubTUCBF = 0;
     1379
     1380    for (UInt subTU = 0; subTU < 2; subTU++)
     1381    {
     1382      UInt uiCbf = MAX_UINT;
     1383      m_pcTDecBinIf->decodeBin(uiCbf, m_cCUQtCbfSCModel.get(0, contextSet, uiCtx) RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(TComCodingStatisticsClassType(STATS__CABAC_BITS__QT_CBF, g_aucConvertToBit[rTu.getRect(compID).width]+2, compID)));
     1384
     1385      const UInt subTUAbsPartIdx = absPartIdx + (subTU * partIdxesPerSubTU);
     1386      pcCU->setCbfPartRange((uiCbf << subTUDepth), compID, subTUAbsPartIdx, partIdxesPerSubTU);
     1387      combinedSubTUCBF |= uiCbf;
    13741388#if !H_MV_ENC_DEC_TRAC 
    1375   DTRACE_CABAC_VL( g_nSymbolCounter++ )
    1376   DTRACE_CABAC_T( "\tparseQtCbf()" )
    1377   DTRACE_CABAC_T( "\tsymbol=" )
    1378   DTRACE_CABAC_V( uiSymbol )
    1379   DTRACE_CABAC_T( "\tctx=" )
    1380   DTRACE_CABAC_V( uiCtx )
    1381   DTRACE_CABAC_T( "\tetype=" )
    1382   DTRACE_CABAC_V( eType )
    1383   DTRACE_CABAC_T( "\tuiAbsPartIdx=" )
    1384   DTRACE_CABAC_V( uiAbsPartIdx )
    1385   DTRACE_CABAC_T( "\n" )
     1389      DTRACE_CABAC_VL( g_nSymbolCounter++ )
     1390      DTRACE_CABAC_T( "\tparseQtCbf()" )
     1391      DTRACE_CABAC_T( "\tsub-TU=" )
     1392      DTRACE_CABAC_V( subTU )
     1393      DTRACE_CABAC_T( "\tsymbol=" )
     1394      DTRACE_CABAC_V( uiCbf )
     1395      DTRACE_CABAC_T( "\tctx=" )
     1396      DTRACE_CABAC_V( uiCtx )
     1397      DTRACE_CABAC_T( "\tetype=" )
     1398      DTRACE_CABAC_V( compID )
     1399      DTRACE_CABAC_T( "\tuiAbsPartIdx=" )
     1400      DTRACE_CABAC_V( subTUAbsPartIdx )
     1401      DTRACE_CABAC_T( "\n" )
    13861402#else
    1387   if ( eType == TEXT_CHROMA_U )
    1388   {
    1389     DTRACE_TU("cbf_cb", uiSymbol )
    1390   }
    1391   else if ( eType == TEXT_CHROMA_V )
    1392   {
    1393     DTRACE_TU("cbf_cr", uiSymbol )
     1403  if ( compID == COMPONENT_Cb )
     1404  {
     1405    DTRACE_TU("cbf_cb", uiCbf )
     1406  }
     1407  else if ( compID == COMPONENT_Cr )
     1408  {
     1409    DTRACE_TU("cbf_cr", uiCbf )
    13941410  }
    13951411  else
    13961412  {
    1397     DTRACE_TU("cbf_luma", uiSymbol )
    1398   }
    1399 #endif
    1400  
    1401   pcCU->setCbfSubParts( uiSymbol << uiTrDepth, eType, uiAbsPartIdx, uiDepth );
    1402 }
    1403 
    1404 void TDecSbac::parseTransformSkipFlags (TComDataCU* pcCU, UInt uiAbsPartIdx, UInt width, UInt height, UInt uiDepth, TextType eTType)
    1405 {
     1413    DTRACE_TU("cbf_luma", uiCbf )
     1414  }
     1415#endif
     1416
     1417    }
     1418
     1419    //propagate the sub-TU CBF up to the lowest TU level
     1420    if (combinedSubTUCBF != 0)
     1421    {
     1422      pcCU->bitwiseOrCbfPartRange((combinedSubTUCBF << lowestTUDepth), compID, absPartIdx, coveredPartIdxes);
     1423      lowestTUCBF = combinedSubTUCBF;
     1424    }
     1425  }
     1426  else
     1427  {
     1428    UInt uiCbf = MAX_UINT;
     1429    m_pcTDecBinIf->decodeBin(uiCbf, m_cCUQtCbfSCModel.get(0, contextSet, uiCtx) RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(TComCodingStatisticsClassType(STATS__CABAC_BITS__QT_CBF, g_aucConvertToBit[rTu.getRect(compID).width]+2, compID)));
     1430
     1431    pcCU->setCbfSubParts((uiCbf << lowestTUDepth), compID, absPartIdx, rTu.GetTransformDepthTotalAdj(compID));
     1432#if !H_MV_ENC_DEC_TRAC
     1433    DTRACE_CABAC_VL( g_nSymbolCounter++ )
     1434    DTRACE_CABAC_T( "\tparseQtCbf()" )
     1435    DTRACE_CABAC_T( "\tsymbol=" )
     1436    DTRACE_CABAC_V( uiCbf )
     1437    DTRACE_CABAC_T( "\tctx=" )
     1438    DTRACE_CABAC_V( uiCtx )
     1439    DTRACE_CABAC_T( "\tetype=" )
     1440    DTRACE_CABAC_V( compID )
     1441    DTRACE_CABAC_T( "\tuiAbsPartIdx=" )
     1442    DTRACE_CABAC_V( rTu.GetAbsPartIdxTU(compID) )
     1443    DTRACE_CABAC_T( "\n" )
     1444#else
     1445    if ( compID == COMPONENT_Cb )
     1446    {
     1447      DTRACE_TU("cbf_cb", uiCbf )
     1448    }
     1449    else if ( compID == COMPONENT_Cr )
     1450    {
     1451      DTRACE_TU("cbf_cr", uiCbf )
     1452    }
     1453    else
     1454    {
     1455      DTRACE_TU("cbf_luma", uiCbf )
     1456    }
     1457#endif
     1458    lowestTUCBF = uiCbf;
     1459  }
     1460
     1461  //propagate the lowest level CBF up to the current level
     1462  if (lowestTUCBF != 0)
     1463  {
     1464    for (UInt depth = TUDepth; depth < lowestTUDepth; depth++)
     1465    {
     1466      pcCU->bitwiseOrCbfPartRange((lowestTUCBF << depth), compID, absPartIdx, coveredPartIdxes);
     1467    }
     1468  }
     1469}
     1470
     1471
     1472Void TDecSbac::parseTransformSkipFlags (TComTU &rTu, ComponentID component)
     1473{
     1474  TComDataCU* pcCU=rTu.getCU();
     1475  UInt uiAbsPartIdx=rTu.GetAbsPartIdxTU(component);
     1476
    14061477  if (pcCU->getCUTransquantBypass(uiAbsPartIdx))
    14071478  {
    14081479    return;
    14091480  }
    1410   if(width != 4 || height != 4)
     1481
     1482  if (!TUCompRectHasAssociatedTransformSkipFlag(rTu.getRect(component), pcCU->getSlice()->getPPS()->getPpsRangeExtension().getLog2MaxTransformSkipBlockSize()))
    14111483  {
    14121484    return;
    14131485  }
    1414  
     1486
    14151487  UInt useTransformSkip;
    1416   m_pcTDecBinIf->decodeBin( useTransformSkip , m_cTransformSkipSCModel.get( 0, eTType? TEXT_CHROMA: TEXT_LUMA, 0 ) );
    1417   if(eTType!= TEXT_LUMA)
    1418   {
    1419     const UInt uiLog2TrafoSize = g_aucConvertToBit[pcCU->getSlice()->getSPS()->getMaxCUWidth()] + 2 - uiDepth;
    1420     if(uiLog2TrafoSize == 2)
    1421     {
    1422       uiDepth --;
    1423     }
    1424   }
     1488
     1489  m_pcTDecBinIf->decodeBin( useTransformSkip , m_cTransformSkipSCModel.get( 0, toChannelType(component), 0 )
     1490      RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(TComCodingStatisticsClassType(STATS__CABAC_BITS__TRANSFORM_SKIP_FLAGS, component))
     1491                          );
     1492
    14251493#if !H_MV_ENC_DEC_TRAC
    14261494  DTRACE_CABAC_VL( g_nSymbolCounter++ )
     
    14291497  DTRACE_CABAC_V( useTransformSkip )
    14301498  DTRACE_CABAC_T( "\tAddr=" )
    1431   DTRACE_CABAC_V( pcCU->getAddr() )
     1499  DTRACE_CABAC_V( pcCU->getCtuRsAddr() )
    14321500  DTRACE_CABAC_T( "\tetype=" )
    1433   DTRACE_CABAC_V( eTType )
     1501  DTRACE_CABAC_V( component )
    14341502  DTRACE_CABAC_T( "\tuiAbsPartIdx=" )
    1435   DTRACE_CABAC_V( uiAbsPartIdx )
     1503  DTRACE_CABAC_V( rTu.GetAbsPartIdxTU() )
    14361504  DTRACE_CABAC_T( "\n" )
    14371505#endif
    14381506
    1439   pcCU->setTransformSkipSubParts( useTransformSkip, eTType, uiAbsPartIdx, uiDepth);
    1440 }
     1507  pcCU->setTransformSkipPartRange( useTransformSkip, component, uiAbsPartIdx, rTu.GetAbsPartIdxNumParts(component));
     1508}
     1509
    14411510
    14421511/** Parse (X,Y) position of the last significant coefficient
     
    14451514 * \param width  Block width
    14461515 * \param height Block height
    1447  * \param eTType plane type / luminance or chrominance
     1516 * \param component chroma compinent ID
    14481517 * \param uiScanIdx scan type (zig-zag, hor, ver)
    14491518 *
    14501519 * This method decodes the X and Y component within a block of the last significant coefficient.
    14511520 */
    1452 Void TDecSbac::parseLastSignificantXY( UInt& uiPosLastX, UInt& uiPosLastY, Int width, Int height, TextType eTType, UInt uiScanIdx )
     1521Void TDecSbac::parseLastSignificantXY( UInt& uiPosLastX, UInt& uiPosLastY, Int width, Int height, ComponentID component, UInt uiScanIdx )
    14531522{
    14541523  UInt uiLast;
    1455   ContextModel *pCtxX = m_cCuCtxLastX.get( 0, eTType );
    1456   ContextModel *pCtxY = m_cCuCtxLastY.get( 0, eTType );
     1524
     1525  ContextModel *pCtxX = m_cCuCtxLastX.get( 0, toChannelType(component) );
     1526  ContextModel *pCtxY = m_cCuCtxLastY.get( 0, toChannelType(component) );
     1527
     1528#if RExt__DECODER_DEBUG_BIT_STATISTICS
     1529  TComCodingStatisticsClassType ctype(STATS__CABAC_BITS__LAST_SIG_X_Y, g_aucConvertToBit[width]+2, component);
     1530#endif
     1531
     1532
     1533  if ( uiScanIdx == SCAN_VER )
     1534  {
     1535    swap( width, height );
     1536  }
    14571537
    14581538  Int blkSizeOffsetX, blkSizeOffsetY, shiftX, shiftY;
    1459   blkSizeOffsetX = eTType ? 0: (g_aucConvertToBit[ width ] *3 + ((g_aucConvertToBit[ width ] +1)>>2));
    1460   blkSizeOffsetY = eTType ? 0: (g_aucConvertToBit[ height ]*3 + ((g_aucConvertToBit[ height ]+1)>>2));
    1461   shiftX= eTType ? g_aucConvertToBit[ width  ] :((g_aucConvertToBit[ width  ]+3)>>2);
    1462   shiftY= eTType ? g_aucConvertToBit[ height ] :((g_aucConvertToBit[ height ]+3)>>2);
     1539  getLastSignificantContextParameters(component, width, height, blkSizeOffsetX, blkSizeOffsetY, shiftX, shiftY);
     1540
     1541  //------------------
     1542
    14631543  // posX
     1544
    14641545  for( uiPosLastX = 0; uiPosLastX < g_uiGroupIdx[ width - 1 ]; uiPosLastX++ )
    14651546  {
    1466     m_pcTDecBinIf->decodeBin( uiLast, *( pCtxX + blkSizeOffsetX + (uiPosLastX >>shiftX) ) );
     1547    m_pcTDecBinIf->decodeBin( uiLast, *( pCtxX + blkSizeOffsetX + (uiPosLastX >>shiftX) ) RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(ctype) );
     1548
    14671549    if( !uiLast )
    14681550    {
     
    14721554
    14731555  // posY
     1556
    14741557  for( uiPosLastY = 0; uiPosLastY < g_uiGroupIdx[ height - 1 ]; uiPosLastY++ )
    14751558  {
    1476     m_pcTDecBinIf->decodeBin( uiLast, *( pCtxY + blkSizeOffsetY + (uiPosLastY >>shiftY)) );
     1559    m_pcTDecBinIf->decodeBin( uiLast, *( pCtxY + blkSizeOffsetY + (uiPosLastY >>shiftY)) RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(ctype) );
     1560
    14771561    if( !uiLast )
    14781562    {
     
    14801564    }
    14811565  }
     1566
     1567  // EP-coded part
     1568
    14821569  if ( uiPosLastX > 3 )
    14831570  {
     
    14861573    for ( Int i = uiCount - 1; i >= 0; i-- )
    14871574    {
    1488       m_pcTDecBinIf->decodeBinEP( uiLast );
     1575      m_pcTDecBinIf->decodeBinEP( uiLast RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(ctype) );
    14891576      uiTemp += uiLast << i;
    14901577    }
     
    14971584    for ( Int i = uiCount - 1; i >= 0; i-- )
    14981585    {
    1499       m_pcTDecBinIf->decodeBinEP( uiLast );
     1586      m_pcTDecBinIf->decodeBinEP( uiLast RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(ctype) );
    15001587      uiTemp += uiLast << i;
    15011588    }
    15021589    uiPosLastY = g_uiMinInGroup[ uiPosLastY ] + uiTemp;
    15031590  }
    1504  
     1591
    15051592  if( uiScanIdx == SCAN_VER )
    15061593  {
     
    15091596}
    15101597
    1511 Void TDecSbac::parseCoeffNxN( TComDataCU* pcCU, TCoeff* pcCoef, UInt uiAbsPartIdx, UInt uiWidth, UInt uiHeight, UInt uiDepth, TextType eTType )
    1512 {
     1598Void TDecSbac::parseCoeffNxN(  TComTU &rTu, ComponentID compID )
     1599{
     1600  TComDataCU* pcCU=rTu.getCU();
     1601  const UInt uiAbsPartIdx=rTu.GetAbsPartIdxTU(compID);
     1602  const TComRectangle &rRect=rTu.getRect(compID);
     1603  const UInt uiWidth=rRect.width;
     1604  const UInt uiHeight=rRect.height;
     1605  TCoeff* pcCoef=(pcCU->getCoeff(compID)+rTu.getCoefficientOffset(compID));
     1606  const TComSPS &sps=*(pcCU->getSlice()->getSPS());
    15131607#if !H_MV_ENC_DEC_TRAC
    15141608  DTRACE_CABAC_VL( g_nSymbolCounter++ )
    15151609  DTRACE_CABAC_T( "\tparseCoeffNxN()\teType=" )
    1516   DTRACE_CABAC_V( eTType )
     1610  DTRACE_CABAC_V( compID )
    15171611  DTRACE_CABAC_T( "\twidth=" )
    15181612  DTRACE_CABAC_V( uiWidth )
     
    15201614  DTRACE_CABAC_V( uiHeight )
    15211615  DTRACE_CABAC_T( "\tdepth=" )
    1522   DTRACE_CABAC_V( uiDepth )
     1616//  DTRACE_CABAC_V( rTu.GetTransformDepthTotalAdj(compID) )
     1617  DTRACE_CABAC_V( rTu.GetTransformDepthTotal() )
    15231618  DTRACE_CABAC_T( "\tabspartidx=" )
    1524   DTRACE_CABAC_V( uiAbsPartIdx )
     1619//  DTRACE_CABAC_V( uiAbsPartIdx )
     1620  DTRACE_CABAC_V( rTu.GetAbsPartIdxTU(compID) )
    15251621  DTRACE_CABAC_T( "\ttoCU-X=" )
    15261622  DTRACE_CABAC_V( pcCU->getCUPelX() )
     
    15281624  DTRACE_CABAC_V( pcCU->getCUPelY() )
    15291625  DTRACE_CABAC_T( "\tCU-addr=" )
    1530   DTRACE_CABAC_V(  pcCU->getAddr() )
     1626  DTRACE_CABAC_V(  pcCU->getCtuRsAddr() )
    15311627  DTRACE_CABAC_T( "\tinCU-X=" )
    1532   DTRACE_CABAC_V( g_auiRasterToPelX[ g_auiZscanToRaster[uiAbsPartIdx] ] )
     1628//  DTRACE_CABAC_V( g_auiRasterToPelX[ g_auiZscanToRaster[uiAbsPartIdx] ] )
     1629  DTRACE_CABAC_V( g_auiRasterToPelX[ g_auiZscanToRaster[rTu.GetAbsPartIdxTU(compID)] ] )
    15331630  DTRACE_CABAC_T( "\tinCU-Y=" )
    1534   DTRACE_CABAC_V( g_auiRasterToPelY[ g_auiZscanToRaster[uiAbsPartIdx] ] )
     1631// DTRACE_CABAC_V( g_auiRasterToPelY[ g_auiZscanToRaster[uiAbsPartIdx] ] )
     1632  DTRACE_CABAC_V( g_auiRasterToPelY[ g_auiZscanToRaster[rTu.GetAbsPartIdxTU(compID)] ] )
    15351633  DTRACE_CABAC_T( "\tpredmode=" )
    15361634  DTRACE_CABAC_V(  pcCU->getPredictionMode( uiAbsPartIdx ) )
    15371635  DTRACE_CABAC_T( "\n" )
    15381636#endif
    1539  
    1540   if( uiWidth > pcCU->getSlice()->getSPS()->getMaxTrSize() )
    1541   {
    1542     uiWidth  = pcCU->getSlice()->getSPS()->getMaxTrSize();
    1543     uiHeight = pcCU->getSlice()->getSPS()->getMaxTrSize();
    1544   }
     1637
     1638  //--------------------------------------------------------------------------------------------------
     1639
     1640  if( uiWidth > sps.getMaxTrSize() )
     1641  {
     1642    std::cerr << "ERROR: parseCoeffNxN was passed a TU with dimensions larger than the maximum allowed size" << std::endl;
     1643    assert(false);
     1644    exit(1);
     1645  }
     1646
     1647  //--------------------------------------------------------------------------------------------------
     1648
     1649  //set parameters
     1650
     1651  const ChannelType  chType            = toChannelType(compID);
     1652  const UInt         uiLog2BlockWidth  = g_aucConvertToBit[ uiWidth  ] + 2;
     1653  const UInt         uiLog2BlockHeight = g_aucConvertToBit[ uiHeight ] + 2;
     1654  const UInt         uiMaxNumCoeff     = uiWidth * uiHeight;
     1655  const UInt         uiMaxNumCoeffM1   = uiMaxNumCoeff - 1;
     1656
     1657  const ChannelType  channelType       = toChannelType(compID);
     1658  const Bool         extendedPrecision = sps.getSpsRangeExtension().getExtendedPrecisionProcessingFlag();
     1659
     1660  const Bool         alignCABACBeforeBypass = sps.getSpsRangeExtension().getCabacBypassAlignmentEnabledFlag();
     1661  const Int          maxLog2TrDynamicRange  = sps.getMaxLog2TrDynamicRange(channelType);
     1662
     1663#if RExt__DECODER_DEBUG_BIT_STATISTICS
     1664  TComCodingStatisticsClassType ctype_group(STATS__CABAC_BITS__SIG_COEFF_GROUP_FLAG, uiLog2BlockWidth, compID);
     1665  TComCodingStatisticsClassType ctype_map(STATS__CABAC_BITS__SIG_COEFF_MAP_FLAG, uiLog2BlockWidth, compID);
     1666  TComCodingStatisticsClassType ctype_gt1(STATS__CABAC_BITS__GT1_FLAG, uiLog2BlockWidth, compID);
     1667  TComCodingStatisticsClassType ctype_gt2(STATS__CABAC_BITS__GT2_FLAG, uiLog2BlockWidth, compID);
     1668#endif
     1669
     1670  Bool beValid;
     1671  if (pcCU->getCUTransquantBypass(uiAbsPartIdx))
     1672  {
     1673    beValid = false;
     1674    if((!pcCU->isIntra(uiAbsPartIdx)) && pcCU->isRDPCMEnabled(uiAbsPartIdx))
     1675    {
     1676      parseExplicitRdpcmMode(rTu, compID);
     1677    }
     1678  }
     1679  else
     1680  {
     1681    beValid = pcCU->getSlice()->getPPS()->getSignHideFlag();
     1682  }
     1683
     1684  UInt absSum = 0;
     1685
     1686  //--------------------------------------------------------------------------------------------------
     1687
    15451688  if(pcCU->getSlice()->getPPS()->getUseTransformSkip())
    15461689  {
    1547     parseTransformSkipFlags( pcCU, uiAbsPartIdx, uiWidth, uiHeight, uiDepth, eTType);
    1548   }
    1549 
    1550   eTType = eTType == TEXT_LUMA ? TEXT_LUMA : ( eTType == TEXT_NONE ? TEXT_NONE : TEXT_CHROMA );
    1551  
    1552   //----- parse significance map -----
    1553   const UInt  uiLog2BlockSize   = g_aucConvertToBit[ uiWidth ] + 2;
    1554   const UInt  uiMaxNumCoeff     = uiWidth * uiHeight;
    1555   const UInt  uiMaxNumCoeffM1   = uiMaxNumCoeff - 1;
    1556   UInt uiScanIdx = pcCU->getCoefScanIdx(uiAbsPartIdx, uiWidth, eTType==TEXT_LUMA, pcCU->isIntra(uiAbsPartIdx));
    1557  
     1690    parseTransformSkipFlags(rTu, compID);
     1691    //  This TU has coefficients and is transform skipped. Check whether is inter coded and if yes decode the explicit RDPCM mode
     1692    if(pcCU->getTransformSkip(uiAbsPartIdx, compID) && (!pcCU->isIntra(uiAbsPartIdx)) && pcCU->isRDPCMEnabled(uiAbsPartIdx) )
     1693    {
     1694      parseExplicitRdpcmMode(rTu, compID);
     1695      if(pcCU->getExplicitRdpcmMode(compID, uiAbsPartIdx) != RDPCM_OFF)
     1696      {
     1697        //  Sign data hiding is avoided for horizontal and vertical RDPCM modes
     1698        beValid = false;
     1699      }
     1700    }
     1701  }
     1702
     1703  Int uiIntraMode = -1;
     1704  const Bool       bIsLuma = isLuma(compID);
     1705  Int isIntra = pcCU->isIntra(uiAbsPartIdx) ? 1 : 0;
     1706  if ( isIntra && pcCU->isRDPCMEnabled(uiAbsPartIdx) )
     1707  {
     1708    const UInt partsPerMinCU = 1<<(2*(sps.getMaxTotalCUDepth() - sps.getLog2DiffMaxMinCodingBlockSize()));
     1709    uiIntraMode = pcCU->getIntraDir( toChannelType(compID), uiAbsPartIdx );
     1710    uiIntraMode = (uiIntraMode==DM_CHROMA_IDX && !bIsLuma) ? pcCU->getIntraDir(CHANNEL_TYPE_LUMA, getChromasCorrespondingPULumaIdx(uiAbsPartIdx, rTu.GetChromaFormat(), partsPerMinCU)) : uiIntraMode;
     1711    uiIntraMode = ((rTu.GetChromaFormat() == CHROMA_422) && !bIsLuma) ? g_chroma422IntraAngleMappingTable[uiIntraMode] : uiIntraMode;
     1712
     1713    Bool transformSkip = pcCU->getTransformSkip( uiAbsPartIdx,compID);
     1714    Bool rdpcm_lossy = ( transformSkip /*&& isIntra*/ && ( (uiIntraMode == HOR_IDX) || (uiIntraMode == VER_IDX) ) );
     1715    if ( rdpcm_lossy )
     1716    {
     1717      beValid = false;
     1718    }
     1719  }
     1720
     1721  //--------------------------------------------------------------------------------------------------
     1722
     1723  const Bool  bUseGolombRiceParameterAdaptation = sps.getSpsRangeExtension().getPersistentRiceAdaptationEnabledFlag();
     1724        UInt &currentGolombRiceStatistic        = m_golombRiceAdaptationStatistics[rTu.getGolombRiceStatisticsIndex(compID)];
     1725
     1726  //select scans
     1727  TUEntropyCodingParameters codingParameters;
     1728  getTUEntropyCodingParameters(codingParameters, rTu, compID);
     1729
    15581730  //===== decode last significant =====
    15591731  UInt uiPosLastX, uiPosLastY;
    1560   parseLastSignificantXY( uiPosLastX, uiPosLastY, uiWidth, uiHeight, eTType, uiScanIdx );
    1561   UInt uiBlkPosLast      = uiPosLastX + (uiPosLastY<<uiLog2BlockSize);
     1732  parseLastSignificantXY( uiPosLastX, uiPosLastY, uiWidth, uiHeight, compID, codingParameters.scanType );
     1733  UInt uiBlkPosLast      = uiPosLastX + (uiPosLastY<<uiLog2BlockWidth);
    15621734  pcCoef[ uiBlkPosLast ] = 1;
    15631735
    15641736  //===== decode significance flags =====
    15651737  UInt uiScanPosLast;
    1566   const UInt *scan   = g_auiSigLastScan[ uiScanIdx ][ uiLog2BlockSize-1 ];
    15671738  for( uiScanPosLast = 0; uiScanPosLast < uiMaxNumCoeffM1; uiScanPosLast++ )
    15681739  {
    1569     UInt uiBlkPos = scan[ uiScanPosLast ];
     1740    UInt uiBlkPos = codingParameters.scan[ uiScanPosLast ];
    15701741    if( uiBlkPosLast == uiBlkPos )
    15711742    {
     
    15741745  }
    15751746
    1576   ContextModel * const baseCoeffGroupCtx = m_cCUSigCoeffGroupSCModel.get( 0, eTType );
    1577   ContextModel * const baseCtx = (eTType==TEXT_LUMA) ? m_cCUSigSCModel.get( 0, 0 ) : m_cCUSigSCModel.get( 0, 0 ) + NUM_SIG_FLAG_CTX_LUMA;
    1578 
    1579   const Int  iLastScanSet      = uiScanPosLast >> LOG2_SCAN_SET_SIZE;
    1580   UInt c1 = 1;
    1581   UInt uiGoRiceParam           = 0;
    1582 
    1583   Bool beValid;
    1584   if (pcCU->getCUTransquantBypass(uiAbsPartIdx))
    1585   {
    1586     beValid = false;
    1587   }
    1588   else
    1589   {
    1590     beValid = pcCU->getSlice()->getPPS()->getSignHideFlag() > 0;
    1591   }
    1592   UInt absSum = 0;
     1747  ContextModel * const baseCoeffGroupCtx = m_cCUSigCoeffGroupSCModel.get( 0, isChroma(chType) );
     1748  ContextModel * const baseCtx = m_cCUSigSCModel.get( 0, 0 ) + getSignificanceMapContextOffset(compID);
     1749
     1750  const Int  iLastScanSet  = uiScanPosLast >> MLS_CG_SIZE;
     1751  UInt c1                  = 1;
     1752  UInt uiGoRiceParam       = 0;
     1753
    15931754
    15941755  UInt uiSigCoeffGroupFlag[ MLS_GRP_NUM ];
    1595   ::memset( uiSigCoeffGroupFlag, 0, sizeof(UInt) * MLS_GRP_NUM );
    1596   const UInt uiNumBlkSide = uiWidth >> (MLS_CG_SIZE >> 1);
    1597   const UInt * scanCG;
    1598   {
    1599     scanCG = g_auiSigLastScan[ uiScanIdx ][ uiLog2BlockSize > 3 ? uiLog2BlockSize-2-1 : 0  ];   
    1600     if( uiLog2BlockSize == 3 )
    1601     {
    1602       scanCG = g_sigLastScan8x8[ uiScanIdx ];
    1603     }
    1604     else if( uiLog2BlockSize == 5 )
    1605     {
    1606       scanCG = g_sigLastScanCG32x32;
    1607     }
    1608   }
     1756  memset( uiSigCoeffGroupFlag, 0, sizeof(UInt) * MLS_GRP_NUM );
     1757
    16091758  Int  iScanPosSig             = (Int) uiScanPosLast;
    16101759  for( Int iSubSet = iLastScanSet; iSubSet >= 0; iSubSet-- )
    16111760  {
    1612     Int  iSubPos     = iSubSet << LOG2_SCAN_SET_SIZE;
    1613     uiGoRiceParam    = 0;
     1761    Int  iSubPos   = iSubSet << MLS_CG_SIZE;
     1762    uiGoRiceParam  = currentGolombRiceStatistic / RExt__GOLOMB_RICE_INCREMENT_DIVISOR;
     1763    Bool updateGolombRiceStatistics = bUseGolombRiceParameterAdaptation; //leave the statistics at 0 when not using the adaptation system
    16141764    Int numNonZero = 0;
    1615    
    1616     Int lastNZPosInCG = -1, firstNZPosInCG = SCAN_SET_SIZE;
    1617 
    1618     Int pos[SCAN_SET_SIZE];
     1765
     1766    Int lastNZPosInCG  = -1;
     1767    Int firstNZPosInCG = 1 << MLS_CG_SIZE;
     1768
     1769    Bool escapeDataPresentInGroup = false;
     1770
     1771    Int pos[1 << MLS_CG_SIZE];
     1772
    16191773    if( iScanPosSig == (Int) uiScanPosLast )
    16201774    {
     
    16271781
    16281782    // decode significant_coeffgroup_flag
    1629     Int iCGBlkPos = scanCG[ iSubSet ];
    1630     Int iCGPosY   = iCGBlkPos / uiNumBlkSide;
    1631     Int iCGPosX   = iCGBlkPos - (iCGPosY * uiNumBlkSide);
     1783    Int iCGBlkPos = codingParameters.scanCG[ iSubSet ];
     1784    Int iCGPosY   = iCGBlkPos / codingParameters.widthInGroups;
     1785    Int iCGPosX   = iCGBlkPos - (iCGPosY * codingParameters.widthInGroups);
     1786
    16321787    if( iSubSet == iLastScanSet || iSubSet == 0)
    16331788    {
     
    16371792    {
    16381793      UInt uiSigCoeffGroup;
    1639       UInt uiCtxSig  = TComTrQuant::getSigCoeffGroupCtxInc( uiSigCoeffGroupFlag, iCGPosX, iCGPosY, uiWidth, uiHeight );
    1640       m_pcTDecBinIf->decodeBin( uiSigCoeffGroup, baseCoeffGroupCtx[ uiCtxSig ] );
     1794      UInt uiCtxSig  = TComTrQuant::getSigCoeffGroupCtxInc( uiSigCoeffGroupFlag, iCGPosX, iCGPosY, codingParameters.widthInGroups, codingParameters.heightInGroups );
     1795      m_pcTDecBinIf->decodeBin( uiSigCoeffGroup, baseCoeffGroupCtx[ uiCtxSig ] RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(ctype_group) );
    16411796      uiSigCoeffGroupFlag[ iCGBlkPos ] = uiSigCoeffGroup;
    16421797    }
    16431798
    16441799    // decode significant_coeff_flag
    1645     Int patternSigCtx = TComTrQuant::calcPatternSigCtx( uiSigCoeffGroupFlag, iCGPosX, iCGPosY, uiWidth, uiHeight );
    1646     UInt uiBlkPos, uiPosY, uiPosX, uiSig, uiCtxSig;
     1800    const Int patternSigCtx = TComTrQuant::calcPatternSigCtx(uiSigCoeffGroupFlag, iCGPosX, iCGPosY, codingParameters.widthInGroups, codingParameters.heightInGroups);
     1801
     1802    UInt uiBlkPos, uiSig, uiCtxSig;
    16471803    for( ; iScanPosSig >= iSubPos; iScanPosSig-- )
    16481804    {
    1649       uiBlkPos  = scan[ iScanPosSig ];
    1650       uiPosY    = uiBlkPos >> uiLog2BlockSize;
    1651       uiPosX    = uiBlkPos - ( uiPosY << uiLog2BlockSize );
     1805      uiBlkPos  = codingParameters.scan[ iScanPosSig ];
    16521806      uiSig     = 0;
    1653      
     1807
    16541808      if( uiSigCoeffGroupFlag[ iCGBlkPos ] )
    16551809      {
    16561810        if( iScanPosSig > iSubPos || iSubSet == 0  || numNonZero )
    16571811        {
    1658           uiCtxSig  = TComTrQuant::getSigCtxInc( patternSigCtx, uiScanIdx, uiPosX, uiPosY, uiLog2BlockSize, eTType );
    1659           m_pcTDecBinIf->decodeBin( uiSig, baseCtx[ uiCtxSig ] );
     1812          uiCtxSig  = TComTrQuant::getSigCtxInc( patternSigCtx, codingParameters, iScanPosSig, uiLog2BlockWidth, uiLog2BlockHeight, chType );
     1813          m_pcTDecBinIf->decodeBin( uiSig, baseCtx[ uiCtxSig ] RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(ctype_map) );
    16601814        }
    16611815        else
     
    16761830      }
    16771831    }
    1678    
    1679     if( numNonZero )
     1832
     1833    if( numNonZero > 0 )
    16801834    {
    16811835      Bool signHidden = ( lastNZPosInCG - firstNZPosInCG >= SBH_THRESHOLD );
     1836
    16821837      absSum = 0;
    1683       UInt uiCtxSet    = (iSubSet > 0 && eTType==TEXT_LUMA) ? 2 : 0;
     1838
     1839      const UInt uiCtxSet = getContextSetIndex(compID, iSubSet, (c1 == 0));
     1840      c1 = 1;
    16841841      UInt uiBin;
    1685       if( c1 == 0 )
    1686       {
    1687         uiCtxSet++;
    1688       }
    1689       c1 = 1;
    1690       ContextModel *baseCtxMod = ( eTType==TEXT_LUMA ) ? m_cCUOneSCModel.get( 0, 0 ) + 4 * uiCtxSet : m_cCUOneSCModel.get( 0, 0 ) + NUM_ONE_FLAG_CTX_LUMA + 4 * uiCtxSet;
    1691       Int absCoeff[SCAN_SET_SIZE];
    1692 
    1693       for ( Int i = 0; i < numNonZero; i++) absCoeff[i] = 1;   
     1842
     1843      ContextModel *baseCtxMod = m_cCUOneSCModel.get( 0, 0 ) + (NUM_ONE_FLAG_CTX_PER_SET * uiCtxSet);
     1844
     1845      Int absCoeff[1 << MLS_CG_SIZE];
     1846
     1847      for ( Int i = 0; i < numNonZero; i++)
     1848      {
     1849        absCoeff[i] = 1;
     1850      }
    16941851      Int numC1Flag = min(numNonZero, C1FLAG_NUMBER);
    16951852      Int firstC2FlagIdx = -1;
     
    16971854      for( Int idx = 0; idx < numC1Flag; idx++ )
    16981855      {
    1699         m_pcTDecBinIf->decodeBin( uiBin, baseCtxMod[c1] );
     1856        m_pcTDecBinIf->decodeBin( uiBin, baseCtxMod[c1] RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(ctype_gt1) );
    17001857        if( uiBin == 1 )
    17011858        {
     
    17051862            firstC2FlagIdx = idx;
    17061863          }
     1864          else //if a greater-than-one has been encountered already this group
     1865          {
     1866            escapeDataPresentInGroup = true;
     1867          }
    17071868        }
    17081869        else if( (c1 < 3) && (c1 > 0) )
     
    17121873        absCoeff[ idx ] = uiBin + 1;
    17131874      }
    1714      
     1875
    17151876      if (c1 == 0)
    17161877      {
    1717         baseCtxMod = ( eTType==TEXT_LUMA ) ? m_cCUAbsSCModel.get( 0, 0 ) + uiCtxSet : m_cCUAbsSCModel.get( 0, 0 ) + NUM_ABS_FLAG_CTX_LUMA + uiCtxSet;
     1878        baseCtxMod = m_cCUAbsSCModel.get( 0, 0 ) + (NUM_ABS_FLAG_CTX_PER_SET * uiCtxSet);
    17181879        if ( firstC2FlagIdx != -1)
    17191880        {
    1720           m_pcTDecBinIf->decodeBin( uiBin, baseCtxMod[0] );
     1881          m_pcTDecBinIf->decodeBin( uiBin, baseCtxMod[0] RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(ctype_gt2) );
    17211882          absCoeff[ firstC2FlagIdx ] = uiBin + 2;
    1722         }
     1883          if (uiBin != 0)
     1884          {
     1885            escapeDataPresentInGroup = true;
     1886          }
     1887        }
     1888      }
     1889
     1890      escapeDataPresentInGroup = escapeDataPresentInGroup || (numNonZero > C1FLAG_NUMBER);
     1891
     1892      const Bool alignGroup = escapeDataPresentInGroup && alignCABACBeforeBypass;
     1893
     1894#if RExt__DECODER_DEBUG_BIT_STATISTICS
     1895      TComCodingStatisticsClassType ctype_signs((alignGroup ? STATS__CABAC_BITS__ALIGNED_SIGN_BIT    : STATS__CABAC_BITS__SIGN_BIT   ), uiLog2BlockWidth, compID);
     1896      TComCodingStatisticsClassType ctype_escs ((alignGroup ? STATS__CABAC_BITS__ALIGNED_ESCAPE_BITS : STATS__CABAC_BITS__ESCAPE_BITS), uiLog2BlockWidth, compID);
     1897#endif
     1898
     1899      if (alignGroup)
     1900      {
     1901        m_pcTDecBinIf->align();
    17231902      }
    17241903
     
    17261905      if ( signHidden && beValid )
    17271906      {
    1728         m_pcTDecBinIf->decodeBinsEP( coeffSigns, numNonZero-1 );
     1907        m_pcTDecBinIf->decodeBinsEP( coeffSigns, numNonZero-1 RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(ctype_signs) );
    17291908        coeffSigns <<= 32 - (numNonZero-1);
    17301909      }
    17311910      else
    17321911      {
    1733         m_pcTDecBinIf->decodeBinsEP( coeffSigns, numNonZero );
     1912        m_pcTDecBinIf->decodeBinsEP( coeffSigns, numNonZero RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(ctype_signs) );
    17341913        coeffSigns <<= 32 - numNonZero;
    17351914      }
    1736      
    1737       Int iFirstCoeff2 = 1;   
    1738       if (c1 == 0 || numNonZero > C1FLAG_NUMBER)
     1915
     1916      Int iFirstCoeff2 = 1;
     1917      if (escapeDataPresentInGroup)
    17391918      {
    17401919        for( Int idx = 0; idx < numNonZero; idx++ )
     
    17451924          {
    17461925            UInt uiLevel;
    1747             xReadCoefRemainExGolomb( uiLevel, uiGoRiceParam );
     1926            xReadCoefRemainExGolomb( uiLevel, uiGoRiceParam, extendedPrecision, maxLog2TrDynamicRange RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(ctype_escs) );
     1927
    17481928            absCoeff[ idx ] = uiLevel + baseLevel;
    1749             if(absCoeff[idx]>3*(1<<uiGoRiceParam))
     1929
     1930            if (absCoeff[idx] > (3 << uiGoRiceParam))
    17501931            {
    1751               uiGoRiceParam = min<UInt>(uiGoRiceParam+ 1, 4);
     1932              uiGoRiceParam = bUseGolombRiceParameterAdaptation ? (uiGoRiceParam + 1) : (std::min<UInt>((uiGoRiceParam + 1), 4));
     1933            }
     1934
     1935            if (updateGolombRiceStatistics)
     1936            {
     1937              const UInt initialGolombRiceParameter = currentGolombRiceStatistic / RExt__GOLOMB_RICE_INCREMENT_DIVISOR;
     1938
     1939              if (uiLevel >= (3 << initialGolombRiceParameter))
     1940              {
     1941                currentGolombRiceStatistic++;
     1942              }
     1943              else if (((uiLevel * 2) < (1 << initialGolombRiceParameter)) && (currentGolombRiceStatistic > 0))
     1944              {
     1945                currentGolombRiceStatistic--;
     1946              }
     1947
     1948              updateGolombRiceStatistics = false;
    17521949            }
    17531950          }
    17541951
    1755           if(absCoeff[ idx ] >= 2) 
     1952          if(absCoeff[ idx ] >= 2)
    17561953          {
    17571954            iFirstCoeff2 = 0;
     
    17841981    }
    17851982  }
    1786  
     1983
     1984#if ENVIRONMENT_VARIABLE_DEBUG_AND_TEST
     1985  printSBACCoeffData(uiPosLastX, uiPosLastY, uiWidth, uiHeight, compID, uiAbsPartIdx, codingParameters.scanType, pcCoef);
     1986#endif
     1987
    17871988  return;
    17881989}
    1789 
    17901990
    17911991Void TDecSbac::parseSaoMaxUvlc ( UInt& val, UInt maxSymbol )
     
    17991999  UInt code;
    18002000  Int  i;
    1801   m_pcTDecBinIf->decodeBinEP( code );
     2001  m_pcTDecBinIf->decodeBinEP( code RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(STATS__CABAC_BITS__SAO) );
    18022002  if ( code == 0 )
    18032003  {
     
    18092009  while (1)
    18102010  {
    1811     m_pcTDecBinIf->decodeBinEP( code );
     2011    m_pcTDecBinIf->decodeBinEP( code RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(STATS__CABAC_BITS__SAO) );
    18122012    if ( code == 0 )
    18132013    {
     
    18152015    }
    18162016    i++;
    1817     if (i == maxSymbol) 
     2017    if (i == maxSymbol)
    18182018    {
    18192019      break;
     
    18232023  val = i;
    18242024}
     2025
    18252026Void TDecSbac::parseSaoUflc (UInt uiLength, UInt&  riVal)
    18262027{
    1827   m_pcTDecBinIf->decodeBinsEP ( riVal, uiLength );
    1828 }
     2028  m_pcTDecBinIf->decodeBinsEP ( riVal, uiLength RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(STATS__CABAC_BITS__SAO) );
     2029}
     2030
    18292031Void TDecSbac::parseSaoMerge (UInt&  ruiVal)
    18302032{
    18312033  UInt uiCode;
    1832   m_pcTDecBinIf->decodeBin( uiCode, m_cSaoMergeSCModel.get( 0, 0, 0 ) );
     2034  m_pcTDecBinIf->decodeBin( uiCode, m_cSaoMergeSCModel.get( 0, 0, 0 ) RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(STATS__CABAC_BITS__SAO) );
    18332035  ruiVal = (Int)uiCode;
    18342036}
     2037
    18352038Void TDecSbac::parseSaoTypeIdx (UInt&  ruiVal)
    18362039{
    18372040  UInt uiCode;
    1838   m_pcTDecBinIf->decodeBin( uiCode, m_cSaoTypeIdxSCModel.get( 0, 0, 0 ) );
    1839   if (uiCode == 0) 
     2041  m_pcTDecBinIf->decodeBin( uiCode, m_cSaoTypeIdxSCModel.get( 0, 0, 0 ) RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(STATS__CABAC_BITS__SAO) );
     2042  if (uiCode == 0)
    18402043  {
    18412044    ruiVal = 0;
     
    18432046  else
    18442047  {
    1845     m_pcTDecBinIf->decodeBinEP( uiCode );
     2048    m_pcTDecBinIf->decodeBinEP( uiCode RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(STATS__CABAC_BITS__SAO) );
    18462049    if (uiCode == 0)
    18472050    {
     
    18572060Void TDecSbac::parseSaoSign(UInt& val)
    18582061{
    1859   m_pcTDecBinIf->decodeBinEP ( val );
     2062  m_pcTDecBinIf->decodeBinEP ( val RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(STATS__CABAC_BITS__SAO) );
    18602063}
    18612064
     
    18642067                                , Bool leftMergeAvail
    18652068                                , Bool aboveMergeAvail
     2069                                , const BitDepths &bitDepths
    18662070                                )
    18672071{
     
    18842088
    18852089  if(isLeftMerge || isAboveMerge) //merge mode
    1886       {
    1887     saoBlkParam[SAO_Y].modeIdc = saoBlkParam[SAO_Cb].modeIdc = saoBlkParam[SAO_Cr].modeIdc = SAO_MODE_MERGE;
    1888     saoBlkParam[SAO_Y].typeIdc = saoBlkParam[SAO_Cb].typeIdc = saoBlkParam[SAO_Cr].typeIdc = (isLeftMerge)?SAO_MERGE_LEFT:SAO_MERGE_ABOVE;
    1889       }   
     2090  {
     2091    for (UInt componentIndex = 0; componentIndex < MAX_NUM_COMPONENT; componentIndex++)
     2092    {
     2093      saoBlkParam[componentIndex].modeIdc = (sliceEnabled[componentIndex]) ? SAO_MODE_MERGE : SAO_MODE_OFF;
     2094      saoBlkParam[componentIndex].typeIdc = (isLeftMerge)?SAO_MERGE_LEFT:SAO_MERGE_ABOVE;
     2095    }
     2096  }
    18902097  else //new or off mode
    1891       {
    1892     for(Int compIdx=0; compIdx < NUM_SAO_COMPONENTS; compIdx++)
    1893         {
     2098  {
     2099    for(Int compId=COMPONENT_Y; compId < MAX_NUM_COMPONENT; compId++)
     2100    {
     2101      const ComponentID compIdx=ComponentID(compId);
     2102      const ComponentID firstCompOfChType = getFirstComponentOfChannel(toChannelType(compIdx));
    18942103      SAOOffset& ctbParam = saoBlkParam[compIdx];
    1895 
     2104#if O0043_BEST_EFFORT_DECODING
     2105      const Int bitDepthOrig = bitDepths.stream[toChannelType(compIdx)];
     2106      const Int forceBitDepthAdjust = bitDepthOrig - bitDepths.recon[toChannelType(compIdx)];
     2107#else
     2108      const Int bitDepthOrig = bitDepths.recon[toChannelType(compIdx)];
     2109#endif
     2110      const Int maxOffsetQVal=TComSampleAdaptiveOffset::getMaxOffsetQVal(bitDepthOrig);
    18962111      if(!sliceEnabled[compIdx])
    1897           {
     2112      {
    18982113        //off
    18992114        ctbParam.modeIdc = SAO_MODE_OFF;
    19002115        continue;
    1901         }
     2116      }
    19022117
    19032118      //type
    1904       if(compIdx == SAO_Y || compIdx == SAO_Cb)
    1905     {
     2119      if(compIdx == firstCompOfChType)
     2120      {
    19062121        parseSaoTypeIdx(uiSymbol); //sao_type_idx_luma or sao_type_idx_chroma
    19072122
     
    19092124
    19102125        if(uiSymbol ==0) //OFF
    1911      {
     2126        {
    19122127          ctbParam.modeIdc = SAO_MODE_OFF;
    1913    }
     2128        }
    19142129        else if(uiSymbol == 1) //BO
    19152130        {
    19162131          ctbParam.modeIdc = SAO_MODE_NEW;
    19172132          ctbParam.typeIdc = SAO_TYPE_START_BO;
    1918   }
     2133        }
    19192134        else //2, EO
    1920   {
     2135        {
    19212136          ctbParam.modeIdc = SAO_MODE_NEW;
    19222137          ctbParam.typeIdc = SAO_TYPE_START_EO;
    19232138        }
    19242139
    1925   }
     2140      }
    19262141      else //Cr, follow Cb SAO type
    19272142      {
    1928         ctbParam.modeIdc = saoBlkParam[SAO_Cb].modeIdc;
    1929         ctbParam.typeIdc = saoBlkParam[SAO_Cb].typeIdc;
    1930 }
     2143        ctbParam.modeIdc = saoBlkParam[COMPONENT_Cb].modeIdc;
     2144        ctbParam.typeIdc = saoBlkParam[COMPONENT_Cb].typeIdc;
     2145      }
    19312146
    19322147      if(ctbParam.modeIdc == SAO_MODE_NEW)
    1933 {
     2148      {
    19342149        Int offset[4];
    19352150        for(Int i=0; i< 4; i++)
    1936   {
    1937           parseSaoMaxUvlc(uiSymbol,  g_saoMaxOffsetQVal[compIdx] ); //sao_offset_abs
     2151        {
     2152          parseSaoMaxUvlc(uiSymbol, maxOffsetQVal ); //sao_offset_abs
    19382153          offset[i] = (Int)uiSymbol;
    1939   }
     2154        }
    19402155
    19412156        if(ctbParam.typeIdc == SAO_TYPE_START_BO)
    1942   {
     2157        {
    19432158          for(Int i=0; i< 4; i++)
    1944     {
     2159          {
    19452160            if(offset[i] != 0)
    1946     {
     2161            {
    19472162              parseSaoSign(uiSymbol); //sao_offset_sign
    19482163              if(uiSymbol)
    1949       {
     2164              {
     2165#if O0043_BEST_EFFORT_DECODING
     2166                offset[i] >>= forceBitDepthAdjust;
     2167#endif
    19502168                offset[i] = -offset[i];
    1951       }
    1952     }
    1953   }
     2169              }
     2170            }
     2171          }
    19542172          parseSaoUflc(NUM_SAO_BO_CLASSES_LOG2, uiSymbol ); //sao_band_position
    19552173          ctbParam.typeAuxInfo = uiSymbol;
    19562174
    19572175          for(Int i=0; i<4; i++)
    1958       {
     2176          {
    19592177            ctbParam.offset[(ctbParam.typeAuxInfo+i)%MAX_NUM_SAO_CLASSES] = offset[i];
    1960       }
     2178          }
    19612179
    19622180        }
     
    19652183          ctbParam.typeAuxInfo = 0;
    19662184
    1967           if(compIdx == SAO_Y || compIdx == SAO_Cb)
    1968         {
     2185          if(firstCompOfChType == compIdx)
     2186          {
    19692187            parseSaoUflc(NUM_SAO_EO_TYPES_LOG2, uiSymbol ); //sao_eo_class_luma or sao_eo_class_chroma
    19702188            ctbParam.typeIdc += uiSymbol;
    1971         }
    1972         else
    1973         {
    1974             ctbParam.typeIdc = saoBlkParam[SAO_Cb].typeIdc;
    1975         }
     2189          }
     2190          else
     2191          {
     2192            ctbParam.typeIdc = saoBlkParam[firstCompOfChType].typeIdc;
     2193          }
    19762194          ctbParam.offset[SAO_CLASS_EO_FULL_VALLEY] = offset[0];
    19772195          ctbParam.offset[SAO_CLASS_EO_HALF_VALLEY] = offset[1];
     
    19792197          ctbParam.offset[SAO_CLASS_EO_HALF_PEAK  ] = -offset[2];
    19802198          ctbParam.offset[SAO_CLASS_EO_FULL_PEAK  ] = -offset[3];
    1981       }
     2199        }
    19822200      }
    19832201    }
     
    19902208 \param pSrc Contexts to be copied.
    19912209 */
    1992 Void TDecSbac::xCopyContextsFrom( TDecSbac* pSrc )
     2210Void TDecSbac::xCopyContextsFrom( const TDecSbac* pSrc )
    19932211{
    19942212  memcpy(m_contextModels, pSrc->m_contextModels, m_numContextModels*sizeof(m_contextModels[0]));
    1995 }
    1996 
    1997 Void TDecSbac::xCopyFrom( TDecSbac* pSrc )
     2213  memcpy(m_golombRiceAdaptationStatistics, pSrc->m_golombRiceAdaptationStatistics, (sizeof(UInt) * RExt__GOLOMB_RICE_ADAPTATION_STATISTICS_SETS));
     2214}
     2215
     2216Void TDecSbac::xCopyFrom( const TDecSbac* pSrc )
    19982217{
    19992218  m_pcTDecBinIf->copyState( pSrc->m_pcTDecBinIf );
    2000 
    2001   m_uiLastQp           = pSrc->m_uiLastQp;
    20022219  xCopyContextsFrom( pSrc );
    2003 
    2004 }
    2005 
    2006 Void TDecSbac::load ( TDecSbac* pScr )
    2007 {
    2008   xCopyFrom(pScr);
    2009 }
    2010 
    2011 Void TDecSbac::loadContexts ( TDecSbac* pScr )
    2012 {
    2013   xCopyContextsFrom(pScr);
    2014 }
    2015 
    2016 #if H_3D_ARP
     2220}
     2221
     2222Void TDecSbac::load ( const TDecSbac* pSrc )
     2223{
     2224  xCopyFrom(pSrc);
     2225}
     2226
     2227Void TDecSbac::loadContexts ( const TDecSbac* pSrc )
     2228{
     2229  xCopyContextsFrom(pSrc);
     2230}
     2231
     2232/** Performs CABAC decoding of the explicit RDPCM mode
     2233 * \param rTu current TU data structure
     2234 * \param compID component identifier
     2235 */
     2236Void TDecSbac::parseExplicitRdpcmMode( TComTU &rTu, ComponentID compID )
     2237{
     2238  TComDataCU* cu = rTu.getCU();
     2239  const UInt absPartIdx=rTu.GetAbsPartIdxTU(compID);
     2240  const TComRectangle &rect = rTu.getRect(compID);
     2241  const UInt tuHeight = g_aucConvertToBit[rect.height];
     2242  const UInt tuWidth  = g_aucConvertToBit[rect.width];
     2243  UInt code = 0;
     2244
     2245  assert(tuHeight == tuWidth);
     2246
     2247#if RExt__DECODER_DEBUG_BIT_STATISTICS
     2248  const TComCodingStatisticsClassType ctype(STATS__EXPLICIT_RDPCM_BITS, g_aucConvertToBit[cu->getSlice()->getSPS()->getMaxCUWidth()>>rTu.GetTransformDepthTotal()]+2);
     2249#endif
     2250
     2251  m_pcTDecBinIf->decodeBin(code, m_explicitRdpcmFlagSCModel.get (0, toChannelType(compID), 0) RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(ctype));
     2252
     2253  if(code == 0)
     2254  {
     2255    cu->setExplicitRdpcmModePartRange( RDPCM_OFF, compID, absPartIdx, rTu.GetAbsPartIdxNumParts(compID));
     2256  }
     2257  else
     2258  {
     2259    m_pcTDecBinIf->decodeBin(code, m_explicitRdpcmDirSCModel.get (0, toChannelType(compID), 0) RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(ctype));
     2260    if(code == 0)
     2261    {
     2262      cu->setExplicitRdpcmModePartRange( RDPCM_HOR, compID, absPartIdx, rTu.GetAbsPartIdxNumParts(compID));
     2263    }
     2264    else
     2265    {
     2266      cu->setExplicitRdpcmModePartRange( RDPCM_VER, compID, absPartIdx, rTu.GetAbsPartIdxNumParts(compID));
     2267    }
     2268  }
     2269}
     2270
     2271#if NH_3D_ARP
    20172272Void TDecSbac::parseARPW( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
    20182273{
    2019   UInt uiMaxW = pcCU->getSlice()->getARPStepNum() - 1;
    20202274  UInt uiW = 0;
    20212275  UInt uiOffset = pcCU->getCTXARPWFlag(uiAbsPartIdx);
    20222276  UInt uiCode = 0;
    20232277
    2024   assert ( uiMaxW > 0 );
    2025 
    2026   m_pcTDecBinIf->decodeBin( uiCode , m_cCUPUARPWSCModel.get( 0, 0, 0 + uiOffset ) );
     2278  m_pcTDecBinIf->decodeBin( uiCode , m_cCUPUARPWSCModel.get( 0, 0, 0 + uiOffset ) RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(STATS__CABAC_BITS__ARP_FLAG));
    20272279
    20282280  uiW = uiCode;
    20292281  if( 1 == uiW )   
    20302282  {
    2031     m_pcTDecBinIf->decodeBin( uiCode , m_cCUPUARPWSCModel.get( 0, 0, 2 ) );
     2283    m_pcTDecBinIf->decodeBin( uiCode , m_cCUPUARPWSCModel.get( 0, 0, 2 ) RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(STATS__CABAC_BITS__ARP_FLAG));
    20322284    uiW += ( 1 == uiCode ? 1 : 0 );
    20332285  }
     
    20392291#endif
    20402292
    2041 #if H_3D_IC
     2293#if NH_3D_IC
    20422294/** parse illumination compensation flag
    20432295 * \param pcCU
     
    20492301{
    20502302  UInt uiSymbol = 0;
    2051   m_pcTDecBinIf->decodeBin( uiSymbol, m_cCUICFlagSCModel.get( 0, 0, 0 ) );
     2303  m_pcTDecBinIf->decodeBin( uiSymbol, m_cCUICFlagSCModel.get( 0, 0, 0 ) RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(STATS__CABAC_BITS__3D_IC) );
     2304
    20522305#if !H_MV_ENC_DEC_TRAC
    20532306  DTRACE_CABAC_VL( g_nSymbolCounter++ );
     
    20662319#endif
    20672320
    2068 #if H_3D_INTER_SDC
     2321#if NH_3D_DMM || NH_3D_SDC_INTRA || NH_3D_SDC_INTER
    20692322Void TDecSbac::parseDeltaDC( TComDataCU* pcCU, UInt absPartIdx, UInt depth )
    20702323{
    2071   if( ! ( pcCU->getSDCFlag( absPartIdx ) || ( pcCU->isIntra( absPartIdx ) && getDimType( pcCU->getLumaIntraDir( absPartIdx ) ) < DIM_NUM_TYPE ) ) )
    2072   {
     2324#if NH_3D_SDC_INTRA || NH_3D_SDC_INTER
     2325  if( !(pcCU->getSDCFlag( absPartIdx )) )
     2326#endif
     2327#if NH_3D_DMM
     2328  if( !(pcCU->isIntra( absPartIdx ) && isDmmMode( pcCU->getIntraDir( CHANNEL_TYPE_LUMA, absPartIdx ) )) )
     2329#endif
    20732330    assert( 0 );
    2074   }
    20752331
    20762332  UInt symbol = 1;
    2077   UInt uiNumSegments = isDimMode( pcCU->getLumaIntraDir( absPartIdx ) ) ? 2 : 1;
    2078 
     2333#if NH_3D_SDC_INTRA
    20792334  if( pcCU->isIntra( absPartIdx ) && pcCU->getSDCFlag( absPartIdx ))
    20802335  {
    2081 
    2082     m_pcTDecBinIf->decodeBin( symbol, m_cDdcFlagSCModel.get( 0, 0, 0 ) );
    2083       assert( pcCU->getPartitionSize( absPartIdx ) == SIZE_2Nx2N );
    2084       pcCU->setTrIdxSubParts( 0, absPartIdx, depth );
    2085       pcCU->setCbfSubParts( 1, 1, 1, absPartIdx, depth );
    2086     }
     2336    m_pcTDecBinIf->decodeBin( symbol, m_cDdcFlagSCModel.get( 0, 0, 0 ) RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(STATS__CABAC_BITS__SDC_DELTADC_FLAG) );
     2337    assert( pcCU->getPartitionSize( absPartIdx ) == SIZE_2Nx2N );
     2338    assert( pcCU->getTransformIdx(absPartIdx) == 0 );
     2339    assert( pcCU->getCbf(absPartIdx, COMPONENT_Y) == 1 );
     2340    }
     2341#endif
     2342  UInt uiNumSegments = 1;
     2343#if NH_3D_DMM
     2344  uiNumSegments = isDmmMode( pcCU->getIntraDir( CHANNEL_TYPE_LUMA, absPartIdx ) ) ? 2 : 1;
     2345#endif
    20872346
    20882347  for( UInt segment = 0; segment < uiNumSegments; segment++ )
     
    20912350    if( symbol )
    20922351    {
    2093       xParseDimDeltaDC( valDeltaDC, uiNumSegments );
     2352      xParseDeltaDC( valDeltaDC, uiNumSegments );
    20942353    }
    20952354
    20962355    if( pcCU->isIntra( absPartIdx ) )
    20972356    {
    2098       UInt dir     = pcCU->getLumaIntraDir( absPartIdx );
    2099 
     2357#if NH_3D_SDC_INTRA
    21002358      if( pcCU->getSDCFlag( absPartIdx ) )
    21012359      {
     
    21042362      else
    21052363      {
    2106         pcCU->setDimDeltaDC( getDimType( dir ), segment, absPartIdx, valDeltaDC );
    2107       }
    2108     }
     2364#endif
     2365#if NH_3D_DMM
     2366        pcCU->setDmmDeltaDC( getDmmType( pcCU->getIntraDir( CHANNEL_TYPE_LUMA, absPartIdx ) ), segment, absPartIdx, valDeltaDC );
     2367#endif
     2368#if NH_3D_SDC_INTRA
     2369      }
     2370#endif
     2371    }
     2372#if NH_3D_SDC_INTER
    21092373    else
    21102374    {
    21112375      pcCU->setSDCSegmentDCOffset( valDeltaDC, segment, absPartIdx );
    21122376    }
    2113   }
    2114 }
    2115 
     2377#endif
     2378  }
     2379}
     2380
     2381Void TDecSbac::xParseDeltaDC( Pel& rValDeltaDC, UInt uiNumSeg )
     2382{
     2383  UInt absValDeltaDC = 0;
     2384  xReadExGolombLevelDdc( absValDeltaDC );
     2385  rValDeltaDC = (Pel)absValDeltaDC + ( uiNumSeg > 1 ? 0 : 1 );
     2386
     2387  if( rValDeltaDC != 0 )
     2388  {
     2389    UInt uiSign;
     2390    m_pcTDecBinIf->decodeBinEP( uiSign RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(STATS__CABAC_BITS__DELTADC_SIGN_EP) );
     2391    if ( uiSign )
     2392    {
     2393      rValDeltaDC = -rValDeltaDC;
     2394    }
     2395  }
     2396#if H_MV_ENC_DEC_TRAC
     2397  DTRACE_CU("delta_dc", rValDeltaDC);
     2398#endif
     2399}
     2400
     2401Void TDecSbac::xReadExGolombLevelDdc( UInt& ruiSymbol )
     2402{
     2403  UInt uiSymbol;
     2404  UInt uiCount = 0;
     2405  do
     2406  {
     2407    m_pcTDecBinIf->decodeBin( uiSymbol, m_cDdcDataSCModel.get(0, 0, 0) RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(STATS__CABAC_BITS__DELTADC_PREFIX) );
     2408    uiCount++;
     2409  }
     2410  while( uiSymbol && ( uiCount != 3 ) );
     2411  ruiSymbol = uiCount - 1;
     2412
     2413  if( uiSymbol )
     2414  {
     2415    xReadEpExGolomb( uiSymbol, 0 RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(STATS__CABAC_BITS__DELTADC_SUFFIX_EP) );
     2416    ruiSymbol += uiSymbol + 1;
     2417  }
     2418
     2419  return;
     2420}
     2421#endif
     2422#if NH_3D_DMM
     2423Void TDecSbac::xParseIntraDepthMode( TComDataCU* pcCU, UInt absPartIdx, UInt depth )
     2424{
     2425  pcCU->setIntraDirSubParts( CHANNEL_TYPE_LUMA, 0, absPartIdx, depth );
     2426
     2427  UInt uiSymbol;
     2428  if( ( pcCU->getSlice()->getSPS()->getMaxCUWidth() >> pcCU->getDepth( absPartIdx ) ) < 64 ) //DMM and HEVC intra modes are both allowed
     2429  {
     2430    m_pcTDecBinIf->decodeBin( uiSymbol, m_cNotDmmFlagSCModel.get( 0, 0, 0 ) RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(STATS__CABAC_BITS__NOTDMM_FLAG) );
     2431  }
     2432  else
     2433  {
     2434    uiSymbol = 1;
     2435  }
     2436
     2437  //decode DMM mode index
     2438  if( !uiSymbol )
     2439  {
     2440    if( pcCU->getSlice()->getIntraSdcWedgeFlag() && pcCU->getSlice()->getIntraContourFlag() )
     2441    {
     2442      m_pcTDecBinIf->decodeBin( uiSymbol, m_cDmmModeSCModel.get( 0, 0, 0 ) RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(STATS__CABAC_BITS__DMMMODE) );
     2443      if( !uiSymbol )
     2444      {
     2445        pcCU->setIntraDirSubParts( CHANNEL_TYPE_LUMA, DMM_OFFSET, absPartIdx, depth );
     2446      }
     2447      else
     2448      {
     2449        pcCU->setIntraDirSubParts( CHANNEL_TYPE_LUMA, ( 1+ DMM_OFFSET ), absPartIdx, depth );
     2450      }
     2451    }
     2452    else if( pcCU->getSlice()->getIntraSdcWedgeFlag() )
     2453    {
     2454      pcCU->setIntraDirSubParts( CHANNEL_TYPE_LUMA, DMM_OFFSET, absPartIdx, depth );
     2455    }
     2456    else if( pcCU->getSlice()->getIntraContourFlag() )
     2457    {
     2458      pcCU->setIntraDirSubParts( CHANNEL_TYPE_LUMA, ( 1+ DMM_OFFSET ), absPartIdx, depth );
     2459    }
     2460  }
     2461}
     2462
     2463Void TDecSbac::xParseDmmData( TComDataCU* pcCU, UInt absPartIdx, UInt depth )
     2464{
     2465  UInt dir = pcCU->getIntraDir( CHANNEL_TYPE_LUMA, absPartIdx );
     2466  switch( getDmmType( dir ) )
     2467  {
     2468  case( DMM1_IDX ):
     2469    {
     2470      UInt uiTabIdx = 0;
     2471      xParseDmm1WedgeIdx( uiTabIdx, g_dmm1TabIdxBits[pcCU->getIntraSizeIdx(absPartIdx)] );
     2472      assert( uiTabIdx < getWedgeListScaled( pcCU->getWidth( absPartIdx ) )->size() );
     2473      pcCU->setDmm1WedgeTabIdxSubParts( uiTabIdx, absPartIdx, depth );
     2474    } break;
     2475  case( DMM4_IDX ): break;
     2476  default: break;
     2477  }
     2478}
     2479
     2480Void TDecSbac::xParseDmm1WedgeIdx( UInt& ruiTabIdx, Int iNumBit )
     2481{
     2482  UInt uiSymbol, uiIdx = 0;
     2483  for( Int i = 0; i < iNumBit; i++ )
     2484  {
     2485    m_pcTDecBinIf->decodeBinEP( uiSymbol RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(STATS__CABAC_BITS__DMM1_BITS_EP) );
     2486    uiIdx += uiSymbol << i;
     2487  }
     2488  ruiTabIdx = uiIdx;
     2489}
     2490#endif
     2491#if NH_3D_SDC_INTRA || NH_3D_SDC_INTER
    21162492Void TDecSbac::parseSDCFlag( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
    21172493{
    21182494  UInt uiSymbol = 0;
    2119   UInt uiCtxSDCFlag = pcCU->getCtxSDCFlag( uiAbsPartIdx );
    2120 
    2121   m_pcTDecBinIf->decodeBin( uiSymbol, m_cSDCFlagSCModel.get( 0, 0, uiCtxSDCFlag ) );
     2495
     2496  m_pcTDecBinIf->decodeBin( uiSymbol, m_cSDCFlagSCModel.get( 0, 0, 0 ) RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(STATS__CABAC_BITS__SDC_INTRA_FLAG) );
     2497#if H_MV_ENC_DEC_TRAC
    21222498  DTRACE_CU("dc_only_flag", uiSymbol)
     2499#endif
    21232500  if( uiSymbol )
    21242501  {
    21252502    pcCU->setSDCFlagSubParts( true, uiAbsPartIdx, uiDepth );
    21262503    pcCU->setTrIdxSubParts( 0, uiAbsPartIdx, uiDepth );
    2127     pcCU->setCbfSubParts( 1, 1, 1, uiAbsPartIdx, uiDepth );
     2504    pcCU->setCbfSubParts(1, COMPONENT_Y, uiAbsPartIdx, uiDepth);
    21282505  }
    21292506  else
     
    21352512#endif
    21362513
    2137 #if H_3D_DBBP
     2514#if NH_3D_DBBP
    21382515Void TDecSbac::parseDBBPFlag( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
    21392516{
     
    21432520  UInt uiSymbol = 0;
    21442521 
    2145   m_pcTDecBinIf->decodeBin( uiSymbol, m_cDBBPFlagSCModel.get( 0, 0, 0 ) );
     2522  m_pcTDecBinIf->decodeBin( uiSymbol, m_cDBBPFlagSCModel.get( 0, 0, 0 ) RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(STATS__CABAC_BITS__DBBP_FLAG) );
    21462523  DTRACE_CU("dbbp_flag", uiSymbol)
    21472524  PartSize ePartSize = pcCU->getPartitionSize( uiAbsPartIdx );
    21482525  AOF( ePartSize == SIZE_2NxN || ePartSize == SIZE_Nx2N );
    2149   UInt uiPUOffset = ( g_auiPUOffset[UInt( ePartSize )] << ( ( pcCU->getSlice()->getSPS()->getMaxCUDepth() - uiDepth ) << 1 ) ) >> 4;
     2526  UInt uiPUOffset = ( g_auiPUOffset[UInt( ePartSize )] << ( ( pcCU->getSlice()->getSPS()->getMaxTotalCUDepth() - uiDepth ) << 1 ) ) >> 4;
    21502527  pcCU->setDBBPFlagSubParts(uiSymbol, uiAbsPartIdx, 0, uiDepth);
    21512528  pcCU->setDBBPFlagSubParts(uiSymbol, uiAbsPartIdx+uiPUOffset, 1, uiDepth);
     
    21542531
    21552532
    2156 
    21572533//! \}
Note: See TracChangeset for help on using the changeset viewer.