source: 3DVCSoftware/trunk/source/Lib/TLibEncoder/TEncEntropy.cpp @ 638

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

Merged DEV-2.0-dev0@604.

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