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