source: 3DVCSoftware/branches/HTM-8.2-dev0-MediaTek/source/Lib/TLibDecoder/TDecEntropy.cpp @ 715

Last change on this file since 715 was 712, checked in by tech, 11 years ago

Merged DEV3 ( branch HTM-8.2-dev3-Samsung@699 )

  • Property svn:eol-style set to native
File size: 26.6 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_ONLY_TEXTURE_IC_F0151
114  if ( pcCU->isIntra( uiAbsPartIdx ) || ( pcCU->getSlice()->getViewIndex() == 0 ) || pcCU->getSlice()->getIsDepth() )
115#else
116  if ( pcCU->isIntra( uiAbsPartIdx ) || ( pcCU->getSlice()->getViewIndex() == 0 ) )
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
216  for ( UInt ui = 0; ui < pcCU->getSlice()->getMaxNumMergeCand(); ui++ )
217  {
218    uhInterDirNeighbours[ui] = 0;
219  }
220  Int numValidMergeCand = 0;
221  Bool isMerged = false;
222
223  pcSubCU->copyInterPredInfoFrom( pcCU, uiAbsPartIdx, REF_PIC_LIST_0 );
224  pcSubCU->copyInterPredInfoFrom( pcCU, uiAbsPartIdx, REF_PIC_LIST_1 );
225#if H_3D_IV_MERGE
226  pcSubCU->copyDVInfoFrom( pcCU, uiAbsPartIdx);
227#endif
228  for ( UInt uiPartIdx = 0, uiSubPartIdx = uiAbsPartIdx; uiPartIdx < uiNumPU; uiPartIdx++, uiSubPartIdx += uiPUOffset )
229  {
230#if H_MV_ENC_DEC_TRAC
231    DTRACE_PU_S("=========== prediction_unit ===========\n")
232    // ToDo:
233    //DTRACE_PU("x0", uiLPelX)
234    //DTRACE_PU("x1", uiTPelY)
235#endif
236    decodeMergeFlag( pcCU, uiSubPartIdx, uiDepth, uiPartIdx );
237    if ( pcCU->getMergeFlag( uiSubPartIdx ) )
238    {
239      decodeMergeIndex( pcCU, uiPartIdx, uiSubPartIdx, uiDepth );
240      UInt uiMergeIndex = pcCU->getMergeIndex(uiSubPartIdx);
241#if LGE_SHARP_VSP_INHERIT_F0104
242#if H_3D_IC
243      decodeICFlag( pcCU, uiAbsPartIdx, uiDepth );
244#endif
245#if H_3D_ARP
246      decodeARPW  ( pcCU, uiAbsPartIdx, uiDepth );
247#endif
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 ETRIKHU_MERGE_REUSE_F0093
259          pcSubCU->initAvailableFlags();
260          pcSubCU->getInterMergeCandidates( 0, 0, cMvFieldNeighbours, uhInterDirNeighbours, numValidMergeCand);
261          pcSubCU->xGetInterMergeCandidates( 0, 0, cMvFieldNeighbours, uhInterDirNeighbours, vspFlag, inheritedVSPDisInfo, numValidMergeCand );
262#else
263          pcSubCU->getInterMergeCandidates( 0, 0, cMvFieldNeighbours, uhInterDirNeighbours, vspFlag, inheritedVSPDisInfo, numValidMergeCand );
264#endif
265          pcCU->setVSPFlagSubParts( vspFlag[uiMergeIndex], uiSubPartIdx, uiPartIdx, uiDepth );
266
267          if(vspFlag[uiMergeIndex])
268          {
269            pcCU->setDvInfoSubParts(inheritedVSPDisInfo[uiMergeIndex].m_acDvInfo, uiSubPartIdx, uiPartIdx, uiDepth);
270          }
271#else
272#if ETRIKHU_MERGE_REUSE_F0093
273          pcSubCU->initAvailableFlags();
274          pcSubCU->getInterMergeCandidates( 0, 0, cMvFieldNeighbours, uhInterDirNeighbours, numValidMergeCand);
275          pcSubCU->xGetInterMergeCandidates( 0, 0, cMvFieldNeighbours, uhInterDirNeighbours, numValidMergeCand );
276
277#else
278          pcSubCU->getInterMergeCandidates( 0, 0, cMvFieldNeighbours, uhInterDirNeighbours, numValidMergeCand );
279#endif
280#endif
281          isMerged = true;
282        }
283        pcSubCU->setPartSizeSubParts( ePartSize, 0, uiDepth );
284      }
285      else
286      {
287        uiMergeIndex = pcCU->getMergeIndex(uiSubPartIdx);
288#if H_3D_VSP
289        Int vspFlag[MRG_MAX_NUM_CANDS_MEM];
290        memset(vspFlag, 0, sizeof(Int)*MRG_MAX_NUM_CANDS_MEM);
291        InheritedVSPDisInfo inheritedVSPDisInfo[MRG_MAX_NUM_CANDS_MEM];
292#if ETRIKHU_MERGE_REUSE_F0093
293        pcSubCU->initAvailableFlags();
294        pcSubCU->getInterMergeCandidates( uiSubPartIdx-uiAbsPartIdx, uiPartIdx, cMvFieldNeighbours, uhInterDirNeighbours, numValidMergeCand, uiMergeIndex );
295        pcSubCU->xGetInterMergeCandidates( uiSubPartIdx-uiAbsPartIdx, uiPartIdx, cMvFieldNeighbours, uhInterDirNeighbours, vspFlag, inheritedVSPDisInfo,numValidMergeCand, uiMergeIndex );
296#else
297        pcSubCU->getInterMergeCandidates( uiSubPartIdx-uiAbsPartIdx, uiPartIdx, cMvFieldNeighbours, uhInterDirNeighbours, vspFlag, inheritedVSPDisInfo,numValidMergeCand, uiMergeIndex );
298#endif
299        pcCU->setVSPFlagSubParts( vspFlag[uiMergeIndex], uiSubPartIdx, uiPartIdx, uiDepth );
300        if(vspFlag[uiMergeIndex])
301        {
302          pcCU->setDvInfoSubParts(inheritedVSPDisInfo[uiMergeIndex].m_acDvInfo, uiSubPartIdx, uiPartIdx, uiDepth);
303        }
304#else
305#if ETRIKHU_MERGE_REUSE_F0093
306        pcSubCU->initAvailableFlags();
307        pcSubCU->getInterMergeCandidates( uiSubPartIdx-uiAbsPartIdx, uiPartIdx, cMvFieldNeighbours, uhInterDirNeighbours, numValidMergeCand, uiMergeIndex );
308        pcSubCU->xGetInterMergeCandidates( uiSubPartIdx-uiAbsPartIdx, uiPartIdx, cMvFieldNeighbours, uhInterDirNeighbours, numValidMergeCand, uiMergeIndex );
309#else
310        pcSubCU->getInterMergeCandidates( uiSubPartIdx-uiAbsPartIdx, uiPartIdx, cMvFieldNeighbours, uhInterDirNeighbours, numValidMergeCand, uiMergeIndex );
311#endif
312#endif
313      }
314      pcCU->setInterDirSubParts( uhInterDirNeighbours[uiMergeIndex], uiSubPartIdx, uiPartIdx, uiDepth );
315
316      TComMv cTmpMv( 0, 0 );
317      for ( UInt uiRefListIdx = 0; uiRefListIdx < 2; uiRefListIdx++ )
318      {       
319        if ( pcCU->getSlice()->getNumRefIdx( RefPicList( uiRefListIdx ) ) > 0 )
320        {
321          pcCU->setMVPIdxSubParts( 0, RefPicList( uiRefListIdx ), uiSubPartIdx, uiPartIdx, uiDepth);
322          pcCU->setMVPNumSubParts( 0, RefPicList( uiRefListIdx ), uiSubPartIdx, uiPartIdx, uiDepth);
323          pcCU->getCUMvField( RefPicList( uiRefListIdx ) )->setAllMvd( cTmpMv, ePartSize, uiSubPartIdx, uiDepth, uiPartIdx );
324          pcCU->getCUMvField( RefPicList( uiRefListIdx ) )->setAllMvField( cMvFieldNeighbours[ 2*uiMergeIndex + uiRefListIdx ], ePartSize, uiSubPartIdx, uiDepth, uiPartIdx );
325        }
326      }
327    }
328    else
329    {
330      decodeInterDirPU( pcCU, uiSubPartIdx, uiDepth, uiPartIdx );
331      for ( UInt uiRefListIdx = 0; uiRefListIdx < 2; uiRefListIdx++ )
332      {       
333        if ( pcCU->getSlice()->getNumRefIdx( RefPicList( uiRefListIdx ) ) > 0 )
334        {
335          decodeRefFrmIdxPU( pcCU,    uiSubPartIdx,              uiDepth, uiPartIdx, RefPicList( uiRefListIdx ) );
336          decodeMvdPU      ( pcCU,    uiSubPartIdx,              uiDepth, uiPartIdx, RefPicList( uiRefListIdx ) );
337          decodeMVPIdxPU   ( pcSubCU, uiSubPartIdx-uiAbsPartIdx, uiDepth, uiPartIdx, RefPicList( uiRefListIdx ) );
338        }
339      }
340#if LGE_SHARP_VSP_INHERIT_F0104
341#if H_3D_IC
342      decodeICFlag( pcCU, uiAbsPartIdx, uiDepth );
343#endif
344#if H_3D_ARP
345      decodeARPW  ( pcCU, uiAbsPartIdx, uiDepth );
346#endif
347#endif
348    }
349#if H_3D_VSP
350    if ( (pcCU->getInterDir(uiSubPartIdx) == 3) && pcSubCU->isBipredRestriction(uiPartIdx) && (pcCU->getVSPFlag(uiSubPartIdx) == false))
351#else
352    if ( (pcCU->getInterDir(uiSubPartIdx) == 3) && pcSubCU->isBipredRestriction(uiPartIdx) )
353#endif
354    {
355      pcCU->getCUMvField( REF_PIC_LIST_1 )->setAllMv( TComMv(0,0), ePartSize, uiSubPartIdx, uiDepth, uiPartIdx);
356      pcCU->getCUMvField( REF_PIC_LIST_1 )->setAllRefIdx( -1, ePartSize, uiSubPartIdx, uiDepth, uiPartIdx);
357      pcCU->setInterDirSubParts( 1, uiSubPartIdx, uiPartIdx, uiDepth);
358    }
359  }
360  return;
361}
362
363/** decode inter direction for a PU block
364 * \param pcCU
365 * \param uiAbsPartIdx
366 * \param uiDepth
367 * \param uiPartIdx
368 * \returns Void
369 */
370Void TDecEntropy::decodeInterDirPU( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, UInt uiPartIdx )
371{
372  UInt uiInterDir;
373
374  if ( pcCU->getSlice()->isInterP() )
375  {
376    uiInterDir = 1;
377  }
378  else
379  {
380    m_pcEntropyDecoderIf->parseInterDir( pcCU, uiInterDir, uiAbsPartIdx );
381  }
382
383  pcCU->setInterDirSubParts( uiInterDir, uiAbsPartIdx, uiPartIdx, uiDepth );
384}
385
386Void TDecEntropy::decodeRefFrmIdxPU( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, UInt uiPartIdx, RefPicList eRefList )
387{
388  Int iRefFrmIdx = 0;
389  Int iParseRefFrmIdx = pcCU->getInterDir( uiAbsPartIdx ) & ( 1 << eRefList );
390
391  if ( pcCU->getSlice()->getNumRefIdx( eRefList ) > 1 && iParseRefFrmIdx )
392  {
393    m_pcEntropyDecoderIf->parseRefFrmIdx( pcCU, iRefFrmIdx, eRefList );
394  }
395  else if ( !iParseRefFrmIdx )
396  {
397    iRefFrmIdx = NOT_VALID;
398  }
399  else
400  {
401    iRefFrmIdx = 0;
402  }
403
404  PartSize ePartSize = pcCU->getPartitionSize( uiAbsPartIdx );
405  pcCU->getCUMvField( eRefList )->setAllRefIdx( iRefFrmIdx, ePartSize, uiAbsPartIdx, uiDepth, uiPartIdx );
406}
407
408/** decode motion vector difference for a PU block
409 * \param pcCU
410 * \param uiAbsPartIdx
411 * \param uiDepth
412 * \param uiPartIdx
413 * \param eRefList
414 * \returns Void
415 */
416Void TDecEntropy::decodeMvdPU( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, UInt uiPartIdx, RefPicList eRefList )
417{
418  if ( pcCU->getInterDir( uiAbsPartIdx ) & ( 1 << eRefList ) )
419  {
420    m_pcEntropyDecoderIf->parseMvd( pcCU, uiAbsPartIdx, uiPartIdx, uiDepth, eRefList );
421  }
422}
423
424Void TDecEntropy::decodeMVPIdxPU( TComDataCU* pcSubCU, UInt uiPartAddr, UInt uiDepth, UInt uiPartIdx, RefPicList eRefList )
425{
426  Int iMVPIdx = -1;
427
428  TComMv cZeroMv( 0, 0 );
429  TComMv cMv     = cZeroMv;
430  Int    iRefIdx = -1;
431
432  TComCUMvField* pcSubCUMvField = pcSubCU->getCUMvField( eRefList );
433  AMVPInfo* pAMVPInfo = pcSubCUMvField->getAMVPInfo();
434
435  iRefIdx = pcSubCUMvField->getRefIdx(uiPartAddr);
436  cMv = cZeroMv;
437
438  if ( (pcSubCU->getInterDir(uiPartAddr) & ( 1 << eRefList )) )
439  {
440    m_pcEntropyDecoderIf->parseMVPIdx( iMVPIdx );
441#if H_MV_ENC_DEC_TRAC
442#if ENC_DEC_TRACE
443    if ( eRefList == REF_PIC_LIST_0 )
444    {
445      DTRACE_PU("mvp_l0_flag", iMVPIdx)
446    }
447    else
448    {
449      DTRACE_PU("mvp_l1_flag", iMVPIdx)
450    }
451#endif
452#endif
453  }
454  pcSubCU->fillMvpCand(uiPartIdx, uiPartAddr, eRefList, iRefIdx, pAMVPInfo);
455  pcSubCU->setMVPNumSubParts(pAMVPInfo->iN, eRefList, uiPartAddr, uiPartIdx, uiDepth);
456  pcSubCU->setMVPIdxSubParts( iMVPIdx, eRefList, uiPartAddr, uiPartIdx, uiDepth );
457  if ( iRefIdx >= 0 )
458  {
459    m_pcPrediction->getMvPredAMVP( pcSubCU, uiPartIdx, uiPartAddr, eRefList, cMv);
460    cMv += pcSubCUMvField->getMvd( uiPartAddr );
461  }
462
463  PartSize ePartSize = pcSubCU->getPartitionSize( uiPartAddr );
464  pcSubCU->getCUMvField( eRefList )->setAllMv(cMv, ePartSize, uiPartAddr, 0, uiPartIdx);
465}
466
467Void TDecEntropy::xDecodeTransform( TComDataCU* pcCU, UInt offsetLuma, UInt offsetChroma, UInt uiAbsPartIdx, UInt uiDepth, UInt width, UInt height, UInt uiTrIdx, Bool& bCodeDQP)
468{
469  UInt uiSubdiv;
470  const UInt uiLog2TrafoSize = g_aucConvertToBit[pcCU->getSlice()->getSPS()->getMaxCUWidth()]+2 - uiDepth;
471
472  if(uiTrIdx==0)
473  {
474    m_bakAbsPartIdxCU = uiAbsPartIdx;
475  }
476  if( uiLog2TrafoSize == 2 )
477  {
478    UInt partNum = pcCU->getPic()->getNumPartInCU() >> ( ( uiDepth - 1 ) << 1 );
479    if( ( uiAbsPartIdx % partNum ) == 0 )
480    {
481      m_uiBakAbsPartIdx   = uiAbsPartIdx;
482      m_uiBakChromaOffset = offsetChroma;
483    }
484  }
485  if( pcCU->getPredictionMode(uiAbsPartIdx) == MODE_INTRA && pcCU->getPartitionSize(uiAbsPartIdx) == SIZE_NxN && uiDepth == pcCU->getDepth(uiAbsPartIdx) )
486  {
487    uiSubdiv = 1;
488  }
489  else if( (pcCU->getSlice()->getSPS()->getQuadtreeTUMaxDepthInter() == 1) && (pcCU->getPredictionMode(uiAbsPartIdx) == MODE_INTER) && ( pcCU->getPartitionSize(uiAbsPartIdx) != SIZE_2Nx2N ) && (uiDepth == pcCU->getDepth(uiAbsPartIdx)) )
490  {
491    uiSubdiv = (uiLog2TrafoSize > pcCU->getQuadtreeTULog2MinSizeInCU(uiAbsPartIdx));
492  }
493  else if( uiLog2TrafoSize > pcCU->getSlice()->getSPS()->getQuadtreeTULog2MaxSize() )
494  {
495    uiSubdiv = 1;
496  }
497  else if( uiLog2TrafoSize == pcCU->getSlice()->getSPS()->getQuadtreeTULog2MinSize() )
498  {
499    uiSubdiv = 0;
500  }
501  else if( uiLog2TrafoSize == pcCU->getQuadtreeTULog2MinSizeInCU(uiAbsPartIdx) )
502  {
503    uiSubdiv = 0;
504  }
505  else
506  {
507    assert( uiLog2TrafoSize > pcCU->getQuadtreeTULog2MinSizeInCU(uiAbsPartIdx) );
508    m_pcEntropyDecoderIf->parseTransformSubdivFlag( uiSubdiv, 5 - uiLog2TrafoSize );
509  }
510 
511  const UInt uiTrDepth = uiDepth - pcCU->getDepth( uiAbsPartIdx );
512  {
513    const Bool bFirstCbfOfCU = uiTrDepth == 0;
514    if( bFirstCbfOfCU )
515    {
516      pcCU->setCbfSubParts( 0, TEXT_CHROMA_U, uiAbsPartIdx, uiDepth );
517      pcCU->setCbfSubParts( 0, TEXT_CHROMA_V, uiAbsPartIdx, uiDepth );
518    }
519    if( bFirstCbfOfCU || uiLog2TrafoSize > 2 )
520    {
521      if( bFirstCbfOfCU || pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_U, uiTrDepth - 1 ) )
522      {
523        m_pcEntropyDecoderIf->parseQtCbf( pcCU, uiAbsPartIdx, TEXT_CHROMA_U, uiTrDepth, uiDepth );
524      }
525      if( bFirstCbfOfCU || pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_V, uiTrDepth - 1 ) )
526      {
527        m_pcEntropyDecoderIf->parseQtCbf( pcCU, uiAbsPartIdx, TEXT_CHROMA_V, uiTrDepth, uiDepth );
528      }
529    }
530    else
531    {
532      pcCU->setCbfSubParts( pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_U, uiTrDepth - 1 ) << uiTrDepth, TEXT_CHROMA_U, uiAbsPartIdx, uiDepth );
533      pcCU->setCbfSubParts( pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_V, uiTrDepth - 1 ) << uiTrDepth, TEXT_CHROMA_V, uiAbsPartIdx, uiDepth );
534    }
535  }
536 
537  if( uiSubdiv )
538  {
539    UInt size;
540    width  >>= 1;
541    height >>= 1;
542    size = width*height;
543    uiTrIdx++;
544    ++uiDepth;
545    const UInt uiQPartNum = pcCU->getPic()->getNumPartInCU() >> (uiDepth << 1);
546    const UInt uiStartAbsPartIdx = uiAbsPartIdx;
547    UInt uiYCbf = 0;
548    UInt uiUCbf = 0;
549    UInt uiVCbf = 0;
550   
551    for( Int i = 0; i < 4; i++ )
552    {
553      xDecodeTransform( pcCU, offsetLuma, offsetChroma, uiAbsPartIdx, uiDepth, width, height, uiTrIdx, bCodeDQP );
554      uiYCbf |= pcCU->getCbf( uiAbsPartIdx, TEXT_LUMA, uiTrDepth+1 );
555      uiUCbf |= pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_U, uiTrDepth+1 );
556      uiVCbf |= pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_V, uiTrDepth+1 );
557      uiAbsPartIdx += uiQPartNum;
558      offsetLuma += size;  offsetChroma += (size>>2);
559    }
560   
561    for( UInt ui = 0; ui < 4 * uiQPartNum; ++ui )
562    {
563      pcCU->getCbf( TEXT_LUMA     )[uiStartAbsPartIdx + ui] |= uiYCbf << uiTrDepth;
564      pcCU->getCbf( TEXT_CHROMA_U )[uiStartAbsPartIdx + ui] |= uiUCbf << uiTrDepth;
565      pcCU->getCbf( TEXT_CHROMA_V )[uiStartAbsPartIdx + ui] |= uiVCbf << uiTrDepth;
566    }
567  }
568  else
569  {
570    assert( uiDepth >= pcCU->getDepth( uiAbsPartIdx ) );
571    pcCU->setTrIdxSubParts( uiTrDepth, uiAbsPartIdx, uiDepth );
572   
573#if !H_MV_ENC_DEC_TRAC
574    {
575      DTRACE_CABAC_VL( g_nSymbolCounter++ );
576      DTRACE_CABAC_T( "\tTrIdx: abspart=" );
577      DTRACE_CABAC_V( uiAbsPartIdx );
578      DTRACE_CABAC_T( "\tdepth=" );
579      DTRACE_CABAC_V( uiDepth );
580      DTRACE_CABAC_T( "\ttrdepth=" );
581      DTRACE_CABAC_V( uiTrDepth );
582      DTRACE_CABAC_T( "\n" );
583    }
584#endif
585   
586    pcCU->setCbfSubParts ( 0, TEXT_LUMA, uiAbsPartIdx, uiDepth );
587    if( pcCU->getPredictionMode(uiAbsPartIdx) != MODE_INTRA && uiDepth == pcCU->getDepth( uiAbsPartIdx ) && !pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_U, 0 ) && !pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_V, 0 ) )
588    {
589      pcCU->setCbfSubParts( 1 << uiTrDepth, TEXT_LUMA, uiAbsPartIdx, uiDepth );
590    }
591    else
592    {
593      m_pcEntropyDecoderIf->parseQtCbf( pcCU, uiAbsPartIdx, TEXT_LUMA, uiTrDepth, uiDepth );
594    }
595
596
597    // transform_unit begin
598    UInt cbfY = pcCU->getCbf( uiAbsPartIdx, TEXT_LUMA    , uiTrIdx );
599    UInt cbfU = pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_U, uiTrIdx );
600    UInt cbfV = pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_V, uiTrIdx );
601    if( uiLog2TrafoSize == 2 )
602    {
603      UInt partNum = pcCU->getPic()->getNumPartInCU() >> ( ( uiDepth - 1 ) << 1 );
604      if( ( uiAbsPartIdx % partNum ) == (partNum - 1) )
605      {
606        cbfU = pcCU->getCbf( m_uiBakAbsPartIdx, TEXT_CHROMA_U, uiTrIdx );
607        cbfV = pcCU->getCbf( m_uiBakAbsPartIdx, TEXT_CHROMA_V, uiTrIdx );
608      }
609    }
610    if ( cbfY || cbfU || cbfV )
611    {
612      // dQP: only for LCU
613      if ( pcCU->getSlice()->getPPS()->getUseDQP() )
614      {
615        if ( bCodeDQP )
616        {
617          decodeQP( pcCU, m_bakAbsPartIdxCU);
618          bCodeDQP = false;
619        }
620      }
621    }
622    if( cbfY )
623    {
624      Int trWidth = width;
625      Int trHeight = height;
626      m_pcEntropyDecoderIf->parseCoeffNxN( pcCU, (pcCU->getCoeffY()+offsetLuma), uiAbsPartIdx, trWidth, trHeight, uiDepth, TEXT_LUMA );
627    }
628    if( uiLog2TrafoSize > 2 )
629    {
630      Int trWidth = width >> 1;
631      Int trHeight = height >> 1;
632      if( cbfU )
633      {
634        m_pcEntropyDecoderIf->parseCoeffNxN( pcCU, (pcCU->getCoeffCb()+offsetChroma), uiAbsPartIdx, trWidth, trHeight, uiDepth, TEXT_CHROMA_U );
635      }
636      if( cbfV )
637      {
638        m_pcEntropyDecoderIf->parseCoeffNxN( pcCU, (pcCU->getCoeffCr()+offsetChroma), uiAbsPartIdx, trWidth, trHeight, uiDepth, TEXT_CHROMA_V );
639      }
640    }
641    else
642    {
643      UInt partNum = pcCU->getPic()->getNumPartInCU() >> ( ( uiDepth - 1 ) << 1 );
644      if( ( uiAbsPartIdx % partNum ) == (partNum - 1) )
645      {
646        Int trWidth = width;
647        Int trHeight = height;
648        if( cbfU )
649        {
650          m_pcEntropyDecoderIf->parseCoeffNxN( pcCU, (pcCU->getCoeffCb()+m_uiBakChromaOffset), m_uiBakAbsPartIdx, trWidth, trHeight, uiDepth, TEXT_CHROMA_U );
651        }
652        if( cbfV )
653        {
654          m_pcEntropyDecoderIf->parseCoeffNxN( pcCU, (pcCU->getCoeffCr()+m_uiBakChromaOffset), m_uiBakAbsPartIdx, trWidth, trHeight, uiDepth, TEXT_CHROMA_V );
655        }
656      }
657    }
658    // transform_unit end
659  }
660}
661
662Void TDecEntropy::decodeQP          ( TComDataCU* pcCU, UInt uiAbsPartIdx )
663{
664  if ( pcCU->getSlice()->getPPS()->getUseDQP() )
665  {
666    m_pcEntropyDecoderIf->parseDeltaQP( pcCU, uiAbsPartIdx, pcCU->getDepth( uiAbsPartIdx ) );
667  }
668}
669
670
671/** decode coefficients
672 * \param pcCU
673 * \param uiAbsPartIdx
674 * \param uiDepth
675 * \param uiWidth
676 * \param uiHeight
677 * \returns Void
678 */
679Void TDecEntropy::decodeCoeff( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, UInt uiWidth, UInt uiHeight, Bool& bCodeDQP )
680{
681  UInt uiMinCoeffSize = pcCU->getPic()->getMinCUWidth()*pcCU->getPic()->getMinCUHeight();
682  UInt uiLumaOffset   = uiMinCoeffSize*uiAbsPartIdx;
683  UInt uiChromaOffset = uiLumaOffset>>2;
684 
685#if H_3D_DIM_SDC
686  if( pcCU->getSDCFlag( uiAbsPartIdx ) )
687  {
688    assert( pcCU->getPartitionSize(uiAbsPartIdx) == SIZE_2Nx2N );
689    assert( pcCU->getTransformIdx(uiAbsPartIdx) == 0 );
690    assert( pcCU->getCbf(uiAbsPartIdx, TEXT_LUMA) == 1 );
691    assert( pcCU->getCbf(uiAbsPartIdx, TEXT_CHROMA_U) == 1 );
692    assert( pcCU->getCbf(uiAbsPartIdx, TEXT_CHROMA_V) == 1 );
693    return;
694  }
695#endif
696 
697#if H_3D_INTER_SDC
698  if( pcCU->getInterSDCFlag( uiAbsPartIdx ) )
699  {
700    assert( !pcCU->isSkipped( uiAbsPartIdx ) );
701    assert( !pcCU->isIntra( uiAbsPartIdx) );
702    assert( pcCU->getSlice()->getIsDepth() );
703
704    decodeInterSDCResidualData( pcCU, uiAbsPartIdx, uiDepth );
705    return;
706  }
707#endif
708
709  if( pcCU->isIntra(uiAbsPartIdx) )
710  {
711  }
712  else
713  {
714    UInt uiQtRootCbf = 1;
715    if( !( pcCU->getPartitionSize( uiAbsPartIdx) == SIZE_2Nx2N && pcCU->getMergeFlag( uiAbsPartIdx ) ) )
716    {
717      m_pcEntropyDecoderIf->parseQtRootCbf( uiAbsPartIdx, uiQtRootCbf );
718    }
719    if ( !uiQtRootCbf )
720    {
721      pcCU->setCbfSubParts( 0, 0, 0, uiAbsPartIdx, uiDepth );
722      pcCU->setTrIdxSubParts( 0 , uiAbsPartIdx, uiDepth );
723      return;
724    }
725   
726  }
727  xDecodeTransform( pcCU, uiLumaOffset, uiChromaOffset, uiAbsPartIdx, uiDepth, uiWidth, uiHeight, 0, bCodeDQP );
728}
729
730#if H_3D_INTER_SDC
731Void TDecEntropy::decodeInterSDCFlag( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
732{
733  pcCU->setInterSDCFlagSubParts( false, uiAbsPartIdx, 0, uiDepth);
734
735  if( !pcCU->getSlice()->getVPS()->getInterSDCFlag( pcCU->getSlice()->getLayerIdInVps() ) )
736  {
737    return;
738  }
739
740  if( !pcCU->getSlice()->getIsDepth() || pcCU->isIntra( uiAbsPartIdx ) || pcCU->isSkipped( uiAbsPartIdx ) )
741  {
742    return;
743  }
744
745  m_pcEntropyDecoderIf->parseInterSDCFlag( pcCU, uiAbsPartIdx, uiDepth );
746}
747
748Void TDecEntropy::decodeInterSDCResidualData( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
749{
750  if( !pcCU->getSlice()->getVPS()->getInterSDCFlag( pcCU->getSlice()->getLayerIdInVps() ) )
751  {
752    return;
753  }
754
755  if( !pcCU->getSlice()->getIsDepth() || pcCU->isIntra( uiAbsPartIdx ) || !pcCU->getInterSDCFlag( uiAbsPartIdx ) )
756  {
757    return;
758  }
759
760  UInt uiNumSegments = ( pcCU->getPartitionSize( uiAbsPartIdx ) == SIZE_2Nx2N ) ? 1 : ( pcCU->getPartitionSize( uiAbsPartIdx ) == SIZE_NxN ? 4 : 2 );
761
762  // decode residual data for each segment
763  for( UInt uiSeg = 0; uiSeg < uiNumSegments; uiSeg++ )
764  {
765    m_pcEntropyDecoderIf->parseInterSDCResidualData( pcCU, uiAbsPartIdx, uiDepth, uiSeg );
766  }
767}
768#endif
769
770//! \}
Note: See TracBrowser for help on using the repository browser.