source: 3DVCSoftware/branches/HTM-9.3-dev1-MediaTek/source/Lib/TLibDecoder/TDecCu.cpp @ 795

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

Integration of DDD (JCT3V-G0063)

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