source: 3DVCSoftware/branches/HTM-13.1-dev1-Samsung/source/Lib/TLibDecoder/TDecCu.cpp @ 1147

Last change on this file since 1147 was 1147, checked in by samsung-htm, 9 years ago

Integration of K0035: Removal of encoder restriction of ARP

  • Property svn:eol-style set to native
File size: 59.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-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  Bool bValidMask = m_pcPrediction->getSegmentMaskFromDepth(pDepthPels, uiDepthStride, pcCU->getWidth(0), pcCU->getHeight(0), pMask);
957  AOF(bValidMask);
958 
959  DBBPTmpData* pDBBPTmpData = pcCU->getDBBPTmpData();
960  TComYuv* apSegPredYuv[2] = { m_ppcYuvReco[uiDepth], m_ppcYuvRecoDBBP[uiDepth] };
961 
962  // first, extract the two sets of motion parameters
963  UInt uiPUOffset = ( g_auiPUOffset[UInt( ePartSize )] << ( ( pcCU->getSlice()->getSPS()->getMaxCUDepth() - uiDepth ) << 1 ) ) >> 4;
964  for( UInt uiSegment = 0; uiSegment < 2; uiSegment++ )
965  {
966    UInt uiPartAddr = uiSegment*uiPUOffset;
967   
968    pDBBPTmpData->auhInterDir[uiSegment] = pcCU->getInterDir(uiPartAddr);
969   
970    for ( UInt uiRefListIdx = 0; uiRefListIdx < 2; uiRefListIdx++ )
971    {
972      RefPicList eRefList = (RefPicList)uiRefListIdx;
973      pcCU->getMvField(pcCU, uiPartAddr, eRefList, pDBBPTmpData->acMvField[uiSegment][eRefList]);
974    }
975   
976    AOF( pcCU->getARPW(uiPartAddr) == 0 );
977    AOF( pcCU->getICFlag(uiPartAddr) == false );
978    AOF( pcCU->getSPIVMPFlag(uiPartAddr) == false );
979    AOF( pcCU->getVSPFlag(uiPartAddr) == 0 );
980  }
981 
982  // do motion compensation for each segment as 2Nx2N
983  pcCU->setPartSizeSubParts( SIZE_2Nx2N, 0, uiDepth );
984  pcCU->setPredModeSubParts( MODE_INTER, 0, uiDepth );
985  for( UInt uiSegment = 0; uiSegment < 2; uiSegment++ )
986  {
987    pcCU->setInterDirSubParts( pDBBPTmpData->auhInterDir[uiSegment], 0, 0, uiDepth );
988 
989    for ( UInt uiRefListIdx = 0; uiRefListIdx < 2; uiRefListIdx++ )
990    {
991      RefPicList eRefList = (RefPicList)uiRefListIdx;
992
993      pcCU->getCUMvField( eRefList )->setAllMvField( pDBBPTmpData->acMvField[uiSegment][eRefList], SIZE_2Nx2N, 0, 0 );
994    }
995   
996    // inter prediction
997    m_pcPrediction->motionCompensation( pcCU, apSegPredYuv[uiSegment] );
998  }
999 
1000  // restore motion information in both segments again
1001  pcCU->setPartSizeSubParts( ePartSize,  0, uiDepth );
1002  pcCU->setPredModeSubParts( MODE_INTER, 0, uiDepth );
1003  for( UInt uiSegment = 0; uiSegment < 2; uiSegment++ )
1004  {
1005    UInt uiPartAddr = uiSegment*uiPUOffset;
1006   
1007    pcCU->setDBBPFlagSubParts(true, uiPartAddr, uiSegment, uiDepth);
1008    pcCU->setInterDirSubParts(pDBBPTmpData->auhInterDir[uiSegment], uiPartAddr, uiSegment, uiDepth); // interprets depth relative to LCU level
1009   
1010    for ( UInt uiRefListIdx = 0; uiRefListIdx < 2; uiRefListIdx++ )
1011    {
1012      RefPicList eRefList = (RefPicList)uiRefListIdx;
1013
1014      pcCU->getCUMvField( eRefList )->setAllMvField( pDBBPTmpData->acMvField[uiSegment][eRefList], ePartSize, uiPartAddr, 0, uiSegment ); // interprets depth relative to rpcTempCU level
1015    }
1016  }
1017 
1018  // reconstruct final prediction signal by combining both segments
1019  m_pcPrediction->combineSegmentsWithMask(apSegPredYuv, m_ppcYuvReco[uiDepth], pMask, pcCU->getWidth(0), pcCU->getHeight(0), 0, ePartSize);
1020
1021  // inter recon
1022  xDecodeInterTexture( pcCU, 0, uiDepth );
1023 
1024  // clip for only non-zero cbp case
1025  if  ( ( pcCU->getCbf( 0, TEXT_LUMA ) ) || ( pcCU->getCbf( 0, TEXT_CHROMA_U ) ) || ( pcCU->getCbf(0, TEXT_CHROMA_V ) ) )
1026  {
1027    m_ppcYuvReco[uiDepth]->addClip( m_ppcYuvReco[uiDepth], m_ppcYuvResi[uiDepth], 0, pcCU->getWidth( 0 ) );
1028  }
1029  else
1030  {
1031    m_ppcYuvReco[uiDepth]->copyPartToPartYuv( m_ppcYuvReco[uiDepth],0, pcCU->getWidth( 0 ),pcCU->getHeight( 0 ));
1032  }
1033}
1034#endif
1035
1036Void
1037TDecCu::xIntraRecLumaBlk( TComDataCU* pcCU,
1038                         UInt        uiTrDepth,
1039                         UInt        uiAbsPartIdx,
1040                         TComYuv*    pcRecoYuv,
1041                         TComYuv*    pcPredYuv, 
1042                         TComYuv*    pcResiYuv )
1043{
1044  UInt    uiWidth           = pcCU     ->getWidth   ( 0 ) >> uiTrDepth;
1045  UInt    uiHeight          = pcCU     ->getHeight  ( 0 ) >> uiTrDepth;
1046  UInt    uiStride          = pcRecoYuv->getStride  ();
1047  Pel*    piReco            = pcRecoYuv->getLumaAddr( uiAbsPartIdx );
1048  Pel*    piPred            = pcPredYuv->getLumaAddr( uiAbsPartIdx );
1049  Pel*    piResi            = pcResiYuv->getLumaAddr( uiAbsPartIdx );
1050 
1051  UInt    uiNumCoeffInc     = ( pcCU->getSlice()->getSPS()->getMaxCUWidth() * pcCU->getSlice()->getSPS()->getMaxCUHeight() ) >> ( pcCU->getSlice()->getSPS()->getMaxCUDepth() << 1 );
1052  TCoeff* pcCoeff           = pcCU->getCoeffY() + ( uiNumCoeffInc * uiAbsPartIdx );
1053 
1054  UInt    uiLumaPredMode    = pcCU->getLumaIntraDir     ( uiAbsPartIdx );
1055 
1056  UInt    uiZOrder          = pcCU->getZorderIdxInCU() + uiAbsPartIdx;
1057  Pel*    piRecIPred        = pcCU->getPic()->getPicYuvRec()->getLumaAddr( pcCU->getAddr(), uiZOrder );
1058  UInt    uiRecIPredStride  = pcCU->getPic()->getPicYuvRec()->getStride  ();
1059  Bool    useTransformSkip  = pcCU->getTransformSkip(uiAbsPartIdx, TEXT_LUMA);
1060  //===== init availability pattern =====
1061  Bool  bAboveAvail = false;
1062  Bool  bLeftAvail  = false;
1063  pcCU->getPattern()->initPattern   ( pcCU, uiTrDepth, uiAbsPartIdx );
1064  pcCU->getPattern()->initAdiPattern( pcCU, uiAbsPartIdx, uiTrDepth, 
1065                                     m_pcPrediction->getPredicBuf       (),
1066                                     m_pcPrediction->getPredicBufWidth  (),
1067                                     m_pcPrediction->getPredicBufHeight (),
1068                                     bAboveAvail, bLeftAvail );
1069 
1070  //===== get prediction signal =====
1071#if H_3D_DIM
1072  if( isDimMode( uiLumaPredMode ) )
1073  {
1074    m_pcPrediction->predIntraLumaDepth( pcCU, uiAbsPartIdx, uiLumaPredMode, piPred, uiStride, uiWidth, uiHeight );
1075  }
1076  else
1077  {
1078#endif
1079  m_pcPrediction->predIntraLumaAng( pcCU->getPattern(), uiLumaPredMode, piPred, uiStride, uiWidth, uiHeight, bAboveAvail, bLeftAvail );
1080#if H_3D_DIM
1081  }
1082#endif
1083 
1084#if H_3D
1085  Bool useDltFlag = (isDimMode( uiLumaPredMode ) || uiLumaPredMode == HOR_IDX || uiLumaPredMode == VER_IDX || uiLumaPredMode == DC_IDX) && pcCU->getSlice()->getIsDepth() && pcCU->getSlice()->getPPS()->getDLT()->getUseDLTFlag(pcCU->getSlice()->getLayerIdInVps());
1086
1087  if ( pcCU->getCbf( uiAbsPartIdx, TEXT_LUMA, uiTrDepth ) || useDltFlag )
1088#else
1089  if ( pcCU->getCbf( uiAbsPartIdx, TEXT_LUMA, uiTrDepth ) )
1090#endif
1091  {
1092  //===== inverse transform =====
1093  m_pcTrQuant->setQPforQuant  ( pcCU->getQP(0), TEXT_LUMA, pcCU->getSlice()->getSPS()->getQpBDOffsetY(), 0 );
1094
1095  Int scalingListType = (pcCU->isIntra(uiAbsPartIdx) ? 0 : 3) + g_eTTable[(Int)TEXT_LUMA];
1096    assert(scalingListType < SCALING_LIST_NUM);
1097  m_pcTrQuant->invtransformNxN( pcCU->getCUTransquantBypass(uiAbsPartIdx), TEXT_LUMA, pcCU->getLumaIntraDir( uiAbsPartIdx ), piResi, uiStride, pcCoeff, uiWidth, uiHeight, scalingListType, useTransformSkip );
1098
1099 
1100  //===== reconstruction =====
1101  Pel* pPred      = piPred;
1102  Pel* pResi      = piResi;
1103  Pel* pReco      = piReco;
1104  Pel* pRecIPred  = piRecIPred;
1105  for( UInt uiY = 0; uiY < uiHeight; uiY++ )
1106  {
1107    for( UInt uiX = 0; uiX < uiWidth; uiX++ )
1108    {
1109      pReco    [ uiX ] = ClipY( pPred[ uiX ] + pResi[ uiX ] );
1110      pRecIPred[ uiX ] = pReco[ uiX ];
1111    }
1112    pPred     += uiStride;
1113    pResi     += uiStride;
1114    pReco     += uiStride;
1115    pRecIPred += uiRecIPredStride;
1116  }
1117}
1118  else
1119  {
1120    //===== reconstruction =====
1121    Pel* pPred      = piPred;
1122    Pel* pReco      = piReco;
1123    Pel* pRecIPred  = piRecIPred;
1124    for ( Int y = 0; y < uiHeight; y++ )
1125    {
1126      for ( Int x = 0; x < uiWidth; x++ )
1127      {
1128        pReco    [ x ] = pPred[ x ];
1129        pRecIPred[ x ] = pReco[ x ];
1130      }
1131      pPred     += uiStride;
1132      pReco     += uiStride;
1133      pRecIPred += uiRecIPredStride;
1134    }
1135  }
1136}
1137
1138
1139Void
1140TDecCu::xIntraRecChromaBlk( TComDataCU* pcCU,
1141                           UInt        uiTrDepth,
1142                           UInt        uiAbsPartIdx,
1143                           TComYuv*    pcRecoYuv,
1144                           TComYuv*    pcPredYuv, 
1145                           TComYuv*    pcResiYuv,
1146                           UInt        uiChromaId )
1147{
1148  UInt uiFullDepth  = pcCU->getDepth( 0 ) + uiTrDepth;
1149  UInt uiLog2TrSize = g_aucConvertToBit[ pcCU->getSlice()->getSPS()->getMaxCUWidth() >> uiFullDepth ] + 2;
1150
1151  if( uiLog2TrSize == 2 )
1152  {
1153    assert( uiTrDepth > 0 );
1154    uiTrDepth--;
1155    UInt uiQPDiv = pcCU->getPic()->getNumPartInCU() >> ( ( pcCU->getDepth( 0 ) + uiTrDepth ) << 1 );
1156    Bool bFirstQ = ( ( uiAbsPartIdx % uiQPDiv ) == 0 );
1157    if( !bFirstQ )
1158    {
1159      return;
1160    }
1161  }
1162
1163  TextType  eText             = ( uiChromaId > 0 ? TEXT_CHROMA_V : TEXT_CHROMA_U );
1164  UInt      uiWidth           = pcCU     ->getWidth   ( 0 ) >> ( uiTrDepth + 1 );
1165  UInt      uiHeight          = pcCU     ->getHeight  ( 0 ) >> ( uiTrDepth + 1 );
1166  UInt      uiStride          = pcRecoYuv->getCStride ();
1167  Pel*      piReco            = ( uiChromaId > 0 ? pcRecoYuv->getCrAddr( uiAbsPartIdx ) : pcRecoYuv->getCbAddr( uiAbsPartIdx ) );
1168  Pel*      piPred            = ( uiChromaId > 0 ? pcPredYuv->getCrAddr( uiAbsPartIdx ) : pcPredYuv->getCbAddr( uiAbsPartIdx ) );
1169  Pel*      piResi            = ( uiChromaId > 0 ? pcResiYuv->getCrAddr( uiAbsPartIdx ) : pcResiYuv->getCbAddr( uiAbsPartIdx ) );
1170
1171  UInt      uiNumCoeffInc     = ( ( pcCU->getSlice()->getSPS()->getMaxCUWidth() * pcCU->getSlice()->getSPS()->getMaxCUHeight() ) >> ( pcCU->getSlice()->getSPS()->getMaxCUDepth() << 1 ) ) >> 2;
1172  TCoeff*   pcCoeff           = ( uiChromaId > 0 ? pcCU->getCoeffCr() : pcCU->getCoeffCb() ) + ( uiNumCoeffInc * uiAbsPartIdx );
1173
1174  UInt      uiChromaPredMode  = pcCU->getChromaIntraDir( 0 );
1175
1176  UInt      uiZOrder          = pcCU->getZorderIdxInCU() + uiAbsPartIdx;
1177  Pel*      piRecIPred        = ( uiChromaId > 0 ? pcCU->getPic()->getPicYuvRec()->getCrAddr( pcCU->getAddr(), uiZOrder ) : pcCU->getPic()->getPicYuvRec()->getCbAddr( pcCU->getAddr(), uiZOrder ) );
1178  UInt      uiRecIPredStride  = pcCU->getPic()->getPicYuvRec()->getCStride();
1179  Bool      useTransformSkipChroma = pcCU->getTransformSkip(uiAbsPartIdx,eText);
1180  //===== init availability pattern =====
1181  Bool  bAboveAvail = false;
1182  Bool  bLeftAvail  = false;
1183  pcCU->getPattern()->initPattern         ( pcCU, uiTrDepth, uiAbsPartIdx );
1184
1185  pcCU->getPattern()->initAdiPatternChroma( pcCU, uiAbsPartIdx, uiTrDepth,
1186    m_pcPrediction->getPredicBuf       (),
1187    m_pcPrediction->getPredicBufWidth  (),
1188    m_pcPrediction->getPredicBufHeight (),
1189    bAboveAvail, bLeftAvail );
1190  Int* pPatChroma   = ( uiChromaId > 0 ? pcCU->getPattern()->getAdiCrBuf( uiWidth, uiHeight, m_pcPrediction->getPredicBuf() ) : pcCU->getPattern()->getAdiCbBuf( uiWidth, uiHeight, m_pcPrediction->getPredicBuf() ) );
1191
1192  //===== get prediction signal =====
1193  {
1194    if( uiChromaPredMode == DM_CHROMA_IDX )
1195    {
1196      uiChromaPredMode = pcCU->getLumaIntraDir( 0 );
1197#if H_3D_DIM
1198      mapDepthModeToIntraDir( uiChromaPredMode );
1199#endif
1200    }
1201    m_pcPrediction->predIntraChromaAng( pPatChroma, uiChromaPredMode, piPred, uiStride, uiWidth, uiHeight, bAboveAvail, bLeftAvail ); 
1202  }
1203
1204  if ( pcCU->getCbf( uiAbsPartIdx, eText, uiTrDepth ) )
1205  {
1206    //===== inverse transform =====
1207    Int curChromaQpOffset;
1208    if(eText == TEXT_CHROMA_U)
1209    {
1210      curChromaQpOffset = pcCU->getSlice()->getPPS()->getChromaCbQpOffset() + pcCU->getSlice()->getSliceQpDeltaCb();
1211    }
1212    else
1213    {
1214      curChromaQpOffset = pcCU->getSlice()->getPPS()->getChromaCrQpOffset() + pcCU->getSlice()->getSliceQpDeltaCr();
1215    }
1216    m_pcTrQuant->setQPforQuant  ( pcCU->getQP(0), eText, pcCU->getSlice()->getSPS()->getQpBDOffsetC(), curChromaQpOffset );
1217
1218    Int scalingListType = (pcCU->isIntra(uiAbsPartIdx) ? 0 : 3) + g_eTTable[(Int)eText];
1219    assert(scalingListType < SCALING_LIST_NUM);
1220    m_pcTrQuant->invtransformNxN( pcCU->getCUTransquantBypass(uiAbsPartIdx), eText, REG_DCT, piResi, uiStride, pcCoeff, uiWidth, uiHeight, scalingListType, useTransformSkipChroma );
1221
1222    //===== reconstruction =====
1223    Pel* pPred      = piPred;
1224    Pel* pResi      = piResi;
1225    Pel* pReco      = piReco;
1226    Pel* pRecIPred  = piRecIPred;
1227    for( UInt uiY = 0; uiY < uiHeight; uiY++ )
1228    {
1229      for( UInt uiX = 0; uiX < uiWidth; uiX++ )
1230      {
1231        pReco    [ uiX ] = ClipC( pPred[ uiX ] + pResi[ uiX ] );
1232        pRecIPred[ uiX ] = pReco[ uiX ];
1233      }
1234      pPred     += uiStride;
1235      pResi     += uiStride;
1236      pReco     += uiStride;
1237      pRecIPred += uiRecIPredStride;
1238    }
1239  }
1240  else
1241  {
1242    //===== reconstruction =====
1243    Pel* pPred      = piPred;
1244    Pel* pReco      = piReco;
1245    Pel* pRecIPred  = piRecIPred;
1246    for ( Int y = 0; y < uiHeight; y++ )
1247    {
1248      for ( Int x = 0; x < uiWidth; x++ )
1249      {
1250        pReco    [ x ] = pPred[ x ];
1251        pRecIPred[ x ] = pReco[ x ];
1252      }
1253      pPred     += uiStride;
1254      pReco     += uiStride;
1255      pRecIPred += uiRecIPredStride;
1256    }   
1257  }
1258}
1259
1260
1261Void
1262TDecCu::xReconIntraQT( TComDataCU* pcCU, UInt uiDepth )
1263{
1264  UInt  uiInitTrDepth = ( pcCU->getPartitionSize(0) == SIZE_2Nx2N ? 0 : 1 );
1265  UInt  uiNumPart     = pcCU->getNumPartitions();
1266  UInt  uiNumQParts   = pcCU->getTotalNumPart() >> 2;
1267 
1268  if (pcCU->getIPCMFlag(0))
1269  {
1270    xReconPCM( pcCU, uiDepth );
1271    return;
1272  }
1273
1274  for( UInt uiPU = 0; uiPU < uiNumPart; uiPU++ )
1275  {
1276    xIntraLumaRecQT( pcCU, uiInitTrDepth, uiPU * uiNumQParts, m_ppcYuvReco[uiDepth], m_ppcYuvReco[uiDepth], m_ppcYuvResi[uiDepth] );
1277  } 
1278
1279  for( UInt uiPU = 0; uiPU < uiNumPart; uiPU++ )
1280  {
1281    xIntraChromaRecQT( pcCU, uiInitTrDepth, uiPU * uiNumQParts, m_ppcYuvReco[uiDepth], m_ppcYuvReco[uiDepth], m_ppcYuvResi[uiDepth] );
1282  }
1283
1284}
1285
1286#if H_3D_DIM_SDC
1287Void TDecCu::xReconIntraSDC( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
1288{
1289  UInt uiWidth        = pcCU->getWidth  ( 0 );
1290  UInt uiHeight       = pcCU->getHeight ( 0 );
1291  TComWedgelet* dmm4SegmentationOrg = new TComWedgelet( uiWidth, uiHeight );
1292  UInt numParts = 1;
1293  UInt sdcDepth    = 0;
1294  TComYuv* pcRecoYuv  = m_ppcYuvReco[uiDepth];
1295  TComYuv* pcPredYuv  = m_ppcYuvReco[uiDepth];
1296  TComYuv* pcResiYuv  = m_ppcYuvResi[uiDepth];
1297
1298  UInt    uiStride = 0;
1299  Pel*    piReco;
1300  Pel*    piPred;
1301  Pel*    piResi;
1302
1303  UInt    uiZOrder;       
1304  Pel*    piRecIPred;     
1305  UInt    uiRecIPredStride;
1306
1307  UInt    uiLumaPredMode = 0; 
1308
1309  if ((uiWidth >> pcCU->getSlice()->getSPS()->getQuadtreeTULog2MaxSize()) > 1)
1310  {
1311    numParts = uiWidth * uiWidth >> (2 * pcCU->getSlice()->getSPS()->getQuadtreeTULog2MaxSize());
1312    sdcDepth = g_aucConvertToBit[uiWidth] + 2 - pcCU->getSlice()->getSPS()->getQuadtreeTULog2MaxSize();
1313    uiWidth = uiHeight = (1 << pcCU->getSlice()->getSPS()->getQuadtreeTULog2MaxSize());
1314  }
1315
1316  for ( Int i = 0; i < numParts; i++ )
1317  {
1318    uiStride    = pcRecoYuv->getStride  ();
1319    piReco      = pcRecoYuv->getLumaAddr( uiAbsPartIdx );
1320    piPred      = pcPredYuv->getLumaAddr( uiAbsPartIdx );
1321    piResi      = pcResiYuv->getLumaAddr( uiAbsPartIdx );
1322
1323    uiZOrder          = pcCU->getZorderIdxInCU() + uiAbsPartIdx;
1324    piRecIPred        = pcCU->getPic()->getPicYuvRec()->getLumaAddr( pcCU->getAddr(), uiZOrder );
1325    uiRecIPredStride  = pcCU->getPic()->getPicYuvRec()->getStride  ();
1326
1327    uiLumaPredMode    = pcCU->getLumaIntraDir     ( uiAbsPartIdx );
1328
1329    AOF( uiWidth == uiHeight );
1330
1331    //===== init availability pattern =====
1332    Bool  bAboveAvail = false;
1333    Bool  bLeftAvail  = false;
1334
1335    pcCU->getPattern()->initPattern   ( pcCU, sdcDepth, uiAbsPartIdx );
1336    pcCU->getPattern()->initAdiPattern( pcCU, uiAbsPartIdx, sdcDepth, m_pcPrediction->getPredicBuf(), m_pcPrediction->getPredicBufWidth(), m_pcPrediction->getPredicBufHeight(), bAboveAvail, bLeftAvail );
1337
1338    TComWedgelet* dmm4Segmentation = new TComWedgelet( uiWidth, uiHeight );
1339    //===== get prediction signal =====
1340    if( isDimMode( uiLumaPredMode ) )
1341    {
1342      m_pcPrediction->predIntraLumaDepth( pcCU, uiAbsPartIdx, uiLumaPredMode, piPred, uiStride, uiWidth, uiHeight, false, dmm4Segmentation  );
1343      Bool* dmm4PatternSplit = dmm4Segmentation->getPattern();
1344      Bool* dmm4PatternOrg = dmm4SegmentationOrg->getPattern();
1345      for( UInt k = 0; k < (uiWidth*uiHeight); k++ ) 
1346      { 
1347        dmm4PatternOrg[k+(uiAbsPartIdx<<4)] = dmm4PatternSplit[k];
1348      }
1349    }
1350    else
1351    {
1352      m_pcPrediction->predIntraLumaAng( pcCU->getPattern(), uiLumaPredMode, piPred, uiStride, uiWidth, uiHeight, bAboveAvail, bLeftAvail );
1353    }
1354
1355    if ( numParts > 1 )
1356    {
1357      for( UInt uiY = 0; uiY < uiHeight; uiY++ )
1358      {
1359        for( UInt uiX = 0; uiX < uiWidth; uiX++ )
1360        {
1361          piReco        [ uiX ] = ClipY( piPred[ uiX ] );
1362          piRecIPred    [ uiX ] = piReco[ uiX ];
1363        }
1364        piPred     += uiStride;
1365        piReco     += uiStride;
1366        piRecIPred += uiRecIPredStride;
1367      }
1368    }
1369    uiAbsPartIdx += ( (uiWidth * uiWidth) >> 4 );
1370    dmm4Segmentation->destroy(); delete dmm4Segmentation;
1371  }
1372  uiAbsPartIdx = 0;
1373 
1374  if ( numParts > 1 )
1375  {
1376    uiWidth = pcCU->getWidth( 0 );
1377    uiHeight = pcCU->getHeight( 0 );
1378  }
1379  piReco      = pcRecoYuv->getLumaAddr( uiAbsPartIdx );
1380  piPred      = pcPredYuv->getLumaAddr( uiAbsPartIdx );
1381  piResi      = pcResiYuv->getLumaAddr( uiAbsPartIdx );
1382  uiZOrder          = pcCU->getZorderIdxInCU() + uiAbsPartIdx;
1383  piRecIPred        = pcCU->getPic()->getPicYuvRec()->getLumaAddr( pcCU->getAddr(), uiZOrder );
1384  uiRecIPredStride  = pcCU->getPic()->getPicYuvRec()->getStride  ();
1385  // number of segments depends on prediction mode
1386  UInt uiNumSegments = 1;
1387  Bool* pbMask = NULL;
1388  UInt uiMaskStride = 0;
1389 
1390  if( getDimType( uiLumaPredMode ) == DMM1_IDX )
1391  {
1392    Int uiTabIdx = pcCU->getDmmWedgeTabIdx(DMM1_IDX, uiAbsPartIdx);
1393
1394    WedgeList* pacWedgeList  = pcCU->isDMM1UpscaleMode(uiWidth) ? &g_dmmWedgeLists[(g_aucConvertToBit[pcCU->getDMM1BasePatternWidth(uiWidth)])] :  &g_dmmWedgeLists[(g_aucConvertToBit[uiWidth])];
1395    TComWedgelet* pcWedgelet = &(pacWedgeList->at( uiTabIdx ));
1396
1397    uiNumSegments = 2;
1398
1399    pbMask       = pcCU->isDMM1UpscaleMode( uiWidth ) ? pcWedgelet->getScaledPattern(uiWidth) : pcWedgelet->getPattern();
1400    uiMaskStride = pcCU->isDMM1UpscaleMode( uiWidth ) ? uiWidth : pcWedgelet->getStride();
1401  }
1402  if( getDimType( uiLumaPredMode ) == DMM4_IDX )
1403  {
1404    uiNumSegments = 2;
1405    pbMask  = dmm4SegmentationOrg->getPattern();
1406    uiMaskStride = dmm4SegmentationOrg->getStride();
1407  }
1408  // get DC prediction for each segment
1409  Pel apDCPredValues[2];
1410  if ( getDimType( uiLumaPredMode ) == DMM1_IDX || getDimType( uiLumaPredMode ) == DMM4_IDX )
1411  {
1412    apDCPredValues[0] = pcCU->getDmmPredictor( 0 );
1413    apDCPredValues[1] = pcCU->getDmmPredictor( 1 );
1414  }
1415  else
1416  {
1417    m_pcPrediction->analyzeSegmentsSDC(piPred, uiStride, uiWidth, apDCPredValues, uiNumSegments, pbMask, uiMaskStride, uiLumaPredMode);
1418  }
1419 
1420  // reconstruct residual based on mask + DC residuals
1421  Pel apDCResiValues[2];
1422  for( UInt uiSegment = 0; uiSegment < uiNumSegments; uiSegment++ )
1423  {
1424#if H_3D_DIM_DLT
1425    Pel   pPredIdx    = pcCU->getSlice()->getPPS()->getDLT()->depthValue2idx( pcCU->getSlice()->getLayerIdInVps(), apDCPredValues[uiSegment] );
1426    Pel   pResiIdx    = pcCU->getSDCSegmentDCOffset(uiSegment, uiAbsPartIdx);
1427    Pel   pRecoValue  = pcCU->getSlice()->getPPS()->getDLT()->idx2DepthValue( pcCU->getSlice()->getLayerIdInVps(), pPredIdx + pResiIdx );
1428
1429    apDCResiValues[uiSegment]  = pRecoValue - apDCPredValues[uiSegment];
1430#else
1431    apDCResiValues[uiSegment]  = pcCU->getSDCSegmentDCOffset(uiSegment, uiAbsPartIdx);
1432#endif
1433  }
1434 
1435  //===== reconstruction =====
1436  Bool*pMask      = pbMask;
1437  Pel* pPred      = piPred;
1438  Pel* pResi      = piResi;
1439  Pel* pReco      = piReco;
1440  Pel* pRecIPred  = piRecIPred;
1441 
1442  for( UInt uiY = 0; uiY < uiHeight; uiY++ )
1443  {
1444    for( UInt uiX = 0; uiX < uiWidth; uiX++ )
1445    {
1446      UChar ucSegment = pMask?(UChar)pMask[uiX]:0;
1447      assert( ucSegment < uiNumSegments );
1448     
1449      Pel pResiDC = apDCResiValues[ucSegment];
1450     
1451      pReco    [ uiX ] = ClipY( pPred[ uiX ] + pResiDC );
1452      pRecIPred[ uiX ] = pReco[ uiX ];
1453    }
1454    pPred     += uiStride;
1455    pResi     += uiStride;
1456    pReco     += uiStride;
1457    pRecIPred += uiRecIPredStride;
1458    pMask     += uiMaskStride;
1459  }
1460 
1461  // clear UV
1462  UInt  uiStrideC     = pcPredYuv->getCStride();
1463  Pel   *pRecCb       = pcPredYuv->getCbAddr();
1464  Pel   *pRecCr       = pcPredYuv->getCrAddr();
1465 
1466  for (Int y=0; y<uiHeight/2; y++)
1467  {
1468    for (Int x=0; x<uiWidth/2; x++)
1469    {
1470      pRecCb[x] = 128;
1471      pRecCr[x] = 128;
1472    }
1473   
1474    pRecCb += uiStrideC;
1475    pRecCr += uiStrideC;
1476  }
1477  dmm4SegmentationOrg->destroy(); delete dmm4SegmentationOrg;
1478}
1479#endif
1480
1481/** Function for deriving recontructed PU/CU Luma sample with QTree structure
1482 * \param pcCU pointer of current CU
1483 * \param uiTrDepth current tranform split depth
1484 * \param uiAbsPartIdx  part index
1485 * \param pcRecoYuv pointer to reconstructed sample arrays
1486 * \param pcPredYuv pointer to prediction sample arrays
1487 * \param pcResiYuv pointer to residue sample arrays
1488 *
1489 \ This function dervies recontructed PU/CU Luma sample with recursive QTree structure
1490 */
1491Void
1492TDecCu::xIntraLumaRecQT( TComDataCU* pcCU,
1493                     UInt        uiTrDepth,
1494                     UInt        uiAbsPartIdx,
1495                     TComYuv*    pcRecoYuv,
1496                     TComYuv*    pcPredYuv, 
1497                     TComYuv*    pcResiYuv )
1498{
1499  UInt uiFullDepth  = pcCU->getDepth(0) + uiTrDepth;
1500  UInt uiTrMode     = pcCU->getTransformIdx( uiAbsPartIdx );
1501  if( uiTrMode == uiTrDepth )
1502  {
1503    xIntraRecLumaBlk  ( pcCU, uiTrDepth, uiAbsPartIdx, pcRecoYuv, pcPredYuv, pcResiYuv );
1504  }
1505  else
1506  {
1507    UInt uiNumQPart  = pcCU->getPic()->getNumPartInCU() >> ( ( uiFullDepth + 1 ) << 1 );
1508    for( UInt uiPart = 0; uiPart < 4; uiPart++ )
1509    {
1510      xIntraLumaRecQT( pcCU, uiTrDepth + 1, uiAbsPartIdx + uiPart * uiNumQPart, pcRecoYuv, pcPredYuv, pcResiYuv );
1511    }
1512  }
1513}
1514
1515/** Function for deriving recontructed PU/CU chroma samples with QTree structure
1516 * \param pcCU pointer of current CU
1517 * \param uiTrDepth current tranform split depth
1518 * \param uiAbsPartIdx  part index
1519 * \param pcRecoYuv pointer to reconstructed sample arrays
1520 * \param pcPredYuv pointer to prediction sample arrays
1521 * \param pcResiYuv pointer to residue sample arrays
1522 *
1523 \ This function dervies recontructed PU/CU chroma samples with QTree recursive structure
1524 */
1525Void
1526TDecCu::xIntraChromaRecQT( TComDataCU* pcCU,
1527                     UInt        uiTrDepth,
1528                     UInt        uiAbsPartIdx,
1529                     TComYuv*    pcRecoYuv,
1530                     TComYuv*    pcPredYuv, 
1531                     TComYuv*    pcResiYuv )
1532{
1533  UInt uiFullDepth  = pcCU->getDepth(0) + uiTrDepth;
1534  UInt uiTrMode     = pcCU->getTransformIdx( uiAbsPartIdx );
1535  if( uiTrMode == uiTrDepth )
1536  {
1537    xIntraRecChromaBlk( pcCU, uiTrDepth, uiAbsPartIdx, pcRecoYuv, pcPredYuv, pcResiYuv, 0 );
1538    xIntraRecChromaBlk( pcCU, uiTrDepth, uiAbsPartIdx, pcRecoYuv, pcPredYuv, pcResiYuv, 1 );
1539  }
1540  else
1541  {
1542    UInt uiNumQPart  = pcCU->getPic()->getNumPartInCU() >> ( ( uiFullDepth + 1 ) << 1 );
1543    for( UInt uiPart = 0; uiPart < 4; uiPart++ )
1544    {
1545      xIntraChromaRecQT( pcCU, uiTrDepth + 1, uiAbsPartIdx + uiPart * uiNumQPart, pcRecoYuv, pcPredYuv, pcResiYuv );
1546    }
1547  }
1548}
1549
1550Void TDecCu::xCopyToPic( TComDataCU* pcCU, TComPic* pcPic, UInt uiZorderIdx, UInt uiDepth )
1551{
1552  UInt uiCUAddr = pcCU->getAddr();
1553 
1554  m_ppcYuvReco[uiDepth]->copyToPicYuv  ( pcPic->getPicYuvRec (), uiCUAddr, uiZorderIdx );
1555 
1556  return;
1557}
1558
1559Void TDecCu::xDecodeInterTexture ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
1560{
1561  UInt    uiWidth    = pcCU->getWidth ( uiAbsPartIdx );
1562  UInt    uiHeight   = pcCU->getHeight( uiAbsPartIdx );
1563  TCoeff* piCoeff;
1564 
1565  Pel*    pResi;
1566  UInt    trMode = pcCU->getTransformIdx( uiAbsPartIdx );
1567 
1568  // Y
1569  piCoeff = pcCU->getCoeffY();
1570  pResi = m_ppcYuvResi[uiDepth]->getLumaAddr();
1571
1572  m_pcTrQuant->setQPforQuant( pcCU->getQP( uiAbsPartIdx ), TEXT_LUMA, pcCU->getSlice()->getSPS()->getQpBDOffsetY(), 0 );
1573
1574  m_pcTrQuant->invRecurTransformNxN ( pcCU, 0, TEXT_LUMA, pResi, 0, m_ppcYuvResi[uiDepth]->getStride(), uiWidth, uiHeight, trMode, 0, piCoeff );
1575 
1576  // Cb and Cr
1577  Int curChromaQpOffset = pcCU->getSlice()->getPPS()->getChromaCbQpOffset() + pcCU->getSlice()->getSliceQpDeltaCb();
1578  m_pcTrQuant->setQPforQuant( pcCU->getQP( uiAbsPartIdx ), TEXT_CHROMA, pcCU->getSlice()->getSPS()->getQpBDOffsetC(), curChromaQpOffset );
1579
1580  uiWidth  >>= 1;
1581  uiHeight >>= 1;
1582  piCoeff = pcCU->getCoeffCb(); pResi = m_ppcYuvResi[uiDepth]->getCbAddr();
1583  m_pcTrQuant->invRecurTransformNxN ( pcCU, 0, TEXT_CHROMA_U, pResi, 0, m_ppcYuvResi[uiDepth]->getCStride(), uiWidth, uiHeight, trMode, 0, piCoeff );
1584
1585  curChromaQpOffset = pcCU->getSlice()->getPPS()->getChromaCrQpOffset() + pcCU->getSlice()->getSliceQpDeltaCr();
1586  m_pcTrQuant->setQPforQuant( pcCU->getQP( uiAbsPartIdx ), TEXT_CHROMA, pcCU->getSlice()->getSPS()->getQpBDOffsetC(), curChromaQpOffset );
1587
1588  piCoeff = pcCU->getCoeffCr(); pResi = m_ppcYuvResi[uiDepth]->getCrAddr();
1589  m_pcTrQuant->invRecurTransformNxN ( pcCU, 0, TEXT_CHROMA_V, pResi, 0, m_ppcYuvResi[uiDepth]->getCStride(), uiWidth, uiHeight, trMode, 0, piCoeff );
1590}
1591
1592/** Function for deriving reconstructed luma/chroma samples of a PCM mode CU.
1593 * \param pcCU pointer to current CU
1594 * \param uiPartIdx part index
1595 * \param piPCM pointer to PCM code arrays
1596 * \param piReco pointer to reconstructed sample arrays
1597 * \param uiStride stride of reconstructed sample arrays
1598 * \param uiWidth CU width
1599 * \param uiHeight CU height
1600 * \param ttText texture component type
1601 * \returns Void
1602 */
1603Void TDecCu::xDecodePCMTexture( TComDataCU* pcCU, UInt uiPartIdx, Pel *piPCM, Pel* piReco, UInt uiStride, UInt uiWidth, UInt uiHeight, TextType ttText)
1604{
1605  UInt uiX, uiY;
1606  Pel* piPicReco;
1607  UInt uiPicStride;
1608  UInt uiPcmLeftShiftBit; 
1609
1610  if( ttText == TEXT_LUMA )
1611  {
1612    uiPicStride   = pcCU->getPic()->getPicYuvRec()->getStride();
1613    piPicReco = pcCU->getPic()->getPicYuvRec()->getLumaAddr(pcCU->getAddr(), pcCU->getZorderIdxInCU()+uiPartIdx);
1614    uiPcmLeftShiftBit = g_bitDepthY - pcCU->getSlice()->getSPS()->getPCMBitDepthLuma();
1615  }
1616  else
1617  {
1618    uiPicStride = pcCU->getPic()->getPicYuvRec()->getCStride();
1619
1620    if( ttText == TEXT_CHROMA_U )
1621    {
1622      piPicReco = pcCU->getPic()->getPicYuvRec()->getCbAddr(pcCU->getAddr(), pcCU->getZorderIdxInCU()+uiPartIdx);
1623    }
1624    else
1625    {
1626      piPicReco = pcCU->getPic()->getPicYuvRec()->getCrAddr(pcCU->getAddr(), pcCU->getZorderIdxInCU()+uiPartIdx);
1627    }
1628    uiPcmLeftShiftBit = g_bitDepthC - pcCU->getSlice()->getSPS()->getPCMBitDepthChroma();
1629  }
1630
1631  for( uiY = 0; uiY < uiHeight; uiY++ )
1632  {
1633    for( uiX = 0; uiX < uiWidth; uiX++ )
1634    {
1635      piReco[uiX] = (piPCM[uiX] << uiPcmLeftShiftBit);
1636      piPicReco[uiX] = piReco[uiX];
1637    }
1638    piPCM += uiWidth;
1639    piReco += uiStride;
1640    piPicReco += uiPicStride;
1641  }
1642}
1643
1644/** Function for reconstructing a PCM mode CU.
1645 * \param pcCU pointer to current CU
1646 * \param uiDepth CU Depth
1647 * \returns Void
1648 */
1649Void TDecCu::xReconPCM( TComDataCU* pcCU, UInt uiDepth )
1650{
1651  // Luma
1652  UInt uiWidth  = (g_uiMaxCUWidth >> uiDepth);
1653  UInt uiHeight = (g_uiMaxCUHeight >> uiDepth);
1654
1655  Pel* piPcmY = pcCU->getPCMSampleY();
1656  Pel* piRecoY = m_ppcYuvReco[uiDepth]->getLumaAddr(0, uiWidth);
1657
1658  UInt uiStride = m_ppcYuvResi[uiDepth]->getStride();
1659
1660  xDecodePCMTexture( pcCU, 0, piPcmY, piRecoY, uiStride, uiWidth, uiHeight, TEXT_LUMA);
1661
1662  // Cb and Cr
1663  UInt uiCWidth  = (uiWidth>>1);
1664  UInt uiCHeight = (uiHeight>>1);
1665
1666  Pel* piPcmCb = pcCU->getPCMSampleCb();
1667  Pel* piPcmCr = pcCU->getPCMSampleCr();
1668  Pel* pRecoCb = m_ppcYuvReco[uiDepth]->getCbAddr();
1669  Pel* pRecoCr = m_ppcYuvReco[uiDepth]->getCrAddr();
1670
1671  UInt uiCStride = m_ppcYuvReco[uiDepth]->getCStride();
1672
1673  xDecodePCMTexture( pcCU, 0, piPcmCb, pRecoCb, uiCStride, uiCWidth, uiCHeight, TEXT_CHROMA_U);
1674  xDecodePCMTexture( pcCU, 0, piPcmCr, pRecoCr, uiCStride, uiCWidth, uiCHeight, TEXT_CHROMA_V);
1675}
1676
1677/** Function for filling the PCM buffer of a CU using its reconstructed sample array
1678 * \param pcCU pointer to current CU
1679 * \param uiDepth CU Depth
1680 * \returns Void
1681 */
1682Void TDecCu::xFillPCMBuffer(TComDataCU* pCU, UInt depth)
1683{
1684  // Luma
1685  UInt width  = (g_uiMaxCUWidth >> depth);
1686  UInt height = (g_uiMaxCUHeight >> depth);
1687
1688  Pel* pPcmY = pCU->getPCMSampleY();
1689  Pel* pRecoY = m_ppcYuvReco[depth]->getLumaAddr(0, width);
1690
1691  UInt stride = m_ppcYuvReco[depth]->getStride();
1692
1693  for(Int y = 0; y < height; y++ )
1694  {
1695    for(Int x = 0; x < width; x++ )
1696    {
1697      pPcmY[x] = pRecoY[x];
1698    }
1699    pPcmY += width;
1700    pRecoY += stride;
1701  }
1702
1703  // Cb and Cr
1704  UInt widthC  = (width>>1);
1705  UInt heightC = (height>>1);
1706
1707  Pel* pPcmCb = pCU->getPCMSampleCb();
1708  Pel* pPcmCr = pCU->getPCMSampleCr();
1709  Pel* pRecoCb = m_ppcYuvReco[depth]->getCbAddr();
1710  Pel* pRecoCr = m_ppcYuvReco[depth]->getCrAddr();
1711
1712  UInt strideC = m_ppcYuvReco[depth]->getCStride();
1713
1714  for(Int y = 0; y < heightC; y++ )
1715  {
1716    for(Int x = 0; x < widthC; x++ )
1717    {
1718      pPcmCb[x] = pRecoCb[x];
1719      pPcmCr[x] = pRecoCr[x];
1720    }
1721    pPcmCr += widthC;
1722    pPcmCb += widthC;
1723    pRecoCb += strideC;
1724    pRecoCr += strideC;
1725  }
1726
1727}
1728
1729//! \}
Note: See TracBrowser for help on using the repository browser.