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

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

Integration of K0033: Depth intra skip (DIS) mode

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