Changeset 1029 in SHVCSoftware for branches/SHM-dev/source/Lib/TLibEncoder/TEncSbac.cpp
- Timestamp:
- 26 Feb 2015, 00:21:54 (10 years ago)
- Location:
- branches/SHM-dev
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/SHM-dev
- Property svn:mergeinfo changed
-
branches/SHM-dev/source
- Property svn:mergeinfo changed
-
branches/SHM-dev/source/Lib/TLibEncoder/TEncSbac.cpp
r713 r1029 2 2 * License, included below. This software may be subject to other third party 3 3 * and contributor rights, including patent rights, and no such rights are 4 * granted under this license. 4 * granted under this license. 5 5 * 6 6 * Copyright (c) 2010-2014, ITU/ISO/IEC … … 38 38 #include "TEncTop.h" 39 39 #include "TEncSbac.h" 40 #include "TLibCommon/TComTU.h" 40 41 41 42 #include <map> 42 43 #include <algorithm> 44 45 #if ENVIRONMENT_VARIABLE_DEBUG_AND_TEST 46 #include "../TLibCommon/Debug.h" 47 #endif 48 43 49 44 50 //! \ingroup TLibEncoder … … 51 57 TEncSbac::TEncSbac() 52 58 // new structure here 53 : m_pcBitIf ( NULL ) 54 , m_pcSlice ( NULL ) 55 , m_pcBinIf ( NULL ) 56 , m_uiCoeffCost ( 0 ) 57 , m_numContextModels ( 0 ) 58 , m_cCUSplitFlagSCModel ( 1, 1, NUM_SPLIT_FLAG_CTX , m_contextModels + m_numContextModels, m_numContextModels ) 59 , m_cCUSkipFlagSCModel ( 1, 1, NUM_SKIP_FLAG_CTX , m_contextModels + m_numContextModels, m_numContextModels) 60 , m_cCUMergeFlagExtSCModel ( 1, 1, NUM_MERGE_FLAG_EXT_CTX , m_contextModels + m_numContextModels, m_numContextModels) 61 , m_cCUMergeIdxExtSCModel ( 1, 1, NUM_MERGE_IDX_EXT_CTX , m_contextModels + m_numContextModels, m_numContextModels) 62 , m_cCUPartSizeSCModel ( 1, 1, NUM_PART_SIZE_CTX , m_contextModels + m_numContextModels, m_numContextModels) 63 , m_cCUPredModeSCModel ( 1, 1, NUM_PRED_MODE_CTX , m_contextModels + m_numContextModels, m_numContextModels) 64 , m_cCUIntraPredSCModel ( 1, 1, NUM_ADI_CTX , m_contextModels + m_numContextModels, m_numContextModels) 65 , m_cCUChromaPredSCModel ( 1, 1, NUM_CHROMA_PRED_CTX , m_contextModels + m_numContextModels, m_numContextModels) 66 , m_cCUDeltaQpSCModel ( 1, 1, NUM_DELTA_QP_CTX , m_contextModels + m_numContextModels, m_numContextModels) 67 , m_cCUInterDirSCModel ( 1, 1, NUM_INTER_DIR_CTX , m_contextModels + m_numContextModels, m_numContextModels) 68 , m_cCURefPicSCModel ( 1, 1, NUM_REF_NO_CTX , m_contextModels + m_numContextModels, m_numContextModels) 69 , m_cCUMvdSCModel ( 1, 1, NUM_MV_RES_CTX , m_contextModels + m_numContextModels, m_numContextModels) 70 , m_cCUQtCbfSCModel ( 1, 2, NUM_QT_CBF_CTX , m_contextModels + m_numContextModels, m_numContextModels) 71 , m_cCUTransSubdivFlagSCModel ( 1, 1, NUM_TRANS_SUBDIV_FLAG_CTX , m_contextModels + m_numContextModels, m_numContextModels) 72 , m_cCUQtRootCbfSCModel ( 1, 1, NUM_QT_ROOT_CBF_CTX , m_contextModels + m_numContextModels, m_numContextModels) 73 , m_cCUSigCoeffGroupSCModel ( 1, 2, NUM_SIG_CG_FLAG_CTX , m_contextModels + m_numContextModels, m_numContextModels) 74 , m_cCUSigSCModel ( 1, 1, NUM_SIG_FLAG_CTX , m_contextModels + m_numContextModels, m_numContextModels) 75 , m_cCuCtxLastX ( 1, 2, NUM_CTX_LAST_FLAG_XY , m_contextModels + m_numContextModels, m_numContextModels) 76 , m_cCuCtxLastY ( 1, 2, NUM_CTX_LAST_FLAG_XY , m_contextModels + m_numContextModels, m_numContextModels) 77 , m_cCUOneSCModel ( 1, 1, NUM_ONE_FLAG_CTX , m_contextModels + m_numContextModels, m_numContextModels) 78 , m_cCUAbsSCModel ( 1, 1, NUM_ABS_FLAG_CTX , m_contextModels + m_numContextModels, m_numContextModels) 79 , m_cMVPIdxSCModel ( 1, 1, NUM_MVP_IDX_CTX , m_contextModels + m_numContextModels, m_numContextModels) 80 , m_cSaoMergeSCModel ( 1, 1, NUM_SAO_MERGE_FLAG_CTX , m_contextModels + m_numContextModels, m_numContextModels) 81 , m_cSaoTypeIdxSCModel ( 1, 1, NUM_SAO_TYPE_IDX_CTX , m_contextModels + m_numContextModels, m_numContextModels) 82 , m_cTransformSkipSCModel ( 1, 2, NUM_TRANSFORMSKIP_FLAG_CTX , m_contextModels + m_numContextModels, m_numContextModels) 83 , m_CUTransquantBypassFlagSCModel( 1, 1, NUM_CU_TRANSQUANT_BYPASS_FLAG_CTX, m_contextModels + m_numContextModels, m_numContextModels) 59 : m_pcBitIf ( NULL ) 60 , m_pcSlice ( NULL ) 61 , m_pcBinIf ( NULL ) 62 , m_numContextModels ( 0 ) 63 , m_cCUSplitFlagSCModel ( 1, 1, NUM_SPLIT_FLAG_CTX , m_contextModels + m_numContextModels, m_numContextModels) 64 , m_cCUSkipFlagSCModel ( 1, 1, NUM_SKIP_FLAG_CTX , m_contextModels + m_numContextModels, m_numContextModels) 65 , m_cCUMergeFlagExtSCModel ( 1, 1, NUM_MERGE_FLAG_EXT_CTX , m_contextModels + m_numContextModels, m_numContextModels) 66 , m_cCUMergeIdxExtSCModel ( 1, 1, NUM_MERGE_IDX_EXT_CTX , m_contextModels + m_numContextModels, m_numContextModels) 67 , m_cCUPartSizeSCModel ( 1, 1, NUM_PART_SIZE_CTX , m_contextModels + m_numContextModels, m_numContextModels) 68 , m_cCUPredModeSCModel ( 1, 1, NUM_PRED_MODE_CTX , m_contextModels + m_numContextModels, m_numContextModels) 69 , m_cCUIntraPredSCModel ( 1, 1, NUM_ADI_CTX , m_contextModels + m_numContextModels, m_numContextModels) 70 , m_cCUChromaPredSCModel ( 1, 1, NUM_CHROMA_PRED_CTX , m_contextModels + m_numContextModels, m_numContextModels) 71 , m_cCUDeltaQpSCModel ( 1, 1, NUM_DELTA_QP_CTX , m_contextModels + m_numContextModels, m_numContextModels) 72 , m_cCUInterDirSCModel ( 1, 1, NUM_INTER_DIR_CTX , m_contextModels + m_numContextModels, m_numContextModels) 73 , m_cCURefPicSCModel ( 1, 1, NUM_REF_NO_CTX , m_contextModels + m_numContextModels, m_numContextModels) 74 , m_cCUMvdSCModel ( 1, 1, NUM_MV_RES_CTX , m_contextModels + m_numContextModels, m_numContextModels) 75 , m_cCUQtCbfSCModel ( 1, NUM_QT_CBF_CTX_SETS, NUM_QT_CBF_CTX_PER_SET , m_contextModels + m_numContextModels, m_numContextModels) 76 , m_cCUTransSubdivFlagSCModel ( 1, 1, NUM_TRANS_SUBDIV_FLAG_CTX , m_contextModels + m_numContextModels, m_numContextModels) 77 , m_cCUQtRootCbfSCModel ( 1, 1, NUM_QT_ROOT_CBF_CTX , m_contextModels + m_numContextModels, m_numContextModels) 78 , m_cCUSigCoeffGroupSCModel ( 1, 2, NUM_SIG_CG_FLAG_CTX , m_contextModels + m_numContextModels, m_numContextModels) 79 , m_cCUSigSCModel ( 1, 1, NUM_SIG_FLAG_CTX , m_contextModels + m_numContextModels, m_numContextModels) 80 , m_cCuCtxLastX ( 1, NUM_CTX_LAST_FLAG_SETS, NUM_CTX_LAST_FLAG_XY , m_contextModels + m_numContextModels, m_numContextModels) 81 , m_cCuCtxLastY ( 1, NUM_CTX_LAST_FLAG_SETS, NUM_CTX_LAST_FLAG_XY , m_contextModels + m_numContextModels, m_numContextModels) 82 , m_cCUOneSCModel ( 1, 1, NUM_ONE_FLAG_CTX , m_contextModels + m_numContextModels, m_numContextModels) 83 , m_cCUAbsSCModel ( 1, 1, NUM_ABS_FLAG_CTX , m_contextModels + m_numContextModels, m_numContextModels) 84 , m_cMVPIdxSCModel ( 1, 1, NUM_MVP_IDX_CTX , m_contextModels + m_numContextModels, m_numContextModels) 85 , m_cSaoMergeSCModel ( 1, 1, NUM_SAO_MERGE_FLAG_CTX , m_contextModels + m_numContextModels, m_numContextModels) 86 , m_cSaoTypeIdxSCModel ( 1, 1, NUM_SAO_TYPE_IDX_CTX , m_contextModels + m_numContextModels, m_numContextModels) 87 , m_cTransformSkipSCModel ( 1, MAX_NUM_CHANNEL_TYPE, NUM_TRANSFORMSKIP_FLAG_CTX , m_contextModels + m_numContextModels, m_numContextModels) 88 , m_CUTransquantBypassFlagSCModel ( 1, 1, NUM_CU_TRANSQUANT_BYPASS_FLAG_CTX , m_contextModels + m_numContextModels, m_numContextModels) 89 , m_explicitRdpcmFlagSCModel ( 1, MAX_NUM_CHANNEL_TYPE, NUM_EXPLICIT_RDPCM_FLAG_CTX , m_contextModels + m_numContextModels, m_numContextModels) 90 , m_explicitRdpcmDirSCModel ( 1, MAX_NUM_CHANNEL_TYPE, NUM_EXPLICIT_RDPCM_DIR_CTX , m_contextModels + m_numContextModels, m_numContextModels) 91 , m_cCrossComponentPredictionSCModel ( 1, 1, NUM_CROSS_COMPONENT_PREDICTION_CTX , m_contextModels + m_numContextModels, m_numContextModels) 92 , m_ChromaQpAdjFlagSCModel ( 1, 1, NUM_CHROMA_QP_ADJ_FLAG_CTX , m_contextModels + m_numContextModels, m_numContextModels) 93 , m_ChromaQpAdjIdcSCModel ( 1, 1, NUM_CHROMA_QP_ADJ_IDC_CTX , m_contextModels + m_numContextModels, m_numContextModels) 84 94 { 85 95 assert( m_numContextModels <= MAX_NUM_CTX_MOD ); … … 98 108 Int iQp = m_pcSlice->getSliceQp(); 99 109 SliceType eSliceType = m_pcSlice->getSliceType(); 100 110 101 111 Int encCABACTableIdx = m_pcSlice->getPPS()->getEncCABACTableIdx(); 102 112 if (!m_pcSlice->isIntra() && (encCABACTableIdx==B_SLICE || encCABACTableIdx==P_SLICE) && m_pcSlice->getPPS()->getCabacInitPresentFlag()) … … 105 115 } 106 116 107 m_cCUSplitFlagSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_SPLIT_FLAG ); 108 109 m_cCUSkipFlagSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_SKIP_FLAG ); 110 m_cCUMergeFlagExtSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_MERGE_FLAG_EXT); 111 m_cCUMergeIdxExtSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_MERGE_IDX_EXT); 112 m_cCUPartSizeSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_PART_SIZE ); 113 m_cCUPredModeSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_PRED_MODE ); 114 m_cCUIntraPredSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_INTRA_PRED_MODE ); 115 m_cCUChromaPredSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_CHROMA_PRED_MODE ); 116 m_cCUInterDirSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_INTER_DIR ); 117 m_cCUMvdSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_MVD ); 118 m_cCURefPicSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_REF_PIC ); 119 m_cCUDeltaQpSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_DQP ); 120 m_cCUQtCbfSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_QT_CBF ); 121 m_cCUQtRootCbfSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_QT_ROOT_CBF ); 122 m_cCUSigCoeffGroupSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_SIG_CG_FLAG ); 123 m_cCUSigSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_SIG_FLAG ); 124 m_cCuCtxLastX.initBuffer ( eSliceType, iQp, (UChar*)INIT_LAST ); 125 m_cCuCtxLastY.initBuffer ( eSliceType, iQp, (UChar*)INIT_LAST ); 126 m_cCUOneSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_ONE_FLAG ); 127 m_cCUAbsSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_ABS_FLAG ); 128 m_cMVPIdxSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_MVP_IDX ); 129 m_cCUTransSubdivFlagSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_TRANS_SUBDIV_FLAG ); 130 m_cSaoMergeSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_SAO_MERGE_FLAG ); 131 m_cSaoTypeIdxSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_SAO_TYPE_IDX ); 132 m_cTransformSkipSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_TRANSFORMSKIP_FLAG ); 133 m_CUTransquantBypassFlagSCModel.initBuffer( eSliceType, iQp, (UChar*)INIT_CU_TRANSQUANT_BYPASS_FLAG ); 134 // new structure 135 m_uiLastQp = iQp; 136 117 m_cCUSplitFlagSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_SPLIT_FLAG ); 118 m_cCUSkipFlagSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_SKIP_FLAG ); 119 m_cCUMergeFlagExtSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_MERGE_FLAG_EXT); 120 m_cCUMergeIdxExtSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_MERGE_IDX_EXT); 121 m_cCUPartSizeSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_PART_SIZE ); 122 m_cCUPredModeSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_PRED_MODE ); 123 m_cCUIntraPredSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_INTRA_PRED_MODE ); 124 m_cCUChromaPredSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_CHROMA_PRED_MODE ); 125 m_cCUInterDirSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_INTER_DIR ); 126 m_cCUMvdSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_MVD ); 127 m_cCURefPicSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_REF_PIC ); 128 m_cCUDeltaQpSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_DQP ); 129 m_cCUQtCbfSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_QT_CBF ); 130 m_cCUQtRootCbfSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_QT_ROOT_CBF ); 131 m_cCUSigCoeffGroupSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_SIG_CG_FLAG ); 132 m_cCUSigSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_SIG_FLAG ); 133 m_cCuCtxLastX.initBuffer ( eSliceType, iQp, (UChar*)INIT_LAST ); 134 m_cCuCtxLastY.initBuffer ( eSliceType, iQp, (UChar*)INIT_LAST ); 135 m_cCUOneSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_ONE_FLAG ); 136 m_cCUAbsSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_ABS_FLAG ); 137 m_cMVPIdxSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_MVP_IDX ); 138 m_cCUTransSubdivFlagSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_TRANS_SUBDIV_FLAG ); 139 m_cSaoMergeSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_SAO_MERGE_FLAG ); 140 m_cSaoTypeIdxSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_SAO_TYPE_IDX ); 141 m_cTransformSkipSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_TRANSFORMSKIP_FLAG ); 142 m_CUTransquantBypassFlagSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_CU_TRANSQUANT_BYPASS_FLAG ); 143 m_explicitRdpcmFlagSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_EXPLICIT_RDPCM_FLAG); 144 m_explicitRdpcmDirSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_EXPLICIT_RDPCM_DIR); 145 m_cCrossComponentPredictionSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_CROSS_COMPONENT_PREDICTION ); 146 m_ChromaQpAdjFlagSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_CHROMA_QP_ADJ_FLAG ); 147 m_ChromaQpAdjIdcSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_CHROMA_QP_ADJ_IDC ); 148 149 for (UInt statisticIndex = 0; statisticIndex < RExt__GOLOMB_RICE_ADAPTATION_STATISTICS_SETS ; statisticIndex++) 150 { 151 m_golombRiceAdaptationStatistics[statisticIndex] = 0; 152 } 153 137 154 m_pcBinIf->start(); 138 155 139 156 return; 140 157 } 141 158 142 /** The function does the following: 143 * If current slice type is P/B then it determines the distance of initialisation type 1 and 2 from the current CABAC states and 159 /** The function does the following: 160 * If current slice type is P/B then it determines the distance of initialisation type 1 and 2 from the current CABAC states and 144 161 * stores the index of the closest table. This index is used for the next P/B slice when cabac_init_present_flag is true. 145 162 */ … … 159 176 SliceType curSliceType = aSliceTypeChoices[idx]; 160 177 161 curCost = m_cCUSplitFlagSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_SPLIT_FLAG ); 162 curCost += m_cCUSkipFlagSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_SKIP_FLAG ); 163 curCost += m_cCUMergeFlagExtSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_MERGE_FLAG_EXT); 164 curCost += m_cCUMergeIdxExtSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_MERGE_IDX_EXT); 165 curCost += m_cCUPartSizeSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_PART_SIZE ); 166 curCost += m_cCUPredModeSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_PRED_MODE ); 167 curCost += m_cCUIntraPredSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_INTRA_PRED_MODE ); 168 curCost += m_cCUChromaPredSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_CHROMA_PRED_MODE ); 169 curCost += m_cCUInterDirSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_INTER_DIR ); 170 curCost += m_cCUMvdSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_MVD ); 171 curCost += m_cCURefPicSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_REF_PIC ); 172 curCost += m_cCUDeltaQpSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_DQP ); 173 curCost += m_cCUQtCbfSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_QT_CBF ); 174 curCost += m_cCUQtRootCbfSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_QT_ROOT_CBF ); 175 curCost += m_cCUSigCoeffGroupSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_SIG_CG_FLAG ); 176 curCost += m_cCUSigSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_SIG_FLAG ); 177 curCost += m_cCuCtxLastX.calcCost ( curSliceType, qp, (UChar*)INIT_LAST ); 178 curCost += m_cCuCtxLastY.calcCost ( curSliceType, qp, (UChar*)INIT_LAST ); 179 curCost += m_cCUOneSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_ONE_FLAG ); 180 curCost += m_cCUAbsSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_ABS_FLAG ); 181 curCost += m_cMVPIdxSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_MVP_IDX ); 182 curCost += m_cCUTransSubdivFlagSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_TRANS_SUBDIV_FLAG ); 183 curCost += m_cSaoMergeSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_SAO_MERGE_FLAG ); 184 curCost += m_cSaoTypeIdxSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_SAO_TYPE_IDX ); 185 curCost += m_cTransformSkipSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_TRANSFORMSKIP_FLAG ); 186 curCost += m_CUTransquantBypassFlagSCModel.calcCost( curSliceType, qp, (UChar*)INIT_CU_TRANSQUANT_BYPASS_FLAG ); 178 curCost = m_cCUSplitFlagSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_SPLIT_FLAG ); 179 curCost += m_cCUSkipFlagSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_SKIP_FLAG ); 180 curCost += m_cCUMergeFlagExtSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_MERGE_FLAG_EXT); 181 curCost += m_cCUMergeIdxExtSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_MERGE_IDX_EXT); 182 curCost += m_cCUPartSizeSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_PART_SIZE ); 183 curCost += m_cCUPredModeSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_PRED_MODE ); 184 curCost += m_cCUIntraPredSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_INTRA_PRED_MODE ); 185 curCost += m_cCUChromaPredSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_CHROMA_PRED_MODE ); 186 curCost += m_cCUInterDirSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_INTER_DIR ); 187 curCost += m_cCUMvdSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_MVD ); 188 curCost += m_cCURefPicSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_REF_PIC ); 189 curCost += m_cCUDeltaQpSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_DQP ); 190 curCost += m_cCUQtCbfSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_QT_CBF ); 191 curCost += m_cCUQtRootCbfSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_QT_ROOT_CBF ); 192 curCost += m_cCUSigCoeffGroupSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_SIG_CG_FLAG ); 193 curCost += m_cCUSigSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_SIG_FLAG ); 194 curCost += m_cCuCtxLastX.calcCost ( curSliceType, qp, (UChar*)INIT_LAST ); 195 curCost += m_cCuCtxLastY.calcCost ( curSliceType, qp, (UChar*)INIT_LAST ); 196 curCost += m_cCUOneSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_ONE_FLAG ); 197 curCost += m_cCUAbsSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_ABS_FLAG ); 198 curCost += m_cMVPIdxSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_MVP_IDX ); 199 curCost += m_cCUTransSubdivFlagSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_TRANS_SUBDIV_FLAG ); 200 curCost += m_cSaoMergeSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_SAO_MERGE_FLAG ); 201 curCost += m_cSaoTypeIdxSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_SAO_TYPE_IDX ); 202 curCost += m_cTransformSkipSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_TRANSFORMSKIP_FLAG ); 203 curCost += m_CUTransquantBypassFlagSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_CU_TRANSQUANT_BYPASS_FLAG ); 204 curCost += m_explicitRdpcmFlagSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_EXPLICIT_RDPCM_FLAG); 205 curCost += m_explicitRdpcmDirSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_EXPLICIT_RDPCM_DIR); 206 curCost += m_cCrossComponentPredictionSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_CROSS_COMPONENT_PREDICTION ); 207 curCost += m_ChromaQpAdjFlagSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_CHROMA_QP_ADJ_FLAG ); 208 curCost += m_ChromaQpAdjIdcSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_CHROMA_QP_ADJ_IDC ); 209 187 210 if (curCost < bestCost) 188 211 { … … 196 219 { 197 220 m_pcSlice->getPPS()->setEncCABACTableIdx( I_SLICE ); 198 } 199 } 200 201 202 /** The function does the followng: Write out terminate bit. Flush CABAC. Intialize CABAC states. Start CABAC. 203 */ 204 Void TEncSbac::updateContextTables( SliceType eSliceType, Int iQp, Bool bExecuteFinish ) 205 { 206 m_pcBinIf->encodeBinTrm(1); 207 if (bExecuteFinish) m_pcBinIf->finish(); 208 m_cCUSplitFlagSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_SPLIT_FLAG ); 209 210 m_cCUSkipFlagSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_SKIP_FLAG ); 211 m_cCUMergeFlagExtSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_MERGE_FLAG_EXT); 212 m_cCUMergeIdxExtSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_MERGE_IDX_EXT); 213 m_cCUPartSizeSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_PART_SIZE ); 214 m_cCUPredModeSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_PRED_MODE ); 215 m_cCUIntraPredSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_INTRA_PRED_MODE ); 216 m_cCUChromaPredSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_CHROMA_PRED_MODE ); 217 m_cCUInterDirSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_INTER_DIR ); 218 m_cCUMvdSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_MVD ); 219 m_cCURefPicSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_REF_PIC ); 220 m_cCUDeltaQpSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_DQP ); 221 m_cCUQtCbfSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_QT_CBF ); 222 m_cCUQtRootCbfSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_QT_ROOT_CBF ); 223 m_cCUSigCoeffGroupSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_SIG_CG_FLAG ); 224 m_cCUSigSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_SIG_FLAG ); 225 m_cCuCtxLastX.initBuffer ( eSliceType, iQp, (UChar*)INIT_LAST ); 226 m_cCuCtxLastY.initBuffer ( eSliceType, iQp, (UChar*)INIT_LAST ); 227 m_cCUOneSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_ONE_FLAG ); 228 m_cCUAbsSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_ABS_FLAG ); 229 m_cMVPIdxSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_MVP_IDX ); 230 m_cCUTransSubdivFlagSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_TRANS_SUBDIV_FLAG ); 231 m_cSaoMergeSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_SAO_MERGE_FLAG ); 232 m_cSaoTypeIdxSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_SAO_TYPE_IDX ); 233 m_cTransformSkipSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_TRANSFORMSKIP_FLAG ); 234 m_CUTransquantBypassFlagSCModel.initBuffer( eSliceType, iQp, (UChar*)INIT_CU_TRANSQUANT_BYPASS_FLAG ); 235 m_pcBinIf->start(); 221 } 236 222 } 237 223 … … 270 256 } 271 257 272 #if POC_RESET_IDC_SIGNALLING 273 Void TEncSbac::codeSliceHeaderExtn( TComSlice* pSlice, Int shBitsWrittenTillNow ) 274 { 275 assert (0); 258 Void TEncSbac::codeTerminatingBit( UInt uilsLast ) 259 { 260 m_pcBinIf->encodeBinTrm( uilsLast ); 261 } 262 263 Void TEncSbac::codeSliceFinish() 264 { 265 m_pcBinIf->finish(); 266 } 267 268 Void TEncSbac::xWriteUnarySymbol( UInt uiSymbol, ContextModel* pcSCModel, Int iOffset ) 269 { 270 m_pcBinIf->encodeBin( uiSymbol ? 1 : 0, pcSCModel[0] ); 271 272 if( 0 == uiSymbol) 273 { 274 return; 275 } 276 277 while( uiSymbol-- ) 278 { 279 m_pcBinIf->encodeBin( uiSymbol ? 1 : 0, pcSCModel[ iOffset ] ); 280 } 281 276 282 return; 277 283 } 278 #endif 279 Void TEncSbac::codeTerminatingBit( UInt uilsLast ) 280 { 281 m_pcBinIf->encodeBinTrm( uilsLast ); 282 } 283 284 Void TEncSbac::codeSliceFinish() 285 { 286 m_pcBinIf->finish(); 287 } 288 289 Void TEncSbac::xWriteUnarySymbol( UInt uiSymbol, ContextModel* pcSCModel, Int iOffset ) 290 { 291 m_pcBinIf->encodeBin( uiSymbol ? 1 : 0, pcSCModel[0] ); 292 293 if( 0 == uiSymbol) 284 285 Void TEncSbac::xWriteUnaryMaxSymbol( UInt uiSymbol, ContextModel* pcSCModel, Int iOffset, UInt uiMaxSymbol ) 286 { 287 if (uiMaxSymbol == 0) 294 288 { 295 289 return; 296 290 } 297 298 while( uiSymbol-- ) 299 { 300 m_pcBinIf->encodeBin( uiSymbol ? 1 : 0, pcSCModel[ iOffset ] ); 301 } 302 303 return; 304 } 305 306 Void TEncSbac::xWriteUnaryMaxSymbol( UInt uiSymbol, ContextModel* pcSCModel, Int iOffset, UInt uiMaxSymbol ) 307 { 308 if (uiMaxSymbol == 0) 291 292 m_pcBinIf->encodeBin( uiSymbol ? 1 : 0, pcSCModel[ 0 ] ); 293 294 if ( uiSymbol == 0 ) 309 295 { 310 296 return; 311 297 } 312 313 m_pcBinIf->encodeBin( uiSymbol ? 1 : 0, pcSCModel[ 0 ] ); 314 315 if ( uiSymbol == 0 ) 316 { 317 return; 318 } 319 298 320 299 Bool bCodeLast = ( uiMaxSymbol > uiSymbol ); 321 300 322 301 while( --uiSymbol ) 323 302 { … … 328 307 m_pcBinIf->encodeBin( 0, pcSCModel[ iOffset ] ); 329 308 } 330 309 331 310 return; 332 311 } … … 336 315 UInt bins = 0; 337 316 Int numBins = 0; 338 317 339 318 while( uiSymbol >= (UInt)(1<<uiCount) ) 340 319 { … … 346 325 bins = 2 * bins + 0; 347 326 numBins++; 348 327 349 328 bins = (bins << uiCount) | uiSymbol; 350 329 numBins += uiCount; 351 330 352 331 assert( numBins <= 32 ); 353 332 m_pcBinIf->encodeBinsEP( bins, numBins ); 354 333 } 334 355 335 356 336 /** Coding of coeff_abs_level_minus3 … … 359 339 * \returns Void 360 340 */ 361 Void TEncSbac::xWriteCoefRemainExGolomb ( UInt symbol, UInt &rParam )341 Void TEncSbac::xWriteCoefRemainExGolomb ( UInt symbol, UInt &rParam, const Bool useLimitedPrefixLength, const ChannelType channelType ) 362 342 { 363 343 Int codeNumber = (Int)symbol; 364 344 UInt length; 345 365 346 if (codeNumber < (COEF_REMAIN_BIN_REDUCTION << rParam)) 366 347 { … … 369 350 m_pcBinIf->encodeBinsEP((codeNumber%(1<<rParam)),rParam); 370 351 } 352 else if (useLimitedPrefixLength) 353 { 354 const UInt maximumPrefixLength = (32 - (COEF_REMAIN_BIN_REDUCTION + g_maxTrDynamicRange[channelType])); 355 356 UInt prefixLength = 0; 357 UInt suffixLength = MAX_UINT; 358 UInt codeValue = (symbol >> rParam) - COEF_REMAIN_BIN_REDUCTION; 359 360 if (codeValue >= ((1 << maximumPrefixLength) - 1)) 361 { 362 prefixLength = maximumPrefixLength; 363 suffixLength = g_maxTrDynamicRange[channelType] - rParam; 364 } 365 else 366 { 367 while (codeValue > ((2 << prefixLength) - 2)) 368 { 369 prefixLength++; 370 } 371 372 suffixLength = prefixLength + 1; //+1 for the separator bit 373 } 374 375 const UInt suffix = codeValue - ((1 << prefixLength) - 1); 376 377 const UInt totalPrefixLength = prefixLength + COEF_REMAIN_BIN_REDUCTION; 378 const UInt prefix = (1 << totalPrefixLength) - 1; 379 const UInt rParamBitMask = (1 << rParam) - 1; 380 381 m_pcBinIf->encodeBinsEP( prefix, totalPrefixLength ); //prefix 382 m_pcBinIf->encodeBinsEP(((suffix << rParam) | (symbol & rParamBitMask)), (suffixLength + rParam)); //separator, suffix, and rParam bits 383 } 371 384 else 372 385 { 373 386 length = rParam; 374 387 codeNumber = codeNumber - ( COEF_REMAIN_BIN_REDUCTION << rParam); 388 375 389 while (codeNumber >= (1<<length)) 376 390 { 377 codeNumber -= (1<<(length++)); 378 } 391 codeNumber -= (1<<(length++)); 392 } 393 379 394 m_pcBinIf->encodeBinsEP((1<<(COEF_REMAIN_BIN_REDUCTION+length+1-rParam))-2,COEF_REMAIN_BIN_REDUCTION+length+1-rParam); 380 395 m_pcBinIf->encodeBinsEP(codeNumber,length); … … 383 398 384 399 // SBAC RD 385 Void TEncSbac::load ( TEncSbac* pSrc)400 Void TEncSbac::load ( const TEncSbac* pSrc) 386 401 { 387 402 this->xCopyFrom(pSrc); 388 403 } 389 404 390 Void TEncSbac::loadIntraDirMode Luma( TEncSbac* pSrc)405 Void TEncSbac::loadIntraDirMode( const TEncSbac* pSrc, const ChannelType chType ) 391 406 { 392 407 m_pcBinIf->copyState( pSrc->m_pcBinIf ); 393 394 this->m_cCUIntraPredSCModel .copyFrom( &pSrc->m_cCUIntraPredSCModel ); 395 } 396 397 398 Void TEncSbac::store( TEncSbac* pDest) 408 if (isLuma(chType)) 409 this->m_cCUIntraPredSCModel .copyFrom( &pSrc->m_cCUIntraPredSCModel ); 410 else 411 this->m_cCUChromaPredSCModel .copyFrom( &pSrc->m_cCUChromaPredSCModel ); 412 } 413 414 415 Void TEncSbac::store( TEncSbac* pDest) const 399 416 { 400 417 pDest->xCopyFrom( this ); … … 402 419 403 420 404 Void TEncSbac::xCopyFrom( TEncSbac* pSrc )421 Void TEncSbac::xCopyFrom( const TEncSbac* pSrc ) 405 422 { 406 423 m_pcBinIf->copyState( pSrc->m_pcBinIf ); 407 408 this->m_uiCoeffCost = pSrc->m_uiCoeffCost; 409 this->m_uiLastQp = pSrc->m_uiLastQp; 410 411 memcpy( m_contextModels, pSrc->m_contextModels, m_numContextModels * sizeof( ContextModel ) ); 424 xCopyContextsFrom(pSrc); 412 425 } 413 426 … … 423 436 { 424 437 PartSize eSize = pcCU->getPartitionSize( uiAbsPartIdx ); 438 425 439 if ( pcCU->isIntra( uiAbsPartIdx ) ) 426 440 { … … 431 445 return; 432 446 } 433 447 434 448 switch(eSize) 435 449 { … … 465 479 m_pcBinIf->encodeBin( 0, m_cCUPartSizeSCModel.get( 0, 0, 0) ); 466 480 m_pcBinIf->encodeBin( 0, m_cCUPartSizeSCModel.get( 0, 0, 1) ); 481 467 482 if( uiDepth == g_uiMaxCUDepth - g_uiAddCUDepth && !( pcCU->getWidth(uiAbsPartIdx) == 8 && pcCU->getHeight(uiAbsPartIdx) == 8 ) ) 468 483 { 469 484 m_pcBinIf->encodeBin( 1, m_cCUPartSizeSCModel.get( 0, 0, 2) ); 470 485 } 486 471 487 if ( pcCU->getSlice()->getSPS()->getAMPAcc( uiDepth ) ) 472 488 { … … 496 512 { 497 513 assert(0); 498 } 499 } 500 } 514 break; 515 } 516 } 517 } 518 501 519 502 520 /** code prediction mode 503 521 * \param pcCU 504 * \param uiAbsPartIdx 522 * \param uiAbsPartIdx 505 523 * \returns Void 506 524 */ … … 508 526 { 509 527 // get context function is here 510 Int iPredMode = pcCU->getPredictionMode( uiAbsPartIdx ); 511 m_pcBinIf->encodeBin( iPredMode == MODE_INTER ? 0 : 1, m_cCUPredModeSCModel.get( 0, 0, 0 ) ); 528 m_pcBinIf->encodeBin( pcCU->isIntra( uiAbsPartIdx ) ? 1 : 0, m_cCUPredModeSCModel.get( 0, 0, 0 ) ); 512 529 } 513 530 … … 520 537 /** code skip flag 521 538 * \param pcCU 522 * \param uiAbsPartIdx 539 * \param uiAbsPartIdx 523 540 * \returns Void 524 541 */ … … 540 557 /** code merge flag 541 558 * \param pcCU 542 * \param uiAbsPartIdx 559 * \param uiAbsPartIdx 543 560 * \returns Void 544 561 */ … … 552 569 DTRACE_CABAC_V( uiSymbol ); 553 570 DTRACE_CABAC_T( "\tAddress: " ); 554 DTRACE_CABAC_V( pcCU->get Addr() );571 DTRACE_CABAC_V( pcCU->getCtuRsAddr() ); 555 572 DTRACE_CABAC_T( "\tuiAbsPartIdx: " ); 556 573 DTRACE_CABAC_V( uiAbsPartIdx ); … … 560 577 /** code merge index 561 578 * \param pcCU 562 * \param uiAbsPartIdx 579 * \param uiAbsPartIdx 563 580 * \returns Void 564 581 */ … … 597 614 if( uiDepth == g_uiMaxCUDepth - g_uiAddCUDepth ) 598 615 return; 599 616 600 617 UInt uiCtx = pcCU->getCtxSplitFlag( uiAbsPartIdx, uiDepth ); 601 618 UInt uiCurrSplitFlag = ( pcCU->getDepth( uiAbsPartIdx ) > uiDepth ) ? 1 : 0; 602 619 603 620 assert( uiCtx < 3 ); 604 621 m_pcBinIf->encodeBin( uiCurrSplitFlag, m_cCUSplitFlagSCModel.get( 0, 0, uiCtx ) ); … … 620 637 } 621 638 639 622 640 Void TEncSbac::codeIntraDirLumaAng( TComDataCU* pcCU, UInt absPartIdx, Bool isMultiple) 623 641 { 624 642 UInt dir[4],j; 625 Int preds[4][ 3] = {{-1, -1, -1},{-1, -1, -1},{-1, -1, -1},{-1, -1, -1}};643 Int preds[4][NUM_MOST_PROBABLE_MODES] = {{-1, -1, -1},{-1, -1, -1},{-1, -1, -1},{-1, -1, -1}}; 626 644 Int predNum[4], predIdx[4] ={ -1,-1,-1,-1}; 627 645 PartSize mode = pcCU->getPartitionSize( absPartIdx ); 628 646 UInt partNum = isMultiple?(mode==SIZE_NxN?4:1):1; 629 UInt partOffset = ( pcCU->getPic()->getNumPart InCU() >> ( pcCU->getDepth(absPartIdx) << 1 ) ) >> 2;647 UInt partOffset = ( pcCU->getPic()->getNumPartitionsInCtu() >> ( pcCU->getDepth(absPartIdx) << 1 ) ) >> 2; 630 648 for (j=0;j<partNum;j++) 631 649 { 632 dir[j] = pcCU->get LumaIntraDir(absPartIdx+partOffset*j );633 predNum[j] = pcCU->getIntraDir LumaPredictor(absPartIdx+partOffset*j, preds[j]);650 dir[j] = pcCU->getIntraDir( CHANNEL_TYPE_LUMA, absPartIdx+partOffset*j ); 651 predNum[j] = pcCU->getIntraDirPredictor(absPartIdx+partOffset*j, preds[j], COMPONENT_Y); 634 652 for(UInt i = 0; i < predNum[j]; i++) 635 653 { … … 640 658 } 641 659 m_pcBinIf->encodeBin((predIdx[j] != -1)? 1 : 0, m_cCUIntraPredSCModel.get( 0, 0, 0 ) ); 642 } 660 } 643 661 for (j=0;j<partNum;j++) 644 662 { … … 653 671 else 654 672 { 673 assert(predNum[j]>=3); // It is currently always 3! 655 674 if (preds[j][0] > preds[j][1]) 656 { 657 std::swap(preds[j][0], preds[j][1]); 675 { 676 std::swap(preds[j][0], preds[j][1]); 658 677 } 659 678 if (preds[j][0] > preds[j][2]) … … 677 696 Void TEncSbac::codeIntraDirChroma( TComDataCU* pcCU, UInt uiAbsPartIdx ) 678 697 { 679 UInt uiIntraDirChroma = pcCU->get ChromaIntraDir(uiAbsPartIdx );680 681 if( uiIntraDirChroma == DM_CHROMA_IDX ) 698 UInt uiIntraDirChroma = pcCU->getIntraDir( CHANNEL_TYPE_CHROMA, uiAbsPartIdx ); 699 700 if( uiIntraDirChroma == DM_CHROMA_IDX ) 682 701 { 683 702 m_pcBinIf->encodeBin( 0, m_cCUChromaPredSCModel.get( 0, 0, 0 ) ); 684 703 } 685 704 else 686 { 705 { 706 m_pcBinIf->encodeBin( 1, m_cCUChromaPredSCModel.get( 0, 0, 0 ) ); 707 687 708 UInt uiAllowedChromaDir[ NUM_CHROMA_MODE ]; 688 709 pcCU->getAllowedChromaDir( uiAbsPartIdx, uiAllowedChromaDir ); … … 696 717 } 697 718 } 698 m_pcBinIf->encodeBin( 1, m_cCUChromaPredSCModel.get( 0, 0, 0 ) );699 719 700 720 m_pcBinIf->encodeBinsEP( uiIntraDirChroma, 2 ); 701 721 } 722 702 723 return; 703 724 } 725 704 726 705 727 Void TEncSbac::codeInterDir( TComDataCU* pcCU, UInt uiAbsPartIdx ) … … 708 730 const UInt uiCtx = pcCU->getCtxInterDir( uiAbsPartIdx ); 709 731 ContextModel *pCtx = m_cCUInterDirSCModel.get( 0 ); 732 710 733 if (pcCU->getPartitionSize(uiAbsPartIdx) == SIZE_2Nx2N || pcCU->getHeight(uiAbsPartIdx) != 8 ) 711 734 { 712 735 m_pcBinIf->encodeBin( uiInterDir == 2 ? 1 : 0, *( pCtx + uiCtx ) ); 713 736 } 737 714 738 if (uiInterDir < 2) 715 739 { 716 740 m_pcBinIf->encodeBin( uiInterDir, *( pCtx + 4 ) ); 717 741 } 742 718 743 return; 719 744 } … … 721 746 Void TEncSbac::codeRefFrmIdx( TComDataCU* pcCU, UInt uiAbsPartIdx, RefPicList eRefList ) 722 747 { 723 { 724 Int iRefFrame = pcCU->getCUMvField( eRefList )->getRefIdx( uiAbsPartIdx ); 725 ContextModel *pCtx = m_cCURefPicSCModel.get( 0 ); 726 m_pcBinIf->encodeBin( ( iRefFrame == 0 ? 0 : 1 ), *pCtx ); 727 728 if( iRefFrame > 0 ) 729 { 730 UInt uiRefNum = pcCU->getSlice()->getNumRefIdx( eRefList ) - 2; 731 pCtx++; 732 iRefFrame--; 733 for( UInt ui = 0; ui < uiRefNum; ++ui ) 734 { 735 const UInt uiSymbol = ui == iRefFrame ? 0 : 1; 736 if( ui == 0 ) 737 { 738 m_pcBinIf->encodeBin( uiSymbol, *pCtx ); 739 } 740 else 741 { 742 m_pcBinIf->encodeBinEP( uiSymbol ); 743 } 744 if( uiSymbol == 0 ) 745 { 746 break; 747 } 748 Int iRefFrame = pcCU->getCUMvField( eRefList )->getRefIdx( uiAbsPartIdx ); 749 ContextModel *pCtx = m_cCURefPicSCModel.get( 0 ); 750 m_pcBinIf->encodeBin( ( iRefFrame == 0 ? 0 : 1 ), *pCtx ); 751 752 if( iRefFrame > 0 ) 753 { 754 UInt uiRefNum = pcCU->getSlice()->getNumRefIdx( eRefList ) - 2; 755 pCtx++; 756 iRefFrame--; 757 for( UInt ui = 0; ui < uiRefNum; ++ui ) 758 { 759 const UInt uiSymbol = ui == iRefFrame ? 0 : 1; 760 if( ui == 0 ) 761 { 762 m_pcBinIf->encodeBin( uiSymbol, *pCtx ); 763 } 764 else 765 { 766 m_pcBinIf->encodeBinEP( uiSymbol ); 767 } 768 if( uiSymbol == 0 ) 769 { 770 break; 748 771 } 749 772 } … … 802 825 m_pcBinIf->encodeBinEP( 0 > iVer ? 1 : 0 ); 803 826 } 804 827 805 828 return; 829 } 830 831 Void TEncSbac::codeCrossComponentPrediction( TComTU &rTu, ComponentID compID ) 832 { 833 TComDataCU *pcCU = rTu.getCU(); 834 835 if( isLuma(compID) || !pcCU->getSlice()->getPPS()->getUseCrossComponentPrediction() ) return; 836 837 const UInt uiAbsPartIdx = rTu.GetAbsPartIdxTU(); 838 839 if (!pcCU->isIntra(uiAbsPartIdx) || (pcCU->getIntraDir( CHANNEL_TYPE_CHROMA, uiAbsPartIdx ) == DM_CHROMA_IDX)) 840 { 841 DTRACE_CABAC_VL( g_nSymbolCounter++ ) 842 DTRACE_CABAC_T("\tparseCrossComponentPrediction()") 843 DTRACE_CABAC_T( "\tAddr=" ) 844 DTRACE_CABAC_V( compID ) 845 DTRACE_CABAC_T( "\tuiAbsPartIdx=" ) 846 DTRACE_CABAC_V( uiAbsPartIdx ) 847 848 Int alpha = pcCU->getCrossComponentPredictionAlpha( uiAbsPartIdx, compID ); 849 ContextModel *pCtx = m_cCrossComponentPredictionSCModel.get(0, 0) + ((compID == COMPONENT_Cr) ? (NUM_CROSS_COMPONENT_PREDICTION_CTX >> 1) : 0); 850 m_pcBinIf->encodeBin(((alpha != 0) ? 1 : 0), pCtx[0]); 851 852 if (alpha != 0) 853 { 854 static const Int log2AbsAlphaMinus1Table[8] = { 0, 1, 1, 2, 2, 2, 3, 3 }; 855 assert(abs(alpha) <= 8); 856 857 if (abs(alpha)>1) 858 { 859 m_pcBinIf->encodeBin(1, pCtx[1]); 860 xWriteUnaryMaxSymbol( log2AbsAlphaMinus1Table[abs(alpha) - 1] - 1, (pCtx + 2), 1, 2 ); 861 } 862 else 863 { 864 m_pcBinIf->encodeBin(0, pCtx[1]); 865 } 866 m_pcBinIf->encodeBin( ((alpha < 0) ? 1 : 0), pCtx[4] ); 867 } 868 DTRACE_CABAC_T( "\tAlpha=" ) 869 DTRACE_CABAC_V( pcCU->getCrossComponentPredictionAlpha( uiAbsPartIdx, compID ) ) 870 DTRACE_CABAC_T( "\n" ) 871 } 806 872 } 807 873 … … 810 876 Int iDQp = pcCU->getQP( uiAbsPartIdx ) - pcCU->getRefQP( uiAbsPartIdx ); 811 877 812 #if REPN_FORMAT_IN_VPS 878 #if REPN_FORMAT_IN_VPS 813 879 Int qpBdOffsetY = pcCU->getSlice()->getQpBDOffsetY(); 814 880 #else 815 Int qpBdOffsetY = pcCU->getSlice()->getSPS()->getQpBDOffset Y();881 Int qpBdOffsetY = pcCU->getSlice()->getSPS()->getQpBDOffset(CHANNEL_TYPE_LUMA); 816 882 #endif 817 883 iDQp = (iDQp + 78 + qpBdOffsetY + (qpBdOffsetY/2)) % (52 + qpBdOffsetY) - 26 - (qpBdOffsetY/2); … … 834 900 } 835 901 836 Void TEncSbac::codeQtCbf( TComDataCU* pcCU, UInt uiAbsPartIdx, TextType eType, UInt uiTrDepth ) 837 { 838 UInt uiCbf = pcCU->getCbf ( uiAbsPartIdx, eType, uiTrDepth ); 839 UInt uiCtx = pcCU->getCtxQtCbf( eType, uiTrDepth ); 840 m_pcBinIf->encodeBin( uiCbf , m_cCUQtCbfSCModel.get( 0, eType ? TEXT_CHROMA : eType, uiCtx ) ); 841 DTRACE_CABAC_VL( g_nSymbolCounter++ ) 842 DTRACE_CABAC_T( "\tparseQtCbf()" ) 843 DTRACE_CABAC_T( "\tsymbol=" ) 844 DTRACE_CABAC_V( uiCbf ) 845 DTRACE_CABAC_T( "\tctx=" ) 846 DTRACE_CABAC_V( uiCtx ) 847 DTRACE_CABAC_T( "\tetype=" ) 848 DTRACE_CABAC_V( eType ) 849 DTRACE_CABAC_T( "\tuiAbsPartIdx=" ) 850 DTRACE_CABAC_V( uiAbsPartIdx ) 851 DTRACE_CABAC_T( "\n" ) 852 } 853 854 void TEncSbac::codeTransformSkipFlags (TComDataCU* pcCU, UInt uiAbsPartIdx, UInt width, UInt height, TextType eTType ) 855 { 902 /** code chroma qp adjustment, converting from the internal table representation 903 * \returns Void 904 */ 905 Void TEncSbac::codeChromaQpAdjustment( TComDataCU* cu, UInt absPartIdx ) 906 { 907 Int internalIdc = cu->getChromaQpAdj( absPartIdx ); 908 Int tableSize = cu->getSlice()->getPPS()->getChromaQpAdjTableSize(); 909 /* internal_idc == 0 => flag = 0 910 * internal_idc > 1 => code idc value (if table size warrents) */ 911 m_pcBinIf->encodeBin( internalIdc > 0, m_ChromaQpAdjFlagSCModel.get( 0, 0, 0 ) ); 912 913 if (internalIdc > 0 && tableSize > 1) 914 { 915 xWriteUnaryMaxSymbol( internalIdc - 1, &m_ChromaQpAdjIdcSCModel.get( 0, 0, 0 ), 0, tableSize - 1 ); 916 } 917 } 918 919 Void TEncSbac::codeQtCbf( TComTU &rTu, const ComponentID compID, const Bool lowestLevel ) 920 { 921 TComDataCU* pcCU = rTu.getCU(); 922 923 const UInt absPartIdx = rTu.GetAbsPartIdxTU(compID); 924 const UInt TUDepth = rTu.GetTransformDepthRel(); 925 UInt uiCtx = pcCU->getCtxQtCbf( rTu, toChannelType(compID) ); 926 const UInt contextSet = toChannelType(compID); 927 928 const UInt width = rTu.getRect(compID).width; 929 const UInt height = rTu.getRect(compID).height; 930 const Bool canQuadSplit = (width >= (MIN_TU_SIZE * 2)) && (height >= (MIN_TU_SIZE * 2)); 931 932 // Since the CBF for chroma is coded at the highest level possible, if sub-TUs are 933 // to be coded for a 4x8 chroma TU, their CBFs must be coded at the highest 4x8 level 934 // (i.e. where luma TUs are 8x8 rather than 4x4) 935 // ___ ___ 936 // | | | <- 4 x (8x8 luma + 4x8 4:2:2 chroma) 937 // |___|___| each quadrant has its own chroma CBF 938 // | | | _ _ _ _ 939 // |___|___| | 940 // <--16---> V 941 // _ _ 942 // |_|_| <- 4 x 4x4 luma + 1 x 4x8 4:2:2 chroma 943 // |_|_| no chroma CBF is coded - instead the parent CBF is inherited 944 // <-8-> if sub-TUs are present, their CBFs had to be coded at the parent level 945 946 const UInt lowestTUDepth = TUDepth + ((!lowestLevel && !canQuadSplit) ? 1 : 0); //unsplittable TUs inherit their parent's CBF 947 948 if ((width != height) && (lowestLevel || !canQuadSplit)) //if sub-TUs are present 949 { 950 const UInt subTUDepth = lowestTUDepth + 1; //if this is the lowest level of the TU-tree, the sub-TUs are directly below. Otherwise, this must be the level above the lowest level (as specified above) 951 const UInt partIdxesPerSubTU = rTu.GetAbsPartIdxNumParts(compID) >> 1; 952 953 for (UInt subTU = 0; subTU < 2; subTU++) 954 { 955 const UInt subTUAbsPartIdx = absPartIdx + (subTU * partIdxesPerSubTU); 956 const UInt uiCbf = pcCU->getCbf(subTUAbsPartIdx, compID, subTUDepth); 957 958 m_pcBinIf->encodeBin(uiCbf, m_cCUQtCbfSCModel.get(0, contextSet, uiCtx)); 959 960 DTRACE_CABAC_VL( g_nSymbolCounter++ ) 961 DTRACE_CABAC_T( "\tparseQtCbf()" ) 962 DTRACE_CABAC_T( "\tsub-TU=" ) 963 DTRACE_CABAC_V( subTU ) 964 DTRACE_CABAC_T( "\tsymbol=" ) 965 DTRACE_CABAC_V( uiCbf ) 966 DTRACE_CABAC_T( "\tctx=" ) 967 DTRACE_CABAC_V( uiCtx ) 968 DTRACE_CABAC_T( "\tetype=" ) 969 DTRACE_CABAC_V( compID ) 970 DTRACE_CABAC_T( "\tuiAbsPartIdx=" ) 971 DTRACE_CABAC_V( subTUAbsPartIdx ) 972 DTRACE_CABAC_T( "\n" ) 973 } 974 } 975 else 976 { 977 const UInt uiCbf = pcCU->getCbf( absPartIdx, compID, lowestTUDepth ); 978 m_pcBinIf->encodeBin( uiCbf , m_cCUQtCbfSCModel.get( 0, contextSet, uiCtx ) ); 979 980 981 DTRACE_CABAC_VL( g_nSymbolCounter++ ) 982 DTRACE_CABAC_T( "\tparseQtCbf()" ) 983 DTRACE_CABAC_T( "\tsymbol=" ) 984 DTRACE_CABAC_V( uiCbf ) 985 DTRACE_CABAC_T( "\tctx=" ) 986 DTRACE_CABAC_V( uiCtx ) 987 DTRACE_CABAC_T( "\tetype=" ) 988 DTRACE_CABAC_V( compID ) 989 DTRACE_CABAC_T( "\tuiAbsPartIdx=" ) 990 DTRACE_CABAC_V( rTu.GetAbsPartIdxTU(compID) ) 991 DTRACE_CABAC_T( "\n" ) 992 } 993 } 994 995 996 Void TEncSbac::codeTransformSkipFlags (TComTU &rTu, ComponentID component ) 997 { 998 TComDataCU* pcCU=rTu.getCU(); 999 const UInt uiAbsPartIdx=rTu.GetAbsPartIdxTU(); 1000 856 1001 if (pcCU->getCUTransquantBypass(uiAbsPartIdx)) 857 1002 { 858 1003 return; 859 1004 } 860 if(width != 4 || height != 4) 1005 1006 if (!TUCompRectHasAssociatedTransformSkipFlag(rTu.getRect(component), pcCU->getSlice()->getPPS()->getTransformSkipLog2MaxSize())) 861 1007 { 862 1008 return; 863 1009 } 864 1010 865 UInt useTransformSkip = pcCU->getTransformSkip( uiAbsPartIdx,eTType); 866 m_pcBinIf->encodeBin( useTransformSkip, m_cTransformSkipSCModel.get( 0, eTType? TEXT_CHROMA: TEXT_LUMA, 0 ) ); 1011 UInt useTransformSkip = pcCU->getTransformSkip( uiAbsPartIdx,component); 1012 m_pcBinIf->encodeBin( useTransformSkip, m_cTransformSkipSCModel.get( 0, toChannelType(component), 0 ) ); 1013 867 1014 DTRACE_CABAC_VL( g_nSymbolCounter++ ) 868 1015 DTRACE_CABAC_T("\tparseTransformSkip()"); … … 870 1017 DTRACE_CABAC_V( useTransformSkip ) 871 1018 DTRACE_CABAC_T( "\tAddr=" ) 872 DTRACE_CABAC_V( pcCU->get Addr() )1019 DTRACE_CABAC_V( pcCU->getCtuRsAddr() ) 873 1020 DTRACE_CABAC_T( "\tetype=" ) 874 DTRACE_CABAC_V( eTType)1021 DTRACE_CABAC_V( component ) 875 1022 DTRACE_CABAC_T( "\tuiAbsPartIdx=" ) 876 DTRACE_CABAC_V( uiAbsPartIdx)1023 DTRACE_CABAC_V( rTu.GetAbsPartIdxTU() ) 877 1024 DTRACE_CABAC_T( "\n" ) 878 1025 } 1026 879 1027 880 1028 /** Code I_PCM information. … … 895 1043 m_pcBinIf->encodePCMAlignBits(); 896 1044 897 UInt uiMinCoeffSize = pcCU->getPic()->getMinCUWidth()*pcCU->getPic()->getMinCUHeight(); 898 UInt uiLumaOffset = uiMinCoeffSize*uiAbsPartIdx; 899 UInt uiChromaOffset = uiLumaOffset>>2; 900 Pel* piPCMSample; 901 UInt uiWidth; 902 UInt uiHeight; 903 UInt uiSampleBits; 904 UInt uiX, uiY; 905 906 piPCMSample = pcCU->getPCMSampleY() + uiLumaOffset; 907 uiWidth = pcCU->getWidth(uiAbsPartIdx); 908 uiHeight = pcCU->getHeight(uiAbsPartIdx); 909 uiSampleBits = pcCU->getSlice()->getSPS()->getPCMBitDepthLuma(); 910 911 for(uiY = 0; uiY < uiHeight; uiY++) 912 { 913 for(uiX = 0; uiX < uiWidth; uiX++) 914 { 915 UInt uiSample = piPCMSample[uiX]; 916 917 m_pcBinIf->xWritePCMCode(uiSample, uiSampleBits); 918 } 919 piPCMSample += uiWidth; 920 } 921 922 #if AUXILIARY_PICTURES 923 if (pcCU->getSlice()->getChromaFormatIdc() != CHROMA_400) 924 { 925 #endif 926 piPCMSample = pcCU->getPCMSampleCb() + uiChromaOffset; 927 uiWidth = pcCU->getWidth(uiAbsPartIdx)/2; 928 uiHeight = pcCU->getHeight(uiAbsPartIdx)/2; 929 uiSampleBits = pcCU->getSlice()->getSPS()->getPCMBitDepthChroma(); 930 931 for(uiY = 0; uiY < uiHeight; uiY++) 932 { 933 for(uiX = 0; uiX < uiWidth; uiX++) 934 { 935 UInt uiSample = piPCMSample[uiX]; 936 937 m_pcBinIf->xWritePCMCode(uiSample, uiSampleBits); 938 } 939 piPCMSample += uiWidth; 940 } 941 942 piPCMSample = pcCU->getPCMSampleCr() + uiChromaOffset; 943 uiWidth = pcCU->getWidth(uiAbsPartIdx)/2; 944 uiHeight = pcCU->getHeight(uiAbsPartIdx)/2; 945 uiSampleBits = pcCU->getSlice()->getSPS()->getPCMBitDepthChroma(); 946 947 for(uiY = 0; uiY < uiHeight; uiY++) 948 { 949 for(uiX = 0; uiX < uiWidth; uiX++) 950 { 951 UInt uiSample = piPCMSample[uiX]; 952 953 m_pcBinIf->xWritePCMCode(uiSample, uiSampleBits); 954 } 955 piPCMSample += uiWidth; 956 } 957 #if AUXILIARY_PICTURES 958 } 959 #endif 1045 const UInt minCoeffSizeY = pcCU->getPic()->getMinCUWidth() * pcCU->getPic()->getMinCUHeight(); 1046 const UInt offsetY = minCoeffSizeY * uiAbsPartIdx; 1047 for (UInt ch=0; ch < pcCU->getPic()->getNumberValidComponents(); ch++) 1048 { 1049 const ComponentID compID = ComponentID(ch); 1050 const UInt offset = offsetY >> (pcCU->getPic()->getComponentScaleX(compID) + pcCU->getPic()->getComponentScaleY(compID)); 1051 Pel * pPCMSample = pcCU->getPCMSample(compID) + offset; 1052 const UInt width = pcCU->getWidth (uiAbsPartIdx) >> pcCU->getPic()->getComponentScaleX(compID); 1053 const UInt height = pcCU->getHeight(uiAbsPartIdx) >> pcCU->getPic()->getComponentScaleY(compID); 1054 const UInt sampleBits = pcCU->getSlice()->getSPS()->getPCMBitDepth(toChannelType(compID)); 1055 for (UInt y=0; y<height; y++) 1056 { 1057 for (UInt x=0; x<width; x++) 1058 { 1059 UInt sample = pPCMSample[x]; 1060 m_pcBinIf->xWritePCMCode(sample, sampleBits); 1061 } 1062 pPCMSample += width; 1063 } 1064 } 1065 960 1066 m_pcBinIf->resetBac(); 961 1067 } … … 978 1084 } 979 1085 980 Void TEncSbac::codeQtCbfZero( TCom DataCU* pcCU, TextType eType, UInt uiTrDepth)1086 Void TEncSbac::codeQtCbfZero( TComTU & rTu, const ChannelType chType ) 981 1087 { 982 1088 // this function is only used to estimate the bits when cbf is 0 983 1089 // and will never be called when writing the bistream. do not need to write log 984 1090 UInt uiCbf = 0; 985 UInt uiCtx = pcCU->getCtxQtCbf( eType, uiTrDepth ); 986 m_pcBinIf->encodeBin( uiCbf , m_cCUQtCbfSCModel.get( 0, eType ? TEXT_CHROMA : eType, uiCtx ) ); 1091 UInt uiCtx = rTu.getCU()->getCtxQtCbf( rTu, chType ); 1092 1093 m_pcBinIf->encodeBin( uiCbf , m_cCUQtCbfSCModel.get( 0, chType, uiCtx ) ); 987 1094 } 988 1095 … … 1005 1112 * This method encodes the X and Y component within a block of the last significant coefficient. 1006 1113 */ 1007 Void TEncSbac::codeLastSignificantXY( UInt uiPosX, UInt uiPosY, Int width, Int height, TextType eTType, UInt uiScanIdx )1008 { 1114 Void TEncSbac::codeLastSignificantXY( UInt uiPosX, UInt uiPosY, Int width, Int height, ComponentID component, UInt uiScanIdx ) 1115 { 1009 1116 // swap 1010 1117 if( uiScanIdx == SCAN_VER ) 1011 1118 { 1012 1119 swap( uiPosX, uiPosY ); 1120 swap( width, height ); 1013 1121 } 1014 1122 1015 1123 UInt uiCtxLast; 1016 ContextModel *pCtxX = m_cCuCtxLastX.get( 0, eTType );1017 ContextModel *pCtxY = m_cCuCtxLastY.get( 0, eTType );1018 1124 UInt uiGroupIdxX = g_uiGroupIdx[ uiPosX ]; 1019 1125 UInt uiGroupIdxY = g_uiGroupIdx[ uiPosY ]; 1020 1126 1127 ContextModel *pCtxX = m_cCuCtxLastX.get( 0, toChannelType(component) ); 1128 ContextModel *pCtxY = m_cCuCtxLastY.get( 0, toChannelType(component) ); 1021 1129 1022 1130 Int blkSizeOffsetX, blkSizeOffsetY, shiftX, shiftY; 1023 blkSizeOffsetX = eTType ? 0: (g_aucConvertToBit[ width ] *3 + ((g_aucConvertToBit[ width ] +1)>>2));1024 blkSizeOffsetY = eTType ? 0: (g_aucConvertToBit[ height ]*3 + ((g_aucConvertToBit[ height ]+1)>>2)); 1025 shiftX= eTType ? g_aucConvertToBit[ width ] :((g_aucConvertToBit[ width ]+3)>>2);1026 shiftY= eTType ? g_aucConvertToBit[ height ] :((g_aucConvertToBit[ height ]+3)>>2); 1131 getLastSignificantContextParameters(component, width, height, blkSizeOffsetX, blkSizeOffsetY, shiftX, shiftY); 1132 1133 //------------------ 1134 1027 1135 // posX 1136 1028 1137 for( uiCtxLast = 0; uiCtxLast < uiGroupIdxX; uiCtxLast++ ) 1029 1138 { 1030 1139 m_pcBinIf->encodeBin( 1, *( pCtxX + blkSizeOffsetX + (uiCtxLast >>shiftX) ) ); 1031 1140 } 1032 1141 if( uiGroupIdxX < g_uiGroupIdx[ width - 1 ]) 1033 1142 { 1034 1143 m_pcBinIf->encodeBin( 0, *( pCtxX + blkSizeOffsetX + (uiCtxLast >>shiftX) ) ); 1035 1144 } 1036 1145 1037 1146 // posY 1147 1038 1148 for( uiCtxLast = 0; uiCtxLast < uiGroupIdxY; uiCtxLast++ ) 1039 1149 { … … 1044 1154 m_pcBinIf->encodeBin( 0, *( pCtxY + blkSizeOffsetY + (uiCtxLast >>shiftY) ) ); 1045 1155 } 1156 1157 // EP-coded part 1158 1046 1159 if ( uiGroupIdxX > 3 ) 1047 { 1160 { 1048 1161 UInt uiCount = ( uiGroupIdxX - 2 ) >> 1; 1049 1162 uiPosX = uiPosX - g_uiMinInGroup[ uiGroupIdxX ]; … … 1054 1167 } 1055 1168 if ( uiGroupIdxY > 3 ) 1056 { 1169 { 1057 1170 UInt uiCount = ( uiGroupIdxY - 2 ) >> 1; 1058 1171 uiPosY = uiPosY - g_uiMinInGroup[ uiGroupIdxY ]; … … 1064 1177 } 1065 1178 1066 Void TEncSbac::codeCoeffNxN( TComDataCU* pcCU, TCoeff* pcCoef, UInt uiAbsPartIdx, UInt uiWidth, UInt uiHeight, UInt uiDepth, TextType eTType ) 1067 { 1179 1180 Void TEncSbac::codeCoeffNxN( TComTU &rTu, TCoeff* pcCoef, const ComponentID compID ) 1181 { 1182 TComDataCU* pcCU=rTu.getCU(); 1183 const UInt uiAbsPartIdx=rTu.GetAbsPartIdxTU(compID); 1184 const TComRectangle &tuRect=rTu.getRect(compID); 1185 const UInt uiWidth=tuRect.width; 1186 const UInt uiHeight=tuRect.height; 1187 1068 1188 DTRACE_CABAC_VL( g_nSymbolCounter++ ) 1069 1189 DTRACE_CABAC_T( "\tparseCoeffNxN()\teType=" ) 1070 DTRACE_CABAC_V( eTType)1190 DTRACE_CABAC_V( compID ) 1071 1191 DTRACE_CABAC_T( "\twidth=" ) 1072 1192 DTRACE_CABAC_V( uiWidth ) … … 1074 1194 DTRACE_CABAC_V( uiHeight ) 1075 1195 DTRACE_CABAC_T( "\tdepth=" ) 1076 DTRACE_CABAC_V( uiDepth ) 1196 // DTRACE_CABAC_V( rTu.GetTransformDepthTotalAdj(compID) ) 1197 DTRACE_CABAC_V( rTu.GetTransformDepthTotal() ) 1077 1198 DTRACE_CABAC_T( "\tabspartidx=" ) 1078 1199 DTRACE_CABAC_V( uiAbsPartIdx ) … … 1082 1203 DTRACE_CABAC_V( pcCU->getCUPelY() ) 1083 1204 DTRACE_CABAC_T( "\tCU-addr=" ) 1084 DTRACE_CABAC_V( pcCU->get Addr() )1205 DTRACE_CABAC_V( pcCU->getCtuRsAddr() ) 1085 1206 DTRACE_CABAC_T( "\tinCU-X=" ) 1086 DTRACE_CABAC_V( g_auiRasterToPelX[ g_auiZscanToRaster[uiAbsPartIdx] ] ) 1207 // DTRACE_CABAC_V( g_auiRasterToPelX[ g_auiZscanToRaster[uiAbsPartIdx] ] ) 1208 DTRACE_CABAC_V( g_auiRasterToPelX[ g_auiZscanToRaster[rTu.GetAbsPartIdxTU(compID)] ] ) 1087 1209 DTRACE_CABAC_T( "\tinCU-Y=" ) 1088 DTRACE_CABAC_V( g_auiRasterToPelY[ g_auiZscanToRaster[uiAbsPartIdx] ] ) 1210 // DTRACE_CABAC_V( g_auiRasterToPelY[ g_auiZscanToRaster[uiAbsPartIdx] ] ) 1211 DTRACE_CABAC_V( g_auiRasterToPelY[ g_auiZscanToRaster[rTu.GetAbsPartIdxTU(compID)] ] ) 1089 1212 DTRACE_CABAC_T( "\tpredmode=" ) 1090 1213 DTRACE_CABAC_V( pcCU->getPredictionMode( uiAbsPartIdx ) ) 1091 1214 DTRACE_CABAC_T( "\n" ) 1092 1215 1216 //-------------------------------------------------------------------------------------------------- 1217 1093 1218 if( uiWidth > m_pcSlice->getSPS()->getMaxTrSize() ) 1094 1219 { 1095 uiWidth = m_pcSlice->getSPS()->getMaxTrSize(); 1096 uiHeight = m_pcSlice->getSPS()->getMaxTrSize(); 1097 } 1098 1099 UInt uiNumSig = 0; 1100 1220 std::cerr << "ERROR: codeCoeffNxN was passed a TU with dimensions larger than the maximum allowed size" << std::endl; 1221 assert(false); 1222 exit(1); 1223 } 1224 1101 1225 // compute number of significant coefficients 1102 uiNumSig = TEncEntropy::countNonZeroCoeffs(pcCoef, uiWidth * uiHeight);1103 1226 UInt uiNumSig = TEncEntropy::countNonZeroCoeffs(pcCoef, uiWidth * uiHeight); 1227 1104 1228 if ( uiNumSig == 0 ) 1105 return; 1229 { 1230 std::cerr << "ERROR: codeCoeffNxN called for empty TU!" << std::endl; 1231 assert(false); 1232 exit(1); 1233 } 1234 1235 //-------------------------------------------------------------------------------------------------- 1236 1237 //set parameters 1238 1239 const ChannelType chType = toChannelType(compID); 1240 const UInt uiLog2BlockWidth = g_aucConvertToBit[ uiWidth ] + 2; 1241 const UInt uiLog2BlockHeight = g_aucConvertToBit[ uiHeight ] + 2; 1242 1243 const ChannelType channelType = toChannelType(compID); 1244 const Bool extendedPrecision = pcCU->getSlice()->getSPS()->getUseExtendedPrecision(); 1245 1246 const Bool alignCABACBeforeBypass = pcCU->getSlice()->getSPS()->getAlignCABACBeforeBypass(); 1247 1248 Bool beValid; 1249 1250 { 1251 Int uiIntraMode = -1; 1252 const Bool bIsLuma = isLuma(compID); 1253 Int isIntra = pcCU->isIntra(uiAbsPartIdx) ? 1 : 0; 1254 if ( isIntra ) 1255 { 1256 uiIntraMode = pcCU->getIntraDir( toChannelType(compID), uiAbsPartIdx ); 1257 1258 uiIntraMode = (uiIntraMode==DM_CHROMA_IDX && !bIsLuma) ? pcCU->getIntraDir(CHANNEL_TYPE_LUMA, getChromasCorrespondingPULumaIdx(uiAbsPartIdx, rTu.GetChromaFormat())) : uiIntraMode; 1259 uiIntraMode = ((rTu.GetChromaFormat() == CHROMA_422) && !bIsLuma) ? g_chroma422IntraAngleMappingTable[uiIntraMode] : uiIntraMode; 1260 } 1261 1262 Int transformSkip = pcCU->getTransformSkip( uiAbsPartIdx,compID) ? 1 : 0; 1263 Bool rdpcm_lossy = ( transformSkip && isIntra && ( (uiIntraMode == HOR_IDX) || (uiIntraMode == VER_IDX) ) ) && pcCU->isRDPCMEnabled(uiAbsPartIdx); 1264 1265 if ( (pcCU->getCUTransquantBypass(uiAbsPartIdx)) || rdpcm_lossy ) 1266 { 1267 beValid = false; 1268 if ( (!pcCU->isIntra(uiAbsPartIdx)) && pcCU->isRDPCMEnabled(uiAbsPartIdx)) 1269 codeExplicitRdpcmMode( rTu, compID); 1270 } 1271 else 1272 { 1273 beValid = pcCU->getSlice()->getPPS()->getSignHideFlag() > 0; 1274 } 1275 } 1276 1277 //-------------------------------------------------------------------------------------------------- 1278 1106 1279 if(pcCU->getSlice()->getPPS()->getUseTransformSkip()) 1107 1280 { 1108 codeTransformSkipFlags( pcCU,uiAbsPartIdx, uiWidth, uiHeight, eTType ); 1109 } 1110 eTType = eTType == TEXT_LUMA ? TEXT_LUMA : ( eTType == TEXT_NONE ? TEXT_NONE : TEXT_CHROMA ); 1111 1281 codeTransformSkipFlags(rTu, compID); 1282 if(pcCU->getTransformSkip(uiAbsPartIdx, compID) && !pcCU->isIntra(uiAbsPartIdx) && pcCU->isRDPCMEnabled(uiAbsPartIdx)) 1283 { 1284 // This TU has coefficients and is transform skipped. Check whether is inter coded and if yes encode the explicit RDPCM mode 1285 codeExplicitRdpcmMode( rTu, compID); 1286 1287 if(pcCU->getExplicitRdpcmMode(compID, uiAbsPartIdx) != RDPCM_OFF) 1288 { 1289 // Sign data hiding is avoided for horizontal and vertical explicit RDPCM modes 1290 beValid = false; 1291 } 1292 } 1293 } 1294 1295 //-------------------------------------------------------------------------------------------------- 1296 1297 const Bool bUseGolombRiceParameterAdaptation = pcCU->getSlice()->getSPS()->getUseGolombRiceParameterAdaptation(); 1298 UInt ¤tGolombRiceStatistic = m_golombRiceAdaptationStatistics[rTu.getGolombRiceStatisticsIndex(compID)]; 1299 1300 //select scans 1301 TUEntropyCodingParameters codingParameters; 1302 getTUEntropyCodingParameters(codingParameters, rTu, compID); 1303 1112 1304 //----- encode significance map ----- 1113 const UInt uiLog2BlockSize = g_aucConvertToBit[ uiWidth ] + 2;1114 UInt uiScanIdx = pcCU->getCoefScanIdx(uiAbsPartIdx, uiWidth, eTType==TEXT_LUMA, pcCU->isIntra(uiAbsPartIdx));1115 const UInt *scan = g_auiSigLastScan[ uiScanIdx ][ uiLog2BlockSize - 1 ];1116 1117 Bool beValid;1118 if (pcCU->getCUTransquantBypass(uiAbsPartIdx))1119 {1120 beValid = false;1121 }1122 else1123 {1124 beValid = pcCU->getSlice()->getPPS()->getSignHideFlag() > 0;1125 }1126 1305 1127 1306 // Find position of last coefficient … … 1129 1308 Int posLast; 1130 1309 1131 const UInt * scanCG; 1132 { 1133 scanCG = g_auiSigLastScan[ uiScanIdx ][ uiLog2BlockSize > 3 ? uiLog2BlockSize-2-1 : 0 ]; 1134 if( uiLog2BlockSize == 3 ) 1135 { 1136 scanCG = g_sigLastScan8x8[ uiScanIdx ]; 1137 } 1138 else if( uiLog2BlockSize == 5 ) 1139 { 1140 scanCG = g_sigLastScanCG32x32; 1141 } 1142 } 1310 1143 1311 UInt uiSigCoeffGroupFlag[ MLS_GRP_NUM ]; 1144 static const UInt uiShift = MLS_CG_SIZE >> 1; 1145 const UInt uiNumBlkSide = uiWidth >> uiShift; 1146 1147 ::memset( uiSigCoeffGroupFlag, 0, sizeof(UInt) * MLS_GRP_NUM ); 1148 1149 do 1150 { 1151 posLast = scan[ ++scanPosLast ]; 1152 1312 1313 memset( uiSigCoeffGroupFlag, 0, sizeof(UInt) * MLS_GRP_NUM ); 1314 do 1315 { 1316 posLast = codingParameters.scan[ ++scanPosLast ]; 1317 1318 if( pcCoef[ posLast ] != 0 ) 1319 { 1153 1320 // get L1 sig map 1154 UInt uiPosY = posLast >> uiLog2BlockSize; 1155 UInt uiPosX = posLast - ( uiPosY << uiLog2BlockSize ); 1156 UInt uiBlkIdx = uiNumBlkSide * (uiPosY >> uiShift) + (uiPosX >> uiShift); 1157 if( pcCoef[ posLast ] ) 1158 { 1159 uiSigCoeffGroupFlag[ uiBlkIdx ] = 1; 1160 } 1161 1162 uiNumSig -= ( pcCoef[ posLast ] != 0 ); 1163 } 1164 while ( uiNumSig > 0 ); 1321 UInt uiPosY = posLast >> uiLog2BlockWidth; 1322 UInt uiPosX = posLast - ( uiPosY << uiLog2BlockWidth ); 1323 1324 UInt uiBlkIdx = (codingParameters.widthInGroups * (uiPosY >> MLS_CG_LOG2_HEIGHT)) + (uiPosX >> MLS_CG_LOG2_WIDTH); 1325 uiSigCoeffGroupFlag[ uiBlkIdx ] = 1; 1326 1327 uiNumSig--; 1328 } 1329 } 1330 while ( uiNumSig > 0 ); 1165 1331 1166 1332 // Code position of last coefficient 1167 Int posLastY = posLast >> uiLog2Block Size;1168 Int posLastX = posLast - ( posLastY << uiLog2Block Size);1169 codeLastSignificantXY(posLastX, posLastY, uiWidth, uiHeight, eTType, uiScanIdx);1170 1333 Int posLastY = posLast >> uiLog2BlockWidth; 1334 Int posLastX = posLast - ( posLastY << uiLog2BlockWidth ); 1335 codeLastSignificantXY(posLastX, posLastY, uiWidth, uiHeight, compID, codingParameters.scanType); 1336 1171 1337 //===== code significance flag ===== 1172 ContextModel * const baseCoeffGroupCtx = m_cCUSigCoeffGroupSCModel.get( 0, eTType );1173 ContextModel * const baseCtx = (eTType==TEXT_LUMA) ? m_cCUSigSCModel.get( 0, 0 ) : m_cCUSigSCModel.get( 0, 0 ) + NUM_SIG_FLAG_CTX_LUMA;1174 1175 1176 const Int iLastScanSet = scanPosLast >> LOG2_SCAN_SET_SIZE; 1177 UInt c1 = 1;1178 UInt uiGoRiceParam 1179 Int iScanPosSig 1338 ContextModel * const baseCoeffGroupCtx = m_cCUSigCoeffGroupSCModel.get( 0, chType ); 1339 ContextModel * const baseCtx = m_cCUSigSCModel.get( 0, 0 ) + getSignificanceMapContextOffset(compID); 1340 1341 const Int iLastScanSet = scanPosLast >> MLS_CG_SIZE; 1342 1343 UInt c1 = 1; 1344 UInt uiGoRiceParam = 0; 1345 Int iScanPosSig = scanPosLast; 1180 1346 1181 1347 for( Int iSubSet = iLastScanSet; iSubSet >= 0; iSubSet-- ) 1182 1348 { 1183 1349 Int numNonZero = 0; 1184 Int iSubPos = iSubSet << LOG2_SCAN_SET_SIZE;1185 uiGoRiceParam = 0;1186 Int absCoeff[16];1350 Int iSubPos = iSubSet << MLS_CG_SIZE; 1351 uiGoRiceParam = currentGolombRiceStatistic / RExt__GOLOMB_RICE_INCREMENT_DIVISOR; 1352 Bool updateGolombRiceStatistics = bUseGolombRiceParameterAdaptation; //leave the statistics at 0 when not using the adaptation system 1187 1353 UInt coeffSigns = 0; 1188 1354 1189 Int lastNZPosInCG = -1, firstNZPosInCG = SCAN_SET_SIZE; 1355 Int absCoeff[1 << MLS_CG_SIZE]; 1356 1357 Int lastNZPosInCG = -1; 1358 Int firstNZPosInCG = 1 << MLS_CG_SIZE; 1359 1360 Bool escapeDataPresentInGroup = false; 1190 1361 1191 1362 if( iScanPosSig == scanPosLast ) 1192 1363 { 1193 absCoeff[ 0 ] = abs( pcCoef[ posLast ]);1364 absCoeff[ 0 ] = Int(abs( pcCoef[ posLast ] )); 1194 1365 coeffSigns = ( pcCoef[ posLast ] < 0 ); 1195 1366 numNonZero = 1; … … 1199 1370 } 1200 1371 1201 // encode significant_coeffgroup_flag 1202 Int iCGBlkPos = scanCG[ iSubSet ]; 1203 Int iCGPosY = iCGBlkPos / uiNumBlkSide; 1204 Int iCGPosX = iCGBlkPos - (iCGPosY * uiNumBlkSide); 1205 if( iSubSet == iLastScanSet || iSubSet == 0) 1206 { 1207 uiSigCoeffGroupFlag[ iCGBlkPos ] = 1; 1208 } 1209 else 1210 { 1211 UInt uiSigCoeffGroup = (uiSigCoeffGroupFlag[ iCGBlkPos ] != 0); 1212 UInt uiCtxSig = TComTrQuant::getSigCoeffGroupCtxInc( uiSigCoeffGroupFlag, iCGPosX, iCGPosY, uiWidth, uiHeight ); 1213 m_pcBinIf->encodeBin( uiSigCoeffGroup, baseCoeffGroupCtx[ uiCtxSig ] ); 1214 } 1215 1216 // encode significant_coeff_flag 1217 if( uiSigCoeffGroupFlag[ iCGBlkPos ] ) 1218 { 1219 Int patternSigCtx = TComTrQuant::calcPatternSigCtx( uiSigCoeffGroupFlag, iCGPosX, iCGPosY, uiWidth, uiHeight ); 1220 UInt uiBlkPos, uiPosY, uiPosX, uiSig, uiCtxSig; 1221 for( ; iScanPosSig >= iSubPos; iScanPosSig-- ) 1372 // encode significant_coeffgroup_flag 1373 Int iCGBlkPos = codingParameters.scanCG[ iSubSet ]; 1374 Int iCGPosY = iCGBlkPos / codingParameters.widthInGroups; 1375 Int iCGPosX = iCGBlkPos - (iCGPosY * codingParameters.widthInGroups); 1376 1377 if( iSubSet == iLastScanSet || iSubSet == 0) 1378 { 1379 uiSigCoeffGroupFlag[ iCGBlkPos ] = 1; 1380 } 1381 else 1382 { 1383 UInt uiSigCoeffGroup = (uiSigCoeffGroupFlag[ iCGBlkPos ] != 0); 1384 UInt uiCtxSig = TComTrQuant::getSigCoeffGroupCtxInc( uiSigCoeffGroupFlag, iCGPosX, iCGPosY, codingParameters.widthInGroups, codingParameters.heightInGroups ); 1385 m_pcBinIf->encodeBin( uiSigCoeffGroup, baseCoeffGroupCtx[ uiCtxSig ] ); 1386 } 1387 1388 // encode significant_coeff_flag 1389 if( uiSigCoeffGroupFlag[ iCGBlkPos ] ) 1390 { 1391 const Int patternSigCtx = TComTrQuant::calcPatternSigCtx(uiSigCoeffGroupFlag, iCGPosX, iCGPosY, codingParameters.widthInGroups, codingParameters.heightInGroups); 1392 1393 UInt uiBlkPos, uiSig, uiCtxSig; 1394 for( ; iScanPosSig >= iSubPos; iScanPosSig-- ) 1395 { 1396 uiBlkPos = codingParameters.scan[ iScanPosSig ]; 1397 uiSig = (pcCoef[ uiBlkPos ] != 0); 1398 if( iScanPosSig > iSubPos || iSubSet == 0 || numNonZero ) 1222 1399 { 1223 uiBlkPos = scan[ iScanPosSig ]; 1224 uiPosY = uiBlkPos >> uiLog2BlockSize; 1225 uiPosX = uiBlkPos - ( uiPosY << uiLog2BlockSize ); 1226 uiSig = (pcCoef[ uiBlkPos ] != 0); 1227 if( iScanPosSig > iSubPos || iSubSet == 0 || numNonZero ) 1400 uiCtxSig = TComTrQuant::getSigCtxInc( patternSigCtx, codingParameters, iScanPosSig, uiLog2BlockWidth, uiLog2BlockHeight, chType ); 1401 m_pcBinIf->encodeBin( uiSig, baseCtx[ uiCtxSig ] ); 1402 } 1403 if( uiSig ) 1404 { 1405 absCoeff[ numNonZero ] = Int(abs( pcCoef[ uiBlkPos ] )); 1406 coeffSigns = 2 * coeffSigns + ( pcCoef[ uiBlkPos ] < 0 ); 1407 numNonZero++; 1408 if( lastNZPosInCG == -1 ) 1228 1409 { 1229 uiCtxSig = TComTrQuant::getSigCtxInc( patternSigCtx, uiScanIdx, uiPosX, uiPosY, uiLog2BlockSize, eTType ); 1230 m_pcBinIf->encodeBin( uiSig, baseCtx[ uiCtxSig ] ); 1410 lastNZPosInCG = iScanPosSig; 1231 1411 } 1232 if( uiSig ) 1233 { 1234 absCoeff[ numNonZero ] = abs( pcCoef[ uiBlkPos ] ); 1235 coeffSigns = 2 * coeffSigns + ( pcCoef[ uiBlkPos ] < 0 ); 1236 numNonZero++; 1237 if( lastNZPosInCG == -1 ) 1238 { 1239 lastNZPosInCG = iScanPosSig; 1240 } 1241 firstNZPosInCG = iScanPosSig; 1242 } 1412 firstNZPosInCG = iScanPosSig; 1243 1413 } 1244 1414 } 1245 else 1246 { 1247 iScanPosSig = iSubPos - 1; 1248 } 1415 } 1416 else 1417 { 1418 iScanPosSig = iSubPos - 1; 1419 } 1249 1420 1250 1421 if( numNonZero > 0 ) 1251 1422 { 1252 1423 Bool signHidden = ( lastNZPosInCG - firstNZPosInCG >= SBH_THRESHOLD ); 1253 UInt uiCtxSet = (iSubSet > 0 && eTType==TEXT_LUMA) ? 2 : 0; 1254 1255 if( c1 == 0 ) 1256 { 1257 uiCtxSet++; 1258 } 1424 1425 const UInt uiCtxSet = getContextSetIndex(compID, iSubSet, (c1 == 0)); 1259 1426 c1 = 1; 1260 ContextModel *baseCtxMod = ( eTType==TEXT_LUMA ) ? m_cCUOneSCModel.get( 0, 0 ) + 4 * uiCtxSet : m_cCUOneSCModel.get( 0, 0 ) + NUM_ONE_FLAG_CTX_LUMA + 4 * uiCtxSet; 1261 1427 1428 ContextModel *baseCtxMod = m_cCUOneSCModel.get( 0, 0 ) + (NUM_ONE_FLAG_CTX_PER_SET * uiCtxSet); 1429 1262 1430 Int numC1Flag = min(numNonZero, C1FLAG_NUMBER); 1263 1431 Int firstC2FlagIdx = -1; … … 1273 1441 { 1274 1442 firstC2FlagIdx = idx; 1443 } 1444 else //if a greater-than-one has been encountered already this group 1445 { 1446 escapeDataPresentInGroup = true; 1275 1447 } 1276 1448 } … … 1280 1452 } 1281 1453 } 1282 1454 1283 1455 if (c1 == 0) 1284 1456 { 1285 1286 baseCtxMod = ( eTType==TEXT_LUMA ) ? m_cCUAbsSCModel.get( 0, 0 ) + uiCtxSet : m_cCUAbsSCModel.get( 0, 0 ) + NUM_ABS_FLAG_CTX_LUMA + uiCtxSet; 1457 baseCtxMod = m_cCUAbsSCModel.get( 0, 0 ) + (NUM_ABS_FLAG_CTX_PER_SET * uiCtxSet); 1287 1458 if ( firstC2FlagIdx != -1) 1288 1459 { 1289 1460 UInt symbol = absCoeff[ firstC2FlagIdx ] > 2; 1290 1461 m_pcBinIf->encodeBin( symbol, baseCtxMod[0] ); 1462 if (symbol != 0) 1463 { 1464 escapeDataPresentInGroup = true; 1465 } 1291 1466 } 1292 1467 } 1293 1468 1469 escapeDataPresentInGroup = escapeDataPresentInGroup || (numNonZero > C1FLAG_NUMBER); 1470 1471 if (escapeDataPresentInGroup && alignCABACBeforeBypass) 1472 { 1473 m_pcBinIf->align(); 1474 } 1475 1294 1476 if( beValid && signHidden ) 1295 1477 { … … 1300 1482 m_pcBinIf->encodeBinsEP( coeffSigns, numNonZero ); 1301 1483 } 1302 1303 Int iFirstCoeff2 = 1; 1304 if ( c1 == 0 || numNonZero > C1FLAG_NUMBER)1484 1485 Int iFirstCoeff2 = 1; 1486 if (escapeDataPresentInGroup) 1305 1487 { 1306 1488 for ( Int idx = 0; idx < numNonZero; idx++ ) … … 1310 1492 if( absCoeff[ idx ] >= baseLevel) 1311 1493 { 1312 xWriteCoefRemainExGolomb( absCoeff[ idx ] - baseLevel, uiGoRiceParam ); 1313 if(absCoeff[idx] > 3*(1<<uiGoRiceParam)) 1494 const UInt escapeCodeValue = absCoeff[idx] - baseLevel; 1495 1496 xWriteCoefRemainExGolomb( escapeCodeValue, uiGoRiceParam, extendedPrecision, channelType ); 1497 1498 if (absCoeff[idx] > (3 << uiGoRiceParam)) 1314 1499 { 1315 uiGoRiceParam = min<UInt>(uiGoRiceParam+ 1, 4); 1500 uiGoRiceParam = bUseGolombRiceParameterAdaptation ? (uiGoRiceParam + 1) : (std::min<UInt>((uiGoRiceParam + 1), 4)); 1501 } 1502 1503 if (updateGolombRiceStatistics) 1504 { 1505 const UInt initialGolombRiceParameter = currentGolombRiceStatistic / RExt__GOLOMB_RICE_INCREMENT_DIVISOR; 1506 1507 if (escapeCodeValue >= (3 << initialGolombRiceParameter)) 1508 { 1509 currentGolombRiceStatistic++; 1510 } 1511 else if (((escapeCodeValue * 2) < (1 << initialGolombRiceParameter)) && (currentGolombRiceStatistic > 0)) 1512 { 1513 currentGolombRiceStatistic--; 1514 } 1515 1516 updateGolombRiceStatistics = false; 1316 1517 } 1317 1518 } 1318 if(absCoeff[ idx ] >= 2) 1519 1520 if(absCoeff[ idx ] >= 2) 1319 1521 { 1320 1522 iFirstCoeff2 = 0; 1321 1523 } 1322 } 1323 } 1324 } 1325 } 1524 } 1525 } 1526 } 1527 } 1528 #if ENVIRONMENT_VARIABLE_DEBUG_AND_TEST 1529 printSBACCoeffData(posLastX, posLastY, uiWidth, uiHeight, compID, uiAbsPartIdx, codingParameters.scanType, pcCoef, g_bFinalEncode); 1530 #endif 1326 1531 1327 1532 return; … … 1364 1569 } 1365 1570 1366 1367 /** Code SAO EO class or BO band position 1571 /** Code SAO EO class or BO band position 1368 1572 * \param uiLength 1369 1573 * \param uiCode … … 1371 1575 Void TEncSbac::codeSaoUflc ( UInt uiLength, UInt uiCode ) 1372 1576 { 1373 m_pcBinIf->encodeBinsEP ( uiCode, uiLength ); 1374 } 1577 m_pcBinIf->encodeBinsEP ( uiCode, uiLength ); 1578 } 1579 1375 1580 /** Code SAO merge flags 1376 1581 * \param uiCode … … 1379 1584 Void TEncSbac::codeSaoMerge ( UInt uiCode ) 1380 1585 { 1381 if (uiCode == 0) 1382 { 1383 m_pcBinIf->encodeBin(0, m_cSaoMergeSCModel.get( 0, 0, 0 )); 1384 } 1385 else 1386 { 1387 m_pcBinIf->encodeBin(1, m_cSaoMergeSCModel.get( 0, 0, 0 )); 1388 } 1389 } 1390 /** Code SAO type index 1586 m_pcBinIf->encodeBin(((uiCode == 0) ? 0 : 1), m_cSaoMergeSCModel.get( 0, 0, 0 )); 1587 } 1588 1589 /** Code SAO type index 1391 1590 * \param uiCode 1392 1591 */ … … 1403 1602 } 1404 1603 } 1405 /*!1406 ****************************************************************************1407 * \brief1408 * estimate bit cost for CBP, significant map and significant coefficients1409 ****************************************************************************1410 */1411 Void TEncSbac::estBit( estBitsSbacStruct* pcEstBitsSbac, Int width, Int height, TextType eTType )1412 {1413 estCBFBit( pcEstBitsSbac );1414 1415 estSignificantCoeffGroupMapBit( pcEstBitsSbac, eTType );1416 1417 // encode significance map1418 estSignificantMapBit( pcEstBitsSbac, width, height, eTType );1419 1420 // encode significant coefficients1421 estSignificantCoefficientsBit( pcEstBitsSbac, eTType );1422 }1423 1424 /*!1425 ****************************************************************************1426 * \brief1427 * estimate bit cost for each CBP bit1428 ****************************************************************************1429 */1430 Void TEncSbac::estCBFBit( estBitsSbacStruct* pcEstBitsSbac )1431 {1432 ContextModel *pCtx = m_cCUQtCbfSCModel.get( 0 );1433 1434 for( UInt uiCtxInc = 0; uiCtxInc < 3*NUM_QT_CBF_CTX; uiCtxInc++ )1435 {1436 pcEstBitsSbac->blockCbpBits[ uiCtxInc ][ 0 ] = pCtx[ uiCtxInc ].getEntropyBits( 0 );1437 pcEstBitsSbac->blockCbpBits[ uiCtxInc ][ 1 ] = pCtx[ uiCtxInc ].getEntropyBits( 1 );1438 }1439 1440 pCtx = m_cCUQtRootCbfSCModel.get( 0 );1441 1442 for( UInt uiCtxInc = 0; uiCtxInc < 4; uiCtxInc++ )1443 {1444 pcEstBitsSbac->blockRootCbpBits[ uiCtxInc ][ 0 ] = pCtx[ uiCtxInc ].getEntropyBits( 0 );1445 pcEstBitsSbac->blockRootCbpBits[ uiCtxInc ][ 1 ] = pCtx[ uiCtxInc ].getEntropyBits( 1 );1446 }1447 }1448 1449 1450 /*!1451 ****************************************************************************1452 * \brief1453 * estimate SAMBAC bit cost for significant coefficient group map1454 ****************************************************************************1455 */1456 Void TEncSbac::estSignificantCoeffGroupMapBit( estBitsSbacStruct* pcEstBitsSbac, TextType eTType )1457 {1458 Int firstCtx = 0, numCtx = NUM_SIG_CG_FLAG_CTX;1459 1460 for ( Int ctxIdx = firstCtx; ctxIdx < firstCtx + numCtx; ctxIdx++ )1461 {1462 for( UInt uiBin = 0; uiBin < 2; uiBin++ )1463 {1464 pcEstBitsSbac->significantCoeffGroupBits[ ctxIdx ][ uiBin ] = m_cCUSigCoeffGroupSCModel.get( 0, eTType, ctxIdx ).getEntropyBits( uiBin );1465 }1466 }1467 }1468 1469 1470 /*!1471 ****************************************************************************1472 * \brief1473 * estimate SAMBAC bit cost for significant coefficient map1474 ****************************************************************************1475 */1476 Void TEncSbac::estSignificantMapBit( estBitsSbacStruct* pcEstBitsSbac, Int width, Int height, TextType eTType )1477 {1478 Int firstCtx = 1, numCtx = 8;1479 if (max(width, height) >= 16)1480 {1481 firstCtx = (eTType == TEXT_LUMA) ? 21 : 12;1482 numCtx = (eTType == TEXT_LUMA) ? 6 : 3;1483 }1484 else if (width == 8)1485 {1486 firstCtx = 9;1487 numCtx = (eTType == TEXT_LUMA) ? 12 : 3;1488 }1489 1490 if (eTType == TEXT_LUMA )1491 {1492 for( UInt bin = 0; bin < 2; bin++ )1493 {1494 pcEstBitsSbac->significantBits[ 0 ][ bin ] = m_cCUSigSCModel.get( 0, 0, 0 ).getEntropyBits( bin );1495 }1496 1497 for ( Int ctxIdx = firstCtx; ctxIdx < firstCtx + numCtx; ctxIdx++ )1498 {1499 for( UInt uiBin = 0; uiBin < 2; uiBin++ )1500 {1501 pcEstBitsSbac->significantBits[ ctxIdx ][ uiBin ] = m_cCUSigSCModel.get( 0, 0, ctxIdx ).getEntropyBits( uiBin );1502 }1503 }1504 }1505 else1506 {1507 for( UInt bin = 0; bin < 2; bin++ )1508 {1509 pcEstBitsSbac->significantBits[ 0 ][ bin ] = m_cCUSigSCModel.get( 0, 0, NUM_SIG_FLAG_CTX_LUMA + 0 ).getEntropyBits( bin );1510 }1511 for ( Int ctxIdx = firstCtx; ctxIdx < firstCtx + numCtx; ctxIdx++ )1512 {1513 for( UInt uiBin = 0; uiBin < 2; uiBin++ )1514 {1515 pcEstBitsSbac->significantBits[ ctxIdx ][ uiBin ] = m_cCUSigSCModel.get( 0, 0, NUM_SIG_FLAG_CTX_LUMA + ctxIdx ).getEntropyBits( uiBin );1516 }1517 }1518 }1519 Int iBitsX = 0, iBitsY = 0;1520 Int blkSizeOffsetX, blkSizeOffsetY, shiftX, shiftY;1521 1522 blkSizeOffsetX = eTType ? 0: (g_aucConvertToBit[ width ] *3 + ((g_aucConvertToBit[ width ] +1)>>2));1523 blkSizeOffsetY = eTType ? 0: (g_aucConvertToBit[ height ]*3 + ((g_aucConvertToBit[ height ]+1)>>2));1524 shiftX = eTType ? g_aucConvertToBit[ width ] :((g_aucConvertToBit[ width ]+3)>>2);1525 shiftY = eTType ? g_aucConvertToBit[ height ] :((g_aucConvertToBit[ height ]+3)>>2);1526 1527 Int ctx;1528 ContextModel *pCtxX = m_cCuCtxLastX.get( 0, eTType );1529 for (ctx = 0; ctx < g_uiGroupIdx[ width - 1 ]; ctx++)1530 {1531 Int ctxOffset = blkSizeOffsetX + (ctx >>shiftX);1532 pcEstBitsSbac->lastXBits[ ctx ] = iBitsX + pCtxX[ ctxOffset ].getEntropyBits( 0 );1533 iBitsX += pCtxX[ ctxOffset ].getEntropyBits( 1 );1534 }1535 pcEstBitsSbac->lastXBits[ctx] = iBitsX;1536 ContextModel *pCtxY = m_cCuCtxLastY.get( 0, eTType );1537 for (ctx = 0; ctx < g_uiGroupIdx[ height - 1 ]; ctx++)1538 {1539 Int ctxOffset = blkSizeOffsetY + (ctx >>shiftY);1540 pcEstBitsSbac->lastYBits[ ctx ] = iBitsY + pCtxY[ ctxOffset ].getEntropyBits( 0 );1541 iBitsY += pCtxY[ ctxOffset ].getEntropyBits( 1 );1542 }1543 pcEstBitsSbac->lastYBits[ctx] = iBitsY;1544 }1545 1546 /*!1547 ****************************************************************************1548 * \brief1549 * estimate bit cost of significant coefficient1550 ****************************************************************************1551 */1552 Void TEncSbac::estSignificantCoefficientsBit( estBitsSbacStruct* pcEstBitsSbac, TextType eTType )1553 {1554 if (eTType==TEXT_LUMA)1555 {1556 ContextModel *ctxOne = m_cCUOneSCModel.get(0, 0);1557 ContextModel *ctxAbs = m_cCUAbsSCModel.get(0, 0);1558 1559 for (Int ctxIdx = 0; ctxIdx < NUM_ONE_FLAG_CTX_LUMA; ctxIdx++)1560 {1561 pcEstBitsSbac->m_greaterOneBits[ ctxIdx ][ 0 ] = ctxOne[ ctxIdx ].getEntropyBits( 0 );1562 pcEstBitsSbac->m_greaterOneBits[ ctxIdx ][ 1 ] = ctxOne[ ctxIdx ].getEntropyBits( 1 );1563 }1564 1565 for (Int ctxIdx = 0; ctxIdx < NUM_ABS_FLAG_CTX_LUMA; ctxIdx++)1566 {1567 pcEstBitsSbac->m_levelAbsBits[ ctxIdx ][ 0 ] = ctxAbs[ ctxIdx ].getEntropyBits( 0 );1568 pcEstBitsSbac->m_levelAbsBits[ ctxIdx ][ 1 ] = ctxAbs[ ctxIdx ].getEntropyBits( 1 );1569 }1570 }1571 else1572 {1573 ContextModel *ctxOne = m_cCUOneSCModel.get(0, 0) + NUM_ONE_FLAG_CTX_LUMA;1574 ContextModel *ctxAbs = m_cCUAbsSCModel.get(0, 0) + NUM_ABS_FLAG_CTX_LUMA;1575 1576 for (Int ctxIdx = 0; ctxIdx < NUM_ONE_FLAG_CTX_CHROMA; ctxIdx++)1577 {1578 pcEstBitsSbac->m_greaterOneBits[ ctxIdx ][ 0 ] = ctxOne[ ctxIdx ].getEntropyBits( 0 );1579 pcEstBitsSbac->m_greaterOneBits[ ctxIdx ][ 1 ] = ctxOne[ ctxIdx ].getEntropyBits( 1 );1580 }1581 1582 for (Int ctxIdx = 0; ctxIdx < NUM_ABS_FLAG_CTX_CHROMA; ctxIdx++)1583 {1584 pcEstBitsSbac->m_levelAbsBits[ ctxIdx ][ 0 ] = ctxAbs[ ctxIdx ].getEntropyBits( 0 );1585 pcEstBitsSbac->m_levelAbsBits[ ctxIdx ][ 1 ] = ctxAbs[ ctxIdx ].getEntropyBits( 1 );1586 }1587 }1588 }1589 1590 /**1591 - Initialize our context information from the nominated source.1592 .1593 \param pSrc From where to copy context information.1594 */1595 Void TEncSbac::xCopyContextsFrom( TEncSbac* pSrc )1596 {1597 memcpy(m_contextModels, pSrc->m_contextModels, m_numContextModels*sizeof(m_contextModels[0]));1598 }1599 1600 Void TEncSbac::loadContexts ( TEncSbac* pScr)1601 {1602 this->xCopyContextsFrom(pScr);1603 }1604 1605 1604 #if SVC_EXTENSION 1606 Void TEncSbac::codeSAOOffsetParam( IntcompIdx, SAOOffset& ctbParam, Bool sliceEnabled, UInt* saoMaxOffsetQVal)1605 Void TEncSbac::codeSAOOffsetParam(ComponentID compIdx, SAOOffset& ctbParam, Bool sliceEnabled, UInt* saoMaxOffsetQVal) 1607 1606 #else 1608 Void TEncSbac::codeSAOOffsetParam( IntcompIdx, SAOOffset& ctbParam, Bool sliceEnabled)1607 Void TEncSbac::codeSAOOffsetParam(ComponentID compIdx, SAOOffset& ctbParam, Bool sliceEnabled) 1609 1608 #endif 1610 1609 { … … 1615 1614 return; 1616 1615 } 1616 const Bool bIsFirstCompOfChType = (getFirstComponentOfChannel(toChannelType(compIdx)) == compIdx); 1617 1617 1618 1618 //type 1619 if( compIdx == SAO_Y || compIdx == SAO_Cb)1619 if(bIsFirstCompOfChType) 1620 1620 { 1621 1621 //sao_type_idx_luma or sao_type_idx_chroma … … 1633 1633 uiSymbol = 2; 1634 1634 } 1635 codeSaoTypeIdx(uiSymbol); 1635 codeSaoTypeIdx(uiSymbol); 1636 1636 } 1637 1637 1638 1638 if(ctbParam.modeIdc == SAO_MODE_NEW) 1639 1639 { 1640 Int numClasses = (ctbParam.typeIdc == SAO_TYPE_BO)?4:NUM_SAO_EO_CLASSES; 1640 Int numClasses = (ctbParam.typeIdc == SAO_TYPE_BO)?4:NUM_SAO_EO_CLASSES; 1641 1641 Int offset[4]; 1642 1642 Int k=0; … … 1676 1676 else //EO 1677 1677 { 1678 if( compIdx == SAO_Y || compIdx == SAO_Cb)1678 if(bIsFirstCompOfChType) 1679 1679 { 1680 1680 assert(ctbParam.typeIdc - SAO_TYPE_START_EO >=0); … … 1703 1703 if(leftMergeAvail) 1704 1704 { 1705 isLeftMerge = ((saoBlkParam[ SAO_Y].modeIdc == SAO_MODE_MERGE) && (saoBlkParam[SAO_Y].typeIdc == SAO_MERGE_LEFT));1705 isLeftMerge = ((saoBlkParam[COMPONENT_Y].modeIdc == SAO_MODE_MERGE) && (saoBlkParam[COMPONENT_Y].typeIdc == SAO_MERGE_LEFT)); 1706 1706 codeSaoMerge( isLeftMerge?1:0 ); //sao_merge_left_flag 1707 1707 } … … 1709 1709 if( aboveMergeAvail && !isLeftMerge) 1710 1710 { 1711 isAboveMerge = ((saoBlkParam[ SAO_Y].modeIdc == SAO_MODE_MERGE) && (saoBlkParam[SAO_Y].typeIdc == SAO_MERGE_ABOVE));1711 isAboveMerge = ((saoBlkParam[COMPONENT_Y].modeIdc == SAO_MODE_MERGE) && (saoBlkParam[COMPONENT_Y].typeIdc == SAO_MERGE_ABOVE)); 1712 1712 codeSaoMerge( isAboveMerge?1:0 ); //sao_merge_left_flag 1713 1713 } … … 1720 1720 if(!isLeftMerge && !isAboveMerge) //not merge mode 1721 1721 { 1722 for(Int compIdx=0; compIdx < NUM_SAO_COMPONENTS; compIdx++)1722 for(Int compIdx=0; compIdx < MAX_NUM_COMPONENT; compIdx++) 1723 1723 { 1724 1724 #if SVC_EXTENSION 1725 codeSAOOffsetParam( compIdx, saoBlkParam[compIdx], sliceEnabled[compIdx], saoMaxOffsetQVal);1725 codeSAOOffsetParam(ComponentID(compIdx), saoBlkParam[compIdx], sliceEnabled[compIdx], saoMaxOffsetQVal); 1726 1726 #else 1727 codeSAOOffsetParam( compIdx, saoBlkParam[compIdx], sliceEnabled[compIdx]);1727 codeSAOOffsetParam(ComponentID(compIdx), saoBlkParam[compIdx], sliceEnabled[compIdx]); 1728 1728 #endif 1729 1729 } … … 1731 1731 } 1732 1732 1733 /*! 1734 **************************************************************************** 1735 * \brief 1736 * estimate bit cost for CBP, significant map and significant coefficients 1737 **************************************************************************** 1738 */ 1739 Void TEncSbac::estBit( estBitsSbacStruct* pcEstBitsSbac, Int width, Int height, ChannelType chType ) 1740 { 1741 estCBFBit( pcEstBitsSbac ); 1742 1743 estSignificantCoeffGroupMapBit( pcEstBitsSbac, chType ); 1744 1745 // encode significance map 1746 estSignificantMapBit( pcEstBitsSbac, width, height, chType ); 1747 1748 // encode last significant position 1749 estLastSignificantPositionBit( pcEstBitsSbac, width, height, chType ); 1750 1751 // encode significant coefficients 1752 estSignificantCoefficientsBit( pcEstBitsSbac, chType ); 1753 1754 memcpy(pcEstBitsSbac->golombRiceAdaptationStatistics, m_golombRiceAdaptationStatistics, (sizeof(UInt) * RExt__GOLOMB_RICE_ADAPTATION_STATISTICS_SETS)); 1755 } 1756 1757 /*! 1758 **************************************************************************** 1759 * \brief 1760 * estimate bit cost for each CBP bit 1761 **************************************************************************** 1762 */ 1763 Void TEncSbac::estCBFBit( estBitsSbacStruct* pcEstBitsSbac ) 1764 { 1765 ContextModel *pCtx = m_cCUQtCbfSCModel.get( 0 ); 1766 1767 for( UInt uiCtxInc = 0; uiCtxInc < (NUM_QT_CBF_CTX_SETS * NUM_QT_CBF_CTX_PER_SET); uiCtxInc++ ) 1768 { 1769 pcEstBitsSbac->blockCbpBits[ uiCtxInc ][ 0 ] = pCtx[ uiCtxInc ].getEntropyBits( 0 ); 1770 pcEstBitsSbac->blockCbpBits[ uiCtxInc ][ 1 ] = pCtx[ uiCtxInc ].getEntropyBits( 1 ); 1771 } 1772 1773 pCtx = m_cCUQtRootCbfSCModel.get( 0 ); 1774 1775 for( UInt uiCtxInc = 0; uiCtxInc < 4; uiCtxInc++ ) 1776 { 1777 pcEstBitsSbac->blockRootCbpBits[ uiCtxInc ][ 0 ] = pCtx[ uiCtxInc ].getEntropyBits( 0 ); 1778 pcEstBitsSbac->blockRootCbpBits[ uiCtxInc ][ 1 ] = pCtx[ uiCtxInc ].getEntropyBits( 1 ); 1779 } 1780 } 1781 1782 1783 /*! 1784 **************************************************************************** 1785 * \brief 1786 * estimate SAMBAC bit cost for significant coefficient group map 1787 **************************************************************************** 1788 */ 1789 Void TEncSbac::estSignificantCoeffGroupMapBit( estBitsSbacStruct* pcEstBitsSbac, ChannelType chType ) 1790 { 1791 Int firstCtx = 0, numCtx = NUM_SIG_CG_FLAG_CTX; 1792 1793 for ( Int ctxIdx = firstCtx; ctxIdx < firstCtx + numCtx; ctxIdx++ ) 1794 { 1795 for( UInt uiBin = 0; uiBin < 2; uiBin++ ) 1796 { 1797 pcEstBitsSbac->significantCoeffGroupBits[ ctxIdx ][ uiBin ] = m_cCUSigCoeffGroupSCModel.get( 0, chType, ctxIdx ).getEntropyBits( uiBin ); 1798 } 1799 } 1800 } 1801 1802 1803 /*! 1804 **************************************************************************** 1805 * \brief 1806 * estimate SAMBAC bit cost for significant coefficient map 1807 **************************************************************************** 1808 */ 1809 Void TEncSbac::estSignificantMapBit( estBitsSbacStruct* pcEstBitsSbac, Int width, Int height, ChannelType chType ) 1810 { 1811 //-------------------------------------------------------------------------------------------------- 1812 1813 //set up the number of channels and context variables 1814 1815 const UInt firstComponent = ((isLuma(chType)) ? (COMPONENT_Y) : (COMPONENT_Cb)); 1816 const UInt lastComponent = ((isLuma(chType)) ? (COMPONENT_Y) : (COMPONENT_Cb)); 1817 1818 //---------------------------------------------------------- 1819 1820 Int firstCtx = MAX_INT; 1821 Int numCtx = MAX_INT; 1822 1823 if ((width == 4) && (height == 4)) 1824 { 1825 firstCtx = significanceMapContextSetStart[chType][CONTEXT_TYPE_4x4]; 1826 numCtx = significanceMapContextSetSize [chType][CONTEXT_TYPE_4x4]; 1827 } 1828 else if ((width == 8) && (height == 8)) 1829 { 1830 firstCtx = significanceMapContextSetStart[chType][CONTEXT_TYPE_8x8]; 1831 numCtx = significanceMapContextSetSize [chType][CONTEXT_TYPE_8x8]; 1832 } 1833 else 1834 { 1835 firstCtx = significanceMapContextSetStart[chType][CONTEXT_TYPE_NxN]; 1836 numCtx = significanceMapContextSetSize [chType][CONTEXT_TYPE_NxN]; 1837 } 1838 1839 //-------------------------------------------------------------------------------------------------- 1840 1841 //fill the data for the significace map 1842 1843 for (UInt component = firstComponent; component <= lastComponent; component++) 1844 { 1845 const UInt contextOffset = getSignificanceMapContextOffset(ComponentID(component)); 1846 1847 if (firstCtx > 0) 1848 { 1849 for( UInt bin = 0; bin < 2; bin++ ) //always get the DC 1850 { 1851 pcEstBitsSbac->significantBits[ contextOffset ][ bin ] = m_cCUSigSCModel.get( 0, 0, contextOffset ).getEntropyBits( bin ); 1852 } 1853 } 1854 1855 // This could be made optional, but would require this function to have knowledge of whether the 1856 // TU is transform-skipped or transquant-bypassed and whether the SPS flag is set 1857 for( UInt bin = 0; bin < 2; bin++ ) 1858 { 1859 const Int ctxIdx = significanceMapContextSetStart[chType][CONTEXT_TYPE_SINGLE]; 1860 pcEstBitsSbac->significantBits[ contextOffset + ctxIdx ][ bin ] = m_cCUSigSCModel.get( 0, 0, (contextOffset + ctxIdx) ).getEntropyBits( bin ); 1861 } 1862 1863 for ( Int ctxIdx = firstCtx; ctxIdx < firstCtx + numCtx; ctxIdx++ ) 1864 { 1865 for( UInt uiBin = 0; uiBin < 2; uiBin++ ) 1866 { 1867 pcEstBitsSbac->significantBits[ contextOffset + ctxIdx ][ uiBin ] = m_cCUSigSCModel.get( 0, 0, (contextOffset + ctxIdx) ).getEntropyBits( uiBin ); 1868 } 1869 } 1870 } 1871 1872 //-------------------------------------------------------------------------------------------------- 1873 } 1874 1875 1876 /*! 1877 **************************************************************************** 1878 * \brief 1879 * estimate bit cost of significant coefficient 1880 **************************************************************************** 1881 */ 1882 1883 Void TEncSbac::estLastSignificantPositionBit( estBitsSbacStruct* pcEstBitsSbac, Int width, Int height, ChannelType chType ) 1884 { 1885 //--------------------------------------------------------------------------------------------------. 1886 1887 //set up the number of channels 1888 1889 const UInt firstComponent = ((isLuma(chType)) ? (COMPONENT_Y) : (COMPONENT_Cb)); 1890 const UInt lastComponent = ((isLuma(chType)) ? (COMPONENT_Y) : (COMPONENT_Cb)); 1891 1892 //-------------------------------------------------------------------------------------------------- 1893 1894 //fill the data for the last-significant-coefficient position 1895 1896 for (UInt componentIndex = firstComponent; componentIndex <= lastComponent; componentIndex++) 1897 { 1898 const ComponentID component = ComponentID(componentIndex); 1899 1900 Int iBitsX = 0, iBitsY = 0; 1901 1902 Int blkSizeOffsetX, blkSizeOffsetY, shiftX, shiftY; 1903 getLastSignificantContextParameters(ComponentID(component), width, height, blkSizeOffsetX, blkSizeOffsetY, shiftX, shiftY); 1904 1905 Int ctx; 1906 1907 const ChannelType channelType = toChannelType(ComponentID(component)); 1908 1909 ContextModel *const pCtxX = m_cCuCtxLastX.get( 0, channelType ); 1910 ContextModel *const pCtxY = m_cCuCtxLastY.get( 0, channelType ); 1911 Int *const lastXBitsArray = pcEstBitsSbac->lastXBits[channelType]; 1912 Int *const lastYBitsArray = pcEstBitsSbac->lastYBits[channelType]; 1913 1914 //------------------------------------------------ 1915 1916 //X-coordinate 1917 1918 for (ctx = 0; ctx < g_uiGroupIdx[ width - 1 ]; ctx++) 1919 { 1920 Int ctxOffset = blkSizeOffsetX + (ctx >>shiftX); 1921 lastXBitsArray[ ctx ] = iBitsX + pCtxX[ ctxOffset ].getEntropyBits( 0 ); 1922 iBitsX += pCtxX[ ctxOffset ].getEntropyBits( 1 ); 1923 } 1924 1925 lastXBitsArray[ctx] = iBitsX; 1926 1927 //------------------------------------------------ 1928 1929 //Y-coordinate 1930 1931 for (ctx = 0; ctx < g_uiGroupIdx[ height - 1 ]; ctx++) 1932 { 1933 Int ctxOffset = blkSizeOffsetY + (ctx >>shiftY); 1934 lastYBitsArray[ ctx ] = iBitsY + pCtxY[ ctxOffset ].getEntropyBits( 0 ); 1935 iBitsY += pCtxY[ ctxOffset ].getEntropyBits( 1 ); 1936 } 1937 1938 lastYBitsArray[ctx] = iBitsY; 1939 1940 } //end of component loop 1941 1942 //-------------------------------------------------------------------------------------------------- 1943 } 1944 1945 1946 /*! 1947 **************************************************************************** 1948 * \brief 1949 * estimate bit cost of significant coefficient 1950 **************************************************************************** 1951 */ 1952 Void TEncSbac::estSignificantCoefficientsBit( estBitsSbacStruct* pcEstBitsSbac, ChannelType chType ) 1953 { 1954 ContextModel *ctxOne = m_cCUOneSCModel.get(0, 0); 1955 ContextModel *ctxAbs = m_cCUAbsSCModel.get(0, 0); 1956 1957 const UInt oneStartIndex = ((isLuma(chType)) ? (0) : (NUM_ONE_FLAG_CTX_LUMA)); 1958 const UInt oneStopIndex = ((isLuma(chType)) ? (NUM_ONE_FLAG_CTX_LUMA) : (NUM_ONE_FLAG_CTX)); 1959 const UInt absStartIndex = ((isLuma(chType)) ? (0) : (NUM_ABS_FLAG_CTX_LUMA)); 1960 const UInt absStopIndex = ((isLuma(chType)) ? (NUM_ABS_FLAG_CTX_LUMA) : (NUM_ABS_FLAG_CTX)); 1961 1962 for (Int ctxIdx = oneStartIndex; ctxIdx < oneStopIndex; ctxIdx++) 1963 { 1964 pcEstBitsSbac->m_greaterOneBits[ ctxIdx ][ 0 ] = ctxOne[ ctxIdx ].getEntropyBits( 0 ); 1965 pcEstBitsSbac->m_greaterOneBits[ ctxIdx ][ 1 ] = ctxOne[ ctxIdx ].getEntropyBits( 1 ); 1966 } 1967 1968 for (Int ctxIdx = absStartIndex; ctxIdx < absStopIndex; ctxIdx++) 1969 { 1970 pcEstBitsSbac->m_levelAbsBits[ ctxIdx ][ 0 ] = ctxAbs[ ctxIdx ].getEntropyBits( 0 ); 1971 pcEstBitsSbac->m_levelAbsBits[ ctxIdx ][ 1 ] = ctxAbs[ ctxIdx ].getEntropyBits( 1 ); 1972 } 1973 } 1974 1975 /** 1976 - Initialize our context information from the nominated source. 1977 . 1978 \param pSrc From where to copy context information. 1979 */ 1980 Void TEncSbac::xCopyContextsFrom( const TEncSbac* pSrc ) 1981 { 1982 memcpy(m_contextModels, pSrc->m_contextModels, m_numContextModels*sizeof(m_contextModels[0])); 1983 memcpy(m_golombRiceAdaptationStatistics, pSrc->m_golombRiceAdaptationStatistics, (sizeof(UInt) * RExt__GOLOMB_RICE_ADAPTATION_STATISTICS_SETS)); 1984 } 1985 1986 Void TEncSbac::loadContexts ( const TEncSbac* pSrc) 1987 { 1988 xCopyContextsFrom(pSrc); 1989 } 1990 1991 /** Performs CABAC encoding of the explicit RDPCM mode 1992 * \param rTu current TU data structure 1993 * \param compID component identifier 1994 */ 1995 Void TEncSbac::codeExplicitRdpcmMode( TComTU &rTu, const ComponentID compID ) 1996 { 1997 TComDataCU *cu = rTu.getCU(); 1998 const TComRectangle &rect = rTu.getRect(compID); 1999 const UInt absPartIdx = rTu.GetAbsPartIdxTU(compID); 2000 const UInt tuHeight = g_aucConvertToBit[rect.height]; 2001 const UInt tuWidth = g_aucConvertToBit[rect.width]; 2002 2003 assert(tuHeight == tuWidth); 2004 assert(tuHeight < 4); 2005 2006 UInt explicitRdpcmMode = cu->getExplicitRdpcmMode(compID, absPartIdx); 2007 2008 if( explicitRdpcmMode == RDPCM_OFF ) 2009 { 2010 m_pcBinIf->encodeBin (0, m_explicitRdpcmFlagSCModel.get (0, toChannelType(compID), 0)); 2011 } 2012 else if( explicitRdpcmMode == RDPCM_HOR || explicitRdpcmMode == RDPCM_VER ) 2013 { 2014 m_pcBinIf->encodeBin (1, m_explicitRdpcmFlagSCModel.get (0, toChannelType(compID), 0)); 2015 if(explicitRdpcmMode == RDPCM_HOR) 2016 { 2017 m_pcBinIf->encodeBin ( 0, m_explicitRdpcmDirSCModel.get(0, toChannelType(compID), 0)); 2018 } 2019 else 2020 { 2021 m_pcBinIf->encodeBin ( 1, m_explicitRdpcmDirSCModel.get(0, toChannelType(compID), 0)); 2022 } 2023 } 2024 else 2025 { 2026 assert(0); 2027 } 2028 } 2029 2030 #if POC_RESET_IDC_SIGNALLING 2031 Void TEncSbac::codeSliceHeaderExtn( TComSlice* pSlice, Int shBitsWrittenTillNow ) 2032 { 2033 assert (0); 2034 return; 2035 } 2036 #endif 2037 1733 2038 //! \}
Note: See TracChangeset for help on using the changeset viewer.