source: 3DVCSoftware/branches/HTM-13.1-dev0/source/Lib/TLibDecoder/TDecCu.cpp @ 1164

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

Merged 13.1-dev2-Sony

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