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-2012, 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_cCUAlfCtrlFlagSCModel ( 1, 1, NUM_ALF_CTRL_FLAG_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
59 | , m_cCUIntraPredSCModel ( 1, 1, NUM_ADI_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
60 | , m_cCUChromaPredSCModel ( 1, 1, NUM_CHROMA_PRED_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
61 | , m_cCUDeltaQpSCModel ( 1, 1, NUM_DELTA_QP_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
62 | , m_cCUInterDirSCModel ( 1, 1, NUM_INTER_DIR_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
63 | , m_cCURefPicSCModel ( 1, 1, NUM_REF_NO_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
64 | , m_cCUMvdSCModel ( 1, 1, NUM_MV_RES_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
65 | , m_cCUQtCbfSCModel ( 1, 2, NUM_QT_CBF_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
66 | , m_cCUTransSubdivFlagSCModel ( 1, 1, NUM_TRANS_SUBDIV_FLAG_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
67 | , m_cCUQtRootCbfSCModel ( 1, 1, NUM_QT_ROOT_CBF_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
68 | , m_cCUSigCoeffGroupSCModel ( 1, 2, NUM_SIG_CG_FLAG_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
69 | , m_cCUSigSCModel ( 1, 1, NUM_SIG_FLAG_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
70 | , m_cCuCtxLastX ( 1, 2, NUM_CTX_LAST_FLAG_XY , m_contextModels + m_numContextModels, m_numContextModels) |
---|
71 | , m_cCuCtxLastY ( 1, 2, NUM_CTX_LAST_FLAG_XY , m_contextModels + m_numContextModels, m_numContextModels) |
---|
72 | , m_cCUOneSCModel ( 1, 1, NUM_ONE_FLAG_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
73 | , m_cCUAbsSCModel ( 1, 1, NUM_ABS_FLAG_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
74 | , m_cMVPIdxSCModel ( 1, 1, NUM_MVP_IDX_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
75 | , m_cALFFlagSCModel ( 1, 1, NUM_ALF_FLAG_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
76 | , m_cALFUvlcSCModel ( 1, 1, NUM_ALF_UVLC_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
77 | , m_cALFSvlcSCModel ( 1, 1, NUM_ALF_SVLC_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
78 | , m_cCUAMPSCModel ( 1, 1, NUM_CU_AMP_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
79 | #if !SAO_ABS_BY_PASS |
---|
80 | , m_cSaoUvlcSCModel ( 1, 1, NUM_SAO_UVLC_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
81 | #endif |
---|
82 | #if SAO_MERGE_ONE_CTX |
---|
83 | , m_cSaoMergeSCModel ( 1, 1, NUM_SAO_MERGE_FLAG_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
84 | #else |
---|
85 | , m_cSaoMergeLeftSCModel ( 1, 1, NUM_SAO_MERGE_LEFT_FLAG_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
86 | , m_cSaoMergeUpSCModel ( 1, 1, NUM_SAO_MERGE_UP_FLAG_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
87 | #endif |
---|
88 | #if INTRA_BL |
---|
89 | , m_cIntraBLPredFlagSCModel (1, 1, NUM_INTRA_BL_PRED_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
90 | #endif |
---|
91 | , m_cSaoTypeIdxSCModel ( 1, 1, NUM_SAO_TYPE_IDX_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
92 | , m_cTransformSkipSCModel ( 1, 2, NUM_TRANSFORMSKIP_FLAG_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
93 | , m_CUTransquantBypassFlagSCModel( 1, 1, NUM_CU_TRANSQUANT_BYPASS_FLAG_CTX, m_contextModels + m_numContextModels, m_numContextModels) |
---|
94 | { |
---|
95 | assert( m_numContextModels <= MAX_NUM_CTX_MOD ); |
---|
96 | #if !REMOVE_FGS |
---|
97 | m_iSliceGranularity = 0; |
---|
98 | #endif |
---|
99 | } |
---|
100 | |
---|
101 | TDecSbac::~TDecSbac() |
---|
102 | { |
---|
103 | } |
---|
104 | |
---|
105 | // ==================================================================================================================== |
---|
106 | // Public member functions |
---|
107 | // ==================================================================================================================== |
---|
108 | |
---|
109 | Void TDecSbac::resetEntropy(TComSlice* pSlice) |
---|
110 | { |
---|
111 | SliceType sliceType = pSlice->getSliceType(); |
---|
112 | Int qp = pSlice->getSliceQp(); |
---|
113 | |
---|
114 | if (pSlice->getPPS()->getCabacInitPresentFlag() && pSlice->getCabacInitFlag()) |
---|
115 | { |
---|
116 | switch (sliceType) |
---|
117 | { |
---|
118 | case P_SLICE: // change initialization table to B_SLICE initialization |
---|
119 | sliceType = B_SLICE; |
---|
120 | break; |
---|
121 | case B_SLICE: // change initialization table to P_SLICE initialization |
---|
122 | sliceType = P_SLICE; |
---|
123 | break; |
---|
124 | default : // should not occur |
---|
125 | assert(0); |
---|
126 | } |
---|
127 | } |
---|
128 | |
---|
129 | m_cCUSplitFlagSCModel.initBuffer ( sliceType, qp, (UChar*)INIT_SPLIT_FLAG ); |
---|
130 | m_cCUSkipFlagSCModel.initBuffer ( sliceType, qp, (UChar*)INIT_SKIP_FLAG ); |
---|
131 | m_cCUMergeFlagExtSCModel.initBuffer ( sliceType, qp, (UChar*)INIT_MERGE_FLAG_EXT ); |
---|
132 | m_cCUMergeIdxExtSCModel.initBuffer ( sliceType, qp, (UChar*)INIT_MERGE_IDX_EXT ); |
---|
133 | m_cCUAlfCtrlFlagSCModel.initBuffer ( sliceType, qp, (UChar*)INIT_ALF_CTRL_FLAG ); |
---|
134 | m_cCUPartSizeSCModel.initBuffer ( sliceType, qp, (UChar*)INIT_PART_SIZE ); |
---|
135 | m_cCUAMPSCModel.initBuffer ( sliceType, qp, (UChar*)INIT_CU_AMP_POS ); |
---|
136 | m_cCUPredModeSCModel.initBuffer ( sliceType, qp, (UChar*)INIT_PRED_MODE ); |
---|
137 | m_cCUIntraPredSCModel.initBuffer ( sliceType, qp, (UChar*)INIT_INTRA_PRED_MODE ); |
---|
138 | m_cCUChromaPredSCModel.initBuffer ( sliceType, qp, (UChar*)INIT_CHROMA_PRED_MODE ); |
---|
139 | m_cCUInterDirSCModel.initBuffer ( sliceType, qp, (UChar*)INIT_INTER_DIR ); |
---|
140 | m_cCUMvdSCModel.initBuffer ( sliceType, qp, (UChar*)INIT_MVD ); |
---|
141 | m_cCURefPicSCModel.initBuffer ( sliceType, qp, (UChar*)INIT_REF_PIC ); |
---|
142 | m_cCUDeltaQpSCModel.initBuffer ( sliceType, qp, (UChar*)INIT_DQP ); |
---|
143 | m_cCUQtCbfSCModel.initBuffer ( sliceType, qp, (UChar*)INIT_QT_CBF ); |
---|
144 | m_cCUQtRootCbfSCModel.initBuffer ( sliceType, qp, (UChar*)INIT_QT_ROOT_CBF ); |
---|
145 | m_cCUSigCoeffGroupSCModel.initBuffer ( sliceType, qp, (UChar*)INIT_SIG_CG_FLAG ); |
---|
146 | m_cCUSigSCModel.initBuffer ( sliceType, qp, (UChar*)INIT_SIG_FLAG ); |
---|
147 | m_cCuCtxLastX.initBuffer ( sliceType, qp, (UChar*)INIT_LAST ); |
---|
148 | m_cCuCtxLastY.initBuffer ( sliceType, qp, (UChar*)INIT_LAST ); |
---|
149 | m_cCUOneSCModel.initBuffer ( sliceType, qp, (UChar*)INIT_ONE_FLAG ); |
---|
150 | m_cCUAbsSCModel.initBuffer ( sliceType, qp, (UChar*)INIT_ABS_FLAG ); |
---|
151 | m_cMVPIdxSCModel.initBuffer ( sliceType, qp, (UChar*)INIT_MVP_IDX ); |
---|
152 | m_cALFFlagSCModel.initBuffer ( sliceType, qp, (UChar*)INIT_ALF_FLAG ); |
---|
153 | m_cALFUvlcSCModel.initBuffer ( sliceType, qp, (UChar*)INIT_ALF_UVLC ); |
---|
154 | m_cALFSvlcSCModel.initBuffer ( sliceType, qp, (UChar*)INIT_ALF_SVLC ); |
---|
155 | #if !SAO_ABS_BY_PASS |
---|
156 | m_cSaoUvlcSCModel.initBuffer ( sliceType, qp, (UChar*)INIT_SAO_UVLC ); |
---|
157 | #endif |
---|
158 | #if SAO_MERGE_ONE_CTX |
---|
159 | m_cSaoMergeSCModel.initBuffer ( sliceType, qp, (UChar*)INIT_SAO_MERGE_FLAG ); |
---|
160 | #else |
---|
161 | m_cSaoMergeLeftSCModel.initBuffer ( sliceType, qp, (UChar*)INIT_SAO_MERGE_LEFT_FLAG ); |
---|
162 | m_cSaoMergeUpSCModel.initBuffer ( sliceType, qp, (UChar*)INIT_SAO_MERGE_UP_FLAG ); |
---|
163 | #endif |
---|
164 | m_cSaoTypeIdxSCModel.initBuffer ( sliceType, qp, (UChar*)INIT_SAO_TYPE_IDX ); |
---|
165 | |
---|
166 | m_cCUTransSubdivFlagSCModel.initBuffer ( sliceType, qp, (UChar*)INIT_TRANS_SUBDIV_FLAG ); |
---|
167 | #if INTRA_BL |
---|
168 | m_cIntraBLPredFlagSCModel.initBuffer ( sliceType, qp, (UChar*)INIT_INTRA_BL_PRED_FLAG ); |
---|
169 | #endif |
---|
170 | m_cTransformSkipSCModel.initBuffer ( sliceType, qp, (UChar*)INIT_TRANSFORMSKIP_FLAG ); |
---|
171 | m_CUTransquantBypassFlagSCModel.initBuffer( sliceType, qp, (UChar*)INIT_CU_TRANSQUANT_BYPASS_FLAG ); |
---|
172 | m_uiLastDQpNonZero = 0; |
---|
173 | |
---|
174 | // new structure |
---|
175 | m_uiLastQp = qp; |
---|
176 | |
---|
177 | m_pcTDecBinIf->start(); |
---|
178 | } |
---|
179 | |
---|
180 | /** The function does the following: Read out terminate bit. Flush CABAC. Byte-align for next tile. |
---|
181 | * Intialize CABAC states. Start CABAC. |
---|
182 | */ |
---|
183 | Void TDecSbac::updateContextTables( SliceType eSliceType, Int iQp ) |
---|
184 | { |
---|
185 | UInt uiBit; |
---|
186 | m_pcTDecBinIf->decodeBinTrm(uiBit); |
---|
187 | m_pcTDecBinIf->finish(); |
---|
188 | m_pcBitstream->readOutTrailingBits(); |
---|
189 | m_cCUSplitFlagSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_SPLIT_FLAG ); |
---|
190 | m_cCUSkipFlagSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_SKIP_FLAG ); |
---|
191 | m_cCUMergeFlagExtSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_MERGE_FLAG_EXT ); |
---|
192 | m_cCUMergeIdxExtSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_MERGE_IDX_EXT ); |
---|
193 | m_cCUAlfCtrlFlagSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_ALF_CTRL_FLAG ); |
---|
194 | m_cCUPartSizeSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_PART_SIZE ); |
---|
195 | m_cCUAMPSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_CU_AMP_POS ); |
---|
196 | m_cCUPredModeSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_PRED_MODE ); |
---|
197 | m_cCUIntraPredSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_INTRA_PRED_MODE ); |
---|
198 | m_cCUChromaPredSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_CHROMA_PRED_MODE ); |
---|
199 | m_cCUInterDirSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_INTER_DIR ); |
---|
200 | m_cCUMvdSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_MVD ); |
---|
201 | m_cCURefPicSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_REF_PIC ); |
---|
202 | m_cCUDeltaQpSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_DQP ); |
---|
203 | m_cCUQtCbfSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_QT_CBF ); |
---|
204 | m_cCUQtRootCbfSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_QT_ROOT_CBF ); |
---|
205 | m_cCUSigCoeffGroupSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_SIG_CG_FLAG ); |
---|
206 | m_cCUSigSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_SIG_FLAG ); |
---|
207 | m_cCuCtxLastX.initBuffer ( eSliceType, iQp, (UChar*)INIT_LAST ); |
---|
208 | m_cCuCtxLastY.initBuffer ( eSliceType, iQp, (UChar*)INIT_LAST ); |
---|
209 | m_cCUOneSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_ONE_FLAG ); |
---|
210 | m_cCUAbsSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_ABS_FLAG ); |
---|
211 | m_cMVPIdxSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_MVP_IDX ); |
---|
212 | m_cALFFlagSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_ALF_FLAG ); |
---|
213 | m_cALFUvlcSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_ALF_UVLC ); |
---|
214 | m_cALFSvlcSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_ALF_SVLC ); |
---|
215 | #if !SAO_ABS_BY_PASS |
---|
216 | m_cSaoUvlcSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_SAO_UVLC ); |
---|
217 | #endif |
---|
218 | #if SAO_MERGE_ONE_CTX |
---|
219 | m_cSaoMergeSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_SAO_MERGE_FLAG ); |
---|
220 | #else |
---|
221 | m_cSaoMergeLeftSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_SAO_MERGE_LEFT_FLAG ); |
---|
222 | m_cSaoMergeUpSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_SAO_MERGE_UP_FLAG ); |
---|
223 | #endif |
---|
224 | m_cSaoTypeIdxSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_SAO_TYPE_IDX ); |
---|
225 | m_cCUTransSubdivFlagSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_TRANS_SUBDIV_FLAG ); |
---|
226 | #if INTRA_BL |
---|
227 | m_cIntraBLPredFlagSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_INTRA_BL_PRED_FLAG ); |
---|
228 | #endif |
---|
229 | m_cTransformSkipSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_TRANSFORMSKIP_FLAG ); |
---|
230 | m_CUTransquantBypassFlagSCModel.initBuffer( eSliceType, iQp, (UChar*)INIT_CU_TRANSQUANT_BYPASS_FLAG ); |
---|
231 | m_pcTDecBinIf->start(); |
---|
232 | } |
---|
233 | |
---|
234 | Void TDecSbac::parseTerminatingBit( UInt& ruiBit ) |
---|
235 | { |
---|
236 | m_pcTDecBinIf->decodeBinTrm( ruiBit ); |
---|
237 | } |
---|
238 | |
---|
239 | |
---|
240 | Void TDecSbac::xReadUnaryMaxSymbol( UInt& ruiSymbol, ContextModel* pcSCModel, Int iOffset, UInt uiMaxSymbol ) |
---|
241 | { |
---|
242 | if (uiMaxSymbol == 0) |
---|
243 | { |
---|
244 | ruiSymbol = 0; |
---|
245 | return; |
---|
246 | } |
---|
247 | |
---|
248 | m_pcTDecBinIf->decodeBin( ruiSymbol, pcSCModel[0] ); |
---|
249 | |
---|
250 | if( ruiSymbol == 0 || uiMaxSymbol == 1 ) |
---|
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 && ( uiSymbol < uiMaxSymbol - 1 ) ); |
---|
264 | |
---|
265 | if( uiCont && ( uiSymbol == uiMaxSymbol - 1 ) ) |
---|
266 | { |
---|
267 | uiSymbol++; |
---|
268 | } |
---|
269 | |
---|
270 | ruiSymbol = uiSymbol; |
---|
271 | } |
---|
272 | |
---|
273 | Void TDecSbac::xReadEpExGolomb( UInt& ruiSymbol, UInt uiCount ) |
---|
274 | { |
---|
275 | UInt uiSymbol = 0; |
---|
276 | UInt uiBit = 1; |
---|
277 | |
---|
278 | while( uiBit ) |
---|
279 | { |
---|
280 | m_pcTDecBinIf->decodeBinEP( uiBit ); |
---|
281 | uiSymbol += uiBit << uiCount++; |
---|
282 | } |
---|
283 | |
---|
284 | if ( --uiCount ) |
---|
285 | { |
---|
286 | UInt bins; |
---|
287 | m_pcTDecBinIf->decodeBinsEP( bins, uiCount ); |
---|
288 | uiSymbol += bins; |
---|
289 | } |
---|
290 | |
---|
291 | ruiSymbol = uiSymbol; |
---|
292 | } |
---|
293 | |
---|
294 | Void TDecSbac::xReadUnarySymbol( UInt& ruiSymbol, ContextModel* pcSCModel, Int iOffset ) |
---|
295 | { |
---|
296 | m_pcTDecBinIf->decodeBin( ruiSymbol, pcSCModel[0] ); |
---|
297 | |
---|
298 | if( !ruiSymbol ) |
---|
299 | { |
---|
300 | return; |
---|
301 | } |
---|
302 | |
---|
303 | UInt uiSymbol = 0; |
---|
304 | UInt uiCont; |
---|
305 | |
---|
306 | do |
---|
307 | { |
---|
308 | m_pcTDecBinIf->decodeBin( uiCont, pcSCModel[ iOffset ] ); |
---|
309 | uiSymbol++; |
---|
310 | } |
---|
311 | while( uiCont ); |
---|
312 | |
---|
313 | ruiSymbol = uiSymbol; |
---|
314 | } |
---|
315 | |
---|
316 | |
---|
317 | /** Parsing of coeff_abs_level_remaing |
---|
318 | * \param ruiSymbol reference to coeff_abs_level_remaing |
---|
319 | * \param ruiParam reference to parameter |
---|
320 | * \returns Void |
---|
321 | */ |
---|
322 | Void TDecSbac::xReadCoefRemainExGolomb ( UInt &rSymbol, UInt &rParam ) |
---|
323 | { |
---|
324 | |
---|
325 | UInt prefix = 0; |
---|
326 | UInt codeWord = 0; |
---|
327 | do |
---|
328 | { |
---|
329 | prefix++; |
---|
330 | m_pcTDecBinIf->decodeBinEP( codeWord ); |
---|
331 | } |
---|
332 | while( codeWord); |
---|
333 | codeWord = 1 - codeWord; |
---|
334 | prefix -= codeWord; |
---|
335 | codeWord=0; |
---|
336 | #if COEF_REMAIN_BIN_REDUCTION |
---|
337 | if (prefix < COEF_REMAIN_BIN_REDUCTION ) |
---|
338 | #else |
---|
339 | if (prefix < 8 ) |
---|
340 | #endif |
---|
341 | { |
---|
342 | m_pcTDecBinIf->decodeBinsEP(codeWord,rParam); |
---|
343 | rSymbol = (prefix<<rParam) + codeWord; |
---|
344 | } |
---|
345 | else |
---|
346 | { |
---|
347 | #if COEF_REMAIN_BIN_REDUCTION |
---|
348 | m_pcTDecBinIf->decodeBinsEP(codeWord,prefix-COEF_REMAIN_BIN_REDUCTION+rParam); |
---|
349 | rSymbol = (((1<<(prefix-COEF_REMAIN_BIN_REDUCTION))+COEF_REMAIN_BIN_REDUCTION-1)<<rParam)+codeWord; |
---|
350 | #else |
---|
351 | m_pcTDecBinIf->decodeBinsEP(codeWord,prefix-8+rParam); |
---|
352 | rSymbol = (((1<<(prefix-8))+8-1)<<rParam)+codeWord; |
---|
353 | #endif |
---|
354 | } |
---|
355 | } |
---|
356 | |
---|
357 | /** Parse I_PCM information. |
---|
358 | * \param pcCU |
---|
359 | * \param uiAbsPartIdx |
---|
360 | * \param uiDepth |
---|
361 | * \returns Void |
---|
362 | * |
---|
363 | * If I_PCM flag indicates that the CU is I_PCM, parse its PCM alignment bits and codes. |
---|
364 | */ |
---|
365 | Void TDecSbac::parseIPCMInfo ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth ) |
---|
366 | { |
---|
367 | UInt uiSymbol; |
---|
368 | Int numSubseqIPCM = 0; |
---|
369 | Bool readPCMSampleFlag = false; |
---|
370 | |
---|
371 | if(pcCU->getNumSucIPCM() > 0) |
---|
372 | { |
---|
373 | readPCMSampleFlag = true; |
---|
374 | } |
---|
375 | else |
---|
376 | { |
---|
377 | m_pcTDecBinIf->decodeBinTrm(uiSymbol); |
---|
378 | |
---|
379 | if (uiSymbol) |
---|
380 | { |
---|
381 | readPCMSampleFlag = true; |
---|
382 | m_pcTDecBinIf->decodeNumSubseqIPCM(numSubseqIPCM); |
---|
383 | pcCU->setNumSucIPCM(numSubseqIPCM + 1); |
---|
384 | m_pcTDecBinIf->decodePCMAlignBits(); |
---|
385 | } |
---|
386 | } |
---|
387 | |
---|
388 | if (readPCMSampleFlag == true) |
---|
389 | { |
---|
390 | Bool bIpcmFlag = true; |
---|
391 | |
---|
392 | pcCU->setPartSizeSubParts ( SIZE_2Nx2N, uiAbsPartIdx, uiDepth ); |
---|
393 | pcCU->setSizeSubParts ( g_uiMaxCUWidth>>uiDepth, g_uiMaxCUHeight>>uiDepth, uiAbsPartIdx, uiDepth ); |
---|
394 | pcCU->setTrIdxSubParts ( 0, uiAbsPartIdx, uiDepth ); |
---|
395 | pcCU->setIPCMFlagSubParts ( bIpcmFlag, uiAbsPartIdx, uiDepth ); |
---|
396 | |
---|
397 | UInt uiMinCoeffSize = pcCU->getPic()->getMinCUWidth()*pcCU->getPic()->getMinCUHeight(); |
---|
398 | UInt uiLumaOffset = uiMinCoeffSize*uiAbsPartIdx; |
---|
399 | UInt uiChromaOffset = uiLumaOffset>>2; |
---|
400 | |
---|
401 | Pel* piPCMSample; |
---|
402 | UInt uiWidth; |
---|
403 | UInt uiHeight; |
---|
404 | UInt uiSampleBits; |
---|
405 | UInt uiX, uiY; |
---|
406 | |
---|
407 | piPCMSample = pcCU->getPCMSampleY() + uiLumaOffset; |
---|
408 | uiWidth = pcCU->getWidth(uiAbsPartIdx); |
---|
409 | uiHeight = pcCU->getHeight(uiAbsPartIdx); |
---|
410 | uiSampleBits = pcCU->getSlice()->getSPS()->getPCMBitDepthLuma(); |
---|
411 | |
---|
412 | for(uiY = 0; uiY < uiHeight; uiY++) |
---|
413 | { |
---|
414 | for(uiX = 0; uiX < uiWidth; uiX++) |
---|
415 | { |
---|
416 | UInt uiSample; |
---|
417 | m_pcTDecBinIf->xReadPCMCode(uiSampleBits, uiSample); |
---|
418 | piPCMSample[uiX] = uiSample; |
---|
419 | } |
---|
420 | piPCMSample += uiWidth; |
---|
421 | } |
---|
422 | |
---|
423 | piPCMSample = pcCU->getPCMSampleCb() + uiChromaOffset; |
---|
424 | uiWidth = pcCU->getWidth(uiAbsPartIdx)/2; |
---|
425 | uiHeight = pcCU->getHeight(uiAbsPartIdx)/2; |
---|
426 | uiSampleBits = pcCU->getSlice()->getSPS()->getPCMBitDepthChroma(); |
---|
427 | |
---|
428 | for(uiY = 0; uiY < uiHeight; uiY++) |
---|
429 | { |
---|
430 | for(uiX = 0; uiX < uiWidth; uiX++) |
---|
431 | { |
---|
432 | UInt uiSample; |
---|
433 | m_pcTDecBinIf->xReadPCMCode(uiSampleBits, uiSample); |
---|
434 | piPCMSample[uiX] = uiSample; |
---|
435 | } |
---|
436 | piPCMSample += uiWidth; |
---|
437 | } |
---|
438 | |
---|
439 | piPCMSample = pcCU->getPCMSampleCr() + uiChromaOffset; |
---|
440 | uiWidth = pcCU->getWidth(uiAbsPartIdx)/2; |
---|
441 | uiHeight = pcCU->getHeight(uiAbsPartIdx)/2; |
---|
442 | uiSampleBits = pcCU->getSlice()->getSPS()->getPCMBitDepthChroma(); |
---|
443 | |
---|
444 | for(uiY = 0; uiY < uiHeight; uiY++) |
---|
445 | { |
---|
446 | for(uiX = 0; uiX < uiWidth; uiX++) |
---|
447 | { |
---|
448 | UInt uiSample; |
---|
449 | m_pcTDecBinIf->xReadPCMCode(uiSampleBits, uiSample); |
---|
450 | piPCMSample[uiX] = uiSample; |
---|
451 | } |
---|
452 | piPCMSample += uiWidth; |
---|
453 | } |
---|
454 | |
---|
455 | pcCU->setNumSucIPCM( pcCU->getNumSucIPCM() - 1); |
---|
456 | if(pcCU->getNumSucIPCM() == 0) |
---|
457 | { |
---|
458 | m_pcTDecBinIf->resetBac(); |
---|
459 | } |
---|
460 | } |
---|
461 | } |
---|
462 | |
---|
463 | Void TDecSbac::parseCUTransquantBypassFlag( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth ) |
---|
464 | { |
---|
465 | UInt uiSymbol; |
---|
466 | m_pcTDecBinIf->decodeBin( uiSymbol, m_CUTransquantBypassFlagSCModel.get( 0, 0, 0 ) ); |
---|
467 | pcCU->setCUTransquantBypassSubParts(uiSymbol ? true : false, uiAbsPartIdx, uiDepth); |
---|
468 | } |
---|
469 | |
---|
470 | /** parse skip flag |
---|
471 | * \param pcCU |
---|
472 | * \param uiAbsPartIdx |
---|
473 | * \param uiDepth |
---|
474 | * \returns Void |
---|
475 | */ |
---|
476 | Void TDecSbac::parseSkipFlag( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth ) |
---|
477 | { |
---|
478 | if( pcCU->getSlice()->isIntra() ) |
---|
479 | { |
---|
480 | return; |
---|
481 | } |
---|
482 | |
---|
483 | UInt uiSymbol = 0; |
---|
484 | UInt uiCtxSkip = pcCU->getCtxSkipFlag( uiAbsPartIdx ); |
---|
485 | m_pcTDecBinIf->decodeBin( uiSymbol, m_cCUSkipFlagSCModel.get( 0, 0, uiCtxSkip ) ); |
---|
486 | DTRACE_CABAC_VL( g_nSymbolCounter++ ); |
---|
487 | DTRACE_CABAC_T( "\tSkipFlag" ); |
---|
488 | DTRACE_CABAC_T( "\tuiCtxSkip: "); |
---|
489 | DTRACE_CABAC_V( uiCtxSkip ); |
---|
490 | DTRACE_CABAC_T( "\tuiSymbol: "); |
---|
491 | DTRACE_CABAC_V( uiSymbol ); |
---|
492 | DTRACE_CABAC_T( "\n"); |
---|
493 | |
---|
494 | if( uiSymbol ) |
---|
495 | { |
---|
496 | #if SKIP_FLAG |
---|
497 | pcCU->setSkipFlagSubParts( true, uiAbsPartIdx, uiDepth ); |
---|
498 | #endif |
---|
499 | pcCU->setPredModeSubParts( MODE_INTER, uiAbsPartIdx, uiDepth ); |
---|
500 | pcCU->setPartSizeSubParts( SIZE_2Nx2N, uiAbsPartIdx, uiDepth ); |
---|
501 | pcCU->setSizeSubParts( g_uiMaxCUWidth>>uiDepth, g_uiMaxCUHeight>>uiDepth, uiAbsPartIdx, uiDepth ); |
---|
502 | pcCU->setMergeFlagSubParts( true , uiAbsPartIdx, 0, uiDepth ); |
---|
503 | } |
---|
504 | } |
---|
505 | |
---|
506 | #if INTRA_BL |
---|
507 | Void TDecSbac::parseIntraBLFlag( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiPartIdx, UInt uiDepth ) |
---|
508 | { |
---|
509 | if( pcCU->getLayerId() == 0 ) |
---|
510 | { |
---|
511 | return; |
---|
512 | } |
---|
513 | |
---|
514 | UInt uiSymbol = 0; |
---|
515 | |
---|
516 | UInt uiCtxIntraBL = pcCU->getCtxIntraBLFlag( uiAbsPartIdx ) ; |
---|
517 | m_pcTDecBinIf->decodeBin( uiSymbol, m_cIntraBLPredFlagSCModel.get( 0, 0, uiCtxIntraBL )); |
---|
518 | DTRACE_CABAC_VL( g_nSymbolCounter++ ); |
---|
519 | DTRACE_CABAC_T( "\tIntrBLFlag" ); |
---|
520 | DTRACE_CABAC_T( "\tuiSymbol: "); |
---|
521 | DTRACE_CABAC_V( uiSymbol ); |
---|
522 | DTRACE_CABAC_T( "\n"); |
---|
523 | |
---|
524 | if ( uiSymbol ) |
---|
525 | { |
---|
526 | pcCU->setPartSizeSubParts( SIZE_2Nx2N, uiAbsPartIdx, uiDepth ); |
---|
527 | pcCU->setPredModeSubParts( MODE_INTRA_BL, uiAbsPartIdx, uiDepth ); |
---|
528 | pcCU->setTrIdxSubParts( 0, uiAbsPartIdx, uiDepth ); |
---|
529 | pcCU->setLumaIntraDirSubParts ( DC_IDX, uiAbsPartIdx, uiDepth ); |
---|
530 | } |
---|
531 | } |
---|
532 | #endif |
---|
533 | |
---|
534 | /** parse merge flag |
---|
535 | * \param pcCU |
---|
536 | * \param uiAbsPartIdx |
---|
537 | * \param uiDepth |
---|
538 | * \param uiPUIdx |
---|
539 | * \returns Void |
---|
540 | */ |
---|
541 | Void TDecSbac::parseMergeFlag ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, UInt uiPUIdx ) |
---|
542 | { |
---|
543 | UInt uiSymbol; |
---|
544 | m_pcTDecBinIf->decodeBin( uiSymbol, *m_cCUMergeFlagExtSCModel.get( 0 ) ); |
---|
545 | pcCU->setMergeFlagSubParts( uiSymbol ? true : false, uiAbsPartIdx, uiPUIdx, uiDepth ); |
---|
546 | |
---|
547 | DTRACE_CABAC_VL( g_nSymbolCounter++ ); |
---|
548 | DTRACE_CABAC_T( "\tMergeFlag: " ); |
---|
549 | DTRACE_CABAC_V( uiSymbol ); |
---|
550 | DTRACE_CABAC_T( "\tAddress: " ); |
---|
551 | DTRACE_CABAC_V( pcCU->getAddr() ); |
---|
552 | DTRACE_CABAC_T( "\tuiAbsPartIdx: " ); |
---|
553 | DTRACE_CABAC_V( uiAbsPartIdx ); |
---|
554 | DTRACE_CABAC_T( "\n" ); |
---|
555 | } |
---|
556 | |
---|
557 | Void TDecSbac::parseMergeIndex ( TComDataCU* pcCU, UInt& ruiMergeIndex, UInt uiAbsPartIdx, UInt uiDepth ) |
---|
558 | { |
---|
559 | UInt uiUnaryIdx = 0; |
---|
560 | UInt uiNumCand = pcCU->getSlice()->getMaxNumMergeCand(); |
---|
561 | if ( uiNumCand > 1 ) |
---|
562 | { |
---|
563 | for( ; uiUnaryIdx < uiNumCand - 1; ++uiUnaryIdx ) |
---|
564 | { |
---|
565 | UInt uiSymbol = 0; |
---|
566 | if ( uiUnaryIdx==0 ) |
---|
567 | { |
---|
568 | m_pcTDecBinIf->decodeBin( uiSymbol, m_cCUMergeIdxExtSCModel.get( 0, 0, 0 ) ); |
---|
569 | } |
---|
570 | else |
---|
571 | { |
---|
572 | m_pcTDecBinIf->decodeBinEP( uiSymbol ); |
---|
573 | } |
---|
574 | if( uiSymbol == 0 ) |
---|
575 | { |
---|
576 | break; |
---|
577 | } |
---|
578 | } |
---|
579 | } |
---|
580 | ruiMergeIndex = uiUnaryIdx; |
---|
581 | |
---|
582 | DTRACE_CABAC_VL( g_nSymbolCounter++ ) |
---|
583 | DTRACE_CABAC_T( "\tparseMergeIndex()" ) |
---|
584 | DTRACE_CABAC_T( "\tuiMRGIdx= " ) |
---|
585 | DTRACE_CABAC_V( ruiMergeIndex ) |
---|
586 | DTRACE_CABAC_T( "\n" ) |
---|
587 | } |
---|
588 | |
---|
589 | Void TDecSbac::parseMVPIdx ( Int& riMVPIdx ) |
---|
590 | { |
---|
591 | UInt uiSymbol; |
---|
592 | xReadUnaryMaxSymbol(uiSymbol, m_cMVPIdxSCModel.get(0), 1, AMVP_MAX_NUM_CANDS-1); |
---|
593 | riMVPIdx = uiSymbol; |
---|
594 | } |
---|
595 | |
---|
596 | Void TDecSbac::parseSplitFlag ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth ) |
---|
597 | { |
---|
598 | if( uiDepth == g_uiMaxCUDepth - g_uiAddCUDepth ) |
---|
599 | { |
---|
600 | pcCU->setDepthSubParts( uiDepth, uiAbsPartIdx ); |
---|
601 | return; |
---|
602 | } |
---|
603 | |
---|
604 | UInt uiSymbol; |
---|
605 | m_pcTDecBinIf->decodeBin( uiSymbol, m_cCUSplitFlagSCModel.get( 0, 0, pcCU->getCtxSplitFlag( uiAbsPartIdx, uiDepth ) ) ); |
---|
606 | DTRACE_CABAC_VL( g_nSymbolCounter++ ) |
---|
607 | DTRACE_CABAC_T( "\tSplitFlag\n" ) |
---|
608 | pcCU->setDepthSubParts( uiDepth + uiSymbol, uiAbsPartIdx ); |
---|
609 | |
---|
610 | return; |
---|
611 | } |
---|
612 | |
---|
613 | /** parse partition size |
---|
614 | * \param pcCU |
---|
615 | * \param uiAbsPartIdx |
---|
616 | * \param uiDepth |
---|
617 | * \returns Void |
---|
618 | */ |
---|
619 | Void TDecSbac::parsePartSize( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth ) |
---|
620 | { |
---|
621 | UInt uiSymbol, uiMode = 0; |
---|
622 | PartSize eMode; |
---|
623 | |
---|
624 | #if INTRA_BL |
---|
625 | if ( pcCU->isIntraBL( uiAbsPartIdx ) ) |
---|
626 | { |
---|
627 | assert( 0 ); |
---|
628 | } |
---|
629 | #endif |
---|
630 | if ( pcCU->isIntra( uiAbsPartIdx ) ) |
---|
631 | { |
---|
632 | uiSymbol = 1; |
---|
633 | if( uiDepth == g_uiMaxCUDepth - g_uiAddCUDepth ) |
---|
634 | { |
---|
635 | m_pcTDecBinIf->decodeBin( uiSymbol, m_cCUPartSizeSCModel.get( 0, 0, 0) ); |
---|
636 | } |
---|
637 | eMode = uiSymbol ? SIZE_2Nx2N : SIZE_NxN; |
---|
638 | UInt uiTrLevel = 0; |
---|
639 | UInt uiWidthInBit = g_aucConvertToBit[pcCU->getWidth(uiAbsPartIdx)]+2; |
---|
640 | UInt uiTrSizeInBit = g_aucConvertToBit[pcCU->getSlice()->getSPS()->getMaxTrSize()]+2; |
---|
641 | uiTrLevel = uiWidthInBit >= uiTrSizeInBit ? uiWidthInBit - uiTrSizeInBit : 0; |
---|
642 | if( eMode == SIZE_NxN ) |
---|
643 | { |
---|
644 | pcCU->setTrIdxSubParts( 1+uiTrLevel, uiAbsPartIdx, uiDepth ); |
---|
645 | } |
---|
646 | else |
---|
647 | { |
---|
648 | pcCU->setTrIdxSubParts( uiTrLevel, uiAbsPartIdx, uiDepth ); |
---|
649 | } |
---|
650 | } |
---|
651 | else |
---|
652 | { |
---|
653 | UInt uiMaxNumBits = 2; |
---|
654 | if( uiDepth == g_uiMaxCUDepth - g_uiAddCUDepth && !( (g_uiMaxCUWidth>>uiDepth) == 8 && (g_uiMaxCUHeight>>uiDepth) == 8 ) ) |
---|
655 | { |
---|
656 | uiMaxNumBits ++; |
---|
657 | } |
---|
658 | for ( UInt ui = 0; ui < uiMaxNumBits; ui++ ) |
---|
659 | { |
---|
660 | m_pcTDecBinIf->decodeBin( uiSymbol, m_cCUPartSizeSCModel.get( 0, 0, ui) ); |
---|
661 | if ( uiSymbol ) |
---|
662 | { |
---|
663 | break; |
---|
664 | } |
---|
665 | uiMode++; |
---|
666 | } |
---|
667 | eMode = (PartSize) uiMode; |
---|
668 | if ( pcCU->getSlice()->getSPS()->getAMPAcc( uiDepth ) ) |
---|
669 | { |
---|
670 | if (eMode == SIZE_2NxN) |
---|
671 | { |
---|
672 | m_pcTDecBinIf->decodeBin(uiSymbol, m_cCUAMPSCModel.get( 0, 0, 0 )); |
---|
673 | if (uiSymbol == 0) |
---|
674 | { |
---|
675 | m_pcTDecBinIf->decodeBinEP(uiSymbol); |
---|
676 | eMode = (uiSymbol == 0? SIZE_2NxnU : SIZE_2NxnD); |
---|
677 | } |
---|
678 | } |
---|
679 | else if (eMode == SIZE_Nx2N) |
---|
680 | { |
---|
681 | m_pcTDecBinIf->decodeBin(uiSymbol, m_cCUAMPSCModel.get( 0, 0, 0 )); |
---|
682 | if (uiSymbol == 0) |
---|
683 | { |
---|
684 | m_pcTDecBinIf->decodeBinEP(uiSymbol); |
---|
685 | eMode = (uiSymbol == 0? SIZE_nLx2N : SIZE_nRx2N); |
---|
686 | } |
---|
687 | } |
---|
688 | } |
---|
689 | } |
---|
690 | pcCU->setPartSizeSubParts( eMode, uiAbsPartIdx, uiDepth ); |
---|
691 | pcCU->setSizeSubParts( g_uiMaxCUWidth>>uiDepth, g_uiMaxCUHeight>>uiDepth, uiAbsPartIdx, uiDepth ); |
---|
692 | } |
---|
693 | |
---|
694 | /** parse prediction mode |
---|
695 | * \param pcCU |
---|
696 | * \param uiAbsPartIdx |
---|
697 | * \param uiDepth |
---|
698 | * \returns Void |
---|
699 | */ |
---|
700 | Void TDecSbac::parsePredMode( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth ) |
---|
701 | { |
---|
702 | if( pcCU->getSlice()->isIntra() ) |
---|
703 | { |
---|
704 | pcCU->setPredModeSubParts( MODE_INTRA, uiAbsPartIdx, uiDepth ); |
---|
705 | return; |
---|
706 | } |
---|
707 | |
---|
708 | UInt uiSymbol; |
---|
709 | Int iPredMode = MODE_INTER; |
---|
710 | m_pcTDecBinIf->decodeBin( uiSymbol, m_cCUPredModeSCModel.get( 0, 0, 0 ) ); |
---|
711 | iPredMode += uiSymbol; |
---|
712 | pcCU->setPredModeSubParts( (PredMode)iPredMode, uiAbsPartIdx, uiDepth ); |
---|
713 | } |
---|
714 | |
---|
715 | Void TDecSbac::parseIntraDirLumaAng ( TComDataCU* pcCU, UInt absPartIdx, UInt depth ) |
---|
716 | { |
---|
717 | PartSize mode = pcCU->getPartitionSize( absPartIdx ); |
---|
718 | UInt partNum = mode==SIZE_NxN?4:1; |
---|
719 | UInt partOffset = ( pcCU->getPic()->getNumPartInCU() >> ( pcCU->getDepth(absPartIdx) << 1 ) ) >> 2; |
---|
720 | UInt mpmPred[4],symbol; |
---|
721 | Int j,intraPredMode; |
---|
722 | if (mode==SIZE_NxN) |
---|
723 | { |
---|
724 | depth++; |
---|
725 | } |
---|
726 | for (j=0;j<partNum;j++) |
---|
727 | { |
---|
728 | m_pcTDecBinIf->decodeBin( symbol, m_cCUIntraPredSCModel.get( 0, 0, 0) ); |
---|
729 | mpmPred[j] = symbol; |
---|
730 | } |
---|
731 | for (j=0;j<partNum;j++) |
---|
732 | { |
---|
733 | Int preds[3] = {-1, -1, -1}; |
---|
734 | Int predNum = pcCU->getIntraDirLumaPredictor(absPartIdx+partOffset*j, preds); |
---|
735 | if (mpmPred[j]) |
---|
736 | { |
---|
737 | m_pcTDecBinIf->decodeBinEP( symbol ); |
---|
738 | if (symbol) |
---|
739 | { |
---|
740 | m_pcTDecBinIf->decodeBinEP( symbol ); |
---|
741 | symbol++; |
---|
742 | } |
---|
743 | intraPredMode = preds[symbol]; |
---|
744 | } |
---|
745 | else |
---|
746 | { |
---|
747 | intraPredMode = 0; |
---|
748 | m_pcTDecBinIf->decodeBinsEP( symbol, 5 ); |
---|
749 | intraPredMode = symbol; |
---|
750 | |
---|
751 | //postponed sorting of MPMs (only in remaining branch) |
---|
752 | if (preds[0] > preds[1]) |
---|
753 | { |
---|
754 | std::swap(preds[0], preds[1]); |
---|
755 | } |
---|
756 | if (preds[0] > preds[2]) |
---|
757 | { |
---|
758 | std::swap(preds[0], preds[2]); |
---|
759 | } |
---|
760 | if (preds[1] > preds[2]) |
---|
761 | { |
---|
762 | std::swap(preds[1], preds[2]); |
---|
763 | } |
---|
764 | for ( Int i = 0; i < predNum; i++ ) |
---|
765 | { |
---|
766 | intraPredMode += ( intraPredMode >= preds[i] ); |
---|
767 | } |
---|
768 | } |
---|
769 | pcCU->setLumaIntraDirSubParts( (UChar)intraPredMode, absPartIdx+partOffset*j, depth ); |
---|
770 | } |
---|
771 | } |
---|
772 | |
---|
773 | Void TDecSbac::parseIntraDirChroma( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth ) |
---|
774 | { |
---|
775 | UInt uiSymbol; |
---|
776 | |
---|
777 | m_pcTDecBinIf->decodeBin( uiSymbol, m_cCUChromaPredSCModel.get( 0, 0, 0 ) ); |
---|
778 | |
---|
779 | if( uiSymbol == 0 ) |
---|
780 | { |
---|
781 | uiSymbol = DM_CHROMA_IDX; |
---|
782 | } |
---|
783 | else |
---|
784 | { |
---|
785 | #if !REMOVE_LMCHROMA |
---|
786 | if( pcCU->getSlice()->getSPS()->getUseLMChroma() ) |
---|
787 | { |
---|
788 | m_pcTDecBinIf->decodeBin( uiSymbol, m_cCUChromaPredSCModel.get( 0, 0, 1 ) ); |
---|
789 | } |
---|
790 | else |
---|
791 | { |
---|
792 | uiSymbol = 1; |
---|
793 | } |
---|
794 | |
---|
795 | if( uiSymbol == 0 ) |
---|
796 | { |
---|
797 | uiSymbol = LM_CHROMA_IDX; |
---|
798 | } |
---|
799 | else |
---|
800 | #endif |
---|
801 | { |
---|
802 | UInt uiIPredMode; |
---|
803 | m_pcTDecBinIf->decodeBinsEP( uiIPredMode, 2 ); |
---|
804 | UInt uiAllowedChromaDir[ NUM_CHROMA_MODE ]; |
---|
805 | pcCU->getAllowedChromaDir( uiAbsPartIdx, uiAllowedChromaDir ); |
---|
806 | uiSymbol = uiAllowedChromaDir[ uiIPredMode ]; |
---|
807 | } |
---|
808 | } |
---|
809 | pcCU->setChromIntraDirSubParts( uiSymbol, uiAbsPartIdx, uiDepth ); |
---|
810 | return; |
---|
811 | } |
---|
812 | |
---|
813 | Void TDecSbac::parseInterDir( TComDataCU* pcCU, UInt& ruiInterDir, UInt uiAbsPartIdx, UInt uiDepth ) |
---|
814 | { |
---|
815 | UInt uiSymbol; |
---|
816 | const UInt uiCtx = pcCU->getCtxInterDir( uiAbsPartIdx ); |
---|
817 | ContextModel *pCtx = m_cCUInterDirSCModel.get( 0 ); |
---|
818 | #if DISALLOW_BIPRED_IN_8x4_4x8PUS |
---|
819 | uiSymbol = 0; |
---|
820 | if (pcCU->getPartitionSize(uiAbsPartIdx) == SIZE_2Nx2N || pcCU->getHeight(uiAbsPartIdx) != 8 ) |
---|
821 | { |
---|
822 | #endif |
---|
823 | m_pcTDecBinIf->decodeBin( uiSymbol, *( pCtx + uiCtx ) ); |
---|
824 | #if DISALLOW_BIPRED_IN_8x4_4x8PUS |
---|
825 | } |
---|
826 | #endif |
---|
827 | |
---|
828 | if( uiSymbol ) |
---|
829 | { |
---|
830 | uiSymbol = 2; |
---|
831 | } |
---|
832 | else |
---|
833 | { |
---|
834 | m_pcTDecBinIf->decodeBin( uiSymbol, *( pCtx + 4 ) ); |
---|
835 | assert(uiSymbol == 0 || uiSymbol == 1); |
---|
836 | } |
---|
837 | |
---|
838 | uiSymbol++; |
---|
839 | ruiInterDir = uiSymbol; |
---|
840 | return; |
---|
841 | } |
---|
842 | |
---|
843 | Void TDecSbac::parseRefFrmIdx( TComDataCU* pcCU, Int& riRefFrmIdx, UInt uiAbsPartIdx, UInt uiDepth, RefPicList eRefList ) |
---|
844 | { |
---|
845 | UInt uiSymbol; |
---|
846 | { |
---|
847 | ContextModel *pCtx = m_cCURefPicSCModel.get( 0 ); |
---|
848 | m_pcTDecBinIf->decodeBin( uiSymbol, *pCtx ); |
---|
849 | |
---|
850 | if( uiSymbol ) |
---|
851 | { |
---|
852 | #if REF_IDX_BYPASS |
---|
853 | UInt uiRefNum = pcCU->getSlice()->getNumRefIdx( eRefList ) - 2; |
---|
854 | pCtx++; |
---|
855 | UInt ui; |
---|
856 | for( ui = 0; ui < uiRefNum; ++ui ) |
---|
857 | { |
---|
858 | if( ui == 0 ) |
---|
859 | { |
---|
860 | m_pcTDecBinIf->decodeBin( uiSymbol, *pCtx ); |
---|
861 | } |
---|
862 | else |
---|
863 | { |
---|
864 | m_pcTDecBinIf->decodeBinEP( uiSymbol ); |
---|
865 | } |
---|
866 | if( uiSymbol == 0 ) |
---|
867 | { |
---|
868 | break; |
---|
869 | } |
---|
870 | } |
---|
871 | uiSymbol = ui + 1; |
---|
872 | #else |
---|
873 | xReadUnaryMaxSymbol( uiSymbol, pCtx + 1, 1, pcCU->getSlice()->getNumRefIdx( eRefList )-2 ); |
---|
874 | uiSymbol++; |
---|
875 | #endif |
---|
876 | } |
---|
877 | riRefFrmIdx = uiSymbol; |
---|
878 | } |
---|
879 | |
---|
880 | return; |
---|
881 | } |
---|
882 | |
---|
883 | Void TDecSbac::parseMvd( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiPartIdx, UInt uiDepth, RefPicList eRefList ) |
---|
884 | { |
---|
885 | UInt uiSymbol; |
---|
886 | UInt uiHorAbs; |
---|
887 | UInt uiVerAbs; |
---|
888 | UInt uiHorSign = 0; |
---|
889 | UInt uiVerSign = 0; |
---|
890 | ContextModel *pCtx = m_cCUMvdSCModel.get( 0 ); |
---|
891 | |
---|
892 | if(pcCU->getSlice()->getMvdL1ZeroFlag() && eRefList == REF_PIC_LIST_1 && pcCU->getInterDir(uiAbsPartIdx)==3) |
---|
893 | { |
---|
894 | uiHorAbs=0; |
---|
895 | uiVerAbs=0; |
---|
896 | } |
---|
897 | else |
---|
898 | { |
---|
899 | m_pcTDecBinIf->decodeBin( uiHorAbs, *pCtx ); |
---|
900 | m_pcTDecBinIf->decodeBin( uiVerAbs, *pCtx ); |
---|
901 | |
---|
902 | const Bool bHorAbsGr0 = uiHorAbs != 0; |
---|
903 | const Bool bVerAbsGr0 = uiVerAbs != 0; |
---|
904 | pCtx++; |
---|
905 | |
---|
906 | if( bHorAbsGr0 ) |
---|
907 | { |
---|
908 | m_pcTDecBinIf->decodeBin( uiSymbol, *pCtx ); |
---|
909 | uiHorAbs += uiSymbol; |
---|
910 | } |
---|
911 | |
---|
912 | if( bVerAbsGr0 ) |
---|
913 | { |
---|
914 | m_pcTDecBinIf->decodeBin( uiSymbol, *pCtx ); |
---|
915 | uiVerAbs += uiSymbol; |
---|
916 | } |
---|
917 | |
---|
918 | if( bHorAbsGr0 ) |
---|
919 | { |
---|
920 | if( 2 == uiHorAbs ) |
---|
921 | { |
---|
922 | xReadEpExGolomb( uiSymbol, 1 ); |
---|
923 | uiHorAbs += uiSymbol; |
---|
924 | } |
---|
925 | |
---|
926 | m_pcTDecBinIf->decodeBinEP( uiHorSign ); |
---|
927 | } |
---|
928 | |
---|
929 | if( bVerAbsGr0 ) |
---|
930 | { |
---|
931 | if( 2 == uiVerAbs ) |
---|
932 | { |
---|
933 | xReadEpExGolomb( uiSymbol, 1 ); |
---|
934 | uiVerAbs += uiSymbol; |
---|
935 | } |
---|
936 | |
---|
937 | m_pcTDecBinIf->decodeBinEP( uiVerSign ); |
---|
938 | } |
---|
939 | |
---|
940 | } |
---|
941 | |
---|
942 | const TComMv cMv( uiHorSign ? -Int( uiHorAbs ): uiHorAbs, uiVerSign ? -Int( uiVerAbs ) : uiVerAbs ); |
---|
943 | pcCU->getCUMvField( eRefList )->setAllMvd( cMv, pcCU->getPartitionSize( uiAbsPartIdx ), uiAbsPartIdx, uiDepth, uiPartIdx ); |
---|
944 | return; |
---|
945 | } |
---|
946 | |
---|
947 | |
---|
948 | Void TDecSbac::parseTransformSubdivFlag( UInt& ruiSubdivFlag, UInt uiLog2TransformBlockSize ) |
---|
949 | { |
---|
950 | m_pcTDecBinIf->decodeBin( ruiSubdivFlag, m_cCUTransSubdivFlagSCModel.get( 0, 0, uiLog2TransformBlockSize ) ); |
---|
951 | DTRACE_CABAC_VL( g_nSymbolCounter++ ) |
---|
952 | DTRACE_CABAC_T( "\tparseTransformSubdivFlag()" ) |
---|
953 | DTRACE_CABAC_T( "\tsymbol=" ) |
---|
954 | DTRACE_CABAC_V( ruiSubdivFlag ) |
---|
955 | DTRACE_CABAC_T( "\tctx=" ) |
---|
956 | DTRACE_CABAC_V( uiLog2TransformBlockSize ) |
---|
957 | DTRACE_CABAC_T( "\n" ) |
---|
958 | } |
---|
959 | |
---|
960 | Void TDecSbac::parseQtRootCbf( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, UInt& uiQtRootCbf ) |
---|
961 | { |
---|
962 | UInt uiSymbol; |
---|
963 | const UInt uiCtx = 0; |
---|
964 | m_pcTDecBinIf->decodeBin( uiSymbol , m_cCUQtRootCbfSCModel.get( 0, 0, uiCtx ) ); |
---|
965 | DTRACE_CABAC_VL( g_nSymbolCounter++ ) |
---|
966 | DTRACE_CABAC_T( "\tparseQtRootCbf()" ) |
---|
967 | DTRACE_CABAC_T( "\tsymbol=" ) |
---|
968 | DTRACE_CABAC_V( uiSymbol ) |
---|
969 | DTRACE_CABAC_T( "\tctx=" ) |
---|
970 | DTRACE_CABAC_V( uiCtx ) |
---|
971 | DTRACE_CABAC_T( "\tuiAbsPartIdx=" ) |
---|
972 | DTRACE_CABAC_V( uiAbsPartIdx ) |
---|
973 | DTRACE_CABAC_T( "\n" ) |
---|
974 | |
---|
975 | uiQtRootCbf = uiSymbol; |
---|
976 | } |
---|
977 | |
---|
978 | Void TDecSbac::parseDeltaQP( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth ) |
---|
979 | { |
---|
980 | Int qp; |
---|
981 | UInt uiDQp; |
---|
982 | Int iDQp; |
---|
983 | |
---|
984 | #if CU_DQP_TU_EG |
---|
985 | UInt uiSymbol; |
---|
986 | |
---|
987 | xReadUnaryMaxSymbol (uiDQp, &m_cCUDeltaQpSCModel.get( 0, 0, 0 ), 1, CU_DQP_TU_CMAX); |
---|
988 | |
---|
989 | if( uiDQp >= CU_DQP_TU_CMAX) |
---|
990 | { |
---|
991 | xReadEpExGolomb( uiSymbol, CU_DQP_EG_k ); |
---|
992 | uiDQp+=uiSymbol; |
---|
993 | } |
---|
994 | |
---|
995 | if ( uiDQp > 0 ) |
---|
996 | { |
---|
997 | UInt uiSign; |
---|
998 | Int qpBdOffsetY = pcCU->getSlice()->getSPS()->getQpBDOffsetY(); |
---|
999 | m_pcTDecBinIf->decodeBinEP(uiSign); |
---|
1000 | iDQp = uiDQp; |
---|
1001 | if(uiSign) |
---|
1002 | { |
---|
1003 | iDQp = -iDQp; |
---|
1004 | } |
---|
1005 | qp = (((Int) pcCU->getRefQP( uiAbsPartIdx ) + iDQp + 52 + 2*qpBdOffsetY )%(52+qpBdOffsetY)) - qpBdOffsetY; |
---|
1006 | } |
---|
1007 | else |
---|
1008 | { |
---|
1009 | iDQp=0; |
---|
1010 | qp = pcCU->getRefQP(uiAbsPartIdx); |
---|
1011 | } |
---|
1012 | #else |
---|
1013 | m_pcTDecBinIf->decodeBin( uiDQp, m_cCUDeltaQpSCModel.get( 0, 0, 0 ) ); |
---|
1014 | |
---|
1015 | if ( uiDQp == 0 ) |
---|
1016 | { |
---|
1017 | qp = pcCU->getRefQP(uiAbsPartIdx); |
---|
1018 | } |
---|
1019 | else |
---|
1020 | { |
---|
1021 | UInt uiSign; |
---|
1022 | Int qpBdOffsetY = pcCU->getSlice()->getSPS()->getQpBDOffsetY(); |
---|
1023 | m_pcTDecBinIf->decodeBinEP(uiSign); |
---|
1024 | |
---|
1025 | UInt uiMaxAbsDQpMinus1 = 24 + (qpBdOffsetY/2) + (uiSign); |
---|
1026 | UInt uiAbsDQpMinus1; |
---|
1027 | xReadUnaryMaxSymbol (uiAbsDQpMinus1, &m_cCUDeltaQpSCModel.get( 0, 0, 1 ), 1, uiMaxAbsDQpMinus1); |
---|
1028 | |
---|
1029 | iDQp = uiAbsDQpMinus1 + 1; |
---|
1030 | |
---|
1031 | if(uiSign) |
---|
1032 | { |
---|
1033 | iDQp = -iDQp; |
---|
1034 | } |
---|
1035 | |
---|
1036 | qp = (((Int) pcCU->getRefQP( uiAbsPartIdx ) + iDQp + 52 + 2*qpBdOffsetY )%(52+qpBdOffsetY)) - qpBdOffsetY; |
---|
1037 | } |
---|
1038 | #endif |
---|
1039 | pcCU->setQPSubParts(qp, uiAbsPartIdx, uiDepth); |
---|
1040 | pcCU->setCodedQP(qp); |
---|
1041 | } |
---|
1042 | |
---|
1043 | Void TDecSbac::parseQtCbf( TComDataCU* pcCU, UInt uiAbsPartIdx, TextType eType, UInt uiTrDepth, UInt uiDepth ) |
---|
1044 | { |
---|
1045 | UInt uiSymbol; |
---|
1046 | const UInt uiCtx = pcCU->getCtxQtCbf( uiAbsPartIdx, eType, uiTrDepth ); |
---|
1047 | m_pcTDecBinIf->decodeBin( uiSymbol , m_cCUQtCbfSCModel.get( 0, eType ? TEXT_CHROMA: eType, uiCtx ) ); |
---|
1048 | |
---|
1049 | DTRACE_CABAC_VL( g_nSymbolCounter++ ) |
---|
1050 | DTRACE_CABAC_T( "\tparseQtCbf()" ) |
---|
1051 | DTRACE_CABAC_T( "\tsymbol=" ) |
---|
1052 | DTRACE_CABAC_V( uiSymbol ) |
---|
1053 | DTRACE_CABAC_T( "\tctx=" ) |
---|
1054 | DTRACE_CABAC_V( uiCtx ) |
---|
1055 | DTRACE_CABAC_T( "\tetype=" ) |
---|
1056 | DTRACE_CABAC_V( eType ) |
---|
1057 | DTRACE_CABAC_T( "\tuiAbsPartIdx=" ) |
---|
1058 | DTRACE_CABAC_V( uiAbsPartIdx ) |
---|
1059 | DTRACE_CABAC_T( "\n" ) |
---|
1060 | |
---|
1061 | pcCU->setCbfSubParts( uiSymbol << uiTrDepth, eType, uiAbsPartIdx, uiDepth ); |
---|
1062 | } |
---|
1063 | |
---|
1064 | void TDecSbac::parseTransformSkipFlags (TComDataCU* pcCU, UInt uiAbsPartIdx, UInt width, UInt height, UInt uiDepth, TextType eTType) |
---|
1065 | { |
---|
1066 | if (pcCU->getCUTransquantBypass(uiAbsPartIdx)) |
---|
1067 | { |
---|
1068 | return; |
---|
1069 | } |
---|
1070 | #if !INTER_TRANSFORMSKIP |
---|
1071 | if(!pcCU->isIntra(uiAbsPartIdx)) |
---|
1072 | { |
---|
1073 | return; |
---|
1074 | } |
---|
1075 | #endif |
---|
1076 | if(width != 4 || height != 4) |
---|
1077 | { |
---|
1078 | return; |
---|
1079 | } |
---|
1080 | |
---|
1081 | UInt useTransformSkip; |
---|
1082 | m_pcTDecBinIf->decodeBin( useTransformSkip , m_cTransformSkipSCModel.get( 0, eTType? TEXT_CHROMA: TEXT_LUMA, 0 ) ); |
---|
1083 | if(eTType!= TEXT_LUMA) |
---|
1084 | { |
---|
1085 | const UInt uiLog2TrafoSize = g_aucConvertToBit[pcCU->getSlice()->getSPS()->getMaxCUWidth()] + 2 - uiDepth; |
---|
1086 | if(uiLog2TrafoSize == 2) |
---|
1087 | { |
---|
1088 | uiDepth --; |
---|
1089 | } |
---|
1090 | } |
---|
1091 | DTRACE_CABAC_VL( g_nSymbolCounter++ ) |
---|
1092 | DTRACE_CABAC_T("\tparseTransformSkip()"); |
---|
1093 | DTRACE_CABAC_T( "\tsymbol=" ) |
---|
1094 | DTRACE_CABAC_V( useTransformSkip ) |
---|
1095 | DTRACE_CABAC_T( "\tAddr=" ) |
---|
1096 | DTRACE_CABAC_V( pcCU->getAddr() ) |
---|
1097 | DTRACE_CABAC_T( "\tetype=" ) |
---|
1098 | DTRACE_CABAC_V( eTType ) |
---|
1099 | DTRACE_CABAC_T( "\tuiAbsPartIdx=" ) |
---|
1100 | DTRACE_CABAC_V( uiAbsPartIdx ) |
---|
1101 | DTRACE_CABAC_T( "\n" ) |
---|
1102 | |
---|
1103 | pcCU->setTransformSkipSubParts( useTransformSkip, eTType, uiAbsPartIdx, uiDepth); |
---|
1104 | } |
---|
1105 | |
---|
1106 | /** Parse (X,Y) position of the last significant coefficient |
---|
1107 | * \param uiPosLastX reference to X component of last coefficient |
---|
1108 | * \param uiPosLastY reference to Y component of last coefficient |
---|
1109 | * \param width Block width |
---|
1110 | * \param height Block height |
---|
1111 | * \param eTType plane type / luminance or chrominance |
---|
1112 | * \param uiScanIdx scan type (zig-zag, hor, ver) |
---|
1113 | * |
---|
1114 | * This method decodes the X and Y component within a block of the last significant coefficient. |
---|
1115 | */ |
---|
1116 | Void TDecSbac::parseLastSignificantXY( UInt& uiPosLastX, UInt& uiPosLastY, Int width, Int height, TextType eTType, UInt uiScanIdx ) |
---|
1117 | { |
---|
1118 | UInt uiLast; |
---|
1119 | ContextModel *pCtxX = m_cCuCtxLastX.get( 0, eTType ); |
---|
1120 | ContextModel *pCtxY = m_cCuCtxLastY.get( 0, eTType ); |
---|
1121 | |
---|
1122 | Int blkSizeOffsetX, blkSizeOffsetY, shiftX, shiftY; |
---|
1123 | blkSizeOffsetX = eTType ? 0: (g_aucConvertToBit[ width ] *3 + ((g_aucConvertToBit[ width ] +1)>>2)); |
---|
1124 | blkSizeOffsetY = eTType ? 0: (g_aucConvertToBit[ height ]*3 + ((g_aucConvertToBit[ height ]+1)>>2)); |
---|
1125 | shiftX= eTType ? g_aucConvertToBit[ width ] :((g_aucConvertToBit[ width ]+3)>>2); |
---|
1126 | shiftY= eTType ? g_aucConvertToBit[ height ] :((g_aucConvertToBit[ height ]+3)>>2); |
---|
1127 | // posX |
---|
1128 | for( uiPosLastX = 0; uiPosLastX < g_uiGroupIdx[ width - 1 ]; uiPosLastX++ ) |
---|
1129 | { |
---|
1130 | m_pcTDecBinIf->decodeBin( uiLast, *( pCtxX + blkSizeOffsetX + (uiPosLastX >>shiftX) ) ); |
---|
1131 | if( !uiLast ) |
---|
1132 | { |
---|
1133 | break; |
---|
1134 | } |
---|
1135 | } |
---|
1136 | |
---|
1137 | // posY |
---|
1138 | for( uiPosLastY = 0; uiPosLastY < g_uiGroupIdx[ height - 1 ]; uiPosLastY++ ) |
---|
1139 | { |
---|
1140 | m_pcTDecBinIf->decodeBin( uiLast, *( pCtxY + blkSizeOffsetY + (uiPosLastY >>shiftY)) ); |
---|
1141 | if( !uiLast ) |
---|
1142 | { |
---|
1143 | break; |
---|
1144 | } |
---|
1145 | } |
---|
1146 | if ( uiPosLastX > 3 ) |
---|
1147 | { |
---|
1148 | UInt uiTemp = 0; |
---|
1149 | UInt uiCount = ( uiPosLastX - 2 ) >> 1; |
---|
1150 | for ( Int i = uiCount - 1; i >= 0; i-- ) |
---|
1151 | { |
---|
1152 | m_pcTDecBinIf->decodeBinEP( uiLast ); |
---|
1153 | uiTemp += uiLast << i; |
---|
1154 | } |
---|
1155 | uiPosLastX = g_uiMinInGroup[ uiPosLastX ] + uiTemp; |
---|
1156 | } |
---|
1157 | if ( uiPosLastY > 3 ) |
---|
1158 | { |
---|
1159 | UInt uiTemp = 0; |
---|
1160 | UInt uiCount = ( uiPosLastY - 2 ) >> 1; |
---|
1161 | for ( Int i = uiCount - 1; i >= 0; i-- ) |
---|
1162 | { |
---|
1163 | m_pcTDecBinIf->decodeBinEP( uiLast ); |
---|
1164 | uiTemp += uiLast << i; |
---|
1165 | } |
---|
1166 | uiPosLastY = g_uiMinInGroup[ uiPosLastY ] + uiTemp; |
---|
1167 | } |
---|
1168 | |
---|
1169 | if( uiScanIdx == SCAN_VER ) |
---|
1170 | { |
---|
1171 | swap( uiPosLastX, uiPosLastY ); |
---|
1172 | } |
---|
1173 | } |
---|
1174 | |
---|
1175 | Void TDecSbac::parseCoeffNxN( TComDataCU* pcCU, TCoeff* pcCoef, UInt uiAbsPartIdx, UInt uiWidth, UInt uiHeight, UInt uiDepth, TextType eTType ) |
---|
1176 | { |
---|
1177 | DTRACE_CABAC_VL( g_nSymbolCounter++ ) |
---|
1178 | DTRACE_CABAC_T( "\tparseCoeffNxN()\teType=" ) |
---|
1179 | DTRACE_CABAC_V( eTType ) |
---|
1180 | DTRACE_CABAC_T( "\twidth=" ) |
---|
1181 | DTRACE_CABAC_V( uiWidth ) |
---|
1182 | DTRACE_CABAC_T( "\theight=" ) |
---|
1183 | DTRACE_CABAC_V( uiHeight ) |
---|
1184 | DTRACE_CABAC_T( "\tdepth=" ) |
---|
1185 | DTRACE_CABAC_V( uiDepth ) |
---|
1186 | DTRACE_CABAC_T( "\tabspartidx=" ) |
---|
1187 | DTRACE_CABAC_V( uiAbsPartIdx ) |
---|
1188 | DTRACE_CABAC_T( "\ttoCU-X=" ) |
---|
1189 | DTRACE_CABAC_V( pcCU->getCUPelX() ) |
---|
1190 | DTRACE_CABAC_T( "\ttoCU-Y=" ) |
---|
1191 | DTRACE_CABAC_V( pcCU->getCUPelY() ) |
---|
1192 | DTRACE_CABAC_T( "\tCU-addr=" ) |
---|
1193 | DTRACE_CABAC_V( pcCU->getAddr() ) |
---|
1194 | DTRACE_CABAC_T( "\tinCU-X=" ) |
---|
1195 | DTRACE_CABAC_V( g_auiRasterToPelX[ g_auiZscanToRaster[uiAbsPartIdx] ] ) |
---|
1196 | DTRACE_CABAC_T( "\tinCU-Y=" ) |
---|
1197 | DTRACE_CABAC_V( g_auiRasterToPelY[ g_auiZscanToRaster[uiAbsPartIdx] ] ) |
---|
1198 | DTRACE_CABAC_T( "\tpredmode=" ) |
---|
1199 | DTRACE_CABAC_V( pcCU->getPredictionMode( uiAbsPartIdx ) ) |
---|
1200 | DTRACE_CABAC_T( "\n" ) |
---|
1201 | |
---|
1202 | if( uiWidth > pcCU->getSlice()->getSPS()->getMaxTrSize() ) |
---|
1203 | { |
---|
1204 | uiWidth = pcCU->getSlice()->getSPS()->getMaxTrSize(); |
---|
1205 | uiHeight = pcCU->getSlice()->getSPS()->getMaxTrSize(); |
---|
1206 | } |
---|
1207 | #if PPS_TS_FLAG |
---|
1208 | if(pcCU->getSlice()->getPPS()->getUseTransformSkip()) |
---|
1209 | #else |
---|
1210 | if(pcCU->getSlice()->getSPS()->getUseTransformSkip()) |
---|
1211 | #endif |
---|
1212 | { |
---|
1213 | parseTransformSkipFlags( pcCU, uiAbsPartIdx, uiWidth, uiHeight, uiDepth, eTType); |
---|
1214 | } |
---|
1215 | |
---|
1216 | eTType = eTType == TEXT_LUMA ? TEXT_LUMA : ( eTType == TEXT_NONE ? TEXT_NONE : TEXT_CHROMA ); |
---|
1217 | |
---|
1218 | //----- parse significance map ----- |
---|
1219 | const UInt uiLog2BlockSize = g_aucConvertToBit[ uiWidth ] + 2; |
---|
1220 | const UInt uiMaxNumCoeff = uiWidth * uiHeight; |
---|
1221 | const UInt uiMaxNumCoeffM1 = uiMaxNumCoeff - 1; |
---|
1222 | UInt uiScanIdx = pcCU->getCoefScanIdx(uiAbsPartIdx, uiWidth, eTType==TEXT_LUMA, pcCU->isIntra(uiAbsPartIdx)); |
---|
1223 | int blockType = uiLog2BlockSize; |
---|
1224 | if (uiWidth != uiHeight) |
---|
1225 | { |
---|
1226 | uiScanIdx = SCAN_DIAG; |
---|
1227 | blockType = 4; |
---|
1228 | } |
---|
1229 | |
---|
1230 | //===== decode last significant ===== |
---|
1231 | UInt uiPosLastX, uiPosLastY; |
---|
1232 | parseLastSignificantXY( uiPosLastX, uiPosLastY, uiWidth, uiHeight, eTType, uiScanIdx ); |
---|
1233 | UInt uiBlkPosLast = uiPosLastX + (uiPosLastY<<uiLog2BlockSize); |
---|
1234 | pcCoef[ uiBlkPosLast ] = 1; |
---|
1235 | |
---|
1236 | //===== decode significance flags ===== |
---|
1237 | UInt uiScanPosLast = uiBlkPosLast; |
---|
1238 | if (uiScanIdx == SCAN_ZIGZAG) |
---|
1239 | { |
---|
1240 | // Map zigzag to diagonal scan |
---|
1241 | uiScanIdx = SCAN_DIAG; |
---|
1242 | } |
---|
1243 | #if REMOVE_NSQT |
---|
1244 | const UInt *scan = g_auiSigLastScan[ uiScanIdx ][ uiLog2BlockSize-1 ]; |
---|
1245 | #else |
---|
1246 | const UInt * scan; |
---|
1247 | if (uiWidth == uiHeight) |
---|
1248 | { |
---|
1249 | scan = g_auiSigLastScan[ uiScanIdx ][ uiLog2BlockSize-1 ]; |
---|
1250 | } |
---|
1251 | else |
---|
1252 | { |
---|
1253 | scan = g_sigScanNSQT[ uiLog2BlockSize - 2 ]; |
---|
1254 | } |
---|
1255 | #endif |
---|
1256 | for( uiScanPosLast = 0; uiScanPosLast < uiMaxNumCoeffM1; uiScanPosLast++ ) |
---|
1257 | { |
---|
1258 | UInt uiBlkPos = scan[ uiScanPosLast ]; |
---|
1259 | if( uiBlkPosLast == uiBlkPos ) |
---|
1260 | { |
---|
1261 | break; |
---|
1262 | } |
---|
1263 | } |
---|
1264 | |
---|
1265 | ContextModel * const baseCoeffGroupCtx = m_cCUSigCoeffGroupSCModel.get( 0, eTType ); |
---|
1266 | ContextModel * const baseCtx = (eTType==TEXT_LUMA) ? m_cCUSigSCModel.get( 0, 0 ) : m_cCUSigSCModel.get( 0, 0 ) + NUM_SIG_FLAG_CTX_LUMA; |
---|
1267 | |
---|
1268 | const Int iLastScanSet = uiScanPosLast >> LOG2_SCAN_SET_SIZE; |
---|
1269 | #if REMOVE_NUM_GREATER1 |
---|
1270 | UInt c1 = 1; |
---|
1271 | #else |
---|
1272 | UInt uiNumOne = 0; |
---|
1273 | #endif |
---|
1274 | UInt uiGoRiceParam = 0; |
---|
1275 | |
---|
1276 | Bool beValid; |
---|
1277 | if (pcCU->getCUTransquantBypass(uiAbsPartIdx)) |
---|
1278 | { |
---|
1279 | beValid = false; |
---|
1280 | } |
---|
1281 | else |
---|
1282 | { |
---|
1283 | beValid = pcCU->getSlice()->getPPS()->getSignHideFlag() > 0; |
---|
1284 | } |
---|
1285 | UInt absSum = 0; |
---|
1286 | |
---|
1287 | UInt uiSigCoeffGroupFlag[ MLS_GRP_NUM ]; |
---|
1288 | ::memset( uiSigCoeffGroupFlag, 0, sizeof(UInt) * MLS_GRP_NUM ); |
---|
1289 | const UInt uiNumBlkSide = uiWidth >> (MLS_CG_SIZE >> 1); |
---|
1290 | const UInt * scanCG; |
---|
1291 | #if !REMOVE_NSQT |
---|
1292 | if (uiWidth == uiHeight) |
---|
1293 | #endif |
---|
1294 | { |
---|
1295 | scanCG = g_auiSigLastScan[ uiScanIdx ][ uiLog2BlockSize > 3 ? uiLog2BlockSize-2-1 : 0 ]; |
---|
1296 | if( uiLog2BlockSize == 3 ) |
---|
1297 | { |
---|
1298 | scanCG = g_sigLastScan8x8[ uiScanIdx ]; |
---|
1299 | } |
---|
1300 | else if( uiLog2BlockSize == 5 ) |
---|
1301 | { |
---|
1302 | scanCG = g_sigLastScanCG32x32; |
---|
1303 | } |
---|
1304 | } |
---|
1305 | #if !REMOVE_NSQT |
---|
1306 | else |
---|
1307 | { |
---|
1308 | scanCG = g_sigCGScanNSQT[ uiLog2BlockSize - 2 ]; |
---|
1309 | } |
---|
1310 | #endif |
---|
1311 | Int iScanPosSig = (Int) uiScanPosLast; |
---|
1312 | for( Int iSubSet = iLastScanSet; iSubSet >= 0; iSubSet-- ) |
---|
1313 | { |
---|
1314 | Int iSubPos = iSubSet << LOG2_SCAN_SET_SIZE; |
---|
1315 | uiGoRiceParam = 0; |
---|
1316 | Int numNonZero = 0; |
---|
1317 | |
---|
1318 | Int lastNZPosInCG = -1, firstNZPosInCG = SCAN_SET_SIZE; |
---|
1319 | |
---|
1320 | Int pos[SCAN_SET_SIZE]; |
---|
1321 | if( iScanPosSig == (Int) uiScanPosLast ) |
---|
1322 | { |
---|
1323 | lastNZPosInCG = iScanPosSig; |
---|
1324 | firstNZPosInCG = iScanPosSig; |
---|
1325 | iScanPosSig--; |
---|
1326 | pos[ numNonZero ] = uiBlkPosLast; |
---|
1327 | numNonZero = 1; |
---|
1328 | } |
---|
1329 | |
---|
1330 | // decode significant_coeffgroup_flag |
---|
1331 | Int iCGBlkPos = scanCG[ iSubSet ]; |
---|
1332 | Int iCGPosY = iCGBlkPos / uiNumBlkSide; |
---|
1333 | Int iCGPosX = iCGBlkPos - (iCGPosY * uiNumBlkSide); |
---|
1334 | #if !REMOVAL_8x2_2x8_CG |
---|
1335 | if( uiWidth == 8 && uiHeight == 8 && (uiScanIdx == SCAN_HOR || uiScanIdx == SCAN_VER) ) |
---|
1336 | { |
---|
1337 | iCGPosY = (uiScanIdx == SCAN_HOR ? iCGBlkPos : 0); |
---|
1338 | iCGPosX = (uiScanIdx == SCAN_VER ? iCGBlkPos : 0); |
---|
1339 | } |
---|
1340 | #endif |
---|
1341 | if( iSubSet == iLastScanSet || iSubSet == 0) |
---|
1342 | { |
---|
1343 | uiSigCoeffGroupFlag[ iCGBlkPos ] = 1; |
---|
1344 | } |
---|
1345 | else |
---|
1346 | { |
---|
1347 | UInt uiSigCoeffGroup; |
---|
1348 | UInt uiCtxSig = TComTrQuant::getSigCoeffGroupCtxInc( uiSigCoeffGroupFlag, iCGPosX, iCGPosY, uiScanIdx, uiWidth, uiHeight ); |
---|
1349 | m_pcTDecBinIf->decodeBin( uiSigCoeffGroup, baseCoeffGroupCtx[ uiCtxSig ] ); |
---|
1350 | uiSigCoeffGroupFlag[ iCGBlkPos ] = uiSigCoeffGroup; |
---|
1351 | } |
---|
1352 | |
---|
1353 | // decode significant_coeff_flag |
---|
1354 | Int patternSigCtx = TComTrQuant::calcPatternSigCtx( uiSigCoeffGroupFlag, iCGPosX, iCGPosY, uiWidth, uiHeight ); |
---|
1355 | UInt uiBlkPos, uiPosY, uiPosX, uiSig, uiCtxSig; |
---|
1356 | for( ; iScanPosSig >= iSubPos; iScanPosSig-- ) |
---|
1357 | { |
---|
1358 | uiBlkPos = scan[ iScanPosSig ]; |
---|
1359 | uiPosY = uiBlkPos >> uiLog2BlockSize; |
---|
1360 | uiPosX = uiBlkPos - ( uiPosY << uiLog2BlockSize ); |
---|
1361 | uiSig = 0; |
---|
1362 | |
---|
1363 | if( uiSigCoeffGroupFlag[ iCGBlkPos ] ) |
---|
1364 | { |
---|
1365 | if( iScanPosSig > iSubPos || iSubSet == 0 || numNonZero ) |
---|
1366 | { |
---|
1367 | #if REMOVAL_8x2_2x8_CG |
---|
1368 | uiCtxSig = TComTrQuant::getSigCtxInc( patternSigCtx, uiScanIdx, uiPosX, uiPosY, blockType, uiWidth, uiHeight, eTType ); |
---|
1369 | #else |
---|
1370 | uiCtxSig = TComTrQuant::getSigCtxInc( patternSigCtx, uiPosX, uiPosY, blockType, uiWidth, uiHeight, eTType ); |
---|
1371 | #endif |
---|
1372 | m_pcTDecBinIf->decodeBin( uiSig, baseCtx[ uiCtxSig ] ); |
---|
1373 | } |
---|
1374 | else |
---|
1375 | { |
---|
1376 | uiSig = 1; |
---|
1377 | } |
---|
1378 | } |
---|
1379 | pcCoef[ uiBlkPos ] = uiSig; |
---|
1380 | if( uiSig ) |
---|
1381 | { |
---|
1382 | pos[ numNonZero ] = uiBlkPos; |
---|
1383 | numNonZero ++; |
---|
1384 | if( lastNZPosInCG == -1 ) |
---|
1385 | { |
---|
1386 | lastNZPosInCG = iScanPosSig; |
---|
1387 | } |
---|
1388 | firstNZPosInCG = iScanPosSig; |
---|
1389 | } |
---|
1390 | } |
---|
1391 | |
---|
1392 | if( numNonZero ) |
---|
1393 | { |
---|
1394 | Bool signHidden = ( lastNZPosInCG - firstNZPosInCG >= SBH_THRESHOLD ); |
---|
1395 | absSum = 0; |
---|
1396 | #if !REMOVE_NUM_GREATER1 |
---|
1397 | UInt c1 = 1; |
---|
1398 | #endif |
---|
1399 | UInt uiCtxSet = (iSubSet > 0 && eTType==TEXT_LUMA) ? 2 : 0; |
---|
1400 | UInt uiBin; |
---|
1401 | #if REMOVE_NUM_GREATER1 |
---|
1402 | if( c1 == 0 ) |
---|
1403 | #else |
---|
1404 | if( uiNumOne > 0 ) |
---|
1405 | #endif |
---|
1406 | { |
---|
1407 | uiCtxSet++; |
---|
1408 | } |
---|
1409 | #if REMOVE_NUM_GREATER1 |
---|
1410 | c1 = 1; |
---|
1411 | #else |
---|
1412 | uiNumOne >>= 1; |
---|
1413 | #endif |
---|
1414 | ContextModel *baseCtxMod = ( eTType==TEXT_LUMA ) ? m_cCUOneSCModel.get( 0, 0 ) + 4 * uiCtxSet : m_cCUOneSCModel.get( 0, 0 ) + NUM_ONE_FLAG_CTX_LUMA + 4 * uiCtxSet; |
---|
1415 | Int absCoeff[SCAN_SET_SIZE]; |
---|
1416 | |
---|
1417 | for ( Int i = 0; i < numNonZero; i++) absCoeff[i] = 1; |
---|
1418 | Int numC1Flag = min(numNonZero, C1FLAG_NUMBER); |
---|
1419 | Int firstC2FlagIdx = -1; |
---|
1420 | |
---|
1421 | for( Int idx = 0; idx < numC1Flag; idx++ ) |
---|
1422 | { |
---|
1423 | m_pcTDecBinIf->decodeBin( uiBin, baseCtxMod[c1] ); |
---|
1424 | if( uiBin == 1 ) |
---|
1425 | { |
---|
1426 | c1 = 0; |
---|
1427 | if (firstC2FlagIdx == -1) |
---|
1428 | { |
---|
1429 | firstC2FlagIdx = idx; |
---|
1430 | } |
---|
1431 | } |
---|
1432 | else if( (c1 < 3) && (c1 > 0) ) |
---|
1433 | { |
---|
1434 | c1++; |
---|
1435 | } |
---|
1436 | absCoeff[ idx ] = uiBin + 1; |
---|
1437 | } |
---|
1438 | |
---|
1439 | if (c1 == 0) |
---|
1440 | { |
---|
1441 | baseCtxMod = ( eTType==TEXT_LUMA ) ? m_cCUAbsSCModel.get( 0, 0 ) + uiCtxSet : m_cCUAbsSCModel.get( 0, 0 ) + NUM_ABS_FLAG_CTX_LUMA + uiCtxSet; |
---|
1442 | if ( firstC2FlagIdx != -1) |
---|
1443 | { |
---|
1444 | m_pcTDecBinIf->decodeBin( uiBin, baseCtxMod[0] ); |
---|
1445 | absCoeff[ firstC2FlagIdx ] = uiBin + 2; |
---|
1446 | } |
---|
1447 | } |
---|
1448 | |
---|
1449 | UInt coeffSigns; |
---|
1450 | if ( signHidden && beValid ) |
---|
1451 | { |
---|
1452 | m_pcTDecBinIf->decodeBinsEP( coeffSigns, numNonZero-1 ); |
---|
1453 | coeffSigns <<= 32 - (numNonZero-1); |
---|
1454 | } |
---|
1455 | else |
---|
1456 | { |
---|
1457 | m_pcTDecBinIf->decodeBinsEP( coeffSigns, numNonZero ); |
---|
1458 | coeffSigns <<= 32 - numNonZero; |
---|
1459 | } |
---|
1460 | |
---|
1461 | Int iFirstCoeff2 = 1; |
---|
1462 | if (c1 == 0 || numNonZero > C1FLAG_NUMBER) |
---|
1463 | { |
---|
1464 | for( Int idx = 0; idx < numNonZero; idx++ ) |
---|
1465 | { |
---|
1466 | UInt baseLevel = (idx < C1FLAG_NUMBER)? (2 + iFirstCoeff2) : 1; |
---|
1467 | |
---|
1468 | if( absCoeff[ idx ] == baseLevel) |
---|
1469 | { |
---|
1470 | UInt uiLevel; |
---|
1471 | xReadCoefRemainExGolomb( uiLevel, uiGoRiceParam ); |
---|
1472 | absCoeff[ idx ] = uiLevel + baseLevel; |
---|
1473 | if(absCoeff[idx]>3*(1<<uiGoRiceParam)) |
---|
1474 | { |
---|
1475 | uiGoRiceParam = min<UInt>(uiGoRiceParam+ 1, 4); |
---|
1476 | } |
---|
1477 | } |
---|
1478 | |
---|
1479 | if(absCoeff[ idx ] >= 2) |
---|
1480 | { |
---|
1481 | iFirstCoeff2 = 0; |
---|
1482 | #if !REMOVE_NUM_GREATER1 |
---|
1483 | uiNumOne++; |
---|
1484 | #endif |
---|
1485 | } |
---|
1486 | } |
---|
1487 | } |
---|
1488 | |
---|
1489 | for( Int idx = 0; idx < numNonZero; idx++ ) |
---|
1490 | { |
---|
1491 | Int blkPos = pos[ idx ]; |
---|
1492 | // Signs applied later. |
---|
1493 | pcCoef[ blkPos ] = absCoeff[ idx ]; |
---|
1494 | absSum += absCoeff[ idx ]; |
---|
1495 | |
---|
1496 | if ( idx == numNonZero-1 && signHidden && beValid ) |
---|
1497 | { |
---|
1498 | // Infer sign of 1st element. |
---|
1499 | if (absSum&0x1) |
---|
1500 | { |
---|
1501 | pcCoef[ blkPos ] = -pcCoef[ blkPos ]; |
---|
1502 | } |
---|
1503 | } |
---|
1504 | else |
---|
1505 | { |
---|
1506 | Int sign = static_cast<Int>( coeffSigns ) >> 31; |
---|
1507 | pcCoef[ blkPos ] = ( pcCoef[ blkPos ] ^ sign ) - sign; |
---|
1508 | coeffSigns <<= 1; |
---|
1509 | } |
---|
1510 | } |
---|
1511 | } |
---|
1512 | #if !REMOVE_NUM_GREATER1 |
---|
1513 | else |
---|
1514 | { |
---|
1515 | uiNumOne >>= 1; |
---|
1516 | } |
---|
1517 | #endif |
---|
1518 | } |
---|
1519 | |
---|
1520 | return; |
---|
1521 | } |
---|
1522 | |
---|
1523 | |
---|
1524 | Void TDecSbac::parseSaoMaxUvlc ( UInt& val, UInt maxSymbol ) |
---|
1525 | { |
---|
1526 | if (maxSymbol == 0) |
---|
1527 | { |
---|
1528 | val = 0; |
---|
1529 | return; |
---|
1530 | } |
---|
1531 | |
---|
1532 | UInt code; |
---|
1533 | Int i; |
---|
1534 | #if SAO_ABS_BY_PASS |
---|
1535 | m_pcTDecBinIf->decodeBinEP( code ); |
---|
1536 | #else |
---|
1537 | m_pcTDecBinIf->decodeBin( code, m_cSaoUvlcSCModel.get( 0, 0, 0 ) ); |
---|
1538 | #endif |
---|
1539 | if ( code == 0 ) |
---|
1540 | { |
---|
1541 | val = 0; |
---|
1542 | return; |
---|
1543 | } |
---|
1544 | |
---|
1545 | i=1; |
---|
1546 | while (1) |
---|
1547 | { |
---|
1548 | #if SAO_ABS_BY_PASS |
---|
1549 | m_pcTDecBinIf->decodeBinEP( code ); |
---|
1550 | #else |
---|
1551 | m_pcTDecBinIf->decodeBin( code, m_cSaoUvlcSCModel.get( 0, 0, 1 ) ); |
---|
1552 | #endif |
---|
1553 | if ( code == 0 ) |
---|
1554 | { |
---|
1555 | break; |
---|
1556 | } |
---|
1557 | i++; |
---|
1558 | if (i == maxSymbol) |
---|
1559 | { |
---|
1560 | break; |
---|
1561 | } |
---|
1562 | } |
---|
1563 | |
---|
1564 | val = i; |
---|
1565 | } |
---|
1566 | #if SAO_TYPE_CODING |
---|
1567 | Void TDecSbac::parseSaoUflc (UInt uiLength, UInt& riVal) |
---|
1568 | { |
---|
1569 | m_pcTDecBinIf->decodeBinsEP ( riVal, uiLength ); |
---|
1570 | } |
---|
1571 | #else |
---|
1572 | Void TDecSbac::parseSaoUflc (UInt& riVal) |
---|
1573 | { |
---|
1574 | m_pcTDecBinIf->decodeBinsEP ( riVal, 5 ); |
---|
1575 | } |
---|
1576 | #endif |
---|
1577 | #if SAO_MERGE_ONE_CTX |
---|
1578 | Void TDecSbac::parseSaoMerge (UInt& ruiVal) |
---|
1579 | #else |
---|
1580 | Void TDecSbac::parseSaoMergeLeft (UInt& ruiVal, UInt uiCompIdx) |
---|
1581 | #endif |
---|
1582 | { |
---|
1583 | UInt uiCode; |
---|
1584 | #if SAO_MERGE_ONE_CTX |
---|
1585 | m_pcTDecBinIf->decodeBin( uiCode, m_cSaoMergeSCModel.get( 0, 0, 0 ) ); |
---|
1586 | #else |
---|
1587 | #if SAO_SINGLE_MERGE |
---|
1588 | m_pcTDecBinIf->decodeBin( uiCode, m_cSaoMergeLeftSCModel.get( 0, 0, 0 ) ); |
---|
1589 | #else |
---|
1590 | m_pcTDecBinIf->decodeBin( uiCode, m_cSaoMergeLeftSCModel.get( 0, 0, uiCompIdx ) ); |
---|
1591 | #endif |
---|
1592 | #endif |
---|
1593 | ruiVal = (Int)uiCode; |
---|
1594 | } |
---|
1595 | #if !SAO_MERGE_ONE_CTX |
---|
1596 | Void TDecSbac::parseSaoMergeUp (UInt& ruiVal) |
---|
1597 | { |
---|
1598 | UInt uiCode; |
---|
1599 | m_pcTDecBinIf->decodeBin( uiCode, m_cSaoMergeUpSCModel.get( 0, 0, 0 ) ); |
---|
1600 | ruiVal = (Int)uiCode; |
---|
1601 | } |
---|
1602 | #endif |
---|
1603 | Void TDecSbac::parseSaoTypeIdx (UInt& ruiVal) |
---|
1604 | { |
---|
1605 | UInt uiCode; |
---|
1606 | #if SAO_TYPE_CODING |
---|
1607 | m_pcTDecBinIf->decodeBin( uiCode, m_cSaoTypeIdxSCModel.get( 0, 0, 0 ) ); |
---|
1608 | if (uiCode == 0) |
---|
1609 | { |
---|
1610 | ruiVal = 0; |
---|
1611 | } |
---|
1612 | else |
---|
1613 | { |
---|
1614 | m_pcTDecBinIf->decodeBinEP( uiCode ); |
---|
1615 | if (uiCode == 0) |
---|
1616 | { |
---|
1617 | ruiVal = 5; |
---|
1618 | } |
---|
1619 | else |
---|
1620 | { |
---|
1621 | ruiVal = 1; |
---|
1622 | } |
---|
1623 | } |
---|
1624 | #else |
---|
1625 | Int i; |
---|
1626 | m_pcTDecBinIf->decodeBin( uiCode, m_cSaoTypeIdxSCModel.get( 0, 0, 0 ) ); |
---|
1627 | if ( uiCode == 0 ) |
---|
1628 | { |
---|
1629 | ruiVal = 0; |
---|
1630 | return; |
---|
1631 | } |
---|
1632 | i=1; |
---|
1633 | while (1) |
---|
1634 | { |
---|
1635 | m_pcTDecBinIf->decodeBin( uiCode, m_cSaoTypeIdxSCModel.get( 0, 0, 1 ) ); |
---|
1636 | if ( uiCode == 0 ) |
---|
1637 | { |
---|
1638 | break; |
---|
1639 | } |
---|
1640 | i++; |
---|
1641 | } |
---|
1642 | ruiVal = i; |
---|
1643 | #endif |
---|
1644 | } |
---|
1645 | |
---|
1646 | inline Void copySaoOneLcuParam(SaoLcuParam* psDst, SaoLcuParam* psSrc) |
---|
1647 | { |
---|
1648 | Int i; |
---|
1649 | psDst->partIdx = psSrc->partIdx; |
---|
1650 | psDst->typeIdx = psSrc->typeIdx; |
---|
1651 | if (psDst->typeIdx != -1) |
---|
1652 | { |
---|
1653 | #if SAO_TYPE_CODING |
---|
1654 | psDst->subTypeIdx = psSrc->subTypeIdx ; |
---|
1655 | #else |
---|
1656 | if (psDst->typeIdx == SAO_BO) |
---|
1657 | { |
---|
1658 | psDst->bandPosition = psSrc->bandPosition ; |
---|
1659 | } |
---|
1660 | else |
---|
1661 | { |
---|
1662 | psDst->bandPosition = 0; |
---|
1663 | } |
---|
1664 | #endif |
---|
1665 | psDst->length = psSrc->length; |
---|
1666 | for (i=0;i<psDst->length;i++) |
---|
1667 | { |
---|
1668 | psDst->offset[i] = psSrc->offset[i]; |
---|
1669 | } |
---|
1670 | } |
---|
1671 | else |
---|
1672 | { |
---|
1673 | psDst->length = 0; |
---|
1674 | for (i=0;i<SAO_BO_LEN;i++) |
---|
1675 | { |
---|
1676 | psDst->offset[i] = 0; |
---|
1677 | } |
---|
1678 | } |
---|
1679 | } |
---|
1680 | |
---|
1681 | #if SAO_TYPE_SHARING |
---|
1682 | Void TDecSbac::parseSaoOffset(SaoLcuParam* psSaoLcuParam, UInt compIdx) |
---|
1683 | #else |
---|
1684 | Void TDecSbac::parseSaoOffset(SaoLcuParam* psSaoLcuParam) |
---|
1685 | #endif |
---|
1686 | { |
---|
1687 | UInt uiSymbol; |
---|
1688 | static Int iTypeLength[MAX_NUM_SAO_TYPE] = |
---|
1689 | { |
---|
1690 | SAO_EO_LEN, |
---|
1691 | SAO_EO_LEN, |
---|
1692 | SAO_EO_LEN, |
---|
1693 | SAO_EO_LEN, |
---|
1694 | SAO_BO_LEN |
---|
1695 | }; |
---|
1696 | |
---|
1697 | #if SAO_TYPE_SHARING |
---|
1698 | if (compIdx==2) |
---|
1699 | { |
---|
1700 | uiSymbol = (UInt)( psSaoLcuParam->typeIdx + 1); |
---|
1701 | } |
---|
1702 | else |
---|
1703 | { |
---|
1704 | parseSaoTypeIdx(uiSymbol); |
---|
1705 | } |
---|
1706 | #else |
---|
1707 | parseSaoTypeIdx(uiSymbol); |
---|
1708 | #endif |
---|
1709 | psSaoLcuParam->typeIdx = (Int)uiSymbol - 1; |
---|
1710 | if (uiSymbol) |
---|
1711 | { |
---|
1712 | psSaoLcuParam->length = iTypeLength[psSaoLcuParam->typeIdx]; |
---|
1713 | #if FULL_NBIT |
---|
1714 | Int offsetTh = 1 << ( min((Int)(g_uiBitDepth + (g_uiBitDepth-8)-5),5) ); |
---|
1715 | #else |
---|
1716 | Int offsetTh = 1 << ( min((Int)(g_uiBitDepth + g_uiBitIncrement-5),5) ); |
---|
1717 | #endif |
---|
1718 | |
---|
1719 | if( psSaoLcuParam->typeIdx == SAO_BO ) |
---|
1720 | { |
---|
1721 | #if !SAO_TYPE_CODING |
---|
1722 | // Parse Left Band Index |
---|
1723 | parseSaoUflc( uiSymbol ); |
---|
1724 | psSaoLcuParam->bandPosition = uiSymbol; |
---|
1725 | #endif |
---|
1726 | for(Int i=0; i< psSaoLcuParam->length; i++) |
---|
1727 | { |
---|
1728 | parseSaoMaxUvlc(uiSymbol, offsetTh -1 ); |
---|
1729 | psSaoLcuParam->offset[i] = uiSymbol; |
---|
1730 | } |
---|
1731 | for(Int i=0; i< psSaoLcuParam->length; i++) |
---|
1732 | { |
---|
1733 | if (psSaoLcuParam->offset[i] != 0) |
---|
1734 | { |
---|
1735 | m_pcTDecBinIf->decodeBinEP ( uiSymbol); |
---|
1736 | if (uiSymbol) |
---|
1737 | { |
---|
1738 | psSaoLcuParam->offset[i] = -psSaoLcuParam->offset[i] ; |
---|
1739 | } |
---|
1740 | } |
---|
1741 | } |
---|
1742 | #if SAO_TYPE_CODING |
---|
1743 | parseSaoUflc(5, uiSymbol ); |
---|
1744 | psSaoLcuParam->subTypeIdx = uiSymbol; |
---|
1745 | #endif |
---|
1746 | } |
---|
1747 | else if( psSaoLcuParam->typeIdx < 4 ) |
---|
1748 | { |
---|
1749 | parseSaoMaxUvlc(uiSymbol, offsetTh -1 ); psSaoLcuParam->offset[0] = uiSymbol; |
---|
1750 | parseSaoMaxUvlc(uiSymbol, offsetTh -1 ); psSaoLcuParam->offset[1] = uiSymbol; |
---|
1751 | parseSaoMaxUvlc(uiSymbol, offsetTh -1 ); psSaoLcuParam->offset[2] = -(Int)uiSymbol; |
---|
1752 | parseSaoMaxUvlc(uiSymbol, offsetTh -1 ); psSaoLcuParam->offset[3] = -(Int)uiSymbol; |
---|
1753 | #if SAO_TYPE_CODING |
---|
1754 | #if SAO_TYPE_SHARING |
---|
1755 | if (compIdx != 2) |
---|
1756 | { |
---|
1757 | parseSaoUflc(2, uiSymbol ); |
---|
1758 | psSaoLcuParam->subTypeIdx = uiSymbol; |
---|
1759 | psSaoLcuParam->typeIdx += psSaoLcuParam->subTypeIdx; |
---|
1760 | } |
---|
1761 | #else |
---|
1762 | parseSaoUflc(2, uiSymbol ); |
---|
1763 | psSaoLcuParam->subTypeIdx = uiSymbol; |
---|
1764 | psSaoLcuParam->typeIdx += psSaoLcuParam->subTypeIdx; |
---|
1765 | #endif |
---|
1766 | #endif |
---|
1767 | } |
---|
1768 | } |
---|
1769 | else |
---|
1770 | { |
---|
1771 | psSaoLcuParam->length = 0; |
---|
1772 | } |
---|
1773 | } |
---|
1774 | |
---|
1775 | Void TDecSbac::parseSaoOneLcuInterleaving(Int rx, Int ry, SAOParam* pSaoParam, TComDataCU* pcCU, Int iCUAddrInSlice, Int iCUAddrUpInSlice, Int allowMergeLeft, Int allowMergeUp) |
---|
1776 | { |
---|
1777 | Int iAddr = pcCU->getAddr(); |
---|
1778 | UInt uiSymbol; |
---|
1779 | #if SAO_SINGLE_MERGE |
---|
1780 | for (Int iCompIdx=0; iCompIdx<3; iCompIdx++) |
---|
1781 | { |
---|
1782 | pSaoParam->saoLcuParam[iCompIdx][iAddr].mergeUpFlag = 0; |
---|
1783 | pSaoParam->saoLcuParam[iCompIdx][iAddr].mergeLeftFlag = 0; |
---|
1784 | #if SAO_TYPE_CODING |
---|
1785 | pSaoParam->saoLcuParam[iCompIdx][iAddr].subTypeIdx = 0; |
---|
1786 | #else |
---|
1787 | pSaoParam->saoLcuParam[iCompIdx][iAddr].bandPosition = 0; |
---|
1788 | #endif |
---|
1789 | pSaoParam->saoLcuParam[iCompIdx][iAddr].typeIdx = -1; |
---|
1790 | pSaoParam->saoLcuParam[iCompIdx][iAddr].offset[0] = 0; |
---|
1791 | pSaoParam->saoLcuParam[iCompIdx][iAddr].offset[1] = 0; |
---|
1792 | pSaoParam->saoLcuParam[iCompIdx][iAddr].offset[2] = 0; |
---|
1793 | pSaoParam->saoLcuParam[iCompIdx][iAddr].offset[3] = 0; |
---|
1794 | |
---|
1795 | } |
---|
1796 | #if SAO_TYPE_SHARING |
---|
1797 | if (pSaoParam->bSaoFlag[0] || pSaoParam->bSaoFlag[1] ) |
---|
1798 | #else |
---|
1799 | if (pSaoParam->bSaoFlag[0] || pSaoParam->bSaoFlag[1] || pSaoParam->bSaoFlag[2]) |
---|
1800 | #endif |
---|
1801 | { |
---|
1802 | if (rx>0 && iCUAddrInSlice!=0 && allowMergeLeft) |
---|
1803 | { |
---|
1804 | #if SAO_MERGE_ONE_CTX |
---|
1805 | parseSaoMerge(uiSymbol); |
---|
1806 | pSaoParam->saoLcuParam[0][iAddr].mergeLeftFlag = (Bool)uiSymbol; |
---|
1807 | #else |
---|
1808 | parseSaoMergeLeft(uiSymbol, 0); |
---|
1809 | pSaoParam->saoLcuParam[0][iAddr].mergeLeftFlag = (Bool)uiSymbol; |
---|
1810 | #endif |
---|
1811 | } |
---|
1812 | if (pSaoParam->saoLcuParam[0][iAddr].mergeLeftFlag==0) |
---|
1813 | { |
---|
1814 | if ((ry > 0) && (iCUAddrUpInSlice>=0) && allowMergeUp) |
---|
1815 | { |
---|
1816 | #if SAO_MERGE_ONE_CTX |
---|
1817 | parseSaoMerge(uiSymbol); |
---|
1818 | pSaoParam->saoLcuParam[0][iAddr].mergeUpFlag = (Bool)uiSymbol; |
---|
1819 | #else |
---|
1820 | parseSaoMergeUp(uiSymbol); |
---|
1821 | pSaoParam->saoLcuParam[0][iAddr].mergeUpFlag = (Bool)uiSymbol; |
---|
1822 | #endif |
---|
1823 | } |
---|
1824 | } |
---|
1825 | } |
---|
1826 | #endif |
---|
1827 | |
---|
1828 | for (Int iCompIdx=0; iCompIdx<3; iCompIdx++) |
---|
1829 | { |
---|
1830 | #if !SAO_SINGLE_MERGE |
---|
1831 | pSaoParam->saoLcuParam[iCompIdx][iAddr].mergeUpFlag = 0; |
---|
1832 | pSaoParam->saoLcuParam[iCompIdx][iAddr].mergeLeftFlag = 0; |
---|
1833 | pSaoParam->saoLcuParam[iCompIdx][iAddr].bandPosition = 0; |
---|
1834 | pSaoParam->saoLcuParam[iCompIdx][iAddr].typeIdx = -1; |
---|
1835 | pSaoParam->saoLcuParam[iCompIdx][iAddr].offset[0] = 0; |
---|
1836 | pSaoParam->saoLcuParam[iCompIdx][iAddr].offset[1] = 0; |
---|
1837 | pSaoParam->saoLcuParam[iCompIdx][iAddr].offset[2] = 0; |
---|
1838 | pSaoParam->saoLcuParam[iCompIdx][iAddr].offset[3] = 0; |
---|
1839 | #endif |
---|
1840 | #if SAO_TYPE_SHARING |
---|
1841 | if ((iCompIdx == 0 && pSaoParam->bSaoFlag[0]) || (iCompIdx > 0 && pSaoParam->bSaoFlag[1]) ) |
---|
1842 | #else |
---|
1843 | if (pSaoParam->bSaoFlag[iCompIdx]) |
---|
1844 | #endif |
---|
1845 | { |
---|
1846 | if (rx>0 && iCUAddrInSlice!=0 && allowMergeLeft) |
---|
1847 | { |
---|
1848 | #if SAO_SINGLE_MERGE |
---|
1849 | pSaoParam->saoLcuParam[iCompIdx][iAddr].mergeLeftFlag = pSaoParam->saoLcuParam[0][iAddr].mergeLeftFlag; |
---|
1850 | #else |
---|
1851 | parseSaoMergeLeft(uiSymbol,iCompIdx); pSaoParam->saoLcuParam[iCompIdx][iAddr].mergeLeftFlag = (Int)uiSymbol; |
---|
1852 | #endif |
---|
1853 | } |
---|
1854 | else |
---|
1855 | { |
---|
1856 | pSaoParam->saoLcuParam[iCompIdx][iAddr].mergeLeftFlag = 0; |
---|
1857 | } |
---|
1858 | |
---|
1859 | if (pSaoParam->saoLcuParam[iCompIdx][iAddr].mergeLeftFlag==0) |
---|
1860 | { |
---|
1861 | if ((ry > 0) && (iCUAddrUpInSlice>=0) && allowMergeUp) |
---|
1862 | { |
---|
1863 | #if SAO_SINGLE_MERGE |
---|
1864 | pSaoParam->saoLcuParam[iCompIdx][iAddr].mergeUpFlag = pSaoParam->saoLcuParam[0][iAddr].mergeUpFlag; |
---|
1865 | #else |
---|
1866 | parseSaoMergeUp(uiSymbol); pSaoParam->saoLcuParam[iCompIdx][iAddr].mergeUpFlag = uiSymbol; |
---|
1867 | #endif |
---|
1868 | } |
---|
1869 | else |
---|
1870 | { |
---|
1871 | pSaoParam->saoLcuParam[iCompIdx][iAddr].mergeUpFlag = 0; |
---|
1872 | } |
---|
1873 | if (!pSaoParam->saoLcuParam[iCompIdx][iAddr].mergeUpFlag) |
---|
1874 | { |
---|
1875 | #if SAO_TYPE_SHARING |
---|
1876 | pSaoParam->saoLcuParam[2][iAddr].typeIdx = pSaoParam->saoLcuParam[1][iAddr].typeIdx; |
---|
1877 | parseSaoOffset(&(pSaoParam->saoLcuParam[iCompIdx][iAddr]), iCompIdx); |
---|
1878 | #else |
---|
1879 | parseSaoOffset(&(pSaoParam->saoLcuParam[iCompIdx][iAddr])); |
---|
1880 | #endif |
---|
1881 | } |
---|
1882 | else |
---|
1883 | { |
---|
1884 | copySaoOneLcuParam(&pSaoParam->saoLcuParam[iCompIdx][iAddr], &pSaoParam->saoLcuParam[iCompIdx][iAddr-pSaoParam->numCuInWidth]); |
---|
1885 | } |
---|
1886 | } |
---|
1887 | else |
---|
1888 | { |
---|
1889 | copySaoOneLcuParam(&pSaoParam->saoLcuParam[iCompIdx][iAddr], &pSaoParam->saoLcuParam[iCompIdx][iAddr-1]); |
---|
1890 | } |
---|
1891 | } |
---|
1892 | else |
---|
1893 | { |
---|
1894 | pSaoParam->saoLcuParam[iCompIdx][iAddr].typeIdx = -1; |
---|
1895 | #if SAO_TYPE_CODING |
---|
1896 | pSaoParam->saoLcuParam[iCompIdx][iAddr].subTypeIdx = 0; |
---|
1897 | #else |
---|
1898 | pSaoParam->saoLcuParam[iCompIdx][iAddr].bandPosition = 0; |
---|
1899 | #endif |
---|
1900 | } |
---|
1901 | } |
---|
1902 | } |
---|
1903 | |
---|
1904 | #if !REMOVE_ALF |
---|
1905 | Void TDecSbac::parseAlfCtrlFlag (Int compIdx, UInt& code) |
---|
1906 | { |
---|
1907 | UInt decodedSymbol; |
---|
1908 | m_pcTDecBinIf->decodeBin( decodedSymbol, m_cCUAlfCtrlFlagSCModel.get( 0, 0, 0 ) ); |
---|
1909 | code = decodedSymbol; |
---|
1910 | |
---|
1911 | DTRACE_CABAC_VL( g_nSymbolCounter++ ) |
---|
1912 | DTRACE_CABAC_T( "parseAlfCtrlFlag()" ) |
---|
1913 | DTRACE_CABAC_T( "\tsymbol=" ) |
---|
1914 | DTRACE_CABAC_V( decodedSymbol ) |
---|
1915 | DTRACE_CABAC_T( "\tcompIdx=" ) |
---|
1916 | DTRACE_CABAC_V( compIdx ) |
---|
1917 | DTRACE_CABAC_T( "\n" ) |
---|
1918 | } |
---|
1919 | #endif |
---|
1920 | |
---|
1921 | /** |
---|
1922 | - Initialize our contexts from the nominated source. |
---|
1923 | . |
---|
1924 | \param pSrc Contexts to be copied. |
---|
1925 | */ |
---|
1926 | Void TDecSbac::xCopyContextsFrom( TDecSbac* pSrc ) |
---|
1927 | { |
---|
1928 | memcpy(m_contextModels, pSrc->m_contextModels, m_numContextModels*sizeof(m_contextModels[0])); |
---|
1929 | } |
---|
1930 | |
---|
1931 | Void TDecSbac::xCopyFrom( TDecSbac* pSrc ) |
---|
1932 | { |
---|
1933 | m_pcTDecBinIf->copyState( pSrc->m_pcTDecBinIf ); |
---|
1934 | |
---|
1935 | m_uiLastQp = pSrc->m_uiLastQp; |
---|
1936 | xCopyContextsFrom( pSrc ); |
---|
1937 | |
---|
1938 | } |
---|
1939 | |
---|
1940 | Void TDecSbac::load ( TDecSbac* pScr ) |
---|
1941 | { |
---|
1942 | xCopyFrom(pScr); |
---|
1943 | } |
---|
1944 | |
---|
1945 | Void TDecSbac::loadContexts ( TDecSbac* pScr ) |
---|
1946 | { |
---|
1947 | xCopyContextsFrom(pScr); |
---|
1948 | } |
---|
1949 | |
---|
1950 | Void TDecSbac::decodeFlush ( ) |
---|
1951 | { |
---|
1952 | UInt uiBit; |
---|
1953 | m_pcTDecBinIf->decodeBinTrm(uiBit); |
---|
1954 | m_pcTDecBinIf->flush(); |
---|
1955 | |
---|
1956 | } |
---|
1957 | //! \} |
---|