source: 3DVCSoftware/branches/HTM-DEV-0.3-dev2/source/Lib/TLibEncoder/TEncEntropy.cpp @ 521

Last change on this file since 521 was 521, checked in by tech, 11 years ago

Integrated following changes:

  • H_MV_FIX1071, fix of encoder side reference list construction on IRAP pictures, same as in HM11.
  • H_3D_VSO_FIX_BORDRE_EXTENSION, fixed uninitialized borders for org-yuvs in VSO
  • H_MV_ENC_DEC_TRAC, added cu/pu level trace ( only enabled when ENC_DEC_TRACE is enabled)
  • Property svn:eol-style set to native
File size: 22.3 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-2013, 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  if (pcSlice->getSPS()->getUseSAO())
54  {
55    SAOParam *saoParam = pcSlice->getPic()->getPicSym()->getSaoParam();
56    pcSlice->setSaoEnabledFlag     (saoParam->bSaoFlag[0]);
57    {
58      pcSlice->setSaoEnabledFlagChroma   (saoParam->bSaoFlag[1]);
59    }
60  }
61
62  m_pcEntropyCoderIf->codeSliceHeader( pcSlice );
63  return;
64}
65
66Void  TEncEntropy::encodeTilesWPPEntryPoint( TComSlice* pSlice )
67{
68  m_pcEntropyCoderIf->codeTilesWPPEntryPoint( pSlice );
69}
70
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
89#if H_3D
90Void TEncEntropy::encodeSPS( TComSPS* pcSPS, Int viewIndex, Bool depthFlag )
91{
92  m_pcEntropyCoderIf->codeSPS( pcSPS, viewIndex, depthFlag );
93  return;
94}
95#else
96Void TEncEntropy::encodeSPS( TComSPS* pcSPS )
97{
98  m_pcEntropyCoderIf->codeSPS( pcSPS );
99  return;
100}
101#endif
102
103Void TEncEntropy::encodeCUTransquantBypassFlag( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool bRD )
104{
105  if( bRD )
106  {
107    uiAbsPartIdx = 0;
108  }
109  m_pcEntropyCoderIf->codeCUTransquantBypassFlag( pcCU, uiAbsPartIdx );
110}
111
112Void TEncEntropy::encodeVPS( TComVPS* pcVPS )
113{
114  m_pcEntropyCoderIf->codeVPS( pcVPS );
115  return;
116}
117
118Void TEncEntropy::encodeSkipFlag( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool bRD )
119{
120  if ( pcCU->getSlice()->isIntra() )
121  {
122    return;
123  }
124  if( bRD )
125  {
126    uiAbsPartIdx = 0;
127  }
128  m_pcEntropyCoderIf->codeSkipFlag( pcCU, uiAbsPartIdx );
129}
130
131/** encode merge flag
132 * \param pcCU
133 * \param uiAbsPartIdx
134 * \returns Void
135 */
136Void TEncEntropy::encodeMergeFlag( TComDataCU* pcCU, UInt uiAbsPartIdx )
137{ 
138  // at least one merge candidate exists
139  m_pcEntropyCoderIf->codeMergeFlag( pcCU, uiAbsPartIdx );
140}
141
142/** encode merge index
143 * \param pcCU
144 * \param uiAbsPartIdx
145 * \param uiPUIdx
146 * \param bRD
147 * \returns Void
148 */
149Void TEncEntropy::encodeMergeIndex( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool bRD )
150{
151  if( bRD )
152  {
153    uiAbsPartIdx = 0;
154    assert( pcCU->getPartitionSize(uiAbsPartIdx) == SIZE_2Nx2N );
155  }
156  m_pcEntropyCoderIf->codeMergeIndex( pcCU, uiAbsPartIdx );
157}
158
159#if H_3D_IC
160Void TEncEntropy::encodeICFlag( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool bRD )
161{
162  if ( pcCU->isIntra( uiAbsPartIdx ) || ( pcCU->getSlice()->getViewIndex() == 0 ) )
163  {
164    return;
165  }
166
167  if( !pcCU->getSlice()->getApplyIC() )
168    return;
169
170  if( bRD )
171  {
172    uiAbsPartIdx = 0;
173  }
174
175  if( pcCU->isICFlagRequired( uiAbsPartIdx ) )
176    m_pcEntropyCoderIf->codeICFlag( pcCU, uiAbsPartIdx );
177}
178#endif
179
180#if H_3D_ARP
181Void TEncEntropy::encodeARPW( TComDataCU* pcCU, UInt uiAbsPartIdx )
182{
183  if( !pcCU->getSlice()->getARPStepNum() || pcCU->isIntra( uiAbsPartIdx ) ) 
184  {
185    return;
186  }
187
188  if ( pcCU->getPartitionSize(uiAbsPartIdx)!=SIZE_2Nx2N )
189  {
190    assert(pcCU->getARPW (uiAbsPartIdx) == 0);
191  }
192  else
193  {
194    m_pcEntropyCoderIf->codeARPW( pcCU, uiAbsPartIdx );
195  }
196}
197#endif
198
199/** encode prediction mode
200 * \param pcCU
201 * \param uiAbsPartIdx
202 * \param bRD
203 * \returns Void
204 */
205Void TEncEntropy::encodePredMode( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool bRD )
206{
207  if( bRD )
208  {
209    uiAbsPartIdx = 0;
210  }
211  if ( pcCU->getSlice()->isIntra() )
212  {
213    return;
214  }
215
216  m_pcEntropyCoderIf->codePredMode( pcCU, uiAbsPartIdx );
217}
218
219// Split mode
220Void TEncEntropy::encodeSplitFlag( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, Bool bRD )
221{
222  if( bRD )
223  {
224    uiAbsPartIdx = 0;
225  }
226  m_pcEntropyCoderIf->codeSplitFlag( pcCU, uiAbsPartIdx, uiDepth );
227}
228
229/** encode partition size
230 * \param pcCU
231 * \param uiAbsPartIdx
232 * \param uiDepth
233 * \param bRD
234 * \returns Void
235 */
236Void TEncEntropy::encodePartSize( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, Bool bRD )
237{
238  if( bRD )
239  {
240    uiAbsPartIdx = 0;
241  }
242  m_pcEntropyCoderIf->codePartSize( pcCU, uiAbsPartIdx, uiDepth );
243}
244
245/** Encode I_PCM information.
246 * \param pcCU pointer to CU
247 * \param uiAbsPartIdx CU index
248 * \param bRD flag indicating estimation or encoding
249 * \returns Void
250 */
251Void TEncEntropy::encodeIPCMInfo( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool bRD )
252{
253  if(!pcCU->getSlice()->getSPS()->getUsePCM()
254    || pcCU->getWidth(uiAbsPartIdx) > (1<<pcCU->getSlice()->getSPS()->getPCMLog2MaxSize())
255    || pcCU->getWidth(uiAbsPartIdx) < (1<<pcCU->getSlice()->getSPS()->getPCMLog2MinSize()))
256  {
257    return;
258  }
259 
260  if( bRD )
261  {
262    uiAbsPartIdx = 0;
263  }
264 
265  m_pcEntropyCoderIf->codeIPCMInfo ( pcCU, uiAbsPartIdx );
266}
267
268Void TEncEntropy::xEncodeTransform( TComDataCU* pcCU,UInt offsetLuma, UInt offsetChroma, UInt uiAbsPartIdx, UInt uiDepth, UInt width, UInt height, UInt uiTrIdx, Bool& bCodeDQP )
269{
270  const UInt uiSubdiv = pcCU->getTransformIdx( uiAbsPartIdx ) + pcCU->getDepth( uiAbsPartIdx ) > uiDepth;
271  const UInt uiLog2TrafoSize = g_aucConvertToBit[pcCU->getSlice()->getSPS()->getMaxCUWidth()]+2 - uiDepth;
272  UInt cbfY = pcCU->getCbf( uiAbsPartIdx, TEXT_LUMA    , uiTrIdx );
273  UInt cbfU = pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_U, uiTrIdx );
274  UInt cbfV = pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_V, uiTrIdx );
275
276  if(uiTrIdx==0)
277  {
278    m_bakAbsPartIdxCU = uiAbsPartIdx;
279  }
280  if( uiLog2TrafoSize == 2 )
281  {
282    UInt partNum = pcCU->getPic()->getNumPartInCU() >> ( ( uiDepth - 1 ) << 1 );
283    if( ( uiAbsPartIdx % partNum ) == 0 )
284    {
285      m_uiBakAbsPartIdx   = uiAbsPartIdx;
286      m_uiBakChromaOffset = offsetChroma;
287    }
288    else if( ( uiAbsPartIdx % partNum ) == (partNum - 1) )
289    {
290      cbfU = pcCU->getCbf( m_uiBakAbsPartIdx, TEXT_CHROMA_U, uiTrIdx );
291      cbfV = pcCU->getCbf( m_uiBakAbsPartIdx, TEXT_CHROMA_V, uiTrIdx );
292    }
293  }
294 
295  if( pcCU->getPredictionMode(uiAbsPartIdx) == MODE_INTRA && pcCU->getPartitionSize(uiAbsPartIdx) == SIZE_NxN && uiDepth == pcCU->getDepth(uiAbsPartIdx) )
296  {
297    assert( uiSubdiv );
298  }
299  else if( pcCU->getPredictionMode(uiAbsPartIdx) == MODE_INTER && (pcCU->getPartitionSize(uiAbsPartIdx) != SIZE_2Nx2N) && uiDepth == pcCU->getDepth(uiAbsPartIdx) &&  (pcCU->getSlice()->getSPS()->getQuadtreeTUMaxDepthInter() == 1) )
300  {
301    if ( uiLog2TrafoSize > pcCU->getQuadtreeTULog2MinSizeInCU(uiAbsPartIdx) )
302    {
303      assert( uiSubdiv );
304    }
305    else
306    {
307      assert(!uiSubdiv );
308    }
309  }
310  else if( uiLog2TrafoSize > pcCU->getSlice()->getSPS()->getQuadtreeTULog2MaxSize() )
311  {
312    assert( uiSubdiv );
313  }
314  else if( uiLog2TrafoSize == pcCU->getSlice()->getSPS()->getQuadtreeTULog2MinSize() )
315  {
316    assert( !uiSubdiv );
317  }
318  else if( uiLog2TrafoSize == pcCU->getQuadtreeTULog2MinSizeInCU(uiAbsPartIdx) )
319  {
320    assert( !uiSubdiv );
321  }
322  else
323  {
324    assert( uiLog2TrafoSize > pcCU->getQuadtreeTULog2MinSizeInCU(uiAbsPartIdx) );
325    m_pcEntropyCoderIf->codeTransformSubdivFlag( uiSubdiv, 5 - uiLog2TrafoSize );
326  }
327
328  const UInt uiTrDepthCurr = uiDepth - pcCU->getDepth( uiAbsPartIdx );
329  const Bool bFirstCbfOfCU = uiTrDepthCurr == 0;
330  if( bFirstCbfOfCU || uiLog2TrafoSize > 2 )
331  {
332    if( bFirstCbfOfCU || pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_U, uiTrDepthCurr - 1 ) )
333    {
334      m_pcEntropyCoderIf->codeQtCbf( pcCU, uiAbsPartIdx, TEXT_CHROMA_U, uiTrDepthCurr );
335    }
336    if( bFirstCbfOfCU || pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_V, uiTrDepthCurr - 1 ) )
337    {
338      m_pcEntropyCoderIf->codeQtCbf( pcCU, uiAbsPartIdx, TEXT_CHROMA_V, uiTrDepthCurr );
339    }
340  }
341  else if( uiLog2TrafoSize == 2 )
342  {
343    assert( pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_U, uiTrDepthCurr ) == pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_U, uiTrDepthCurr - 1 ) );
344    assert( pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_V, uiTrDepthCurr ) == pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_V, uiTrDepthCurr - 1 ) );
345  }
346 
347  if( uiSubdiv )
348  {
349    UInt size;
350    width  >>= 1;
351    height >>= 1;
352    size = width*height;
353    uiTrIdx++;
354    ++uiDepth;
355    const UInt partNum = pcCU->getPic()->getNumPartInCU() >> (uiDepth << 1);
356   
357    xEncodeTransform( pcCU, offsetLuma, offsetChroma, uiAbsPartIdx, uiDepth, width, height, uiTrIdx, bCodeDQP );
358
359    uiAbsPartIdx += partNum;  offsetLuma += size;  offsetChroma += (size>>2);
360    xEncodeTransform( pcCU, offsetLuma, offsetChroma, uiAbsPartIdx, uiDepth, width, height, uiTrIdx, bCodeDQP );
361
362    uiAbsPartIdx += partNum;  offsetLuma += size;  offsetChroma += (size>>2);
363    xEncodeTransform( pcCU, offsetLuma, offsetChroma, uiAbsPartIdx, uiDepth, width, height, uiTrIdx, bCodeDQP );
364
365    uiAbsPartIdx += partNum;  offsetLuma += size;  offsetChroma += (size>>2);
366    xEncodeTransform( pcCU, offsetLuma, offsetChroma, uiAbsPartIdx, uiDepth, width, height, uiTrIdx, bCodeDQP );
367  }
368  else
369  {
370#if !H_MV_ENC_DEC_TRAC
371    {
372      DTRACE_CABAC_VL( g_nSymbolCounter++ );
373      DTRACE_CABAC_T( "\tTrIdx: abspart=" );
374      DTRACE_CABAC_V( uiAbsPartIdx );
375      DTRACE_CABAC_T( "\tdepth=" );
376      DTRACE_CABAC_V( uiDepth );
377      DTRACE_CABAC_T( "\ttrdepth=" );
378      DTRACE_CABAC_V( pcCU->getTransformIdx( uiAbsPartIdx ) );
379      DTRACE_CABAC_T( "\n" );
380    }
381#endif
382   
383    if( pcCU->getPredictionMode(uiAbsPartIdx) != MODE_INTRA && uiDepth == pcCU->getDepth( uiAbsPartIdx ) && !pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_U, 0 ) && !pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_V, 0 ) )
384    {
385      assert( pcCU->getCbf( uiAbsPartIdx, TEXT_LUMA, 0 ) );
386      //      printf( "saved one bin! " );
387    }
388    else
389    {
390      m_pcEntropyCoderIf->codeQtCbf( pcCU, uiAbsPartIdx, TEXT_LUMA, pcCU->getTransformIdx( uiAbsPartIdx ) );
391    }
392
393
394    if ( cbfY || cbfU || cbfV )
395    {
396      // dQP: only for LCU once
397      if ( pcCU->getSlice()->getPPS()->getUseDQP() )
398      {
399        if ( bCodeDQP )
400        {
401          encodeQP( pcCU, m_bakAbsPartIdxCU );
402          bCodeDQP = false;
403        }
404      }
405    }
406    if( cbfY )
407    {
408      Int trWidth = width;
409      Int trHeight = height;
410      m_pcEntropyCoderIf->codeCoeffNxN( pcCU, (pcCU->getCoeffY()+offsetLuma), uiAbsPartIdx, trWidth, trHeight, uiDepth, TEXT_LUMA );
411    }
412    if( uiLog2TrafoSize > 2 )
413    {
414      Int trWidth = width >> 1;
415      Int trHeight = height >> 1;
416      if( cbfU )
417      {
418        m_pcEntropyCoderIf->codeCoeffNxN( pcCU, (pcCU->getCoeffCb()+offsetChroma), uiAbsPartIdx, trWidth, trHeight, uiDepth, TEXT_CHROMA_U );
419      }
420      if( cbfV )
421      {
422        m_pcEntropyCoderIf->codeCoeffNxN( pcCU, (pcCU->getCoeffCr()+offsetChroma), uiAbsPartIdx, trWidth, trHeight, uiDepth, TEXT_CHROMA_V );
423      }
424    }
425    else
426    {
427      UInt partNum = pcCU->getPic()->getNumPartInCU() >> ( ( uiDepth - 1 ) << 1 );
428      if( ( uiAbsPartIdx % partNum ) == (partNum - 1) )
429      {
430        Int trWidth = width;
431        Int trHeight = height;
432        if( cbfU )
433        {
434          m_pcEntropyCoderIf->codeCoeffNxN( pcCU, (pcCU->getCoeffCb()+m_uiBakChromaOffset), m_uiBakAbsPartIdx, trWidth, trHeight, uiDepth, TEXT_CHROMA_U );
435        }
436        if( cbfV )
437        {
438          m_pcEntropyCoderIf->codeCoeffNxN( pcCU, (pcCU->getCoeffCr()+m_uiBakChromaOffset), m_uiBakAbsPartIdx, trWidth, trHeight, uiDepth, TEXT_CHROMA_V );
439        }
440      }
441    }
442  }
443}
444
445// Intra direction for Luma
446Void TEncEntropy::encodeIntraDirModeLuma  ( TComDataCU* pcCU, UInt absPartIdx, Bool isMultiplePU )
447{
448  m_pcEntropyCoderIf->codeIntraDirLumaAng( pcCU, absPartIdx , isMultiplePU);
449}
450
451// Intra direction for Chroma
452Void TEncEntropy::encodeIntraDirModeChroma( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool bRD )
453{
454  if( bRD )
455  {
456    uiAbsPartIdx = 0;
457  }
458 
459  m_pcEntropyCoderIf->codeIntraDirChroma( pcCU, uiAbsPartIdx );
460}
461
462Void TEncEntropy::encodePredInfo( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool bRD )
463{
464  if( bRD )
465  {
466    uiAbsPartIdx = 0;
467  }
468  if( pcCU->isIntra( uiAbsPartIdx ) )                                 // If it is Intra mode, encode intra prediction mode.
469  {
470    encodeIntraDirModeLuma  ( pcCU, uiAbsPartIdx,true );
471    encodeIntraDirModeChroma( pcCU, uiAbsPartIdx, bRD );
472  }
473  else                                                                // if it is Inter mode, encode motion vector and reference index
474  {
475    encodePUWise( pcCU, uiAbsPartIdx, bRD );
476  }
477}
478
479/** encode motion information for every PU block
480 * \param pcCU
481 * \param uiAbsPartIdx
482 * \param bRD
483 * \returns Void
484 */
485Void TEncEntropy::encodePUWise( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool bRD )
486{
487  if ( bRD )
488  {
489    uiAbsPartIdx = 0;
490  }
491 
492  PartSize ePartSize = pcCU->getPartitionSize( uiAbsPartIdx );
493  UInt uiNumPU = ( ePartSize == SIZE_2Nx2N ? 1 : ( ePartSize == SIZE_NxN ? 4 : 2 ) );
494  UInt uiDepth = pcCU->getDepth( uiAbsPartIdx );
495  UInt uiPUOffset = ( g_auiPUOffset[UInt( ePartSize )] << ( ( pcCU->getSlice()->getSPS()->getMaxCUDepth() - uiDepth ) << 1 ) ) >> 4;
496
497  for ( UInt uiPartIdx = 0, uiSubPartIdx = uiAbsPartIdx; uiPartIdx < uiNumPU; uiPartIdx++, uiSubPartIdx += uiPUOffset )
498  {
499#if H_MV_ENC_DEC_TRAC
500    DTRACE_PU_S("=========== prediction_unit ===========\n")
501       //Todo:
502      //DTRACE_PU("x0", uiLPelX)
503      //DTRACE_PU("x1", uiTPelY)
504#endif
505    encodeMergeFlag( pcCU, uiSubPartIdx );
506    if ( pcCU->getMergeFlag( uiSubPartIdx ) )
507    {
508      encodeMergeIndex( pcCU, uiSubPartIdx );
509    }
510    else
511    {
512      encodeInterDirPU( pcCU, uiSubPartIdx );
513      for ( UInt uiRefListIdx = 0; uiRefListIdx < 2; uiRefListIdx++ )
514      {
515        if ( pcCU->getSlice()->getNumRefIdx( RefPicList( uiRefListIdx ) ) > 0 )
516        {
517          encodeRefFrmIdxPU ( pcCU, uiSubPartIdx, RefPicList( uiRefListIdx ) );
518          encodeMvdPU       ( pcCU, uiSubPartIdx, RefPicList( uiRefListIdx ) );
519          encodeMVPIdxPU    ( pcCU, uiSubPartIdx, RefPicList( uiRefListIdx ) );
520        }
521      }
522    }
523  }
524
525  return;
526}
527
528Void TEncEntropy::encodeInterDirPU( TComDataCU* pcCU, UInt uiAbsPartIdx )
529{
530  if ( !pcCU->getSlice()->isInterB() )
531  {
532    return;
533  }
534
535  m_pcEntropyCoderIf->codeInterDir( pcCU, uiAbsPartIdx );
536  return;
537}
538
539/** encode reference frame index for a PU block
540 * \param pcCU
541 * \param uiAbsPartIdx
542 * \param eRefList
543 * \returns Void
544 */
545Void TEncEntropy::encodeRefFrmIdxPU( TComDataCU* pcCU, UInt uiAbsPartIdx, RefPicList eRefList )
546{
547  assert( !pcCU->isIntra( uiAbsPartIdx ) );
548  {
549    if ( ( pcCU->getSlice()->getNumRefIdx( eRefList ) == 1 ) )
550    {
551      return;
552    }
553
554    if ( pcCU->getInterDir( uiAbsPartIdx ) & ( 1 << eRefList ) )
555    {
556      m_pcEntropyCoderIf->codeRefFrmIdx( pcCU, uiAbsPartIdx, eRefList );
557    }
558  }
559
560  return;
561}
562
563/** encode motion vector difference for a PU block
564 * \param pcCU
565 * \param uiAbsPartIdx
566 * \param eRefList
567 * \returns Void
568 */
569Void TEncEntropy::encodeMvdPU( TComDataCU* pcCU, UInt uiAbsPartIdx, RefPicList eRefList )
570{
571  assert( !pcCU->isIntra( uiAbsPartIdx ) );
572
573  if ( pcCU->getInterDir( uiAbsPartIdx ) & ( 1 << eRefList ) )
574  {
575    m_pcEntropyCoderIf->codeMvd( pcCU, uiAbsPartIdx, eRefList );
576  }
577  return;
578}
579
580Void TEncEntropy::encodeMVPIdxPU( TComDataCU* pcCU, UInt uiAbsPartIdx, RefPicList eRefList )
581{
582  if ( (pcCU->getInterDir( uiAbsPartIdx ) & ( 1 << eRefList )) )
583  {
584    m_pcEntropyCoderIf->codeMVPIdx( pcCU, uiAbsPartIdx, eRefList );
585  }
586
587  return;
588}
589
590Void TEncEntropy::encodeQtCbf( TComDataCU* pcCU, UInt uiAbsPartIdx, TextType eType, UInt uiTrDepth )
591{
592  m_pcEntropyCoderIf->codeQtCbf( pcCU, uiAbsPartIdx, eType, uiTrDepth );
593}
594
595Void TEncEntropy::encodeTransformSubdivFlag( UInt uiSymbol, UInt uiCtx )
596{
597  m_pcEntropyCoderIf->codeTransformSubdivFlag( uiSymbol, uiCtx );
598}
599
600Void TEncEntropy::encodeQtRootCbf( TComDataCU* pcCU, UInt uiAbsPartIdx )
601{
602  m_pcEntropyCoderIf->codeQtRootCbf( pcCU, uiAbsPartIdx );
603}
604
605Void TEncEntropy::encodeQtCbfZero( TComDataCU* pcCU, TextType eType, UInt uiTrDepth )
606{
607  m_pcEntropyCoderIf->codeQtCbfZero( pcCU, eType, uiTrDepth );
608}
609Void TEncEntropy::encodeQtRootCbfZero( TComDataCU* pcCU )
610{
611  m_pcEntropyCoderIf->codeQtRootCbfZero( pcCU );
612}
613
614// dQP
615Void TEncEntropy::encodeQP( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool bRD )
616{
617  if( bRD )
618  {
619    uiAbsPartIdx = 0;
620  }
621 
622  if ( pcCU->getSlice()->getPPS()->getUseDQP() )
623  {
624    m_pcEntropyCoderIf->codeDeltaQP( pcCU, uiAbsPartIdx );
625  }
626}
627
628
629// texture
630/** encode coefficients
631 * \param pcCU
632 * \param uiAbsPartIdx
633 * \param uiDepth
634 * \param uiWidth
635 * \param uiHeight
636 */
637Void TEncEntropy::encodeCoeff( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, UInt uiWidth, UInt uiHeight, Bool& bCodeDQP )
638{
639  UInt uiMinCoeffSize = pcCU->getPic()->getMinCUWidth()*pcCU->getPic()->getMinCUHeight();
640  UInt uiLumaOffset   = uiMinCoeffSize*uiAbsPartIdx;
641  UInt uiChromaOffset = uiLumaOffset>>2;
642   
643  if( pcCU->isIntra(uiAbsPartIdx) )
644  {
645#if !H_MV
646    DTRACE_CABAC_VL( g_nSymbolCounter++ )
647    DTRACE_CABAC_T( "\tdecodeTransformIdx()\tCUDepth=" )
648    DTRACE_CABAC_V( uiDepth )
649    DTRACE_CABAC_T( "\n" )
650#endif
651  }
652  else
653  {
654    if( !(pcCU->getMergeFlag( uiAbsPartIdx ) && pcCU->getPartitionSize(uiAbsPartIdx) == SIZE_2Nx2N ) )
655    {
656      m_pcEntropyCoderIf->codeQtRootCbf( pcCU, uiAbsPartIdx );
657    }
658    if ( !pcCU->getQtRootCbf( uiAbsPartIdx ) )
659    {
660      return;
661    }
662  }
663 
664  xEncodeTransform( pcCU, uiLumaOffset, uiChromaOffset, uiAbsPartIdx, uiDepth, uiWidth, uiHeight, 0, bCodeDQP);
665}
666
667Void TEncEntropy::encodeCoeffNxN( TComDataCU* pcCU, TCoeff* pcCoeff, UInt uiAbsPartIdx, UInt uiTrWidth, UInt uiTrHeight, UInt uiDepth, TextType eType )
668{
669  // This is for Transform unit processing. This may be used at mode selection stage for Inter.
670  m_pcEntropyCoderIf->codeCoeffNxN( pcCU, pcCoeff, uiAbsPartIdx, uiTrWidth, uiTrHeight, uiDepth, eType );
671}
672
673Void TEncEntropy::estimateBit (estBitsSbacStruct* pcEstBitsSbac, Int width, Int height, TextType eTType)
674{ 
675  eTType = eTType == TEXT_LUMA ? TEXT_LUMA : TEXT_CHROMA;
676 
677  m_pcEntropyCoderIf->estBit ( pcEstBitsSbac, width, height, eTType );
678}
679
680/** Encode SAO Offset
681 * \param  saoLcuParam SAO LCU paramters
682 */
683Void TEncEntropy::encodeSaoOffset(SaoLcuParam* saoLcuParam, UInt compIdx)
684{
685  UInt uiSymbol;
686  Int i;
687
688  uiSymbol = saoLcuParam->typeIdx + 1;
689  if (compIdx!=2)
690  {
691    m_pcEntropyCoderIf->codeSaoTypeIdx(uiSymbol);
692  }
693  if (uiSymbol)
694  {
695    if (saoLcuParam->typeIdx < 4 && compIdx != 2)
696    {
697      saoLcuParam->subTypeIdx = saoLcuParam->typeIdx;
698    }
699    Int bitDepth = compIdx ? g_bitDepthC : g_bitDepthY;
700    Int offsetTh = 1 << min(bitDepth - 5,5);
701    if( saoLcuParam->typeIdx == SAO_BO )
702    {
703      for( i=0; i< saoLcuParam->length; i++)
704      {
705        UInt absOffset = ( (saoLcuParam->offset[i] < 0) ? -saoLcuParam->offset[i] : saoLcuParam->offset[i]);
706        m_pcEntropyCoderIf->codeSaoMaxUvlc(absOffset, offsetTh-1);
707      } 
708      for( i=0; i< saoLcuParam->length; i++)
709      {
710        if (saoLcuParam->offset[i] != 0)
711        {
712          UInt sign = (saoLcuParam->offset[i] < 0) ? 1 : 0 ;
713          m_pcEntropyCoderIf->codeSAOSign(sign);
714        }
715      }
716      uiSymbol = (UInt) (saoLcuParam->subTypeIdx);
717      m_pcEntropyCoderIf->codeSaoUflc(5, uiSymbol);
718    }
719    else if( saoLcuParam->typeIdx < 4 )
720    {
721      m_pcEntropyCoderIf->codeSaoMaxUvlc( saoLcuParam->offset[0], offsetTh-1);
722      m_pcEntropyCoderIf->codeSaoMaxUvlc( saoLcuParam->offset[1], offsetTh-1);
723      m_pcEntropyCoderIf->codeSaoMaxUvlc(-saoLcuParam->offset[2], offsetTh-1);
724      m_pcEntropyCoderIf->codeSaoMaxUvlc(-saoLcuParam->offset[3], offsetTh-1);
725      if (compIdx!=2)
726      {
727        uiSymbol = (UInt) (saoLcuParam->subTypeIdx);
728        m_pcEntropyCoderIf->codeSaoUflc(2, uiSymbol);
729      }
730    }
731  }
732}
733
734/** Encode SAO unit interleaving
735* \param  rx
736* \param  ry
737* \param  pSaoParam
738* \param  pcCU
739* \param  iCUAddrInSlice
740* \param  iCUAddrUpInSlice
741* \param  bLFCrossSliceBoundaryFlag
742 */
743Void TEncEntropy::encodeSaoUnitInterleaving(Int compIdx, Bool saoFlag, Int rx, Int ry, SaoLcuParam* saoLcuParam, Int cuAddrInSlice, Int cuAddrUpInSlice, Int allowMergeLeft, Int allowMergeUp)
744{
745  if (saoFlag)
746  {
747    if (rx>0 && cuAddrInSlice!=0 && allowMergeLeft)
748    {
749      m_pcEntropyCoderIf->codeSaoMerge(saoLcuParam->mergeLeftFlag);
750    }
751    else
752    {
753      saoLcuParam->mergeLeftFlag = 0;
754    }
755    if (saoLcuParam->mergeLeftFlag == 0)
756    {
757      if ( (ry > 0) && (cuAddrUpInSlice>=0) && allowMergeUp )
758      {
759        m_pcEntropyCoderIf->codeSaoMerge(saoLcuParam->mergeUpFlag);
760      }
761      else
762      {
763        saoLcuParam->mergeUpFlag = 0;
764      }
765      if (!saoLcuParam->mergeUpFlag)
766      {
767        encodeSaoOffset(saoLcuParam, compIdx);
768      }
769    }
770  }
771}
772
773Int TEncEntropy::countNonZeroCoeffs( TCoeff* pcCoef, UInt uiSize )
774{
775  Int count = 0;
776 
777  for ( Int i = 0; i < uiSize; i++ )
778  {
779    count += pcCoef[i] != 0;
780  }
781 
782  return count;
783}
784
785/** encode quantization matrix
786 * \param scalingList quantization matrix information
787 */
788Void TEncEntropy::encodeScalingList( TComScalingList* scalingList )
789{
790  m_pcEntropyCoderIf->codeScalingList( scalingList );
791}
792
793//! \}
Note: See TracBrowser for help on using the repository browser.