source: 3DVCSoftware/branches/HTM-DEV-0.3-dev2/source/Lib/TLibDecoder/TDecCu.cpp @ 521

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

Integrated following changes:

  • H_MV_FIX1071, fix of encoder side reference list construction on IRAP pictures, same as in HM11.
  • H_3D_VSO_FIX_BORDRE_EXTENSION, fixed uninitialized borders for org-yuvs in VSO
  • H_MV_ENC_DEC_TRAC, added cu/pu level trace ( only enabled when ENC_DEC_TRACE is enabled)
  • Property svn:eol-style set to native
File size: 36.0 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
369    m_ppcCU[uiDepth]->getInterMergeCandidates( 0, 0, cMvFieldNeighbours, uhInterDirNeighbours, vspFlag, numValidMergeCand, uiMergeIndex );
370    pcCU->setVSPFlagSubParts( vspFlag[uiMergeIndex], uiAbsPartIdx, 0, uiDepth );
371#else
372    m_ppcCU[uiDepth]->getInterMergeCandidates( 0, 0, cMvFieldNeighbours, uhInterDirNeighbours, numValidMergeCand, uiMergeIndex );
373#endif
374
375    pcCU->setInterDirSubParts( uhInterDirNeighbours[uiMergeIndex], uiAbsPartIdx, 0, uiDepth );
376
377    TComMv cTmpMv( 0, 0 );
378    for ( UInt uiRefListIdx = 0; uiRefListIdx < 2; uiRefListIdx++ )
379    {       
380      if ( pcCU->getSlice()->getNumRefIdx( RefPicList( uiRefListIdx ) ) > 0 )
381      {
382        pcCU->setMVPIdxSubParts( 0, RefPicList( uiRefListIdx ), uiAbsPartIdx, 0, uiDepth);
383        pcCU->setMVPNumSubParts( 0, RefPicList( uiRefListIdx ), uiAbsPartIdx, 0, uiDepth);
384        pcCU->getCUMvField( RefPicList( uiRefListIdx ) )->setAllMvd( cTmpMv, SIZE_2Nx2N, uiAbsPartIdx, uiDepth );
385        pcCU->getCUMvField( RefPicList( uiRefListIdx ) )->setAllMvField( cMvFieldNeighbours[ 2*uiMergeIndex + uiRefListIdx ], SIZE_2Nx2N, uiAbsPartIdx, uiDepth );
386      }
387    }
388#if H_3D_IC
389    m_pcEntropyDecoder->decodeICFlag( pcCU, uiAbsPartIdx, uiDepth );
390#endif
391#if H_3D_ARP
392    m_pcEntropyDecoder->decodeARPW( pcCU , uiAbsPartIdx , uiDepth );
393#endif
394    xFinishDecodeCU( pcCU, uiAbsPartIdx, uiDepth, ruiIsLast );
395    return;
396  }
397
398  m_pcEntropyDecoder->decodePredMode( pcCU, uiAbsPartIdx, uiDepth );
399  m_pcEntropyDecoder->decodePartSize( pcCU, uiAbsPartIdx, uiDepth );
400
401  if (pcCU->isIntra( uiAbsPartIdx ) && pcCU->getPartitionSize( uiAbsPartIdx ) == SIZE_2Nx2N )
402  {
403    m_pcEntropyDecoder->decodeIPCMInfo( pcCU, uiAbsPartIdx, uiDepth );
404
405    if(pcCU->getIPCMFlag(uiAbsPartIdx))
406    {
407      xFinishDecodeCU( pcCU, uiAbsPartIdx, uiDepth, ruiIsLast );
408      return;
409    }
410  }
411
412  UInt uiCurrWidth      = pcCU->getWidth ( uiAbsPartIdx );
413  UInt uiCurrHeight     = pcCU->getHeight( uiAbsPartIdx );
414 
415  // prediction mode ( Intra : direction mode, Inter : Mv, reference idx )
416  m_pcEntropyDecoder->decodePredInfo( pcCU, uiAbsPartIdx, uiDepth, m_ppcCU[uiDepth]);
417#if H_3D_IC
418  m_pcEntropyDecoder->decodeICFlag( pcCU, uiAbsPartIdx, uiDepth );
419#endif
420#if H_3D_ARP
421  m_pcEntropyDecoder->decodeARPW    ( pcCU , uiAbsPartIdx , uiDepth ); 
422#endif 
423  // Coefficient decoding
424  Bool bCodeDQP = getdQPFlag();
425  m_pcEntropyDecoder->decodeCoeff( pcCU, uiAbsPartIdx, uiDepth, uiCurrWidth, uiCurrHeight, bCodeDQP );
426  setdQPFlag( bCodeDQP );
427  xFinishDecodeCU( pcCU, uiAbsPartIdx, uiDepth, ruiIsLast );
428}
429
430Void TDecCu::xFinishDecodeCU( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, UInt& ruiIsLast)
431{
432  if(  pcCU->getSlice()->getPPS()->getUseDQP())
433  {
434    pcCU->setQPSubParts( getdQPFlag()?pcCU->getRefQP(uiAbsPartIdx):pcCU->getCodedQP(), uiAbsPartIdx, uiDepth ); // set QP
435  }
436
437  ruiIsLast = xDecodeSliceEnd( pcCU, uiAbsPartIdx, uiDepth);
438}
439
440Void TDecCu::xDecompressCU( TComDataCU* pcCU, UInt uiAbsPartIdx,  UInt uiDepth )
441{
442  TComPic* pcPic = pcCU->getPic();
443 
444  Bool bBoundary = false;
445  UInt uiLPelX   = pcCU->getCUPelX() + g_auiRasterToPelX[ g_auiZscanToRaster[uiAbsPartIdx] ];
446  UInt uiRPelX   = uiLPelX + (g_uiMaxCUWidth>>uiDepth)  - 1;
447  UInt uiTPelY   = pcCU->getCUPelY() + g_auiRasterToPelY[ g_auiZscanToRaster[uiAbsPartIdx] ];
448  UInt uiBPelY   = uiTPelY + (g_uiMaxCUHeight>>uiDepth) - 1;
449 
450  UInt uiCurNumParts    = pcPic->getNumPartInCU() >> (uiDepth<<1);
451  TComSlice * pcSlice = pcCU->getPic()->getSlice(pcCU->getPic()->getCurrSliceIdx());
452  Bool bStartInCU = pcCU->getSCUAddr()+uiAbsPartIdx+uiCurNumParts>pcSlice->getSliceSegmentCurStartCUAddr()&&pcCU->getSCUAddr()+uiAbsPartIdx<pcSlice->getSliceSegmentCurStartCUAddr();
453  if(bStartInCU||( uiRPelX >= pcSlice->getSPS()->getPicWidthInLumaSamples() ) || ( uiBPelY >= pcSlice->getSPS()->getPicHeightInLumaSamples() ) )
454  {
455    bBoundary = true;
456  }
457 
458  if( ( ( uiDepth < pcCU->getDepth( uiAbsPartIdx ) ) && ( uiDepth < g_uiMaxCUDepth - g_uiAddCUDepth ) ) || bBoundary )
459  {
460    UInt uiNextDepth = uiDepth + 1;
461    UInt uiQNumParts = pcCU->getTotalNumPart() >> (uiNextDepth<<1);
462    UInt uiIdx = uiAbsPartIdx;
463    for ( UInt uiPartIdx = 0; uiPartIdx < 4; uiPartIdx++ )
464    {
465      uiLPelX = pcCU->getCUPelX() + g_auiRasterToPelX[ g_auiZscanToRaster[uiIdx] ];
466      uiTPelY = pcCU->getCUPelY() + g_auiRasterToPelY[ g_auiZscanToRaster[uiIdx] ];
467     
468      Bool binSlice = (pcCU->getSCUAddr()+uiIdx+uiQNumParts>pcSlice->getSliceSegmentCurStartCUAddr())&&(pcCU->getSCUAddr()+uiIdx<pcSlice->getSliceSegmentCurEndCUAddr());
469      if(binSlice&&( uiLPelX < pcSlice->getSPS()->getPicWidthInLumaSamples() ) && ( uiTPelY < pcSlice->getSPS()->getPicHeightInLumaSamples() ) )
470      {
471        xDecompressCU(pcCU, uiIdx, uiNextDepth );
472      }
473     
474      uiIdx += uiQNumParts;
475    }
476    return;
477  }
478 
479  // Residual reconstruction
480  m_ppcYuvResi[uiDepth]->clear();
481 
482  m_ppcCU[uiDepth]->copySubCU( pcCU, uiAbsPartIdx, uiDepth );
483 
484  switch( m_ppcCU[uiDepth]->getPredictionMode(0) )
485  {
486    case MODE_INTER:
487      xReconInter( m_ppcCU[uiDepth], uiDepth );
488      break;
489    case MODE_INTRA:
490      xReconIntraQT( m_ppcCU[uiDepth], uiDepth );
491      break;
492    default:
493      assert(0);
494      break;
495  }
496  if ( m_ppcCU[uiDepth]->isLosslessCoded(0) && (m_ppcCU[uiDepth]->getIPCMFlag(0) == false))
497  {
498    xFillPCMBuffer(m_ppcCU[uiDepth], uiDepth);
499  }
500 
501  xCopyToPic( m_ppcCU[uiDepth], pcPic, uiAbsPartIdx, uiDepth );
502}
503
504Void TDecCu::xReconInter( TComDataCU* pcCU, UInt uiDepth )
505{
506 
507  // inter prediction
508  m_pcPrediction->motionCompensation( pcCU, m_ppcYuvReco[uiDepth] );
509 
510  // inter recon
511  xDecodeInterTexture( pcCU, 0, uiDepth );
512 
513  // clip for only non-zero cbp case
514  if  ( ( pcCU->getCbf( 0, TEXT_LUMA ) ) || ( pcCU->getCbf( 0, TEXT_CHROMA_U ) ) || ( pcCU->getCbf(0, TEXT_CHROMA_V ) ) )
515  {
516    m_ppcYuvReco[uiDepth]->addClip( m_ppcYuvReco[uiDepth], m_ppcYuvResi[uiDepth], 0, pcCU->getWidth( 0 ) );
517  }
518  else
519  {
520    m_ppcYuvReco[uiDepth]->copyPartToPartYuv( m_ppcYuvReco[uiDepth],0, pcCU->getWidth( 0 ),pcCU->getHeight( 0 ));
521  }
522}
523
524Void
525TDecCu::xIntraRecLumaBlk( TComDataCU* pcCU,
526                         UInt        uiTrDepth,
527                         UInt        uiAbsPartIdx,
528                         TComYuv*    pcRecoYuv,
529                         TComYuv*    pcPredYuv, 
530                         TComYuv*    pcResiYuv )
531{
532  UInt    uiWidth           = pcCU     ->getWidth   ( 0 ) >> uiTrDepth;
533  UInt    uiHeight          = pcCU     ->getHeight  ( 0 ) >> uiTrDepth;
534  UInt    uiStride          = pcRecoYuv->getStride  ();
535  Pel*    piReco            = pcRecoYuv->getLumaAddr( uiAbsPartIdx );
536  Pel*    piPred            = pcPredYuv->getLumaAddr( uiAbsPartIdx );
537  Pel*    piResi            = pcResiYuv->getLumaAddr( uiAbsPartIdx );
538 
539  UInt    uiNumCoeffInc     = ( pcCU->getSlice()->getSPS()->getMaxCUWidth() * pcCU->getSlice()->getSPS()->getMaxCUHeight() ) >> ( pcCU->getSlice()->getSPS()->getMaxCUDepth() << 1 );
540  TCoeff* pcCoeff           = pcCU->getCoeffY() + ( uiNumCoeffInc * uiAbsPartIdx );
541 
542  UInt    uiLumaPredMode    = pcCU->getLumaIntraDir     ( uiAbsPartIdx );
543 
544  UInt    uiZOrder          = pcCU->getZorderIdxInCU() + uiAbsPartIdx;
545  Pel*    piRecIPred        = pcCU->getPic()->getPicYuvRec()->getLumaAddr( pcCU->getAddr(), uiZOrder );
546  UInt    uiRecIPredStride  = pcCU->getPic()->getPicYuvRec()->getStride  ();
547  Bool    useTransformSkip  = pcCU->getTransformSkip(uiAbsPartIdx, TEXT_LUMA);
548  //===== init availability pattern =====
549  Bool  bAboveAvail = false;
550  Bool  bLeftAvail  = false;
551  pcCU->getPattern()->initPattern   ( pcCU, uiTrDepth, uiAbsPartIdx );
552  pcCU->getPattern()->initAdiPattern( pcCU, uiAbsPartIdx, uiTrDepth, 
553                                     m_pcPrediction->getPredicBuf       (),
554                                     m_pcPrediction->getPredicBufWidth  (),
555                                     m_pcPrediction->getPredicBufHeight (),
556                                     bAboveAvail, bLeftAvail );
557 
558  //===== get prediction signal =====
559  m_pcPrediction->predIntraLumaAng( pcCU->getPattern(), uiLumaPredMode, piPred, uiStride, uiWidth, uiHeight, bAboveAvail, bLeftAvail );
560 
561  //===== inverse transform =====
562  m_pcTrQuant->setQPforQuant  ( pcCU->getQP(0), TEXT_LUMA, pcCU->getSlice()->getSPS()->getQpBDOffsetY(), 0 );
563
564  Int scalingListType = (pcCU->isIntra(uiAbsPartIdx) ? 0 : 3) + g_eTTable[(Int)TEXT_LUMA];
565  assert(scalingListType < 6);
566  m_pcTrQuant->invtransformNxN( pcCU->getCUTransquantBypass(uiAbsPartIdx), TEXT_LUMA, pcCU->getLumaIntraDir( uiAbsPartIdx ), piResi, uiStride, pcCoeff, uiWidth, uiHeight, scalingListType, useTransformSkip );
567
568 
569  //===== reconstruction =====
570  Pel* pPred      = piPred;
571  Pel* pResi      = piResi;
572  Pel* pReco      = piReco;
573  Pel* pRecIPred  = piRecIPred;
574  for( UInt uiY = 0; uiY < uiHeight; uiY++ )
575  {
576    for( UInt uiX = 0; uiX < uiWidth; uiX++ )
577    {
578      pReco    [ uiX ] = ClipY( pPred[ uiX ] + pResi[ uiX ] );
579      pRecIPred[ uiX ] = pReco[ uiX ];
580    }
581    pPred     += uiStride;
582    pResi     += uiStride;
583    pReco     += uiStride;
584    pRecIPred += uiRecIPredStride;
585  }
586}
587
588
589Void
590TDecCu::xIntraRecChromaBlk( TComDataCU* pcCU,
591                           UInt        uiTrDepth,
592                           UInt        uiAbsPartIdx,
593                           TComYuv*    pcRecoYuv,
594                           TComYuv*    pcPredYuv, 
595                           TComYuv*    pcResiYuv,
596                           UInt        uiChromaId )
597{
598  UInt uiFullDepth  = pcCU->getDepth( 0 ) + uiTrDepth;
599  UInt uiLog2TrSize = g_aucConvertToBit[ pcCU->getSlice()->getSPS()->getMaxCUWidth() >> uiFullDepth ] + 2;
600
601  if( uiLog2TrSize == 2 )
602  {
603    assert( uiTrDepth > 0 );
604    uiTrDepth--;
605    UInt uiQPDiv = pcCU->getPic()->getNumPartInCU() >> ( ( pcCU->getDepth( 0 ) + uiTrDepth ) << 1 );
606    Bool bFirstQ = ( ( uiAbsPartIdx % uiQPDiv ) == 0 );
607    if( !bFirstQ )
608    {
609      return;
610    }
611  }
612 
613  TextType  eText             = ( uiChromaId > 0 ? TEXT_CHROMA_V : TEXT_CHROMA_U );
614  UInt      uiWidth           = pcCU     ->getWidth   ( 0 ) >> ( uiTrDepth + 1 );
615  UInt      uiHeight          = pcCU     ->getHeight  ( 0 ) >> ( uiTrDepth + 1 );
616  UInt      uiStride          = pcRecoYuv->getCStride ();
617  Pel*      piReco            = ( uiChromaId > 0 ? pcRecoYuv->getCrAddr( uiAbsPartIdx ) : pcRecoYuv->getCbAddr( uiAbsPartIdx ) );
618  Pel*      piPred            = ( uiChromaId > 0 ? pcPredYuv->getCrAddr( uiAbsPartIdx ) : pcPredYuv->getCbAddr( uiAbsPartIdx ) );
619  Pel*      piResi            = ( uiChromaId > 0 ? pcResiYuv->getCrAddr( uiAbsPartIdx ) : pcResiYuv->getCbAddr( uiAbsPartIdx ) );
620 
621  UInt      uiNumCoeffInc     = ( ( pcCU->getSlice()->getSPS()->getMaxCUWidth() * pcCU->getSlice()->getSPS()->getMaxCUHeight() ) >> ( pcCU->getSlice()->getSPS()->getMaxCUDepth() << 1 ) ) >> 2;
622  TCoeff*   pcCoeff           = ( uiChromaId > 0 ? pcCU->getCoeffCr() : pcCU->getCoeffCb() ) + ( uiNumCoeffInc * uiAbsPartIdx );
623 
624  UInt      uiChromaPredMode  = pcCU->getChromaIntraDir( 0 );
625 
626  UInt      uiZOrder          = pcCU->getZorderIdxInCU() + uiAbsPartIdx;
627  Pel*      piRecIPred        = ( uiChromaId > 0 ? pcCU->getPic()->getPicYuvRec()->getCrAddr( pcCU->getAddr(), uiZOrder ) : pcCU->getPic()->getPicYuvRec()->getCbAddr( pcCU->getAddr(), uiZOrder ) );
628  UInt      uiRecIPredStride  = pcCU->getPic()->getPicYuvRec()->getCStride();
629  Bool      useTransformSkipChroma = pcCU->getTransformSkip(uiAbsPartIdx,eText);
630  //===== init availability pattern =====
631  Bool  bAboveAvail = false;
632  Bool  bLeftAvail  = false;
633  pcCU->getPattern()->initPattern         ( pcCU, uiTrDepth, uiAbsPartIdx );
634
635  pcCU->getPattern()->initAdiPatternChroma( pcCU, uiAbsPartIdx, uiTrDepth,
636                                           m_pcPrediction->getPredicBuf       (),
637                                           m_pcPrediction->getPredicBufWidth  (),
638                                           m_pcPrediction->getPredicBufHeight (),
639                                           bAboveAvail, bLeftAvail );
640  Int* pPatChroma   = ( uiChromaId > 0 ? pcCU->getPattern()->getAdiCrBuf( uiWidth, uiHeight, m_pcPrediction->getPredicBuf() ) : pcCU->getPattern()->getAdiCbBuf( uiWidth, uiHeight, m_pcPrediction->getPredicBuf() ) );
641 
642  //===== get prediction signal =====
643  {
644    if( uiChromaPredMode == DM_CHROMA_IDX )
645    {
646      uiChromaPredMode = pcCU->getLumaIntraDir( 0 );
647    }
648    m_pcPrediction->predIntraChromaAng( pPatChroma, uiChromaPredMode, piPred, uiStride, uiWidth, uiHeight, bAboveAvail, bLeftAvail ); 
649  }
650
651  //===== inverse transform =====
652  Int curChromaQpOffset;
653  if(eText == TEXT_CHROMA_U)
654  {
655    curChromaQpOffset = pcCU->getSlice()->getPPS()->getChromaCbQpOffset() + pcCU->getSlice()->getSliceQpDeltaCb();
656  }
657  else
658  {
659    curChromaQpOffset = pcCU->getSlice()->getPPS()->getChromaCrQpOffset() + pcCU->getSlice()->getSliceQpDeltaCr();
660  }
661  m_pcTrQuant->setQPforQuant  ( pcCU->getQP(0), eText, pcCU->getSlice()->getSPS()->getQpBDOffsetC(), curChromaQpOffset );
662
663  Int scalingListType = (pcCU->isIntra(uiAbsPartIdx) ? 0 : 3) + g_eTTable[(Int)eText];
664  assert(scalingListType < 6);
665  m_pcTrQuant->invtransformNxN( pcCU->getCUTransquantBypass(uiAbsPartIdx), eText, REG_DCT, piResi, uiStride, pcCoeff, uiWidth, uiHeight, scalingListType, useTransformSkipChroma );
666
667  //===== reconstruction =====
668  Pel* pPred      = piPred;
669  Pel* pResi      = piResi;
670  Pel* pReco      = piReco;
671  Pel* pRecIPred  = piRecIPred;
672  for( UInt uiY = 0; uiY < uiHeight; uiY++ )
673  {
674    for( UInt uiX = 0; uiX < uiWidth; uiX++ )
675    {
676      pReco    [ uiX ] = ClipC( pPred[ uiX ] + pResi[ uiX ] );
677      pRecIPred[ uiX ] = pReco[ uiX ];
678    }
679    pPred     += uiStride;
680    pResi     += uiStride;
681    pReco     += uiStride;
682    pRecIPred += uiRecIPredStride;
683  }
684}
685
686
687Void
688TDecCu::xReconIntraQT( TComDataCU* pcCU, UInt uiDepth )
689{
690  UInt  uiInitTrDepth = ( pcCU->getPartitionSize(0) == SIZE_2Nx2N ? 0 : 1 );
691  UInt  uiNumPart     = pcCU->getNumPartInter();
692  UInt  uiNumQParts   = pcCU->getTotalNumPart() >> 2;
693 
694  if (pcCU->getIPCMFlag(0))
695  {
696    xReconPCM( pcCU, uiDepth );
697    return;
698  }
699
700  for( UInt uiPU = 0; uiPU < uiNumPart; uiPU++ )
701  {
702    xIntraLumaRecQT( pcCU, uiInitTrDepth, uiPU * uiNumQParts, m_ppcYuvReco[uiDepth], m_ppcYuvReco[uiDepth], m_ppcYuvResi[uiDepth] );
703  } 
704
705  for( UInt uiPU = 0; uiPU < uiNumPart; uiPU++ )
706  {
707    xIntraChromaRecQT( pcCU, uiInitTrDepth, uiPU * uiNumQParts, m_ppcYuvReco[uiDepth], m_ppcYuvReco[uiDepth], m_ppcYuvResi[uiDepth] );
708  }
709
710}
711
712/** Function for deriving recontructed PU/CU Luma sample with QTree structure
713 * \param pcCU pointer of current CU
714 * \param uiTrDepth current tranform split depth
715 * \param uiAbsPartIdx  part index
716 * \param pcRecoYuv pointer to reconstructed sample arrays
717 * \param pcPredYuv pointer to prediction sample arrays
718 * \param pcResiYuv pointer to residue sample arrays
719 *
720 \ This function dervies recontructed PU/CU Luma sample with recursive QTree structure
721 */
722Void
723TDecCu::xIntraLumaRecQT( TComDataCU* pcCU,
724                     UInt        uiTrDepth,
725                     UInt        uiAbsPartIdx,
726                     TComYuv*    pcRecoYuv,
727                     TComYuv*    pcPredYuv, 
728                     TComYuv*    pcResiYuv )
729{
730  UInt uiFullDepth  = pcCU->getDepth(0) + uiTrDepth;
731  UInt uiTrMode     = pcCU->getTransformIdx( uiAbsPartIdx );
732  if( uiTrMode == uiTrDepth )
733  {
734    xIntraRecLumaBlk  ( pcCU, uiTrDepth, uiAbsPartIdx, pcRecoYuv, pcPredYuv, pcResiYuv );
735  }
736  else
737  {
738    UInt uiNumQPart  = pcCU->getPic()->getNumPartInCU() >> ( ( uiFullDepth + 1 ) << 1 );
739    for( UInt uiPart = 0; uiPart < 4; uiPart++ )
740    {
741      xIntraLumaRecQT( pcCU, uiTrDepth + 1, uiAbsPartIdx + uiPart * uiNumQPart, pcRecoYuv, pcPredYuv, pcResiYuv );
742    }
743  }
744}
745
746/** Function for deriving recontructed PU/CU chroma samples with QTree structure
747 * \param pcCU pointer of current CU
748 * \param uiTrDepth current tranform split depth
749 * \param uiAbsPartIdx  part index
750 * \param pcRecoYuv pointer to reconstructed sample arrays
751 * \param pcPredYuv pointer to prediction sample arrays
752 * \param pcResiYuv pointer to residue sample arrays
753 *
754 \ This function dervies recontructed PU/CU chroma samples with QTree recursive structure
755 */
756Void
757TDecCu::xIntraChromaRecQT( TComDataCU* pcCU,
758                     UInt        uiTrDepth,
759                     UInt        uiAbsPartIdx,
760                     TComYuv*    pcRecoYuv,
761                     TComYuv*    pcPredYuv, 
762                     TComYuv*    pcResiYuv )
763{
764  UInt uiFullDepth  = pcCU->getDepth(0) + uiTrDepth;
765  UInt uiTrMode     = pcCU->getTransformIdx( uiAbsPartIdx );
766  if( uiTrMode == uiTrDepth )
767  {
768    xIntraRecChromaBlk( pcCU, uiTrDepth, uiAbsPartIdx, pcRecoYuv, pcPredYuv, pcResiYuv, 0 );
769    xIntraRecChromaBlk( pcCU, uiTrDepth, uiAbsPartIdx, pcRecoYuv, pcPredYuv, pcResiYuv, 1 );
770  }
771  else
772  {
773    UInt uiNumQPart  = pcCU->getPic()->getNumPartInCU() >> ( ( uiFullDepth + 1 ) << 1 );
774    for( UInt uiPart = 0; uiPart < 4; uiPart++ )
775    {
776      xIntraChromaRecQT( pcCU, uiTrDepth + 1, uiAbsPartIdx + uiPart * uiNumQPart, pcRecoYuv, pcPredYuv, pcResiYuv );
777    }
778  }
779}
780
781Void TDecCu::xCopyToPic( TComDataCU* pcCU, TComPic* pcPic, UInt uiZorderIdx, UInt uiDepth )
782{
783  UInt uiCUAddr = pcCU->getAddr();
784 
785  m_ppcYuvReco[uiDepth]->copyToPicYuv  ( pcPic->getPicYuvRec (), uiCUAddr, uiZorderIdx );
786 
787  return;
788}
789
790Void TDecCu::xDecodeInterTexture ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
791{
792  UInt    uiWidth    = pcCU->getWidth ( uiAbsPartIdx );
793  UInt    uiHeight   = pcCU->getHeight( uiAbsPartIdx );
794  TCoeff* piCoeff;
795 
796  Pel*    pResi;
797  UInt    trMode = pcCU->getTransformIdx( uiAbsPartIdx );
798 
799  // Y
800  piCoeff = pcCU->getCoeffY();
801  pResi = m_ppcYuvResi[uiDepth]->getLumaAddr();
802
803  m_pcTrQuant->setQPforQuant( pcCU->getQP( uiAbsPartIdx ), TEXT_LUMA, pcCU->getSlice()->getSPS()->getQpBDOffsetY(), 0 );
804
805  m_pcTrQuant->invRecurTransformNxN ( pcCU, 0, TEXT_LUMA, pResi, 0, m_ppcYuvResi[uiDepth]->getStride(), uiWidth, uiHeight, trMode, 0, piCoeff );
806 
807  // Cb and Cr
808  Int curChromaQpOffset = pcCU->getSlice()->getPPS()->getChromaCbQpOffset() + pcCU->getSlice()->getSliceQpDeltaCb();
809  m_pcTrQuant->setQPforQuant( pcCU->getQP( uiAbsPartIdx ), TEXT_CHROMA, pcCU->getSlice()->getSPS()->getQpBDOffsetC(), curChromaQpOffset );
810
811  uiWidth  >>= 1;
812  uiHeight >>= 1;
813  piCoeff = pcCU->getCoeffCb(); pResi = m_ppcYuvResi[uiDepth]->getCbAddr();
814  m_pcTrQuant->invRecurTransformNxN ( pcCU, 0, TEXT_CHROMA_U, pResi, 0, m_ppcYuvResi[uiDepth]->getCStride(), uiWidth, uiHeight, trMode, 0, piCoeff );
815
816  curChromaQpOffset = pcCU->getSlice()->getPPS()->getChromaCrQpOffset() + pcCU->getSlice()->getSliceQpDeltaCr();
817  m_pcTrQuant->setQPforQuant( pcCU->getQP( uiAbsPartIdx ), TEXT_CHROMA, pcCU->getSlice()->getSPS()->getQpBDOffsetC(), curChromaQpOffset );
818
819  piCoeff = pcCU->getCoeffCr(); pResi = m_ppcYuvResi[uiDepth]->getCrAddr();
820  m_pcTrQuant->invRecurTransformNxN ( pcCU, 0, TEXT_CHROMA_V, pResi, 0, m_ppcYuvResi[uiDepth]->getCStride(), uiWidth, uiHeight, trMode, 0, piCoeff );
821}
822
823/** Function for deriving reconstructed luma/chroma samples of a PCM mode CU.
824 * \param pcCU pointer to current CU
825 * \param uiPartIdx part index
826 * \param piPCM pointer to PCM code arrays
827 * \param piReco pointer to reconstructed sample arrays
828 * \param uiStride stride of reconstructed sample arrays
829 * \param uiWidth CU width
830 * \param uiHeight CU height
831 * \param ttText texture component type
832 * \returns Void
833 */
834Void TDecCu::xDecodePCMTexture( TComDataCU* pcCU, UInt uiPartIdx, Pel *piPCM, Pel* piReco, UInt uiStride, UInt uiWidth, UInt uiHeight, TextType ttText)
835{
836  UInt uiX, uiY;
837  Pel* piPicReco;
838  UInt uiPicStride;
839  UInt uiPcmLeftShiftBit; 
840
841  if( ttText == TEXT_LUMA )
842  {
843    uiPicStride   = pcCU->getPic()->getPicYuvRec()->getStride();
844    piPicReco = pcCU->getPic()->getPicYuvRec()->getLumaAddr(pcCU->getAddr(), pcCU->getZorderIdxInCU()+uiPartIdx);
845    uiPcmLeftShiftBit = g_bitDepthY - pcCU->getSlice()->getSPS()->getPCMBitDepthLuma();
846  }
847  else
848  {
849    uiPicStride = pcCU->getPic()->getPicYuvRec()->getCStride();
850
851    if( ttText == TEXT_CHROMA_U )
852    {
853      piPicReco = pcCU->getPic()->getPicYuvRec()->getCbAddr(pcCU->getAddr(), pcCU->getZorderIdxInCU()+uiPartIdx);
854    }
855    else
856    {
857      piPicReco = pcCU->getPic()->getPicYuvRec()->getCrAddr(pcCU->getAddr(), pcCU->getZorderIdxInCU()+uiPartIdx);
858    }
859    uiPcmLeftShiftBit = g_bitDepthC - pcCU->getSlice()->getSPS()->getPCMBitDepthChroma();
860  }
861
862  for( uiY = 0; uiY < uiHeight; uiY++ )
863  {
864    for( uiX = 0; uiX < uiWidth; uiX++ )
865    {
866      piReco[uiX] = (piPCM[uiX] << uiPcmLeftShiftBit);
867      piPicReco[uiX] = piReco[uiX];
868    }
869    piPCM += uiWidth;
870    piReco += uiStride;
871    piPicReco += uiPicStride;
872  }
873}
874
875/** Function for reconstructing a PCM mode CU.
876 * \param pcCU pointer to current CU
877 * \param uiDepth CU Depth
878 * \returns Void
879 */
880Void TDecCu::xReconPCM( TComDataCU* pcCU, UInt uiDepth )
881{
882  // Luma
883  UInt uiWidth  = (g_uiMaxCUWidth >> uiDepth);
884  UInt uiHeight = (g_uiMaxCUHeight >> uiDepth);
885
886  Pel* piPcmY = pcCU->getPCMSampleY();
887  Pel* piRecoY = m_ppcYuvReco[uiDepth]->getLumaAddr(0, uiWidth);
888
889  UInt uiStride = m_ppcYuvResi[uiDepth]->getStride();
890
891  xDecodePCMTexture( pcCU, 0, piPcmY, piRecoY, uiStride, uiWidth, uiHeight, TEXT_LUMA);
892
893  // Cb and Cr
894  UInt uiCWidth  = (uiWidth>>1);
895  UInt uiCHeight = (uiHeight>>1);
896
897  Pel* piPcmCb = pcCU->getPCMSampleCb();
898  Pel* piPcmCr = pcCU->getPCMSampleCr();
899  Pel* pRecoCb = m_ppcYuvReco[uiDepth]->getCbAddr();
900  Pel* pRecoCr = m_ppcYuvReco[uiDepth]->getCrAddr();
901
902  UInt uiCStride = m_ppcYuvReco[uiDepth]->getCStride();
903
904  xDecodePCMTexture( pcCU, 0, piPcmCb, pRecoCb, uiCStride, uiCWidth, uiCHeight, TEXT_CHROMA_U);
905  xDecodePCMTexture( pcCU, 0, piPcmCr, pRecoCr, uiCStride, uiCWidth, uiCHeight, TEXT_CHROMA_V);
906}
907
908/** Function for filling the PCM buffer of a CU using its reconstructed sample array
909 * \param pcCU pointer to current CU
910 * \param uiDepth CU Depth
911 * \returns Void
912 */
913Void TDecCu::xFillPCMBuffer(TComDataCU* pCU, UInt depth)
914{
915  // Luma
916  UInt width  = (g_uiMaxCUWidth >> depth);
917  UInt height = (g_uiMaxCUHeight >> depth);
918
919  Pel* pPcmY = pCU->getPCMSampleY();
920  Pel* pRecoY = m_ppcYuvReco[depth]->getLumaAddr(0, width);
921
922  UInt stride = m_ppcYuvReco[depth]->getStride();
923
924  for(Int y = 0; y < height; y++ )
925  {
926    for(Int x = 0; x < width; x++ )
927    {
928      pPcmY[x] = pRecoY[x];
929    }
930    pPcmY += width;
931    pRecoY += stride;
932  }
933
934  // Cb and Cr
935  UInt widthC  = (width>>1);
936  UInt heightC = (height>>1);
937
938  Pel* pPcmCb = pCU->getPCMSampleCb();
939  Pel* pPcmCr = pCU->getPCMSampleCr();
940  Pel* pRecoCb = m_ppcYuvReco[depth]->getCbAddr();
941  Pel* pRecoCr = m_ppcYuvReco[depth]->getCrAddr();
942
943  UInt strideC = m_ppcYuvReco[depth]->getCStride();
944
945  for(Int y = 0; y < heightC; y++ )
946  {
947    for(Int x = 0; x < widthC; x++ )
948    {
949      pPcmCb[x] = pRecoCb[x];
950      pPcmCr[x] = pRecoCr[x];
951    }
952    pPcmCr += widthC;
953    pPcmCb += widthC;
954    pRecoCb += strideC;
955    pRecoCr += strideC;
956  }
957
958}
959
960//! \}
Note: See TracBrowser for help on using the repository browser.