source: 3DVCSoftware/branches/HTM-10.2-dev0/source/Lib/TLibDecoder/TDecCu.cpp @ 937

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

Added missing guard macros ETRIKHU_CLEANUP_H0083_MISSING.

  • Property svn:eol-style set to native
File size: 56.2 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
434#if !ETRIKHU_CLEANUP_H0083
435      ,vspFlag
436#endif
437      , inheritedVSPDisInfo
438#if H_3D_SPIVMP
439#if !ETRIKHU_CLEANUP_H0083_MISSING
440      , bSPIVMPFlag
441#endif
442      , pcMvFieldSP, puhInterDirSP
443#endif
444      , numValidMergeCand, uiMergeIndex );
445
446#if ETRIKHU_CLEANUP_H0083
447    m_ppcCU[uiDepth]->buildMCL( cMvFieldNeighbours, uhInterDirNeighbours, vspFlag
448#if H_3D_SPIVMP
449      , bSPIVMPFlag
450#endif
451      , numValidMergeCand );
452#endif
453    pcCU->setVSPFlagSubParts( vspFlag[uiMergeIndex], uiAbsPartIdx, 0, uiDepth );
454#else
455#if H_3D
456    m_ppcCU[uiDepth]->initAvailableFlags();
457    m_ppcCU[uiDepth]->getInterMergeCandidates( 0, 0, cMvFieldNeighbours, uhInterDirNeighbours, numValidMergeCand, uiMergeIndex );
458    m_ppcCU[uiDepth]->xGetInterMergeCandidates( 0, 0, cMvFieldNeighbours, uhInterDirNeighbours, numValidMergeCand, uiMergeIndex );
459#else
460    m_ppcCU[uiDepth]->getInterMergeCandidates( 0, 0, cMvFieldNeighbours, uhInterDirNeighbours, numValidMergeCand, uiMergeIndex );
461#endif
462#endif
463#if H_3D_VSP
464    if(vspFlag[uiMergeIndex])
465    {
466      pcCU->setDvInfoSubParts(inheritedVSPDisInfo[uiMergeIndex].m_acDvInfo, uiAbsPartIdx, 0, uiDepth);
467    }
468#endif
469    pcCU->setInterDirSubParts( uhInterDirNeighbours[uiMergeIndex], uiAbsPartIdx, 0, uiDepth );
470
471#if H_3D_DDD
472    if( uiMergeIndex == m_ppcCU[uiDepth]->getUseDDDCandIdx() )
473    {
474        assert( pcCU->getSlice()->getViewIndex() != 0 );
475        pcCU->setUseDDD( true, uiAbsPartIdx, 0, uiDepth );
476        pcCU->setDDDepthSubParts( m_ppcCU[uiDepth]->getDDTmpDepth(),uiAbsPartIdx, 0, uiDepth );
477    }
478#endif
479
480    TComMv cTmpMv( 0, 0 );
481    for ( UInt uiRefListIdx = 0; uiRefListIdx < 2; uiRefListIdx++ )
482    {       
483      if ( pcCU->getSlice()->getNumRefIdx( RefPicList( uiRefListIdx ) ) > 0 )
484      {
485        pcCU->setMVPIdxSubParts( 0, RefPicList( uiRefListIdx ), uiAbsPartIdx, 0, uiDepth);
486        pcCU->setMVPNumSubParts( 0, RefPicList( uiRefListIdx ), uiAbsPartIdx, 0, uiDepth);
487        pcCU->getCUMvField( RefPicList( uiRefListIdx ) )->setAllMvd( cTmpMv, SIZE_2Nx2N, uiAbsPartIdx, uiDepth );
488        pcCU->getCUMvField( RefPicList( uiRefListIdx ) )->setAllMvField( cMvFieldNeighbours[ 2*uiMergeIndex + uiRefListIdx ], SIZE_2Nx2N, uiAbsPartIdx, uiDepth );
489#if H_3D_VSP
490        if( pcCU->getVSPFlag( uiAbsPartIdx ) != 0 )
491        {
492          if ( uhInterDirNeighbours[ uiMergeIndex ] & (1<<uiRefListIdx) )
493          {
494            UInt dummy;
495            Int vspSize;
496            Int width, height;
497            m_ppcCU[uiDepth]->getPartIndexAndSize( uiAbsPartIdx, dummy, width, height );
498            m_ppcCU[uiDepth]->setMvFieldPUForVSP( pcCU, uiAbsPartIdx, width, height, RefPicList( uiRefListIdx ), cMvFieldNeighbours[ 2*uiMergeIndex + uiRefListIdx ].getRefIdx(), vspSize );
499            pcCU->setVSPFlag( uiAbsPartIdx, vspSize );
500          }
501        }
502#endif
503#if ENC_DEC_TRACE && H_MV_ENC_DEC_TRAC   
504        if ( g_decTraceMvFromMerge )
505        {       
506          if ( uiRefListIdx == 0 )
507          {
508            DTRACE_PU( "mvL0[0]", cMvFieldNeighbours[ 2*uiMergeIndex + uiRefListIdx ].getHor());
509            DTRACE_PU( "mvL0[1]", cMvFieldNeighbours[ 2*uiMergeIndex + uiRefListIdx ].getVer());
510            DTRACE_PU( "refIdxL0   ", cMvFieldNeighbours[ 2*uiMergeIndex + uiRefListIdx ].getRefIdx());
511          }
512          else
513          {
514            DTRACE_PU( "mvL1[0]", cMvFieldNeighbours[ 2*uiMergeIndex + uiRefListIdx ].getHor());
515            DTRACE_PU( "mvL1[1]", cMvFieldNeighbours[ 2*uiMergeIndex + uiRefListIdx ].getVer());
516            DTRACE_PU( "refIdxL1", cMvFieldNeighbours[ 2*uiMergeIndex + uiRefListIdx ].getRefIdx());
517          }
518        }
519#endif
520      }
521    }
522#if H_3D_SPIVMP
523    pcCU->setSPIVMPFlagSubParts(bSPIVMPFlag[uiMergeIndex], uiAbsPartIdx, 0, uiDepth ); 
524    if (bSPIVMPFlag[uiMergeIndex])
525    {
526      UInt uiSPAddr;
527      Int iWidth = pcCU->getWidth(uiAbsPartIdx);
528      Int iHeight = pcCU->getHeight(uiAbsPartIdx);
529
530      Int iNumSPInOneLine, iNumSP, iSPWidth, iSPHeight;
531
532      pcCU->getSPPara(iWidth, iHeight, iNumSP, iNumSPInOneLine, iSPWidth, iSPHeight);
533
534      for (Int iPartitionIdx = 0; iPartitionIdx < iNumSP; iPartitionIdx++)
535      {
536        pcCU->getSPAbsPartIdx(uiAbsPartIdx, iSPWidth, iSPHeight, iPartitionIdx, iNumSPInOneLine, uiSPAddr);
537        pcCU->setInterDirSP(puhInterDirSP[iPartitionIdx], uiSPAddr, iSPWidth, iSPHeight);
538        pcCU->getCUMvField( REF_PIC_LIST_0 )->setMvFieldSP(pcCU, uiSPAddr, pcMvFieldSP[2*iPartitionIdx], iSPWidth, iSPHeight);
539        pcCU->getCUMvField( REF_PIC_LIST_1 )->setMvFieldSP(pcCU, uiSPAddr, pcMvFieldSP[2*iPartitionIdx + 1], iSPWidth, iSPHeight);
540      }
541    }
542    delete[] pcMvFieldSP;
543    delete[] puhInterDirSP;
544#endif
545
546    xFinishDecodeCU( pcCU, uiAbsPartIdx, uiDepth, ruiIsLast );
547#if H_3D_IV_MERGE
548    xDecompressCU(pcCU, uiAbsPartIdx, uiDepth );
549#endif
550    return;
551  }
552
553  m_pcEntropyDecoder->decodePredMode( pcCU, uiAbsPartIdx, uiDepth );
554  m_pcEntropyDecoder->decodePartSize( pcCU, uiAbsPartIdx, uiDepth );
555
556#if H_3D_DIM_SDC
557  m_pcEntropyDecoder->decodeSDCFlag( pcCU, uiAbsPartIdx, uiDepth );
558#endif
559  if (pcCU->isIntra( uiAbsPartIdx ) && pcCU->getPartitionSize( uiAbsPartIdx ) == SIZE_2Nx2N )
560  {
561    m_pcEntropyDecoder->decodeIPCMInfo( pcCU, uiAbsPartIdx, uiDepth );
562
563    if(pcCU->getIPCMFlag(uiAbsPartIdx))
564    {
565      xFinishDecodeCU( pcCU, uiAbsPartIdx, uiDepth, ruiIsLast );
566#if H_3D_IV_MERGE
567      xDecompressCU(pcCU, uiAbsPartIdx, uiDepth );
568#endif
569      return;
570    }
571  }
572
573  UInt uiCurrWidth      = pcCU->getWidth ( uiAbsPartIdx );
574  UInt uiCurrHeight     = pcCU->getHeight( uiAbsPartIdx );
575 
576  // prediction mode ( Intra : direction mode, Inter : Mv, reference idx )
577  m_pcEntropyDecoder->decodePredInfo( pcCU, uiAbsPartIdx, uiDepth, m_ppcCU[uiDepth]);
578  // Coefficient decoding
579  Bool bCodeDQP = getdQPFlag();
580  m_pcEntropyDecoder->decodeCoeff( pcCU, uiAbsPartIdx, uiDepth, uiCurrWidth, uiCurrHeight, bCodeDQP );
581  setdQPFlag( bCodeDQP );
582  xFinishDecodeCU( pcCU, uiAbsPartIdx, uiDepth, ruiIsLast );
583#if H_3D_IV_MERGE
584  xDecompressCU(pcCU, uiAbsPartIdx, uiDepth );
585#endif
586}
587
588Void TDecCu::xFinishDecodeCU( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, UInt& ruiIsLast)
589{
590  if(  pcCU->getSlice()->getPPS()->getUseDQP())
591  {
592    pcCU->setQPSubParts( getdQPFlag()?pcCU->getRefQP(uiAbsPartIdx):pcCU->getCodedQP(), uiAbsPartIdx, uiDepth ); // set QP
593  }
594
595  ruiIsLast = xDecodeSliceEnd( pcCU, uiAbsPartIdx, uiDepth);
596}
597
598Void TDecCu::xDecompressCU( TComDataCU* pcCU, UInt uiAbsPartIdx,  UInt uiDepth )
599{
600  TComPic* pcPic = pcCU->getPic();
601#if !H_3D_IV_MERGE
602  Bool bBoundary = false;
603  UInt uiLPelX   = pcCU->getCUPelX() + g_auiRasterToPelX[ g_auiZscanToRaster[uiAbsPartIdx] ];
604  UInt uiRPelX   = uiLPelX + (g_uiMaxCUWidth>>uiDepth)  - 1;
605  UInt uiTPelY   = pcCU->getCUPelY() + g_auiRasterToPelY[ g_auiZscanToRaster[uiAbsPartIdx] ];
606  UInt uiBPelY   = uiTPelY + (g_uiMaxCUHeight>>uiDepth) - 1;
607 
608  UInt uiCurNumParts    = pcPic->getNumPartInCU() >> (uiDepth<<1);
609  TComSlice * pcSlice = pcCU->getPic()->getSlice(pcCU->getPic()->getCurrSliceIdx());
610  Bool bStartInCU = pcCU->getSCUAddr()+uiAbsPartIdx+uiCurNumParts>pcSlice->getSliceSegmentCurStartCUAddr()&&pcCU->getSCUAddr()+uiAbsPartIdx<pcSlice->getSliceSegmentCurStartCUAddr();
611  if(bStartInCU||( uiRPelX >= pcSlice->getSPS()->getPicWidthInLumaSamples() ) || ( uiBPelY >= pcSlice->getSPS()->getPicHeightInLumaSamples() ) )
612  {
613    bBoundary = true;
614  }
615 
616  if( ( ( uiDepth < pcCU->getDepth( uiAbsPartIdx ) ) && ( uiDepth < g_uiMaxCUDepth - g_uiAddCUDepth ) ) || bBoundary )
617  {
618    UInt uiNextDepth = uiDepth + 1;
619    UInt uiQNumParts = pcCU->getTotalNumPart() >> (uiNextDepth<<1);
620    UInt uiIdx = uiAbsPartIdx;
621    for ( UInt uiPartIdx = 0; uiPartIdx < 4; uiPartIdx++ )
622    {
623      uiLPelX = pcCU->getCUPelX() + g_auiRasterToPelX[ g_auiZscanToRaster[uiIdx] ];
624      uiTPelY = pcCU->getCUPelY() + g_auiRasterToPelY[ g_auiZscanToRaster[uiIdx] ];
625     
626      Bool binSlice = (pcCU->getSCUAddr()+uiIdx+uiQNumParts>pcSlice->getSliceSegmentCurStartCUAddr())&&(pcCU->getSCUAddr()+uiIdx<pcSlice->getSliceSegmentCurEndCUAddr());
627      if(binSlice&&( uiLPelX < pcSlice->getSPS()->getPicWidthInLumaSamples() ) && ( uiTPelY < pcSlice->getSPS()->getPicHeightInLumaSamples() ) )
628      {
629        xDecompressCU(pcCU, uiIdx, uiNextDepth );
630      }
631     
632      uiIdx += uiQNumParts;
633    }
634    return;
635  }
636#endif 
637  // Residual reconstruction
638  m_ppcYuvResi[uiDepth]->clear();
639 
640  m_ppcCU[uiDepth]->copySubCU( pcCU, uiAbsPartIdx, uiDepth );
641 
642#if H_MV_ENC_DEC_TRAC
643#if ENC_DEC_TRACE
644  stopAtPos  ( m_ppcCU[uiDepth]->getSlice()->getPOC(), 
645    m_ppcCU[uiDepth]->getSlice()->getLayerId(), 
646    m_ppcCU[uiDepth]->getCUPelX(),
647    m_ppcCU[uiDepth]->getCUPelY(),
648    m_ppcCU[uiDepth]->getWidth(0), 
649    m_ppcCU[uiDepth]->getHeight(0) );
650#endif
651#endif
652
653  switch( m_ppcCU[uiDepth]->getPredictionMode(0) )
654  {
655    case MODE_INTER:
656#if H_3D_DBBP
657      if( m_ppcCU[uiDepth]->getDBBPFlag(0) )
658      {
659        xReconInterDBBP( m_ppcCU[uiDepth], uiAbsPartIdx, uiDepth );
660      }
661      else
662      {
663#endif
664#if H_3D_INTER_SDC
665      if( m_ppcCU[uiDepth]->getSDCFlag( 0 ) )
666      {
667        xReconInterSDC( m_ppcCU[uiDepth], uiAbsPartIdx, uiDepth );
668      }
669      else
670      {
671#endif
672      xReconInter( m_ppcCU[uiDepth], uiDepth );
673#if H_3D_INTER_SDC
674      }
675#endif
676#if H_3D_DBBP
677      }
678#endif
679      break;
680    case MODE_INTRA:
681#if H_3D_DIM_SDC
682      if( m_ppcCU[uiDepth]->getSDCFlag(0) )
683        xReconIntraSDC( m_ppcCU[uiDepth], 0, uiDepth );
684      else
685#endif
686      xReconIntraQT( m_ppcCU[uiDepth], uiDepth );
687      break;
688    default:
689      assert(0);
690      break;
691  }
692  if ( m_ppcCU[uiDepth]->isLosslessCoded(0) && (m_ppcCU[uiDepth]->getIPCMFlag(0) == false))
693  {
694    xFillPCMBuffer(m_ppcCU[uiDepth], uiDepth);
695  }
696 
697  xCopyToPic( m_ppcCU[uiDepth], pcPic, uiAbsPartIdx, uiDepth );
698}
699
700Void TDecCu::xReconInter( TComDataCU* pcCU, UInt uiDepth )
701{
702 
703  // inter prediction
704  m_pcPrediction->motionCompensation( pcCU, m_ppcYuvReco[uiDepth] );
705 
706  // inter recon
707  xDecodeInterTexture( pcCU, 0, uiDepth );
708 
709  // clip for only non-zero cbp case
710  if  ( ( pcCU->getCbf( 0, TEXT_LUMA ) ) || ( pcCU->getCbf( 0, TEXT_CHROMA_U ) ) || ( pcCU->getCbf(0, TEXT_CHROMA_V ) ) )
711  {
712    m_ppcYuvReco[uiDepth]->addClip( m_ppcYuvReco[uiDepth], m_ppcYuvResi[uiDepth], 0, pcCU->getWidth( 0 ) );
713  }
714  else
715  {
716    m_ppcYuvReco[uiDepth]->copyPartToPartYuv( m_ppcYuvReco[uiDepth],0, pcCU->getWidth( 0 ),pcCU->getHeight( 0 ));
717  }
718}
719
720#if H_3D_INTER_SDC
721Void TDecCu::xReconInterSDC( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
722{
723  // inter prediction
724  m_pcPrediction->motionCompensation( pcCU, m_ppcYuvReco[uiDepth] );
725
726  UInt  uiWidth      = pcCU->getWidth ( 0 );
727  UInt  uiHeight     = pcCU->getHeight( 0 );
728
729  Pel  *pResi;
730  UInt uiPelX, uiPelY;
731  UInt uiResiStride = m_ppcYuvResi[uiDepth]->getStride();
732
733  pResi = m_ppcYuvResi[uiDepth]->getLumaAddr( 0 );
734  for( uiPelY = 0; uiPelY < uiHeight; uiPelY++ )
735  {
736    for( uiPelX = 0; uiPelX < uiWidth; uiPelX++ )
737    {
738      pResi[ uiPelX ] = pcCU->getSDCSegmentDCOffset( 0, 0 );
739    }
740    pResi += uiResiStride;
741  }
742
743  m_ppcYuvReco[uiDepth]->addClip( m_ppcYuvReco[uiDepth], m_ppcYuvResi[uiDepth], 0, pcCU->getWidth( 0 ) );
744
745  // clear UV
746  UInt  uiStrideC     = m_ppcYuvReco[uiDepth]->getCStride();
747  Pel   *pRecCb       = m_ppcYuvReco[uiDepth]->getCbAddr();
748  Pel   *pRecCr       = m_ppcYuvReco[uiDepth]->getCrAddr();
749
750  for (Int y = 0; y < uiHeight/2; y++)
751  {
752    for (Int x = 0; x < uiWidth/2; x++)
753    {
754      pRecCb[x] = (Pel)( 1 << ( g_bitDepthC - 1 ) );
755      pRecCr[x] = (Pel)( 1 << ( g_bitDepthC - 1 ) );
756    }
757
758    pRecCb += uiStrideC;
759    pRecCr += uiStrideC;
760  }
761}
762#endif
763
764#if H_3D_DBBP
765Void TDecCu::xReconInterDBBP( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
766{
767  AOF(!pcCU->getSlice()->getIsDepth());
768  AOF(!pcCU->getSlice()->isIntra());
769  PartSize ePartSize = pcCU->getPartitionSize( 0 );
770 
771  // get collocated depth block
772  UInt uiDepthStride = 0;
773  Pel* pDepthPels = pcCU->getVirtualDepthBlock(0, pcCU->getWidth(0), pcCU->getHeight(0), uiDepthStride);
774  AOF( pDepthPels != NULL );
775  AOF( uiDepthStride != 0 );
776 
777  // compute mask by segmenting depth block
778  Bool pMask[MAX_CU_SIZE*MAX_CU_SIZE];
779  Bool bValidMask = m_pcPrediction->getSegmentMaskFromDepth(pDepthPels, uiDepthStride, pcCU->getWidth(0), pcCU->getHeight(0), pMask);
780  AOF(bValidMask);
781 
782  DBBPTmpData* pDBBPTmpData = pcCU->getDBBPTmpData();
783  TComYuv* apSegPredYuv[2] = { m_ppcYuvReco[uiDepth], m_ppcYuvRecoDBBP[uiDepth] };
784 
785  // first, extract the two sets of motion parameters
786  UInt uiPUOffset = ( g_auiPUOffset[UInt( ePartSize )] << ( ( pcCU->getSlice()->getSPS()->getMaxCUDepth() - uiDepth ) << 1 ) ) >> 4;
787  for( UInt uiSegment = 0; uiSegment < 2; uiSegment++ )
788  {
789    UInt uiPartAddr = uiSegment*uiPUOffset;
790   
791    pDBBPTmpData->auhInterDir[uiSegment] = pcCU->getInterDir(uiPartAddr);
792   
793    for ( UInt uiRefListIdx = 0; uiRefListIdx < 2; uiRefListIdx++ )
794    {
795      RefPicList eRefList = (RefPicList)uiRefListIdx;
796      pcCU->getMvField(pcCU, uiPartAddr, eRefList, pDBBPTmpData->acMvField[uiSegment][eRefList]);
797    }
798   
799#if RWTH_DBBP_NO_SPU_H0057
800    AOF( pcCU->getARPW(uiPartAddr) == 0 );
801    AOF( pcCU->getICFlag(uiPartAddr) == false );
802    AOF( pcCU->getSPIVMPFlag(uiPartAddr) == false );
803    AOF( pcCU->getVSPFlag(uiPartAddr) == 0 );
804#else
805    pDBBPTmpData->ahVSPFlag[uiSegment] = pcCU->getVSPFlag( uiPartAddr );
806    pDBBPTmpData->acDvInfo[uiSegment] = pcCU->getDvInfo( uiPartAddr );
807#endif
808  }
809 
810  // do motion compensation for each segment as 2Nx2N
811  pcCU->setPartSizeSubParts( SIZE_2Nx2N, 0, uiDepth );
812  pcCU->setPredModeSubParts( MODE_INTER, 0, uiDepth );
813  for( UInt uiSegment = 0; uiSegment < 2; uiSegment++ )
814  {
815    pcCU->setInterDirSubParts( pDBBPTmpData->auhInterDir[uiSegment], 0, 0, uiDepth );
816   
817#if !RWTH_DBBP_NO_SPU_H0057
818    pcCU->setVSPFlagSubParts( pDBBPTmpData->ahVSPFlag[uiSegment], 0, 0, uiDepth );
819    pcCU->setDvInfoSubParts( pDBBPTmpData->acDvInfo[uiSegment], 0, 0, uiDepth );
820#endif
821   
822    for ( UInt uiRefListIdx = 0; uiRefListIdx < 2; uiRefListIdx++ )
823    {
824      RefPicList eRefList = (RefPicList)uiRefListIdx;
825
826      pcCU->getCUMvField( eRefList )->setAllMvField( pDBBPTmpData->acMvField[uiSegment][eRefList], SIZE_2Nx2N, 0, 0 );
827    }
828   
829    // inter prediction
830    m_pcPrediction->motionCompensation( pcCU, apSegPredYuv[uiSegment] );
831  }
832 
833  // restore motion information in both segments again
834  pcCU->setPartSizeSubParts( ePartSize,  0, uiDepth );
835  pcCU->setPredModeSubParts( MODE_INTER, 0, uiDepth );
836  for( UInt uiSegment = 0; uiSegment < 2; uiSegment++ )
837  {
838    UInt uiPartAddr = uiSegment*uiPUOffset;
839   
840    pcCU->setDBBPFlagSubParts(true, uiPartAddr, uiSegment, uiDepth);
841   
842#if !RWTH_DBBP_NO_SPU_H0057
843    pcCU->setVSPFlagSubParts( pDBBPTmpData->ahVSPFlag[uiSegment], uiPartAddr, uiSegment, uiDepth );
844    pcCU->setDvInfoSubParts( pDBBPTmpData->acDvInfo[uiSegment], uiPartAddr, uiSegment, uiDepth );
845#endif
846   
847    pcCU->setInterDirSubParts(pDBBPTmpData->auhInterDir[uiSegment], uiPartAddr, uiSegment, uiDepth); // interprets depth relative to LCU level
848   
849    for ( UInt uiRefListIdx = 0; uiRefListIdx < 2; uiRefListIdx++ )
850    {
851      RefPicList eRefList = (RefPicList)uiRefListIdx;
852
853      pcCU->getCUMvField( eRefList )->setAllMvField( pDBBPTmpData->acMvField[uiSegment][eRefList], ePartSize, uiPartAddr, 0, uiSegment ); // interprets depth relative to rpcTempCU level
854    }
855  }
856 
857  // reconstruct final prediction signal by combining both segments
858  m_pcPrediction->combineSegmentsWithMask(apSegPredYuv, m_ppcYuvReco[uiDepth], pMask, pcCU->getWidth(0), pcCU->getHeight(0));
859 
860  // inter recon
861  xDecodeInterTexture( pcCU, 0, uiDepth );
862 
863  // clip for only non-zero cbp case
864  if  ( ( pcCU->getCbf( 0, TEXT_LUMA ) ) || ( pcCU->getCbf( 0, TEXT_CHROMA_U ) ) || ( pcCU->getCbf(0, TEXT_CHROMA_V ) ) )
865  {
866    m_ppcYuvReco[uiDepth]->addClip( m_ppcYuvReco[uiDepth], m_ppcYuvResi[uiDepth], 0, pcCU->getWidth( 0 ) );
867  }
868  else
869  {
870    m_ppcYuvReco[uiDepth]->copyPartToPartYuv( m_ppcYuvReco[uiDepth],0, pcCU->getWidth( 0 ),pcCU->getHeight( 0 ));
871  }
872}
873#endif
874
875Void
876TDecCu::xIntraRecLumaBlk( TComDataCU* pcCU,
877                         UInt        uiTrDepth,
878                         UInt        uiAbsPartIdx,
879                         TComYuv*    pcRecoYuv,
880                         TComYuv*    pcPredYuv, 
881                         TComYuv*    pcResiYuv )
882{
883  UInt    uiWidth           = pcCU     ->getWidth   ( 0 ) >> uiTrDepth;
884  UInt    uiHeight          = pcCU     ->getHeight  ( 0 ) >> uiTrDepth;
885  UInt    uiStride          = pcRecoYuv->getStride  ();
886  Pel*    piReco            = pcRecoYuv->getLumaAddr( uiAbsPartIdx );
887  Pel*    piPred            = pcPredYuv->getLumaAddr( uiAbsPartIdx );
888  Pel*    piResi            = pcResiYuv->getLumaAddr( uiAbsPartIdx );
889 
890  UInt    uiNumCoeffInc     = ( pcCU->getSlice()->getSPS()->getMaxCUWidth() * pcCU->getSlice()->getSPS()->getMaxCUHeight() ) >> ( pcCU->getSlice()->getSPS()->getMaxCUDepth() << 1 );
891  TCoeff* pcCoeff           = pcCU->getCoeffY() + ( uiNumCoeffInc * uiAbsPartIdx );
892 
893  UInt    uiLumaPredMode    = pcCU->getLumaIntraDir     ( uiAbsPartIdx );
894 
895  UInt    uiZOrder          = pcCU->getZorderIdxInCU() + uiAbsPartIdx;
896  Pel*    piRecIPred        = pcCU->getPic()->getPicYuvRec()->getLumaAddr( pcCU->getAddr(), uiZOrder );
897  UInt    uiRecIPredStride  = pcCU->getPic()->getPicYuvRec()->getStride  ();
898  Bool    useTransformSkip  = pcCU->getTransformSkip(uiAbsPartIdx, TEXT_LUMA);
899  //===== init availability pattern =====
900  Bool  bAboveAvail = false;
901  Bool  bLeftAvail  = false;
902  pcCU->getPattern()->initPattern   ( pcCU, uiTrDepth, uiAbsPartIdx );
903  pcCU->getPattern()->initAdiPattern( pcCU, uiAbsPartIdx, uiTrDepth, 
904                                     m_pcPrediction->getPredicBuf       (),
905                                     m_pcPrediction->getPredicBufWidth  (),
906                                     m_pcPrediction->getPredicBufHeight (),
907                                     bAboveAvail, bLeftAvail );
908 
909  //===== get prediction signal =====
910#if H_3D_DIM
911  if( isDimMode( uiLumaPredMode ) )
912  {
913    m_pcPrediction->predIntraLumaDepth( pcCU, uiAbsPartIdx, uiLumaPredMode, piPred, uiStride, uiWidth, uiHeight );
914  }
915  else
916  {
917#endif
918  m_pcPrediction->predIntraLumaAng( pcCU->getPattern(), uiLumaPredMode, piPred, uiStride, uiWidth, uiHeight, bAboveAvail, bLeftAvail );
919#if H_3D_DIM
920  }
921#endif
922 
923#if H_3D
924  Bool useDltFlag = (isDimMode( uiLumaPredMode ) || uiLumaPredMode == HOR_IDX || uiLumaPredMode == VER_IDX || uiLumaPredMode == DC_IDX) && pcCU->getSlice()->getIsDepth() && pcCU->getSlice()->getPPS()->getDLT()->getUseDLTFlag(pcCU->getSlice()->getLayerIdInVps());
925
926  if ( pcCU->getCbf( uiAbsPartIdx, TEXT_LUMA, uiTrDepth ) || useDltFlag )
927#else
928  if ( pcCU->getCbf( uiAbsPartIdx, TEXT_LUMA, uiTrDepth ) )
929#endif
930  {
931  //===== inverse transform =====
932  m_pcTrQuant->setQPforQuant  ( pcCU->getQP(0), TEXT_LUMA, pcCU->getSlice()->getSPS()->getQpBDOffsetY(), 0 );
933
934  Int scalingListType = (pcCU->isIntra(uiAbsPartIdx) ? 0 : 3) + g_eTTable[(Int)TEXT_LUMA];
935    assert(scalingListType < SCALING_LIST_NUM);
936  m_pcTrQuant->invtransformNxN( pcCU->getCUTransquantBypass(uiAbsPartIdx), TEXT_LUMA, pcCU->getLumaIntraDir( uiAbsPartIdx ), piResi, uiStride, pcCoeff, uiWidth, uiHeight, scalingListType, useTransformSkip );
937
938 
939  //===== reconstruction =====
940  Pel* pPred      = piPred;
941  Pel* pResi      = piResi;
942  Pel* pReco      = piReco;
943  Pel* pRecIPred  = piRecIPred;
944  for( UInt uiY = 0; uiY < uiHeight; uiY++ )
945  {
946    for( UInt uiX = 0; uiX < uiWidth; uiX++ )
947    {
948#if H_3D && !SEC_NO_RESI_DLT_H0105
949      if ( useDltFlag )
950      {
951        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 ] ) );
952      }
953      else
954      {
955        pReco    [ uiX ] = ClipY( pPred[ uiX ] + pResi[ uiX ] );
956      }
957#else
958      pReco    [ uiX ] = ClipY( pPred[ uiX ] + pResi[ uiX ] );
959#endif
960      pRecIPred[ uiX ] = pReco[ uiX ];
961    }
962    pPred     += uiStride;
963    pResi     += uiStride;
964    pReco     += uiStride;
965    pRecIPred += uiRecIPredStride;
966  }
967}
968  else
969  {
970    //===== reconstruction =====
971    Pel* pPred      = piPred;
972    Pel* pReco      = piReco;
973    Pel* pRecIPred  = piRecIPred;
974    for ( Int y = 0; y < uiHeight; y++ )
975    {
976      for ( Int x = 0; x < uiWidth; x++ )
977      {
978        pReco    [ x ] = pPred[ x ];
979        pRecIPred[ x ] = pReco[ x ];
980      }
981      pPred     += uiStride;
982      pReco     += uiStride;
983      pRecIPred += uiRecIPredStride;
984    }
985  }
986}
987
988
989Void
990TDecCu::xIntraRecChromaBlk( TComDataCU* pcCU,
991                           UInt        uiTrDepth,
992                           UInt        uiAbsPartIdx,
993                           TComYuv*    pcRecoYuv,
994                           TComYuv*    pcPredYuv, 
995                           TComYuv*    pcResiYuv,
996                           UInt        uiChromaId )
997{
998  UInt uiFullDepth  = pcCU->getDepth( 0 ) + uiTrDepth;
999  UInt uiLog2TrSize = g_aucConvertToBit[ pcCU->getSlice()->getSPS()->getMaxCUWidth() >> uiFullDepth ] + 2;
1000
1001  if( uiLog2TrSize == 2 )
1002  {
1003    assert( uiTrDepth > 0 );
1004    uiTrDepth--;
1005    UInt uiQPDiv = pcCU->getPic()->getNumPartInCU() >> ( ( pcCU->getDepth( 0 ) + uiTrDepth ) << 1 );
1006    Bool bFirstQ = ( ( uiAbsPartIdx % uiQPDiv ) == 0 );
1007    if( !bFirstQ )
1008    {
1009      return;
1010    }
1011  }
1012 
1013  TextType  eText             = ( uiChromaId > 0 ? TEXT_CHROMA_V : TEXT_CHROMA_U );
1014  UInt      uiWidth           = pcCU     ->getWidth   ( 0 ) >> ( uiTrDepth + 1 );
1015  UInt      uiHeight          = pcCU     ->getHeight  ( 0 ) >> ( uiTrDepth + 1 );
1016  UInt      uiStride          = pcRecoYuv->getCStride ();
1017  Pel*      piReco            = ( uiChromaId > 0 ? pcRecoYuv->getCrAddr( uiAbsPartIdx ) : pcRecoYuv->getCbAddr( uiAbsPartIdx ) );
1018  Pel*      piPred            = ( uiChromaId > 0 ? pcPredYuv->getCrAddr( uiAbsPartIdx ) : pcPredYuv->getCbAddr( uiAbsPartIdx ) );
1019  Pel*      piResi            = ( uiChromaId > 0 ? pcResiYuv->getCrAddr( uiAbsPartIdx ) : pcResiYuv->getCbAddr( uiAbsPartIdx ) );
1020 
1021  UInt      uiNumCoeffInc     = ( ( pcCU->getSlice()->getSPS()->getMaxCUWidth() * pcCU->getSlice()->getSPS()->getMaxCUHeight() ) >> ( pcCU->getSlice()->getSPS()->getMaxCUDepth() << 1 ) ) >> 2;
1022  TCoeff*   pcCoeff           = ( uiChromaId > 0 ? pcCU->getCoeffCr() : pcCU->getCoeffCb() ) + ( uiNumCoeffInc * uiAbsPartIdx );
1023 
1024  UInt      uiChromaPredMode  = pcCU->getChromaIntraDir( 0 );
1025 
1026  UInt      uiZOrder          = pcCU->getZorderIdxInCU() + uiAbsPartIdx;
1027  Pel*      piRecIPred        = ( uiChromaId > 0 ? pcCU->getPic()->getPicYuvRec()->getCrAddr( pcCU->getAddr(), uiZOrder ) : pcCU->getPic()->getPicYuvRec()->getCbAddr( pcCU->getAddr(), uiZOrder ) );
1028  UInt      uiRecIPredStride  = pcCU->getPic()->getPicYuvRec()->getCStride();
1029  Bool      useTransformSkipChroma = pcCU->getTransformSkip(uiAbsPartIdx,eText);
1030  //===== init availability pattern =====
1031  Bool  bAboveAvail = false;
1032  Bool  bLeftAvail  = false;
1033  pcCU->getPattern()->initPattern         ( pcCU, uiTrDepth, uiAbsPartIdx );
1034
1035  pcCU->getPattern()->initAdiPatternChroma( pcCU, uiAbsPartIdx, uiTrDepth,
1036                                           m_pcPrediction->getPredicBuf       (),
1037                                           m_pcPrediction->getPredicBufWidth  (),
1038                                           m_pcPrediction->getPredicBufHeight (),
1039                                           bAboveAvail, bLeftAvail );
1040  Int* pPatChroma   = ( uiChromaId > 0 ? pcCU->getPattern()->getAdiCrBuf( uiWidth, uiHeight, m_pcPrediction->getPredicBuf() ) : pcCU->getPattern()->getAdiCbBuf( uiWidth, uiHeight, m_pcPrediction->getPredicBuf() ) );
1041 
1042  //===== get prediction signal =====
1043  {
1044    if( uiChromaPredMode == DM_CHROMA_IDX )
1045    {
1046      uiChromaPredMode = pcCU->getLumaIntraDir( 0 );
1047#if H_3D_DIM
1048      mapDepthModeToIntraDir( uiChromaPredMode );
1049#endif
1050    }
1051    m_pcPrediction->predIntraChromaAng( pPatChroma, uiChromaPredMode, piPred, uiStride, uiWidth, uiHeight, bAboveAvail, bLeftAvail ); 
1052  }
1053
1054  if ( pcCU->getCbf( uiAbsPartIdx, eText, uiTrDepth ) )
1055  {
1056  //===== inverse transform =====
1057  Int curChromaQpOffset;
1058  if(eText == TEXT_CHROMA_U)
1059  {
1060    curChromaQpOffset = pcCU->getSlice()->getPPS()->getChromaCbQpOffset() + pcCU->getSlice()->getSliceQpDeltaCb();
1061  }
1062  else
1063  {
1064    curChromaQpOffset = pcCU->getSlice()->getPPS()->getChromaCrQpOffset() + pcCU->getSlice()->getSliceQpDeltaCr();
1065  }
1066  m_pcTrQuant->setQPforQuant  ( pcCU->getQP(0), eText, pcCU->getSlice()->getSPS()->getQpBDOffsetC(), curChromaQpOffset );
1067
1068  Int scalingListType = (pcCU->isIntra(uiAbsPartIdx) ? 0 : 3) + g_eTTable[(Int)eText];
1069    assert(scalingListType < SCALING_LIST_NUM);
1070  m_pcTrQuant->invtransformNxN( pcCU->getCUTransquantBypass(uiAbsPartIdx), eText, REG_DCT, piResi, uiStride, pcCoeff, uiWidth, uiHeight, scalingListType, useTransformSkipChroma );
1071
1072  //===== reconstruction =====
1073  Pel* pPred      = piPred;
1074  Pel* pResi      = piResi;
1075  Pel* pReco      = piReco;
1076  Pel* pRecIPred  = piRecIPred;
1077  for( UInt uiY = 0; uiY < uiHeight; uiY++ )
1078  {
1079    for( UInt uiX = 0; uiX < uiWidth; uiX++ )
1080    {
1081      pReco    [ uiX ] = ClipC( pPred[ uiX ] + pResi[ uiX ] );
1082      pRecIPred[ uiX ] = pReco[ uiX ];
1083    }
1084    pPred     += uiStride;
1085    pResi     += uiStride;
1086    pReco     += uiStride;
1087    pRecIPred += uiRecIPredStride;
1088  }
1089}
1090  else
1091  {
1092    //===== reconstruction =====
1093    Pel* pPred      = piPred;
1094    Pel* pReco      = piReco;
1095    Pel* pRecIPred  = piRecIPred;
1096    for ( Int y = 0; y < uiHeight; y++ )
1097    {
1098      for ( Int x = 0; x < uiWidth; x++ )
1099      {
1100        pReco    [ x ] = pPred[ x ];
1101        pRecIPred[ x ] = pReco[ x ];
1102      }
1103      pPred     += uiStride;
1104      pReco     += uiStride;
1105      pRecIPred += uiRecIPredStride;
1106    }   
1107  }
1108}
1109
1110
1111Void
1112TDecCu::xReconIntraQT( TComDataCU* pcCU, UInt uiDepth )
1113{
1114  UInt  uiInitTrDepth = ( pcCU->getPartitionSize(0) == SIZE_2Nx2N ? 0 : 1 );
1115  UInt  uiNumPart     = pcCU->getNumPartInter();
1116  UInt  uiNumQParts   = pcCU->getTotalNumPart() >> 2;
1117 
1118  if (pcCU->getIPCMFlag(0))
1119  {
1120    xReconPCM( pcCU, uiDepth );
1121    return;
1122  }
1123
1124  for( UInt uiPU = 0; uiPU < uiNumPart; uiPU++ )
1125  {
1126    xIntraLumaRecQT( pcCU, uiInitTrDepth, uiPU * uiNumQParts, m_ppcYuvReco[uiDepth], m_ppcYuvReco[uiDepth], m_ppcYuvResi[uiDepth] );
1127  } 
1128
1129  for( UInt uiPU = 0; uiPU < uiNumPart; uiPU++ )
1130  {
1131    xIntraChromaRecQT( pcCU, uiInitTrDepth, uiPU * uiNumQParts, m_ppcYuvReco[uiDepth], m_ppcYuvReco[uiDepth], m_ppcYuvResi[uiDepth] );
1132  }
1133
1134}
1135
1136#if H_3D_DIM_SDC
1137Void TDecCu::xReconIntraSDC( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
1138{
1139  UInt uiWidth        = pcCU->getWidth  ( 0 );
1140  UInt uiHeight       = pcCU->getHeight ( 0 );
1141  TComWedgelet* dmm4SegmentationOrg = new TComWedgelet( uiWidth, uiHeight );
1142  UInt numParts = 1;
1143  UInt sdcDepth    = 0;
1144  TComYuv* pcRecoYuv  = m_ppcYuvReco[uiDepth];
1145  TComYuv* pcPredYuv  = m_ppcYuvReco[uiDepth];
1146  TComYuv* pcResiYuv  = m_ppcYuvResi[uiDepth];
1147
1148  UInt    uiStride = 0;
1149  Pel*    piReco;
1150  Pel*    piPred;
1151  Pel*    piResi;
1152
1153  UInt    uiZOrder;       
1154  Pel*    piRecIPred;     
1155  UInt    uiRecIPredStride;
1156
1157  UInt    uiLumaPredMode = 0; 
1158
1159  if ((uiWidth >> pcCU->getSlice()->getSPS()->getQuadtreeTULog2MaxSize()) > 1)
1160  {
1161    numParts = uiWidth * uiWidth >> (2 * pcCU->getSlice()->getSPS()->getQuadtreeTULog2MaxSize());
1162    sdcDepth = g_aucConvertToBit[uiWidth] + 2 - pcCU->getSlice()->getSPS()->getQuadtreeTULog2MaxSize();
1163    uiWidth = uiHeight = (1 << pcCU->getSlice()->getSPS()->getQuadtreeTULog2MaxSize());
1164  }
1165
1166  for ( Int i = 0; i < numParts; i++ )
1167  {
1168    uiStride    = pcRecoYuv->getStride  ();
1169    piReco      = pcRecoYuv->getLumaAddr( uiAbsPartIdx );
1170    piPred      = pcPredYuv->getLumaAddr( uiAbsPartIdx );
1171    piResi      = pcResiYuv->getLumaAddr( uiAbsPartIdx );
1172
1173    uiZOrder          = pcCU->getZorderIdxInCU() + uiAbsPartIdx;
1174    piRecIPred        = pcCU->getPic()->getPicYuvRec()->getLumaAddr( pcCU->getAddr(), uiZOrder );
1175    uiRecIPredStride  = pcCU->getPic()->getPicYuvRec()->getStride  ();
1176
1177    uiLumaPredMode    = pcCU->getLumaIntraDir     ( uiAbsPartIdx );
1178
1179    AOF( uiWidth == uiHeight );
1180
1181    //===== init availability pattern =====
1182    Bool  bAboveAvail = false;
1183    Bool  bLeftAvail  = false;
1184
1185    pcCU->getPattern()->initPattern   ( pcCU, sdcDepth, uiAbsPartIdx );
1186    pcCU->getPattern()->initAdiPattern( pcCU, uiAbsPartIdx, sdcDepth, m_pcPrediction->getPredicBuf(), m_pcPrediction->getPredicBufWidth(), m_pcPrediction->getPredicBufHeight(), bAboveAvail, bLeftAvail );
1187
1188    TComWedgelet* dmm4Segmentation = new TComWedgelet( uiWidth, uiHeight );
1189    //===== get prediction signal =====
1190    if( isDimMode( uiLumaPredMode ) )
1191    {
1192      m_pcPrediction->predIntraLumaDepth( pcCU, uiAbsPartIdx, uiLumaPredMode, piPred, uiStride, uiWidth, uiHeight, false, dmm4Segmentation  );
1193      Bool* dmm4PatternSplit = dmm4Segmentation->getPattern();
1194      Bool* dmm4PatternOrg = dmm4SegmentationOrg->getPattern();
1195      for( UInt k = 0; k < (uiWidth*uiHeight); k++ ) 
1196      { 
1197        dmm4PatternOrg[k+(uiAbsPartIdx<<4)] = dmm4PatternSplit[k];
1198      }
1199    }
1200    else
1201    {
1202      m_pcPrediction->predIntraLumaAng( pcCU->getPattern(), uiLumaPredMode, piPred, uiStride, uiWidth, uiHeight, bAboveAvail, bLeftAvail );
1203    }
1204
1205    if ( numParts > 1 )
1206    {
1207      for( UInt uiY = 0; uiY < uiHeight; uiY++ )
1208      {
1209        for( UInt uiX = 0; uiX < uiWidth; uiX++ )
1210        {
1211          piReco        [ uiX ] = ClipY( piPred[ uiX ] );
1212          piRecIPred    [ uiX ] = piReco[ uiX ];
1213        }
1214        piPred     += uiStride;
1215        piReco     += uiStride;
1216        piRecIPred += uiRecIPredStride;
1217      }
1218    }
1219    uiAbsPartIdx += ( (uiWidth * uiWidth) >> 4 );
1220    dmm4Segmentation->destroy(); delete dmm4Segmentation;
1221  }
1222  uiAbsPartIdx = 0;
1223 
1224  if ( numParts > 1 )
1225  {
1226    uiWidth = pcCU->getWidth( 0 );
1227    uiHeight = pcCU->getHeight( 0 );
1228  }
1229  piReco      = pcRecoYuv->getLumaAddr( uiAbsPartIdx );
1230  piPred      = pcPredYuv->getLumaAddr( uiAbsPartIdx );
1231  piResi      = pcResiYuv->getLumaAddr( uiAbsPartIdx );
1232  uiZOrder          = pcCU->getZorderIdxInCU() + uiAbsPartIdx;
1233  piRecIPred        = pcCU->getPic()->getPicYuvRec()->getLumaAddr( pcCU->getAddr(), uiZOrder );
1234  uiRecIPredStride  = pcCU->getPic()->getPicYuvRec()->getStride  ();
1235  // number of segments depends on prediction mode
1236  UInt uiNumSegments = 1;
1237  Bool* pbMask = NULL;
1238  UInt uiMaskStride = 0;
1239 
1240  if( getDimType( uiLumaPredMode ) == DMM1_IDX )
1241  {
1242    Int uiTabIdx = pcCU->getDmmWedgeTabIdx(DMM1_IDX, uiAbsPartIdx);
1243   
1244    WedgeList* pacWedgeList = &g_dmmWedgeLists[(g_aucConvertToBit[uiWidth])];
1245    TComWedgelet* pcWedgelet = &(pacWedgeList->at( uiTabIdx ));
1246   
1247    uiNumSegments = 2;
1248    pbMask = pcWedgelet->getPattern();
1249    uiMaskStride = pcWedgelet->getStride();
1250  }
1251  if( getDimType( uiLumaPredMode ) == DMM4_IDX )
1252  {
1253    uiNumSegments = 2;
1254    pbMask  = dmm4SegmentationOrg->getPattern();
1255    uiMaskStride = dmm4SegmentationOrg->getStride();
1256  }
1257  // get DC prediction for each segment
1258  Pel apDCPredValues[2];
1259  m_pcPrediction->analyzeSegmentsSDC(piPred, uiStride, uiWidth, apDCPredValues, uiNumSegments, pbMask, uiMaskStride, uiLumaPredMode);
1260 
1261  // reconstruct residual based on mask + DC residuals
1262  Pel apDCResiValues[2];
1263  for( UInt uiSegment = 0; uiSegment < uiNumSegments; uiSegment++ )
1264  {
1265#if H_3D_DIM_DLT
1266    Pel   pPredIdx    = pcCU->getSlice()->getPPS()->getDLT()->depthValue2idx( pcCU->getSlice()->getLayerIdInVps(), apDCPredValues[uiSegment] );
1267    Pel   pResiIdx    = pcCU->getSDCSegmentDCOffset(uiSegment, uiAbsPartIdx);
1268    Pel   pRecoValue  = pcCU->getSlice()->getPPS()->getDLT()->idx2DepthValue( pcCU->getSlice()->getLayerIdInVps(), pPredIdx + pResiIdx );
1269
1270    apDCResiValues[uiSegment]  = pRecoValue - apDCPredValues[uiSegment];
1271#else
1272    apDCResiValues[uiSegment]  = pcCU->getSDCSegmentDCOffset(uiSegment, uiAbsPartIdx);
1273#endif
1274  }
1275 
1276  //===== reconstruction =====
1277  Bool*pMask      = pbMask;
1278  Pel* pPred      = piPred;
1279  Pel* pResi      = piResi;
1280  Pel* pReco      = piReco;
1281  Pel* pRecIPred  = piRecIPred;
1282 
1283  for( UInt uiY = 0; uiY < uiHeight; uiY++ )
1284  {
1285    for( UInt uiX = 0; uiX < uiWidth; uiX++ )
1286    {
1287      UChar ucSegment = pMask?(UChar)pMask[uiX]:0;
1288      assert( ucSegment < uiNumSegments );
1289     
1290      Pel pResiDC = apDCResiValues[ucSegment];
1291     
1292      pReco    [ uiX ] = ClipY( pPred[ uiX ] + pResiDC );
1293      pRecIPred[ uiX ] = pReco[ uiX ];
1294    }
1295    pPred     += uiStride;
1296    pResi     += uiStride;
1297    pReco     += uiStride;
1298    pRecIPred += uiRecIPredStride;
1299    pMask     += uiMaskStride;
1300  }
1301 
1302  // clear UV
1303  UInt  uiStrideC     = pcPredYuv->getCStride();
1304  Pel   *pRecCb       = pcPredYuv->getCbAddr();
1305  Pel   *pRecCr       = pcPredYuv->getCrAddr();
1306 
1307  for (Int y=0; y<uiHeight/2; y++)
1308  {
1309    for (Int x=0; x<uiWidth/2; x++)
1310    {
1311      pRecCb[x] = 128;
1312      pRecCr[x] = 128;
1313    }
1314   
1315    pRecCb += uiStrideC;
1316    pRecCr += uiStrideC;
1317  }
1318  dmm4SegmentationOrg->destroy(); delete dmm4SegmentationOrg;
1319}
1320#endif
1321
1322/** Function for deriving recontructed PU/CU Luma sample with QTree structure
1323 * \param pcCU pointer of current CU
1324 * \param uiTrDepth current tranform split depth
1325 * \param uiAbsPartIdx  part index
1326 * \param pcRecoYuv pointer to reconstructed sample arrays
1327 * \param pcPredYuv pointer to prediction sample arrays
1328 * \param pcResiYuv pointer to residue sample arrays
1329 *
1330 \ This function dervies recontructed PU/CU Luma sample with recursive QTree structure
1331 */
1332Void
1333TDecCu::xIntraLumaRecQT( TComDataCU* pcCU,
1334                     UInt        uiTrDepth,
1335                     UInt        uiAbsPartIdx,
1336                     TComYuv*    pcRecoYuv,
1337                     TComYuv*    pcPredYuv, 
1338                     TComYuv*    pcResiYuv )
1339{
1340  UInt uiFullDepth  = pcCU->getDepth(0) + uiTrDepth;
1341  UInt uiTrMode     = pcCU->getTransformIdx( uiAbsPartIdx );
1342  if( uiTrMode == uiTrDepth )
1343  {
1344    xIntraRecLumaBlk  ( pcCU, uiTrDepth, uiAbsPartIdx, pcRecoYuv, pcPredYuv, pcResiYuv );
1345  }
1346  else
1347  {
1348    UInt uiNumQPart  = pcCU->getPic()->getNumPartInCU() >> ( ( uiFullDepth + 1 ) << 1 );
1349    for( UInt uiPart = 0; uiPart < 4; uiPart++ )
1350    {
1351      xIntraLumaRecQT( pcCU, uiTrDepth + 1, uiAbsPartIdx + uiPart * uiNumQPart, pcRecoYuv, pcPredYuv, pcResiYuv );
1352    }
1353  }
1354}
1355
1356/** Function for deriving recontructed PU/CU chroma samples with QTree structure
1357 * \param pcCU pointer of current CU
1358 * \param uiTrDepth current tranform split depth
1359 * \param uiAbsPartIdx  part index
1360 * \param pcRecoYuv pointer to reconstructed sample arrays
1361 * \param pcPredYuv pointer to prediction sample arrays
1362 * \param pcResiYuv pointer to residue sample arrays
1363 *
1364 \ This function dervies recontructed PU/CU chroma samples with QTree recursive structure
1365 */
1366Void
1367TDecCu::xIntraChromaRecQT( TComDataCU* pcCU,
1368                     UInt        uiTrDepth,
1369                     UInt        uiAbsPartIdx,
1370                     TComYuv*    pcRecoYuv,
1371                     TComYuv*    pcPredYuv, 
1372                     TComYuv*    pcResiYuv )
1373{
1374  UInt uiFullDepth  = pcCU->getDepth(0) + uiTrDepth;
1375  UInt uiTrMode     = pcCU->getTransformIdx( uiAbsPartIdx );
1376  if( uiTrMode == uiTrDepth )
1377  {
1378    xIntraRecChromaBlk( pcCU, uiTrDepth, uiAbsPartIdx, pcRecoYuv, pcPredYuv, pcResiYuv, 0 );
1379    xIntraRecChromaBlk( pcCU, uiTrDepth, uiAbsPartIdx, pcRecoYuv, pcPredYuv, pcResiYuv, 1 );
1380  }
1381  else
1382  {
1383    UInt uiNumQPart  = pcCU->getPic()->getNumPartInCU() >> ( ( uiFullDepth + 1 ) << 1 );
1384    for( UInt uiPart = 0; uiPart < 4; uiPart++ )
1385    {
1386      xIntraChromaRecQT( pcCU, uiTrDepth + 1, uiAbsPartIdx + uiPart * uiNumQPart, pcRecoYuv, pcPredYuv, pcResiYuv );
1387    }
1388  }
1389}
1390
1391Void TDecCu::xCopyToPic( TComDataCU* pcCU, TComPic* pcPic, UInt uiZorderIdx, UInt uiDepth )
1392{
1393  UInt uiCUAddr = pcCU->getAddr();
1394 
1395  m_ppcYuvReco[uiDepth]->copyToPicYuv  ( pcPic->getPicYuvRec (), uiCUAddr, uiZorderIdx );
1396 
1397  return;
1398}
1399
1400Void TDecCu::xDecodeInterTexture ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
1401{
1402  UInt    uiWidth    = pcCU->getWidth ( uiAbsPartIdx );
1403  UInt    uiHeight   = pcCU->getHeight( uiAbsPartIdx );
1404  TCoeff* piCoeff;
1405 
1406  Pel*    pResi;
1407  UInt    trMode = pcCU->getTransformIdx( uiAbsPartIdx );
1408 
1409  // Y
1410  piCoeff = pcCU->getCoeffY();
1411  pResi = m_ppcYuvResi[uiDepth]->getLumaAddr();
1412
1413  m_pcTrQuant->setQPforQuant( pcCU->getQP( uiAbsPartIdx ), TEXT_LUMA, pcCU->getSlice()->getSPS()->getQpBDOffsetY(), 0 );
1414
1415  m_pcTrQuant->invRecurTransformNxN ( pcCU, 0, TEXT_LUMA, pResi, 0, m_ppcYuvResi[uiDepth]->getStride(), uiWidth, uiHeight, trMode, 0, piCoeff );
1416 
1417  // Cb and Cr
1418  Int curChromaQpOffset = pcCU->getSlice()->getPPS()->getChromaCbQpOffset() + pcCU->getSlice()->getSliceQpDeltaCb();
1419  m_pcTrQuant->setQPforQuant( pcCU->getQP( uiAbsPartIdx ), TEXT_CHROMA, pcCU->getSlice()->getSPS()->getQpBDOffsetC(), curChromaQpOffset );
1420
1421  uiWidth  >>= 1;
1422  uiHeight >>= 1;
1423  piCoeff = pcCU->getCoeffCb(); pResi = m_ppcYuvResi[uiDepth]->getCbAddr();
1424  m_pcTrQuant->invRecurTransformNxN ( pcCU, 0, TEXT_CHROMA_U, pResi, 0, m_ppcYuvResi[uiDepth]->getCStride(), uiWidth, uiHeight, trMode, 0, piCoeff );
1425
1426  curChromaQpOffset = pcCU->getSlice()->getPPS()->getChromaCrQpOffset() + pcCU->getSlice()->getSliceQpDeltaCr();
1427  m_pcTrQuant->setQPforQuant( pcCU->getQP( uiAbsPartIdx ), TEXT_CHROMA, pcCU->getSlice()->getSPS()->getQpBDOffsetC(), curChromaQpOffset );
1428
1429  piCoeff = pcCU->getCoeffCr(); pResi = m_ppcYuvResi[uiDepth]->getCrAddr();
1430  m_pcTrQuant->invRecurTransformNxN ( pcCU, 0, TEXT_CHROMA_V, pResi, 0, m_ppcYuvResi[uiDepth]->getCStride(), uiWidth, uiHeight, trMode, 0, piCoeff );
1431}
1432
1433/** Function for deriving reconstructed luma/chroma samples of a PCM mode CU.
1434 * \param pcCU pointer to current CU
1435 * \param uiPartIdx part index
1436 * \param piPCM pointer to PCM code arrays
1437 * \param piReco pointer to reconstructed sample arrays
1438 * \param uiStride stride of reconstructed sample arrays
1439 * \param uiWidth CU width
1440 * \param uiHeight CU height
1441 * \param ttText texture component type
1442 * \returns Void
1443 */
1444Void TDecCu::xDecodePCMTexture( TComDataCU* pcCU, UInt uiPartIdx, Pel *piPCM, Pel* piReco, UInt uiStride, UInt uiWidth, UInt uiHeight, TextType ttText)
1445{
1446  UInt uiX, uiY;
1447  Pel* piPicReco;
1448  UInt uiPicStride;
1449  UInt uiPcmLeftShiftBit; 
1450
1451  if( ttText == TEXT_LUMA )
1452  {
1453    uiPicStride   = pcCU->getPic()->getPicYuvRec()->getStride();
1454    piPicReco = pcCU->getPic()->getPicYuvRec()->getLumaAddr(pcCU->getAddr(), pcCU->getZorderIdxInCU()+uiPartIdx);
1455    uiPcmLeftShiftBit = g_bitDepthY - pcCU->getSlice()->getSPS()->getPCMBitDepthLuma();
1456  }
1457  else
1458  {
1459    uiPicStride = pcCU->getPic()->getPicYuvRec()->getCStride();
1460
1461    if( ttText == TEXT_CHROMA_U )
1462    {
1463      piPicReco = pcCU->getPic()->getPicYuvRec()->getCbAddr(pcCU->getAddr(), pcCU->getZorderIdxInCU()+uiPartIdx);
1464    }
1465    else
1466    {
1467      piPicReco = pcCU->getPic()->getPicYuvRec()->getCrAddr(pcCU->getAddr(), pcCU->getZorderIdxInCU()+uiPartIdx);
1468    }
1469    uiPcmLeftShiftBit = g_bitDepthC - pcCU->getSlice()->getSPS()->getPCMBitDepthChroma();
1470  }
1471
1472  for( uiY = 0; uiY < uiHeight; uiY++ )
1473  {
1474    for( uiX = 0; uiX < uiWidth; uiX++ )
1475    {
1476      piReco[uiX] = (piPCM[uiX] << uiPcmLeftShiftBit);
1477      piPicReco[uiX] = piReco[uiX];
1478    }
1479    piPCM += uiWidth;
1480    piReco += uiStride;
1481    piPicReco += uiPicStride;
1482  }
1483}
1484
1485/** Function for reconstructing a PCM mode CU.
1486 * \param pcCU pointer to current CU
1487 * \param uiDepth CU Depth
1488 * \returns Void
1489 */
1490Void TDecCu::xReconPCM( TComDataCU* pcCU, UInt uiDepth )
1491{
1492  // Luma
1493  UInt uiWidth  = (g_uiMaxCUWidth >> uiDepth);
1494  UInt uiHeight = (g_uiMaxCUHeight >> uiDepth);
1495
1496  Pel* piPcmY = pcCU->getPCMSampleY();
1497  Pel* piRecoY = m_ppcYuvReco[uiDepth]->getLumaAddr(0, uiWidth);
1498
1499  UInt uiStride = m_ppcYuvResi[uiDepth]->getStride();
1500
1501  xDecodePCMTexture( pcCU, 0, piPcmY, piRecoY, uiStride, uiWidth, uiHeight, TEXT_LUMA);
1502
1503  // Cb and Cr
1504  UInt uiCWidth  = (uiWidth>>1);
1505  UInt uiCHeight = (uiHeight>>1);
1506
1507  Pel* piPcmCb = pcCU->getPCMSampleCb();
1508  Pel* piPcmCr = pcCU->getPCMSampleCr();
1509  Pel* pRecoCb = m_ppcYuvReco[uiDepth]->getCbAddr();
1510  Pel* pRecoCr = m_ppcYuvReco[uiDepth]->getCrAddr();
1511
1512  UInt uiCStride = m_ppcYuvReco[uiDepth]->getCStride();
1513
1514  xDecodePCMTexture( pcCU, 0, piPcmCb, pRecoCb, uiCStride, uiCWidth, uiCHeight, TEXT_CHROMA_U);
1515  xDecodePCMTexture( pcCU, 0, piPcmCr, pRecoCr, uiCStride, uiCWidth, uiCHeight, TEXT_CHROMA_V);
1516}
1517
1518/** Function for filling the PCM buffer of a CU using its reconstructed sample array
1519 * \param pcCU pointer to current CU
1520 * \param uiDepth CU Depth
1521 * \returns Void
1522 */
1523Void TDecCu::xFillPCMBuffer(TComDataCU* pCU, UInt depth)
1524{
1525  // Luma
1526  UInt width  = (g_uiMaxCUWidth >> depth);
1527  UInt height = (g_uiMaxCUHeight >> depth);
1528
1529  Pel* pPcmY = pCU->getPCMSampleY();
1530  Pel* pRecoY = m_ppcYuvReco[depth]->getLumaAddr(0, width);
1531
1532  UInt stride = m_ppcYuvReco[depth]->getStride();
1533
1534  for(Int y = 0; y < height; y++ )
1535  {
1536    for(Int x = 0; x < width; x++ )
1537    {
1538      pPcmY[x] = pRecoY[x];
1539    }
1540    pPcmY += width;
1541    pRecoY += stride;
1542  }
1543
1544  // Cb and Cr
1545  UInt widthC  = (width>>1);
1546  UInt heightC = (height>>1);
1547
1548  Pel* pPcmCb = pCU->getPCMSampleCb();
1549  Pel* pPcmCr = pCU->getPCMSampleCr();
1550  Pel* pRecoCb = m_ppcYuvReco[depth]->getCbAddr();
1551  Pel* pRecoCr = m_ppcYuvReco[depth]->getCrAddr();
1552
1553  UInt strideC = m_ppcYuvReco[depth]->getCStride();
1554
1555  for(Int y = 0; y < heightC; y++ )
1556  {
1557    for(Int x = 0; x < widthC; x++ )
1558    {
1559      pPcmCb[x] = pRecoCb[x];
1560      pPcmCr[x] = pRecoCr[x];
1561    }
1562    pPcmCr += widthC;
1563    pPcmCb += widthC;
1564    pRecoCb += strideC;
1565    pRecoCr += strideC;
1566  }
1567
1568}
1569
1570//! \}
Note: See TracBrowser for help on using the repository browser.