source: 3DVCSoftware/branches/HTM-13.1-dev1-Samsung/source/Lib/TLibDecoder/TDecEntropy.cpp @ 1147

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

Integration of K0033: Depth intra skip (DIS) mode

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