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