[313] | 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 |
---|
[1029] | 4 | * granted under this license. |
---|
[313] | 5 | * |
---|
[595] | 6 | * Copyright (c) 2010-2014, ITU/ISO/IEC |
---|
[313] | 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. |
---|
| 17 | * * Neither the name of the ITU/ISO/IEC nor the names of its contributors may |
---|
| 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 | */ |
---|
| 33 | |
---|
| 34 | /** \file TDecSbac.cpp |
---|
| 35 | \brief Context-adaptive entropy decoder class |
---|
| 36 | */ |
---|
| 37 | |
---|
| 38 | #include "TDecSbac.h" |
---|
[1029] | 39 | #include "TLibCommon/TComTU.h" |
---|
[313] | 40 | |
---|
[1029] | 41 | #if RExt__DECODER_DEBUG_BIT_STATISTICS |
---|
| 42 | #include "TLibCommon/TComCodingStatistics.h" |
---|
| 43 | // |
---|
| 44 | #define RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(a) , a |
---|
| 45 | #else |
---|
| 46 | #define RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(a) |
---|
| 47 | #endif |
---|
| 48 | |
---|
[313] | 49 | //! \ingroup TLibDecoder |
---|
| 50 | //! \{ |
---|
| 51 | |
---|
[1029] | 52 | #if ENVIRONMENT_VARIABLE_DEBUG_AND_TEST |
---|
| 53 | #include "../TLibCommon/Debug.h" |
---|
| 54 | #endif |
---|
| 55 | |
---|
| 56 | |
---|
[313] | 57 | ////////////////////////////////////////////////////////////////////// |
---|
| 58 | // Construction/Destruction |
---|
| 59 | ////////////////////////////////////////////////////////////////////// |
---|
| 60 | |
---|
[1029] | 61 | TDecSbac::TDecSbac() |
---|
[313] | 62 | // new structure here |
---|
[1029] | 63 | : m_pcBitstream ( 0 ) |
---|
| 64 | , m_pcTDecBinIf ( NULL ) |
---|
| 65 | , m_numContextModels ( 0 ) |
---|
| 66 | , m_cCUSplitFlagSCModel ( 1, 1, NUM_SPLIT_FLAG_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
| 67 | , m_cCUSkipFlagSCModel ( 1, 1, NUM_SKIP_FLAG_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
| 68 | , m_cCUMergeFlagExtSCModel ( 1, 1, NUM_MERGE_FLAG_EXT_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
| 69 | , m_cCUMergeIdxExtSCModel ( 1, 1, NUM_MERGE_IDX_EXT_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
| 70 | , m_cCUPartSizeSCModel ( 1, 1, NUM_PART_SIZE_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
| 71 | , m_cCUPredModeSCModel ( 1, 1, NUM_PRED_MODE_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
| 72 | , m_cCUIntraPredSCModel ( 1, 1, NUM_ADI_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
| 73 | , m_cCUChromaPredSCModel ( 1, 1, NUM_CHROMA_PRED_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
| 74 | , m_cCUDeltaQpSCModel ( 1, 1, NUM_DELTA_QP_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
| 75 | , m_cCUInterDirSCModel ( 1, 1, NUM_INTER_DIR_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
| 76 | , m_cCURefPicSCModel ( 1, 1, NUM_REF_NO_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
| 77 | , m_cCUMvdSCModel ( 1, 1, NUM_MV_RES_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
| 78 | , m_cCUQtCbfSCModel ( 1, NUM_QT_CBF_CTX_SETS, NUM_QT_CBF_CTX_PER_SET , m_contextModels + m_numContextModels, m_numContextModels) |
---|
| 79 | , m_cCUTransSubdivFlagSCModel ( 1, 1, NUM_TRANS_SUBDIV_FLAG_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
| 80 | , m_cCUQtRootCbfSCModel ( 1, 1, NUM_QT_ROOT_CBF_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
| 81 | , m_cCUSigCoeffGroupSCModel ( 1, 2, NUM_SIG_CG_FLAG_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
| 82 | , m_cCUSigSCModel ( 1, 1, NUM_SIG_FLAG_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
| 83 | , m_cCuCtxLastX ( 1, NUM_CTX_LAST_FLAG_SETS, NUM_CTX_LAST_FLAG_XY , m_contextModels + m_numContextModels, m_numContextModels) |
---|
| 84 | , m_cCuCtxLastY ( 1, NUM_CTX_LAST_FLAG_SETS, NUM_CTX_LAST_FLAG_XY , m_contextModels + m_numContextModels, m_numContextModels) |
---|
| 85 | , m_cCUOneSCModel ( 1, 1, NUM_ONE_FLAG_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
| 86 | , m_cCUAbsSCModel ( 1, 1, NUM_ABS_FLAG_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
| 87 | , m_cMVPIdxSCModel ( 1, 1, NUM_MVP_IDX_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
| 88 | , m_cSaoMergeSCModel ( 1, 1, NUM_SAO_MERGE_FLAG_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
| 89 | , m_cSaoTypeIdxSCModel ( 1, 1, NUM_SAO_TYPE_IDX_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
| 90 | , m_cTransformSkipSCModel ( 1, MAX_NUM_CHANNEL_TYPE, NUM_TRANSFORMSKIP_FLAG_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
| 91 | , m_CUTransquantBypassFlagSCModel ( 1, 1, NUM_CU_TRANSQUANT_BYPASS_FLAG_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
| 92 | , m_explicitRdpcmFlagSCModel ( 1, MAX_NUM_CHANNEL_TYPE, NUM_EXPLICIT_RDPCM_FLAG_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
| 93 | , m_explicitRdpcmDirSCModel ( 1, MAX_NUM_CHANNEL_TYPE, NUM_EXPLICIT_RDPCM_DIR_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
| 94 | , m_cCrossComponentPredictionSCModel ( 1, 1, NUM_CROSS_COMPONENT_PREDICTION_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
| 95 | , m_ChromaQpAdjFlagSCModel ( 1, 1, NUM_CHROMA_QP_ADJ_FLAG_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
| 96 | , m_ChromaQpAdjIdcSCModel ( 1, 1, NUM_CHROMA_QP_ADJ_IDC_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
[313] | 97 | { |
---|
| 98 | assert( m_numContextModels <= MAX_NUM_CTX_MOD ); |
---|
| 99 | } |
---|
| 100 | |
---|
| 101 | TDecSbac::~TDecSbac() |
---|
| 102 | { |
---|
| 103 | } |
---|
| 104 | |
---|
| 105 | // ==================================================================================================================== |
---|
| 106 | // Public member functions |
---|
| 107 | // ==================================================================================================================== |
---|
| 108 | |
---|
| 109 | Void TDecSbac::resetEntropy(TComSlice* pSlice) |
---|
| 110 | { |
---|
| 111 | SliceType sliceType = pSlice->getSliceType(); |
---|
| 112 | Int qp = pSlice->getSliceQp(); |
---|
| 113 | |
---|
| 114 | if (pSlice->getPPS()->getCabacInitPresentFlag() && pSlice->getCabacInitFlag()) |
---|
| 115 | { |
---|
| 116 | switch (sliceType) |
---|
| 117 | { |
---|
| 118 | case P_SLICE: // change initialization table to B_SLICE initialization |
---|
[1029] | 119 | sliceType = B_SLICE; |
---|
[313] | 120 | break; |
---|
| 121 | case B_SLICE: // change initialization table to P_SLICE initialization |
---|
[1029] | 122 | sliceType = P_SLICE; |
---|
[313] | 123 | break; |
---|
| 124 | default : // should not occur |
---|
| 125 | assert(0); |
---|
[1029] | 126 | break; |
---|
[313] | 127 | } |
---|
| 128 | } |
---|
| 129 | |
---|
[1029] | 130 | m_cCUSplitFlagSCModel.initBuffer ( sliceType, qp, (UChar*)INIT_SPLIT_FLAG ); |
---|
| 131 | m_cCUSkipFlagSCModel.initBuffer ( sliceType, qp, (UChar*)INIT_SKIP_FLAG ); |
---|
| 132 | m_cCUMergeFlagExtSCModel.initBuffer ( sliceType, qp, (UChar*)INIT_MERGE_FLAG_EXT ); |
---|
| 133 | m_cCUMergeIdxExtSCModel.initBuffer ( sliceType, qp, (UChar*)INIT_MERGE_IDX_EXT ); |
---|
| 134 | m_cCUPartSizeSCModel.initBuffer ( sliceType, qp, (UChar*)INIT_PART_SIZE ); |
---|
| 135 | m_cCUPredModeSCModel.initBuffer ( sliceType, qp, (UChar*)INIT_PRED_MODE ); |
---|
| 136 | m_cCUIntraPredSCModel.initBuffer ( sliceType, qp, (UChar*)INIT_INTRA_PRED_MODE ); |
---|
| 137 | m_cCUChromaPredSCModel.initBuffer ( sliceType, qp, (UChar*)INIT_CHROMA_PRED_MODE ); |
---|
| 138 | m_cCUInterDirSCModel.initBuffer ( sliceType, qp, (UChar*)INIT_INTER_DIR ); |
---|
| 139 | m_cCUMvdSCModel.initBuffer ( sliceType, qp, (UChar*)INIT_MVD ); |
---|
| 140 | m_cCURefPicSCModel.initBuffer ( sliceType, qp, (UChar*)INIT_REF_PIC ); |
---|
| 141 | m_cCUDeltaQpSCModel.initBuffer ( sliceType, qp, (UChar*)INIT_DQP ); |
---|
| 142 | m_cCUQtCbfSCModel.initBuffer ( sliceType, qp, (UChar*)INIT_QT_CBF ); |
---|
| 143 | m_cCUQtRootCbfSCModel.initBuffer ( sliceType, qp, (UChar*)INIT_QT_ROOT_CBF ); |
---|
| 144 | m_cCUSigCoeffGroupSCModel.initBuffer ( sliceType, qp, (UChar*)INIT_SIG_CG_FLAG ); |
---|
| 145 | m_cCUSigSCModel.initBuffer ( sliceType, qp, (UChar*)INIT_SIG_FLAG ); |
---|
| 146 | m_cCuCtxLastX.initBuffer ( sliceType, qp, (UChar*)INIT_LAST ); |
---|
| 147 | m_cCuCtxLastY.initBuffer ( sliceType, qp, (UChar*)INIT_LAST ); |
---|
| 148 | m_cCUOneSCModel.initBuffer ( sliceType, qp, (UChar*)INIT_ONE_FLAG ); |
---|
| 149 | m_cCUAbsSCModel.initBuffer ( sliceType, qp, (UChar*)INIT_ABS_FLAG ); |
---|
| 150 | m_cMVPIdxSCModel.initBuffer ( sliceType, qp, (UChar*)INIT_MVP_IDX ); |
---|
| 151 | m_cSaoMergeSCModel.initBuffer ( sliceType, qp, (UChar*)INIT_SAO_MERGE_FLAG ); |
---|
| 152 | m_cSaoTypeIdxSCModel.initBuffer ( sliceType, qp, (UChar*)INIT_SAO_TYPE_IDX ); |
---|
| 153 | m_cCUTransSubdivFlagSCModel.initBuffer ( sliceType, qp, (UChar*)INIT_TRANS_SUBDIV_FLAG ); |
---|
| 154 | m_cTransformSkipSCModel.initBuffer ( sliceType, qp, (UChar*)INIT_TRANSFORMSKIP_FLAG ); |
---|
| 155 | m_CUTransquantBypassFlagSCModel.initBuffer ( sliceType, qp, (UChar*)INIT_CU_TRANSQUANT_BYPASS_FLAG ); |
---|
| 156 | m_explicitRdpcmFlagSCModel.initBuffer ( sliceType, qp, (UChar*)INIT_EXPLICIT_RDPCM_FLAG); |
---|
| 157 | m_explicitRdpcmDirSCModel.initBuffer ( sliceType, qp, (UChar*)INIT_EXPLICIT_RDPCM_DIR); |
---|
| 158 | m_cCrossComponentPredictionSCModel.initBuffer ( sliceType, qp, (UChar*)INIT_CROSS_COMPONENT_PREDICTION ); |
---|
| 159 | m_ChromaQpAdjFlagSCModel.initBuffer ( sliceType, qp, (UChar*)INIT_CHROMA_QP_ADJ_FLAG ); |
---|
| 160 | m_ChromaQpAdjIdcSCModel.initBuffer ( sliceType, qp, (UChar*)INIT_CHROMA_QP_ADJ_IDC ); |
---|
[313] | 161 | |
---|
[1029] | 162 | for (UInt statisticIndex = 0; statisticIndex < RExt__GOLOMB_RICE_ADAPTATION_STATISTICS_SETS ; statisticIndex++) |
---|
| 163 | { |
---|
| 164 | m_golombRiceAdaptationStatistics[statisticIndex] = 0; |
---|
| 165 | } |
---|
[313] | 166 | |
---|
| 167 | m_pcTDecBinIf->start(); |
---|
| 168 | } |
---|
| 169 | |
---|
| 170 | Void TDecSbac::parseTerminatingBit( UInt& ruiBit ) |
---|
| 171 | { |
---|
| 172 | m_pcTDecBinIf->decodeBinTrm( ruiBit ); |
---|
[1029] | 173 | if ( ruiBit == 1 ) |
---|
[313] | 174 | { |
---|
| 175 | m_pcTDecBinIf->finish(); |
---|
[1029] | 176 | |
---|
| 177 | #if RExt__DECODER_DEBUG_BIT_STATISTICS |
---|
| 178 | TComCodingStatistics::IncrementStatisticEP(STATS__TRAILING_BITS, m_pcBitstream->readOutTrailingBits(),0); |
---|
| 179 | #else |
---|
| 180 | m_pcBitstream->readOutTrailingBits(); |
---|
| 181 | #endif |
---|
[313] | 182 | } |
---|
| 183 | } |
---|
| 184 | |
---|
[1029] | 185 | Void TDecSbac::parseRemainingBytes( Bool noTrailingBytesExpected ) |
---|
| 186 | { |
---|
| 187 | if (noTrailingBytesExpected) |
---|
| 188 | { |
---|
| 189 | const UInt numberOfRemainingSubstreamBytes=m_pcBitstream->getNumBitsLeft(); |
---|
| 190 | assert (numberOfRemainingSubstreamBytes == 0); |
---|
| 191 | } |
---|
| 192 | else |
---|
| 193 | { |
---|
| 194 | while (m_pcBitstream->getNumBitsLeft()) |
---|
| 195 | { |
---|
| 196 | UInt trailingNullByte=m_pcBitstream->readByte(); |
---|
| 197 | if (trailingNullByte!=0) |
---|
| 198 | { |
---|
| 199 | printf("Trailing byte should be 0, but has value %02x\n", trailingNullByte); |
---|
| 200 | assert(trailingNullByte==0); |
---|
| 201 | } |
---|
| 202 | } |
---|
| 203 | } |
---|
| 204 | } |
---|
[313] | 205 | |
---|
[1029] | 206 | #if RExt__DECODER_DEBUG_BIT_STATISTICS |
---|
| 207 | Void TDecSbac::xReadUnaryMaxSymbol( UInt& ruiSymbol, ContextModel* pcSCModel, Int iOffset, UInt uiMaxSymbol, const class TComCodingStatisticsClassType &whichStat ) |
---|
| 208 | #else |
---|
[313] | 209 | Void TDecSbac::xReadUnaryMaxSymbol( UInt& ruiSymbol, ContextModel* pcSCModel, Int iOffset, UInt uiMaxSymbol ) |
---|
[1029] | 210 | #endif |
---|
[313] | 211 | { |
---|
| 212 | if (uiMaxSymbol == 0) |
---|
| 213 | { |
---|
| 214 | ruiSymbol = 0; |
---|
| 215 | return; |
---|
| 216 | } |
---|
[1029] | 217 | |
---|
| 218 | m_pcTDecBinIf->decodeBin( ruiSymbol, pcSCModel[0] RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(whichStat) ); |
---|
| 219 | |
---|
[313] | 220 | if( ruiSymbol == 0 || uiMaxSymbol == 1 ) |
---|
| 221 | { |
---|
| 222 | return; |
---|
| 223 | } |
---|
[1029] | 224 | |
---|
[313] | 225 | UInt uiSymbol = 0; |
---|
| 226 | UInt uiCont; |
---|
[1029] | 227 | |
---|
[313] | 228 | do |
---|
| 229 | { |
---|
[1029] | 230 | m_pcTDecBinIf->decodeBin( uiCont, pcSCModel[ iOffset ] RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(whichStat) ); |
---|
[313] | 231 | uiSymbol++; |
---|
| 232 | } |
---|
| 233 | while( uiCont && ( uiSymbol < uiMaxSymbol - 1 ) ); |
---|
[1029] | 234 | |
---|
[313] | 235 | if( uiCont && ( uiSymbol == uiMaxSymbol - 1 ) ) |
---|
| 236 | { |
---|
| 237 | uiSymbol++; |
---|
| 238 | } |
---|
[1029] | 239 | |
---|
[313] | 240 | ruiSymbol = uiSymbol; |
---|
| 241 | } |
---|
| 242 | |
---|
[1029] | 243 | #if RExt__DECODER_DEBUG_BIT_STATISTICS |
---|
| 244 | Void TDecSbac::xReadEpExGolomb( UInt& ruiSymbol, UInt uiCount, const class TComCodingStatisticsClassType &whichStat ) |
---|
| 245 | #else |
---|
[313] | 246 | Void TDecSbac::xReadEpExGolomb( UInt& ruiSymbol, UInt uiCount ) |
---|
[1029] | 247 | #endif |
---|
[313] | 248 | { |
---|
| 249 | UInt uiSymbol = 0; |
---|
| 250 | UInt uiBit = 1; |
---|
[1029] | 251 | |
---|
[313] | 252 | while( uiBit ) |
---|
| 253 | { |
---|
[1029] | 254 | m_pcTDecBinIf->decodeBinEP( uiBit RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(whichStat) ); |
---|
[313] | 255 | uiSymbol += uiBit << uiCount++; |
---|
| 256 | } |
---|
[1029] | 257 | |
---|
[313] | 258 | if ( --uiCount ) |
---|
| 259 | { |
---|
| 260 | UInt bins; |
---|
[1029] | 261 | m_pcTDecBinIf->decodeBinsEP( bins, uiCount RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(whichStat) ); |
---|
[313] | 262 | uiSymbol += bins; |
---|
| 263 | } |
---|
[1029] | 264 | |
---|
[313] | 265 | ruiSymbol = uiSymbol; |
---|
| 266 | } |
---|
| 267 | |
---|
[1029] | 268 | #if RExt__DECODER_DEBUG_BIT_STATISTICS |
---|
| 269 | Void TDecSbac::xReadUnarySymbol( UInt& ruiSymbol, ContextModel* pcSCModel, Int iOffset, const class TComCodingStatisticsClassType &whichStat ) |
---|
| 270 | #else |
---|
[313] | 271 | Void TDecSbac::xReadUnarySymbol( UInt& ruiSymbol, ContextModel* pcSCModel, Int iOffset ) |
---|
[1029] | 272 | #endif |
---|
[313] | 273 | { |
---|
[1029] | 274 | m_pcTDecBinIf->decodeBin( ruiSymbol, pcSCModel[0] RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(whichStat)); |
---|
| 275 | |
---|
[313] | 276 | if( !ruiSymbol ) |
---|
| 277 | { |
---|
| 278 | return; |
---|
| 279 | } |
---|
[1029] | 280 | |
---|
[313] | 281 | UInt uiSymbol = 0; |
---|
| 282 | UInt uiCont; |
---|
[1029] | 283 | |
---|
[313] | 284 | do |
---|
| 285 | { |
---|
[1029] | 286 | m_pcTDecBinIf->decodeBin( uiCont, pcSCModel[ iOffset ] RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(whichStat)); |
---|
[313] | 287 | uiSymbol++; |
---|
| 288 | } |
---|
| 289 | while( uiCont ); |
---|
[1029] | 290 | |
---|
[313] | 291 | ruiSymbol = uiSymbol; |
---|
| 292 | } |
---|
| 293 | |
---|
| 294 | |
---|
| 295 | /** Parsing of coeff_abs_level_remaing |
---|
| 296 | * \param ruiSymbol reference to coeff_abs_level_remaing |
---|
| 297 | * \param ruiParam reference to parameter |
---|
| 298 | * \returns Void |
---|
| 299 | */ |
---|
[1029] | 300 | #if RExt__DECODER_DEBUG_BIT_STATISTICS |
---|
| 301 | Void TDecSbac::xReadCoefRemainExGolomb ( UInt &rSymbol, UInt &rParam, const Bool useLimitedPrefixLength, const ChannelType channelType, const class TComCodingStatisticsClassType &whichStat ) |
---|
| 302 | #else |
---|
| 303 | Void TDecSbac::xReadCoefRemainExGolomb ( UInt &rSymbol, UInt &rParam, const Bool useLimitedPrefixLength, const ChannelType channelType ) |
---|
| 304 | #endif |
---|
[313] | 305 | { |
---|
| 306 | UInt prefix = 0; |
---|
| 307 | UInt codeWord = 0; |
---|
[1029] | 308 | |
---|
| 309 | if (useLimitedPrefixLength) |
---|
[313] | 310 | { |
---|
[1029] | 311 | const UInt longestPossiblePrefix = (32 - (COEF_REMAIN_BIN_REDUCTION + g_maxTrDynamicRange[channelType])) + COEF_REMAIN_BIN_REDUCTION; |
---|
| 312 | |
---|
| 313 | do |
---|
| 314 | { |
---|
| 315 | prefix++; |
---|
| 316 | m_pcTDecBinIf->decodeBinEP( codeWord RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(whichStat) ); |
---|
| 317 | } |
---|
| 318 | while((codeWord != 0) && (prefix < longestPossiblePrefix)); |
---|
[313] | 319 | } |
---|
[1029] | 320 | else |
---|
| 321 | { |
---|
| 322 | do |
---|
| 323 | { |
---|
| 324 | prefix++; |
---|
| 325 | m_pcTDecBinIf->decodeBinEP( codeWord RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(whichStat) ); |
---|
| 326 | } |
---|
| 327 | while( codeWord); |
---|
| 328 | } |
---|
| 329 | |
---|
[313] | 330 | codeWord = 1 - codeWord; |
---|
| 331 | prefix -= codeWord; |
---|
| 332 | codeWord=0; |
---|
[1029] | 333 | |
---|
[313] | 334 | if (prefix < COEF_REMAIN_BIN_REDUCTION ) |
---|
| 335 | { |
---|
[1029] | 336 | m_pcTDecBinIf->decodeBinsEP(codeWord,rParam RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(whichStat)); |
---|
[313] | 337 | rSymbol = (prefix<<rParam) + codeWord; |
---|
| 338 | } |
---|
[1029] | 339 | else if (useLimitedPrefixLength) |
---|
| 340 | { |
---|
| 341 | const UInt maximumPrefixLength = (32 - (COEF_REMAIN_BIN_REDUCTION + g_maxTrDynamicRange[channelType])); |
---|
| 342 | |
---|
| 343 | const UInt prefixLength = prefix - COEF_REMAIN_BIN_REDUCTION; |
---|
| 344 | const UInt suffixLength = (prefixLength == maximumPrefixLength) ? (g_maxTrDynamicRange[channelType] - rParam) : prefixLength; |
---|
| 345 | |
---|
| 346 | m_pcTDecBinIf->decodeBinsEP(codeWord, (suffixLength + rParam) RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(whichStat)); |
---|
| 347 | |
---|
| 348 | rSymbol = codeWord + ((((1 << prefixLength) - 1) + COEF_REMAIN_BIN_REDUCTION) << rParam); |
---|
| 349 | } |
---|
[313] | 350 | else |
---|
| 351 | { |
---|
[1029] | 352 | m_pcTDecBinIf->decodeBinsEP(codeWord,prefix-COEF_REMAIN_BIN_REDUCTION+rParam RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(whichStat)); |
---|
[313] | 353 | rSymbol = (((1<<(prefix-COEF_REMAIN_BIN_REDUCTION))+COEF_REMAIN_BIN_REDUCTION-1)<<rParam)+codeWord; |
---|
| 354 | } |
---|
| 355 | } |
---|
| 356 | |
---|
[1029] | 357 | |
---|
| 358 | /** Parse I_PCM information. |
---|
[313] | 359 | * \param pcCU |
---|
[1029] | 360 | * \param uiAbsPartIdx |
---|
[313] | 361 | * \param uiDepth |
---|
| 362 | * \returns Void |
---|
| 363 | * |
---|
[1029] | 364 | * If I_PCM flag indicates that the CU is I_PCM, parse its PCM alignment bits and codes. |
---|
[313] | 365 | */ |
---|
| 366 | Void TDecSbac::parseIPCMInfo ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth ) |
---|
| 367 | { |
---|
| 368 | UInt uiSymbol; |
---|
| 369 | |
---|
[1029] | 370 | m_pcTDecBinIf->decodeBinTrm(uiSymbol); |
---|
[313] | 371 | |
---|
[1029] | 372 | if (uiSymbol == 1) |
---|
| 373 | { |
---|
[313] | 374 | Bool bIpcmFlag = true; |
---|
| 375 | |
---|
| 376 | pcCU->setPartSizeSubParts ( SIZE_2Nx2N, uiAbsPartIdx, uiDepth ); |
---|
| 377 | pcCU->setSizeSubParts ( g_uiMaxCUWidth>>uiDepth, g_uiMaxCUHeight>>uiDepth, uiAbsPartIdx, uiDepth ); |
---|
| 378 | pcCU->setTrIdxSubParts ( 0, uiAbsPartIdx, uiDepth ); |
---|
| 379 | pcCU->setIPCMFlagSubParts ( bIpcmFlag, uiAbsPartIdx, uiDepth ); |
---|
| 380 | |
---|
[1029] | 381 | const UInt minCoeffSizeY = pcCU->getPic()->getMinCUWidth() * pcCU->getPic()->getMinCUHeight(); |
---|
| 382 | const UInt offsetY = minCoeffSizeY * uiAbsPartIdx; |
---|
| 383 | for (UInt ch=0; ch < pcCU->getPic()->getNumberValidComponents(); ch++) |
---|
[313] | 384 | { |
---|
[1029] | 385 | const ComponentID compID = ComponentID(ch); |
---|
| 386 | const UInt offset = offsetY >> (pcCU->getPic()->getComponentScaleX(compID) + pcCU->getPic()->getComponentScaleY(compID)); |
---|
| 387 | Pel * pPCMSample = pcCU->getPCMSample(compID) + offset; |
---|
| 388 | const UInt width = pcCU->getWidth (uiAbsPartIdx) >> pcCU->getPic()->getComponentScaleX(compID); |
---|
| 389 | const UInt height = pcCU->getHeight(uiAbsPartIdx) >> pcCU->getPic()->getComponentScaleY(compID); |
---|
| 390 | const UInt sampleBits = pcCU->getSlice()->getSPS()->getPCMBitDepth(toChannelType(compID)); |
---|
| 391 | for (UInt y=0; y<height; y++) |
---|
[313] | 392 | { |
---|
[1029] | 393 | for (UInt x=0; x<width; x++) |
---|
[540] | 394 | { |
---|
[1029] | 395 | UInt sample; |
---|
| 396 | m_pcTDecBinIf->xReadPCMCode(sampleBits, sample); |
---|
| 397 | pPCMSample[x] = sample; |
---|
[540] | 398 | } |
---|
[1029] | 399 | pPCMSample += width; |
---|
[313] | 400 | } |
---|
| 401 | } |
---|
| 402 | |
---|
| 403 | m_pcTDecBinIf->start(); |
---|
| 404 | } |
---|
| 405 | } |
---|
| 406 | |
---|
| 407 | Void TDecSbac::parseCUTransquantBypassFlag( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth ) |
---|
| 408 | { |
---|
| 409 | UInt uiSymbol; |
---|
[1029] | 410 | m_pcTDecBinIf->decodeBin( uiSymbol, m_CUTransquantBypassFlagSCModel.get( 0, 0, 0 ) RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(STATS__CABAC_BITS__TQ_BYPASS_FLAG) ); |
---|
[313] | 411 | pcCU->setCUTransquantBypassSubParts(uiSymbol ? true : false, uiAbsPartIdx, uiDepth); |
---|
| 412 | } |
---|
| 413 | |
---|
| 414 | /** parse skip flag |
---|
| 415 | * \param pcCU |
---|
[1029] | 416 | * \param uiAbsPartIdx |
---|
[313] | 417 | * \param uiDepth |
---|
| 418 | * \returns Void |
---|
| 419 | */ |
---|
| 420 | Void TDecSbac::parseSkipFlag( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth ) |
---|
| 421 | { |
---|
| 422 | if( pcCU->getSlice()->isIntra() ) |
---|
| 423 | { |
---|
| 424 | return; |
---|
| 425 | } |
---|
[1029] | 426 | |
---|
[313] | 427 | UInt uiSymbol = 0; |
---|
| 428 | UInt uiCtxSkip = pcCU->getCtxSkipFlag( uiAbsPartIdx ); |
---|
[1029] | 429 | m_pcTDecBinIf->decodeBin( uiSymbol, m_cCUSkipFlagSCModel.get( 0, 0, uiCtxSkip ) RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(STATS__CABAC_BITS__SKIP_FLAG) ); |
---|
[313] | 430 | DTRACE_CABAC_VL( g_nSymbolCounter++ ); |
---|
| 431 | DTRACE_CABAC_T( "\tSkipFlag" ); |
---|
| 432 | DTRACE_CABAC_T( "\tuiCtxSkip: "); |
---|
| 433 | DTRACE_CABAC_V( uiCtxSkip ); |
---|
| 434 | DTRACE_CABAC_T( "\tuiSymbol: "); |
---|
| 435 | DTRACE_CABAC_V( uiSymbol ); |
---|
| 436 | DTRACE_CABAC_T( "\n"); |
---|
[1029] | 437 | |
---|
[313] | 438 | if( uiSymbol ) |
---|
| 439 | { |
---|
| 440 | pcCU->setSkipFlagSubParts( true, uiAbsPartIdx, uiDepth ); |
---|
| 441 | pcCU->setPredModeSubParts( MODE_INTER, uiAbsPartIdx, uiDepth ); |
---|
| 442 | pcCU->setPartSizeSubParts( SIZE_2Nx2N, uiAbsPartIdx, uiDepth ); |
---|
| 443 | pcCU->setSizeSubParts( g_uiMaxCUWidth>>uiDepth, g_uiMaxCUHeight>>uiDepth, uiAbsPartIdx, uiDepth ); |
---|
| 444 | pcCU->setMergeFlagSubParts( true , uiAbsPartIdx, 0, uiDepth ); |
---|
| 445 | } |
---|
| 446 | } |
---|
| 447 | |
---|
[1029] | 448 | |
---|
[313] | 449 | /** parse merge flag |
---|
| 450 | * \param pcCU |
---|
[1029] | 451 | * \param uiAbsPartIdx |
---|
[313] | 452 | * \param uiDepth |
---|
| 453 | * \param uiPUIdx |
---|
| 454 | * \returns Void |
---|
| 455 | */ |
---|
| 456 | Void TDecSbac::parseMergeFlag ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, UInt uiPUIdx ) |
---|
| 457 | { |
---|
| 458 | UInt uiSymbol; |
---|
[1029] | 459 | m_pcTDecBinIf->decodeBin( uiSymbol, *m_cCUMergeFlagExtSCModel.get( 0 ) RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(STATS__CABAC_BITS__MERGE_FLAG) ); |
---|
[313] | 460 | pcCU->setMergeFlagSubParts( uiSymbol ? true : false, uiAbsPartIdx, uiPUIdx, uiDepth ); |
---|
| 461 | |
---|
| 462 | DTRACE_CABAC_VL( g_nSymbolCounter++ ); |
---|
| 463 | DTRACE_CABAC_T( "\tMergeFlag: " ); |
---|
| 464 | DTRACE_CABAC_V( uiSymbol ); |
---|
| 465 | DTRACE_CABAC_T( "\tAddress: " ); |
---|
[1029] | 466 | DTRACE_CABAC_V( pcCU->getCtuRsAddr() ); |
---|
[313] | 467 | DTRACE_CABAC_T( "\tuiAbsPartIdx: " ); |
---|
| 468 | DTRACE_CABAC_V( uiAbsPartIdx ); |
---|
| 469 | DTRACE_CABAC_T( "\n" ); |
---|
| 470 | } |
---|
| 471 | |
---|
| 472 | Void TDecSbac::parseMergeIndex ( TComDataCU* pcCU, UInt& ruiMergeIndex ) |
---|
| 473 | { |
---|
| 474 | UInt uiUnaryIdx = 0; |
---|
| 475 | UInt uiNumCand = pcCU->getSlice()->getMaxNumMergeCand(); |
---|
| 476 | if ( uiNumCand > 1 ) |
---|
| 477 | { |
---|
| 478 | for( ; uiUnaryIdx < uiNumCand - 1; ++uiUnaryIdx ) |
---|
| 479 | { |
---|
| 480 | UInt uiSymbol = 0; |
---|
| 481 | if ( uiUnaryIdx==0 ) |
---|
| 482 | { |
---|
[1029] | 483 | m_pcTDecBinIf->decodeBin( uiSymbol, m_cCUMergeIdxExtSCModel.get( 0, 0, 0 ) RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(STATS__CABAC_BITS__MERGE_INDEX) ); |
---|
[313] | 484 | } |
---|
| 485 | else |
---|
| 486 | { |
---|
[1029] | 487 | m_pcTDecBinIf->decodeBinEP( uiSymbol RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(STATS__CABAC_BITS__MERGE_INDEX) ); |
---|
[313] | 488 | } |
---|
| 489 | if( uiSymbol == 0 ) |
---|
| 490 | { |
---|
| 491 | break; |
---|
| 492 | } |
---|
| 493 | } |
---|
| 494 | } |
---|
| 495 | ruiMergeIndex = uiUnaryIdx; |
---|
| 496 | |
---|
| 497 | DTRACE_CABAC_VL( g_nSymbolCounter++ ) |
---|
| 498 | DTRACE_CABAC_T( "\tparseMergeIndex()" ) |
---|
| 499 | DTRACE_CABAC_T( "\tuiMRGIdx= " ) |
---|
| 500 | DTRACE_CABAC_V( ruiMergeIndex ) |
---|
| 501 | DTRACE_CABAC_T( "\n" ) |
---|
| 502 | } |
---|
| 503 | |
---|
| 504 | Void TDecSbac::parseMVPIdx ( Int& riMVPIdx ) |
---|
| 505 | { |
---|
| 506 | UInt uiSymbol; |
---|
[1029] | 507 | xReadUnaryMaxSymbol(uiSymbol, m_cMVPIdxSCModel.get(0), 1, AMVP_MAX_NUM_CANDS-1 RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(STATS__CABAC_BITS__MVP_IDX) ); |
---|
[313] | 508 | riMVPIdx = uiSymbol; |
---|
| 509 | } |
---|
| 510 | |
---|
| 511 | Void TDecSbac::parseSplitFlag ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth ) |
---|
| 512 | { |
---|
| 513 | if( uiDepth == g_uiMaxCUDepth - g_uiAddCUDepth ) |
---|
| 514 | { |
---|
| 515 | pcCU->setDepthSubParts( uiDepth, uiAbsPartIdx ); |
---|
| 516 | return; |
---|
| 517 | } |
---|
[1029] | 518 | #if RExt__DECODER_DEBUG_BIT_STATISTICS |
---|
| 519 | const TComCodingStatisticsClassType ctype(STATS__CABAC_BITS__SPLIT_FLAG, g_aucConvertToBit[g_uiMaxCUWidth>>uiDepth]+2); |
---|
| 520 | #endif |
---|
| 521 | |
---|
[313] | 522 | UInt uiSymbol; |
---|
[1029] | 523 | m_pcTDecBinIf->decodeBin( uiSymbol, m_cCUSplitFlagSCModel.get( 0, 0, pcCU->getCtxSplitFlag( uiAbsPartIdx, uiDepth ) ) RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(ctype) ); |
---|
[313] | 524 | DTRACE_CABAC_VL( g_nSymbolCounter++ ) |
---|
| 525 | DTRACE_CABAC_T( "\tSplitFlag\n" ) |
---|
| 526 | pcCU->setDepthSubParts( uiDepth + uiSymbol, uiAbsPartIdx ); |
---|
[1029] | 527 | |
---|
[313] | 528 | return; |
---|
| 529 | } |
---|
| 530 | |
---|
| 531 | /** parse partition size |
---|
| 532 | * \param pcCU |
---|
[1029] | 533 | * \param uiAbsPartIdx |
---|
[313] | 534 | * \param uiDepth |
---|
| 535 | * \returns Void |
---|
| 536 | */ |
---|
| 537 | Void TDecSbac::parsePartSize( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth ) |
---|
| 538 | { |
---|
| 539 | UInt uiSymbol, uiMode = 0; |
---|
| 540 | PartSize eMode; |
---|
[345] | 541 | |
---|
[1029] | 542 | #if RExt__DECODER_DEBUG_BIT_STATISTICS |
---|
| 543 | const TComCodingStatisticsClassType ctype(STATS__CABAC_BITS__PART_SIZE, g_aucConvertToBit[g_uiMaxCUWidth>>uiDepth]+2); |
---|
| 544 | #endif |
---|
| 545 | |
---|
[313] | 546 | if ( pcCU->isIntra( uiAbsPartIdx ) ) |
---|
| 547 | { |
---|
| 548 | uiSymbol = 1; |
---|
| 549 | if( uiDepth == g_uiMaxCUDepth - g_uiAddCUDepth ) |
---|
| 550 | { |
---|
[1029] | 551 | m_pcTDecBinIf->decodeBin( uiSymbol, m_cCUPartSizeSCModel.get( 0, 0, 0) RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(ctype) ); |
---|
[313] | 552 | } |
---|
| 553 | eMode = uiSymbol ? SIZE_2Nx2N : SIZE_NxN; |
---|
[1029] | 554 | UInt uiTrLevel = 0; |
---|
[313] | 555 | UInt uiWidthInBit = g_aucConvertToBit[pcCU->getWidth(uiAbsPartIdx)]+2; |
---|
| 556 | UInt uiTrSizeInBit = g_aucConvertToBit[pcCU->getSlice()->getSPS()->getMaxTrSize()]+2; |
---|
| 557 | uiTrLevel = uiWidthInBit >= uiTrSizeInBit ? uiWidthInBit - uiTrSizeInBit : 0; |
---|
| 558 | if( eMode == SIZE_NxN ) |
---|
| 559 | { |
---|
| 560 | pcCU->setTrIdxSubParts( 1+uiTrLevel, uiAbsPartIdx, uiDepth ); |
---|
| 561 | } |
---|
| 562 | else |
---|
| 563 | { |
---|
| 564 | pcCU->setTrIdxSubParts( uiTrLevel, uiAbsPartIdx, uiDepth ); |
---|
| 565 | } |
---|
| 566 | } |
---|
| 567 | else |
---|
| 568 | { |
---|
| 569 | UInt uiMaxNumBits = 2; |
---|
[1029] | 570 | |
---|
[313] | 571 | if( uiDepth == g_uiMaxCUDepth - g_uiAddCUDepth && !( (g_uiMaxCUWidth>>uiDepth) == 8 && (g_uiMaxCUHeight>>uiDepth) == 8 ) ) |
---|
| 572 | { |
---|
| 573 | uiMaxNumBits ++; |
---|
| 574 | } |
---|
[1029] | 575 | |
---|
[313] | 576 | for ( UInt ui = 0; ui < uiMaxNumBits; ui++ ) |
---|
| 577 | { |
---|
[1029] | 578 | m_pcTDecBinIf->decodeBin( uiSymbol, m_cCUPartSizeSCModel.get( 0, 0, ui) RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(ctype) ); |
---|
[313] | 579 | if ( uiSymbol ) |
---|
| 580 | { |
---|
| 581 | break; |
---|
| 582 | } |
---|
| 583 | uiMode++; |
---|
| 584 | } |
---|
| 585 | eMode = (PartSize) uiMode; |
---|
| 586 | if ( pcCU->getSlice()->getSPS()->getAMPAcc( uiDepth ) ) |
---|
| 587 | { |
---|
| 588 | if (eMode == SIZE_2NxN) |
---|
| 589 | { |
---|
[1029] | 590 | m_pcTDecBinIf->decodeBin(uiSymbol, m_cCUPartSizeSCModel.get( 0, 0, 3 ) RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(ctype)); |
---|
[313] | 591 | if (uiSymbol == 0) |
---|
| 592 | { |
---|
[1029] | 593 | m_pcTDecBinIf->decodeBinEP(uiSymbol RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(ctype) ); |
---|
[313] | 594 | eMode = (uiSymbol == 0? SIZE_2NxnU : SIZE_2NxnD); |
---|
| 595 | } |
---|
| 596 | } |
---|
| 597 | else if (eMode == SIZE_Nx2N) |
---|
| 598 | { |
---|
[1029] | 599 | m_pcTDecBinIf->decodeBin(uiSymbol, m_cCUPartSizeSCModel.get( 0, 0, 3 ) RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(ctype) ); |
---|
[313] | 600 | if (uiSymbol == 0) |
---|
| 601 | { |
---|
[1029] | 602 | m_pcTDecBinIf->decodeBinEP(uiSymbol RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(ctype) ); |
---|
[313] | 603 | eMode = (uiSymbol == 0? SIZE_nLx2N : SIZE_nRx2N); |
---|
| 604 | } |
---|
| 605 | } |
---|
| 606 | } |
---|
| 607 | } |
---|
| 608 | pcCU->setPartSizeSubParts( eMode, uiAbsPartIdx, uiDepth ); |
---|
| 609 | pcCU->setSizeSubParts( g_uiMaxCUWidth>>uiDepth, g_uiMaxCUHeight>>uiDepth, uiAbsPartIdx, uiDepth ); |
---|
| 610 | } |
---|
| 611 | |
---|
[1029] | 612 | |
---|
[313] | 613 | /** parse prediction mode |
---|
| 614 | * \param pcCU |
---|
[1029] | 615 | * \param uiAbsPartIdx |
---|
[313] | 616 | * \param uiDepth |
---|
| 617 | * \returns Void |
---|
| 618 | */ |
---|
| 619 | Void TDecSbac::parsePredMode( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth ) |
---|
| 620 | { |
---|
| 621 | if( pcCU->getSlice()->isIntra() ) |
---|
| 622 | { |
---|
| 623 | pcCU->setPredModeSubParts( MODE_INTRA, uiAbsPartIdx, uiDepth ); |
---|
| 624 | return; |
---|
| 625 | } |
---|
[1029] | 626 | |
---|
[313] | 627 | UInt uiSymbol; |
---|
| 628 | Int iPredMode = MODE_INTER; |
---|
[1029] | 629 | m_pcTDecBinIf->decodeBin( uiSymbol, m_cCUPredModeSCModel.get( 0, 0, 0 ) RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(STATS__CABAC_BITS__PRED_MODE) ); |
---|
[313] | 630 | iPredMode += uiSymbol; |
---|
| 631 | pcCU->setPredModeSubParts( (PredMode)iPredMode, uiAbsPartIdx, uiDepth ); |
---|
| 632 | } |
---|
| 633 | |
---|
[1029] | 634 | |
---|
[313] | 635 | Void TDecSbac::parseIntraDirLumaAng ( TComDataCU* pcCU, UInt absPartIdx, UInt depth ) |
---|
| 636 | { |
---|
| 637 | PartSize mode = pcCU->getPartitionSize( absPartIdx ); |
---|
| 638 | UInt partNum = mode==SIZE_NxN?4:1; |
---|
[1029] | 639 | UInt partOffset = ( pcCU->getPic()->getNumPartitionsInCtu() >> ( pcCU->getDepth(absPartIdx) << 1 ) ) >> 2; |
---|
[313] | 640 | UInt mpmPred[4],symbol; |
---|
[1029] | 641 | Int j,intraPredMode; |
---|
[313] | 642 | if (mode==SIZE_NxN) |
---|
| 643 | { |
---|
| 644 | depth++; |
---|
| 645 | } |
---|
[1029] | 646 | #if RExt__DECODER_DEBUG_BIT_STATISTICS |
---|
| 647 | const TComCodingStatisticsClassType ctype(STATS__CABAC_BITS__INTRA_DIR_ANG, g_aucConvertToBit[g_uiMaxCUWidth>>depth]+2, CHANNEL_TYPE_LUMA); |
---|
| 648 | #endif |
---|
[313] | 649 | for (j=0;j<partNum;j++) |
---|
| 650 | { |
---|
[1029] | 651 | m_pcTDecBinIf->decodeBin( symbol, m_cCUIntraPredSCModel.get( 0, 0, 0) RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(ctype) ); |
---|
[313] | 652 | mpmPred[j] = symbol; |
---|
| 653 | } |
---|
| 654 | for (j=0;j<partNum;j++) |
---|
| 655 | { |
---|
[1029] | 656 | Int preds[NUM_MOST_PROBABLE_MODES] = {-1, -1, -1}; |
---|
| 657 | Int predNum = pcCU->getIntraDirPredictor(absPartIdx+partOffset*j, preds, COMPONENT_Y); |
---|
[313] | 658 | if (mpmPred[j]) |
---|
| 659 | { |
---|
[1029] | 660 | m_pcTDecBinIf->decodeBinEP( symbol RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(ctype) ); |
---|
[313] | 661 | if (symbol) |
---|
| 662 | { |
---|
[1029] | 663 | m_pcTDecBinIf->decodeBinEP( symbol RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(ctype) ); |
---|
[313] | 664 | symbol++; |
---|
| 665 | } |
---|
| 666 | intraPredMode = preds[symbol]; |
---|
| 667 | } |
---|
| 668 | else |
---|
| 669 | { |
---|
[1029] | 670 | m_pcTDecBinIf->decodeBinsEP( symbol, 5 RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(ctype) ); |
---|
[313] | 671 | intraPredMode = symbol; |
---|
[1029] | 672 | |
---|
[313] | 673 | //postponed sorting of MPMs (only in remaining branch) |
---|
[1029] | 674 | assert(predNum>=3); // It is currently always 3! |
---|
[313] | 675 | if (preds[0] > preds[1]) |
---|
[1029] | 676 | { |
---|
| 677 | std::swap(preds[0], preds[1]); |
---|
[313] | 678 | } |
---|
| 679 | if (preds[0] > preds[2]) |
---|
| 680 | { |
---|
| 681 | std::swap(preds[0], preds[2]); |
---|
| 682 | } |
---|
| 683 | if (preds[1] > preds[2]) |
---|
| 684 | { |
---|
| 685 | std::swap(preds[1], preds[2]); |
---|
| 686 | } |
---|
| 687 | for ( Int i = 0; i < predNum; i++ ) |
---|
| 688 | { |
---|
| 689 | intraPredMode += ( intraPredMode >= preds[i] ); |
---|
| 690 | } |
---|
| 691 | } |
---|
[1029] | 692 | pcCU->setIntraDirSubParts(CHANNEL_TYPE_LUMA, (UChar)intraPredMode, absPartIdx+partOffset*j, depth ); |
---|
[313] | 693 | } |
---|
| 694 | } |
---|
| 695 | |
---|
[1029] | 696 | |
---|
[313] | 697 | Void TDecSbac::parseIntraDirChroma( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth ) |
---|
| 698 | { |
---|
| 699 | UInt uiSymbol; |
---|
[1029] | 700 | #if RExt__DECODER_DEBUG_BIT_STATISTICS |
---|
| 701 | const TComCodingStatisticsClassType ctype(STATS__CABAC_BITS__INTRA_DIR_ANG, g_aucConvertToBit[g_uiMaxCUWidth>>uiDepth]+2, CHANNEL_TYPE_CHROMA); |
---|
[494] | 702 | #endif |
---|
[313] | 703 | |
---|
[1029] | 704 | m_pcTDecBinIf->decodeBin( uiSymbol, m_cCUChromaPredSCModel.get( 0, 0, 0 ) RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(ctype) ); |
---|
[313] | 705 | if( uiSymbol == 0 ) |
---|
| 706 | { |
---|
| 707 | uiSymbol = DM_CHROMA_IDX; |
---|
[1029] | 708 | } |
---|
| 709 | else |
---|
[313] | 710 | { |
---|
[1029] | 711 | UInt uiIPredMode; |
---|
| 712 | m_pcTDecBinIf->decodeBinsEP( uiIPredMode, 2 RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(ctype) ); |
---|
| 713 | UInt uiAllowedChromaDir[ NUM_CHROMA_MODE ]; |
---|
| 714 | pcCU->getAllowedChromaDir( uiAbsPartIdx, uiAllowedChromaDir ); |
---|
| 715 | uiSymbol = uiAllowedChromaDir[ uiIPredMode ]; |
---|
[313] | 716 | } |
---|
[1029] | 717 | |
---|
| 718 | pcCU->setIntraDirSubParts( CHANNEL_TYPE_CHROMA, uiSymbol, uiAbsPartIdx, uiDepth ); |
---|
[313] | 719 | } |
---|
| 720 | |
---|
[1029] | 721 | |
---|
[313] | 722 | Void TDecSbac::parseInterDir( TComDataCU* pcCU, UInt& ruiInterDir, UInt uiAbsPartIdx ) |
---|
| 723 | { |
---|
| 724 | UInt uiSymbol; |
---|
| 725 | const UInt uiCtx = pcCU->getCtxInterDir( uiAbsPartIdx ); |
---|
| 726 | ContextModel *pCtx = m_cCUInterDirSCModel.get( 0 ); |
---|
[1029] | 727 | |
---|
[313] | 728 | uiSymbol = 0; |
---|
| 729 | if (pcCU->getPartitionSize(uiAbsPartIdx) == SIZE_2Nx2N || pcCU->getHeight(uiAbsPartIdx) != 8 ) |
---|
| 730 | { |
---|
[1029] | 731 | m_pcTDecBinIf->decodeBin( uiSymbol, *( pCtx + uiCtx ) RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(STATS__CABAC_BITS__INTER_DIR) ); |
---|
[313] | 732 | } |
---|
| 733 | |
---|
| 734 | if( uiSymbol ) |
---|
| 735 | { |
---|
| 736 | uiSymbol = 2; |
---|
| 737 | } |
---|
| 738 | else |
---|
| 739 | { |
---|
[1029] | 740 | m_pcTDecBinIf->decodeBin( uiSymbol, *( pCtx + 4 ) RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(STATS__CABAC_BITS__INTER_DIR) ); |
---|
[313] | 741 | assert(uiSymbol == 0 || uiSymbol == 1); |
---|
| 742 | } |
---|
| 743 | |
---|
| 744 | uiSymbol++; |
---|
| 745 | ruiInterDir = uiSymbol; |
---|
| 746 | return; |
---|
| 747 | } |
---|
| 748 | |
---|
| 749 | Void TDecSbac::parseRefFrmIdx( TComDataCU* pcCU, Int& riRefFrmIdx, RefPicList eRefList ) |
---|
| 750 | { |
---|
| 751 | UInt uiSymbol; |
---|
[1029] | 752 | |
---|
| 753 | ContextModel *pCtx = m_cCURefPicSCModel.get( 0 ); |
---|
| 754 | m_pcTDecBinIf->decodeBin( uiSymbol, *pCtx RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(STATS__CABAC_BITS__REF_FRM_IDX) ); |
---|
| 755 | |
---|
| 756 | if( uiSymbol ) |
---|
[313] | 757 | { |
---|
[1029] | 758 | UInt uiRefNum = pcCU->getSlice()->getNumRefIdx( eRefList ) - 2; |
---|
| 759 | pCtx++; |
---|
| 760 | UInt ui; |
---|
| 761 | for( ui = 0; ui < uiRefNum; ++ui ) |
---|
[313] | 762 | { |
---|
[1029] | 763 | if( ui == 0 ) |
---|
[313] | 764 | { |
---|
[1029] | 765 | m_pcTDecBinIf->decodeBin( uiSymbol, *pCtx RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(STATS__CABAC_BITS__REF_FRM_IDX) ); |
---|
[313] | 766 | } |
---|
[1029] | 767 | else |
---|
| 768 | { |
---|
| 769 | m_pcTDecBinIf->decodeBinEP( uiSymbol RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(STATS__CABAC_BITS__REF_FRM_IDX) ); |
---|
| 770 | } |
---|
| 771 | if( uiSymbol == 0 ) |
---|
| 772 | { |
---|
| 773 | break; |
---|
| 774 | } |
---|
[313] | 775 | } |
---|
[1029] | 776 | uiSymbol = ui + 1; |
---|
[313] | 777 | } |
---|
[1029] | 778 | riRefFrmIdx = uiSymbol; |
---|
[313] | 779 | |
---|
| 780 | return; |
---|
| 781 | } |
---|
| 782 | |
---|
| 783 | Void TDecSbac::parseMvd( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiPartIdx, UInt uiDepth, RefPicList eRefList ) |
---|
| 784 | { |
---|
| 785 | UInt uiSymbol; |
---|
| 786 | UInt uiHorAbs; |
---|
| 787 | UInt uiVerAbs; |
---|
| 788 | UInt uiHorSign = 0; |
---|
| 789 | UInt uiVerSign = 0; |
---|
| 790 | ContextModel *pCtx = m_cCUMvdSCModel.get( 0 ); |
---|
| 791 | |
---|
| 792 | if(pcCU->getSlice()->getMvdL1ZeroFlag() && eRefList == REF_PIC_LIST_1 && pcCU->getInterDir(uiAbsPartIdx)==3) |
---|
| 793 | { |
---|
| 794 | uiHorAbs=0; |
---|
| 795 | uiVerAbs=0; |
---|
| 796 | } |
---|
| 797 | else |
---|
| 798 | { |
---|
[1029] | 799 | m_pcTDecBinIf->decodeBin( uiHorAbs, *pCtx RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(STATS__CABAC_BITS__MVD) ); |
---|
| 800 | m_pcTDecBinIf->decodeBin( uiVerAbs, *pCtx RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(STATS__CABAC_BITS__MVD) ); |
---|
[313] | 801 | |
---|
| 802 | const Bool bHorAbsGr0 = uiHorAbs != 0; |
---|
| 803 | const Bool bVerAbsGr0 = uiVerAbs != 0; |
---|
| 804 | pCtx++; |
---|
| 805 | |
---|
| 806 | if( bHorAbsGr0 ) |
---|
| 807 | { |
---|
[1029] | 808 | m_pcTDecBinIf->decodeBin( uiSymbol, *pCtx RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(STATS__CABAC_BITS__MVD) ); |
---|
[313] | 809 | uiHorAbs += uiSymbol; |
---|
| 810 | } |
---|
| 811 | |
---|
| 812 | if( bVerAbsGr0 ) |
---|
| 813 | { |
---|
[1029] | 814 | m_pcTDecBinIf->decodeBin( uiSymbol, *pCtx RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(STATS__CABAC_BITS__MVD) ); |
---|
[313] | 815 | uiVerAbs += uiSymbol; |
---|
| 816 | } |
---|
| 817 | |
---|
| 818 | if( bHorAbsGr0 ) |
---|
| 819 | { |
---|
| 820 | if( 2 == uiHorAbs ) |
---|
| 821 | { |
---|
[1029] | 822 | xReadEpExGolomb( uiSymbol, 1 RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(STATS__CABAC_BITS__MVD_EP) ); |
---|
[313] | 823 | uiHorAbs += uiSymbol; |
---|
| 824 | } |
---|
| 825 | |
---|
[1029] | 826 | m_pcTDecBinIf->decodeBinEP( uiHorSign RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(STATS__CABAC_BITS__MVD_EP) ); |
---|
[313] | 827 | } |
---|
| 828 | |
---|
| 829 | if( bVerAbsGr0 ) |
---|
| 830 | { |
---|
| 831 | if( 2 == uiVerAbs ) |
---|
| 832 | { |
---|
[1029] | 833 | xReadEpExGolomb( uiSymbol, 1 RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(STATS__CABAC_BITS__MVD_EP) ); |
---|
[313] | 834 | uiVerAbs += uiSymbol; |
---|
| 835 | } |
---|
| 836 | |
---|
[1029] | 837 | m_pcTDecBinIf->decodeBinEP( uiVerSign RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(STATS__CABAC_BITS__MVD_EP) ); |
---|
[313] | 838 | } |
---|
| 839 | |
---|
| 840 | } |
---|
| 841 | |
---|
| 842 | const TComMv cMv( uiHorSign ? -Int( uiHorAbs ): uiHorAbs, uiVerSign ? -Int( uiVerAbs ) : uiVerAbs ); |
---|
| 843 | pcCU->getCUMvField( eRefList )->setAllMvd( cMv, pcCU->getPartitionSize( uiAbsPartIdx ), uiAbsPartIdx, uiDepth, uiPartIdx ); |
---|
| 844 | return; |
---|
| 845 | } |
---|
| 846 | |
---|
[1029] | 847 | Void TDecSbac::parseCrossComponentPrediction( TComTU &rTu, ComponentID compID ) |
---|
| 848 | { |
---|
| 849 | TComDataCU *pcCU = rTu.getCU(); |
---|
[313] | 850 | |
---|
[1029] | 851 | if( isLuma(compID) || !pcCU->getSlice()->getPPS()->getUseCrossComponentPrediction() ) return; |
---|
| 852 | |
---|
| 853 | const UInt uiAbsPartIdx = rTu.GetAbsPartIdxTU(); |
---|
| 854 | |
---|
| 855 | if (!pcCU->isIntra(uiAbsPartIdx) || (pcCU->getIntraDir( CHANNEL_TYPE_CHROMA, uiAbsPartIdx ) == DM_CHROMA_IDX)) |
---|
| 856 | { |
---|
| 857 | Char alpha = 0; |
---|
| 858 | UInt symbol = 0; |
---|
| 859 | |
---|
| 860 | DTRACE_CABAC_VL( g_nSymbolCounter++ ) |
---|
| 861 | DTRACE_CABAC_T("\tparseCrossComponentPrediction()") |
---|
| 862 | DTRACE_CABAC_T( "\tAddr=" ) |
---|
| 863 | DTRACE_CABAC_V( compID ) |
---|
| 864 | DTRACE_CABAC_T( "\tuiAbsPartIdx=" ) |
---|
| 865 | DTRACE_CABAC_V( uiAbsPartIdx ) |
---|
| 866 | #if RExt__DECODER_DEBUG_BIT_STATISTICS |
---|
| 867 | TComCodingStatisticsClassType ctype(STATS__CABAC_BITS__CROSS_COMPONENT_PREDICTION, (g_aucConvertToBit[rTu.getRect(compID).width] + 2), compID); |
---|
| 868 | #endif |
---|
| 869 | ContextModel *pCtx = m_cCrossComponentPredictionSCModel.get(0, 0) + ((compID == COMPONENT_Cr) ? (NUM_CROSS_COMPONENT_PREDICTION_CTX >> 1) : 0); |
---|
| 870 | m_pcTDecBinIf->decodeBin( symbol, pCtx[0] RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(ctype) ); |
---|
| 871 | |
---|
| 872 | if(symbol != 0) |
---|
| 873 | { |
---|
| 874 | // Cross-component prediction alpha is non-zero. |
---|
| 875 | UInt sign = 0; |
---|
| 876 | m_pcTDecBinIf->decodeBin( symbol, pCtx[1] RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(ctype) ); |
---|
| 877 | |
---|
| 878 | if (symbol != 0) |
---|
| 879 | { |
---|
| 880 | // alpha is 2 (symbol=1), 4(symbol=2) or 8(symbol=3). |
---|
| 881 | // Read up to two more bits |
---|
| 882 | xReadUnaryMaxSymbol( symbol, (pCtx + 2), 1, 2 RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(ctype) ); |
---|
| 883 | symbol += 1; |
---|
| 884 | } |
---|
| 885 | m_pcTDecBinIf->decodeBin( sign, pCtx[4] RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(ctype) ); |
---|
| 886 | |
---|
| 887 | alpha = (sign != 0) ? -(1 << symbol) : (1 << symbol); |
---|
| 888 | } |
---|
| 889 | DTRACE_CABAC_T( "\tAlpha=" ) |
---|
| 890 | DTRACE_CABAC_V( alpha ) |
---|
| 891 | DTRACE_CABAC_T( "\n" ) |
---|
| 892 | |
---|
| 893 | pcCU->setCrossComponentPredictionAlphaPartRange( alpha, compID, uiAbsPartIdx, rTu.GetAbsPartIdxNumParts( compID ) ); |
---|
| 894 | } |
---|
| 895 | } |
---|
| 896 | |
---|
[313] | 897 | Void TDecSbac::parseTransformSubdivFlag( UInt& ruiSubdivFlag, UInt uiLog2TransformBlockSize ) |
---|
| 898 | { |
---|
[1029] | 899 | m_pcTDecBinIf->decodeBin( ruiSubdivFlag, m_cCUTransSubdivFlagSCModel.get( 0, 0, uiLog2TransformBlockSize ) |
---|
| 900 | RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(TComCodingStatisticsClassType(STATS__CABAC_BITS__TRANSFORM_SUBDIV_FLAG, 5-uiLog2TransformBlockSize)) |
---|
| 901 | ); |
---|
[313] | 902 | DTRACE_CABAC_VL( g_nSymbolCounter++ ) |
---|
| 903 | DTRACE_CABAC_T( "\tparseTransformSubdivFlag()" ) |
---|
| 904 | DTRACE_CABAC_T( "\tsymbol=" ) |
---|
| 905 | DTRACE_CABAC_V( ruiSubdivFlag ) |
---|
| 906 | DTRACE_CABAC_T( "\tctx=" ) |
---|
| 907 | DTRACE_CABAC_V( uiLog2TransformBlockSize ) |
---|
| 908 | DTRACE_CABAC_T( "\n" ) |
---|
| 909 | } |
---|
| 910 | |
---|
| 911 | Void TDecSbac::parseQtRootCbf( UInt uiAbsPartIdx, UInt& uiQtRootCbf ) |
---|
| 912 | { |
---|
| 913 | UInt uiSymbol; |
---|
| 914 | const UInt uiCtx = 0; |
---|
[1029] | 915 | m_pcTDecBinIf->decodeBin( uiSymbol , m_cCUQtRootCbfSCModel.get( 0, 0, uiCtx ) RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(STATS__CABAC_BITS__QT_ROOT_CBF) ); |
---|
[313] | 916 | DTRACE_CABAC_VL( g_nSymbolCounter++ ) |
---|
| 917 | DTRACE_CABAC_T( "\tparseQtRootCbf()" ) |
---|
| 918 | DTRACE_CABAC_T( "\tsymbol=" ) |
---|
| 919 | DTRACE_CABAC_V( uiSymbol ) |
---|
| 920 | DTRACE_CABAC_T( "\tctx=" ) |
---|
| 921 | DTRACE_CABAC_V( uiCtx ) |
---|
| 922 | DTRACE_CABAC_T( "\tuiAbsPartIdx=" ) |
---|
| 923 | DTRACE_CABAC_V( uiAbsPartIdx ) |
---|
| 924 | DTRACE_CABAC_T( "\n" ) |
---|
[1029] | 925 | |
---|
[313] | 926 | uiQtRootCbf = uiSymbol; |
---|
| 927 | } |
---|
| 928 | |
---|
| 929 | Void TDecSbac::parseDeltaQP( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth ) |
---|
| 930 | { |
---|
| 931 | Int qp; |
---|
| 932 | UInt uiDQp; |
---|
| 933 | Int iDQp; |
---|
[1029] | 934 | |
---|
[313] | 935 | UInt uiSymbol; |
---|
| 936 | |
---|
[1029] | 937 | xReadUnaryMaxSymbol (uiDQp, &m_cCUDeltaQpSCModel.get( 0, 0, 0 ), 1, CU_DQP_TU_CMAX RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(STATS__CABAC_BITS__DELTA_QP_EP) ); |
---|
[313] | 938 | |
---|
| 939 | if( uiDQp >= CU_DQP_TU_CMAX) |
---|
| 940 | { |
---|
[1029] | 941 | xReadEpExGolomb( uiSymbol, CU_DQP_EG_k RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(STATS__CABAC_BITS__DELTA_QP_EP)); |
---|
[313] | 942 | uiDQp+=uiSymbol; |
---|
| 943 | } |
---|
| 944 | |
---|
| 945 | if ( uiDQp > 0 ) |
---|
| 946 | { |
---|
| 947 | UInt uiSign; |
---|
[442] | 948 | #if REPN_FORMAT_IN_VPS |
---|
| 949 | Int qpBdOffsetY = pcCU->getSlice()->getQpBDOffsetY(); |
---|
| 950 | #else |
---|
[1029] | 951 | Int qpBdOffsetY = pcCU->getSlice()->getSPS()->getQpBDOffset(CHANNEL_TYPE_LUMA); |
---|
[442] | 952 | #endif |
---|
[1029] | 953 | m_pcTDecBinIf->decodeBinEP(uiSign RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(STATS__CABAC_BITS__DELTA_QP_EP)); |
---|
[313] | 954 | iDQp = uiDQp; |
---|
| 955 | if(uiSign) |
---|
| 956 | { |
---|
| 957 | iDQp = -iDQp; |
---|
| 958 | } |
---|
| 959 | qp = (((Int) pcCU->getRefQP( uiAbsPartIdx ) + iDQp + 52 + 2*qpBdOffsetY )%(52+qpBdOffsetY)) - qpBdOffsetY; |
---|
| 960 | } |
---|
[1029] | 961 | else |
---|
[313] | 962 | { |
---|
| 963 | qp = pcCU->getRefQP(uiAbsPartIdx); |
---|
| 964 | } |
---|
[1029] | 965 | |
---|
| 966 | pcCU->setQPSubParts(qp, uiAbsPartIdx, uiDepth); |
---|
[313] | 967 | pcCU->setCodedQP(qp); |
---|
| 968 | } |
---|
| 969 | |
---|
[1029] | 970 | /** parse chroma qp adjustment, converting to the internal table representation. |
---|
| 971 | * \returns Void |
---|
| 972 | */ |
---|
| 973 | Void TDecSbac::parseChromaQpAdjustment( TComDataCU* cu, UInt absPartIdx, UInt depth ) |
---|
[313] | 974 | { |
---|
[1029] | 975 | UInt symbol; |
---|
| 976 | #if RExt__DECODER_DEBUG_BIT_STATISTICS |
---|
| 977 | const TComCodingStatisticsClassType ctype(STATS__CABAC_BITS__CHROMA_QP_ADJUSTMENT, g_aucConvertToBit[g_uiMaxCUWidth>>depth]+2, CHANNEL_TYPE_CHROMA); |
---|
| 978 | #endif |
---|
| 979 | |
---|
| 980 | Int tableSize = cu->getSlice()->getPPS()->getChromaQpAdjTableSize(); |
---|
| 981 | |
---|
| 982 | /* cu_chroma_qp_adjustment_flag */ |
---|
| 983 | m_pcTDecBinIf->decodeBin( symbol, m_ChromaQpAdjFlagSCModel.get( 0, 0, 0 ) RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(ctype) ); |
---|
| 984 | |
---|
| 985 | if (symbol && tableSize > 1) { |
---|
| 986 | /* cu_chroma_qp_adjustment_idc */ |
---|
| 987 | xReadUnaryMaxSymbol( symbol, &m_ChromaQpAdjIdcSCModel.get( 0, 0, 0 ), 0, tableSize - 1 RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(ctype) ); |
---|
| 988 | symbol++; |
---|
| 989 | } |
---|
| 990 | /* NB, symbol = 0 if outer flag is not set, |
---|
| 991 | * 1 if outer flag is set and there is no inner flag |
---|
| 992 | * 1+ otherwise */ |
---|
| 993 | cu->setChromaQpAdjSubParts( symbol, absPartIdx, depth ); |
---|
| 994 | cu->setCodedChromaQpAdj(symbol); |
---|
| 995 | } |
---|
| 996 | |
---|
| 997 | Void TDecSbac::parseQtCbf( TComTU &rTu, const ComponentID compID, const Bool lowestLevel ) |
---|
| 998 | { |
---|
| 999 | TComDataCU* pcCU = rTu.getCU(); |
---|
| 1000 | |
---|
| 1001 | const UInt absPartIdx = rTu.GetAbsPartIdxTU(compID); |
---|
| 1002 | const UInt TUDepth = rTu.GetTransformDepthRel(); |
---|
| 1003 | const UInt uiCtx = pcCU->getCtxQtCbf( rTu, toChannelType(compID) ); |
---|
| 1004 | const UInt contextSet = toChannelType(compID); |
---|
| 1005 | |
---|
| 1006 | const UInt width = rTu.getRect(compID).width; |
---|
| 1007 | const UInt height = rTu.getRect(compID).height; |
---|
| 1008 | const Bool canQuadSplit = (width >= (MIN_TU_SIZE * 2)) && (height >= (MIN_TU_SIZE * 2)); |
---|
| 1009 | const UInt coveredPartIdxes = rTu.GetAbsPartIdxNumParts(compID); |
---|
| 1010 | |
---|
| 1011 | // Since the CBF for chroma is coded at the highest level possible, if sub-TUs are |
---|
| 1012 | // to be coded for a 4x8 chroma TU, their CBFs must be coded at the highest 4x8 level |
---|
| 1013 | // (i.e. where luma TUs are 8x8 rather than 4x4) |
---|
| 1014 | // ___ ___ |
---|
| 1015 | // | | | <- 4 x (8x8 luma + 4x8 4:2:2 chroma) |
---|
| 1016 | // |___|___| each quadrant has its own chroma CBF |
---|
| 1017 | // | | | _ _ _ _ |
---|
| 1018 | // |___|___| | |
---|
| 1019 | // <--16---> V |
---|
| 1020 | // _ _ |
---|
| 1021 | // |_|_| <- 4 x 4x4 luma + 1 x 4x8 4:2:2 chroma |
---|
| 1022 | // |_|_| no chroma CBF is coded - instead the parent CBF is inherited |
---|
| 1023 | // <-8-> if sub-TUs are present, their CBFs had to be coded at the parent level |
---|
| 1024 | |
---|
| 1025 | const UInt lowestTUDepth = TUDepth + ((!lowestLevel && !canQuadSplit) ? 1 : 0); //unsplittable TUs inherit their parent's CBF |
---|
| 1026 | UInt lowestTUCBF = 0; |
---|
| 1027 | |
---|
| 1028 | if ((width != height) && (lowestLevel || !canQuadSplit)) //if sub-TUs are present |
---|
[494] | 1029 | { |
---|
[1029] | 1030 | const UInt subTUDepth = lowestTUDepth + 1; |
---|
| 1031 | const UInt partIdxesPerSubTU = rTu.GetAbsPartIdxNumParts(compID) >> 1; |
---|
| 1032 | |
---|
| 1033 | UInt combinedSubTUCBF = 0; |
---|
| 1034 | |
---|
| 1035 | for (UInt subTU = 0; subTU < 2; subTU++) |
---|
| 1036 | { |
---|
| 1037 | UInt uiCbf = MAX_UINT; |
---|
| 1038 | m_pcTDecBinIf->decodeBin(uiCbf, m_cCUQtCbfSCModel.get(0, contextSet, uiCtx) RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(TComCodingStatisticsClassType(STATS__CABAC_BITS__QT_CBF, g_aucConvertToBit[rTu.getRect(compID).width]+2, compID))); |
---|
| 1039 | |
---|
| 1040 | const UInt subTUAbsPartIdx = absPartIdx + (subTU * partIdxesPerSubTU); |
---|
| 1041 | pcCU->setCbfPartRange((uiCbf << subTUDepth), compID, subTUAbsPartIdx, partIdxesPerSubTU); |
---|
| 1042 | combinedSubTUCBF |= uiCbf; |
---|
| 1043 | |
---|
| 1044 | DTRACE_CABAC_VL( g_nSymbolCounter++ ) |
---|
| 1045 | DTRACE_CABAC_T( "\tparseQtCbf()" ) |
---|
| 1046 | DTRACE_CABAC_T( "\tsub-TU=" ) |
---|
| 1047 | DTRACE_CABAC_V( subTU ) |
---|
| 1048 | DTRACE_CABAC_T( "\tsymbol=" ) |
---|
| 1049 | DTRACE_CABAC_V( uiCbf ) |
---|
| 1050 | DTRACE_CABAC_T( "\tctx=" ) |
---|
| 1051 | DTRACE_CABAC_V( uiCtx ) |
---|
| 1052 | DTRACE_CABAC_T( "\tetype=" ) |
---|
| 1053 | DTRACE_CABAC_V( compID ) |
---|
| 1054 | DTRACE_CABAC_T( "\tuiAbsPartIdx=" ) |
---|
| 1055 | DTRACE_CABAC_V( subTUAbsPartIdx ) |
---|
| 1056 | DTRACE_CABAC_T( "\n" ) |
---|
| 1057 | } |
---|
| 1058 | |
---|
| 1059 | //propagate the sub-TU CBF up to the lowest TU level |
---|
| 1060 | if (combinedSubTUCBF != 0) |
---|
| 1061 | { |
---|
| 1062 | pcCU->bitwiseOrCbfPartRange((combinedSubTUCBF << lowestTUDepth), compID, absPartIdx, coveredPartIdxes); |
---|
| 1063 | lowestTUCBF = combinedSubTUCBF; |
---|
| 1064 | } |
---|
[494] | 1065 | } |
---|
| 1066 | else |
---|
| 1067 | { |
---|
[1029] | 1068 | UInt uiCbf = MAX_UINT; |
---|
| 1069 | m_pcTDecBinIf->decodeBin(uiCbf, m_cCUQtCbfSCModel.get(0, contextSet, uiCtx) RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(TComCodingStatisticsClassType(STATS__CABAC_BITS__QT_CBF, g_aucConvertToBit[rTu.getRect(compID).width]+2, compID))); |
---|
| 1070 | |
---|
| 1071 | pcCU->setCbfSubParts((uiCbf << lowestTUDepth), compID, absPartIdx, rTu.GetTransformDepthTotalAdj(compID)); |
---|
| 1072 | |
---|
| 1073 | DTRACE_CABAC_VL( g_nSymbolCounter++ ) |
---|
| 1074 | DTRACE_CABAC_T( "\tparseQtCbf()" ) |
---|
| 1075 | DTRACE_CABAC_T( "\tsymbol=" ) |
---|
| 1076 | DTRACE_CABAC_V( uiCbf ) |
---|
| 1077 | DTRACE_CABAC_T( "\tctx=" ) |
---|
| 1078 | DTRACE_CABAC_V( uiCtx ) |
---|
| 1079 | DTRACE_CABAC_T( "\tetype=" ) |
---|
| 1080 | DTRACE_CABAC_V( compID ) |
---|
| 1081 | DTRACE_CABAC_T( "\tuiAbsPartIdx=" ) |
---|
| 1082 | DTRACE_CABAC_V( rTu.GetAbsPartIdxTU(compID) ) |
---|
| 1083 | DTRACE_CABAC_T( "\n" ) |
---|
| 1084 | |
---|
| 1085 | lowestTUCBF = uiCbf; |
---|
[494] | 1086 | } |
---|
[1029] | 1087 | |
---|
| 1088 | //propagate the lowest level CBF up to the current level |
---|
| 1089 | if (lowestTUCBF != 0) |
---|
| 1090 | { |
---|
| 1091 | for (UInt depth = TUDepth; depth < lowestTUDepth; depth++) |
---|
| 1092 | { |
---|
| 1093 | pcCU->bitwiseOrCbfPartRange((lowestTUCBF << depth), compID, absPartIdx, coveredPartIdxes); |
---|
| 1094 | } |
---|
| 1095 | } |
---|
[313] | 1096 | } |
---|
| 1097 | |
---|
[1029] | 1098 | |
---|
| 1099 | Void TDecSbac::parseTransformSkipFlags (TComTU &rTu, ComponentID component) |
---|
[313] | 1100 | { |
---|
[1029] | 1101 | TComDataCU* pcCU=rTu.getCU(); |
---|
| 1102 | UInt uiAbsPartIdx=rTu.GetAbsPartIdxTU(component); |
---|
| 1103 | |
---|
[313] | 1104 | if (pcCU->getCUTransquantBypass(uiAbsPartIdx)) |
---|
| 1105 | { |
---|
| 1106 | return; |
---|
| 1107 | } |
---|
[1029] | 1108 | |
---|
| 1109 | if (!TUCompRectHasAssociatedTransformSkipFlag(rTu.getRect(component), pcCU->getSlice()->getPPS()->getTransformSkipLog2MaxSize())) |
---|
[313] | 1110 | { |
---|
| 1111 | return; |
---|
| 1112 | } |
---|
[1029] | 1113 | |
---|
[313] | 1114 | UInt useTransformSkip; |
---|
[1029] | 1115 | |
---|
| 1116 | m_pcTDecBinIf->decodeBin( useTransformSkip , m_cTransformSkipSCModel.get( 0, toChannelType(component), 0 ) |
---|
| 1117 | RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(TComCodingStatisticsClassType(STATS__CABAC_BITS__TRANSFORM_SKIP_FLAGS, component)) |
---|
| 1118 | ); |
---|
| 1119 | |
---|
[313] | 1120 | DTRACE_CABAC_VL( g_nSymbolCounter++ ) |
---|
| 1121 | DTRACE_CABAC_T("\tparseTransformSkip()"); |
---|
| 1122 | DTRACE_CABAC_T( "\tsymbol=" ) |
---|
| 1123 | DTRACE_CABAC_V( useTransformSkip ) |
---|
| 1124 | DTRACE_CABAC_T( "\tAddr=" ) |
---|
[1029] | 1125 | DTRACE_CABAC_V( pcCU->getCtuRsAddr() ) |
---|
[313] | 1126 | DTRACE_CABAC_T( "\tetype=" ) |
---|
[1029] | 1127 | DTRACE_CABAC_V( component ) |
---|
[313] | 1128 | DTRACE_CABAC_T( "\tuiAbsPartIdx=" ) |
---|
[1029] | 1129 | DTRACE_CABAC_V( rTu.GetAbsPartIdxTU() ) |
---|
[313] | 1130 | DTRACE_CABAC_T( "\n" ) |
---|
| 1131 | |
---|
[1029] | 1132 | pcCU->setTransformSkipPartRange( useTransformSkip, component, uiAbsPartIdx, rTu.GetAbsPartIdxNumParts(component)); |
---|
[313] | 1133 | } |
---|
| 1134 | |
---|
[1029] | 1135 | |
---|
[313] | 1136 | /** Parse (X,Y) position of the last significant coefficient |
---|
| 1137 | * \param uiPosLastX reference to X component of last coefficient |
---|
| 1138 | * \param uiPosLastY reference to Y component of last coefficient |
---|
| 1139 | * \param width Block width |
---|
| 1140 | * \param height Block height |
---|
| 1141 | * \param eTType plane type / luminance or chrominance |
---|
| 1142 | * \param uiScanIdx scan type (zig-zag, hor, ver) |
---|
| 1143 | * |
---|
| 1144 | * This method decodes the X and Y component within a block of the last significant coefficient. |
---|
| 1145 | */ |
---|
[1029] | 1146 | Void TDecSbac::parseLastSignificantXY( UInt& uiPosLastX, UInt& uiPosLastY, Int width, Int height, ComponentID component, UInt uiScanIdx ) |
---|
[313] | 1147 | { |
---|
| 1148 | UInt uiLast; |
---|
| 1149 | |
---|
[1029] | 1150 | ContextModel *pCtxX = m_cCuCtxLastX.get( 0, toChannelType(component) ); |
---|
| 1151 | ContextModel *pCtxY = m_cCuCtxLastY.get( 0, toChannelType(component) ); |
---|
| 1152 | |
---|
| 1153 | #if RExt__DECODER_DEBUG_BIT_STATISTICS |
---|
| 1154 | TComCodingStatisticsClassType ctype(STATS__CABAC_BITS__LAST_SIG_X_Y, g_aucConvertToBit[width]+2, component); |
---|
| 1155 | #endif |
---|
| 1156 | |
---|
| 1157 | |
---|
| 1158 | if ( uiScanIdx == SCAN_VER ) |
---|
| 1159 | { |
---|
| 1160 | swap( width, height ); |
---|
| 1161 | } |
---|
| 1162 | |
---|
[313] | 1163 | Int blkSizeOffsetX, blkSizeOffsetY, shiftX, shiftY; |
---|
[1029] | 1164 | getLastSignificantContextParameters(component, width, height, blkSizeOffsetX, blkSizeOffsetY, shiftX, shiftY); |
---|
| 1165 | |
---|
| 1166 | //------------------ |
---|
| 1167 | |
---|
[313] | 1168 | // posX |
---|
[1029] | 1169 | |
---|
[313] | 1170 | for( uiPosLastX = 0; uiPosLastX < g_uiGroupIdx[ width - 1 ]; uiPosLastX++ ) |
---|
| 1171 | { |
---|
[1029] | 1172 | m_pcTDecBinIf->decodeBin( uiLast, *( pCtxX + blkSizeOffsetX + (uiPosLastX >>shiftX) ) RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(ctype) ); |
---|
| 1173 | |
---|
[313] | 1174 | if( !uiLast ) |
---|
| 1175 | { |
---|
| 1176 | break; |
---|
| 1177 | } |
---|
| 1178 | } |
---|
| 1179 | |
---|
| 1180 | // posY |
---|
[1029] | 1181 | |
---|
[313] | 1182 | for( uiPosLastY = 0; uiPosLastY < g_uiGroupIdx[ height - 1 ]; uiPosLastY++ ) |
---|
| 1183 | { |
---|
[1029] | 1184 | m_pcTDecBinIf->decodeBin( uiLast, *( pCtxY + blkSizeOffsetY + (uiPosLastY >>shiftY)) RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(ctype) ); |
---|
| 1185 | |
---|
[313] | 1186 | if( !uiLast ) |
---|
| 1187 | { |
---|
| 1188 | break; |
---|
| 1189 | } |
---|
| 1190 | } |
---|
[1029] | 1191 | |
---|
| 1192 | // EP-coded part |
---|
| 1193 | |
---|
[313] | 1194 | if ( uiPosLastX > 3 ) |
---|
| 1195 | { |
---|
| 1196 | UInt uiTemp = 0; |
---|
| 1197 | UInt uiCount = ( uiPosLastX - 2 ) >> 1; |
---|
| 1198 | for ( Int i = uiCount - 1; i >= 0; i-- ) |
---|
| 1199 | { |
---|
[1029] | 1200 | m_pcTDecBinIf->decodeBinEP( uiLast RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(ctype) ); |
---|
[313] | 1201 | uiTemp += uiLast << i; |
---|
| 1202 | } |
---|
| 1203 | uiPosLastX = g_uiMinInGroup[ uiPosLastX ] + uiTemp; |
---|
| 1204 | } |
---|
| 1205 | if ( uiPosLastY > 3 ) |
---|
| 1206 | { |
---|
| 1207 | UInt uiTemp = 0; |
---|
| 1208 | UInt uiCount = ( uiPosLastY - 2 ) >> 1; |
---|
| 1209 | for ( Int i = uiCount - 1; i >= 0; i-- ) |
---|
| 1210 | { |
---|
[1029] | 1211 | m_pcTDecBinIf->decodeBinEP( uiLast RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(ctype) ); |
---|
[313] | 1212 | uiTemp += uiLast << i; |
---|
| 1213 | } |
---|
| 1214 | uiPosLastY = g_uiMinInGroup[ uiPosLastY ] + uiTemp; |
---|
| 1215 | } |
---|
[1029] | 1216 | |
---|
[313] | 1217 | if( uiScanIdx == SCAN_VER ) |
---|
| 1218 | { |
---|
| 1219 | swap( uiPosLastX, uiPosLastY ); |
---|
| 1220 | } |
---|
| 1221 | } |
---|
| 1222 | |
---|
[1029] | 1223 | Void TDecSbac::parseCoeffNxN( TComTU &rTu, ComponentID compID ) |
---|
[313] | 1224 | { |
---|
[1029] | 1225 | TComDataCU* pcCU=rTu.getCU(); |
---|
| 1226 | const UInt uiAbsPartIdx=rTu.GetAbsPartIdxTU(compID); |
---|
| 1227 | const TComRectangle &rRect=rTu.getRect(compID); |
---|
| 1228 | const UInt uiWidth=rRect.width; |
---|
| 1229 | const UInt uiHeight=rRect.height; |
---|
| 1230 | TCoeff* pcCoef=(pcCU->getCoeff(compID)+rTu.getCoefficientOffset(compID)); |
---|
| 1231 | |
---|
[313] | 1232 | DTRACE_CABAC_VL( g_nSymbolCounter++ ) |
---|
| 1233 | DTRACE_CABAC_T( "\tparseCoeffNxN()\teType=" ) |
---|
[1029] | 1234 | DTRACE_CABAC_V( compID ) |
---|
[313] | 1235 | DTRACE_CABAC_T( "\twidth=" ) |
---|
| 1236 | DTRACE_CABAC_V( uiWidth ) |
---|
| 1237 | DTRACE_CABAC_T( "\theight=" ) |
---|
| 1238 | DTRACE_CABAC_V( uiHeight ) |
---|
| 1239 | DTRACE_CABAC_T( "\tdepth=" ) |
---|
[1029] | 1240 | // DTRACE_CABAC_V( rTu.GetTransformDepthTotalAdj(compID) ) |
---|
| 1241 | DTRACE_CABAC_V( rTu.GetTransformDepthTotal() ) |
---|
[313] | 1242 | DTRACE_CABAC_T( "\tabspartidx=" ) |
---|
[1029] | 1243 | // DTRACE_CABAC_V( uiAbsPartIdx ) |
---|
| 1244 | DTRACE_CABAC_V( rTu.GetAbsPartIdxTU(compID) ) |
---|
[313] | 1245 | DTRACE_CABAC_T( "\ttoCU-X=" ) |
---|
| 1246 | DTRACE_CABAC_V( pcCU->getCUPelX() ) |
---|
| 1247 | DTRACE_CABAC_T( "\ttoCU-Y=" ) |
---|
| 1248 | DTRACE_CABAC_V( pcCU->getCUPelY() ) |
---|
| 1249 | DTRACE_CABAC_T( "\tCU-addr=" ) |
---|
[1029] | 1250 | DTRACE_CABAC_V( pcCU->getCtuRsAddr() ) |
---|
[313] | 1251 | DTRACE_CABAC_T( "\tinCU-X=" ) |
---|
[1029] | 1252 | // DTRACE_CABAC_V( g_auiRasterToPelX[ g_auiZscanToRaster[uiAbsPartIdx] ] ) |
---|
| 1253 | DTRACE_CABAC_V( g_auiRasterToPelX[ g_auiZscanToRaster[rTu.GetAbsPartIdxTU(compID)] ] ) |
---|
[313] | 1254 | DTRACE_CABAC_T( "\tinCU-Y=" ) |
---|
[1029] | 1255 | // DTRACE_CABAC_V( g_auiRasterToPelY[ g_auiZscanToRaster[uiAbsPartIdx] ] ) |
---|
| 1256 | DTRACE_CABAC_V( g_auiRasterToPelY[ g_auiZscanToRaster[rTu.GetAbsPartIdxTU(compID)] ] ) |
---|
[313] | 1257 | DTRACE_CABAC_T( "\tpredmode=" ) |
---|
| 1258 | DTRACE_CABAC_V( pcCU->getPredictionMode( uiAbsPartIdx ) ) |
---|
| 1259 | DTRACE_CABAC_T( "\n" ) |
---|
[1029] | 1260 | |
---|
| 1261 | //-------------------------------------------------------------------------------------------------- |
---|
| 1262 | |
---|
[313] | 1263 | if( uiWidth > pcCU->getSlice()->getSPS()->getMaxTrSize() ) |
---|
| 1264 | { |
---|
[1029] | 1265 | std::cerr << "ERROR: parseCoeffNxN was passed a TU with dimensions larger than the maximum allowed size" << std::endl; |
---|
| 1266 | assert(false); |
---|
| 1267 | exit(1); |
---|
[313] | 1268 | } |
---|
[1029] | 1269 | |
---|
| 1270 | //-------------------------------------------------------------------------------------------------- |
---|
| 1271 | |
---|
| 1272 | //set parameters |
---|
| 1273 | |
---|
| 1274 | const ChannelType chType = toChannelType(compID); |
---|
| 1275 | const UInt uiLog2BlockWidth = g_aucConvertToBit[ uiWidth ] + 2; |
---|
| 1276 | const UInt uiLog2BlockHeight = g_aucConvertToBit[ uiHeight ] + 2; |
---|
| 1277 | const UInt uiMaxNumCoeff = uiWidth * uiHeight; |
---|
| 1278 | const UInt uiMaxNumCoeffM1 = uiMaxNumCoeff - 1; |
---|
| 1279 | |
---|
| 1280 | const ChannelType channelType = toChannelType(compID); |
---|
| 1281 | const Bool extendedPrecision = pcCU->getSlice()->getSPS()->getUseExtendedPrecision(); |
---|
| 1282 | |
---|
| 1283 | const Bool alignCABACBeforeBypass = pcCU->getSlice()->getSPS()->getAlignCABACBeforeBypass(); |
---|
| 1284 | |
---|
| 1285 | #if RExt__DECODER_DEBUG_BIT_STATISTICS |
---|
| 1286 | TComCodingStatisticsClassType ctype_group(STATS__CABAC_BITS__SIG_COEFF_GROUP_FLAG, uiLog2BlockWidth, compID); |
---|
| 1287 | TComCodingStatisticsClassType ctype_map(STATS__CABAC_BITS__SIG_COEFF_MAP_FLAG, uiLog2BlockWidth, compID); |
---|
| 1288 | TComCodingStatisticsClassType ctype_gt1(STATS__CABAC_BITS__GT1_FLAG, uiLog2BlockWidth, compID); |
---|
| 1289 | TComCodingStatisticsClassType ctype_gt2(STATS__CABAC_BITS__GT2_FLAG, uiLog2BlockWidth, compID); |
---|
| 1290 | #endif |
---|
| 1291 | |
---|
| 1292 | Bool beValid; |
---|
| 1293 | if (pcCU->getCUTransquantBypass(uiAbsPartIdx)) |
---|
| 1294 | { |
---|
| 1295 | beValid = false; |
---|
| 1296 | if((!pcCU->isIntra(uiAbsPartIdx)) && pcCU->isRDPCMEnabled(uiAbsPartIdx)) |
---|
| 1297 | parseExplicitRdpcmMode(rTu, compID); |
---|
| 1298 | } |
---|
| 1299 | else |
---|
| 1300 | { |
---|
| 1301 | beValid = pcCU->getSlice()->getPPS()->getSignHideFlag() > 0; |
---|
| 1302 | } |
---|
| 1303 | |
---|
| 1304 | UInt absSum = 0; |
---|
| 1305 | |
---|
| 1306 | //-------------------------------------------------------------------------------------------------- |
---|
| 1307 | |
---|
[313] | 1308 | if(pcCU->getSlice()->getPPS()->getUseTransformSkip()) |
---|
| 1309 | { |
---|
[1029] | 1310 | parseTransformSkipFlags(rTu, compID); |
---|
| 1311 | // This TU has coefficients and is transform skipped. Check whether is inter coded and if yes decode the explicit RDPCM mode |
---|
| 1312 | if(pcCU->getTransformSkip(uiAbsPartIdx, compID) && (!pcCU->isIntra(uiAbsPartIdx)) && pcCU->isRDPCMEnabled(uiAbsPartIdx) ) |
---|
| 1313 | { |
---|
| 1314 | parseExplicitRdpcmMode(rTu, compID); |
---|
| 1315 | if(pcCU->getExplicitRdpcmMode(compID, uiAbsPartIdx) != RDPCM_OFF) |
---|
| 1316 | { |
---|
| 1317 | // Sign data hiding is avoided for horizontal and vertical RDPCM modes |
---|
| 1318 | beValid = false; |
---|
| 1319 | } |
---|
| 1320 | } |
---|
[313] | 1321 | } |
---|
| 1322 | |
---|
[1029] | 1323 | Int uiIntraMode = -1; |
---|
| 1324 | const Bool bIsLuma = isLuma(compID); |
---|
| 1325 | Int isIntra = pcCU->isIntra(uiAbsPartIdx) ? 1 : 0; |
---|
| 1326 | if ( isIntra && pcCU->isRDPCMEnabled(uiAbsPartIdx) ) |
---|
| 1327 | { |
---|
| 1328 | uiIntraMode = pcCU->getIntraDir( toChannelType(compID), uiAbsPartIdx ); |
---|
| 1329 | uiIntraMode = (uiIntraMode==DM_CHROMA_IDX && !bIsLuma) ? pcCU->getIntraDir(CHANNEL_TYPE_LUMA, getChromasCorrespondingPULumaIdx(uiAbsPartIdx, rTu.GetChromaFormat())) : uiIntraMode; |
---|
| 1330 | uiIntraMode = ((rTu.GetChromaFormat() == CHROMA_422) && !bIsLuma) ? g_chroma422IntraAngleMappingTable[uiIntraMode] : uiIntraMode; |
---|
| 1331 | |
---|
| 1332 | Bool transformSkip = pcCU->getTransformSkip( uiAbsPartIdx,compID); |
---|
| 1333 | Bool rdpcm_lossy = ( transformSkip /*&& isIntra*/ && ( (uiIntraMode == HOR_IDX) || (uiIntraMode == VER_IDX) ) ); |
---|
| 1334 | if ( rdpcm_lossy ) |
---|
| 1335 | { |
---|
| 1336 | beValid = false; |
---|
| 1337 | } |
---|
| 1338 | } |
---|
| 1339 | |
---|
| 1340 | //-------------------------------------------------------------------------------------------------- |
---|
| 1341 | |
---|
| 1342 | const Bool bUseGolombRiceParameterAdaptation = pcCU->getSlice()->getSPS()->getUseGolombRiceParameterAdaptation(); |
---|
| 1343 | UInt ¤tGolombRiceStatistic = m_golombRiceAdaptationStatistics[rTu.getGolombRiceStatisticsIndex(compID)]; |
---|
| 1344 | |
---|
| 1345 | //select scans |
---|
| 1346 | TUEntropyCodingParameters codingParameters; |
---|
| 1347 | getTUEntropyCodingParameters(codingParameters, rTu, compID); |
---|
| 1348 | |
---|
[313] | 1349 | //===== decode last significant ===== |
---|
| 1350 | UInt uiPosLastX, uiPosLastY; |
---|
[1029] | 1351 | parseLastSignificantXY( uiPosLastX, uiPosLastY, uiWidth, uiHeight, compID, codingParameters.scanType ); |
---|
| 1352 | UInt uiBlkPosLast = uiPosLastX + (uiPosLastY<<uiLog2BlockWidth); |
---|
[313] | 1353 | pcCoef[ uiBlkPosLast ] = 1; |
---|
| 1354 | |
---|
| 1355 | //===== decode significance flags ===== |
---|
| 1356 | UInt uiScanPosLast; |
---|
| 1357 | for( uiScanPosLast = 0; uiScanPosLast < uiMaxNumCoeffM1; uiScanPosLast++ ) |
---|
| 1358 | { |
---|
[1029] | 1359 | UInt uiBlkPos = codingParameters.scan[ uiScanPosLast ]; |
---|
[313] | 1360 | if( uiBlkPosLast == uiBlkPos ) |
---|
| 1361 | { |
---|
| 1362 | break; |
---|
| 1363 | } |
---|
| 1364 | } |
---|
| 1365 | |
---|
[1029] | 1366 | ContextModel * const baseCoeffGroupCtx = m_cCUSigCoeffGroupSCModel.get( 0, isChroma(chType) ); |
---|
| 1367 | ContextModel * const baseCtx = m_cCUSigSCModel.get( 0, 0 ) + getSignificanceMapContextOffset(compID); |
---|
[313] | 1368 | |
---|
[1029] | 1369 | const Int iLastScanSet = uiScanPosLast >> MLS_CG_SIZE; |
---|
| 1370 | UInt c1 = 1; |
---|
| 1371 | UInt uiGoRiceParam = 0; |
---|
[313] | 1372 | |
---|
| 1373 | |
---|
| 1374 | UInt uiSigCoeffGroupFlag[ MLS_GRP_NUM ]; |
---|
[1029] | 1375 | memset( uiSigCoeffGroupFlag, 0, sizeof(UInt) * MLS_GRP_NUM ); |
---|
| 1376 | |
---|
[313] | 1377 | Int iScanPosSig = (Int) uiScanPosLast; |
---|
| 1378 | for( Int iSubSet = iLastScanSet; iSubSet >= 0; iSubSet-- ) |
---|
| 1379 | { |
---|
[1029] | 1380 | Int iSubPos = iSubSet << MLS_CG_SIZE; |
---|
| 1381 | uiGoRiceParam = currentGolombRiceStatistic / RExt__GOLOMB_RICE_INCREMENT_DIVISOR; |
---|
| 1382 | Bool updateGolombRiceStatistics = bUseGolombRiceParameterAdaptation; //leave the statistics at 0 when not using the adaptation system |
---|
[313] | 1383 | Int numNonZero = 0; |
---|
| 1384 | |
---|
[1029] | 1385 | Int lastNZPosInCG = -1; |
---|
| 1386 | Int firstNZPosInCG = 1 << MLS_CG_SIZE; |
---|
| 1387 | |
---|
| 1388 | Bool escapeDataPresentInGroup = false; |
---|
| 1389 | |
---|
| 1390 | Int pos[1 << MLS_CG_SIZE]; |
---|
| 1391 | |
---|
[313] | 1392 | if( iScanPosSig == (Int) uiScanPosLast ) |
---|
| 1393 | { |
---|
| 1394 | lastNZPosInCG = iScanPosSig; |
---|
| 1395 | firstNZPosInCG = iScanPosSig; |
---|
| 1396 | iScanPosSig--; |
---|
| 1397 | pos[ numNonZero ] = uiBlkPosLast; |
---|
| 1398 | numNonZero = 1; |
---|
| 1399 | } |
---|
| 1400 | |
---|
| 1401 | // decode significant_coeffgroup_flag |
---|
[1029] | 1402 | Int iCGBlkPos = codingParameters.scanCG[ iSubSet ]; |
---|
| 1403 | Int iCGPosY = iCGBlkPos / codingParameters.widthInGroups; |
---|
| 1404 | Int iCGPosX = iCGBlkPos - (iCGPosY * codingParameters.widthInGroups); |
---|
| 1405 | |
---|
[313] | 1406 | if( iSubSet == iLastScanSet || iSubSet == 0) |
---|
| 1407 | { |
---|
| 1408 | uiSigCoeffGroupFlag[ iCGBlkPos ] = 1; |
---|
| 1409 | } |
---|
| 1410 | else |
---|
| 1411 | { |
---|
| 1412 | UInt uiSigCoeffGroup; |
---|
[1029] | 1413 | UInt uiCtxSig = TComTrQuant::getSigCoeffGroupCtxInc( uiSigCoeffGroupFlag, iCGPosX, iCGPosY, codingParameters.widthInGroups, codingParameters.heightInGroups ); |
---|
| 1414 | m_pcTDecBinIf->decodeBin( uiSigCoeffGroup, baseCoeffGroupCtx[ uiCtxSig ] RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(ctype_group) ); |
---|
[313] | 1415 | uiSigCoeffGroupFlag[ iCGBlkPos ] = uiSigCoeffGroup; |
---|
| 1416 | } |
---|
| 1417 | |
---|
| 1418 | // decode significant_coeff_flag |
---|
[1029] | 1419 | const Int patternSigCtx = TComTrQuant::calcPatternSigCtx(uiSigCoeffGroupFlag, iCGPosX, iCGPosY, codingParameters.widthInGroups, codingParameters.heightInGroups); |
---|
| 1420 | |
---|
| 1421 | UInt uiBlkPos, uiSig, uiCtxSig; |
---|
[313] | 1422 | for( ; iScanPosSig >= iSubPos; iScanPosSig-- ) |
---|
| 1423 | { |
---|
[1029] | 1424 | uiBlkPos = codingParameters.scan[ iScanPosSig ]; |
---|
[313] | 1425 | uiSig = 0; |
---|
[1029] | 1426 | |
---|
[313] | 1427 | if( uiSigCoeffGroupFlag[ iCGBlkPos ] ) |
---|
| 1428 | { |
---|
| 1429 | if( iScanPosSig > iSubPos || iSubSet == 0 || numNonZero ) |
---|
| 1430 | { |
---|
[1029] | 1431 | uiCtxSig = TComTrQuant::getSigCtxInc( patternSigCtx, codingParameters, iScanPosSig, uiLog2BlockWidth, uiLog2BlockHeight, chType ); |
---|
| 1432 | m_pcTDecBinIf->decodeBin( uiSig, baseCtx[ uiCtxSig ] RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(ctype_map) ); |
---|
[313] | 1433 | } |
---|
| 1434 | else |
---|
| 1435 | { |
---|
| 1436 | uiSig = 1; |
---|
| 1437 | } |
---|
| 1438 | } |
---|
| 1439 | pcCoef[ uiBlkPos ] = uiSig; |
---|
| 1440 | if( uiSig ) |
---|
| 1441 | { |
---|
| 1442 | pos[ numNonZero ] = uiBlkPos; |
---|
| 1443 | numNonZero ++; |
---|
| 1444 | if( lastNZPosInCG == -1 ) |
---|
| 1445 | { |
---|
| 1446 | lastNZPosInCG = iScanPosSig; |
---|
| 1447 | } |
---|
| 1448 | firstNZPosInCG = iScanPosSig; |
---|
| 1449 | } |
---|
| 1450 | } |
---|
[1029] | 1451 | |
---|
| 1452 | if( numNonZero > 0 ) |
---|
[313] | 1453 | { |
---|
| 1454 | Bool signHidden = ( lastNZPosInCG - firstNZPosInCG >= SBH_THRESHOLD ); |
---|
[1029] | 1455 | |
---|
[313] | 1456 | absSum = 0; |
---|
[1029] | 1457 | |
---|
| 1458 | const UInt uiCtxSet = getContextSetIndex(compID, iSubSet, (c1 == 0)); |
---|
| 1459 | c1 = 1; |
---|
[313] | 1460 | UInt uiBin; |
---|
| 1461 | |
---|
[1029] | 1462 | ContextModel *baseCtxMod = m_cCUOneSCModel.get( 0, 0 ) + (NUM_ONE_FLAG_CTX_PER_SET * uiCtxSet); |
---|
| 1463 | |
---|
| 1464 | Int absCoeff[1 << MLS_CG_SIZE]; |
---|
| 1465 | |
---|
| 1466 | for ( Int i = 0; i < numNonZero; i++) absCoeff[i] = 1; |
---|
[313] | 1467 | Int numC1Flag = min(numNonZero, C1FLAG_NUMBER); |
---|
| 1468 | Int firstC2FlagIdx = -1; |
---|
| 1469 | |
---|
| 1470 | for( Int idx = 0; idx < numC1Flag; idx++ ) |
---|
| 1471 | { |
---|
[1029] | 1472 | m_pcTDecBinIf->decodeBin( uiBin, baseCtxMod[c1] RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(ctype_gt1) ); |
---|
[313] | 1473 | if( uiBin == 1 ) |
---|
| 1474 | { |
---|
| 1475 | c1 = 0; |
---|
| 1476 | if (firstC2FlagIdx == -1) |
---|
| 1477 | { |
---|
| 1478 | firstC2FlagIdx = idx; |
---|
| 1479 | } |
---|
[1029] | 1480 | else //if a greater-than-one has been encountered already this group |
---|
| 1481 | { |
---|
| 1482 | escapeDataPresentInGroup = true; |
---|
| 1483 | } |
---|
[313] | 1484 | } |
---|
| 1485 | else if( (c1 < 3) && (c1 > 0) ) |
---|
| 1486 | { |
---|
| 1487 | c1++; |
---|
| 1488 | } |
---|
| 1489 | absCoeff[ idx ] = uiBin + 1; |
---|
| 1490 | } |
---|
[1029] | 1491 | |
---|
[313] | 1492 | if (c1 == 0) |
---|
| 1493 | { |
---|
[1029] | 1494 | baseCtxMod = m_cCUAbsSCModel.get( 0, 0 ) + (NUM_ABS_FLAG_CTX_PER_SET * uiCtxSet); |
---|
[313] | 1495 | if ( firstC2FlagIdx != -1) |
---|
| 1496 | { |
---|
[1029] | 1497 | m_pcTDecBinIf->decodeBin( uiBin, baseCtxMod[0] RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(ctype_gt2) ); |
---|
[313] | 1498 | absCoeff[ firstC2FlagIdx ] = uiBin + 2; |
---|
[1029] | 1499 | if (uiBin != 0) |
---|
| 1500 | { |
---|
| 1501 | escapeDataPresentInGroup = true; |
---|
| 1502 | } |
---|
[313] | 1503 | } |
---|
| 1504 | } |
---|
| 1505 | |
---|
[1029] | 1506 | escapeDataPresentInGroup = escapeDataPresentInGroup || (numNonZero > C1FLAG_NUMBER); |
---|
| 1507 | |
---|
| 1508 | const Bool alignGroup = escapeDataPresentInGroup && alignCABACBeforeBypass; |
---|
| 1509 | |
---|
| 1510 | #if RExt__DECODER_DEBUG_BIT_STATISTICS |
---|
| 1511 | TComCodingStatisticsClassType ctype_signs((alignGroup ? STATS__CABAC_BITS__ALIGNED_SIGN_BIT : STATS__CABAC_BITS__SIGN_BIT ), uiLog2BlockWidth, compID); |
---|
| 1512 | TComCodingStatisticsClassType ctype_escs ((alignGroup ? STATS__CABAC_BITS__ALIGNED_ESCAPE_BITS : STATS__CABAC_BITS__ESCAPE_BITS), uiLog2BlockWidth, compID); |
---|
| 1513 | #endif |
---|
| 1514 | |
---|
| 1515 | if (alignGroup) |
---|
| 1516 | { |
---|
| 1517 | m_pcTDecBinIf->align(); |
---|
| 1518 | } |
---|
| 1519 | |
---|
[313] | 1520 | UInt coeffSigns; |
---|
| 1521 | if ( signHidden && beValid ) |
---|
| 1522 | { |
---|
[1029] | 1523 | m_pcTDecBinIf->decodeBinsEP( coeffSigns, numNonZero-1 RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(ctype_signs) ); |
---|
[313] | 1524 | coeffSigns <<= 32 - (numNonZero-1); |
---|
| 1525 | } |
---|
| 1526 | else |
---|
| 1527 | { |
---|
[1029] | 1528 | m_pcTDecBinIf->decodeBinsEP( coeffSigns, numNonZero RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(ctype_signs) ); |
---|
[313] | 1529 | coeffSigns <<= 32 - numNonZero; |
---|
| 1530 | } |
---|
[1029] | 1531 | |
---|
| 1532 | Int iFirstCoeff2 = 1; |
---|
| 1533 | if (escapeDataPresentInGroup) |
---|
[313] | 1534 | { |
---|
| 1535 | for( Int idx = 0; idx < numNonZero; idx++ ) |
---|
| 1536 | { |
---|
| 1537 | UInt baseLevel = (idx < C1FLAG_NUMBER)? (2 + iFirstCoeff2) : 1; |
---|
| 1538 | |
---|
| 1539 | if( absCoeff[ idx ] == baseLevel) |
---|
| 1540 | { |
---|
| 1541 | UInt uiLevel; |
---|
[1029] | 1542 | xReadCoefRemainExGolomb( uiLevel, uiGoRiceParam, extendedPrecision, channelType RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(ctype_escs) ); |
---|
| 1543 | |
---|
[313] | 1544 | absCoeff[ idx ] = uiLevel + baseLevel; |
---|
[1029] | 1545 | |
---|
| 1546 | if (absCoeff[idx] > (3 << uiGoRiceParam)) |
---|
[313] | 1547 | { |
---|
[1029] | 1548 | uiGoRiceParam = bUseGolombRiceParameterAdaptation ? (uiGoRiceParam + 1) : (std::min<UInt>((uiGoRiceParam + 1), 4)); |
---|
[313] | 1549 | } |
---|
[1029] | 1550 | |
---|
| 1551 | if (updateGolombRiceStatistics) |
---|
| 1552 | { |
---|
| 1553 | const UInt initialGolombRiceParameter = currentGolombRiceStatistic / RExt__GOLOMB_RICE_INCREMENT_DIVISOR; |
---|
| 1554 | |
---|
| 1555 | if (uiLevel >= (3 << initialGolombRiceParameter)) |
---|
| 1556 | { |
---|
| 1557 | currentGolombRiceStatistic++; |
---|
| 1558 | } |
---|
| 1559 | else if (((uiLevel * 2) < (1 << initialGolombRiceParameter)) && (currentGolombRiceStatistic > 0)) |
---|
| 1560 | { |
---|
| 1561 | currentGolombRiceStatistic--; |
---|
| 1562 | } |
---|
| 1563 | |
---|
| 1564 | updateGolombRiceStatistics = false; |
---|
| 1565 | } |
---|
[313] | 1566 | } |
---|
| 1567 | |
---|
[1029] | 1568 | if(absCoeff[ idx ] >= 2) |
---|
[313] | 1569 | { |
---|
| 1570 | iFirstCoeff2 = 0; |
---|
| 1571 | } |
---|
| 1572 | } |
---|
| 1573 | } |
---|
| 1574 | |
---|
| 1575 | for( Int idx = 0; idx < numNonZero; idx++ ) |
---|
| 1576 | { |
---|
| 1577 | Int blkPos = pos[ idx ]; |
---|
| 1578 | // Signs applied later. |
---|
| 1579 | pcCoef[ blkPos ] = absCoeff[ idx ]; |
---|
| 1580 | absSum += absCoeff[ idx ]; |
---|
| 1581 | |
---|
| 1582 | if ( idx == numNonZero-1 && signHidden && beValid ) |
---|
| 1583 | { |
---|
| 1584 | // Infer sign of 1st element. |
---|
[1029] | 1585 | if (absSum&0x1) pcCoef[ blkPos ] = -pcCoef[ blkPos ]; |
---|
[313] | 1586 | } |
---|
| 1587 | else |
---|
| 1588 | { |
---|
| 1589 | Int sign = static_cast<Int>( coeffSigns ) >> 31; |
---|
| 1590 | pcCoef[ blkPos ] = ( pcCoef[ blkPos ] ^ sign ) - sign; |
---|
| 1591 | coeffSigns <<= 1; |
---|
| 1592 | } |
---|
| 1593 | } |
---|
| 1594 | } |
---|
| 1595 | } |
---|
[1029] | 1596 | |
---|
| 1597 | #if ENVIRONMENT_VARIABLE_DEBUG_AND_TEST |
---|
| 1598 | printSBACCoeffData(uiPosLastX, uiPosLastY, uiWidth, uiHeight, compID, uiAbsPartIdx, codingParameters.scanType, pcCoef); |
---|
| 1599 | #endif |
---|
| 1600 | |
---|
[313] | 1601 | return; |
---|
| 1602 | } |
---|
| 1603 | |
---|
| 1604 | Void TDecSbac::parseSaoMaxUvlc ( UInt& val, UInt maxSymbol ) |
---|
| 1605 | { |
---|
| 1606 | if (maxSymbol == 0) |
---|
| 1607 | { |
---|
| 1608 | val = 0; |
---|
| 1609 | return; |
---|
| 1610 | } |
---|
| 1611 | |
---|
| 1612 | UInt code; |
---|
| 1613 | Int i; |
---|
[1029] | 1614 | m_pcTDecBinIf->decodeBinEP( code RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(STATS__CABAC_BITS__SAO) ); |
---|
[313] | 1615 | if ( code == 0 ) |
---|
| 1616 | { |
---|
| 1617 | val = 0; |
---|
| 1618 | return; |
---|
| 1619 | } |
---|
| 1620 | |
---|
| 1621 | i=1; |
---|
| 1622 | while (1) |
---|
| 1623 | { |
---|
[1029] | 1624 | m_pcTDecBinIf->decodeBinEP( code RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(STATS__CABAC_BITS__SAO) ); |
---|
[313] | 1625 | if ( code == 0 ) |
---|
| 1626 | { |
---|
| 1627 | break; |
---|
| 1628 | } |
---|
| 1629 | i++; |
---|
[1029] | 1630 | if (i == maxSymbol) |
---|
[313] | 1631 | { |
---|
| 1632 | break; |
---|
| 1633 | } |
---|
| 1634 | } |
---|
| 1635 | |
---|
| 1636 | val = i; |
---|
| 1637 | } |
---|
[1029] | 1638 | |
---|
[313] | 1639 | Void TDecSbac::parseSaoUflc (UInt uiLength, UInt& riVal) |
---|
| 1640 | { |
---|
[1029] | 1641 | m_pcTDecBinIf->decodeBinsEP ( riVal, uiLength RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(STATS__CABAC_BITS__SAO) ); |
---|
[313] | 1642 | } |
---|
[1029] | 1643 | |
---|
[313] | 1644 | Void TDecSbac::parseSaoMerge (UInt& ruiVal) |
---|
| 1645 | { |
---|
| 1646 | UInt uiCode; |
---|
[1029] | 1647 | m_pcTDecBinIf->decodeBin( uiCode, m_cSaoMergeSCModel.get( 0, 0, 0 ) RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(STATS__CABAC_BITS__SAO) ); |
---|
[313] | 1648 | ruiVal = (Int)uiCode; |
---|
| 1649 | } |
---|
[1029] | 1650 | |
---|
[313] | 1651 | Void TDecSbac::parseSaoTypeIdx (UInt& ruiVal) |
---|
| 1652 | { |
---|
| 1653 | UInt uiCode; |
---|
[1029] | 1654 | m_pcTDecBinIf->decodeBin( uiCode, m_cSaoTypeIdxSCModel.get( 0, 0, 0 ) RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(STATS__CABAC_BITS__SAO) ); |
---|
| 1655 | if (uiCode == 0) |
---|
[313] | 1656 | { |
---|
| 1657 | ruiVal = 0; |
---|
| 1658 | } |
---|
| 1659 | else |
---|
| 1660 | { |
---|
[1029] | 1661 | m_pcTDecBinIf->decodeBinEP( uiCode RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(STATS__CABAC_BITS__SAO) ); |
---|
[313] | 1662 | if (uiCode == 0) |
---|
| 1663 | { |
---|
[540] | 1664 | ruiVal = 1; |
---|
[313] | 1665 | } |
---|
| 1666 | else |
---|
| 1667 | { |
---|
[540] | 1668 | ruiVal = 2; |
---|
[313] | 1669 | } |
---|
| 1670 | } |
---|
| 1671 | } |
---|
| 1672 | |
---|
[540] | 1673 | Void TDecSbac::parseSaoSign(UInt& val) |
---|
| 1674 | { |
---|
[1029] | 1675 | m_pcTDecBinIf->decodeBinEP ( val RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(STATS__CABAC_BITS__SAO) ); |
---|
[540] | 1676 | } |
---|
| 1677 | |
---|
| 1678 | Void TDecSbac::parseSAOBlkParam (SAOBlkParam& saoBlkParam |
---|
[644] | 1679 | #if SVC_EXTENSION |
---|
| 1680 | , UInt* saoMaxOffsetQVal |
---|
| 1681 | #endif |
---|
[540] | 1682 | , Bool* sliceEnabled |
---|
| 1683 | , Bool leftMergeAvail |
---|
| 1684 | , Bool aboveMergeAvail |
---|
| 1685 | ) |
---|
| 1686 | { |
---|
| 1687 | UInt uiSymbol; |
---|
| 1688 | |
---|
| 1689 | Bool isLeftMerge = false; |
---|
| 1690 | Bool isAboveMerge= false; |
---|
| 1691 | |
---|
| 1692 | if(leftMergeAvail) |
---|
| 1693 | { |
---|
| 1694 | parseSaoMerge(uiSymbol); //sao_merge_left_flag |
---|
| 1695 | isLeftMerge = (uiSymbol?true:false); |
---|
| 1696 | } |
---|
| 1697 | |
---|
| 1698 | if( aboveMergeAvail && !isLeftMerge) |
---|
| 1699 | { |
---|
| 1700 | parseSaoMerge(uiSymbol); //sao_merge_up_flag |
---|
| 1701 | isAboveMerge = (uiSymbol?true:false); |
---|
| 1702 | } |
---|
| 1703 | |
---|
| 1704 | if(isLeftMerge || isAboveMerge) //merge mode |
---|
| 1705 | { |
---|
[1029] | 1706 | for (UInt componentIndex = 0; componentIndex < MAX_NUM_COMPONENT; componentIndex++) |
---|
| 1707 | { |
---|
| 1708 | saoBlkParam[componentIndex].modeIdc = (sliceEnabled[componentIndex]) ? SAO_MODE_MERGE : SAO_MODE_OFF; |
---|
| 1709 | saoBlkParam[componentIndex].typeIdc = (isLeftMerge)?SAO_MERGE_LEFT:SAO_MERGE_ABOVE; |
---|
| 1710 | } |
---|
[540] | 1711 | } |
---|
| 1712 | else //new or off mode |
---|
[1029] | 1713 | { |
---|
| 1714 | for(Int compId=COMPONENT_Y; compId < MAX_NUM_COMPONENT; compId++) |
---|
[540] | 1715 | { |
---|
[1029] | 1716 | const ComponentID compIdx=ComponentID(compId); |
---|
| 1717 | const ComponentID firstCompOfChType = getFirstComponentOfChannel(toChannelType(compIdx)); |
---|
[540] | 1718 | SAOOffset& ctbParam = saoBlkParam[compIdx]; |
---|
| 1719 | |
---|
| 1720 | if(!sliceEnabled[compIdx]) |
---|
| 1721 | { |
---|
| 1722 | //off |
---|
| 1723 | ctbParam.modeIdc = SAO_MODE_OFF; |
---|
| 1724 | continue; |
---|
| 1725 | } |
---|
| 1726 | |
---|
| 1727 | //type |
---|
[1029] | 1728 | if(compIdx == firstCompOfChType) |
---|
[540] | 1729 | { |
---|
| 1730 | parseSaoTypeIdx(uiSymbol); //sao_type_idx_luma or sao_type_idx_chroma |
---|
| 1731 | |
---|
| 1732 | assert(uiSymbol ==0 || uiSymbol ==1 || uiSymbol ==2); |
---|
| 1733 | |
---|
| 1734 | if(uiSymbol ==0) //OFF |
---|
| 1735 | { |
---|
| 1736 | ctbParam.modeIdc = SAO_MODE_OFF; |
---|
| 1737 | } |
---|
| 1738 | else if(uiSymbol == 1) //BO |
---|
| 1739 | { |
---|
| 1740 | ctbParam.modeIdc = SAO_MODE_NEW; |
---|
| 1741 | ctbParam.typeIdc = SAO_TYPE_START_BO; |
---|
| 1742 | } |
---|
| 1743 | else //2, EO |
---|
| 1744 | { |
---|
| 1745 | ctbParam.modeIdc = SAO_MODE_NEW; |
---|
| 1746 | ctbParam.typeIdc = SAO_TYPE_START_EO; |
---|
| 1747 | } |
---|
| 1748 | |
---|
| 1749 | } |
---|
| 1750 | else //Cr, follow Cb SAO type |
---|
| 1751 | { |
---|
[1029] | 1752 | ctbParam.modeIdc = saoBlkParam[COMPONENT_Cb].modeIdc; |
---|
| 1753 | ctbParam.typeIdc = saoBlkParam[COMPONENT_Cb].typeIdc; |
---|
[540] | 1754 | } |
---|
| 1755 | |
---|
| 1756 | if(ctbParam.modeIdc == SAO_MODE_NEW) |
---|
| 1757 | { |
---|
[1029] | 1758 | #if O0043_BEST_EFFORT_DECODING |
---|
| 1759 | Int bitDepthOrig = g_bitDepthInStream[toChannelType(compIdx)]; |
---|
| 1760 | Int forceBitDepthAdjust = bitDepthOrig - g_bitDepth[toChannelType(compIdx)]; |
---|
| 1761 | #endif |
---|
[540] | 1762 | Int offset[4]; |
---|
| 1763 | for(Int i=0; i< 4; i++) |
---|
| 1764 | { |
---|
[644] | 1765 | #if SVC_EXTENSION |
---|
| 1766 | parseSaoMaxUvlc(uiSymbol, saoMaxOffsetQVal[compIdx] ); //sao_offset_abs |
---|
| 1767 | #else |
---|
[1029] | 1768 | #if O0043_BEST_EFFORT_DECODING |
---|
| 1769 | Int saoMaxOffsetQVal = (1<<(min(bitDepthOrig, MAX_SAO_TRUNCATED_BITDEPTH)-5))-1; |
---|
| 1770 | parseSaoMaxUvlc(uiSymbol, saoMaxOffsetQVal); //sao_offset_abs |
---|
| 1771 | #else |
---|
[540] | 1772 | parseSaoMaxUvlc(uiSymbol, g_saoMaxOffsetQVal[compIdx] ); //sao_offset_abs |
---|
[644] | 1773 | #endif |
---|
[1029] | 1774 | #endif |
---|
[540] | 1775 | offset[i] = (Int)uiSymbol; |
---|
| 1776 | } |
---|
| 1777 | |
---|
| 1778 | if(ctbParam.typeIdc == SAO_TYPE_START_BO) |
---|
| 1779 | { |
---|
| 1780 | for(Int i=0; i< 4; i++) |
---|
| 1781 | { |
---|
| 1782 | if(offset[i] != 0) |
---|
| 1783 | { |
---|
| 1784 | parseSaoSign(uiSymbol); //sao_offset_sign |
---|
| 1785 | if(uiSymbol) |
---|
| 1786 | { |
---|
[1029] | 1787 | #if O0043_BEST_EFFORT_DECODING |
---|
| 1788 | offset[i] >>= forceBitDepthAdjust; |
---|
| 1789 | #endif |
---|
[540] | 1790 | offset[i] = -offset[i]; |
---|
| 1791 | } |
---|
| 1792 | } |
---|
| 1793 | } |
---|
| 1794 | parseSaoUflc(NUM_SAO_BO_CLASSES_LOG2, uiSymbol ); //sao_band_position |
---|
| 1795 | ctbParam.typeAuxInfo = uiSymbol; |
---|
[1029] | 1796 | |
---|
[540] | 1797 | for(Int i=0; i<4; i++) |
---|
| 1798 | { |
---|
| 1799 | ctbParam.offset[(ctbParam.typeAuxInfo+i)%MAX_NUM_SAO_CLASSES] = offset[i]; |
---|
[1029] | 1800 | } |
---|
| 1801 | |
---|
[540] | 1802 | } |
---|
| 1803 | else //EO |
---|
| 1804 | { |
---|
| 1805 | ctbParam.typeAuxInfo = 0; |
---|
| 1806 | |
---|
[1029] | 1807 | if(firstCompOfChType == compIdx) |
---|
[540] | 1808 | { |
---|
| 1809 | parseSaoUflc(NUM_SAO_EO_TYPES_LOG2, uiSymbol ); //sao_eo_class_luma or sao_eo_class_chroma |
---|
| 1810 | ctbParam.typeIdc += uiSymbol; |
---|
| 1811 | } |
---|
| 1812 | else |
---|
| 1813 | { |
---|
[1029] | 1814 | ctbParam.typeIdc = saoBlkParam[firstCompOfChType].typeIdc; |
---|
[540] | 1815 | } |
---|
| 1816 | ctbParam.offset[SAO_CLASS_EO_FULL_VALLEY] = offset[0]; |
---|
| 1817 | ctbParam.offset[SAO_CLASS_EO_HALF_VALLEY] = offset[1]; |
---|
| 1818 | ctbParam.offset[SAO_CLASS_EO_PLAIN ] = 0; |
---|
| 1819 | ctbParam.offset[SAO_CLASS_EO_HALF_PEAK ] = -offset[2]; |
---|
| 1820 | ctbParam.offset[SAO_CLASS_EO_FULL_PEAK ] = -offset[3]; |
---|
| 1821 | } |
---|
| 1822 | } |
---|
| 1823 | } |
---|
| 1824 | } |
---|
| 1825 | } |
---|
| 1826 | |
---|
[313] | 1827 | /** |
---|
| 1828 | - Initialize our contexts from the nominated source. |
---|
| 1829 | . |
---|
| 1830 | \param pSrc Contexts to be copied. |
---|
| 1831 | */ |
---|
[1029] | 1832 | Void TDecSbac::xCopyContextsFrom( const TDecSbac* pSrc ) |
---|
[313] | 1833 | { |
---|
| 1834 | memcpy(m_contextModels, pSrc->m_contextModels, m_numContextModels*sizeof(m_contextModels[0])); |
---|
[1029] | 1835 | memcpy(m_golombRiceAdaptationStatistics, pSrc->m_golombRiceAdaptationStatistics, (sizeof(UInt) * RExt__GOLOMB_RICE_ADAPTATION_STATISTICS_SETS)); |
---|
[313] | 1836 | } |
---|
| 1837 | |
---|
[1029] | 1838 | Void TDecSbac::xCopyFrom( const TDecSbac* pSrc ) |
---|
[313] | 1839 | { |
---|
| 1840 | m_pcTDecBinIf->copyState( pSrc->m_pcTDecBinIf ); |
---|
| 1841 | xCopyContextsFrom( pSrc ); |
---|
[1029] | 1842 | } |
---|
[313] | 1843 | |
---|
[1029] | 1844 | Void TDecSbac::load ( const TDecSbac* pSrc ) |
---|
| 1845 | { |
---|
| 1846 | xCopyFrom(pSrc); |
---|
[313] | 1847 | } |
---|
| 1848 | |
---|
[1029] | 1849 | Void TDecSbac::loadContexts ( const TDecSbac* pSrc ) |
---|
[313] | 1850 | { |
---|
[1029] | 1851 | xCopyContextsFrom(pSrc); |
---|
[313] | 1852 | } |
---|
| 1853 | |
---|
[1029] | 1854 | /** Performs CABAC decoding of the explicit RDPCM mode |
---|
| 1855 | * \param rTu current TU data structure |
---|
| 1856 | * \param compID component identifier |
---|
| 1857 | */ |
---|
| 1858 | Void TDecSbac::parseExplicitRdpcmMode( TComTU &rTu, ComponentID compID ) |
---|
[313] | 1859 | { |
---|
[1029] | 1860 | TComDataCU* cu = rTu.getCU(); |
---|
| 1861 | const UInt absPartIdx=rTu.GetAbsPartIdxTU(compID); |
---|
| 1862 | const TComRectangle &rect = rTu.getRect(compID); |
---|
| 1863 | const UInt tuHeight = g_aucConvertToBit[rect.height]; |
---|
| 1864 | const UInt tuWidth = g_aucConvertToBit[rect.width]; |
---|
| 1865 | UInt code = 0; |
---|
| 1866 | |
---|
| 1867 | assert(tuHeight == tuWidth); |
---|
| 1868 | |
---|
| 1869 | #if RExt__DECODER_DEBUG_BIT_STATISTICS |
---|
| 1870 | const TComCodingStatisticsClassType ctype(STATS__EXPLICIT_RDPCM_BITS, g_aucConvertToBit[g_uiMaxCUWidth>>rTu.GetTransformDepthTotal()]+2); |
---|
| 1871 | #endif |
---|
| 1872 | |
---|
| 1873 | m_pcTDecBinIf->decodeBin(code, m_explicitRdpcmFlagSCModel.get (0, toChannelType(compID), 0) RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(ctype)); |
---|
| 1874 | |
---|
| 1875 | if(code == 0) |
---|
| 1876 | { |
---|
| 1877 | cu->setExplicitRdpcmModePartRange( RDPCM_OFF, compID, absPartIdx, rTu.GetAbsPartIdxNumParts(compID)); |
---|
| 1878 | } |
---|
| 1879 | else |
---|
| 1880 | { |
---|
| 1881 | m_pcTDecBinIf->decodeBin(code, m_explicitRdpcmDirSCModel.get (0, toChannelType(compID), 0) RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(ctype)); |
---|
| 1882 | if(code == 0) |
---|
| 1883 | { |
---|
| 1884 | cu->setExplicitRdpcmModePartRange( RDPCM_HOR, compID, absPartIdx, rTu.GetAbsPartIdxNumParts(compID)); |
---|
| 1885 | } |
---|
| 1886 | else |
---|
| 1887 | { |
---|
| 1888 | cu->setExplicitRdpcmModePartRange( RDPCM_VER, compID, absPartIdx, rTu.GetAbsPartIdxNumParts(compID)); |
---|
| 1889 | } |
---|
| 1890 | } |
---|
[313] | 1891 | } |
---|
[1029] | 1892 | |
---|
| 1893 | |
---|
[313] | 1894 | //! \} |
---|