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

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

macro cleanup: HIGHER_LAYER_IRAP_SKIP_FLAG, HIGHER_LAYER_IRAP_SKIP_FLAG (keep it for encoder only)

  • Property svn:eol-style set to native
File size: 30.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 *
[595]6 * Copyright (c) 2010-2014, 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"
[313]40#if SVC_EXTENSION
41#include "TDecTop.h"
42#endif
43
44
45//! \ingroup TLibDecoder
46//! \{
47
48// ====================================================================================================================
49// Constructor / destructor / create / destroy
50// ====================================================================================================================
51
52TDecCu::TDecCu()
53{
54  m_ppcYuvResi = NULL;
55  m_ppcYuvReco = NULL;
56  m_ppcCU      = NULL;
57}
58
59TDecCu::~TDecCu()
60{
61}
62
63#if SVC_EXTENSION
64Void TDecCu::init(TDecTop** ppcDecTop, TDecEntropy* pcEntropyDecoder, TComTrQuant* pcTrQuant, TComPrediction* pcPrediction, UInt layerId)
65{
66  m_pcEntropyDecoder  = pcEntropyDecoder;
67  m_pcTrQuant         = pcTrQuant;
68  m_pcPrediction      = pcPrediction; 
69  m_ppcTDecTop = ppcDecTop;
70  m_layerId = layerId; 
71
72  for ( UInt ui = 0; ui < m_uiMaxDepth-1; ui++ )
73  {
74    m_ppcCU     [ui]->setLayerId(layerId);
75  }
[713]76 
77#if LAYER_CTB
78  memcpy(g_auiLayerZscanToRaster[m_layerId], g_auiZscanToRaster, sizeof( g_auiZscanToRaster ) );
79  memcpy(g_auiLayerRasterToZscan[m_layerId], g_auiRasterToZscan, sizeof( g_auiRasterToZscan ) );
80  memcpy(g_auiLayerRasterToPelX[m_layerId],  g_auiRasterToPelX,  sizeof( g_auiRasterToPelX ) );
81  memcpy(g_auiLayerRasterToPelY[m_layerId],  g_auiRasterToPelY,  sizeof( g_auiRasterToPelY ) );
82#endif
[313]83}
84#else
85Void TDecCu::init( TDecEntropy* pcEntropyDecoder, TComTrQuant* pcTrQuant, TComPrediction* pcPrediction)
86{
87  m_pcEntropyDecoder  = pcEntropyDecoder;
88  m_pcTrQuant         = pcTrQuant;
89  m_pcPrediction      = pcPrediction;
90}
91#endif
92
93/**
94 \param    uiMaxDepth    total number of allowable depth
95 \param    uiMaxWidth    largest CU width
96 \param    uiMaxHeight   largest CU height
97 */
[1029]98Void TDecCu::create( UInt uiMaxDepth, UInt uiMaxWidth, UInt uiMaxHeight, ChromaFormat chromaFormatIDC )
[313]99{
100  m_uiMaxDepth = uiMaxDepth+1;
[1029]101
[313]102  m_ppcYuvResi = new TComYuv*[m_uiMaxDepth-1];
103  m_ppcYuvReco = new TComYuv*[m_uiMaxDepth-1];
104  m_ppcCU      = new TComDataCU*[m_uiMaxDepth-1];
[1029]105
[313]106  UInt uiNumPartitions;
107  for ( UInt ui = 0; ui < m_uiMaxDepth-1; ui++ )
108  {
109    uiNumPartitions = 1<<( ( m_uiMaxDepth - ui - 1 )<<1 );
110    UInt uiWidth  = uiMaxWidth  >> ui;
111    UInt uiHeight = uiMaxHeight >> ui;
[1029]112
113    m_ppcYuvResi[ui] = new TComYuv;    m_ppcYuvResi[ui]->create( uiWidth, uiHeight, chromaFormatIDC );
114    m_ppcYuvReco[ui] = new TComYuv;    m_ppcYuvReco[ui]->create( uiWidth, uiHeight, chromaFormatIDC );
115    m_ppcCU     [ui] = new TComDataCU; m_ppcCU     [ui]->create( chromaFormatIDC, uiNumPartitions, uiWidth, uiHeight, true, uiMaxWidth >> (m_uiMaxDepth - 1) );
[313]116  }
[1029]117
[313]118  m_bDecodeDQP = false;
[1029]119  m_IsChromaQpAdjCoded = false;
[313]120
121  // initialize partition order.
122  UInt* piTmp = &g_auiZscanToRaster[0];
123  initZscanToRaster(m_uiMaxDepth, 1, 0, piTmp);
124  initRasterToZscan( uiMaxWidth, uiMaxHeight, m_uiMaxDepth );
[1029]125
[313]126  // initialize conversion matrix from partition index to pel
127  initRasterToPelXY( uiMaxWidth, uiMaxHeight, m_uiMaxDepth );
128}
129
130Void TDecCu::destroy()
131{
132  for ( UInt ui = 0; ui < m_uiMaxDepth-1; ui++ )
133  {
134    m_ppcYuvResi[ui]->destroy(); delete m_ppcYuvResi[ui]; m_ppcYuvResi[ui] = NULL;
135    m_ppcYuvReco[ui]->destroy(); delete m_ppcYuvReco[ui]; m_ppcYuvReco[ui] = NULL;
136    m_ppcCU     [ui]->destroy(); delete m_ppcCU     [ui]; m_ppcCU     [ui] = NULL;
137  }
[1029]138
[313]139  delete [] m_ppcYuvResi; m_ppcYuvResi = NULL;
140  delete [] m_ppcYuvReco; m_ppcYuvReco = NULL;
141  delete [] m_ppcCU     ; m_ppcCU      = NULL;
142}
143
144// ====================================================================================================================
145// Public member functions
146// ====================================================================================================================
147
148/** \param    pcCU        pointer of CU data
149 \param    ruiIsLast   last data?
150 */
[1029]151Void TDecCu::decodeCtu( TComDataCU* pCtu, Bool& isLastCtuOfSliceSegment )
[313]152{
[1029]153  if ( pCtu->getSlice()->getPPS()->getUseDQP() )
[313]154  {
155    setdQPFlag(true);
156  }
157
[1029]158  if ( pCtu->getSlice()->getUseChromaQpAdj() )
159  {
160    setIsChromaQpAdjCoded(true);
161  }
162
[313]163#if SVC_EXTENSION
[1029]164  pCtu->setLayerId(m_layerId);
[313]165#endif
[1029]166
167  // start from the top level CU
168  xDecodeCU( pCtu, 0, 0, isLastCtuOfSliceSegment);
[313]169}
170
171/** \param    pcCU        pointer of CU data
172 */
[1029]173Void TDecCu::decompressCtu( TComDataCU* pCtu )
[313]174{
[1029]175  xDecompressCU( pCtu, 0,  0 );
[313]176}
177
178// ====================================================================================================================
179// Protected member functions
180// ====================================================================================================================
181
182/**decode end-of-slice flag
183 * \param pcCU
[1029]184 * \param uiAbsPartIdx
185 * \param uiDepth
[313]186 * \returns Bool
187 */
[1029]188Bool TDecCu::xDecodeSliceEnd( TComDataCU* pcCU, UInt uiAbsPartIdx )
[313]189{
[1029]190  UInt uiIsLastCtuOfSliceSegment;
[313]191
[1029]192  if (pcCU->isLastSubCUOfCtu(uiAbsPartIdx))
[313]193  {
[1029]194    m_pcEntropyDecoder->decodeTerminatingBit( uiIsLastCtuOfSliceSegment );
[313]195  }
196  else
197  {
[1029]198    uiIsLastCtuOfSliceSegment=0;
[313]199  }
200
[1029]201  return uiIsLastCtuOfSliceSegment>0;
[313]202}
203
204/** decode CU block recursively
205 * \param pcCU
[1029]206 * \param uiAbsPartIdx
207 * \param uiDepth
[313]208 * \returns Void
209 */
210
[1029]211Void TDecCu::xDecodeCU( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, Bool &isLastCtuOfSliceSegment)
[313]212{
213  TComPic* pcPic = pcCU->getPic();
[1029]214  UInt uiCurNumParts    = pcPic->getNumPartitionsInCtu() >> (uiDepth<<1);
[313]215  UInt uiQNumParts      = uiCurNumParts>>2;
[1029]216
[313]217  Bool bBoundary = false;
218  UInt uiLPelX   = pcCU->getCUPelX() + g_auiRasterToPelX[ g_auiZscanToRaster[uiAbsPartIdx] ];
219  UInt uiRPelX   = uiLPelX + (g_uiMaxCUWidth>>uiDepth)  - 1;
220  UInt uiTPelY   = pcCU->getCUPelY() + g_auiRasterToPelY[ g_auiZscanToRaster[uiAbsPartIdx] ];
221  UInt uiBPelY   = uiTPelY + (g_uiMaxCUHeight>>uiDepth) - 1;
[1029]222
[313]223  TComSlice * pcSlice = pcCU->getPic()->getSlice(pcCU->getPic()->getCurrSliceIdx());
[442]224#if REPN_FORMAT_IN_VPS
[1029]225  if( ( uiRPelX < pcSlice->getPicWidthInLumaSamples() ) && ( uiBPelY < pcSlice->getPicHeightInLumaSamples() ) )
[442]226#else
[1029]227  if( ( uiRPelX < pcSlice->getSPS()->getPicWidthInLumaSamples() ) && ( uiBPelY < pcSlice->getSPS()->getPicHeightInLumaSamples() ) )
[442]228#endif
[313]229  {
230    m_pcEntropyDecoder->decodeSplitFlag( pcCU, uiAbsPartIdx, uiDepth );
231  }
232  else
233  {
234    bBoundary = true;
235  }
[1029]236
[313]237  if( ( ( uiDepth < pcCU->getDepth( uiAbsPartIdx ) ) && ( uiDepth < g_uiMaxCUDepth - g_uiAddCUDepth ) ) || bBoundary )
238  {
239    UInt uiIdx = uiAbsPartIdx;
240    if( (g_uiMaxCUWidth>>uiDepth) == pcCU->getSlice()->getPPS()->getMinCuDQPSize() && pcCU->getSlice()->getPPS()->getUseDQP())
241    {
242      setdQPFlag(true);
243      pcCU->setQPSubParts( pcCU->getRefQP(uiAbsPartIdx), uiAbsPartIdx, uiDepth ); // set QP to default QP
244    }
245
[1029]246    if( (g_uiMaxCUWidth>>uiDepth) == pcCU->getSlice()->getPPS()->getMinCuChromaQpAdjSize() && pcCU->getSlice()->getUseChromaQpAdj() )
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
[442]256#if REPN_FORMAT_IN_VPS
[1029]257      if ( !isLastCtuOfSliceSegment && ( uiLPelX < pcCU->getSlice()->getPicWidthInLumaSamples() ) && ( uiTPelY < pcCU->getSlice()->getPicHeightInLumaSamples() ) )
[442]258#else
[1029]259      if ( !isLastCtuOfSliceSegment && ( uiLPelX < pcCU->getSlice()->getSPS()->getPicWidthInLumaSamples() ) && ( uiTPelY < pcCU->getSlice()->getSPS()->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    }
271    if( (g_uiMaxCUWidth>>uiDepth) == pcCU->getSlice()->getPPS()->getMinCuDQPSize() && pcCU->getSlice()->getPPS()->getUseDQP())
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
[313]282  if( (g_uiMaxCUWidth>>uiDepth) >= pcCU->getSlice()->getPPS()->getMinCuDQPSize() && pcCU->getSlice()->getPPS()->getUseDQP())
283  {
284    setdQPFlag(true);
285    pcCU->setQPSubParts( pcCU->getRefQP(uiAbsPartIdx), uiAbsPartIdx, uiDepth ); // set QP to default QP
286  }
287
[1029]288  if( (g_uiMaxCUWidth>>uiDepth) >= pcCU->getSlice()->getPPS()->getMinCuChromaQpAdjSize() && pcCU->getSlice()->getUseChromaQpAdj() )
289  {
290    setIsChromaQpAdjCoded(true);
291  }
292
[313]293  if (pcCU->getSlice()->getPPS()->getTransquantBypassEnableFlag())
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();
399
[313]400  Bool bBoundary = false;
[1029]401  UInt uiLPelX   = pCtu->getCUPelX() + g_auiRasterToPelX[ g_auiZscanToRaster[uiAbsPartIdx] ];
[313]402  UInt uiRPelX   = uiLPelX + (g_uiMaxCUWidth>>uiDepth)  - 1;
[1029]403  UInt uiTPelY   = pCtu->getCUPelY() + g_auiRasterToPelY[ g_auiZscanToRaster[uiAbsPartIdx] ];
[313]404  UInt uiBPelY   = uiTPelY + (g_uiMaxCUHeight>>uiDepth) - 1;
[1029]405
406  TComSlice * pcSlice = pCtu->getPic()->getSlice(pCtu->getPic()->getCurrSliceIdx());
407
[442]408#if REPN_FORMAT_IN_VPS
[1029]409  if( ( uiRPelX >= pcSlice->getPicWidthInLumaSamples() ) || ( uiBPelY >= pcSlice->getPicHeightInLumaSamples() ) )
410
[442]411#else
[1029]412  if( ( uiRPelX >= pcSlice->getSPS()->getPicWidthInLumaSamples() ) || ( uiBPelY >= pcSlice->getSPS()->getPicHeightInLumaSamples() ) )
[442]413#endif
[313]414  {
415    bBoundary = true;
416  }
[1029]417
418  if( ( ( uiDepth < pCtu->getDepth( uiAbsPartIdx ) ) && ( uiDepth < g_uiMaxCUDepth - g_uiAddCUDepth ) ) || bBoundary )
[313]419  {
420    UInt uiNextDepth = uiDepth + 1;
[1029]421    UInt uiQNumParts = pCtu->getTotalNumPart() >> (uiNextDepth<<1);
[313]422    UInt uiIdx = uiAbsPartIdx;
423    for ( UInt uiPartIdx = 0; uiPartIdx < 4; uiPartIdx++ )
424    {
[1029]425      uiLPelX = pCtu->getCUPelX() + g_auiRasterToPelX[ g_auiZscanToRaster[uiIdx] ];
426      uiTPelY = pCtu->getCUPelY() + g_auiRasterToPelY[ g_auiZscanToRaster[uiIdx] ];
427
[442]428#if REPN_FORMAT_IN_VPS
[1029]429      if( ( uiLPelX < pcSlice->getPicWidthInLumaSamples() ) && ( uiTPelY < pcSlice->getPicHeightInLumaSamples() ) )
[442]430#else
[1029]431      if( ( uiLPelX < pcSlice->getSPS()->getPicWidthInLumaSamples() ) && ( uiTPelY < pcSlice->getSPS()->getPicHeightInLumaSamples() ) )
[442]432#endif
[313]433      {
[1029]434        xDecompressCU(pCtu, uiIdx, uiNextDepth );
[313]435      }
[1029]436
[313]437      uiIdx += uiQNumParts;
438    }
439    return;
440  }
[1029]441
[313]442  // Residual reconstruction
443  m_ppcYuvResi[uiDepth]->clear();
[1029]444
445  m_ppcCU[uiDepth]->copySubCU( pCtu, uiAbsPartIdx, uiDepth );
446
[313]447  switch( m_ppcCU[uiDepth]->getPredictionMode(0) )
448  {
449    case MODE_INTER:
450      xReconInter( m_ppcCU[uiDepth], uiDepth );
451      break;
452    case MODE_INTRA:
453      xReconIntraQT( m_ppcCU[uiDepth], uiDepth );
454      break;
455    default:
456      assert(0);
457      break;
458  }
[1029]459
460#ifdef DEBUG_STRING
461  const PredMode predMode=m_ppcCU[uiDepth]->getPredictionMode(0);
462  if (DebugOptionList::DebugString_Structure.getInt()&DebugStringGetPredModeMask(predMode))
463  {
464    PartSize eSize=m_ppcCU[uiDepth]->getPartitionSize(0);
465    std::ostream &ss(std::cout);
466
467    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;
468  }
469#endif
470
[313]471  if ( m_ppcCU[uiDepth]->isLosslessCoded(0) && (m_ppcCU[uiDepth]->getIPCMFlag(0) == false))
472  {
473    xFillPCMBuffer(m_ppcCU[uiDepth], uiDepth);
474  }
[1029]475
[313]476  xCopyToPic( m_ppcCU[uiDepth], pcPic, uiAbsPartIdx, uiDepth );
477}
478
479Void TDecCu::xReconInter( TComDataCU* pcCU, UInt uiDepth )
480{
[1029]481
[313]482  // inter prediction
483  m_pcPrediction->motionCompensation( pcCU, m_ppcYuvReco[uiDepth] );
[1029]484
485#ifdef DEBUG_STRING
486  const Int debugPredModeMask=DebugStringGetPredModeMask(MODE_INTER);
487  if (DebugOptionList::DebugString_Pred.getInt()&debugPredModeMask) printBlockToStream(std::cout, "###inter-pred: ", *(m_ppcYuvReco[uiDepth]));
488#endif
489
[313]490  // inter recon
[1029]491  xDecodeInterTexture( pcCU, uiDepth );
492
493#ifdef DEBUG_STRING
494  if (DebugOptionList::DebugString_Resi.getInt()&debugPredModeMask) printBlockToStream(std::cout, "###inter-resi: ", *(m_ppcYuvResi[uiDepth]));
495#endif
496
[313]497  // clip for only non-zero cbp case
[1029]498  if  ( pcCU->getQtRootCbf( 0) )
[313]499  {
500    m_ppcYuvReco[uiDepth]->addClip( m_ppcYuvReco[uiDepth], m_ppcYuvResi[uiDepth], 0, pcCU->getWidth( 0 ) );
501  }
502  else
503  {
504    m_ppcYuvReco[uiDepth]->copyPartToPartYuv( m_ppcYuvReco[uiDepth],0, pcCU->getWidth( 0 ),pcCU->getHeight( 0 ));
505  }
[1029]506#ifdef DEBUG_STRING
507  if (DebugOptionList::DebugString_Reco.getInt()&debugPredModeMask) printBlockToStream(std::cout, "###inter-reco: ", *(m_ppcYuvReco[uiDepth]));
508#endif
509
[313]510}
511
[1029]512
[313]513Void
[1029]514TDecCu::xIntraRecBlk(       TComYuv*    pcRecoYuv,
515                            TComYuv*    pcPredYuv,
516                            TComYuv*    pcResiYuv,
517                      const ComponentID compID,
518                            TComTU     &rTu)
[313]519{
[1029]520  if (!rTu.ProcessComponentSection(compID)) return;
521  const Bool       bIsLuma = isLuma(compID);
[313]522
523
[1029]524  TComDataCU *pcCU = rTu.getCU();
525  const UInt uiAbsPartIdx=rTu.GetAbsPartIdxTU();
526
527  const TComRectangle &tuRect  =rTu.getRect(compID);
528  const UInt uiWidth           = tuRect.width;
529  const UInt uiHeight          = tuRect.height;
530  const UInt uiStride          = pcRecoYuv->getStride (compID);
531        Pel* piPred            = pcPredYuv->getAddr( compID, uiAbsPartIdx );
532  const ChromaFormat chFmt     = rTu.GetChromaFormat();
533
534  if (uiWidth != uiHeight)
[313]535  {
[1029]536    //------------------------------------------------
[313]537
[1029]538    //split at current level if dividing into square sub-TUs
[313]539
[1029]540    TComTURecurse subTURecurse(rTu, false, TComTU::VERTICAL_SPLIT, true, compID);
[313]541
[1029]542    //recurse further
543    do
[313]544    {
[1029]545      xIntraRecBlk(pcRecoYuv, pcPredYuv, pcResiYuv, compID, subTURecurse);
[313]546    }
[1029]547    while (subTURecurse.nextSection(rTu));
548
549    //------------------------------------------------
550
551    return;
[313]552  }
[1029]553
554  const UInt uiChPredMode  = pcCU->getIntraDir( toChannelType(compID), uiAbsPartIdx );
555  const UInt uiChCodedMode = (uiChPredMode==DM_CHROMA_IDX && !bIsLuma) ? pcCU->getIntraDir(CHANNEL_TYPE_LUMA, getChromasCorrespondingPULumaIdx(uiAbsPartIdx, chFmt)) : uiChPredMode;
556  const UInt uiChFinalMode = ((chFmt == CHROMA_422)       && !bIsLuma) ? g_chroma422IntraAngleMappingTable[uiChCodedMode] : uiChCodedMode;
557
[313]558  //===== init availability pattern =====
559  Bool  bAboveAvail = false;
560  Bool  bLeftAvail  = false;
561
[1029]562  const Bool bUseFilteredPredictions=TComPrediction::filteringIntraReferenceSamples(compID, uiChFinalMode, uiWidth, uiHeight, chFmt, pcCU->getSlice()->getSPS()->getDisableIntraReferenceSmoothing());
563
564#ifdef DEBUG_STRING
565  std::ostream &ss(std::cout);
566#endif
567
568  DEBUG_STRING_NEW(sTemp)
569  m_pcPrediction->initAdiPatternChType( rTu, bAboveAvail, bLeftAvail, compID, bUseFilteredPredictions  DEBUG_STRING_PASS_INTO(sTemp) );
570
571
[313]572  //===== get prediction signal =====
573
[1029]574  m_pcPrediction->predIntraAng( compID,   uiChFinalMode, 0 /* Decoder does not have an original image */, 0, piPred, uiStride, rTu, bAboveAvail, bLeftAvail, bUseFilteredPredictions );
575
576#ifdef DEBUG_STRING
577  ss << sTemp;
578#endif
579
[313]580  //===== inverse transform =====
[1029]581  Pel*      piResi            = pcResiYuv->getAddr( compID, uiAbsPartIdx );
582  TCoeff*   pcCoeff           = pcCU->getCoeff(compID) + rTu.getCoefficientOffset(compID);//( uiNumCoeffInc * uiAbsPartIdx );
583
584  const QpParam cQP(*pcCU, compID);
585
586
587  DEBUG_STRING_NEW(sDebug);
588#ifdef DEBUG_STRING
589  const Int debugPredModeMask=DebugStringGetPredModeMask(MODE_INTRA);
590  std::string *psDebug=(DebugOptionList::DebugString_InvTran.getInt()&debugPredModeMask) ? &sDebug : 0;
591#endif
592
593  if (pcCU->getCbf(uiAbsPartIdx, compID, rTu.GetTransformDepthRel()) != 0)
[313]594  {
[1029]595    m_pcTrQuant->invTransformNxN( rTu, compID, piResi, uiStride, pcCoeff, cQP DEBUG_STRING_PASS_INTO(psDebug) );
[313]596  }
597  else
598  {
[1029]599    for (UInt y = 0; y < uiHeight; y++)
600      for (UInt x = 0; x < uiWidth; x++)
601      {
602        piResi[(y * uiStride) + x] = 0;
603      }
[313]604  }
[1029]605
606#ifdef DEBUG_STRING
607  if (psDebug)
608    ss << (*psDebug);
[494]609#endif
[1029]610
611  //===== reconstruction =====
612  const UInt uiRecIPredStride  = pcCU->getPic()->getPicYuvRec()->getStride(compID);
613
614  const Bool useCrossComponentPrediction = isChroma(compID) && (pcCU->getCrossComponentPredictionAlpha(uiAbsPartIdx, compID) != 0);
615  const Pel* pResiLuma  = pcResiYuv->getAddr( COMPONENT_Y, uiAbsPartIdx );
616  const Int  strideLuma = pcResiYuv->getStride( COMPONENT_Y );
617
618        Pel* pPred      = piPred;
619        Pel* pResi      = piResi;
620        Pel* pReco      = pcRecoYuv->getAddr( compID, uiAbsPartIdx );
621        Pel* pRecIPred  = pcCU->getPic()->getPicYuvRec()->getAddr( compID, pcCU->getCtuRsAddr(), pcCU->getZorderIdxInCtu() + uiAbsPartIdx );
622
623
624#ifdef DEBUG_STRING
625  const Bool bDebugPred=((DebugOptionList::DebugString_Pred.getInt()&debugPredModeMask) && DEBUG_STRING_CHANNEL_CONDITION(compID));
626  const Bool bDebugResi=((DebugOptionList::DebugString_Resi.getInt()&debugPredModeMask) && DEBUG_STRING_CHANNEL_CONDITION(compID));
627  const Bool bDebugReco=((DebugOptionList::DebugString_Reco.getInt()&debugPredModeMask) && DEBUG_STRING_CHANNEL_CONDITION(compID));
628  if (bDebugPred || bDebugResi || bDebugReco)
629    ss << "###: " << "CompID: " << compID << " pred mode (ch/fin): " << uiChPredMode << "/" << uiChFinalMode << " absPartIdx: " << rTu.GetAbsPartIdxTU() << std::endl;
[494]630#endif
[313]631
[1029]632#if O0043_BEST_EFFORT_DECODING
633  const Int bitDepthDelta = g_bitDepthInStream[toChannelType(compID)] - g_bitDepth[toChannelType(compID)];
634#endif
635  const Int clipbd = g_bitDepth[toChannelType(compID)];
[313]636
[1029]637  if( useCrossComponentPrediction )
638  {
639    TComTrQuant::crossComponentPrediction( rTu, compID, pResiLuma, piResi, piResi, uiWidth, uiHeight, strideLuma, uiStride, uiStride, true );
640  }
641
[313]642  for( UInt uiY = 0; uiY < uiHeight; uiY++ )
643  {
[1029]644#ifdef DEBUG_STRING
645    if (bDebugPred || bDebugResi || bDebugReco) ss << "###: ";
646
647    if (bDebugPred)
648    {
649      ss << " - pred: ";
650      for( UInt uiX = 0; uiX < uiWidth; uiX++ )
651      {
652        ss << pPred[ uiX ] << ", ";
653      }
654    }
655    if (bDebugResi) ss << " - resi: ";
656#endif
657
[313]658    for( UInt uiX = 0; uiX < uiWidth; uiX++ )
659    {
[1029]660#ifdef DEBUG_STRING
661      if (bDebugResi)
662        ss << pResi[ uiX ] << ", ";
663#endif
664#if O0043_BEST_EFFORT_DECODING
665      pReco    [ uiX ] = ClipBD( rightShiftEvenRounding<Pel>(pPred[ uiX ] + pResi[ uiX ], bitDepthDelta), clipbd );
666#else
667      pReco    [ uiX ] = ClipBD( pPred[ uiX ] + pResi[ uiX ], clipbd );
668#endif
[313]669      pRecIPred[ uiX ] = pReco[ uiX ];
670    }
[1029]671#ifdef DEBUG_STRING
672    if (bDebugReco)
673    {
674      ss << " - reco: ";
675      for( UInt uiX = 0; uiX < uiWidth; uiX++ )
676      {
677        ss << pReco[ uiX ] << ", ";
678      }
679    }
680
681    if (bDebugPred || bDebugResi || bDebugReco)
682      ss << "\n";
683#endif
[313]684    pPred     += uiStride;
685    pResi     += uiStride;
686    pReco     += uiStride;
687    pRecIPred += uiRecIPredStride;
688  }
689}
690
691
692Void
693TDecCu::xReconIntraQT( TComDataCU* pcCU, UInt uiDepth )
694{
695  if (pcCU->getIPCMFlag(0))
696  {
697    xReconPCM( pcCU, uiDepth );
698    return;
699  }
[1029]700  const UInt numChType = pcCU->getPic()->getChromaFormat()!=CHROMA_400 ? 2 : 1;
701  for (UInt chType=CHANNEL_TYPE_LUMA; chType<numChType; chType++)
[313]702  {
[1029]703    const ChannelType chanType=ChannelType(chType);
704    const Bool NxNPUHas4Parts = ::isChroma(chanType) ? enable4ChromaPUsInIntraNxNCU(pcCU->getPic()->getChromaFormat()) : true;
705    const UInt uiInitTrDepth = ( pcCU->getPartitionSize(0) != SIZE_2Nx2N && NxNPUHas4Parts ? 1 : 0 );
[313]706
[1029]707    TComTURecurse tuRecurseCU(pcCU, 0);
708    TComTURecurse tuRecurseWithPU(tuRecurseCU, false, (uiInitTrDepth==0)?TComTU::DONT_SPLIT : TComTU::QUAD_SPLIT);
[313]709
[1029]710    do
[313]711    {
[1029]712      xIntraRecQT( m_ppcYuvReco[uiDepth], m_ppcYuvReco[uiDepth], m_ppcYuvResi[uiDepth], chanType, tuRecurseWithPU );
713    } while (tuRecurseWithPU.nextSection(tuRecurseCU));
[313]714  }
715}
716
[1029]717
718
[313]719/** Function for deriving recontructed PU/CU chroma samples with QTree structure
720 * \param pcCU pointer of current CU
721 * \param uiTrDepth current tranform split depth
722 * \param uiAbsPartIdx  part index
723 * \param pcRecoYuv pointer to reconstructed sample arrays
724 * \param pcPredYuv pointer to prediction sample arrays
725 * \param pcResiYuv pointer to residue sample arrays
[1029]726 *
[313]727 \ This function dervies recontructed PU/CU chroma samples with QTree recursive structure
728 */
[1029]729
[313]730Void
[1029]731TDecCu::xIntraRecQT(TComYuv*    pcRecoYuv,
732                    TComYuv*    pcPredYuv,
733                    TComYuv*    pcResiYuv,
734                    const ChannelType chType,
735                    TComTU     &rTu)
[313]736{
[1029]737  UInt uiTrDepth    = rTu.GetTransformDepthRel();
738  TComDataCU *pcCU  = rTu.getCU();
739  UInt uiAbsPartIdx = rTu.GetAbsPartIdxTU();
[313]740  UInt uiTrMode     = pcCU->getTransformIdx( uiAbsPartIdx );
741  if( uiTrMode == uiTrDepth )
742  {
[1029]743    if (isLuma(chType))
744      xIntraRecBlk( pcRecoYuv, pcPredYuv, pcResiYuv, COMPONENT_Y,  rTu );
745    else
746    {
747      const UInt numValidComp=getNumberValidComponents(rTu.GetChromaFormat());
748      for(UInt compID=COMPONENT_Cb; compID<numValidComp; compID++)
749      {
750        xIntraRecBlk( pcRecoYuv, pcPredYuv, pcResiYuv, ComponentID(compID), rTu );
751      }
752    }
[313]753  }
754  else
755  {
[1029]756    TComTURecurse tuRecurseChild(rTu, false);
757    do
[313]758    {
[1029]759      xIntraRecQT( pcRecoYuv, pcPredYuv, pcResiYuv, chType, tuRecurseChild );
760    } while (tuRecurseChild.nextSection(rTu));
[313]761  }
762}
763
764Void TDecCu::xCopyToPic( TComDataCU* pcCU, TComPic* pcPic, UInt uiZorderIdx, UInt uiDepth )
765{
[1029]766  UInt uiCtuRsAddr = pcCU->getCtuRsAddr();
767
768  m_ppcYuvReco[uiDepth]->copyToPicYuv  ( pcPic->getPicYuvRec (), uiCtuRsAddr, uiZorderIdx );
769
[313]770  return;
771}
772
[1029]773Void TDecCu::xDecodeInterTexture ( TComDataCU* pcCU, UInt uiDepth )
[313]774{
775
[1029]776  TComTURecurse tuRecur(pcCU, 0, uiDepth);
[313]777
[1029]778  for(UInt ch=0; ch<pcCU->getPic()->getNumberValidComponents(); ch++)
779  {
780    const ComponentID compID=ComponentID(ch);
781    DEBUG_STRING_OUTPUT(std::cout, debug_reorder_data_inter_token[compID])
[313]782
[1029]783    m_pcTrQuant->invRecurTransformNxN ( compID, m_ppcYuvResi[uiDepth], tuRecur );
784  }
[313]785
[1029]786  DEBUG_STRING_OUTPUT(std::cout, debug_reorder_data_inter_token[MAX_NUM_COMPONENT])
[313]787}
788
789/** Function for deriving reconstructed luma/chroma samples of a PCM mode CU.
790 * \param pcCU pointer to current CU
791 * \param uiPartIdx part index
792 * \param piPCM pointer to PCM code arrays
793 * \param piReco pointer to reconstructed sample arrays
794 * \param uiStride stride of reconstructed sample arrays
795 * \param uiWidth CU width
796 * \param uiHeight CU height
797 * \param ttText texture component type
798 * \returns Void
799 */
[1029]800Void 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]801{
[1029]802        Pel* piPicReco         = pcCU->getPic()->getPicYuvRec()->getAddr(compID, pcCU->getCtuRsAddr(), pcCU->getZorderIdxInCtu()+uiPartIdx);
803  const UInt uiPicStride       = pcCU->getPic()->getPicYuvRec()->getStride(compID);
804  const UInt uiPcmLeftShiftBit = g_bitDepth[toChannelType(compID)] - pcCU->getSlice()->getSPS()->getPCMBitDepth(toChannelType(compID));
[313]805
[1029]806  for(UInt uiY = 0; uiY < uiHeight; uiY++ )
[313]807  {
[1029]808    for(UInt uiX = 0; uiX < uiWidth; uiX++ )
[313]809    {
810      piReco[uiX] = (piPCM[uiX] << uiPcmLeftShiftBit);
811      piPicReco[uiX] = piReco[uiX];
812    }
813    piPCM += uiWidth;
814    piReco += uiStride;
815    piPicReco += uiPicStride;
816  }
817}
818
819/** Function for reconstructing a PCM mode CU.
820 * \param pcCU pointer to current CU
821 * \param uiDepth CU Depth
822 * \returns Void
823 */
824Void TDecCu::xReconPCM( TComDataCU* pcCU, UInt uiDepth )
825{
[1029]826  for (UInt ch=0; ch < pcCU->getPic()->getNumberValidComponents(); ch++)
827  {
828    const ComponentID compID = ComponentID(ch);
829    const UInt width  = (g_uiMaxCUWidth >>(uiDepth+m_ppcYuvResi[uiDepth]->getComponentScaleX(compID)));
830    const UInt height = (g_uiMaxCUHeight>>(uiDepth+m_ppcYuvResi[uiDepth]->getComponentScaleY(compID)));
831    const UInt stride = m_ppcYuvResi[uiDepth]->getStride(compID);
832    Pel * pPCMChannel = pcCU->getPCMSample(compID);
833    Pel * pRecChannel = m_ppcYuvReco[uiDepth]->getAddr(compID);
834    xDecodePCMTexture( pcCU, 0, pPCMChannel, pRecChannel, stride, width, height, compID );
835  }
[313]836}
837
[1029]838/** Function for filling the PCM buffer of a CU using its reconstructed sample array
[313]839 * \param pcCU pointer to current CU
840 * \param uiDepth CU Depth
841 * \returns Void
842 */
843Void TDecCu::xFillPCMBuffer(TComDataCU* pCU, UInt depth)
844{
[1029]845  const ChromaFormat format = pCU->getPic()->getChromaFormat();
846  const UInt numValidComp=getNumberValidComponents(format);
[313]847
[1029]848  for (UInt componentIndex = 0; componentIndex < numValidComp; componentIndex++)
[313]849  {
[1029]850    const ComponentID component = ComponentID(componentIndex);
[313]851
[1029]852    const UInt width  = g_uiMaxCUWidth  >> (depth + getComponentScaleX(component, format));
853    const UInt height = g_uiMaxCUHeight >> (depth + getComponentScaleY(component, format));
[313]854
[1029]855    Pel *source      = m_ppcYuvReco[depth]->getAddr(component, 0, width);
856    Pel *destination = pCU->getPCMSample(component);
[313]857
[1029]858    const UInt sourceStride = m_ppcYuvReco[depth]->getStride(component);
[313]859
[1029]860    for (Int line = 0; line < height; line++)
[313]861    {
[1029]862      for (Int column = 0; column < width; column++)
863      {
864        destination[column] = source[column];
865      }
866
867      source      += sourceStride;
868      destination += width;
[313]869    }
870  }
871}
[540]872
[313]873//! \}
Note: See TracBrowser for help on using the repository browser.