source: 3DVCSoftware/branches/HTM-10.2-dev2-RWTH/source/Lib/TLibDecoder/TDecCu.cpp @ 898

Last change on this file since 898 was 898, checked in by rwth, 10 years ago
  • renamed macros
  • all changes are now encapsulated by guard macros
  • H0057 on and H0072 off
  • Property svn:eol-style set to native
File size: 55.9 KB
Line 
1/* The copyright in this software is being made available under the BSD
2 * License, included below. This software may be subject to other third party
3 * and contributor rights, including patent rights, and no such rights are
4 * granted under this license. 
5 *
6* Copyright (c) 2010-2014, ITU/ISO/IEC
7 * All rights reserved.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions are met:
11 *
12 *  * Redistributions of source code must retain the above copyright notice,
13 *    this list of conditions and the following disclaimer.
14 *  * Redistributions in binary form must reproduce the above copyright notice,
15 *    this list of conditions and the following disclaimer in the documentation
16 *    and/or other materials provided with the distribution.
17 *  * Neither the name of the ITU/ISO/IEC nor the names of its contributors may
18 *    be used to endorse or promote products derived from this software without
19 *    specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS
25 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
31 * THE POSSIBILITY OF SUCH DAMAGE.
32 */
33
34/** \file     TDecCu.cpp
35    \brief    CU decoder class
36*/
37
38#include "TDecCu.h"
39
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#if H_3D_DBBP
53  m_ppcYuvRecoDBBP = NULL;
54#endif
55}
56
57TDecCu::~TDecCu()
58{
59}
60
61Void TDecCu::init( TDecEntropy* pcEntropyDecoder, TComTrQuant* pcTrQuant, TComPrediction* pcPrediction)
62{
63  m_pcEntropyDecoder  = pcEntropyDecoder;
64  m_pcTrQuant         = pcTrQuant;
65  m_pcPrediction      = pcPrediction;
66}
67
68/**
69 \param    uiMaxDepth    total number of allowable depth
70 \param    uiMaxWidth    largest CU width
71 \param    uiMaxHeight   largest CU height
72 */
73Void TDecCu::create( UInt uiMaxDepth, UInt uiMaxWidth, UInt uiMaxHeight )
74{
75  m_uiMaxDepth = uiMaxDepth+1;
76 
77  m_ppcYuvResi = new TComYuv*[m_uiMaxDepth-1];
78  m_ppcYuvReco = new TComYuv*[m_uiMaxDepth-1];
79  m_ppcCU      = new TComDataCU*[m_uiMaxDepth-1];
80#if H_3D_DBBP
81  m_ppcYuvRecoDBBP = new TComYuv*[m_uiMaxDepth-1];
82#endif
83 
84  UInt uiNumPartitions;
85  for ( UInt ui = 0; ui < m_uiMaxDepth-1; ui++ )
86  {
87    uiNumPartitions = 1<<( ( m_uiMaxDepth - ui - 1 )<<1 );
88    UInt uiWidth  = uiMaxWidth  >> ui;
89    UInt uiHeight = uiMaxHeight >> ui;
90   
91    m_ppcYuvResi[ui] = new TComYuv;    m_ppcYuvResi[ui]->create( uiWidth, uiHeight );
92    m_ppcYuvReco[ui] = new TComYuv;    m_ppcYuvReco[ui]->create( uiWidth, uiHeight );
93    m_ppcCU     [ui] = new TComDataCU; m_ppcCU     [ui]->create( uiNumPartitions, uiWidth, uiHeight, true, uiMaxWidth >> (m_uiMaxDepth - 1) );
94#if H_3D_DBBP
95    m_ppcYuvRecoDBBP[ui] = new TComYuv;    m_ppcYuvRecoDBBP[ui]->create( uiWidth, uiHeight );
96#endif
97  }
98 
99  m_bDecodeDQP = false;
100
101  // initialize partition order.
102  UInt* piTmp = &g_auiZscanToRaster[0];
103  initZscanToRaster(m_uiMaxDepth, 1, 0, piTmp);
104  initRasterToZscan( uiMaxWidth, uiMaxHeight, m_uiMaxDepth );
105 
106  // initialize conversion matrix from partition index to pel
107  initRasterToPelXY( uiMaxWidth, uiMaxHeight, m_uiMaxDepth );
108}
109
110Void TDecCu::destroy()
111{
112  for ( UInt ui = 0; ui < m_uiMaxDepth-1; ui++ )
113  {
114    m_ppcYuvResi[ui]->destroy(); delete m_ppcYuvResi[ui]; m_ppcYuvResi[ui] = NULL;
115    m_ppcYuvReco[ui]->destroy(); delete m_ppcYuvReco[ui]; m_ppcYuvReco[ui] = NULL;
116    m_ppcCU     [ui]->destroy(); delete m_ppcCU     [ui]; m_ppcCU     [ui] = NULL;
117#if H_3D_DBBP
118    m_ppcYuvRecoDBBP[ui]->destroy(); delete m_ppcYuvRecoDBBP[ui]; m_ppcYuvRecoDBBP[ui] = NULL;
119#endif
120  }
121 
122  delete [] m_ppcYuvResi; m_ppcYuvResi = NULL;
123  delete [] m_ppcYuvReco; m_ppcYuvReco = NULL;
124  delete [] m_ppcCU     ; m_ppcCU      = NULL;
125#if H_3D_DBBP
126  delete [] m_ppcYuvRecoDBBP; m_ppcYuvRecoDBBP = NULL;
127#endif
128}
129
130// ====================================================================================================================
131// Public member functions
132// ====================================================================================================================
133
134/** \param    pcCU        pointer of CU data
135 \param    ruiIsLast   last data?
136 */
137Void TDecCu::decodeCU( TComDataCU* pcCU, UInt& ruiIsLast )
138{
139  if ( pcCU->getSlice()->getPPS()->getUseDQP() )
140  {
141    setdQPFlag(true);
142  }
143
144  // start from the top level CU
145  xDecodeCU( pcCU, 0, 0, ruiIsLast);
146}
147
148/** \param    pcCU        pointer of CU data
149 */
150Void TDecCu::decompressCU( TComDataCU* pcCU )
151{
152#if !H_3D_IV_MERGE
153  xDecompressCU( pcCU, 0,  0 );
154#endif
155}
156
157// ====================================================================================================================
158// Protected member functions
159// ====================================================================================================================
160
161/**decode end-of-slice flag
162 * \param pcCU
163 * \param uiAbsPartIdx
164 * \param uiDepth
165 * \returns Bool
166 */
167Bool TDecCu::xDecodeSliceEnd( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth)
168{
169  UInt uiIsLast;
170  TComPic* pcPic = pcCU->getPic();
171  TComSlice * pcSlice = pcPic->getSlice(pcPic->getCurrSliceIdx());
172  UInt uiCurNumParts    = pcPic->getNumPartInCU() >> (uiDepth<<1);
173  UInt uiWidth = pcSlice->getSPS()->getPicWidthInLumaSamples();
174  UInt uiHeight = pcSlice->getSPS()->getPicHeightInLumaSamples();
175  UInt uiGranularityWidth = g_uiMaxCUWidth;
176  UInt uiPosX = pcCU->getCUPelX() + g_auiRasterToPelX[ g_auiZscanToRaster[uiAbsPartIdx] ];
177  UInt uiPosY = pcCU->getCUPelY() + g_auiRasterToPelY[ g_auiZscanToRaster[uiAbsPartIdx] ];
178
179  if(((uiPosX+pcCU->getWidth(uiAbsPartIdx))%uiGranularityWidth==0||(uiPosX+pcCU->getWidth(uiAbsPartIdx)==uiWidth))
180    &&((uiPosY+pcCU->getHeight(uiAbsPartIdx))%uiGranularityWidth==0||(uiPosY+pcCU->getHeight(uiAbsPartIdx)==uiHeight)))
181  {
182    m_pcEntropyDecoder->decodeTerminatingBit( uiIsLast );
183  }
184  else
185  {
186    uiIsLast=0;
187  }
188 
189  if(uiIsLast) 
190  {
191    if(pcSlice->isNextSliceSegment()&&!pcSlice->isNextSlice()) 
192    {
193      pcSlice->setSliceSegmentCurEndCUAddr(pcCU->getSCUAddr()+uiAbsPartIdx+uiCurNumParts);
194    }
195    else 
196    {
197      pcSlice->setSliceCurEndCUAddr(pcCU->getSCUAddr()+uiAbsPartIdx+uiCurNumParts);
198      pcSlice->setSliceSegmentCurEndCUAddr(pcCU->getSCUAddr()+uiAbsPartIdx+uiCurNumParts);
199    }
200  }
201
202  return uiIsLast>0;
203}
204
205/** decode CU block recursively
206 * \param pcCU
207 * \param uiAbsPartIdx
208 * \param uiDepth
209 * \returns Void
210 */
211
212Void TDecCu::xDecodeCU( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, UInt& ruiIsLast)
213{
214  TComPic* pcPic = pcCU->getPic();
215  UInt uiCurNumParts    = pcPic->getNumPartInCU() >> (uiDepth<<1);
216  UInt uiQNumParts      = uiCurNumParts>>2;
217 
218  Bool bBoundary = false;
219  UInt uiLPelX   = pcCU->getCUPelX() + g_auiRasterToPelX[ g_auiZscanToRaster[uiAbsPartIdx] ];
220  UInt uiRPelX   = uiLPelX + (g_uiMaxCUWidth>>uiDepth)  - 1;
221  UInt uiTPelY   = pcCU->getCUPelY() + g_auiRasterToPelY[ g_auiZscanToRaster[uiAbsPartIdx] ];
222  UInt uiBPelY   = uiTPelY + (g_uiMaxCUHeight>>uiDepth) - 1;
223#if H_MV_ENC_DEC_TRAC
224  DTRACE_CU_S("=========== coding_quadtree ===========\n")
225  DTRACE_CU("x0", uiLPelX)
226  DTRACE_CU("x1", uiTPelY)
227  DTRACE_CU("log2CbSize", g_uiMaxCUWidth>>uiDepth)
228  DTRACE_CU("cqtDepth"  , uiDepth)
229#endif
230
231  TComSlice * pcSlice = pcCU->getPic()->getSlice(pcCU->getPic()->getCurrSliceIdx());
232  Bool bStartInCU = pcCU->getSCUAddr()+uiAbsPartIdx+uiCurNumParts>pcSlice->getSliceSegmentCurStartCUAddr()&&pcCU->getSCUAddr()+uiAbsPartIdx<pcSlice->getSliceSegmentCurStartCUAddr();
233  if((!bStartInCU) && ( uiRPelX < pcSlice->getSPS()->getPicWidthInLumaSamples() ) && ( uiBPelY < pcSlice->getSPS()->getPicHeightInLumaSamples() ) )
234  {
235    m_pcEntropyDecoder->decodeSplitFlag( pcCU, uiAbsPartIdx, uiDepth );
236  }
237  else
238  {
239    bBoundary = true;
240  }
241 
242  if( ( ( uiDepth < pcCU->getDepth( uiAbsPartIdx ) ) && ( uiDepth < g_uiMaxCUDepth - g_uiAddCUDepth ) ) || bBoundary )
243  {
244    UInt uiIdx = uiAbsPartIdx;
245    if( (g_uiMaxCUWidth>>uiDepth) == pcCU->getSlice()->getPPS()->getMinCuDQPSize() && pcCU->getSlice()->getPPS()->getUseDQP())
246    {
247      setdQPFlag(true);
248      pcCU->setQPSubParts( pcCU->getRefQP(uiAbsPartIdx), uiAbsPartIdx, uiDepth ); // set QP to default QP
249    }
250
251    for ( UInt uiPartUnitIdx = 0; uiPartUnitIdx < 4; uiPartUnitIdx++ )
252    {
253      uiLPelX   = pcCU->getCUPelX() + g_auiRasterToPelX[ g_auiZscanToRaster[uiIdx] ];
254      uiTPelY   = pcCU->getCUPelY() + g_auiRasterToPelY[ g_auiZscanToRaster[uiIdx] ];
255     
256      Bool bSubInSlice = pcCU->getSCUAddr()+uiIdx+uiQNumParts>pcSlice->getSliceSegmentCurStartCUAddr();
257      if ( bSubInSlice )
258      {
259        if ( !ruiIsLast && ( uiLPelX < pcCU->getSlice()->getSPS()->getPicWidthInLumaSamples() ) && ( uiTPelY < pcCU->getSlice()->getSPS()->getPicHeightInLumaSamples() ) )
260        {
261          xDecodeCU( pcCU, uiIdx, uiDepth+1, ruiIsLast );
262        }
263        else
264        {
265          pcCU->setOutsideCUPart( uiIdx, uiDepth+1 );
266        }
267      }
268     
269      uiIdx += uiQNumParts;
270    }
271    if( (g_uiMaxCUWidth>>uiDepth) == pcCU->getSlice()->getPPS()->getMinCuDQPSize() && pcCU->getSlice()->getPPS()->getUseDQP())
272    {
273      if ( getdQPFlag() )
274      {
275        UInt uiQPSrcPartIdx;
276        if ( pcPic->getCU( pcCU->getAddr() )->getSliceSegmentStartCU(uiAbsPartIdx) != pcSlice->getSliceSegmentCurStartCUAddr() )
277        {
278          uiQPSrcPartIdx = pcSlice->getSliceSegmentCurStartCUAddr() % pcPic->getNumPartInCU();
279        }
280        else
281        {
282          uiQPSrcPartIdx = uiAbsPartIdx;
283        }
284        pcCU->setQPSubParts( pcCU->getRefQP( uiQPSrcPartIdx ), uiAbsPartIdx, uiDepth ); // set QP to default QP
285      }
286    }
287    return;
288  }
289 
290#if H_MV_ENC_DEC_TRAC
291  DTRACE_CU_S("=========== coding_unit ===========\n")
292#endif
293
294
295#if H_3D_DDD
296      pcCU->setUseDDD( false, uiAbsPartIdx, uiDepth );
297#endif
298
299  if( (g_uiMaxCUWidth>>uiDepth) >= pcCU->getSlice()->getPPS()->getMinCuDQPSize() && pcCU->getSlice()->getPPS()->getUseDQP())
300  {
301    setdQPFlag(true);
302    pcCU->setQPSubParts( pcCU->getRefQP(uiAbsPartIdx), uiAbsPartIdx, uiDepth ); // set QP to default QP
303  }
304#if H_3D_NBDV
305  DisInfo DvInfo; 
306  DvInfo.bDV = false;
307  DvInfo.m_acNBDV.setZero();
308  DvInfo.m_aVIdxCan = 0;
309#if H_3D_NBDV_REF 
310  DvInfo.m_acDoNBDV.setZero();
311#endif
312 
313 
314  if(!pcCU->getSlice()->isIntra())
315  {
316#if H_3D_ARP && H_3D_IV_MERGE
317    if( pcCU->getSlice()->getVPS()->getUseAdvRP( pcCU->getSlice()->getLayerId() ) || pcCU->getSlice()->getVPS()->getIvMvPredFlag( pcCU->getSlice()->getLayerId() ))
318#else
319#if H_3D_ARP
320    if( pcCU->getSlice()->getVPS()->getUseAdvRP(pcCU->getSlice()->getLayerId()) )
321#else
322#if H_3D_IV_MERGE
323    if( pcCU->getSlice()->getVPS()->getIvMvPredFlag(pcCU->getSlice()->getLayerId()) )
324#else
325    if (0)
326#endif
327#endif
328#endif
329    {
330      m_ppcCU[uiDepth]->copyInterPredInfoFrom( pcCU, uiAbsPartIdx, REF_PIC_LIST_0, true );
331      m_ppcCU[uiDepth]->copyDVInfoFrom( pcCU, uiAbsPartIdx);
332      PartSize ePartTemp = m_ppcCU[uiDepth]->getPartitionSize(0);
333      UChar cWidTemp     = m_ppcCU[uiDepth]->getWidth(0);
334      UChar cHeightTemp  = m_ppcCU[uiDepth]->getHeight(0);
335      m_ppcCU[uiDepth]->setWidth  ( 0, pcCU->getSlice()->getSPS()->getMaxCUWidth ()/(1<<uiDepth)  );
336      m_ppcCU[uiDepth]->setHeight ( 0, pcCU->getSlice()->getSPS()->getMaxCUHeight()/(1<<uiDepth)  );
337      m_ppcCU[uiDepth]->setPartSizeSubParts( SIZE_2Nx2N, 0, uiDepth );     
338#if H_3D_IV_MERGE
339      if( pcCU->getSlice()->getIsDepth())
340      {
341        DvInfo.bDV = m_ppcCU[uiDepth]->getDispforDepth(0, 0, &DvInfo);
342      }
343      else
344      {
345#endif
346#if H_3D_NBDV_REF
347      if(pcCU->getSlice()->getVPS()->getDepthRefinementFlag( pcCU->getSlice()->getLayerIdInVps() ))  //Notes from QC: please check the condition for DoNBDV. Remove this comment once it is done.
348      {
349        DvInfo.bDV = m_ppcCU[uiDepth]->getDisMvpCandNBDV(&DvInfo, true);
350      }
351      else
352#endif
353      {
354        DvInfo.bDV = m_ppcCU[uiDepth]->getDisMvpCandNBDV(&DvInfo);
355      }
356#if H_3D_IV_MERGE
357      }
358#endif
359#if ENC_DEC_TRACE && H_MV_ENC_DEC_TRAC   
360      if ( g_decTraceDispDer )
361      {
362        DTRACE_CU( "RefViewIdx",  DvInfo.m_aVIdxCan );       
363        DTRACE_CU( "MvDisp[x]", DvInfo.m_acNBDV.getHor() );
364        DTRACE_CU( "MvDisp[y]", DvInfo.m_acNBDV.getVer() );
365        DTRACE_CU( "MvRefinedDisp[x]", DvInfo.m_acDoNBDV.getHor() );
366        DTRACE_CU( "MvRefinedDisp[y]", DvInfo.m_acDoNBDV.getVer() );
367      }
368#endif
369
370      pcCU->setDvInfoSubParts(DvInfo, uiAbsPartIdx, uiDepth);
371      m_ppcCU[uiDepth]->setPartSizeSubParts( ePartTemp, 0, uiDepth );
372      m_ppcCU[uiDepth]->setWidth  ( 0, cWidTemp );
373      m_ppcCU[uiDepth]->setHeight ( 0, cHeightTemp );
374     }
375  }
376#endif
377  if (pcCU->getSlice()->getPPS()->getTransquantBypassEnableFlag())
378  {
379    m_pcEntropyDecoder->decodeCUTransquantBypassFlag( pcCU, uiAbsPartIdx, uiDepth );
380  }
381 
382  // decode CU mode and the partition size
383  if( !pcCU->getSlice()->isIntra())
384  {
385    m_pcEntropyDecoder->decodeSkipFlag( pcCU, uiAbsPartIdx, uiDepth );
386  }
387 
388  if( pcCU->isSkipped(uiAbsPartIdx) )
389  {
390#if H_MV_ENC_DEC_TRAC
391    DTRACE_PU_S("=========== prediction_unit ===========\n")
392    DTRACE_PU("x0", uiLPelX)
393    DTRACE_PU("x1", uiTPelY)
394#endif
395    m_ppcCU[uiDepth]->copyInterPredInfoFrom( pcCU, uiAbsPartIdx, REF_PIC_LIST_0 );
396    m_ppcCU[uiDepth]->copyInterPredInfoFrom( pcCU, uiAbsPartIdx, REF_PIC_LIST_1 );
397#if H_3D_IV_MERGE
398    m_ppcCU[uiDepth]->copyDVInfoFrom(pcCU, uiAbsPartIdx);
399    TComMvField cMvFieldNeighbours[MRG_MAX_NUM_CANDS_MEM << 1]; // double length for mv of both lists
400    UChar uhInterDirNeighbours[MRG_MAX_NUM_CANDS_MEM];
401#else
402    TComMvField cMvFieldNeighbours[MRG_MAX_NUM_CANDS << 1]; // double length for mv of both lists
403    UChar uhInterDirNeighbours[MRG_MAX_NUM_CANDS];
404#endif
405    Int numValidMergeCand = 0;
406    for( UInt ui = 0; ui < m_ppcCU[uiDepth]->getSlice()->getMaxNumMergeCand(); ++ui )
407    {
408      uhInterDirNeighbours[ui] = 0;
409    }
410    m_pcEntropyDecoder->decodeMergeIndex( pcCU, 0, uiAbsPartIdx, uiDepth );
411    UInt uiMergeIndex = pcCU->getMergeIndex(uiAbsPartIdx);
412#if H_3D_ARP
413    m_pcEntropyDecoder->decodeARPW( pcCU , uiAbsPartIdx , uiDepth );
414#endif
415#if H_3D_IC
416    m_pcEntropyDecoder->decodeICFlag( pcCU, uiAbsPartIdx, uiDepth );
417#endif
418
419#if H_3D_VSP
420    Int vspFlag[MRG_MAX_NUM_CANDS_MEM];
421    memset(vspFlag, 0, sizeof(Int)*MRG_MAX_NUM_CANDS_MEM);
422    InheritedVSPDisInfo inheritedVSPDisInfo[MRG_MAX_NUM_CANDS_MEM];
423#if H_3D_SPIVMP
424    Bool bSPIVMPFlag[MRG_MAX_NUM_CANDS_MEM];
425    memset(bSPIVMPFlag, false, sizeof(Bool)*MRG_MAX_NUM_CANDS_MEM);
426    TComMvField*  pcMvFieldSP;
427    UChar* puhInterDirSP;
428    pcMvFieldSP = new TComMvField[pcCU->getPic()->getPicSym()->getNumPartition()*2]; 
429    puhInterDirSP = new UChar[pcCU->getPic()->getPicSym()->getNumPartition()]; 
430#endif
431    m_ppcCU[uiDepth]->initAvailableFlags();
432    m_ppcCU[uiDepth]->getInterMergeCandidates( 0, 0, cMvFieldNeighbours, uhInterDirNeighbours, numValidMergeCand, uiMergeIndex );
433    m_ppcCU[uiDepth]->xGetInterMergeCandidates( 0, 0, cMvFieldNeighbours, uhInterDirNeighbours, vspFlag, inheritedVSPDisInfo
434#if H_3D_SPIVMP
435      , bSPIVMPFlag, pcMvFieldSP, puhInterDirSP
436#endif
437      , numValidMergeCand, uiMergeIndex );
438    pcCU->setVSPFlagSubParts( vspFlag[uiMergeIndex], uiAbsPartIdx, 0, uiDepth );
439#else
440#if H_3D
441    m_ppcCU[uiDepth]->initAvailableFlags();
442    m_ppcCU[uiDepth]->getInterMergeCandidates( 0, 0, cMvFieldNeighbours, uhInterDirNeighbours, numValidMergeCand, uiMergeIndex );
443    m_ppcCU[uiDepth]->xGetInterMergeCandidates( 0, 0, cMvFieldNeighbours, uhInterDirNeighbours, numValidMergeCand, uiMergeIndex );
444#else
445    m_ppcCU[uiDepth]->getInterMergeCandidates( 0, 0, cMvFieldNeighbours, uhInterDirNeighbours, numValidMergeCand, uiMergeIndex );
446#endif
447#endif
448#if H_3D_VSP
449    if(vspFlag[uiMergeIndex])
450    {
451      pcCU->setDvInfoSubParts(inheritedVSPDisInfo[uiMergeIndex].m_acDvInfo, uiAbsPartIdx, 0, uiDepth);
452    }
453#endif
454    pcCU->setInterDirSubParts( uhInterDirNeighbours[uiMergeIndex], uiAbsPartIdx, 0, uiDepth );
455
456#if H_3D_DDD
457    if( uiMergeIndex == m_ppcCU[uiDepth]->getUseDDDCandIdx() )
458    {
459        assert( pcCU->getSlice()->getViewIndex() != 0 );
460        pcCU->setUseDDD( true, uiAbsPartIdx, 0, uiDepth );
461        pcCU->setDDDepthSubParts( m_ppcCU[uiDepth]->getDDTmpDepth(),uiAbsPartIdx, 0, uiDepth );
462    }
463#endif
464
465    TComMv cTmpMv( 0, 0 );
466    for ( UInt uiRefListIdx = 0; uiRefListIdx < 2; uiRefListIdx++ )
467    {       
468      if ( pcCU->getSlice()->getNumRefIdx( RefPicList( uiRefListIdx ) ) > 0 )
469      {
470        pcCU->setMVPIdxSubParts( 0, RefPicList( uiRefListIdx ), uiAbsPartIdx, 0, uiDepth);
471        pcCU->setMVPNumSubParts( 0, RefPicList( uiRefListIdx ), uiAbsPartIdx, 0, uiDepth);
472        pcCU->getCUMvField( RefPicList( uiRefListIdx ) )->setAllMvd( cTmpMv, SIZE_2Nx2N, uiAbsPartIdx, uiDepth );
473        pcCU->getCUMvField( RefPicList( uiRefListIdx ) )->setAllMvField( cMvFieldNeighbours[ 2*uiMergeIndex + uiRefListIdx ], SIZE_2Nx2N, uiAbsPartIdx, uiDepth );
474#if H_3D_VSP
475        if( pcCU->getVSPFlag( uiAbsPartIdx ) != 0 )
476        {
477          if ( uhInterDirNeighbours[ uiMergeIndex ] & (1<<uiRefListIdx) )
478          {
479            UInt dummy;
480            Int vspSize;
481            Int width, height;
482            m_ppcCU[uiDepth]->getPartIndexAndSize( uiAbsPartIdx, dummy, width, height );
483            m_ppcCU[uiDepth]->setMvFieldPUForVSP( pcCU, uiAbsPartIdx, width, height, RefPicList( uiRefListIdx ), cMvFieldNeighbours[ 2*uiMergeIndex + uiRefListIdx ].getRefIdx(), vspSize );
484            pcCU->setVSPFlag( uiAbsPartIdx, vspSize );
485          }
486        }
487#endif
488#if ENC_DEC_TRACE && H_MV_ENC_DEC_TRAC   
489        if ( g_decTraceMvFromMerge )
490        {       
491          if ( uiRefListIdx == 0 )
492          {
493            DTRACE_PU( "mvL0[0]", cMvFieldNeighbours[ 2*uiMergeIndex + uiRefListIdx ].getHor());
494            DTRACE_PU( "mvL0[1]", cMvFieldNeighbours[ 2*uiMergeIndex + uiRefListIdx ].getVer());
495            DTRACE_PU( "refIdxL0   ", cMvFieldNeighbours[ 2*uiMergeIndex + uiRefListIdx ].getRefIdx());
496          }
497          else
498          {
499            DTRACE_PU( "mvL1[0]", cMvFieldNeighbours[ 2*uiMergeIndex + uiRefListIdx ].getHor());
500            DTRACE_PU( "mvL1[1]", cMvFieldNeighbours[ 2*uiMergeIndex + uiRefListIdx ].getVer());
501            DTRACE_PU( "refIdxL1", cMvFieldNeighbours[ 2*uiMergeIndex + uiRefListIdx ].getRefIdx());
502          }
503        }
504#endif
505      }
506    }
507#if H_3D_SPIVMP
508    pcCU->setSPIVMPFlagSubParts(bSPIVMPFlag[uiMergeIndex], uiAbsPartIdx, 0, uiDepth ); 
509    if (bSPIVMPFlag[uiMergeIndex])
510    {
511      UInt uiSPAddr;
512      Int iWidth = pcCU->getWidth(uiAbsPartIdx);
513      Int iHeight = pcCU->getHeight(uiAbsPartIdx);
514
515      Int iNumSPInOneLine, iNumSP, iSPWidth, iSPHeight;
516
517      pcCU->getSPPara(iWidth, iHeight, iNumSP, iNumSPInOneLine, iSPWidth, iSPHeight);
518
519      for (Int iPartitionIdx = 0; iPartitionIdx < iNumSP; iPartitionIdx++)
520      {
521        pcCU->getSPAbsPartIdx(uiAbsPartIdx, iSPWidth, iSPHeight, iPartitionIdx, iNumSPInOneLine, uiSPAddr);
522        pcCU->setInterDirSP(puhInterDirSP[iPartitionIdx], uiSPAddr, iSPWidth, iSPHeight);
523        pcCU->getCUMvField( REF_PIC_LIST_0 )->setMvFieldSP(pcCU, uiSPAddr, pcMvFieldSP[2*iPartitionIdx], iSPWidth, iSPHeight);
524        pcCU->getCUMvField( REF_PIC_LIST_1 )->setMvFieldSP(pcCU, uiSPAddr, pcMvFieldSP[2*iPartitionIdx + 1], iSPWidth, iSPHeight);
525      }
526    }
527    delete[] pcMvFieldSP;
528    delete[] puhInterDirSP;
529#endif
530
531    xFinishDecodeCU( pcCU, uiAbsPartIdx, uiDepth, ruiIsLast );
532#if H_3D_IV_MERGE
533    xDecompressCU(pcCU, uiAbsPartIdx, uiDepth );
534#endif
535    return;
536  }
537
538  m_pcEntropyDecoder->decodePredMode( pcCU, uiAbsPartIdx, uiDepth );
539  m_pcEntropyDecoder->decodePartSize( pcCU, uiAbsPartIdx, uiDepth );
540
541#if H_3D_DIM_SDC
542  m_pcEntropyDecoder->decodeSDCFlag( pcCU, uiAbsPartIdx, uiDepth );
543#endif
544  if (pcCU->isIntra( uiAbsPartIdx ) && pcCU->getPartitionSize( uiAbsPartIdx ) == SIZE_2Nx2N )
545  {
546    m_pcEntropyDecoder->decodeIPCMInfo( pcCU, uiAbsPartIdx, uiDepth );
547
548    if(pcCU->getIPCMFlag(uiAbsPartIdx))
549    {
550      xFinishDecodeCU( pcCU, uiAbsPartIdx, uiDepth, ruiIsLast );
551#if H_3D_IV_MERGE
552      xDecompressCU(pcCU, uiAbsPartIdx, uiDepth );
553#endif
554      return;
555    }
556  }
557
558  UInt uiCurrWidth      = pcCU->getWidth ( uiAbsPartIdx );
559  UInt uiCurrHeight     = pcCU->getHeight( uiAbsPartIdx );
560 
561  // prediction mode ( Intra : direction mode, Inter : Mv, reference idx )
562  m_pcEntropyDecoder->decodePredInfo( pcCU, uiAbsPartIdx, uiDepth, m_ppcCU[uiDepth]);
563  // Coefficient decoding
564  Bool bCodeDQP = getdQPFlag();
565  m_pcEntropyDecoder->decodeCoeff( pcCU, uiAbsPartIdx, uiDepth, uiCurrWidth, uiCurrHeight, bCodeDQP );
566  setdQPFlag( bCodeDQP );
567  xFinishDecodeCU( pcCU, uiAbsPartIdx, uiDepth, ruiIsLast );
568#if H_3D_IV_MERGE
569  xDecompressCU(pcCU, uiAbsPartIdx, uiDepth );
570#endif
571}
572
573Void TDecCu::xFinishDecodeCU( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, UInt& ruiIsLast)
574{
575  if(  pcCU->getSlice()->getPPS()->getUseDQP())
576  {
577    pcCU->setQPSubParts( getdQPFlag()?pcCU->getRefQP(uiAbsPartIdx):pcCU->getCodedQP(), uiAbsPartIdx, uiDepth ); // set QP
578  }
579
580  ruiIsLast = xDecodeSliceEnd( pcCU, uiAbsPartIdx, uiDepth);
581}
582
583Void TDecCu::xDecompressCU( TComDataCU* pcCU, UInt uiAbsPartIdx,  UInt uiDepth )
584{
585  TComPic* pcPic = pcCU->getPic();
586#if !H_3D_IV_MERGE
587  Bool bBoundary = false;
588  UInt uiLPelX   = pcCU->getCUPelX() + g_auiRasterToPelX[ g_auiZscanToRaster[uiAbsPartIdx] ];
589  UInt uiRPelX   = uiLPelX + (g_uiMaxCUWidth>>uiDepth)  - 1;
590  UInt uiTPelY   = pcCU->getCUPelY() + g_auiRasterToPelY[ g_auiZscanToRaster[uiAbsPartIdx] ];
591  UInt uiBPelY   = uiTPelY + (g_uiMaxCUHeight>>uiDepth) - 1;
592 
593  UInt uiCurNumParts    = pcPic->getNumPartInCU() >> (uiDepth<<1);
594  TComSlice * pcSlice = pcCU->getPic()->getSlice(pcCU->getPic()->getCurrSliceIdx());
595  Bool bStartInCU = pcCU->getSCUAddr()+uiAbsPartIdx+uiCurNumParts>pcSlice->getSliceSegmentCurStartCUAddr()&&pcCU->getSCUAddr()+uiAbsPartIdx<pcSlice->getSliceSegmentCurStartCUAddr();
596  if(bStartInCU||( uiRPelX >= pcSlice->getSPS()->getPicWidthInLumaSamples() ) || ( uiBPelY >= pcSlice->getSPS()->getPicHeightInLumaSamples() ) )
597  {
598    bBoundary = true;
599  }
600 
601  if( ( ( uiDepth < pcCU->getDepth( uiAbsPartIdx ) ) && ( uiDepth < g_uiMaxCUDepth - g_uiAddCUDepth ) ) || bBoundary )
602  {
603    UInt uiNextDepth = uiDepth + 1;
604    UInt uiQNumParts = pcCU->getTotalNumPart() >> (uiNextDepth<<1);
605    UInt uiIdx = uiAbsPartIdx;
606    for ( UInt uiPartIdx = 0; uiPartIdx < 4; uiPartIdx++ )
607    {
608      uiLPelX = pcCU->getCUPelX() + g_auiRasterToPelX[ g_auiZscanToRaster[uiIdx] ];
609      uiTPelY = pcCU->getCUPelY() + g_auiRasterToPelY[ g_auiZscanToRaster[uiIdx] ];
610     
611      Bool binSlice = (pcCU->getSCUAddr()+uiIdx+uiQNumParts>pcSlice->getSliceSegmentCurStartCUAddr())&&(pcCU->getSCUAddr()+uiIdx<pcSlice->getSliceSegmentCurEndCUAddr());
612      if(binSlice&&( uiLPelX < pcSlice->getSPS()->getPicWidthInLumaSamples() ) && ( uiTPelY < pcSlice->getSPS()->getPicHeightInLumaSamples() ) )
613      {
614        xDecompressCU(pcCU, uiIdx, uiNextDepth );
615      }
616     
617      uiIdx += uiQNumParts;
618    }
619    return;
620  }
621#endif 
622  // Residual reconstruction
623  m_ppcYuvResi[uiDepth]->clear();
624 
625  m_ppcCU[uiDepth]->copySubCU( pcCU, uiAbsPartIdx, uiDepth );
626 
627#if H_MV_ENC_DEC_TRAC
628#if ENC_DEC_TRACE
629  stopAtPos  ( m_ppcCU[uiDepth]->getSlice()->getPOC(), 
630    m_ppcCU[uiDepth]->getSlice()->getLayerId(), 
631    m_ppcCU[uiDepth]->getCUPelX(),
632    m_ppcCU[uiDepth]->getCUPelY(),
633    m_ppcCU[uiDepth]->getWidth(0), 
634    m_ppcCU[uiDepth]->getHeight(0) );
635#endif
636#endif
637
638  switch( m_ppcCU[uiDepth]->getPredictionMode(0) )
639  {
640    case MODE_INTER:
641#if H_3D_DBBP
642      if( m_ppcCU[uiDepth]->getDBBPFlag(0) )
643      {
644        xReconInterDBBP( m_ppcCU[uiDepth], uiAbsPartIdx, uiDepth );
645      }
646      else
647      {
648#endif
649#if H_3D_INTER_SDC
650      if( m_ppcCU[uiDepth]->getSDCFlag( 0 ) )
651      {
652        xReconInterSDC( m_ppcCU[uiDepth], uiAbsPartIdx, uiDepth );
653      }
654      else
655      {
656#endif
657      xReconInter( m_ppcCU[uiDepth], uiDepth );
658#if H_3D_INTER_SDC
659      }
660#endif
661#if H_3D_DBBP
662      }
663#endif
664      break;
665    case MODE_INTRA:
666#if H_3D_DIM_SDC
667      if( m_ppcCU[uiDepth]->getSDCFlag(0) )
668        xReconIntraSDC( m_ppcCU[uiDepth], 0, uiDepth );
669      else
670#endif
671      xReconIntraQT( m_ppcCU[uiDepth], uiDepth );
672      break;
673    default:
674      assert(0);
675      break;
676  }
677  if ( m_ppcCU[uiDepth]->isLosslessCoded(0) && (m_ppcCU[uiDepth]->getIPCMFlag(0) == false))
678  {
679    xFillPCMBuffer(m_ppcCU[uiDepth], uiDepth);
680  }
681 
682  xCopyToPic( m_ppcCU[uiDepth], pcPic, uiAbsPartIdx, uiDepth );
683}
684
685Void TDecCu::xReconInter( TComDataCU* pcCU, UInt uiDepth )
686{
687 
688  // inter prediction
689  m_pcPrediction->motionCompensation( pcCU, m_ppcYuvReco[uiDepth] );
690 
691  // inter recon
692  xDecodeInterTexture( pcCU, 0, uiDepth );
693 
694  // clip for only non-zero cbp case
695  if  ( ( pcCU->getCbf( 0, TEXT_LUMA ) ) || ( pcCU->getCbf( 0, TEXT_CHROMA_U ) ) || ( pcCU->getCbf(0, TEXT_CHROMA_V ) ) )
696  {
697    m_ppcYuvReco[uiDepth]->addClip( m_ppcYuvReco[uiDepth], m_ppcYuvResi[uiDepth], 0, pcCU->getWidth( 0 ) );
698  }
699  else
700  {
701    m_ppcYuvReco[uiDepth]->copyPartToPartYuv( m_ppcYuvReco[uiDepth],0, pcCU->getWidth( 0 ),pcCU->getHeight( 0 ));
702  }
703}
704
705#if H_3D_INTER_SDC
706Void TDecCu::xReconInterSDC( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
707{
708  // inter prediction
709  m_pcPrediction->motionCompensation( pcCU, m_ppcYuvReco[uiDepth] );
710
711  UInt  uiWidth      = pcCU->getWidth ( 0 );
712  UInt  uiHeight     = pcCU->getHeight( 0 );
713
714  Pel  *pResi;
715  UInt uiPelX, uiPelY;
716  UInt uiResiStride = m_ppcYuvResi[uiDepth]->getStride();
717
718  pResi = m_ppcYuvResi[uiDepth]->getLumaAddr( 0 );
719  for( uiPelY = 0; uiPelY < uiHeight; uiPelY++ )
720  {
721    for( uiPelX = 0; uiPelX < uiWidth; uiPelX++ )
722    {
723      pResi[ uiPelX ] = pcCU->getSDCSegmentDCOffset( 0, 0 );
724    }
725    pResi += uiResiStride;
726  }
727
728  m_ppcYuvReco[uiDepth]->addClip( m_ppcYuvReco[uiDepth], m_ppcYuvResi[uiDepth], 0, pcCU->getWidth( 0 ) );
729
730  // clear UV
731  UInt  uiStrideC     = m_ppcYuvReco[uiDepth]->getCStride();
732  Pel   *pRecCb       = m_ppcYuvReco[uiDepth]->getCbAddr();
733  Pel   *pRecCr       = m_ppcYuvReco[uiDepth]->getCrAddr();
734
735  for (Int y = 0; y < uiHeight/2; y++)
736  {
737    for (Int x = 0; x < uiWidth/2; x++)
738    {
739      pRecCb[x] = (Pel)( 1 << ( g_bitDepthC - 1 ) );
740      pRecCr[x] = (Pel)( 1 << ( g_bitDepthC - 1 ) );
741    }
742
743    pRecCb += uiStrideC;
744    pRecCr += uiStrideC;
745  }
746}
747#endif
748
749#if H_3D_DBBP
750Void TDecCu::xReconInterDBBP( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
751{
752  AOF(!pcCU->getSlice()->getIsDepth());
753  AOF(!pcCU->getSlice()->isIntra());
754  PartSize ePartSize = pcCU->getPartitionSize( 0 );
755 
756  // get collocated depth block
757  UInt uiDepthStride = 0;
758  Pel* pDepthPels = pcCU->getVirtualDepthBlock(0, pcCU->getWidth(0), pcCU->getHeight(0), uiDepthStride);
759  AOF( pDepthPels != NULL );
760  AOF( uiDepthStride != 0 );
761 
762  // compute mask by segmenting depth block
763  Bool pMask[MAX_CU_SIZE*MAX_CU_SIZE];
764  Bool bValidMask = m_pcPrediction->getSegmentMaskFromDepth(pDepthPels, uiDepthStride, pcCU->getWidth(0), pcCU->getHeight(0), pMask);
765  AOF(bValidMask);
766 
767  DBBPTmpData* pDBBPTmpData = pcCU->getDBBPTmpData();
768  TComYuv* apSegPredYuv[2] = { m_ppcYuvReco[uiDepth], m_ppcYuvRecoDBBP[uiDepth] };
769 
770  // first, extract the two sets of motion parameters
771  UInt uiPUOffset = ( g_auiPUOffset[UInt( ePartSize )] << ( ( pcCU->getSlice()->getSPS()->getMaxCUDepth() - uiDepth ) << 1 ) ) >> 4;
772  for( UInt uiSegment = 0; uiSegment < 2; uiSegment++ )
773  {
774    UInt uiPartAddr = uiSegment*uiPUOffset;
775   
776    pDBBPTmpData->auhInterDir[uiSegment] = pcCU->getInterDir(uiPartAddr);
777   
778    for ( UInt uiRefListIdx = 0; uiRefListIdx < 2; uiRefListIdx++ )
779    {
780      RefPicList eRefList = (RefPicList)uiRefListIdx;
781      pcCU->getMvField(pcCU, uiPartAddr, eRefList, pDBBPTmpData->acMvField[uiSegment][eRefList]);
782    }
783   
784#if RWTH_DBBP_NO_SPU_H0057
785    AOF( pcCU->getARPW(uiPartAddr) == 0 );
786    AOF( pcCU->getICFlag(uiPartAddr) == false );
787    AOF( pcCU->getSPIVMPFlag(uiPartAddr) == false );
788    AOF( pcCU->getVSPFlag(uiPartAddr) == 0 );
789#else
790    pDBBPTmpData->ahVSPFlag[uiSegment] = pcCU->getVSPFlag( uiPartAddr );
791    pDBBPTmpData->acDvInfo[uiSegment] = pcCU->getDvInfo( uiPartAddr );
792#endif
793  }
794 
795  // do motion compensation for each segment as 2Nx2N
796  pcCU->setPartSizeSubParts( SIZE_2Nx2N, 0, uiDepth );
797  pcCU->setPredModeSubParts( MODE_INTER, 0, uiDepth );
798  for( UInt uiSegment = 0; uiSegment < 2; uiSegment++ )
799  {
800    pcCU->setInterDirSubParts( pDBBPTmpData->auhInterDir[uiSegment], 0, 0, uiDepth );
801   
802#if !RWTH_DBBP_NO_SPU_H0057
803    pcCU->setVSPFlagSubParts( pDBBPTmpData->ahVSPFlag[uiSegment], 0, 0, uiDepth );
804    pcCU->setDvInfoSubParts( pDBBPTmpData->acDvInfo[uiSegment], 0, 0, uiDepth );
805#endif
806   
807    for ( UInt uiRefListIdx = 0; uiRefListIdx < 2; uiRefListIdx++ )
808    {
809      RefPicList eRefList = (RefPicList)uiRefListIdx;
810
811      pcCU->getCUMvField( eRefList )->setAllMvField( pDBBPTmpData->acMvField[uiSegment][eRefList], SIZE_2Nx2N, 0, 0 );
812    }
813   
814    // inter prediction
815    m_pcPrediction->motionCompensation( pcCU, apSegPredYuv[uiSegment] );
816  }
817 
818  // restore motion information in both segments again
819  pcCU->setPartSizeSubParts( ePartSize,  0, uiDepth );
820  pcCU->setPredModeSubParts( MODE_INTER, 0, uiDepth );
821  for( UInt uiSegment = 0; uiSegment < 2; uiSegment++ )
822  {
823    UInt uiPartAddr = uiSegment*uiPUOffset;
824   
825    pcCU->setDBBPFlagSubParts(true, uiPartAddr, uiSegment, uiDepth);
826   
827#if !RWTH_DBBP_NO_SPU_H0057
828    pcCU->setVSPFlagSubParts( pDBBPTmpData->ahVSPFlag[uiSegment], uiPartAddr, uiSegment, uiDepth );
829    pcCU->setDvInfoSubParts( pDBBPTmpData->acDvInfo[uiSegment], uiPartAddr, uiSegment, uiDepth );
830#endif
831   
832    pcCU->setInterDirSubParts(pDBBPTmpData->auhInterDir[uiSegment], uiPartAddr, uiSegment, uiDepth); // interprets depth relative to LCU level
833   
834    for ( UInt uiRefListIdx = 0; uiRefListIdx < 2; uiRefListIdx++ )
835    {
836      RefPicList eRefList = (RefPicList)uiRefListIdx;
837
838      pcCU->getCUMvField( eRefList )->setAllMvField( pDBBPTmpData->acMvField[uiSegment][eRefList], ePartSize, uiPartAddr, 0, uiSegment ); // interprets depth relative to rpcTempCU level
839    }
840  }
841 
842  // reconstruct final prediction signal by combining both segments
843  m_pcPrediction->combineSegmentsWithMask(apSegPredYuv, m_ppcYuvReco[uiDepth], pMask, pcCU->getWidth(0), pcCU->getHeight(0));
844 
845  // inter recon
846  xDecodeInterTexture( pcCU, 0, uiDepth );
847 
848  // clip for only non-zero cbp case
849  if  ( ( pcCU->getCbf( 0, TEXT_LUMA ) ) || ( pcCU->getCbf( 0, TEXT_CHROMA_U ) ) || ( pcCU->getCbf(0, TEXT_CHROMA_V ) ) )
850  {
851    m_ppcYuvReco[uiDepth]->addClip( m_ppcYuvReco[uiDepth], m_ppcYuvResi[uiDepth], 0, pcCU->getWidth( 0 ) );
852  }
853  else
854  {
855    m_ppcYuvReco[uiDepth]->copyPartToPartYuv( m_ppcYuvReco[uiDepth],0, pcCU->getWidth( 0 ),pcCU->getHeight( 0 ));
856  }
857}
858#endif
859
860Void
861TDecCu::xIntraRecLumaBlk( TComDataCU* pcCU,
862                         UInt        uiTrDepth,
863                         UInt        uiAbsPartIdx,
864                         TComYuv*    pcRecoYuv,
865                         TComYuv*    pcPredYuv, 
866                         TComYuv*    pcResiYuv )
867{
868  UInt    uiWidth           = pcCU     ->getWidth   ( 0 ) >> uiTrDepth;
869  UInt    uiHeight          = pcCU     ->getHeight  ( 0 ) >> uiTrDepth;
870  UInt    uiStride          = pcRecoYuv->getStride  ();
871  Pel*    piReco            = pcRecoYuv->getLumaAddr( uiAbsPartIdx );
872  Pel*    piPred            = pcPredYuv->getLumaAddr( uiAbsPartIdx );
873  Pel*    piResi            = pcResiYuv->getLumaAddr( uiAbsPartIdx );
874 
875  UInt    uiNumCoeffInc     = ( pcCU->getSlice()->getSPS()->getMaxCUWidth() * pcCU->getSlice()->getSPS()->getMaxCUHeight() ) >> ( pcCU->getSlice()->getSPS()->getMaxCUDepth() << 1 );
876  TCoeff* pcCoeff           = pcCU->getCoeffY() + ( uiNumCoeffInc * uiAbsPartIdx );
877 
878  UInt    uiLumaPredMode    = pcCU->getLumaIntraDir     ( uiAbsPartIdx );
879 
880  UInt    uiZOrder          = pcCU->getZorderIdxInCU() + uiAbsPartIdx;
881  Pel*    piRecIPred        = pcCU->getPic()->getPicYuvRec()->getLumaAddr( pcCU->getAddr(), uiZOrder );
882  UInt    uiRecIPredStride  = pcCU->getPic()->getPicYuvRec()->getStride  ();
883  Bool    useTransformSkip  = pcCU->getTransformSkip(uiAbsPartIdx, TEXT_LUMA);
884  //===== init availability pattern =====
885  Bool  bAboveAvail = false;
886  Bool  bLeftAvail  = false;
887  pcCU->getPattern()->initPattern   ( pcCU, uiTrDepth, uiAbsPartIdx );
888  pcCU->getPattern()->initAdiPattern( pcCU, uiAbsPartIdx, uiTrDepth, 
889                                     m_pcPrediction->getPredicBuf       (),
890                                     m_pcPrediction->getPredicBufWidth  (),
891                                     m_pcPrediction->getPredicBufHeight (),
892                                     bAboveAvail, bLeftAvail );
893 
894  //===== get prediction signal =====
895#if H_3D_DIM
896  if( isDimMode( uiLumaPredMode ) )
897  {
898    m_pcPrediction->predIntraLumaDepth( pcCU, uiAbsPartIdx, uiLumaPredMode, piPred, uiStride, uiWidth, uiHeight );
899  }
900  else
901  {
902#endif
903  m_pcPrediction->predIntraLumaAng( pcCU->getPattern(), uiLumaPredMode, piPred, uiStride, uiWidth, uiHeight, bAboveAvail, bLeftAvail );
904#if H_3D_DIM
905  }
906#endif
907 
908#if H_3D
909  Bool useDltFlag = (isDimMode( uiLumaPredMode ) || uiLumaPredMode == HOR_IDX || uiLumaPredMode == VER_IDX || uiLumaPredMode == DC_IDX) && pcCU->getSlice()->getIsDepth() && pcCU->getSlice()->getPPS()->getDLT()->getUseDLTFlag(pcCU->getSlice()->getLayerIdInVps());
910
911  if ( pcCU->getCbf( uiAbsPartIdx, TEXT_LUMA, uiTrDepth ) || useDltFlag )
912#else
913  if ( pcCU->getCbf( uiAbsPartIdx, TEXT_LUMA, uiTrDepth ) )
914#endif
915  {
916  //===== inverse transform =====
917  m_pcTrQuant->setQPforQuant  ( pcCU->getQP(0), TEXT_LUMA, pcCU->getSlice()->getSPS()->getQpBDOffsetY(), 0 );
918
919  Int scalingListType = (pcCU->isIntra(uiAbsPartIdx) ? 0 : 3) + g_eTTable[(Int)TEXT_LUMA];
920    assert(scalingListType < SCALING_LIST_NUM);
921  m_pcTrQuant->invtransformNxN( pcCU->getCUTransquantBypass(uiAbsPartIdx), TEXT_LUMA, pcCU->getLumaIntraDir( uiAbsPartIdx ), piResi, uiStride, pcCoeff, uiWidth, uiHeight, scalingListType, useTransformSkip );
922
923 
924  //===== reconstruction =====
925  Pel* pPred      = piPred;
926  Pel* pResi      = piResi;
927  Pel* pReco      = piReco;
928  Pel* pRecIPred  = piRecIPred;
929  for( UInt uiY = 0; uiY < uiHeight; uiY++ )
930  {
931    for( UInt uiX = 0; uiX < uiWidth; uiX++ )
932    {
933#if H_3D
934      if ( useDltFlag )
935      {
936        pReco    [ uiX ] = pcCU->getSlice()->getPPS()->getDLT()->idx2DepthValue( pcCU->getSlice()->getLayerIdInVps(), Clip3( 0, pcCU->getSlice()->getPPS()->getDLT()->getNumDepthValues( pcCU->getSlice()->getLayerIdInVps() ) - 1, pcCU->getSlice()->getPPS()->getDLT()->depthValue2idx( pcCU->getSlice()->getLayerIdInVps(), pPred[ uiX ] ) + pResi[ uiX ] ) );
937      }
938      else
939      {
940        pReco    [ uiX ] = ClipY( pPred[ uiX ] + pResi[ uiX ] );
941      }
942#else
943      pReco    [ uiX ] = ClipY( pPred[ uiX ] + pResi[ uiX ] );
944#endif
945      pRecIPred[ uiX ] = pReco[ uiX ];
946    }
947    pPred     += uiStride;
948    pResi     += uiStride;
949    pReco     += uiStride;
950    pRecIPred += uiRecIPredStride;
951  }
952}
953  else
954  {
955    //===== reconstruction =====
956    Pel* pPred      = piPred;
957    Pel* pReco      = piReco;
958    Pel* pRecIPred  = piRecIPred;
959    for ( Int y = 0; y < uiHeight; y++ )
960    {
961      for ( Int x = 0; x < uiWidth; x++ )
962      {
963        pReco    [ x ] = pPred[ x ];
964        pRecIPred[ x ] = pReco[ x ];
965      }
966      pPred     += uiStride;
967      pReco     += uiStride;
968      pRecIPred += uiRecIPredStride;
969    }
970  }
971}
972
973
974Void
975TDecCu::xIntraRecChromaBlk( TComDataCU* pcCU,
976                           UInt        uiTrDepth,
977                           UInt        uiAbsPartIdx,
978                           TComYuv*    pcRecoYuv,
979                           TComYuv*    pcPredYuv, 
980                           TComYuv*    pcResiYuv,
981                           UInt        uiChromaId )
982{
983  UInt uiFullDepth  = pcCU->getDepth( 0 ) + uiTrDepth;
984  UInt uiLog2TrSize = g_aucConvertToBit[ pcCU->getSlice()->getSPS()->getMaxCUWidth() >> uiFullDepth ] + 2;
985
986  if( uiLog2TrSize == 2 )
987  {
988    assert( uiTrDepth > 0 );
989    uiTrDepth--;
990    UInt uiQPDiv = pcCU->getPic()->getNumPartInCU() >> ( ( pcCU->getDepth( 0 ) + uiTrDepth ) << 1 );
991    Bool bFirstQ = ( ( uiAbsPartIdx % uiQPDiv ) == 0 );
992    if( !bFirstQ )
993    {
994      return;
995    }
996  }
997 
998  TextType  eText             = ( uiChromaId > 0 ? TEXT_CHROMA_V : TEXT_CHROMA_U );
999  UInt      uiWidth           = pcCU     ->getWidth   ( 0 ) >> ( uiTrDepth + 1 );
1000  UInt      uiHeight          = pcCU     ->getHeight  ( 0 ) >> ( uiTrDepth + 1 );
1001  UInt      uiStride          = pcRecoYuv->getCStride ();
1002  Pel*      piReco            = ( uiChromaId > 0 ? pcRecoYuv->getCrAddr( uiAbsPartIdx ) : pcRecoYuv->getCbAddr( uiAbsPartIdx ) );
1003  Pel*      piPred            = ( uiChromaId > 0 ? pcPredYuv->getCrAddr( uiAbsPartIdx ) : pcPredYuv->getCbAddr( uiAbsPartIdx ) );
1004  Pel*      piResi            = ( uiChromaId > 0 ? pcResiYuv->getCrAddr( uiAbsPartIdx ) : pcResiYuv->getCbAddr( uiAbsPartIdx ) );
1005 
1006  UInt      uiNumCoeffInc     = ( ( pcCU->getSlice()->getSPS()->getMaxCUWidth() * pcCU->getSlice()->getSPS()->getMaxCUHeight() ) >> ( pcCU->getSlice()->getSPS()->getMaxCUDepth() << 1 ) ) >> 2;
1007  TCoeff*   pcCoeff           = ( uiChromaId > 0 ? pcCU->getCoeffCr() : pcCU->getCoeffCb() ) + ( uiNumCoeffInc * uiAbsPartIdx );
1008 
1009  UInt      uiChromaPredMode  = pcCU->getChromaIntraDir( 0 );
1010 
1011  UInt      uiZOrder          = pcCU->getZorderIdxInCU() + uiAbsPartIdx;
1012  Pel*      piRecIPred        = ( uiChromaId > 0 ? pcCU->getPic()->getPicYuvRec()->getCrAddr( pcCU->getAddr(), uiZOrder ) : pcCU->getPic()->getPicYuvRec()->getCbAddr( pcCU->getAddr(), uiZOrder ) );
1013  UInt      uiRecIPredStride  = pcCU->getPic()->getPicYuvRec()->getCStride();
1014  Bool      useTransformSkipChroma = pcCU->getTransformSkip(uiAbsPartIdx,eText);
1015  //===== init availability pattern =====
1016  Bool  bAboveAvail = false;
1017  Bool  bLeftAvail  = false;
1018  pcCU->getPattern()->initPattern         ( pcCU, uiTrDepth, uiAbsPartIdx );
1019
1020  pcCU->getPattern()->initAdiPatternChroma( pcCU, uiAbsPartIdx, uiTrDepth,
1021                                           m_pcPrediction->getPredicBuf       (),
1022                                           m_pcPrediction->getPredicBufWidth  (),
1023                                           m_pcPrediction->getPredicBufHeight (),
1024                                           bAboveAvail, bLeftAvail );
1025  Int* pPatChroma   = ( uiChromaId > 0 ? pcCU->getPattern()->getAdiCrBuf( uiWidth, uiHeight, m_pcPrediction->getPredicBuf() ) : pcCU->getPattern()->getAdiCbBuf( uiWidth, uiHeight, m_pcPrediction->getPredicBuf() ) );
1026 
1027  //===== get prediction signal =====
1028  {
1029    if( uiChromaPredMode == DM_CHROMA_IDX )
1030    {
1031      uiChromaPredMode = pcCU->getLumaIntraDir( 0 );
1032#if H_3D_DIM
1033      mapDepthModeToIntraDir( uiChromaPredMode );
1034#endif
1035    }
1036    m_pcPrediction->predIntraChromaAng( pPatChroma, uiChromaPredMode, piPred, uiStride, uiWidth, uiHeight, bAboveAvail, bLeftAvail ); 
1037  }
1038
1039  if ( pcCU->getCbf( uiAbsPartIdx, eText, uiTrDepth ) )
1040  {
1041  //===== inverse transform =====
1042  Int curChromaQpOffset;
1043  if(eText == TEXT_CHROMA_U)
1044  {
1045    curChromaQpOffset = pcCU->getSlice()->getPPS()->getChromaCbQpOffset() + pcCU->getSlice()->getSliceQpDeltaCb();
1046  }
1047  else
1048  {
1049    curChromaQpOffset = pcCU->getSlice()->getPPS()->getChromaCrQpOffset() + pcCU->getSlice()->getSliceQpDeltaCr();
1050  }
1051  m_pcTrQuant->setQPforQuant  ( pcCU->getQP(0), eText, pcCU->getSlice()->getSPS()->getQpBDOffsetC(), curChromaQpOffset );
1052
1053  Int scalingListType = (pcCU->isIntra(uiAbsPartIdx) ? 0 : 3) + g_eTTable[(Int)eText];
1054    assert(scalingListType < SCALING_LIST_NUM);
1055  m_pcTrQuant->invtransformNxN( pcCU->getCUTransquantBypass(uiAbsPartIdx), eText, REG_DCT, piResi, uiStride, pcCoeff, uiWidth, uiHeight, scalingListType, useTransformSkipChroma );
1056
1057  //===== reconstruction =====
1058  Pel* pPred      = piPred;
1059  Pel* pResi      = piResi;
1060  Pel* pReco      = piReco;
1061  Pel* pRecIPred  = piRecIPred;
1062  for( UInt uiY = 0; uiY < uiHeight; uiY++ )
1063  {
1064    for( UInt uiX = 0; uiX < uiWidth; uiX++ )
1065    {
1066      pReco    [ uiX ] = ClipC( pPred[ uiX ] + pResi[ uiX ] );
1067      pRecIPred[ uiX ] = pReco[ uiX ];
1068    }
1069    pPred     += uiStride;
1070    pResi     += uiStride;
1071    pReco     += uiStride;
1072    pRecIPred += uiRecIPredStride;
1073  }
1074}
1075  else
1076  {
1077    //===== reconstruction =====
1078    Pel* pPred      = piPred;
1079    Pel* pReco      = piReco;
1080    Pel* pRecIPred  = piRecIPred;
1081    for ( Int y = 0; y < uiHeight; y++ )
1082    {
1083      for ( Int x = 0; x < uiWidth; x++ )
1084      {
1085        pReco    [ x ] = pPred[ x ];
1086        pRecIPred[ x ] = pReco[ x ];
1087      }
1088      pPred     += uiStride;
1089      pReco     += uiStride;
1090      pRecIPred += uiRecIPredStride;
1091    }   
1092  }
1093}
1094
1095
1096Void
1097TDecCu::xReconIntraQT( TComDataCU* pcCU, UInt uiDepth )
1098{
1099  UInt  uiInitTrDepth = ( pcCU->getPartitionSize(0) == SIZE_2Nx2N ? 0 : 1 );
1100  UInt  uiNumPart     = pcCU->getNumPartInter();
1101  UInt  uiNumQParts   = pcCU->getTotalNumPart() >> 2;
1102 
1103  if (pcCU->getIPCMFlag(0))
1104  {
1105    xReconPCM( pcCU, uiDepth );
1106    return;
1107  }
1108
1109  for( UInt uiPU = 0; uiPU < uiNumPart; uiPU++ )
1110  {
1111    xIntraLumaRecQT( pcCU, uiInitTrDepth, uiPU * uiNumQParts, m_ppcYuvReco[uiDepth], m_ppcYuvReco[uiDepth], m_ppcYuvResi[uiDepth] );
1112  } 
1113
1114  for( UInt uiPU = 0; uiPU < uiNumPart; uiPU++ )
1115  {
1116    xIntraChromaRecQT( pcCU, uiInitTrDepth, uiPU * uiNumQParts, m_ppcYuvReco[uiDepth], m_ppcYuvReco[uiDepth], m_ppcYuvResi[uiDepth] );
1117  }
1118
1119}
1120
1121#if H_3D_DIM_SDC
1122Void TDecCu::xReconIntraSDC( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
1123{
1124  UInt uiWidth        = pcCU->getWidth  ( 0 );
1125  UInt uiHeight       = pcCU->getHeight ( 0 );
1126  TComWedgelet* dmm4SegmentationOrg = new TComWedgelet( uiWidth, uiHeight );
1127  UInt numParts = 1;
1128  UInt sdcDepth    = 0;
1129  TComYuv* pcRecoYuv  = m_ppcYuvReco[uiDepth];
1130  TComYuv* pcPredYuv  = m_ppcYuvReco[uiDepth];
1131  TComYuv* pcResiYuv  = m_ppcYuvResi[uiDepth];
1132
1133  UInt    uiStride = 0;
1134  Pel*    piReco;
1135  Pel*    piPred;
1136  Pel*    piResi;
1137
1138  UInt    uiZOrder;       
1139  Pel*    piRecIPred;     
1140  UInt    uiRecIPredStride;
1141
1142  UInt    uiLumaPredMode = 0; 
1143
1144  if ((uiWidth >> pcCU->getSlice()->getSPS()->getQuadtreeTULog2MaxSize()) > 1)
1145  {
1146    numParts = uiWidth * uiWidth >> (2 * pcCU->getSlice()->getSPS()->getQuadtreeTULog2MaxSize());
1147    sdcDepth = g_aucConvertToBit[uiWidth] + 2 - pcCU->getSlice()->getSPS()->getQuadtreeTULog2MaxSize();
1148    uiWidth = uiHeight = (1 << pcCU->getSlice()->getSPS()->getQuadtreeTULog2MaxSize());
1149  }
1150
1151  for ( Int i = 0; i < numParts; i++ )
1152  {
1153    uiStride    = pcRecoYuv->getStride  ();
1154    piReco      = pcRecoYuv->getLumaAddr( uiAbsPartIdx );
1155    piPred      = pcPredYuv->getLumaAddr( uiAbsPartIdx );
1156    piResi      = pcResiYuv->getLumaAddr( uiAbsPartIdx );
1157
1158    uiZOrder          = pcCU->getZorderIdxInCU() + uiAbsPartIdx;
1159    piRecIPred        = pcCU->getPic()->getPicYuvRec()->getLumaAddr( pcCU->getAddr(), uiZOrder );
1160    uiRecIPredStride  = pcCU->getPic()->getPicYuvRec()->getStride  ();
1161
1162    uiLumaPredMode    = pcCU->getLumaIntraDir     ( uiAbsPartIdx );
1163
1164    AOF( uiWidth == uiHeight );
1165
1166    //===== init availability pattern =====
1167    Bool  bAboveAvail = false;
1168    Bool  bLeftAvail  = false;
1169
1170    pcCU->getPattern()->initPattern   ( pcCU, sdcDepth, uiAbsPartIdx );
1171    pcCU->getPattern()->initAdiPattern( pcCU, uiAbsPartIdx, sdcDepth, m_pcPrediction->getPredicBuf(), m_pcPrediction->getPredicBufWidth(), m_pcPrediction->getPredicBufHeight(), bAboveAvail, bLeftAvail );
1172
1173    TComWedgelet* dmm4Segmentation = new TComWedgelet( uiWidth, uiHeight );
1174    //===== get prediction signal =====
1175    if( isDimMode( uiLumaPredMode ) )
1176    {
1177      m_pcPrediction->predIntraLumaDepth( pcCU, uiAbsPartIdx, uiLumaPredMode, piPred, uiStride, uiWidth, uiHeight, false, dmm4Segmentation  );
1178      Bool* dmm4PatternSplit = dmm4Segmentation->getPattern();
1179      Bool* dmm4PatternOrg = dmm4SegmentationOrg->getPattern();
1180      for( UInt k = 0; k < (uiWidth*uiHeight); k++ ) 
1181      { 
1182        dmm4PatternOrg[k+(uiAbsPartIdx<<4)] = dmm4PatternSplit[k];
1183      }
1184    }
1185    else
1186    {
1187      m_pcPrediction->predIntraLumaAng( pcCU->getPattern(), uiLumaPredMode, piPred, uiStride, uiWidth, uiHeight, bAboveAvail, bLeftAvail );
1188    }
1189
1190    if ( numParts > 1 )
1191    {
1192      for( UInt uiY = 0; uiY < uiHeight; uiY++ )
1193      {
1194        for( UInt uiX = 0; uiX < uiWidth; uiX++ )
1195        {
1196          piReco        [ uiX ] = ClipY( piPred[ uiX ] );
1197          piRecIPred    [ uiX ] = piReco[ uiX ];
1198        }
1199        piPred     += uiStride;
1200        piReco     += uiStride;
1201        piRecIPred += uiRecIPredStride;
1202      }
1203    }
1204    uiAbsPartIdx += ( (uiWidth * uiWidth) >> 4 );
1205    dmm4Segmentation->destroy(); delete dmm4Segmentation;
1206  }
1207  uiAbsPartIdx = 0;
1208 
1209  if ( numParts > 1 )
1210  {
1211    uiWidth = pcCU->getWidth( 0 );
1212    uiHeight = pcCU->getHeight( 0 );
1213  }
1214  piReco      = pcRecoYuv->getLumaAddr( uiAbsPartIdx );
1215  piPred      = pcPredYuv->getLumaAddr( uiAbsPartIdx );
1216  piResi      = pcResiYuv->getLumaAddr( uiAbsPartIdx );
1217  uiZOrder          = pcCU->getZorderIdxInCU() + uiAbsPartIdx;
1218  piRecIPred        = pcCU->getPic()->getPicYuvRec()->getLumaAddr( pcCU->getAddr(), uiZOrder );
1219  uiRecIPredStride  = pcCU->getPic()->getPicYuvRec()->getStride  ();
1220  // number of segments depends on prediction mode
1221  UInt uiNumSegments = 1;
1222  Bool* pbMask = NULL;
1223  UInt uiMaskStride = 0;
1224 
1225  if( getDimType( uiLumaPredMode ) == DMM1_IDX )
1226  {
1227    Int uiTabIdx = pcCU->getDmmWedgeTabIdx(DMM1_IDX, uiAbsPartIdx);
1228   
1229    WedgeList* pacWedgeList = &g_dmmWedgeLists[(g_aucConvertToBit[uiWidth])];
1230    TComWedgelet* pcWedgelet = &(pacWedgeList->at( uiTabIdx ));
1231   
1232    uiNumSegments = 2;
1233    pbMask = pcWedgelet->getPattern();
1234    uiMaskStride = pcWedgelet->getStride();
1235  }
1236  if( getDimType( uiLumaPredMode ) == DMM4_IDX )
1237  {
1238    uiNumSegments = 2;
1239    pbMask  = dmm4SegmentationOrg->getPattern();
1240    uiMaskStride = dmm4SegmentationOrg->getStride();
1241  }
1242  // get DC prediction for each segment
1243  Pel apDCPredValues[2];
1244  m_pcPrediction->analyzeSegmentsSDC(piPred, uiStride, uiWidth, apDCPredValues, uiNumSegments, pbMask, uiMaskStride, uiLumaPredMode);
1245 
1246  // reconstruct residual based on mask + DC residuals
1247  Pel apDCResiValues[2];
1248  for( UInt uiSegment = 0; uiSegment < uiNumSegments; uiSegment++ )
1249  {
1250#if H_3D_DIM_DLT
1251    Pel   pPredIdx    = pcCU->getSlice()->getPPS()->getDLT()->depthValue2idx( pcCU->getSlice()->getLayerIdInVps(), apDCPredValues[uiSegment] );
1252    Pel   pResiIdx    = pcCU->getSDCSegmentDCOffset(uiSegment, uiAbsPartIdx);
1253    Pel   pRecoValue  = pcCU->getSlice()->getPPS()->getDLT()->idx2DepthValue( pcCU->getSlice()->getLayerIdInVps(), pPredIdx + pResiIdx );
1254
1255    apDCResiValues[uiSegment]  = pRecoValue - apDCPredValues[uiSegment];
1256#else
1257    apDCResiValues[uiSegment]  = pcCU->getSDCSegmentDCOffset(uiSegment, uiAbsPartIdx);
1258#endif
1259  }
1260 
1261  //===== reconstruction =====
1262  Bool*pMask      = pbMask;
1263  Pel* pPred      = piPred;
1264  Pel* pResi      = piResi;
1265  Pel* pReco      = piReco;
1266  Pel* pRecIPred  = piRecIPred;
1267 
1268  for( UInt uiY = 0; uiY < uiHeight; uiY++ )
1269  {
1270    for( UInt uiX = 0; uiX < uiWidth; uiX++ )
1271    {
1272      UChar ucSegment = pMask?(UChar)pMask[uiX]:0;
1273      assert( ucSegment < uiNumSegments );
1274     
1275      Pel pResiDC = apDCResiValues[ucSegment];
1276     
1277      pReco    [ uiX ] = ClipY( pPred[ uiX ] + pResiDC );
1278      pRecIPred[ uiX ] = pReco[ uiX ];
1279    }
1280    pPred     += uiStride;
1281    pResi     += uiStride;
1282    pReco     += uiStride;
1283    pRecIPred += uiRecIPredStride;
1284    pMask     += uiMaskStride;
1285  }
1286 
1287  // clear UV
1288  UInt  uiStrideC     = pcPredYuv->getCStride();
1289  Pel   *pRecCb       = pcPredYuv->getCbAddr();
1290  Pel   *pRecCr       = pcPredYuv->getCrAddr();
1291 
1292  for (Int y=0; y<uiHeight/2; y++)
1293  {
1294    for (Int x=0; x<uiWidth/2; x++)
1295    {
1296      pRecCb[x] = 128;
1297      pRecCr[x] = 128;
1298    }
1299   
1300    pRecCb += uiStrideC;
1301    pRecCr += uiStrideC;
1302  }
1303  dmm4SegmentationOrg->destroy(); delete dmm4SegmentationOrg;
1304}
1305#endif
1306
1307/** Function for deriving recontructed PU/CU Luma sample with QTree structure
1308 * \param pcCU pointer of current CU
1309 * \param uiTrDepth current tranform split depth
1310 * \param uiAbsPartIdx  part index
1311 * \param pcRecoYuv pointer to reconstructed sample arrays
1312 * \param pcPredYuv pointer to prediction sample arrays
1313 * \param pcResiYuv pointer to residue sample arrays
1314 *
1315 \ This function dervies recontructed PU/CU Luma sample with recursive QTree structure
1316 */
1317Void
1318TDecCu::xIntraLumaRecQT( TComDataCU* pcCU,
1319                     UInt        uiTrDepth,
1320                     UInt        uiAbsPartIdx,
1321                     TComYuv*    pcRecoYuv,
1322                     TComYuv*    pcPredYuv, 
1323                     TComYuv*    pcResiYuv )
1324{
1325  UInt uiFullDepth  = pcCU->getDepth(0) + uiTrDepth;
1326  UInt uiTrMode     = pcCU->getTransformIdx( uiAbsPartIdx );
1327  if( uiTrMode == uiTrDepth )
1328  {
1329    xIntraRecLumaBlk  ( pcCU, uiTrDepth, uiAbsPartIdx, pcRecoYuv, pcPredYuv, pcResiYuv );
1330  }
1331  else
1332  {
1333    UInt uiNumQPart  = pcCU->getPic()->getNumPartInCU() >> ( ( uiFullDepth + 1 ) << 1 );
1334    for( UInt uiPart = 0; uiPart < 4; uiPart++ )
1335    {
1336      xIntraLumaRecQT( pcCU, uiTrDepth + 1, uiAbsPartIdx + uiPart * uiNumQPart, pcRecoYuv, pcPredYuv, pcResiYuv );
1337    }
1338  }
1339}
1340
1341/** Function for deriving recontructed PU/CU chroma samples with QTree structure
1342 * \param pcCU pointer of current CU
1343 * \param uiTrDepth current tranform split depth
1344 * \param uiAbsPartIdx  part index
1345 * \param pcRecoYuv pointer to reconstructed sample arrays
1346 * \param pcPredYuv pointer to prediction sample arrays
1347 * \param pcResiYuv pointer to residue sample arrays
1348 *
1349 \ This function dervies recontructed PU/CU chroma samples with QTree recursive structure
1350 */
1351Void
1352TDecCu::xIntraChromaRecQT( TComDataCU* pcCU,
1353                     UInt        uiTrDepth,
1354                     UInt        uiAbsPartIdx,
1355                     TComYuv*    pcRecoYuv,
1356                     TComYuv*    pcPredYuv, 
1357                     TComYuv*    pcResiYuv )
1358{
1359  UInt uiFullDepth  = pcCU->getDepth(0) + uiTrDepth;
1360  UInt uiTrMode     = pcCU->getTransformIdx( uiAbsPartIdx );
1361  if( uiTrMode == uiTrDepth )
1362  {
1363    xIntraRecChromaBlk( pcCU, uiTrDepth, uiAbsPartIdx, pcRecoYuv, pcPredYuv, pcResiYuv, 0 );
1364    xIntraRecChromaBlk( pcCU, uiTrDepth, uiAbsPartIdx, pcRecoYuv, pcPredYuv, pcResiYuv, 1 );
1365  }
1366  else
1367  {
1368    UInt uiNumQPart  = pcCU->getPic()->getNumPartInCU() >> ( ( uiFullDepth + 1 ) << 1 );
1369    for( UInt uiPart = 0; uiPart < 4; uiPart++ )
1370    {
1371      xIntraChromaRecQT( pcCU, uiTrDepth + 1, uiAbsPartIdx + uiPart * uiNumQPart, pcRecoYuv, pcPredYuv, pcResiYuv );
1372    }
1373  }
1374}
1375
1376Void TDecCu::xCopyToPic( TComDataCU* pcCU, TComPic* pcPic, UInt uiZorderIdx, UInt uiDepth )
1377{
1378  UInt uiCUAddr = pcCU->getAddr();
1379 
1380  m_ppcYuvReco[uiDepth]->copyToPicYuv  ( pcPic->getPicYuvRec (), uiCUAddr, uiZorderIdx );
1381 
1382  return;
1383}
1384
1385Void TDecCu::xDecodeInterTexture ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
1386{
1387  UInt    uiWidth    = pcCU->getWidth ( uiAbsPartIdx );
1388  UInt    uiHeight   = pcCU->getHeight( uiAbsPartIdx );
1389  TCoeff* piCoeff;
1390 
1391  Pel*    pResi;
1392  UInt    trMode = pcCU->getTransformIdx( uiAbsPartIdx );
1393 
1394  // Y
1395  piCoeff = pcCU->getCoeffY();
1396  pResi = m_ppcYuvResi[uiDepth]->getLumaAddr();
1397
1398  m_pcTrQuant->setQPforQuant( pcCU->getQP( uiAbsPartIdx ), TEXT_LUMA, pcCU->getSlice()->getSPS()->getQpBDOffsetY(), 0 );
1399
1400  m_pcTrQuant->invRecurTransformNxN ( pcCU, 0, TEXT_LUMA, pResi, 0, m_ppcYuvResi[uiDepth]->getStride(), uiWidth, uiHeight, trMode, 0, piCoeff );
1401 
1402  // Cb and Cr
1403  Int curChromaQpOffset = pcCU->getSlice()->getPPS()->getChromaCbQpOffset() + pcCU->getSlice()->getSliceQpDeltaCb();
1404  m_pcTrQuant->setQPforQuant( pcCU->getQP( uiAbsPartIdx ), TEXT_CHROMA, pcCU->getSlice()->getSPS()->getQpBDOffsetC(), curChromaQpOffset );
1405
1406  uiWidth  >>= 1;
1407  uiHeight >>= 1;
1408  piCoeff = pcCU->getCoeffCb(); pResi = m_ppcYuvResi[uiDepth]->getCbAddr();
1409  m_pcTrQuant->invRecurTransformNxN ( pcCU, 0, TEXT_CHROMA_U, pResi, 0, m_ppcYuvResi[uiDepth]->getCStride(), uiWidth, uiHeight, trMode, 0, piCoeff );
1410
1411  curChromaQpOffset = pcCU->getSlice()->getPPS()->getChromaCrQpOffset() + pcCU->getSlice()->getSliceQpDeltaCr();
1412  m_pcTrQuant->setQPforQuant( pcCU->getQP( uiAbsPartIdx ), TEXT_CHROMA, pcCU->getSlice()->getSPS()->getQpBDOffsetC(), curChromaQpOffset );
1413
1414  piCoeff = pcCU->getCoeffCr(); pResi = m_ppcYuvResi[uiDepth]->getCrAddr();
1415  m_pcTrQuant->invRecurTransformNxN ( pcCU, 0, TEXT_CHROMA_V, pResi, 0, m_ppcYuvResi[uiDepth]->getCStride(), uiWidth, uiHeight, trMode, 0, piCoeff );
1416}
1417
1418/** Function for deriving reconstructed luma/chroma samples of a PCM mode CU.
1419 * \param pcCU pointer to current CU
1420 * \param uiPartIdx part index
1421 * \param piPCM pointer to PCM code arrays
1422 * \param piReco pointer to reconstructed sample arrays
1423 * \param uiStride stride of reconstructed sample arrays
1424 * \param uiWidth CU width
1425 * \param uiHeight CU height
1426 * \param ttText texture component type
1427 * \returns Void
1428 */
1429Void TDecCu::xDecodePCMTexture( TComDataCU* pcCU, UInt uiPartIdx, Pel *piPCM, Pel* piReco, UInt uiStride, UInt uiWidth, UInt uiHeight, TextType ttText)
1430{
1431  UInt uiX, uiY;
1432  Pel* piPicReco;
1433  UInt uiPicStride;
1434  UInt uiPcmLeftShiftBit; 
1435
1436  if( ttText == TEXT_LUMA )
1437  {
1438    uiPicStride   = pcCU->getPic()->getPicYuvRec()->getStride();
1439    piPicReco = pcCU->getPic()->getPicYuvRec()->getLumaAddr(pcCU->getAddr(), pcCU->getZorderIdxInCU()+uiPartIdx);
1440    uiPcmLeftShiftBit = g_bitDepthY - pcCU->getSlice()->getSPS()->getPCMBitDepthLuma();
1441  }
1442  else
1443  {
1444    uiPicStride = pcCU->getPic()->getPicYuvRec()->getCStride();
1445
1446    if( ttText == TEXT_CHROMA_U )
1447    {
1448      piPicReco = pcCU->getPic()->getPicYuvRec()->getCbAddr(pcCU->getAddr(), pcCU->getZorderIdxInCU()+uiPartIdx);
1449    }
1450    else
1451    {
1452      piPicReco = pcCU->getPic()->getPicYuvRec()->getCrAddr(pcCU->getAddr(), pcCU->getZorderIdxInCU()+uiPartIdx);
1453    }
1454    uiPcmLeftShiftBit = g_bitDepthC - pcCU->getSlice()->getSPS()->getPCMBitDepthChroma();
1455  }
1456
1457  for( uiY = 0; uiY < uiHeight; uiY++ )
1458  {
1459    for( uiX = 0; uiX < uiWidth; uiX++ )
1460    {
1461      piReco[uiX] = (piPCM[uiX] << uiPcmLeftShiftBit);
1462      piPicReco[uiX] = piReco[uiX];
1463    }
1464    piPCM += uiWidth;
1465    piReco += uiStride;
1466    piPicReco += uiPicStride;
1467  }
1468}
1469
1470/** Function for reconstructing a PCM mode CU.
1471 * \param pcCU pointer to current CU
1472 * \param uiDepth CU Depth
1473 * \returns Void
1474 */
1475Void TDecCu::xReconPCM( TComDataCU* pcCU, UInt uiDepth )
1476{
1477  // Luma
1478  UInt uiWidth  = (g_uiMaxCUWidth >> uiDepth);
1479  UInt uiHeight = (g_uiMaxCUHeight >> uiDepth);
1480
1481  Pel* piPcmY = pcCU->getPCMSampleY();
1482  Pel* piRecoY = m_ppcYuvReco[uiDepth]->getLumaAddr(0, uiWidth);
1483
1484  UInt uiStride = m_ppcYuvResi[uiDepth]->getStride();
1485
1486  xDecodePCMTexture( pcCU, 0, piPcmY, piRecoY, uiStride, uiWidth, uiHeight, TEXT_LUMA);
1487
1488  // Cb and Cr
1489  UInt uiCWidth  = (uiWidth>>1);
1490  UInt uiCHeight = (uiHeight>>1);
1491
1492  Pel* piPcmCb = pcCU->getPCMSampleCb();
1493  Pel* piPcmCr = pcCU->getPCMSampleCr();
1494  Pel* pRecoCb = m_ppcYuvReco[uiDepth]->getCbAddr();
1495  Pel* pRecoCr = m_ppcYuvReco[uiDepth]->getCrAddr();
1496
1497  UInt uiCStride = m_ppcYuvReco[uiDepth]->getCStride();
1498
1499  xDecodePCMTexture( pcCU, 0, piPcmCb, pRecoCb, uiCStride, uiCWidth, uiCHeight, TEXT_CHROMA_U);
1500  xDecodePCMTexture( pcCU, 0, piPcmCr, pRecoCr, uiCStride, uiCWidth, uiCHeight, TEXT_CHROMA_V);
1501}
1502
1503/** Function for filling the PCM buffer of a CU using its reconstructed sample array
1504 * \param pcCU pointer to current CU
1505 * \param uiDepth CU Depth
1506 * \returns Void
1507 */
1508Void TDecCu::xFillPCMBuffer(TComDataCU* pCU, UInt depth)
1509{
1510  // Luma
1511  UInt width  = (g_uiMaxCUWidth >> depth);
1512  UInt height = (g_uiMaxCUHeight >> depth);
1513
1514  Pel* pPcmY = pCU->getPCMSampleY();
1515  Pel* pRecoY = m_ppcYuvReco[depth]->getLumaAddr(0, width);
1516
1517  UInt stride = m_ppcYuvReco[depth]->getStride();
1518
1519  for(Int y = 0; y < height; y++ )
1520  {
1521    for(Int x = 0; x < width; x++ )
1522    {
1523      pPcmY[x] = pRecoY[x];
1524    }
1525    pPcmY += width;
1526    pRecoY += stride;
1527  }
1528
1529  // Cb and Cr
1530  UInt widthC  = (width>>1);
1531  UInt heightC = (height>>1);
1532
1533  Pel* pPcmCb = pCU->getPCMSampleCb();
1534  Pel* pPcmCr = pCU->getPCMSampleCr();
1535  Pel* pRecoCb = m_ppcYuvReco[depth]->getCbAddr();
1536  Pel* pRecoCr = m_ppcYuvReco[depth]->getCrAddr();
1537
1538  UInt strideC = m_ppcYuvReco[depth]->getCStride();
1539
1540  for(Int y = 0; y < heightC; y++ )
1541  {
1542    for(Int x = 0; x < widthC; x++ )
1543    {
1544      pPcmCb[x] = pRecoCb[x];
1545      pPcmCr[x] = pRecoCr[x];
1546    }
1547    pPcmCr += widthC;
1548    pPcmCb += widthC;
1549    pRecoCb += strideC;
1550    pRecoCr += strideC;
1551  }
1552
1553}
1554
1555//! \}
Note: See TracBrowser for help on using the repository browser.