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

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

Integration of JCT3V-G0101: InterSDC with multiple DC candidates

  • Property svn:eol-style set to native
File size: 47.5 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#if QC_SDC_UNIFY_G0130
498  m_pcEntropyDecoder->decodeSDCFlag( pcCU, uiAbsPartIdx, uiDepth );
499#endif
500  if (pcCU->isIntra( uiAbsPartIdx ) && pcCU->getPartitionSize( uiAbsPartIdx ) == SIZE_2Nx2N )
501  {
502    m_pcEntropyDecoder->decodeIPCMInfo( pcCU, uiAbsPartIdx, uiDepth );
503
504    if(pcCU->getIPCMFlag(uiAbsPartIdx))
505    {
506      xFinishDecodeCU( pcCU, uiAbsPartIdx, uiDepth, ruiIsLast );
507#if H_3D_IV_MERGE
508      xDecompressCU(pcCU, uiAbsPartIdx, uiDepth );
509#endif
510      return;
511    }
512  }
513
514  UInt uiCurrWidth      = pcCU->getWidth ( uiAbsPartIdx );
515  UInt uiCurrHeight     = pcCU->getHeight( uiAbsPartIdx );
516 
517  // prediction mode ( Intra : direction mode, Inter : Mv, reference idx )
518  m_pcEntropyDecoder->decodePredInfo( pcCU, uiAbsPartIdx, uiDepth, m_ppcCU[uiDepth]);
519#if H_3D_INTER_SDC && !QC_SDC_UNIFY_G0130
520  m_pcEntropyDecoder->decodeInterSDCFlag( pcCU, uiAbsPartIdx, uiDepth );
521#endif
522  // Coefficient decoding
523  Bool bCodeDQP = getdQPFlag();
524  m_pcEntropyDecoder->decodeCoeff( pcCU, uiAbsPartIdx, uiDepth, uiCurrWidth, uiCurrHeight, bCodeDQP );
525  setdQPFlag( bCodeDQP );
526  xFinishDecodeCU( pcCU, uiAbsPartIdx, uiDepth, ruiIsLast );
527#if H_3D_IV_MERGE
528  xDecompressCU(pcCU, uiAbsPartIdx, uiDepth );
529#endif
530}
531
532Void TDecCu::xFinishDecodeCU( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, UInt& ruiIsLast)
533{
534  if(  pcCU->getSlice()->getPPS()->getUseDQP())
535  {
536    pcCU->setQPSubParts( getdQPFlag()?pcCU->getRefQP(uiAbsPartIdx):pcCU->getCodedQP(), uiAbsPartIdx, uiDepth ); // set QP
537  }
538
539  ruiIsLast = xDecodeSliceEnd( pcCU, uiAbsPartIdx, uiDepth);
540}
541
542Void TDecCu::xDecompressCU( TComDataCU* pcCU, UInt uiAbsPartIdx,  UInt uiDepth )
543{
544  TComPic* pcPic = pcCU->getPic();
545#if !H_3D_IV_MERGE
546  Bool bBoundary = false;
547  UInt uiLPelX   = pcCU->getCUPelX() + g_auiRasterToPelX[ g_auiZscanToRaster[uiAbsPartIdx] ];
548  UInt uiRPelX   = uiLPelX + (g_uiMaxCUWidth>>uiDepth)  - 1;
549  UInt uiTPelY   = pcCU->getCUPelY() + g_auiRasterToPelY[ g_auiZscanToRaster[uiAbsPartIdx] ];
550  UInt uiBPelY   = uiTPelY + (g_uiMaxCUHeight>>uiDepth) - 1;
551 
552  UInt uiCurNumParts    = pcPic->getNumPartInCU() >> (uiDepth<<1);
553  TComSlice * pcSlice = pcCU->getPic()->getSlice(pcCU->getPic()->getCurrSliceIdx());
554  Bool bStartInCU = pcCU->getSCUAddr()+uiAbsPartIdx+uiCurNumParts>pcSlice->getSliceSegmentCurStartCUAddr()&&pcCU->getSCUAddr()+uiAbsPartIdx<pcSlice->getSliceSegmentCurStartCUAddr();
555  if(bStartInCU||( uiRPelX >= pcSlice->getSPS()->getPicWidthInLumaSamples() ) || ( uiBPelY >= pcSlice->getSPS()->getPicHeightInLumaSamples() ) )
556  {
557    bBoundary = true;
558  }
559 
560  if( ( ( uiDepth < pcCU->getDepth( uiAbsPartIdx ) ) && ( uiDepth < g_uiMaxCUDepth - g_uiAddCUDepth ) ) || bBoundary )
561  {
562    UInt uiNextDepth = uiDepth + 1;
563    UInt uiQNumParts = pcCU->getTotalNumPart() >> (uiNextDepth<<1);
564    UInt uiIdx = uiAbsPartIdx;
565    for ( UInt uiPartIdx = 0; uiPartIdx < 4; uiPartIdx++ )
566    {
567      uiLPelX = pcCU->getCUPelX() + g_auiRasterToPelX[ g_auiZscanToRaster[uiIdx] ];
568      uiTPelY = pcCU->getCUPelY() + g_auiRasterToPelY[ g_auiZscanToRaster[uiIdx] ];
569     
570      Bool binSlice = (pcCU->getSCUAddr()+uiIdx+uiQNumParts>pcSlice->getSliceSegmentCurStartCUAddr())&&(pcCU->getSCUAddr()+uiIdx<pcSlice->getSliceSegmentCurEndCUAddr());
571      if(binSlice&&( uiLPelX < pcSlice->getSPS()->getPicWidthInLumaSamples() ) && ( uiTPelY < pcSlice->getSPS()->getPicHeightInLumaSamples() ) )
572      {
573        xDecompressCU(pcCU, uiIdx, uiNextDepth );
574      }
575     
576      uiIdx += uiQNumParts;
577    }
578    return;
579  }
580#endif 
581  // Residual reconstruction
582  m_ppcYuvResi[uiDepth]->clear();
583 
584  m_ppcCU[uiDepth]->copySubCU( pcCU, uiAbsPartIdx, uiDepth );
585 
586  switch( m_ppcCU[uiDepth]->getPredictionMode(0) )
587  {
588    case MODE_INTER:
589#if H_3D_INTER_SDC
590#if QC_SDC_UNIFY_G0130
591      if( m_ppcCU[uiDepth]->getSDCFlag( 0 ) )
592#else
593      if( m_ppcCU[uiDepth]->getInterSDCFlag( 0 ) )
594#endif
595      {
596        xReconInterSDC( m_ppcCU[uiDepth], uiAbsPartIdx, uiDepth );
597      }
598      else
599      {
600#endif
601      xReconInter( m_ppcCU[uiDepth], uiDepth );
602#if H_3D_INTER_SDC
603      }
604#endif
605      break;
606    case MODE_INTRA:
607#if H_3D_DIM_SDC
608      if( m_ppcCU[uiDepth]->getSDCFlag(0) )
609        xReconIntraSDC( m_ppcCU[uiDepth], 0, uiDepth );
610      else
611#endif
612      xReconIntraQT( m_ppcCU[uiDepth], uiDepth );
613      break;
614    default:
615      assert(0);
616      break;
617  }
618  if ( m_ppcCU[uiDepth]->isLosslessCoded(0) && (m_ppcCU[uiDepth]->getIPCMFlag(0) == false))
619  {
620    xFillPCMBuffer(m_ppcCU[uiDepth], uiDepth);
621  }
622 
623  xCopyToPic( m_ppcCU[uiDepth], pcPic, uiAbsPartIdx, uiDepth );
624}
625
626Void TDecCu::xReconInter( TComDataCU* pcCU, UInt uiDepth )
627{
628 
629  // inter prediction
630  m_pcPrediction->motionCompensation( pcCU, m_ppcYuvReco[uiDepth] );
631 
632  // inter recon
633  xDecodeInterTexture( pcCU, 0, uiDepth );
634 
635  // clip for only non-zero cbp case
636  if  ( ( pcCU->getCbf( 0, TEXT_LUMA ) ) || ( pcCU->getCbf( 0, TEXT_CHROMA_U ) ) || ( pcCU->getCbf(0, TEXT_CHROMA_V ) ) )
637  {
638    m_ppcYuvReco[uiDepth]->addClip( m_ppcYuvReco[uiDepth], m_ppcYuvResi[uiDepth], 0, pcCU->getWidth( 0 ) );
639  }
640  else
641  {
642    m_ppcYuvReco[uiDepth]->copyPartToPartYuv( m_ppcYuvReco[uiDepth],0, pcCU->getWidth( 0 ),pcCU->getHeight( 0 ));
643  }
644}
645
646#if H_3D_INTER_SDC
647Void TDecCu::xReconInterSDC( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
648{
649  // inter prediction
650  m_pcPrediction->motionCompensation( pcCU, m_ppcYuvReco[uiDepth] );
651
652  UInt  uiWidth      = pcCU->getWidth ( 0 );
653  UInt  uiHeight     = pcCU->getHeight( 0 );
654#if !SEC_INTER_SDC_G0101
655  UChar* pMask       = pcCU->getInterSDCMask();
656
657  memset( pMask, 0, uiWidth*uiHeight );
658  pcCU->xSetInterSDCCUMask( pcCU, pMask );
659#endif
660
661  Pel  *pResi;
662  UInt uiPelX, uiPelY;
663  UInt uiResiStride = m_ppcYuvResi[uiDepth]->getStride();
664
665  pResi = m_ppcYuvResi[uiDepth]->getLumaAddr( 0 );
666  for( uiPelY = 0; uiPelY < uiHeight; uiPelY++ )
667  {
668    for( uiPelX = 0; uiPelX < uiWidth; uiPelX++ )
669    {
670#if SEC_INTER_SDC_G0101
671      pResi[ uiPelX ] = pcCU->getSDCSegmentDCOffset( 0, 0 );
672#else
673      UChar uiSeg = pMask[ uiPelX + uiPelY*uiWidth ];
674#if QC_SDC_UNIFY_G0130
675      pResi[ uiPelX ] = pcCU->getSDCSegmentDCOffset( uiSeg, 0 );
676#else
677      pResi[ uiPelX ] = pcCU->getInterSDCSegmentDCOffset( uiSeg, 0 );
678#endif
679#endif
680    }
681    pResi += uiResiStride;
682  }
683
684  m_ppcYuvReco[uiDepth]->addClip( m_ppcYuvReco[uiDepth], m_ppcYuvResi[uiDepth], 0, pcCU->getWidth( 0 ) );
685
686  // clear UV
687  UInt  uiStrideC     = m_ppcYuvReco[uiDepth]->getCStride();
688  Pel   *pRecCb       = m_ppcYuvReco[uiDepth]->getCbAddr();
689  Pel   *pRecCr       = m_ppcYuvReco[uiDepth]->getCrAddr();
690
691  for (Int y = 0; y < uiHeight/2; y++)
692  {
693    for (Int x = 0; x < uiWidth/2; x++)
694    {
695      pRecCb[x] = (Pel)( 1 << ( g_bitDepthC - 1 ) );
696      pRecCr[x] = (Pel)( 1 << ( g_bitDepthC - 1 ) );
697    }
698
699    pRecCb += uiStrideC;
700    pRecCr += uiStrideC;
701  }
702}
703#endif
704
705Void
706TDecCu::xIntraRecLumaBlk( TComDataCU* pcCU,
707                         UInt        uiTrDepth,
708                         UInt        uiAbsPartIdx,
709                         TComYuv*    pcRecoYuv,
710                         TComYuv*    pcPredYuv, 
711                         TComYuv*    pcResiYuv )
712{
713  UInt    uiWidth           = pcCU     ->getWidth   ( 0 ) >> uiTrDepth;
714  UInt    uiHeight          = pcCU     ->getHeight  ( 0 ) >> uiTrDepth;
715  UInt    uiStride          = pcRecoYuv->getStride  ();
716  Pel*    piReco            = pcRecoYuv->getLumaAddr( uiAbsPartIdx );
717  Pel*    piPred            = pcPredYuv->getLumaAddr( uiAbsPartIdx );
718  Pel*    piResi            = pcResiYuv->getLumaAddr( uiAbsPartIdx );
719 
720  UInt    uiNumCoeffInc     = ( pcCU->getSlice()->getSPS()->getMaxCUWidth() * pcCU->getSlice()->getSPS()->getMaxCUHeight() ) >> ( pcCU->getSlice()->getSPS()->getMaxCUDepth() << 1 );
721  TCoeff* pcCoeff           = pcCU->getCoeffY() + ( uiNumCoeffInc * uiAbsPartIdx );
722 
723  UInt    uiLumaPredMode    = pcCU->getLumaIntraDir     ( uiAbsPartIdx );
724 
725  UInt    uiZOrder          = pcCU->getZorderIdxInCU() + uiAbsPartIdx;
726  Pel*    piRecIPred        = pcCU->getPic()->getPicYuvRec()->getLumaAddr( pcCU->getAddr(), uiZOrder );
727  UInt    uiRecIPredStride  = pcCU->getPic()->getPicYuvRec()->getStride  ();
728  Bool    useTransformSkip  = pcCU->getTransformSkip(uiAbsPartIdx, TEXT_LUMA);
729  //===== init availability pattern =====
730  Bool  bAboveAvail = false;
731  Bool  bLeftAvail  = false;
732  pcCU->getPattern()->initPattern   ( pcCU, uiTrDepth, uiAbsPartIdx );
733  pcCU->getPattern()->initAdiPattern( pcCU, uiAbsPartIdx, uiTrDepth, 
734                                     m_pcPrediction->getPredicBuf       (),
735                                     m_pcPrediction->getPredicBufWidth  (),
736                                     m_pcPrediction->getPredicBufHeight (),
737                                     bAboveAvail, bLeftAvail );
738 
739  //===== get prediction signal =====
740#if H_3D_DIM
741  if( isDimMode( uiLumaPredMode ) )
742  {
743    m_pcPrediction->predIntraLumaDepth( pcCU, uiAbsPartIdx, uiLumaPredMode, piPred, uiStride, uiWidth, uiHeight );
744  }
745  else
746  {
747#endif
748  m_pcPrediction->predIntraLumaAng( pcCU->getPattern(), uiLumaPredMode, piPred, uiStride, uiWidth, uiHeight, bAboveAvail, bLeftAvail );
749#if H_3D_DIM
750  }
751#endif
752 
753  //===== inverse transform =====
754  m_pcTrQuant->setQPforQuant  ( pcCU->getQP(0), TEXT_LUMA, pcCU->getSlice()->getSPS()->getQpBDOffsetY(), 0 );
755
756  Int scalingListType = (pcCU->isIntra(uiAbsPartIdx) ? 0 : 3) + g_eTTable[(Int)TEXT_LUMA];
757  assert(scalingListType < 6);
758  m_pcTrQuant->invtransformNxN( pcCU->getCUTransquantBypass(uiAbsPartIdx), TEXT_LUMA, pcCU->getLumaIntraDir( uiAbsPartIdx ), piResi, uiStride, pcCoeff, uiWidth, uiHeight, scalingListType, useTransformSkip );
759
760 
761  //===== reconstruction =====
762  Pel* pPred      = piPred;
763  Pel* pResi      = piResi;
764  Pel* pReco      = piReco;
765  Pel* pRecIPred  = piRecIPred;
766  for( UInt uiY = 0; uiY < uiHeight; uiY++ )
767  {
768    for( UInt uiX = 0; uiX < uiWidth; uiX++ )
769    {
770#if H_3D
771      if( (isDimMode( uiLumaPredMode ) || uiLumaPredMode == HOR_IDX || uiLumaPredMode == VER_IDX || uiLumaPredMode == DC_IDX) && pcCU->getSlice()->getIsDepth() && pcCU->getSlice()->getPPS()->getDLT()->getUseDLTFlag(pcCU->getSlice()->getLayerIdInVps()) )
772      {
773        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 ] ) );
774      }
775      else
776      {
777        pReco    [ uiX ] = ClipY( pPred[ uiX ] + pResi[ uiX ] );
778      }
779#else
780      pReco    [ uiX ] = ClipY( pPred[ uiX ] + pResi[ uiX ] );
781#endif
782      pRecIPred[ uiX ] = pReco[ uiX ];
783    }
784    pPred     += uiStride;
785    pResi     += uiStride;
786    pReco     += uiStride;
787    pRecIPred += uiRecIPredStride;
788  }
789}
790
791
792Void
793TDecCu::xIntraRecChromaBlk( TComDataCU* pcCU,
794                           UInt        uiTrDepth,
795                           UInt        uiAbsPartIdx,
796                           TComYuv*    pcRecoYuv,
797                           TComYuv*    pcPredYuv, 
798                           TComYuv*    pcResiYuv,
799                           UInt        uiChromaId )
800{
801  UInt uiFullDepth  = pcCU->getDepth( 0 ) + uiTrDepth;
802  UInt uiLog2TrSize = g_aucConvertToBit[ pcCU->getSlice()->getSPS()->getMaxCUWidth() >> uiFullDepth ] + 2;
803
804  if( uiLog2TrSize == 2 )
805  {
806    assert( uiTrDepth > 0 );
807    uiTrDepth--;
808    UInt uiQPDiv = pcCU->getPic()->getNumPartInCU() >> ( ( pcCU->getDepth( 0 ) + uiTrDepth ) << 1 );
809    Bool bFirstQ = ( ( uiAbsPartIdx % uiQPDiv ) == 0 );
810    if( !bFirstQ )
811    {
812      return;
813    }
814  }
815 
816  TextType  eText             = ( uiChromaId > 0 ? TEXT_CHROMA_V : TEXT_CHROMA_U );
817  UInt      uiWidth           = pcCU     ->getWidth   ( 0 ) >> ( uiTrDepth + 1 );
818  UInt      uiHeight          = pcCU     ->getHeight  ( 0 ) >> ( uiTrDepth + 1 );
819  UInt      uiStride          = pcRecoYuv->getCStride ();
820  Pel*      piReco            = ( uiChromaId > 0 ? pcRecoYuv->getCrAddr( uiAbsPartIdx ) : pcRecoYuv->getCbAddr( uiAbsPartIdx ) );
821  Pel*      piPred            = ( uiChromaId > 0 ? pcPredYuv->getCrAddr( uiAbsPartIdx ) : pcPredYuv->getCbAddr( uiAbsPartIdx ) );
822  Pel*      piResi            = ( uiChromaId > 0 ? pcResiYuv->getCrAddr( uiAbsPartIdx ) : pcResiYuv->getCbAddr( uiAbsPartIdx ) );
823 
824  UInt      uiNumCoeffInc     = ( ( pcCU->getSlice()->getSPS()->getMaxCUWidth() * pcCU->getSlice()->getSPS()->getMaxCUHeight() ) >> ( pcCU->getSlice()->getSPS()->getMaxCUDepth() << 1 ) ) >> 2;
825  TCoeff*   pcCoeff           = ( uiChromaId > 0 ? pcCU->getCoeffCr() : pcCU->getCoeffCb() ) + ( uiNumCoeffInc * uiAbsPartIdx );
826 
827  UInt      uiChromaPredMode  = pcCU->getChromaIntraDir( 0 );
828 
829  UInt      uiZOrder          = pcCU->getZorderIdxInCU() + uiAbsPartIdx;
830  Pel*      piRecIPred        = ( uiChromaId > 0 ? pcCU->getPic()->getPicYuvRec()->getCrAddr( pcCU->getAddr(), uiZOrder ) : pcCU->getPic()->getPicYuvRec()->getCbAddr( pcCU->getAddr(), uiZOrder ) );
831  UInt      uiRecIPredStride  = pcCU->getPic()->getPicYuvRec()->getCStride();
832  Bool      useTransformSkipChroma = pcCU->getTransformSkip(uiAbsPartIdx,eText);
833  //===== init availability pattern =====
834  Bool  bAboveAvail = false;
835  Bool  bLeftAvail  = false;
836  pcCU->getPattern()->initPattern         ( pcCU, uiTrDepth, uiAbsPartIdx );
837
838  pcCU->getPattern()->initAdiPatternChroma( pcCU, uiAbsPartIdx, uiTrDepth,
839                                           m_pcPrediction->getPredicBuf       (),
840                                           m_pcPrediction->getPredicBufWidth  (),
841                                           m_pcPrediction->getPredicBufHeight (),
842                                           bAboveAvail, bLeftAvail );
843  Int* pPatChroma   = ( uiChromaId > 0 ? pcCU->getPattern()->getAdiCrBuf( uiWidth, uiHeight, m_pcPrediction->getPredicBuf() ) : pcCU->getPattern()->getAdiCbBuf( uiWidth, uiHeight, m_pcPrediction->getPredicBuf() ) );
844 
845  //===== get prediction signal =====
846  {
847    if( uiChromaPredMode == DM_CHROMA_IDX )
848    {
849      uiChromaPredMode = pcCU->getLumaIntraDir( 0 );
850#if H_3D_DIM
851      mapDepthModeToIntraDir( uiChromaPredMode );
852#endif
853    }
854    m_pcPrediction->predIntraChromaAng( pPatChroma, uiChromaPredMode, piPred, uiStride, uiWidth, uiHeight, bAboveAvail, bLeftAvail ); 
855  }
856
857  //===== inverse transform =====
858  Int curChromaQpOffset;
859  if(eText == TEXT_CHROMA_U)
860  {
861    curChromaQpOffset = pcCU->getSlice()->getPPS()->getChromaCbQpOffset() + pcCU->getSlice()->getSliceQpDeltaCb();
862  }
863  else
864  {
865    curChromaQpOffset = pcCU->getSlice()->getPPS()->getChromaCrQpOffset() + pcCU->getSlice()->getSliceQpDeltaCr();
866  }
867  m_pcTrQuant->setQPforQuant  ( pcCU->getQP(0), eText, pcCU->getSlice()->getSPS()->getQpBDOffsetC(), curChromaQpOffset );
868
869  Int scalingListType = (pcCU->isIntra(uiAbsPartIdx) ? 0 : 3) + g_eTTable[(Int)eText];
870  assert(scalingListType < 6);
871  m_pcTrQuant->invtransformNxN( pcCU->getCUTransquantBypass(uiAbsPartIdx), eText, REG_DCT, piResi, uiStride, pcCoeff, uiWidth, uiHeight, scalingListType, useTransformSkipChroma );
872
873  //===== reconstruction =====
874  Pel* pPred      = piPred;
875  Pel* pResi      = piResi;
876  Pel* pReco      = piReco;
877  Pel* pRecIPred  = piRecIPred;
878  for( UInt uiY = 0; uiY < uiHeight; uiY++ )
879  {
880    for( UInt uiX = 0; uiX < uiWidth; uiX++ )
881    {
882      pReco    [ uiX ] = ClipC( pPred[ uiX ] + pResi[ uiX ] );
883      pRecIPred[ uiX ] = pReco[ uiX ];
884    }
885    pPred     += uiStride;
886    pResi     += uiStride;
887    pReco     += uiStride;
888    pRecIPred += uiRecIPredStride;
889  }
890}
891
892
893Void
894TDecCu::xReconIntraQT( TComDataCU* pcCU, UInt uiDepth )
895{
896  UInt  uiInitTrDepth = ( pcCU->getPartitionSize(0) == SIZE_2Nx2N ? 0 : 1 );
897  UInt  uiNumPart     = pcCU->getNumPartInter();
898  UInt  uiNumQParts   = pcCU->getTotalNumPart() >> 2;
899 
900  if (pcCU->getIPCMFlag(0))
901  {
902    xReconPCM( pcCU, uiDepth );
903    return;
904  }
905
906  for( UInt uiPU = 0; uiPU < uiNumPart; uiPU++ )
907  {
908    xIntraLumaRecQT( pcCU, uiInitTrDepth, uiPU * uiNumQParts, m_ppcYuvReco[uiDepth], m_ppcYuvReco[uiDepth], m_ppcYuvResi[uiDepth] );
909  } 
910
911  for( UInt uiPU = 0; uiPU < uiNumPart; uiPU++ )
912  {
913    xIntraChromaRecQT( pcCU, uiInitTrDepth, uiPU * uiNumQParts, m_ppcYuvReco[uiDepth], m_ppcYuvReco[uiDepth], m_ppcYuvResi[uiDepth] );
914  }
915
916}
917
918#if H_3D_DIM_SDC
919Void TDecCu::xReconIntraSDC( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
920{
921  UInt uiWidth        = pcCU->getWidth  ( 0 );
922  UInt uiHeight       = pcCU->getHeight ( 0 );
923 
924  TComYuv* pcRecoYuv  = m_ppcYuvReco[uiDepth];
925  TComYuv* pcPredYuv  = m_ppcYuvReco[uiDepth];
926  TComYuv* pcResiYuv  = m_ppcYuvResi[uiDepth];
927 
928  UInt    uiStride    = pcRecoYuv->getStride  ();
929  Pel*    piReco      = pcRecoYuv->getLumaAddr( uiAbsPartIdx );
930  Pel*    piPred      = pcPredYuv->getLumaAddr( uiAbsPartIdx );
931  Pel*    piResi      = pcResiYuv->getLumaAddr( uiAbsPartIdx );
932 
933  UInt    uiZOrder          = pcCU->getZorderIdxInCU() + uiAbsPartIdx;
934  Pel*    piRecIPred        = pcCU->getPic()->getPicYuvRec()->getLumaAddr( pcCU->getAddr(), uiZOrder );
935  UInt    uiRecIPredStride  = pcCU->getPic()->getPicYuvRec()->getStride  ();
936 
937  UInt    uiLumaPredMode    = pcCU->getLumaIntraDir     ( uiAbsPartIdx );
938 
939  AOF( uiWidth == uiHeight );
940  AOF( uiAbsPartIdx == 0 );
941  AOF( pcCU->getSDCAvailable(uiAbsPartIdx) );
942  AOF( pcCU->getSDCFlag(uiAbsPartIdx) );
943 
944  //===== init availability pattern =====
945  Bool  bAboveAvail = false;
946  Bool  bLeftAvail  = false;
947  pcCU->getPattern()->initPattern   ( pcCU, 0, uiAbsPartIdx );
948  pcCU->getPattern()->initAdiPattern( pcCU, uiAbsPartIdx, 0, m_pcPrediction->getPredicBuf(), m_pcPrediction->getPredicBufWidth(), m_pcPrediction->getPredicBufHeight(), bAboveAvail, bLeftAvail );
949#if QC_GENERIC_SDC_G0122
950  TComWedgelet* dmm4Segmentation = new TComWedgelet( uiWidth, uiHeight );
951#endif
952  //===== get prediction signal =====
953#if H_3D_DIM
954  if( isDimMode( uiLumaPredMode ) )
955  {
956    m_pcPrediction->predIntraLumaDepth( pcCU, uiAbsPartIdx, uiLumaPredMode, piPred, uiStride, uiWidth, uiHeight
957#if QC_GENERIC_SDC_G0122
958      , false, dmm4Segmentation
959#endif
960      );
961  }
962  else
963  {
964#endif
965    m_pcPrediction->predIntraLumaAng( pcCU->getPattern(), uiLumaPredMode, piPred, uiStride, uiWidth, uiHeight, bAboveAvail, bLeftAvail );
966#if H_3D_DIM
967  }
968#endif
969 
970  // number of segments depends on prediction mode
971  UInt uiNumSegments = 1;
972  Bool* pbMask = NULL;
973  UInt uiMaskStride = 0;
974 
975  if( getDimType( uiLumaPredMode ) == DMM1_IDX )
976  {
977    Int uiTabIdx = pcCU->getDmmWedgeTabIdx(DMM1_IDX, uiAbsPartIdx);
978   
979    WedgeList* pacWedgeList = &g_dmmWedgeLists[(g_aucConvertToBit[uiWidth])];
980    TComWedgelet* pcWedgelet = &(pacWedgeList->at( uiTabIdx ));
981   
982    uiNumSegments = 2;
983    pbMask = pcWedgelet->getPattern();
984    uiMaskStride = pcWedgelet->getStride();
985  }
986#if QC_GENERIC_SDC_G0122
987  if( getDimType( uiLumaPredMode ) == DMM4_IDX )
988  {
989    uiNumSegments = 2;
990    pbMask  = dmm4Segmentation->getPattern();
991    uiMaskStride = dmm4Segmentation->getStride();
992  }
993#endif
994  // get DC prediction for each segment
995  Pel apDCPredValues[2];
996  m_pcPrediction->analyzeSegmentsSDC(piPred, uiStride, uiWidth, apDCPredValues, uiNumSegments, pbMask, uiMaskStride, uiLumaPredMode);
997 
998  // reconstruct residual based on mask + DC residuals
999  Pel apDCResiValues[2];
1000  for( UInt uiSegment = 0; uiSegment < uiNumSegments; uiSegment++ )
1001  {
1002#if H_3D_DIM_DLT
1003    Pel   pPredIdx    = pcCU->getSlice()->getPPS()->getDLT()->depthValue2idx( pcCU->getSlice()->getLayerIdInVps(), apDCPredValues[uiSegment] );
1004    Pel   pResiIdx    = pcCU->getSDCSegmentDCOffset(uiSegment, uiAbsPartIdx);
1005    Pel   pRecoValue  = pcCU->getSlice()->getPPS()->getDLT()->idx2DepthValue( pcCU->getSlice()->getLayerIdInVps(), pPredIdx + pResiIdx );
1006
1007    apDCResiValues[uiSegment]  = pRecoValue - apDCPredValues[uiSegment];
1008#else
1009    apDCResiValues[uiSegment]  = pcCU->getSDCSegmentDCOffset(uiSegment, uiAbsPartIdx);
1010#endif
1011  }
1012 
1013  //===== reconstruction =====
1014  Bool*pMask      = pbMask;
1015  Pel* pPred      = piPred;
1016  Pel* pResi      = piResi;
1017  Pel* pReco      = piReco;
1018  Pel* pRecIPred  = piRecIPred;
1019 
1020  for( UInt uiY = 0; uiY < uiHeight; uiY++ )
1021  {
1022    for( UInt uiX = 0; uiX < uiWidth; uiX++ )
1023    {
1024      UChar ucSegment = pMask?(UChar)pMask[uiX]:0;
1025      assert( ucSegment < uiNumSegments );
1026     
1027      Pel pResiDC = apDCResiValues[ucSegment];
1028     
1029      pReco    [ uiX ] = ClipY( pPred[ uiX ] + pResiDC );
1030      pRecIPred[ uiX ] = pReco[ uiX ];
1031    }
1032    pPred     += uiStride;
1033    pResi     += uiStride;
1034    pReco     += uiStride;
1035    pRecIPred += uiRecIPredStride;
1036    pMask     += uiMaskStride;
1037  }
1038 
1039  // clear UV
1040  UInt  uiStrideC     = pcPredYuv->getCStride();
1041  Pel   *pRecCb       = pcPredYuv->getCbAddr();
1042  Pel   *pRecCr       = pcPredYuv->getCrAddr();
1043 
1044  for (Int y=0; y<uiHeight/2; y++)
1045  {
1046    for (Int x=0; x<uiWidth/2; x++)
1047    {
1048      pRecCb[x] = 128;
1049      pRecCr[x] = 128;
1050    }
1051   
1052    pRecCb += uiStrideC;
1053    pRecCr += uiStrideC;
1054  }
1055#if QC_GENERIC_SDC_G0122
1056  dmm4Segmentation->destroy(); delete dmm4Segmentation;
1057#endif
1058}
1059#endif
1060
1061/** Function for deriving recontructed PU/CU Luma sample with QTree structure
1062 * \param pcCU pointer of current CU
1063 * \param uiTrDepth current tranform split depth
1064 * \param uiAbsPartIdx  part index
1065 * \param pcRecoYuv pointer to reconstructed sample arrays
1066 * \param pcPredYuv pointer to prediction sample arrays
1067 * \param pcResiYuv pointer to residue sample arrays
1068 *
1069 \ This function dervies recontructed PU/CU Luma sample with recursive QTree structure
1070 */
1071Void
1072TDecCu::xIntraLumaRecQT( TComDataCU* pcCU,
1073                     UInt        uiTrDepth,
1074                     UInt        uiAbsPartIdx,
1075                     TComYuv*    pcRecoYuv,
1076                     TComYuv*    pcPredYuv, 
1077                     TComYuv*    pcResiYuv )
1078{
1079  UInt uiFullDepth  = pcCU->getDepth(0) + uiTrDepth;
1080  UInt uiTrMode     = pcCU->getTransformIdx( uiAbsPartIdx );
1081  if( uiTrMode == uiTrDepth )
1082  {
1083    xIntraRecLumaBlk  ( pcCU, uiTrDepth, uiAbsPartIdx, pcRecoYuv, pcPredYuv, pcResiYuv );
1084  }
1085  else
1086  {
1087    UInt uiNumQPart  = pcCU->getPic()->getNumPartInCU() >> ( ( uiFullDepth + 1 ) << 1 );
1088    for( UInt uiPart = 0; uiPart < 4; uiPart++ )
1089    {
1090      xIntraLumaRecQT( pcCU, uiTrDepth + 1, uiAbsPartIdx + uiPart * uiNumQPart, pcRecoYuv, pcPredYuv, pcResiYuv );
1091    }
1092  }
1093}
1094
1095/** Function for deriving recontructed PU/CU chroma samples with QTree structure
1096 * \param pcCU pointer of current CU
1097 * \param uiTrDepth current tranform split depth
1098 * \param uiAbsPartIdx  part index
1099 * \param pcRecoYuv pointer to reconstructed sample arrays
1100 * \param pcPredYuv pointer to prediction sample arrays
1101 * \param pcResiYuv pointer to residue sample arrays
1102 *
1103 \ This function dervies recontructed PU/CU chroma samples with QTree recursive structure
1104 */
1105Void
1106TDecCu::xIntraChromaRecQT( TComDataCU* pcCU,
1107                     UInt        uiTrDepth,
1108                     UInt        uiAbsPartIdx,
1109                     TComYuv*    pcRecoYuv,
1110                     TComYuv*    pcPredYuv, 
1111                     TComYuv*    pcResiYuv )
1112{
1113  UInt uiFullDepth  = pcCU->getDepth(0) + uiTrDepth;
1114  UInt uiTrMode     = pcCU->getTransformIdx( uiAbsPartIdx );
1115  if( uiTrMode == uiTrDepth )
1116  {
1117    xIntraRecChromaBlk( pcCU, uiTrDepth, uiAbsPartIdx, pcRecoYuv, pcPredYuv, pcResiYuv, 0 );
1118    xIntraRecChromaBlk( pcCU, uiTrDepth, uiAbsPartIdx, pcRecoYuv, pcPredYuv, pcResiYuv, 1 );
1119  }
1120  else
1121  {
1122    UInt uiNumQPart  = pcCU->getPic()->getNumPartInCU() >> ( ( uiFullDepth + 1 ) << 1 );
1123    for( UInt uiPart = 0; uiPart < 4; uiPart++ )
1124    {
1125      xIntraChromaRecQT( pcCU, uiTrDepth + 1, uiAbsPartIdx + uiPart * uiNumQPart, pcRecoYuv, pcPredYuv, pcResiYuv );
1126    }
1127  }
1128}
1129
1130Void TDecCu::xCopyToPic( TComDataCU* pcCU, TComPic* pcPic, UInt uiZorderIdx, UInt uiDepth )
1131{
1132  UInt uiCUAddr = pcCU->getAddr();
1133 
1134  m_ppcYuvReco[uiDepth]->copyToPicYuv  ( pcPic->getPicYuvRec (), uiCUAddr, uiZorderIdx );
1135 
1136  return;
1137}
1138
1139Void TDecCu::xDecodeInterTexture ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
1140{
1141  UInt    uiWidth    = pcCU->getWidth ( uiAbsPartIdx );
1142  UInt    uiHeight   = pcCU->getHeight( uiAbsPartIdx );
1143  TCoeff* piCoeff;
1144 
1145  Pel*    pResi;
1146  UInt    trMode = pcCU->getTransformIdx( uiAbsPartIdx );
1147 
1148  // Y
1149  piCoeff = pcCU->getCoeffY();
1150  pResi = m_ppcYuvResi[uiDepth]->getLumaAddr();
1151
1152  m_pcTrQuant->setQPforQuant( pcCU->getQP( uiAbsPartIdx ), TEXT_LUMA, pcCU->getSlice()->getSPS()->getQpBDOffsetY(), 0 );
1153
1154  m_pcTrQuant->invRecurTransformNxN ( pcCU, 0, TEXT_LUMA, pResi, 0, m_ppcYuvResi[uiDepth]->getStride(), uiWidth, uiHeight, trMode, 0, piCoeff );
1155 
1156  // Cb and Cr
1157  Int curChromaQpOffset = pcCU->getSlice()->getPPS()->getChromaCbQpOffset() + pcCU->getSlice()->getSliceQpDeltaCb();
1158  m_pcTrQuant->setQPforQuant( pcCU->getQP( uiAbsPartIdx ), TEXT_CHROMA, pcCU->getSlice()->getSPS()->getQpBDOffsetC(), curChromaQpOffset );
1159
1160  uiWidth  >>= 1;
1161  uiHeight >>= 1;
1162  piCoeff = pcCU->getCoeffCb(); pResi = m_ppcYuvResi[uiDepth]->getCbAddr();
1163  m_pcTrQuant->invRecurTransformNxN ( pcCU, 0, TEXT_CHROMA_U, pResi, 0, m_ppcYuvResi[uiDepth]->getCStride(), uiWidth, uiHeight, trMode, 0, piCoeff );
1164
1165  curChromaQpOffset = pcCU->getSlice()->getPPS()->getChromaCrQpOffset() + pcCU->getSlice()->getSliceQpDeltaCr();
1166  m_pcTrQuant->setQPforQuant( pcCU->getQP( uiAbsPartIdx ), TEXT_CHROMA, pcCU->getSlice()->getSPS()->getQpBDOffsetC(), curChromaQpOffset );
1167
1168  piCoeff = pcCU->getCoeffCr(); pResi = m_ppcYuvResi[uiDepth]->getCrAddr();
1169  m_pcTrQuant->invRecurTransformNxN ( pcCU, 0, TEXT_CHROMA_V, pResi, 0, m_ppcYuvResi[uiDepth]->getCStride(), uiWidth, uiHeight, trMode, 0, piCoeff );
1170}
1171
1172/** Function for deriving reconstructed luma/chroma samples of a PCM mode CU.
1173 * \param pcCU pointer to current CU
1174 * \param uiPartIdx part index
1175 * \param piPCM pointer to PCM code arrays
1176 * \param piReco pointer to reconstructed sample arrays
1177 * \param uiStride stride of reconstructed sample arrays
1178 * \param uiWidth CU width
1179 * \param uiHeight CU height
1180 * \param ttText texture component type
1181 * \returns Void
1182 */
1183Void TDecCu::xDecodePCMTexture( TComDataCU* pcCU, UInt uiPartIdx, Pel *piPCM, Pel* piReco, UInt uiStride, UInt uiWidth, UInt uiHeight, TextType ttText)
1184{
1185  UInt uiX, uiY;
1186  Pel* piPicReco;
1187  UInt uiPicStride;
1188  UInt uiPcmLeftShiftBit; 
1189
1190  if( ttText == TEXT_LUMA )
1191  {
1192    uiPicStride   = pcCU->getPic()->getPicYuvRec()->getStride();
1193    piPicReco = pcCU->getPic()->getPicYuvRec()->getLumaAddr(pcCU->getAddr(), pcCU->getZorderIdxInCU()+uiPartIdx);
1194    uiPcmLeftShiftBit = g_bitDepthY - pcCU->getSlice()->getSPS()->getPCMBitDepthLuma();
1195  }
1196  else
1197  {
1198    uiPicStride = pcCU->getPic()->getPicYuvRec()->getCStride();
1199
1200    if( ttText == TEXT_CHROMA_U )
1201    {
1202      piPicReco = pcCU->getPic()->getPicYuvRec()->getCbAddr(pcCU->getAddr(), pcCU->getZorderIdxInCU()+uiPartIdx);
1203    }
1204    else
1205    {
1206      piPicReco = pcCU->getPic()->getPicYuvRec()->getCrAddr(pcCU->getAddr(), pcCU->getZorderIdxInCU()+uiPartIdx);
1207    }
1208    uiPcmLeftShiftBit = g_bitDepthC - pcCU->getSlice()->getSPS()->getPCMBitDepthChroma();
1209  }
1210
1211  for( uiY = 0; uiY < uiHeight; uiY++ )
1212  {
1213    for( uiX = 0; uiX < uiWidth; uiX++ )
1214    {
1215      piReco[uiX] = (piPCM[uiX] << uiPcmLeftShiftBit);
1216      piPicReco[uiX] = piReco[uiX];
1217    }
1218    piPCM += uiWidth;
1219    piReco += uiStride;
1220    piPicReco += uiPicStride;
1221  }
1222}
1223
1224/** Function for reconstructing a PCM mode CU.
1225 * \param pcCU pointer to current CU
1226 * \param uiDepth CU Depth
1227 * \returns Void
1228 */
1229Void TDecCu::xReconPCM( TComDataCU* pcCU, UInt uiDepth )
1230{
1231  // Luma
1232  UInt uiWidth  = (g_uiMaxCUWidth >> uiDepth);
1233  UInt uiHeight = (g_uiMaxCUHeight >> uiDepth);
1234
1235  Pel* piPcmY = pcCU->getPCMSampleY();
1236  Pel* piRecoY = m_ppcYuvReco[uiDepth]->getLumaAddr(0, uiWidth);
1237
1238  UInt uiStride = m_ppcYuvResi[uiDepth]->getStride();
1239
1240  xDecodePCMTexture( pcCU, 0, piPcmY, piRecoY, uiStride, uiWidth, uiHeight, TEXT_LUMA);
1241
1242  // Cb and Cr
1243  UInt uiCWidth  = (uiWidth>>1);
1244  UInt uiCHeight = (uiHeight>>1);
1245
1246  Pel* piPcmCb = pcCU->getPCMSampleCb();
1247  Pel* piPcmCr = pcCU->getPCMSampleCr();
1248  Pel* pRecoCb = m_ppcYuvReco[uiDepth]->getCbAddr();
1249  Pel* pRecoCr = m_ppcYuvReco[uiDepth]->getCrAddr();
1250
1251  UInt uiCStride = m_ppcYuvReco[uiDepth]->getCStride();
1252
1253  xDecodePCMTexture( pcCU, 0, piPcmCb, pRecoCb, uiCStride, uiCWidth, uiCHeight, TEXT_CHROMA_U);
1254  xDecodePCMTexture( pcCU, 0, piPcmCr, pRecoCr, uiCStride, uiCWidth, uiCHeight, TEXT_CHROMA_V);
1255}
1256
1257/** Function for filling the PCM buffer of a CU using its reconstructed sample array
1258 * \param pcCU pointer to current CU
1259 * \param uiDepth CU Depth
1260 * \returns Void
1261 */
1262Void TDecCu::xFillPCMBuffer(TComDataCU* pCU, UInt depth)
1263{
1264  // Luma
1265  UInt width  = (g_uiMaxCUWidth >> depth);
1266  UInt height = (g_uiMaxCUHeight >> depth);
1267
1268  Pel* pPcmY = pCU->getPCMSampleY();
1269  Pel* pRecoY = m_ppcYuvReco[depth]->getLumaAddr(0, width);
1270
1271  UInt stride = m_ppcYuvReco[depth]->getStride();
1272
1273  for(Int y = 0; y < height; y++ )
1274  {
1275    for(Int x = 0; x < width; x++ )
1276    {
1277      pPcmY[x] = pRecoY[x];
1278    }
1279    pPcmY += width;
1280    pRecoY += stride;
1281  }
1282
1283  // Cb and Cr
1284  UInt widthC  = (width>>1);
1285  UInt heightC = (height>>1);
1286
1287  Pel* pPcmCb = pCU->getPCMSampleCb();
1288  Pel* pPcmCr = pCU->getPCMSampleCr();
1289  Pel* pRecoCb = m_ppcYuvReco[depth]->getCbAddr();
1290  Pel* pRecoCr = m_ppcYuvReco[depth]->getCrAddr();
1291
1292  UInt strideC = m_ppcYuvReco[depth]->getCStride();
1293
1294  for(Int y = 0; y < heightC; y++ )
1295  {
1296    for(Int x = 0; x < widthC; x++ )
1297    {
1298      pPcmCb[x] = pRecoCb[x];
1299      pPcmCr[x] = pRecoCr[x];
1300    }
1301    pPcmCr += widthC;
1302    pPcmCb += widthC;
1303    pRecoCb += strideC;
1304    pRecoCr += strideC;
1305  }
1306
1307}
1308
1309//! \}
Note: See TracBrowser for help on using the repository browser.