source: 3DVCSoftware/branches/HTM-14.1-update-dev1-RWTH/source/Lib/TLibDecoder/TDecCu.cpp @ 1227

Last change on this file since 1227 was 1227, checked in by hhi, 9 years ago
  • SDC with DMM seems to work now (incompatible with DLT -> high level syntax problem?).
  • Renamed macros for intra and inter SDC.
  • Property svn:eol-style set to native
File size: 57.7 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#if H_3D_DBBP
55  m_ppcYuvRecoDBBP = NULL;
56#endif
57}
58
59TDecCu::~TDecCu()
60{
61}
62
63Void TDecCu::init( TDecEntropy* pcEntropyDecoder, TComTrQuant* pcTrQuant, TComPrediction* pcPrediction)
64{
65  m_pcEntropyDecoder  = pcEntropyDecoder;
66  m_pcTrQuant         = pcTrQuant;
67  m_pcPrediction      = pcPrediction;
68}
69
70/**
71 \param    uiMaxDepth      total number of allowable depth
72 \param    uiMaxWidth      largest CU width
73 \param    uiMaxHeight     largest CU height
74 \param    chromaFormatIDC chroma format
75 */
76Void TDecCu::create( UInt uiMaxDepth, UInt uiMaxWidth, UInt uiMaxHeight, ChromaFormat chromaFormatIDC )
77{
78  m_uiMaxDepth = uiMaxDepth+1;
79
80  m_ppcYuvResi = new TComYuv*[m_uiMaxDepth-1];
81  m_ppcYuvReco = new TComYuv*[m_uiMaxDepth-1];
82  m_ppcCU      = new TComDataCU*[m_uiMaxDepth-1];
83#if H_3D_DBBP
84  m_ppcYuvRecoDBBP = new TComYuv*[m_uiMaxDepth-1];
85#endif
86
87  UInt uiNumPartitions;
88  for ( UInt ui = 0; ui < m_uiMaxDepth-1; ui++ )
89  {
90    uiNumPartitions = 1<<( ( m_uiMaxDepth - ui - 1 )<<1 );
91    UInt uiWidth  = uiMaxWidth  >> ui;
92    UInt uiHeight = uiMaxHeight >> ui;
93
94    m_ppcYuvResi[ui] = new TComYuv;    m_ppcYuvResi[ui]->create( uiWidth, uiHeight, chromaFormatIDC );
95    m_ppcYuvReco[ui] = new TComYuv;    m_ppcYuvReco[ui]->create( uiWidth, uiHeight, chromaFormatIDC );
96    m_ppcCU     [ui] = new TComDataCU; m_ppcCU     [ui]->create( chromaFormatIDC, uiNumPartitions, uiWidth, uiHeight, true, uiMaxWidth >> (m_uiMaxDepth - 1) );
97#if H_3D_DBBP
98    m_ppcYuvRecoDBBP[ui] = new TComYuv;    m_ppcYuvRecoDBBP[ui]->create( uiWidth, uiHeight );
99#endif
100}
101
102  m_bDecodeDQP = false;
103  m_IsChromaQpAdjCoded = false;
104
105  // initialize partition order.
106  UInt* piTmp = &g_auiZscanToRaster[0];
107  initZscanToRaster(m_uiMaxDepth, 1, 0, piTmp);
108  initRasterToZscan( uiMaxWidth, uiMaxHeight, m_uiMaxDepth );
109
110  // initialize conversion matrix from partition index to pel
111  initRasterToPelXY( uiMaxWidth, uiMaxHeight, m_uiMaxDepth );
112}
113
114Void TDecCu::destroy()
115{
116  for ( UInt ui = 0; ui < m_uiMaxDepth-1; ui++ )
117  {
118    m_ppcYuvResi[ui]->destroy(); delete m_ppcYuvResi[ui]; m_ppcYuvResi[ui] = NULL;
119    m_ppcYuvReco[ui]->destroy(); delete m_ppcYuvReco[ui]; m_ppcYuvReco[ui] = NULL;
120    m_ppcCU     [ui]->destroy(); delete m_ppcCU     [ui]; m_ppcCU     [ui] = NULL;
121#if H_3D_DBBP
122    m_ppcYuvRecoDBBP[ui]->destroy(); delete m_ppcYuvRecoDBBP[ui]; m_ppcYuvRecoDBBP[ui] = NULL;
123#endif
124  }
125
126  delete [] m_ppcYuvResi; m_ppcYuvResi = NULL;
127  delete [] m_ppcYuvReco; m_ppcYuvReco = NULL;
128  delete [] m_ppcCU     ; m_ppcCU      = NULL;
129#if H_3D_DBBP
130  delete [] m_ppcYuvRecoDBBP; m_ppcYuvRecoDBBP = NULL;
131#endif
132}
133
134// ====================================================================================================================
135// Public member functions
136// ====================================================================================================================
137
138/**
139 Parse a CTU.
140 \param    pCtu                      [in/out] pointer to CTU data structure
141 \param    isLastCtuOfSliceSegment   [out]    true, if last CTU of the slice segment
142 */
143Void TDecCu::decodeCtu( TComDataCU* pCtu, Bool& isLastCtuOfSliceSegment )
144{
145  if ( pCtu->getSlice()->getPPS()->getUseDQP() )
146  {
147    setdQPFlag(true);
148  }
149
150  if ( pCtu->getSlice()->getUseChromaQpAdj() )
151  {
152    setIsChromaQpAdjCoded(true);
153  }
154
155  // start from the top level CU
156  xDecodeCU( pCtu, 0, 0, isLastCtuOfSliceSegment);
157}
158
159/**
160 Decoding process for a CTU.
161 \param    pCtu                      [in/out] pointer to CTU data structure
162 */
163Void TDecCu::decompressCtu( TComDataCU* pCtu )
164{
165#if !H_3D_IV_MERGE
166  xDecompressCU( pCtu, 0,  0 );
167#endif
168}
169
170// ====================================================================================================================
171// Protected member functions
172// ====================================================================================================================
173
174//! decode end-of-slice flag
175Bool TDecCu::xDecodeSliceEnd( TComDataCU* pcCU, UInt uiAbsPartIdx )
176{
177  UInt uiIsLastCtuOfSliceSegment;
178
179  if (pcCU->isLastSubCUOfCtu(uiAbsPartIdx))
180  {
181    m_pcEntropyDecoder->decodeTerminatingBit( uiIsLastCtuOfSliceSegment );
182  }
183  else
184  {
185    uiIsLastCtuOfSliceSegment=0;
186  }
187
188  return uiIsLastCtuOfSliceSegment>0;
189}
190
191//! decode CU block recursively
192Void TDecCu::xDecodeCU( TComDataCU*const pcCU, const UInt uiAbsPartIdx, const UInt uiDepth, Bool &isLastCtuOfSliceSegment)
193{
194  TComPic* pcPic        = pcCU->getPic();
195  const TComSPS &sps    = pcPic->getPicSym()->getSPS();
196  const TComPPS &pps    = pcPic->getPicSym()->getPPS();
197  const UInt maxCuWidth = sps.getMaxCUWidth();
198  const UInt maxCuHeight= sps.getMaxCUHeight();
199  UInt uiCurNumParts    = pcPic->getNumPartitionsInCtu() >> (uiDepth<<1);
200  UInt uiQNumParts      = uiCurNumParts>>2;
201
202
203  Bool bBoundary = false;
204  UInt uiLPelX   = pcCU->getCUPelX() + g_auiRasterToPelX[ g_auiZscanToRaster[uiAbsPartIdx] ];
205  UInt uiRPelX   = uiLPelX + (maxCuWidth>>uiDepth)  - 1;
206  UInt uiTPelY   = pcCU->getCUPelY() + g_auiRasterToPelY[ g_auiZscanToRaster[uiAbsPartIdx] ];
207  UInt uiBPelY   = uiTPelY + (maxCuHeight>>uiDepth) - 1;
208#if H_MV_ENC_DEC_TRAC
209  DTRACE_CU_S("=========== coding_quadtree ===========\n")
210  DTRACE_CU("x0", uiLPelX)
211  DTRACE_CU("x1", uiTPelY)
212  DTRACE_CU("log2CbSize", maxCuWidth>>uiDepth)
213  DTRACE_CU("cqtDepth"  , uiDepth)
214#endif
215
216  if( ( uiRPelX < sps.getPicWidthInLumaSamples() ) && ( uiBPelY < sps.getPicHeightInLumaSamples() ) )
217  {
218    m_pcEntropyDecoder->decodeSplitFlag( pcCU, uiAbsPartIdx, uiDepth );
219  }
220  else
221  {
222    bBoundary = true;
223  }
224  if( ( ( uiDepth < pcCU->getDepth( uiAbsPartIdx ) ) && ( uiDepth < sps.getLog2DiffMaxMinCodingBlockSize() ) ) || bBoundary )
225  {
226    UInt uiIdx = uiAbsPartIdx;
227    if( uiDepth == pps.getMaxCuDQPDepth() && pps.getUseDQP())
228    {
229      setdQPFlag(true);
230      pcCU->setQPSubParts( pcCU->getRefQP(uiAbsPartIdx), uiAbsPartIdx, uiDepth ); // set QP to default QP
231    }
232
233    if( uiDepth == pps.getPpsRangeExtension().getDiffCuChromaQpOffsetDepth() && pcCU->getSlice()->getUseChromaQpAdj() )
234    {
235      setIsChromaQpAdjCoded(true);
236    }
237
238    for ( UInt uiPartUnitIdx = 0; uiPartUnitIdx < 4; uiPartUnitIdx++ )
239    {
240      uiLPelX   = pcCU->getCUPelX() + g_auiRasterToPelX[ g_auiZscanToRaster[uiIdx] ];
241      uiTPelY   = pcCU->getCUPelY() + g_auiRasterToPelY[ g_auiZscanToRaster[uiIdx] ];
242
243      if ( !isLastCtuOfSliceSegment && ( uiLPelX < sps.getPicWidthInLumaSamples() ) && ( uiTPelY < sps.getPicHeightInLumaSamples() ) )
244      {
245        xDecodeCU( pcCU, uiIdx, uiDepth+1, isLastCtuOfSliceSegment );
246      }
247      else
248      {
249        pcCU->setOutsideCUPart( uiIdx, uiDepth+1 );
250      }
251
252      uiIdx += uiQNumParts;
253    }
254    if( uiDepth == pps.getMaxCuDQPDepth() && pps.getUseDQP())
255    {
256      if ( getdQPFlag() )
257      {
258        UInt uiQPSrcPartIdx = uiAbsPartIdx;
259        pcCU->setQPSubParts( pcCU->getRefQP( uiQPSrcPartIdx ), uiAbsPartIdx, uiDepth ); // set QP to default QP
260      }
261    }
262    return;
263  }
264
265#if H_MV_ENC_DEC_TRAC
266  DTRACE_CU_S("=========== coding_unit ===========\n")
267#if H_MV_ENC_DEC_TRAC
268#if ENC_DEC_TRACE
269    stopAtPos  ( pcCU->getSlice()->getPOC(), 
270    pcCU->getSlice()->getLayerId(), 
271    uiLPelX,
272    uiTPelY,
273    uiRPelX-uiLPelX+1, 
274    uiBPelY-uiTPelY+1);
275#endif
276#endif
277
278#endif
279
280  if( uiDepth <= pps.getMaxCuDQPDepth() && pps.getUseDQP())
281  {
282    setdQPFlag(true);
283    pcCU->setQPSubParts( pcCU->getRefQP(uiAbsPartIdx), uiAbsPartIdx, uiDepth ); // set QP to default QP
284  }
285#if H_3D_NBDV
286  DisInfo DvInfo; 
287  DvInfo.m_acNBDV.setZero();
288  DvInfo.m_aVIdxCan = 0;
289#if H_3D_NBDV_REF 
290  DvInfo.m_acDoNBDV.setZero();
291#endif
292 
293if(!pcCU->getSlice()->isIntra())
294  {
295#if H_3D_ARP && H_3D_IV_MERGE
296    if( pcCU->getSlice()->getIvResPredFlag() || pcCU->getSlice()->getIvMvPredFlag() )
297#else
298#if H_3D_ARP
299    if( pcCU->getSlice()->getVPS()->getUseAdvRP(pcCU->getSlice()->getLayerId()) )
300#else
301#if H_3D_IV_MERGE
302    if( pcCU->getSlice()->getVPS()->getIvMvPredFlag(pcCU->getSlice()->getLayerId()) )
303#else
304    if (0)
305#endif
306#endif
307#endif
308    {
309      m_ppcCU[uiDepth]->copyInterPredInfoFrom( pcCU, uiAbsPartIdx, REF_PIC_LIST_0, true );
310      m_ppcCU[uiDepth]->copyDVInfoFrom( pcCU, uiAbsPartIdx);
311      PartSize ePartTemp = m_ppcCU[uiDepth]->getPartitionSize(0);
312      UChar cWidTemp     = m_ppcCU[uiDepth]->getWidth(0);
313      UChar cHeightTemp  = m_ppcCU[uiDepth]->getHeight(0);
314      m_ppcCU[uiDepth]->setWidth  ( 0, pcCU->getSlice()->getSPS()->getMaxCUWidth ()/(1<<uiDepth)  );
315      m_ppcCU[uiDepth]->setHeight ( 0, pcCU->getSlice()->getSPS()->getMaxCUHeight()/(1<<uiDepth)  );
316      m_ppcCU[uiDepth]->setPartSizeSubParts( SIZE_2Nx2N, 0, uiDepth );     
317#if H_3D_IV_MERGE
318      if( pcCU->getSlice()->getIsDepth())
319      {
320        m_ppcCU[uiDepth]->getDispforDepth(0, 0, &DvInfo);
321      }
322      else
323      {
324#endif
325#if H_3D_NBDV_REF
326      if( pcCU->getSlice()->getDepthBasedBlkPartFlag() )  //Notes from QC: please check the condition for DoNBDV. Remove this comment once it is done.
327      {
328        m_ppcCU[uiDepth]->getDisMvpCandNBDV(&DvInfo, true);
329      }
330      else
331#endif
332      {
333        m_ppcCU[uiDepth]->getDisMvpCandNBDV(&DvInfo);
334      }
335#if H_3D_IV_MERGE
336      }
337#endif
338#if ENC_DEC_TRACE && H_MV_ENC_DEC_TRAC   
339      if ( g_decTraceDispDer )
340      {
341        DTRACE_CU( "RefViewIdx",  DvInfo.m_aVIdxCan );       
342        DTRACE_CU( "MvDisp[x]", DvInfo.m_acNBDV.getHor() );
343        DTRACE_CU( "MvDisp[y]", DvInfo.m_acNBDV.getVer() );
344        DTRACE_CU( "MvRefinedDisp[x]", DvInfo.m_acDoNBDV.getHor() );
345        DTRACE_CU( "MvRefinedDisp[y]", DvInfo.m_acDoNBDV.getVer() );
346      }
347#endif
348
349      pcCU->setDvInfoSubParts(DvInfo, uiAbsPartIdx, uiDepth);
350      m_ppcCU[uiDepth]->setPartSizeSubParts( ePartTemp, 0, uiDepth );
351      m_ppcCU[uiDepth]->setWidth  ( 0, cWidTemp );
352      m_ppcCU[uiDepth]->setHeight ( 0, cHeightTemp );
353     }
354  }
355#endif
356
357  if( uiDepth <= pps.getPpsRangeExtension().getDiffCuChromaQpOffsetDepth() && pcCU->getSlice()->getUseChromaQpAdj() )
358  {
359    setIsChromaQpAdjCoded(true);
360  }
361
362  if (pps.getTransquantBypassEnableFlag())
363  {
364    m_pcEntropyDecoder->decodeCUTransquantBypassFlag( pcCU, uiAbsPartIdx, uiDepth );
365  }
366
367  // decode CU mode and the partition size
368  if( !pcCU->getSlice()->isIntra())
369  {
370    m_pcEntropyDecoder->decodeSkipFlag( pcCU, uiAbsPartIdx, uiDepth );
371  }
372
373
374  if( pcCU->isSkipped(uiAbsPartIdx) )
375  {
376#if H_MV_ENC_DEC_TRAC
377    DTRACE_PU_S("=========== prediction_unit ===========\n")
378    DTRACE_PU("x0", uiLPelX)
379    DTRACE_PU("x1", uiTPelY)
380#endif
381    m_ppcCU[uiDepth]->copyInterPredInfoFrom( pcCU, uiAbsPartIdx, REF_PIC_LIST_0 );
382    m_ppcCU[uiDepth]->copyInterPredInfoFrom( pcCU, uiAbsPartIdx, REF_PIC_LIST_1 );
383#if H_3D_IV_MERGE
384    m_ppcCU[uiDepth]->copyDVInfoFrom(pcCU, uiAbsPartIdx);
385    TComMvField cMvFieldNeighbours[MRG_MAX_NUM_CANDS_MEM << 1]; // double length for mv of both lists
386    UChar uhInterDirNeighbours[MRG_MAX_NUM_CANDS_MEM];
387#else
388    TComMvField cMvFieldNeighbours[MRG_MAX_NUM_CANDS << 1]; // double length for mv of both lists
389    UChar uhInterDirNeighbours[MRG_MAX_NUM_CANDS];
390#endif
391    Int numValidMergeCand = 0;
392    for( UInt ui = 0; ui < m_ppcCU[uiDepth]->getSlice()->getMaxNumMergeCand(); ++ui )
393    {
394      uhInterDirNeighbours[ui] = 0;
395    }
396    m_pcEntropyDecoder->decodeMergeIndex( pcCU, 0, uiAbsPartIdx, uiDepth );
397    UInt uiMergeIndex = pcCU->getMergeIndex(uiAbsPartIdx);
398#if H_3D_ARP
399    m_pcEntropyDecoder->decodeARPW( pcCU , uiAbsPartIdx , uiDepth );
400#endif
401#if H_3D_IC
402    m_pcEntropyDecoder->decodeICFlag( pcCU, uiAbsPartIdx, uiDepth );
403#endif
404
405#if H_3D_VSP
406    Int vspFlag[MRG_MAX_NUM_CANDS_MEM];
407    memset(vspFlag, 0, sizeof(Int)*MRG_MAX_NUM_CANDS_MEM);
408#if H_3D_SPIVMP
409    Bool bSPIVMPFlag[MRG_MAX_NUM_CANDS_MEM];
410    memset(bSPIVMPFlag, false, sizeof(Bool)*MRG_MAX_NUM_CANDS_MEM);
411    TComMvField*  pcMvFieldSP;
412    UChar* puhInterDirSP;
413    pcMvFieldSP = new TComMvField[pcCU->getPic()->getPicSym()->getNumPartition()*2]; 
414    puhInterDirSP = new UChar[pcCU->getPic()->getPicSym()->getNumPartition()]; 
415#endif
416    m_ppcCU[uiDepth]->initAvailableFlags();
417    m_ppcCU[uiDepth]->getInterMergeCandidates( 0, 0, cMvFieldNeighbours, uhInterDirNeighbours, numValidMergeCand, uiMergeIndex );
418    m_ppcCU[uiDepth]->xGetInterMergeCandidates( 0, 0, cMvFieldNeighbours, uhInterDirNeighbours
419#if H_3D_SPIVMP
420      , pcMvFieldSP, puhInterDirSP
421#endif
422      , numValidMergeCand, uiMergeIndex );
423
424    m_ppcCU[uiDepth]->buildMCL( cMvFieldNeighbours, uhInterDirNeighbours, vspFlag
425#if H_3D_SPIVMP
426      , bSPIVMPFlag
427#endif
428      , numValidMergeCand );
429    pcCU->setVSPFlagSubParts( vspFlag[uiMergeIndex], uiAbsPartIdx, 0, uiDepth );
430#else
431#if H_3D
432    m_ppcCU[uiDepth]->initAvailableFlags();
433    m_ppcCU[uiDepth]->getInterMergeCandidates( 0, 0, cMvFieldNeighbours, uhInterDirNeighbours, numValidMergeCand, uiMergeIndex );
434    m_ppcCU[uiDepth]->xGetInterMergeCandidates( 0, 0, cMvFieldNeighbours, uhInterDirNeighbours, numValidMergeCand, uiMergeIndex );
435#else
436    m_ppcCU[uiDepth]->getInterMergeCandidates( 0, 0, cMvFieldNeighbours, uhInterDirNeighbours, numValidMergeCand, uiMergeIndex );
437#endif
438#endif
439    pcCU->setInterDirSubParts( uhInterDirNeighbours[uiMergeIndex], uiAbsPartIdx, 0, uiDepth );
440
441    TComMv cTmpMv( 0, 0 );
442    for ( UInt uiRefListIdx = 0; uiRefListIdx < 2; uiRefListIdx++ )
443    {
444      if ( pcCU->getSlice()->getNumRefIdx( RefPicList( uiRefListIdx ) ) > 0 )
445      {
446        pcCU->setMVPIdxSubParts( 0, RefPicList( uiRefListIdx ), uiAbsPartIdx, 0, uiDepth);
447        pcCU->setMVPNumSubParts( 0, RefPicList( uiRefListIdx ), uiAbsPartIdx, 0, uiDepth);
448        pcCU->getCUMvField( RefPicList( uiRefListIdx ) )->setAllMvd( cTmpMv, SIZE_2Nx2N, uiAbsPartIdx, uiDepth );
449        pcCU->getCUMvField( RefPicList( uiRefListIdx ) )->setAllMvField( cMvFieldNeighbours[ 2*uiMergeIndex + uiRefListIdx ], SIZE_2Nx2N, uiAbsPartIdx, uiDepth );
450#if H_3D_VSP
451        if( pcCU->getVSPFlag( uiAbsPartIdx ) != 0 )
452        {
453          if ( uhInterDirNeighbours[ uiMergeIndex ] & (1<<uiRefListIdx) )
454          {
455            UInt dummy;
456            Int vspSize;
457            Int width, height;
458            m_ppcCU[uiDepth]->getPartIndexAndSize( uiAbsPartIdx, dummy, width, height );
459            m_ppcCU[uiDepth]->setMvFieldPUForVSP( pcCU, uiAbsPartIdx, width, height, RefPicList( uiRefListIdx ), cMvFieldNeighbours[ 2*uiMergeIndex + uiRefListIdx ].getRefIdx(), vspSize );
460            pcCU->setVSPFlag( uiAbsPartIdx, vspSize );
461          }
462        }
463#endif
464#if ENC_DEC_TRACE && H_MV_ENC_DEC_TRAC   
465        if ( g_decTraceMvFromMerge )
466        {       
467          if ( uiRefListIdx == 0 )
468          {
469            DTRACE_PU( "mvL0[0]", cMvFieldNeighbours[ 2*uiMergeIndex + uiRefListIdx ].getHor());
470            DTRACE_PU( "mvL0[1]", cMvFieldNeighbours[ 2*uiMergeIndex + uiRefListIdx ].getVer());
471            DTRACE_PU( "refIdxL0   ", cMvFieldNeighbours[ 2*uiMergeIndex + uiRefListIdx ].getRefIdx());
472          }
473          else
474          {
475            DTRACE_PU( "mvL1[0]", cMvFieldNeighbours[ 2*uiMergeIndex + uiRefListIdx ].getHor());
476            DTRACE_PU( "mvL1[1]", cMvFieldNeighbours[ 2*uiMergeIndex + uiRefListIdx ].getVer());
477            DTRACE_PU( "refIdxL1", cMvFieldNeighbours[ 2*uiMergeIndex + uiRefListIdx ].getRefIdx());
478          }
479        }
480#endif
481      }
482    }
483#if H_3D_SPIVMP
484    pcCU->setSPIVMPFlagSubParts(bSPIVMPFlag[uiMergeIndex], uiAbsPartIdx, 0, uiDepth ); 
485    if (bSPIVMPFlag[uiMergeIndex])
486    {
487      UInt uiSPAddr;
488      Int iWidth = pcCU->getWidth(uiAbsPartIdx);
489      Int iHeight = pcCU->getHeight(uiAbsPartIdx);
490
491      Int iNumSPInOneLine, iNumSP, iSPWidth, iSPHeight;
492
493      pcCU->getSPPara(iWidth, iHeight, iNumSP, iNumSPInOneLine, iSPWidth, iSPHeight);
494
495      for (Int iPartitionIdx = 0; iPartitionIdx < iNumSP; iPartitionIdx++)
496      {
497        pcCU->getSPAbsPartIdx(uiAbsPartIdx, iSPWidth, iSPHeight, iPartitionIdx, iNumSPInOneLine, uiSPAddr);
498        pcCU->setInterDirSP(puhInterDirSP[iPartitionIdx], uiSPAddr, iSPWidth, iSPHeight);
499        pcCU->getCUMvField( REF_PIC_LIST_0 )->setMvFieldSP(pcCU, uiSPAddr, pcMvFieldSP[2*iPartitionIdx], iSPWidth, iSPHeight);
500        pcCU->getCUMvField( REF_PIC_LIST_1 )->setMvFieldSP(pcCU, uiSPAddr, pcMvFieldSP[2*iPartitionIdx + 1], iSPWidth, iSPHeight);
501      }
502    }
503    delete[] pcMvFieldSP;
504    delete[] puhInterDirSP;
505#endif
506
507    xFinishDecodeCU( pcCU, uiAbsPartIdx, uiDepth, isLastCtuOfSliceSegment );
508#if H_3D_IV_MERGE
509    xDecompressCU(pcCU, uiAbsPartIdx, uiDepth );
510#endif
511
512    return;
513  }
514#if H_3D
515  m_pcEntropyDecoder->decodeDIS( pcCU, uiAbsPartIdx, uiDepth );
516  if(!pcCU->getDISFlag(uiAbsPartIdx))
517  {
518#endif
519
520  m_pcEntropyDecoder->decodePredMode( pcCU, uiAbsPartIdx, uiDepth );
521  m_pcEntropyDecoder->decodePartSize( pcCU, uiAbsPartIdx, uiDepth );
522
523  if (pcCU->isIntra( uiAbsPartIdx ) && pcCU->getPartitionSize( uiAbsPartIdx ) == SIZE_2Nx2N )
524  {
525    m_pcEntropyDecoder->decodeIPCMInfo( pcCU, uiAbsPartIdx, uiDepth );
526
527    if(pcCU->getIPCMFlag(uiAbsPartIdx))
528    {
529#if NH_3D_SDC_INTRA
530      m_pcEntropyDecoder->decodeSDCFlag( pcCU, uiAbsPartIdx, uiDepth );
531#endif
532      xFinishDecodeCU( pcCU, uiAbsPartIdx, uiDepth, isLastCtuOfSliceSegment );
533#if H_3D_IV_MERGE
534      xDecompressCU(pcCU, uiAbsPartIdx, uiDepth );
535#endif
536      return;
537    }
538  }
539
540  // prediction mode ( Intra : direction mode, Inter : Mv, reference idx )
541  m_pcEntropyDecoder->decodePredInfo( pcCU, uiAbsPartIdx, uiDepth, m_ppcCU[uiDepth]);
542
543  // Coefficient decoding
544  Bool bCodeDQP = getdQPFlag();
545  Bool isChromaQpAdjCoded = getIsChromaQpAdjCoded();
546  m_pcEntropyDecoder->decodeCoeff( pcCU, uiAbsPartIdx, uiDepth, bCodeDQP, isChromaQpAdjCoded );
547  setIsChromaQpAdjCoded( isChromaQpAdjCoded );
548  setdQPFlag( bCodeDQP );
549#if H_3D
550  }
551#endif
552  xFinishDecodeCU( pcCU, uiAbsPartIdx, uiDepth, isLastCtuOfSliceSegment );
553#if H_3D_IV_MERGE
554  xDecompressCU(pcCU, uiAbsPartIdx, uiDepth );
555#endif
556}
557
558Void TDecCu::xFinishDecodeCU( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, Bool &isLastCtuOfSliceSegment)
559{
560  if(  pcCU->getSlice()->getPPS()->getUseDQP())
561  {
562    pcCU->setQPSubParts( getdQPFlag()?pcCU->getRefQP(uiAbsPartIdx):pcCU->getCodedQP(), uiAbsPartIdx, uiDepth ); // set QP
563  }
564
565  if (pcCU->getSlice()->getUseChromaQpAdj() && !getIsChromaQpAdjCoded())
566  {
567    pcCU->setChromaQpAdjSubParts( pcCU->getCodedChromaQpAdj(), uiAbsPartIdx, uiDepth ); // set QP
568  }
569
570  isLastCtuOfSliceSegment = xDecodeSliceEnd( pcCU, uiAbsPartIdx );
571}
572
573Void TDecCu::xDecompressCU( TComDataCU* pCtu, UInt uiAbsPartIdx,  UInt uiDepth )
574{
575  TComPic* pcPic = pCtu->getPic();
576#if !H_3D_IV_MERGE
577  TComSlice * pcSlice = pCtu->getSlice();
578  const TComSPS &sps=*(pcSlice->getSPS());
579
580  Bool bBoundary = false;
581  UInt uiLPelX   = pCtu->getCUPelX() + g_auiRasterToPelX[ g_auiZscanToRaster[uiAbsPartIdx] ];
582  UInt uiRPelX   = uiLPelX + (sps.getMaxCUWidth()>>uiDepth)  - 1;
583  UInt uiTPelY   = pCtu->getCUPelY() + g_auiRasterToPelY[ g_auiZscanToRaster[uiAbsPartIdx] ];
584  UInt uiBPelY   = uiTPelY + (sps.getMaxCUHeight()>>uiDepth) - 1;
585
586  if( ( uiRPelX >= sps.getPicWidthInLumaSamples() ) || ( uiBPelY >= sps.getPicHeightInLumaSamples() ) )
587  {
588    bBoundary = true;
589  }
590
591  if( ( ( uiDepth < pCtu->getDepth( uiAbsPartIdx ) ) && ( uiDepth < sps.getLog2DiffMaxMinCodingBlockSize() ) ) || bBoundary )
592  {
593    UInt uiNextDepth = uiDepth + 1;
594    UInt uiQNumParts = pCtu->getTotalNumPart() >> (uiNextDepth<<1);
595    UInt uiIdx = uiAbsPartIdx;
596    for ( UInt uiPartIdx = 0; uiPartIdx < 4; uiPartIdx++ )
597    {
598      uiLPelX = pCtu->getCUPelX() + g_auiRasterToPelX[ g_auiZscanToRaster[uiIdx] ];
599      uiTPelY = pCtu->getCUPelY() + g_auiRasterToPelY[ g_auiZscanToRaster[uiIdx] ];
600
601      if( ( uiLPelX < sps.getPicWidthInLumaSamples() ) && ( uiTPelY < sps.getPicHeightInLumaSamples() ) )
602      {
603        xDecompressCU(pCtu, uiIdx, uiNextDepth );
604      }
605
606      uiIdx += uiQNumParts;
607    }
608    return;
609  }
610#endif
611  // Residual reconstruction
612  m_ppcYuvResi[uiDepth]->clear();
613
614  m_ppcCU[uiDepth]->copySubCU( pCtu, uiAbsPartIdx );
615
616  switch( m_ppcCU[uiDepth]->getPredictionMode(0) )
617  {
618    case MODE_INTER:
619#if H_3D_DBBP
620    if( m_ppcCU[uiDepth]->getDBBPFlag(0) )
621    {
622      xReconInterDBBP( m_ppcCU[uiDepth], uiAbsPartIdx, uiDepth );
623    }
624    else
625    {
626#endif
627#if H_3D_INTER_SDC
628      if( m_ppcCU[uiDepth]->getSDCFlag( 0 ) )
629      {
630        xReconInterSDC( m_ppcCU[uiDepth], uiAbsPartIdx, uiDepth );
631      }
632      else
633      {
634#endif
635      xReconInter( m_ppcCU[uiDepth], uiDepth );
636#if H_3D_INTER_SDC
637      }
638#endif
639#if H_3D_DBBP
640    }
641#endif
642      break;
643    case MODE_INTRA:
644#if NH_3D
645    if( false /*m_ppcCU[uiDepth]->getDISFlag(0)*/ )
646    {
647      //xReconDIS( m_ppcCU[uiDepth], 0, uiDepth );
648    }
649#if NH_3D_SDC_INTRA
650    else if( m_ppcCU[uiDepth]->getSDCFlag(0) )
651    {
652      xReconIntraSDC( m_ppcCU[uiDepth], 0, uiDepth );
653    }
654#endif
655    else
656#endif
657      xReconIntraQT( m_ppcCU[uiDepth], uiDepth );
658      break;
659    default:
660      assert(0);
661      break;
662  }
663
664#if DEBUG_STRING
665  const PredMode predMode=m_ppcCU[uiDepth]->getPredictionMode(0);
666  if (DebugOptionList::DebugString_Structure.getInt()&DebugStringGetPredModeMask(predMode))
667  {
668    PartSize eSize=m_ppcCU[uiDepth]->getPartitionSize(0);
669    std::ostream &ss(std::cout);
670
671    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;
672  }
673#endif
674
675  if ( m_ppcCU[uiDepth]->isLosslessCoded(0) && (m_ppcCU[uiDepth]->getIPCMFlag(0) == false))
676  {
677    xFillPCMBuffer(m_ppcCU[uiDepth], uiDepth);
678  }
679
680  xCopyToPic( m_ppcCU[uiDepth], pcPic, uiAbsPartIdx, uiDepth );
681}
682
683Void TDecCu::xReconInter( TComDataCU* pcCU, UInt uiDepth )
684{
685
686  // inter prediction
687  m_pcPrediction->motionCompensation( pcCU, m_ppcYuvReco[uiDepth] );
688
689#if DEBUG_STRING
690  const Int debugPredModeMask=DebugStringGetPredModeMask(MODE_INTER);
691  if (DebugOptionList::DebugString_Pred.getInt()&debugPredModeMask)
692  {
693    printBlockToStream(std::cout, "###inter-pred: ", *(m_ppcYuvReco[uiDepth]));
694  }
695#endif
696
697  // inter recon
698  xDecodeInterTexture( pcCU, uiDepth );
699
700#if DEBUG_STRING
701  if (DebugOptionList::DebugString_Resi.getInt()&debugPredModeMask)
702  {
703    printBlockToStream(std::cout, "###inter-resi: ", *(m_ppcYuvResi[uiDepth]));
704  }
705#endif
706
707  // clip for only non-zero cbp case
708  if  ( pcCU->getQtRootCbf( 0) )
709  {
710    m_ppcYuvReco[uiDepth]->addClip( m_ppcYuvReco[uiDepth], m_ppcYuvResi[uiDepth], 0, pcCU->getWidth( 0 ), pcCU->getSlice()->getSPS()->getBitDepths() );
711  }
712  else
713  {
714    m_ppcYuvReco[uiDepth]->copyPartToPartYuv( m_ppcYuvReco[uiDepth],0, pcCU->getWidth( 0 ),pcCU->getHeight( 0 ));
715  }
716#if DEBUG_STRING
717  if (DebugOptionList::DebugString_Reco.getInt()&debugPredModeMask)
718  {
719    printBlockToStream(std::cout, "###inter-reco: ", *(m_ppcYuvReco[uiDepth]));
720  }
721#endif
722
723}
724
725#if H_3D
726Void TDecCu::xReconDIS( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
727{
728  UInt uiWidth        = pcCU->getWidth  ( 0 );
729  UInt uiHeight       = pcCU->getHeight ( 0 );
730
731  TComYuv* pcRecoYuv  = m_ppcYuvReco[uiDepth];
732
733  UInt    uiStride    = pcRecoYuv->getStride  ();
734  Pel*    piReco      = pcRecoYuv->getLumaAddr( uiAbsPartIdx );
735
736
737  AOF( uiWidth == uiHeight );
738  AOF( uiAbsPartIdx == 0 );
739
740  Bool  bAboveAvail = false;
741  Bool  bLeftAvail  = false;
742  pcCU->getPattern()->initPattern   ( pcCU, 0, uiAbsPartIdx );
743  pcCU->getPattern()->initAdiPattern( pcCU, uiAbsPartIdx, 0, 
744    m_pcPrediction->getPredicBuf       (),
745    m_pcPrediction->getPredicBufWidth  (),
746    m_pcPrediction->getPredicBufHeight (),
747    bAboveAvail, bLeftAvail
748    );
749
750  if ( pcCU->getDISType(uiAbsPartIdx) == 0 )
751  {
752    m_pcPrediction->predIntraLumaAng( pcCU->getPattern(), VER_IDX, piReco, uiStride, uiWidth, uiHeight, bAboveAvail, bLeftAvail );
753  }
754  else if ( pcCU->getDISType(uiAbsPartIdx) == 1 )
755  {
756    m_pcPrediction->predIntraLumaAng( pcCU->getPattern(), HOR_IDX, piReco, uiStride, uiWidth, uiHeight, bAboveAvail, bLeftAvail );
757  }
758  else if ( pcCU->getDISType(uiAbsPartIdx) == 2 )
759  {
760    Pel pSingleDepth = 1 << ( g_bitDepthY - 1 );
761    pcCU->getNeighDepth ( 0, 0, &pSingleDepth, 0 );
762    for( UInt uiY = 0; uiY < uiHeight; uiY++ )
763    {
764      for( UInt uiX = 0; uiX < uiWidth; uiX++ )
765      {
766        piReco[ uiX ] = pSingleDepth;
767      }
768      piReco+= uiStride;
769    }
770  }
771  else if ( pcCU->getDISType(uiAbsPartIdx) == 3 )
772  {
773    Pel pSingleDepth = 1 << ( g_bitDepthY - 1 );
774    pcCU->getNeighDepth ( 0, 0, &pSingleDepth, 1 );
775    for( UInt uiY = 0; uiY < uiHeight; uiY++ )
776    {
777      for( UInt uiX = 0; uiX < uiWidth; uiX++ )
778      {
779        piReco[ uiX ] = pSingleDepth;
780      }
781      piReco+= uiStride;
782    }
783  }
784
785  // clear UV
786  UInt  uiStrideC     = pcRecoYuv->getCStride();
787  Pel   *pRecCb       = pcRecoYuv->getCbAddr();
788  Pel   *pRecCr       = pcRecoYuv->getCrAddr();
789
790  for (Int y=0; y<uiHeight/2; y++)
791  {
792    for (Int x=0; x<uiWidth/2; x++)
793    {
794      pRecCb[x] = 1<<(g_bitDepthC-1);
795      pRecCr[x] = 1<<(g_bitDepthC-1);
796    }
797
798    pRecCb += uiStrideC;
799    pRecCr += uiStrideC;
800  }
801}
802#endif
803#if H_3D_INTER_SDC
804Void TDecCu::xReconInterSDC( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
805{
806  // inter prediction
807  m_pcPrediction->motionCompensation( pcCU, m_ppcYuvReco[uiDepth] );
808
809  UInt  uiWidth      = pcCU->getWidth ( 0 );
810  UInt  uiHeight     = pcCU->getHeight( 0 );
811
812  Pel  *pResi;
813  UInt uiPelX, uiPelY;
814  UInt uiResiStride = m_ppcYuvResi[uiDepth]->getStride();
815
816  pResi = m_ppcYuvResi[uiDepth]->getLumaAddr( 0 );
817  for( uiPelY = 0; uiPelY < uiHeight; uiPelY++ )
818  {
819    for( uiPelX = 0; uiPelX < uiWidth; uiPelX++ )
820    {
821      pResi[ uiPelX ] = pcCU->getSDCSegmentDCOffset( 0, 0 );
822    }
823    pResi += uiResiStride;
824  }
825
826  m_ppcYuvReco[uiDepth]->addClip( m_ppcYuvReco[uiDepth], m_ppcYuvResi[uiDepth], 0, pcCU->getWidth( 0 ) );
827
828  // clear UV
829  UInt  uiStrideC     = m_ppcYuvReco[uiDepth]->getCStride();
830  Pel   *pRecCb       = m_ppcYuvReco[uiDepth]->getCbAddr();
831  Pel   *pRecCr       = m_ppcYuvReco[uiDepth]->getCrAddr();
832
833  for (Int y = 0; y < uiHeight/2; y++)
834  {
835    for (Int x = 0; x < uiWidth/2; x++)
836    {
837      pRecCb[x] = (Pel)( 1 << ( g_bitDepthC - 1 ) );
838      pRecCr[x] = (Pel)( 1 << ( g_bitDepthC - 1 ) );
839    }
840
841    pRecCb += uiStrideC;
842    pRecCr += uiStrideC;
843  }
844}
845#endif
846
847#if H_3D_DBBP
848Void TDecCu::xReconInterDBBP( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
849{
850  AOF(!pcCU->getSlice()->getIsDepth());
851  AOF(!pcCU->getSlice()->isIntra());
852  PartSize ePartSize = pcCU->getPartitionSize( 0 );
853 
854  // get collocated depth block
855  UInt uiDepthStride = 0;
856#if H_3D_FCO
857  Pel* pDepthPels = pcCU->getVirtualDepthBlock(pcCU->getZorderIdxInCU(), pcCU->getWidth(0), pcCU->getHeight(0), uiDepthStride);
858#else
859  Pel* pDepthPels = pcCU->getVirtualDepthBlock(0, pcCU->getWidth(0), pcCU->getHeight(0), uiDepthStride);
860#endif
861  AOF( pDepthPels != NULL );
862  AOF( uiDepthStride != 0 );
863 
864  // compute mask by segmenting depth block
865  Bool pMask[MAX_CU_SIZE*MAX_CU_SIZE];
866  Bool bValidMask = m_pcPrediction->getSegmentMaskFromDepth(pDepthPels, uiDepthStride, pcCU->getWidth(0), pcCU->getHeight(0), pMask, pcCU);
867  AOF(bValidMask);
868 
869  DbbpTmpData* pDBBPTmpData = pcCU->getDBBPTmpData();
870  TComYuv* apSegPredYuv[2] = { m_ppcYuvReco[uiDepth], m_ppcYuvRecoDBBP[uiDepth] };
871 
872  // first, extract the two sets of motion parameters
873  UInt uiPUOffset = ( g_auiPUOffset[UInt( ePartSize )] << ( ( pcCU->getSlice()->getSPS()->getMaxCUDepth() - uiDepth ) << 1 ) ) >> 4;
874  for( UInt uiSegment = 0; uiSegment < 2; uiSegment++ )
875  {
876    UInt uiPartAddr = uiSegment*uiPUOffset;
877   
878    pDBBPTmpData->auhInterDir[uiSegment] = pcCU->getInterDir(uiPartAddr);
879   
880    for ( UInt uiRefListIdx = 0; uiRefListIdx < 2; uiRefListIdx++ )
881    {
882      RefPicList eRefList = (RefPicList)uiRefListIdx;
883      pcCU->getMvField(pcCU, uiPartAddr, eRefList, pDBBPTmpData->acMvField[uiSegment][eRefList]);
884    }
885   
886    AOF( pcCU->getARPW(uiPartAddr) == 0 );
887    AOF( pcCU->getICFlag(uiPartAddr) == false );
888    AOF( pcCU->getSPIVMPFlag(uiPartAddr) == false );
889    AOF( pcCU->getVSPFlag(uiPartAddr) == 0 );
890  }
891 
892  // do motion compensation for each segment as 2Nx2N
893  pcCU->setPartSizeSubParts( SIZE_2Nx2N, 0, uiDepth );
894  pcCU->setPredModeSubParts( MODE_INTER, 0, uiDepth );
895  for( UInt uiSegment = 0; uiSegment < 2; uiSegment++ )
896  {
897    pcCU->setInterDirSubParts( pDBBPTmpData->auhInterDir[uiSegment], 0, 0, uiDepth );
898 
899    for ( UInt uiRefListIdx = 0; uiRefListIdx < 2; uiRefListIdx++ )
900    {
901      RefPicList eRefList = (RefPicList)uiRefListIdx;
902
903      pcCU->getCUMvField( eRefList )->setAllMvField( pDBBPTmpData->acMvField[uiSegment][eRefList], SIZE_2Nx2N, 0, 0 );
904    }
905   
906    // inter prediction
907    m_pcPrediction->motionCompensation( pcCU, apSegPredYuv[uiSegment] );
908  }
909 
910  // restore motion information in both segments again
911  pcCU->setPartSizeSubParts( ePartSize,  0, uiDepth );
912  pcCU->setPredModeSubParts( MODE_INTER, 0, uiDepth );
913  for( UInt uiSegment = 0; uiSegment < 2; uiSegment++ )
914  {
915    UInt uiPartAddr = uiSegment*uiPUOffset;
916   
917    pcCU->setDBBPFlagSubParts(true, uiPartAddr, uiSegment, uiDepth);
918    pcCU->setInterDirSubParts(pDBBPTmpData->auhInterDir[uiSegment], uiPartAddr, uiSegment, uiDepth); // interprets depth relative to LCU level
919   
920    for ( UInt uiRefListIdx = 0; uiRefListIdx < 2; uiRefListIdx++ )
921    {
922      RefPicList eRefList = (RefPicList)uiRefListIdx;
923
924      pcCU->getCUMvField( eRefList )->setAllMvField( pDBBPTmpData->acMvField[uiSegment][eRefList], ePartSize, uiPartAddr, 0, uiSegment ); // interprets depth relative to rpcTempCU level
925    }
926  }
927 
928  // reconstruct final prediction signal by combining both segments
929  m_pcPrediction->combineSegmentsWithMask(apSegPredYuv, m_ppcYuvReco[uiDepth], pMask, pcCU->getWidth(0), pcCU->getHeight(0), 0, ePartSize);
930
931  // inter recon
932  xDecodeInterTexture( pcCU, 0, uiDepth );
933 
934  // clip for only non-zero cbp case
935  if  ( ( pcCU->getCbf( 0, TEXT_LUMA ) ) || ( pcCU->getCbf( 0, TEXT_CHROMA_U ) ) || ( pcCU->getCbf(0, TEXT_CHROMA_V ) ) )
936  {
937    m_ppcYuvReco[uiDepth]->addClip( m_ppcYuvReco[uiDepth], m_ppcYuvResi[uiDepth], 0, pcCU->getWidth( 0 ) );
938  }
939  else
940  {
941    m_ppcYuvReco[uiDepth]->copyPartToPartYuv( m_ppcYuvReco[uiDepth],0, pcCU->getWidth( 0 ),pcCU->getHeight( 0 ));
942  }
943}
944#endif
945
946
947Void
948TDecCu::xIntraRecBlk(       TComYuv*    pcRecoYuv,
949                            TComYuv*    pcPredYuv,
950                            TComYuv*    pcResiYuv,
951                      const ComponentID compID,
952                            TComTU     &rTu)
953{
954  if (!rTu.ProcessComponentSection(compID))
955  {
956    return;
957  }
958  const Bool       bIsLuma = isLuma(compID);
959
960
961  TComDataCU *pcCU = rTu.getCU();
962  const TComSPS &sps=*(pcCU->getSlice()->getSPS());
963  const UInt uiAbsPartIdx=rTu.GetAbsPartIdxTU();
964
965  const TComRectangle &tuRect  =rTu.getRect(compID);
966  const UInt uiWidth           = tuRect.width;
967  const UInt uiHeight          = tuRect.height;
968  const UInt uiStride          = pcRecoYuv->getStride (compID);
969        Pel* piPred            = pcPredYuv->getAddr( compID, uiAbsPartIdx );
970  const ChromaFormat chFmt     = rTu.GetChromaFormat();
971
972  if (uiWidth != uiHeight)
973  {
974    //------------------------------------------------
975
976    //split at current level if dividing into square sub-TUs
977
978    TComTURecurse subTURecurse(rTu, false, TComTU::VERTICAL_SPLIT, true, compID);
979
980    //recurse further
981    do
982    {
983      xIntraRecBlk(pcRecoYuv, pcPredYuv, pcResiYuv, compID, subTURecurse);
984    } while (subTURecurse.nextSection(rTu));
985
986    //------------------------------------------------
987
988    return;
989  }
990
991  const UInt uiChPredMode  = pcCU->getIntraDir( toChannelType(compID), uiAbsPartIdx );
992  const UInt partsPerMinCU = 1<<(2*(sps.getMaxTotalCUDepth() - sps.getLog2DiffMaxMinCodingBlockSize()));
993  const UInt uiChCodedMode = (uiChPredMode==DM_CHROMA_IDX && !bIsLuma) ? pcCU->getIntraDir(CHANNEL_TYPE_LUMA, getChromasCorrespondingPULumaIdx(uiAbsPartIdx, chFmt, partsPerMinCU)) : uiChPredMode;
994  const UInt uiChFinalMode = ((chFmt == CHROMA_422)       && !bIsLuma) ? g_chroma422IntraAngleMappingTable[uiChCodedMode] : uiChCodedMode;
995
996  //===== init availability pattern =====
997  Bool  bAboveAvail = false;
998  Bool  bLeftAvail  = false;
999
1000  const Bool bUseFilteredPredictions=TComPrediction::filteringIntraReferenceSamples(compID, uiChFinalMode, uiWidth, uiHeight, chFmt, pcCU->getSlice()->getSPS()->getSpsRangeExtension().getIntraSmoothingDisabledFlag());
1001
1002#if DEBUG_STRING
1003  std::ostream &ss(std::cout);
1004#endif
1005
1006  DEBUG_STRING_NEW(sTemp)
1007  m_pcPrediction->initIntraPatternChType( rTu, bAboveAvail, bLeftAvail, compID, bUseFilteredPredictions  DEBUG_STRING_PASS_INTO(sTemp) );
1008
1009
1010  //===== get prediction signal =====
1011#if NH_3D_DMM
1012  if( bIsLuma && isDmmMode( uiChFinalMode ) )
1013  {
1014    m_pcPrediction->predIntraLumaDmm( pcCU, uiAbsPartIdx, getDmmType( uiChFinalMode ), piPred, uiStride, uiWidth, uiHeight );
1015  }
1016  else
1017  {
1018#endif
1019  m_pcPrediction->predIntraAng( compID,   uiChFinalMode, 0 /* Decoder does not have an original image */, 0, piPred, uiStride, rTu, bAboveAvail, bLeftAvail, bUseFilteredPredictions );
1020#if NH_3D_DMM
1021  }
1022#endif
1023
1024#if DEBUG_STRING
1025  ss << sTemp;
1026#endif
1027
1028  //===== inverse transform =====
1029  Pel*      piResi            = pcResiYuv->getAddr( compID, uiAbsPartIdx );
1030  TCoeff*   pcCoeff           = pcCU->getCoeff(compID) + rTu.getCoefficientOffset(compID);//( uiNumCoeffInc * uiAbsPartIdx );
1031
1032  const QpParam cQP(*pcCU, compID);
1033
1034
1035  DEBUG_STRING_NEW(sDebug);
1036#if DEBUG_STRING
1037  const Int debugPredModeMask=DebugStringGetPredModeMask(MODE_INTRA);
1038  std::string *psDebug=(DebugOptionList::DebugString_InvTran.getInt()&debugPredModeMask) ? &sDebug : 0;
1039#endif
1040#if H_3D
1041  Bool useDltFlag = (isDmmMode( uiLumaPredMode ) || uiLumaPredMode == HOR_IDX || uiLumaPredMode == VER_IDX || uiLumaPredMode == DC_IDX) && pcCU->getSlice()->getIsDepth() && pcCU->getSlice()->getPPS()->getDLT()->getUseDLTFlag(pcCU->getSlice()->getLayerIdInVps());
1042
1043  if ( pcCU->getCbf( uiAbsPartIdx, TEXT_LUMA, uiTrDepth ) || useDltFlag )
1044#else
1045  if (pcCU->getCbf(uiAbsPartIdx, compID, rTu.GetTransformDepthRel()) != 0)
1046#endif
1047  {
1048    m_pcTrQuant->invTransformNxN( rTu, compID, piResi, uiStride, pcCoeff, cQP DEBUG_STRING_PASS_INTO(psDebug) );
1049  }
1050  else
1051  {
1052    for (UInt y = 0; y < uiHeight; y++)
1053    {
1054      for (UInt x = 0; x < uiWidth; x++)
1055      {
1056        piResi[(y * uiStride) + x] = 0;
1057      }
1058    }
1059  }
1060
1061#if DEBUG_STRING
1062  if (psDebug)
1063  {
1064    ss << (*psDebug);
1065  }
1066#endif
1067
1068  //===== reconstruction =====
1069  const UInt uiRecIPredStride  = pcCU->getPic()->getPicYuvRec()->getStride(compID);
1070
1071  const Bool useCrossComponentPrediction = isChroma(compID) && (pcCU->getCrossComponentPredictionAlpha(uiAbsPartIdx, compID) != 0);
1072  const Pel* pResiLuma  = pcResiYuv->getAddr( COMPONENT_Y, uiAbsPartIdx );
1073  const Int  strideLuma = pcResiYuv->getStride( COMPONENT_Y );
1074
1075        Pel* pPred      = piPred;
1076        Pel* pResi      = piResi;
1077        Pel* pReco      = pcRecoYuv->getAddr( compID, uiAbsPartIdx );
1078        Pel* pRecIPred  = pcCU->getPic()->getPicYuvRec()->getAddr( compID, pcCU->getCtuRsAddr(), pcCU->getZorderIdxInCtu() + uiAbsPartIdx );
1079
1080
1081#if DEBUG_STRING
1082  const Bool bDebugPred=((DebugOptionList::DebugString_Pred.getInt()&debugPredModeMask) && DEBUG_STRING_CHANNEL_CONDITION(compID));
1083  const Bool bDebugResi=((DebugOptionList::DebugString_Resi.getInt()&debugPredModeMask) && DEBUG_STRING_CHANNEL_CONDITION(compID));
1084  const Bool bDebugReco=((DebugOptionList::DebugString_Reco.getInt()&debugPredModeMask) && DEBUG_STRING_CHANNEL_CONDITION(compID));
1085  if (bDebugPred || bDebugResi || bDebugReco)
1086  {
1087    ss << "###: " << "CompID: " << compID << " pred mode (ch/fin): " << uiChPredMode << "/" << uiChFinalMode << " absPartIdx: " << rTu.GetAbsPartIdxTU() << std::endl;
1088  }
1089#endif
1090
1091  const Int clipbd = sps.getBitDepth(toChannelType(compID));
1092#if O0043_BEST_EFFORT_DECODING
1093  const Int bitDepthDelta = sps.getStreamBitDepth(toChannelType(compID)) - clipbd;
1094#endif
1095
1096  if( useCrossComponentPrediction )
1097  {
1098    TComTrQuant::crossComponentPrediction( rTu, compID, pResiLuma, piResi, piResi, uiWidth, uiHeight, strideLuma, uiStride, uiStride, true );
1099  }
1100
1101  for( UInt uiY = 0; uiY < uiHeight; uiY++ )
1102  {
1103#if DEBUG_STRING
1104    if (bDebugPred || bDebugResi || bDebugReco)
1105    {
1106      ss << "###: ";
1107    }
1108
1109    if (bDebugPred)
1110    {
1111      ss << " - pred: ";
1112      for( UInt uiX = 0; uiX < uiWidth; uiX++ )
1113      {
1114        ss << pPred[ uiX ] << ", ";
1115      }
1116    }
1117    if (bDebugResi)
1118    {
1119      ss << " - resi: ";
1120    }
1121#endif
1122
1123    for( UInt uiX = 0; uiX < uiWidth; uiX++ )
1124    {
1125#if DEBUG_STRING
1126      if (bDebugResi)
1127      {
1128        ss << pResi[ uiX ] << ", ";
1129      }
1130#endif
1131#if O0043_BEST_EFFORT_DECODING
1132      pReco    [ uiX ] = ClipBD( rightShiftEvenRounding<Pel>(pPred[ uiX ] + pResi[ uiX ], bitDepthDelta), clipbd );
1133#else
1134      pReco    [ uiX ] = ClipBD( pPred[ uiX ] + pResi[ uiX ], clipbd );
1135#endif
1136      pRecIPred[ uiX ] = pReco[ uiX ];
1137    }
1138#if DEBUG_STRING
1139    if (bDebugReco)
1140    {
1141      ss << " - reco: ";
1142      for( UInt uiX = 0; uiX < uiWidth; uiX++ )
1143      {
1144        ss << pReco[ uiX ] << ", ";
1145      }
1146    }
1147
1148    if (bDebugPred || bDebugResi || bDebugReco)
1149    {
1150      ss << "\n";
1151    }
1152#endif
1153    pPred     += uiStride;
1154    pResi     += uiStride;
1155    pReco     += uiStride;
1156    pRecIPred += uiRecIPredStride;
1157  }
1158}
1159
1160Void
1161TDecCu::xReconIntraQT( TComDataCU* pcCU, UInt uiDepth )
1162{
1163  if (pcCU->getIPCMFlag(0))
1164  {
1165    xReconPCM( pcCU, uiDepth );
1166    return;
1167  }
1168  const UInt numChType = pcCU->getPic()->getChromaFormat()!=CHROMA_400 ? 2 : 1;
1169  for (UInt chType=CHANNEL_TYPE_LUMA; chType<numChType; chType++)
1170  {
1171    const ChannelType chanType=ChannelType(chType);
1172    const Bool NxNPUHas4Parts = ::isChroma(chanType) ? enable4ChromaPUsInIntraNxNCU(pcCU->getPic()->getChromaFormat()) : true;
1173    const UInt uiInitTrDepth = ( pcCU->getPartitionSize(0) != SIZE_2Nx2N && NxNPUHas4Parts ? 1 : 0 );
1174
1175    TComTURecurse tuRecurseCU(pcCU, 0);
1176    TComTURecurse tuRecurseWithPU(tuRecurseCU, false, (uiInitTrDepth==0)?TComTU::DONT_SPLIT : TComTU::QUAD_SPLIT);
1177
1178    do
1179    {
1180      xIntraRecQT( m_ppcYuvReco[uiDepth], m_ppcYuvReco[uiDepth], m_ppcYuvResi[uiDepth], chanType, tuRecurseWithPU );
1181    } while (tuRecurseWithPU.nextSection(tuRecurseCU));
1182  }
1183}
1184
1185#if NH_3D_SDC_INTRA
1186Void TDecCu::xReconIntraSDC( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
1187{
1188#if TEMP_SDC_CLEANUP // PM: consider this cleanup for DMM and SDC
1189  TComYuv* pcRecoYuv  = m_ppcYuvReco[uiDepth];
1190  TComYuv* pcPredYuv  = m_ppcYuvReco[uiDepth];
1191  TComYuv* pcResiYuv  = m_ppcYuvResi[uiDepth];
1192
1193  UInt uiWidth        = pcCU->getWidth ( 0 );
1194  UInt uiHeight       = pcCU->getHeight( 0 );
1195  UInt uiLumaPredMode = pcCU->getIntraDir( CHANNEL_TYPE_LUMA, uiAbsPartIdx );
1196  const Int bitDepthY = pcCU->getSlice()->getSPS()->getBitDepth(CHANNEL_TYPE_LUMA);
1197  const TComSPS     &sps    = *(pcCU->getSlice()->getSPS());
1198  const ChromaFormat chFmt  = pcCU->getPic()->getChromaFormat();
1199
1200  UInt sdcDepth = 0;
1201  UInt uiStride;
1202  Pel* piReco;
1203  Pel* piPred;
1204  Pel* piResi;
1205
1206  Pel* piRecIPred;
1207  UInt uiRecIPredStride;
1208 
1209  Pel apDCPredValues[2];
1210  UInt uiNumSegments;
1211
1212  Bool* pbMask = NULL;
1213  UInt uiMaskStride = 0;
1214
1215#if NH_3D_DMM
1216  if( isDmmMode( uiLumaPredMode ) )
1217  {
1218    assert( uiWidth == uiHeight  );
1219    assert( uiWidth >= DMM_MIN_SIZE && uiWidth <= DMM_MAX_SIZE );
1220    assert( !((uiWidth >> pcCU->getSlice()->getSPS()->getQuadtreeTULog2MaxSize()) > 1) );
1221
1222    uiNumSegments     = 2;
1223
1224    uiStride          = pcRecoYuv->getStride( COMPONENT_Y );
1225    piReco            = pcRecoYuv->getAddr  ( COMPONENT_Y, uiAbsPartIdx );
1226    piPred            = pcPredYuv->getAddr  ( COMPONENT_Y, uiAbsPartIdx );
1227    piResi            = pcResiYuv->getAddr  ( COMPONENT_Y, uiAbsPartIdx );
1228
1229    piRecIPred        = pcCU->getPic()->getPicYuvRec()->getAddr  ( COMPONENT_Y, pcCU->getCtuRsAddr(), pcCU->getZorderIdxInCtu() + uiAbsPartIdx );
1230    uiRecIPredStride  = pcCU->getPic()->getPicYuvRec()->getStride( COMPONENT_Y );
1231
1232    //===== init availability pattern =====
1233    TComTURecurse tuRecurseCU(pcCU, 0);
1234    TComTURecurse tuRecurseWithPU(tuRecurseCU, false, TComTU::DONT_SPLIT);
1235
1236    Bool bAboveAvail = false;
1237    Bool bLeftAvail  = false;
1238    m_pcPrediction->initIntraPatternChType( tuRecurseWithPU, bAboveAvail, bLeftAvail, COMPONENT_Y, false DEBUG_STRING_PASS_INTO(sTemp) );
1239
1240    // get partition
1241    pbMask       = new Bool[ uiWidth*uiHeight ];
1242    uiMaskStride = uiWidth;
1243    switch( getDmmType( uiLumaPredMode ) )
1244    {
1245    case( DMM1_IDX ): { (getWedgeListScaled( uiWidth )->at( pcCU->getDmm1WedgeTabIdx( uiAbsPartIdx ) )).getPatternScaledCopy( uiWidth, pbMask ); } break;
1246    case( DMM4_IDX ): { m_pcPrediction->predContourFromTex( pcCU, uiAbsPartIdx, uiWidth, uiHeight, pbMask );                                     } break;
1247    default: assert(0);
1248    }
1249
1250    // get predicted partition values
1251    Pel predDC1 = 0, predDC2 = 0;
1252    m_pcPrediction->predBiSegDCs( pcCU, uiAbsPartIdx, uiWidth, uiHeight, pbMask, uiMaskStride, predDC1, predDC2 );
1253
1254    // set prediction signal
1255    Pel* pDst = piPred;
1256    m_pcPrediction->assignBiSegDCs( pDst, uiStride, pbMask, uiMaskStride, predDC1, predDC2 );
1257    apDCPredValues[0] = predDC1;
1258    apDCPredValues[1] = predDC2;
1259  }
1260  else // regular HEVC intra modes
1261  {
1262#endif
1263    uiNumSegments = 1;
1264
1265    if( ( uiWidth >> pcCU->getSlice()->getSPS()->getQuadtreeTULog2MaxSize() ) > 1 )
1266    {
1267      sdcDepth = g_aucConvertToBit[uiWidth] + 2 - pcCU->getSlice()->getSPS()->getQuadtreeTULog2MaxSize();
1268    }
1269   
1270    //===== loop over partitions =====
1271    TComTURecurse tuRecurseCU(pcCU, 0);
1272    TComTURecurse tuRecurseWithPU(tuRecurseCU, false, (sdcDepth==0)?TComTU::DONT_SPLIT:TComTU::QUAD_SPLIT);
1273
1274    do
1275    {
1276      const TComRectangle &puRect = tuRecurseWithPU.getRect(COMPONENT_Y);
1277      const UInt uiAbsPartIdxTU = tuRecurseWithPU.GetAbsPartIdxTU();
1278     
1279      Pel* piPredTU       = pcPredYuv->getAddr  ( COMPONENT_Y, uiAbsPartIdxTU );
1280      UInt uiStrideTU     = pcPredYuv->getStride( COMPONENT_Y );
1281     
1282      Pel* piRecIPredTU   = pcCU->getPic()->getPicYuvRec()->getAddr( COMPONENT_Y, pcCU->getCtuRsAddr(), pcCU->getZorderIdxInCtu() + uiAbsPartIdxTU );
1283      UInt uiRecIPredStrideTU  = pcCU->getPic()->getPicYuvRec()->getStride(COMPONENT_Y);
1284     
1285      const Bool bUseFilter = TComPrediction::filteringIntraReferenceSamples(COMPONENT_Y, uiLumaPredMode, puRect.width, puRect.height, chFmt, sps.getSpsRangeExtension().getIntraSmoothingDisabledFlag());
1286     
1287      //===== init pattern for luma prediction =====
1288      Bool bAboveAvail = false;
1289      Bool bLeftAvail  = false;
1290     
1291      m_pcPrediction->initIntraPatternChType( tuRecurseWithPU, bAboveAvail, bLeftAvail, COMPONENT_Y, bUseFilter  DEBUG_STRING_PASS_INTO(sTemp) );
1292     
1293      m_pcPrediction->predIntraAng( COMPONENT_Y, uiLumaPredMode, NULL, uiStrideTU, piPredTU, uiStrideTU, tuRecurseWithPU, bAboveAvail, bLeftAvail, bUseFilter );
1294     
1295      // copy for prediction of next part
1296      for( UInt uiY = 0; uiY < puRect.height; uiY++ )
1297      {
1298        for( UInt uiX = 0; uiX < puRect.width; uiX++ )
1299        {
1300          piPredTU      [ uiX ] = ClipBD( piPredTU[ uiX ], bitDepthY );
1301          piRecIPredTU  [ uiX ] = piPredTU[ uiX ];
1302        }
1303        piPredTU     += uiStrideTU;
1304        piRecIPredTU += uiRecIPredStrideTU;
1305      }
1306     
1307     
1308    } while (tuRecurseWithPU.nextSection(tuRecurseCU));
1309
1310    // reset to full block
1311    uiWidth  = pcCU->getWidth( 0 );
1312    uiHeight = pcCU->getHeight( 0 );
1313
1314    uiStride          = pcRecoYuv->getStride( COMPONENT_Y );
1315    piReco            = pcRecoYuv->getAddr  ( COMPONENT_Y, uiAbsPartIdx );
1316    piPred            = pcPredYuv->getAddr  ( COMPONENT_Y, uiAbsPartIdx );
1317    piResi            = pcResiYuv->getAddr  ( COMPONENT_Y, uiAbsPartIdx );
1318   
1319    piRecIPred        = pcCU->getPic()->getPicYuvRec()->getAddr  ( COMPONENT_Y, pcCU->getCtuRsAddr(), pcCU->getZorderIdxInCtu() + uiAbsPartIdx );
1320    uiRecIPredStride  = pcCU->getPic()->getPicYuvRec()->getStride( COMPONENT_Y );
1321
1322    m_pcPrediction->predConstantSDC( piPred, uiStride, uiWidth, apDCPredValues[0] ); apDCPredValues[1] = 0;
1323#if NH_3D_DMM
1324  }
1325#endif
1326#else
1327  UInt uiWidth        = pcCU->getWidth  ( 0 );
1328  UInt uiHeight       = pcCU->getHeight ( 0 );
1329  TComWedgelet* dmm4SegmentationOrg = new TComWedgelet( uiWidth, uiHeight );
1330  UInt numParts = 1;
1331  UInt sdcDepth    = 0;
1332  TComYuv* pcRecoYuv  = m_ppcYuvReco[uiDepth];
1333  TComYuv* pcPredYuv  = m_ppcYuvReco[uiDepth];
1334  TComYuv* pcResiYuv  = m_ppcYuvResi[uiDepth];
1335
1336  UInt    uiStride = 0;
1337  Pel*    piReco;
1338  Pel*    piPred;
1339  Pel*    piResi;
1340
1341  UInt    uiZOrder;       
1342  Pel*    piRecIPred;     
1343  UInt    uiRecIPredStride;
1344
1345  UInt    uiLumaPredMode = 0; 
1346
1347  if ((uiWidth >> pcCU->getSlice()->getSPS()->getQuadtreeTULog2MaxSize()) > 1)
1348  {
1349    numParts = uiWidth * uiWidth >> (2 * pcCU->getSlice()->getSPS()->getQuadtreeTULog2MaxSize());
1350    sdcDepth = g_aucConvertToBit[uiWidth] + 2 - pcCU->getSlice()->getSPS()->getQuadtreeTULog2MaxSize();
1351    uiWidth = uiHeight = (1 << pcCU->getSlice()->getSPS()->getQuadtreeTULog2MaxSize());
1352  }
1353
1354  for ( Int i = 0; i < numParts; i++ )
1355  {
1356    uiStride    = pcRecoYuv->getStride  ();
1357    piReco      = pcRecoYuv->getLumaAddr( uiAbsPartIdx );
1358    piPred      = pcPredYuv->getLumaAddr( uiAbsPartIdx );
1359    piResi      = pcResiYuv->getLumaAddr( uiAbsPartIdx );
1360
1361    uiZOrder          = pcCU->getZorderIdxInCU() + uiAbsPartIdx;
1362    piRecIPred        = pcCU->getPic()->getPicYuvRec()->getLumaAddr( pcCU->getAddr(), uiZOrder );
1363    uiRecIPredStride  = pcCU->getPic()->getPicYuvRec()->getStride  ();
1364
1365    uiLumaPredMode    = pcCU->getLumaIntraDir     ( uiAbsPartIdx );
1366
1367    AOF( uiWidth == uiHeight );
1368
1369    //===== init availability pattern =====
1370    Bool  bAboveAvail = false;
1371    Bool  bLeftAvail  = false;
1372
1373    pcCU->getPattern()->initPattern   ( pcCU, sdcDepth, uiAbsPartIdx );
1374    pcCU->getPattern()->initAdiPattern( pcCU, uiAbsPartIdx, sdcDepth, m_pcPrediction->getPredicBuf(), m_pcPrediction->getPredicBufWidth(), m_pcPrediction->getPredicBufHeight(), bAboveAvail, bLeftAvail );
1375
1376    TComWedgelet* dmm4Segmentation = new TComWedgelet( uiWidth, uiHeight );
1377    //===== get prediction signal =====
1378    if( isDmmMode( uiLumaPredMode ) )
1379    {
1380      m_pcPrediction->predIntraLumaDepth( pcCU, uiAbsPartIdx, uiLumaPredMode, piPred, uiStride, uiWidth, uiHeight, false, dmm4Segmentation  );
1381      Bool* dmm4PatternSplit = dmm4Segmentation->getPattern();
1382      Bool* dmm4PatternOrg = dmm4SegmentationOrg->getPattern();
1383      for( UInt k = 0; k < (uiWidth*uiHeight); k++ ) 
1384      { 
1385        dmm4PatternOrg[k+(uiAbsPartIdx<<4)] = dmm4PatternSplit[k];
1386      }
1387    }
1388    else
1389    {
1390      m_pcPrediction->predIntraLumaAng( pcCU->getPattern(), uiLumaPredMode, piPred, uiStride, uiWidth, uiHeight, bAboveAvail, bLeftAvail );
1391    }
1392
1393    if ( numParts > 1 )
1394    {
1395      for( UInt uiY = 0; uiY < uiHeight; uiY++ )
1396      {
1397        for( UInt uiX = 0; uiX < uiWidth; uiX++ )
1398        {
1399          piReco        [ uiX ] = ClipY( piPred[ uiX ] );
1400          piRecIPred    [ uiX ] = piReco[ uiX ];
1401        }
1402        piPred     += uiStride;
1403        piReco     += uiStride;
1404        piRecIPred += uiRecIPredStride;
1405      }
1406    }
1407    uiAbsPartIdx += ( (uiWidth * uiWidth) >> 4 );
1408    dmm4Segmentation->destroy(); delete dmm4Segmentation;
1409  }
1410  uiAbsPartIdx = 0;
1411 
1412  if ( numParts > 1 )
1413  {
1414    uiWidth = pcCU->getWidth( 0 );
1415    uiHeight = pcCU->getHeight( 0 );
1416  }
1417  piReco      = pcRecoYuv->getLumaAddr( uiAbsPartIdx );
1418  piPred      = pcPredYuv->getLumaAddr( uiAbsPartIdx );
1419  piResi      = pcResiYuv->getLumaAddr( uiAbsPartIdx );
1420  uiZOrder          = pcCU->getZorderIdxInCU() + uiAbsPartIdx;
1421  piRecIPred        = pcCU->getPic()->getPicYuvRec()->getLumaAddr( pcCU->getAddr(), uiZOrder );
1422  uiRecIPredStride  = pcCU->getPic()->getPicYuvRec()->getStride  ();
1423  // number of segments depends on prediction mode
1424  UInt uiNumSegments = 1;
1425  Bool* pbMask = NULL;
1426  UInt uiMaskStride = 0;
1427 
1428  if( getDmmType( uiLumaPredMode ) == DMM1_IDX )
1429  {
1430    Int uiTabIdx = pcCU->getDmmWedgeTabIdx(DMM1_IDX, uiAbsPartIdx);
1431
1432    WedgeList* pacWedgeList  = pcCU->isDMM1UpscaleMode(uiWidth) ? &g_dmmWedgeLists[(g_aucConvertToBit[pcCU->getDMM1BasePatternWidth(uiWidth)])] :  &g_dmmWedgeLists[(g_aucConvertToBit[uiWidth])];
1433    TComWedgelet* pcWedgelet = &(pacWedgeList->at( uiTabIdx ));
1434
1435    uiNumSegments = 2;
1436
1437    pbMask       = pcCU->isDMM1UpscaleMode( uiWidth ) ? pcWedgelet->getScaledPattern(uiWidth) : pcWedgelet->getPattern();
1438    uiMaskStride = pcCU->isDMM1UpscaleMode( uiWidth ) ? uiWidth : pcWedgelet->getStride();
1439  }
1440  if( getDmmType( uiLumaPredMode ) == DMM4_IDX )
1441  {
1442    uiNumSegments = 2;
1443    pbMask  = dmm4SegmentationOrg->getPattern();
1444    uiMaskStride = dmm4SegmentationOrg->getStride();
1445  }
1446  // get DC prediction for each segment
1447  Pel apDCPredValues[2];
1448  if ( getDmmType( uiLumaPredMode ) == DMM1_IDX || getDmmType( uiLumaPredMode ) == DMM4_IDX )
1449  {
1450    apDCPredValues[0] = pcCU->getDmmPredictor( 0 );
1451    apDCPredValues[1] = pcCU->getDmmPredictor( 1 );
1452  }
1453  else
1454  {
1455    m_pcPrediction->analyzeSegmentsSDC(piPred, uiStride, uiWidth, apDCPredValues, uiNumSegments, pbMask, uiMaskStride, uiLumaPredMode);
1456  }
1457#endif
1458 
1459  // reconstruct residual based on mask + DC residuals
1460  Pel apDCResiValues[2];
1461  for( UInt uiSegment = 0; uiSegment < uiNumSegments; uiSegment++ )
1462  {
1463#if NH_3D_DLT
1464    Pel   pPredIdx    = pcCU->getSlice()->getPPS()->getDLT()->depthValue2idx( pcCU->getSlice()->getLayerIdInVps(), apDCPredValues[uiSegment] );
1465    Pel   pResiIdx    = pcCU->getSDCSegmentDCOffset(uiSegment, uiAbsPartIdx);
1466    Pel   pRecoValue  = pcCU->getSlice()->getPPS()->getDLT()->idx2DepthValue( pcCU->getSlice()->getLayerIdInVps(), pPredIdx + pResiIdx );
1467
1468    apDCResiValues[uiSegment]  = pRecoValue - apDCPredValues[uiSegment];
1469#else
1470    apDCResiValues[uiSegment]  = pcCU->getSDCSegmentDCOffset(uiSegment, uiAbsPartIdx);
1471#endif
1472  }
1473 
1474  //===== reconstruction =====
1475  Bool*pMask      = pbMask;
1476  Pel* pPred      = piPred;
1477  Pel* pResi      = piResi;
1478  Pel* pReco      = piReco;
1479  Pel* pRecIPred  = piRecIPred;
1480 
1481  for( UInt uiY = 0; uiY < uiHeight; uiY++ )
1482  {
1483    for( UInt uiX = 0; uiX < uiWidth; uiX++ )
1484    {
1485      UChar ucSegment = pMask?(UChar)pMask[uiX]:0;
1486      assert( ucSegment < uiNumSegments );
1487     
1488      Pel pResiDC = apDCResiValues[ucSegment];
1489     
1490      pReco    [ uiX ] = ClipBD( pPred[ uiX ] + pResiDC, bitDepthY );
1491      pRecIPred[ uiX ] = pReco[ uiX ];
1492    }
1493    pPred     += uiStride;
1494    pResi     += uiStride;
1495    pReco     += uiStride;
1496    pRecIPred += uiRecIPredStride;
1497    pMask     += uiMaskStride;
1498  }
1499 
1500  // clear chroma
1501  UInt  uiStrideC     = pcPredYuv->getStride( COMPONENT_Cb );
1502  Pel   *pRecCb       = pcPredYuv->getAddr  ( COMPONENT_Cb, uiAbsPartIdx );
1503  Pel   *pRecCr       = pcPredYuv->getAddr  ( COMPONENT_Cr, uiAbsPartIdx );
1504 
1505  for (Int y=0; y<uiHeight/2; y++)
1506  {
1507    for (Int x=0; x<uiWidth/2; x++)
1508    {
1509      pRecCb[x] = 128;
1510      pRecCr[x] = 128;
1511    }
1512   
1513    pRecCb += uiStrideC;
1514    pRecCr += uiStrideC;
1515  }
1516#if NH_3D_DMM
1517#if TEMP_SDC_CLEANUP // PM: consider this cleanup for DMM and SDC
1518  if( pbMask ) { delete[] pbMask; }
1519#else
1520  dmm4SegmentationOrg->destroy(); delete dmm4SegmentationOrg;
1521#endif
1522#endif
1523}
1524#endif
1525
1526
1527/** Function for deriving reconstructed PU/CU chroma samples with QTree structure
1528 * \param pcRecoYuv pointer to reconstructed sample arrays
1529 * \param pcPredYuv pointer to prediction sample arrays
1530 * \param pcResiYuv pointer to residue sample arrays
1531 * \param chType    texture channel type (luma/chroma)
1532 * \param rTu       reference to transform data
1533 *
1534 \ This function derives reconstructed PU/CU chroma samples with QTree recursive structure
1535 */
1536
1537Void
1538TDecCu::xIntraRecQT(TComYuv*    pcRecoYuv,
1539                    TComYuv*    pcPredYuv,
1540                    TComYuv*    pcResiYuv,
1541                    const ChannelType chType,
1542                    TComTU     &rTu)
1543{
1544  UInt uiTrDepth    = rTu.GetTransformDepthRel();
1545  TComDataCU *pcCU  = rTu.getCU();
1546  UInt uiAbsPartIdx = rTu.GetAbsPartIdxTU();
1547  UInt uiTrMode     = pcCU->getTransformIdx( uiAbsPartIdx );
1548  if( uiTrMode == uiTrDepth )
1549  {
1550    if (isLuma(chType))
1551    {
1552      xIntraRecBlk( pcRecoYuv, pcPredYuv, pcResiYuv, COMPONENT_Y,  rTu );
1553    }
1554    else
1555    {
1556      const UInt numValidComp=getNumberValidComponents(rTu.GetChromaFormat());
1557      for(UInt compID=COMPONENT_Cb; compID<numValidComp; compID++)
1558      {
1559        xIntraRecBlk( pcRecoYuv, pcPredYuv, pcResiYuv, ComponentID(compID), rTu );
1560      }
1561    }
1562  }
1563  else
1564  {
1565    TComTURecurse tuRecurseChild(rTu, false);
1566    do
1567    {
1568      xIntraRecQT( pcRecoYuv, pcPredYuv, pcResiYuv, chType, tuRecurseChild );
1569    } while (tuRecurseChild.nextSection(rTu));
1570  }
1571}
1572
1573Void TDecCu::xCopyToPic( TComDataCU* pcCU, TComPic* pcPic, UInt uiZorderIdx, UInt uiDepth )
1574{
1575  UInt uiCtuRsAddr = pcCU->getCtuRsAddr();
1576
1577  m_ppcYuvReco[uiDepth]->copyToPicYuv  ( pcPic->getPicYuvRec (), uiCtuRsAddr, uiZorderIdx );
1578
1579  return;
1580}
1581
1582Void TDecCu::xDecodeInterTexture ( TComDataCU* pcCU, UInt uiDepth )
1583{
1584
1585  TComTURecurse tuRecur(pcCU, 0, uiDepth);
1586
1587  for(UInt ch=0; ch<pcCU->getPic()->getNumberValidComponents(); ch++)
1588  {
1589    const ComponentID compID=ComponentID(ch);
1590    DEBUG_STRING_OUTPUT(std::cout, debug_reorder_data_inter_token[compID])
1591
1592    m_pcTrQuant->invRecurTransformNxN ( compID, m_ppcYuvResi[uiDepth], tuRecur );
1593  }
1594
1595  DEBUG_STRING_OUTPUT(std::cout, debug_reorder_data_inter_token[MAX_NUM_COMPONENT])
1596}
1597
1598/** Function for deriving reconstructed luma/chroma samples of a PCM mode CU.
1599 * \param pcCU pointer to current CU
1600 * \param uiPartIdx part index
1601 * \param piPCM pointer to PCM code arrays
1602 * \param piReco pointer to reconstructed sample arrays
1603 * \param uiStride stride of reconstructed sample arrays
1604 * \param uiWidth CU width
1605 * \param uiHeight CU height
1606 * \param compID colour component ID
1607 * \returns Void
1608 */
1609Void TDecCu::xDecodePCMTexture( TComDataCU* pcCU, const UInt uiPartIdx, const Pel *piPCM, Pel* piReco, const UInt uiStride, const UInt uiWidth, const UInt uiHeight, const ComponentID compID)
1610{
1611        Pel* piPicReco         = pcCU->getPic()->getPicYuvRec()->getAddr(compID, pcCU->getCtuRsAddr(), pcCU->getZorderIdxInCtu()+uiPartIdx);
1612  const UInt uiPicStride       = pcCU->getPic()->getPicYuvRec()->getStride(compID);
1613  const TComSPS &sps           = *(pcCU->getSlice()->getSPS());
1614  const UInt uiPcmLeftShiftBit = sps.getBitDepth(toChannelType(compID)) - sps.getPCMBitDepth(toChannelType(compID));
1615
1616  for(UInt uiY = 0; uiY < uiHeight; uiY++ )
1617  {
1618    for(UInt uiX = 0; uiX < uiWidth; uiX++ )
1619    {
1620      piReco[uiX] = (piPCM[uiX] << uiPcmLeftShiftBit);
1621      piPicReco[uiX] = piReco[uiX];
1622    }
1623    piPCM += uiWidth;
1624    piReco += uiStride;
1625    piPicReco += uiPicStride;
1626  }
1627}
1628
1629/** Function for reconstructing a PCM mode CU.
1630 * \param pcCU pointer to current CU
1631 * \param uiDepth CU Depth
1632 * \returns Void
1633 */
1634Void TDecCu::xReconPCM( TComDataCU* pcCU, UInt uiDepth )
1635{
1636  const UInt maxCuWidth     = pcCU->getSlice()->getSPS()->getMaxCUWidth();
1637  const UInt maxCuHeight    = pcCU->getSlice()->getSPS()->getMaxCUHeight();
1638  for (UInt ch=0; ch < pcCU->getPic()->getNumberValidComponents(); ch++)
1639  {
1640    const ComponentID compID = ComponentID(ch);
1641    const UInt width  = (maxCuWidth >>(uiDepth+m_ppcYuvResi[uiDepth]->getComponentScaleX(compID)));
1642    const UInt height = (maxCuHeight>>(uiDepth+m_ppcYuvResi[uiDepth]->getComponentScaleY(compID)));
1643    const UInt stride = m_ppcYuvResi[uiDepth]->getStride(compID);
1644    Pel * pPCMChannel = pcCU->getPCMSample(compID);
1645    Pel * pRecChannel = m_ppcYuvReco[uiDepth]->getAddr(compID);
1646    xDecodePCMTexture( pcCU, 0, pPCMChannel, pRecChannel, stride, width, height, compID );
1647  }
1648}
1649
1650/** Function for filling the PCM buffer of a CU using its reconstructed sample array
1651 * \param pCU   pointer to current CU
1652 * \param depth CU Depth
1653 */
1654Void TDecCu::xFillPCMBuffer(TComDataCU* pCU, UInt depth)
1655{
1656  const ChromaFormat format = pCU->getPic()->getChromaFormat();
1657  const UInt numValidComp   = getNumberValidComponents(format);
1658  const UInt maxCuWidth     = pCU->getSlice()->getSPS()->getMaxCUWidth();
1659  const UInt maxCuHeight    = pCU->getSlice()->getSPS()->getMaxCUHeight();
1660
1661  for (UInt componentIndex = 0; componentIndex < numValidComp; componentIndex++)
1662  {
1663    const ComponentID component = ComponentID(componentIndex);
1664
1665    const UInt width  = maxCuWidth  >> (depth + getComponentScaleX(component, format));
1666    const UInt height = maxCuHeight >> (depth + getComponentScaleY(component, format));
1667
1668    Pel *source      = m_ppcYuvReco[depth]->getAddr(component, 0, width);
1669    Pel *destination = pCU->getPCMSample(component);
1670
1671    const UInt sourceStride = m_ppcYuvReco[depth]->getStride(component);
1672
1673    for (Int line = 0; line < height; line++)
1674    {
1675      for (Int column = 0; column < width; column++)
1676      {
1677        destination[column] = source[column];
1678      }
1679
1680      source      += sourceStride;
1681      destination += width;
1682    }
1683  }
1684}
1685
1686//! \}
Note: See TracBrowser for help on using the repository browser.