source: 3DVCSoftware/branches/HTM-11.2-dev0/source/Lib/TLibDecoder/TDecCu.cpp @ 1038

Last change on this file since 1038 was 1038, checked in by sharpjp-htm, 10 years ago

Fix tickets #75 Bi-pred restriction bug in VSP
Fix tickets #79 Unused VSP code

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