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

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

port rev 4260

  • Property svn:eol-style set to native
File size: 30.6 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
[1029]206Void TDecCu::xDecodeCU( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, Bool &isLastCtuOfSliceSegment)
[313]207{
208  TComPic* pcPic = pcCU->getPic();
[1029]209  UInt uiCurNumParts    = pcPic->getNumPartitionsInCtu() >> (uiDepth<<1);
[313]210  UInt uiQNumParts      = uiCurNumParts>>2;
[1029]211
[313]212  Bool bBoundary = false;
213  UInt uiLPelX   = pcCU->getCUPelX() + g_auiRasterToPelX[ g_auiZscanToRaster[uiAbsPartIdx] ];
214  UInt uiRPelX   = uiLPelX + (g_uiMaxCUWidth>>uiDepth)  - 1;
215  UInt uiTPelY   = pcCU->getCUPelY() + g_auiRasterToPelY[ g_auiZscanToRaster[uiAbsPartIdx] ];
216  UInt uiBPelY   = uiTPelY + (g_uiMaxCUHeight>>uiDepth) - 1;
[1029]217
[313]218  TComSlice * pcSlice = pcCU->getPic()->getSlice(pcCU->getPic()->getCurrSliceIdx());
[1203]219
220#if SVC_EXTENSION
[1029]221  if( ( uiRPelX < pcSlice->getPicWidthInLumaSamples() ) && ( uiBPelY < pcSlice->getPicHeightInLumaSamples() ) )
[442]222#else
[1029]223  if( ( uiRPelX < pcSlice->getSPS()->getPicWidthInLumaSamples() ) && ( uiBPelY < pcSlice->getSPS()->getPicHeightInLumaSamples() ) )
[442]224#endif
[313]225  {
226    m_pcEntropyDecoder->decodeSplitFlag( pcCU, uiAbsPartIdx, uiDepth );
227  }
228  else
229  {
230    bBoundary = true;
231  }
[1029]232
[313]233  if( ( ( uiDepth < pcCU->getDepth( uiAbsPartIdx ) ) && ( uiDepth < g_uiMaxCUDepth - g_uiAddCUDepth ) ) || bBoundary )
234  {
235    UInt uiIdx = uiAbsPartIdx;
[1235]236    if( (g_uiMaxCUWidth>>uiDepth) == (g_uiMaxCUWidth >> ( pcCU->getSlice()->getPPS()->getMaxCuDQPDepth())) && pcCU->getSlice()->getPPS()->getUseDQP())
[313]237    {
238      setdQPFlag(true);
239      pcCU->setQPSubParts( pcCU->getRefQP(uiAbsPartIdx), uiAbsPartIdx, uiDepth ); // set QP to default QP
240    }
241
[1235]242    if( (g_uiMaxCUWidth>>uiDepth) == (g_uiMaxCUWidth >> ( pcCU->getSlice()->getPPS()->getMaxCuChromaQpAdjDepth())) && pcCU->getSlice()->getUseChromaQpAdj() )
[1029]243    {
244      setIsChromaQpAdjCoded(true);
245    }
246
[313]247    for ( UInt uiPartUnitIdx = 0; uiPartUnitIdx < 4; uiPartUnitIdx++ )
248    {
249      uiLPelX   = pcCU->getCUPelX() + g_auiRasterToPelX[ g_auiZscanToRaster[uiIdx] ];
250      uiTPelY   = pcCU->getCUPelY() + g_auiRasterToPelY[ g_auiZscanToRaster[uiIdx] ];
[1029]251
[1203]252#if SVC_EXTENSION
[1029]253      if ( !isLastCtuOfSliceSegment && ( uiLPelX < pcCU->getSlice()->getPicWidthInLumaSamples() ) && ( uiTPelY < pcCU->getSlice()->getPicHeightInLumaSamples() ) )
[442]254#else
[1029]255      if ( !isLastCtuOfSliceSegment && ( uiLPelX < pcCU->getSlice()->getSPS()->getPicWidthInLumaSamples() ) && ( uiTPelY < pcCU->getSlice()->getSPS()->getPicHeightInLumaSamples() ) )
[442]256#endif
[1029]257      {
258        xDecodeCU( pcCU, uiIdx, uiDepth+1, isLastCtuOfSliceSegment );
[313]259      }
[1029]260      else
261      {
262        pcCU->setOutsideCUPart( uiIdx, uiDepth+1 );
263      }
264
[313]265      uiIdx += uiQNumParts;
266    }
[1235]267    if( (g_uiMaxCUWidth>>uiDepth) == (g_uiMaxCUWidth >> ( pcCU->getSlice()->getPPS()->getMaxCuDQPDepth())) && pcCU->getSlice()->getPPS()->getUseDQP())
[313]268    {
269      if ( getdQPFlag() )
270      {
[1029]271        UInt uiQPSrcPartIdx = uiAbsPartIdx;
[313]272        pcCU->setQPSubParts( pcCU->getRefQP( uiQPSrcPartIdx ), uiAbsPartIdx, uiDepth ); // set QP to default QP
273      }
274    }
275    return;
276  }
[1029]277
[1235]278  if( (g_uiMaxCUWidth>>uiDepth) >= (g_uiMaxCUWidth >> ( pcCU->getSlice()->getPPS()->getMaxCuDQPDepth())) && pcCU->getSlice()->getPPS()->getUseDQP())
[313]279  {
280    setdQPFlag(true);
281    pcCU->setQPSubParts( pcCU->getRefQP(uiAbsPartIdx), uiAbsPartIdx, uiDepth ); // set QP to default QP
282  }
283
[1235]284  if( (g_uiMaxCUWidth>>uiDepth) >= (g_uiMaxCUWidth >> ( pcCU->getSlice()->getPPS()->getMaxCuChromaQpAdjDepth())) && pcCU->getSlice()->getUseChromaQpAdj() )
[1029]285  {
286    setIsChromaQpAdjCoded(true);
287  }
288
[313]289  if (pcCU->getSlice()->getPPS()->getTransquantBypassEnableFlag())
290  {
291    m_pcEntropyDecoder->decodeCUTransquantBypassFlag( pcCU, uiAbsPartIdx, uiDepth );
292  }
[1029]293
[313]294  // decode CU mode and the partition size
295  if( !pcCU->getSlice()->isIntra())
296  {
297    m_pcEntropyDecoder->decodeSkipFlag( pcCU, uiAbsPartIdx, uiDepth );
298  }
299 
[1128]300#if SVC_EXTENSION
301  // Check CU skip for higher layer IRAP skip flag
302  if( pcCU->getSlice()->getVPS()->getHigherLayerIrapSkipFlag() && pcCU->getSlice()->getVPS()->getSingleLayerForNonIrapFlag() && pcCU->getLayerId() > 0 )
[540]303  {
304    Bool lowerLayerExist = false;
305    for(int i=0;i<pcCU->getLayerId();i++)
306    {
307      if(pcCU->getSlice()->getBaseColPic(pcCU->getSlice()->getInterLayerPredLayerIdc(i)))
308      {
309        lowerLayerExist = true;
310      }
311    }
[1128]312
313    if( lowerLayerExist && !pcCU->isSkipped(uiAbsPartIdx) )
[540]314    {
[1128]315      printf( "Warning: CU is not skipped with enabled higher layer IRAP skip flag\n" );
[540]316    }
317  }
318#endif
319 
[313]320  if( pcCU->isSkipped(uiAbsPartIdx) )
321  {
322    m_ppcCU[uiDepth]->copyInterPredInfoFrom( pcCU, uiAbsPartIdx, REF_PIC_LIST_0 );
323    m_ppcCU[uiDepth]->copyInterPredInfoFrom( pcCU, uiAbsPartIdx, REF_PIC_LIST_1 );
324    TComMvField cMvFieldNeighbours[MRG_MAX_NUM_CANDS << 1]; // double length for mv of both lists
325    UChar uhInterDirNeighbours[MRG_MAX_NUM_CANDS];
326    Int numValidMergeCand = 0;
327    for( UInt ui = 0; ui < m_ppcCU[uiDepth]->getSlice()->getMaxNumMergeCand(); ++ui )
328    {
329      uhInterDirNeighbours[ui] = 0;
330    }
331    m_pcEntropyDecoder->decodeMergeIndex( pcCU, 0, uiAbsPartIdx, uiDepth );
332    UInt uiMergeIndex = pcCU->getMergeIndex(uiAbsPartIdx);
333    m_ppcCU[uiDepth]->getInterMergeCandidates( 0, 0, cMvFieldNeighbours, uhInterDirNeighbours, numValidMergeCand, uiMergeIndex );
334    pcCU->setInterDirSubParts( uhInterDirNeighbours[uiMergeIndex], uiAbsPartIdx, 0, uiDepth );
335
336    TComMv cTmpMv( 0, 0 );
337    for ( UInt uiRefListIdx = 0; uiRefListIdx < 2; uiRefListIdx++ )
[1029]338    {
[313]339      if ( pcCU->getSlice()->getNumRefIdx( RefPicList( uiRefListIdx ) ) > 0 )
340      {
341        pcCU->setMVPIdxSubParts( 0, RefPicList( uiRefListIdx ), uiAbsPartIdx, 0, uiDepth);
342        pcCU->setMVPNumSubParts( 0, RefPicList( uiRefListIdx ), uiAbsPartIdx, 0, uiDepth);
343        pcCU->getCUMvField( RefPicList( uiRefListIdx ) )->setAllMvd( cTmpMv, SIZE_2Nx2N, uiAbsPartIdx, uiDepth );
344        pcCU->getCUMvField( RefPicList( uiRefListIdx ) )->setAllMvField( cMvFieldNeighbours[ 2*uiMergeIndex + uiRefListIdx ], SIZE_2Nx2N, uiAbsPartIdx, uiDepth );
345      }
346    }
[1029]347    xFinishDecodeCU( pcCU, uiAbsPartIdx, uiDepth, isLastCtuOfSliceSegment );
[313]348    return;
349  }
350
351  m_pcEntropyDecoder->decodePredMode( pcCU, uiAbsPartIdx, uiDepth );
352  m_pcEntropyDecoder->decodePartSize( pcCU, uiAbsPartIdx, uiDepth );
353
354  if (pcCU->isIntra( uiAbsPartIdx ) && pcCU->getPartitionSize( uiAbsPartIdx ) == SIZE_2Nx2N )
355  {
356    m_pcEntropyDecoder->decodeIPCMInfo( pcCU, uiAbsPartIdx, uiDepth );
357
358    if(pcCU->getIPCMFlag(uiAbsPartIdx))
359    {
[1029]360      xFinishDecodeCU( pcCU, uiAbsPartIdx, uiDepth, isLastCtuOfSliceSegment );
[313]361      return;
362    }
363  }
364
365  // prediction mode ( Intra : direction mode, Inter : Mv, reference idx )
366  m_pcEntropyDecoder->decodePredInfo( pcCU, uiAbsPartIdx, uiDepth, m_ppcCU[uiDepth]);
367
368  // Coefficient decoding
369  Bool bCodeDQP = getdQPFlag();
[1029]370  Bool isChromaQpAdjCoded = getIsChromaQpAdjCoded();
371  m_pcEntropyDecoder->decodeCoeff( pcCU, uiAbsPartIdx, uiDepth, bCodeDQP, isChromaQpAdjCoded );
372  setIsChromaQpAdjCoded( isChromaQpAdjCoded );
[313]373  setdQPFlag( bCodeDQP );
[1029]374  xFinishDecodeCU( pcCU, uiAbsPartIdx, uiDepth, isLastCtuOfSliceSegment );
[313]375}
376
[1029]377Void TDecCu::xFinishDecodeCU( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, Bool &isLastCtuOfSliceSegment)
[313]378{
379  if(  pcCU->getSlice()->getPPS()->getUseDQP())
380  {
381    pcCU->setQPSubParts( getdQPFlag()?pcCU->getRefQP(uiAbsPartIdx):pcCU->getCodedQP(), uiAbsPartIdx, uiDepth ); // set QP
382  }
383
[1029]384  if (pcCU->getSlice()->getUseChromaQpAdj() && !getIsChromaQpAdjCoded())
385  {
386    pcCU->setChromaQpAdjSubParts( pcCU->getCodedChromaQpAdj(), uiAbsPartIdx, uiDepth ); // set QP
387  }
388
389  isLastCtuOfSliceSegment = xDecodeSliceEnd( pcCU, uiAbsPartIdx );
[313]390}
391
[1029]392Void TDecCu::xDecompressCU( TComDataCU* pCtu, UInt uiAbsPartIdx,  UInt uiDepth )
[313]393{
[1029]394  TComPic* pcPic = pCtu->getPic();
395
[313]396  Bool bBoundary = false;
[1029]397  UInt uiLPelX   = pCtu->getCUPelX() + g_auiRasterToPelX[ g_auiZscanToRaster[uiAbsPartIdx] ];
[313]398  UInt uiRPelX   = uiLPelX + (g_uiMaxCUWidth>>uiDepth)  - 1;
[1029]399  UInt uiTPelY   = pCtu->getCUPelY() + g_auiRasterToPelY[ g_auiZscanToRaster[uiAbsPartIdx] ];
[313]400  UInt uiBPelY   = uiTPelY + (g_uiMaxCUHeight>>uiDepth) - 1;
[1029]401
402  TComSlice * pcSlice = pCtu->getPic()->getSlice(pCtu->getPic()->getCurrSliceIdx());
403
[1203]404#if SVC_EXTENSION
[1029]405  if( ( uiRPelX >= pcSlice->getPicWidthInLumaSamples() ) || ( uiBPelY >= pcSlice->getPicHeightInLumaSamples() ) )
[442]406#else
[1029]407  if( ( uiRPelX >= pcSlice->getSPS()->getPicWidthInLumaSamples() ) || ( uiBPelY >= pcSlice->getSPS()->getPicHeightInLumaSamples() ) )
[442]408#endif
[313]409  {
410    bBoundary = true;
411  }
[1029]412
413  if( ( ( uiDepth < pCtu->getDepth( uiAbsPartIdx ) ) && ( uiDepth < g_uiMaxCUDepth - g_uiAddCUDepth ) ) || bBoundary )
[313]414  {
415    UInt uiNextDepth = uiDepth + 1;
[1029]416    UInt uiQNumParts = pCtu->getTotalNumPart() >> (uiNextDepth<<1);
[313]417    UInt uiIdx = uiAbsPartIdx;
418    for ( UInt uiPartIdx = 0; uiPartIdx < 4; uiPartIdx++ )
419    {
[1029]420      uiLPelX = pCtu->getCUPelX() + g_auiRasterToPelX[ g_auiZscanToRaster[uiIdx] ];
421      uiTPelY = pCtu->getCUPelY() + g_auiRasterToPelY[ g_auiZscanToRaster[uiIdx] ];
422
[1203]423#if SVC_EXTENSION
[1029]424      if( ( uiLPelX < pcSlice->getPicWidthInLumaSamples() ) && ( uiTPelY < pcSlice->getPicHeightInLumaSamples() ) )
[442]425#else
[1029]426      if( ( uiLPelX < pcSlice->getSPS()->getPicWidthInLumaSamples() ) && ( uiTPelY < pcSlice->getSPS()->getPicHeightInLumaSamples() ) )
[442]427#endif
[313]428      {
[1029]429        xDecompressCU(pCtu, uiIdx, uiNextDepth );
[313]430      }
[1029]431
[313]432      uiIdx += uiQNumParts;
433    }
434    return;
435  }
[1029]436
[313]437  // Residual reconstruction
438  m_ppcYuvResi[uiDepth]->clear();
[1029]439
440  m_ppcCU[uiDepth]->copySubCU( pCtu, uiAbsPartIdx, uiDepth );
441
[313]442  switch( m_ppcCU[uiDepth]->getPredictionMode(0) )
443  {
444    case MODE_INTER:
445      xReconInter( m_ppcCU[uiDepth], uiDepth );
446      break;
447    case MODE_INTRA:
448      xReconIntraQT( m_ppcCU[uiDepth], uiDepth );
449      break;
450    default:
451      assert(0);
452      break;
453  }
[1029]454
455#ifdef DEBUG_STRING
456  const PredMode predMode=m_ppcCU[uiDepth]->getPredictionMode(0);
457  if (DebugOptionList::DebugString_Structure.getInt()&DebugStringGetPredModeMask(predMode))
458  {
459    PartSize eSize=m_ppcCU[uiDepth]->getPartitionSize(0);
460    std::ostream &ss(std::cout);
461
462    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;
463  }
464#endif
465
[313]466  if ( m_ppcCU[uiDepth]->isLosslessCoded(0) && (m_ppcCU[uiDepth]->getIPCMFlag(0) == false))
467  {
468    xFillPCMBuffer(m_ppcCU[uiDepth], uiDepth);
469  }
[1029]470
[313]471  xCopyToPic( m_ppcCU[uiDepth], pcPic, uiAbsPartIdx, uiDepth );
472}
473
474Void TDecCu::xReconInter( TComDataCU* pcCU, UInt uiDepth )
475{
[1029]476
[313]477  // inter prediction
478  m_pcPrediction->motionCompensation( pcCU, m_ppcYuvReco[uiDepth] );
[1029]479
480#ifdef DEBUG_STRING
481  const Int debugPredModeMask=DebugStringGetPredModeMask(MODE_INTER);
[1246]482  if (DebugOptionList::DebugString_Pred.getInt()&debugPredModeMask)
483  {
484    printBlockToStream(std::cout, "###inter-pred: ", *(m_ppcYuvReco[uiDepth]));
485  }
[1029]486#endif
487
[313]488  // inter recon
[1029]489  xDecodeInterTexture( pcCU, uiDepth );
490
491#ifdef DEBUG_STRING
[1246]492  if (DebugOptionList::DebugString_Resi.getInt()&debugPredModeMask)
493  {
494    printBlockToStream(std::cout, "###inter-resi: ", *(m_ppcYuvResi[uiDepth]));
495  }
[1029]496#endif
497
[313]498  // clip for only non-zero cbp case
[1029]499  if  ( pcCU->getQtRootCbf( 0) )
[313]500  {
501    m_ppcYuvReco[uiDepth]->addClip( m_ppcYuvReco[uiDepth], m_ppcYuvResi[uiDepth], 0, pcCU->getWidth( 0 ) );
502  }
503  else
504  {
505    m_ppcYuvReco[uiDepth]->copyPartToPartYuv( m_ppcYuvReco[uiDepth],0, pcCU->getWidth( 0 ),pcCU->getHeight( 0 ));
506  }
[1029]507#ifdef DEBUG_STRING
[1246]508  if (DebugOptionList::DebugString_Reco.getInt()&debugPredModeMask)
509  {
510    printBlockToStream(std::cout, "###inter-reco: ", *(m_ppcYuvReco[uiDepth]));
511  }
[1029]512#endif
513
[313]514}
515
[1029]516
[313]517Void
[1029]518TDecCu::xIntraRecBlk(       TComYuv*    pcRecoYuv,
519                            TComYuv*    pcPredYuv,
520                            TComYuv*    pcResiYuv,
521                      const ComponentID compID,
522                            TComTU     &rTu)
[313]523{
[1246]524  if (!rTu.ProcessComponentSection(compID))
525  {
526    return;
527  }
[1029]528  const Bool       bIsLuma = isLuma(compID);
[313]529
530
[1029]531  TComDataCU *pcCU = rTu.getCU();
532  const UInt uiAbsPartIdx=rTu.GetAbsPartIdxTU();
533
534  const TComRectangle &tuRect  =rTu.getRect(compID);
535  const UInt uiWidth           = tuRect.width;
536  const UInt uiHeight          = tuRect.height;
537  const UInt uiStride          = pcRecoYuv->getStride (compID);
538        Pel* piPred            = pcPredYuv->getAddr( compID, uiAbsPartIdx );
539  const ChromaFormat chFmt     = rTu.GetChromaFormat();
540
541  if (uiWidth != uiHeight)
[313]542  {
[1029]543    //------------------------------------------------
[313]544
[1029]545    //split at current level if dividing into square sub-TUs
[313]546
[1029]547    TComTURecurse subTURecurse(rTu, false, TComTU::VERTICAL_SPLIT, true, compID);
[313]548
[1029]549    //recurse further
550    do
[313]551    {
[1029]552      xIntraRecBlk(pcRecoYuv, pcPredYuv, pcResiYuv, compID, subTURecurse);
[1246]553    } while (subTURecurse.nextSection(rTu));
[1029]554
555    //------------------------------------------------
556
557    return;
[313]558  }
[1029]559
560  const UInt uiChPredMode  = pcCU->getIntraDir( toChannelType(compID), uiAbsPartIdx );
561  const UInt uiChCodedMode = (uiChPredMode==DM_CHROMA_IDX && !bIsLuma) ? pcCU->getIntraDir(CHANNEL_TYPE_LUMA, getChromasCorrespondingPULumaIdx(uiAbsPartIdx, chFmt)) : uiChPredMode;
562  const UInt uiChFinalMode = ((chFmt == CHROMA_422)       && !bIsLuma) ? g_chroma422IntraAngleMappingTable[uiChCodedMode] : uiChCodedMode;
563
[313]564  //===== init availability pattern =====
565  Bool  bAboveAvail = false;
566  Bool  bLeftAvail  = false;
567
[1029]568  const Bool bUseFilteredPredictions=TComPrediction::filteringIntraReferenceSamples(compID, uiChFinalMode, uiWidth, uiHeight, chFmt, pcCU->getSlice()->getSPS()->getDisableIntraReferenceSmoothing());
569
570#ifdef DEBUG_STRING
571  std::ostream &ss(std::cout);
572#endif
573
574  DEBUG_STRING_NEW(sTemp)
575  m_pcPrediction->initAdiPatternChType( rTu, bAboveAvail, bLeftAvail, compID, bUseFilteredPredictions  DEBUG_STRING_PASS_INTO(sTemp) );
576
577
[313]578  //===== get prediction signal =====
579
[1029]580  m_pcPrediction->predIntraAng( compID,   uiChFinalMode, 0 /* Decoder does not have an original image */, 0, piPred, uiStride, rTu, bAboveAvail, bLeftAvail, bUseFilteredPredictions );
581
582#ifdef DEBUG_STRING
583  ss << sTemp;
584#endif
585
[313]586  //===== inverse transform =====
[1029]587  Pel*      piResi            = pcResiYuv->getAddr( compID, uiAbsPartIdx );
588  TCoeff*   pcCoeff           = pcCU->getCoeff(compID) + rTu.getCoefficientOffset(compID);//( uiNumCoeffInc * uiAbsPartIdx );
589
590  const QpParam cQP(*pcCU, compID);
591
592
593  DEBUG_STRING_NEW(sDebug);
594#ifdef DEBUG_STRING
595  const Int debugPredModeMask=DebugStringGetPredModeMask(MODE_INTRA);
596  std::string *psDebug=(DebugOptionList::DebugString_InvTran.getInt()&debugPredModeMask) ? &sDebug : 0;
597#endif
598
599  if (pcCU->getCbf(uiAbsPartIdx, compID, rTu.GetTransformDepthRel()) != 0)
[313]600  {
[1029]601    m_pcTrQuant->invTransformNxN( rTu, compID, piResi, uiStride, pcCoeff, cQP DEBUG_STRING_PASS_INTO(psDebug) );
[313]602  }
603  else
604  {
[1029]605    for (UInt y = 0; y < uiHeight; y++)
[1246]606    {
[1029]607      for (UInt x = 0; x < uiWidth; x++)
608      {
609        piResi[(y * uiStride) + x] = 0;
610      }
[1246]611    }
[313]612  }
[1029]613
614#ifdef DEBUG_STRING
615  if (psDebug)
[1246]616  {
[1029]617    ss << (*psDebug);
[1246]618  }
[494]619#endif
[1029]620
621  //===== reconstruction =====
622  const UInt uiRecIPredStride  = pcCU->getPic()->getPicYuvRec()->getStride(compID);
623
624  const Bool useCrossComponentPrediction = isChroma(compID) && (pcCU->getCrossComponentPredictionAlpha(uiAbsPartIdx, compID) != 0);
625  const Pel* pResiLuma  = pcResiYuv->getAddr( COMPONENT_Y, uiAbsPartIdx );
626  const Int  strideLuma = pcResiYuv->getStride( COMPONENT_Y );
627
628        Pel* pPred      = piPred;
629        Pel* pResi      = piResi;
630        Pel* pReco      = pcRecoYuv->getAddr( compID, uiAbsPartIdx );
631        Pel* pRecIPred  = pcCU->getPic()->getPicYuvRec()->getAddr( compID, pcCU->getCtuRsAddr(), pcCU->getZorderIdxInCtu() + uiAbsPartIdx );
632
633
634#ifdef DEBUG_STRING
635  const Bool bDebugPred=((DebugOptionList::DebugString_Pred.getInt()&debugPredModeMask) && DEBUG_STRING_CHANNEL_CONDITION(compID));
636  const Bool bDebugResi=((DebugOptionList::DebugString_Resi.getInt()&debugPredModeMask) && DEBUG_STRING_CHANNEL_CONDITION(compID));
637  const Bool bDebugReco=((DebugOptionList::DebugString_Reco.getInt()&debugPredModeMask) && DEBUG_STRING_CHANNEL_CONDITION(compID));
638  if (bDebugPred || bDebugResi || bDebugReco)
[1246]639  {
[1029]640    ss << "###: " << "CompID: " << compID << " pred mode (ch/fin): " << uiChPredMode << "/" << uiChFinalMode << " absPartIdx: " << rTu.GetAbsPartIdxTU() << std::endl;
[1246]641  }
[494]642#endif
[313]643
[1029]644#if O0043_BEST_EFFORT_DECODING
645  const Int bitDepthDelta = g_bitDepthInStream[toChannelType(compID)] - g_bitDepth[toChannelType(compID)];
646#endif
647  const Int clipbd = g_bitDepth[toChannelType(compID)];
[313]648
[1029]649  if( useCrossComponentPrediction )
650  {
651    TComTrQuant::crossComponentPrediction( rTu, compID, pResiLuma, piResi, piResi, uiWidth, uiHeight, strideLuma, uiStride, uiStride, true );
652  }
653
[313]654  for( UInt uiY = 0; uiY < uiHeight; uiY++ )
655  {
[1029]656#ifdef DEBUG_STRING
[1246]657    if (bDebugPred || bDebugResi || bDebugReco)
658    {
659      ss << "###: ";
660    }
[1029]661
662    if (bDebugPred)
663    {
664      ss << " - pred: ";
665      for( UInt uiX = 0; uiX < uiWidth; uiX++ )
666      {
667        ss << pPred[ uiX ] << ", ";
668      }
669    }
[1246]670    if (bDebugResi)
671    {
672      ss << " - resi: ";
673    }
[1029]674#endif
675
[313]676    for( UInt uiX = 0; uiX < uiWidth; uiX++ )
677    {
[1029]678#ifdef DEBUG_STRING
679      if (bDebugResi)
[1246]680      {
[1029]681        ss << pResi[ uiX ] << ", ";
[1246]682      }
[1029]683#endif
684#if O0043_BEST_EFFORT_DECODING
685      pReco    [ uiX ] = ClipBD( rightShiftEvenRounding<Pel>(pPred[ uiX ] + pResi[ uiX ], bitDepthDelta), clipbd );
686#else
687      pReco    [ uiX ] = ClipBD( pPred[ uiX ] + pResi[ uiX ], clipbd );
688#endif
[313]689      pRecIPred[ uiX ] = pReco[ uiX ];
690    }
[1029]691#ifdef DEBUG_STRING
692    if (bDebugReco)
693    {
694      ss << " - reco: ";
695      for( UInt uiX = 0; uiX < uiWidth; uiX++ )
696      {
697        ss << pReco[ uiX ] << ", ";
698      }
699    }
700
701    if (bDebugPred || bDebugResi || bDebugReco)
[1246]702    {
[1029]703      ss << "\n";
[1246]704    }
[1029]705#endif
[313]706    pPred     += uiStride;
707    pResi     += uiStride;
708    pReco     += uiStride;
709    pRecIPred += uiRecIPredStride;
710  }
711}
712
713
714Void
715TDecCu::xReconIntraQT( TComDataCU* pcCU, UInt uiDepth )
716{
717  if (pcCU->getIPCMFlag(0))
718  {
719    xReconPCM( pcCU, uiDepth );
720    return;
721  }
[1029]722  const UInt numChType = pcCU->getPic()->getChromaFormat()!=CHROMA_400 ? 2 : 1;
723  for (UInt chType=CHANNEL_TYPE_LUMA; chType<numChType; chType++)
[313]724  {
[1029]725    const ChannelType chanType=ChannelType(chType);
726    const Bool NxNPUHas4Parts = ::isChroma(chanType) ? enable4ChromaPUsInIntraNxNCU(pcCU->getPic()->getChromaFormat()) : true;
727    const UInt uiInitTrDepth = ( pcCU->getPartitionSize(0) != SIZE_2Nx2N && NxNPUHas4Parts ? 1 : 0 );
[313]728
[1029]729    TComTURecurse tuRecurseCU(pcCU, 0);
730    TComTURecurse tuRecurseWithPU(tuRecurseCU, false, (uiInitTrDepth==0)?TComTU::DONT_SPLIT : TComTU::QUAD_SPLIT);
[313]731
[1029]732    do
[313]733    {
[1029]734      xIntraRecQT( m_ppcYuvReco[uiDepth], m_ppcYuvReco[uiDepth], m_ppcYuvResi[uiDepth], chanType, tuRecurseWithPU );
735    } while (tuRecurseWithPU.nextSection(tuRecurseCU));
[313]736  }
737}
738
[1029]739
740
[1260]741/** Function for deriving reconstructed PU/CU chroma samples with QTree structure
[313]742 * \param pcRecoYuv pointer to reconstructed sample arrays
743 * \param pcPredYuv pointer to prediction sample arrays
744 * \param pcResiYuv pointer to residue sample arrays
[1260]745 * \param chType    texture channel type (luma/chroma)
746 * \param rTu       reference to transform data
[1029]747 *
[1260]748 \ This function derives reconstructed PU/CU chroma samples with QTree recursive structure
[313]749 */
[1029]750
[313]751Void
[1029]752TDecCu::xIntraRecQT(TComYuv*    pcRecoYuv,
753                    TComYuv*    pcPredYuv,
754                    TComYuv*    pcResiYuv,
755                    const ChannelType chType,
756                    TComTU     &rTu)
[313]757{
[1029]758  UInt uiTrDepth    = rTu.GetTransformDepthRel();
759  TComDataCU *pcCU  = rTu.getCU();
760  UInt uiAbsPartIdx = rTu.GetAbsPartIdxTU();
[313]761  UInt uiTrMode     = pcCU->getTransformIdx( uiAbsPartIdx );
762  if( uiTrMode == uiTrDepth )
763  {
[1029]764    if (isLuma(chType))
[1246]765    {
[1029]766      xIntraRecBlk( pcRecoYuv, pcPredYuv, pcResiYuv, COMPONENT_Y,  rTu );
[1246]767    }
[1029]768    else
769    {
770      const UInt numValidComp=getNumberValidComponents(rTu.GetChromaFormat());
771      for(UInt compID=COMPONENT_Cb; compID<numValidComp; compID++)
772      {
773        xIntraRecBlk( pcRecoYuv, pcPredYuv, pcResiYuv, ComponentID(compID), rTu );
774      }
775    }
[313]776  }
777  else
778  {
[1029]779    TComTURecurse tuRecurseChild(rTu, false);
780    do
[313]781    {
[1029]782      xIntraRecQT( pcRecoYuv, pcPredYuv, pcResiYuv, chType, tuRecurseChild );
783    } while (tuRecurseChild.nextSection(rTu));
[313]784  }
785}
786
787Void TDecCu::xCopyToPic( TComDataCU* pcCU, TComPic* pcPic, UInt uiZorderIdx, UInt uiDepth )
788{
[1029]789  UInt uiCtuRsAddr = pcCU->getCtuRsAddr();
790
791  m_ppcYuvReco[uiDepth]->copyToPicYuv  ( pcPic->getPicYuvRec (), uiCtuRsAddr, uiZorderIdx );
792
[313]793  return;
794}
795
[1029]796Void TDecCu::xDecodeInterTexture ( TComDataCU* pcCU, UInt uiDepth )
[313]797{
798
[1029]799  TComTURecurse tuRecur(pcCU, 0, uiDepth);
[313]800
[1029]801  for(UInt ch=0; ch<pcCU->getPic()->getNumberValidComponents(); ch++)
802  {
803    const ComponentID compID=ComponentID(ch);
804    DEBUG_STRING_OUTPUT(std::cout, debug_reorder_data_inter_token[compID])
[313]805
[1029]806    m_pcTrQuant->invRecurTransformNxN ( compID, m_ppcYuvResi[uiDepth], tuRecur );
807  }
[313]808
[1029]809  DEBUG_STRING_OUTPUT(std::cout, debug_reorder_data_inter_token[MAX_NUM_COMPONENT])
[313]810}
811
812/** Function for deriving reconstructed luma/chroma samples of a PCM mode CU.
813 * \param pcCU pointer to current CU
814 * \param uiPartIdx part index
815 * \param piPCM pointer to PCM code arrays
816 * \param piReco pointer to reconstructed sample arrays
817 * \param uiStride stride of reconstructed sample arrays
818 * \param uiWidth CU width
819 * \param uiHeight CU height
[1260]820 * \param compID colour component ID
[313]821 * \returns Void
822 */
[1029]823Void 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]824{
[1029]825        Pel* piPicReco         = pcCU->getPic()->getPicYuvRec()->getAddr(compID, pcCU->getCtuRsAddr(), pcCU->getZorderIdxInCtu()+uiPartIdx);
826  const UInt uiPicStride       = pcCU->getPic()->getPicYuvRec()->getStride(compID);
827  const UInt uiPcmLeftShiftBit = g_bitDepth[toChannelType(compID)] - pcCU->getSlice()->getSPS()->getPCMBitDepth(toChannelType(compID));
[313]828
[1029]829  for(UInt uiY = 0; uiY < uiHeight; uiY++ )
[313]830  {
[1029]831    for(UInt uiX = 0; uiX < uiWidth; uiX++ )
[313]832    {
833      piReco[uiX] = (piPCM[uiX] << uiPcmLeftShiftBit);
834      piPicReco[uiX] = piReco[uiX];
835    }
836    piPCM += uiWidth;
837    piReco += uiStride;
838    piPicReco += uiPicStride;
839  }
840}
841
842/** Function for reconstructing a PCM mode CU.
843 * \param pcCU pointer to current CU
844 * \param uiDepth CU Depth
845 * \returns Void
846 */
847Void TDecCu::xReconPCM( TComDataCU* pcCU, UInt uiDepth )
848{
[1029]849  for (UInt ch=0; ch < pcCU->getPic()->getNumberValidComponents(); ch++)
850  {
851    const ComponentID compID = ComponentID(ch);
852    const UInt width  = (g_uiMaxCUWidth >>(uiDepth+m_ppcYuvResi[uiDepth]->getComponentScaleX(compID)));
853    const UInt height = (g_uiMaxCUHeight>>(uiDepth+m_ppcYuvResi[uiDepth]->getComponentScaleY(compID)));
854    const UInt stride = m_ppcYuvResi[uiDepth]->getStride(compID);
855    Pel * pPCMChannel = pcCU->getPCMSample(compID);
856    Pel * pRecChannel = m_ppcYuvReco[uiDepth]->getAddr(compID);
857    xDecodePCMTexture( pcCU, 0, pPCMChannel, pRecChannel, stride, width, height, compID );
858  }
[313]859}
860
[1029]861/** Function for filling the PCM buffer of a CU using its reconstructed sample array
[1260]862 * \param pCU   pointer to current CU
863 * \param depth CU Depth
[313]864 */
865Void TDecCu::xFillPCMBuffer(TComDataCU* pCU, UInt depth)
866{
[1029]867  const ChromaFormat format = pCU->getPic()->getChromaFormat();
868  const UInt numValidComp=getNumberValidComponents(format);
[313]869
[1029]870  for (UInt componentIndex = 0; componentIndex < numValidComp; componentIndex++)
[313]871  {
[1029]872    const ComponentID component = ComponentID(componentIndex);
[313]873
[1029]874    const UInt width  = g_uiMaxCUWidth  >> (depth + getComponentScaleX(component, format));
875    const UInt height = g_uiMaxCUHeight >> (depth + getComponentScaleY(component, format));
[313]876
[1029]877    Pel *source      = m_ppcYuvReco[depth]->getAddr(component, 0, width);
878    Pel *destination = pCU->getPCMSample(component);
[313]879
[1029]880    const UInt sourceStride = m_ppcYuvReco[depth]->getStride(component);
[313]881
[1029]882    for (Int line = 0; line < height; line++)
[313]883    {
[1029]884      for (Int column = 0; column < width; column++)
885      {
886        destination[column] = source[column];
887      }
888
889      source      += sourceStride;
890      destination += width;
[313]891    }
892  }
893}
[540]894
[313]895//! \}
Note: See TracBrowser for help on using the repository browser.