[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(); |
---|
| 358 | |
---|
| 359 | for(uiY = 0; uiY < uiHeight; uiY++) |
---|
| 360 | { |
---|
| 361 | for(uiX = 0; uiX < uiWidth; uiX++) |
---|
| 362 | { |
---|
| 363 | UInt uiSample; |
---|
| 364 | m_pcTDecBinIf->xReadPCMCode(uiSampleBits, uiSample); |
---|
| 365 | piPCMSample[uiX] = uiSample; |
---|
| 366 | } |
---|
| 367 | piPCMSample += uiWidth; |
---|
| 368 | } |
---|
| 369 | |
---|
| 370 | piPCMSample = pcCU->getPCMSampleCr() + uiChromaOffset; |
---|
| 371 | uiWidth = pcCU->getWidth(uiAbsPartIdx)/2; |
---|
| 372 | uiHeight = pcCU->getHeight(uiAbsPartIdx)/2; |
---|
| 373 | uiSampleBits = pcCU->getSlice()->getSPS()->getPCMBitDepthChroma(); |
---|
| 374 | |
---|
| 375 | for(uiY = 0; uiY < uiHeight; uiY++) |
---|
| 376 | { |
---|
| 377 | for(uiX = 0; uiX < uiWidth; uiX++) |
---|
| 378 | { |
---|
| 379 | UInt uiSample; |
---|
| 380 | m_pcTDecBinIf->xReadPCMCode(uiSampleBits, uiSample); |
---|
| 381 | piPCMSample[uiX] = uiSample; |
---|
| 382 | } |
---|
| 383 | piPCMSample += uiWidth; |
---|
| 384 | } |
---|
| 385 | |
---|
| 386 | m_pcTDecBinIf->start(); |
---|
| 387 | } |
---|
| 388 | } |
---|
| 389 | |
---|
| 390 | Void TDecSbac::parseCUTransquantBypassFlag( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth ) |
---|
| 391 | { |
---|
| 392 | UInt uiSymbol; |
---|
| 393 | m_pcTDecBinIf->decodeBin( uiSymbol, m_CUTransquantBypassFlagSCModel.get( 0, 0, 0 ) ); |
---|
| 394 | pcCU->setCUTransquantBypassSubParts(uiSymbol ? true : false, uiAbsPartIdx, uiDepth); |
---|
| 395 | } |
---|
| 396 | |
---|
| 397 | /** parse skip flag |
---|
| 398 | * \param pcCU |
---|
| 399 | * \param uiAbsPartIdx |
---|
| 400 | * \param uiDepth |
---|
| 401 | * \returns Void |
---|
| 402 | */ |
---|
| 403 | Void TDecSbac::parseSkipFlag( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth ) |
---|
| 404 | { |
---|
| 405 | if( pcCU->getSlice()->isIntra() ) |
---|
| 406 | { |
---|
| 407 | return; |
---|
| 408 | } |
---|
| 409 | |
---|
| 410 | UInt uiSymbol = 0; |
---|
| 411 | UInt uiCtxSkip = pcCU->getCtxSkipFlag( uiAbsPartIdx ); |
---|
| 412 | m_pcTDecBinIf->decodeBin( uiSymbol, m_cCUSkipFlagSCModel.get( 0, 0, uiCtxSkip ) ); |
---|
| 413 | DTRACE_CABAC_VL( g_nSymbolCounter++ ); |
---|
| 414 | DTRACE_CABAC_T( "\tSkipFlag" ); |
---|
| 415 | DTRACE_CABAC_T( "\tuiCtxSkip: "); |
---|
| 416 | DTRACE_CABAC_V( uiCtxSkip ); |
---|
| 417 | DTRACE_CABAC_T( "\tuiSymbol: "); |
---|
| 418 | DTRACE_CABAC_V( uiSymbol ); |
---|
| 419 | DTRACE_CABAC_T( "\n"); |
---|
| 420 | |
---|
| 421 | if( uiSymbol ) |
---|
| 422 | { |
---|
| 423 | pcCU->setSkipFlagSubParts( true, uiAbsPartIdx, uiDepth ); |
---|
| 424 | pcCU->setPredModeSubParts( MODE_INTER, uiAbsPartIdx, uiDepth ); |
---|
| 425 | pcCU->setPartSizeSubParts( SIZE_2Nx2N, uiAbsPartIdx, uiDepth ); |
---|
| 426 | pcCU->setSizeSubParts( g_uiMaxCUWidth>>uiDepth, g_uiMaxCUHeight>>uiDepth, uiAbsPartIdx, uiDepth ); |
---|
| 427 | pcCU->setMergeFlagSubParts( true , uiAbsPartIdx, 0, uiDepth ); |
---|
| 428 | } |
---|
| 429 | } |
---|
| 430 | |
---|
| 431 | /** parse merge flag |
---|
| 432 | * \param pcCU |
---|
| 433 | * \param uiAbsPartIdx |
---|
| 434 | * \param uiDepth |
---|
| 435 | * \param uiPUIdx |
---|
| 436 | * \returns Void |
---|
| 437 | */ |
---|
| 438 | Void TDecSbac::parseMergeFlag ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, UInt uiPUIdx ) |
---|
| 439 | { |
---|
| 440 | UInt uiSymbol; |
---|
| 441 | m_pcTDecBinIf->decodeBin( uiSymbol, *m_cCUMergeFlagExtSCModel.get( 0 ) ); |
---|
| 442 | pcCU->setMergeFlagSubParts( uiSymbol ? true : false, uiAbsPartIdx, uiPUIdx, uiDepth ); |
---|
| 443 | |
---|
| 444 | DTRACE_CABAC_VL( g_nSymbolCounter++ ); |
---|
| 445 | DTRACE_CABAC_T( "\tMergeFlag: " ); |
---|
| 446 | DTRACE_CABAC_V( uiSymbol ); |
---|
| 447 | DTRACE_CABAC_T( "\tAddress: " ); |
---|
| 448 | DTRACE_CABAC_V( pcCU->getAddr() ); |
---|
| 449 | DTRACE_CABAC_T( "\tuiAbsPartIdx: " ); |
---|
| 450 | DTRACE_CABAC_V( uiAbsPartIdx ); |
---|
| 451 | DTRACE_CABAC_T( "\n" ); |
---|
| 452 | } |
---|
| 453 | |
---|
| 454 | Void TDecSbac::parseMergeIndex ( TComDataCU* pcCU, UInt& ruiMergeIndex ) |
---|
| 455 | { |
---|
| 456 | UInt uiUnaryIdx = 0; |
---|
| 457 | UInt uiNumCand = pcCU->getSlice()->getMaxNumMergeCand(); |
---|
| 458 | if ( uiNumCand > 1 ) |
---|
| 459 | { |
---|
| 460 | for( ; uiUnaryIdx < uiNumCand - 1; ++uiUnaryIdx ) |
---|
| 461 | { |
---|
| 462 | UInt uiSymbol = 0; |
---|
| 463 | if ( uiUnaryIdx==0 ) |
---|
| 464 | { |
---|
| 465 | m_pcTDecBinIf->decodeBin( uiSymbol, m_cCUMergeIdxExtSCModel.get( 0, 0, 0 ) ); |
---|
| 466 | } |
---|
| 467 | else |
---|
| 468 | { |
---|
| 469 | m_pcTDecBinIf->decodeBinEP( uiSymbol ); |
---|
| 470 | } |
---|
| 471 | if( uiSymbol == 0 ) |
---|
| 472 | { |
---|
| 473 | break; |
---|
| 474 | } |
---|
| 475 | } |
---|
| 476 | } |
---|
| 477 | ruiMergeIndex = uiUnaryIdx; |
---|
| 478 | |
---|
| 479 | DTRACE_CABAC_VL( g_nSymbolCounter++ ) |
---|
| 480 | DTRACE_CABAC_T( "\tparseMergeIndex()" ) |
---|
| 481 | DTRACE_CABAC_T( "\tuiMRGIdx= " ) |
---|
| 482 | DTRACE_CABAC_V( ruiMergeIndex ) |
---|
| 483 | DTRACE_CABAC_T( "\n" ) |
---|
| 484 | } |
---|
| 485 | |
---|
| 486 | Void TDecSbac::parseMVPIdx ( Int& riMVPIdx ) |
---|
| 487 | { |
---|
| 488 | UInt uiSymbol; |
---|
| 489 | xReadUnaryMaxSymbol(uiSymbol, m_cMVPIdxSCModel.get(0), 1, AMVP_MAX_NUM_CANDS-1); |
---|
| 490 | riMVPIdx = uiSymbol; |
---|
| 491 | } |
---|
| 492 | |
---|
| 493 | Void TDecSbac::parseSplitFlag ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth ) |
---|
| 494 | { |
---|
| 495 | if( uiDepth == g_uiMaxCUDepth - g_uiAddCUDepth ) |
---|
| 496 | { |
---|
| 497 | pcCU->setDepthSubParts( uiDepth, uiAbsPartIdx ); |
---|
| 498 | return; |
---|
| 499 | } |
---|
| 500 | |
---|
| 501 | UInt uiSymbol; |
---|
| 502 | m_pcTDecBinIf->decodeBin( uiSymbol, m_cCUSplitFlagSCModel.get( 0, 0, pcCU->getCtxSplitFlag( uiAbsPartIdx, uiDepth ) ) ); |
---|
| 503 | DTRACE_CABAC_VL( g_nSymbolCounter++ ) |
---|
| 504 | DTRACE_CABAC_T( "\tSplitFlag\n" ) |
---|
| 505 | pcCU->setDepthSubParts( uiDepth + uiSymbol, uiAbsPartIdx ); |
---|
| 506 | |
---|
| 507 | return; |
---|
| 508 | } |
---|
| 509 | |
---|
| 510 | /** parse partition size |
---|
| 511 | * \param pcCU |
---|
| 512 | * \param uiAbsPartIdx |
---|
| 513 | * \param uiDepth |
---|
| 514 | * \returns Void |
---|
| 515 | */ |
---|
| 516 | Void TDecSbac::parsePartSize( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth ) |
---|
| 517 | { |
---|
| 518 | UInt uiSymbol, uiMode = 0; |
---|
| 519 | PartSize eMode; |
---|
[321] | 520 | |
---|
[313] | 521 | if ( pcCU->isIntra( uiAbsPartIdx ) ) |
---|
| 522 | { |
---|
| 523 | uiSymbol = 1; |
---|
| 524 | if( uiDepth == g_uiMaxCUDepth - g_uiAddCUDepth ) |
---|
| 525 | { |
---|
| 526 | m_pcTDecBinIf->decodeBin( uiSymbol, m_cCUPartSizeSCModel.get( 0, 0, 0) ); |
---|
| 527 | } |
---|
| 528 | eMode = uiSymbol ? SIZE_2Nx2N : SIZE_NxN; |
---|
| 529 | UInt uiTrLevel = 0; |
---|
| 530 | UInt uiWidthInBit = g_aucConvertToBit[pcCU->getWidth(uiAbsPartIdx)]+2; |
---|
| 531 | UInt uiTrSizeInBit = g_aucConvertToBit[pcCU->getSlice()->getSPS()->getMaxTrSize()]+2; |
---|
| 532 | uiTrLevel = uiWidthInBit >= uiTrSizeInBit ? uiWidthInBit - uiTrSizeInBit : 0; |
---|
| 533 | if( eMode == SIZE_NxN ) |
---|
| 534 | { |
---|
| 535 | pcCU->setTrIdxSubParts( 1+uiTrLevel, uiAbsPartIdx, uiDepth ); |
---|
| 536 | } |
---|
| 537 | else |
---|
| 538 | { |
---|
| 539 | pcCU->setTrIdxSubParts( uiTrLevel, uiAbsPartIdx, uiDepth ); |
---|
| 540 | } |
---|
| 541 | } |
---|
| 542 | else |
---|
| 543 | { |
---|
| 544 | UInt uiMaxNumBits = 2; |
---|
| 545 | if( uiDepth == g_uiMaxCUDepth - g_uiAddCUDepth && !( (g_uiMaxCUWidth>>uiDepth) == 8 && (g_uiMaxCUHeight>>uiDepth) == 8 ) ) |
---|
| 546 | { |
---|
| 547 | uiMaxNumBits ++; |
---|
| 548 | } |
---|
| 549 | for ( UInt ui = 0; ui < uiMaxNumBits; ui++ ) |
---|
| 550 | { |
---|
| 551 | m_pcTDecBinIf->decodeBin( uiSymbol, m_cCUPartSizeSCModel.get( 0, 0, ui) ); |
---|
| 552 | if ( uiSymbol ) |
---|
| 553 | { |
---|
| 554 | break; |
---|
| 555 | } |
---|
| 556 | uiMode++; |
---|
| 557 | } |
---|
| 558 | eMode = (PartSize) uiMode; |
---|
| 559 | if ( pcCU->getSlice()->getSPS()->getAMPAcc( uiDepth ) ) |
---|
| 560 | { |
---|
| 561 | if (eMode == SIZE_2NxN) |
---|
| 562 | { |
---|
| 563 | m_pcTDecBinIf->decodeBin(uiSymbol, m_cCUAMPSCModel.get( 0, 0, 0 )); |
---|
| 564 | if (uiSymbol == 0) |
---|
| 565 | { |
---|
| 566 | m_pcTDecBinIf->decodeBinEP(uiSymbol); |
---|
| 567 | eMode = (uiSymbol == 0? SIZE_2NxnU : SIZE_2NxnD); |
---|
| 568 | } |
---|
| 569 | } |
---|
| 570 | else if (eMode == SIZE_Nx2N) |
---|
| 571 | { |
---|
| 572 | m_pcTDecBinIf->decodeBin(uiSymbol, m_cCUAMPSCModel.get( 0, 0, 0 )); |
---|
| 573 | if (uiSymbol == 0) |
---|
| 574 | { |
---|
| 575 | m_pcTDecBinIf->decodeBinEP(uiSymbol); |
---|
| 576 | eMode = (uiSymbol == 0? SIZE_nLx2N : SIZE_nRx2N); |
---|
| 577 | } |
---|
| 578 | } |
---|
| 579 | } |
---|
| 580 | } |
---|
| 581 | pcCU->setPartSizeSubParts( eMode, uiAbsPartIdx, uiDepth ); |
---|
| 582 | pcCU->setSizeSubParts( g_uiMaxCUWidth>>uiDepth, g_uiMaxCUHeight>>uiDepth, uiAbsPartIdx, uiDepth ); |
---|
| 583 | } |
---|
| 584 | |
---|
| 585 | /** parse prediction mode |
---|
| 586 | * \param pcCU |
---|
| 587 | * \param uiAbsPartIdx |
---|
| 588 | * \param uiDepth |
---|
| 589 | * \returns Void |
---|
| 590 | */ |
---|
| 591 | Void TDecSbac::parsePredMode( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth ) |
---|
| 592 | { |
---|
| 593 | if( pcCU->getSlice()->isIntra() ) |
---|
| 594 | { |
---|
| 595 | pcCU->setPredModeSubParts( MODE_INTRA, uiAbsPartIdx, uiDepth ); |
---|
| 596 | return; |
---|
| 597 | } |
---|
| 598 | |
---|
| 599 | UInt uiSymbol; |
---|
| 600 | Int iPredMode = MODE_INTER; |
---|
| 601 | m_pcTDecBinIf->decodeBin( uiSymbol, m_cCUPredModeSCModel.get( 0, 0, 0 ) ); |
---|
| 602 | iPredMode += uiSymbol; |
---|
| 603 | pcCU->setPredModeSubParts( (PredMode)iPredMode, uiAbsPartIdx, uiDepth ); |
---|
| 604 | } |
---|
| 605 | |
---|
| 606 | Void TDecSbac::parseIntraDirLumaAng ( TComDataCU* pcCU, UInt absPartIdx, UInt depth ) |
---|
| 607 | { |
---|
| 608 | PartSize mode = pcCU->getPartitionSize( absPartIdx ); |
---|
| 609 | UInt partNum = mode==SIZE_NxN?4:1; |
---|
| 610 | UInt partOffset = ( pcCU->getPic()->getNumPartInCU() >> ( pcCU->getDepth(absPartIdx) << 1 ) ) >> 2; |
---|
| 611 | UInt mpmPred[4],symbol; |
---|
| 612 | Int j,intraPredMode; |
---|
| 613 | if (mode==SIZE_NxN) |
---|
| 614 | { |
---|
| 615 | depth++; |
---|
| 616 | } |
---|
| 617 | for (j=0;j<partNum;j++) |
---|
| 618 | { |
---|
| 619 | m_pcTDecBinIf->decodeBin( symbol, m_cCUIntraPredSCModel.get( 0, 0, 0) ); |
---|
| 620 | mpmPred[j] = symbol; |
---|
| 621 | } |
---|
| 622 | for (j=0;j<partNum;j++) |
---|
| 623 | { |
---|
| 624 | Int preds[3] = {-1, -1, -1}; |
---|
| 625 | Int predNum = pcCU->getIntraDirLumaPredictor(absPartIdx+partOffset*j, preds); |
---|
| 626 | if (mpmPred[j]) |
---|
| 627 | { |
---|
| 628 | m_pcTDecBinIf->decodeBinEP( symbol ); |
---|
| 629 | if (symbol) |
---|
| 630 | { |
---|
| 631 | m_pcTDecBinIf->decodeBinEP( symbol ); |
---|
| 632 | symbol++; |
---|
| 633 | } |
---|
| 634 | intraPredMode = preds[symbol]; |
---|
| 635 | } |
---|
| 636 | else |
---|
| 637 | { |
---|
| 638 | m_pcTDecBinIf->decodeBinsEP( symbol, 5 ); |
---|
| 639 | intraPredMode = symbol; |
---|
| 640 | |
---|
| 641 | //postponed sorting of MPMs (only in remaining branch) |
---|
| 642 | if (preds[0] > preds[1]) |
---|
| 643 | { |
---|
| 644 | std::swap(preds[0], preds[1]); |
---|
| 645 | } |
---|
| 646 | if (preds[0] > preds[2]) |
---|
| 647 | { |
---|
| 648 | std::swap(preds[0], preds[2]); |
---|
| 649 | } |
---|
| 650 | if (preds[1] > preds[2]) |
---|
| 651 | { |
---|
| 652 | std::swap(preds[1], preds[2]); |
---|
| 653 | } |
---|
| 654 | for ( Int i = 0; i < predNum; i++ ) |
---|
| 655 | { |
---|
| 656 | intraPredMode += ( intraPredMode >= preds[i] ); |
---|
| 657 | } |
---|
| 658 | } |
---|
| 659 | pcCU->setLumaIntraDirSubParts( (UChar)intraPredMode, absPartIdx+partOffset*j, depth ); |
---|
| 660 | } |
---|
| 661 | } |
---|
| 662 | |
---|
| 663 | Void TDecSbac::parseIntraDirChroma( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth ) |
---|
| 664 | { |
---|
| 665 | UInt uiSymbol; |
---|
| 666 | |
---|
| 667 | m_pcTDecBinIf->decodeBin( uiSymbol, m_cCUChromaPredSCModel.get( 0, 0, 0 ) ); |
---|
| 668 | |
---|
| 669 | if( uiSymbol == 0 ) |
---|
| 670 | { |
---|
| 671 | uiSymbol = DM_CHROMA_IDX; |
---|
| 672 | } |
---|
| 673 | else |
---|
| 674 | { |
---|
| 675 | { |
---|
| 676 | UInt uiIPredMode; |
---|
| 677 | m_pcTDecBinIf->decodeBinsEP( uiIPredMode, 2 ); |
---|
| 678 | UInt uiAllowedChromaDir[ NUM_CHROMA_MODE ]; |
---|
| 679 | pcCU->getAllowedChromaDir( uiAbsPartIdx, uiAllowedChromaDir ); |
---|
| 680 | uiSymbol = uiAllowedChromaDir[ uiIPredMode ]; |
---|
| 681 | } |
---|
| 682 | } |
---|
| 683 | pcCU->setChromIntraDirSubParts( uiSymbol, uiAbsPartIdx, uiDepth ); |
---|
| 684 | return; |
---|
| 685 | } |
---|
| 686 | |
---|
| 687 | Void TDecSbac::parseInterDir( TComDataCU* pcCU, UInt& ruiInterDir, UInt uiAbsPartIdx ) |
---|
| 688 | { |
---|
| 689 | UInt uiSymbol; |
---|
| 690 | const UInt uiCtx = pcCU->getCtxInterDir( uiAbsPartIdx ); |
---|
| 691 | ContextModel *pCtx = m_cCUInterDirSCModel.get( 0 ); |
---|
| 692 | uiSymbol = 0; |
---|
| 693 | if (pcCU->getPartitionSize(uiAbsPartIdx) == SIZE_2Nx2N || pcCU->getHeight(uiAbsPartIdx) != 8 ) |
---|
| 694 | { |
---|
| 695 | m_pcTDecBinIf->decodeBin( uiSymbol, *( pCtx + uiCtx ) ); |
---|
| 696 | } |
---|
| 697 | |
---|
| 698 | if( uiSymbol ) |
---|
| 699 | { |
---|
| 700 | uiSymbol = 2; |
---|
| 701 | } |
---|
| 702 | else |
---|
| 703 | { |
---|
| 704 | m_pcTDecBinIf->decodeBin( uiSymbol, *( pCtx + 4 ) ); |
---|
| 705 | assert(uiSymbol == 0 || uiSymbol == 1); |
---|
| 706 | } |
---|
| 707 | |
---|
| 708 | uiSymbol++; |
---|
| 709 | ruiInterDir = uiSymbol; |
---|
| 710 | return; |
---|
| 711 | } |
---|
| 712 | |
---|
| 713 | Void TDecSbac::parseRefFrmIdx( TComDataCU* pcCU, Int& riRefFrmIdx, RefPicList eRefList ) |
---|
| 714 | { |
---|
| 715 | UInt uiSymbol; |
---|
| 716 | { |
---|
| 717 | ContextModel *pCtx = m_cCURefPicSCModel.get( 0 ); |
---|
| 718 | m_pcTDecBinIf->decodeBin( uiSymbol, *pCtx ); |
---|
| 719 | |
---|
| 720 | if( uiSymbol ) |
---|
| 721 | { |
---|
| 722 | UInt uiRefNum = pcCU->getSlice()->getNumRefIdx( eRefList ) - 2; |
---|
| 723 | pCtx++; |
---|
| 724 | UInt ui; |
---|
| 725 | for( ui = 0; ui < uiRefNum; ++ui ) |
---|
| 726 | { |
---|
| 727 | if( ui == 0 ) |
---|
| 728 | { |
---|
| 729 | m_pcTDecBinIf->decodeBin( uiSymbol, *pCtx ); |
---|
| 730 | } |
---|
| 731 | else |
---|
| 732 | { |
---|
| 733 | m_pcTDecBinIf->decodeBinEP( uiSymbol ); |
---|
| 734 | } |
---|
| 735 | if( uiSymbol == 0 ) |
---|
| 736 | { |
---|
| 737 | break; |
---|
| 738 | } |
---|
| 739 | } |
---|
| 740 | uiSymbol = ui + 1; |
---|
| 741 | } |
---|
| 742 | riRefFrmIdx = uiSymbol; |
---|
| 743 | } |
---|
| 744 | |
---|
| 745 | return; |
---|
| 746 | } |
---|
| 747 | |
---|
| 748 | Void TDecSbac::parseMvd( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiPartIdx, UInt uiDepth, RefPicList eRefList ) |
---|
| 749 | { |
---|
| 750 | UInt uiSymbol; |
---|
| 751 | UInt uiHorAbs; |
---|
| 752 | UInt uiVerAbs; |
---|
| 753 | UInt uiHorSign = 0; |
---|
| 754 | UInt uiVerSign = 0; |
---|
| 755 | ContextModel *pCtx = m_cCUMvdSCModel.get( 0 ); |
---|
| 756 | |
---|
| 757 | if(pcCU->getSlice()->getMvdL1ZeroFlag() && eRefList == REF_PIC_LIST_1 && pcCU->getInterDir(uiAbsPartIdx)==3) |
---|
| 758 | { |
---|
| 759 | uiHorAbs=0; |
---|
| 760 | uiVerAbs=0; |
---|
| 761 | } |
---|
| 762 | else |
---|
| 763 | { |
---|
| 764 | m_pcTDecBinIf->decodeBin( uiHorAbs, *pCtx ); |
---|
| 765 | m_pcTDecBinIf->decodeBin( uiVerAbs, *pCtx ); |
---|
| 766 | |
---|
| 767 | const Bool bHorAbsGr0 = uiHorAbs != 0; |
---|
| 768 | const Bool bVerAbsGr0 = uiVerAbs != 0; |
---|
| 769 | pCtx++; |
---|
| 770 | |
---|
| 771 | if( bHorAbsGr0 ) |
---|
| 772 | { |
---|
| 773 | m_pcTDecBinIf->decodeBin( uiSymbol, *pCtx ); |
---|
| 774 | uiHorAbs += uiSymbol; |
---|
| 775 | } |
---|
| 776 | |
---|
| 777 | if( bVerAbsGr0 ) |
---|
| 778 | { |
---|
| 779 | m_pcTDecBinIf->decodeBin( uiSymbol, *pCtx ); |
---|
| 780 | uiVerAbs += uiSymbol; |
---|
| 781 | } |
---|
| 782 | |
---|
| 783 | if( bHorAbsGr0 ) |
---|
| 784 | { |
---|
| 785 | if( 2 == uiHorAbs ) |
---|
| 786 | { |
---|
| 787 | xReadEpExGolomb( uiSymbol, 1 ); |
---|
| 788 | uiHorAbs += uiSymbol; |
---|
| 789 | } |
---|
| 790 | |
---|
| 791 | m_pcTDecBinIf->decodeBinEP( uiHorSign ); |
---|
| 792 | } |
---|
| 793 | |
---|
| 794 | if( bVerAbsGr0 ) |
---|
| 795 | { |
---|
| 796 | if( 2 == uiVerAbs ) |
---|
| 797 | { |
---|
| 798 | xReadEpExGolomb( uiSymbol, 1 ); |
---|
| 799 | uiVerAbs += uiSymbol; |
---|
| 800 | } |
---|
| 801 | |
---|
| 802 | m_pcTDecBinIf->decodeBinEP( uiVerSign ); |
---|
| 803 | } |
---|
| 804 | |
---|
| 805 | } |
---|
| 806 | |
---|
| 807 | const TComMv cMv( uiHorSign ? -Int( uiHorAbs ): uiHorAbs, uiVerSign ? -Int( uiVerAbs ) : uiVerAbs ); |
---|
| 808 | pcCU->getCUMvField( eRefList )->setAllMvd( cMv, pcCU->getPartitionSize( uiAbsPartIdx ), uiAbsPartIdx, uiDepth, uiPartIdx ); |
---|
| 809 | return; |
---|
| 810 | } |
---|
| 811 | |
---|
| 812 | |
---|
| 813 | Void TDecSbac::parseTransformSubdivFlag( UInt& ruiSubdivFlag, UInt uiLog2TransformBlockSize ) |
---|
| 814 | { |
---|
| 815 | m_pcTDecBinIf->decodeBin( ruiSubdivFlag, m_cCUTransSubdivFlagSCModel.get( 0, 0, uiLog2TransformBlockSize ) ); |
---|
| 816 | DTRACE_CABAC_VL( g_nSymbolCounter++ ) |
---|
| 817 | DTRACE_CABAC_T( "\tparseTransformSubdivFlag()" ) |
---|
| 818 | DTRACE_CABAC_T( "\tsymbol=" ) |
---|
| 819 | DTRACE_CABAC_V( ruiSubdivFlag ) |
---|
| 820 | DTRACE_CABAC_T( "\tctx=" ) |
---|
| 821 | DTRACE_CABAC_V( uiLog2TransformBlockSize ) |
---|
| 822 | DTRACE_CABAC_T( "\n" ) |
---|
| 823 | } |
---|
| 824 | |
---|
| 825 | Void TDecSbac::parseQtRootCbf( UInt uiAbsPartIdx, UInt& uiQtRootCbf ) |
---|
| 826 | { |
---|
| 827 | UInt uiSymbol; |
---|
| 828 | const UInt uiCtx = 0; |
---|
| 829 | m_pcTDecBinIf->decodeBin( uiSymbol , m_cCUQtRootCbfSCModel.get( 0, 0, uiCtx ) ); |
---|
| 830 | DTRACE_CABAC_VL( g_nSymbolCounter++ ) |
---|
| 831 | DTRACE_CABAC_T( "\tparseQtRootCbf()" ) |
---|
| 832 | DTRACE_CABAC_T( "\tsymbol=" ) |
---|
| 833 | DTRACE_CABAC_V( uiSymbol ) |
---|
| 834 | DTRACE_CABAC_T( "\tctx=" ) |
---|
| 835 | DTRACE_CABAC_V( uiCtx ) |
---|
| 836 | DTRACE_CABAC_T( "\tuiAbsPartIdx=" ) |
---|
| 837 | DTRACE_CABAC_V( uiAbsPartIdx ) |
---|
| 838 | DTRACE_CABAC_T( "\n" ) |
---|
| 839 | |
---|
| 840 | uiQtRootCbf = uiSymbol; |
---|
| 841 | } |
---|
| 842 | |
---|
| 843 | Void TDecSbac::parseDeltaQP( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth ) |
---|
| 844 | { |
---|
| 845 | Int qp; |
---|
| 846 | UInt uiDQp; |
---|
| 847 | Int iDQp; |
---|
| 848 | |
---|
| 849 | UInt uiSymbol; |
---|
| 850 | |
---|
| 851 | xReadUnaryMaxSymbol (uiDQp, &m_cCUDeltaQpSCModel.get( 0, 0, 0 ), 1, CU_DQP_TU_CMAX); |
---|
| 852 | |
---|
| 853 | if( uiDQp >= CU_DQP_TU_CMAX) |
---|
| 854 | { |
---|
| 855 | xReadEpExGolomb( uiSymbol, CU_DQP_EG_k ); |
---|
| 856 | uiDQp+=uiSymbol; |
---|
| 857 | } |
---|
| 858 | |
---|
| 859 | if ( uiDQp > 0 ) |
---|
| 860 | { |
---|
| 861 | UInt uiSign; |
---|
| 862 | Int qpBdOffsetY = pcCU->getSlice()->getSPS()->getQpBDOffsetY(); |
---|
| 863 | m_pcTDecBinIf->decodeBinEP(uiSign); |
---|
| 864 | iDQp = uiDQp; |
---|
| 865 | if(uiSign) |
---|
| 866 | { |
---|
| 867 | iDQp = -iDQp; |
---|
| 868 | } |
---|
| 869 | qp = (((Int) pcCU->getRefQP( uiAbsPartIdx ) + iDQp + 52 + 2*qpBdOffsetY )%(52+qpBdOffsetY)) - qpBdOffsetY; |
---|
| 870 | } |
---|
| 871 | else |
---|
| 872 | { |
---|
| 873 | qp = pcCU->getRefQP(uiAbsPartIdx); |
---|
| 874 | } |
---|
| 875 | pcCU->setQPSubParts(qp, uiAbsPartIdx, uiDepth); |
---|
| 876 | pcCU->setCodedQP(qp); |
---|
| 877 | } |
---|
| 878 | |
---|
| 879 | Void TDecSbac::parseQtCbf( TComDataCU* pcCU, UInt uiAbsPartIdx, TextType eType, UInt uiTrDepth, UInt uiDepth ) |
---|
| 880 | { |
---|
| 881 | UInt uiSymbol; |
---|
| 882 | const UInt uiCtx = pcCU->getCtxQtCbf( eType, uiTrDepth ); |
---|
| 883 | m_pcTDecBinIf->decodeBin( uiSymbol , m_cCUQtCbfSCModel.get( 0, eType ? TEXT_CHROMA: eType, uiCtx ) ); |
---|
| 884 | |
---|
| 885 | DTRACE_CABAC_VL( g_nSymbolCounter++ ) |
---|
| 886 | DTRACE_CABAC_T( "\tparseQtCbf()" ) |
---|
| 887 | DTRACE_CABAC_T( "\tsymbol=" ) |
---|
| 888 | DTRACE_CABAC_V( uiSymbol ) |
---|
| 889 | DTRACE_CABAC_T( "\tctx=" ) |
---|
| 890 | DTRACE_CABAC_V( uiCtx ) |
---|
| 891 | DTRACE_CABAC_T( "\tetype=" ) |
---|
| 892 | DTRACE_CABAC_V( eType ) |
---|
| 893 | DTRACE_CABAC_T( "\tuiAbsPartIdx=" ) |
---|
| 894 | DTRACE_CABAC_V( uiAbsPartIdx ) |
---|
| 895 | DTRACE_CABAC_T( "\n" ) |
---|
| 896 | |
---|
| 897 | pcCU->setCbfSubParts( uiSymbol << uiTrDepth, eType, uiAbsPartIdx, uiDepth ); |
---|
| 898 | } |
---|
| 899 | |
---|
| 900 | void TDecSbac::parseTransformSkipFlags (TComDataCU* pcCU, UInt uiAbsPartIdx, UInt width, UInt height, UInt uiDepth, TextType eTType) |
---|
| 901 | { |
---|
| 902 | if (pcCU->getCUTransquantBypass(uiAbsPartIdx)) |
---|
| 903 | { |
---|
| 904 | return; |
---|
| 905 | } |
---|
| 906 | if(width != 4 || height != 4) |
---|
| 907 | { |
---|
| 908 | return; |
---|
| 909 | } |
---|
| 910 | |
---|
| 911 | UInt useTransformSkip; |
---|
| 912 | m_pcTDecBinIf->decodeBin( useTransformSkip , m_cTransformSkipSCModel.get( 0, eTType? TEXT_CHROMA: TEXT_LUMA, 0 ) ); |
---|
| 913 | if(eTType!= TEXT_LUMA) |
---|
| 914 | { |
---|
| 915 | const UInt uiLog2TrafoSize = g_aucConvertToBit[pcCU->getSlice()->getSPS()->getMaxCUWidth()] + 2 - uiDepth; |
---|
| 916 | if(uiLog2TrafoSize == 2) |
---|
| 917 | { |
---|
| 918 | uiDepth --; |
---|
| 919 | } |
---|
| 920 | } |
---|
| 921 | DTRACE_CABAC_VL( g_nSymbolCounter++ ) |
---|
| 922 | DTRACE_CABAC_T("\tparseTransformSkip()"); |
---|
| 923 | DTRACE_CABAC_T( "\tsymbol=" ) |
---|
| 924 | DTRACE_CABAC_V( useTransformSkip ) |
---|
| 925 | DTRACE_CABAC_T( "\tAddr=" ) |
---|
| 926 | DTRACE_CABAC_V( pcCU->getAddr() ) |
---|
| 927 | DTRACE_CABAC_T( "\tetype=" ) |
---|
| 928 | DTRACE_CABAC_V( eTType ) |
---|
| 929 | DTRACE_CABAC_T( "\tuiAbsPartIdx=" ) |
---|
| 930 | DTRACE_CABAC_V( uiAbsPartIdx ) |
---|
| 931 | DTRACE_CABAC_T( "\n" ) |
---|
| 932 | |
---|
| 933 | pcCU->setTransformSkipSubParts( useTransformSkip, eTType, uiAbsPartIdx, uiDepth); |
---|
| 934 | } |
---|
| 935 | |
---|
| 936 | /** Parse (X,Y) position of the last significant coefficient |
---|
| 937 | * \param uiPosLastX reference to X component of last coefficient |
---|
| 938 | * \param uiPosLastY reference to Y component of last coefficient |
---|
| 939 | * \param width Block width |
---|
| 940 | * \param height Block height |
---|
| 941 | * \param eTType plane type / luminance or chrominance |
---|
| 942 | * \param uiScanIdx scan type (zig-zag, hor, ver) |
---|
| 943 | * |
---|
| 944 | * This method decodes the X and Y component within a block of the last significant coefficient. |
---|
| 945 | */ |
---|
| 946 | Void TDecSbac::parseLastSignificantXY( UInt& uiPosLastX, UInt& uiPosLastY, Int width, Int height, TextType eTType, UInt uiScanIdx ) |
---|
| 947 | { |
---|
| 948 | UInt uiLast; |
---|
| 949 | ContextModel *pCtxX = m_cCuCtxLastX.get( 0, eTType ); |
---|
| 950 | ContextModel *pCtxY = m_cCuCtxLastY.get( 0, eTType ); |
---|
| 951 | |
---|
| 952 | Int blkSizeOffsetX, blkSizeOffsetY, shiftX, shiftY; |
---|
| 953 | blkSizeOffsetX = eTType ? 0: (g_aucConvertToBit[ width ] *3 + ((g_aucConvertToBit[ width ] +1)>>2)); |
---|
| 954 | blkSizeOffsetY = eTType ? 0: (g_aucConvertToBit[ height ]*3 + ((g_aucConvertToBit[ height ]+1)>>2)); |
---|
| 955 | shiftX= eTType ? g_aucConvertToBit[ width ] :((g_aucConvertToBit[ width ]+3)>>2); |
---|
| 956 | shiftY= eTType ? g_aucConvertToBit[ height ] :((g_aucConvertToBit[ height ]+3)>>2); |
---|
| 957 | // posX |
---|
| 958 | for( uiPosLastX = 0; uiPosLastX < g_uiGroupIdx[ width - 1 ]; uiPosLastX++ ) |
---|
| 959 | { |
---|
| 960 | m_pcTDecBinIf->decodeBin( uiLast, *( pCtxX + blkSizeOffsetX + (uiPosLastX >>shiftX) ) ); |
---|
| 961 | if( !uiLast ) |
---|
| 962 | { |
---|
| 963 | break; |
---|
| 964 | } |
---|
| 965 | } |
---|
| 966 | |
---|
| 967 | // posY |
---|
| 968 | for( uiPosLastY = 0; uiPosLastY < g_uiGroupIdx[ height - 1 ]; uiPosLastY++ ) |
---|
| 969 | { |
---|
| 970 | m_pcTDecBinIf->decodeBin( uiLast, *( pCtxY + blkSizeOffsetY + (uiPosLastY >>shiftY)) ); |
---|
| 971 | if( !uiLast ) |
---|
| 972 | { |
---|
| 973 | break; |
---|
| 974 | } |
---|
| 975 | } |
---|
| 976 | if ( uiPosLastX > 3 ) |
---|
| 977 | { |
---|
| 978 | UInt uiTemp = 0; |
---|
| 979 | UInt uiCount = ( uiPosLastX - 2 ) >> 1; |
---|
| 980 | for ( Int i = uiCount - 1; i >= 0; i-- ) |
---|
| 981 | { |
---|
| 982 | m_pcTDecBinIf->decodeBinEP( uiLast ); |
---|
| 983 | uiTemp += uiLast << i; |
---|
| 984 | } |
---|
| 985 | uiPosLastX = g_uiMinInGroup[ uiPosLastX ] + uiTemp; |
---|
| 986 | } |
---|
| 987 | if ( uiPosLastY > 3 ) |
---|
| 988 | { |
---|
| 989 | UInt uiTemp = 0; |
---|
| 990 | UInt uiCount = ( uiPosLastY - 2 ) >> 1; |
---|
| 991 | for ( Int i = uiCount - 1; i >= 0; i-- ) |
---|
| 992 | { |
---|
| 993 | m_pcTDecBinIf->decodeBinEP( uiLast ); |
---|
| 994 | uiTemp += uiLast << i; |
---|
| 995 | } |
---|
| 996 | uiPosLastY = g_uiMinInGroup[ uiPosLastY ] + uiTemp; |
---|
| 997 | } |
---|
| 998 | |
---|
| 999 | if( uiScanIdx == SCAN_VER ) |
---|
| 1000 | { |
---|
| 1001 | swap( uiPosLastX, uiPosLastY ); |
---|
| 1002 | } |
---|
| 1003 | } |
---|
| 1004 | |
---|
| 1005 | Void TDecSbac::parseCoeffNxN( TComDataCU* pcCU, TCoeff* pcCoef, UInt uiAbsPartIdx, UInt uiWidth, UInt uiHeight, UInt uiDepth, TextType eTType ) |
---|
| 1006 | { |
---|
| 1007 | DTRACE_CABAC_VL( g_nSymbolCounter++ ) |
---|
| 1008 | DTRACE_CABAC_T( "\tparseCoeffNxN()\teType=" ) |
---|
| 1009 | DTRACE_CABAC_V( eTType ) |
---|
| 1010 | DTRACE_CABAC_T( "\twidth=" ) |
---|
| 1011 | DTRACE_CABAC_V( uiWidth ) |
---|
| 1012 | DTRACE_CABAC_T( "\theight=" ) |
---|
| 1013 | DTRACE_CABAC_V( uiHeight ) |
---|
| 1014 | DTRACE_CABAC_T( "\tdepth=" ) |
---|
| 1015 | DTRACE_CABAC_V( uiDepth ) |
---|
| 1016 | DTRACE_CABAC_T( "\tabspartidx=" ) |
---|
| 1017 | DTRACE_CABAC_V( uiAbsPartIdx ) |
---|
| 1018 | DTRACE_CABAC_T( "\ttoCU-X=" ) |
---|
| 1019 | DTRACE_CABAC_V( pcCU->getCUPelX() ) |
---|
| 1020 | DTRACE_CABAC_T( "\ttoCU-Y=" ) |
---|
| 1021 | DTRACE_CABAC_V( pcCU->getCUPelY() ) |
---|
| 1022 | DTRACE_CABAC_T( "\tCU-addr=" ) |
---|
| 1023 | DTRACE_CABAC_V( pcCU->getAddr() ) |
---|
| 1024 | DTRACE_CABAC_T( "\tinCU-X=" ) |
---|
| 1025 | DTRACE_CABAC_V( g_auiRasterToPelX[ g_auiZscanToRaster[uiAbsPartIdx] ] ) |
---|
| 1026 | DTRACE_CABAC_T( "\tinCU-Y=" ) |
---|
| 1027 | DTRACE_CABAC_V( g_auiRasterToPelY[ g_auiZscanToRaster[uiAbsPartIdx] ] ) |
---|
| 1028 | DTRACE_CABAC_T( "\tpredmode=" ) |
---|
| 1029 | DTRACE_CABAC_V( pcCU->getPredictionMode( uiAbsPartIdx ) ) |
---|
| 1030 | DTRACE_CABAC_T( "\n" ) |
---|
| 1031 | |
---|
| 1032 | if( uiWidth > pcCU->getSlice()->getSPS()->getMaxTrSize() ) |
---|
| 1033 | { |
---|
| 1034 | uiWidth = pcCU->getSlice()->getSPS()->getMaxTrSize(); |
---|
| 1035 | uiHeight = pcCU->getSlice()->getSPS()->getMaxTrSize(); |
---|
| 1036 | } |
---|
| 1037 | if(pcCU->getSlice()->getPPS()->getUseTransformSkip()) |
---|
| 1038 | { |
---|
| 1039 | parseTransformSkipFlags( pcCU, uiAbsPartIdx, uiWidth, uiHeight, uiDepth, eTType); |
---|
| 1040 | } |
---|
| 1041 | |
---|
| 1042 | eTType = eTType == TEXT_LUMA ? TEXT_LUMA : ( eTType == TEXT_NONE ? TEXT_NONE : TEXT_CHROMA ); |
---|
| 1043 | |
---|
| 1044 | //----- parse significance map ----- |
---|
| 1045 | const UInt uiLog2BlockSize = g_aucConvertToBit[ uiWidth ] + 2; |
---|
| 1046 | const UInt uiMaxNumCoeff = uiWidth * uiHeight; |
---|
| 1047 | const UInt uiMaxNumCoeffM1 = uiMaxNumCoeff - 1; |
---|
| 1048 | UInt uiScanIdx = pcCU->getCoefScanIdx(uiAbsPartIdx, uiWidth, eTType==TEXT_LUMA, pcCU->isIntra(uiAbsPartIdx)); |
---|
| 1049 | |
---|
| 1050 | //===== decode last significant ===== |
---|
| 1051 | UInt uiPosLastX, uiPosLastY; |
---|
| 1052 | parseLastSignificantXY( uiPosLastX, uiPosLastY, uiWidth, uiHeight, eTType, uiScanIdx ); |
---|
| 1053 | UInt uiBlkPosLast = uiPosLastX + (uiPosLastY<<uiLog2BlockSize); |
---|
| 1054 | pcCoef[ uiBlkPosLast ] = 1; |
---|
| 1055 | |
---|
| 1056 | //===== decode significance flags ===== |
---|
| 1057 | UInt uiScanPosLast; |
---|
| 1058 | const UInt *scan = g_auiSigLastScan[ uiScanIdx ][ uiLog2BlockSize-1 ]; |
---|
| 1059 | for( uiScanPosLast = 0; uiScanPosLast < uiMaxNumCoeffM1; uiScanPosLast++ ) |
---|
| 1060 | { |
---|
| 1061 | UInt uiBlkPos = scan[ uiScanPosLast ]; |
---|
| 1062 | if( uiBlkPosLast == uiBlkPos ) |
---|
| 1063 | { |
---|
| 1064 | break; |
---|
| 1065 | } |
---|
| 1066 | } |
---|
| 1067 | |
---|
| 1068 | ContextModel * const baseCoeffGroupCtx = m_cCUSigCoeffGroupSCModel.get( 0, eTType ); |
---|
| 1069 | ContextModel * const baseCtx = (eTType==TEXT_LUMA) ? m_cCUSigSCModel.get( 0, 0 ) : m_cCUSigSCModel.get( 0, 0 ) + NUM_SIG_FLAG_CTX_LUMA; |
---|
| 1070 | |
---|
| 1071 | const Int iLastScanSet = uiScanPosLast >> LOG2_SCAN_SET_SIZE; |
---|
| 1072 | UInt c1 = 1; |
---|
| 1073 | UInt uiGoRiceParam = 0; |
---|
| 1074 | |
---|
| 1075 | Bool beValid; |
---|
| 1076 | if (pcCU->getCUTransquantBypass(uiAbsPartIdx)) |
---|
| 1077 | { |
---|
| 1078 | beValid = false; |
---|
| 1079 | } |
---|
| 1080 | else |
---|
| 1081 | { |
---|
| 1082 | beValid = pcCU->getSlice()->getPPS()->getSignHideFlag() > 0; |
---|
| 1083 | } |
---|
| 1084 | UInt absSum = 0; |
---|
| 1085 | |
---|
| 1086 | UInt uiSigCoeffGroupFlag[ MLS_GRP_NUM ]; |
---|
| 1087 | ::memset( uiSigCoeffGroupFlag, 0, sizeof(UInt) * MLS_GRP_NUM ); |
---|
| 1088 | const UInt uiNumBlkSide = uiWidth >> (MLS_CG_SIZE >> 1); |
---|
| 1089 | const UInt * scanCG; |
---|
| 1090 | { |
---|
| 1091 | scanCG = g_auiSigLastScan[ uiScanIdx ][ uiLog2BlockSize > 3 ? uiLog2BlockSize-2-1 : 0 ]; |
---|
| 1092 | if( uiLog2BlockSize == 3 ) |
---|
| 1093 | { |
---|
| 1094 | scanCG = g_sigLastScan8x8[ uiScanIdx ]; |
---|
| 1095 | } |
---|
| 1096 | else if( uiLog2BlockSize == 5 ) |
---|
| 1097 | { |
---|
| 1098 | scanCG = g_sigLastScanCG32x32; |
---|
| 1099 | } |
---|
| 1100 | } |
---|
| 1101 | Int iScanPosSig = (Int) uiScanPosLast; |
---|
| 1102 | for( Int iSubSet = iLastScanSet; iSubSet >= 0; iSubSet-- ) |
---|
| 1103 | { |
---|
| 1104 | Int iSubPos = iSubSet << LOG2_SCAN_SET_SIZE; |
---|
| 1105 | uiGoRiceParam = 0; |
---|
| 1106 | Int numNonZero = 0; |
---|
| 1107 | |
---|
| 1108 | Int lastNZPosInCG = -1, firstNZPosInCG = SCAN_SET_SIZE; |
---|
| 1109 | |
---|
| 1110 | Int pos[SCAN_SET_SIZE]; |
---|
| 1111 | if( iScanPosSig == (Int) uiScanPosLast ) |
---|
| 1112 | { |
---|
| 1113 | lastNZPosInCG = iScanPosSig; |
---|
| 1114 | firstNZPosInCG = iScanPosSig; |
---|
| 1115 | iScanPosSig--; |
---|
| 1116 | pos[ numNonZero ] = uiBlkPosLast; |
---|
| 1117 | numNonZero = 1; |
---|
| 1118 | } |
---|
| 1119 | |
---|
| 1120 | // decode significant_coeffgroup_flag |
---|
| 1121 | Int iCGBlkPos = scanCG[ iSubSet ]; |
---|
| 1122 | Int iCGPosY = iCGBlkPos / uiNumBlkSide; |
---|
| 1123 | Int iCGPosX = iCGBlkPos - (iCGPosY * uiNumBlkSide); |
---|
| 1124 | if( iSubSet == iLastScanSet || iSubSet == 0) |
---|
| 1125 | { |
---|
| 1126 | uiSigCoeffGroupFlag[ iCGBlkPos ] = 1; |
---|
| 1127 | } |
---|
| 1128 | else |
---|
| 1129 | { |
---|
| 1130 | UInt uiSigCoeffGroup; |
---|
| 1131 | UInt uiCtxSig = TComTrQuant::getSigCoeffGroupCtxInc( uiSigCoeffGroupFlag, iCGPosX, iCGPosY, uiWidth, uiHeight ); |
---|
| 1132 | m_pcTDecBinIf->decodeBin( uiSigCoeffGroup, baseCoeffGroupCtx[ uiCtxSig ] ); |
---|
| 1133 | uiSigCoeffGroupFlag[ iCGBlkPos ] = uiSigCoeffGroup; |
---|
| 1134 | } |
---|
| 1135 | |
---|
| 1136 | // decode significant_coeff_flag |
---|
| 1137 | Int patternSigCtx = TComTrQuant::calcPatternSigCtx( uiSigCoeffGroupFlag, iCGPosX, iCGPosY, uiWidth, uiHeight ); |
---|
| 1138 | UInt uiBlkPos, uiPosY, uiPosX, uiSig, uiCtxSig; |
---|
| 1139 | for( ; iScanPosSig >= iSubPos; iScanPosSig-- ) |
---|
| 1140 | { |
---|
| 1141 | uiBlkPos = scan[ iScanPosSig ]; |
---|
| 1142 | uiPosY = uiBlkPos >> uiLog2BlockSize; |
---|
| 1143 | uiPosX = uiBlkPos - ( uiPosY << uiLog2BlockSize ); |
---|
| 1144 | uiSig = 0; |
---|
| 1145 | |
---|
| 1146 | if( uiSigCoeffGroupFlag[ iCGBlkPos ] ) |
---|
| 1147 | { |
---|
| 1148 | if( iScanPosSig > iSubPos || iSubSet == 0 || numNonZero ) |
---|
| 1149 | { |
---|
| 1150 | uiCtxSig = TComTrQuant::getSigCtxInc( patternSigCtx, uiScanIdx, uiPosX, uiPosY, uiLog2BlockSize, eTType ); |
---|
| 1151 | m_pcTDecBinIf->decodeBin( uiSig, baseCtx[ uiCtxSig ] ); |
---|
| 1152 | } |
---|
| 1153 | else |
---|
| 1154 | { |
---|
| 1155 | uiSig = 1; |
---|
| 1156 | } |
---|
| 1157 | } |
---|
| 1158 | pcCoef[ uiBlkPos ] = uiSig; |
---|
| 1159 | if( uiSig ) |
---|
| 1160 | { |
---|
| 1161 | pos[ numNonZero ] = uiBlkPos; |
---|
| 1162 | numNonZero ++; |
---|
| 1163 | if( lastNZPosInCG == -1 ) |
---|
| 1164 | { |
---|
| 1165 | lastNZPosInCG = iScanPosSig; |
---|
| 1166 | } |
---|
| 1167 | firstNZPosInCG = iScanPosSig; |
---|
| 1168 | } |
---|
| 1169 | } |
---|
| 1170 | |
---|
| 1171 | if( numNonZero ) |
---|
| 1172 | { |
---|
| 1173 | Bool signHidden = ( lastNZPosInCG - firstNZPosInCG >= SBH_THRESHOLD ); |
---|
| 1174 | absSum = 0; |
---|
| 1175 | UInt uiCtxSet = (iSubSet > 0 && eTType==TEXT_LUMA) ? 2 : 0; |
---|
| 1176 | UInt uiBin; |
---|
| 1177 | if( c1 == 0 ) |
---|
| 1178 | { |
---|
| 1179 | uiCtxSet++; |
---|
| 1180 | } |
---|
| 1181 | c1 = 1; |
---|
| 1182 | ContextModel *baseCtxMod = ( eTType==TEXT_LUMA ) ? m_cCUOneSCModel.get( 0, 0 ) + 4 * uiCtxSet : m_cCUOneSCModel.get( 0, 0 ) + NUM_ONE_FLAG_CTX_LUMA + 4 * uiCtxSet; |
---|
| 1183 | Int absCoeff[SCAN_SET_SIZE]; |
---|
| 1184 | |
---|
| 1185 | for ( Int i = 0; i < numNonZero; i++) absCoeff[i] = 1; |
---|
| 1186 | Int numC1Flag = min(numNonZero, C1FLAG_NUMBER); |
---|
| 1187 | Int firstC2FlagIdx = -1; |
---|
| 1188 | |
---|
| 1189 | for( Int idx = 0; idx < numC1Flag; idx++ ) |
---|
| 1190 | { |
---|
| 1191 | m_pcTDecBinIf->decodeBin( uiBin, baseCtxMod[c1] ); |
---|
| 1192 | if( uiBin == 1 ) |
---|
| 1193 | { |
---|
| 1194 | c1 = 0; |
---|
| 1195 | if (firstC2FlagIdx == -1) |
---|
| 1196 | { |
---|
| 1197 | firstC2FlagIdx = idx; |
---|
| 1198 | } |
---|
| 1199 | } |
---|
| 1200 | else if( (c1 < 3) && (c1 > 0) ) |
---|
| 1201 | { |
---|
| 1202 | c1++; |
---|
| 1203 | } |
---|
| 1204 | absCoeff[ idx ] = uiBin + 1; |
---|
| 1205 | } |
---|
| 1206 | |
---|
| 1207 | if (c1 == 0) |
---|
| 1208 | { |
---|
| 1209 | baseCtxMod = ( eTType==TEXT_LUMA ) ? m_cCUAbsSCModel.get( 0, 0 ) + uiCtxSet : m_cCUAbsSCModel.get( 0, 0 ) + NUM_ABS_FLAG_CTX_LUMA + uiCtxSet; |
---|
| 1210 | if ( firstC2FlagIdx != -1) |
---|
| 1211 | { |
---|
| 1212 | m_pcTDecBinIf->decodeBin( uiBin, baseCtxMod[0] ); |
---|
| 1213 | absCoeff[ firstC2FlagIdx ] = uiBin + 2; |
---|
| 1214 | } |
---|
| 1215 | } |
---|
| 1216 | |
---|
| 1217 | UInt coeffSigns; |
---|
| 1218 | if ( signHidden && beValid ) |
---|
| 1219 | { |
---|
| 1220 | m_pcTDecBinIf->decodeBinsEP( coeffSigns, numNonZero-1 ); |
---|
| 1221 | coeffSigns <<= 32 - (numNonZero-1); |
---|
| 1222 | } |
---|
| 1223 | else |
---|
| 1224 | { |
---|
| 1225 | m_pcTDecBinIf->decodeBinsEP( coeffSigns, numNonZero ); |
---|
| 1226 | coeffSigns <<= 32 - numNonZero; |
---|
| 1227 | } |
---|
| 1228 | |
---|
| 1229 | Int iFirstCoeff2 = 1; |
---|
| 1230 | if (c1 == 0 || numNonZero > C1FLAG_NUMBER) |
---|
| 1231 | { |
---|
| 1232 | for( Int idx = 0; idx < numNonZero; idx++ ) |
---|
| 1233 | { |
---|
| 1234 | UInt baseLevel = (idx < C1FLAG_NUMBER)? (2 + iFirstCoeff2) : 1; |
---|
| 1235 | |
---|
| 1236 | if( absCoeff[ idx ] == baseLevel) |
---|
| 1237 | { |
---|
| 1238 | UInt uiLevel; |
---|
| 1239 | xReadCoefRemainExGolomb( uiLevel, uiGoRiceParam ); |
---|
| 1240 | absCoeff[ idx ] = uiLevel + baseLevel; |
---|
| 1241 | if(absCoeff[idx]>3*(1<<uiGoRiceParam)) |
---|
| 1242 | { |
---|
| 1243 | uiGoRiceParam = min<UInt>(uiGoRiceParam+ 1, 4); |
---|
| 1244 | } |
---|
| 1245 | } |
---|
| 1246 | |
---|
| 1247 | if(absCoeff[ idx ] >= 2) |
---|
| 1248 | { |
---|
| 1249 | iFirstCoeff2 = 0; |
---|
| 1250 | } |
---|
| 1251 | } |
---|
| 1252 | } |
---|
| 1253 | |
---|
| 1254 | for( Int idx = 0; idx < numNonZero; idx++ ) |
---|
| 1255 | { |
---|
| 1256 | Int blkPos = pos[ idx ]; |
---|
| 1257 | // Signs applied later. |
---|
| 1258 | pcCoef[ blkPos ] = absCoeff[ idx ]; |
---|
| 1259 | absSum += absCoeff[ idx ]; |
---|
| 1260 | |
---|
| 1261 | if ( idx == numNonZero-1 && signHidden && beValid ) |
---|
| 1262 | { |
---|
| 1263 | // Infer sign of 1st element. |
---|
| 1264 | if (absSum&0x1) |
---|
| 1265 | { |
---|
| 1266 | pcCoef[ blkPos ] = -pcCoef[ blkPos ]; |
---|
| 1267 | } |
---|
| 1268 | } |
---|
| 1269 | else |
---|
| 1270 | { |
---|
| 1271 | Int sign = static_cast<Int>( coeffSigns ) >> 31; |
---|
| 1272 | pcCoef[ blkPos ] = ( pcCoef[ blkPos ] ^ sign ) - sign; |
---|
| 1273 | coeffSigns <<= 1; |
---|
| 1274 | } |
---|
| 1275 | } |
---|
| 1276 | } |
---|
| 1277 | } |
---|
| 1278 | |
---|
| 1279 | return; |
---|
| 1280 | } |
---|
| 1281 | |
---|
| 1282 | |
---|
| 1283 | Void TDecSbac::parseSaoMaxUvlc ( UInt& val, UInt maxSymbol ) |
---|
| 1284 | { |
---|
| 1285 | if (maxSymbol == 0) |
---|
| 1286 | { |
---|
| 1287 | val = 0; |
---|
| 1288 | return; |
---|
| 1289 | } |
---|
| 1290 | |
---|
| 1291 | UInt code; |
---|
| 1292 | Int i; |
---|
| 1293 | m_pcTDecBinIf->decodeBinEP( code ); |
---|
| 1294 | if ( code == 0 ) |
---|
| 1295 | { |
---|
| 1296 | val = 0; |
---|
| 1297 | return; |
---|
| 1298 | } |
---|
| 1299 | |
---|
| 1300 | i=1; |
---|
| 1301 | while (1) |
---|
| 1302 | { |
---|
| 1303 | m_pcTDecBinIf->decodeBinEP( code ); |
---|
| 1304 | if ( code == 0 ) |
---|
| 1305 | { |
---|
| 1306 | break; |
---|
| 1307 | } |
---|
| 1308 | i++; |
---|
| 1309 | if (i == maxSymbol) |
---|
| 1310 | { |
---|
| 1311 | break; |
---|
| 1312 | } |
---|
| 1313 | } |
---|
| 1314 | |
---|
| 1315 | val = i; |
---|
| 1316 | } |
---|
| 1317 | Void TDecSbac::parseSaoUflc (UInt uiLength, UInt& riVal) |
---|
| 1318 | { |
---|
| 1319 | m_pcTDecBinIf->decodeBinsEP ( riVal, uiLength ); |
---|
| 1320 | } |
---|
| 1321 | Void TDecSbac::parseSaoMerge (UInt& ruiVal) |
---|
| 1322 | { |
---|
| 1323 | UInt uiCode; |
---|
| 1324 | m_pcTDecBinIf->decodeBin( uiCode, m_cSaoMergeSCModel.get( 0, 0, 0 ) ); |
---|
| 1325 | ruiVal = (Int)uiCode; |
---|
| 1326 | } |
---|
| 1327 | Void TDecSbac::parseSaoTypeIdx (UInt& ruiVal) |
---|
| 1328 | { |
---|
| 1329 | UInt uiCode; |
---|
| 1330 | m_pcTDecBinIf->decodeBin( uiCode, m_cSaoTypeIdxSCModel.get( 0, 0, 0 ) ); |
---|
| 1331 | if (uiCode == 0) |
---|
| 1332 | { |
---|
| 1333 | ruiVal = 0; |
---|
| 1334 | } |
---|
| 1335 | else |
---|
| 1336 | { |
---|
| 1337 | m_pcTDecBinIf->decodeBinEP( uiCode ); |
---|
| 1338 | if (uiCode == 0) |
---|
| 1339 | { |
---|
| 1340 | ruiVal = 5; |
---|
| 1341 | } |
---|
| 1342 | else |
---|
| 1343 | { |
---|
| 1344 | ruiVal = 1; |
---|
| 1345 | } |
---|
| 1346 | } |
---|
| 1347 | } |
---|
| 1348 | |
---|
| 1349 | inline Void copySaoOneLcuParam(SaoLcuParam* psDst, SaoLcuParam* psSrc) |
---|
| 1350 | { |
---|
| 1351 | Int i; |
---|
| 1352 | psDst->partIdx = psSrc->partIdx; |
---|
| 1353 | psDst->typeIdx = psSrc->typeIdx; |
---|
| 1354 | if (psDst->typeIdx != -1) |
---|
| 1355 | { |
---|
| 1356 | psDst->subTypeIdx = psSrc->subTypeIdx ; |
---|
| 1357 | psDst->length = psSrc->length; |
---|
| 1358 | for (i=0;i<psDst->length;i++) |
---|
| 1359 | { |
---|
| 1360 | psDst->offset[i] = psSrc->offset[i]; |
---|
| 1361 | } |
---|
| 1362 | } |
---|
| 1363 | else |
---|
| 1364 | { |
---|
| 1365 | psDst->length = 0; |
---|
| 1366 | for (i=0;i<SAO_BO_LEN;i++) |
---|
| 1367 | { |
---|
| 1368 | psDst->offset[i] = 0; |
---|
| 1369 | } |
---|
| 1370 | } |
---|
| 1371 | } |
---|
| 1372 | |
---|
| 1373 | Void TDecSbac::parseSaoOffset(SaoLcuParam* psSaoLcuParam, UInt compIdx) |
---|
| 1374 | { |
---|
| 1375 | UInt uiSymbol; |
---|
| 1376 | static Int iTypeLength[MAX_NUM_SAO_TYPE] = |
---|
| 1377 | { |
---|
| 1378 | SAO_EO_LEN, |
---|
| 1379 | SAO_EO_LEN, |
---|
| 1380 | SAO_EO_LEN, |
---|
| 1381 | SAO_EO_LEN, |
---|
| 1382 | SAO_BO_LEN |
---|
| 1383 | }; |
---|
| 1384 | |
---|
| 1385 | if (compIdx==2) |
---|
| 1386 | { |
---|
| 1387 | uiSymbol = (UInt)( psSaoLcuParam->typeIdx + 1); |
---|
| 1388 | } |
---|
| 1389 | else |
---|
| 1390 | { |
---|
| 1391 | parseSaoTypeIdx(uiSymbol); |
---|
| 1392 | } |
---|
| 1393 | psSaoLcuParam->typeIdx = (Int)uiSymbol - 1; |
---|
| 1394 | if (uiSymbol) |
---|
| 1395 | { |
---|
| 1396 | psSaoLcuParam->length = iTypeLength[psSaoLcuParam->typeIdx]; |
---|
| 1397 | |
---|
| 1398 | Int bitDepth = compIdx ? g_bitDepthC : g_bitDepthY; |
---|
| 1399 | Int offsetTh = 1 << min(bitDepth - 5,5); |
---|
| 1400 | |
---|
| 1401 | if( psSaoLcuParam->typeIdx == SAO_BO ) |
---|
| 1402 | { |
---|
| 1403 | for(Int i=0; i< psSaoLcuParam->length; i++) |
---|
| 1404 | { |
---|
| 1405 | parseSaoMaxUvlc(uiSymbol, offsetTh -1 ); |
---|
| 1406 | psSaoLcuParam->offset[i] = uiSymbol; |
---|
| 1407 | } |
---|
| 1408 | for(Int i=0; i< psSaoLcuParam->length; i++) |
---|
| 1409 | { |
---|
| 1410 | if (psSaoLcuParam->offset[i] != 0) |
---|
| 1411 | { |
---|
| 1412 | m_pcTDecBinIf->decodeBinEP ( uiSymbol); |
---|
| 1413 | if (uiSymbol) |
---|
| 1414 | { |
---|
| 1415 | psSaoLcuParam->offset[i] = -psSaoLcuParam->offset[i] ; |
---|
| 1416 | } |
---|
| 1417 | } |
---|
| 1418 | } |
---|
| 1419 | parseSaoUflc(5, uiSymbol ); |
---|
| 1420 | psSaoLcuParam->subTypeIdx = uiSymbol; |
---|
| 1421 | } |
---|
| 1422 | else if( psSaoLcuParam->typeIdx < 4 ) |
---|
| 1423 | { |
---|
| 1424 | parseSaoMaxUvlc(uiSymbol, offsetTh -1 ); psSaoLcuParam->offset[0] = uiSymbol; |
---|
| 1425 | parseSaoMaxUvlc(uiSymbol, offsetTh -1 ); psSaoLcuParam->offset[1] = uiSymbol; |
---|
| 1426 | parseSaoMaxUvlc(uiSymbol, offsetTh -1 ); psSaoLcuParam->offset[2] = -(Int)uiSymbol; |
---|
| 1427 | parseSaoMaxUvlc(uiSymbol, offsetTh -1 ); psSaoLcuParam->offset[3] = -(Int)uiSymbol; |
---|
| 1428 | if (compIdx != 2) |
---|
| 1429 | { |
---|
| 1430 | parseSaoUflc(2, uiSymbol ); |
---|
| 1431 | psSaoLcuParam->subTypeIdx = uiSymbol; |
---|
| 1432 | psSaoLcuParam->typeIdx += psSaoLcuParam->subTypeIdx; |
---|
| 1433 | } |
---|
| 1434 | } |
---|
| 1435 | } |
---|
| 1436 | else |
---|
| 1437 | { |
---|
| 1438 | psSaoLcuParam->length = 0; |
---|
| 1439 | } |
---|
| 1440 | } |
---|
| 1441 | |
---|
| 1442 | Void TDecSbac::parseSaoOneLcuInterleaving(Int rx, Int ry, SAOParam* pSaoParam, TComDataCU* pcCU, Int iCUAddrInSlice, Int iCUAddrUpInSlice, Int allowMergeLeft, Int allowMergeUp) |
---|
| 1443 | { |
---|
| 1444 | Int iAddr = pcCU->getAddr(); |
---|
| 1445 | UInt uiSymbol; |
---|
| 1446 | for (Int iCompIdx=0; iCompIdx<3; iCompIdx++) |
---|
| 1447 | { |
---|
| 1448 | pSaoParam->saoLcuParam[iCompIdx][iAddr].mergeUpFlag = 0; |
---|
| 1449 | pSaoParam->saoLcuParam[iCompIdx][iAddr].mergeLeftFlag = 0; |
---|
| 1450 | pSaoParam->saoLcuParam[iCompIdx][iAddr].subTypeIdx = 0; |
---|
| 1451 | pSaoParam->saoLcuParam[iCompIdx][iAddr].typeIdx = -1; |
---|
| 1452 | pSaoParam->saoLcuParam[iCompIdx][iAddr].offset[0] = 0; |
---|
| 1453 | pSaoParam->saoLcuParam[iCompIdx][iAddr].offset[1] = 0; |
---|
| 1454 | pSaoParam->saoLcuParam[iCompIdx][iAddr].offset[2] = 0; |
---|
| 1455 | pSaoParam->saoLcuParam[iCompIdx][iAddr].offset[3] = 0; |
---|
| 1456 | |
---|
| 1457 | } |
---|
| 1458 | if (pSaoParam->bSaoFlag[0] || pSaoParam->bSaoFlag[1] ) |
---|
| 1459 | { |
---|
| 1460 | if (rx>0 && iCUAddrInSlice!=0 && allowMergeLeft) |
---|
| 1461 | { |
---|
| 1462 | parseSaoMerge(uiSymbol); |
---|
| 1463 | pSaoParam->saoLcuParam[0][iAddr].mergeLeftFlag = (Bool)uiSymbol; |
---|
| 1464 | } |
---|
| 1465 | if (pSaoParam->saoLcuParam[0][iAddr].mergeLeftFlag==0) |
---|
| 1466 | { |
---|
| 1467 | if ((ry > 0) && (iCUAddrUpInSlice>=0) && allowMergeUp) |
---|
| 1468 | { |
---|
| 1469 | parseSaoMerge(uiSymbol); |
---|
| 1470 | pSaoParam->saoLcuParam[0][iAddr].mergeUpFlag = (Bool)uiSymbol; |
---|
| 1471 | } |
---|
| 1472 | } |
---|
| 1473 | } |
---|
| 1474 | |
---|
| 1475 | for (Int iCompIdx=0; iCompIdx<3; iCompIdx++) |
---|
| 1476 | { |
---|
| 1477 | if ((iCompIdx == 0 && pSaoParam->bSaoFlag[0]) || (iCompIdx > 0 && pSaoParam->bSaoFlag[1]) ) |
---|
| 1478 | { |
---|
| 1479 | if (rx>0 && iCUAddrInSlice!=0 && allowMergeLeft) |
---|
| 1480 | { |
---|
| 1481 | pSaoParam->saoLcuParam[iCompIdx][iAddr].mergeLeftFlag = pSaoParam->saoLcuParam[0][iAddr].mergeLeftFlag; |
---|
| 1482 | } |
---|
| 1483 | else |
---|
| 1484 | { |
---|
| 1485 | pSaoParam->saoLcuParam[iCompIdx][iAddr].mergeLeftFlag = 0; |
---|
| 1486 | } |
---|
| 1487 | |
---|
| 1488 | if (pSaoParam->saoLcuParam[iCompIdx][iAddr].mergeLeftFlag==0) |
---|
| 1489 | { |
---|
| 1490 | if ((ry > 0) && (iCUAddrUpInSlice>=0) && allowMergeUp) |
---|
| 1491 | { |
---|
| 1492 | pSaoParam->saoLcuParam[iCompIdx][iAddr].mergeUpFlag = pSaoParam->saoLcuParam[0][iAddr].mergeUpFlag; |
---|
| 1493 | } |
---|
| 1494 | else |
---|
| 1495 | { |
---|
| 1496 | pSaoParam->saoLcuParam[iCompIdx][iAddr].mergeUpFlag = 0; |
---|
| 1497 | } |
---|
| 1498 | if (!pSaoParam->saoLcuParam[iCompIdx][iAddr].mergeUpFlag) |
---|
| 1499 | { |
---|
| 1500 | pSaoParam->saoLcuParam[2][iAddr].typeIdx = pSaoParam->saoLcuParam[1][iAddr].typeIdx; |
---|
| 1501 | parseSaoOffset(&(pSaoParam->saoLcuParam[iCompIdx][iAddr]), iCompIdx); |
---|
| 1502 | } |
---|
| 1503 | else |
---|
| 1504 | { |
---|
| 1505 | copySaoOneLcuParam(&pSaoParam->saoLcuParam[iCompIdx][iAddr], &pSaoParam->saoLcuParam[iCompIdx][iAddr-pSaoParam->numCuInWidth]); |
---|
| 1506 | } |
---|
| 1507 | } |
---|
| 1508 | else |
---|
| 1509 | { |
---|
| 1510 | copySaoOneLcuParam(&pSaoParam->saoLcuParam[iCompIdx][iAddr], &pSaoParam->saoLcuParam[iCompIdx][iAddr-1]); |
---|
| 1511 | } |
---|
| 1512 | } |
---|
| 1513 | else |
---|
| 1514 | { |
---|
| 1515 | pSaoParam->saoLcuParam[iCompIdx][iAddr].typeIdx = -1; |
---|
| 1516 | pSaoParam->saoLcuParam[iCompIdx][iAddr].subTypeIdx = 0; |
---|
| 1517 | } |
---|
| 1518 | } |
---|
| 1519 | } |
---|
| 1520 | |
---|
| 1521 | /** |
---|
| 1522 | - Initialize our contexts from the nominated source. |
---|
| 1523 | . |
---|
| 1524 | \param pSrc Contexts to be copied. |
---|
| 1525 | */ |
---|
| 1526 | Void TDecSbac::xCopyContextsFrom( TDecSbac* pSrc ) |
---|
| 1527 | { |
---|
| 1528 | memcpy(m_contextModels, pSrc->m_contextModels, m_numContextModels*sizeof(m_contextModels[0])); |
---|
| 1529 | } |
---|
| 1530 | |
---|
| 1531 | Void TDecSbac::xCopyFrom( TDecSbac* pSrc ) |
---|
| 1532 | { |
---|
| 1533 | m_pcTDecBinIf->copyState( pSrc->m_pcTDecBinIf ); |
---|
| 1534 | |
---|
| 1535 | m_uiLastQp = pSrc->m_uiLastQp; |
---|
| 1536 | xCopyContextsFrom( pSrc ); |
---|
| 1537 | |
---|
| 1538 | } |
---|
| 1539 | |
---|
| 1540 | Void TDecSbac::load ( TDecSbac* pScr ) |
---|
| 1541 | { |
---|
| 1542 | xCopyFrom(pScr); |
---|
| 1543 | } |
---|
| 1544 | |
---|
| 1545 | Void TDecSbac::loadContexts ( TDecSbac* pScr ) |
---|
| 1546 | { |
---|
| 1547 | xCopyContextsFrom(pScr); |
---|
| 1548 | } |
---|
| 1549 | //! \} |
---|