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 | #if SVC_EXTENSION |
---|
954 | Int qpBdOffsetY = pcCU->getSlice()->getQpBDOffset(CHANNEL_TYPE_LUMA); |
---|
955 | #else |
---|
956 | Int qpBdOffsetY = pcCU->getSlice()->getSPS()->getQpBDOffset(CHANNEL_TYPE_LUMA); |
---|
957 | #endif |
---|
958 | m_pcTDecBinIf->decodeBinEP(uiSign RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(STATS__CABAC_BITS__DELTA_QP_EP)); |
---|
959 | iDQp = uiDQp; |
---|
960 | if(uiSign) |
---|
961 | { |
---|
962 | iDQp = -iDQp; |
---|
963 | } |
---|
964 | qp = (((Int) pcCU->getRefQP( uiAbsPartIdx ) + iDQp + 52 + 2*qpBdOffsetY )%(52+qpBdOffsetY)) - qpBdOffsetY; |
---|
965 | } |
---|
966 | else |
---|
967 | { |
---|
968 | qp = pcCU->getRefQP(uiAbsPartIdx); |
---|
969 | } |
---|
970 | |
---|
971 | pcCU->setQPSubParts(qp, uiAbsPartIdx, uiDepth); |
---|
972 | pcCU->setCodedQP(qp); |
---|
973 | } |
---|
974 | |
---|
975 | /** parse chroma qp adjustment, converting to the internal table representation. |
---|
976 | * \returns Void |
---|
977 | */ |
---|
978 | Void TDecSbac::parseChromaQpAdjustment( TComDataCU* cu, UInt absPartIdx, UInt depth ) |
---|
979 | { |
---|
980 | UInt symbol; |
---|
981 | #if RExt__DECODER_DEBUG_BIT_STATISTICS |
---|
982 | const TComCodingStatisticsClassType ctype(STATS__CABAC_BITS__CHROMA_QP_ADJUSTMENT, g_aucConvertToBit[cu->getSlice()->getSPS()->getMaxCUWidth()>>depth]+2, CHANNEL_TYPE_CHROMA); |
---|
983 | #endif |
---|
984 | |
---|
985 | Int chromaQpOffsetListLen = cu->getSlice()->getPPS()->getPpsRangeExtension().getChromaQpOffsetListLen(); |
---|
986 | |
---|
987 | // cu_chroma_qp_offset_flag |
---|
988 | m_pcTDecBinIf->decodeBin( symbol, m_ChromaQpAdjFlagSCModel.get( 0, 0, 0 ) RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(ctype) ); |
---|
989 | |
---|
990 | if (symbol && chromaQpOffsetListLen > 1) |
---|
991 | { |
---|
992 | // cu_chroma_qp_offset_idx |
---|
993 | xReadUnaryMaxSymbol( symbol, &m_ChromaQpAdjIdcSCModel.get( 0, 0, 0 ), 0, chromaQpOffsetListLen - 1 RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(ctype) ); |
---|
994 | symbol++; |
---|
995 | } |
---|
996 | /* NB, symbol = 0 if outer flag is not set, |
---|
997 | * 1 if outer flag is set and there is no inner flag |
---|
998 | * 1+ otherwise */ |
---|
999 | cu->setChromaQpAdjSubParts( symbol, absPartIdx, depth ); |
---|
1000 | cu->setCodedChromaQpAdj(symbol); |
---|
1001 | } |
---|
1002 | |
---|
1003 | Void TDecSbac::parseQtCbf( TComTU &rTu, const ComponentID compID, const Bool lowestLevel ) |
---|
1004 | { |
---|
1005 | TComDataCU* pcCU = rTu.getCU(); |
---|
1006 | |
---|
1007 | const UInt absPartIdx = rTu.GetAbsPartIdxTU(compID); |
---|
1008 | const UInt TUDepth = rTu.GetTransformDepthRel(); |
---|
1009 | const UInt uiCtx = pcCU->getCtxQtCbf( rTu, toChannelType(compID) ); |
---|
1010 | const UInt contextSet = toChannelType(compID); |
---|
1011 | |
---|
1012 | const UInt width = rTu.getRect(compID).width; |
---|
1013 | const UInt height = rTu.getRect(compID).height; |
---|
1014 | const Bool canQuadSplit = (width >= (MIN_TU_SIZE * 2)) && (height >= (MIN_TU_SIZE * 2)); |
---|
1015 | const UInt coveredPartIdxes = rTu.GetAbsPartIdxNumParts(compID); |
---|
1016 | |
---|
1017 | // Since the CBF for chroma is coded at the highest level possible, if sub-TUs are |
---|
1018 | // to be coded for a 4x8 chroma TU, their CBFs must be coded at the highest 4x8 level |
---|
1019 | // (i.e. where luma TUs are 8x8 rather than 4x4) |
---|
1020 | // ___ ___ |
---|
1021 | // | | | <- 4 x (8x8 luma + 4x8 4:2:2 chroma) |
---|
1022 | // |___|___| each quadrant has its own chroma CBF |
---|
1023 | // | | | _ _ _ _ |
---|
1024 | // |___|___| | |
---|
1025 | // <--16---> V |
---|
1026 | // _ _ |
---|
1027 | // |_|_| <- 4 x 4x4 luma + 1 x 4x8 4:2:2 chroma |
---|
1028 | // |_|_| no chroma CBF is coded - instead the parent CBF is inherited |
---|
1029 | // <-8-> if sub-TUs are present, their CBFs had to be coded at the parent level |
---|
1030 | |
---|
1031 | const UInt lowestTUDepth = TUDepth + ((!lowestLevel && !canQuadSplit) ? 1 : 0); //unsplittable TUs inherit their parent's CBF |
---|
1032 | UInt lowestTUCBF = 0; |
---|
1033 | |
---|
1034 | if ((width != height) && (lowestLevel || !canQuadSplit)) //if sub-TUs are present |
---|
1035 | { |
---|
1036 | const UInt subTUDepth = lowestTUDepth + 1; |
---|
1037 | const UInt partIdxesPerSubTU = rTu.GetAbsPartIdxNumParts(compID) >> 1; |
---|
1038 | |
---|
1039 | UInt combinedSubTUCBF = 0; |
---|
1040 | |
---|
1041 | for (UInt subTU = 0; subTU < 2; subTU++) |
---|
1042 | { |
---|
1043 | UInt uiCbf = MAX_UINT; |
---|
1044 | 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))); |
---|
1045 | |
---|
1046 | const UInt subTUAbsPartIdx = absPartIdx + (subTU * partIdxesPerSubTU); |
---|
1047 | pcCU->setCbfPartRange((uiCbf << subTUDepth), compID, subTUAbsPartIdx, partIdxesPerSubTU); |
---|
1048 | combinedSubTUCBF |= uiCbf; |
---|
1049 | |
---|
1050 | DTRACE_CABAC_VL( g_nSymbolCounter++ ) |
---|
1051 | DTRACE_CABAC_T( "\tparseQtCbf()" ) |
---|
1052 | DTRACE_CABAC_T( "\tsub-TU=" ) |
---|
1053 | DTRACE_CABAC_V( subTU ) |
---|
1054 | DTRACE_CABAC_T( "\tsymbol=" ) |
---|
1055 | DTRACE_CABAC_V( uiCbf ) |
---|
1056 | DTRACE_CABAC_T( "\tctx=" ) |
---|
1057 | DTRACE_CABAC_V( uiCtx ) |
---|
1058 | DTRACE_CABAC_T( "\tetype=" ) |
---|
1059 | DTRACE_CABAC_V( compID ) |
---|
1060 | DTRACE_CABAC_T( "\tuiAbsPartIdx=" ) |
---|
1061 | DTRACE_CABAC_V( subTUAbsPartIdx ) |
---|
1062 | DTRACE_CABAC_T( "\n" ) |
---|
1063 | } |
---|
1064 | |
---|
1065 | //propagate the sub-TU CBF up to the lowest TU level |
---|
1066 | if (combinedSubTUCBF != 0) |
---|
1067 | { |
---|
1068 | pcCU->bitwiseOrCbfPartRange((combinedSubTUCBF << lowestTUDepth), compID, absPartIdx, coveredPartIdxes); |
---|
1069 | lowestTUCBF = combinedSubTUCBF; |
---|
1070 | } |
---|
1071 | } |
---|
1072 | else |
---|
1073 | { |
---|
1074 | UInt uiCbf = MAX_UINT; |
---|
1075 | 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))); |
---|
1076 | |
---|
1077 | pcCU->setCbfSubParts((uiCbf << lowestTUDepth), compID, absPartIdx, rTu.GetTransformDepthTotalAdj(compID)); |
---|
1078 | |
---|
1079 | DTRACE_CABAC_VL( g_nSymbolCounter++ ) |
---|
1080 | DTRACE_CABAC_T( "\tparseQtCbf()" ) |
---|
1081 | DTRACE_CABAC_T( "\tsymbol=" ) |
---|
1082 | DTRACE_CABAC_V( uiCbf ) |
---|
1083 | DTRACE_CABAC_T( "\tctx=" ) |
---|
1084 | DTRACE_CABAC_V( uiCtx ) |
---|
1085 | DTRACE_CABAC_T( "\tetype=" ) |
---|
1086 | DTRACE_CABAC_V( compID ) |
---|
1087 | DTRACE_CABAC_T( "\tuiAbsPartIdx=" ) |
---|
1088 | DTRACE_CABAC_V( rTu.GetAbsPartIdxTU(compID) ) |
---|
1089 | DTRACE_CABAC_T( "\n" ) |
---|
1090 | |
---|
1091 | lowestTUCBF = uiCbf; |
---|
1092 | } |
---|
1093 | |
---|
1094 | //propagate the lowest level CBF up to the current level |
---|
1095 | if (lowestTUCBF != 0) |
---|
1096 | { |
---|
1097 | for (UInt depth = TUDepth; depth < lowestTUDepth; depth++) |
---|
1098 | { |
---|
1099 | pcCU->bitwiseOrCbfPartRange((lowestTUCBF << depth), compID, absPartIdx, coveredPartIdxes); |
---|
1100 | } |
---|
1101 | } |
---|
1102 | } |
---|
1103 | |
---|
1104 | |
---|
1105 | Void TDecSbac::parseTransformSkipFlags (TComTU &rTu, ComponentID component) |
---|
1106 | { |
---|
1107 | TComDataCU* pcCU=rTu.getCU(); |
---|
1108 | UInt uiAbsPartIdx=rTu.GetAbsPartIdxTU(component); |
---|
1109 | |
---|
1110 | if (pcCU->getCUTransquantBypass(uiAbsPartIdx)) |
---|
1111 | { |
---|
1112 | return; |
---|
1113 | } |
---|
1114 | |
---|
1115 | if (!TUCompRectHasAssociatedTransformSkipFlag(rTu.getRect(component), pcCU->getSlice()->getPPS()->getPpsRangeExtension().getLog2MaxTransformSkipBlockSize())) |
---|
1116 | { |
---|
1117 | return; |
---|
1118 | } |
---|
1119 | |
---|
1120 | UInt useTransformSkip; |
---|
1121 | |
---|
1122 | m_pcTDecBinIf->decodeBin( useTransformSkip , m_cTransformSkipSCModel.get( 0, toChannelType(component), 0 ) |
---|
1123 | RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(TComCodingStatisticsClassType(STATS__CABAC_BITS__TRANSFORM_SKIP_FLAGS, component)) |
---|
1124 | ); |
---|
1125 | |
---|
1126 | DTRACE_CABAC_VL( g_nSymbolCounter++ ) |
---|
1127 | DTRACE_CABAC_T("\tparseTransformSkip()"); |
---|
1128 | DTRACE_CABAC_T( "\tsymbol=" ) |
---|
1129 | DTRACE_CABAC_V( useTransformSkip ) |
---|
1130 | DTRACE_CABAC_T( "\tAddr=" ) |
---|
1131 | DTRACE_CABAC_V( pcCU->getCtuRsAddr() ) |
---|
1132 | DTRACE_CABAC_T( "\tetype=" ) |
---|
1133 | DTRACE_CABAC_V( component ) |
---|
1134 | DTRACE_CABAC_T( "\tuiAbsPartIdx=" ) |
---|
1135 | DTRACE_CABAC_V( rTu.GetAbsPartIdxTU() ) |
---|
1136 | DTRACE_CABAC_T( "\n" ) |
---|
1137 | |
---|
1138 | pcCU->setTransformSkipPartRange( useTransformSkip, component, uiAbsPartIdx, rTu.GetAbsPartIdxNumParts(component)); |
---|
1139 | } |
---|
1140 | |
---|
1141 | |
---|
1142 | /** Parse (X,Y) position of the last significant coefficient |
---|
1143 | * \param uiPosLastX reference to X component of last coefficient |
---|
1144 | * \param uiPosLastY reference to Y component of last coefficient |
---|
1145 | * \param width Block width |
---|
1146 | * \param height Block height |
---|
1147 | * \param component chroma compinent ID |
---|
1148 | * \param uiScanIdx scan type (zig-zag, hor, ver) |
---|
1149 | * |
---|
1150 | * This method decodes the X and Y component within a block of the last significant coefficient. |
---|
1151 | */ |
---|
1152 | Void TDecSbac::parseLastSignificantXY( UInt& uiPosLastX, UInt& uiPosLastY, Int width, Int height, ComponentID component, UInt uiScanIdx ) |
---|
1153 | { |
---|
1154 | UInt uiLast; |
---|
1155 | |
---|
1156 | ContextModel *pCtxX = m_cCuCtxLastX.get( 0, toChannelType(component) ); |
---|
1157 | ContextModel *pCtxY = m_cCuCtxLastY.get( 0, toChannelType(component) ); |
---|
1158 | |
---|
1159 | #if RExt__DECODER_DEBUG_BIT_STATISTICS |
---|
1160 | TComCodingStatisticsClassType ctype(STATS__CABAC_BITS__LAST_SIG_X_Y, g_aucConvertToBit[width]+2, component); |
---|
1161 | #endif |
---|
1162 | |
---|
1163 | |
---|
1164 | if ( uiScanIdx == SCAN_VER ) |
---|
1165 | { |
---|
1166 | swap( width, height ); |
---|
1167 | } |
---|
1168 | |
---|
1169 | Int blkSizeOffsetX, blkSizeOffsetY, shiftX, shiftY; |
---|
1170 | getLastSignificantContextParameters(component, width, height, blkSizeOffsetX, blkSizeOffsetY, shiftX, shiftY); |
---|
1171 | |
---|
1172 | //------------------ |
---|
1173 | |
---|
1174 | // posX |
---|
1175 | |
---|
1176 | for( uiPosLastX = 0; uiPosLastX < g_uiGroupIdx[ width - 1 ]; uiPosLastX++ ) |
---|
1177 | { |
---|
1178 | m_pcTDecBinIf->decodeBin( uiLast, *( pCtxX + blkSizeOffsetX + (uiPosLastX >>shiftX) ) RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(ctype) ); |
---|
1179 | |
---|
1180 | if( !uiLast ) |
---|
1181 | { |
---|
1182 | break; |
---|
1183 | } |
---|
1184 | } |
---|
1185 | |
---|
1186 | // posY |
---|
1187 | |
---|
1188 | for( uiPosLastY = 0; uiPosLastY < g_uiGroupIdx[ height - 1 ]; uiPosLastY++ ) |
---|
1189 | { |
---|
1190 | m_pcTDecBinIf->decodeBin( uiLast, *( pCtxY + blkSizeOffsetY + (uiPosLastY >>shiftY)) RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(ctype) ); |
---|
1191 | |
---|
1192 | if( !uiLast ) |
---|
1193 | { |
---|
1194 | break; |
---|
1195 | } |
---|
1196 | } |
---|
1197 | |
---|
1198 | // EP-coded part |
---|
1199 | |
---|
1200 | if ( uiPosLastX > 3 ) |
---|
1201 | { |
---|
1202 | UInt uiTemp = 0; |
---|
1203 | UInt uiCount = ( uiPosLastX - 2 ) >> 1; |
---|
1204 | for ( Int i = uiCount - 1; i >= 0; i-- ) |
---|
1205 | { |
---|
1206 | m_pcTDecBinIf->decodeBinEP( uiLast RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(ctype) ); |
---|
1207 | uiTemp += uiLast << i; |
---|
1208 | } |
---|
1209 | uiPosLastX = g_uiMinInGroup[ uiPosLastX ] + uiTemp; |
---|
1210 | } |
---|
1211 | if ( uiPosLastY > 3 ) |
---|
1212 | { |
---|
1213 | UInt uiTemp = 0; |
---|
1214 | UInt uiCount = ( uiPosLastY - 2 ) >> 1; |
---|
1215 | for ( Int i = uiCount - 1; i >= 0; i-- ) |
---|
1216 | { |
---|
1217 | m_pcTDecBinIf->decodeBinEP( uiLast RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(ctype) ); |
---|
1218 | uiTemp += uiLast << i; |
---|
1219 | } |
---|
1220 | uiPosLastY = g_uiMinInGroup[ uiPosLastY ] + uiTemp; |
---|
1221 | } |
---|
1222 | |
---|
1223 | if( uiScanIdx == SCAN_VER ) |
---|
1224 | { |
---|
1225 | swap( uiPosLastX, uiPosLastY ); |
---|
1226 | } |
---|
1227 | } |
---|
1228 | |
---|
1229 | Void TDecSbac::parseCoeffNxN( TComTU &rTu, ComponentID compID ) |
---|
1230 | { |
---|
1231 | TComDataCU* pcCU=rTu.getCU(); |
---|
1232 | const UInt uiAbsPartIdx=rTu.GetAbsPartIdxTU(compID); |
---|
1233 | const TComRectangle &rRect=rTu.getRect(compID); |
---|
1234 | const UInt uiWidth=rRect.width; |
---|
1235 | const UInt uiHeight=rRect.height; |
---|
1236 | TCoeff* pcCoef=(pcCU->getCoeff(compID)+rTu.getCoefficientOffset(compID)); |
---|
1237 | const TComSPS &sps=*(pcCU->getSlice()->getSPS()); |
---|
1238 | |
---|
1239 | DTRACE_CABAC_VL( g_nSymbolCounter++ ) |
---|
1240 | DTRACE_CABAC_T( "\tparseCoeffNxN()\teType=" ) |
---|
1241 | DTRACE_CABAC_V( compID ) |
---|
1242 | DTRACE_CABAC_T( "\twidth=" ) |
---|
1243 | DTRACE_CABAC_V( uiWidth ) |
---|
1244 | DTRACE_CABAC_T( "\theight=" ) |
---|
1245 | DTRACE_CABAC_V( uiHeight ) |
---|
1246 | DTRACE_CABAC_T( "\tdepth=" ) |
---|
1247 | // DTRACE_CABAC_V( rTu.GetTransformDepthTotalAdj(compID) ) |
---|
1248 | DTRACE_CABAC_V( rTu.GetTransformDepthTotal() ) |
---|
1249 | DTRACE_CABAC_T( "\tabspartidx=" ) |
---|
1250 | // DTRACE_CABAC_V( uiAbsPartIdx ) |
---|
1251 | DTRACE_CABAC_V( rTu.GetAbsPartIdxTU(compID) ) |
---|
1252 | DTRACE_CABAC_T( "\ttoCU-X=" ) |
---|
1253 | DTRACE_CABAC_V( pcCU->getCUPelX() ) |
---|
1254 | DTRACE_CABAC_T( "\ttoCU-Y=" ) |
---|
1255 | DTRACE_CABAC_V( pcCU->getCUPelY() ) |
---|
1256 | DTRACE_CABAC_T( "\tCU-addr=" ) |
---|
1257 | DTRACE_CABAC_V( pcCU->getCtuRsAddr() ) |
---|
1258 | DTRACE_CABAC_T( "\tinCU-X=" ) |
---|
1259 | // DTRACE_CABAC_V( g_auiRasterToPelX[ g_auiZscanToRaster[uiAbsPartIdx] ] ) |
---|
1260 | DTRACE_CABAC_V( g_auiRasterToPelX[ g_auiZscanToRaster[rTu.GetAbsPartIdxTU(compID)] ] ) |
---|
1261 | DTRACE_CABAC_T( "\tinCU-Y=" ) |
---|
1262 | // DTRACE_CABAC_V( g_auiRasterToPelY[ g_auiZscanToRaster[uiAbsPartIdx] ] ) |
---|
1263 | DTRACE_CABAC_V( g_auiRasterToPelY[ g_auiZscanToRaster[rTu.GetAbsPartIdxTU(compID)] ] ) |
---|
1264 | DTRACE_CABAC_T( "\tpredmode=" ) |
---|
1265 | DTRACE_CABAC_V( pcCU->getPredictionMode( uiAbsPartIdx ) ) |
---|
1266 | DTRACE_CABAC_T( "\n" ) |
---|
1267 | |
---|
1268 | //-------------------------------------------------------------------------------------------------- |
---|
1269 | |
---|
1270 | if( uiWidth > sps.getMaxTrSize() ) |
---|
1271 | { |
---|
1272 | std::cerr << "ERROR: parseCoeffNxN was passed a TU with dimensions larger than the maximum allowed size" << std::endl; |
---|
1273 | assert(false); |
---|
1274 | exit(1); |
---|
1275 | } |
---|
1276 | |
---|
1277 | //-------------------------------------------------------------------------------------------------- |
---|
1278 | |
---|
1279 | //set parameters |
---|
1280 | |
---|
1281 | const ChannelType chType = toChannelType(compID); |
---|
1282 | const UInt uiLog2BlockWidth = g_aucConvertToBit[ uiWidth ] + 2; |
---|
1283 | const UInt uiLog2BlockHeight = g_aucConvertToBit[ uiHeight ] + 2; |
---|
1284 | const UInt uiMaxNumCoeff = uiWidth * uiHeight; |
---|
1285 | const UInt uiMaxNumCoeffM1 = uiMaxNumCoeff - 1; |
---|
1286 | |
---|
1287 | const ChannelType channelType = toChannelType(compID); |
---|
1288 | const Bool extendedPrecision = sps.getSpsRangeExtension().getExtendedPrecisionProcessingFlag(); |
---|
1289 | |
---|
1290 | const Bool alignCABACBeforeBypass = sps.getSpsRangeExtension().getCabacBypassAlignmentEnabledFlag(); |
---|
1291 | const Int maxLog2TrDynamicRange = sps.getMaxLog2TrDynamicRange(channelType); |
---|
1292 | |
---|
1293 | #if RExt__DECODER_DEBUG_BIT_STATISTICS |
---|
1294 | TComCodingStatisticsClassType ctype_group(STATS__CABAC_BITS__SIG_COEFF_GROUP_FLAG, uiLog2BlockWidth, compID); |
---|
1295 | TComCodingStatisticsClassType ctype_map(STATS__CABAC_BITS__SIG_COEFF_MAP_FLAG, uiLog2BlockWidth, compID); |
---|
1296 | TComCodingStatisticsClassType ctype_gt1(STATS__CABAC_BITS__GT1_FLAG, uiLog2BlockWidth, compID); |
---|
1297 | TComCodingStatisticsClassType ctype_gt2(STATS__CABAC_BITS__GT2_FLAG, uiLog2BlockWidth, compID); |
---|
1298 | #endif |
---|
1299 | |
---|
1300 | Bool beValid; |
---|
1301 | if (pcCU->getCUTransquantBypass(uiAbsPartIdx)) |
---|
1302 | { |
---|
1303 | beValid = false; |
---|
1304 | if((!pcCU->isIntra(uiAbsPartIdx)) && pcCU->isRDPCMEnabled(uiAbsPartIdx)) |
---|
1305 | { |
---|
1306 | parseExplicitRdpcmMode(rTu, compID); |
---|
1307 | } |
---|
1308 | } |
---|
1309 | else |
---|
1310 | { |
---|
1311 | beValid = pcCU->getSlice()->getPPS()->getSignHideFlag(); |
---|
1312 | } |
---|
1313 | |
---|
1314 | UInt absSum = 0; |
---|
1315 | |
---|
1316 | //-------------------------------------------------------------------------------------------------- |
---|
1317 | |
---|
1318 | if(pcCU->getSlice()->getPPS()->getUseTransformSkip()) |
---|
1319 | { |
---|
1320 | parseTransformSkipFlags(rTu, compID); |
---|
1321 | // This TU has coefficients and is transform skipped. Check whether is inter coded and if yes decode the explicit RDPCM mode |
---|
1322 | if(pcCU->getTransformSkip(uiAbsPartIdx, compID) && (!pcCU->isIntra(uiAbsPartIdx)) && pcCU->isRDPCMEnabled(uiAbsPartIdx) ) |
---|
1323 | { |
---|
1324 | parseExplicitRdpcmMode(rTu, compID); |
---|
1325 | if(pcCU->getExplicitRdpcmMode(compID, uiAbsPartIdx) != RDPCM_OFF) |
---|
1326 | { |
---|
1327 | // Sign data hiding is avoided for horizontal and vertical RDPCM modes |
---|
1328 | beValid = false; |
---|
1329 | } |
---|
1330 | } |
---|
1331 | } |
---|
1332 | |
---|
1333 | Int uiIntraMode = -1; |
---|
1334 | const Bool bIsLuma = isLuma(compID); |
---|
1335 | Int isIntra = pcCU->isIntra(uiAbsPartIdx) ? 1 : 0; |
---|
1336 | if ( isIntra && pcCU->isRDPCMEnabled(uiAbsPartIdx) ) |
---|
1337 | { |
---|
1338 | const UInt partsPerMinCU = 1<<(2*(sps.getMaxTotalCUDepth() - sps.getLog2DiffMaxMinCodingBlockSize())); |
---|
1339 | uiIntraMode = pcCU->getIntraDir( toChannelType(compID), uiAbsPartIdx ); |
---|
1340 | uiIntraMode = (uiIntraMode==DM_CHROMA_IDX && !bIsLuma) ? pcCU->getIntraDir(CHANNEL_TYPE_LUMA, getChromasCorrespondingPULumaIdx(uiAbsPartIdx, rTu.GetChromaFormat(), partsPerMinCU)) : uiIntraMode; |
---|
1341 | uiIntraMode = ((rTu.GetChromaFormat() == CHROMA_422) && !bIsLuma) ? g_chroma422IntraAngleMappingTable[uiIntraMode] : uiIntraMode; |
---|
1342 | |
---|
1343 | Bool transformSkip = pcCU->getTransformSkip( uiAbsPartIdx,compID); |
---|
1344 | Bool rdpcm_lossy = ( transformSkip /*&& isIntra*/ && ( (uiIntraMode == HOR_IDX) || (uiIntraMode == VER_IDX) ) ); |
---|
1345 | if ( rdpcm_lossy ) |
---|
1346 | { |
---|
1347 | beValid = false; |
---|
1348 | } |
---|
1349 | } |
---|
1350 | |
---|
1351 | //-------------------------------------------------------------------------------------------------- |
---|
1352 | |
---|
1353 | const Bool bUseGolombRiceParameterAdaptation = sps.getSpsRangeExtension().getPersistentRiceAdaptationEnabledFlag(); |
---|
1354 | UInt ¤tGolombRiceStatistic = m_golombRiceAdaptationStatistics[rTu.getGolombRiceStatisticsIndex(compID)]; |
---|
1355 | |
---|
1356 | //select scans |
---|
1357 | TUEntropyCodingParameters codingParameters; |
---|
1358 | getTUEntropyCodingParameters(codingParameters, rTu, compID); |
---|
1359 | |
---|
1360 | //===== decode last significant ===== |
---|
1361 | UInt uiPosLastX, uiPosLastY; |
---|
1362 | parseLastSignificantXY( uiPosLastX, uiPosLastY, uiWidth, uiHeight, compID, codingParameters.scanType ); |
---|
1363 | UInt uiBlkPosLast = uiPosLastX + (uiPosLastY<<uiLog2BlockWidth); |
---|
1364 | pcCoef[ uiBlkPosLast ] = 1; |
---|
1365 | |
---|
1366 | //===== decode significance flags ===== |
---|
1367 | UInt uiScanPosLast; |
---|
1368 | for( uiScanPosLast = 0; uiScanPosLast < uiMaxNumCoeffM1; uiScanPosLast++ ) |
---|
1369 | { |
---|
1370 | UInt uiBlkPos = codingParameters.scan[ uiScanPosLast ]; |
---|
1371 | if( uiBlkPosLast == uiBlkPos ) |
---|
1372 | { |
---|
1373 | break; |
---|
1374 | } |
---|
1375 | } |
---|
1376 | |
---|
1377 | ContextModel * const baseCoeffGroupCtx = m_cCUSigCoeffGroupSCModel.get( 0, isChroma(chType) ); |
---|
1378 | ContextModel * const baseCtx = m_cCUSigSCModel.get( 0, 0 ) + getSignificanceMapContextOffset(compID); |
---|
1379 | |
---|
1380 | const Int iLastScanSet = uiScanPosLast >> MLS_CG_SIZE; |
---|
1381 | UInt c1 = 1; |
---|
1382 | UInt uiGoRiceParam = 0; |
---|
1383 | |
---|
1384 | |
---|
1385 | UInt uiSigCoeffGroupFlag[ MLS_GRP_NUM ]; |
---|
1386 | memset( uiSigCoeffGroupFlag, 0, sizeof(UInt) * MLS_GRP_NUM ); |
---|
1387 | |
---|
1388 | Int iScanPosSig = (Int) uiScanPosLast; |
---|
1389 | for( Int iSubSet = iLastScanSet; iSubSet >= 0; iSubSet-- ) |
---|
1390 | { |
---|
1391 | Int iSubPos = iSubSet << MLS_CG_SIZE; |
---|
1392 | uiGoRiceParam = currentGolombRiceStatistic / RExt__GOLOMB_RICE_INCREMENT_DIVISOR; |
---|
1393 | Bool updateGolombRiceStatistics = bUseGolombRiceParameterAdaptation; //leave the statistics at 0 when not using the adaptation system |
---|
1394 | Int numNonZero = 0; |
---|
1395 | |
---|
1396 | Int lastNZPosInCG = -1; |
---|
1397 | Int firstNZPosInCG = 1 << MLS_CG_SIZE; |
---|
1398 | |
---|
1399 | Bool escapeDataPresentInGroup = false; |
---|
1400 | |
---|
1401 | Int pos[1 << MLS_CG_SIZE]; |
---|
1402 | |
---|
1403 | if( iScanPosSig == (Int) uiScanPosLast ) |
---|
1404 | { |
---|
1405 | lastNZPosInCG = iScanPosSig; |
---|
1406 | firstNZPosInCG = iScanPosSig; |
---|
1407 | iScanPosSig--; |
---|
1408 | pos[ numNonZero ] = uiBlkPosLast; |
---|
1409 | numNonZero = 1; |
---|
1410 | } |
---|
1411 | |
---|
1412 | // decode significant_coeffgroup_flag |
---|
1413 | Int iCGBlkPos = codingParameters.scanCG[ iSubSet ]; |
---|
1414 | Int iCGPosY = iCGBlkPos / codingParameters.widthInGroups; |
---|
1415 | Int iCGPosX = iCGBlkPos - (iCGPosY * codingParameters.widthInGroups); |
---|
1416 | |
---|
1417 | if( iSubSet == iLastScanSet || iSubSet == 0) |
---|
1418 | { |
---|
1419 | uiSigCoeffGroupFlag[ iCGBlkPos ] = 1; |
---|
1420 | } |
---|
1421 | else |
---|
1422 | { |
---|
1423 | UInt uiSigCoeffGroup; |
---|
1424 | UInt uiCtxSig = TComTrQuant::getSigCoeffGroupCtxInc( uiSigCoeffGroupFlag, iCGPosX, iCGPosY, codingParameters.widthInGroups, codingParameters.heightInGroups ); |
---|
1425 | m_pcTDecBinIf->decodeBin( uiSigCoeffGroup, baseCoeffGroupCtx[ uiCtxSig ] RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(ctype_group) ); |
---|
1426 | uiSigCoeffGroupFlag[ iCGBlkPos ] = uiSigCoeffGroup; |
---|
1427 | } |
---|
1428 | |
---|
1429 | // decode significant_coeff_flag |
---|
1430 | const Int patternSigCtx = TComTrQuant::calcPatternSigCtx(uiSigCoeffGroupFlag, iCGPosX, iCGPosY, codingParameters.widthInGroups, codingParameters.heightInGroups); |
---|
1431 | |
---|
1432 | UInt uiBlkPos, uiSig, uiCtxSig; |
---|
1433 | for( ; iScanPosSig >= iSubPos; iScanPosSig-- ) |
---|
1434 | { |
---|
1435 | uiBlkPos = codingParameters.scan[ iScanPosSig ]; |
---|
1436 | uiSig = 0; |
---|
1437 | |
---|
1438 | if( uiSigCoeffGroupFlag[ iCGBlkPos ] ) |
---|
1439 | { |
---|
1440 | if( iScanPosSig > iSubPos || iSubSet == 0 || numNonZero ) |
---|
1441 | { |
---|
1442 | uiCtxSig = TComTrQuant::getSigCtxInc( patternSigCtx, codingParameters, iScanPosSig, uiLog2BlockWidth, uiLog2BlockHeight, chType ); |
---|
1443 | m_pcTDecBinIf->decodeBin( uiSig, baseCtx[ uiCtxSig ] RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(ctype_map) ); |
---|
1444 | } |
---|
1445 | else |
---|
1446 | { |
---|
1447 | uiSig = 1; |
---|
1448 | } |
---|
1449 | } |
---|
1450 | pcCoef[ uiBlkPos ] = uiSig; |
---|
1451 | if( uiSig ) |
---|
1452 | { |
---|
1453 | pos[ numNonZero ] = uiBlkPos; |
---|
1454 | numNonZero ++; |
---|
1455 | if( lastNZPosInCG == -1 ) |
---|
1456 | { |
---|
1457 | lastNZPosInCG = iScanPosSig; |
---|
1458 | } |
---|
1459 | firstNZPosInCG = iScanPosSig; |
---|
1460 | } |
---|
1461 | } |
---|
1462 | |
---|
1463 | if( numNonZero > 0 ) |
---|
1464 | { |
---|
1465 | Bool signHidden = ( lastNZPosInCG - firstNZPosInCG >= SBH_THRESHOLD ); |
---|
1466 | |
---|
1467 | absSum = 0; |
---|
1468 | |
---|
1469 | const UInt uiCtxSet = getContextSetIndex(compID, iSubSet, (c1 == 0)); |
---|
1470 | c1 = 1; |
---|
1471 | UInt uiBin; |
---|
1472 | |
---|
1473 | ContextModel *baseCtxMod = m_cCUOneSCModel.get( 0, 0 ) + (NUM_ONE_FLAG_CTX_PER_SET * uiCtxSet); |
---|
1474 | |
---|
1475 | Int absCoeff[1 << MLS_CG_SIZE]; |
---|
1476 | |
---|
1477 | for ( Int i = 0; i < numNonZero; i++) |
---|
1478 | { |
---|
1479 | absCoeff[i] = 1; |
---|
1480 | } |
---|
1481 | Int numC1Flag = min(numNonZero, C1FLAG_NUMBER); |
---|
1482 | Int firstC2FlagIdx = -1; |
---|
1483 | |
---|
1484 | for( Int idx = 0; idx < numC1Flag; idx++ ) |
---|
1485 | { |
---|
1486 | m_pcTDecBinIf->decodeBin( uiBin, baseCtxMod[c1] RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(ctype_gt1) ); |
---|
1487 | if( uiBin == 1 ) |
---|
1488 | { |
---|
1489 | c1 = 0; |
---|
1490 | if (firstC2FlagIdx == -1) |
---|
1491 | { |
---|
1492 | firstC2FlagIdx = idx; |
---|
1493 | } |
---|
1494 | else //if a greater-than-one has been encountered already this group |
---|
1495 | { |
---|
1496 | escapeDataPresentInGroup = true; |
---|
1497 | } |
---|
1498 | } |
---|
1499 | else if( (c1 < 3) && (c1 > 0) ) |
---|
1500 | { |
---|
1501 | c1++; |
---|
1502 | } |
---|
1503 | absCoeff[ idx ] = uiBin + 1; |
---|
1504 | } |
---|
1505 | |
---|
1506 | if (c1 == 0) |
---|
1507 | { |
---|
1508 | baseCtxMod = m_cCUAbsSCModel.get( 0, 0 ) + (NUM_ABS_FLAG_CTX_PER_SET * uiCtxSet); |
---|
1509 | if ( firstC2FlagIdx != -1) |
---|
1510 | { |
---|
1511 | m_pcTDecBinIf->decodeBin( uiBin, baseCtxMod[0] RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(ctype_gt2) ); |
---|
1512 | absCoeff[ firstC2FlagIdx ] = uiBin + 2; |
---|
1513 | if (uiBin != 0) |
---|
1514 | { |
---|
1515 | escapeDataPresentInGroup = true; |
---|
1516 | } |
---|
1517 | } |
---|
1518 | } |
---|
1519 | |
---|
1520 | escapeDataPresentInGroup = escapeDataPresentInGroup || (numNonZero > C1FLAG_NUMBER); |
---|
1521 | |
---|
1522 | const Bool alignGroup = escapeDataPresentInGroup && alignCABACBeforeBypass; |
---|
1523 | |
---|
1524 | #if RExt__DECODER_DEBUG_BIT_STATISTICS |
---|
1525 | TComCodingStatisticsClassType ctype_signs((alignGroup ? STATS__CABAC_BITS__ALIGNED_SIGN_BIT : STATS__CABAC_BITS__SIGN_BIT ), uiLog2BlockWidth, compID); |
---|
1526 | TComCodingStatisticsClassType ctype_escs ((alignGroup ? STATS__CABAC_BITS__ALIGNED_ESCAPE_BITS : STATS__CABAC_BITS__ESCAPE_BITS), uiLog2BlockWidth, compID); |
---|
1527 | #endif |
---|
1528 | |
---|
1529 | if (alignGroup) |
---|
1530 | { |
---|
1531 | m_pcTDecBinIf->align(); |
---|
1532 | } |
---|
1533 | |
---|
1534 | UInt coeffSigns; |
---|
1535 | if ( signHidden && beValid ) |
---|
1536 | { |
---|
1537 | m_pcTDecBinIf->decodeBinsEP( coeffSigns, numNonZero-1 RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(ctype_signs) ); |
---|
1538 | coeffSigns <<= 32 - (numNonZero-1); |
---|
1539 | } |
---|
1540 | else |
---|
1541 | { |
---|
1542 | m_pcTDecBinIf->decodeBinsEP( coeffSigns, numNonZero RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(ctype_signs) ); |
---|
1543 | coeffSigns <<= 32 - numNonZero; |
---|
1544 | } |
---|
1545 | |
---|
1546 | Int iFirstCoeff2 = 1; |
---|
1547 | if (escapeDataPresentInGroup) |
---|
1548 | { |
---|
1549 | for( Int idx = 0; idx < numNonZero; idx++ ) |
---|
1550 | { |
---|
1551 | UInt baseLevel = (idx < C1FLAG_NUMBER)? (2 + iFirstCoeff2) : 1; |
---|
1552 | |
---|
1553 | if( absCoeff[ idx ] == baseLevel) |
---|
1554 | { |
---|
1555 | UInt uiLevel; |
---|
1556 | xReadCoefRemainExGolomb( uiLevel, uiGoRiceParam, extendedPrecision, maxLog2TrDynamicRange RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(ctype_escs) ); |
---|
1557 | |
---|
1558 | absCoeff[ idx ] = uiLevel + baseLevel; |
---|
1559 | |
---|
1560 | if (absCoeff[idx] > (3 << uiGoRiceParam)) |
---|
1561 | { |
---|
1562 | uiGoRiceParam = bUseGolombRiceParameterAdaptation ? (uiGoRiceParam + 1) : (std::min<UInt>((uiGoRiceParam + 1), 4)); |
---|
1563 | } |
---|
1564 | |
---|
1565 | if (updateGolombRiceStatistics) |
---|
1566 | { |
---|
1567 | const UInt initialGolombRiceParameter = currentGolombRiceStatistic / RExt__GOLOMB_RICE_INCREMENT_DIVISOR; |
---|
1568 | |
---|
1569 | if (uiLevel >= (3 << initialGolombRiceParameter)) |
---|
1570 | { |
---|
1571 | currentGolombRiceStatistic++; |
---|
1572 | } |
---|
1573 | else if (((uiLevel * 2) < (1 << initialGolombRiceParameter)) && (currentGolombRiceStatistic > 0)) |
---|
1574 | { |
---|
1575 | currentGolombRiceStatistic--; |
---|
1576 | } |
---|
1577 | |
---|
1578 | updateGolombRiceStatistics = false; |
---|
1579 | } |
---|
1580 | } |
---|
1581 | |
---|
1582 | if(absCoeff[ idx ] >= 2) |
---|
1583 | { |
---|
1584 | iFirstCoeff2 = 0; |
---|
1585 | } |
---|
1586 | } |
---|
1587 | } |
---|
1588 | |
---|
1589 | for( Int idx = 0; idx < numNonZero; idx++ ) |
---|
1590 | { |
---|
1591 | Int blkPos = pos[ idx ]; |
---|
1592 | // Signs applied later. |
---|
1593 | pcCoef[ blkPos ] = absCoeff[ idx ]; |
---|
1594 | absSum += absCoeff[ idx ]; |
---|
1595 | |
---|
1596 | if ( idx == numNonZero-1 && signHidden && beValid ) |
---|
1597 | { |
---|
1598 | // Infer sign of 1st element. |
---|
1599 | if (absSum&0x1) |
---|
1600 | { |
---|
1601 | pcCoef[ blkPos ] = -pcCoef[ blkPos ]; |
---|
1602 | } |
---|
1603 | } |
---|
1604 | else |
---|
1605 | { |
---|
1606 | Int sign = static_cast<Int>( coeffSigns ) >> 31; |
---|
1607 | pcCoef[ blkPos ] = ( pcCoef[ blkPos ] ^ sign ) - sign; |
---|
1608 | coeffSigns <<= 1; |
---|
1609 | } |
---|
1610 | } |
---|
1611 | } |
---|
1612 | } |
---|
1613 | |
---|
1614 | #if ENVIRONMENT_VARIABLE_DEBUG_AND_TEST |
---|
1615 | printSBACCoeffData(uiPosLastX, uiPosLastY, uiWidth, uiHeight, compID, uiAbsPartIdx, codingParameters.scanType, pcCoef); |
---|
1616 | #endif |
---|
1617 | |
---|
1618 | return; |
---|
1619 | } |
---|
1620 | |
---|
1621 | Void TDecSbac::parseSaoMaxUvlc ( UInt& val, UInt maxSymbol ) |
---|
1622 | { |
---|
1623 | if (maxSymbol == 0) |
---|
1624 | { |
---|
1625 | val = 0; |
---|
1626 | return; |
---|
1627 | } |
---|
1628 | |
---|
1629 | UInt code; |
---|
1630 | Int i; |
---|
1631 | m_pcTDecBinIf->decodeBinEP( code RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(STATS__CABAC_BITS__SAO) ); |
---|
1632 | if ( code == 0 ) |
---|
1633 | { |
---|
1634 | val = 0; |
---|
1635 | return; |
---|
1636 | } |
---|
1637 | |
---|
1638 | i=1; |
---|
1639 | while (1) |
---|
1640 | { |
---|
1641 | m_pcTDecBinIf->decodeBinEP( code RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(STATS__CABAC_BITS__SAO) ); |
---|
1642 | if ( code == 0 ) |
---|
1643 | { |
---|
1644 | break; |
---|
1645 | } |
---|
1646 | i++; |
---|
1647 | if (i == maxSymbol) |
---|
1648 | { |
---|
1649 | break; |
---|
1650 | } |
---|
1651 | } |
---|
1652 | |
---|
1653 | val = i; |
---|
1654 | } |
---|
1655 | |
---|
1656 | Void TDecSbac::parseSaoUflc (UInt uiLength, UInt& riVal) |
---|
1657 | { |
---|
1658 | m_pcTDecBinIf->decodeBinsEP ( riVal, uiLength RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(STATS__CABAC_BITS__SAO) ); |
---|
1659 | } |
---|
1660 | |
---|
1661 | Void TDecSbac::parseSaoMerge (UInt& ruiVal) |
---|
1662 | { |
---|
1663 | UInt uiCode; |
---|
1664 | m_pcTDecBinIf->decodeBin( uiCode, m_cSaoMergeSCModel.get( 0, 0, 0 ) RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(STATS__CABAC_BITS__SAO) ); |
---|
1665 | ruiVal = (Int)uiCode; |
---|
1666 | } |
---|
1667 | |
---|
1668 | Void TDecSbac::parseSaoTypeIdx (UInt& ruiVal) |
---|
1669 | { |
---|
1670 | UInt uiCode; |
---|
1671 | m_pcTDecBinIf->decodeBin( uiCode, m_cSaoTypeIdxSCModel.get( 0, 0, 0 ) RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(STATS__CABAC_BITS__SAO) ); |
---|
1672 | if (uiCode == 0) |
---|
1673 | { |
---|
1674 | ruiVal = 0; |
---|
1675 | } |
---|
1676 | else |
---|
1677 | { |
---|
1678 | m_pcTDecBinIf->decodeBinEP( uiCode RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(STATS__CABAC_BITS__SAO) ); |
---|
1679 | if (uiCode == 0) |
---|
1680 | { |
---|
1681 | ruiVal = 1; |
---|
1682 | } |
---|
1683 | else |
---|
1684 | { |
---|
1685 | ruiVal = 2; |
---|
1686 | } |
---|
1687 | } |
---|
1688 | } |
---|
1689 | |
---|
1690 | Void TDecSbac::parseSaoSign(UInt& val) |
---|
1691 | { |
---|
1692 | m_pcTDecBinIf->decodeBinEP ( val RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(STATS__CABAC_BITS__SAO) ); |
---|
1693 | } |
---|
1694 | |
---|
1695 | Void TDecSbac::parseSAOBlkParam (SAOBlkParam& saoBlkParam |
---|
1696 | , Bool* sliceEnabled |
---|
1697 | , Bool leftMergeAvail |
---|
1698 | , Bool aboveMergeAvail |
---|
1699 | , const BitDepths &bitDepths |
---|
1700 | ) |
---|
1701 | { |
---|
1702 | UInt uiSymbol; |
---|
1703 | |
---|
1704 | Bool isLeftMerge = false; |
---|
1705 | Bool isAboveMerge= false; |
---|
1706 | |
---|
1707 | if(leftMergeAvail) |
---|
1708 | { |
---|
1709 | parseSaoMerge(uiSymbol); //sao_merge_left_flag |
---|
1710 | isLeftMerge = (uiSymbol?true:false); |
---|
1711 | } |
---|
1712 | |
---|
1713 | if( aboveMergeAvail && !isLeftMerge) |
---|
1714 | { |
---|
1715 | parseSaoMerge(uiSymbol); //sao_merge_up_flag |
---|
1716 | isAboveMerge = (uiSymbol?true:false); |
---|
1717 | } |
---|
1718 | |
---|
1719 | if(isLeftMerge || isAboveMerge) //merge mode |
---|
1720 | { |
---|
1721 | for (UInt componentIndex = 0; componentIndex < MAX_NUM_COMPONENT; componentIndex++) |
---|
1722 | { |
---|
1723 | saoBlkParam[componentIndex].modeIdc = (sliceEnabled[componentIndex]) ? SAO_MODE_MERGE : SAO_MODE_OFF; |
---|
1724 | saoBlkParam[componentIndex].typeIdc = (isLeftMerge)?SAO_MERGE_LEFT:SAO_MERGE_ABOVE; |
---|
1725 | } |
---|
1726 | } |
---|
1727 | else //new or off mode |
---|
1728 | { |
---|
1729 | for(Int compId=COMPONENT_Y; compId < MAX_NUM_COMPONENT; compId++) |
---|
1730 | { |
---|
1731 | const ComponentID compIdx=ComponentID(compId); |
---|
1732 | const ComponentID firstCompOfChType = getFirstComponentOfChannel(toChannelType(compIdx)); |
---|
1733 | SAOOffset& ctbParam = saoBlkParam[compIdx]; |
---|
1734 | #if O0043_BEST_EFFORT_DECODING |
---|
1735 | const Int bitDepthOrig = bitDepths.stream[toChannelType(compIdx)]; |
---|
1736 | const Int forceBitDepthAdjust = bitDepthOrig - bitDepths.recon[toChannelType(compIdx)]; |
---|
1737 | #else |
---|
1738 | const Int bitDepthOrig = bitDepths.recon[toChannelType(compIdx)]; |
---|
1739 | #endif |
---|
1740 | const Int maxOffsetQVal=TComSampleAdaptiveOffset::getMaxOffsetQVal(bitDepthOrig); |
---|
1741 | if(!sliceEnabled[compIdx]) |
---|
1742 | { |
---|
1743 | //off |
---|
1744 | ctbParam.modeIdc = SAO_MODE_OFF; |
---|
1745 | continue; |
---|
1746 | } |
---|
1747 | |
---|
1748 | //type |
---|
1749 | if(compIdx == firstCompOfChType) |
---|
1750 | { |
---|
1751 | parseSaoTypeIdx(uiSymbol); //sao_type_idx_luma or sao_type_idx_chroma |
---|
1752 | |
---|
1753 | assert(uiSymbol ==0 || uiSymbol ==1 || uiSymbol ==2); |
---|
1754 | |
---|
1755 | if(uiSymbol ==0) //OFF |
---|
1756 | { |
---|
1757 | ctbParam.modeIdc = SAO_MODE_OFF; |
---|
1758 | } |
---|
1759 | else if(uiSymbol == 1) //BO |
---|
1760 | { |
---|
1761 | ctbParam.modeIdc = SAO_MODE_NEW; |
---|
1762 | ctbParam.typeIdc = SAO_TYPE_START_BO; |
---|
1763 | } |
---|
1764 | else //2, EO |
---|
1765 | { |
---|
1766 | ctbParam.modeIdc = SAO_MODE_NEW; |
---|
1767 | ctbParam.typeIdc = SAO_TYPE_START_EO; |
---|
1768 | } |
---|
1769 | |
---|
1770 | } |
---|
1771 | else //Cr, follow Cb SAO type |
---|
1772 | { |
---|
1773 | ctbParam.modeIdc = saoBlkParam[COMPONENT_Cb].modeIdc; |
---|
1774 | ctbParam.typeIdc = saoBlkParam[COMPONENT_Cb].typeIdc; |
---|
1775 | } |
---|
1776 | |
---|
1777 | if(ctbParam.modeIdc == SAO_MODE_NEW) |
---|
1778 | { |
---|
1779 | Int offset[4]; |
---|
1780 | for(Int i=0; i< 4; i++) |
---|
1781 | { |
---|
1782 | parseSaoMaxUvlc(uiSymbol, maxOffsetQVal ); //sao_offset_abs |
---|
1783 | offset[i] = (Int)uiSymbol; |
---|
1784 | } |
---|
1785 | |
---|
1786 | if(ctbParam.typeIdc == SAO_TYPE_START_BO) |
---|
1787 | { |
---|
1788 | for(Int i=0; i< 4; i++) |
---|
1789 | { |
---|
1790 | if(offset[i] != 0) |
---|
1791 | { |
---|
1792 | parseSaoSign(uiSymbol); //sao_offset_sign |
---|
1793 | if(uiSymbol) |
---|
1794 | { |
---|
1795 | #if O0043_BEST_EFFORT_DECODING |
---|
1796 | offset[i] >>= forceBitDepthAdjust; |
---|
1797 | #endif |
---|
1798 | offset[i] = -offset[i]; |
---|
1799 | } |
---|
1800 | } |
---|
1801 | } |
---|
1802 | parseSaoUflc(NUM_SAO_BO_CLASSES_LOG2, uiSymbol ); //sao_band_position |
---|
1803 | ctbParam.typeAuxInfo = uiSymbol; |
---|
1804 | |
---|
1805 | for(Int i=0; i<4; i++) |
---|
1806 | { |
---|
1807 | ctbParam.offset[(ctbParam.typeAuxInfo+i)%MAX_NUM_SAO_CLASSES] = offset[i]; |
---|
1808 | } |
---|
1809 | |
---|
1810 | } |
---|
1811 | else //EO |
---|
1812 | { |
---|
1813 | ctbParam.typeAuxInfo = 0; |
---|
1814 | |
---|
1815 | if(firstCompOfChType == compIdx) |
---|
1816 | { |
---|
1817 | parseSaoUflc(NUM_SAO_EO_TYPES_LOG2, uiSymbol ); //sao_eo_class_luma or sao_eo_class_chroma |
---|
1818 | ctbParam.typeIdc += uiSymbol; |
---|
1819 | } |
---|
1820 | else |
---|
1821 | { |
---|
1822 | ctbParam.typeIdc = saoBlkParam[firstCompOfChType].typeIdc; |
---|
1823 | } |
---|
1824 | ctbParam.offset[SAO_CLASS_EO_FULL_VALLEY] = offset[0]; |
---|
1825 | ctbParam.offset[SAO_CLASS_EO_HALF_VALLEY] = offset[1]; |
---|
1826 | ctbParam.offset[SAO_CLASS_EO_PLAIN ] = 0; |
---|
1827 | ctbParam.offset[SAO_CLASS_EO_HALF_PEAK ] = -offset[2]; |
---|
1828 | ctbParam.offset[SAO_CLASS_EO_FULL_PEAK ] = -offset[3]; |
---|
1829 | } |
---|
1830 | } |
---|
1831 | } |
---|
1832 | } |
---|
1833 | } |
---|
1834 | |
---|
1835 | /** |
---|
1836 | - Initialize our contexts from the nominated source. |
---|
1837 | . |
---|
1838 | \param pSrc Contexts to be copied. |
---|
1839 | */ |
---|
1840 | Void TDecSbac::xCopyContextsFrom( const TDecSbac* pSrc ) |
---|
1841 | { |
---|
1842 | memcpy(m_contextModels, pSrc->m_contextModels, m_numContextModels*sizeof(m_contextModels[0])); |
---|
1843 | memcpy(m_golombRiceAdaptationStatistics, pSrc->m_golombRiceAdaptationStatistics, (sizeof(UInt) * RExt__GOLOMB_RICE_ADAPTATION_STATISTICS_SETS)); |
---|
1844 | } |
---|
1845 | |
---|
1846 | Void TDecSbac::xCopyFrom( const TDecSbac* pSrc ) |
---|
1847 | { |
---|
1848 | m_pcTDecBinIf->copyState( pSrc->m_pcTDecBinIf ); |
---|
1849 | xCopyContextsFrom( pSrc ); |
---|
1850 | } |
---|
1851 | |
---|
1852 | Void TDecSbac::load ( const TDecSbac* pSrc ) |
---|
1853 | { |
---|
1854 | xCopyFrom(pSrc); |
---|
1855 | } |
---|
1856 | |
---|
1857 | Void TDecSbac::loadContexts ( const TDecSbac* pSrc ) |
---|
1858 | { |
---|
1859 | xCopyContextsFrom(pSrc); |
---|
1860 | } |
---|
1861 | |
---|
1862 | /** Performs CABAC decoding of the explicit RDPCM mode |
---|
1863 | * \param rTu current TU data structure |
---|
1864 | * \param compID component identifier |
---|
1865 | */ |
---|
1866 | Void TDecSbac::parseExplicitRdpcmMode( TComTU &rTu, ComponentID compID ) |
---|
1867 | { |
---|
1868 | TComDataCU* cu = rTu.getCU(); |
---|
1869 | const UInt absPartIdx=rTu.GetAbsPartIdxTU(compID); |
---|
1870 | const TComRectangle &rect = rTu.getRect(compID); |
---|
1871 | const UInt tuHeight = g_aucConvertToBit[rect.height]; |
---|
1872 | const UInt tuWidth = g_aucConvertToBit[rect.width]; |
---|
1873 | UInt code = 0; |
---|
1874 | |
---|
1875 | assert(tuHeight == tuWidth); |
---|
1876 | |
---|
1877 | #if RExt__DECODER_DEBUG_BIT_STATISTICS |
---|
1878 | const TComCodingStatisticsClassType ctype(STATS__EXPLICIT_RDPCM_BITS, g_aucConvertToBit[cu->getSlice()->getSPS()->getMaxCUWidth()>>rTu.GetTransformDepthTotal()]+2); |
---|
1879 | #endif |
---|
1880 | |
---|
1881 | m_pcTDecBinIf->decodeBin(code, m_explicitRdpcmFlagSCModel.get (0, toChannelType(compID), 0) RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(ctype)); |
---|
1882 | |
---|
1883 | if(code == 0) |
---|
1884 | { |
---|
1885 | cu->setExplicitRdpcmModePartRange( RDPCM_OFF, compID, absPartIdx, rTu.GetAbsPartIdxNumParts(compID)); |
---|
1886 | } |
---|
1887 | else |
---|
1888 | { |
---|
1889 | m_pcTDecBinIf->decodeBin(code, m_explicitRdpcmDirSCModel.get (0, toChannelType(compID), 0) RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(ctype)); |
---|
1890 | if(code == 0) |
---|
1891 | { |
---|
1892 | cu->setExplicitRdpcmModePartRange( RDPCM_HOR, compID, absPartIdx, rTu.GetAbsPartIdxNumParts(compID)); |
---|
1893 | } |
---|
1894 | else |
---|
1895 | { |
---|
1896 | cu->setExplicitRdpcmModePartRange( RDPCM_VER, compID, absPartIdx, rTu.GetAbsPartIdxNumParts(compID)); |
---|
1897 | } |
---|
1898 | } |
---|
1899 | } |
---|
1900 | |
---|
1901 | |
---|
1902 | //! \} |
---|