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

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

Removed 3D.

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