1 | |
---|
2 | |
---|
3 | /** \file TDecCAVLC.cpp |
---|
4 | \brief CAVLC decoder class |
---|
5 | */ |
---|
6 | |
---|
7 | #include "TDecCAVLC.h" |
---|
8 | #include "SEIread.h" |
---|
9 | |
---|
10 | // ==================================================================================================================== |
---|
11 | // Constructor / destructor / create / destroy |
---|
12 | // ==================================================================================================================== |
---|
13 | |
---|
14 | TDecCavlc::TDecCavlc() |
---|
15 | { |
---|
16 | m_bAlfCtrl = false; |
---|
17 | m_uiMaxAlfCtrlDepth = 0; |
---|
18 | |
---|
19 | m_aaiTempScale = new Int* [ MAX_NUMBER_VIEWS ]; |
---|
20 | m_aaiTempOffset = new Int* [ MAX_NUMBER_VIEWS ]; |
---|
21 | m_aaiTempPdmScaleNomDelta = new Int* [ MAX_NUMBER_VIEWS ]; |
---|
22 | m_aaiTempPdmOffset = new Int* [ MAX_NUMBER_VIEWS ]; |
---|
23 | for( UInt uiVId = 0; uiVId < MAX_NUMBER_VIEWS; uiVId++ ) |
---|
24 | { |
---|
25 | m_aaiTempScale [ uiVId ] = new Int [ MAX_NUMBER_VIEWS ]; |
---|
26 | m_aaiTempOffset [ uiVId ] = new Int [ MAX_NUMBER_VIEWS ]; |
---|
27 | m_aaiTempPdmScaleNomDelta [ uiVId ] = new Int [ MAX_NUMBER_VIEWS ]; |
---|
28 | m_aaiTempPdmOffset [ uiVId ] = new Int [ MAX_NUMBER_VIEWS ]; |
---|
29 | } |
---|
30 | } |
---|
31 | |
---|
32 | TDecCavlc::~TDecCavlc() |
---|
33 | { |
---|
34 | for( UInt uiVId = 0; uiVId < MAX_NUMBER_VIEWS; uiVId++ ) |
---|
35 | { |
---|
36 | delete [] m_aaiTempScale [ uiVId ]; |
---|
37 | delete [] m_aaiTempOffset [ uiVId ]; |
---|
38 | delete [] m_aaiTempPdmScaleNomDelta [ uiVId ]; |
---|
39 | delete [] m_aaiTempPdmOffset [ uiVId ]; |
---|
40 | } |
---|
41 | delete [] m_aaiTempScale; |
---|
42 | delete [] m_aaiTempOffset; |
---|
43 | delete [] m_aaiTempPdmScaleNomDelta; |
---|
44 | delete [] m_aaiTempPdmOffset; |
---|
45 | } |
---|
46 | |
---|
47 | // ==================================================================================================================== |
---|
48 | // Public member functions |
---|
49 | // ==================================================================================================================== |
---|
50 | |
---|
51 | Void TDecCavlc::parseNalUnitHeader ( NalUnitType& eNalUnitType, UInt& TemporalId, Bool& bOutputFlag ) |
---|
52 | { |
---|
53 | UInt uiCode; |
---|
54 | |
---|
55 | xReadCode ( 1, uiCode ); assert( 0 == uiCode); // forbidden_zero_bit |
---|
56 | xReadCode ( 2, uiCode ); // nal_ref_idc |
---|
57 | xReadCode ( 5, uiCode ); // nal_unit_type |
---|
58 | eNalUnitType = (NalUnitType) uiCode; |
---|
59 | |
---|
60 | if ( (eNalUnitType == NAL_UNIT_CODED_SLICE) || (eNalUnitType == NAL_UNIT_CODED_SLICE_IDR) || (eNalUnitType == NAL_UNIT_CODED_SLICE_CDR) ) |
---|
61 | { |
---|
62 | xReadCode(3, uiCode); // temporal_id |
---|
63 | TemporalId = uiCode; |
---|
64 | xReadFlag(uiCode); // output_flag |
---|
65 | bOutputFlag = (0!=uiCode); |
---|
66 | xReadCode(4, uiCode); // reserved_one_4bits |
---|
67 | } |
---|
68 | else |
---|
69 | { |
---|
70 | TemporalId = 0; |
---|
71 | bOutputFlag = true; |
---|
72 | } |
---|
73 | } |
---|
74 | |
---|
75 | /** |
---|
76 | * unmarshal a sequence of SEI messages from bitstream. |
---|
77 | */ |
---|
78 | void TDecCavlc::parseSEI(SEImessages& seis) |
---|
79 | { |
---|
80 | assert(!m_pcBitstream->getBitsUntilByteAligned()); |
---|
81 | do { |
---|
82 | parseSEImessage(*m_pcBitstream, seis); |
---|
83 | /* SEI messages are an integer number of bytes, something has failed |
---|
84 | * in the parsing if bitstream not byte-aligned */ |
---|
85 | assert(!m_pcBitstream->getBitsUntilByteAligned()); |
---|
86 | } while (0x80 != m_pcBitstream->peekBits(8)); |
---|
87 | assert(m_pcBitstream->getBitsLeft() == 8); /* rsbp_trailing_bits */ |
---|
88 | } |
---|
89 | |
---|
90 | Void TDecCavlc::parsePPS(TComPPS* pcPPS) |
---|
91 | { |
---|
92 | UInt uiCode; |
---|
93 | |
---|
94 | xReadUvlc( uiCode ); pcPPS->setPPSId( uiCode ); |
---|
95 | xReadUvlc( uiCode ); pcPPS->setSPSId( uiCode ); |
---|
96 | #if CONSTRAINED_INTRA_PRED |
---|
97 | xReadFlag ( uiCode ); pcPPS->setConstrainedIntraPred( uiCode ? true : false ); |
---|
98 | #endif |
---|
99 | |
---|
100 | #ifdef WEIGHT_PRED |
---|
101 | xReadCode( 1, uiCode ); // Use of Weighting Prediction (P_SLICE) |
---|
102 | pcPPS->setUseWP( uiCode==1 ); |
---|
103 | xReadCode( 2, uiCode ); // Use of Bi-Directional Weighting Prediction (B_SLICE) |
---|
104 | pcPPS->setWPBiPredIdc( uiCode ); |
---|
105 | printf("TDecCavlc::parsePPS():\tm_bUseWeightPred=%d\tm_uiBiPredIdc=%d\n", pcPPS->getUseWP(), pcPPS->getWPBiPredIdc()); |
---|
106 | #endif |
---|
107 | return; |
---|
108 | } |
---|
109 | |
---|
110 | Void TDecCavlc::parseSPS(TComSPS* pcSPS) |
---|
111 | { |
---|
112 | UInt uiCode; |
---|
113 | Int iCode; |
---|
114 | |
---|
115 | // Structure |
---|
116 | xReadUvlc ( uiCode ); pcSPS->setSPSId ( uiCode ); |
---|
117 | xReadUvlc ( uiCode ); pcSPS->setWidth ( uiCode ); |
---|
118 | xReadUvlc ( uiCode ); pcSPS->setHeight ( uiCode ); |
---|
119 | xReadUvlc ( uiCode ); pcSPS->setPadX ( uiCode ); |
---|
120 | xReadUvlc ( uiCode ); pcSPS->setPadY ( uiCode ); |
---|
121 | |
---|
122 | xReadUvlc ( uiCode ); |
---|
123 | pcSPS->setMaxCUWidth ( uiCode ); g_uiMaxCUWidth = uiCode; |
---|
124 | pcSPS->setMaxCUHeight ( uiCode ); g_uiMaxCUHeight = uiCode; |
---|
125 | |
---|
126 | xReadUvlc ( uiCode ); |
---|
127 | pcSPS->setMaxCUDepth ( uiCode+1 ); g_uiMaxCUDepth = uiCode + 1; |
---|
128 | UInt uiMaxCUDepthCorrect = uiCode; |
---|
129 | |
---|
130 | xReadUvlc( uiCode ); pcSPS->setQuadtreeTULog2MinSize( uiCode + 2 ); |
---|
131 | xReadUvlc( uiCode ); pcSPS->setQuadtreeTULog2MaxSize( uiCode + pcSPS->getQuadtreeTULog2MinSize() ); |
---|
132 | pcSPS->setMaxTrSize( 1<<(uiCode + pcSPS->getQuadtreeTULog2MinSize()) ); |
---|
133 | xReadUvlc ( uiCode ); pcSPS->setQuadtreeTUMaxDepthInter( uiCode+1 ); |
---|
134 | xReadUvlc ( uiCode ); pcSPS->setQuadtreeTUMaxDepthIntra( uiCode+1 ); |
---|
135 | g_uiAddCUDepth = 0; |
---|
136 | while( ( pcSPS->getMaxCUWidth() >> uiMaxCUDepthCorrect ) > ( 1 << ( pcSPS->getQuadtreeTULog2MinSize() + g_uiAddCUDepth ) ) ) g_uiAddCUDepth++; |
---|
137 | pcSPS->setMaxCUDepth( uiMaxCUDepthCorrect+g_uiAddCUDepth ); g_uiMaxCUDepth = uiMaxCUDepthCorrect+g_uiAddCUDepth; |
---|
138 | // BB: these parameters may be removed completly and replaced by the fixed values |
---|
139 | pcSPS->setMinTrDepth( 0 ); |
---|
140 | pcSPS->setMaxTrDepth( 1 ); |
---|
141 | |
---|
142 | xReadUvlc( uiCode ); pcSPS->setCodedPictureBufferSize( uiCode ); |
---|
143 | |
---|
144 | // Tool on/off |
---|
145 | xReadFlag( uiCode ); pcSPS->setUseALF ( uiCode ? true : false ); |
---|
146 | xReadFlag( uiCode ); pcSPS->setUseDQP ( uiCode ? true : false ); |
---|
147 | #if !SB_NO_LowDelayCoding |
---|
148 | xReadFlag( uiCode ); pcSPS->setUseLDC ( uiCode ? true : false ); |
---|
149 | #endif |
---|
150 | xReadFlag( uiCode ); pcSPS->setUseMRG ( uiCode ? true : false ); // SOPH: |
---|
151 | |
---|
152 | #if LM_CHROMA |
---|
153 | xReadFlag( uiCode ); pcSPS->setUseLMChroma ( uiCode ? true : false ); |
---|
154 | #endif |
---|
155 | |
---|
156 | #if HHI_RMP_SWITCH |
---|
157 | xReadFlag( uiCode ); pcSPS->setUseRMP( uiCode ? true : false ); |
---|
158 | #endif |
---|
159 | |
---|
160 | // AMVP mode for each depth (AM_NONE or AM_EXPL) |
---|
161 | for (Int i = 0; i < pcSPS->getMaxCUDepth(); i++) |
---|
162 | { |
---|
163 | xReadFlag( uiCode ); |
---|
164 | pcSPS->setAMVPMode( i, (AMVP_MODE)uiCode ); |
---|
165 | } |
---|
166 | |
---|
167 | // Bit-depth information |
---|
168 | #if FULL_NBIT |
---|
169 | xReadUvlc( uiCode ); |
---|
170 | g_uiBitDepth = 8 + uiCode; |
---|
171 | g_uiBitIncrement = 0; |
---|
172 | pcSPS->setBitDepth(g_uiBitDepth); |
---|
173 | pcSPS->setBitIncrement(g_uiBitIncrement); |
---|
174 | #else |
---|
175 | #if ENABLE_IBDI |
---|
176 | xReadUvlc( uiCode ); pcSPS->setBitDepth ( uiCode+8 ); g_uiBitDepth = uiCode + 8; |
---|
177 | xReadUvlc( uiCode ); pcSPS->setBitIncrement ( uiCode ); g_uiBitIncrement = uiCode; |
---|
178 | #else |
---|
179 | xReadUvlc( uiCode ); |
---|
180 | g_uiBitDepth = 8; |
---|
181 | g_uiBitIncrement = uiCode; |
---|
182 | pcSPS->setBitDepth(g_uiBitDepth); |
---|
183 | pcSPS->setBitIncrement(g_uiBitIncrement); |
---|
184 | #endif |
---|
185 | #endif |
---|
186 | |
---|
187 | g_uiBASE_MAX = ((1<<(g_uiBitDepth))-1); |
---|
188 | |
---|
189 | #if IBDI_NOCLIP_RANGE |
---|
190 | g_uiIBDI_MAX = g_uiBASE_MAX << g_uiBitIncrement; |
---|
191 | #else |
---|
192 | g_uiIBDI_MAX = ((1<<(g_uiBitDepth+g_uiBitIncrement))-1); |
---|
193 | #endif |
---|
194 | |
---|
195 | #if HHI_DMM_INTRA |
---|
196 | g_dDeltaDCsQuantOffset = Double(g_uiBitIncrement) - 2.0; |
---|
197 | #endif |
---|
198 | |
---|
199 | #if MTK_NONCROSS_INLOOP_FILTER |
---|
200 | xReadFlag( uiCode ); |
---|
201 | pcSPS->setLFCrossSliceBoundaryFlag( uiCode ? true : false); |
---|
202 | #endif |
---|
203 | #if MTK_SAO |
---|
204 | xReadFlag( uiCode ); pcSPS->setUseSAO ( uiCode ? true : false ); |
---|
205 | #endif |
---|
206 | |
---|
207 | xReadFlag( uiCode ); // SPS base view flag |
---|
208 | if( uiCode ) |
---|
209 | { // baseview SPS -> set standard values |
---|
210 | pcSPS->initMultiviewSPS ( 0 ); |
---|
211 | pcSPS->setPredDepthMapGeneration( 0, false ); |
---|
212 | pcSPS->setMultiviewResPredMode ( 0 ); |
---|
213 | } |
---|
214 | else |
---|
215 | { |
---|
216 | xReadFlag ( uiCode ); // depth flag |
---|
217 | if( uiCode ) |
---|
218 | { |
---|
219 | xReadUvlc( uiCode ); // view id |
---|
220 | xReadSvlc( iCode ); // view order index |
---|
221 | pcSPS->initMultiviewSPSDepth ( uiCode, iCode ); |
---|
222 | pcSPS->setPredDepthMapGeneration( uiCode, true ); |
---|
223 | pcSPS->setMultiviewResPredMode ( 0 ); |
---|
224 | #if HHI_DMM_INTRA |
---|
225 | xReadFlag( uiCode ); |
---|
226 | pcSPS->setUseDepthModelModes( uiCode ? true : false ); |
---|
227 | #endif |
---|
228 | xReadFlag( uiCode ); |
---|
229 | pcSPS->setUseMVI( uiCode ? true : false ); |
---|
230 | } |
---|
231 | else |
---|
232 | { |
---|
233 | UInt uiViewId, uiCamParPrecision; |
---|
234 | Int iVOI; |
---|
235 | Bool bCamParSlice; |
---|
236 | xReadUvlc( uiViewId ); uiViewId++; |
---|
237 | xReadSvlc( iVOI ); |
---|
238 | xReadUvlc( uiCamParPrecision ); |
---|
239 | xReadFlag( uiCode ); bCamParSlice = ( uiCode == 1 ); |
---|
240 | if( !bCamParSlice ) |
---|
241 | { |
---|
242 | for( UInt uiBaseId = 0; uiBaseId < uiViewId; uiBaseId++ ) |
---|
243 | { |
---|
244 | xReadSvlc( iCode ); m_aaiTempScale [ uiBaseId ][ uiViewId ] = iCode; |
---|
245 | xReadSvlc( iCode ); m_aaiTempOffset[ uiBaseId ][ uiViewId ] = iCode; |
---|
246 | xReadSvlc( iCode ); m_aaiTempScale [ uiViewId ][ uiBaseId ] = iCode - m_aaiTempScale [ uiBaseId ][ uiViewId ]; |
---|
247 | xReadSvlc( iCode ); m_aaiTempOffset[ uiViewId ][ uiBaseId ] = iCode - m_aaiTempOffset[ uiBaseId ][ uiViewId ]; |
---|
248 | } |
---|
249 | } |
---|
250 | pcSPS->initMultiviewSPS( uiViewId, iVOI, uiCamParPrecision, bCamParSlice, m_aaiTempScale, m_aaiTempOffset ); |
---|
251 | |
---|
252 | UInt uiPredDepthMapGeneration = 0, uiMultiviewMvPredMode = 0, uiPdmPrecision = 0, uiMultiviewResPredMode = 0; |
---|
253 | xReadUvlc( uiPredDepthMapGeneration ); |
---|
254 | if( uiPredDepthMapGeneration ) |
---|
255 | { |
---|
256 | xReadUvlc ( uiPdmPrecision ); |
---|
257 | for( UInt uiBaseId = 0; uiBaseId < uiViewId; uiBaseId++ ) |
---|
258 | { |
---|
259 | xReadSvlc( iCode ); m_aaiTempPdmScaleNomDelta[ uiViewId ][ uiBaseId ] = iCode; |
---|
260 | xReadSvlc( iCode ); m_aaiTempPdmOffset [ uiViewId ][ uiBaseId ] = iCode; |
---|
261 | } |
---|
262 | xReadUvlc ( uiMultiviewMvPredMode ); |
---|
263 | xReadFlag ( uiMultiviewResPredMode ); |
---|
264 | } |
---|
265 | pcSPS->setPredDepthMapGeneration( uiViewId, false, uiPredDepthMapGeneration, uiMultiviewMvPredMode, uiPdmPrecision, m_aaiTempPdmScaleNomDelta, m_aaiTempPdmOffset ); |
---|
266 | pcSPS->setMultiviewResPredMode ( uiMultiviewResPredMode ); |
---|
267 | pcSPS->setUseMVI( false ); |
---|
268 | } |
---|
269 | } |
---|
270 | |
---|
271 | return; |
---|
272 | } |
---|
273 | |
---|
274 | Void TDecCavlc::parseSliceHeader (TComSlice*& rpcSlice) |
---|
275 | { |
---|
276 | UInt uiCode; |
---|
277 | Int iCode; |
---|
278 | |
---|
279 | xReadFlag ( uiCode ); |
---|
280 | Bool bEntropySlice = uiCode ? true : false; |
---|
281 | if (!bEntropySlice) |
---|
282 | { |
---|
283 | xReadUvlc ( uiCode ); rpcSlice->setPPSId( uiCode ); |
---|
284 | xReadCode (10, uiCode); rpcSlice->setPOC (uiCode); // 9 == SPS->Log2MaxFrameNum() |
---|
285 | xReadUvlc ( uiCode); rpcSlice->setSliceType ((SliceType)uiCode); |
---|
286 | xReadSvlc ( iCode); rpcSlice->setSliceQp (iCode); |
---|
287 | } |
---|
288 | if (bEntropySlice) |
---|
289 | { |
---|
290 | rpcSlice->setNextSlice ( false ); |
---|
291 | rpcSlice->setNextEntropySlice ( true ); |
---|
292 | |
---|
293 | xReadUvlc(uiCode); |
---|
294 | rpcSlice->setEntropySliceCurStartCUAddr( uiCode ); // start CU addr for entropy slice |
---|
295 | } |
---|
296 | else |
---|
297 | { |
---|
298 | rpcSlice->setNextSlice ( true ); |
---|
299 | rpcSlice->setNextEntropySlice ( false ); |
---|
300 | |
---|
301 | xReadUvlc(uiCode); |
---|
302 | rpcSlice->setSliceCurStartCUAddr( uiCode ); // start CU addr for slice |
---|
303 | rpcSlice->setEntropySliceCurStartCUAddr( uiCode ); // start CU addr for entropy slice |
---|
304 | |
---|
305 | xReadFlag ( uiCode ); |
---|
306 | rpcSlice->setSymbolMode( uiCode ); |
---|
307 | |
---|
308 | if (!rpcSlice->isIntra()) |
---|
309 | xReadFlag ( uiCode); |
---|
310 | else |
---|
311 | uiCode = 1; |
---|
312 | |
---|
313 | rpcSlice->setReferenced (uiCode ? true : false); |
---|
314 | |
---|
315 | #if !HIGH_ACCURACY_BI |
---|
316 | #ifdef ROUNDING_CONTROL_BIPRED |
---|
317 | if(!rpcSlice->isIntra()) |
---|
318 | { |
---|
319 | xReadFlag( uiCode ); |
---|
320 | Bool b = (uiCode != 0); |
---|
321 | rpcSlice->setRounding(b); |
---|
322 | } |
---|
323 | #endif |
---|
324 | #else |
---|
325 | #if !HIGH_ACCURACY_BI |
---|
326 | if(!rpcSlice->isIntra()) |
---|
327 | { |
---|
328 | rpcSlice->setRounding(false); |
---|
329 | } |
---|
330 | #endif |
---|
331 | #endif |
---|
332 | |
---|
333 | xReadFlag ( uiCode); rpcSlice->setLoopFilterDisable(uiCode ? 1 : 0); |
---|
334 | |
---|
335 | if (!rpcSlice->isIntra()) |
---|
336 | { |
---|
337 | xReadCode (3, uiCode); rpcSlice->setNumRefIdx (REF_PIC_LIST_0, uiCode); |
---|
338 | } |
---|
339 | else |
---|
340 | { |
---|
341 | rpcSlice->setNumRefIdx(REF_PIC_LIST_0, 0); |
---|
342 | } |
---|
343 | if (rpcSlice->isInterB()) |
---|
344 | { |
---|
345 | xReadCode (3, uiCode); rpcSlice->setNumRefIdx (REF_PIC_LIST_1, uiCode); |
---|
346 | } |
---|
347 | else |
---|
348 | { |
---|
349 | rpcSlice->setNumRefIdx(REF_PIC_LIST_1, 0); |
---|
350 | } |
---|
351 | |
---|
352 | if (!rpcSlice->isIntra()) |
---|
353 | { |
---|
354 | for(Int i = 0; i<rpcSlice->getNumRefIdx(REF_PIC_LIST_0);i++) |
---|
355 | { |
---|
356 | xReadFlag( uiCode ) ; |
---|
357 | if( uiCode ) // interview |
---|
358 | { |
---|
359 | xReadUvlc( uiCode ) ; |
---|
360 | rpcSlice->setRefViewIdx(uiCode, REF_PIC_LIST_0, i) ; |
---|
361 | rpcSlice->setRefPOC(rpcSlice->getPOC(), REF_PIC_LIST_0, i) ; |
---|
362 | } |
---|
363 | else |
---|
364 | { |
---|
365 | xReadSvlc( iCode ) ; |
---|
366 | rpcSlice->setRefPOC(rpcSlice->getPOC()-iCode, REF_PIC_LIST_0, i) ; |
---|
367 | rpcSlice->setRefViewIdx(rpcSlice->getViewIdx(), REF_PIC_LIST_0, i) ; |
---|
368 | } |
---|
369 | } |
---|
370 | } |
---|
371 | else |
---|
372 | { |
---|
373 | rpcSlice->setNumRefIdx(REF_PIC_LIST_0, 0); |
---|
374 | } |
---|
375 | if( rpcSlice->isInterB()) |
---|
376 | { |
---|
377 | for(Int i = 0; i<rpcSlice->getNumRefIdx(REF_PIC_LIST_1);i++) |
---|
378 | { |
---|
379 | xReadFlag( uiCode ) ; |
---|
380 | if( uiCode ) // interview |
---|
381 | { |
---|
382 | xReadUvlc( uiCode ) ; |
---|
383 | rpcSlice->setRefViewIdx(uiCode, REF_PIC_LIST_1, i) ; |
---|
384 | rpcSlice->setRefPOC(rpcSlice->getPOC(), REF_PIC_LIST_1, i) ; |
---|
385 | } |
---|
386 | else |
---|
387 | { |
---|
388 | xReadSvlc( iCode ) ; |
---|
389 | rpcSlice->setRefPOC(rpcSlice->getPOC()-iCode, REF_PIC_LIST_1, i) ; |
---|
390 | rpcSlice->setRefViewIdx(rpcSlice->getViewIdx(), REF_PIC_LIST_1, i) ; |
---|
391 | } |
---|
392 | } |
---|
393 | } |
---|
394 | else |
---|
395 | { |
---|
396 | rpcSlice->setNumRefIdx(REF_PIC_LIST_1, 0); |
---|
397 | } |
---|
398 | |
---|
399 | #if DCM_COMB_LIST |
---|
400 | if (rpcSlice->isInterB()) |
---|
401 | { |
---|
402 | xReadFlag (uiCode); rpcSlice->setRefPicListCombinationFlag(uiCode ? 1 : 0); |
---|
403 | if(uiCode) |
---|
404 | { |
---|
405 | xReadUvlc(uiCode); rpcSlice->setNumRefIdx (REF_PIC_LIST_C, uiCode+1); |
---|
406 | |
---|
407 | xReadFlag (uiCode); rpcSlice->setRefPicListModificationFlagLC(uiCode ? 1 : 0); |
---|
408 | if(uiCode) |
---|
409 | { |
---|
410 | for (UInt i=0;i<rpcSlice->getNumRefIdx(REF_PIC_LIST_C);i++) |
---|
411 | { |
---|
412 | xReadFlag(uiCode); |
---|
413 | rpcSlice->setListIdFromIdxOfLC(i, uiCode); |
---|
414 | xReadUvlc(uiCode); |
---|
415 | rpcSlice->setRefIdxFromIdxOfLC(i, uiCode); |
---|
416 | rpcSlice->setRefIdxOfLC((RefPicList)rpcSlice->getListIdFromIdxOfLC(i), rpcSlice->getRefIdxFromIdxOfLC(i), i); |
---|
417 | } |
---|
418 | } |
---|
419 | } |
---|
420 | else |
---|
421 | { |
---|
422 | rpcSlice->setRefPicListCombinationFlag(false); |
---|
423 | rpcSlice->setRefPicListModificationFlagLC(false); |
---|
424 | rpcSlice->setNumRefIdx(REF_PIC_LIST_C, -1); |
---|
425 | } |
---|
426 | } |
---|
427 | #endif |
---|
428 | |
---|
429 | #if AMVP_NEIGH_COL |
---|
430 | if ( rpcSlice->getSliceType() == B_SLICE ) |
---|
431 | { |
---|
432 | xReadFlag (uiCode); |
---|
433 | rpcSlice->setColDir(uiCode); |
---|
434 | } |
---|
435 | #endif |
---|
436 | |
---|
437 | #ifdef WEIGHT_PRED |
---|
438 | if ( (rpcSlice->getPPS()->getUseWP() && rpcSlice->getSliceType()==P_SLICE) || (rpcSlice->getPPS()->getWPBiPredIdc() && rpcSlice->getSliceType()==B_SLICE) ) |
---|
439 | { |
---|
440 | parseWeightPredTable(rpcSlice); |
---|
441 | rpcSlice->initWpScaling(); |
---|
442 | rpcSlice->displayWpScaling(); |
---|
443 | } |
---|
444 | #endif |
---|
445 | if( rpcSlice->getPPS()->getPPSId() != rpcSlice->getPPSId() ) |
---|
446 | { |
---|
447 | return; |
---|
448 | } |
---|
449 | |
---|
450 | |
---|
451 | if( rpcSlice->getSPS()->hasCamParInSliceHeader() ) |
---|
452 | { |
---|
453 | UInt uiViewId = rpcSlice->getSPS()->getViewId(); |
---|
454 | for( UInt uiBaseId = 0; uiBaseId < uiViewId; uiBaseId++ ) |
---|
455 | { |
---|
456 | xReadSvlc( iCode ); m_aaiTempScale [ uiBaseId ][ uiViewId ] = iCode; |
---|
457 | xReadSvlc( iCode ); m_aaiTempOffset[ uiBaseId ][ uiViewId ] = iCode; |
---|
458 | xReadSvlc( iCode ); m_aaiTempScale [ uiViewId ][ uiBaseId ] = iCode - m_aaiTempScale [ uiBaseId ][ uiViewId ]; |
---|
459 | xReadSvlc( iCode ); m_aaiTempOffset[ uiViewId ][ uiBaseId ] = iCode - m_aaiTempOffset[ uiBaseId ][ uiViewId ]; |
---|
460 | } |
---|
461 | rpcSlice->initMultiviewSlice( m_aaiTempScale, m_aaiTempOffset ); |
---|
462 | } |
---|
463 | } |
---|
464 | return; |
---|
465 | } |
---|
466 | |
---|
467 | Void TDecCavlc::resetEntropy (TComSlice* pcSlice) |
---|
468 | { |
---|
469 | m_bRunLengthCoding = ! pcSlice->isIntra(); |
---|
470 | m_uiRun = 0; |
---|
471 | |
---|
472 | #if !CAVLC_COEF_LRG_BLK |
---|
473 | ::memcpy(m_uiLPTableD8, g_auiLPTableD8, 10*128*sizeof(UInt)); |
---|
474 | #endif |
---|
475 | ::memcpy(m_uiLPTableD4, g_auiLPTableD4, 3*32*sizeof(UInt)); |
---|
476 | ::memcpy(m_uiLastPosVlcIndex, g_auiLastPosVlcIndex, 10*sizeof(UInt)); |
---|
477 | |
---|
478 | #if CAVLC_RQT_CBP |
---|
479 | ::memcpy(m_uiCBP_YUV_TableD, g_auiCBP_YUV_TableD, 4*8*sizeof(UInt)); |
---|
480 | ::memcpy(m_uiCBP_YS_TableD, g_auiCBP_YS_TableD, 2*4*sizeof(UInt)); |
---|
481 | ::memcpy(m_uiCBP_YCS_TableD, g_auiCBP_YCS_TableD, 2*8*sizeof(UInt)); |
---|
482 | ::memcpy(m_uiCBP_4Y_TableD, g_auiCBP_4Y_TableD, 2*15*sizeof(UInt)); |
---|
483 | m_uiCBP_4Y_VlcIdx = 0; |
---|
484 | #else |
---|
485 | m_uiCbpVlcIdx[0] = 0; |
---|
486 | m_uiCbpVlcIdx[1] = 0; |
---|
487 | ::memcpy(m_uiCBPTableD, g_auiCBPTableD, 2*8*sizeof(UInt)); |
---|
488 | ::memcpy(m_uiBlkCBPTableD, g_auiBlkCBPTableD, 2*15*sizeof(UInt)); |
---|
489 | m_uiBlkCbpVlcIdx = 0; |
---|
490 | #endif |
---|
491 | |
---|
492 | #if UNIFY_INTER_TABLE |
---|
493 | ::memcpy(m_uiMI1TableD, g_auiComMI1TableD, 9*sizeof(UInt)); |
---|
494 | #else |
---|
495 | ::memcpy(m_uiMI1TableD, g_auiMI1TableD, 8*sizeof(UInt)); |
---|
496 | ::memcpy(m_uiMI2TableD, g_auiMI2TableD, 15*sizeof(UInt)); |
---|
497 | |
---|
498 | #if DCM_COMB_LIST |
---|
499 | if ( pcSlice->getNoBackPredFlag() || pcSlice->getNumRefIdx(REF_PIC_LIST_C)>0) |
---|
500 | #else |
---|
501 | if ( pcSlice->getNoBackPredFlag() ) |
---|
502 | #endif |
---|
503 | { |
---|
504 | ::memcpy(m_uiMI1TableD, g_auiMI1TableDNoL1, 8*sizeof(UInt)); |
---|
505 | ::memcpy(m_uiMI2TableD, g_auiMI2TableDNoL1, 15*sizeof(UInt)); |
---|
506 | } |
---|
507 | |
---|
508 | #if MS_LCEC_ONE_FRAME |
---|
509 | if ( pcSlice->getNumRefIdx(REF_PIC_LIST_0) <= 1 && pcSlice->getNumRefIdx(REF_PIC_LIST_1) <= 1 ) |
---|
510 | { |
---|
511 | if ( pcSlice->getNoBackPredFlag() || ( pcSlice->getNumRefIdx(REF_PIC_LIST_C) > 0 && pcSlice->getNumRefIdx(REF_PIC_LIST_C) <= 1 ) ) |
---|
512 | { |
---|
513 | ::memcpy(m_uiMI1TableD, g_auiMI1TableDOnly1RefNoL1, 8*sizeof(UInt)); |
---|
514 | } |
---|
515 | else |
---|
516 | { |
---|
517 | ::memcpy(m_uiMI1TableD, g_auiMI1TableDOnly1Ref, 8*sizeof(UInt)); |
---|
518 | } |
---|
519 | } |
---|
520 | #endif |
---|
521 | #if MS_LCEC_LOOKUP_TABLE_EXCEPTION |
---|
522 | if (pcSlice->getNumRefIdx(REF_PIC_LIST_C)>0) |
---|
523 | { |
---|
524 | m_uiMI1TableD[8] = 8; |
---|
525 | } |
---|
526 | else // GPB case |
---|
527 | { |
---|
528 | m_uiMI1TableD[8] = m_uiMI1TableD[6]; |
---|
529 | m_uiMI1TableD[6] = 8; |
---|
530 | } |
---|
531 | #endif |
---|
532 | #endif |
---|
533 | |
---|
534 | #if LCEC_INTRA_MODE |
---|
535 | #if MTK_DCM_MPM |
---|
536 | ::memcpy(m_uiIntraModeTableD17[0], g_auiIntraModeTableD17[0], 16*sizeof(UInt)); |
---|
537 | ::memcpy(m_uiIntraModeTableD34[0], g_auiIntraModeTableD34[0], 33*sizeof(UInt)); |
---|
538 | ::memcpy(m_uiIntraModeTableD17[1], g_auiIntraModeTableD17[1], 16*sizeof(UInt)); |
---|
539 | ::memcpy(m_uiIntraModeTableD34[1], g_auiIntraModeTableD34[1], 33*sizeof(UInt)); |
---|
540 | #else |
---|
541 | ::memcpy(m_uiIntraModeTableD17, g_auiIntraModeTableD17, 16*sizeof(UInt)); |
---|
542 | ::memcpy(m_uiIntraModeTableD34, g_auiIntraModeTableD34, 33*sizeof(UInt)); |
---|
543 | #endif |
---|
544 | #endif |
---|
545 | #if QC_LCEC_INTER_MODE |
---|
546 | ::memcpy(m_uiSplitTableD, g_auiInterModeTableD, 4*7*sizeof(UInt)); |
---|
547 | #endif |
---|
548 | m_uiMITableVlcIdx = 0; |
---|
549 | |
---|
550 | #if CAVLC_COUNTER_ADAPT |
---|
551 | #if CAVLC_RQT_CBP |
---|
552 | ::memset(m_ucCBP_YUV_TableCounter, 0, 4*4*sizeof(UChar)); |
---|
553 | ::memset(m_ucCBP_4Y_TableCounter, 0, 2*2*sizeof(UChar)); |
---|
554 | ::memset(m_ucCBP_YCS_TableCounter, 0, 2*4*sizeof(UChar)); |
---|
555 | ::memset(m_ucCBP_YS_TableCounter, 0, 2*3*sizeof(UChar)); |
---|
556 | #else |
---|
557 | ::memset(m_ucCBFTableCounter, 0, 2*4*sizeof(UChar)); |
---|
558 | ::memset(m_ucBlkCBPTableCounter, 0, 2*2*sizeof(UChar)); |
---|
559 | #endif |
---|
560 | |
---|
561 | ::memset(m_ucMI1TableCounter, 0, 4*sizeof(UChar)); |
---|
562 | ::memset(m_ucSplitTableCounter, 0, 4*4*sizeof(UChar)); |
---|
563 | |
---|
564 | #if CAVLC_RQT_CBP |
---|
565 | m_ucCBP_YUV_TableCounterSum[0] = m_ucCBP_YUV_TableCounterSum[1] = m_ucCBP_YUV_TableCounterSum[2] = m_ucCBP_YUV_TableCounterSum[3] = 0; |
---|
566 | m_ucCBP_4Y_TableCounterSum[0] = m_ucCBP_4Y_TableCounterSum[1] = 0; |
---|
567 | m_ucCBP_YCS_TableCounterSum[0] = m_ucCBP_YCS_TableCounterSum[1] = 0; |
---|
568 | m_ucCBP_YS_TableCounterSum[0] = m_ucCBP_YS_TableCounterSum[1] = 0; |
---|
569 | #else |
---|
570 | m_ucCBFTableCounterSum[0] = m_ucCBFTableCounterSum[1] = 0; |
---|
571 | m_ucBlkCBPTableCounterSum[0] = m_ucBlkCBPTableCounterSum[1] = 0; |
---|
572 | #endif |
---|
573 | |
---|
574 | m_ucSplitTableCounterSum[0] = m_ucSplitTableCounterSum[1] = m_ucSplitTableCounterSum[2]= m_ucSplitTableCounterSum[3] = 0; |
---|
575 | m_ucMI1TableCounterSum = 0; |
---|
576 | #endif |
---|
577 | } |
---|
578 | |
---|
579 | Void TDecCavlc::parseTerminatingBit( UInt& ruiBit ) |
---|
580 | { |
---|
581 | ruiBit = false; |
---|
582 | Int iBitsLeft = m_pcBitstream->getBitsLeft(); |
---|
583 | if(iBitsLeft <= 8) |
---|
584 | { |
---|
585 | UInt uiPeekValue = m_pcBitstream->peekBits(iBitsLeft); |
---|
586 | if (uiPeekValue == (1<<(iBitsLeft-1))) |
---|
587 | ruiBit = true; |
---|
588 | } |
---|
589 | } |
---|
590 | |
---|
591 | Void TDecCavlc::parseAlfCtrlDepth ( UInt& ruiAlfCtrlDepth ) |
---|
592 | { |
---|
593 | UInt uiSymbol; |
---|
594 | xReadUnaryMaxSymbol(uiSymbol, g_uiMaxCUDepth-1); |
---|
595 | ruiAlfCtrlDepth = uiSymbol; |
---|
596 | } |
---|
597 | |
---|
598 | Void TDecCavlc::parseAlfCtrlFlag( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth ) |
---|
599 | { |
---|
600 | if (!m_bAlfCtrl) |
---|
601 | return; |
---|
602 | |
---|
603 | if( uiDepth > m_uiMaxAlfCtrlDepth && !pcCU->isFirstAbsZorderIdxInDepth(uiAbsPartIdx, m_uiMaxAlfCtrlDepth)) |
---|
604 | { |
---|
605 | return; |
---|
606 | } |
---|
607 | |
---|
608 | UInt uiSymbol; |
---|
609 | xReadFlag( uiSymbol ); |
---|
610 | |
---|
611 | if (uiDepth > m_uiMaxAlfCtrlDepth) |
---|
612 | { |
---|
613 | pcCU->setAlfCtrlFlagSubParts( uiSymbol, uiAbsPartIdx, m_uiMaxAlfCtrlDepth); |
---|
614 | } |
---|
615 | else |
---|
616 | { |
---|
617 | pcCU->setAlfCtrlFlagSubParts( uiSymbol, uiAbsPartIdx, uiDepth ); |
---|
618 | } |
---|
619 | } |
---|
620 | |
---|
621 | Void TDecCavlc::parseSkipFlag( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth ) |
---|
622 | { |
---|
623 | #if QC_LCEC_INTER_MODE |
---|
624 | return; |
---|
625 | #else |
---|
626 | |
---|
627 | if( pcCU->getSlice()->isIntra() ) |
---|
628 | { |
---|
629 | return; |
---|
630 | } |
---|
631 | |
---|
632 | UInt uiSymbol = 0; |
---|
633 | xReadFlag( uiSymbol ); |
---|
634 | |
---|
635 | if( uiSymbol ) |
---|
636 | { |
---|
637 | pcCU->setPredModeSubParts( MODE_SKIP, uiAbsPartIdx, uiDepth ); |
---|
638 | pcCU->setPartSizeSubParts( SIZE_2Nx2N, uiAbsPartIdx, uiDepth ); |
---|
639 | pcCU->setSizeSubParts( g_uiMaxCUWidth>>uiDepth, g_uiMaxCUHeight>>uiDepth, uiAbsPartIdx, uiDepth ); |
---|
640 | #if HHI_MRG_SKIP |
---|
641 | pcCU->setMergeFlagSubParts( true , uiAbsPartIdx, 0, uiDepth ); |
---|
642 | #else |
---|
643 | TComMv cZeroMv(0,0); |
---|
644 | pcCU->getCUMvField( REF_PIC_LIST_0 )->setAllMvd ( cZeroMv, SIZE_2Nx2N, uiAbsPartIdx, 0, uiDepth ); |
---|
645 | pcCU->getCUMvField( REF_PIC_LIST_1 )->setAllMvd ( cZeroMv, SIZE_2Nx2N, uiAbsPartIdx, 0, uiDepth ); |
---|
646 | |
---|
647 | pcCU->setTrIdxSubParts( 0, uiAbsPartIdx, uiDepth ); |
---|
648 | pcCU->setCbfSubParts ( 0, 0, 0, uiAbsPartIdx, uiDepth ); |
---|
649 | |
---|
650 | if ( pcCU->getSlice()->isInterP() ) |
---|
651 | { |
---|
652 | pcCU->setInterDirSubParts( 1, uiAbsPartIdx, 0, uiDepth ); |
---|
653 | |
---|
654 | if ( pcCU->getSlice()->getNumRefIdx( REF_PIC_LIST_0 ) > 0 ) |
---|
655 | pcCU->getCUMvField( REF_PIC_LIST_0 )->setAllRefIdx( 0, SIZE_2Nx2N, uiAbsPartIdx, 0, uiDepth ); |
---|
656 | if ( pcCU->getSlice()->getNumRefIdx( REF_PIC_LIST_1 ) > 0 ) |
---|
657 | pcCU->getCUMvField( REF_PIC_LIST_1 )->setAllRefIdx( NOT_VALID, SIZE_2Nx2N, uiAbsPartIdx, 0, uiDepth ); |
---|
658 | } |
---|
659 | else |
---|
660 | { |
---|
661 | pcCU->setInterDirSubParts( 3, uiAbsPartIdx, 0, uiDepth ); |
---|
662 | |
---|
663 | if ( pcCU->getSlice()->getNumRefIdx( REF_PIC_LIST_0 ) > 0 ) |
---|
664 | pcCU->getCUMvField( REF_PIC_LIST_0 )->setAllRefIdx( 0, SIZE_2Nx2N, uiAbsPartIdx, 0, uiDepth ); |
---|
665 | if ( pcCU->getSlice()->getNumRefIdx( REF_PIC_LIST_1 ) > 0 ) |
---|
666 | pcCU->getCUMvField( REF_PIC_LIST_1 )->setAllRefIdx( 0, SIZE_2Nx2N, uiAbsPartIdx, 0, uiDepth ); |
---|
667 | } |
---|
668 | } |
---|
669 | #endif // HHI_MRG_SKIP |
---|
670 | #endif // QC_LCEC_INTER_MODE |
---|
671 | } |
---|
672 | |
---|
673 | /** parse the motion vector predictor index |
---|
674 | * \param pcCU |
---|
675 | * \param riMVPIdx |
---|
676 | * \param iMVPNum |
---|
677 | * \param uiAbsPartIdx |
---|
678 | * \param uiDepth |
---|
679 | * \param eRefList |
---|
680 | * \returns Void |
---|
681 | */ |
---|
682 | Void TDecCavlc::parseMVPIdx( TComDataCU* pcCU, Int& riMVPIdx, Int iMVPNum, UInt uiAbsPartIdx, UInt uiDepth, RefPicList eRefList ) |
---|
683 | { |
---|
684 | UInt uiSymbol; |
---|
685 | xReadUnaryMaxSymbol(uiSymbol, iMVPNum-1); |
---|
686 | riMVPIdx = uiSymbol; |
---|
687 | } |
---|
688 | |
---|
689 | Void TDecCavlc::parseViewIdx(Int& riViewIdx) |
---|
690 | { |
---|
691 | UInt uiSymbol; |
---|
692 | xReadUnaryMaxSymbol(uiSymbol, MAX_NUMBER_VIEWS); |
---|
693 | riViewIdx = uiSymbol; |
---|
694 | } |
---|
695 | |
---|
696 | #if QC_LCEC_INTER_MODE |
---|
697 | /** parse the split flag |
---|
698 | * \param pcCU |
---|
699 | * \param uiAbsPartIdx |
---|
700 | * \param uiDepth |
---|
701 | * \returns Void |
---|
702 | */ |
---|
703 | Void TDecCavlc::parseSplitFlag ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth ) |
---|
704 | { |
---|
705 | if (pcCU->getSlice()->isIntra()) |
---|
706 | { |
---|
707 | if( uiDepth == g_uiMaxCUDepth - g_uiAddCUDepth ) |
---|
708 | { |
---|
709 | pcCU->setDepthSubParts( uiDepth, uiAbsPartIdx ); |
---|
710 | return ; |
---|
711 | } |
---|
712 | |
---|
713 | UInt uiSymbol; |
---|
714 | xReadFlag( uiSymbol ); |
---|
715 | pcCU->setDepthSubParts( uiDepth + uiSymbol, uiAbsPartIdx ); |
---|
716 | |
---|
717 | return ; |
---|
718 | } |
---|
719 | UInt tmp=0; |
---|
720 | UInt cx=0; |
---|
721 | UInt uiMode ; |
---|
722 | { |
---|
723 | UInt iMaxLen= (uiDepth == g_uiMaxCUDepth - g_uiAddCUDepth)?5:6; |
---|
724 | while (tmp==0 && cx<iMaxLen) |
---|
725 | { |
---|
726 | xReadFlag( tmp ); |
---|
727 | cx++; |
---|
728 | }; |
---|
729 | if(tmp!=0) |
---|
730 | cx--; |
---|
731 | |
---|
732 | UInt uiDepthRemember = uiDepth; |
---|
733 | if ( uiDepth == g_uiMaxCUDepth - g_uiAddCUDepth ) |
---|
734 | { |
---|
735 | uiDepth = 3; |
---|
736 | } |
---|
737 | UInt x = m_uiSplitTableD[uiDepth][cx]; |
---|
738 | /* Adapt table */ |
---|
739 | uiMode = x; |
---|
740 | #if CAVLC_COUNTER_ADAPT |
---|
741 | adaptCodeword(cx, m_ucSplitTableCounter[uiDepth], m_ucSplitTableCounterSum[uiDepth], m_uiSplitTableD[uiDepth], NULL, 4 ); |
---|
742 | #else |
---|
743 | if (cx>0) |
---|
744 | { |
---|
745 | UInt cy = Max(0,cx-1); |
---|
746 | UInt y = m_uiSplitTableD[uiDepth][cy]; |
---|
747 | m_uiSplitTableD[uiDepth][cy] = x; |
---|
748 | m_uiSplitTableD[uiDepth][cx] = y; |
---|
749 | } |
---|
750 | #endif |
---|
751 | uiDepth = uiDepthRemember; |
---|
752 | } |
---|
753 | if (uiMode==0) |
---|
754 | { |
---|
755 | pcCU->setDepthSubParts( uiDepth + 1, uiAbsPartIdx ); |
---|
756 | } |
---|
757 | else |
---|
758 | { |
---|
759 | pcCU->setPartSizeSubParts( SIZE_2Nx2N, uiAbsPartIdx, uiDepth ); |
---|
760 | pcCU->setMergeFlagSubParts(false, uiAbsPartIdx,0, uiDepth ); |
---|
761 | pcCU->setDepthSubParts( uiDepth , uiAbsPartIdx ); |
---|
762 | if (uiMode ==1) |
---|
763 | { |
---|
764 | TComMv cZeroMv(0,0); |
---|
765 | pcCU->setPredModeSubParts( MODE_SKIP, uiAbsPartIdx, uiDepth ); |
---|
766 | pcCU->setPartSizeSubParts( SIZE_2Nx2N, uiAbsPartIdx, uiDepth ); |
---|
767 | pcCU->setSizeSubParts( g_uiMaxCUWidth>>uiDepth, g_uiMaxCUHeight>>uiDepth, uiAbsPartIdx, uiDepth ); |
---|
768 | pcCU->getCUMvField( REF_PIC_LIST_0 )->setAllMvd ( cZeroMv, SIZE_2Nx2N, uiAbsPartIdx, 0, uiDepth ); |
---|
769 | pcCU->getCUMvField( REF_PIC_LIST_1 )->setAllMvd ( cZeroMv, SIZE_2Nx2N, uiAbsPartIdx, 0, uiDepth ); |
---|
770 | pcCU->setTrIdxSubParts( 0, uiAbsPartIdx, uiDepth ); |
---|
771 | pcCU->setCbfSubParts ( 0, 0, 0, uiAbsPartIdx, uiDepth ); |
---|
772 | |
---|
773 | #if HHI_MRG_SKIP |
---|
774 | pcCU->setMergeFlagSubParts( true, uiAbsPartIdx, 0, uiDepth ); |
---|
775 | #else |
---|
776 | if ( pcCU->getSlice()->isInterP() ) |
---|
777 | { |
---|
778 | pcCU->setInterDirSubParts( 1, uiAbsPartIdx, 0, uiDepth ); |
---|
779 | |
---|
780 | if ( pcCU->getSlice()->getNumRefIdx( REF_PIC_LIST_0 ) > 0 ) |
---|
781 | pcCU->getCUMvField( REF_PIC_LIST_0 )->setAllRefIdx( 0, SIZE_2Nx2N, uiAbsPartIdx, 0, uiDepth ); |
---|
782 | if ( pcCU->getSlice()->getNumRefIdx( REF_PIC_LIST_1 ) > 0 ) |
---|
783 | pcCU->getCUMvField( REF_PIC_LIST_1 )->setAllRefIdx( NOT_VALID, SIZE_2Nx2N, uiAbsPartIdx, 0, uiDepth ); |
---|
784 | } |
---|
785 | else |
---|
786 | { |
---|
787 | pcCU->setInterDirSubParts( 3, uiAbsPartIdx, 0, uiDepth ); |
---|
788 | |
---|
789 | if ( pcCU->getSlice()->getNumRefIdx( REF_PIC_LIST_0 ) > 0 ) |
---|
790 | pcCU->getCUMvField( REF_PIC_LIST_0 )->setAllRefIdx( 0, SIZE_2Nx2N, uiAbsPartIdx, 0, uiDepth ); |
---|
791 | if ( pcCU->getSlice()->getNumRefIdx( REF_PIC_LIST_1 ) > 0 ) |
---|
792 | pcCU->getCUMvField( REF_PIC_LIST_1 )->setAllRefIdx( 0, SIZE_2Nx2N, uiAbsPartIdx, 0, uiDepth ); |
---|
793 | } |
---|
794 | #endif |
---|
795 | } |
---|
796 | else if (uiMode==2) |
---|
797 | { |
---|
798 | pcCU->setPredModeSubParts( MODE_INTER, uiAbsPartIdx, uiDepth ); |
---|
799 | pcCU->setPartSizeSubParts( SIZE_2Nx2N, uiAbsPartIdx, uiDepth ); |
---|
800 | pcCU->setMergeFlagSubParts(true, uiAbsPartIdx,0, uiDepth ); |
---|
801 | pcCU->setSizeSubParts( g_uiMaxCUWidth>>uiDepth, g_uiMaxCUHeight>>uiDepth, uiAbsPartIdx, uiDepth ); |
---|
802 | } |
---|
803 | else if (uiMode==6) |
---|
804 | { |
---|
805 | #if MTK_DISABLE_INTRA_NxN_SPLIT && HHI_DISABLE_INTER_NxN_SPLIT |
---|
806 | if (uiDepth != g_uiMaxCUDepth - g_uiAddCUDepth) |
---|
807 | { |
---|
808 | pcCU->setPredModeSubParts( MODE_INTRA, uiAbsPartIdx, uiDepth ); |
---|
809 | pcCU->setPartSizeSubParts( SIZE_2Nx2N, uiAbsPartIdx, uiDepth ); |
---|
810 | pcCU->setSizeSubParts( g_uiMaxCUWidth>>uiDepth, g_uiMaxCUHeight>>uiDepth, uiAbsPartIdx, uiDepth ); |
---|
811 | UInt uiTrLevel = 0; |
---|
812 | UInt uiWidthInBit = g_aucConvertToBit[pcCU->getWidth(uiAbsPartIdx)]+2; |
---|
813 | UInt uiTrSizeInBit = g_aucConvertToBit[pcCU->getSlice()->getSPS()->getMaxTrSize()]+2; |
---|
814 | uiTrLevel = uiWidthInBit >= uiTrSizeInBit ? uiWidthInBit - uiTrSizeInBit : 0; |
---|
815 | pcCU->setTrIdxSubParts( uiTrLevel, uiAbsPartIdx, uiDepth ); |
---|
816 | } |
---|
817 | else |
---|
818 | #endif |
---|
819 | { |
---|
820 | pcCU->setPredModeSubParts( MODE_INTER, uiAbsPartIdx, uiDepth ); |
---|
821 | pcCU->setPartSizeSubParts( SIZE_NxN, uiAbsPartIdx, uiDepth ); |
---|
822 | } |
---|
823 | } |
---|
824 | else |
---|
825 | { |
---|
826 | pcCU->setPredModeSubParts( MODE_INTER, uiAbsPartIdx, uiDepth ); |
---|
827 | pcCU->setPartSizeSubParts( PartSize(uiMode-3), uiAbsPartIdx, uiDepth ); |
---|
828 | pcCU->setSizeSubParts( g_uiMaxCUWidth>>uiDepth, g_uiMaxCUHeight>>uiDepth, uiAbsPartIdx, uiDepth ); |
---|
829 | } |
---|
830 | } |
---|
831 | } |
---|
832 | #else |
---|
833 | Void TDecCavlc::parseSplitFlag( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth ) |
---|
834 | { |
---|
835 | if( uiDepth == g_uiMaxCUDepth - g_uiAddCUDepth ) |
---|
836 | { |
---|
837 | pcCU->setDepthSubParts( uiDepth, uiAbsPartIdx ); |
---|
838 | return ; |
---|
839 | } |
---|
840 | |
---|
841 | UInt uiSymbol; |
---|
842 | xReadFlag( uiSymbol ); |
---|
843 | pcCU->setDepthSubParts( uiDepth + uiSymbol, uiAbsPartIdx ); |
---|
844 | |
---|
845 | return ; |
---|
846 | } |
---|
847 | #endif |
---|
848 | |
---|
849 | #if MW_MVI_SIGNALLING_MODE == 0 |
---|
850 | Void TDecCavlc::parseMvInheritanceFlag( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth ) |
---|
851 | { |
---|
852 | const Int iTextureModeDepth = pcCU->getTextureModeDepth( uiAbsPartIdx ); |
---|
853 | if( iTextureModeDepth != -1 && uiDepth > iTextureModeDepth ) |
---|
854 | return; |
---|
855 | |
---|
856 | UInt uiSymbol; |
---|
857 | xReadFlag( uiSymbol ); |
---|
858 | if( uiSymbol == 1 ) |
---|
859 | { |
---|
860 | pcCU->setTextureModeDepthSubParts( uiDepth, uiAbsPartIdx, uiDepth ); |
---|
861 | } |
---|
862 | } |
---|
863 | #endif |
---|
864 | |
---|
865 | #if QC_LCEC_INTER_MODE |
---|
866 | |
---|
867 | /** parse partition size |
---|
868 | * \param pcCU |
---|
869 | * \param uiAbsPartIdx |
---|
870 | * \param uiDepth |
---|
871 | * \returns Void |
---|
872 | */ |
---|
873 | Void TDecCavlc::parsePartSize( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth ) |
---|
874 | { |
---|
875 | UInt uiMode=0; |
---|
876 | if ( pcCU->getSlice()->isIntra()&& pcCU->isIntra( uiAbsPartIdx ) ) |
---|
877 | { |
---|
878 | #if MTK_DISABLE_INTRA_NxN_SPLIT |
---|
879 | uiMode = 1; |
---|
880 | if ( uiDepth == (g_uiMaxCUDepth - g_uiAddCUDepth )) |
---|
881 | #endif |
---|
882 | { |
---|
883 | UInt uiSymbol; |
---|
884 | xReadFlag( uiSymbol ); |
---|
885 | uiMode = uiSymbol ? 1 : 2; |
---|
886 | } |
---|
887 | } |
---|
888 | #if MTK_DISABLE_INTRA_NxN_SPLIT && HHI_DISABLE_INTER_NxN_SPLIT |
---|
889 | else if (uiDepth != (g_uiMaxCUDepth - g_uiAddCUDepth ) || pcCU->getPartitionSize(uiAbsPartIdx ) != SIZE_NxN) |
---|
890 | #else |
---|
891 | else if (pcCU->getPartitionSize(uiAbsPartIdx ) != SIZE_NxN) |
---|
892 | #endif |
---|
893 | { |
---|
894 | return; |
---|
895 | } |
---|
896 | else |
---|
897 | { |
---|
898 | UInt uiSymbol; |
---|
899 | xReadFlag( uiSymbol ); |
---|
900 | if(uiSymbol) |
---|
901 | { |
---|
902 | uiMode = 1; |
---|
903 | } |
---|
904 | else |
---|
905 | { |
---|
906 | #if (MTK_DISABLE_INTRA_NxN_SPLIT && !HHI_DISABLE_INTER_NxN_SPLIT) || (!MTK_DISABLE_INTRA_NxN_SPLIT && HHI_DISABLE_INTER_NxN_SPLIT ) |
---|
907 | if ( uiDepth != (g_uiMaxCUDepth - g_uiAddCUDepth )) |
---|
908 | { |
---|
909 | #if MTK_DISABLE_INTRA_NxN_SPLIT && !HHI_DISABLE_INTER_NxN_SPLIT |
---|
910 | uiMode = 0; |
---|
911 | #elif !MTK_DISABLE_INTRA_NxN_SPLIT && HHI_DISABLE_INTER_NxN_SPLIT |
---|
912 | uiMode = 2; |
---|
913 | #endif |
---|
914 | } |
---|
915 | else |
---|
916 | #endif |
---|
917 | { |
---|
918 | xReadFlag( uiSymbol ); |
---|
919 | uiMode = uiSymbol ? 2 : 0; |
---|
920 | } |
---|
921 | } |
---|
922 | } |
---|
923 | PartSize ePartSize; |
---|
924 | PredMode eMode; |
---|
925 | if (uiMode > 0) |
---|
926 | { |
---|
927 | eMode = MODE_INTRA; |
---|
928 | ePartSize = (uiMode==1) ? SIZE_2Nx2N:SIZE_NxN; |
---|
929 | } |
---|
930 | else |
---|
931 | { |
---|
932 | eMode = MODE_INTER; |
---|
933 | ePartSize = SIZE_NxN; |
---|
934 | } |
---|
935 | pcCU->setPredModeSubParts( eMode , uiAbsPartIdx, uiDepth ); |
---|
936 | pcCU->setPartSizeSubParts( ePartSize, uiAbsPartIdx, uiDepth ); |
---|
937 | pcCU->setSizeSubParts( g_uiMaxCUWidth>>uiDepth, g_uiMaxCUHeight>>uiDepth, uiAbsPartIdx, uiDepth ); |
---|
938 | |
---|
939 | if( pcCU->getPredictionMode(uiAbsPartIdx) == MODE_INTRA ) |
---|
940 | { |
---|
941 | UInt uiTrLevel = 0; |
---|
942 | UInt uiWidthInBit = g_aucConvertToBit[pcCU->getWidth(uiAbsPartIdx)] + 2; |
---|
943 | UInt uiTrSizeInBit = g_aucConvertToBit[pcCU->getSlice()->getSPS()->getMaxTrSize()] + 2; |
---|
944 | uiTrLevel = uiWidthInBit >= uiTrSizeInBit ? uiWidthInBit - uiTrSizeInBit : 0; |
---|
945 | if( pcCU->getPartitionSize( uiAbsPartIdx ) == SIZE_NxN ) |
---|
946 | { |
---|
947 | pcCU->setTrIdxSubParts( 1 + uiTrLevel, uiAbsPartIdx, uiDepth ); |
---|
948 | } |
---|
949 | else |
---|
950 | { |
---|
951 | pcCU->setTrIdxSubParts( uiTrLevel, uiAbsPartIdx, uiDepth ); |
---|
952 | } |
---|
953 | } |
---|
954 | } |
---|
955 | #else |
---|
956 | Void TDecCavlc::parsePartSize( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth ) |
---|
957 | { |
---|
958 | UInt uiSymbol, uiMode = 0; |
---|
959 | PartSize eMode; |
---|
960 | |
---|
961 | if ( pcCU->isIntra( uiAbsPartIdx ) ) |
---|
962 | { |
---|
963 | #if MTK_DISABLE_INTRA_NxN_SPLIT |
---|
964 | eMode = SIZE_2Nx2N; |
---|
965 | if( uiDepth == g_uiMaxCUDepth - g_uiAddCUDepth ) |
---|
966 | #endif |
---|
967 | { |
---|
968 | xReadFlag( uiSymbol ); |
---|
969 | eMode = uiSymbol ? SIZE_2Nx2N : SIZE_NxN; |
---|
970 | } |
---|
971 | } |
---|
972 | else |
---|
973 | { |
---|
974 | #if HHI_RMP_SWITCH |
---|
975 | if ( !pcCU->getSlice()->getSPS()->getUseRMP()) |
---|
976 | { |
---|
977 | xReadFlag( uiSymbol ); |
---|
978 | if( uiSymbol ) |
---|
979 | uiMode = 0; |
---|
980 | else |
---|
981 | uiMode = 3; |
---|
982 | } |
---|
983 | else |
---|
984 | #endif |
---|
985 | { |
---|
986 | UInt uiMaxNumBits = 3; |
---|
987 | for ( UInt ui = 0; ui < uiMaxNumBits; ui++ ) |
---|
988 | { |
---|
989 | xReadFlag( uiSymbol ); |
---|
990 | if ( uiSymbol ) |
---|
991 | { |
---|
992 | break; |
---|
993 | } |
---|
994 | uiMode++; |
---|
995 | } |
---|
996 | } |
---|
997 | eMode = (PartSize) uiMode; |
---|
998 | |
---|
999 | if (pcCU->getSlice()->isInterB() && uiMode == 3) |
---|
1000 | { |
---|
1001 | #if HHI_DISABLE_INTER_NxN_SPLIT |
---|
1002 | uiSymbol = 0; |
---|
1003 | if( uiDepth == g_uiMaxCUDepth - g_uiAddCUDepth ) |
---|
1004 | #endif |
---|
1005 | { |
---|
1006 | xReadFlag( uiSymbol ); |
---|
1007 | } |
---|
1008 | |
---|
1009 | if (uiSymbol == 0) |
---|
1010 | { |
---|
1011 | pcCU->setPredModeSubParts( MODE_INTRA, uiAbsPartIdx, uiDepth ); |
---|
1012 | #if MTK_DISABLE_INTRA_NxN_SPLIT |
---|
1013 | if( uiDepth == g_uiMaxCUDepth - g_uiAddCUDepth ) |
---|
1014 | #endif |
---|
1015 | { |
---|
1016 | xReadFlag( uiSymbol ); |
---|
1017 | } |
---|
1018 | if (uiSymbol == 0) |
---|
1019 | eMode = SIZE_2Nx2N; |
---|
1020 | } |
---|
1021 | } |
---|
1022 | |
---|
1023 | } |
---|
1024 | |
---|
1025 | pcCU->setPartSizeSubParts( eMode, uiAbsPartIdx, uiDepth ); |
---|
1026 | pcCU->setSizeSubParts( g_uiMaxCUWidth>>uiDepth, g_uiMaxCUHeight>>uiDepth, uiAbsPartIdx, uiDepth ); |
---|
1027 | |
---|
1028 | UInt uiTrLevel = 0; |
---|
1029 | |
---|
1030 | UInt uiWidthInBit = g_aucConvertToBit[pcCU->getWidth(uiAbsPartIdx)]+2; |
---|
1031 | UInt uiTrSizeInBit = g_aucConvertToBit[pcCU->getSlice()->getSPS()->getMaxTrSize()]+2; |
---|
1032 | uiTrLevel = uiWidthInBit >= uiTrSizeInBit ? uiWidthInBit - uiTrSizeInBit : 0; |
---|
1033 | |
---|
1034 | if( pcCU->getPredictionMode(uiAbsPartIdx) == MODE_INTRA ) |
---|
1035 | { |
---|
1036 | if( pcCU->getPartitionSize( uiAbsPartIdx ) == SIZE_NxN ) |
---|
1037 | { |
---|
1038 | pcCU->setTrIdxSubParts( 1+uiTrLevel, uiAbsPartIdx, uiDepth ); |
---|
1039 | } |
---|
1040 | else |
---|
1041 | { |
---|
1042 | pcCU->setTrIdxSubParts( uiTrLevel, uiAbsPartIdx, uiDepth ); |
---|
1043 | } |
---|
1044 | } |
---|
1045 | } |
---|
1046 | #endif |
---|
1047 | |
---|
1048 | /** parse prediction mode |
---|
1049 | * \param pcCU |
---|
1050 | * \param uiAbsPartIdx |
---|
1051 | * \param uiDepth |
---|
1052 | * \returns Void |
---|
1053 | */ |
---|
1054 | Void TDecCavlc::parsePredMode( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth ) |
---|
1055 | { |
---|
1056 | if( pcCU->getSlice()->isIntra() ) |
---|
1057 | { |
---|
1058 | pcCU->setPredModeSubParts( MODE_INTRA, uiAbsPartIdx, uiDepth ); |
---|
1059 | return ; |
---|
1060 | } |
---|
1061 | #if !QC_LCEC_INTER_MODE |
---|
1062 | UInt uiSymbol; |
---|
1063 | Int iPredMode = MODE_INTER; |
---|
1064 | |
---|
1065 | if ( pcCU->getSlice()->isInterB() ) |
---|
1066 | { |
---|
1067 | pcCU->setPredModeSubParts( (PredMode)iPredMode, uiAbsPartIdx, uiDepth ); |
---|
1068 | return; |
---|
1069 | } |
---|
1070 | xReadFlag( uiSymbol ); |
---|
1071 | iPredMode += uiSymbol; |
---|
1072 | |
---|
1073 | pcCU->setPredModeSubParts( (PredMode)iPredMode, uiAbsPartIdx, uiDepth ); |
---|
1074 | #endif |
---|
1075 | } |
---|
1076 | |
---|
1077 | #if LCEC_INTRA_MODE |
---|
1078 | #if MTK_DCM_MPM |
---|
1079 | Void TDecCavlc::parseIntraDirLumaAng ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth ) |
---|
1080 | { |
---|
1081 | Int uiIPredMode = 0; |
---|
1082 | Int iIntraIdx = pcCU->getIntraSizeIdx(uiAbsPartIdx); |
---|
1083 | |
---|
1084 | Int uiPreds[2] = {-1, -1}; |
---|
1085 | Int uiPredNum = pcCU->getIntraDirLumaPredictor(uiAbsPartIdx, uiPreds); |
---|
1086 | |
---|
1087 | if ( g_aucIntraModeBitsAng[iIntraIdx] < 5 ) |
---|
1088 | { |
---|
1089 | UInt uiSymbol; |
---|
1090 | xReadFlag( uiSymbol ); |
---|
1091 | if ( uiSymbol ) |
---|
1092 | { |
---|
1093 | if(uiPredNum == 1) |
---|
1094 | { |
---|
1095 | uiIPredMode = uiPreds[0]; |
---|
1096 | } |
---|
1097 | else |
---|
1098 | { |
---|
1099 | xReadFlag( uiSymbol ); |
---|
1100 | uiIPredMode = uiPreds[uiSymbol]; |
---|
1101 | } |
---|
1102 | } |
---|
1103 | else |
---|
1104 | { |
---|
1105 | xReadFlag( uiSymbol ); uiIPredMode = uiSymbol; |
---|
1106 | if ( g_aucIntraModeBitsAng[iIntraIdx] > 2 ) { xReadFlag( uiSymbol ); uiIPredMode |= uiSymbol << 1; } |
---|
1107 | if ( g_aucIntraModeBitsAng[iIntraIdx] > 3 ) { xReadFlag( uiSymbol ); uiIPredMode |= uiSymbol << 2; } |
---|
1108 | |
---|
1109 | for(UInt i = 0; i < uiPredNum; i++) |
---|
1110 | { |
---|
1111 | if(uiIPredMode >= uiPreds[i]) { uiIPredMode ++;} |
---|
1112 | } |
---|
1113 | |
---|
1114 | } |
---|
1115 | } |
---|
1116 | else |
---|
1117 | { |
---|
1118 | Int iDir, iDirLarger, iRankIntraMode, iRankIntraModeLarger; |
---|
1119 | |
---|
1120 | const UInt *huff; |
---|
1121 | const UInt *lengthHuff; |
---|
1122 | UInt totMode; |
---|
1123 | UInt *m_uiIntraModeTableD; |
---|
1124 | |
---|
1125 | if ( g_aucIntraModeBitsAng[iIntraIdx] == 5 ) |
---|
1126 | { |
---|
1127 | totMode = (uiPredNum == 1)? 17: 16; |
---|
1128 | huff = huff17_2[uiPredNum - 1]; |
---|
1129 | lengthHuff = lengthHuff17_2[uiPredNum - 1]; |
---|
1130 | m_uiIntraModeTableD = m_uiIntraModeTableD17[uiPredNum - 1]; |
---|
1131 | } |
---|
1132 | else |
---|
1133 | { |
---|
1134 | totMode = (uiPredNum == 1)? 34: 33; |
---|
1135 | huff = huff34_2[uiPredNum - 1]; |
---|
1136 | lengthHuff = lengthHuff34_2[uiPredNum - 1]; |
---|
1137 | m_uiIntraModeTableD = m_uiIntraModeTableD34[uiPredNum - 1]; |
---|
1138 | } |
---|
1139 | |
---|
1140 | UInt uiCode; |
---|
1141 | UInt uiLength = lengthHuff[totMode - 1]; |
---|
1142 | |
---|
1143 | m_pcBitstream->pseudoRead(uiLength,uiCode); |
---|
1144 | if ((uiCode>>(uiLength- lengthHuff[0])) == huff[0]) |
---|
1145 | { |
---|
1146 | m_pcBitstream->read(lengthHuff[0],uiCode); |
---|
1147 | |
---|
1148 | if(uiPredNum == 1) |
---|
1149 | { |
---|
1150 | uiIPredMode = uiPreds[0]; |
---|
1151 | } |
---|
1152 | else if(uiPredNum == 2) |
---|
1153 | { |
---|
1154 | UInt uiPredIdx= 0; |
---|
1155 | xReadFlag( uiPredIdx ); |
---|
1156 | uiIPredMode = uiPreds[uiPredIdx]; |
---|
1157 | } |
---|
1158 | |
---|
1159 | } |
---|
1160 | else |
---|
1161 | { |
---|
1162 | iRankIntraMode = 0; |
---|
1163 | |
---|
1164 | for(Int i = 1; i < totMode; i++) |
---|
1165 | { |
---|
1166 | if( (uiCode>>(uiLength- lengthHuff[i])) == huff[i]) |
---|
1167 | { |
---|
1168 | m_pcBitstream->read(lengthHuff[i], uiCode); |
---|
1169 | iRankIntraMode = i; |
---|
1170 | break; |
---|
1171 | } |
---|
1172 | } |
---|
1173 | |
---|
1174 | iRankIntraMode --; |
---|
1175 | iDir = m_uiIntraModeTableD[iRankIntraMode]; |
---|
1176 | iRankIntraModeLarger = Max(0,iRankIntraMode-1); |
---|
1177 | iDirLarger = m_uiIntraModeTableD[iRankIntraModeLarger]; |
---|
1178 | m_uiIntraModeTableD[iRankIntraModeLarger] = iDir; |
---|
1179 | m_uiIntraModeTableD[iRankIntraMode] = iDirLarger; |
---|
1180 | |
---|
1181 | for(UInt i = 0; i < uiPredNum; i++) |
---|
1182 | { |
---|
1183 | if(iDir >= uiPreds[i]) |
---|
1184 | { |
---|
1185 | iDir ++; |
---|
1186 | } |
---|
1187 | } |
---|
1188 | |
---|
1189 | uiIPredMode = iDir; |
---|
1190 | |
---|
1191 | |
---|
1192 | } |
---|
1193 | } |
---|
1194 | #if ADD_PLANAR_MODE |
---|
1195 | if (uiIPredMode == 2) |
---|
1196 | { |
---|
1197 | UInt planarFlag; |
---|
1198 | xReadFlag( planarFlag ); |
---|
1199 | if ( planarFlag ) |
---|
1200 | { |
---|
1201 | uiIPredMode = PLANAR_IDX; |
---|
1202 | } |
---|
1203 | } |
---|
1204 | #endif |
---|
1205 | |
---|
1206 | pcCU->setLumaIntraDirSubParts( (UChar)uiIPredMode, uiAbsPartIdx, uiDepth ); |
---|
1207 | } |
---|
1208 | #else |
---|
1209 | Void TDecCavlc::parseIntraDirLumaAng ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth ) |
---|
1210 | { |
---|
1211 | UInt uiSymbol; |
---|
1212 | Int uiIPredMode; |
---|
1213 | Int iMostProbable = pcCU->getMostProbableIntraDirLuma( uiAbsPartIdx ); |
---|
1214 | Int iIntraIdx = pcCU->getIntraSizeIdx(uiAbsPartIdx); |
---|
1215 | Int iDir, iDirLarger, iRankIntraMode, iRankIntraModeLarger; |
---|
1216 | |
---|
1217 | Int iLeft = pcCU->getLeftIntraDirLuma( uiAbsPartIdx ); |
---|
1218 | Int iAbove = pcCU->getAboveIntraDirLuma( uiAbsPartIdx ); |
---|
1219 | UInt ind=(iLeft==iAbove)? 0 : 1; |
---|
1220 | |
---|
1221 | const UInt *huff17=huff17_2[ind]; |
---|
1222 | const UInt *lengthHuff17=lengthHuff17_2[ind]; |
---|
1223 | const UInt *huff34=huff34_2[ind]; |
---|
1224 | const UInt *lengthHuff34=lengthHuff34_2[ind]; |
---|
1225 | |
---|
1226 | if ( g_aucIntraModeBitsAng[iIntraIdx] < 5 ) |
---|
1227 | { |
---|
1228 | xReadFlag( uiSymbol ); |
---|
1229 | if ( uiSymbol ) |
---|
1230 | uiIPredMode = iMostProbable; |
---|
1231 | else |
---|
1232 | { |
---|
1233 | xReadFlag( uiSymbol ); uiIPredMode = uiSymbol; |
---|
1234 | if ( g_aucIntraModeBitsAng[iIntraIdx] > 2 ) { xReadFlag( uiSymbol ); uiIPredMode |= uiSymbol << 1; } |
---|
1235 | if ( g_aucIntraModeBitsAng[iIntraIdx] > 3 ) { xReadFlag( uiSymbol ); uiIPredMode |= uiSymbol << 2; } |
---|
1236 | if(uiIPredMode >= iMostProbable) |
---|
1237 | uiIPredMode ++; |
---|
1238 | } |
---|
1239 | } |
---|
1240 | else if ( g_aucIntraModeBitsAng[iIntraIdx] == 5 ) |
---|
1241 | { |
---|
1242 | UInt uiCode; |
---|
1243 | UInt uiLength = lengthHuff17[15]; |
---|
1244 | m_pcBitstream->pseudoRead(uiLength,uiCode); |
---|
1245 | if ((uiCode>>(uiLength- lengthHuff17[0])) == huff17[0]) |
---|
1246 | { |
---|
1247 | m_pcBitstream->read(lengthHuff17[0],uiCode); |
---|
1248 | uiIPredMode = iMostProbable; |
---|
1249 | } |
---|
1250 | else |
---|
1251 | { |
---|
1252 | iRankIntraMode = 0; |
---|
1253 | for (Int i=1;i<17;i++) |
---|
1254 | { |
---|
1255 | if( (uiCode>>(uiLength- lengthHuff17[i])) == huff17[i]) |
---|
1256 | { |
---|
1257 | m_pcBitstream->read(lengthHuff17[i], uiCode); |
---|
1258 | iRankIntraMode = i; |
---|
1259 | break; |
---|
1260 | } |
---|
1261 | } |
---|
1262 | |
---|
1263 | if ( iRankIntraMode > 0 ) |
---|
1264 | iRankIntraMode --; |
---|
1265 | iDir = m_uiIntraModeTableD17[iRankIntraMode]; |
---|
1266 | |
---|
1267 | iRankIntraModeLarger = Max(0,iRankIntraMode-1); |
---|
1268 | iDirLarger = m_uiIntraModeTableD17[iRankIntraModeLarger]; |
---|
1269 | |
---|
1270 | m_uiIntraModeTableD17[iRankIntraModeLarger] = iDir; |
---|
1271 | m_uiIntraModeTableD17[iRankIntraMode] = iDirLarger; |
---|
1272 | |
---|
1273 | uiIPredMode = (iDir>=iMostProbable? iDir+1: iDir); |
---|
1274 | } |
---|
1275 | } |
---|
1276 | else |
---|
1277 | { |
---|
1278 | UInt uiCode; |
---|
1279 | UInt uiLength = lengthHuff34[32]; |
---|
1280 | m_pcBitstream->pseudoRead(uiLength,uiCode); |
---|
1281 | if ((uiCode>>(uiLength- lengthHuff34[0])) == huff34[0]) |
---|
1282 | { |
---|
1283 | m_pcBitstream->read(lengthHuff34[0],uiCode); |
---|
1284 | uiIPredMode = iMostProbable; |
---|
1285 | } |
---|
1286 | else |
---|
1287 | { |
---|
1288 | iRankIntraMode = 0; |
---|
1289 | for (Int i=1;i<34;i++) |
---|
1290 | { |
---|
1291 | if( (uiCode>>(uiLength- lengthHuff34[i])) == huff34[i]) |
---|
1292 | { |
---|
1293 | m_pcBitstream->read(lengthHuff34[i], uiCode); |
---|
1294 | iRankIntraMode = i; |
---|
1295 | break; |
---|
1296 | } |
---|
1297 | } |
---|
1298 | |
---|
1299 | if ( iRankIntraMode > 0 ) |
---|
1300 | iRankIntraMode --; |
---|
1301 | iDir = m_uiIntraModeTableD34[iRankIntraMode]; |
---|
1302 | |
---|
1303 | iRankIntraModeLarger = Max(0,iRankIntraMode-1); |
---|
1304 | iDirLarger = m_uiIntraModeTableD34[iRankIntraModeLarger]; |
---|
1305 | |
---|
1306 | m_uiIntraModeTableD34[iRankIntraModeLarger] = iDir; |
---|
1307 | m_uiIntraModeTableD34[iRankIntraMode] = iDirLarger; |
---|
1308 | |
---|
1309 | uiIPredMode = (iDir>=iMostProbable? iDir+1: iDir); |
---|
1310 | } |
---|
1311 | } |
---|
1312 | |
---|
1313 | #if ADD_PLANAR_MODE |
---|
1314 | if (uiIPredMode == 2) |
---|
1315 | { |
---|
1316 | UInt planarFlag; |
---|
1317 | xReadFlag( planarFlag ); |
---|
1318 | if ( planarFlag ) |
---|
1319 | { |
---|
1320 | uiIPredMode = PLANAR_IDX; |
---|
1321 | } |
---|
1322 | } |
---|
1323 | #endif |
---|
1324 | pcCU->setLumaIntraDirSubParts( (UChar)uiIPredMode, uiAbsPartIdx, uiDepth ); |
---|
1325 | } |
---|
1326 | #endif |
---|
1327 | #else |
---|
1328 | Void TDecCavlc::parseIntraDirLumaAng ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth ) |
---|
1329 | { |
---|
1330 | UInt uiSymbol; |
---|
1331 | Int uiIPredMode; |
---|
1332 | Int iMostProbable = pcCU->getMostProbableIntraDirLuma( uiAbsPartIdx ); |
---|
1333 | |
---|
1334 | xReadFlag( uiSymbol ); |
---|
1335 | |
---|
1336 | if ( uiSymbol ) |
---|
1337 | uiIPredMode = iMostProbable; |
---|
1338 | else |
---|
1339 | { |
---|
1340 | Int iIntraIdx = pcCU->getIntraSizeIdx(uiAbsPartIdx); |
---|
1341 | if ( g_aucIntraModeBitsAng[iIntraIdx] < 6 ) |
---|
1342 | { |
---|
1343 | xReadFlag( uiSymbol ); uiIPredMode = uiSymbol; |
---|
1344 | if ( g_aucIntraModeBitsAng[iIntraIdx] > 2 ) { xReadFlag( uiSymbol ); uiIPredMode |= uiSymbol << 1; } |
---|
1345 | if ( g_aucIntraModeBitsAng[iIntraIdx] > 3 ) { xReadFlag( uiSymbol ); uiIPredMode |= uiSymbol << 2; } |
---|
1346 | if ( g_aucIntraModeBitsAng[iIntraIdx] > 4 ) { xReadFlag( uiSymbol ); uiIPredMode |= uiSymbol << 3; } |
---|
1347 | } |
---|
1348 | else |
---|
1349 | { |
---|
1350 | xReadFlag( uiSymbol ); uiIPredMode = uiSymbol; |
---|
1351 | xReadFlag( uiSymbol ); uiIPredMode |= uiSymbol << 1; |
---|
1352 | xReadFlag( uiSymbol ); uiIPredMode |= uiSymbol << 2; |
---|
1353 | xReadFlag( uiSymbol ); uiIPredMode |= uiSymbol << 3; |
---|
1354 | xReadFlag( uiSymbol ); uiIPredMode |= uiSymbol << 4; |
---|
1355 | |
---|
1356 | if (uiIPredMode == 31) |
---|
1357 | { // Escape coding for the last two modes |
---|
1358 | xReadFlag( uiSymbol ); |
---|
1359 | uiIPredMode = uiSymbol ? 32 : 31; |
---|
1360 | } |
---|
1361 | } |
---|
1362 | |
---|
1363 | if (uiIPredMode >= iMostProbable) |
---|
1364 | uiIPredMode++; |
---|
1365 | } |
---|
1366 | |
---|
1367 | #if ADD_PLANAR_MODE |
---|
1368 | if (uiIPredMode == 2) |
---|
1369 | { |
---|
1370 | UInt planarFlag; |
---|
1371 | xReadFlag( planarFlag ); |
---|
1372 | if ( planarFlag ) |
---|
1373 | { |
---|
1374 | uiIPredMode = PLANAR_IDX; |
---|
1375 | } |
---|
1376 | } |
---|
1377 | #endif |
---|
1378 | pcCU->setLumaIntraDirSubParts( (UChar)uiIPredMode, uiAbsPartIdx, uiDepth ); |
---|
1379 | } |
---|
1380 | #endif |
---|
1381 | |
---|
1382 | Void TDecCavlc::parseIntraDirChroma( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth ) |
---|
1383 | { |
---|
1384 | UInt uiSymbol; |
---|
1385 | #if CHROMA_CODEWORD |
---|
1386 | UInt uiMode = pcCU->getLumaIntraDir(uiAbsPartIdx); |
---|
1387 | #if ADD_PLANAR_MODE |
---|
1388 | if ( (uiMode == 2 ) || (uiMode == PLANAR_IDX) ) |
---|
1389 | { |
---|
1390 | uiMode = 4; |
---|
1391 | } |
---|
1392 | #endif |
---|
1393 | #if LM_CHROMA |
---|
1394 | Int iMaxMode = pcCU->getSlice()->getSPS()->getUseLMChroma() ? 3 : 4; |
---|
1395 | |
---|
1396 | Int iMax = uiMode < iMaxMode ? 3 : 4; |
---|
1397 | |
---|
1398 | xReadUnaryMaxSymbol( uiSymbol, iMax ); |
---|
1399 | |
---|
1400 | //switch codeword |
---|
1401 | if (uiSymbol == 0) |
---|
1402 | { |
---|
1403 | uiSymbol = 4; |
---|
1404 | } |
---|
1405 | else if (uiSymbol == 1 && pcCU->getSlice()->getSPS()->getUseLMChroma()) |
---|
1406 | { |
---|
1407 | uiSymbol = 3; |
---|
1408 | } |
---|
1409 | else |
---|
1410 | { |
---|
1411 | #if CHROMA_CODEWORD_SWITCH |
---|
1412 | uiSymbol = ChromaMapping[iMax-3][uiSymbol]; |
---|
1413 | #endif |
---|
1414 | |
---|
1415 | if (pcCU->getSlice()->getSPS()->getUseLMChroma()) |
---|
1416 | uiSymbol --; |
---|
1417 | |
---|
1418 | if (uiSymbol <= uiMode) |
---|
1419 | uiSymbol --; |
---|
1420 | } |
---|
1421 | |
---|
1422 | #else // -- LM_CHROMA |
---|
1423 | |
---|
1424 | Int iMax = uiMode < 4 ? 3 : 4; |
---|
1425 | xReadUnaryMaxSymbol( uiSymbol, iMax ); |
---|
1426 | |
---|
1427 | //switch codeword |
---|
1428 | if (uiSymbol == 0) |
---|
1429 | { |
---|
1430 | uiSymbol = 4; |
---|
1431 | } |
---|
1432 | #if CHROMA_CODEWORD_SWITCH |
---|
1433 | else |
---|
1434 | { |
---|
1435 | uiSymbol = ChromaMapping[iMax-3][uiSymbol]; |
---|
1436 | if (uiSymbol <= uiMode) |
---|
1437 | { |
---|
1438 | uiSymbol --; |
---|
1439 | } |
---|
1440 | } |
---|
1441 | #else |
---|
1442 | else if (uiSymbol <= uiMode) |
---|
1443 | { |
---|
1444 | uiSymbol --; |
---|
1445 | } |
---|
1446 | #endif |
---|
1447 | #endif // --> LM_CHROMA |
---|
1448 | |
---|
1449 | //printf("uiMode %d, chroma %d, codeword %d, imax %d\n", uiMode, uiSymbol, uiRead, iMax); |
---|
1450 | #else |
---|
1451 | xReadFlag( uiSymbol ); |
---|
1452 | |
---|
1453 | if ( uiSymbol ) |
---|
1454 | { |
---|
1455 | xReadUnaryMaxSymbol( uiSymbol, 3 ); |
---|
1456 | uiSymbol++; |
---|
1457 | } |
---|
1458 | #endif |
---|
1459 | |
---|
1460 | #if ADD_PLANAR_MODE |
---|
1461 | if (uiSymbol == 2) |
---|
1462 | { |
---|
1463 | #if CHROMA_CODEWORD |
---|
1464 | uiMode = pcCU->getLumaIntraDir(uiAbsPartIdx); |
---|
1465 | if (uiMode == 2) |
---|
1466 | { |
---|
1467 | uiSymbol = PLANAR_IDX; |
---|
1468 | } |
---|
1469 | else if (uiMode != PLANAR_IDX) |
---|
1470 | #endif |
---|
1471 | { |
---|
1472 | UInt planarFlag; |
---|
1473 | xReadFlag( planarFlag ); |
---|
1474 | if ( planarFlag ) |
---|
1475 | { |
---|
1476 | uiSymbol = PLANAR_IDX; |
---|
1477 | } |
---|
1478 | } |
---|
1479 | } |
---|
1480 | #endif |
---|
1481 | pcCU->setChromIntraDirSubParts( uiSymbol, uiAbsPartIdx, uiDepth ); |
---|
1482 | |
---|
1483 | return ; |
---|
1484 | } |
---|
1485 | |
---|
1486 | Void TDecCavlc::parseInterDir( TComDataCU* pcCU, UInt& ruiInterDir, UInt uiAbsPartIdx, UInt uiDepth ) |
---|
1487 | { |
---|
1488 | UInt uiSymbol; |
---|
1489 | |
---|
1490 | #if UNIFY_INTER_TABLE |
---|
1491 | #if DCM_COMB_LIST |
---|
1492 | UInt uiNumRefIdxOfLC = pcCU->getSlice()->getNumRefIdx(REF_PIC_LIST_C); |
---|
1493 | #endif |
---|
1494 | #define min(a, b) (((a) < (b)) ? (a) : (b)) |
---|
1495 | #if DCM_COMB_LIST |
---|
1496 | UInt uiValNumRefIdxOfLC = min(4,pcCU->getSlice()->getNumRefIdx(REF_PIC_LIST_C)); |
---|
1497 | #endif |
---|
1498 | UInt uiValNumRefIdxOfL0 = min(2,pcCU->getSlice()->getNumRefIdx(REF_PIC_LIST_0)); |
---|
1499 | UInt uiValNumRefIdxOfL1 = min(2,pcCU->getSlice()->getNumRefIdx(REF_PIC_LIST_1)); |
---|
1500 | |
---|
1501 | if ( pcCU->getSlice()->getRefIdxCombineCoding() ) |
---|
1502 | { |
---|
1503 | UInt uiIndex,tmp; |
---|
1504 | #if CAVLC_COUNTER_ADAPT |
---|
1505 | Int x,cx; |
---|
1506 | #else |
---|
1507 | Int x,cx,y,cy; |
---|
1508 | #endif |
---|
1509 | |
---|
1510 | UInt *m_uiMITableD = m_uiMI1TableD; |
---|
1511 | |
---|
1512 | UInt uiMaxVal; |
---|
1513 | #if DCM_COMB_LIST |
---|
1514 | if (uiNumRefIdxOfLC > 0) |
---|
1515 | { |
---|
1516 | uiMaxVal = uiValNumRefIdxOfLC + uiValNumRefIdxOfL0*uiValNumRefIdxOfL1; |
---|
1517 | } |
---|
1518 | else |
---|
1519 | #endif |
---|
1520 | if (pcCU->getSlice()->getNoBackPredFlag()) |
---|
1521 | { |
---|
1522 | uiMaxVal = uiValNumRefIdxOfL0 + uiValNumRefIdxOfL0*uiValNumRefIdxOfL1; |
---|
1523 | } |
---|
1524 | else |
---|
1525 | { |
---|
1526 | uiMaxVal = uiValNumRefIdxOfL0 + uiValNumRefIdxOfL1 + uiValNumRefIdxOfL0*uiValNumRefIdxOfL1; |
---|
1527 | } |
---|
1528 | |
---|
1529 | xReadUnaryMaxSymbol( tmp, uiMaxVal ); |
---|
1530 | |
---|
1531 | x = m_uiMITableD[tmp]; |
---|
1532 | uiIndex = x; |
---|
1533 | |
---|
1534 | /* Adapt table */ |
---|
1535 | |
---|
1536 | cx = tmp; |
---|
1537 | #if CAVLC_COUNTER_ADAPT |
---|
1538 | adaptCodeword(cx, m_ucMI1TableCounter, m_ucMI1TableCounterSum, m_uiMITableD, NULL, 4 ); |
---|
1539 | #else |
---|
1540 | cy = Max(0,cx-1); |
---|
1541 | y = m_uiMITableD[cy]; |
---|
1542 | m_uiMITableD[cy] = x; |
---|
1543 | m_uiMITableD[cx] = y; |
---|
1544 | m_uiMITableVlcIdx += cx == m_uiMITableVlcIdx ? 0 : (cx < m_uiMITableVlcIdx ? -1 : 1); |
---|
1545 | #endif |
---|
1546 | |
---|
1547 | if (uiIndex < uiMaxVal) |
---|
1548 | { |
---|
1549 | #if DCM_COMB_LIST |
---|
1550 | if (uiNumRefIdxOfLC > 0) |
---|
1551 | { |
---|
1552 | if (uiIndex < uiValNumRefIdxOfLC) |
---|
1553 | { |
---|
1554 | ruiInterDir = 1; |
---|
1555 | m_iRefFrame0[uiAbsPartIdx] = uiIndex; |
---|
1556 | } |
---|
1557 | else |
---|
1558 | { |
---|
1559 | UInt uiTmp = uiIndex-uiValNumRefIdxOfLC; |
---|
1560 | ruiInterDir = 3; |
---|
1561 | |
---|
1562 | m_iRefFrame0[uiAbsPartIdx] = uiTmp/uiValNumRefIdxOfL1; //uiValNumRefIdxOfL1 == 1 or 2, so division can be converted to shift op |
---|
1563 | m_iRefFrame1[uiAbsPartIdx] = uiTmp%uiValNumRefIdxOfL1; |
---|
1564 | } |
---|
1565 | } |
---|
1566 | else |
---|
1567 | #endif |
---|
1568 | if (pcCU->getSlice()->getNoBackPredFlag()) |
---|
1569 | { |
---|
1570 | if (uiIndex < uiValNumRefIdxOfL0) |
---|
1571 | { |
---|
1572 | ruiInterDir = 1; |
---|
1573 | m_iRefFrame0[uiAbsPartIdx] = uiIndex; |
---|
1574 | } |
---|
1575 | else |
---|
1576 | { |
---|
1577 | UInt uiTmp = uiIndex-uiValNumRefIdxOfL0; |
---|
1578 | ruiInterDir = 3; |
---|
1579 | |
---|
1580 | m_iRefFrame0[uiAbsPartIdx] = uiTmp/uiValNumRefIdxOfL1; //uiValNumRefIdxOfL1 == 1 or 2, so division can be converted to shift op |
---|
1581 | m_iRefFrame1[uiAbsPartIdx] = uiTmp%uiValNumRefIdxOfL1; |
---|
1582 | } |
---|
1583 | } |
---|
1584 | else |
---|
1585 | { |
---|
1586 | if (uiIndex < uiValNumRefIdxOfL0) |
---|
1587 | { |
---|
1588 | ruiInterDir = 1; |
---|
1589 | m_iRefFrame0[uiAbsPartIdx] = uiIndex; |
---|
1590 | } |
---|
1591 | else if (uiIndex < uiValNumRefIdxOfL1) |
---|
1592 | { |
---|
1593 | ruiInterDir = 2; |
---|
1594 | m_iRefFrame1[uiAbsPartIdx] = uiIndex-uiValNumRefIdxOfL0; |
---|
1595 | } |
---|
1596 | else |
---|
1597 | { |
---|
1598 | UInt uiTmp = uiIndex-uiValNumRefIdxOfL0-uiValNumRefIdxOfL1; |
---|
1599 | ruiInterDir = 3; |
---|
1600 | |
---|
1601 | m_iRefFrame0[uiAbsPartIdx] = uiTmp/uiValNumRefIdxOfL1; //uiValNumRefIdxOfL1 == 1 or 2, so division can be converted to shift op |
---|
1602 | m_iRefFrame1[uiAbsPartIdx] = uiTmp%uiValNumRefIdxOfL1; |
---|
1603 | } |
---|
1604 | } |
---|
1605 | |
---|
1606 | return; |
---|
1607 | } |
---|
1608 | } |
---|
1609 | #else //UNIFY_INTER_TABLE |
---|
1610 | #if MS_LCEC_LOOKUP_TABLE_EXCEPTION |
---|
1611 | if ( pcCU->getSlice()->getRefIdxCombineCoding() ) |
---|
1612 | #else |
---|
1613 | if(pcCU->getSlice()->getNumRefIdx( REF_PIC_LIST_0 ) <= 2 && pcCU->getSlice()->getNumRefIdx( REF_PIC_LIST_1 ) <= 2) |
---|
1614 | #endif |
---|
1615 | { |
---|
1616 | UInt uiIndex,uiInterDir,tmp; |
---|
1617 | |
---|
1618 | #if CAVLC_COUNTER_ADAPT |
---|
1619 | Int x,cx; |
---|
1620 | #else |
---|
1621 | Int x,cx,y,cy; |
---|
1622 | #endif |
---|
1623 | |
---|
1624 | #if MS_LCEC_LOOKUP_TABLE_MAX_VALUE |
---|
1625 | UInt uiMaxVal = 7; |
---|
1626 | #if MS_LCEC_LOOKUP_TABLE_EXCEPTION |
---|
1627 | uiMaxVal = 8; |
---|
1628 | #endif |
---|
1629 | if ( pcCU->getSlice()->getNumRefIdx( REF_PIC_LIST_0 ) <= 1 && pcCU->getSlice()->getNumRefIdx( REF_PIC_LIST_1 ) <= 1 ) |
---|
1630 | { |
---|
1631 | if ( pcCU->getSlice()->getNoBackPredFlag() || ( pcCU->getSlice()->getNumRefIdx(REF_PIC_LIST_C) > 0 && pcCU->getSlice()->getNumRefIdx(REF_PIC_LIST_C) <= 1 ) ) |
---|
1632 | { |
---|
1633 | uiMaxVal = 1; |
---|
1634 | } |
---|
1635 | else |
---|
1636 | { |
---|
1637 | uiMaxVal = 2; |
---|
1638 | } |
---|
1639 | } |
---|
1640 | else if ( pcCU->getSlice()->getNumRefIdx( REF_PIC_LIST_0 ) <= 2 && pcCU->getSlice()->getNumRefIdx( REF_PIC_LIST_1 ) <= 2 ) |
---|
1641 | { |
---|
1642 | if ( pcCU->getSlice()->getNoBackPredFlag() || ( pcCU->getSlice()->getNumRefIdx(REF_PIC_LIST_C) > 0 && pcCU->getSlice()->getNumRefIdx(REF_PIC_LIST_C) <= 2 ) ) |
---|
1643 | { |
---|
1644 | uiMaxVal = 5; |
---|
1645 | } |
---|
1646 | else |
---|
1647 | { |
---|
1648 | uiMaxVal = 7; |
---|
1649 | } |
---|
1650 | } |
---|
1651 | else if ( pcCU->getSlice()->getNumRefIdx(REF_PIC_LIST_C) <= 0 ) |
---|
1652 | { |
---|
1653 | uiMaxVal = 4+1+MS_LCEC_UNI_EXCEPTION_THRES; |
---|
1654 | } |
---|
1655 | |
---|
1656 | xReadUnaryMaxSymbol( tmp, uiMaxVal ); |
---|
1657 | #else |
---|
1658 | UInt vlcn = g_auiMITableVlcNum[m_uiMITableVlcIdx]; |
---|
1659 | tmp = xReadVlc( vlcn ); |
---|
1660 | #endif |
---|
1661 | |
---|
1662 | UInt *m_uiMITableD = m_uiMI1TableD; |
---|
1663 | x = m_uiMITableD[tmp]; |
---|
1664 | uiIndex = x; |
---|
1665 | |
---|
1666 | /* Adapt table */ |
---|
1667 | |
---|
1668 | cx = tmp; |
---|
1669 | |
---|
1670 | #if CAVLC_COUNTER_ADAPT |
---|
1671 | adaptCodeword(cx, m_ucMI1TableCounter, m_ucMI1TableCounterSum, m_uiMITableD, NULL, 4 ); |
---|
1672 | #else |
---|
1673 | cy = Max(0,cx-1); |
---|
1674 | y = m_uiMITableD[cy]; |
---|
1675 | m_uiMITableD[cy] = x; |
---|
1676 | m_uiMITableD[cx] = y; |
---|
1677 | m_uiMITableVlcIdx += cx == m_uiMITableVlcIdx ? 0 : (cx < m_uiMITableVlcIdx ? -1 : 1); |
---|
1678 | #endif |
---|
1679 | { |
---|
1680 | uiInterDir = Min(2,uiIndex>>1); |
---|
1681 | #if MS_LCEC_LOOKUP_TABLE_EXCEPTION |
---|
1682 | if ( uiIndex >=4 ) |
---|
1683 | { |
---|
1684 | uiInterDir = 2; |
---|
1685 | } |
---|
1686 | else |
---|
1687 | { |
---|
1688 | uiInterDir = 0; |
---|
1689 | } |
---|
1690 | #endif |
---|
1691 | #if DCM_COMB_LIST |
---|
1692 | if(uiInterDir!=2 && pcCU->getSlice()->getNumRefIdx(REF_PIC_LIST_C)>0) |
---|
1693 | { |
---|
1694 | uiInterDir = 0; |
---|
1695 | m_iRefFrame0[uiAbsPartIdx] = uiIndex; |
---|
1696 | } |
---|
1697 | else |
---|
1698 | #endif |
---|
1699 | if (uiInterDir==0) |
---|
1700 | { |
---|
1701 | #if MS_LCEC_LOOKUP_TABLE_EXCEPTION |
---|
1702 | m_iRefFrame0[uiAbsPartIdx] = uiIndex; |
---|
1703 | #else |
---|
1704 | m_iRefFrame0[uiAbsPartIdx] = uiIndex&1; |
---|
1705 | #endif |
---|
1706 | } |
---|
1707 | else if (uiInterDir==1) |
---|
1708 | m_iRefFrame1[uiAbsPartIdx] = uiIndex&1; |
---|
1709 | else |
---|
1710 | { |
---|
1711 | m_iRefFrame0[uiAbsPartIdx] = (uiIndex>>1)&1; |
---|
1712 | m_iRefFrame1[uiAbsPartIdx] = (uiIndex>>0)&1; |
---|
1713 | } |
---|
1714 | } |
---|
1715 | ruiInterDir = uiInterDir+1; |
---|
1716 | #if MS_LCEC_LOOKUP_TABLE_EXCEPTION |
---|
1717 | if ( x < 8 ) |
---|
1718 | #endif |
---|
1719 | { |
---|
1720 | return; |
---|
1721 | } |
---|
1722 | } |
---|
1723 | #endif //UNIFY_INTER_TABLE |
---|
1724 | |
---|
1725 | #if MS_LCEC_LOOKUP_TABLE_EXCEPTION |
---|
1726 | m_iRefFrame0[uiAbsPartIdx] = 1000; |
---|
1727 | m_iRefFrame1[uiAbsPartIdx] = 1000; |
---|
1728 | #endif |
---|
1729 | |
---|
1730 | xReadFlag( uiSymbol ); |
---|
1731 | |
---|
1732 | if ( uiSymbol ) |
---|
1733 | { |
---|
1734 | uiSymbol = 2; |
---|
1735 | } |
---|
1736 | #if DCM_COMB_LIST |
---|
1737 | else if(pcCU->getSlice()->getNumRefIdx(REF_PIC_LIST_C) > 0) |
---|
1738 | { |
---|
1739 | uiSymbol = 0; |
---|
1740 | } |
---|
1741 | #endif |
---|
1742 | else if ( pcCU->getSlice()->getNoBackPredFlag() ) |
---|
1743 | { |
---|
1744 | uiSymbol = 0; |
---|
1745 | } |
---|
1746 | else |
---|
1747 | { |
---|
1748 | xReadFlag( uiSymbol ); |
---|
1749 | } |
---|
1750 | uiSymbol++; |
---|
1751 | ruiInterDir = uiSymbol; |
---|
1752 | return; |
---|
1753 | } |
---|
1754 | |
---|
1755 | Void TDecCavlc::parseRefFrmIdx( TComDataCU* pcCU, Int& riRefFrmIdx, UInt uiAbsPartIdx, UInt uiDepth, RefPicList eRefList ) |
---|
1756 | { |
---|
1757 | UInt uiSymbol; |
---|
1758 | |
---|
1759 | if (pcCU->getSlice()->getNumRefIdx( REF_PIC_LIST_0 ) <= 2 && pcCU->getSlice()->getNumRefIdx( REF_PIC_LIST_1 ) <= 2 && pcCU->getSlice()->isInterB()) |
---|
1760 | { |
---|
1761 | #if DCM_COMB_LIST |
---|
1762 | if(pcCU->getSlice()->getNumRefIdx(REF_PIC_LIST_C ) > 0 && eRefList==REF_PIC_LIST_C) |
---|
1763 | { |
---|
1764 | riRefFrmIdx = m_iRefFrame0[uiAbsPartIdx]; |
---|
1765 | } |
---|
1766 | else |
---|
1767 | #endif |
---|
1768 | if (eRefList==REF_PIC_LIST_0) |
---|
1769 | { |
---|
1770 | riRefFrmIdx = m_iRefFrame0[uiAbsPartIdx]; |
---|
1771 | } |
---|
1772 | if (eRefList==REF_PIC_LIST_1) |
---|
1773 | { |
---|
1774 | riRefFrmIdx = m_iRefFrame1[uiAbsPartIdx]; |
---|
1775 | } |
---|
1776 | return; |
---|
1777 | } |
---|
1778 | |
---|
1779 | #if MS_LCEC_LOOKUP_TABLE_EXCEPTION |
---|
1780 | if ( ( m_iRefFrame0[uiAbsPartIdx] != 1000 || m_iRefFrame1[uiAbsPartIdx] != 1000 ) && |
---|
1781 | pcCU->getSlice()->getRefIdxCombineCoding() ) |
---|
1782 | { |
---|
1783 | if(pcCU->getSlice()->getNumRefIdx(REF_PIC_LIST_C ) > 0 && eRefList==REF_PIC_LIST_C ) |
---|
1784 | { |
---|
1785 | riRefFrmIdx = m_iRefFrame0[uiAbsPartIdx]; |
---|
1786 | } |
---|
1787 | else if (eRefList==REF_PIC_LIST_0) |
---|
1788 | { |
---|
1789 | riRefFrmIdx = m_iRefFrame0[uiAbsPartIdx]; |
---|
1790 | } |
---|
1791 | else if (eRefList==REF_PIC_LIST_1) |
---|
1792 | { |
---|
1793 | riRefFrmIdx = m_iRefFrame1[uiAbsPartIdx]; |
---|
1794 | } |
---|
1795 | return; |
---|
1796 | } |
---|
1797 | |
---|
1798 | UInt uiRefFrmIdxMinus = 0; |
---|
1799 | if ( pcCU->getSlice()->getRefIdxCombineCoding() ) |
---|
1800 | { |
---|
1801 | if ( pcCU->getInterDir( uiAbsPartIdx ) != 3 ) |
---|
1802 | { |
---|
1803 | if ( pcCU->getSlice()->getNumRefIdx(REF_PIC_LIST_C) > 0 ) |
---|
1804 | { |
---|
1805 | uiRefFrmIdxMinus = 4; |
---|
1806 | } |
---|
1807 | else |
---|
1808 | { |
---|
1809 | uiRefFrmIdxMinus = MS_LCEC_UNI_EXCEPTION_THRES+1; |
---|
1810 | } |
---|
1811 | } |
---|
1812 | else if ( eRefList == REF_PIC_LIST_1 && pcCU->getCUMvField( REF_PIC_LIST_0 )->getRefIdx( uiAbsPartIdx ) < 2 ) |
---|
1813 | { |
---|
1814 | uiRefFrmIdxMinus = 2; |
---|
1815 | } |
---|
1816 | } |
---|
1817 | if ( pcCU->getSlice()->getNumRefIdx( eRefList ) - uiRefFrmIdxMinus <= 1 ) |
---|
1818 | { |
---|
1819 | uiSymbol = 0; |
---|
1820 | riRefFrmIdx = uiSymbol; |
---|
1821 | riRefFrmIdx += uiRefFrmIdxMinus; |
---|
1822 | return; |
---|
1823 | } |
---|
1824 | #endif |
---|
1825 | |
---|
1826 | xReadFlag ( uiSymbol ); |
---|
1827 | if ( uiSymbol ) |
---|
1828 | { |
---|
1829 | #if MS_LCEC_LOOKUP_TABLE_EXCEPTION |
---|
1830 | xReadUnaryMaxSymbol( uiSymbol, pcCU->getSlice()->getNumRefIdx( eRefList )-2 - uiRefFrmIdxMinus ); |
---|
1831 | #else |
---|
1832 | xReadUnaryMaxSymbol( uiSymbol, pcCU->getSlice()->getNumRefIdx( eRefList )-2 ); |
---|
1833 | #endif |
---|
1834 | |
---|
1835 | uiSymbol++; |
---|
1836 | } |
---|
1837 | riRefFrmIdx = uiSymbol; |
---|
1838 | #if MS_LCEC_LOOKUP_TABLE_EXCEPTION |
---|
1839 | riRefFrmIdx += uiRefFrmIdxMinus; |
---|
1840 | #endif |
---|
1841 | |
---|
1842 | return; |
---|
1843 | } |
---|
1844 | |
---|
1845 | Void TDecCavlc::parseMvd( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiPartIdx, UInt uiDepth, RefPicList eRefList ) |
---|
1846 | { |
---|
1847 | Int iHor, iVer; |
---|
1848 | UInt uiAbsPartIdxL, uiAbsPartIdxA; |
---|
1849 | Int iHorPred, iVerPred; |
---|
1850 | |
---|
1851 | TComDataCU* pcCUL = pcCU->getPULeft ( uiAbsPartIdxL, pcCU->getZorderIdxInCU() + uiAbsPartIdx ); |
---|
1852 | TComDataCU* pcCUA = pcCU->getPUAbove( uiAbsPartIdxA, pcCU->getZorderIdxInCU() + uiAbsPartIdx ); |
---|
1853 | |
---|
1854 | TComCUMvField* pcCUMvFieldL = ( pcCUL == NULL || pcCUL->isIntra( uiAbsPartIdxL ) ) ? NULL : pcCUL->getCUMvField( eRefList ); |
---|
1855 | TComCUMvField* pcCUMvFieldA = ( pcCUA == NULL || pcCUA->isIntra( uiAbsPartIdxA ) ) ? NULL : pcCUA->getCUMvField( eRefList ); |
---|
1856 | |
---|
1857 | iHorPred = ( (pcCUMvFieldL == NULL) ? 0 : pcCUMvFieldL->getMvd( uiAbsPartIdxL ).getAbsHor() ) + |
---|
1858 | ( (pcCUMvFieldA == NULL) ? 0 : pcCUMvFieldA->getMvd( uiAbsPartIdxA ).getAbsHor() ); |
---|
1859 | iVerPred = ( (pcCUMvFieldL == NULL) ? 0 : pcCUMvFieldL->getMvd( uiAbsPartIdxL ).getAbsVer() ) + |
---|
1860 | ( (pcCUMvFieldA == NULL) ? 0 : pcCUMvFieldA->getMvd( uiAbsPartIdxA ).getAbsVer() ); |
---|
1861 | |
---|
1862 | TComMv cTmpMv( 0, 0 ); |
---|
1863 | pcCU->getCUMvField( eRefList )->setAllMv( cTmpMv, pcCU->getPartitionSize( uiAbsPartIdx ), uiAbsPartIdx, uiPartIdx, uiDepth ); |
---|
1864 | |
---|
1865 | xReadSvlc( iHor ); |
---|
1866 | xReadSvlc( iVer ); |
---|
1867 | |
---|
1868 | // set mvd |
---|
1869 | TComMv cMv( iHor, iVer ); |
---|
1870 | pcCU->getCUMvField( eRefList )->setAllMvd( cMv, pcCU->getPartitionSize( uiAbsPartIdx ), uiAbsPartIdx, uiPartIdx, uiDepth ); |
---|
1871 | |
---|
1872 | return; |
---|
1873 | } |
---|
1874 | |
---|
1875 | Void TDecCavlc::parseDeltaQP( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth ) |
---|
1876 | { |
---|
1877 | UInt uiDQp; |
---|
1878 | Int iDQp; |
---|
1879 | |
---|
1880 | xReadFlag( uiDQp ); |
---|
1881 | |
---|
1882 | if ( uiDQp == 0 ) |
---|
1883 | { |
---|
1884 | uiDQp = pcCU->getSlice()->getSliceQp(); |
---|
1885 | } |
---|
1886 | else |
---|
1887 | { |
---|
1888 | xReadSvlc( iDQp ); |
---|
1889 | uiDQp = pcCU->getSlice()->getSliceQp() + iDQp; |
---|
1890 | } |
---|
1891 | |
---|
1892 | pcCU->setQPSubParts( uiDQp, uiAbsPartIdx, uiDepth ); |
---|
1893 | } |
---|
1894 | |
---|
1895 | #if CAVLC_RQT_CBP |
---|
1896 | /** Function for parsing cbf and split |
---|
1897 | * \param pcCU pointer to CU |
---|
1898 | * \param uiAbsPartIdx CU index |
---|
1899 | * \param uiTrDepth Transform depth |
---|
1900 | * \param uiDepth CU Depth |
---|
1901 | * \param uiSubdiv split flag |
---|
1902 | * \returns |
---|
1903 | * This function performs parsing for cbf and split flag |
---|
1904 | */ |
---|
1905 | Void TDecCavlc::parseCbfTrdiv( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiTrDepth, UInt uiDepth, UInt& uiSubdiv ) |
---|
1906 | { |
---|
1907 | UInt uiCbf,tmp; |
---|
1908 | UInt uiCBP,uiCbfY,uiCbfU,uiCbfV; |
---|
1909 | UInt n,cx; |
---|
1910 | UInt uiLog2TrSize = g_aucConvertToBit[ pcCU->getSlice()->getSPS()->getMaxCUWidth() >> uiDepth ] + 2; |
---|
1911 | UInt uiQPartNumParent = pcCU->getPic()->getNumPartInCU() >> ((uiDepth-1) << 1); |
---|
1912 | UInt uiQPartNumCurr = pcCU->getPic()->getNumPartInCU() >> ((uiDepth) << 1); |
---|
1913 | |
---|
1914 | UInt uiFlagPattern = xGetFlagPattern( pcCU, uiAbsPartIdx, uiDepth, uiSubdiv ); |
---|
1915 | |
---|
1916 | n = pcCU->isIntra( uiAbsPartIdx ) ? 0 : 1; |
---|
1917 | uiCbfY = uiCbfU = uiCbfV = 0; |
---|
1918 | |
---|
1919 | if(uiFlagPattern < 8) |
---|
1920 | { |
---|
1921 | if( uiLog2TrSize > pcCU->getSlice()->getSPS()->getQuadtreeTULog2MinSize() ) |
---|
1922 | { |
---|
1923 | if(uiFlagPattern & 0x04) |
---|
1924 | { |
---|
1925 | xReadFlag(uiCbfU); |
---|
1926 | } |
---|
1927 | if(uiFlagPattern & 0x02) |
---|
1928 | { |
---|
1929 | xReadFlag(uiCbfV); |
---|
1930 | } |
---|
1931 | } |
---|
1932 | else |
---|
1933 | { |
---|
1934 | uiCbfU = pcCU->getCbf(uiAbsPartIdx, TEXT_CHROMA_U, uiTrDepth - 1)?1:0; |
---|
1935 | uiCbfV = pcCU->getCbf(uiAbsPartIdx, TEXT_CHROMA_V, uiTrDepth - 1)?1:0; |
---|
1936 | } |
---|
1937 | if(uiFlagPattern & 0x01) |
---|
1938 | { |
---|
1939 | parseTransformSubdivFlag( uiSubdiv, 0); |
---|
1940 | } |
---|
1941 | } |
---|
1942 | else |
---|
1943 | { |
---|
1944 | if(uiFlagPattern == 8) |
---|
1945 | { |
---|
1946 | if (uiAbsPartIdx % uiQPartNumParent ==0) |
---|
1947 | { |
---|
1948 | parseBlockCbf(pcCU, uiAbsPartIdx, TEXT_LUMA, uiTrDepth,uiDepth, uiQPartNumCurr); |
---|
1949 | } |
---|
1950 | uiCbfY = ( pcCU->getCbf( uiAbsPartIdx, TEXT_LUMA ) >> uiTrDepth) & 0x1; |
---|
1951 | if( uiLog2TrSize <= pcCU->getSlice()->getSPS()->getQuadtreeTULog2MinSize() ) |
---|
1952 | { |
---|
1953 | uiCbfU = pcCU->getCbf(uiAbsPartIdx, TEXT_CHROMA_U, uiTrDepth - 1)?1:0; |
---|
1954 | uiCbfV = pcCU->getCbf(uiAbsPartIdx, TEXT_CHROMA_V, uiTrDepth - 1)?1:0; |
---|
1955 | } |
---|
1956 | } |
---|
1957 | else if(uiFlagPattern == 9) |
---|
1958 | { |
---|
1959 | bool bNeedToDecode = true; |
---|
1960 | if ( n==1 && (uiAbsPartIdx%uiQPartNumParent) / uiQPartNumCurr == 3 ) // last one |
---|
1961 | { |
---|
1962 | UInt uiTempAbsPartIdx = uiAbsPartIdx/uiQPartNumParent*uiQPartNumParent; |
---|
1963 | if ( pcCU->getCbf( uiTempAbsPartIdx + uiQPartNumCurr*0, TEXT_LUMA, uiTrDepth ) || |
---|
1964 | pcCU->getCbf( uiTempAbsPartIdx + uiQPartNumCurr*1, TEXT_LUMA, uiTrDepth ) || |
---|
1965 | pcCU->getCbf( uiTempAbsPartIdx + uiQPartNumCurr*2, TEXT_LUMA, uiTrDepth ) ) |
---|
1966 | { |
---|
1967 | bNeedToDecode = true; |
---|
1968 | } |
---|
1969 | else |
---|
1970 | { |
---|
1971 | bNeedToDecode = false; |
---|
1972 | xReadFlag( uiSubdiv ); |
---|
1973 | uiCbfY = 1; |
---|
1974 | } |
---|
1975 | } |
---|
1976 | if ( bNeedToDecode ) |
---|
1977 | { |
---|
1978 | UInt uiSymbol; |
---|
1979 | xReadUnaryMaxSymbol(cx, n?2:3); |
---|
1980 | uiSymbol = m_uiCBP_YS_TableD[n][cx]; |
---|
1981 | uiCbfY = uiSymbol >> 1; |
---|
1982 | uiSubdiv = uiSymbol & 0x01; |
---|
1983 | adaptCodeword(cx, m_ucCBP_YS_TableCounter[n], m_ucCBP_YS_TableCounterSum[n], m_uiCBP_YS_TableD[n], NULL, 3); |
---|
1984 | } |
---|
1985 | } |
---|
1986 | else if (uiFlagPattern == 14) |
---|
1987 | { |
---|
1988 | UInt uiIdx = uiTrDepth? (2 + n) : n; |
---|
1989 | xReadUnaryMaxSymbol(cx, 7); |
---|
1990 | uiCBP = m_uiCBP_YUV_TableD[uiIdx][cx]; |
---|
1991 | adaptCodeword(cx, m_ucCBP_YUV_TableCounter[uiIdx], m_ucCBP_YUV_TableCounterSum[uiIdx], m_uiCBP_YUV_TableD[uiIdx], NULL, 4); |
---|
1992 | uiCbfY = (uiCBP>>2)&1; |
---|
1993 | uiCbfU = (uiCBP>>1)&1; |
---|
1994 | uiCbfV = (uiCBP>>0)&1; |
---|
1995 | } |
---|
1996 | else if ( uiFlagPattern == 11 || uiFlagPattern == 13 || uiFlagPattern == 15) |
---|
1997 | { |
---|
1998 | UInt uiSymbol, i; |
---|
1999 | m_pcBitstream->pseudoRead(6, uiSymbol); |
---|
2000 | for (i=0;i<8;i++) |
---|
2001 | { |
---|
2002 | if( (uiSymbol>>(6 - g_auiCBP_YCS_TableLen[n][i])) == g_auiCBP_YCS_Table[n][i] && g_auiCBP_YCS_TableLen[n][i]) |
---|
2003 | { |
---|
2004 | m_pcBitstream->read(g_auiCBP_YCS_TableLen[n][i],uiSymbol); |
---|
2005 | uiSymbol =i; |
---|
2006 | break; |
---|
2007 | } |
---|
2008 | } |
---|
2009 | |
---|
2010 | uiCBP = m_uiCBP_YCS_TableD[n][uiSymbol]; |
---|
2011 | adaptCodeword(uiSymbol, m_ucCBP_YCS_TableCounter[n], m_ucCBP_YCS_TableCounterSum[n], m_uiCBP_YCS_TableD[n], NULL, 4); |
---|
2012 | uiCbfY = uiCBP >> 2; |
---|
2013 | UInt uiCbfUV = (uiCBP >> 1)& 0x01; |
---|
2014 | uiSubdiv = uiCBP & 0x01; |
---|
2015 | |
---|
2016 | uiCbfU = 0; uiCbfV = 0; |
---|
2017 | if (uiFlagPattern == 15) |
---|
2018 | { |
---|
2019 | if(uiCbfUV) |
---|
2020 | { |
---|
2021 | xReadUnaryMaxSymbol( uiSymbol , 2); |
---|
2022 | uiSymbol = n? (uiSymbol + 1): (3 - uiSymbol); |
---|
2023 | uiCbfU = uiSymbol >> 1; |
---|
2024 | uiCbfV = uiSymbol & 0x01; |
---|
2025 | } |
---|
2026 | } |
---|
2027 | else |
---|
2028 | { |
---|
2029 | uiCbfU = (uiFlagPattern & 0x04) ? uiCbfUV: 0; |
---|
2030 | uiCbfV = (uiFlagPattern & 0x02) ? uiCbfUV: 0; |
---|
2031 | } |
---|
2032 | } |
---|
2033 | else if (uiFlagPattern == 10 || uiFlagPattern == 12) |
---|
2034 | { |
---|
2035 | UInt uiSymbol; |
---|
2036 | xReadUnaryMaxSymbol(tmp, 3); |
---|
2037 | uiSymbol = g_auiCBP_YC_TableD[n][tmp]; |
---|
2038 | uiCbfY = uiSymbol >> 1; |
---|
2039 | |
---|
2040 | uiCbfU = uiCbfV = 0; |
---|
2041 | if(uiSymbol & 0x01) |
---|
2042 | { |
---|
2043 | uiCbfU = (uiFlagPattern & 0x04)? 1 : 0; |
---|
2044 | uiCbfV = (uiFlagPattern & 0x02)? 1 : 0; |
---|
2045 | } |
---|
2046 | } |
---|
2047 | } |
---|
2048 | |
---|
2049 | uiCbf = pcCU->getCbf( uiAbsPartIdx, TEXT_LUMA ); |
---|
2050 | pcCU->setCbfSubParts( uiCbf | ( uiCbfY << uiTrDepth ), TEXT_LUMA, uiAbsPartIdx, uiDepth ); |
---|
2051 | |
---|
2052 | uiCbf = pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_U ); |
---|
2053 | pcCU->setCbfSubParts( uiCbf | ( uiCbfU << uiTrDepth ), TEXT_CHROMA_U, uiAbsPartIdx, uiDepth ); |
---|
2054 | |
---|
2055 | uiCbf = pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_V ); |
---|
2056 | pcCU->setCbfSubParts( uiCbf | ( uiCbfV << uiTrDepth ), TEXT_CHROMA_V, uiAbsPartIdx, uiDepth ); |
---|
2057 | |
---|
2058 | if(!pcCU->isIntra(uiAbsPartIdx) && uiCbfY == 0 && uiCbfU == 0 && uiCbfV == 0) |
---|
2059 | { |
---|
2060 | uiSubdiv = 0; |
---|
2061 | } |
---|
2062 | |
---|
2063 | return; |
---|
2064 | } |
---|
2065 | |
---|
2066 | /** Function for parsing cbf and split |
---|
2067 | * \param pcCU pointer to CU |
---|
2068 | * \param uiAbsPartIdx CU index |
---|
2069 | * \param uiDepth CU Depth |
---|
2070 | * \param uiSubdiv split flag |
---|
2071 | * \returns flag pattern |
---|
2072 | * This function gets flagpattern for cbf and split flag |
---|
2073 | */ |
---|
2074 | UInt TDecCavlc::xGetFlagPattern( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, UInt& uiSubdiv ) |
---|
2075 | { |
---|
2076 | const UInt uiLog2TrafoSize = g_aucConvertToBit[pcCU->getSlice()->getSPS()->getMaxCUWidth()]+2 - uiDepth; |
---|
2077 | UInt uiTrDepth = uiDepth - pcCU->getDepth( uiAbsPartIdx ); |
---|
2078 | UInt patternYUV, patternDiv; |
---|
2079 | UInt bY, bU, bV; |
---|
2080 | |
---|
2081 | |
---|
2082 | UInt uiFullDepth = pcCU->getDepth(uiAbsPartIdx) + uiTrDepth; |
---|
2083 | UInt uiLog2TrSize = g_aucConvertToBit[ pcCU->getSlice()->getSPS()->getMaxCUWidth() >> uiFullDepth ] + 2; |
---|
2084 | if(uiTrDepth == 0) |
---|
2085 | { |
---|
2086 | patternYUV = 7; |
---|
2087 | } |
---|
2088 | else if( uiLog2TrSize > pcCU->getSlice()->getSPS()->getQuadtreeTULog2MinSize() ) |
---|
2089 | { |
---|
2090 | bY = pcCU->getCbf(uiAbsPartIdx, TEXT_LUMA, uiTrDepth - 1)?1:0; |
---|
2091 | bU = pcCU->getCbf(uiAbsPartIdx, TEXT_CHROMA_U, uiTrDepth - 1)?1:0; |
---|
2092 | bV = pcCU->getCbf(uiAbsPartIdx, TEXT_CHROMA_V, uiTrDepth - 1)?1:0; |
---|
2093 | patternYUV = (bY<<2) + (bU<<1) + bV; |
---|
2094 | } |
---|
2095 | else |
---|
2096 | { |
---|
2097 | bY = pcCU->getCbf(uiAbsPartIdx, TEXT_LUMA, uiTrDepth - 1)?1:0; |
---|
2098 | patternYUV = bY<<2; |
---|
2099 | } |
---|
2100 | |
---|
2101 | |
---|
2102 | if( pcCU->getPredictionMode(uiAbsPartIdx) == MODE_INTRA && pcCU->getPartitionSize(uiAbsPartIdx) == SIZE_NxN && uiDepth == pcCU->getDepth(uiAbsPartIdx) ) |
---|
2103 | { |
---|
2104 | patternDiv = 0; uiSubdiv = 1; |
---|
2105 | } |
---|
2106 | else if( uiLog2TrafoSize > pcCU->getSlice()->getSPS()->getQuadtreeTULog2MaxSize() ) |
---|
2107 | { |
---|
2108 | patternDiv = 0; uiSubdiv = 1; |
---|
2109 | } |
---|
2110 | else if( uiLog2TrafoSize == pcCU->getSlice()->getSPS()->getQuadtreeTULog2MinSize() ) |
---|
2111 | { |
---|
2112 | patternDiv = 0; uiSubdiv = 0; |
---|
2113 | } |
---|
2114 | else if( uiLog2TrafoSize == pcCU->getQuadtreeTULog2MinSizeInCU(uiAbsPartIdx) ) |
---|
2115 | { |
---|
2116 | patternDiv = 0; uiSubdiv = 0; |
---|
2117 | } |
---|
2118 | else |
---|
2119 | { |
---|
2120 | patternDiv = 1; |
---|
2121 | } |
---|
2122 | |
---|
2123 | return ((patternYUV<<1)+patternDiv); |
---|
2124 | } |
---|
2125 | #endif |
---|
2126 | Void TDecCavlc::parseCbf( TComDataCU* pcCU, UInt uiAbsPartIdx, TextType eType, UInt uiTrDepth, UInt uiDepth ) |
---|
2127 | { |
---|
2128 | if (eType == TEXT_ALL) |
---|
2129 | { |
---|
2130 | UInt uiCbf,tmp; |
---|
2131 | UInt uiCBP,uiCbfY,uiCbfU,uiCbfV; |
---|
2132 | |
---|
2133 | #if CAVLC_COUNTER_ADAPT |
---|
2134 | Int n, cx; |
---|
2135 | #else |
---|
2136 | Int n,x,cx,y,cy; |
---|
2137 | #endif |
---|
2138 | |
---|
2139 | /* Start adaptation */ |
---|
2140 | n = pcCU->isIntra( uiAbsPartIdx ) ? 0 : 1; |
---|
2141 | #if CAVLC_RQT_CBP |
---|
2142 | UInt vlcn = 0; |
---|
2143 | #else |
---|
2144 | UInt vlcn = g_auiCbpVlcNum[n][m_uiCbpVlcIdx[n]]; |
---|
2145 | #endif |
---|
2146 | tmp = xReadVlc( vlcn ); |
---|
2147 | #if CAVLC_RQT_CBP |
---|
2148 | uiCBP = m_uiCBP_YUV_TableD[n][tmp]; |
---|
2149 | #else |
---|
2150 | uiCBP = m_uiCBPTableD[n][tmp]; |
---|
2151 | #endif |
---|
2152 | |
---|
2153 | /* Adapt LP table */ |
---|
2154 | cx = tmp; |
---|
2155 | |
---|
2156 | #if CAVLC_COUNTER_ADAPT |
---|
2157 | #if CAVLC_RQT_CBP |
---|
2158 | adaptCodeword(cx, m_ucCBP_YUV_TableCounter[n], m_ucCBP_YUV_TableCounterSum[n], m_uiCBP_YUV_TableD[n], NULL, 4); |
---|
2159 | #else |
---|
2160 | adaptCodeword(cx, m_ucCBFTableCounter[n], m_ucCBFTableCounterSum[n], m_uiCBPTableD[n], NULL, 4); |
---|
2161 | #endif |
---|
2162 | #else |
---|
2163 | cy = Max(0,cx-1); |
---|
2164 | x = uiCBP; |
---|
2165 | y = m_uiCBPTableD[n][cy]; |
---|
2166 | m_uiCBPTableD[n][cy] = x; |
---|
2167 | m_uiCBPTableD[n][cx] = y; |
---|
2168 | m_uiCbpVlcIdx[n] += cx == m_uiCbpVlcIdx[n] ? 0 : (cx < m_uiCbpVlcIdx[n] ? -1 : 1); |
---|
2169 | #endif |
---|
2170 | |
---|
2171 | uiCbfY = (uiCBP>>0)&1; |
---|
2172 | uiCbfU = (uiCBP>>1)&1; |
---|
2173 | uiCbfV = (uiCBP>>2)&1; |
---|
2174 | |
---|
2175 | uiCbf = pcCU->getCbf( uiAbsPartIdx, TEXT_LUMA ); |
---|
2176 | pcCU->setCbfSubParts( uiCbf | ( uiCbfY << uiTrDepth ), TEXT_LUMA, uiAbsPartIdx, uiDepth ); |
---|
2177 | |
---|
2178 | uiCbf = pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_U ); |
---|
2179 | pcCU->setCbfSubParts( uiCbf | ( uiCbfU << uiTrDepth ), TEXT_CHROMA_U, uiAbsPartIdx, uiDepth ); |
---|
2180 | |
---|
2181 | uiCbf = pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_V ); |
---|
2182 | pcCU->setCbfSubParts( uiCbf | ( uiCbfV << uiTrDepth ), TEXT_CHROMA_V, uiAbsPartIdx, uiDepth ); |
---|
2183 | } |
---|
2184 | } |
---|
2185 | |
---|
2186 | Void TDecCavlc::parseBlockCbf( TComDataCU* pcCU, UInt uiAbsPartIdx, TextType eType, UInt uiTrDepth, UInt uiDepth, UInt uiQPartNum ) |
---|
2187 | { |
---|
2188 | assert(uiTrDepth > 0); |
---|
2189 | UInt uiCbf4, uiCbf; |
---|
2190 | |
---|
2191 | #if CAVLC_COUNTER_ADAPT |
---|
2192 | Int cx; |
---|
2193 | #else |
---|
2194 | Int x,cx,y,cy; |
---|
2195 | #endif |
---|
2196 | |
---|
2197 | UInt tmp; |
---|
2198 | |
---|
2199 | UInt n = (pcCU->isIntra(uiAbsPartIdx) && eType == TEXT_LUMA)? 0:1; |
---|
2200 | #if CAVLC_RQT_CBP |
---|
2201 | UInt vlcn = (n==0)?g_auiCBP_4Y_VlcNum[m_uiCBP_4Y_VlcIdx]:11; |
---|
2202 | #else |
---|
2203 | UInt vlcn = (n==0)?g_auiBlkCbpVlcNum[m_uiBlkCbpVlcIdx]:11; |
---|
2204 | #endif |
---|
2205 | tmp = xReadVlc( vlcn ); |
---|
2206 | #if CAVLC_RQT_CBP |
---|
2207 | uiCbf4 = m_uiCBP_4Y_TableD[n][tmp]; |
---|
2208 | #else |
---|
2209 | uiCbf4 = m_uiBlkCBPTableD[n][tmp]; |
---|
2210 | #endif |
---|
2211 | |
---|
2212 | cx = tmp; |
---|
2213 | |
---|
2214 | #if CAVLC_COUNTER_ADAPT |
---|
2215 | #if CAVLC_RQT_CBP |
---|
2216 | adaptCodeword(cx, m_ucCBP_4Y_TableCounter[n], m_ucCBP_4Y_TableCounterSum[n], m_uiCBP_4Y_TableD[n], NULL, 2); |
---|
2217 | #else |
---|
2218 | adaptCodeword(cx, m_ucBlkCBPTableCounter[n], m_ucBlkCBPTableCounterSum[n], m_uiBlkCBPTableD[n], NULL, 2); |
---|
2219 | #endif |
---|
2220 | #else |
---|
2221 | cy = Max(0,cx-1); |
---|
2222 | x = uiCbf4; |
---|
2223 | y = m_uiBlkCBPTableD[n][cy]; |
---|
2224 | m_uiBlkCBPTableD[n][cy] = x; |
---|
2225 | m_uiBlkCBPTableD[n][cx] = y; |
---|
2226 | #endif |
---|
2227 | |
---|
2228 | #if CAVLC_RQT_CBP |
---|
2229 | if(n==0) |
---|
2230 | m_uiCBP_4Y_VlcIdx += cx == m_uiCBP_4Y_VlcIdx ? 0 : (cx < m_uiCBP_4Y_VlcIdx ? -1 : 1); |
---|
2231 | #else |
---|
2232 | if(n==0) |
---|
2233 | m_uiBlkCbpVlcIdx += cx == m_uiBlkCbpVlcIdx ? 0 : (cx < m_uiBlkCbpVlcIdx ? -1 : 1); |
---|
2234 | #endif |
---|
2235 | |
---|
2236 | uiCbf4++; |
---|
2237 | uiCbf = pcCU->getCbf( uiAbsPartIdx, eType ); |
---|
2238 | pcCU->setCbfSubParts( uiCbf | ( ((uiCbf4>>3)&0x01) << uiTrDepth ), eType, uiAbsPartIdx, uiDepth ); uiAbsPartIdx += uiQPartNum; |
---|
2239 | uiCbf = pcCU->getCbf( uiAbsPartIdx, eType ); |
---|
2240 | pcCU->setCbfSubParts( uiCbf | ( ((uiCbf4>>2)&0x01) << uiTrDepth ), eType, uiAbsPartIdx, uiDepth ); uiAbsPartIdx += uiQPartNum; |
---|
2241 | uiCbf = pcCU->getCbf( uiAbsPartIdx, eType ); |
---|
2242 | pcCU->setCbfSubParts( uiCbf | ( ((uiCbf4>>1)&0x01) << uiTrDepth ), eType, uiAbsPartIdx, uiDepth ); uiAbsPartIdx += uiQPartNum; |
---|
2243 | uiCbf = pcCU->getCbf( uiAbsPartIdx, eType ); |
---|
2244 | pcCU->setCbfSubParts( uiCbf | ( (uiCbf4&0x01) << uiTrDepth ), eType, uiAbsPartIdx, uiDepth ); |
---|
2245 | |
---|
2246 | return; |
---|
2247 | } |
---|
2248 | |
---|
2249 | Void TDecCavlc::parseCoeffNxN( TComDataCU* pcCU, TCoeff* pcCoef, UInt uiAbsPartIdx, UInt uiWidth, UInt uiHeight, UInt uiDepth, TextType eTType ) |
---|
2250 | { |
---|
2251 | |
---|
2252 | if ( uiWidth > pcCU->getSlice()->getSPS()->getMaxTrSize() ) |
---|
2253 | { |
---|
2254 | uiWidth = pcCU->getSlice()->getSPS()->getMaxTrSize(); |
---|
2255 | uiHeight = pcCU->getSlice()->getSPS()->getMaxTrSize(); |
---|
2256 | } |
---|
2257 | UInt uiSize = uiWidth*uiHeight; |
---|
2258 | |
---|
2259 | // point to coefficient |
---|
2260 | TCoeff* piCoeff = pcCoef; |
---|
2261 | |
---|
2262 | // initialize scan |
---|
2263 | const UInt* pucScan; |
---|
2264 | |
---|
2265 | #if CAVLC_COEF_LRG_BLK |
---|
2266 | UInt maxBlSize = (eTType==TEXT_LUMA)? 32:8; |
---|
2267 | UInt uiBlSize = Min(maxBlSize,uiWidth); |
---|
2268 | UInt uiConvBit = g_aucConvertToBit[ pcCU->isIntra( uiAbsPartIdx ) ? uiWidth : uiBlSize]; |
---|
2269 | UInt uiNoCoeff = uiBlSize*uiBlSize; |
---|
2270 | #else |
---|
2271 | //UInt uiConvBit = g_aucConvertToBit[ Min(8,uiWidth) ]; |
---|
2272 | UInt uiConvBit = g_aucConvertToBit[ pcCU->isIntra( uiAbsPartIdx ) ? uiWidth : Min(8,uiWidth) ]; |
---|
2273 | #endif |
---|
2274 | pucScan = g_auiFrameScanXY [ uiConvBit + 1 ]; |
---|
2275 | |
---|
2276 | #if QC_MDCS |
---|
2277 | UInt uiBlkPos; |
---|
2278 | #if CAVLC_COEF_LRG_BLK |
---|
2279 | UInt uiLog2BlkSize = g_aucConvertToBit[ pcCU->isIntra( uiAbsPartIdx ) ? uiWidth : uiBlSize] + 2; |
---|
2280 | #else |
---|
2281 | UInt uiLog2BlkSize = g_aucConvertToBit[ pcCU->isIntra( uiAbsPartIdx ) ? uiWidth : Min(8,uiWidth) ] + 2; |
---|
2282 | #endif |
---|
2283 | const UInt uiScanIdx = pcCU->getCoefScanIdx(uiAbsPartIdx, uiWidth, eTType==TEXT_LUMA, pcCU->isIntra(uiAbsPartIdx)); |
---|
2284 | #endif //QC_MDCS |
---|
2285 | |
---|
2286 | UInt uiDecodeDCCoeff = 0; |
---|
2287 | Int dcCoeff = 0; |
---|
2288 | if (pcCU->isIntra(uiAbsPartIdx)) |
---|
2289 | { |
---|
2290 | UInt uiAbsPartIdxL, uiAbsPartIdxA; |
---|
2291 | TComDataCU* pcCUL = pcCU->getPULeft (uiAbsPartIdxL, pcCU->getZorderIdxInCU() + uiAbsPartIdx); |
---|
2292 | TComDataCU* pcCUA = pcCU->getPUAbove(uiAbsPartIdxA, pcCU->getZorderIdxInCU() + uiAbsPartIdx); |
---|
2293 | if (pcCUL == NULL && pcCUA == NULL) |
---|
2294 | { |
---|
2295 | uiDecodeDCCoeff = 1; |
---|
2296 | dcCoeff = xReadVlc(eTType == TEXT_LUMA ? 3 : 1); |
---|
2297 | if (dcCoeff) |
---|
2298 | { |
---|
2299 | UInt sign; |
---|
2300 | xReadFlag(sign); |
---|
2301 | if (sign) |
---|
2302 | { |
---|
2303 | dcCoeff = -dcCoeff; |
---|
2304 | } |
---|
2305 | } |
---|
2306 | } |
---|
2307 | } |
---|
2308 | |
---|
2309 | UInt uiScanning; |
---|
2310 | |
---|
2311 | #if CAVLC_COEF_LRG_BLK |
---|
2312 | static TCoeff scoeff[1024]; |
---|
2313 | #else |
---|
2314 | TCoeff scoeff[64]; |
---|
2315 | #endif |
---|
2316 | Int iBlockType; |
---|
2317 | if( uiSize == 2*2 ) |
---|
2318 | { |
---|
2319 | // hack: re-use 4x4 coding |
---|
2320 | #if QC_MOD_LCEC |
---|
2321 | if (eTType==TEXT_CHROMA_U || eTType==TEXT_CHROMA_V) |
---|
2322 | iBlockType = eTType-2; |
---|
2323 | else |
---|
2324 | iBlockType = 2 + ( pcCU->isIntra(uiAbsPartIdx) ? 0 : pcCU->getSlice()->getSliceType() ); |
---|
2325 | #else |
---|
2326 | iBlockType = pcCU->isIntra(uiAbsPartIdx) ? 0 : pcCU->getSlice()->getSliceType(); |
---|
2327 | #endif |
---|
2328 | |
---|
2329 | #if CAVLC_COEF_LRG_BLK |
---|
2330 | xParseCoeff( scoeff, iBlockType, 4 ); |
---|
2331 | #else |
---|
2332 | xParseCoeff4x4( scoeff, iBlockType ); |
---|
2333 | #endif |
---|
2334 | |
---|
2335 | for (uiScanning=0; uiScanning<4; uiScanning++) |
---|
2336 | { |
---|
2337 | #if QC_MDCS |
---|
2338 | uiBlkPos = g_auiSigLastScan[uiScanIdx][uiLog2BlkSize-1][uiScanning]; |
---|
2339 | piCoeff[ uiBlkPos ] = scoeff[15-uiScanning]; |
---|
2340 | #else |
---|
2341 | piCoeff[ pucScan[ uiScanning ] ] = scoeff[15-uiScanning]; |
---|
2342 | #endif //QC_MDCS |
---|
2343 | } |
---|
2344 | } |
---|
2345 | else if ( uiSize == 4*4 ) |
---|
2346 | { |
---|
2347 | #if QC_MOD_LCEC |
---|
2348 | if (eTType==TEXT_CHROMA_U || eTType==TEXT_CHROMA_V) |
---|
2349 | iBlockType = eTType-2; |
---|
2350 | else |
---|
2351 | iBlockType = 2 + ( pcCU->isIntra(uiAbsPartIdx) ? 0 : pcCU->getSlice()->getSliceType() ); |
---|
2352 | #else |
---|
2353 | iBlockType = pcCU->isIntra(uiAbsPartIdx) ? 0 : pcCU->getSlice()->getSliceType(); |
---|
2354 | #endif |
---|
2355 | #if CAVLC_COEF_LRG_BLK |
---|
2356 | xParseCoeff( scoeff, iBlockType, 4 ); |
---|
2357 | #else |
---|
2358 | xParseCoeff4x4( scoeff, iBlockType ); |
---|
2359 | #endif |
---|
2360 | |
---|
2361 | for (uiScanning=0; uiScanning<16; uiScanning++) |
---|
2362 | { |
---|
2363 | #if QC_MDCS |
---|
2364 | uiBlkPos = g_auiSigLastScan[uiScanIdx][uiLog2BlkSize-1][uiScanning]; |
---|
2365 | piCoeff[ uiBlkPos ] = scoeff[15-uiScanning]; |
---|
2366 | #else |
---|
2367 | piCoeff[ pucScan[ uiScanning ] ] = scoeff[15-uiScanning]; |
---|
2368 | #endif //QC_MDCS |
---|
2369 | } |
---|
2370 | } |
---|
2371 | else if ( uiSize == 8*8 ) |
---|
2372 | { |
---|
2373 | if (eTType==TEXT_CHROMA_U || eTType==TEXT_CHROMA_V) //8x8 specific |
---|
2374 | iBlockType = eTType-2; |
---|
2375 | else |
---|
2376 | iBlockType = 2 + ( pcCU->isIntra(uiAbsPartIdx) ? 0 : pcCU->getSlice()->getSliceType() ); |
---|
2377 | #if CAVLC_COEF_LRG_BLK |
---|
2378 | xParseCoeff( scoeff, iBlockType, 8 ); |
---|
2379 | #else |
---|
2380 | xParseCoeff8x8( scoeff, iBlockType ); |
---|
2381 | #endif |
---|
2382 | |
---|
2383 | for (uiScanning=0; uiScanning<64; uiScanning++) |
---|
2384 | { |
---|
2385 | #if QC_MDCS |
---|
2386 | uiBlkPos = g_auiSigLastScan[uiScanIdx][uiLog2BlkSize-1][uiScanning]; |
---|
2387 | piCoeff[ uiBlkPos ] = scoeff[63-uiScanning]; |
---|
2388 | #else |
---|
2389 | piCoeff[ pucScan[ uiScanning ] ] = scoeff[63-uiScanning]; |
---|
2390 | #endif //QC_MDCS |
---|
2391 | } |
---|
2392 | |
---|
2393 | } |
---|
2394 | else |
---|
2395 | { |
---|
2396 | if (!pcCU->isIntra( uiAbsPartIdx )) |
---|
2397 | { |
---|
2398 | memset(piCoeff,0,sizeof(TCoeff)*uiSize); |
---|
2399 | if (eTType==TEXT_CHROMA_U || eTType==TEXT_CHROMA_V) |
---|
2400 | iBlockType = eTType-2; |
---|
2401 | else |
---|
2402 | iBlockType = 5 + ( pcCU->isIntra(uiAbsPartIdx) ? 0 : pcCU->getSlice()->getSliceType() ); |
---|
2403 | #if CAVLC_COEF_LRG_BLK |
---|
2404 | xParseCoeff( scoeff, iBlockType, uiBlSize ); |
---|
2405 | #else |
---|
2406 | xParseCoeff8x8( scoeff, iBlockType ); |
---|
2407 | #endif |
---|
2408 | |
---|
2409 | #if CAVLC_COEF_LRG_BLK |
---|
2410 | for (uiScanning=0; uiScanning<uiNoCoeff; uiScanning++) |
---|
2411 | { |
---|
2412 | #if QC_MDCS |
---|
2413 | uiBlkPos = g_auiSigLastScan[uiScanIdx][uiLog2BlkSize-1][uiScanning]; |
---|
2414 | uiBlkPos = (uiBlkPos/uiBlSize)* uiWidth + (uiBlkPos&(uiBlSize-1)); |
---|
2415 | piCoeff[ uiBlkPos ] = scoeff[uiNoCoeff-uiScanning-1]; |
---|
2416 | #else |
---|
2417 | piCoeff[(pucScan[uiScanning]/uiBlSize)*uiWidth + (pucScan[uiScanning]&(uiBlSize-1))]=scoeff[uiNoCoeff-uiScanning-1]; |
---|
2418 | #endif |
---|
2419 | } |
---|
2420 | #else |
---|
2421 | for (uiScanning=0; uiScanning<64; uiScanning++) |
---|
2422 | { |
---|
2423 | #if QC_MDCS |
---|
2424 | uiBlkPos = g_auiSigLastScan[uiScanIdx][uiLog2BlkSize-1][uiScanning]; |
---|
2425 | uiBlkPos = (uiBlkPos/8)* uiWidth + uiBlkPos%8; |
---|
2426 | piCoeff[ uiBlkPos ] = scoeff[63-uiScanning]; |
---|
2427 | #else |
---|
2428 | piCoeff[(pucScan[uiScanning]/8)*uiWidth + (pucScan[uiScanning]%8)] = scoeff[63-uiScanning]; |
---|
2429 | #endif //QC_MDCS |
---|
2430 | } |
---|
2431 | #endif |
---|
2432 | return; |
---|
2433 | } |
---|
2434 | |
---|
2435 | if(pcCU->isIntra( uiAbsPartIdx )) |
---|
2436 | { |
---|
2437 | memset(piCoeff,0,sizeof(TCoeff)*uiSize); |
---|
2438 | |
---|
2439 | if (eTType==TEXT_CHROMA_U || eTType==TEXT_CHROMA_V) |
---|
2440 | iBlockType = eTType-2; |
---|
2441 | else |
---|
2442 | iBlockType = 5 + ( pcCU->isIntra(uiAbsPartIdx) ? 0 : pcCU->getSlice()->getSliceType() ); |
---|
2443 | |
---|
2444 | #if CAVLC_COEF_LRG_BLK |
---|
2445 | xParseCoeff( scoeff, iBlockType, uiBlSize ); |
---|
2446 | for (uiScanning=0; uiScanning<uiNoCoeff; uiScanning++) |
---|
2447 | { |
---|
2448 | #if QC_MDCS |
---|
2449 | uiBlkPos = g_auiSigLastScan[uiScanIdx][uiLog2BlkSize-1][uiScanning]; |
---|
2450 | piCoeff[ uiBlkPos ] = scoeff[uiNoCoeff - uiScanning - 1]; |
---|
2451 | #else |
---|
2452 | piCoeff[ pucScan[ uiScanning ] ] = scoeff[uiNoCoeff - uiScanning - 1]; |
---|
2453 | #endif //QC_MDCS |
---|
2454 | } |
---|
2455 | #else |
---|
2456 | xParseCoeff8x8( scoeff, iBlockType ); |
---|
2457 | |
---|
2458 | for (uiScanning=0; uiScanning<64; uiScanning++) |
---|
2459 | { |
---|
2460 | #if QC_MDCS |
---|
2461 | uiBlkPos = g_auiSigLastScan[uiScanIdx][uiLog2BlkSize-1][uiScanning]; |
---|
2462 | piCoeff[ uiBlkPos ] = scoeff[63-uiScanning]; |
---|
2463 | #else |
---|
2464 | piCoeff[ pucScan[ uiScanning ] ] = scoeff[63-uiScanning]; |
---|
2465 | #endif //QC_MDCS |
---|
2466 | } |
---|
2467 | #endif |
---|
2468 | } |
---|
2469 | } |
---|
2470 | |
---|
2471 | if (uiDecodeDCCoeff == 1) |
---|
2472 | { |
---|
2473 | piCoeff[0] = dcCoeff; |
---|
2474 | } |
---|
2475 | |
---|
2476 | return ; |
---|
2477 | } |
---|
2478 | |
---|
2479 | Void TDecCavlc::parseTransformSubdivFlag( UInt& ruiSubdivFlag, UInt uiLog2TransformBlockSize ) |
---|
2480 | { |
---|
2481 | xReadFlag( ruiSubdivFlag ); |
---|
2482 | } |
---|
2483 | |
---|
2484 | Void TDecCavlc::parseQtCbf( TComDataCU* pcCU, UInt uiAbsPartIdx, TextType eType, UInt uiTrDepth, UInt uiDepth ) |
---|
2485 | { |
---|
2486 | UInt uiSymbol; |
---|
2487 | xReadFlag( uiSymbol ); |
---|
2488 | pcCU->setCbfSubParts( uiSymbol << uiTrDepth, eType, uiAbsPartIdx, uiDepth ); |
---|
2489 | } |
---|
2490 | |
---|
2491 | Void TDecCavlc::parseQtRootCbf( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, UInt& uiQtRootCbf ) |
---|
2492 | { |
---|
2493 | UInt uiSymbol; |
---|
2494 | xReadFlag( uiSymbol ); |
---|
2495 | uiQtRootCbf = uiSymbol; |
---|
2496 | } |
---|
2497 | |
---|
2498 | Void TDecCavlc::parseAlfFlag (UInt& ruiVal) |
---|
2499 | { |
---|
2500 | xReadFlag( ruiVal ); |
---|
2501 | } |
---|
2502 | |
---|
2503 | #if TSB_ALF_HEADER |
---|
2504 | Void TDecCavlc::parseAlfFlagNum( UInt& ruiVal, UInt minValue, UInt depth ) |
---|
2505 | { |
---|
2506 | UInt uiLength = 0; |
---|
2507 | UInt maxValue = (minValue << (depth*2)); |
---|
2508 | UInt temp = maxValue - minValue; |
---|
2509 | for(UInt i=0; i<32; i++) |
---|
2510 | { |
---|
2511 | if(temp&0x1) |
---|
2512 | { |
---|
2513 | uiLength = i+1; |
---|
2514 | } |
---|
2515 | temp = (temp >> 1); |
---|
2516 | } |
---|
2517 | if(uiLength) |
---|
2518 | { |
---|
2519 | xReadCode( uiLength, ruiVal ); |
---|
2520 | } |
---|
2521 | else |
---|
2522 | { |
---|
2523 | ruiVal = 0; |
---|
2524 | } |
---|
2525 | ruiVal += minValue; |
---|
2526 | } |
---|
2527 | |
---|
2528 | Void TDecCavlc::parseAlfCtrlFlag( UInt &ruiAlfCtrlFlag ) |
---|
2529 | { |
---|
2530 | UInt uiSymbol; |
---|
2531 | xReadFlag( uiSymbol ); |
---|
2532 | ruiAlfCtrlFlag = uiSymbol; |
---|
2533 | } |
---|
2534 | #endif |
---|
2535 | |
---|
2536 | Void TDecCavlc::parseAlfUvlc (UInt& ruiVal) |
---|
2537 | { |
---|
2538 | xReadUvlc( ruiVal ); |
---|
2539 | } |
---|
2540 | |
---|
2541 | Void TDecCavlc::parseAlfSvlc (Int& riVal) |
---|
2542 | { |
---|
2543 | xReadSvlc( riVal ); |
---|
2544 | } |
---|
2545 | |
---|
2546 | |
---|
2547 | |
---|
2548 | #if MTK_SAO |
---|
2549 | Void TDecCavlc::parseAoFlag (UInt& ruiVal) |
---|
2550 | { |
---|
2551 | xReadFlag( ruiVal ); |
---|
2552 | } |
---|
2553 | Void TDecCavlc::parseAoUvlc (UInt& ruiVal) |
---|
2554 | { |
---|
2555 | xReadUvlc( ruiVal ); |
---|
2556 | } |
---|
2557 | |
---|
2558 | Void TDecCavlc::parseAoSvlc (Int& riVal) |
---|
2559 | { |
---|
2560 | xReadSvlc( riVal ); |
---|
2561 | } |
---|
2562 | #endif |
---|
2563 | |
---|
2564 | Void TDecCavlc::parseMergeFlag ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, UInt uiPUIdx ) |
---|
2565 | { |
---|
2566 | #if QC_LCEC_INTER_MODE |
---|
2567 | if (pcCU->getPartitionSize(uiAbsPartIdx) == SIZE_2Nx2N ) |
---|
2568 | return; |
---|
2569 | #endif |
---|
2570 | UInt uiSymbol; |
---|
2571 | xReadFlag( uiSymbol ); |
---|
2572 | pcCU->setMergeFlagSubParts( uiSymbol ? true : false, uiAbsPartIdx, uiPUIdx, uiDepth ); |
---|
2573 | } |
---|
2574 | |
---|
2575 | |
---|
2576 | Void |
---|
2577 | TDecCavlc::parseMergeIndexMV( TComDataCU* pcCU, UInt& ruiMergeIndex, UInt uiAbsPartIdx, UInt uiDepth ) |
---|
2578 | { |
---|
2579 | UInt uiNumCand = 0; |
---|
2580 | #if MW_MVI_SIGNALLING_MODE == 1 |
---|
2581 | const Bool bMVIAvailable = pcCU->getSlice()->getSPS()->getUseMVI() && pcCU->getSlice()->getSliceType() != I_SLICE; |
---|
2582 | const UInt uiMviMergePos = bMVIAvailable ? MVI_MERGE_POS : MRG_MAX_NUM_CANDS; |
---|
2583 | if( bMVIAvailable ) |
---|
2584 | uiNumCand++; |
---|
2585 | #endif |
---|
2586 | for( UInt uiIdx = 0; uiIdx < MRG_MAX_NUM_CANDS; uiIdx++ ) |
---|
2587 | { |
---|
2588 | if( pcCU->getNeighbourCandIdx( uiIdx, uiAbsPartIdx ) == uiIdx + 1 ) |
---|
2589 | { |
---|
2590 | uiNumCand++; |
---|
2591 | } |
---|
2592 | } |
---|
2593 | AOF( uiNumCand > 1 ); |
---|
2594 | UInt uiUnaryIdx = 0; |
---|
2595 | for( ; uiUnaryIdx < uiNumCand - 1; uiUnaryIdx++ ) |
---|
2596 | { |
---|
2597 | UInt uiSymbol = 0; |
---|
2598 | xReadFlag( uiSymbol ); |
---|
2599 | if( uiSymbol == 0 ) |
---|
2600 | { |
---|
2601 | break; |
---|
2602 | } |
---|
2603 | } |
---|
2604 | ruiMergeIndex = uiUnaryIdx; |
---|
2605 | for( UInt uiIdx = 0; uiIdx <= ruiMergeIndex; uiIdx++ ) |
---|
2606 | { |
---|
2607 | #if MW_MVI_SIGNALLING_MODE == 1 |
---|
2608 | if( uiIdx > uiMviMergePos ) |
---|
2609 | { |
---|
2610 | if( pcCU->getNeighbourCandIdx( uiIdx - 1, uiAbsPartIdx ) != uiIdx ) |
---|
2611 | { |
---|
2612 | ruiMergeIndex++; |
---|
2613 | } |
---|
2614 | } |
---|
2615 | else if( uiIdx < uiMviMergePos ) |
---|
2616 | #endif |
---|
2617 | if( pcCU->getNeighbourCandIdx( uiIdx, uiAbsPartIdx ) != uiIdx + 1 ) |
---|
2618 | { |
---|
2619 | ruiMergeIndex++; |
---|
2620 | } |
---|
2621 | } |
---|
2622 | #if MW_MVI_SIGNALLING_MODE == 1 |
---|
2623 | if( ruiMergeIndex > uiMviMergePos ) |
---|
2624 | { |
---|
2625 | ruiMergeIndex--; |
---|
2626 | } |
---|
2627 | else if( ruiMergeIndex == uiMviMergePos ) |
---|
2628 | { |
---|
2629 | pcCU->setTextureModeDepthSubParts( uiDepth, uiAbsPartIdx, uiDepth ); |
---|
2630 | } |
---|
2631 | #endif |
---|
2632 | } |
---|
2633 | |
---|
2634 | |
---|
2635 | /** parse merge index |
---|
2636 | * \param pcCU |
---|
2637 | * \param ruiMergeIndex |
---|
2638 | * \param uiAbsPartIdx |
---|
2639 | * \param uiDepth |
---|
2640 | * \returns Void |
---|
2641 | */ |
---|
2642 | Void TDecCavlc::parseMergeIndex ( TComDataCU* pcCU, UInt& ruiMergeIndex, UInt uiAbsPartIdx, UInt uiDepth ) |
---|
2643 | { |
---|
2644 | #if MW_MVI_SIGNALLING_MODE == 1 |
---|
2645 | if( ( pcCU->getSlice()->getSPS()->getViewId() > 0 && ( pcCU->getSlice()->getSPS()->getMultiviewMvPredMode() & PDM_USE_FOR_MERGE ) == PDM_USE_FOR_MERGE ) || |
---|
2646 | ( pcCU->getSlice()->getSPS()->getUseMVI() && pcCU->getSlice()->getSliceType() != I_SLICE && pcCU->getPartitionSize( uiAbsPartIdx ) == SIZE_2Nx2N ) ) |
---|
2647 | #else |
---|
2648 | if( pcCU->getSlice()->getSPS()->getViewId() > 0 && ( pcCU->getSlice()->getSPS()->getMultiviewMvPredMode() & PDM_USE_FOR_MERGE ) == PDM_USE_FOR_MERGE ) |
---|
2649 | #endif |
---|
2650 | { |
---|
2651 | parseMergeIndexMV( pcCU, ruiMergeIndex, uiAbsPartIdx, uiDepth ); |
---|
2652 | return; |
---|
2653 | } |
---|
2654 | |
---|
2655 | Bool bLeftInvolved = false; |
---|
2656 | Bool bAboveInvolved = false; |
---|
2657 | Bool bCollocatedInvolved = false; |
---|
2658 | Bool bCornerInvolved = false; |
---|
2659 | UInt uiNumCand = 0; |
---|
2660 | for( UInt uiIter = 0; uiIter < MRG_MAX_NUM_CANDS; ++uiIter ) |
---|
2661 | { |
---|
2662 | if( pcCU->getNeighbourCandIdx( uiIter, uiAbsPartIdx ) == uiIter + 1 ) |
---|
2663 | { |
---|
2664 | uiNumCand++; |
---|
2665 | if( uiIter == 0 ) |
---|
2666 | { |
---|
2667 | bLeftInvolved = true; |
---|
2668 | } |
---|
2669 | else if( uiIter == 1 ) |
---|
2670 | { |
---|
2671 | bAboveInvolved = true; |
---|
2672 | } |
---|
2673 | else if( uiIter == 2 ) |
---|
2674 | { |
---|
2675 | bCollocatedInvolved = true; |
---|
2676 | } |
---|
2677 | else if( uiIter == 3 ) |
---|
2678 | { |
---|
2679 | bCornerInvolved = true; |
---|
2680 | } |
---|
2681 | } |
---|
2682 | } |
---|
2683 | assert( uiNumCand > 1 ); |
---|
2684 | UInt uiUnaryIdx = 0; |
---|
2685 | for( ; uiUnaryIdx < uiNumCand - 1; ++uiUnaryIdx ) |
---|
2686 | { |
---|
2687 | UInt uiSymbol = 0; |
---|
2688 | xReadFlag( uiSymbol ); |
---|
2689 | if( uiSymbol == 0 ) |
---|
2690 | { |
---|
2691 | break; |
---|
2692 | } |
---|
2693 | } |
---|
2694 | if( !bLeftInvolved ) |
---|
2695 | { |
---|
2696 | ++uiUnaryIdx; |
---|
2697 | } |
---|
2698 | if( !bAboveInvolved && uiUnaryIdx >= 1 ) |
---|
2699 | { |
---|
2700 | ++uiUnaryIdx; |
---|
2701 | } |
---|
2702 | if( !bCollocatedInvolved && uiUnaryIdx >= 2 ) |
---|
2703 | { |
---|
2704 | ++uiUnaryIdx; |
---|
2705 | } |
---|
2706 | if( !bCornerInvolved && uiUnaryIdx >= 3 ) |
---|
2707 | { |
---|
2708 | ++uiUnaryIdx; |
---|
2709 | } |
---|
2710 | ruiMergeIndex = uiUnaryIdx; |
---|
2711 | } |
---|
2712 | |
---|
2713 | |
---|
2714 | Void |
---|
2715 | TDecCavlc::parseResPredFlag( TComDataCU* pcCU, Bool& rbResPredFlag, UInt uiAbsPartIdx, UInt uiDepth ) |
---|
2716 | { |
---|
2717 | UInt uiSymbol = 0; |
---|
2718 | xReadFlag( uiSymbol ); |
---|
2719 | rbResPredFlag = ( uiSymbol != 0 ); |
---|
2720 | } |
---|
2721 | |
---|
2722 | |
---|
2723 | // ==================================================================================================================== |
---|
2724 | // Protected member functions |
---|
2725 | // ==================================================================================================================== |
---|
2726 | |
---|
2727 | Void TDecCavlc::xReadCode (UInt uiLength, UInt& ruiCode) |
---|
2728 | { |
---|
2729 | assert ( uiLength > 0 ); |
---|
2730 | m_pcBitstream->read (uiLength, ruiCode); |
---|
2731 | } |
---|
2732 | |
---|
2733 | Void TDecCavlc::xReadUvlc( UInt& ruiVal) |
---|
2734 | { |
---|
2735 | UInt uiVal = 0; |
---|
2736 | UInt uiCode = 0; |
---|
2737 | UInt uiLength; |
---|
2738 | m_pcBitstream->read( 1, uiCode ); |
---|
2739 | |
---|
2740 | if( 0 == uiCode ) |
---|
2741 | { |
---|
2742 | uiLength = 0; |
---|
2743 | |
---|
2744 | while( ! ( uiCode & 1 )) |
---|
2745 | { |
---|
2746 | m_pcBitstream->read( 1, uiCode ); |
---|
2747 | uiLength++; |
---|
2748 | } |
---|
2749 | |
---|
2750 | m_pcBitstream->read( uiLength, uiVal ); |
---|
2751 | |
---|
2752 | uiVal += (1 << uiLength)-1; |
---|
2753 | } |
---|
2754 | |
---|
2755 | ruiVal = uiVal; |
---|
2756 | } |
---|
2757 | |
---|
2758 | Void TDecCavlc::xReadSvlc( Int& riVal) |
---|
2759 | { |
---|
2760 | UInt uiBits = 0; |
---|
2761 | m_pcBitstream->read( 1, uiBits ); |
---|
2762 | if( 0 == uiBits ) |
---|
2763 | { |
---|
2764 | UInt uiLength = 0; |
---|
2765 | |
---|
2766 | while( ! ( uiBits & 1 )) |
---|
2767 | { |
---|
2768 | m_pcBitstream->read( 1, uiBits ); |
---|
2769 | uiLength++; |
---|
2770 | } |
---|
2771 | |
---|
2772 | m_pcBitstream->read( uiLength, uiBits ); |
---|
2773 | |
---|
2774 | uiBits += (1 << uiLength); |
---|
2775 | riVal = ( uiBits & 1) ? -(Int)(uiBits>>1) : (Int)(uiBits>>1); |
---|
2776 | } |
---|
2777 | else |
---|
2778 | { |
---|
2779 | riVal = 0; |
---|
2780 | } |
---|
2781 | } |
---|
2782 | |
---|
2783 | Void TDecCavlc::xReadFlag (UInt& ruiCode) |
---|
2784 | { |
---|
2785 | m_pcBitstream->read( 1, ruiCode ); |
---|
2786 | } |
---|
2787 | |
---|
2788 | Void TDecCavlc::xReadUnaryMaxSymbol( UInt& ruiSymbol, UInt uiMaxSymbol ) |
---|
2789 | { |
---|
2790 | if (uiMaxSymbol == 0) |
---|
2791 | { |
---|
2792 | ruiSymbol = 0; |
---|
2793 | return; |
---|
2794 | } |
---|
2795 | |
---|
2796 | xReadFlag( ruiSymbol ); |
---|
2797 | |
---|
2798 | if (ruiSymbol == 0 || uiMaxSymbol == 1) |
---|
2799 | { |
---|
2800 | return; |
---|
2801 | } |
---|
2802 | |
---|
2803 | UInt uiSymbol = 0; |
---|
2804 | UInt uiCont; |
---|
2805 | |
---|
2806 | do |
---|
2807 | { |
---|
2808 | xReadFlag( uiCont ); |
---|
2809 | uiSymbol++; |
---|
2810 | } |
---|
2811 | while( uiCont && (uiSymbol < uiMaxSymbol-1) ); |
---|
2812 | |
---|
2813 | if( uiCont && (uiSymbol == uiMaxSymbol-1) ) |
---|
2814 | { |
---|
2815 | uiSymbol++; |
---|
2816 | } |
---|
2817 | |
---|
2818 | ruiSymbol = uiSymbol; |
---|
2819 | } |
---|
2820 | |
---|
2821 | Void TDecCavlc::xReadExGolombLevel( UInt& ruiSymbol ) |
---|
2822 | { |
---|
2823 | UInt uiSymbol ; |
---|
2824 | UInt uiCount = 0; |
---|
2825 | do |
---|
2826 | { |
---|
2827 | xReadFlag( uiSymbol ); |
---|
2828 | uiCount++; |
---|
2829 | } |
---|
2830 | while( uiSymbol && (uiCount != 13)); |
---|
2831 | |
---|
2832 | ruiSymbol = uiCount-1; |
---|
2833 | |
---|
2834 | if( uiSymbol ) |
---|
2835 | { |
---|
2836 | xReadEpExGolomb( uiSymbol, 0 ); |
---|
2837 | ruiSymbol += uiSymbol+1; |
---|
2838 | } |
---|
2839 | |
---|
2840 | return; |
---|
2841 | } |
---|
2842 | |
---|
2843 | Void TDecCavlc::xReadEpExGolomb( UInt& ruiSymbol, UInt uiCount ) |
---|
2844 | { |
---|
2845 | UInt uiSymbol = 0; |
---|
2846 | UInt uiBit = 1; |
---|
2847 | |
---|
2848 | |
---|
2849 | while( uiBit ) |
---|
2850 | { |
---|
2851 | xReadFlag( uiBit ); |
---|
2852 | uiSymbol += uiBit << uiCount++; |
---|
2853 | } |
---|
2854 | |
---|
2855 | uiCount--; |
---|
2856 | while( uiCount-- ) |
---|
2857 | { |
---|
2858 | xReadFlag( uiBit ); |
---|
2859 | uiSymbol += uiBit << uiCount; |
---|
2860 | } |
---|
2861 | |
---|
2862 | ruiSymbol = uiSymbol; |
---|
2863 | |
---|
2864 | return; |
---|
2865 | } |
---|
2866 | |
---|
2867 | UInt TDecCavlc::xGetBit() |
---|
2868 | { |
---|
2869 | UInt ruiCode; |
---|
2870 | m_pcBitstream->read( 1, ruiCode ); |
---|
2871 | return ruiCode; |
---|
2872 | } |
---|
2873 | |
---|
2874 | Int TDecCavlc::xReadVlc( Int n ) |
---|
2875 | { |
---|
2876 | #if CAVLC_COEF_LRG_BLK |
---|
2877 | assert( n>=0 && n<=13 ); |
---|
2878 | #else |
---|
2879 | assert( n>=0 && n<=11 ); |
---|
2880 | #endif |
---|
2881 | |
---|
2882 | UInt zeroes=0, done=0, tmp; |
---|
2883 | UInt cw, bit; |
---|
2884 | UInt val = 0; |
---|
2885 | UInt first; |
---|
2886 | UInt lead = 0; |
---|
2887 | |
---|
2888 | if (n < 5) |
---|
2889 | { |
---|
2890 | while (!done && zeroes < 6) |
---|
2891 | { |
---|
2892 | xReadFlag( bit ); |
---|
2893 | if (bit) |
---|
2894 | { |
---|
2895 | if (n) |
---|
2896 | { |
---|
2897 | xReadCode( n, cw ); |
---|
2898 | } |
---|
2899 | else |
---|
2900 | { |
---|
2901 | cw = 0; |
---|
2902 | } |
---|
2903 | done = 1; |
---|
2904 | } |
---|
2905 | else |
---|
2906 | { |
---|
2907 | zeroes++; |
---|
2908 | } |
---|
2909 | } |
---|
2910 | if ( done ) |
---|
2911 | { |
---|
2912 | val = (zeroes<<n)+cw; |
---|
2913 | } |
---|
2914 | else |
---|
2915 | { |
---|
2916 | lead = n; |
---|
2917 | while (!done) |
---|
2918 | { |
---|
2919 | xReadFlag( first ); |
---|
2920 | if ( !first ) |
---|
2921 | { |
---|
2922 | lead++; |
---|
2923 | } |
---|
2924 | else |
---|
2925 | { |
---|
2926 | if ( lead ) |
---|
2927 | { |
---|
2928 | xReadCode( lead, tmp ); |
---|
2929 | } |
---|
2930 | else |
---|
2931 | { |
---|
2932 | tmp = 0; |
---|
2933 | } |
---|
2934 | val = 6 * (1 << n) + (1 << lead) + tmp - (1 << n); |
---|
2935 | done = 1; |
---|
2936 | } |
---|
2937 | } |
---|
2938 | } |
---|
2939 | } |
---|
2940 | else if (n < 8) |
---|
2941 | { |
---|
2942 | while (!done) |
---|
2943 | { |
---|
2944 | xReadFlag( bit ); |
---|
2945 | if ( bit ) |
---|
2946 | { |
---|
2947 | xReadCode( n-4, cw ); |
---|
2948 | done = 1; |
---|
2949 | } |
---|
2950 | else |
---|
2951 | { |
---|
2952 | zeroes++; |
---|
2953 | } |
---|
2954 | } |
---|
2955 | val = (zeroes<<(n-4))+cw; |
---|
2956 | } |
---|
2957 | else if (n == 8) |
---|
2958 | { |
---|
2959 | if ( xGetBit() ) |
---|
2960 | { |
---|
2961 | val = 0; |
---|
2962 | } |
---|
2963 | else if ( xGetBit() ) |
---|
2964 | { |
---|
2965 | val = 1; |
---|
2966 | } |
---|
2967 | else |
---|
2968 | { |
---|
2969 | val = 2; |
---|
2970 | } |
---|
2971 | } |
---|
2972 | else if (n == 9) |
---|
2973 | { |
---|
2974 | if ( xGetBit() ) |
---|
2975 | { |
---|
2976 | if ( xGetBit() ) |
---|
2977 | { |
---|
2978 | xReadCode(3, val); |
---|
2979 | val += 3; |
---|
2980 | } |
---|
2981 | else if ( xGetBit() ) |
---|
2982 | { |
---|
2983 | val = xGetBit() + 1; |
---|
2984 | } |
---|
2985 | else |
---|
2986 | { |
---|
2987 | val = 0; |
---|
2988 | } |
---|
2989 | } |
---|
2990 | else |
---|
2991 | { |
---|
2992 | while (!done) |
---|
2993 | { |
---|
2994 | xReadFlag( bit ); |
---|
2995 | if ( bit ) |
---|
2996 | { |
---|
2997 | xReadCode(4, cw); |
---|
2998 | done = 1; |
---|
2999 | } |
---|
3000 | else |
---|
3001 | { |
---|
3002 | zeroes++; |
---|
3003 | } |
---|
3004 | } |
---|
3005 | val = (zeroes<<4)+cw+11; |
---|
3006 | } |
---|
3007 | } |
---|
3008 | else if (n == 10) |
---|
3009 | { |
---|
3010 | while (!done) |
---|
3011 | { |
---|
3012 | xReadFlag( first ); |
---|
3013 | if ( !first ) |
---|
3014 | { |
---|
3015 | lead++; |
---|
3016 | } |
---|
3017 | else |
---|
3018 | { |
---|
3019 | if ( !lead ) |
---|
3020 | { |
---|
3021 | val = 0; |
---|
3022 | } |
---|
3023 | else |
---|
3024 | { |
---|
3025 | xReadCode(lead, val); |
---|
3026 | val += (1<<lead); |
---|
3027 | val--; |
---|
3028 | } |
---|
3029 | done = 1; |
---|
3030 | } |
---|
3031 | } |
---|
3032 | } |
---|
3033 | else if (n == 11) |
---|
3034 | { |
---|
3035 | UInt code; |
---|
3036 | xReadCode(3, val); |
---|
3037 | if(val) |
---|
3038 | { |
---|
3039 | xReadCode(1, code); |
---|
3040 | val = (val<<1)|code; |
---|
3041 | val--; |
---|
3042 | } |
---|
3043 | } |
---|
3044 | #if CAVLC_COEF_LRG_BLK |
---|
3045 | else if (n == 12) |
---|
3046 | { |
---|
3047 | while (!done) |
---|
3048 | { |
---|
3049 | m_pcBitstream->pseudoRead(32,val); |
---|
3050 | if (val) |
---|
3051 | { |
---|
3052 | tmp = 31; |
---|
3053 | while(!done) |
---|
3054 | { |
---|
3055 | if( val>>tmp ) |
---|
3056 | { |
---|
3057 | xReadCode(32-tmp, val); |
---|
3058 | lead += 31-tmp; |
---|
3059 | xReadCode(6, val); |
---|
3060 | val += (lead<<6); |
---|
3061 | done = 1; |
---|
3062 | } |
---|
3063 | tmp--; |
---|
3064 | } |
---|
3065 | } |
---|
3066 | else |
---|
3067 | { |
---|
3068 | xReadCode(32, val); |
---|
3069 | lead += 32; |
---|
3070 | } |
---|
3071 | } |
---|
3072 | } |
---|
3073 | else if (n == 13) |
---|
3074 | { |
---|
3075 | while (!done) |
---|
3076 | { |
---|
3077 | m_pcBitstream->pseudoRead(32,val); |
---|
3078 | if (val) |
---|
3079 | { |
---|
3080 | tmp = 31; |
---|
3081 | while(!done) |
---|
3082 | { |
---|
3083 | if(val>>tmp) |
---|
3084 | { |
---|
3085 | xReadCode(32-tmp, cw); |
---|
3086 | zeroes += 31-tmp; |
---|
3087 | xReadCode(4, cw); |
---|
3088 | done = 1; |
---|
3089 | } |
---|
3090 | tmp--; |
---|
3091 | } |
---|
3092 | } |
---|
3093 | else |
---|
3094 | { |
---|
3095 | xReadCode(32, val); |
---|
3096 | zeroes += 32; |
---|
3097 | } |
---|
3098 | } |
---|
3099 | val = (zeroes<<4)+cw; |
---|
3100 | } |
---|
3101 | #endif |
---|
3102 | |
---|
3103 | return val; |
---|
3104 | } |
---|
3105 | |
---|
3106 | #if !CAVLC_COEF_LRG_BLK |
---|
3107 | Void TDecCavlc::xParseCoeff4x4( TCoeff* scoeff, Int n ) |
---|
3108 | { |
---|
3109 | Int i; |
---|
3110 | UInt sign; |
---|
3111 | Int tmp; |
---|
3112 | Int vlc,cn,this_pos; |
---|
3113 | Int maxrun; |
---|
3114 | Int last_position; |
---|
3115 | Int atable[5] = {4,6,14,28,0xfffffff}; |
---|
3116 | Int vlc_adaptive=0; |
---|
3117 | Int done; |
---|
3118 | LastCoeffStruct combo; |
---|
3119 | |
---|
3120 | #if QC_MOD_LCEC |
---|
3121 | Int nTab; |
---|
3122 | Int tr1; |
---|
3123 | nTab=max(0,n-2); |
---|
3124 | #endif |
---|
3125 | |
---|
3126 | for (i = 0; i < 16; i++) |
---|
3127 | { |
---|
3128 | scoeff[i] = 0; |
---|
3129 | } |
---|
3130 | |
---|
3131 | { |
---|
3132 | /* Get the last nonzero coeff */ |
---|
3133 | Int x,y,cx,cy,vlcNum; |
---|
3134 | Int vlcTable[8] = {2,2,2}; |
---|
3135 | |
---|
3136 | /* Decode according to current LP table */ |
---|
3137 | #if QC_MOD_LCEC |
---|
3138 | vlcNum = vlcTable[nTab]; |
---|
3139 | tmp = xReadVlc( vlcNum ); |
---|
3140 | cn = m_uiLPTableD4[nTab][tmp]; |
---|
3141 | #else |
---|
3142 | vlcNum = vlcTable[n]; |
---|
3143 | |
---|
3144 | tmp = xReadVlc( vlcNum ); |
---|
3145 | cn = m_uiLPTableD4[n][tmp]; |
---|
3146 | #endif |
---|
3147 | combo.level = (cn>15); |
---|
3148 | combo.last_pos = cn&0x0f; |
---|
3149 | |
---|
3150 | /* Adapt LP table */ |
---|
3151 | cx = tmp; |
---|
3152 | cy = Max( 0, cx-1 ); |
---|
3153 | x = cn; |
---|
3154 | #if QC_MOD_LCEC |
---|
3155 | y = m_uiLPTableD4[nTab][cy]; |
---|
3156 | m_uiLPTableD4[nTab][cy] = x; |
---|
3157 | m_uiLPTableD4[nTab][cx] = y; |
---|
3158 | #else |
---|
3159 | y = m_uiLPTableD4[n][cy]; |
---|
3160 | m_uiLPTableD4[n][cy] = x; |
---|
3161 | m_uiLPTableD4[n][cx] = y; |
---|
3162 | #endif |
---|
3163 | } |
---|
3164 | |
---|
3165 | if ( combo.level == 1 ) |
---|
3166 | { |
---|
3167 | tmp = xReadVlc( 0 ); |
---|
3168 | sign = tmp&1; |
---|
3169 | tmp = (tmp>>1)+2; |
---|
3170 | } |
---|
3171 | else |
---|
3172 | { |
---|
3173 | tmp = 1; |
---|
3174 | xReadFlag( sign ); |
---|
3175 | } |
---|
3176 | |
---|
3177 | #if QC_MOD_LCEC |
---|
3178 | if (tmp>1) |
---|
3179 | { |
---|
3180 | tr1=0; |
---|
3181 | } |
---|
3182 | else |
---|
3183 | { |
---|
3184 | tr1=1; |
---|
3185 | } |
---|
3186 | #endif |
---|
3187 | |
---|
3188 | if ( sign ) |
---|
3189 | { |
---|
3190 | tmp = -tmp; |
---|
3191 | } |
---|
3192 | |
---|
3193 | last_position = combo.last_pos; |
---|
3194 | this_pos = 15 - last_position; |
---|
3195 | scoeff[this_pos] = tmp; |
---|
3196 | i = this_pos; |
---|
3197 | i++; |
---|
3198 | |
---|
3199 | done = 0; |
---|
3200 | { |
---|
3201 | while (!done && i < 16) |
---|
3202 | { |
---|
3203 | maxrun = 15-i; |
---|
3204 | #if QC_MOD_LCEC |
---|
3205 | if(n==2) |
---|
3206 | vlc = g_auiVlcTable8x8Intra[maxrun]; |
---|
3207 | else |
---|
3208 | vlc = g_auiVlcTable8x8Inter[maxrun]; |
---|
3209 | #else |
---|
3210 | if (maxrun > 27) |
---|
3211 | { |
---|
3212 | maxrun = 28; |
---|
3213 | vlc = 3; |
---|
3214 | } |
---|
3215 | else |
---|
3216 | { |
---|
3217 | vlc = g_auiVlcTable8x8[maxrun]; |
---|
3218 | } |
---|
3219 | #endif |
---|
3220 | |
---|
3221 | /* Go into run mode */ |
---|
3222 | cn = xReadVlc( vlc ); |
---|
3223 | #if QC_MOD_LCEC |
---|
3224 | if(n==2) |
---|
3225 | { |
---|
3226 | xRunLevelIndInv(&combo, maxrun, g_auiLumaRunTr14x4[tr1][maxrun], cn); |
---|
3227 | } |
---|
3228 | else |
---|
3229 | #endif |
---|
3230 | { |
---|
3231 | #if RUNLEVEL_TABLE_CUT |
---|
3232 | xRunLevelIndInterInv(&combo, maxrun, cn); |
---|
3233 | #else |
---|
3234 | combo = g_acstructLumaRun8x8[maxrun][cn]; |
---|
3235 | #endif |
---|
3236 | } |
---|
3237 | i += combo.last_pos; |
---|
3238 | /* No sign for last zeroes */ |
---|
3239 | if (i < 16) |
---|
3240 | { |
---|
3241 | if (combo.level == 1) |
---|
3242 | { |
---|
3243 | tmp = xReadVlc( 0 ); |
---|
3244 | sign = tmp&1; |
---|
3245 | tmp = (tmp>>1)+2; |
---|
3246 | done = 1; |
---|
3247 | } |
---|
3248 | else |
---|
3249 | { |
---|
3250 | tmp = 1; |
---|
3251 | xReadFlag( sign ); |
---|
3252 | } |
---|
3253 | if ( sign ) |
---|
3254 | { |
---|
3255 | tmp = -tmp; |
---|
3256 | } |
---|
3257 | scoeff[i] = tmp; |
---|
3258 | } |
---|
3259 | i++; |
---|
3260 | #if QC_MOD_LCEC |
---|
3261 | if (tr1>0 && tr1<MAX_TR1) |
---|
3262 | { |
---|
3263 | tr1++; |
---|
3264 | } |
---|
3265 | #endif |
---|
3266 | } |
---|
3267 | } |
---|
3268 | if (i < 16) |
---|
3269 | { |
---|
3270 | /* Get the rest in level mode */ |
---|
3271 | while ( i < 16 ) |
---|
3272 | { |
---|
3273 | tmp = xReadVlc( vlc_adaptive ); |
---|
3274 | if ( tmp > atable[vlc_adaptive] ) |
---|
3275 | { |
---|
3276 | vlc_adaptive++; |
---|
3277 | } |
---|
3278 | if ( tmp ) |
---|
3279 | { |
---|
3280 | xReadFlag( sign ); |
---|
3281 | if ( sign ) |
---|
3282 | { |
---|
3283 | tmp = -tmp; |
---|
3284 | } |
---|
3285 | } |
---|
3286 | scoeff[i] = tmp; |
---|
3287 | i++; |
---|
3288 | } |
---|
3289 | } |
---|
3290 | |
---|
3291 | return; |
---|
3292 | } |
---|
3293 | #endif |
---|
3294 | |
---|
3295 | #if QC_MOD_LCEC |
---|
3296 | |
---|
3297 | Void TDecCavlc::xRunLevelIndInv(LastCoeffStruct *combo, Int maxrun, UInt lrg1Pos, UInt cn) |
---|
3298 | { |
---|
3299 | int lev, run; |
---|
3300 | if (lrg1Pos>0) |
---|
3301 | { |
---|
3302 | if(cn < min(lrg1Pos, maxrun+2)) |
---|
3303 | { |
---|
3304 | lev = 0; |
---|
3305 | run = cn; |
---|
3306 | } |
---|
3307 | else if(cn < (maxrun<<1) + 4 - (Int)lrg1Pos) |
---|
3308 | { |
---|
3309 | if((cn+lrg1Pos)&1) |
---|
3310 | { |
---|
3311 | lev = 0; |
---|
3312 | run = (cn + lrg1Pos - 1) >> 1; |
---|
3313 | } |
---|
3314 | else |
---|
3315 | { |
---|
3316 | lev = 1; |
---|
3317 | run = (cn - lrg1Pos)>>1; |
---|
3318 | } |
---|
3319 | } |
---|
3320 | else |
---|
3321 | { |
---|
3322 | lev = 1; |
---|
3323 | run = cn - maxrun - 2; |
---|
3324 | } |
---|
3325 | } |
---|
3326 | else |
---|
3327 | { |
---|
3328 | if( cn & 1 ) |
---|
3329 | { |
---|
3330 | lev = 0; run = (cn-1)>>1; |
---|
3331 | } |
---|
3332 | else |
---|
3333 | { |
---|
3334 | run = cn >> 1; |
---|
3335 | lev = (run <= maxrun)?1:0; |
---|
3336 | } |
---|
3337 | } |
---|
3338 | combo->level = lev; |
---|
3339 | combo->last_pos = run; |
---|
3340 | } |
---|
3341 | |
---|
3342 | #if RUNLEVEL_TABLE_CUT |
---|
3343 | /** Function for deriving run and level value in CAVLC run-level coding |
---|
3344 | * \param combo pointer to a struct of run and level |
---|
3345 | * \param maxrun maximum length of run for a given coefficient location |
---|
3346 | * \param cn codeword index |
---|
3347 | * \returns |
---|
3348 | * This function derives run and level value in CAVLC run-level coding based on codeword index and maximum run value. |
---|
3349 | */ |
---|
3350 | Void TDecCavlc::xRunLevelIndInterInv(LastCoeffStruct *combo, Int maxrun, UInt cn) |
---|
3351 | { |
---|
3352 | if (maxrun<28) |
---|
3353 | { |
---|
3354 | if(cn > maxrun+1) |
---|
3355 | { |
---|
3356 | combo->level = 1; |
---|
3357 | combo->last_pos = g_acstructLumaRun8x8[maxrun][cn-maxrun-1]; |
---|
3358 | } |
---|
3359 | else |
---|
3360 | { |
---|
3361 | combo->level = 0; |
---|
3362 | combo->last_pos = g_acstructLumaRun8x8[maxrun][cn]; |
---|
3363 | } |
---|
3364 | } |
---|
3365 | else |
---|
3366 | { |
---|
3367 | if(cn<maxrun+2) |
---|
3368 | { |
---|
3369 | combo->level = 0; |
---|
3370 | combo->last_pos = cn; |
---|
3371 | } |
---|
3372 | else |
---|
3373 | { |
---|
3374 | combo->level = 1; |
---|
3375 | combo->last_pos = cn-maxrun-2; |
---|
3376 | } |
---|
3377 | } |
---|
3378 | } |
---|
3379 | #endif |
---|
3380 | #endif |
---|
3381 | |
---|
3382 | |
---|
3383 | #if !CAVLC_COEF_LRG_BLK |
---|
3384 | Void TDecCavlc::xParseCoeff8x8(TCoeff* scoeff, int n) |
---|
3385 | { |
---|
3386 | Int i; |
---|
3387 | UInt sign; |
---|
3388 | Int tmp; |
---|
3389 | LastCoeffStruct combo; |
---|
3390 | Int vlc,cn,this_pos; |
---|
3391 | Int maxrun; |
---|
3392 | Int last_position; |
---|
3393 | Int atable[5] = {4,6,14,28,0xfffffff}; |
---|
3394 | Int vlc_adaptive=0; |
---|
3395 | Int done; |
---|
3396 | #if QC_MOD_LCEC |
---|
3397 | Int tr1; |
---|
3398 | #endif |
---|
3399 | |
---|
3400 | static const Int switch_thr[10] = {49,49,0,49,49,0,49,49,49,49}; |
---|
3401 | Int sum_big_coef = 0; |
---|
3402 | |
---|
3403 | for (i = 0; i < 64; i++) |
---|
3404 | { |
---|
3405 | scoeff[i] = 0; |
---|
3406 | } |
---|
3407 | |
---|
3408 | /* Get the last nonzero coeff */ |
---|
3409 | { |
---|
3410 | Int x,y,cx,cy,vlcNum; |
---|
3411 | |
---|
3412 | /* Decode according to current LP table */ |
---|
3413 | // ADAPT_VLC_NUM |
---|
3414 | vlcNum = g_auiLastPosVlcNum[n][Min(16,m_uiLastPosVlcIndex[n])]; |
---|
3415 | tmp = xReadVlc( vlcNum ); |
---|
3416 | cn = m_uiLPTableD8[n][tmp]; |
---|
3417 | combo.level = (cn>63); |
---|
3418 | combo.last_pos = cn&0x3f; |
---|
3419 | |
---|
3420 | /* Adapt LP table */ |
---|
3421 | cx = tmp; |
---|
3422 | cy = Max(0,cx-1); |
---|
3423 | x = cn; |
---|
3424 | y = m_uiLPTableD8[n][cy]; |
---|
3425 | m_uiLPTableD8[n][cy] = x; |
---|
3426 | m_uiLPTableD8[n][cx] = y; |
---|
3427 | |
---|
3428 | // ADAPT_VLC_NUM |
---|
3429 | m_uiLastPosVlcIndex[n] += cx == m_uiLastPosVlcIndex[n] ? 0 : (cx < m_uiLastPosVlcIndex[n] ? -1 : 1); |
---|
3430 | } |
---|
3431 | |
---|
3432 | if (combo.level == 1) |
---|
3433 | { |
---|
3434 | tmp = xReadVlc( 0 ); |
---|
3435 | sign = tmp&1; |
---|
3436 | tmp = (tmp>>1)+2; |
---|
3437 | } |
---|
3438 | else |
---|
3439 | { |
---|
3440 | tmp = 1; |
---|
3441 | xReadFlag( sign ); |
---|
3442 | } |
---|
3443 | |
---|
3444 | #if QC_MOD_LCEC |
---|
3445 | if (tmp>1) |
---|
3446 | { |
---|
3447 | tr1=0; |
---|
3448 | } |
---|
3449 | else |
---|
3450 | { |
---|
3451 | tr1=1; |
---|
3452 | } |
---|
3453 | #endif |
---|
3454 | |
---|
3455 | if ( sign ) |
---|
3456 | { |
---|
3457 | tmp = -tmp; |
---|
3458 | } |
---|
3459 | |
---|
3460 | last_position = combo.last_pos; |
---|
3461 | this_pos = 63 - last_position; |
---|
3462 | scoeff[this_pos] = tmp; |
---|
3463 | i = this_pos; |
---|
3464 | i++; |
---|
3465 | |
---|
3466 | done = 0; |
---|
3467 | { |
---|
3468 | while (!done && i < 64) |
---|
3469 | { |
---|
3470 | maxrun = 63-i; |
---|
3471 | #if QC_MOD_LCEC |
---|
3472 | if (n == 2 || n == 5) |
---|
3473 | vlc = g_auiVlcTable8x8Intra[Min(maxrun,28)]; |
---|
3474 | else |
---|
3475 | vlc = g_auiVlcTable8x8Inter[Min(maxrun,28)]; |
---|
3476 | #else |
---|
3477 | if (maxrun > 27) |
---|
3478 | { |
---|
3479 | maxrun = 28; |
---|
3480 | vlc = 3; |
---|
3481 | } |
---|
3482 | else |
---|
3483 | { |
---|
3484 | vlc = g_auiVlcTable8x8[maxrun]; |
---|
3485 | } |
---|
3486 | #endif |
---|
3487 | |
---|
3488 | /* Go into run mode */ |
---|
3489 | cn = xReadVlc( vlc ); |
---|
3490 | #if QC_MOD_LCEC |
---|
3491 | if (n == 2 || n == 5) |
---|
3492 | xRunLevelIndInv(&combo, maxrun, g_auiLumaRunTr18x8[tr1][min(maxrun,28)], cn); |
---|
3493 | else |
---|
3494 | #if RUNLEVEL_TABLE_CUT |
---|
3495 | xRunLevelIndInterInv(&combo, maxrun, cn); |
---|
3496 | #else |
---|
3497 | combo = g_acstructLumaRun8x8[Min(maxrun,28)][cn]; |
---|
3498 | #endif |
---|
3499 | #else |
---|
3500 | combo = g_acstructLumaRun8x8[maxrun][cn]; |
---|
3501 | #endif |
---|
3502 | i += combo.last_pos; |
---|
3503 | /* No sign for last zeroes */ |
---|
3504 | if (i < 64) |
---|
3505 | { |
---|
3506 | if (combo.level == 1) |
---|
3507 | { |
---|
3508 | tmp = xReadVlc( 0 ); |
---|
3509 | sign = tmp&1; |
---|
3510 | tmp = (tmp>>1)+2; |
---|
3511 | |
---|
3512 | sum_big_coef += tmp; |
---|
3513 | if (i > switch_thr[n] || sum_big_coef > 2) |
---|
3514 | { |
---|
3515 | done = 1; |
---|
3516 | } |
---|
3517 | } |
---|
3518 | else |
---|
3519 | { |
---|
3520 | tmp = 1; |
---|
3521 | xReadFlag( sign ); |
---|
3522 | } |
---|
3523 | if ( sign ) |
---|
3524 | { |
---|
3525 | tmp = -tmp; |
---|
3526 | } |
---|
3527 | scoeff[i] = tmp; |
---|
3528 | } |
---|
3529 | i++; |
---|
3530 | #if QC_MOD_LCEC |
---|
3531 | if (tr1==0 || combo.level != 0) |
---|
3532 | { |
---|
3533 | tr1=0; |
---|
3534 | } |
---|
3535 | else if( tr1 < MAX_TR1) |
---|
3536 | { |
---|
3537 | tr1++; |
---|
3538 | } |
---|
3539 | #endif |
---|
3540 | } |
---|
3541 | } |
---|
3542 | if (i < 64) |
---|
3543 | { |
---|
3544 | /* Get the rest in level mode */ |
---|
3545 | while (i<64) |
---|
3546 | { |
---|
3547 | tmp = xReadVlc( vlc_adaptive ); |
---|
3548 | |
---|
3549 | if (tmp>atable[vlc_adaptive]) |
---|
3550 | { |
---|
3551 | vlc_adaptive++; |
---|
3552 | } |
---|
3553 | if (tmp) |
---|
3554 | { |
---|
3555 | xReadFlag( sign ); |
---|
3556 | if ( sign ) |
---|
3557 | { |
---|
3558 | tmp = -tmp; |
---|
3559 | } |
---|
3560 | } |
---|
3561 | scoeff[i] = tmp; |
---|
3562 | i++; |
---|
3563 | } |
---|
3564 | } |
---|
3565 | return; |
---|
3566 | } |
---|
3567 | #endif |
---|
3568 | |
---|
3569 | |
---|
3570 | #if CAVLC_COEF_LRG_BLK |
---|
3571 | /** Function for parsing a block of transform coeffcients in CAVLC. |
---|
3572 | * \param scoeff pointer to transform coefficient buffer |
---|
3573 | * \param n block type information, e.g. luma, chroma, intra, inter, etc. |
---|
3574 | * \param blSize block size |
---|
3575 | * \returns |
---|
3576 | * This function performs parsing for a block of transform coefficient in CAVLC. |
---|
3577 | */ |
---|
3578 | Void TDecCavlc::xParseCoeff(TCoeff* scoeff, int n, Int blSize) |
---|
3579 | { |
---|
3580 | static const Int switch_thr[10] = {49,49,0,49,49,0,49,49,49,49}; |
---|
3581 | Int i, noCoeff=blSize*blSize;; |
---|
3582 | UInt sign; |
---|
3583 | LastCoeffStruct combo; |
---|
3584 | Int cn, maxrun, tmprun; |
---|
3585 | Int atable[5] = {4,6,14,28,0xfffffff}; |
---|
3586 | Int done, tr1, tmp; |
---|
3587 | Int sum_big_coef = 0; |
---|
3588 | |
---|
3589 | memset(scoeff,0,sizeof(TCoeff)*noCoeff); |
---|
3590 | |
---|
3591 | /* Get the last nonzero coeff */ |
---|
3592 | if(blSize >=8 ) |
---|
3593 | { |
---|
3594 | /* Decode according to current LP table */ |
---|
3595 | // ADAPT_VLC_NUM |
---|
3596 | tmp = g_auiLastPosVlcNum[n][Min(16,m_uiLastPosVlcIndex[n])]; |
---|
3597 | cn = xReadVlc( tmp ); |
---|
3598 | xLastLevelIndInv(combo.level, combo.last_pos, blSize, cn); |
---|
3599 | |
---|
3600 | /* Adapt LP table */ |
---|
3601 | cn = (blSize==8)?cn:(cn>>2); |
---|
3602 | // ADAPT_VLC_NUM |
---|
3603 | m_uiLastPosVlcIndex[n] += cn == m_uiLastPosVlcIndex[n] ? 0 : (cn < m_uiLastPosVlcIndex[n] ? -1 : 1); |
---|
3604 | } |
---|
3605 | else |
---|
3606 | { |
---|
3607 | /* Get the last nonzero coeff */ |
---|
3608 | Int y,cy; |
---|
3609 | Int nTab = max(0,n-2); |
---|
3610 | |
---|
3611 | /* Decode according to current LP table */ |
---|
3612 | tmp = xReadVlc( 2 ); |
---|
3613 | cn = m_uiLPTableD4[nTab][tmp]; |
---|
3614 | combo.level = (cn>15)?1:0; |
---|
3615 | combo.last_pos = cn&0x0f; |
---|
3616 | |
---|
3617 | /* Adapt LP table */ |
---|
3618 | cy = Max( 0, tmp-1 ); |
---|
3619 | y = m_uiLPTableD4[nTab][cy]; |
---|
3620 | m_uiLPTableD4[nTab][cy] = cn; |
---|
3621 | m_uiLPTableD4[nTab][tmp] = y; |
---|
3622 | } |
---|
3623 | |
---|
3624 | if (combo.level == 1) |
---|
3625 | { |
---|
3626 | tmp = xReadVlc( 0 ); |
---|
3627 | sign = tmp&1; |
---|
3628 | tmp = (tmp>>1)+2; |
---|
3629 | tr1=0; |
---|
3630 | } |
---|
3631 | else |
---|
3632 | { |
---|
3633 | tmp = 1; |
---|
3634 | xReadFlag( sign ); |
---|
3635 | tr1=1; |
---|
3636 | } |
---|
3637 | |
---|
3638 | i = noCoeff - 1 - combo.last_pos; |
---|
3639 | scoeff[i++] = sign? -tmp:tmp; |
---|
3640 | |
---|
3641 | done = 0; |
---|
3642 | const UInt *vlcTable = (n == 2||n == 5)? ((blSize<=8)? g_auiVlcTable8x8Intra:g_auiVlcTable16x16Intra): |
---|
3643 | ((blSize<=8)? g_auiVlcTable8x8Inter:g_auiVlcTable16x16Inter); |
---|
3644 | const UInt **pLumaRunTr1 = (blSize==4)? g_pLumaRunTr14x4:g_pLumaRunTr18x8; |
---|
3645 | while (!done && i < noCoeff) |
---|
3646 | { |
---|
3647 | maxrun = noCoeff - 1 -i; |
---|
3648 | tmprun = min(maxrun,28); |
---|
3649 | tmp = vlcTable[tmprun]; |
---|
3650 | |
---|
3651 | /* Go into run mode */ |
---|
3652 | cn = xReadVlc( tmp ); |
---|
3653 | if (n == 2 || n == 5) |
---|
3654 | { |
---|
3655 | xRunLevelIndInv(&combo, maxrun, pLumaRunTr1[tr1][tmprun], cn); |
---|
3656 | } |
---|
3657 | else |
---|
3658 | { |
---|
3659 | xRunLevelIndInterInv(&combo, maxrun, cn); |
---|
3660 | } |
---|
3661 | |
---|
3662 | i += combo.last_pos; |
---|
3663 | if (i < noCoeff) |
---|
3664 | { |
---|
3665 | if (combo.level == 1) |
---|
3666 | { |
---|
3667 | tmp = xReadVlc( 0 ); |
---|
3668 | sign = tmp&1; |
---|
3669 | tmp = (tmp>>1)+2; |
---|
3670 | |
---|
3671 | sum_big_coef += tmp; |
---|
3672 | if (blSize==4 ||i > switch_thr[n] || sum_big_coef > 2) |
---|
3673 | { |
---|
3674 | done = 1; |
---|
3675 | } |
---|
3676 | } |
---|
3677 | else |
---|
3678 | { |
---|
3679 | tmp = 1; |
---|
3680 | xReadFlag( sign ); |
---|
3681 | } |
---|
3682 | scoeff[i++] = sign? -tmp:tmp; |
---|
3683 | } |
---|
3684 | |
---|
3685 | if (tr1==0 || combo.level != 0) |
---|
3686 | { |
---|
3687 | tr1=0; |
---|
3688 | } |
---|
3689 | else if( tr1 < MAX_TR1) |
---|
3690 | { |
---|
3691 | tr1++; |
---|
3692 | } |
---|
3693 | } |
---|
3694 | |
---|
3695 | if (i < noCoeff) |
---|
3696 | { |
---|
3697 | /* Get the rest in level mode */ |
---|
3698 | Int vlc_adaptive = 0; |
---|
3699 | while (i < noCoeff) |
---|
3700 | { |
---|
3701 | tmp = xReadVlc( vlc_adaptive ); |
---|
3702 | |
---|
3703 | if (tmp) |
---|
3704 | { |
---|
3705 | xReadFlag( sign ); |
---|
3706 | scoeff[i] = sign?-tmp:tmp; |
---|
3707 | if (tmp > atable[vlc_adaptive]) |
---|
3708 | { |
---|
3709 | vlc_adaptive++; |
---|
3710 | } |
---|
3711 | } |
---|
3712 | i++; |
---|
3713 | } |
---|
3714 | } |
---|
3715 | |
---|
3716 | return; |
---|
3717 | } |
---|
3718 | |
---|
3719 | #endif |
---|
3720 | |
---|
3721 | #ifdef WEIGHT_PRED |
---|
3722 | Void TDecCavlc::parseWeightPredTable( TComSlice* pcSlice ) |
---|
3723 | { |
---|
3724 | wpScalingParam *wp; |
---|
3725 | Bool bChroma = true; // color always present in HEVC ? |
---|
3726 | TComPPS* pps = pcSlice->getPPS(); |
---|
3727 | SliceType eSliceType = pcSlice->getSliceType(); |
---|
3728 | Int nbRef = (eSliceType == B_SLICE ) ? (2) : (1); |
---|
3729 | UInt uiLog2WeightDenomLuma, uiLog2WeightDenomChroma; |
---|
3730 | UInt uiMode = 0; |
---|
3731 | |
---|
3732 | if ( (eSliceType==P_SLICE && pps->getUseWP()) || (eSliceType==B_SLICE && pps->getWPBiPredIdc()==1) ) |
---|
3733 | uiMode = 1; |
---|
3734 | else if ( eSliceType==B_SLICE && pps->getWPBiPredIdc()==2 ) |
---|
3735 | uiMode = 2; |
---|
3736 | |
---|
3737 | if ( uiMode == 1 ) // explicit |
---|
3738 | { |
---|
3739 | printf("\nTDecCavlc::parseWeightPredTable(poc=%d) explicit...\n", pcSlice->getPOC()); |
---|
3740 | |
---|
3741 | // decode luma_log2_weight_denom : |
---|
3742 | xReadUvlc( uiLog2WeightDenomLuma ); // ue(v): luma_log2_weight_denom |
---|
3743 | if( bChroma ) { // color always present in HEVC ? |
---|
3744 | xReadUvlc( uiLog2WeightDenomChroma ); // ue(v): chroma_log2_weight_denom |
---|
3745 | } |
---|
3746 | |
---|
3747 | for ( Int numRef=0 ; numRef<nbRef ; numRef++ ) { |
---|
3748 | RefPicList eRefPicList = ( numRef ? REF_PIC_LIST_1 : REF_PIC_LIST_0 ); |
---|
3749 | for ( Int iRefIdx=0 ; iRefIdx<pcSlice->getNumRefIdx(eRefPicList) ; iRefIdx++ ) { |
---|
3750 | pcSlice->getWpScaling(eRefPicList, iRefIdx, wp); |
---|
3751 | |
---|
3752 | wp[0].uiLog2WeightDenom = uiLog2WeightDenomLuma; |
---|
3753 | wp[1].uiLog2WeightDenom = uiLog2WeightDenomChroma; |
---|
3754 | wp[2].uiLog2WeightDenom = uiLog2WeightDenomChroma; |
---|
3755 | |
---|
3756 | UInt uiCode; |
---|
3757 | xReadFlag( uiCode ); // u(1): luma_weight_l0_flag |
---|
3758 | wp[0].bPresentFlag = ( uiCode == 1 ); |
---|
3759 | if ( wp[0].bPresentFlag ) { |
---|
3760 | xReadSvlc( wp[0].iWeight ); // se(v): luma_weight_l0[i] |
---|
3761 | xReadSvlc( wp[0].iOffset ); // se(v): luma_offset_l0[i] |
---|
3762 | } |
---|
3763 | else { |
---|
3764 | wp[0].iWeight = (1 << wp[0].uiLog2WeightDenom); |
---|
3765 | wp[0].iOffset = 0; |
---|
3766 | } |
---|
3767 | if ( bChroma ) { |
---|
3768 | xReadFlag( uiCode ); // u(1): chroma_weight_l0_flag |
---|
3769 | wp[1].bPresentFlag = ( uiCode == 1 ); |
---|
3770 | wp[2].bPresentFlag = ( uiCode == 1 ); |
---|
3771 | if ( wp[1].bPresentFlag ) { |
---|
3772 | for ( Int j=1 ; j<3 ; j++ ) { |
---|
3773 | xReadSvlc( wp[j].iWeight ); // se(v): chroma_weight_l0[i][j] |
---|
3774 | xReadSvlc( wp[j].iOffset ); // se(v): chroma_offset_l0[i][j] |
---|
3775 | } |
---|
3776 | } |
---|
3777 | else { |
---|
3778 | for ( Int j=1 ; j<3 ; j++ ) { |
---|
3779 | wp[j].iWeight = (1 << wp[j].uiLog2WeightDenom); |
---|
3780 | wp[j].iOffset = 0; |
---|
3781 | } |
---|
3782 | } |
---|
3783 | } |
---|
3784 | } |
---|
3785 | |
---|
3786 | // Just for displayWpScaling(): |
---|
3787 | for ( Int iRefIdx=pcSlice->getNumRefIdx(eRefPicList) ; iRefIdx<MAX_NUM_REF ; iRefIdx++ ) { |
---|
3788 | pcSlice->getWpScaling(eRefPicList, iRefIdx, wp); |
---|
3789 | |
---|
3790 | wp[0].bPresentFlag = false; |
---|
3791 | wp[1].bPresentFlag = false; |
---|
3792 | wp[2].bPresentFlag = false; |
---|
3793 | } |
---|
3794 | |
---|
3795 | } |
---|
3796 | |
---|
3797 | } |
---|
3798 | else if ( uiMode == 2 ) // implicit |
---|
3799 | { |
---|
3800 | printf("\nTDecCavlc::parseWeightPredTable(poc=%d) implicit...\n", pcSlice->getPOC()); |
---|
3801 | } |
---|
3802 | else |
---|
3803 | assert(0); |
---|
3804 | } |
---|
3805 | #endif |
---|