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