source: 3DVCSoftware/branches/HTM-12.2-dev0/source/Lib/TLibDecoder/TDecCu.cpp @ 1118

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

Merged 12.2-dev1-Hisilicon@1116.

  • Property svn:eol-style set to native
File size: 57.9 KB
Line 
1/* The copyright in this software is being made available under the BSD
2 * License, included below. This software may be subject to other third party
3 * and contributor rights, including patent rights, and no such rights are
4 * granted under this license. 
5 *
6* Copyright (c) 2010-2014, ITU/ISO/IEC
7 * All rights reserved.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions are met:
11 *
12 *  * Redistributions of source code must retain the above copyright notice,
13 *    this list of conditions and the following disclaimer.
14 *  * Redistributions in binary form must reproduce the above copyright notice,
15 *    this list of conditions and the following disclaimer in the documentation
16 *    and/or other materials provided with the distribution.
17 *  * Neither the name of the ITU/ISO/IEC nor the names of its contributors may
18 *    be used to endorse or promote products derived from this software without
19 *    specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS
25 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
31 * THE POSSIBILITY OF SUCH DAMAGE.
32 */
33
34/** \file     TDecCu.cpp
35    \brief    CU decoder class
36*/
37
38#include "TDecCu.h"
39
40//! \ingroup TLibDecoder
41//! \{
42
43// ====================================================================================================================
44// Constructor / destructor / create / destroy
45// ====================================================================================================================
46
47TDecCu::TDecCu()
48{
49  m_ppcYuvResi = NULL;
50  m_ppcYuvReco = NULL;
51  m_ppcCU      = NULL;
52#if H_3D_DBBP
53  m_ppcYuvRecoDBBP = NULL;
54#endif
55}
56
57TDecCu::~TDecCu()
58{
59}
60
61Void TDecCu::init( TDecEntropy* pcEntropyDecoder, TComTrQuant* pcTrQuant, TComPrediction* pcPrediction)
62{
63  m_pcEntropyDecoder  = pcEntropyDecoder;
64  m_pcTrQuant         = pcTrQuant;
65  m_pcPrediction      = pcPrediction;
66}
67
68/**
69 \param    uiMaxDepth    total number of allowable depth
70 \param    uiMaxWidth    largest CU width
71 \param    uiMaxHeight   largest CU height
72 */
73Void TDecCu::create( UInt uiMaxDepth, UInt uiMaxWidth, UInt uiMaxHeight )
74{
75  m_uiMaxDepth = uiMaxDepth+1;
76 
77  m_ppcYuvResi = new TComYuv*[m_uiMaxDepth-1];
78  m_ppcYuvReco = new TComYuv*[m_uiMaxDepth-1];
79  m_ppcCU      = new TComDataCU*[m_uiMaxDepth-1];
80#if H_3D_DBBP
81  m_ppcYuvRecoDBBP = new TComYuv*[m_uiMaxDepth-1];
82#endif
83 
84  UInt uiNumPartitions;
85  for ( UInt ui = 0; ui < m_uiMaxDepth-1; ui++ )
86  {
87    uiNumPartitions = 1<<( ( m_uiMaxDepth - ui - 1 )<<1 );
88    UInt uiWidth  = uiMaxWidth  >> ui;
89    UInt uiHeight = uiMaxHeight >> ui;
90   
91    m_ppcYuvResi[ui] = new TComYuv;    m_ppcYuvResi[ui]->create( uiWidth, uiHeight );
92    m_ppcYuvReco[ui] = new TComYuv;    m_ppcYuvReco[ui]->create( uiWidth, uiHeight );
93    m_ppcCU     [ui] = new TComDataCU; m_ppcCU     [ui]->create( uiNumPartitions, uiWidth, uiHeight, true, uiMaxWidth >> (m_uiMaxDepth - 1) );
94#if H_3D_DBBP
95    m_ppcYuvRecoDBBP[ui] = new TComYuv;    m_ppcYuvRecoDBBP[ui]->create( uiWidth, uiHeight );
96#endif
97  }
98 
99  m_bDecodeDQP = false;
100
101  // initialize partition order.
102  UInt* piTmp = &g_auiZscanToRaster[0];
103  initZscanToRaster(m_uiMaxDepth, 1, 0, piTmp);
104  initRasterToZscan( uiMaxWidth, uiMaxHeight, m_uiMaxDepth );
105 
106  // initialize conversion matrix from partition index to pel
107  initRasterToPelXY( uiMaxWidth, uiMaxHeight, m_uiMaxDepth );
108}
109
110Void TDecCu::destroy()
111{
112  for ( UInt ui = 0; ui < m_uiMaxDepth-1; ui++ )
113  {
114    m_ppcYuvResi[ui]->destroy(); delete m_ppcYuvResi[ui]; m_ppcYuvResi[ui] = NULL;
115    m_ppcYuvReco[ui]->destroy(); delete m_ppcYuvReco[ui]; m_ppcYuvReco[ui] = NULL;
116    m_ppcCU     [ui]->destroy(); delete m_ppcCU     [ui]; m_ppcCU     [ui] = NULL;
117#if H_3D_DBBP
118    m_ppcYuvRecoDBBP[ui]->destroy(); delete m_ppcYuvRecoDBBP[ui]; m_ppcYuvRecoDBBP[ui] = NULL;
119#endif
120  }
121 
122  delete [] m_ppcYuvResi; m_ppcYuvResi = NULL;
123  delete [] m_ppcYuvReco; m_ppcYuvReco = NULL;
124  delete [] m_ppcCU     ; m_ppcCU      = NULL;
125#if H_3D_DBBP
126  delete [] m_ppcYuvRecoDBBP; m_ppcYuvRecoDBBP = NULL;
127#endif
128}
129
130// ====================================================================================================================
131// Public member functions
132// ====================================================================================================================
133
134/** \param    pcCU        pointer of CU data
135 \param    ruiIsLast   last data?
136 */
137Void TDecCu::decodeCU( TComDataCU* pcCU, UInt& ruiIsLast )
138{
139  if ( pcCU->getSlice()->getPPS()->getUseDQP() )
140  {
141    setdQPFlag(true);
142  }
143
144  // start from the top level CU
145  xDecodeCU( pcCU, 0, 0, ruiIsLast);
146}
147
148/** \param    pcCU        pointer of CU data
149 */
150Void TDecCu::decompressCU( TComDataCU* pcCU )
151{
152#if !H_3D_IV_MERGE
153  xDecompressCU( pcCU, 0,  0 );
154#endif
155}
156
157// ====================================================================================================================
158// Protected member functions
159// ====================================================================================================================
160
161/**decode end-of-slice flag
162 * \param pcCU
163 * \param uiAbsPartIdx
164 * \param uiDepth
165 * \returns Bool
166 */
167Bool TDecCu::xDecodeSliceEnd( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth)
168{
169  UInt uiIsLast;
170  TComPic* pcPic = pcCU->getPic();
171  TComSlice * pcSlice = pcPic->getSlice(pcPic->getCurrSliceIdx());
172  UInt uiCurNumParts    = pcPic->getNumPartInCU() >> (uiDepth<<1);
173  UInt uiWidth = pcSlice->getSPS()->getPicWidthInLumaSamples();
174  UInt uiHeight = pcSlice->getSPS()->getPicHeightInLumaSamples();
175  UInt uiGranularityWidth = g_uiMaxCUWidth;
176  UInt uiPosX = pcCU->getCUPelX() + g_auiRasterToPelX[ g_auiZscanToRaster[uiAbsPartIdx] ];
177  UInt uiPosY = pcCU->getCUPelY() + g_auiRasterToPelY[ g_auiZscanToRaster[uiAbsPartIdx] ];
178
179  if(((uiPosX+pcCU->getWidth(uiAbsPartIdx))%uiGranularityWidth==0||(uiPosX+pcCU->getWidth(uiAbsPartIdx)==uiWidth))
180    &&((uiPosY+pcCU->getHeight(uiAbsPartIdx))%uiGranularityWidth==0||(uiPosY+pcCU->getHeight(uiAbsPartIdx)==uiHeight)))
181  {
182    m_pcEntropyDecoder->decodeTerminatingBit( uiIsLast );
183  }
184  else
185  {
186    uiIsLast=0;
187  }
188 
189  if(uiIsLast) 
190  {
191    if(pcSlice->isNextSliceSegment()&&!pcSlice->isNextSlice()) 
192    {
193      pcSlice->setSliceSegmentCurEndCUAddr(pcCU->getSCUAddr()+uiAbsPartIdx+uiCurNumParts);
194    }
195    else 
196    {
197      pcSlice->setSliceCurEndCUAddr(pcCU->getSCUAddr()+uiAbsPartIdx+uiCurNumParts);
198      pcSlice->setSliceSegmentCurEndCUAddr(pcCU->getSCUAddr()+uiAbsPartIdx+uiCurNumParts);
199    }
200  }
201
202  return uiIsLast>0;
203}
204
205/** decode CU block recursively
206 * \param pcCU
207 * \param uiAbsPartIdx
208 * \param uiDepth
209 * \returns Void
210 */
211
212Void TDecCu::xDecodeCU( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, UInt& ruiIsLast)
213{
214  TComPic* pcPic = pcCU->getPic();
215  UInt uiCurNumParts    = pcPic->getNumPartInCU() >> (uiDepth<<1);
216  UInt uiQNumParts      = uiCurNumParts>>2;
217 
218  Bool bBoundary = false;
219  UInt uiLPelX   = pcCU->getCUPelX() + g_auiRasterToPelX[ g_auiZscanToRaster[uiAbsPartIdx] ];
220  UInt uiRPelX   = uiLPelX + (g_uiMaxCUWidth>>uiDepth)  - 1;
221  UInt uiTPelY   = pcCU->getCUPelY() + g_auiRasterToPelY[ g_auiZscanToRaster[uiAbsPartIdx] ];
222  UInt uiBPelY   = uiTPelY + (g_uiMaxCUHeight>>uiDepth) - 1;
223#if H_MV_ENC_DEC_TRAC
224  DTRACE_CU_S("=========== coding_quadtree ===========\n")
225  DTRACE_CU("x0", uiLPelX)
226  DTRACE_CU("x1", uiTPelY)
227  DTRACE_CU("log2CbSize", g_uiMaxCUWidth>>uiDepth)
228  DTRACE_CU("cqtDepth"  , uiDepth)
229#endif
230
231  TComSlice * pcSlice = pcCU->getPic()->getSlice(pcCU->getPic()->getCurrSliceIdx());
232  Bool bStartInCU = pcCU->getSCUAddr()+uiAbsPartIdx+uiCurNumParts>pcSlice->getSliceSegmentCurStartCUAddr()&&pcCU->getSCUAddr()+uiAbsPartIdx<pcSlice->getSliceSegmentCurStartCUAddr();
233  if((!bStartInCU) && ( uiRPelX < pcSlice->getSPS()->getPicWidthInLumaSamples() ) && ( uiBPelY < pcSlice->getSPS()->getPicHeightInLumaSamples() ) )
234  {
235    m_pcEntropyDecoder->decodeSplitFlag( pcCU, uiAbsPartIdx, uiDepth );
236  }
237  else
238  {
239    bBoundary = true;
240  }
241 
242  if( ( ( uiDepth < pcCU->getDepth( uiAbsPartIdx ) ) && ( uiDepth < g_uiMaxCUDepth - g_uiAddCUDepth ) ) || bBoundary )
243  {
244    UInt uiIdx = uiAbsPartIdx;
245    if( (g_uiMaxCUWidth>>uiDepth) == pcCU->getSlice()->getPPS()->getMinCuDQPSize() && pcCU->getSlice()->getPPS()->getUseDQP())
246    {
247      setdQPFlag(true);
248      pcCU->setQPSubParts( pcCU->getRefQP(uiAbsPartIdx), uiAbsPartIdx, uiDepth ); // set QP to default QP
249    }
250
251    for ( UInt uiPartUnitIdx = 0; uiPartUnitIdx < 4; uiPartUnitIdx++ )
252    {
253      uiLPelX   = pcCU->getCUPelX() + g_auiRasterToPelX[ g_auiZscanToRaster[uiIdx] ];
254      uiTPelY   = pcCU->getCUPelY() + g_auiRasterToPelY[ g_auiZscanToRaster[uiIdx] ];
255     
256      Bool bSubInSlice = pcCU->getSCUAddr()+uiIdx+uiQNumParts>pcSlice->getSliceSegmentCurStartCUAddr();
257      if ( bSubInSlice )
258      {
259        if ( !ruiIsLast && ( uiLPelX < pcCU->getSlice()->getSPS()->getPicWidthInLumaSamples() ) && ( uiTPelY < pcCU->getSlice()->getSPS()->getPicHeightInLumaSamples() ) )
260        {
261          xDecodeCU( pcCU, uiIdx, uiDepth+1, ruiIsLast );
262        }
263        else
264        {
265          pcCU->setOutsideCUPart( uiIdx, uiDepth+1 );
266        }
267      }
268     
269      uiIdx += uiQNumParts;
270    }
271    if( (g_uiMaxCUWidth>>uiDepth) == pcCU->getSlice()->getPPS()->getMinCuDQPSize() && pcCU->getSlice()->getPPS()->getUseDQP())
272    {
273      if ( getdQPFlag() )
274      {
275        UInt uiQPSrcPartIdx;
276        if ( pcPic->getCU( pcCU->getAddr() )->getSliceSegmentStartCU(uiAbsPartIdx) != pcSlice->getSliceSegmentCurStartCUAddr() )
277        {
278          uiQPSrcPartIdx = pcSlice->getSliceSegmentCurStartCUAddr() % pcPic->getNumPartInCU();
279        }
280        else
281        {
282          uiQPSrcPartIdx = uiAbsPartIdx;
283        }
284        pcCU->setQPSubParts( pcCU->getRefQP( uiQPSrcPartIdx ), uiAbsPartIdx, uiDepth ); // set QP to default QP
285      }
286    }
287    return;
288  }
289 
290#if H_MV_ENC_DEC_TRAC
291  DTRACE_CU_S("=========== coding_unit ===========\n")
292#endif
293#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#if SINGLE_DEPTH_SIMP_J0115
747  Pel DepthNeighbours[2];
748#else
749  Pel DepthNeighbours[5];
750#endif
751  Int index =0;
752#if SINGLE_DEPTH_SIMP_J0115
753  for( Int i = 0; (i < 2) && (index<SINGLE_DEPTH_MODE_CAND_LIST_SIZE) ; i++ )
754#else
755  for( Int i = 0; (i < 5) && (index<SINGLE_DEPTH_MODE_CAND_LIST_SIZE) ; i++ )
756#endif
757  {
758    if(!pcCU->getNeighDepth (0, uiAbsPartIdx, &testDepth, i))
759    {
760      continue;
761    }
762    DepthNeighbours[index]=testDepth;
763    index++;
764#if !SINGLE_DEPTH_SIMP_J0115
765    for(Int j=0;j<index-1;j++)
766    {
767     if( (DepthNeighbours[index-1]==DepthNeighbours[j]) )
768     {
769       index--;
770       break;
771     }
772    }
773#endif
774  }
775
776  if(index==0)
777  {
778    DepthNeighbours[index]=1<<(g_bitDepthY-1);
779    index++;
780  }
781
782  if(index==1)
783  {
784    DepthNeighbours[index]=ClipY(DepthNeighbours[0] + 1 );
785    index++;
786  }
787
788  for( UInt uiY = 0; uiY < uiHeight; uiY++ )
789  {
790    for( UInt uiX = 0; uiX < uiWidth; uiX++ )
791    {
792      piReco[ uiX ] =DepthNeighbours[(Int)pcCU->getSingleDepthValue(uiAbsPartIdx)];
793    }
794    piReco     += uiStride;
795  }
796
797  // clear UV
798  UInt  uiStrideC     = pcRecoYuv->getCStride();
799  Pel   *pRecCb       = pcRecoYuv->getCbAddr();
800  Pel   *pRecCr       = pcRecoYuv->getCrAddr();
801
802  for (Int y=0; y<uiHeight/2; y++)
803  {
804    for (Int x=0; x<uiWidth/2; x++)
805    {
806      pRecCb[x] = 1<<(g_bitDepthC-1);
807      pRecCr[x] = 1<<(g_bitDepthC-1);
808    }
809
810    pRecCb += uiStrideC;
811    pRecCr += uiStrideC;
812  }
813}
814#endif
815#if H_3D_INTER_SDC
816Void TDecCu::xReconInterSDC( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
817{
818  // inter prediction
819  m_pcPrediction->motionCompensation( pcCU, m_ppcYuvReco[uiDepth] );
820
821  UInt  uiWidth      = pcCU->getWidth ( 0 );
822  UInt  uiHeight     = pcCU->getHeight( 0 );
823
824  Pel  *pResi;
825  UInt uiPelX, uiPelY;
826  UInt uiResiStride = m_ppcYuvResi[uiDepth]->getStride();
827
828  pResi = m_ppcYuvResi[uiDepth]->getLumaAddr( 0 );
829  for( uiPelY = 0; uiPelY < uiHeight; uiPelY++ )
830  {
831    for( uiPelX = 0; uiPelX < uiWidth; uiPelX++ )
832    {
833      pResi[ uiPelX ] = pcCU->getSDCSegmentDCOffset( 0, 0 );
834    }
835    pResi += uiResiStride;
836  }
837
838  m_ppcYuvReco[uiDepth]->addClip( m_ppcYuvReco[uiDepth], m_ppcYuvResi[uiDepth], 0, pcCU->getWidth( 0 ) );
839
840  // clear UV
841  UInt  uiStrideC     = m_ppcYuvReco[uiDepth]->getCStride();
842  Pel   *pRecCb       = m_ppcYuvReco[uiDepth]->getCbAddr();
843  Pel   *pRecCr       = m_ppcYuvReco[uiDepth]->getCrAddr();
844
845  for (Int y = 0; y < uiHeight/2; y++)
846  {
847    for (Int x = 0; x < uiWidth/2; x++)
848    {
849      pRecCb[x] = (Pel)( 1 << ( g_bitDepthC - 1 ) );
850      pRecCr[x] = (Pel)( 1 << ( g_bitDepthC - 1 ) );
851    }
852
853    pRecCb += uiStrideC;
854    pRecCr += uiStrideC;
855  }
856}
857#endif
858
859#if H_3D_DBBP
860Void TDecCu::xReconInterDBBP( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
861{
862  AOF(!pcCU->getSlice()->getIsDepth());
863  AOF(!pcCU->getSlice()->isIntra());
864  PartSize ePartSize = pcCU->getPartitionSize( 0 );
865 
866  // get collocated depth block
867  UInt uiDepthStride = 0;
868#if H_3D_FCO
869  Pel* pDepthPels = pcCU->getVirtualDepthBlock(pcCU->getZorderIdxInCU(), pcCU->getWidth(0), pcCU->getHeight(0), uiDepthStride);
870#else
871  Pel* pDepthPels = pcCU->getVirtualDepthBlock(0, pcCU->getWidth(0), pcCU->getHeight(0), uiDepthStride);
872#endif
873  AOF( pDepthPels != NULL );
874  AOF( uiDepthStride != 0 );
875 
876  // compute mask by segmenting depth block
877  Bool pMask[MAX_CU_SIZE*MAX_CU_SIZE];
878  Bool bValidMask = m_pcPrediction->getSegmentMaskFromDepth(pDepthPels, uiDepthStride, pcCU->getWidth(0), pcCU->getHeight(0), pMask);
879  AOF(bValidMask);
880 
881  DBBPTmpData* pDBBPTmpData = pcCU->getDBBPTmpData();
882  TComYuv* apSegPredYuv[2] = { m_ppcYuvReco[uiDepth], m_ppcYuvRecoDBBP[uiDepth] };
883 
884  // first, extract the two sets of motion parameters
885  UInt uiPUOffset = ( g_auiPUOffset[UInt( ePartSize )] << ( ( pcCU->getSlice()->getSPS()->getMaxCUDepth() - uiDepth ) << 1 ) ) >> 4;
886  for( UInt uiSegment = 0; uiSegment < 2; uiSegment++ )
887  {
888    UInt uiPartAddr = uiSegment*uiPUOffset;
889   
890    pDBBPTmpData->auhInterDir[uiSegment] = pcCU->getInterDir(uiPartAddr);
891   
892    for ( UInt uiRefListIdx = 0; uiRefListIdx < 2; uiRefListIdx++ )
893    {
894      RefPicList eRefList = (RefPicList)uiRefListIdx;
895      pcCU->getMvField(pcCU, uiPartAddr, eRefList, pDBBPTmpData->acMvField[uiSegment][eRefList]);
896    }
897   
898    AOF( pcCU->getARPW(uiPartAddr) == 0 );
899    AOF( pcCU->getICFlag(uiPartAddr) == false );
900    AOF( pcCU->getSPIVMPFlag(uiPartAddr) == false );
901    AOF( pcCU->getVSPFlag(uiPartAddr) == 0 );
902  }
903 
904  // do motion compensation for each segment as 2Nx2N
905  pcCU->setPartSizeSubParts( SIZE_2Nx2N, 0, uiDepth );
906  pcCU->setPredModeSubParts( MODE_INTER, 0, uiDepth );
907  for( UInt uiSegment = 0; uiSegment < 2; uiSegment++ )
908  {
909    pcCU->setInterDirSubParts( pDBBPTmpData->auhInterDir[uiSegment], 0, 0, uiDepth );
910 
911    for ( UInt uiRefListIdx = 0; uiRefListIdx < 2; uiRefListIdx++ )
912    {
913      RefPicList eRefList = (RefPicList)uiRefListIdx;
914
915      pcCU->getCUMvField( eRefList )->setAllMvField( pDBBPTmpData->acMvField[uiSegment][eRefList], SIZE_2Nx2N, 0, 0 );
916    }
917   
918    // inter prediction
919    m_pcPrediction->motionCompensation( pcCU, apSegPredYuv[uiSegment] );
920  }
921 
922  // restore motion information in both segments again
923  pcCU->setPartSizeSubParts( ePartSize,  0, uiDepth );
924  pcCU->setPredModeSubParts( MODE_INTER, 0, uiDepth );
925  for( UInt uiSegment = 0; uiSegment < 2; uiSegment++ )
926  {
927    UInt uiPartAddr = uiSegment*uiPUOffset;
928   
929    pcCU->setDBBPFlagSubParts(true, uiPartAddr, uiSegment, uiDepth);
930    pcCU->setInterDirSubParts(pDBBPTmpData->auhInterDir[uiSegment], uiPartAddr, uiSegment, uiDepth); // interprets depth relative to LCU level
931   
932    for ( UInt uiRefListIdx = 0; uiRefListIdx < 2; uiRefListIdx++ )
933    {
934      RefPicList eRefList = (RefPicList)uiRefListIdx;
935
936      pcCU->getCUMvField( eRefList )->setAllMvField( pDBBPTmpData->acMvField[uiSegment][eRefList], ePartSize, uiPartAddr, 0, uiSegment ); // interprets depth relative to rpcTempCU level
937    }
938  }
939 
940  // reconstruct final prediction signal by combining both segments
941  m_pcPrediction->combineSegmentsWithMask(apSegPredYuv, m_ppcYuvReco[uiDepth], pMask, pcCU->getWidth(0), pcCU->getHeight(0), 0, ePartSize);
942
943  // inter recon
944  xDecodeInterTexture( pcCU, 0, uiDepth );
945 
946  // clip for only non-zero cbp case
947  if  ( ( pcCU->getCbf( 0, TEXT_LUMA ) ) || ( pcCU->getCbf( 0, TEXT_CHROMA_U ) ) || ( pcCU->getCbf(0, TEXT_CHROMA_V ) ) )
948  {
949    m_ppcYuvReco[uiDepth]->addClip( m_ppcYuvReco[uiDepth], m_ppcYuvResi[uiDepth], 0, pcCU->getWidth( 0 ) );
950  }
951  else
952  {
953    m_ppcYuvReco[uiDepth]->copyPartToPartYuv( m_ppcYuvReco[uiDepth],0, pcCU->getWidth( 0 ),pcCU->getHeight( 0 ));
954  }
955}
956#endif
957
958Void
959TDecCu::xIntraRecLumaBlk( TComDataCU* pcCU,
960                         UInt        uiTrDepth,
961                         UInt        uiAbsPartIdx,
962                         TComYuv*    pcRecoYuv,
963                         TComYuv*    pcPredYuv, 
964                         TComYuv*    pcResiYuv )
965{
966  UInt    uiWidth           = pcCU     ->getWidth   ( 0 ) >> uiTrDepth;
967  UInt    uiHeight          = pcCU     ->getHeight  ( 0 ) >> uiTrDepth;
968  UInt    uiStride          = pcRecoYuv->getStride  ();
969  Pel*    piReco            = pcRecoYuv->getLumaAddr( uiAbsPartIdx );
970  Pel*    piPred            = pcPredYuv->getLumaAddr( uiAbsPartIdx );
971  Pel*    piResi            = pcResiYuv->getLumaAddr( uiAbsPartIdx );
972 
973  UInt    uiNumCoeffInc     = ( pcCU->getSlice()->getSPS()->getMaxCUWidth() * pcCU->getSlice()->getSPS()->getMaxCUHeight() ) >> ( pcCU->getSlice()->getSPS()->getMaxCUDepth() << 1 );
974  TCoeff* pcCoeff           = pcCU->getCoeffY() + ( uiNumCoeffInc * uiAbsPartIdx );
975 
976  UInt    uiLumaPredMode    = pcCU->getLumaIntraDir     ( uiAbsPartIdx );
977 
978  UInt    uiZOrder          = pcCU->getZorderIdxInCU() + uiAbsPartIdx;
979  Pel*    piRecIPred        = pcCU->getPic()->getPicYuvRec()->getLumaAddr( pcCU->getAddr(), uiZOrder );
980  UInt    uiRecIPredStride  = pcCU->getPic()->getPicYuvRec()->getStride  ();
981  Bool    useTransformSkip  = pcCU->getTransformSkip(uiAbsPartIdx, TEXT_LUMA);
982  //===== init availability pattern =====
983  Bool  bAboveAvail = false;
984  Bool  bLeftAvail  = false;
985  pcCU->getPattern()->initPattern   ( pcCU, uiTrDepth, uiAbsPartIdx );
986  pcCU->getPattern()->initAdiPattern( pcCU, uiAbsPartIdx, uiTrDepth, 
987                                     m_pcPrediction->getPredicBuf       (),
988                                     m_pcPrediction->getPredicBufWidth  (),
989                                     m_pcPrediction->getPredicBufHeight (),
990                                     bAboveAvail, bLeftAvail );
991 
992  //===== get prediction signal =====
993#if H_3D_DIM
994  if( isDimMode( uiLumaPredMode ) )
995  {
996    m_pcPrediction->predIntraLumaDepth( pcCU, uiAbsPartIdx, uiLumaPredMode, piPred, uiStride, uiWidth, uiHeight );
997  }
998  else
999  {
1000#endif
1001  m_pcPrediction->predIntraLumaAng( pcCU->getPattern(), uiLumaPredMode, piPred, uiStride, uiWidth, uiHeight, bAboveAvail, bLeftAvail );
1002#if H_3D_DIM
1003  }
1004#endif
1005 
1006#if H_3D
1007  Bool useDltFlag = (isDimMode( uiLumaPredMode ) || uiLumaPredMode == HOR_IDX || uiLumaPredMode == VER_IDX || uiLumaPredMode == DC_IDX) && pcCU->getSlice()->getIsDepth() && pcCU->getSlice()->getPPS()->getDLT()->getUseDLTFlag(pcCU->getSlice()->getLayerIdInVps());
1008
1009  if ( pcCU->getCbf( uiAbsPartIdx, TEXT_LUMA, uiTrDepth ) || useDltFlag )
1010#else
1011  if ( pcCU->getCbf( uiAbsPartIdx, TEXT_LUMA, uiTrDepth ) )
1012#endif
1013  {
1014  //===== inverse transform =====
1015  m_pcTrQuant->setQPforQuant  ( pcCU->getQP(0), TEXT_LUMA, pcCU->getSlice()->getSPS()->getQpBDOffsetY(), 0 );
1016
1017  Int scalingListType = (pcCU->isIntra(uiAbsPartIdx) ? 0 : 3) + g_eTTable[(Int)TEXT_LUMA];
1018    assert(scalingListType < SCALING_LIST_NUM);
1019  m_pcTrQuant->invtransformNxN( pcCU->getCUTransquantBypass(uiAbsPartIdx), TEXT_LUMA, pcCU->getLumaIntraDir( uiAbsPartIdx ), piResi, uiStride, pcCoeff, uiWidth, uiHeight, scalingListType, useTransformSkip );
1020
1021 
1022  //===== reconstruction =====
1023  Pel* pPred      = piPred;
1024  Pel* pResi      = piResi;
1025  Pel* pReco      = piReco;
1026  Pel* pRecIPred  = piRecIPred;
1027  for( UInt uiY = 0; uiY < uiHeight; uiY++ )
1028  {
1029    for( UInt uiX = 0; uiX < uiWidth; uiX++ )
1030    {
1031      pReco    [ uiX ] = ClipY( pPred[ uiX ] + pResi[ uiX ] );
1032      pRecIPred[ uiX ] = pReco[ uiX ];
1033    }
1034    pPred     += uiStride;
1035    pResi     += uiStride;
1036    pReco     += uiStride;
1037    pRecIPred += uiRecIPredStride;
1038  }
1039}
1040  else
1041  {
1042    //===== reconstruction =====
1043    Pel* pPred      = piPred;
1044    Pel* pReco      = piReco;
1045    Pel* pRecIPred  = piRecIPred;
1046    for ( Int y = 0; y < uiHeight; y++ )
1047    {
1048      for ( Int x = 0; x < uiWidth; x++ )
1049      {
1050        pReco    [ x ] = pPred[ x ];
1051        pRecIPred[ x ] = pReco[ x ];
1052      }
1053      pPred     += uiStride;
1054      pReco     += uiStride;
1055      pRecIPred += uiRecIPredStride;
1056    }
1057  }
1058}
1059
1060
1061Void
1062TDecCu::xIntraRecChromaBlk( TComDataCU* pcCU,
1063                           UInt        uiTrDepth,
1064                           UInt        uiAbsPartIdx,
1065                           TComYuv*    pcRecoYuv,
1066                           TComYuv*    pcPredYuv, 
1067                           TComYuv*    pcResiYuv,
1068                           UInt        uiChromaId )
1069{
1070  UInt uiFullDepth  = pcCU->getDepth( 0 ) + uiTrDepth;
1071  UInt uiLog2TrSize = g_aucConvertToBit[ pcCU->getSlice()->getSPS()->getMaxCUWidth() >> uiFullDepth ] + 2;
1072
1073  if( uiLog2TrSize == 2 )
1074  {
1075    assert( uiTrDepth > 0 );
1076    uiTrDepth--;
1077    UInt uiQPDiv = pcCU->getPic()->getNumPartInCU() >> ( ( pcCU->getDepth( 0 ) + uiTrDepth ) << 1 );
1078    Bool bFirstQ = ( ( uiAbsPartIdx % uiQPDiv ) == 0 );
1079    if( !bFirstQ )
1080    {
1081      return;
1082    }
1083  }
1084
1085  TextType  eText             = ( uiChromaId > 0 ? TEXT_CHROMA_V : TEXT_CHROMA_U );
1086  UInt      uiWidth           = pcCU     ->getWidth   ( 0 ) >> ( uiTrDepth + 1 );
1087  UInt      uiHeight          = pcCU     ->getHeight  ( 0 ) >> ( uiTrDepth + 1 );
1088  UInt      uiStride          = pcRecoYuv->getCStride ();
1089  Pel*      piReco            = ( uiChromaId > 0 ? pcRecoYuv->getCrAddr( uiAbsPartIdx ) : pcRecoYuv->getCbAddr( uiAbsPartIdx ) );
1090  Pel*      piPred            = ( uiChromaId > 0 ? pcPredYuv->getCrAddr( uiAbsPartIdx ) : pcPredYuv->getCbAddr( uiAbsPartIdx ) );
1091  Pel*      piResi            = ( uiChromaId > 0 ? pcResiYuv->getCrAddr( uiAbsPartIdx ) : pcResiYuv->getCbAddr( uiAbsPartIdx ) );
1092
1093  UInt      uiNumCoeffInc     = ( ( pcCU->getSlice()->getSPS()->getMaxCUWidth() * pcCU->getSlice()->getSPS()->getMaxCUHeight() ) >> ( pcCU->getSlice()->getSPS()->getMaxCUDepth() << 1 ) ) >> 2;
1094  TCoeff*   pcCoeff           = ( uiChromaId > 0 ? pcCU->getCoeffCr() : pcCU->getCoeffCb() ) + ( uiNumCoeffInc * uiAbsPartIdx );
1095
1096  UInt      uiChromaPredMode  = pcCU->getChromaIntraDir( 0 );
1097
1098  UInt      uiZOrder          = pcCU->getZorderIdxInCU() + uiAbsPartIdx;
1099  Pel*      piRecIPred        = ( uiChromaId > 0 ? pcCU->getPic()->getPicYuvRec()->getCrAddr( pcCU->getAddr(), uiZOrder ) : pcCU->getPic()->getPicYuvRec()->getCbAddr( pcCU->getAddr(), uiZOrder ) );
1100  UInt      uiRecIPredStride  = pcCU->getPic()->getPicYuvRec()->getCStride();
1101  Bool      useTransformSkipChroma = pcCU->getTransformSkip(uiAbsPartIdx,eText);
1102  //===== init availability pattern =====
1103  Bool  bAboveAvail = false;
1104  Bool  bLeftAvail  = false;
1105  pcCU->getPattern()->initPattern         ( pcCU, uiTrDepth, uiAbsPartIdx );
1106
1107  pcCU->getPattern()->initAdiPatternChroma( pcCU, uiAbsPartIdx, uiTrDepth,
1108    m_pcPrediction->getPredicBuf       (),
1109    m_pcPrediction->getPredicBufWidth  (),
1110    m_pcPrediction->getPredicBufHeight (),
1111    bAboveAvail, bLeftAvail );
1112  Int* pPatChroma   = ( uiChromaId > 0 ? pcCU->getPattern()->getAdiCrBuf( uiWidth, uiHeight, m_pcPrediction->getPredicBuf() ) : pcCU->getPattern()->getAdiCbBuf( uiWidth, uiHeight, m_pcPrediction->getPredicBuf() ) );
1113
1114  //===== get prediction signal =====
1115  {
1116    if( uiChromaPredMode == DM_CHROMA_IDX )
1117    {
1118      uiChromaPredMode = pcCU->getLumaIntraDir( 0 );
1119#if H_3D_DIM
1120      mapDepthModeToIntraDir( uiChromaPredMode );
1121#endif
1122    }
1123    m_pcPrediction->predIntraChromaAng( pPatChroma, uiChromaPredMode, piPred, uiStride, uiWidth, uiHeight, bAboveAvail, bLeftAvail ); 
1124  }
1125
1126  if ( pcCU->getCbf( uiAbsPartIdx, eText, uiTrDepth ) )
1127  {
1128    //===== inverse transform =====
1129    Int curChromaQpOffset;
1130    if(eText == TEXT_CHROMA_U)
1131    {
1132      curChromaQpOffset = pcCU->getSlice()->getPPS()->getChromaCbQpOffset() + pcCU->getSlice()->getSliceQpDeltaCb();
1133    }
1134    else
1135    {
1136      curChromaQpOffset = pcCU->getSlice()->getPPS()->getChromaCrQpOffset() + pcCU->getSlice()->getSliceQpDeltaCr();
1137    }
1138    m_pcTrQuant->setQPforQuant  ( pcCU->getQP(0), eText, pcCU->getSlice()->getSPS()->getQpBDOffsetC(), curChromaQpOffset );
1139
1140    Int scalingListType = (pcCU->isIntra(uiAbsPartIdx) ? 0 : 3) + g_eTTable[(Int)eText];
1141    assert(scalingListType < SCALING_LIST_NUM);
1142    m_pcTrQuant->invtransformNxN( pcCU->getCUTransquantBypass(uiAbsPartIdx), eText, REG_DCT, piResi, uiStride, pcCoeff, uiWidth, uiHeight, scalingListType, useTransformSkipChroma );
1143
1144    //===== reconstruction =====
1145    Pel* pPred      = piPred;
1146    Pel* pResi      = piResi;
1147    Pel* pReco      = piReco;
1148    Pel* pRecIPred  = piRecIPred;
1149    for( UInt uiY = 0; uiY < uiHeight; uiY++ )
1150    {
1151      for( UInt uiX = 0; uiX < uiWidth; uiX++ )
1152      {
1153        pReco    [ uiX ] = ClipC( pPred[ uiX ] + pResi[ uiX ] );
1154        pRecIPred[ uiX ] = pReco[ uiX ];
1155      }
1156      pPred     += uiStride;
1157      pResi     += uiStride;
1158      pReco     += uiStride;
1159      pRecIPred += uiRecIPredStride;
1160    }
1161  }
1162  else
1163  {
1164    //===== reconstruction =====
1165    Pel* pPred      = piPred;
1166    Pel* pReco      = piReco;
1167    Pel* pRecIPred  = piRecIPred;
1168    for ( Int y = 0; y < uiHeight; y++ )
1169    {
1170      for ( Int x = 0; x < uiWidth; x++ )
1171      {
1172        pReco    [ x ] = pPred[ x ];
1173        pRecIPred[ x ] = pReco[ x ];
1174      }
1175      pPred     += uiStride;
1176      pReco     += uiStride;
1177      pRecIPred += uiRecIPredStride;
1178    }   
1179  }
1180}
1181
1182
1183Void
1184TDecCu::xReconIntraQT( TComDataCU* pcCU, UInt uiDepth )
1185{
1186  UInt  uiInitTrDepth = ( pcCU->getPartitionSize(0) == SIZE_2Nx2N ? 0 : 1 );
1187  UInt  uiNumPart     = pcCU->getNumPartitions();
1188  UInt  uiNumQParts   = pcCU->getTotalNumPart() >> 2;
1189 
1190  if (pcCU->getIPCMFlag(0))
1191  {
1192    xReconPCM( pcCU, uiDepth );
1193    return;
1194  }
1195
1196  for( UInt uiPU = 0; uiPU < uiNumPart; uiPU++ )
1197  {
1198    xIntraLumaRecQT( pcCU, uiInitTrDepth, uiPU * uiNumQParts, m_ppcYuvReco[uiDepth], m_ppcYuvReco[uiDepth], m_ppcYuvResi[uiDepth] );
1199  } 
1200
1201  for( UInt uiPU = 0; uiPU < uiNumPart; uiPU++ )
1202  {
1203    xIntraChromaRecQT( pcCU, uiInitTrDepth, uiPU * uiNumQParts, m_ppcYuvReco[uiDepth], m_ppcYuvReco[uiDepth], m_ppcYuvResi[uiDepth] );
1204  }
1205
1206}
1207
1208#if H_3D_DIM_SDC
1209Void TDecCu::xReconIntraSDC( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
1210{
1211  UInt uiWidth        = pcCU->getWidth  ( 0 );
1212  UInt uiHeight       = pcCU->getHeight ( 0 );
1213  TComWedgelet* dmm4SegmentationOrg = new TComWedgelet( uiWidth, uiHeight );
1214  UInt numParts = 1;
1215  UInt sdcDepth    = 0;
1216  TComYuv* pcRecoYuv  = m_ppcYuvReco[uiDepth];
1217  TComYuv* pcPredYuv  = m_ppcYuvReco[uiDepth];
1218  TComYuv* pcResiYuv  = m_ppcYuvResi[uiDepth];
1219
1220  UInt    uiStride = 0;
1221  Pel*    piReco;
1222  Pel*    piPred;
1223  Pel*    piResi;
1224
1225  UInt    uiZOrder;       
1226  Pel*    piRecIPred;     
1227  UInt    uiRecIPredStride;
1228
1229  UInt    uiLumaPredMode = 0; 
1230
1231  if ((uiWidth >> pcCU->getSlice()->getSPS()->getQuadtreeTULog2MaxSize()) > 1)
1232  {
1233    numParts = uiWidth * uiWidth >> (2 * pcCU->getSlice()->getSPS()->getQuadtreeTULog2MaxSize());
1234    sdcDepth = g_aucConvertToBit[uiWidth] + 2 - pcCU->getSlice()->getSPS()->getQuadtreeTULog2MaxSize();
1235    uiWidth = uiHeight = (1 << pcCU->getSlice()->getSPS()->getQuadtreeTULog2MaxSize());
1236  }
1237
1238  for ( Int i = 0; i < numParts; i++ )
1239  {
1240    uiStride    = pcRecoYuv->getStride  ();
1241    piReco      = pcRecoYuv->getLumaAddr( uiAbsPartIdx );
1242    piPred      = pcPredYuv->getLumaAddr( uiAbsPartIdx );
1243    piResi      = pcResiYuv->getLumaAddr( uiAbsPartIdx );
1244
1245    uiZOrder          = pcCU->getZorderIdxInCU() + uiAbsPartIdx;
1246    piRecIPred        = pcCU->getPic()->getPicYuvRec()->getLumaAddr( pcCU->getAddr(), uiZOrder );
1247    uiRecIPredStride  = pcCU->getPic()->getPicYuvRec()->getStride  ();
1248
1249    uiLumaPredMode    = pcCU->getLumaIntraDir     ( uiAbsPartIdx );
1250
1251    AOF( uiWidth == uiHeight );
1252
1253    //===== init availability pattern =====
1254    Bool  bAboveAvail = false;
1255    Bool  bLeftAvail  = false;
1256
1257    pcCU->getPattern()->initPattern   ( pcCU, sdcDepth, uiAbsPartIdx );
1258    pcCU->getPattern()->initAdiPattern( pcCU, uiAbsPartIdx, sdcDepth, m_pcPrediction->getPredicBuf(), m_pcPrediction->getPredicBufWidth(), m_pcPrediction->getPredicBufHeight(), bAboveAvail, bLeftAvail );
1259
1260    TComWedgelet* dmm4Segmentation = new TComWedgelet( uiWidth, uiHeight );
1261    //===== get prediction signal =====
1262    if( isDimMode( uiLumaPredMode ) )
1263    {
1264      m_pcPrediction->predIntraLumaDepth( pcCU, uiAbsPartIdx, uiLumaPredMode, piPred, uiStride, uiWidth, uiHeight, false, dmm4Segmentation  );
1265      Bool* dmm4PatternSplit = dmm4Segmentation->getPattern();
1266      Bool* dmm4PatternOrg = dmm4SegmentationOrg->getPattern();
1267      for( UInt k = 0; k < (uiWidth*uiHeight); k++ ) 
1268      { 
1269        dmm4PatternOrg[k+(uiAbsPartIdx<<4)] = dmm4PatternSplit[k];
1270      }
1271    }
1272    else
1273    {
1274      m_pcPrediction->predIntraLumaAng( pcCU->getPattern(), uiLumaPredMode, piPred, uiStride, uiWidth, uiHeight, bAboveAvail, bLeftAvail );
1275    }
1276
1277    if ( numParts > 1 )
1278    {
1279      for( UInt uiY = 0; uiY < uiHeight; uiY++ )
1280      {
1281        for( UInt uiX = 0; uiX < uiWidth; uiX++ )
1282        {
1283          piReco        [ uiX ] = ClipY( piPred[ uiX ] );
1284          piRecIPred    [ uiX ] = piReco[ uiX ];
1285        }
1286        piPred     += uiStride;
1287        piReco     += uiStride;
1288        piRecIPred += uiRecIPredStride;
1289      }
1290    }
1291    uiAbsPartIdx += ( (uiWidth * uiWidth) >> 4 );
1292    dmm4Segmentation->destroy(); delete dmm4Segmentation;
1293  }
1294  uiAbsPartIdx = 0;
1295 
1296  if ( numParts > 1 )
1297  {
1298    uiWidth = pcCU->getWidth( 0 );
1299    uiHeight = pcCU->getHeight( 0 );
1300  }
1301  piReco      = pcRecoYuv->getLumaAddr( uiAbsPartIdx );
1302  piPred      = pcPredYuv->getLumaAddr( uiAbsPartIdx );
1303  piResi      = pcResiYuv->getLumaAddr( uiAbsPartIdx );
1304  uiZOrder          = pcCU->getZorderIdxInCU() + uiAbsPartIdx;
1305  piRecIPred        = pcCU->getPic()->getPicYuvRec()->getLumaAddr( pcCU->getAddr(), uiZOrder );
1306  uiRecIPredStride  = pcCU->getPic()->getPicYuvRec()->getStride  ();
1307  // number of segments depends on prediction mode
1308  UInt uiNumSegments = 1;
1309  Bool* pbMask = NULL;
1310  UInt uiMaskStride = 0;
1311 
1312  if( getDimType( uiLumaPredMode ) == DMM1_IDX )
1313  {
1314    Int uiTabIdx = pcCU->getDmmWedgeTabIdx(DMM1_IDX, uiAbsPartIdx);
1315
1316    WedgeList* pacWedgeList  = pcCU->isDMM1UpscaleMode(uiWidth) ? &g_dmmWedgeLists[(g_aucConvertToBit[pcCU->getDMM1BasePatternWidth(uiWidth)])] :  &g_dmmWedgeLists[(g_aucConvertToBit[uiWidth])];
1317    TComWedgelet* pcWedgelet = &(pacWedgeList->at( uiTabIdx ));
1318
1319    uiNumSegments = 2;
1320
1321    pbMask       = pcCU->isDMM1UpscaleMode( uiWidth ) ? pcWedgelet->getScaledPattern(uiWidth) : pcWedgelet->getPattern();
1322    uiMaskStride = pcCU->isDMM1UpscaleMode( uiWidth ) ? uiWidth : pcWedgelet->getStride();
1323  }
1324  if( getDimType( uiLumaPredMode ) == DMM4_IDX )
1325  {
1326    uiNumSegments = 2;
1327    pbMask  = dmm4SegmentationOrg->getPattern();
1328    uiMaskStride = dmm4SegmentationOrg->getStride();
1329  }
1330  // get DC prediction for each segment
1331  Pel apDCPredValues[2];
1332  if ( getDimType( uiLumaPredMode ) == DMM1_IDX || getDimType( uiLumaPredMode ) == DMM4_IDX )
1333  {
1334    apDCPredValues[0] = pcCU->getDmmPredictor( 0 );
1335    apDCPredValues[1] = pcCU->getDmmPredictor( 1 );
1336  }
1337  else
1338  {
1339    m_pcPrediction->analyzeSegmentsSDC(piPred, uiStride, uiWidth, apDCPredValues, uiNumSegments, pbMask, uiMaskStride, uiLumaPredMode);
1340  }
1341 
1342  // reconstruct residual based on mask + DC residuals
1343  Pel apDCResiValues[2];
1344  for( UInt uiSegment = 0; uiSegment < uiNumSegments; uiSegment++ )
1345  {
1346#if H_3D_DIM_DLT
1347    Pel   pPredIdx    = pcCU->getSlice()->getPPS()->getDLT()->depthValue2idx( pcCU->getSlice()->getLayerIdInVps(), apDCPredValues[uiSegment] );
1348    Pel   pResiIdx    = pcCU->getSDCSegmentDCOffset(uiSegment, uiAbsPartIdx);
1349    Pel   pRecoValue  = pcCU->getSlice()->getPPS()->getDLT()->idx2DepthValue( pcCU->getSlice()->getLayerIdInVps(), pPredIdx + pResiIdx );
1350
1351    apDCResiValues[uiSegment]  = pRecoValue - apDCPredValues[uiSegment];
1352#else
1353    apDCResiValues[uiSegment]  = pcCU->getSDCSegmentDCOffset(uiSegment, uiAbsPartIdx);
1354#endif
1355  }
1356 
1357  //===== reconstruction =====
1358  Bool*pMask      = pbMask;
1359  Pel* pPred      = piPred;
1360  Pel* pResi      = piResi;
1361  Pel* pReco      = piReco;
1362  Pel* pRecIPred  = piRecIPred;
1363 
1364  for( UInt uiY = 0; uiY < uiHeight; uiY++ )
1365  {
1366    for( UInt uiX = 0; uiX < uiWidth; uiX++ )
1367    {
1368      UChar ucSegment = pMask?(UChar)pMask[uiX]:0;
1369      assert( ucSegment < uiNumSegments );
1370     
1371      Pel pResiDC = apDCResiValues[ucSegment];
1372     
1373      pReco    [ uiX ] = ClipY( pPred[ uiX ] + pResiDC );
1374      pRecIPred[ uiX ] = pReco[ uiX ];
1375    }
1376    pPred     += uiStride;
1377    pResi     += uiStride;
1378    pReco     += uiStride;
1379    pRecIPred += uiRecIPredStride;
1380    pMask     += uiMaskStride;
1381  }
1382 
1383  // clear UV
1384  UInt  uiStrideC     = pcPredYuv->getCStride();
1385  Pel   *pRecCb       = pcPredYuv->getCbAddr();
1386  Pel   *pRecCr       = pcPredYuv->getCrAddr();
1387 
1388  for (Int y=0; y<uiHeight/2; y++)
1389  {
1390    for (Int x=0; x<uiWidth/2; x++)
1391    {
1392      pRecCb[x] = 128;
1393      pRecCr[x] = 128;
1394    }
1395   
1396    pRecCb += uiStrideC;
1397    pRecCr += uiStrideC;
1398  }
1399  dmm4SegmentationOrg->destroy(); delete dmm4SegmentationOrg;
1400}
1401#endif
1402
1403/** Function for deriving recontructed PU/CU Luma sample with QTree structure
1404 * \param pcCU pointer of current CU
1405 * \param uiTrDepth current tranform split depth
1406 * \param uiAbsPartIdx  part index
1407 * \param pcRecoYuv pointer to reconstructed sample arrays
1408 * \param pcPredYuv pointer to prediction sample arrays
1409 * \param pcResiYuv pointer to residue sample arrays
1410 *
1411 \ This function dervies recontructed PU/CU Luma sample with recursive QTree structure
1412 */
1413Void
1414TDecCu::xIntraLumaRecQT( TComDataCU* pcCU,
1415                     UInt        uiTrDepth,
1416                     UInt        uiAbsPartIdx,
1417                     TComYuv*    pcRecoYuv,
1418                     TComYuv*    pcPredYuv, 
1419                     TComYuv*    pcResiYuv )
1420{
1421  UInt uiFullDepth  = pcCU->getDepth(0) + uiTrDepth;
1422  UInt uiTrMode     = pcCU->getTransformIdx( uiAbsPartIdx );
1423  if( uiTrMode == uiTrDepth )
1424  {
1425    xIntraRecLumaBlk  ( pcCU, uiTrDepth, uiAbsPartIdx, pcRecoYuv, pcPredYuv, pcResiYuv );
1426  }
1427  else
1428  {
1429    UInt uiNumQPart  = pcCU->getPic()->getNumPartInCU() >> ( ( uiFullDepth + 1 ) << 1 );
1430    for( UInt uiPart = 0; uiPart < 4; uiPart++ )
1431    {
1432      xIntraLumaRecQT( pcCU, uiTrDepth + 1, uiAbsPartIdx + uiPart * uiNumQPart, pcRecoYuv, pcPredYuv, pcResiYuv );
1433    }
1434  }
1435}
1436
1437/** Function for deriving recontructed PU/CU chroma samples with QTree structure
1438 * \param pcCU pointer of current CU
1439 * \param uiTrDepth current tranform split depth
1440 * \param uiAbsPartIdx  part index
1441 * \param pcRecoYuv pointer to reconstructed sample arrays
1442 * \param pcPredYuv pointer to prediction sample arrays
1443 * \param pcResiYuv pointer to residue sample arrays
1444 *
1445 \ This function dervies recontructed PU/CU chroma samples with QTree recursive structure
1446 */
1447Void
1448TDecCu::xIntraChromaRecQT( TComDataCU* pcCU,
1449                     UInt        uiTrDepth,
1450                     UInt        uiAbsPartIdx,
1451                     TComYuv*    pcRecoYuv,
1452                     TComYuv*    pcPredYuv, 
1453                     TComYuv*    pcResiYuv )
1454{
1455  UInt uiFullDepth  = pcCU->getDepth(0) + uiTrDepth;
1456  UInt uiTrMode     = pcCU->getTransformIdx( uiAbsPartIdx );
1457  if( uiTrMode == uiTrDepth )
1458  {
1459    xIntraRecChromaBlk( pcCU, uiTrDepth, uiAbsPartIdx, pcRecoYuv, pcPredYuv, pcResiYuv, 0 );
1460    xIntraRecChromaBlk( pcCU, uiTrDepth, uiAbsPartIdx, pcRecoYuv, pcPredYuv, pcResiYuv, 1 );
1461  }
1462  else
1463  {
1464    UInt uiNumQPart  = pcCU->getPic()->getNumPartInCU() >> ( ( uiFullDepth + 1 ) << 1 );
1465    for( UInt uiPart = 0; uiPart < 4; uiPart++ )
1466    {
1467      xIntraChromaRecQT( pcCU, uiTrDepth + 1, uiAbsPartIdx + uiPart * uiNumQPart, pcRecoYuv, pcPredYuv, pcResiYuv );
1468    }
1469  }
1470}
1471
1472Void TDecCu::xCopyToPic( TComDataCU* pcCU, TComPic* pcPic, UInt uiZorderIdx, UInt uiDepth )
1473{
1474  UInt uiCUAddr = pcCU->getAddr();
1475 
1476  m_ppcYuvReco[uiDepth]->copyToPicYuv  ( pcPic->getPicYuvRec (), uiCUAddr, uiZorderIdx );
1477 
1478  return;
1479}
1480
1481Void TDecCu::xDecodeInterTexture ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
1482{
1483  UInt    uiWidth    = pcCU->getWidth ( uiAbsPartIdx );
1484  UInt    uiHeight   = pcCU->getHeight( uiAbsPartIdx );
1485  TCoeff* piCoeff;
1486 
1487  Pel*    pResi;
1488  UInt    trMode = pcCU->getTransformIdx( uiAbsPartIdx );
1489 
1490  // Y
1491  piCoeff = pcCU->getCoeffY();
1492  pResi = m_ppcYuvResi[uiDepth]->getLumaAddr();
1493
1494  m_pcTrQuant->setQPforQuant( pcCU->getQP( uiAbsPartIdx ), TEXT_LUMA, pcCU->getSlice()->getSPS()->getQpBDOffsetY(), 0 );
1495
1496  m_pcTrQuant->invRecurTransformNxN ( pcCU, 0, TEXT_LUMA, pResi, 0, m_ppcYuvResi[uiDepth]->getStride(), uiWidth, uiHeight, trMode, 0, piCoeff );
1497 
1498  // Cb and Cr
1499  Int curChromaQpOffset = pcCU->getSlice()->getPPS()->getChromaCbQpOffset() + pcCU->getSlice()->getSliceQpDeltaCb();
1500  m_pcTrQuant->setQPforQuant( pcCU->getQP( uiAbsPartIdx ), TEXT_CHROMA, pcCU->getSlice()->getSPS()->getQpBDOffsetC(), curChromaQpOffset );
1501
1502  uiWidth  >>= 1;
1503  uiHeight >>= 1;
1504  piCoeff = pcCU->getCoeffCb(); pResi = m_ppcYuvResi[uiDepth]->getCbAddr();
1505  m_pcTrQuant->invRecurTransformNxN ( pcCU, 0, TEXT_CHROMA_U, pResi, 0, m_ppcYuvResi[uiDepth]->getCStride(), uiWidth, uiHeight, trMode, 0, piCoeff );
1506
1507  curChromaQpOffset = pcCU->getSlice()->getPPS()->getChromaCrQpOffset() + pcCU->getSlice()->getSliceQpDeltaCr();
1508  m_pcTrQuant->setQPforQuant( pcCU->getQP( uiAbsPartIdx ), TEXT_CHROMA, pcCU->getSlice()->getSPS()->getQpBDOffsetC(), curChromaQpOffset );
1509
1510  piCoeff = pcCU->getCoeffCr(); pResi = m_ppcYuvResi[uiDepth]->getCrAddr();
1511  m_pcTrQuant->invRecurTransformNxN ( pcCU, 0, TEXT_CHROMA_V, pResi, 0, m_ppcYuvResi[uiDepth]->getCStride(), uiWidth, uiHeight, trMode, 0, piCoeff );
1512}
1513
1514/** Function for deriving reconstructed luma/chroma samples of a PCM mode CU.
1515 * \param pcCU pointer to current CU
1516 * \param uiPartIdx part index
1517 * \param piPCM pointer to PCM code arrays
1518 * \param piReco pointer to reconstructed sample arrays
1519 * \param uiStride stride of reconstructed sample arrays
1520 * \param uiWidth CU width
1521 * \param uiHeight CU height
1522 * \param ttText texture component type
1523 * \returns Void
1524 */
1525Void TDecCu::xDecodePCMTexture( TComDataCU* pcCU, UInt uiPartIdx, Pel *piPCM, Pel* piReco, UInt uiStride, UInt uiWidth, UInt uiHeight, TextType ttText)
1526{
1527  UInt uiX, uiY;
1528  Pel* piPicReco;
1529  UInt uiPicStride;
1530  UInt uiPcmLeftShiftBit; 
1531
1532  if( ttText == TEXT_LUMA )
1533  {
1534    uiPicStride   = pcCU->getPic()->getPicYuvRec()->getStride();
1535    piPicReco = pcCU->getPic()->getPicYuvRec()->getLumaAddr(pcCU->getAddr(), pcCU->getZorderIdxInCU()+uiPartIdx);
1536    uiPcmLeftShiftBit = g_bitDepthY - pcCU->getSlice()->getSPS()->getPCMBitDepthLuma();
1537  }
1538  else
1539  {
1540    uiPicStride = pcCU->getPic()->getPicYuvRec()->getCStride();
1541
1542    if( ttText == TEXT_CHROMA_U )
1543    {
1544      piPicReco = pcCU->getPic()->getPicYuvRec()->getCbAddr(pcCU->getAddr(), pcCU->getZorderIdxInCU()+uiPartIdx);
1545    }
1546    else
1547    {
1548      piPicReco = pcCU->getPic()->getPicYuvRec()->getCrAddr(pcCU->getAddr(), pcCU->getZorderIdxInCU()+uiPartIdx);
1549    }
1550    uiPcmLeftShiftBit = g_bitDepthC - pcCU->getSlice()->getSPS()->getPCMBitDepthChroma();
1551  }
1552
1553  for( uiY = 0; uiY < uiHeight; uiY++ )
1554  {
1555    for( uiX = 0; uiX < uiWidth; uiX++ )
1556    {
1557      piReco[uiX] = (piPCM[uiX] << uiPcmLeftShiftBit);
1558      piPicReco[uiX] = piReco[uiX];
1559    }
1560    piPCM += uiWidth;
1561    piReco += uiStride;
1562    piPicReco += uiPicStride;
1563  }
1564}
1565
1566/** Function for reconstructing a PCM mode CU.
1567 * \param pcCU pointer to current CU
1568 * \param uiDepth CU Depth
1569 * \returns Void
1570 */
1571Void TDecCu::xReconPCM( TComDataCU* pcCU, UInt uiDepth )
1572{
1573  // Luma
1574  UInt uiWidth  = (g_uiMaxCUWidth >> uiDepth);
1575  UInt uiHeight = (g_uiMaxCUHeight >> uiDepth);
1576
1577  Pel* piPcmY = pcCU->getPCMSampleY();
1578  Pel* piRecoY = m_ppcYuvReco[uiDepth]->getLumaAddr(0, uiWidth);
1579
1580  UInt uiStride = m_ppcYuvResi[uiDepth]->getStride();
1581
1582  xDecodePCMTexture( pcCU, 0, piPcmY, piRecoY, uiStride, uiWidth, uiHeight, TEXT_LUMA);
1583
1584  // Cb and Cr
1585  UInt uiCWidth  = (uiWidth>>1);
1586  UInt uiCHeight = (uiHeight>>1);
1587
1588  Pel* piPcmCb = pcCU->getPCMSampleCb();
1589  Pel* piPcmCr = pcCU->getPCMSampleCr();
1590  Pel* pRecoCb = m_ppcYuvReco[uiDepth]->getCbAddr();
1591  Pel* pRecoCr = m_ppcYuvReco[uiDepth]->getCrAddr();
1592
1593  UInt uiCStride = m_ppcYuvReco[uiDepth]->getCStride();
1594
1595  xDecodePCMTexture( pcCU, 0, piPcmCb, pRecoCb, uiCStride, uiCWidth, uiCHeight, TEXT_CHROMA_U);
1596  xDecodePCMTexture( pcCU, 0, piPcmCr, pRecoCr, uiCStride, uiCWidth, uiCHeight, TEXT_CHROMA_V);
1597}
1598
1599/** Function for filling the PCM buffer of a CU using its reconstructed sample array
1600 * \param pcCU pointer to current CU
1601 * \param uiDepth CU Depth
1602 * \returns Void
1603 */
1604Void TDecCu::xFillPCMBuffer(TComDataCU* pCU, UInt depth)
1605{
1606  // Luma
1607  UInt width  = (g_uiMaxCUWidth >> depth);
1608  UInt height = (g_uiMaxCUHeight >> depth);
1609
1610  Pel* pPcmY = pCU->getPCMSampleY();
1611  Pel* pRecoY = m_ppcYuvReco[depth]->getLumaAddr(0, width);
1612
1613  UInt stride = m_ppcYuvReco[depth]->getStride();
1614
1615  for(Int y = 0; y < height; y++ )
1616  {
1617    for(Int x = 0; x < width; x++ )
1618    {
1619      pPcmY[x] = pRecoY[x];
1620    }
1621    pPcmY += width;
1622    pRecoY += stride;
1623  }
1624
1625  // Cb and Cr
1626  UInt widthC  = (width>>1);
1627  UInt heightC = (height>>1);
1628
1629  Pel* pPcmCb = pCU->getPCMSampleCb();
1630  Pel* pPcmCr = pCU->getPCMSampleCr();
1631  Pel* pRecoCb = m_ppcYuvReco[depth]->getCbAddr();
1632  Pel* pRecoCr = m_ppcYuvReco[depth]->getCrAddr();
1633
1634  UInt strideC = m_ppcYuvReco[depth]->getCStride();
1635
1636  for(Int y = 0; y < heightC; y++ )
1637  {
1638    for(Int x = 0; x < widthC; x++ )
1639    {
1640      pPcmCb[x] = pRecoCb[x];
1641      pPcmCr[x] = pRecoCr[x];
1642    }
1643    pPcmCr += widthC;
1644    pPcmCb += widthC;
1645    pRecoCb += strideC;
1646    pRecoCr += strideC;
1647  }
1648
1649}
1650
1651//! \}
Note: See TracBrowser for help on using the repository browser.