source: 3DVCSoftware/branches/HTM-DEV-0.3-dev2/source/Lib/TLibDecoder/TDecEntropy.cpp @ 521

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

Integrated following changes:

  • H_MV_FIX1071, fix of encoder side reference list construction on IRAP pictures, same as in HM11.
  • H_3D_VSO_FIX_BORDRE_EXTENSION, fixed uninitialized borders for org-yuvs in VSO
  • H_MV_ENC_DEC_TRAC, added cu/pu level trace ( only enabled when ENC_DEC_TRACE is enabled)
  • Property svn:eol-style set to native
File size: 22.0 KB
Line 
1/* The copyright in this software is being made available under the BSD
2 * License, included below. This software may be subject to other third party
3 * and contributor rights, including patent rights, and no such rights are
4 * granted under this license. 
5 *
6 * Copyright (c) 2010-2013, ITU/ISO/IEC
7 * All rights reserved.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions are met:
11 *
12 *  * Redistributions of source code must retain the above copyright notice,
13 *    this list of conditions and the following disclaimer.
14 *  * Redistributions in binary form must reproduce the above copyright notice,
15 *    this list of conditions and the following disclaimer in the documentation
16 *    and/or other materials provided with the distribution.
17 *  * Neither the name of the ITU/ISO/IEC nor the names of its contributors may
18 *    be used to endorse or promote products derived from this software without
19 *    specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS
25 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
31 * THE POSSIBILITY OF SUCH DAMAGE.
32 */
33
34/** \file     TDecEntropy.cpp
35    \brief    entropy decoder class
36*/
37
38#include "TDecEntropy.h"
39
40//! \ingroup TLibDecoder
41//! \{
42
43Void TDecEntropy::setEntropyDecoder         ( TDecEntropyIf* p )
44{
45  m_pcEntropyDecoderIf = p;
46}
47
48#include "TLibCommon/TComSampleAdaptiveOffset.h"
49
50Void TDecEntropy::decodeSkipFlag( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
51{
52  m_pcEntropyDecoderIf->parseSkipFlag( pcCU, uiAbsPartIdx, uiDepth );
53}
54
55Void TDecEntropy::decodeCUTransquantBypassFlag(TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
56{
57  m_pcEntropyDecoderIf->parseCUTransquantBypassFlag( pcCU, uiAbsPartIdx, uiDepth );
58}
59
60/** decode merge flag
61 * \param pcSubCU
62 * \param uiAbsPartIdx
63 * \param uiDepth
64 * \param uiPUIdx
65 * \returns Void
66 */
67Void TDecEntropy::decodeMergeFlag( TComDataCU* pcSubCU, UInt uiAbsPartIdx, UInt uiDepth, UInt uiPUIdx )
68{ 
69  // at least one merge candidate exists
70  m_pcEntropyDecoderIf->parseMergeFlag( pcSubCU, uiAbsPartIdx, uiDepth, uiPUIdx );
71}
72
73/** decode merge index
74 * \param pcCU
75 * \param uiPartIdx
76 * \param uiAbsPartIdx
77 * \param puhInterDirNeighbours pointer to list of inter direction from the casual neighbours
78 * \param pcMvFieldNeighbours pointer to list of motion vector field from the casual neighbours
79 * \param uiDepth
80 * \returns Void
81 */
82Void TDecEntropy::decodeMergeIndex( TComDataCU* pcCU, UInt uiPartIdx, UInt uiAbsPartIdx, UInt uiDepth )
83{
84  UInt uiMergeIndex = 0;
85  m_pcEntropyDecoderIf->parseMergeIndex( pcCU, uiMergeIndex );
86  pcCU->setMergeIndexSubParts( uiMergeIndex, uiAbsPartIdx, uiPartIdx, uiDepth );
87}
88
89#if H_3D_ARP
90Void TDecEntropy::decodeARPW( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
91{
92  if( !pcCU->getSlice()->getARPStepNum() || pcCU->isIntra( uiAbsPartIdx ) )
93  {
94    return;
95  }
96
97  if( pcCU->getPartitionSize(uiAbsPartIdx) != SIZE_2Nx2N )
98  {
99    pcCU->setARPWSubParts( 0 , uiAbsPartIdx, uiDepth );
100  }
101  else
102  {
103    m_pcEntropyDecoderIf->parseARPW( pcCU , uiAbsPartIdx , uiDepth );
104  }
105}
106#endif
107
108#if H_3D_IC
109Void TDecEntropy::decodeICFlag( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
110{
111  pcCU->setICFlagSubParts( false , uiAbsPartIdx, 0, uiDepth );
112
113  if ( pcCU->isIntra( uiAbsPartIdx ) || ( pcCU->getSlice()->getViewIndex() == 0 ) )
114  {
115    return;
116  }
117
118  if( !pcCU->getSlice()->getApplyIC() )
119    return;
120
121  if( pcCU->isICFlagRequired( uiAbsPartIdx ) )
122    m_pcEntropyDecoderIf->parseICFlag( pcCU, uiAbsPartIdx, uiDepth );
123}
124#endif
125
126Void TDecEntropy::decodeSplitFlag   ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
127{
128  m_pcEntropyDecoderIf->parseSplitFlag( pcCU, uiAbsPartIdx, uiDepth );
129}
130
131Void TDecEntropy::decodePredMode( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
132{
133  m_pcEntropyDecoderIf->parsePredMode( pcCU, uiAbsPartIdx, uiDepth );
134}
135
136Void TDecEntropy::decodePartSize( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
137{
138  m_pcEntropyDecoderIf->parsePartSize( pcCU, uiAbsPartIdx, uiDepth );
139}
140
141Void TDecEntropy::decodePredInfo    ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, TComDataCU* pcSubCU )
142{
143  if( pcCU->isIntra( uiAbsPartIdx ) )                                 // If it is Intra mode, encode intra prediction mode.
144  {
145    decodeIntraDirModeLuma  ( pcCU, uiAbsPartIdx, uiDepth );
146    decodeIntraDirModeChroma( pcCU, uiAbsPartIdx, uiDepth );
147  }
148  else                                                                // if it is Inter mode, encode motion vector and reference index
149  {
150    decodePUWise( pcCU, uiAbsPartIdx, uiDepth, pcSubCU );
151  }
152}
153
154/** Parse I_PCM information.
155 * \param pcCU  pointer to CUpointer to CU
156 * \param uiAbsPartIdx CU index
157 * \param uiDepth CU depth
158 * \returns Void
159 */
160Void TDecEntropy::decodeIPCMInfo( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
161{
162  if(!pcCU->getSlice()->getSPS()->getUsePCM()
163    || pcCU->getWidth(uiAbsPartIdx) > (1<<pcCU->getSlice()->getSPS()->getPCMLog2MaxSize())
164    || pcCU->getWidth(uiAbsPartIdx) < (1<<pcCU->getSlice()->getSPS()->getPCMLog2MinSize()) )
165  {
166    return;
167  }
168 
169  m_pcEntropyDecoderIf->parseIPCMInfo( pcCU, uiAbsPartIdx, uiDepth );
170}
171
172Void TDecEntropy::decodeIntraDirModeLuma  ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
173{
174  m_pcEntropyDecoderIf->parseIntraDirLumaAng( pcCU, uiAbsPartIdx, uiDepth );
175}
176
177Void TDecEntropy::decodeIntraDirModeChroma( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
178{
179  m_pcEntropyDecoderIf->parseIntraDirChroma( pcCU, uiAbsPartIdx, uiDepth );
180}
181
182/** decode motion information for every PU block.
183 * \param pcCU
184 * \param uiAbsPartIdx
185 * \param uiDepth
186 * \param pcSubCU
187 * \returns Void
188 */
189Void TDecEntropy::decodePUWise( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, TComDataCU* pcSubCU )
190{
191  PartSize ePartSize = pcCU->getPartitionSize( uiAbsPartIdx );
192  UInt uiNumPU = ( ePartSize == SIZE_2Nx2N ? 1 : ( ePartSize == SIZE_NxN ? 4 : 2 ) );
193  UInt uiPUOffset = ( g_auiPUOffset[UInt( ePartSize )] << ( ( pcCU->getSlice()->getSPS()->getMaxCUDepth() - uiDepth ) << 1 ) ) >> 4;
194
195#if H_3D_IV_MERGE
196  TComMvField cMvFieldNeighbours[MRG_MAX_NUM_CANDS_MEM << 1]; // double length for mv of both lists
197  UChar uhInterDirNeighbours[MRG_MAX_NUM_CANDS_MEM];
198#else
199  TComMvField cMvFieldNeighbours[MRG_MAX_NUM_CANDS << 1]; // double length for mv of both lists
200  UChar uhInterDirNeighbours[MRG_MAX_NUM_CANDS];
201#endif
202
203  for ( UInt ui = 0; ui < pcCU->getSlice()->getMaxNumMergeCand(); ui++ )
204  {
205    uhInterDirNeighbours[ui] = 0;
206  }
207  Int numValidMergeCand = 0;
208  Bool isMerged = false;
209
210  pcSubCU->copyInterPredInfoFrom( pcCU, uiAbsPartIdx, REF_PIC_LIST_0 );
211  pcSubCU->copyInterPredInfoFrom( pcCU, uiAbsPartIdx, REF_PIC_LIST_1 );
212#if H_3D_IV_MERGE
213  pcSubCU->copyDVInfoFrom( pcCU, uiAbsPartIdx);
214#endif
215  for ( UInt uiPartIdx = 0, uiSubPartIdx = uiAbsPartIdx; uiPartIdx < uiNumPU; uiPartIdx++, uiSubPartIdx += uiPUOffset )
216  {
217#if H_MV_ENC_DEC_TRAC
218    DTRACE_PU_S("=========== prediction_unit ===========\n")
219    // ToDo:
220    //DTRACE_PU("x0", uiLPelX)
221    //DTRACE_PU("x1", uiTPelY)
222#endif
223    decodeMergeFlag( pcCU, uiSubPartIdx, uiDepth, uiPartIdx );
224    if ( pcCU->getMergeFlag( uiSubPartIdx ) )
225    {
226      decodeMergeIndex( pcCU, uiPartIdx, uiSubPartIdx, uiDepth );
227      UInt uiMergeIndex = pcCU->getMergeIndex(uiSubPartIdx);
228      if ( pcCU->getSlice()->getPPS()->getLog2ParallelMergeLevelMinus2() && ePartSize != SIZE_2Nx2N && pcSubCU->getWidth( 0 ) <= 8 ) 
229      {
230        pcSubCU->setPartSizeSubParts( SIZE_2Nx2N, 0, uiDepth );
231        if ( !isMerged )
232        {
233#if H_3D_VSP
234          Int vspFlag[MRG_MAX_NUM_CANDS_MEM];
235          memset(vspFlag, 0, sizeof(Int)*MRG_MAX_NUM_CANDS_MEM);
236          pcSubCU->getInterMergeCandidates( 0, 0, cMvFieldNeighbours, uhInterDirNeighbours, vspFlag, numValidMergeCand );
237          pcCU->setVSPFlagSubParts( vspFlag[uiMergeIndex], uiSubPartIdx, uiPartIdx, uiDepth );
238#else
239          pcSubCU->getInterMergeCandidates( 0, 0, cMvFieldNeighbours, uhInterDirNeighbours, numValidMergeCand );
240#endif
241          isMerged = true;
242        }
243        pcSubCU->setPartSizeSubParts( ePartSize, 0, uiDepth );
244      }
245      else
246      {
247        uiMergeIndex = pcCU->getMergeIndex(uiSubPartIdx); // Redundant line
248#if H_3D_VSP
249        Int vspFlag[MRG_MAX_NUM_CANDS_MEM];
250        memset(vspFlag, 0, sizeof(Int)*MRG_MAX_NUM_CANDS_MEM);
251        pcSubCU->getInterMergeCandidates( uiSubPartIdx-uiAbsPartIdx, uiPartIdx, cMvFieldNeighbours, uhInterDirNeighbours, vspFlag, numValidMergeCand, uiMergeIndex );
252        pcCU->setVSPFlagSubParts( vspFlag[uiMergeIndex], uiSubPartIdx, uiPartIdx, uiDepth );
253#else
254        pcSubCU->getInterMergeCandidates( uiSubPartIdx-uiAbsPartIdx, uiPartIdx, cMvFieldNeighbours, uhInterDirNeighbours, numValidMergeCand, uiMergeIndex );
255#endif
256      }
257      pcCU->setInterDirSubParts( uhInterDirNeighbours[uiMergeIndex], uiSubPartIdx, uiPartIdx, uiDepth );
258
259      TComMv cTmpMv( 0, 0 );
260      for ( UInt uiRefListIdx = 0; uiRefListIdx < 2; uiRefListIdx++ )
261      {       
262        if ( pcCU->getSlice()->getNumRefIdx( RefPicList( uiRefListIdx ) ) > 0 )
263        {
264          pcCU->setMVPIdxSubParts( 0, RefPicList( uiRefListIdx ), uiSubPartIdx, uiPartIdx, uiDepth);
265          pcCU->setMVPNumSubParts( 0, RefPicList( uiRefListIdx ), uiSubPartIdx, uiPartIdx, uiDepth);
266          pcCU->getCUMvField( RefPicList( uiRefListIdx ) )->setAllMvd( cTmpMv, ePartSize, uiSubPartIdx, uiDepth, uiPartIdx );
267          pcCU->getCUMvField( RefPicList( uiRefListIdx ) )->setAllMvField( cMvFieldNeighbours[ 2*uiMergeIndex + uiRefListIdx ], ePartSize, uiSubPartIdx, uiDepth, uiPartIdx );
268        }
269      }
270    }
271    else
272    {
273      decodeInterDirPU( pcCU, uiSubPartIdx, uiDepth, uiPartIdx );
274      for ( UInt uiRefListIdx = 0; uiRefListIdx < 2; uiRefListIdx++ )
275      {       
276        if ( pcCU->getSlice()->getNumRefIdx( RefPicList( uiRefListIdx ) ) > 0 )
277        {
278          decodeRefFrmIdxPU( pcCU,    uiSubPartIdx,              uiDepth, uiPartIdx, RefPicList( uiRefListIdx ) );
279          decodeMvdPU      ( pcCU,    uiSubPartIdx,              uiDepth, uiPartIdx, RefPicList( uiRefListIdx ) );
280          decodeMVPIdxPU   ( pcSubCU, uiSubPartIdx-uiAbsPartIdx, uiDepth, uiPartIdx, RefPicList( uiRefListIdx ) );
281        }
282      }
283    }
284    if ( (pcCU->getInterDir(uiSubPartIdx) == 3) && pcSubCU->isBipredRestriction(uiPartIdx) )
285    {
286      pcCU->getCUMvField( REF_PIC_LIST_1 )->setAllMv( TComMv(0,0), ePartSize, uiSubPartIdx, uiDepth, uiPartIdx);
287      pcCU->getCUMvField( REF_PIC_LIST_1 )->setAllRefIdx( -1, ePartSize, uiSubPartIdx, uiDepth, uiPartIdx);
288      pcCU->setInterDirSubParts( 1, uiSubPartIdx, uiPartIdx, uiDepth);
289    }
290  }
291  return;
292}
293
294/** decode inter direction for a PU block
295 * \param pcCU
296 * \param uiAbsPartIdx
297 * \param uiDepth
298 * \param uiPartIdx
299 * \returns Void
300 */
301Void TDecEntropy::decodeInterDirPU( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, UInt uiPartIdx )
302{
303  UInt uiInterDir;
304
305  if ( pcCU->getSlice()->isInterP() )
306  {
307    uiInterDir = 1;
308  }
309  else
310  {
311    m_pcEntropyDecoderIf->parseInterDir( pcCU, uiInterDir, uiAbsPartIdx );
312  }
313
314  pcCU->setInterDirSubParts( uiInterDir, uiAbsPartIdx, uiPartIdx, uiDepth );
315}
316
317Void TDecEntropy::decodeRefFrmIdxPU( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, UInt uiPartIdx, RefPicList eRefList )
318{
319  Int iRefFrmIdx = 0;
320  Int iParseRefFrmIdx = pcCU->getInterDir( uiAbsPartIdx ) & ( 1 << eRefList );
321
322  if ( pcCU->getSlice()->getNumRefIdx( eRefList ) > 1 && iParseRefFrmIdx )
323  {
324    m_pcEntropyDecoderIf->parseRefFrmIdx( pcCU, iRefFrmIdx, eRefList );
325  }
326  else if ( !iParseRefFrmIdx )
327  {
328    iRefFrmIdx = NOT_VALID;
329  }
330  else
331  {
332    iRefFrmIdx = 0;
333  }
334
335  PartSize ePartSize = pcCU->getPartitionSize( uiAbsPartIdx );
336  pcCU->getCUMvField( eRefList )->setAllRefIdx( iRefFrmIdx, ePartSize, uiAbsPartIdx, uiDepth, uiPartIdx );
337}
338
339/** decode motion vector difference for a PU block
340 * \param pcCU
341 * \param uiAbsPartIdx
342 * \param uiDepth
343 * \param uiPartIdx
344 * \param eRefList
345 * \returns Void
346 */
347Void TDecEntropy::decodeMvdPU( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, UInt uiPartIdx, RefPicList eRefList )
348{
349  if ( pcCU->getInterDir( uiAbsPartIdx ) & ( 1 << eRefList ) )
350  {
351    m_pcEntropyDecoderIf->parseMvd( pcCU, uiAbsPartIdx, uiPartIdx, uiDepth, eRefList );
352  }
353}
354
355Void TDecEntropy::decodeMVPIdxPU( TComDataCU* pcSubCU, UInt uiPartAddr, UInt uiDepth, UInt uiPartIdx, RefPicList eRefList )
356{
357  Int iMVPIdx = -1;
358
359  TComMv cZeroMv( 0, 0 );
360  TComMv cMv     = cZeroMv;
361  Int    iRefIdx = -1;
362
363  TComCUMvField* pcSubCUMvField = pcSubCU->getCUMvField( eRefList );
364  AMVPInfo* pAMVPInfo = pcSubCUMvField->getAMVPInfo();
365
366  iRefIdx = pcSubCUMvField->getRefIdx(uiPartAddr);
367  cMv = cZeroMv;
368
369  if ( (pcSubCU->getInterDir(uiPartAddr) & ( 1 << eRefList )) )
370  {
371    m_pcEntropyDecoderIf->parseMVPIdx( iMVPIdx );
372#if H_MV_ENC_DEC_TRAC
373#if ENC_DEC_TRACE
374    if ( eRefList == REF_PIC_LIST_0 )
375    {
376      DTRACE_PU("mvp_l0_flag", iMVPIdx)
377    }
378    else
379    {
380      DTRACE_PU("mvp_l1_flag", iMVPIdx)
381    }
382#endif
383#endif
384  }
385  pcSubCU->fillMvpCand(uiPartIdx, uiPartAddr, eRefList, iRefIdx, pAMVPInfo);
386  pcSubCU->setMVPNumSubParts(pAMVPInfo->iN, eRefList, uiPartAddr, uiPartIdx, uiDepth);
387  pcSubCU->setMVPIdxSubParts( iMVPIdx, eRefList, uiPartAddr, uiPartIdx, uiDepth );
388  if ( iRefIdx >= 0 )
389  {
390    m_pcPrediction->getMvPredAMVP( pcSubCU, uiPartIdx, uiPartAddr, eRefList, cMv);
391    cMv += pcSubCUMvField->getMvd( uiPartAddr );
392  }
393
394  PartSize ePartSize = pcSubCU->getPartitionSize( uiPartAddr );
395  pcSubCU->getCUMvField( eRefList )->setAllMv(cMv, ePartSize, uiPartAddr, 0, uiPartIdx);
396}
397
398Void TDecEntropy::xDecodeTransform( TComDataCU* pcCU, UInt offsetLuma, UInt offsetChroma, UInt uiAbsPartIdx, UInt uiDepth, UInt width, UInt height, UInt uiTrIdx, Bool& bCodeDQP)
399{
400  UInt uiSubdiv;
401  const UInt uiLog2TrafoSize = g_aucConvertToBit[pcCU->getSlice()->getSPS()->getMaxCUWidth()]+2 - uiDepth;
402
403  if(uiTrIdx==0)
404  {
405    m_bakAbsPartIdxCU = uiAbsPartIdx;
406  }
407  if( uiLog2TrafoSize == 2 )
408  {
409    UInt partNum = pcCU->getPic()->getNumPartInCU() >> ( ( uiDepth - 1 ) << 1 );
410    if( ( uiAbsPartIdx % partNum ) == 0 )
411    {
412      m_uiBakAbsPartIdx   = uiAbsPartIdx;
413      m_uiBakChromaOffset = offsetChroma;
414    }
415  }
416  if( pcCU->getPredictionMode(uiAbsPartIdx) == MODE_INTRA && pcCU->getPartitionSize(uiAbsPartIdx) == SIZE_NxN && uiDepth == pcCU->getDepth(uiAbsPartIdx) )
417  {
418    uiSubdiv = 1;
419  }
420  else if( (pcCU->getSlice()->getSPS()->getQuadtreeTUMaxDepthInter() == 1) && (pcCU->getPredictionMode(uiAbsPartIdx) == MODE_INTER) && ( pcCU->getPartitionSize(uiAbsPartIdx) != SIZE_2Nx2N ) && (uiDepth == pcCU->getDepth(uiAbsPartIdx)) )
421  {
422    uiSubdiv = (uiLog2TrafoSize > pcCU->getQuadtreeTULog2MinSizeInCU(uiAbsPartIdx));
423  }
424  else if( uiLog2TrafoSize > pcCU->getSlice()->getSPS()->getQuadtreeTULog2MaxSize() )
425  {
426    uiSubdiv = 1;
427  }
428  else if( uiLog2TrafoSize == pcCU->getSlice()->getSPS()->getQuadtreeTULog2MinSize() )
429  {
430    uiSubdiv = 0;
431  }
432  else if( uiLog2TrafoSize == pcCU->getQuadtreeTULog2MinSizeInCU(uiAbsPartIdx) )
433  {
434    uiSubdiv = 0;
435  }
436  else
437  {
438    assert( uiLog2TrafoSize > pcCU->getQuadtreeTULog2MinSizeInCU(uiAbsPartIdx) );
439    m_pcEntropyDecoderIf->parseTransformSubdivFlag( uiSubdiv, 5 - uiLog2TrafoSize );
440  }
441 
442  const UInt uiTrDepth = uiDepth - pcCU->getDepth( uiAbsPartIdx );
443  {
444    const Bool bFirstCbfOfCU = uiTrDepth == 0;
445    if( bFirstCbfOfCU )
446    {
447      pcCU->setCbfSubParts( 0, TEXT_CHROMA_U, uiAbsPartIdx, uiDepth );
448      pcCU->setCbfSubParts( 0, TEXT_CHROMA_V, uiAbsPartIdx, uiDepth );
449    }
450    if( bFirstCbfOfCU || uiLog2TrafoSize > 2 )
451    {
452      if( bFirstCbfOfCU || pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_U, uiTrDepth - 1 ) )
453      {
454        m_pcEntropyDecoderIf->parseQtCbf( pcCU, uiAbsPartIdx, TEXT_CHROMA_U, uiTrDepth, uiDepth );
455      }
456      if( bFirstCbfOfCU || pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_V, uiTrDepth - 1 ) )
457      {
458        m_pcEntropyDecoderIf->parseQtCbf( pcCU, uiAbsPartIdx, TEXT_CHROMA_V, uiTrDepth, uiDepth );
459      }
460    }
461    else
462    {
463      pcCU->setCbfSubParts( pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_U, uiTrDepth - 1 ) << uiTrDepth, TEXT_CHROMA_U, uiAbsPartIdx, uiDepth );
464      pcCU->setCbfSubParts( pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_V, uiTrDepth - 1 ) << uiTrDepth, TEXT_CHROMA_V, uiAbsPartIdx, uiDepth );
465    }
466  }
467 
468  if( uiSubdiv )
469  {
470    UInt size;
471    width  >>= 1;
472    height >>= 1;
473    size = width*height;
474    uiTrIdx++;
475    ++uiDepth;
476    const UInt uiQPartNum = pcCU->getPic()->getNumPartInCU() >> (uiDepth << 1);
477    const UInt uiStartAbsPartIdx = uiAbsPartIdx;
478    UInt uiYCbf = 0;
479    UInt uiUCbf = 0;
480    UInt uiVCbf = 0;
481   
482    for( Int i = 0; i < 4; i++ )
483    {
484      xDecodeTransform( pcCU, offsetLuma, offsetChroma, uiAbsPartIdx, uiDepth, width, height, uiTrIdx, bCodeDQP );
485      uiYCbf |= pcCU->getCbf( uiAbsPartIdx, TEXT_LUMA, uiTrDepth+1 );
486      uiUCbf |= pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_U, uiTrDepth+1 );
487      uiVCbf |= pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_V, uiTrDepth+1 );
488      uiAbsPartIdx += uiQPartNum;
489      offsetLuma += size;  offsetChroma += (size>>2);
490    }
491   
492    for( UInt ui = 0; ui < 4 * uiQPartNum; ++ui )
493    {
494      pcCU->getCbf( TEXT_LUMA     )[uiStartAbsPartIdx + ui] |= uiYCbf << uiTrDepth;
495      pcCU->getCbf( TEXT_CHROMA_U )[uiStartAbsPartIdx + ui] |= uiUCbf << uiTrDepth;
496      pcCU->getCbf( TEXT_CHROMA_V )[uiStartAbsPartIdx + ui] |= uiVCbf << uiTrDepth;
497    }
498  }
499  else
500  {
501    assert( uiDepth >= pcCU->getDepth( uiAbsPartIdx ) );
502    pcCU->setTrIdxSubParts( uiTrDepth, uiAbsPartIdx, uiDepth );
503   
504#if !H_MV_ENC_DEC_TRAC
505    {
506      DTRACE_CABAC_VL( g_nSymbolCounter++ );
507      DTRACE_CABAC_T( "\tTrIdx: abspart=" );
508      DTRACE_CABAC_V( uiAbsPartIdx );
509      DTRACE_CABAC_T( "\tdepth=" );
510      DTRACE_CABAC_V( uiDepth );
511      DTRACE_CABAC_T( "\ttrdepth=" );
512      DTRACE_CABAC_V( uiTrDepth );
513      DTRACE_CABAC_T( "\n" );
514    }
515#endif
516   
517    pcCU->setCbfSubParts ( 0, TEXT_LUMA, uiAbsPartIdx, uiDepth );
518    if( pcCU->getPredictionMode(uiAbsPartIdx) != MODE_INTRA && uiDepth == pcCU->getDepth( uiAbsPartIdx ) && !pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_U, 0 ) && !pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_V, 0 ) )
519    {
520      pcCU->setCbfSubParts( 1 << uiTrDepth, TEXT_LUMA, uiAbsPartIdx, uiDepth );
521    }
522    else
523    {
524      m_pcEntropyDecoderIf->parseQtCbf( pcCU, uiAbsPartIdx, TEXT_LUMA, uiTrDepth, uiDepth );
525    }
526
527
528    // transform_unit begin
529    UInt cbfY = pcCU->getCbf( uiAbsPartIdx, TEXT_LUMA    , uiTrIdx );
530    UInt cbfU = pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_U, uiTrIdx );
531    UInt cbfV = pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_V, uiTrIdx );
532    if( uiLog2TrafoSize == 2 )
533    {
534      UInt partNum = pcCU->getPic()->getNumPartInCU() >> ( ( uiDepth - 1 ) << 1 );
535      if( ( uiAbsPartIdx % partNum ) == (partNum - 1) )
536      {
537        cbfU = pcCU->getCbf( m_uiBakAbsPartIdx, TEXT_CHROMA_U, uiTrIdx );
538        cbfV = pcCU->getCbf( m_uiBakAbsPartIdx, TEXT_CHROMA_V, uiTrIdx );
539      }
540    }
541    if ( cbfY || cbfU || cbfV )
542    {
543      // dQP: only for LCU
544      if ( pcCU->getSlice()->getPPS()->getUseDQP() )
545      {
546        if ( bCodeDQP )
547        {
548          decodeQP( pcCU, m_bakAbsPartIdxCU);
549          bCodeDQP = false;
550        }
551      }
552    }
553    if( cbfY )
554    {
555      Int trWidth = width;
556      Int trHeight = height;
557      m_pcEntropyDecoderIf->parseCoeffNxN( pcCU, (pcCU->getCoeffY()+offsetLuma), uiAbsPartIdx, trWidth, trHeight, uiDepth, TEXT_LUMA );
558    }
559    if( uiLog2TrafoSize > 2 )
560    {
561      Int trWidth = width >> 1;
562      Int trHeight = height >> 1;
563      if( cbfU )
564      {
565        m_pcEntropyDecoderIf->parseCoeffNxN( pcCU, (pcCU->getCoeffCb()+offsetChroma), uiAbsPartIdx, trWidth, trHeight, uiDepth, TEXT_CHROMA_U );
566      }
567      if( cbfV )
568      {
569        m_pcEntropyDecoderIf->parseCoeffNxN( pcCU, (pcCU->getCoeffCr()+offsetChroma), uiAbsPartIdx, trWidth, trHeight, uiDepth, TEXT_CHROMA_V );
570      }
571    }
572    else
573    {
574      UInt partNum = pcCU->getPic()->getNumPartInCU() >> ( ( uiDepth - 1 ) << 1 );
575      if( ( uiAbsPartIdx % partNum ) == (partNum - 1) )
576      {
577        Int trWidth = width;
578        Int trHeight = height;
579        if( cbfU )
580        {
581          m_pcEntropyDecoderIf->parseCoeffNxN( pcCU, (pcCU->getCoeffCb()+m_uiBakChromaOffset), m_uiBakAbsPartIdx, trWidth, trHeight, uiDepth, TEXT_CHROMA_U );
582        }
583        if( cbfV )
584        {
585          m_pcEntropyDecoderIf->parseCoeffNxN( pcCU, (pcCU->getCoeffCr()+m_uiBakChromaOffset), m_uiBakAbsPartIdx, trWidth, trHeight, uiDepth, TEXT_CHROMA_V );
586        }
587      }
588    }
589    // transform_unit end
590  }
591}
592
593Void TDecEntropy::decodeQP          ( TComDataCU* pcCU, UInt uiAbsPartIdx )
594{
595  if ( pcCU->getSlice()->getPPS()->getUseDQP() )
596  {
597    m_pcEntropyDecoderIf->parseDeltaQP( pcCU, uiAbsPartIdx, pcCU->getDepth( uiAbsPartIdx ) );
598  }
599}
600
601
602/** decode coefficients
603 * \param pcCU
604 * \param uiAbsPartIdx
605 * \param uiDepth
606 * \param uiWidth
607 * \param uiHeight
608 * \returns Void
609 */
610Void TDecEntropy::decodeCoeff( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, UInt uiWidth, UInt uiHeight, Bool& bCodeDQP )
611{
612  UInt uiMinCoeffSize = pcCU->getPic()->getMinCUWidth()*pcCU->getPic()->getMinCUHeight();
613  UInt uiLumaOffset   = uiMinCoeffSize*uiAbsPartIdx;
614  UInt uiChromaOffset = uiLumaOffset>>2;
615 
616  if( pcCU->isIntra(uiAbsPartIdx) )
617  {
618  }
619  else
620  {
621    UInt uiQtRootCbf = 1;
622    if( !( pcCU->getPartitionSize( uiAbsPartIdx) == SIZE_2Nx2N && pcCU->getMergeFlag( uiAbsPartIdx ) ) )
623    {
624      m_pcEntropyDecoderIf->parseQtRootCbf( uiAbsPartIdx, uiQtRootCbf );
625    }
626    if ( !uiQtRootCbf )
627    {
628      pcCU->setCbfSubParts( 0, 0, 0, uiAbsPartIdx, uiDepth );
629      pcCU->setTrIdxSubParts( 0 , uiAbsPartIdx, uiDepth );
630      return;
631    }
632   
633  }
634  xDecodeTransform( pcCU, uiLumaOffset, uiChromaOffset, uiAbsPartIdx, uiDepth, uiWidth, uiHeight, 0, bCodeDQP );
635}
636
637//! \}
Note: See TracBrowser for help on using the repository browser.