source: 3DVCSoftware/branches/HTM-9.3-dev1-RWTH/source/Lib/TLibEncoder/TEncEntropy.cpp @ 820

Last change on this file since 820 was 820, checked in by rwth, 10 years ago
  • cleanup: removed some assertions and added some comments
  • Property svn:eol-style set to native
File size: 25.4 KB
RevLine 
[5]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
[56]4 * granted under this license. 
[5]5 *
[608]6 * Copyright (c) 2010-2013, ITU/ISO/IEC
[5]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.
[56]17 *  * Neither the name of the ITU/ISO/IEC nor the names of its contributors may
[5]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 */
[2]33
34/** \file     TEncEntropy.cpp
35    \brief    entropy encoder class
36*/
37
38#include "TEncEntropy.h"
[56]39#include "TLibCommon/TypeDef.h"
40#include "TLibCommon/TComSampleAdaptiveOffset.h"
[2]41
[56]42//! \ingroup TLibEncoder
43//! \{
44
[2]45Void TEncEntropy::setEntropyCoder ( TEncEntropyIf* e, TComSlice* pcSlice )
46{
47  m_pcEntropyCoderIf = e;
48  m_pcEntropyCoderIf->setSlice ( pcSlice );
49}
50
51Void TEncEntropy::encodeSliceHeader ( TComSlice* pcSlice )
52{
[56]53  if (pcSlice->getSPS()->getUseSAO())
54  {
[608]55    SAOParam *saoParam = pcSlice->getPic()->getPicSym()->getSaoParam();
56    pcSlice->setSaoEnabledFlag     (saoParam->bSaoFlag[0]);
[443]57    {
[608]58      pcSlice->setSaoEnabledFlagChroma   (saoParam->bSaoFlag[1]);
[443]59    }
[56]60  }
61
[2]62  m_pcEntropyCoderIf->codeSliceHeader( pcSlice );
63  return;
64}
65
[56]66Void  TEncEntropy::encodeTilesWPPEntryPoint( TComSlice* pSlice )
67{
68  m_pcEntropyCoderIf->codeTilesWPPEntryPoint( pSlice );
69}
70
[2]71Void TEncEntropy::encodeTerminatingBit      ( UInt uiIsLast )
72{
73  m_pcEntropyCoderIf->codeTerminatingBit( uiIsLast );
74 
75  return;
76}
77
78Void TEncEntropy::encodeSliceFinish()
79{
80  m_pcEntropyCoderIf->codeSliceFinish();
81}
82
83Void TEncEntropy::encodePPS( TComPPS* pcPPS )
84{
85  m_pcEntropyCoderIf->codePPS( pcPPS );
86  return;
87}
88
[608]89#if H_3D
90Void TEncEntropy::encodeSPS( TComSPS* pcSPS, Int viewIndex, Bool depthFlag )
[77]91{
[608]92  m_pcEntropyCoderIf->codeSPS( pcSPS, viewIndex, depthFlag );
[77]93  return;
94}
[56]95#else
[2]96Void TEncEntropy::encodeSPS( TComSPS* pcSPS )
97{
98  m_pcEntropyCoderIf->codeSPS( pcSPS );
99  return;
100}
[56]101#endif
[2]102
[608]103Void TEncEntropy::encodeCUTransquantBypassFlag( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool bRD )
[2]104{
105  if( bRD )
[56]106  {
[2]107    uiAbsPartIdx = 0;
[56]108  }
[608]109  m_pcEntropyCoderIf->codeCUTransquantBypassFlag( pcCU, uiAbsPartIdx );
[2]110}
111
[608]112Void TEncEntropy::encodeVPS( TComVPS* pcVPS )
[189]113{
[608]114  m_pcEntropyCoderIf->codeVPS( pcVPS );
115  return;
116}
117
118Void TEncEntropy::encodeSkipFlag( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool bRD )
119{
120  if ( pcCU->getSlice()->isIntra() )
[189]121  {
122    return;
123  }
124  if( bRD )
125  {
126    uiAbsPartIdx = 0;
127  }
[608]128  m_pcEntropyCoderIf->codeSkipFlag( pcCU, uiAbsPartIdx );
[189]129}
130
[2]131/** encode merge flag
132 * \param pcCU
133 * \param uiAbsPartIdx
134 * \returns Void
135 */
[608]136Void TEncEntropy::encodeMergeFlag( TComDataCU* pcCU, UInt uiAbsPartIdx )
[2]137{ 
[56]138  // at least one merge candidate exists
139  m_pcEntropyCoderIf->codeMergeFlag( pcCU, uiAbsPartIdx );
[2]140}
141
142/** encode merge index
143 * \param pcCU
144 * \param uiAbsPartIdx
145 * \param uiPUIdx
146 * \param bRD
147 * \returns Void
148 */
[608]149Void TEncEntropy::encodeMergeIndex( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool bRD )
[2]150{
151  if( bRD )
152  {
153    uiAbsPartIdx = 0;
154    assert( pcCU->getPartitionSize(uiAbsPartIdx) == SIZE_2Nx2N );
155  }
[608]156  m_pcEntropyCoderIf->codeMergeIndex( pcCU, uiAbsPartIdx );
[2]157}
158
[608]159#if H_3D_IC
160Void TEncEntropy::encodeICFlag( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool bRD )
[443]161{
[724]162  if ( pcCU->isIntra( uiAbsPartIdx ) || ( pcCU->getSlice()->getViewIndex() == 0 ) || pcCU->getSlice()->getIsDepth() )
[443]163  {
164    return;
165  }
[608]166
167  if( !pcCU->getSlice()->getApplyIC() )
168    return;
169
[443]170  if( bRD )
171  {
172    uiAbsPartIdx = 0;
173  }
[608]174
175  if( pcCU->isICFlagRequired( uiAbsPartIdx ) )
176    m_pcEntropyCoderIf->codeICFlag( pcCU, uiAbsPartIdx );
[443]177}
178#endif
[2]179
[608]180#if H_3D_ARP
181Void TEncEntropy::encodeARPW( TComDataCU* pcCU, UInt uiAbsPartIdx )
[56]182{
[608]183  if( !pcCU->getSlice()->getARPStepNum() || pcCU->isIntra( uiAbsPartIdx ) ) 
[56]184  {
[608]185    return;
[56]186  }
187
[608]188  if ( pcCU->getPartitionSize(uiAbsPartIdx)!=SIZE_2Nx2N )
[56]189  {
[608]190    assert(pcCU->getARPW (uiAbsPartIdx) == 0);
[56]191  }
[608]192  else
[56]193  {
[608]194    m_pcEntropyCoderIf->codeARPW( pcCU, uiAbsPartIdx );
[56]195  }
196}
[608]197#endif
[56]198
[2]199/** encode prediction mode
200 * \param pcCU
201 * \param uiAbsPartIdx
202 * \param bRD
203 * \returns Void
204 */
205Void TEncEntropy::encodePredMode( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool bRD )
206{
207  if( bRD )
[56]208  {
[2]209    uiAbsPartIdx = 0;
[56]210  }
[2]211  if ( pcCU->getSlice()->isIntra() )
212  {
213    return;
214  }
[56]215
[2]216  m_pcEntropyCoderIf->codePredMode( pcCU, uiAbsPartIdx );
217}
218
219// Split mode
220Void TEncEntropy::encodeSplitFlag( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, Bool bRD )
221{
222  if( bRD )
[56]223  {
[2]224    uiAbsPartIdx = 0;
[56]225  }
[2]226  m_pcEntropyCoderIf->codeSplitFlag( pcCU, uiAbsPartIdx, uiDepth );
227}
228
229/** encode partition size
230 * \param pcCU
231 * \param uiAbsPartIdx
232 * \param uiDepth
233 * \param bRD
234 * \returns Void
235 */
236Void TEncEntropy::encodePartSize( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, Bool bRD )
237{
238  if( bRD )
[56]239  {
[2]240    uiAbsPartIdx = 0;
[56]241  }
[816]242 
243#if H_3D_DBBP
244  PartSize eVirtualPartSize = pcCU->getPartitionSize(uiAbsPartIdx);
245  if( pcCU->getDBBPFlag(uiAbsPartIdx) )
246  {
[820]247    AOF( pcCU->getSlice()->getVPS()->getUseDBBP(pcCU->getSlice()->getLayerIdInVps()) );
248   
[816]249    // temporarily change partition size for DBBP blocks
250    pcCU->setPartSizeSubParts(RWTH_DBBP_PACK_MODE, uiAbsPartIdx, uiDepth);
251  }
252#endif
253 
[2]254  m_pcEntropyCoderIf->codePartSize( pcCU, uiAbsPartIdx, uiDepth );
[816]255 
256#if H_3D_DBBP
257  if( pcCU->getSlice()->getVPS()->getUseDBBP(pcCU->getSlice()->getLayerIdInVps()) && pcCU->getPartitionSize(uiAbsPartIdx) == RWTH_DBBP_PACK_MODE )
258  {
259    encodeDBBPFlag(pcCU, uiAbsPartIdx, bRD);
260   
261    if( pcCU->getDBBPFlag(uiAbsPartIdx) )
262    {
263      AOF( pcCU->getPartitionSize(uiAbsPartIdx) == RWTH_DBBP_PACK_MODE );
264      // restore virtual partition size for DBBP blocks
265      pcCU->setPartSizeSubParts(eVirtualPartSize, uiAbsPartIdx, uiDepth);
266    }
267  }
268#endif
[2]269}
270
[56]271/** Encode I_PCM information.
272 * \param pcCU pointer to CU
273 * \param uiAbsPartIdx CU index
274 * \param bRD flag indicating estimation or encoding
275 * \returns Void
276 */
277Void TEncEntropy::encodeIPCMInfo( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool bRD )
[2]278{
[56]279  if(!pcCU->getSlice()->getSPS()->getUsePCM()
280    || pcCU->getWidth(uiAbsPartIdx) > (1<<pcCU->getSlice()->getSPS()->getPCMLog2MaxSize())
281    || pcCU->getWidth(uiAbsPartIdx) < (1<<pcCU->getSlice()->getSPS()->getPCMLog2MinSize()))
282  {
283    return;
284  }
[608]285#if H_3D_DIM_SDC
[189]286  if( pcCU->getSDCFlag(uiAbsPartIdx) )
287  {
288    return;
289  }
290#endif
291 
[56]292  if( bRD )
293  {
294    uiAbsPartIdx = 0;
295  }
296 
[608]297  m_pcEntropyCoderIf->codeIPCMInfo ( pcCU, uiAbsPartIdx );
[56]298}
299
[608]300Void TEncEntropy::xEncodeTransform( TComDataCU* pcCU,UInt offsetLuma, UInt offsetChroma, UInt uiAbsPartIdx, UInt uiDepth, UInt width, UInt height, UInt uiTrIdx, Bool& bCodeDQP )
[56]301{
[2]302  const UInt uiSubdiv = pcCU->getTransformIdx( uiAbsPartIdx ) + pcCU->getDepth( uiAbsPartIdx ) > uiDepth;
303  const UInt uiLog2TrafoSize = g_aucConvertToBit[pcCU->getSlice()->getSPS()->getMaxCUWidth()]+2 - uiDepth;
[56]304  UInt cbfY = pcCU->getCbf( uiAbsPartIdx, TEXT_LUMA    , uiTrIdx );
305  UInt cbfU = pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_U, uiTrIdx );
306  UInt cbfV = pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_V, uiTrIdx );
307
308  if(uiTrIdx==0)
[2]309  {
[56]310    m_bakAbsPartIdxCU = uiAbsPartIdx;
[2]311  }
[56]312  if( uiLog2TrafoSize == 2 )
[2]313  {
[56]314    UInt partNum = pcCU->getPic()->getNumPartInCU() >> ( ( uiDepth - 1 ) << 1 );
315    if( ( uiAbsPartIdx % partNum ) == 0 )
316    {
317      m_uiBakAbsPartIdx   = uiAbsPartIdx;
318      m_uiBakChromaOffset = offsetChroma;
319    }
320    else if( ( uiAbsPartIdx % partNum ) == (partNum - 1) )
321    {
322      cbfU = pcCU->getCbf( m_uiBakAbsPartIdx, TEXT_CHROMA_U, uiTrIdx );
323      cbfV = pcCU->getCbf( m_uiBakAbsPartIdx, TEXT_CHROMA_V, uiTrIdx );
324    }
[2]325  }
[608]326 
327  if( pcCU->getPredictionMode(uiAbsPartIdx) == MODE_INTRA && pcCU->getPartitionSize(uiAbsPartIdx) == SIZE_NxN && uiDepth == pcCU->getDepth(uiAbsPartIdx) )
328  {
329    assert( uiSubdiv );
330  }
331  else if( pcCU->getPredictionMode(uiAbsPartIdx) == MODE_INTER && (pcCU->getPartitionSize(uiAbsPartIdx) != SIZE_2Nx2N) && uiDepth == pcCU->getDepth(uiAbsPartIdx) &&  (pcCU->getSlice()->getSPS()->getQuadtreeTUMaxDepthInter() == 1) )
332  {
333    if ( uiLog2TrafoSize > pcCU->getQuadtreeTULog2MinSizeInCU(uiAbsPartIdx) )
[2]334    {
335      assert( uiSubdiv );
336    }
[608]337    else
[56]338    {
[608]339      assert(!uiSubdiv );
[56]340    }
[608]341  }
342  else if( uiLog2TrafoSize > pcCU->getSlice()->getSPS()->getQuadtreeTULog2MaxSize() )
343  {
344    assert( uiSubdiv );
345  }
346  else if( uiLog2TrafoSize == pcCU->getSlice()->getSPS()->getQuadtreeTULog2MinSize() )
347  {
348    assert( !uiSubdiv );
349  }
350  else if( uiLog2TrafoSize == pcCU->getQuadtreeTULog2MinSizeInCU(uiAbsPartIdx) )
351  {
352    assert( !uiSubdiv );
353  }
354  else
355  {
356    assert( uiLog2TrafoSize > pcCU->getQuadtreeTULog2MinSizeInCU(uiAbsPartIdx) );
357    m_pcEntropyCoderIf->codeTransformSubdivFlag( uiSubdiv, 5 - uiLog2TrafoSize );
358  }
359
360  const UInt uiTrDepthCurr = uiDepth - pcCU->getDepth( uiAbsPartIdx );
361  const Bool bFirstCbfOfCU = uiTrDepthCurr == 0;
362  if( bFirstCbfOfCU || uiLog2TrafoSize > 2 )
363  {
364    if( bFirstCbfOfCU || pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_U, uiTrDepthCurr - 1 ) )
[56]365    {
[608]366      m_pcEntropyCoderIf->codeQtCbf( pcCU, uiAbsPartIdx, TEXT_CHROMA_U, uiTrDepthCurr );
[56]367    }
[608]368    if( bFirstCbfOfCU || pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_V, uiTrDepthCurr - 1 ) )
[2]369    {
[608]370      m_pcEntropyCoderIf->codeQtCbf( pcCU, uiAbsPartIdx, TEXT_CHROMA_V, uiTrDepthCurr );
[2]371    }
[608]372  }
373  else if( uiLog2TrafoSize == 2 )
374  {
375    assert( pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_U, uiTrDepthCurr ) == pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_U, uiTrDepthCurr - 1 ) );
376    assert( pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_V, uiTrDepthCurr ) == pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_V, uiTrDepthCurr - 1 ) );
377  }
378 
379  if( uiSubdiv )
380  {
381    UInt size;
382    width  >>= 1;
383    height >>= 1;
384    size = width*height;
385    uiTrIdx++;
386    ++uiDepth;
387    const UInt partNum = pcCU->getPic()->getNumPartInCU() >> (uiDepth << 1);
388   
389    xEncodeTransform( pcCU, offsetLuma, offsetChroma, uiAbsPartIdx, uiDepth, width, height, uiTrIdx, bCodeDQP );
390
391    uiAbsPartIdx += partNum;  offsetLuma += size;  offsetChroma += (size>>2);
392    xEncodeTransform( pcCU, offsetLuma, offsetChroma, uiAbsPartIdx, uiDepth, width, height, uiTrIdx, bCodeDQP );
393
394    uiAbsPartIdx += partNum;  offsetLuma += size;  offsetChroma += (size>>2);
395    xEncodeTransform( pcCU, offsetLuma, offsetChroma, uiAbsPartIdx, uiDepth, width, height, uiTrIdx, bCodeDQP );
396
397    uiAbsPartIdx += partNum;  offsetLuma += size;  offsetChroma += (size>>2);
398    xEncodeTransform( pcCU, offsetLuma, offsetChroma, uiAbsPartIdx, uiDepth, width, height, uiTrIdx, bCodeDQP );
399  }
400  else
401  {
402#if !H_MV_ENC_DEC_TRAC
[2]403    {
[608]404      DTRACE_CABAC_VL( g_nSymbolCounter++ );
405      DTRACE_CABAC_T( "\tTrIdx: abspart=" );
406      DTRACE_CABAC_V( uiAbsPartIdx );
407      DTRACE_CABAC_T( "\tdepth=" );
408      DTRACE_CABAC_V( uiDepth );
409      DTRACE_CABAC_T( "\ttrdepth=" );
410      DTRACE_CABAC_V( pcCU->getTransformIdx( uiAbsPartIdx ) );
411      DTRACE_CABAC_T( "\n" );
[2]412    }
[608]413#endif
414   
415    if( pcCU->getPredictionMode(uiAbsPartIdx) != MODE_INTRA && uiDepth == pcCU->getDepth( uiAbsPartIdx ) && !pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_U, 0 ) && !pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_V, 0 ) )
416    {
417      assert( pcCU->getCbf( uiAbsPartIdx, TEXT_LUMA, 0 ) );
418      //      printf( "saved one bin! " );
419    }
[2]420    else
421    {
[608]422      m_pcEntropyCoderIf->codeQtCbf( pcCU, uiAbsPartIdx, TEXT_LUMA, pcCU->getTransformIdx( uiAbsPartIdx ) );
[2]423    }
[56]424
[608]425
426    if ( cbfY || cbfU || cbfV )
[2]427    {
[608]428      // dQP: only for LCU once
429      if ( pcCU->getSlice()->getPPS()->getUseDQP() )
[2]430      {
[608]431        if ( bCodeDQP )
[2]432        {
[608]433          encodeQP( pcCU, m_bakAbsPartIdxCU );
434          bCodeDQP = false;
[2]435        }
436      }
437    }
[608]438    if( cbfY )
[2]439    {
[608]440      Int trWidth = width;
441      Int trHeight = height;
442      m_pcEntropyCoderIf->codeCoeffNxN( pcCU, (pcCU->getCoeffY()+offsetLuma), uiAbsPartIdx, trWidth, trHeight, uiDepth, TEXT_LUMA );
[2]443    }
[608]444    if( uiLog2TrafoSize > 2 )
[2]445    {
[608]446      Int trWidth = width >> 1;
447      Int trHeight = height >> 1;
448      if( cbfU )
[2]449      {
[608]450        m_pcEntropyCoderIf->codeCoeffNxN( pcCU, (pcCU->getCoeffCb()+offsetChroma), uiAbsPartIdx, trWidth, trHeight, uiDepth, TEXT_CHROMA_U );
[2]451      }
[608]452      if( cbfV )
[56]453      {
[608]454        m_pcEntropyCoderIf->codeCoeffNxN( pcCU, (pcCU->getCoeffCr()+offsetChroma), uiAbsPartIdx, trWidth, trHeight, uiDepth, TEXT_CHROMA_V );
[56]455      }
[608]456    }
457    else
458    {
459      UInt partNum = pcCU->getPic()->getNumPartInCU() >> ( ( uiDepth - 1 ) << 1 );
460      if( ( uiAbsPartIdx % partNum ) == (partNum - 1) )
[2]461      {
[56]462        Int trWidth = width;
463        Int trHeight = height;
464        if( cbfU )
[2]465        {
[608]466          m_pcEntropyCoderIf->codeCoeffNxN( pcCU, (pcCU->getCoeffCb()+m_uiBakChromaOffset), m_uiBakAbsPartIdx, trWidth, trHeight, uiDepth, TEXT_CHROMA_U );
[2]467        }
[56]468        if( cbfV )
469        {
[608]470          m_pcEntropyCoderIf->codeCoeffNxN( pcCU, (pcCU->getCoeffCr()+m_uiBakChromaOffset), m_uiBakAbsPartIdx, trWidth, trHeight, uiDepth, TEXT_CHROMA_V );
[56]471        }
[2]472      }
473    }
474  }
475}
476
477// Intra direction for Luma
[608]478Void TEncEntropy::encodeIntraDirModeLuma  ( TComDataCU* pcCU, UInt absPartIdx, Bool isMultiplePU )
[2]479{
[608]480  m_pcEntropyCoderIf->codeIntraDirLumaAng( pcCU, absPartIdx , isMultiplePU);
[2]481}
482
483// Intra direction for Chroma
484Void TEncEntropy::encodeIntraDirModeChroma( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool bRD )
485{
486  if( bRD )
[56]487  {
[2]488    uiAbsPartIdx = 0;
[56]489  }
[2]490 
491  m_pcEntropyCoderIf->codeIntraDirChroma( pcCU, uiAbsPartIdx );
492}
493
[608]494Void TEncEntropy::encodePredInfo( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool bRD )
[2]495{
496  if( bRD )
[56]497  {
[2]498    uiAbsPartIdx = 0;
[56]499  }
[2]500  if( pcCU->isIntra( uiAbsPartIdx ) )                                 // If it is Intra mode, encode intra prediction mode.
501  {
[608]502    encodeIntraDirModeLuma  ( pcCU, uiAbsPartIdx,true );
503#if H_3D_DIM_SDC
504    if(!pcCU->getSDCFlag(uiAbsPartIdx))
[443]505#endif
[608]506    encodeIntraDirModeChroma( pcCU, uiAbsPartIdx, bRD );
[2]507  }
508  else                                                                // if it is Inter mode, encode motion vector and reference index
509  {
[56]510    encodePUWise( pcCU, uiAbsPartIdx, bRD );
[2]511  }
512}
513
514/** encode motion information for every PU block
515 * \param pcCU
516 * \param uiAbsPartIdx
517 * \param bRD
518 * \returns Void
519 */
520Void TEncEntropy::encodePUWise( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool bRD )
521{
522  if ( bRD )
[56]523  {
[2]524    uiAbsPartIdx = 0;
[56]525  }
526 
[2]527  PartSize ePartSize = pcCU->getPartitionSize( uiAbsPartIdx );
528  UInt uiNumPU = ( ePartSize == SIZE_2Nx2N ? 1 : ( ePartSize == SIZE_NxN ? 4 : 2 ) );
529  UInt uiDepth = pcCU->getDepth( uiAbsPartIdx );
530  UInt uiPUOffset = ( g_auiPUOffset[UInt( ePartSize )] << ( ( pcCU->getSlice()->getSPS()->getMaxCUDepth() - uiDepth ) << 1 ) ) >> 4;
531
532  for ( UInt uiPartIdx = 0, uiSubPartIdx = uiAbsPartIdx; uiPartIdx < uiNumPU; uiPartIdx++, uiSubPartIdx += uiPUOffset )
533  {
[608]534#if H_MV_ENC_DEC_TRAC
535    DTRACE_PU_S("=========== prediction_unit ===========\n")
536       //Todo:
537      //DTRACE_PU("x0", uiLPelX)
538      //DTRACE_PU("x1", uiTPelY)
539#endif
540    encodeMergeFlag( pcCU, uiSubPartIdx );
[2]541    if ( pcCU->getMergeFlag( uiSubPartIdx ) )
542    {
[608]543      encodeMergeIndex( pcCU, uiSubPartIdx );
[2]544    }
545    else
546    {
547      encodeInterDirPU( pcCU, uiSubPartIdx );
548      for ( UInt uiRefListIdx = 0; uiRefListIdx < 2; uiRefListIdx++ )
549      {
550        if ( pcCU->getSlice()->getNumRefIdx( RefPicList( uiRefListIdx ) ) > 0 )
551        {
552          encodeRefFrmIdxPU ( pcCU, uiSubPartIdx, RefPicList( uiRefListIdx ) );
553          encodeMvdPU       ( pcCU, uiSubPartIdx, RefPicList( uiRefListIdx ) );
554          encodeMVPIdxPU    ( pcCU, uiSubPartIdx, RefPicList( uiRefListIdx ) );
555        }
556      }
557    }
558  }
559
560  return;
561}
562
563Void TEncEntropy::encodeInterDirPU( TComDataCU* pcCU, UInt uiAbsPartIdx )
564{
565  if ( !pcCU->getSlice()->isInterB() )
566  {
567    return;
568  }
569
570  m_pcEntropyCoderIf->codeInterDir( pcCU, uiAbsPartIdx );
571  return;
572}
573
574/** encode reference frame index for a PU block
575 * \param pcCU
576 * \param uiAbsPartIdx
577 * \param eRefList
578 * \returns Void
579 */
580Void TEncEntropy::encodeRefFrmIdxPU( TComDataCU* pcCU, UInt uiAbsPartIdx, RefPicList eRefList )
581{
582  assert( !pcCU->isIntra( uiAbsPartIdx ) );
583  {
[56]584    if ( ( pcCU->getSlice()->getNumRefIdx( eRefList ) == 1 ) )
585    {
586      return;
587    }
[2]588
[56]589    if ( pcCU->getInterDir( uiAbsPartIdx ) & ( 1 << eRefList ) )
590    {
591      m_pcEntropyCoderIf->codeRefFrmIdx( pcCU, uiAbsPartIdx, eRefList );
592    }
[2]593  }
594
595  return;
596}
597
598/** encode motion vector difference for a PU block
599 * \param pcCU
600 * \param uiAbsPartIdx
601 * \param eRefList
602 * \returns Void
603 */
604Void TEncEntropy::encodeMvdPU( TComDataCU* pcCU, UInt uiAbsPartIdx, RefPicList eRefList )
605{
606  assert( !pcCU->isIntra( uiAbsPartIdx ) );
607
608  if ( pcCU->getInterDir( uiAbsPartIdx ) & ( 1 << eRefList ) )
609  {
610    m_pcEntropyCoderIf->codeMvd( pcCU, uiAbsPartIdx, eRefList );
611  }
612  return;
613}
614
615Void TEncEntropy::encodeMVPIdxPU( TComDataCU* pcCU, UInt uiAbsPartIdx, RefPicList eRefList )
616{
[608]617  if ( (pcCU->getInterDir( uiAbsPartIdx ) & ( 1 << eRefList )) )
[2]618  {
619    m_pcEntropyCoderIf->codeMVPIdx( pcCU, uiAbsPartIdx, eRefList );
620  }
621
622  return;
623}
624
625Void TEncEntropy::encodeQtCbf( TComDataCU* pcCU, UInt uiAbsPartIdx, TextType eType, UInt uiTrDepth )
626{
627  m_pcEntropyCoderIf->codeQtCbf( pcCU, uiAbsPartIdx, eType, uiTrDepth );
628}
629
630Void TEncEntropy::encodeTransformSubdivFlag( UInt uiSymbol, UInt uiCtx )
631{
632  m_pcEntropyCoderIf->codeTransformSubdivFlag( uiSymbol, uiCtx );
633}
634
635Void TEncEntropy::encodeQtRootCbf( TComDataCU* pcCU, UInt uiAbsPartIdx )
636{
637  m_pcEntropyCoderIf->codeQtRootCbf( pcCU, uiAbsPartIdx );
638}
639
[608]640Void TEncEntropy::encodeQtCbfZero( TComDataCU* pcCU, TextType eType, UInt uiTrDepth )
641{
642  m_pcEntropyCoderIf->codeQtCbfZero( pcCU, eType, uiTrDepth );
643}
644Void TEncEntropy::encodeQtRootCbfZero( TComDataCU* pcCU )
645{
646  m_pcEntropyCoderIf->codeQtRootCbfZero( pcCU );
647}
648
[2]649// dQP
650Void TEncEntropy::encodeQP( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool bRD )
651{
652  if( bRD )
[56]653  {
[2]654    uiAbsPartIdx = 0;
[56]655  }
[2]656 
[56]657  if ( pcCU->getSlice()->getPPS()->getUseDQP() )
[2]658  {
659    m_pcEntropyCoderIf->codeDeltaQP( pcCU, uiAbsPartIdx );
660  }
661}
662
663
664// texture
665/** encode coefficients
666 * \param pcCU
667 * \param uiAbsPartIdx
668 * \param uiDepth
669 * \param uiWidth
670 * \param uiHeight
671 */
[56]672Void TEncEntropy::encodeCoeff( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, UInt uiWidth, UInt uiHeight, Bool& bCodeDQP )
[2]673{
674  UInt uiMinCoeffSize = pcCU->getPic()->getMinCUWidth()*pcCU->getPic()->getMinCUHeight();
675  UInt uiLumaOffset   = uiMinCoeffSize*uiAbsPartIdx;
676  UInt uiChromaOffset = uiLumaOffset>>2;
[608]677   
678#if H_3D_DIM_SDC
[189]679  if( pcCU->getSDCFlag( uiAbsPartIdx ) )
680  {
681    assert( pcCU->getPartitionSize(uiAbsPartIdx) == SIZE_2Nx2N );
682    assert( pcCU->getTransformIdx(uiAbsPartIdx) == 0 );
683    assert( pcCU->getCbf(uiAbsPartIdx, TEXT_LUMA) == 1 );
684    assert( pcCU->getCbf(uiAbsPartIdx, TEXT_CHROMA_U) == 1 );
685    assert( pcCU->getCbf(uiAbsPartIdx, TEXT_CHROMA_V) == 1 );
[608]686    return;
687  }
[443]688#endif
[608]689
[655]690#if H_3D_INTER_SDC
[608]691  if( pcCU->getInterSDCFlag( uiAbsPartIdx ) )
692  {
693    assert( !pcCU->isSkipped( uiAbsPartIdx ) );
694    assert( !pcCU->isIntra( uiAbsPartIdx) );
695    assert( pcCU->getSlice()->getIsDepth() );
696
697    encodeInterSDCResidualData( pcCU, uiAbsPartIdx, false );
[189]698    return;
699  }
700#endif
[608]701
[2]702  if( pcCU->isIntra(uiAbsPartIdx) )
703  {
[608]704#if !H_MV
[56]705    DTRACE_CABAC_VL( g_nSymbolCounter++ )
[2]706    DTRACE_CABAC_T( "\tdecodeTransformIdx()\tCUDepth=" )
707    DTRACE_CABAC_V( uiDepth )
708    DTRACE_CABAC_T( "\n" )
[608]709#endif
[2]710  }
711  else
712  {
[608]713    if( !(pcCU->getMergeFlag( uiAbsPartIdx ) && pcCU->getPartitionSize(uiAbsPartIdx) == SIZE_2Nx2N ) )
[2]714    {
[608]715      m_pcEntropyCoderIf->codeQtRootCbf( pcCU, uiAbsPartIdx );
[2]716    }
[608]717    if ( !pcCU->getQtRootCbf( uiAbsPartIdx ) )
[189]718    {
[608]719      return;
[189]720    }
721  }
[608]722 
723  xEncodeTransform( pcCU, uiLumaOffset, uiChromaOffset, uiAbsPartIdx, uiDepth, uiWidth, uiHeight, 0, bCodeDQP);
[2]724}
725
[56]726Void TEncEntropy::encodeCoeffNxN( TComDataCU* pcCU, TCoeff* pcCoeff, UInt uiAbsPartIdx, UInt uiTrWidth, UInt uiTrHeight, UInt uiDepth, TextType eType )
[608]727{
728  // This is for Transform unit processing. This may be used at mode selection stage for Inter.
[56]729  m_pcEntropyCoderIf->codeCoeffNxN( pcCU, pcCoeff, uiAbsPartIdx, uiTrWidth, uiTrHeight, uiDepth, eType );
[2]730}
731
[56]732Void TEncEntropy::estimateBit (estBitsSbacStruct* pcEstBitsSbac, Int width, Int height, TextType eTType)
733{ 
734  eTType = eTType == TEXT_LUMA ? TEXT_LUMA : TEXT_CHROMA;
735 
736  m_pcEntropyCoderIf->estBit ( pcEstBitsSbac, width, height, eTType );
737}
738
739/** Encode SAO Offset
740 * \param  saoLcuParam SAO LCU paramters
741 */
[608]742Void TEncEntropy::encodeSaoOffset(SaoLcuParam* saoLcuParam, UInt compIdx)
[2]743{
[56]744  UInt uiSymbol;
745  Int i;
746
747  uiSymbol = saoLcuParam->typeIdx + 1;
[608]748  if (compIdx!=2)
749  {
750    m_pcEntropyCoderIf->codeSaoTypeIdx(uiSymbol);
751  }
[56]752  if (uiSymbol)
[2]753  {
[608]754    if (saoLcuParam->typeIdx < 4 && compIdx != 2)
755    {
756      saoLcuParam->subTypeIdx = saoLcuParam->typeIdx;
757    }
758    Int bitDepth = compIdx ? g_bitDepthC : g_bitDepthY;
759    Int offsetTh = 1 << min(bitDepth - 5,5);
[56]760    if( saoLcuParam->typeIdx == SAO_BO )
761    {
762      for( i=0; i< saoLcuParam->length; i++)
763      {
[608]764        UInt absOffset = ( (saoLcuParam->offset[i] < 0) ? -saoLcuParam->offset[i] : saoLcuParam->offset[i]);
765        m_pcEntropyCoderIf->codeSaoMaxUvlc(absOffset, offsetTh-1);
[56]766      } 
[608]767      for( i=0; i< saoLcuParam->length; i++)
[56]768      {
[608]769        if (saoLcuParam->offset[i] != 0)
770        {
771          UInt sign = (saoLcuParam->offset[i] < 0) ? 1 : 0 ;
772          m_pcEntropyCoderIf->codeSAOSign(sign);
773        }
[56]774      }
[608]775      uiSymbol = (UInt) (saoLcuParam->subTypeIdx);
776      m_pcEntropyCoderIf->codeSaoUflc(5, uiSymbol);
777    }
778    else if( saoLcuParam->typeIdx < 4 )
[56]779    {
[608]780      m_pcEntropyCoderIf->codeSaoMaxUvlc( saoLcuParam->offset[0], offsetTh-1);
781      m_pcEntropyCoderIf->codeSaoMaxUvlc( saoLcuParam->offset[1], offsetTh-1);
782      m_pcEntropyCoderIf->codeSaoMaxUvlc(-saoLcuParam->offset[2], offsetTh-1);
783      m_pcEntropyCoderIf->codeSaoMaxUvlc(-saoLcuParam->offset[3], offsetTh-1);
784      if (compIdx!=2)
[56]785      {
[608]786        uiSymbol = (UInt) (saoLcuParam->subTypeIdx);
787        m_pcEntropyCoderIf->codeSaoUflc(2, uiSymbol);
[56]788      }
789    }
790  }
791}
792
793/** Encode SAO unit interleaving
794* \param  rx
795* \param  ry
796* \param  pSaoParam
797* \param  pcCU
798* \param  iCUAddrInSlice
799* \param  iCUAddrUpInSlice
800* \param  bLFCrossSliceBoundaryFlag
[2]801 */
[608]802Void TEncEntropy::encodeSaoUnitInterleaving(Int compIdx, Bool saoFlag, Int rx, Int ry, SaoLcuParam* saoLcuParam, Int cuAddrInSlice, Int cuAddrUpInSlice, Int allowMergeLeft, Int allowMergeUp)
[2]803{
[608]804  if (saoFlag)
[56]805  {
[608]806    if (rx>0 && cuAddrInSlice!=0 && allowMergeLeft)
[56]807    {
[608]808      m_pcEntropyCoderIf->codeSaoMerge(saoLcuParam->mergeLeftFlag);
809    }
810    else
811    {
812      saoLcuParam->mergeLeftFlag = 0;
813    }
814    if (saoLcuParam->mergeLeftFlag == 0)
815    {
816      if ( (ry > 0) && (cuAddrUpInSlice>=0) && allowMergeUp )
[56]817      {
[608]818        m_pcEntropyCoderIf->codeSaoMerge(saoLcuParam->mergeUpFlag);
[56]819      }
820      else
821      {
[608]822        saoLcuParam->mergeUpFlag = 0;
[56]823      }
[608]824      if (!saoLcuParam->mergeUpFlag)
[56]825      {
[608]826        encodeSaoOffset(saoLcuParam, compIdx);
[56]827      }
828    }
829  }
830}
831
832Int TEncEntropy::countNonZeroCoeffs( TCoeff* pcCoef, UInt uiSize )
833{
834  Int count = 0;
835 
836  for ( Int i = 0; i < uiSize; i++ )
[2]837  {
[56]838    count += pcCoef[i] != 0;
[2]839  }
[56]840 
841  return count;
842}
[2]843
[56]844/** encode quantization matrix
845 * \param scalingList quantization matrix information
846 */
847Void TEncEntropy::encodeScalingList( TComScalingList* scalingList )
848{
849  m_pcEntropyCoderIf->codeScalingList( scalingList );
[2]850}
851
[655]852#if H_3D_INTER_SDC
[608]853Void TEncEntropy::encodeInterSDCFlag( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool bRD )
[56]854{
[608]855  if( !pcCU->getSlice()->getVPS()->getInterSDCFlag( pcCU->getSlice()->getLayerIdInVps() ) )
856  {
857    return;
858  }
[2]859
[608]860  if( !pcCU->getSlice()->getIsDepth() || pcCU->isIntra( uiAbsPartIdx ) || pcCU->isSkipped( uiAbsPartIdx ) )
[56]861  {
[608]862    return;
[56]863  }
[2]864
[189]865  if( bRD )
[608]866  {
[189]867    uiAbsPartIdx = 0;
[608]868  }
869
870  m_pcEntropyCoderIf->codeInterSDCFlag( pcCU, uiAbsPartIdx );
[189]871}
872
[608]873Void TEncEntropy::encodeInterSDCResidualData( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool bRD )
[189]874{
[608]875  if( !pcCU->getSlice()->getVPS()->getInterSDCFlag( pcCU->getSlice()->getLayerIdInVps() ) )
876  {
877    return;
878  }
879
880  if( !pcCU->getSlice()->getIsDepth() || pcCU->isIntra( uiAbsPartIdx ) || !pcCU->getInterSDCFlag( uiAbsPartIdx ) )
881  {
882    return;
883  }
884
[189]885  if( bRD )
[608]886  {
[189]887    uiAbsPartIdx = 0;
[608]888  }
889
[189]890  // number of segments depends on prediction mode for INTRA
[608]891  UInt uiNumSegments = ( pcCU->getPartitionSize( uiAbsPartIdx ) == SIZE_2Nx2N ) ? 1 : ( pcCU->getPartitionSize( uiAbsPartIdx ) == SIZE_NxN ? 4 : 2 );
892
[189]893  // encode residual data for each segment
894  for( UInt uiSeg = 0; uiSeg < uiNumSegments; uiSeg++ )
[608]895  {
896    m_pcEntropyCoderIf->codeInterSDCResidualData( pcCU, uiAbsPartIdx, uiSeg );
897  }
[189]898}
899#endif
900
[816]901#if H_3D_DBBP
902Void TEncEntropy::encodeDBBPFlag( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool bRD )
903{
904  if( bRD )
905  {
906    uiAbsPartIdx = 0;
907  }
908  m_pcEntropyCoderIf->codeDBBPFlag( pcCU, uiAbsPartIdx );
909}
910#endif
911
[56]912//! \}
Note: See TracBrowser for help on using the repository browser.