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

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

Removed 3D-HEVC.

  • Property svn:eol-style set to native
File size: 19.0 KB
Line 
1/* The copyright in this software is being made available under the BSD
2 * License, included below. This software may be subject to other third party
3 * and contributor rights, including patent rights, and no such rights are
4 * granted under this license. 
5 *
6* Copyright (c) 2010-2015, 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
115/** encode merge flag
116 * \param pcCU
117 * \param uiAbsPartIdx
118 * \returns Void
119 */
120Void TEncEntropy::encodeMergeFlag( TComDataCU* pcCU, UInt uiAbsPartIdx )
121{ 
122  // at least one merge candidate exists
123  m_pcEntropyCoderIf->codeMergeFlag( pcCU, uiAbsPartIdx );
124}
125
126/** encode merge index
127 * \param pcCU
128 * \param uiAbsPartIdx
129 * \param uiPUIdx
130 * \param bRD
131 * \returns Void
132 */
133Void TEncEntropy::encodeMergeIndex( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool bRD )
134{
135  if( bRD )
136  {
137    uiAbsPartIdx = 0;
138    assert( pcCU->getPartitionSize(uiAbsPartIdx) == SIZE_2Nx2N );
139  }
140  m_pcEntropyCoderIf->codeMergeIndex( pcCU, uiAbsPartIdx );
141}
142
143
144
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 )
154  {
155    uiAbsPartIdx = 0;
156  }
157  if ( pcCU->getSlice()->isIntra() )
158  {
159    return;
160  }
161
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 )
169  {
170    uiAbsPartIdx = 0;
171  }
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 )
185  {
186    uiAbsPartIdx = 0;
187  }
188 
189  m_pcEntropyCoderIf->codePartSize( pcCU, uiAbsPartIdx, uiDepth );
190 
191}
192
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 )
200{
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  }
207 
208  if( bRD )
209  {
210    uiAbsPartIdx = 0;
211  }
212 
213  m_pcEntropyCoderIf->codeIPCMInfo ( pcCU, uiAbsPartIdx );
214}
215
216Void TEncEntropy::xEncodeTransform( TComDataCU* pcCU,UInt offsetLuma, UInt offsetChroma, UInt uiAbsPartIdx, UInt uiDepth, UInt width, UInt height, UInt uiTrIdx, Bool& bCodeDQP )
217{
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
232  const UInt uiSubdiv = pcCU->getTransformIdx( uiAbsPartIdx ) + pcCU->getDepth( uiAbsPartIdx ) > uiDepth;
233  const UInt uiLog2TrafoSize = g_aucConvertToBit[pcCU->getSlice()->getSPS()->getMaxCUWidth()]+2 - uiDepth;
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)
238  {
239    m_bakAbsPartIdxCU = uiAbsPartIdx;
240  }
241  if( uiLog2TrafoSize == 2 )
242  {
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    }
254  }
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) )
263    {
264      assert( uiSubdiv );
265    }
266    else
267    {
268      assert(!uiSubdiv );
269    }
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 ) )
294    {
295      m_pcEntropyCoderIf->codeQtCbf( pcCU, uiAbsPartIdx, TEXT_CHROMA_U, uiTrDepthCurr );
296    }
297    if( bFirstCbfOfCU || pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_V, uiTrDepthCurr - 1 ) )
298    {
299      m_pcEntropyCoderIf->codeQtCbf( pcCU, uiAbsPartIdx, TEXT_CHROMA_V, uiTrDepthCurr );
300    }
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
332    {
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" );
341    }
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    }
349    else
350    {
351      m_pcEntropyCoderIf->codeQtCbf( pcCU, uiAbsPartIdx, TEXT_LUMA, pcCU->getTransformIdx( uiAbsPartIdx ) );
352    }
353
354
355    if ( cbfY || cbfU || cbfV )
356    {
357      // dQP: only for LCU once
358      if ( pcCU->getSlice()->getPPS()->getUseDQP() )
359      {
360        if ( bCodeDQP )
361        {
362          encodeQP( pcCU, m_bakAbsPartIdxCU );
363          bCodeDQP = false;
364        }
365      }
366    }
367    if( cbfY )
368    {
369      Int trWidth = width;
370      Int trHeight = height;
371      m_pcEntropyCoderIf->codeCoeffNxN( pcCU, (pcCU->getCoeffY()+offsetLuma), uiAbsPartIdx, trWidth, trHeight, uiDepth, TEXT_LUMA );
372    }
373    if( uiLog2TrafoSize > 2 )
374    {
375      Int trWidth = width >> 1;
376      Int trHeight = height >> 1;
377      if( cbfU )
378      {
379        m_pcEntropyCoderIf->codeCoeffNxN( pcCU, (pcCU->getCoeffCb()+offsetChroma), uiAbsPartIdx, trWidth, trHeight, uiDepth, TEXT_CHROMA_U );
380      }
381      if( cbfV )
382      {
383        m_pcEntropyCoderIf->codeCoeffNxN( pcCU, (pcCU->getCoeffCr()+offsetChroma), uiAbsPartIdx, trWidth, trHeight, uiDepth, TEXT_CHROMA_V );
384      }
385    }
386    else
387    {
388      UInt partNum = pcCU->getPic()->getNumPartInCU() >> ( ( uiDepth - 1 ) << 1 );
389      if( ( uiAbsPartIdx % partNum ) == (partNum - 1) )
390      {
391        Int trWidth = width;
392        Int trHeight = height;
393        if( cbfU )
394        {
395          m_pcEntropyCoderIf->codeCoeffNxN( pcCU, (pcCU->getCoeffCb()+m_uiBakChromaOffset), m_uiBakAbsPartIdx, trWidth, trHeight, uiDepth, TEXT_CHROMA_U );
396        }
397        if( cbfV )
398        {
399          m_pcEntropyCoderIf->codeCoeffNxN( pcCU, (pcCU->getCoeffCr()+m_uiBakChromaOffset), m_uiBakAbsPartIdx, trWidth, trHeight, uiDepth, TEXT_CHROMA_V );
400        }
401      }
402    }
403  }
404}
405
406// Intra direction for Luma
407Void TEncEntropy::encodeIntraDirModeLuma  ( TComDataCU* pcCU, UInt absPartIdx, Bool isMultiplePU )
408{
409  m_pcEntropyCoderIf->codeIntraDirLumaAng( pcCU, absPartIdx , isMultiplePU);
410}
411
412// Intra direction for Chroma
413Void TEncEntropy::encodeIntraDirModeChroma( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool bRD )
414{
415  if( bRD )
416  {
417    uiAbsPartIdx = 0;
418  }
419 
420  m_pcEntropyCoderIf->codeIntraDirChroma( pcCU, uiAbsPartIdx );
421}
422
423Void TEncEntropy::encodePredInfo( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool bRD )
424{
425  if( bRD )
426  {
427    uiAbsPartIdx = 0;
428  }
429  if( pcCU->isIntra( uiAbsPartIdx ) )                                 // If it is Intra mode, encode intra prediction mode.
430  {
431    encodeIntraDirModeLuma  ( pcCU, uiAbsPartIdx,true );
432    encodeIntraDirModeChroma( pcCU, uiAbsPartIdx, bRD );
433  }
434  else                                                                // if it is Inter mode, encode motion vector and reference index
435  {
436    encodePUWise( pcCU, uiAbsPartIdx, bRD );
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 )
449  {
450    uiAbsPartIdx = 0;
451  }
452 
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  {
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 );
467    if ( pcCU->getMergeFlag( uiSubPartIdx ) )
468    {
469      encodeMergeIndex( pcCU, uiSubPartIdx );
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  {
510    if ( ( pcCU->getSlice()->getNumRefIdx( eRefList ) == 1 ) )
511    {
512      return;
513    }
514
515    if ( pcCU->getInterDir( uiAbsPartIdx ) & ( 1 << eRefList ) )
516    {
517      m_pcEntropyCoderIf->codeRefFrmIdx( pcCU, uiAbsPartIdx, eRefList );
518    }
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{
543  if ( (pcCU->getInterDir( uiAbsPartIdx ) & ( 1 << eRefList )) )
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
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
575// dQP
576Void TEncEntropy::encodeQP( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool bRD )
577{
578  if( bRD )
579  {
580    uiAbsPartIdx = 0;
581  }
582 
583  if ( pcCU->getSlice()->getPPS()->getUseDQP() )
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 */
598Void TEncEntropy::encodeCoeff( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, UInt uiWidth, UInt uiHeight, Bool& bCodeDQP )
599{
600  UInt uiMinCoeffSize = pcCU->getPic()->getMinCUWidth()*pcCU->getPic()->getMinCUHeight();
601  UInt uiLumaOffset   = uiMinCoeffSize*uiAbsPartIdx;
602  UInt uiChromaOffset = uiLumaOffset>>2;
603
604  if( pcCU->isIntra(uiAbsPartIdx) )
605  {
606#if !H_MV
607    DTRACE_CABAC_VL( g_nSymbolCounter++ )
608    DTRACE_CABAC_T( "\tdecodeTransformIdx()\tCUDepth=" )
609    DTRACE_CABAC_V( uiDepth )
610    DTRACE_CABAC_T( "\n" )
611#endif
612  }
613  else
614  {
615    if( !(pcCU->getMergeFlag( uiAbsPartIdx ) && pcCU->getPartitionSize(uiAbsPartIdx) == SIZE_2Nx2N ) )
616    {
617      m_pcEntropyCoderIf->codeQtRootCbf( pcCU, uiAbsPartIdx );
618    }
619    if ( !pcCU->getQtRootCbf( uiAbsPartIdx ) )
620    {
621      return;
622    }
623  }
624 
625  xEncodeTransform( pcCU, uiLumaOffset, uiChromaOffset, uiAbsPartIdx, uiDepth, uiWidth, uiHeight, 0, bCodeDQP);
626}
627
628Void TEncEntropy::encodeCoeffNxN( TComDataCU* pcCU, TCoeff* pcCoeff, UInt uiAbsPartIdx, UInt uiTrWidth, UInt uiTrHeight, UInt uiDepth, TextType eType )
629{
630  // This is for Transform unit processing. This may be used at mode selection stage for Inter.
631  m_pcEntropyCoderIf->codeCoeffNxN( pcCU, pcCoeff, uiAbsPartIdx, uiTrWidth, uiTrHeight, uiDepth, eType );
632}
633
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++ )
646  {
647    count += pcCoef[i] != 0;
648  }
649 
650  return count;
651}
652
653/** encode quantization matrix
654 * \param scalingList quantization matrix information
655 */
656Void TEncEntropy::encodeScalingList( TComScalingList* scalingList )
657{
658  m_pcEntropyCoderIf->codeScalingList( scalingList );
659}
660
661//! \}
Note: See TracBrowser for help on using the repository browser.