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

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

Integration of JCT3V-G0072: IC and ARP Flags Signaling

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