source: 3DVCSoftware/branches/HTM-10.2-dev3-MediaTek/source/Lib/TLibEncoder/TEncEntropy.cpp @ 1417

Last change on this file since 1417 was 904, checked in by mediatek-htm, 11 years ago

Integration of H0095 to remove the conditional check of PCM flag based on SDC flag.
The MACRO is "MTK_SDC_FLAG_FIX_H0095".

By Yi-Wen Chen (yiwen.chen@…)

  • Property svn:eol-style set to native
File size: 23.3 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 *
[872]6* Copyright (c) 2010-2014, 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{
53  m_pcEntropyCoderIf->codeSliceHeader( pcSlice );
54  return;
55}
56
[56]57Void  TEncEntropy::encodeTilesWPPEntryPoint( TComSlice* pSlice )
58{
59  m_pcEntropyCoderIf->codeTilesWPPEntryPoint( pSlice );
60}
61
[2]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
[608]80#if H_3D
81Void TEncEntropy::encodeSPS( TComSPS* pcSPS, Int viewIndex, Bool depthFlag )
[77]82{
[608]83  m_pcEntropyCoderIf->codeSPS( pcSPS, viewIndex, depthFlag );
[77]84  return;
85}
[56]86#else
[2]87Void TEncEntropy::encodeSPS( TComSPS* pcSPS )
88{
89  m_pcEntropyCoderIf->codeSPS( pcSPS );
90  return;
91}
[56]92#endif
[2]93
[608]94Void TEncEntropy::encodeCUTransquantBypassFlag( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool bRD )
[2]95{
96  if( bRD )
[56]97  {
[2]98    uiAbsPartIdx = 0;
[56]99  }
[608]100  m_pcEntropyCoderIf->codeCUTransquantBypassFlag( pcCU, uiAbsPartIdx );
[2]101}
102
[608]103Void TEncEntropy::encodeVPS( TComVPS* pcVPS )
[189]104{
[608]105  m_pcEntropyCoderIf->codeVPS( pcVPS );
106  return;
107}
108
109Void TEncEntropy::encodeSkipFlag( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool bRD )
110{
111  if ( pcCU->getSlice()->isIntra() )
[189]112  {
113    return;
114  }
115  if( bRD )
116  {
117    uiAbsPartIdx = 0;
118  }
[608]119  m_pcEntropyCoderIf->codeSkipFlag( pcCU, uiAbsPartIdx );
[189]120}
121
[2]122/** encode merge flag
123 * \param pcCU
124 * \param uiAbsPartIdx
125 * \returns Void
126 */
[608]127Void TEncEntropy::encodeMergeFlag( TComDataCU* pcCU, UInt uiAbsPartIdx )
[2]128{ 
[56]129  // at least one merge candidate exists
130  m_pcEntropyCoderIf->codeMergeFlag( pcCU, uiAbsPartIdx );
[2]131}
132
133/** encode merge index
134 * \param pcCU
135 * \param uiAbsPartIdx
136 * \param uiPUIdx
137 * \param bRD
138 * \returns Void
139 */
[608]140Void TEncEntropy::encodeMergeIndex( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool bRD )
[2]141{
142  if( bRD )
143  {
144    uiAbsPartIdx = 0;
145    assert( pcCU->getPartitionSize(uiAbsPartIdx) == SIZE_2Nx2N );
146  }
[608]147  m_pcEntropyCoderIf->codeMergeIndex( pcCU, uiAbsPartIdx );
[2]148}
149
[608]150#if H_3D_IC
151Void TEncEntropy::encodeICFlag( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool bRD )
[443]152{
[833]153  if ( pcCU->isIntra( uiAbsPartIdx ) || ( pcCU->getSlice()->getViewIndex() == 0 ) || pcCU->getSlice()->getIsDepth() || pcCU->getARPW( uiAbsPartIdx ) > 0 )
[443]154  {
155    return;
156  }
[608]157
158  if( !pcCU->getSlice()->getApplyIC() )
159    return;
160
[443]161  if( bRD )
162  {
163    uiAbsPartIdx = 0;
164  }
[902]165#if MTK_LOW_LATENCY_IC_ENCODING_H0086
166  else
167  {
168    g_aICEnableCANDIDATE[pcCU->getSlice()->getDepth()]++;
169    if(pcCU->getICFlag(uiAbsPartIdx))
170    {
171      g_aICEnableNUM[pcCU->getSlice()->getDepth()]++;
172    }
173  }
174#endif
[608]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  }
[833]242 
243#if H_3D_DBBP
244  PartSize eVirtualPartSize = pcCU->getPartitionSize(uiAbsPartIdx);
245  if( pcCU->getDBBPFlag(uiAbsPartIdx) )
246  {
247    AOF( pcCU->getSlice()->getVPS()->getUseDBBP(pcCU->getSlice()->getLayerIdInVps()) );
248   
249    // temporarily change partition size for DBBP blocks
250    pcCU->setPartSizeSubParts(RWTH_DBBP_PACK_MODE, uiAbsPartIdx, uiDepth);
251  }
252#endif
253 
[2]254  m_pcEntropyCoderIf->codePartSize( pcCU, uiAbsPartIdx, uiDepth );
[833]255 
256#if H_3D_DBBP
257  if( pcCU->getSlice()->getVPS()->getUseDBBP(pcCU->getSlice()->getLayerIdInVps()) && pcCU->getPartitionSize(uiAbsPartIdx) == RWTH_DBBP_PACK_MODE )
258  {
259    encodeDBBPFlag(pcCU, uiAbsPartIdx, bRD);
260   
261    if( pcCU->getDBBPFlag(uiAbsPartIdx) )
262    {
263      AOF( pcCU->getPartitionSize(uiAbsPartIdx) == RWTH_DBBP_PACK_MODE );
264      // restore virtual partition size for DBBP blocks
265      pcCU->setPartSizeSubParts(eVirtualPartSize, uiAbsPartIdx, uiDepth);
266    }
267  }
268#endif
[2]269}
270
[56]271/** Encode I_PCM information.
272 * \param pcCU pointer to CU
273 * \param uiAbsPartIdx CU index
274 * \param bRD flag indicating estimation or encoding
275 * \returns Void
276 */
277Void TEncEntropy::encodeIPCMInfo( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool bRD )
[2]278{
[56]279  if(!pcCU->getSlice()->getSPS()->getUsePCM()
280    || pcCU->getWidth(uiAbsPartIdx) > (1<<pcCU->getSlice()->getSPS()->getPCMLog2MaxSize())
281    || pcCU->getWidth(uiAbsPartIdx) < (1<<pcCU->getSlice()->getSPS()->getPCMLog2MinSize()))
282  {
283    return;
284  }
[904]285#if !MTK_SDC_FLAG_FIX_H0095
[608]286#if H_3D_DIM_SDC
[189]287  if( pcCU->getSDCFlag(uiAbsPartIdx) )
288  {
289    return;
290  }
291#endif
[904]292#endif
[189]293 
[56]294  if( bRD )
295  {
296    uiAbsPartIdx = 0;
297  }
298 
[608]299  m_pcEntropyCoderIf->codeIPCMInfo ( pcCU, uiAbsPartIdx );
[56]300}
301
[608]302Void TEncEntropy::xEncodeTransform( TComDataCU* pcCU,UInt offsetLuma, UInt offsetChroma, UInt uiAbsPartIdx, UInt uiDepth, UInt width, UInt height, UInt uiTrIdx, Bool& bCodeDQP )
[56]303{
[2]304  const UInt uiSubdiv = pcCU->getTransformIdx( uiAbsPartIdx ) + pcCU->getDepth( uiAbsPartIdx ) > uiDepth;
305  const UInt uiLog2TrafoSize = g_aucConvertToBit[pcCU->getSlice()->getSPS()->getMaxCUWidth()]+2 - uiDepth;
[56]306  UInt cbfY = pcCU->getCbf( uiAbsPartIdx, TEXT_LUMA    , uiTrIdx );
307  UInt cbfU = pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_U, uiTrIdx );
308  UInt cbfV = pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_V, uiTrIdx );
309
310  if(uiTrIdx==0)
[2]311  {
[56]312    m_bakAbsPartIdxCU = uiAbsPartIdx;
[2]313  }
[56]314  if( uiLog2TrafoSize == 2 )
[2]315  {
[56]316    UInt partNum = pcCU->getPic()->getNumPartInCU() >> ( ( uiDepth - 1 ) << 1 );
317    if( ( uiAbsPartIdx % partNum ) == 0 )
318    {
319      m_uiBakAbsPartIdx   = uiAbsPartIdx;
320      m_uiBakChromaOffset = offsetChroma;
321    }
322    else if( ( uiAbsPartIdx % partNum ) == (partNum - 1) )
323    {
324      cbfU = pcCU->getCbf( m_uiBakAbsPartIdx, TEXT_CHROMA_U, uiTrIdx );
325      cbfV = pcCU->getCbf( m_uiBakAbsPartIdx, TEXT_CHROMA_V, uiTrIdx );
326    }
[2]327  }
[608]328 
329  if( pcCU->getPredictionMode(uiAbsPartIdx) == MODE_INTRA && pcCU->getPartitionSize(uiAbsPartIdx) == SIZE_NxN && uiDepth == pcCU->getDepth(uiAbsPartIdx) )
330  {
331    assert( uiSubdiv );
332  }
333  else if( pcCU->getPredictionMode(uiAbsPartIdx) == MODE_INTER && (pcCU->getPartitionSize(uiAbsPartIdx) != SIZE_2Nx2N) && uiDepth == pcCU->getDepth(uiAbsPartIdx) &&  (pcCU->getSlice()->getSPS()->getQuadtreeTUMaxDepthInter() == 1) )
334  {
335    if ( uiLog2TrafoSize > pcCU->getQuadtreeTULog2MinSizeInCU(uiAbsPartIdx) )
[2]336    {
337      assert( uiSubdiv );
338    }
[608]339    else
[56]340    {
[608]341      assert(!uiSubdiv );
[56]342    }
[608]343  }
344  else if( uiLog2TrafoSize > pcCU->getSlice()->getSPS()->getQuadtreeTULog2MaxSize() )
345  {
346    assert( uiSubdiv );
347  }
348  else if( uiLog2TrafoSize == pcCU->getSlice()->getSPS()->getQuadtreeTULog2MinSize() )
349  {
350    assert( !uiSubdiv );
351  }
352  else if( uiLog2TrafoSize == pcCU->getQuadtreeTULog2MinSizeInCU(uiAbsPartIdx) )
353  {
354    assert( !uiSubdiv );
355  }
356  else
357  {
358    assert( uiLog2TrafoSize > pcCU->getQuadtreeTULog2MinSizeInCU(uiAbsPartIdx) );
359    m_pcEntropyCoderIf->codeTransformSubdivFlag( uiSubdiv, 5 - uiLog2TrafoSize );
360  }
361
362  const UInt uiTrDepthCurr = uiDepth - pcCU->getDepth( uiAbsPartIdx );
363  const Bool bFirstCbfOfCU = uiTrDepthCurr == 0;
364  if( bFirstCbfOfCU || uiLog2TrafoSize > 2 )
365  {
366    if( bFirstCbfOfCU || pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_U, uiTrDepthCurr - 1 ) )
[56]367    {
[608]368      m_pcEntropyCoderIf->codeQtCbf( pcCU, uiAbsPartIdx, TEXT_CHROMA_U, uiTrDepthCurr );
[56]369    }
[608]370    if( bFirstCbfOfCU || pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_V, uiTrDepthCurr - 1 ) )
[2]371    {
[608]372      m_pcEntropyCoderIf->codeQtCbf( pcCU, uiAbsPartIdx, TEXT_CHROMA_V, uiTrDepthCurr );
[2]373    }
[608]374  }
375  else if( uiLog2TrafoSize == 2 )
376  {
377    assert( pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_U, uiTrDepthCurr ) == pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_U, uiTrDepthCurr - 1 ) );
378    assert( pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_V, uiTrDepthCurr ) == pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_V, uiTrDepthCurr - 1 ) );
379  }
380 
381  if( uiSubdiv )
382  {
383    UInt size;
384    width  >>= 1;
385    height >>= 1;
386    size = width*height;
387    uiTrIdx++;
388    ++uiDepth;
389    const UInt partNum = pcCU->getPic()->getNumPartInCU() >> (uiDepth << 1);
390   
391    xEncodeTransform( pcCU, offsetLuma, offsetChroma, uiAbsPartIdx, uiDepth, width, height, uiTrIdx, bCodeDQP );
392
393    uiAbsPartIdx += partNum;  offsetLuma += size;  offsetChroma += (size>>2);
394    xEncodeTransform( pcCU, offsetLuma, offsetChroma, uiAbsPartIdx, uiDepth, width, height, uiTrIdx, bCodeDQP );
395
396    uiAbsPartIdx += partNum;  offsetLuma += size;  offsetChroma += (size>>2);
397    xEncodeTransform( pcCU, offsetLuma, offsetChroma, uiAbsPartIdx, uiDepth, width, height, uiTrIdx, bCodeDQP );
398
399    uiAbsPartIdx += partNum;  offsetLuma += size;  offsetChroma += (size>>2);
400    xEncodeTransform( pcCU, offsetLuma, offsetChroma, uiAbsPartIdx, uiDepth, width, height, uiTrIdx, bCodeDQP );
401  }
402  else
403  {
404#if !H_MV_ENC_DEC_TRAC
[2]405    {
[608]406      DTRACE_CABAC_VL( g_nSymbolCounter++ );
407      DTRACE_CABAC_T( "\tTrIdx: abspart=" );
408      DTRACE_CABAC_V( uiAbsPartIdx );
409      DTRACE_CABAC_T( "\tdepth=" );
410      DTRACE_CABAC_V( uiDepth );
411      DTRACE_CABAC_T( "\ttrdepth=" );
412      DTRACE_CABAC_V( pcCU->getTransformIdx( uiAbsPartIdx ) );
413      DTRACE_CABAC_T( "\n" );
[2]414    }
[608]415#endif
416   
417    if( pcCU->getPredictionMode(uiAbsPartIdx) != MODE_INTRA && uiDepth == pcCU->getDepth( uiAbsPartIdx ) && !pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_U, 0 ) && !pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_V, 0 ) )
418    {
419      assert( pcCU->getCbf( uiAbsPartIdx, TEXT_LUMA, 0 ) );
420      //      printf( "saved one bin! " );
421    }
[2]422    else
423    {
[608]424      m_pcEntropyCoderIf->codeQtCbf( pcCU, uiAbsPartIdx, TEXT_LUMA, pcCU->getTransformIdx( uiAbsPartIdx ) );
[2]425    }
[56]426
[608]427
428    if ( cbfY || cbfU || cbfV )
[2]429    {
[608]430      // dQP: only for LCU once
431      if ( pcCU->getSlice()->getPPS()->getUseDQP() )
[2]432      {
[608]433        if ( bCodeDQP )
[2]434        {
[608]435          encodeQP( pcCU, m_bakAbsPartIdxCU );
436          bCodeDQP = false;
[2]437        }
438      }
439    }
[608]440    if( cbfY )
[2]441    {
[608]442      Int trWidth = width;
443      Int trHeight = height;
444      m_pcEntropyCoderIf->codeCoeffNxN( pcCU, (pcCU->getCoeffY()+offsetLuma), uiAbsPartIdx, trWidth, trHeight, uiDepth, TEXT_LUMA );
[2]445    }
[608]446    if( uiLog2TrafoSize > 2 )
[2]447    {
[608]448      Int trWidth = width >> 1;
449      Int trHeight = height >> 1;
450      if( cbfU )
[2]451      {
[608]452        m_pcEntropyCoderIf->codeCoeffNxN( pcCU, (pcCU->getCoeffCb()+offsetChroma), uiAbsPartIdx, trWidth, trHeight, uiDepth, TEXT_CHROMA_U );
[2]453      }
[608]454      if( cbfV )
[56]455      {
[608]456        m_pcEntropyCoderIf->codeCoeffNxN( pcCU, (pcCU->getCoeffCr()+offsetChroma), uiAbsPartIdx, trWidth, trHeight, uiDepth, TEXT_CHROMA_V );
[56]457      }
[608]458    }
459    else
460    {
461      UInt partNum = pcCU->getPic()->getNumPartInCU() >> ( ( uiDepth - 1 ) << 1 );
462      if( ( uiAbsPartIdx % partNum ) == (partNum - 1) )
[2]463      {
[56]464        Int trWidth = width;
465        Int trHeight = height;
466        if( cbfU )
[2]467        {
[608]468          m_pcEntropyCoderIf->codeCoeffNxN( pcCU, (pcCU->getCoeffCb()+m_uiBakChromaOffset), m_uiBakAbsPartIdx, trWidth, trHeight, uiDepth, TEXT_CHROMA_U );
[2]469        }
[56]470        if( cbfV )
471        {
[608]472          m_pcEntropyCoderIf->codeCoeffNxN( pcCU, (pcCU->getCoeffCr()+m_uiBakChromaOffset), m_uiBakAbsPartIdx, trWidth, trHeight, uiDepth, TEXT_CHROMA_V );
[56]473        }
[2]474      }
475    }
476  }
477}
478
479// Intra direction for Luma
[608]480Void TEncEntropy::encodeIntraDirModeLuma  ( TComDataCU* pcCU, UInt absPartIdx, Bool isMultiplePU )
[2]481{
[608]482  m_pcEntropyCoderIf->codeIntraDirLumaAng( pcCU, absPartIdx , isMultiplePU);
[2]483}
484
485// Intra direction for Chroma
486Void TEncEntropy::encodeIntraDirModeChroma( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool bRD )
487{
488  if( bRD )
[56]489  {
[2]490    uiAbsPartIdx = 0;
[56]491  }
[2]492 
493  m_pcEntropyCoderIf->codeIntraDirChroma( pcCU, uiAbsPartIdx );
494}
495
[608]496Void TEncEntropy::encodePredInfo( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool bRD )
[2]497{
498  if( bRD )
[56]499  {
[2]500    uiAbsPartIdx = 0;
[56]501  }
[2]502  if( pcCU->isIntra( uiAbsPartIdx ) )                                 // If it is Intra mode, encode intra prediction mode.
503  {
[608]504    encodeIntraDirModeLuma  ( pcCU, uiAbsPartIdx,true );
505#if H_3D_DIM_SDC
506    if(!pcCU->getSDCFlag(uiAbsPartIdx))
[443]507#endif
[608]508    encodeIntraDirModeChroma( pcCU, uiAbsPartIdx, bRD );
[2]509  }
510  else                                                                // if it is Inter mode, encode motion vector and reference index
511  {
[56]512    encodePUWise( pcCU, uiAbsPartIdx, bRD );
[2]513  }
514}
515
516/** encode motion information for every PU block
517 * \param pcCU
518 * \param uiAbsPartIdx
519 * \param bRD
520 * \returns Void
521 */
522Void TEncEntropy::encodePUWise( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool bRD )
523{
524  if ( bRD )
[56]525  {
[2]526    uiAbsPartIdx = 0;
[56]527  }
528 
[2]529  PartSize ePartSize = pcCU->getPartitionSize( uiAbsPartIdx );
530  UInt uiNumPU = ( ePartSize == SIZE_2Nx2N ? 1 : ( ePartSize == SIZE_NxN ? 4 : 2 ) );
531  UInt uiDepth = pcCU->getDepth( uiAbsPartIdx );
532  UInt uiPUOffset = ( g_auiPUOffset[UInt( ePartSize )] << ( ( pcCU->getSlice()->getSPS()->getMaxCUDepth() - uiDepth ) << 1 ) ) >> 4;
533
534  for ( UInt uiPartIdx = 0, uiSubPartIdx = uiAbsPartIdx; uiPartIdx < uiNumPU; uiPartIdx++, uiSubPartIdx += uiPUOffset )
535  {
[608]536#if H_MV_ENC_DEC_TRAC
537    DTRACE_PU_S("=========== prediction_unit ===========\n")
538       //Todo:
539      //DTRACE_PU("x0", uiLPelX)
540      //DTRACE_PU("x1", uiTPelY)
541#endif
542    encodeMergeFlag( pcCU, uiSubPartIdx );
[2]543    if ( pcCU->getMergeFlag( uiSubPartIdx ) )
544    {
[608]545      encodeMergeIndex( pcCU, uiSubPartIdx );
[2]546    }
547    else
548    {
549      encodeInterDirPU( pcCU, uiSubPartIdx );
550      for ( UInt uiRefListIdx = 0; uiRefListIdx < 2; uiRefListIdx++ )
551      {
552        if ( pcCU->getSlice()->getNumRefIdx( RefPicList( uiRefListIdx ) ) > 0 )
553        {
554          encodeRefFrmIdxPU ( pcCU, uiSubPartIdx, RefPicList( uiRefListIdx ) );
555          encodeMvdPU       ( pcCU, uiSubPartIdx, RefPicList( uiRefListIdx ) );
556          encodeMVPIdxPU    ( pcCU, uiSubPartIdx, RefPicList( uiRefListIdx ) );
557        }
558      }
559    }
560  }
561
562  return;
563}
564
565Void TEncEntropy::encodeInterDirPU( TComDataCU* pcCU, UInt uiAbsPartIdx )
566{
567  if ( !pcCU->getSlice()->isInterB() )
568  {
569    return;
570  }
571
572  m_pcEntropyCoderIf->codeInterDir( pcCU, uiAbsPartIdx );
573  return;
574}
575
576/** encode reference frame index for a PU block
577 * \param pcCU
578 * \param uiAbsPartIdx
579 * \param eRefList
580 * \returns Void
581 */
582Void TEncEntropy::encodeRefFrmIdxPU( TComDataCU* pcCU, UInt uiAbsPartIdx, RefPicList eRefList )
583{
584  assert( !pcCU->isIntra( uiAbsPartIdx ) );
585  {
[56]586    if ( ( pcCU->getSlice()->getNumRefIdx( eRefList ) == 1 ) )
587    {
588      return;
589    }
[2]590
[56]591    if ( pcCU->getInterDir( uiAbsPartIdx ) & ( 1 << eRefList ) )
592    {
593      m_pcEntropyCoderIf->codeRefFrmIdx( pcCU, uiAbsPartIdx, eRefList );
594    }
[2]595  }
596
597  return;
598}
599
600/** encode motion vector difference for a PU block
601 * \param pcCU
602 * \param uiAbsPartIdx
603 * \param eRefList
604 * \returns Void
605 */
606Void TEncEntropy::encodeMvdPU( TComDataCU* pcCU, UInt uiAbsPartIdx, RefPicList eRefList )
607{
608  assert( !pcCU->isIntra( uiAbsPartIdx ) );
609
610  if ( pcCU->getInterDir( uiAbsPartIdx ) & ( 1 << eRefList ) )
611  {
612    m_pcEntropyCoderIf->codeMvd( pcCU, uiAbsPartIdx, eRefList );
613  }
614  return;
615}
616
617Void TEncEntropy::encodeMVPIdxPU( TComDataCU* pcCU, UInt uiAbsPartIdx, RefPicList eRefList )
618{
[608]619  if ( (pcCU->getInterDir( uiAbsPartIdx ) & ( 1 << eRefList )) )
[2]620  {
621    m_pcEntropyCoderIf->codeMVPIdx( pcCU, uiAbsPartIdx, eRefList );
622  }
623
624  return;
625}
626
627Void TEncEntropy::encodeQtCbf( TComDataCU* pcCU, UInt uiAbsPartIdx, TextType eType, UInt uiTrDepth )
628{
629  m_pcEntropyCoderIf->codeQtCbf( pcCU, uiAbsPartIdx, eType, uiTrDepth );
630}
631
632Void TEncEntropy::encodeTransformSubdivFlag( UInt uiSymbol, UInt uiCtx )
633{
634  m_pcEntropyCoderIf->codeTransformSubdivFlag( uiSymbol, uiCtx );
635}
636
637Void TEncEntropy::encodeQtRootCbf( TComDataCU* pcCU, UInt uiAbsPartIdx )
638{
639  m_pcEntropyCoderIf->codeQtRootCbf( pcCU, uiAbsPartIdx );
640}
641
[608]642Void TEncEntropy::encodeQtCbfZero( TComDataCU* pcCU, TextType eType, UInt uiTrDepth )
643{
644  m_pcEntropyCoderIf->codeQtCbfZero( pcCU, eType, uiTrDepth );
645}
646Void TEncEntropy::encodeQtRootCbfZero( TComDataCU* pcCU )
647{
648  m_pcEntropyCoderIf->codeQtRootCbfZero( pcCU );
649}
650
[2]651// dQP
652Void TEncEntropy::encodeQP( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool bRD )
653{
654  if( bRD )
[56]655  {
[2]656    uiAbsPartIdx = 0;
[56]657  }
[2]658 
[56]659  if ( pcCU->getSlice()->getPPS()->getUseDQP() )
[2]660  {
661    m_pcEntropyCoderIf->codeDeltaQP( pcCU, uiAbsPartIdx );
662  }
663}
664
665
666// texture
667/** encode coefficients
668 * \param pcCU
669 * \param uiAbsPartIdx
670 * \param uiDepth
671 * \param uiWidth
672 * \param uiHeight
673 */
[56]674Void TEncEntropy::encodeCoeff( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, UInt uiWidth, UInt uiHeight, Bool& bCodeDQP )
[2]675{
676  UInt uiMinCoeffSize = pcCU->getPic()->getMinCUWidth()*pcCU->getPic()->getMinCUHeight();
677  UInt uiLumaOffset   = uiMinCoeffSize*uiAbsPartIdx;
678  UInt uiChromaOffset = uiLumaOffset>>2;
[833]679#if H_3D_DIM_SDC
680  if( pcCU->getSDCFlag( uiAbsPartIdx ) && pcCU->isIntra( uiAbsPartIdx ) )
681  {
682    assert( pcCU->getPartitionSize(uiAbsPartIdx) == SIZE_2Nx2N );
683    assert( pcCU->getTransformIdx(uiAbsPartIdx) == 0 );
684    assert( pcCU->getCbf(uiAbsPartIdx, TEXT_LUMA) == 1 );
685    assert( pcCU->getCbf(uiAbsPartIdx, TEXT_CHROMA_U) == 1 );
686    assert( pcCU->getCbf(uiAbsPartIdx, TEXT_CHROMA_V) == 1 );
687  }
688
689  if( pcCU->getSDCFlag( uiAbsPartIdx ) && !pcCU->isIntra( uiAbsPartIdx ) )
690  {
691    assert( !pcCU->isSkipped( uiAbsPartIdx ) );
692    assert( !pcCU->isIntra( uiAbsPartIdx) );
693    assert( pcCU->getSlice()->getIsDepth() );
694  }
[884]695
[833]696  if( pcCU->getSlice()->getIsDepth() && ( pcCU->getSDCFlag( uiAbsPartIdx ) || pcCU->isIntra( uiAbsPartIdx ) ) )
697  {
698    Int iPartNum = ( pcCU->isIntra( uiAbsPartIdx ) && pcCU->getPartitionSize( uiAbsPartIdx ) == SIZE_NxN ) ? 4 : 1;
699    UInt uiPartOffset = ( pcCU->getPic()->getNumPartInCU() >> ( pcCU->getDepth( uiAbsPartIdx ) << 1 ) ) >> 2;
[608]700   
[833]701    if( !pcCU->getSDCFlag( uiAbsPartIdx ) )
702    {
703      for( Int iPart = 0; iPart < iPartNum; iPart++ )
704      {
705        if( getDimType( pcCU->getLumaIntraDir( uiAbsPartIdx + uiPartOffset*iPart ) ) < DIM_NUM_TYPE ) 
706        {
707          m_pcEntropyCoderIf->codeDeltaDC( pcCU, uiAbsPartIdx + uiPartOffset*iPart );
708        }
709      }
710    }
711    else
712    {
713      m_pcEntropyCoderIf->codeDeltaDC( pcCU, uiAbsPartIdx );
714      return;
715    }
716  }
[443]717#endif
[608]718
[2]719  if( pcCU->isIntra(uiAbsPartIdx) )
720  {
[608]721#if !H_MV
[56]722    DTRACE_CABAC_VL( g_nSymbolCounter++ )
[2]723    DTRACE_CABAC_T( "\tdecodeTransformIdx()\tCUDepth=" )
724    DTRACE_CABAC_V( uiDepth )
725    DTRACE_CABAC_T( "\n" )
[608]726#endif
[2]727  }
728  else
729  {
[608]730    if( !(pcCU->getMergeFlag( uiAbsPartIdx ) && pcCU->getPartitionSize(uiAbsPartIdx) == SIZE_2Nx2N ) )
[2]731    {
[608]732      m_pcEntropyCoderIf->codeQtRootCbf( pcCU, uiAbsPartIdx );
[2]733    }
[608]734    if ( !pcCU->getQtRootCbf( uiAbsPartIdx ) )
[189]735    {
[608]736      return;
[189]737    }
738  }
[608]739 
740  xEncodeTransform( pcCU, uiLumaOffset, uiChromaOffset, uiAbsPartIdx, uiDepth, uiWidth, uiHeight, 0, bCodeDQP);
[2]741}
742
[56]743Void TEncEntropy::encodeCoeffNxN( TComDataCU* pcCU, TCoeff* pcCoeff, UInt uiAbsPartIdx, UInt uiTrWidth, UInt uiTrHeight, UInt uiDepth, TextType eType )
[608]744{
745  // This is for Transform unit processing. This may be used at mode selection stage for Inter.
[56]746  m_pcEntropyCoderIf->codeCoeffNxN( pcCU, pcCoeff, uiAbsPartIdx, uiTrWidth, uiTrHeight, uiDepth, eType );
[2]747}
748
[56]749Void TEncEntropy::estimateBit (estBitsSbacStruct* pcEstBitsSbac, Int width, Int height, TextType eTType)
750{ 
751  eTType = eTType == TEXT_LUMA ? TEXT_LUMA : TEXT_CHROMA;
752 
753  m_pcEntropyCoderIf->estBit ( pcEstBitsSbac, width, height, eTType );
754}
755
756Int TEncEntropy::countNonZeroCoeffs( TCoeff* pcCoef, UInt uiSize )
757{
758  Int count = 0;
759 
760  for ( Int i = 0; i < uiSize; i++ )
[2]761  {
[56]762    count += pcCoef[i] != 0;
[2]763  }
[56]764 
765  return count;
766}
[2]767
[56]768/** encode quantization matrix
769 * \param scalingList quantization matrix information
770 */
771Void TEncEntropy::encodeScalingList( TComScalingList* scalingList )
772{
773  m_pcEntropyCoderIf->codeScalingList( scalingList );
[2]774}
775
[655]776#if H_3D_INTER_SDC
[833]777Void TEncEntropy::encodeDeltaDC  ( TComDataCU* pcCU, UInt absPartIdx )
778{
779  m_pcEntropyCoderIf->codeDeltaDC( pcCU, absPartIdx );
780}
781
782Void TEncEntropy::encodeSDCFlag( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool bRD )
783{
784  if( ( !pcCU->isIntra( uiAbsPartIdx ) && !pcCU->getSlice()->getVPS()->getInterSDCFlag( pcCU->getSlice()->getLayerIdInVps() ) ) || 
785    ( pcCU->isIntra( uiAbsPartIdx ) && !pcCU->getSlice()->getVPS()->getVpsDepthModesFlag( pcCU->getSlice()->getLayerIdInVps() ) ) )
786  {
787    return;
788  }
789
790  if( !pcCU->getSlice()->getIsDepth() || pcCU->getPartitionSize( uiAbsPartIdx ) != SIZE_2Nx2N || pcCU->isSkipped( uiAbsPartIdx ) )
791  {
792    return;
793  }
794
795  assert( pcCU->getPartitionSize( uiAbsPartIdx ) == SIZE_2Nx2N || ( !pcCU->isIntra( uiAbsPartIdx ) && !pcCU->isSkipped( uiAbsPartIdx ) ) );
796
797  if( bRD )
798  {
799    uiAbsPartIdx = 0;
800  }
801
802  m_pcEntropyCoderIf->codeSDCFlag( pcCU, uiAbsPartIdx );
803}
[2]804
[189]805#endif
[833]806#if H_3D_DBBP
807Void TEncEntropy::encodeDBBPFlag( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool bRD )
808{
809  if( bRD )
810  {
811    uiAbsPartIdx = 0;
812  }
813  m_pcEntropyCoderIf->codeDBBPFlag( pcCU, uiAbsPartIdx );
814}
815#endif
[56]816//! \}
Note: See TracBrowser for help on using the repository browser.