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

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

Merged branch/9.2-dev0@722.

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