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