source: 3DVCSoftware/branches/HTM-10.0rc1-dev0/source/Lib/TLibDecoder/TDecCu.cpp @ 847

Last change on this file since 847 was 847, checked in by tech, 10 years ago

Further fix to braces. Aligned Intra reconstruction.

  • Property svn:eol-style set to native
File size: 59.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//! \ingroup TLibDecoder
40//! \{
41
42// ====================================================================================================================
43// Constructor / destructor / create / destroy
44// ====================================================================================================================
45
46TDecCu::TDecCu()
47{
48  m_ppcYuvResi = NULL;
49  m_ppcYuvReco = NULL;
50  m_ppcCU      = NULL;
51#if H_3D_DBBP
52  m_ppcYuvRecoDBBP = NULL;
53#endif
54}
55
56TDecCu::~TDecCu()
57{
58}
59
60Void TDecCu::init( TDecEntropy* pcEntropyDecoder, TComTrQuant* pcTrQuant, TComPrediction* pcPrediction)
61{
62  m_pcEntropyDecoder  = pcEntropyDecoder;
63  m_pcTrQuant         = pcTrQuant;
64  m_pcPrediction      = pcPrediction;
65}
66
67/**
68 \param    uiMaxDepth    total number of allowable depth
69 \param    uiMaxWidth    largest CU width
70 \param    uiMaxHeight   largest CU height
71 */
72Void TDecCu::create( UInt uiMaxDepth, UInt uiMaxWidth, UInt uiMaxHeight )
73{
74  m_uiMaxDepth = uiMaxDepth+1;
75 
76  m_ppcYuvResi = new TComYuv*[m_uiMaxDepth-1];
77  m_ppcYuvReco = new TComYuv*[m_uiMaxDepth-1];
78  m_ppcCU      = new TComDataCU*[m_uiMaxDepth-1];
79#if H_3D_DBBP
80  m_ppcYuvRecoDBBP = new TComYuv*[m_uiMaxDepth-1];
81#endif
82 
83  UInt uiNumPartitions;
84  for ( UInt ui = 0; ui < m_uiMaxDepth-1; ui++ )
85  {
86    uiNumPartitions = 1<<( ( m_uiMaxDepth - ui - 1 )<<1 );
87    UInt uiWidth  = uiMaxWidth  >> ui;
88    UInt uiHeight = uiMaxHeight >> ui;
89   
90    m_ppcYuvResi[ui] = new TComYuv;    m_ppcYuvResi[ui]->create( uiWidth, uiHeight );
91    m_ppcYuvReco[ui] = new TComYuv;    m_ppcYuvReco[ui]->create( uiWidth, uiHeight );
92    m_ppcCU     [ui] = new TComDataCU; m_ppcCU     [ui]->create( uiNumPartitions, uiWidth, uiHeight, true, uiMaxWidth >> (m_uiMaxDepth - 1) );
93#if H_3D_DBBP
94    m_ppcYuvRecoDBBP[ui] = new TComYuv;    m_ppcYuvRecoDBBP[ui]->create( uiWidth, uiHeight );
95#endif
96  }
97 
98  m_bDecodeDQP = false;
99
100  // initialize partition order.
101  UInt* piTmp = &g_auiZscanToRaster[0];
102  initZscanToRaster(m_uiMaxDepth, 1, 0, piTmp);
103  initRasterToZscan( uiMaxWidth, uiMaxHeight, m_uiMaxDepth );
104 
105  // initialize conversion matrix from partition index to pel
106  initRasterToPelXY( uiMaxWidth, uiMaxHeight, m_uiMaxDepth );
107}
108
109Void TDecCu::destroy()
110{
111  for ( UInt ui = 0; ui < m_uiMaxDepth-1; ui++ )
112  {
113    m_ppcYuvResi[ui]->destroy(); delete m_ppcYuvResi[ui]; m_ppcYuvResi[ui] = NULL;
114    m_ppcYuvReco[ui]->destroy(); delete m_ppcYuvReco[ui]; m_ppcYuvReco[ui] = NULL;
115    m_ppcCU     [ui]->destroy(); delete m_ppcCU     [ui]; m_ppcCU     [ui] = NULL;
116#if H_3D_DBBP
117    m_ppcYuvRecoDBBP[ui]->destroy(); delete m_ppcYuvRecoDBBP[ui]; m_ppcYuvRecoDBBP[ui] = NULL;
118#endif
119  }
120 
121  delete [] m_ppcYuvResi; m_ppcYuvResi = NULL;
122  delete [] m_ppcYuvReco; m_ppcYuvReco = NULL;
123  delete [] m_ppcCU     ; m_ppcCU      = NULL;
124#if H_3D_DBBP
125  delete [] m_ppcYuvRecoDBBP; m_ppcYuvRecoDBBP = NULL;
126#endif
127}
128
129// ====================================================================================================================
130// Public member functions
131// ====================================================================================================================
132
133/** \param    pcCU        pointer of CU data
134 \param    ruiIsLast   last data?
135 */
136Void TDecCu::decodeCU( TComDataCU* pcCU, UInt& ruiIsLast )
137{
138  if ( pcCU->getSlice()->getPPS()->getUseDQP() )
139  {
140    setdQPFlag(true);
141  }
142
143  // start from the top level CU
144  xDecodeCU( pcCU, 0, 0, ruiIsLast);
145}
146
147/** \param    pcCU        pointer of CU data
148 */
149Void TDecCu::decompressCU( TComDataCU* pcCU )
150{
151#if !H_3D_IV_MERGE
152  xDecompressCU( pcCU, 0,  0 );
153#endif
154}
155
156// ====================================================================================================================
157// Protected member functions
158// ====================================================================================================================
159
160/**decode end-of-slice flag
161 * \param pcCU
162 * \param uiAbsPartIdx
163 * \param uiDepth
164 * \returns Bool
165 */
166Bool TDecCu::xDecodeSliceEnd( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth)
167{
168  UInt uiIsLast;
169  TComPic* pcPic = pcCU->getPic();
170  TComSlice * pcSlice = pcPic->getSlice(pcPic->getCurrSliceIdx());
171  UInt uiCurNumParts    = pcPic->getNumPartInCU() >> (uiDepth<<1);
172  UInt uiWidth = pcSlice->getSPS()->getPicWidthInLumaSamples();
173  UInt uiHeight = pcSlice->getSPS()->getPicHeightInLumaSamples();
174  UInt uiGranularityWidth = g_uiMaxCUWidth;
175  UInt uiPosX = pcCU->getCUPelX() + g_auiRasterToPelX[ g_auiZscanToRaster[uiAbsPartIdx] ];
176  UInt uiPosY = pcCU->getCUPelY() + g_auiRasterToPelY[ g_auiZscanToRaster[uiAbsPartIdx] ];
177
178  if(((uiPosX+pcCU->getWidth(uiAbsPartIdx))%uiGranularityWidth==0||(uiPosX+pcCU->getWidth(uiAbsPartIdx)==uiWidth))
179    &&((uiPosY+pcCU->getHeight(uiAbsPartIdx))%uiGranularityWidth==0||(uiPosY+pcCU->getHeight(uiAbsPartIdx)==uiHeight)))
180  {
181    m_pcEntropyDecoder->decodeTerminatingBit( uiIsLast );
182  }
183  else
184  {
185    uiIsLast=0;
186  }
187 
188  if(uiIsLast) 
189  {
190    if(pcSlice->isNextSliceSegment()&&!pcSlice->isNextSlice()) 
191    {
192      pcSlice->setSliceSegmentCurEndCUAddr(pcCU->getSCUAddr()+uiAbsPartIdx+uiCurNumParts);
193    }
194    else 
195    {
196      pcSlice->setSliceCurEndCUAddr(pcCU->getSCUAddr()+uiAbsPartIdx+uiCurNumParts);
197      pcSlice->setSliceSegmentCurEndCUAddr(pcCU->getSCUAddr()+uiAbsPartIdx+uiCurNumParts);
198    }
199  }
200
201  return uiIsLast>0;
202}
203
204/** decode CU block recursively
205 * \param pcCU
206 * \param uiAbsPartIdx
207 * \param uiDepth
208 * \returns Void
209 */
210
211Void TDecCu::xDecodeCU( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, UInt& ruiIsLast)
212{
213  TComPic* pcPic = pcCU->getPic();
214  UInt uiCurNumParts    = pcPic->getNumPartInCU() >> (uiDepth<<1);
215  UInt uiQNumParts      = uiCurNumParts>>2;
216 
217  Bool bBoundary = false;
218  UInt uiLPelX   = pcCU->getCUPelX() + g_auiRasterToPelX[ g_auiZscanToRaster[uiAbsPartIdx] ];
219  UInt uiRPelX   = uiLPelX + (g_uiMaxCUWidth>>uiDepth)  - 1;
220  UInt uiTPelY   = pcCU->getCUPelY() + g_auiRasterToPelY[ g_auiZscanToRaster[uiAbsPartIdx] ];
221  UInt uiBPelY   = uiTPelY + (g_uiMaxCUHeight>>uiDepth) - 1;
222#if H_MV_ENC_DEC_TRAC
223  DTRACE_CU_S("=========== coding_quadtree ===========\n")
224  DTRACE_CU("x0", uiLPelX)
225  DTRACE_CU("x1", uiTPelY)
226  DTRACE_CU("log2CbSize", g_uiMaxCUWidth>>uiDepth)
227  DTRACE_CU("cqtDepth"  , uiDepth)
228#endif
229
230  TComSlice * pcSlice = pcCU->getPic()->getSlice(pcCU->getPic()->getCurrSliceIdx());
231  Bool bStartInCU = pcCU->getSCUAddr()+uiAbsPartIdx+uiCurNumParts>pcSlice->getSliceSegmentCurStartCUAddr()&&pcCU->getSCUAddr()+uiAbsPartIdx<pcSlice->getSliceSegmentCurStartCUAddr();
232  if((!bStartInCU) && ( uiRPelX < pcSlice->getSPS()->getPicWidthInLumaSamples() ) && ( uiBPelY < pcSlice->getSPS()->getPicHeightInLumaSamples() ) )
233  {
234    m_pcEntropyDecoder->decodeSplitFlag( pcCU, uiAbsPartIdx, uiDepth );
235  }
236  else
237  {
238    bBoundary = true;
239  }
240 
241  if( ( ( uiDepth < pcCU->getDepth( uiAbsPartIdx ) ) && ( uiDepth < g_uiMaxCUDepth - g_uiAddCUDepth ) ) || bBoundary )
242  {
243    UInt uiIdx = uiAbsPartIdx;
244    if( (g_uiMaxCUWidth>>uiDepth) == pcCU->getSlice()->getPPS()->getMinCuDQPSize() && pcCU->getSlice()->getPPS()->getUseDQP())
245    {
246      setdQPFlag(true);
247      pcCU->setQPSubParts( pcCU->getRefQP(uiAbsPartIdx), uiAbsPartIdx, uiDepth ); // set QP to default QP
248    }
249
250    for ( UInt uiPartUnitIdx = 0; uiPartUnitIdx < 4; uiPartUnitIdx++ )
251    {
252      uiLPelX   = pcCU->getCUPelX() + g_auiRasterToPelX[ g_auiZscanToRaster[uiIdx] ];
253      uiTPelY   = pcCU->getCUPelY() + g_auiRasterToPelY[ g_auiZscanToRaster[uiIdx] ];
254     
255      Bool bSubInSlice = pcCU->getSCUAddr()+uiIdx+uiQNumParts>pcSlice->getSliceSegmentCurStartCUAddr();
256      if ( bSubInSlice )
257      {
258        if ( !ruiIsLast && ( uiLPelX < pcCU->getSlice()->getSPS()->getPicWidthInLumaSamples() ) && ( uiTPelY < pcCU->getSlice()->getSPS()->getPicHeightInLumaSamples() ) )
259        {
260          xDecodeCU( pcCU, uiIdx, uiDepth+1, ruiIsLast );
261        }
262        else
263        {
264          pcCU->setOutsideCUPart( uiIdx, uiDepth+1 );
265        }
266      }
267     
268      uiIdx += uiQNumParts;
269    }
270    if( (g_uiMaxCUWidth>>uiDepth) == pcCU->getSlice()->getPPS()->getMinCuDQPSize() && pcCU->getSlice()->getPPS()->getUseDQP())
271    {
272      if ( getdQPFlag() )
273      {
274        UInt uiQPSrcPartIdx;
275        if ( pcPic->getCU( pcCU->getAddr() )->getSliceSegmentStartCU(uiAbsPartIdx) != pcSlice->getSliceSegmentCurStartCUAddr() )
276        {
277          uiQPSrcPartIdx = pcSlice->getSliceSegmentCurStartCUAddr() % pcPic->getNumPartInCU();
278        }
279        else
280        {
281          uiQPSrcPartIdx = uiAbsPartIdx;
282        }
283        pcCU->setQPSubParts( pcCU->getRefQP( uiQPSrcPartIdx ), uiAbsPartIdx, uiDepth ); // set QP to default QP
284      }
285    }
286    return;
287  }
288 
289#if H_MV_ENC_DEC_TRAC
290  DTRACE_CU_S("=========== coding_unit ===========\n")
291#endif
292
293
294#if MTK_DDD_G0063
295      pcCU->setUseDDD( false, uiAbsPartIdx, uiDepth );
296#endif
297
298  if( (g_uiMaxCUWidth>>uiDepth) >= pcCU->getSlice()->getPPS()->getMinCuDQPSize() && pcCU->getSlice()->getPPS()->getUseDQP())
299  {
300    setdQPFlag(true);
301    pcCU->setQPSubParts( pcCU->getRefQP(uiAbsPartIdx), uiAbsPartIdx, uiDepth ); // set QP to default QP
302  }
303#if H_3D_NBDV
304  DisInfo DvInfo; 
305  DvInfo.bDV = false;
306  DvInfo.m_acNBDV.setZero();
307  DvInfo.m_aVIdxCan = 0;
308#if H_3D_NBDV_REF 
309  DvInfo.m_acDoNBDV.setZero();
310#endif
311 
312 
313  if(!pcCU->getSlice()->isIntra())
314  {
315#if H_3D_ARP && H_3D_IV_MERGE
316    if( pcCU->getSlice()->getVPS()->getUseAdvRP( pcCU->getSlice()->getLayerId() ) || pcCU->getSlice()->getVPS()->getIvMvPredFlag( pcCU->getSlice()->getLayerId() ))
317#else
318#if H_3D_ARP
319    if( pcCU->getSlice()->getVPS()->getUseAdvRP(pcCU->getSlice()->getLayerId()) )
320#else
321#if H_3D_IV_MERGE
322    if( pcCU->getSlice()->getVPS()->getIvMvPredFlag(pcCU->getSlice()->getLayerId()) )
323#else
324    if (0)
325#endif
326#endif
327#endif
328    {
329      m_ppcCU[uiDepth]->copyInterPredInfoFrom( pcCU, uiAbsPartIdx, REF_PIC_LIST_0, true );
330      m_ppcCU[uiDepth]->copyDVInfoFrom( pcCU, uiAbsPartIdx);
331      PartSize ePartTemp = m_ppcCU[uiDepth]->getPartitionSize(0);
332      UChar cWidTemp     = m_ppcCU[uiDepth]->getWidth(0);
333      UChar cHeightTemp  = m_ppcCU[uiDepth]->getHeight(0);
334      m_ppcCU[uiDepth]->setWidth  ( 0, pcCU->getSlice()->getSPS()->getMaxCUWidth ()/(1<<uiDepth)  );
335      m_ppcCU[uiDepth]->setHeight ( 0, pcCU->getSlice()->getSPS()->getMaxCUHeight()/(1<<uiDepth)  );
336      m_ppcCU[uiDepth]->setPartSizeSubParts( SIZE_2Nx2N, 0, uiDepth );     
337#if H_3D_IV_MERGE
338      if( pcCU->getSlice()->getIsDepth())
339      {
340#if SEC_DEPTH_DV_DERIVAITON_G0074
341        DvInfo.bDV = m_ppcCU[uiDepth]->getDispforDepth(0, 0, &DvInfo);
342#else
343        DvInfo.bDV = m_ppcCU[uiDepth]->getDispNeighBlocks(0, 0, &DvInfo);
344#endif
345      }
346      else
347      {
348#endif
349#if H_3D_NBDV_REF
350      if(pcCU->getSlice()->getVPS()->getDepthRefinementFlag( pcCU->getSlice()->getLayerIdInVps() ))  //Notes from QC: please check the condition for DoNBDV. Remove this comment once it is done.
351      {
352        DvInfo.bDV = m_ppcCU[uiDepth]->getDisMvpCandNBDV(&DvInfo, true);
353      }
354      else
355#endif
356      {
357        DvInfo.bDV = m_ppcCU[uiDepth]->getDisMvpCandNBDV(&DvInfo);
358      }
359#if H_3D_IV_MERGE
360      }
361#endif
362#if ENC_DEC_TRACE && H_MV_ENC_DEC_TRAC   
363      if ( g_decTraceDispDer )
364      {
365        DTRACE_CU( "RefViewIdx",  DvInfo.m_aVIdxCan );       
366        DTRACE_CU( "MvDisp[x]", DvInfo.m_acNBDV.getHor() );
367        DTRACE_CU( "MvDisp[y]", DvInfo.m_acNBDV.getVer() );
368        DTRACE_CU( "MvRefinedDisp[x]", DvInfo.m_acDoNBDV.getHor() );
369        DTRACE_CU( "MvRefinedDisp[y]", DvInfo.m_acDoNBDV.getVer() );
370      }
371#endif
372
373      pcCU->setDvInfoSubParts(DvInfo, uiAbsPartIdx, uiDepth);
374      m_ppcCU[uiDepth]->setPartSizeSubParts( ePartTemp, 0, uiDepth );
375      m_ppcCU[uiDepth]->setWidth  ( 0, cWidTemp );
376      m_ppcCU[uiDepth]->setHeight ( 0, cHeightTemp );
377     }
378  }
379#endif
380  if (pcCU->getSlice()->getPPS()->getTransquantBypassEnableFlag())
381  {
382    m_pcEntropyDecoder->decodeCUTransquantBypassFlag( pcCU, uiAbsPartIdx, uiDepth );
383  }
384 
385  // decode CU mode and the partition size
386  if( !pcCU->getSlice()->isIntra())
387  {
388    m_pcEntropyDecoder->decodeSkipFlag( pcCU, uiAbsPartIdx, uiDepth );
389  }
390 
391  if( pcCU->isSkipped(uiAbsPartIdx) )
392  {
393#if H_MV_ENC_DEC_TRAC
394    DTRACE_PU_S("=========== prediction_unit ===========\n")
395    DTRACE_PU("x0", uiLPelX)
396    DTRACE_PU("x1", uiTPelY)
397#endif
398    m_ppcCU[uiDepth]->copyInterPredInfoFrom( pcCU, uiAbsPartIdx, REF_PIC_LIST_0 );
399    m_ppcCU[uiDepth]->copyInterPredInfoFrom( pcCU, uiAbsPartIdx, REF_PIC_LIST_1 );
400#if H_3D_IV_MERGE
401    m_ppcCU[uiDepth]->copyDVInfoFrom(pcCU, uiAbsPartIdx);
402    TComMvField cMvFieldNeighbours[MRG_MAX_NUM_CANDS_MEM << 1]; // double length for mv of both lists
403    UChar uhInterDirNeighbours[MRG_MAX_NUM_CANDS_MEM];
404#else
405    TComMvField cMvFieldNeighbours[MRG_MAX_NUM_CANDS << 1]; // double length for mv of both lists
406    UChar uhInterDirNeighbours[MRG_MAX_NUM_CANDS];
407#endif
408    Int numValidMergeCand = 0;
409    for( UInt ui = 0; ui < m_ppcCU[uiDepth]->getSlice()->getMaxNumMergeCand(); ++ui )
410    {
411      uhInterDirNeighbours[ui] = 0;
412    }
413    m_pcEntropyDecoder->decodeMergeIndex( pcCU, 0, uiAbsPartIdx, uiDepth );
414    UInt uiMergeIndex = pcCU->getMergeIndex(uiAbsPartIdx);
415
416#if !SEC_IC_ARP_SIG_G0072
417#if H_3D_IC
418    m_pcEntropyDecoder->decodeICFlag( pcCU, uiAbsPartIdx, uiDepth );
419#endif
420#endif
421#if H_3D_ARP
422    m_pcEntropyDecoder->decodeARPW( pcCU , uiAbsPartIdx , uiDepth );
423#endif
424#if SEC_IC_ARP_SIG_G0072
425#if H_3D_IC
426    m_pcEntropyDecoder->decodeICFlag( pcCU, uiAbsPartIdx, uiDepth );
427#endif
428#endif
429
430#if H_3D_VSP
431    Int vspFlag[MRG_MAX_NUM_CANDS_MEM];
432    memset(vspFlag, 0, sizeof(Int)*MRG_MAX_NUM_CANDS_MEM);
433    InheritedVSPDisInfo inheritedVSPDisInfo[MRG_MAX_NUM_CANDS_MEM];
434#if H_3D_SPIVMP
435    Bool bSPIVMPFlag[MRG_MAX_NUM_CANDS_MEM];
436    memset(bSPIVMPFlag, false, sizeof(Bool)*MRG_MAX_NUM_CANDS_MEM);
437    TComMvField*  pcMvFieldSP;
438    UChar* puhInterDirSP;
439    pcMvFieldSP = new TComMvField[pcCU->getPic()->getPicSym()->getNumPartition()*2]; 
440    puhInterDirSP = new UChar[pcCU->getPic()->getPicSym()->getNumPartition()]; 
441#endif
442    m_ppcCU[uiDepth]->initAvailableFlags();
443    m_ppcCU[uiDepth]->getInterMergeCandidates( 0, 0, cMvFieldNeighbours, uhInterDirNeighbours, numValidMergeCand, uiMergeIndex );
444    m_ppcCU[uiDepth]->xGetInterMergeCandidates( 0, 0, cMvFieldNeighbours, uhInterDirNeighbours, vspFlag, inheritedVSPDisInfo
445#if H_3D_SPIVMP
446      , bSPIVMPFlag, pcMvFieldSP, puhInterDirSP
447#endif
448      , numValidMergeCand, uiMergeIndex );
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
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 MTK_DDD_G0063
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 NTT_STORE_SPDV_VSP_G0148
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
549  m_pcEntropyDecoder->decodePredMode( pcCU, uiAbsPartIdx, uiDepth );
550  m_pcEntropyDecoder->decodePartSize( pcCU, uiAbsPartIdx, uiDepth );
551
552#if QC_SDC_UNIFY_G0130
553  m_pcEntropyDecoder->decodeSDCFlag( pcCU, uiAbsPartIdx, uiDepth );
554#endif
555  if (pcCU->isIntra( uiAbsPartIdx ) && pcCU->getPartitionSize( uiAbsPartIdx ) == SIZE_2Nx2N )
556  {
557    m_pcEntropyDecoder->decodeIPCMInfo( pcCU, uiAbsPartIdx, uiDepth );
558
559    if(pcCU->getIPCMFlag(uiAbsPartIdx))
560    {
561      xFinishDecodeCU( pcCU, uiAbsPartIdx, uiDepth, ruiIsLast );
562#if H_3D_IV_MERGE
563      xDecompressCU(pcCU, uiAbsPartIdx, uiDepth );
564#endif
565      return;
566    }
567  }
568
569  UInt uiCurrWidth      = pcCU->getWidth ( uiAbsPartIdx );
570  UInt uiCurrHeight     = pcCU->getHeight( uiAbsPartIdx );
571 
572  // prediction mode ( Intra : direction mode, Inter : Mv, reference idx )
573  m_pcEntropyDecoder->decodePredInfo( pcCU, uiAbsPartIdx, uiDepth, m_ppcCU[uiDepth]);
574#if H_3D_INTER_SDC && !QC_SDC_UNIFY_G0130
575  m_pcEntropyDecoder->decodeInterSDCFlag( pcCU, uiAbsPartIdx, uiDepth );
576#endif
577  // Coefficient decoding
578  Bool bCodeDQP = getdQPFlag();
579  m_pcEntropyDecoder->decodeCoeff( pcCU, uiAbsPartIdx, uiDepth, uiCurrWidth, uiCurrHeight, bCodeDQP );
580  setdQPFlag( bCodeDQP );
581  xFinishDecodeCU( pcCU, uiAbsPartIdx, uiDepth, ruiIsLast );
582#if H_3D_IV_MERGE
583  xDecompressCU(pcCU, uiAbsPartIdx, uiDepth );
584#endif
585}
586
587Void TDecCu::xFinishDecodeCU( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, UInt& ruiIsLast)
588{
589  if(  pcCU->getSlice()->getPPS()->getUseDQP())
590  {
591    pcCU->setQPSubParts( getdQPFlag()?pcCU->getRefQP(uiAbsPartIdx):pcCU->getCodedQP(), uiAbsPartIdx, uiDepth ); // set QP
592  }
593
594  ruiIsLast = xDecodeSliceEnd( pcCU, uiAbsPartIdx, uiDepth);
595}
596
597Void TDecCu::xDecompressCU( TComDataCU* pcCU, UInt uiAbsPartIdx,  UInt uiDepth )
598{
599  TComPic* pcPic = pcCU->getPic();
600#if !H_3D_IV_MERGE
601  Bool bBoundary = false;
602  UInt uiLPelX   = pcCU->getCUPelX() + g_auiRasterToPelX[ g_auiZscanToRaster[uiAbsPartIdx] ];
603  UInt uiRPelX   = uiLPelX + (g_uiMaxCUWidth>>uiDepth)  - 1;
604  UInt uiTPelY   = pcCU->getCUPelY() + g_auiRasterToPelY[ g_auiZscanToRaster[uiAbsPartIdx] ];
605  UInt uiBPelY   = uiTPelY + (g_uiMaxCUHeight>>uiDepth) - 1;
606 
607  UInt uiCurNumParts    = pcPic->getNumPartInCU() >> (uiDepth<<1);
608  TComSlice * pcSlice = pcCU->getPic()->getSlice(pcCU->getPic()->getCurrSliceIdx());
609  Bool bStartInCU = pcCU->getSCUAddr()+uiAbsPartIdx+uiCurNumParts>pcSlice->getSliceSegmentCurStartCUAddr()&&pcCU->getSCUAddr()+uiAbsPartIdx<pcSlice->getSliceSegmentCurStartCUAddr();
610  if(bStartInCU||( uiRPelX >= pcSlice->getSPS()->getPicWidthInLumaSamples() ) || ( uiBPelY >= pcSlice->getSPS()->getPicHeightInLumaSamples() ) )
611  {
612    bBoundary = true;
613  }
614 
615  if( ( ( uiDepth < pcCU->getDepth( uiAbsPartIdx ) ) && ( uiDepth < g_uiMaxCUDepth - g_uiAddCUDepth ) ) || bBoundary )
616  {
617    UInt uiNextDepth = uiDepth + 1;
618    UInt uiQNumParts = pcCU->getTotalNumPart() >> (uiNextDepth<<1);
619    UInt uiIdx = uiAbsPartIdx;
620    for ( UInt uiPartIdx = 0; uiPartIdx < 4; uiPartIdx++ )
621    {
622      uiLPelX = pcCU->getCUPelX() + g_auiRasterToPelX[ g_auiZscanToRaster[uiIdx] ];
623      uiTPelY = pcCU->getCUPelY() + g_auiRasterToPelY[ g_auiZscanToRaster[uiIdx] ];
624     
625      Bool binSlice = (pcCU->getSCUAddr()+uiIdx+uiQNumParts>pcSlice->getSliceSegmentCurStartCUAddr())&&(pcCU->getSCUAddr()+uiIdx<pcSlice->getSliceSegmentCurEndCUAddr());
626      if(binSlice&&( uiLPelX < pcSlice->getSPS()->getPicWidthInLumaSamples() ) && ( uiTPelY < pcSlice->getSPS()->getPicHeightInLumaSamples() ) )
627      {
628        xDecompressCU(pcCU, uiIdx, uiNextDepth );
629      }
630     
631      uiIdx += uiQNumParts;
632    }
633    return;
634  }
635#endif 
636  // Residual reconstruction
637  m_ppcYuvResi[uiDepth]->clear();
638 
639  m_ppcCU[uiDepth]->copySubCU( pcCU, uiAbsPartIdx, uiDepth );
640
641#if H_MV_ENC_DEC_TRAC
642#if ENC_DEC_TRACE
643  stopAtPos  ( m_ppcCU[uiDepth]->getSlice()->getPOC(), 
644    m_ppcCU[uiDepth]->getSlice()->getLayerId(), 
645    m_ppcCU[uiDepth]->getCUPelX(),
646    m_ppcCU[uiDepth]->getCUPelY(),
647    m_ppcCU[uiDepth]->getWidth(0), 
648    m_ppcCU[uiDepth]->getHeight(0) );
649#endif
650#endif
651
652  switch( m_ppcCU[uiDepth]->getPredictionMode(0) )
653  {
654    case MODE_INTER:
655#if H_3D_DBBP
656      if( m_ppcCU[uiDepth]->getDBBPFlag(0) )
657      {
658        xReconInterDBBP( m_ppcCU[uiDepth], uiAbsPartIdx, uiDepth );
659      }
660      else
661      {
662#endif
663#if H_3D_INTER_SDC
664#if QC_SDC_UNIFY_G0130
665      if( m_ppcCU[uiDepth]->getSDCFlag( 0 ) )
666#else
667      if( m_ppcCU[uiDepth]->getInterSDCFlag( 0 ) )
668#endif
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 H_3D_DIM_SDC
685      if( m_ppcCU[uiDepth]->getSDCFlag(0) )
686        xReconIntraSDC( m_ppcCU[uiDepth], 0, uiDepth );
687      else
688#endif
689      xReconIntraQT( m_ppcCU[uiDepth], uiDepth );
690      break;
691    default:
692      assert(0);
693      break;
694  }
695  if ( m_ppcCU[uiDepth]->isLosslessCoded(0) && (m_ppcCU[uiDepth]->getIPCMFlag(0) == false))
696  {
697    xFillPCMBuffer(m_ppcCU[uiDepth], uiDepth);
698  }
699 
700  xCopyToPic( m_ppcCU[uiDepth], pcPic, uiAbsPartIdx, uiDepth );
701}
702
703Void TDecCu::xReconInter( TComDataCU* pcCU, UInt uiDepth )
704{
705 
706  // inter prediction
707  m_pcPrediction->motionCompensation( pcCU, m_ppcYuvReco[uiDepth] );
708 
709  // inter recon
710  xDecodeInterTexture( pcCU, 0, uiDepth );
711 
712  // clip for only non-zero cbp case
713  if  ( ( pcCU->getCbf( 0, TEXT_LUMA ) ) || ( pcCU->getCbf( 0, TEXT_CHROMA_U ) ) || ( pcCU->getCbf(0, TEXT_CHROMA_V ) ) )
714  {
715    m_ppcYuvReco[uiDepth]->addClip( m_ppcYuvReco[uiDepth], m_ppcYuvResi[uiDepth], 0, pcCU->getWidth( 0 ) );
716  }
717  else
718  {
719    m_ppcYuvReco[uiDepth]->copyPartToPartYuv( m_ppcYuvReco[uiDepth],0, pcCU->getWidth( 0 ),pcCU->getHeight( 0 ));
720  }
721}
722
723#if H_3D_INTER_SDC
724Void TDecCu::xReconInterSDC( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
725{
726  // inter prediction
727  m_pcPrediction->motionCompensation( pcCU, m_ppcYuvReco[uiDepth] );
728
729  UInt  uiWidth      = pcCU->getWidth ( 0 );
730  UInt  uiHeight     = pcCU->getHeight( 0 );
731#if !SEC_INTER_SDC_G0101
732  UChar* pMask       = pcCU->getInterSDCMask();
733
734  memset( pMask, 0, uiWidth*uiHeight );
735  pcCU->xSetInterSDCCUMask( pcCU, pMask );
736#endif
737
738  Pel  *pResi;
739  UInt uiPelX, uiPelY;
740  UInt uiResiStride = m_ppcYuvResi[uiDepth]->getStride();
741
742  pResi = m_ppcYuvResi[uiDepth]->getLumaAddr( 0 );
743  for( uiPelY = 0; uiPelY < uiHeight; uiPelY++ )
744  {
745    for( uiPelX = 0; uiPelX < uiWidth; uiPelX++ )
746    {
747#if SEC_INTER_SDC_G0101
748      pResi[ uiPelX ] = pcCU->getSDCSegmentDCOffset( 0, 0 );
749#else
750      UChar uiSeg = pMask[ uiPelX + uiPelY*uiWidth ];
751#if QC_SDC_UNIFY_G0130
752      pResi[ uiPelX ] = pcCU->getSDCSegmentDCOffset( uiSeg, 0 );
753#else
754      pResi[ uiPelX ] = pcCU->getInterSDCSegmentDCOffset( uiSeg, 0 );
755#endif
756#endif
757    }
758    pResi += uiResiStride;
759  }
760
761  m_ppcYuvReco[uiDepth]->addClip( m_ppcYuvReco[uiDepth], m_ppcYuvResi[uiDepth], 0, pcCU->getWidth( 0 ) );
762
763  // clear UV
764  UInt  uiStrideC     = m_ppcYuvReco[uiDepth]->getCStride();
765  Pel   *pRecCb       = m_ppcYuvReco[uiDepth]->getCbAddr();
766  Pel   *pRecCr       = m_ppcYuvReco[uiDepth]->getCrAddr();
767
768  for (Int y = 0; y < uiHeight/2; y++)
769  {
770    for (Int x = 0; x < uiWidth/2; x++)
771    {
772      pRecCb[x] = (Pel)( 1 << ( g_bitDepthC - 1 ) );
773      pRecCr[x] = (Pel)( 1 << ( g_bitDepthC - 1 ) );
774    }
775
776    pRecCb += uiStrideC;
777    pRecCr += uiStrideC;
778  }
779}
780#endif
781
782#if H_3D_DBBP
783Void TDecCu::xReconInterDBBP( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
784{
785  AOF(!pcCU->getSlice()->getIsDepth());
786  AOF(!pcCU->getSlice()->isIntra());
787  PartSize ePartSize = pcCU->getPartitionSize( 0 );
788 
789  // get collocated depth block
790  UInt uiDepthStride = 0;
791  Pel* pDepthPels = pcCU->getVirtualDepthBlock(0, pcCU->getWidth(0), pcCU->getHeight(0), uiDepthStride);
792  AOF( pDepthPels != NULL );
793  AOF( uiDepthStride != 0 );
794 
795  // compute mask by segmenting depth block
796  Bool pMask[MAX_CU_SIZE*MAX_CU_SIZE];
797  Bool bValidMask = m_pcPrediction->getSegmentMaskFromDepth(pDepthPels, uiDepthStride, pcCU->getWidth(0), pcCU->getHeight(0), pMask);
798  AOF(bValidMask);
799 
800  DBBPTmpData* pDBBPTmpData = pcCU->getDBBPTmpData();
801  TComYuv* apSegPredYuv[2] = { m_ppcYuvReco[uiDepth], m_ppcYuvRecoDBBP[uiDepth] };
802 
803  // first, extract the two sets of motion parameters
804  UInt uiPUOffset = ( g_auiPUOffset[UInt( ePartSize )] << ( ( pcCU->getSlice()->getSPS()->getMaxCUDepth() - uiDepth ) << 1 ) ) >> 4;
805  for( UInt uiSegment = 0; uiSegment < 2; uiSegment++ )
806  {
807    UInt uiPartAddr = uiSegment*uiPUOffset;
808   
809    pDBBPTmpData->auhInterDir[uiSegment] = pcCU->getInterDir(uiPartAddr);
810   
811    for ( UInt uiRefListIdx = 0; uiRefListIdx < 2; uiRefListIdx++ )
812    {
813      RefPicList eRefList = (RefPicList)uiRefListIdx;
814      pcCU->getMvField(pcCU, uiPartAddr, eRefList, pDBBPTmpData->acMvField[uiSegment][eRefList]);
815    }
816   
817    pDBBPTmpData->ahVSPFlag[uiSegment] = pcCU->getVSPFlag( uiPartAddr );
818    pDBBPTmpData->acDvInfo[uiSegment] = pcCU->getDvInfo( uiPartAddr );
819  }
820 
821  // do motion compensation for each segment as 2Nx2N
822  pcCU->setPartSizeSubParts( SIZE_2Nx2N, 0, uiDepth );
823  pcCU->setPredModeSubParts( MODE_INTER, 0, uiDepth );
824  for( UInt uiSegment = 0; uiSegment < 2; uiSegment++ )
825  {
826    pcCU->setInterDirSubParts( pDBBPTmpData->auhInterDir[uiSegment], 0, 0, uiDepth );
827   
828    pcCU->setVSPFlagSubParts( pDBBPTmpData->ahVSPFlag[uiSegment], 0, 0, uiDepth );
829    pcCU->setDvInfoSubParts( pDBBPTmpData->acDvInfo[uiSegment], 0, 0, uiDepth );
830   
831    for ( UInt uiRefListIdx = 0; uiRefListIdx < 2; uiRefListIdx++ )
832    {
833      RefPicList eRefList = (RefPicList)uiRefListIdx;
834
835      pcCU->getCUMvField( eRefList )->setAllMvField( pDBBPTmpData->acMvField[uiSegment][eRefList], SIZE_2Nx2N, 0, 0 );
836    }
837   
838    // inter prediction
839    m_pcPrediction->motionCompensation( pcCU, apSegPredYuv[uiSegment] );
840  }
841 
842  // restore motion information in both segments again
843  pcCU->setPartSizeSubParts( ePartSize,  0, uiDepth );
844  pcCU->setPredModeSubParts( MODE_INTER, 0, uiDepth );
845  for( UInt uiSegment = 0; uiSegment < 2; uiSegment++ )
846  {
847    UInt uiPartAddr = uiSegment*uiPUOffset;
848   
849    pcCU->setDBBPFlagSubParts(true, uiPartAddr, uiSegment, uiDepth);
850   
851    pcCU->setVSPFlagSubParts( pDBBPTmpData->ahVSPFlag[uiSegment], uiPartAddr, uiSegment, uiDepth );
852    pcCU->setDvInfoSubParts( pDBBPTmpData->acDvInfo[uiSegment], uiPartAddr, uiSegment, uiDepth );
853   
854    pcCU->setInterDirSubParts(pDBBPTmpData->auhInterDir[uiSegment], uiPartAddr, uiSegment, uiDepth); // interprets depth relative to LCU level
855   
856    for ( UInt uiRefListIdx = 0; uiRefListIdx < 2; uiRefListIdx++ )
857    {
858      RefPicList eRefList = (RefPicList)uiRefListIdx;
859
860      pcCU->getCUMvField( eRefList )->setAllMvField( pDBBPTmpData->acMvField[uiSegment][eRefList], ePartSize, uiPartAddr, 0, uiSegment ); // interprets depth relative to rpcTempCU level
861    }
862  }
863 
864  // reconstruct final prediction signal by combining both segments
865  m_pcPrediction->combineSegmentsWithMask(apSegPredYuv, m_ppcYuvReco[uiDepth], pMask, pcCU->getWidth(0), pcCU->getHeight(0));
866 
867  // inter recon
868  xDecodeInterTexture( pcCU, 0, uiDepth );
869 
870  // clip for only non-zero cbp case
871  if  ( ( pcCU->getCbf( 0, TEXT_LUMA ) ) || ( pcCU->getCbf( 0, TEXT_CHROMA_U ) ) || ( pcCU->getCbf(0, TEXT_CHROMA_V ) ) )
872  {
873    m_ppcYuvReco[uiDepth]->addClip( m_ppcYuvReco[uiDepth], m_ppcYuvResi[uiDepth], 0, pcCU->getWidth( 0 ) );
874  }
875  else
876  {
877    m_ppcYuvReco[uiDepth]->copyPartToPartYuv( m_ppcYuvReco[uiDepth],0, pcCU->getWidth( 0 ),pcCU->getHeight( 0 ));
878  }
879}
880#endif
881
882Void
883TDecCu::xIntraRecLumaBlk( TComDataCU* pcCU,
884                         UInt        uiTrDepth,
885                         UInt        uiAbsPartIdx,
886                         TComYuv*    pcRecoYuv,
887                         TComYuv*    pcPredYuv, 
888                         TComYuv*    pcResiYuv )
889{
890  UInt    uiWidth           = pcCU     ->getWidth   ( 0 ) >> uiTrDepth;
891  UInt    uiHeight          = pcCU     ->getHeight  ( 0 ) >> uiTrDepth;
892  UInt    uiStride          = pcRecoYuv->getStride  ();
893  Pel*    piReco            = pcRecoYuv->getLumaAddr( uiAbsPartIdx );
894  Pel*    piPred            = pcPredYuv->getLumaAddr( uiAbsPartIdx );
895  Pel*    piResi            = pcResiYuv->getLumaAddr( uiAbsPartIdx );
896 
897  UInt    uiNumCoeffInc     = ( pcCU->getSlice()->getSPS()->getMaxCUWidth() * pcCU->getSlice()->getSPS()->getMaxCUHeight() ) >> ( pcCU->getSlice()->getSPS()->getMaxCUDepth() << 1 );
898  TCoeff* pcCoeff           = pcCU->getCoeffY() + ( uiNumCoeffInc * uiAbsPartIdx );
899 
900  UInt    uiLumaPredMode    = pcCU->getLumaIntraDir     ( uiAbsPartIdx );
901 
902  UInt    uiZOrder          = pcCU->getZorderIdxInCU() + uiAbsPartIdx;
903  Pel*    piRecIPred        = pcCU->getPic()->getPicYuvRec()->getLumaAddr( pcCU->getAddr(), uiZOrder );
904  UInt    uiRecIPredStride  = pcCU->getPic()->getPicYuvRec()->getStride  ();
905  Bool    useTransformSkip  = pcCU->getTransformSkip(uiAbsPartIdx, TEXT_LUMA);
906  //===== init availability pattern =====
907  Bool  bAboveAvail = false;
908  Bool  bLeftAvail  = false;
909  pcCU->getPattern()->initPattern   ( pcCU, uiTrDepth, uiAbsPartIdx );
910  pcCU->getPattern()->initAdiPattern( pcCU, uiAbsPartIdx, uiTrDepth, 
911                                     m_pcPrediction->getPredicBuf       (),
912                                     m_pcPrediction->getPredicBufWidth  (),
913                                     m_pcPrediction->getPredicBufHeight (),
914                                     bAboveAvail, bLeftAvail );
915 
916  //===== get prediction signal =====
917#if H_3D_DIM
918  if( isDimMode( uiLumaPredMode ) )
919  {
920    m_pcPrediction->predIntraLumaDepth( pcCU, uiAbsPartIdx, uiLumaPredMode, piPred, uiStride, uiWidth, uiHeight );
921  }
922  else
923  {
924#endif
925  m_pcPrediction->predIntraLumaAng( pcCU->getPattern(), uiLumaPredMode, piPred, uiStride, uiWidth, uiHeight, bAboveAvail, bLeftAvail );
926#if H_3D_DIM
927  }
928#endif
929
930#if UPDATE_HM13
931  Bool useDltFlag = (isDimMode( uiLumaPredMode ) || uiLumaPredMode == HOR_IDX || uiLumaPredMode == VER_IDX || uiLumaPredMode == DC_IDX) && pcCU->getSlice()->getIsDepth() && pcCU->getSlice()->getPPS()->getDLT()->getUseDLTFlag(pcCU->getSlice()->getLayerIdInVps());
932
933  if ( pcCU->getCbf( uiAbsPartIdx, TEXT_LUMA, uiTrDepth ) || useDltFlag )
934#else
935  if ( pcCU->getCbf( uiAbsPartIdx, TEXT_LUMA, uiTrDepth ) )
936#endif
937  {
938  //===== inverse transform =====
939  m_pcTrQuant->setQPforQuant  ( pcCU->getQP(0), TEXT_LUMA, pcCU->getSlice()->getSPS()->getQpBDOffsetY(), 0 );
940
941  Int scalingListType = (pcCU->isIntra(uiAbsPartIdx) ? 0 : 3) + g_eTTable[(Int)TEXT_LUMA];
942    assert(scalingListType < SCALING_LIST_NUM);
943  m_pcTrQuant->invtransformNxN( pcCU->getCUTransquantBypass(uiAbsPartIdx), TEXT_LUMA, pcCU->getLumaIntraDir( uiAbsPartIdx ), piResi, uiStride, pcCoeff, uiWidth, uiHeight, scalingListType, useTransformSkip );
944
945 
946  //===== reconstruction =====
947  Pel* pPred      = piPred;
948  Pel* pResi      = piResi;
949  Pel* pReco      = piReco;
950  Pel* pRecIPred  = piRecIPred;
951  for( UInt uiY = 0; uiY < uiHeight; uiY++ )
952  {
953    for( UInt uiX = 0; uiX < uiWidth; uiX++ )
954    {
955#if H_3D
956#if UPDATE_HM13
957      if ( useDltFlag )
958#else
959      if( (isDimMode( uiLumaPredMode ) || uiLumaPredMode == HOR_IDX || uiLumaPredMode == VER_IDX || uiLumaPredMode == DC_IDX) && pcCU->getSlice()->getIsDepth() && pcCU->getSlice()->getPPS()->getDLT()->getUseDLTFlag(pcCU->getSlice()->getLayerIdInVps()) )
960#endif
961      {
962        pReco    [ uiX ] = pcCU->getSlice()->getPPS()->getDLT()->idx2DepthValue( pcCU->getSlice()->getLayerIdInVps(), Clip3( 0, pcCU->getSlice()->getPPS()->getDLT()->getNumDepthValues( pcCU->getSlice()->getLayerIdInVps() ) - 1, pcCU->getSlice()->getPPS()->getDLT()->depthValue2idx( pcCU->getSlice()->getLayerIdInVps(), pPred[ uiX ] ) + pResi[ uiX ] ) );
963      }
964      else
965      {
966        pReco    [ uiX ] = ClipY( pPred[ uiX ] + pResi[ uiX ] );
967      }
968#else
969      pReco    [ uiX ] = ClipY( pPred[ uiX ] + pResi[ uiX ] );
970#endif
971      pRecIPred[ uiX ] = pReco[ uiX ];
972    }
973    pPred     += uiStride;
974    pResi     += uiStride;
975    pReco     += uiStride;
976    pRecIPred += uiRecIPredStride;
977  }
978}
979  else
980  {
981    //===== reconstruction =====
982    Pel* pPred      = piPred;
983    Pel* pReco      = piReco;
984    Pel* pRecIPred  = piRecIPred;
985    for ( Int y = 0; y < uiHeight; y++ )
986    {
987      for ( Int x = 0; x < uiWidth; x++ )
988      {
989        pReco    [ x ] = pPred[ x ];
990        pRecIPred[ x ] = pReco[ x ];
991      }
992      pPred     += uiStride;
993      pReco     += uiStride;
994      pRecIPred += uiRecIPredStride;
995    }
996  }
997}
998
999
1000Void
1001TDecCu::xIntraRecChromaBlk( TComDataCU* pcCU,
1002                           UInt        uiTrDepth,
1003                           UInt        uiAbsPartIdx,
1004                           TComYuv*    pcRecoYuv,
1005                           TComYuv*    pcPredYuv, 
1006                           TComYuv*    pcResiYuv,
1007                           UInt        uiChromaId )
1008{
1009  UInt uiFullDepth  = pcCU->getDepth( 0 ) + uiTrDepth;
1010  UInt uiLog2TrSize = g_aucConvertToBit[ pcCU->getSlice()->getSPS()->getMaxCUWidth() >> uiFullDepth ] + 2;
1011
1012  if( uiLog2TrSize == 2 )
1013  {
1014    assert( uiTrDepth > 0 );
1015    uiTrDepth--;
1016    UInt uiQPDiv = pcCU->getPic()->getNumPartInCU() >> ( ( pcCU->getDepth( 0 ) + uiTrDepth ) << 1 );
1017    Bool bFirstQ = ( ( uiAbsPartIdx % uiQPDiv ) == 0 );
1018    if( !bFirstQ )
1019    {
1020      return;
1021    }
1022  }
1023 
1024  TextType  eText             = ( uiChromaId > 0 ? TEXT_CHROMA_V : TEXT_CHROMA_U );
1025  UInt      uiWidth           = pcCU     ->getWidth   ( 0 ) >> ( uiTrDepth + 1 );
1026  UInt      uiHeight          = pcCU     ->getHeight  ( 0 ) >> ( uiTrDepth + 1 );
1027  UInt      uiStride          = pcRecoYuv->getCStride ();
1028  Pel*      piReco            = ( uiChromaId > 0 ? pcRecoYuv->getCrAddr( uiAbsPartIdx ) : pcRecoYuv->getCbAddr( uiAbsPartIdx ) );
1029  Pel*      piPred            = ( uiChromaId > 0 ? pcPredYuv->getCrAddr( uiAbsPartIdx ) : pcPredYuv->getCbAddr( uiAbsPartIdx ) );
1030  Pel*      piResi            = ( uiChromaId > 0 ? pcResiYuv->getCrAddr( uiAbsPartIdx ) : pcResiYuv->getCbAddr( uiAbsPartIdx ) );
1031 
1032  UInt      uiNumCoeffInc     = ( ( pcCU->getSlice()->getSPS()->getMaxCUWidth() * pcCU->getSlice()->getSPS()->getMaxCUHeight() ) >> ( pcCU->getSlice()->getSPS()->getMaxCUDepth() << 1 ) ) >> 2;
1033  TCoeff*   pcCoeff           = ( uiChromaId > 0 ? pcCU->getCoeffCr() : pcCU->getCoeffCb() ) + ( uiNumCoeffInc * uiAbsPartIdx );
1034 
1035  UInt      uiChromaPredMode  = pcCU->getChromaIntraDir( 0 );
1036 
1037  UInt      uiZOrder          = pcCU->getZorderIdxInCU() + uiAbsPartIdx;
1038  Pel*      piRecIPred        = ( uiChromaId > 0 ? pcCU->getPic()->getPicYuvRec()->getCrAddr( pcCU->getAddr(), uiZOrder ) : pcCU->getPic()->getPicYuvRec()->getCbAddr( pcCU->getAddr(), uiZOrder ) );
1039  UInt      uiRecIPredStride  = pcCU->getPic()->getPicYuvRec()->getCStride();
1040  Bool      useTransformSkipChroma = pcCU->getTransformSkip(uiAbsPartIdx,eText);
1041  //===== init availability pattern =====
1042  Bool  bAboveAvail = false;
1043  Bool  bLeftAvail  = false;
1044  pcCU->getPattern()->initPattern         ( pcCU, uiTrDepth, uiAbsPartIdx );
1045
1046  pcCU->getPattern()->initAdiPatternChroma( pcCU, uiAbsPartIdx, uiTrDepth,
1047                                           m_pcPrediction->getPredicBuf       (),
1048                                           m_pcPrediction->getPredicBufWidth  (),
1049                                           m_pcPrediction->getPredicBufHeight (),
1050                                           bAboveAvail, bLeftAvail );
1051  Int* pPatChroma   = ( uiChromaId > 0 ? pcCU->getPattern()->getAdiCrBuf( uiWidth, uiHeight, m_pcPrediction->getPredicBuf() ) : pcCU->getPattern()->getAdiCbBuf( uiWidth, uiHeight, m_pcPrediction->getPredicBuf() ) );
1052 
1053  //===== get prediction signal =====
1054  {
1055    if( uiChromaPredMode == DM_CHROMA_IDX )
1056    {
1057      uiChromaPredMode = pcCU->getLumaIntraDir( 0 );
1058#if H_3D_DIM
1059      mapDepthModeToIntraDir( uiChromaPredMode );
1060#endif
1061    }
1062    m_pcPrediction->predIntraChromaAng( pPatChroma, uiChromaPredMode, piPred, uiStride, uiWidth, uiHeight, bAboveAvail, bLeftAvail ); 
1063  }
1064
1065  if ( pcCU->getCbf( uiAbsPartIdx, eText, uiTrDepth ) )
1066  {
1067  //===== inverse transform =====
1068  Int curChromaQpOffset;
1069  if(eText == TEXT_CHROMA_U)
1070  {
1071    curChromaQpOffset = pcCU->getSlice()->getPPS()->getChromaCbQpOffset() + pcCU->getSlice()->getSliceQpDeltaCb();
1072  }
1073  else
1074  {
1075    curChromaQpOffset = pcCU->getSlice()->getPPS()->getChromaCrQpOffset() + pcCU->getSlice()->getSliceQpDeltaCr();
1076  }
1077  m_pcTrQuant->setQPforQuant  ( pcCU->getQP(0), eText, pcCU->getSlice()->getSPS()->getQpBDOffsetC(), curChromaQpOffset );
1078
1079  Int scalingListType = (pcCU->isIntra(uiAbsPartIdx) ? 0 : 3) + g_eTTable[(Int)eText];
1080    assert(scalingListType < SCALING_LIST_NUM);
1081  m_pcTrQuant->invtransformNxN( pcCU->getCUTransquantBypass(uiAbsPartIdx), eText, REG_DCT, piResi, uiStride, pcCoeff, uiWidth, uiHeight, scalingListType, useTransformSkipChroma );
1082
1083  //===== reconstruction =====
1084  Pel* pPred      = piPred;
1085  Pel* pResi      = piResi;
1086  Pel* pReco      = piReco;
1087  Pel* pRecIPred  = piRecIPred;
1088  for( UInt uiY = 0; uiY < uiHeight; uiY++ )
1089  {
1090    for( UInt uiX = 0; uiX < uiWidth; uiX++ )
1091    {
1092      pReco    [ uiX ] = ClipC( pPred[ uiX ] + pResi[ uiX ] );
1093      pRecIPred[ uiX ] = pReco[ uiX ];
1094    }
1095    pPred     += uiStride;
1096    pResi     += uiStride;
1097    pReco     += uiStride;
1098    pRecIPred += uiRecIPredStride;
1099  }
1100}
1101  else
1102  {
1103    //===== reconstruction =====
1104    Pel* pPred      = piPred;
1105    Pel* pReco      = piReco;
1106    Pel* pRecIPred  = piRecIPred;
1107    for ( Int y = 0; y < uiHeight; y++ )
1108    {
1109      for ( Int x = 0; x < uiWidth; x++ )
1110      {
1111        pReco    [ x ] = pPred[ x ];
1112        pRecIPred[ x ] = pReco[ x ];
1113      }
1114      pPred     += uiStride;
1115      pReco     += uiStride;
1116      pRecIPred += uiRecIPredStride;
1117    }   
1118  }
1119}
1120
1121
1122Void
1123TDecCu::xReconIntraQT( TComDataCU* pcCU, UInt uiDepth )
1124{
1125  UInt  uiInitTrDepth = ( pcCU->getPartitionSize(0) == SIZE_2Nx2N ? 0 : 1 );
1126  UInt  uiNumPart     = pcCU->getNumPartInter();
1127  UInt  uiNumQParts   = pcCU->getTotalNumPart() >> 2;
1128 
1129  if (pcCU->getIPCMFlag(0))
1130  {
1131    xReconPCM( pcCU, uiDepth );
1132    return;
1133  }
1134
1135  for( UInt uiPU = 0; uiPU < uiNumPart; uiPU++ )
1136  {
1137    xIntraLumaRecQT( pcCU, uiInitTrDepth, uiPU * uiNumQParts, m_ppcYuvReco[uiDepth], m_ppcYuvReco[uiDepth], m_ppcYuvResi[uiDepth] );
1138  } 
1139
1140  for( UInt uiPU = 0; uiPU < uiNumPart; uiPU++ )
1141  {
1142    xIntraChromaRecQT( pcCU, uiInitTrDepth, uiPU * uiNumQParts, m_ppcYuvReco[uiDepth], m_ppcYuvReco[uiDepth], m_ppcYuvResi[uiDepth] );
1143  }
1144
1145}
1146
1147#if H_3D_DIM_SDC
1148Void TDecCu::xReconIntraSDC( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
1149{
1150  UInt uiWidth        = pcCU->getWidth  ( 0 );
1151  UInt uiHeight       = pcCU->getHeight ( 0 );
1152#if QC_PKU_SDC_SPLIT_G0123
1153#if HS_TSINGHUA_SDC_SPLIT_G0111
1154#if QC_GENERIC_SDC_G0122
1155  TComWedgelet* dmm4SegmentationOrg = new TComWedgelet( uiWidth, uiHeight );
1156#endif
1157#else
1158#if QC_GENERIC_SDC_G0122
1159  TComWedgelet* dmm4Segmentation = new TComWedgelet( uiWidth, uiHeight );
1160#endif
1161#endif
1162#endif
1163#if QC_PKU_SDC_SPLIT_G0123
1164  UInt numParts = 1;
1165  UInt i = 0;
1166  UInt sdcDepth    = 0;
1167  TComYuv* pcRecoYuv  = m_ppcYuvReco[uiDepth];
1168  TComYuv* pcPredYuv  = m_ppcYuvReco[uiDepth];
1169  TComYuv* pcResiYuv  = m_ppcYuvResi[uiDepth];
1170
1171  UInt    uiStride = 0;
1172  Pel*    piReco;
1173  Pel*    piPred;
1174  Pel*    piResi;
1175
1176  UInt    uiZOrder;       
1177  Pel*    piRecIPred;     
1178  UInt    uiRecIPredStride;
1179
1180  UInt    uiLumaPredMode = 0; 
1181
1182#if HS_TSINGHUA_SDC_SPLIT_G0111
1183  if ((uiWidth >> pcCU->getSlice()->getSPS()->getQuadtreeTULog2MaxSize()) > 1)
1184  {
1185    numParts = uiWidth * uiWidth >> (2 * pcCU->getSlice()->getSPS()->getQuadtreeTULog2MaxSize());
1186    sdcDepth = g_aucConvertToBit[uiWidth] + 2 - pcCU->getSlice()->getSPS()->getQuadtreeTULog2MaxSize();
1187    uiWidth = uiHeight = (1 << pcCU->getSlice()->getSPS()->getQuadtreeTULog2MaxSize());
1188  }
1189#else
1190  if (uiWidth == 64)
1191  {
1192    numParts = 4;
1193    sdcDepth = 1;
1194    uiWidth = uiHeight = 32;
1195  }
1196#endif
1197
1198  for ( i = 0; i < numParts; i++ )
1199  {
1200    uiStride    = pcRecoYuv->getStride  ();
1201    piReco      = pcRecoYuv->getLumaAddr( uiAbsPartIdx );
1202    piPred      = pcPredYuv->getLumaAddr( uiAbsPartIdx );
1203    piResi      = pcResiYuv->getLumaAddr( uiAbsPartIdx );
1204 
1205    uiZOrder          = pcCU->getZorderIdxInCU() + uiAbsPartIdx;
1206    piRecIPred        = pcCU->getPic()->getPicYuvRec()->getLumaAddr( pcCU->getAddr(), uiZOrder );
1207    uiRecIPredStride  = pcCU->getPic()->getPicYuvRec()->getStride  ();
1208
1209    uiLumaPredMode    = pcCU->getLumaIntraDir     ( uiAbsPartIdx );
1210
1211    AOF( uiWidth == uiHeight );
1212#else
1213  TComYuv* pcRecoYuv  = m_ppcYuvReco[uiDepth];
1214  TComYuv* pcPredYuv  = m_ppcYuvReco[uiDepth];
1215  TComYuv* pcResiYuv  = m_ppcYuvResi[uiDepth];
1216 
1217  UInt    uiStride    = pcRecoYuv->getStride  ();
1218  Pel*    piReco      = pcRecoYuv->getLumaAddr( uiAbsPartIdx );
1219  Pel*    piPred      = pcPredYuv->getLumaAddr( uiAbsPartIdx );
1220  Pel*    piResi      = pcResiYuv->getLumaAddr( uiAbsPartIdx );
1221 
1222  UInt    uiZOrder          = pcCU->getZorderIdxInCU() + uiAbsPartIdx;
1223  Pel*    piRecIPred        = pcCU->getPic()->getPicYuvRec()->getLumaAddr( pcCU->getAddr(), uiZOrder );
1224  UInt    uiRecIPredStride  = pcCU->getPic()->getPicYuvRec()->getStride  ();
1225 
1226  UInt    uiLumaPredMode    = pcCU->getLumaIntraDir     ( uiAbsPartIdx );
1227 
1228  AOF( uiWidth == uiHeight );
1229  AOF( uiAbsPartIdx == 0 );
1230  AOF( pcCU->getSDCAvailable(uiAbsPartIdx) );
1231  AOF( pcCU->getSDCFlag(uiAbsPartIdx) );
1232#endif
1233 
1234  //===== init availability pattern =====
1235  Bool  bAboveAvail = false;
1236  Bool  bLeftAvail  = false;
1237#if QC_PKU_SDC_SPLIT_G0123
1238  pcCU->getPattern()->initPattern   ( pcCU, sdcDepth, uiAbsPartIdx );
1239  pcCU->getPattern()->initAdiPattern( pcCU, uiAbsPartIdx, sdcDepth, m_pcPrediction->getPredicBuf(), m_pcPrediction->getPredicBufWidth(), m_pcPrediction->getPredicBufHeight(), bAboveAvail, bLeftAvail );
1240#else
1241  pcCU->getPattern()->initPattern   ( pcCU, 0, uiAbsPartIdx );
1242  pcCU->getPattern()->initAdiPattern( pcCU, uiAbsPartIdx, 0, m_pcPrediction->getPredicBuf(), m_pcPrediction->getPredicBufWidth(), m_pcPrediction->getPredicBufHeight(), bAboveAvail, bLeftAvail );
1243#endif
1244#if !QC_PKU_SDC_SPLIT_G0123
1245#if QC_GENERIC_SDC_G0122
1246  TComWedgelet* dmm4Segmentation = new TComWedgelet( uiWidth, uiHeight );
1247#endif
1248#endif
1249#if HS_TSINGHUA_SDC_SPLIT_G0111
1250  TComWedgelet* dmm4Segmentation = new TComWedgelet( uiWidth, uiHeight );
1251#endif
1252  //===== get prediction signal =====
1253#if H_3D_DIM
1254  if( isDimMode( uiLumaPredMode ) )
1255  {
1256    m_pcPrediction->predIntraLumaDepth( pcCU, uiAbsPartIdx, uiLumaPredMode, piPred, uiStride, uiWidth, uiHeight
1257#if QC_GENERIC_SDC_G0122
1258      , false, dmm4Segmentation
1259#endif
1260      );
1261#if HS_TSINGHUA_SDC_SPLIT_G0111
1262    Bool* dmm4PatternSplit = dmm4Segmentation->getPattern();
1263    Bool* dmm4PatternOrg = dmm4SegmentationOrg->getPattern();
1264    for( UInt k = 0; k < (uiWidth*uiHeight); k++ ) 
1265    { 
1266      dmm4PatternOrg[k+(uiAbsPartIdx<<4)] = dmm4PatternSplit[k];
1267    }
1268#endif
1269  }
1270  else
1271  {
1272#endif
1273    m_pcPrediction->predIntraLumaAng( pcCU->getPattern(), uiLumaPredMode, piPred, uiStride, uiWidth, uiHeight, bAboveAvail, bLeftAvail );
1274#if H_3D_DIM
1275  }
1276#endif
1277#if QC_PKU_SDC_SPLIT_G0123
1278    if ( numParts > 1 )
1279    {
1280      for( UInt uiY = 0; uiY < uiHeight; uiY++ )
1281      {
1282        for( UInt uiX = 0; uiX < uiWidth; uiX++ )
1283        {
1284          piReco        [ uiX ] = ClipY( piPred[ uiX ] );
1285          piRecIPred    [ uiX ] = piReco[ uiX ];
1286        }
1287        piPred     += uiStride;
1288        piReco     += uiStride;
1289        piRecIPred += uiRecIPredStride;
1290      }
1291    }
1292    uiAbsPartIdx += ( (uiWidth * uiWidth) >> 4 );
1293#if HS_TSINGHUA_SDC_SPLIT_G0111
1294    dmm4Segmentation->destroy(); delete dmm4Segmentation;
1295#endif
1296  }
1297  uiAbsPartIdx = 0;
1298 
1299  if ( numParts > 1 )
1300  {
1301    uiWidth = pcCU->getWidth( 0 );
1302    uiHeight = pcCU->getHeight( 0 );
1303  }
1304  piReco      = pcRecoYuv->getLumaAddr( uiAbsPartIdx );
1305  piPred      = pcPredYuv->getLumaAddr( uiAbsPartIdx );
1306  piResi      = pcResiYuv->getLumaAddr( uiAbsPartIdx );
1307  uiZOrder          = pcCU->getZorderIdxInCU() + uiAbsPartIdx;
1308  piRecIPred        = pcCU->getPic()->getPicYuvRec()->getLumaAddr( pcCU->getAddr(), uiZOrder );
1309  uiRecIPredStride  = pcCU->getPic()->getPicYuvRec()->getStride  ();
1310#endif
1311  // number of segments depends on prediction mode
1312  UInt uiNumSegments = 1;
1313  Bool* pbMask = NULL;
1314  UInt uiMaskStride = 0;
1315 
1316  if( getDimType( uiLumaPredMode ) == DMM1_IDX )
1317  {
1318    Int uiTabIdx = pcCU->getDmmWedgeTabIdx(DMM1_IDX, uiAbsPartIdx);
1319   
1320    WedgeList* pacWedgeList = &g_dmmWedgeLists[(g_aucConvertToBit[uiWidth])];
1321    TComWedgelet* pcWedgelet = &(pacWedgeList->at( uiTabIdx ));
1322   
1323    uiNumSegments = 2;
1324    pbMask = pcWedgelet->getPattern();
1325    uiMaskStride = pcWedgelet->getStride();
1326  }
1327#if QC_GENERIC_SDC_G0122
1328  if( getDimType( uiLumaPredMode ) == DMM4_IDX )
1329  {
1330    uiNumSegments = 2;
1331#if HS_TSINGHUA_SDC_SPLIT_G0111
1332    pbMask  = dmm4SegmentationOrg->getPattern();
1333    uiMaskStride = dmm4SegmentationOrg->getStride();
1334#else
1335    pbMask  = dmm4Segmentation->getPattern();
1336    uiMaskStride = dmm4Segmentation->getStride();
1337#endif
1338  }
1339#endif
1340  // get DC prediction for each segment
1341  Pel apDCPredValues[2];
1342  m_pcPrediction->analyzeSegmentsSDC(piPred, uiStride, uiWidth, apDCPredValues, uiNumSegments, pbMask, uiMaskStride, uiLumaPredMode);
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#if QC_GENERIC_SDC_G0122
1402#if HS_TSINGHUA_SDC_SPLIT_G0111
1403  dmm4SegmentationOrg->destroy(); delete dmm4SegmentationOrg;
1404#else
1405  dmm4Segmentation->destroy(); delete dmm4Segmentation;
1406#endif
1407#endif
1408}
1409#endif
1410
1411/** Function for deriving recontructed PU/CU Luma sample with QTree structure
1412 * \param pcCU pointer of current CU
1413 * \param uiTrDepth current tranform split depth
1414 * \param uiAbsPartIdx  part index
1415 * \param pcRecoYuv pointer to reconstructed sample arrays
1416 * \param pcPredYuv pointer to prediction sample arrays
1417 * \param pcResiYuv pointer to residue sample arrays
1418 *
1419 \ This function dervies recontructed PU/CU Luma sample with recursive QTree structure
1420 */
1421Void
1422TDecCu::xIntraLumaRecQT( TComDataCU* pcCU,
1423                     UInt        uiTrDepth,
1424                     UInt        uiAbsPartIdx,
1425                     TComYuv*    pcRecoYuv,
1426                     TComYuv*    pcPredYuv, 
1427                     TComYuv*    pcResiYuv )
1428{
1429  UInt uiFullDepth  = pcCU->getDepth(0) + uiTrDepth;
1430  UInt uiTrMode     = pcCU->getTransformIdx( uiAbsPartIdx );
1431  if( uiTrMode == uiTrDepth )
1432  {
1433    xIntraRecLumaBlk  ( pcCU, uiTrDepth, uiAbsPartIdx, pcRecoYuv, pcPredYuv, pcResiYuv );
1434  }
1435  else
1436  {
1437    UInt uiNumQPart  = pcCU->getPic()->getNumPartInCU() >> ( ( uiFullDepth + 1 ) << 1 );
1438    for( UInt uiPart = 0; uiPart < 4; uiPart++ )
1439    {
1440      xIntraLumaRecQT( pcCU, uiTrDepth + 1, uiAbsPartIdx + uiPart * uiNumQPart, pcRecoYuv, pcPredYuv, pcResiYuv );
1441    }
1442  }
1443}
1444
1445/** Function for deriving recontructed PU/CU chroma samples with QTree structure
1446 * \param pcCU pointer of current CU
1447 * \param uiTrDepth current tranform split depth
1448 * \param uiAbsPartIdx  part index
1449 * \param pcRecoYuv pointer to reconstructed sample arrays
1450 * \param pcPredYuv pointer to prediction sample arrays
1451 * \param pcResiYuv pointer to residue sample arrays
1452 *
1453 \ This function dervies recontructed PU/CU chroma samples with QTree recursive structure
1454 */
1455Void
1456TDecCu::xIntraChromaRecQT( TComDataCU* pcCU,
1457                     UInt        uiTrDepth,
1458                     UInt        uiAbsPartIdx,
1459                     TComYuv*    pcRecoYuv,
1460                     TComYuv*    pcPredYuv, 
1461                     TComYuv*    pcResiYuv )
1462{
1463  UInt uiFullDepth  = pcCU->getDepth(0) + uiTrDepth;
1464  UInt uiTrMode     = pcCU->getTransformIdx( uiAbsPartIdx );
1465  if( uiTrMode == uiTrDepth )
1466  {
1467    xIntraRecChromaBlk( pcCU, uiTrDepth, uiAbsPartIdx, pcRecoYuv, pcPredYuv, pcResiYuv, 0 );
1468    xIntraRecChromaBlk( pcCU, uiTrDepth, uiAbsPartIdx, pcRecoYuv, pcPredYuv, pcResiYuv, 1 );
1469  }
1470  else
1471  {
1472    UInt uiNumQPart  = pcCU->getPic()->getNumPartInCU() >> ( ( uiFullDepth + 1 ) << 1 );
1473    for( UInt uiPart = 0; uiPart < 4; uiPart++ )
1474    {
1475      xIntraChromaRecQT( pcCU, uiTrDepth + 1, uiAbsPartIdx + uiPart * uiNumQPart, pcRecoYuv, pcPredYuv, pcResiYuv );
1476    }
1477  }
1478}
1479
1480Void TDecCu::xCopyToPic( TComDataCU* pcCU, TComPic* pcPic, UInt uiZorderIdx, UInt uiDepth )
1481{
1482  UInt uiCUAddr = pcCU->getAddr();
1483 
1484  m_ppcYuvReco[uiDepth]->copyToPicYuv  ( pcPic->getPicYuvRec (), uiCUAddr, uiZorderIdx );
1485 
1486  return;
1487}
1488
1489Void TDecCu::xDecodeInterTexture ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
1490{
1491  UInt    uiWidth    = pcCU->getWidth ( uiAbsPartIdx );
1492  UInt    uiHeight   = pcCU->getHeight( uiAbsPartIdx );
1493  TCoeff* piCoeff;
1494 
1495  Pel*    pResi;
1496  UInt    trMode = pcCU->getTransformIdx( uiAbsPartIdx );
1497 
1498  // Y
1499  piCoeff = pcCU->getCoeffY();
1500  pResi = m_ppcYuvResi[uiDepth]->getLumaAddr();
1501
1502  m_pcTrQuant->setQPforQuant( pcCU->getQP( uiAbsPartIdx ), TEXT_LUMA, pcCU->getSlice()->getSPS()->getQpBDOffsetY(), 0 );
1503
1504  m_pcTrQuant->invRecurTransformNxN ( pcCU, 0, TEXT_LUMA, pResi, 0, m_ppcYuvResi[uiDepth]->getStride(), uiWidth, uiHeight, trMode, 0, piCoeff );
1505 
1506  // Cb and Cr
1507  Int curChromaQpOffset = pcCU->getSlice()->getPPS()->getChromaCbQpOffset() + pcCU->getSlice()->getSliceQpDeltaCb();
1508  m_pcTrQuant->setQPforQuant( pcCU->getQP( uiAbsPartIdx ), TEXT_CHROMA, pcCU->getSlice()->getSPS()->getQpBDOffsetC(), curChromaQpOffset );
1509
1510  uiWidth  >>= 1;
1511  uiHeight >>= 1;
1512  piCoeff = pcCU->getCoeffCb(); pResi = m_ppcYuvResi[uiDepth]->getCbAddr();
1513  m_pcTrQuant->invRecurTransformNxN ( pcCU, 0, TEXT_CHROMA_U, pResi, 0, m_ppcYuvResi[uiDepth]->getCStride(), uiWidth, uiHeight, trMode, 0, piCoeff );
1514
1515  curChromaQpOffset = pcCU->getSlice()->getPPS()->getChromaCrQpOffset() + pcCU->getSlice()->getSliceQpDeltaCr();
1516  m_pcTrQuant->setQPforQuant( pcCU->getQP( uiAbsPartIdx ), TEXT_CHROMA, pcCU->getSlice()->getSPS()->getQpBDOffsetC(), curChromaQpOffset );
1517
1518  piCoeff = pcCU->getCoeffCr(); pResi = m_ppcYuvResi[uiDepth]->getCrAddr();
1519  m_pcTrQuant->invRecurTransformNxN ( pcCU, 0, TEXT_CHROMA_V, pResi, 0, m_ppcYuvResi[uiDepth]->getCStride(), uiWidth, uiHeight, trMode, 0, piCoeff );
1520}
1521
1522/** Function for deriving reconstructed luma/chroma samples of a PCM mode CU.
1523 * \param pcCU pointer to current CU
1524 * \param uiPartIdx part index
1525 * \param piPCM pointer to PCM code arrays
1526 * \param piReco pointer to reconstructed sample arrays
1527 * \param uiStride stride of reconstructed sample arrays
1528 * \param uiWidth CU width
1529 * \param uiHeight CU height
1530 * \param ttText texture component type
1531 * \returns Void
1532 */
1533Void TDecCu::xDecodePCMTexture( TComDataCU* pcCU, UInt uiPartIdx, Pel *piPCM, Pel* piReco, UInt uiStride, UInt uiWidth, UInt uiHeight, TextType ttText)
1534{
1535  UInt uiX, uiY;
1536  Pel* piPicReco;
1537  UInt uiPicStride;
1538  UInt uiPcmLeftShiftBit; 
1539
1540  if( ttText == TEXT_LUMA )
1541  {
1542    uiPicStride   = pcCU->getPic()->getPicYuvRec()->getStride();
1543    piPicReco = pcCU->getPic()->getPicYuvRec()->getLumaAddr(pcCU->getAddr(), pcCU->getZorderIdxInCU()+uiPartIdx);
1544    uiPcmLeftShiftBit = g_bitDepthY - pcCU->getSlice()->getSPS()->getPCMBitDepthLuma();
1545  }
1546  else
1547  {
1548    uiPicStride = pcCU->getPic()->getPicYuvRec()->getCStride();
1549
1550    if( ttText == TEXT_CHROMA_U )
1551    {
1552      piPicReco = pcCU->getPic()->getPicYuvRec()->getCbAddr(pcCU->getAddr(), pcCU->getZorderIdxInCU()+uiPartIdx);
1553    }
1554    else
1555    {
1556      piPicReco = pcCU->getPic()->getPicYuvRec()->getCrAddr(pcCU->getAddr(), pcCU->getZorderIdxInCU()+uiPartIdx);
1557    }
1558    uiPcmLeftShiftBit = g_bitDepthC - pcCU->getSlice()->getSPS()->getPCMBitDepthChroma();
1559  }
1560
1561  for( uiY = 0; uiY < uiHeight; uiY++ )
1562  {
1563    for( uiX = 0; uiX < uiWidth; uiX++ )
1564    {
1565      piReco[uiX] = (piPCM[uiX] << uiPcmLeftShiftBit);
1566      piPicReco[uiX] = piReco[uiX];
1567    }
1568    piPCM += uiWidth;
1569    piReco += uiStride;
1570    piPicReco += uiPicStride;
1571  }
1572}
1573
1574/** Function for reconstructing a PCM mode CU.
1575 * \param pcCU pointer to current CU
1576 * \param uiDepth CU Depth
1577 * \returns Void
1578 */
1579Void TDecCu::xReconPCM( TComDataCU* pcCU, UInt uiDepth )
1580{
1581  // Luma
1582  UInt uiWidth  = (g_uiMaxCUWidth >> uiDepth);
1583  UInt uiHeight = (g_uiMaxCUHeight >> uiDepth);
1584
1585  Pel* piPcmY = pcCU->getPCMSampleY();
1586  Pel* piRecoY = m_ppcYuvReco[uiDepth]->getLumaAddr(0, uiWidth);
1587
1588  UInt uiStride = m_ppcYuvResi[uiDepth]->getStride();
1589
1590  xDecodePCMTexture( pcCU, 0, piPcmY, piRecoY, uiStride, uiWidth, uiHeight, TEXT_LUMA);
1591
1592  // Cb and Cr
1593  UInt uiCWidth  = (uiWidth>>1);
1594  UInt uiCHeight = (uiHeight>>1);
1595
1596  Pel* piPcmCb = pcCU->getPCMSampleCb();
1597  Pel* piPcmCr = pcCU->getPCMSampleCr();
1598  Pel* pRecoCb = m_ppcYuvReco[uiDepth]->getCbAddr();
1599  Pel* pRecoCr = m_ppcYuvReco[uiDepth]->getCrAddr();
1600
1601  UInt uiCStride = m_ppcYuvReco[uiDepth]->getCStride();
1602
1603  xDecodePCMTexture( pcCU, 0, piPcmCb, pRecoCb, uiCStride, uiCWidth, uiCHeight, TEXT_CHROMA_U);
1604  xDecodePCMTexture( pcCU, 0, piPcmCr, pRecoCr, uiCStride, uiCWidth, uiCHeight, TEXT_CHROMA_V);
1605}
1606
1607/** Function for filling the PCM buffer of a CU using its reconstructed sample array
1608 * \param pcCU pointer to current CU
1609 * \param uiDepth CU Depth
1610 * \returns Void
1611 */
1612Void TDecCu::xFillPCMBuffer(TComDataCU* pCU, UInt depth)
1613{
1614  // Luma
1615  UInt width  = (g_uiMaxCUWidth >> depth);
1616  UInt height = (g_uiMaxCUHeight >> depth);
1617
1618  Pel* pPcmY = pCU->getPCMSampleY();
1619  Pel* pRecoY = m_ppcYuvReco[depth]->getLumaAddr(0, width);
1620
1621  UInt stride = m_ppcYuvReco[depth]->getStride();
1622
1623  for(Int y = 0; y < height; y++ )
1624  {
1625    for(Int x = 0; x < width; x++ )
1626    {
1627      pPcmY[x] = pRecoY[x];
1628    }
1629    pPcmY += width;
1630    pRecoY += stride;
1631  }
1632
1633  // Cb and Cr
1634  UInt widthC  = (width>>1);
1635  UInt heightC = (height>>1);
1636
1637  Pel* pPcmCb = pCU->getPCMSampleCb();
1638  Pel* pPcmCr = pCU->getPCMSampleCr();
1639  Pel* pRecoCb = m_ppcYuvReco[depth]->getCbAddr();
1640  Pel* pRecoCr = m_ppcYuvReco[depth]->getCrAddr();
1641
1642  UInt strideC = m_ppcYuvReco[depth]->getCStride();
1643
1644  for(Int y = 0; y < heightC; y++ )
1645  {
1646    for(Int x = 0; x < widthC; x++ )
1647    {
1648      pPcmCb[x] = pRecoCb[x];
1649      pPcmCr[x] = pRecoCr[x];
1650    }
1651    pPcmCr += widthC;
1652    pPcmCb += widthC;
1653    pRecoCb += strideC;
1654    pRecoCr += strideC;
1655  }
1656
1657}
1658
1659//! \}
Note: See TracBrowser for help on using the repository browser.