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 | assert(uiBit); // end_of_sub_stream_one_bit must be equal to 1 |
---|
155 | m_pcTDecBinIf->finish(); |
---|
156 | m_pcBitstream->readOutTrailingBits(); |
---|
157 | m_cCUSplitFlagSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_SPLIT_FLAG ); |
---|
158 | m_cCUSkipFlagSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_SKIP_FLAG ); |
---|
159 | m_cCUMergeFlagExtSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_MERGE_FLAG_EXT ); |
---|
160 | m_cCUMergeIdxExtSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_MERGE_IDX_EXT ); |
---|
161 | m_cCUPartSizeSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_PART_SIZE ); |
---|
162 | m_cCUAMPSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_CU_AMP_POS ); |
---|
163 | m_cCUPredModeSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_PRED_MODE ); |
---|
164 | m_cCUIntraPredSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_INTRA_PRED_MODE ); |
---|
165 | m_cCUChromaPredSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_CHROMA_PRED_MODE ); |
---|
166 | m_cCUInterDirSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_INTER_DIR ); |
---|
167 | m_cCUMvdSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_MVD ); |
---|
168 | m_cCURefPicSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_REF_PIC ); |
---|
169 | m_cCUDeltaQpSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_DQP ); |
---|
170 | m_cCUQtCbfSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_QT_CBF ); |
---|
171 | m_cCUQtRootCbfSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_QT_ROOT_CBF ); |
---|
172 | m_cCUSigCoeffGroupSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_SIG_CG_FLAG ); |
---|
173 | m_cCUSigSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_SIG_FLAG ); |
---|
174 | m_cCuCtxLastX.initBuffer ( eSliceType, iQp, (UChar*)INIT_LAST ); |
---|
175 | m_cCuCtxLastY.initBuffer ( eSliceType, iQp, (UChar*)INIT_LAST ); |
---|
176 | m_cCUOneSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_ONE_FLAG ); |
---|
177 | m_cCUAbsSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_ABS_FLAG ); |
---|
178 | m_cMVPIdxSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_MVP_IDX ); |
---|
179 | m_cSaoMergeSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_SAO_MERGE_FLAG ); |
---|
180 | m_cSaoTypeIdxSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_SAO_TYPE_IDX ); |
---|
181 | m_cCUTransSubdivFlagSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_TRANS_SUBDIV_FLAG ); |
---|
182 | m_cTransformSkipSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_TRANSFORMSKIP_FLAG ); |
---|
183 | m_CUTransquantBypassFlagSCModel.initBuffer( eSliceType, iQp, (UChar*)INIT_CU_TRANSQUANT_BYPASS_FLAG ); |
---|
184 | m_pcTDecBinIf->start(); |
---|
185 | } |
---|
186 | |
---|
187 | Void TDecSbac::parseTerminatingBit( UInt& ruiBit ) |
---|
188 | { |
---|
189 | m_pcTDecBinIf->decodeBinTrm( ruiBit ); |
---|
190 | if ( ruiBit ) |
---|
191 | { |
---|
192 | m_pcTDecBinIf->finish(); |
---|
193 | } |
---|
194 | } |
---|
195 | |
---|
196 | |
---|
197 | Void TDecSbac::xReadUnaryMaxSymbol( UInt& ruiSymbol, ContextModel* pcSCModel, Int iOffset, UInt uiMaxSymbol ) |
---|
198 | { |
---|
199 | if (uiMaxSymbol == 0) |
---|
200 | { |
---|
201 | ruiSymbol = 0; |
---|
202 | return; |
---|
203 | } |
---|
204 | |
---|
205 | m_pcTDecBinIf->decodeBin( ruiSymbol, pcSCModel[0] ); |
---|
206 | |
---|
207 | if( ruiSymbol == 0 || uiMaxSymbol == 1 ) |
---|
208 | { |
---|
209 | return; |
---|
210 | } |
---|
211 | |
---|
212 | UInt uiSymbol = 0; |
---|
213 | UInt uiCont; |
---|
214 | |
---|
215 | do |
---|
216 | { |
---|
217 | m_pcTDecBinIf->decodeBin( uiCont, pcSCModel[ iOffset ] ); |
---|
218 | uiSymbol++; |
---|
219 | } |
---|
220 | while( uiCont && ( uiSymbol < uiMaxSymbol - 1 ) ); |
---|
221 | |
---|
222 | if( uiCont && ( uiSymbol == uiMaxSymbol - 1 ) ) |
---|
223 | { |
---|
224 | uiSymbol++; |
---|
225 | } |
---|
226 | |
---|
227 | ruiSymbol = uiSymbol; |
---|
228 | } |
---|
229 | |
---|
230 | Void TDecSbac::xReadEpExGolomb( UInt& ruiSymbol, UInt uiCount ) |
---|
231 | { |
---|
232 | UInt uiSymbol = 0; |
---|
233 | UInt uiBit = 1; |
---|
234 | |
---|
235 | while( uiBit ) |
---|
236 | { |
---|
237 | m_pcTDecBinIf->decodeBinEP( uiBit ); |
---|
238 | uiSymbol += uiBit << uiCount++; |
---|
239 | } |
---|
240 | |
---|
241 | if ( --uiCount ) |
---|
242 | { |
---|
243 | UInt bins; |
---|
244 | m_pcTDecBinIf->decodeBinsEP( bins, uiCount ); |
---|
245 | uiSymbol += bins; |
---|
246 | } |
---|
247 | |
---|
248 | ruiSymbol = uiSymbol; |
---|
249 | } |
---|
250 | |
---|
251 | Void TDecSbac::xReadUnarySymbol( UInt& ruiSymbol, ContextModel* pcSCModel, Int iOffset ) |
---|
252 | { |
---|
253 | m_pcTDecBinIf->decodeBin( ruiSymbol, pcSCModel[0] ); |
---|
254 | |
---|
255 | if( !ruiSymbol ) |
---|
256 | { |
---|
257 | return; |
---|
258 | } |
---|
259 | |
---|
260 | UInt uiSymbol = 0; |
---|
261 | UInt uiCont; |
---|
262 | |
---|
263 | do |
---|
264 | { |
---|
265 | m_pcTDecBinIf->decodeBin( uiCont, pcSCModel[ iOffset ] ); |
---|
266 | uiSymbol++; |
---|
267 | } |
---|
268 | while( uiCont ); |
---|
269 | |
---|
270 | ruiSymbol = uiSymbol; |
---|
271 | } |
---|
272 | |
---|
273 | |
---|
274 | /** Parsing of coeff_abs_level_remaing |
---|
275 | * \param ruiSymbol reference to coeff_abs_level_remaing |
---|
276 | * \param ruiParam reference to parameter |
---|
277 | * \returns Void |
---|
278 | */ |
---|
279 | Void TDecSbac::xReadCoefRemainExGolomb ( UInt &rSymbol, UInt &rParam ) |
---|
280 | { |
---|
281 | |
---|
282 | UInt prefix = 0; |
---|
283 | UInt codeWord = 0; |
---|
284 | do |
---|
285 | { |
---|
286 | prefix++; |
---|
287 | m_pcTDecBinIf->decodeBinEP( codeWord ); |
---|
288 | } |
---|
289 | while( codeWord); |
---|
290 | codeWord = 1 - codeWord; |
---|
291 | prefix -= codeWord; |
---|
292 | codeWord=0; |
---|
293 | if (prefix < COEF_REMAIN_BIN_REDUCTION ) |
---|
294 | { |
---|
295 | m_pcTDecBinIf->decodeBinsEP(codeWord,rParam); |
---|
296 | rSymbol = (prefix<<rParam) + codeWord; |
---|
297 | } |
---|
298 | else |
---|
299 | { |
---|
300 | m_pcTDecBinIf->decodeBinsEP(codeWord,prefix-COEF_REMAIN_BIN_REDUCTION+rParam); |
---|
301 | rSymbol = (((1<<(prefix-COEF_REMAIN_BIN_REDUCTION))+COEF_REMAIN_BIN_REDUCTION-1)<<rParam)+codeWord; |
---|
302 | } |
---|
303 | } |
---|
304 | |
---|
305 | /** Parse I_PCM information. |
---|
306 | * \param pcCU |
---|
307 | * \param uiAbsPartIdx |
---|
308 | * \param uiDepth |
---|
309 | * \returns Void |
---|
310 | * |
---|
311 | * If I_PCM flag indicates that the CU is I_PCM, parse its PCM alignment bits and codes. |
---|
312 | */ |
---|
313 | Void TDecSbac::parseIPCMInfo ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth ) |
---|
314 | { |
---|
315 | UInt uiSymbol; |
---|
316 | |
---|
317 | m_pcTDecBinIf->decodeBinTrm(uiSymbol); |
---|
318 | |
---|
319 | if (uiSymbol) |
---|
320 | { |
---|
321 | Bool bIpcmFlag = true; |
---|
322 | |
---|
323 | pcCU->setPartSizeSubParts ( SIZE_2Nx2N, uiAbsPartIdx, uiDepth ); |
---|
324 | pcCU->setSizeSubParts ( g_uiMaxCUWidth>>uiDepth, g_uiMaxCUHeight>>uiDepth, uiAbsPartIdx, uiDepth ); |
---|
325 | pcCU->setTrIdxSubParts ( 0, uiAbsPartIdx, uiDepth ); |
---|
326 | pcCU->setIPCMFlagSubParts ( bIpcmFlag, uiAbsPartIdx, uiDepth ); |
---|
327 | |
---|
328 | UInt uiMinCoeffSize = pcCU->getPic()->getMinCUWidth()*pcCU->getPic()->getMinCUHeight(); |
---|
329 | UInt uiLumaOffset = uiMinCoeffSize*uiAbsPartIdx; |
---|
330 | UInt uiChromaOffset = uiLumaOffset>>2; |
---|
331 | |
---|
332 | Pel* piPCMSample; |
---|
333 | UInt uiWidth; |
---|
334 | UInt uiHeight; |
---|
335 | UInt uiSampleBits; |
---|
336 | UInt uiX, uiY; |
---|
337 | |
---|
338 | piPCMSample = pcCU->getPCMSampleY() + uiLumaOffset; |
---|
339 | uiWidth = pcCU->getWidth(uiAbsPartIdx); |
---|
340 | uiHeight = pcCU->getHeight(uiAbsPartIdx); |
---|
341 | uiSampleBits = pcCU->getSlice()->getSPS()->getPCMBitDepthLuma(); |
---|
342 | |
---|
343 | for(uiY = 0; uiY < uiHeight; uiY++) |
---|
344 | { |
---|
345 | for(uiX = 0; uiX < uiWidth; uiX++) |
---|
346 | { |
---|
347 | UInt uiSample; |
---|
348 | m_pcTDecBinIf->xReadPCMCode(uiSampleBits, uiSample); |
---|
349 | piPCMSample[uiX] = uiSample; |
---|
350 | } |
---|
351 | piPCMSample += uiWidth; |
---|
352 | } |
---|
353 | |
---|
354 | piPCMSample = pcCU->getPCMSampleCb() + uiChromaOffset; |
---|
355 | uiWidth = pcCU->getWidth(uiAbsPartIdx)/2; |
---|
356 | uiHeight = pcCU->getHeight(uiAbsPartIdx)/2; |
---|
357 | uiSampleBits = pcCU->getSlice()->getSPS()->getPCMBitDepthChroma(); |
---|
358 | |
---|
359 | for(uiY = 0; uiY < uiHeight; uiY++) |
---|
360 | { |
---|
361 | for(uiX = 0; uiX < uiWidth; uiX++) |
---|
362 | { |
---|
363 | UInt uiSample; |
---|
364 | m_pcTDecBinIf->xReadPCMCode(uiSampleBits, uiSample); |
---|
365 | piPCMSample[uiX] = uiSample; |
---|
366 | } |
---|
367 | piPCMSample += uiWidth; |
---|
368 | } |
---|
369 | |
---|
370 | piPCMSample = pcCU->getPCMSampleCr() + uiChromaOffset; |
---|
371 | uiWidth = pcCU->getWidth(uiAbsPartIdx)/2; |
---|
372 | uiHeight = pcCU->getHeight(uiAbsPartIdx)/2; |
---|
373 | uiSampleBits = pcCU->getSlice()->getSPS()->getPCMBitDepthChroma(); |
---|
374 | |
---|
375 | for(uiY = 0; uiY < uiHeight; uiY++) |
---|
376 | { |
---|
377 | for(uiX = 0; uiX < uiWidth; uiX++) |
---|
378 | { |
---|
379 | UInt uiSample; |
---|
380 | m_pcTDecBinIf->xReadPCMCode(uiSampleBits, uiSample); |
---|
381 | piPCMSample[uiX] = uiSample; |
---|
382 | } |
---|
383 | piPCMSample += uiWidth; |
---|
384 | } |
---|
385 | |
---|
386 | m_pcTDecBinIf->start(); |
---|
387 | } |
---|
388 | } |
---|
389 | |
---|
390 | Void TDecSbac::parseCUTransquantBypassFlag( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth ) |
---|
391 | { |
---|
392 | UInt uiSymbol; |
---|
393 | m_pcTDecBinIf->decodeBin( uiSymbol, m_CUTransquantBypassFlagSCModel.get( 0, 0, 0 ) ); |
---|
394 | pcCU->setCUTransquantBypassSubParts(uiSymbol ? true : false, uiAbsPartIdx, uiDepth); |
---|
395 | } |
---|
396 | |
---|
397 | /** parse skip flag |
---|
398 | * \param pcCU |
---|
399 | * \param uiAbsPartIdx |
---|
400 | * \param uiDepth |
---|
401 | * \returns Void |
---|
402 | */ |
---|
403 | Void TDecSbac::parseSkipFlag( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth ) |
---|
404 | { |
---|
405 | if( pcCU->getSlice()->isIntra() ) |
---|
406 | { |
---|
407 | return; |
---|
408 | } |
---|
409 | |
---|
410 | UInt uiSymbol = 0; |
---|
411 | UInt uiCtxSkip = pcCU->getCtxSkipFlag( uiAbsPartIdx ); |
---|
412 | m_pcTDecBinIf->decodeBin( uiSymbol, m_cCUSkipFlagSCModel.get( 0, 0, uiCtxSkip ) ); |
---|
413 | DTRACE_CABAC_VL( g_nSymbolCounter++ ); |
---|
414 | DTRACE_CABAC_T( "\tSkipFlag" ); |
---|
415 | DTRACE_CABAC_T( "\tuiCtxSkip: "); |
---|
416 | DTRACE_CABAC_V( uiCtxSkip ); |
---|
417 | DTRACE_CABAC_T( "\tuiSymbol: "); |
---|
418 | DTRACE_CABAC_V( uiSymbol ); |
---|
419 | DTRACE_CABAC_T( "\n"); |
---|
420 | |
---|
421 | if( uiSymbol ) |
---|
422 | { |
---|
423 | pcCU->setSkipFlagSubParts( true, uiAbsPartIdx, uiDepth ); |
---|
424 | pcCU->setPredModeSubParts( MODE_INTER, uiAbsPartIdx, uiDepth ); |
---|
425 | pcCU->setPartSizeSubParts( SIZE_2Nx2N, uiAbsPartIdx, uiDepth ); |
---|
426 | pcCU->setSizeSubParts( g_uiMaxCUWidth>>uiDepth, g_uiMaxCUHeight>>uiDepth, uiAbsPartIdx, uiDepth ); |
---|
427 | pcCU->setMergeFlagSubParts( true , uiAbsPartIdx, 0, uiDepth ); |
---|
428 | } |
---|
429 | } |
---|
430 | |
---|
431 | /** parse merge flag |
---|
432 | * \param pcCU |
---|
433 | * \param uiAbsPartIdx |
---|
434 | * \param uiDepth |
---|
435 | * \param uiPUIdx |
---|
436 | * \returns Void |
---|
437 | */ |
---|
438 | Void TDecSbac::parseMergeFlag ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, UInt uiPUIdx ) |
---|
439 | { |
---|
440 | UInt uiSymbol; |
---|
441 | m_pcTDecBinIf->decodeBin( uiSymbol, *m_cCUMergeFlagExtSCModel.get( 0 ) ); |
---|
442 | pcCU->setMergeFlagSubParts( uiSymbol ? true : false, uiAbsPartIdx, uiPUIdx, uiDepth ); |
---|
443 | |
---|
444 | DTRACE_CABAC_VL( g_nSymbolCounter++ ); |
---|
445 | DTRACE_CABAC_T( "\tMergeFlag: " ); |
---|
446 | DTRACE_CABAC_V( uiSymbol ); |
---|
447 | DTRACE_CABAC_T( "\tAddress: " ); |
---|
448 | DTRACE_CABAC_V( pcCU->getAddr() ); |
---|
449 | DTRACE_CABAC_T( "\tuiAbsPartIdx: " ); |
---|
450 | DTRACE_CABAC_V( uiAbsPartIdx ); |
---|
451 | DTRACE_CABAC_T( "\n" ); |
---|
452 | } |
---|
453 | |
---|
454 | Void TDecSbac::parseMergeIndex ( TComDataCU* pcCU, UInt& ruiMergeIndex ) |
---|
455 | { |
---|
456 | UInt uiUnaryIdx = 0; |
---|
457 | UInt uiNumCand = pcCU->getSlice()->getMaxNumMergeCand(); |
---|
458 | if ( uiNumCand > 1 ) |
---|
459 | { |
---|
460 | for( ; uiUnaryIdx < uiNumCand - 1; ++uiUnaryIdx ) |
---|
461 | { |
---|
462 | UInt uiSymbol = 0; |
---|
463 | if ( uiUnaryIdx==0 ) |
---|
464 | { |
---|
465 | m_pcTDecBinIf->decodeBin( uiSymbol, m_cCUMergeIdxExtSCModel.get( 0, 0, 0 ) ); |
---|
466 | } |
---|
467 | else |
---|
468 | { |
---|
469 | m_pcTDecBinIf->decodeBinEP( uiSymbol ); |
---|
470 | } |
---|
471 | if( uiSymbol == 0 ) |
---|
472 | { |
---|
473 | break; |
---|
474 | } |
---|
475 | } |
---|
476 | } |
---|
477 | ruiMergeIndex = uiUnaryIdx; |
---|
478 | |
---|
479 | DTRACE_CABAC_VL( g_nSymbolCounter++ ) |
---|
480 | DTRACE_CABAC_T( "\tparseMergeIndex()" ) |
---|
481 | DTRACE_CABAC_T( "\tuiMRGIdx= " ) |
---|
482 | DTRACE_CABAC_V( ruiMergeIndex ) |
---|
483 | DTRACE_CABAC_T( "\n" ) |
---|
484 | } |
---|
485 | |
---|
486 | Void TDecSbac::parseMVPIdx ( Int& riMVPIdx ) |
---|
487 | { |
---|
488 | UInt uiSymbol; |
---|
489 | xReadUnaryMaxSymbol(uiSymbol, m_cMVPIdxSCModel.get(0), 1, AMVP_MAX_NUM_CANDS-1); |
---|
490 | riMVPIdx = uiSymbol; |
---|
491 | } |
---|
492 | |
---|
493 | Void TDecSbac::parseSplitFlag ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth ) |
---|
494 | { |
---|
495 | if( uiDepth == g_uiMaxCUDepth - g_uiAddCUDepth ) |
---|
496 | { |
---|
497 | pcCU->setDepthSubParts( uiDepth, uiAbsPartIdx ); |
---|
498 | return; |
---|
499 | } |
---|
500 | |
---|
501 | UInt uiSymbol; |
---|
502 | m_pcTDecBinIf->decodeBin( uiSymbol, m_cCUSplitFlagSCModel.get( 0, 0, pcCU->getCtxSplitFlag( uiAbsPartIdx, uiDepth ) ) ); |
---|
503 | DTRACE_CABAC_VL( g_nSymbolCounter++ ) |
---|
504 | DTRACE_CABAC_T( "\tSplitFlag\n" ) |
---|
505 | pcCU->setDepthSubParts( uiDepth + uiSymbol, uiAbsPartIdx ); |
---|
506 | |
---|
507 | return; |
---|
508 | } |
---|
509 | |
---|
510 | /** parse partition size |
---|
511 | * \param pcCU |
---|
512 | * \param uiAbsPartIdx |
---|
513 | * \param uiDepth |
---|
514 | * \returns Void |
---|
515 | */ |
---|
516 | Void TDecSbac::parsePartSize( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth ) |
---|
517 | { |
---|
518 | UInt uiSymbol, uiMode = 0; |
---|
519 | PartSize eMode; |
---|
520 | |
---|
521 | if ( pcCU->isIntra( uiAbsPartIdx ) ) |
---|
522 | { |
---|
523 | uiSymbol = 1; |
---|
524 | if( uiDepth == g_uiMaxCUDepth - g_uiAddCUDepth ) |
---|
525 | { |
---|
526 | m_pcTDecBinIf->decodeBin( uiSymbol, m_cCUPartSizeSCModel.get( 0, 0, 0) ); |
---|
527 | } |
---|
528 | eMode = uiSymbol ? SIZE_2Nx2N : SIZE_NxN; |
---|
529 | UInt uiTrLevel = 0; |
---|
530 | UInt uiWidthInBit = g_aucConvertToBit[pcCU->getWidth(uiAbsPartIdx)]+2; |
---|
531 | UInt uiTrSizeInBit = g_aucConvertToBit[pcCU->getSlice()->getSPS()->getMaxTrSize()]+2; |
---|
532 | uiTrLevel = uiWidthInBit >= uiTrSizeInBit ? uiWidthInBit - uiTrSizeInBit : 0; |
---|
533 | if( eMode == SIZE_NxN ) |
---|
534 | { |
---|
535 | pcCU->setTrIdxSubParts( 1+uiTrLevel, uiAbsPartIdx, uiDepth ); |
---|
536 | } |
---|
537 | else |
---|
538 | { |
---|
539 | pcCU->setTrIdxSubParts( uiTrLevel, uiAbsPartIdx, uiDepth ); |
---|
540 | } |
---|
541 | } |
---|
542 | else |
---|
543 | { |
---|
544 | UInt uiMaxNumBits = 2; |
---|
545 | if( uiDepth == g_uiMaxCUDepth - g_uiAddCUDepth && !( (g_uiMaxCUWidth>>uiDepth) == 8 && (g_uiMaxCUHeight>>uiDepth) == 8 ) ) |
---|
546 | { |
---|
547 | uiMaxNumBits ++; |
---|
548 | } |
---|
549 | for ( UInt ui = 0; ui < uiMaxNumBits; ui++ ) |
---|
550 | { |
---|
551 | m_pcTDecBinIf->decodeBin( uiSymbol, m_cCUPartSizeSCModel.get( 0, 0, ui) ); |
---|
552 | if ( uiSymbol ) |
---|
553 | { |
---|
554 | break; |
---|
555 | } |
---|
556 | uiMode++; |
---|
557 | } |
---|
558 | eMode = (PartSize) uiMode; |
---|
559 | if ( pcCU->getSlice()->getSPS()->getAMPAcc( uiDepth ) ) |
---|
560 | { |
---|
561 | if (eMode == SIZE_2NxN) |
---|
562 | { |
---|
563 | m_pcTDecBinIf->decodeBin(uiSymbol, m_cCUAMPSCModel.get( 0, 0, 0 )); |
---|
564 | if (uiSymbol == 0) |
---|
565 | { |
---|
566 | m_pcTDecBinIf->decodeBinEP(uiSymbol); |
---|
567 | eMode = (uiSymbol == 0? SIZE_2NxnU : SIZE_2NxnD); |
---|
568 | } |
---|
569 | } |
---|
570 | else if (eMode == SIZE_Nx2N) |
---|
571 | { |
---|
572 | m_pcTDecBinIf->decodeBin(uiSymbol, m_cCUAMPSCModel.get( 0, 0, 0 )); |
---|
573 | if (uiSymbol == 0) |
---|
574 | { |
---|
575 | m_pcTDecBinIf->decodeBinEP(uiSymbol); |
---|
576 | eMode = (uiSymbol == 0? SIZE_nLx2N : SIZE_nRx2N); |
---|
577 | } |
---|
578 | } |
---|
579 | } |
---|
580 | } |
---|
581 | pcCU->setPartSizeSubParts( eMode, uiAbsPartIdx, uiDepth ); |
---|
582 | pcCU->setSizeSubParts( g_uiMaxCUWidth>>uiDepth, g_uiMaxCUHeight>>uiDepth, uiAbsPartIdx, uiDepth ); |
---|
583 | } |
---|
584 | |
---|
585 | /** parse prediction mode |
---|
586 | * \param pcCU |
---|
587 | * \param uiAbsPartIdx |
---|
588 | * \param uiDepth |
---|
589 | * \returns Void |
---|
590 | */ |
---|
591 | Void TDecSbac::parsePredMode( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth ) |
---|
592 | { |
---|
593 | if( pcCU->getSlice()->isIntra() ) |
---|
594 | { |
---|
595 | pcCU->setPredModeSubParts( MODE_INTRA, uiAbsPartIdx, uiDepth ); |
---|
596 | return; |
---|
597 | } |
---|
598 | |
---|
599 | UInt uiSymbol; |
---|
600 | Int iPredMode = MODE_INTER; |
---|
601 | m_pcTDecBinIf->decodeBin( uiSymbol, m_cCUPredModeSCModel.get( 0, 0, 0 ) ); |
---|
602 | iPredMode += uiSymbol; |
---|
603 | pcCU->setPredModeSubParts( (PredMode)iPredMode, uiAbsPartIdx, uiDepth ); |
---|
604 | } |
---|
605 | |
---|
606 | Void TDecSbac::parseIntraDirLumaAng ( TComDataCU* pcCU, UInt absPartIdx, UInt depth ) |
---|
607 | { |
---|
608 | PartSize mode = pcCU->getPartitionSize( absPartIdx ); |
---|
609 | UInt partNum = mode==SIZE_NxN?4:1; |
---|
610 | UInt partOffset = ( pcCU->getPic()->getNumPartInCU() >> ( pcCU->getDepth(absPartIdx) << 1 ) ) >> 2; |
---|
611 | UInt mpmPred[4],symbol; |
---|
612 | Int j,intraPredMode; |
---|
613 | if (mode==SIZE_NxN) |
---|
614 | { |
---|
615 | depth++; |
---|
616 | } |
---|
617 | for (j=0;j<partNum;j++) |
---|
618 | { |
---|
619 | m_pcTDecBinIf->decodeBin( symbol, m_cCUIntraPredSCModel.get( 0, 0, 0) ); |
---|
620 | mpmPred[j] = symbol; |
---|
621 | } |
---|
622 | for (j=0;j<partNum;j++) |
---|
623 | { |
---|
624 | Int preds[3] = {-1, -1, -1}; |
---|
625 | Int predNum = pcCU->getIntraDirLumaPredictor(absPartIdx+partOffset*j, preds); |
---|
626 | if (mpmPred[j]) |
---|
627 | { |
---|
628 | m_pcTDecBinIf->decodeBinEP( symbol ); |
---|
629 | if (symbol) |
---|
630 | { |
---|
631 | m_pcTDecBinIf->decodeBinEP( symbol ); |
---|
632 | symbol++; |
---|
633 | } |
---|
634 | intraPredMode = preds[symbol]; |
---|
635 | } |
---|
636 | else |
---|
637 | { |
---|
638 | m_pcTDecBinIf->decodeBinsEP( symbol, 5 ); |
---|
639 | intraPredMode = symbol; |
---|
640 | |
---|
641 | //postponed sorting of MPMs (only in remaining branch) |
---|
642 | if (preds[0] > preds[1]) |
---|
643 | { |
---|
644 | std::swap(preds[0], preds[1]); |
---|
645 | } |
---|
646 | if (preds[0] > preds[2]) |
---|
647 | { |
---|
648 | std::swap(preds[0], preds[2]); |
---|
649 | } |
---|
650 | if (preds[1] > preds[2]) |
---|
651 | { |
---|
652 | std::swap(preds[1], preds[2]); |
---|
653 | } |
---|
654 | for ( Int i = 0; i < predNum; i++ ) |
---|
655 | { |
---|
656 | intraPredMode += ( intraPredMode >= preds[i] ); |
---|
657 | } |
---|
658 | } |
---|
659 | pcCU->setLumaIntraDirSubParts( (UChar)intraPredMode, absPartIdx+partOffset*j, depth ); |
---|
660 | } |
---|
661 | } |
---|
662 | |
---|
663 | Void TDecSbac::parseIntraDirChroma( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth ) |
---|
664 | { |
---|
665 | UInt uiSymbol; |
---|
666 | |
---|
667 | m_pcTDecBinIf->decodeBin( uiSymbol, m_cCUChromaPredSCModel.get( 0, 0, 0 ) ); |
---|
668 | |
---|
669 | if( uiSymbol == 0 ) |
---|
670 | { |
---|
671 | uiSymbol = DM_CHROMA_IDX; |
---|
672 | } |
---|
673 | else |
---|
674 | { |
---|
675 | { |
---|
676 | UInt uiIPredMode; |
---|
677 | m_pcTDecBinIf->decodeBinsEP( uiIPredMode, 2 ); |
---|
678 | UInt uiAllowedChromaDir[ NUM_CHROMA_MODE ]; |
---|
679 | pcCU->getAllowedChromaDir( uiAbsPartIdx, uiAllowedChromaDir ); |
---|
680 | uiSymbol = uiAllowedChromaDir[ uiIPredMode ]; |
---|
681 | } |
---|
682 | } |
---|
683 | pcCU->setChromIntraDirSubParts( uiSymbol, uiAbsPartIdx, uiDepth ); |
---|
684 | return; |
---|
685 | } |
---|
686 | |
---|
687 | Void TDecSbac::parseInterDir( TComDataCU* pcCU, UInt& ruiInterDir, UInt uiAbsPartIdx ) |
---|
688 | { |
---|
689 | UInt uiSymbol; |
---|
690 | const UInt uiCtx = pcCU->getCtxInterDir( uiAbsPartIdx ); |
---|
691 | ContextModel *pCtx = m_cCUInterDirSCModel.get( 0 ); |
---|
692 | uiSymbol = 0; |
---|
693 | if (pcCU->getPartitionSize(uiAbsPartIdx) == SIZE_2Nx2N || pcCU->getHeight(uiAbsPartIdx) != 8 ) |
---|
694 | { |
---|
695 | m_pcTDecBinIf->decodeBin( uiSymbol, *( pCtx + uiCtx ) ); |
---|
696 | } |
---|
697 | |
---|
698 | if( uiSymbol ) |
---|
699 | { |
---|
700 | uiSymbol = 2; |
---|
701 | } |
---|
702 | else |
---|
703 | { |
---|
704 | m_pcTDecBinIf->decodeBin( uiSymbol, *( pCtx + 4 ) ); |
---|
705 | assert(uiSymbol == 0 || uiSymbol == 1); |
---|
706 | } |
---|
707 | |
---|
708 | uiSymbol++; |
---|
709 | ruiInterDir = uiSymbol; |
---|
710 | return; |
---|
711 | } |
---|
712 | |
---|
713 | Void TDecSbac::parseRefFrmIdx( TComDataCU* pcCU, Int& riRefFrmIdx, RefPicList eRefList ) |
---|
714 | { |
---|
715 | UInt uiSymbol; |
---|
716 | { |
---|
717 | ContextModel *pCtx = m_cCURefPicSCModel.get( 0 ); |
---|
718 | m_pcTDecBinIf->decodeBin( uiSymbol, *pCtx ); |
---|
719 | |
---|
720 | if( uiSymbol ) |
---|
721 | { |
---|
722 | UInt uiRefNum = pcCU->getSlice()->getNumRefIdx( eRefList ) - 2; |
---|
723 | pCtx++; |
---|
724 | UInt ui; |
---|
725 | for( ui = 0; ui < uiRefNum; ++ui ) |
---|
726 | { |
---|
727 | if( ui == 0 ) |
---|
728 | { |
---|
729 | m_pcTDecBinIf->decodeBin( uiSymbol, *pCtx ); |
---|
730 | } |
---|
731 | else |
---|
732 | { |
---|
733 | m_pcTDecBinIf->decodeBinEP( uiSymbol ); |
---|
734 | } |
---|
735 | if( uiSymbol == 0 ) |
---|
736 | { |
---|
737 | break; |
---|
738 | } |
---|
739 | } |
---|
740 | uiSymbol = ui + 1; |
---|
741 | } |
---|
742 | riRefFrmIdx = uiSymbol; |
---|
743 | } |
---|
744 | |
---|
745 | return; |
---|
746 | } |
---|
747 | |
---|
748 | Void TDecSbac::parseMvd( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiPartIdx, UInt uiDepth, RefPicList eRefList ) |
---|
749 | { |
---|
750 | UInt uiSymbol; |
---|
751 | UInt uiHorAbs; |
---|
752 | UInt uiVerAbs; |
---|
753 | UInt uiHorSign = 0; |
---|
754 | UInt uiVerSign = 0; |
---|
755 | ContextModel *pCtx = m_cCUMvdSCModel.get( 0 ); |
---|
756 | |
---|
757 | if(pcCU->getSlice()->getMvdL1ZeroFlag() && eRefList == REF_PIC_LIST_1 && pcCU->getInterDir(uiAbsPartIdx)==3) |
---|
758 | { |
---|
759 | uiHorAbs=0; |
---|
760 | uiVerAbs=0; |
---|
761 | } |
---|
762 | else |
---|
763 | { |
---|
764 | m_pcTDecBinIf->decodeBin( uiHorAbs, *pCtx ); |
---|
765 | m_pcTDecBinIf->decodeBin( uiVerAbs, *pCtx ); |
---|
766 | |
---|
767 | const Bool bHorAbsGr0 = uiHorAbs != 0; |
---|
768 | const Bool bVerAbsGr0 = uiVerAbs != 0; |
---|
769 | pCtx++; |
---|
770 | |
---|
771 | if( bHorAbsGr0 ) |
---|
772 | { |
---|
773 | m_pcTDecBinIf->decodeBin( uiSymbol, *pCtx ); |
---|
774 | uiHorAbs += uiSymbol; |
---|
775 | } |
---|
776 | |
---|
777 | if( bVerAbsGr0 ) |
---|
778 | { |
---|
779 | m_pcTDecBinIf->decodeBin( uiSymbol, *pCtx ); |
---|
780 | uiVerAbs += uiSymbol; |
---|
781 | } |
---|
782 | |
---|
783 | if( bHorAbsGr0 ) |
---|
784 | { |
---|
785 | if( 2 == uiHorAbs ) |
---|
786 | { |
---|
787 | xReadEpExGolomb( uiSymbol, 1 ); |
---|
788 | uiHorAbs += uiSymbol; |
---|
789 | } |
---|
790 | |
---|
791 | m_pcTDecBinIf->decodeBinEP( uiHorSign ); |
---|
792 | } |
---|
793 | |
---|
794 | if( bVerAbsGr0 ) |
---|
795 | { |
---|
796 | if( 2 == uiVerAbs ) |
---|
797 | { |
---|
798 | xReadEpExGolomb( uiSymbol, 1 ); |
---|
799 | uiVerAbs += uiSymbol; |
---|
800 | } |
---|
801 | |
---|
802 | m_pcTDecBinIf->decodeBinEP( uiVerSign ); |
---|
803 | } |
---|
804 | |
---|
805 | } |
---|
806 | |
---|
807 | const TComMv cMv( uiHorSign ? -Int( uiHorAbs ): uiHorAbs, uiVerSign ? -Int( uiVerAbs ) : uiVerAbs ); |
---|
808 | pcCU->getCUMvField( eRefList )->setAllMvd( cMv, pcCU->getPartitionSize( uiAbsPartIdx ), uiAbsPartIdx, uiDepth, uiPartIdx ); |
---|
809 | return; |
---|
810 | } |
---|
811 | |
---|
812 | |
---|
813 | Void TDecSbac::parseTransformSubdivFlag( UInt& ruiSubdivFlag, UInt uiLog2TransformBlockSize ) |
---|
814 | { |
---|
815 | m_pcTDecBinIf->decodeBin( ruiSubdivFlag, m_cCUTransSubdivFlagSCModel.get( 0, 0, uiLog2TransformBlockSize ) ); |
---|
816 | DTRACE_CABAC_VL( g_nSymbolCounter++ ) |
---|
817 | DTRACE_CABAC_T( "\tparseTransformSubdivFlag()" ) |
---|
818 | DTRACE_CABAC_T( "\tsymbol=" ) |
---|
819 | DTRACE_CABAC_V( ruiSubdivFlag ) |
---|
820 | DTRACE_CABAC_T( "\tctx=" ) |
---|
821 | DTRACE_CABAC_V( uiLog2TransformBlockSize ) |
---|
822 | DTRACE_CABAC_T( "\n" ) |
---|
823 | } |
---|
824 | |
---|
825 | Void TDecSbac::parseQtRootCbf( UInt uiAbsPartIdx, UInt& uiQtRootCbf ) |
---|
826 | { |
---|
827 | UInt uiSymbol; |
---|
828 | const UInt uiCtx = 0; |
---|
829 | m_pcTDecBinIf->decodeBin( uiSymbol , m_cCUQtRootCbfSCModel.get( 0, 0, uiCtx ) ); |
---|
830 | DTRACE_CABAC_VL( g_nSymbolCounter++ ) |
---|
831 | DTRACE_CABAC_T( "\tparseQtRootCbf()" ) |
---|
832 | DTRACE_CABAC_T( "\tsymbol=" ) |
---|
833 | DTRACE_CABAC_V( uiSymbol ) |
---|
834 | DTRACE_CABAC_T( "\tctx=" ) |
---|
835 | DTRACE_CABAC_V( uiCtx ) |
---|
836 | DTRACE_CABAC_T( "\tuiAbsPartIdx=" ) |
---|
837 | DTRACE_CABAC_V( uiAbsPartIdx ) |
---|
838 | DTRACE_CABAC_T( "\n" ) |
---|
839 | |
---|
840 | uiQtRootCbf = uiSymbol; |
---|
841 | } |
---|
842 | |
---|
843 | Void TDecSbac::parseDeltaQP( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth ) |
---|
844 | { |
---|
845 | Int qp; |
---|
846 | UInt uiDQp; |
---|
847 | Int iDQp; |
---|
848 | |
---|
849 | UInt uiSymbol; |
---|
850 | |
---|
851 | xReadUnaryMaxSymbol (uiDQp, &m_cCUDeltaQpSCModel.get( 0, 0, 0 ), 1, CU_DQP_TU_CMAX); |
---|
852 | |
---|
853 | if( uiDQp >= CU_DQP_TU_CMAX) |
---|
854 | { |
---|
855 | xReadEpExGolomb( uiSymbol, CU_DQP_EG_k ); |
---|
856 | uiDQp+=uiSymbol; |
---|
857 | } |
---|
858 | |
---|
859 | if ( uiDQp > 0 ) |
---|
860 | { |
---|
861 | UInt uiSign; |
---|
862 | #if REPN_FORMAT_IN_VPS |
---|
863 | Int qpBdOffsetY = pcCU->getSlice()->getQpBDOffsetY(); |
---|
864 | #else |
---|
865 | Int qpBdOffsetY = pcCU->getSlice()->getSPS()->getQpBDOffsetY(); |
---|
866 | #endif |
---|
867 | m_pcTDecBinIf->decodeBinEP(uiSign); |
---|
868 | iDQp = uiDQp; |
---|
869 | if(uiSign) |
---|
870 | { |
---|
871 | iDQp = -iDQp; |
---|
872 | } |
---|
873 | qp = (((Int) pcCU->getRefQP( uiAbsPartIdx ) + iDQp + 52 + 2*qpBdOffsetY )%(52+qpBdOffsetY)) - qpBdOffsetY; |
---|
874 | } |
---|
875 | else |
---|
876 | { |
---|
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; |
---|
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 | //! \} |
---|