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

Last change on this file since 1502 was 1502, checked in by seregin, 8 years ago

infer parameters in SPS after activation, fixing chroma scaling for non 4:2:0

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