source: 3DVCSoftware/branches/HTM-14.0-MV-draft-3/source/Lib/TLibEncoder/TEncEntropy.cpp @ 1213

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

Removed 3D-HEVC.

  • Property svn:eol-style set to native
File size: 19.0 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 *
[1179]6* Copyright (c) 2010-2015, 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{
53  m_pcEntropyCoderIf->codeSliceHeader( pcSlice );
54  return;
55}
56
[56]57Void  TEncEntropy::encodeTilesWPPEntryPoint( TComSlice* pSlice )
58{
59  m_pcEntropyCoderIf->codeTilesWPPEntryPoint( pSlice );
60}
61
[2]62Void TEncEntropy::encodeTerminatingBit      ( UInt uiIsLast )
63{
64  m_pcEntropyCoderIf->codeTerminatingBit( uiIsLast );
65 
66  return;
67}
68
69Void TEncEntropy::encodeSliceFinish()
70{
71  m_pcEntropyCoderIf->codeSliceFinish();
72}
73
74Void TEncEntropy::encodePPS( TComPPS* pcPPS )
75{
76  m_pcEntropyCoderIf->codePPS( pcPPS );
77  return;
78}
79
[1124]80Void TEncEntropy::encodeSPS( TComSPS* pcSPS )
81{
82  m_pcEntropyCoderIf->codeSPS( pcSPS );
83  return;
84}
[2]85
[608]86Void TEncEntropy::encodeCUTransquantBypassFlag( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool bRD )
[2]87{
88  if( bRD )
[56]89  {
[2]90    uiAbsPartIdx = 0;
[56]91  }
[608]92  m_pcEntropyCoderIf->codeCUTransquantBypassFlag( pcCU, uiAbsPartIdx );
[2]93}
94
[608]95Void TEncEntropy::encodeVPS( TComVPS* pcVPS )
[189]96{
[608]97  m_pcEntropyCoderIf->codeVPS( pcVPS );
98  return;
99}
100
101Void TEncEntropy::encodeSkipFlag( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool bRD )
102{
103  if ( pcCU->getSlice()->isIntra() )
[189]104  {
105    return;
106  }
107  if( bRD )
108  {
109    uiAbsPartIdx = 0;
110  }
[608]111  m_pcEntropyCoderIf->codeSkipFlag( pcCU, uiAbsPartIdx );
[189]112}
[1179]113
114
[2]115/** encode merge flag
116 * \param pcCU
117 * \param uiAbsPartIdx
118 * \returns Void
119 */
[608]120Void TEncEntropy::encodeMergeFlag( TComDataCU* pcCU, UInt uiAbsPartIdx )
[2]121{ 
[56]122  // at least one merge candidate exists
123  m_pcEntropyCoderIf->codeMergeFlag( pcCU, uiAbsPartIdx );
[2]124}
125
126/** encode merge index
127 * \param pcCU
128 * \param uiAbsPartIdx
129 * \param uiPUIdx
130 * \param bRD
131 * \returns Void
132 */
[608]133Void TEncEntropy::encodeMergeIndex( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool bRD )
[2]134{
135  if( bRD )
136  {
137    uiAbsPartIdx = 0;
138    assert( pcCU->getPartitionSize(uiAbsPartIdx) == SIZE_2Nx2N );
139  }
[608]140  m_pcEntropyCoderIf->codeMergeIndex( pcCU, uiAbsPartIdx );
[2]141}
142
[608]143
144
[2]145/** encode prediction mode
146 * \param pcCU
147 * \param uiAbsPartIdx
148 * \param bRD
149 * \returns Void
150 */
151Void TEncEntropy::encodePredMode( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool bRD )
152{
153  if( bRD )
[56]154  {
[2]155    uiAbsPartIdx = 0;
[56]156  }
[2]157  if ( pcCU->getSlice()->isIntra() )
158  {
159    return;
160  }
[56]161
[2]162  m_pcEntropyCoderIf->codePredMode( pcCU, uiAbsPartIdx );
163}
164
165// Split mode
166Void TEncEntropy::encodeSplitFlag( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, Bool bRD )
167{
168  if( bRD )
[56]169  {
[2]170    uiAbsPartIdx = 0;
[56]171  }
[2]172  m_pcEntropyCoderIf->codeSplitFlag( pcCU, uiAbsPartIdx, uiDepth );
173}
174
175/** encode partition size
176 * \param pcCU
177 * \param uiAbsPartIdx
178 * \param uiDepth
179 * \param bRD
180 * \returns Void
181 */
182Void TEncEntropy::encodePartSize( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, Bool bRD )
183{
184  if( bRD )
[56]185  {
[2]186    uiAbsPartIdx = 0;
[56]187  }
[833]188 
[2]189  m_pcEntropyCoderIf->codePartSize( pcCU, uiAbsPartIdx, uiDepth );
[833]190 
[2]191}
192
[56]193/** Encode I_PCM information.
194 * \param pcCU pointer to CU
195 * \param uiAbsPartIdx CU index
196 * \param bRD flag indicating estimation or encoding
197 * \returns Void
198 */
199Void TEncEntropy::encodeIPCMInfo( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool bRD )
[2]200{
[56]201  if(!pcCU->getSlice()->getSPS()->getUsePCM()
202    || pcCU->getWidth(uiAbsPartIdx) > (1<<pcCU->getSlice()->getSPS()->getPCMLog2MaxSize())
203    || pcCU->getWidth(uiAbsPartIdx) < (1<<pcCU->getSlice()->getSPS()->getPCMLog2MinSize()))
204  {
205    return;
206  }
[189]207 
[56]208  if( bRD )
209  {
210    uiAbsPartIdx = 0;
211  }
212 
[608]213  m_pcEntropyCoderIf->codeIPCMInfo ( pcCU, uiAbsPartIdx );
[56]214}
215
[608]216Void TEncEntropy::xEncodeTransform( TComDataCU* pcCU,UInt offsetLuma, UInt offsetChroma, UInt uiAbsPartIdx, UInt uiDepth, UInt width, UInt height, UInt uiTrIdx, Bool& bCodeDQP )
[56]217{
[1179]218
219#if H_MV_ENC_DEC_TRAC
220#if ENC_DEC_TRACE
221  UInt uiLPelX   = pcCU->getCUPelX() + g_auiRasterToPelX[ g_auiZscanToRaster[uiAbsPartIdx] ];
222  UInt uiTPelY   = pcCU->getCUPelY() + g_auiRasterToPelY[ g_auiZscanToRaster[uiAbsPartIdx] ];
223
224  DTRACE_TU_S("=========== transform_tree ===========\n")
225  DTRACE_TU("x0", uiLPelX)
226  DTRACE_TU("x1", uiTPelY)
227  DTRACE_TU("log2TrafoSize", g_uiMaxCUWidth>>uiDepth)
228  DTRACE_TU("trafoDepth"  , uiDepth)
229#endif
230#endif
231
[2]232  const UInt uiSubdiv = pcCU->getTransformIdx( uiAbsPartIdx ) + pcCU->getDepth( uiAbsPartIdx ) > uiDepth;
233  const UInt uiLog2TrafoSize = g_aucConvertToBit[pcCU->getSlice()->getSPS()->getMaxCUWidth()]+2 - uiDepth;
[56]234  UInt cbfY = pcCU->getCbf( uiAbsPartIdx, TEXT_LUMA    , uiTrIdx );
235  UInt cbfU = pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_U, uiTrIdx );
236  UInt cbfV = pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_V, uiTrIdx );
237  if(uiTrIdx==0)
[2]238  {
[56]239    m_bakAbsPartIdxCU = uiAbsPartIdx;
[2]240  }
[56]241  if( uiLog2TrafoSize == 2 )
[2]242  {
[56]243    UInt partNum = pcCU->getPic()->getNumPartInCU() >> ( ( uiDepth - 1 ) << 1 );
244    if( ( uiAbsPartIdx % partNum ) == 0 )
245    {
246      m_uiBakAbsPartIdx   = uiAbsPartIdx;
247      m_uiBakChromaOffset = offsetChroma;
248    }
249    else if( ( uiAbsPartIdx % partNum ) == (partNum - 1) )
250    {
251      cbfU = pcCU->getCbf( m_uiBakAbsPartIdx, TEXT_CHROMA_U, uiTrIdx );
252      cbfV = pcCU->getCbf( m_uiBakAbsPartIdx, TEXT_CHROMA_V, uiTrIdx );
253    }
[2]254  }
[608]255 
256  if( pcCU->getPredictionMode(uiAbsPartIdx) == MODE_INTRA && pcCU->getPartitionSize(uiAbsPartIdx) == SIZE_NxN && uiDepth == pcCU->getDepth(uiAbsPartIdx) )
257  {
258    assert( uiSubdiv );
259  }
260  else if( pcCU->getPredictionMode(uiAbsPartIdx) == MODE_INTER && (pcCU->getPartitionSize(uiAbsPartIdx) != SIZE_2Nx2N) && uiDepth == pcCU->getDepth(uiAbsPartIdx) &&  (pcCU->getSlice()->getSPS()->getQuadtreeTUMaxDepthInter() == 1) )
261  {
262    if ( uiLog2TrafoSize > pcCU->getQuadtreeTULog2MinSizeInCU(uiAbsPartIdx) )
[2]263    {
264      assert( uiSubdiv );
265    }
[608]266    else
[56]267    {
[608]268      assert(!uiSubdiv );
[56]269    }
[608]270  }
271  else if( uiLog2TrafoSize > pcCU->getSlice()->getSPS()->getQuadtreeTULog2MaxSize() )
272  {
273    assert( uiSubdiv );
274  }
275  else if( uiLog2TrafoSize == pcCU->getSlice()->getSPS()->getQuadtreeTULog2MinSize() )
276  {
277    assert( !uiSubdiv );
278  }
279  else if( uiLog2TrafoSize == pcCU->getQuadtreeTULog2MinSizeInCU(uiAbsPartIdx) )
280  {
281    assert( !uiSubdiv );
282  }
283  else
284  {
285    assert( uiLog2TrafoSize > pcCU->getQuadtreeTULog2MinSizeInCU(uiAbsPartIdx) );
286    m_pcEntropyCoderIf->codeTransformSubdivFlag( uiSubdiv, 5 - uiLog2TrafoSize );
287  }
288
289  const UInt uiTrDepthCurr = uiDepth - pcCU->getDepth( uiAbsPartIdx );
290  const Bool bFirstCbfOfCU = uiTrDepthCurr == 0;
291  if( bFirstCbfOfCU || uiLog2TrafoSize > 2 )
292  {
293    if( bFirstCbfOfCU || pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_U, uiTrDepthCurr - 1 ) )
[56]294    {
[608]295      m_pcEntropyCoderIf->codeQtCbf( pcCU, uiAbsPartIdx, TEXT_CHROMA_U, uiTrDepthCurr );
[56]296    }
[608]297    if( bFirstCbfOfCU || pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_V, uiTrDepthCurr - 1 ) )
[2]298    {
[608]299      m_pcEntropyCoderIf->codeQtCbf( pcCU, uiAbsPartIdx, TEXT_CHROMA_V, uiTrDepthCurr );
[2]300    }
[608]301  }
302  else if( uiLog2TrafoSize == 2 )
303  {
304    assert( pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_U, uiTrDepthCurr ) == pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_U, uiTrDepthCurr - 1 ) );
305    assert( pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_V, uiTrDepthCurr ) == pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_V, uiTrDepthCurr - 1 ) );
306  }
307 
308  if( uiSubdiv )
309  {
310    UInt size;
311    width  >>= 1;
312    height >>= 1;
313    size = width*height;
314    uiTrIdx++;
315    ++uiDepth;
316    const UInt partNum = pcCU->getPic()->getNumPartInCU() >> (uiDepth << 1);
317   
318    xEncodeTransform( pcCU, offsetLuma, offsetChroma, uiAbsPartIdx, uiDepth, width, height, uiTrIdx, bCodeDQP );
319
320    uiAbsPartIdx += partNum;  offsetLuma += size;  offsetChroma += (size>>2);
321    xEncodeTransform( pcCU, offsetLuma, offsetChroma, uiAbsPartIdx, uiDepth, width, height, uiTrIdx, bCodeDQP );
322
323    uiAbsPartIdx += partNum;  offsetLuma += size;  offsetChroma += (size>>2);
324    xEncodeTransform( pcCU, offsetLuma, offsetChroma, uiAbsPartIdx, uiDepth, width, height, uiTrIdx, bCodeDQP );
325
326    uiAbsPartIdx += partNum;  offsetLuma += size;  offsetChroma += (size>>2);
327    xEncodeTransform( pcCU, offsetLuma, offsetChroma, uiAbsPartIdx, uiDepth, width, height, uiTrIdx, bCodeDQP );
328  }
329  else
330  {
331#if !H_MV_ENC_DEC_TRAC
[2]332    {
[608]333      DTRACE_CABAC_VL( g_nSymbolCounter++ );
334      DTRACE_CABAC_T( "\tTrIdx: abspart=" );
335      DTRACE_CABAC_V( uiAbsPartIdx );
336      DTRACE_CABAC_T( "\tdepth=" );
337      DTRACE_CABAC_V( uiDepth );
338      DTRACE_CABAC_T( "\ttrdepth=" );
339      DTRACE_CABAC_V( pcCU->getTransformIdx( uiAbsPartIdx ) );
340      DTRACE_CABAC_T( "\n" );
[2]341    }
[608]342#endif
343   
344    if( pcCU->getPredictionMode(uiAbsPartIdx) != MODE_INTRA && uiDepth == pcCU->getDepth( uiAbsPartIdx ) && !pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_U, 0 ) && !pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_V, 0 ) )
345    {
346      assert( pcCU->getCbf( uiAbsPartIdx, TEXT_LUMA, 0 ) );
347      //      printf( "saved one bin! " );
348    }
[2]349    else
350    {
[608]351      m_pcEntropyCoderIf->codeQtCbf( pcCU, uiAbsPartIdx, TEXT_LUMA, pcCU->getTransformIdx( uiAbsPartIdx ) );
[2]352    }
[56]353
[608]354
355    if ( cbfY || cbfU || cbfV )
[2]356    {
[608]357      // dQP: only for LCU once
358      if ( pcCU->getSlice()->getPPS()->getUseDQP() )
[2]359      {
[608]360        if ( bCodeDQP )
[2]361        {
[608]362          encodeQP( pcCU, m_bakAbsPartIdxCU );
363          bCodeDQP = false;
[2]364        }
365      }
366    }
[608]367    if( cbfY )
[2]368    {
[608]369      Int trWidth = width;
370      Int trHeight = height;
371      m_pcEntropyCoderIf->codeCoeffNxN( pcCU, (pcCU->getCoeffY()+offsetLuma), uiAbsPartIdx, trWidth, trHeight, uiDepth, TEXT_LUMA );
[2]372    }
[608]373    if( uiLog2TrafoSize > 2 )
[2]374    {
[608]375      Int trWidth = width >> 1;
376      Int trHeight = height >> 1;
377      if( cbfU )
[2]378      {
[608]379        m_pcEntropyCoderIf->codeCoeffNxN( pcCU, (pcCU->getCoeffCb()+offsetChroma), uiAbsPartIdx, trWidth, trHeight, uiDepth, TEXT_CHROMA_U );
[2]380      }
[608]381      if( cbfV )
[56]382      {
[608]383        m_pcEntropyCoderIf->codeCoeffNxN( pcCU, (pcCU->getCoeffCr()+offsetChroma), uiAbsPartIdx, trWidth, trHeight, uiDepth, TEXT_CHROMA_V );
[56]384      }
[608]385    }
386    else
387    {
388      UInt partNum = pcCU->getPic()->getNumPartInCU() >> ( ( uiDepth - 1 ) << 1 );
389      if( ( uiAbsPartIdx % partNum ) == (partNum - 1) )
[2]390      {
[56]391        Int trWidth = width;
392        Int trHeight = height;
393        if( cbfU )
[2]394        {
[608]395          m_pcEntropyCoderIf->codeCoeffNxN( pcCU, (pcCU->getCoeffCb()+m_uiBakChromaOffset), m_uiBakAbsPartIdx, trWidth, trHeight, uiDepth, TEXT_CHROMA_U );
[2]396        }
[56]397        if( cbfV )
398        {
[608]399          m_pcEntropyCoderIf->codeCoeffNxN( pcCU, (pcCU->getCoeffCr()+m_uiBakChromaOffset), m_uiBakAbsPartIdx, trWidth, trHeight, uiDepth, TEXT_CHROMA_V );
[56]400        }
[2]401      }
402    }
403  }
404}
405
406// Intra direction for Luma
[608]407Void TEncEntropy::encodeIntraDirModeLuma  ( TComDataCU* pcCU, UInt absPartIdx, Bool isMultiplePU )
[2]408{
[608]409  m_pcEntropyCoderIf->codeIntraDirLumaAng( pcCU, absPartIdx , isMultiplePU);
[2]410}
411
412// Intra direction for Chroma
413Void TEncEntropy::encodeIntraDirModeChroma( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool bRD )
414{
415  if( bRD )
[56]416  {
[2]417    uiAbsPartIdx = 0;
[56]418  }
[2]419 
420  m_pcEntropyCoderIf->codeIntraDirChroma( pcCU, uiAbsPartIdx );
421}
422
[608]423Void TEncEntropy::encodePredInfo( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool bRD )
[2]424{
425  if( bRD )
[56]426  {
[2]427    uiAbsPartIdx = 0;
[56]428  }
[2]429  if( pcCU->isIntra( uiAbsPartIdx ) )                                 // If it is Intra mode, encode intra prediction mode.
430  {
[608]431    encodeIntraDirModeLuma  ( pcCU, uiAbsPartIdx,true );
432    encodeIntraDirModeChroma( pcCU, uiAbsPartIdx, bRD );
[2]433  }
434  else                                                                // if it is Inter mode, encode motion vector and reference index
435  {
[56]436    encodePUWise( pcCU, uiAbsPartIdx, bRD );
[2]437  }
438}
439
440/** encode motion information for every PU block
441 * \param pcCU
442 * \param uiAbsPartIdx
443 * \param bRD
444 * \returns Void
445 */
446Void TEncEntropy::encodePUWise( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool bRD )
447{
448  if ( bRD )
[56]449  {
[2]450    uiAbsPartIdx = 0;
[56]451  }
452 
[2]453  PartSize ePartSize = pcCU->getPartitionSize( uiAbsPartIdx );
454  UInt uiNumPU = ( ePartSize == SIZE_2Nx2N ? 1 : ( ePartSize == SIZE_NxN ? 4 : 2 ) );
455  UInt uiDepth = pcCU->getDepth( uiAbsPartIdx );
456  UInt uiPUOffset = ( g_auiPUOffset[UInt( ePartSize )] << ( ( pcCU->getSlice()->getSPS()->getMaxCUDepth() - uiDepth ) << 1 ) ) >> 4;
457
458  for ( UInt uiPartIdx = 0, uiSubPartIdx = uiAbsPartIdx; uiPartIdx < uiNumPU; uiPartIdx++, uiSubPartIdx += uiPUOffset )
459  {
[608]460#if H_MV_ENC_DEC_TRAC
461    DTRACE_PU_S("=========== prediction_unit ===========\n")
462       //Todo:
463      //DTRACE_PU("x0", uiLPelX)
464      //DTRACE_PU("x1", uiTPelY)
465#endif
466    encodeMergeFlag( pcCU, uiSubPartIdx );
[2]467    if ( pcCU->getMergeFlag( uiSubPartIdx ) )
468    {
[608]469      encodeMergeIndex( pcCU, uiSubPartIdx );
[2]470    }
471    else
472    {
473      encodeInterDirPU( pcCU, uiSubPartIdx );
474      for ( UInt uiRefListIdx = 0; uiRefListIdx < 2; uiRefListIdx++ )
475      {
476        if ( pcCU->getSlice()->getNumRefIdx( RefPicList( uiRefListIdx ) ) > 0 )
477        {
478          encodeRefFrmIdxPU ( pcCU, uiSubPartIdx, RefPicList( uiRefListIdx ) );
479          encodeMvdPU       ( pcCU, uiSubPartIdx, RefPicList( uiRefListIdx ) );
480          encodeMVPIdxPU    ( pcCU, uiSubPartIdx, RefPicList( uiRefListIdx ) );
481        }
482      }
483    }
484  }
485
486  return;
487}
488
489Void TEncEntropy::encodeInterDirPU( TComDataCU* pcCU, UInt uiAbsPartIdx )
490{
491  if ( !pcCU->getSlice()->isInterB() )
492  {
493    return;
494  }
495
496  m_pcEntropyCoderIf->codeInterDir( pcCU, uiAbsPartIdx );
497  return;
498}
499
500/** encode reference frame index for a PU block
501 * \param pcCU
502 * \param uiAbsPartIdx
503 * \param eRefList
504 * \returns Void
505 */
506Void TEncEntropy::encodeRefFrmIdxPU( TComDataCU* pcCU, UInt uiAbsPartIdx, RefPicList eRefList )
507{
508  assert( !pcCU->isIntra( uiAbsPartIdx ) );
509  {
[56]510    if ( ( pcCU->getSlice()->getNumRefIdx( eRefList ) == 1 ) )
511    {
512      return;
513    }
[2]514
[56]515    if ( pcCU->getInterDir( uiAbsPartIdx ) & ( 1 << eRefList ) )
516    {
517      m_pcEntropyCoderIf->codeRefFrmIdx( pcCU, uiAbsPartIdx, eRefList );
518    }
[2]519  }
520
521  return;
522}
523
524/** encode motion vector difference for a PU block
525 * \param pcCU
526 * \param uiAbsPartIdx
527 * \param eRefList
528 * \returns Void
529 */
530Void TEncEntropy::encodeMvdPU( TComDataCU* pcCU, UInt uiAbsPartIdx, RefPicList eRefList )
531{
532  assert( !pcCU->isIntra( uiAbsPartIdx ) );
533
534  if ( pcCU->getInterDir( uiAbsPartIdx ) & ( 1 << eRefList ) )
535  {
536    m_pcEntropyCoderIf->codeMvd( pcCU, uiAbsPartIdx, eRefList );
537  }
538  return;
539}
540
541Void TEncEntropy::encodeMVPIdxPU( TComDataCU* pcCU, UInt uiAbsPartIdx, RefPicList eRefList )
542{
[608]543  if ( (pcCU->getInterDir( uiAbsPartIdx ) & ( 1 << eRefList )) )
[2]544  {
545    m_pcEntropyCoderIf->codeMVPIdx( pcCU, uiAbsPartIdx, eRefList );
546  }
547
548  return;
549}
550
551Void TEncEntropy::encodeQtCbf( TComDataCU* pcCU, UInt uiAbsPartIdx, TextType eType, UInt uiTrDepth )
552{
553  m_pcEntropyCoderIf->codeQtCbf( pcCU, uiAbsPartIdx, eType, uiTrDepth );
554}
555
556Void TEncEntropy::encodeTransformSubdivFlag( UInt uiSymbol, UInt uiCtx )
557{
558  m_pcEntropyCoderIf->codeTransformSubdivFlag( uiSymbol, uiCtx );
559}
560
561Void TEncEntropy::encodeQtRootCbf( TComDataCU* pcCU, UInt uiAbsPartIdx )
562{
563  m_pcEntropyCoderIf->codeQtRootCbf( pcCU, uiAbsPartIdx );
564}
565
[608]566Void TEncEntropy::encodeQtCbfZero( TComDataCU* pcCU, TextType eType, UInt uiTrDepth )
567{
568  m_pcEntropyCoderIf->codeQtCbfZero( pcCU, eType, uiTrDepth );
569}
570Void TEncEntropy::encodeQtRootCbfZero( TComDataCU* pcCU )
571{
572  m_pcEntropyCoderIf->codeQtRootCbfZero( pcCU );
573}
574
[2]575// dQP
576Void TEncEntropy::encodeQP( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool bRD )
577{
578  if( bRD )
[56]579  {
[2]580    uiAbsPartIdx = 0;
[56]581  }
[2]582 
[56]583  if ( pcCU->getSlice()->getPPS()->getUseDQP() )
[2]584  {
585    m_pcEntropyCoderIf->codeDeltaQP( pcCU, uiAbsPartIdx );
586  }
587}
588
589
590// texture
591/** encode coefficients
592 * \param pcCU
593 * \param uiAbsPartIdx
594 * \param uiDepth
595 * \param uiWidth
596 * \param uiHeight
597 */
[56]598Void TEncEntropy::encodeCoeff( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, UInt uiWidth, UInt uiHeight, Bool& bCodeDQP )
[2]599{
600  UInt uiMinCoeffSize = pcCU->getPic()->getMinCUWidth()*pcCU->getPic()->getMinCUHeight();
601  UInt uiLumaOffset   = uiMinCoeffSize*uiAbsPartIdx;
602  UInt uiChromaOffset = uiLumaOffset>>2;
[833]603
[2]604  if( pcCU->isIntra(uiAbsPartIdx) )
605  {
[608]606#if !H_MV
[56]607    DTRACE_CABAC_VL( g_nSymbolCounter++ )
[2]608    DTRACE_CABAC_T( "\tdecodeTransformIdx()\tCUDepth=" )
609    DTRACE_CABAC_V( uiDepth )
610    DTRACE_CABAC_T( "\n" )
[608]611#endif
[2]612  }
613  else
614  {
[608]615    if( !(pcCU->getMergeFlag( uiAbsPartIdx ) && pcCU->getPartitionSize(uiAbsPartIdx) == SIZE_2Nx2N ) )
[2]616    {
[608]617      m_pcEntropyCoderIf->codeQtRootCbf( pcCU, uiAbsPartIdx );
[2]618    }
[608]619    if ( !pcCU->getQtRootCbf( uiAbsPartIdx ) )
[189]620    {
[608]621      return;
[189]622    }
623  }
[608]624 
625  xEncodeTransform( pcCU, uiLumaOffset, uiChromaOffset, uiAbsPartIdx, uiDepth, uiWidth, uiHeight, 0, bCodeDQP);
[2]626}
627
[56]628Void TEncEntropy::encodeCoeffNxN( TComDataCU* pcCU, TCoeff* pcCoeff, UInt uiAbsPartIdx, UInt uiTrWidth, UInt uiTrHeight, UInt uiDepth, TextType eType )
[608]629{
630  // This is for Transform unit processing. This may be used at mode selection stage for Inter.
[56]631  m_pcEntropyCoderIf->codeCoeffNxN( pcCU, pcCoeff, uiAbsPartIdx, uiTrWidth, uiTrHeight, uiDepth, eType );
[2]632}
633
[56]634Void TEncEntropy::estimateBit (estBitsSbacStruct* pcEstBitsSbac, Int width, Int height, TextType eTType)
635{ 
636  eTType = eTType == TEXT_LUMA ? TEXT_LUMA : TEXT_CHROMA;
637 
638  m_pcEntropyCoderIf->estBit ( pcEstBitsSbac, width, height, eTType );
639}
640
641Int TEncEntropy::countNonZeroCoeffs( TCoeff* pcCoef, UInt uiSize )
642{
643  Int count = 0;
644 
645  for ( Int i = 0; i < uiSize; i++ )
[2]646  {
[56]647    count += pcCoef[i] != 0;
[2]648  }
[56]649 
650  return count;
651}
[2]652
[56]653/** encode quantization matrix
654 * \param scalingList quantization matrix information
655 */
656Void TEncEntropy::encodeScalingList( TComScalingList* scalingList )
657{
658  m_pcEntropyCoderIf->codeScalingList( scalingList );
[2]659}
660
[56]661//! \}
Note: See TracBrowser for help on using the repository browser.