1 | /* ==================================================================================================================== |
---|
2 | |
---|
3 | The copyright in this software is being made available under the License included below. |
---|
4 | This software may be subject to other third party and contributor rights, including patent rights, and no such |
---|
5 | rights are granted under this license. |
---|
6 | |
---|
7 | Copyright (c) 2010, SAMSUNG ELECTRONICS CO., LTD. and BRITISH BROADCASTING CORPORATION |
---|
8 | All rights reserved. |
---|
9 | |
---|
10 | Redistribution and use in source and binary forms, with or without modification, are permitted only for |
---|
11 | the purpose of developing standards within the Joint Collaborative Team on Video Coding and for testing and |
---|
12 | promoting such standards. The following conditions are required to be met: |
---|
13 | |
---|
14 | * Redistributions of source code must retain the above copyright notice, this list of conditions and |
---|
15 | the following disclaimer. |
---|
16 | * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and |
---|
17 | the following disclaimer in the documentation and/or other materials provided with the distribution. |
---|
18 | * Neither the name of SAMSUNG ELECTRONICS CO., LTD. nor the name of the BRITISH BROADCASTING CORPORATION |
---|
19 | may be used to endorse or promote products derived from this software without specific prior written permission. |
---|
20 | |
---|
21 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, |
---|
22 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
---|
23 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, |
---|
24 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
---|
25 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
---|
26 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
---|
27 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
---|
28 | |
---|
29 | * ==================================================================================================================== |
---|
30 | */ |
---|
31 | |
---|
32 | /** \file TDecCAVLC.cpp |
---|
33 | \brief CAVLC decoder class |
---|
34 | */ |
---|
35 | |
---|
36 | #include "TDecCAVLC.h" |
---|
37 | |
---|
38 | // ==================================================================================================================== |
---|
39 | // Constructor / destructor / create / destroy |
---|
40 | // ==================================================================================================================== |
---|
41 | |
---|
42 | TDecCavlc::TDecCavlc() |
---|
43 | { |
---|
44 | m_bAlfCtrl = false; |
---|
45 | m_uiMaxAlfCtrlDepth = 0; |
---|
46 | } |
---|
47 | |
---|
48 | TDecCavlc::~TDecCavlc() |
---|
49 | { |
---|
50 | |
---|
51 | } |
---|
52 | |
---|
53 | // ==================================================================================================================== |
---|
54 | // Public member functions |
---|
55 | // ==================================================================================================================== |
---|
56 | |
---|
57 | Void TDecCavlc::parsePPS(TComPPS* pcPPS) |
---|
58 | { |
---|
59 | UInt uiCode; |
---|
60 | |
---|
61 | xReadCode ( 2, uiCode ); //NalRefIdc |
---|
62 | xReadCode ( 1, uiCode ); assert( 0 == uiCode); // zero bit |
---|
63 | xReadCode ( 5, uiCode ); assert( NAL_UNIT_PPS == uiCode);//NalUnitType |
---|
64 | return; |
---|
65 | } |
---|
66 | |
---|
67 | Void TDecCavlc::parseSPS(TComSPS* pcSPS) |
---|
68 | { |
---|
69 | UInt uiCode; |
---|
70 | xReadCode ( 2, uiCode ); //NalRefIdc |
---|
71 | xReadCode ( 1, uiCode ); assert( 0 == uiCode); // zero bit |
---|
72 | xReadCode ( 5, uiCode ); assert( NAL_UNIT_SPS == uiCode);//NalUnitType |
---|
73 | |
---|
74 | // Structure |
---|
75 | xReadUvlc ( uiCode ); pcSPS->setWidth ( uiCode ); |
---|
76 | xReadUvlc ( uiCode ); pcSPS->setHeight ( uiCode ); |
---|
77 | xReadUvlc ( uiCode ); pcSPS->setPadX ( uiCode ); |
---|
78 | xReadUvlc ( uiCode ); pcSPS->setPadY ( uiCode ); |
---|
79 | |
---|
80 | xReadUvlc ( uiCode ); |
---|
81 | pcSPS->setMaxCUWidth ( uiCode ); g_uiMaxCUWidth = uiCode; |
---|
82 | pcSPS->setMaxCUHeight ( uiCode ); g_uiMaxCUHeight = uiCode; |
---|
83 | |
---|
84 | xReadUvlc ( uiCode ); |
---|
85 | pcSPS->setMaxCUDepth ( uiCode+1 ); g_uiMaxCUDepth = uiCode + 1; |
---|
86 | UInt uiMaxCUDepthCorrect = uiCode; |
---|
87 | |
---|
88 | xReadUvlc( uiCode ); pcSPS->setQuadtreeTULog2MinSize( uiCode + 2 ); |
---|
89 | xReadUvlc( uiCode ); pcSPS->setQuadtreeTULog2MaxSize( uiCode + pcSPS->getQuadtreeTULog2MinSize() ); |
---|
90 | pcSPS->setMaxTrSize( 1<<(uiCode + pcSPS->getQuadtreeTULog2MinSize()) ); |
---|
91 | xReadUvlc ( uiCode ); pcSPS->setQuadtreeTUMaxDepthInter( uiCode+1 ); |
---|
92 | xReadUvlc ( uiCode ); pcSPS->setQuadtreeTUMaxDepthIntra( uiCode+1 ); |
---|
93 | g_uiAddCUDepth = 0; |
---|
94 | while( ( pcSPS->getMaxCUWidth() >> uiMaxCUDepthCorrect ) > ( 1 << ( pcSPS->getQuadtreeTULog2MinSize() + g_uiAddCUDepth ) ) ) g_uiAddCUDepth++; |
---|
95 | pcSPS->setMaxCUDepth( uiMaxCUDepthCorrect+g_uiAddCUDepth ); g_uiMaxCUDepth = uiMaxCUDepthCorrect+g_uiAddCUDepth; |
---|
96 | // BB: these parameters may be removed completly and replaced by the fixed values |
---|
97 | pcSPS->setMinTrDepth( 0 ); |
---|
98 | pcSPS->setMaxTrDepth( 1 ); |
---|
99 | |
---|
100 | // Tool on/off |
---|
101 | xReadFlag( uiCode ); pcSPS->setUseALF ( uiCode ? true : false ); |
---|
102 | xReadFlag( uiCode ); pcSPS->setUseDQP ( uiCode ? true : false ); |
---|
103 | xReadFlag( uiCode ); pcSPS->setUseLDC ( uiCode ? true : false ); |
---|
104 | #if HHI_MRG |
---|
105 | xReadFlag( uiCode ); pcSPS->setUseMRG ( uiCode ? true : false ); // SOPH: |
---|
106 | #endif |
---|
107 | |
---|
108 | #if HHI_RMP_SWITCH |
---|
109 | xReadFlag( uiCode ); pcSPS->setUseRMP( uiCode ? true : false ); |
---|
110 | #endif |
---|
111 | |
---|
112 | #if !DCTIF_8_6_LUMA |
---|
113 | // number of taps for DIF |
---|
114 | xReadUvlc( uiCode ); pcSPS->setDIFTap ( (uiCode+2)<<1 ); // 4, 6, 8, 10, 12 |
---|
115 | #endif |
---|
116 | |
---|
117 | // AMVP mode for each depth (AM_NONE or AM_EXPL) |
---|
118 | for (Int i = 0; i < pcSPS->getMaxCUDepth(); i++) |
---|
119 | { |
---|
120 | xReadFlag( uiCode ); |
---|
121 | pcSPS->setAMVPMode( i, (AMVP_MODE)uiCode ); |
---|
122 | } |
---|
123 | |
---|
124 | // Bit-depth information |
---|
125 | #if FULL_NBIT |
---|
126 | xReadUvlc( uiCode ); |
---|
127 | g_uiBitDepth = 8 + uiCode; |
---|
128 | g_uiBitIncrement = 0; |
---|
129 | pcSPS->setBitDepth(g_uiBitDepth); |
---|
130 | pcSPS->setBitIncrement(g_uiBitIncrement); |
---|
131 | #else |
---|
132 | #if ENABLE_IBDI |
---|
133 | xReadUvlc( uiCode ); pcSPS->setBitDepth ( uiCode+8 ); g_uiBitDepth = uiCode + 8; |
---|
134 | xReadUvlc( uiCode ); pcSPS->setBitIncrement ( uiCode ); g_uiBitIncrement = uiCode; |
---|
135 | #else |
---|
136 | xReadUvlc( uiCode ); |
---|
137 | g_uiBitDepth = 8; |
---|
138 | g_uiBitIncrement = uiCode; |
---|
139 | pcSPS->setBitDepth(g_uiBitDepth); |
---|
140 | pcSPS->setBitIncrement(g_uiBitIncrement); |
---|
141 | #endif |
---|
142 | #endif |
---|
143 | |
---|
144 | g_uiBASE_MAX = ((1<<(g_uiBitDepth))-1); |
---|
145 | |
---|
146 | #if IBDI_NOCLIP_RANGE |
---|
147 | g_uiIBDI_MAX = g_uiBASE_MAX << g_uiBitIncrement; |
---|
148 | #else |
---|
149 | g_uiIBDI_MAX = ((1<<(g_uiBitDepth+g_uiBitIncrement))-1); |
---|
150 | #endif |
---|
151 | |
---|
152 | return; |
---|
153 | } |
---|
154 | |
---|
155 | Void TDecCavlc::parseSliceHeader (TComSlice*& rpcSlice) |
---|
156 | { |
---|
157 | UInt uiCode; |
---|
158 | Int iCode; |
---|
159 | xReadCode ( 2, uiCode ); //NalRefIdc |
---|
160 | xReadCode ( 1, uiCode ); assert( 0 == uiCode); // zero bit |
---|
161 | #if DCM_DECODING_REFRESH |
---|
162 | xReadCode ( 5, uiCode ); |
---|
163 | rpcSlice->setNalUnitType ((NalUnitType)uiCode);//NalUnitType |
---|
164 | #else |
---|
165 | xReadCode ( 5, uiCode ); assert( NAL_UNIT_CODED_SLICE == uiCode);//NalUnitType |
---|
166 | #endif |
---|
167 | |
---|
168 | xReadCode (10, uiCode); rpcSlice->setPOC (uiCode); // 9 == SPS->Log2MaxFrameNum() |
---|
169 | xReadUvlc ( uiCode); rpcSlice->setSliceType ((SliceType)uiCode); |
---|
170 | xReadSvlc ( iCode); rpcSlice->setSliceQp (iCode); |
---|
171 | |
---|
172 | xReadFlag ( uiCode ); |
---|
173 | rpcSlice->setSymbolMode( uiCode ); |
---|
174 | |
---|
175 | if (!rpcSlice->isIntra()) |
---|
176 | xReadFlag ( uiCode); |
---|
177 | else |
---|
178 | uiCode = 1; |
---|
179 | |
---|
180 | rpcSlice->setReferenced (uiCode ? true : false); |
---|
181 | |
---|
182 | #if !HIGH_ACCURACY_BI |
---|
183 | #ifdef ROUNDING_CONTROL_BIPRED |
---|
184 | if(!rpcSlice->isIntra()) |
---|
185 | { |
---|
186 | xReadFlag( uiCode ); |
---|
187 | Bool b = (uiCode != 0); |
---|
188 | rpcSlice->setRounding(b); |
---|
189 | } |
---|
190 | #endif |
---|
191 | #else |
---|
192 | if(!rpcSlice->isIntra()) |
---|
193 | { |
---|
194 | rpcSlice->setRounding(false); |
---|
195 | } |
---|
196 | #endif |
---|
197 | |
---|
198 | xReadFlag ( uiCode); rpcSlice->setLoopFilterDisable(uiCode ? 1 : 0); |
---|
199 | |
---|
200 | if (!rpcSlice->isIntra()) |
---|
201 | { |
---|
202 | xReadCode (3, uiCode); rpcSlice->setNumRefIdx (REF_PIC_LIST_0, uiCode); |
---|
203 | } |
---|
204 | else |
---|
205 | { |
---|
206 | rpcSlice->setNumRefIdx(REF_PIC_LIST_0, 0); |
---|
207 | } |
---|
208 | if (rpcSlice->isInterB()) |
---|
209 | { |
---|
210 | xReadCode (3, uiCode); rpcSlice->setNumRefIdx (REF_PIC_LIST_1, uiCode); |
---|
211 | } |
---|
212 | else |
---|
213 | { |
---|
214 | rpcSlice->setNumRefIdx(REF_PIC_LIST_1, 0); |
---|
215 | } |
---|
216 | |
---|
217 | #if DCM_COMB_LIST |
---|
218 | if (rpcSlice->isInterB()) |
---|
219 | { |
---|
220 | xReadFlag (uiCode); rpcSlice->setRefPicListCombinationFlag(uiCode ? 1 : 0); |
---|
221 | if(uiCode) |
---|
222 | { |
---|
223 | xReadUvlc(uiCode); rpcSlice->setNumRefIdx (REF_PIC_LIST_C, uiCode+1); |
---|
224 | |
---|
225 | xReadFlag (uiCode); rpcSlice->setRefPicListModificationFlagLC(uiCode ? 1 : 0); |
---|
226 | if(uiCode) |
---|
227 | { |
---|
228 | for (UInt i=0;i<rpcSlice->getNumRefIdx(REF_PIC_LIST_C);i++) |
---|
229 | { |
---|
230 | xReadFlag(uiCode); |
---|
231 | rpcSlice->setListIdFromIdxOfLC(i, uiCode); |
---|
232 | xReadUvlc(uiCode); |
---|
233 | rpcSlice->setRefIdxFromIdxOfLC(i, uiCode); |
---|
234 | rpcSlice->setRefIdxOfLC((RefPicList)rpcSlice->getListIdFromIdxOfLC(i), rpcSlice->getRefIdxFromIdxOfLC(i), i); |
---|
235 | } |
---|
236 | } |
---|
237 | } |
---|
238 | else |
---|
239 | { |
---|
240 | rpcSlice->setRefPicListCombinationFlag(false); |
---|
241 | rpcSlice->setRefPicListModificationFlagLC(false); |
---|
242 | rpcSlice->setNumRefIdx(REF_PIC_LIST_C, -1); |
---|
243 | } |
---|
244 | } |
---|
245 | #endif |
---|
246 | |
---|
247 | xReadFlag (uiCode); rpcSlice->setDRBFlag (uiCode ? 1 : 0); |
---|
248 | if ( !rpcSlice->getDRBFlag() ) |
---|
249 | { |
---|
250 | xReadCode(2, uiCode); rpcSlice->setERBIndex( (ERBIndex)uiCode ); assert (uiCode == ERB_NONE || uiCode == ERB_LTR); |
---|
251 | } |
---|
252 | #if !DCTIF_8_6_LUMA |
---|
253 | xReadUvlc( uiCode ); rpcSlice->setInterpFilterType( uiCode ); |
---|
254 | #endif |
---|
255 | |
---|
256 | |
---|
257 | #if AMVP_NEIGH_COL |
---|
258 | if ( rpcSlice->getSliceType() == B_SLICE ) |
---|
259 | { |
---|
260 | xReadFlag (uiCode); |
---|
261 | rpcSlice->setColDir(uiCode); |
---|
262 | } |
---|
263 | #endif |
---|
264 | return; |
---|
265 | } |
---|
266 | |
---|
267 | Void TDecCavlc::resetEntropy (TComSlice* pcSlice) |
---|
268 | { |
---|
269 | m_bRunLengthCoding = ! pcSlice->isIntra(); |
---|
270 | m_uiRun = 0; |
---|
271 | |
---|
272 | ::memcpy(m_uiLPTableD8, g_auiLPTableD8, 10*128*sizeof(UInt)); |
---|
273 | ::memcpy(m_uiLPTableD4, g_auiLPTableD4, 3*32*sizeof(UInt)); |
---|
274 | ::memcpy(m_uiLastPosVlcIndex, g_auiLastPosVlcIndex, 10*sizeof(UInt)); |
---|
275 | |
---|
276 | ::memcpy(m_uiCBPTableD, g_auiCBPTableD, 2*8*sizeof(UInt)); |
---|
277 | m_uiCbpVlcIdx[0] = 0; |
---|
278 | m_uiCbpVlcIdx[1] = 0; |
---|
279 | |
---|
280 | #if QC_BLK_CBP |
---|
281 | ::memcpy(m_uiBlkCBPTableD, g_auiBlkCBPTableD, 2*15*sizeof(UInt)); |
---|
282 | m_uiBlkCbpVlcIdx = 0; |
---|
283 | #endif |
---|
284 | |
---|
285 | ::memcpy(m_uiMI1TableD, g_auiMI1TableD, 8*sizeof(UInt)); |
---|
286 | ::memcpy(m_uiMI2TableD, g_auiMI2TableD, 15*sizeof(UInt)); |
---|
287 | |
---|
288 | #if MS_NO_BACK_PRED_IN_B0 |
---|
289 | #if DCM_COMB_LIST |
---|
290 | if ( pcSlice->getNoBackPredFlag() || pcSlice->getNumRefIdx(REF_PIC_LIST_C)>0) |
---|
291 | #else |
---|
292 | if ( pcSlice->getNoBackPredFlag() ) |
---|
293 | #endif |
---|
294 | { |
---|
295 | ::memcpy(m_uiMI1TableD, g_auiMI1TableDNoL1, 8*sizeof(UInt)); |
---|
296 | ::memcpy(m_uiMI2TableD, g_auiMI2TableDNoL1, 15*sizeof(UInt)); |
---|
297 | } |
---|
298 | #endif |
---|
299 | |
---|
300 | #if MS_LCEC_ONE_FRAME |
---|
301 | if ( pcSlice->getNumRefIdx(REF_PIC_LIST_0) <= 1 && pcSlice->getNumRefIdx(REF_PIC_LIST_1) <= 1 ) |
---|
302 | { |
---|
303 | if ( pcSlice->getNoBackPredFlag() || ( pcSlice->getNumRefIdx(REF_PIC_LIST_C) > 0 && pcSlice->getNumRefIdx(REF_PIC_LIST_C) <= 1 ) ) |
---|
304 | { |
---|
305 | ::memcpy(m_uiMI1TableD, g_auiMI1TableDOnly1RefNoL1, 8*sizeof(UInt)); |
---|
306 | } |
---|
307 | else |
---|
308 | { |
---|
309 | ::memcpy(m_uiMI1TableD, g_auiMI1TableDOnly1Ref, 8*sizeof(UInt)); |
---|
310 | } |
---|
311 | } |
---|
312 | #endif |
---|
313 | #if MS_LCEC_LOOKUP_TABLE_EXCEPTION |
---|
314 | if (pcSlice->getNumRefIdx(REF_PIC_LIST_C)>0) |
---|
315 | { |
---|
316 | m_uiMI1TableD[8] = 8; |
---|
317 | } |
---|
318 | else // GPB case |
---|
319 | { |
---|
320 | m_uiMI1TableD[8] = m_uiMI1TableD[6]; |
---|
321 | m_uiMI1TableD[6] = 8; |
---|
322 | } |
---|
323 | #endif |
---|
324 | |
---|
325 | #if LCEC_INTRA_MODE |
---|
326 | ::memcpy(m_uiIntraModeTableD17, g_auiIntraModeTableD17, 16*sizeof(UInt)); |
---|
327 | ::memcpy(m_uiIntraModeTableD34, g_auiIntraModeTableD34, 33*sizeof(UInt)); |
---|
328 | #endif |
---|
329 | #if QC_LCEC_INTER_MODE |
---|
330 | ::memcpy(m_uiSplitTableD, g_auiInterModeTableD, 4*7*sizeof(UInt)); |
---|
331 | #endif |
---|
332 | m_uiMITableVlcIdx = 0; |
---|
333 | } |
---|
334 | |
---|
335 | Void TDecCavlc::parseTerminatingBit( UInt& ruiBit ) |
---|
336 | { |
---|
337 | #if BUGFIX102 |
---|
338 | ruiBit = false; |
---|
339 | #else |
---|
340 | xReadFlag( ruiBit ); |
---|
341 | #endif |
---|
342 | } |
---|
343 | |
---|
344 | Void TDecCavlc::parseAlfCtrlDepth ( UInt& ruiAlfCtrlDepth ) |
---|
345 | { |
---|
346 | UInt uiSymbol; |
---|
347 | xReadUnaryMaxSymbol(uiSymbol, g_uiMaxCUDepth-1); |
---|
348 | ruiAlfCtrlDepth = uiSymbol; |
---|
349 | } |
---|
350 | |
---|
351 | Void TDecCavlc::parseAlfCtrlFlag( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth ) |
---|
352 | { |
---|
353 | if (!m_bAlfCtrl) |
---|
354 | return; |
---|
355 | |
---|
356 | if( uiDepth > m_uiMaxAlfCtrlDepth && !pcCU->isFirstAbsZorderIdxInDepth(uiAbsPartIdx, m_uiMaxAlfCtrlDepth)) |
---|
357 | { |
---|
358 | return; |
---|
359 | } |
---|
360 | |
---|
361 | UInt uiSymbol; |
---|
362 | xReadFlag( uiSymbol ); |
---|
363 | |
---|
364 | if (uiDepth > m_uiMaxAlfCtrlDepth) |
---|
365 | { |
---|
366 | pcCU->setAlfCtrlFlagSubParts( uiSymbol, uiAbsPartIdx, m_uiMaxAlfCtrlDepth); |
---|
367 | } |
---|
368 | else |
---|
369 | { |
---|
370 | pcCU->setAlfCtrlFlagSubParts( uiSymbol, uiAbsPartIdx, uiDepth ); |
---|
371 | } |
---|
372 | } |
---|
373 | |
---|
374 | Void TDecCavlc::parseSkipFlag( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth ) |
---|
375 | { |
---|
376 | #if QC_LCEC_INTER_MODE |
---|
377 | return; |
---|
378 | #else |
---|
379 | #if HHI_MRG && !SAMSUNG_MRG_SKIP_DIRECT |
---|
380 | if ( pcCU->getSlice()->getSPS()->getUseMRG() ) |
---|
381 | { |
---|
382 | return; |
---|
383 | } |
---|
384 | #endif |
---|
385 | |
---|
386 | if( pcCU->getSlice()->isIntra() ) |
---|
387 | { |
---|
388 | return; |
---|
389 | } |
---|
390 | |
---|
391 | UInt uiSymbol; |
---|
392 | xReadFlag( uiSymbol ); |
---|
393 | |
---|
394 | if( uiSymbol ) |
---|
395 | { |
---|
396 | pcCU->setPredModeSubParts( MODE_SKIP, uiAbsPartIdx, uiDepth ); |
---|
397 | pcCU->setPartSizeSubParts( SIZE_2Nx2N, uiAbsPartIdx, uiDepth ); |
---|
398 | pcCU->setSizeSubParts( g_uiMaxCUWidth>>uiDepth, g_uiMaxCUHeight>>uiDepth, uiAbsPartIdx, uiDepth ); |
---|
399 | |
---|
400 | TComMv cZeroMv(0,0); |
---|
401 | pcCU->getCUMvField( REF_PIC_LIST_0 )->setAllMvd ( cZeroMv, SIZE_2Nx2N, uiAbsPartIdx, 0, uiDepth ); |
---|
402 | pcCU->getCUMvField( REF_PIC_LIST_1 )->setAllMvd ( cZeroMv, SIZE_2Nx2N, uiAbsPartIdx, 0, uiDepth ); |
---|
403 | |
---|
404 | pcCU->setTrIdxSubParts( 0, uiAbsPartIdx, uiDepth ); |
---|
405 | pcCU->setCbfSubParts ( 0, 0, 0, uiAbsPartIdx, uiDepth ); |
---|
406 | |
---|
407 | if ( pcCU->getSlice()->isInterP() ) |
---|
408 | { |
---|
409 | pcCU->setInterDirSubParts( 1, uiAbsPartIdx, 0, uiDepth ); |
---|
410 | |
---|
411 | if ( pcCU->getSlice()->getNumRefIdx( REF_PIC_LIST_0 ) > 0 ) |
---|
412 | pcCU->getCUMvField( REF_PIC_LIST_0 )->setAllRefIdx( 0, SIZE_2Nx2N, uiAbsPartIdx, 0, uiDepth ); |
---|
413 | if ( pcCU->getSlice()->getNumRefIdx( REF_PIC_LIST_1 ) > 0 ) |
---|
414 | pcCU->getCUMvField( REF_PIC_LIST_1 )->setAllRefIdx( NOT_VALID, SIZE_2Nx2N, uiAbsPartIdx, 0, uiDepth ); |
---|
415 | } |
---|
416 | else |
---|
417 | { |
---|
418 | pcCU->setInterDirSubParts( 3, uiAbsPartIdx, 0, uiDepth ); |
---|
419 | |
---|
420 | if ( pcCU->getSlice()->getNumRefIdx( REF_PIC_LIST_0 ) > 0 ) |
---|
421 | pcCU->getCUMvField( REF_PIC_LIST_0 )->setAllRefIdx( 0, SIZE_2Nx2N, uiAbsPartIdx, 0, uiDepth ); |
---|
422 | if ( pcCU->getSlice()->getNumRefIdx( REF_PIC_LIST_1 ) > 0 ) |
---|
423 | pcCU->getCUMvField( REF_PIC_LIST_1 )->setAllRefIdx( 0, SIZE_2Nx2N, uiAbsPartIdx, 0, uiDepth ); |
---|
424 | } |
---|
425 | } |
---|
426 | #endif |
---|
427 | } |
---|
428 | |
---|
429 | Void TDecCavlc::parseMVPIdx( TComDataCU* pcCU, Int& riMVPIdx, Int iMVPNum, UInt uiAbsPartIdx, UInt uiDepth, RefPicList eRefList ) |
---|
430 | { |
---|
431 | UInt uiSymbol; |
---|
432 | xReadUnaryMaxSymbol(uiSymbol, iMVPNum-1); |
---|
433 | riMVPIdx = uiSymbol; |
---|
434 | } |
---|
435 | #if QC_LCEC_INTER_MODE |
---|
436 | Void TDecCavlc::parseSplitFlag ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth ) |
---|
437 | { |
---|
438 | if (pcCU->getSlice()->isIntra()) |
---|
439 | { |
---|
440 | if( uiDepth == g_uiMaxCUDepth - g_uiAddCUDepth ) |
---|
441 | { |
---|
442 | pcCU->setDepthSubParts( uiDepth, uiAbsPartIdx ); |
---|
443 | return ; |
---|
444 | } |
---|
445 | |
---|
446 | UInt uiSymbol; |
---|
447 | xReadFlag( uiSymbol ); |
---|
448 | pcCU->setDepthSubParts( uiDepth + uiSymbol, uiAbsPartIdx ); |
---|
449 | |
---|
450 | return ; |
---|
451 | } |
---|
452 | UInt tmp=0; |
---|
453 | UInt cx=0; |
---|
454 | UInt uiMode ; |
---|
455 | { |
---|
456 | UInt iMaxLen= (uiDepth == g_uiMaxCUDepth - g_uiAddCUDepth)?5:6; |
---|
457 | while (tmp==0 && cx<iMaxLen) |
---|
458 | { |
---|
459 | xReadFlag( tmp ); |
---|
460 | cx++; |
---|
461 | }; |
---|
462 | if(tmp!=0) |
---|
463 | cx--; |
---|
464 | UInt x = m_uiSplitTableD[uiDepth][cx]; |
---|
465 | /* Adapt table */ |
---|
466 | uiMode = x; |
---|
467 | if (cx>0) |
---|
468 | { |
---|
469 | UInt cy = Max(0,cx-1); |
---|
470 | UInt y = m_uiSplitTableD[uiDepth][cy]; |
---|
471 | m_uiSplitTableD[uiDepth][cy] = x; |
---|
472 | m_uiSplitTableD[uiDepth][cx] = y; |
---|
473 | } |
---|
474 | } |
---|
475 | if (uiMode==0) |
---|
476 | { |
---|
477 | pcCU->setDepthSubParts( uiDepth + 1, uiAbsPartIdx ); |
---|
478 | } |
---|
479 | else |
---|
480 | { |
---|
481 | pcCU->setPartSizeSubParts( SIZE_2Nx2N, uiAbsPartIdx, uiDepth ); |
---|
482 | pcCU->setMergeFlagSubParts(false, uiAbsPartIdx,0, uiDepth ); |
---|
483 | pcCU->setDepthSubParts( uiDepth , uiAbsPartIdx ); |
---|
484 | if (uiMode ==1) |
---|
485 | { |
---|
486 | TComMv cZeroMv(0,0); |
---|
487 | pcCU->setPredModeSubParts( MODE_SKIP, uiAbsPartIdx, uiDepth ); |
---|
488 | pcCU->setPartSizeSubParts( SIZE_2Nx2N, uiAbsPartIdx, uiDepth ); |
---|
489 | pcCU->setSizeSubParts( g_uiMaxCUWidth>>uiDepth, g_uiMaxCUHeight>>uiDepth, uiAbsPartIdx, uiDepth ); |
---|
490 | pcCU->getCUMvField( REF_PIC_LIST_0 )->setAllMvd ( cZeroMv, SIZE_2Nx2N, uiAbsPartIdx, 0, uiDepth ); |
---|
491 | pcCU->getCUMvField( REF_PIC_LIST_1 )->setAllMvd ( cZeroMv, SIZE_2Nx2N, uiAbsPartIdx, 0, uiDepth ); |
---|
492 | pcCU->setTrIdxSubParts( 0, uiAbsPartIdx, uiDepth ); |
---|
493 | pcCU->setCbfSubParts ( 0, 0, 0, uiAbsPartIdx, uiDepth ); |
---|
494 | |
---|
495 | if ( pcCU->getSlice()->isInterP() ) |
---|
496 | { |
---|
497 | pcCU->setInterDirSubParts( 1, uiAbsPartIdx, 0, uiDepth ); |
---|
498 | |
---|
499 | if ( pcCU->getSlice()->getNumRefIdx( REF_PIC_LIST_0 ) > 0 ) |
---|
500 | pcCU->getCUMvField( REF_PIC_LIST_0 )->setAllRefIdx( 0, SIZE_2Nx2N, uiAbsPartIdx, 0, uiDepth ); |
---|
501 | if ( pcCU->getSlice()->getNumRefIdx( REF_PIC_LIST_1 ) > 0 ) |
---|
502 | pcCU->getCUMvField( REF_PIC_LIST_1 )->setAllRefIdx( NOT_VALID, SIZE_2Nx2N, uiAbsPartIdx, 0, uiDepth ); |
---|
503 | } |
---|
504 | else |
---|
505 | { |
---|
506 | pcCU->setInterDirSubParts( 3, uiAbsPartIdx, 0, uiDepth ); |
---|
507 | |
---|
508 | if ( pcCU->getSlice()->getNumRefIdx( REF_PIC_LIST_0 ) > 0 ) |
---|
509 | pcCU->getCUMvField( REF_PIC_LIST_0 )->setAllRefIdx( 0, SIZE_2Nx2N, uiAbsPartIdx, 0, uiDepth ); |
---|
510 | if ( pcCU->getSlice()->getNumRefIdx( REF_PIC_LIST_1 ) > 0 ) |
---|
511 | pcCU->getCUMvField( REF_PIC_LIST_1 )->setAllRefIdx( 0, SIZE_2Nx2N, uiAbsPartIdx, 0, uiDepth ); |
---|
512 | } |
---|
513 | } |
---|
514 | else if (uiMode==2) |
---|
515 | { |
---|
516 | pcCU->setPredModeSubParts( MODE_INTER, uiAbsPartIdx, uiDepth ); |
---|
517 | pcCU->setPartSizeSubParts( SIZE_2Nx2N, uiAbsPartIdx, uiDepth ); |
---|
518 | pcCU->setMergeFlagSubParts(true, uiAbsPartIdx,0, uiDepth ); |
---|
519 | pcCU->setSizeSubParts( g_uiMaxCUWidth>>uiDepth, g_uiMaxCUHeight>>uiDepth, uiAbsPartIdx, uiDepth ); |
---|
520 | } |
---|
521 | else if (uiMode==6) |
---|
522 | { |
---|
523 | #if MTK_DISABLE_INTRA_NxN_SPLIT && HHI_DISABLE_INTER_NxN_SPLIT |
---|
524 | if (uiDepth != g_uiMaxCUDepth - g_uiAddCUDepth) |
---|
525 | { |
---|
526 | pcCU->setPredModeSubParts( MODE_INTRA, uiAbsPartIdx, uiDepth ); |
---|
527 | pcCU->setPartSizeSubParts( SIZE_2Nx2N, uiAbsPartIdx, uiDepth ); |
---|
528 | pcCU->setSizeSubParts( g_uiMaxCUWidth>>uiDepth, g_uiMaxCUHeight>>uiDepth, uiAbsPartIdx, uiDepth ); |
---|
529 | UInt uiTrLevel = 0; |
---|
530 | UInt uiWidthInBit = g_aucConvertToBit[pcCU->getWidth(uiAbsPartIdx)]+2; |
---|
531 | UInt uiTrSizeInBit = g_aucConvertToBit[pcCU->getSlice()->getSPS()->getMaxTrSize()]+2; |
---|
532 | uiTrLevel = uiWidthInBit >= uiTrSizeInBit ? uiWidthInBit - uiTrSizeInBit : 0; |
---|
533 | pcCU->setTrIdxSubParts( uiTrLevel, uiAbsPartIdx, uiDepth ); |
---|
534 | } |
---|
535 | else |
---|
536 | #endif |
---|
537 | { |
---|
538 | pcCU->setPredModeSubParts( MODE_INTER, uiAbsPartIdx, uiDepth ); |
---|
539 | pcCU->setPartSizeSubParts( SIZE_NxN, uiAbsPartIdx, uiDepth ); |
---|
540 | } |
---|
541 | } |
---|
542 | else |
---|
543 | { |
---|
544 | pcCU->setPredModeSubParts( MODE_INTER, uiAbsPartIdx, uiDepth ); |
---|
545 | pcCU->setPartSizeSubParts( PartSize(uiMode-3), uiAbsPartIdx, uiDepth ); |
---|
546 | pcCU->setSizeSubParts( g_uiMaxCUWidth>>uiDepth, g_uiMaxCUHeight>>uiDepth, uiAbsPartIdx, uiDepth ); |
---|
547 | } |
---|
548 | } |
---|
549 | } |
---|
550 | #else |
---|
551 | Void TDecCavlc::parseSplitFlag( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth ) |
---|
552 | { |
---|
553 | if( uiDepth == g_uiMaxCUDepth - g_uiAddCUDepth ) |
---|
554 | { |
---|
555 | pcCU->setDepthSubParts( uiDepth, uiAbsPartIdx ); |
---|
556 | return ; |
---|
557 | } |
---|
558 | |
---|
559 | UInt uiSymbol; |
---|
560 | xReadFlag( uiSymbol ); |
---|
561 | pcCU->setDepthSubParts( uiDepth + uiSymbol, uiAbsPartIdx ); |
---|
562 | |
---|
563 | return ; |
---|
564 | } |
---|
565 | #endif |
---|
566 | #if QC_LCEC_INTER_MODE |
---|
567 | Void TDecCavlc::parsePartSize( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth ) |
---|
568 | { |
---|
569 | if ( pcCU->isSkip( uiAbsPartIdx )) |
---|
570 | { |
---|
571 | return ; |
---|
572 | } |
---|
573 | UInt uiMode=0; |
---|
574 | if ( pcCU->getSlice()->isIntra()&& pcCU->isIntra( uiAbsPartIdx ) ) |
---|
575 | { |
---|
576 | #if MTK_DISABLE_INTRA_NxN_SPLIT |
---|
577 | uiMode = 1; |
---|
578 | if ( uiDepth == (g_uiMaxCUDepth - g_uiAddCUDepth )) |
---|
579 | #endif |
---|
580 | { |
---|
581 | UInt uiSymbol; |
---|
582 | xReadFlag( uiSymbol ); |
---|
583 | uiMode = uiSymbol ? 1 : 2; |
---|
584 | } |
---|
585 | } |
---|
586 | #if MTK_DISABLE_INTRA_NxN_SPLIT && HHI_DISABLE_INTER_NxN_SPLIT |
---|
587 | else if (uiDepth != (g_uiMaxCUDepth - g_uiAddCUDepth ) || pcCU->getPartitionSize(uiAbsPartIdx ) != SIZE_NxN) |
---|
588 | #else |
---|
589 | else if (pcCU->getPartitionSize(uiAbsPartIdx ) != SIZE_NxN) |
---|
590 | #endif |
---|
591 | { |
---|
592 | return; |
---|
593 | } |
---|
594 | else |
---|
595 | { |
---|
596 | UInt uiSymbol; |
---|
597 | xReadFlag( uiSymbol ); |
---|
598 | if(uiSymbol) |
---|
599 | { |
---|
600 | uiMode = 1; |
---|
601 | } |
---|
602 | else |
---|
603 | { |
---|
604 | #if (MTK_DISABLE_INTRA_NxN_SPLIT && !HHI_DISABLE_INTER_NxN_SPLIT) || (!MTK_DISABLE_INTRA_NxN_SPLIT && HHI_DISABLE_INTER_NxN_SPLIT ) |
---|
605 | if ( uiDepth != (g_uiMaxCUDepth - g_uiAddCUDepth )) |
---|
606 | { |
---|
607 | #if MTK_DISABLE_INTRA_NxN_SPLIT && !HHI_DISABLE_INTER_NxN_SPLIT |
---|
608 | uiMode = 0; |
---|
609 | #elif !MTK_DISABLE_INTRA_NxN_SPLIT && HHI_DISABLE_INTER_NxN_SPLIT |
---|
610 | uiMode = 2; |
---|
611 | #endif |
---|
612 | } |
---|
613 | else |
---|
614 | #endif |
---|
615 | { |
---|
616 | xReadFlag( uiSymbol ); |
---|
617 | uiMode = uiSymbol ? 2 : 0; |
---|
618 | } |
---|
619 | } |
---|
620 | } |
---|
621 | PartSize ePartSize; |
---|
622 | PredMode eMode; |
---|
623 | if (uiMode > 0) |
---|
624 | { |
---|
625 | eMode = MODE_INTRA; |
---|
626 | ePartSize = (uiMode==1) ? SIZE_2Nx2N:SIZE_NxN; |
---|
627 | } |
---|
628 | else |
---|
629 | { |
---|
630 | eMode = MODE_INTER; |
---|
631 | ePartSize = SIZE_NxN; |
---|
632 | } |
---|
633 | pcCU->setPredModeSubParts( eMode , uiAbsPartIdx, uiDepth ); |
---|
634 | pcCU->setPartSizeSubParts( ePartSize, uiAbsPartIdx, uiDepth ); |
---|
635 | pcCU->setSizeSubParts( g_uiMaxCUWidth>>uiDepth, g_uiMaxCUHeight>>uiDepth, uiAbsPartIdx, uiDepth ); |
---|
636 | |
---|
637 | if( pcCU->getPredictionMode(uiAbsPartIdx) == MODE_INTRA ) |
---|
638 | { |
---|
639 | UInt uiTrLevel = 0; |
---|
640 | UInt uiWidthInBit = g_aucConvertToBit[pcCU->getWidth(uiAbsPartIdx)] + 2; |
---|
641 | UInt uiTrSizeInBit = g_aucConvertToBit[pcCU->getSlice()->getSPS()->getMaxTrSize()] + 2; |
---|
642 | uiTrLevel = uiWidthInBit >= uiTrSizeInBit ? uiWidthInBit - uiTrSizeInBit : 0; |
---|
643 | if( pcCU->getPartitionSize( uiAbsPartIdx ) == SIZE_NxN ) |
---|
644 | { |
---|
645 | pcCU->setTrIdxSubParts( 1 + uiTrLevel, uiAbsPartIdx, uiDepth ); |
---|
646 | } |
---|
647 | else |
---|
648 | { |
---|
649 | pcCU->setTrIdxSubParts( uiTrLevel, uiAbsPartIdx, uiDepth ); |
---|
650 | } |
---|
651 | } |
---|
652 | } |
---|
653 | #else |
---|
654 | Void TDecCavlc::parsePartSize( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth ) |
---|
655 | { |
---|
656 | if ( pcCU->isSkip( uiAbsPartIdx ) ) |
---|
657 | { |
---|
658 | pcCU->setPartSizeSubParts( SIZE_2Nx2N, uiAbsPartIdx, uiDepth ); |
---|
659 | pcCU->setSizeSubParts( g_uiMaxCUWidth>>uiDepth, g_uiMaxCUHeight>>uiDepth, uiAbsPartIdx, uiDepth ); |
---|
660 | return ; |
---|
661 | } |
---|
662 | |
---|
663 | UInt uiSymbol, uiMode = 0; |
---|
664 | PartSize eMode; |
---|
665 | |
---|
666 | if ( pcCU->isIntra( uiAbsPartIdx ) ) |
---|
667 | { |
---|
668 | #if MTK_DISABLE_INTRA_NxN_SPLIT |
---|
669 | eMode = SIZE_2Nx2N; |
---|
670 | if ( (g_uiMaxCUWidth >> uiDepth) == 8 ) |
---|
671 | #endif |
---|
672 | { |
---|
673 | xReadFlag( uiSymbol ); |
---|
674 | eMode = uiSymbol ? SIZE_2Nx2N : SIZE_NxN; |
---|
675 | } |
---|
676 | } |
---|
677 | else |
---|
678 | { |
---|
679 | #if HHI_RMP_SWITCH |
---|
680 | if ( !pcCU->getSlice()->getSPS()->getUseRMP()) |
---|
681 | { |
---|
682 | xReadFlag( uiSymbol ); |
---|
683 | if( uiSymbol ) |
---|
684 | uiMode = 0; |
---|
685 | else |
---|
686 | uiMode = 3; |
---|
687 | } |
---|
688 | else |
---|
689 | #endif |
---|
690 | { |
---|
691 | UInt uiMaxNumBits = 3; |
---|
692 | for ( UInt ui = 0; ui < uiMaxNumBits; ui++ ) |
---|
693 | { |
---|
694 | xReadFlag( uiSymbol ); |
---|
695 | if ( uiSymbol ) |
---|
696 | { |
---|
697 | break; |
---|
698 | } |
---|
699 | uiMode++; |
---|
700 | } |
---|
701 | } |
---|
702 | eMode = (PartSize) uiMode; |
---|
703 | |
---|
704 | if (pcCU->getSlice()->isInterB() && uiMode == 3) |
---|
705 | { |
---|
706 | #if HHI_DISABLE_INTER_NxN_SPLIT |
---|
707 | uiSymbol = 0; |
---|
708 | if( g_uiMaxCUWidth>>uiDepth == 8 ) |
---|
709 | #endif |
---|
710 | { |
---|
711 | xReadFlag( uiSymbol ); |
---|
712 | } |
---|
713 | |
---|
714 | if (uiSymbol == 0) |
---|
715 | { |
---|
716 | pcCU->setPredModeSubParts( MODE_INTRA, uiAbsPartIdx, uiDepth ); |
---|
717 | #if MTK_DISABLE_INTRA_NxN_SPLIT |
---|
718 | if ( (g_uiMaxCUWidth >> uiDepth) == 8 ) |
---|
719 | #endif |
---|
720 | { |
---|
721 | xReadFlag( uiSymbol ); |
---|
722 | } |
---|
723 | if (uiSymbol == 0) |
---|
724 | eMode = SIZE_2Nx2N; |
---|
725 | } |
---|
726 | } |
---|
727 | |
---|
728 | } |
---|
729 | |
---|
730 | pcCU->setPartSizeSubParts( eMode, uiAbsPartIdx, uiDepth ); |
---|
731 | pcCU->setSizeSubParts( g_uiMaxCUWidth>>uiDepth, g_uiMaxCUHeight>>uiDepth, uiAbsPartIdx, uiDepth ); |
---|
732 | |
---|
733 | UInt uiTrLevel = 0; |
---|
734 | |
---|
735 | UInt uiWidthInBit = g_aucConvertToBit[pcCU->getWidth(uiAbsPartIdx)]+2; |
---|
736 | UInt uiTrSizeInBit = g_aucConvertToBit[pcCU->getSlice()->getSPS()->getMaxTrSize()]+2; |
---|
737 | uiTrLevel = uiWidthInBit >= uiTrSizeInBit ? uiWidthInBit - uiTrSizeInBit : 0; |
---|
738 | |
---|
739 | if( pcCU->getPredictionMode(uiAbsPartIdx) == MODE_INTRA ) |
---|
740 | { |
---|
741 | if( pcCU->getPartitionSize( uiAbsPartIdx ) == SIZE_NxN ) |
---|
742 | { |
---|
743 | pcCU->setTrIdxSubParts( 1+uiTrLevel, uiAbsPartIdx, uiDepth ); |
---|
744 | } |
---|
745 | else |
---|
746 | { |
---|
747 | pcCU->setTrIdxSubParts( uiTrLevel, uiAbsPartIdx, uiDepth ); |
---|
748 | } |
---|
749 | } |
---|
750 | } |
---|
751 | #endif |
---|
752 | Void TDecCavlc::parsePredMode( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth ) |
---|
753 | { |
---|
754 | if( pcCU->getSlice()->isIntra() ) |
---|
755 | { |
---|
756 | pcCU->setPredModeSubParts( MODE_INTRA, uiAbsPartIdx, uiDepth ); |
---|
757 | return ; |
---|
758 | } |
---|
759 | #if !QC_LCEC_INTER_MODE |
---|
760 | UInt uiSymbol; |
---|
761 | Int iPredMode = MODE_INTER; |
---|
762 | |
---|
763 | if ( pcCU->getSlice()->isInterB() ) |
---|
764 | { |
---|
765 | pcCU->setPredModeSubParts( (PredMode)iPredMode, uiAbsPartIdx, uiDepth ); |
---|
766 | return; |
---|
767 | } |
---|
768 | |
---|
769 | if ( iPredMode != MODE_SKIP ) |
---|
770 | { |
---|
771 | xReadFlag( uiSymbol ); |
---|
772 | iPredMode += uiSymbol; |
---|
773 | } |
---|
774 | |
---|
775 | pcCU->setPredModeSubParts( (PredMode)iPredMode, uiAbsPartIdx, uiDepth ); |
---|
776 | #endif |
---|
777 | } |
---|
778 | |
---|
779 | #if LCEC_INTRA_MODE |
---|
780 | Void TDecCavlc::parseIntraDirLumaAng ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth ) |
---|
781 | { |
---|
782 | UInt uiSymbol; |
---|
783 | Int uiIPredMode; |
---|
784 | Int iMostProbable = pcCU->getMostProbableIntraDirLuma( uiAbsPartIdx ); |
---|
785 | Int iIntraIdx = pcCU->getIntraSizeIdx(uiAbsPartIdx); |
---|
786 | Int iDir, iDirLarger, iRankIntraMode, iRankIntraModeLarger; |
---|
787 | |
---|
788 | Int iLeft = pcCU->getLeftIntraDirLuma( uiAbsPartIdx ); |
---|
789 | Int iAbove = pcCU->getAboveIntraDirLuma( uiAbsPartIdx ); |
---|
790 | UInt ind=(iLeft==iAbove)? 0 : 1; |
---|
791 | |
---|
792 | const UInt *huff17=huff17_2[ind]; |
---|
793 | const UInt *lengthHuff17=lengthHuff17_2[ind]; |
---|
794 | const UInt *huff34=huff34_2[ind]; |
---|
795 | const UInt *lengthHuff34=lengthHuff34_2[ind]; |
---|
796 | |
---|
797 | if ( g_aucIntraModeBitsAng[iIntraIdx] < 5 ) |
---|
798 | { |
---|
799 | xReadFlag( uiSymbol ); |
---|
800 | if ( uiSymbol ) |
---|
801 | uiIPredMode = iMostProbable; |
---|
802 | else |
---|
803 | { |
---|
804 | xReadFlag( uiSymbol ); uiIPredMode = uiSymbol; |
---|
805 | if ( g_aucIntraModeBitsAng[iIntraIdx] > 2 ) { xReadFlag( uiSymbol ); uiIPredMode |= uiSymbol << 1; } |
---|
806 | if ( g_aucIntraModeBitsAng[iIntraIdx] > 3 ) { xReadFlag( uiSymbol ); uiIPredMode |= uiSymbol << 2; } |
---|
807 | if(uiIPredMode >= iMostProbable) |
---|
808 | uiIPredMode ++; |
---|
809 | } |
---|
810 | } |
---|
811 | else if ( g_aucIntraModeBitsAng[iIntraIdx] == 5 ) |
---|
812 | { |
---|
813 | UInt uiCode; |
---|
814 | UInt uiLength = lengthHuff17[15]; |
---|
815 | m_pcBitstream->pseudoRead(uiLength,uiCode); |
---|
816 | if ((uiCode>>(uiLength- lengthHuff17[0])) == huff17[0]) |
---|
817 | { |
---|
818 | m_pcBitstream->read(lengthHuff17[0],uiCode); |
---|
819 | uiIPredMode = iMostProbable; |
---|
820 | } |
---|
821 | else |
---|
822 | { |
---|
823 | iRankIntraMode = 0; |
---|
824 | for (Int i=1;i<17;i++) |
---|
825 | { |
---|
826 | if( (uiCode>>(uiLength- lengthHuff17[i])) == huff17[i]) |
---|
827 | { |
---|
828 | m_pcBitstream->read(lengthHuff17[i], uiCode); |
---|
829 | iRankIntraMode = i; |
---|
830 | break; |
---|
831 | } |
---|
832 | } |
---|
833 | |
---|
834 | if ( iRankIntraMode > 0 ) |
---|
835 | iRankIntraMode --; |
---|
836 | iDir = m_uiIntraModeTableD17[iRankIntraMode]; |
---|
837 | |
---|
838 | iRankIntraModeLarger = Max(0,iRankIntraMode-1); |
---|
839 | iDirLarger = m_uiIntraModeTableD17[iRankIntraModeLarger]; |
---|
840 | |
---|
841 | m_uiIntraModeTableD17[iRankIntraModeLarger] = iDir; |
---|
842 | m_uiIntraModeTableD17[iRankIntraMode] = iDirLarger; |
---|
843 | |
---|
844 | uiIPredMode = (iDir>=iMostProbable? iDir+1: iDir); |
---|
845 | } |
---|
846 | } |
---|
847 | else |
---|
848 | { |
---|
849 | UInt uiCode; |
---|
850 | UInt uiLength = lengthHuff34[32]; |
---|
851 | m_pcBitstream->pseudoRead(uiLength,uiCode); |
---|
852 | if ((uiCode>>(uiLength- lengthHuff34[0])) == huff34[0]) |
---|
853 | { |
---|
854 | m_pcBitstream->read(lengthHuff34[0],uiCode); |
---|
855 | uiIPredMode = iMostProbable; |
---|
856 | } |
---|
857 | else |
---|
858 | { |
---|
859 | iRankIntraMode = 0; |
---|
860 | for (Int i=1;i<34;i++) |
---|
861 | { |
---|
862 | if( (uiCode>>(uiLength- lengthHuff34[i])) == huff34[i]) |
---|
863 | { |
---|
864 | m_pcBitstream->read(lengthHuff34[i], uiCode); |
---|
865 | iRankIntraMode = i; |
---|
866 | break; |
---|
867 | } |
---|
868 | } |
---|
869 | |
---|
870 | if ( iRankIntraMode > 0 ) |
---|
871 | iRankIntraMode --; |
---|
872 | iDir = m_uiIntraModeTableD34[iRankIntraMode]; |
---|
873 | |
---|
874 | iRankIntraModeLarger = Max(0,iRankIntraMode-1); |
---|
875 | iDirLarger = m_uiIntraModeTableD34[iRankIntraModeLarger]; |
---|
876 | |
---|
877 | m_uiIntraModeTableD34[iRankIntraModeLarger] = iDir; |
---|
878 | m_uiIntraModeTableD34[iRankIntraMode] = iDirLarger; |
---|
879 | |
---|
880 | uiIPredMode = (iDir>=iMostProbable? iDir+1: iDir); |
---|
881 | } |
---|
882 | } |
---|
883 | |
---|
884 | pcCU->setLumaIntraDirSubParts( (UChar)uiIPredMode, uiAbsPartIdx, uiDepth ); |
---|
885 | } |
---|
886 | |
---|
887 | #else |
---|
888 | Void TDecCavlc::parseIntraDirLumaAng ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth ) |
---|
889 | { |
---|
890 | UInt uiSymbol; |
---|
891 | Int uiIPredMode; |
---|
892 | Int iMostProbable = pcCU->getMostProbableIntraDirLuma( uiAbsPartIdx ); |
---|
893 | |
---|
894 | xReadFlag( uiSymbol ); |
---|
895 | |
---|
896 | if ( uiSymbol ) |
---|
897 | uiIPredMode = iMostProbable; |
---|
898 | else |
---|
899 | { |
---|
900 | Int iIntraIdx = pcCU->getIntraSizeIdx(uiAbsPartIdx); |
---|
901 | if ( g_aucIntraModeBitsAng[iIntraIdx] < 6 ) |
---|
902 | { |
---|
903 | xReadFlag( uiSymbol ); uiIPredMode = uiSymbol; |
---|
904 | if ( g_aucIntraModeBitsAng[iIntraIdx] > 2 ) { xReadFlag( uiSymbol ); uiIPredMode |= uiSymbol << 1; } |
---|
905 | if ( g_aucIntraModeBitsAng[iIntraIdx] > 3 ) { xReadFlag( uiSymbol ); uiIPredMode |= uiSymbol << 2; } |
---|
906 | if ( g_aucIntraModeBitsAng[iIntraIdx] > 4 ) { xReadFlag( uiSymbol ); uiIPredMode |= uiSymbol << 3; } |
---|
907 | } |
---|
908 | else |
---|
909 | { |
---|
910 | xReadFlag( uiSymbol ); uiIPredMode = uiSymbol; |
---|
911 | xReadFlag( uiSymbol ); uiIPredMode |= uiSymbol << 1; |
---|
912 | xReadFlag( uiSymbol ); uiIPredMode |= uiSymbol << 2; |
---|
913 | xReadFlag( uiSymbol ); uiIPredMode |= uiSymbol << 3; |
---|
914 | xReadFlag( uiSymbol ); uiIPredMode |= uiSymbol << 4; |
---|
915 | |
---|
916 | if (uiIPredMode == 31) |
---|
917 | { // Escape coding for the last two modes |
---|
918 | xReadFlag( uiSymbol ); |
---|
919 | uiIPredMode = uiSymbol ? 32 : 31; |
---|
920 | } |
---|
921 | } |
---|
922 | |
---|
923 | if (uiIPredMode >= iMostProbable) |
---|
924 | uiIPredMode++; |
---|
925 | } |
---|
926 | |
---|
927 | pcCU->setLumaIntraDirSubParts( (UChar)uiIPredMode, uiAbsPartIdx, uiDepth ); |
---|
928 | } |
---|
929 | #endif |
---|
930 | |
---|
931 | Void TDecCavlc::parseIntraDirChroma( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth ) |
---|
932 | { |
---|
933 | UInt uiSymbol; |
---|
934 | #if CHROMA_CODEWORD |
---|
935 | UInt uiMode = pcCU->getLumaIntraDir(uiAbsPartIdx); |
---|
936 | Int iMax = uiMode < 4 ? 3 : 4; |
---|
937 | xReadUnaryMaxSymbol( uiSymbol, iMax ); |
---|
938 | |
---|
939 | //switch codeword |
---|
940 | if (uiSymbol == 0) |
---|
941 | { |
---|
942 | uiSymbol = 4; |
---|
943 | } |
---|
944 | #if CHROMA_CODEWORD_SWITCH |
---|
945 | else |
---|
946 | { |
---|
947 | uiSymbol = ChromaMapping[iMax-3][uiSymbol]; |
---|
948 | if (uiSymbol <= uiMode) |
---|
949 | { |
---|
950 | uiSymbol --; |
---|
951 | } |
---|
952 | } |
---|
953 | #else |
---|
954 | else if (uiSymbol <= uiMode) |
---|
955 | { |
---|
956 | uiSymbol --; |
---|
957 | } |
---|
958 | #endif |
---|
959 | //printf("uiMode %d, chroma %d, codeword %d, imax %d\n", uiMode, uiSymbol, uiRead, iMax); |
---|
960 | #else |
---|
961 | xReadFlag( uiSymbol ); |
---|
962 | |
---|
963 | if ( uiSymbol ) |
---|
964 | { |
---|
965 | xReadUnaryMaxSymbol( uiSymbol, 3 ); |
---|
966 | uiSymbol++; |
---|
967 | } |
---|
968 | #endif |
---|
969 | pcCU->setChromIntraDirSubParts( uiSymbol, uiAbsPartIdx, uiDepth ); |
---|
970 | |
---|
971 | return ; |
---|
972 | } |
---|
973 | |
---|
974 | Void TDecCavlc::parseInterDir( TComDataCU* pcCU, UInt& ruiInterDir, UInt uiAbsPartIdx, UInt uiDepth ) |
---|
975 | { |
---|
976 | UInt uiSymbol; |
---|
977 | |
---|
978 | #if MS_LCEC_LOOKUP_TABLE_EXCEPTION |
---|
979 | if ( pcCU->getSlice()->getRefIdxCombineCoding() ) |
---|
980 | #else |
---|
981 | if(pcCU->getSlice()->getNumRefIdx( REF_PIC_LIST_0 ) <= 2 && pcCU->getSlice()->getNumRefIdx( REF_PIC_LIST_1 ) <= 2) |
---|
982 | #endif |
---|
983 | { |
---|
984 | UInt uiIndex,uiInterDir,tmp; |
---|
985 | Int x,cx,y,cy; |
---|
986 | |
---|
987 | #if MS_LCEC_LOOKUP_TABLE_MAX_VALUE |
---|
988 | UInt uiMaxVal = 7; |
---|
989 | #if MS_LCEC_LOOKUP_TABLE_EXCEPTION |
---|
990 | uiMaxVal = 8; |
---|
991 | #endif |
---|
992 | if ( pcCU->getSlice()->getNumRefIdx( REF_PIC_LIST_0 ) <= 1 && pcCU->getSlice()->getNumRefIdx( REF_PIC_LIST_1 ) <= 1 ) |
---|
993 | { |
---|
994 | if ( pcCU->getSlice()->getNoBackPredFlag() || ( pcCU->getSlice()->getNumRefIdx(REF_PIC_LIST_C) > 0 && pcCU->getSlice()->getNumRefIdx(REF_PIC_LIST_C) <= 1 ) ) |
---|
995 | { |
---|
996 | uiMaxVal = 1; |
---|
997 | } |
---|
998 | else |
---|
999 | { |
---|
1000 | uiMaxVal = 2; |
---|
1001 | } |
---|
1002 | } |
---|
1003 | else if ( pcCU->getSlice()->getNumRefIdx( REF_PIC_LIST_0 ) <= 2 && pcCU->getSlice()->getNumRefIdx( REF_PIC_LIST_1 ) <= 2 ) |
---|
1004 | { |
---|
1005 | if ( pcCU->getSlice()->getNoBackPredFlag() || ( pcCU->getSlice()->getNumRefIdx(REF_PIC_LIST_C) > 0 && pcCU->getSlice()->getNumRefIdx(REF_PIC_LIST_C) <= 2 ) ) |
---|
1006 | { |
---|
1007 | uiMaxVal = 5; |
---|
1008 | } |
---|
1009 | else |
---|
1010 | { |
---|
1011 | uiMaxVal = 7; |
---|
1012 | } |
---|
1013 | } |
---|
1014 | else if ( pcCU->getSlice()->getNumRefIdx(REF_PIC_LIST_C) <= 0 ) |
---|
1015 | { |
---|
1016 | uiMaxVal = 4+1+MS_LCEC_UNI_EXCEPTION_THRES; |
---|
1017 | } |
---|
1018 | |
---|
1019 | xReadUnaryMaxSymbol( tmp, uiMaxVal ); |
---|
1020 | #else |
---|
1021 | UInt vlcn = g_auiMITableVlcNum[m_uiMITableVlcIdx]; |
---|
1022 | tmp = xReadVlc( vlcn ); |
---|
1023 | #endif |
---|
1024 | UInt *m_uiMITableD = m_uiMI1TableD; |
---|
1025 | x = m_uiMITableD[tmp]; |
---|
1026 | uiIndex = x; |
---|
1027 | |
---|
1028 | /* Adapt table */ |
---|
1029 | |
---|
1030 | cx = tmp; |
---|
1031 | cy = Max(0,cx-1); |
---|
1032 | y = m_uiMITableD[cy]; |
---|
1033 | m_uiMITableD[cy] = x; |
---|
1034 | m_uiMITableD[cx] = y; |
---|
1035 | m_uiMITableVlcIdx += cx == m_uiMITableVlcIdx ? 0 : (cx < m_uiMITableVlcIdx ? -1 : 1); |
---|
1036 | |
---|
1037 | { |
---|
1038 | uiInterDir = Min(2,uiIndex>>1); |
---|
1039 | #if MS_LCEC_LOOKUP_TABLE_EXCEPTION |
---|
1040 | if ( uiIndex >=4 ) |
---|
1041 | { |
---|
1042 | uiInterDir = 2; |
---|
1043 | } |
---|
1044 | else |
---|
1045 | { |
---|
1046 | uiInterDir = 0; |
---|
1047 | } |
---|
1048 | #endif |
---|
1049 | #if DCM_COMB_LIST |
---|
1050 | if(uiInterDir!=2 && pcCU->getSlice()->getNumRefIdx(REF_PIC_LIST_C)>0) |
---|
1051 | { |
---|
1052 | uiInterDir = 0; |
---|
1053 | m_iRefFrame0[uiAbsPartIdx] = uiIndex; |
---|
1054 | } |
---|
1055 | else |
---|
1056 | #endif |
---|
1057 | if (uiInterDir==0) |
---|
1058 | { |
---|
1059 | #if MS_LCEC_LOOKUP_TABLE_EXCEPTION |
---|
1060 | m_iRefFrame0[uiAbsPartIdx] = uiIndex; |
---|
1061 | #else |
---|
1062 | m_iRefFrame0[uiAbsPartIdx] = uiIndex&1; |
---|
1063 | #endif |
---|
1064 | } |
---|
1065 | else if (uiInterDir==1) |
---|
1066 | m_iRefFrame1[uiAbsPartIdx] = uiIndex&1; |
---|
1067 | else |
---|
1068 | { |
---|
1069 | m_iRefFrame0[uiAbsPartIdx] = (uiIndex>>1)&1; |
---|
1070 | m_iRefFrame1[uiAbsPartIdx] = (uiIndex>>0)&1; |
---|
1071 | } |
---|
1072 | } |
---|
1073 | ruiInterDir = uiInterDir+1; |
---|
1074 | #if MS_LCEC_LOOKUP_TABLE_EXCEPTION |
---|
1075 | if ( x < 8 ) |
---|
1076 | #endif |
---|
1077 | { |
---|
1078 | return; |
---|
1079 | } |
---|
1080 | } |
---|
1081 | |
---|
1082 | #if MS_LCEC_LOOKUP_TABLE_EXCEPTION |
---|
1083 | m_iRefFrame0[uiAbsPartIdx] = 1000; |
---|
1084 | m_iRefFrame1[uiAbsPartIdx] = 1000; |
---|
1085 | #endif |
---|
1086 | |
---|
1087 | xReadFlag( uiSymbol ); |
---|
1088 | |
---|
1089 | if ( uiSymbol ) |
---|
1090 | { |
---|
1091 | uiSymbol = 2; |
---|
1092 | } |
---|
1093 | #if DCM_COMB_LIST |
---|
1094 | else if(pcCU->getSlice()->getNumRefIdx(REF_PIC_LIST_C) > 0) |
---|
1095 | { |
---|
1096 | uiSymbol = 0; |
---|
1097 | } |
---|
1098 | #endif |
---|
1099 | #if MS_NO_BACK_PRED_IN_B0 |
---|
1100 | else if ( pcCU->getSlice()->getNoBackPredFlag() ) |
---|
1101 | { |
---|
1102 | uiSymbol = 0; |
---|
1103 | } |
---|
1104 | #endif |
---|
1105 | else |
---|
1106 | { |
---|
1107 | xReadFlag( uiSymbol ); |
---|
1108 | } |
---|
1109 | uiSymbol++; |
---|
1110 | ruiInterDir = uiSymbol; |
---|
1111 | return; |
---|
1112 | } |
---|
1113 | |
---|
1114 | Void TDecCavlc::parseRefFrmIdx( TComDataCU* pcCU, Int& riRefFrmIdx, UInt uiAbsPartIdx, UInt uiDepth, RefPicList eRefList ) |
---|
1115 | { |
---|
1116 | UInt uiSymbol; |
---|
1117 | |
---|
1118 | if (pcCU->getSlice()->getNumRefIdx( REF_PIC_LIST_0 ) <= 2 && pcCU->getSlice()->getNumRefIdx( REF_PIC_LIST_1 ) <= 2 && pcCU->getSlice()->isInterB()) |
---|
1119 | { |
---|
1120 | #if DCM_COMB_LIST |
---|
1121 | if(pcCU->getSlice()->getNumRefIdx(REF_PIC_LIST_C ) > 0 && eRefList==REF_PIC_LIST_C) |
---|
1122 | { |
---|
1123 | riRefFrmIdx = m_iRefFrame0[uiAbsPartIdx]; |
---|
1124 | } |
---|
1125 | else |
---|
1126 | #endif |
---|
1127 | if (eRefList==REF_PIC_LIST_0) |
---|
1128 | { |
---|
1129 | riRefFrmIdx = m_iRefFrame0[uiAbsPartIdx]; |
---|
1130 | } |
---|
1131 | if (eRefList==REF_PIC_LIST_1) |
---|
1132 | { |
---|
1133 | riRefFrmIdx = m_iRefFrame1[uiAbsPartIdx]; |
---|
1134 | } |
---|
1135 | return; |
---|
1136 | } |
---|
1137 | |
---|
1138 | #if MS_LCEC_LOOKUP_TABLE_EXCEPTION |
---|
1139 | if ( ( m_iRefFrame0[uiAbsPartIdx] != 1000 || m_iRefFrame1[uiAbsPartIdx] != 1000 ) && |
---|
1140 | pcCU->getSlice()->getRefIdxCombineCoding() ) |
---|
1141 | { |
---|
1142 | if(pcCU->getSlice()->getNumRefIdx(REF_PIC_LIST_C ) > 0 && eRefList==REF_PIC_LIST_C ) |
---|
1143 | { |
---|
1144 | riRefFrmIdx = m_iRefFrame0[uiAbsPartIdx]; |
---|
1145 | } |
---|
1146 | else if (eRefList==REF_PIC_LIST_0) |
---|
1147 | { |
---|
1148 | riRefFrmIdx = m_iRefFrame0[uiAbsPartIdx]; |
---|
1149 | } |
---|
1150 | else if (eRefList==REF_PIC_LIST_1) |
---|
1151 | { |
---|
1152 | riRefFrmIdx = m_iRefFrame1[uiAbsPartIdx]; |
---|
1153 | } |
---|
1154 | return; |
---|
1155 | } |
---|
1156 | |
---|
1157 | UInt uiRefFrmIdxMinus = 0; |
---|
1158 | if ( pcCU->getSlice()->getRefIdxCombineCoding() ) |
---|
1159 | { |
---|
1160 | if ( pcCU->getInterDir( uiAbsPartIdx ) != 3 ) |
---|
1161 | { |
---|
1162 | if ( pcCU->getSlice()->getNumRefIdx(REF_PIC_LIST_C) > 0 ) |
---|
1163 | { |
---|
1164 | uiRefFrmIdxMinus = 4; |
---|
1165 | } |
---|
1166 | else |
---|
1167 | { |
---|
1168 | uiRefFrmIdxMinus = MS_LCEC_UNI_EXCEPTION_THRES+1; |
---|
1169 | } |
---|
1170 | } |
---|
1171 | else if ( eRefList == REF_PIC_LIST_1 && pcCU->getCUMvField( REF_PIC_LIST_0 )->getRefIdx( uiAbsPartIdx ) < 2 ) |
---|
1172 | { |
---|
1173 | uiRefFrmIdxMinus = 2; |
---|
1174 | } |
---|
1175 | } |
---|
1176 | if ( pcCU->getSlice()->getNumRefIdx( eRefList ) - uiRefFrmIdxMinus <= 1 ) |
---|
1177 | { |
---|
1178 | uiSymbol = 0; |
---|
1179 | riRefFrmIdx = uiSymbol; |
---|
1180 | riRefFrmIdx += uiRefFrmIdxMinus; |
---|
1181 | return; |
---|
1182 | } |
---|
1183 | #endif |
---|
1184 | |
---|
1185 | xReadFlag ( uiSymbol ); |
---|
1186 | if ( uiSymbol ) |
---|
1187 | { |
---|
1188 | #if MS_LCEC_LOOKUP_TABLE_EXCEPTION |
---|
1189 | xReadUnaryMaxSymbol( uiSymbol, pcCU->getSlice()->getNumRefIdx( eRefList )-2 - uiRefFrmIdxMinus ); |
---|
1190 | #else |
---|
1191 | xReadUnaryMaxSymbol( uiSymbol, pcCU->getSlice()->getNumRefIdx( eRefList )-2 ); |
---|
1192 | #endif |
---|
1193 | |
---|
1194 | uiSymbol++; |
---|
1195 | } |
---|
1196 | riRefFrmIdx = uiSymbol; |
---|
1197 | #if MS_LCEC_LOOKUP_TABLE_EXCEPTION |
---|
1198 | riRefFrmIdx += uiRefFrmIdxMinus; |
---|
1199 | #endif |
---|
1200 | |
---|
1201 | return; |
---|
1202 | } |
---|
1203 | |
---|
1204 | Void TDecCavlc::parseMvd( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiPartIdx, UInt uiDepth, RefPicList eRefList ) |
---|
1205 | { |
---|
1206 | Int iHor, iVer; |
---|
1207 | UInt uiAbsPartIdxL, uiAbsPartIdxA; |
---|
1208 | Int iHorPred, iVerPred; |
---|
1209 | |
---|
1210 | TComDataCU* pcCUL = pcCU->getPULeft ( uiAbsPartIdxL, pcCU->getZorderIdxInCU() + uiAbsPartIdx ); |
---|
1211 | TComDataCU* pcCUA = pcCU->getPUAbove( uiAbsPartIdxA, pcCU->getZorderIdxInCU() + uiAbsPartIdx ); |
---|
1212 | |
---|
1213 | TComCUMvField* pcCUMvFieldL = ( pcCUL == NULL || pcCUL->isIntra( uiAbsPartIdxL ) ) ? NULL : pcCUL->getCUMvField( eRefList ); |
---|
1214 | TComCUMvField* pcCUMvFieldA = ( pcCUA == NULL || pcCUA->isIntra( uiAbsPartIdxA ) ) ? NULL : pcCUA->getCUMvField( eRefList ); |
---|
1215 | |
---|
1216 | iHorPred = ( (pcCUMvFieldL == NULL) ? 0 : pcCUMvFieldL->getMvd( uiAbsPartIdxL ).getAbsHor() ) + |
---|
1217 | ( (pcCUMvFieldA == NULL) ? 0 : pcCUMvFieldA->getMvd( uiAbsPartIdxA ).getAbsHor() ); |
---|
1218 | iVerPred = ( (pcCUMvFieldL == NULL) ? 0 : pcCUMvFieldL->getMvd( uiAbsPartIdxL ).getAbsVer() ) + |
---|
1219 | ( (pcCUMvFieldA == NULL) ? 0 : pcCUMvFieldA->getMvd( uiAbsPartIdxA ).getAbsVer() ); |
---|
1220 | |
---|
1221 | TComMv cTmpMv( 0, 0 ); |
---|
1222 | pcCU->getCUMvField( eRefList )->setAllMv( cTmpMv, pcCU->getPartitionSize( uiAbsPartIdx ), uiAbsPartIdx, uiPartIdx, uiDepth ); |
---|
1223 | |
---|
1224 | xReadSvlc( iHor ); |
---|
1225 | xReadSvlc( iVer ); |
---|
1226 | |
---|
1227 | // set mvd |
---|
1228 | TComMv cMv( iHor, iVer ); |
---|
1229 | pcCU->getCUMvField( eRefList )->setAllMvd( cMv, pcCU->getPartitionSize( uiAbsPartIdx ), uiAbsPartIdx, uiPartIdx, uiDepth ); |
---|
1230 | |
---|
1231 | return; |
---|
1232 | } |
---|
1233 | |
---|
1234 | Void TDecCavlc::parseDeltaQP( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth ) |
---|
1235 | { |
---|
1236 | UInt uiDQp; |
---|
1237 | Int iDQp; |
---|
1238 | |
---|
1239 | xReadFlag( uiDQp ); |
---|
1240 | |
---|
1241 | if ( uiDQp == 0 ) |
---|
1242 | { |
---|
1243 | uiDQp = pcCU->getSlice()->getSliceQp(); |
---|
1244 | } |
---|
1245 | else |
---|
1246 | { |
---|
1247 | xReadSvlc( iDQp ); |
---|
1248 | uiDQp = pcCU->getSlice()->getSliceQp() + iDQp; |
---|
1249 | } |
---|
1250 | |
---|
1251 | pcCU->setQPSubParts( uiDQp, uiAbsPartIdx, uiDepth ); |
---|
1252 | } |
---|
1253 | |
---|
1254 | #if LCEC_CBP_YUV_ROOT |
---|
1255 | Void TDecCavlc::parseCbf( TComDataCU* pcCU, UInt uiAbsPartIdx, TextType eType, UInt uiTrDepth, UInt uiDepth ) |
---|
1256 | { |
---|
1257 | if (eType == TEXT_ALL) |
---|
1258 | { |
---|
1259 | UInt uiCbf,tmp; |
---|
1260 | UInt uiCBP,uiCbfY,uiCbfU,uiCbfV; |
---|
1261 | Int n,x,cx,y,cy; |
---|
1262 | |
---|
1263 | /* Start adaptation */ |
---|
1264 | n = pcCU->isIntra( uiAbsPartIdx ) ? 0 : 1; |
---|
1265 | UInt vlcn = g_auiCbpVlcNum[n][m_uiCbpVlcIdx[n]]; |
---|
1266 | tmp = xReadVlc( vlcn ); |
---|
1267 | uiCBP = m_uiCBPTableD[n][tmp]; |
---|
1268 | |
---|
1269 | /* Adapt LP table */ |
---|
1270 | cx = tmp; |
---|
1271 | cy = Max(0,cx-1); |
---|
1272 | x = uiCBP; |
---|
1273 | y = m_uiCBPTableD[n][cy]; |
---|
1274 | m_uiCBPTableD[n][cy] = x; |
---|
1275 | m_uiCBPTableD[n][cx] = y; |
---|
1276 | m_uiCbpVlcIdx[n] += cx == m_uiCbpVlcIdx[n] ? 0 : (cx < m_uiCbpVlcIdx[n] ? -1 : 1); |
---|
1277 | |
---|
1278 | uiCbfY = (uiCBP>>0)&1; |
---|
1279 | uiCbfU = (uiCBP>>1)&1; |
---|
1280 | uiCbfV = (uiCBP>>2)&1; |
---|
1281 | |
---|
1282 | uiCbf = pcCU->getCbf( uiAbsPartIdx, TEXT_LUMA ); |
---|
1283 | pcCU->setCbfSubParts( uiCbf | ( uiCbfY << uiTrDepth ), TEXT_LUMA, uiAbsPartIdx, uiDepth ); |
---|
1284 | |
---|
1285 | uiCbf = pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_U ); |
---|
1286 | pcCU->setCbfSubParts( uiCbf | ( uiCbfU << uiTrDepth ), TEXT_CHROMA_U, uiAbsPartIdx, uiDepth ); |
---|
1287 | |
---|
1288 | uiCbf = pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_V ); |
---|
1289 | pcCU->setCbfSubParts( uiCbf | ( uiCbfV << uiTrDepth ), TEXT_CHROMA_V, uiAbsPartIdx, uiDepth ); |
---|
1290 | } |
---|
1291 | } |
---|
1292 | |
---|
1293 | Void TDecCavlc::parseBlockCbf( TComDataCU* pcCU, UInt uiAbsPartIdx, TextType eType, UInt uiTrDepth, UInt uiDepth, UInt uiQPartNum ) |
---|
1294 | { |
---|
1295 | assert(uiTrDepth > 0); |
---|
1296 | UInt uiCbf4, uiCbf; |
---|
1297 | |
---|
1298 | #if QC_BLK_CBP |
---|
1299 | Int x,cx,y,cy; |
---|
1300 | UInt tmp; |
---|
1301 | |
---|
1302 | UInt n = (pcCU->isIntra(uiAbsPartIdx) && eType == TEXT_LUMA)? 0:1; |
---|
1303 | UInt vlcn = (n==0)?g_auiBlkCbpVlcNum[m_uiBlkCbpVlcIdx]:11; |
---|
1304 | |
---|
1305 | tmp = xReadVlc( vlcn ); |
---|
1306 | uiCbf4 = m_uiBlkCBPTableD[n][tmp]; |
---|
1307 | |
---|
1308 | cx = tmp; |
---|
1309 | cy = Max(0,cx-1); |
---|
1310 | x = uiCbf4; |
---|
1311 | y = m_uiBlkCBPTableD[n][cy]; |
---|
1312 | m_uiBlkCBPTableD[n][cy] = x; |
---|
1313 | m_uiBlkCBPTableD[n][cx] = y; |
---|
1314 | if(n==0) |
---|
1315 | m_uiBlkCbpVlcIdx += cx == m_uiBlkCbpVlcIdx ? 0 : (cx < m_uiBlkCbpVlcIdx ? -1 : 1); |
---|
1316 | |
---|
1317 | uiCbf4++; |
---|
1318 | #else |
---|
1319 | xReadCode(4, uiCbf4); |
---|
1320 | #endif |
---|
1321 | |
---|
1322 | uiCbf = pcCU->getCbf( uiAbsPartIdx, eType ); |
---|
1323 | pcCU->setCbfSubParts( uiCbf | ( ((uiCbf4>>3)&0x01) << uiTrDepth ), eType, uiAbsPartIdx, uiDepth ); uiAbsPartIdx += uiQPartNum; |
---|
1324 | uiCbf = pcCU->getCbf( uiAbsPartIdx, eType ); |
---|
1325 | pcCU->setCbfSubParts( uiCbf | ( ((uiCbf4>>2)&0x01) << uiTrDepth ), eType, uiAbsPartIdx, uiDepth ); uiAbsPartIdx += uiQPartNum; |
---|
1326 | uiCbf = pcCU->getCbf( uiAbsPartIdx, eType ); |
---|
1327 | pcCU->setCbfSubParts( uiCbf | ( ((uiCbf4>>1)&0x01) << uiTrDepth ), eType, uiAbsPartIdx, uiDepth ); uiAbsPartIdx += uiQPartNum; |
---|
1328 | uiCbf = pcCU->getCbf( uiAbsPartIdx, eType ); |
---|
1329 | pcCU->setCbfSubParts( uiCbf | ( (uiCbf4&0x01) << uiTrDepth ), eType, uiAbsPartIdx, uiDepth ); |
---|
1330 | |
---|
1331 | return; |
---|
1332 | } |
---|
1333 | #endif |
---|
1334 | |
---|
1335 | Void TDecCavlc::parseCoeffNxN( TComDataCU* pcCU, TCoeff* pcCoef, UInt uiAbsPartIdx, UInt uiWidth, UInt uiHeight, UInt uiDepth, TextType eTType ) |
---|
1336 | { |
---|
1337 | |
---|
1338 | if ( uiWidth > pcCU->getSlice()->getSPS()->getMaxTrSize() ) |
---|
1339 | { |
---|
1340 | uiWidth = pcCU->getSlice()->getSPS()->getMaxTrSize(); |
---|
1341 | uiHeight = pcCU->getSlice()->getSPS()->getMaxTrSize(); |
---|
1342 | } |
---|
1343 | UInt uiSize = uiWidth*uiHeight; |
---|
1344 | |
---|
1345 | // point to coefficient |
---|
1346 | TCoeff* piCoeff = pcCoef; |
---|
1347 | |
---|
1348 | // initialize scan |
---|
1349 | const UInt* pucScan; |
---|
1350 | |
---|
1351 | //UInt uiConvBit = g_aucConvertToBit[ Min(8,uiWidth) ]; |
---|
1352 | UInt uiConvBit = g_aucConvertToBit[ pcCU->isIntra( uiAbsPartIdx ) ? uiWidth : Min(8,uiWidth) ]; |
---|
1353 | pucScan = g_auiFrameScanXY [ uiConvBit + 1 ]; |
---|
1354 | |
---|
1355 | #if QC_MDCS |
---|
1356 | UInt uiBlkPos; |
---|
1357 | UInt uiLog2BlkSize = g_aucConvertToBit[ pcCU->isIntra( uiAbsPartIdx ) ? uiWidth : Min(8,uiWidth) ] + 2; |
---|
1358 | const UInt uiScanIdx = pcCU->getCoefScanIdx(uiAbsPartIdx, uiWidth, eTType==TEXT_LUMA, pcCU->isIntra(uiAbsPartIdx)); |
---|
1359 | #endif //QC_MDCS |
---|
1360 | |
---|
1361 | UInt uiDecodeDCCoeff = 0; |
---|
1362 | Int dcCoeff = 0; |
---|
1363 | if (pcCU->isIntra(uiAbsPartIdx)) |
---|
1364 | { |
---|
1365 | UInt uiAbsPartIdxL, uiAbsPartIdxA; |
---|
1366 | TComDataCU* pcCUL = pcCU->getPULeft (uiAbsPartIdxL, pcCU->getZorderIdxInCU() + uiAbsPartIdx); |
---|
1367 | TComDataCU* pcCUA = pcCU->getPUAbove(uiAbsPartIdxA, pcCU->getZorderIdxInCU() + uiAbsPartIdx); |
---|
1368 | if (pcCUL == NULL && pcCUA == NULL) |
---|
1369 | { |
---|
1370 | uiDecodeDCCoeff = 1; |
---|
1371 | dcCoeff = xReadVlc(eTType == TEXT_LUMA ? 3 : 1); |
---|
1372 | if (dcCoeff) |
---|
1373 | { |
---|
1374 | UInt sign; |
---|
1375 | xReadFlag(sign); |
---|
1376 | if (sign) |
---|
1377 | { |
---|
1378 | dcCoeff = -dcCoeff; |
---|
1379 | } |
---|
1380 | } |
---|
1381 | } |
---|
1382 | } |
---|
1383 | |
---|
1384 | UInt uiScanning; |
---|
1385 | |
---|
1386 | TCoeff scoeff[64]; |
---|
1387 | Int iBlockType; |
---|
1388 | if( uiSize == 2*2 ) |
---|
1389 | { |
---|
1390 | // hack: re-use 4x4 coding |
---|
1391 | #if QC_MOD_LCEC |
---|
1392 | if (eTType==TEXT_CHROMA_U || eTType==TEXT_CHROMA_V) |
---|
1393 | iBlockType = eTType-2; |
---|
1394 | else |
---|
1395 | iBlockType = 2 + ( pcCU->isIntra(uiAbsPartIdx) ? 0 : pcCU->getSlice()->getSliceType() ); |
---|
1396 | #else |
---|
1397 | iBlockType = pcCU->isIntra(uiAbsPartIdx) ? 0 : pcCU->getSlice()->getSliceType(); |
---|
1398 | #endif |
---|
1399 | xParseCoeff4x4( scoeff, iBlockType ); |
---|
1400 | |
---|
1401 | for (uiScanning=0; uiScanning<4; uiScanning++) |
---|
1402 | { |
---|
1403 | #if QC_MDCS |
---|
1404 | uiBlkPos = g_auiSigLastScan[uiScanIdx][uiLog2BlkSize-1][uiScanning]; |
---|
1405 | piCoeff[ uiBlkPos ] = scoeff[15-uiScanning]; |
---|
1406 | #else |
---|
1407 | piCoeff[ pucScan[ uiScanning ] ] = scoeff[15-uiScanning]; |
---|
1408 | #endif //QC_MDCS |
---|
1409 | } |
---|
1410 | } |
---|
1411 | else if ( uiSize == 4*4 ) |
---|
1412 | { |
---|
1413 | #if QC_MOD_LCEC |
---|
1414 | if (eTType==TEXT_CHROMA_U || eTType==TEXT_CHROMA_V) |
---|
1415 | iBlockType = eTType-2; |
---|
1416 | else |
---|
1417 | iBlockType = 2 + ( pcCU->isIntra(uiAbsPartIdx) ? 0 : pcCU->getSlice()->getSliceType() ); |
---|
1418 | #else |
---|
1419 | iBlockType = pcCU->isIntra(uiAbsPartIdx) ? 0 : pcCU->getSlice()->getSliceType(); |
---|
1420 | #endif |
---|
1421 | xParseCoeff4x4( scoeff, iBlockType ); |
---|
1422 | |
---|
1423 | for (uiScanning=0; uiScanning<16; uiScanning++) |
---|
1424 | { |
---|
1425 | #if QC_MDCS |
---|
1426 | uiBlkPos = g_auiSigLastScan[uiScanIdx][uiLog2BlkSize-1][uiScanning]; |
---|
1427 | piCoeff[ uiBlkPos ] = scoeff[15-uiScanning]; |
---|
1428 | #else |
---|
1429 | piCoeff[ pucScan[ uiScanning ] ] = scoeff[15-uiScanning]; |
---|
1430 | #endif //QC_MDCS |
---|
1431 | } |
---|
1432 | } |
---|
1433 | else if ( uiSize == 8*8 ) |
---|
1434 | { |
---|
1435 | if (eTType==TEXT_CHROMA_U || eTType==TEXT_CHROMA_V) //8x8 specific |
---|
1436 | iBlockType = eTType-2; |
---|
1437 | else |
---|
1438 | iBlockType = 2 + ( pcCU->isIntra(uiAbsPartIdx) ? 0 : pcCU->getSlice()->getSliceType() ); |
---|
1439 | xParseCoeff8x8( scoeff, iBlockType ); |
---|
1440 | |
---|
1441 | for (uiScanning=0; uiScanning<64; uiScanning++) |
---|
1442 | { |
---|
1443 | #if QC_MDCS |
---|
1444 | uiBlkPos = g_auiSigLastScan[uiScanIdx][uiLog2BlkSize-1][uiScanning]; |
---|
1445 | piCoeff[ uiBlkPos ] = scoeff[63-uiScanning]; |
---|
1446 | #else |
---|
1447 | piCoeff[ pucScan[ uiScanning ] ] = scoeff[63-uiScanning]; |
---|
1448 | #endif //QC_MDCS |
---|
1449 | } |
---|
1450 | |
---|
1451 | } |
---|
1452 | else |
---|
1453 | { |
---|
1454 | if (!pcCU->isIntra( uiAbsPartIdx )) |
---|
1455 | { |
---|
1456 | memset(piCoeff,0,sizeof(TCoeff)*uiSize); |
---|
1457 | if (eTType==TEXT_CHROMA_U || eTType==TEXT_CHROMA_V) |
---|
1458 | iBlockType = eTType-2; |
---|
1459 | else |
---|
1460 | iBlockType = 5 + ( pcCU->isIntra(uiAbsPartIdx) ? 0 : pcCU->getSlice()->getSliceType() ); |
---|
1461 | xParseCoeff8x8( scoeff, iBlockType ); |
---|
1462 | |
---|
1463 | for (uiScanning=0; uiScanning<64; uiScanning++) |
---|
1464 | { |
---|
1465 | #if QC_MDCS |
---|
1466 | uiBlkPos = g_auiSigLastScan[uiScanIdx][uiLog2BlkSize-1][uiScanning]; |
---|
1467 | uiBlkPos = (uiBlkPos/8)* uiWidth + uiBlkPos%8; |
---|
1468 | piCoeff[ uiBlkPos ] = scoeff[63-uiScanning]; |
---|
1469 | #else |
---|
1470 | piCoeff[(pucScan[uiScanning]/8)*uiWidth + (pucScan[uiScanning]%8)] = scoeff[63-uiScanning]; |
---|
1471 | #endif //QC_MDCS |
---|
1472 | } |
---|
1473 | return; |
---|
1474 | } |
---|
1475 | |
---|
1476 | if(pcCU->isIntra( uiAbsPartIdx )) |
---|
1477 | { |
---|
1478 | memset(piCoeff,0,sizeof(TCoeff)*uiSize); |
---|
1479 | |
---|
1480 | if (eTType==TEXT_CHROMA_U || eTType==TEXT_CHROMA_V) |
---|
1481 | iBlockType = eTType-2; |
---|
1482 | else |
---|
1483 | iBlockType = 5 + ( pcCU->isIntra(uiAbsPartIdx) ? 0 : pcCU->getSlice()->getSliceType() ); |
---|
1484 | xParseCoeff8x8( scoeff, iBlockType ); |
---|
1485 | |
---|
1486 | for (uiScanning=0; uiScanning<64; uiScanning++) |
---|
1487 | { |
---|
1488 | #if QC_MDCS |
---|
1489 | uiBlkPos = g_auiSigLastScan[uiScanIdx][uiLog2BlkSize-1][uiScanning]; |
---|
1490 | piCoeff[ uiBlkPos ] = scoeff[63-uiScanning]; |
---|
1491 | #else |
---|
1492 | piCoeff[ pucScan[ uiScanning ] ] = scoeff[63-uiScanning]; |
---|
1493 | #endif //QC_MDCS |
---|
1494 | } |
---|
1495 | } |
---|
1496 | } |
---|
1497 | |
---|
1498 | if (uiDecodeDCCoeff == 1) |
---|
1499 | { |
---|
1500 | piCoeff[0] = dcCoeff; |
---|
1501 | } |
---|
1502 | |
---|
1503 | return ; |
---|
1504 | } |
---|
1505 | |
---|
1506 | Void TDecCavlc::parseTransformSubdivFlag( UInt& ruiSubdivFlag, UInt uiLog2TransformBlockSize ) |
---|
1507 | { |
---|
1508 | xReadFlag( ruiSubdivFlag ); |
---|
1509 | } |
---|
1510 | |
---|
1511 | Void TDecCavlc::parseQtCbf( TComDataCU* pcCU, UInt uiAbsPartIdx, TextType eType, UInt uiTrDepth, UInt uiDepth ) |
---|
1512 | { |
---|
1513 | UInt uiSymbol; |
---|
1514 | xReadFlag( uiSymbol ); |
---|
1515 | pcCU->setCbfSubParts( uiSymbol << uiTrDepth, eType, uiAbsPartIdx, uiDepth ); |
---|
1516 | } |
---|
1517 | |
---|
1518 | Void TDecCavlc::parseQtRootCbf( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, UInt& uiQtRootCbf ) |
---|
1519 | { |
---|
1520 | UInt uiSymbol; |
---|
1521 | xReadFlag( uiSymbol ); |
---|
1522 | uiQtRootCbf = uiSymbol; |
---|
1523 | } |
---|
1524 | |
---|
1525 | Void TDecCavlc::parseAlfFlag (UInt& ruiVal) |
---|
1526 | { |
---|
1527 | xReadFlag( ruiVal ); |
---|
1528 | } |
---|
1529 | |
---|
1530 | #if TSB_ALF_HEADER |
---|
1531 | Void TDecCavlc::parseAlfFlagNum( UInt& ruiVal, UInt minValue, UInt depth ) |
---|
1532 | { |
---|
1533 | UInt uiLength = 0; |
---|
1534 | UInt maxValue = (minValue << (depth*2)); |
---|
1535 | UInt temp = maxValue - minValue; |
---|
1536 | for(UInt i=0; i<32; i++) |
---|
1537 | { |
---|
1538 | if(temp&0x1) |
---|
1539 | { |
---|
1540 | uiLength = i+1; |
---|
1541 | } |
---|
1542 | temp = (temp >> 1); |
---|
1543 | } |
---|
1544 | if(uiLength) |
---|
1545 | { |
---|
1546 | xReadCode( uiLength, ruiVal ); |
---|
1547 | } |
---|
1548 | else |
---|
1549 | { |
---|
1550 | ruiVal = 0; |
---|
1551 | } |
---|
1552 | ruiVal += minValue; |
---|
1553 | } |
---|
1554 | |
---|
1555 | Void TDecCavlc::parseAlfCtrlFlag( UInt &ruiAlfCtrlFlag ) |
---|
1556 | { |
---|
1557 | UInt uiSymbol; |
---|
1558 | xReadFlag( uiSymbol ); |
---|
1559 | ruiAlfCtrlFlag = uiSymbol; |
---|
1560 | } |
---|
1561 | #endif |
---|
1562 | |
---|
1563 | Void TDecCavlc::parseAlfUvlc (UInt& ruiVal) |
---|
1564 | { |
---|
1565 | xReadUvlc( ruiVal ); |
---|
1566 | } |
---|
1567 | |
---|
1568 | Void TDecCavlc::parseAlfSvlc (Int& riVal) |
---|
1569 | { |
---|
1570 | xReadSvlc( riVal ); |
---|
1571 | } |
---|
1572 | |
---|
1573 | |
---|
1574 | #if HHI_MRG |
---|
1575 | Void TDecCavlc::parseMergeFlag ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, UInt uiPUIdx ) |
---|
1576 | { |
---|
1577 | #if QC_LCEC_INTER_MODE |
---|
1578 | if (pcCU->getPartitionSize(uiAbsPartIdx) == SIZE_2Nx2N ) |
---|
1579 | return; |
---|
1580 | #endif |
---|
1581 | UInt uiSymbol; |
---|
1582 | xReadFlag( uiSymbol ); |
---|
1583 | pcCU->setMergeFlagSubParts( uiSymbol ? true : false, uiAbsPartIdx, uiPUIdx, uiDepth ); |
---|
1584 | } |
---|
1585 | |
---|
1586 | Void TDecCavlc::parseMergeIndex ( TComDataCU* pcCU, UInt& ruiMergeIndex, UInt uiAbsPartIdx, UInt uiDepth ) |
---|
1587 | { |
---|
1588 | Bool bLeftInvolved = false; |
---|
1589 | Bool bAboveInvolved = false; |
---|
1590 | Bool bCollocatedInvolved = false; |
---|
1591 | Bool bCornerInvolved = false; |
---|
1592 | #if !HHI_MRG_LCEC_FIX |
---|
1593 | Bool bCornerBLInvolved = false; |
---|
1594 | #endif |
---|
1595 | UInt uiNumCand = 0; |
---|
1596 | for( UInt uiIter = 0; uiIter < HHI_NUM_MRG_CAND; ++uiIter ) |
---|
1597 | { |
---|
1598 | if( pcCU->getNeighbourCandIdx( uiIter, uiAbsPartIdx ) == uiIter + 1 ) |
---|
1599 | { |
---|
1600 | uiNumCand++; |
---|
1601 | if( uiIter == 0 ) |
---|
1602 | { |
---|
1603 | bLeftInvolved = true; |
---|
1604 | } |
---|
1605 | else if( uiIter == 1 ) |
---|
1606 | { |
---|
1607 | bAboveInvolved = true; |
---|
1608 | } |
---|
1609 | else if( uiIter == 2 ) |
---|
1610 | { |
---|
1611 | bCollocatedInvolved = true; |
---|
1612 | } |
---|
1613 | else if( uiIter == 3 ) |
---|
1614 | { |
---|
1615 | bCornerInvolved = true; |
---|
1616 | } |
---|
1617 | #if !HHI_MRG_LCEC_FIX |
---|
1618 | else if( uiIter == 4 ) |
---|
1619 | { |
---|
1620 | bCornerBLInvolved = true; |
---|
1621 | } |
---|
1622 | #endif |
---|
1623 | } |
---|
1624 | } |
---|
1625 | assert( uiNumCand > 1 ); |
---|
1626 | #if HHI_MRG_LCEC_FIX |
---|
1627 | UInt uiUnaryIdx = 0; |
---|
1628 | for( ; uiUnaryIdx < uiNumCand - 1; ++uiUnaryIdx ) |
---|
1629 | { |
---|
1630 | UInt uiSymbol = 0; |
---|
1631 | xReadFlag( uiSymbol ); |
---|
1632 | if( uiSymbol == 0 ) |
---|
1633 | { |
---|
1634 | break; |
---|
1635 | } |
---|
1636 | } |
---|
1637 | if( !bLeftInvolved ) |
---|
1638 | { |
---|
1639 | ++uiUnaryIdx; |
---|
1640 | } |
---|
1641 | if( !bAboveInvolved && uiUnaryIdx >= 1 ) |
---|
1642 | { |
---|
1643 | ++uiUnaryIdx; |
---|
1644 | } |
---|
1645 | |
---|
1646 | if( !bCollocatedInvolved && uiUnaryIdx >= 2 ) |
---|
1647 | { |
---|
1648 | ++uiUnaryIdx; |
---|
1649 | } |
---|
1650 | if( !bCornerInvolved && uiUnaryIdx >= 3 ) |
---|
1651 | { |
---|
1652 | ++uiUnaryIdx; |
---|
1653 | } |
---|
1654 | ruiMergeIndex = uiUnaryIdx; |
---|
1655 | #else |
---|
1656 | UInt uiOffset = 0; |
---|
1657 | if( bAboveInvolved && !bCollocatedInvolved && !bCornerInvolved && !bCornerBLInvolved ) |
---|
1658 | { |
---|
1659 | uiOffset = 0; |
---|
1660 | } |
---|
1661 | else if( uiNumCand < 3 ) |
---|
1662 | { |
---|
1663 | uiOffset = 1; |
---|
1664 | } |
---|
1665 | else |
---|
1666 | { |
---|
1667 | uiOffset = 2; |
---|
1668 | } |
---|
1669 | UInt uiSymbol = 0; |
---|
1670 | xReadFlag( uiSymbol ); |
---|
1671 | |
---|
1672 | if( uiNumCand == 2 ) |
---|
1673 | { |
---|
1674 | if( !bCollocatedInvolved ) |
---|
1675 | { |
---|
1676 | if( !bCornerInvolved && !bCornerBLInvolved ) |
---|
1677 | { |
---|
1678 | ruiMergeIndex = uiSymbol; |
---|
1679 | } |
---|
1680 | else if( bAboveInvolved && bCornerInvolved) |
---|
1681 | { |
---|
1682 | ruiMergeIndex = ( uiSymbol == 1 ) ? 3 : 1; |
---|
1683 | } |
---|
1684 | else if( bAboveInvolved && bCornerBLInvolved) |
---|
1685 | { |
---|
1686 | ruiMergeIndex = ( uiSymbol == 1 ) ? 4 : 1; |
---|
1687 | } |
---|
1688 | else if( bCornerInvolved && bCornerBLInvolved ) |
---|
1689 | { |
---|
1690 | ruiMergeIndex = ( uiSymbol == 1 ) ? 4 : 3; |
---|
1691 | } |
---|
1692 | else if( !bAboveInvolved && !bCornerBLInvolved) |
---|
1693 | { |
---|
1694 | ruiMergeIndex = ( uiSymbol == 1 ) ? 3 : 0; |
---|
1695 | } |
---|
1696 | else if( !bAboveInvolved && !bCornerInvolved ) |
---|
1697 | { |
---|
1698 | ruiMergeIndex = ( uiSymbol == 1 ) ? 4 : 0; |
---|
1699 | } |
---|
1700 | } |
---|
1701 | else |
---|
1702 | { |
---|
1703 | if( bAboveInvolved ) |
---|
1704 | { |
---|
1705 | ruiMergeIndex = ( uiSymbol == 1 ) ? 2 : 1; |
---|
1706 | } |
---|
1707 | else if( bCornerInvolved ) |
---|
1708 | { |
---|
1709 | ruiMergeIndex = ( uiSymbol == 1 ) ? 3 : 2; |
---|
1710 | } |
---|
1711 | else if( bCornerBLInvolved ) |
---|
1712 | { |
---|
1713 | ruiMergeIndex = ( uiSymbol == 1 ) ? 4 : 2; |
---|
1714 | } |
---|
1715 | else |
---|
1716 | { |
---|
1717 | ruiMergeIndex = ( uiSymbol == 1 ) ? 2 : 0; |
---|
1718 | } |
---|
1719 | } |
---|
1720 | return; |
---|
1721 | } |
---|
1722 | else if( uiNumCand == 3 ) |
---|
1723 | { |
---|
1724 | if( uiSymbol == 0 ) |
---|
1725 | { |
---|
1726 | if( bLeftInvolved ) |
---|
1727 | { |
---|
1728 | ruiMergeIndex = 0; |
---|
1729 | } |
---|
1730 | else if( !bLeftInvolved && bAboveInvolved ) |
---|
1731 | { |
---|
1732 | ruiMergeIndex = 1; |
---|
1733 | } |
---|
1734 | else if(!bLeftInvolved && !bAboveInvolved ) |
---|
1735 | { |
---|
1736 | ruiMergeIndex = 2; |
---|
1737 | } |
---|
1738 | } |
---|
1739 | else |
---|
1740 | { |
---|
1741 | xReadFlag( uiSymbol ); |
---|
1742 | if( uiSymbol == 1 ) |
---|
1743 | { |
---|
1744 | if( bCornerBLInvolved ) |
---|
1745 | { |
---|
1746 | ruiMergeIndex = 4; |
---|
1747 | } |
---|
1748 | else if( !bCornerBLInvolved && bCornerInvolved ) |
---|
1749 | { |
---|
1750 | ruiMergeIndex = 3; |
---|
1751 | } |
---|
1752 | else if( !bCornerBLInvolved && !bCornerInvolved && bCollocatedInvolved ) |
---|
1753 | { |
---|
1754 | ruiMergeIndex = 2; |
---|
1755 | } |
---|
1756 | } |
---|
1757 | else |
---|
1758 | { |
---|
1759 | if( bLeftInvolved && bAboveInvolved ) |
---|
1760 | { |
---|
1761 | ruiMergeIndex = 1; |
---|
1762 | } |
---|
1763 | else if( ( ( !bLeftInvolved && bAboveInvolved) || ( bLeftInvolved && !bAboveInvolved ) )&& bCollocatedInvolved ) |
---|
1764 | { |
---|
1765 | ruiMergeIndex = 2; |
---|
1766 | } |
---|
1767 | else if( bCornerBLInvolved && bCornerInvolved ) |
---|
1768 | { |
---|
1769 | ruiMergeIndex = 3; |
---|
1770 | } |
---|
1771 | } |
---|
1772 | } |
---|
1773 | } |
---|
1774 | else //uiNumCand > 3 |
---|
1775 | { |
---|
1776 | if( uiSymbol == 1 ) |
---|
1777 | { |
---|
1778 | UInt uiAbove = 0; |
---|
1779 | xReadFlag( uiAbove ); |
---|
1780 | if( uiAbove == 0 ) |
---|
1781 | { |
---|
1782 | ruiMergeIndex = 1; |
---|
1783 | } |
---|
1784 | else |
---|
1785 | { |
---|
1786 | UInt uiCol = 0; |
---|
1787 | xReadFlag( uiCol ); |
---|
1788 | if( uiCol == 0 ) |
---|
1789 | { |
---|
1790 | ruiMergeIndex = 2; |
---|
1791 | } |
---|
1792 | else |
---|
1793 | { |
---|
1794 | UInt uiCorner = 0; |
---|
1795 | xReadFlag( uiCorner ); |
---|
1796 | if( uiCorner == 0 ) |
---|
1797 | { |
---|
1798 | ruiMergeIndex = 3; |
---|
1799 | } |
---|
1800 | else |
---|
1801 | { |
---|
1802 | ruiMergeIndex = 4; |
---|
1803 | } |
---|
1804 | } |
---|
1805 | } |
---|
1806 | } |
---|
1807 | else |
---|
1808 | { |
---|
1809 | ruiMergeIndex = 0; |
---|
1810 | } |
---|
1811 | } |
---|
1812 | #endif //HHI_MRG_LCEC_FIX |
---|
1813 | } |
---|
1814 | #endif //HHI_MRG |
---|
1815 | |
---|
1816 | // ==================================================================================================================== |
---|
1817 | // Protected member functions |
---|
1818 | // ==================================================================================================================== |
---|
1819 | |
---|
1820 | Void TDecCavlc::xReadCode (UInt uiLength, UInt& ruiCode) |
---|
1821 | { |
---|
1822 | assert ( uiLength > 0 ); |
---|
1823 | m_pcBitstream->read (uiLength, ruiCode); |
---|
1824 | } |
---|
1825 | |
---|
1826 | Void TDecCavlc::xReadUvlc( UInt& ruiVal) |
---|
1827 | { |
---|
1828 | UInt uiVal = 0; |
---|
1829 | UInt uiCode = 0; |
---|
1830 | UInt uiLength; |
---|
1831 | m_pcBitstream->read( 1, uiCode ); |
---|
1832 | |
---|
1833 | if( 0 == uiCode ) |
---|
1834 | { |
---|
1835 | uiLength = 0; |
---|
1836 | |
---|
1837 | while( ! ( uiCode & 1 )) |
---|
1838 | { |
---|
1839 | m_pcBitstream->read( 1, uiCode ); |
---|
1840 | uiLength++; |
---|
1841 | } |
---|
1842 | |
---|
1843 | m_pcBitstream->read( uiLength, uiVal ); |
---|
1844 | |
---|
1845 | uiVal += (1 << uiLength)-1; |
---|
1846 | } |
---|
1847 | |
---|
1848 | ruiVal = uiVal; |
---|
1849 | } |
---|
1850 | |
---|
1851 | Void TDecCavlc::xReadSvlc( Int& riVal) |
---|
1852 | { |
---|
1853 | UInt uiBits = 0; |
---|
1854 | m_pcBitstream->read( 1, uiBits ); |
---|
1855 | if( 0 == uiBits ) |
---|
1856 | { |
---|
1857 | UInt uiLength = 0; |
---|
1858 | |
---|
1859 | while( ! ( uiBits & 1 )) |
---|
1860 | { |
---|
1861 | m_pcBitstream->read( 1, uiBits ); |
---|
1862 | uiLength++; |
---|
1863 | } |
---|
1864 | |
---|
1865 | m_pcBitstream->read( uiLength, uiBits ); |
---|
1866 | |
---|
1867 | uiBits += (1 << uiLength); |
---|
1868 | riVal = ( uiBits & 1) ? -(Int)(uiBits>>1) : (Int)(uiBits>>1); |
---|
1869 | } |
---|
1870 | else |
---|
1871 | { |
---|
1872 | riVal = 0; |
---|
1873 | } |
---|
1874 | } |
---|
1875 | |
---|
1876 | Void TDecCavlc::xReadFlag (UInt& ruiCode) |
---|
1877 | { |
---|
1878 | m_pcBitstream->read( 1, ruiCode ); |
---|
1879 | } |
---|
1880 | |
---|
1881 | Void TDecCavlc::xReadUnaryMaxSymbol( UInt& ruiSymbol, UInt uiMaxSymbol ) |
---|
1882 | { |
---|
1883 | if (uiMaxSymbol == 0) |
---|
1884 | { |
---|
1885 | ruiSymbol = 0; |
---|
1886 | return; |
---|
1887 | } |
---|
1888 | |
---|
1889 | xReadFlag( ruiSymbol ); |
---|
1890 | |
---|
1891 | if (ruiSymbol == 0 || uiMaxSymbol == 1) |
---|
1892 | { |
---|
1893 | return; |
---|
1894 | } |
---|
1895 | |
---|
1896 | UInt uiSymbol = 0; |
---|
1897 | UInt uiCont; |
---|
1898 | |
---|
1899 | do |
---|
1900 | { |
---|
1901 | xReadFlag( uiCont ); |
---|
1902 | uiSymbol++; |
---|
1903 | } |
---|
1904 | while( uiCont && (uiSymbol < uiMaxSymbol-1) ); |
---|
1905 | |
---|
1906 | if( uiCont && (uiSymbol == uiMaxSymbol-1) ) |
---|
1907 | { |
---|
1908 | uiSymbol++; |
---|
1909 | } |
---|
1910 | |
---|
1911 | ruiSymbol = uiSymbol; |
---|
1912 | } |
---|
1913 | |
---|
1914 | Void TDecCavlc::xReadExGolombLevel( UInt& ruiSymbol ) |
---|
1915 | { |
---|
1916 | UInt uiSymbol ; |
---|
1917 | UInt uiCount = 0; |
---|
1918 | do |
---|
1919 | { |
---|
1920 | xReadFlag( uiSymbol ); |
---|
1921 | uiCount++; |
---|
1922 | } |
---|
1923 | while( uiSymbol && (uiCount != 13)); |
---|
1924 | |
---|
1925 | ruiSymbol = uiCount-1; |
---|
1926 | |
---|
1927 | if( uiSymbol ) |
---|
1928 | { |
---|
1929 | xReadEpExGolomb( uiSymbol, 0 ); |
---|
1930 | ruiSymbol += uiSymbol+1; |
---|
1931 | } |
---|
1932 | |
---|
1933 | return; |
---|
1934 | } |
---|
1935 | |
---|
1936 | Void TDecCavlc::xReadEpExGolomb( UInt& ruiSymbol, UInt uiCount ) |
---|
1937 | { |
---|
1938 | UInt uiSymbol = 0; |
---|
1939 | UInt uiBit = 1; |
---|
1940 | |
---|
1941 | |
---|
1942 | while( uiBit ) |
---|
1943 | { |
---|
1944 | xReadFlag( uiBit ); |
---|
1945 | uiSymbol += uiBit << uiCount++; |
---|
1946 | } |
---|
1947 | |
---|
1948 | uiCount--; |
---|
1949 | while( uiCount-- ) |
---|
1950 | { |
---|
1951 | xReadFlag( uiBit ); |
---|
1952 | uiSymbol += uiBit << uiCount; |
---|
1953 | } |
---|
1954 | |
---|
1955 | ruiSymbol = uiSymbol; |
---|
1956 | |
---|
1957 | return; |
---|
1958 | } |
---|
1959 | |
---|
1960 | UInt TDecCavlc::xGetBit() |
---|
1961 | { |
---|
1962 | UInt ruiCode; |
---|
1963 | m_pcBitstream->read( 1, ruiCode ); |
---|
1964 | return ruiCode; |
---|
1965 | } |
---|
1966 | |
---|
1967 | Int TDecCavlc::xReadVlc( Int n ) |
---|
1968 | { |
---|
1969 | #if QC_BLK_CBP |
---|
1970 | assert( n>=0 && n<=11 ); |
---|
1971 | #else |
---|
1972 | assert( n>=0 && n<=10 ); |
---|
1973 | #endif |
---|
1974 | |
---|
1975 | UInt zeroes=0, done=0, tmp; |
---|
1976 | UInt cw, bit; |
---|
1977 | UInt val = 0; |
---|
1978 | UInt first; |
---|
1979 | UInt lead = 0; |
---|
1980 | |
---|
1981 | if (n < 5) |
---|
1982 | { |
---|
1983 | while (!done && zeroes < 6) |
---|
1984 | { |
---|
1985 | xReadFlag( bit ); |
---|
1986 | if (bit) |
---|
1987 | { |
---|
1988 | if (n) |
---|
1989 | { |
---|
1990 | xReadCode( n, cw ); |
---|
1991 | } |
---|
1992 | else |
---|
1993 | { |
---|
1994 | cw = 0; |
---|
1995 | } |
---|
1996 | done = 1; |
---|
1997 | } |
---|
1998 | else |
---|
1999 | { |
---|
2000 | zeroes++; |
---|
2001 | } |
---|
2002 | } |
---|
2003 | if ( done ) |
---|
2004 | { |
---|
2005 | val = (zeroes<<n)+cw; |
---|
2006 | } |
---|
2007 | else |
---|
2008 | { |
---|
2009 | lead = n; |
---|
2010 | while (!done) |
---|
2011 | { |
---|
2012 | xReadFlag( first ); |
---|
2013 | if ( !first ) |
---|
2014 | { |
---|
2015 | lead++; |
---|
2016 | } |
---|
2017 | else |
---|
2018 | { |
---|
2019 | if ( lead ) |
---|
2020 | { |
---|
2021 | xReadCode( lead, tmp ); |
---|
2022 | } |
---|
2023 | else |
---|
2024 | { |
---|
2025 | tmp = 0; |
---|
2026 | } |
---|
2027 | val = 6 * (1 << n) + (1 << lead) + tmp - (1 << n); |
---|
2028 | done = 1; |
---|
2029 | } |
---|
2030 | } |
---|
2031 | } |
---|
2032 | } |
---|
2033 | else if (n < 8) |
---|
2034 | { |
---|
2035 | while (!done) |
---|
2036 | { |
---|
2037 | xReadFlag( bit ); |
---|
2038 | if ( bit ) |
---|
2039 | { |
---|
2040 | xReadCode( n-4, cw ); |
---|
2041 | done = 1; |
---|
2042 | } |
---|
2043 | else |
---|
2044 | { |
---|
2045 | zeroes++; |
---|
2046 | } |
---|
2047 | } |
---|
2048 | val = (zeroes<<(n-4))+cw; |
---|
2049 | } |
---|
2050 | else if (n == 8) |
---|
2051 | { |
---|
2052 | if ( xGetBit() ) |
---|
2053 | { |
---|
2054 | val = 0; |
---|
2055 | } |
---|
2056 | else if ( xGetBit() ) |
---|
2057 | { |
---|
2058 | val = 1; |
---|
2059 | } |
---|
2060 | else |
---|
2061 | { |
---|
2062 | val = 2; |
---|
2063 | } |
---|
2064 | } |
---|
2065 | else if (n == 9) |
---|
2066 | { |
---|
2067 | if ( xGetBit() ) |
---|
2068 | { |
---|
2069 | if ( xGetBit() ) |
---|
2070 | { |
---|
2071 | xReadCode(3, val); |
---|
2072 | val += 3; |
---|
2073 | } |
---|
2074 | else if ( xGetBit() ) |
---|
2075 | { |
---|
2076 | val = xGetBit() + 1; |
---|
2077 | } |
---|
2078 | else |
---|
2079 | { |
---|
2080 | val = 0; |
---|
2081 | } |
---|
2082 | } |
---|
2083 | else |
---|
2084 | { |
---|
2085 | while (!done) |
---|
2086 | { |
---|
2087 | xReadFlag( bit ); |
---|
2088 | if ( bit ) |
---|
2089 | { |
---|
2090 | xReadCode(4, cw); |
---|
2091 | done = 1; |
---|
2092 | } |
---|
2093 | else |
---|
2094 | { |
---|
2095 | zeroes++; |
---|
2096 | } |
---|
2097 | } |
---|
2098 | val = (zeroes<<4)+cw+11; |
---|
2099 | } |
---|
2100 | } |
---|
2101 | else if (n == 10) |
---|
2102 | { |
---|
2103 | while (!done) |
---|
2104 | { |
---|
2105 | xReadFlag( first ); |
---|
2106 | if ( !first ) |
---|
2107 | { |
---|
2108 | lead++; |
---|
2109 | } |
---|
2110 | else |
---|
2111 | { |
---|
2112 | if ( !lead ) |
---|
2113 | { |
---|
2114 | val = 0; |
---|
2115 | } |
---|
2116 | else |
---|
2117 | { |
---|
2118 | xReadCode(lead, val); |
---|
2119 | val += (1<<lead); |
---|
2120 | val--; |
---|
2121 | } |
---|
2122 | done = 1; |
---|
2123 | } |
---|
2124 | } |
---|
2125 | } |
---|
2126 | #if QC_BLK_CBP |
---|
2127 | else if (n == 11) |
---|
2128 | { |
---|
2129 | UInt code; |
---|
2130 | xReadCode(3, val); |
---|
2131 | if(val) |
---|
2132 | { |
---|
2133 | xReadCode(1, code); |
---|
2134 | val = (val<<1)|code; |
---|
2135 | val--; |
---|
2136 | } |
---|
2137 | } |
---|
2138 | #endif |
---|
2139 | |
---|
2140 | return val; |
---|
2141 | } |
---|
2142 | |
---|
2143 | Void TDecCavlc::xParseCoeff4x4( TCoeff* scoeff, Int n ) |
---|
2144 | { |
---|
2145 | Int i; |
---|
2146 | UInt sign; |
---|
2147 | Int tmp; |
---|
2148 | Int vlc,cn,this_pos; |
---|
2149 | Int maxrun; |
---|
2150 | Int last_position; |
---|
2151 | Int atable[5] = {4,6,14,28,0xfffffff}; |
---|
2152 | Int vlc_adaptive=0; |
---|
2153 | Int done; |
---|
2154 | LastCoeffStruct combo; |
---|
2155 | |
---|
2156 | #if QC_MOD_LCEC |
---|
2157 | Int nTab; |
---|
2158 | Int tr1; |
---|
2159 | nTab=max(0,n-2); |
---|
2160 | #endif |
---|
2161 | |
---|
2162 | for (i = 0; i < 16; i++) |
---|
2163 | { |
---|
2164 | scoeff[i] = 0; |
---|
2165 | } |
---|
2166 | |
---|
2167 | { |
---|
2168 | /* Get the last nonzero coeff */ |
---|
2169 | Int x,y,cx,cy,vlcNum; |
---|
2170 | Int vlcTable[8] = {2,2,2}; |
---|
2171 | |
---|
2172 | /* Decode according to current LP table */ |
---|
2173 | #if QC_MOD_LCEC |
---|
2174 | vlcNum = vlcTable[nTab]; |
---|
2175 | tmp = xReadVlc( vlcNum ); |
---|
2176 | cn = m_uiLPTableD4[nTab][tmp]; |
---|
2177 | #else |
---|
2178 | vlcNum = vlcTable[n]; |
---|
2179 | |
---|
2180 | tmp = xReadVlc( vlcNum ); |
---|
2181 | cn = m_uiLPTableD4[n][tmp]; |
---|
2182 | #endif |
---|
2183 | combo.level = (cn>15); |
---|
2184 | combo.last_pos = cn&0x0f; |
---|
2185 | |
---|
2186 | /* Adapt LP table */ |
---|
2187 | cx = tmp; |
---|
2188 | cy = Max( 0, cx-1 ); |
---|
2189 | x = cn; |
---|
2190 | #if QC_MOD_LCEC |
---|
2191 | y = m_uiLPTableD4[nTab][cy]; |
---|
2192 | m_uiLPTableD4[nTab][cy] = x; |
---|
2193 | m_uiLPTableD4[nTab][cx] = y; |
---|
2194 | #else |
---|
2195 | y = m_uiLPTableD4[n][cy]; |
---|
2196 | m_uiLPTableD4[n][cy] = x; |
---|
2197 | m_uiLPTableD4[n][cx] = y; |
---|
2198 | #endif |
---|
2199 | } |
---|
2200 | |
---|
2201 | if ( combo.level == 1 ) |
---|
2202 | { |
---|
2203 | tmp = xReadVlc( 0 ); |
---|
2204 | sign = tmp&1; |
---|
2205 | tmp = (tmp>>1)+2; |
---|
2206 | } |
---|
2207 | else |
---|
2208 | { |
---|
2209 | tmp = 1; |
---|
2210 | xReadFlag( sign ); |
---|
2211 | } |
---|
2212 | |
---|
2213 | #if QC_MOD_LCEC |
---|
2214 | if (tmp>1) |
---|
2215 | { |
---|
2216 | tr1=0; |
---|
2217 | } |
---|
2218 | else |
---|
2219 | { |
---|
2220 | tr1=1; |
---|
2221 | } |
---|
2222 | #endif |
---|
2223 | |
---|
2224 | if ( sign ) |
---|
2225 | { |
---|
2226 | tmp = -tmp; |
---|
2227 | } |
---|
2228 | |
---|
2229 | last_position = combo.last_pos; |
---|
2230 | this_pos = 15 - last_position; |
---|
2231 | scoeff[this_pos] = tmp; |
---|
2232 | i = this_pos; |
---|
2233 | i++; |
---|
2234 | |
---|
2235 | done = 0; |
---|
2236 | { |
---|
2237 | while (!done && i < 16) |
---|
2238 | { |
---|
2239 | maxrun = 15-i; |
---|
2240 | #if QC_MOD_LCEC |
---|
2241 | if(n==2) |
---|
2242 | vlc = g_auiVlcTable8x8Intra[maxrun]; |
---|
2243 | else |
---|
2244 | vlc = g_auiVlcTable8x8Inter[maxrun]; |
---|
2245 | #else |
---|
2246 | if (maxrun > 27) |
---|
2247 | { |
---|
2248 | maxrun = 28; |
---|
2249 | vlc = 3; |
---|
2250 | } |
---|
2251 | else |
---|
2252 | { |
---|
2253 | vlc = g_auiVlcTable8x8[maxrun]; |
---|
2254 | } |
---|
2255 | #endif |
---|
2256 | |
---|
2257 | /* Go into run mode */ |
---|
2258 | cn = xReadVlc( vlc ); |
---|
2259 | #if QC_MOD_LCEC |
---|
2260 | if(n==2) |
---|
2261 | { |
---|
2262 | xRunLevelIndInv(&combo, maxrun, g_auiLumaRunTr14x4[tr1][maxrun], cn); |
---|
2263 | } |
---|
2264 | else |
---|
2265 | #endif |
---|
2266 | { |
---|
2267 | combo = g_acstructLumaRun8x8[maxrun][cn]; |
---|
2268 | } |
---|
2269 | i += combo.last_pos; |
---|
2270 | /* No sign for last zeroes */ |
---|
2271 | if (i < 16) |
---|
2272 | { |
---|
2273 | if (combo.level == 1) |
---|
2274 | { |
---|
2275 | tmp = xReadVlc( 0 ); |
---|
2276 | sign = tmp&1; |
---|
2277 | tmp = (tmp>>1)+2; |
---|
2278 | done = 1; |
---|
2279 | } |
---|
2280 | else |
---|
2281 | { |
---|
2282 | tmp = 1; |
---|
2283 | xReadFlag( sign ); |
---|
2284 | } |
---|
2285 | if ( sign ) |
---|
2286 | { |
---|
2287 | tmp = -tmp; |
---|
2288 | } |
---|
2289 | scoeff[i] = tmp; |
---|
2290 | } |
---|
2291 | i++; |
---|
2292 | #if QC_MOD_LCEC |
---|
2293 | if (tr1>0 && tr1<MAX_TR1) |
---|
2294 | { |
---|
2295 | tr1++; |
---|
2296 | } |
---|
2297 | #endif |
---|
2298 | } |
---|
2299 | } |
---|
2300 | if (i < 16) |
---|
2301 | { |
---|
2302 | /* Get the rest in level mode */ |
---|
2303 | while ( i < 16 ) |
---|
2304 | { |
---|
2305 | tmp = xReadVlc( vlc_adaptive ); |
---|
2306 | if ( tmp > atable[vlc_adaptive] ) |
---|
2307 | { |
---|
2308 | vlc_adaptive++; |
---|
2309 | } |
---|
2310 | if ( tmp ) |
---|
2311 | { |
---|
2312 | xReadFlag( sign ); |
---|
2313 | if ( sign ) |
---|
2314 | { |
---|
2315 | tmp = -tmp; |
---|
2316 | } |
---|
2317 | } |
---|
2318 | scoeff[i] = tmp; |
---|
2319 | i++; |
---|
2320 | } |
---|
2321 | } |
---|
2322 | |
---|
2323 | return; |
---|
2324 | } |
---|
2325 | |
---|
2326 | #if QC_MOD_LCEC |
---|
2327 | |
---|
2328 | Void TDecCavlc::xRunLevelIndInv(LastCoeffStruct *combo, Int maxrun, UInt lrg1Pos, UInt cn) |
---|
2329 | { |
---|
2330 | int lev, run; |
---|
2331 | if (lrg1Pos>0) |
---|
2332 | { |
---|
2333 | if(cn < min(lrg1Pos, maxrun+2)) |
---|
2334 | { |
---|
2335 | lev = 0; |
---|
2336 | run = cn; |
---|
2337 | } |
---|
2338 | else if(cn < (maxrun<<1) + 4 - (Int)lrg1Pos) |
---|
2339 | { |
---|
2340 | if((cn+lrg1Pos)&1) |
---|
2341 | { |
---|
2342 | lev = 0; |
---|
2343 | run = (cn + lrg1Pos - 1) >> 1; |
---|
2344 | } |
---|
2345 | else |
---|
2346 | { |
---|
2347 | lev = 1; |
---|
2348 | run = (cn - lrg1Pos)>>1; |
---|
2349 | } |
---|
2350 | } |
---|
2351 | else |
---|
2352 | { |
---|
2353 | lev = 1; |
---|
2354 | run = cn - maxrun - 2; |
---|
2355 | } |
---|
2356 | } |
---|
2357 | else |
---|
2358 | { |
---|
2359 | if( cn & 1 ) |
---|
2360 | { |
---|
2361 | lev = 0; run = (cn-1)>>1; |
---|
2362 | } |
---|
2363 | else |
---|
2364 | { |
---|
2365 | run = cn >> 1; |
---|
2366 | lev = (run <= maxrun)?1:0; |
---|
2367 | } |
---|
2368 | } |
---|
2369 | combo->level = lev; |
---|
2370 | combo->last_pos = run; |
---|
2371 | } |
---|
2372 | #endif |
---|
2373 | |
---|
2374 | |
---|
2375 | Void TDecCavlc::xParseCoeff8x8(TCoeff* scoeff, int n) |
---|
2376 | { |
---|
2377 | Int i; |
---|
2378 | UInt sign; |
---|
2379 | Int tmp; |
---|
2380 | LastCoeffStruct combo; |
---|
2381 | Int vlc,cn,this_pos; |
---|
2382 | Int maxrun; |
---|
2383 | Int last_position; |
---|
2384 | Int atable[5] = {4,6,14,28,0xfffffff}; |
---|
2385 | Int vlc_adaptive=0; |
---|
2386 | Int done; |
---|
2387 | #if QC_MOD_LCEC |
---|
2388 | Int tr1; |
---|
2389 | #endif |
---|
2390 | |
---|
2391 | static const Int switch_thr[10] = {49,49,0,49,49,0,49,49,49,49}; |
---|
2392 | Int sum_big_coef = 0; |
---|
2393 | |
---|
2394 | for (i = 0; i < 64; i++) |
---|
2395 | { |
---|
2396 | scoeff[i] = 0; |
---|
2397 | } |
---|
2398 | |
---|
2399 | /* Get the last nonzero coeff */ |
---|
2400 | { |
---|
2401 | Int x,y,cx,cy,vlcNum; |
---|
2402 | |
---|
2403 | /* Decode according to current LP table */ |
---|
2404 | // ADAPT_VLC_NUM |
---|
2405 | vlcNum = g_auiLastPosVlcNum[n][Min(16,m_uiLastPosVlcIndex[n])]; |
---|
2406 | tmp = xReadVlc( vlcNum ); |
---|
2407 | cn = m_uiLPTableD8[n][tmp]; |
---|
2408 | combo.level = (cn>63); |
---|
2409 | combo.last_pos = cn&0x3f; |
---|
2410 | |
---|
2411 | /* Adapt LP table */ |
---|
2412 | cx = tmp; |
---|
2413 | cy = Max(0,cx-1); |
---|
2414 | x = cn; |
---|
2415 | y = m_uiLPTableD8[n][cy]; |
---|
2416 | m_uiLPTableD8[n][cy] = x; |
---|
2417 | m_uiLPTableD8[n][cx] = y; |
---|
2418 | // ADAPT_VLC_NUM |
---|
2419 | m_uiLastPosVlcIndex[n] += cx == m_uiLastPosVlcIndex[n] ? 0 : (cx < m_uiLastPosVlcIndex[n] ? -1 : 1); |
---|
2420 | } |
---|
2421 | |
---|
2422 | if (combo.level == 1) |
---|
2423 | { |
---|
2424 | tmp = xReadVlc( 0 ); |
---|
2425 | sign = tmp&1; |
---|
2426 | tmp = (tmp>>1)+2; |
---|
2427 | } |
---|
2428 | else |
---|
2429 | { |
---|
2430 | tmp = 1; |
---|
2431 | xReadFlag( sign ); |
---|
2432 | } |
---|
2433 | |
---|
2434 | #if QC_MOD_LCEC |
---|
2435 | if (tmp>1) |
---|
2436 | { |
---|
2437 | tr1=0; |
---|
2438 | } |
---|
2439 | else |
---|
2440 | { |
---|
2441 | tr1=1; |
---|
2442 | } |
---|
2443 | #endif |
---|
2444 | |
---|
2445 | if ( sign ) |
---|
2446 | { |
---|
2447 | tmp = -tmp; |
---|
2448 | } |
---|
2449 | |
---|
2450 | last_position = combo.last_pos; |
---|
2451 | this_pos = 63 - last_position; |
---|
2452 | scoeff[this_pos] = tmp; |
---|
2453 | i = this_pos; |
---|
2454 | i++; |
---|
2455 | |
---|
2456 | done = 0; |
---|
2457 | { |
---|
2458 | while (!done && i < 64) |
---|
2459 | { |
---|
2460 | maxrun = 63-i; |
---|
2461 | #if QC_MOD_LCEC |
---|
2462 | if (n == 2 || n == 5) |
---|
2463 | vlc = g_auiVlcTable8x8Intra[Min(maxrun,28)]; |
---|
2464 | else |
---|
2465 | vlc = g_auiVlcTable8x8Inter[Min(maxrun,28)]; |
---|
2466 | #else |
---|
2467 | if (maxrun > 27) |
---|
2468 | { |
---|
2469 | maxrun = 28; |
---|
2470 | vlc = 3; |
---|
2471 | } |
---|
2472 | else |
---|
2473 | { |
---|
2474 | vlc = g_auiVlcTable8x8[maxrun]; |
---|
2475 | } |
---|
2476 | #endif |
---|
2477 | |
---|
2478 | /* Go into run mode */ |
---|
2479 | cn = xReadVlc( vlc ); |
---|
2480 | #if QC_MOD_LCEC |
---|
2481 | if (n == 2 || n == 5) |
---|
2482 | xRunLevelIndInv(&combo, maxrun, g_auiLumaRunTr18x8[tr1][min(maxrun,28)], cn); |
---|
2483 | else |
---|
2484 | combo = g_acstructLumaRun8x8[Min(maxrun,28)][cn]; |
---|
2485 | #else |
---|
2486 | combo = g_acstructLumaRun8x8[maxrun][cn]; |
---|
2487 | #endif |
---|
2488 | i += combo.last_pos; |
---|
2489 | /* No sign for last zeroes */ |
---|
2490 | if (i < 64) |
---|
2491 | { |
---|
2492 | if (combo.level == 1) |
---|
2493 | { |
---|
2494 | tmp = xReadVlc( 0 ); |
---|
2495 | sign = tmp&1; |
---|
2496 | tmp = (tmp>>1)+2; |
---|
2497 | |
---|
2498 | sum_big_coef += tmp; |
---|
2499 | if (i > switch_thr[n] || sum_big_coef > 2) |
---|
2500 | { |
---|
2501 | done = 1; |
---|
2502 | } |
---|
2503 | } |
---|
2504 | else |
---|
2505 | { |
---|
2506 | tmp = 1; |
---|
2507 | xReadFlag( sign ); |
---|
2508 | } |
---|
2509 | if ( sign ) |
---|
2510 | { |
---|
2511 | tmp = -tmp; |
---|
2512 | } |
---|
2513 | scoeff[i] = tmp; |
---|
2514 | } |
---|
2515 | i++; |
---|
2516 | #if QC_MOD_LCEC |
---|
2517 | if (tr1==0 || combo.level != 0) |
---|
2518 | { |
---|
2519 | tr1=0; |
---|
2520 | } |
---|
2521 | else if( tr1 < MAX_TR1) |
---|
2522 | { |
---|
2523 | tr1++; |
---|
2524 | } |
---|
2525 | #endif |
---|
2526 | } |
---|
2527 | } |
---|
2528 | if (i < 64) |
---|
2529 | { |
---|
2530 | /* Get the rest in level mode */ |
---|
2531 | while (i<64) |
---|
2532 | { |
---|
2533 | tmp = xReadVlc( vlc_adaptive ); |
---|
2534 | |
---|
2535 | if (tmp>atable[vlc_adaptive]) |
---|
2536 | { |
---|
2537 | vlc_adaptive++; |
---|
2538 | } |
---|
2539 | if (tmp) |
---|
2540 | { |
---|
2541 | xReadFlag( sign ); |
---|
2542 | if ( sign ) |
---|
2543 | { |
---|
2544 | tmp = -tmp; |
---|
2545 | } |
---|
2546 | } |
---|
2547 | scoeff[i] = tmp; |
---|
2548 | i++; |
---|
2549 | } |
---|
2550 | } |
---|
2551 | return; |
---|
2552 | } |
---|