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-2013, 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 | |
---|
40 | //! \ingroup TLibDecoder |
---|
41 | //! \{ |
---|
42 | |
---|
43 | ////////////////////////////////////////////////////////////////////// |
---|
44 | // Construction/Destruction |
---|
45 | ////////////////////////////////////////////////////////////////////// |
---|
46 | |
---|
47 | TDecSbac::TDecSbac() |
---|
48 | // new structure here |
---|
49 | : m_pcBitstream ( 0 ) |
---|
50 | , m_pcTDecBinIf ( NULL ) |
---|
51 | , m_numContextModels ( 0 ) |
---|
52 | , m_cCUSplitFlagSCModel ( 1, 1, NUM_SPLIT_FLAG_CTX , m_contextModels + m_numContextModels, m_numContextModels ) |
---|
53 | , m_cCUSkipFlagSCModel ( 1, 1, NUM_SKIP_FLAG_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
54 | , m_cCUMergeFlagExtSCModel ( 1, 1, NUM_MERGE_FLAG_EXT_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
55 | , m_cCUMergeIdxExtSCModel ( 1, 1, NUM_MERGE_IDX_EXT_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
56 | , m_cCUPartSizeSCModel ( 1, 1, NUM_PART_SIZE_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
57 | , m_cCUPredModeSCModel ( 1, 1, NUM_PRED_MODE_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
58 | , m_cCUIntraPredSCModel ( 1, 1, NUM_ADI_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
59 | , m_cCUChromaPredSCModel ( 1, 1, NUM_CHROMA_PRED_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
60 | , m_cCUDeltaQpSCModel ( 1, 1, NUM_DELTA_QP_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
61 | , m_cCUInterDirSCModel ( 1, 1, NUM_INTER_DIR_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
62 | , m_cCURefPicSCModel ( 1, 1, NUM_REF_NO_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
63 | , m_cCUMvdSCModel ( 1, 1, NUM_MV_RES_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
64 | , m_cCUQtCbfSCModel ( 1, 2, NUM_QT_CBF_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
65 | , m_cCUTransSubdivFlagSCModel ( 1, 1, NUM_TRANS_SUBDIV_FLAG_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
66 | , m_cCUQtRootCbfSCModel ( 1, 1, NUM_QT_ROOT_CBF_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
67 | , m_cCUSigCoeffGroupSCModel ( 1, 2, NUM_SIG_CG_FLAG_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
68 | , m_cCUSigSCModel ( 1, 1, NUM_SIG_FLAG_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
69 | , m_cCuCtxLastX ( 1, 2, NUM_CTX_LAST_FLAG_XY , m_contextModels + m_numContextModels, m_numContextModels) |
---|
70 | , m_cCuCtxLastY ( 1, 2, NUM_CTX_LAST_FLAG_XY , m_contextModels + m_numContextModels, m_numContextModels) |
---|
71 | , m_cCUOneSCModel ( 1, 1, NUM_ONE_FLAG_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
72 | , m_cCUAbsSCModel ( 1, 1, NUM_ABS_FLAG_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
73 | , m_cMVPIdxSCModel ( 1, 1, NUM_MVP_IDX_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
74 | , m_cCUAMPSCModel ( 1, 1, NUM_CU_AMP_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
75 | , m_cSaoMergeSCModel ( 1, 1, NUM_SAO_MERGE_FLAG_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
76 | , m_cSaoTypeIdxSCModel ( 1, 1, NUM_SAO_TYPE_IDX_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
77 | , m_cTransformSkipSCModel ( 1, 2, NUM_TRANSFORMSKIP_FLAG_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
78 | , m_CUTransquantBypassFlagSCModel( 1, 1, NUM_CU_TRANSQUANT_BYPASS_FLAG_CTX, m_contextModels + m_numContextModels, m_numContextModels) |
---|
79 | { |
---|
80 | assert( m_numContextModels <= MAX_NUM_CTX_MOD ); |
---|
81 | } |
---|
82 | |
---|
83 | TDecSbac::~TDecSbac() |
---|
84 | { |
---|
85 | } |
---|
86 | |
---|
87 | // ==================================================================================================================== |
---|
88 | // Public member functions |
---|
89 | // ==================================================================================================================== |
---|
90 | |
---|
91 | Void TDecSbac::resetEntropy(TComSlice* pSlice) |
---|
92 | { |
---|
93 | SliceType sliceType = pSlice->getSliceType(); |
---|
94 | Int qp = pSlice->getSliceQp(); |
---|
95 | |
---|
96 | if (pSlice->getPPS()->getCabacInitPresentFlag() && pSlice->getCabacInitFlag()) |
---|
97 | { |
---|
98 | switch (sliceType) |
---|
99 | { |
---|
100 | case P_SLICE: // change initialization table to B_SLICE initialization |
---|
101 | sliceType = B_SLICE; |
---|
102 | break; |
---|
103 | case B_SLICE: // change initialization table to P_SLICE initialization |
---|
104 | sliceType = P_SLICE; |
---|
105 | break; |
---|
106 | default : // should not occur |
---|
107 | assert(0); |
---|
108 | } |
---|
109 | } |
---|
110 | |
---|
111 | m_cCUSplitFlagSCModel.initBuffer ( sliceType, qp, (UChar*)INIT_SPLIT_FLAG ); |
---|
112 | m_cCUSkipFlagSCModel.initBuffer ( sliceType, qp, (UChar*)INIT_SKIP_FLAG ); |
---|
113 | m_cCUMergeFlagExtSCModel.initBuffer ( sliceType, qp, (UChar*)INIT_MERGE_FLAG_EXT ); |
---|
114 | m_cCUMergeIdxExtSCModel.initBuffer ( sliceType, qp, (UChar*)INIT_MERGE_IDX_EXT ); |
---|
115 | m_cCUPartSizeSCModel.initBuffer ( sliceType, qp, (UChar*)INIT_PART_SIZE ); |
---|
116 | m_cCUAMPSCModel.initBuffer ( sliceType, qp, (UChar*)INIT_CU_AMP_POS ); |
---|
117 | m_cCUPredModeSCModel.initBuffer ( sliceType, qp, (UChar*)INIT_PRED_MODE ); |
---|
118 | m_cCUIntraPredSCModel.initBuffer ( sliceType, qp, (UChar*)INIT_INTRA_PRED_MODE ); |
---|
119 | m_cCUChromaPredSCModel.initBuffer ( sliceType, qp, (UChar*)INIT_CHROMA_PRED_MODE ); |
---|
120 | m_cCUInterDirSCModel.initBuffer ( sliceType, qp, (UChar*)INIT_INTER_DIR ); |
---|
121 | m_cCUMvdSCModel.initBuffer ( sliceType, qp, (UChar*)INIT_MVD ); |
---|
122 | m_cCURefPicSCModel.initBuffer ( sliceType, qp, (UChar*)INIT_REF_PIC ); |
---|
123 | m_cCUDeltaQpSCModel.initBuffer ( sliceType, qp, (UChar*)INIT_DQP ); |
---|
124 | m_cCUQtCbfSCModel.initBuffer ( sliceType, qp, (UChar*)INIT_QT_CBF ); |
---|
125 | m_cCUQtRootCbfSCModel.initBuffer ( sliceType, qp, (UChar*)INIT_QT_ROOT_CBF ); |
---|
126 | m_cCUSigCoeffGroupSCModel.initBuffer ( sliceType, qp, (UChar*)INIT_SIG_CG_FLAG ); |
---|
127 | m_cCUSigSCModel.initBuffer ( sliceType, qp, (UChar*)INIT_SIG_FLAG ); |
---|
128 | m_cCuCtxLastX.initBuffer ( sliceType, qp, (UChar*)INIT_LAST ); |
---|
129 | m_cCuCtxLastY.initBuffer ( sliceType, qp, (UChar*)INIT_LAST ); |
---|
130 | m_cCUOneSCModel.initBuffer ( sliceType, qp, (UChar*)INIT_ONE_FLAG ); |
---|
131 | m_cCUAbsSCModel.initBuffer ( sliceType, qp, (UChar*)INIT_ABS_FLAG ); |
---|
132 | m_cMVPIdxSCModel.initBuffer ( sliceType, qp, (UChar*)INIT_MVP_IDX ); |
---|
133 | m_cSaoMergeSCModel.initBuffer ( sliceType, qp, (UChar*)INIT_SAO_MERGE_FLAG ); |
---|
134 | m_cSaoTypeIdxSCModel.initBuffer ( sliceType, qp, (UChar*)INIT_SAO_TYPE_IDX ); |
---|
135 | |
---|
136 | m_cCUTransSubdivFlagSCModel.initBuffer ( sliceType, qp, (UChar*)INIT_TRANS_SUBDIV_FLAG ); |
---|
137 | m_cTransformSkipSCModel.initBuffer ( sliceType, qp, (UChar*)INIT_TRANSFORMSKIP_FLAG ); |
---|
138 | m_CUTransquantBypassFlagSCModel.initBuffer( sliceType, qp, (UChar*)INIT_CU_TRANSQUANT_BYPASS_FLAG ); |
---|
139 | m_uiLastDQpNonZero = 0; |
---|
140 | |
---|
141 | // new structure |
---|
142 | m_uiLastQp = qp; |
---|
143 | |
---|
144 | m_pcTDecBinIf->start(); |
---|
145 | } |
---|
146 | |
---|
147 | /** The function does the following: Read out terminate bit. Flush CABAC. Byte-align for next tile. |
---|
148 | * Intialize CABAC states. Start CABAC. |
---|
149 | */ |
---|
150 | Void TDecSbac::updateContextTables( SliceType eSliceType, Int iQp ) |
---|
151 | { |
---|
152 | UInt uiBit; |
---|
153 | m_pcTDecBinIf->decodeBinTrm(uiBit); |
---|
154 | m_pcTDecBinIf->finish(); |
---|
155 | m_pcBitstream->readOutTrailingBits(); |
---|
156 | m_cCUSplitFlagSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_SPLIT_FLAG ); |
---|
157 | m_cCUSkipFlagSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_SKIP_FLAG ); |
---|
158 | m_cCUMergeFlagExtSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_MERGE_FLAG_EXT ); |
---|
159 | m_cCUMergeIdxExtSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_MERGE_IDX_EXT ); |
---|
160 | m_cCUPartSizeSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_PART_SIZE ); |
---|
161 | m_cCUAMPSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_CU_AMP_POS ); |
---|
162 | m_cCUPredModeSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_PRED_MODE ); |
---|
163 | m_cCUIntraPredSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_INTRA_PRED_MODE ); |
---|
164 | m_cCUChromaPredSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_CHROMA_PRED_MODE ); |
---|
165 | m_cCUInterDirSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_INTER_DIR ); |
---|
166 | m_cCUMvdSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_MVD ); |
---|
167 | m_cCURefPicSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_REF_PIC ); |
---|
168 | m_cCUDeltaQpSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_DQP ); |
---|
169 | m_cCUQtCbfSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_QT_CBF ); |
---|
170 | m_cCUQtRootCbfSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_QT_ROOT_CBF ); |
---|
171 | m_cCUSigCoeffGroupSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_SIG_CG_FLAG ); |
---|
172 | m_cCUSigSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_SIG_FLAG ); |
---|
173 | m_cCuCtxLastX.initBuffer ( eSliceType, iQp, (UChar*)INIT_LAST ); |
---|
174 | m_cCuCtxLastY.initBuffer ( eSliceType, iQp, (UChar*)INIT_LAST ); |
---|
175 | m_cCUOneSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_ONE_FLAG ); |
---|
176 | m_cCUAbsSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_ABS_FLAG ); |
---|
177 | m_cMVPIdxSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_MVP_IDX ); |
---|
178 | m_cSaoMergeSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_SAO_MERGE_FLAG ); |
---|
179 | m_cSaoTypeIdxSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_SAO_TYPE_IDX ); |
---|
180 | m_cCUTransSubdivFlagSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_TRANS_SUBDIV_FLAG ); |
---|
181 | m_cTransformSkipSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_TRANSFORMSKIP_FLAG ); |
---|
182 | m_CUTransquantBypassFlagSCModel.initBuffer( eSliceType, iQp, (UChar*)INIT_CU_TRANSQUANT_BYPASS_FLAG ); |
---|
183 | m_pcTDecBinIf->start(); |
---|
184 | } |
---|
185 | |
---|
186 | Void TDecSbac::parseTerminatingBit( UInt& ruiBit ) |
---|
187 | { |
---|
188 | m_pcTDecBinIf->decodeBinTrm( ruiBit ); |
---|
189 | } |
---|
190 | |
---|
191 | |
---|
192 | Void TDecSbac::xReadUnaryMaxSymbol( UInt& ruiSymbol, ContextModel* pcSCModel, Int iOffset, UInt uiMaxSymbol ) |
---|
193 | { |
---|
194 | if (uiMaxSymbol == 0) |
---|
195 | { |
---|
196 | ruiSymbol = 0; |
---|
197 | return; |
---|
198 | } |
---|
199 | |
---|
200 | m_pcTDecBinIf->decodeBin( ruiSymbol, pcSCModel[0] ); |
---|
201 | |
---|
202 | if( ruiSymbol == 0 || uiMaxSymbol == 1 ) |
---|
203 | { |
---|
204 | return; |
---|
205 | } |
---|
206 | |
---|
207 | UInt uiSymbol = 0; |
---|
208 | UInt uiCont; |
---|
209 | |
---|
210 | do |
---|
211 | { |
---|
212 | m_pcTDecBinIf->decodeBin( uiCont, pcSCModel[ iOffset ] ); |
---|
213 | uiSymbol++; |
---|
214 | } |
---|
215 | while( uiCont && ( uiSymbol < uiMaxSymbol - 1 ) ); |
---|
216 | |
---|
217 | if( uiCont && ( uiSymbol == uiMaxSymbol - 1 ) ) |
---|
218 | { |
---|
219 | uiSymbol++; |
---|
220 | } |
---|
221 | |
---|
222 | ruiSymbol = uiSymbol; |
---|
223 | } |
---|
224 | |
---|
225 | Void TDecSbac::xReadEpExGolomb( UInt& ruiSymbol, UInt uiCount ) |
---|
226 | { |
---|
227 | UInt uiSymbol = 0; |
---|
228 | UInt uiBit = 1; |
---|
229 | |
---|
230 | while( uiBit ) |
---|
231 | { |
---|
232 | m_pcTDecBinIf->decodeBinEP( uiBit ); |
---|
233 | uiSymbol += uiBit << uiCount++; |
---|
234 | } |
---|
235 | |
---|
236 | if ( --uiCount ) |
---|
237 | { |
---|
238 | UInt bins; |
---|
239 | m_pcTDecBinIf->decodeBinsEP( bins, uiCount ); |
---|
240 | uiSymbol += bins; |
---|
241 | } |
---|
242 | |
---|
243 | ruiSymbol = uiSymbol; |
---|
244 | } |
---|
245 | |
---|
246 | Void TDecSbac::xReadUnarySymbol( UInt& ruiSymbol, ContextModel* pcSCModel, Int iOffset ) |
---|
247 | { |
---|
248 | m_pcTDecBinIf->decodeBin( ruiSymbol, pcSCModel[0] ); |
---|
249 | |
---|
250 | if( !ruiSymbol ) |
---|
251 | { |
---|
252 | return; |
---|
253 | } |
---|
254 | |
---|
255 | UInt uiSymbol = 0; |
---|
256 | UInt uiCont; |
---|
257 | |
---|
258 | do |
---|
259 | { |
---|
260 | m_pcTDecBinIf->decodeBin( uiCont, pcSCModel[ iOffset ] ); |
---|
261 | uiSymbol++; |
---|
262 | } |
---|
263 | while( uiCont ); |
---|
264 | |
---|
265 | ruiSymbol = uiSymbol; |
---|
266 | } |
---|
267 | |
---|
268 | |
---|
269 | /** Parsing of coeff_abs_level_remaing |
---|
270 | * \param ruiSymbol reference to coeff_abs_level_remaing |
---|
271 | * \param ruiParam reference to parameter |
---|
272 | * \returns Void |
---|
273 | */ |
---|
274 | Void TDecSbac::xReadCoefRemainExGolomb ( UInt &rSymbol, UInt &rParam ) |
---|
275 | { |
---|
276 | |
---|
277 | UInt prefix = 0; |
---|
278 | UInt codeWord = 0; |
---|
279 | do |
---|
280 | { |
---|
281 | prefix++; |
---|
282 | m_pcTDecBinIf->decodeBinEP( codeWord ); |
---|
283 | } |
---|
284 | while( codeWord); |
---|
285 | codeWord = 1 - codeWord; |
---|
286 | prefix -= codeWord; |
---|
287 | codeWord=0; |
---|
288 | if (prefix < COEF_REMAIN_BIN_REDUCTION ) |
---|
289 | { |
---|
290 | m_pcTDecBinIf->decodeBinsEP(codeWord,rParam); |
---|
291 | rSymbol = (prefix<<rParam) + codeWord; |
---|
292 | } |
---|
293 | else |
---|
294 | { |
---|
295 | m_pcTDecBinIf->decodeBinsEP(codeWord,prefix-COEF_REMAIN_BIN_REDUCTION+rParam); |
---|
296 | rSymbol = (((1<<(prefix-COEF_REMAIN_BIN_REDUCTION))+COEF_REMAIN_BIN_REDUCTION-1)<<rParam)+codeWord; |
---|
297 | } |
---|
298 | } |
---|
299 | |
---|
300 | /** Parse I_PCM information. |
---|
301 | * \param pcCU |
---|
302 | * \param uiAbsPartIdx |
---|
303 | * \param uiDepth |
---|
304 | * \returns Void |
---|
305 | * |
---|
306 | * If I_PCM flag indicates that the CU is I_PCM, parse its PCM alignment bits and codes. |
---|
307 | */ |
---|
308 | Void TDecSbac::parseIPCMInfo ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth ) |
---|
309 | { |
---|
310 | UInt uiSymbol; |
---|
311 | Bool readPCMSampleFlag = false; |
---|
312 | |
---|
313 | m_pcTDecBinIf->decodeBinTrm(uiSymbol); |
---|
314 | |
---|
315 | if (uiSymbol) |
---|
316 | { |
---|
317 | readPCMSampleFlag = true; |
---|
318 | m_pcTDecBinIf->decodePCMAlignBits(); |
---|
319 | } |
---|
320 | |
---|
321 | if (readPCMSampleFlag == true) |
---|
322 | { |
---|
323 | Bool bIpcmFlag = true; |
---|
324 | |
---|
325 | pcCU->setPartSizeSubParts ( SIZE_2Nx2N, uiAbsPartIdx, uiDepth ); |
---|
326 | pcCU->setSizeSubParts ( g_uiMaxCUWidth>>uiDepth, g_uiMaxCUHeight>>uiDepth, uiAbsPartIdx, uiDepth ); |
---|
327 | pcCU->setTrIdxSubParts ( 0, uiAbsPartIdx, uiDepth ); |
---|
328 | pcCU->setIPCMFlagSubParts ( bIpcmFlag, uiAbsPartIdx, uiDepth ); |
---|
329 | |
---|
330 | UInt uiMinCoeffSize = pcCU->getPic()->getMinCUWidth()*pcCU->getPic()->getMinCUHeight(); |
---|
331 | UInt uiLumaOffset = uiMinCoeffSize*uiAbsPartIdx; |
---|
332 | UInt uiChromaOffset = uiLumaOffset>>2; |
---|
333 | |
---|
334 | Pel* piPCMSample; |
---|
335 | UInt uiWidth; |
---|
336 | UInt uiHeight; |
---|
337 | UInt uiSampleBits; |
---|
338 | UInt uiX, uiY; |
---|
339 | |
---|
340 | piPCMSample = pcCU->getPCMSampleY() + uiLumaOffset; |
---|
341 | uiWidth = pcCU->getWidth(uiAbsPartIdx); |
---|
342 | uiHeight = pcCU->getHeight(uiAbsPartIdx); |
---|
343 | uiSampleBits = pcCU->getSlice()->getSPS()->getPCMBitDepthLuma(); |
---|
344 | |
---|
345 | for(uiY = 0; uiY < uiHeight; uiY++) |
---|
346 | { |
---|
347 | for(uiX = 0; uiX < uiWidth; uiX++) |
---|
348 | { |
---|
349 | UInt uiSample; |
---|
350 | m_pcTDecBinIf->xReadPCMCode(uiSampleBits, uiSample); |
---|
351 | piPCMSample[uiX] = uiSample; |
---|
352 | } |
---|
353 | piPCMSample += uiWidth; |
---|
354 | } |
---|
355 | |
---|
356 | piPCMSample = pcCU->getPCMSampleCb() + uiChromaOffset; |
---|
357 | uiWidth = pcCU->getWidth(uiAbsPartIdx)/2; |
---|
358 | uiHeight = pcCU->getHeight(uiAbsPartIdx)/2; |
---|
359 | uiSampleBits = pcCU->getSlice()->getSPS()->getPCMBitDepthChroma(); |
---|
360 | |
---|
361 | for(uiY = 0; uiY < uiHeight; uiY++) |
---|
362 | { |
---|
363 | for(uiX = 0; uiX < uiWidth; uiX++) |
---|
364 | { |
---|
365 | UInt uiSample; |
---|
366 | m_pcTDecBinIf->xReadPCMCode(uiSampleBits, uiSample); |
---|
367 | piPCMSample[uiX] = uiSample; |
---|
368 | } |
---|
369 | piPCMSample += uiWidth; |
---|
370 | } |
---|
371 | |
---|
372 | piPCMSample = pcCU->getPCMSampleCr() + uiChromaOffset; |
---|
373 | uiWidth = pcCU->getWidth(uiAbsPartIdx)/2; |
---|
374 | uiHeight = pcCU->getHeight(uiAbsPartIdx)/2; |
---|
375 | uiSampleBits = pcCU->getSlice()->getSPS()->getPCMBitDepthChroma(); |
---|
376 | |
---|
377 | for(uiY = 0; uiY < uiHeight; uiY++) |
---|
378 | { |
---|
379 | for(uiX = 0; uiX < uiWidth; uiX++) |
---|
380 | { |
---|
381 | UInt uiSample; |
---|
382 | m_pcTDecBinIf->xReadPCMCode(uiSampleBits, uiSample); |
---|
383 | piPCMSample[uiX] = uiSample; |
---|
384 | } |
---|
385 | piPCMSample += uiWidth; |
---|
386 | } |
---|
387 | |
---|
388 | m_pcTDecBinIf->resetBac(); |
---|
389 | } |
---|
390 | } |
---|
391 | |
---|
392 | Void TDecSbac::parseCUTransquantBypassFlag( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth ) |
---|
393 | { |
---|
394 | UInt uiSymbol; |
---|
395 | m_pcTDecBinIf->decodeBin( uiSymbol, m_CUTransquantBypassFlagSCModel.get( 0, 0, 0 ) ); |
---|
396 | pcCU->setCUTransquantBypassSubParts(uiSymbol ? true : false, uiAbsPartIdx, uiDepth); |
---|
397 | } |
---|
398 | |
---|
399 | /** parse skip flag |
---|
400 | * \param pcCU |
---|
401 | * \param uiAbsPartIdx |
---|
402 | * \param uiDepth |
---|
403 | * \returns Void |
---|
404 | */ |
---|
405 | Void TDecSbac::parseSkipFlag( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth ) |
---|
406 | { |
---|
407 | if( pcCU->getSlice()->isIntra() ) |
---|
408 | { |
---|
409 | return; |
---|
410 | } |
---|
411 | |
---|
412 | UInt uiSymbol = 0; |
---|
413 | UInt uiCtxSkip = pcCU->getCtxSkipFlag( uiAbsPartIdx ); |
---|
414 | m_pcTDecBinIf->decodeBin( uiSymbol, m_cCUSkipFlagSCModel.get( 0, 0, uiCtxSkip ) ); |
---|
415 | DTRACE_CABAC_VL( g_nSymbolCounter++ ); |
---|
416 | DTRACE_CABAC_T( "\tSkipFlag" ); |
---|
417 | DTRACE_CABAC_T( "\tuiCtxSkip: "); |
---|
418 | DTRACE_CABAC_V( uiCtxSkip ); |
---|
419 | DTRACE_CABAC_T( "\tuiSymbol: "); |
---|
420 | DTRACE_CABAC_V( uiSymbol ); |
---|
421 | DTRACE_CABAC_T( "\n"); |
---|
422 | |
---|
423 | if( uiSymbol ) |
---|
424 | { |
---|
425 | pcCU->setSkipFlagSubParts( true, uiAbsPartIdx, uiDepth ); |
---|
426 | pcCU->setPredModeSubParts( MODE_INTER, uiAbsPartIdx, uiDepth ); |
---|
427 | pcCU->setPartSizeSubParts( SIZE_2Nx2N, uiAbsPartIdx, uiDepth ); |
---|
428 | pcCU->setSizeSubParts( g_uiMaxCUWidth>>uiDepth, g_uiMaxCUHeight>>uiDepth, uiAbsPartIdx, uiDepth ); |
---|
429 | pcCU->setMergeFlagSubParts( true , uiAbsPartIdx, 0, uiDepth ); |
---|
430 | } |
---|
431 | } |
---|
432 | |
---|
433 | /** parse merge flag |
---|
434 | * \param pcCU |
---|
435 | * \param uiAbsPartIdx |
---|
436 | * \param uiDepth |
---|
437 | * \param uiPUIdx |
---|
438 | * \returns Void |
---|
439 | */ |
---|
440 | Void TDecSbac::parseMergeFlag ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, UInt uiPUIdx ) |
---|
441 | { |
---|
442 | UInt uiSymbol; |
---|
443 | m_pcTDecBinIf->decodeBin( uiSymbol, *m_cCUMergeFlagExtSCModel.get( 0 ) ); |
---|
444 | pcCU->setMergeFlagSubParts( uiSymbol ? true : false, uiAbsPartIdx, uiPUIdx, uiDepth ); |
---|
445 | |
---|
446 | DTRACE_CABAC_VL( g_nSymbolCounter++ ); |
---|
447 | DTRACE_CABAC_T( "\tMergeFlag: " ); |
---|
448 | DTRACE_CABAC_V( uiSymbol ); |
---|
449 | DTRACE_CABAC_T( "\tAddress: " ); |
---|
450 | DTRACE_CABAC_V( pcCU->getAddr() ); |
---|
451 | DTRACE_CABAC_T( "\tuiAbsPartIdx: " ); |
---|
452 | DTRACE_CABAC_V( uiAbsPartIdx ); |
---|
453 | DTRACE_CABAC_T( "\n" ); |
---|
454 | } |
---|
455 | |
---|
456 | Void TDecSbac::parseMergeIndex ( TComDataCU* pcCU, UInt& ruiMergeIndex ) |
---|
457 | { |
---|
458 | UInt uiUnaryIdx = 0; |
---|
459 | UInt uiNumCand = pcCU->getSlice()->getMaxNumMergeCand(); |
---|
460 | if ( uiNumCand > 1 ) |
---|
461 | { |
---|
462 | for( ; uiUnaryIdx < uiNumCand - 1; ++uiUnaryIdx ) |
---|
463 | { |
---|
464 | UInt uiSymbol = 0; |
---|
465 | if ( uiUnaryIdx==0 ) |
---|
466 | { |
---|
467 | m_pcTDecBinIf->decodeBin( uiSymbol, m_cCUMergeIdxExtSCModel.get( 0, 0, 0 ) ); |
---|
468 | } |
---|
469 | else |
---|
470 | { |
---|
471 | m_pcTDecBinIf->decodeBinEP( uiSymbol ); |
---|
472 | } |
---|
473 | if( uiSymbol == 0 ) |
---|
474 | { |
---|
475 | break; |
---|
476 | } |
---|
477 | } |
---|
478 | } |
---|
479 | ruiMergeIndex = uiUnaryIdx; |
---|
480 | |
---|
481 | DTRACE_CABAC_VL( g_nSymbolCounter++ ) |
---|
482 | DTRACE_CABAC_T( "\tparseMergeIndex()" ) |
---|
483 | DTRACE_CABAC_T( "\tuiMRGIdx= " ) |
---|
484 | DTRACE_CABAC_V( ruiMergeIndex ) |
---|
485 | DTRACE_CABAC_T( "\n" ) |
---|
486 | } |
---|
487 | |
---|
488 | Void TDecSbac::parseMVPIdx ( Int& riMVPIdx ) |
---|
489 | { |
---|
490 | UInt uiSymbol; |
---|
491 | xReadUnaryMaxSymbol(uiSymbol, m_cMVPIdxSCModel.get(0), 1, AMVP_MAX_NUM_CANDS-1); |
---|
492 | riMVPIdx = uiSymbol; |
---|
493 | } |
---|
494 | |
---|
495 | Void TDecSbac::parseSplitFlag ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth ) |
---|
496 | { |
---|
497 | if( uiDepth == g_uiMaxCUDepth - g_uiAddCUDepth ) |
---|
498 | { |
---|
499 | pcCU->setDepthSubParts( uiDepth, uiAbsPartIdx ); |
---|
500 | return; |
---|
501 | } |
---|
502 | |
---|
503 | UInt uiSymbol; |
---|
504 | m_pcTDecBinIf->decodeBin( uiSymbol, m_cCUSplitFlagSCModel.get( 0, 0, pcCU->getCtxSplitFlag( uiAbsPartIdx, uiDepth ) ) ); |
---|
505 | DTRACE_CABAC_VL( g_nSymbolCounter++ ) |
---|
506 | DTRACE_CABAC_T( "\tSplitFlag\n" ) |
---|
507 | pcCU->setDepthSubParts( uiDepth + uiSymbol, uiAbsPartIdx ); |
---|
508 | |
---|
509 | return; |
---|
510 | } |
---|
511 | |
---|
512 | /** parse partition size |
---|
513 | * \param pcCU |
---|
514 | * \param uiAbsPartIdx |
---|
515 | * \param uiDepth |
---|
516 | * \returns Void |
---|
517 | */ |
---|
518 | Void TDecSbac::parsePartSize( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth ) |
---|
519 | { |
---|
520 | UInt uiSymbol, uiMode = 0; |
---|
521 | PartSize eMode; |
---|
522 | |
---|
523 | if ( pcCU->isIntra( uiAbsPartIdx ) ) |
---|
524 | { |
---|
525 | uiSymbol = 1; |
---|
526 | if( uiDepth == g_uiMaxCUDepth - g_uiAddCUDepth ) |
---|
527 | { |
---|
528 | m_pcTDecBinIf->decodeBin( uiSymbol, m_cCUPartSizeSCModel.get( 0, 0, 0) ); |
---|
529 | } |
---|
530 | eMode = uiSymbol ? SIZE_2Nx2N : SIZE_NxN; |
---|
531 | UInt uiTrLevel = 0; |
---|
532 | UInt uiWidthInBit = g_aucConvertToBit[pcCU->getWidth(uiAbsPartIdx)]+2; |
---|
533 | UInt uiTrSizeInBit = g_aucConvertToBit[pcCU->getSlice()->getSPS()->getMaxTrSize()]+2; |
---|
534 | uiTrLevel = uiWidthInBit >= uiTrSizeInBit ? uiWidthInBit - uiTrSizeInBit : 0; |
---|
535 | if( eMode == SIZE_NxN ) |
---|
536 | { |
---|
537 | pcCU->setTrIdxSubParts( 1+uiTrLevel, uiAbsPartIdx, uiDepth ); |
---|
538 | } |
---|
539 | else |
---|
540 | { |
---|
541 | pcCU->setTrIdxSubParts( uiTrLevel, uiAbsPartIdx, uiDepth ); |
---|
542 | } |
---|
543 | } |
---|
544 | else |
---|
545 | { |
---|
546 | UInt uiMaxNumBits = 2; |
---|
547 | if( uiDepth == g_uiMaxCUDepth - g_uiAddCUDepth && !( (g_uiMaxCUWidth>>uiDepth) == 8 && (g_uiMaxCUHeight>>uiDepth) == 8 ) ) |
---|
548 | { |
---|
549 | uiMaxNumBits ++; |
---|
550 | } |
---|
551 | for ( UInt ui = 0; ui < uiMaxNumBits; ui++ ) |
---|
552 | { |
---|
553 | m_pcTDecBinIf->decodeBin( uiSymbol, m_cCUPartSizeSCModel.get( 0, 0, ui) ); |
---|
554 | if ( uiSymbol ) |
---|
555 | { |
---|
556 | break; |
---|
557 | } |
---|
558 | uiMode++; |
---|
559 | } |
---|
560 | eMode = (PartSize) uiMode; |
---|
561 | if ( pcCU->getSlice()->getSPS()->getAMPAcc( uiDepth ) ) |
---|
562 | { |
---|
563 | if (eMode == SIZE_2NxN) |
---|
564 | { |
---|
565 | m_pcTDecBinIf->decodeBin(uiSymbol, m_cCUAMPSCModel.get( 0, 0, 0 )); |
---|
566 | if (uiSymbol == 0) |
---|
567 | { |
---|
568 | m_pcTDecBinIf->decodeBinEP(uiSymbol); |
---|
569 | eMode = (uiSymbol == 0? SIZE_2NxnU : SIZE_2NxnD); |
---|
570 | } |
---|
571 | } |
---|
572 | else if (eMode == SIZE_Nx2N) |
---|
573 | { |
---|
574 | m_pcTDecBinIf->decodeBin(uiSymbol, m_cCUAMPSCModel.get( 0, 0, 0 )); |
---|
575 | if (uiSymbol == 0) |
---|
576 | { |
---|
577 | m_pcTDecBinIf->decodeBinEP(uiSymbol); |
---|
578 | eMode = (uiSymbol == 0? SIZE_nLx2N : SIZE_nRx2N); |
---|
579 | } |
---|
580 | } |
---|
581 | } |
---|
582 | } |
---|
583 | pcCU->setPartSizeSubParts( eMode, uiAbsPartIdx, uiDepth ); |
---|
584 | pcCU->setSizeSubParts( g_uiMaxCUWidth>>uiDepth, g_uiMaxCUHeight>>uiDepth, uiAbsPartIdx, uiDepth ); |
---|
585 | } |
---|
586 | |
---|
587 | /** parse prediction mode |
---|
588 | * \param pcCU |
---|
589 | * \param uiAbsPartIdx |
---|
590 | * \param uiDepth |
---|
591 | * \returns Void |
---|
592 | */ |
---|
593 | Void TDecSbac::parsePredMode( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth ) |
---|
594 | { |
---|
595 | if( pcCU->getSlice()->isIntra() ) |
---|
596 | { |
---|
597 | pcCU->setPredModeSubParts( MODE_INTRA, uiAbsPartIdx, uiDepth ); |
---|
598 | return; |
---|
599 | } |
---|
600 | |
---|
601 | UInt uiSymbol; |
---|
602 | Int iPredMode = MODE_INTER; |
---|
603 | m_pcTDecBinIf->decodeBin( uiSymbol, m_cCUPredModeSCModel.get( 0, 0, 0 ) ); |
---|
604 | iPredMode += uiSymbol; |
---|
605 | pcCU->setPredModeSubParts( (PredMode)iPredMode, uiAbsPartIdx, uiDepth ); |
---|
606 | } |
---|
607 | |
---|
608 | Void TDecSbac::parseIntraDirLumaAng ( TComDataCU* pcCU, UInt absPartIdx, UInt depth ) |
---|
609 | { |
---|
610 | PartSize mode = pcCU->getPartitionSize( absPartIdx ); |
---|
611 | UInt partNum = mode==SIZE_NxN?4:1; |
---|
612 | UInt partOffset = ( pcCU->getPic()->getNumPartInCU() >> ( pcCU->getDepth(absPartIdx) << 1 ) ) >> 2; |
---|
613 | UInt mpmPred[4],symbol; |
---|
614 | Int j,intraPredMode; |
---|
615 | if (mode==SIZE_NxN) |
---|
616 | { |
---|
617 | depth++; |
---|
618 | } |
---|
619 | for (j=0;j<partNum;j++) |
---|
620 | { |
---|
621 | m_pcTDecBinIf->decodeBin( symbol, m_cCUIntraPredSCModel.get( 0, 0, 0) ); |
---|
622 | mpmPred[j] = symbol; |
---|
623 | } |
---|
624 | for (j=0;j<partNum;j++) |
---|
625 | { |
---|
626 | Int preds[3] = {-1, -1, -1}; |
---|
627 | Int predNum = pcCU->getIntraDirLumaPredictor(absPartIdx+partOffset*j, preds); |
---|
628 | if (mpmPred[j]) |
---|
629 | { |
---|
630 | m_pcTDecBinIf->decodeBinEP( symbol ); |
---|
631 | if (symbol) |
---|
632 | { |
---|
633 | m_pcTDecBinIf->decodeBinEP( symbol ); |
---|
634 | symbol++; |
---|
635 | } |
---|
636 | intraPredMode = preds[symbol]; |
---|
637 | } |
---|
638 | else |
---|
639 | { |
---|
640 | intraPredMode = 0; |
---|
641 | m_pcTDecBinIf->decodeBinsEP( symbol, 5 ); |
---|
642 | intraPredMode = symbol; |
---|
643 | |
---|
644 | //postponed sorting of MPMs (only in remaining branch) |
---|
645 | if (preds[0] > preds[1]) |
---|
646 | { |
---|
647 | std::swap(preds[0], preds[1]); |
---|
648 | } |
---|
649 | if (preds[0] > preds[2]) |
---|
650 | { |
---|
651 | std::swap(preds[0], preds[2]); |
---|
652 | } |
---|
653 | if (preds[1] > preds[2]) |
---|
654 | { |
---|
655 | std::swap(preds[1], preds[2]); |
---|
656 | } |
---|
657 | for ( Int i = 0; i < predNum; i++ ) |
---|
658 | { |
---|
659 | intraPredMode += ( intraPredMode >= preds[i] ); |
---|
660 | } |
---|
661 | } |
---|
662 | pcCU->setLumaIntraDirSubParts( (UChar)intraPredMode, absPartIdx+partOffset*j, depth ); |
---|
663 | } |
---|
664 | } |
---|
665 | |
---|
666 | Void TDecSbac::parseIntraDirChroma( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth ) |
---|
667 | { |
---|
668 | UInt uiSymbol; |
---|
669 | |
---|
670 | m_pcTDecBinIf->decodeBin( uiSymbol, m_cCUChromaPredSCModel.get( 0, 0, 0 ) ); |
---|
671 | |
---|
672 | if( uiSymbol == 0 ) |
---|
673 | { |
---|
674 | uiSymbol = DM_CHROMA_IDX; |
---|
675 | } |
---|
676 | else |
---|
677 | { |
---|
678 | { |
---|
679 | UInt uiIPredMode; |
---|
680 | m_pcTDecBinIf->decodeBinsEP( uiIPredMode, 2 ); |
---|
681 | UInt uiAllowedChromaDir[ NUM_CHROMA_MODE ]; |
---|
682 | pcCU->getAllowedChromaDir( uiAbsPartIdx, uiAllowedChromaDir ); |
---|
683 | uiSymbol = uiAllowedChromaDir[ uiIPredMode ]; |
---|
684 | } |
---|
685 | } |
---|
686 | pcCU->setChromIntraDirSubParts( uiSymbol, uiAbsPartIdx, uiDepth ); |
---|
687 | return; |
---|
688 | } |
---|
689 | |
---|
690 | Void TDecSbac::parseInterDir( TComDataCU* pcCU, UInt& ruiInterDir, UInt uiAbsPartIdx ) |
---|
691 | { |
---|
692 | UInt uiSymbol; |
---|
693 | const UInt uiCtx = pcCU->getCtxInterDir( uiAbsPartIdx ); |
---|
694 | ContextModel *pCtx = m_cCUInterDirSCModel.get( 0 ); |
---|
695 | uiSymbol = 0; |
---|
696 | if (pcCU->getPartitionSize(uiAbsPartIdx) == SIZE_2Nx2N || pcCU->getHeight(uiAbsPartIdx) != 8 ) |
---|
697 | { |
---|
698 | m_pcTDecBinIf->decodeBin( uiSymbol, *( pCtx + uiCtx ) ); |
---|
699 | } |
---|
700 | |
---|
701 | if( uiSymbol ) |
---|
702 | { |
---|
703 | uiSymbol = 2; |
---|
704 | } |
---|
705 | else |
---|
706 | { |
---|
707 | m_pcTDecBinIf->decodeBin( uiSymbol, *( pCtx + 4 ) ); |
---|
708 | assert(uiSymbol == 0 || uiSymbol == 1); |
---|
709 | } |
---|
710 | |
---|
711 | uiSymbol++; |
---|
712 | ruiInterDir = uiSymbol; |
---|
713 | return; |
---|
714 | } |
---|
715 | |
---|
716 | Void TDecSbac::parseRefFrmIdx( TComDataCU* pcCU, Int& riRefFrmIdx, RefPicList eRefList ) |
---|
717 | { |
---|
718 | UInt uiSymbol; |
---|
719 | { |
---|
720 | ContextModel *pCtx = m_cCURefPicSCModel.get( 0 ); |
---|
721 | m_pcTDecBinIf->decodeBin( uiSymbol, *pCtx ); |
---|
722 | |
---|
723 | if( uiSymbol ) |
---|
724 | { |
---|
725 | UInt uiRefNum = pcCU->getSlice()->getNumRefIdx( eRefList ) - 2; |
---|
726 | pCtx++; |
---|
727 | UInt ui; |
---|
728 | for( ui = 0; ui < uiRefNum; ++ui ) |
---|
729 | { |
---|
730 | if( ui == 0 ) |
---|
731 | { |
---|
732 | m_pcTDecBinIf->decodeBin( uiSymbol, *pCtx ); |
---|
733 | } |
---|
734 | else |
---|
735 | { |
---|
736 | m_pcTDecBinIf->decodeBinEP( uiSymbol ); |
---|
737 | } |
---|
738 | if( uiSymbol == 0 ) |
---|
739 | { |
---|
740 | break; |
---|
741 | } |
---|
742 | } |
---|
743 | uiSymbol = ui + 1; |
---|
744 | } |
---|
745 | riRefFrmIdx = uiSymbol; |
---|
746 | } |
---|
747 | |
---|
748 | return; |
---|
749 | } |
---|
750 | |
---|
751 | Void TDecSbac::parseMvd( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiPartIdx, UInt uiDepth, RefPicList eRefList ) |
---|
752 | { |
---|
753 | UInt uiSymbol; |
---|
754 | UInt uiHorAbs; |
---|
755 | UInt uiVerAbs; |
---|
756 | UInt uiHorSign = 0; |
---|
757 | UInt uiVerSign = 0; |
---|
758 | ContextModel *pCtx = m_cCUMvdSCModel.get( 0 ); |
---|
759 | |
---|
760 | if(pcCU->getSlice()->getMvdL1ZeroFlag() && eRefList == REF_PIC_LIST_1 && pcCU->getInterDir(uiAbsPartIdx)==3) |
---|
761 | { |
---|
762 | uiHorAbs=0; |
---|
763 | uiVerAbs=0; |
---|
764 | } |
---|
765 | else |
---|
766 | { |
---|
767 | m_pcTDecBinIf->decodeBin( uiHorAbs, *pCtx ); |
---|
768 | m_pcTDecBinIf->decodeBin( uiVerAbs, *pCtx ); |
---|
769 | |
---|
770 | const Bool bHorAbsGr0 = uiHorAbs != 0; |
---|
771 | const Bool bVerAbsGr0 = uiVerAbs != 0; |
---|
772 | pCtx++; |
---|
773 | |
---|
774 | if( bHorAbsGr0 ) |
---|
775 | { |
---|
776 | m_pcTDecBinIf->decodeBin( uiSymbol, *pCtx ); |
---|
777 | uiHorAbs += uiSymbol; |
---|
778 | } |
---|
779 | |
---|
780 | if( bVerAbsGr0 ) |
---|
781 | { |
---|
782 | m_pcTDecBinIf->decodeBin( uiSymbol, *pCtx ); |
---|
783 | uiVerAbs += uiSymbol; |
---|
784 | } |
---|
785 | |
---|
786 | if( bHorAbsGr0 ) |
---|
787 | { |
---|
788 | if( 2 == uiHorAbs ) |
---|
789 | { |
---|
790 | xReadEpExGolomb( uiSymbol, 1 ); |
---|
791 | uiHorAbs += uiSymbol; |
---|
792 | } |
---|
793 | |
---|
794 | m_pcTDecBinIf->decodeBinEP( uiHorSign ); |
---|
795 | } |
---|
796 | |
---|
797 | if( bVerAbsGr0 ) |
---|
798 | { |
---|
799 | if( 2 == uiVerAbs ) |
---|
800 | { |
---|
801 | xReadEpExGolomb( uiSymbol, 1 ); |
---|
802 | uiVerAbs += uiSymbol; |
---|
803 | } |
---|
804 | |
---|
805 | m_pcTDecBinIf->decodeBinEP( uiVerSign ); |
---|
806 | } |
---|
807 | |
---|
808 | } |
---|
809 | |
---|
810 | const TComMv cMv( uiHorSign ? -Int( uiHorAbs ): uiHorAbs, uiVerSign ? -Int( uiVerAbs ) : uiVerAbs ); |
---|
811 | pcCU->getCUMvField( eRefList )->setAllMvd( cMv, pcCU->getPartitionSize( uiAbsPartIdx ), uiAbsPartIdx, uiDepth, uiPartIdx ); |
---|
812 | return; |
---|
813 | } |
---|
814 | |
---|
815 | |
---|
816 | Void TDecSbac::parseTransformSubdivFlag( UInt& ruiSubdivFlag, UInt uiLog2TransformBlockSize ) |
---|
817 | { |
---|
818 | m_pcTDecBinIf->decodeBin( ruiSubdivFlag, m_cCUTransSubdivFlagSCModel.get( 0, 0, uiLog2TransformBlockSize ) ); |
---|
819 | DTRACE_CABAC_VL( g_nSymbolCounter++ ) |
---|
820 | DTRACE_CABAC_T( "\tparseTransformSubdivFlag()" ) |
---|
821 | DTRACE_CABAC_T( "\tsymbol=" ) |
---|
822 | DTRACE_CABAC_V( ruiSubdivFlag ) |
---|
823 | DTRACE_CABAC_T( "\tctx=" ) |
---|
824 | DTRACE_CABAC_V( uiLog2TransformBlockSize ) |
---|
825 | DTRACE_CABAC_T( "\n" ) |
---|
826 | } |
---|
827 | |
---|
828 | Void TDecSbac::parseQtRootCbf( UInt uiAbsPartIdx, UInt& uiQtRootCbf ) |
---|
829 | { |
---|
830 | UInt uiSymbol; |
---|
831 | const UInt uiCtx = 0; |
---|
832 | m_pcTDecBinIf->decodeBin( uiSymbol , m_cCUQtRootCbfSCModel.get( 0, 0, uiCtx ) ); |
---|
833 | DTRACE_CABAC_VL( g_nSymbolCounter++ ) |
---|
834 | DTRACE_CABAC_T( "\tparseQtRootCbf()" ) |
---|
835 | DTRACE_CABAC_T( "\tsymbol=" ) |
---|
836 | DTRACE_CABAC_V( uiSymbol ) |
---|
837 | DTRACE_CABAC_T( "\tctx=" ) |
---|
838 | DTRACE_CABAC_V( uiCtx ) |
---|
839 | DTRACE_CABAC_T( "\tuiAbsPartIdx=" ) |
---|
840 | DTRACE_CABAC_V( uiAbsPartIdx ) |
---|
841 | DTRACE_CABAC_T( "\n" ) |
---|
842 | |
---|
843 | uiQtRootCbf = uiSymbol; |
---|
844 | } |
---|
845 | |
---|
846 | Void TDecSbac::parseDeltaQP( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth ) |
---|
847 | { |
---|
848 | Int qp; |
---|
849 | UInt uiDQp; |
---|
850 | Int iDQp; |
---|
851 | |
---|
852 | UInt uiSymbol; |
---|
853 | |
---|
854 | xReadUnaryMaxSymbol (uiDQp, &m_cCUDeltaQpSCModel.get( 0, 0, 0 ), 1, CU_DQP_TU_CMAX); |
---|
855 | |
---|
856 | if( uiDQp >= CU_DQP_TU_CMAX) |
---|
857 | { |
---|
858 | xReadEpExGolomb( uiSymbol, CU_DQP_EG_k ); |
---|
859 | uiDQp+=uiSymbol; |
---|
860 | } |
---|
861 | |
---|
862 | if ( uiDQp > 0 ) |
---|
863 | { |
---|
864 | UInt uiSign; |
---|
865 | Int qpBdOffsetY = pcCU->getSlice()->getSPS()->getQpBDOffsetY(); |
---|
866 | m_pcTDecBinIf->decodeBinEP(uiSign); |
---|
867 | iDQp = uiDQp; |
---|
868 | if(uiSign) |
---|
869 | { |
---|
870 | iDQp = -iDQp; |
---|
871 | } |
---|
872 | qp = (((Int) pcCU->getRefQP( uiAbsPartIdx ) + iDQp + 52 + 2*qpBdOffsetY )%(52+qpBdOffsetY)) - qpBdOffsetY; |
---|
873 | } |
---|
874 | else |
---|
875 | { |
---|
876 | iDQp=0; |
---|
877 | qp = pcCU->getRefQP(uiAbsPartIdx); |
---|
878 | } |
---|
879 | pcCU->setQPSubParts(qp, uiAbsPartIdx, uiDepth); |
---|
880 | pcCU->setCodedQP(qp); |
---|
881 | } |
---|
882 | |
---|
883 | Void TDecSbac::parseQtCbf( TComDataCU* pcCU, UInt uiAbsPartIdx, TextType eType, UInt uiTrDepth, UInt uiDepth ) |
---|
884 | { |
---|
885 | UInt uiSymbol; |
---|
886 | const UInt uiCtx = pcCU->getCtxQtCbf( eType, uiTrDepth ); |
---|
887 | m_pcTDecBinIf->decodeBin( uiSymbol , m_cCUQtCbfSCModel.get( 0, eType ? TEXT_CHROMA: eType, uiCtx ) ); |
---|
888 | |
---|
889 | DTRACE_CABAC_VL( g_nSymbolCounter++ ) |
---|
890 | DTRACE_CABAC_T( "\tparseQtCbf()" ) |
---|
891 | DTRACE_CABAC_T( "\tsymbol=" ) |
---|
892 | DTRACE_CABAC_V( uiSymbol ) |
---|
893 | DTRACE_CABAC_T( "\tctx=" ) |
---|
894 | DTRACE_CABAC_V( uiCtx ) |
---|
895 | DTRACE_CABAC_T( "\tetype=" ) |
---|
896 | DTRACE_CABAC_V( eType ) |
---|
897 | DTRACE_CABAC_T( "\tuiAbsPartIdx=" ) |
---|
898 | DTRACE_CABAC_V( uiAbsPartIdx ) |
---|
899 | DTRACE_CABAC_T( "\n" ) |
---|
900 | |
---|
901 | pcCU->setCbfSubParts( uiSymbol << uiTrDepth, eType, uiAbsPartIdx, uiDepth ); |
---|
902 | } |
---|
903 | |
---|
904 | void TDecSbac::parseTransformSkipFlags (TComDataCU* pcCU, UInt uiAbsPartIdx, UInt width, UInt height, UInt uiDepth, TextType eTType) |
---|
905 | { |
---|
906 | if (pcCU->getCUTransquantBypass(uiAbsPartIdx)) |
---|
907 | { |
---|
908 | return; |
---|
909 | } |
---|
910 | if(width != 4 || height != 4) |
---|
911 | { |
---|
912 | return; |
---|
913 | } |
---|
914 | |
---|
915 | UInt useTransformSkip; |
---|
916 | m_pcTDecBinIf->decodeBin( useTransformSkip , m_cTransformSkipSCModel.get( 0, eTType? TEXT_CHROMA: TEXT_LUMA, 0 ) ); |
---|
917 | if(eTType!= TEXT_LUMA) |
---|
918 | { |
---|
919 | const UInt uiLog2TrafoSize = g_aucConvertToBit[pcCU->getSlice()->getSPS()->getMaxCUWidth()] + 2 - uiDepth; |
---|
920 | if(uiLog2TrafoSize == 2) |
---|
921 | { |
---|
922 | uiDepth --; |
---|
923 | } |
---|
924 | } |
---|
925 | DTRACE_CABAC_VL( g_nSymbolCounter++ ) |
---|
926 | DTRACE_CABAC_T("\tparseTransformSkip()"); |
---|
927 | DTRACE_CABAC_T( "\tsymbol=" ) |
---|
928 | DTRACE_CABAC_V( useTransformSkip ) |
---|
929 | DTRACE_CABAC_T( "\tAddr=" ) |
---|
930 | DTRACE_CABAC_V( pcCU->getAddr() ) |
---|
931 | DTRACE_CABAC_T( "\tetype=" ) |
---|
932 | DTRACE_CABAC_V( eTType ) |
---|
933 | DTRACE_CABAC_T( "\tuiAbsPartIdx=" ) |
---|
934 | DTRACE_CABAC_V( uiAbsPartIdx ) |
---|
935 | DTRACE_CABAC_T( "\n" ) |
---|
936 | |
---|
937 | pcCU->setTransformSkipSubParts( useTransformSkip, eTType, uiAbsPartIdx, uiDepth); |
---|
938 | } |
---|
939 | |
---|
940 | /** Parse (X,Y) position of the last significant coefficient |
---|
941 | * \param uiPosLastX reference to X component of last coefficient |
---|
942 | * \param uiPosLastY reference to Y component of last coefficient |
---|
943 | * \param width Block width |
---|
944 | * \param height Block height |
---|
945 | * \param eTType plane type / luminance or chrominance |
---|
946 | * \param uiScanIdx scan type (zig-zag, hor, ver) |
---|
947 | * |
---|
948 | * This method decodes the X and Y component within a block of the last significant coefficient. |
---|
949 | */ |
---|
950 | Void TDecSbac::parseLastSignificantXY( UInt& uiPosLastX, UInt& uiPosLastY, Int width, Int height, TextType eTType, UInt uiScanIdx ) |
---|
951 | { |
---|
952 | UInt uiLast; |
---|
953 | ContextModel *pCtxX = m_cCuCtxLastX.get( 0, eTType ); |
---|
954 | ContextModel *pCtxY = m_cCuCtxLastY.get( 0, eTType ); |
---|
955 | |
---|
956 | Int blkSizeOffsetX, blkSizeOffsetY, shiftX, shiftY; |
---|
957 | blkSizeOffsetX = eTType ? 0: (g_aucConvertToBit[ width ] *3 + ((g_aucConvertToBit[ width ] +1)>>2)); |
---|
958 | blkSizeOffsetY = eTType ? 0: (g_aucConvertToBit[ height ]*3 + ((g_aucConvertToBit[ height ]+1)>>2)); |
---|
959 | shiftX= eTType ? g_aucConvertToBit[ width ] :((g_aucConvertToBit[ width ]+3)>>2); |
---|
960 | shiftY= eTType ? g_aucConvertToBit[ height ] :((g_aucConvertToBit[ height ]+3)>>2); |
---|
961 | // posX |
---|
962 | for( uiPosLastX = 0; uiPosLastX < g_uiGroupIdx[ width - 1 ]; uiPosLastX++ ) |
---|
963 | { |
---|
964 | m_pcTDecBinIf->decodeBin( uiLast, *( pCtxX + blkSizeOffsetX + (uiPosLastX >>shiftX) ) ); |
---|
965 | if( !uiLast ) |
---|
966 | { |
---|
967 | break; |
---|
968 | } |
---|
969 | } |
---|
970 | |
---|
971 | // posY |
---|
972 | for( uiPosLastY = 0; uiPosLastY < g_uiGroupIdx[ height - 1 ]; uiPosLastY++ ) |
---|
973 | { |
---|
974 | m_pcTDecBinIf->decodeBin( uiLast, *( pCtxY + blkSizeOffsetY + (uiPosLastY >>shiftY)) ); |
---|
975 | if( !uiLast ) |
---|
976 | { |
---|
977 | break; |
---|
978 | } |
---|
979 | } |
---|
980 | if ( uiPosLastX > 3 ) |
---|
981 | { |
---|
982 | UInt uiTemp = 0; |
---|
983 | UInt uiCount = ( uiPosLastX - 2 ) >> 1; |
---|
984 | for ( Int i = uiCount - 1; i >= 0; i-- ) |
---|
985 | { |
---|
986 | m_pcTDecBinIf->decodeBinEP( uiLast ); |
---|
987 | uiTemp += uiLast << i; |
---|
988 | } |
---|
989 | uiPosLastX = g_uiMinInGroup[ uiPosLastX ] + uiTemp; |
---|
990 | } |
---|
991 | if ( uiPosLastY > 3 ) |
---|
992 | { |
---|
993 | UInt uiTemp = 0; |
---|
994 | UInt uiCount = ( uiPosLastY - 2 ) >> 1; |
---|
995 | for ( Int i = uiCount - 1; i >= 0; i-- ) |
---|
996 | { |
---|
997 | m_pcTDecBinIf->decodeBinEP( uiLast ); |
---|
998 | uiTemp += uiLast << i; |
---|
999 | } |
---|
1000 | uiPosLastY = g_uiMinInGroup[ uiPosLastY ] + uiTemp; |
---|
1001 | } |
---|
1002 | |
---|
1003 | if( uiScanIdx == SCAN_VER ) |
---|
1004 | { |
---|
1005 | swap( uiPosLastX, uiPosLastY ); |
---|
1006 | } |
---|
1007 | } |
---|
1008 | |
---|
1009 | Void TDecSbac::parseCoeffNxN( TComDataCU* pcCU, TCoeff* pcCoef, UInt uiAbsPartIdx, UInt uiWidth, UInt uiHeight, UInt uiDepth, TextType eTType ) |
---|
1010 | { |
---|
1011 | DTRACE_CABAC_VL( g_nSymbolCounter++ ) |
---|
1012 | DTRACE_CABAC_T( "\tparseCoeffNxN()\teType=" ) |
---|
1013 | DTRACE_CABAC_V( eTType ) |
---|
1014 | DTRACE_CABAC_T( "\twidth=" ) |
---|
1015 | DTRACE_CABAC_V( uiWidth ) |
---|
1016 | DTRACE_CABAC_T( "\theight=" ) |
---|
1017 | DTRACE_CABAC_V( uiHeight ) |
---|
1018 | DTRACE_CABAC_T( "\tdepth=" ) |
---|
1019 | DTRACE_CABAC_V( uiDepth ) |
---|
1020 | DTRACE_CABAC_T( "\tabspartidx=" ) |
---|
1021 | DTRACE_CABAC_V( uiAbsPartIdx ) |
---|
1022 | DTRACE_CABAC_T( "\ttoCU-X=" ) |
---|
1023 | DTRACE_CABAC_V( pcCU->getCUPelX() ) |
---|
1024 | DTRACE_CABAC_T( "\ttoCU-Y=" ) |
---|
1025 | DTRACE_CABAC_V( pcCU->getCUPelY() ) |
---|
1026 | DTRACE_CABAC_T( "\tCU-addr=" ) |
---|
1027 | DTRACE_CABAC_V( pcCU->getAddr() ) |
---|
1028 | DTRACE_CABAC_T( "\tinCU-X=" ) |
---|
1029 | DTRACE_CABAC_V( g_auiRasterToPelX[ g_auiZscanToRaster[uiAbsPartIdx] ] ) |
---|
1030 | DTRACE_CABAC_T( "\tinCU-Y=" ) |
---|
1031 | DTRACE_CABAC_V( g_auiRasterToPelY[ g_auiZscanToRaster[uiAbsPartIdx] ] ) |
---|
1032 | DTRACE_CABAC_T( "\tpredmode=" ) |
---|
1033 | DTRACE_CABAC_V( pcCU->getPredictionMode( uiAbsPartIdx ) ) |
---|
1034 | DTRACE_CABAC_T( "\n" ) |
---|
1035 | |
---|
1036 | if( uiWidth > pcCU->getSlice()->getSPS()->getMaxTrSize() ) |
---|
1037 | { |
---|
1038 | uiWidth = pcCU->getSlice()->getSPS()->getMaxTrSize(); |
---|
1039 | uiHeight = pcCU->getSlice()->getSPS()->getMaxTrSize(); |
---|
1040 | } |
---|
1041 | if(pcCU->getSlice()->getPPS()->getUseTransformSkip()) |
---|
1042 | { |
---|
1043 | parseTransformSkipFlags( pcCU, uiAbsPartIdx, uiWidth, uiHeight, uiDepth, eTType); |
---|
1044 | } |
---|
1045 | |
---|
1046 | eTType = eTType == TEXT_LUMA ? TEXT_LUMA : ( eTType == TEXT_NONE ? TEXT_NONE : TEXT_CHROMA ); |
---|
1047 | |
---|
1048 | //----- parse significance map ----- |
---|
1049 | const UInt uiLog2BlockSize = g_aucConvertToBit[ uiWidth ] + 2; |
---|
1050 | const UInt uiMaxNumCoeff = uiWidth * uiHeight; |
---|
1051 | const UInt uiMaxNumCoeffM1 = uiMaxNumCoeff - 1; |
---|
1052 | UInt uiScanIdx = pcCU->getCoefScanIdx(uiAbsPartIdx, uiWidth, eTType==TEXT_LUMA, pcCU->isIntra(uiAbsPartIdx)); |
---|
1053 | |
---|
1054 | //===== decode last significant ===== |
---|
1055 | UInt uiPosLastX, uiPosLastY; |
---|
1056 | parseLastSignificantXY( uiPosLastX, uiPosLastY, uiWidth, uiHeight, eTType, uiScanIdx ); |
---|
1057 | UInt uiBlkPosLast = uiPosLastX + (uiPosLastY<<uiLog2BlockSize); |
---|
1058 | pcCoef[ uiBlkPosLast ] = 1; |
---|
1059 | |
---|
1060 | //===== decode significance flags ===== |
---|
1061 | UInt uiScanPosLast = uiBlkPosLast; |
---|
1062 | const UInt *scan = g_auiSigLastScan[ uiScanIdx ][ uiLog2BlockSize-1 ]; |
---|
1063 | for( uiScanPosLast = 0; uiScanPosLast < uiMaxNumCoeffM1; uiScanPosLast++ ) |
---|
1064 | { |
---|
1065 | UInt uiBlkPos = scan[ uiScanPosLast ]; |
---|
1066 | if( uiBlkPosLast == uiBlkPos ) |
---|
1067 | { |
---|
1068 | break; |
---|
1069 | } |
---|
1070 | } |
---|
1071 | |
---|
1072 | ContextModel * const baseCoeffGroupCtx = m_cCUSigCoeffGroupSCModel.get( 0, eTType ); |
---|
1073 | ContextModel * const baseCtx = (eTType==TEXT_LUMA) ? m_cCUSigSCModel.get( 0, 0 ) : m_cCUSigSCModel.get( 0, 0 ) + NUM_SIG_FLAG_CTX_LUMA; |
---|
1074 | |
---|
1075 | const Int iLastScanSet = uiScanPosLast >> LOG2_SCAN_SET_SIZE; |
---|
1076 | UInt c1 = 1; |
---|
1077 | UInt uiGoRiceParam = 0; |
---|
1078 | |
---|
1079 | Bool beValid; |
---|
1080 | if (pcCU->getCUTransquantBypass(uiAbsPartIdx)) |
---|
1081 | { |
---|
1082 | beValid = false; |
---|
1083 | } |
---|
1084 | else |
---|
1085 | { |
---|
1086 | beValid = pcCU->getSlice()->getPPS()->getSignHideFlag() > 0; |
---|
1087 | } |
---|
1088 | UInt absSum = 0; |
---|
1089 | |
---|
1090 | UInt uiSigCoeffGroupFlag[ MLS_GRP_NUM ]; |
---|
1091 | ::memset( uiSigCoeffGroupFlag, 0, sizeof(UInt) * MLS_GRP_NUM ); |
---|
1092 | const UInt uiNumBlkSide = uiWidth >> (MLS_CG_SIZE >> 1); |
---|
1093 | const UInt * scanCG; |
---|
1094 | { |
---|
1095 | scanCG = g_auiSigLastScan[ uiScanIdx ][ uiLog2BlockSize > 3 ? uiLog2BlockSize-2-1 : 0 ]; |
---|
1096 | if( uiLog2BlockSize == 3 ) |
---|
1097 | { |
---|
1098 | scanCG = g_sigLastScan8x8[ uiScanIdx ]; |
---|
1099 | } |
---|
1100 | else if( uiLog2BlockSize == 5 ) |
---|
1101 | { |
---|
1102 | scanCG = g_sigLastScanCG32x32; |
---|
1103 | } |
---|
1104 | } |
---|
1105 | Int iScanPosSig = (Int) uiScanPosLast; |
---|
1106 | for( Int iSubSet = iLastScanSet; iSubSet >= 0; iSubSet-- ) |
---|
1107 | { |
---|
1108 | Int iSubPos = iSubSet << LOG2_SCAN_SET_SIZE; |
---|
1109 | uiGoRiceParam = 0; |
---|
1110 | Int numNonZero = 0; |
---|
1111 | |
---|
1112 | Int lastNZPosInCG = -1, firstNZPosInCG = SCAN_SET_SIZE; |
---|
1113 | |
---|
1114 | Int pos[SCAN_SET_SIZE]; |
---|
1115 | if( iScanPosSig == (Int) uiScanPosLast ) |
---|
1116 | { |
---|
1117 | lastNZPosInCG = iScanPosSig; |
---|
1118 | firstNZPosInCG = iScanPosSig; |
---|
1119 | iScanPosSig--; |
---|
1120 | pos[ numNonZero ] = uiBlkPosLast; |
---|
1121 | numNonZero = 1; |
---|
1122 | } |
---|
1123 | |
---|
1124 | // decode significant_coeffgroup_flag |
---|
1125 | Int iCGBlkPos = scanCG[ iSubSet ]; |
---|
1126 | Int iCGPosY = iCGBlkPos / uiNumBlkSide; |
---|
1127 | Int iCGPosX = iCGBlkPos - (iCGPosY * uiNumBlkSide); |
---|
1128 | if( iSubSet == iLastScanSet || iSubSet == 0) |
---|
1129 | { |
---|
1130 | uiSigCoeffGroupFlag[ iCGBlkPos ] = 1; |
---|
1131 | } |
---|
1132 | else |
---|
1133 | { |
---|
1134 | UInt uiSigCoeffGroup; |
---|
1135 | UInt uiCtxSig = TComTrQuant::getSigCoeffGroupCtxInc( uiSigCoeffGroupFlag, iCGPosX, iCGPosY, uiWidth, uiHeight ); |
---|
1136 | m_pcTDecBinIf->decodeBin( uiSigCoeffGroup, baseCoeffGroupCtx[ uiCtxSig ] ); |
---|
1137 | uiSigCoeffGroupFlag[ iCGBlkPos ] = uiSigCoeffGroup; |
---|
1138 | } |
---|
1139 | |
---|
1140 | // decode significant_coeff_flag |
---|
1141 | Int patternSigCtx = TComTrQuant::calcPatternSigCtx( uiSigCoeffGroupFlag, iCGPosX, iCGPosY, uiWidth, uiHeight ); |
---|
1142 | UInt uiBlkPos, uiPosY, uiPosX, uiSig, uiCtxSig; |
---|
1143 | for( ; iScanPosSig >= iSubPos; iScanPosSig-- ) |
---|
1144 | { |
---|
1145 | uiBlkPos = scan[ iScanPosSig ]; |
---|
1146 | uiPosY = uiBlkPos >> uiLog2BlockSize; |
---|
1147 | uiPosX = uiBlkPos - ( uiPosY << uiLog2BlockSize ); |
---|
1148 | uiSig = 0; |
---|
1149 | |
---|
1150 | if( uiSigCoeffGroupFlag[ iCGBlkPos ] ) |
---|
1151 | { |
---|
1152 | if( iScanPosSig > iSubPos || iSubSet == 0 || numNonZero ) |
---|
1153 | { |
---|
1154 | uiCtxSig = TComTrQuant::getSigCtxInc( patternSigCtx, uiScanIdx, uiPosX, uiPosY, uiLog2BlockSize, eTType ); |
---|
1155 | m_pcTDecBinIf->decodeBin( uiSig, baseCtx[ uiCtxSig ] ); |
---|
1156 | } |
---|
1157 | else |
---|
1158 | { |
---|
1159 | uiSig = 1; |
---|
1160 | } |
---|
1161 | } |
---|
1162 | pcCoef[ uiBlkPos ] = uiSig; |
---|
1163 | if( uiSig ) |
---|
1164 | { |
---|
1165 | pos[ numNonZero ] = uiBlkPos; |
---|
1166 | numNonZero ++; |
---|
1167 | if( lastNZPosInCG == -1 ) |
---|
1168 | { |
---|
1169 | lastNZPosInCG = iScanPosSig; |
---|
1170 | } |
---|
1171 | firstNZPosInCG = iScanPosSig; |
---|
1172 | } |
---|
1173 | } |
---|
1174 | |
---|
1175 | if( numNonZero ) |
---|
1176 | { |
---|
1177 | Bool signHidden = ( lastNZPosInCG - firstNZPosInCG >= SBH_THRESHOLD ); |
---|
1178 | absSum = 0; |
---|
1179 | UInt uiCtxSet = (iSubSet > 0 && eTType==TEXT_LUMA) ? 2 : 0; |
---|
1180 | UInt uiBin; |
---|
1181 | if( c1 == 0 ) |
---|
1182 | { |
---|
1183 | uiCtxSet++; |
---|
1184 | } |
---|
1185 | c1 = 1; |
---|
1186 | ContextModel *baseCtxMod = ( eTType==TEXT_LUMA ) ? m_cCUOneSCModel.get( 0, 0 ) + 4 * uiCtxSet : m_cCUOneSCModel.get( 0, 0 ) + NUM_ONE_FLAG_CTX_LUMA + 4 * uiCtxSet; |
---|
1187 | Int absCoeff[SCAN_SET_SIZE]; |
---|
1188 | |
---|
1189 | for ( Int i = 0; i < numNonZero; i++) absCoeff[i] = 1; |
---|
1190 | Int numC1Flag = min(numNonZero, C1FLAG_NUMBER); |
---|
1191 | Int firstC2FlagIdx = -1; |
---|
1192 | |
---|
1193 | for( Int idx = 0; idx < numC1Flag; idx++ ) |
---|
1194 | { |
---|
1195 | m_pcTDecBinIf->decodeBin( uiBin, baseCtxMod[c1] ); |
---|
1196 | if( uiBin == 1 ) |
---|
1197 | { |
---|
1198 | c1 = 0; |
---|
1199 | if (firstC2FlagIdx == -1) |
---|
1200 | { |
---|
1201 | firstC2FlagIdx = idx; |
---|
1202 | } |
---|
1203 | } |
---|
1204 | else if( (c1 < 3) && (c1 > 0) ) |
---|
1205 | { |
---|
1206 | c1++; |
---|
1207 | } |
---|
1208 | absCoeff[ idx ] = uiBin + 1; |
---|
1209 | } |
---|
1210 | |
---|
1211 | if (c1 == 0) |
---|
1212 | { |
---|
1213 | baseCtxMod = ( eTType==TEXT_LUMA ) ? m_cCUAbsSCModel.get( 0, 0 ) + uiCtxSet : m_cCUAbsSCModel.get( 0, 0 ) + NUM_ABS_FLAG_CTX_LUMA + uiCtxSet; |
---|
1214 | if ( firstC2FlagIdx != -1) |
---|
1215 | { |
---|
1216 | m_pcTDecBinIf->decodeBin( uiBin, baseCtxMod[0] ); |
---|
1217 | absCoeff[ firstC2FlagIdx ] = uiBin + 2; |
---|
1218 | } |
---|
1219 | } |
---|
1220 | |
---|
1221 | UInt coeffSigns; |
---|
1222 | if ( signHidden && beValid ) |
---|
1223 | { |
---|
1224 | m_pcTDecBinIf->decodeBinsEP( coeffSigns, numNonZero-1 ); |
---|
1225 | coeffSigns <<= 32 - (numNonZero-1); |
---|
1226 | } |
---|
1227 | else |
---|
1228 | { |
---|
1229 | m_pcTDecBinIf->decodeBinsEP( coeffSigns, numNonZero ); |
---|
1230 | coeffSigns <<= 32 - numNonZero; |
---|
1231 | } |
---|
1232 | |
---|
1233 | Int iFirstCoeff2 = 1; |
---|
1234 | if (c1 == 0 || numNonZero > C1FLAG_NUMBER) |
---|
1235 | { |
---|
1236 | for( Int idx = 0; idx < numNonZero; idx++ ) |
---|
1237 | { |
---|
1238 | UInt baseLevel = (idx < C1FLAG_NUMBER)? (2 + iFirstCoeff2) : 1; |
---|
1239 | |
---|
1240 | if( absCoeff[ idx ] == baseLevel) |
---|
1241 | { |
---|
1242 | UInt uiLevel; |
---|
1243 | xReadCoefRemainExGolomb( uiLevel, uiGoRiceParam ); |
---|
1244 | absCoeff[ idx ] = uiLevel + baseLevel; |
---|
1245 | if(absCoeff[idx]>3*(1<<uiGoRiceParam)) |
---|
1246 | { |
---|
1247 | uiGoRiceParam = min<UInt>(uiGoRiceParam+ 1, 4); |
---|
1248 | } |
---|
1249 | } |
---|
1250 | |
---|
1251 | if(absCoeff[ idx ] >= 2) |
---|
1252 | { |
---|
1253 | iFirstCoeff2 = 0; |
---|
1254 | } |
---|
1255 | } |
---|
1256 | } |
---|
1257 | |
---|
1258 | for( Int idx = 0; idx < numNonZero; idx++ ) |
---|
1259 | { |
---|
1260 | Int blkPos = pos[ idx ]; |
---|
1261 | // Signs applied later. |
---|
1262 | pcCoef[ blkPos ] = absCoeff[ idx ]; |
---|
1263 | absSum += absCoeff[ idx ]; |
---|
1264 | |
---|
1265 | if ( idx == numNonZero-1 && signHidden && beValid ) |
---|
1266 | { |
---|
1267 | // Infer sign of 1st element. |
---|
1268 | if (absSum&0x1) |
---|
1269 | { |
---|
1270 | pcCoef[ blkPos ] = -pcCoef[ blkPos ]; |
---|
1271 | } |
---|
1272 | } |
---|
1273 | else |
---|
1274 | { |
---|
1275 | Int sign = static_cast<Int>( coeffSigns ) >> 31; |
---|
1276 | pcCoef[ blkPos ] = ( pcCoef[ blkPos ] ^ sign ) - sign; |
---|
1277 | coeffSigns <<= 1; |
---|
1278 | } |
---|
1279 | } |
---|
1280 | } |
---|
1281 | } |
---|
1282 | |
---|
1283 | return; |
---|
1284 | } |
---|
1285 | |
---|
1286 | |
---|
1287 | Void TDecSbac::parseSaoMaxUvlc ( UInt& val, UInt maxSymbol ) |
---|
1288 | { |
---|
1289 | if (maxSymbol == 0) |
---|
1290 | { |
---|
1291 | val = 0; |
---|
1292 | return; |
---|
1293 | } |
---|
1294 | |
---|
1295 | UInt code; |
---|
1296 | Int i; |
---|
1297 | m_pcTDecBinIf->decodeBinEP( code ); |
---|
1298 | if ( code == 0 ) |
---|
1299 | { |
---|
1300 | val = 0; |
---|
1301 | return; |
---|
1302 | } |
---|
1303 | |
---|
1304 | i=1; |
---|
1305 | while (1) |
---|
1306 | { |
---|
1307 | m_pcTDecBinIf->decodeBinEP( code ); |
---|
1308 | if ( code == 0 ) |
---|
1309 | { |
---|
1310 | break; |
---|
1311 | } |
---|
1312 | i++; |
---|
1313 | if (i == maxSymbol) |
---|
1314 | { |
---|
1315 | break; |
---|
1316 | } |
---|
1317 | } |
---|
1318 | |
---|
1319 | val = i; |
---|
1320 | } |
---|
1321 | Void TDecSbac::parseSaoUflc (UInt uiLength, UInt& riVal) |
---|
1322 | { |
---|
1323 | m_pcTDecBinIf->decodeBinsEP ( riVal, uiLength ); |
---|
1324 | } |
---|
1325 | Void TDecSbac::parseSaoMerge (UInt& ruiVal) |
---|
1326 | { |
---|
1327 | UInt uiCode; |
---|
1328 | m_pcTDecBinIf->decodeBin( uiCode, m_cSaoMergeSCModel.get( 0, 0, 0 ) ); |
---|
1329 | ruiVal = (Int)uiCode; |
---|
1330 | } |
---|
1331 | Void TDecSbac::parseSaoTypeIdx (UInt& ruiVal) |
---|
1332 | { |
---|
1333 | UInt uiCode; |
---|
1334 | m_pcTDecBinIf->decodeBin( uiCode, m_cSaoTypeIdxSCModel.get( 0, 0, 0 ) ); |
---|
1335 | if (uiCode == 0) |
---|
1336 | { |
---|
1337 | ruiVal = 0; |
---|
1338 | } |
---|
1339 | else |
---|
1340 | { |
---|
1341 | m_pcTDecBinIf->decodeBinEP( uiCode ); |
---|
1342 | if (uiCode == 0) |
---|
1343 | { |
---|
1344 | ruiVal = 5; |
---|
1345 | } |
---|
1346 | else |
---|
1347 | { |
---|
1348 | ruiVal = 1; |
---|
1349 | } |
---|
1350 | } |
---|
1351 | } |
---|
1352 | |
---|
1353 | inline Void copySaoOneLcuParam(SaoLcuParam* psDst, SaoLcuParam* psSrc) |
---|
1354 | { |
---|
1355 | Int i; |
---|
1356 | psDst->partIdx = psSrc->partIdx; |
---|
1357 | psDst->typeIdx = psSrc->typeIdx; |
---|
1358 | if (psDst->typeIdx != -1) |
---|
1359 | { |
---|
1360 | psDst->subTypeIdx = psSrc->subTypeIdx ; |
---|
1361 | psDst->length = psSrc->length; |
---|
1362 | for (i=0;i<psDst->length;i++) |
---|
1363 | { |
---|
1364 | psDst->offset[i] = psSrc->offset[i]; |
---|
1365 | } |
---|
1366 | } |
---|
1367 | else |
---|
1368 | { |
---|
1369 | psDst->length = 0; |
---|
1370 | for (i=0;i<SAO_BO_LEN;i++) |
---|
1371 | { |
---|
1372 | psDst->offset[i] = 0; |
---|
1373 | } |
---|
1374 | } |
---|
1375 | } |
---|
1376 | |
---|
1377 | Void TDecSbac::parseSaoOffset(SaoLcuParam* psSaoLcuParam, UInt compIdx) |
---|
1378 | { |
---|
1379 | UInt uiSymbol; |
---|
1380 | static Int iTypeLength[MAX_NUM_SAO_TYPE] = |
---|
1381 | { |
---|
1382 | SAO_EO_LEN, |
---|
1383 | SAO_EO_LEN, |
---|
1384 | SAO_EO_LEN, |
---|
1385 | SAO_EO_LEN, |
---|
1386 | SAO_BO_LEN |
---|
1387 | }; |
---|
1388 | |
---|
1389 | if (compIdx==2) |
---|
1390 | { |
---|
1391 | uiSymbol = (UInt)( psSaoLcuParam->typeIdx + 1); |
---|
1392 | } |
---|
1393 | else |
---|
1394 | { |
---|
1395 | parseSaoTypeIdx(uiSymbol); |
---|
1396 | } |
---|
1397 | psSaoLcuParam->typeIdx = (Int)uiSymbol - 1; |
---|
1398 | if (uiSymbol) |
---|
1399 | { |
---|
1400 | psSaoLcuParam->length = iTypeLength[psSaoLcuParam->typeIdx]; |
---|
1401 | |
---|
1402 | Int bitDepth = compIdx ? g_bitDepthC : g_bitDepthY; |
---|
1403 | Int offsetTh = 1 << min(bitDepth - 5,5); |
---|
1404 | |
---|
1405 | if( psSaoLcuParam->typeIdx == SAO_BO ) |
---|
1406 | { |
---|
1407 | for(Int i=0; i< psSaoLcuParam->length; i++) |
---|
1408 | { |
---|
1409 | parseSaoMaxUvlc(uiSymbol, offsetTh -1 ); |
---|
1410 | psSaoLcuParam->offset[i] = uiSymbol; |
---|
1411 | } |
---|
1412 | for(Int i=0; i< psSaoLcuParam->length; i++) |
---|
1413 | { |
---|
1414 | if (psSaoLcuParam->offset[i] != 0) |
---|
1415 | { |
---|
1416 | m_pcTDecBinIf->decodeBinEP ( uiSymbol); |
---|
1417 | if (uiSymbol) |
---|
1418 | { |
---|
1419 | psSaoLcuParam->offset[i] = -psSaoLcuParam->offset[i] ; |
---|
1420 | } |
---|
1421 | } |
---|
1422 | } |
---|
1423 | parseSaoUflc(5, uiSymbol ); |
---|
1424 | psSaoLcuParam->subTypeIdx = uiSymbol; |
---|
1425 | } |
---|
1426 | else if( psSaoLcuParam->typeIdx < 4 ) |
---|
1427 | { |
---|
1428 | parseSaoMaxUvlc(uiSymbol, offsetTh -1 ); psSaoLcuParam->offset[0] = uiSymbol; |
---|
1429 | parseSaoMaxUvlc(uiSymbol, offsetTh -1 ); psSaoLcuParam->offset[1] = uiSymbol; |
---|
1430 | parseSaoMaxUvlc(uiSymbol, offsetTh -1 ); psSaoLcuParam->offset[2] = -(Int)uiSymbol; |
---|
1431 | parseSaoMaxUvlc(uiSymbol, offsetTh -1 ); psSaoLcuParam->offset[3] = -(Int)uiSymbol; |
---|
1432 | if (compIdx != 2) |
---|
1433 | { |
---|
1434 | parseSaoUflc(2, uiSymbol ); |
---|
1435 | psSaoLcuParam->subTypeIdx = uiSymbol; |
---|
1436 | psSaoLcuParam->typeIdx += psSaoLcuParam->subTypeIdx; |
---|
1437 | } |
---|
1438 | } |
---|
1439 | } |
---|
1440 | else |
---|
1441 | { |
---|
1442 | psSaoLcuParam->length = 0; |
---|
1443 | } |
---|
1444 | } |
---|
1445 | |
---|
1446 | Void TDecSbac::parseSaoOneLcuInterleaving(Int rx, Int ry, SAOParam* pSaoParam, TComDataCU* pcCU, Int iCUAddrInSlice, Int iCUAddrUpInSlice, Int allowMergeLeft, Int allowMergeUp) |
---|
1447 | { |
---|
1448 | Int iAddr = pcCU->getAddr(); |
---|
1449 | UInt uiSymbol; |
---|
1450 | for (Int iCompIdx=0; iCompIdx<3; iCompIdx++) |
---|
1451 | { |
---|
1452 | pSaoParam->saoLcuParam[iCompIdx][iAddr].mergeUpFlag = 0; |
---|
1453 | pSaoParam->saoLcuParam[iCompIdx][iAddr].mergeLeftFlag = 0; |
---|
1454 | pSaoParam->saoLcuParam[iCompIdx][iAddr].subTypeIdx = 0; |
---|
1455 | pSaoParam->saoLcuParam[iCompIdx][iAddr].typeIdx = -1; |
---|
1456 | pSaoParam->saoLcuParam[iCompIdx][iAddr].offset[0] = 0; |
---|
1457 | pSaoParam->saoLcuParam[iCompIdx][iAddr].offset[1] = 0; |
---|
1458 | pSaoParam->saoLcuParam[iCompIdx][iAddr].offset[2] = 0; |
---|
1459 | pSaoParam->saoLcuParam[iCompIdx][iAddr].offset[3] = 0; |
---|
1460 | |
---|
1461 | } |
---|
1462 | if (pSaoParam->bSaoFlag[0] || pSaoParam->bSaoFlag[1] ) |
---|
1463 | { |
---|
1464 | if (rx>0 && iCUAddrInSlice!=0 && allowMergeLeft) |
---|
1465 | { |
---|
1466 | parseSaoMerge(uiSymbol); |
---|
1467 | pSaoParam->saoLcuParam[0][iAddr].mergeLeftFlag = (Bool)uiSymbol; |
---|
1468 | } |
---|
1469 | if (pSaoParam->saoLcuParam[0][iAddr].mergeLeftFlag==0) |
---|
1470 | { |
---|
1471 | if ((ry > 0) && (iCUAddrUpInSlice>=0) && allowMergeUp) |
---|
1472 | { |
---|
1473 | parseSaoMerge(uiSymbol); |
---|
1474 | pSaoParam->saoLcuParam[0][iAddr].mergeUpFlag = (Bool)uiSymbol; |
---|
1475 | } |
---|
1476 | } |
---|
1477 | } |
---|
1478 | |
---|
1479 | for (Int iCompIdx=0; iCompIdx<3; iCompIdx++) |
---|
1480 | { |
---|
1481 | if ((iCompIdx == 0 && pSaoParam->bSaoFlag[0]) || (iCompIdx > 0 && pSaoParam->bSaoFlag[1]) ) |
---|
1482 | { |
---|
1483 | if (rx>0 && iCUAddrInSlice!=0 && allowMergeLeft) |
---|
1484 | { |
---|
1485 | pSaoParam->saoLcuParam[iCompIdx][iAddr].mergeLeftFlag = pSaoParam->saoLcuParam[0][iAddr].mergeLeftFlag; |
---|
1486 | } |
---|
1487 | else |
---|
1488 | { |
---|
1489 | pSaoParam->saoLcuParam[iCompIdx][iAddr].mergeLeftFlag = 0; |
---|
1490 | } |
---|
1491 | |
---|
1492 | if (pSaoParam->saoLcuParam[iCompIdx][iAddr].mergeLeftFlag==0) |
---|
1493 | { |
---|
1494 | if ((ry > 0) && (iCUAddrUpInSlice>=0) && allowMergeUp) |
---|
1495 | { |
---|
1496 | pSaoParam->saoLcuParam[iCompIdx][iAddr].mergeUpFlag = pSaoParam->saoLcuParam[0][iAddr].mergeUpFlag; |
---|
1497 | } |
---|
1498 | else |
---|
1499 | { |
---|
1500 | pSaoParam->saoLcuParam[iCompIdx][iAddr].mergeUpFlag = 0; |
---|
1501 | } |
---|
1502 | if (!pSaoParam->saoLcuParam[iCompIdx][iAddr].mergeUpFlag) |
---|
1503 | { |
---|
1504 | pSaoParam->saoLcuParam[2][iAddr].typeIdx = pSaoParam->saoLcuParam[1][iAddr].typeIdx; |
---|
1505 | parseSaoOffset(&(pSaoParam->saoLcuParam[iCompIdx][iAddr]), iCompIdx); |
---|
1506 | } |
---|
1507 | else |
---|
1508 | { |
---|
1509 | copySaoOneLcuParam(&pSaoParam->saoLcuParam[iCompIdx][iAddr], &pSaoParam->saoLcuParam[iCompIdx][iAddr-pSaoParam->numCuInWidth]); |
---|
1510 | } |
---|
1511 | } |
---|
1512 | else |
---|
1513 | { |
---|
1514 | copySaoOneLcuParam(&pSaoParam->saoLcuParam[iCompIdx][iAddr], &pSaoParam->saoLcuParam[iCompIdx][iAddr-1]); |
---|
1515 | } |
---|
1516 | } |
---|
1517 | else |
---|
1518 | { |
---|
1519 | pSaoParam->saoLcuParam[iCompIdx][iAddr].typeIdx = -1; |
---|
1520 | pSaoParam->saoLcuParam[iCompIdx][iAddr].subTypeIdx = 0; |
---|
1521 | } |
---|
1522 | } |
---|
1523 | } |
---|
1524 | |
---|
1525 | /** |
---|
1526 | - Initialize our contexts from the nominated source. |
---|
1527 | . |
---|
1528 | \param pSrc Contexts to be copied. |
---|
1529 | */ |
---|
1530 | Void TDecSbac::xCopyContextsFrom( TDecSbac* pSrc ) |
---|
1531 | { |
---|
1532 | memcpy(m_contextModels, pSrc->m_contextModels, m_numContextModels*sizeof(m_contextModels[0])); |
---|
1533 | } |
---|
1534 | |
---|
1535 | Void TDecSbac::xCopyFrom( TDecSbac* pSrc ) |
---|
1536 | { |
---|
1537 | m_pcTDecBinIf->copyState( pSrc->m_pcTDecBinIf ); |
---|
1538 | |
---|
1539 | m_uiLastQp = pSrc->m_uiLastQp; |
---|
1540 | xCopyContextsFrom( pSrc ); |
---|
1541 | |
---|
1542 | } |
---|
1543 | |
---|
1544 | Void TDecSbac::load ( TDecSbac* pScr ) |
---|
1545 | { |
---|
1546 | xCopyFrom(pScr); |
---|
1547 | } |
---|
1548 | |
---|
1549 | Void TDecSbac::loadContexts ( TDecSbac* pScr ) |
---|
1550 | { |
---|
1551 | xCopyContextsFrom(pScr); |
---|
1552 | } |
---|
1553 | //! \} |
---|