source: 3DVCSoftware/branches/HTM-DEV-2.0-dev1-Mediatek/source/Lib/TLibDecoder/TDecCu.cpp @ 566

Last change on this file since 566 was 566, checked in by mediatek-htm, 11 years ago

Integration of JCT3V-E0172. The MACRO is "MTK_RVS_BUGFIX_E0172".

By Na Zhang (na.zhang@…)

  • Property svn:eol-style set to native
File size: 40.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  xDecompressCU( pcCU, 0,  0 );
138}
139
140// ====================================================================================================================
141// Protected member functions
142// ====================================================================================================================
143
144/**decode end-of-slice flag
145 * \param pcCU
146 * \param uiAbsPartIdx
147 * \param uiDepth
148 * \returns Bool
149 */
150Bool TDecCu::xDecodeSliceEnd( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth)
151{
152  UInt uiIsLast;
153  TComPic* pcPic = pcCU->getPic();
154  TComSlice * pcSlice = pcPic->getSlice(pcPic->getCurrSliceIdx());
155  UInt uiCurNumParts    = pcPic->getNumPartInCU() >> (uiDepth<<1);
156  UInt uiWidth = pcSlice->getSPS()->getPicWidthInLumaSamples();
157  UInt uiHeight = pcSlice->getSPS()->getPicHeightInLumaSamples();
158  UInt uiGranularityWidth = g_uiMaxCUWidth;
159  UInt uiPosX = pcCU->getCUPelX() + g_auiRasterToPelX[ g_auiZscanToRaster[uiAbsPartIdx] ];
160  UInt uiPosY = pcCU->getCUPelY() + g_auiRasterToPelY[ g_auiZscanToRaster[uiAbsPartIdx] ];
161
162  if(((uiPosX+pcCU->getWidth(uiAbsPartIdx))%uiGranularityWidth==0||(uiPosX+pcCU->getWidth(uiAbsPartIdx)==uiWidth))
163    &&((uiPosY+pcCU->getHeight(uiAbsPartIdx))%uiGranularityWidth==0||(uiPosY+pcCU->getHeight(uiAbsPartIdx)==uiHeight)))
164  {
165    m_pcEntropyDecoder->decodeTerminatingBit( uiIsLast );
166  }
167  else
168  {
169    uiIsLast=0;
170  }
171 
172  if(uiIsLast) 
173  {
174    if(pcSlice->isNextSliceSegment()&&!pcSlice->isNextSlice()) 
175    {
176      pcSlice->setSliceSegmentCurEndCUAddr(pcCU->getSCUAddr()+uiAbsPartIdx+uiCurNumParts);
177    }
178    else 
179    {
180      pcSlice->setSliceCurEndCUAddr(pcCU->getSCUAddr()+uiAbsPartIdx+uiCurNumParts);
181      pcSlice->setSliceSegmentCurEndCUAddr(pcCU->getSCUAddr()+uiAbsPartIdx+uiCurNumParts);
182    }
183  }
184
185  return uiIsLast>0;
186}
187
188/** decode CU block recursively
189 * \param pcCU
190 * \param uiAbsPartIdx
191 * \param uiDepth
192 * \returns Void
193 */
194
195Void TDecCu::xDecodeCU( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, UInt& ruiIsLast)
196{
197  TComPic* pcPic = pcCU->getPic();
198  UInt uiCurNumParts    = pcPic->getNumPartInCU() >> (uiDepth<<1);
199  UInt uiQNumParts      = uiCurNumParts>>2;
200 
201  Bool bBoundary = false;
202  UInt uiLPelX   = pcCU->getCUPelX() + g_auiRasterToPelX[ g_auiZscanToRaster[uiAbsPartIdx] ];
203  UInt uiRPelX   = uiLPelX + (g_uiMaxCUWidth>>uiDepth)  - 1;
204  UInt uiTPelY   = pcCU->getCUPelY() + g_auiRasterToPelY[ g_auiZscanToRaster[uiAbsPartIdx] ];
205  UInt uiBPelY   = uiTPelY + (g_uiMaxCUHeight>>uiDepth) - 1;
206#if H_MV_ENC_DEC_TRAC
207  DTRACE_CU_S("=========== coding_quadtree ===========\n")
208  DTRACE_CU("x0", uiLPelX)
209  DTRACE_CU("x1", uiTPelY)
210  DTRACE_CU("log2CbSize", g_uiMaxCUWidth>>uiDepth)
211  DTRACE_CU("cqtDepth"  , uiDepth)
212#endif
213  TComSlice * pcSlice = pcCU->getPic()->getSlice(pcCU->getPic()->getCurrSliceIdx());
214  Bool bStartInCU = pcCU->getSCUAddr()+uiAbsPartIdx+uiCurNumParts>pcSlice->getSliceSegmentCurStartCUAddr()&&pcCU->getSCUAddr()+uiAbsPartIdx<pcSlice->getSliceSegmentCurStartCUAddr();
215  if((!bStartInCU) && ( uiRPelX < pcSlice->getSPS()->getPicWidthInLumaSamples() ) && ( uiBPelY < pcSlice->getSPS()->getPicHeightInLumaSamples() ) )
216  {
217    m_pcEntropyDecoder->decodeSplitFlag( pcCU, uiAbsPartIdx, uiDepth );
218  }
219  else
220  {
221    bBoundary = true;
222  }
223 
224  if( ( ( uiDepth < pcCU->getDepth( uiAbsPartIdx ) ) && ( uiDepth < g_uiMaxCUDepth - g_uiAddCUDepth ) ) || bBoundary )
225  {
226    UInt uiIdx = uiAbsPartIdx;
227    if( (g_uiMaxCUWidth>>uiDepth) == pcCU->getSlice()->getPPS()->getMinCuDQPSize() && pcCU->getSlice()->getPPS()->getUseDQP())
228    {
229      setdQPFlag(true);
230      pcCU->setQPSubParts( pcCU->getRefQP(uiAbsPartIdx), uiAbsPartIdx, uiDepth ); // set QP to default QP
231    }
232
233    for ( UInt uiPartUnitIdx = 0; uiPartUnitIdx < 4; uiPartUnitIdx++ )
234    {
235      uiLPelX   = pcCU->getCUPelX() + g_auiRasterToPelX[ g_auiZscanToRaster[uiIdx] ];
236      uiTPelY   = pcCU->getCUPelY() + g_auiRasterToPelY[ g_auiZscanToRaster[uiIdx] ];
237     
238      Bool bSubInSlice = pcCU->getSCUAddr()+uiIdx+uiQNumParts>pcSlice->getSliceSegmentCurStartCUAddr();
239      if ( bSubInSlice )
240      {
241        if ( !ruiIsLast && ( uiLPelX < pcCU->getSlice()->getSPS()->getPicWidthInLumaSamples() ) && ( uiTPelY < pcCU->getSlice()->getSPS()->getPicHeightInLumaSamples() ) )
242        {
243          xDecodeCU( pcCU, uiIdx, uiDepth+1, ruiIsLast );
244        }
245        else
246        {
247          pcCU->setOutsideCUPart( uiIdx, uiDepth+1 );
248        }
249      }
250     
251      uiIdx += uiQNumParts;
252    }
253    if( (g_uiMaxCUWidth>>uiDepth) == pcCU->getSlice()->getPPS()->getMinCuDQPSize() && pcCU->getSlice()->getPPS()->getUseDQP())
254    {
255      if ( getdQPFlag() )
256      {
257        UInt uiQPSrcPartIdx;
258        if ( pcPic->getCU( pcCU->getAddr() )->getSliceSegmentStartCU(uiAbsPartIdx) != pcSlice->getSliceSegmentCurStartCUAddr() )
259        {
260          uiQPSrcPartIdx = pcSlice->getSliceSegmentCurStartCUAddr() % pcPic->getNumPartInCU();
261        }
262        else
263        {
264          uiQPSrcPartIdx = uiAbsPartIdx;
265        }
266        pcCU->setQPSubParts( pcCU->getRefQP( uiQPSrcPartIdx ), uiAbsPartIdx, uiDepth ); // set QP to default QP
267      }
268    }
269    return;
270  }
271 
272#if H_MV_ENC_DEC_TRAC
273  DTRACE_CU_S("=========== coding_unit ===========\n")
274#endif
275
276  if( (g_uiMaxCUWidth>>uiDepth) >= pcCU->getSlice()->getPPS()->getMinCuDQPSize() && pcCU->getSlice()->getPPS()->getUseDQP())
277  {
278    setdQPFlag(true);
279    pcCU->setQPSubParts( pcCU->getRefQP(uiAbsPartIdx), uiAbsPartIdx, uiDepth ); // set QP to default QP
280  }
281#if H_3D_NBDV
282  DisInfo DvInfo; 
283  DvInfo.bDV = false;
284  DvInfo.m_acNBDV.setZero();
285  DvInfo.m_aVIdxCan = 0;
286#if H_3D_NBDV_REF 
287  DvInfo.m_acDoNBDV.setZero();
288#endif
289 
290 
291  if(!pcCU->getSlice()->isIntra())
292  {
293#if H_3D_ARP && H_3D_IV_MERGE
294    if( pcCU->getSlice()->getVPS()->getUseAdvRP( pcCU->getSlice()->getLayerId() ) || pcCU->getSlice()->getVPS()->getIvMvPredFlag( pcCU->getSlice()->getLayerId() ))
295#else
296#if H_3D_ARP
297    if( pcCU->getSlice()->getVPS()->getUseAdvRP(pcCU->getSlice()->getLayerId()) )
298#else
299#if H_3D_IV_MERGE
300    if( pcCU->getSlice()->getVPS()->getIvMvPredFlag(pcCU->getSlice()->getLayerId()) )
301#else
302    if (0)
303#endif
304#endif
305#endif
306    {
307      m_ppcCU[uiDepth]->copyInterPredInfoFrom( pcCU, uiAbsPartIdx, REF_PIC_LIST_0, true );
308      m_ppcCU[uiDepth]->copyDVInfoFrom( pcCU, uiAbsPartIdx);
309      PartSize ePartTemp = m_ppcCU[uiDepth]->getPartitionSize(0);
310      UChar cWidTemp     = m_ppcCU[uiDepth]->getWidth(0);
311      UChar cHeightTemp  = m_ppcCU[uiDepth]->getHeight(0);
312      m_ppcCU[uiDepth]->setWidth  ( 0, pcCU->getSlice()->getSPS()->getMaxCUWidth ()/(1<<uiDepth)  );
313      m_ppcCU[uiDepth]->setHeight ( 0, pcCU->getSlice()->getSPS()->getMaxCUHeight()/(1<<uiDepth)  );
314      m_ppcCU[uiDepth]->setPartSizeSubParts( SIZE_2Nx2N, 0, uiDepth );     
315#if H_3D_NBDV_REF
316      if(pcCU->getSlice()->getVPS()->getDepthRefinementFlag( pcCU->getSlice()->getLayerIdInVps() ))  //Notes from QC: please check the condition for DoNBDV. Remove this comment once it is done.
317        DvInfo.bDV = m_ppcCU[uiDepth]->getDisMvpCandNBDV(&DvInfo, true);
318      else
319#endif
320        DvInfo.bDV = m_ppcCU[uiDepth]->getDisMvpCandNBDV(&DvInfo);
321
322      pcCU->setDvInfoSubParts(DvInfo, uiAbsPartIdx, uiDepth);
323      m_ppcCU[uiDepth]->setPartSizeSubParts( ePartTemp, 0, uiDepth );
324      m_ppcCU[uiDepth]->setWidth  ( 0, cWidTemp );
325      m_ppcCU[uiDepth]->setHeight ( 0, cHeightTemp );
326     }
327  }
328#endif
329  if (pcCU->getSlice()->getPPS()->getTransquantBypassEnableFlag())
330  {
331    m_pcEntropyDecoder->decodeCUTransquantBypassFlag( pcCU, uiAbsPartIdx, uiDepth );
332  }
333 
334  // decode CU mode and the partition size
335  if( !pcCU->getSlice()->isIntra())
336  {
337    m_pcEntropyDecoder->decodeSkipFlag( pcCU, uiAbsPartIdx, uiDepth );
338  }
339 
340  if( pcCU->isSkipped(uiAbsPartIdx) )
341  {
342#if H_MV_ENC_DEC_TRAC
343    DTRACE_PU_S("=========== prediction_unit ===========\n")
344    DTRACE_PU("x0", uiLPelX)
345    DTRACE_PU("x1", uiTPelY)
346#endif
347    m_ppcCU[uiDepth]->copyInterPredInfoFrom( pcCU, uiAbsPartIdx, REF_PIC_LIST_0 );
348    m_ppcCU[uiDepth]->copyInterPredInfoFrom( pcCU, uiAbsPartIdx, REF_PIC_LIST_1 );
349#if H_3D_IV_MERGE
350    m_ppcCU[uiDepth]->copyDVInfoFrom(pcCU, uiAbsPartIdx);
351    TComMvField cMvFieldNeighbours[MRG_MAX_NUM_CANDS_MEM << 1]; // double length for mv of both lists
352    UChar uhInterDirNeighbours[MRG_MAX_NUM_CANDS_MEM];
353#else
354    TComMvField cMvFieldNeighbours[MRG_MAX_NUM_CANDS << 1]; // double length for mv of both lists
355    UChar uhInterDirNeighbours[MRG_MAX_NUM_CANDS];
356#endif
357    Int numValidMergeCand = 0;
358    for( UInt ui = 0; ui < m_ppcCU[uiDepth]->getSlice()->getMaxNumMergeCand(); ++ui )
359    {
360      uhInterDirNeighbours[ui] = 0;
361    }
362    m_pcEntropyDecoder->decodeMergeIndex( pcCU, 0, uiAbsPartIdx, uiDepth );
363    UInt uiMergeIndex = pcCU->getMergeIndex(uiAbsPartIdx);
364
365#if H_3D_VSP
366    Int vspFlag[MRG_MAX_NUM_CANDS_MEM];
367    memset(vspFlag, 0, sizeof(Int)*MRG_MAX_NUM_CANDS_MEM);
368#if MTK_VSP_FIX_E0172
369    Int vspDir[MRG_MAX_NUM_CANDS_MEM];
370    memset(vspDir, 0, sizeof(Int)*MRG_MAX_NUM_CANDS_MEM);
371    m_ppcCU[uiDepth]->getInterMergeCandidates( 0, 0, cMvFieldNeighbours, uhInterDirNeighbours, vspFlag,vspDir, numValidMergeCand, uiMergeIndex );
372    pcCU->setVSPDirSubParts( vspDir[uiMergeIndex], uiAbsPartIdx, 0, uiDepth );
373#else
374    m_ppcCU[uiDepth]->getInterMergeCandidates( 0, 0, cMvFieldNeighbours, uhInterDirNeighbours, vspFlag, numValidMergeCand, uiMergeIndex );
375#endif
376    pcCU->setVSPFlagSubParts( vspFlag[uiMergeIndex], uiAbsPartIdx, 0, uiDepth );
377#else
378    m_ppcCU[uiDepth]->getInterMergeCandidates( 0, 0, cMvFieldNeighbours, uhInterDirNeighbours, numValidMergeCand, uiMergeIndex );
379#endif
380
381    pcCU->setInterDirSubParts( uhInterDirNeighbours[uiMergeIndex], uiAbsPartIdx, 0, uiDepth );
382
383    TComMv cTmpMv( 0, 0 );
384    for ( UInt uiRefListIdx = 0; uiRefListIdx < 2; uiRefListIdx++ )
385    {       
386      if ( pcCU->getSlice()->getNumRefIdx( RefPicList( uiRefListIdx ) ) > 0 )
387      {
388        pcCU->setMVPIdxSubParts( 0, RefPicList( uiRefListIdx ), uiAbsPartIdx, 0, uiDepth);
389        pcCU->setMVPNumSubParts( 0, RefPicList( uiRefListIdx ), uiAbsPartIdx, 0, uiDepth);
390        pcCU->getCUMvField( RefPicList( uiRefListIdx ) )->setAllMvd( cTmpMv, SIZE_2Nx2N, uiAbsPartIdx, uiDepth );
391        pcCU->getCUMvField( RefPicList( uiRefListIdx ) )->setAllMvField( cMvFieldNeighbours[ 2*uiMergeIndex + uiRefListIdx ], SIZE_2Nx2N, uiAbsPartIdx, uiDepth );
392      }
393    }
394#if H_3D_IC
395    m_pcEntropyDecoder->decodeICFlag( pcCU, uiAbsPartIdx, uiDepth );
396#endif
397#if H_3D_ARP
398    m_pcEntropyDecoder->decodeARPW( pcCU , uiAbsPartIdx , uiDepth );
399#endif
400    xFinishDecodeCU( pcCU, uiAbsPartIdx, uiDepth, ruiIsLast );
401    return;
402  }
403
404  m_pcEntropyDecoder->decodePredMode( pcCU, uiAbsPartIdx, uiDepth );
405  m_pcEntropyDecoder->decodePartSize( pcCU, uiAbsPartIdx, uiDepth );
406
407  if (pcCU->isIntra( uiAbsPartIdx ) && pcCU->getPartitionSize( uiAbsPartIdx ) == SIZE_2Nx2N )
408  {
409    m_pcEntropyDecoder->decodeIPCMInfo( pcCU, uiAbsPartIdx, uiDepth );
410
411    if(pcCU->getIPCMFlag(uiAbsPartIdx))
412    {
413      xFinishDecodeCU( pcCU, uiAbsPartIdx, uiDepth, ruiIsLast );
414      return;
415    }
416  }
417
418  UInt uiCurrWidth      = pcCU->getWidth ( uiAbsPartIdx );
419  UInt uiCurrHeight     = pcCU->getHeight( uiAbsPartIdx );
420 
421  // prediction mode ( Intra : direction mode, Inter : Mv, reference idx )
422  m_pcEntropyDecoder->decodePredInfo( pcCU, uiAbsPartIdx, uiDepth, m_ppcCU[uiDepth]);
423#if H_3D_IC
424  m_pcEntropyDecoder->decodeICFlag( pcCU, uiAbsPartIdx, uiDepth );
425#endif
426#if H_3D_ARP
427  m_pcEntropyDecoder->decodeARPW    ( pcCU , uiAbsPartIdx , uiDepth ); 
428#endif 
429  // Coefficient decoding
430  Bool bCodeDQP = getdQPFlag();
431  m_pcEntropyDecoder->decodeCoeff( pcCU, uiAbsPartIdx, uiDepth, uiCurrWidth, uiCurrHeight, bCodeDQP );
432  setdQPFlag( bCodeDQP );
433  xFinishDecodeCU( pcCU, uiAbsPartIdx, uiDepth, ruiIsLast );
434}
435
436Void TDecCu::xFinishDecodeCU( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, UInt& ruiIsLast)
437{
438  if(  pcCU->getSlice()->getPPS()->getUseDQP())
439  {
440    pcCU->setQPSubParts( getdQPFlag()?pcCU->getRefQP(uiAbsPartIdx):pcCU->getCodedQP(), uiAbsPartIdx, uiDepth ); // set QP
441  }
442
443  ruiIsLast = xDecodeSliceEnd( pcCU, uiAbsPartIdx, uiDepth);
444}
445
446Void TDecCu::xDecompressCU( TComDataCU* pcCU, UInt uiAbsPartIdx,  UInt uiDepth )
447{
448  TComPic* pcPic = pcCU->getPic();
449 
450  Bool bBoundary = false;
451  UInt uiLPelX   = pcCU->getCUPelX() + g_auiRasterToPelX[ g_auiZscanToRaster[uiAbsPartIdx] ];
452  UInt uiRPelX   = uiLPelX + (g_uiMaxCUWidth>>uiDepth)  - 1;
453  UInt uiTPelY   = pcCU->getCUPelY() + g_auiRasterToPelY[ g_auiZscanToRaster[uiAbsPartIdx] ];
454  UInt uiBPelY   = uiTPelY + (g_uiMaxCUHeight>>uiDepth) - 1;
455 
456  UInt uiCurNumParts    = pcPic->getNumPartInCU() >> (uiDepth<<1);
457  TComSlice * pcSlice = pcCU->getPic()->getSlice(pcCU->getPic()->getCurrSliceIdx());
458  Bool bStartInCU = pcCU->getSCUAddr()+uiAbsPartIdx+uiCurNumParts>pcSlice->getSliceSegmentCurStartCUAddr()&&pcCU->getSCUAddr()+uiAbsPartIdx<pcSlice->getSliceSegmentCurStartCUAddr();
459  if(bStartInCU||( uiRPelX >= pcSlice->getSPS()->getPicWidthInLumaSamples() ) || ( uiBPelY >= pcSlice->getSPS()->getPicHeightInLumaSamples() ) )
460  {
461    bBoundary = true;
462  }
463 
464  if( ( ( uiDepth < pcCU->getDepth( uiAbsPartIdx ) ) && ( uiDepth < g_uiMaxCUDepth - g_uiAddCUDepth ) ) || bBoundary )
465  {
466    UInt uiNextDepth = uiDepth + 1;
467    UInt uiQNumParts = pcCU->getTotalNumPart() >> (uiNextDepth<<1);
468    UInt uiIdx = uiAbsPartIdx;
469    for ( UInt uiPartIdx = 0; uiPartIdx < 4; uiPartIdx++ )
470    {
471      uiLPelX = pcCU->getCUPelX() + g_auiRasterToPelX[ g_auiZscanToRaster[uiIdx] ];
472      uiTPelY = pcCU->getCUPelY() + g_auiRasterToPelY[ g_auiZscanToRaster[uiIdx] ];
473     
474      Bool binSlice = (pcCU->getSCUAddr()+uiIdx+uiQNumParts>pcSlice->getSliceSegmentCurStartCUAddr())&&(pcCU->getSCUAddr()+uiIdx<pcSlice->getSliceSegmentCurEndCUAddr());
475      if(binSlice&&( uiLPelX < pcSlice->getSPS()->getPicWidthInLumaSamples() ) && ( uiTPelY < pcSlice->getSPS()->getPicHeightInLumaSamples() ) )
476      {
477        xDecompressCU(pcCU, uiIdx, uiNextDepth );
478      }
479     
480      uiIdx += uiQNumParts;
481    }
482    return;
483  }
484 
485  // Residual reconstruction
486  m_ppcYuvResi[uiDepth]->clear();
487 
488  m_ppcCU[uiDepth]->copySubCU( pcCU, uiAbsPartIdx, uiDepth );
489 
490  switch( m_ppcCU[uiDepth]->getPredictionMode(0) )
491  {
492    case MODE_INTER:
493      xReconInter( m_ppcCU[uiDepth], uiDepth );
494      break;
495    case MODE_INTRA:
496#if H_3D_DIM_SDC
497      if( m_ppcCU[uiDepth]->getSDCFlag(0) )
498        xReconIntraSDC( m_ppcCU[uiDepth], 0, uiDepth );
499      else
500#endif
501      xReconIntraQT( m_ppcCU[uiDepth], uiDepth );
502      break;
503    default:
504      assert(0);
505      break;
506  }
507  if ( m_ppcCU[uiDepth]->isLosslessCoded(0) && (m_ppcCU[uiDepth]->getIPCMFlag(0) == false))
508  {
509    xFillPCMBuffer(m_ppcCU[uiDepth], uiDepth);
510  }
511 
512  xCopyToPic( m_ppcCU[uiDepth], pcPic, uiAbsPartIdx, uiDepth );
513}
514
515Void TDecCu::xReconInter( TComDataCU* pcCU, UInt uiDepth )
516{
517 
518  // inter prediction
519  m_pcPrediction->motionCompensation( pcCU, m_ppcYuvReco[uiDepth] );
520 
521  // inter recon
522  xDecodeInterTexture( pcCU, 0, uiDepth );
523 
524  // clip for only non-zero cbp case
525  if  ( ( pcCU->getCbf( 0, TEXT_LUMA ) ) || ( pcCU->getCbf( 0, TEXT_CHROMA_U ) ) || ( pcCU->getCbf(0, TEXT_CHROMA_V ) ) )
526  {
527    m_ppcYuvReco[uiDepth]->addClip( m_ppcYuvReco[uiDepth], m_ppcYuvResi[uiDepth], 0, pcCU->getWidth( 0 ) );
528  }
529  else
530  {
531    m_ppcYuvReco[uiDepth]->copyPartToPartYuv( m_ppcYuvReco[uiDepth],0, pcCU->getWidth( 0 ),pcCU->getHeight( 0 ));
532  }
533}
534
535Void
536TDecCu::xIntraRecLumaBlk( TComDataCU* pcCU,
537                         UInt        uiTrDepth,
538                         UInt        uiAbsPartIdx,
539                         TComYuv*    pcRecoYuv,
540                         TComYuv*    pcPredYuv, 
541                         TComYuv*    pcResiYuv )
542{
543  UInt    uiWidth           = pcCU     ->getWidth   ( 0 ) >> uiTrDepth;
544  UInt    uiHeight          = pcCU     ->getHeight  ( 0 ) >> uiTrDepth;
545  UInt    uiStride          = pcRecoYuv->getStride  ();
546  Pel*    piReco            = pcRecoYuv->getLumaAddr( uiAbsPartIdx );
547  Pel*    piPred            = pcPredYuv->getLumaAddr( uiAbsPartIdx );
548  Pel*    piResi            = pcResiYuv->getLumaAddr( uiAbsPartIdx );
549 
550  UInt    uiNumCoeffInc     = ( pcCU->getSlice()->getSPS()->getMaxCUWidth() * pcCU->getSlice()->getSPS()->getMaxCUHeight() ) >> ( pcCU->getSlice()->getSPS()->getMaxCUDepth() << 1 );
551  TCoeff* pcCoeff           = pcCU->getCoeffY() + ( uiNumCoeffInc * uiAbsPartIdx );
552 
553  UInt    uiLumaPredMode    = pcCU->getLumaIntraDir     ( uiAbsPartIdx );
554 
555  UInt    uiZOrder          = pcCU->getZorderIdxInCU() + uiAbsPartIdx;
556  Pel*    piRecIPred        = pcCU->getPic()->getPicYuvRec()->getLumaAddr( pcCU->getAddr(), uiZOrder );
557  UInt    uiRecIPredStride  = pcCU->getPic()->getPicYuvRec()->getStride  ();
558  Bool    useTransformSkip  = pcCU->getTransformSkip(uiAbsPartIdx, TEXT_LUMA);
559  //===== init availability pattern =====
560  Bool  bAboveAvail = false;
561  Bool  bLeftAvail  = false;
562  pcCU->getPattern()->initPattern   ( pcCU, uiTrDepth, uiAbsPartIdx );
563  pcCU->getPattern()->initAdiPattern( pcCU, uiAbsPartIdx, uiTrDepth, 
564                                     m_pcPrediction->getPredicBuf       (),
565                                     m_pcPrediction->getPredicBufWidth  (),
566                                     m_pcPrediction->getPredicBufHeight (),
567                                     bAboveAvail, bLeftAvail );
568 
569  //===== get prediction signal =====
570#if H_3D_DIM
571  if( isDimMode( uiLumaPredMode ) )
572  {
573    m_pcPrediction->predIntraLumaDepth( pcCU, uiAbsPartIdx, uiLumaPredMode, piPred, uiStride, uiWidth, uiHeight );
574  }
575  else
576  {
577#endif
578  m_pcPrediction->predIntraLumaAng( pcCU->getPattern(), uiLumaPredMode, piPred, uiStride, uiWidth, uiHeight, bAboveAvail, bLeftAvail );
579#if H_3D_DIM
580  }
581#endif
582 
583  //===== inverse transform =====
584  m_pcTrQuant->setQPforQuant  ( pcCU->getQP(0), TEXT_LUMA, pcCU->getSlice()->getSPS()->getQpBDOffsetY(), 0 );
585
586  Int scalingListType = (pcCU->isIntra(uiAbsPartIdx) ? 0 : 3) + g_eTTable[(Int)TEXT_LUMA];
587  assert(scalingListType < 6);
588  m_pcTrQuant->invtransformNxN( pcCU->getCUTransquantBypass(uiAbsPartIdx), TEXT_LUMA, pcCU->getLumaIntraDir( uiAbsPartIdx ), piResi, uiStride, pcCoeff, uiWidth, uiHeight, scalingListType, useTransformSkip );
589
590 
591  //===== reconstruction =====
592  Pel* pPred      = piPred;
593  Pel* pResi      = piResi;
594  Pel* pReco      = piReco;
595  Pel* pRecIPred  = piRecIPred;
596  for( UInt uiY = 0; uiY < uiHeight; uiY++ )
597  {
598    for( UInt uiX = 0; uiX < uiWidth; uiX++ )
599    {
600      pReco    [ uiX ] = ClipY( pPred[ uiX ] + pResi[ uiX ] );
601      pRecIPred[ uiX ] = pReco[ uiX ];
602    }
603    pPred     += uiStride;
604    pResi     += uiStride;
605    pReco     += uiStride;
606    pRecIPred += uiRecIPredStride;
607  }
608}
609
610
611Void
612TDecCu::xIntraRecChromaBlk( TComDataCU* pcCU,
613                           UInt        uiTrDepth,
614                           UInt        uiAbsPartIdx,
615                           TComYuv*    pcRecoYuv,
616                           TComYuv*    pcPredYuv, 
617                           TComYuv*    pcResiYuv,
618                           UInt        uiChromaId )
619{
620  UInt uiFullDepth  = pcCU->getDepth( 0 ) + uiTrDepth;
621  UInt uiLog2TrSize = g_aucConvertToBit[ pcCU->getSlice()->getSPS()->getMaxCUWidth() >> uiFullDepth ] + 2;
622
623  if( uiLog2TrSize == 2 )
624  {
625    assert( uiTrDepth > 0 );
626    uiTrDepth--;
627    UInt uiQPDiv = pcCU->getPic()->getNumPartInCU() >> ( ( pcCU->getDepth( 0 ) + uiTrDepth ) << 1 );
628    Bool bFirstQ = ( ( uiAbsPartIdx % uiQPDiv ) == 0 );
629    if( !bFirstQ )
630    {
631      return;
632    }
633  }
634 
635  TextType  eText             = ( uiChromaId > 0 ? TEXT_CHROMA_V : TEXT_CHROMA_U );
636  UInt      uiWidth           = pcCU     ->getWidth   ( 0 ) >> ( uiTrDepth + 1 );
637  UInt      uiHeight          = pcCU     ->getHeight  ( 0 ) >> ( uiTrDepth + 1 );
638  UInt      uiStride          = pcRecoYuv->getCStride ();
639  Pel*      piReco            = ( uiChromaId > 0 ? pcRecoYuv->getCrAddr( uiAbsPartIdx ) : pcRecoYuv->getCbAddr( uiAbsPartIdx ) );
640  Pel*      piPred            = ( uiChromaId > 0 ? pcPredYuv->getCrAddr( uiAbsPartIdx ) : pcPredYuv->getCbAddr( uiAbsPartIdx ) );
641  Pel*      piResi            = ( uiChromaId > 0 ? pcResiYuv->getCrAddr( uiAbsPartIdx ) : pcResiYuv->getCbAddr( uiAbsPartIdx ) );
642 
643  UInt      uiNumCoeffInc     = ( ( pcCU->getSlice()->getSPS()->getMaxCUWidth() * pcCU->getSlice()->getSPS()->getMaxCUHeight() ) >> ( pcCU->getSlice()->getSPS()->getMaxCUDepth() << 1 ) ) >> 2;
644  TCoeff*   pcCoeff           = ( uiChromaId > 0 ? pcCU->getCoeffCr() : pcCU->getCoeffCb() ) + ( uiNumCoeffInc * uiAbsPartIdx );
645 
646  UInt      uiChromaPredMode  = pcCU->getChromaIntraDir( 0 );
647 
648  UInt      uiZOrder          = pcCU->getZorderIdxInCU() + uiAbsPartIdx;
649  Pel*      piRecIPred        = ( uiChromaId > 0 ? pcCU->getPic()->getPicYuvRec()->getCrAddr( pcCU->getAddr(), uiZOrder ) : pcCU->getPic()->getPicYuvRec()->getCbAddr( pcCU->getAddr(), uiZOrder ) );
650  UInt      uiRecIPredStride  = pcCU->getPic()->getPicYuvRec()->getCStride();
651  Bool      useTransformSkipChroma = pcCU->getTransformSkip(uiAbsPartIdx,eText);
652  //===== init availability pattern =====
653  Bool  bAboveAvail = false;
654  Bool  bLeftAvail  = false;
655  pcCU->getPattern()->initPattern         ( pcCU, uiTrDepth, uiAbsPartIdx );
656
657  pcCU->getPattern()->initAdiPatternChroma( pcCU, uiAbsPartIdx, uiTrDepth,
658                                           m_pcPrediction->getPredicBuf       (),
659                                           m_pcPrediction->getPredicBufWidth  (),
660                                           m_pcPrediction->getPredicBufHeight (),
661                                           bAboveAvail, bLeftAvail );
662  Int* pPatChroma   = ( uiChromaId > 0 ? pcCU->getPattern()->getAdiCrBuf( uiWidth, uiHeight, m_pcPrediction->getPredicBuf() ) : pcCU->getPattern()->getAdiCbBuf( uiWidth, uiHeight, m_pcPrediction->getPredicBuf() ) );
663 
664  //===== get prediction signal =====
665  {
666    if( uiChromaPredMode == DM_CHROMA_IDX )
667    {
668      uiChromaPredMode = pcCU->getLumaIntraDir( 0 );
669#if H_3D_DIM
670      mapDepthModeToIntraDir( uiChromaPredMode );
671#endif
672    }
673    m_pcPrediction->predIntraChromaAng( pPatChroma, uiChromaPredMode, piPred, uiStride, uiWidth, uiHeight, bAboveAvail, bLeftAvail ); 
674  }
675
676  //===== inverse transform =====
677  Int curChromaQpOffset;
678  if(eText == TEXT_CHROMA_U)
679  {
680    curChromaQpOffset = pcCU->getSlice()->getPPS()->getChromaCbQpOffset() + pcCU->getSlice()->getSliceQpDeltaCb();
681  }
682  else
683  {
684    curChromaQpOffset = pcCU->getSlice()->getPPS()->getChromaCrQpOffset() + pcCU->getSlice()->getSliceQpDeltaCr();
685  }
686  m_pcTrQuant->setQPforQuant  ( pcCU->getQP(0), eText, pcCU->getSlice()->getSPS()->getQpBDOffsetC(), curChromaQpOffset );
687
688  Int scalingListType = (pcCU->isIntra(uiAbsPartIdx) ? 0 : 3) + g_eTTable[(Int)eText];
689  assert(scalingListType < 6);
690  m_pcTrQuant->invtransformNxN( pcCU->getCUTransquantBypass(uiAbsPartIdx), eText, REG_DCT, piResi, uiStride, pcCoeff, uiWidth, uiHeight, scalingListType, useTransformSkipChroma );
691
692  //===== reconstruction =====
693  Pel* pPred      = piPred;
694  Pel* pResi      = piResi;
695  Pel* pReco      = piReco;
696  Pel* pRecIPred  = piRecIPred;
697  for( UInt uiY = 0; uiY < uiHeight; uiY++ )
698  {
699    for( UInt uiX = 0; uiX < uiWidth; uiX++ )
700    {
701      pReco    [ uiX ] = ClipC( pPred[ uiX ] + pResi[ uiX ] );
702      pRecIPred[ uiX ] = pReco[ uiX ];
703    }
704    pPred     += uiStride;
705    pResi     += uiStride;
706    pReco     += uiStride;
707    pRecIPred += uiRecIPredStride;
708  }
709}
710
711
712Void
713TDecCu::xReconIntraQT( TComDataCU* pcCU, UInt uiDepth )
714{
715  UInt  uiInitTrDepth = ( pcCU->getPartitionSize(0) == SIZE_2Nx2N ? 0 : 1 );
716  UInt  uiNumPart     = pcCU->getNumPartInter();
717  UInt  uiNumQParts   = pcCU->getTotalNumPart() >> 2;
718 
719  if (pcCU->getIPCMFlag(0))
720  {
721    xReconPCM( pcCU, uiDepth );
722    return;
723  }
724
725  for( UInt uiPU = 0; uiPU < uiNumPart; uiPU++ )
726  {
727    xIntraLumaRecQT( pcCU, uiInitTrDepth, uiPU * uiNumQParts, m_ppcYuvReco[uiDepth], m_ppcYuvReco[uiDepth], m_ppcYuvResi[uiDepth] );
728  } 
729
730  for( UInt uiPU = 0; uiPU < uiNumPart; uiPU++ )
731  {
732    xIntraChromaRecQT( pcCU, uiInitTrDepth, uiPU * uiNumQParts, m_ppcYuvReco[uiDepth], m_ppcYuvReco[uiDepth], m_ppcYuvResi[uiDepth] );
733  }
734
735}
736
737#if H_3D_DIM_SDC
738Void TDecCu::xReconIntraSDC( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
739{
740  UInt uiWidth        = pcCU->getWidth  ( 0 );
741  UInt uiHeight       = pcCU->getHeight ( 0 );
742 
743  TComYuv* pcRecoYuv  = m_ppcYuvReco[uiDepth];
744  TComYuv* pcPredYuv  = m_ppcYuvReco[uiDepth];
745  TComYuv* pcResiYuv  = m_ppcYuvResi[uiDepth];
746 
747  UInt    uiStride    = pcRecoYuv->getStride  ();
748  Pel*    piReco      = pcRecoYuv->getLumaAddr( uiAbsPartIdx );
749  Pel*    piPred      = pcPredYuv->getLumaAddr( uiAbsPartIdx );
750  Pel*    piResi      = pcResiYuv->getLumaAddr( uiAbsPartIdx );
751 
752  UInt    uiZOrder          = pcCU->getZorderIdxInCU() + uiAbsPartIdx;
753  Pel*    piRecIPred        = pcCU->getPic()->getPicYuvRec()->getLumaAddr( pcCU->getAddr(), uiZOrder );
754  UInt    uiRecIPredStride  = pcCU->getPic()->getPicYuvRec()->getStride  ();
755 
756  UInt    uiLumaPredMode    = pcCU->getLumaIntraDir     ( uiAbsPartIdx );
757 
758  AOF( uiWidth == uiHeight );
759  AOF( uiAbsPartIdx == 0 );
760  AOF( pcCU->getSDCAvailable(uiAbsPartIdx) );
761  AOF( pcCU->getSDCFlag(uiAbsPartIdx) );
762 
763  //===== init availability pattern =====
764  Bool  bAboveAvail = false;
765  Bool  bLeftAvail  = false;
766  pcCU->getPattern()->initPattern   ( pcCU, 0, uiAbsPartIdx );
767  pcCU->getPattern()->initAdiPattern( pcCU, uiAbsPartIdx, 0, m_pcPrediction->getPredicBuf(), m_pcPrediction->getPredicBufWidth(), m_pcPrediction->getPredicBufHeight(), bAboveAvail, bLeftAvail );
768 
769  //===== get prediction signal =====
770#if H_3D_DIM
771  if( isDimMode( uiLumaPredMode ) )
772  {
773    m_pcPrediction->predIntraLumaDepth( pcCU, uiAbsPartIdx, uiLumaPredMode, piPred, uiStride, uiWidth, uiHeight );
774  }
775  else
776  {
777#endif
778    m_pcPrediction->predIntraLumaAng( pcCU->getPattern(), uiLumaPredMode, piPred, uiStride, uiWidth, uiHeight, bAboveAvail, bLeftAvail );
779#if H_3D_DIM
780  }
781#endif
782 
783  // number of segments depends on prediction mode
784  UInt uiNumSegments = 1;
785  Bool* pbMask = NULL;
786  UInt uiMaskStride = 0;
787 
788  if( getDimType( uiLumaPredMode ) == DMM1_IDX )
789  {
790    Int uiTabIdx = pcCU->getDmmWedgeTabIdx(DMM1_IDX, uiAbsPartIdx);
791   
792    WedgeList* pacWedgeList = &g_dmmWedgeLists[(g_aucConvertToBit[uiWidth])];
793    TComWedgelet* pcWedgelet = &(pacWedgeList->at( uiTabIdx ));
794   
795    uiNumSegments = 2;
796    pbMask = pcWedgelet->getPattern();
797    uiMaskStride = pcWedgelet->getStride();
798  }
799 
800  // get DC prediction for each segment
801  Pel apDCPredValues[2];
802  m_pcPrediction->analyzeSegmentsSDC(piPred, uiStride, uiWidth, apDCPredValues, uiNumSegments, pbMask, uiMaskStride);
803 
804  // reconstruct residual based on mask + DC residuals
805  Pel apDCResiValues[2];
806  for( UInt uiSegment = 0; uiSegment < uiNumSegments; uiSegment++ )
807  {
808#if H_3D_DIM_DLT
809    Pel   pPredIdx    = pcCU->getSlice()->getVPS()->depthValue2idx( pcCU->getSlice()->getLayerIdInVps(), apDCPredValues[uiSegment] );
810    Pel   pResiIdx    = pcCU->getSDCSegmentDCOffset(uiSegment, uiAbsPartIdx);
811    Pel   pRecoValue  = pcCU->getSlice()->getVPS()->idx2DepthValue( pcCU->getSlice()->getLayerIdInVps(), pPredIdx + pResiIdx );
812   
813    apDCResiValues[uiSegment]  = pRecoValue - apDCPredValues[uiSegment];
814#else
815    apDCResiValues[uiSegment]  = pcCU->getSDCSegmentDCOffset(uiSegment, uiAbsPartIdx);
816#endif
817  }
818 
819  //===== reconstruction =====
820  Bool*pMask      = pbMask;
821  Pel* pPred      = piPred;
822  Pel* pResi      = piResi;
823  Pel* pReco      = piReco;
824  Pel* pRecIPred  = piRecIPred;
825 
826  for( UInt uiY = 0; uiY < uiHeight; uiY++ )
827  {
828    for( UInt uiX = 0; uiX < uiWidth; uiX++ )
829    {
830      UChar ucSegment = pMask?(UChar)pMask[uiX]:0;
831      assert( ucSegment < uiNumSegments );
832     
833      Pel pResiDC = apDCResiValues[ucSegment];
834     
835      pReco    [ uiX ] = ClipY( pPred[ uiX ] + pResiDC );
836      pRecIPred[ uiX ] = pReco[ uiX ];
837    }
838    pPred     += uiStride;
839    pResi     += uiStride;
840    pReco     += uiStride;
841    pRecIPred += uiRecIPredStride;
842    pMask     += uiMaskStride;
843  }
844 
845  // clear UV
846  UInt  uiStrideC     = pcPredYuv->getCStride();
847  Pel   *pRecCb       = pcPredYuv->getCbAddr();
848  Pel   *pRecCr       = pcPredYuv->getCrAddr();
849 
850  for (Int y=0; y<uiHeight/2; y++)
851  {
852    for (Int x=0; x<uiWidth/2; x++)
853    {
854      pRecCb[x] = 128;
855      pRecCr[x] = 128;
856    }
857   
858    pRecCb += uiStrideC;
859    pRecCr += uiStrideC;
860  }
861}
862#endif
863
864/** Function for deriving recontructed PU/CU Luma sample with QTree structure
865 * \param pcCU pointer of current CU
866 * \param uiTrDepth current tranform split depth
867 * \param uiAbsPartIdx  part index
868 * \param pcRecoYuv pointer to reconstructed sample arrays
869 * \param pcPredYuv pointer to prediction sample arrays
870 * \param pcResiYuv pointer to residue sample arrays
871 *
872 \ This function dervies recontructed PU/CU Luma sample with recursive QTree structure
873 */
874Void
875TDecCu::xIntraLumaRecQT( TComDataCU* pcCU,
876                     UInt        uiTrDepth,
877                     UInt        uiAbsPartIdx,
878                     TComYuv*    pcRecoYuv,
879                     TComYuv*    pcPredYuv, 
880                     TComYuv*    pcResiYuv )
881{
882  UInt uiFullDepth  = pcCU->getDepth(0) + uiTrDepth;
883  UInt uiTrMode     = pcCU->getTransformIdx( uiAbsPartIdx );
884  if( uiTrMode == uiTrDepth )
885  {
886    xIntraRecLumaBlk  ( pcCU, uiTrDepth, uiAbsPartIdx, pcRecoYuv, pcPredYuv, pcResiYuv );
887  }
888  else
889  {
890    UInt uiNumQPart  = pcCU->getPic()->getNumPartInCU() >> ( ( uiFullDepth + 1 ) << 1 );
891    for( UInt uiPart = 0; uiPart < 4; uiPart++ )
892    {
893      xIntraLumaRecQT( pcCU, uiTrDepth + 1, uiAbsPartIdx + uiPart * uiNumQPart, pcRecoYuv, pcPredYuv, pcResiYuv );
894    }
895  }
896}
897
898/** Function for deriving recontructed PU/CU chroma samples with QTree structure
899 * \param pcCU pointer of current CU
900 * \param uiTrDepth current tranform split depth
901 * \param uiAbsPartIdx  part index
902 * \param pcRecoYuv pointer to reconstructed sample arrays
903 * \param pcPredYuv pointer to prediction sample arrays
904 * \param pcResiYuv pointer to residue sample arrays
905 *
906 \ This function dervies recontructed PU/CU chroma samples with QTree recursive structure
907 */
908Void
909TDecCu::xIntraChromaRecQT( TComDataCU* pcCU,
910                     UInt        uiTrDepth,
911                     UInt        uiAbsPartIdx,
912                     TComYuv*    pcRecoYuv,
913                     TComYuv*    pcPredYuv, 
914                     TComYuv*    pcResiYuv )
915{
916  UInt uiFullDepth  = pcCU->getDepth(0) + uiTrDepth;
917  UInt uiTrMode     = pcCU->getTransformIdx( uiAbsPartIdx );
918  if( uiTrMode == uiTrDepth )
919  {
920    xIntraRecChromaBlk( pcCU, uiTrDepth, uiAbsPartIdx, pcRecoYuv, pcPredYuv, pcResiYuv, 0 );
921    xIntraRecChromaBlk( pcCU, uiTrDepth, uiAbsPartIdx, pcRecoYuv, pcPredYuv, pcResiYuv, 1 );
922  }
923  else
924  {
925    UInt uiNumQPart  = pcCU->getPic()->getNumPartInCU() >> ( ( uiFullDepth + 1 ) << 1 );
926    for( UInt uiPart = 0; uiPart < 4; uiPart++ )
927    {
928      xIntraChromaRecQT( pcCU, uiTrDepth + 1, uiAbsPartIdx + uiPart * uiNumQPart, pcRecoYuv, pcPredYuv, pcResiYuv );
929    }
930  }
931}
932
933Void TDecCu::xCopyToPic( TComDataCU* pcCU, TComPic* pcPic, UInt uiZorderIdx, UInt uiDepth )
934{
935  UInt uiCUAddr = pcCU->getAddr();
936 
937  m_ppcYuvReco[uiDepth]->copyToPicYuv  ( pcPic->getPicYuvRec (), uiCUAddr, uiZorderIdx );
938 
939  return;
940}
941
942Void TDecCu::xDecodeInterTexture ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
943{
944  UInt    uiWidth    = pcCU->getWidth ( uiAbsPartIdx );
945  UInt    uiHeight   = pcCU->getHeight( uiAbsPartIdx );
946  TCoeff* piCoeff;
947 
948  Pel*    pResi;
949  UInt    trMode = pcCU->getTransformIdx( uiAbsPartIdx );
950 
951  // Y
952  piCoeff = pcCU->getCoeffY();
953  pResi = m_ppcYuvResi[uiDepth]->getLumaAddr();
954
955  m_pcTrQuant->setQPforQuant( pcCU->getQP( uiAbsPartIdx ), TEXT_LUMA, pcCU->getSlice()->getSPS()->getQpBDOffsetY(), 0 );
956
957  m_pcTrQuant->invRecurTransformNxN ( pcCU, 0, TEXT_LUMA, pResi, 0, m_ppcYuvResi[uiDepth]->getStride(), uiWidth, uiHeight, trMode, 0, piCoeff );
958 
959  // Cb and Cr
960  Int curChromaQpOffset = pcCU->getSlice()->getPPS()->getChromaCbQpOffset() + pcCU->getSlice()->getSliceQpDeltaCb();
961  m_pcTrQuant->setQPforQuant( pcCU->getQP( uiAbsPartIdx ), TEXT_CHROMA, pcCU->getSlice()->getSPS()->getQpBDOffsetC(), curChromaQpOffset );
962
963  uiWidth  >>= 1;
964  uiHeight >>= 1;
965  piCoeff = pcCU->getCoeffCb(); pResi = m_ppcYuvResi[uiDepth]->getCbAddr();
966  m_pcTrQuant->invRecurTransformNxN ( pcCU, 0, TEXT_CHROMA_U, pResi, 0, m_ppcYuvResi[uiDepth]->getCStride(), uiWidth, uiHeight, trMode, 0, piCoeff );
967
968  curChromaQpOffset = pcCU->getSlice()->getPPS()->getChromaCrQpOffset() + pcCU->getSlice()->getSliceQpDeltaCr();
969  m_pcTrQuant->setQPforQuant( pcCU->getQP( uiAbsPartIdx ), TEXT_CHROMA, pcCU->getSlice()->getSPS()->getQpBDOffsetC(), curChromaQpOffset );
970
971  piCoeff = pcCU->getCoeffCr(); pResi = m_ppcYuvResi[uiDepth]->getCrAddr();
972  m_pcTrQuant->invRecurTransformNxN ( pcCU, 0, TEXT_CHROMA_V, pResi, 0, m_ppcYuvResi[uiDepth]->getCStride(), uiWidth, uiHeight, trMode, 0, piCoeff );
973}
974
975/** Function for deriving reconstructed luma/chroma samples of a PCM mode CU.
976 * \param pcCU pointer to current CU
977 * \param uiPartIdx part index
978 * \param piPCM pointer to PCM code arrays
979 * \param piReco pointer to reconstructed sample arrays
980 * \param uiStride stride of reconstructed sample arrays
981 * \param uiWidth CU width
982 * \param uiHeight CU height
983 * \param ttText texture component type
984 * \returns Void
985 */
986Void TDecCu::xDecodePCMTexture( TComDataCU* pcCU, UInt uiPartIdx, Pel *piPCM, Pel* piReco, UInt uiStride, UInt uiWidth, UInt uiHeight, TextType ttText)
987{
988  UInt uiX, uiY;
989  Pel* piPicReco;
990  UInt uiPicStride;
991  UInt uiPcmLeftShiftBit; 
992
993  if( ttText == TEXT_LUMA )
994  {
995    uiPicStride   = pcCU->getPic()->getPicYuvRec()->getStride();
996    piPicReco = pcCU->getPic()->getPicYuvRec()->getLumaAddr(pcCU->getAddr(), pcCU->getZorderIdxInCU()+uiPartIdx);
997    uiPcmLeftShiftBit = g_bitDepthY - pcCU->getSlice()->getSPS()->getPCMBitDepthLuma();
998  }
999  else
1000  {
1001    uiPicStride = pcCU->getPic()->getPicYuvRec()->getCStride();
1002
1003    if( ttText == TEXT_CHROMA_U )
1004    {
1005      piPicReco = pcCU->getPic()->getPicYuvRec()->getCbAddr(pcCU->getAddr(), pcCU->getZorderIdxInCU()+uiPartIdx);
1006    }
1007    else
1008    {
1009      piPicReco = pcCU->getPic()->getPicYuvRec()->getCrAddr(pcCU->getAddr(), pcCU->getZorderIdxInCU()+uiPartIdx);
1010    }
1011    uiPcmLeftShiftBit = g_bitDepthC - pcCU->getSlice()->getSPS()->getPCMBitDepthChroma();
1012  }
1013
1014  for( uiY = 0; uiY < uiHeight; uiY++ )
1015  {
1016    for( uiX = 0; uiX < uiWidth; uiX++ )
1017    {
1018      piReco[uiX] = (piPCM[uiX] << uiPcmLeftShiftBit);
1019      piPicReco[uiX] = piReco[uiX];
1020    }
1021    piPCM += uiWidth;
1022    piReco += uiStride;
1023    piPicReco += uiPicStride;
1024  }
1025}
1026
1027/** Function for reconstructing a PCM mode CU.
1028 * \param pcCU pointer to current CU
1029 * \param uiDepth CU Depth
1030 * \returns Void
1031 */
1032Void TDecCu::xReconPCM( TComDataCU* pcCU, UInt uiDepth )
1033{
1034  // Luma
1035  UInt uiWidth  = (g_uiMaxCUWidth >> uiDepth);
1036  UInt uiHeight = (g_uiMaxCUHeight >> uiDepth);
1037
1038  Pel* piPcmY = pcCU->getPCMSampleY();
1039  Pel* piRecoY = m_ppcYuvReco[uiDepth]->getLumaAddr(0, uiWidth);
1040
1041  UInt uiStride = m_ppcYuvResi[uiDepth]->getStride();
1042
1043  xDecodePCMTexture( pcCU, 0, piPcmY, piRecoY, uiStride, uiWidth, uiHeight, TEXT_LUMA);
1044
1045  // Cb and Cr
1046  UInt uiCWidth  = (uiWidth>>1);
1047  UInt uiCHeight = (uiHeight>>1);
1048
1049  Pel* piPcmCb = pcCU->getPCMSampleCb();
1050  Pel* piPcmCr = pcCU->getPCMSampleCr();
1051  Pel* pRecoCb = m_ppcYuvReco[uiDepth]->getCbAddr();
1052  Pel* pRecoCr = m_ppcYuvReco[uiDepth]->getCrAddr();
1053
1054  UInt uiCStride = m_ppcYuvReco[uiDepth]->getCStride();
1055
1056  xDecodePCMTexture( pcCU, 0, piPcmCb, pRecoCb, uiCStride, uiCWidth, uiCHeight, TEXT_CHROMA_U);
1057  xDecodePCMTexture( pcCU, 0, piPcmCr, pRecoCr, uiCStride, uiCWidth, uiCHeight, TEXT_CHROMA_V);
1058}
1059
1060/** Function for filling the PCM buffer of a CU using its reconstructed sample array
1061 * \param pcCU pointer to current CU
1062 * \param uiDepth CU Depth
1063 * \returns Void
1064 */
1065Void TDecCu::xFillPCMBuffer(TComDataCU* pCU, UInt depth)
1066{
1067  // Luma
1068  UInt width  = (g_uiMaxCUWidth >> depth);
1069  UInt height = (g_uiMaxCUHeight >> depth);
1070
1071  Pel* pPcmY = pCU->getPCMSampleY();
1072  Pel* pRecoY = m_ppcYuvReco[depth]->getLumaAddr(0, width);
1073
1074  UInt stride = m_ppcYuvReco[depth]->getStride();
1075
1076  for(Int y = 0; y < height; y++ )
1077  {
1078    for(Int x = 0; x < width; x++ )
1079    {
1080      pPcmY[x] = pRecoY[x];
1081    }
1082    pPcmY += width;
1083    pRecoY += stride;
1084  }
1085
1086  // Cb and Cr
1087  UInt widthC  = (width>>1);
1088  UInt heightC = (height>>1);
1089
1090  Pel* pPcmCb = pCU->getPCMSampleCb();
1091  Pel* pPcmCr = pCU->getPCMSampleCr();
1092  Pel* pRecoCb = m_ppcYuvReco[depth]->getCbAddr();
1093  Pel* pRecoCr = m_ppcYuvReco[depth]->getCrAddr();
1094
1095  UInt strideC = m_ppcYuvReco[depth]->getCStride();
1096
1097  for(Int y = 0; y < heightC; y++ )
1098  {
1099    for(Int x = 0; x < widthC; x++ )
1100    {
1101      pPcmCb[x] = pRecoCb[x];
1102      pPcmCr[x] = pRecoCr[x];
1103    }
1104    pPcmCr += widthC;
1105    pPcmCb += widthC;
1106    pRecoCb += strideC;
1107    pRecoCr += strideC;
1108  }
1109
1110}
1111
1112//! \}
Note: See TracBrowser for help on using the repository browser.