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-2017, 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 | #if NH_3D |
---|
70 | , m_cCUDISFlagSCModel ( 1, 1, NUM_DIS_FLAG_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
71 | , m_cCUDISTypeSCModel ( 1, 1, NUM_DIS_TYPE_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
72 | #endif |
---|
73 | , m_cCUMergeFlagExtSCModel ( 1, 1, NUM_MERGE_FLAG_EXT_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
74 | , m_cCUMergeIdxExtSCModel ( 1, 1, NUM_MERGE_IDX_EXT_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
75 | #if NH_3D |
---|
76 | , m_cCUPUARPWSCModel ( 1, 1, NUM_ARPW_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
77 | , m_cCUICFlagSCModel ( 1, 1, NUM_IC_FLAG_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
78 | #endif |
---|
79 | , m_cCUPartSizeSCModel ( 1, 1, NUM_PART_SIZE_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
80 | , m_cCUPredModeSCModel ( 1, 1, NUM_PRED_MODE_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
81 | , m_cCUIntraPredSCModel ( 1, 1, NUM_INTRA_PREDICT_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
82 | , m_cCUChromaPredSCModel ( 1, 1, NUM_CHROMA_PRED_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
83 | , m_cCUDeltaQpSCModel ( 1, 1, NUM_DELTA_QP_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
84 | , m_cCUInterDirSCModel ( 1, 1, NUM_INTER_DIR_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
85 | , m_cCURefPicSCModel ( 1, 1, NUM_REF_NO_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
86 | , m_cCUMvdSCModel ( 1, 1, NUM_MV_RES_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
87 | , m_cCUQtCbfSCModel ( 1, NUM_QT_CBF_CTX_SETS, NUM_QT_CBF_CTX_PER_SET , m_contextModels + m_numContextModels, m_numContextModels) |
---|
88 | , m_cCUTransSubdivFlagSCModel ( 1, 1, NUM_TRANS_SUBDIV_FLAG_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
89 | , m_cCUQtRootCbfSCModel ( 1, 1, NUM_QT_ROOT_CBF_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
90 | , m_cCUSigCoeffGroupSCModel ( 1, 2, NUM_SIG_CG_FLAG_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
91 | , m_cCUSigSCModel ( 1, 1, NUM_SIG_FLAG_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
92 | , m_cCuCtxLastX ( 1, NUM_CTX_LAST_FLAG_SETS, NUM_CTX_LAST_FLAG_XY , m_contextModels + m_numContextModels, m_numContextModels) |
---|
93 | , m_cCuCtxLastY ( 1, NUM_CTX_LAST_FLAG_SETS, NUM_CTX_LAST_FLAG_XY , m_contextModels + m_numContextModels, m_numContextModels) |
---|
94 | , m_cCUOneSCModel ( 1, 1, NUM_ONE_FLAG_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
95 | , m_cCUAbsSCModel ( 1, 1, NUM_ABS_FLAG_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
96 | , m_cMVPIdxSCModel ( 1, 1, NUM_MVP_IDX_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
97 | , m_cSaoMergeSCModel ( 1, 1, NUM_SAO_MERGE_FLAG_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
98 | , m_cSaoTypeIdxSCModel ( 1, 1, NUM_SAO_TYPE_IDX_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
99 | , m_cTransformSkipSCModel ( 1, MAX_NUM_CHANNEL_TYPE, NUM_TRANSFORMSKIP_FLAG_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
100 | , m_CUTransquantBypassFlagSCModel ( 1, 1, NUM_CU_TRANSQUANT_BYPASS_FLAG_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
101 | , m_explicitRdpcmFlagSCModel ( 1, MAX_NUM_CHANNEL_TYPE, NUM_EXPLICIT_RDPCM_FLAG_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
102 | , m_explicitRdpcmDirSCModel ( 1, MAX_NUM_CHANNEL_TYPE, NUM_EXPLICIT_RDPCM_DIR_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
103 | , m_cCrossComponentPredictionSCModel ( 1, 1, NUM_CROSS_COMPONENT_PREDICTION_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
104 | , m_ChromaQpAdjFlagSCModel ( 1, 1, NUM_CHROMA_QP_ADJ_FLAG_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
105 | , m_ChromaQpAdjIdcSCModel ( 1, 1, NUM_CHROMA_QP_ADJ_IDC_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
106 | |
---|
107 | #if NH_3D |
---|
108 | , m_cNotDmmFlagSCModel ( 1, 1, NUM_NOTDMM_FLAG_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
109 | , m_cDmmModeSCModel ( 1, 1, NUM_DMM_MODE_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
110 | , m_cDdcDataSCModel ( 1, 1, NUM_DDC_DATA_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
111 | , m_cSDCFlagSCModel ( 1, 1, NUM_SDC_FLAG_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
112 | , m_cSDCResidualFlagSCModel ( 1, 1, SDC_NUM_RESIDUAL_FLAG_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
113 | , m_cSDCResidualSCModel ( 1, 1, SDC_NUM_RESIDUAL_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
114 | , m_cDdcFlagSCModel ( 1, 1, NUM_DDC_FLAG_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
115 | , m_cDBBPFlagSCModel ( 1, 1, DBBP_NUM_FLAG_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
116 | #endif |
---|
117 | |
---|
118 | { |
---|
119 | assert( m_numContextModels <= MAX_NUM_CTX_MOD ); |
---|
120 | } |
---|
121 | |
---|
122 | TDecSbac::~TDecSbac() |
---|
123 | { |
---|
124 | } |
---|
125 | |
---|
126 | // ==================================================================================================================== |
---|
127 | // Public member functions |
---|
128 | // ==================================================================================================================== |
---|
129 | |
---|
130 | Void TDecSbac::resetEntropy(TComSlice* pSlice) |
---|
131 | { |
---|
132 | SliceType sliceType = pSlice->getSliceType(); |
---|
133 | Int qp = pSlice->getSliceQp(); |
---|
134 | |
---|
135 | if (pSlice->getPPS()->getCabacInitPresentFlag() && pSlice->getCabacInitFlag()) |
---|
136 | { |
---|
137 | switch (sliceType) |
---|
138 | { |
---|
139 | case P_SLICE: // change initialization table to B_SLICE initialization |
---|
140 | sliceType = B_SLICE; |
---|
141 | break; |
---|
142 | case B_SLICE: // change initialization table to P_SLICE initialization |
---|
143 | sliceType = P_SLICE; |
---|
144 | break; |
---|
145 | default : // should not occur |
---|
146 | assert(0); |
---|
147 | break; |
---|
148 | } |
---|
149 | } |
---|
150 | |
---|
151 | m_cCUSplitFlagSCModel.initBuffer ( sliceType, qp, (UChar*)INIT_SPLIT_FLAG ); |
---|
152 | m_cCUSkipFlagSCModel.initBuffer ( sliceType, qp, (UChar*)INIT_SKIP_FLAG ); |
---|
153 | #if NH_3D |
---|
154 | m_cCUDISFlagSCModel.initBuffer ( sliceType, qp, (UChar*)INIT_DIS_FLAG ); |
---|
155 | m_cCUDISTypeSCModel.initBuffer ( sliceType, qp, (UChar*)INIT_DIS_TYPE ); |
---|
156 | #endif |
---|
157 | m_cCUMergeFlagExtSCModel.initBuffer ( sliceType, qp, (UChar*)INIT_MERGE_FLAG_EXT ); |
---|
158 | m_cCUMergeIdxExtSCModel.initBuffer ( sliceType, qp, (UChar*)INIT_MERGE_IDX_EXT ); |
---|
159 | #if NH_3D |
---|
160 | m_cCUPUARPWSCModel.initBuffer ( sliceType, qp, (UChar*)INIT_ARPW ); |
---|
161 | m_cCUICFlagSCModel.initBuffer ( sliceType, qp, (UChar*)INIT_IC_FLAG ); |
---|
162 | #endif |
---|
163 | m_cCUPartSizeSCModel.initBuffer ( sliceType, qp, (UChar*)INIT_PART_SIZE ); |
---|
164 | m_cCUPredModeSCModel.initBuffer ( sliceType, qp, (UChar*)INIT_PRED_MODE ); |
---|
165 | m_cCUIntraPredSCModel.initBuffer ( sliceType, qp, (UChar*)INIT_INTRA_PRED_MODE ); |
---|
166 | m_cCUChromaPredSCModel.initBuffer ( sliceType, qp, (UChar*)INIT_CHROMA_PRED_MODE ); |
---|
167 | m_cCUInterDirSCModel.initBuffer ( sliceType, qp, (UChar*)INIT_INTER_DIR ); |
---|
168 | m_cCUMvdSCModel.initBuffer ( sliceType, qp, (UChar*)INIT_MVD ); |
---|
169 | m_cCURefPicSCModel.initBuffer ( sliceType, qp, (UChar*)INIT_REF_PIC ); |
---|
170 | m_cCUDeltaQpSCModel.initBuffer ( sliceType, qp, (UChar*)INIT_DQP ); |
---|
171 | m_cCUQtCbfSCModel.initBuffer ( sliceType, qp, (UChar*)INIT_QT_CBF ); |
---|
172 | m_cCUQtRootCbfSCModel.initBuffer ( sliceType, qp, (UChar*)INIT_QT_ROOT_CBF ); |
---|
173 | m_cCUSigCoeffGroupSCModel.initBuffer ( sliceType, qp, (UChar*)INIT_SIG_CG_FLAG ); |
---|
174 | m_cCUSigSCModel.initBuffer ( sliceType, qp, (UChar*)INIT_SIG_FLAG ); |
---|
175 | m_cCuCtxLastX.initBuffer ( sliceType, qp, (UChar*)INIT_LAST ); |
---|
176 | m_cCuCtxLastY.initBuffer ( sliceType, qp, (UChar*)INIT_LAST ); |
---|
177 | m_cCUOneSCModel.initBuffer ( sliceType, qp, (UChar*)INIT_ONE_FLAG ); |
---|
178 | m_cCUAbsSCModel.initBuffer ( sliceType, qp, (UChar*)INIT_ABS_FLAG ); |
---|
179 | m_cMVPIdxSCModel.initBuffer ( sliceType, qp, (UChar*)INIT_MVP_IDX ); |
---|
180 | m_cSaoMergeSCModel.initBuffer ( sliceType, qp, (UChar*)INIT_SAO_MERGE_FLAG ); |
---|
181 | m_cSaoTypeIdxSCModel.initBuffer ( sliceType, qp, (UChar*)INIT_SAO_TYPE_IDX ); |
---|
182 | m_cCUTransSubdivFlagSCModel.initBuffer ( sliceType, qp, (UChar*)INIT_TRANS_SUBDIV_FLAG ); |
---|
183 | m_cTransformSkipSCModel.initBuffer ( sliceType, qp, (UChar*)INIT_TRANSFORMSKIP_FLAG ); |
---|
184 | m_CUTransquantBypassFlagSCModel.initBuffer ( sliceType, qp, (UChar*)INIT_CU_TRANSQUANT_BYPASS_FLAG ); |
---|
185 | m_explicitRdpcmFlagSCModel.initBuffer ( sliceType, qp, (UChar*)INIT_EXPLICIT_RDPCM_FLAG); |
---|
186 | m_explicitRdpcmDirSCModel.initBuffer ( sliceType, qp, (UChar*)INIT_EXPLICIT_RDPCM_DIR); |
---|
187 | m_cCrossComponentPredictionSCModel.initBuffer ( sliceType, qp, (UChar*)INIT_CROSS_COMPONENT_PREDICTION ); |
---|
188 | m_ChromaQpAdjFlagSCModel.initBuffer ( sliceType, qp, (UChar*)INIT_CHROMA_QP_ADJ_FLAG ); |
---|
189 | m_ChromaQpAdjIdcSCModel.initBuffer ( sliceType, qp, (UChar*)INIT_CHROMA_QP_ADJ_IDC ); |
---|
190 | #if NH_3D |
---|
191 | m_cNotDmmFlagSCModel.initBuffer ( sliceType, qp, (UChar*)INIT_NOTDMM_FLAG ); |
---|
192 | m_cDmmModeSCModel.initBuffer ( sliceType, qp, (UChar*)INIT_DMM_MODE ); |
---|
193 | m_cDdcDataSCModel.initBuffer ( sliceType, qp, (UChar*)INIT_DDC_DATA ); |
---|
194 | m_cSDCFlagSCModel.initBuffer ( sliceType, qp, (UChar*)INIT_SDC_FLAG ); |
---|
195 | m_cSDCResidualFlagSCModel.initBuffer ( sliceType, qp, (UChar*)INIT_SDC_RESIDUAL_FLAG ); |
---|
196 | m_cSDCResidualSCModel.initBuffer ( sliceType, qp, (UChar*)INIT_SDC_RESIDUAL ); |
---|
197 | m_cDdcFlagSCModel.initBuffer ( sliceType, qp, (UChar*)INIT_DDC_FLAG ); |
---|
198 | m_cDBBPFlagSCModel.initBuffer ( sliceType, qp, (UChar*)INIT_DBBP_FLAG ); |
---|
199 | #endif |
---|
200 | |
---|
201 | for (UInt statisticIndex = 0; statisticIndex < RExt__GOLOMB_RICE_ADAPTATION_STATISTICS_SETS ; statisticIndex++) |
---|
202 | { |
---|
203 | m_golombRiceAdaptationStatistics[statisticIndex] = 0; |
---|
204 | } |
---|
205 | |
---|
206 | m_pcTDecBinIf->start(); |
---|
207 | } |
---|
208 | |
---|
209 | Void TDecSbac::parseTerminatingBit( UInt& ruiBit ) |
---|
210 | { |
---|
211 | m_pcTDecBinIf->decodeBinTrm( ruiBit ); |
---|
212 | if ( ruiBit == 1 ) |
---|
213 | { |
---|
214 | m_pcTDecBinIf->finish(); |
---|
215 | |
---|
216 | #if RExt__DECODER_DEBUG_BIT_STATISTICS |
---|
217 | TComCodingStatistics::IncrementStatisticEP(STATS__TRAILING_BITS, m_pcBitstream->readOutTrailingBits(),0); |
---|
218 | #else |
---|
219 | m_pcBitstream->readOutTrailingBits(); |
---|
220 | #endif |
---|
221 | } |
---|
222 | } |
---|
223 | |
---|
224 | |
---|
225 | |
---|
226 | Void TDecSbac::parseRemainingBytes( Bool noTrailingBytesExpected ) |
---|
227 | { |
---|
228 | if (noTrailingBytesExpected) |
---|
229 | { |
---|
230 | const UInt numberOfRemainingSubstreamBytes=m_pcBitstream->getNumBitsLeft(); |
---|
231 | assert (numberOfRemainingSubstreamBytes == 0); |
---|
232 | } |
---|
233 | else |
---|
234 | { |
---|
235 | while (m_pcBitstream->getNumBitsLeft()) |
---|
236 | { |
---|
237 | UInt trailingNullByte=m_pcBitstream->readByte(); |
---|
238 | if (trailingNullByte!=0) |
---|
239 | { |
---|
240 | printf("Trailing byte should be 0, but has value %02x\n", trailingNullByte); |
---|
241 | assert(trailingNullByte==0); |
---|
242 | } |
---|
243 | } |
---|
244 | } |
---|
245 | } |
---|
246 | |
---|
247 | #if RExt__DECODER_DEBUG_BIT_STATISTICS |
---|
248 | Void TDecSbac::xReadUnaryMaxSymbol( UInt& ruiSymbol, ContextModel* pcSCModel, Int iOffset, UInt uiMaxSymbol, const class TComCodingStatisticsClassType &whichStat ) |
---|
249 | #else |
---|
250 | Void TDecSbac::xReadUnaryMaxSymbol( UInt& ruiSymbol, ContextModel* pcSCModel, Int iOffset, UInt uiMaxSymbol ) |
---|
251 | #endif |
---|
252 | { |
---|
253 | if (uiMaxSymbol == 0) |
---|
254 | { |
---|
255 | ruiSymbol = 0; |
---|
256 | return; |
---|
257 | } |
---|
258 | |
---|
259 | m_pcTDecBinIf->decodeBin( ruiSymbol, pcSCModel[0] RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(whichStat) ); |
---|
260 | |
---|
261 | if( ruiSymbol == 0 || uiMaxSymbol == 1 ) |
---|
262 | { |
---|
263 | return; |
---|
264 | } |
---|
265 | |
---|
266 | UInt uiSymbol = 0; |
---|
267 | UInt uiCont; |
---|
268 | |
---|
269 | do |
---|
270 | { |
---|
271 | m_pcTDecBinIf->decodeBin( uiCont, pcSCModel[ iOffset ] RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(whichStat) ); |
---|
272 | uiSymbol++; |
---|
273 | } while( uiCont && ( uiSymbol < uiMaxSymbol - 1 ) ); |
---|
274 | |
---|
275 | if( uiCont && ( uiSymbol == uiMaxSymbol - 1 ) ) |
---|
276 | { |
---|
277 | uiSymbol++; |
---|
278 | } |
---|
279 | |
---|
280 | ruiSymbol = uiSymbol; |
---|
281 | } |
---|
282 | |
---|
283 | #if RExt__DECODER_DEBUG_BIT_STATISTICS |
---|
284 | Void TDecSbac::xReadEpExGolomb( UInt& ruiSymbol, UInt uiCount, const class TComCodingStatisticsClassType &whichStat ) |
---|
285 | #else |
---|
286 | Void TDecSbac::xReadEpExGolomb( UInt& ruiSymbol, UInt uiCount ) |
---|
287 | #endif |
---|
288 | { |
---|
289 | UInt uiSymbol = 0; |
---|
290 | UInt uiBit = 1; |
---|
291 | |
---|
292 | while( uiBit ) |
---|
293 | { |
---|
294 | m_pcTDecBinIf->decodeBinEP( uiBit RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(whichStat) ); |
---|
295 | uiSymbol += uiBit << uiCount++; |
---|
296 | } |
---|
297 | |
---|
298 | if ( --uiCount ) |
---|
299 | { |
---|
300 | UInt bins; |
---|
301 | m_pcTDecBinIf->decodeBinsEP( bins, uiCount RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(whichStat) ); |
---|
302 | uiSymbol += bins; |
---|
303 | } |
---|
304 | |
---|
305 | ruiSymbol = uiSymbol; |
---|
306 | } |
---|
307 | |
---|
308 | #if RExt__DECODER_DEBUG_BIT_STATISTICS |
---|
309 | Void TDecSbac::xReadUnarySymbol( UInt& ruiSymbol, ContextModel* pcSCModel, Int iOffset, const class TComCodingStatisticsClassType &whichStat ) |
---|
310 | #else |
---|
311 | Void TDecSbac::xReadUnarySymbol( UInt& ruiSymbol, ContextModel* pcSCModel, Int iOffset ) |
---|
312 | #endif |
---|
313 | { |
---|
314 | m_pcTDecBinIf->decodeBin( ruiSymbol, pcSCModel[0] RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(whichStat)); |
---|
315 | |
---|
316 | if( !ruiSymbol ) |
---|
317 | { |
---|
318 | return; |
---|
319 | } |
---|
320 | |
---|
321 | UInt uiSymbol = 0; |
---|
322 | UInt uiCont; |
---|
323 | |
---|
324 | do |
---|
325 | { |
---|
326 | m_pcTDecBinIf->decodeBin( uiCont, pcSCModel[ iOffset ] RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(whichStat)); |
---|
327 | uiSymbol++; |
---|
328 | } while( uiCont ); |
---|
329 | |
---|
330 | ruiSymbol = uiSymbol; |
---|
331 | } |
---|
332 | |
---|
333 | |
---|
334 | /** Parsing of coeff_abs_level_remaing |
---|
335 | * \param rSymbol reference to coeff_abs_level_remaing |
---|
336 | * \param rParam reference to parameter |
---|
337 | * \param useLimitedPrefixLength |
---|
338 | * \param maxLog2TrDynamicRange |
---|
339 | */ |
---|
340 | #if RExt__DECODER_DEBUG_BIT_STATISTICS |
---|
341 | Void TDecSbac::xReadCoefRemainExGolomb ( UInt &rSymbol, UInt &rParam, const Bool useLimitedPrefixLength, const Int maxLog2TrDynamicRange, const class TComCodingStatisticsClassType &whichStat ) |
---|
342 | #else |
---|
343 | Void TDecSbac::xReadCoefRemainExGolomb ( UInt &rSymbol, UInt &rParam, const Bool useLimitedPrefixLength, const Int maxLog2TrDynamicRange ) |
---|
344 | #endif |
---|
345 | { |
---|
346 | UInt prefix = 0; |
---|
347 | UInt codeWord = 0; |
---|
348 | |
---|
349 | if (useLimitedPrefixLength) |
---|
350 | { |
---|
351 | const UInt longestPossiblePrefix = (32 - (COEF_REMAIN_BIN_REDUCTION + maxLog2TrDynamicRange)) + COEF_REMAIN_BIN_REDUCTION; |
---|
352 | |
---|
353 | do |
---|
354 | { |
---|
355 | prefix++; |
---|
356 | m_pcTDecBinIf->decodeBinEP( codeWord RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(whichStat) ); |
---|
357 | } while((codeWord != 0) && (prefix < longestPossiblePrefix)); |
---|
358 | } |
---|
359 | else |
---|
360 | { |
---|
361 | do |
---|
362 | { |
---|
363 | prefix++; |
---|
364 | m_pcTDecBinIf->decodeBinEP( codeWord RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(whichStat) ); |
---|
365 | } while( codeWord); |
---|
366 | } |
---|
367 | |
---|
368 | codeWord = 1 - codeWord; |
---|
369 | prefix -= codeWord; |
---|
370 | codeWord=0; |
---|
371 | |
---|
372 | if (prefix < COEF_REMAIN_BIN_REDUCTION ) |
---|
373 | { |
---|
374 | m_pcTDecBinIf->decodeBinsEP(codeWord,rParam RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(whichStat)); |
---|
375 | rSymbol = (prefix<<rParam) + codeWord; |
---|
376 | } |
---|
377 | else if (useLimitedPrefixLength) |
---|
378 | { |
---|
379 | const UInt maximumPrefixLength = (32 - (COEF_REMAIN_BIN_REDUCTION + maxLog2TrDynamicRange)); |
---|
380 | |
---|
381 | const UInt prefixLength = prefix - COEF_REMAIN_BIN_REDUCTION; |
---|
382 | const UInt suffixLength = (prefixLength == maximumPrefixLength) ? (maxLog2TrDynamicRange - rParam) : prefixLength; |
---|
383 | |
---|
384 | m_pcTDecBinIf->decodeBinsEP(codeWord, (suffixLength + rParam) RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(whichStat)); |
---|
385 | |
---|
386 | rSymbol = codeWord + ((((1 << prefixLength) - 1) + COEF_REMAIN_BIN_REDUCTION) << rParam); |
---|
387 | } |
---|
388 | else |
---|
389 | { |
---|
390 | m_pcTDecBinIf->decodeBinsEP(codeWord,prefix-COEF_REMAIN_BIN_REDUCTION+rParam RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(whichStat)); |
---|
391 | rSymbol = (((1<<(prefix-COEF_REMAIN_BIN_REDUCTION))+COEF_REMAIN_BIN_REDUCTION-1)<<rParam)+codeWord; |
---|
392 | } |
---|
393 | } |
---|
394 | |
---|
395 | /** Parse I_PCM information. |
---|
396 | * \param pcCU |
---|
397 | * \param uiAbsPartIdx |
---|
398 | * \param uiDepth |
---|
399 | * \returns Void |
---|
400 | * |
---|
401 | * If I_PCM flag indicates that the CU is I_PCM, parse its PCM alignment bits and codes. |
---|
402 | */ |
---|
403 | Void TDecSbac::parseIPCMInfo ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth ) |
---|
404 | { |
---|
405 | UInt uiSymbol; |
---|
406 | |
---|
407 | m_pcTDecBinIf->decodeBinTrm(uiSymbol); |
---|
408 | |
---|
409 | #if NH_MV_ENC_DEC_TRAC |
---|
410 | DTRACE_CU("pcm_flag", uiSymbol) |
---|
411 | #endif |
---|
412 | |
---|
413 | |
---|
414 | if (uiSymbol == 1) |
---|
415 | { |
---|
416 | Bool bIpcmFlag = true; |
---|
417 | const TComSPS &sps=*(pcCU->getSlice()->getSPS()); |
---|
418 | |
---|
419 | pcCU->setPartSizeSubParts ( SIZE_2Nx2N, uiAbsPartIdx, uiDepth ); |
---|
420 | pcCU->setSizeSubParts ( sps.getMaxCUWidth()>>uiDepth, sps.getMaxCUHeight()>>uiDepth, uiAbsPartIdx, uiDepth ); |
---|
421 | pcCU->setTrIdxSubParts ( 0, uiAbsPartIdx, uiDepth ); |
---|
422 | pcCU->setIPCMFlagSubParts ( bIpcmFlag, uiAbsPartIdx, uiDepth ); |
---|
423 | |
---|
424 | const UInt minCoeffSizeY = pcCU->getPic()->getMinCUWidth() * pcCU->getPic()->getMinCUHeight(); |
---|
425 | const UInt offsetY = minCoeffSizeY * uiAbsPartIdx; |
---|
426 | for (UInt ch=0; ch < pcCU->getPic()->getNumberValidComponents(); ch++) |
---|
427 | { |
---|
428 | const ComponentID compID = ComponentID(ch); |
---|
429 | const UInt offset = offsetY >> (pcCU->getPic()->getComponentScaleX(compID) + pcCU->getPic()->getComponentScaleY(compID)); |
---|
430 | Pel * pPCMSample = pcCU->getPCMSample(compID) + offset; |
---|
431 | const UInt width = pcCU->getWidth (uiAbsPartIdx) >> pcCU->getPic()->getComponentScaleX(compID); |
---|
432 | const UInt height = pcCU->getHeight(uiAbsPartIdx) >> pcCU->getPic()->getComponentScaleY(compID); |
---|
433 | const UInt sampleBits = pcCU->getSlice()->getSPS()->getPCMBitDepth(toChannelType(compID)); |
---|
434 | for (UInt y=0; y<height; y++) |
---|
435 | { |
---|
436 | for (UInt x=0; x<width; x++) |
---|
437 | { |
---|
438 | UInt sample; |
---|
439 | m_pcTDecBinIf->xReadPCMCode(sampleBits, sample); |
---|
440 | pPCMSample[x] = sample; |
---|
441 | } |
---|
442 | pPCMSample += width; |
---|
443 | } |
---|
444 | } |
---|
445 | m_pcTDecBinIf->start(); |
---|
446 | } |
---|
447 | } |
---|
448 | |
---|
449 | Void TDecSbac::parseCUTransquantBypassFlag( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth ) |
---|
450 | { |
---|
451 | UInt uiSymbol; |
---|
452 | m_pcTDecBinIf->decodeBin( uiSymbol, m_CUTransquantBypassFlagSCModel.get( 0, 0, 0 ) RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(STATS__CABAC_BITS__TQ_BYPASS_FLAG) ); |
---|
453 | #if NH_MV_ENC_DEC_TRAC |
---|
454 | DTRACE_CU("cu_transquant_bypass_flag", uiSymbol); |
---|
455 | #endif |
---|
456 | |
---|
457 | pcCU->setCUTransquantBypassSubParts(uiSymbol ? true : false, uiAbsPartIdx, uiDepth); |
---|
458 | } |
---|
459 | |
---|
460 | /** parse skip flag |
---|
461 | * \param pcCU |
---|
462 | * \param uiAbsPartIdx |
---|
463 | * \param uiDepth |
---|
464 | * \returns Void |
---|
465 | */ |
---|
466 | Void TDecSbac::parseSkipFlag( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth ) |
---|
467 | { |
---|
468 | if( pcCU->getSlice()->isIntra() ) |
---|
469 | { |
---|
470 | return; |
---|
471 | } |
---|
472 | |
---|
473 | UInt uiSymbol = 0; |
---|
474 | UInt uiCtxSkip = pcCU->getCtxSkipFlag( uiAbsPartIdx ); |
---|
475 | m_pcTDecBinIf->decodeBin( uiSymbol, m_cCUSkipFlagSCModel.get( 0, 0, uiCtxSkip ) RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(STATS__CABAC_BITS__SKIP_FLAG) ); |
---|
476 | #if !NH_MV_ENC_DEC_TRAC |
---|
477 | DTRACE_CABAC_VL( g_nSymbolCounter++ ); |
---|
478 | DTRACE_CABAC_T( "\tSkipFlag" ); |
---|
479 | DTRACE_CABAC_T( "\tuiCtxSkip: "); |
---|
480 | DTRACE_CABAC_V( uiCtxSkip ); |
---|
481 | DTRACE_CABAC_T( "\tuiSymbol: "); |
---|
482 | DTRACE_CABAC_V( uiSymbol ); |
---|
483 | DTRACE_CABAC_T( "\n"); |
---|
484 | #endif |
---|
485 | if( uiSymbol ) |
---|
486 | { |
---|
487 | pcCU->setSkipFlagSubParts( true, uiAbsPartIdx, uiDepth ); |
---|
488 | pcCU->setPredModeSubParts( MODE_INTER, uiAbsPartIdx, uiDepth ); |
---|
489 | pcCU->setPartSizeSubParts( SIZE_2Nx2N, uiAbsPartIdx, uiDepth ); |
---|
490 | pcCU->setSizeSubParts( pcCU->getSlice()->getSPS()->getMaxCUWidth()>>uiDepth, pcCU->getSlice()->getSPS()->getMaxCUHeight()>>uiDepth, uiAbsPartIdx, uiDepth ); |
---|
491 | pcCU->setMergeFlagSubParts( true , uiAbsPartIdx, 0, uiDepth ); |
---|
492 | } |
---|
493 | #if NH_MV_ENC_DEC_TRAC |
---|
494 | DTRACE_CU("cu_skip_flag", uiSymbol); |
---|
495 | #endif |
---|
496 | |
---|
497 | } |
---|
498 | #if NH_3D |
---|
499 | Void TDecSbac::parseDIS( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth ) |
---|
500 | { |
---|
501 | pcCU->setDISFlagSubParts( false, uiAbsPartIdx, uiDepth ); |
---|
502 | UInt uiSymbol = 0; |
---|
503 | m_pcTDecBinIf->decodeBin( uiSymbol, m_cCUDISFlagSCModel.get( 0, 0, 0 ) RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(STATS__CABAC_BITS__SKIP_FLAG) ); |
---|
504 | if( uiSymbol ) |
---|
505 | { |
---|
506 | pcCU->setDISFlagSubParts( true, uiAbsPartIdx, uiDepth ); |
---|
507 | pcCU->setSkipFlagSubParts( false, uiAbsPartIdx, uiDepth ); |
---|
508 | pcCU->setSDCFlagSubParts( false, uiAbsPartIdx, uiDepth ); |
---|
509 | pcCU->setPredModeSubParts( MODE_INTRA, uiAbsPartIdx, uiDepth ); |
---|
510 | pcCU->setPartSizeSubParts( SIZE_2Nx2N, uiAbsPartIdx, uiDepth ); |
---|
511 | pcCU->setIntraDirSubParts(CHANNEL_TYPE_LUMA, DC_IDX, uiAbsPartIdx, uiDepth ); |
---|
512 | pcCU->setSizeSubParts( pcCU->getSlice()->getSPS()->getMaxCUWidth()>>uiDepth, pcCU->getSlice()->getSPS()->getMaxCUHeight()>>uiDepth, uiAbsPartIdx, uiDepth ); |
---|
513 | pcCU->setMergeFlagSubParts( false , uiAbsPartIdx, 0, uiDepth ); |
---|
514 | pcCU->setTrIdxSubParts(0, uiAbsPartIdx, uiDepth); |
---|
515 | pcCU->setCbfSubParts(0, COMPONENT_Y, uiAbsPartIdx, uiDepth); |
---|
516 | |
---|
517 | UInt uiUnaryIdx = 0; |
---|
518 | UInt uiNumCand = 4; |
---|
519 | |
---|
520 | if ( uiNumCand > 1 ) |
---|
521 | { |
---|
522 | for( ; uiUnaryIdx < uiNumCand - 1; ++uiUnaryIdx ) |
---|
523 | { |
---|
524 | UInt uiSymbol2 = 0; |
---|
525 | if ( uiUnaryIdx==0 ) |
---|
526 | { |
---|
527 | m_pcTDecBinIf->decodeBin( uiSymbol2, m_cCUDISTypeSCModel.get( 0, 0, 0 ) RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(STATS__CABAC_BITS__SKIP_FLAG) ); |
---|
528 | } |
---|
529 | else |
---|
530 | { |
---|
531 | m_pcTDecBinIf->decodeBinEP( uiSymbol2 RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(STATS__CABAC_BITS__SKIP_FLAG)); |
---|
532 | } |
---|
533 | if( uiSymbol2 == 0 ) |
---|
534 | { |
---|
535 | break; |
---|
536 | } |
---|
537 | } |
---|
538 | } |
---|
539 | pcCU->setDISTypeSubParts((UChar)uiUnaryIdx, uiAbsPartIdx, uiDepth); |
---|
540 | } |
---|
541 | } |
---|
542 | #endif |
---|
543 | |
---|
544 | |
---|
545 | /** parse merge flag |
---|
546 | * \param pcCU |
---|
547 | * \param uiAbsPartIdx |
---|
548 | * \param uiDepth |
---|
549 | * \param uiPUIdx |
---|
550 | * \returns Void |
---|
551 | */ |
---|
552 | Void TDecSbac::parseMergeFlag ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, UInt uiPUIdx ) |
---|
553 | { |
---|
554 | UInt uiSymbol; |
---|
555 | m_pcTDecBinIf->decodeBin( uiSymbol, *m_cCUMergeFlagExtSCModel.get( 0 ) RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(STATS__CABAC_BITS__MERGE_FLAG) ); |
---|
556 | #if NH_MV_ENC_DEC_TRAC |
---|
557 | DTRACE_PU("merge_flag", uiSymbol) |
---|
558 | #endif |
---|
559 | pcCU->setMergeFlagSubParts( uiSymbol ? true : false, uiAbsPartIdx, uiPUIdx, uiDepth ); |
---|
560 | #if !NH_MV_ENC_DEC_TRAC |
---|
561 | DTRACE_CABAC_VL( g_nSymbolCounter++ ); |
---|
562 | DTRACE_CABAC_T( "\tMergeFlag: " ); |
---|
563 | DTRACE_CABAC_V( uiSymbol ); |
---|
564 | DTRACE_CABAC_T( "\tAddress: " ); |
---|
565 | DTRACE_CABAC_V( pcCU->getCtuRsAddr() ); |
---|
566 | DTRACE_CABAC_T( "\tuiAbsPartIdx: " ); |
---|
567 | DTRACE_CABAC_V( uiAbsPartIdx ); |
---|
568 | DTRACE_CABAC_T( "\n" ); |
---|
569 | #endif |
---|
570 | } |
---|
571 | |
---|
572 | Void TDecSbac::parseMergeIndex ( TComDataCU* pcCU, UInt& ruiMergeIndex ) |
---|
573 | { |
---|
574 | UInt uiUnaryIdx = 0; |
---|
575 | UInt uiNumCand = pcCU->getSlice()->getMaxNumMergeCand(); |
---|
576 | if ( uiNumCand > 1 ) |
---|
577 | { |
---|
578 | for( ; uiUnaryIdx < uiNumCand - 1; ++uiUnaryIdx ) |
---|
579 | { |
---|
580 | UInt uiSymbol = 0; |
---|
581 | if ( uiUnaryIdx==0 ) |
---|
582 | { |
---|
583 | m_pcTDecBinIf->decodeBin( uiSymbol, m_cCUMergeIdxExtSCModel.get( 0, 0, 0 ) RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(STATS__CABAC_BITS__MERGE_INDEX) ); |
---|
584 | } |
---|
585 | else |
---|
586 | { |
---|
587 | m_pcTDecBinIf->decodeBinEP( uiSymbol RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(STATS__CABAC_BITS__MERGE_INDEX) ); |
---|
588 | } |
---|
589 | if( uiSymbol == 0 ) |
---|
590 | { |
---|
591 | break; |
---|
592 | } |
---|
593 | } |
---|
594 | #if NH_MV_ENC_DEC_TRAC |
---|
595 | DTRACE_PU("merge_idx", uiUnaryIdx) |
---|
596 | #endif |
---|
597 | } |
---|
598 | ruiMergeIndex = uiUnaryIdx; |
---|
599 | |
---|
600 | #if !NH_MV_ENC_DEC_TRAC |
---|
601 | DTRACE_CABAC_VL( g_nSymbolCounter++ ) |
---|
602 | DTRACE_CABAC_T( "\tparseMergeIndex()" ) |
---|
603 | DTRACE_CABAC_T( "\tuiMRGIdx= " ) |
---|
604 | DTRACE_CABAC_V( ruiMergeIndex ) |
---|
605 | DTRACE_CABAC_T( "\n" ) |
---|
606 | #endif |
---|
607 | } |
---|
608 | |
---|
609 | Void TDecSbac::parseMVPIdx ( Int& riMVPIdx ) |
---|
610 | { |
---|
611 | UInt uiSymbol; |
---|
612 | 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) ); |
---|
613 | riMVPIdx = uiSymbol; |
---|
614 | } |
---|
615 | |
---|
616 | Void TDecSbac::parseSplitFlag ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth ) |
---|
617 | { |
---|
618 | if( uiDepth == pcCU->getSlice()->getSPS()->getLog2DiffMaxMinCodingBlockSize() ) |
---|
619 | { |
---|
620 | pcCU->setDepthSubParts( uiDepth, uiAbsPartIdx ); |
---|
621 | return; |
---|
622 | } |
---|
623 | #if RExt__DECODER_DEBUG_BIT_STATISTICS |
---|
624 | const TComCodingStatisticsClassType ctype(STATS__CABAC_BITS__SPLIT_FLAG, g_aucConvertToBit[pcCU->getSlice()->getSPS()->getMaxCUWidth()>>uiDepth]+2); |
---|
625 | #endif |
---|
626 | |
---|
627 | UInt uiSymbol; |
---|
628 | #if NH_3D |
---|
629 | Bool bParseSplitFlag = true; |
---|
630 | Bool bLimQtPredFlag = pcCU->getPic()->getSlice(0)->getQtPredFlag(); |
---|
631 | TComPic *pcTexture = pcCU->getSlice()->getTexturePic(); |
---|
632 | Bool bDepthMapDetect = (pcTexture != NULL); |
---|
633 | Bool bIntraSliceDetect = (pcCU->getSlice()->getSliceType() == I_SLICE); |
---|
634 | |
---|
635 | Bool rapPic = (pcCU->getSlice()->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_W_RADL || pcCU->getSlice()->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_N_LP || pcCU->getSlice()->getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA); |
---|
636 | |
---|
637 | if(bDepthMapDetect && !bIntraSliceDetect && !rapPic && bLimQtPredFlag) |
---|
638 | { |
---|
639 | TComDataCU *pcTextureCU = pcTexture->getCtu(pcCU->getCtuRsAddr()); |
---|
640 | assert(pcTextureCU->getDepth(uiAbsPartIdx) >= uiDepth); |
---|
641 | bParseSplitFlag = (pcTextureCU->getDepth(uiAbsPartIdx) > uiDepth); |
---|
642 | } |
---|
643 | |
---|
644 | if(bParseSplitFlag) |
---|
645 | { |
---|
646 | #endif |
---|
647 | m_pcTDecBinIf->decodeBin( uiSymbol, m_cCUSplitFlagSCModel.get( 0, 0, pcCU->getCtxSplitFlag( uiAbsPartIdx, uiDepth ) ) RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(ctype) ); |
---|
648 | #if NH_MV_ENC_DEC_TRAC |
---|
649 | DTRACE_CU("split_cu_flag", uiSymbol); |
---|
650 | #else |
---|
651 | DTRACE_CABAC_VL( g_nSymbolCounter++ ) |
---|
652 | DTRACE_CABAC_T( "\tSplitFlag\n" ) |
---|
653 | #endif |
---|
654 | #if NH_3D |
---|
655 | } |
---|
656 | else |
---|
657 | { |
---|
658 | uiSymbol = 0; |
---|
659 | } |
---|
660 | #endif |
---|
661 | pcCU->setDepthSubParts( uiDepth + uiSymbol, uiAbsPartIdx ); |
---|
662 | |
---|
663 | return; |
---|
664 | } |
---|
665 | |
---|
666 | /** parse partition size |
---|
667 | * \param pcCU |
---|
668 | * \param uiAbsPartIdx |
---|
669 | * \param uiDepth |
---|
670 | * \returns Void |
---|
671 | */ |
---|
672 | Void TDecSbac::parsePartSize( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth ) |
---|
673 | { |
---|
674 | UInt uiSymbol, uiMode = 0; |
---|
675 | PartSize eMode; |
---|
676 | const UChar cuWidth =UChar(pcCU->getSlice()->getSPS()->getMaxCUWidth()>>uiDepth); |
---|
677 | const UChar cuHeight=UChar(pcCU->getSlice()->getSPS()->getMaxCUHeight()>>uiDepth); |
---|
678 | const Int log2DiffMaxMinCodingBlockSize = pcCU->getSlice()->getSPS()->getLog2DiffMaxMinCodingBlockSize(); |
---|
679 | |
---|
680 | #if RExt__DECODER_DEBUG_BIT_STATISTICS |
---|
681 | const TComCodingStatisticsClassType ctype(STATS__CABAC_BITS__PART_SIZE, g_aucConvertToBit[cuWidth]+2); |
---|
682 | #endif |
---|
683 | |
---|
684 | assert ( pcCU->getSlice()->getSPS()->getLog2DiffMaxMinCodingBlockSize() == log2DiffMaxMinCodingBlockSize); |
---|
685 | |
---|
686 | #if NH_3D |
---|
687 | Bool bParsePartSize = true; |
---|
688 | |
---|
689 | Bool bLimQtPredFlag = pcCU->getPic()->getSlice(0)->getQtPredFlag(); |
---|
690 | TComPic *pcTexture = pcCU->getSlice()->getTexturePic(); |
---|
691 | Bool bDepthMapDetect = (pcTexture != NULL); |
---|
692 | Bool bIntraSliceDetect = (pcCU->getSlice()->getSliceType() == I_SLICE); |
---|
693 | |
---|
694 | Bool rapPic = (pcCU->getSlice()->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_W_RADL || pcCU->getSlice()->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_N_LP || pcCU->getSlice()->getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA); |
---|
695 | |
---|
696 | Bool depthDependent = false; |
---|
697 | UInt uiTexturePart = uiMode; |
---|
698 | |
---|
699 | if(bDepthMapDetect && !bIntraSliceDetect && !rapPic && bLimQtPredFlag ) |
---|
700 | { |
---|
701 | TComDataCU *pcTextureCU = pcTexture->getCtu(pcCU->getCtuRsAddr()); |
---|
702 | assert(pcTextureCU->getDepth(uiAbsPartIdx) >= uiDepth); |
---|
703 | if(pcTextureCU->getDepth(uiAbsPartIdx) == uiDepth ) |
---|
704 | { |
---|
705 | depthDependent = true; |
---|
706 | uiTexturePart = pcTextureCU->getPartitionSize( uiAbsPartIdx ); |
---|
707 | } |
---|
708 | if (pcTextureCU->getDepth(uiAbsPartIdx) == uiDepth && pcTextureCU->getPartitionSize( uiAbsPartIdx ) == SIZE_2Nx2N) |
---|
709 | { |
---|
710 | bParsePartSize = false; |
---|
711 | eMode = SIZE_2Nx2N; |
---|
712 | } |
---|
713 | } |
---|
714 | #endif |
---|
715 | |
---|
716 | if ( pcCU->isIntra( uiAbsPartIdx ) ) |
---|
717 | { |
---|
718 | #if NH_3D |
---|
719 | if(bParsePartSize) |
---|
720 | { |
---|
721 | #endif |
---|
722 | uiSymbol = 1; |
---|
723 | if( uiDepth == log2DiffMaxMinCodingBlockSize ) |
---|
724 | { |
---|
725 | m_pcTDecBinIf->decodeBin( uiSymbol, m_cCUPartSizeSCModel.get( 0, 0, 0) RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(ctype) ); |
---|
726 | #if NH_MV_ENC_DEC_TRAC |
---|
727 | DTRACE_CU("part_mode", uiSymbol) |
---|
728 | #endif |
---|
729 | } |
---|
730 | eMode = uiSymbol ? SIZE_2Nx2N : SIZE_NxN; |
---|
731 | #if NH_3D |
---|
732 | } |
---|
733 | #endif |
---|
734 | UInt uiTrLevel = 0; |
---|
735 | UInt uiWidthInBit = g_aucConvertToBit[pcCU->getWidth(uiAbsPartIdx)]+2; |
---|
736 | UInt uiTrSizeInBit = g_aucConvertToBit[pcCU->getSlice()->getSPS()->getMaxTrSize()]+2; |
---|
737 | uiTrLevel = uiWidthInBit >= uiTrSizeInBit ? uiWidthInBit - uiTrSizeInBit : 0; |
---|
738 | if( eMode == SIZE_NxN ) |
---|
739 | { |
---|
740 | pcCU->setTrIdxSubParts( 1+uiTrLevel, uiAbsPartIdx, uiDepth ); |
---|
741 | } |
---|
742 | else |
---|
743 | { |
---|
744 | pcCU->setTrIdxSubParts( uiTrLevel, uiAbsPartIdx, uiDepth ); |
---|
745 | } |
---|
746 | } |
---|
747 | else |
---|
748 | { |
---|
749 | #if NH_3D |
---|
750 | if(bParsePartSize) |
---|
751 | { |
---|
752 | if (depthDependent==false || uiTexturePart == SIZE_NxN|| uiTexturePart == SIZE_2Nx2N) |
---|
753 | { |
---|
754 | #endif |
---|
755 | UInt uiMaxNumBits = 2; |
---|
756 | |
---|
757 | if( uiDepth == log2DiffMaxMinCodingBlockSize && !( cuWidth == 8 && cuHeight == 8 ) ) |
---|
758 | { |
---|
759 | uiMaxNumBits ++; |
---|
760 | } |
---|
761 | |
---|
762 | for ( UInt ui = 0; ui < uiMaxNumBits; ui++ ) |
---|
763 | { |
---|
764 | m_pcTDecBinIf->decodeBin( uiSymbol, m_cCUPartSizeSCModel.get( 0, 0, ui) RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(ctype) ); |
---|
765 | if ( uiSymbol ) |
---|
766 | { |
---|
767 | break; |
---|
768 | } |
---|
769 | uiMode++; |
---|
770 | } |
---|
771 | eMode = (PartSize) uiMode; |
---|
772 | if ( pcCU->getSlice()->getSPS()->getUseAMP() && uiDepth < log2DiffMaxMinCodingBlockSize ) |
---|
773 | { |
---|
774 | if (eMode == SIZE_2NxN) |
---|
775 | { |
---|
776 | m_pcTDecBinIf->decodeBin(uiSymbol, m_cCUPartSizeSCModel.get( 0, 0, 3 ) RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(ctype)); |
---|
777 | if (uiSymbol == 0) |
---|
778 | { |
---|
779 | m_pcTDecBinIf->decodeBinEP(uiSymbol RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(ctype) ); |
---|
780 | eMode = (uiSymbol == 0? SIZE_2NxnU : SIZE_2NxnD); |
---|
781 | } |
---|
782 | } |
---|
783 | else if (eMode == SIZE_Nx2N) |
---|
784 | { |
---|
785 | m_pcTDecBinIf->decodeBin(uiSymbol, m_cCUPartSizeSCModel.get( 0, 0, 3 ) RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(ctype) ); |
---|
786 | if (uiSymbol == 0) |
---|
787 | { |
---|
788 | m_pcTDecBinIf->decodeBinEP(uiSymbol RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(ctype) ); |
---|
789 | eMode = (uiSymbol == 0? SIZE_nLx2N : SIZE_nRx2N); |
---|
790 | } |
---|
791 | } |
---|
792 | } |
---|
793 | #if NH_3D |
---|
794 | } |
---|
795 | else if(uiTexturePart == SIZE_2NxN || uiTexturePart == SIZE_2NxnU || uiTexturePart == SIZE_2NxnD) |
---|
796 | { |
---|
797 | UInt uiMaxNumBits = 1; |
---|
798 | if ( ( pcCU->getSlice()->getSPS()->getUseAMP() && uiDepth < log2DiffMaxMinCodingBlockSize ) && uiDepth < log2DiffMaxMinCodingBlockSize ) |
---|
799 | { |
---|
800 | uiMaxNumBits ++; |
---|
801 | } |
---|
802 | for ( UInt ui = 0; ui < uiMaxNumBits; ui++ ) |
---|
803 | { |
---|
804 | m_pcTDecBinIf->decodeBin( uiSymbol, m_cCUPartSizeSCModel.get( 0, 0, ui) RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(ctype) ); |
---|
805 | if ( uiSymbol ) |
---|
806 | { |
---|
807 | break; |
---|
808 | } |
---|
809 | uiMode++; |
---|
810 | } |
---|
811 | eMode = (PartSize) uiMode; |
---|
812 | if(uiMode && ( ( pcCU->getSlice()->getSPS()->getUseAMP() && uiDepth < log2DiffMaxMinCodingBlockSize ) && uiDepth < log2DiffMaxMinCodingBlockSize ) && uiSymbol==1 ) |
---|
813 | { |
---|
814 | eMode = SIZE_2NxN; |
---|
815 | } |
---|
816 | else if (uiMode && (( ( pcCU->getSlice()->getSPS()->getUseAMP() && uiDepth < log2DiffMaxMinCodingBlockSize ) && uiDepth < log2DiffMaxMinCodingBlockSize )==0) && uiSymbol==0) |
---|
817 | { |
---|
818 | eMode = SIZE_2NxN; |
---|
819 | } |
---|
820 | else if (uiMode && ( ( pcCU->getSlice()->getSPS()->getUseAMP() && uiDepth < log2DiffMaxMinCodingBlockSize ) && uiDepth < log2DiffMaxMinCodingBlockSize ) && uiSymbol==0) |
---|
821 | { |
---|
822 | m_pcTDecBinIf->decodeBinEP(uiSymbol RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(ctype)); |
---|
823 | eMode = (uiSymbol == 0? SIZE_2NxnU : SIZE_2NxnD); |
---|
824 | } |
---|
825 | } |
---|
826 | else if(uiTexturePart == SIZE_Nx2N|| uiTexturePart==SIZE_nLx2N || uiTexturePart==SIZE_nRx2N) |
---|
827 | { |
---|
828 | UInt uiMaxNumBits = 1; |
---|
829 | if ( ( pcCU->getSlice()->getSPS()->getUseAMP() && uiDepth < log2DiffMaxMinCodingBlockSize ) && uiDepth < log2DiffMaxMinCodingBlockSize ) |
---|
830 | { |
---|
831 | uiMaxNumBits ++; |
---|
832 | } |
---|
833 | for ( UInt ui = 0; ui < uiMaxNumBits; ui++ ) |
---|
834 | { |
---|
835 | m_pcTDecBinIf->decodeBin( uiSymbol, m_cCUPartSizeSCModel.get( 0, 0, ui) RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(ctype)); |
---|
836 | if ( uiSymbol ) |
---|
837 | { |
---|
838 | break; |
---|
839 | } |
---|
840 | uiMode++; |
---|
841 | } |
---|
842 | eMode = (PartSize) uiMode; |
---|
843 | if(uiMode && ( ( pcCU->getSlice()->getSPS()->getUseAMP() && uiDepth < log2DiffMaxMinCodingBlockSize ) && uiDepth < log2DiffMaxMinCodingBlockSize ) && uiSymbol==1 ) |
---|
844 | { |
---|
845 | eMode = SIZE_Nx2N; |
---|
846 | } |
---|
847 | else if (uiMode && (( ( pcCU->getSlice()->getSPS()->getUseAMP() && uiDepth < log2DiffMaxMinCodingBlockSize ) && uiDepth < log2DiffMaxMinCodingBlockSize )==0) && uiSymbol==0) |
---|
848 | { |
---|
849 | eMode = SIZE_Nx2N; |
---|
850 | } |
---|
851 | else if (uiMode && ( ( pcCU->getSlice()->getSPS()->getUseAMP() && uiDepth < log2DiffMaxMinCodingBlockSize ) && uiDepth < log2DiffMaxMinCodingBlockSize ) && uiSymbol==0) |
---|
852 | { |
---|
853 | m_pcTDecBinIf->decodeBinEP(uiSymbol RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(ctype)); |
---|
854 | eMode = (uiSymbol == 0? SIZE_nLx2N : SIZE_nRx2N); |
---|
855 | } |
---|
856 | } |
---|
857 | else |
---|
858 | { |
---|
859 | assert(0); |
---|
860 | } |
---|
861 | #endif |
---|
862 | #if NH_MV_ENC_DEC_TRAC |
---|
863 | DTRACE_CU("part_mode", eMode ) |
---|
864 | #endif |
---|
865 | #if NH_3D |
---|
866 | } |
---|
867 | #endif |
---|
868 | } |
---|
869 | pcCU->setPartSizeSubParts( eMode, uiAbsPartIdx, uiDepth ); |
---|
870 | pcCU->setSizeSubParts( cuWidth, cuHeight, uiAbsPartIdx, uiDepth ); |
---|
871 | } |
---|
872 | |
---|
873 | |
---|
874 | /** parse prediction mode |
---|
875 | * \param pcCU |
---|
876 | * \param uiAbsPartIdx |
---|
877 | * \param uiDepth |
---|
878 | * \returns Void |
---|
879 | */ |
---|
880 | Void TDecSbac::parsePredMode( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth ) |
---|
881 | { |
---|
882 | if( pcCU->getSlice()->isIntra() ) |
---|
883 | { |
---|
884 | pcCU->setPredModeSubParts( MODE_INTRA, uiAbsPartIdx, uiDepth ); |
---|
885 | return; |
---|
886 | } |
---|
887 | |
---|
888 | UInt uiSymbol; |
---|
889 | Int iPredMode = MODE_INTER; |
---|
890 | m_pcTDecBinIf->decodeBin( uiSymbol, m_cCUPredModeSCModel.get( 0, 0, 0 ) RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(STATS__CABAC_BITS__PRED_MODE) ); |
---|
891 | iPredMode += uiSymbol; |
---|
892 | #if NH_MV_ENC_DEC_TRAC |
---|
893 | DTRACE_CU("pred_mode_flag", uiSymbol) |
---|
894 | #endif |
---|
895 | pcCU->setPredModeSubParts( (PredMode)iPredMode, uiAbsPartIdx, uiDepth ); |
---|
896 | } |
---|
897 | |
---|
898 | |
---|
899 | Void TDecSbac::parseIntraDirLumaAng ( TComDataCU* pcCU, UInt absPartIdx, UInt depth ) |
---|
900 | { |
---|
901 | PartSize mode = pcCU->getPartitionSize( absPartIdx ); |
---|
902 | UInt partNum = mode==SIZE_NxN?4:1; |
---|
903 | UInt partOffset = ( pcCU->getPic()->getNumPartitionsInCtu() >> ( pcCU->getDepth(absPartIdx) << 1 ) ) >> 2; |
---|
904 | UInt mpmPred[4],symbol; |
---|
905 | Int j,intraPredMode; |
---|
906 | if (mode==SIZE_NxN) |
---|
907 | { |
---|
908 | depth++; |
---|
909 | } |
---|
910 | #if RExt__DECODER_DEBUG_BIT_STATISTICS |
---|
911 | const TComCodingStatisticsClassType ctype(STATS__CABAC_BITS__INTRA_DIR_ANG, g_aucConvertToBit[pcCU->getSlice()->getSPS()->getMaxCUWidth()>>depth]+2, CHANNEL_TYPE_LUMA); |
---|
912 | #endif |
---|
913 | for (j=0;j<partNum;j++) |
---|
914 | { |
---|
915 | #if NH_3D |
---|
916 | if( pcCU->getSlice()->getIntraSdcWedgeFlag() || pcCU->getSlice()->getIntraContourFlag() ) |
---|
917 | { |
---|
918 | xParseIntraDepthMode( pcCU, absPartIdx+partOffset*j, depth ); |
---|
919 | xParseDmmData ( pcCU, absPartIdx+partOffset*j, depth ); |
---|
920 | } |
---|
921 | if( pcCU->getIntraDir( CHANNEL_TYPE_LUMA, absPartIdx+partOffset*j ) < NUM_INTRA_MODE ) |
---|
922 | { |
---|
923 | #endif |
---|
924 | m_pcTDecBinIf->decodeBin( symbol, m_cCUIntraPredSCModel.get( 0, 0, 0) RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(ctype) ); |
---|
925 | mpmPred[j] = symbol; |
---|
926 | #if NH_MV_ENC_DEC_TRAC |
---|
927 | DTRACE_CU("prev_intra_luma_pred_flag", symbol) |
---|
928 | #endif |
---|
929 | #if NH_3D |
---|
930 | } |
---|
931 | #endif |
---|
932 | } |
---|
933 | for (j=0;j<partNum;j++) |
---|
934 | { |
---|
935 | #if NH_3D |
---|
936 | if( pcCU->getIntraDir( CHANNEL_TYPE_LUMA, absPartIdx+partOffset*j ) < NUM_INTRA_MODE ) |
---|
937 | { |
---|
938 | #endif |
---|
939 | Int preds[NUM_MOST_PROBABLE_MODES] = {-1, -1, -1}; |
---|
940 | pcCU->getIntraDirPredictor(absPartIdx+partOffset*j, preds, COMPONENT_Y); |
---|
941 | if (mpmPred[j]) |
---|
942 | { |
---|
943 | m_pcTDecBinIf->decodeBinEP( symbol RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(ctype) ); |
---|
944 | if (symbol) |
---|
945 | { |
---|
946 | m_pcTDecBinIf->decodeBinEP( symbol RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(ctype) ); |
---|
947 | symbol++; |
---|
948 | } |
---|
949 | #if NH_MV_ENC_DEC_TRAC |
---|
950 | DTRACE_CU("mpm_idx", symbol) |
---|
951 | #endif |
---|
952 | intraPredMode = preds[symbol]; |
---|
953 | } |
---|
954 | else |
---|
955 | { |
---|
956 | m_pcTDecBinIf->decodeBinsEP( symbol, 5 RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(ctype) ); |
---|
957 | intraPredMode = symbol; |
---|
958 | #if NH_MV_ENC_DEC_TRAC |
---|
959 | DTRACE_CU("rem_intra_luma_pred_mode", symbol) |
---|
960 | #endif |
---|
961 | |
---|
962 | //postponed sorting of MPMs (only in remaining branch) |
---|
963 | if (preds[0] > preds[1]) |
---|
964 | { |
---|
965 | std::swap(preds[0], preds[1]); |
---|
966 | } |
---|
967 | if (preds[0] > preds[2]) |
---|
968 | { |
---|
969 | std::swap(preds[0], preds[2]); |
---|
970 | } |
---|
971 | if (preds[1] > preds[2]) |
---|
972 | { |
---|
973 | std::swap(preds[1], preds[2]); |
---|
974 | } |
---|
975 | for ( UInt i = 0; i < NUM_MOST_PROBABLE_MODES; i++ ) |
---|
976 | { |
---|
977 | intraPredMode += ( intraPredMode >= preds[i] ); |
---|
978 | } |
---|
979 | } |
---|
980 | pcCU->setIntraDirSubParts(CHANNEL_TYPE_LUMA, (UChar)intraPredMode, absPartIdx+partOffset*j, depth ); |
---|
981 | #if NH_3D |
---|
982 | } |
---|
983 | #endif |
---|
984 | } |
---|
985 | } |
---|
986 | |
---|
987 | |
---|
988 | Void TDecSbac::parseIntraDirChroma( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth ) |
---|
989 | { |
---|
990 | UInt uiSymbol; |
---|
991 | #if RExt__DECODER_DEBUG_BIT_STATISTICS |
---|
992 | const TComCodingStatisticsClassType ctype(STATS__CABAC_BITS__INTRA_DIR_ANG, g_aucConvertToBit[pcCU->getSlice()->getSPS()->getMaxCUWidth()>>uiDepth]+2, CHANNEL_TYPE_CHROMA); |
---|
993 | #endif |
---|
994 | |
---|
995 | m_pcTDecBinIf->decodeBin( uiSymbol, m_cCUChromaPredSCModel.get( 0, 0, 0 ) RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(ctype) ); |
---|
996 | if( uiSymbol == 0 ) |
---|
997 | { |
---|
998 | #if NH_MV_ENC_DEC_TRAC |
---|
999 | DTRACE_CU("intra_chroma_pred_mode", uiSymbol ) |
---|
1000 | #endif |
---|
1001 | uiSymbol = DM_CHROMA_IDX; |
---|
1002 | } |
---|
1003 | else |
---|
1004 | { |
---|
1005 | UInt uiIPredMode; |
---|
1006 | m_pcTDecBinIf->decodeBinsEP( uiIPredMode, 2 RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(ctype) ); |
---|
1007 | #if NH_MV_ENC_DEC_TRAC |
---|
1008 | DTRACE_CU("intra_chroma_pred_mode", uiIPredMode ) |
---|
1009 | #endif |
---|
1010 | UInt uiAllowedChromaDir[ NUM_CHROMA_MODE ]; |
---|
1011 | pcCU->getAllowedChromaDir( uiAbsPartIdx, uiAllowedChromaDir ); |
---|
1012 | uiSymbol = uiAllowedChromaDir[ uiIPredMode ]; |
---|
1013 | } |
---|
1014 | |
---|
1015 | pcCU->setIntraDirSubParts( CHANNEL_TYPE_CHROMA, uiSymbol, uiAbsPartIdx, uiDepth ); |
---|
1016 | } |
---|
1017 | |
---|
1018 | Void TDecSbac::parseInterDir( TComDataCU* pcCU, UInt& ruiInterDir, UInt uiAbsPartIdx ) |
---|
1019 | { |
---|
1020 | UInt uiSymbol; |
---|
1021 | const UInt uiCtx = pcCU->getCtxInterDir( uiAbsPartIdx ); |
---|
1022 | ContextModel *pCtx = m_cCUInterDirSCModel.get( 0 ); |
---|
1023 | |
---|
1024 | uiSymbol = 0; |
---|
1025 | if (pcCU->getPartitionSize(uiAbsPartIdx) == SIZE_2Nx2N || pcCU->getHeight(uiAbsPartIdx) != 8 ) |
---|
1026 | { |
---|
1027 | m_pcTDecBinIf->decodeBin( uiSymbol, *( pCtx + uiCtx ) RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(STATS__CABAC_BITS__INTER_DIR) ); |
---|
1028 | } |
---|
1029 | |
---|
1030 | if( uiSymbol ) |
---|
1031 | { |
---|
1032 | uiSymbol = 2; |
---|
1033 | } |
---|
1034 | else |
---|
1035 | { |
---|
1036 | m_pcTDecBinIf->decodeBin( uiSymbol, *( pCtx + 4 ) RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(STATS__CABAC_BITS__INTER_DIR) ); |
---|
1037 | assert(uiSymbol == 0 || uiSymbol == 1); |
---|
1038 | } |
---|
1039 | |
---|
1040 | uiSymbol++; |
---|
1041 | ruiInterDir = uiSymbol; |
---|
1042 | #if NH_MV_ENC_DEC_TRAC |
---|
1043 | DTRACE_PU("inter_pred_idc", ruiInterDir - 1 ) |
---|
1044 | #endif |
---|
1045 | |
---|
1046 | return; |
---|
1047 | } |
---|
1048 | |
---|
1049 | Void TDecSbac::parseRefFrmIdx( TComDataCU* pcCU, Int& riRefFrmIdx, RefPicList eRefList ) |
---|
1050 | { |
---|
1051 | UInt uiSymbol; |
---|
1052 | |
---|
1053 | ContextModel *pCtx = m_cCURefPicSCModel.get( 0 ); |
---|
1054 | m_pcTDecBinIf->decodeBin( uiSymbol, *pCtx RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(STATS__CABAC_BITS__REF_FRM_IDX) ); |
---|
1055 | |
---|
1056 | if( uiSymbol ) |
---|
1057 | { |
---|
1058 | UInt uiRefNum = pcCU->getSlice()->getNumRefIdx( eRefList ) - 2; |
---|
1059 | pCtx++; |
---|
1060 | UInt ui; |
---|
1061 | for( ui = 0; ui < uiRefNum; ++ui ) |
---|
1062 | { |
---|
1063 | if( ui == 0 ) |
---|
1064 | { |
---|
1065 | m_pcTDecBinIf->decodeBin( uiSymbol, *pCtx RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(STATS__CABAC_BITS__REF_FRM_IDX) ); |
---|
1066 | } |
---|
1067 | else |
---|
1068 | { |
---|
1069 | m_pcTDecBinIf->decodeBinEP( uiSymbol RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(STATS__CABAC_BITS__REF_FRM_IDX) ); |
---|
1070 | } |
---|
1071 | if( uiSymbol == 0 ) |
---|
1072 | { |
---|
1073 | break; |
---|
1074 | } |
---|
1075 | } |
---|
1076 | uiSymbol = ui + 1; |
---|
1077 | } |
---|
1078 | riRefFrmIdx = uiSymbol; |
---|
1079 | #if NH_MV_ENC_DEC_TRAC |
---|
1080 | #if ENC_DEC_TRACE |
---|
1081 | if ( eRefList == REF_PIC_LIST_0 ) |
---|
1082 | { |
---|
1083 | DTRACE_PU("ref_idx_l0", uiSymbol) |
---|
1084 | } |
---|
1085 | else |
---|
1086 | { |
---|
1087 | DTRACE_PU("ref_idx_l1", uiSymbol) |
---|
1088 | } |
---|
1089 | #endif |
---|
1090 | #endif |
---|
1091 | |
---|
1092 | return; |
---|
1093 | } |
---|
1094 | |
---|
1095 | Void TDecSbac::parseMvd( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiPartIdx, UInt uiDepth, RefPicList eRefList ) |
---|
1096 | { |
---|
1097 | UInt uiSymbol; |
---|
1098 | UInt uiHorAbs; |
---|
1099 | UInt uiVerAbs; |
---|
1100 | UInt uiHorSign = 0; |
---|
1101 | UInt uiVerSign = 0; |
---|
1102 | ContextModel *pCtx = m_cCUMvdSCModel.get( 0 ); |
---|
1103 | |
---|
1104 | if(pcCU->getSlice()->getMvdL1ZeroFlag() && eRefList == REF_PIC_LIST_1 && pcCU->getInterDir(uiAbsPartIdx)==3) |
---|
1105 | { |
---|
1106 | uiHorAbs=0; |
---|
1107 | uiVerAbs=0; |
---|
1108 | } |
---|
1109 | else |
---|
1110 | { |
---|
1111 | m_pcTDecBinIf->decodeBin( uiHorAbs, *pCtx RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(STATS__CABAC_BITS__MVD) ); |
---|
1112 | m_pcTDecBinIf->decodeBin( uiVerAbs, *pCtx RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(STATS__CABAC_BITS__MVD) ); |
---|
1113 | |
---|
1114 | const Bool bHorAbsGr0 = uiHorAbs != 0; |
---|
1115 | const Bool bVerAbsGr0 = uiVerAbs != 0; |
---|
1116 | pCtx++; |
---|
1117 | |
---|
1118 | if( bHorAbsGr0 ) |
---|
1119 | { |
---|
1120 | m_pcTDecBinIf->decodeBin( uiSymbol, *pCtx RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(STATS__CABAC_BITS__MVD) ); |
---|
1121 | uiHorAbs += uiSymbol; |
---|
1122 | } |
---|
1123 | |
---|
1124 | if( bVerAbsGr0 ) |
---|
1125 | { |
---|
1126 | m_pcTDecBinIf->decodeBin( uiSymbol, *pCtx RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(STATS__CABAC_BITS__MVD) ); |
---|
1127 | uiVerAbs += uiSymbol; |
---|
1128 | } |
---|
1129 | |
---|
1130 | if( bHorAbsGr0 ) |
---|
1131 | { |
---|
1132 | if( 2 == uiHorAbs ) |
---|
1133 | { |
---|
1134 | xReadEpExGolomb( uiSymbol, 1 RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(STATS__CABAC_BITS__MVD_EP) ); |
---|
1135 | uiHorAbs += uiSymbol; |
---|
1136 | } |
---|
1137 | |
---|
1138 | m_pcTDecBinIf->decodeBinEP( uiHorSign RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(STATS__CABAC_BITS__MVD_EP) ); |
---|
1139 | } |
---|
1140 | |
---|
1141 | if( bVerAbsGr0 ) |
---|
1142 | { |
---|
1143 | if( 2 == uiVerAbs ) |
---|
1144 | { |
---|
1145 | xReadEpExGolomb( uiSymbol, 1 RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(STATS__CABAC_BITS__MVD_EP) ); |
---|
1146 | uiVerAbs += uiSymbol; |
---|
1147 | } |
---|
1148 | |
---|
1149 | m_pcTDecBinIf->decodeBinEP( uiVerSign RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(STATS__CABAC_BITS__MVD_EP) ); |
---|
1150 | } |
---|
1151 | |
---|
1152 | } |
---|
1153 | |
---|
1154 | const TComMv cMv( uiHorSign ? -Int( uiHorAbs ): uiHorAbs, uiVerSign ? -Int( uiVerAbs ) : uiVerAbs ); |
---|
1155 | pcCU->getCUMvField( eRefList )->setAllMvd( cMv, pcCU->getPartitionSize( uiAbsPartIdx ), uiAbsPartIdx, uiDepth, uiPartIdx ); |
---|
1156 | return; |
---|
1157 | } |
---|
1158 | |
---|
1159 | Void TDecSbac::parseCrossComponentPrediction( TComTU &rTu, ComponentID compID ) |
---|
1160 | { |
---|
1161 | TComDataCU *pcCU = rTu.getCU(); |
---|
1162 | |
---|
1163 | if( isLuma(compID) || !pcCU->getSlice()->getPPS()->getPpsRangeExtension().getCrossComponentPredictionEnabledFlag() ) |
---|
1164 | { |
---|
1165 | return; |
---|
1166 | } |
---|
1167 | |
---|
1168 | const UInt uiAbsPartIdx = rTu.GetAbsPartIdxTU(); |
---|
1169 | |
---|
1170 | if (!pcCU->isIntra(uiAbsPartIdx) || (pcCU->getIntraDir( CHANNEL_TYPE_CHROMA, uiAbsPartIdx ) == DM_CHROMA_IDX)) |
---|
1171 | { |
---|
1172 | SChar alpha = 0; |
---|
1173 | UInt symbol = 0; |
---|
1174 | |
---|
1175 | DTRACE_CABAC_VL( g_nSymbolCounter++ ) |
---|
1176 | DTRACE_CABAC_T("\tparseCrossComponentPrediction()") |
---|
1177 | DTRACE_CABAC_T( "\tAddr=" ) |
---|
1178 | DTRACE_CABAC_V( compID ) |
---|
1179 | DTRACE_CABAC_T( "\tuiAbsPartIdx=" ) |
---|
1180 | DTRACE_CABAC_V( uiAbsPartIdx ) |
---|
1181 | #if RExt__DECODER_DEBUG_BIT_STATISTICS |
---|
1182 | TComCodingStatisticsClassType ctype(STATS__CABAC_BITS__CROSS_COMPONENT_PREDICTION, (g_aucConvertToBit[rTu.getRect(compID).width] + 2), compID); |
---|
1183 | #endif |
---|
1184 | ContextModel *pCtx = m_cCrossComponentPredictionSCModel.get(0, 0) + ((compID == COMPONENT_Cr) ? (NUM_CROSS_COMPONENT_PREDICTION_CTX >> 1) : 0); |
---|
1185 | m_pcTDecBinIf->decodeBin( symbol, pCtx[0] RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(ctype) ); |
---|
1186 | |
---|
1187 | if(symbol != 0) |
---|
1188 | { |
---|
1189 | // Cross-component prediction alpha is non-zero. |
---|
1190 | UInt sign = 0; |
---|
1191 | m_pcTDecBinIf->decodeBin( symbol, pCtx[1] RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(ctype) ); |
---|
1192 | |
---|
1193 | if (symbol != 0) |
---|
1194 | { |
---|
1195 | // alpha is 2 (symbol=1), 4(symbol=2) or 8(symbol=3). |
---|
1196 | // Read up to two more bits |
---|
1197 | xReadUnaryMaxSymbol( symbol, (pCtx + 2), 1, 2 RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(ctype) ); |
---|
1198 | symbol += 1; |
---|
1199 | } |
---|
1200 | m_pcTDecBinIf->decodeBin( sign, pCtx[4] RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(ctype) ); |
---|
1201 | |
---|
1202 | alpha = (sign != 0) ? -(1 << symbol) : (1 << symbol); |
---|
1203 | } |
---|
1204 | DTRACE_CABAC_T( "\tAlpha=" ) |
---|
1205 | DTRACE_CABAC_V( alpha ) |
---|
1206 | DTRACE_CABAC_T( "\n" ) |
---|
1207 | |
---|
1208 | pcCU->setCrossComponentPredictionAlphaPartRange( alpha, compID, uiAbsPartIdx, rTu.GetAbsPartIdxNumParts( compID ) ); |
---|
1209 | } |
---|
1210 | } |
---|
1211 | |
---|
1212 | Void TDecSbac::parseTransformSubdivFlag( UInt& ruiSubdivFlag, UInt uiLog2TransformBlockSize ) |
---|
1213 | { |
---|
1214 | m_pcTDecBinIf->decodeBin( ruiSubdivFlag, m_cCUTransSubdivFlagSCModel.get( 0, 0, uiLog2TransformBlockSize ) |
---|
1215 | RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(TComCodingStatisticsClassType(STATS__CABAC_BITS__TRANSFORM_SUBDIV_FLAG, 5-uiLog2TransformBlockSize)) |
---|
1216 | ); |
---|
1217 | #if !NH_MV_ENC_DEC_TRAC |
---|
1218 | DTRACE_CABAC_VL( g_nSymbolCounter++ ) |
---|
1219 | DTRACE_CABAC_T( "\tparseTransformSubdivFlag()" ) |
---|
1220 | DTRACE_CABAC_T( "\tsymbol=" ) |
---|
1221 | DTRACE_CABAC_V( ruiSubdivFlag ) |
---|
1222 | DTRACE_CABAC_T( "\tctx=" ) |
---|
1223 | DTRACE_CABAC_V( uiLog2TransformBlockSize ) |
---|
1224 | DTRACE_CABAC_T( "\n" ) |
---|
1225 | #else |
---|
1226 | DTRACE_TU("split_transform_flag", ruiSubdivFlag ) |
---|
1227 | #endif |
---|
1228 | |
---|
1229 | } |
---|
1230 | |
---|
1231 | Void TDecSbac::parseQtRootCbf( UInt uiAbsPartIdx, UInt& uiQtRootCbf ) |
---|
1232 | { |
---|
1233 | UInt uiSymbol; |
---|
1234 | const UInt uiCtx = 0; |
---|
1235 | m_pcTDecBinIf->decodeBin( uiSymbol , m_cCUQtRootCbfSCModel.get( 0, 0, uiCtx ) RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(STATS__CABAC_BITS__QT_ROOT_CBF) ); |
---|
1236 | #if !NH_MV_ENC_DEC_TRAC |
---|
1237 | DTRACE_CABAC_VL( g_nSymbolCounter++ ) |
---|
1238 | DTRACE_CABAC_T( "\tparseQtRootCbf()" ) |
---|
1239 | DTRACE_CABAC_T( "\tsymbol=" ) |
---|
1240 | DTRACE_CABAC_V( uiSymbol ) |
---|
1241 | DTRACE_CABAC_T( "\tctx=" ) |
---|
1242 | DTRACE_CABAC_V( uiCtx ) |
---|
1243 | DTRACE_CABAC_T( "\tuiAbsPartIdx=" ) |
---|
1244 | DTRACE_CABAC_V( uiAbsPartIdx ) |
---|
1245 | DTRACE_CABAC_T( "\n" ) |
---|
1246 | #else |
---|
1247 | DTRACE_CU( "rqt_root_cbf", uiSymbol ) |
---|
1248 | #endif |
---|
1249 | |
---|
1250 | uiQtRootCbf = uiSymbol; |
---|
1251 | } |
---|
1252 | |
---|
1253 | Void TDecSbac::parseDeltaQP( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth ) |
---|
1254 | { |
---|
1255 | Int qp; |
---|
1256 | UInt uiDQp; |
---|
1257 | Int iDQp; |
---|
1258 | |
---|
1259 | UInt uiSymbol; |
---|
1260 | |
---|
1261 | 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) ); |
---|
1262 | |
---|
1263 | if( uiDQp >= CU_DQP_TU_CMAX) |
---|
1264 | { |
---|
1265 | xReadEpExGolomb( uiSymbol, CU_DQP_EG_k RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(STATS__CABAC_BITS__DELTA_QP_EP)); |
---|
1266 | uiDQp+=uiSymbol; |
---|
1267 | } |
---|
1268 | |
---|
1269 | if ( uiDQp > 0 ) |
---|
1270 | { |
---|
1271 | UInt uiSign; |
---|
1272 | Int qpBdOffsetY = pcCU->getSlice()->getSPS()->getQpBDOffset(CHANNEL_TYPE_LUMA); |
---|
1273 | m_pcTDecBinIf->decodeBinEP(uiSign RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(STATS__CABAC_BITS__DELTA_QP_EP)); |
---|
1274 | iDQp = uiDQp; |
---|
1275 | if(uiSign) |
---|
1276 | { |
---|
1277 | iDQp = -iDQp; |
---|
1278 | } |
---|
1279 | qp = (((Int) pcCU->getRefQP( uiAbsPartIdx ) + iDQp + 52 + 2*qpBdOffsetY )%(52+qpBdOffsetY)) - qpBdOffsetY; |
---|
1280 | } |
---|
1281 | else |
---|
1282 | { |
---|
1283 | qp = pcCU->getRefQP(uiAbsPartIdx); |
---|
1284 | } |
---|
1285 | |
---|
1286 | pcCU->setQPSubParts(qp, uiAbsPartIdx, uiDepth); |
---|
1287 | pcCU->setCodedQP(qp); |
---|
1288 | } |
---|
1289 | |
---|
1290 | /** parse chroma qp adjustment, converting to the internal table representation. |
---|
1291 | * \returns Void |
---|
1292 | */ |
---|
1293 | Void TDecSbac::parseChromaQpAdjustment( TComDataCU* cu, UInt absPartIdx, UInt depth ) |
---|
1294 | { |
---|
1295 | UInt symbol; |
---|
1296 | #if RExt__DECODER_DEBUG_BIT_STATISTICS |
---|
1297 | const TComCodingStatisticsClassType ctype(STATS__CABAC_BITS__CHROMA_QP_ADJUSTMENT, g_aucConvertToBit[cu->getSlice()->getSPS()->getMaxCUWidth()>>depth]+2, CHANNEL_TYPE_CHROMA); |
---|
1298 | #endif |
---|
1299 | |
---|
1300 | Int chromaQpOffsetListLen = cu->getSlice()->getPPS()->getPpsRangeExtension().getChromaQpOffsetListLen(); |
---|
1301 | |
---|
1302 | // cu_chroma_qp_offset_flag |
---|
1303 | m_pcTDecBinIf->decodeBin( symbol, m_ChromaQpAdjFlagSCModel.get( 0, 0, 0 ) RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(ctype) ); |
---|
1304 | |
---|
1305 | if (symbol && chromaQpOffsetListLen > 1) |
---|
1306 | { |
---|
1307 | // cu_chroma_qp_offset_idx |
---|
1308 | xReadUnaryMaxSymbol( symbol, &m_ChromaQpAdjIdcSCModel.get( 0, 0, 0 ), 0, chromaQpOffsetListLen - 1 RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(ctype) ); |
---|
1309 | symbol++; |
---|
1310 | } |
---|
1311 | /* NB, symbol = 0 if outer flag is not set, |
---|
1312 | * 1 if outer flag is set and there is no inner flag |
---|
1313 | * 1+ otherwise */ |
---|
1314 | cu->setChromaQpAdjSubParts( symbol, absPartIdx, depth ); |
---|
1315 | cu->setCodedChromaQpAdj(symbol); |
---|
1316 | } |
---|
1317 | |
---|
1318 | Void TDecSbac::parseQtCbf( TComTU &rTu, const ComponentID compID, const Bool lowestLevel ) |
---|
1319 | { |
---|
1320 | TComDataCU* pcCU = rTu.getCU(); |
---|
1321 | |
---|
1322 | const UInt absPartIdx = rTu.GetAbsPartIdxTU(compID); |
---|
1323 | const UInt TUDepth = rTu.GetTransformDepthRel(); |
---|
1324 | const UInt uiCtx = pcCU->getCtxQtCbf( rTu, toChannelType(compID) ); |
---|
1325 | const UInt contextSet = toChannelType(compID); |
---|
1326 | |
---|
1327 | const UInt width = rTu.getRect(compID).width; |
---|
1328 | const UInt height = rTu.getRect(compID).height; |
---|
1329 | const Bool canQuadSplit = (width >= (MIN_TU_SIZE * 2)) && (height >= (MIN_TU_SIZE * 2)); |
---|
1330 | const UInt coveredPartIdxes = rTu.GetAbsPartIdxNumParts(compID); |
---|
1331 | |
---|
1332 | // Since the CBF for chroma is coded at the highest level possible, if sub-TUs are |
---|
1333 | // to be coded for a 4x8 chroma TU, their CBFs must be coded at the highest 4x8 level |
---|
1334 | // (i.e. where luma TUs are 8x8 rather than 4x4) |
---|
1335 | // ___ ___ |
---|
1336 | // | | | <- 4 x (8x8 luma + 4x8 4:2:2 chroma) |
---|
1337 | // |___|___| each quadrant has its own chroma CBF |
---|
1338 | // | | | _ _ _ _ |
---|
1339 | // |___|___| | |
---|
1340 | // <--16---> V |
---|
1341 | // _ _ |
---|
1342 | // |_|_| <- 4 x 4x4 luma + 1 x 4x8 4:2:2 chroma |
---|
1343 | // |_|_| no chroma CBF is coded - instead the parent CBF is inherited |
---|
1344 | // <-8-> if sub-TUs are present, their CBFs had to be coded at the parent level |
---|
1345 | |
---|
1346 | const UInt lowestTUDepth = TUDepth + ((!lowestLevel && !canQuadSplit) ? 1 : 0); //unsplittable TUs inherit their parent's CBF |
---|
1347 | UInt lowestTUCBF = 0; |
---|
1348 | |
---|
1349 | if ((width != height) && (lowestLevel || !canQuadSplit)) //if sub-TUs are present |
---|
1350 | { |
---|
1351 | const UInt subTUDepth = lowestTUDepth + 1; |
---|
1352 | const UInt partIdxesPerSubTU = rTu.GetAbsPartIdxNumParts(compID) >> 1; |
---|
1353 | |
---|
1354 | UInt combinedSubTUCBF = 0; |
---|
1355 | |
---|
1356 | for (UInt subTU = 0; subTU < 2; subTU++) |
---|
1357 | { |
---|
1358 | UInt uiCbf = MAX_UINT; |
---|
1359 | 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))); |
---|
1360 | |
---|
1361 | const UInt subTUAbsPartIdx = absPartIdx + (subTU * partIdxesPerSubTU); |
---|
1362 | pcCU->setCbfPartRange((uiCbf << subTUDepth), compID, subTUAbsPartIdx, partIdxesPerSubTU); |
---|
1363 | combinedSubTUCBF |= uiCbf; |
---|
1364 | #if !NH_MV_ENC_DEC_TRAC |
---|
1365 | DTRACE_CABAC_VL( g_nSymbolCounter++ ) |
---|
1366 | DTRACE_CABAC_T( "\tparseQtCbf()" ) |
---|
1367 | DTRACE_CABAC_T( "\tsub-TU=" ) |
---|
1368 | DTRACE_CABAC_V( subTU ) |
---|
1369 | DTRACE_CABAC_T( "\tsymbol=" ) |
---|
1370 | DTRACE_CABAC_V( uiCbf ) |
---|
1371 | DTRACE_CABAC_T( "\tctx=" ) |
---|
1372 | DTRACE_CABAC_V( uiCtx ) |
---|
1373 | DTRACE_CABAC_T( "\tetype=" ) |
---|
1374 | DTRACE_CABAC_V( compID ) |
---|
1375 | DTRACE_CABAC_T( "\tuiAbsPartIdx=" ) |
---|
1376 | DTRACE_CABAC_V( subTUAbsPartIdx ) |
---|
1377 | DTRACE_CABAC_T( "\n" ) |
---|
1378 | #else |
---|
1379 | if ( compID == COMPONENT_Cb ) |
---|
1380 | { |
---|
1381 | DTRACE_TU("cbf_cb", uiCbf ) |
---|
1382 | } |
---|
1383 | else if ( compID == COMPONENT_Cr ) |
---|
1384 | { |
---|
1385 | DTRACE_TU("cbf_cr", uiCbf ) |
---|
1386 | } |
---|
1387 | else |
---|
1388 | { |
---|
1389 | DTRACE_TU("cbf_luma", uiCbf ) |
---|
1390 | } |
---|
1391 | #endif |
---|
1392 | |
---|
1393 | } |
---|
1394 | |
---|
1395 | //propagate the sub-TU CBF up to the lowest TU level |
---|
1396 | if (combinedSubTUCBF != 0) |
---|
1397 | { |
---|
1398 | pcCU->bitwiseOrCbfPartRange((combinedSubTUCBF << lowestTUDepth), compID, absPartIdx, coveredPartIdxes); |
---|
1399 | lowestTUCBF = combinedSubTUCBF; |
---|
1400 | } |
---|
1401 | } |
---|
1402 | else |
---|
1403 | { |
---|
1404 | UInt uiCbf = MAX_UINT; |
---|
1405 | 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))); |
---|
1406 | |
---|
1407 | pcCU->setCbfSubParts((uiCbf << lowestTUDepth), compID, absPartIdx, rTu.GetTransformDepthTotalAdj(compID)); |
---|
1408 | #if !NH_MV_ENC_DEC_TRAC |
---|
1409 | DTRACE_CABAC_VL( g_nSymbolCounter++ ) |
---|
1410 | DTRACE_CABAC_T( "\tparseQtCbf()" ) |
---|
1411 | DTRACE_CABAC_T( "\tsymbol=" ) |
---|
1412 | DTRACE_CABAC_V( uiCbf ) |
---|
1413 | DTRACE_CABAC_T( "\tctx=" ) |
---|
1414 | DTRACE_CABAC_V( uiCtx ) |
---|
1415 | DTRACE_CABAC_T( "\tetype=" ) |
---|
1416 | DTRACE_CABAC_V( compID ) |
---|
1417 | DTRACE_CABAC_T( "\tuiAbsPartIdx=" ) |
---|
1418 | DTRACE_CABAC_V( rTu.GetAbsPartIdxTU(compID) ) |
---|
1419 | DTRACE_CABAC_T( "\n" ) |
---|
1420 | #else |
---|
1421 | if ( compID == COMPONENT_Cb ) |
---|
1422 | { |
---|
1423 | DTRACE_TU("cbf_cb", uiCbf ) |
---|
1424 | } |
---|
1425 | else if ( compID == COMPONENT_Cr ) |
---|
1426 | { |
---|
1427 | DTRACE_TU("cbf_cr", uiCbf ) |
---|
1428 | } |
---|
1429 | else |
---|
1430 | { |
---|
1431 | DTRACE_TU("cbf_luma", uiCbf ) |
---|
1432 | } |
---|
1433 | #endif |
---|
1434 | lowestTUCBF = uiCbf; |
---|
1435 | } |
---|
1436 | |
---|
1437 | //propagate the lowest level CBF up to the current level |
---|
1438 | if (lowestTUCBF != 0) |
---|
1439 | { |
---|
1440 | for (UInt depth = TUDepth; depth < lowestTUDepth; depth++) |
---|
1441 | { |
---|
1442 | pcCU->bitwiseOrCbfPartRange((lowestTUCBF << depth), compID, absPartIdx, coveredPartIdxes); |
---|
1443 | } |
---|
1444 | } |
---|
1445 | } |
---|
1446 | |
---|
1447 | |
---|
1448 | Void TDecSbac::parseTransformSkipFlags (TComTU &rTu, ComponentID component) |
---|
1449 | { |
---|
1450 | TComDataCU* pcCU=rTu.getCU(); |
---|
1451 | UInt uiAbsPartIdx=rTu.GetAbsPartIdxTU(component); |
---|
1452 | |
---|
1453 | if (pcCU->getCUTransquantBypass(uiAbsPartIdx)) |
---|
1454 | { |
---|
1455 | return; |
---|
1456 | } |
---|
1457 | |
---|
1458 | if (!TUCompRectHasAssociatedTransformSkipFlag(rTu.getRect(component), pcCU->getSlice()->getPPS()->getPpsRangeExtension().getLog2MaxTransformSkipBlockSize())) |
---|
1459 | { |
---|
1460 | return; |
---|
1461 | } |
---|
1462 | |
---|
1463 | UInt useTransformSkip; |
---|
1464 | |
---|
1465 | m_pcTDecBinIf->decodeBin( useTransformSkip , m_cTransformSkipSCModel.get( 0, toChannelType(component), 0 ) |
---|
1466 | RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(TComCodingStatisticsClassType(STATS__CABAC_BITS__TRANSFORM_SKIP_FLAGS, component)) |
---|
1467 | ); |
---|
1468 | |
---|
1469 | #if !NH_MV_ENC_DEC_TRAC |
---|
1470 | DTRACE_CABAC_VL( g_nSymbolCounter++ ) |
---|
1471 | DTRACE_CABAC_T("\tparseTransformSkip()"); |
---|
1472 | DTRACE_CABAC_T( "\tsymbol=" ) |
---|
1473 | DTRACE_CABAC_V( useTransformSkip ) |
---|
1474 | DTRACE_CABAC_T( "\tAddr=" ) |
---|
1475 | DTRACE_CABAC_V( pcCU->getCtuRsAddr() ) |
---|
1476 | DTRACE_CABAC_T( "\tetype=" ) |
---|
1477 | DTRACE_CABAC_V( component ) |
---|
1478 | DTRACE_CABAC_T( "\tuiAbsPartIdx=" ) |
---|
1479 | DTRACE_CABAC_V( rTu.GetAbsPartIdxTU() ) |
---|
1480 | DTRACE_CABAC_T( "\n" ) |
---|
1481 | #endif |
---|
1482 | |
---|
1483 | pcCU->setTransformSkipPartRange( useTransformSkip, component, uiAbsPartIdx, rTu.GetAbsPartIdxNumParts(component)); |
---|
1484 | } |
---|
1485 | |
---|
1486 | |
---|
1487 | /** Parse (X,Y) position of the last significant coefficient |
---|
1488 | * \param uiPosLastX reference to X component of last coefficient |
---|
1489 | * \param uiPosLastY reference to Y component of last coefficient |
---|
1490 | * \param width Block width |
---|
1491 | * \param height Block height |
---|
1492 | * \param component chroma compinent ID |
---|
1493 | * \param uiScanIdx scan type (zig-zag, hor, ver) |
---|
1494 | * |
---|
1495 | * This method decodes the X and Y component within a block of the last significant coefficient. |
---|
1496 | */ |
---|
1497 | Void TDecSbac::parseLastSignificantXY( UInt& uiPosLastX, UInt& uiPosLastY, Int width, Int height, ComponentID component, UInt uiScanIdx ) |
---|
1498 | { |
---|
1499 | UInt uiLast; |
---|
1500 | |
---|
1501 | ContextModel *pCtxX = m_cCuCtxLastX.get( 0, toChannelType(component) ); |
---|
1502 | ContextModel *pCtxY = m_cCuCtxLastY.get( 0, toChannelType(component) ); |
---|
1503 | |
---|
1504 | #if RExt__DECODER_DEBUG_BIT_STATISTICS |
---|
1505 | TComCodingStatisticsClassType ctype(STATS__CABAC_BITS__LAST_SIG_X_Y, g_aucConvertToBit[width]+2, component); |
---|
1506 | #endif |
---|
1507 | |
---|
1508 | |
---|
1509 | if ( uiScanIdx == SCAN_VER ) |
---|
1510 | { |
---|
1511 | swap( width, height ); |
---|
1512 | } |
---|
1513 | |
---|
1514 | Int blkSizeOffsetX, blkSizeOffsetY, shiftX, shiftY; |
---|
1515 | getLastSignificantContextParameters(component, width, height, blkSizeOffsetX, blkSizeOffsetY, shiftX, shiftY); |
---|
1516 | |
---|
1517 | //------------------ |
---|
1518 | |
---|
1519 | // posX |
---|
1520 | |
---|
1521 | for( uiPosLastX = 0; uiPosLastX < g_uiGroupIdx[ width - 1 ]; uiPosLastX++ ) |
---|
1522 | { |
---|
1523 | m_pcTDecBinIf->decodeBin( uiLast, *( pCtxX + blkSizeOffsetX + (uiPosLastX >>shiftX) ) RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(ctype) ); |
---|
1524 | |
---|
1525 | if( !uiLast ) |
---|
1526 | { |
---|
1527 | break; |
---|
1528 | } |
---|
1529 | } |
---|
1530 | |
---|
1531 | // posY |
---|
1532 | |
---|
1533 | for( uiPosLastY = 0; uiPosLastY < g_uiGroupIdx[ height - 1 ]; uiPosLastY++ ) |
---|
1534 | { |
---|
1535 | m_pcTDecBinIf->decodeBin( uiLast, *( pCtxY + blkSizeOffsetY + (uiPosLastY >>shiftY)) RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(ctype) ); |
---|
1536 | |
---|
1537 | if( !uiLast ) |
---|
1538 | { |
---|
1539 | break; |
---|
1540 | } |
---|
1541 | } |
---|
1542 | |
---|
1543 | // EP-coded part |
---|
1544 | |
---|
1545 | if ( uiPosLastX > 3 ) |
---|
1546 | { |
---|
1547 | UInt uiTemp = 0; |
---|
1548 | UInt uiCount = ( uiPosLastX - 2 ) >> 1; |
---|
1549 | for ( Int i = uiCount - 1; i >= 0; i-- ) |
---|
1550 | { |
---|
1551 | m_pcTDecBinIf->decodeBinEP( uiLast RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(ctype) ); |
---|
1552 | uiTemp += uiLast << i; |
---|
1553 | } |
---|
1554 | uiPosLastX = g_uiMinInGroup[ uiPosLastX ] + uiTemp; |
---|
1555 | } |
---|
1556 | if ( uiPosLastY > 3 ) |
---|
1557 | { |
---|
1558 | UInt uiTemp = 0; |
---|
1559 | UInt uiCount = ( uiPosLastY - 2 ) >> 1; |
---|
1560 | for ( Int i = uiCount - 1; i >= 0; i-- ) |
---|
1561 | { |
---|
1562 | m_pcTDecBinIf->decodeBinEP( uiLast RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(ctype) ); |
---|
1563 | uiTemp += uiLast << i; |
---|
1564 | } |
---|
1565 | uiPosLastY = g_uiMinInGroup[ uiPosLastY ] + uiTemp; |
---|
1566 | } |
---|
1567 | |
---|
1568 | if( uiScanIdx == SCAN_VER ) |
---|
1569 | { |
---|
1570 | swap( uiPosLastX, uiPosLastY ); |
---|
1571 | } |
---|
1572 | } |
---|
1573 | |
---|
1574 | Void TDecSbac::parseCoeffNxN( TComTU &rTu, ComponentID compID ) |
---|
1575 | { |
---|
1576 | TComDataCU* pcCU=rTu.getCU(); |
---|
1577 | const UInt uiAbsPartIdx=rTu.GetAbsPartIdxTU(compID); |
---|
1578 | const TComRectangle &rRect=rTu.getRect(compID); |
---|
1579 | const UInt uiWidth=rRect.width; |
---|
1580 | const UInt uiHeight=rRect.height; |
---|
1581 | TCoeff* pcCoef=(pcCU->getCoeff(compID)+rTu.getCoefficientOffset(compID)); |
---|
1582 | const TComSPS &sps=*(pcCU->getSlice()->getSPS()); |
---|
1583 | #if !NH_MV_ENC_DEC_TRAC |
---|
1584 | DTRACE_CABAC_VL( g_nSymbolCounter++ ) |
---|
1585 | DTRACE_CABAC_T( "\tparseCoeffNxN()\teType=" ) |
---|
1586 | DTRACE_CABAC_V( compID ) |
---|
1587 | DTRACE_CABAC_T( "\twidth=" ) |
---|
1588 | DTRACE_CABAC_V( uiWidth ) |
---|
1589 | DTRACE_CABAC_T( "\theight=" ) |
---|
1590 | DTRACE_CABAC_V( uiHeight ) |
---|
1591 | DTRACE_CABAC_T( "\tdepth=" ) |
---|
1592 | // DTRACE_CABAC_V( rTu.GetTransformDepthTotalAdj(compID) ) |
---|
1593 | DTRACE_CABAC_V( rTu.GetTransformDepthTotal() ) |
---|
1594 | DTRACE_CABAC_T( "\tabspartidx=" ) |
---|
1595 | // DTRACE_CABAC_V( uiAbsPartIdx ) |
---|
1596 | DTRACE_CABAC_V( rTu.GetAbsPartIdxTU(compID) ) |
---|
1597 | DTRACE_CABAC_T( "\ttoCU-X=" ) |
---|
1598 | DTRACE_CABAC_V( pcCU->getCUPelX() ) |
---|
1599 | DTRACE_CABAC_T( "\ttoCU-Y=" ) |
---|
1600 | DTRACE_CABAC_V( pcCU->getCUPelY() ) |
---|
1601 | DTRACE_CABAC_T( "\tCU-addr=" ) |
---|
1602 | DTRACE_CABAC_V( pcCU->getCtuRsAddr() ) |
---|
1603 | DTRACE_CABAC_T( "\tinCU-X=" ) |
---|
1604 | // DTRACE_CABAC_V( g_auiRasterToPelX[ g_auiZscanToRaster[uiAbsPartIdx] ] ) |
---|
1605 | DTRACE_CABAC_V( g_auiRasterToPelX[ g_auiZscanToRaster[rTu.GetAbsPartIdxTU(compID)] ] ) |
---|
1606 | DTRACE_CABAC_T( "\tinCU-Y=" ) |
---|
1607 | // DTRACE_CABAC_V( g_auiRasterToPelY[ g_auiZscanToRaster[uiAbsPartIdx] ] ) |
---|
1608 | DTRACE_CABAC_V( g_auiRasterToPelY[ g_auiZscanToRaster[rTu.GetAbsPartIdxTU(compID)] ] ) |
---|
1609 | DTRACE_CABAC_T( "\tpredmode=" ) |
---|
1610 | DTRACE_CABAC_V( pcCU->getPredictionMode( uiAbsPartIdx ) ) |
---|
1611 | DTRACE_CABAC_T( "\n" ) |
---|
1612 | #endif |
---|
1613 | |
---|
1614 | //-------------------------------------------------------------------------------------------------- |
---|
1615 | |
---|
1616 | if( uiWidth > sps.getMaxTrSize() ) |
---|
1617 | { |
---|
1618 | std::cerr << "ERROR: parseCoeffNxN was passed a TU with dimensions larger than the maximum allowed size" << std::endl; |
---|
1619 | assert(false); |
---|
1620 | exit(1); |
---|
1621 | } |
---|
1622 | |
---|
1623 | //-------------------------------------------------------------------------------------------------- |
---|
1624 | |
---|
1625 | //set parameters |
---|
1626 | |
---|
1627 | const ChannelType chType = toChannelType(compID); |
---|
1628 | const UInt uiLog2BlockWidth = g_aucConvertToBit[ uiWidth ] + 2; |
---|
1629 | const UInt uiLog2BlockHeight = g_aucConvertToBit[ uiHeight ] + 2; |
---|
1630 | const UInt uiMaxNumCoeff = uiWidth * uiHeight; |
---|
1631 | const UInt uiMaxNumCoeffM1 = uiMaxNumCoeff - 1; |
---|
1632 | |
---|
1633 | const ChannelType channelType = toChannelType(compID); |
---|
1634 | const Bool extendedPrecision = sps.getSpsRangeExtension().getExtendedPrecisionProcessingFlag(); |
---|
1635 | |
---|
1636 | const Bool alignCABACBeforeBypass = sps.getSpsRangeExtension().getCabacBypassAlignmentEnabledFlag(); |
---|
1637 | const Int maxLog2TrDynamicRange = sps.getMaxLog2TrDynamicRange(channelType); |
---|
1638 | |
---|
1639 | #if RExt__DECODER_DEBUG_BIT_STATISTICS |
---|
1640 | TComCodingStatisticsClassType ctype_group(STATS__CABAC_BITS__SIG_COEFF_GROUP_FLAG, uiLog2BlockWidth, compID); |
---|
1641 | TComCodingStatisticsClassType ctype_map(STATS__CABAC_BITS__SIG_COEFF_MAP_FLAG, uiLog2BlockWidth, compID); |
---|
1642 | TComCodingStatisticsClassType ctype_gt1(STATS__CABAC_BITS__GT1_FLAG, uiLog2BlockWidth, compID); |
---|
1643 | TComCodingStatisticsClassType ctype_gt2(STATS__CABAC_BITS__GT2_FLAG, uiLog2BlockWidth, compID); |
---|
1644 | #endif |
---|
1645 | |
---|
1646 | Bool beValid; |
---|
1647 | if (pcCU->getCUTransquantBypass(uiAbsPartIdx)) |
---|
1648 | { |
---|
1649 | beValid = false; |
---|
1650 | if((!pcCU->isIntra(uiAbsPartIdx)) && pcCU->isRDPCMEnabled(uiAbsPartIdx)) |
---|
1651 | { |
---|
1652 | parseExplicitRdpcmMode(rTu, compID); |
---|
1653 | } |
---|
1654 | } |
---|
1655 | else |
---|
1656 | { |
---|
1657 | beValid = pcCU->getSlice()->getPPS()->getSignDataHidingEnabledFlag(); |
---|
1658 | } |
---|
1659 | |
---|
1660 | UInt absSum = 0; |
---|
1661 | |
---|
1662 | //-------------------------------------------------------------------------------------------------- |
---|
1663 | |
---|
1664 | if(pcCU->getSlice()->getPPS()->getUseTransformSkip()) |
---|
1665 | { |
---|
1666 | parseTransformSkipFlags(rTu, compID); |
---|
1667 | // This TU has coefficients and is transform skipped. Check whether is inter coded and if yes decode the explicit RDPCM mode |
---|
1668 | if(pcCU->getTransformSkip(uiAbsPartIdx, compID) && (!pcCU->isIntra(uiAbsPartIdx)) && pcCU->isRDPCMEnabled(uiAbsPartIdx) ) |
---|
1669 | { |
---|
1670 | parseExplicitRdpcmMode(rTu, compID); |
---|
1671 | if(pcCU->getExplicitRdpcmMode(compID, uiAbsPartIdx) != RDPCM_OFF) |
---|
1672 | { |
---|
1673 | // Sign data hiding is avoided for horizontal and vertical RDPCM modes |
---|
1674 | beValid = false; |
---|
1675 | } |
---|
1676 | } |
---|
1677 | } |
---|
1678 | |
---|
1679 | Int uiIntraMode = -1; |
---|
1680 | const Bool bIsLuma = isLuma(compID); |
---|
1681 | Int isIntra = pcCU->isIntra(uiAbsPartIdx) ? 1 : 0; |
---|
1682 | if ( isIntra && pcCU->isRDPCMEnabled(uiAbsPartIdx) ) |
---|
1683 | { |
---|
1684 | const UInt partsPerMinCU = 1<<(2*(sps.getMaxTotalCUDepth() - sps.getLog2DiffMaxMinCodingBlockSize())); |
---|
1685 | uiIntraMode = pcCU->getIntraDir( toChannelType(compID), uiAbsPartIdx ); |
---|
1686 | uiIntraMode = (uiIntraMode==DM_CHROMA_IDX && !bIsLuma) ? pcCU->getIntraDir(CHANNEL_TYPE_LUMA, getChromasCorrespondingPULumaIdx(uiAbsPartIdx, rTu.GetChromaFormat(), partsPerMinCU)) : uiIntraMode; |
---|
1687 | uiIntraMode = ((rTu.GetChromaFormat() == CHROMA_422) && !bIsLuma) ? g_chroma422IntraAngleMappingTable[uiIntraMode] : uiIntraMode; |
---|
1688 | |
---|
1689 | Bool transformSkip = pcCU->getTransformSkip( uiAbsPartIdx,compID); |
---|
1690 | Bool rdpcm_lossy = ( transformSkip /*&& isIntra*/ && ( (uiIntraMode == HOR_IDX) || (uiIntraMode == VER_IDX) ) ); |
---|
1691 | if ( rdpcm_lossy ) |
---|
1692 | { |
---|
1693 | beValid = false; |
---|
1694 | } |
---|
1695 | } |
---|
1696 | |
---|
1697 | //-------------------------------------------------------------------------------------------------- |
---|
1698 | |
---|
1699 | const Bool bUseGolombRiceParameterAdaptation = sps.getSpsRangeExtension().getPersistentRiceAdaptationEnabledFlag(); |
---|
1700 | UInt ¤tGolombRiceStatistic = m_golombRiceAdaptationStatistics[rTu.getGolombRiceStatisticsIndex(compID)]; |
---|
1701 | |
---|
1702 | //select scans |
---|
1703 | TUEntropyCodingParameters codingParameters; |
---|
1704 | getTUEntropyCodingParameters(codingParameters, rTu, compID); |
---|
1705 | |
---|
1706 | //===== decode last significant ===== |
---|
1707 | UInt uiPosLastX, uiPosLastY; |
---|
1708 | parseLastSignificantXY( uiPosLastX, uiPosLastY, uiWidth, uiHeight, compID, codingParameters.scanType ); |
---|
1709 | UInt uiBlkPosLast = uiPosLastX + (uiPosLastY<<uiLog2BlockWidth); |
---|
1710 | pcCoef[ uiBlkPosLast ] = 1; |
---|
1711 | |
---|
1712 | //===== decode significance flags ===== |
---|
1713 | UInt uiScanPosLast; |
---|
1714 | for( uiScanPosLast = 0; uiScanPosLast < uiMaxNumCoeffM1; uiScanPosLast++ ) |
---|
1715 | { |
---|
1716 | UInt uiBlkPos = codingParameters.scan[ uiScanPosLast ]; |
---|
1717 | if( uiBlkPosLast == uiBlkPos ) |
---|
1718 | { |
---|
1719 | break; |
---|
1720 | } |
---|
1721 | } |
---|
1722 | |
---|
1723 | ContextModel * const baseCoeffGroupCtx = m_cCUSigCoeffGroupSCModel.get( 0, isChroma(chType) ); |
---|
1724 | ContextModel * const baseCtx = m_cCUSigSCModel.get( 0, 0 ) + getSignificanceMapContextOffset(compID); |
---|
1725 | |
---|
1726 | const Int iLastScanSet = uiScanPosLast >> MLS_CG_SIZE; |
---|
1727 | UInt c1 = 1; |
---|
1728 | UInt uiGoRiceParam = 0; |
---|
1729 | |
---|
1730 | |
---|
1731 | UInt uiSigCoeffGroupFlag[ MLS_GRP_NUM ]; |
---|
1732 | memset( uiSigCoeffGroupFlag, 0, sizeof(UInt) * MLS_GRP_NUM ); |
---|
1733 | |
---|
1734 | Int iScanPosSig = (Int) uiScanPosLast; |
---|
1735 | for( Int iSubSet = iLastScanSet; iSubSet >= 0; iSubSet-- ) |
---|
1736 | { |
---|
1737 | Int iSubPos = iSubSet << MLS_CG_SIZE; |
---|
1738 | uiGoRiceParam = currentGolombRiceStatistic / RExt__GOLOMB_RICE_INCREMENT_DIVISOR; |
---|
1739 | Bool updateGolombRiceStatistics = bUseGolombRiceParameterAdaptation; //leave the statistics at 0 when not using the adaptation system |
---|
1740 | Int numNonZero = 0; |
---|
1741 | |
---|
1742 | Int lastNZPosInCG = -1; |
---|
1743 | Int firstNZPosInCG = 1 << MLS_CG_SIZE; |
---|
1744 | |
---|
1745 | Bool escapeDataPresentInGroup = false; |
---|
1746 | |
---|
1747 | Int pos[1 << MLS_CG_SIZE]; |
---|
1748 | |
---|
1749 | if( iScanPosSig == (Int) uiScanPosLast ) |
---|
1750 | { |
---|
1751 | lastNZPosInCG = iScanPosSig; |
---|
1752 | firstNZPosInCG = iScanPosSig; |
---|
1753 | iScanPosSig--; |
---|
1754 | pos[ numNonZero ] = uiBlkPosLast; |
---|
1755 | numNonZero = 1; |
---|
1756 | } |
---|
1757 | |
---|
1758 | // decode significant_coeffgroup_flag |
---|
1759 | Int iCGBlkPos = codingParameters.scanCG[ iSubSet ]; |
---|
1760 | Int iCGPosY = iCGBlkPos / codingParameters.widthInGroups; |
---|
1761 | Int iCGPosX = iCGBlkPos - (iCGPosY * codingParameters.widthInGroups); |
---|
1762 | |
---|
1763 | if( iSubSet == iLastScanSet || iSubSet == 0) |
---|
1764 | { |
---|
1765 | uiSigCoeffGroupFlag[ iCGBlkPos ] = 1; |
---|
1766 | } |
---|
1767 | else |
---|
1768 | { |
---|
1769 | UInt uiSigCoeffGroup; |
---|
1770 | UInt uiCtxSig = TComTrQuant::getSigCoeffGroupCtxInc( uiSigCoeffGroupFlag, iCGPosX, iCGPosY, codingParameters.widthInGroups, codingParameters.heightInGroups ); |
---|
1771 | m_pcTDecBinIf->decodeBin( uiSigCoeffGroup, baseCoeffGroupCtx[ uiCtxSig ] RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(ctype_group) ); |
---|
1772 | uiSigCoeffGroupFlag[ iCGBlkPos ] = uiSigCoeffGroup; |
---|
1773 | } |
---|
1774 | |
---|
1775 | // decode significant_coeff_flag |
---|
1776 | const Int patternSigCtx = TComTrQuant::calcPatternSigCtx(uiSigCoeffGroupFlag, iCGPosX, iCGPosY, codingParameters.widthInGroups, codingParameters.heightInGroups); |
---|
1777 | |
---|
1778 | UInt uiBlkPos, uiSig, uiCtxSig; |
---|
1779 | for( ; iScanPosSig >= iSubPos; iScanPosSig-- ) |
---|
1780 | { |
---|
1781 | uiBlkPos = codingParameters.scan[ iScanPosSig ]; |
---|
1782 | uiSig = 0; |
---|
1783 | |
---|
1784 | if( uiSigCoeffGroupFlag[ iCGBlkPos ] ) |
---|
1785 | { |
---|
1786 | if( iScanPosSig > iSubPos || iSubSet == 0 || numNonZero ) |
---|
1787 | { |
---|
1788 | uiCtxSig = TComTrQuant::getSigCtxInc( patternSigCtx, codingParameters, iScanPosSig, uiLog2BlockWidth, uiLog2BlockHeight, chType ); |
---|
1789 | m_pcTDecBinIf->decodeBin( uiSig, baseCtx[ uiCtxSig ] RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(ctype_map) ); |
---|
1790 | } |
---|
1791 | else |
---|
1792 | { |
---|
1793 | uiSig = 1; |
---|
1794 | } |
---|
1795 | } |
---|
1796 | pcCoef[ uiBlkPos ] = uiSig; |
---|
1797 | if( uiSig ) |
---|
1798 | { |
---|
1799 | pos[ numNonZero ] = uiBlkPos; |
---|
1800 | numNonZero ++; |
---|
1801 | if( lastNZPosInCG == -1 ) |
---|
1802 | { |
---|
1803 | lastNZPosInCG = iScanPosSig; |
---|
1804 | } |
---|
1805 | firstNZPosInCG = iScanPosSig; |
---|
1806 | } |
---|
1807 | } |
---|
1808 | |
---|
1809 | if( numNonZero > 0 ) |
---|
1810 | { |
---|
1811 | Bool signHidden = ( lastNZPosInCG - firstNZPosInCG >= SBH_THRESHOLD ); |
---|
1812 | |
---|
1813 | absSum = 0; |
---|
1814 | |
---|
1815 | const UInt uiCtxSet = getContextSetIndex(compID, iSubSet, (c1 == 0)); |
---|
1816 | c1 = 1; |
---|
1817 | UInt uiBin; |
---|
1818 | |
---|
1819 | ContextModel *baseCtxMod = m_cCUOneSCModel.get( 0, 0 ) + (NUM_ONE_FLAG_CTX_PER_SET * uiCtxSet); |
---|
1820 | |
---|
1821 | Int absCoeff[1 << MLS_CG_SIZE]; |
---|
1822 | |
---|
1823 | for ( Int i = 0; i < numNonZero; i++) |
---|
1824 | { |
---|
1825 | absCoeff[i] = 1; |
---|
1826 | } |
---|
1827 | Int numC1Flag = min(numNonZero, C1FLAG_NUMBER); |
---|
1828 | Int firstC2FlagIdx = -1; |
---|
1829 | |
---|
1830 | for( Int idx = 0; idx < numC1Flag; idx++ ) |
---|
1831 | { |
---|
1832 | m_pcTDecBinIf->decodeBin( uiBin, baseCtxMod[c1] RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(ctype_gt1) ); |
---|
1833 | if( uiBin == 1 ) |
---|
1834 | { |
---|
1835 | c1 = 0; |
---|
1836 | if (firstC2FlagIdx == -1) |
---|
1837 | { |
---|
1838 | firstC2FlagIdx = idx; |
---|
1839 | } |
---|
1840 | else //if a greater-than-one has been encountered already this group |
---|
1841 | { |
---|
1842 | escapeDataPresentInGroup = true; |
---|
1843 | } |
---|
1844 | } |
---|
1845 | else if( (c1 < 3) && (c1 > 0) ) |
---|
1846 | { |
---|
1847 | c1++; |
---|
1848 | } |
---|
1849 | absCoeff[ idx ] = uiBin + 1; |
---|
1850 | } |
---|
1851 | |
---|
1852 | if (c1 == 0) |
---|
1853 | { |
---|
1854 | baseCtxMod = m_cCUAbsSCModel.get( 0, 0 ) + (NUM_ABS_FLAG_CTX_PER_SET * uiCtxSet); |
---|
1855 | if ( firstC2FlagIdx != -1) |
---|
1856 | { |
---|
1857 | m_pcTDecBinIf->decodeBin( uiBin, baseCtxMod[0] RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(ctype_gt2) ); |
---|
1858 | absCoeff[ firstC2FlagIdx ] = uiBin + 2; |
---|
1859 | if (uiBin != 0) |
---|
1860 | { |
---|
1861 | escapeDataPresentInGroup = true; |
---|
1862 | } |
---|
1863 | } |
---|
1864 | } |
---|
1865 | |
---|
1866 | escapeDataPresentInGroup = escapeDataPresentInGroup || (numNonZero > C1FLAG_NUMBER); |
---|
1867 | |
---|
1868 | const Bool alignGroup = escapeDataPresentInGroup && alignCABACBeforeBypass; |
---|
1869 | |
---|
1870 | #if RExt__DECODER_DEBUG_BIT_STATISTICS |
---|
1871 | TComCodingStatisticsClassType ctype_signs((alignGroup ? STATS__CABAC_BITS__ALIGNED_SIGN_BIT : STATS__CABAC_BITS__SIGN_BIT ), uiLog2BlockWidth, compID); |
---|
1872 | TComCodingStatisticsClassType ctype_escs ((alignGroup ? STATS__CABAC_BITS__ALIGNED_ESCAPE_BITS : STATS__CABAC_BITS__ESCAPE_BITS), uiLog2BlockWidth, compID); |
---|
1873 | #endif |
---|
1874 | |
---|
1875 | if (alignGroup) |
---|
1876 | { |
---|
1877 | m_pcTDecBinIf->align(); |
---|
1878 | } |
---|
1879 | |
---|
1880 | UInt coeffSigns; |
---|
1881 | if ( signHidden && beValid ) |
---|
1882 | { |
---|
1883 | m_pcTDecBinIf->decodeBinsEP( coeffSigns, numNonZero-1 RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(ctype_signs) ); |
---|
1884 | coeffSigns <<= 32 - (numNonZero-1); |
---|
1885 | } |
---|
1886 | else |
---|
1887 | { |
---|
1888 | m_pcTDecBinIf->decodeBinsEP( coeffSigns, numNonZero RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(ctype_signs) ); |
---|
1889 | coeffSigns <<= 32 - numNonZero; |
---|
1890 | } |
---|
1891 | |
---|
1892 | Int iFirstCoeff2 = 1; |
---|
1893 | if (escapeDataPresentInGroup) |
---|
1894 | { |
---|
1895 | for( Int idx = 0; idx < numNonZero; idx++ ) |
---|
1896 | { |
---|
1897 | UInt baseLevel = (idx < C1FLAG_NUMBER)? (2 + iFirstCoeff2) : 1; |
---|
1898 | |
---|
1899 | if( absCoeff[ idx ] == baseLevel) |
---|
1900 | { |
---|
1901 | UInt uiLevel; |
---|
1902 | xReadCoefRemainExGolomb( uiLevel, uiGoRiceParam, extendedPrecision, maxLog2TrDynamicRange RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(ctype_escs) ); |
---|
1903 | |
---|
1904 | absCoeff[ idx ] = uiLevel + baseLevel; |
---|
1905 | |
---|
1906 | if (absCoeff[idx] > (3 << uiGoRiceParam)) |
---|
1907 | { |
---|
1908 | uiGoRiceParam = bUseGolombRiceParameterAdaptation ? (uiGoRiceParam + 1) : (std::min<UInt>((uiGoRiceParam + 1), 4)); |
---|
1909 | } |
---|
1910 | |
---|
1911 | if (updateGolombRiceStatistics) |
---|
1912 | { |
---|
1913 | const UInt initialGolombRiceParameter = currentGolombRiceStatistic / RExt__GOLOMB_RICE_INCREMENT_DIVISOR; |
---|
1914 | |
---|
1915 | if (uiLevel >= (3 << initialGolombRiceParameter)) |
---|
1916 | { |
---|
1917 | currentGolombRiceStatistic++; |
---|
1918 | } |
---|
1919 | else if (((uiLevel * 2) < (1 << initialGolombRiceParameter)) && (currentGolombRiceStatistic > 0)) |
---|
1920 | { |
---|
1921 | currentGolombRiceStatistic--; |
---|
1922 | } |
---|
1923 | |
---|
1924 | updateGolombRiceStatistics = false; |
---|
1925 | } |
---|
1926 | } |
---|
1927 | |
---|
1928 | if(absCoeff[ idx ] >= 2) |
---|
1929 | { |
---|
1930 | iFirstCoeff2 = 0; |
---|
1931 | } |
---|
1932 | } |
---|
1933 | } |
---|
1934 | |
---|
1935 | for( Int idx = 0; idx < numNonZero; idx++ ) |
---|
1936 | { |
---|
1937 | Int blkPos = pos[ idx ]; |
---|
1938 | // Signs applied later. |
---|
1939 | pcCoef[ blkPos ] = absCoeff[ idx ]; |
---|
1940 | absSum += absCoeff[ idx ]; |
---|
1941 | |
---|
1942 | if ( idx == numNonZero-1 && signHidden && beValid ) |
---|
1943 | { |
---|
1944 | // Infer sign of 1st element. |
---|
1945 | if (absSum&0x1) |
---|
1946 | { |
---|
1947 | pcCoef[ blkPos ] = -pcCoef[ blkPos ]; |
---|
1948 | } |
---|
1949 | } |
---|
1950 | else |
---|
1951 | { |
---|
1952 | Int sign = static_cast<Int>( coeffSigns ) >> 31; |
---|
1953 | pcCoef[ blkPos ] = ( pcCoef[ blkPos ] ^ sign ) - sign; |
---|
1954 | coeffSigns <<= 1; |
---|
1955 | } |
---|
1956 | } |
---|
1957 | } |
---|
1958 | } |
---|
1959 | |
---|
1960 | #if ENVIRONMENT_VARIABLE_DEBUG_AND_TEST |
---|
1961 | printSBACCoeffData(uiPosLastX, uiPosLastY, uiWidth, uiHeight, compID, uiAbsPartIdx, codingParameters.scanType, pcCoef); |
---|
1962 | #endif |
---|
1963 | |
---|
1964 | return; |
---|
1965 | } |
---|
1966 | |
---|
1967 | Void TDecSbac::parseSaoMaxUvlc ( UInt& val, UInt maxSymbol ) |
---|
1968 | { |
---|
1969 | if (maxSymbol == 0) |
---|
1970 | { |
---|
1971 | val = 0; |
---|
1972 | return; |
---|
1973 | } |
---|
1974 | |
---|
1975 | UInt code; |
---|
1976 | Int i; |
---|
1977 | m_pcTDecBinIf->decodeBinEP( code RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(STATS__CABAC_BITS__SAO) ); |
---|
1978 | if ( code == 0 ) |
---|
1979 | { |
---|
1980 | val = 0; |
---|
1981 | return; |
---|
1982 | } |
---|
1983 | |
---|
1984 | i=1; |
---|
1985 | while (1) |
---|
1986 | { |
---|
1987 | m_pcTDecBinIf->decodeBinEP( code RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(STATS__CABAC_BITS__SAO) ); |
---|
1988 | if ( code == 0 ) |
---|
1989 | { |
---|
1990 | break; |
---|
1991 | } |
---|
1992 | i++; |
---|
1993 | if (i == maxSymbol) |
---|
1994 | { |
---|
1995 | break; |
---|
1996 | } |
---|
1997 | } |
---|
1998 | |
---|
1999 | val = i; |
---|
2000 | } |
---|
2001 | |
---|
2002 | Void TDecSbac::parseSaoUflc (UInt uiLength, UInt& riVal) |
---|
2003 | { |
---|
2004 | m_pcTDecBinIf->decodeBinsEP ( riVal, uiLength RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(STATS__CABAC_BITS__SAO) ); |
---|
2005 | } |
---|
2006 | |
---|
2007 | Void TDecSbac::parseSaoMerge (UInt& ruiVal) |
---|
2008 | { |
---|
2009 | UInt uiCode; |
---|
2010 | m_pcTDecBinIf->decodeBin( uiCode, m_cSaoMergeSCModel.get( 0, 0, 0 ) RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(STATS__CABAC_BITS__SAO) ); |
---|
2011 | ruiVal = (Int)uiCode; |
---|
2012 | } |
---|
2013 | |
---|
2014 | Void TDecSbac::parseSaoTypeIdx (UInt& ruiVal) |
---|
2015 | { |
---|
2016 | UInt uiCode; |
---|
2017 | m_pcTDecBinIf->decodeBin( uiCode, m_cSaoTypeIdxSCModel.get( 0, 0, 0 ) RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(STATS__CABAC_BITS__SAO) ); |
---|
2018 | if (uiCode == 0) |
---|
2019 | { |
---|
2020 | ruiVal = 0; |
---|
2021 | } |
---|
2022 | else |
---|
2023 | { |
---|
2024 | m_pcTDecBinIf->decodeBinEP( uiCode RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(STATS__CABAC_BITS__SAO) ); |
---|
2025 | if (uiCode == 0) |
---|
2026 | { |
---|
2027 | ruiVal = 1; |
---|
2028 | } |
---|
2029 | else |
---|
2030 | { |
---|
2031 | ruiVal = 2; |
---|
2032 | } |
---|
2033 | } |
---|
2034 | } |
---|
2035 | |
---|
2036 | Void TDecSbac::parseSaoSign(UInt& val) |
---|
2037 | { |
---|
2038 | m_pcTDecBinIf->decodeBinEP ( val RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(STATS__CABAC_BITS__SAO) ); |
---|
2039 | } |
---|
2040 | |
---|
2041 | Void TDecSbac::parseSAOBlkParam (SAOBlkParam& saoBlkParam |
---|
2042 | , Bool* sliceEnabled |
---|
2043 | , Bool leftMergeAvail |
---|
2044 | , Bool aboveMergeAvail |
---|
2045 | , const BitDepths &bitDepths |
---|
2046 | ) |
---|
2047 | { |
---|
2048 | UInt uiSymbol; |
---|
2049 | |
---|
2050 | Bool isLeftMerge = false; |
---|
2051 | Bool isAboveMerge= false; |
---|
2052 | |
---|
2053 | if(leftMergeAvail) |
---|
2054 | { |
---|
2055 | parseSaoMerge(uiSymbol); //sao_merge_left_flag |
---|
2056 | isLeftMerge = (uiSymbol?true:false); |
---|
2057 | } |
---|
2058 | |
---|
2059 | if( aboveMergeAvail && !isLeftMerge) |
---|
2060 | { |
---|
2061 | parseSaoMerge(uiSymbol); //sao_merge_up_flag |
---|
2062 | isAboveMerge = (uiSymbol?true:false); |
---|
2063 | } |
---|
2064 | |
---|
2065 | if(isLeftMerge || isAboveMerge) //merge mode |
---|
2066 | { |
---|
2067 | for (UInt componentIndex = 0; componentIndex < MAX_NUM_COMPONENT; componentIndex++) |
---|
2068 | { |
---|
2069 | saoBlkParam[componentIndex].modeIdc = (sliceEnabled[componentIndex]) ? SAO_MODE_MERGE : SAO_MODE_OFF; |
---|
2070 | saoBlkParam[componentIndex].typeIdc = (isLeftMerge)?SAO_MERGE_LEFT:SAO_MERGE_ABOVE; |
---|
2071 | } |
---|
2072 | } |
---|
2073 | else //new or off mode |
---|
2074 | { |
---|
2075 | for(Int compId=COMPONENT_Y; compId < MAX_NUM_COMPONENT; compId++) |
---|
2076 | { |
---|
2077 | const ComponentID compIdx=ComponentID(compId); |
---|
2078 | const ComponentID firstCompOfChType = getFirstComponentOfChannel(toChannelType(compIdx)); |
---|
2079 | SAOOffset& ctbParam = saoBlkParam[compIdx]; |
---|
2080 | #if O0043_BEST_EFFORT_DECODING |
---|
2081 | const Int bitDepthOrig = bitDepths.stream[toChannelType(compIdx)]; |
---|
2082 | const Int forceBitDepthAdjust = bitDepthOrig - bitDepths.recon[toChannelType(compIdx)]; |
---|
2083 | #else |
---|
2084 | const Int bitDepthOrig = bitDepths.recon[toChannelType(compIdx)]; |
---|
2085 | #endif |
---|
2086 | const Int maxOffsetQVal=TComSampleAdaptiveOffset::getMaxOffsetQVal(bitDepthOrig); |
---|
2087 | if(!sliceEnabled[compIdx]) |
---|
2088 | { |
---|
2089 | //off |
---|
2090 | ctbParam.modeIdc = SAO_MODE_OFF; |
---|
2091 | continue; |
---|
2092 | } |
---|
2093 | |
---|
2094 | //type |
---|
2095 | if(compIdx == firstCompOfChType) |
---|
2096 | { |
---|
2097 | parseSaoTypeIdx(uiSymbol); //sao_type_idx_luma or sao_type_idx_chroma |
---|
2098 | |
---|
2099 | assert(uiSymbol ==0 || uiSymbol ==1 || uiSymbol ==2); |
---|
2100 | |
---|
2101 | if(uiSymbol ==0) //OFF |
---|
2102 | { |
---|
2103 | ctbParam.modeIdc = SAO_MODE_OFF; |
---|
2104 | } |
---|
2105 | else if(uiSymbol == 1) //BO |
---|
2106 | { |
---|
2107 | ctbParam.modeIdc = SAO_MODE_NEW; |
---|
2108 | ctbParam.typeIdc = SAO_TYPE_START_BO; |
---|
2109 | } |
---|
2110 | else //2, EO |
---|
2111 | { |
---|
2112 | ctbParam.modeIdc = SAO_MODE_NEW; |
---|
2113 | ctbParam.typeIdc = SAO_TYPE_START_EO; |
---|
2114 | } |
---|
2115 | |
---|
2116 | } |
---|
2117 | else //Cr, follow Cb SAO type |
---|
2118 | { |
---|
2119 | ctbParam.modeIdc = saoBlkParam[COMPONENT_Cb].modeIdc; |
---|
2120 | ctbParam.typeIdc = saoBlkParam[COMPONENT_Cb].typeIdc; |
---|
2121 | } |
---|
2122 | |
---|
2123 | if(ctbParam.modeIdc == SAO_MODE_NEW) |
---|
2124 | { |
---|
2125 | Int offset[4]; |
---|
2126 | for(Int i=0; i< 4; i++) |
---|
2127 | { |
---|
2128 | parseSaoMaxUvlc(uiSymbol, maxOffsetQVal ); //sao_offset_abs |
---|
2129 | offset[i] = (Int)uiSymbol; |
---|
2130 | } |
---|
2131 | |
---|
2132 | if(ctbParam.typeIdc == SAO_TYPE_START_BO) |
---|
2133 | { |
---|
2134 | for(Int i=0; i< 4; i++) |
---|
2135 | { |
---|
2136 | if(offset[i] != 0) |
---|
2137 | { |
---|
2138 | parseSaoSign(uiSymbol); //sao_offset_sign |
---|
2139 | if(uiSymbol) |
---|
2140 | { |
---|
2141 | #if O0043_BEST_EFFORT_DECODING |
---|
2142 | offset[i] >>= forceBitDepthAdjust; |
---|
2143 | #endif |
---|
2144 | offset[i] = -offset[i]; |
---|
2145 | } |
---|
2146 | } |
---|
2147 | } |
---|
2148 | parseSaoUflc(NUM_SAO_BO_CLASSES_LOG2, uiSymbol ); //sao_band_position |
---|
2149 | ctbParam.typeAuxInfo = uiSymbol; |
---|
2150 | |
---|
2151 | for(Int i=0; i<4; i++) |
---|
2152 | { |
---|
2153 | ctbParam.offset[(ctbParam.typeAuxInfo+i)%MAX_NUM_SAO_CLASSES] = offset[i]; |
---|
2154 | } |
---|
2155 | |
---|
2156 | } |
---|
2157 | else //EO |
---|
2158 | { |
---|
2159 | ctbParam.typeAuxInfo = 0; |
---|
2160 | |
---|
2161 | if(firstCompOfChType == compIdx) |
---|
2162 | { |
---|
2163 | parseSaoUflc(NUM_SAO_EO_TYPES_LOG2, uiSymbol ); //sao_eo_class_luma or sao_eo_class_chroma |
---|
2164 | ctbParam.typeIdc += uiSymbol; |
---|
2165 | } |
---|
2166 | else |
---|
2167 | { |
---|
2168 | ctbParam.typeIdc = saoBlkParam[firstCompOfChType].typeIdc; |
---|
2169 | } |
---|
2170 | ctbParam.offset[SAO_CLASS_EO_FULL_VALLEY] = offset[0]; |
---|
2171 | ctbParam.offset[SAO_CLASS_EO_HALF_VALLEY] = offset[1]; |
---|
2172 | ctbParam.offset[SAO_CLASS_EO_PLAIN ] = 0; |
---|
2173 | ctbParam.offset[SAO_CLASS_EO_HALF_PEAK ] = -offset[2]; |
---|
2174 | ctbParam.offset[SAO_CLASS_EO_FULL_PEAK ] = -offset[3]; |
---|
2175 | } |
---|
2176 | } |
---|
2177 | } |
---|
2178 | } |
---|
2179 | } |
---|
2180 | |
---|
2181 | /** |
---|
2182 | - Initialize our contexts from the nominated source. |
---|
2183 | . |
---|
2184 | \param pSrc Contexts to be copied. |
---|
2185 | */ |
---|
2186 | Void TDecSbac::xCopyContextsFrom( const TDecSbac* pSrc ) |
---|
2187 | { |
---|
2188 | memcpy(m_contextModels, pSrc->m_contextModels, m_numContextModels*sizeof(m_contextModels[0])); |
---|
2189 | memcpy(m_golombRiceAdaptationStatistics, pSrc->m_golombRiceAdaptationStatistics, (sizeof(UInt) * RExt__GOLOMB_RICE_ADAPTATION_STATISTICS_SETS)); |
---|
2190 | } |
---|
2191 | |
---|
2192 | Void TDecSbac::xCopyFrom( const TDecSbac* pSrc ) |
---|
2193 | { |
---|
2194 | m_pcTDecBinIf->copyState( pSrc->m_pcTDecBinIf ); |
---|
2195 | xCopyContextsFrom( pSrc ); |
---|
2196 | } |
---|
2197 | |
---|
2198 | Void TDecSbac::load ( const TDecSbac* pSrc ) |
---|
2199 | { |
---|
2200 | xCopyFrom(pSrc); |
---|
2201 | } |
---|
2202 | |
---|
2203 | Void TDecSbac::loadContexts ( const TDecSbac* pSrc ) |
---|
2204 | { |
---|
2205 | xCopyContextsFrom(pSrc); |
---|
2206 | } |
---|
2207 | |
---|
2208 | /** Performs CABAC decoding of the explicit RDPCM mode |
---|
2209 | * \param rTu current TU data structure |
---|
2210 | * \param compID component identifier |
---|
2211 | */ |
---|
2212 | Void TDecSbac::parseExplicitRdpcmMode( TComTU &rTu, ComponentID compID ) |
---|
2213 | { |
---|
2214 | TComDataCU* cu = rTu.getCU(); |
---|
2215 | const UInt absPartIdx=rTu.GetAbsPartIdxTU(compID); |
---|
2216 | const TComRectangle &rect = rTu.getRect(compID); |
---|
2217 | const UInt tuHeight = g_aucConvertToBit[rect.height]; |
---|
2218 | const UInt tuWidth = g_aucConvertToBit[rect.width]; |
---|
2219 | UInt code = 0; |
---|
2220 | |
---|
2221 | assert(tuHeight == tuWidth); |
---|
2222 | |
---|
2223 | #if RExt__DECODER_DEBUG_BIT_STATISTICS |
---|
2224 | const TComCodingStatisticsClassType ctype(STATS__EXPLICIT_RDPCM_BITS, g_aucConvertToBit[cu->getSlice()->getSPS()->getMaxCUWidth()>>rTu.GetTransformDepthTotal()]+2); |
---|
2225 | #endif |
---|
2226 | |
---|
2227 | m_pcTDecBinIf->decodeBin(code, m_explicitRdpcmFlagSCModel.get (0, toChannelType(compID), 0) RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(ctype)); |
---|
2228 | |
---|
2229 | if(code == 0) |
---|
2230 | { |
---|
2231 | cu->setExplicitRdpcmModePartRange( RDPCM_OFF, compID, absPartIdx, rTu.GetAbsPartIdxNumParts(compID)); |
---|
2232 | } |
---|
2233 | else |
---|
2234 | { |
---|
2235 | m_pcTDecBinIf->decodeBin(code, m_explicitRdpcmDirSCModel.get (0, toChannelType(compID), 0) RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(ctype)); |
---|
2236 | if(code == 0) |
---|
2237 | { |
---|
2238 | cu->setExplicitRdpcmModePartRange( RDPCM_HOR, compID, absPartIdx, rTu.GetAbsPartIdxNumParts(compID)); |
---|
2239 | } |
---|
2240 | else |
---|
2241 | { |
---|
2242 | cu->setExplicitRdpcmModePartRange( RDPCM_VER, compID, absPartIdx, rTu.GetAbsPartIdxNumParts(compID)); |
---|
2243 | } |
---|
2244 | } |
---|
2245 | } |
---|
2246 | |
---|
2247 | #if NH_3D |
---|
2248 | Void TDecSbac::parseARPW( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth ) |
---|
2249 | { |
---|
2250 | UInt uiW = 0; |
---|
2251 | UInt uiOffset = pcCU->getCTXARPWFlag(uiAbsPartIdx); |
---|
2252 | UInt uiCode = 0; |
---|
2253 | |
---|
2254 | m_pcTDecBinIf->decodeBin( uiCode , m_cCUPUARPWSCModel.get( 0, 0, 0 + uiOffset ) RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(STATS__CABAC_BITS__ARP_FLAG)); |
---|
2255 | |
---|
2256 | uiW = uiCode; |
---|
2257 | if( 1 == uiW ) |
---|
2258 | { |
---|
2259 | m_pcTDecBinIf->decodeBin( uiCode , m_cCUPUARPWSCModel.get( 0, 0, 2 ) RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(STATS__CABAC_BITS__ARP_FLAG)); |
---|
2260 | uiW += ( 1 == uiCode ? 1 : 0 ); |
---|
2261 | } |
---|
2262 | #if NH_MV_ENC_DEC_TRAC |
---|
2263 | DTRACE_CU("iv_res_pred_weight_idx", uiW ) |
---|
2264 | #endif |
---|
2265 | pcCU->setARPWSubParts( ( UChar )( uiW ) , uiAbsPartIdx, uiDepth ); |
---|
2266 | } |
---|
2267 | |
---|
2268 | /** parse illumination compensation flag |
---|
2269 | * \param pcCU |
---|
2270 | * \param uiAbsPartIdx |
---|
2271 | * \param uiDepth |
---|
2272 | * \returns Void |
---|
2273 | */ |
---|
2274 | Void TDecSbac::parseICFlag( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth ) |
---|
2275 | { |
---|
2276 | UInt uiSymbol = 0; |
---|
2277 | m_pcTDecBinIf->decodeBin( uiSymbol, m_cCUICFlagSCModel.get( 0, 0, 0 ) RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(STATS__CABAC_BITS__3D_IC) ); |
---|
2278 | |
---|
2279 | #if !NH_MV_ENC_DEC_TRAC |
---|
2280 | DTRACE_CABAC_VL( g_nSymbolCounter++ ); |
---|
2281 | DTRACE_CABAC_T( "\tICFlag" ); |
---|
2282 | DTRACE_CABAC_T( "\tuiCtxIC: "); |
---|
2283 | DTRACE_CABAC_V( uiCtxIC ); |
---|
2284 | DTRACE_CABAC_T( "\tuiSymbol: "); |
---|
2285 | DTRACE_CABAC_V( uiSymbol ); |
---|
2286 | DTRACE_CABAC_T( "\n"); |
---|
2287 | #else |
---|
2288 | DTRACE_CU("ic_flag", uiSymbol) |
---|
2289 | #endif |
---|
2290 | |
---|
2291 | pcCU->setICFlagSubParts( uiSymbol ? true : false , uiAbsPartIdx, 0, uiDepth ); |
---|
2292 | } |
---|
2293 | |
---|
2294 | Void TDecSbac::parseDeltaDC( TComDataCU* pcCU, UInt absPartIdx, UInt depth ) |
---|
2295 | { |
---|
2296 | if( !(pcCU->getSDCFlag( absPartIdx )) ) |
---|
2297 | if( !(pcCU->isIntra( absPartIdx ) && isDmmMode( pcCU->getIntraDir( CHANNEL_TYPE_LUMA, absPartIdx ) )) ) |
---|
2298 | assert( 0 ); |
---|
2299 | |
---|
2300 | UInt symbol = 1; |
---|
2301 | if( pcCU->isIntra( absPartIdx ) && pcCU->getSDCFlag( absPartIdx )) |
---|
2302 | { |
---|
2303 | m_pcTDecBinIf->decodeBin( symbol, m_cDdcFlagSCModel.get( 0, 0, 0 ) RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(STATS__CABAC_BITS__SDC_DELTADC_FLAG) ); |
---|
2304 | assert( pcCU->getPartitionSize( absPartIdx ) == SIZE_2Nx2N ); |
---|
2305 | assert( pcCU->getTransformIdx(absPartIdx) == 0 ); |
---|
2306 | assert( pcCU->getCbf(absPartIdx, COMPONENT_Y) == 1 ); |
---|
2307 | } |
---|
2308 | UInt uiNumSegments = isDmmMode( pcCU->getIntraDir( CHANNEL_TYPE_LUMA, absPartIdx ) ) ? 2 : 1; |
---|
2309 | |
---|
2310 | for( UInt segment = 0; segment < uiNumSegments; segment++ ) |
---|
2311 | { |
---|
2312 | Pel valDeltaDC = 0; |
---|
2313 | if( symbol ) |
---|
2314 | { |
---|
2315 | xParseDeltaDC( valDeltaDC, uiNumSegments ); |
---|
2316 | } |
---|
2317 | |
---|
2318 | if( pcCU->isIntra( absPartIdx ) ) |
---|
2319 | { |
---|
2320 | if( pcCU->getSDCFlag( absPartIdx ) ) |
---|
2321 | { |
---|
2322 | pcCU->setSDCSegmentDCOffset( valDeltaDC, segment, absPartIdx ); |
---|
2323 | } |
---|
2324 | else |
---|
2325 | { |
---|
2326 | pcCU->setDmmDeltaDC( getDmmType( pcCU->getIntraDir( CHANNEL_TYPE_LUMA, absPartIdx ) ), segment, absPartIdx, valDeltaDC ); |
---|
2327 | } |
---|
2328 | } |
---|
2329 | else |
---|
2330 | { |
---|
2331 | pcCU->setSDCSegmentDCOffset( valDeltaDC, segment, absPartIdx ); |
---|
2332 | } |
---|
2333 | } |
---|
2334 | } |
---|
2335 | |
---|
2336 | Void TDecSbac::xParseDeltaDC( Pel& rValDeltaDC, UInt uiNumSeg ) |
---|
2337 | { |
---|
2338 | UInt absValDeltaDC = 0; |
---|
2339 | xReadExGolombLevelDdc( absValDeltaDC ); |
---|
2340 | rValDeltaDC = (Pel)absValDeltaDC + ( uiNumSeg > 1 ? 0 : 1 ); |
---|
2341 | |
---|
2342 | if( rValDeltaDC != 0 ) |
---|
2343 | { |
---|
2344 | UInt uiSign; |
---|
2345 | m_pcTDecBinIf->decodeBinEP( uiSign RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(STATS__CABAC_BITS__DELTADC_SIGN_EP) ); |
---|
2346 | if ( uiSign ) |
---|
2347 | { |
---|
2348 | rValDeltaDC = -rValDeltaDC; |
---|
2349 | } |
---|
2350 | } |
---|
2351 | #if NH_MV_ENC_DEC_TRAC |
---|
2352 | DTRACE_CU("delta_dc", rValDeltaDC); |
---|
2353 | #endif |
---|
2354 | } |
---|
2355 | |
---|
2356 | Void TDecSbac::xReadExGolombLevelDdc( UInt& ruiSymbol ) |
---|
2357 | { |
---|
2358 | UInt uiSymbol; |
---|
2359 | UInt uiCount = 0; |
---|
2360 | do |
---|
2361 | { |
---|
2362 | m_pcTDecBinIf->decodeBin( uiSymbol, m_cDdcDataSCModel.get(0, 0, 0) RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(STATS__CABAC_BITS__DELTADC_PREFIX) ); |
---|
2363 | uiCount++; |
---|
2364 | } |
---|
2365 | while( uiSymbol && ( uiCount != 3 ) ); |
---|
2366 | ruiSymbol = uiCount - 1; |
---|
2367 | |
---|
2368 | if( uiSymbol ) |
---|
2369 | { |
---|
2370 | xReadEpExGolomb( uiSymbol, 0 RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(STATS__CABAC_BITS__DELTADC_SUFFIX_EP) ); |
---|
2371 | ruiSymbol += uiSymbol + 1; |
---|
2372 | } |
---|
2373 | |
---|
2374 | return; |
---|
2375 | } |
---|
2376 | |
---|
2377 | Void TDecSbac::xParseIntraDepthMode( TComDataCU* pcCU, UInt absPartIdx, UInt depth ) |
---|
2378 | { |
---|
2379 | pcCU->setIntraDirSubParts( CHANNEL_TYPE_LUMA, 0, absPartIdx, depth ); |
---|
2380 | |
---|
2381 | UInt uiSymbol; |
---|
2382 | if( ( pcCU->getSlice()->getSPS()->getMaxCUWidth() >> pcCU->getDepth( absPartIdx ) ) < 64 ) //DMM and HEVC intra modes are both allowed |
---|
2383 | { |
---|
2384 | m_pcTDecBinIf->decodeBin( uiSymbol, m_cNotDmmFlagSCModel.get( 0, 0, 0 ) RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(STATS__CABAC_BITS__NOTDMM_FLAG) ); |
---|
2385 | } |
---|
2386 | else |
---|
2387 | { |
---|
2388 | uiSymbol = 1; |
---|
2389 | } |
---|
2390 | |
---|
2391 | //decode DMM mode index |
---|
2392 | if( !uiSymbol ) |
---|
2393 | { |
---|
2394 | if( pcCU->getSlice()->getIntraSdcWedgeFlag() && pcCU->getSlice()->getIntraContourFlag() ) |
---|
2395 | { |
---|
2396 | m_pcTDecBinIf->decodeBin( uiSymbol, m_cDmmModeSCModel.get( 0, 0, 0 ) RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(STATS__CABAC_BITS__DMMMODE) ); |
---|
2397 | if( !uiSymbol ) |
---|
2398 | { |
---|
2399 | pcCU->setIntraDirSubParts( CHANNEL_TYPE_LUMA, DMM_OFFSET, absPartIdx, depth ); |
---|
2400 | } |
---|
2401 | else |
---|
2402 | { |
---|
2403 | pcCU->setIntraDirSubParts( CHANNEL_TYPE_LUMA, ( 1+ DMM_OFFSET ), absPartIdx, depth ); |
---|
2404 | } |
---|
2405 | } |
---|
2406 | else if( pcCU->getSlice()->getIntraSdcWedgeFlag() ) |
---|
2407 | { |
---|
2408 | pcCU->setIntraDirSubParts( CHANNEL_TYPE_LUMA, DMM_OFFSET, absPartIdx, depth ); |
---|
2409 | } |
---|
2410 | else if( pcCU->getSlice()->getIntraContourFlag() ) |
---|
2411 | { |
---|
2412 | pcCU->setIntraDirSubParts( CHANNEL_TYPE_LUMA, ( 1+ DMM_OFFSET ), absPartIdx, depth ); |
---|
2413 | } |
---|
2414 | } |
---|
2415 | } |
---|
2416 | |
---|
2417 | Void TDecSbac::xParseDmmData( TComDataCU* pcCU, UInt absPartIdx, UInt depth ) |
---|
2418 | { |
---|
2419 | UInt dir = pcCU->getIntraDir( CHANNEL_TYPE_LUMA, absPartIdx ); |
---|
2420 | switch( getDmmType( dir ) ) |
---|
2421 | { |
---|
2422 | case( DMM1_IDX ): |
---|
2423 | { |
---|
2424 | UInt uiTabIdx = 0; |
---|
2425 | xParseDmm1WedgeIdx( uiTabIdx, g_dmm1TabIdxBits[pcCU->getIntraSizeIdx(absPartIdx)] ); |
---|
2426 | assert( uiTabIdx < getWedgeListScaled( pcCU->getWidth( absPartIdx ) )->size() ); |
---|
2427 | pcCU->setDmm1WedgeTabIdxSubParts( uiTabIdx, absPartIdx, depth ); |
---|
2428 | } break; |
---|
2429 | case( DMM4_IDX ): break; |
---|
2430 | default: break; |
---|
2431 | } |
---|
2432 | } |
---|
2433 | |
---|
2434 | Void TDecSbac::xParseDmm1WedgeIdx( UInt& ruiTabIdx, Int iNumBit ) |
---|
2435 | { |
---|
2436 | UInt uiSymbol, uiIdx = 0; |
---|
2437 | for( Int i = 0; i < iNumBit; i++ ) |
---|
2438 | { |
---|
2439 | m_pcTDecBinIf->decodeBinEP( uiSymbol RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(STATS__CABAC_BITS__DMM1_BITS_EP) ); |
---|
2440 | uiIdx += uiSymbol << i; |
---|
2441 | } |
---|
2442 | ruiTabIdx = uiIdx; |
---|
2443 | } |
---|
2444 | |
---|
2445 | Void TDecSbac::parseSDCFlag( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth ) |
---|
2446 | { |
---|
2447 | UInt uiSymbol = 0; |
---|
2448 | |
---|
2449 | m_pcTDecBinIf->decodeBin( uiSymbol, m_cSDCFlagSCModel.get( 0, 0, 0 ) RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(STATS__CABAC_BITS__SDC_INTRA_FLAG) ); |
---|
2450 | #if NH_MV_ENC_DEC_TRAC |
---|
2451 | DTRACE_CU("dc_only_flag", uiSymbol) |
---|
2452 | #endif |
---|
2453 | if( uiSymbol ) |
---|
2454 | { |
---|
2455 | pcCU->setSDCFlagSubParts( true, uiAbsPartIdx, uiDepth ); |
---|
2456 | pcCU->setTrIdxSubParts( 0, uiAbsPartIdx, uiDepth ); |
---|
2457 | pcCU->setCbfSubParts(1, COMPONENT_Y, uiAbsPartIdx, uiDepth); |
---|
2458 | } |
---|
2459 | else |
---|
2460 | { |
---|
2461 | pcCU->setSDCFlagSubParts( false, uiAbsPartIdx, uiDepth ); |
---|
2462 | } |
---|
2463 | } |
---|
2464 | |
---|
2465 | Void TDecSbac::parseDBBPFlag( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth ) |
---|
2466 | { |
---|
2467 | AOF( pcCU->getSlice()->getDepthBasedBlkPartFlag() ); |
---|
2468 | AOF( !pcCU->getSlice()->getIsDepth() ); |
---|
2469 | |
---|
2470 | UInt uiSymbol = 0; |
---|
2471 | |
---|
2472 | m_pcTDecBinIf->decodeBin( uiSymbol, m_cDBBPFlagSCModel.get( 0, 0, 0 ) RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(STATS__CABAC_BITS__DBBP_FLAG) ); |
---|
2473 | DTRACE_CU("dbbp_flag", uiSymbol) |
---|
2474 | PartSize ePartSize = pcCU->getPartitionSize( uiAbsPartIdx ); |
---|
2475 | AOF( ePartSize == SIZE_2NxN || ePartSize == SIZE_Nx2N ); |
---|
2476 | UInt uiPUOffset = ( g_auiPUOffset[UInt( ePartSize )] << ( ( pcCU->getSlice()->getSPS()->getMaxTotalCUDepth() - uiDepth ) << 1 ) ) >> 4; |
---|
2477 | pcCU->setDBBPFlagSubParts(uiSymbol, uiAbsPartIdx, 0, uiDepth); |
---|
2478 | pcCU->setDBBPFlagSubParts(uiSymbol, uiAbsPartIdx+uiPUOffset, 1, uiDepth); |
---|
2479 | } |
---|
2480 | #endif |
---|
2481 | |
---|
2482 | |
---|
2483 | //! \} |
---|