[5] | 1 | /* The copyright in this software is being made available under the BSD |
---|
| 2 | * License, included below. This software may be subject to other third party |
---|
| 3 | * and contributor rights, including patent rights, and no such rights are |
---|
[1200] | 4 | * granted under this license. |
---|
[5] | 5 | * |
---|
[1200] | 6 | * Copyright (c) 2010-2015, ITU/ISO/IEC |
---|
[5] | 7 | * All rights reserved. |
---|
| 8 | * |
---|
| 9 | * Redistribution and use in source and binary forms, with or without |
---|
| 10 | * modification, are permitted provided that the following conditions are met: |
---|
| 11 | * |
---|
| 12 | * * Redistributions of source code must retain the above copyright notice, |
---|
| 13 | * this list of conditions and the following disclaimer. |
---|
| 14 | * * Redistributions in binary form must reproduce the above copyright notice, |
---|
| 15 | * this list of conditions and the following disclaimer in the documentation |
---|
| 16 | * and/or other materials provided with the distribution. |
---|
[56] | 17 | * * Neither the name of the ITU/ISO/IEC nor the names of its contributors may |
---|
[5] | 18 | * be used to endorse or promote products derived from this software without |
---|
| 19 | * specific prior written permission. |
---|
| 20 | * |
---|
| 21 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
---|
| 22 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
---|
| 23 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
---|
| 24 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS |
---|
| 25 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
---|
| 26 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
---|
| 27 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
---|
| 28 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
---|
| 29 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
---|
| 30 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF |
---|
| 31 | * THE POSSIBILITY OF SUCH DAMAGE. |
---|
| 32 | */ |
---|
[2] | 33 | |
---|
| 34 | /** \file TEncSbac.cpp |
---|
| 35 | \brief SBAC encoder class |
---|
| 36 | */ |
---|
| 37 | |
---|
| 38 | #include "TEncTop.h" |
---|
| 39 | #include "TEncSbac.h" |
---|
[1200] | 40 | #include "TLibCommon/TComTU.h" |
---|
[2] | 41 | |
---|
| 42 | #include <map> |
---|
[56] | 43 | #include <algorithm> |
---|
[2] | 44 | |
---|
[1200] | 45 | #if ENVIRONMENT_VARIABLE_DEBUG_AND_TEST |
---|
| 46 | #include "../TLibCommon/Debug.h" |
---|
| 47 | #endif |
---|
| 48 | |
---|
| 49 | |
---|
[56] | 50 | //! \ingroup TLibEncoder |
---|
| 51 | //! \{ |
---|
[2] | 52 | |
---|
| 53 | // ==================================================================================================================== |
---|
| 54 | // Constructor / destructor / create / destroy |
---|
| 55 | // ==================================================================================================================== |
---|
| 56 | |
---|
| 57 | TEncSbac::TEncSbac() |
---|
| 58 | // new structure here |
---|
[1200] | 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) |
---|
[1258] | 64 | #if NH_3D_DIS |
---|
[1200] | 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) |
---|
[1039] | 67 | #endif |
---|
[1200] | 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) |
---|
[1279] | 70 | #if NH_3D_ARP |
---|
[1200] | 71 | , m_cCUPUARPWSCModel ( 1, 1, NUM_ARPW_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
| 72 | #endif |
---|
[1279] | 73 | #if NH_3D_IC |
---|
[1200] | 74 | , m_cCUICFlagSCModel ( 1, 1, NUM_IC_FLAG_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
[2] | 75 | #endif |
---|
[1200] | 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) |
---|
[1209] | 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 |
---|
[1304] | 108 | #if NH_3D_DMM || NH_3D_SDC_INTRA || NH_3D_SDC_INTER |
---|
[1200] | 109 | , m_cDdcDataSCModel ( 1, 1, NUM_DDC_DATA_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
[1304] | 110 | , m_cSDCFlagSCModel ( 1, 1, NUM_SDC_FLAG_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
[1209] | 111 | #endif |
---|
[1227] | 112 | #if NH_3D_SDC_INTRA |
---|
[1200] | 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) |
---|
[1209] | 115 | , m_cDdcFlagSCModel ( 1, 1, NUM_DDC_FLAG_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
[1200] | 116 | #endif |
---|
[1279] | 117 | #if NH_3D_DBBP |
---|
[1200] | 118 | , m_cDBBPFlagSCModel ( 1, 1, DBBP_NUM_FLAG_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
[833] | 119 | #endif |
---|
[2] | 120 | { |
---|
[56] | 121 | assert( m_numContextModels <= MAX_NUM_CTX_MOD ); |
---|
[2] | 122 | } |
---|
| 123 | |
---|
| 124 | TEncSbac::~TEncSbac() |
---|
| 125 | { |
---|
| 126 | } |
---|
| 127 | |
---|
| 128 | // ==================================================================================================================== |
---|
| 129 | // Public member functions |
---|
| 130 | // ==================================================================================================================== |
---|
| 131 | |
---|
[1200] | 132 | Void TEncSbac::resetEntropy (const TComSlice *pSlice) |
---|
[2] | 133 | { |
---|
[1200] | 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()) |
---|
[56] | 139 | { |
---|
[1200] | 140 | eSliceType = encCABACTableIdx; |
---|
[56] | 141 | } |
---|
| 142 | |
---|
[1200] | 143 | m_cCUSplitFlagSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_SPLIT_FLAG ); |
---|
| 144 | m_cCUSkipFlagSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_SKIP_FLAG ); |
---|
[1258] | 145 | #if NH_3D_DIS |
---|
[1200] | 146 | m_cCUDISFlagSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_DIS_FLAG ); |
---|
| 147 | m_cCUDISTypeSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_DIS_TYPE ); |
---|
[1039] | 148 | #endif |
---|
[1200] | 149 | m_cCUMergeFlagExtSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_MERGE_FLAG_EXT); |
---|
| 150 | m_cCUMergeIdxExtSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_MERGE_IDX_EXT); |
---|
[1279] | 151 | #if NH_3D_ARP |
---|
[1200] | 152 | m_cCUPUARPWSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_ARPW ); |
---|
[2] | 153 | #endif |
---|
[1279] | 154 | #if NH_3D_IC |
---|
[1200] | 155 | m_cCUICFlagSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_IC_FLAG ); |
---|
[443] | 156 | #endif |
---|
[1200] | 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 ); |
---|
[1209] | 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 |
---|
[1304] | 189 | #if NH_3D_DMM || NH_3D_SDC_INTRA || NH_3D_SDC_INTER |
---|
[1200] | 190 | m_cDdcDataSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_DDC_DATA ); |
---|
[1304] | 191 | m_cSDCFlagSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_SDC_FLAG ); |
---|
[1209] | 192 | #endif |
---|
[1227] | 193 | #if NH_3D_SDC_INTRA |
---|
[1200] | 194 | m_cSDCResidualFlagSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_SDC_RESIDUAL_FLAG ); |
---|
| 195 | m_cSDCResidualSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_SDC_RESIDUAL ); |
---|
[1209] | 196 | m_cDdcFlagSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_DDC_FLAG ); |
---|
[1200] | 197 | #endif |
---|
[1279] | 198 | #if NH_3D_DBBP |
---|
[1200] | 199 | m_cDBBPFlagSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_DBBP_FLAG ); |
---|
[100] | 200 | #endif |
---|
[1200] | 201 | |
---|
| 202 | for (UInt statisticIndex = 0; statisticIndex < RExt__GOLOMB_RICE_ADAPTATION_STATISTICS_SETS ; statisticIndex++) |
---|
| 203 | { |
---|
| 204 | m_golombRiceAdaptationStatistics[statisticIndex] = 0; |
---|
| 205 | } |
---|
| 206 | |
---|
[2] | 207 | m_pcBinIf->start(); |
---|
[1200] | 208 | |
---|
[2] | 209 | return; |
---|
| 210 | } |
---|
| 211 | |
---|
[1200] | 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 |
---|
[56] | 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. |
---|
| 215 | */ |
---|
[1200] | 216 | SliceType TEncSbac::determineCabacInitIdx(const TComSlice *pSlice) |
---|
[56] | 217 | { |
---|
[1200] | 218 | Int qp = pSlice->getSliceQp(); |
---|
[56] | 219 | |
---|
[1200] | 220 | if (!pSlice->isIntra()) |
---|
[56] | 221 | { |
---|
| 222 | SliceType aSliceTypeChoices[] = {B_SLICE, P_SLICE}; |
---|
| 223 | |
---|
| 224 | UInt bestCost = MAX_UINT; |
---|
| 225 | SliceType bestSliceType = aSliceTypeChoices[0]; |
---|
| 226 | for (UInt idx=0; idx<2; idx++) |
---|
| 227 | { |
---|
| 228 | UInt curCost = 0; |
---|
| 229 | SliceType curSliceType = aSliceTypeChoices[idx]; |
---|
| 230 | |
---|
[1200] | 231 | curCost = m_cCUSplitFlagSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_SPLIT_FLAG ); |
---|
| 232 | curCost += m_cCUSkipFlagSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_SKIP_FLAG ); |
---|
[1258] | 233 | #if NH_3D_DIS |
---|
[1200] | 234 | curCost += m_cCUDISFlagSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_DIS_FLAG ); |
---|
| 235 | curCost += m_cCUDISTypeSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_DIS_TYPE ); |
---|
[1039] | 236 | #endif |
---|
[1200] | 237 | curCost += m_cCUMergeFlagExtSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_MERGE_FLAG_EXT); |
---|
| 238 | curCost += m_cCUMergeIdxExtSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_MERGE_IDX_EXT); |
---|
[1279] | 239 | #if NH_3D_ARP |
---|
[1200] | 240 | curCost += m_cCUPUARPWSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_ARPW ); |
---|
| 241 | #endif |
---|
[1279] | 242 | #if NH_3D_IC |
---|
[1200] | 243 | curCost += m_cCUICFlagSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_IC_FLAG ); |
---|
| 244 | #endif |
---|
[1304] | 245 | #if NH_3D_SDC_INTRA || NH_3D_SDC_INTER |
---|
[1200] | 246 | curCost += m_cSDCFlagSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_SDC_FLAG ); |
---|
| 247 | #endif |
---|
[1279] | 248 | #if NH_3D_DBBP |
---|
[1200] | 249 | curCost += m_cDBBPFlagSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_DBBP_FLAG ); |
---|
[56] | 250 | #endif |
---|
[1200] | 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 ); |
---|
[1209] | 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 ); |
---|
[608] | 281 | #endif |
---|
[1304] | 282 | #if NH_3D_DMM || NH_3D_SDC_INTRA || NH_3D_SDC_INTER |
---|
[1209] | 283 | curCost += m_cDdcDataSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_DDC_DATA ); |
---|
| 284 | #endif |
---|
[1200] | 285 | |
---|
[56] | 286 | if (curCost < bestCost) |
---|
| 287 | { |
---|
| 288 | bestSliceType = curSliceType; |
---|
| 289 | bestCost = curCost; |
---|
| 290 | } |
---|
| 291 | } |
---|
[1200] | 292 | return bestSliceType; |
---|
[56] | 293 | } |
---|
| 294 | else |
---|
| 295 | { |
---|
[1200] | 296 | return I_SLICE; |
---|
| 297 | } |
---|
[56] | 298 | } |
---|
[2] | 299 | |
---|
[1200] | 300 | |
---|
| 301 | Void TEncSbac::codeVPS( const TComVPS* /*pcVPS*/ ) |
---|
[77] | 302 | { |
---|
[100] | 303 | assert (0); |
---|
[77] | 304 | return; |
---|
| 305 | } |
---|
| 306 | |
---|
[1200] | 307 | Void TEncSbac::codeSPS( const TComSPS* /*pcSPS*/ ) |
---|
[2] | 308 | { |
---|
| 309 | assert (0); |
---|
| 310 | return; |
---|
| 311 | } |
---|
| 312 | |
---|
[1200] | 313 | Void TEncSbac::codePPS( const TComPPS* /*pcPPS*/ ) |
---|
[2] | 314 | { |
---|
| 315 | assert (0); |
---|
| 316 | return; |
---|
| 317 | } |
---|
| 318 | |
---|
[1200] | 319 | Void TEncSbac::codeSliceHeader( TComSlice* /*pcSlice*/ ) |
---|
[2] | 320 | { |
---|
| 321 | assert (0); |
---|
| 322 | return; |
---|
| 323 | } |
---|
| 324 | |
---|
[1200] | 325 | Void TEncSbac::codeTilesWPPEntryPoint( TComSlice* /*pSlice*/ ) |
---|
[56] | 326 | { |
---|
| 327 | assert (0); |
---|
| 328 | return; |
---|
| 329 | } |
---|
| 330 | |
---|
[2] | 331 | Void TEncSbac::codeTerminatingBit( UInt uilsLast ) |
---|
| 332 | { |
---|
| 333 | m_pcBinIf->encodeBinTrm( uilsLast ); |
---|
| 334 | } |
---|
| 335 | |
---|
| 336 | Void TEncSbac::codeSliceFinish() |
---|
| 337 | { |
---|
| 338 | m_pcBinIf->finish(); |
---|
| 339 | } |
---|
| 340 | |
---|
| 341 | Void TEncSbac::xWriteUnarySymbol( UInt uiSymbol, ContextModel* pcSCModel, Int iOffset ) |
---|
| 342 | { |
---|
| 343 | m_pcBinIf->encodeBin( uiSymbol ? 1 : 0, pcSCModel[0] ); |
---|
[1200] | 344 | |
---|
[2] | 345 | if( 0 == uiSymbol) |
---|
| 346 | { |
---|
| 347 | return; |
---|
| 348 | } |
---|
[1200] | 349 | |
---|
[2] | 350 | while( uiSymbol-- ) |
---|
| 351 | { |
---|
| 352 | m_pcBinIf->encodeBin( uiSymbol ? 1 : 0, pcSCModel[ iOffset ] ); |
---|
| 353 | } |
---|
[1200] | 354 | |
---|
[2] | 355 | return; |
---|
| 356 | } |
---|
| 357 | |
---|
| 358 | Void TEncSbac::xWriteUnaryMaxSymbol( UInt uiSymbol, ContextModel* pcSCModel, Int iOffset, UInt uiMaxSymbol ) |
---|
| 359 | { |
---|
| 360 | if (uiMaxSymbol == 0) |
---|
| 361 | { |
---|
| 362 | return; |
---|
| 363 | } |
---|
[1200] | 364 | |
---|
[2] | 365 | m_pcBinIf->encodeBin( uiSymbol ? 1 : 0, pcSCModel[ 0 ] ); |
---|
[1200] | 366 | |
---|
[2] | 367 | if ( uiSymbol == 0 ) |
---|
| 368 | { |
---|
| 369 | return; |
---|
| 370 | } |
---|
[1200] | 371 | |
---|
[2] | 372 | Bool bCodeLast = ( uiMaxSymbol > uiSymbol ); |
---|
[1200] | 373 | |
---|
[2] | 374 | while( --uiSymbol ) |
---|
| 375 | { |
---|
| 376 | m_pcBinIf->encodeBin( 1, pcSCModel[ iOffset ] ); |
---|
| 377 | } |
---|
| 378 | if( bCodeLast ) |
---|
| 379 | { |
---|
| 380 | m_pcBinIf->encodeBin( 0, pcSCModel[ iOffset ] ); |
---|
| 381 | } |
---|
[1200] | 382 | |
---|
[2] | 383 | return; |
---|
| 384 | } |
---|
| 385 | |
---|
| 386 | Void TEncSbac::xWriteEpExGolomb( UInt uiSymbol, UInt uiCount ) |
---|
| 387 | { |
---|
[56] | 388 | UInt bins = 0; |
---|
| 389 | Int numBins = 0; |
---|
[1200] | 390 | |
---|
[2] | 391 | while( uiSymbol >= (UInt)(1<<uiCount) ) |
---|
| 392 | { |
---|
[56] | 393 | bins = 2 * bins + 1; |
---|
| 394 | numBins++; |
---|
| 395 | uiSymbol -= 1 << uiCount; |
---|
[2] | 396 | uiCount ++; |
---|
| 397 | } |
---|
[56] | 398 | bins = 2 * bins + 0; |
---|
| 399 | numBins++; |
---|
[1200] | 400 | |
---|
[56] | 401 | bins = (bins << uiCount) | uiSymbol; |
---|
| 402 | numBins += uiCount; |
---|
[1200] | 403 | |
---|
[56] | 404 | assert( numBins <= 32 ); |
---|
| 405 | m_pcBinIf->encodeBinsEP( bins, numBins ); |
---|
[2] | 406 | } |
---|
[1200] | 407 | |
---|
[1258] | 408 | #if NH_3D_DIS |
---|
[1179] | 409 | Void TEncSbac::codeDIS( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
| 410 | { |
---|
| 411 | UInt uiSymbol = pcCU->getDISFlag(uiAbsPartIdx ) ? 1 : 0; |
---|
| 412 | m_pcBinIf->encodeBin( uiSymbol, m_cCUDISFlagSCModel.get( 0, 0, 0 ) ); |
---|
| 413 | if(uiSymbol) |
---|
| 414 | { |
---|
| 415 | UInt uiUnaryIdx = (UInt) pcCU->getDISType(uiAbsPartIdx); |
---|
| 416 | UInt uiNumCand = 4; |
---|
| 417 | |
---|
| 418 | if ( uiNumCand > 1 ) |
---|
| 419 | { |
---|
| 420 | for( UInt ui = 0; ui < uiNumCand - 1; ++ui ) |
---|
| 421 | { |
---|
| 422 | const UInt uiSymbol2 = ui == uiUnaryIdx ? 0 : 1; |
---|
| 423 | if ( ui == 0 ) |
---|
| 424 | { |
---|
| 425 | m_pcBinIf->encodeBin( uiSymbol2, m_cCUDISTypeSCModel.get( 0, 0, 0 ) ); |
---|
| 426 | } |
---|
| 427 | else |
---|
| 428 | { |
---|
| 429 | m_pcBinIf->encodeBinEP( uiSymbol2 ); |
---|
| 430 | } |
---|
| 431 | if( uiSymbol2 == 0 ) |
---|
| 432 | { |
---|
| 433 | break; |
---|
| 434 | } |
---|
| 435 | } |
---|
| 436 | } |
---|
| 437 | } |
---|
| 438 | } |
---|
[1039] | 439 | #endif |
---|
[1200] | 440 | |
---|
| 441 | |
---|
[2] | 442 | /** Coding of coeff_abs_level_minus3 |
---|
[1200] | 443 | * \param symbol value of coeff_abs_level_minus3 |
---|
| 444 | * \param rParam reference to Rice parameter |
---|
| 445 | * \param useLimitedPrefixLength |
---|
| 446 | * \param maxLog2TrDynamicRange |
---|
[2] | 447 | */ |
---|
[1200] | 448 | Void TEncSbac::xWriteCoefRemainExGolomb ( UInt symbol, UInt &rParam, const Bool useLimitedPrefixLength, const Int maxLog2TrDynamicRange ) |
---|
[2] | 449 | { |
---|
[608] | 450 | Int codeNumber = (Int)symbol; |
---|
| 451 | UInt length; |
---|
[1200] | 452 | |
---|
[608] | 453 | if (codeNumber < (COEF_REMAIN_BIN_REDUCTION << rParam)) |
---|
[2] | 454 | { |
---|
[608] | 455 | length = codeNumber>>rParam; |
---|
| 456 | m_pcBinIf->encodeBinsEP( (1<<(length+1))-2 , length+1); |
---|
| 457 | m_pcBinIf->encodeBinsEP((codeNumber%(1<<rParam)),rParam); |
---|
[2] | 458 | } |
---|
[1200] | 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 | } |
---|
[2] | 491 | else |
---|
| 492 | { |
---|
[608] | 493 | length = rParam; |
---|
| 494 | codeNumber = codeNumber - ( COEF_REMAIN_BIN_REDUCTION << rParam); |
---|
[1200] | 495 | |
---|
[608] | 496 | while (codeNumber >= (1<<length)) |
---|
| 497 | { |
---|
[1200] | 498 | codeNumber -= (1<<(length++)); |
---|
[608] | 499 | } |
---|
[1200] | 500 | |
---|
[608] | 501 | m_pcBinIf->encodeBinsEP((1<<(COEF_REMAIN_BIN_REDUCTION+length+1-rParam))-2,COEF_REMAIN_BIN_REDUCTION+length+1-rParam); |
---|
| 502 | m_pcBinIf->encodeBinsEP(codeNumber,length); |
---|
[2] | 503 | } |
---|
[608] | 504 | } |
---|
[56] | 505 | // SBAC RD |
---|
[1200] | 506 | Void TEncSbac::load ( const TEncSbac* pSrc) |
---|
[2] | 507 | { |
---|
[56] | 508 | this->xCopyFrom(pSrc); |
---|
[2] | 509 | } |
---|
| 510 | |
---|
[1200] | 511 | Void TEncSbac::loadIntraDirMode( const TEncSbac* pSrc, const ChannelType chType ) |
---|
[2] | 512 | { |
---|
[56] | 513 | m_pcBinIf->copyState( pSrc->m_pcBinIf ); |
---|
[1200] | 514 | if (isLuma(chType)) |
---|
| 515 | { |
---|
| 516 | this->m_cCUIntraPredSCModel .copyFrom( &pSrc->m_cCUIntraPredSCModel ); |
---|
| 517 | } |
---|
| 518 | else |
---|
| 519 | { |
---|
| 520 | this->m_cCUChromaPredSCModel .copyFrom( &pSrc->m_cCUChromaPredSCModel ); |
---|
| 521 | } |
---|
[2] | 522 | } |
---|
[1200] | 523 | |
---|
[1209] | 524 | #if NH_3D_DMM |
---|
| 525 | Void TEncSbac::loadIntraDepthDmm( const TEncSbac* pSrc ) |
---|
[443] | 526 | { |
---|
| 527 | m_pcBinIf->copyState( pSrc->m_pcBinIf ); |
---|
[1209] | 528 | this->m_cNotDmmFlagSCModel.copyFrom( &pSrc->m_cNotDmmFlagSCModel ); |
---|
| 529 | this->m_cDmmModeSCModel .copyFrom( &pSrc->m_cDmmModeSCModel ); |
---|
[443] | 530 | } |
---|
| 531 | #endif |
---|
[608] | 532 | |
---|
[1200] | 533 | |
---|
| 534 | Void TEncSbac::store( TEncSbac* pDest) const |
---|
[2] | 535 | { |
---|
| 536 | pDest->xCopyFrom( this ); |
---|
| 537 | } |
---|
| 538 | |
---|
| 539 | |
---|
[1200] | 540 | Void TEncSbac::xCopyFrom( const TEncSbac* pSrc ) |
---|
[2] | 541 | { |
---|
| 542 | m_pcBinIf->copyState( pSrc->m_pcBinIf ); |
---|
[1200] | 543 | xCopyContextsFrom(pSrc); |
---|
[2] | 544 | } |
---|
| 545 | |
---|
| 546 | Void TEncSbac::codeMVPIdx ( TComDataCU* pcCU, UInt uiAbsPartIdx, RefPicList eRefList ) |
---|
| 547 | { |
---|
| 548 | Int iSymbol = pcCU->getMVPIdx(eRefList, uiAbsPartIdx); |
---|
[56] | 549 | Int iNum = AMVP_MAX_NUM_CANDS; |
---|
[2] | 550 | |
---|
| 551 | xWriteUnaryMaxSymbol(iSymbol, m_cMVPIdxSCModel.get(0), 1, iNum-1); |
---|
[608] | 552 | #if H_MV_ENC_DEC_TRAC |
---|
| 553 | #if ENC_DEC_TRACE |
---|
| 554 | if ( eRefList == REF_PIC_LIST_0 ) |
---|
| 555 | { |
---|
| 556 | DTRACE_PU("mvp_l0_flag", iSymbol) |
---|
| 557 | } |
---|
| 558 | else |
---|
| 559 | { |
---|
| 560 | DTRACE_PU("mvp_l1_flag", iSymbol) |
---|
| 561 | } |
---|
| 562 | #endif |
---|
| 563 | #endif |
---|
[2] | 564 | } |
---|
| 565 | |
---|
| 566 | Void TEncSbac::codePartSize( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth ) |
---|
| 567 | { |
---|
| 568 | PartSize eSize = pcCU->getPartitionSize( uiAbsPartIdx ); |
---|
[1279] | 569 | #if NH_3D_QTLPC |
---|
[1124] | 570 | Bool bLimQtPredFlag = pcCU->getPic()->getSlice(0)->getQtPredFlag(); |
---|
[189] | 571 | TComPic *pcTexture = pcCU->getSlice()->getTexturePic(); |
---|
| 572 | Bool bDepthMapDetect = (pcTexture != NULL); |
---|
| 573 | Bool bIntraSliceDetect = (pcCU->getSlice()->getSliceType() == I_SLICE); |
---|
[1196] | 574 | |
---|
[608] | 575 | Bool rapPic = (pcCU->getSlice()->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_W_RADL || pcCU->getSlice()->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_N_LP || pcCU->getSlice()->getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA); |
---|
| 576 | |
---|
[833] | 577 | Bool depthDependent = false; |
---|
| 578 | UInt uiTexturePart = eSize; |
---|
[1084] | 579 | |
---|
| 580 | #if H_3D_FCO |
---|
[1066] | 581 | if(bDepthMapDetect && !bIntraSliceDetect && !rapPic && pcCU->getPic()->getReduceBitsFlag() && bLimQtPredFlag && pcTexture->getReconMark()) |
---|
| 582 | #else |
---|
[1039] | 583 | if(bDepthMapDetect && !bIntraSliceDetect && !rapPic && pcCU->getPic()->getReduceBitsFlag() && bLimQtPredFlag ) |
---|
[1066] | 584 | #endif |
---|
[189] | 585 | { |
---|
[1279] | 586 | TComDataCU *pcTextureCU = pcTexture->getCtu(pcCU->getCtuRsAddr()); |
---|
| 587 | UInt uiCUIdx = (pcCU->getZorderIdxInCtu() == 0) ? uiAbsPartIdx : pcCU->getZorderIdxInCtu(); |
---|
[189] | 588 | assert(pcTextureCU->getDepth(uiCUIdx) >= uiDepth); |
---|
[833] | 589 | if(pcTextureCU->getDepth(uiCUIdx) == uiDepth ) |
---|
[189] | 590 | { |
---|
[833] | 591 | depthDependent = true; |
---|
| 592 | uiTexturePart = pcTextureCU->getPartitionSize( uiCUIdx ); |
---|
| 593 | } |
---|
| 594 | if (pcTextureCU->getDepth(uiCUIdx) == uiDepth && pcTextureCU->getPartitionSize( uiCUIdx ) == SIZE_2Nx2N) |
---|
| 595 | { |
---|
[189] | 596 | assert( eSize == SIZE_2Nx2N ); |
---|
| 597 | return; |
---|
| 598 | } |
---|
| 599 | } |
---|
[115] | 600 | #endif |
---|
[1200] | 601 | const UInt log2DiffMaxMinCodingBlockSize = pcCU->getSlice()->getSPS()->getLog2DiffMaxMinCodingBlockSize(); |
---|
| 602 | |
---|
[2] | 603 | if ( pcCU->isIntra( uiAbsPartIdx ) ) |
---|
| 604 | { |
---|
[1200] | 605 | if( uiDepth == log2DiffMaxMinCodingBlockSize ) |
---|
[2] | 606 | { |
---|
| 607 | m_pcBinIf->encodeBin( eSize == SIZE_2Nx2N? 1 : 0, m_cCUPartSizeSCModel.get( 0, 0, 0 ) ); |
---|
[608] | 608 | #if H_MV_ENC_DEC_TRAC |
---|
| 609 | DTRACE_CU("part_mode", eSize == SIZE_2Nx2N? 1 : 0) |
---|
| 610 | #endif |
---|
[1200] | 611 | |
---|
[2] | 612 | } |
---|
| 613 | return; |
---|
| 614 | } |
---|
[608] | 615 | #if H_MV_ENC_DEC_TRAC |
---|
| 616 | DTRACE_CU("part_mode", eSize ) |
---|
| 617 | #endif |
---|
[1279] | 618 | #if NH_3D_QTLPC |
---|
[833] | 619 | if (depthDependent==false || uiTexturePart == SIZE_NxN|| uiTexturePart == SIZE_2Nx2N) |
---|
| 620 | { |
---|
| 621 | #endif |
---|
[1200] | 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 ) |
---|
[56] | 637 | { |
---|
[1200] | 638 | if (eSize == SIZE_2NxN) |
---|
[56] | 639 | { |
---|
[1200] | 640 | m_pcBinIf->encodeBin(1, m_cCUPartSizeSCModel.get( 0, 0, 3 )); |
---|
[56] | 641 | } |
---|
[1200] | 642 | else |
---|
[56] | 643 | { |
---|
[1200] | 644 | m_pcBinIf->encodeBin(0, m_cCUPartSizeSCModel.get( 0, 0, 3 )); |
---|
| 645 | m_pcBinIf->encodeBinEP((eSize == SIZE_2NxnU? 0: 1)); |
---|
[56] | 646 | } |
---|
[1200] | 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) |
---|
[56] | 665 | { |
---|
[1200] | 666 | m_pcBinIf->encodeBin(1, m_cCUPartSizeSCModel.get( 0, 0, 3 )); |
---|
[56] | 667 | } |
---|
[1200] | 668 | else |
---|
[56] | 669 | { |
---|
[1200] | 670 | m_pcBinIf->encodeBin(0, m_cCUPartSizeSCModel.get( 0, 0, 3 )); |
---|
| 671 | m_pcBinIf->encodeBinEP((eSize == SIZE_nLx2N? 0: 1)); |
---|
[56] | 672 | } |
---|
| 673 | } |
---|
[1200] | 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 | } |
---|
[1279] | 692 | #if NH_3D_QTLPC |
---|
[833] | 693 | } |
---|
| 694 | else if(uiTexturePart == SIZE_2NxN || uiTexturePart == SIZE_2NxnU || uiTexturePart == SIZE_2NxnD) |
---|
| 695 | { |
---|
| 696 | //assert(eSize!=SIZE_NxN); |
---|
| 697 | //assert(eSize!=SIZE_Nx2N); |
---|
| 698 | //assert(eSize==SIZE_2Nx2N || eSize==SIZE_2NxN || eSize==SIZE_2NxnU || eSize==SIZE_2NxnD); |
---|
| 699 | switch(eSize) |
---|
| 700 | { |
---|
| 701 | case SIZE_2Nx2N: |
---|
| 702 | { |
---|
| 703 | m_pcBinIf->encodeBin( 1, m_cCUPartSizeSCModel.get( 0, 0, 0) ); |
---|
| 704 | break; |
---|
| 705 | } |
---|
| 706 | case SIZE_2NxN: |
---|
| 707 | { |
---|
| 708 | m_pcBinIf->encodeBin( 0, m_cCUPartSizeSCModel.get( 0, 0, 0) ); |
---|
[1279] | 709 | if ( pcCU->getSlice()->getSPS()->getUseAMP() && uiDepth < log2DiffMaxMinCodingBlockSize ) |
---|
[833] | 710 | { |
---|
| 711 | m_pcBinIf->encodeBin( 1, m_cCUPartSizeSCModel.get( 0, 0, 1) ); |
---|
| 712 | } |
---|
| 713 | break; |
---|
| 714 | } |
---|
| 715 | case SIZE_2NxnU: |
---|
| 716 | case SIZE_2NxnD: |
---|
| 717 | { |
---|
| 718 | m_pcBinIf->encodeBin( 0, m_cCUPartSizeSCModel.get( 0, 0, 0) ); |
---|
| 719 | m_pcBinIf->encodeBin( 0, m_cCUPartSizeSCModel.get( 0, 0, 1) ); |
---|
| 720 | m_pcBinIf->encodeBinEP((eSize == SIZE_2NxnU? 0: 1)); |
---|
| 721 | break; |
---|
| 722 | } |
---|
| 723 | default: |
---|
| 724 | { |
---|
| 725 | assert(0); |
---|
| 726 | } |
---|
| 727 | } |
---|
| 728 | } |
---|
| 729 | else if(uiTexturePart == SIZE_Nx2N|| uiTexturePart==SIZE_nLx2N || uiTexturePart==SIZE_nRx2N) |
---|
| 730 | { |
---|
| 731 | //assert(eSize!=SIZE_NxN); |
---|
| 732 | //assert(eSize!=SIZE_2NxN); |
---|
| 733 | //assert(eSize==SIZE_2Nx2N ||eSize==SIZE_Nx2N || eSize==SIZE_nLx2N || eSize==SIZE_nRx2N); |
---|
| 734 | switch(eSize) |
---|
| 735 | { |
---|
| 736 | case SIZE_2Nx2N: |
---|
| 737 | { |
---|
| 738 | m_pcBinIf->encodeBin( 1, m_cCUPartSizeSCModel.get( 0, 0, 0) ); |
---|
| 739 | break; |
---|
| 740 | } |
---|
| 741 | case SIZE_Nx2N: |
---|
| 742 | { |
---|
| 743 | m_pcBinIf->encodeBin( 0, m_cCUPartSizeSCModel.get( 0, 0, 0) ); |
---|
[1279] | 744 | if ( pcCU->getSlice()->getSPS()->getUseAMP() && uiDepth < log2DiffMaxMinCodingBlockSize ) |
---|
[833] | 745 | { |
---|
| 746 | m_pcBinIf->encodeBin( 1, m_cCUPartSizeSCModel.get( 0, 0, 1) ); |
---|
| 747 | } |
---|
| 748 | break; |
---|
| 749 | } |
---|
| 750 | case SIZE_nLx2N: |
---|
| 751 | case SIZE_nRx2N: |
---|
| 752 | { |
---|
| 753 | m_pcBinIf->encodeBin( 0, m_cCUPartSizeSCModel.get( 0, 0, 0) ); |
---|
| 754 | m_pcBinIf->encodeBin( 0, m_cCUPartSizeSCModel.get( 0, 0, 1) ); |
---|
| 755 | m_pcBinIf->encodeBinEP((eSize == SIZE_nLx2N? 0: 1)); |
---|
| 756 | break; |
---|
| 757 | } |
---|
| 758 | default: |
---|
| 759 | { |
---|
| 760 | assert(0); |
---|
| 761 | } |
---|
| 762 | } |
---|
| 763 | } |
---|
| 764 | else |
---|
| 765 | { |
---|
| 766 | printf("uiTexturePart=%d",uiTexturePart); |
---|
| 767 | assert(0); |
---|
| 768 | } |
---|
| 769 | #endif |
---|
[1200] | 770 | |
---|
[2] | 771 | } |
---|
| 772 | |
---|
[1200] | 773 | |
---|
[2] | 774 | /** code prediction mode |
---|
| 775 | * \param pcCU |
---|
[1200] | 776 | * \param uiAbsPartIdx |
---|
[2] | 777 | * \returns Void |
---|
| 778 | */ |
---|
| 779 | Void TEncSbac::codePredMode( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
| 780 | { |
---|
| 781 | // get context function is here |
---|
[1200] | 782 | m_pcBinIf->encodeBin( pcCU->isIntra( uiAbsPartIdx ) ? 1 : 0, m_cCUPredModeSCModel.get( 0, 0, 0 ) ); |
---|
[608] | 783 | #if H_MV_ENC_DEC_TRAC |
---|
[1200] | 784 | DTRACE_CU("pred_mode_flag", pcCU->isIntra( uiAbsPartIdx ) ? 1 : 0); |
---|
[608] | 785 | #endif |
---|
[1200] | 786 | |
---|
[2] | 787 | } |
---|
| 788 | |
---|
[608] | 789 | Void TEncSbac::codeCUTransquantBypassFlag( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
[2] | 790 | { |
---|
[608] | 791 | UInt uiSymbol = pcCU->getCUTransquantBypass(uiAbsPartIdx); |
---|
| 792 | m_pcBinIf->encodeBin( uiSymbol, m_CUTransquantBypassFlagSCModel.get( 0, 0, 0 ) ); |
---|
| 793 | #if H_MV_ENC_DEC_TRAC |
---|
| 794 | DTRACE_CU("cu_transquant_bypass_flag", uiSymbol); |
---|
| 795 | #endif |
---|
[1200] | 796 | |
---|
[2] | 797 | } |
---|
| 798 | |
---|
| 799 | /** code skip flag |
---|
| 800 | * \param pcCU |
---|
[1200] | 801 | * \param uiAbsPartIdx |
---|
[2] | 802 | * \returns Void |
---|
| 803 | */ |
---|
| 804 | Void TEncSbac::codeSkipFlag( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
| 805 | { |
---|
| 806 | // get context function is here |
---|
| 807 | UInt uiSymbol = pcCU->isSkipped( uiAbsPartIdx ) ? 1 : 0; |
---|
| 808 | UInt uiCtxSkip = pcCU->getCtxSkipFlag( uiAbsPartIdx ) ; |
---|
| 809 | m_pcBinIf->encodeBin( uiSymbol, m_cCUSkipFlagSCModel.get( 0, 0, uiCtxSkip ) ); |
---|
[608] | 810 | #if !H_MV_ENC_DEC_TRAC |
---|
[56] | 811 | DTRACE_CABAC_VL( g_nSymbolCounter++ ); |
---|
[2] | 812 | DTRACE_CABAC_T( "\tSkipFlag" ); |
---|
| 813 | DTRACE_CABAC_T( "\tuiCtxSkip: "); |
---|
| 814 | DTRACE_CABAC_V( uiCtxSkip ); |
---|
| 815 | DTRACE_CABAC_T( "\tuiSymbol: "); |
---|
| 816 | DTRACE_CABAC_V( uiSymbol ); |
---|
| 817 | DTRACE_CABAC_T( "\n"); |
---|
[608] | 818 | #else |
---|
| 819 | DTRACE_CU("cu_skip_flag", uiSymbol); |
---|
| 820 | #endif |
---|
[2] | 821 | } |
---|
| 822 | |
---|
| 823 | /** code merge flag |
---|
| 824 | * \param pcCU |
---|
[1200] | 825 | * \param uiAbsPartIdx |
---|
[2] | 826 | * \returns Void |
---|
| 827 | */ |
---|
| 828 | Void TEncSbac::codeMergeFlag( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
| 829 | { |
---|
[56] | 830 | const UInt uiSymbol = pcCU->getMergeFlag( uiAbsPartIdx ) ? 1 : 0; |
---|
| 831 | m_pcBinIf->encodeBin( uiSymbol, *m_cCUMergeFlagExtSCModel.get( 0 ) ); |
---|
[2] | 832 | |
---|
[608] | 833 | #if H_MV_ENC_DEC_TRAC |
---|
| 834 | DTRACE_PU("merge_flag", uiSymbol); |
---|
| 835 | #else |
---|
[56] | 836 | DTRACE_CABAC_VL( g_nSymbolCounter++ ); |
---|
[2] | 837 | DTRACE_CABAC_T( "\tMergeFlag: " ); |
---|
| 838 | DTRACE_CABAC_V( uiSymbol ); |
---|
| 839 | DTRACE_CABAC_T( "\tAddress: " ); |
---|
[1200] | 840 | DTRACE_CABAC_V( pcCU->getCtuRsAddr() ); |
---|
[2] | 841 | DTRACE_CABAC_T( "\tuiAbsPartIdx: " ); |
---|
| 842 | DTRACE_CABAC_V( uiAbsPartIdx ); |
---|
| 843 | DTRACE_CABAC_T( "\n" ); |
---|
[608] | 844 | #endif |
---|
[2] | 845 | } |
---|
| 846 | |
---|
[56] | 847 | /** code merge index |
---|
| 848 | * \param pcCU |
---|
[1200] | 849 | * \param uiAbsPartIdx |
---|
[56] | 850 | * \returns Void |
---|
| 851 | */ |
---|
| 852 | Void TEncSbac::codeMergeIndex( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
[2] | 853 | { |
---|
[56] | 854 | UInt uiUnaryIdx = pcCU->getMergeIndex( uiAbsPartIdx ); |
---|
[608] | 855 | UInt uiNumCand = pcCU->getSlice()->getMaxNumMergeCand(); |
---|
[56] | 856 | if ( uiNumCand > 1 ) |
---|
[2] | 857 | { |
---|
[56] | 858 | for( UInt ui = 0; ui < uiNumCand - 1; ++ui ) |
---|
[2] | 859 | { |
---|
[56] | 860 | const UInt uiSymbol = ui == uiUnaryIdx ? 0 : 1; |
---|
| 861 | if ( ui==0 ) |
---|
[2] | 862 | { |
---|
[56] | 863 | m_pcBinIf->encodeBin( uiSymbol, m_cCUMergeIdxExtSCModel.get( 0, 0, 0 ) ); |
---|
[2] | 864 | } |
---|
[56] | 865 | else |
---|
[2] | 866 | { |
---|
[56] | 867 | m_pcBinIf->encodeBinEP( uiSymbol ); |
---|
[2] | 868 | } |
---|
[56] | 869 | if( uiSymbol == 0 ) |
---|
[2] | 870 | { |
---|
[56] | 871 | break; |
---|
[2] | 872 | } |
---|
| 873 | } |
---|
[608] | 874 | #if H_MV_ENC_DEC_TRAC |
---|
| 875 | DTRACE_PU("merge_idx", uiUnaryIdx); |
---|
| 876 | #endif |
---|
[2] | 877 | } |
---|
[608] | 878 | #if !H_MV_ENC_DEC_TRAC |
---|
[56] | 879 | DTRACE_CABAC_VL( g_nSymbolCounter++ ); |
---|
[2] | 880 | DTRACE_CABAC_T( "\tparseMergeIndex()" ); |
---|
| 881 | DTRACE_CABAC_T( "\tuiMRGIdx= " ); |
---|
| 882 | DTRACE_CABAC_V( pcCU->getMergeIndex( uiAbsPartIdx ) ); |
---|
| 883 | DTRACE_CABAC_T( "\n" ); |
---|
[608] | 884 | #endif |
---|
[2] | 885 | } |
---|
| 886 | |
---|
[1279] | 887 | #if NH_3D_ARP |
---|
[443] | 888 | Void TEncSbac::codeARPW( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
| 889 | { |
---|
[608] | 890 | Int iW = (Int)pcCU->getARPW( uiAbsPartIdx ); |
---|
| 891 | Int iMaxW = pcCU->getSlice()->getARPStepNum() - 1; |
---|
| 892 | assert( iMaxW > 0); |
---|
| 893 | |
---|
| 894 | Int nOffset = pcCU->getCTXARPWFlag(uiAbsPartIdx); |
---|
| 895 | Int nBinNum = iW + ( iW != iMaxW ); |
---|
| 896 | m_pcBinIf->encodeBin( iW ? 1 : 0 , m_cCUPUARPWSCModel.get( 0, 0, 0 + nOffset ) ); |
---|
| 897 | if( nBinNum > 1 ) |
---|
[443] | 898 | { |
---|
[833] | 899 | m_pcBinIf->encodeBin( ( iW == iMaxW ) ? 1 : 0, m_cCUPUARPWSCModel.get( 0, 0, 2 ) ); |
---|
[443] | 900 | } |
---|
[608] | 901 | #if H_MV_ENC_DEC_TRAC |
---|
| 902 | DTRACE_CU("iv_res_pred_weight_idx", iW); |
---|
| 903 | #endif |
---|
[443] | 904 | } |
---|
| 905 | #endif |
---|
[608] | 906 | |
---|
[1279] | 907 | #if NH_3D_IC |
---|
[608] | 908 | /** code Illumination Compensation flag |
---|
| 909 | * \param pcCU |
---|
| 910 | * \param uiAbsPartIdx |
---|
| 911 | * \returns Void |
---|
| 912 | */ |
---|
| 913 | Void TEncSbac::codeICFlag( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
| 914 | { |
---|
| 915 | // get context function is here |
---|
| 916 | UInt uiSymbol = pcCU->getICFlag( uiAbsPartIdx ) ? 1 : 0; |
---|
[833] | 917 | m_pcBinIf->encodeBin( uiSymbol, m_cCUICFlagSCModel.get( 0, 0, 0 ) ); |
---|
[608] | 918 | #if !H_MV_ENC_DEC_TRAC |
---|
| 919 | DTRACE_CABAC_VL( g_nSymbolCounter++ ); |
---|
| 920 | DTRACE_CABAC_T( "\tICFlag" ); |
---|
| 921 | DTRACE_CABAC_T( "\tuiSymbol: "); |
---|
| 922 | DTRACE_CABAC_V( uiSymbol ); |
---|
| 923 | DTRACE_CABAC_T( "\n"); |
---|
| 924 | #else |
---|
| 925 | DTRACE_CU("ic_flag", uiSymbol ); |
---|
| 926 | #endif |
---|
| 927 | } |
---|
| 928 | #endif |
---|
| 929 | |
---|
| 930 | |
---|
[2] | 931 | Void TEncSbac::codeSplitFlag ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth ) |
---|
| 932 | { |
---|
[1200] | 933 | if( uiDepth == pcCU->getSlice()->getSPS()->getLog2DiffMaxMinCodingBlockSize() ) |
---|
| 934 | { |
---|
[2] | 935 | return; |
---|
[1200] | 936 | } |
---|
| 937 | |
---|
[2] | 938 | UInt uiCtx = pcCU->getCtxSplitFlag( uiAbsPartIdx, uiDepth ); |
---|
| 939 | UInt uiCurrSplitFlag = ( pcCU->getDepth( uiAbsPartIdx ) > uiDepth ) ? 1 : 0; |
---|
[1200] | 940 | |
---|
[2] | 941 | assert( uiCtx < 3 ); |
---|
[1279] | 942 | #if NH_3D_QTLPC |
---|
[189] | 943 | Bool bCodeSplitFlag = true; |
---|
| 944 | |
---|
[1124] | 945 | |
---|
| 946 | Bool bLimQtPredFlag = pcCU->getPic()->getSlice(0)->getQtPredFlag(); |
---|
[189] | 947 | TComPic *pcTexture = pcCU->getSlice()->getTexturePic(); |
---|
| 948 | Bool bDepthMapDetect = (pcTexture != NULL); |
---|
| 949 | Bool bIntraSliceDetect = (pcCU->getSlice()->getSliceType() == I_SLICE); |
---|
| 950 | |
---|
[608] | 951 | Bool rapPic = (pcCU->getSlice()->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_W_RADL || pcCU->getSlice()->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_N_LP || pcCU->getSlice()->getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA); |
---|
| 952 | |
---|
[1084] | 953 | #if H_3D_FCO |
---|
[1066] | 954 | if(bDepthMapDetect && !bIntraSliceDetect && !rapPic && pcCU->getPic()->getReduceBitsFlag() && bLimQtPredFlag && pcTexture->getReconMark() ) |
---|
| 955 | #else |
---|
[1039] | 956 | if(bDepthMapDetect && !bIntraSliceDetect && !rapPic && pcCU->getPic()->getReduceBitsFlag() && bLimQtPredFlag ) |
---|
[1066] | 957 | #endif |
---|
[115] | 958 | { |
---|
[1279] | 959 | TComDataCU *pcTextureCU = pcTexture->getCtu(pcCU->getCtuRsAddr()); |
---|
| 960 | UInt uiCUIdx = (pcCU->getZorderIdxInCtu() == 0) ? uiAbsPartIdx : pcCU->getZorderIdxInCtu(); |
---|
[189] | 961 | assert(pcTextureCU->getDepth(uiCUIdx) >= uiDepth); |
---|
| 962 | bCodeSplitFlag = (pcTextureCU->getDepth(uiCUIdx) > uiDepth); |
---|
[115] | 963 | } |
---|
[189] | 964 | |
---|
| 965 | if(!bCodeSplitFlag) |
---|
| 966 | { |
---|
| 967 | assert(uiCurrSplitFlag == 0); |
---|
| 968 | return; |
---|
| 969 | } |
---|
[115] | 970 | #endif |
---|
[1200] | 971 | |
---|
[189] | 972 | m_pcBinIf->encodeBin( uiCurrSplitFlag, m_cCUSplitFlagSCModel.get( 0, 0, uiCtx ) ); |
---|
[608] | 973 | #if !H_MV_ENC_DEC_TRAC |
---|
[56] | 974 | DTRACE_CABAC_VL( g_nSymbolCounter++ ) |
---|
[2] | 975 | DTRACE_CABAC_T( "\tSplitFlag\n" ) |
---|
[608] | 976 | #else |
---|
| 977 | DTRACE_CU("split_cu_flag", uiCurrSplitFlag ); |
---|
| 978 | #endif |
---|
[2] | 979 | return; |
---|
| 980 | } |
---|
| 981 | |
---|
| 982 | Void TEncSbac::codeTransformSubdivFlag( UInt uiSymbol, UInt uiCtx ) |
---|
| 983 | { |
---|
| 984 | m_pcBinIf->encodeBin( uiSymbol, m_cCUTransSubdivFlagSCModel.get( 0, 0, uiCtx ) ); |
---|
[608] | 985 | #if !H_MV_ENC_DEC_TRAC |
---|
[56] | 986 | DTRACE_CABAC_VL( g_nSymbolCounter++ ) |
---|
[2] | 987 | DTRACE_CABAC_T( "\tparseTransformSubdivFlag()" ) |
---|
| 988 | DTRACE_CABAC_T( "\tsymbol=" ) |
---|
| 989 | DTRACE_CABAC_V( uiSymbol ) |
---|
| 990 | DTRACE_CABAC_T( "\tctx=" ) |
---|
| 991 | DTRACE_CABAC_V( uiCtx ) |
---|
| 992 | DTRACE_CABAC_T( "\n" ) |
---|
[1179] | 993 | #else |
---|
| 994 | DTRACE_TU("split_transform_flag", uiSymbol ) |
---|
[608] | 995 | #endif |
---|
[1179] | 996 | |
---|
[2] | 997 | } |
---|
[100] | 998 | |
---|
[1200] | 999 | |
---|
[608] | 1000 | Void TEncSbac::codeIntraDirLumaAng( TComDataCU* pcCU, UInt absPartIdx, Bool isMultiple) |
---|
[100] | 1001 | { |
---|
[608] | 1002 | UInt dir[4],j; |
---|
[1200] | 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}; |
---|
[608] | 1005 | PartSize mode = pcCU->getPartitionSize( absPartIdx ); |
---|
| 1006 | UInt partNum = isMultiple?(mode==SIZE_NxN?4:1):1; |
---|
[1200] | 1007 | UInt partOffset = ( pcCU->getPic()->getNumPartitionsInCtu() >> ( pcCU->getDepth(absPartIdx) << 1 ) ) >> 2; |
---|
[608] | 1008 | for (j=0;j<partNum;j++) |
---|
[100] | 1009 | { |
---|
[1200] | 1010 | dir[j] = pcCU->getIntraDir( CHANNEL_TYPE_LUMA, absPartIdx+partOffset*j ); |
---|
[1209] | 1011 | #if NH_3D_DMM |
---|
[1124] | 1012 | if( pcCU->getSlice()->getIntraSdcWedgeFlag() || pcCU->getSlice()->getIntraContourFlag() ) |
---|
[100] | 1013 | { |
---|
[1209] | 1014 | xCodeIntraDepthMode( pcCU, absPartIdx+partOffset*j ); |
---|
| 1015 | xCodeDmmData ( pcCU, absPartIdx+partOffset*j ); |
---|
[100] | 1016 | } |
---|
[1209] | 1017 | if( pcCU->getIntraDir( CHANNEL_TYPE_LUMA, absPartIdx+partOffset*j ) < NUM_INTRA_MODE ) |
---|
[443] | 1018 | { |
---|
[608] | 1019 | #endif |
---|
[1200] | 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]) |
---|
[608] | 1024 | { |
---|
[1200] | 1025 | predIdx[j] = i; |
---|
[608] | 1026 | } |
---|
[1200] | 1027 | } |
---|
| 1028 | m_pcBinIf->encodeBin((predIdx[j] != -1)? 1 : 0, m_cCUIntraPredSCModel.get( 0, 0, 0 ) ); |
---|
[608] | 1029 | #if H_MV_ENC_DEC_TRAC |
---|
[884] | 1030 | DTRACE_CU("prev_intra_luma_pred_flag", (predIdx[j] != -1)? 1 : 0); |
---|
[608] | 1031 | #endif |
---|
[1209] | 1032 | #if NH_3D_DMM |
---|
[608] | 1033 | } |
---|
| 1034 | #endif |
---|
[100] | 1035 | |
---|
[1200] | 1036 | } |
---|
[608] | 1037 | for (j=0;j<partNum;j++) |
---|
[443] | 1038 | { |
---|
[1209] | 1039 | #if NH_3D_DMM |
---|
| 1040 | if( pcCU->getIntraDir( CHANNEL_TYPE_LUMA, absPartIdx+partOffset*j ) < NUM_INTRA_MODE ) |
---|
[443] | 1041 | { |
---|
[608] | 1042 | #endif |
---|
[1200] | 1043 | if(predIdx[j] != -1) |
---|
| 1044 | { |
---|
| 1045 | m_pcBinIf->encodeBinEP( predIdx[j] ? 1 : 0 ); |
---|
| 1046 | if (predIdx[j]) |
---|
[443] | 1047 | { |
---|
[1200] | 1048 | m_pcBinIf->encodeBinEP( predIdx[j]-1 ); |
---|
| 1049 | } |
---|
[608] | 1050 | #if H_MV_ENC_DEC_TRAC |
---|
[1196] | 1051 | DTRACE_CU("mpm_idx", predIdx[j] ); |
---|
[608] | 1052 | #endif |
---|
[1200] | 1053 | } |
---|
| 1054 | else |
---|
| 1055 | { |
---|
| 1056 | if (preds[j][0] > preds[j][1]) |
---|
| 1057 | { |
---|
| 1058 | std::swap(preds[j][0], preds[j][1]); |
---|
[443] | 1059 | } |
---|
[1200] | 1060 | if (preds[j][0] > preds[j][2]) |
---|
[443] | 1061 | { |
---|
[1200] | 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 ); |
---|
[608] | 1073 | #if H_MV_ENC_DEC_TRAC |
---|
[1196] | 1074 | DTRACE_CU("rem_intra_luma_pred_mode", dir[j] ); |
---|
[608] | 1075 | #endif |
---|
[1200] | 1076 | } |
---|
[1209] | 1077 | #if NH_3D_DMM |
---|
[608] | 1078 | } |
---|
| 1079 | #endif |
---|
[443] | 1080 | } |
---|
[608] | 1081 | return; |
---|
| 1082 | } |
---|
| 1083 | |
---|
| 1084 | Void TEncSbac::codeIntraDirChroma( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
| 1085 | { |
---|
[1200] | 1086 | UInt uiIntraDirChroma = pcCU->getIntraDir( CHANNEL_TYPE_CHROMA, uiAbsPartIdx ); |
---|
[608] | 1087 | |
---|
[1200] | 1088 | if( uiIntraDirChroma == DM_CHROMA_IDX ) |
---|
[443] | 1089 | { |
---|
[608] | 1090 | m_pcBinIf->encodeBin( 0, m_cCUChromaPredSCModel.get( 0, 0, 0 ) ); |
---|
| 1091 | #if H_MV_ENC_DEC_TRAC |
---|
| 1092 | DTRACE_CU("intra_chroma_pred_mode", 0 ); |
---|
| 1093 | #endif |
---|
| 1094 | } |
---|
| 1095 | else |
---|
[1200] | 1096 | { |
---|
| 1097 | m_pcBinIf->encodeBin( 1, m_cCUChromaPredSCModel.get( 0, 0, 0 ) ); |
---|
| 1098 | |
---|
[608] | 1099 | UInt uiAllowedChromaDir[ NUM_CHROMA_MODE ]; |
---|
| 1100 | pcCU->getAllowedChromaDir( uiAbsPartIdx, uiAllowedChromaDir ); |
---|
[443] | 1101 | |
---|
[608] | 1102 | for( Int i = 0; i < NUM_CHROMA_MODE - 1; i++ ) |
---|
[443] | 1103 | { |
---|
[608] | 1104 | if( uiIntraDirChroma == uiAllowedChromaDir[i] ) |
---|
[443] | 1105 | { |
---|
[608] | 1106 | uiIntraDirChroma = i; |
---|
| 1107 | break; |
---|
[443] | 1108 | } |
---|
| 1109 | } |
---|
[608] | 1110 | |
---|
| 1111 | m_pcBinIf->encodeBinsEP( uiIntraDirChroma, 2 ); |
---|
| 1112 | #if H_MV_ENC_DEC_TRAC |
---|
| 1113 | DTRACE_CU("intra_chroma_pred_mode", uiIntraDirChroma ); |
---|
| 1114 | #endif |
---|
| 1115 | |
---|
[443] | 1116 | } |
---|
[1200] | 1117 | |
---|
[608] | 1118 | return; |
---|
[443] | 1119 | } |
---|
[608] | 1120 | |
---|
[2] | 1121 | Void TEncSbac::codeInterDir( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
| 1122 | { |
---|
[56] | 1123 | const UInt uiInterDir = pcCU->getInterDir( uiAbsPartIdx ) - 1; |
---|
| 1124 | const UInt uiCtx = pcCU->getCtxInterDir( uiAbsPartIdx ); |
---|
| 1125 | ContextModel *pCtx = m_cCUInterDirSCModel.get( 0 ); |
---|
[1200] | 1126 | |
---|
[608] | 1127 | if (pcCU->getPartitionSize(uiAbsPartIdx) == SIZE_2Nx2N || pcCU->getHeight(uiAbsPartIdx) != 8 ) |
---|
| 1128 | { |
---|
| 1129 | m_pcBinIf->encodeBin( uiInterDir == 2 ? 1 : 0, *( pCtx + uiCtx ) ); |
---|
| 1130 | } |
---|
[1200] | 1131 | |
---|
[608] | 1132 | if (uiInterDir < 2) |
---|
| 1133 | { |
---|
| 1134 | m_pcBinIf->encodeBin( uiInterDir, *( pCtx + 4 ) ); |
---|
| 1135 | } |
---|
| 1136 | #if H_MV_ENC_DEC_TRAC |
---|
| 1137 | DTRACE_PU("inter_pred_idc", uiInterDir ); |
---|
| 1138 | #endif |
---|
[56] | 1139 | |
---|
[2] | 1140 | return; |
---|
| 1141 | } |
---|
| 1142 | |
---|
| 1143 | Void TEncSbac::codeRefFrmIdx( TComDataCU* pcCU, UInt uiAbsPartIdx, RefPicList eRefList ) |
---|
| 1144 | { |
---|
[1200] | 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 ) |
---|
[2] | 1150 | { |
---|
[1200] | 1151 | UInt uiRefNum = pcCU->getSlice()->getNumRefIdx( eRefList ) - 2; |
---|
| 1152 | pCtx++; |
---|
| 1153 | iRefFrame--; |
---|
| 1154 | for( UInt ui = 0; ui < uiRefNum; ++ui ) |
---|
[2] | 1155 | { |
---|
[1200] | 1156 | const UInt uiSymbol = ui == iRefFrame ? 0 : 1; |
---|
| 1157 | if( ui == 0 ) |
---|
[608] | 1158 | { |
---|
[1200] | 1159 | m_pcBinIf->encodeBin( uiSymbol, *pCtx ); |
---|
[608] | 1160 | } |
---|
[1200] | 1161 | else |
---|
| 1162 | { |
---|
| 1163 | m_pcBinIf->encodeBinEP( uiSymbol ); |
---|
| 1164 | } |
---|
| 1165 | if( uiSymbol == 0 ) |
---|
| 1166 | { |
---|
| 1167 | break; |
---|
| 1168 | } |
---|
[2] | 1169 | } |
---|
[1200] | 1170 | } |
---|
[608] | 1171 | #if H_MV_ENC_DEC_TRAC |
---|
| 1172 | #if ENC_DEC_TRACE |
---|
| 1173 | iRefFrame = pcCU->getCUMvField( eRefList )->getRefIdx( uiAbsPartIdx ); |
---|
| 1174 | if ( eRefList == REF_PIC_LIST_0 ) |
---|
[296] | 1175 | { |
---|
[608] | 1176 | DTRACE_PU("ref_idx_l0", iRefFrame) |
---|
[296] | 1177 | } |
---|
[608] | 1178 | else |
---|
[56] | 1179 | { |
---|
[608] | 1180 | DTRACE_PU("ref_idx_l1", iRefFrame) |
---|
[56] | 1181 | } |
---|
[296] | 1182 | #endif |
---|
[608] | 1183 | #endif |
---|
[2] | 1184 | return; |
---|
| 1185 | } |
---|
| 1186 | |
---|
| 1187 | Void TEncSbac::codeMvd( TComDataCU* pcCU, UInt uiAbsPartIdx, RefPicList eRefList ) |
---|
| 1188 | { |
---|
[56] | 1189 | if(pcCU->getSlice()->getMvdL1ZeroFlag() && eRefList == REF_PIC_LIST_1 && pcCU->getInterDir(uiAbsPartIdx)==3) |
---|
| 1190 | { |
---|
| 1191 | return; |
---|
| 1192 | } |
---|
[2] | 1193 | |
---|
[56] | 1194 | const TComCUMvField* pcCUMvField = pcCU->getCUMvField( eRefList ); |
---|
| 1195 | const Int iHor = pcCUMvField->getMvd( uiAbsPartIdx ).getHor(); |
---|
| 1196 | const Int iVer = pcCUMvField->getMvd( uiAbsPartIdx ).getVer(); |
---|
| 1197 | ContextModel* pCtx = m_cCUMvdSCModel.get( 0 ); |
---|
[2] | 1198 | |
---|
[56] | 1199 | m_pcBinIf->encodeBin( iHor != 0 ? 1 : 0, *pCtx ); |
---|
| 1200 | m_pcBinIf->encodeBin( iVer != 0 ? 1 : 0, *pCtx ); |
---|
[2] | 1201 | |
---|
[56] | 1202 | const Bool bHorAbsGr0 = iHor != 0; |
---|
| 1203 | const Bool bVerAbsGr0 = iVer != 0; |
---|
| 1204 | const UInt uiHorAbs = 0 > iHor ? -iHor : iHor; |
---|
| 1205 | const UInt uiVerAbs = 0 > iVer ? -iVer : iVer; |
---|
| 1206 | pCtx++; |
---|
[2] | 1207 | |
---|
[56] | 1208 | if( bHorAbsGr0 ) |
---|
| 1209 | { |
---|
| 1210 | m_pcBinIf->encodeBin( uiHorAbs > 1 ? 1 : 0, *pCtx ); |
---|
| 1211 | } |
---|
| 1212 | |
---|
| 1213 | if( bVerAbsGr0 ) |
---|
| 1214 | { |
---|
| 1215 | m_pcBinIf->encodeBin( uiVerAbs > 1 ? 1 : 0, *pCtx ); |
---|
| 1216 | } |
---|
| 1217 | |
---|
| 1218 | if( bHorAbsGr0 ) |
---|
| 1219 | { |
---|
| 1220 | if( uiHorAbs > 1 ) |
---|
| 1221 | { |
---|
| 1222 | xWriteEpExGolomb( uiHorAbs-2, 1 ); |
---|
| 1223 | } |
---|
| 1224 | |
---|
| 1225 | m_pcBinIf->encodeBinEP( 0 > iHor ? 1 : 0 ); |
---|
| 1226 | } |
---|
| 1227 | |
---|
| 1228 | if( bVerAbsGr0 ) |
---|
| 1229 | { |
---|
| 1230 | if( uiVerAbs > 1 ) |
---|
| 1231 | { |
---|
| 1232 | xWriteEpExGolomb( uiVerAbs-2, 1 ); |
---|
| 1233 | } |
---|
| 1234 | |
---|
| 1235 | m_pcBinIf->encodeBinEP( 0 > iVer ? 1 : 0 ); |
---|
| 1236 | } |
---|
[1200] | 1237 | |
---|
[2] | 1238 | return; |
---|
| 1239 | } |
---|
| 1240 | |
---|
[1200] | 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 | |
---|
[2] | 1287 | Void TEncSbac::codeDeltaQP( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
| 1288 | { |
---|
[56] | 1289 | Int iDQp = pcCU->getQP( uiAbsPartIdx ) - pcCU->getRefQP( uiAbsPartIdx ); |
---|
[1200] | 1290 | |
---|
| 1291 | Int qpBdOffsetY = pcCU->getSlice()->getSPS()->getQpBDOffset(CHANNEL_TYPE_LUMA); |
---|
[56] | 1292 | iDQp = (iDQp + 78 + qpBdOffsetY + (qpBdOffsetY/2)) % (52 + qpBdOffsetY) - 26 - (qpBdOffsetY/2); |
---|
| 1293 | |
---|
[608] | 1294 | UInt uiAbsDQp = (UInt)((iDQp > 0)? iDQp : (-iDQp)); |
---|
| 1295 | UInt TUValue = min((Int)uiAbsDQp, CU_DQP_TU_CMAX); |
---|
| 1296 | xWriteUnaryMaxSymbol( TUValue, &m_cCUDeltaQpSCModel.get( 0, 0, 0 ), 1, CU_DQP_TU_CMAX); |
---|
| 1297 | if( uiAbsDQp >= CU_DQP_TU_CMAX ) |
---|
[2] | 1298 | { |
---|
[608] | 1299 | xWriteEpExGolomb( uiAbsDQp - CU_DQP_TU_CMAX, CU_DQP_EG_k ); |
---|
[2] | 1300 | } |
---|
[608] | 1301 | |
---|
| 1302 | if ( uiAbsDQp > 0) |
---|
[2] | 1303 | { |
---|
[56] | 1304 | UInt uiSign = (iDQp > 0 ? 0 : 1); |
---|
| 1305 | m_pcBinIf->encodeBinEP(uiSign); |
---|
[608] | 1306 | } |
---|
[56] | 1307 | |
---|
[2] | 1308 | return; |
---|
| 1309 | } |
---|
| 1310 | |
---|
[1200] | 1311 | /** code chroma qp adjustment, converting from the internal table representation |
---|
| 1312 | * \returns Void |
---|
| 1313 | */ |
---|
| 1314 | Void TEncSbac::codeChromaQpAdjustment( TComDataCU* cu, UInt absPartIdx ) |
---|
[2] | 1315 | { |
---|
[1200] | 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) |
---|
[1179] | 1323 | { |
---|
[1200] | 1324 | xWriteUnaryMaxSymbol( internalIdc - 1, &m_ChromaQpAdjIdcSCModel.get( 0, 0, 0 ), 0, chromaQpOffsetListLen - 1 ); |
---|
[1179] | 1325 | } |
---|
[1200] | 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 |
---|
[1179] | 1358 | { |
---|
[1200] | 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)); |
---|
| 1368 | #if !H_MV_ENC_DEC_TRAC |
---|
| 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" ) |
---|
| 1382 | #else |
---|
| 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 | } |
---|
[1179] | 1397 | } |
---|
| 1398 | else |
---|
| 1399 | { |
---|
[1200] | 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 | |
---|
[1179] | 1429 | } |
---|
[2] | 1430 | } |
---|
| 1431 | |
---|
[1200] | 1432 | |
---|
| 1433 | Void TEncSbac::codeTransformSkipFlags (TComTU &rTu, ComponentID component ) |
---|
[608] | 1434 | { |
---|
[1200] | 1435 | TComDataCU* pcCU=rTu.getCU(); |
---|
| 1436 | const UInt uiAbsPartIdx=rTu.GetAbsPartIdxTU(); |
---|
| 1437 | |
---|
[608] | 1438 | if (pcCU->getCUTransquantBypass(uiAbsPartIdx)) |
---|
| 1439 | { |
---|
| 1440 | return; |
---|
| 1441 | } |
---|
[1200] | 1442 | |
---|
| 1443 | if (!TUCompRectHasAssociatedTransformSkipFlag(rTu.getRect(component), pcCU->getSlice()->getPPS()->getPpsRangeExtension().getLog2MaxTransformSkipBlockSize())) |
---|
[608] | 1444 | { |
---|
| 1445 | return; |
---|
| 1446 | } |
---|
| 1447 | |
---|
[1200] | 1448 | UInt useTransformSkip = pcCU->getTransformSkip( uiAbsPartIdx,component); |
---|
| 1449 | m_pcBinIf->encodeBin( useTransformSkip, m_cTransformSkipSCModel.get( 0, toChannelType(component), 0 ) ); |
---|
[608] | 1450 | #if !H_MV_ENC_DEC_TRAC |
---|
| 1451 | DTRACE_CABAC_VL( g_nSymbolCounter++ ) |
---|
| 1452 | DTRACE_CABAC_T("\tparseTransformSkip()"); |
---|
| 1453 | DTRACE_CABAC_T( "\tsymbol=" ) |
---|
| 1454 | DTRACE_CABAC_V( useTransformSkip ) |
---|
| 1455 | DTRACE_CABAC_T( "\tAddr=" ) |
---|
[1200] | 1456 | DTRACE_CABAC_V( pcCU->getCtuRsAddr() ) |
---|
[608] | 1457 | DTRACE_CABAC_T( "\tetype=" ) |
---|
[1200] | 1458 | DTRACE_CABAC_V( component ) |
---|
[608] | 1459 | DTRACE_CABAC_T( "\tuiAbsPartIdx=" ) |
---|
[1200] | 1460 | DTRACE_CABAC_V( rTu.GetAbsPartIdxTU() ) |
---|
[608] | 1461 | DTRACE_CABAC_T( "\n" ) |
---|
| 1462 | #endif |
---|
| 1463 | } |
---|
| 1464 | |
---|
[1200] | 1465 | |
---|
[608] | 1466 | /** Code I_PCM information. |
---|
[56] | 1467 | * \param pcCU pointer to CU |
---|
| 1468 | * \param uiAbsPartIdx CU index |
---|
| 1469 | * \returns Void |
---|
| 1470 | */ |
---|
[608] | 1471 | Void TEncSbac::codeIPCMInfo( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
[2] | 1472 | { |
---|
[56] | 1473 | UInt uiIPCM = (pcCU->getIPCMFlag(uiAbsPartIdx) == true)? 1 : 0; |
---|
| 1474 | |
---|
| 1475 | Bool writePCMSampleFlag = pcCU->getIPCMFlag(uiAbsPartIdx); |
---|
| 1476 | |
---|
[608] | 1477 | m_pcBinIf->encodeBinTrm (uiIPCM); |
---|
| 1478 | #if H_MV_ENC_DEC_TRAC |
---|
| 1479 | DTRACE_CU("pcm_flag", uiIPCM) |
---|
| 1480 | #endif |
---|
| 1481 | if (writePCMSampleFlag) |
---|
[2] | 1482 | { |
---|
[608] | 1483 | m_pcBinIf->encodePCMAlignBits(); |
---|
[56] | 1484 | |
---|
[1200] | 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++) |
---|
[56] | 1488 | { |
---|
[1200] | 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++) |
---|
[2] | 1496 | { |
---|
[1200] | 1497 | for (UInt x=0; x<width; x++) |
---|
[1196] | 1498 | { |
---|
[1200] | 1499 | UInt sample = pPCMSample[x]; |
---|
| 1500 | m_pcBinIf->xWritePCMCode(sample, sampleBits); |
---|
[1196] | 1501 | } |
---|
[1200] | 1502 | pPCMSample += width; |
---|
[56] | 1503 | } |
---|
[1179] | 1504 | } |
---|
[608] | 1505 | m_pcBinIf->resetBac(); |
---|
[2] | 1506 | } |
---|
| 1507 | } |
---|
| 1508 | |
---|
| 1509 | Void TEncSbac::codeQtRootCbf( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
| 1510 | { |
---|
| 1511 | UInt uiCbf = pcCU->getQtRootCbf( uiAbsPartIdx ); |
---|
[56] | 1512 | UInt uiCtx = 0; |
---|
[2] | 1513 | m_pcBinIf->encodeBin( uiCbf , m_cCUQtRootCbfSCModel.get( 0, 0, uiCtx ) ); |
---|
[608] | 1514 | #if !H_MV_ENC_DEC_TRAC |
---|
[56] | 1515 | DTRACE_CABAC_VL( g_nSymbolCounter++ ) |
---|
[2] | 1516 | DTRACE_CABAC_T( "\tparseQtRootCbf()" ) |
---|
| 1517 | DTRACE_CABAC_T( "\tsymbol=" ) |
---|
| 1518 | DTRACE_CABAC_V( uiCbf ) |
---|
| 1519 | DTRACE_CABAC_T( "\tctx=" ) |
---|
| 1520 | DTRACE_CABAC_V( uiCtx ) |
---|
| 1521 | DTRACE_CABAC_T( "\tuiAbsPartIdx=" ) |
---|
| 1522 | DTRACE_CABAC_V( uiAbsPartIdx ) |
---|
| 1523 | DTRACE_CABAC_T( "\n" ) |
---|
[608] | 1524 | #else |
---|
| 1525 | DTRACE_CU( "rqt_root_cbf", uiCbf ) |
---|
| 1526 | #endif |
---|
[2] | 1527 | } |
---|
| 1528 | |
---|
[1200] | 1529 | Void TEncSbac::codeQtCbfZero( TComTU & rTu, const ChannelType chType ) |
---|
[608] | 1530 | { |
---|
| 1531 | // this function is only used to estimate the bits when cbf is 0 |
---|
| 1532 | // and will never be called when writing the bistream. do not need to write log |
---|
| 1533 | UInt uiCbf = 0; |
---|
[1200] | 1534 | UInt uiCtx = rTu.getCU()->getCtxQtCbf( rTu, chType ); |
---|
| 1535 | |
---|
| 1536 | m_pcBinIf->encodeBin( uiCbf , m_cCUQtCbfSCModel.get( 0, chType, uiCtx ) ); |
---|
[608] | 1537 | } |
---|
| 1538 | |
---|
[1200] | 1539 | Void TEncSbac::codeQtRootCbfZero( ) |
---|
[608] | 1540 | { |
---|
| 1541 | // this function is only used to estimate the bits when cbf is 0 |
---|
| 1542 | // and will never be called when writing the bistream. do not need to write log |
---|
| 1543 | UInt uiCbf = 0; |
---|
| 1544 | UInt uiCtx = 0; |
---|
| 1545 | m_pcBinIf->encodeBin( uiCbf , m_cCUQtRootCbfSCModel.get( 0, 0, uiCtx ) ); |
---|
| 1546 | } |
---|
| 1547 | |
---|
[2] | 1548 | /** Encode (X,Y) position of the last significant coefficient |
---|
[1200] | 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) |
---|
[2] | 1555 | * This method encodes the X and Y component within a block of the last significant coefficient. |
---|
| 1556 | */ |
---|
[1200] | 1557 | Void TEncSbac::codeLastSignificantXY( UInt uiPosX, UInt uiPosY, Int width, Int height, ComponentID component, UInt uiScanIdx ) |
---|
| 1558 | { |
---|
[56] | 1559 | // swap |
---|
[2] | 1560 | if( uiScanIdx == SCAN_VER ) |
---|
| 1561 | { |
---|
| 1562 | swap( uiPosX, uiPosY ); |
---|
[1200] | 1563 | swap( width, height ); |
---|
[2] | 1564 | } |
---|
| 1565 | |
---|
[56] | 1566 | UInt uiCtxLast; |
---|
| 1567 | UInt uiGroupIdxX = g_uiGroupIdx[ uiPosX ]; |
---|
| 1568 | UInt uiGroupIdxY = g_uiGroupIdx[ uiPosY ]; |
---|
| 1569 | |
---|
[1200] | 1570 | ContextModel *pCtxX = m_cCuCtxLastX.get( 0, toChannelType(component) ); |
---|
| 1571 | ContextModel *pCtxY = m_cCuCtxLastY.get( 0, toChannelType(component) ); |
---|
[608] | 1572 | |
---|
| 1573 | Int blkSizeOffsetX, blkSizeOffsetY, shiftX, shiftY; |
---|
[1200] | 1574 | getLastSignificantContextParameters(component, width, height, blkSizeOffsetX, blkSizeOffsetY, shiftX, shiftY); |
---|
| 1575 | |
---|
| 1576 | //------------------ |
---|
| 1577 | |
---|
[56] | 1578 | // posX |
---|
[1200] | 1579 | |
---|
[56] | 1580 | for( uiCtxLast = 0; uiCtxLast < uiGroupIdxX; uiCtxLast++ ) |
---|
[2] | 1581 | { |
---|
[1200] | 1582 | m_pcBinIf->encodeBin( 1, *( pCtxX + blkSizeOffsetX + (uiCtxLast >>shiftX) ) ); |
---|
[2] | 1583 | } |
---|
[56] | 1584 | if( uiGroupIdxX < g_uiGroupIdx[ width - 1 ]) |
---|
[2] | 1585 | { |
---|
[1200] | 1586 | m_pcBinIf->encodeBin( 0, *( pCtxX + blkSizeOffsetX + (uiCtxLast >>shiftX) ) ); |
---|
[2] | 1587 | } |
---|
| 1588 | |
---|
[56] | 1589 | // posY |
---|
[1200] | 1590 | |
---|
[56] | 1591 | for( uiCtxLast = 0; uiCtxLast < uiGroupIdxY; uiCtxLast++ ) |
---|
[2] | 1592 | { |
---|
[608] | 1593 | m_pcBinIf->encodeBin( 1, *( pCtxY + blkSizeOffsetY + (uiCtxLast >>shiftY) ) ); |
---|
[2] | 1594 | } |
---|
[56] | 1595 | if( uiGroupIdxY < g_uiGroupIdx[ height - 1 ]) |
---|
[2] | 1596 | { |
---|
[608] | 1597 | m_pcBinIf->encodeBin( 0, *( pCtxY + blkSizeOffsetY + (uiCtxLast >>shiftY) ) ); |
---|
| 1598 | } |
---|
[1200] | 1599 | |
---|
| 1600 | // EP-coded part |
---|
| 1601 | |
---|
[56] | 1602 | if ( uiGroupIdxX > 3 ) |
---|
[1200] | 1603 | { |
---|
[56] | 1604 | UInt uiCount = ( uiGroupIdxX - 2 ) >> 1; |
---|
| 1605 | uiPosX = uiPosX - g_uiMinInGroup[ uiGroupIdxX ]; |
---|
| 1606 | for (Int i = uiCount - 1 ; i >= 0; i-- ) |
---|
| 1607 | { |
---|
| 1608 | m_pcBinIf->encodeBinEP( ( uiPosX >> i ) & 1 ); |
---|
| 1609 | } |
---|
[2] | 1610 | } |
---|
[56] | 1611 | if ( uiGroupIdxY > 3 ) |
---|
[1200] | 1612 | { |
---|
[56] | 1613 | UInt uiCount = ( uiGroupIdxY - 2 ) >> 1; |
---|
| 1614 | uiPosY = uiPosY - g_uiMinInGroup[ uiGroupIdxY ]; |
---|
| 1615 | for ( Int i = uiCount - 1 ; i >= 0; i-- ) |
---|
| 1616 | { |
---|
| 1617 | m_pcBinIf->encodeBinEP( ( uiPosY >> i ) & 1 ); |
---|
| 1618 | } |
---|
| 1619 | } |
---|
[2] | 1620 | } |
---|
| 1621 | |
---|
[1200] | 1622 | |
---|
| 1623 | Void TEncSbac::codeCoeffNxN( TComTU &rTu, TCoeff* pcCoef, const ComponentID compID ) |
---|
[2] | 1624 | { |
---|
[1200] | 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()); |
---|
[608] | 1631 | #if !H_MV_ENC_DEC_TRAC |
---|
[1200] | 1632 | |
---|
[56] | 1633 | DTRACE_CABAC_VL( g_nSymbolCounter++ ) |
---|
[2] | 1634 | DTRACE_CABAC_T( "\tparseCoeffNxN()\teType=" ) |
---|
[1200] | 1635 | DTRACE_CABAC_V( compID ) |
---|
[2] | 1636 | DTRACE_CABAC_T( "\twidth=" ) |
---|
| 1637 | DTRACE_CABAC_V( uiWidth ) |
---|
| 1638 | DTRACE_CABAC_T( "\theight=" ) |
---|
| 1639 | DTRACE_CABAC_V( uiHeight ) |
---|
| 1640 | DTRACE_CABAC_T( "\tdepth=" ) |
---|
[1200] | 1641 | // DTRACE_CABAC_V( rTu.GetTransformDepthTotalAdj(compID) ) |
---|
| 1642 | DTRACE_CABAC_V( rTu.GetTransformDepthTotal() ) |
---|
[2] | 1643 | DTRACE_CABAC_T( "\tabspartidx=" ) |
---|
| 1644 | DTRACE_CABAC_V( uiAbsPartIdx ) |
---|
| 1645 | DTRACE_CABAC_T( "\ttoCU-X=" ) |
---|
| 1646 | DTRACE_CABAC_V( pcCU->getCUPelX() ) |
---|
| 1647 | DTRACE_CABAC_T( "\ttoCU-Y=" ) |
---|
| 1648 | DTRACE_CABAC_V( pcCU->getCUPelY() ) |
---|
| 1649 | DTRACE_CABAC_T( "\tCU-addr=" ) |
---|
[1200] | 1650 | DTRACE_CABAC_V( pcCU->getCtuRsAddr() ) |
---|
[2] | 1651 | DTRACE_CABAC_T( "\tinCU-X=" ) |
---|
[1200] | 1652 | // DTRACE_CABAC_V( g_auiRasterToPelX[ g_auiZscanToRaster[uiAbsPartIdx] ] ) |
---|
| 1653 | DTRACE_CABAC_V( g_auiRasterToPelX[ g_auiZscanToRaster[rTu.GetAbsPartIdxTU(compID)] ] ) |
---|
[2] | 1654 | DTRACE_CABAC_T( "\tinCU-Y=" ) |
---|
[1200] | 1655 | // DTRACE_CABAC_V( g_auiRasterToPelY[ g_auiZscanToRaster[uiAbsPartIdx] ] ) |
---|
| 1656 | DTRACE_CABAC_V( g_auiRasterToPelY[ g_auiZscanToRaster[rTu.GetAbsPartIdxTU(compID)] ] ) |
---|
[2] | 1657 | DTRACE_CABAC_T( "\tpredmode=" ) |
---|
| 1658 | DTRACE_CABAC_V( pcCU->getPredictionMode( uiAbsPartIdx ) ) |
---|
| 1659 | DTRACE_CABAC_T( "\n" ) |
---|
[608] | 1660 | #endif |
---|
[1200] | 1661 | |
---|
| 1662 | //-------------------------------------------------------------------------------------------------- |
---|
| 1663 | |
---|
| 1664 | if( uiWidth > sps.getMaxTrSize() ) |
---|
[2] | 1665 | { |
---|
[1200] | 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); |
---|
[2] | 1669 | } |
---|
[1200] | 1670 | |
---|
[2] | 1671 | // compute number of significant coefficients |
---|
[1200] | 1672 | UInt uiNumSig = TEncEntropy::countNonZeroCoeffs(pcCoef, uiWidth * uiHeight); |
---|
| 1673 | |
---|
[2] | 1674 | if ( uiNumSig == 0 ) |
---|
[608] | 1675 | { |
---|
[1200] | 1676 | std::cerr << "ERROR: codeCoeffNxN called for empty TU!" << std::endl; |
---|
| 1677 | assert(false); |
---|
| 1678 | exit(1); |
---|
[608] | 1679 | } |
---|
[1200] | 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 | |
---|
[608] | 1695 | Bool beValid; |
---|
[1200] | 1696 | |
---|
[56] | 1697 | { |
---|
[1200] | 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 ); |
---|
[2] | 1704 | |
---|
[1200] | 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 | } |
---|
[56] | 1709 | |
---|
[1200] | 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 ) |
---|
[56] | 1714 | { |
---|
[1200] | 1715 | beValid = false; |
---|
| 1716 | if ( (!pcCU->isIntra(uiAbsPartIdx)) && pcCU->isRDPCMEnabled(uiAbsPartIdx)) |
---|
| 1717 | { |
---|
| 1718 | codeExplicitRdpcmMode( rTu, compID); |
---|
| 1719 | } |
---|
[2] | 1720 | } |
---|
[1200] | 1721 | else |
---|
[56] | 1722 | { |
---|
[1200] | 1723 | beValid = pcCU->getSlice()->getPPS()->getSignHideFlag(); |
---|
[56] | 1724 | } |
---|
| 1725 | } |
---|
[2] | 1726 | |
---|
[1200] | 1727 | //-------------------------------------------------------------------------------------------------- |
---|
[56] | 1728 | |
---|
[1200] | 1729 | if(pcCU->getSlice()->getPPS()->getUseTransformSkip()) |
---|
| 1730 | { |
---|
| 1731 | codeTransformSkipFlags(rTu, compID); |
---|
| 1732 | if(pcCU->getTransformSkip(uiAbsPartIdx, compID) && !pcCU->isIntra(uiAbsPartIdx) && pcCU->isRDPCMEnabled(uiAbsPartIdx)) |
---|
[2] | 1733 | { |
---|
[1200] | 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); |
---|
[56] | 1736 | |
---|
[1200] | 1737 | if(pcCU->getExplicitRdpcmMode(compID, uiAbsPartIdx) != RDPCM_OFF) |
---|
[2] | 1738 | { |
---|
[1200] | 1739 | // Sign data hiding is avoided for horizontal and vertical explicit RDPCM modes |
---|
| 1740 | beValid = false; |
---|
[2] | 1741 | } |
---|
[1200] | 1742 | } |
---|
| 1743 | } |
---|
[56] | 1744 | |
---|
[1200] | 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 | |
---|
| 1754 | //----- encode significance map ----- |
---|
| 1755 | |
---|
| 1756 | // Find position of last coefficient |
---|
| 1757 | Int scanPosLast = -1; |
---|
| 1758 | Int posLast; |
---|
| 1759 | |
---|
| 1760 | |
---|
| 1761 | UInt uiSigCoeffGroupFlag[ MLS_GRP_NUM ]; |
---|
| 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 | { |
---|
| 1770 | // get L1 sig map |
---|
| 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--; |
---|
[2] | 1778 | } |
---|
[1200] | 1779 | } while ( uiNumSig > 0 ); |
---|
[56] | 1780 | |
---|
| 1781 | // Code position of last coefficient |
---|
[1200] | 1782 | Int posLastY = posLast >> uiLog2BlockWidth; |
---|
| 1783 | Int posLastX = posLast - ( posLastY << uiLog2BlockWidth ); |
---|
| 1784 | codeLastSignificantXY(posLastX, posLastY, uiWidth, uiHeight, compID, codingParameters.scanType); |
---|
| 1785 | |
---|
[56] | 1786 | //===== code significance flag ===== |
---|
[1200] | 1787 | ContextModel * const baseCoeffGroupCtx = m_cCUSigCoeffGroupSCModel.get( 0, chType ); |
---|
| 1788 | ContextModel * const baseCtx = m_cCUSigSCModel.get( 0, 0 ) + getSignificanceMapContextOffset(compID); |
---|
[56] | 1789 | |
---|
[1200] | 1790 | const Int iLastScanSet = scanPosLast >> MLS_CG_SIZE; |
---|
[56] | 1791 | |
---|
[1200] | 1792 | UInt c1 = 1; |
---|
| 1793 | UInt uiGoRiceParam = 0; |
---|
| 1794 | Int iScanPosSig = scanPosLast; |
---|
[56] | 1795 | |
---|
| 1796 | for( Int iSubSet = iLastScanSet; iSubSet >= 0; iSubSet-- ) |
---|
[2] | 1797 | { |
---|
[56] | 1798 | Int numNonZero = 0; |
---|
[1200] | 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 |
---|
[56] | 1802 | UInt coeffSigns = 0; |
---|
| 1803 | |
---|
[1200] | 1804 | Int absCoeff[1 << MLS_CG_SIZE]; |
---|
[56] | 1805 | |
---|
[1200] | 1806 | Int lastNZPosInCG = -1; |
---|
| 1807 | Int firstNZPosInCG = 1 << MLS_CG_SIZE; |
---|
| 1808 | |
---|
| 1809 | Bool escapeDataPresentInGroup = false; |
---|
| 1810 | |
---|
[56] | 1811 | if( iScanPosSig == scanPosLast ) |
---|
[2] | 1812 | { |
---|
[1200] | 1813 | absCoeff[ 0 ] = Int(abs( pcCoef[ posLast ] )); |
---|
[56] | 1814 | coeffSigns = ( pcCoef[ posLast ] < 0 ); |
---|
| 1815 | numNonZero = 1; |
---|
| 1816 | lastNZPosInCG = iScanPosSig; |
---|
| 1817 | firstNZPosInCG = iScanPosSig; |
---|
| 1818 | iScanPosSig--; |
---|
| 1819 | } |
---|
[2] | 1820 | |
---|
[1200] | 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-- ) |
---|
[2] | 1844 | { |
---|
[1200] | 1845 | uiBlkPos = codingParameters.scan[ iScanPosSig ]; |
---|
| 1846 | uiSig = (pcCoef[ uiBlkPos ] != 0); |
---|
| 1847 | if( iScanPosSig > iSubPos || iSubSet == 0 || numNonZero ) |
---|
[2] | 1848 | { |
---|
[1200] | 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 ) |
---|
[2] | 1858 | { |
---|
[1200] | 1859 | lastNZPosInCG = iScanPosSig; |
---|
[56] | 1860 | } |
---|
[1200] | 1861 | firstNZPosInCG = iScanPosSig; |
---|
[2] | 1862 | } |
---|
[56] | 1863 | } |
---|
[1200] | 1864 | } |
---|
| 1865 | else |
---|
| 1866 | { |
---|
| 1867 | iScanPosSig = iSubPos - 1; |
---|
| 1868 | } |
---|
[56] | 1869 | |
---|
| 1870 | if( numNonZero > 0 ) |
---|
| 1871 | { |
---|
[608] | 1872 | Bool signHidden = ( lastNZPosInCG - firstNZPosInCG >= SBH_THRESHOLD ); |
---|
[1200] | 1873 | |
---|
| 1874 | const UInt uiCtxSet = getContextSetIndex(compID, iSubSet, (c1 == 0)); |
---|
[608] | 1875 | c1 = 1; |
---|
[1200] | 1876 | |
---|
| 1877 | ContextModel *baseCtxMod = m_cCUOneSCModel.get( 0, 0 ) + (NUM_ONE_FLAG_CTX_PER_SET * uiCtxSet); |
---|
| 1878 | |
---|
[56] | 1879 | Int numC1Flag = min(numNonZero, C1FLAG_NUMBER); |
---|
| 1880 | Int firstC2FlagIdx = -1; |
---|
| 1881 | for( Int idx = 0; idx < numC1Flag; idx++ ) |
---|
[2] | 1882 | { |
---|
[56] | 1883 | UInt uiSymbol = absCoeff[ idx ] > 1; |
---|
| 1884 | m_pcBinIf->encodeBin( uiSymbol, baseCtxMod[c1] ); |
---|
[2] | 1885 | if( uiSymbol ) |
---|
| 1886 | { |
---|
| 1887 | c1 = 0; |
---|
[56] | 1888 | |
---|
| 1889 | if (firstC2FlagIdx == -1) |
---|
| 1890 | { |
---|
| 1891 | firstC2FlagIdx = idx; |
---|
| 1892 | } |
---|
[1200] | 1893 | else //if a greater-than-one has been encountered already this group |
---|
| 1894 | { |
---|
| 1895 | escapeDataPresentInGroup = true; |
---|
| 1896 | } |
---|
[2] | 1897 | } |
---|
[56] | 1898 | else if( (c1 < 3) && (c1 > 0) ) |
---|
[2] | 1899 | { |
---|
| 1900 | c1++; |
---|
| 1901 | } |
---|
| 1902 | } |
---|
[1200] | 1903 | |
---|
[56] | 1904 | if (c1 == 0) |
---|
[2] | 1905 | { |
---|
[1200] | 1906 | baseCtxMod = m_cCUAbsSCModel.get( 0, 0 ) + (NUM_ABS_FLAG_CTX_PER_SET * uiCtxSet); |
---|
[56] | 1907 | if ( firstC2FlagIdx != -1) |
---|
[2] | 1908 | { |
---|
[56] | 1909 | UInt symbol = absCoeff[ firstC2FlagIdx ] > 2; |
---|
| 1910 | m_pcBinIf->encodeBin( symbol, baseCtxMod[0] ); |
---|
[1200] | 1911 | if (symbol != 0) |
---|
| 1912 | { |
---|
| 1913 | escapeDataPresentInGroup = true; |
---|
| 1914 | } |
---|
[56] | 1915 | } |
---|
[2] | 1916 | } |
---|
[1200] | 1917 | |
---|
| 1918 | escapeDataPresentInGroup = escapeDataPresentInGroup || (numNonZero > C1FLAG_NUMBER); |
---|
| 1919 | |
---|
| 1920 | if (escapeDataPresentInGroup && alignCABACBeforeBypass) |
---|
| 1921 | { |
---|
| 1922 | m_pcBinIf->align(); |
---|
| 1923 | } |
---|
| 1924 | |
---|
[56] | 1925 | if( beValid && signHidden ) |
---|
[2] | 1926 | { |
---|
[56] | 1927 | m_pcBinIf->encodeBinsEP( (coeffSigns >> 1), numNonZero-1 ); |
---|
[2] | 1928 | } |
---|
[56] | 1929 | else |
---|
| 1930 | { |
---|
| 1931 | m_pcBinIf->encodeBinsEP( coeffSigns, numNonZero ); |
---|
| 1932 | } |
---|
[1200] | 1933 | |
---|
| 1934 | Int iFirstCoeff2 = 1; |
---|
| 1935 | if (escapeDataPresentInGroup) |
---|
[56] | 1936 | { |
---|
| 1937 | for ( Int idx = 0; idx < numNonZero; idx++ ) |
---|
| 1938 | { |
---|
| 1939 | UInt baseLevel = (idx < C1FLAG_NUMBER)? (2 + iFirstCoeff2 ) : 1; |
---|
[2] | 1940 | |
---|
[56] | 1941 | if( absCoeff[ idx ] >= baseLevel) |
---|
| 1942 | { |
---|
[1200] | 1943 | const UInt escapeCodeValue = absCoeff[idx] - baseLevel; |
---|
| 1944 | |
---|
| 1945 | xWriteCoefRemainExGolomb( escapeCodeValue, uiGoRiceParam, extendedPrecision, maxLog2TrDynamicRange ); |
---|
| 1946 | |
---|
| 1947 | if (absCoeff[idx] > (3 << uiGoRiceParam)) |
---|
[608] | 1948 | { |
---|
[1200] | 1949 | uiGoRiceParam = bUseGolombRiceParameterAdaptation ? (uiGoRiceParam + 1) : (std::min<UInt>((uiGoRiceParam + 1), 4)); |
---|
[608] | 1950 | } |
---|
[1200] | 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; |
---|
| 1966 | } |
---|
[56] | 1967 | } |
---|
[1200] | 1968 | |
---|
| 1969 | if(absCoeff[ idx ] >= 2) |
---|
[56] | 1970 | { |
---|
| 1971 | iFirstCoeff2 = 0; |
---|
| 1972 | } |
---|
[1200] | 1973 | } |
---|
[56] | 1974 | } |
---|
[2] | 1975 | } |
---|
| 1976 | } |
---|
[1200] | 1977 | #if ENVIRONMENT_VARIABLE_DEBUG_AND_TEST |
---|
| 1978 | printSBACCoeffData(posLastX, posLastY, uiWidth, uiHeight, compID, uiAbsPartIdx, codingParameters.scanType, pcCoef, pcCU->getSlice()->getFinalized()); |
---|
| 1979 | #endif |
---|
[56] | 1980 | |
---|
[2] | 1981 | return; |
---|
| 1982 | } |
---|
| 1983 | |
---|
[608] | 1984 | /** code SAO offset sign |
---|
| 1985 | * \param code sign value |
---|
| 1986 | */ |
---|
[443] | 1987 | Void TEncSbac::codeSAOSign( UInt code ) |
---|
| 1988 | { |
---|
| 1989 | m_pcBinIf->encodeBinEP( code ); |
---|
| 1990 | } |
---|
[2] | 1991 | |
---|
[443] | 1992 | Void TEncSbac::codeSaoMaxUvlc ( UInt code, UInt maxSymbol ) |
---|
| 1993 | { |
---|
| 1994 | if (maxSymbol == 0) |
---|
| 1995 | { |
---|
| 1996 | return; |
---|
| 1997 | } |
---|
| 1998 | |
---|
| 1999 | Int i; |
---|
| 2000 | Bool bCodeLast = ( maxSymbol > code ); |
---|
| 2001 | |
---|
| 2002 | if ( code == 0 ) |
---|
| 2003 | { |
---|
| 2004 | m_pcBinIf->encodeBinEP( 0 ); |
---|
| 2005 | } |
---|
| 2006 | else |
---|
| 2007 | { |
---|
| 2008 | m_pcBinIf->encodeBinEP( 1 ); |
---|
| 2009 | for ( i=0; i<code-1; i++ ) |
---|
| 2010 | { |
---|
| 2011 | m_pcBinIf->encodeBinEP( 1 ); |
---|
| 2012 | } |
---|
| 2013 | if( bCodeLast ) |
---|
| 2014 | { |
---|
| 2015 | m_pcBinIf->encodeBinEP( 0 ); |
---|
| 2016 | } |
---|
| 2017 | } |
---|
| 2018 | } |
---|
| 2019 | |
---|
[1200] | 2020 | /** Code SAO EO class or BO band position |
---|
[443] | 2021 | */ |
---|
| 2022 | Void TEncSbac::codeSaoUflc ( UInt uiLength, UInt uiCode ) |
---|
| 2023 | { |
---|
[1200] | 2024 | m_pcBinIf->encodeBinsEP ( uiCode, uiLength ); |
---|
[443] | 2025 | } |
---|
[1200] | 2026 | |
---|
[443] | 2027 | /** Code SAO merge flags |
---|
| 2028 | */ |
---|
| 2029 | Void TEncSbac::codeSaoMerge ( UInt uiCode ) |
---|
| 2030 | { |
---|
[1200] | 2031 | m_pcBinIf->encodeBin(((uiCode == 0) ? 0 : 1), m_cSaoMergeSCModel.get( 0, 0, 0 )); |
---|
[443] | 2032 | } |
---|
[1200] | 2033 | |
---|
| 2034 | /** Code SAO type index |
---|
[443] | 2035 | */ |
---|
| 2036 | Void TEncSbac::codeSaoTypeIdx ( UInt uiCode) |
---|
| 2037 | { |
---|
| 2038 | if (uiCode == 0) |
---|
| 2039 | { |
---|
| 2040 | m_pcBinIf->encodeBin( 0, m_cSaoTypeIdxSCModel.get( 0, 0, 0 ) ); |
---|
| 2041 | } |
---|
| 2042 | else |
---|
| 2043 | { |
---|
| 2044 | m_pcBinIf->encodeBin( 1, m_cSaoTypeIdxSCModel.get( 0, 0, 0 ) ); |
---|
[872] | 2045 | m_pcBinIf->encodeBinEP( uiCode == 1 ? 0 : 1 ); |
---|
[443] | 2046 | } |
---|
| 2047 | } |
---|
[1200] | 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 | |
---|
[2] | 2164 | /*! |
---|
| 2165 | **************************************************************************** |
---|
| 2166 | * \brief |
---|
| 2167 | * estimate bit cost for CBP, significant map and significant coefficients |
---|
| 2168 | **************************************************************************** |
---|
| 2169 | */ |
---|
[1200] | 2170 | Void TEncSbac::estBit( estBitsSbacStruct* pcEstBitsSbac, Int width, Int height, ChannelType chType ) |
---|
[2] | 2171 | { |
---|
[608] | 2172 | estCBFBit( pcEstBitsSbac ); |
---|
[56] | 2173 | |
---|
[1200] | 2174 | estSignificantCoeffGroupMapBit( pcEstBitsSbac, chType ); |
---|
| 2175 | |
---|
[2] | 2176 | // encode significance map |
---|
[1200] | 2177 | estSignificantMapBit( pcEstBitsSbac, width, height, chType ); |
---|
| 2178 | |
---|
| 2179 | // encode last significant position |
---|
| 2180 | estLastSignificantPositionBit( pcEstBitsSbac, width, height, chType ); |
---|
| 2181 | |
---|
[2] | 2182 | // encode significant coefficients |
---|
[1200] | 2183 | estSignificantCoefficientsBit( pcEstBitsSbac, chType ); |
---|
| 2184 | |
---|
| 2185 | memcpy(pcEstBitsSbac->golombRiceAdaptationStatistics, m_golombRiceAdaptationStatistics, (sizeof(UInt) * RExt__GOLOMB_RICE_ADAPTATION_STATISTICS_SETS)); |
---|
[2] | 2186 | } |
---|
| 2187 | |
---|
| 2188 | /*! |
---|
| 2189 | **************************************************************************** |
---|
| 2190 | * \brief |
---|
| 2191 | * estimate bit cost for each CBP bit |
---|
| 2192 | **************************************************************************** |
---|
| 2193 | */ |
---|
[608] | 2194 | Void TEncSbac::estCBFBit( estBitsSbacStruct* pcEstBitsSbac ) |
---|
[2] | 2195 | { |
---|
| 2196 | ContextModel *pCtx = m_cCUQtCbfSCModel.get( 0 ); |
---|
| 2197 | |
---|
[1200] | 2198 | for( UInt uiCtxInc = 0; uiCtxInc < (NUM_QT_CBF_CTX_SETS * NUM_QT_CBF_CTX_PER_SET); uiCtxInc++ ) |
---|
[2] | 2199 | { |
---|
[56] | 2200 | pcEstBitsSbac->blockCbpBits[ uiCtxInc ][ 0 ] = pCtx[ uiCtxInc ].getEntropyBits( 0 ); |
---|
| 2201 | pcEstBitsSbac->blockCbpBits[ uiCtxInc ][ 1 ] = pCtx[ uiCtxInc ].getEntropyBits( 1 ); |
---|
[2] | 2202 | } |
---|
| 2203 | |
---|
[56] | 2204 | pCtx = m_cCUQtRootCbfSCModel.get( 0 ); |
---|
[1200] | 2205 | |
---|
[2] | 2206 | for( UInt uiCtxInc = 0; uiCtxInc < 4; uiCtxInc++ ) |
---|
| 2207 | { |
---|
[56] | 2208 | pcEstBitsSbac->blockRootCbpBits[ uiCtxInc ][ 0 ] = pCtx[ uiCtxInc ].getEntropyBits( 0 ); |
---|
| 2209 | pcEstBitsSbac->blockRootCbpBits[ uiCtxInc ][ 1 ] = pCtx[ uiCtxInc ].getEntropyBits( 1 ); |
---|
[2] | 2210 | } |
---|
| 2211 | } |
---|
| 2212 | |
---|
| 2213 | |
---|
| 2214 | /*! |
---|
| 2215 | **************************************************************************** |
---|
| 2216 | * \brief |
---|
[56] | 2217 | * estimate SAMBAC bit cost for significant coefficient group map |
---|
[2] | 2218 | **************************************************************************** |
---|
| 2219 | */ |
---|
[1200] | 2220 | Void TEncSbac::estSignificantCoeffGroupMapBit( estBitsSbacStruct* pcEstBitsSbac, ChannelType chType ) |
---|
[2] | 2221 | { |
---|
[56] | 2222 | Int firstCtx = 0, numCtx = NUM_SIG_CG_FLAG_CTX; |
---|
| 2223 | |
---|
| 2224 | for ( Int ctxIdx = firstCtx; ctxIdx < firstCtx + numCtx; ctxIdx++ ) |
---|
[2] | 2225 | { |
---|
| 2226 | for( UInt uiBin = 0; uiBin < 2; uiBin++ ) |
---|
| 2227 | { |
---|
[1200] | 2228 | pcEstBitsSbac->significantCoeffGroupBits[ ctxIdx ][ uiBin ] = m_cCUSigCoeffGroupSCModel.get( 0, chType, ctxIdx ).getEntropyBits( uiBin ); |
---|
[56] | 2229 | } |
---|
| 2230 | } |
---|
| 2231 | } |
---|
| 2232 | |
---|
| 2233 | |
---|
| 2234 | /*! |
---|
| 2235 | **************************************************************************** |
---|
| 2236 | * \brief |
---|
| 2237 | * estimate SAMBAC bit cost for significant coefficient map |
---|
| 2238 | **************************************************************************** |
---|
| 2239 | */ |
---|
[1200] | 2240 | Void TEncSbac::estSignificantMapBit( estBitsSbacStruct* pcEstBitsSbac, Int width, Int height, ChannelType chType ) |
---|
[56] | 2241 | { |
---|
[1200] | 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)) |
---|
[56] | 2255 | { |
---|
[1200] | 2256 | firstCtx = significanceMapContextSetStart[chType][CONTEXT_TYPE_4x4]; |
---|
| 2257 | numCtx = significanceMapContextSetSize [chType][CONTEXT_TYPE_4x4]; |
---|
[56] | 2258 | } |
---|
[1200] | 2259 | else if ((width == 8) && (height == 8)) |
---|
[56] | 2260 | { |
---|
[1200] | 2261 | firstCtx = significanceMapContextSetStart[chType][CONTEXT_TYPE_8x8]; |
---|
| 2262 | numCtx = significanceMapContextSetSize [chType][CONTEXT_TYPE_8x8]; |
---|
[56] | 2263 | } |
---|
[1200] | 2264 | else |
---|
[56] | 2265 | { |
---|
[1200] | 2266 | firstCtx = significanceMapContextSetStart[chType][CONTEXT_TYPE_NxN]; |
---|
| 2267 | numCtx = significanceMapContextSetSize [chType][CONTEXT_TYPE_NxN]; |
---|
| 2268 | } |
---|
[608] | 2269 | |
---|
[1200] | 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) |
---|
[56] | 2279 | { |
---|
[1200] | 2280 | for( UInt bin = 0; bin < 2; bin++ ) //always get the DC |
---|
[2] | 2281 | { |
---|
[1200] | 2282 | pcEstBitsSbac->significantBits[ contextOffset ][ bin ] = m_cCUSigSCModel.get( 0, 0, contextOffset ).getEntropyBits( bin ); |
---|
[2] | 2283 | } |
---|
[56] | 2284 | } |
---|
[1200] | 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 |
---|
[608] | 2288 | for( UInt bin = 0; bin < 2; bin++ ) |
---|
| 2289 | { |
---|
[1200] | 2290 | const Int ctxIdx = significanceMapContextSetStart[chType][CONTEXT_TYPE_SINGLE]; |
---|
| 2291 | pcEstBitsSbac->significantBits[ contextOffset + ctxIdx ][ bin ] = m_cCUSigSCModel.get( 0, 0, (contextOffset + ctxIdx) ).getEntropyBits( bin ); |
---|
[608] | 2292 | } |
---|
[1200] | 2293 | |
---|
[56] | 2294 | for ( Int ctxIdx = firstCtx; ctxIdx < firstCtx + numCtx; ctxIdx++ ) |
---|
| 2295 | { |
---|
| 2296 | for( UInt uiBin = 0; uiBin < 2; uiBin++ ) |
---|
[2] | 2297 | { |
---|
[1200] | 2298 | pcEstBitsSbac->significantBits[ contextOffset + ctxIdx ][ uiBin ] = m_cCUSigSCModel.get( 0, 0, (contextOffset + ctxIdx) ).getEntropyBits( uiBin ); |
---|
[2] | 2299 | } |
---|
[56] | 2300 | } |
---|
| 2301 | } |
---|
[608] | 2302 | |
---|
[1200] | 2303 | //-------------------------------------------------------------------------------------------------- |
---|
[2] | 2304 | } |
---|
| 2305 | |
---|
[1200] | 2306 | |
---|
[2] | 2307 | /*! |
---|
| 2308 | **************************************************************************** |
---|
| 2309 | * \brief |
---|
| 2310 | * estimate bit cost of significant coefficient |
---|
| 2311 | **************************************************************************** |
---|
| 2312 | */ |
---|
[1200] | 2313 | |
---|
| 2314 | Void TEncSbac::estLastSignificantPositionBit( estBitsSbacStruct* pcEstBitsSbac, Int width, Int height, ChannelType chType ) |
---|
[2] | 2315 | { |
---|
[1200] | 2316 | //--------------------------------------------------------------------------------------------------. |
---|
[56] | 2317 | |
---|
[1200] | 2318 | //set up the number of channels |
---|
[56] | 2319 | |
---|
[1200] | 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++) |
---|
[56] | 2328 | { |
---|
[1200] | 2329 | const ComponentID component = ComponentID(componentIndex); |
---|
[56] | 2330 | |
---|
[1200] | 2331 | Int iBitsX = 0, iBitsY = 0; |
---|
[56] | 2332 | |
---|
[1200] | 2333 | Int blkSizeOffsetX, blkSizeOffsetY, shiftX, shiftY; |
---|
| 2334 | getLastSignificantContextParameters(ComponentID(component), width, height, blkSizeOffsetX, blkSizeOffsetY, shiftX, shiftY); |
---|
[2] | 2335 | |
---|
[1200] | 2336 | Int ctx; |
---|
[56] | 2337 | |
---|
[1200] | 2338 | const ChannelType channelType = toChannelType(ComponentID(component)); |
---|
[56] | 2339 | |
---|
[1200] | 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]; |
---|
[872] | 2344 | |
---|
[1200] | 2345 | //------------------------------------------------ |
---|
[872] | 2346 | |
---|
[1200] | 2347 | //X-coordinate |
---|
[872] | 2348 | |
---|
[1200] | 2349 | for (ctx = 0; ctx < g_uiGroupIdx[ width - 1 ]; ctx++) |
---|
[872] | 2350 | { |
---|
[1200] | 2351 | Int ctxOffset = blkSizeOffsetX + (ctx >>shiftX); |
---|
| 2352 | lastXBitsArray[ ctx ] = iBitsX + pCtxX[ ctxOffset ].getEntropyBits( 0 ); |
---|
| 2353 | iBitsX += pCtxX[ ctxOffset ].getEntropyBits( 1 ); |
---|
[872] | 2354 | } |
---|
| 2355 | |
---|
[1200] | 2356 | lastXBitsArray[ctx] = iBitsX; |
---|
[872] | 2357 | |
---|
[1200] | 2358 | //------------------------------------------------ |
---|
[872] | 2359 | |
---|
[1200] | 2360 | //Y-coordinate |
---|
| 2361 | |
---|
| 2362 | for (ctx = 0; ctx < g_uiGroupIdx[ height - 1 ]; ctx++) |
---|
[872] | 2363 | { |
---|
[1200] | 2364 | Int ctxOffset = blkSizeOffsetY + (ctx >>shiftY); |
---|
| 2365 | lastYBitsArray[ ctx ] = iBitsY + pCtxY[ ctxOffset ].getEntropyBits( 0 ); |
---|
| 2366 | iBitsY += pCtxY[ ctxOffset ].getEntropyBits( 1 ); |
---|
[872] | 2367 | } |
---|
| 2368 | |
---|
[1200] | 2369 | lastYBitsArray[ctx] = iBitsY; |
---|
| 2370 | |
---|
| 2371 | } //end of component loop |
---|
| 2372 | |
---|
| 2373 | //-------------------------------------------------------------------------------------------------- |
---|
[872] | 2374 | } |
---|
| 2375 | |
---|
| 2376 | |
---|
[1200] | 2377 | /*! |
---|
| 2378 | **************************************************************************** |
---|
| 2379 | * \brief |
---|
| 2380 | * estimate bit cost of significant coefficient |
---|
| 2381 | **************************************************************************** |
---|
| 2382 | */ |
---|
| 2383 | Void TEncSbac::estSignificantCoefficientsBit( estBitsSbacStruct* pcEstBitsSbac, ChannelType chType ) |
---|
[872] | 2384 | { |
---|
[1200] | 2385 | ContextModel *ctxOne = m_cCUOneSCModel.get(0, 0); |
---|
| 2386 | ContextModel *ctxAbs = m_cCUAbsSCModel.get(0, 0); |
---|
[872] | 2387 | |
---|
[1200] | 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)); |
---|
[872] | 2392 | |
---|
[1200] | 2393 | for (Int ctxIdx = oneStartIndex; ctxIdx < oneStopIndex; ctxIdx++) |
---|
[872] | 2394 | { |
---|
[1200] | 2395 | pcEstBitsSbac->m_greaterOneBits[ ctxIdx ][ 0 ] = ctxOne[ ctxIdx ].getEntropyBits( 0 ); |
---|
| 2396 | pcEstBitsSbac->m_greaterOneBits[ ctxIdx ][ 1 ] = ctxOne[ ctxIdx ].getEntropyBits( 1 ); |
---|
[872] | 2397 | } |
---|
| 2398 | |
---|
[1200] | 2399 | for (Int ctxIdx = absStartIndex; ctxIdx < absStopIndex; ctxIdx++) |
---|
[872] | 2400 | { |
---|
[1200] | 2401 | pcEstBitsSbac->m_levelAbsBits[ ctxIdx ][ 0 ] = ctxAbs[ ctxIdx ].getEntropyBits( 0 ); |
---|
| 2402 | pcEstBitsSbac->m_levelAbsBits[ ctxIdx ][ 1 ] = ctxAbs[ ctxIdx ].getEntropyBits( 1 ); |
---|
[872] | 2403 | } |
---|
[1200] | 2404 | } |
---|
[872] | 2405 | |
---|
[1200] | 2406 | /** |
---|
| 2407 | - Initialize our context information from the nominated source. |
---|
| 2408 | . |
---|
| 2409 | \param pSrc From where to copy context information. |
---|
| 2410 | */ |
---|
| 2411 | Void TEncSbac::xCopyContextsFrom( const TEncSbac* pSrc ) |
---|
| 2412 | { |
---|
| 2413 | memcpy(m_contextModels, pSrc->m_contextModels, m_numContextModels*sizeof(m_contextModels[0])); |
---|
| 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 ) |
---|
[872] | 2440 | { |
---|
[1200] | 2441 | m_pcBinIf->encodeBin (0, m_explicitRdpcmFlagSCModel.get (0, toChannelType(compID), 0)); |
---|
[872] | 2442 | } |
---|
[1200] | 2443 | else if( explicitRdpcmMode == RDPCM_HOR || explicitRdpcmMode == RDPCM_VER ) |
---|
[872] | 2444 | { |
---|
[1200] | 2445 | m_pcBinIf->encodeBin (1, m_explicitRdpcmFlagSCModel.get (0, toChannelType(compID), 0)); |
---|
| 2446 | if(explicitRdpcmMode == RDPCM_HOR) |
---|
[872] | 2447 | { |
---|
[1200] | 2448 | m_pcBinIf->encodeBin ( 0, m_explicitRdpcmDirSCModel.get(0, toChannelType(compID), 0)); |
---|
[872] | 2449 | } |
---|
[1200] | 2450 | else |
---|
| 2451 | { |
---|
| 2452 | m_pcBinIf->encodeBin ( 1, m_explicitRdpcmDirSCModel.get(0, toChannelType(compID), 0)); |
---|
| 2453 | } |
---|
[872] | 2454 | } |
---|
[1200] | 2455 | else |
---|
| 2456 | { |
---|
| 2457 | assert(0); |
---|
| 2458 | } |
---|
[872] | 2459 | } |
---|
| 2460 | |
---|
[1304] | 2461 | #if NH_3D_DMM || NH_3D_SDC_INTRA || NH_3D_SDC_INTER |
---|
[833] | 2462 | Void TEncSbac::codeDeltaDC( TComDataCU* pcCU, UInt absPartIdx ) |
---|
| 2463 | { |
---|
[1304] | 2464 | #if NH_3D_SDC_INTRA || NH_3D_SDC_INTER |
---|
[1209] | 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 |
---|
[833] | 2470 | assert( 0 ); |
---|
| 2471 | |
---|
[1209] | 2472 | UInt uiNumSegments = 1; |
---|
| 2473 | #if NH_3D_DMM |
---|
| 2474 | uiNumSegments = isDmmMode( pcCU->getIntraDir( CHANNEL_TYPE_LUMA, absPartIdx ) ) ? 2 : 1; |
---|
| 2475 | #endif |
---|
[833] | 2476 | |
---|
[1209] | 2477 | UInt hasDeltaDC = 1; |
---|
[1227] | 2478 | #if NH_3D_SDC_INTRA |
---|
[1039] | 2479 | if( pcCU->isIntra( absPartIdx ) && pcCU->getSDCFlag( absPartIdx )) |
---|
| 2480 | { |
---|
[1209] | 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 ) ); |
---|
[833] | 2490 | } |
---|
[1209] | 2491 | #endif |
---|
[833] | 2492 | |
---|
[1209] | 2493 | if( hasDeltaDC ) |
---|
[833] | 2494 | { |
---|
| 2495 | for( UInt segment = 0; segment < uiNumSegments; segment++ ) |
---|
| 2496 | { |
---|
| 2497 | Pel deltaDC = 0; |
---|
| 2498 | if( pcCU->isIntra( absPartIdx ) ) |
---|
| 2499 | { |
---|
[1227] | 2500 | #if NH_3D_SDC_INTRA |
---|
[1209] | 2501 | if( pcCU->getSDCFlag( absPartIdx ) ) |
---|
| 2502 | { |
---|
| 2503 | deltaDC = pcCU->getSDCSegmentDCOffset( segment, absPartIdx ); |
---|
| 2504 | } |
---|
| 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 |
---|
[1227] | 2511 | #if NH_3D_SDC_INTRA |
---|
[1209] | 2512 | } |
---|
| 2513 | #endif |
---|
[833] | 2514 | } |
---|
[1304] | 2515 | #if NH_3D_SDC_INTER |
---|
[833] | 2516 | else |
---|
| 2517 | { |
---|
| 2518 | deltaDC = pcCU->getSDCSegmentDCOffset( segment, absPartIdx ); |
---|
| 2519 | } |
---|
[1209] | 2520 | #endif |
---|
| 2521 | xCodeDeltaDC( deltaDC, uiNumSegments ); |
---|
| 2522 | } |
---|
| 2523 | } |
---|
| 2524 | } |
---|
[833] | 2525 | |
---|
[1209] | 2526 | Void TEncSbac::xCodeDeltaDC( Pel valDeltaDC, UInt uiNumSeg ) |
---|
| 2527 | { |
---|
[1223] | 2528 | #if ENC_DEC_TRACE && H_MV_ENC_DEC_TRAC |
---|
[1221] | 2529 | DTRACE_CU("delta_dc", valDeltaDC); |
---|
[1223] | 2530 | #endif |
---|
[1209] | 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) ); |
---|
[833] | 2550 | } |
---|
[1209] | 2551 | if( bNoExGo ) |
---|
| 2552 | { |
---|
| 2553 | m_pcBinIf->encodeBin( 0, m_cDdcDataSCModel.get(0, 0, 0) ); |
---|
| 2554 | } |
---|
| 2555 | else |
---|
| 2556 | { |
---|
| 2557 | xWriteEpExGolomb( uiSymbol, 0 ); |
---|
| 2558 | } |
---|
[833] | 2559 | } |
---|
[1209] | 2560 | else |
---|
| 2561 | { |
---|
| 2562 | m_pcBinIf->encodeBin( 0, m_cDdcDataSCModel.get(0, 0, 0) ); |
---|
| 2563 | } |
---|
| 2564 | |
---|
| 2565 | return; |
---|
[833] | 2566 | } |
---|
[1209] | 2567 | #endif |
---|
[833] | 2568 | |
---|
[1209] | 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 | |
---|
[1304] | 2616 | #if NH_3D_SDC_INTRA || NH_3D_SDC_INTER |
---|
[833] | 2617 | Void TEncSbac::codeSDCFlag( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
| 2618 | { |
---|
| 2619 | UInt uiSymbol = pcCU->getSDCFlag( uiAbsPartIdx ) ? 1 : 0; |
---|
[1223] | 2620 | #if ENC_DEC_TRACE && H_MV_ENC_DEC_TRAC |
---|
[1179] | 2621 | DTRACE_CU("dc_only_flag", uiSymbol) |
---|
[1223] | 2622 | #endif |
---|
[1221] | 2623 | m_pcBinIf->encodeBin( uiSymbol, m_cSDCFlagSCModel.get( 0, 0, 0 ) ); |
---|
[833] | 2624 | } |
---|
[56] | 2625 | |
---|
| 2626 | #endif |
---|
[833] | 2627 | |
---|
[1279] | 2628 | #if NH_3D_DBBP |
---|
[833] | 2629 | Void TEncSbac::codeDBBPFlag( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
| 2630 | { |
---|
[1039] | 2631 | PartSize ePartSize = pcCU->getPartitionSize( uiAbsPartIdx ); |
---|
| 2632 | AOF( ePartSize == SIZE_2NxN || ePartSize == SIZE_Nx2N ); |
---|
[1124] | 2633 | AOF( pcCU->getSlice()->getDepthBasedBlkPartFlag() ); |
---|
[833] | 2634 | AOF( !pcCU->getSlice()->getIsDepth() ); |
---|
| 2635 | |
---|
| 2636 | UInt uiSymbol = pcCU->getDBBPFlag( uiAbsPartIdx ) ? 1 : 0; |
---|
| 2637 | m_pcBinIf->encodeBin( uiSymbol, m_cDBBPFlagSCModel.get( 0, 0, 0 ) ); |
---|
[1179] | 2638 | DTRACE_CU("dbbp_flag", uiSymbol) |
---|
[833] | 2639 | } |
---|
| 2640 | #endif |
---|
| 2641 | |
---|
[56] | 2642 | //! \} |
---|