source: 3DVCSoftware/trunk/source/Lib/TLibDecoder/TDecEntropy.cpp @ 773

Last change on this file since 773 was 773, checked in by tech, 10 years ago

Merged branch/9.2-dev0@722.

  • Property svn:eol-style set to native
File size: 27.7 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-2013, 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/TComSampleAdaptiveOffset.h"
49
50Void TDecEntropy::decodeSkipFlag( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
51{
52  m_pcEntropyDecoderIf->parseSkipFlag( pcCU, uiAbsPartIdx, uiDepth );
53}
54
55Void TDecEntropy::decodeCUTransquantBypassFlag(TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
56{
57  m_pcEntropyDecoderIf->parseCUTransquantBypassFlag( pcCU, uiAbsPartIdx, uiDepth );
58}
59
60/** decode merge flag
61 * \param pcSubCU
62 * \param uiAbsPartIdx
63 * \param uiDepth
64 * \param uiPUIdx
65 * \returns Void
66 */
67Void TDecEntropy::decodeMergeFlag( TComDataCU* pcSubCU, UInt uiAbsPartIdx, UInt uiDepth, UInt uiPUIdx )
68{ 
69  // at least one merge candidate exists
70  m_pcEntropyDecoderIf->parseMergeFlag( pcSubCU, uiAbsPartIdx, uiDepth, uiPUIdx );
71}
72
73/** decode merge index
74 * \param pcCU
75 * \param uiPartIdx
76 * \param uiAbsPartIdx
77 * \param puhInterDirNeighbours pointer to list of inter direction from the casual neighbours
78 * \param pcMvFieldNeighbours pointer to list of motion vector field from the casual neighbours
79 * \param uiDepth
80 * \returns Void
81 */
82Void TDecEntropy::decodeMergeIndex( TComDataCU* pcCU, UInt uiPartIdx, UInt uiAbsPartIdx, UInt uiDepth )
83{
84  UInt uiMergeIndex = 0;
85  m_pcEntropyDecoderIf->parseMergeIndex( pcCU, uiMergeIndex );
86  pcCU->setMergeIndexSubParts( uiMergeIndex, uiAbsPartIdx, uiPartIdx, uiDepth );
87}
88
89#if H_3D_ARP
90Void TDecEntropy::decodeARPW( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
91{
92  if( !pcCU->getSlice()->getARPStepNum() || pcCU->isIntra( uiAbsPartIdx ) )
93  {
94    return;
95  }
96
97  if( pcCU->getPartitionSize(uiAbsPartIdx) != SIZE_2Nx2N )
98  {
99    pcCU->setARPWSubParts( 0 , uiAbsPartIdx, uiDepth );
100  }
101  else
102  {
103    m_pcEntropyDecoderIf->parseARPW( pcCU , uiAbsPartIdx , uiDepth );
104  }
105}
106#endif
107
108#if H_3D_IC
109Void TDecEntropy::decodeICFlag( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
110{
111  pcCU->setICFlagSubParts( false , uiAbsPartIdx, 0, uiDepth );
112
113  if ( pcCU->isIntra( uiAbsPartIdx ) || ( pcCU->getSlice()->getViewIndex() == 0 ) || pcCU->getSlice()->getIsDepth() )
114  {
115    return;
116  }
117
118  if( !pcCU->getSlice()->getApplyIC() )
119    return;
120
121  if( pcCU->isICFlagRequired( uiAbsPartIdx ) )
122    m_pcEntropyDecoderIf->parseICFlag( pcCU, uiAbsPartIdx, uiDepth );
123}
124#endif
125
126Void TDecEntropy::decodeSplitFlag   ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
127{
128  m_pcEntropyDecoderIf->parseSplitFlag( pcCU, uiAbsPartIdx, uiDepth );
129}
130
131Void TDecEntropy::decodePredMode( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
132{
133  m_pcEntropyDecoderIf->parsePredMode( pcCU, uiAbsPartIdx, uiDepth );
134}
135
136Void TDecEntropy::decodePartSize( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
137{
138  m_pcEntropyDecoderIf->parsePartSize( pcCU, uiAbsPartIdx, uiDepth );
139}
140
141Void TDecEntropy::decodePredInfo    ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, TComDataCU* pcSubCU )
142{
143  if( pcCU->isIntra( uiAbsPartIdx ) )                                 // If it is Intra mode, encode intra prediction mode.
144  {
145    decodeIntraDirModeLuma  ( pcCU, uiAbsPartIdx, uiDepth );
146#if H_3D_DIM_SDC
147    if(!pcCU->getSDCFlag(uiAbsPartIdx))
148#endif
149    decodeIntraDirModeChroma( pcCU, uiAbsPartIdx, uiDepth );
150  }
151  else                                                                // if it is Inter mode, encode motion vector and reference index
152  {
153    decodePUWise( pcCU, uiAbsPartIdx, uiDepth, pcSubCU );
154  }
155}
156
157/** Parse I_PCM information.
158 * \param pcCU  pointer to CUpointer to CU
159 * \param uiAbsPartIdx CU index
160 * \param uiDepth CU depth
161 * \returns Void
162 */
163Void TDecEntropy::decodeIPCMInfo( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
164{
165  if(!pcCU->getSlice()->getSPS()->getUsePCM()
166    || pcCU->getWidth(uiAbsPartIdx) > (1<<pcCU->getSlice()->getSPS()->getPCMLog2MaxSize())
167    || pcCU->getWidth(uiAbsPartIdx) < (1<<pcCU->getSlice()->getSPS()->getPCMLog2MinSize()) )
168  {
169    return;
170  }
171#if H_3D_DIM_SDC
172  if( pcCU->getSDCFlag(uiAbsPartIdx) )
173  {
174    return;
175  }
176#endif
177 
178  m_pcEntropyDecoderIf->parseIPCMInfo( pcCU, uiAbsPartIdx, uiDepth );
179}
180
181Void TDecEntropy::decodeIntraDirModeLuma  ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
182{
183  m_pcEntropyDecoderIf->parseIntraDirLumaAng( pcCU, uiAbsPartIdx, uiDepth );
184}
185
186Void TDecEntropy::decodeIntraDirModeChroma( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
187{
188  m_pcEntropyDecoderIf->parseIntraDirChroma( pcCU, uiAbsPartIdx, uiDepth );
189}
190
191/** decode motion information for every PU block.
192 * \param pcCU
193 * \param uiAbsPartIdx
194 * \param uiDepth
195 * \param pcSubCU
196 * \returns Void
197 */
198Void TDecEntropy::decodePUWise( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, TComDataCU* pcSubCU )
199{
200  PartSize ePartSize = pcCU->getPartitionSize( uiAbsPartIdx );
201  UInt uiNumPU = ( ePartSize == SIZE_2Nx2N ? 1 : ( ePartSize == SIZE_NxN ? 4 : 2 ) );
202  UInt uiPUOffset = ( g_auiPUOffset[UInt( ePartSize )] << ( ( pcCU->getSlice()->getSPS()->getMaxCUDepth() - uiDepth ) << 1 ) ) >> 4;
203
204#if H_3D_IV_MERGE
205  TComMvField cMvFieldNeighbours[MRG_MAX_NUM_CANDS_MEM << 1]; // double length for mv of both lists
206  UChar uhInterDirNeighbours[MRG_MAX_NUM_CANDS_MEM];
207#else
208  TComMvField cMvFieldNeighbours[MRG_MAX_NUM_CANDS << 1]; // double length for mv of both lists
209  UChar uhInterDirNeighbours[MRG_MAX_NUM_CANDS];
210#endif
211#if H_3D_SPIVMP
212  Bool bSPIVMPFlag[MRG_MAX_NUM_CANDS_MEM];
213  TComMvField*  pcMvFieldSP;
214  UChar* puhInterDirSP;
215  pcMvFieldSP = new TComMvField[pcCU->getPic()->getPicSym()->getNumPartition()*2]; 
216  puhInterDirSP = new UChar[pcCU->getPic()->getPicSym()->getNumPartition()]; 
217#endif
218  for ( UInt ui = 0; ui < pcCU->getSlice()->getMaxNumMergeCand(); ui++ )
219  {
220    uhInterDirNeighbours[ui] = 0;
221  }
222  Int numValidMergeCand = 0;
223  Bool isMerged = false;
224
225  pcSubCU->copyInterPredInfoFrom( pcCU, uiAbsPartIdx, REF_PIC_LIST_0 );
226  pcSubCU->copyInterPredInfoFrom( pcCU, uiAbsPartIdx, REF_PIC_LIST_1 );
227#if H_3D_IV_MERGE
228  pcSubCU->copyDVInfoFrom( pcCU, uiAbsPartIdx);
229#endif
230  for ( UInt uiPartIdx = 0, uiSubPartIdx = uiAbsPartIdx; uiPartIdx < uiNumPU; uiPartIdx++, uiSubPartIdx += uiPUOffset )
231  {
232#if H_MV_ENC_DEC_TRAC
233    DTRACE_PU_S("=========== prediction_unit ===========\n")
234    // ToDo:
235    //DTRACE_PU("x0", uiLPelX)
236    //DTRACE_PU("x1", uiTPelY)
237#endif
238    decodeMergeFlag( pcCU, uiSubPartIdx, uiDepth, uiPartIdx );
239    if ( pcCU->getMergeFlag( uiSubPartIdx ) )
240    {
241      decodeMergeIndex( pcCU, uiPartIdx, uiSubPartIdx, uiDepth );
242      UInt uiMergeIndex = pcCU->getMergeIndex(uiSubPartIdx);
243#if H_3D_IC
244      decodeICFlag( pcCU, uiAbsPartIdx, uiDepth );
245#endif
246#if H_3D_ARP
247      decodeARPW  ( pcCU, uiAbsPartIdx, uiDepth );
248#endif
249      if ( pcCU->getSlice()->getPPS()->getLog2ParallelMergeLevelMinus2() && ePartSize != SIZE_2Nx2N && pcSubCU->getWidth( 0 ) <= 8 ) 
250      {
251        pcSubCU->setPartSizeSubParts( SIZE_2Nx2N, 0, uiDepth );
252        if ( !isMerged )
253        {
254#if H_3D_VSP
255          Int vspFlag[MRG_MAX_NUM_CANDS_MEM];
256          memset(vspFlag, 0, sizeof(Int)*MRG_MAX_NUM_CANDS_MEM);
257          InheritedVSPDisInfo inheritedVSPDisInfo[MRG_MAX_NUM_CANDS_MEM];
258#if H_3D_SPIVMP
259          memset(bSPIVMPFlag, false, sizeof(Bool)*MRG_MAX_NUM_CANDS_MEM);
260#endif
261          pcSubCU->initAvailableFlags();
262          pcSubCU->getInterMergeCandidates( 0, 0, cMvFieldNeighbours, uhInterDirNeighbours, numValidMergeCand);
263          pcSubCU->xGetInterMergeCandidates( 0, 0, cMvFieldNeighbours, uhInterDirNeighbours, vspFlag, inheritedVSPDisInfo
264#if H_3D_SPIVMP
265            , bSPIVMPFlag, pcMvFieldSP, puhInterDirSP
266#endif
267            , numValidMergeCand );
268          pcCU->setVSPFlagSubParts( vspFlag[uiMergeIndex], uiSubPartIdx, uiPartIdx, uiDepth );
269
270          if(vspFlag[uiMergeIndex])
271          {
272            pcCU->setDvInfoSubParts(inheritedVSPDisInfo[uiMergeIndex].m_acDvInfo, uiSubPartIdx, uiPartIdx, uiDepth);
273          }
274#else
275#if H_3D
276          pcSubCU->initAvailableFlags();
277          pcSubCU->getInterMergeCandidates( 0, 0, cMvFieldNeighbours, uhInterDirNeighbours, numValidMergeCand);
278          pcSubCU->xGetInterMergeCandidates( 0, 0, cMvFieldNeighbours, uhInterDirNeighbours, numValidMergeCand );
279
280#else
281          pcSubCU->getInterMergeCandidates( 0, 0, cMvFieldNeighbours, uhInterDirNeighbours, numValidMergeCand );
282#endif
283#endif
284          isMerged = true;
285        }
286        pcSubCU->setPartSizeSubParts( ePartSize, 0, uiDepth );
287      }
288      else
289      {
290        uiMergeIndex = pcCU->getMergeIndex(uiSubPartIdx);
291#if H_3D_VSP
292        Int vspFlag[MRG_MAX_NUM_CANDS_MEM];
293        memset(vspFlag, 0, sizeof(Int)*MRG_MAX_NUM_CANDS_MEM);
294        InheritedVSPDisInfo inheritedVSPDisInfo[MRG_MAX_NUM_CANDS_MEM];
295#if H_3D_SPIVMP
296        memset(bSPIVMPFlag, false, sizeof(Bool)*MRG_MAX_NUM_CANDS_MEM);
297#endif
298        pcSubCU->initAvailableFlags();
299        pcSubCU->getInterMergeCandidates( uiSubPartIdx-uiAbsPartIdx, uiPartIdx, cMvFieldNeighbours, uhInterDirNeighbours, numValidMergeCand, uiMergeIndex );
300        pcSubCU->xGetInterMergeCandidates( uiSubPartIdx-uiAbsPartIdx, uiPartIdx, cMvFieldNeighbours, uhInterDirNeighbours, vspFlag, inheritedVSPDisInfo
301#if H_3D_SPIVMP
302          , bSPIVMPFlag, pcMvFieldSP, puhInterDirSP
303#endif
304          ,numValidMergeCand, uiMergeIndex );
305        pcCU->setVSPFlagSubParts( vspFlag[uiMergeIndex], uiSubPartIdx, uiPartIdx, uiDepth );
306        if(vspFlag[uiMergeIndex])
307        {
308          pcCU->setDvInfoSubParts(inheritedVSPDisInfo[uiMergeIndex].m_acDvInfo, uiSubPartIdx, uiPartIdx, uiDepth);
309        }
310#else
311#if H_3D
312        pcSubCU->initAvailableFlags();
313        pcSubCU->getInterMergeCandidates( uiSubPartIdx-uiAbsPartIdx, uiPartIdx, cMvFieldNeighbours, uhInterDirNeighbours, numValidMergeCand, uiMergeIndex );
314        pcSubCU->xGetInterMergeCandidates( uiSubPartIdx-uiAbsPartIdx, uiPartIdx, cMvFieldNeighbours, uhInterDirNeighbours, numValidMergeCand, uiMergeIndex );
315#else
316        pcSubCU->getInterMergeCandidates( uiSubPartIdx-uiAbsPartIdx, uiPartIdx, cMvFieldNeighbours, uhInterDirNeighbours, numValidMergeCand, uiMergeIndex );
317#endif
318#endif
319      }
320      pcCU->setInterDirSubParts( uhInterDirNeighbours[uiMergeIndex], uiSubPartIdx, uiPartIdx, uiDepth );
321
322      TComMv cTmpMv( 0, 0 );
323      for ( UInt uiRefListIdx = 0; uiRefListIdx < 2; uiRefListIdx++ )
324      {       
325        if ( pcCU->getSlice()->getNumRefIdx( RefPicList( uiRefListIdx ) ) > 0 )
326        {
327          pcCU->setMVPIdxSubParts( 0, RefPicList( uiRefListIdx ), uiSubPartIdx, uiPartIdx, uiDepth);
328          pcCU->setMVPNumSubParts( 0, RefPicList( uiRefListIdx ), uiSubPartIdx, uiPartIdx, uiDepth);
329          pcCU->getCUMvField( RefPicList( uiRefListIdx ) )->setAllMvd( cTmpMv, ePartSize, uiSubPartIdx, uiDepth, uiPartIdx );
330          pcCU->getCUMvField( RefPicList( uiRefListIdx ) )->setAllMvField( cMvFieldNeighbours[ 2*uiMergeIndex + uiRefListIdx ], ePartSize, uiSubPartIdx, uiDepth, uiPartIdx );
331        }
332      }
333#if H_3D_SPIVMP
334      pcCU->setSPIVMPFlagSubParts(bSPIVMPFlag[uiMergeIndex], uiSubPartIdx, uiPartIdx, uiDepth ); 
335      if (bSPIVMPFlag[uiMergeIndex] != 0)
336      {
337        Int iWidth, iHeight;
338        UInt uiIdx;
339        pcCU->getPartIndexAndSize( uiPartIdx, uiIdx, iWidth, iHeight, uiSubPartIdx, true );
340
341        UInt uiSPAddr;
342
343        Int iNumSPInOneLine, iNumSP, iSPWidth, iSPHeight;
344
345        pcCU->getSPPara(iWidth, iHeight, iNumSP, iNumSPInOneLine, iSPWidth, iSPHeight);
346
347        for (Int iPartitionIdx = 0; iPartitionIdx < iNumSP; iPartitionIdx++)
348        {
349          pcCU->getSPAbsPartIdx(uiSubPartIdx, iSPWidth, iSPHeight, iPartitionIdx, iNumSPInOneLine, uiSPAddr);
350          pcCU->setInterDirSP(puhInterDirSP[iPartitionIdx], uiSPAddr, iSPWidth, iSPHeight);
351          pcCU->getCUMvField( REF_PIC_LIST_0 )->setMvFieldSP(pcCU, uiSPAddr, pcMvFieldSP[2*iPartitionIdx], iSPWidth, iSPHeight);
352          pcCU->getCUMvField( REF_PIC_LIST_1 )->setMvFieldSP(pcCU, uiSPAddr, pcMvFieldSP[2*iPartitionIdx + 1], iSPWidth, iSPHeight);
353        }
354      }
355#endif
356    }
357    else
358    {
359      decodeInterDirPU( pcCU, uiSubPartIdx, uiDepth, uiPartIdx );
360      for ( UInt uiRefListIdx = 0; uiRefListIdx < 2; uiRefListIdx++ )
361      {       
362        if ( pcCU->getSlice()->getNumRefIdx( RefPicList( uiRefListIdx ) ) > 0 )
363        {
364          decodeRefFrmIdxPU( pcCU,    uiSubPartIdx,              uiDepth, uiPartIdx, RefPicList( uiRefListIdx ) );
365          decodeMvdPU      ( pcCU,    uiSubPartIdx,              uiDepth, uiPartIdx, RefPicList( uiRefListIdx ) );
366          decodeMVPIdxPU   ( pcSubCU, uiSubPartIdx-uiAbsPartIdx, uiDepth, uiPartIdx, RefPicList( uiRefListIdx ) );
367        }
368      }
369#if H_3D_IC
370      decodeICFlag( pcCU, uiAbsPartIdx, uiDepth );
371#endif
372#if H_3D_ARP
373      decodeARPW  ( pcCU, uiAbsPartIdx, uiDepth );
374#endif
375    }
376#if H_3D_VSP
377    if ( (pcCU->getInterDir(uiSubPartIdx) == 3) && pcSubCU->isBipredRestriction(uiPartIdx) && (pcCU->getVSPFlag(uiSubPartIdx) == false))
378#else
379    if ( (pcCU->getInterDir(uiSubPartIdx) == 3) && pcSubCU->isBipredRestriction(uiPartIdx) )
380#endif
381    {
382      pcCU->getCUMvField( REF_PIC_LIST_1 )->setAllMv( TComMv(0,0), ePartSize, uiSubPartIdx, uiDepth, uiPartIdx);
383      pcCU->getCUMvField( REF_PIC_LIST_1 )->setAllRefIdx( -1, ePartSize, uiSubPartIdx, uiDepth, uiPartIdx);
384      pcCU->setInterDirSubParts( 1, uiSubPartIdx, uiPartIdx, uiDepth);
385    }
386  }
387#if H_3D_SPIVMP
388  delete[] pcMvFieldSP;
389  delete[] puhInterDirSP;
390#endif
391  return;
392}
393
394/** decode inter direction for a PU block
395 * \param pcCU
396 * \param uiAbsPartIdx
397 * \param uiDepth
398 * \param uiPartIdx
399 * \returns Void
400 */
401Void TDecEntropy::decodeInterDirPU( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, UInt uiPartIdx )
402{
403  UInt uiInterDir;
404
405  if ( pcCU->getSlice()->isInterP() )
406  {
407    uiInterDir = 1;
408  }
409  else
410  {
411    m_pcEntropyDecoderIf->parseInterDir( pcCU, uiInterDir, uiAbsPartIdx );
412  }
413
414  pcCU->setInterDirSubParts( uiInterDir, uiAbsPartIdx, uiPartIdx, uiDepth );
415}
416
417Void TDecEntropy::decodeRefFrmIdxPU( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, UInt uiPartIdx, RefPicList eRefList )
418{
419  Int iRefFrmIdx = 0;
420  Int iParseRefFrmIdx = pcCU->getInterDir( uiAbsPartIdx ) & ( 1 << eRefList );
421
422  if ( pcCU->getSlice()->getNumRefIdx( eRefList ) > 1 && iParseRefFrmIdx )
423  {
424    m_pcEntropyDecoderIf->parseRefFrmIdx( pcCU, iRefFrmIdx, eRefList );
425  }
426  else if ( !iParseRefFrmIdx )
427  {
428    iRefFrmIdx = NOT_VALID;
429  }
430  else
431  {
432    iRefFrmIdx = 0;
433  }
434
435  PartSize ePartSize = pcCU->getPartitionSize( uiAbsPartIdx );
436  pcCU->getCUMvField( eRefList )->setAllRefIdx( iRefFrmIdx, ePartSize, uiAbsPartIdx, uiDepth, uiPartIdx );
437}
438
439/** decode motion vector difference for a PU block
440 * \param pcCU
441 * \param uiAbsPartIdx
442 * \param uiDepth
443 * \param uiPartIdx
444 * \param eRefList
445 * \returns Void
446 */
447Void TDecEntropy::decodeMvdPU( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, UInt uiPartIdx, RefPicList eRefList )
448{
449  if ( pcCU->getInterDir( uiAbsPartIdx ) & ( 1 << eRefList ) )
450  {
451    m_pcEntropyDecoderIf->parseMvd( pcCU, uiAbsPartIdx, uiPartIdx, uiDepth, eRefList );
452  }
453}
454
455Void TDecEntropy::decodeMVPIdxPU( TComDataCU* pcSubCU, UInt uiPartAddr, UInt uiDepth, UInt uiPartIdx, RefPicList eRefList )
456{
457  Int iMVPIdx = -1;
458
459  TComMv cZeroMv( 0, 0 );
460  TComMv cMv     = cZeroMv;
461  Int    iRefIdx = -1;
462
463  TComCUMvField* pcSubCUMvField = pcSubCU->getCUMvField( eRefList );
464  AMVPInfo* pAMVPInfo = pcSubCUMvField->getAMVPInfo();
465
466  iRefIdx = pcSubCUMvField->getRefIdx(uiPartAddr);
467  cMv = cZeroMv;
468
469  if ( (pcSubCU->getInterDir(uiPartAddr) & ( 1 << eRefList )) )
470  {
471    m_pcEntropyDecoderIf->parseMVPIdx( iMVPIdx );
472#if H_MV_ENC_DEC_TRAC
473#if ENC_DEC_TRACE
474    if ( eRefList == REF_PIC_LIST_0 )
475    {
476      DTRACE_PU("mvp_l0_flag", iMVPIdx)
477    }
478    else
479    {
480      DTRACE_PU("mvp_l1_flag", iMVPIdx)
481    }
482#endif
483#endif
484  }
485  pcSubCU->fillMvpCand(uiPartIdx, uiPartAddr, eRefList, iRefIdx, pAMVPInfo);
486  pcSubCU->setMVPNumSubParts(pAMVPInfo->iN, eRefList, uiPartAddr, uiPartIdx, uiDepth);
487  pcSubCU->setMVPIdxSubParts( iMVPIdx, eRefList, uiPartAddr, uiPartIdx, uiDepth );
488  if ( iRefIdx >= 0 )
489  {
490    m_pcPrediction->getMvPredAMVP( pcSubCU, uiPartIdx, uiPartAddr, eRefList, cMv);
491    cMv += pcSubCUMvField->getMvd( uiPartAddr );
492  }
493
494  PartSize ePartSize = pcSubCU->getPartitionSize( uiPartAddr );
495  pcSubCU->getCUMvField( eRefList )->setAllMv(cMv, ePartSize, uiPartAddr, 0, uiPartIdx);
496}
497
498Void TDecEntropy::xDecodeTransform( TComDataCU* pcCU, UInt offsetLuma, UInt offsetChroma, UInt uiAbsPartIdx, UInt uiDepth, UInt width, UInt height, UInt uiTrIdx, Bool& bCodeDQP)
499{
500  UInt uiSubdiv;
501  const UInt uiLog2TrafoSize = g_aucConvertToBit[pcCU->getSlice()->getSPS()->getMaxCUWidth()]+2 - uiDepth;
502
503  if(uiTrIdx==0)
504  {
505    m_bakAbsPartIdxCU = uiAbsPartIdx;
506  }
507  if( uiLog2TrafoSize == 2 )
508  {
509    UInt partNum = pcCU->getPic()->getNumPartInCU() >> ( ( uiDepth - 1 ) << 1 );
510    if( ( uiAbsPartIdx % partNum ) == 0 )
511    {
512      m_uiBakAbsPartIdx   = uiAbsPartIdx;
513      m_uiBakChromaOffset = offsetChroma;
514    }
515  }
516  if( pcCU->getPredictionMode(uiAbsPartIdx) == MODE_INTRA && pcCU->getPartitionSize(uiAbsPartIdx) == SIZE_NxN && uiDepth == pcCU->getDepth(uiAbsPartIdx) )
517  {
518    uiSubdiv = 1;
519  }
520  else if( (pcCU->getSlice()->getSPS()->getQuadtreeTUMaxDepthInter() == 1) && (pcCU->getPredictionMode(uiAbsPartIdx) == MODE_INTER) && ( pcCU->getPartitionSize(uiAbsPartIdx) != SIZE_2Nx2N ) && (uiDepth == pcCU->getDepth(uiAbsPartIdx)) )
521  {
522    uiSubdiv = (uiLog2TrafoSize > pcCU->getQuadtreeTULog2MinSizeInCU(uiAbsPartIdx));
523  }
524  else if( uiLog2TrafoSize > pcCU->getSlice()->getSPS()->getQuadtreeTULog2MaxSize() )
525  {
526    uiSubdiv = 1;
527  }
528  else if( uiLog2TrafoSize == pcCU->getSlice()->getSPS()->getQuadtreeTULog2MinSize() )
529  {
530    uiSubdiv = 0;
531  }
532  else if( uiLog2TrafoSize == pcCU->getQuadtreeTULog2MinSizeInCU(uiAbsPartIdx) )
533  {
534    uiSubdiv = 0;
535  }
536  else
537  {
538    assert( uiLog2TrafoSize > pcCU->getQuadtreeTULog2MinSizeInCU(uiAbsPartIdx) );
539    m_pcEntropyDecoderIf->parseTransformSubdivFlag( uiSubdiv, 5 - uiLog2TrafoSize );
540  }
541 
542  const UInt uiTrDepth = uiDepth - pcCU->getDepth( uiAbsPartIdx );
543  {
544    const Bool bFirstCbfOfCU = uiTrDepth == 0;
545    if( bFirstCbfOfCU )
546    {
547      pcCU->setCbfSubParts( 0, TEXT_CHROMA_U, uiAbsPartIdx, uiDepth );
548      pcCU->setCbfSubParts( 0, TEXT_CHROMA_V, uiAbsPartIdx, uiDepth );
549    }
550    if( bFirstCbfOfCU || uiLog2TrafoSize > 2 )
551    {
552      if( bFirstCbfOfCU || pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_U, uiTrDepth - 1 ) )
553      {
554        m_pcEntropyDecoderIf->parseQtCbf( pcCU, uiAbsPartIdx, TEXT_CHROMA_U, uiTrDepth, uiDepth );
555      }
556      if( bFirstCbfOfCU || pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_V, uiTrDepth - 1 ) )
557      {
558        m_pcEntropyDecoderIf->parseQtCbf( pcCU, uiAbsPartIdx, TEXT_CHROMA_V, uiTrDepth, uiDepth );
559      }
560    }
561    else
562    {
563      pcCU->setCbfSubParts( pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_U, uiTrDepth - 1 ) << uiTrDepth, TEXT_CHROMA_U, uiAbsPartIdx, uiDepth );
564      pcCU->setCbfSubParts( pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_V, uiTrDepth - 1 ) << uiTrDepth, TEXT_CHROMA_V, uiAbsPartIdx, uiDepth );
565    }
566  }
567 
568  if( uiSubdiv )
569  {
570    UInt size;
571    width  >>= 1;
572    height >>= 1;
573    size = width*height;
574    uiTrIdx++;
575    ++uiDepth;
576    const UInt uiQPartNum = pcCU->getPic()->getNumPartInCU() >> (uiDepth << 1);
577    const UInt uiStartAbsPartIdx = uiAbsPartIdx;
578    UInt uiYCbf = 0;
579    UInt uiUCbf = 0;
580    UInt uiVCbf = 0;
581   
582    for( Int i = 0; i < 4; i++ )
583    {
584      xDecodeTransform( pcCU, offsetLuma, offsetChroma, uiAbsPartIdx, uiDepth, width, height, uiTrIdx, bCodeDQP );
585      uiYCbf |= pcCU->getCbf( uiAbsPartIdx, TEXT_LUMA, uiTrDepth+1 );
586      uiUCbf |= pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_U, uiTrDepth+1 );
587      uiVCbf |= pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_V, uiTrDepth+1 );
588      uiAbsPartIdx += uiQPartNum;
589      offsetLuma += size;  offsetChroma += (size>>2);
590    }
591   
592    for( UInt ui = 0; ui < 4 * uiQPartNum; ++ui )
593    {
594      pcCU->getCbf( TEXT_LUMA     )[uiStartAbsPartIdx + ui] |= uiYCbf << uiTrDepth;
595      pcCU->getCbf( TEXT_CHROMA_U )[uiStartAbsPartIdx + ui] |= uiUCbf << uiTrDepth;
596      pcCU->getCbf( TEXT_CHROMA_V )[uiStartAbsPartIdx + ui] |= uiVCbf << uiTrDepth;
597    }
598  }
599  else
600  {
601    assert( uiDepth >= pcCU->getDepth( uiAbsPartIdx ) );
602    pcCU->setTrIdxSubParts( uiTrDepth, uiAbsPartIdx, uiDepth );
603   
604#if !H_MV_ENC_DEC_TRAC
605    {
606      DTRACE_CABAC_VL( g_nSymbolCounter++ );
607      DTRACE_CABAC_T( "\tTrIdx: abspart=" );
608      DTRACE_CABAC_V( uiAbsPartIdx );
609      DTRACE_CABAC_T( "\tdepth=" );
610      DTRACE_CABAC_V( uiDepth );
611      DTRACE_CABAC_T( "\ttrdepth=" );
612      DTRACE_CABAC_V( uiTrDepth );
613      DTRACE_CABAC_T( "\n" );
614    }
615#endif
616   
617    pcCU->setCbfSubParts ( 0, TEXT_LUMA, uiAbsPartIdx, uiDepth );
618    if( pcCU->getPredictionMode(uiAbsPartIdx) != MODE_INTRA && uiDepth == pcCU->getDepth( uiAbsPartIdx ) && !pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_U, 0 ) && !pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_V, 0 ) )
619    {
620      pcCU->setCbfSubParts( 1 << uiTrDepth, TEXT_LUMA, uiAbsPartIdx, uiDepth );
621    }
622    else
623    {
624      m_pcEntropyDecoderIf->parseQtCbf( pcCU, uiAbsPartIdx, TEXT_LUMA, uiTrDepth, uiDepth );
625    }
626
627
628    // transform_unit begin
629    UInt cbfY = pcCU->getCbf( uiAbsPartIdx, TEXT_LUMA    , uiTrIdx );
630    UInt cbfU = pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_U, uiTrIdx );
631    UInt cbfV = pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_V, uiTrIdx );
632    if( uiLog2TrafoSize == 2 )
633    {
634      UInt partNum = pcCU->getPic()->getNumPartInCU() >> ( ( uiDepth - 1 ) << 1 );
635      if( ( uiAbsPartIdx % partNum ) == (partNum - 1) )
636      {
637        cbfU = pcCU->getCbf( m_uiBakAbsPartIdx, TEXT_CHROMA_U, uiTrIdx );
638        cbfV = pcCU->getCbf( m_uiBakAbsPartIdx, TEXT_CHROMA_V, uiTrIdx );
639      }
640    }
641    if ( cbfY || cbfU || cbfV )
642    {
643      // dQP: only for LCU
644      if ( pcCU->getSlice()->getPPS()->getUseDQP() )
645      {
646        if ( bCodeDQP )
647        {
648          decodeQP( pcCU, m_bakAbsPartIdxCU);
649          bCodeDQP = false;
650        }
651      }
652    }
653    if( cbfY )
654    {
655      Int trWidth = width;
656      Int trHeight = height;
657      m_pcEntropyDecoderIf->parseCoeffNxN( pcCU, (pcCU->getCoeffY()+offsetLuma), uiAbsPartIdx, trWidth, trHeight, uiDepth, TEXT_LUMA );
658    }
659    if( uiLog2TrafoSize > 2 )
660    {
661      Int trWidth = width >> 1;
662      Int trHeight = height >> 1;
663      if( cbfU )
664      {
665        m_pcEntropyDecoderIf->parseCoeffNxN( pcCU, (pcCU->getCoeffCb()+offsetChroma), uiAbsPartIdx, trWidth, trHeight, uiDepth, TEXT_CHROMA_U );
666      }
667      if( cbfV )
668      {
669        m_pcEntropyDecoderIf->parseCoeffNxN( pcCU, (pcCU->getCoeffCr()+offsetChroma), uiAbsPartIdx, trWidth, trHeight, uiDepth, TEXT_CHROMA_V );
670      }
671    }
672    else
673    {
674      UInt partNum = pcCU->getPic()->getNumPartInCU() >> ( ( uiDepth - 1 ) << 1 );
675      if( ( uiAbsPartIdx % partNum ) == (partNum - 1) )
676      {
677        Int trWidth = width;
678        Int trHeight = height;
679        if( cbfU )
680        {
681          m_pcEntropyDecoderIf->parseCoeffNxN( pcCU, (pcCU->getCoeffCb()+m_uiBakChromaOffset), m_uiBakAbsPartIdx, trWidth, trHeight, uiDepth, TEXT_CHROMA_U );
682        }
683        if( cbfV )
684        {
685          m_pcEntropyDecoderIf->parseCoeffNxN( pcCU, (pcCU->getCoeffCr()+m_uiBakChromaOffset), m_uiBakAbsPartIdx, trWidth, trHeight, uiDepth, TEXT_CHROMA_V );
686        }
687      }
688    }
689    // transform_unit end
690  }
691}
692
693Void TDecEntropy::decodeQP          ( TComDataCU* pcCU, UInt uiAbsPartIdx )
694{
695  if ( pcCU->getSlice()->getPPS()->getUseDQP() )
696  {
697    m_pcEntropyDecoderIf->parseDeltaQP( pcCU, uiAbsPartIdx, pcCU->getDepth( uiAbsPartIdx ) );
698  }
699}
700
701
702/** decode coefficients
703 * \param pcCU
704 * \param uiAbsPartIdx
705 * \param uiDepth
706 * \param uiWidth
707 * \param uiHeight
708 * \returns Void
709 */
710Void TDecEntropy::decodeCoeff( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, UInt uiWidth, UInt uiHeight, Bool& bCodeDQP )
711{
712  UInt uiMinCoeffSize = pcCU->getPic()->getMinCUWidth()*pcCU->getPic()->getMinCUHeight();
713  UInt uiLumaOffset   = uiMinCoeffSize*uiAbsPartIdx;
714  UInt uiChromaOffset = uiLumaOffset>>2;
715 
716#if H_3D_DIM_SDC
717  if( pcCU->getSDCFlag( uiAbsPartIdx ) )
718  {
719    assert( pcCU->getPartitionSize(uiAbsPartIdx) == SIZE_2Nx2N );
720    assert( pcCU->getTransformIdx(uiAbsPartIdx) == 0 );
721    assert( pcCU->getCbf(uiAbsPartIdx, TEXT_LUMA) == 1 );
722    assert( pcCU->getCbf(uiAbsPartIdx, TEXT_CHROMA_U) == 1 );
723    assert( pcCU->getCbf(uiAbsPartIdx, TEXT_CHROMA_V) == 1 );
724    return;
725  }
726#endif
727 
728#if H_3D_INTER_SDC
729  if( pcCU->getInterSDCFlag( uiAbsPartIdx ) )
730  {
731    assert( !pcCU->isSkipped( uiAbsPartIdx ) );
732    assert( !pcCU->isIntra( uiAbsPartIdx) );
733    assert( pcCU->getSlice()->getIsDepth() );
734
735    decodeInterSDCResidualData( pcCU, uiAbsPartIdx, uiDepth );
736    return;
737  }
738#endif
739
740  if( pcCU->isIntra(uiAbsPartIdx) )
741  {
742  }
743  else
744  {
745    UInt uiQtRootCbf = 1;
746    if( !( pcCU->getPartitionSize( uiAbsPartIdx) == SIZE_2Nx2N && pcCU->getMergeFlag( uiAbsPartIdx ) ) )
747    {
748      m_pcEntropyDecoderIf->parseQtRootCbf( uiAbsPartIdx, uiQtRootCbf );
749    }
750    if ( !uiQtRootCbf )
751    {
752      pcCU->setCbfSubParts( 0, 0, 0, uiAbsPartIdx, uiDepth );
753      pcCU->setTrIdxSubParts( 0 , uiAbsPartIdx, uiDepth );
754      return;
755    }
756   
757  }
758  xDecodeTransform( pcCU, uiLumaOffset, uiChromaOffset, uiAbsPartIdx, uiDepth, uiWidth, uiHeight, 0, bCodeDQP );
759}
760
761#if H_3D_INTER_SDC
762Void TDecEntropy::decodeInterSDCFlag( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
763{
764  pcCU->setInterSDCFlagSubParts( false, uiAbsPartIdx, 0, uiDepth);
765
766  if( !pcCU->getSlice()->getVPS()->getInterSDCFlag( pcCU->getSlice()->getLayerIdInVps() ) )
767  {
768    return;
769  }
770
771  if( !pcCU->getSlice()->getIsDepth() || pcCU->isIntra( uiAbsPartIdx ) || pcCU->isSkipped( uiAbsPartIdx ) )
772  {
773    return;
774  }
775
776  m_pcEntropyDecoderIf->parseInterSDCFlag( pcCU, uiAbsPartIdx, uiDepth );
777}
778
779Void TDecEntropy::decodeInterSDCResidualData( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
780{
781  if( !pcCU->getSlice()->getVPS()->getInterSDCFlag( pcCU->getSlice()->getLayerIdInVps() ) )
782  {
783    return;
784  }
785
786  if( !pcCU->getSlice()->getIsDepth() || pcCU->isIntra( uiAbsPartIdx ) || !pcCU->getInterSDCFlag( uiAbsPartIdx ) )
787  {
788    return;
789  }
790
791  UInt uiNumSegments = ( pcCU->getPartitionSize( uiAbsPartIdx ) == SIZE_2Nx2N ) ? 1 : ( pcCU->getPartitionSize( uiAbsPartIdx ) == SIZE_NxN ? 4 : 2 );
792
793  // decode residual data for each segment
794  for( UInt uiSeg = 0; uiSeg < uiNumSegments; uiSeg++ )
795  {
796    m_pcEntropyDecoderIf->parseInterSDCResidualData( pcCU, uiAbsPartIdx, uiDepth, uiSeg );
797  }
798}
799#endif
800
801//! \}
Note: See TracBrowser for help on using the repository browser.