source: SHVCSoftware/branches/SHM-dev/source/Lib/TLibDecoder/TDecCu.cpp @ 1323

Last change on this file since 1323 was 1316, checked in by seregin, 9 years ago

port rev 4391

  • Property svn:eol-style set to native
File size: 31.3 KB
RevLine 
[313]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
[1029]4 * granted under this license.
[313]5 *
[1259]6 * Copyright (c) 2010-2015, ITU/ISO/IEC
[313]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     TDecCu.cpp
35    \brief    CU decoder class
36*/
37
38#include "TDecCu.h"
[1029]39#include "TLibCommon/TComTU.h"
[1263]40#include "TLibCommon/TComPrediction.h"
[313]41#if SVC_EXTENSION
42#include "TDecTop.h"
43#endif
44
45
46//! \ingroup TLibDecoder
47//! \{
48
49// ====================================================================================================================
50// Constructor / destructor / create / destroy
51// ====================================================================================================================
52
53TDecCu::TDecCu()
54{
55  m_ppcYuvResi = NULL;
56  m_ppcYuvReco = NULL;
57  m_ppcCU      = NULL;
58}
59
60TDecCu::~TDecCu()
61{
62}
63
64#if SVC_EXTENSION
65Void TDecCu::init(TDecTop** ppcDecTop, TDecEntropy* pcEntropyDecoder, TComTrQuant* pcTrQuant, TComPrediction* pcPrediction, UInt layerId)
66{
67  m_pcEntropyDecoder  = pcEntropyDecoder;
68  m_pcTrQuant         = pcTrQuant;
69  m_pcPrediction      = pcPrediction; 
70  m_ppcTDecTop = ppcDecTop;
71  m_layerId = layerId; 
72
73  for ( UInt ui = 0; ui < m_uiMaxDepth-1; ui++ )
74  {
75    m_ppcCU     [ui]->setLayerId(layerId);
76  }
[713]77 
78#if LAYER_CTB
79  memcpy(g_auiLayerZscanToRaster[m_layerId], g_auiZscanToRaster, sizeof( g_auiZscanToRaster ) );
80  memcpy(g_auiLayerRasterToZscan[m_layerId], g_auiRasterToZscan, sizeof( g_auiRasterToZscan ) );
81  memcpy(g_auiLayerRasterToPelX[m_layerId],  g_auiRasterToPelX,  sizeof( g_auiRasterToPelX ) );
82  memcpy(g_auiLayerRasterToPelY[m_layerId],  g_auiRasterToPelY,  sizeof( g_auiRasterToPelY ) );
83#endif
[313]84}
85#else
86Void TDecCu::init( TDecEntropy* pcEntropyDecoder, TComTrQuant* pcTrQuant, TComPrediction* pcPrediction)
87{
88  m_pcEntropyDecoder  = pcEntropyDecoder;
89  m_pcTrQuant         = pcTrQuant;
90  m_pcPrediction      = pcPrediction;
91}
92#endif
93
94/**
[1260]95 \param    uiMaxDepth      total number of allowable depth
96 \param    uiMaxWidth      largest CU width
97 \param    uiMaxHeight     largest CU height
98 \param    chromaFormatIDC chroma format
[313]99 */
[1029]100Void TDecCu::create( UInt uiMaxDepth, UInt uiMaxWidth, UInt uiMaxHeight, ChromaFormat chromaFormatIDC )
[313]101{
102  m_uiMaxDepth = uiMaxDepth+1;
[1029]103
[313]104  m_ppcYuvResi = new TComYuv*[m_uiMaxDepth-1];
105  m_ppcYuvReco = new TComYuv*[m_uiMaxDepth-1];
106  m_ppcCU      = new TComDataCU*[m_uiMaxDepth-1];
[1029]107
[313]108  UInt uiNumPartitions;
109  for ( UInt ui = 0; ui < m_uiMaxDepth-1; ui++ )
110  {
111    uiNumPartitions = 1<<( ( m_uiMaxDepth - ui - 1 )<<1 );
112    UInt uiWidth  = uiMaxWidth  >> ui;
113    UInt uiHeight = uiMaxHeight >> ui;
[1029]114
115    m_ppcYuvResi[ui] = new TComYuv;    m_ppcYuvResi[ui]->create( uiWidth, uiHeight, chromaFormatIDC );
116    m_ppcYuvReco[ui] = new TComYuv;    m_ppcYuvReco[ui]->create( uiWidth, uiHeight, chromaFormatIDC );
117    m_ppcCU     [ui] = new TComDataCU; m_ppcCU     [ui]->create( chromaFormatIDC, uiNumPartitions, uiWidth, uiHeight, true, uiMaxWidth >> (m_uiMaxDepth - 1) );
[313]118  }
[1029]119
[313]120  m_bDecodeDQP = false;
[1029]121  m_IsChromaQpAdjCoded = false;
[313]122
123  // initialize partition order.
124  UInt* piTmp = &g_auiZscanToRaster[0];
125  initZscanToRaster(m_uiMaxDepth, 1, 0, piTmp);
126  initRasterToZscan( uiMaxWidth, uiMaxHeight, m_uiMaxDepth );
[1029]127
[313]128  // initialize conversion matrix from partition index to pel
129  initRasterToPelXY( uiMaxWidth, uiMaxHeight, m_uiMaxDepth );
130}
131
132Void TDecCu::destroy()
133{
134  for ( UInt ui = 0; ui < m_uiMaxDepth-1; ui++ )
135  {
136    m_ppcYuvResi[ui]->destroy(); delete m_ppcYuvResi[ui]; m_ppcYuvResi[ui] = NULL;
137    m_ppcYuvReco[ui]->destroy(); delete m_ppcYuvReco[ui]; m_ppcYuvReco[ui] = NULL;
138    m_ppcCU     [ui]->destroy(); delete m_ppcCU     [ui]; m_ppcCU     [ui] = NULL;
139  }
[1029]140
[313]141  delete [] m_ppcYuvResi; m_ppcYuvResi = NULL;
142  delete [] m_ppcYuvReco; m_ppcYuvReco = NULL;
143  delete [] m_ppcCU     ; m_ppcCU      = NULL;
144}
145
146// ====================================================================================================================
147// Public member functions
148// ====================================================================================================================
149
[1260]150/**
151 Parse a CTU.
152 \param    pCtu                      [in/out] pointer to CTU data structure
153 \param    isLastCtuOfSliceSegment   [out]    true, if last CTU of the slice segment
[313]154 */
[1029]155Void TDecCu::decodeCtu( TComDataCU* pCtu, Bool& isLastCtuOfSliceSegment )
[313]156{
[1029]157  if ( pCtu->getSlice()->getPPS()->getUseDQP() )
[313]158  {
159    setdQPFlag(true);
160  }
161
[1029]162  if ( pCtu->getSlice()->getUseChromaQpAdj() )
163  {
164    setIsChromaQpAdjCoded(true);
165  }
166
[313]167#if SVC_EXTENSION
[1029]168  pCtu->setLayerId(m_layerId);
[313]169#endif
[1029]170
171  // start from the top level CU
172  xDecodeCU( pCtu, 0, 0, isLastCtuOfSliceSegment);
[313]173}
174
[1260]175/**
176 Decoding process for a CTU.
177 \param    pCtu                      [in/out] pointer to CTU data structure
[313]178 */
[1029]179Void TDecCu::decompressCtu( TComDataCU* pCtu )
[313]180{
[1029]181  xDecompressCU( pCtu, 0,  0 );
[313]182}
183
184// ====================================================================================================================
185// Protected member functions
186// ====================================================================================================================
187
[1260]188//! decode end-of-slice flag
[1029]189Bool TDecCu::xDecodeSliceEnd( TComDataCU* pcCU, UInt uiAbsPartIdx )
[313]190{
[1029]191  UInt uiIsLastCtuOfSliceSegment;
[313]192
[1029]193  if (pcCU->isLastSubCUOfCtu(uiAbsPartIdx))
[313]194  {
[1029]195    m_pcEntropyDecoder->decodeTerminatingBit( uiIsLastCtuOfSliceSegment );
[313]196  }
197  else
198  {
[1029]199    uiIsLastCtuOfSliceSegment=0;
[313]200  }
201
[1029]202  return uiIsLastCtuOfSliceSegment>0;
[313]203}
204
[1260]205//! decode CU block recursively
[1289]206Void TDecCu::xDecodeCU( TComDataCU*const pcCU, const UInt uiAbsPartIdx, const UInt uiDepth, Bool &isLastCtuOfSliceSegment)
[313]207{
[1289]208  TComPic* pcPic        = pcCU->getPic();
209  const TComSPS &sps    = pcPic->getPicSym()->getSPS();
210  const TComPPS &pps    = pcPic->getPicSym()->getPPS();
211  const UInt maxCuWidth = sps.getMaxCUWidth();
212  const UInt maxCuHeight= sps.getMaxCUHeight();
[1029]213  UInt uiCurNumParts    = pcPic->getNumPartitionsInCtu() >> (uiDepth<<1);
[313]214  UInt uiQNumParts      = uiCurNumParts>>2;
[1029]215
[1289]216
[313]217  Bool bBoundary = false;
218  UInt uiLPelX   = pcCU->getCUPelX() + g_auiRasterToPelX[ g_auiZscanToRaster[uiAbsPartIdx] ];
[1289]219  UInt uiRPelX   = uiLPelX + (maxCuWidth>>uiDepth)  - 1;
[313]220  UInt uiTPelY   = pcCU->getCUPelY() + g_auiRasterToPelY[ g_auiZscanToRaster[uiAbsPartIdx] ];
[1289]221  UInt uiBPelY   = uiTPelY + (maxCuHeight>>uiDepth) - 1;
[1029]222
[1289]223#if SVC_EXTENSION
224  TComSlice * pcSlice = pcPic->getSlice(pcPic->getCurrSliceIdx());
[1203]225
[1029]226  if( ( uiRPelX < pcSlice->getPicWidthInLumaSamples() ) && ( uiBPelY < pcSlice->getPicHeightInLumaSamples() ) )
[442]227#else
[1289]228  if( ( uiRPelX < sps.getPicWidthInLumaSamples() ) && ( uiBPelY < sps.getPicHeightInLumaSamples() ) )
[442]229#endif
[313]230  {
231    m_pcEntropyDecoder->decodeSplitFlag( pcCU, uiAbsPartIdx, uiDepth );
232  }
233  else
234  {
235    bBoundary = true;
236  }
[1290]237  if( ( ( uiDepth < pcCU->getDepth( uiAbsPartIdx ) ) && ( uiDepth < sps.getLog2DiffMaxMinCodingBlockSize() ) ) || bBoundary )
[313]238  {
239    UInt uiIdx = uiAbsPartIdx;
[1290]240    if( uiDepth == pps.getMaxCuDQPDepth() && pps.getUseDQP())
[313]241    {
242      setdQPFlag(true);
243      pcCU->setQPSubParts( pcCU->getRefQP(uiAbsPartIdx), uiAbsPartIdx, uiDepth ); // set QP to default QP
244    }
245
[1316]246    if( uiDepth == pps.getPpsRangeExtension().getDiffCuChromaQpOffsetDepth() && pcCU->getSlice()->getUseChromaQpAdj() )
[1029]247    {
248      setIsChromaQpAdjCoded(true);
249    }
250
[313]251    for ( UInt uiPartUnitIdx = 0; uiPartUnitIdx < 4; uiPartUnitIdx++ )
252    {
253      uiLPelX   = pcCU->getCUPelX() + g_auiRasterToPelX[ g_auiZscanToRaster[uiIdx] ];
254      uiTPelY   = pcCU->getCUPelY() + g_auiRasterToPelY[ g_auiZscanToRaster[uiIdx] ];
[1029]255
[1203]256#if SVC_EXTENSION
[1029]257      if ( !isLastCtuOfSliceSegment && ( uiLPelX < pcCU->getSlice()->getPicWidthInLumaSamples() ) && ( uiTPelY < pcCU->getSlice()->getPicHeightInLumaSamples() ) )
[442]258#else
[1289]259      if ( !isLastCtuOfSliceSegment && ( uiLPelX < sps.getPicWidthInLumaSamples() ) && ( uiTPelY < sps.getPicHeightInLumaSamples() ) )
[442]260#endif
[1029]261      {
262        xDecodeCU( pcCU, uiIdx, uiDepth+1, isLastCtuOfSliceSegment );
[313]263      }
[1029]264      else
265      {
266        pcCU->setOutsideCUPart( uiIdx, uiDepth+1 );
267      }
268
[313]269      uiIdx += uiQNumParts;
270    }
[1290]271    if( uiDepth == pps.getMaxCuDQPDepth() && pps.getUseDQP())
[313]272    {
273      if ( getdQPFlag() )
274      {
[1029]275        UInt uiQPSrcPartIdx = uiAbsPartIdx;
[313]276        pcCU->setQPSubParts( pcCU->getRefQP( uiQPSrcPartIdx ), uiAbsPartIdx, uiDepth ); // set QP to default QP
277      }
278    }
279    return;
280  }
[1029]281
[1290]282  if( uiDepth <= pps.getMaxCuDQPDepth() && pps.getUseDQP())
[313]283  {
284    setdQPFlag(true);
285    pcCU->setQPSubParts( pcCU->getRefQP(uiAbsPartIdx), uiAbsPartIdx, uiDepth ); // set QP to default QP
286  }
287
[1316]288  if( uiDepth <= pps.getPpsRangeExtension().getDiffCuChromaQpOffsetDepth() && pcCU->getSlice()->getUseChromaQpAdj() )
[1029]289  {
290    setIsChromaQpAdjCoded(true);
291  }
292
[1289]293  if (pps.getTransquantBypassEnableFlag())
[313]294  {
295    m_pcEntropyDecoder->decodeCUTransquantBypassFlag( pcCU, uiAbsPartIdx, uiDepth );
296  }
[1029]297
[313]298  // decode CU mode and the partition size
299  if( !pcCU->getSlice()->isIntra())
300  {
301    m_pcEntropyDecoder->decodeSkipFlag( pcCU, uiAbsPartIdx, uiDepth );
302  }
303 
[1128]304#if SVC_EXTENSION
305  // Check CU skip for higher layer IRAP skip flag
306  if( pcCU->getSlice()->getVPS()->getHigherLayerIrapSkipFlag() && pcCU->getSlice()->getVPS()->getSingleLayerForNonIrapFlag() && pcCU->getLayerId() > 0 )
[540]307  {
308    Bool lowerLayerExist = false;
309    for(int i=0;i<pcCU->getLayerId();i++)
310    {
311      if(pcCU->getSlice()->getBaseColPic(pcCU->getSlice()->getInterLayerPredLayerIdc(i)))
312      {
313        lowerLayerExist = true;
314      }
315    }
[1128]316
317    if( lowerLayerExist && !pcCU->isSkipped(uiAbsPartIdx) )
[540]318    {
[1128]319      printf( "Warning: CU is not skipped with enabled higher layer IRAP skip flag\n" );
[540]320    }
321  }
322#endif
323 
[313]324  if( pcCU->isSkipped(uiAbsPartIdx) )
325  {
326    m_ppcCU[uiDepth]->copyInterPredInfoFrom( pcCU, uiAbsPartIdx, REF_PIC_LIST_0 );
327    m_ppcCU[uiDepth]->copyInterPredInfoFrom( pcCU, uiAbsPartIdx, REF_PIC_LIST_1 );
328    TComMvField cMvFieldNeighbours[MRG_MAX_NUM_CANDS << 1]; // double length for mv of both lists
329    UChar uhInterDirNeighbours[MRG_MAX_NUM_CANDS];
330    Int numValidMergeCand = 0;
331    for( UInt ui = 0; ui < m_ppcCU[uiDepth]->getSlice()->getMaxNumMergeCand(); ++ui )
332    {
333      uhInterDirNeighbours[ui] = 0;
334    }
335    m_pcEntropyDecoder->decodeMergeIndex( pcCU, 0, uiAbsPartIdx, uiDepth );
336    UInt uiMergeIndex = pcCU->getMergeIndex(uiAbsPartIdx);
337    m_ppcCU[uiDepth]->getInterMergeCandidates( 0, 0, cMvFieldNeighbours, uhInterDirNeighbours, numValidMergeCand, uiMergeIndex );
338    pcCU->setInterDirSubParts( uhInterDirNeighbours[uiMergeIndex], uiAbsPartIdx, 0, uiDepth );
339
340    TComMv cTmpMv( 0, 0 );
341    for ( UInt uiRefListIdx = 0; uiRefListIdx < 2; uiRefListIdx++ )
[1029]342    {
[313]343      if ( pcCU->getSlice()->getNumRefIdx( RefPicList( uiRefListIdx ) ) > 0 )
344      {
345        pcCU->setMVPIdxSubParts( 0, RefPicList( uiRefListIdx ), uiAbsPartIdx, 0, uiDepth);
346        pcCU->setMVPNumSubParts( 0, RefPicList( uiRefListIdx ), uiAbsPartIdx, 0, uiDepth);
347        pcCU->getCUMvField( RefPicList( uiRefListIdx ) )->setAllMvd( cTmpMv, SIZE_2Nx2N, uiAbsPartIdx, uiDepth );
348        pcCU->getCUMvField( RefPicList( uiRefListIdx ) )->setAllMvField( cMvFieldNeighbours[ 2*uiMergeIndex + uiRefListIdx ], SIZE_2Nx2N, uiAbsPartIdx, uiDepth );
349      }
350    }
[1029]351    xFinishDecodeCU( pcCU, uiAbsPartIdx, uiDepth, isLastCtuOfSliceSegment );
[313]352    return;
353  }
354
355  m_pcEntropyDecoder->decodePredMode( pcCU, uiAbsPartIdx, uiDepth );
356  m_pcEntropyDecoder->decodePartSize( pcCU, uiAbsPartIdx, uiDepth );
357
358  if (pcCU->isIntra( uiAbsPartIdx ) && pcCU->getPartitionSize( uiAbsPartIdx ) == SIZE_2Nx2N )
359  {
360    m_pcEntropyDecoder->decodeIPCMInfo( pcCU, uiAbsPartIdx, uiDepth );
361
362    if(pcCU->getIPCMFlag(uiAbsPartIdx))
363    {
[1029]364      xFinishDecodeCU( pcCU, uiAbsPartIdx, uiDepth, isLastCtuOfSliceSegment );
[313]365      return;
366    }
367  }
368
369  // prediction mode ( Intra : direction mode, Inter : Mv, reference idx )
370  m_pcEntropyDecoder->decodePredInfo( pcCU, uiAbsPartIdx, uiDepth, m_ppcCU[uiDepth]);
371
372  // Coefficient decoding
373  Bool bCodeDQP = getdQPFlag();
[1029]374  Bool isChromaQpAdjCoded = getIsChromaQpAdjCoded();
375  m_pcEntropyDecoder->decodeCoeff( pcCU, uiAbsPartIdx, uiDepth, bCodeDQP, isChromaQpAdjCoded );
376  setIsChromaQpAdjCoded( isChromaQpAdjCoded );
[313]377  setdQPFlag( bCodeDQP );
[1029]378  xFinishDecodeCU( pcCU, uiAbsPartIdx, uiDepth, isLastCtuOfSliceSegment );
[313]379}
380
[1029]381Void TDecCu::xFinishDecodeCU( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, Bool &isLastCtuOfSliceSegment)
[313]382{
383  if(  pcCU->getSlice()->getPPS()->getUseDQP())
384  {
385    pcCU->setQPSubParts( getdQPFlag()?pcCU->getRefQP(uiAbsPartIdx):pcCU->getCodedQP(), uiAbsPartIdx, uiDepth ); // set QP
386  }
387
[1029]388  if (pcCU->getSlice()->getUseChromaQpAdj() && !getIsChromaQpAdjCoded())
389  {
390    pcCU->setChromaQpAdjSubParts( pcCU->getCodedChromaQpAdj(), uiAbsPartIdx, uiDepth ); // set QP
391  }
392
393  isLastCtuOfSliceSegment = xDecodeSliceEnd( pcCU, uiAbsPartIdx );
[313]394}
395
[1029]396Void TDecCu::xDecompressCU( TComDataCU* pCtu, UInt uiAbsPartIdx,  UInt uiDepth )
[313]397{
[1029]398  TComPic* pcPic = pCtu->getPic();
[1289]399  TComSlice * pcSlice = pCtu->getSlice();
400  const TComSPS &sps=*(pcSlice->getSPS());
[1029]401
[313]402  Bool bBoundary = false;
[1029]403  UInt uiLPelX   = pCtu->getCUPelX() + g_auiRasterToPelX[ g_auiZscanToRaster[uiAbsPartIdx] ];
[1289]404  UInt uiRPelX   = uiLPelX + (sps.getMaxCUWidth()>>uiDepth)  - 1;
[1029]405  UInt uiTPelY   = pCtu->getCUPelY() + g_auiRasterToPelY[ g_auiZscanToRaster[uiAbsPartIdx] ];
[1289]406  UInt uiBPelY   = uiTPelY + (sps.getMaxCUHeight()>>uiDepth) - 1;
[1029]407
[1203]408#if SVC_EXTENSION
[1029]409  if( ( uiRPelX >= pcSlice->getPicWidthInLumaSamples() ) || ( uiBPelY >= pcSlice->getPicHeightInLumaSamples() ) )
[442]410#else
[1289]411  if( ( uiRPelX >= sps.getPicWidthInLumaSamples() ) || ( uiBPelY >= sps.getPicHeightInLumaSamples() ) )
[442]412#endif
[313]413  {
414    bBoundary = true;
415  }
[1029]416
[1290]417  if( ( ( uiDepth < pCtu->getDepth( uiAbsPartIdx ) ) && ( uiDepth < sps.getLog2DiffMaxMinCodingBlockSize() ) ) || bBoundary )
[313]418  {
419    UInt uiNextDepth = uiDepth + 1;
[1029]420    UInt uiQNumParts = pCtu->getTotalNumPart() >> (uiNextDepth<<1);
[313]421    UInt uiIdx = uiAbsPartIdx;
422    for ( UInt uiPartIdx = 0; uiPartIdx < 4; uiPartIdx++ )
423    {
[1029]424      uiLPelX = pCtu->getCUPelX() + g_auiRasterToPelX[ g_auiZscanToRaster[uiIdx] ];
425      uiTPelY = pCtu->getCUPelY() + g_auiRasterToPelY[ g_auiZscanToRaster[uiIdx] ];
426
[1203]427#if SVC_EXTENSION
[1029]428      if( ( uiLPelX < pcSlice->getPicWidthInLumaSamples() ) && ( uiTPelY < pcSlice->getPicHeightInLumaSamples() ) )
[442]429#else
[1289]430      if( ( uiLPelX < sps.getPicWidthInLumaSamples() ) && ( uiTPelY < sps.getPicHeightInLumaSamples() ) )
[442]431#endif
[313]432      {
[1029]433        xDecompressCU(pCtu, uiIdx, uiNextDepth );
[313]434      }
[1029]435
[313]436      uiIdx += uiQNumParts;
437    }
438    return;
439  }
[1029]440
[313]441  // Residual reconstruction
442  m_ppcYuvResi[uiDepth]->clear();
[1029]443
[1307]444  m_ppcCU[uiDepth]->copySubCU( pCtu, uiAbsPartIdx );
[1029]445
[313]446  switch( m_ppcCU[uiDepth]->getPredictionMode(0) )
447  {
448    case MODE_INTER:
449      xReconInter( m_ppcCU[uiDepth], uiDepth );
450      break;
451    case MODE_INTRA:
452      xReconIntraQT( m_ppcCU[uiDepth], uiDepth );
453      break;
454    default:
455      assert(0);
456      break;
457  }
[1029]458
459#ifdef DEBUG_STRING
460  const PredMode predMode=m_ppcCU[uiDepth]->getPredictionMode(0);
461  if (DebugOptionList::DebugString_Structure.getInt()&DebugStringGetPredModeMask(predMode))
462  {
463    PartSize eSize=m_ppcCU[uiDepth]->getPartitionSize(0);
464    std::ostream &ss(std::cout);
465
466    ss <<"###: " << (predMode==MODE_INTRA?"Intra   ":"Inter   ") << partSizeToString[eSize] << " CU at " << m_ppcCU[uiDepth]->getCUPelX() << ", " << m_ppcCU[uiDepth]->getCUPelY() << " width=" << UInt(m_ppcCU[uiDepth]->getWidth(0)) << std::endl;
467  }
468#endif
469
[313]470  if ( m_ppcCU[uiDepth]->isLosslessCoded(0) && (m_ppcCU[uiDepth]->getIPCMFlag(0) == false))
471  {
472    xFillPCMBuffer(m_ppcCU[uiDepth], uiDepth);
473  }
[1029]474
[313]475  xCopyToPic( m_ppcCU[uiDepth], pcPic, uiAbsPartIdx, uiDepth );
476}
477
478Void TDecCu::xReconInter( TComDataCU* pcCU, UInt uiDepth )
479{
[1029]480
[313]481  // inter prediction
482  m_pcPrediction->motionCompensation( pcCU, m_ppcYuvReco[uiDepth] );
[1029]483
484#ifdef DEBUG_STRING
485  const Int debugPredModeMask=DebugStringGetPredModeMask(MODE_INTER);
[1246]486  if (DebugOptionList::DebugString_Pred.getInt()&debugPredModeMask)
487  {
488    printBlockToStream(std::cout, "###inter-pred: ", *(m_ppcYuvReco[uiDepth]));
489  }
[1029]490#endif
491
[313]492  // inter recon
[1029]493  xDecodeInterTexture( pcCU, uiDepth );
494
495#ifdef DEBUG_STRING
[1246]496  if (DebugOptionList::DebugString_Resi.getInt()&debugPredModeMask)
497  {
498    printBlockToStream(std::cout, "###inter-resi: ", *(m_ppcYuvResi[uiDepth]));
499  }
[1029]500#endif
501
[313]502  // clip for only non-zero cbp case
[1029]503  if  ( pcCU->getQtRootCbf( 0) )
[313]504  {
[1287]505#if SVC_EXTENSION
506    m_ppcYuvReco[uiDepth]->addClip( m_ppcYuvReco[uiDepth], m_ppcYuvResi[uiDepth], 0, pcCU->getWidth( 0 ), pcCU->getSlice()->getBitDepths() );
507#else
508    m_ppcYuvReco[uiDepth]->addClip( m_ppcYuvReco[uiDepth], m_ppcYuvResi[uiDepth], 0, pcCU->getWidth( 0 ), pcCU->getSlice()->getSPS()->getBitDepths() );
509#endif
[313]510  }
511  else
512  {
513    m_ppcYuvReco[uiDepth]->copyPartToPartYuv( m_ppcYuvReco[uiDepth],0, pcCU->getWidth( 0 ),pcCU->getHeight( 0 ));
514  }
[1029]515#ifdef DEBUG_STRING
[1246]516  if (DebugOptionList::DebugString_Reco.getInt()&debugPredModeMask)
517  {
518    printBlockToStream(std::cout, "###inter-reco: ", *(m_ppcYuvReco[uiDepth]));
519  }
[1029]520#endif
521
[313]522}
523
[1029]524
[313]525Void
[1029]526TDecCu::xIntraRecBlk(       TComYuv*    pcRecoYuv,
527                            TComYuv*    pcPredYuv,
528                            TComYuv*    pcResiYuv,
529                      const ComponentID compID,
530                            TComTU     &rTu)
[313]531{
[1246]532  if (!rTu.ProcessComponentSection(compID))
533  {
534    return;
535  }
[1029]536  const Bool       bIsLuma = isLuma(compID);
[313]537
538
[1029]539  TComDataCU *pcCU = rTu.getCU();
[1289]540  const TComSPS &sps=*(pcCU->getSlice()->getSPS());
[1029]541  const UInt uiAbsPartIdx=rTu.GetAbsPartIdxTU();
542
543  const TComRectangle &tuRect  =rTu.getRect(compID);
544  const UInt uiWidth           = tuRect.width;
545  const UInt uiHeight          = tuRect.height;
546  const UInt uiStride          = pcRecoYuv->getStride (compID);
547        Pel* piPred            = pcPredYuv->getAddr( compID, uiAbsPartIdx );
548  const ChromaFormat chFmt     = rTu.GetChromaFormat();
549
550  if (uiWidth != uiHeight)
[313]551  {
[1029]552    //------------------------------------------------
[313]553
[1029]554    //split at current level if dividing into square sub-TUs
[313]555
[1029]556    TComTURecurse subTURecurse(rTu, false, TComTU::VERTICAL_SPLIT, true, compID);
[313]557
[1029]558    //recurse further
559    do
[313]560    {
[1029]561      xIntraRecBlk(pcRecoYuv, pcPredYuv, pcResiYuv, compID, subTURecurse);
[1246]562    } while (subTURecurse.nextSection(rTu));
[1029]563
564    //------------------------------------------------
565
566    return;
[313]567  }
[1029]568
569  const UInt uiChPredMode  = pcCU->getIntraDir( toChannelType(compID), uiAbsPartIdx );
[1290]570  const UInt partsPerMinCU = 1<<(2*(sps.getMaxTotalCUDepth() - sps.getLog2DiffMaxMinCodingBlockSize()));
571  const UInt uiChCodedMode = (uiChPredMode==DM_CHROMA_IDX && !bIsLuma) ? pcCU->getIntraDir(CHANNEL_TYPE_LUMA, getChromasCorrespondingPULumaIdx(uiAbsPartIdx, chFmt, partsPerMinCU)) : uiChPredMode;
[1029]572  const UInt uiChFinalMode = ((chFmt == CHROMA_422)       && !bIsLuma) ? g_chroma422IntraAngleMappingTable[uiChCodedMode] : uiChCodedMode;
573
[313]574  //===== init availability pattern =====
575  Bool  bAboveAvail = false;
576  Bool  bLeftAvail  = false;
577
[1316]578  const Bool bUseFilteredPredictions=TComPrediction::filteringIntraReferenceSamples(compID, uiChFinalMode, uiWidth, uiHeight, chFmt, pcCU->getSlice()->getSPS()->getSpsRangeExtension().getIntraSmoothingDisabledFlag());
[1029]579
580#ifdef DEBUG_STRING
581  std::ostream &ss(std::cout);
582#endif
583
584  DEBUG_STRING_NEW(sTemp)
[1315]585  m_pcPrediction->initIntraPatternChType( rTu, bAboveAvail, bLeftAvail, compID, bUseFilteredPredictions  DEBUG_STRING_PASS_INTO(sTemp) );
[1029]586
587
[313]588  //===== get prediction signal =====
589
[1029]590  m_pcPrediction->predIntraAng( compID,   uiChFinalMode, 0 /* Decoder does not have an original image */, 0, piPred, uiStride, rTu, bAboveAvail, bLeftAvail, bUseFilteredPredictions );
591
592#ifdef DEBUG_STRING
593  ss << sTemp;
594#endif
595
[313]596  //===== inverse transform =====
[1029]597  Pel*      piResi            = pcResiYuv->getAddr( compID, uiAbsPartIdx );
598  TCoeff*   pcCoeff           = pcCU->getCoeff(compID) + rTu.getCoefficientOffset(compID);//( uiNumCoeffInc * uiAbsPartIdx );
599
600  const QpParam cQP(*pcCU, compID);
601
602
603  DEBUG_STRING_NEW(sDebug);
604#ifdef DEBUG_STRING
605  const Int debugPredModeMask=DebugStringGetPredModeMask(MODE_INTRA);
606  std::string *psDebug=(DebugOptionList::DebugString_InvTran.getInt()&debugPredModeMask) ? &sDebug : 0;
607#endif
608
609  if (pcCU->getCbf(uiAbsPartIdx, compID, rTu.GetTransformDepthRel()) != 0)
[313]610  {
[1029]611    m_pcTrQuant->invTransformNxN( rTu, compID, piResi, uiStride, pcCoeff, cQP DEBUG_STRING_PASS_INTO(psDebug) );
[313]612  }
613  else
614  {
[1029]615    for (UInt y = 0; y < uiHeight; y++)
[1246]616    {
[1029]617      for (UInt x = 0; x < uiWidth; x++)
618      {
619        piResi[(y * uiStride) + x] = 0;
620      }
[1246]621    }
[313]622  }
[1029]623
624#ifdef DEBUG_STRING
625  if (psDebug)
[1246]626  {
[1029]627    ss << (*psDebug);
[1246]628  }
[494]629#endif
[1029]630
631  //===== reconstruction =====
632  const UInt uiRecIPredStride  = pcCU->getPic()->getPicYuvRec()->getStride(compID);
633
634  const Bool useCrossComponentPrediction = isChroma(compID) && (pcCU->getCrossComponentPredictionAlpha(uiAbsPartIdx, compID) != 0);
635  const Pel* pResiLuma  = pcResiYuv->getAddr( COMPONENT_Y, uiAbsPartIdx );
636  const Int  strideLuma = pcResiYuv->getStride( COMPONENT_Y );
637
638        Pel* pPred      = piPred;
639        Pel* pResi      = piResi;
640        Pel* pReco      = pcRecoYuv->getAddr( compID, uiAbsPartIdx );
641        Pel* pRecIPred  = pcCU->getPic()->getPicYuvRec()->getAddr( compID, pcCU->getCtuRsAddr(), pcCU->getZorderIdxInCtu() + uiAbsPartIdx );
642
643
644#ifdef DEBUG_STRING
645  const Bool bDebugPred=((DebugOptionList::DebugString_Pred.getInt()&debugPredModeMask) && DEBUG_STRING_CHANNEL_CONDITION(compID));
646  const Bool bDebugResi=((DebugOptionList::DebugString_Resi.getInt()&debugPredModeMask) && DEBUG_STRING_CHANNEL_CONDITION(compID));
647  const Bool bDebugReco=((DebugOptionList::DebugString_Reco.getInt()&debugPredModeMask) && DEBUG_STRING_CHANNEL_CONDITION(compID));
648  if (bDebugPred || bDebugResi || bDebugReco)
[1246]649  {
[1029]650    ss << "###: " << "CompID: " << compID << " pred mode (ch/fin): " << uiChPredMode << "/" << uiChFinalMode << " absPartIdx: " << rTu.GetAbsPartIdxTU() << std::endl;
[1246]651  }
[494]652#endif
[313]653
[1287]654#if SVC_EXTENSION
655  const Int clipbd = pcCU->getSlice()->getBitDepth(toChannelType(compID));
656#else
[1289]657  const Int clipbd = sps.getBitDepth(toChannelType(compID));
[1287]658#endif
[1029]659#if O0043_BEST_EFFORT_DECODING
[1289]660  const Int bitDepthDelta = sps.getStreamBitDepth(toChannelType(compID)) - clipbd;
[1029]661#endif
[313]662
[1029]663  if( useCrossComponentPrediction )
664  {
665    TComTrQuant::crossComponentPrediction( rTu, compID, pResiLuma, piResi, piResi, uiWidth, uiHeight, strideLuma, uiStride, uiStride, true );
666  }
667
[313]668  for( UInt uiY = 0; uiY < uiHeight; uiY++ )
669  {
[1029]670#ifdef DEBUG_STRING
[1246]671    if (bDebugPred || bDebugResi || bDebugReco)
672    {
673      ss << "###: ";
674    }
[1029]675
676    if (bDebugPred)
677    {
678      ss << " - pred: ";
679      for( UInt uiX = 0; uiX < uiWidth; uiX++ )
680      {
681        ss << pPred[ uiX ] << ", ";
682      }
683    }
[1246]684    if (bDebugResi)
685    {
686      ss << " - resi: ";
687    }
[1029]688#endif
689
[313]690    for( UInt uiX = 0; uiX < uiWidth; uiX++ )
691    {
[1029]692#ifdef DEBUG_STRING
693      if (bDebugResi)
[1246]694      {
[1029]695        ss << pResi[ uiX ] << ", ";
[1246]696      }
[1029]697#endif
698#if O0043_BEST_EFFORT_DECODING
699      pReco    [ uiX ] = ClipBD( rightShiftEvenRounding<Pel>(pPred[ uiX ] + pResi[ uiX ], bitDepthDelta), clipbd );
700#else
701      pReco    [ uiX ] = ClipBD( pPred[ uiX ] + pResi[ uiX ], clipbd );
702#endif
[313]703      pRecIPred[ uiX ] = pReco[ uiX ];
704    }
[1029]705#ifdef DEBUG_STRING
706    if (bDebugReco)
707    {
708      ss << " - reco: ";
709      for( UInt uiX = 0; uiX < uiWidth; uiX++ )
710      {
711        ss << pReco[ uiX ] << ", ";
712      }
713    }
714
715    if (bDebugPred || bDebugResi || bDebugReco)
[1246]716    {
[1029]717      ss << "\n";
[1246]718    }
[1029]719#endif
[313]720    pPred     += uiStride;
721    pResi     += uiStride;
722    pReco     += uiStride;
723    pRecIPred += uiRecIPredStride;
724  }
725}
726
727
728Void
729TDecCu::xReconIntraQT( TComDataCU* pcCU, UInt uiDepth )
730{
731  if (pcCU->getIPCMFlag(0))
732  {
733    xReconPCM( pcCU, uiDepth );
734    return;
735  }
[1029]736  const UInt numChType = pcCU->getPic()->getChromaFormat()!=CHROMA_400 ? 2 : 1;
737  for (UInt chType=CHANNEL_TYPE_LUMA; chType<numChType; chType++)
[313]738  {
[1029]739    const ChannelType chanType=ChannelType(chType);
740    const Bool NxNPUHas4Parts = ::isChroma(chanType) ? enable4ChromaPUsInIntraNxNCU(pcCU->getPic()->getChromaFormat()) : true;
741    const UInt uiInitTrDepth = ( pcCU->getPartitionSize(0) != SIZE_2Nx2N && NxNPUHas4Parts ? 1 : 0 );
[313]742
[1029]743    TComTURecurse tuRecurseCU(pcCU, 0);
744    TComTURecurse tuRecurseWithPU(tuRecurseCU, false, (uiInitTrDepth==0)?TComTU::DONT_SPLIT : TComTU::QUAD_SPLIT);
[313]745
[1029]746    do
[313]747    {
[1029]748      xIntraRecQT( m_ppcYuvReco[uiDepth], m_ppcYuvReco[uiDepth], m_ppcYuvResi[uiDepth], chanType, tuRecurseWithPU );
749    } while (tuRecurseWithPU.nextSection(tuRecurseCU));
[313]750  }
751}
752
[1029]753
754
[1260]755/** Function for deriving reconstructed PU/CU chroma samples with QTree structure
[313]756 * \param pcRecoYuv pointer to reconstructed sample arrays
757 * \param pcPredYuv pointer to prediction sample arrays
758 * \param pcResiYuv pointer to residue sample arrays
[1260]759 * \param chType    texture channel type (luma/chroma)
760 * \param rTu       reference to transform data
[1029]761 *
[1260]762 \ This function derives reconstructed PU/CU chroma samples with QTree recursive structure
[313]763 */
[1029]764
[313]765Void
[1029]766TDecCu::xIntraRecQT(TComYuv*    pcRecoYuv,
767                    TComYuv*    pcPredYuv,
768                    TComYuv*    pcResiYuv,
769                    const ChannelType chType,
770                    TComTU     &rTu)
[313]771{
[1029]772  UInt uiTrDepth    = rTu.GetTransformDepthRel();
773  TComDataCU *pcCU  = rTu.getCU();
774  UInt uiAbsPartIdx = rTu.GetAbsPartIdxTU();
[313]775  UInt uiTrMode     = pcCU->getTransformIdx( uiAbsPartIdx );
776  if( uiTrMode == uiTrDepth )
777  {
[1029]778    if (isLuma(chType))
[1246]779    {
[1029]780      xIntraRecBlk( pcRecoYuv, pcPredYuv, pcResiYuv, COMPONENT_Y,  rTu );
[1246]781    }
[1029]782    else
783    {
784      const UInt numValidComp=getNumberValidComponents(rTu.GetChromaFormat());
785      for(UInt compID=COMPONENT_Cb; compID<numValidComp; compID++)
786      {
787        xIntraRecBlk( pcRecoYuv, pcPredYuv, pcResiYuv, ComponentID(compID), rTu );
788      }
789    }
[313]790  }
791  else
792  {
[1029]793    TComTURecurse tuRecurseChild(rTu, false);
794    do
[313]795    {
[1029]796      xIntraRecQT( pcRecoYuv, pcPredYuv, pcResiYuv, chType, tuRecurseChild );
797    } while (tuRecurseChild.nextSection(rTu));
[313]798  }
799}
800
801Void TDecCu::xCopyToPic( TComDataCU* pcCU, TComPic* pcPic, UInt uiZorderIdx, UInt uiDepth )
802{
[1029]803  UInt uiCtuRsAddr = pcCU->getCtuRsAddr();
804
805  m_ppcYuvReco[uiDepth]->copyToPicYuv  ( pcPic->getPicYuvRec (), uiCtuRsAddr, uiZorderIdx );
806
[313]807  return;
808}
809
[1029]810Void TDecCu::xDecodeInterTexture ( TComDataCU* pcCU, UInt uiDepth )
[313]811{
812
[1029]813  TComTURecurse tuRecur(pcCU, 0, uiDepth);
[313]814
[1029]815  for(UInt ch=0; ch<pcCU->getPic()->getNumberValidComponents(); ch++)
816  {
817    const ComponentID compID=ComponentID(ch);
818    DEBUG_STRING_OUTPUT(std::cout, debug_reorder_data_inter_token[compID])
[313]819
[1029]820    m_pcTrQuant->invRecurTransformNxN ( compID, m_ppcYuvResi[uiDepth], tuRecur );
821  }
[313]822
[1029]823  DEBUG_STRING_OUTPUT(std::cout, debug_reorder_data_inter_token[MAX_NUM_COMPONENT])
[313]824}
825
826/** Function for deriving reconstructed luma/chroma samples of a PCM mode CU.
827 * \param pcCU pointer to current CU
828 * \param uiPartIdx part index
829 * \param piPCM pointer to PCM code arrays
830 * \param piReco pointer to reconstructed sample arrays
831 * \param uiStride stride of reconstructed sample arrays
832 * \param uiWidth CU width
833 * \param uiHeight CU height
[1260]834 * \param compID colour component ID
[313]835 * \returns Void
836 */
[1029]837Void TDecCu::xDecodePCMTexture( TComDataCU* pcCU, const UInt uiPartIdx, const Pel *piPCM, Pel* piReco, const UInt uiStride, const UInt uiWidth, const UInt uiHeight, const ComponentID compID)
[313]838{
[1029]839        Pel* piPicReco         = pcCU->getPic()->getPicYuvRec()->getAddr(compID, pcCU->getCtuRsAddr(), pcCU->getZorderIdxInCtu()+uiPartIdx);
840  const UInt uiPicStride       = pcCU->getPic()->getPicYuvRec()->getStride(compID);
[1287]841#if SVC_EXTENSION
842  const UInt uiPcmLeftShiftBit = pcCU->getSlice()->getBitDepth(toChannelType(compID)) - pcCU->getSlice()->getSPS()->getPCMBitDepth(toChannelType(compID));
843#else
[1289]844  const TComSPS &sps           = *(pcCU->getSlice()->getSPS());
845  const UInt uiPcmLeftShiftBit = sps.getBitDepth(toChannelType(compID)) - sps.getPCMBitDepth(toChannelType(compID));
[1287]846#endif
[313]847
[1029]848  for(UInt uiY = 0; uiY < uiHeight; uiY++ )
[313]849  {
[1029]850    for(UInt uiX = 0; uiX < uiWidth; uiX++ )
[313]851    {
852      piReco[uiX] = (piPCM[uiX] << uiPcmLeftShiftBit);
853      piPicReco[uiX] = piReco[uiX];
854    }
855    piPCM += uiWidth;
856    piReco += uiStride;
857    piPicReco += uiPicStride;
858  }
859}
860
861/** Function for reconstructing a PCM mode CU.
862 * \param pcCU pointer to current CU
863 * \param uiDepth CU Depth
864 * \returns Void
865 */
866Void TDecCu::xReconPCM( TComDataCU* pcCU, UInt uiDepth )
867{
[1289]868  const UInt maxCuWidth     = pcCU->getSlice()->getSPS()->getMaxCUWidth();
869  const UInt maxCuHeight    = pcCU->getSlice()->getSPS()->getMaxCUHeight();
[1029]870  for (UInt ch=0; ch < pcCU->getPic()->getNumberValidComponents(); ch++)
871  {
872    const ComponentID compID = ComponentID(ch);
[1289]873    const UInt width  = (maxCuWidth >>(uiDepth+m_ppcYuvResi[uiDepth]->getComponentScaleX(compID)));
874    const UInt height = (maxCuHeight>>(uiDepth+m_ppcYuvResi[uiDepth]->getComponentScaleY(compID)));
[1029]875    const UInt stride = m_ppcYuvResi[uiDepth]->getStride(compID);
876    Pel * pPCMChannel = pcCU->getPCMSample(compID);
877    Pel * pRecChannel = m_ppcYuvReco[uiDepth]->getAddr(compID);
878    xDecodePCMTexture( pcCU, 0, pPCMChannel, pRecChannel, stride, width, height, compID );
879  }
[313]880}
881
[1029]882/** Function for filling the PCM buffer of a CU using its reconstructed sample array
[1260]883 * \param pCU   pointer to current CU
884 * \param depth CU Depth
[313]885 */
886Void TDecCu::xFillPCMBuffer(TComDataCU* pCU, UInt depth)
887{
[1029]888  const ChromaFormat format = pCU->getPic()->getChromaFormat();
[1289]889  const UInt numValidComp   = getNumberValidComponents(format);
890  const UInt maxCuWidth     = pCU->getSlice()->getSPS()->getMaxCUWidth();
891  const UInt maxCuHeight    = pCU->getSlice()->getSPS()->getMaxCUHeight();
[313]892
[1029]893  for (UInt componentIndex = 0; componentIndex < numValidComp; componentIndex++)
[313]894  {
[1029]895    const ComponentID component = ComponentID(componentIndex);
[313]896
[1289]897    const UInt width  = maxCuWidth  >> (depth + getComponentScaleX(component, format));
898    const UInt height = maxCuHeight >> (depth + getComponentScaleY(component, format));
[313]899
[1029]900    Pel *source      = m_ppcYuvReco[depth]->getAddr(component, 0, width);
901    Pel *destination = pCU->getPCMSample(component);
[313]902
[1029]903    const UInt sourceStride = m_ppcYuvReco[depth]->getStride(component);
[313]904
[1029]905    for (Int line = 0; line < height; line++)
[313]906    {
[1029]907      for (Int column = 0; column < width; column++)
908      {
909        destination[column] = source[column];
910      }
911
912      source      += sourceStride;
913      destination += width;
[313]914    }
915  }
916}
[540]917
[313]918//! \}
Note: See TracBrowser for help on using the repository browser.