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