[51] | 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 |
---|
| 4 | * granted under this license. |
---|
| 5 | * |
---|
| 6 | * Copyright (c) 2010-2013, ITU/ISO/IEC |
---|
| 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" |
---|
| 39 | |
---|
| 40 | //! \ingroup TLibDecoder |
---|
| 41 | //! \{ |
---|
| 42 | |
---|
| 43 | ////////////////////////////////////////////////////////////////////// |
---|
| 44 | // Construction/Destruction |
---|
| 45 | ////////////////////////////////////////////////////////////////////// |
---|
| 46 | |
---|
| 47 | TDecSbac::TDecSbac() |
---|
| 48 | // new structure here |
---|
| 49 | : m_pcBitstream ( 0 ) |
---|
| 50 | , m_pcTDecBinIf ( NULL ) |
---|
| 51 | , m_numContextModels ( 0 ) |
---|
| 52 | , m_cCUSplitFlagSCModel ( 1, 1, NUM_SPLIT_FLAG_CTX , m_contextModels + m_numContextModels, m_numContextModels ) |
---|
| 53 | , m_cCUSkipFlagSCModel ( 1, 1, NUM_SKIP_FLAG_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
| 54 | , m_cCUMergeFlagExtSCModel ( 1, 1, NUM_MERGE_FLAG_EXT_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
| 55 | , m_cCUMergeIdxExtSCModel ( 1, 1, NUM_MERGE_IDX_EXT_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
| 56 | , m_cCUPartSizeSCModel ( 1, 1, NUM_PART_SIZE_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
| 57 | , m_cCUPredModeSCModel ( 1, 1, NUM_PRED_MODE_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
| 58 | , m_cCUIntraPredSCModel ( 1, 1, NUM_ADI_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
| 59 | , m_cCUChromaPredSCModel ( 1, 1, NUM_CHROMA_PRED_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
| 60 | , m_cCUDeltaQpSCModel ( 1, 1, NUM_DELTA_QP_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
| 61 | , m_cCUInterDirSCModel ( 1, 1, NUM_INTER_DIR_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
| 62 | , m_cCURefPicSCModel ( 1, 1, NUM_REF_NO_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
| 63 | , m_cCUMvdSCModel ( 1, 1, NUM_MV_RES_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
| 64 | , m_cCUQtCbfSCModel ( 1, 2, NUM_QT_CBF_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
| 65 | , m_cCUTransSubdivFlagSCModel ( 1, 1, NUM_TRANS_SUBDIV_FLAG_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
| 66 | , m_cCUQtRootCbfSCModel ( 1, 1, NUM_QT_ROOT_CBF_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
| 67 | , m_cCUSigCoeffGroupSCModel ( 1, 2, NUM_SIG_CG_FLAG_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
| 68 | , m_cCUSigSCModel ( 1, 1, NUM_SIG_FLAG_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
| 69 | , m_cCuCtxLastX ( 1, 2, NUM_CTX_LAST_FLAG_XY , m_contextModels + m_numContextModels, m_numContextModels) |
---|
| 70 | , m_cCuCtxLastY ( 1, 2, NUM_CTX_LAST_FLAG_XY , m_contextModels + m_numContextModels, m_numContextModels) |
---|
| 71 | , m_cCUOneSCModel ( 1, 1, NUM_ONE_FLAG_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
| 72 | , m_cCUAbsSCModel ( 1, 1, NUM_ABS_FLAG_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
| 73 | , m_cMVPIdxSCModel ( 1, 1, NUM_MVP_IDX_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
| 74 | , m_cCUAMPSCModel ( 1, 1, NUM_CU_AMP_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
| 75 | , m_cSaoMergeSCModel ( 1, 1, NUM_SAO_MERGE_FLAG_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
| 76 | , m_cSaoTypeIdxSCModel ( 1, 1, NUM_SAO_TYPE_IDX_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
| 77 | , m_cTransformSkipSCModel ( 1, 2, NUM_TRANSFORMSKIP_FLAG_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
| 78 | , m_CUTransquantBypassFlagSCModel( 1, 1, NUM_CU_TRANSQUANT_BYPASS_FLAG_CTX, m_contextModels + m_numContextModels, m_numContextModels) |
---|
[54] | 79 | #if INTRA_BL |
---|
| 80 | , m_cIntraBLPredFlagSCModel (1, 1, NUM_INTRA_BL_PRED_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
| 81 | #endif |
---|
[51] | 82 | { |
---|
| 83 | assert( m_numContextModels <= MAX_NUM_CTX_MOD ); |
---|
| 84 | } |
---|
| 85 | |
---|
| 86 | TDecSbac::~TDecSbac() |
---|
| 87 | { |
---|
| 88 | } |
---|
| 89 | |
---|
| 90 | // ==================================================================================================================== |
---|
| 91 | // Public member functions |
---|
| 92 | // ==================================================================================================================== |
---|
| 93 | |
---|
| 94 | Void TDecSbac::resetEntropy(TComSlice* pSlice) |
---|
| 95 | { |
---|
| 96 | SliceType sliceType = pSlice->getSliceType(); |
---|
| 97 | Int qp = pSlice->getSliceQp(); |
---|
| 98 | |
---|
| 99 | if (pSlice->getPPS()->getCabacInitPresentFlag() && pSlice->getCabacInitFlag()) |
---|
| 100 | { |
---|
| 101 | switch (sliceType) |
---|
| 102 | { |
---|
| 103 | case P_SLICE: // change initialization table to B_SLICE initialization |
---|
| 104 | sliceType = B_SLICE; |
---|
| 105 | break; |
---|
| 106 | case B_SLICE: // change initialization table to P_SLICE initialization |
---|
| 107 | sliceType = P_SLICE; |
---|
| 108 | break; |
---|
| 109 | default : // should not occur |
---|
| 110 | assert(0); |
---|
| 111 | } |
---|
| 112 | } |
---|
| 113 | |
---|
| 114 | m_cCUSplitFlagSCModel.initBuffer ( sliceType, qp, (UChar*)INIT_SPLIT_FLAG ); |
---|
| 115 | m_cCUSkipFlagSCModel.initBuffer ( sliceType, qp, (UChar*)INIT_SKIP_FLAG ); |
---|
| 116 | m_cCUMergeFlagExtSCModel.initBuffer ( sliceType, qp, (UChar*)INIT_MERGE_FLAG_EXT ); |
---|
| 117 | m_cCUMergeIdxExtSCModel.initBuffer ( sliceType, qp, (UChar*)INIT_MERGE_IDX_EXT ); |
---|
| 118 | m_cCUPartSizeSCModel.initBuffer ( sliceType, qp, (UChar*)INIT_PART_SIZE ); |
---|
| 119 | m_cCUAMPSCModel.initBuffer ( sliceType, qp, (UChar*)INIT_CU_AMP_POS ); |
---|
| 120 | m_cCUPredModeSCModel.initBuffer ( sliceType, qp, (UChar*)INIT_PRED_MODE ); |
---|
| 121 | m_cCUIntraPredSCModel.initBuffer ( sliceType, qp, (UChar*)INIT_INTRA_PRED_MODE ); |
---|
| 122 | m_cCUChromaPredSCModel.initBuffer ( sliceType, qp, (UChar*)INIT_CHROMA_PRED_MODE ); |
---|
| 123 | m_cCUInterDirSCModel.initBuffer ( sliceType, qp, (UChar*)INIT_INTER_DIR ); |
---|
| 124 | m_cCUMvdSCModel.initBuffer ( sliceType, qp, (UChar*)INIT_MVD ); |
---|
| 125 | m_cCURefPicSCModel.initBuffer ( sliceType, qp, (UChar*)INIT_REF_PIC ); |
---|
| 126 | m_cCUDeltaQpSCModel.initBuffer ( sliceType, qp, (UChar*)INIT_DQP ); |
---|
| 127 | m_cCUQtCbfSCModel.initBuffer ( sliceType, qp, (UChar*)INIT_QT_CBF ); |
---|
| 128 | m_cCUQtRootCbfSCModel.initBuffer ( sliceType, qp, (UChar*)INIT_QT_ROOT_CBF ); |
---|
| 129 | m_cCUSigCoeffGroupSCModel.initBuffer ( sliceType, qp, (UChar*)INIT_SIG_CG_FLAG ); |
---|
| 130 | m_cCUSigSCModel.initBuffer ( sliceType, qp, (UChar*)INIT_SIG_FLAG ); |
---|
| 131 | m_cCuCtxLastX.initBuffer ( sliceType, qp, (UChar*)INIT_LAST ); |
---|
| 132 | m_cCuCtxLastY.initBuffer ( sliceType, qp, (UChar*)INIT_LAST ); |
---|
| 133 | m_cCUOneSCModel.initBuffer ( sliceType, qp, (UChar*)INIT_ONE_FLAG ); |
---|
| 134 | m_cCUAbsSCModel.initBuffer ( sliceType, qp, (UChar*)INIT_ABS_FLAG ); |
---|
| 135 | m_cMVPIdxSCModel.initBuffer ( sliceType, qp, (UChar*)INIT_MVP_IDX ); |
---|
| 136 | m_cSaoMergeSCModel.initBuffer ( sliceType, qp, (UChar*)INIT_SAO_MERGE_FLAG ); |
---|
| 137 | m_cSaoTypeIdxSCModel.initBuffer ( sliceType, qp, (UChar*)INIT_SAO_TYPE_IDX ); |
---|
| 138 | |
---|
| 139 | m_cCUTransSubdivFlagSCModel.initBuffer ( sliceType, qp, (UChar*)INIT_TRANS_SUBDIV_FLAG ); |
---|
[54] | 140 | #if INTRA_BL |
---|
| 141 | m_cIntraBLPredFlagSCModel.initBuffer ( sliceType, qp, (UChar*)INIT_INTRA_BL_PRED_FLAG ); |
---|
| 142 | #endif |
---|
[51] | 143 | m_cTransformSkipSCModel.initBuffer ( sliceType, qp, (UChar*)INIT_TRANSFORMSKIP_FLAG ); |
---|
| 144 | m_CUTransquantBypassFlagSCModel.initBuffer( sliceType, qp, (UChar*)INIT_CU_TRANSQUANT_BYPASS_FLAG ); |
---|
| 145 | m_uiLastDQpNonZero = 0; |
---|
| 146 | |
---|
| 147 | // new structure |
---|
| 148 | m_uiLastQp = qp; |
---|
| 149 | |
---|
| 150 | m_pcTDecBinIf->start(); |
---|
| 151 | } |
---|
| 152 | |
---|
| 153 | /** The function does the following: Read out terminate bit. Flush CABAC. Byte-align for next tile. |
---|
| 154 | * Intialize CABAC states. Start CABAC. |
---|
| 155 | */ |
---|
| 156 | Void TDecSbac::updateContextTables( SliceType eSliceType, Int iQp ) |
---|
| 157 | { |
---|
| 158 | UInt uiBit; |
---|
| 159 | m_pcTDecBinIf->decodeBinTrm(uiBit); |
---|
| 160 | m_pcTDecBinIf->finish(); |
---|
| 161 | m_pcBitstream->readOutTrailingBits(); |
---|
| 162 | m_cCUSplitFlagSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_SPLIT_FLAG ); |
---|
| 163 | m_cCUSkipFlagSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_SKIP_FLAG ); |
---|
| 164 | m_cCUMergeFlagExtSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_MERGE_FLAG_EXT ); |
---|
| 165 | m_cCUMergeIdxExtSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_MERGE_IDX_EXT ); |
---|
| 166 | m_cCUPartSizeSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_PART_SIZE ); |
---|
| 167 | m_cCUAMPSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_CU_AMP_POS ); |
---|
| 168 | m_cCUPredModeSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_PRED_MODE ); |
---|
| 169 | m_cCUIntraPredSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_INTRA_PRED_MODE ); |
---|
| 170 | m_cCUChromaPredSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_CHROMA_PRED_MODE ); |
---|
| 171 | m_cCUInterDirSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_INTER_DIR ); |
---|
| 172 | m_cCUMvdSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_MVD ); |
---|
| 173 | m_cCURefPicSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_REF_PIC ); |
---|
| 174 | m_cCUDeltaQpSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_DQP ); |
---|
| 175 | m_cCUQtCbfSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_QT_CBF ); |
---|
| 176 | m_cCUQtRootCbfSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_QT_ROOT_CBF ); |
---|
| 177 | m_cCUSigCoeffGroupSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_SIG_CG_FLAG ); |
---|
| 178 | m_cCUSigSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_SIG_FLAG ); |
---|
| 179 | m_cCuCtxLastX.initBuffer ( eSliceType, iQp, (UChar*)INIT_LAST ); |
---|
| 180 | m_cCuCtxLastY.initBuffer ( eSliceType, iQp, (UChar*)INIT_LAST ); |
---|
| 181 | m_cCUOneSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_ONE_FLAG ); |
---|
| 182 | m_cCUAbsSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_ABS_FLAG ); |
---|
| 183 | m_cMVPIdxSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_MVP_IDX ); |
---|
| 184 | m_cSaoMergeSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_SAO_MERGE_FLAG ); |
---|
| 185 | m_cSaoTypeIdxSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_SAO_TYPE_IDX ); |
---|
| 186 | m_cCUTransSubdivFlagSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_TRANS_SUBDIV_FLAG ); |
---|
[54] | 187 | #if INTRA_BL |
---|
| 188 | m_cIntraBLPredFlagSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_INTRA_BL_PRED_FLAG ); |
---|
| 189 | #endif |
---|
[51] | 190 | m_cTransformSkipSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_TRANSFORMSKIP_FLAG ); |
---|
| 191 | m_CUTransquantBypassFlagSCModel.initBuffer( eSliceType, iQp, (UChar*)INIT_CU_TRANSQUANT_BYPASS_FLAG ); |
---|
| 192 | m_pcTDecBinIf->start(); |
---|
| 193 | } |
---|
| 194 | |
---|
| 195 | Void TDecSbac::parseTerminatingBit( UInt& ruiBit ) |
---|
| 196 | { |
---|
| 197 | m_pcTDecBinIf->decodeBinTrm( ruiBit ); |
---|
| 198 | } |
---|
| 199 | |
---|
| 200 | |
---|
| 201 | Void TDecSbac::xReadUnaryMaxSymbol( UInt& ruiSymbol, ContextModel* pcSCModel, Int iOffset, UInt uiMaxSymbol ) |
---|
| 202 | { |
---|
| 203 | if (uiMaxSymbol == 0) |
---|
| 204 | { |
---|
| 205 | ruiSymbol = 0; |
---|
| 206 | return; |
---|
| 207 | } |
---|
| 208 | |
---|
| 209 | m_pcTDecBinIf->decodeBin( ruiSymbol, pcSCModel[0] ); |
---|
| 210 | |
---|
| 211 | if( ruiSymbol == 0 || uiMaxSymbol == 1 ) |
---|
| 212 | { |
---|
| 213 | return; |
---|
| 214 | } |
---|
| 215 | |
---|
| 216 | UInt uiSymbol = 0; |
---|
| 217 | UInt uiCont; |
---|
| 218 | |
---|
| 219 | do |
---|
| 220 | { |
---|
| 221 | m_pcTDecBinIf->decodeBin( uiCont, pcSCModel[ iOffset ] ); |
---|
| 222 | uiSymbol++; |
---|
| 223 | } |
---|
| 224 | while( uiCont && ( uiSymbol < uiMaxSymbol - 1 ) ); |
---|
| 225 | |
---|
| 226 | if( uiCont && ( uiSymbol == uiMaxSymbol - 1 ) ) |
---|
| 227 | { |
---|
| 228 | uiSymbol++; |
---|
| 229 | } |
---|
| 230 | |
---|
| 231 | ruiSymbol = uiSymbol; |
---|
| 232 | } |
---|
| 233 | |
---|
| 234 | Void TDecSbac::xReadEpExGolomb( UInt& ruiSymbol, UInt uiCount ) |
---|
| 235 | { |
---|
| 236 | UInt uiSymbol = 0; |
---|
| 237 | UInt uiBit = 1; |
---|
| 238 | |
---|
| 239 | while( uiBit ) |
---|
| 240 | { |
---|
| 241 | m_pcTDecBinIf->decodeBinEP( uiBit ); |
---|
| 242 | uiSymbol += uiBit << uiCount++; |
---|
| 243 | } |
---|
| 244 | |
---|
| 245 | if ( --uiCount ) |
---|
| 246 | { |
---|
| 247 | UInt bins; |
---|
| 248 | m_pcTDecBinIf->decodeBinsEP( bins, uiCount ); |
---|
| 249 | uiSymbol += bins; |
---|
| 250 | } |
---|
| 251 | |
---|
| 252 | ruiSymbol = uiSymbol; |
---|
| 253 | } |
---|
| 254 | |
---|
| 255 | Void TDecSbac::xReadUnarySymbol( UInt& ruiSymbol, ContextModel* pcSCModel, Int iOffset ) |
---|
| 256 | { |
---|
| 257 | m_pcTDecBinIf->decodeBin( ruiSymbol, pcSCModel[0] ); |
---|
| 258 | |
---|
| 259 | if( !ruiSymbol ) |
---|
| 260 | { |
---|
| 261 | return; |
---|
| 262 | } |
---|
| 263 | |
---|
| 264 | UInt uiSymbol = 0; |
---|
| 265 | UInt uiCont; |
---|
| 266 | |
---|
| 267 | do |
---|
| 268 | { |
---|
| 269 | m_pcTDecBinIf->decodeBin( uiCont, pcSCModel[ iOffset ] ); |
---|
| 270 | uiSymbol++; |
---|
| 271 | } |
---|
| 272 | while( uiCont ); |
---|
| 273 | |
---|
| 274 | ruiSymbol = uiSymbol; |
---|
| 275 | } |
---|
| 276 | |
---|
| 277 | |
---|
| 278 | /** Parsing of coeff_abs_level_remaing |
---|
| 279 | * \param ruiSymbol reference to coeff_abs_level_remaing |
---|
| 280 | * \param ruiParam reference to parameter |
---|
| 281 | * \returns Void |
---|
| 282 | */ |
---|
| 283 | Void TDecSbac::xReadCoefRemainExGolomb ( UInt &rSymbol, UInt &rParam ) |
---|
| 284 | { |
---|
| 285 | |
---|
| 286 | UInt prefix = 0; |
---|
| 287 | UInt codeWord = 0; |
---|
| 288 | do |
---|
| 289 | { |
---|
| 290 | prefix++; |
---|
| 291 | m_pcTDecBinIf->decodeBinEP( codeWord ); |
---|
| 292 | } |
---|
| 293 | while( codeWord); |
---|
| 294 | codeWord = 1 - codeWord; |
---|
| 295 | prefix -= codeWord; |
---|
| 296 | codeWord=0; |
---|
| 297 | if (prefix < COEF_REMAIN_BIN_REDUCTION ) |
---|
| 298 | { |
---|
| 299 | m_pcTDecBinIf->decodeBinsEP(codeWord,rParam); |
---|
| 300 | rSymbol = (prefix<<rParam) + codeWord; |
---|
| 301 | } |
---|
| 302 | else |
---|
| 303 | { |
---|
| 304 | m_pcTDecBinIf->decodeBinsEP(codeWord,prefix-COEF_REMAIN_BIN_REDUCTION+rParam); |
---|
| 305 | rSymbol = (((1<<(prefix-COEF_REMAIN_BIN_REDUCTION))+COEF_REMAIN_BIN_REDUCTION-1)<<rParam)+codeWord; |
---|
| 306 | } |
---|
| 307 | } |
---|
| 308 | |
---|
| 309 | /** Parse I_PCM information. |
---|
| 310 | * \param pcCU |
---|
| 311 | * \param uiAbsPartIdx |
---|
| 312 | * \param uiDepth |
---|
| 313 | * \returns Void |
---|
| 314 | * |
---|
| 315 | * If I_PCM flag indicates that the CU is I_PCM, parse its PCM alignment bits and codes. |
---|
| 316 | */ |
---|
| 317 | Void TDecSbac::parseIPCMInfo ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth ) |
---|
| 318 | { |
---|
| 319 | UInt uiSymbol; |
---|
| 320 | Bool readPCMSampleFlag = false; |
---|
| 321 | |
---|
| 322 | m_pcTDecBinIf->decodeBinTrm(uiSymbol); |
---|
| 323 | |
---|
| 324 | if (uiSymbol) |
---|
| 325 | { |
---|
| 326 | readPCMSampleFlag = true; |
---|
| 327 | m_pcTDecBinIf->decodePCMAlignBits(); |
---|
| 328 | } |
---|
| 329 | |
---|
| 330 | if (readPCMSampleFlag == true) |
---|
| 331 | { |
---|
| 332 | Bool bIpcmFlag = true; |
---|
| 333 | |
---|
| 334 | pcCU->setPartSizeSubParts ( SIZE_2Nx2N, uiAbsPartIdx, uiDepth ); |
---|
| 335 | pcCU->setSizeSubParts ( g_uiMaxCUWidth>>uiDepth, g_uiMaxCUHeight>>uiDepth, uiAbsPartIdx, uiDepth ); |
---|
| 336 | pcCU->setTrIdxSubParts ( 0, uiAbsPartIdx, uiDepth ); |
---|
| 337 | pcCU->setIPCMFlagSubParts ( bIpcmFlag, uiAbsPartIdx, uiDepth ); |
---|
| 338 | |
---|
| 339 | UInt uiMinCoeffSize = pcCU->getPic()->getMinCUWidth()*pcCU->getPic()->getMinCUHeight(); |
---|
| 340 | UInt uiLumaOffset = uiMinCoeffSize*uiAbsPartIdx; |
---|
| 341 | UInt uiChromaOffset = uiLumaOffset>>2; |
---|
| 342 | |
---|
| 343 | Pel* piPCMSample; |
---|
| 344 | UInt uiWidth; |
---|
| 345 | UInt uiHeight; |
---|
| 346 | UInt uiSampleBits; |
---|
| 347 | UInt uiX, uiY; |
---|
| 348 | |
---|
| 349 | piPCMSample = pcCU->getPCMSampleY() + uiLumaOffset; |
---|
| 350 | uiWidth = pcCU->getWidth(uiAbsPartIdx); |
---|
| 351 | uiHeight = pcCU->getHeight(uiAbsPartIdx); |
---|
| 352 | uiSampleBits = pcCU->getSlice()->getSPS()->getPCMBitDepthLuma(); |
---|
| 353 | |
---|
| 354 | for(uiY = 0; uiY < uiHeight; uiY++) |
---|
| 355 | { |
---|
| 356 | for(uiX = 0; uiX < uiWidth; uiX++) |
---|
| 357 | { |
---|
| 358 | UInt uiSample; |
---|
| 359 | m_pcTDecBinIf->xReadPCMCode(uiSampleBits, uiSample); |
---|
| 360 | piPCMSample[uiX] = uiSample; |
---|
| 361 | } |
---|
| 362 | piPCMSample += uiWidth; |
---|
| 363 | } |
---|
| 364 | |
---|
| 365 | piPCMSample = pcCU->getPCMSampleCb() + uiChromaOffset; |
---|
| 366 | uiWidth = pcCU->getWidth(uiAbsPartIdx)/2; |
---|
| 367 | uiHeight = pcCU->getHeight(uiAbsPartIdx)/2; |
---|
| 368 | uiSampleBits = pcCU->getSlice()->getSPS()->getPCMBitDepthChroma(); |
---|
| 369 | |
---|
| 370 | for(uiY = 0; uiY < uiHeight; uiY++) |
---|
| 371 | { |
---|
| 372 | for(uiX = 0; uiX < uiWidth; uiX++) |
---|
| 373 | { |
---|
| 374 | UInt uiSample; |
---|
| 375 | m_pcTDecBinIf->xReadPCMCode(uiSampleBits, uiSample); |
---|
| 376 | piPCMSample[uiX] = uiSample; |
---|
| 377 | } |
---|
| 378 | piPCMSample += uiWidth; |
---|
| 379 | } |
---|
| 380 | |
---|
| 381 | piPCMSample = pcCU->getPCMSampleCr() + uiChromaOffset; |
---|
| 382 | uiWidth = pcCU->getWidth(uiAbsPartIdx)/2; |
---|
| 383 | uiHeight = pcCU->getHeight(uiAbsPartIdx)/2; |
---|
| 384 | uiSampleBits = pcCU->getSlice()->getSPS()->getPCMBitDepthChroma(); |
---|
| 385 | |
---|
| 386 | for(uiY = 0; uiY < uiHeight; uiY++) |
---|
| 387 | { |
---|
| 388 | for(uiX = 0; uiX < uiWidth; uiX++) |
---|
| 389 | { |
---|
| 390 | UInt uiSample; |
---|
| 391 | m_pcTDecBinIf->xReadPCMCode(uiSampleBits, uiSample); |
---|
| 392 | piPCMSample[uiX] = uiSample; |
---|
| 393 | } |
---|
| 394 | piPCMSample += uiWidth; |
---|
| 395 | } |
---|
| 396 | |
---|
| 397 | m_pcTDecBinIf->resetBac(); |
---|
| 398 | } |
---|
| 399 | } |
---|
| 400 | |
---|
| 401 | Void TDecSbac::parseCUTransquantBypassFlag( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth ) |
---|
| 402 | { |
---|
| 403 | UInt uiSymbol; |
---|
| 404 | m_pcTDecBinIf->decodeBin( uiSymbol, m_CUTransquantBypassFlagSCModel.get( 0, 0, 0 ) ); |
---|
| 405 | pcCU->setCUTransquantBypassSubParts(uiSymbol ? true : false, uiAbsPartIdx, uiDepth); |
---|
| 406 | } |
---|
| 407 | |
---|
| 408 | /** parse skip flag |
---|
| 409 | * \param pcCU |
---|
| 410 | * \param uiAbsPartIdx |
---|
| 411 | * \param uiDepth |
---|
| 412 | * \returns Void |
---|
| 413 | */ |
---|
| 414 | Void TDecSbac::parseSkipFlag( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth ) |
---|
| 415 | { |
---|
| 416 | if( pcCU->getSlice()->isIntra() ) |
---|
| 417 | { |
---|
| 418 | return; |
---|
| 419 | } |
---|
| 420 | |
---|
| 421 | UInt uiSymbol = 0; |
---|
| 422 | UInt uiCtxSkip = pcCU->getCtxSkipFlag( uiAbsPartIdx ); |
---|
| 423 | m_pcTDecBinIf->decodeBin( uiSymbol, m_cCUSkipFlagSCModel.get( 0, 0, uiCtxSkip ) ); |
---|
| 424 | DTRACE_CABAC_VL( g_nSymbolCounter++ ); |
---|
| 425 | DTRACE_CABAC_T( "\tSkipFlag" ); |
---|
| 426 | DTRACE_CABAC_T( "\tuiCtxSkip: "); |
---|
| 427 | DTRACE_CABAC_V( uiCtxSkip ); |
---|
| 428 | DTRACE_CABAC_T( "\tuiSymbol: "); |
---|
| 429 | DTRACE_CABAC_V( uiSymbol ); |
---|
| 430 | DTRACE_CABAC_T( "\n"); |
---|
| 431 | |
---|
| 432 | if( uiSymbol ) |
---|
| 433 | { |
---|
| 434 | pcCU->setSkipFlagSubParts( true, uiAbsPartIdx, uiDepth ); |
---|
| 435 | pcCU->setPredModeSubParts( MODE_INTER, uiAbsPartIdx, uiDepth ); |
---|
| 436 | pcCU->setPartSizeSubParts( SIZE_2Nx2N, uiAbsPartIdx, uiDepth ); |
---|
| 437 | pcCU->setSizeSubParts( g_uiMaxCUWidth>>uiDepth, g_uiMaxCUHeight>>uiDepth, uiAbsPartIdx, uiDepth ); |
---|
| 438 | pcCU->setMergeFlagSubParts( true , uiAbsPartIdx, 0, uiDepth ); |
---|
| 439 | } |
---|
| 440 | } |
---|
| 441 | |
---|
[54] | 442 | #if INTRA_BL |
---|
| 443 | Void TDecSbac::parseIntraBLFlag( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiPartIdx, UInt uiDepth ) |
---|
| 444 | { |
---|
| 445 | if( pcCU->getLayerId() == 0 ) |
---|
| 446 | { |
---|
| 447 | return; |
---|
| 448 | } |
---|
| 449 | |
---|
| 450 | UInt uiSymbol = 0; |
---|
| 451 | |
---|
| 452 | UInt uiCtxIntraBL = pcCU->getCtxIntraBLFlag( uiAbsPartIdx ) ; |
---|
| 453 | m_pcTDecBinIf->decodeBin( uiSymbol, m_cIntraBLPredFlagSCModel.get( 0, 0, uiCtxIntraBL )); |
---|
| 454 | DTRACE_CABAC_VL( g_nSymbolCounter++ ); |
---|
| 455 | DTRACE_CABAC_T( "\tIntrBLFlag" ); |
---|
| 456 | DTRACE_CABAC_T( "\tuiSymbol: "); |
---|
| 457 | DTRACE_CABAC_V( uiSymbol ); |
---|
| 458 | DTRACE_CABAC_T( "\n"); |
---|
| 459 | |
---|
| 460 | if ( uiSymbol ) |
---|
| 461 | { |
---|
| 462 | pcCU->setPartSizeSubParts( SIZE_2Nx2N, uiAbsPartIdx, uiDepth ); |
---|
| 463 | pcCU->setPredModeSubParts( MODE_INTRA_BL, uiAbsPartIdx, uiDepth ); |
---|
| 464 | pcCU->setTrIdxSubParts( 0, uiAbsPartIdx, uiDepth ); |
---|
| 465 | pcCU->setLumaIntraDirSubParts ( DC_IDX, uiAbsPartIdx, uiDepth ); |
---|
| 466 | } |
---|
| 467 | } |
---|
| 468 | #endif |
---|
| 469 | |
---|
[51] | 470 | /** parse merge flag |
---|
| 471 | * \param pcCU |
---|
| 472 | * \param uiAbsPartIdx |
---|
| 473 | * \param uiDepth |
---|
| 474 | * \param uiPUIdx |
---|
| 475 | * \returns Void |
---|
| 476 | */ |
---|
| 477 | Void TDecSbac::parseMergeFlag ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, UInt uiPUIdx ) |
---|
| 478 | { |
---|
| 479 | UInt uiSymbol; |
---|
| 480 | m_pcTDecBinIf->decodeBin( uiSymbol, *m_cCUMergeFlagExtSCModel.get( 0 ) ); |
---|
| 481 | pcCU->setMergeFlagSubParts( uiSymbol ? true : false, uiAbsPartIdx, uiPUIdx, uiDepth ); |
---|
| 482 | |
---|
| 483 | DTRACE_CABAC_VL( g_nSymbolCounter++ ); |
---|
| 484 | DTRACE_CABAC_T( "\tMergeFlag: " ); |
---|
| 485 | DTRACE_CABAC_V( uiSymbol ); |
---|
| 486 | DTRACE_CABAC_T( "\tAddress: " ); |
---|
| 487 | DTRACE_CABAC_V( pcCU->getAddr() ); |
---|
| 488 | DTRACE_CABAC_T( "\tuiAbsPartIdx: " ); |
---|
| 489 | DTRACE_CABAC_V( uiAbsPartIdx ); |
---|
| 490 | DTRACE_CABAC_T( "\n" ); |
---|
| 491 | } |
---|
| 492 | |
---|
| 493 | Void TDecSbac::parseMergeIndex ( TComDataCU* pcCU, UInt& ruiMergeIndex ) |
---|
| 494 | { |
---|
| 495 | UInt uiUnaryIdx = 0; |
---|
| 496 | UInt uiNumCand = pcCU->getSlice()->getMaxNumMergeCand(); |
---|
| 497 | if ( uiNumCand > 1 ) |
---|
| 498 | { |
---|
| 499 | for( ; uiUnaryIdx < uiNumCand - 1; ++uiUnaryIdx ) |
---|
| 500 | { |
---|
| 501 | UInt uiSymbol = 0; |
---|
| 502 | if ( uiUnaryIdx==0 ) |
---|
| 503 | { |
---|
| 504 | m_pcTDecBinIf->decodeBin( uiSymbol, m_cCUMergeIdxExtSCModel.get( 0, 0, 0 ) ); |
---|
| 505 | } |
---|
| 506 | else |
---|
| 507 | { |
---|
| 508 | m_pcTDecBinIf->decodeBinEP( uiSymbol ); |
---|
| 509 | } |
---|
| 510 | if( uiSymbol == 0 ) |
---|
| 511 | { |
---|
| 512 | break; |
---|
| 513 | } |
---|
| 514 | } |
---|
| 515 | } |
---|
| 516 | ruiMergeIndex = uiUnaryIdx; |
---|
| 517 | |
---|
| 518 | DTRACE_CABAC_VL( g_nSymbolCounter++ ) |
---|
| 519 | DTRACE_CABAC_T( "\tparseMergeIndex()" ) |
---|
| 520 | DTRACE_CABAC_T( "\tuiMRGIdx= " ) |
---|
| 521 | DTRACE_CABAC_V( ruiMergeIndex ) |
---|
| 522 | DTRACE_CABAC_T( "\n" ) |
---|
| 523 | } |
---|
| 524 | |
---|
| 525 | Void TDecSbac::parseMVPIdx ( Int& riMVPIdx ) |
---|
| 526 | { |
---|
| 527 | UInt uiSymbol; |
---|
| 528 | xReadUnaryMaxSymbol(uiSymbol, m_cMVPIdxSCModel.get(0), 1, AMVP_MAX_NUM_CANDS-1); |
---|
| 529 | riMVPIdx = uiSymbol; |
---|
| 530 | } |
---|
| 531 | |
---|
| 532 | Void TDecSbac::parseSplitFlag ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth ) |
---|
| 533 | { |
---|
| 534 | if( uiDepth == g_uiMaxCUDepth - g_uiAddCUDepth ) |
---|
| 535 | { |
---|
| 536 | pcCU->setDepthSubParts( uiDepth, uiAbsPartIdx ); |
---|
| 537 | return; |
---|
| 538 | } |
---|
| 539 | |
---|
| 540 | UInt uiSymbol; |
---|
| 541 | m_pcTDecBinIf->decodeBin( uiSymbol, m_cCUSplitFlagSCModel.get( 0, 0, pcCU->getCtxSplitFlag( uiAbsPartIdx, uiDepth ) ) ); |
---|
| 542 | DTRACE_CABAC_VL( g_nSymbolCounter++ ) |
---|
| 543 | DTRACE_CABAC_T( "\tSplitFlag\n" ) |
---|
| 544 | pcCU->setDepthSubParts( uiDepth + uiSymbol, uiAbsPartIdx ); |
---|
| 545 | |
---|
| 546 | return; |
---|
| 547 | } |
---|
| 548 | |
---|
| 549 | /** parse partition size |
---|
| 550 | * \param pcCU |
---|
| 551 | * \param uiAbsPartIdx |
---|
| 552 | * \param uiDepth |
---|
| 553 | * \returns Void |
---|
| 554 | */ |
---|
| 555 | Void TDecSbac::parsePartSize( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth ) |
---|
| 556 | { |
---|
| 557 | UInt uiSymbol, uiMode = 0; |
---|
| 558 | PartSize eMode; |
---|
| 559 | |
---|
[54] | 560 | #if INTRA_BL |
---|
| 561 | if ( pcCU->isIntraBL( uiAbsPartIdx ) ) |
---|
| 562 | { |
---|
| 563 | assert( 0 ); |
---|
| 564 | } |
---|
| 565 | #endif |
---|
[51] | 566 | if ( pcCU->isIntra( uiAbsPartIdx ) ) |
---|
| 567 | { |
---|
| 568 | uiSymbol = 1; |
---|
| 569 | if( uiDepth == g_uiMaxCUDepth - g_uiAddCUDepth ) |
---|
| 570 | { |
---|
| 571 | m_pcTDecBinIf->decodeBin( uiSymbol, m_cCUPartSizeSCModel.get( 0, 0, 0) ); |
---|
| 572 | } |
---|
| 573 | eMode = uiSymbol ? SIZE_2Nx2N : SIZE_NxN; |
---|
| 574 | UInt uiTrLevel = 0; |
---|
| 575 | UInt uiWidthInBit = g_aucConvertToBit[pcCU->getWidth(uiAbsPartIdx)]+2; |
---|
| 576 | UInt uiTrSizeInBit = g_aucConvertToBit[pcCU->getSlice()->getSPS()->getMaxTrSize()]+2; |
---|
| 577 | uiTrLevel = uiWidthInBit >= uiTrSizeInBit ? uiWidthInBit - uiTrSizeInBit : 0; |
---|
| 578 | if( eMode == SIZE_NxN ) |
---|
| 579 | { |
---|
| 580 | pcCU->setTrIdxSubParts( 1+uiTrLevel, uiAbsPartIdx, uiDepth ); |
---|
| 581 | } |
---|
| 582 | else |
---|
| 583 | { |
---|
| 584 | pcCU->setTrIdxSubParts( uiTrLevel, uiAbsPartIdx, uiDepth ); |
---|
| 585 | } |
---|
| 586 | } |
---|
| 587 | else |
---|
| 588 | { |
---|
| 589 | UInt uiMaxNumBits = 2; |
---|
| 590 | if( uiDepth == g_uiMaxCUDepth - g_uiAddCUDepth && !( (g_uiMaxCUWidth>>uiDepth) == 8 && (g_uiMaxCUHeight>>uiDepth) == 8 ) ) |
---|
| 591 | { |
---|
| 592 | uiMaxNumBits ++; |
---|
| 593 | } |
---|
| 594 | for ( UInt ui = 0; ui < uiMaxNumBits; ui++ ) |
---|
| 595 | { |
---|
| 596 | m_pcTDecBinIf->decodeBin( uiSymbol, m_cCUPartSizeSCModel.get( 0, 0, ui) ); |
---|
| 597 | if ( uiSymbol ) |
---|
| 598 | { |
---|
| 599 | break; |
---|
| 600 | } |
---|
| 601 | uiMode++; |
---|
| 602 | } |
---|
| 603 | eMode = (PartSize) uiMode; |
---|
| 604 | if ( pcCU->getSlice()->getSPS()->getAMPAcc( uiDepth ) ) |
---|
| 605 | { |
---|
| 606 | if (eMode == SIZE_2NxN) |
---|
| 607 | { |
---|
| 608 | m_pcTDecBinIf->decodeBin(uiSymbol, m_cCUAMPSCModel.get( 0, 0, 0 )); |
---|
| 609 | if (uiSymbol == 0) |
---|
| 610 | { |
---|
| 611 | m_pcTDecBinIf->decodeBinEP(uiSymbol); |
---|
| 612 | eMode = (uiSymbol == 0? SIZE_2NxnU : SIZE_2NxnD); |
---|
| 613 | } |
---|
| 614 | } |
---|
| 615 | else if (eMode == SIZE_Nx2N) |
---|
| 616 | { |
---|
| 617 | m_pcTDecBinIf->decodeBin(uiSymbol, m_cCUAMPSCModel.get( 0, 0, 0 )); |
---|
| 618 | if (uiSymbol == 0) |
---|
| 619 | { |
---|
| 620 | m_pcTDecBinIf->decodeBinEP(uiSymbol); |
---|
| 621 | eMode = (uiSymbol == 0? SIZE_nLx2N : SIZE_nRx2N); |
---|
| 622 | } |
---|
| 623 | } |
---|
| 624 | } |
---|
| 625 | } |
---|
| 626 | pcCU->setPartSizeSubParts( eMode, uiAbsPartIdx, uiDepth ); |
---|
| 627 | pcCU->setSizeSubParts( g_uiMaxCUWidth>>uiDepth, g_uiMaxCUHeight>>uiDepth, uiAbsPartIdx, uiDepth ); |
---|
| 628 | } |
---|
| 629 | |
---|
| 630 | /** parse prediction mode |
---|
| 631 | * \param pcCU |
---|
| 632 | * \param uiAbsPartIdx |
---|
| 633 | * \param uiDepth |
---|
| 634 | * \returns Void |
---|
| 635 | */ |
---|
| 636 | Void TDecSbac::parsePredMode( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth ) |
---|
| 637 | { |
---|
| 638 | if( pcCU->getSlice()->isIntra() ) |
---|
| 639 | { |
---|
| 640 | pcCU->setPredModeSubParts( MODE_INTRA, uiAbsPartIdx, uiDepth ); |
---|
| 641 | return; |
---|
| 642 | } |
---|
| 643 | |
---|
| 644 | UInt uiSymbol; |
---|
| 645 | Int iPredMode = MODE_INTER; |
---|
| 646 | m_pcTDecBinIf->decodeBin( uiSymbol, m_cCUPredModeSCModel.get( 0, 0, 0 ) ); |
---|
| 647 | iPredMode += uiSymbol; |
---|
| 648 | pcCU->setPredModeSubParts( (PredMode)iPredMode, uiAbsPartIdx, uiDepth ); |
---|
| 649 | } |
---|
| 650 | |
---|
| 651 | Void TDecSbac::parseIntraDirLumaAng ( TComDataCU* pcCU, UInt absPartIdx, UInt depth ) |
---|
| 652 | { |
---|
| 653 | PartSize mode = pcCU->getPartitionSize( absPartIdx ); |
---|
| 654 | UInt partNum = mode==SIZE_NxN?4:1; |
---|
| 655 | UInt partOffset = ( pcCU->getPic()->getNumPartInCU() >> ( pcCU->getDepth(absPartIdx) << 1 ) ) >> 2; |
---|
| 656 | UInt mpmPred[4],symbol; |
---|
| 657 | Int j,intraPredMode; |
---|
| 658 | if (mode==SIZE_NxN) |
---|
| 659 | { |
---|
| 660 | depth++; |
---|
| 661 | } |
---|
| 662 | for (j=0;j<partNum;j++) |
---|
| 663 | { |
---|
| 664 | m_pcTDecBinIf->decodeBin( symbol, m_cCUIntraPredSCModel.get( 0, 0, 0) ); |
---|
| 665 | mpmPred[j] = symbol; |
---|
| 666 | } |
---|
| 667 | for (j=0;j<partNum;j++) |
---|
| 668 | { |
---|
| 669 | Int preds[3] = {-1, -1, -1}; |
---|
| 670 | Int predNum = pcCU->getIntraDirLumaPredictor(absPartIdx+partOffset*j, preds); |
---|
| 671 | if (mpmPred[j]) |
---|
| 672 | { |
---|
| 673 | m_pcTDecBinIf->decodeBinEP( symbol ); |
---|
| 674 | if (symbol) |
---|
| 675 | { |
---|
| 676 | m_pcTDecBinIf->decodeBinEP( symbol ); |
---|
| 677 | symbol++; |
---|
| 678 | } |
---|
| 679 | intraPredMode = preds[symbol]; |
---|
| 680 | } |
---|
| 681 | else |
---|
| 682 | { |
---|
| 683 | intraPredMode = 0; |
---|
| 684 | m_pcTDecBinIf->decodeBinsEP( symbol, 5 ); |
---|
| 685 | intraPredMode = symbol; |
---|
| 686 | |
---|
| 687 | //postponed sorting of MPMs (only in remaining branch) |
---|
| 688 | if (preds[0] > preds[1]) |
---|
| 689 | { |
---|
| 690 | std::swap(preds[0], preds[1]); |
---|
| 691 | } |
---|
| 692 | if (preds[0] > preds[2]) |
---|
| 693 | { |
---|
| 694 | std::swap(preds[0], preds[2]); |
---|
| 695 | } |
---|
| 696 | if (preds[1] > preds[2]) |
---|
| 697 | { |
---|
| 698 | std::swap(preds[1], preds[2]); |
---|
| 699 | } |
---|
| 700 | for ( Int i = 0; i < predNum; i++ ) |
---|
| 701 | { |
---|
| 702 | intraPredMode += ( intraPredMode >= preds[i] ); |
---|
| 703 | } |
---|
| 704 | } |
---|
| 705 | pcCU->setLumaIntraDirSubParts( (UChar)intraPredMode, absPartIdx+partOffset*j, depth ); |
---|
| 706 | } |
---|
| 707 | } |
---|
| 708 | |
---|
| 709 | Void TDecSbac::parseIntraDirChroma( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth ) |
---|
| 710 | { |
---|
| 711 | UInt uiSymbol; |
---|
| 712 | |
---|
| 713 | m_pcTDecBinIf->decodeBin( uiSymbol, m_cCUChromaPredSCModel.get( 0, 0, 0 ) ); |
---|
| 714 | |
---|
| 715 | if( uiSymbol == 0 ) |
---|
| 716 | { |
---|
| 717 | uiSymbol = DM_CHROMA_IDX; |
---|
| 718 | } |
---|
| 719 | else |
---|
| 720 | { |
---|
| 721 | { |
---|
| 722 | UInt uiIPredMode; |
---|
| 723 | m_pcTDecBinIf->decodeBinsEP( uiIPredMode, 2 ); |
---|
| 724 | UInt uiAllowedChromaDir[ NUM_CHROMA_MODE ]; |
---|
| 725 | pcCU->getAllowedChromaDir( uiAbsPartIdx, uiAllowedChromaDir ); |
---|
| 726 | uiSymbol = uiAllowedChromaDir[ uiIPredMode ]; |
---|
| 727 | } |
---|
| 728 | } |
---|
| 729 | pcCU->setChromIntraDirSubParts( uiSymbol, uiAbsPartIdx, uiDepth ); |
---|
| 730 | return; |
---|
| 731 | } |
---|
| 732 | |
---|
| 733 | Void TDecSbac::parseInterDir( TComDataCU* pcCU, UInt& ruiInterDir, UInt uiAbsPartIdx ) |
---|
| 734 | { |
---|
| 735 | UInt uiSymbol; |
---|
| 736 | const UInt uiCtx = pcCU->getCtxInterDir( uiAbsPartIdx ); |
---|
| 737 | ContextModel *pCtx = m_cCUInterDirSCModel.get( 0 ); |
---|
| 738 | uiSymbol = 0; |
---|
| 739 | if (pcCU->getPartitionSize(uiAbsPartIdx) == SIZE_2Nx2N || pcCU->getHeight(uiAbsPartIdx) != 8 ) |
---|
| 740 | { |
---|
| 741 | m_pcTDecBinIf->decodeBin( uiSymbol, *( pCtx + uiCtx ) ); |
---|
| 742 | } |
---|
| 743 | |
---|
| 744 | if( uiSymbol ) |
---|
| 745 | { |
---|
| 746 | uiSymbol = 2; |
---|
| 747 | } |
---|
| 748 | else |
---|
| 749 | { |
---|
| 750 | m_pcTDecBinIf->decodeBin( uiSymbol, *( pCtx + 4 ) ); |
---|
| 751 | assert(uiSymbol == 0 || uiSymbol == 1); |
---|
| 752 | } |
---|
| 753 | |
---|
| 754 | uiSymbol++; |
---|
| 755 | ruiInterDir = uiSymbol; |
---|
| 756 | return; |
---|
| 757 | } |
---|
| 758 | |
---|
| 759 | Void TDecSbac::parseRefFrmIdx( TComDataCU* pcCU, Int& riRefFrmIdx, RefPicList eRefList ) |
---|
| 760 | { |
---|
| 761 | UInt uiSymbol; |
---|
| 762 | { |
---|
| 763 | ContextModel *pCtx = m_cCURefPicSCModel.get( 0 ); |
---|
| 764 | m_pcTDecBinIf->decodeBin( uiSymbol, *pCtx ); |
---|
| 765 | |
---|
| 766 | if( uiSymbol ) |
---|
| 767 | { |
---|
| 768 | UInt uiRefNum = pcCU->getSlice()->getNumRefIdx( eRefList ) - 2; |
---|
| 769 | pCtx++; |
---|
| 770 | UInt ui; |
---|
| 771 | for( ui = 0; ui < uiRefNum; ++ui ) |
---|
| 772 | { |
---|
| 773 | if( ui == 0 ) |
---|
| 774 | { |
---|
| 775 | m_pcTDecBinIf->decodeBin( uiSymbol, *pCtx ); |
---|
| 776 | } |
---|
| 777 | else |
---|
| 778 | { |
---|
| 779 | m_pcTDecBinIf->decodeBinEP( uiSymbol ); |
---|
| 780 | } |
---|
| 781 | if( uiSymbol == 0 ) |
---|
| 782 | { |
---|
| 783 | break; |
---|
| 784 | } |
---|
| 785 | } |
---|
| 786 | uiSymbol = ui + 1; |
---|
| 787 | } |
---|
| 788 | riRefFrmIdx = uiSymbol; |
---|
| 789 | } |
---|
| 790 | |
---|
| 791 | return; |
---|
| 792 | } |
---|
| 793 | |
---|
| 794 | Void TDecSbac::parseMvd( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiPartIdx, UInt uiDepth, RefPicList eRefList ) |
---|
| 795 | { |
---|
| 796 | UInt uiSymbol; |
---|
| 797 | UInt uiHorAbs; |
---|
| 798 | UInt uiVerAbs; |
---|
| 799 | UInt uiHorSign = 0; |
---|
| 800 | UInt uiVerSign = 0; |
---|
| 801 | ContextModel *pCtx = m_cCUMvdSCModel.get( 0 ); |
---|
| 802 | |
---|
| 803 | if(pcCU->getSlice()->getMvdL1ZeroFlag() && eRefList == REF_PIC_LIST_1 && pcCU->getInterDir(uiAbsPartIdx)==3) |
---|
| 804 | { |
---|
| 805 | uiHorAbs=0; |
---|
| 806 | uiVerAbs=0; |
---|
| 807 | } |
---|
| 808 | else |
---|
| 809 | { |
---|
| 810 | m_pcTDecBinIf->decodeBin( uiHorAbs, *pCtx ); |
---|
| 811 | m_pcTDecBinIf->decodeBin( uiVerAbs, *pCtx ); |
---|
| 812 | |
---|
| 813 | const Bool bHorAbsGr0 = uiHorAbs != 0; |
---|
| 814 | const Bool bVerAbsGr0 = uiVerAbs != 0; |
---|
| 815 | pCtx++; |
---|
| 816 | |
---|
| 817 | if( bHorAbsGr0 ) |
---|
| 818 | { |
---|
| 819 | m_pcTDecBinIf->decodeBin( uiSymbol, *pCtx ); |
---|
| 820 | uiHorAbs += uiSymbol; |
---|
| 821 | } |
---|
| 822 | |
---|
| 823 | if( bVerAbsGr0 ) |
---|
| 824 | { |
---|
| 825 | m_pcTDecBinIf->decodeBin( uiSymbol, *pCtx ); |
---|
| 826 | uiVerAbs += uiSymbol; |
---|
| 827 | } |
---|
| 828 | |
---|
| 829 | if( bHorAbsGr0 ) |
---|
| 830 | { |
---|
| 831 | if( 2 == uiHorAbs ) |
---|
| 832 | { |
---|
| 833 | xReadEpExGolomb( uiSymbol, 1 ); |
---|
| 834 | uiHorAbs += uiSymbol; |
---|
| 835 | } |
---|
| 836 | |
---|
| 837 | m_pcTDecBinIf->decodeBinEP( uiHorSign ); |
---|
| 838 | } |
---|
| 839 | |
---|
| 840 | if( bVerAbsGr0 ) |
---|
| 841 | { |
---|
| 842 | if( 2 == uiVerAbs ) |
---|
| 843 | { |
---|
| 844 | xReadEpExGolomb( uiSymbol, 1 ); |
---|
| 845 | uiVerAbs += uiSymbol; |
---|
| 846 | } |
---|
| 847 | |
---|
| 848 | m_pcTDecBinIf->decodeBinEP( uiVerSign ); |
---|
| 849 | } |
---|
| 850 | |
---|
| 851 | } |
---|
| 852 | |
---|
| 853 | const TComMv cMv( uiHorSign ? -Int( uiHorAbs ): uiHorAbs, uiVerSign ? -Int( uiVerAbs ) : uiVerAbs ); |
---|
| 854 | pcCU->getCUMvField( eRefList )->setAllMvd( cMv, pcCU->getPartitionSize( uiAbsPartIdx ), uiAbsPartIdx, uiDepth, uiPartIdx ); |
---|
| 855 | return; |
---|
| 856 | } |
---|
| 857 | |
---|
| 858 | |
---|
| 859 | Void TDecSbac::parseTransformSubdivFlag( UInt& ruiSubdivFlag, UInt uiLog2TransformBlockSize ) |
---|
| 860 | { |
---|
| 861 | m_pcTDecBinIf->decodeBin( ruiSubdivFlag, m_cCUTransSubdivFlagSCModel.get( 0, 0, uiLog2TransformBlockSize ) ); |
---|
| 862 | DTRACE_CABAC_VL( g_nSymbolCounter++ ) |
---|
| 863 | DTRACE_CABAC_T( "\tparseTransformSubdivFlag()" ) |
---|
| 864 | DTRACE_CABAC_T( "\tsymbol=" ) |
---|
| 865 | DTRACE_CABAC_V( ruiSubdivFlag ) |
---|
| 866 | DTRACE_CABAC_T( "\tctx=" ) |
---|
| 867 | DTRACE_CABAC_V( uiLog2TransformBlockSize ) |
---|
| 868 | DTRACE_CABAC_T( "\n" ) |
---|
| 869 | } |
---|
| 870 | |
---|
| 871 | Void TDecSbac::parseQtRootCbf( UInt uiAbsPartIdx, UInt& uiQtRootCbf ) |
---|
| 872 | { |
---|
| 873 | UInt uiSymbol; |
---|
| 874 | const UInt uiCtx = 0; |
---|
| 875 | m_pcTDecBinIf->decodeBin( uiSymbol , m_cCUQtRootCbfSCModel.get( 0, 0, uiCtx ) ); |
---|
| 876 | DTRACE_CABAC_VL( g_nSymbolCounter++ ) |
---|
| 877 | DTRACE_CABAC_T( "\tparseQtRootCbf()" ) |
---|
| 878 | DTRACE_CABAC_T( "\tsymbol=" ) |
---|
| 879 | DTRACE_CABAC_V( uiSymbol ) |
---|
| 880 | DTRACE_CABAC_T( "\tctx=" ) |
---|
| 881 | DTRACE_CABAC_V( uiCtx ) |
---|
| 882 | DTRACE_CABAC_T( "\tuiAbsPartIdx=" ) |
---|
| 883 | DTRACE_CABAC_V( uiAbsPartIdx ) |
---|
| 884 | DTRACE_CABAC_T( "\n" ) |
---|
| 885 | |
---|
| 886 | uiQtRootCbf = uiSymbol; |
---|
| 887 | } |
---|
| 888 | |
---|
| 889 | Void TDecSbac::parseDeltaQP( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth ) |
---|
| 890 | { |
---|
| 891 | Int qp; |
---|
| 892 | UInt uiDQp; |
---|
| 893 | Int iDQp; |
---|
| 894 | |
---|
| 895 | UInt uiSymbol; |
---|
| 896 | |
---|
| 897 | xReadUnaryMaxSymbol (uiDQp, &m_cCUDeltaQpSCModel.get( 0, 0, 0 ), 1, CU_DQP_TU_CMAX); |
---|
| 898 | |
---|
| 899 | if( uiDQp >= CU_DQP_TU_CMAX) |
---|
| 900 | { |
---|
| 901 | xReadEpExGolomb( uiSymbol, CU_DQP_EG_k ); |
---|
| 902 | uiDQp+=uiSymbol; |
---|
| 903 | } |
---|
| 904 | |
---|
| 905 | if ( uiDQp > 0 ) |
---|
| 906 | { |
---|
| 907 | UInt uiSign; |
---|
| 908 | Int qpBdOffsetY = pcCU->getSlice()->getSPS()->getQpBDOffsetY(); |
---|
| 909 | m_pcTDecBinIf->decodeBinEP(uiSign); |
---|
| 910 | iDQp = uiDQp; |
---|
| 911 | if(uiSign) |
---|
| 912 | { |
---|
| 913 | iDQp = -iDQp; |
---|
| 914 | } |
---|
| 915 | qp = (((Int) pcCU->getRefQP( uiAbsPartIdx ) + iDQp + 52 + 2*qpBdOffsetY )%(52+qpBdOffsetY)) - qpBdOffsetY; |
---|
| 916 | } |
---|
| 917 | else |
---|
| 918 | { |
---|
| 919 | iDQp=0; |
---|
| 920 | qp = pcCU->getRefQP(uiAbsPartIdx); |
---|
| 921 | } |
---|
| 922 | pcCU->setQPSubParts(qp, uiAbsPartIdx, uiDepth); |
---|
| 923 | pcCU->setCodedQP(qp); |
---|
| 924 | } |
---|
| 925 | |
---|
| 926 | Void TDecSbac::parseQtCbf( TComDataCU* pcCU, UInt uiAbsPartIdx, TextType eType, UInt uiTrDepth, UInt uiDepth ) |
---|
| 927 | { |
---|
| 928 | UInt uiSymbol; |
---|
| 929 | const UInt uiCtx = pcCU->getCtxQtCbf( eType, uiTrDepth ); |
---|
| 930 | m_pcTDecBinIf->decodeBin( uiSymbol , m_cCUQtCbfSCModel.get( 0, eType ? TEXT_CHROMA: eType, uiCtx ) ); |
---|
| 931 | |
---|
| 932 | DTRACE_CABAC_VL( g_nSymbolCounter++ ) |
---|
| 933 | DTRACE_CABAC_T( "\tparseQtCbf()" ) |
---|
| 934 | DTRACE_CABAC_T( "\tsymbol=" ) |
---|
| 935 | DTRACE_CABAC_V( uiSymbol ) |
---|
| 936 | DTRACE_CABAC_T( "\tctx=" ) |
---|
| 937 | DTRACE_CABAC_V( uiCtx ) |
---|
| 938 | DTRACE_CABAC_T( "\tetype=" ) |
---|
| 939 | DTRACE_CABAC_V( eType ) |
---|
| 940 | DTRACE_CABAC_T( "\tuiAbsPartIdx=" ) |
---|
| 941 | DTRACE_CABAC_V( uiAbsPartIdx ) |
---|
| 942 | DTRACE_CABAC_T( "\n" ) |
---|
| 943 | |
---|
| 944 | pcCU->setCbfSubParts( uiSymbol << uiTrDepth, eType, uiAbsPartIdx, uiDepth ); |
---|
| 945 | } |
---|
| 946 | |
---|
| 947 | void TDecSbac::parseTransformSkipFlags (TComDataCU* pcCU, UInt uiAbsPartIdx, UInt width, UInt height, UInt uiDepth, TextType eTType) |
---|
| 948 | { |
---|
| 949 | if (pcCU->getCUTransquantBypass(uiAbsPartIdx)) |
---|
| 950 | { |
---|
| 951 | return; |
---|
| 952 | } |
---|
| 953 | if(width != 4 || height != 4) |
---|
| 954 | { |
---|
| 955 | return; |
---|
| 956 | } |
---|
| 957 | |
---|
| 958 | UInt useTransformSkip; |
---|
| 959 | m_pcTDecBinIf->decodeBin( useTransformSkip , m_cTransformSkipSCModel.get( 0, eTType? TEXT_CHROMA: TEXT_LUMA, 0 ) ); |
---|
| 960 | if(eTType!= TEXT_LUMA) |
---|
| 961 | { |
---|
| 962 | const UInt uiLog2TrafoSize = g_aucConvertToBit[pcCU->getSlice()->getSPS()->getMaxCUWidth()] + 2 - uiDepth; |
---|
| 963 | if(uiLog2TrafoSize == 2) |
---|
| 964 | { |
---|
| 965 | uiDepth --; |
---|
| 966 | } |
---|
| 967 | } |
---|
| 968 | DTRACE_CABAC_VL( g_nSymbolCounter++ ) |
---|
| 969 | DTRACE_CABAC_T("\tparseTransformSkip()"); |
---|
| 970 | DTRACE_CABAC_T( "\tsymbol=" ) |
---|
| 971 | DTRACE_CABAC_V( useTransformSkip ) |
---|
| 972 | DTRACE_CABAC_T( "\tAddr=" ) |
---|
| 973 | DTRACE_CABAC_V( pcCU->getAddr() ) |
---|
| 974 | DTRACE_CABAC_T( "\tetype=" ) |
---|
| 975 | DTRACE_CABAC_V( eTType ) |
---|
| 976 | DTRACE_CABAC_T( "\tuiAbsPartIdx=" ) |
---|
| 977 | DTRACE_CABAC_V( uiAbsPartIdx ) |
---|
| 978 | DTRACE_CABAC_T( "\n" ) |
---|
| 979 | |
---|
| 980 | pcCU->setTransformSkipSubParts( useTransformSkip, eTType, uiAbsPartIdx, uiDepth); |
---|
| 981 | } |
---|
| 982 | |
---|
| 983 | /** Parse (X,Y) position of the last significant coefficient |
---|
| 984 | * \param uiPosLastX reference to X component of last coefficient |
---|
| 985 | * \param uiPosLastY reference to Y component of last coefficient |
---|
| 986 | * \param width Block width |
---|
| 987 | * \param height Block height |
---|
| 988 | * \param eTType plane type / luminance or chrominance |
---|
| 989 | * \param uiScanIdx scan type (zig-zag, hor, ver) |
---|
| 990 | * |
---|
| 991 | * This method decodes the X and Y component within a block of the last significant coefficient. |
---|
| 992 | */ |
---|
| 993 | Void TDecSbac::parseLastSignificantXY( UInt& uiPosLastX, UInt& uiPosLastY, Int width, Int height, TextType eTType, UInt uiScanIdx ) |
---|
| 994 | { |
---|
| 995 | UInt uiLast; |
---|
| 996 | ContextModel *pCtxX = m_cCuCtxLastX.get( 0, eTType ); |
---|
| 997 | ContextModel *pCtxY = m_cCuCtxLastY.get( 0, eTType ); |
---|
| 998 | |
---|
| 999 | Int blkSizeOffsetX, blkSizeOffsetY, shiftX, shiftY; |
---|
| 1000 | blkSizeOffsetX = eTType ? 0: (g_aucConvertToBit[ width ] *3 + ((g_aucConvertToBit[ width ] +1)>>2)); |
---|
| 1001 | blkSizeOffsetY = eTType ? 0: (g_aucConvertToBit[ height ]*3 + ((g_aucConvertToBit[ height ]+1)>>2)); |
---|
| 1002 | shiftX= eTType ? g_aucConvertToBit[ width ] :((g_aucConvertToBit[ width ]+3)>>2); |
---|
| 1003 | shiftY= eTType ? g_aucConvertToBit[ height ] :((g_aucConvertToBit[ height ]+3)>>2); |
---|
| 1004 | // posX |
---|
| 1005 | for( uiPosLastX = 0; uiPosLastX < g_uiGroupIdx[ width - 1 ]; uiPosLastX++ ) |
---|
| 1006 | { |
---|
| 1007 | m_pcTDecBinIf->decodeBin( uiLast, *( pCtxX + blkSizeOffsetX + (uiPosLastX >>shiftX) ) ); |
---|
| 1008 | if( !uiLast ) |
---|
| 1009 | { |
---|
| 1010 | break; |
---|
| 1011 | } |
---|
| 1012 | } |
---|
| 1013 | |
---|
| 1014 | // posY |
---|
| 1015 | for( uiPosLastY = 0; uiPosLastY < g_uiGroupIdx[ height - 1 ]; uiPosLastY++ ) |
---|
| 1016 | { |
---|
| 1017 | m_pcTDecBinIf->decodeBin( uiLast, *( pCtxY + blkSizeOffsetY + (uiPosLastY >>shiftY)) ); |
---|
| 1018 | if( !uiLast ) |
---|
| 1019 | { |
---|
| 1020 | break; |
---|
| 1021 | } |
---|
| 1022 | } |
---|
| 1023 | if ( uiPosLastX > 3 ) |
---|
| 1024 | { |
---|
| 1025 | UInt uiTemp = 0; |
---|
| 1026 | UInt uiCount = ( uiPosLastX - 2 ) >> 1; |
---|
| 1027 | for ( Int i = uiCount - 1; i >= 0; i-- ) |
---|
| 1028 | { |
---|
| 1029 | m_pcTDecBinIf->decodeBinEP( uiLast ); |
---|
| 1030 | uiTemp += uiLast << i; |
---|
| 1031 | } |
---|
| 1032 | uiPosLastX = g_uiMinInGroup[ uiPosLastX ] + uiTemp; |
---|
| 1033 | } |
---|
| 1034 | if ( uiPosLastY > 3 ) |
---|
| 1035 | { |
---|
| 1036 | UInt uiTemp = 0; |
---|
| 1037 | UInt uiCount = ( uiPosLastY - 2 ) >> 1; |
---|
| 1038 | for ( Int i = uiCount - 1; i >= 0; i-- ) |
---|
| 1039 | { |
---|
| 1040 | m_pcTDecBinIf->decodeBinEP( uiLast ); |
---|
| 1041 | uiTemp += uiLast << i; |
---|
| 1042 | } |
---|
| 1043 | uiPosLastY = g_uiMinInGroup[ uiPosLastY ] + uiTemp; |
---|
| 1044 | } |
---|
| 1045 | |
---|
| 1046 | if( uiScanIdx == SCAN_VER ) |
---|
| 1047 | { |
---|
| 1048 | swap( uiPosLastX, uiPosLastY ); |
---|
| 1049 | } |
---|
| 1050 | } |
---|
| 1051 | |
---|
| 1052 | Void TDecSbac::parseCoeffNxN( TComDataCU* pcCU, TCoeff* pcCoef, UInt uiAbsPartIdx, UInt uiWidth, UInt uiHeight, UInt uiDepth, TextType eTType ) |
---|
| 1053 | { |
---|
| 1054 | DTRACE_CABAC_VL( g_nSymbolCounter++ ) |
---|
| 1055 | DTRACE_CABAC_T( "\tparseCoeffNxN()\teType=" ) |
---|
| 1056 | DTRACE_CABAC_V( eTType ) |
---|
| 1057 | DTRACE_CABAC_T( "\twidth=" ) |
---|
| 1058 | DTRACE_CABAC_V( uiWidth ) |
---|
| 1059 | DTRACE_CABAC_T( "\theight=" ) |
---|
| 1060 | DTRACE_CABAC_V( uiHeight ) |
---|
| 1061 | DTRACE_CABAC_T( "\tdepth=" ) |
---|
| 1062 | DTRACE_CABAC_V( uiDepth ) |
---|
| 1063 | DTRACE_CABAC_T( "\tabspartidx=" ) |
---|
| 1064 | DTRACE_CABAC_V( uiAbsPartIdx ) |
---|
| 1065 | DTRACE_CABAC_T( "\ttoCU-X=" ) |
---|
| 1066 | DTRACE_CABAC_V( pcCU->getCUPelX() ) |
---|
| 1067 | DTRACE_CABAC_T( "\ttoCU-Y=" ) |
---|
| 1068 | DTRACE_CABAC_V( pcCU->getCUPelY() ) |
---|
| 1069 | DTRACE_CABAC_T( "\tCU-addr=" ) |
---|
| 1070 | DTRACE_CABAC_V( pcCU->getAddr() ) |
---|
| 1071 | DTRACE_CABAC_T( "\tinCU-X=" ) |
---|
| 1072 | DTRACE_CABAC_V( g_auiRasterToPelX[ g_auiZscanToRaster[uiAbsPartIdx] ] ) |
---|
| 1073 | DTRACE_CABAC_T( "\tinCU-Y=" ) |
---|
| 1074 | DTRACE_CABAC_V( g_auiRasterToPelY[ g_auiZscanToRaster[uiAbsPartIdx] ] ) |
---|
| 1075 | DTRACE_CABAC_T( "\tpredmode=" ) |
---|
| 1076 | DTRACE_CABAC_V( pcCU->getPredictionMode( uiAbsPartIdx ) ) |
---|
| 1077 | DTRACE_CABAC_T( "\n" ) |
---|
| 1078 | |
---|
| 1079 | if( uiWidth > pcCU->getSlice()->getSPS()->getMaxTrSize() ) |
---|
| 1080 | { |
---|
| 1081 | uiWidth = pcCU->getSlice()->getSPS()->getMaxTrSize(); |
---|
| 1082 | uiHeight = pcCU->getSlice()->getSPS()->getMaxTrSize(); |
---|
| 1083 | } |
---|
| 1084 | if(pcCU->getSlice()->getPPS()->getUseTransformSkip()) |
---|
| 1085 | { |
---|
| 1086 | parseTransformSkipFlags( pcCU, uiAbsPartIdx, uiWidth, uiHeight, uiDepth, eTType); |
---|
| 1087 | } |
---|
| 1088 | |
---|
| 1089 | eTType = eTType == TEXT_LUMA ? TEXT_LUMA : ( eTType == TEXT_NONE ? TEXT_NONE : TEXT_CHROMA ); |
---|
| 1090 | |
---|
| 1091 | //----- parse significance map ----- |
---|
| 1092 | const UInt uiLog2BlockSize = g_aucConvertToBit[ uiWidth ] + 2; |
---|
| 1093 | const UInt uiMaxNumCoeff = uiWidth * uiHeight; |
---|
| 1094 | const UInt uiMaxNumCoeffM1 = uiMaxNumCoeff - 1; |
---|
| 1095 | UInt uiScanIdx = pcCU->getCoefScanIdx(uiAbsPartIdx, uiWidth, eTType==TEXT_LUMA, pcCU->isIntra(uiAbsPartIdx)); |
---|
| 1096 | |
---|
| 1097 | //===== decode last significant ===== |
---|
| 1098 | UInt uiPosLastX, uiPosLastY; |
---|
| 1099 | parseLastSignificantXY( uiPosLastX, uiPosLastY, uiWidth, uiHeight, eTType, uiScanIdx ); |
---|
| 1100 | UInt uiBlkPosLast = uiPosLastX + (uiPosLastY<<uiLog2BlockSize); |
---|
| 1101 | pcCoef[ uiBlkPosLast ] = 1; |
---|
| 1102 | |
---|
| 1103 | //===== decode significance flags ===== |
---|
| 1104 | UInt uiScanPosLast = uiBlkPosLast; |
---|
| 1105 | const UInt *scan = g_auiSigLastScan[ uiScanIdx ][ uiLog2BlockSize-1 ]; |
---|
| 1106 | for( uiScanPosLast = 0; uiScanPosLast < uiMaxNumCoeffM1; uiScanPosLast++ ) |
---|
| 1107 | { |
---|
| 1108 | UInt uiBlkPos = scan[ uiScanPosLast ]; |
---|
| 1109 | if( uiBlkPosLast == uiBlkPos ) |
---|
| 1110 | { |
---|
| 1111 | break; |
---|
| 1112 | } |
---|
| 1113 | } |
---|
| 1114 | |
---|
| 1115 | ContextModel * const baseCoeffGroupCtx = m_cCUSigCoeffGroupSCModel.get( 0, eTType ); |
---|
| 1116 | ContextModel * const baseCtx = (eTType==TEXT_LUMA) ? m_cCUSigSCModel.get( 0, 0 ) : m_cCUSigSCModel.get( 0, 0 ) + NUM_SIG_FLAG_CTX_LUMA; |
---|
| 1117 | |
---|
| 1118 | const Int iLastScanSet = uiScanPosLast >> LOG2_SCAN_SET_SIZE; |
---|
| 1119 | UInt c1 = 1; |
---|
| 1120 | UInt uiGoRiceParam = 0; |
---|
| 1121 | |
---|
| 1122 | Bool beValid; |
---|
| 1123 | if (pcCU->getCUTransquantBypass(uiAbsPartIdx)) |
---|
| 1124 | { |
---|
| 1125 | beValid = false; |
---|
| 1126 | } |
---|
| 1127 | else |
---|
| 1128 | { |
---|
| 1129 | beValid = pcCU->getSlice()->getPPS()->getSignHideFlag() > 0; |
---|
| 1130 | } |
---|
| 1131 | UInt absSum = 0; |
---|
| 1132 | |
---|
| 1133 | UInt uiSigCoeffGroupFlag[ MLS_GRP_NUM ]; |
---|
| 1134 | ::memset( uiSigCoeffGroupFlag, 0, sizeof(UInt) * MLS_GRP_NUM ); |
---|
| 1135 | const UInt uiNumBlkSide = uiWidth >> (MLS_CG_SIZE >> 1); |
---|
| 1136 | const UInt * scanCG; |
---|
| 1137 | { |
---|
| 1138 | scanCG = g_auiSigLastScan[ uiScanIdx ][ uiLog2BlockSize > 3 ? uiLog2BlockSize-2-1 : 0 ]; |
---|
| 1139 | if( uiLog2BlockSize == 3 ) |
---|
| 1140 | { |
---|
| 1141 | scanCG = g_sigLastScan8x8[ uiScanIdx ]; |
---|
| 1142 | } |
---|
| 1143 | else if( uiLog2BlockSize == 5 ) |
---|
| 1144 | { |
---|
| 1145 | scanCG = g_sigLastScanCG32x32; |
---|
| 1146 | } |
---|
| 1147 | } |
---|
| 1148 | Int iScanPosSig = (Int) uiScanPosLast; |
---|
| 1149 | for( Int iSubSet = iLastScanSet; iSubSet >= 0; iSubSet-- ) |
---|
| 1150 | { |
---|
| 1151 | Int iSubPos = iSubSet << LOG2_SCAN_SET_SIZE; |
---|
| 1152 | uiGoRiceParam = 0; |
---|
| 1153 | Int numNonZero = 0; |
---|
| 1154 | |
---|
| 1155 | Int lastNZPosInCG = -1, firstNZPosInCG = SCAN_SET_SIZE; |
---|
| 1156 | |
---|
| 1157 | Int pos[SCAN_SET_SIZE]; |
---|
| 1158 | if( iScanPosSig == (Int) uiScanPosLast ) |
---|
| 1159 | { |
---|
| 1160 | lastNZPosInCG = iScanPosSig; |
---|
| 1161 | firstNZPosInCG = iScanPosSig; |
---|
| 1162 | iScanPosSig--; |
---|
| 1163 | pos[ numNonZero ] = uiBlkPosLast; |
---|
| 1164 | numNonZero = 1; |
---|
| 1165 | } |
---|
| 1166 | |
---|
| 1167 | // decode significant_coeffgroup_flag |
---|
| 1168 | Int iCGBlkPos = scanCG[ iSubSet ]; |
---|
| 1169 | Int iCGPosY = iCGBlkPos / uiNumBlkSide; |
---|
| 1170 | Int iCGPosX = iCGBlkPos - (iCGPosY * uiNumBlkSide); |
---|
| 1171 | if( iSubSet == iLastScanSet || iSubSet == 0) |
---|
| 1172 | { |
---|
| 1173 | uiSigCoeffGroupFlag[ iCGBlkPos ] = 1; |
---|
| 1174 | } |
---|
| 1175 | else |
---|
| 1176 | { |
---|
| 1177 | UInt uiSigCoeffGroup; |
---|
| 1178 | UInt uiCtxSig = TComTrQuant::getSigCoeffGroupCtxInc( uiSigCoeffGroupFlag, iCGPosX, iCGPosY, uiWidth, uiHeight ); |
---|
| 1179 | m_pcTDecBinIf->decodeBin( uiSigCoeffGroup, baseCoeffGroupCtx[ uiCtxSig ] ); |
---|
| 1180 | uiSigCoeffGroupFlag[ iCGBlkPos ] = uiSigCoeffGroup; |
---|
| 1181 | } |
---|
| 1182 | |
---|
| 1183 | // decode significant_coeff_flag |
---|
| 1184 | Int patternSigCtx = TComTrQuant::calcPatternSigCtx( uiSigCoeffGroupFlag, iCGPosX, iCGPosY, uiWidth, uiHeight ); |
---|
| 1185 | UInt uiBlkPos, uiPosY, uiPosX, uiSig, uiCtxSig; |
---|
| 1186 | for( ; iScanPosSig >= iSubPos; iScanPosSig-- ) |
---|
| 1187 | { |
---|
| 1188 | uiBlkPos = scan[ iScanPosSig ]; |
---|
| 1189 | uiPosY = uiBlkPos >> uiLog2BlockSize; |
---|
| 1190 | uiPosX = uiBlkPos - ( uiPosY << uiLog2BlockSize ); |
---|
| 1191 | uiSig = 0; |
---|
| 1192 | |
---|
| 1193 | if( uiSigCoeffGroupFlag[ iCGBlkPos ] ) |
---|
| 1194 | { |
---|
| 1195 | if( iScanPosSig > iSubPos || iSubSet == 0 || numNonZero ) |
---|
| 1196 | { |
---|
| 1197 | uiCtxSig = TComTrQuant::getSigCtxInc( patternSigCtx, uiScanIdx, uiPosX, uiPosY, uiLog2BlockSize, eTType ); |
---|
| 1198 | m_pcTDecBinIf->decodeBin( uiSig, baseCtx[ uiCtxSig ] ); |
---|
| 1199 | } |
---|
| 1200 | else |
---|
| 1201 | { |
---|
| 1202 | uiSig = 1; |
---|
| 1203 | } |
---|
| 1204 | } |
---|
| 1205 | pcCoef[ uiBlkPos ] = uiSig; |
---|
| 1206 | if( uiSig ) |
---|
| 1207 | { |
---|
| 1208 | pos[ numNonZero ] = uiBlkPos; |
---|
| 1209 | numNonZero ++; |
---|
| 1210 | if( lastNZPosInCG == -1 ) |
---|
| 1211 | { |
---|
| 1212 | lastNZPosInCG = iScanPosSig; |
---|
| 1213 | } |
---|
| 1214 | firstNZPosInCG = iScanPosSig; |
---|
| 1215 | } |
---|
| 1216 | } |
---|
| 1217 | |
---|
| 1218 | if( numNonZero ) |
---|
| 1219 | { |
---|
| 1220 | Bool signHidden = ( lastNZPosInCG - firstNZPosInCG >= SBH_THRESHOLD ); |
---|
| 1221 | absSum = 0; |
---|
| 1222 | UInt uiCtxSet = (iSubSet > 0 && eTType==TEXT_LUMA) ? 2 : 0; |
---|
| 1223 | UInt uiBin; |
---|
| 1224 | if( c1 == 0 ) |
---|
| 1225 | { |
---|
| 1226 | uiCtxSet++; |
---|
| 1227 | } |
---|
| 1228 | c1 = 1; |
---|
| 1229 | ContextModel *baseCtxMod = ( eTType==TEXT_LUMA ) ? m_cCUOneSCModel.get( 0, 0 ) + 4 * uiCtxSet : m_cCUOneSCModel.get( 0, 0 ) + NUM_ONE_FLAG_CTX_LUMA + 4 * uiCtxSet; |
---|
| 1230 | Int absCoeff[SCAN_SET_SIZE]; |
---|
| 1231 | |
---|
| 1232 | for ( Int i = 0; i < numNonZero; i++) absCoeff[i] = 1; |
---|
| 1233 | Int numC1Flag = min(numNonZero, C1FLAG_NUMBER); |
---|
| 1234 | Int firstC2FlagIdx = -1; |
---|
| 1235 | |
---|
| 1236 | for( Int idx = 0; idx < numC1Flag; idx++ ) |
---|
| 1237 | { |
---|
| 1238 | m_pcTDecBinIf->decodeBin( uiBin, baseCtxMod[c1] ); |
---|
| 1239 | if( uiBin == 1 ) |
---|
| 1240 | { |
---|
| 1241 | c1 = 0; |
---|
| 1242 | if (firstC2FlagIdx == -1) |
---|
| 1243 | { |
---|
| 1244 | firstC2FlagIdx = idx; |
---|
| 1245 | } |
---|
| 1246 | } |
---|
| 1247 | else if( (c1 < 3) && (c1 > 0) ) |
---|
| 1248 | { |
---|
| 1249 | c1++; |
---|
| 1250 | } |
---|
| 1251 | absCoeff[ idx ] = uiBin + 1; |
---|
| 1252 | } |
---|
| 1253 | |
---|
| 1254 | if (c1 == 0) |
---|
| 1255 | { |
---|
| 1256 | baseCtxMod = ( eTType==TEXT_LUMA ) ? m_cCUAbsSCModel.get( 0, 0 ) + uiCtxSet : m_cCUAbsSCModel.get( 0, 0 ) + NUM_ABS_FLAG_CTX_LUMA + uiCtxSet; |
---|
| 1257 | if ( firstC2FlagIdx != -1) |
---|
| 1258 | { |
---|
| 1259 | m_pcTDecBinIf->decodeBin( uiBin, baseCtxMod[0] ); |
---|
| 1260 | absCoeff[ firstC2FlagIdx ] = uiBin + 2; |
---|
| 1261 | } |
---|
| 1262 | } |
---|
| 1263 | |
---|
| 1264 | UInt coeffSigns; |
---|
| 1265 | if ( signHidden && beValid ) |
---|
| 1266 | { |
---|
| 1267 | m_pcTDecBinIf->decodeBinsEP( coeffSigns, numNonZero-1 ); |
---|
| 1268 | coeffSigns <<= 32 - (numNonZero-1); |
---|
| 1269 | } |
---|
| 1270 | else |
---|
| 1271 | { |
---|
| 1272 | m_pcTDecBinIf->decodeBinsEP( coeffSigns, numNonZero ); |
---|
| 1273 | coeffSigns <<= 32 - numNonZero; |
---|
| 1274 | } |
---|
| 1275 | |
---|
| 1276 | Int iFirstCoeff2 = 1; |
---|
| 1277 | if (c1 == 0 || numNonZero > C1FLAG_NUMBER) |
---|
| 1278 | { |
---|
| 1279 | for( Int idx = 0; idx < numNonZero; idx++ ) |
---|
| 1280 | { |
---|
| 1281 | UInt baseLevel = (idx < C1FLAG_NUMBER)? (2 + iFirstCoeff2) : 1; |
---|
| 1282 | |
---|
| 1283 | if( absCoeff[ idx ] == baseLevel) |
---|
| 1284 | { |
---|
| 1285 | UInt uiLevel; |
---|
| 1286 | xReadCoefRemainExGolomb( uiLevel, uiGoRiceParam ); |
---|
| 1287 | absCoeff[ idx ] = uiLevel + baseLevel; |
---|
| 1288 | if(absCoeff[idx]>3*(1<<uiGoRiceParam)) |
---|
| 1289 | { |
---|
| 1290 | uiGoRiceParam = min<UInt>(uiGoRiceParam+ 1, 4); |
---|
| 1291 | } |
---|
| 1292 | } |
---|
| 1293 | |
---|
| 1294 | if(absCoeff[ idx ] >= 2) |
---|
| 1295 | { |
---|
| 1296 | iFirstCoeff2 = 0; |
---|
| 1297 | } |
---|
| 1298 | } |
---|
| 1299 | } |
---|
| 1300 | |
---|
| 1301 | for( Int idx = 0; idx < numNonZero; idx++ ) |
---|
| 1302 | { |
---|
| 1303 | Int blkPos = pos[ idx ]; |
---|
| 1304 | // Signs applied later. |
---|
| 1305 | pcCoef[ blkPos ] = absCoeff[ idx ]; |
---|
| 1306 | absSum += absCoeff[ idx ]; |
---|
| 1307 | |
---|
| 1308 | if ( idx == numNonZero-1 && signHidden && beValid ) |
---|
| 1309 | { |
---|
| 1310 | // Infer sign of 1st element. |
---|
| 1311 | if (absSum&0x1) |
---|
| 1312 | { |
---|
| 1313 | pcCoef[ blkPos ] = -pcCoef[ blkPos ]; |
---|
| 1314 | } |
---|
| 1315 | } |
---|
| 1316 | else |
---|
| 1317 | { |
---|
| 1318 | Int sign = static_cast<Int>( coeffSigns ) >> 31; |
---|
| 1319 | pcCoef[ blkPos ] = ( pcCoef[ blkPos ] ^ sign ) - sign; |
---|
| 1320 | coeffSigns <<= 1; |
---|
| 1321 | } |
---|
| 1322 | } |
---|
| 1323 | } |
---|
| 1324 | } |
---|
| 1325 | |
---|
| 1326 | return; |
---|
| 1327 | } |
---|
| 1328 | |
---|
| 1329 | |
---|
| 1330 | Void TDecSbac::parseSaoMaxUvlc ( UInt& val, UInt maxSymbol ) |
---|
| 1331 | { |
---|
| 1332 | if (maxSymbol == 0) |
---|
| 1333 | { |
---|
| 1334 | val = 0; |
---|
| 1335 | return; |
---|
| 1336 | } |
---|
| 1337 | |
---|
| 1338 | UInt code; |
---|
| 1339 | Int i; |
---|
| 1340 | m_pcTDecBinIf->decodeBinEP( code ); |
---|
| 1341 | if ( code == 0 ) |
---|
| 1342 | { |
---|
| 1343 | val = 0; |
---|
| 1344 | return; |
---|
| 1345 | } |
---|
| 1346 | |
---|
| 1347 | i=1; |
---|
| 1348 | while (1) |
---|
| 1349 | { |
---|
| 1350 | m_pcTDecBinIf->decodeBinEP( code ); |
---|
| 1351 | if ( code == 0 ) |
---|
| 1352 | { |
---|
| 1353 | break; |
---|
| 1354 | } |
---|
| 1355 | i++; |
---|
| 1356 | if (i == maxSymbol) |
---|
| 1357 | { |
---|
| 1358 | break; |
---|
| 1359 | } |
---|
| 1360 | } |
---|
| 1361 | |
---|
| 1362 | val = i; |
---|
| 1363 | } |
---|
| 1364 | Void TDecSbac::parseSaoUflc (UInt uiLength, UInt& riVal) |
---|
| 1365 | { |
---|
| 1366 | m_pcTDecBinIf->decodeBinsEP ( riVal, uiLength ); |
---|
| 1367 | } |
---|
| 1368 | Void TDecSbac::parseSaoMerge (UInt& ruiVal) |
---|
| 1369 | { |
---|
| 1370 | UInt uiCode; |
---|
| 1371 | m_pcTDecBinIf->decodeBin( uiCode, m_cSaoMergeSCModel.get( 0, 0, 0 ) ); |
---|
| 1372 | ruiVal = (Int)uiCode; |
---|
| 1373 | } |
---|
| 1374 | Void TDecSbac::parseSaoTypeIdx (UInt& ruiVal) |
---|
| 1375 | { |
---|
| 1376 | UInt uiCode; |
---|
| 1377 | m_pcTDecBinIf->decodeBin( uiCode, m_cSaoTypeIdxSCModel.get( 0, 0, 0 ) ); |
---|
| 1378 | if (uiCode == 0) |
---|
| 1379 | { |
---|
| 1380 | ruiVal = 0; |
---|
| 1381 | } |
---|
| 1382 | else |
---|
| 1383 | { |
---|
| 1384 | m_pcTDecBinIf->decodeBinEP( uiCode ); |
---|
| 1385 | if (uiCode == 0) |
---|
| 1386 | { |
---|
| 1387 | ruiVal = 5; |
---|
| 1388 | } |
---|
| 1389 | else |
---|
| 1390 | { |
---|
| 1391 | ruiVal = 1; |
---|
| 1392 | } |
---|
| 1393 | } |
---|
| 1394 | } |
---|
| 1395 | |
---|
| 1396 | inline Void copySaoOneLcuParam(SaoLcuParam* psDst, SaoLcuParam* psSrc) |
---|
| 1397 | { |
---|
| 1398 | Int i; |
---|
| 1399 | psDst->partIdx = psSrc->partIdx; |
---|
| 1400 | psDst->typeIdx = psSrc->typeIdx; |
---|
| 1401 | if (psDst->typeIdx != -1) |
---|
| 1402 | { |
---|
| 1403 | psDst->subTypeIdx = psSrc->subTypeIdx ; |
---|
| 1404 | psDst->length = psSrc->length; |
---|
| 1405 | for (i=0;i<psDst->length;i++) |
---|
| 1406 | { |
---|
| 1407 | psDst->offset[i] = psSrc->offset[i]; |
---|
| 1408 | } |
---|
| 1409 | } |
---|
| 1410 | else |
---|
| 1411 | { |
---|
| 1412 | psDst->length = 0; |
---|
| 1413 | for (i=0;i<SAO_BO_LEN;i++) |
---|
| 1414 | { |
---|
| 1415 | psDst->offset[i] = 0; |
---|
| 1416 | } |
---|
| 1417 | } |
---|
| 1418 | } |
---|
| 1419 | |
---|
| 1420 | Void TDecSbac::parseSaoOffset(SaoLcuParam* psSaoLcuParam, UInt compIdx) |
---|
| 1421 | { |
---|
| 1422 | UInt uiSymbol; |
---|
| 1423 | static Int iTypeLength[MAX_NUM_SAO_TYPE] = |
---|
| 1424 | { |
---|
| 1425 | SAO_EO_LEN, |
---|
| 1426 | SAO_EO_LEN, |
---|
| 1427 | SAO_EO_LEN, |
---|
| 1428 | SAO_EO_LEN, |
---|
| 1429 | SAO_BO_LEN |
---|
| 1430 | }; |
---|
| 1431 | |
---|
| 1432 | if (compIdx==2) |
---|
| 1433 | { |
---|
| 1434 | uiSymbol = (UInt)( psSaoLcuParam->typeIdx + 1); |
---|
| 1435 | } |
---|
| 1436 | else |
---|
| 1437 | { |
---|
| 1438 | parseSaoTypeIdx(uiSymbol); |
---|
| 1439 | } |
---|
| 1440 | psSaoLcuParam->typeIdx = (Int)uiSymbol - 1; |
---|
| 1441 | if (uiSymbol) |
---|
| 1442 | { |
---|
| 1443 | psSaoLcuParam->length = iTypeLength[psSaoLcuParam->typeIdx]; |
---|
| 1444 | |
---|
| 1445 | Int bitDepth = compIdx ? g_bitDepthC : g_bitDepthY; |
---|
| 1446 | Int offsetTh = 1 << min(bitDepth - 5,5); |
---|
| 1447 | |
---|
| 1448 | if( psSaoLcuParam->typeIdx == SAO_BO ) |
---|
| 1449 | { |
---|
| 1450 | for(Int i=0; i< psSaoLcuParam->length; i++) |
---|
| 1451 | { |
---|
| 1452 | parseSaoMaxUvlc(uiSymbol, offsetTh -1 ); |
---|
| 1453 | psSaoLcuParam->offset[i] = uiSymbol; |
---|
| 1454 | } |
---|
| 1455 | for(Int i=0; i< psSaoLcuParam->length; i++) |
---|
| 1456 | { |
---|
| 1457 | if (psSaoLcuParam->offset[i] != 0) |
---|
| 1458 | { |
---|
| 1459 | m_pcTDecBinIf->decodeBinEP ( uiSymbol); |
---|
| 1460 | if (uiSymbol) |
---|
| 1461 | { |
---|
| 1462 | psSaoLcuParam->offset[i] = -psSaoLcuParam->offset[i] ; |
---|
| 1463 | } |
---|
| 1464 | } |
---|
| 1465 | } |
---|
| 1466 | parseSaoUflc(5, uiSymbol ); |
---|
| 1467 | psSaoLcuParam->subTypeIdx = uiSymbol; |
---|
| 1468 | } |
---|
| 1469 | else if( psSaoLcuParam->typeIdx < 4 ) |
---|
| 1470 | { |
---|
| 1471 | parseSaoMaxUvlc(uiSymbol, offsetTh -1 ); psSaoLcuParam->offset[0] = uiSymbol; |
---|
| 1472 | parseSaoMaxUvlc(uiSymbol, offsetTh -1 ); psSaoLcuParam->offset[1] = uiSymbol; |
---|
| 1473 | parseSaoMaxUvlc(uiSymbol, offsetTh -1 ); psSaoLcuParam->offset[2] = -(Int)uiSymbol; |
---|
| 1474 | parseSaoMaxUvlc(uiSymbol, offsetTh -1 ); psSaoLcuParam->offset[3] = -(Int)uiSymbol; |
---|
| 1475 | if (compIdx != 2) |
---|
| 1476 | { |
---|
| 1477 | parseSaoUflc(2, uiSymbol ); |
---|
| 1478 | psSaoLcuParam->subTypeIdx = uiSymbol; |
---|
| 1479 | psSaoLcuParam->typeIdx += psSaoLcuParam->subTypeIdx; |
---|
| 1480 | } |
---|
| 1481 | } |
---|
| 1482 | } |
---|
| 1483 | else |
---|
| 1484 | { |
---|
| 1485 | psSaoLcuParam->length = 0; |
---|
| 1486 | } |
---|
| 1487 | } |
---|
| 1488 | |
---|
| 1489 | Void TDecSbac::parseSaoOneLcuInterleaving(Int rx, Int ry, SAOParam* pSaoParam, TComDataCU* pcCU, Int iCUAddrInSlice, Int iCUAddrUpInSlice, Int allowMergeLeft, Int allowMergeUp) |
---|
| 1490 | { |
---|
| 1491 | Int iAddr = pcCU->getAddr(); |
---|
| 1492 | UInt uiSymbol; |
---|
| 1493 | for (Int iCompIdx=0; iCompIdx<3; iCompIdx++) |
---|
| 1494 | { |
---|
| 1495 | pSaoParam->saoLcuParam[iCompIdx][iAddr].mergeUpFlag = 0; |
---|
| 1496 | pSaoParam->saoLcuParam[iCompIdx][iAddr].mergeLeftFlag = 0; |
---|
| 1497 | pSaoParam->saoLcuParam[iCompIdx][iAddr].subTypeIdx = 0; |
---|
| 1498 | pSaoParam->saoLcuParam[iCompIdx][iAddr].typeIdx = -1; |
---|
| 1499 | pSaoParam->saoLcuParam[iCompIdx][iAddr].offset[0] = 0; |
---|
| 1500 | pSaoParam->saoLcuParam[iCompIdx][iAddr].offset[1] = 0; |
---|
| 1501 | pSaoParam->saoLcuParam[iCompIdx][iAddr].offset[2] = 0; |
---|
| 1502 | pSaoParam->saoLcuParam[iCompIdx][iAddr].offset[3] = 0; |
---|
| 1503 | |
---|
| 1504 | } |
---|
| 1505 | if (pSaoParam->bSaoFlag[0] || pSaoParam->bSaoFlag[1] ) |
---|
| 1506 | { |
---|
| 1507 | if (rx>0 && iCUAddrInSlice!=0 && allowMergeLeft) |
---|
| 1508 | { |
---|
| 1509 | parseSaoMerge(uiSymbol); |
---|
| 1510 | pSaoParam->saoLcuParam[0][iAddr].mergeLeftFlag = (Bool)uiSymbol; |
---|
| 1511 | } |
---|
| 1512 | if (pSaoParam->saoLcuParam[0][iAddr].mergeLeftFlag==0) |
---|
| 1513 | { |
---|
| 1514 | if ((ry > 0) && (iCUAddrUpInSlice>=0) && allowMergeUp) |
---|
| 1515 | { |
---|
| 1516 | parseSaoMerge(uiSymbol); |
---|
| 1517 | pSaoParam->saoLcuParam[0][iAddr].mergeUpFlag = (Bool)uiSymbol; |
---|
| 1518 | } |
---|
| 1519 | } |
---|
| 1520 | } |
---|
| 1521 | |
---|
| 1522 | for (Int iCompIdx=0; iCompIdx<3; iCompIdx++) |
---|
| 1523 | { |
---|
| 1524 | if ((iCompIdx == 0 && pSaoParam->bSaoFlag[0]) || (iCompIdx > 0 && pSaoParam->bSaoFlag[1]) ) |
---|
| 1525 | { |
---|
| 1526 | if (rx>0 && iCUAddrInSlice!=0 && allowMergeLeft) |
---|
| 1527 | { |
---|
| 1528 | pSaoParam->saoLcuParam[iCompIdx][iAddr].mergeLeftFlag = pSaoParam->saoLcuParam[0][iAddr].mergeLeftFlag; |
---|
| 1529 | } |
---|
| 1530 | else |
---|
| 1531 | { |
---|
| 1532 | pSaoParam->saoLcuParam[iCompIdx][iAddr].mergeLeftFlag = 0; |
---|
| 1533 | } |
---|
| 1534 | |
---|
| 1535 | if (pSaoParam->saoLcuParam[iCompIdx][iAddr].mergeLeftFlag==0) |
---|
| 1536 | { |
---|
| 1537 | if ((ry > 0) && (iCUAddrUpInSlice>=0) && allowMergeUp) |
---|
| 1538 | { |
---|
| 1539 | pSaoParam->saoLcuParam[iCompIdx][iAddr].mergeUpFlag = pSaoParam->saoLcuParam[0][iAddr].mergeUpFlag; |
---|
| 1540 | } |
---|
| 1541 | else |
---|
| 1542 | { |
---|
| 1543 | pSaoParam->saoLcuParam[iCompIdx][iAddr].mergeUpFlag = 0; |
---|
| 1544 | } |
---|
| 1545 | if (!pSaoParam->saoLcuParam[iCompIdx][iAddr].mergeUpFlag) |
---|
| 1546 | { |
---|
| 1547 | pSaoParam->saoLcuParam[2][iAddr].typeIdx = pSaoParam->saoLcuParam[1][iAddr].typeIdx; |
---|
| 1548 | parseSaoOffset(&(pSaoParam->saoLcuParam[iCompIdx][iAddr]), iCompIdx); |
---|
| 1549 | } |
---|
| 1550 | else |
---|
| 1551 | { |
---|
| 1552 | copySaoOneLcuParam(&pSaoParam->saoLcuParam[iCompIdx][iAddr], &pSaoParam->saoLcuParam[iCompIdx][iAddr-pSaoParam->numCuInWidth]); |
---|
| 1553 | } |
---|
| 1554 | } |
---|
| 1555 | else |
---|
| 1556 | { |
---|
| 1557 | copySaoOneLcuParam(&pSaoParam->saoLcuParam[iCompIdx][iAddr], &pSaoParam->saoLcuParam[iCompIdx][iAddr-1]); |
---|
| 1558 | } |
---|
| 1559 | } |
---|
| 1560 | else |
---|
| 1561 | { |
---|
| 1562 | pSaoParam->saoLcuParam[iCompIdx][iAddr].typeIdx = -1; |
---|
| 1563 | pSaoParam->saoLcuParam[iCompIdx][iAddr].subTypeIdx = 0; |
---|
| 1564 | } |
---|
| 1565 | } |
---|
| 1566 | } |
---|
| 1567 | |
---|
| 1568 | /** |
---|
| 1569 | - Initialize our contexts from the nominated source. |
---|
| 1570 | . |
---|
| 1571 | \param pSrc Contexts to be copied. |
---|
| 1572 | */ |
---|
| 1573 | Void TDecSbac::xCopyContextsFrom( TDecSbac* pSrc ) |
---|
| 1574 | { |
---|
| 1575 | memcpy(m_contextModels, pSrc->m_contextModels, m_numContextModels*sizeof(m_contextModels[0])); |
---|
| 1576 | } |
---|
| 1577 | |
---|
| 1578 | Void TDecSbac::xCopyFrom( TDecSbac* pSrc ) |
---|
| 1579 | { |
---|
| 1580 | m_pcTDecBinIf->copyState( pSrc->m_pcTDecBinIf ); |
---|
| 1581 | |
---|
| 1582 | m_uiLastQp = pSrc->m_uiLastQp; |
---|
| 1583 | xCopyContextsFrom( pSrc ); |
---|
| 1584 | |
---|
| 1585 | } |
---|
| 1586 | |
---|
| 1587 | Void TDecSbac::load ( TDecSbac* pScr ) |
---|
| 1588 | { |
---|
| 1589 | xCopyFrom(pScr); |
---|
| 1590 | } |
---|
| 1591 | |
---|
| 1592 | Void TDecSbac::loadContexts ( TDecSbac* pScr ) |
---|
| 1593 | { |
---|
| 1594 | xCopyContextsFrom(pScr); |
---|
| 1595 | } |
---|
| 1596 | //! \} |
---|