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

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

Integration of H0094

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