source: 3DVCSoftware/branches/HTM-12.2-dev2-HHI/source/Lib/TLibDecoder/TDecCu.cpp @ 1106

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