source: 3DVCSoftware/branches/HTM-8.2-dev3-Samsung/source/Lib/TLibDecoder/TDecCu.cpp @ 697

Last change on this file since 697 was 697, checked in by samsung-htm, 12 years ago

Integration of F0147: DMM simplification and signalling

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