source: 3DVCSoftware/branches/HTM-9.3-dev2-Samsung/source/Lib/TLibDecoder/TDecEntropy.cpp @ 785

Last change on this file since 785 was 785, checked in by samsung-htm, 10 years ago

Integration of JCT3V-G0072: IC and ARP Flags Signaling

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