source: 3DVCSoftware/branches/HTM-8.2-dev0/source/Lib/TLibDecoder/TDecCu.cpp @ 1417

Last change on this file since 1417 was 712, checked in by tech, 11 years ago

Merged DEV3 ( branch HTM-8.2-dev3-Samsung@699 )

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