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

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

Merged HTM-8.2-dev0@723.

  • Property svn:eol-style set to native
File size: 47.4 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-2013, 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}
53
54TDecCu::~TDecCu()
55{
56}
57
58Void TDecCu::init( TDecEntropy* pcEntropyDecoder, TComTrQuant* pcTrQuant, TComPrediction* pcPrediction)
59{
60  m_pcEntropyDecoder  = pcEntropyDecoder;
61  m_pcTrQuant         = pcTrQuant;
62  m_pcPrediction      = pcPrediction;
63}
64
65/**
66 \param    uiMaxDepth    total number of allowable depth
67 \param    uiMaxWidth    largest CU width
68 \param    uiMaxHeight   largest CU height
69 */
70Void TDecCu::create( UInt uiMaxDepth, UInt uiMaxWidth, UInt uiMaxHeight )
71{
72  m_uiMaxDepth = uiMaxDepth+1;
73 
74  m_ppcYuvResi = new TComYuv*[m_uiMaxDepth-1];
75  m_ppcYuvReco = new TComYuv*[m_uiMaxDepth-1];
76  m_ppcCU      = new TComDataCU*[m_uiMaxDepth-1];
77 
78  UInt uiNumPartitions;
79  for ( UInt ui = 0; ui < m_uiMaxDepth-1; ui++ )
80  {
81    uiNumPartitions = 1<<( ( m_uiMaxDepth - ui - 1 )<<1 );
82    UInt uiWidth  = uiMaxWidth  >> ui;
83    UInt uiHeight = uiMaxHeight >> ui;
84   
85    m_ppcYuvResi[ui] = new TComYuv;    m_ppcYuvResi[ui]->create( uiWidth, uiHeight );
86    m_ppcYuvReco[ui] = new TComYuv;    m_ppcYuvReco[ui]->create( uiWidth, uiHeight );
87    m_ppcCU     [ui] = new TComDataCU; m_ppcCU     [ui]->create( uiNumPartitions, uiWidth, uiHeight, true, uiMaxWidth >> (m_uiMaxDepth - 1) );
88  }
89 
90  m_bDecodeDQP = false;
91
92  // initialize partition order.
93  UInt* piTmp = &g_auiZscanToRaster[0];
94  initZscanToRaster(m_uiMaxDepth, 1, 0, piTmp);
95  initRasterToZscan( uiMaxWidth, uiMaxHeight, m_uiMaxDepth );
96 
97  // initialize conversion matrix from partition index to pel
98  initRasterToPelXY( uiMaxWidth, uiMaxHeight, m_uiMaxDepth );
99}
100
101Void TDecCu::destroy()
102{
103  for ( UInt ui = 0; ui < m_uiMaxDepth-1; ui++ )
104  {
105    m_ppcYuvResi[ui]->destroy(); delete m_ppcYuvResi[ui]; m_ppcYuvResi[ui] = NULL;
106    m_ppcYuvReco[ui]->destroy(); delete m_ppcYuvReco[ui]; m_ppcYuvReco[ui] = NULL;
107    m_ppcCU     [ui]->destroy(); delete m_ppcCU     [ui]; m_ppcCU     [ui] = NULL;
108  }
109 
110  delete [] m_ppcYuvResi; m_ppcYuvResi = NULL;
111  delete [] m_ppcYuvReco; m_ppcYuvReco = NULL;
112  delete [] m_ppcCU     ; m_ppcCU      = NULL;
113}
114
115// ====================================================================================================================
116// Public member functions
117// ====================================================================================================================
118
119/** \param    pcCU        pointer of CU data
120 \param    ruiIsLast   last data?
121 */
122Void TDecCu::decodeCU( TComDataCU* pcCU, UInt& ruiIsLast )
123{
124  if ( pcCU->getSlice()->getPPS()->getUseDQP() )
125  {
126    setdQPFlag(true);
127  }
128
129  // start from the top level CU
130  xDecodeCU( pcCU, 0, 0, ruiIsLast);
131}
132
133/** \param    pcCU        pointer of CU data
134 */
135Void TDecCu::decompressCU( TComDataCU* pcCU )
136{
137#if !QC_DEPTH_IV_MRG_F0125
138  xDecompressCU( pcCU, 0,  0 );
139#endif
140}
141
142// ====================================================================================================================
143// Protected member functions
144// ====================================================================================================================
145
146/**decode end-of-slice flag
147 * \param pcCU
148 * \param uiAbsPartIdx
149 * \param uiDepth
150 * \returns Bool
151 */
152Bool TDecCu::xDecodeSliceEnd( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth)
153{
154  UInt uiIsLast;
155  TComPic* pcPic = pcCU->getPic();
156  TComSlice * pcSlice = pcPic->getSlice(pcPic->getCurrSliceIdx());
157  UInt uiCurNumParts    = pcPic->getNumPartInCU() >> (uiDepth<<1);
158  UInt uiWidth = pcSlice->getSPS()->getPicWidthInLumaSamples();
159  UInt uiHeight = pcSlice->getSPS()->getPicHeightInLumaSamples();
160  UInt uiGranularityWidth = g_uiMaxCUWidth;
161  UInt uiPosX = pcCU->getCUPelX() + g_auiRasterToPelX[ g_auiZscanToRaster[uiAbsPartIdx] ];
162  UInt uiPosY = pcCU->getCUPelY() + g_auiRasterToPelY[ g_auiZscanToRaster[uiAbsPartIdx] ];
163
164  if(((uiPosX+pcCU->getWidth(uiAbsPartIdx))%uiGranularityWidth==0||(uiPosX+pcCU->getWidth(uiAbsPartIdx)==uiWidth))
165    &&((uiPosY+pcCU->getHeight(uiAbsPartIdx))%uiGranularityWidth==0||(uiPosY+pcCU->getHeight(uiAbsPartIdx)==uiHeight)))
166  {
167    m_pcEntropyDecoder->decodeTerminatingBit( uiIsLast );
168  }
169  else
170  {
171    uiIsLast=0;
172  }
173 
174  if(uiIsLast) 
175  {
176    if(pcSlice->isNextSliceSegment()&&!pcSlice->isNextSlice()) 
177    {
178      pcSlice->setSliceSegmentCurEndCUAddr(pcCU->getSCUAddr()+uiAbsPartIdx+uiCurNumParts);
179    }
180    else 
181    {
182      pcSlice->setSliceCurEndCUAddr(pcCU->getSCUAddr()+uiAbsPartIdx+uiCurNumParts);
183      pcSlice->setSliceSegmentCurEndCUAddr(pcCU->getSCUAddr()+uiAbsPartIdx+uiCurNumParts);
184    }
185  }
186
187  return uiIsLast>0;
188}
189
190/** decode CU block recursively
191 * \param pcCU
192 * \param uiAbsPartIdx
193 * \param uiDepth
194 * \returns Void
195 */
196
197Void TDecCu::xDecodeCU( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, UInt& ruiIsLast)
198{
199  TComPic* pcPic = pcCU->getPic();
200  UInt uiCurNumParts    = pcPic->getNumPartInCU() >> (uiDepth<<1);
201  UInt uiQNumParts      = uiCurNumParts>>2;
202 
203  Bool bBoundary = false;
204  UInt uiLPelX   = pcCU->getCUPelX() + g_auiRasterToPelX[ g_auiZscanToRaster[uiAbsPartIdx] ];
205  UInt uiRPelX   = uiLPelX + (g_uiMaxCUWidth>>uiDepth)  - 1;
206  UInt uiTPelY   = pcCU->getCUPelY() + g_auiRasterToPelY[ g_auiZscanToRaster[uiAbsPartIdx] ];
207  UInt uiBPelY   = uiTPelY + (g_uiMaxCUHeight>>uiDepth) - 1;
208#if H_MV_ENC_DEC_TRAC
209  DTRACE_CU_S("=========== coding_quadtree ===========\n")
210  DTRACE_CU("x0", uiLPelX)
211  DTRACE_CU("x1", uiTPelY)
212  DTRACE_CU("log2CbSize", g_uiMaxCUWidth>>uiDepth)
213  DTRACE_CU("cqtDepth"  , uiDepth)
214#endif
215  TComSlice * pcSlice = pcCU->getPic()->getSlice(pcCU->getPic()->getCurrSliceIdx());
216  Bool bStartInCU = pcCU->getSCUAddr()+uiAbsPartIdx+uiCurNumParts>pcSlice->getSliceSegmentCurStartCUAddr()&&pcCU->getSCUAddr()+uiAbsPartIdx<pcSlice->getSliceSegmentCurStartCUAddr();
217  if((!bStartInCU) && ( uiRPelX < pcSlice->getSPS()->getPicWidthInLumaSamples() ) && ( uiBPelY < pcSlice->getSPS()->getPicHeightInLumaSamples() ) )
218  {
219    m_pcEntropyDecoder->decodeSplitFlag( pcCU, uiAbsPartIdx, uiDepth );
220  }
221  else
222  {
223    bBoundary = true;
224  }
225 
226  if( ( ( uiDepth < pcCU->getDepth( uiAbsPartIdx ) ) && ( uiDepth < g_uiMaxCUDepth - g_uiAddCUDepth ) ) || bBoundary )
227  {
228    UInt uiIdx = uiAbsPartIdx;
229    if( (g_uiMaxCUWidth>>uiDepth) == pcCU->getSlice()->getPPS()->getMinCuDQPSize() && pcCU->getSlice()->getPPS()->getUseDQP())
230    {
231      setdQPFlag(true);
232      pcCU->setQPSubParts( pcCU->getRefQP(uiAbsPartIdx), uiAbsPartIdx, uiDepth ); // set QP to default QP
233    }
234
235    for ( UInt uiPartUnitIdx = 0; uiPartUnitIdx < 4; uiPartUnitIdx++ )
236    {
237      uiLPelX   = pcCU->getCUPelX() + g_auiRasterToPelX[ g_auiZscanToRaster[uiIdx] ];
238      uiTPelY   = pcCU->getCUPelY() + g_auiRasterToPelY[ g_auiZscanToRaster[uiIdx] ];
239     
240      Bool bSubInSlice = pcCU->getSCUAddr()+uiIdx+uiQNumParts>pcSlice->getSliceSegmentCurStartCUAddr();
241      if ( bSubInSlice )
242      {
243        if ( !ruiIsLast && ( uiLPelX < pcCU->getSlice()->getSPS()->getPicWidthInLumaSamples() ) && ( uiTPelY < pcCU->getSlice()->getSPS()->getPicHeightInLumaSamples() ) )
244        {
245          xDecodeCU( pcCU, uiIdx, uiDepth+1, ruiIsLast );
246        }
247        else
248        {
249          pcCU->setOutsideCUPart( uiIdx, uiDepth+1 );
250        }
251      }
252     
253      uiIdx += uiQNumParts;
254    }
255    if( (g_uiMaxCUWidth>>uiDepth) == pcCU->getSlice()->getPPS()->getMinCuDQPSize() && pcCU->getSlice()->getPPS()->getUseDQP())
256    {
257      if ( getdQPFlag() )
258      {
259        UInt uiQPSrcPartIdx;
260        if ( pcPic->getCU( pcCU->getAddr() )->getSliceSegmentStartCU(uiAbsPartIdx) != pcSlice->getSliceSegmentCurStartCUAddr() )
261        {
262          uiQPSrcPartIdx = pcSlice->getSliceSegmentCurStartCUAddr() % pcPic->getNumPartInCU();
263        }
264        else
265        {
266          uiQPSrcPartIdx = uiAbsPartIdx;
267        }
268        pcCU->setQPSubParts( pcCU->getRefQP( uiQPSrcPartIdx ), uiAbsPartIdx, uiDepth ); // set QP to default QP
269      }
270    }
271    return;
272  }
273 
274#if H_MV_ENC_DEC_TRAC
275  DTRACE_CU_S("=========== coding_unit ===========\n")
276#endif
277
278  if( (g_uiMaxCUWidth>>uiDepth) >= pcCU->getSlice()->getPPS()->getMinCuDQPSize() && pcCU->getSlice()->getPPS()->getUseDQP())
279  {
280    setdQPFlag(true);
281    pcCU->setQPSubParts( pcCU->getRefQP(uiAbsPartIdx), uiAbsPartIdx, uiDepth ); // set QP to default QP
282  }
283#if H_3D_NBDV
284  DisInfo DvInfo; 
285  DvInfo.bDV = false;
286  DvInfo.m_acNBDV.setZero();
287  DvInfo.m_aVIdxCan = 0;
288#if H_3D_NBDV_REF 
289  DvInfo.m_acDoNBDV.setZero();
290#endif
291 
292 
293  if(!pcCU->getSlice()->isIntra())
294  {
295#if H_3D_ARP && H_3D_IV_MERGE
296    if( pcCU->getSlice()->getVPS()->getUseAdvRP( pcCU->getSlice()->getLayerId() ) || pcCU->getSlice()->getVPS()->getIvMvPredFlag( pcCU->getSlice()->getLayerId() ))
297#else
298#if H_3D_ARP
299    if( pcCU->getSlice()->getVPS()->getUseAdvRP(pcCU->getSlice()->getLayerId()) )
300#else
301#if H_3D_IV_MERGE
302    if( pcCU->getSlice()->getVPS()->getIvMvPredFlag(pcCU->getSlice()->getLayerId()) )
303#else
304    if (0)
305#endif
306#endif
307#endif
308    {
309      m_ppcCU[uiDepth]->copyInterPredInfoFrom( pcCU, uiAbsPartIdx, REF_PIC_LIST_0, true );
310      m_ppcCU[uiDepth]->copyDVInfoFrom( pcCU, uiAbsPartIdx);
311      PartSize ePartTemp = m_ppcCU[uiDepth]->getPartitionSize(0);
312      UChar cWidTemp     = m_ppcCU[uiDepth]->getWidth(0);
313      UChar cHeightTemp  = m_ppcCU[uiDepth]->getHeight(0);
314      m_ppcCU[uiDepth]->setWidth  ( 0, pcCU->getSlice()->getSPS()->getMaxCUWidth ()/(1<<uiDepth)  );
315      m_ppcCU[uiDepth]->setHeight ( 0, pcCU->getSlice()->getSPS()->getMaxCUHeight()/(1<<uiDepth)  );
316      m_ppcCU[uiDepth]->setPartSizeSubParts( SIZE_2Nx2N, 0, uiDepth );     
317#if QC_DEPTH_IV_MRG_F0125
318      if( pcCU->getSlice()->getIsDepth())
319      {
320        DvInfo.bDV = m_ppcCU[uiDepth]->getDispNeighBlocks(0, 0, &DvInfo);
321      }
322      else
323      {
324#endif
325#if H_3D_NBDV_REF
326      if(pcCU->getSlice()->getVPS()->getDepthRefinementFlag( pcCU->getSlice()->getLayerIdInVps() ))  //Notes from QC: please check the condition for DoNBDV. Remove this comment once it is done.
327      {
328        DvInfo.bDV = m_ppcCU[uiDepth]->getDisMvpCandNBDV(&DvInfo, true);
329      }
330      else
331#endif
332      {
333        DvInfo.bDV = m_ppcCU[uiDepth]->getDisMvpCandNBDV(&DvInfo);
334      }
335#if QC_DEPTH_IV_MRG_F0125
336      }
337#endif
338#if ENC_DEC_TRACE && H_MV_ENC_DEC_TRAC   
339      if ( g_decTraceDispDer )
340      {
341        DTRACE_CU( "RefViewIdx",  DvInfo.m_aVIdxCan );       
342        DTRACE_CU( "MvDisp[x]", DvInfo.m_acNBDV.getHor() );
343        DTRACE_CU( "MvDisp[y]", DvInfo.m_acNBDV.getVer() );
344        DTRACE_CU( "MvRefinedDisp[x]", DvInfo.m_acDoNBDV.getHor() );
345        DTRACE_CU( "MvRefinedDisp[y]", DvInfo.m_acDoNBDV.getVer() );
346      }
347#endif
348
349      pcCU->setDvInfoSubParts(DvInfo, uiAbsPartIdx, uiDepth);
350      m_ppcCU[uiDepth]->setPartSizeSubParts( ePartTemp, 0, uiDepth );
351      m_ppcCU[uiDepth]->setWidth  ( 0, cWidTemp );
352      m_ppcCU[uiDepth]->setHeight ( 0, cHeightTemp );
353     }
354  }
355#endif
356  if (pcCU->getSlice()->getPPS()->getTransquantBypassEnableFlag())
357  {
358    m_pcEntropyDecoder->decodeCUTransquantBypassFlag( pcCU, uiAbsPartIdx, uiDepth );
359  }
360 
361  // decode CU mode and the partition size
362  if( !pcCU->getSlice()->isIntra())
363  {
364    m_pcEntropyDecoder->decodeSkipFlag( pcCU, uiAbsPartIdx, uiDepth );
365  }
366 
367  if( pcCU->isSkipped(uiAbsPartIdx) )
368  {
369#if H_MV_ENC_DEC_TRAC
370    DTRACE_PU_S("=========== prediction_unit ===========\n")
371    DTRACE_PU("x0", uiLPelX)
372    DTRACE_PU("x1", uiTPelY)
373#endif
374    m_ppcCU[uiDepth]->copyInterPredInfoFrom( pcCU, uiAbsPartIdx, REF_PIC_LIST_0 );
375    m_ppcCU[uiDepth]->copyInterPredInfoFrom( pcCU, uiAbsPartIdx, REF_PIC_LIST_1 );
376#if H_3D_IV_MERGE
377    m_ppcCU[uiDepth]->copyDVInfoFrom(pcCU, uiAbsPartIdx);
378    TComMvField cMvFieldNeighbours[MRG_MAX_NUM_CANDS_MEM << 1]; // double length for mv of both lists
379    UChar uhInterDirNeighbours[MRG_MAX_NUM_CANDS_MEM];
380#else
381    TComMvField cMvFieldNeighbours[MRG_MAX_NUM_CANDS << 1]; // double length for mv of both lists
382    UChar uhInterDirNeighbours[MRG_MAX_NUM_CANDS];
383#endif
384    Int numValidMergeCand = 0;
385    for( UInt ui = 0; ui < m_ppcCU[uiDepth]->getSlice()->getMaxNumMergeCand(); ++ui )
386    {
387      uhInterDirNeighbours[ui] = 0;
388    }
389    m_pcEntropyDecoder->decodeMergeIndex( pcCU, 0, uiAbsPartIdx, uiDepth );
390    UInt uiMergeIndex = pcCU->getMergeIndex(uiAbsPartIdx);
391
392#if LGE_SHARP_VSP_INHERIT_F0104
393#if H_3D_IC
394    m_pcEntropyDecoder->decodeICFlag( pcCU, uiAbsPartIdx, uiDepth );
395#endif
396#if H_3D_ARP
397    m_pcEntropyDecoder->decodeARPW( pcCU , uiAbsPartIdx , uiDepth );
398#endif
399#endif
400
401#if H_3D_VSP
402    Int vspFlag[MRG_MAX_NUM_CANDS_MEM];
403    memset(vspFlag, 0, sizeof(Int)*MRG_MAX_NUM_CANDS_MEM);
404    InheritedVSPDisInfo inheritedVSPDisInfo[MRG_MAX_NUM_CANDS_MEM];
405#if MTK_SPIVMP_F0110
406    Bool bSPIVMPFlag[MRG_MAX_NUM_CANDS_MEM];
407    memset(bSPIVMPFlag, false, sizeof(Bool)*MRG_MAX_NUM_CANDS_MEM);
408    TComMvField*  pcMvFieldSP;
409    UChar* puhInterDirSP;
410    pcMvFieldSP = new TComMvField[pcCU->getPic()->getPicSym()->getNumPartition()*2]; 
411    puhInterDirSP = new UChar[pcCU->getPic()->getPicSym()->getNumPartition()]; 
412#endif
413#if ETRIKHU_MERGE_REUSE_F0093
414    m_ppcCU[uiDepth]->initAvailableFlags();
415    m_ppcCU[uiDepth]->getInterMergeCandidates( 0, 0, cMvFieldNeighbours, uhInterDirNeighbours, numValidMergeCand, uiMergeIndex );
416    m_ppcCU[uiDepth]->xGetInterMergeCandidates( 0, 0, cMvFieldNeighbours, uhInterDirNeighbours, vspFlag, inheritedVSPDisInfo
417#if MTK_SPIVMP_F0110
418      , bSPIVMPFlag, pcMvFieldSP, puhInterDirSP
419#endif
420      , numValidMergeCand, uiMergeIndex );
421#else
422    m_ppcCU[uiDepth]->getInterMergeCandidates( 0, 0, cMvFieldNeighbours, uhInterDirNeighbours, vspFlag, inheritedVSPDisInfo, numValidMergeCand, uiMergeIndex );
423#endif
424    pcCU->setVSPFlagSubParts( vspFlag[uiMergeIndex], uiAbsPartIdx, 0, uiDepth );
425#else
426#if ETRIKHU_MERGE_REUSE_F0093
427    m_ppcCU[uiDepth]->initAvailableFlags();
428    m_ppcCU[uiDepth]->getInterMergeCandidates( 0, 0, cMvFieldNeighbours, uhInterDirNeighbours, numValidMergeCand, uiMergeIndex );
429    m_ppcCU[uiDepth]->xGetInterMergeCandidates( 0, 0, cMvFieldNeighbours, uhInterDirNeighbours, numValidMergeCand, uiMergeIndex );
430#else
431    m_ppcCU[uiDepth]->getInterMergeCandidates( 0, 0, cMvFieldNeighbours, uhInterDirNeighbours, numValidMergeCand, uiMergeIndex );
432#endif
433#endif
434#if H_3D_VSP
435    if(vspFlag[uiMergeIndex])
436    {
437      pcCU->setDvInfoSubParts(inheritedVSPDisInfo[uiMergeIndex].m_acDvInfo, uiAbsPartIdx, 0, uiDepth);
438    }
439#endif
440    pcCU->setInterDirSubParts( uhInterDirNeighbours[uiMergeIndex], uiAbsPartIdx, 0, uiDepth );
441
442    TComMv cTmpMv( 0, 0 );
443    for ( UInt uiRefListIdx = 0; uiRefListIdx < 2; uiRefListIdx++ )
444    {       
445      if ( pcCU->getSlice()->getNumRefIdx( RefPicList( uiRefListIdx ) ) > 0 )
446      {
447        pcCU->setMVPIdxSubParts( 0, RefPicList( uiRefListIdx ), uiAbsPartIdx, 0, uiDepth);
448        pcCU->setMVPNumSubParts( 0, RefPicList( uiRefListIdx ), uiAbsPartIdx, 0, uiDepth);
449        pcCU->getCUMvField( RefPicList( uiRefListIdx ) )->setAllMvd( cTmpMv, SIZE_2Nx2N, uiAbsPartIdx, uiDepth );
450        pcCU->getCUMvField( RefPicList( uiRefListIdx ) )->setAllMvField( cMvFieldNeighbours[ 2*uiMergeIndex + uiRefListIdx ], SIZE_2Nx2N, uiAbsPartIdx, uiDepth );
451#if ENC_DEC_TRACE && H_MV_ENC_DEC_TRAC   
452        if ( g_decTraceMvFromMerge )
453        {       
454          if ( uiRefListIdx == 0 )
455          {
456            DTRACE_PU( "mvL0[0]", cMvFieldNeighbours[ 2*uiMergeIndex + uiRefListIdx ].getHor());
457            DTRACE_PU( "mvL0[1]", cMvFieldNeighbours[ 2*uiMergeIndex + uiRefListIdx ].getVer());
458            DTRACE_PU( "refIdxL0   ", cMvFieldNeighbours[ 2*uiMergeIndex + uiRefListIdx ].getRefIdx());
459          }
460          else
461          {
462            DTRACE_PU( "mvL1[0]", cMvFieldNeighbours[ 2*uiMergeIndex + uiRefListIdx ].getHor());
463            DTRACE_PU( "mvL1[1]", cMvFieldNeighbours[ 2*uiMergeIndex + uiRefListIdx ].getVer());
464            DTRACE_PU( "refIdxL1", cMvFieldNeighbours[ 2*uiMergeIndex + uiRefListIdx ].getRefIdx());
465          }
466        }
467#endif
468      }
469    }
470#if MTK_SPIVMP_F0110
471    pcCU->setSPIVMPFlagSubParts(bSPIVMPFlag[uiMergeIndex], uiAbsPartIdx, 0, uiDepth ); 
472    if (bSPIVMPFlag[uiMergeIndex])
473    {
474      UInt uiSPAddr;
475      Int iWidth = pcCU->getWidth(uiAbsPartIdx);
476      Int iHeight = pcCU->getHeight(uiAbsPartIdx);
477
478      Int iNumSPInOneLine, iNumSP, iSPWidth, iSPHeight;
479
480      pcCU->getSPPara(iWidth, iHeight, iNumSP, iNumSPInOneLine, iSPWidth, iSPHeight);
481
482      for (Int iPartitionIdx = 0; iPartitionIdx < iNumSP; iPartitionIdx++)
483      {
484        pcCU->getSPAbsPartIdx(uiAbsPartIdx, iSPWidth, iSPHeight, iPartitionIdx, iNumSPInOneLine, uiSPAddr);
485        pcCU->setInterDirSP(puhInterDirSP[iPartitionIdx], uiSPAddr, iSPWidth, iSPHeight);
486        pcCU->getCUMvField( REF_PIC_LIST_0 )->setMvFieldSP(pcCU, uiSPAddr, pcMvFieldSP[2*iPartitionIdx], iSPWidth, iSPHeight);
487        pcCU->getCUMvField( REF_PIC_LIST_1 )->setMvFieldSP(pcCU, uiSPAddr, pcMvFieldSP[2*iPartitionIdx + 1], iSPWidth, iSPHeight);
488      }
489    }
490    delete pcMvFieldSP;
491    delete puhInterDirSP;
492#endif
493#if !LGE_SHARP_VSP_INHERIT_F0104
494#if H_3D_IC
495    m_pcEntropyDecoder->decodeICFlag( pcCU, uiAbsPartIdx, uiDepth );
496#endif
497#if H_3D_ARP
498    m_pcEntropyDecoder->decodeARPW( pcCU , uiAbsPartIdx , uiDepth );
499#endif
500#endif
501
502    xFinishDecodeCU( pcCU, uiAbsPartIdx, uiDepth, ruiIsLast );
503#if QC_DEPTH_IV_MRG_F0125
504    xDecompressCU(pcCU, uiAbsPartIdx, uiDepth );
505#endif
506    return;
507  }
508
509  m_pcEntropyDecoder->decodePredMode( pcCU, uiAbsPartIdx, uiDepth );
510  m_pcEntropyDecoder->decodePartSize( pcCU, uiAbsPartIdx, uiDepth );
511
512  if (pcCU->isIntra( uiAbsPartIdx ) && pcCU->getPartitionSize( uiAbsPartIdx ) == SIZE_2Nx2N )
513  {
514    m_pcEntropyDecoder->decodeIPCMInfo( pcCU, uiAbsPartIdx, uiDepth );
515
516    if(pcCU->getIPCMFlag(uiAbsPartIdx))
517    {
518      xFinishDecodeCU( pcCU, uiAbsPartIdx, uiDepth, ruiIsLast );
519#if QC_DEPTH_IV_MRG_F0125
520      xDecompressCU(pcCU, uiAbsPartIdx, uiDepth );
521#endif
522      return;
523    }
524  }
525
526  UInt uiCurrWidth      = pcCU->getWidth ( uiAbsPartIdx );
527  UInt uiCurrHeight     = pcCU->getHeight( uiAbsPartIdx );
528 
529  // prediction mode ( Intra : direction mode, Inter : Mv, reference idx )
530  m_pcEntropyDecoder->decodePredInfo( pcCU, uiAbsPartIdx, uiDepth, m_ppcCU[uiDepth]);
531#if !LGE_SHARP_VSP_INHERIT_F0104
532#if H_3D_IC
533  m_pcEntropyDecoder->decodeICFlag( pcCU, uiAbsPartIdx, uiDepth );
534#endif
535#if H_3D_ARP
536  m_pcEntropyDecoder->decodeARPW    ( pcCU , uiAbsPartIdx , uiDepth ); 
537#endif 
538#endif
539#if H_3D_INTER_SDC
540  m_pcEntropyDecoder->decodeInterSDCFlag( pcCU, uiAbsPartIdx, uiDepth );
541#endif
542  // Coefficient decoding
543  Bool bCodeDQP = getdQPFlag();
544  m_pcEntropyDecoder->decodeCoeff( pcCU, uiAbsPartIdx, uiDepth, uiCurrWidth, uiCurrHeight, bCodeDQP );
545  setdQPFlag( bCodeDQP );
546  xFinishDecodeCU( pcCU, uiAbsPartIdx, uiDepth, ruiIsLast );
547#if QC_DEPTH_IV_MRG_F0125
548  xDecompressCU(pcCU, uiAbsPartIdx, uiDepth );
549#endif
550}
551
552Void TDecCu::xFinishDecodeCU( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, UInt& ruiIsLast)
553{
554  if(  pcCU->getSlice()->getPPS()->getUseDQP())
555  {
556    pcCU->setQPSubParts( getdQPFlag()?pcCU->getRefQP(uiAbsPartIdx):pcCU->getCodedQP(), uiAbsPartIdx, uiDepth ); // set QP
557  }
558
559  ruiIsLast = xDecodeSliceEnd( pcCU, uiAbsPartIdx, uiDepth);
560}
561
562Void TDecCu::xDecompressCU( TComDataCU* pcCU, UInt uiAbsPartIdx,  UInt uiDepth )
563{
564  TComPic* pcPic = pcCU->getPic();
565#if !QC_DEPTH_IV_MRG_F0125 
566  Bool bBoundary = false;
567  UInt uiLPelX   = pcCU->getCUPelX() + g_auiRasterToPelX[ g_auiZscanToRaster[uiAbsPartIdx] ];
568  UInt uiRPelX   = uiLPelX + (g_uiMaxCUWidth>>uiDepth)  - 1;
569  UInt uiTPelY   = pcCU->getCUPelY() + g_auiRasterToPelY[ g_auiZscanToRaster[uiAbsPartIdx] ];
570  UInt uiBPelY   = uiTPelY + (g_uiMaxCUHeight>>uiDepth) - 1;
571 
572  UInt uiCurNumParts    = pcPic->getNumPartInCU() >> (uiDepth<<1);
573  TComSlice * pcSlice = pcCU->getPic()->getSlice(pcCU->getPic()->getCurrSliceIdx());
574  Bool bStartInCU = pcCU->getSCUAddr()+uiAbsPartIdx+uiCurNumParts>pcSlice->getSliceSegmentCurStartCUAddr()&&pcCU->getSCUAddr()+uiAbsPartIdx<pcSlice->getSliceSegmentCurStartCUAddr();
575  if(bStartInCU||( uiRPelX >= pcSlice->getSPS()->getPicWidthInLumaSamples() ) || ( uiBPelY >= pcSlice->getSPS()->getPicHeightInLumaSamples() ) )
576  {
577    bBoundary = true;
578  }
579 
580  if( ( ( uiDepth < pcCU->getDepth( uiAbsPartIdx ) ) && ( uiDepth < g_uiMaxCUDepth - g_uiAddCUDepth ) ) || bBoundary )
581  {
582    UInt uiNextDepth = uiDepth + 1;
583    UInt uiQNumParts = pcCU->getTotalNumPart() >> (uiNextDepth<<1);
584    UInt uiIdx = uiAbsPartIdx;
585    for ( UInt uiPartIdx = 0; uiPartIdx < 4; uiPartIdx++ )
586    {
587      uiLPelX = pcCU->getCUPelX() + g_auiRasterToPelX[ g_auiZscanToRaster[uiIdx] ];
588      uiTPelY = pcCU->getCUPelY() + g_auiRasterToPelY[ g_auiZscanToRaster[uiIdx] ];
589     
590      Bool binSlice = (pcCU->getSCUAddr()+uiIdx+uiQNumParts>pcSlice->getSliceSegmentCurStartCUAddr())&&(pcCU->getSCUAddr()+uiIdx<pcSlice->getSliceSegmentCurEndCUAddr());
591      if(binSlice&&( uiLPelX < pcSlice->getSPS()->getPicWidthInLumaSamples() ) && ( uiTPelY < pcSlice->getSPS()->getPicHeightInLumaSamples() ) )
592      {
593        xDecompressCU(pcCU, uiIdx, uiNextDepth );
594      }
595     
596      uiIdx += uiQNumParts;
597    }
598    return;
599  }
600#endif 
601  // Residual reconstruction
602  m_ppcYuvResi[uiDepth]->clear();
603 
604  m_ppcCU[uiDepth]->copySubCU( pcCU, uiAbsPartIdx, uiDepth );
605 
606  switch( m_ppcCU[uiDepth]->getPredictionMode(0) )
607  {
608    case MODE_INTER:
609#if H_3D_INTER_SDC
610      if( m_ppcCU[uiDepth]->getInterSDCFlag( 0 ) )
611      {
612        xReconInterSDC( m_ppcCU[uiDepth], uiAbsPartIdx, uiDepth );
613      }
614      else
615      {
616#endif
617      xReconInter( m_ppcCU[uiDepth], uiDepth );
618#if H_3D_INTER_SDC
619      }
620#endif
621      break;
622    case MODE_INTRA:
623#if H_3D_DIM_SDC
624      if( m_ppcCU[uiDepth]->getSDCFlag(0) )
625        xReconIntraSDC( m_ppcCU[uiDepth], 0, uiDepth );
626      else
627#endif
628      xReconIntraQT( m_ppcCU[uiDepth], uiDepth );
629      break;
630    default:
631      assert(0);
632      break;
633  }
634  if ( m_ppcCU[uiDepth]->isLosslessCoded(0) && (m_ppcCU[uiDepth]->getIPCMFlag(0) == false))
635  {
636    xFillPCMBuffer(m_ppcCU[uiDepth], uiDepth);
637  }
638 
639  xCopyToPic( m_ppcCU[uiDepth], pcPic, uiAbsPartIdx, uiDepth );
640}
641
642Void TDecCu::xReconInter( TComDataCU* pcCU, UInt uiDepth )
643{
644 
645  // inter prediction
646  m_pcPrediction->motionCompensation( pcCU, m_ppcYuvReco[uiDepth] );
647 
648  // inter recon
649  xDecodeInterTexture( pcCU, 0, uiDepth );
650 
651  // clip for only non-zero cbp case
652  if  ( ( pcCU->getCbf( 0, TEXT_LUMA ) ) || ( pcCU->getCbf( 0, TEXT_CHROMA_U ) ) || ( pcCU->getCbf(0, TEXT_CHROMA_V ) ) )
653  {
654    m_ppcYuvReco[uiDepth]->addClip( m_ppcYuvReco[uiDepth], m_ppcYuvResi[uiDepth], 0, pcCU->getWidth( 0 ) );
655  }
656  else
657  {
658    m_ppcYuvReco[uiDepth]->copyPartToPartYuv( m_ppcYuvReco[uiDepth],0, pcCU->getWidth( 0 ),pcCU->getHeight( 0 ));
659  }
660}
661
662#if H_3D_INTER_SDC
663Void TDecCu::xReconInterSDC( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
664{
665  // inter prediction
666  m_pcPrediction->motionCompensation( pcCU, m_ppcYuvReco[uiDepth] );
667
668  UInt  uiWidth      = pcCU->getWidth ( 0 );
669  UInt  uiHeight     = pcCU->getHeight( 0 );
670  UChar* pMask       = pcCU->getInterSDCMask();
671
672  memset( pMask, 0, uiWidth*uiHeight );
673  pcCU->xSetInterSDCCUMask( pcCU, pMask );
674
675  Pel  *pResi;
676  UInt uiPelX, uiPelY;
677  UInt uiResiStride = m_ppcYuvResi[uiDepth]->getStride();
678
679  pResi = m_ppcYuvResi[uiDepth]->getLumaAddr( 0 );
680  for( uiPelY = 0; uiPelY < uiHeight; uiPelY++ )
681  {
682    for( uiPelX = 0; uiPelX < uiWidth; uiPelX++ )
683    {
684      UChar uiSeg = pMask[ uiPelX + uiPelY*uiWidth ];
685
686      pResi[ uiPelX ] = pcCU->getInterSDCSegmentDCOffset( uiSeg, 0 );;
687    }
688    pResi += uiResiStride;
689  }
690
691  m_ppcYuvReco[uiDepth]->addClip( m_ppcYuvReco[uiDepth], m_ppcYuvResi[uiDepth], 0, pcCU->getWidth( 0 ) );
692
693  // clear UV
694  UInt  uiStrideC     = m_ppcYuvReco[uiDepth]->getCStride();
695  Pel   *pRecCb       = m_ppcYuvReco[uiDepth]->getCbAddr();
696  Pel   *pRecCr       = m_ppcYuvReco[uiDepth]->getCrAddr();
697
698  for (Int y = 0; y < uiHeight/2; y++)
699  {
700    for (Int x = 0; x < uiWidth/2; x++)
701    {
702      pRecCb[x] = (Pel)( 1 << ( g_bitDepthC - 1 ) );
703      pRecCr[x] = (Pel)( 1 << ( g_bitDepthC - 1 ) );
704    }
705
706    pRecCb += uiStrideC;
707    pRecCr += uiStrideC;
708  }
709}
710#endif
711
712Void
713TDecCu::xIntraRecLumaBlk( TComDataCU* pcCU,
714                         UInt        uiTrDepth,
715                         UInt        uiAbsPartIdx,
716                         TComYuv*    pcRecoYuv,
717                         TComYuv*    pcPredYuv, 
718                         TComYuv*    pcResiYuv )
719{
720  UInt    uiWidth           = pcCU     ->getWidth   ( 0 ) >> uiTrDepth;
721  UInt    uiHeight          = pcCU     ->getHeight  ( 0 ) >> uiTrDepth;
722  UInt    uiStride          = pcRecoYuv->getStride  ();
723  Pel*    piReco            = pcRecoYuv->getLumaAddr( uiAbsPartIdx );
724  Pel*    piPred            = pcPredYuv->getLumaAddr( uiAbsPartIdx );
725  Pel*    piResi            = pcResiYuv->getLumaAddr( uiAbsPartIdx );
726 
727  UInt    uiNumCoeffInc     = ( pcCU->getSlice()->getSPS()->getMaxCUWidth() * pcCU->getSlice()->getSPS()->getMaxCUHeight() ) >> ( pcCU->getSlice()->getSPS()->getMaxCUDepth() << 1 );
728  TCoeff* pcCoeff           = pcCU->getCoeffY() + ( uiNumCoeffInc * uiAbsPartIdx );
729 
730  UInt    uiLumaPredMode    = pcCU->getLumaIntraDir     ( uiAbsPartIdx );
731 
732  UInt    uiZOrder          = pcCU->getZorderIdxInCU() + uiAbsPartIdx;
733  Pel*    piRecIPred        = pcCU->getPic()->getPicYuvRec()->getLumaAddr( pcCU->getAddr(), uiZOrder );
734  UInt    uiRecIPredStride  = pcCU->getPic()->getPicYuvRec()->getStride  ();
735  Bool    useTransformSkip  = pcCU->getTransformSkip(uiAbsPartIdx, TEXT_LUMA);
736  //===== init availability pattern =====
737  Bool  bAboveAvail = false;
738  Bool  bLeftAvail  = false;
739  pcCU->getPattern()->initPattern   ( pcCU, uiTrDepth, uiAbsPartIdx );
740  pcCU->getPattern()->initAdiPattern( pcCU, uiAbsPartIdx, uiTrDepth, 
741                                     m_pcPrediction->getPredicBuf       (),
742                                     m_pcPrediction->getPredicBufWidth  (),
743                                     m_pcPrediction->getPredicBufHeight (),
744                                     bAboveAvail, bLeftAvail );
745 
746  //===== get prediction signal =====
747#if H_3D_DIM
748  if( isDimMode( uiLumaPredMode ) )
749  {
750    m_pcPrediction->predIntraLumaDepth( pcCU, uiAbsPartIdx, uiLumaPredMode, piPred, uiStride, uiWidth, uiHeight );
751  }
752  else
753  {
754#endif
755  m_pcPrediction->predIntraLumaAng( pcCU->getPattern(), uiLumaPredMode, piPred, uiStride, uiWidth, uiHeight, bAboveAvail, bLeftAvail );
756#if H_3D_DIM
757  }
758#endif
759 
760  //===== inverse transform =====
761  m_pcTrQuant->setQPforQuant  ( pcCU->getQP(0), TEXT_LUMA, pcCU->getSlice()->getSPS()->getQpBDOffsetY(), 0 );
762
763  Int scalingListType = (pcCU->isIntra(uiAbsPartIdx) ? 0 : 3) + g_eTTable[(Int)TEXT_LUMA];
764  assert(scalingListType < 6);
765  m_pcTrQuant->invtransformNxN( pcCU->getCUTransquantBypass(uiAbsPartIdx), TEXT_LUMA, pcCU->getLumaIntraDir( uiAbsPartIdx ), piResi, uiStride, pcCoeff, uiWidth, uiHeight, scalingListType, useTransformSkip );
766
767 
768  //===== reconstruction =====
769  Pel* pPred      = piPred;
770  Pel* pResi      = piResi;
771  Pel* pReco      = piReco;
772  Pel* pRecIPred  = piRecIPred;
773  for( UInt uiY = 0; uiY < uiHeight; uiY++ )
774  {
775    for( UInt uiX = 0; uiX < uiWidth; uiX++ )
776    {
777#if LGE_PRED_RES_CODING_DLT_DOMAIN_F0159
778        if( (isDimMode( uiLumaPredMode ) || uiLumaPredMode == HOR_IDX || uiLumaPredMode == VER_IDX || uiLumaPredMode == DC_IDX) && pcCU->getSlice()->getIsDepth() && pcCU->getSlice()->getVPS()->getUseDLTFlag(pcCU->getSlice()->getLayerIdInVps()) )
779        {
780            pReco    [ uiX ] = pcCU->getSlice()->getVPS()->idx2DepthValue( pcCU->getSlice()->getLayerIdInVps(), Clip3( 0, pcCU->getSlice()->getVPS()->getNumDepthValues( pcCU->getSlice()->getLayerIdInVps() ) - 1, pcCU->getSlice()->getVPS()->depthValue2idx( pcCU->getSlice()->getLayerIdInVps(), pPred[ uiX ] ) + pResi[ uiX ] ) );
781        }
782        else
783        {
784      pReco    [ uiX ] = ClipY( pPred[ uiX ] + pResi[ uiX ] );
785        }
786#else
787      pReco    [ uiX ] = ClipY( pPred[ uiX ] + pResi[ uiX ] );
788#endif
789      pRecIPred[ uiX ] = pReco[ uiX ];
790    }
791    pPred     += uiStride;
792    pResi     += uiStride;
793    pReco     += uiStride;
794    pRecIPred += uiRecIPredStride;
795  }
796}
797
798
799Void
800TDecCu::xIntraRecChromaBlk( TComDataCU* pcCU,
801                           UInt        uiTrDepth,
802                           UInt        uiAbsPartIdx,
803                           TComYuv*    pcRecoYuv,
804                           TComYuv*    pcPredYuv, 
805                           TComYuv*    pcResiYuv,
806                           UInt        uiChromaId )
807{
808  UInt uiFullDepth  = pcCU->getDepth( 0 ) + uiTrDepth;
809  UInt uiLog2TrSize = g_aucConvertToBit[ pcCU->getSlice()->getSPS()->getMaxCUWidth() >> uiFullDepth ] + 2;
810
811  if( uiLog2TrSize == 2 )
812  {
813    assert( uiTrDepth > 0 );
814    uiTrDepth--;
815    UInt uiQPDiv = pcCU->getPic()->getNumPartInCU() >> ( ( pcCU->getDepth( 0 ) + uiTrDepth ) << 1 );
816    Bool bFirstQ = ( ( uiAbsPartIdx % uiQPDiv ) == 0 );
817    if( !bFirstQ )
818    {
819      return;
820    }
821  }
822 
823  TextType  eText             = ( uiChromaId > 0 ? TEXT_CHROMA_V : TEXT_CHROMA_U );
824  UInt      uiWidth           = pcCU     ->getWidth   ( 0 ) >> ( uiTrDepth + 1 );
825  UInt      uiHeight          = pcCU     ->getHeight  ( 0 ) >> ( uiTrDepth + 1 );
826  UInt      uiStride          = pcRecoYuv->getCStride ();
827  Pel*      piReco            = ( uiChromaId > 0 ? pcRecoYuv->getCrAddr( uiAbsPartIdx ) : pcRecoYuv->getCbAddr( uiAbsPartIdx ) );
828  Pel*      piPred            = ( uiChromaId > 0 ? pcPredYuv->getCrAddr( uiAbsPartIdx ) : pcPredYuv->getCbAddr( uiAbsPartIdx ) );
829  Pel*      piResi            = ( uiChromaId > 0 ? pcResiYuv->getCrAddr( uiAbsPartIdx ) : pcResiYuv->getCbAddr( uiAbsPartIdx ) );
830 
831  UInt      uiNumCoeffInc     = ( ( pcCU->getSlice()->getSPS()->getMaxCUWidth() * pcCU->getSlice()->getSPS()->getMaxCUHeight() ) >> ( pcCU->getSlice()->getSPS()->getMaxCUDepth() << 1 ) ) >> 2;
832  TCoeff*   pcCoeff           = ( uiChromaId > 0 ? pcCU->getCoeffCr() : pcCU->getCoeffCb() ) + ( uiNumCoeffInc * uiAbsPartIdx );
833 
834  UInt      uiChromaPredMode  = pcCU->getChromaIntraDir( 0 );
835 
836  UInt      uiZOrder          = pcCU->getZorderIdxInCU() + uiAbsPartIdx;
837  Pel*      piRecIPred        = ( uiChromaId > 0 ? pcCU->getPic()->getPicYuvRec()->getCrAddr( pcCU->getAddr(), uiZOrder ) : pcCU->getPic()->getPicYuvRec()->getCbAddr( pcCU->getAddr(), uiZOrder ) );
838  UInt      uiRecIPredStride  = pcCU->getPic()->getPicYuvRec()->getCStride();
839  Bool      useTransformSkipChroma = pcCU->getTransformSkip(uiAbsPartIdx,eText);
840  //===== init availability pattern =====
841  Bool  bAboveAvail = false;
842  Bool  bLeftAvail  = false;
843  pcCU->getPattern()->initPattern         ( pcCU, uiTrDepth, uiAbsPartIdx );
844
845  pcCU->getPattern()->initAdiPatternChroma( pcCU, uiAbsPartIdx, uiTrDepth,
846                                           m_pcPrediction->getPredicBuf       (),
847                                           m_pcPrediction->getPredicBufWidth  (),
848                                           m_pcPrediction->getPredicBufHeight (),
849                                           bAboveAvail, bLeftAvail );
850  Int* pPatChroma   = ( uiChromaId > 0 ? pcCU->getPattern()->getAdiCrBuf( uiWidth, uiHeight, m_pcPrediction->getPredicBuf() ) : pcCU->getPattern()->getAdiCbBuf( uiWidth, uiHeight, m_pcPrediction->getPredicBuf() ) );
851 
852  //===== get prediction signal =====
853  {
854    if( uiChromaPredMode == DM_CHROMA_IDX )
855    {
856      uiChromaPredMode = pcCU->getLumaIntraDir( 0 );
857#if H_3D_DIM
858      mapDepthModeToIntraDir( uiChromaPredMode );
859#endif
860    }
861    m_pcPrediction->predIntraChromaAng( pPatChroma, uiChromaPredMode, piPred, uiStride, uiWidth, uiHeight, bAboveAvail, bLeftAvail ); 
862  }
863
864  //===== inverse transform =====
865  Int curChromaQpOffset;
866  if(eText == TEXT_CHROMA_U)
867  {
868    curChromaQpOffset = pcCU->getSlice()->getPPS()->getChromaCbQpOffset() + pcCU->getSlice()->getSliceQpDeltaCb();
869  }
870  else
871  {
872    curChromaQpOffset = pcCU->getSlice()->getPPS()->getChromaCrQpOffset() + pcCU->getSlice()->getSliceQpDeltaCr();
873  }
874  m_pcTrQuant->setQPforQuant  ( pcCU->getQP(0), eText, pcCU->getSlice()->getSPS()->getQpBDOffsetC(), curChromaQpOffset );
875
876  Int scalingListType = (pcCU->isIntra(uiAbsPartIdx) ? 0 : 3) + g_eTTable[(Int)eText];
877  assert(scalingListType < 6);
878  m_pcTrQuant->invtransformNxN( pcCU->getCUTransquantBypass(uiAbsPartIdx), eText, REG_DCT, piResi, uiStride, pcCoeff, uiWidth, uiHeight, scalingListType, useTransformSkipChroma );
879
880  //===== reconstruction =====
881  Pel* pPred      = piPred;
882  Pel* pResi      = piResi;
883  Pel* pReco      = piReco;
884  Pel* pRecIPred  = piRecIPred;
885  for( UInt uiY = 0; uiY < uiHeight; uiY++ )
886  {
887    for( UInt uiX = 0; uiX < uiWidth; uiX++ )
888    {
889      pReco    [ uiX ] = ClipC( pPred[ uiX ] + pResi[ uiX ] );
890      pRecIPred[ uiX ] = pReco[ uiX ];
891    }
892    pPred     += uiStride;
893    pResi     += uiStride;
894    pReco     += uiStride;
895    pRecIPred += uiRecIPredStride;
896  }
897}
898
899
900Void
901TDecCu::xReconIntraQT( TComDataCU* pcCU, UInt uiDepth )
902{
903  UInt  uiInitTrDepth = ( pcCU->getPartitionSize(0) == SIZE_2Nx2N ? 0 : 1 );
904  UInt  uiNumPart     = pcCU->getNumPartInter();
905  UInt  uiNumQParts   = pcCU->getTotalNumPart() >> 2;
906 
907  if (pcCU->getIPCMFlag(0))
908  {
909    xReconPCM( pcCU, uiDepth );
910    return;
911  }
912
913  for( UInt uiPU = 0; uiPU < uiNumPart; uiPU++ )
914  {
915    xIntraLumaRecQT( pcCU, uiInitTrDepth, uiPU * uiNumQParts, m_ppcYuvReco[uiDepth], m_ppcYuvReco[uiDepth], m_ppcYuvResi[uiDepth] );
916  } 
917
918  for( UInt uiPU = 0; uiPU < uiNumPart; uiPU++ )
919  {
920    xIntraChromaRecQT( pcCU, uiInitTrDepth, uiPU * uiNumQParts, m_ppcYuvReco[uiDepth], m_ppcYuvReco[uiDepth], m_ppcYuvResi[uiDepth] );
921  }
922
923}
924
925#if H_3D_DIM_SDC
926Void TDecCu::xReconIntraSDC( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
927{
928  UInt uiWidth        = pcCU->getWidth  ( 0 );
929  UInt uiHeight       = pcCU->getHeight ( 0 );
930 
931  TComYuv* pcRecoYuv  = m_ppcYuvReco[uiDepth];
932  TComYuv* pcPredYuv  = m_ppcYuvReco[uiDepth];
933  TComYuv* pcResiYuv  = m_ppcYuvResi[uiDepth];
934 
935  UInt    uiStride    = pcRecoYuv->getStride  ();
936  Pel*    piReco      = pcRecoYuv->getLumaAddr( uiAbsPartIdx );
937  Pel*    piPred      = pcPredYuv->getLumaAddr( uiAbsPartIdx );
938  Pel*    piResi      = pcResiYuv->getLumaAddr( uiAbsPartIdx );
939 
940  UInt    uiZOrder          = pcCU->getZorderIdxInCU() + uiAbsPartIdx;
941  Pel*    piRecIPred        = pcCU->getPic()->getPicYuvRec()->getLumaAddr( pcCU->getAddr(), uiZOrder );
942  UInt    uiRecIPredStride  = pcCU->getPic()->getPicYuvRec()->getStride  ();
943 
944  UInt    uiLumaPredMode    = pcCU->getLumaIntraDir     ( uiAbsPartIdx );
945 
946  AOF( uiWidth == uiHeight );
947  AOF( uiAbsPartIdx == 0 );
948  AOF( pcCU->getSDCAvailable(uiAbsPartIdx) );
949  AOF( pcCU->getSDCFlag(uiAbsPartIdx) );
950 
951  //===== init availability pattern =====
952  Bool  bAboveAvail = false;
953  Bool  bLeftAvail  = false;
954  pcCU->getPattern()->initPattern   ( pcCU, 0, uiAbsPartIdx );
955  pcCU->getPattern()->initAdiPattern( pcCU, uiAbsPartIdx, 0, m_pcPrediction->getPredicBuf(), m_pcPrediction->getPredicBufWidth(), m_pcPrediction->getPredicBufHeight(), bAboveAvail, bLeftAvail );
956 
957  //===== get prediction signal =====
958#if H_3D_DIM
959  if( isDimMode( uiLumaPredMode ) )
960  {
961    m_pcPrediction->predIntraLumaDepth( pcCU, uiAbsPartIdx, uiLumaPredMode, piPred, uiStride, uiWidth, uiHeight );
962  }
963  else
964  {
965#endif
966    m_pcPrediction->predIntraLumaAng( pcCU->getPattern(), uiLumaPredMode, piPred, uiStride, uiWidth, uiHeight, bAboveAvail, bLeftAvail );
967#if H_3D_DIM
968  }
969#endif
970 
971  // number of segments depends on prediction mode
972  UInt uiNumSegments = 1;
973  Bool* pbMask = NULL;
974  UInt uiMaskStride = 0;
975 
976  if( getDimType( uiLumaPredMode ) == DMM1_IDX )
977  {
978    Int uiTabIdx = pcCU->getDmmWedgeTabIdx(DMM1_IDX, uiAbsPartIdx);
979   
980    WedgeList* pacWedgeList = &g_dmmWedgeLists[(g_aucConvertToBit[uiWidth])];
981    TComWedgelet* pcWedgelet = &(pacWedgeList->at( uiTabIdx ));
982   
983    uiNumSegments = 2;
984    pbMask = pcWedgelet->getPattern();
985    uiMaskStride = pcWedgelet->getStride();
986  }
987 
988  // get DC prediction for each segment
989  Pel apDCPredValues[2];
990  m_pcPrediction->analyzeSegmentsSDC(piPred, uiStride, uiWidth, apDCPredValues, uiNumSegments, pbMask, uiMaskStride, uiLumaPredMode);
991 
992  // reconstruct residual based on mask + DC residuals
993  Pel apDCResiValues[2];
994  for( UInt uiSegment = 0; uiSegment < uiNumSegments; uiSegment++ )
995  {
996#if H_3D_DIM_DLT
997    Pel   pPredIdx    = pcCU->getSlice()->getVPS()->depthValue2idx( pcCU->getSlice()->getLayerIdInVps(), apDCPredValues[uiSegment] );
998    Pel   pResiIdx    = pcCU->getSDCSegmentDCOffset(uiSegment, uiAbsPartIdx);
999    Pel   pRecoValue  = pcCU->getSlice()->getVPS()->idx2DepthValue( pcCU->getSlice()->getLayerIdInVps(), pPredIdx + pResiIdx );
1000   
1001    apDCResiValues[uiSegment]  = pRecoValue - apDCPredValues[uiSegment];
1002#else
1003    apDCResiValues[uiSegment]  = pcCU->getSDCSegmentDCOffset(uiSegment, uiAbsPartIdx);
1004#endif
1005  }
1006 
1007  //===== reconstruction =====
1008  Bool*pMask      = pbMask;
1009  Pel* pPred      = piPred;
1010  Pel* pResi      = piResi;
1011  Pel* pReco      = piReco;
1012  Pel* pRecIPred  = piRecIPred;
1013 
1014  for( UInt uiY = 0; uiY < uiHeight; uiY++ )
1015  {
1016    for( UInt uiX = 0; uiX < uiWidth; uiX++ )
1017    {
1018      UChar ucSegment = pMask?(UChar)pMask[uiX]:0;
1019      assert( ucSegment < uiNumSegments );
1020     
1021      Pel pResiDC = apDCResiValues[ucSegment];
1022     
1023      pReco    [ uiX ] = ClipY( pPred[ uiX ] + pResiDC );
1024      pRecIPred[ uiX ] = pReco[ uiX ];
1025    }
1026    pPred     += uiStride;
1027    pResi     += uiStride;
1028    pReco     += uiStride;
1029    pRecIPred += uiRecIPredStride;
1030    pMask     += uiMaskStride;
1031  }
1032 
1033  // clear UV
1034  UInt  uiStrideC     = pcPredYuv->getCStride();
1035  Pel   *pRecCb       = pcPredYuv->getCbAddr();
1036  Pel   *pRecCr       = pcPredYuv->getCrAddr();
1037 
1038  for (Int y=0; y<uiHeight/2; y++)
1039  {
1040    for (Int x=0; x<uiWidth/2; x++)
1041    {
1042      pRecCb[x] = 128;
1043      pRecCr[x] = 128;
1044    }
1045   
1046    pRecCb += uiStrideC;
1047    pRecCr += uiStrideC;
1048  }
1049}
1050#endif
1051
1052/** Function for deriving recontructed PU/CU Luma sample with QTree structure
1053 * \param pcCU pointer of current CU
1054 * \param uiTrDepth current tranform split depth
1055 * \param uiAbsPartIdx  part index
1056 * \param pcRecoYuv pointer to reconstructed sample arrays
1057 * \param pcPredYuv pointer to prediction sample arrays
1058 * \param pcResiYuv pointer to residue sample arrays
1059 *
1060 \ This function dervies recontructed PU/CU Luma sample with recursive QTree structure
1061 */
1062Void
1063TDecCu::xIntraLumaRecQT( TComDataCU* pcCU,
1064                     UInt        uiTrDepth,
1065                     UInt        uiAbsPartIdx,
1066                     TComYuv*    pcRecoYuv,
1067                     TComYuv*    pcPredYuv, 
1068                     TComYuv*    pcResiYuv )
1069{
1070  UInt uiFullDepth  = pcCU->getDepth(0) + uiTrDepth;
1071  UInt uiTrMode     = pcCU->getTransformIdx( uiAbsPartIdx );
1072  if( uiTrMode == uiTrDepth )
1073  {
1074    xIntraRecLumaBlk  ( pcCU, uiTrDepth, uiAbsPartIdx, pcRecoYuv, pcPredYuv, pcResiYuv );
1075  }
1076  else
1077  {
1078    UInt uiNumQPart  = pcCU->getPic()->getNumPartInCU() >> ( ( uiFullDepth + 1 ) << 1 );
1079    for( UInt uiPart = 0; uiPart < 4; uiPart++ )
1080    {
1081      xIntraLumaRecQT( pcCU, uiTrDepth + 1, uiAbsPartIdx + uiPart * uiNumQPart, pcRecoYuv, pcPredYuv, pcResiYuv );
1082    }
1083  }
1084}
1085
1086/** Function for deriving recontructed PU/CU chroma samples with QTree structure
1087 * \param pcCU pointer of current CU
1088 * \param uiTrDepth current tranform split depth
1089 * \param uiAbsPartIdx  part index
1090 * \param pcRecoYuv pointer to reconstructed sample arrays
1091 * \param pcPredYuv pointer to prediction sample arrays
1092 * \param pcResiYuv pointer to residue sample arrays
1093 *
1094 \ This function dervies recontructed PU/CU chroma samples with QTree recursive structure
1095 */
1096Void
1097TDecCu::xIntraChromaRecQT( TComDataCU* pcCU,
1098                     UInt        uiTrDepth,
1099                     UInt        uiAbsPartIdx,
1100                     TComYuv*    pcRecoYuv,
1101                     TComYuv*    pcPredYuv, 
1102                     TComYuv*    pcResiYuv )
1103{
1104  UInt uiFullDepth  = pcCU->getDepth(0) + uiTrDepth;
1105  UInt uiTrMode     = pcCU->getTransformIdx( uiAbsPartIdx );
1106  if( uiTrMode == uiTrDepth )
1107  {
1108    xIntraRecChromaBlk( pcCU, uiTrDepth, uiAbsPartIdx, pcRecoYuv, pcPredYuv, pcResiYuv, 0 );
1109    xIntraRecChromaBlk( pcCU, uiTrDepth, uiAbsPartIdx, pcRecoYuv, pcPredYuv, pcResiYuv, 1 );
1110  }
1111  else
1112  {
1113    UInt uiNumQPart  = pcCU->getPic()->getNumPartInCU() >> ( ( uiFullDepth + 1 ) << 1 );
1114    for( UInt uiPart = 0; uiPart < 4; uiPart++ )
1115    {
1116      xIntraChromaRecQT( pcCU, uiTrDepth + 1, uiAbsPartIdx + uiPart * uiNumQPart, pcRecoYuv, pcPredYuv, pcResiYuv );
1117    }
1118  }
1119}
1120
1121Void TDecCu::xCopyToPic( TComDataCU* pcCU, TComPic* pcPic, UInt uiZorderIdx, UInt uiDepth )
1122{
1123  UInt uiCUAddr = pcCU->getAddr();
1124 
1125  m_ppcYuvReco[uiDepth]->copyToPicYuv  ( pcPic->getPicYuvRec (), uiCUAddr, uiZorderIdx );
1126 
1127  return;
1128}
1129
1130Void TDecCu::xDecodeInterTexture ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
1131{
1132  UInt    uiWidth    = pcCU->getWidth ( uiAbsPartIdx );
1133  UInt    uiHeight   = pcCU->getHeight( uiAbsPartIdx );
1134  TCoeff* piCoeff;
1135 
1136  Pel*    pResi;
1137  UInt    trMode = pcCU->getTransformIdx( uiAbsPartIdx );
1138 
1139  // Y
1140  piCoeff = pcCU->getCoeffY();
1141  pResi = m_ppcYuvResi[uiDepth]->getLumaAddr();
1142
1143  m_pcTrQuant->setQPforQuant( pcCU->getQP( uiAbsPartIdx ), TEXT_LUMA, pcCU->getSlice()->getSPS()->getQpBDOffsetY(), 0 );
1144
1145  m_pcTrQuant->invRecurTransformNxN ( pcCU, 0, TEXT_LUMA, pResi, 0, m_ppcYuvResi[uiDepth]->getStride(), uiWidth, uiHeight, trMode, 0, piCoeff );
1146 
1147  // Cb and Cr
1148  Int curChromaQpOffset = pcCU->getSlice()->getPPS()->getChromaCbQpOffset() + pcCU->getSlice()->getSliceQpDeltaCb();
1149  m_pcTrQuant->setQPforQuant( pcCU->getQP( uiAbsPartIdx ), TEXT_CHROMA, pcCU->getSlice()->getSPS()->getQpBDOffsetC(), curChromaQpOffset );
1150
1151  uiWidth  >>= 1;
1152  uiHeight >>= 1;
1153  piCoeff = pcCU->getCoeffCb(); pResi = m_ppcYuvResi[uiDepth]->getCbAddr();
1154  m_pcTrQuant->invRecurTransformNxN ( pcCU, 0, TEXT_CHROMA_U, pResi, 0, m_ppcYuvResi[uiDepth]->getCStride(), uiWidth, uiHeight, trMode, 0, piCoeff );
1155
1156  curChromaQpOffset = pcCU->getSlice()->getPPS()->getChromaCrQpOffset() + pcCU->getSlice()->getSliceQpDeltaCr();
1157  m_pcTrQuant->setQPforQuant( pcCU->getQP( uiAbsPartIdx ), TEXT_CHROMA, pcCU->getSlice()->getSPS()->getQpBDOffsetC(), curChromaQpOffset );
1158
1159  piCoeff = pcCU->getCoeffCr(); pResi = m_ppcYuvResi[uiDepth]->getCrAddr();
1160  m_pcTrQuant->invRecurTransformNxN ( pcCU, 0, TEXT_CHROMA_V, pResi, 0, m_ppcYuvResi[uiDepth]->getCStride(), uiWidth, uiHeight, trMode, 0, piCoeff );
1161}
1162
1163/** Function for deriving reconstructed luma/chroma samples of a PCM mode CU.
1164 * \param pcCU pointer to current CU
1165 * \param uiPartIdx part index
1166 * \param piPCM pointer to PCM code arrays
1167 * \param piReco pointer to reconstructed sample arrays
1168 * \param uiStride stride of reconstructed sample arrays
1169 * \param uiWidth CU width
1170 * \param uiHeight CU height
1171 * \param ttText texture component type
1172 * \returns Void
1173 */
1174Void TDecCu::xDecodePCMTexture( TComDataCU* pcCU, UInt uiPartIdx, Pel *piPCM, Pel* piReco, UInt uiStride, UInt uiWidth, UInt uiHeight, TextType ttText)
1175{
1176  UInt uiX, uiY;
1177  Pel* piPicReco;
1178  UInt uiPicStride;
1179  UInt uiPcmLeftShiftBit; 
1180
1181  if( ttText == TEXT_LUMA )
1182  {
1183    uiPicStride   = pcCU->getPic()->getPicYuvRec()->getStride();
1184    piPicReco = pcCU->getPic()->getPicYuvRec()->getLumaAddr(pcCU->getAddr(), pcCU->getZorderIdxInCU()+uiPartIdx);
1185    uiPcmLeftShiftBit = g_bitDepthY - pcCU->getSlice()->getSPS()->getPCMBitDepthLuma();
1186  }
1187  else
1188  {
1189    uiPicStride = pcCU->getPic()->getPicYuvRec()->getCStride();
1190
1191    if( ttText == TEXT_CHROMA_U )
1192    {
1193      piPicReco = pcCU->getPic()->getPicYuvRec()->getCbAddr(pcCU->getAddr(), pcCU->getZorderIdxInCU()+uiPartIdx);
1194    }
1195    else
1196    {
1197      piPicReco = pcCU->getPic()->getPicYuvRec()->getCrAddr(pcCU->getAddr(), pcCU->getZorderIdxInCU()+uiPartIdx);
1198    }
1199    uiPcmLeftShiftBit = g_bitDepthC - pcCU->getSlice()->getSPS()->getPCMBitDepthChroma();
1200  }
1201
1202  for( uiY = 0; uiY < uiHeight; uiY++ )
1203  {
1204    for( uiX = 0; uiX < uiWidth; uiX++ )
1205    {
1206      piReco[uiX] = (piPCM[uiX] << uiPcmLeftShiftBit);
1207      piPicReco[uiX] = piReco[uiX];
1208    }
1209    piPCM += uiWidth;
1210    piReco += uiStride;
1211    piPicReco += uiPicStride;
1212  }
1213}
1214
1215/** Function for reconstructing a PCM mode CU.
1216 * \param pcCU pointer to current CU
1217 * \param uiDepth CU Depth
1218 * \returns Void
1219 */
1220Void TDecCu::xReconPCM( TComDataCU* pcCU, UInt uiDepth )
1221{
1222  // Luma
1223  UInt uiWidth  = (g_uiMaxCUWidth >> uiDepth);
1224  UInt uiHeight = (g_uiMaxCUHeight >> uiDepth);
1225
1226  Pel* piPcmY = pcCU->getPCMSampleY();
1227  Pel* piRecoY = m_ppcYuvReco[uiDepth]->getLumaAddr(0, uiWidth);
1228
1229  UInt uiStride = m_ppcYuvResi[uiDepth]->getStride();
1230
1231  xDecodePCMTexture( pcCU, 0, piPcmY, piRecoY, uiStride, uiWidth, uiHeight, TEXT_LUMA);
1232
1233  // Cb and Cr
1234  UInt uiCWidth  = (uiWidth>>1);
1235  UInt uiCHeight = (uiHeight>>1);
1236
1237  Pel* piPcmCb = pcCU->getPCMSampleCb();
1238  Pel* piPcmCr = pcCU->getPCMSampleCr();
1239  Pel* pRecoCb = m_ppcYuvReco[uiDepth]->getCbAddr();
1240  Pel* pRecoCr = m_ppcYuvReco[uiDepth]->getCrAddr();
1241
1242  UInt uiCStride = m_ppcYuvReco[uiDepth]->getCStride();
1243
1244  xDecodePCMTexture( pcCU, 0, piPcmCb, pRecoCb, uiCStride, uiCWidth, uiCHeight, TEXT_CHROMA_U);
1245  xDecodePCMTexture( pcCU, 0, piPcmCr, pRecoCr, uiCStride, uiCWidth, uiCHeight, TEXT_CHROMA_V);
1246}
1247
1248/** Function for filling the PCM buffer of a CU using its reconstructed sample array
1249 * \param pcCU pointer to current CU
1250 * \param uiDepth CU Depth
1251 * \returns Void
1252 */
1253Void TDecCu::xFillPCMBuffer(TComDataCU* pCU, UInt depth)
1254{
1255  // Luma
1256  UInt width  = (g_uiMaxCUWidth >> depth);
1257  UInt height = (g_uiMaxCUHeight >> depth);
1258
1259  Pel* pPcmY = pCU->getPCMSampleY();
1260  Pel* pRecoY = m_ppcYuvReco[depth]->getLumaAddr(0, width);
1261
1262  UInt stride = m_ppcYuvReco[depth]->getStride();
1263
1264  for(Int y = 0; y < height; y++ )
1265  {
1266    for(Int x = 0; x < width; x++ )
1267    {
1268      pPcmY[x] = pRecoY[x];
1269    }
1270    pPcmY += width;
1271    pRecoY += stride;
1272  }
1273
1274  // Cb and Cr
1275  UInt widthC  = (width>>1);
1276  UInt heightC = (height>>1);
1277
1278  Pel* pPcmCb = pCU->getPCMSampleCb();
1279  Pel* pPcmCr = pCU->getPCMSampleCr();
1280  Pel* pRecoCb = m_ppcYuvReco[depth]->getCbAddr();
1281  Pel* pRecoCr = m_ppcYuvReco[depth]->getCrAddr();
1282
1283  UInt strideC = m_ppcYuvReco[depth]->getCStride();
1284
1285  for(Int y = 0; y < heightC; y++ )
1286  {
1287    for(Int x = 0; x < widthC; x++ )
1288    {
1289      pPcmCb[x] = pRecoCb[x];
1290      pPcmCr[x] = pRecoCr[x];
1291    }
1292    pPcmCr += widthC;
1293    pPcmCb += widthC;
1294    pRecoCb += strideC;
1295    pRecoCr += strideC;
1296  }
1297
1298}
1299
1300//! \}
Note: See TracBrowser for help on using the repository browser.