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

Last change on this file since 1098 was 1094, checked in by lg, 10 years ago

Integration of JCT3V-J0042. The MACRO is "LGE_DDD_REMOVAL_J0042_J0030."
Integration of JCT3V-J0046. The MACRO is "LGE_DEFAULT_DV_J0046."
Integration of JCT3V-J0050. The MACRO is "LGE_CHROMA_IC_J0050_J0034."
Integration of JCT3V-J0041. The MACRO is "LGE_SIMP_DISP_AVAIL_J0041."

By Sunmi Yoo (sunmi.yoo@…) and Junghak Nam (junghak.nam@…)

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