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