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