source: 3DVCSoftware/branches/HTM-16.0-MV-draft-5/source/Lib/TLibDecoder/TDecEntropy.cpp

Last change on this file was 1390, checked in by tech, 9 years ago

Removed 3D.

  • Property svn:eol-style set to native
File size: 23.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-2015, 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#include "TLibCommon/TComTU.h"
40#include "TLibCommon/TComPrediction.h"
41
42#if ENVIRONMENT_VARIABLE_DEBUG_AND_TEST
43#include "../TLibCommon/Debug.h"
44static const Bool bDebugRQT = DebugOptionList::DebugRQT.getInt()!=0;
45static const Bool bDebugPredEnabled = DebugOptionList::DebugPred.getInt()!=0;
46#endif
47
48//! \ingroup TLibDecoder
49//! \{
50
51Void TDecEntropy::setEntropyDecoder         ( TDecEntropyIf* p )
52{
53  m_pcEntropyDecoderIf = p;
54}
55
56#include "TLibCommon/TComSampleAdaptiveOffset.h"
57
58Void TDecEntropy::decodeSkipFlag( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
59{
60  m_pcEntropyDecoderIf->parseSkipFlag( pcCU, uiAbsPartIdx, uiDepth );
61}
62
63Void TDecEntropy::decodeCUTransquantBypassFlag(TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
64{
65  m_pcEntropyDecoderIf->parseCUTransquantBypassFlag( pcCU, uiAbsPartIdx, uiDepth );
66}
67
68
69/** decode merge flag
70 * \param pcSubCU
71 * \param uiAbsPartIdx
72 * \param uiDepth
73 * \param uiPUIdx
74 * \returns Void
75 */
76Void TDecEntropy::decodeMergeFlag( TComDataCU* pcSubCU, UInt uiAbsPartIdx, UInt uiDepth, UInt uiPUIdx )
77{
78  // at least one merge candidate exists
79  m_pcEntropyDecoderIf->parseMergeFlag( pcSubCU, uiAbsPartIdx, uiDepth, uiPUIdx );
80}
81
82/** decode merge index
83 * \param pcCU
84 * \param uiPartIdx
85 * \param uiAbsPartIdx
86 * \param uiDepth
87 * \returns Void
88 */
89Void TDecEntropy::decodeMergeIndex( TComDataCU* pcCU, UInt uiPartIdx, UInt uiAbsPartIdx, UInt uiDepth )
90{
91  UInt uiMergeIndex = 0;
92  m_pcEntropyDecoderIf->parseMergeIndex( pcCU, uiMergeIndex );
93  pcCU->setMergeIndexSubParts( uiMergeIndex, uiAbsPartIdx, uiPartIdx, uiDepth );
94}
95
96
97
98Void TDecEntropy::decodeSplitFlag   ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
99{
100  m_pcEntropyDecoderIf->parseSplitFlag( pcCU, uiAbsPartIdx, uiDepth );
101}
102
103Void TDecEntropy::decodePredMode( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
104{
105  m_pcEntropyDecoderIf->parsePredMode( pcCU, uiAbsPartIdx, uiDepth );
106}
107
108Void TDecEntropy::decodePartSize( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
109{
110  m_pcEntropyDecoderIf->parsePartSize( pcCU, uiAbsPartIdx, uiDepth );
111}
112
113Void TDecEntropy::decodePredInfo    ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, TComDataCU* pcSubCU )
114{
115  if( pcCU->isIntra( uiAbsPartIdx ) )                                 // If it is Intra mode, encode intra prediction mode.
116  {
117    decodeIntraDirModeLuma  ( pcCU, uiAbsPartIdx, uiDepth );
118    if (pcCU->getPic()->getChromaFormat()!=CHROMA_400)
119    {
120      decodeIntraDirModeChroma( pcCU, uiAbsPartIdx, uiDepth );
121      if (enable4ChromaPUsInIntraNxNCU(pcCU->getPic()->getChromaFormat()) && pcCU->getPartitionSize( uiAbsPartIdx )==SIZE_NxN)
122      {
123        UInt uiPartOffset = ( pcCU->getPic()->getNumPartitionsInCtu() >> ( pcCU->getDepth(uiAbsPartIdx) << 1 ) ) >> 2;
124        decodeIntraDirModeChroma( pcCU, uiAbsPartIdx + uiPartOffset,   uiDepth+1 );
125        decodeIntraDirModeChroma( pcCU, uiAbsPartIdx + uiPartOffset*2, uiDepth+1 );
126        decodeIntraDirModeChroma( pcCU, uiAbsPartIdx + uiPartOffset*3, uiDepth+1 );
127      }
128    }
129  }
130  else                                                                // if it is Inter mode, encode motion vector and reference index
131  {
132    decodePUWise( pcCU, uiAbsPartIdx, uiDepth, pcSubCU );
133  }
134}
135
136/** Parse I_PCM information.
137 * \param pcCU  pointer to CUpointer to CU
138 * \param uiAbsPartIdx CU index
139 * \param uiDepth CU depth
140 * \returns Void
141 */
142Void TDecEntropy::decodeIPCMInfo( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
143{
144  if(!pcCU->getSlice()->getSPS()->getUsePCM()
145    || pcCU->getWidth(uiAbsPartIdx) > (1<<pcCU->getSlice()->getSPS()->getPCMLog2MaxSize())
146    || pcCU->getWidth(uiAbsPartIdx) < (1<<pcCU->getSlice()->getSPS()->getPCMLog2MinSize()) )
147  {
148    return;
149  }
150
151  m_pcEntropyDecoderIf->parseIPCMInfo( pcCU, uiAbsPartIdx, uiDepth );
152}
153
154Void TDecEntropy::decodeIntraDirModeLuma  ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
155{
156  m_pcEntropyDecoderIf->parseIntraDirLumaAng( pcCU, uiAbsPartIdx, uiDepth );
157}
158
159Void TDecEntropy::decodeIntraDirModeChroma( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
160{
161  m_pcEntropyDecoderIf->parseIntraDirChroma( pcCU, uiAbsPartIdx, uiDepth );
162#if ENVIRONMENT_VARIABLE_DEBUG_AND_TEST
163  if (bDebugPredEnabled)
164  {
165    UInt cdir=pcCU->getIntraDir(CHANNEL_TYPE_CHROMA, uiAbsPartIdx);
166    if (cdir==36)
167    {
168      cdir=pcCU->getIntraDir(CHANNEL_TYPE_LUMA, uiAbsPartIdx);
169    }
170    printf("coding chroma Intra dir: %d, uiAbsPartIdx: %d, luma dir: %d\n", cdir, uiAbsPartIdx, pcCU->getIntraDir(CHANNEL_TYPE_LUMA, uiAbsPartIdx));
171  }
172#endif
173}
174
175
176/** decode motion information for every PU block.
177 * \param pcCU
178 * \param uiAbsPartIdx
179 * \param uiDepth
180 * \param pcSubCU
181 * \returns Void
182 */
183Void TDecEntropy::decodePUWise( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, TComDataCU* pcSubCU )
184{
185  PartSize ePartSize = pcCU->getPartitionSize( uiAbsPartIdx );
186  UInt uiNumPU = ( ePartSize == SIZE_2Nx2N ? 1 : ( ePartSize == SIZE_NxN ? 4 : 2 ) );
187  UInt uiPUOffset = ( g_auiPUOffset[UInt( ePartSize )] << ( ( pcCU->getSlice()->getSPS()->getMaxTotalCUDepth() - uiDepth ) << 1 ) ) >> 4;
188
189  TComMvField cMvFieldNeighbours[MRG_MAX_NUM_CANDS << 1]; // double length for mv of both lists
190  UChar uhInterDirNeighbours[MRG_MAX_NUM_CANDS];
191  for ( UInt ui = 0; ui < pcCU->getSlice()->getMaxNumMergeCand(); ui++ )
192  {
193    uhInterDirNeighbours[ui] = 0;
194  }
195  Int numValidMergeCand = 0;
196  Bool hasMergedCandList = false;
197
198  pcSubCU->copyInterPredInfoFrom( pcCU, uiAbsPartIdx, REF_PIC_LIST_0 );
199  pcSubCU->copyInterPredInfoFrom( pcCU, uiAbsPartIdx, REF_PIC_LIST_1 );
200  for ( UInt uiPartIdx = 0, uiSubPartIdx = uiAbsPartIdx; uiPartIdx < uiNumPU; uiPartIdx++, uiSubPartIdx += uiPUOffset )
201  {
202#if NH_MV_ENC_DEC_TRAC
203    DTRACE_PU_S("=========== prediction_unit ===========\n")
204    // ToDo:
205    //DTRACE_PU("x0", uiLPelX)
206    //DTRACE_PU("x1", uiTPelY)
207#endif
208    decodeMergeFlag( pcCU, uiSubPartIdx, uiDepth, uiPartIdx );
209    if ( pcCU->getMergeFlag( uiSubPartIdx ) )
210    {
211      decodeMergeIndex( pcCU, uiPartIdx, uiSubPartIdx, uiDepth );
212#if ENVIRONMENT_VARIABLE_DEBUG_AND_TEST
213      if (bDebugPredEnabled)
214      {
215        std::cout << "Coded merge flag, CU absPartIdx: " << uiAbsPartIdx << " PU(" << uiPartIdx << ") absPartIdx: " << uiSubPartIdx;
216        std::cout << " merge index: " << (UInt)pcCU->getMergeIndex(uiSubPartIdx) << std::endl;
217      }
218#endif
219
220      const UInt uiMergeIndex = pcCU->getMergeIndex(uiSubPartIdx);
221      if ( pcCU->getSlice()->getPPS()->getLog2ParallelMergeLevelMinus2() && ePartSize != SIZE_2Nx2N && pcSubCU->getWidth( 0 ) <= 8 )
222      {
223        if ( !hasMergedCandList )
224        {
225          pcSubCU->setPartSizeSubParts( SIZE_2Nx2N, 0, uiDepth ); // temporarily set.
226
227          pcSubCU->getInterMergeCandidates( 0, 0, cMvFieldNeighbours, uhInterDirNeighbours, numValidMergeCand );
228          pcSubCU->setPartSizeSubParts( ePartSize, 0, uiDepth ); // restore.
229          hasMergedCandList = true;
230        }
231      }
232      else
233      {
234
235        pcSubCU->getInterMergeCandidates( uiSubPartIdx-uiAbsPartIdx, uiPartIdx, cMvFieldNeighbours, uhInterDirNeighbours, numValidMergeCand, uiMergeIndex );
236      }
237
238      pcCU->setInterDirSubParts( uhInterDirNeighbours[uiMergeIndex], uiSubPartIdx, uiPartIdx, uiDepth );
239
240      TComMv cTmpMv( 0, 0 );
241      for ( UInt uiRefListIdx = 0; uiRefListIdx < 2; uiRefListIdx++ )
242      {
243        if ( pcCU->getSlice()->getNumRefIdx( RefPicList( uiRefListIdx ) ) > 0 )
244        {
245          pcCU->setMVPIdxSubParts( 0, RefPicList( uiRefListIdx ), uiSubPartIdx, uiPartIdx, uiDepth);
246          pcCU->setMVPNumSubParts( 0, RefPicList( uiRefListIdx ), uiSubPartIdx, uiPartIdx, uiDepth);
247          pcCU->getCUMvField( RefPicList( uiRefListIdx ) )->setAllMvd( cTmpMv, ePartSize, uiSubPartIdx, uiDepth, uiPartIdx );
248          pcCU->getCUMvField( RefPicList( uiRefListIdx ) )->setAllMvField( cMvFieldNeighbours[ 2*uiMergeIndex + uiRefListIdx ], ePartSize, uiSubPartIdx, uiDepth, uiPartIdx );
249        }
250      }
251    }
252    else
253    {
254      decodeInterDirPU( pcCU, uiSubPartIdx, uiDepth, uiPartIdx );
255      for ( UInt uiRefListIdx = 0; uiRefListIdx < 2; uiRefListIdx++ )
256      {
257        if ( pcCU->getSlice()->getNumRefIdx( RefPicList( uiRefListIdx ) ) > 0 )
258        {
259          decodeRefFrmIdxPU( pcCU,    uiSubPartIdx,              uiDepth, uiPartIdx, RefPicList( uiRefListIdx ) );
260          decodeMvdPU      ( pcCU,    uiSubPartIdx,              uiDepth, uiPartIdx, RefPicList( uiRefListIdx ) );
261          decodeMVPIdxPU   ( pcSubCU, uiSubPartIdx-uiAbsPartIdx, uiDepth, uiPartIdx, RefPicList( uiRefListIdx ) );
262#if ENVIRONMENT_VARIABLE_DEBUG_AND_TEST
263          if (bDebugPredEnabled)
264          {
265            std::cout << "refListIdx: " << uiRefListIdx << std::endl;
266            std::cout << "MVD horizontal: " << pcCU->getCUMvField(RefPicList(uiRefListIdx))->getMvd( uiAbsPartIdx ).getHor() << std::endl;
267            std::cout << "MVD vertical:   " << pcCU->getCUMvField(RefPicList(uiRefListIdx))->getMvd( uiAbsPartIdx ).getVer() << std::endl;
268            std::cout << "MVPIdxPU: " << pcCU->getMVPIdx(RefPicList( uiRefListIdx ), uiSubPartIdx) << std::endl;
269            std::cout << "InterDir: " << (UInt)pcCU->getInterDir(uiSubPartIdx) << std::endl;
270          }
271#endif
272        }
273      } 
274    }
275
276    if ( (pcCU->getInterDir(uiSubPartIdx) == 3) && pcSubCU->isBipredRestriction(uiPartIdx) )
277    {
278      pcCU->getCUMvField( REF_PIC_LIST_1 )->setAllMv( TComMv(0,0), ePartSize, uiSubPartIdx, uiDepth, uiPartIdx);
279      pcCU->getCUMvField( REF_PIC_LIST_1 )->setAllRefIdx( -1, ePartSize, uiSubPartIdx, uiDepth, uiPartIdx);
280      pcCU->setInterDirSubParts( 1, uiSubPartIdx, uiPartIdx, uiDepth);
281    }
282  }
283  return;
284}
285
286/** decode inter direction for a PU block
287 * \param pcCU
288 * \param uiAbsPartIdx
289 * \param uiDepth
290 * \param uiPartIdx
291 * \returns Void
292 */
293Void TDecEntropy::decodeInterDirPU( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, UInt uiPartIdx )
294{
295  UInt uiInterDir;
296
297  if ( pcCU->getSlice()->isInterP() )
298  {
299    uiInterDir = 1;
300  }
301  else
302  {
303    m_pcEntropyDecoderIf->parseInterDir( pcCU, uiInterDir, uiAbsPartIdx );
304  }
305
306  pcCU->setInterDirSubParts( uiInterDir, uiAbsPartIdx, uiPartIdx, uiDepth );
307}
308
309Void TDecEntropy::decodeRefFrmIdxPU( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, UInt uiPartIdx, RefPicList eRefList )
310{
311  Int iRefFrmIdx = 0;
312  Int iParseRefFrmIdx = pcCU->getInterDir( uiAbsPartIdx ) & ( 1 << eRefList );
313
314  if ( pcCU->getSlice()->getNumRefIdx( eRefList ) > 1 && iParseRefFrmIdx )
315  {
316    m_pcEntropyDecoderIf->parseRefFrmIdx( pcCU, iRefFrmIdx, eRefList );
317  }
318  else if ( !iParseRefFrmIdx )
319  {
320    iRefFrmIdx = NOT_VALID;
321  }
322  else
323  {
324    iRefFrmIdx = 0;
325  }
326
327  PartSize ePartSize = pcCU->getPartitionSize( uiAbsPartIdx );
328  pcCU->getCUMvField( eRefList )->setAllRefIdx( iRefFrmIdx, ePartSize, uiAbsPartIdx, uiDepth, uiPartIdx );
329}
330
331/** decode motion vector difference for a PU block
332 * \param pcCU
333 * \param uiAbsPartIdx
334 * \param uiDepth
335 * \param uiPartIdx
336 * \param eRefList
337 * \returns Void
338 */
339Void TDecEntropy::decodeMvdPU( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, UInt uiPartIdx, RefPicList eRefList )
340{
341  if ( pcCU->getInterDir( uiAbsPartIdx ) & ( 1 << eRefList ) )
342  {
343    m_pcEntropyDecoderIf->parseMvd( pcCU, uiAbsPartIdx, uiPartIdx, uiDepth, eRefList );
344  }
345}
346
347Void TDecEntropy::decodeMVPIdxPU( TComDataCU* pcSubCU, UInt uiPartAddr, UInt uiDepth, UInt uiPartIdx, RefPicList eRefList )
348{
349  Int iMVPIdx = -1;
350
351  TComMv cZeroMv( 0, 0 );
352  TComMv cMv     = cZeroMv;
353  Int    iRefIdx = -1;
354
355  TComCUMvField* pcSubCUMvField = pcSubCU->getCUMvField( eRefList );
356  AMVPInfo* pAMVPInfo = pcSubCUMvField->getAMVPInfo();
357
358  iRefIdx = pcSubCUMvField->getRefIdx(uiPartAddr);
359  cMv = cZeroMv;
360
361  if ( (pcSubCU->getInterDir(uiPartAddr) & ( 1 << eRefList )) )
362  {
363    m_pcEntropyDecoderIf->parseMVPIdx( iMVPIdx );
364#if NH_MV_ENC_DEC_TRAC
365#if ENC_DEC_TRACE
366    if ( eRefList == REF_PIC_LIST_0 )
367    {
368      DTRACE_PU("mvp_l0_flag", iMVPIdx)
369    }
370    else
371    {
372      DTRACE_PU("mvp_l1_flag", iMVPIdx)
373    }
374#endif
375#endif
376  }
377  pcSubCU->fillMvpCand(uiPartIdx, uiPartAddr, eRefList, iRefIdx, pAMVPInfo);
378  pcSubCU->setMVPNumSubParts(pAMVPInfo->iN, eRefList, uiPartAddr, uiPartIdx, uiDepth);
379  pcSubCU->setMVPIdxSubParts( iMVPIdx, eRefList, uiPartAddr, uiPartIdx, uiDepth );
380  if ( iRefIdx >= 0 )
381  {
382    m_pcPrediction->getMvPredAMVP( pcSubCU, uiPartIdx, uiPartAddr, eRefList, cMv);
383    cMv += pcSubCUMvField->getMvd( uiPartAddr );
384  }
385
386  PartSize ePartSize = pcSubCU->getPartitionSize( uiPartAddr );
387  pcSubCU->getCUMvField( eRefList )->setAllMv(cMv, ePartSize, uiPartAddr, 0, uiPartIdx);
388}
389
390Void TDecEntropy::xDecodeTransform        ( Bool& bCodeDQP, Bool& isChromaQpAdjCoded, TComTU &rTu, const Int quadtreeTULog2MinSizeInCU )
391{
392
393  TComDataCU *pcCU=rTu.getCU();
394  const UInt uiAbsPartIdx=rTu.GetAbsPartIdxTU();
395  const UInt uiDepth=rTu.GetTransformDepthTotal();
396  const UInt uiTrDepth = rTu.GetTransformDepthRel();
397
398#if NH_MV_ENC_DEC_TRAC
399#if ENC_DEC_TRACE
400  UInt uiLPelX   = pcCU->getCUPelX() + g_auiRasterToPelX[ g_auiZscanToRaster[uiAbsPartIdx] ];
401  UInt uiTPelY   = pcCU->getCUPelY() + g_auiRasterToPelY[ g_auiZscanToRaster[uiAbsPartIdx] ];
402
403  DTRACE_TU_S("=========== transform_tree ===========\n")
404  DTRACE_TU("x0", uiLPelX)
405  DTRACE_TU("x1", uiTPelY)
406 
407  DTRACE_TU("log2TrafoSize", pcCU->getSlice()->getSPS()->getMaxCUWidth()  >> uiDepth )
408  DTRACE_TU("trafoDepth"  , uiDepth)
409#endif
410#endif
411
412  UInt uiSubdiv;
413  const UInt numValidComponent = pcCU->getPic()->getNumberValidComponents();
414  const Bool bChroma = isChromaEnabled(pcCU->getPic()->getChromaFormat());
415
416  const UInt uiLog2TrafoSize = rTu.GetLog2LumaTrSize();
417#if ENVIRONMENT_VARIABLE_DEBUG_AND_TEST
418  if (bDebugRQT)
419  {
420    printf("x..codeTransform: offsetLuma=%d offsetChroma=%d absPartIdx=%d, uiDepth=%d\n width=%d, height=%d, uiTrIdx=%d, uiInnerQuadIdx=%d\n",
421        rTu.getCoefficientOffset(COMPONENT_Y), rTu.getCoefficientOffset(COMPONENT_Cb), uiAbsPartIdx, uiDepth, rTu.getRect(COMPONENT_Y).width, rTu.getRect(COMPONENT_Y).height, rTu.GetTransformDepthRel(), rTu.GetSectionNumber());
422    fflush(stdout);
423  }
424#endif
425
426  if( pcCU->isIntra(uiAbsPartIdx) && pcCU->getPartitionSize(uiAbsPartIdx) == SIZE_NxN && uiDepth == pcCU->getDepth(uiAbsPartIdx) )
427  {
428    uiSubdiv = 1;
429  }
430  else if( (pcCU->getSlice()->getSPS()->getQuadtreeTUMaxDepthInter() == 1) && (pcCU->isInter(uiAbsPartIdx)) && ( pcCU->getPartitionSize(uiAbsPartIdx) != SIZE_2Nx2N ) && (uiDepth == pcCU->getDepth(uiAbsPartIdx)) )
431  {
432    uiSubdiv = (uiLog2TrafoSize >quadtreeTULog2MinSizeInCU);
433  }
434  else if( uiLog2TrafoSize > pcCU->getSlice()->getSPS()->getQuadtreeTULog2MaxSize() )
435  {
436    uiSubdiv = 1;
437  }
438  else if( uiLog2TrafoSize == pcCU->getSlice()->getSPS()->getQuadtreeTULog2MinSize() )
439  {
440    uiSubdiv = 0;
441  }
442  else if( uiLog2TrafoSize == quadtreeTULog2MinSizeInCU )
443  {
444    uiSubdiv = 0;
445  }
446  else
447  {
448    assert( uiLog2TrafoSize > quadtreeTULog2MinSizeInCU );
449    m_pcEntropyDecoderIf->parseTransformSubdivFlag( uiSubdiv, 5 - uiLog2TrafoSize );
450  }
451
452  for(Int chan=COMPONENT_Cb; chan<numValidComponent; chan++)
453  {
454    const ComponentID compID=ComponentID(chan);
455    const UInt trDepthTotalAdj=rTu.GetTransformDepthTotalAdj(compID);
456
457    const Bool bFirstCbfOfCU = uiTrDepth == 0;
458
459    if( bFirstCbfOfCU )
460    {
461      pcCU->setCbfSubParts( 0, compID, rTu.GetAbsPartIdxTU(compID), trDepthTotalAdj);
462    }
463    if( bFirstCbfOfCU || rTu.ProcessingAllQuadrants(compID) )
464    {
465      if( bFirstCbfOfCU || pcCU->getCbf( uiAbsPartIdx, compID, uiTrDepth - 1 ) )
466      {
467        m_pcEntropyDecoderIf->parseQtCbf( rTu, compID, (uiSubdiv == 0) );
468      }
469    }
470  }
471
472  if( uiSubdiv )
473  {
474    const UInt uiQPartNum = pcCU->getPic()->getNumPartitionsInCtu() >> ((uiDepth+1) << 1);
475    UInt uiYUVCbf[MAX_NUM_COMPONENT] = {0,0,0};
476
477    TComTURecurse tuRecurseChild(rTu, true);
478
479    do
480    {
481      xDecodeTransform( bCodeDQP, isChromaQpAdjCoded, tuRecurseChild, quadtreeTULog2MinSizeInCU );
482      UInt childTUAbsPartIdx=tuRecurseChild.GetAbsPartIdxTU();
483      for(UInt ch=0; ch<numValidComponent; ch++)
484      {
485        uiYUVCbf[ch] |= pcCU->getCbf(childTUAbsPartIdx , ComponentID(ch),  uiTrDepth+1 );
486      }
487    } while (tuRecurseChild.nextSection(rTu) );
488
489    for(UInt ch=0; ch<numValidComponent; ch++)
490    {
491      UChar *pBase = pcCU->getCbf( ComponentID(ch) ) + uiAbsPartIdx;
492      const UChar flag = uiYUVCbf[ch] << uiTrDepth;
493
494      for( UInt ui = 0; ui < 4 * uiQPartNum; ++ui )
495      {
496        pBase[ui] |= flag;
497      }
498    }
499  }
500  else
501  {
502    assert( uiDepth >= pcCU->getDepth( uiAbsPartIdx ) );
503    pcCU->setTrIdxSubParts( uiTrDepth, uiAbsPartIdx, uiDepth );
504
505#if !NH_MV_ENC_DEC_TRAC
506    {
507      DTRACE_CABAC_VL( g_nSymbolCounter++ );
508      DTRACE_CABAC_T( "\tTrIdx: abspart=" );
509      DTRACE_CABAC_V( uiAbsPartIdx );
510      DTRACE_CABAC_T( "\tdepth=" );
511      DTRACE_CABAC_V( uiDepth );
512      DTRACE_CABAC_T( "\ttrdepth=" );
513      DTRACE_CABAC_V( uiTrDepth );
514      DTRACE_CABAC_T( "\n" );
515    }
516#endif
517
518    pcCU->setCbfSubParts ( 0, COMPONENT_Y, uiAbsPartIdx, uiDepth );
519
520    if( (!pcCU->isIntra(uiAbsPartIdx)) && uiDepth == pcCU->getDepth( uiAbsPartIdx ) && ((!bChroma) || (!pcCU->getCbf( uiAbsPartIdx, COMPONENT_Cb, 0 ) && !pcCU->getCbf( uiAbsPartIdx, COMPONENT_Cr, 0 )) ))
521    {
522      pcCU->setCbfSubParts( 1 << uiTrDepth, COMPONENT_Y, uiAbsPartIdx, uiDepth );
523    }
524    else
525    {
526      m_pcEntropyDecoderIf->parseQtCbf( rTu, COMPONENT_Y, true );
527    }
528
529
530    // transform_unit begin
531    UInt cbf[MAX_NUM_COMPONENT]={0,0,0};
532    Bool validCbf       = false;
533    Bool validChromaCbf = false;
534    const UInt uiTrIdx = rTu.GetTransformDepthRel();
535
536    for(UInt ch=0; ch<pcCU->getPic()->getNumberValidComponents(); ch++)
537    {
538      const ComponentID compID = ComponentID(ch);
539
540      cbf[compID] = pcCU->getCbf( uiAbsPartIdx, compID, uiTrIdx );
541
542      if (cbf[compID] != 0)
543      {
544        validCbf = true;
545        if (isChroma(compID))
546        {
547          validChromaCbf = true;
548        }
549      }
550    }
551
552    if ( validCbf )
553    {
554
555      // dQP: only for CTU
556      if ( pcCU->getSlice()->getPPS()->getUseDQP() )
557      {
558        if ( bCodeDQP )
559        {
560          const UInt uiAbsPartIdxCU=rTu.GetAbsPartIdxCU();
561          decodeQP( pcCU, uiAbsPartIdxCU);
562          bCodeDQP = false;
563        }
564      }
565
566      if ( pcCU->getSlice()->getUseChromaQpAdj() )
567      {
568        if ( validChromaCbf && isChromaQpAdjCoded && !pcCU->getCUTransquantBypass(rTu.GetAbsPartIdxCU()) )
569        {
570          decodeChromaQpAdjustment( pcCU, rTu.GetAbsPartIdxCU() );
571          isChromaQpAdjCoded = false;
572        }
573      }
574
575      const UInt numValidComp=pcCU->getPic()->getNumberValidComponents();
576
577      for(UInt ch=COMPONENT_Y; ch<numValidComp; ch++)
578      {
579        const ComponentID compID=ComponentID(ch);
580
581        if( rTu.ProcessComponentSection(compID) )
582        {
583#if ENVIRONMENT_VARIABLE_DEBUG_AND_TEST
584          if (bDebugRQT)
585          {
586            printf("Call NxN for chan %d width=%d height=%d cbf=%d\n", compID, rTu.getRect(compID).width, rTu.getRect(compID).height, 1);
587          }
588#endif
589
590          if (rTu.getRect(compID).width != rTu.getRect(compID).height)
591          {
592            //code two sub-TUs
593            TComTURecurse subTUIterator(rTu, false, TComTU::VERTICAL_SPLIT, true, compID);
594
595            do
596            {
597              const UInt subTUCBF = pcCU->getCbf(subTUIterator.GetAbsPartIdxTU(), compID, (uiTrIdx + 1));
598
599              if (subTUCBF != 0)
600              {
601#if ENVIRONMENT_VARIABLE_DEBUG_AND_TEST
602                if (bDebugRQT)
603                {
604                  printf("Call NxN for chan %d width=%d height=%d cbf=%d\n", compID, subTUIterator.getRect(compID).width, subTUIterator.getRect(compID).height, 1);
605                }
606#endif
607                m_pcEntropyDecoderIf->parseCoeffNxN( subTUIterator, compID );
608              }
609            } while (subTUIterator.nextSection(rTu));
610          }
611          else
612          {
613            if(isChroma(compID) && (cbf[COMPONENT_Y] != 0))
614            {
615              m_pcEntropyDecoderIf->parseCrossComponentPrediction( rTu, compID );
616            }
617
618            if(cbf[compID] != 0)
619            {
620              m_pcEntropyDecoderIf->parseCoeffNxN( rTu, compID );
621            }
622          }
623        }
624      }
625    }
626    // transform_unit end
627  }
628}
629
630Void TDecEntropy::decodeQP          ( TComDataCU* pcCU, UInt uiAbsPartIdx )
631{
632  if ( pcCU->getSlice()->getPPS()->getUseDQP() )
633  {
634    m_pcEntropyDecoderIf->parseDeltaQP( pcCU, uiAbsPartIdx, pcCU->getDepth( uiAbsPartIdx ) );
635  }
636}
637
638Void TDecEntropy::decodeChromaQpAdjustment( TComDataCU* pcCU, UInt uiAbsPartIdx )
639{
640  if ( pcCU->getSlice()->getUseChromaQpAdj() )
641  {
642    m_pcEntropyDecoderIf->parseChromaQpAdjustment( pcCU, uiAbsPartIdx, pcCU->getDepth( uiAbsPartIdx ) );
643  }
644}
645
646
647//! decode coefficients
648Void TDecEntropy::decodeCoeff( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, Bool& bCodeDQP, Bool& isChromaQpAdjCoded )
649{
650
651  if( pcCU->isIntra(uiAbsPartIdx) )
652  {
653  }
654  else
655  {
656    UInt uiQtRootCbf = 1;
657    if( !( pcCU->getPartitionSize( uiAbsPartIdx) == SIZE_2Nx2N && pcCU->getMergeFlag( uiAbsPartIdx ) ) )
658    {
659      m_pcEntropyDecoderIf->parseQtRootCbf( uiAbsPartIdx, uiQtRootCbf );
660    }
661    if ( !uiQtRootCbf )
662    {
663      static const UInt cbfZero[MAX_NUM_COMPONENT]={0,0,0};
664      pcCU->setCbfSubParts( cbfZero, uiAbsPartIdx, uiDepth );
665      pcCU->setTrIdxSubParts( 0 , uiAbsPartIdx, uiDepth );
666      return;
667    }
668
669  }
670
671  TComTURecurse tuRecurse(pcCU, uiAbsPartIdx, uiDepth);
672
673#if ENVIRONMENT_VARIABLE_DEBUG_AND_TEST
674  if (bDebugRQT)
675  {
676    printf("..codeCoeff: uiAbsPartIdx=%d, PU format=%d, 2Nx2N=%d, NxN=%d\n", uiAbsPartIdx, pcCU->getPartitionSize(uiAbsPartIdx), SIZE_2Nx2N, SIZE_NxN);
677  }
678#endif
679
680  Int quadtreeTULog2MinSizeInCU = pcCU->getQuadtreeTULog2MinSizeInCU(uiAbsPartIdx);
681 
682  xDecodeTransform( bCodeDQP, isChromaQpAdjCoded, tuRecurse, quadtreeTULog2MinSizeInCU );
683}
684
685
686
687
688//! \}
Note: See TracBrowser for help on using the repository browser.