source: SHVCSoftware/trunk/source/Lib/TLibEncoder/TEncEntropy.cpp @ 601

Last change on this file since 601 was 595, checked in by seregin, 11 years ago

merge with SHM-5.0-dev branch

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