Changeset 1313 in 3DVCSoftware for trunk/source/Lib/TLibEncoder/TEncSbac.cpp
- Timestamp:
- 13 Aug 2015, 17:38:13 (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/source/Lib/TLibEncoder/TEncSbac.cpp
r1196 r1313 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 * Copyright (c) 2010-2015, ITU/ISO/IEC6 * Copyright (c) 2010-2015, ITU/ISO/IEC 7 7 * All rights reserved. 8 8 * … … 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 #if H_3D 61 , m_cCUDISFlagSCModel ( 1, 1, NUM_DIS_FLAG_CTX , m_contextModels + m_numContextModels, m_numContextModels) 62 , m_cCUDISTypeSCModel ( 1, 1, NUM_DIS_TYPE_CTX , m_contextModels + m_numContextModels, m_numContextModels) 63 #endif 64 , m_cCUMergeFlagExtSCModel ( 1, 1, NUM_MERGE_FLAG_EXT_CTX , m_contextModels + m_numContextModels, m_numContextModels) 65 , m_cCUMergeIdxExtSCModel ( 1, 1, NUM_MERGE_IDX_EXT_CTX , m_contextModels + m_numContextModels, m_numContextModels) 66 #if H_3D_ARP 67 , m_cCUPUARPWSCModel ( 1, 1, NUM_ARPW_CTX , m_contextModels + m_numContextModels, m_numContextModels) 68 #endif 69 #if H_3D_IC 70 , m_cCUICFlagSCModel ( 1, 1, NUM_IC_FLAG_CTX , m_contextModels + m_numContextModels, m_numContextModels) 71 #endif 72 , m_cCUPartSizeSCModel ( 1, 1, NUM_PART_SIZE_CTX , m_contextModels + m_numContextModels, m_numContextModels) 73 , m_cCUPredModeSCModel ( 1, 1, NUM_PRED_MODE_CTX , m_contextModels + m_numContextModels, m_numContextModels) 74 , m_cCUIntraPredSCModel ( 1, 1, NUM_ADI_CTX , m_contextModels + m_numContextModels, m_numContextModels) 75 , m_cCUChromaPredSCModel ( 1, 1, NUM_CHROMA_PRED_CTX , m_contextModels + m_numContextModels, m_numContextModels) 76 , m_cCUDeltaQpSCModel ( 1, 1, NUM_DELTA_QP_CTX , m_contextModels + m_numContextModels, m_numContextModels) 77 , m_cCUInterDirSCModel ( 1, 1, NUM_INTER_DIR_CTX , m_contextModels + m_numContextModels, m_numContextModels) 78 , m_cCURefPicSCModel ( 1, 1, NUM_REF_NO_CTX , m_contextModels + m_numContextModels, m_numContextModels) 79 , m_cCUMvdSCModel ( 1, 1, NUM_MV_RES_CTX , m_contextModels + m_numContextModels, m_numContextModels) 80 , m_cCUQtCbfSCModel ( 1, 2, NUM_QT_CBF_CTX , m_contextModels + m_numContextModels, m_numContextModels) 81 , m_cCUTransSubdivFlagSCModel ( 1, 1, NUM_TRANS_SUBDIV_FLAG_CTX , m_contextModels + m_numContextModels, m_numContextModels) 82 , m_cCUQtRootCbfSCModel ( 1, 1, NUM_QT_ROOT_CBF_CTX , m_contextModels + m_numContextModels, m_numContextModels) 83 , m_cCUSigCoeffGroupSCModel ( 1, 2, NUM_SIG_CG_FLAG_CTX , m_contextModels + m_numContextModels, m_numContextModels) 84 , m_cCUSigSCModel ( 1, 1, NUM_SIG_FLAG_CTX , m_contextModels + m_numContextModels, m_numContextModels) 85 , m_cCuCtxLastX ( 1, 2, NUM_CTX_LAST_FLAG_XY , m_contextModels + m_numContextModels, m_numContextModels) 86 , m_cCuCtxLastY ( 1, 2, NUM_CTX_LAST_FLAG_XY , m_contextModels + m_numContextModels, m_numContextModels) 87 , m_cCUOneSCModel ( 1, 1, NUM_ONE_FLAG_CTX , m_contextModels + m_numContextModels, m_numContextModels) 88 , m_cCUAbsSCModel ( 1, 1, NUM_ABS_FLAG_CTX , m_contextModels + m_numContextModels, m_numContextModels) 89 , m_cMVPIdxSCModel ( 1, 1, NUM_MVP_IDX_CTX , m_contextModels + m_numContextModels, m_numContextModels) 90 , m_cSaoMergeSCModel ( 1, 1, NUM_SAO_MERGE_FLAG_CTX , m_contextModels + m_numContextModels, m_numContextModels) 91 , m_cSaoTypeIdxSCModel ( 1, 1, NUM_SAO_TYPE_IDX_CTX , m_contextModels + m_numContextModels, m_numContextModels) 92 , m_cTransformSkipSCModel ( 1, 2, NUM_TRANSFORMSKIP_FLAG_CTX , m_contextModels + m_numContextModels, m_numContextModels) 93 , m_CUTransquantBypassFlagSCModel( 1, 1, NUM_CU_TRANSQUANT_BYPASS_FLAG_CTX, m_contextModels + m_numContextModels, m_numContextModels) 94 #if H_3D_DIM 95 , m_cDepthIntraModeSCModel ( 1, 1, NUM_DEPTH_INTRA_MODE_CTX , m_contextModels + m_numContextModels, m_numContextModels) 96 , m_cDdcFlagSCModel ( 1, 1, NUM_DDC_FLAG_CTX , m_contextModels + m_numContextModels, m_numContextModels) 97 , m_cDdcDataSCModel ( 1, 1, NUM_DDC_DATA_CTX , m_contextModels + m_numContextModels, m_numContextModels) 98 , m_cAngleFlagSCModel ( 1, 1, NUM_ANGLE_FLAG_CTX , m_contextModels + m_numContextModels, m_numContextModels) 99 #if H_3D_DIM_SDC 100 , m_cSDCResidualFlagSCModel ( 1, 1, SDC_NUM_RESIDUAL_FLAG_CTX , m_contextModels + m_numContextModels, m_numContextModels) 101 , m_cSDCResidualSCModel ( 1, 1, SDC_NUM_RESIDUAL_CTX , m_contextModels + m_numContextModels, m_numContextModels) 102 #endif 103 #endif 104 #if H_3D_DIM_SDC 105 , m_cSDCFlagSCModel ( 1, 1, NUM_SDC_FLAG_CTX , m_contextModels + m_numContextModels, m_numContextModels) 106 #endif 107 #if H_3D_DBBP 108 , m_cDBBPFlagSCModel ( 1, 1, DBBP_NUM_FLAG_CTX , m_contextModels + m_numContextModels, m_numContextModels) 59 : m_pcBitIf ( NULL ) 60 , m_pcBinIf ( NULL ) 61 , m_numContextModels ( 0 ) 62 , m_cCUSplitFlagSCModel ( 1, 1, NUM_SPLIT_FLAG_CTX , m_contextModels + m_numContextModels, m_numContextModels) 63 , m_cCUSkipFlagSCModel ( 1, 1, NUM_SKIP_FLAG_CTX , m_contextModels + m_numContextModels, m_numContextModels) 64 #if NH_3D_DIS 65 , m_cCUDISFlagSCModel ( 1, 1, NUM_DIS_FLAG_CTX , m_contextModels + m_numContextModels, m_numContextModels) 66 , m_cCUDISTypeSCModel ( 1, 1, NUM_DIS_TYPE_CTX , m_contextModels + m_numContextModels, m_numContextModels) 67 #endif 68 , m_cCUMergeFlagExtSCModel ( 1, 1, NUM_MERGE_FLAG_EXT_CTX , m_contextModels + m_numContextModels, m_numContextModels) 69 , m_cCUMergeIdxExtSCModel ( 1, 1, NUM_MERGE_IDX_EXT_CTX , m_contextModels + m_numContextModels, m_numContextModels) 70 #if NH_3D_ARP 71 , m_cCUPUARPWSCModel ( 1, 1, NUM_ARPW_CTX , m_contextModels + m_numContextModels, m_numContextModels) 72 #endif 73 #if NH_3D_IC 74 , m_cCUICFlagSCModel ( 1, 1, NUM_IC_FLAG_CTX , m_contextModels + m_numContextModels, m_numContextModels) 75 #endif 76 , m_cCUPartSizeSCModel ( 1, 1, NUM_PART_SIZE_CTX , m_contextModels + m_numContextModels, m_numContextModels) 77 , m_cCUPredModeSCModel ( 1, 1, NUM_PRED_MODE_CTX , m_contextModels + m_numContextModels, m_numContextModels) 78 , m_cCUIntraPredSCModel ( 1, 1, NUM_INTRA_PREDICT_CTX , m_contextModels + m_numContextModels, m_numContextModels) 79 , m_cCUChromaPredSCModel ( 1, 1, NUM_CHROMA_PRED_CTX , m_contextModels + m_numContextModels, m_numContextModels) 80 , m_cCUDeltaQpSCModel ( 1, 1, NUM_DELTA_QP_CTX , m_contextModels + m_numContextModels, m_numContextModels) 81 , m_cCUInterDirSCModel ( 1, 1, NUM_INTER_DIR_CTX , m_contextModels + m_numContextModels, m_numContextModels) 82 , m_cCURefPicSCModel ( 1, 1, NUM_REF_NO_CTX , m_contextModels + m_numContextModels, m_numContextModels) 83 , m_cCUMvdSCModel ( 1, 1, NUM_MV_RES_CTX , m_contextModels + m_numContextModels, m_numContextModels) 84 , m_cCUQtCbfSCModel ( 1, NUM_QT_CBF_CTX_SETS, NUM_QT_CBF_CTX_PER_SET , m_contextModels + m_numContextModels, m_numContextModels) 85 , m_cCUTransSubdivFlagSCModel ( 1, 1, NUM_TRANS_SUBDIV_FLAG_CTX , m_contextModels + m_numContextModels, m_numContextModels) 86 , m_cCUQtRootCbfSCModel ( 1, 1, NUM_QT_ROOT_CBF_CTX , m_contextModels + m_numContextModels, m_numContextModels) 87 , m_cCUSigCoeffGroupSCModel ( 1, 2, NUM_SIG_CG_FLAG_CTX , m_contextModels + m_numContextModels, m_numContextModels) 88 , m_cCUSigSCModel ( 1, 1, NUM_SIG_FLAG_CTX , m_contextModels + m_numContextModels, m_numContextModels) 89 , m_cCuCtxLastX ( 1, NUM_CTX_LAST_FLAG_SETS, NUM_CTX_LAST_FLAG_XY , m_contextModels + m_numContextModels, m_numContextModels) 90 , m_cCuCtxLastY ( 1, NUM_CTX_LAST_FLAG_SETS, NUM_CTX_LAST_FLAG_XY , m_contextModels + m_numContextModels, m_numContextModels) 91 , m_cCUOneSCModel ( 1, 1, NUM_ONE_FLAG_CTX , m_contextModels + m_numContextModels, m_numContextModels) 92 , m_cCUAbsSCModel ( 1, 1, NUM_ABS_FLAG_CTX , m_contextModels + m_numContextModels, m_numContextModels) 93 , m_cMVPIdxSCModel ( 1, 1, NUM_MVP_IDX_CTX , m_contextModels + m_numContextModels, m_numContextModels) 94 , m_cSaoMergeSCModel ( 1, 1, NUM_SAO_MERGE_FLAG_CTX , m_contextModels + m_numContextModels, m_numContextModels) 95 , m_cSaoTypeIdxSCModel ( 1, 1, NUM_SAO_TYPE_IDX_CTX , m_contextModels + m_numContextModels, m_numContextModels) 96 , m_cTransformSkipSCModel ( 1, MAX_NUM_CHANNEL_TYPE, NUM_TRANSFORMSKIP_FLAG_CTX , m_contextModels + m_numContextModels, m_numContextModels) 97 , m_CUTransquantBypassFlagSCModel ( 1, 1, NUM_CU_TRANSQUANT_BYPASS_FLAG_CTX , m_contextModels + m_numContextModels, m_numContextModels) 98 , m_explicitRdpcmFlagSCModel ( 1, MAX_NUM_CHANNEL_TYPE, NUM_EXPLICIT_RDPCM_FLAG_CTX , m_contextModels + m_numContextModels, m_numContextModels) 99 , m_explicitRdpcmDirSCModel ( 1, MAX_NUM_CHANNEL_TYPE, NUM_EXPLICIT_RDPCM_DIR_CTX , m_contextModels + m_numContextModels, m_numContextModels) 100 , m_cCrossComponentPredictionSCModel ( 1, 1, NUM_CROSS_COMPONENT_PREDICTION_CTX , m_contextModels + m_numContextModels, m_numContextModels) 101 , m_ChromaQpAdjFlagSCModel ( 1, 1, NUM_CHROMA_QP_ADJ_FLAG_CTX , m_contextModels + m_numContextModels, m_numContextModels) 102 , m_ChromaQpAdjIdcSCModel ( 1, 1, NUM_CHROMA_QP_ADJ_IDC_CTX , m_contextModels + m_numContextModels, m_numContextModels) 103 104 #if NH_3D_DMM 105 , m_cNotDmmFlagSCModel ( 1, 1, NUM_NOTDMM_FLAG_CTX , m_contextModels + m_numContextModels, m_numContextModels) 106 , m_cDmmModeSCModel ( 1, 1, NUM_DMM_MODE_CTX , m_contextModels + m_numContextModels, m_numContextModels) 107 #endif 108 #if NH_3D_DMM || NH_3D_SDC_INTRA || NH_3D_SDC_INTER 109 , m_cDdcDataSCModel ( 1, 1, NUM_DDC_DATA_CTX , m_contextModels + m_numContextModels, m_numContextModels) 110 , m_cSDCFlagSCModel ( 1, 1, NUM_SDC_FLAG_CTX , m_contextModels + m_numContextModels, m_numContextModels) 111 #endif 112 #if NH_3D_SDC_INTRA 113 , m_cSDCResidualFlagSCModel ( 1, 1, SDC_NUM_RESIDUAL_FLAG_CTX , m_contextModels + m_numContextModels, m_numContextModels) 114 , m_cSDCResidualSCModel ( 1, 1, SDC_NUM_RESIDUAL_CTX , m_contextModels + m_numContextModels, m_numContextModels) 115 , m_cDdcFlagSCModel ( 1, 1, NUM_DDC_FLAG_CTX , m_contextModels + m_numContextModels, m_numContextModels) 116 #endif 117 #if NH_3D_DBBP 118 , m_cDBBPFlagSCModel ( 1, 1, DBBP_NUM_FLAG_CTX , m_contextModels + m_numContextModels, m_numContextModels) 109 119 #endif 110 120 { … … 120 130 // ==================================================================================================================== 121 131 122 Void TEncSbac::resetEntropy () 123 { 124 Int iQp = m_pcSlice->getSliceQp(); 125 SliceType eSliceType = m_pcSlice->getSliceType(); 126 127 Int encCABACTableIdx = m_pcSlice->getPPS()->getEncCABACTableIdx(); 128 if (!m_pcSlice->isIntra() && (encCABACTableIdx==B_SLICE || encCABACTableIdx==P_SLICE) && m_pcSlice->getPPS()->getCabacInitPresentFlag()) 129 { 130 eSliceType = (SliceType) encCABACTableIdx; 131 } 132 133 m_cCUSplitFlagSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_SPLIT_FLAG ); 134 135 m_cCUSkipFlagSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_SKIP_FLAG ); 136 #if H_3D 137 m_cCUDISFlagSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_DIS_FLAG ); 138 m_cCUDISTypeSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_DIS_TYPE ); 139 #endif 140 m_cCUMergeFlagExtSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_MERGE_FLAG_EXT); 141 m_cCUMergeIdxExtSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_MERGE_IDX_EXT); 142 #if H_3D_ARP 143 m_cCUPUARPWSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_ARPW ); 144 #endif 145 #if H_3D_IC 146 m_cCUICFlagSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_IC_FLAG ); 147 #endif 148 m_cCUPartSizeSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_PART_SIZE ); 149 m_cCUPredModeSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_PRED_MODE ); 150 m_cCUIntraPredSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_INTRA_PRED_MODE ); 151 m_cCUChromaPredSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_CHROMA_PRED_MODE ); 152 m_cCUInterDirSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_INTER_DIR ); 153 m_cCUMvdSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_MVD ); 154 m_cCURefPicSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_REF_PIC ); 155 m_cCUDeltaQpSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_DQP ); 156 m_cCUQtCbfSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_QT_CBF ); 157 m_cCUQtRootCbfSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_QT_ROOT_CBF ); 158 m_cCUSigCoeffGroupSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_SIG_CG_FLAG ); 159 m_cCUSigSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_SIG_FLAG ); 160 m_cCuCtxLastX.initBuffer ( eSliceType, iQp, (UChar*)INIT_LAST ); 161 m_cCuCtxLastY.initBuffer ( eSliceType, iQp, (UChar*)INIT_LAST ); 162 m_cCUOneSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_ONE_FLAG ); 163 m_cCUAbsSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_ABS_FLAG ); 164 m_cMVPIdxSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_MVP_IDX ); 165 m_cCUTransSubdivFlagSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_TRANS_SUBDIV_FLAG ); 166 m_cSaoMergeSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_SAO_MERGE_FLAG ); 167 m_cSaoTypeIdxSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_SAO_TYPE_IDX ); 168 m_cTransformSkipSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_TRANSFORMSKIP_FLAG ); 169 m_CUTransquantBypassFlagSCModel.initBuffer( eSliceType, iQp, (UChar*)INIT_CU_TRANSQUANT_BYPASS_FLAG ); 170 171 #if H_3D_DIM 172 m_cDepthIntraModeSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_DEPTH_INTRA_MODE ); 173 m_cDdcFlagSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_DDC_FLAG ); 174 m_cDdcDataSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_DDC_DATA ); 175 m_cAngleFlagSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_ANGLE_FLAG ); 176 #if H_3D_DIM_SDC 177 m_cSDCResidualFlagSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_SDC_RESIDUAL_FLAG ); 178 m_cSDCResidualSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_SDC_RESIDUAL ); 179 #endif 180 #endif 181 #if H_3D_DIM_SDC 182 m_cSDCFlagSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_SDC_FLAG ); 183 #endif 184 #if H_3D_DBBP 185 m_cDBBPFlagSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_DBBP_FLAG ); 186 #endif 187 // new structure 188 m_uiLastQp = iQp; 189 132 Void TEncSbac::resetEntropy (const TComSlice *pSlice) 133 { 134 Int iQp = pSlice->getSliceQp(); 135 SliceType eSliceType = pSlice->getSliceType(); 136 137 SliceType encCABACTableIdx = pSlice->getEncCABACTableIdx(); 138 if (!pSlice->isIntra() && (encCABACTableIdx==B_SLICE || encCABACTableIdx==P_SLICE) && pSlice->getPPS()->getCabacInitPresentFlag()) 139 { 140 eSliceType = encCABACTableIdx; 141 } 142 143 m_cCUSplitFlagSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_SPLIT_FLAG ); 144 m_cCUSkipFlagSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_SKIP_FLAG ); 145 #if NH_3D_DIS 146 m_cCUDISFlagSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_DIS_FLAG ); 147 m_cCUDISTypeSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_DIS_TYPE ); 148 #endif 149 m_cCUMergeFlagExtSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_MERGE_FLAG_EXT); 150 m_cCUMergeIdxExtSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_MERGE_IDX_EXT); 151 #if NH_3D_ARP 152 m_cCUPUARPWSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_ARPW ); 153 #endif 154 #if NH_3D_IC 155 m_cCUICFlagSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_IC_FLAG ); 156 #endif 157 m_cCUPartSizeSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_PART_SIZE ); 158 m_cCUPredModeSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_PRED_MODE ); 159 m_cCUIntraPredSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_INTRA_PRED_MODE ); 160 m_cCUChromaPredSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_CHROMA_PRED_MODE ); 161 m_cCUInterDirSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_INTER_DIR ); 162 m_cCUMvdSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_MVD ); 163 m_cCURefPicSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_REF_PIC ); 164 m_cCUDeltaQpSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_DQP ); 165 m_cCUQtCbfSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_QT_CBF ); 166 m_cCUQtRootCbfSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_QT_ROOT_CBF ); 167 m_cCUSigCoeffGroupSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_SIG_CG_FLAG ); 168 m_cCUSigSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_SIG_FLAG ); 169 m_cCuCtxLastX.initBuffer ( eSliceType, iQp, (UChar*)INIT_LAST ); 170 m_cCuCtxLastY.initBuffer ( eSliceType, iQp, (UChar*)INIT_LAST ); 171 m_cCUOneSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_ONE_FLAG ); 172 m_cCUAbsSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_ABS_FLAG ); 173 m_cMVPIdxSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_MVP_IDX ); 174 m_cCUTransSubdivFlagSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_TRANS_SUBDIV_FLAG ); 175 m_cSaoMergeSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_SAO_MERGE_FLAG ); 176 m_cSaoTypeIdxSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_SAO_TYPE_IDX ); 177 m_cTransformSkipSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_TRANSFORMSKIP_FLAG ); 178 m_CUTransquantBypassFlagSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_CU_TRANSQUANT_BYPASS_FLAG ); 179 m_explicitRdpcmFlagSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_EXPLICIT_RDPCM_FLAG); 180 m_explicitRdpcmDirSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_EXPLICIT_RDPCM_DIR); 181 m_cCrossComponentPredictionSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_CROSS_COMPONENT_PREDICTION ); 182 m_ChromaQpAdjFlagSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_CHROMA_QP_ADJ_FLAG ); 183 m_ChromaQpAdjIdcSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_CHROMA_QP_ADJ_IDC ); 184 185 #if NH_3D_DMM 186 m_cNotDmmFlagSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_NOTDMM_FLAG ); 187 m_cDmmModeSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_DMM_MODE ); 188 #endif 189 #if NH_3D_DMM || NH_3D_SDC_INTRA || NH_3D_SDC_INTER 190 m_cDdcDataSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_DDC_DATA ); 191 m_cSDCFlagSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_SDC_FLAG ); 192 #endif 193 #if NH_3D_SDC_INTRA 194 m_cSDCResidualFlagSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_SDC_RESIDUAL_FLAG ); 195 m_cSDCResidualSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_SDC_RESIDUAL ); 196 m_cDdcFlagSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_DDC_FLAG ); 197 #endif 198 #if NH_3D_DBBP 199 m_cDBBPFlagSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_DBBP_FLAG ); 200 #endif 201 202 for (UInt statisticIndex = 0; statisticIndex < RExt__GOLOMB_RICE_ADAPTATION_STATISTICS_SETS ; statisticIndex++) 203 { 204 m_golombRiceAdaptationStatistics[statisticIndex] = 0; 205 } 206 190 207 m_pcBinIf->start(); 191 208 192 209 return; 193 210 } 194 211 195 /** The function does the following: 196 * If current slice type is P/B then it determines the distance of initialisation type 1 and 2 from the current CABAC states and 212 /** The function does the following: 213 * If current slice type is P/B then it determines the distance of initialisation type 1 and 2 from the current CABAC states and 197 214 * stores the index of the closest table. This index is used for the next P/B slice when cabac_init_present_flag is true. 198 215 */ 199 Void TEncSbac::determineCabacInitIdx()200 { 201 Int qp = m_pcSlice->getSliceQp();202 203 if (! m_pcSlice->isIntra())216 SliceType TEncSbac::determineCabacInitIdx(const TComSlice *pSlice) 217 { 218 Int qp = pSlice->getSliceQp(); 219 220 if (!pSlice->isIntra()) 204 221 { 205 222 SliceType aSliceTypeChoices[] = {B_SLICE, P_SLICE}; … … 212 229 SliceType curSliceType = aSliceTypeChoices[idx]; 213 230 214 curCost = m_cCUSplitFlagSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_SPLIT_FLAG ); 215 curCost += m_cCUSkipFlagSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_SKIP_FLAG ); 216 #if H_3D 217 curCost += m_cCUDISFlagSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_DIS_FLAG ); 218 curCost += m_cCUDISTypeSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_DIS_TYPE ); 219 #endif 220 curCost += m_cCUMergeFlagExtSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_MERGE_FLAG_EXT); 221 curCost += m_cCUMergeIdxExtSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_MERGE_IDX_EXT); 222 #if H_3D_ARP 223 curCost += m_cCUPUARPWSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_ARPW ); 224 #endif 225 #if H_3D_IC 226 curCost += m_cCUICFlagSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_IC_FLAG ); 227 #endif 228 #if H_3D_DIM_SDC 229 curCost += m_cSDCFlagSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_SDC_FLAG ); 230 #endif 231 #if H_3D_DBBP 232 curCost += m_cDBBPFlagSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_DBBP_FLAG ); 233 #endif 234 curCost += m_cCUPartSizeSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_PART_SIZE ); 235 curCost += m_cCUPredModeSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_PRED_MODE ); 236 curCost += m_cCUIntraPredSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_INTRA_PRED_MODE ); 237 curCost += m_cCUChromaPredSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_CHROMA_PRED_MODE ); 238 curCost += m_cCUInterDirSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_INTER_DIR ); 239 curCost += m_cCUMvdSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_MVD ); 240 curCost += m_cCURefPicSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_REF_PIC ); 241 curCost += m_cCUDeltaQpSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_DQP ); 242 curCost += m_cCUQtCbfSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_QT_CBF ); 243 curCost += m_cCUQtRootCbfSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_QT_ROOT_CBF ); 244 curCost += m_cCUSigCoeffGroupSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_SIG_CG_FLAG ); 245 curCost += m_cCUSigSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_SIG_FLAG ); 246 curCost += m_cCuCtxLastX.calcCost ( curSliceType, qp, (UChar*)INIT_LAST ); 247 curCost += m_cCuCtxLastY.calcCost ( curSliceType, qp, (UChar*)INIT_LAST ); 248 curCost += m_cCUOneSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_ONE_FLAG ); 249 curCost += m_cCUAbsSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_ABS_FLAG ); 250 curCost += m_cMVPIdxSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_MVP_IDX ); 251 curCost += m_cCUTransSubdivFlagSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_TRANS_SUBDIV_FLAG ); 252 curCost += m_cSaoMergeSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_SAO_MERGE_FLAG ); 253 curCost += m_cSaoTypeIdxSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_SAO_TYPE_IDX ); 254 curCost += m_cTransformSkipSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_TRANSFORMSKIP_FLAG ); 255 curCost += m_CUTransquantBypassFlagSCModel.calcCost( curSliceType, qp, (UChar*)INIT_CU_TRANSQUANT_BYPASS_FLAG ); 256 #if H_3D_DIM 257 if( m_pcSlice->getIntraSdcWedgeFlag() || m_pcSlice->getIntraContourFlag() ) 258 { 259 curCost += m_cDepthIntraModeSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_DEPTH_INTRA_MODE ); 260 curCost += m_cDdcFlagSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_DDC_FLAG ); 261 curCost += m_cDdcDataSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_DDC_DATA ); 262 curCost += m_cAngleFlagSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_ANGLE_FLAG ); 263 } 264 #endif 231 curCost = m_cCUSplitFlagSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_SPLIT_FLAG ); 232 curCost += m_cCUSkipFlagSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_SKIP_FLAG ); 233 #if NH_3D_DIS 234 curCost += m_cCUDISFlagSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_DIS_FLAG ); 235 curCost += m_cCUDISTypeSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_DIS_TYPE ); 236 #endif 237 curCost += m_cCUMergeFlagExtSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_MERGE_FLAG_EXT); 238 curCost += m_cCUMergeIdxExtSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_MERGE_IDX_EXT); 239 #if NH_3D_ARP 240 curCost += m_cCUPUARPWSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_ARPW ); 241 #endif 242 #if NH_3D_IC 243 curCost += m_cCUICFlagSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_IC_FLAG ); 244 #endif 245 #if NH_3D_SDC_INTRA || NH_3D_SDC_INTER 246 curCost += m_cSDCFlagSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_SDC_FLAG ); 247 #endif 248 #if NH_3D_DBBP 249 curCost += m_cDBBPFlagSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_DBBP_FLAG ); 250 #endif 251 curCost += m_cCUPartSizeSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_PART_SIZE ); 252 curCost += m_cCUPredModeSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_PRED_MODE ); 253 curCost += m_cCUIntraPredSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_INTRA_PRED_MODE ); 254 curCost += m_cCUChromaPredSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_CHROMA_PRED_MODE ); 255 curCost += m_cCUInterDirSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_INTER_DIR ); 256 curCost += m_cCUMvdSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_MVD ); 257 curCost += m_cCURefPicSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_REF_PIC ); 258 curCost += m_cCUDeltaQpSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_DQP ); 259 curCost += m_cCUQtCbfSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_QT_CBF ); 260 curCost += m_cCUQtRootCbfSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_QT_ROOT_CBF ); 261 curCost += m_cCUSigCoeffGroupSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_SIG_CG_FLAG ); 262 curCost += m_cCUSigSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_SIG_FLAG ); 263 curCost += m_cCuCtxLastX.calcCost ( curSliceType, qp, (UChar*)INIT_LAST ); 264 curCost += m_cCuCtxLastY.calcCost ( curSliceType, qp, (UChar*)INIT_LAST ); 265 curCost += m_cCUOneSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_ONE_FLAG ); 266 curCost += m_cCUAbsSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_ABS_FLAG ); 267 curCost += m_cMVPIdxSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_MVP_IDX ); 268 curCost += m_cCUTransSubdivFlagSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_TRANS_SUBDIV_FLAG ); 269 curCost += m_cSaoMergeSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_SAO_MERGE_FLAG ); 270 curCost += m_cSaoTypeIdxSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_SAO_TYPE_IDX ); 271 curCost += m_cTransformSkipSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_TRANSFORMSKIP_FLAG ); 272 curCost += m_CUTransquantBypassFlagSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_CU_TRANSQUANT_BYPASS_FLAG ); 273 curCost += m_explicitRdpcmFlagSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_EXPLICIT_RDPCM_FLAG); 274 curCost += m_explicitRdpcmDirSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_EXPLICIT_RDPCM_DIR); 275 curCost += m_cCrossComponentPredictionSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_CROSS_COMPONENT_PREDICTION ); 276 curCost += m_ChromaQpAdjFlagSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_CHROMA_QP_ADJ_FLAG ); 277 curCost += m_ChromaQpAdjIdcSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_CHROMA_QP_ADJ_IDC ); 278 #if NH_3D_DMM 279 curCost += m_cNotDmmFlagSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_NOTDMM_FLAG ); 280 curCost += m_cDmmModeSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_DMM_MODE ); 281 #endif 282 #if NH_3D_DMM || NH_3D_SDC_INTRA || NH_3D_SDC_INTER 283 curCost += m_cDdcDataSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_DDC_DATA ); 284 #endif 285 265 286 if (curCost < bestCost) 266 287 { … … 269 290 } 270 291 } 271 m_pcSlice->getPPS()->setEncCABACTableIdx( bestSliceType );292 return bestSliceType; 272 293 } 273 294 else 274 295 { 275 m_pcSlice->getPPS()->setEncCABACTableIdx( I_SLICE ); 276 } 277 } 278 279 280 /** The function does the followng: Write out terminate bit. Flush CABAC. Intialize CABAC states. Start CABAC. 281 */ 282 Void TEncSbac::updateContextTables( SliceType eSliceType, Int iQp, Bool bExecuteFinish ) 283 { 284 m_pcBinIf->encodeBinTrm(1); 285 if (bExecuteFinish) m_pcBinIf->finish(); 286 m_cCUSplitFlagSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_SPLIT_FLAG ); 287 288 m_cCUSkipFlagSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_SKIP_FLAG ); 289 #if H_3D 290 m_cCUDISFlagSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_DIS_FLAG ); 291 m_cCUDISTypeSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_DIS_TYPE ); 292 #endif 293 m_cCUMergeFlagExtSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_MERGE_FLAG_EXT); 294 m_cCUMergeIdxExtSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_MERGE_IDX_EXT); 295 #if H_3D_ARP 296 m_cCUPUARPWSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_ARPW ); 297 #endif 298 #if H_3D_IC 299 m_cCUICFlagSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_IC_FLAG ); 300 #endif 301 m_cCUPartSizeSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_PART_SIZE ); 302 m_cCUPredModeSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_PRED_MODE ); 303 m_cCUIntraPredSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_INTRA_PRED_MODE ); 304 m_cCUChromaPredSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_CHROMA_PRED_MODE ); 305 m_cCUInterDirSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_INTER_DIR ); 306 m_cCUMvdSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_MVD ); 307 m_cCURefPicSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_REF_PIC ); 308 m_cCUDeltaQpSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_DQP ); 309 m_cCUQtCbfSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_QT_CBF ); 310 m_cCUQtRootCbfSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_QT_ROOT_CBF ); 311 m_cCUSigCoeffGroupSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_SIG_CG_FLAG ); 312 m_cCUSigSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_SIG_FLAG ); 313 m_cCuCtxLastX.initBuffer ( eSliceType, iQp, (UChar*)INIT_LAST ); 314 m_cCuCtxLastY.initBuffer ( eSliceType, iQp, (UChar*)INIT_LAST ); 315 m_cCUOneSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_ONE_FLAG ); 316 m_cCUAbsSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_ABS_FLAG ); 317 m_cMVPIdxSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_MVP_IDX ); 318 m_cCUTransSubdivFlagSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_TRANS_SUBDIV_FLAG ); 319 m_cSaoMergeSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_SAO_MERGE_FLAG ); 320 m_cSaoTypeIdxSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_SAO_TYPE_IDX ); 321 m_cTransformSkipSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_TRANSFORMSKIP_FLAG ); 322 m_CUTransquantBypassFlagSCModel.initBuffer( eSliceType, iQp, (UChar*)INIT_CU_TRANSQUANT_BYPASS_FLAG ); 323 #if H_3D_DIM 324 m_cDepthIntraModeSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_DEPTH_INTRA_MODE ); 325 m_cDdcFlagSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_DDC_FLAG ); 326 m_cDdcDataSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_DDC_DATA ); 327 m_cAngleFlagSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_ANGLE_FLAG ); 328 #if H_3D_DIM_SDC 329 m_cSDCResidualFlagSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_SDC_RESIDUAL_FLAG ); 330 m_cSDCResidualSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_SDC_RESIDUAL ); 331 #endif 332 #endif 333 #if H_3D_DIM_SDC 334 m_cSDCFlagSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_SDC_FLAG ); 335 #endif 336 #if H_3D_DBBP 337 m_cDBBPFlagSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_DBBP_FLAG ); 338 #endif 339 m_pcBinIf->start(); 340 } 341 342 Void TEncSbac::codeVPS( TComVPS* pcVPS ) 296 return I_SLICE; 297 } 298 } 299 300 301 Void TEncSbac::codeVPS( const TComVPS* /*pcVPS*/ ) 343 302 { 344 303 assert (0); … … 346 305 } 347 306 348 Void TEncSbac::codeSPS( TComSPS* pcSPS)307 Void TEncSbac::codeSPS( const TComSPS* /*pcSPS*/ ) 349 308 { 350 309 assert (0); … … 352 311 } 353 312 354 Void TEncSbac::codePPS( TComPPS* pcPPS)313 Void TEncSbac::codePPS( const TComPPS* /*pcPPS*/ ) 355 314 { 356 315 assert (0); … … 358 317 } 359 318 360 Void TEncSbac::codeSliceHeader( TComSlice* pcSlice)319 Void TEncSbac::codeSliceHeader( TComSlice* /*pcSlice*/ ) 361 320 { 362 321 assert (0); … … 364 323 } 365 324 366 Void TEncSbac::codeTilesWPPEntryPoint( TComSlice* pSlice)325 Void TEncSbac::codeTilesWPPEntryPoint( TComSlice* /*pSlice*/ ) 367 326 { 368 327 assert (0); … … 383 342 { 384 343 m_pcBinIf->encodeBin( uiSymbol ? 1 : 0, pcSCModel[0] ); 385 344 386 345 if( 0 == uiSymbol) 387 346 { 388 347 return; 389 348 } 390 349 391 350 while( uiSymbol-- ) 392 351 { 393 352 m_pcBinIf->encodeBin( uiSymbol ? 1 : 0, pcSCModel[ iOffset ] ); 394 353 } 395 354 396 355 return; 397 356 } … … 403 362 return; 404 363 } 405 364 406 365 m_pcBinIf->encodeBin( uiSymbol ? 1 : 0, pcSCModel[ 0 ] ); 407 366 408 367 if ( uiSymbol == 0 ) 409 368 { 410 369 return; 411 370 } 412 371 413 372 Bool bCodeLast = ( uiMaxSymbol > uiSymbol ); 414 373 415 374 while( --uiSymbol ) 416 375 { … … 421 380 m_pcBinIf->encodeBin( 0, pcSCModel[ iOffset ] ); 422 381 } 423 382 424 383 return; 425 384 } … … 429 388 UInt bins = 0; 430 389 Int numBins = 0; 431 390 432 391 while( uiSymbol >= (UInt)(1<<uiCount) ) 433 392 { … … 439 398 bins = 2 * bins + 0; 440 399 numBins++; 441 400 442 401 bins = (bins << uiCount) | uiSymbol; 443 402 numBins += uiCount; 444 403 445 404 assert( numBins <= 32 ); 446 405 m_pcBinIf->encodeBinsEP( bins, numBins ); 447 406 } 448 #if H_3D 407 408 #if NH_3D_DIS 449 409 Void TEncSbac::codeDIS( TComDataCU* pcCU, UInt uiAbsPartIdx ) 450 410 { … … 478 438 } 479 439 #endif 440 441 480 442 /** Coding of coeff_abs_level_minus3 481 * \param uiSymbol value of coeff_abs_level_minus3 482 * \param ruiGoRiceParam reference to Rice parameter 483 * \returns Void 443 * \param symbol value of coeff_abs_level_minus3 444 * \param rParam reference to Rice parameter 445 * \param useLimitedPrefixLength 446 * \param maxLog2TrDynamicRange 484 447 */ 485 Void TEncSbac::xWriteCoefRemainExGolomb ( UInt symbol, UInt &rParam )448 Void TEncSbac::xWriteCoefRemainExGolomb ( UInt symbol, UInt &rParam, const Bool useLimitedPrefixLength, const Int maxLog2TrDynamicRange ) 486 449 { 487 450 Int codeNumber = (Int)symbol; 488 451 UInt length; 452 489 453 if (codeNumber < (COEF_REMAIN_BIN_REDUCTION << rParam)) 490 454 { … … 493 457 m_pcBinIf->encodeBinsEP((codeNumber%(1<<rParam)),rParam); 494 458 } 459 else if (useLimitedPrefixLength) 460 { 461 const UInt maximumPrefixLength = (32 - (COEF_REMAIN_BIN_REDUCTION + maxLog2TrDynamicRange)); 462 463 UInt prefixLength = 0; 464 UInt suffixLength = MAX_UINT; 465 UInt codeValue = (symbol >> rParam) - COEF_REMAIN_BIN_REDUCTION; 466 467 if (codeValue >= ((1 << maximumPrefixLength) - 1)) 468 { 469 prefixLength = maximumPrefixLength; 470 suffixLength = maxLog2TrDynamicRange - rParam; 471 } 472 else 473 { 474 while (codeValue > ((2 << prefixLength) - 2)) 475 { 476 prefixLength++; 477 } 478 479 suffixLength = prefixLength + 1; //+1 for the separator bit 480 } 481 482 const UInt suffix = codeValue - ((1 << prefixLength) - 1); 483 484 const UInt totalPrefixLength = prefixLength + COEF_REMAIN_BIN_REDUCTION; 485 const UInt prefix = (1 << totalPrefixLength) - 1; 486 const UInt rParamBitMask = (1 << rParam) - 1; 487 488 m_pcBinIf->encodeBinsEP( prefix, totalPrefixLength ); //prefix 489 m_pcBinIf->encodeBinsEP(((suffix << rParam) | (symbol & rParamBitMask)), (suffixLength + rParam)); //separator, suffix, and rParam bits 490 } 495 491 else 496 492 { 497 493 length = rParam; 498 494 codeNumber = codeNumber - ( COEF_REMAIN_BIN_REDUCTION << rParam); 495 499 496 while (codeNumber >= (1<<length)) 500 497 { 501 codeNumber -= (1<<(length++)); 502 } 498 codeNumber -= (1<<(length++)); 499 } 500 503 501 m_pcBinIf->encodeBinsEP((1<<(COEF_REMAIN_BIN_REDUCTION+length+1-rParam))-2,COEF_REMAIN_BIN_REDUCTION+length+1-rParam); 504 502 m_pcBinIf->encodeBinsEP(codeNumber,length); 505 503 } 506 504 } 507 508 #if H_3D_DIM 509 Void TEncSbac::xWriteExGolombLevel( UInt uiSymbol, ContextModel& rcSCModel ) 510 { 511 if( uiSymbol ) 512 { 513 m_pcBinIf->encodeBin( 1, rcSCModel ); 514 UInt uiCount = 0; 515 Bool bNoExGo = ( uiSymbol < 3 ); 516 517 while( --uiSymbol && ++uiCount < 3 ) 518 { 519 m_pcBinIf->encodeBin( 1, rcSCModel ); 520 } 521 if( bNoExGo ) 522 { 523 m_pcBinIf->encodeBin( 0, rcSCModel ); 524 } 525 else 526 { 527 xWriteEpExGolomb( uiSymbol, 0 ); 528 } 505 // SBAC RD 506 Void TEncSbac::load ( const TEncSbac* pSrc) 507 { 508 this->xCopyFrom(pSrc); 509 } 510 511 Void TEncSbac::loadIntraDirMode( const TEncSbac* pSrc, const ChannelType chType ) 512 { 513 m_pcBinIf->copyState( pSrc->m_pcBinIf ); 514 if (isLuma(chType)) 515 { 516 this->m_cCUIntraPredSCModel .copyFrom( &pSrc->m_cCUIntraPredSCModel ); 529 517 } 530 518 else 531 519 { 532 m_pcBinIf->encodeBin( 0, rcSCModel ); 533 } 534 535 return; 536 } 537 538 Void TEncSbac::xCodeDimDeltaDC( Pel valDeltaDC, UInt uiNumSeg ) 539 { 540 xWriteExGolombLevel( UInt( abs( valDeltaDC ) - ( uiNumSeg > 1 ? 0 : 1 ) ), m_cDdcDataSCModel.get(0, 0, 0) ); 541 if( valDeltaDC != 0 ) 542 { 543 UInt uiSign = valDeltaDC > 0 ? 0 : 1; 544 m_pcBinIf->encodeBinEP( uiSign ); 545 } 546 } 547 548 #if H_3D_DIM_DMM 549 Void TEncSbac::xCodeDmm1WedgeIdx( UInt uiTabIdx, Int iNumBit ) 550 { 551 for ( Int i = 0; i < iNumBit; i++ ) 552 { 553 m_pcBinIf->encodeBinEP( ( uiTabIdx >> i ) & 1 ); 554 } 555 } 556 557 #endif 558 #endif 559 560 561 // SBAC RD 562 Void TEncSbac::load ( TEncSbac* pSrc) 563 { 564 this->xCopyFrom(pSrc); 565 } 566 567 Void TEncSbac::loadIntraDirModeLuma( TEncSbac* pSrc) 520 this->m_cCUChromaPredSCModel .copyFrom( &pSrc->m_cCUChromaPredSCModel ); 521 } 522 } 523 524 #if NH_3D_DMM 525 Void TEncSbac::loadIntraDepthDmm( const TEncSbac* pSrc ) 568 526 { 569 527 m_pcBinIf->copyState( pSrc->m_pcBinIf ); 570 571 this->m_cCUIntraPredSCModel .copyFrom( &pSrc->m_cCUIntraPredSCModel ); 572 } 573 #if H_3D_DIM 574 Void TEncSbac::loadIntraDepthMode( TEncSbac* pSrc) 528 this->m_cNotDmmFlagSCModel.copyFrom( &pSrc->m_cNotDmmFlagSCModel ); 529 this->m_cDmmModeSCModel .copyFrom( &pSrc->m_cDmmModeSCModel ); 530 } 531 #endif 532 533 534 Void TEncSbac::store( TEncSbac* pDest) const 535 { 536 pDest->xCopyFrom( this ); 537 } 538 539 540 Void TEncSbac::xCopyFrom( const TEncSbac* pSrc ) 575 541 { 576 542 m_pcBinIf->copyState( pSrc->m_pcBinIf ); 577 578 this->m_cDepthIntraModeSCModel .copyFrom( &pSrc->m_cDepthIntraModeSCModel ); 579 this->m_cDdcFlagSCModel .copyFrom( &pSrc->m_cDdcFlagSCModel ); 580 this->m_cAngleFlagSCModel .copyFrom( &pSrc->m_cAngleFlagSCModel ); 581 } 582 #endif 583 584 Void TEncSbac::store( TEncSbac* pDest) 585 { 586 pDest->xCopyFrom( this ); 587 } 588 589 590 Void TEncSbac::xCopyFrom( TEncSbac* pSrc ) 591 { 592 m_pcBinIf->copyState( pSrc->m_pcBinIf ); 593 594 this->m_uiCoeffCost = pSrc->m_uiCoeffCost; 595 this->m_uiLastQp = pSrc->m_uiLastQp; 596 597 memcpy( m_contextModels, pSrc->m_contextModels, m_numContextModels * sizeof( ContextModel ) ); 543 xCopyContextsFrom(pSrc); 598 544 } 599 545 … … 621 567 { 622 568 PartSize eSize = pcCU->getPartitionSize( uiAbsPartIdx ); 623 #if H_3D_QTLPC569 #if NH_3D_QTLPC 624 570 Bool bLimQtPredFlag = pcCU->getPic()->getSlice(0)->getQtPredFlag(); 625 571 TComPic *pcTexture = pcCU->getSlice()->getTexturePic(); … … 638 584 #endif 639 585 { 640 TComDataCU *pcTextureCU = pcTexture->getC U(pcCU->getAddr());641 UInt uiCUIdx = (pcCU->getZorderIdxInC U() == 0) ? uiAbsPartIdx : pcCU->getZorderIdxInCU();586 TComDataCU *pcTextureCU = pcTexture->getCtu(pcCU->getCtuRsAddr()); 587 UInt uiCUIdx = (pcCU->getZorderIdxInCtu() == 0) ? uiAbsPartIdx : pcCU->getZorderIdxInCtu(); 642 588 assert(pcTextureCU->getDepth(uiCUIdx) >= uiDepth); 643 589 if(pcTextureCU->getDepth(uiCUIdx) == uiDepth ) … … 653 599 } 654 600 #endif 601 const UInt log2DiffMaxMinCodingBlockSize = pcCU->getSlice()->getSPS()->getLog2DiffMaxMinCodingBlockSize(); 602 655 603 if ( pcCU->isIntra( uiAbsPartIdx ) ) 656 604 { 657 if( uiDepth == g_uiMaxCUDepth - g_uiAddCUDepth)605 if( uiDepth == log2DiffMaxMinCodingBlockSize ) 658 606 { 659 607 m_pcBinIf->encodeBin( eSize == SIZE_2Nx2N? 1 : 0, m_cCUPartSizeSCModel.get( 0, 0, 0 ) ); … … 661 609 DTRACE_CU("part_mode", eSize == SIZE_2Nx2N? 1 : 0) 662 610 #endif 611 663 612 } 664 613 return; 665 614 } 666 667 615 #if H_MV_ENC_DEC_TRAC 668 616 DTRACE_CU("part_mode", eSize ) 669 617 #endif 670 #if H_3D_QTLPC618 #if NH_3D_QTLPC 671 619 if (depthDependent==false || uiTexturePart == SIZE_NxN|| uiTexturePart == SIZE_2Nx2N) 672 620 { 673 621 #endif 674 switch(eSize) 675 { 676 case SIZE_2Nx2N: 622 623 switch(eSize) 624 { 625 case SIZE_2Nx2N: 626 { 627 m_pcBinIf->encodeBin( 1, m_cCUPartSizeSCModel.get( 0, 0, 0) ); 628 break; 629 } 630 case SIZE_2NxN: 631 case SIZE_2NxnU: 632 case SIZE_2NxnD: 633 { 634 m_pcBinIf->encodeBin( 0, m_cCUPartSizeSCModel.get( 0, 0, 0) ); 635 m_pcBinIf->encodeBin( 1, m_cCUPartSizeSCModel.get( 0, 0, 1) ); 636 if ( pcCU->getSlice()->getSPS()->getUseAMP() && uiDepth < log2DiffMaxMinCodingBlockSize ) 637 { 638 if (eSize == SIZE_2NxN) 677 639 { 678 m_pcBinIf->encodeBin( 1, m_cCUPartSizeSCModel.get( 0, 0, 0) ); 679 break; 640 m_pcBinIf->encodeBin(1, m_cCUPartSizeSCModel.get( 0, 0, 3 )); 680 641 } 681 case SIZE_2NxN: 682 case SIZE_2NxnU: 683 case SIZE_2NxnD: 642 else 684 643 { 685 m_pcBinIf->encodeBin( 0, m_cCUPartSizeSCModel.get( 0, 0, 0) ); 686 m_pcBinIf->encodeBin( 1, m_cCUPartSizeSCModel.get( 0, 0, 1) ); 687 if ( pcCU->getSlice()->getSPS()->getAMPAcc( uiDepth ) ) 688 { 689 if (eSize == SIZE_2NxN) 690 { 691 m_pcBinIf->encodeBin(1, m_cCUPartSizeSCModel.get( 0, 0, 3 )); 692 } 693 else 694 { 695 m_pcBinIf->encodeBin(0, m_cCUPartSizeSCModel.get( 0, 0, 3 )); 696 m_pcBinIf->encodeBinEP((eSize == SIZE_2NxnU? 0: 1)); 697 } 698 } 699 break; 644 m_pcBinIf->encodeBin(0, m_cCUPartSizeSCModel.get( 0, 0, 3 )); 645 m_pcBinIf->encodeBinEP((eSize == SIZE_2NxnU? 0: 1)); 700 646 } 701 case SIZE_Nx2N: 702 case SIZE_nLx2N: 703 case SIZE_nRx2N: 647 } 648 break; 649 } 650 case SIZE_Nx2N: 651 case SIZE_nLx2N: 652 case SIZE_nRx2N: 653 { 654 m_pcBinIf->encodeBin( 0, m_cCUPartSizeSCModel.get( 0, 0, 0) ); 655 m_pcBinIf->encodeBin( 0, m_cCUPartSizeSCModel.get( 0, 0, 1) ); 656 657 if( uiDepth == log2DiffMaxMinCodingBlockSize && !( pcCU->getWidth(uiAbsPartIdx) == 8 && pcCU->getHeight(uiAbsPartIdx) == 8 ) ) 658 { 659 m_pcBinIf->encodeBin( 1, m_cCUPartSizeSCModel.get( 0, 0, 2) ); 660 } 661 662 if ( pcCU->getSlice()->getSPS()->getUseAMP() && uiDepth < log2DiffMaxMinCodingBlockSize ) 663 { 664 if (eSize == SIZE_Nx2N) 704 665 { 705 m_pcBinIf->encodeBin( 0, m_cCUPartSizeSCModel.get( 0, 0, 0) ); 706 m_pcBinIf->encodeBin( 0, m_cCUPartSizeSCModel.get( 0, 0, 1) ); 707 if( uiDepth == g_uiMaxCUDepth - g_uiAddCUDepth && !( pcCU->getWidth(uiAbsPartIdx) == 8 && pcCU->getHeight(uiAbsPartIdx) == 8 ) ) 708 { 709 m_pcBinIf->encodeBin( 1, m_cCUPartSizeSCModel.get( 0, 0, 2) ); 710 } 711 if ( pcCU->getSlice()->getSPS()->getAMPAcc( uiDepth ) ) 712 { 713 if (eSize == SIZE_Nx2N) 714 { 715 m_pcBinIf->encodeBin(1, m_cCUPartSizeSCModel.get( 0, 0, 3 )); 716 } 717 else 718 { 719 m_pcBinIf->encodeBin(0, m_cCUPartSizeSCModel.get( 0, 0, 3 )); 720 m_pcBinIf->encodeBinEP((eSize == SIZE_nLx2N? 0: 1)); 721 } 722 } 723 break; 666 m_pcBinIf->encodeBin(1, m_cCUPartSizeSCModel.get( 0, 0, 3 )); 724 667 } 725 case SIZE_NxN:668 else 726 669 { 727 if( uiDepth == g_uiMaxCUDepth - g_uiAddCUDepth && !( pcCU->getWidth(uiAbsPartIdx) == 8 && pcCU->getHeight(uiAbsPartIdx) == 8 ) ) 728 { 729 m_pcBinIf->encodeBin( 0, m_cCUPartSizeSCModel.get( 0, 0, 0) ); 730 m_pcBinIf->encodeBin( 0, m_cCUPartSizeSCModel.get( 0, 0, 1) ); 731 m_pcBinIf->encodeBin( 0, m_cCUPartSizeSCModel.get( 0, 0, 2) ); 732 } 733 break; 670 m_pcBinIf->encodeBin(0, m_cCUPartSizeSCModel.get( 0, 0, 3 )); 671 m_pcBinIf->encodeBinEP((eSize == SIZE_nLx2N? 0: 1)); 734 672 } 735 default: 736 { 737 assert(0); 738 } 739 } 740 #if H_3D_QTLPC 673 } 674 break; 675 } 676 case SIZE_NxN: 677 { 678 if( uiDepth == log2DiffMaxMinCodingBlockSize && !( pcCU->getWidth(uiAbsPartIdx) == 8 && pcCU->getHeight(uiAbsPartIdx) == 8 ) ) 679 { 680 m_pcBinIf->encodeBin( 0, m_cCUPartSizeSCModel.get( 0, 0, 0) ); 681 m_pcBinIf->encodeBin( 0, m_cCUPartSizeSCModel.get( 0, 0, 1) ); 682 m_pcBinIf->encodeBin( 0, m_cCUPartSizeSCModel.get( 0, 0, 2) ); 683 } 684 break; 685 } 686 default: 687 { 688 assert(0); 689 break; 690 } 691 } 692 #if NH_3D_QTLPC 741 693 } 742 694 else if(uiTexturePart == SIZE_2NxN || uiTexturePart == SIZE_2NxnU || uiTexturePart == SIZE_2NxnD) … … 755 707 { 756 708 m_pcBinIf->encodeBin( 0, m_cCUPartSizeSCModel.get( 0, 0, 0) ); 757 if ( pcCU->getSlice()->getSPS()->getAMPAcc( uiDepth ))709 if ( pcCU->getSlice()->getSPS()->getUseAMP() && uiDepth < log2DiffMaxMinCodingBlockSize ) 758 710 { 759 711 m_pcBinIf->encodeBin( 1, m_cCUPartSizeSCModel.get( 0, 0, 1) ); … … 790 742 { 791 743 m_pcBinIf->encodeBin( 0, m_cCUPartSizeSCModel.get( 0, 0, 0) ); 792 if ( pcCU->getSlice()->getSPS()->get AMPAcc( uiDepth ))744 if ( pcCU->getSlice()->getSPS()->getUseAMP() && uiDepth < log2DiffMaxMinCodingBlockSize ) 793 745 { 794 746 m_pcBinIf->encodeBin( 1, m_cCUPartSizeSCModel.get( 0, 0, 1) ); … … 816 768 } 817 769 #endif 818 } 770 771 } 772 819 773 820 774 /** code prediction mode 821 775 * \param pcCU 822 * \param uiAbsPartIdx 776 * \param uiAbsPartIdx 823 777 * \returns Void 824 778 */ 825 779 Void TEncSbac::codePredMode( TComDataCU* pcCU, UInt uiAbsPartIdx ) 826 780 { 827 #if H_3D_DIM_SDC828 if ( pcCU->getSlice()->isIntra() )829 {830 assert( pcCU->isIntra(uiAbsPartIdx) );831 return;832 }833 #endif834 835 781 // get context function is here 836 Int iPredMode = pcCU->getPredictionMode( uiAbsPartIdx ); 837 m_pcBinIf->encodeBin( iPredMode == MODE_INTER ? 0 : 1, m_cCUPredModeSCModel.get( 0, 0, 0 ) ); 782 m_pcBinIf->encodeBin( pcCU->isIntra( uiAbsPartIdx ) ? 1 : 0, m_cCUPredModeSCModel.get( 0, 0, 0 ) ); 838 783 #if H_MV_ENC_DEC_TRAC 839 DTRACE_CU("pred_mode_flag", iPredMode == MODE_INTER ? 0 : 1); 840 #endif 784 DTRACE_CU("pred_mode_flag", pcCU->isIntra( uiAbsPartIdx ) ? 1 : 0); 785 #endif 786 841 787 } 842 788 … … 848 794 DTRACE_CU("cu_transquant_bypass_flag", uiSymbol); 849 795 #endif 796 850 797 } 851 798 852 799 /** code skip flag 853 800 * \param pcCU 854 * \param uiAbsPartIdx 801 * \param uiAbsPartIdx 855 802 * \returns Void 856 803 */ … … 876 823 /** code merge flag 877 824 * \param pcCU 878 * \param uiAbsPartIdx 825 * \param uiAbsPartIdx 879 826 * \returns Void 880 827 */ … … 891 838 DTRACE_CABAC_V( uiSymbol ); 892 839 DTRACE_CABAC_T( "\tAddress: " ); 893 DTRACE_CABAC_V( pcCU->get Addr() );840 DTRACE_CABAC_V( pcCU->getCtuRsAddr() ); 894 841 DTRACE_CABAC_T( "\tuiAbsPartIdx: " ); 895 842 DTRACE_CABAC_V( uiAbsPartIdx ); … … 900 847 /** code merge index 901 848 * \param pcCU 902 * \param uiAbsPartIdx 849 * \param uiAbsPartIdx 903 850 * \returns Void 904 851 */ … … 938 885 } 939 886 940 #if H_3D_ARP887 #if NH_3D_ARP 941 888 Void TEncSbac::codeARPW( TComDataCU* pcCU, UInt uiAbsPartIdx ) 942 889 { … … 958 905 #endif 959 906 960 #if H_3D_IC907 #if NH_3D_IC 961 908 /** code Illumination Compensation flag 962 909 * \param pcCU … … 984 931 Void TEncSbac::codeSplitFlag ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth ) 985 932 { 986 if( uiDepth == g_uiMaxCUDepth - g_uiAddCUDepth ) 933 if( uiDepth == pcCU->getSlice()->getSPS()->getLog2DiffMaxMinCodingBlockSize() ) 934 { 987 935 return; 988 936 } 937 989 938 UInt uiCtx = pcCU->getCtxSplitFlag( uiAbsPartIdx, uiDepth ); 990 939 UInt uiCurrSplitFlag = ( pcCU->getDepth( uiAbsPartIdx ) > uiDepth ) ? 1 : 0; 991 940 992 941 assert( uiCtx < 3 ); 993 #if H_3D_QTLPC942 #if NH_3D_QTLPC 994 943 Bool bCodeSplitFlag = true; 995 944 … … 1008 957 #endif 1009 958 { 1010 TComDataCU *pcTextureCU = pcTexture->getC U(pcCU->getAddr());1011 UInt uiCUIdx = (pcCU->getZorderIdxInC U() == 0) ? uiAbsPartIdx : pcCU->getZorderIdxInCU();959 TComDataCU *pcTextureCU = pcTexture->getCtu(pcCU->getCtuRsAddr()); 960 UInt uiCUIdx = (pcCU->getZorderIdxInCtu() == 0) ? uiAbsPartIdx : pcCU->getZorderIdxInCtu(); 1012 961 assert(pcTextureCU->getDepth(uiCUIdx) >= uiDepth); 1013 962 bCodeSplitFlag = (pcTextureCU->getDepth(uiCUIdx) > uiDepth); … … 1020 969 } 1021 970 #endif 971 1022 972 m_pcBinIf->encodeBin( uiCurrSplitFlag, m_cCUSplitFlagSCModel.get( 0, 0, uiCtx ) ); 1023 973 #if !H_MV_ENC_DEC_TRAC … … 1047 997 } 1048 998 999 1049 1000 Void TEncSbac::codeIntraDirLumaAng( TComDataCU* pcCU, UInt absPartIdx, Bool isMultiple) 1050 1001 { 1051 1002 UInt dir[4],j; 1052 Int preds[4][ 3] = {{-1, -1, -1},{-1, -1, -1},{-1, -1, -1},{-1, -1, -1}};1053 Int pred Num[4], predIdx[4] ={ -1,-1,-1,-1};1003 Int preds[4][NUM_MOST_PROBABLE_MODES] = {{-1, -1, -1},{-1, -1, -1},{-1, -1, -1},{-1, -1, -1}}; 1004 Int predIdx[4] ={ -1,-1,-1,-1}; 1054 1005 PartSize mode = pcCU->getPartitionSize( absPartIdx ); 1055 1006 UInt partNum = isMultiple?(mode==SIZE_NxN?4:1):1; 1056 UInt partOffset = ( pcCU->getPic()->getNumPart InCU() >> ( pcCU->getDepth(absPartIdx) << 1 ) ) >> 2;1007 UInt partOffset = ( pcCU->getPic()->getNumPartitionsInCtu() >> ( pcCU->getDepth(absPartIdx) << 1 ) ) >> 2; 1057 1008 for (j=0;j<partNum;j++) 1058 1009 { 1059 dir[j] = pcCU->get LumaIntraDir(absPartIdx+partOffset*j );1060 #if H_3D_DIM1010 dir[j] = pcCU->getIntraDir( CHANNEL_TYPE_LUMA, absPartIdx+partOffset*j ); 1011 #if NH_3D_DMM 1061 1012 if( pcCU->getSlice()->getIntraSdcWedgeFlag() || pcCU->getSlice()->getIntraContourFlag() ) 1062 1013 { 1063 codeIntraDepth( pcCU, absPartIdx+partOffset*j ); 1064 } 1065 if( pcCU->getLumaIntraDir( absPartIdx+partOffset*j ) < NUM_INTRA_MODE ) 1066 { 1067 #endif 1068 predNum[j] = pcCU->getIntraDirLumaPredictor(absPartIdx+partOffset*j, preds[j]); 1069 for(UInt i = 0; i < predNum[j]; i++) 1070 { 1071 if(dir[j] == preds[j][i]) 1072 { 1073 predIdx[j] = i; 1074 } 1075 } 1076 m_pcBinIf->encodeBin((predIdx[j] != -1)? 1 : 0, m_cCUIntraPredSCModel.get( 0, 0, 0 ) ); 1014 xCodeIntraDepthMode( pcCU, absPartIdx+partOffset*j ); 1015 xCodeDmmData ( pcCU, absPartIdx+partOffset*j ); 1016 } 1017 if( pcCU->getIntraDir( CHANNEL_TYPE_LUMA, absPartIdx+partOffset*j ) < NUM_INTRA_MODE ) 1018 { 1019 #endif 1020 pcCU->getIntraDirPredictor(absPartIdx+partOffset*j, preds[j], COMPONENT_Y); 1021 for(UInt i = 0; i < NUM_MOST_PROBABLE_MODES; i++) 1022 { 1023 if(dir[j] == preds[j][i]) 1024 { 1025 predIdx[j] = i; 1026 } 1027 } 1028 m_pcBinIf->encodeBin((predIdx[j] != -1)? 1 : 0, m_cCUIntraPredSCModel.get( 0, 0, 0 ) ); 1077 1029 #if H_MV_ENC_DEC_TRAC 1078 1030 DTRACE_CU("prev_intra_luma_pred_flag", (predIdx[j] != -1)? 1 : 0); 1079 1031 #endif 1080 #if H_3D_DIM1081 } 1082 #endif 1083 1084 } 1032 #if NH_3D_DMM 1033 } 1034 #endif 1035 1036 } 1085 1037 for (j=0;j<partNum;j++) 1086 1038 { 1087 #if H_3D_DIM1088 if( pcCU->get LumaIntraDir(absPartIdx+partOffset*j ) < NUM_INTRA_MODE )1089 { 1090 #endif 1091 1092 1093 1094 1095 1096 1097 1039 #if NH_3D_DMM 1040 if( pcCU->getIntraDir( CHANNEL_TYPE_LUMA, absPartIdx+partOffset*j ) < NUM_INTRA_MODE ) 1041 { 1042 #endif 1043 if(predIdx[j] != -1) 1044 { 1045 m_pcBinIf->encodeBinEP( predIdx[j] ? 1 : 0 ); 1046 if (predIdx[j]) 1047 { 1048 m_pcBinIf->encodeBinEP( predIdx[j]-1 ); 1049 } 1098 1050 #if H_MV_ENC_DEC_TRAC 1099 1051 DTRACE_CU("mpm_idx", predIdx[j] ); 1100 1052 #endif 1101 1102 1103 1104 1105 {1106 std::swap(preds[j][0], preds[j][1]);1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 for(Int i = (predNum[j]- 1); i >= 0; i--)1117 1118 1119 1120 1053 } 1054 else 1055 { 1056 if (preds[j][0] > preds[j][1]) 1057 { 1058 std::swap(preds[j][0], preds[j][1]); 1059 } 1060 if (preds[j][0] > preds[j][2]) 1061 { 1062 std::swap(preds[j][0], preds[j][2]); 1063 } 1064 if (preds[j][1] > preds[j][2]) 1065 { 1066 std::swap(preds[j][1], preds[j][2]); 1067 } 1068 for(Int i = (Int(NUM_MOST_PROBABLE_MODES) - 1); i >= 0; i--) 1069 { 1070 dir[j] = dir[j] > preds[j][i] ? dir[j] - 1 : dir[j]; 1071 } 1072 m_pcBinIf->encodeBinsEP( dir[j], 5 ); 1121 1073 #if H_MV_ENC_DEC_TRAC 1122 1074 DTRACE_CU("rem_intra_luma_pred_mode", dir[j] ); 1123 1075 #endif 1124 1125 #if H_3D_DIM1076 } 1077 #if NH_3D_DMM 1126 1078 } 1127 1079 #endif … … 1132 1084 Void TEncSbac::codeIntraDirChroma( TComDataCU* pcCU, UInt uiAbsPartIdx ) 1133 1085 { 1134 UInt uiIntraDirChroma = pcCU->get ChromaIntraDir(uiAbsPartIdx );1135 1136 if( uiIntraDirChroma == DM_CHROMA_IDX ) 1086 UInt uiIntraDirChroma = pcCU->getIntraDir( CHANNEL_TYPE_CHROMA, uiAbsPartIdx ); 1087 1088 if( uiIntraDirChroma == DM_CHROMA_IDX ) 1137 1089 { 1138 1090 m_pcBinIf->encodeBin( 0, m_cCUChromaPredSCModel.get( 0, 0, 0 ) ); … … 1142 1094 } 1143 1095 else 1144 { 1096 { 1097 m_pcBinIf->encodeBin( 1, m_cCUChromaPredSCModel.get( 0, 0, 0 ) ); 1098 1145 1099 UInt uiAllowedChromaDir[ NUM_CHROMA_MODE ]; 1146 1100 pcCU->getAllowedChromaDir( uiAbsPartIdx, uiAllowedChromaDir ); … … 1154 1108 } 1155 1109 } 1156 m_pcBinIf->encodeBin( 1, m_cCUChromaPredSCModel.get( 0, 0, 0 ) );1157 1110 1158 1111 m_pcBinIf->encodeBinsEP( uiIntraDirChroma, 2 ); … … 1162 1115 1163 1116 } 1117 1164 1118 return; 1165 1119 } 1166 1167 #if H_3D_DIM1168 Void TEncSbac::codeIntraDepth( TComDataCU* pcCU, UInt absPartIdx )1169 {1170 codeIntraDepthMode( pcCU, absPartIdx );1171 1172 UInt dir = pcCU->getLumaIntraDir( absPartIdx );1173 UInt dimType = getDimType( dir );1174 1175 switch( dimType )1176 {1177 #if H_3D_DIM_DMM1178 case( DMM1_IDX ):1179 {1180 xCodeDmm1WedgeIdx( pcCU->getDmmWedgeTabIdx( dimType, absPartIdx ), g_dmm1TabIdxBits[pcCU->getIntraSizeIdx(absPartIdx)] );1181 } break;1182 case( DMM4_IDX ): break;1183 #endif1184 default: break;1185 }1186 }1187 1188 Void TEncSbac::codeIntraDepthMode( TComDataCU* pcCU, UInt absPartIdx )1189 {1190 UInt dir = pcCU->getLumaIntraDir( absPartIdx );1191 1192 if( ( pcCU->getSlice()->getSPS()->getMaxCUWidth() >> pcCU->getDepth( absPartIdx ) ) < 64 ) //DMM and HEVC intra modes are both allowed1193 {1194 m_pcBinIf->encodeBin( isDimMode( dir ) ? 0 : 1, m_cAngleFlagSCModel.get( 0, 0, 0 ) );1195 }1196 if( isDimMode( dir ) )1197 {1198 UInt uiCodeIdx = 0;1199 1200 switch( getDimType( dir ) )1201 {1202 case DMM1_IDX: uiCodeIdx = 0; break;1203 case DMM4_IDX: uiCodeIdx = 1; break;1204 default: break;1205 }1206 //mode coding1207 if( pcCU->getSlice()->getIntraSdcWedgeFlag() && pcCU->getSlice()->getIntraContourFlag())1208 {1209 m_pcBinIf->encodeBin( uiCodeIdx == 0 ? 0 : 1, m_cDepthIntraModeSCModel.get( 0, 0, 0 ) );1210 }1211 }1212 }1213 #endif1214 1215 1120 1216 1121 Void TEncSbac::codeInterDir( TComDataCU* pcCU, UInt uiAbsPartIdx ) … … 1219 1124 const UInt uiCtx = pcCU->getCtxInterDir( uiAbsPartIdx ); 1220 1125 ContextModel *pCtx = m_cCUInterDirSCModel.get( 0 ); 1126 1221 1127 if (pcCU->getPartitionSize(uiAbsPartIdx) == SIZE_2Nx2N || pcCU->getHeight(uiAbsPartIdx) != 8 ) 1222 1128 { 1223 1129 m_pcBinIf->encodeBin( uiInterDir == 2 ? 1 : 0, *( pCtx + uiCtx ) ); 1224 1130 } 1131 1225 1132 if (uiInterDir < 2) 1226 1133 { … … 1236 1143 Void TEncSbac::codeRefFrmIdx( TComDataCU* pcCU, UInt uiAbsPartIdx, RefPicList eRefList ) 1237 1144 { 1238 { 1239 Int iRefFrame = pcCU->getCUMvField( eRefList )->getRefIdx( uiAbsPartIdx ); 1240 ContextModel *pCtx = m_cCURefPicSCModel.get( 0 ); 1241 m_pcBinIf->encodeBin( ( iRefFrame == 0 ? 0 : 1 ), *pCtx ); 1242 1243 if( iRefFrame > 0 ) 1244 { 1245 UInt uiRefNum = pcCU->getSlice()->getNumRefIdx( eRefList ) - 2; 1246 pCtx++; 1247 iRefFrame--; 1248 for( UInt ui = 0; ui < uiRefNum; ++ui ) 1249 { 1250 const UInt uiSymbol = ui == iRefFrame ? 0 : 1; 1251 if( ui == 0 ) 1252 { 1253 m_pcBinIf->encodeBin( uiSymbol, *pCtx ); 1254 } 1255 else 1256 { 1257 m_pcBinIf->encodeBinEP( uiSymbol ); 1258 } 1259 if( uiSymbol == 0 ) 1260 { 1261 break; 1262 } 1263 } 1264 } 1145 Int iRefFrame = pcCU->getCUMvField( eRefList )->getRefIdx( uiAbsPartIdx ); 1146 ContextModel *pCtx = m_cCURefPicSCModel.get( 0 ); 1147 m_pcBinIf->encodeBin( ( iRefFrame == 0 ? 0 : 1 ), *pCtx ); 1148 1149 if( iRefFrame > 0 ) 1150 { 1151 UInt uiRefNum = pcCU->getSlice()->getNumRefIdx( eRefList ) - 2; 1152 pCtx++; 1153 iRefFrame--; 1154 for( UInt ui = 0; ui < uiRefNum; ++ui ) 1155 { 1156 const UInt uiSymbol = ui == iRefFrame ? 0 : 1; 1157 if( ui == 0 ) 1158 { 1159 m_pcBinIf->encodeBin( uiSymbol, *pCtx ); 1160 } 1161 else 1162 { 1163 m_pcBinIf->encodeBinEP( uiSymbol ); 1164 } 1165 if( uiSymbol == 0 ) 1166 { 1167 break; 1168 } 1169 } 1170 } 1265 1171 #if H_MV_ENC_DEC_TRAC 1266 1172 #if ENC_DEC_TRACE … … 1276 1182 #endif 1277 1183 #endif 1278 }1279 1184 return; 1280 1185 } … … 1330 1235 m_pcBinIf->encodeBinEP( 0 > iVer ? 1 : 0 ); 1331 1236 } 1332 1237 1333 1238 return; 1334 1239 } 1335 1240 1241 Void TEncSbac::codeCrossComponentPrediction( TComTU &rTu, ComponentID compID ) 1242 { 1243 TComDataCU *pcCU = rTu.getCU(); 1244 1245 if( isLuma(compID) || !pcCU->getSlice()->getPPS()->getPpsRangeExtension().getCrossComponentPredictionEnabledFlag() ) 1246 { 1247 return; 1248 } 1249 1250 const UInt uiAbsPartIdx = rTu.GetAbsPartIdxTU(); 1251 1252 if (!pcCU->isIntra(uiAbsPartIdx) || (pcCU->getIntraDir( CHANNEL_TYPE_CHROMA, uiAbsPartIdx ) == DM_CHROMA_IDX)) 1253 { 1254 DTRACE_CABAC_VL( g_nSymbolCounter++ ) 1255 DTRACE_CABAC_T("\tparseCrossComponentPrediction()") 1256 DTRACE_CABAC_T( "\tAddr=" ) 1257 DTRACE_CABAC_V( compID ) 1258 DTRACE_CABAC_T( "\tuiAbsPartIdx=" ) 1259 DTRACE_CABAC_V( uiAbsPartIdx ) 1260 1261 Int alpha = pcCU->getCrossComponentPredictionAlpha( uiAbsPartIdx, compID ); 1262 ContextModel *pCtx = m_cCrossComponentPredictionSCModel.get(0, 0) + ((compID == COMPONENT_Cr) ? (NUM_CROSS_COMPONENT_PREDICTION_CTX >> 1) : 0); 1263 m_pcBinIf->encodeBin(((alpha != 0) ? 1 : 0), pCtx[0]); 1264 1265 if (alpha != 0) 1266 { 1267 static const Int log2AbsAlphaMinus1Table[8] = { 0, 1, 1, 2, 2, 2, 3, 3 }; 1268 assert(abs(alpha) <= 8); 1269 1270 if (abs(alpha)>1) 1271 { 1272 m_pcBinIf->encodeBin(1, pCtx[1]); 1273 xWriteUnaryMaxSymbol( log2AbsAlphaMinus1Table[abs(alpha) - 1] - 1, (pCtx + 2), 1, 2 ); 1274 } 1275 else 1276 { 1277 m_pcBinIf->encodeBin(0, pCtx[1]); 1278 } 1279 m_pcBinIf->encodeBin( ((alpha < 0) ? 1 : 0), pCtx[4] ); 1280 } 1281 DTRACE_CABAC_T( "\tAlpha=" ) 1282 DTRACE_CABAC_V( pcCU->getCrossComponentPredictionAlpha( uiAbsPartIdx, compID ) ) 1283 DTRACE_CABAC_T( "\n" ) 1284 } 1285 } 1286 1336 1287 Void TEncSbac::codeDeltaQP( TComDataCU* pcCU, UInt uiAbsPartIdx ) 1337 1288 { 1338 1289 Int iDQp = pcCU->getQP( uiAbsPartIdx ) - pcCU->getRefQP( uiAbsPartIdx ); 1339 1340 Int qpBdOffsetY = pcCU->getSlice()->getSPS()->getQpBDOffset Y();1290 1291 Int qpBdOffsetY = pcCU->getSlice()->getSPS()->getQpBDOffset(CHANNEL_TYPE_LUMA); 1341 1292 iDQp = (iDQp + 78 + qpBdOffsetY + (qpBdOffsetY/2)) % (52 + qpBdOffsetY) - 26 - (qpBdOffsetY/2); 1342 1293 … … 1358 1309 } 1359 1310 1360 Void TEncSbac::codeQtCbf( TComDataCU* pcCU, UInt uiAbsPartIdx, TextType eType, UInt uiTrDepth ) 1361 { 1362 UInt uiCbf = pcCU->getCbf ( uiAbsPartIdx, eType, uiTrDepth ); 1363 UInt uiCtx = pcCU->getCtxQtCbf( eType, uiTrDepth ); 1364 m_pcBinIf->encodeBin( uiCbf , m_cCUQtCbfSCModel.get( 0, eType ? TEXT_CHROMA : eType, uiCtx ) ); 1311 /** code chroma qp adjustment, converting from the internal table representation 1312 * \returns Void 1313 */ 1314 Void TEncSbac::codeChromaQpAdjustment( TComDataCU* cu, UInt absPartIdx ) 1315 { 1316 Int internalIdc = cu->getChromaQpAdj( absPartIdx ); 1317 Int chromaQpOffsetListLen = cu->getSlice()->getPPS()->getPpsRangeExtension().getChromaQpOffsetListLen(); 1318 /* internal_idc == 0 => flag = 0 1319 * internal_idc > 1 => code idc value (if table size warrents) */ 1320 m_pcBinIf->encodeBin( internalIdc > 0, m_ChromaQpAdjFlagSCModel.get( 0, 0, 0 ) ); 1321 1322 if (internalIdc > 0 && chromaQpOffsetListLen > 1) 1323 { 1324 xWriteUnaryMaxSymbol( internalIdc - 1, &m_ChromaQpAdjIdcSCModel.get( 0, 0, 0 ), 0, chromaQpOffsetListLen - 1 ); 1325 } 1326 } 1327 1328 Void TEncSbac::codeQtCbf( TComTU &rTu, const ComponentID compID, const Bool lowestLevel ) 1329 { 1330 TComDataCU* pcCU = rTu.getCU(); 1331 1332 const UInt absPartIdx = rTu.GetAbsPartIdxTU(compID); 1333 const UInt TUDepth = rTu.GetTransformDepthRel(); 1334 UInt uiCtx = pcCU->getCtxQtCbf( rTu, toChannelType(compID) ); 1335 const UInt contextSet = toChannelType(compID); 1336 1337 const UInt width = rTu.getRect(compID).width; 1338 const UInt height = rTu.getRect(compID).height; 1339 const Bool canQuadSplit = (width >= (MIN_TU_SIZE * 2)) && (height >= (MIN_TU_SIZE * 2)); 1340 1341 // Since the CBF for chroma is coded at the highest level possible, if sub-TUs are 1342 // to be coded for a 4x8 chroma TU, their CBFs must be coded at the highest 4x8 level 1343 // (i.e. where luma TUs are 8x8 rather than 4x4) 1344 // ___ ___ 1345 // | | | <- 4 x (8x8 luma + 4x8 4:2:2 chroma) 1346 // |___|___| each quadrant has its own chroma CBF 1347 // | | | _ _ _ _ 1348 // |___|___| | 1349 // <--16---> V 1350 // _ _ 1351 // |_|_| <- 4 x 4x4 luma + 1 x 4x8 4:2:2 chroma 1352 // |_|_| no chroma CBF is coded - instead the parent CBF is inherited 1353 // <-8-> if sub-TUs are present, their CBFs had to be coded at the parent level 1354 1355 const UInt lowestTUDepth = TUDepth + ((!lowestLevel && !canQuadSplit) ? 1 : 0); //unsplittable TUs inherit their parent's CBF 1356 1357 if ((width != height) && (lowestLevel || !canQuadSplit)) //if sub-TUs are present 1358 { 1359 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) 1360 const UInt partIdxesPerSubTU = rTu.GetAbsPartIdxNumParts(compID) >> 1; 1361 1362 for (UInt subTU = 0; subTU < 2; subTU++) 1363 { 1364 const UInt subTUAbsPartIdx = absPartIdx + (subTU * partIdxesPerSubTU); 1365 const UInt uiCbf = pcCU->getCbf(subTUAbsPartIdx, compID, subTUDepth); 1366 1367 m_pcBinIf->encodeBin(uiCbf, m_cCUQtCbfSCModel.get(0, contextSet, uiCtx)); 1365 1368 #if !H_MV_ENC_DEC_TRAC 1366 DTRACE_CABAC_VL( g_nSymbolCounter++ ) 1367 DTRACE_CABAC_T( "\tparseQtCbf()" ) 1368 DTRACE_CABAC_T( "\tsymbol=" ) 1369 DTRACE_CABAC_V( uiCbf ) 1370 DTRACE_CABAC_T( "\tctx=" ) 1371 DTRACE_CABAC_V( uiCtx ) 1372 DTRACE_CABAC_T( "\tetype=" ) 1373 DTRACE_CABAC_V( eType ) 1374 DTRACE_CABAC_T( "\tuiAbsPartIdx=" ) 1375 DTRACE_CABAC_V( uiAbsPartIdx ) 1376 DTRACE_CABAC_T( "\n" ) 1369 DTRACE_CABAC_VL( g_nSymbolCounter++ ) 1370 DTRACE_CABAC_T( "\tparseQtCbf()" ) 1371 DTRACE_CABAC_T( "\tsub-TU=" ) 1372 DTRACE_CABAC_V( subTU ) 1373 DTRACE_CABAC_T( "\tsymbol=" ) 1374 DTRACE_CABAC_V( uiCbf ) 1375 DTRACE_CABAC_T( "\tctx=" ) 1376 DTRACE_CABAC_V( uiCtx ) 1377 DTRACE_CABAC_T( "\tetype=" ) 1378 DTRACE_CABAC_V( compID ) 1379 DTRACE_CABAC_T( "\tuiAbsPartIdx=" ) 1380 DTRACE_CABAC_V( subTUAbsPartIdx ) 1381 DTRACE_CABAC_T( "\n" ) 1377 1382 #else 1378 if ( eType == TEXT_CHROMA_U ) 1379 { 1380 DTRACE_TU("cbf_cb", uiCbf ) 1381 } 1382 else if ( eType == TEXT_CHROMA_V ) 1383 { 1384 DTRACE_TU("cbf_cr", uiCbf ) 1383 if ( compID == COMPONENT_Cb ) 1384 { 1385 DTRACE_TU("cbf_cb", uiCbf ) 1386 } 1387 else if ( compID == COMPONENT_Cr ) 1388 { 1389 DTRACE_TU("cbf_cr", uiCbf ) 1390 } 1391 else 1392 { 1393 DTRACE_TU("cbf_luma", uiCbf ) 1394 } 1395 #endif 1396 } 1385 1397 } 1386 1398 else 1387 1399 { 1388 DTRACE_TU("cbf_luma", uiCbf ) 1389 } 1390 #endif 1391 } 1392 1393 void TEncSbac::codeTransformSkipFlags (TComDataCU* pcCU, UInt uiAbsPartIdx, UInt width, UInt height, TextType eTType ) 1394 { 1400 const UInt uiCbf = pcCU->getCbf( absPartIdx, compID, lowestTUDepth ); 1401 m_pcBinIf->encodeBin( uiCbf , m_cCUQtCbfSCModel.get( 0, contextSet, uiCtx ) ); 1402 #if !H_MV_ENC_DEC_TRAC 1403 DTRACE_CABAC_VL( g_nSymbolCounter++ ) 1404 DTRACE_CABAC_T( "\tparseQtCbf()" ) 1405 DTRACE_CABAC_T( "\tsymbol=" ) 1406 DTRACE_CABAC_V( uiCbf ) 1407 DTRACE_CABAC_T( "\tctx=" ) 1408 DTRACE_CABAC_V( uiCtx ) 1409 DTRACE_CABAC_T( "\tetype=" ) 1410 DTRACE_CABAC_V( compID ) 1411 DTRACE_CABAC_T( "\tuiAbsPartIdx=" ) 1412 DTRACE_CABAC_V( rTu.GetAbsPartIdxTU(compID) ) 1413 DTRACE_CABAC_T( "\n" ) 1414 #else 1415 if ( compID == COMPONENT_Cb ) 1416 { 1417 DTRACE_TU("cbf_cb", uiCbf ) 1418 } 1419 else if ( compID == COMPONENT_Cr ) 1420 { 1421 DTRACE_TU("cbf_cr", uiCbf ) 1422 } 1423 else 1424 { 1425 DTRACE_TU("cbf_luma", uiCbf ) 1426 } 1427 #endif 1428 1429 } 1430 } 1431 1432 1433 Void TEncSbac::codeTransformSkipFlags (TComTU &rTu, ComponentID component ) 1434 { 1435 TComDataCU* pcCU=rTu.getCU(); 1436 const UInt uiAbsPartIdx=rTu.GetAbsPartIdxTU(); 1437 1395 1438 if (pcCU->getCUTransquantBypass(uiAbsPartIdx)) 1396 1439 { 1397 1440 return; 1398 1441 } 1399 if(width != 4 || height != 4) 1442 1443 if (!TUCompRectHasAssociatedTransformSkipFlag(rTu.getRect(component), pcCU->getSlice()->getPPS()->getPpsRangeExtension().getLog2MaxTransformSkipBlockSize())) 1400 1444 { 1401 1445 return; 1402 1446 } 1403 1447 1404 UInt useTransformSkip = pcCU->getTransformSkip( uiAbsPartIdx, eTType);1405 m_pcBinIf->encodeBin( useTransformSkip, m_cTransformSkipSCModel.get( 0, eTType? TEXT_CHROMA: TEXT_LUMA, 0 ) );1448 UInt useTransformSkip = pcCU->getTransformSkip( uiAbsPartIdx,component); 1449 m_pcBinIf->encodeBin( useTransformSkip, m_cTransformSkipSCModel.get( 0, toChannelType(component), 0 ) ); 1406 1450 #if !H_MV_ENC_DEC_TRAC 1407 1451 DTRACE_CABAC_VL( g_nSymbolCounter++ ) … … 1410 1454 DTRACE_CABAC_V( useTransformSkip ) 1411 1455 DTRACE_CABAC_T( "\tAddr=" ) 1412 DTRACE_CABAC_V( pcCU->get Addr() )1456 DTRACE_CABAC_V( pcCU->getCtuRsAddr() ) 1413 1457 DTRACE_CABAC_T( "\tetype=" ) 1414 DTRACE_CABAC_V( eTType)1458 DTRACE_CABAC_V( component ) 1415 1459 DTRACE_CABAC_T( "\tuiAbsPartIdx=" ) 1416 DTRACE_CABAC_V( uiAbsPartIdx)1460 DTRACE_CABAC_V( rTu.GetAbsPartIdxTU() ) 1417 1461 DTRACE_CABAC_T( "\n" ) 1418 1462 #endif 1419 1463 } 1464 1420 1465 1421 1466 /** Code I_PCM information. … … 1438 1483 m_pcBinIf->encodePCMAlignBits(); 1439 1484 1440 UInt uiMinCoeffSize = pcCU->getPic()->getMinCUWidth()*pcCU->getPic()->getMinCUHeight(); 1441 UInt uiLumaOffset = uiMinCoeffSize*uiAbsPartIdx; 1442 UInt uiChromaOffset = uiLumaOffset>>2; 1443 Pel* piPCMSample; 1444 UInt uiWidth; 1445 UInt uiHeight; 1446 UInt uiSampleBits; 1447 UInt uiX, uiY; 1448 1449 piPCMSample = pcCU->getPCMSampleY() + uiLumaOffset; 1450 uiWidth = pcCU->getWidth(uiAbsPartIdx); 1451 uiHeight = pcCU->getHeight(uiAbsPartIdx); 1452 uiSampleBits = pcCU->getSlice()->getSPS()->getPCMBitDepthLuma(); 1453 1454 for(uiY = 0; uiY < uiHeight; uiY++) 1455 { 1456 for(uiX = 0; uiX < uiWidth; uiX++) 1457 { 1458 UInt uiSample = piPCMSample[uiX]; 1459 1460 m_pcBinIf->xWritePCMCode(uiSample, uiSampleBits); 1461 } 1462 piPCMSample += uiWidth; 1463 } 1464 1465 #if H_3D_DISABLE_CHROMA 1466 if( pcCU->getSlice()->getSPS()->getChromaFormatIdc() != 0 ) 1467 { 1468 #endif 1469 piPCMSample = pcCU->getPCMSampleCb() + uiChromaOffset; 1470 uiWidth = pcCU->getWidth(uiAbsPartIdx)/2; 1471 uiHeight = pcCU->getHeight(uiAbsPartIdx)/2; 1472 uiSampleBits = pcCU->getSlice()->getSPS()->getPCMBitDepthChroma(); 1473 1474 for(uiY = 0; uiY < uiHeight; uiY++) 1475 { 1476 for(uiX = 0; uiX < uiWidth; uiX++) 1485 const UInt minCoeffSizeY = pcCU->getPic()->getMinCUWidth() * pcCU->getPic()->getMinCUHeight(); 1486 const UInt offsetY = minCoeffSizeY * uiAbsPartIdx; 1487 for (UInt ch=0; ch < pcCU->getPic()->getNumberValidComponents(); ch++) 1488 { 1489 const ComponentID compID = ComponentID(ch); 1490 const UInt offset = offsetY >> (pcCU->getPic()->getComponentScaleX(compID) + pcCU->getPic()->getComponentScaleY(compID)); 1491 Pel * pPCMSample = pcCU->getPCMSample(compID) + offset; 1492 const UInt width = pcCU->getWidth (uiAbsPartIdx) >> pcCU->getPic()->getComponentScaleX(compID); 1493 const UInt height = pcCU->getHeight(uiAbsPartIdx) >> pcCU->getPic()->getComponentScaleY(compID); 1494 const UInt sampleBits = pcCU->getSlice()->getSPS()->getPCMBitDepth(toChannelType(compID)); 1495 for (UInt y=0; y<height; y++) 1496 { 1497 for (UInt x=0; x<width; x++) 1477 1498 { 1478 UInt uiSample = piPCMSample[uiX]; 1479 1480 m_pcBinIf->xWritePCMCode(uiSample, uiSampleBits); 1499 UInt sample = pPCMSample[x]; 1500 m_pcBinIf->xWritePCMCode(sample, sampleBits); 1481 1501 } 1482 piPCMSample += uiWidth; 1483 } 1484 1485 piPCMSample = pcCU->getPCMSampleCr() + uiChromaOffset; 1486 uiWidth = pcCU->getWidth(uiAbsPartIdx)/2; 1487 uiHeight = pcCU->getHeight(uiAbsPartIdx)/2; 1488 uiSampleBits = pcCU->getSlice()->getSPS()->getPCMBitDepthChroma(); 1489 1490 for(uiY = 0; uiY < uiHeight; uiY++) 1491 { 1492 for(uiX = 0; uiX < uiWidth; uiX++) 1493 { 1494 UInt uiSample = piPCMSample[uiX]; 1495 1496 m_pcBinIf->xWritePCMCode(uiSample, uiSampleBits); 1497 } 1498 piPCMSample += uiWidth; 1499 } 1500 #if H_3D_DISABLE_CHROMA 1501 } 1502 #endif 1502 pPCMSample += width; 1503 } 1504 } 1503 1505 m_pcBinIf->resetBac(); 1504 1506 } … … 1525 1527 } 1526 1528 1527 Void TEncSbac::codeQtCbfZero( TCom DataCU* pcCU, TextType eType, UInt uiTrDepth)1529 Void TEncSbac::codeQtCbfZero( TComTU & rTu, const ChannelType chType ) 1528 1530 { 1529 1531 // this function is only used to estimate the bits when cbf is 0 1530 1532 // and will never be called when writing the bistream. do not need to write log 1531 1533 UInt uiCbf = 0; 1532 UInt uiCtx = pcCU->getCtxQtCbf( eType, uiTrDepth ); 1533 m_pcBinIf->encodeBin( uiCbf , m_cCUQtCbfSCModel.get( 0, eType ? TEXT_CHROMA : eType, uiCtx ) ); 1534 } 1535 1536 Void TEncSbac::codeQtRootCbfZero( TComDataCU* pcCU ) 1534 UInt uiCtx = rTu.getCU()->getCtxQtCbf( rTu, chType ); 1535 1536 m_pcBinIf->encodeBin( uiCbf , m_cCUQtCbfSCModel.get( 0, chType, uiCtx ) ); 1537 } 1538 1539 Void TEncSbac::codeQtRootCbfZero( ) 1537 1540 { 1538 1541 // this function is only used to estimate the bits when cbf is 0 … … 1544 1547 1545 1548 /** Encode (X,Y) position of the last significant coefficient 1546 * \param uiPosX X component of last coefficient1547 * \param uiPosY Y component of last coefficient1548 * \param width Block width1549 * \param height Block height1550 * \param eTType plane type / luminance or chrominance1551 * \param uiScanIdx scan type (zig-zag, hor, ver)1549 * \param uiPosX X component of last coefficient 1550 * \param uiPosY Y component of last coefficient 1551 * \param width Block width 1552 * \param height Block height 1553 * \param component chroma component ID 1554 * \param uiScanIdx scan type (zig-zag, hor, ver) 1552 1555 * This method encodes the X and Y component within a block of the last significant coefficient. 1553 1556 */ 1554 Void TEncSbac::codeLastSignificantXY( UInt uiPosX, UInt uiPosY, Int width, Int height, TextType eTType, UInt uiScanIdx )1555 { 1557 Void TEncSbac::codeLastSignificantXY( UInt uiPosX, UInt uiPosY, Int width, Int height, ComponentID component, UInt uiScanIdx ) 1558 { 1556 1559 // swap 1557 1560 if( uiScanIdx == SCAN_VER ) 1558 1561 { 1559 1562 swap( uiPosX, uiPosY ); 1563 swap( width, height ); 1560 1564 } 1561 1565 1562 1566 UInt uiCtxLast; 1563 ContextModel *pCtxX = m_cCuCtxLastX.get( 0, eTType );1564 ContextModel *pCtxY = m_cCuCtxLastY.get( 0, eTType );1565 1567 UInt uiGroupIdxX = g_uiGroupIdx[ uiPosX ]; 1566 1568 UInt uiGroupIdxY = g_uiGroupIdx[ uiPosY ]; 1567 1569 1570 ContextModel *pCtxX = m_cCuCtxLastX.get( 0, toChannelType(component) ); 1571 ContextModel *pCtxY = m_cCuCtxLastY.get( 0, toChannelType(component) ); 1568 1572 1569 1573 Int blkSizeOffsetX, blkSizeOffsetY, shiftX, shiftY; 1570 blkSizeOffsetX = eTType ? 0: (g_aucConvertToBit[ width ] *3 + ((g_aucConvertToBit[ width ] +1)>>2));1571 blkSizeOffsetY = eTType ? 0: (g_aucConvertToBit[ height ]*3 + ((g_aucConvertToBit[ height ]+1)>>2)); 1572 shiftX= eTType ? g_aucConvertToBit[ width ] :((g_aucConvertToBit[ width ]+3)>>2);1573 shiftY= eTType ? g_aucConvertToBit[ height ] :((g_aucConvertToBit[ height ]+3)>>2); 1574 getLastSignificantContextParameters(component, width, height, blkSizeOffsetX, blkSizeOffsetY, shiftX, shiftY); 1575 1576 //------------------ 1577 1574 1578 // posX 1579 1575 1580 for( uiCtxLast = 0; uiCtxLast < uiGroupIdxX; uiCtxLast++ ) 1576 1581 { 1577 1582 m_pcBinIf->encodeBin( 1, *( pCtxX + blkSizeOffsetX + (uiCtxLast >>shiftX) ) ); 1578 1583 } 1579 1584 if( uiGroupIdxX < g_uiGroupIdx[ width - 1 ]) 1580 1585 { 1581 1586 m_pcBinIf->encodeBin( 0, *( pCtxX + blkSizeOffsetX + (uiCtxLast >>shiftX) ) ); 1582 1587 } 1583 1588 1584 1589 // posY 1590 1585 1591 for( uiCtxLast = 0; uiCtxLast < uiGroupIdxY; uiCtxLast++ ) 1586 1592 { … … 1591 1597 m_pcBinIf->encodeBin( 0, *( pCtxY + blkSizeOffsetY + (uiCtxLast >>shiftY) ) ); 1592 1598 } 1599 1600 // EP-coded part 1601 1593 1602 if ( uiGroupIdxX > 3 ) 1594 { 1603 { 1595 1604 UInt uiCount = ( uiGroupIdxX - 2 ) >> 1; 1596 1605 uiPosX = uiPosX - g_uiMinInGroup[ uiGroupIdxX ]; … … 1601 1610 } 1602 1611 if ( uiGroupIdxY > 3 ) 1603 { 1612 { 1604 1613 UInt uiCount = ( uiGroupIdxY - 2 ) >> 1; 1605 1614 uiPosY = uiPosY - g_uiMinInGroup[ uiGroupIdxY ]; … … 1611 1620 } 1612 1621 1613 Void TEncSbac::codeCoeffNxN( TComDataCU* pcCU, TCoeff* pcCoef, UInt uiAbsPartIdx, UInt uiWidth, UInt uiHeight, UInt uiDepth, TextType eTType ) 1614 { 1622 1623 Void TEncSbac::codeCoeffNxN( TComTU &rTu, TCoeff* pcCoef, const ComponentID compID ) 1624 { 1625 TComDataCU* pcCU=rTu.getCU(); 1626 const UInt uiAbsPartIdx=rTu.GetAbsPartIdxTU(compID); 1627 const TComRectangle &tuRect=rTu.getRect(compID); 1628 const UInt uiWidth=tuRect.width; 1629 const UInt uiHeight=tuRect.height; 1630 const TComSPS &sps=*(pcCU->getSlice()->getSPS()); 1615 1631 #if !H_MV_ENC_DEC_TRAC 1632 1616 1633 DTRACE_CABAC_VL( g_nSymbolCounter++ ) 1617 1634 DTRACE_CABAC_T( "\tparseCoeffNxN()\teType=" ) 1618 DTRACE_CABAC_V( eTType)1635 DTRACE_CABAC_V( compID ) 1619 1636 DTRACE_CABAC_T( "\twidth=" ) 1620 1637 DTRACE_CABAC_V( uiWidth ) … … 1622 1639 DTRACE_CABAC_V( uiHeight ) 1623 1640 DTRACE_CABAC_T( "\tdepth=" ) 1624 DTRACE_CABAC_V( uiDepth ) 1641 // DTRACE_CABAC_V( rTu.GetTransformDepthTotalAdj(compID) ) 1642 DTRACE_CABAC_V( rTu.GetTransformDepthTotal() ) 1625 1643 DTRACE_CABAC_T( "\tabspartidx=" ) 1626 1644 DTRACE_CABAC_V( uiAbsPartIdx ) … … 1630 1648 DTRACE_CABAC_V( pcCU->getCUPelY() ) 1631 1649 DTRACE_CABAC_T( "\tCU-addr=" ) 1632 DTRACE_CABAC_V( pcCU->get Addr() )1650 DTRACE_CABAC_V( pcCU->getCtuRsAddr() ) 1633 1651 DTRACE_CABAC_T( "\tinCU-X=" ) 1634 DTRACE_CABAC_V( g_auiRasterToPelX[ g_auiZscanToRaster[uiAbsPartIdx] ] ) 1652 // DTRACE_CABAC_V( g_auiRasterToPelX[ g_auiZscanToRaster[uiAbsPartIdx] ] ) 1653 DTRACE_CABAC_V( g_auiRasterToPelX[ g_auiZscanToRaster[rTu.GetAbsPartIdxTU(compID)] ] ) 1635 1654 DTRACE_CABAC_T( "\tinCU-Y=" ) 1636 DTRACE_CABAC_V( g_auiRasterToPelY[ g_auiZscanToRaster[uiAbsPartIdx] ] ) 1655 // DTRACE_CABAC_V( g_auiRasterToPelY[ g_auiZscanToRaster[uiAbsPartIdx] ] ) 1656 DTRACE_CABAC_V( g_auiRasterToPelY[ g_auiZscanToRaster[rTu.GetAbsPartIdxTU(compID)] ] ) 1637 1657 DTRACE_CABAC_T( "\tpredmode=" ) 1638 1658 DTRACE_CABAC_V( pcCU->getPredictionMode( uiAbsPartIdx ) ) 1639 1659 DTRACE_CABAC_T( "\n" ) 1640 1660 #endif 1641 if( uiWidth > m_pcSlice->getSPS()->getMaxTrSize() ) 1642 { 1643 uiWidth = m_pcSlice->getSPS()->getMaxTrSize(); 1644 uiHeight = m_pcSlice->getSPS()->getMaxTrSize(); 1645 } 1646 1647 UInt uiNumSig = 0; 1648 1661 1662 //-------------------------------------------------------------------------------------------------- 1663 1664 if( uiWidth > sps.getMaxTrSize() ) 1665 { 1666 std::cerr << "ERROR: codeCoeffNxN was passed a TU with dimensions larger than the maximum allowed size" << std::endl; 1667 assert(false); 1668 exit(1); 1669 } 1670 1649 1671 // compute number of significant coefficients 1650 uiNumSig = TEncEntropy::countNonZeroCoeffs(pcCoef, uiWidth * uiHeight);1651 1672 UInt uiNumSig = TEncEntropy::countNonZeroCoeffs(pcCoef, uiWidth * uiHeight); 1673 1652 1674 if ( uiNumSig == 0 ) 1653 return; 1675 { 1676 std::cerr << "ERROR: codeCoeffNxN called for empty TU!" << std::endl; 1677 assert(false); 1678 exit(1); 1679 } 1680 1681 //-------------------------------------------------------------------------------------------------- 1682 1683 //set parameters 1684 1685 const ChannelType chType = toChannelType(compID); 1686 const UInt uiLog2BlockWidth = g_aucConvertToBit[ uiWidth ] + 2; 1687 const UInt uiLog2BlockHeight = g_aucConvertToBit[ uiHeight ] + 2; 1688 1689 const ChannelType channelType = toChannelType(compID); 1690 const Bool extendedPrecision = sps.getSpsRangeExtension().getExtendedPrecisionProcessingFlag(); 1691 1692 const Bool alignCABACBeforeBypass = sps.getSpsRangeExtension().getCabacBypassAlignmentEnabledFlag(); 1693 const Int maxLog2TrDynamicRange = sps.getMaxLog2TrDynamicRange(channelType); 1694 1695 Bool beValid; 1696 1697 { 1698 Int uiIntraMode = -1; 1699 const Bool bIsLuma = isLuma(compID); 1700 Int isIntra = pcCU->isIntra(uiAbsPartIdx) ? 1 : 0; 1701 if ( isIntra ) 1702 { 1703 uiIntraMode = pcCU->getIntraDir( toChannelType(compID), uiAbsPartIdx ); 1704 1705 const UInt partsPerMinCU = 1<<(2*(sps.getMaxTotalCUDepth() - sps.getLog2DiffMaxMinCodingBlockSize())); 1706 uiIntraMode = (uiIntraMode==DM_CHROMA_IDX && !bIsLuma) ? pcCU->getIntraDir(CHANNEL_TYPE_LUMA, getChromasCorrespondingPULumaIdx(uiAbsPartIdx, rTu.GetChromaFormat(), partsPerMinCU)) : uiIntraMode; 1707 uiIntraMode = ((rTu.GetChromaFormat() == CHROMA_422) && !bIsLuma) ? g_chroma422IntraAngleMappingTable[uiIntraMode] : uiIntraMode; 1708 } 1709 1710 Int transformSkip = pcCU->getTransformSkip( uiAbsPartIdx,compID) ? 1 : 0; 1711 Bool rdpcm_lossy = ( transformSkip && isIntra && ( (uiIntraMode == HOR_IDX) || (uiIntraMode == VER_IDX) ) ) && pcCU->isRDPCMEnabled(uiAbsPartIdx); 1712 1713 if ( (pcCU->getCUTransquantBypass(uiAbsPartIdx)) || rdpcm_lossy ) 1714 { 1715 beValid = false; 1716 if ( (!pcCU->isIntra(uiAbsPartIdx)) && pcCU->isRDPCMEnabled(uiAbsPartIdx)) 1717 { 1718 codeExplicitRdpcmMode( rTu, compID); 1719 } 1720 } 1721 else 1722 { 1723 beValid = pcCU->getSlice()->getPPS()->getSignHideFlag(); 1724 } 1725 } 1726 1727 //-------------------------------------------------------------------------------------------------- 1728 1654 1729 if(pcCU->getSlice()->getPPS()->getUseTransformSkip()) 1655 1730 { 1656 codeTransformSkipFlags( pcCU,uiAbsPartIdx, uiWidth, uiHeight, eTType ); 1657 } 1658 eTType = eTType == TEXT_LUMA ? TEXT_LUMA : ( eTType == TEXT_NONE ? TEXT_NONE : TEXT_CHROMA ); 1659 1731 codeTransformSkipFlags(rTu, compID); 1732 if(pcCU->getTransformSkip(uiAbsPartIdx, compID) && !pcCU->isIntra(uiAbsPartIdx) && pcCU->isRDPCMEnabled(uiAbsPartIdx)) 1733 { 1734 // This TU has coefficients and is transform skipped. Check whether is inter coded and if yes encode the explicit RDPCM mode 1735 codeExplicitRdpcmMode( rTu, compID); 1736 1737 if(pcCU->getExplicitRdpcmMode(compID, uiAbsPartIdx) != RDPCM_OFF) 1738 { 1739 // Sign data hiding is avoided for horizontal and vertical explicit RDPCM modes 1740 beValid = false; 1741 } 1742 } 1743 } 1744 1745 //-------------------------------------------------------------------------------------------------- 1746 1747 const Bool bUseGolombRiceParameterAdaptation = sps.getSpsRangeExtension().getPersistentRiceAdaptationEnabledFlag(); 1748 UInt ¤tGolombRiceStatistic = m_golombRiceAdaptationStatistics[rTu.getGolombRiceStatisticsIndex(compID)]; 1749 1750 //select scans 1751 TUEntropyCodingParameters codingParameters; 1752 getTUEntropyCodingParameters(codingParameters, rTu, compID); 1753 1660 1754 //----- encode significance map ----- 1661 const UInt uiLog2BlockSize = g_aucConvertToBit[ uiWidth ] + 2;1662 UInt uiScanIdx = pcCU->getCoefScanIdx(uiAbsPartIdx, uiWidth, eTType==TEXT_LUMA, pcCU->isIntra(uiAbsPartIdx));1663 const UInt *scan = g_auiSigLastScan[ uiScanIdx ][ uiLog2BlockSize - 1 ];1664 1665 Bool beValid;1666 if (pcCU->getCUTransquantBypass(uiAbsPartIdx))1667 {1668 beValid = false;1669 }1670 else1671 {1672 beValid = pcCU->getSlice()->getPPS()->getSignHideFlag() > 0;1673 }1674 1755 1675 1756 // Find position of last coefficient … … 1677 1758 Int posLast; 1678 1759 1679 const UInt * scanCG; 1680 { 1681 scanCG = g_auiSigLastScan[ uiScanIdx ][ uiLog2BlockSize > 3 ? uiLog2BlockSize-2-1 : 0 ]; 1682 if( uiLog2BlockSize == 3 ) 1683 { 1684 scanCG = g_sigLastScan8x8[ uiScanIdx ]; 1685 } 1686 else if( uiLog2BlockSize == 5 ) 1687 { 1688 scanCG = g_sigLastScanCG32x32; 1689 } 1690 } 1760 1691 1761 UInt uiSigCoeffGroupFlag[ MLS_GRP_NUM ]; 1692 static const UInt uiShift = MLS_CG_SIZE >> 1; 1693 const UInt uiNumBlkSide = uiWidth >> uiShift; 1694 1695 ::memset( uiSigCoeffGroupFlag, 0, sizeof(UInt) * MLS_GRP_NUM ); 1696 1697 do 1698 { 1699 posLast = scan[ ++scanPosLast ]; 1700 1762 1763 memset( uiSigCoeffGroupFlag, 0, sizeof(UInt) * MLS_GRP_NUM ); 1764 do 1765 { 1766 posLast = codingParameters.scan[ ++scanPosLast ]; 1767 1768 if( pcCoef[ posLast ] != 0 ) 1769 { 1701 1770 // get L1 sig map 1702 UInt uiPosY = posLast >> uiLog2BlockSize; 1703 UInt uiPosX = posLast - ( uiPosY << uiLog2BlockSize ); 1704 UInt uiBlkIdx = uiNumBlkSide * (uiPosY >> uiShift) + (uiPosX >> uiShift); 1705 if( pcCoef[ posLast ] ) 1706 { 1707 uiSigCoeffGroupFlag[ uiBlkIdx ] = 1; 1708 } 1709 1710 uiNumSig -= ( pcCoef[ posLast ] != 0 ); 1711 } 1712 while ( uiNumSig > 0 ); 1771 UInt uiPosY = posLast >> uiLog2BlockWidth; 1772 UInt uiPosX = posLast - ( uiPosY << uiLog2BlockWidth ); 1773 1774 UInt uiBlkIdx = (codingParameters.widthInGroups * (uiPosY >> MLS_CG_LOG2_HEIGHT)) + (uiPosX >> MLS_CG_LOG2_WIDTH); 1775 uiSigCoeffGroupFlag[ uiBlkIdx ] = 1; 1776 1777 uiNumSig--; 1778 } 1779 } while ( uiNumSig > 0 ); 1713 1780 1714 1781 // Code position of last coefficient 1715 Int posLastY = posLast >> uiLog2Block Size;1716 Int posLastX = posLast - ( posLastY << uiLog2Block Size);1717 codeLastSignificantXY(posLastX, posLastY, uiWidth, uiHeight, eTType, uiScanIdx);1718 1782 Int posLastY = posLast >> uiLog2BlockWidth; 1783 Int posLastX = posLast - ( posLastY << uiLog2BlockWidth ); 1784 codeLastSignificantXY(posLastX, posLastY, uiWidth, uiHeight, compID, codingParameters.scanType); 1785 1719 1786 //===== code significance flag ===== 1720 ContextModel * const baseCoeffGroupCtx = m_cCUSigCoeffGroupSCModel.get( 0, eTType );1721 ContextModel * const baseCtx = (eTType==TEXT_LUMA) ? m_cCUSigSCModel.get( 0, 0 ) : m_cCUSigSCModel.get( 0, 0 ) + NUM_SIG_FLAG_CTX_LUMA;1722 1723 1724 const Int iLastScanSet = scanPosLast >> LOG2_SCAN_SET_SIZE; 1725 UInt c1 = 1;1726 UInt uiGoRiceParam 1727 Int iScanPosSig 1787 ContextModel * const baseCoeffGroupCtx = m_cCUSigCoeffGroupSCModel.get( 0, chType ); 1788 ContextModel * const baseCtx = m_cCUSigSCModel.get( 0, 0 ) + getSignificanceMapContextOffset(compID); 1789 1790 const Int iLastScanSet = scanPosLast >> MLS_CG_SIZE; 1791 1792 UInt c1 = 1; 1793 UInt uiGoRiceParam = 0; 1794 Int iScanPosSig = scanPosLast; 1728 1795 1729 1796 for( Int iSubSet = iLastScanSet; iSubSet >= 0; iSubSet-- ) 1730 1797 { 1731 1798 Int numNonZero = 0; 1732 Int iSubPos = iSubSet << LOG2_SCAN_SET_SIZE;1733 uiGoRiceParam = 0;1734 Int absCoeff[16];1799 Int iSubPos = iSubSet << MLS_CG_SIZE; 1800 uiGoRiceParam = currentGolombRiceStatistic / RExt__GOLOMB_RICE_INCREMENT_DIVISOR; 1801 Bool updateGolombRiceStatistics = bUseGolombRiceParameterAdaptation; //leave the statistics at 0 when not using the adaptation system 1735 1802 UInt coeffSigns = 0; 1736 1803 1737 Int lastNZPosInCG = -1, firstNZPosInCG = SCAN_SET_SIZE; 1804 Int absCoeff[1 << MLS_CG_SIZE]; 1805 1806 Int lastNZPosInCG = -1; 1807 Int firstNZPosInCG = 1 << MLS_CG_SIZE; 1808 1809 Bool escapeDataPresentInGroup = false; 1738 1810 1739 1811 if( iScanPosSig == scanPosLast ) 1740 1812 { 1741 absCoeff[ 0 ] = abs( pcCoef[ posLast ]);1813 absCoeff[ 0 ] = Int(abs( pcCoef[ posLast ] )); 1742 1814 coeffSigns = ( pcCoef[ posLast ] < 0 ); 1743 1815 numNonZero = 1; … … 1747 1819 } 1748 1820 1749 // encode significant_coeffgroup_flag 1750 Int iCGBlkPos = scanCG[ iSubSet ]; 1751 Int iCGPosY = iCGBlkPos / uiNumBlkSide; 1752 Int iCGPosX = iCGBlkPos - (iCGPosY * uiNumBlkSide); 1753 if( iSubSet == iLastScanSet || iSubSet == 0) 1754 { 1755 uiSigCoeffGroupFlag[ iCGBlkPos ] = 1; 1756 } 1757 else 1758 { 1759 UInt uiSigCoeffGroup = (uiSigCoeffGroupFlag[ iCGBlkPos ] != 0); 1760 UInt uiCtxSig = TComTrQuant::getSigCoeffGroupCtxInc( uiSigCoeffGroupFlag, iCGPosX, iCGPosY, uiWidth, uiHeight ); 1761 m_pcBinIf->encodeBin( uiSigCoeffGroup, baseCoeffGroupCtx[ uiCtxSig ] ); 1762 } 1763 1764 // encode significant_coeff_flag 1765 if( uiSigCoeffGroupFlag[ iCGBlkPos ] ) 1766 { 1767 Int patternSigCtx = TComTrQuant::calcPatternSigCtx( uiSigCoeffGroupFlag, iCGPosX, iCGPosY, uiWidth, uiHeight ); 1768 UInt uiBlkPos, uiPosY, uiPosX, uiSig, uiCtxSig; 1769 for( ; iScanPosSig >= iSubPos; iScanPosSig-- ) 1821 // encode significant_coeffgroup_flag 1822 Int iCGBlkPos = codingParameters.scanCG[ iSubSet ]; 1823 Int iCGPosY = iCGBlkPos / codingParameters.widthInGroups; 1824 Int iCGPosX = iCGBlkPos - (iCGPosY * codingParameters.widthInGroups); 1825 1826 if( iSubSet == iLastScanSet || iSubSet == 0) 1827 { 1828 uiSigCoeffGroupFlag[ iCGBlkPos ] = 1; 1829 } 1830 else 1831 { 1832 UInt uiSigCoeffGroup = (uiSigCoeffGroupFlag[ iCGBlkPos ] != 0); 1833 UInt uiCtxSig = TComTrQuant::getSigCoeffGroupCtxInc( uiSigCoeffGroupFlag, iCGPosX, iCGPosY, codingParameters.widthInGroups, codingParameters.heightInGroups ); 1834 m_pcBinIf->encodeBin( uiSigCoeffGroup, baseCoeffGroupCtx[ uiCtxSig ] ); 1835 } 1836 1837 // encode significant_coeff_flag 1838 if( uiSigCoeffGroupFlag[ iCGBlkPos ] ) 1839 { 1840 const Int patternSigCtx = TComTrQuant::calcPatternSigCtx(uiSigCoeffGroupFlag, iCGPosX, iCGPosY, codingParameters.widthInGroups, codingParameters.heightInGroups); 1841 1842 UInt uiBlkPos, uiSig, uiCtxSig; 1843 for( ; iScanPosSig >= iSubPos; iScanPosSig-- ) 1844 { 1845 uiBlkPos = codingParameters.scan[ iScanPosSig ]; 1846 uiSig = (pcCoef[ uiBlkPos ] != 0); 1847 if( iScanPosSig > iSubPos || iSubSet == 0 || numNonZero ) 1770 1848 { 1771 uiBlkPos = scan[ iScanPosSig ]; 1772 uiPosY = uiBlkPos >> uiLog2BlockSize; 1773 uiPosX = uiBlkPos - ( uiPosY << uiLog2BlockSize ); 1774 uiSig = (pcCoef[ uiBlkPos ] != 0); 1775 if( iScanPosSig > iSubPos || iSubSet == 0 || numNonZero ) 1849 uiCtxSig = TComTrQuant::getSigCtxInc( patternSigCtx, codingParameters, iScanPosSig, uiLog2BlockWidth, uiLog2BlockHeight, chType ); 1850 m_pcBinIf->encodeBin( uiSig, baseCtx[ uiCtxSig ] ); 1851 } 1852 if( uiSig ) 1853 { 1854 absCoeff[ numNonZero ] = Int(abs( pcCoef[ uiBlkPos ] )); 1855 coeffSigns = 2 * coeffSigns + ( pcCoef[ uiBlkPos ] < 0 ); 1856 numNonZero++; 1857 if( lastNZPosInCG == -1 ) 1776 1858 { 1777 uiCtxSig = TComTrQuant::getSigCtxInc( patternSigCtx, uiScanIdx, uiPosX, uiPosY, uiLog2BlockSize, eTType ); 1778 m_pcBinIf->encodeBin( uiSig, baseCtx[ uiCtxSig ] ); 1859 lastNZPosInCG = iScanPosSig; 1779 1860 } 1780 if( uiSig ) 1781 { 1782 absCoeff[ numNonZero ] = abs( pcCoef[ uiBlkPos ] ); 1783 coeffSigns = 2 * coeffSigns + ( pcCoef[ uiBlkPos ] < 0 ); 1784 numNonZero++; 1785 if( lastNZPosInCG == -1 ) 1786 { 1787 lastNZPosInCG = iScanPosSig; 1788 } 1789 firstNZPosInCG = iScanPosSig; 1790 } 1861 firstNZPosInCG = iScanPosSig; 1791 1862 } 1792 1863 } 1793 else 1794 { 1795 iScanPosSig = iSubPos - 1; 1796 } 1864 } 1865 else 1866 { 1867 iScanPosSig = iSubPos - 1; 1868 } 1797 1869 1798 1870 if( numNonZero > 0 ) 1799 1871 { 1800 1872 Bool signHidden = ( lastNZPosInCG - firstNZPosInCG >= SBH_THRESHOLD ); 1801 UInt uiCtxSet = (iSubSet > 0 && eTType==TEXT_LUMA) ? 2 : 0; 1802 1803 if( c1 == 0 ) 1804 { 1805 uiCtxSet++; 1806 } 1873 1874 const UInt uiCtxSet = getContextSetIndex(compID, iSubSet, (c1 == 0)); 1807 1875 c1 = 1; 1808 ContextModel *baseCtxMod = ( eTType==TEXT_LUMA ) ? m_cCUOneSCModel.get( 0, 0 ) + 4 * uiCtxSet : m_cCUOneSCModel.get( 0, 0 ) + NUM_ONE_FLAG_CTX_LUMA + 4 * uiCtxSet; 1809 1876 1877 ContextModel *baseCtxMod = m_cCUOneSCModel.get( 0, 0 ) + (NUM_ONE_FLAG_CTX_PER_SET * uiCtxSet); 1878 1810 1879 Int numC1Flag = min(numNonZero, C1FLAG_NUMBER); 1811 1880 Int firstC2FlagIdx = -1; … … 1821 1890 { 1822 1891 firstC2FlagIdx = idx; 1892 } 1893 else //if a greater-than-one has been encountered already this group 1894 { 1895 escapeDataPresentInGroup = true; 1823 1896 } 1824 1897 } … … 1828 1901 } 1829 1902 } 1830 1903 1831 1904 if (c1 == 0) 1832 1905 { 1833 1834 baseCtxMod = ( eTType==TEXT_LUMA ) ? m_cCUAbsSCModel.get( 0, 0 ) + uiCtxSet : m_cCUAbsSCModel.get( 0, 0 ) + NUM_ABS_FLAG_CTX_LUMA + uiCtxSet; 1906 baseCtxMod = m_cCUAbsSCModel.get( 0, 0 ) + (NUM_ABS_FLAG_CTX_PER_SET * uiCtxSet); 1835 1907 if ( firstC2FlagIdx != -1) 1836 1908 { 1837 1909 UInt symbol = absCoeff[ firstC2FlagIdx ] > 2; 1838 1910 m_pcBinIf->encodeBin( symbol, baseCtxMod[0] ); 1911 if (symbol != 0) 1912 { 1913 escapeDataPresentInGroup = true; 1914 } 1839 1915 } 1840 1916 } 1841 1917 1918 escapeDataPresentInGroup = escapeDataPresentInGroup || (numNonZero > C1FLAG_NUMBER); 1919 1920 if (escapeDataPresentInGroup && alignCABACBeforeBypass) 1921 { 1922 m_pcBinIf->align(); 1923 } 1924 1842 1925 if( beValid && signHidden ) 1843 1926 { … … 1848 1931 m_pcBinIf->encodeBinsEP( coeffSigns, numNonZero ); 1849 1932 } 1850 1851 Int iFirstCoeff2 = 1; 1852 if ( c1 == 0 || numNonZero > C1FLAG_NUMBER)1933 1934 Int iFirstCoeff2 = 1; 1935 if (escapeDataPresentInGroup) 1853 1936 { 1854 1937 for ( Int idx = 0; idx < numNonZero; idx++ ) … … 1858 1941 if( absCoeff[ idx ] >= baseLevel) 1859 1942 { 1860 xWriteCoefRemainExGolomb( absCoeff[ idx ] - baseLevel, uiGoRiceParam ); 1861 if(absCoeff[idx] > 3*(1<<uiGoRiceParam)) 1943 const UInt escapeCodeValue = absCoeff[idx] - baseLevel; 1944 1945 xWriteCoefRemainExGolomb( escapeCodeValue, uiGoRiceParam, extendedPrecision, maxLog2TrDynamicRange ); 1946 1947 if (absCoeff[idx] > (3 << uiGoRiceParam)) 1862 1948 { 1863 uiGoRiceParam = min<UInt>(uiGoRiceParam+ 1, 4); 1949 uiGoRiceParam = bUseGolombRiceParameterAdaptation ? (uiGoRiceParam + 1) : (std::min<UInt>((uiGoRiceParam + 1), 4)); 1950 } 1951 1952 if (updateGolombRiceStatistics) 1953 { 1954 const UInt initialGolombRiceParameter = currentGolombRiceStatistic / RExt__GOLOMB_RICE_INCREMENT_DIVISOR; 1955 1956 if (escapeCodeValue >= (3 << initialGolombRiceParameter)) 1957 { 1958 currentGolombRiceStatistic++; 1959 } 1960 else if (((escapeCodeValue * 2) < (1 << initialGolombRiceParameter)) && (currentGolombRiceStatistic > 0)) 1961 { 1962 currentGolombRiceStatistic--; 1963 } 1964 1965 updateGolombRiceStatistics = false; 1864 1966 } 1865 1967 } 1866 if(absCoeff[ idx ] >= 2) 1968 1969 if(absCoeff[ idx ] >= 2) 1867 1970 { 1868 1971 iFirstCoeff2 = 0; 1869 1972 } 1870 } 1871 } 1872 } 1873 } 1973 } 1974 } 1975 } 1976 } 1977 #if ENVIRONMENT_VARIABLE_DEBUG_AND_TEST 1978 printSBACCoeffData(posLastX, posLastY, uiWidth, uiHeight, compID, uiAbsPartIdx, codingParameters.scanType, pcCoef, pcCU->getSlice()->getFinalized()); 1979 #endif 1874 1980 1875 1981 return; … … 1912 2018 } 1913 2019 1914 1915 /** Code SAO EO class or BO band position 1916 * \param uiLength 1917 * \param uiCode 2020 /** Code SAO EO class or BO band position 1918 2021 */ 1919 2022 Void TEncSbac::codeSaoUflc ( UInt uiLength, UInt uiCode ) 1920 2023 { 1921 m_pcBinIf->encodeBinsEP ( uiCode, uiLength ); 1922 } 2024 m_pcBinIf->encodeBinsEP ( uiCode, uiLength ); 2025 } 2026 1923 2027 /** Code SAO merge flags 1924 * \param uiCode1925 * \param uiCompIdx1926 2028 */ 1927 2029 Void TEncSbac::codeSaoMerge ( UInt uiCode ) 1928 2030 { 1929 if (uiCode == 0) 1930 { 1931 m_pcBinIf->encodeBin(0, m_cSaoMergeSCModel.get( 0, 0, 0 )); 1932 } 1933 else 1934 { 1935 m_pcBinIf->encodeBin(1, m_cSaoMergeSCModel.get( 0, 0, 0 )); 1936 } 1937 } 1938 /** Code SAO type index 1939 * \param uiCode 2031 m_pcBinIf->encodeBin(((uiCode == 0) ? 0 : 1), m_cSaoMergeSCModel.get( 0, 0, 0 )); 2032 } 2033 2034 /** Code SAO type index 1940 2035 */ 1941 2036 Void TEncSbac::codeSaoTypeIdx ( UInt uiCode) … … 1951 2046 } 1952 2047 } 2048 2049 Void TEncSbac::codeSAOOffsetParam(ComponentID compIdx, SAOOffset& ctbParam, Bool sliceEnabled, const Int channelBitDepth) 2050 { 2051 UInt uiSymbol; 2052 if(!sliceEnabled) 2053 { 2054 assert(ctbParam.modeIdc == SAO_MODE_OFF); 2055 return; 2056 } 2057 const Bool bIsFirstCompOfChType = (getFirstComponentOfChannel(toChannelType(compIdx)) == compIdx); 2058 2059 //type 2060 if(bIsFirstCompOfChType) 2061 { 2062 //sao_type_idx_luma or sao_type_idx_chroma 2063 if(ctbParam.modeIdc == SAO_MODE_OFF) 2064 { 2065 uiSymbol =0; 2066 } 2067 else if(ctbParam.typeIdc == SAO_TYPE_BO) //BO 2068 { 2069 uiSymbol = 1; 2070 } 2071 else 2072 { 2073 assert(ctbParam.typeIdc < SAO_TYPE_START_BO); //EO 2074 uiSymbol = 2; 2075 } 2076 codeSaoTypeIdx(uiSymbol); 2077 } 2078 2079 if(ctbParam.modeIdc == SAO_MODE_NEW) 2080 { 2081 Int numClasses = (ctbParam.typeIdc == SAO_TYPE_BO)?4:NUM_SAO_EO_CLASSES; 2082 Int offset[4]; 2083 Int k=0; 2084 for(Int i=0; i< numClasses; i++) 2085 { 2086 if(ctbParam.typeIdc != SAO_TYPE_BO && i == SAO_CLASS_EO_PLAIN) 2087 { 2088 continue; 2089 } 2090 Int classIdx = (ctbParam.typeIdc == SAO_TYPE_BO)?( (ctbParam.typeAuxInfo+i)% NUM_SAO_BO_CLASSES ):i; 2091 offset[k] = ctbParam.offset[classIdx]; 2092 k++; 2093 } 2094 2095 const Int maxOffsetQVal = TComSampleAdaptiveOffset::getMaxOffsetQVal(channelBitDepth); 2096 for(Int i=0; i< 4; i++) 2097 { 2098 codeSaoMaxUvlc((offset[i]<0)?(-offset[i]):(offset[i]), maxOffsetQVal ); //sao_offset_abs 2099 } 2100 2101 2102 if(ctbParam.typeIdc == SAO_TYPE_BO) 2103 { 2104 for(Int i=0; i< 4; i++) 2105 { 2106 if(offset[i] != 0) 2107 { 2108 codeSAOSign((offset[i]< 0)?1:0); 2109 } 2110 } 2111 2112 codeSaoUflc(NUM_SAO_BO_CLASSES_LOG2, ctbParam.typeAuxInfo ); //sao_band_position 2113 } 2114 else //EO 2115 { 2116 if(bIsFirstCompOfChType) 2117 { 2118 assert(ctbParam.typeIdc - SAO_TYPE_START_EO >=0); 2119 codeSaoUflc(NUM_SAO_EO_TYPES_LOG2, ctbParam.typeIdc - SAO_TYPE_START_EO ); //sao_eo_class_luma or sao_eo_class_chroma 2120 } 2121 } 2122 2123 } 2124 } 2125 2126 2127 Void TEncSbac::codeSAOBlkParam(SAOBlkParam& saoBlkParam, const BitDepths &bitDepths 2128 , Bool* sliceEnabled 2129 , Bool leftMergeAvail 2130 , Bool aboveMergeAvail 2131 , Bool onlyEstMergeInfo // = false 2132 ) 2133 { 2134 2135 Bool isLeftMerge = false; 2136 Bool isAboveMerge= false; 2137 2138 if(leftMergeAvail) 2139 { 2140 isLeftMerge = ((saoBlkParam[COMPONENT_Y].modeIdc == SAO_MODE_MERGE) && (saoBlkParam[COMPONENT_Y].typeIdc == SAO_MERGE_LEFT)); 2141 codeSaoMerge( isLeftMerge?1:0 ); //sao_merge_left_flag 2142 } 2143 2144 if( aboveMergeAvail && !isLeftMerge) 2145 { 2146 isAboveMerge = ((saoBlkParam[COMPONENT_Y].modeIdc == SAO_MODE_MERGE) && (saoBlkParam[COMPONENT_Y].typeIdc == SAO_MERGE_ABOVE)); 2147 codeSaoMerge( isAboveMerge?1:0 ); //sao_merge_left_flag 2148 } 2149 2150 if(onlyEstMergeInfo) 2151 { 2152 return; //only for RDO 2153 } 2154 2155 if(!isLeftMerge && !isAboveMerge) //not merge mode 2156 { 2157 for(Int compIdx=0; compIdx < MAX_NUM_COMPONENT; compIdx++) 2158 { 2159 codeSAOOffsetParam(ComponentID(compIdx), saoBlkParam[compIdx], sliceEnabled[compIdx], bitDepths.recon[toChannelType(ComponentID(compIdx))]); 2160 } 2161 } 2162 } 2163 1953 2164 /*! 1954 2165 **************************************************************************** … … 1957 2168 **************************************************************************** 1958 2169 */ 1959 Void TEncSbac::estBit( estBitsSbacStruct* pcEstBitsSbac, Int width, Int height, TextType eTType )2170 Void TEncSbac::estBit( estBitsSbacStruct* pcEstBitsSbac, Int width, Int height, ChannelType chType ) 1960 2171 { 1961 2172 estCBFBit( pcEstBitsSbac ); 1962 2173 1963 estSignificantCoeffGroupMapBit( pcEstBitsSbac, eTType );1964 2174 estSignificantCoeffGroupMapBit( pcEstBitsSbac, chType ); 2175 1965 2176 // encode significance map 1966 estSignificantMapBit( pcEstBitsSbac, width, height, eTType ); 1967 2177 estSignificantMapBit( pcEstBitsSbac, width, height, chType ); 2178 2179 // encode last significant position 2180 estLastSignificantPositionBit( pcEstBitsSbac, width, height, chType ); 2181 1968 2182 // encode significant coefficients 1969 estSignificantCoefficientsBit( pcEstBitsSbac, eTType ); 2183 estSignificantCoefficientsBit( pcEstBitsSbac, chType ); 2184 2185 memcpy(pcEstBitsSbac->golombRiceAdaptationStatistics, m_golombRiceAdaptationStatistics, (sizeof(UInt) * RExt__GOLOMB_RICE_ADAPTATION_STATISTICS_SETS)); 1970 2186 } 1971 2187 … … 1980 2196 ContextModel *pCtx = m_cCUQtCbfSCModel.get( 0 ); 1981 2197 1982 for( UInt uiCtxInc = 0; uiCtxInc < 3*NUM_QT_CBF_CTX; uiCtxInc++ )2198 for( UInt uiCtxInc = 0; uiCtxInc < (NUM_QT_CBF_CTX_SETS * NUM_QT_CBF_CTX_PER_SET); uiCtxInc++ ) 1983 2199 { 1984 2200 pcEstBitsSbac->blockCbpBits[ uiCtxInc ][ 0 ] = pCtx[ uiCtxInc ].getEntropyBits( 0 ); … … 1987 2203 1988 2204 pCtx = m_cCUQtRootCbfSCModel.get( 0 ); 1989 2205 1990 2206 for( UInt uiCtxInc = 0; uiCtxInc < 4; uiCtxInc++ ) 1991 2207 { … … 2002 2218 **************************************************************************** 2003 2219 */ 2004 Void TEncSbac::estSignificantCoeffGroupMapBit( estBitsSbacStruct* pcEstBitsSbac, TextType eTType )2220 Void TEncSbac::estSignificantCoeffGroupMapBit( estBitsSbacStruct* pcEstBitsSbac, ChannelType chType ) 2005 2221 { 2006 2222 Int firstCtx = 0, numCtx = NUM_SIG_CG_FLAG_CTX; … … 2010 2226 for( UInt uiBin = 0; uiBin < 2; uiBin++ ) 2011 2227 { 2012 pcEstBitsSbac->significantCoeffGroupBits[ ctxIdx ][ uiBin ] = m_cCUSigCoeffGroupSCModel.get( 0, eTType, ctxIdx ).getEntropyBits( uiBin );2228 pcEstBitsSbac->significantCoeffGroupBits[ ctxIdx ][ uiBin ] = m_cCUSigCoeffGroupSCModel.get( 0, chType, ctxIdx ).getEntropyBits( uiBin ); 2013 2229 } 2014 2230 } … … 2022 2238 **************************************************************************** 2023 2239 */ 2024 Void TEncSbac::estSignificantMapBit( estBitsSbacStruct* pcEstBitsSbac, Int width, Int height, TextType eTType ) 2025 { 2026 Int firstCtx = 1, numCtx = 8; 2027 if (max(width, height) >= 16) 2028 { 2029 firstCtx = (eTType == TEXT_LUMA) ? 21 : 12; 2030 numCtx = (eTType == TEXT_LUMA) ? 6 : 3; 2031 } 2032 else if (width == 8) 2033 { 2034 firstCtx = 9; 2035 numCtx = (eTType == TEXT_LUMA) ? 12 : 3; 2036 } 2037 2038 if (eTType == TEXT_LUMA ) 2039 { 2240 Void TEncSbac::estSignificantMapBit( estBitsSbacStruct* pcEstBitsSbac, Int width, Int height, ChannelType chType ) 2241 { 2242 //-------------------------------------------------------------------------------------------------- 2243 2244 //set up the number of channels and context variables 2245 2246 const UInt firstComponent = ((isLuma(chType)) ? (COMPONENT_Y) : (COMPONENT_Cb)); 2247 const UInt lastComponent = ((isLuma(chType)) ? (COMPONENT_Y) : (COMPONENT_Cb)); 2248 2249 //---------------------------------------------------------- 2250 2251 Int firstCtx = MAX_INT; 2252 Int numCtx = MAX_INT; 2253 2254 if ((width == 4) && (height == 4)) 2255 { 2256 firstCtx = significanceMapContextSetStart[chType][CONTEXT_TYPE_4x4]; 2257 numCtx = significanceMapContextSetSize [chType][CONTEXT_TYPE_4x4]; 2258 } 2259 else if ((width == 8) && (height == 8)) 2260 { 2261 firstCtx = significanceMapContextSetStart[chType][CONTEXT_TYPE_8x8]; 2262 numCtx = significanceMapContextSetSize [chType][CONTEXT_TYPE_8x8]; 2263 } 2264 else 2265 { 2266 firstCtx = significanceMapContextSetStart[chType][CONTEXT_TYPE_NxN]; 2267 numCtx = significanceMapContextSetSize [chType][CONTEXT_TYPE_NxN]; 2268 } 2269 2270 //-------------------------------------------------------------------------------------------------- 2271 2272 //fill the data for the significace map 2273 2274 for (UInt component = firstComponent; component <= lastComponent; component++) 2275 { 2276 const UInt contextOffset = getSignificanceMapContextOffset(ComponentID(component)); 2277 2278 if (firstCtx > 0) 2279 { 2280 for( UInt bin = 0; bin < 2; bin++ ) //always get the DC 2281 { 2282 pcEstBitsSbac->significantBits[ contextOffset ][ bin ] = m_cCUSigSCModel.get( 0, 0, contextOffset ).getEntropyBits( bin ); 2283 } 2284 } 2285 2286 // This could be made optional, but would require this function to have knowledge of whether the 2287 // TU is transform-skipped or transquant-bypassed and whether the SPS flag is set 2040 2288 for( UInt bin = 0; bin < 2; bin++ ) 2041 2289 { 2042 pcEstBitsSbac->significantBits[ 0 ][ bin ] = m_cCUSigSCModel.get( 0, 0, 0 ).getEntropyBits( bin ); 2290 const Int ctxIdx = significanceMapContextSetStart[chType][CONTEXT_TYPE_SINGLE]; 2291 pcEstBitsSbac->significantBits[ contextOffset + ctxIdx ][ bin ] = m_cCUSigSCModel.get( 0, 0, (contextOffset + ctxIdx) ).getEntropyBits( bin ); 2043 2292 } 2044 2293 … … 2047 2296 for( UInt uiBin = 0; uiBin < 2; uiBin++ ) 2048 2297 { 2049 pcEstBitsSbac->significantBits[ ctxIdx ][ uiBin ] = m_cCUSigSCModel.get( 0, 0, ctxIdx ).getEntropyBits( uiBin ); 2050 } 2051 } 2052 } 2053 else 2054 { 2055 for( UInt bin = 0; bin < 2; bin++ ) 2056 { 2057 pcEstBitsSbac->significantBits[ 0 ][ bin ] = m_cCUSigSCModel.get( 0, 0, NUM_SIG_FLAG_CTX_LUMA + 0 ).getEntropyBits( bin ); 2058 } 2059 for ( Int ctxIdx = firstCtx; ctxIdx < firstCtx + numCtx; ctxIdx++ ) 2060 { 2061 for( UInt uiBin = 0; uiBin < 2; uiBin++ ) 2062 { 2063 pcEstBitsSbac->significantBits[ ctxIdx ][ uiBin ] = m_cCUSigSCModel.get( 0, 0, NUM_SIG_FLAG_CTX_LUMA + ctxIdx ).getEntropyBits( uiBin ); 2064 } 2065 } 2066 } 2067 Int iBitsX = 0, iBitsY = 0; 2068 Int blkSizeOffsetX, blkSizeOffsetY, shiftX, shiftY; 2069 2070 blkSizeOffsetX = eTType ? 0: (g_aucConvertToBit[ width ] *3 + ((g_aucConvertToBit[ width ] +1)>>2)); 2071 blkSizeOffsetY = eTType ? 0: (g_aucConvertToBit[ height ]*3 + ((g_aucConvertToBit[ height ]+1)>>2)); 2072 shiftX = eTType ? g_aucConvertToBit[ width ] :((g_aucConvertToBit[ width ]+3)>>2); 2073 shiftY = eTType ? g_aucConvertToBit[ height ] :((g_aucConvertToBit[ height ]+3)>>2); 2074 2075 Int ctx; 2076 ContextModel *pCtxX = m_cCuCtxLastX.get( 0, eTType ); 2077 for (ctx = 0; ctx < g_uiGroupIdx[ width - 1 ]; ctx++) 2078 { 2079 Int ctxOffset = blkSizeOffsetX + (ctx >>shiftX); 2080 pcEstBitsSbac->lastXBits[ ctx ] = iBitsX + pCtxX[ ctxOffset ].getEntropyBits( 0 ); 2081 iBitsX += pCtxX[ ctxOffset ].getEntropyBits( 1 ); 2082 } 2083 pcEstBitsSbac->lastXBits[ctx] = iBitsX; 2084 ContextModel *pCtxY = m_cCuCtxLastY.get( 0, eTType ); 2085 for (ctx = 0; ctx < g_uiGroupIdx[ height - 1 ]; ctx++) 2086 { 2087 Int ctxOffset = blkSizeOffsetY + (ctx >>shiftY); 2088 pcEstBitsSbac->lastYBits[ ctx ] = iBitsY + pCtxY[ ctxOffset ].getEntropyBits( 0 ); 2089 iBitsY += pCtxY[ ctxOffset ].getEntropyBits( 1 ); 2090 } 2091 pcEstBitsSbac->lastYBits[ctx] = iBitsY; 2092 } 2298 pcEstBitsSbac->significantBits[ contextOffset + ctxIdx ][ uiBin ] = m_cCUSigSCModel.get( 0, 0, (contextOffset + ctxIdx) ).getEntropyBits( uiBin ); 2299 } 2300 } 2301 } 2302 2303 //-------------------------------------------------------------------------------------------------- 2304 } 2305 2093 2306 2094 2307 /*! … … 2098 2311 **************************************************************************** 2099 2312 */ 2100 Void TEncSbac::estSignificantCoefficientsBit( estBitsSbacStruct* pcEstBitsSbac, TextType eTType ) 2101 { 2102 if (eTType==TEXT_LUMA) 2103 { 2104 ContextModel *ctxOne = m_cCUOneSCModel.get(0, 0); 2105 ContextModel *ctxAbs = m_cCUAbsSCModel.get(0, 0); 2106 2107 for (Int ctxIdx = 0; ctxIdx < NUM_ONE_FLAG_CTX_LUMA; ctxIdx++) 2108 { 2109 pcEstBitsSbac->m_greaterOneBits[ ctxIdx ][ 0 ] = ctxOne[ ctxIdx ].getEntropyBits( 0 ); 2110 pcEstBitsSbac->m_greaterOneBits[ ctxIdx ][ 1 ] = ctxOne[ ctxIdx ].getEntropyBits( 1 ); 2111 } 2112 2113 for (Int ctxIdx = 0; ctxIdx < NUM_ABS_FLAG_CTX_LUMA; ctxIdx++) 2114 { 2115 pcEstBitsSbac->m_levelAbsBits[ ctxIdx ][ 0 ] = ctxAbs[ ctxIdx ].getEntropyBits( 0 ); 2116 pcEstBitsSbac->m_levelAbsBits[ ctxIdx ][ 1 ] = ctxAbs[ ctxIdx ].getEntropyBits( 1 ); 2117 } 2118 } 2119 else 2120 { 2121 ContextModel *ctxOne = m_cCUOneSCModel.get(0, 0) + NUM_ONE_FLAG_CTX_LUMA; 2122 ContextModel *ctxAbs = m_cCUAbsSCModel.get(0, 0) + NUM_ABS_FLAG_CTX_LUMA; 2123 2124 for (Int ctxIdx = 0; ctxIdx < NUM_ONE_FLAG_CTX_CHROMA; ctxIdx++) 2125 { 2126 pcEstBitsSbac->m_greaterOneBits[ ctxIdx ][ 0 ] = ctxOne[ ctxIdx ].getEntropyBits( 0 ); 2127 pcEstBitsSbac->m_greaterOneBits[ ctxIdx ][ 1 ] = ctxOne[ ctxIdx ].getEntropyBits( 1 ); 2128 } 2129 2130 for (Int ctxIdx = 0; ctxIdx < NUM_ABS_FLAG_CTX_CHROMA; ctxIdx++) 2131 { 2132 pcEstBitsSbac->m_levelAbsBits[ ctxIdx ][ 0 ] = ctxAbs[ ctxIdx ].getEntropyBits( 0 ); 2133 pcEstBitsSbac->m_levelAbsBits[ ctxIdx ][ 1 ] = ctxAbs[ ctxIdx ].getEntropyBits( 1 ); 2134 } 2313 2314 Void TEncSbac::estLastSignificantPositionBit( estBitsSbacStruct* pcEstBitsSbac, Int width, Int height, ChannelType chType ) 2315 { 2316 //--------------------------------------------------------------------------------------------------. 2317 2318 //set up the number of channels 2319 2320 const UInt firstComponent = ((isLuma(chType)) ? (COMPONENT_Y) : (COMPONENT_Cb)); 2321 const UInt lastComponent = ((isLuma(chType)) ? (COMPONENT_Y) : (COMPONENT_Cb)); 2322 2323 //-------------------------------------------------------------------------------------------------- 2324 2325 //fill the data for the last-significant-coefficient position 2326 2327 for (UInt componentIndex = firstComponent; componentIndex <= lastComponent; componentIndex++) 2328 { 2329 const ComponentID component = ComponentID(componentIndex); 2330 2331 Int iBitsX = 0, iBitsY = 0; 2332 2333 Int blkSizeOffsetX, blkSizeOffsetY, shiftX, shiftY; 2334 getLastSignificantContextParameters(ComponentID(component), width, height, blkSizeOffsetX, blkSizeOffsetY, shiftX, shiftY); 2335 2336 Int ctx; 2337 2338 const ChannelType channelType = toChannelType(ComponentID(component)); 2339 2340 ContextModel *const pCtxX = m_cCuCtxLastX.get( 0, channelType ); 2341 ContextModel *const pCtxY = m_cCuCtxLastY.get( 0, channelType ); 2342 Int *const lastXBitsArray = pcEstBitsSbac->lastXBits[channelType]; 2343 Int *const lastYBitsArray = pcEstBitsSbac->lastYBits[channelType]; 2344 2345 //------------------------------------------------ 2346 2347 //X-coordinate 2348 2349 for (ctx = 0; ctx < g_uiGroupIdx[ width - 1 ]; ctx++) 2350 { 2351 Int ctxOffset = blkSizeOffsetX + (ctx >>shiftX); 2352 lastXBitsArray[ ctx ] = iBitsX + pCtxX[ ctxOffset ].getEntropyBits( 0 ); 2353 iBitsX += pCtxX[ ctxOffset ].getEntropyBits( 1 ); 2354 } 2355 2356 lastXBitsArray[ctx] = iBitsX; 2357 2358 //------------------------------------------------ 2359 2360 //Y-coordinate 2361 2362 for (ctx = 0; ctx < g_uiGroupIdx[ height - 1 ]; ctx++) 2363 { 2364 Int ctxOffset = blkSizeOffsetY + (ctx >>shiftY); 2365 lastYBitsArray[ ctx ] = iBitsY + pCtxY[ ctxOffset ].getEntropyBits( 0 ); 2366 iBitsY += pCtxY[ ctxOffset ].getEntropyBits( 1 ); 2367 } 2368 2369 lastYBitsArray[ctx] = iBitsY; 2370 2371 } //end of component loop 2372 2373 //-------------------------------------------------------------------------------------------------- 2374 } 2375 2376 2377 /*! 2378 **************************************************************************** 2379 * \brief 2380 * estimate bit cost of significant coefficient 2381 **************************************************************************** 2382 */ 2383 Void TEncSbac::estSignificantCoefficientsBit( estBitsSbacStruct* pcEstBitsSbac, ChannelType chType ) 2384 { 2385 ContextModel *ctxOne = m_cCUOneSCModel.get(0, 0); 2386 ContextModel *ctxAbs = m_cCUAbsSCModel.get(0, 0); 2387 2388 const UInt oneStartIndex = ((isLuma(chType)) ? (0) : (NUM_ONE_FLAG_CTX_LUMA)); 2389 const UInt oneStopIndex = ((isLuma(chType)) ? (NUM_ONE_FLAG_CTX_LUMA) : (NUM_ONE_FLAG_CTX)); 2390 const UInt absStartIndex = ((isLuma(chType)) ? (0) : (NUM_ABS_FLAG_CTX_LUMA)); 2391 const UInt absStopIndex = ((isLuma(chType)) ? (NUM_ABS_FLAG_CTX_LUMA) : (NUM_ABS_FLAG_CTX)); 2392 2393 for (Int ctxIdx = oneStartIndex; ctxIdx < oneStopIndex; ctxIdx++) 2394 { 2395 pcEstBitsSbac->m_greaterOneBits[ ctxIdx ][ 0 ] = ctxOne[ ctxIdx ].getEntropyBits( 0 ); 2396 pcEstBitsSbac->m_greaterOneBits[ ctxIdx ][ 1 ] = ctxOne[ ctxIdx ].getEntropyBits( 1 ); 2397 } 2398 2399 for (Int ctxIdx = absStartIndex; ctxIdx < absStopIndex; ctxIdx++) 2400 { 2401 pcEstBitsSbac->m_levelAbsBits[ ctxIdx ][ 0 ] = ctxAbs[ ctxIdx ].getEntropyBits( 0 ); 2402 pcEstBitsSbac->m_levelAbsBits[ ctxIdx ][ 1 ] = ctxAbs[ ctxIdx ].getEntropyBits( 1 ); 2135 2403 } 2136 2404 } … … 2141 2409 \param pSrc From where to copy context information. 2142 2410 */ 2143 Void TEncSbac::xCopyContextsFrom( TEncSbac* pSrc )2144 { 2411 Void TEncSbac::xCopyContextsFrom( const TEncSbac* pSrc ) 2412 { 2145 2413 memcpy(m_contextModels, pSrc->m_contextModels, m_numContextModels*sizeof(m_contextModels[0])); 2146 } 2147 2148 Void TEncSbac::loadContexts ( TEncSbac* pScr) 2149 { 2150 this->xCopyContextsFrom(pScr); 2151 } 2152 2153 Void TEncSbac::codeSAOOffsetParam(Int compIdx, SAOOffset& ctbParam, Bool sliceEnabled) 2154 { 2155 UInt uiSymbol; 2156 if(!sliceEnabled) 2157 { 2158 assert(ctbParam.modeIdc == SAO_MODE_OFF); 2159 return; 2160 } 2161 2162 //type 2163 if(compIdx == SAO_Y || compIdx == SAO_Cb) 2164 { 2165 //sao_type_idx_luma or sao_type_idx_chroma 2166 if(ctbParam.modeIdc == SAO_MODE_OFF) 2167 { 2168 uiSymbol =0; 2169 } 2170 else if(ctbParam.typeIdc == SAO_TYPE_BO) //BO 2171 { 2172 uiSymbol = 1; 2414 memcpy(m_golombRiceAdaptationStatistics, pSrc->m_golombRiceAdaptationStatistics, (sizeof(UInt) * RExt__GOLOMB_RICE_ADAPTATION_STATISTICS_SETS)); 2415 } 2416 2417 Void TEncSbac::loadContexts ( const TEncSbac* pSrc) 2418 { 2419 xCopyContextsFrom(pSrc); 2420 } 2421 2422 /** Performs CABAC encoding of the explicit RDPCM mode 2423 * \param rTu current TU data structure 2424 * \param compID component identifier 2425 */ 2426 Void TEncSbac::codeExplicitRdpcmMode( TComTU &rTu, const ComponentID compID ) 2427 { 2428 TComDataCU *cu = rTu.getCU(); 2429 const TComRectangle &rect = rTu.getRect(compID); 2430 const UInt absPartIdx = rTu.GetAbsPartIdxTU(compID); 2431 const UInt tuHeight = g_aucConvertToBit[rect.height]; 2432 const UInt tuWidth = g_aucConvertToBit[rect.width]; 2433 2434 assert(tuHeight == tuWidth); 2435 assert(tuHeight < 4); 2436 2437 UInt explicitRdpcmMode = cu->getExplicitRdpcmMode(compID, absPartIdx); 2438 2439 if( explicitRdpcmMode == RDPCM_OFF ) 2440 { 2441 m_pcBinIf->encodeBin (0, m_explicitRdpcmFlagSCModel.get (0, toChannelType(compID), 0)); 2442 } 2443 else if( explicitRdpcmMode == RDPCM_HOR || explicitRdpcmMode == RDPCM_VER ) 2444 { 2445 m_pcBinIf->encodeBin (1, m_explicitRdpcmFlagSCModel.get (0, toChannelType(compID), 0)); 2446 if(explicitRdpcmMode == RDPCM_HOR) 2447 { 2448 m_pcBinIf->encodeBin ( 0, m_explicitRdpcmDirSCModel.get(0, toChannelType(compID), 0)); 2173 2449 } 2174 2450 else 2175 2451 { 2176 assert(ctbParam.typeIdc < SAO_TYPE_START_BO); //EO 2177 uiSymbol = 2; 2178 } 2179 codeSaoTypeIdx(uiSymbol); 2180 } 2181 2182 if(ctbParam.modeIdc == SAO_MODE_NEW) 2183 { 2184 Int numClasses = (ctbParam.typeIdc == SAO_TYPE_BO)?4:NUM_SAO_EO_CLASSES; 2185 Int offset[4]; 2186 Int k=0; 2187 for(Int i=0; i< numClasses; i++) 2188 { 2189 if(ctbParam.typeIdc != SAO_TYPE_BO && i == SAO_CLASS_EO_PLAIN) 2190 { 2191 continue; 2192 } 2193 Int classIdx = (ctbParam.typeIdc == SAO_TYPE_BO)?( (ctbParam.typeAuxInfo+i)% NUM_SAO_BO_CLASSES ):i; 2194 offset[k] = ctbParam.offset[classIdx]; 2195 k++; 2196 } 2197 2198 for(Int i=0; i< 4; i++) 2199 { 2200 codeSaoMaxUvlc((offset[i]<0)?(-offset[i]):(offset[i]), g_saoMaxOffsetQVal[compIdx] ); //sao_offset_abs 2201 } 2202 2203 2204 if(ctbParam.typeIdc == SAO_TYPE_BO) 2205 { 2206 for(Int i=0; i< 4; i++) 2207 { 2208 if(offset[i] != 0) 2452 m_pcBinIf->encodeBin ( 1, m_explicitRdpcmDirSCModel.get(0, toChannelType(compID), 0)); 2453 } 2454 } 2455 else 2456 { 2457 assert(0); 2458 } 2459 } 2460 2461 #if NH_3D_DMM || NH_3D_SDC_INTRA || NH_3D_SDC_INTER 2462 Void TEncSbac::codeDeltaDC( TComDataCU* pcCU, UInt absPartIdx ) 2463 { 2464 #if NH_3D_SDC_INTRA || NH_3D_SDC_INTER 2465 if( !(pcCU->getSDCFlag( absPartIdx )) ) 2466 #endif 2467 #if NH_3D_DMM 2468 if( !(pcCU->isIntra( absPartIdx ) && isDmmMode( pcCU->getIntraDir( CHANNEL_TYPE_LUMA, absPartIdx ) )) ) 2469 #endif 2470 assert( 0 ); 2471 2472 UInt uiNumSegments = 1; 2473 #if NH_3D_DMM 2474 uiNumSegments = isDmmMode( pcCU->getIntraDir( CHANNEL_TYPE_LUMA, absPartIdx ) ) ? 2 : 1; 2475 #endif 2476 2477 UInt hasDeltaDC = 1; 2478 #if NH_3D_SDC_INTRA 2479 if( pcCU->isIntra( absPartIdx ) && pcCU->getSDCFlag( absPartIdx )) 2480 { 2481 if( uiNumSegments == 1 ) 2482 { 2483 hasDeltaDC = pcCU->getSDCSegmentDCOffset( 0, absPartIdx ) ? 1 : 0; 2484 } 2485 else 2486 { 2487 hasDeltaDC = ( pcCU->getSDCSegmentDCOffset( 0, absPartIdx ) || pcCU->getSDCSegmentDCOffset( 1, absPartIdx ) ) ? 1 : 0; 2488 } 2489 m_pcBinIf->encodeBin( hasDeltaDC, m_cDdcFlagSCModel.get( 0, 0, 0 ) ); 2490 } 2491 #endif 2492 2493 if( hasDeltaDC ) 2494 { 2495 for( UInt segment = 0; segment < uiNumSegments; segment++ ) 2496 { 2497 Pel deltaDC = 0; 2498 if( pcCU->isIntra( absPartIdx ) ) 2499 { 2500 #if NH_3D_SDC_INTRA 2501 if( pcCU->getSDCFlag( absPartIdx ) ) 2209 2502 { 2210 codeSAOSign((offset[i]< 0)?1:0);2503 deltaDC = pcCU->getSDCSegmentDCOffset( segment, absPartIdx ); 2211 2504 } 2212 } 2213 2214 codeSaoUflc(NUM_SAO_BO_CLASSES_LOG2, ctbParam.typeAuxInfo ); //sao_band_position 2215 } 2216 else //EO 2217 { 2218 if(compIdx == SAO_Y || compIdx == SAO_Cb) 2219 { 2220 assert(ctbParam.typeIdc - SAO_TYPE_START_EO >=0); 2221 codeSaoUflc(NUM_SAO_EO_TYPES_LOG2, ctbParam.typeIdc - SAO_TYPE_START_EO ); //sao_eo_class_luma or sao_eo_class_chroma 2222 } 2223 } 2224 2225 } 2226 } 2227 2228 2229 Void TEncSbac::codeSAOBlkParam(SAOBlkParam& saoBlkParam 2230 , Bool* sliceEnabled 2231 , Bool leftMergeAvail 2232 , Bool aboveMergeAvail 2233 , Bool onlyEstMergeInfo // = false 2234 ) 2235 { 2236 2237 Bool isLeftMerge = false; 2238 Bool isAboveMerge= false; 2239 2240 if(leftMergeAvail) 2241 { 2242 isLeftMerge = ((saoBlkParam[SAO_Y].modeIdc == SAO_MODE_MERGE) && (saoBlkParam[SAO_Y].typeIdc == SAO_MERGE_LEFT)); 2243 codeSaoMerge( isLeftMerge?1:0 ); //sao_merge_left_flag 2244 } 2245 2246 if( aboveMergeAvail && !isLeftMerge) 2247 { 2248 isAboveMerge = ((saoBlkParam[SAO_Y].modeIdc == SAO_MODE_MERGE) && (saoBlkParam[SAO_Y].typeIdc == SAO_MERGE_ABOVE)); 2249 codeSaoMerge( isAboveMerge?1:0 ); //sao_merge_left_flag 2250 } 2251 2252 if(onlyEstMergeInfo) 2253 { 2254 return; //only for RDO 2255 } 2256 2257 if(!isLeftMerge && !isAboveMerge) //not merge mode 2258 { 2259 for(Int compIdx=0; compIdx < NUM_SAO_COMPONENTS; compIdx++) 2260 { 2261 codeSAOOffsetParam(compIdx, saoBlkParam[compIdx], sliceEnabled[compIdx]); 2262 } 2263 } 2264 } 2265 2266 #if H_3D_INTER_SDC 2267 Void TEncSbac::codeDeltaDC( TComDataCU* pcCU, UInt absPartIdx ) 2268 { 2269 if( !( pcCU->getSDCFlag( absPartIdx ) || ( pcCU->isIntra( absPartIdx ) && getDimType( pcCU->getLumaIntraDir( absPartIdx ) ) < DIM_NUM_TYPE ) ) ) 2270 { 2271 assert( 0 ); 2272 } 2273 2274 UInt uiNumSegments = isDimMode( pcCU->getLumaIntraDir( absPartIdx ) ) ? 2 : 1; 2275 UInt dimDeltaDC = 1; 2276 2277 if( pcCU->isIntra( absPartIdx ) && pcCU->getSDCFlag( absPartIdx )) 2278 { 2279 if( uiNumSegments == 1 ) 2280 { 2281 dimDeltaDC = pcCU->getSDCSegmentDCOffset( 0, absPartIdx ) ? 1 : 0; 2282 } 2505 else 2506 { 2507 #endif 2508 #if NH_3D_DMM 2509 deltaDC = pcCU->getDmmDeltaDC( getDmmType( pcCU->getIntraDir( CHANNEL_TYPE_LUMA, absPartIdx ) ), segment, absPartIdx ); 2510 #endif 2511 #if NH_3D_SDC_INTRA 2512 } 2513 #endif 2514 } 2515 #if NH_3D_SDC_INTER 2283 2516 else 2284 2517 { 2285 dimDeltaDC = ( pcCU->getSDCSegmentDCOffset( 0, absPartIdx ) || pcCU->getSDCSegmentDCOffset( 1, absPartIdx ) ) ? 1 : 0;2286 }2287 m_pcBinIf->encodeBin( dimDeltaDC, m_cDdcFlagSCModel.get( 0, 0, 0 ) );2288 }2289 2290 if( dimDeltaDC )2291 {2292 for( UInt segment = 0; segment < uiNumSegments; segment++ )2293 {2294 Pel deltaDC = 0;2295 2296 if( pcCU->isIntra( absPartIdx ) )2297 {2298 UInt dir = pcCU->getLumaIntraDir( absPartIdx );2299 deltaDC = pcCU->getSDCFlag( absPartIdx ) ? pcCU->getSDCSegmentDCOffset( segment, absPartIdx ) : pcCU->getDimDeltaDC( getDimType( dir ), segment, absPartIdx );2300 }2301 else2302 {2303 2518 deltaDC = pcCU->getSDCSegmentDCOffset( segment, absPartIdx ); 2304 2519 } 2305 2306 xCodeDimDeltaDC( deltaDC, uiNumSegments ); 2307 } 2308 } 2309 } 2310 2520 #endif 2521 xCodeDeltaDC( deltaDC, uiNumSegments ); 2522 } 2523 } 2524 } 2525 2526 Void TEncSbac::xCodeDeltaDC( Pel valDeltaDC, UInt uiNumSeg ) 2527 { 2528 #if ENC_DEC_TRACE && H_MV_ENC_DEC_TRAC 2529 DTRACE_CU("delta_dc", valDeltaDC); 2530 #endif 2531 xWriteExGolombLevelDdc( UInt( abs( valDeltaDC ) - ( uiNumSeg > 1 ? 0 : 1 ) ) ); 2532 if( valDeltaDC != 0 ) 2533 { 2534 UInt uiSign = valDeltaDC > 0 ? 0 : 1; 2535 m_pcBinIf->encodeBinEP( uiSign ); 2536 } 2537 } 2538 2539 Void TEncSbac::xWriteExGolombLevelDdc( UInt uiSymbol ) 2540 { 2541 if( uiSymbol ) 2542 { 2543 m_pcBinIf->encodeBin( 1, m_cDdcDataSCModel.get(0, 0, 0) ); 2544 UInt uiCount = 0; 2545 Bool bNoExGo = ( uiSymbol < 3 ); 2546 2547 while( --uiSymbol && ++uiCount < 3 ) 2548 { 2549 m_pcBinIf->encodeBin( 1, m_cDdcDataSCModel.get(0, 0, 0) ); 2550 } 2551 if( bNoExGo ) 2552 { 2553 m_pcBinIf->encodeBin( 0, m_cDdcDataSCModel.get(0, 0, 0) ); 2554 } 2555 else 2556 { 2557 xWriteEpExGolomb( uiSymbol, 0 ); 2558 } 2559 } 2560 else 2561 { 2562 m_pcBinIf->encodeBin( 0, m_cDdcDataSCModel.get(0, 0, 0) ); 2563 } 2564 2565 return; 2566 } 2567 #endif 2568 2569 #if NH_3D_DMM 2570 Void TEncSbac::xCodeIntraDepthMode( TComDataCU* pcCU, UInt absPartIdx ) 2571 { 2572 UInt dir = pcCU->getIntraDir( CHANNEL_TYPE_LUMA, absPartIdx ); 2573 2574 if( ( pcCU->getSlice()->getSPS()->getMaxCUWidth() >> pcCU->getDepth( absPartIdx ) ) < 64 ) //DMM and HEVC intra modes are both allowed 2575 { 2576 m_pcBinIf->encodeBin( isDmmMode( dir ) ? 0 : 1, m_cNotDmmFlagSCModel.get( 0, 0, 0 ) ); 2577 } 2578 if( isDmmMode( dir ) ) 2579 { 2580 UInt uiCodeIdx = 0; 2581 2582 switch( getDmmType( dir ) ) 2583 { 2584 case DMM1_IDX: uiCodeIdx = 0; break; 2585 case DMM4_IDX: uiCodeIdx = 1; break; 2586 default: break; 2587 } 2588 //mode coding 2589 if( pcCU->getSlice()->getIntraSdcWedgeFlag() && pcCU->getSlice()->getIntraContourFlag()) 2590 { 2591 m_pcBinIf->encodeBin( uiCodeIdx == 0 ? 0 : 1, m_cDmmModeSCModel.get( 0, 0, 0 ) ); 2592 } 2593 } 2594 } 2595 2596 Void TEncSbac::xCodeDmmData( TComDataCU* pcCU, UInt absPartIdx ) 2597 { 2598 UInt dir = pcCU->getIntraDir( CHANNEL_TYPE_LUMA, absPartIdx ); 2599 switch( getDmmType( dir ) ) 2600 { 2601 case( DMM1_IDX ): { xCodeDmm1WedgeIdx( pcCU->getDmm1WedgeTabIdx( absPartIdx ), g_dmm1TabIdxBits[pcCU->getIntraSizeIdx(absPartIdx)] ); } break; 2602 case( DMM4_IDX ): break; 2603 default: break; 2604 } 2605 } 2606 2607 Void TEncSbac::xCodeDmm1WedgeIdx( UInt uiTabIdx, Int iNumBit ) 2608 { 2609 for ( Int i = 0; i < iNumBit; i++ ) 2610 { 2611 m_pcBinIf->encodeBinEP( ( uiTabIdx >> i ) & 1 ); 2612 } 2613 } 2614 #endif 2615 2616 #if NH_3D_SDC_INTRA || NH_3D_SDC_INTER 2311 2617 Void TEncSbac::codeSDCFlag( TComDataCU* pcCU, UInt uiAbsPartIdx ) 2312 2618 { 2313 2619 UInt uiSymbol = pcCU->getSDCFlag( uiAbsPartIdx ) ? 1 : 0; 2314 UInt uiCtxSDCFlag = pcCU->getCtxSDCFlag( uiAbsPartIdx ); 2620 #if ENC_DEC_TRACE && H_MV_ENC_DEC_TRAC 2315 2621 DTRACE_CU("dc_only_flag", uiSymbol) 2316 m_pcBinIf->encodeBin( uiSymbol, m_cSDCFlagSCModel.get( 0, 0, uiCtxSDCFlag ) ); 2317 } 2318 2319 #endif 2320 2321 #if H_3D_DBBP 2622 #endif 2623 m_pcBinIf->encodeBin( uiSymbol, m_cSDCFlagSCModel.get( 0, 0, 0 ) ); 2624 } 2625 2626 #endif 2627 2628 #if NH_3D_DBBP 2322 2629 Void TEncSbac::codeDBBPFlag( TComDataCU* pcCU, UInt uiAbsPartIdx ) 2323 2630 {
Note: See TracChangeset for help on using the changeset viewer.