source: 3DVCSoftware/branches/HTM-5.1-dev0/source/Lib/TLibDecoder/TDecEntropy.cpp @ 292

Last change on this file since 292 was 292, checked in by tech, 12 years ago

Removed macros related to IV motion parameter prediction.

  • Property svn:eol-style set to native
File size: 41.5 KB
Line 
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-2012, ITU/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 ITU/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/** \file     TDecEntropy.cpp
35    \brief    entropy decoder class
36*/
37
38#include "TDecEntropy.h"
39
40//! \ingroup TLibDecoder
41//! \{
42
43Void TDecEntropy::setEntropyDecoder         ( TDecEntropyIf* p )
44{
45  m_pcEntropyDecoderIf = p;
46}
47
48#include "TLibCommon/TComAdaptiveLoopFilter.h"
49#include "TLibCommon/TComSampleAdaptiveOffset.h"
50
51Void TDecEntropy::decodeSkipFlag( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
52{
53  m_pcEntropyDecoderIf->parseSkipFlag( pcCU, uiAbsPartIdx, uiDepth );
54}
55
56/** decode merge flag
57 * \param pcSubCU
58 * \param uiAbsPartIdx
59 * \param uiDepth
60 * \param uiPUIdx
61 * \returns Void
62 */
63Void TDecEntropy::decodeMergeFlag( TComDataCU* pcSubCU, UInt uiAbsPartIdx, UInt uiDepth, UInt uiPUIdx )
64{ 
65  // at least one merge candidate exists
66  m_pcEntropyDecoderIf->parseMergeFlag( pcSubCU, uiAbsPartIdx, uiDepth, uiPUIdx );
67}
68
69#if LGE_ILLUCOMP_B0045
70Void TDecEntropy::decodeICFlag( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
71{
72  pcCU->setICFlagSubParts( false , uiAbsPartIdx, 0, uiDepth );
73
74  if (pcCU->isIntra(uiAbsPartIdx) || (pcCU->getSlice()->getViewId() == 0) 
75#if !LGE_ILLUCOMP_DEPTH_C0046
76      || pcCU->getSlice()->getSPS()->isDepth()
77#endif
78      )
79  {
80    return;
81  }
82
83  if(!pcCU->getSlice()->getApplyIC())
84    return;
85
86#if LGE_ILLUCOMP_DEPTH_C0046
87  if(pcCU->isICFlagRequired(uiAbsPartIdx, uiDepth)) //This modification is not needed after integrating JCT3V-C0137
88#else
89  if(pcCU->isICFlagRequired(uiAbsPartIdx))
90#endif
91    m_pcEntropyDecoderIf->parseICFlag( pcCU, uiAbsPartIdx, uiDepth );
92}
93#endif
94/** decode merge index
95 * \param pcCU
96 * \param uiPartIdx
97 * \param uiAbsPartIdx
98 * \param puhInterDirNeighbours pointer to list of inter direction from the casual neighbours
99 * \param pcMvFieldNeighbours pointer to list of motion vector field from the casual neighbours
100 * \param uiDepth
101 * \returns Void
102 */
103Void TDecEntropy::decodeMergeIndex( TComDataCU* pcCU, UInt uiPartIdx, UInt uiAbsPartIdx, PartSize eCUMode, UChar* puhInterDirNeighbours, TComMvField* pcMvFieldNeighbours, UInt uiDepth )
104{
105  UInt uiMergeIndex = 0;
106  m_pcEntropyDecoderIf->parseMergeIndex( pcCU, uiMergeIndex, uiAbsPartIdx, uiDepth );
107  pcCU->setMergeIndexSubParts( uiMergeIndex, uiAbsPartIdx, uiPartIdx, uiDepth );
108}
109
110#if HHI_INTER_VIEW_RESIDUAL_PRED && !MTK_MDIVRP_C0138
111Void
112TDecEntropy::decodeResPredFlag( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, TComDataCU* pcSubCU, UInt uiPUIdx )
113{
114  Bool  bResPredAvailable   = false;
115  Bool  bResPredFlag        = false;
116
117  Bool  bResPredAllowed     =                    (!pcCU->getSlice()->getSPS()->isDepth                () );
118  bResPredAllowed           = bResPredAllowed && ( pcCU->getSlice()->getSPS()->getViewId              () );
119  bResPredAllowed           = bResPredAllowed && ( pcCU->getSlice()->getSPS()->getMultiviewResPredMode() );
120  bResPredAllowed           = bResPredAllowed && (!pcCU->isIntra           ( uiAbsPartIdx )              );
121
122  // check if supported
123  if( bResPredAllowed )
124  {
125    bResPredAvailable       = pcSubCU->getResidualSamples( uiPUIdx , false  );
126  }
127
128  // read from bitstream
129  if( bResPredAvailable )
130  {
131#if LG_RESTRICTEDRESPRED_M24766
132    Int iPUResiPredShift[4];
133    pcCU->getPUResiPredShift(iPUResiPredShift, uiAbsPartIdx);
134    if(iPUResiPredShift[0] >= 0 || iPUResiPredShift[1] >= 0  || iPUResiPredShift[2] >= 0  || iPUResiPredShift[3] >= 0 )
135#endif
136    m_pcEntropyDecoderIf->parseResPredFlag( pcCU, bResPredFlag, uiAbsPartIdx, uiDepth );
137  }
138
139  // set data
140  pcCU->setResPredAvailSubParts ( bResPredAvailable, uiAbsPartIdx, uiPUIdx, uiDepth );
141  pcCU->setResPredFlagSubParts  ( bResPredFlag,      uiAbsPartIdx, uiPUIdx, uiDepth );
142}
143#endif
144
145Void TDecEntropy::decodeSplitFlag   ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
146{
147  m_pcEntropyDecoderIf->parseSplitFlag( pcCU, uiAbsPartIdx, uiDepth );
148}
149
150Void TDecEntropy::decodePredMode( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
151{
152  m_pcEntropyDecoderIf->parsePredMode( pcCU, uiAbsPartIdx, uiDepth );
153 
154#if RWTH_SDC_DLT_B0036
155  // if B-Slice, code SDC flag later
156  if( !pcCU->getSlice()->isInterB() && pcCU->isIntra(uiAbsPartIdx) && pcCU->getSlice()->getSPS()->isDepth() )
157  {
158    // decode SDC flag
159    decodeSDCFlag(pcCU, uiAbsPartIdx, uiDepth);
160  }
161#endif
162}
163
164Void TDecEntropy::decodePartSize( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
165{
166#if RWTH_SDC_DLT_B0036
167  if( !pcCU->getSlice()->isInterB() && pcCU->isIntra(uiAbsPartIdx) && pcCU->getSDCFlag(uiAbsPartIdx)  )
168  {
169    pcCU->setPartSizeSubParts( SIZE_2Nx2N, uiAbsPartIdx, uiDepth );
170    pcCU->setSizeSubParts( g_uiMaxCUWidth>>uiDepth, g_uiMaxCUHeight>>uiDepth, uiAbsPartIdx, uiDepth );
171    return;
172  }
173#endif
174 
175  m_pcEntropyDecoderIf->parsePartSize( pcCU, uiAbsPartIdx, uiDepth );
176 
177#if RWTH_SDC_DLT_B0036
178  if( pcCU->getSlice()->isInterB() && pcCU->getSlice()->getSPS()->isDepth() && pcCU->isIntra(uiAbsPartIdx) )
179  {
180    // decode SDC flag
181    decodeSDCFlag(pcCU, uiAbsPartIdx, uiDepth);
182   
183    if( pcCU->getSDCFlag(uiAbsPartIdx) )
184    {
185      // part size is also known for SDC intra
186      pcCU->setPartSizeSubParts( SIZE_2Nx2N, uiAbsPartIdx, uiDepth );
187      pcCU->setSizeSubParts( g_uiMaxCUWidth>>uiDepth, g_uiMaxCUHeight>>uiDepth, uiAbsPartIdx, uiDepth );
188    }
189  }
190#endif
191}
192
193Void TDecEntropy::decodePredInfo    ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, TComDataCU* pcSubCU )
194{
195#if RWTH_SDC_DLT_B0036
196  if( pcCU->getSDCFlag(uiAbsPartIdx) )
197  {
198    decodeSDCPredMode(pcCU, uiAbsPartIdx, uiDepth);
199    return;
200  }
201#endif
202 
203  PartSize eMode = pcCU->getPartitionSize( uiAbsPartIdx );
204 
205  if( pcCU->isIntra( uiAbsPartIdx ) )                                 // If it is Intra mode, encode intra prediction mode.
206  {
207    if( eMode == SIZE_NxN )                                         // if it is NxN size, encode 4 intra directions.
208    {
209      UInt uiPartOffset = ( pcCU->getPic()->getNumPartInCU() >> ( pcCU->getDepth(uiAbsPartIdx) << 1 ) ) >> 2;
210      // if it is NxN size, this size might be the smallest partition size.                                                         // if it is NxN size, this size might be the smallest partition size.
211      decodeIntraDirModeLuma( pcCU, uiAbsPartIdx,                  uiDepth+1 );
212      decodeIntraDirModeLuma( pcCU, uiAbsPartIdx + uiPartOffset,   uiDepth+1 );
213      decodeIntraDirModeLuma( pcCU, uiAbsPartIdx + uiPartOffset*2, uiDepth+1 );
214      decodeIntraDirModeLuma( pcCU, uiAbsPartIdx + uiPartOffset*3, uiDepth+1 );
215      decodeIntraDirModeChroma( pcCU, uiAbsPartIdx, uiDepth );
216    }
217    else                                                                // if it is not NxN size, encode 1 intra directions
218    {
219      decodeIntraDirModeLuma  ( pcCU, uiAbsPartIdx, uiDepth );
220      decodeIntraDirModeChroma( pcCU, uiAbsPartIdx, uiDepth );
221    }
222  }
223  else                                                                // if it is Inter mode, encode motion vector and reference index
224  {
225    decodePUWise( pcCU, uiAbsPartIdx, uiDepth, pcSubCU );
226  }
227}
228
229/** Parse I_PCM information.
230 * \param pcCU  pointer to CUpointer to CU
231 * \param uiAbsPartIdx CU index
232 * \param uiDepth CU depth
233 * \returns Void
234 */
235Void TDecEntropy::decodeIPCMInfo( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
236{
237  if(!pcCU->getSlice()->getSPS()->getUsePCM()
238    || pcCU->getWidth(uiAbsPartIdx) > (1<<pcCU->getSlice()->getSPS()->getPCMLog2MaxSize())
239    || pcCU->getWidth(uiAbsPartIdx) < (1<<pcCU->getSlice()->getSPS()->getPCMLog2MinSize()) )
240  {
241    return;
242  }
243 
244#if RWTH_SDC_DLT_B0036
245  if( pcCU->getSDCFlag(uiAbsPartIdx) )
246  {
247    return;
248  }
249#endif
250 
251  m_pcEntropyDecoderIf->parseIPCMInfo( pcCU, uiAbsPartIdx, uiDepth );
252}
253
254Void TDecEntropy::decodeIntraDirModeLuma  ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
255{
256  m_pcEntropyDecoderIf->parseIntraDirLumaAng( pcCU, uiAbsPartIdx, uiDepth );
257}
258
259Void TDecEntropy::decodeIntraDirModeChroma( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
260{
261  m_pcEntropyDecoderIf->parseIntraDirChroma( pcCU, uiAbsPartIdx, uiDepth );
262}
263
264/** decode motion information for every PU block.
265 * \param pcCU
266 * \param uiAbsPartIdx
267 * \param uiDepth
268 * \param pcSubCU
269 * \returns Void
270 */
271Void TDecEntropy::decodePUWise( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, TComDataCU* pcSubCU )
272{
273  PartSize ePartSize = pcCU->getPartitionSize( uiAbsPartIdx );
274  UInt uiNumPU = ( ePartSize == SIZE_2Nx2N ? 1 : ( ePartSize == SIZE_NxN ? 4 : 2 ) );
275  UInt uiPUOffset = ( g_auiPUOffset[UInt( ePartSize )] << ( ( pcCU->getSlice()->getSPS()->getMaxCUDepth() - uiDepth ) << 1 ) ) >> 4;
276
277#if CU_BASED_MRG_CAND_LIST
278#if H3D_IVMP
279  TComMvField cMvFieldNeighbours[MRG_MAX_NUM_CANDS_MEM << 1]; // double length for mv of both lists
280  UChar uhInterDirNeighbours[MRG_MAX_NUM_CANDS_MEM];
281  for ( UInt ui = 0; ui < MRG_MAX_NUM_CANDS_MEM; ui++ )
282#else
283  TComMvField cMvFieldNeighbours[MRG_MAX_NUM_CANDS << 1]; // double length for mv of both lists
284  UChar uhInterDirNeighbours[MRG_MAX_NUM_CANDS];
285  for ( UInt ui = 0; ui < MRG_MAX_NUM_CANDS; ui++ )
286#endif
287  {
288    uhInterDirNeighbours[ui] = 0;
289  }
290  Int numValidMergeCand = 0;
291  bool isMerged = false;
292#endif
293
294  pcSubCU->copyInterPredInfoFrom( pcCU, uiAbsPartIdx, REF_PIC_LIST_0 );
295  pcSubCU->copyInterPredInfoFrom( pcCU, uiAbsPartIdx, REF_PIC_LIST_1 );
296  for ( UInt uiPartIdx = 0, uiSubPartIdx = uiAbsPartIdx; uiPartIdx < uiNumPU; uiPartIdx++, uiSubPartIdx += uiPUOffset )
297  {
298#if !CU_BASED_MRG_CAND_LIST
299#if H3D_IVMP
300    TComMvField cMvFieldNeighbours[MRG_MAX_NUM_CANDS_MEM << 1]; // double length for mv of both lists
301    UChar uhInterDirNeighbours[MRG_MAX_NUM_CANDS_MEM];
302    Int numValidMergeCand = 0;
303    for( UInt ui = 0; ui < MRG_MAX_NUM_CANDS_MEM; ++ui )
304#else
305    TComMvField cMvFieldNeighbours[MRG_MAX_NUM_CANDS << 1]; // double length for mv of both lists
306    UChar uhInterDirNeighbours[MRG_MAX_NUM_CANDS];
307    Int numValidMergeCand = 0;
308    for( UInt ui = 0; ui < MRG_MAX_NUM_CANDS; ++ui )
309#endif
310    {
311      uhInterDirNeighbours[ui] = 0;
312    }
313#endif
314    decodeMergeFlag( pcCU, uiSubPartIdx, uiDepth, uiPartIdx );
315    if ( pcCU->getMergeFlag( uiSubPartIdx ) )
316    {
317      decodeMergeIndex( pcCU, uiPartIdx, uiSubPartIdx, ePartSize, uhInterDirNeighbours, cMvFieldNeighbours, uiDepth );
318#if CU_BASED_MRG_CAND_LIST
319      UInt uiMergeIndex = pcCU->getMergeIndex(uiSubPartIdx);
320      if ( pcCU->getSlice()->getPPS()->getLog2ParallelMergeLevelMinus2() && ePartSize != SIZE_2Nx2N && pcSubCU->getWidth( 0 ) <= 8 ) 
321      {
322        pcSubCU->setPartSizeSubParts( SIZE_2Nx2N, 0, uiDepth );
323        if ( !isMerged )
324        {
325          pcSubCU->getInterMergeCandidates( 0, 0, uiDepth, cMvFieldNeighbours, uhInterDirNeighbours, numValidMergeCand );
326          isMerged = true;
327        }
328        pcSubCU->setPartSizeSubParts( ePartSize, 0, uiDepth );
329      }
330      else
331      {
332#if SIMP_MRG_PRUN
333        uiMergeIndex = pcCU->getMergeIndex(uiSubPartIdx);
334        pcSubCU->getInterMergeCandidates( uiSubPartIdx-uiAbsPartIdx, uiPartIdx, uiDepth, cMvFieldNeighbours, uhInterDirNeighbours, numValidMergeCand, uiMergeIndex );
335#else     
336        pcSubCU->getInterMergeCandidates( uiSubPartIdx-uiAbsPartIdx, uiPartIdx, uiDepth, cMvFieldNeighbours, uhInterDirNeighbours, numValidMergeCand );
337        uiMergeIndex = pcCU->getMergeIndex(uiSubPartIdx);
338#endif
339      }
340#else
341#if SIMP_MRG_PRUN       
342      UInt uiMergeIndex = pcCU->getMergeIndex(uiSubPartIdx);
343#if MERL_VSP_C0152
344      Int iVSPIndexTrue[3] = {-1, -1, -1};
345      pcSubCU->getInterMergeCandidates( uiSubPartIdx-uiAbsPartIdx, uiPartIdx, uiDepth, cMvFieldNeighbours, uhInterDirNeighbours, numValidMergeCand, iVSPIndexTrue, uiMergeIndex );
346
347#if HHI_MPI
348      if(pcCU->getTextureModeDepth( uiSubPartIdx ) == uiDepth)//MPI is used
349      {
350        TComDataCU *pcTextureCU = pcCU->getSlice()->getTexturePic()->getCU( pcCU->getAddr() );
351        UInt uiCurrPartNumb = pcCU->getPic()->getNumPartInCU() >> (uiDepth << 1);
352        for( UInt ui = 0; ui < uiCurrPartNumb; ui++ )
353        {
354          Int vspIdx = pcTextureCU->getVSPIndex( uiAbsPartIdx + ui);
355          pcCU->setVSPIndex( uiAbsPartIdx + ui, vspIdx);
356        }
357      }
358      else // MPI not used
359#endif
360      {
361        Int iVSPIdx = 0;
362        Int numVspIdx;
363        numVspIdx = 3;
364        for (Int i = 0; i < numVspIdx; i++)
365        {
366          if (iVSPIndexTrue[i] == uiMergeIndex)
367            {
368              iVSPIdx = i+1;
369              break;
370            }
371        }
372        pcCU->setVSPIndexSubParts( iVSPIdx, uiSubPartIdx, uiPartIdx, uiDepth );  //Initialize the VSP, may change later in get InterMergeCandidates()
373      }
374
375#else
376      pcSubCU->getInterMergeCandidates( uiSubPartIdx-uiAbsPartIdx, uiPartIdx, uiDepth, cMvFieldNeighbours, uhInterDirNeighbours, numValidMergeCand, uiMergeIndex );
377#endif
378#else     
379      pcSubCU->getInterMergeCandidates( uiSubPartIdx-uiAbsPartIdx, uiPartIdx, uiDepth, cMvFieldNeighbours, uhInterDirNeighbours, numValidMergeCand );
380      UInt uiMergeIndex = pcCU->getMergeIndex(uiSubPartIdx);
381#endif
382#endif
383      pcCU->setInterDirSubParts( uhInterDirNeighbours[uiMergeIndex], uiSubPartIdx, uiPartIdx, uiDepth );
384
385      TComMv cTmpMv( 0, 0 );
386      for ( UInt uiRefListIdx = 0; uiRefListIdx < 2; uiRefListIdx++ )
387      {       
388        if ( pcCU->getSlice()->getNumRefIdx( RefPicList( uiRefListIdx ) ) > 0 )
389        {
390          pcCU->setMVPIdxSubParts( 0, RefPicList( uiRefListIdx ), uiSubPartIdx, uiPartIdx, uiDepth);
391          pcCU->setMVPNumSubParts( 0, RefPicList( uiRefListIdx ), uiSubPartIdx, uiPartIdx, uiDepth);
392          pcCU->getCUMvField( RefPicList( uiRefListIdx ) )->setAllMvd( cTmpMv, ePartSize, uiSubPartIdx, uiDepth, uiPartIdx );
393          pcCU->getCUMvField( RefPicList( uiRefListIdx ) )->setAllMvField( cMvFieldNeighbours[ 2*uiMergeIndex + uiRefListIdx ], ePartSize, uiSubPartIdx, uiDepth, uiPartIdx );
394
395        }
396      }
397    }
398    else
399    {
400      decodeInterDirPU( pcCU, uiSubPartIdx, uiDepth, uiPartIdx );
401      for ( UInt uiRefListIdx = 0; uiRefListIdx < 2; uiRefListIdx++ )
402      {       
403        if ( pcCU->getSlice()->getNumRefIdx( RefPicList( uiRefListIdx ) ) > 0 )
404        {
405          decodeRefFrmIdxPU( pcCU,    uiSubPartIdx,              uiDepth, uiPartIdx, RefPicList( uiRefListIdx ) );
406          decodeMvdPU      ( pcCU,    uiSubPartIdx,              uiDepth, uiPartIdx, RefPicList( uiRefListIdx ) );
407          decodeMVPIdxPU   ( pcSubCU, uiSubPartIdx-uiAbsPartIdx, uiDepth, uiPartIdx, RefPicList( uiRefListIdx ) );
408        }
409      }
410    }
411  }
412  return;
413}
414
415/** decode inter direction for a PU block
416 * \param pcCU
417 * \param uiAbsPartIdx
418 * \param uiDepth
419 * \param uiPartIdx
420 * \returns Void
421 */
422Void TDecEntropy::decodeInterDirPU( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, UInt uiPartIdx )
423{
424  UInt uiInterDir;
425
426  if ( pcCU->getSlice()->isInterP() )
427  {
428    uiInterDir = 1;
429  }
430  else
431  {
432    m_pcEntropyDecoderIf->parseInterDir( pcCU, uiInterDir, uiAbsPartIdx, uiDepth );
433  }
434
435  pcCU->setInterDirSubParts( uiInterDir, uiAbsPartIdx, uiPartIdx, uiDepth );
436}
437
438Void TDecEntropy::decodeRefFrmIdxPU( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, UInt uiPartIdx, RefPicList eRefList )
439{
440  if(pcCU->getSlice()->getNumRefIdx(REF_PIC_LIST_C) > 0 && pcCU->getInterDir( uiAbsPartIdx ) != 3)
441  {
442    if(eRefList == REF_PIC_LIST_1)
443    {
444      return;
445    }
446
447    Int iRefFrmIdx = 0;
448    Int iRefFrmIdxTemp;
449    UInt uiInterDir;
450    RefPicList eRefListTemp;
451
452    PartSize ePartSize = pcCU->getPartitionSize( uiAbsPartIdx );
453
454    if ( pcCU->getSlice()->getNumRefIdx ( REF_PIC_LIST_C ) > 1 )
455    {
456      m_pcEntropyDecoderIf->parseRefFrmIdx( pcCU, iRefFrmIdx, uiAbsPartIdx, uiDepth, REF_PIC_LIST_C );
457    }
458    else
459    {
460      iRefFrmIdx=0;
461    }
462    uiInterDir = pcCU->getSlice()->getListIdFromIdxOfLC(iRefFrmIdx) + 1;
463    iRefFrmIdxTemp = pcCU->getSlice()->getRefIdxFromIdxOfLC(iRefFrmIdx);
464    eRefListTemp = (RefPicList)pcCU->getSlice()->getListIdFromIdxOfLC(iRefFrmIdx);
465
466    pcCU->getCUMvField( eRefListTemp )->setAllRefIdx( iRefFrmIdxTemp, ePartSize, uiAbsPartIdx, uiDepth, uiPartIdx );
467
468    pcCU->setInterDirSubParts( uiInterDir, uiAbsPartIdx, uiPartIdx, uiDepth );
469  }
470  else
471  {
472    Int iRefFrmIdx = 0;
473    Int iParseRefFrmIdx = pcCU->getInterDir( uiAbsPartIdx ) & ( 1 << eRefList );
474
475    if ( pcCU->getSlice()->getNumRefIdx( eRefList ) > 1 && iParseRefFrmIdx )
476    {
477      m_pcEntropyDecoderIf->parseRefFrmIdx( pcCU, iRefFrmIdx, uiAbsPartIdx, uiDepth, eRefList );
478    }
479    else if ( !iParseRefFrmIdx )
480    {
481      iRefFrmIdx = NOT_VALID;
482    }
483    else
484    {
485      iRefFrmIdx = 0;
486    }
487
488    PartSize ePartSize = pcCU->getPartitionSize( uiAbsPartIdx );
489    pcCU->getCUMvField( eRefList )->setAllRefIdx( iRefFrmIdx, ePartSize, uiAbsPartIdx, uiDepth, uiPartIdx );
490  }
491}
492
493/** decode motion vector difference for a PU block
494 * \param pcCU
495 * \param uiAbsPartIdx
496 * \param uiDepth
497 * \param uiPartIdx
498 * \param eRefList
499 * \returns Void
500 */
501Void TDecEntropy::decodeMvdPU( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, UInt uiPartIdx, RefPicList eRefList )
502{
503  if ( pcCU->getInterDir( uiAbsPartIdx ) & ( 1 << eRefList ) )
504  {
505    m_pcEntropyDecoderIf->parseMvd( pcCU, uiAbsPartIdx, uiPartIdx, uiDepth, eRefList );
506  }
507}
508
509Void TDecEntropy::decodeMVPIdxPU( TComDataCU* pcSubCU, UInt uiPartAddr, UInt uiDepth, UInt uiPartIdx, RefPicList eRefList )
510{
511  Int iMVPIdx = -1;
512
513  TComMv cZeroMv( 0, 0 );
514  TComMv cMv     = cZeroMv;
515  Int    iRefIdx = -1;
516
517  TComCUMvField* pcSubCUMvField = pcSubCU->getCUMvField( eRefList );
518  AMVPInfo* pAMVPInfo = pcSubCUMvField->getAMVPInfo();
519
520  iRefIdx = pcSubCUMvField->getRefIdx(uiPartAddr);
521  cMv = cZeroMv;
522
523  if ( (pcSubCU->getInterDir(uiPartAddr) & ( 1 << eRefList )) && (pcSubCU->getAMVPMode(uiPartAddr) == AM_EXPL) )
524  {
525#if H3D_IVMP
526    const Int iNumAMVPCands = AMVP_MAX_NUM_CANDS + ( pcSubCU->getSlice()->getSPS()->getMultiviewMvPredMode() ? 1 : 0 );
527    m_pcEntropyDecoderIf->parseMVPIdx( iMVPIdx, iNumAMVPCands );
528#else
529    m_pcEntropyDecoderIf->parseMVPIdx( iMVPIdx );
530#endif
531  }
532#if H3D_IVMP
533  pcSubCU->fillMvpCand(uiPartIdx, uiPartAddr, eRefList, iRefIdx, pAMVPInfo, iMVPIdx);
534#else
535  pcSubCU->fillMvpCand(uiPartIdx, uiPartAddr, eRefList, iRefIdx, pAMVPInfo);
536#endif
537  pcSubCU->setMVPNumSubParts(pAMVPInfo->iN, eRefList, uiPartAddr, uiPartIdx, uiDepth);
538  pcSubCU->setMVPIdxSubParts( iMVPIdx, eRefList, uiPartAddr, uiPartIdx, uiDepth );
539  if ( iRefIdx >= 0 )
540  {
541    m_pcPrediction->getMvPredAMVP( pcSubCU, uiPartIdx, uiPartAddr, eRefList, iRefIdx, cMv);
542    cMv += pcSubCUMvField->getMvd( uiPartAddr );
543  }
544
545  PartSize ePartSize = pcSubCU->getPartitionSize( uiPartAddr );
546  pcSubCU->getCUMvField( eRefList )->setAllMv(cMv, ePartSize, uiPartAddr, 0, uiPartIdx);
547}
548
549#if UNIFIED_TRANSFORM_TREE
550Void TDecEntropy::xDecodeTransform( TComDataCU* pcCU, UInt offsetLuma, UInt offsetChroma, UInt uiAbsPartIdx, UInt absTUPartIdx, UInt uiDepth, UInt width, UInt height, UInt uiTrIdx, UInt uiInnerQuadIdx, UInt& uiYCbfFront3, UInt& uiUCbfFront3, UInt& uiVCbfFront3, Bool& bCodeDQP )
551#else
552Void TDecEntropy::xDecodeTransformSubdiv( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt absTUPartIdx, UInt uiDepth, UInt uiInnerQuadIdx, UInt& uiYCbfFront3, UInt& uiUCbfFront3, UInt& uiVCbfFront3 )
553#endif
554{
555  UInt uiSubdiv;
556  const UInt uiLog2TrafoSize = g_aucConvertToBit[pcCU->getSlice()->getSPS()->getMaxCUWidth()]+2 - uiDepth;
557
558#if UNIFIED_TRANSFORM_TREE
559  if(uiTrIdx==0)
560  {
561    m_bakAbsPartIdxCU = uiAbsPartIdx;
562  }
563  if( uiLog2TrafoSize == 2 )
564  {
565    UInt partNum = pcCU->getPic()->getNumPartInCU() >> ( ( uiDepth - 1 ) << 1 );
566    if( ( uiAbsPartIdx % partNum ) == 0 )
567    {
568      m_uiBakAbsPartIdx   = uiAbsPartIdx;
569      m_uiBakChromaOffset = offsetChroma;
570    }
571  }
572#endif // UNIFIED_TRANSFORM_TREE
573  if( pcCU->getPredictionMode(uiAbsPartIdx) == MODE_INTRA && pcCU->getPartitionSize(uiAbsPartIdx) == SIZE_NxN && uiDepth == pcCU->getDepth(uiAbsPartIdx) )
574  {
575    uiSubdiv = 1;
576  }
577#if G519_TU_AMP_NSQT_HARMONIZATION
578  else if( (pcCU->getSlice()->getSPS()->getQuadtreeTUMaxDepthInter() == 1) && (pcCU->getPredictionMode(uiAbsPartIdx) == MODE_INTER) && ( pcCU->getPartitionSize(uiAbsPartIdx) != SIZE_2Nx2N ) && (uiDepth == pcCU->getDepth(uiAbsPartIdx)) )
579#else
580  else if( (pcCU->getSlice()->getSPS()->getQuadtreeTUMaxDepthInter() == 1) && (pcCU->getPredictionMode(uiAbsPartIdx) == MODE_INTER) && ( pcCU->getPartitionSize(uiAbsPartIdx) == SIZE_2NxN || pcCU->getPartitionSize(uiAbsPartIdx) == SIZE_Nx2N) && (uiDepth == pcCU->getDepth(uiAbsPartIdx)) )
581#endif
582  {
583    uiSubdiv = (uiLog2TrafoSize > pcCU->getQuadtreeTULog2MinSizeInCU(uiAbsPartIdx));
584  }
585  else if( uiLog2TrafoSize > pcCU->getSlice()->getSPS()->getQuadtreeTULog2MaxSize() )
586  {
587    uiSubdiv = 1;
588  }
589  else if( uiLog2TrafoSize == pcCU->getSlice()->getSPS()->getQuadtreeTULog2MinSize() )
590  {
591    uiSubdiv = 0;
592  }
593  else if( uiLog2TrafoSize == pcCU->getQuadtreeTULog2MinSizeInCU(uiAbsPartIdx) )
594  {
595    uiSubdiv = 0;
596  }
597  else
598  {
599    assert( uiLog2TrafoSize > pcCU->getQuadtreeTULog2MinSizeInCU(uiAbsPartIdx) );
600    m_pcEntropyDecoderIf->parseTransformSubdivFlag( uiSubdiv, uiDepth );
601  }
602 
603  const UInt uiTrDepth = uiDepth - pcCU->getDepth( uiAbsPartIdx );
604 
605  if( uiLog2TrafoSize <= pcCU->getSlice()->getSPS()->getQuadtreeTULog2MaxSize() )
606  {
607    const Bool bFirstCbfOfCU = uiLog2TrafoSize == pcCU->getSlice()->getSPS()->getQuadtreeTULog2MaxSize() || uiTrDepth == 0;
608    if( bFirstCbfOfCU )
609    {
610      pcCU->setCbfSubParts( 0, TEXT_CHROMA_U, uiAbsPartIdx, uiDepth );
611      pcCU->setCbfSubParts( 0, TEXT_CHROMA_V, uiAbsPartIdx, uiDepth );
612    }
613    if( bFirstCbfOfCU || uiLog2TrafoSize > 2 )
614    {
615      if( bFirstCbfOfCU || pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_U, uiTrDepth - 1 ) )
616      {
617        if ( uiInnerQuadIdx == 3 && uiUCbfFront3 == 0 && uiLog2TrafoSize < pcCU->getSlice()->getSPS()->getQuadtreeTULog2MaxSize() )
618        {
619          uiUCbfFront3++;
620          pcCU->setCbfSubParts( 1 << uiTrDepth, TEXT_CHROMA_U, uiAbsPartIdx, uiDepth );
621          //printf( " \nsave bits, U Cbf");
622        }
623        else
624        {
625          m_pcEntropyDecoderIf->parseQtCbf( pcCU, uiAbsPartIdx, TEXT_CHROMA_U, uiTrDepth, uiDepth );
626          uiUCbfFront3 += pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_U, uiTrDepth );
627        }
628      }
629      if( bFirstCbfOfCU || pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_V, uiTrDepth - 1 ) )
630      {
631        if ( uiInnerQuadIdx == 3 && uiVCbfFront3 == 0 && uiLog2TrafoSize < pcCU->getSlice()->getSPS()->getQuadtreeTULog2MaxSize() )
632        {
633          uiVCbfFront3++;
634          pcCU->setCbfSubParts( 1 << uiTrDepth, TEXT_CHROMA_V, uiAbsPartIdx, uiDepth );
635          //printf( " \nsave bits, V Cbf");
636        }
637        else
638        {
639          m_pcEntropyDecoderIf->parseQtCbf( pcCU, uiAbsPartIdx, TEXT_CHROMA_V, uiTrDepth, uiDepth );
640          uiVCbfFront3 += pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_V, uiTrDepth );
641        }
642      }
643    }
644    else
645    {
646      pcCU->setCbfSubParts( pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_U, uiTrDepth - 1 ) << uiTrDepth, TEXT_CHROMA_U, uiAbsPartIdx, uiDepth );
647      pcCU->setCbfSubParts( pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_V, uiTrDepth - 1 ) << uiTrDepth, TEXT_CHROMA_V, uiAbsPartIdx, uiDepth );
648      if ( uiLog2TrafoSize == 2 )
649      {
650        uiUCbfFront3 += pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_U, uiTrDepth );
651        uiVCbfFront3 += pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_V, uiTrDepth );
652      }
653    }
654  }
655 
656  if( uiSubdiv )
657  {
658#if UNIFIED_TRANSFORM_TREE
659    UInt size;
660    width  >>= 1;
661    height >>= 1;
662    size = width*height;
663    uiTrIdx++;
664#endif
665    ++uiDepth;
666    const UInt uiQPartNum = pcCU->getPic()->getNumPartInCU() >> (uiDepth << 1);
667    const UInt uiStartAbsPartIdx = uiAbsPartIdx;
668    UInt uiLumaTrMode, uiChromaTrMode;
669    pcCU->convertTransIdx( uiStartAbsPartIdx, uiTrDepth+1, uiLumaTrMode, uiChromaTrMode );
670    UInt uiYCbf = 0;
671    UInt uiUCbf = 0;
672    UInt uiVCbf = 0;
673   
674    UInt uiCurrentCbfY = 0;
675    UInt uiCurrentCbfU = 0;
676    UInt uiCurrentCbfV = 0;
677   
678    for( Int i = 0; i < 4; i++ )
679    {
680#if UNIFIED_TRANSFORM_TREE
681      UInt nsAddr = 0;
682      nsAddr = pcCU->getNSAbsPartIdx( uiLog2TrafoSize-1, uiAbsPartIdx, absTUPartIdx, i, uiTrDepth+1 );
683      xDecodeTransform( pcCU, offsetLuma, offsetChroma, uiAbsPartIdx, nsAddr, uiDepth, width, height, uiTrIdx, i, uiCurrentCbfY, uiCurrentCbfU, uiCurrentCbfV, bCodeDQP );
684#else
685      UInt nsAddr = 0;
686      nsAddr = pcCU->getNSAbsPartIdx( uiLog2TrafoSize-1, uiAbsPartIdx, absTUPartIdx, i, uiTrDepth+1 );
687      xDecodeTransformSubdiv( pcCU, uiAbsPartIdx, nsAddr, uiDepth, i, uiCurrentCbfY, uiCurrentCbfU, uiCurrentCbfV );
688#endif
689      uiYCbf |= pcCU->getCbf( uiAbsPartIdx, TEXT_LUMA, uiLumaTrMode );
690      uiUCbf |= pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_U, uiChromaTrMode );
691      uiVCbf |= pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_V, uiChromaTrMode );
692      uiAbsPartIdx += uiQPartNum;
693#if UNIFIED_TRANSFORM_TREE
694      offsetLuma += size;  offsetChroma += (size>>2);
695#endif
696    }
697   
698    uiYCbfFront3 += uiCurrentCbfY;
699    uiUCbfFront3 += uiCurrentCbfU;
700    uiVCbfFront3 += uiCurrentCbfV;
701   
702    pcCU->convertTransIdx( uiStartAbsPartIdx, uiTrDepth, uiLumaTrMode, uiChromaTrMode );
703    for( UInt ui = 0; ui < 4 * uiQPartNum; ++ui )
704    {
705      pcCU->getCbf( TEXT_LUMA     )[uiStartAbsPartIdx + ui] |= uiYCbf << uiLumaTrMode;
706      pcCU->getCbf( TEXT_CHROMA_U )[uiStartAbsPartIdx + ui] |= uiUCbf << uiChromaTrMode;
707      pcCU->getCbf( TEXT_CHROMA_V )[uiStartAbsPartIdx + ui] |= uiVCbf << uiChromaTrMode;
708    }
709  }
710  else
711  {
712    assert( uiDepth >= pcCU->getDepth( uiAbsPartIdx ) );
713    pcCU->setTrIdxSubParts( uiTrDepth, uiAbsPartIdx, uiDepth );
714   
715    {
716      DTRACE_CABAC_VL( g_nSymbolCounter++ );
717      DTRACE_CABAC_T( "\tTrIdx: abspart=" );
718      DTRACE_CABAC_V( uiAbsPartIdx );
719      DTRACE_CABAC_T( "\tdepth=" );
720      DTRACE_CABAC_V( uiDepth );
721      DTRACE_CABAC_T( "\ttrdepth=" );
722      DTRACE_CABAC_V( uiTrDepth );
723      DTRACE_CABAC_T( "\n" );
724    }
725   
726    UInt uiLumaTrMode, uiChromaTrMode;
727    pcCU->convertTransIdx( uiAbsPartIdx, uiTrDepth, uiLumaTrMode, uiChromaTrMode );
728    if(pcCU->getPredictionMode( uiAbsPartIdx ) == MODE_INTER && pcCU->useNonSquarePU( uiAbsPartIdx ) )
729    {
730      pcCU->setNSQTIdxSubParts( uiLog2TrafoSize, uiAbsPartIdx, absTUPartIdx, uiLumaTrMode );
731    }
732    pcCU->setCbfSubParts ( 0, TEXT_LUMA, uiAbsPartIdx, uiDepth );
733    if( pcCU->getPredictionMode(uiAbsPartIdx) != MODE_INTRA && uiDepth == pcCU->getDepth( uiAbsPartIdx ) && !pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_U, 0 ) && !pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_V, 0 ) )
734    {
735      pcCU->setCbfSubParts( 1 << uiLumaTrMode, TEXT_LUMA, uiAbsPartIdx, uiDepth );
736    }
737    else
738    {
739      const UInt uiLog2CUSize = g_aucConvertToBit[pcCU->getSlice()->getSPS()->getMaxCUWidth()] + 2 - pcCU->getDepth( uiAbsPartIdx );
740      if ( pcCU->getPredictionMode( uiAbsPartIdx ) != MODE_INTRA && uiInnerQuadIdx == 3 && uiYCbfFront3 == 0 && uiUCbfFront3 == 0 && uiVCbfFront3 == 0
741          && ( uiLog2CUSize <= pcCU->getSlice()->getSPS()->getQuadtreeTULog2MaxSize() + 1 || uiLog2TrafoSize < pcCU->getSlice()->getSPS()->getQuadtreeTULog2MaxSize() ) )
742      {
743        pcCU->setCbfSubParts( 1 << uiLumaTrMode, TEXT_LUMA, uiAbsPartIdx, uiDepth );
744        //printf( " \nsave bits, Y Cbf");
745        uiYCbfFront3++;   
746      }
747      else
748      {
749        m_pcEntropyDecoderIf->parseQtCbf( pcCU, uiAbsPartIdx, TEXT_LUMA, uiLumaTrMode, uiDepth );
750        uiYCbfFront3 += pcCU->getCbf( uiAbsPartIdx, TEXT_LUMA, uiLumaTrMode );
751      }
752    }
753#if UNIFIED_TRANSFORM_TREE
754    // transform_unit begin
755    UInt cbfY = pcCU->getCbf( uiAbsPartIdx, TEXT_LUMA    , uiTrIdx );
756    UInt cbfU = pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_U, uiTrIdx );
757    UInt cbfV = pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_V, uiTrIdx );
758    if( uiLog2TrafoSize == 2 )
759    {
760      UInt partNum = pcCU->getPic()->getNumPartInCU() >> ( ( uiDepth - 1 ) << 1 );
761      if( ( uiAbsPartIdx % partNum ) == (partNum - 1) )
762      {
763        cbfU = pcCU->getCbf( m_uiBakAbsPartIdx, TEXT_CHROMA_U, uiTrIdx );
764        cbfV = pcCU->getCbf( m_uiBakAbsPartIdx, TEXT_CHROMA_V, uiTrIdx );
765      }
766    }
767    if ( cbfY || cbfU || cbfV )
768    {
769      // dQP: only for LCU
770      if ( pcCU->getSlice()->getPPS()->getUseDQP() )
771      {
772        if ( bCodeDQP )
773        {
774          decodeQP( pcCU, m_bakAbsPartIdxCU);
775          bCodeDQP = false;
776        }
777      }
778    }
779    if( cbfY )
780    {
781      Int trWidth = width;
782      Int trHeight = height;
783      pcCU->getNSQTSize( uiTrIdx, uiAbsPartIdx, trWidth, trHeight );
784      m_pcEntropyDecoderIf->parseCoeffNxN( pcCU, (pcCU->getCoeffY()+offsetLuma), uiAbsPartIdx, trWidth, trHeight, uiDepth, TEXT_LUMA );
785    }
786    if( uiLog2TrafoSize > 2 )
787    {
788      Int trWidth = width >> 1;
789      Int trHeight = height >> 1;
790      pcCU->getNSQTSize( uiTrIdx, uiAbsPartIdx, trWidth, trHeight );
791      if( cbfU )
792      {
793        m_pcEntropyDecoderIf->parseCoeffNxN( pcCU, (pcCU->getCoeffCb()+offsetChroma), uiAbsPartIdx, trWidth, trHeight, uiDepth, TEXT_CHROMA_U );
794      }
795      if( cbfV )
796      {
797        m_pcEntropyDecoderIf->parseCoeffNxN( pcCU, (pcCU->getCoeffCr()+offsetChroma), uiAbsPartIdx, trWidth, trHeight, uiDepth, TEXT_CHROMA_V );
798      }
799    }
800    else
801    {
802      UInt partNum = pcCU->getPic()->getNumPartInCU() >> ( ( uiDepth - 1 ) << 1 );
803      if( ( uiAbsPartIdx % partNum ) == (partNum - 1) )
804      {
805        Int trWidth = width;
806        Int trHeight = height;
807        pcCU->getNSQTSize( uiTrIdx - 1, uiAbsPartIdx, trWidth, trHeight );
808        if( cbfU )
809        {
810          m_pcEntropyDecoderIf->parseCoeffNxN( pcCU, (pcCU->getCoeffCb()+m_uiBakChromaOffset), m_uiBakAbsPartIdx, trWidth, trHeight, uiDepth, TEXT_CHROMA_U );
811        }
812        if( cbfV )
813        {
814          m_pcEntropyDecoderIf->parseCoeffNxN( pcCU, (pcCU->getCoeffCr()+m_uiBakChromaOffset), m_uiBakAbsPartIdx, trWidth, trHeight, uiDepth, TEXT_CHROMA_V );
815        }
816      }
817    }
818    // transform_unit end
819#endif // UNIFIED_TRANSFORM_TREE
820  }
821}
822
823#if !UNIFIED_TRANSFORM_TREE
824Void TDecEntropy::decodeTransformIdx( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
825{
826  DTRACE_CABAC_VL( g_nSymbolCounter++ )
827  DTRACE_CABAC_T( "\tdecodeTransformIdx()\tCUDepth=" )
828  DTRACE_CABAC_V( uiDepth )
829  DTRACE_CABAC_T( "\n" )
830  UInt temp = 0;
831  UInt temp1 = 0;
832  UInt temp2 = 0;
833  xDecodeTransformSubdiv( pcCU, uiAbsPartIdx, uiAbsPartIdx, uiDepth, 0, temp, temp1, temp2 );
834}
835#endif // UNIFIED_TRANSFORM_TREE
836
837#if UNIFIED_TRANSFORM_TREE
838Void TDecEntropy::decodeQP          ( TComDataCU* pcCU, UInt uiAbsPartIdx )
839{
840  if ( pcCU->getSlice()->getPPS()->getUseDQP() )
841  {
842    m_pcEntropyDecoderIf->parseDeltaQP( pcCU, uiAbsPartIdx, pcCU->getDepth( uiAbsPartIdx ) );
843  }
844}
845#else
846Void TDecEntropy::decodeQP          ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
847{
848  if ( pcCU->getSlice()->getPPS()->getUseDQP() )
849  {
850    m_pcEntropyDecoderIf->parseDeltaQP( pcCU, uiAbsPartIdx, uiDepth );
851  }
852}
853#endif
854
855#if !UNIFIED_TRANSFORM_TREE
856Void TDecEntropy::xDecodeCoeff( TComDataCU* pcCU, UInt uiLumaOffset, UInt uiChromaOffset, UInt uiAbsPartIdx, UInt uiDepth, UInt uiWidth, UInt uiHeight, UInt uiTrIdx, UInt uiCurrTrIdx, Bool& bCodeDQP )
857{
858  UInt uiLog2TrSize = g_aucConvertToBit[ pcCU->getSlice()->getSPS()->getMaxCUWidth() >> uiDepth ] + 2;
859  UInt uiCbfY = pcCU->getCbf( uiAbsPartIdx, TEXT_LUMA, uiTrIdx );
860  UInt uiCbfU = pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_U, uiTrIdx );
861  UInt uiCbfV = pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_V, uiTrIdx );
862  if( uiLog2TrSize == 2 )
863  {
864    UInt uiQPDiv = pcCU->getPic()->getNumPartInCU() >> ( ( uiDepth - 1 ) << 1 );
865    if( ( uiAbsPartIdx % uiQPDiv ) == 0 )
866    {
867      m_uiBakAbsPartIdx   = uiAbsPartIdx;
868      m_uiBakChromaOffset = uiChromaOffset;
869    }
870    else if( ( uiAbsPartIdx % uiQPDiv ) == (uiQPDiv - 1) )
871    {
872      uiCbfU = pcCU->getCbf( m_uiBakAbsPartIdx, TEXT_CHROMA_U, uiTrIdx );
873      uiCbfV = pcCU->getCbf( m_uiBakAbsPartIdx, TEXT_CHROMA_V, uiTrIdx );
874    }
875  }
876
877  if ( uiCbfY || uiCbfU || uiCbfV )
878  {
879    // dQP: only for LCU
880    if ( pcCU->getSlice()->getPPS()->getUseDQP() )
881    {
882      if ( bCodeDQP )
883      {
884        decodeQP( pcCU, uiAbsPartIdx, uiDepth);
885        bCodeDQP = false;
886      }
887    }   
888    UInt uiLumaTrMode, uiChromaTrMode;
889    pcCU->convertTransIdx( uiAbsPartIdx, pcCU->getTransformIdx( uiAbsPartIdx ), uiLumaTrMode, uiChromaTrMode );
890    const UInt uiStopTrMode = uiLumaTrMode;
891   
892    if( uiTrIdx == uiStopTrMode )
893    {
894      if( pcCU->getCbf( uiAbsPartIdx, TEXT_LUMA, uiTrIdx ) )
895      {
896        Int trWidth = uiWidth;
897        Int trHeight = uiHeight;
898        pcCU->getNSQTSize( uiTrIdx, uiAbsPartIdx, trWidth, trHeight );
899        m_pcEntropyDecoderIf->parseCoeffNxN( pcCU, (pcCU->getCoeffY()+uiLumaOffset), uiAbsPartIdx, trWidth, trHeight, uiDepth, TEXT_LUMA );
900      }
901     
902      uiWidth  >>= 1;
903      uiHeight >>= 1;
904
905      if( uiLog2TrSize == 2 )
906      {
907        UInt uiQPDiv = pcCU->getPic()->getNumPartInCU() >> ( ( uiDepth - 1 ) << 1 );
908        if( ( uiAbsPartIdx % uiQPDiv ) == (uiQPDiv - 1) )
909        {
910          uiWidth  <<= 1;
911          uiHeight <<= 1;
912          Int trWidth = uiWidth;
913          Int trHeight = uiHeight;
914          pcCU->getNSQTSize( uiTrIdx-1, uiAbsPartIdx, trWidth, trHeight );
915          if( pcCU->getCbf( m_uiBakAbsPartIdx, TEXT_CHROMA_U, uiTrIdx ) )
916          {
917            m_pcEntropyDecoderIf->parseCoeffNxN( pcCU, (pcCU->getCoeffCb()+m_uiBakChromaOffset), m_uiBakAbsPartIdx, trWidth, trHeight, uiDepth, TEXT_CHROMA_U );
918          }
919          if( pcCU->getCbf( m_uiBakAbsPartIdx, TEXT_CHROMA_V, uiTrIdx ) )
920          {
921            m_pcEntropyDecoderIf->parseCoeffNxN( pcCU, (pcCU->getCoeffCr()+m_uiBakChromaOffset), m_uiBakAbsPartIdx, trWidth, trHeight, uiDepth, TEXT_CHROMA_V );
922          }
923        }
924      }
925      else
926      {
927        Int trWidth = uiWidth;
928        Int trHeight = uiHeight;
929        pcCU->getNSQTSize( uiTrIdx, uiAbsPartIdx, trWidth, trHeight );
930        if( pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_U, uiTrIdx ) )
931        {
932          m_pcEntropyDecoderIf->parseCoeffNxN( pcCU, (pcCU->getCoeffCb()+uiChromaOffset), uiAbsPartIdx, trWidth, trHeight, uiDepth, TEXT_CHROMA_U );
933        }
934        if( pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_V, uiTrIdx ) )
935        {
936          m_pcEntropyDecoderIf->parseCoeffNxN( pcCU, (pcCU->getCoeffCr()+uiChromaOffset), uiAbsPartIdx, trWidth, trHeight, uiDepth, TEXT_CHROMA_V );
937        }
938      }
939    }
940    else
941    {
942      {
943        DTRACE_CABAC_VL( g_nSymbolCounter++ );
944        DTRACE_CABAC_T( "\tgoing down\tdepth=" );
945        DTRACE_CABAC_V( uiDepth );
946        DTRACE_CABAC_T( "\ttridx=" );
947        DTRACE_CABAC_V( uiTrIdx );
948        DTRACE_CABAC_T( "\n" );
949      }
950      if( uiCurrTrIdx <= uiTrIdx )
951      {
952        assert(1);
953      }
954      UInt uiSize;
955      uiWidth  >>= 1;
956      uiHeight >>= 1;
957      uiSize = uiWidth*uiHeight;
958      uiDepth++;
959      uiTrIdx++;
960     
961      UInt uiQPartNum = pcCU->getPic()->getNumPartInCU() >> (uiDepth << 1);
962      UInt uiIdx      = uiAbsPartIdx;
963     
964      xDecodeCoeff( pcCU, uiLumaOffset, uiChromaOffset, uiIdx, uiDepth, uiWidth, uiHeight, uiTrIdx, uiCurrTrIdx, bCodeDQP );
965      uiLumaOffset += uiSize;  uiChromaOffset += (uiSize>>2);  uiIdx += uiQPartNum;
966     
967      xDecodeCoeff( pcCU, uiLumaOffset, uiChromaOffset, uiIdx, uiDepth, uiWidth, uiHeight, uiTrIdx, uiCurrTrIdx, bCodeDQP );
968      uiLumaOffset += uiSize;  uiChromaOffset += (uiSize>>2);  uiIdx += uiQPartNum;
969     
970      xDecodeCoeff( pcCU, uiLumaOffset, uiChromaOffset, uiIdx, uiDepth, uiWidth, uiHeight, uiTrIdx, uiCurrTrIdx, bCodeDQP );
971      uiLumaOffset += uiSize;  uiChromaOffset += (uiSize>>2);  uiIdx += uiQPartNum;
972     
973      xDecodeCoeff( pcCU, uiLumaOffset, uiChromaOffset, uiIdx, uiDepth, uiWidth, uiHeight, uiTrIdx, uiCurrTrIdx, bCodeDQP );
974      {
975        DTRACE_CABAC_VL( g_nSymbolCounter++ );
976        DTRACE_CABAC_T( "\tgoing up\n" );
977      }
978    }
979  }
980}
981#endif // !UNIFIED_TRANSFORM_TREE
982
983/** decode coefficients
984 * \param pcCU
985 * \param uiAbsPartIdx
986 * \param uiDepth
987 * \param uiWidth
988 * \param uiHeight
989 * \returns Void
990 */
991Void TDecEntropy::decodeCoeff( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, UInt uiWidth, UInt uiHeight, Bool& bCodeDQP )
992{
993  UInt uiMinCoeffSize = pcCU->getPic()->getMinCUWidth()*pcCU->getPic()->getMinCUHeight();
994  UInt uiLumaOffset   = uiMinCoeffSize*uiAbsPartIdx;
995  UInt uiChromaOffset = uiLumaOffset>>2;
996#if UNIFIED_TRANSFORM_TREE
997  UInt temp  = 0;
998  UInt temp1 = 0;
999  UInt temp2 = 0;
1000#else
1001  UInt uiLumaTrMode, uiChromaTrMode;
1002#endif
1003 
1004#if RWTH_SDC_DLT_B0036
1005  if( pcCU->getSDCAvailable(uiAbsPartIdx) && pcCU->getSDCFlag( uiAbsPartIdx ) )
1006  {
1007    assert( pcCU->getPartitionSize(uiAbsPartIdx) == SIZE_2Nx2N );
1008    assert( pcCU->getTransformIdx(uiAbsPartIdx) == 0 );
1009    assert( pcCU->getCbf(uiAbsPartIdx, TEXT_LUMA) == 1 );
1010    assert( pcCU->getCbf(uiAbsPartIdx, TEXT_CHROMA_U) == 1 );
1011    assert( pcCU->getCbf(uiAbsPartIdx, TEXT_CHROMA_V) == 1 );
1012   
1013    decodeSDCResidualData(pcCU, uiAbsPartIdx, uiDepth);
1014    return;
1015  }
1016#endif
1017 
1018  if( pcCU->isIntra(uiAbsPartIdx) )
1019  {
1020#if !UNIFIED_TRANSFORM_TREE
1021    decodeTransformIdx( pcCU, uiAbsPartIdx, pcCU->getDepth(uiAbsPartIdx) );
1022   
1023    pcCU->convertTransIdx( uiAbsPartIdx, pcCU->getTransformIdx(uiAbsPartIdx), uiLumaTrMode, uiChromaTrMode );
1024   
1025#endif // !UNIFIED_TRANSFORM_TREE
1026  }
1027  else
1028  {
1029    UInt uiQtRootCbf = 1;
1030#if HHI_MPI
1031    if( !(pcCU->getMergeFlag( uiAbsPartIdx ) && pcCU->getPartitionSize(uiAbsPartIdx) == SIZE_2Nx2N &&
1032          ( pcCU->getTextureModeDepth( uiAbsPartIdx ) == -1 || uiDepth == pcCU->getTextureModeDepth( uiAbsPartIdx ) ) ) )
1033#else
1034    if( !( pcCU->getPartitionSize( uiAbsPartIdx) == SIZE_2Nx2N && pcCU->getMergeFlag( uiAbsPartIdx ) ) )
1035#endif
1036    {
1037      m_pcEntropyDecoderIf->parseQtRootCbf( pcCU, uiAbsPartIdx, uiDepth, uiQtRootCbf );
1038    }
1039    if ( !uiQtRootCbf )
1040    {
1041      pcCU->setCbfSubParts( 0, 0, 0, uiAbsPartIdx, uiDepth );
1042      pcCU->setTrIdxSubParts( 0 , uiAbsPartIdx, uiDepth );
1043      pcCU->setNSQTIdxSubParts( uiAbsPartIdx, uiDepth );
1044      return;
1045    }
1046   
1047#if !UNIFIED_TRANSFORM_TREE
1048    decodeTransformIdx( pcCU, uiAbsPartIdx, pcCU->getDepth(uiAbsPartIdx) );
1049   
1050    pcCU->convertTransIdx( uiAbsPartIdx, pcCU->getTransformIdx(uiAbsPartIdx), uiLumaTrMode, uiChromaTrMode );
1051#endif // !UNIFIED_TRANSFORM_TREE
1052  }
1053
1054#if FIX_MPI_B0065
1055  if( pcCU->getPredictionMode(uiAbsPartIdx) == MODE_INTER && pcCU->getMergeFlag( uiAbsPartIdx ) && pcCU->getMergeIndex( uiAbsPartIdx ) == 0 && pcCU->getPartitionSize(uiAbsPartIdx) == SIZE_2Nx2N &&  pcCU->getTextureModeDepth( uiAbsPartIdx ) != -1  )
1056  {
1057    TComDataCU *pcTextureCU = pcCU->getSlice()->getTexturePic()->getCU( pcCU->getAddr() );
1058    if( uiDepth == pcTextureCU->getDepth(uiAbsPartIdx))
1059    {
1060      PartSize partSize = pcTextureCU->getPartitionSize(uiAbsPartIdx);
1061      pcCU->setPartSizeSubParts( partSize, uiAbsPartIdx, uiDepth );
1062    }
1063    else
1064    {
1065      pcCU->setPartSizeSubParts( SIZE_NxN, uiAbsPartIdx, uiDepth );
1066    }
1067  }
1068#endif
1069
1070#if UNIFIED_TRANSFORM_TREE
1071  xDecodeTransform( pcCU, uiLumaOffset, uiChromaOffset, uiAbsPartIdx, uiAbsPartIdx, uiDepth, uiWidth, uiHeight, 0, 0, temp, temp1, temp2, bCodeDQP );
1072#else // UNIFIED_TRANSFORM_TREE
1073  xDecodeCoeff( pcCU, uiLumaOffset, uiChromaOffset, uiAbsPartIdx, uiDepth, uiWidth, uiHeight, 0, uiLumaTrMode, bCodeDQP );
1074#endif // UNIFIED_TRANSFORM_TREE
1075
1076#if FIX_MPI_B0065
1077  if( pcCU->getPredictionMode(uiAbsPartIdx) == MODE_INTER && pcCU->getMergeFlag( uiAbsPartIdx ) && pcCU->getMergeIndex( uiAbsPartIdx ) == 0 && pcCU->getPartitionSize(uiAbsPartIdx) != SIZE_2Nx2N &&  pcCU->getTextureModeDepth( uiAbsPartIdx ) != -1 )
1078  {
1079    pcCU->setPartSizeSubParts( SIZE_2Nx2N, uiAbsPartIdx, uiDepth ); 
1080  }
1081#endif
1082}
1083
1084#if RWTH_SDC_DLT_B0036
1085Void TDecEntropy::decodeSDCPredMode( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
1086{
1087  assert( pcCU->getSlice()->getSPS()->isDepth() );
1088  assert( pcCU->getPartitionSize(uiAbsPartIdx) == SIZE_2Nx2N );
1089 
1090  m_pcEntropyDecoderIf->parseSDCPredMode(pcCU, uiAbsPartIdx, uiDepth );
1091}
1092
1093Void TDecEntropy::decodeSDCFlag( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
1094{
1095  assert( pcCU->getSlice()->getSPS()->isDepth() );
1096 
1097  m_pcEntropyDecoderIf->parseSDCFlag(pcCU, uiAbsPartIdx, uiDepth );
1098}
1099
1100Void TDecEntropy::decodeSDCResidualData( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
1101{
1102  assert( pcCU->getSlice()->getSPS()->isDepth() );
1103  assert( pcCU->getSDCFlag(uiAbsPartIdx) );
1104 
1105  // number of segments depends on prediction mode for INTRA
1106  UInt uiNumSegments = 2;
1107  UInt uiLumaPredMode = pcCU->getLumaIntraDir( uiAbsPartIdx );
1108  if( pcCU->getPredictionMode(uiAbsPartIdx) == MODE_INTRA && (uiLumaPredMode == DC_IDX || uiLumaPredMode == PLANAR_IDX) )
1109    uiNumSegments = 1;
1110 
1111  // decode residual data for each segment
1112  for( UInt uiSeg = 0; uiSeg < uiNumSegments; uiSeg++ )
1113    m_pcEntropyDecoderIf->parseSDCResidualData(pcCU, uiAbsPartIdx, uiDepth, uiSeg);
1114}
1115#endif
1116
1117//! \}
Note: See TracBrowser for help on using the repository browser.