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

Last change on this file since 655 was 655, checked in by tech, 11 years ago

Merged 8.1-Cleanup@654

  • Property svn:eol-style set to native
File size: 43.7 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      pReco    [ uiX ] = ClipY( pPred[ uiX ] + pResi[ uiX ] );
696      pRecIPred[ uiX ] = pReco[ uiX ];
697    }
698    pPred     += uiStride;
699    pResi     += uiStride;
700    pReco     += uiStride;
701    pRecIPred += uiRecIPredStride;
702  }
703}
704
705
706Void
707TDecCu::xIntraRecChromaBlk( TComDataCU* pcCU,
708                           UInt        uiTrDepth,
709                           UInt        uiAbsPartIdx,
710                           TComYuv*    pcRecoYuv,
711                           TComYuv*    pcPredYuv, 
712                           TComYuv*    pcResiYuv,
713                           UInt        uiChromaId )
714{
715  UInt uiFullDepth  = pcCU->getDepth( 0 ) + uiTrDepth;
716  UInt uiLog2TrSize = g_aucConvertToBit[ pcCU->getSlice()->getSPS()->getMaxCUWidth() >> uiFullDepth ] + 2;
717
718  if( uiLog2TrSize == 2 )
719  {
720    assert( uiTrDepth > 0 );
721    uiTrDepth--;
722    UInt uiQPDiv = pcCU->getPic()->getNumPartInCU() >> ( ( pcCU->getDepth( 0 ) + uiTrDepth ) << 1 );
723    Bool bFirstQ = ( ( uiAbsPartIdx % uiQPDiv ) == 0 );
724    if( !bFirstQ )
725    {
726      return;
727    }
728  }
729 
730  TextType  eText             = ( uiChromaId > 0 ? TEXT_CHROMA_V : TEXT_CHROMA_U );
731  UInt      uiWidth           = pcCU     ->getWidth   ( 0 ) >> ( uiTrDepth + 1 );
732  UInt      uiHeight          = pcCU     ->getHeight  ( 0 ) >> ( uiTrDepth + 1 );
733  UInt      uiStride          = pcRecoYuv->getCStride ();
734  Pel*      piReco            = ( uiChromaId > 0 ? pcRecoYuv->getCrAddr( uiAbsPartIdx ) : pcRecoYuv->getCbAddr( uiAbsPartIdx ) );
735  Pel*      piPred            = ( uiChromaId > 0 ? pcPredYuv->getCrAddr( uiAbsPartIdx ) : pcPredYuv->getCbAddr( uiAbsPartIdx ) );
736  Pel*      piResi            = ( uiChromaId > 0 ? pcResiYuv->getCrAddr( uiAbsPartIdx ) : pcResiYuv->getCbAddr( uiAbsPartIdx ) );
737 
738  UInt      uiNumCoeffInc     = ( ( pcCU->getSlice()->getSPS()->getMaxCUWidth() * pcCU->getSlice()->getSPS()->getMaxCUHeight() ) >> ( pcCU->getSlice()->getSPS()->getMaxCUDepth() << 1 ) ) >> 2;
739  TCoeff*   pcCoeff           = ( uiChromaId > 0 ? pcCU->getCoeffCr() : pcCU->getCoeffCb() ) + ( uiNumCoeffInc * uiAbsPartIdx );
740 
741  UInt      uiChromaPredMode  = pcCU->getChromaIntraDir( 0 );
742 
743  UInt      uiZOrder          = pcCU->getZorderIdxInCU() + uiAbsPartIdx;
744  Pel*      piRecIPred        = ( uiChromaId > 0 ? pcCU->getPic()->getPicYuvRec()->getCrAddr( pcCU->getAddr(), uiZOrder ) : pcCU->getPic()->getPicYuvRec()->getCbAddr( pcCU->getAddr(), uiZOrder ) );
745  UInt      uiRecIPredStride  = pcCU->getPic()->getPicYuvRec()->getCStride();
746  Bool      useTransformSkipChroma = pcCU->getTransformSkip(uiAbsPartIdx,eText);
747  //===== init availability pattern =====
748  Bool  bAboveAvail = false;
749  Bool  bLeftAvail  = false;
750  pcCU->getPattern()->initPattern         ( pcCU, uiTrDepth, uiAbsPartIdx );
751
752  pcCU->getPattern()->initAdiPatternChroma( pcCU, uiAbsPartIdx, uiTrDepth,
753                                           m_pcPrediction->getPredicBuf       (),
754                                           m_pcPrediction->getPredicBufWidth  (),
755                                           m_pcPrediction->getPredicBufHeight (),
756                                           bAboveAvail, bLeftAvail );
757  Int* pPatChroma   = ( uiChromaId > 0 ? pcCU->getPattern()->getAdiCrBuf( uiWidth, uiHeight, m_pcPrediction->getPredicBuf() ) : pcCU->getPattern()->getAdiCbBuf( uiWidth, uiHeight, m_pcPrediction->getPredicBuf() ) );
758 
759  //===== get prediction signal =====
760  {
761    if( uiChromaPredMode == DM_CHROMA_IDX )
762    {
763      uiChromaPredMode = pcCU->getLumaIntraDir( 0 );
764#if H_3D_DIM
765      mapDepthModeToIntraDir( uiChromaPredMode );
766#endif
767    }
768    m_pcPrediction->predIntraChromaAng( pPatChroma, uiChromaPredMode, piPred, uiStride, uiWidth, uiHeight, bAboveAvail, bLeftAvail ); 
769  }
770
771  //===== inverse transform =====
772  Int curChromaQpOffset;
773  if(eText == TEXT_CHROMA_U)
774  {
775    curChromaQpOffset = pcCU->getSlice()->getPPS()->getChromaCbQpOffset() + pcCU->getSlice()->getSliceQpDeltaCb();
776  }
777  else
778  {
779    curChromaQpOffset = pcCU->getSlice()->getPPS()->getChromaCrQpOffset() + pcCU->getSlice()->getSliceQpDeltaCr();
780  }
781  m_pcTrQuant->setQPforQuant  ( pcCU->getQP(0), eText, pcCU->getSlice()->getSPS()->getQpBDOffsetC(), curChromaQpOffset );
782
783  Int scalingListType = (pcCU->isIntra(uiAbsPartIdx) ? 0 : 3) + g_eTTable[(Int)eText];
784  assert(scalingListType < 6);
785  m_pcTrQuant->invtransformNxN( pcCU->getCUTransquantBypass(uiAbsPartIdx), eText, REG_DCT, piResi, uiStride, pcCoeff, uiWidth, uiHeight, scalingListType, useTransformSkipChroma );
786
787  //===== reconstruction =====
788  Pel* pPred      = piPred;
789  Pel* pResi      = piResi;
790  Pel* pReco      = piReco;
791  Pel* pRecIPred  = piRecIPred;
792  for( UInt uiY = 0; uiY < uiHeight; uiY++ )
793  {
794    for( UInt uiX = 0; uiX < uiWidth; uiX++ )
795    {
796      pReco    [ uiX ] = ClipC( pPred[ uiX ] + pResi[ uiX ] );
797      pRecIPred[ uiX ] = pReco[ uiX ];
798    }
799    pPred     += uiStride;
800    pResi     += uiStride;
801    pReco     += uiStride;
802    pRecIPred += uiRecIPredStride;
803  }
804}
805
806
807Void
808TDecCu::xReconIntraQT( TComDataCU* pcCU, UInt uiDepth )
809{
810  UInt  uiInitTrDepth = ( pcCU->getPartitionSize(0) == SIZE_2Nx2N ? 0 : 1 );
811  UInt  uiNumPart     = pcCU->getNumPartInter();
812  UInt  uiNumQParts   = pcCU->getTotalNumPart() >> 2;
813 
814  if (pcCU->getIPCMFlag(0))
815  {
816    xReconPCM( pcCU, uiDepth );
817    return;
818  }
819
820  for( UInt uiPU = 0; uiPU < uiNumPart; uiPU++ )
821  {
822    xIntraLumaRecQT( pcCU, uiInitTrDepth, uiPU * uiNumQParts, m_ppcYuvReco[uiDepth], m_ppcYuvReco[uiDepth], m_ppcYuvResi[uiDepth] );
823  } 
824
825  for( UInt uiPU = 0; uiPU < uiNumPart; uiPU++ )
826  {
827    xIntraChromaRecQT( pcCU, uiInitTrDepth, uiPU * uiNumQParts, m_ppcYuvReco[uiDepth], m_ppcYuvReco[uiDepth], m_ppcYuvResi[uiDepth] );
828  }
829
830}
831
832#if H_3D_DIM_SDC
833Void TDecCu::xReconIntraSDC( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
834{
835  UInt uiWidth        = pcCU->getWidth  ( 0 );
836  UInt uiHeight       = pcCU->getHeight ( 0 );
837 
838  TComYuv* pcRecoYuv  = m_ppcYuvReco[uiDepth];
839  TComYuv* pcPredYuv  = m_ppcYuvReco[uiDepth];
840  TComYuv* pcResiYuv  = m_ppcYuvResi[uiDepth];
841 
842  UInt    uiStride    = pcRecoYuv->getStride  ();
843  Pel*    piReco      = pcRecoYuv->getLumaAddr( uiAbsPartIdx );
844  Pel*    piPred      = pcPredYuv->getLumaAddr( uiAbsPartIdx );
845  Pel*    piResi      = pcResiYuv->getLumaAddr( uiAbsPartIdx );
846 
847  UInt    uiZOrder          = pcCU->getZorderIdxInCU() + uiAbsPartIdx;
848  Pel*    piRecIPred        = pcCU->getPic()->getPicYuvRec()->getLumaAddr( pcCU->getAddr(), uiZOrder );
849  UInt    uiRecIPredStride  = pcCU->getPic()->getPicYuvRec()->getStride  ();
850 
851  UInt    uiLumaPredMode    = pcCU->getLumaIntraDir     ( uiAbsPartIdx );
852 
853  AOF( uiWidth == uiHeight );
854  AOF( uiAbsPartIdx == 0 );
855  AOF( pcCU->getSDCAvailable(uiAbsPartIdx) );
856  AOF( pcCU->getSDCFlag(uiAbsPartIdx) );
857 
858  //===== init availability pattern =====
859  Bool  bAboveAvail = false;
860  Bool  bLeftAvail  = false;
861  pcCU->getPattern()->initPattern   ( pcCU, 0, uiAbsPartIdx );
862  pcCU->getPattern()->initAdiPattern( pcCU, uiAbsPartIdx, 0, m_pcPrediction->getPredicBuf(), m_pcPrediction->getPredicBufWidth(), m_pcPrediction->getPredicBufHeight(), bAboveAvail, bLeftAvail );
863 
864  //===== get prediction signal =====
865#if H_3D_DIM
866  if( isDimMode( uiLumaPredMode ) )
867  {
868    m_pcPrediction->predIntraLumaDepth( pcCU, uiAbsPartIdx, uiLumaPredMode, piPred, uiStride, uiWidth, uiHeight );
869  }
870  else
871  {
872#endif
873    m_pcPrediction->predIntraLumaAng( pcCU->getPattern(), uiLumaPredMode, piPred, uiStride, uiWidth, uiHeight, bAboveAvail, bLeftAvail );
874#if H_3D_DIM
875  }
876#endif
877 
878  // number of segments depends on prediction mode
879  UInt uiNumSegments = 1;
880  Bool* pbMask = NULL;
881  UInt uiMaskStride = 0;
882 
883  if( getDimType( uiLumaPredMode ) == DMM1_IDX )
884  {
885    Int uiTabIdx = pcCU->getDmmWedgeTabIdx(DMM1_IDX, uiAbsPartIdx);
886   
887    WedgeList* pacWedgeList = &g_dmmWedgeLists[(g_aucConvertToBit[uiWidth])];
888    TComWedgelet* pcWedgelet = &(pacWedgeList->at( uiTabIdx ));
889   
890    uiNumSegments = 2;
891    pbMask = pcWedgelet->getPattern();
892    uiMaskStride = pcWedgelet->getStride();
893  }
894 
895  // get DC prediction for each segment
896  Pel apDCPredValues[2];
897  m_pcPrediction->analyzeSegmentsSDC(piPred, uiStride, uiWidth, apDCPredValues, uiNumSegments, pbMask, uiMaskStride, uiLumaPredMode);
898 
899  // reconstruct residual based on mask + DC residuals
900  Pel apDCResiValues[2];
901  for( UInt uiSegment = 0; uiSegment < uiNumSegments; uiSegment++ )
902  {
903#if H_3D_DIM_DLT
904    Pel   pPredIdx    = pcCU->getSlice()->getVPS()->depthValue2idx( pcCU->getSlice()->getLayerIdInVps(), apDCPredValues[uiSegment] );
905    Pel   pResiIdx    = pcCU->getSDCSegmentDCOffset(uiSegment, uiAbsPartIdx);
906    Pel   pRecoValue  = pcCU->getSlice()->getVPS()->idx2DepthValue( pcCU->getSlice()->getLayerIdInVps(), pPredIdx + pResiIdx );
907   
908    apDCResiValues[uiSegment]  = pRecoValue - apDCPredValues[uiSegment];
909#else
910    apDCResiValues[uiSegment]  = pcCU->getSDCSegmentDCOffset(uiSegment, uiAbsPartIdx);
911#endif
912  }
913 
914  //===== reconstruction =====
915  Bool*pMask      = pbMask;
916  Pel* pPred      = piPred;
917  Pel* pResi      = piResi;
918  Pel* pReco      = piReco;
919  Pel* pRecIPred  = piRecIPred;
920 
921  for( UInt uiY = 0; uiY < uiHeight; uiY++ )
922  {
923    for( UInt uiX = 0; uiX < uiWidth; uiX++ )
924    {
925      UChar ucSegment = pMask?(UChar)pMask[uiX]:0;
926      assert( ucSegment < uiNumSegments );
927     
928      Pel pResiDC = apDCResiValues[ucSegment];
929     
930      pReco    [ uiX ] = ClipY( pPred[ uiX ] + pResiDC );
931      pRecIPred[ uiX ] = pReco[ uiX ];
932    }
933    pPred     += uiStride;
934    pResi     += uiStride;
935    pReco     += uiStride;
936    pRecIPred += uiRecIPredStride;
937    pMask     += uiMaskStride;
938  }
939 
940  // clear UV
941  UInt  uiStrideC     = pcPredYuv->getCStride();
942  Pel   *pRecCb       = pcPredYuv->getCbAddr();
943  Pel   *pRecCr       = pcPredYuv->getCrAddr();
944 
945  for (Int y=0; y<uiHeight/2; y++)
946  {
947    for (Int x=0; x<uiWidth/2; x++)
948    {
949      pRecCb[x] = 128;
950      pRecCr[x] = 128;
951    }
952   
953    pRecCb += uiStrideC;
954    pRecCr += uiStrideC;
955  }
956}
957#endif
958
959/** Function for deriving recontructed PU/CU Luma sample with QTree structure
960 * \param pcCU pointer of current CU
961 * \param uiTrDepth current tranform split depth
962 * \param uiAbsPartIdx  part index
963 * \param pcRecoYuv pointer to reconstructed sample arrays
964 * \param pcPredYuv pointer to prediction sample arrays
965 * \param pcResiYuv pointer to residue sample arrays
966 *
967 \ This function dervies recontructed PU/CU Luma sample with recursive QTree structure
968 */
969Void
970TDecCu::xIntraLumaRecQT( TComDataCU* pcCU,
971                     UInt        uiTrDepth,
972                     UInt        uiAbsPartIdx,
973                     TComYuv*    pcRecoYuv,
974                     TComYuv*    pcPredYuv, 
975                     TComYuv*    pcResiYuv )
976{
977  UInt uiFullDepth  = pcCU->getDepth(0) + uiTrDepth;
978  UInt uiTrMode     = pcCU->getTransformIdx( uiAbsPartIdx );
979  if( uiTrMode == uiTrDepth )
980  {
981    xIntraRecLumaBlk  ( pcCU, uiTrDepth, uiAbsPartIdx, pcRecoYuv, pcPredYuv, pcResiYuv );
982  }
983  else
984  {
985    UInt uiNumQPart  = pcCU->getPic()->getNumPartInCU() >> ( ( uiFullDepth + 1 ) << 1 );
986    for( UInt uiPart = 0; uiPart < 4; uiPart++ )
987    {
988      xIntraLumaRecQT( pcCU, uiTrDepth + 1, uiAbsPartIdx + uiPart * uiNumQPart, pcRecoYuv, pcPredYuv, pcResiYuv );
989    }
990  }
991}
992
993/** Function for deriving recontructed PU/CU chroma samples with QTree structure
994 * \param pcCU pointer of current CU
995 * \param uiTrDepth current tranform split depth
996 * \param uiAbsPartIdx  part index
997 * \param pcRecoYuv pointer to reconstructed sample arrays
998 * \param pcPredYuv pointer to prediction sample arrays
999 * \param pcResiYuv pointer to residue sample arrays
1000 *
1001 \ This function dervies recontructed PU/CU chroma samples with QTree recursive structure
1002 */
1003Void
1004TDecCu::xIntraChromaRecQT( TComDataCU* pcCU,
1005                     UInt        uiTrDepth,
1006                     UInt        uiAbsPartIdx,
1007                     TComYuv*    pcRecoYuv,
1008                     TComYuv*    pcPredYuv, 
1009                     TComYuv*    pcResiYuv )
1010{
1011  UInt uiFullDepth  = pcCU->getDepth(0) + uiTrDepth;
1012  UInt uiTrMode     = pcCU->getTransformIdx( uiAbsPartIdx );
1013  if( uiTrMode == uiTrDepth )
1014  {
1015    xIntraRecChromaBlk( pcCU, uiTrDepth, uiAbsPartIdx, pcRecoYuv, pcPredYuv, pcResiYuv, 0 );
1016    xIntraRecChromaBlk( pcCU, uiTrDepth, uiAbsPartIdx, pcRecoYuv, pcPredYuv, pcResiYuv, 1 );
1017  }
1018  else
1019  {
1020    UInt uiNumQPart  = pcCU->getPic()->getNumPartInCU() >> ( ( uiFullDepth + 1 ) << 1 );
1021    for( UInt uiPart = 0; uiPart < 4; uiPart++ )
1022    {
1023      xIntraChromaRecQT( pcCU, uiTrDepth + 1, uiAbsPartIdx + uiPart * uiNumQPart, pcRecoYuv, pcPredYuv, pcResiYuv );
1024    }
1025  }
1026}
1027
1028Void TDecCu::xCopyToPic( TComDataCU* pcCU, TComPic* pcPic, UInt uiZorderIdx, UInt uiDepth )
1029{
1030  UInt uiCUAddr = pcCU->getAddr();
1031 
1032  m_ppcYuvReco[uiDepth]->copyToPicYuv  ( pcPic->getPicYuvRec (), uiCUAddr, uiZorderIdx );
1033 
1034  return;
1035}
1036
1037Void TDecCu::xDecodeInterTexture ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
1038{
1039  UInt    uiWidth    = pcCU->getWidth ( uiAbsPartIdx );
1040  UInt    uiHeight   = pcCU->getHeight( uiAbsPartIdx );
1041  TCoeff* piCoeff;
1042 
1043  Pel*    pResi;
1044  UInt    trMode = pcCU->getTransformIdx( uiAbsPartIdx );
1045 
1046  // Y
1047  piCoeff = pcCU->getCoeffY();
1048  pResi = m_ppcYuvResi[uiDepth]->getLumaAddr();
1049
1050  m_pcTrQuant->setQPforQuant( pcCU->getQP( uiAbsPartIdx ), TEXT_LUMA, pcCU->getSlice()->getSPS()->getQpBDOffsetY(), 0 );
1051
1052  m_pcTrQuant->invRecurTransformNxN ( pcCU, 0, TEXT_LUMA, pResi, 0, m_ppcYuvResi[uiDepth]->getStride(), uiWidth, uiHeight, trMode, 0, piCoeff );
1053 
1054  // Cb and Cr
1055  Int curChromaQpOffset = pcCU->getSlice()->getPPS()->getChromaCbQpOffset() + pcCU->getSlice()->getSliceQpDeltaCb();
1056  m_pcTrQuant->setQPforQuant( pcCU->getQP( uiAbsPartIdx ), TEXT_CHROMA, pcCU->getSlice()->getSPS()->getQpBDOffsetC(), curChromaQpOffset );
1057
1058  uiWidth  >>= 1;
1059  uiHeight >>= 1;
1060  piCoeff = pcCU->getCoeffCb(); pResi = m_ppcYuvResi[uiDepth]->getCbAddr();
1061  m_pcTrQuant->invRecurTransformNxN ( pcCU, 0, TEXT_CHROMA_U, pResi, 0, m_ppcYuvResi[uiDepth]->getCStride(), uiWidth, uiHeight, trMode, 0, piCoeff );
1062
1063  curChromaQpOffset = pcCU->getSlice()->getPPS()->getChromaCrQpOffset() + pcCU->getSlice()->getSliceQpDeltaCr();
1064  m_pcTrQuant->setQPforQuant( pcCU->getQP( uiAbsPartIdx ), TEXT_CHROMA, pcCU->getSlice()->getSPS()->getQpBDOffsetC(), curChromaQpOffset );
1065
1066  piCoeff = pcCU->getCoeffCr(); pResi = m_ppcYuvResi[uiDepth]->getCrAddr();
1067  m_pcTrQuant->invRecurTransformNxN ( pcCU, 0, TEXT_CHROMA_V, pResi, 0, m_ppcYuvResi[uiDepth]->getCStride(), uiWidth, uiHeight, trMode, 0, piCoeff );
1068}
1069
1070/** Function for deriving reconstructed luma/chroma samples of a PCM mode CU.
1071 * \param pcCU pointer to current CU
1072 * \param uiPartIdx part index
1073 * \param piPCM pointer to PCM code arrays
1074 * \param piReco pointer to reconstructed sample arrays
1075 * \param uiStride stride of reconstructed sample arrays
1076 * \param uiWidth CU width
1077 * \param uiHeight CU height
1078 * \param ttText texture component type
1079 * \returns Void
1080 */
1081Void TDecCu::xDecodePCMTexture( TComDataCU* pcCU, UInt uiPartIdx, Pel *piPCM, Pel* piReco, UInt uiStride, UInt uiWidth, UInt uiHeight, TextType ttText)
1082{
1083  UInt uiX, uiY;
1084  Pel* piPicReco;
1085  UInt uiPicStride;
1086  UInt uiPcmLeftShiftBit; 
1087
1088  if( ttText == TEXT_LUMA )
1089  {
1090    uiPicStride   = pcCU->getPic()->getPicYuvRec()->getStride();
1091    piPicReco = pcCU->getPic()->getPicYuvRec()->getLumaAddr(pcCU->getAddr(), pcCU->getZorderIdxInCU()+uiPartIdx);
1092    uiPcmLeftShiftBit = g_bitDepthY - pcCU->getSlice()->getSPS()->getPCMBitDepthLuma();
1093  }
1094  else
1095  {
1096    uiPicStride = pcCU->getPic()->getPicYuvRec()->getCStride();
1097
1098    if( ttText == TEXT_CHROMA_U )
1099    {
1100      piPicReco = pcCU->getPic()->getPicYuvRec()->getCbAddr(pcCU->getAddr(), pcCU->getZorderIdxInCU()+uiPartIdx);
1101    }
1102    else
1103    {
1104      piPicReco = pcCU->getPic()->getPicYuvRec()->getCrAddr(pcCU->getAddr(), pcCU->getZorderIdxInCU()+uiPartIdx);
1105    }
1106    uiPcmLeftShiftBit = g_bitDepthC - pcCU->getSlice()->getSPS()->getPCMBitDepthChroma();
1107  }
1108
1109  for( uiY = 0; uiY < uiHeight; uiY++ )
1110  {
1111    for( uiX = 0; uiX < uiWidth; uiX++ )
1112    {
1113      piReco[uiX] = (piPCM[uiX] << uiPcmLeftShiftBit);
1114      piPicReco[uiX] = piReco[uiX];
1115    }
1116    piPCM += uiWidth;
1117    piReco += uiStride;
1118    piPicReco += uiPicStride;
1119  }
1120}
1121
1122/** Function for reconstructing a PCM mode CU.
1123 * \param pcCU pointer to current CU
1124 * \param uiDepth CU Depth
1125 * \returns Void
1126 */
1127Void TDecCu::xReconPCM( TComDataCU* pcCU, UInt uiDepth )
1128{
1129  // Luma
1130  UInt uiWidth  = (g_uiMaxCUWidth >> uiDepth);
1131  UInt uiHeight = (g_uiMaxCUHeight >> uiDepth);
1132
1133  Pel* piPcmY = pcCU->getPCMSampleY();
1134  Pel* piRecoY = m_ppcYuvReco[uiDepth]->getLumaAddr(0, uiWidth);
1135
1136  UInt uiStride = m_ppcYuvResi[uiDepth]->getStride();
1137
1138  xDecodePCMTexture( pcCU, 0, piPcmY, piRecoY, uiStride, uiWidth, uiHeight, TEXT_LUMA);
1139
1140  // Cb and Cr
1141  UInt uiCWidth  = (uiWidth>>1);
1142  UInt uiCHeight = (uiHeight>>1);
1143
1144  Pel* piPcmCb = pcCU->getPCMSampleCb();
1145  Pel* piPcmCr = pcCU->getPCMSampleCr();
1146  Pel* pRecoCb = m_ppcYuvReco[uiDepth]->getCbAddr();
1147  Pel* pRecoCr = m_ppcYuvReco[uiDepth]->getCrAddr();
1148
1149  UInt uiCStride = m_ppcYuvReco[uiDepth]->getCStride();
1150
1151  xDecodePCMTexture( pcCU, 0, piPcmCb, pRecoCb, uiCStride, uiCWidth, uiCHeight, TEXT_CHROMA_U);
1152  xDecodePCMTexture( pcCU, 0, piPcmCr, pRecoCr, uiCStride, uiCWidth, uiCHeight, TEXT_CHROMA_V);
1153}
1154
1155/** Function for filling the PCM buffer of a CU using its reconstructed sample array
1156 * \param pcCU pointer to current CU
1157 * \param uiDepth CU Depth
1158 * \returns Void
1159 */
1160Void TDecCu::xFillPCMBuffer(TComDataCU* pCU, UInt depth)
1161{
1162  // Luma
1163  UInt width  = (g_uiMaxCUWidth >> depth);
1164  UInt height = (g_uiMaxCUHeight >> depth);
1165
1166  Pel* pPcmY = pCU->getPCMSampleY();
1167  Pel* pRecoY = m_ppcYuvReco[depth]->getLumaAddr(0, width);
1168
1169  UInt stride = m_ppcYuvReco[depth]->getStride();
1170
1171  for(Int y = 0; y < height; y++ )
1172  {
1173    for(Int x = 0; x < width; x++ )
1174    {
1175      pPcmY[x] = pRecoY[x];
1176    }
1177    pPcmY += width;
1178    pRecoY += stride;
1179  }
1180
1181  // Cb and Cr
1182  UInt widthC  = (width>>1);
1183  UInt heightC = (height>>1);
1184
1185  Pel* pPcmCb = pCU->getPCMSampleCb();
1186  Pel* pPcmCr = pCU->getPCMSampleCr();
1187  Pel* pRecoCb = m_ppcYuvReco[depth]->getCbAddr();
1188  Pel* pRecoCr = m_ppcYuvReco[depth]->getCrAddr();
1189
1190  UInt strideC = m_ppcYuvReco[depth]->getCStride();
1191
1192  for(Int y = 0; y < heightC; y++ )
1193  {
1194    for(Int x = 0; x < widthC; x++ )
1195    {
1196      pPcmCb[x] = pRecoCb[x];
1197      pPcmCr[x] = pRecoCr[x];
1198    }
1199    pPcmCr += widthC;
1200    pPcmCb += widthC;
1201    pRecoCb += strideC;
1202    pRecoCr += strideC;
1203  }
1204
1205}
1206
1207//! \}
Note: See TracBrowser for help on using the repository browser.