source: SHVCSoftware/branches/SHM-6-dev/source/Lib/TLibEncoder/TEncEntropy.cpp @ 674

Last change on this file since 674 was 644, checked in by seregin, 11 years ago

merge with SHM-5.1-dev branch

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