source: 3DVCSoftware/trunk/source/Lib/TLibEncoder/TEncEntropy.cpp @ 724

Last change on this file since 724 was 724, checked in by tech, 10 years ago

Merged HTM-8.2-dev0@723.

  • Property svn:eol-style set to native
File size: 24.5 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 SEC_ONLY_TEXTURE_IC_F0151
163  if ( pcCU->isIntra( uiAbsPartIdx ) || ( pcCU->getSlice()->getViewIndex() == 0 ) || pcCU->getSlice()->getIsDepth() )
164#else
[608]165  if ( pcCU->isIntra( uiAbsPartIdx ) || ( pcCU->getSlice()->getViewIndex() == 0 ) )
[724]166#endif
[443]167  {
168    return;
169  }
[608]170
171  if( !pcCU->getSlice()->getApplyIC() )
172    return;
173
[443]174  if( bRD )
175  {
176    uiAbsPartIdx = 0;
177  }
[608]178
179  if( pcCU->isICFlagRequired( uiAbsPartIdx ) )
180    m_pcEntropyCoderIf->codeICFlag( pcCU, uiAbsPartIdx );
[443]181}
182#endif
[2]183
[608]184#if H_3D_ARP
185Void TEncEntropy::encodeARPW( TComDataCU* pcCU, UInt uiAbsPartIdx )
[56]186{
[608]187  if( !pcCU->getSlice()->getARPStepNum() || pcCU->isIntra( uiAbsPartIdx ) ) 
[56]188  {
[608]189    return;
[56]190  }
191
[608]192  if ( pcCU->getPartitionSize(uiAbsPartIdx)!=SIZE_2Nx2N )
[56]193  {
[608]194    assert(pcCU->getARPW (uiAbsPartIdx) == 0);
[56]195  }
[608]196  else
[56]197  {
[608]198    m_pcEntropyCoderIf->codeARPW( pcCU, uiAbsPartIdx );
[56]199  }
200}
[608]201#endif
[56]202
[2]203/** encode prediction mode
204 * \param pcCU
205 * \param uiAbsPartIdx
206 * \param bRD
207 * \returns Void
208 */
209Void TEncEntropy::encodePredMode( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool bRD )
210{
211  if( bRD )
[56]212  {
[2]213    uiAbsPartIdx = 0;
[56]214  }
[2]215  if ( pcCU->getSlice()->isIntra() )
216  {
217    return;
218  }
[56]219
[2]220  m_pcEntropyCoderIf->codePredMode( pcCU, uiAbsPartIdx );
221}
222
223// Split mode
224Void TEncEntropy::encodeSplitFlag( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, Bool bRD )
225{
226  if( bRD )
[56]227  {
[2]228    uiAbsPartIdx = 0;
[56]229  }
[2]230  m_pcEntropyCoderIf->codeSplitFlag( pcCU, uiAbsPartIdx, uiDepth );
231}
232
233/** encode partition size
234 * \param pcCU
235 * \param uiAbsPartIdx
236 * \param uiDepth
237 * \param bRD
238 * \returns Void
239 */
240Void TEncEntropy::encodePartSize( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, Bool bRD )
241{
242  if( bRD )
[56]243  {
[2]244    uiAbsPartIdx = 0;
[56]245  }
[2]246  m_pcEntropyCoderIf->codePartSize( pcCU, uiAbsPartIdx, uiDepth );
247}
248
[56]249/** Encode I_PCM information.
250 * \param pcCU pointer to CU
251 * \param uiAbsPartIdx CU index
252 * \param bRD flag indicating estimation or encoding
253 * \returns Void
254 */
255Void TEncEntropy::encodeIPCMInfo( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool bRD )
[2]256{
[56]257  if(!pcCU->getSlice()->getSPS()->getUsePCM()
258    || pcCU->getWidth(uiAbsPartIdx) > (1<<pcCU->getSlice()->getSPS()->getPCMLog2MaxSize())
259    || pcCU->getWidth(uiAbsPartIdx) < (1<<pcCU->getSlice()->getSPS()->getPCMLog2MinSize()))
260  {
261    return;
262  }
[608]263#if H_3D_DIM_SDC
[189]264  if( pcCU->getSDCFlag(uiAbsPartIdx) )
265  {
266    return;
267  }
268#endif
269 
[56]270  if( bRD )
271  {
272    uiAbsPartIdx = 0;
273  }
274 
[608]275  m_pcEntropyCoderIf->codeIPCMInfo ( pcCU, uiAbsPartIdx );
[56]276}
277
[608]278Void TEncEntropy::xEncodeTransform( TComDataCU* pcCU,UInt offsetLuma, UInt offsetChroma, UInt uiAbsPartIdx, UInt uiDepth, UInt width, UInt height, UInt uiTrIdx, Bool& bCodeDQP )
[56]279{
[2]280  const UInt uiSubdiv = pcCU->getTransformIdx( uiAbsPartIdx ) + pcCU->getDepth( uiAbsPartIdx ) > uiDepth;
281  const UInt uiLog2TrafoSize = g_aucConvertToBit[pcCU->getSlice()->getSPS()->getMaxCUWidth()]+2 - uiDepth;
[56]282  UInt cbfY = pcCU->getCbf( uiAbsPartIdx, TEXT_LUMA    , uiTrIdx );
283  UInt cbfU = pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_U, uiTrIdx );
284  UInt cbfV = pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_V, uiTrIdx );
285
286  if(uiTrIdx==0)
[2]287  {
[56]288    m_bakAbsPartIdxCU = uiAbsPartIdx;
[2]289  }
[56]290  if( uiLog2TrafoSize == 2 )
[2]291  {
[56]292    UInt partNum = pcCU->getPic()->getNumPartInCU() >> ( ( uiDepth - 1 ) << 1 );
293    if( ( uiAbsPartIdx % partNum ) == 0 )
294    {
295      m_uiBakAbsPartIdx   = uiAbsPartIdx;
296      m_uiBakChromaOffset = offsetChroma;
297    }
298    else if( ( uiAbsPartIdx % partNum ) == (partNum - 1) )
299    {
300      cbfU = pcCU->getCbf( m_uiBakAbsPartIdx, TEXT_CHROMA_U, uiTrIdx );
301      cbfV = pcCU->getCbf( m_uiBakAbsPartIdx, TEXT_CHROMA_V, uiTrIdx );
302    }
[2]303  }
[608]304 
305  if( pcCU->getPredictionMode(uiAbsPartIdx) == MODE_INTRA && pcCU->getPartitionSize(uiAbsPartIdx) == SIZE_NxN && uiDepth == pcCU->getDepth(uiAbsPartIdx) )
306  {
307    assert( uiSubdiv );
308  }
309  else if( pcCU->getPredictionMode(uiAbsPartIdx) == MODE_INTER && (pcCU->getPartitionSize(uiAbsPartIdx) != SIZE_2Nx2N) && uiDepth == pcCU->getDepth(uiAbsPartIdx) &&  (pcCU->getSlice()->getSPS()->getQuadtreeTUMaxDepthInter() == 1) )
310  {
311    if ( uiLog2TrafoSize > pcCU->getQuadtreeTULog2MinSizeInCU(uiAbsPartIdx) )
[2]312    {
313      assert( uiSubdiv );
314    }
[608]315    else
[56]316    {
[608]317      assert(!uiSubdiv );
[56]318    }
[608]319  }
320  else if( uiLog2TrafoSize > pcCU->getSlice()->getSPS()->getQuadtreeTULog2MaxSize() )
321  {
322    assert( uiSubdiv );
323  }
324  else if( uiLog2TrafoSize == pcCU->getSlice()->getSPS()->getQuadtreeTULog2MinSize() )
325  {
326    assert( !uiSubdiv );
327  }
328  else if( uiLog2TrafoSize == pcCU->getQuadtreeTULog2MinSizeInCU(uiAbsPartIdx) )
329  {
330    assert( !uiSubdiv );
331  }
332  else
333  {
334    assert( uiLog2TrafoSize > pcCU->getQuadtreeTULog2MinSizeInCU(uiAbsPartIdx) );
335    m_pcEntropyCoderIf->codeTransformSubdivFlag( uiSubdiv, 5 - uiLog2TrafoSize );
336  }
337
338  const UInt uiTrDepthCurr = uiDepth - pcCU->getDepth( uiAbsPartIdx );
339  const Bool bFirstCbfOfCU = uiTrDepthCurr == 0;
340  if( bFirstCbfOfCU || uiLog2TrafoSize > 2 )
341  {
342    if( bFirstCbfOfCU || pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_U, uiTrDepthCurr - 1 ) )
[56]343    {
[608]344      m_pcEntropyCoderIf->codeQtCbf( pcCU, uiAbsPartIdx, TEXT_CHROMA_U, uiTrDepthCurr );
[56]345    }
[608]346    if( bFirstCbfOfCU || pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_V, uiTrDepthCurr - 1 ) )
[2]347    {
[608]348      m_pcEntropyCoderIf->codeQtCbf( pcCU, uiAbsPartIdx, TEXT_CHROMA_V, uiTrDepthCurr );
[2]349    }
[608]350  }
351  else if( uiLog2TrafoSize == 2 )
352  {
353    assert( pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_U, uiTrDepthCurr ) == pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_U, uiTrDepthCurr - 1 ) );
354    assert( pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_V, uiTrDepthCurr ) == pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_V, uiTrDepthCurr - 1 ) );
355  }
356 
357  if( uiSubdiv )
358  {
359    UInt size;
360    width  >>= 1;
361    height >>= 1;
362    size = width*height;
363    uiTrIdx++;
364    ++uiDepth;
365    const UInt partNum = pcCU->getPic()->getNumPartInCU() >> (uiDepth << 1);
366   
367    xEncodeTransform( pcCU, offsetLuma, offsetChroma, uiAbsPartIdx, uiDepth, width, height, uiTrIdx, bCodeDQP );
368
369    uiAbsPartIdx += partNum;  offsetLuma += size;  offsetChroma += (size>>2);
370    xEncodeTransform( pcCU, offsetLuma, offsetChroma, uiAbsPartIdx, uiDepth, width, height, uiTrIdx, bCodeDQP );
371
372    uiAbsPartIdx += partNum;  offsetLuma += size;  offsetChroma += (size>>2);
373    xEncodeTransform( pcCU, offsetLuma, offsetChroma, uiAbsPartIdx, uiDepth, width, height, uiTrIdx, bCodeDQP );
374
375    uiAbsPartIdx += partNum;  offsetLuma += size;  offsetChroma += (size>>2);
376    xEncodeTransform( pcCU, offsetLuma, offsetChroma, uiAbsPartIdx, uiDepth, width, height, uiTrIdx, bCodeDQP );
377  }
378  else
379  {
380#if !H_MV_ENC_DEC_TRAC
[2]381    {
[608]382      DTRACE_CABAC_VL( g_nSymbolCounter++ );
383      DTRACE_CABAC_T( "\tTrIdx: abspart=" );
384      DTRACE_CABAC_V( uiAbsPartIdx );
385      DTRACE_CABAC_T( "\tdepth=" );
386      DTRACE_CABAC_V( uiDepth );
387      DTRACE_CABAC_T( "\ttrdepth=" );
388      DTRACE_CABAC_V( pcCU->getTransformIdx( uiAbsPartIdx ) );
389      DTRACE_CABAC_T( "\n" );
[2]390    }
[608]391#endif
392   
393    if( pcCU->getPredictionMode(uiAbsPartIdx) != MODE_INTRA && uiDepth == pcCU->getDepth( uiAbsPartIdx ) && !pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_U, 0 ) && !pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_V, 0 ) )
394    {
395      assert( pcCU->getCbf( uiAbsPartIdx, TEXT_LUMA, 0 ) );
396      //      printf( "saved one bin! " );
397    }
[2]398    else
399    {
[608]400      m_pcEntropyCoderIf->codeQtCbf( pcCU, uiAbsPartIdx, TEXT_LUMA, pcCU->getTransformIdx( uiAbsPartIdx ) );
[2]401    }
[56]402
[608]403
404    if ( cbfY || cbfU || cbfV )
[2]405    {
[608]406      // dQP: only for LCU once
407      if ( pcCU->getSlice()->getPPS()->getUseDQP() )
[2]408      {
[608]409        if ( bCodeDQP )
[2]410        {
[608]411          encodeQP( pcCU, m_bakAbsPartIdxCU );
412          bCodeDQP = false;
[2]413        }
414      }
415    }
[608]416    if( cbfY )
[2]417    {
[608]418      Int trWidth = width;
419      Int trHeight = height;
420      m_pcEntropyCoderIf->codeCoeffNxN( pcCU, (pcCU->getCoeffY()+offsetLuma), uiAbsPartIdx, trWidth, trHeight, uiDepth, TEXT_LUMA );
[2]421    }
[608]422    if( uiLog2TrafoSize > 2 )
[2]423    {
[608]424      Int trWidth = width >> 1;
425      Int trHeight = height >> 1;
426      if( cbfU )
[2]427      {
[608]428        m_pcEntropyCoderIf->codeCoeffNxN( pcCU, (pcCU->getCoeffCb()+offsetChroma), uiAbsPartIdx, trWidth, trHeight, uiDepth, TEXT_CHROMA_U );
[2]429      }
[608]430      if( cbfV )
[56]431      {
[608]432        m_pcEntropyCoderIf->codeCoeffNxN( pcCU, (pcCU->getCoeffCr()+offsetChroma), uiAbsPartIdx, trWidth, trHeight, uiDepth, TEXT_CHROMA_V );
[56]433      }
[608]434    }
435    else
436    {
437      UInt partNum = pcCU->getPic()->getNumPartInCU() >> ( ( uiDepth - 1 ) << 1 );
438      if( ( uiAbsPartIdx % partNum ) == (partNum - 1) )
[2]439      {
[56]440        Int trWidth = width;
441        Int trHeight = height;
442        if( cbfU )
[2]443        {
[608]444          m_pcEntropyCoderIf->codeCoeffNxN( pcCU, (pcCU->getCoeffCb()+m_uiBakChromaOffset), m_uiBakAbsPartIdx, trWidth, trHeight, uiDepth, TEXT_CHROMA_U );
[2]445        }
[56]446        if( cbfV )
447        {
[608]448          m_pcEntropyCoderIf->codeCoeffNxN( pcCU, (pcCU->getCoeffCr()+m_uiBakChromaOffset), m_uiBakAbsPartIdx, trWidth, trHeight, uiDepth, TEXT_CHROMA_V );
[56]449        }
[2]450      }
451    }
452  }
453}
454
455// Intra direction for Luma
[608]456Void TEncEntropy::encodeIntraDirModeLuma  ( TComDataCU* pcCU, UInt absPartIdx, Bool isMultiplePU )
[2]457{
[608]458  m_pcEntropyCoderIf->codeIntraDirLumaAng( pcCU, absPartIdx , isMultiplePU);
[2]459}
460
461// Intra direction for Chroma
462Void TEncEntropy::encodeIntraDirModeChroma( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool bRD )
463{
464  if( bRD )
[56]465  {
[2]466    uiAbsPartIdx = 0;
[56]467  }
[2]468 
469  m_pcEntropyCoderIf->codeIntraDirChroma( pcCU, uiAbsPartIdx );
470}
471
[608]472Void TEncEntropy::encodePredInfo( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool bRD )
[2]473{
474  if( bRD )
[56]475  {
[2]476    uiAbsPartIdx = 0;
[56]477  }
[2]478  if( pcCU->isIntra( uiAbsPartIdx ) )                                 // If it is Intra mode, encode intra prediction mode.
479  {
[608]480    encodeIntraDirModeLuma  ( pcCU, uiAbsPartIdx,true );
481#if H_3D_DIM_SDC
482    if(!pcCU->getSDCFlag(uiAbsPartIdx))
[443]483#endif
[608]484    encodeIntraDirModeChroma( pcCU, uiAbsPartIdx, bRD );
[2]485  }
486  else                                                                // if it is Inter mode, encode motion vector and reference index
487  {
[56]488    encodePUWise( pcCU, uiAbsPartIdx, bRD );
[2]489  }
490}
491
492/** encode motion information for every PU block
493 * \param pcCU
494 * \param uiAbsPartIdx
495 * \param bRD
496 * \returns Void
497 */
498Void TEncEntropy::encodePUWise( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool bRD )
499{
500  if ( bRD )
[56]501  {
[2]502    uiAbsPartIdx = 0;
[56]503  }
504 
[2]505  PartSize ePartSize = pcCU->getPartitionSize( uiAbsPartIdx );
506  UInt uiNumPU = ( ePartSize == SIZE_2Nx2N ? 1 : ( ePartSize == SIZE_NxN ? 4 : 2 ) );
507  UInt uiDepth = pcCU->getDepth( uiAbsPartIdx );
508  UInt uiPUOffset = ( g_auiPUOffset[UInt( ePartSize )] << ( ( pcCU->getSlice()->getSPS()->getMaxCUDepth() - uiDepth ) << 1 ) ) >> 4;
509
510  for ( UInt uiPartIdx = 0, uiSubPartIdx = uiAbsPartIdx; uiPartIdx < uiNumPU; uiPartIdx++, uiSubPartIdx += uiPUOffset )
511  {
[608]512#if H_MV_ENC_DEC_TRAC
513    DTRACE_PU_S("=========== prediction_unit ===========\n")
514       //Todo:
515      //DTRACE_PU("x0", uiLPelX)
516      //DTRACE_PU("x1", uiTPelY)
517#endif
518    encodeMergeFlag( pcCU, uiSubPartIdx );
[2]519    if ( pcCU->getMergeFlag( uiSubPartIdx ) )
520    {
[608]521      encodeMergeIndex( pcCU, uiSubPartIdx );
[2]522    }
523    else
524    {
525      encodeInterDirPU( pcCU, uiSubPartIdx );
526      for ( UInt uiRefListIdx = 0; uiRefListIdx < 2; uiRefListIdx++ )
527      {
528        if ( pcCU->getSlice()->getNumRefIdx( RefPicList( uiRefListIdx ) ) > 0 )
529        {
530          encodeRefFrmIdxPU ( pcCU, uiSubPartIdx, RefPicList( uiRefListIdx ) );
531          encodeMvdPU       ( pcCU, uiSubPartIdx, RefPicList( uiRefListIdx ) );
532          encodeMVPIdxPU    ( pcCU, uiSubPartIdx, RefPicList( uiRefListIdx ) );
533        }
534      }
535    }
536  }
537
538  return;
539}
540
541Void TEncEntropy::encodeInterDirPU( TComDataCU* pcCU, UInt uiAbsPartIdx )
542{
543  if ( !pcCU->getSlice()->isInterB() )
544  {
545    return;
546  }
547
548  m_pcEntropyCoderIf->codeInterDir( pcCU, uiAbsPartIdx );
549  return;
550}
551
552/** encode reference frame index for a PU block
553 * \param pcCU
554 * \param uiAbsPartIdx
555 * \param eRefList
556 * \returns Void
557 */
558Void TEncEntropy::encodeRefFrmIdxPU( TComDataCU* pcCU, UInt uiAbsPartIdx, RefPicList eRefList )
559{
560  assert( !pcCU->isIntra( uiAbsPartIdx ) );
561  {
[56]562    if ( ( pcCU->getSlice()->getNumRefIdx( eRefList ) == 1 ) )
563    {
564      return;
565    }
[2]566
[56]567    if ( pcCU->getInterDir( uiAbsPartIdx ) & ( 1 << eRefList ) )
568    {
569      m_pcEntropyCoderIf->codeRefFrmIdx( pcCU, uiAbsPartIdx, eRefList );
570    }
[2]571  }
572
573  return;
574}
575
576/** encode motion vector difference for a PU block
577 * \param pcCU
578 * \param uiAbsPartIdx
579 * \param eRefList
580 * \returns Void
581 */
582Void TEncEntropy::encodeMvdPU( TComDataCU* pcCU, UInt uiAbsPartIdx, RefPicList eRefList )
583{
584  assert( !pcCU->isIntra( uiAbsPartIdx ) );
585
586  if ( pcCU->getInterDir( uiAbsPartIdx ) & ( 1 << eRefList ) )
587  {
588    m_pcEntropyCoderIf->codeMvd( pcCU, uiAbsPartIdx, eRefList );
589  }
590  return;
591}
592
593Void TEncEntropy::encodeMVPIdxPU( TComDataCU* pcCU, UInt uiAbsPartIdx, RefPicList eRefList )
594{
[608]595  if ( (pcCU->getInterDir( uiAbsPartIdx ) & ( 1 << eRefList )) )
[2]596  {
597    m_pcEntropyCoderIf->codeMVPIdx( pcCU, uiAbsPartIdx, eRefList );
598  }
599
600  return;
601}
602
603Void TEncEntropy::encodeQtCbf( TComDataCU* pcCU, UInt uiAbsPartIdx, TextType eType, UInt uiTrDepth )
604{
605  m_pcEntropyCoderIf->codeQtCbf( pcCU, uiAbsPartIdx, eType, uiTrDepth );
606}
607
608Void TEncEntropy::encodeTransformSubdivFlag( UInt uiSymbol, UInt uiCtx )
609{
610  m_pcEntropyCoderIf->codeTransformSubdivFlag( uiSymbol, uiCtx );
611}
612
613Void TEncEntropy::encodeQtRootCbf( TComDataCU* pcCU, UInt uiAbsPartIdx )
614{
615  m_pcEntropyCoderIf->codeQtRootCbf( pcCU, uiAbsPartIdx );
616}
617
[608]618Void TEncEntropy::encodeQtCbfZero( TComDataCU* pcCU, TextType eType, UInt uiTrDepth )
619{
620  m_pcEntropyCoderIf->codeQtCbfZero( pcCU, eType, uiTrDepth );
621}
622Void TEncEntropy::encodeQtRootCbfZero( TComDataCU* pcCU )
623{
624  m_pcEntropyCoderIf->codeQtRootCbfZero( pcCU );
625}
626
[2]627// dQP
628Void TEncEntropy::encodeQP( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool bRD )
629{
630  if( bRD )
[56]631  {
[2]632    uiAbsPartIdx = 0;
[56]633  }
[2]634 
[56]635  if ( pcCU->getSlice()->getPPS()->getUseDQP() )
[2]636  {
637    m_pcEntropyCoderIf->codeDeltaQP( pcCU, uiAbsPartIdx );
638  }
639}
640
641
642// texture
643/** encode coefficients
644 * \param pcCU
645 * \param uiAbsPartIdx
646 * \param uiDepth
647 * \param uiWidth
648 * \param uiHeight
649 */
[56]650Void TEncEntropy::encodeCoeff( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, UInt uiWidth, UInt uiHeight, Bool& bCodeDQP )
[2]651{
652  UInt uiMinCoeffSize = pcCU->getPic()->getMinCUWidth()*pcCU->getPic()->getMinCUHeight();
653  UInt uiLumaOffset   = uiMinCoeffSize*uiAbsPartIdx;
654  UInt uiChromaOffset = uiLumaOffset>>2;
[608]655   
656#if H_3D_DIM_SDC
[189]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 );
[608]664    return;
665  }
[443]666#endif
[608]667
[655]668#if H_3D_INTER_SDC
[608]669  if( pcCU->getInterSDCFlag( uiAbsPartIdx ) )
670  {
671    assert( !pcCU->isSkipped( uiAbsPartIdx ) );
672    assert( !pcCU->isIntra( uiAbsPartIdx) );
673    assert( pcCU->getSlice()->getIsDepth() );
674
675    encodeInterSDCResidualData( pcCU, uiAbsPartIdx, false );
[189]676    return;
677  }
678#endif
[608]679
[2]680  if( pcCU->isIntra(uiAbsPartIdx) )
681  {
[608]682#if !H_MV
[56]683    DTRACE_CABAC_VL( g_nSymbolCounter++ )
[2]684    DTRACE_CABAC_T( "\tdecodeTransformIdx()\tCUDepth=" )
685    DTRACE_CABAC_V( uiDepth )
686    DTRACE_CABAC_T( "\n" )
[608]687#endif
[2]688  }
689  else
690  {
[608]691    if( !(pcCU->getMergeFlag( uiAbsPartIdx ) && pcCU->getPartitionSize(uiAbsPartIdx) == SIZE_2Nx2N ) )
[2]692    {
[608]693      m_pcEntropyCoderIf->codeQtRootCbf( pcCU, uiAbsPartIdx );
[2]694    }
[608]695    if ( !pcCU->getQtRootCbf( uiAbsPartIdx ) )
[189]696    {
[608]697      return;
[189]698    }
699  }
[608]700 
701  xEncodeTransform( pcCU, uiLumaOffset, uiChromaOffset, uiAbsPartIdx, uiDepth, uiWidth, uiHeight, 0, bCodeDQP);
[2]702}
703
[56]704Void TEncEntropy::encodeCoeffNxN( TComDataCU* pcCU, TCoeff* pcCoeff, UInt uiAbsPartIdx, UInt uiTrWidth, UInt uiTrHeight, UInt uiDepth, TextType eType )
[608]705{
706  // This is for Transform unit processing. This may be used at mode selection stage for Inter.
[56]707  m_pcEntropyCoderIf->codeCoeffNxN( pcCU, pcCoeff, uiAbsPartIdx, uiTrWidth, uiTrHeight, uiDepth, eType );
[2]708}
709
[56]710Void TEncEntropy::estimateBit (estBitsSbacStruct* pcEstBitsSbac, Int width, Int height, TextType eTType)
711{ 
712  eTType = eTType == TEXT_LUMA ? TEXT_LUMA : TEXT_CHROMA;
713 
714  m_pcEntropyCoderIf->estBit ( pcEstBitsSbac, width, height, eTType );
715}
716
717/** Encode SAO Offset
718 * \param  saoLcuParam SAO LCU paramters
719 */
[608]720Void TEncEntropy::encodeSaoOffset(SaoLcuParam* saoLcuParam, UInt compIdx)
[2]721{
[56]722  UInt uiSymbol;
723  Int i;
724
725  uiSymbol = saoLcuParam->typeIdx + 1;
[608]726  if (compIdx!=2)
727  {
728    m_pcEntropyCoderIf->codeSaoTypeIdx(uiSymbol);
729  }
[56]730  if (uiSymbol)
[2]731  {
[608]732    if (saoLcuParam->typeIdx < 4 && compIdx != 2)
733    {
734      saoLcuParam->subTypeIdx = saoLcuParam->typeIdx;
735    }
736    Int bitDepth = compIdx ? g_bitDepthC : g_bitDepthY;
737    Int offsetTh = 1 << min(bitDepth - 5,5);
[56]738    if( saoLcuParam->typeIdx == SAO_BO )
739    {
740      for( i=0; i< saoLcuParam->length; i++)
741      {
[608]742        UInt absOffset = ( (saoLcuParam->offset[i] < 0) ? -saoLcuParam->offset[i] : saoLcuParam->offset[i]);
743        m_pcEntropyCoderIf->codeSaoMaxUvlc(absOffset, offsetTh-1);
[56]744      } 
[608]745      for( i=0; i< saoLcuParam->length; i++)
[56]746      {
[608]747        if (saoLcuParam->offset[i] != 0)
748        {
749          UInt sign = (saoLcuParam->offset[i] < 0) ? 1 : 0 ;
750          m_pcEntropyCoderIf->codeSAOSign(sign);
751        }
[56]752      }
[608]753      uiSymbol = (UInt) (saoLcuParam->subTypeIdx);
754      m_pcEntropyCoderIf->codeSaoUflc(5, uiSymbol);
755    }
756    else if( saoLcuParam->typeIdx < 4 )
[56]757    {
[608]758      m_pcEntropyCoderIf->codeSaoMaxUvlc( saoLcuParam->offset[0], offsetTh-1);
759      m_pcEntropyCoderIf->codeSaoMaxUvlc( saoLcuParam->offset[1], offsetTh-1);
760      m_pcEntropyCoderIf->codeSaoMaxUvlc(-saoLcuParam->offset[2], offsetTh-1);
761      m_pcEntropyCoderIf->codeSaoMaxUvlc(-saoLcuParam->offset[3], offsetTh-1);
762      if (compIdx!=2)
[56]763      {
[608]764        uiSymbol = (UInt) (saoLcuParam->subTypeIdx);
765        m_pcEntropyCoderIf->codeSaoUflc(2, uiSymbol);
[56]766      }
767    }
768  }
769}
770
771/** Encode SAO unit interleaving
772* \param  rx
773* \param  ry
774* \param  pSaoParam
775* \param  pcCU
776* \param  iCUAddrInSlice
777* \param  iCUAddrUpInSlice
778* \param  bLFCrossSliceBoundaryFlag
[2]779 */
[608]780Void TEncEntropy::encodeSaoUnitInterleaving(Int compIdx, Bool saoFlag, Int rx, Int ry, SaoLcuParam* saoLcuParam, Int cuAddrInSlice, Int cuAddrUpInSlice, Int allowMergeLeft, Int allowMergeUp)
[2]781{
[608]782  if (saoFlag)
[56]783  {
[608]784    if (rx>0 && cuAddrInSlice!=0 && allowMergeLeft)
[56]785    {
[608]786      m_pcEntropyCoderIf->codeSaoMerge(saoLcuParam->mergeLeftFlag);
787    }
788    else
789    {
790      saoLcuParam->mergeLeftFlag = 0;
791    }
792    if (saoLcuParam->mergeLeftFlag == 0)
793    {
794      if ( (ry > 0) && (cuAddrUpInSlice>=0) && allowMergeUp )
[56]795      {
[608]796        m_pcEntropyCoderIf->codeSaoMerge(saoLcuParam->mergeUpFlag);
[56]797      }
798      else
799      {
[608]800        saoLcuParam->mergeUpFlag = 0;
[56]801      }
[608]802      if (!saoLcuParam->mergeUpFlag)
[56]803      {
[608]804        encodeSaoOffset(saoLcuParam, compIdx);
[56]805      }
806    }
807  }
808}
809
810Int TEncEntropy::countNonZeroCoeffs( TCoeff* pcCoef, UInt uiSize )
811{
812  Int count = 0;
813 
814  for ( Int i = 0; i < uiSize; i++ )
[2]815  {
[56]816    count += pcCoef[i] != 0;
[2]817  }
[56]818 
819  return count;
820}
[2]821
[56]822/** encode quantization matrix
823 * \param scalingList quantization matrix information
824 */
825Void TEncEntropy::encodeScalingList( TComScalingList* scalingList )
826{
827  m_pcEntropyCoderIf->codeScalingList( scalingList );
[2]828}
829
[655]830#if H_3D_INTER_SDC
[608]831Void TEncEntropy::encodeInterSDCFlag( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool bRD )
[56]832{
[608]833  if( !pcCU->getSlice()->getVPS()->getInterSDCFlag( pcCU->getSlice()->getLayerIdInVps() ) )
834  {
835    return;
836  }
[2]837
[608]838  if( !pcCU->getSlice()->getIsDepth() || pcCU->isIntra( uiAbsPartIdx ) || pcCU->isSkipped( uiAbsPartIdx ) )
[56]839  {
[608]840    return;
[56]841  }
[2]842
[189]843  if( bRD )
[608]844  {
[189]845    uiAbsPartIdx = 0;
[608]846  }
847
848  m_pcEntropyCoderIf->codeInterSDCFlag( pcCU, uiAbsPartIdx );
[189]849}
850
[608]851Void TEncEntropy::encodeInterSDCResidualData( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool bRD )
[189]852{
[608]853  if( !pcCU->getSlice()->getVPS()->getInterSDCFlag( pcCU->getSlice()->getLayerIdInVps() ) )
854  {
855    return;
856  }
857
858  if( !pcCU->getSlice()->getIsDepth() || pcCU->isIntra( uiAbsPartIdx ) || !pcCU->getInterSDCFlag( uiAbsPartIdx ) )
859  {
860    return;
861  }
862
[189]863  if( bRD )
[608]864  {
[189]865    uiAbsPartIdx = 0;
[608]866  }
867
[189]868  // number of segments depends on prediction mode for INTRA
[608]869  UInt uiNumSegments = ( pcCU->getPartitionSize( uiAbsPartIdx ) == SIZE_2Nx2N ) ? 1 : ( pcCU->getPartitionSize( uiAbsPartIdx ) == SIZE_NxN ? 4 : 2 );
870
[189]871  // encode residual data for each segment
872  for( UInt uiSeg = 0; uiSeg < uiNumSegments; uiSeg++ )
[608]873  {
874    m_pcEntropyCoderIf->codeInterSDCResidualData( pcCU, uiAbsPartIdx, uiSeg );
875  }
[189]876}
877#endif
878
[56]879//! \}
Note: See TracBrowser for help on using the repository browser.