source: 3DVCSoftware/trunk/source/Lib/TLibDecoder/TDecCu.cpp @ 1196

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

Merged 14.0-dev0@1187.

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