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