source: 3DVCSoftware/branches/HTM-8.2-dev2-Samsung/source/Lib/TLibDecoder/TDecEntropy.cpp

Last change on this file was 690, checked in by lg, 11 years ago

Integration of "Removal of redundancy on VSP, ARP and IC"
FJCT3V-F0104
MACRO "LGE_SHARP_VSP_INHERIT_F0104"

By Taesup Kim (taesup.kim@…)

  • Property svn:eol-style set to native
File size: 25.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     TDecEntropy.cpp
35    \brief    entropy decoder class
36*/
37
38#include "TDecEntropy.h"
39
40//! \ingroup TLibDecoder
41//! \{
42
43Void TDecEntropy::setEntropyDecoder         ( TDecEntropyIf* p )
44{
45  m_pcEntropyDecoderIf = p;
46}
47
48#include "TLibCommon/TComSampleAdaptiveOffset.h"
49
50Void TDecEntropy::decodeSkipFlag( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
51{
52  m_pcEntropyDecoderIf->parseSkipFlag( pcCU, uiAbsPartIdx, uiDepth );
53}
54
55Void TDecEntropy::decodeCUTransquantBypassFlag(TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
56{
57  m_pcEntropyDecoderIf->parseCUTransquantBypassFlag( pcCU, uiAbsPartIdx, uiDepth );
58}
59
60/** decode merge flag
61 * \param pcSubCU
62 * \param uiAbsPartIdx
63 * \param uiDepth
64 * \param uiPUIdx
65 * \returns Void
66 */
67Void TDecEntropy::decodeMergeFlag( TComDataCU* pcSubCU, UInt uiAbsPartIdx, UInt uiDepth, UInt uiPUIdx )
68{ 
69  // at least one merge candidate exists
70  m_pcEntropyDecoderIf->parseMergeFlag( pcSubCU, uiAbsPartIdx, uiDepth, uiPUIdx );
71}
72
73/** decode merge index
74 * \param pcCU
75 * \param uiPartIdx
76 * \param uiAbsPartIdx
77 * \param puhInterDirNeighbours pointer to list of inter direction from the casual neighbours
78 * \param pcMvFieldNeighbours pointer to list of motion vector field from the casual neighbours
79 * \param uiDepth
80 * \returns Void
81 */
82Void TDecEntropy::decodeMergeIndex( TComDataCU* pcCU, UInt uiPartIdx, UInt uiAbsPartIdx, UInt uiDepth )
83{
84  UInt uiMergeIndex = 0;
85  m_pcEntropyDecoderIf->parseMergeIndex( pcCU, uiMergeIndex );
86  pcCU->setMergeIndexSubParts( uiMergeIndex, uiAbsPartIdx, uiPartIdx, uiDepth );
87}
88
89#if H_3D_ARP
90Void TDecEntropy::decodeARPW( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
91{
92  if( !pcCU->getSlice()->getARPStepNum() || pcCU->isIntra( uiAbsPartIdx ) )
93  {
94    return;
95  }
96
97  if( pcCU->getPartitionSize(uiAbsPartIdx) != SIZE_2Nx2N )
98  {
99    pcCU->setARPWSubParts( 0 , uiAbsPartIdx, uiDepth );
100  }
101  else
102  {
103    m_pcEntropyDecoderIf->parseARPW( pcCU , uiAbsPartIdx , uiDepth );
104  }
105}
106#endif
107
108#if H_3D_IC
109Void TDecEntropy::decodeICFlag( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
110{
111  pcCU->setICFlagSubParts( false , uiAbsPartIdx, 0, uiDepth );
112
113  if ( pcCU->isIntra( uiAbsPartIdx ) || ( pcCU->getSlice()->getViewIndex() == 0 ) )
114  {
115    return;
116  }
117
118  if( !pcCU->getSlice()->getApplyIC() )
119    return;
120
121  if( pcCU->isICFlagRequired( uiAbsPartIdx ) )
122    m_pcEntropyDecoderIf->parseICFlag( pcCU, uiAbsPartIdx, uiDepth );
123}
124#endif
125
126Void TDecEntropy::decodeSplitFlag   ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
127{
128  m_pcEntropyDecoderIf->parseSplitFlag( pcCU, uiAbsPartIdx, uiDepth );
129}
130
131Void TDecEntropy::decodePredMode( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
132{
133  m_pcEntropyDecoderIf->parsePredMode( pcCU, uiAbsPartIdx, uiDepth );
134}
135
136Void TDecEntropy::decodePartSize( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
137{
138  m_pcEntropyDecoderIf->parsePartSize( pcCU, uiAbsPartIdx, uiDepth );
139}
140
141Void TDecEntropy::decodePredInfo    ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, TComDataCU* pcSubCU )
142{
143  if( pcCU->isIntra( uiAbsPartIdx ) )                                 // If it is Intra mode, encode intra prediction mode.
144  {
145    decodeIntraDirModeLuma  ( pcCU, uiAbsPartIdx, uiDepth );
146#if H_3D_DIM_SDC
147    if(!pcCU->getSDCFlag(uiAbsPartIdx))
148#endif
149    decodeIntraDirModeChroma( pcCU, uiAbsPartIdx, uiDepth );
150  }
151  else                                                                // if it is Inter mode, encode motion vector and reference index
152  {
153    decodePUWise( pcCU, uiAbsPartIdx, uiDepth, pcSubCU );
154  }
155}
156
157/** Parse I_PCM information.
158 * \param pcCU  pointer to CUpointer to CU
159 * \param uiAbsPartIdx CU index
160 * \param uiDepth CU depth
161 * \returns Void
162 */
163Void TDecEntropy::decodeIPCMInfo( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
164{
165  if(!pcCU->getSlice()->getSPS()->getUsePCM()
166    || pcCU->getWidth(uiAbsPartIdx) > (1<<pcCU->getSlice()->getSPS()->getPCMLog2MaxSize())
167    || pcCU->getWidth(uiAbsPartIdx) < (1<<pcCU->getSlice()->getSPS()->getPCMLog2MinSize()) )
168  {
169    return;
170  }
171#if H_3D_DIM_SDC
172  if( pcCU->getSDCFlag(uiAbsPartIdx) )
173  {
174    return;
175  }
176#endif
177 
178  m_pcEntropyDecoderIf->parseIPCMInfo( pcCU, uiAbsPartIdx, uiDepth );
179}
180
181Void TDecEntropy::decodeIntraDirModeLuma  ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
182{
183  m_pcEntropyDecoderIf->parseIntraDirLumaAng( pcCU, uiAbsPartIdx, uiDepth );
184}
185
186Void TDecEntropy::decodeIntraDirModeChroma( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
187{
188  m_pcEntropyDecoderIf->parseIntraDirChroma( pcCU, uiAbsPartIdx, uiDepth );
189}
190
191/** decode motion information for every PU block.
192 * \param pcCU
193 * \param uiAbsPartIdx
194 * \param uiDepth
195 * \param pcSubCU
196 * \returns Void
197 */
198Void TDecEntropy::decodePUWise( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, TComDataCU* pcSubCU )
199{
200  PartSize ePartSize = pcCU->getPartitionSize( uiAbsPartIdx );
201  UInt uiNumPU = ( ePartSize == SIZE_2Nx2N ? 1 : ( ePartSize == SIZE_NxN ? 4 : 2 ) );
202  UInt uiPUOffset = ( g_auiPUOffset[UInt( ePartSize )] << ( ( pcCU->getSlice()->getSPS()->getMaxCUDepth() - uiDepth ) << 1 ) ) >> 4;
203
204#if H_3D_IV_MERGE
205  TComMvField cMvFieldNeighbours[MRG_MAX_NUM_CANDS_MEM << 1]; // double length for mv of both lists
206  UChar uhInterDirNeighbours[MRG_MAX_NUM_CANDS_MEM];
207#else
208  TComMvField cMvFieldNeighbours[MRG_MAX_NUM_CANDS << 1]; // double length for mv of both lists
209  UChar uhInterDirNeighbours[MRG_MAX_NUM_CANDS];
210#endif
211
212  for ( UInt ui = 0; ui < pcCU->getSlice()->getMaxNumMergeCand(); ui++ )
213  {
214    uhInterDirNeighbours[ui] = 0;
215  }
216  Int numValidMergeCand = 0;
217  Bool isMerged = false;
218
219  pcSubCU->copyInterPredInfoFrom( pcCU, uiAbsPartIdx, REF_PIC_LIST_0 );
220  pcSubCU->copyInterPredInfoFrom( pcCU, uiAbsPartIdx, REF_PIC_LIST_1 );
221#if H_3D_IV_MERGE
222  pcSubCU->copyDVInfoFrom( pcCU, uiAbsPartIdx);
223#endif
224  for ( UInt uiPartIdx = 0, uiSubPartIdx = uiAbsPartIdx; uiPartIdx < uiNumPU; uiPartIdx++, uiSubPartIdx += uiPUOffset )
225  {
226#if H_MV_ENC_DEC_TRAC
227    DTRACE_PU_S("=========== prediction_unit ===========\n")
228    // ToDo:
229    //DTRACE_PU("x0", uiLPelX)
230    //DTRACE_PU("x1", uiTPelY)
231#endif
232    decodeMergeFlag( pcCU, uiSubPartIdx, uiDepth, uiPartIdx );
233    if ( pcCU->getMergeFlag( uiSubPartIdx ) )
234    {
235      decodeMergeIndex( pcCU, uiPartIdx, uiSubPartIdx, uiDepth );
236      UInt uiMergeIndex = pcCU->getMergeIndex(uiSubPartIdx);
237#if LGE_SHARP_VSP_INHERIT_F0104
238#if H_3D_IC
239      decodeICFlag( pcCU, uiAbsPartIdx, uiDepth );
240#endif
241#if H_3D_ARP
242      decodeARPW  ( pcCU, uiAbsPartIdx, uiDepth );
243#endif
244#endif
245      if ( pcCU->getSlice()->getPPS()->getLog2ParallelMergeLevelMinus2() && ePartSize != SIZE_2Nx2N && pcSubCU->getWidth( 0 ) <= 8 ) 
246      {
247        pcSubCU->setPartSizeSubParts( SIZE_2Nx2N, 0, uiDepth );
248        if ( !isMerged )
249        {
250#if H_3D_VSP
251          Int vspFlag[MRG_MAX_NUM_CANDS_MEM];
252          memset(vspFlag, 0, sizeof(Int)*MRG_MAX_NUM_CANDS_MEM);
253          InheritedVSPDisInfo inheritedVSPDisInfo[MRG_MAX_NUM_CANDS_MEM];
254          pcSubCU->getInterMergeCandidates( 0, 0, cMvFieldNeighbours, uhInterDirNeighbours, vspFlag, inheritedVSPDisInfo, numValidMergeCand );
255          pcCU->setVSPFlagSubParts( vspFlag[uiMergeIndex], uiSubPartIdx, uiPartIdx, uiDepth );
256
257          if(vspFlag[uiMergeIndex])
258          {
259            pcCU->setDvInfoSubParts(inheritedVSPDisInfo[uiMergeIndex].m_acDvInfo, uiSubPartIdx, uiPartIdx, uiDepth);
260          }
261#else
262          pcSubCU->getInterMergeCandidates( 0, 0, cMvFieldNeighbours, uhInterDirNeighbours, numValidMergeCand );
263#endif
264          isMerged = true;
265        }
266        pcSubCU->setPartSizeSubParts( ePartSize, 0, uiDepth );
267      }
268      else
269      {
270        uiMergeIndex = pcCU->getMergeIndex(uiSubPartIdx);
271#if H_3D_VSP
272        Int vspFlag[MRG_MAX_NUM_CANDS_MEM];
273        memset(vspFlag, 0, sizeof(Int)*MRG_MAX_NUM_CANDS_MEM);
274        InheritedVSPDisInfo inheritedVSPDisInfo[MRG_MAX_NUM_CANDS_MEM];
275        pcSubCU->getInterMergeCandidates( uiSubPartIdx-uiAbsPartIdx, uiPartIdx, cMvFieldNeighbours, uhInterDirNeighbours, vspFlag, inheritedVSPDisInfo,numValidMergeCand, uiMergeIndex );
276        pcCU->setVSPFlagSubParts( vspFlag[uiMergeIndex], uiSubPartIdx, uiPartIdx, uiDepth );
277        if(vspFlag[uiMergeIndex])
278        {
279          pcCU->setDvInfoSubParts(inheritedVSPDisInfo[uiMergeIndex].m_acDvInfo, uiSubPartIdx, uiPartIdx, uiDepth);
280        }
281#else
282        pcSubCU->getInterMergeCandidates( uiSubPartIdx-uiAbsPartIdx, uiPartIdx, cMvFieldNeighbours, uhInterDirNeighbours, numValidMergeCand, uiMergeIndex );
283#endif
284      }
285      pcCU->setInterDirSubParts( uhInterDirNeighbours[uiMergeIndex], uiSubPartIdx, uiPartIdx, uiDepth );
286
287      TComMv cTmpMv( 0, 0 );
288      for ( UInt uiRefListIdx = 0; uiRefListIdx < 2; uiRefListIdx++ )
289      {       
290        if ( pcCU->getSlice()->getNumRefIdx( RefPicList( uiRefListIdx ) ) > 0 )
291        {
292          pcCU->setMVPIdxSubParts( 0, RefPicList( uiRefListIdx ), uiSubPartIdx, uiPartIdx, uiDepth);
293          pcCU->setMVPNumSubParts( 0, RefPicList( uiRefListIdx ), uiSubPartIdx, uiPartIdx, uiDepth);
294          pcCU->getCUMvField( RefPicList( uiRefListIdx ) )->setAllMvd( cTmpMv, ePartSize, uiSubPartIdx, uiDepth, uiPartIdx );
295          pcCU->getCUMvField( RefPicList( uiRefListIdx ) )->setAllMvField( cMvFieldNeighbours[ 2*uiMergeIndex + uiRefListIdx ], ePartSize, uiSubPartIdx, uiDepth, uiPartIdx );
296        }
297      }
298    }
299    else
300    {
301      decodeInterDirPU( pcCU, uiSubPartIdx, uiDepth, uiPartIdx );
302      for ( UInt uiRefListIdx = 0; uiRefListIdx < 2; uiRefListIdx++ )
303      {       
304        if ( pcCU->getSlice()->getNumRefIdx( RefPicList( uiRefListIdx ) ) > 0 )
305        {
306          decodeRefFrmIdxPU( pcCU,    uiSubPartIdx,              uiDepth, uiPartIdx, RefPicList( uiRefListIdx ) );
307          decodeMvdPU      ( pcCU,    uiSubPartIdx,              uiDepth, uiPartIdx, RefPicList( uiRefListIdx ) );
308          decodeMVPIdxPU   ( pcSubCU, uiSubPartIdx-uiAbsPartIdx, uiDepth, uiPartIdx, RefPicList( uiRefListIdx ) );
309        }
310      }
311#if LGE_SHARP_VSP_INHERIT_F0104
312#if H_3D_IC
313      decodeICFlag( pcCU, uiAbsPartIdx, uiDepth );
314#endif
315#if H_3D_ARP
316      decodeARPW  ( pcCU, uiAbsPartIdx, uiDepth );
317#endif
318#endif
319    }
320#if H_3D_VSP
321    if ( (pcCU->getInterDir(uiSubPartIdx) == 3) && pcSubCU->isBipredRestriction(uiPartIdx) && (pcCU->getVSPFlag(uiSubPartIdx) == false))
322#else
323    if ( (pcCU->getInterDir(uiSubPartIdx) == 3) && pcSubCU->isBipredRestriction(uiPartIdx) )
324#endif
325    {
326      pcCU->getCUMvField( REF_PIC_LIST_1 )->setAllMv( TComMv(0,0), ePartSize, uiSubPartIdx, uiDepth, uiPartIdx);
327      pcCU->getCUMvField( REF_PIC_LIST_1 )->setAllRefIdx( -1, ePartSize, uiSubPartIdx, uiDepth, uiPartIdx);
328      pcCU->setInterDirSubParts( 1, uiSubPartIdx, uiPartIdx, uiDepth);
329    }
330  }
331  return;
332}
333
334/** decode inter direction for a PU block
335 * \param pcCU
336 * \param uiAbsPartIdx
337 * \param uiDepth
338 * \param uiPartIdx
339 * \returns Void
340 */
341Void TDecEntropy::decodeInterDirPU( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, UInt uiPartIdx )
342{
343  UInt uiInterDir;
344
345  if ( pcCU->getSlice()->isInterP() )
346  {
347    uiInterDir = 1;
348  }
349  else
350  {
351    m_pcEntropyDecoderIf->parseInterDir( pcCU, uiInterDir, uiAbsPartIdx );
352  }
353
354  pcCU->setInterDirSubParts( uiInterDir, uiAbsPartIdx, uiPartIdx, uiDepth );
355}
356
357Void TDecEntropy::decodeRefFrmIdxPU( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, UInt uiPartIdx, RefPicList eRefList )
358{
359  Int iRefFrmIdx = 0;
360  Int iParseRefFrmIdx = pcCU->getInterDir( uiAbsPartIdx ) & ( 1 << eRefList );
361
362  if ( pcCU->getSlice()->getNumRefIdx( eRefList ) > 1 && iParseRefFrmIdx )
363  {
364    m_pcEntropyDecoderIf->parseRefFrmIdx( pcCU, iRefFrmIdx, eRefList );
365  }
366  else if ( !iParseRefFrmIdx )
367  {
368    iRefFrmIdx = NOT_VALID;
369  }
370  else
371  {
372    iRefFrmIdx = 0;
373  }
374
375  PartSize ePartSize = pcCU->getPartitionSize( uiAbsPartIdx );
376  pcCU->getCUMvField( eRefList )->setAllRefIdx( iRefFrmIdx, ePartSize, uiAbsPartIdx, uiDepth, uiPartIdx );
377}
378
379/** decode motion vector difference for a PU block
380 * \param pcCU
381 * \param uiAbsPartIdx
382 * \param uiDepth
383 * \param uiPartIdx
384 * \param eRefList
385 * \returns Void
386 */
387Void TDecEntropy::decodeMvdPU( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, UInt uiPartIdx, RefPicList eRefList )
388{
389  if ( pcCU->getInterDir( uiAbsPartIdx ) & ( 1 << eRefList ) )
390  {
391    m_pcEntropyDecoderIf->parseMvd( pcCU, uiAbsPartIdx, uiPartIdx, uiDepth, eRefList );
392  }
393}
394
395Void TDecEntropy::decodeMVPIdxPU( TComDataCU* pcSubCU, UInt uiPartAddr, UInt uiDepth, UInt uiPartIdx, RefPicList eRefList )
396{
397  Int iMVPIdx = -1;
398
399  TComMv cZeroMv( 0, 0 );
400  TComMv cMv     = cZeroMv;
401  Int    iRefIdx = -1;
402
403  TComCUMvField* pcSubCUMvField = pcSubCU->getCUMvField( eRefList );
404  AMVPInfo* pAMVPInfo = pcSubCUMvField->getAMVPInfo();
405
406  iRefIdx = pcSubCUMvField->getRefIdx(uiPartAddr);
407  cMv = cZeroMv;
408
409  if ( (pcSubCU->getInterDir(uiPartAddr) & ( 1 << eRefList )) )
410  {
411    m_pcEntropyDecoderIf->parseMVPIdx( iMVPIdx );
412#if H_MV_ENC_DEC_TRAC
413#if ENC_DEC_TRACE
414    if ( eRefList == REF_PIC_LIST_0 )
415    {
416      DTRACE_PU("mvp_l0_flag", iMVPIdx)
417    }
418    else
419    {
420      DTRACE_PU("mvp_l1_flag", iMVPIdx)
421    }
422#endif
423#endif
424  }
425  pcSubCU->fillMvpCand(uiPartIdx, uiPartAddr, eRefList, iRefIdx, pAMVPInfo);
426  pcSubCU->setMVPNumSubParts(pAMVPInfo->iN, eRefList, uiPartAddr, uiPartIdx, uiDepth);
427  pcSubCU->setMVPIdxSubParts( iMVPIdx, eRefList, uiPartAddr, uiPartIdx, uiDepth );
428  if ( iRefIdx >= 0 )
429  {
430    m_pcPrediction->getMvPredAMVP( pcSubCU, uiPartIdx, uiPartAddr, eRefList, cMv);
431    cMv += pcSubCUMvField->getMvd( uiPartAddr );
432  }
433
434  PartSize ePartSize = pcSubCU->getPartitionSize( uiPartAddr );
435  pcSubCU->getCUMvField( eRefList )->setAllMv(cMv, ePartSize, uiPartAddr, 0, uiPartIdx);
436}
437
438Void TDecEntropy::xDecodeTransform( TComDataCU* pcCU, UInt offsetLuma, UInt offsetChroma, UInt uiAbsPartIdx, UInt uiDepth, UInt width, UInt height, UInt uiTrIdx, Bool& bCodeDQP)
439{
440  UInt uiSubdiv;
441  const UInt uiLog2TrafoSize = g_aucConvertToBit[pcCU->getSlice()->getSPS()->getMaxCUWidth()]+2 - uiDepth;
442
443  if(uiTrIdx==0)
444  {
445    m_bakAbsPartIdxCU = uiAbsPartIdx;
446  }
447  if( uiLog2TrafoSize == 2 )
448  {
449    UInt partNum = pcCU->getPic()->getNumPartInCU() >> ( ( uiDepth - 1 ) << 1 );
450    if( ( uiAbsPartIdx % partNum ) == 0 )
451    {
452      m_uiBakAbsPartIdx   = uiAbsPartIdx;
453      m_uiBakChromaOffset = offsetChroma;
454    }
455  }
456  if( pcCU->getPredictionMode(uiAbsPartIdx) == MODE_INTRA && pcCU->getPartitionSize(uiAbsPartIdx) == SIZE_NxN && uiDepth == pcCU->getDepth(uiAbsPartIdx) )
457  {
458    uiSubdiv = 1;
459  }
460  else if( (pcCU->getSlice()->getSPS()->getQuadtreeTUMaxDepthInter() == 1) && (pcCU->getPredictionMode(uiAbsPartIdx) == MODE_INTER) && ( pcCU->getPartitionSize(uiAbsPartIdx) != SIZE_2Nx2N ) && (uiDepth == pcCU->getDepth(uiAbsPartIdx)) )
461  {
462    uiSubdiv = (uiLog2TrafoSize > pcCU->getQuadtreeTULog2MinSizeInCU(uiAbsPartIdx));
463  }
464  else if( uiLog2TrafoSize > pcCU->getSlice()->getSPS()->getQuadtreeTULog2MaxSize() )
465  {
466    uiSubdiv = 1;
467  }
468  else if( uiLog2TrafoSize == pcCU->getSlice()->getSPS()->getQuadtreeTULog2MinSize() )
469  {
470    uiSubdiv = 0;
471  }
472  else if( uiLog2TrafoSize == pcCU->getQuadtreeTULog2MinSizeInCU(uiAbsPartIdx) )
473  {
474    uiSubdiv = 0;
475  }
476  else
477  {
478    assert( uiLog2TrafoSize > pcCU->getQuadtreeTULog2MinSizeInCU(uiAbsPartIdx) );
479    m_pcEntropyDecoderIf->parseTransformSubdivFlag( uiSubdiv, 5 - uiLog2TrafoSize );
480  }
481 
482  const UInt uiTrDepth = uiDepth - pcCU->getDepth( uiAbsPartIdx );
483  {
484    const Bool bFirstCbfOfCU = uiTrDepth == 0;
485    if( bFirstCbfOfCU )
486    {
487      pcCU->setCbfSubParts( 0, TEXT_CHROMA_U, uiAbsPartIdx, uiDepth );
488      pcCU->setCbfSubParts( 0, TEXT_CHROMA_V, uiAbsPartIdx, uiDepth );
489    }
490    if( bFirstCbfOfCU || uiLog2TrafoSize > 2 )
491    {
492      if( bFirstCbfOfCU || pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_U, uiTrDepth - 1 ) )
493      {
494        m_pcEntropyDecoderIf->parseQtCbf( pcCU, uiAbsPartIdx, TEXT_CHROMA_U, uiTrDepth, uiDepth );
495      }
496      if( bFirstCbfOfCU || pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_V, uiTrDepth - 1 ) )
497      {
498        m_pcEntropyDecoderIf->parseQtCbf( pcCU, uiAbsPartIdx, TEXT_CHROMA_V, uiTrDepth, uiDepth );
499      }
500    }
501    else
502    {
503      pcCU->setCbfSubParts( pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_U, uiTrDepth - 1 ) << uiTrDepth, TEXT_CHROMA_U, uiAbsPartIdx, uiDepth );
504      pcCU->setCbfSubParts( pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_V, uiTrDepth - 1 ) << uiTrDepth, TEXT_CHROMA_V, uiAbsPartIdx, uiDepth );
505    }
506  }
507 
508  if( uiSubdiv )
509  {
510    UInt size;
511    width  >>= 1;
512    height >>= 1;
513    size = width*height;
514    uiTrIdx++;
515    ++uiDepth;
516    const UInt uiQPartNum = pcCU->getPic()->getNumPartInCU() >> (uiDepth << 1);
517    const UInt uiStartAbsPartIdx = uiAbsPartIdx;
518    UInt uiYCbf = 0;
519    UInt uiUCbf = 0;
520    UInt uiVCbf = 0;
521   
522    for( Int i = 0; i < 4; i++ )
523    {
524      xDecodeTransform( pcCU, offsetLuma, offsetChroma, uiAbsPartIdx, uiDepth, width, height, uiTrIdx, bCodeDQP );
525      uiYCbf |= pcCU->getCbf( uiAbsPartIdx, TEXT_LUMA, uiTrDepth+1 );
526      uiUCbf |= pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_U, uiTrDepth+1 );
527      uiVCbf |= pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_V, uiTrDepth+1 );
528      uiAbsPartIdx += uiQPartNum;
529      offsetLuma += size;  offsetChroma += (size>>2);
530    }
531   
532    for( UInt ui = 0; ui < 4 * uiQPartNum; ++ui )
533    {
534      pcCU->getCbf( TEXT_LUMA     )[uiStartAbsPartIdx + ui] |= uiYCbf << uiTrDepth;
535      pcCU->getCbf( TEXT_CHROMA_U )[uiStartAbsPartIdx + ui] |= uiUCbf << uiTrDepth;
536      pcCU->getCbf( TEXT_CHROMA_V )[uiStartAbsPartIdx + ui] |= uiVCbf << uiTrDepth;
537    }
538  }
539  else
540  {
541    assert( uiDepth >= pcCU->getDepth( uiAbsPartIdx ) );
542    pcCU->setTrIdxSubParts( uiTrDepth, uiAbsPartIdx, uiDepth );
543   
544#if !H_MV_ENC_DEC_TRAC
545    {
546      DTRACE_CABAC_VL( g_nSymbolCounter++ );
547      DTRACE_CABAC_T( "\tTrIdx: abspart=" );
548      DTRACE_CABAC_V( uiAbsPartIdx );
549      DTRACE_CABAC_T( "\tdepth=" );
550      DTRACE_CABAC_V( uiDepth );
551      DTRACE_CABAC_T( "\ttrdepth=" );
552      DTRACE_CABAC_V( uiTrDepth );
553      DTRACE_CABAC_T( "\n" );
554    }
555#endif
556   
557    pcCU->setCbfSubParts ( 0, TEXT_LUMA, uiAbsPartIdx, uiDepth );
558    if( pcCU->getPredictionMode(uiAbsPartIdx) != MODE_INTRA && uiDepth == pcCU->getDepth( uiAbsPartIdx ) && !pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_U, 0 ) && !pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_V, 0 ) )
559    {
560      pcCU->setCbfSubParts( 1 << uiTrDepth, TEXT_LUMA, uiAbsPartIdx, uiDepth );
561    }
562    else
563    {
564      m_pcEntropyDecoderIf->parseQtCbf( pcCU, uiAbsPartIdx, TEXT_LUMA, uiTrDepth, uiDepth );
565    }
566
567
568    // transform_unit begin
569    UInt cbfY = pcCU->getCbf( uiAbsPartIdx, TEXT_LUMA    , uiTrIdx );
570    UInt cbfU = pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_U, uiTrIdx );
571    UInt cbfV = pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_V, uiTrIdx );
572    if( uiLog2TrafoSize == 2 )
573    {
574      UInt partNum = pcCU->getPic()->getNumPartInCU() >> ( ( uiDepth - 1 ) << 1 );
575      if( ( uiAbsPartIdx % partNum ) == (partNum - 1) )
576      {
577        cbfU = pcCU->getCbf( m_uiBakAbsPartIdx, TEXT_CHROMA_U, uiTrIdx );
578        cbfV = pcCU->getCbf( m_uiBakAbsPartIdx, TEXT_CHROMA_V, uiTrIdx );
579      }
580    }
581    if ( cbfY || cbfU || cbfV )
582    {
583      // dQP: only for LCU
584      if ( pcCU->getSlice()->getPPS()->getUseDQP() )
585      {
586        if ( bCodeDQP )
587        {
588          decodeQP( pcCU, m_bakAbsPartIdxCU);
589          bCodeDQP = false;
590        }
591      }
592    }
593    if( cbfY )
594    {
595      Int trWidth = width;
596      Int trHeight = height;
597      m_pcEntropyDecoderIf->parseCoeffNxN( pcCU, (pcCU->getCoeffY()+offsetLuma), uiAbsPartIdx, trWidth, trHeight, uiDepth, TEXT_LUMA );
598    }
599    if( uiLog2TrafoSize > 2 )
600    {
601      Int trWidth = width >> 1;
602      Int trHeight = height >> 1;
603      if( cbfU )
604      {
605        m_pcEntropyDecoderIf->parseCoeffNxN( pcCU, (pcCU->getCoeffCb()+offsetChroma), uiAbsPartIdx, trWidth, trHeight, uiDepth, TEXT_CHROMA_U );
606      }
607      if( cbfV )
608      {
609        m_pcEntropyDecoderIf->parseCoeffNxN( pcCU, (pcCU->getCoeffCr()+offsetChroma), uiAbsPartIdx, trWidth, trHeight, uiDepth, TEXT_CHROMA_V );
610      }
611    }
612    else
613    {
614      UInt partNum = pcCU->getPic()->getNumPartInCU() >> ( ( uiDepth - 1 ) << 1 );
615      if( ( uiAbsPartIdx % partNum ) == (partNum - 1) )
616      {
617        Int trWidth = width;
618        Int trHeight = height;
619        if( cbfU )
620        {
621          m_pcEntropyDecoderIf->parseCoeffNxN( pcCU, (pcCU->getCoeffCb()+m_uiBakChromaOffset), m_uiBakAbsPartIdx, trWidth, trHeight, uiDepth, TEXT_CHROMA_U );
622        }
623        if( cbfV )
624        {
625          m_pcEntropyDecoderIf->parseCoeffNxN( pcCU, (pcCU->getCoeffCr()+m_uiBakChromaOffset), m_uiBakAbsPartIdx, trWidth, trHeight, uiDepth, TEXT_CHROMA_V );
626        }
627      }
628    }
629    // transform_unit end
630  }
631}
632
633Void TDecEntropy::decodeQP          ( TComDataCU* pcCU, UInt uiAbsPartIdx )
634{
635  if ( pcCU->getSlice()->getPPS()->getUseDQP() )
636  {
637    m_pcEntropyDecoderIf->parseDeltaQP( pcCU, uiAbsPartIdx, pcCU->getDepth( uiAbsPartIdx ) );
638  }
639}
640
641
642/** decode coefficients
643 * \param pcCU
644 * \param uiAbsPartIdx
645 * \param uiDepth
646 * \param uiWidth
647 * \param uiHeight
648 * \returns Void
649 */
650Void TDecEntropy::decodeCoeff( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, UInt uiWidth, UInt uiHeight, Bool& bCodeDQP )
651{
652  UInt uiMinCoeffSize = pcCU->getPic()->getMinCUWidth()*pcCU->getPic()->getMinCUHeight();
653  UInt uiLumaOffset   = uiMinCoeffSize*uiAbsPartIdx;
654  UInt uiChromaOffset = uiLumaOffset>>2;
655 
656#if H_3D_DIM_SDC
657  if( pcCU->getSDCFlag( uiAbsPartIdx ) )
658  {
659    assert( pcCU->getPartitionSize(uiAbsPartIdx) == SIZE_2Nx2N );
660    assert( pcCU->getTransformIdx(uiAbsPartIdx) == 0 );
661    assert( pcCU->getCbf(uiAbsPartIdx, TEXT_LUMA) == 1 );
662    assert( pcCU->getCbf(uiAbsPartIdx, TEXT_CHROMA_U) == 1 );
663    assert( pcCU->getCbf(uiAbsPartIdx, TEXT_CHROMA_V) == 1 );
664    return;
665  }
666#endif
667 
668#if H_3D_INTER_SDC
669  if( pcCU->getInterSDCFlag( uiAbsPartIdx ) )
670  {
671    assert( !pcCU->isSkipped( uiAbsPartIdx ) );
672    assert( !pcCU->isIntra( uiAbsPartIdx) );
673    assert( pcCU->getSlice()->getIsDepth() );
674
675    decodeInterSDCResidualData( pcCU, uiAbsPartIdx, uiDepth );
676    return;
677  }
678#endif
679
680  if( pcCU->isIntra(uiAbsPartIdx) )
681  {
682  }
683  else
684  {
685    UInt uiQtRootCbf = 1;
686    if( !( pcCU->getPartitionSize( uiAbsPartIdx) == SIZE_2Nx2N && pcCU->getMergeFlag( uiAbsPartIdx ) ) )
687    {
688      m_pcEntropyDecoderIf->parseQtRootCbf( uiAbsPartIdx, uiQtRootCbf );
689    }
690    if ( !uiQtRootCbf )
691    {
692      pcCU->setCbfSubParts( 0, 0, 0, uiAbsPartIdx, uiDepth );
693      pcCU->setTrIdxSubParts( 0 , uiAbsPartIdx, uiDepth );
694      return;
695    }
696   
697  }
698  xDecodeTransform( pcCU, uiLumaOffset, uiChromaOffset, uiAbsPartIdx, uiDepth, uiWidth, uiHeight, 0, bCodeDQP );
699}
700
701#if H_3D_INTER_SDC
702Void TDecEntropy::decodeInterSDCFlag( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
703{
704  pcCU->setInterSDCFlagSubParts( false, uiAbsPartIdx, 0, uiDepth);
705
706  if( !pcCU->getSlice()->getVPS()->getInterSDCFlag( pcCU->getSlice()->getLayerIdInVps() ) )
707  {
708    return;
709  }
710
711  if( !pcCU->getSlice()->getIsDepth() || pcCU->isIntra( uiAbsPartIdx ) || pcCU->isSkipped( uiAbsPartIdx ) )
712  {
713    return;
714  }
715
716  m_pcEntropyDecoderIf->parseInterSDCFlag( pcCU, uiAbsPartIdx, uiDepth );
717}
718
719Void TDecEntropy::decodeInterSDCResidualData( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
720{
721  if( !pcCU->getSlice()->getVPS()->getInterSDCFlag( pcCU->getSlice()->getLayerIdInVps() ) )
722  {
723    return;
724  }
725
726  if( !pcCU->getSlice()->getIsDepth() || pcCU->isIntra( uiAbsPartIdx ) || !pcCU->getInterSDCFlag( uiAbsPartIdx ) )
727  {
728    return;
729  }
730
731  UInt uiNumSegments = ( pcCU->getPartitionSize( uiAbsPartIdx ) == SIZE_2Nx2N ) ? 1 : ( pcCU->getPartitionSize( uiAbsPartIdx ) == SIZE_NxN ? 4 : 2 );
732
733  // decode residual data for each segment
734  for( UInt uiSeg = 0; uiSeg < uiNumSegments; uiSeg++ )
735  {
736    m_pcEntropyDecoderIf->parseInterSDCResidualData( pcCU, uiAbsPartIdx, uiDepth, uiSeg );
737  }
738}
739#endif
740
741//! \}
Note: See TracBrowser for help on using the repository browser.