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

Last change on this file since 1191 was 1179, checked in by tech, 10 years ago

Merged branch 13.1-dev0@1178.

  • Property svn:eol-style set to native
File size: 27.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 *
[1179]6* Copyright (c) 2010-2015, 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
[1124]80Void TEncEntropy::encodeSPS( TComSPS* pcSPS )
81{
82  m_pcEntropyCoderIf->codeSPS( pcSPS );
83  return;
84}
[2]85
[608]86Void TEncEntropy::encodeCUTransquantBypassFlag( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool bRD )
[2]87{
88  if( bRD )
[56]89  {
[2]90    uiAbsPartIdx = 0;
[56]91  }
[608]92  m_pcEntropyCoderIf->codeCUTransquantBypassFlag( pcCU, uiAbsPartIdx );
[2]93}
94
[608]95Void TEncEntropy::encodeVPS( TComVPS* pcVPS )
[189]96{
[608]97  m_pcEntropyCoderIf->codeVPS( pcVPS );
98  return;
99}
100
101Void TEncEntropy::encodeSkipFlag( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool bRD )
102{
103  if ( pcCU->getSlice()->isIntra() )
[189]104  {
105    return;
106  }
107  if( bRD )
108  {
109    uiAbsPartIdx = 0;
110  }
[608]111  m_pcEntropyCoderIf->codeSkipFlag( pcCU, uiAbsPartIdx );
[189]112}
[1179]113
114#if SEC_DEPTH_INTRA_SKIP_MODE_K0033
115Void TEncEntropy::encodeDIS( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool bRD )
116{
117  if ( !pcCU->getSlice()->getIsDepth() )
118  {
119    return;
120  }
121  if( bRD )
122  {
123    uiAbsPartIdx = 0;
124  }
125  m_pcEntropyCoderIf->codeDIS( pcCU, uiAbsPartIdx );
126}
127#else
[1084]128#if H_3D_SINGLE_DEPTH
[1039]129Void TEncEntropy::encodeSingleDepthMode( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool bRD )
130{
[1124]131  if(!pcCU->getSlice()->getIntraSingleFlag() )
132  {
133    return;
134  }
[1039]135  if( bRD )
136  {
137    uiAbsPartIdx = 0;
138  }
139  m_pcEntropyCoderIf->codeSingleDepthMode( pcCU, uiAbsPartIdx );
140}
141#endif
[1179]142#endif
143
[2]144/** encode merge flag
145 * \param pcCU
146 * \param uiAbsPartIdx
147 * \returns Void
148 */
[608]149Void TEncEntropy::encodeMergeFlag( TComDataCU* pcCU, UInt uiAbsPartIdx )
[2]150{ 
[56]151  // at least one merge candidate exists
152  m_pcEntropyCoderIf->codeMergeFlag( pcCU, uiAbsPartIdx );
[2]153}
154
155/** encode merge index
156 * \param pcCU
157 * \param uiAbsPartIdx
158 * \param uiPUIdx
159 * \param bRD
160 * \returns Void
161 */
[608]162Void TEncEntropy::encodeMergeIndex( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool bRD )
[2]163{
164  if( bRD )
165  {
166    uiAbsPartIdx = 0;
167    assert( pcCU->getPartitionSize(uiAbsPartIdx) == SIZE_2Nx2N );
168  }
[608]169  m_pcEntropyCoderIf->codeMergeIndex( pcCU, uiAbsPartIdx );
[2]170}
171
[608]172#if H_3D_IC
173Void TEncEntropy::encodeICFlag( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool bRD )
[443]174{
[833]175  if ( pcCU->isIntra( uiAbsPartIdx ) || ( pcCU->getSlice()->getViewIndex() == 0 ) || pcCU->getSlice()->getIsDepth() || pcCU->getARPW( uiAbsPartIdx ) > 0 )
[443]176  {
177    return;
178  }
[608]179
180  if( !pcCU->getSlice()->getApplyIC() )
[976]181  {
[608]182    return;
[976]183  }
[608]184
[443]185  if( bRD )
186  {
187    uiAbsPartIdx = 0;
188  }
[950]189  else
190  {
[1066]191    Int ICEnableCandidate = pcCU->getSlice()->getICEnableCandidate(pcCU->getSlice()->getDepth());
192    Int ICEnableNum = pcCU->getSlice()->getICEnableNum(pcCU->getSlice()->getDepth());
193    ICEnableCandidate++;
194    if(pcCU->getICFlag(uiAbsPartIdx))
195    {
196      ICEnableNum++;
197    }
198    pcCU->getSlice()->setICEnableCandidate(pcCU->getSlice()->getDepth(), ICEnableCandidate);
199    pcCU->getSlice()->setICEnableNum(pcCU->getSlice()->getDepth(), ICEnableNum);
[950]200  }
[608]201  if( pcCU->isICFlagRequired( uiAbsPartIdx ) )
[976]202  {
[608]203    m_pcEntropyCoderIf->codeICFlag( pcCU, uiAbsPartIdx );
[976]204  }
[443]205}
206#endif
[2]207
[608]208#if H_3D_ARP
209Void TEncEntropy::encodeARPW( TComDataCU* pcCU, UInt uiAbsPartIdx )
[56]210{
[608]211  if( !pcCU->getSlice()->getARPStepNum() || pcCU->isIntra( uiAbsPartIdx ) ) 
[56]212  {
[608]213    return;
[56]214  }
215
[608]216  if ( pcCU->getPartitionSize(uiAbsPartIdx)!=SIZE_2Nx2N )
[56]217  {
[608]218    assert(pcCU->getARPW (uiAbsPartIdx) == 0);
[56]219  }
[608]220  else
[56]221  {
[608]222    m_pcEntropyCoderIf->codeARPW( pcCU, uiAbsPartIdx );
[56]223  }
224}
[608]225#endif
[56]226
[2]227/** encode prediction mode
228 * \param pcCU
229 * \param uiAbsPartIdx
230 * \param bRD
231 * \returns Void
232 */
233Void TEncEntropy::encodePredMode( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool bRD )
234{
235  if( bRD )
[56]236  {
[2]237    uiAbsPartIdx = 0;
[56]238  }
[2]239  if ( pcCU->getSlice()->isIntra() )
240  {
241    return;
242  }
[56]243
[2]244  m_pcEntropyCoderIf->codePredMode( pcCU, uiAbsPartIdx );
245}
246
247// Split mode
248Void TEncEntropy::encodeSplitFlag( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, Bool bRD )
249{
250  if( bRD )
[56]251  {
[2]252    uiAbsPartIdx = 0;
[56]253  }
[2]254  m_pcEntropyCoderIf->codeSplitFlag( pcCU, uiAbsPartIdx, uiDepth );
255}
256
257/** encode partition size
258 * \param pcCU
259 * \param uiAbsPartIdx
260 * \param uiDepth
261 * \param bRD
262 * \returns Void
263 */
264Void TEncEntropy::encodePartSize( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, Bool bRD )
265{
266  if( bRD )
[56]267  {
[2]268    uiAbsPartIdx = 0;
[56]269  }
[833]270 
[2]271  m_pcEntropyCoderIf->codePartSize( pcCU, uiAbsPartIdx, uiDepth );
[833]272 
[1179]273#if !HHI_MOVE_SYN_K0052
[833]274#if H_3D_DBBP
[1124]275  if( pcCU->getSlice()->getDepthBasedBlkPartFlag() && (pcCU->getPartitionSize(uiAbsPartIdx) == SIZE_2NxN || pcCU->getPartitionSize(uiAbsPartIdx) == SIZE_Nx2N) && pcCU->getWidth(uiAbsPartIdx) > 8 && pcCU->getSlice()->getDefaultRefViewIdxAvailableFlag() )
[833]276  {
277    encodeDBBPFlag(pcCU, uiAbsPartIdx, bRD);
278  }
279#endif
[1179]280#endif
[2]281}
282
[56]283/** Encode I_PCM information.
284 * \param pcCU pointer to CU
285 * \param uiAbsPartIdx CU index
286 * \param bRD flag indicating estimation or encoding
287 * \returns Void
288 */
289Void TEncEntropy::encodeIPCMInfo( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool bRD )
[2]290{
[56]291  if(!pcCU->getSlice()->getSPS()->getUsePCM()
292    || pcCU->getWidth(uiAbsPartIdx) > (1<<pcCU->getSlice()->getSPS()->getPCMLog2MaxSize())
293    || pcCU->getWidth(uiAbsPartIdx) < (1<<pcCU->getSlice()->getSPS()->getPCMLog2MinSize()))
294  {
295    return;
296  }
[189]297 
[56]298  if( bRD )
299  {
300    uiAbsPartIdx = 0;
301  }
302 
[608]303  m_pcEntropyCoderIf->codeIPCMInfo ( pcCU, uiAbsPartIdx );
[56]304}
305
[1179]306#if H_3D_DISABLE_CHROMA
307Void TEncEntropy::xEncodeTransform( TComDataCU* pcCU,UInt offsetLuma, UInt offsetChroma, UInt uiAbsPartIdx, UInt uiDepth, UInt width, UInt height, UInt uiTrIdx, Bool& bCodeDQP, Bool rd )
308#else
[608]309Void TEncEntropy::xEncodeTransform( TComDataCU* pcCU,UInt offsetLuma, UInt offsetChroma, UInt uiAbsPartIdx, UInt uiDepth, UInt width, UInt height, UInt uiTrIdx, Bool& bCodeDQP )
[1179]310#endif
[56]311{
[1179]312
313#if H_MV_ENC_DEC_TRAC
314#if ENC_DEC_TRACE
315  UInt uiLPelX   = pcCU->getCUPelX() + g_auiRasterToPelX[ g_auiZscanToRaster[uiAbsPartIdx] ];
316  UInt uiTPelY   = pcCU->getCUPelY() + g_auiRasterToPelY[ g_auiZscanToRaster[uiAbsPartIdx] ];
317
318  DTRACE_TU_S("=========== transform_tree ===========\n")
319  DTRACE_TU("x0", uiLPelX)
320  DTRACE_TU("x1", uiTPelY)
321  DTRACE_TU("log2TrafoSize", g_uiMaxCUWidth>>uiDepth)
322  DTRACE_TU("trafoDepth"  , uiDepth)
323#endif
324#endif
325
[2]326  const UInt uiSubdiv = pcCU->getTransformIdx( uiAbsPartIdx ) + pcCU->getDepth( uiAbsPartIdx ) > uiDepth;
327  const UInt uiLog2TrafoSize = g_aucConvertToBit[pcCU->getSlice()->getSPS()->getMaxCUWidth()]+2 - uiDepth;
[56]328  UInt cbfY = pcCU->getCbf( uiAbsPartIdx, TEXT_LUMA    , uiTrIdx );
329  UInt cbfU = pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_U, uiTrIdx );
330  UInt cbfV = pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_V, uiTrIdx );
[1179]331#if H_3D_DISABLE_CHROMA
332  if( !rd && pcCU->getSlice()->getSPS()->getChromaFormatIdc() == 0 )
333  {
334    cbfU = 0;
335    cbfV = 0;
336  }
337#endif
[56]338  if(uiTrIdx==0)
[2]339  {
[56]340    m_bakAbsPartIdxCU = uiAbsPartIdx;
[2]341  }
[56]342  if( uiLog2TrafoSize == 2 )
[2]343  {
[56]344    UInt partNum = pcCU->getPic()->getNumPartInCU() >> ( ( uiDepth - 1 ) << 1 );
345    if( ( uiAbsPartIdx % partNum ) == 0 )
346    {
347      m_uiBakAbsPartIdx   = uiAbsPartIdx;
348      m_uiBakChromaOffset = offsetChroma;
349    }
350    else if( ( uiAbsPartIdx % partNum ) == (partNum - 1) )
351    {
352      cbfU = pcCU->getCbf( m_uiBakAbsPartIdx, TEXT_CHROMA_U, uiTrIdx );
353      cbfV = pcCU->getCbf( m_uiBakAbsPartIdx, TEXT_CHROMA_V, uiTrIdx );
[1179]354#if H_3D_DISABLE_CHROMA
355      if( !rd && pcCU->getSlice()->getSPS()->getChromaFormatIdc() == 0 )
356      {
357        cbfU = 0;
358        cbfV = 0;
359      }
360#endif
[56]361    }
[2]362  }
[608]363 
364  if( pcCU->getPredictionMode(uiAbsPartIdx) == MODE_INTRA && pcCU->getPartitionSize(uiAbsPartIdx) == SIZE_NxN && uiDepth == pcCU->getDepth(uiAbsPartIdx) )
365  {
366    assert( uiSubdiv );
367  }
368  else if( pcCU->getPredictionMode(uiAbsPartIdx) == MODE_INTER && (pcCU->getPartitionSize(uiAbsPartIdx) != SIZE_2Nx2N) && uiDepth == pcCU->getDepth(uiAbsPartIdx) &&  (pcCU->getSlice()->getSPS()->getQuadtreeTUMaxDepthInter() == 1) )
369  {
370    if ( uiLog2TrafoSize > pcCU->getQuadtreeTULog2MinSizeInCU(uiAbsPartIdx) )
[2]371    {
372      assert( uiSubdiv );
373    }
[608]374    else
[56]375    {
[608]376      assert(!uiSubdiv );
[56]377    }
[608]378  }
379  else if( uiLog2TrafoSize > pcCU->getSlice()->getSPS()->getQuadtreeTULog2MaxSize() )
380  {
381    assert( uiSubdiv );
382  }
383  else if( uiLog2TrafoSize == pcCU->getSlice()->getSPS()->getQuadtreeTULog2MinSize() )
384  {
385    assert( !uiSubdiv );
386  }
387  else if( uiLog2TrafoSize == pcCU->getQuadtreeTULog2MinSizeInCU(uiAbsPartIdx) )
388  {
389    assert( !uiSubdiv );
390  }
391  else
392  {
393    assert( uiLog2TrafoSize > pcCU->getQuadtreeTULog2MinSizeInCU(uiAbsPartIdx) );
394    m_pcEntropyCoderIf->codeTransformSubdivFlag( uiSubdiv, 5 - uiLog2TrafoSize );
395  }
396
397  const UInt uiTrDepthCurr = uiDepth - pcCU->getDepth( uiAbsPartIdx );
398  const Bool bFirstCbfOfCU = uiTrDepthCurr == 0;
399  if( bFirstCbfOfCU || uiLog2TrafoSize > 2 )
400  {
[1179]401#if H_3D_DISABLE_CHROMA
402    if (pcCU->getSlice()->getSPS()->getChromaFormatIdc() != 0 || rd)
403    {
404      if( bFirstCbfOfCU || pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_U, uiTrDepthCurr - 1 ) )
405      {
406        m_pcEntropyCoderIf->codeQtCbf( pcCU, uiAbsPartIdx, TEXT_CHROMA_U, uiTrDepthCurr );
407      }
408      if( bFirstCbfOfCU || pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_V, uiTrDepthCurr - 1 ) )
409      {
410        m_pcEntropyCoderIf->codeQtCbf( pcCU, uiAbsPartIdx, TEXT_CHROMA_V, uiTrDepthCurr );
411      }
412    }
413#else
[608]414    if( bFirstCbfOfCU || pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_U, uiTrDepthCurr - 1 ) )
[56]415    {
[608]416      m_pcEntropyCoderIf->codeQtCbf( pcCU, uiAbsPartIdx, TEXT_CHROMA_U, uiTrDepthCurr );
[56]417    }
[608]418    if( bFirstCbfOfCU || pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_V, uiTrDepthCurr - 1 ) )
[2]419    {
[608]420      m_pcEntropyCoderIf->codeQtCbf( pcCU, uiAbsPartIdx, TEXT_CHROMA_V, uiTrDepthCurr );
[2]421    }
[1179]422#endif
[608]423  }
424  else if( uiLog2TrafoSize == 2 )
425  {
[1179]426#if H_3D_DISABLE_CHROMA
427    if ( rd && pcCU->getSlice()->getSPS()->getChromaFormatIdc() != 0 )
428    {
[608]429    assert( pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_U, uiTrDepthCurr ) == pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_U, uiTrDepthCurr - 1 ) );
430    assert( pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_V, uiTrDepthCurr ) == pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_V, uiTrDepthCurr - 1 ) );
431  }
[1179]432#else
433    assert( pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_U, uiTrDepthCurr ) == pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_U, uiTrDepthCurr - 1 ) );
434    assert( pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_V, uiTrDepthCurr ) == pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_V, uiTrDepthCurr - 1 ) );
435#endif
436  }
[608]437 
438  if( uiSubdiv )
439  {
440    UInt size;
441    width  >>= 1;
442    height >>= 1;
443    size = width*height;
444    uiTrIdx++;
445    ++uiDepth;
446    const UInt partNum = pcCU->getPic()->getNumPartInCU() >> (uiDepth << 1);
447   
[1179]448#if H_3D_DISABLE_CHROMA
449    xEncodeTransform( pcCU, offsetLuma, offsetChroma, uiAbsPartIdx, uiDepth, width, height, uiTrIdx, bCodeDQP, rd );
450
451    uiAbsPartIdx += partNum;  offsetLuma += size;  offsetChroma += (size>>2);
452    xEncodeTransform( pcCU, offsetLuma, offsetChroma, uiAbsPartIdx, uiDepth, width, height, uiTrIdx, bCodeDQP ,rd );
453
454    uiAbsPartIdx += partNum;  offsetLuma += size;  offsetChroma += (size>>2);
455    xEncodeTransform( pcCU, offsetLuma, offsetChroma, uiAbsPartIdx, uiDepth, width, height, uiTrIdx, bCodeDQP, rd );
456
457    uiAbsPartIdx += partNum;  offsetLuma += size;  offsetChroma += (size>>2);
458    xEncodeTransform( pcCU, offsetLuma, offsetChroma, uiAbsPartIdx, uiDepth, width, height, uiTrIdx, bCodeDQP, rd );
459#else
[608]460    xEncodeTransform( pcCU, offsetLuma, offsetChroma, uiAbsPartIdx, uiDepth, width, height, uiTrIdx, bCodeDQP );
461
462    uiAbsPartIdx += partNum;  offsetLuma += size;  offsetChroma += (size>>2);
463    xEncodeTransform( pcCU, offsetLuma, offsetChroma, uiAbsPartIdx, uiDepth, width, height, uiTrIdx, bCodeDQP );
464
465    uiAbsPartIdx += partNum;  offsetLuma += size;  offsetChroma += (size>>2);
466    xEncodeTransform( pcCU, offsetLuma, offsetChroma, uiAbsPartIdx, uiDepth, width, height, uiTrIdx, bCodeDQP );
467
468    uiAbsPartIdx += partNum;  offsetLuma += size;  offsetChroma += (size>>2);
469    xEncodeTransform( pcCU, offsetLuma, offsetChroma, uiAbsPartIdx, uiDepth, width, height, uiTrIdx, bCodeDQP );
[1179]470#endif
[608]471  }
472  else
473  {
474#if !H_MV_ENC_DEC_TRAC
[2]475    {
[608]476      DTRACE_CABAC_VL( g_nSymbolCounter++ );
477      DTRACE_CABAC_T( "\tTrIdx: abspart=" );
478      DTRACE_CABAC_V( uiAbsPartIdx );
479      DTRACE_CABAC_T( "\tdepth=" );
480      DTRACE_CABAC_V( uiDepth );
481      DTRACE_CABAC_T( "\ttrdepth=" );
482      DTRACE_CABAC_V( pcCU->getTransformIdx( uiAbsPartIdx ) );
483      DTRACE_CABAC_T( "\n" );
[2]484    }
[608]485#endif
486   
[1179]487#if H_3D_DISABLE_CHROMA
488    Bool notcbfUV = !rd && pcCU->getSlice()->getSPS()->getChromaFormatIdc() == 0 ? 1 : ( !pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_U, 0 ) && !pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_V, 0 ) ) ;
489    if( pcCU->getPredictionMode(uiAbsPartIdx) != MODE_INTRA && 
490      uiDepth == pcCU->getDepth( uiAbsPartIdx ) && notcbfUV ) 
491#else
[608]492    if( pcCU->getPredictionMode(uiAbsPartIdx) != MODE_INTRA && uiDepth == pcCU->getDepth( uiAbsPartIdx ) && !pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_U, 0 ) && !pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_V, 0 ) )
[1179]493#endif
[608]494    {
495      assert( pcCU->getCbf( uiAbsPartIdx, TEXT_LUMA, 0 ) );
496      //      printf( "saved one bin! " );
497    }
[2]498    else
499    {
[608]500      m_pcEntropyCoderIf->codeQtCbf( pcCU, uiAbsPartIdx, TEXT_LUMA, pcCU->getTransformIdx( uiAbsPartIdx ) );
[2]501    }
[56]502
[608]503
504    if ( cbfY || cbfU || cbfV )
[2]505    {
[608]506      // dQP: only for LCU once
507      if ( pcCU->getSlice()->getPPS()->getUseDQP() )
[2]508      {
[608]509        if ( bCodeDQP )
[2]510        {
[608]511          encodeQP( pcCU, m_bakAbsPartIdxCU );
512          bCodeDQP = false;
[2]513        }
514      }
515    }
[608]516    if( cbfY )
[2]517    {
[608]518      Int trWidth = width;
519      Int trHeight = height;
520      m_pcEntropyCoderIf->codeCoeffNxN( pcCU, (pcCU->getCoeffY()+offsetLuma), uiAbsPartIdx, trWidth, trHeight, uiDepth, TEXT_LUMA );
[2]521    }
[608]522    if( uiLog2TrafoSize > 2 )
[2]523    {
[608]524      Int trWidth = width >> 1;
525      Int trHeight = height >> 1;
526      if( cbfU )
[2]527      {
[608]528        m_pcEntropyCoderIf->codeCoeffNxN( pcCU, (pcCU->getCoeffCb()+offsetChroma), uiAbsPartIdx, trWidth, trHeight, uiDepth, TEXT_CHROMA_U );
[2]529      }
[608]530      if( cbfV )
[56]531      {
[608]532        m_pcEntropyCoderIf->codeCoeffNxN( pcCU, (pcCU->getCoeffCr()+offsetChroma), uiAbsPartIdx, trWidth, trHeight, uiDepth, TEXT_CHROMA_V );
[56]533      }
[608]534    }
535    else
536    {
537      UInt partNum = pcCU->getPic()->getNumPartInCU() >> ( ( uiDepth - 1 ) << 1 );
538      if( ( uiAbsPartIdx % partNum ) == (partNum - 1) )
[2]539      {
[56]540        Int trWidth = width;
541        Int trHeight = height;
542        if( cbfU )
[2]543        {
[608]544          m_pcEntropyCoderIf->codeCoeffNxN( pcCU, (pcCU->getCoeffCb()+m_uiBakChromaOffset), m_uiBakAbsPartIdx, trWidth, trHeight, uiDepth, TEXT_CHROMA_U );
[2]545        }
[56]546        if( cbfV )
547        {
[608]548          m_pcEntropyCoderIf->codeCoeffNxN( pcCU, (pcCU->getCoeffCr()+m_uiBakChromaOffset), m_uiBakAbsPartIdx, trWidth, trHeight, uiDepth, TEXT_CHROMA_V );
[56]549        }
[2]550      }
551    }
552  }
553}
554
555// Intra direction for Luma
[608]556Void TEncEntropy::encodeIntraDirModeLuma  ( TComDataCU* pcCU, UInt absPartIdx, Bool isMultiplePU )
[2]557{
[608]558  m_pcEntropyCoderIf->codeIntraDirLumaAng( pcCU, absPartIdx , isMultiplePU);
[2]559}
560
561// Intra direction for Chroma
562Void TEncEntropy::encodeIntraDirModeChroma( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool bRD )
563{
564  if( bRD )
[56]565  {
[2]566    uiAbsPartIdx = 0;
[56]567  }
[2]568 
569  m_pcEntropyCoderIf->codeIntraDirChroma( pcCU, uiAbsPartIdx );
570}
571
[608]572Void TEncEntropy::encodePredInfo( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool bRD )
[2]573{
574  if( bRD )
[56]575  {
[2]576    uiAbsPartIdx = 0;
[56]577  }
[2]578  if( pcCU->isIntra( uiAbsPartIdx ) )                                 // If it is Intra mode, encode intra prediction mode.
579  {
[608]580    encodeIntraDirModeLuma  ( pcCU, uiAbsPartIdx,true );
581#if H_3D_DIM_SDC
[1179]582#if H_3D_DISABLE_CHROMA
583    if(!pcCU->getSDCFlag(uiAbsPartIdx) && ( pcCU->getSlice()->getSPS()->getChromaFormatIdc() != 0  || bRD ) ) 
584#else
[608]585    if(!pcCU->getSDCFlag(uiAbsPartIdx))
[443]586#endif
[1179]587#endif
[608]588    encodeIntraDirModeChroma( pcCU, uiAbsPartIdx, bRD );
[2]589  }
590  else                                                                // if it is Inter mode, encode motion vector and reference index
591  {
[56]592    encodePUWise( pcCU, uiAbsPartIdx, bRD );
[2]593  }
594}
595
596/** encode motion information for every PU block
597 * \param pcCU
598 * \param uiAbsPartIdx
599 * \param bRD
600 * \returns Void
601 */
602Void TEncEntropy::encodePUWise( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool bRD )
603{
604  if ( bRD )
[56]605  {
[2]606    uiAbsPartIdx = 0;
[56]607  }
608 
[2]609  PartSize ePartSize = pcCU->getPartitionSize( uiAbsPartIdx );
610  UInt uiNumPU = ( ePartSize == SIZE_2Nx2N ? 1 : ( ePartSize == SIZE_NxN ? 4 : 2 ) );
611  UInt uiDepth = pcCU->getDepth( uiAbsPartIdx );
612  UInt uiPUOffset = ( g_auiPUOffset[UInt( ePartSize )] << ( ( pcCU->getSlice()->getSPS()->getMaxCUDepth() - uiDepth ) << 1 ) ) >> 4;
613
614  for ( UInt uiPartIdx = 0, uiSubPartIdx = uiAbsPartIdx; uiPartIdx < uiNumPU; uiPartIdx++, uiSubPartIdx += uiPUOffset )
615  {
[608]616#if H_MV_ENC_DEC_TRAC
617    DTRACE_PU_S("=========== prediction_unit ===========\n")
618       //Todo:
619      //DTRACE_PU("x0", uiLPelX)
620      //DTRACE_PU("x1", uiTPelY)
621#endif
622    encodeMergeFlag( pcCU, uiSubPartIdx );
[2]623    if ( pcCU->getMergeFlag( uiSubPartIdx ) )
624    {
[608]625      encodeMergeIndex( pcCU, uiSubPartIdx );
[2]626    }
627    else
628    {
629      encodeInterDirPU( pcCU, uiSubPartIdx );
630      for ( UInt uiRefListIdx = 0; uiRefListIdx < 2; uiRefListIdx++ )
631      {
632        if ( pcCU->getSlice()->getNumRefIdx( RefPicList( uiRefListIdx ) ) > 0 )
633        {
634          encodeRefFrmIdxPU ( pcCU, uiSubPartIdx, RefPicList( uiRefListIdx ) );
635          encodeMvdPU       ( pcCU, uiSubPartIdx, RefPicList( uiRefListIdx ) );
636          encodeMVPIdxPU    ( pcCU, uiSubPartIdx, RefPicList( uiRefListIdx ) );
637        }
638      }
639    }
640  }
641
642  return;
643}
644
645Void TEncEntropy::encodeInterDirPU( TComDataCU* pcCU, UInt uiAbsPartIdx )
646{
647  if ( !pcCU->getSlice()->isInterB() )
648  {
649    return;
650  }
651
652  m_pcEntropyCoderIf->codeInterDir( pcCU, uiAbsPartIdx );
653  return;
654}
655
656/** encode reference frame index for a PU block
657 * \param pcCU
658 * \param uiAbsPartIdx
659 * \param eRefList
660 * \returns Void
661 */
662Void TEncEntropy::encodeRefFrmIdxPU( TComDataCU* pcCU, UInt uiAbsPartIdx, RefPicList eRefList )
663{
664  assert( !pcCU->isIntra( uiAbsPartIdx ) );
665  {
[56]666    if ( ( pcCU->getSlice()->getNumRefIdx( eRefList ) == 1 ) )
667    {
668      return;
669    }
[2]670
[56]671    if ( pcCU->getInterDir( uiAbsPartIdx ) & ( 1 << eRefList ) )
672    {
673      m_pcEntropyCoderIf->codeRefFrmIdx( pcCU, uiAbsPartIdx, eRefList );
674    }
[2]675  }
676
677  return;
678}
679
680/** encode motion vector difference for a PU block
681 * \param pcCU
682 * \param uiAbsPartIdx
683 * \param eRefList
684 * \returns Void
685 */
686Void TEncEntropy::encodeMvdPU( TComDataCU* pcCU, UInt uiAbsPartIdx, RefPicList eRefList )
687{
688  assert( !pcCU->isIntra( uiAbsPartIdx ) );
689
690  if ( pcCU->getInterDir( uiAbsPartIdx ) & ( 1 << eRefList ) )
691  {
692    m_pcEntropyCoderIf->codeMvd( pcCU, uiAbsPartIdx, eRefList );
693  }
694  return;
695}
696
697Void TEncEntropy::encodeMVPIdxPU( TComDataCU* pcCU, UInt uiAbsPartIdx, RefPicList eRefList )
698{
[608]699  if ( (pcCU->getInterDir( uiAbsPartIdx ) & ( 1 << eRefList )) )
[2]700  {
701    m_pcEntropyCoderIf->codeMVPIdx( pcCU, uiAbsPartIdx, eRefList );
702  }
703
704  return;
705}
706
707Void TEncEntropy::encodeQtCbf( TComDataCU* pcCU, UInt uiAbsPartIdx, TextType eType, UInt uiTrDepth )
708{
709  m_pcEntropyCoderIf->codeQtCbf( pcCU, uiAbsPartIdx, eType, uiTrDepth );
710}
711
712Void TEncEntropy::encodeTransformSubdivFlag( UInt uiSymbol, UInt uiCtx )
713{
714  m_pcEntropyCoderIf->codeTransformSubdivFlag( uiSymbol, uiCtx );
715}
716
717Void TEncEntropy::encodeQtRootCbf( TComDataCU* pcCU, UInt uiAbsPartIdx )
718{
719  m_pcEntropyCoderIf->codeQtRootCbf( pcCU, uiAbsPartIdx );
720}
721
[608]722Void TEncEntropy::encodeQtCbfZero( TComDataCU* pcCU, TextType eType, UInt uiTrDepth )
723{
724  m_pcEntropyCoderIf->codeQtCbfZero( pcCU, eType, uiTrDepth );
725}
726Void TEncEntropy::encodeQtRootCbfZero( TComDataCU* pcCU )
727{
728  m_pcEntropyCoderIf->codeQtRootCbfZero( pcCU );
729}
730
[2]731// dQP
732Void TEncEntropy::encodeQP( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool bRD )
733{
734  if( bRD )
[56]735  {
[2]736    uiAbsPartIdx = 0;
[56]737  }
[2]738 
[56]739  if ( pcCU->getSlice()->getPPS()->getUseDQP() )
[2]740  {
741    m_pcEntropyCoderIf->codeDeltaQP( pcCU, uiAbsPartIdx );
742  }
743}
744
745
746// texture
747/** encode coefficients
748 * \param pcCU
749 * \param uiAbsPartIdx
750 * \param uiDepth
751 * \param uiWidth
752 * \param uiHeight
753 */
[1179]754#if H_3D_DISABLE_CHROMA
755Void TEncEntropy::encodeCoeff( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, UInt uiWidth, UInt uiHeight, Bool& bCodeDQP, Bool rd )
756#else
[56]757Void TEncEntropy::encodeCoeff( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, UInt uiWidth, UInt uiHeight, Bool& bCodeDQP )
[1179]758#endif
[2]759{
760  UInt uiMinCoeffSize = pcCU->getPic()->getMinCUWidth()*pcCU->getPic()->getMinCUHeight();
761  UInt uiLumaOffset   = uiMinCoeffSize*uiAbsPartIdx;
762  UInt uiChromaOffset = uiLumaOffset>>2;
[833]763#if H_3D_DIM_SDC
764  if( pcCU->getSDCFlag( uiAbsPartIdx ) && pcCU->isIntra( uiAbsPartIdx ) )
765  {
766    assert( pcCU->getPartitionSize(uiAbsPartIdx) == SIZE_2Nx2N );
767    assert( pcCU->getTransformIdx(uiAbsPartIdx) == 0 );
768    assert( pcCU->getCbf(uiAbsPartIdx, TEXT_LUMA) == 1 );
[1179]769#if H_3D_DISABLE_CHROMA
770    if (!pcCU->getSlice()->getIsDepth() )
771    {
772      assert( pcCU->getCbf(uiAbsPartIdx, TEXT_CHROMA_U) == 1 );
773      assert( pcCU->getCbf(uiAbsPartIdx, TEXT_CHROMA_V) == 1 );
774    }
775#else
[833]776    assert( pcCU->getCbf(uiAbsPartIdx, TEXT_CHROMA_U) == 1 );
777    assert( pcCU->getCbf(uiAbsPartIdx, TEXT_CHROMA_V) == 1 );
[1179]778#endif
[833]779  }
780
[1179]781
[833]782  if( pcCU->getSDCFlag( uiAbsPartIdx ) && !pcCU->isIntra( uiAbsPartIdx ) )
783  {
784    assert( !pcCU->isSkipped( uiAbsPartIdx ) );
785    assert( !pcCU->isIntra( uiAbsPartIdx) );
786    assert( pcCU->getSlice()->getIsDepth() );
787  }
[884]788
[833]789  if( pcCU->getSlice()->getIsDepth() && ( pcCU->getSDCFlag( uiAbsPartIdx ) || pcCU->isIntra( uiAbsPartIdx ) ) )
790  {
791    Int iPartNum = ( pcCU->isIntra( uiAbsPartIdx ) && pcCU->getPartitionSize( uiAbsPartIdx ) == SIZE_NxN ) ? 4 : 1;
792    UInt uiPartOffset = ( pcCU->getPic()->getNumPartInCU() >> ( pcCU->getDepth( uiAbsPartIdx ) << 1 ) ) >> 2;
[608]793   
[833]794    if( !pcCU->getSDCFlag( uiAbsPartIdx ) )
795    {
796      for( Int iPart = 0; iPart < iPartNum; iPart++ )
797      {
798        if( getDimType( pcCU->getLumaIntraDir( uiAbsPartIdx + uiPartOffset*iPart ) ) < DIM_NUM_TYPE ) 
799        {
800          m_pcEntropyCoderIf->codeDeltaDC( pcCU, uiAbsPartIdx + uiPartOffset*iPart );
801        }
802      }
803    }
804    else
805    {
806      m_pcEntropyCoderIf->codeDeltaDC( pcCU, uiAbsPartIdx );
807      return;
808    }
809  }
[443]810#endif
[608]811
[2]812  if( pcCU->isIntra(uiAbsPartIdx) )
813  {
[608]814#if !H_MV
[56]815    DTRACE_CABAC_VL( g_nSymbolCounter++ )
[2]816    DTRACE_CABAC_T( "\tdecodeTransformIdx()\tCUDepth=" )
817    DTRACE_CABAC_V( uiDepth )
818    DTRACE_CABAC_T( "\n" )
[608]819#endif
[2]820  }
821  else
822  {
[608]823    if( !(pcCU->getMergeFlag( uiAbsPartIdx ) && pcCU->getPartitionSize(uiAbsPartIdx) == SIZE_2Nx2N ) )
[2]824    {
[608]825      m_pcEntropyCoderIf->codeQtRootCbf( pcCU, uiAbsPartIdx );
[2]826    }
[608]827    if ( !pcCU->getQtRootCbf( uiAbsPartIdx ) )
[189]828    {
[608]829      return;
[189]830    }
831  }
[608]832 
[1179]833#if H_3D_DISABLE_CHROMA
834  xEncodeTransform( pcCU, uiLumaOffset, uiChromaOffset, uiAbsPartIdx, uiDepth, uiWidth, uiHeight, 0, bCodeDQP, rd);
835#else
[608]836  xEncodeTransform( pcCU, uiLumaOffset, uiChromaOffset, uiAbsPartIdx, uiDepth, uiWidth, uiHeight, 0, bCodeDQP);
[1179]837#endif
[2]838}
839
[56]840Void TEncEntropy::encodeCoeffNxN( TComDataCU* pcCU, TCoeff* pcCoeff, UInt uiAbsPartIdx, UInt uiTrWidth, UInt uiTrHeight, UInt uiDepth, TextType eType )
[608]841{
842  // This is for Transform unit processing. This may be used at mode selection stage for Inter.
[56]843  m_pcEntropyCoderIf->codeCoeffNxN( pcCU, pcCoeff, uiAbsPartIdx, uiTrWidth, uiTrHeight, uiDepth, eType );
[2]844}
845
[56]846Void TEncEntropy::estimateBit (estBitsSbacStruct* pcEstBitsSbac, Int width, Int height, TextType eTType)
847{ 
848  eTType = eTType == TEXT_LUMA ? TEXT_LUMA : TEXT_CHROMA;
849 
850  m_pcEntropyCoderIf->estBit ( pcEstBitsSbac, width, height, eTType );
851}
852
853Int TEncEntropy::countNonZeroCoeffs( TCoeff* pcCoef, UInt uiSize )
854{
855  Int count = 0;
856 
857  for ( Int i = 0; i < uiSize; i++ )
[2]858  {
[56]859    count += pcCoef[i] != 0;
[2]860  }
[56]861 
862  return count;
863}
[2]864
[56]865/** encode quantization matrix
866 * \param scalingList quantization matrix information
867 */
868Void TEncEntropy::encodeScalingList( TComScalingList* scalingList )
869{
870  m_pcEntropyCoderIf->codeScalingList( scalingList );
[2]871}
872
[655]873#if H_3D_INTER_SDC
[833]874Void TEncEntropy::encodeDeltaDC  ( TComDataCU* pcCU, UInt absPartIdx )
875{
876  m_pcEntropyCoderIf->codeDeltaDC( pcCU, absPartIdx );
877}
878
879Void TEncEntropy::encodeSDCFlag( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool bRD )
880{
[1124]881  if( ( !pcCU->isIntra( uiAbsPartIdx ) && !pcCU->getSlice()->getInterSdcFlag() ) || 
882    ( pcCU->isIntra( uiAbsPartIdx ) && !pcCU->getSlice()->getIntraSdcWedgeFlag() ) )
[833]883  {
884    return;
885  }
886
887  if( !pcCU->getSlice()->getIsDepth() || pcCU->getPartitionSize( uiAbsPartIdx ) != SIZE_2Nx2N || pcCU->isSkipped( uiAbsPartIdx ) )
888  {
889    return;
890  }
891
892  assert( pcCU->getPartitionSize( uiAbsPartIdx ) == SIZE_2Nx2N || ( !pcCU->isIntra( uiAbsPartIdx ) && !pcCU->isSkipped( uiAbsPartIdx ) ) );
893
894  if( bRD )
895  {
896    uiAbsPartIdx = 0;
897  }
898
899  m_pcEntropyCoderIf->codeSDCFlag( pcCU, uiAbsPartIdx );
900}
[2]901
[189]902#endif
[833]903#if H_3D_DBBP
904Void TEncEntropy::encodeDBBPFlag( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool bRD )
905{
[1179]906#if HHI_MOVE_SYN_K0052
907  if( pcCU->getSlice()->getDepthBasedBlkPartFlag() && 
908    ( pcCU->getPartitionSize(uiAbsPartIdx) == SIZE_2NxN || 
909      pcCU->getPartitionSize(uiAbsPartIdx) == SIZE_Nx2N) && 
910      pcCU->getWidth(uiAbsPartIdx) > 8 && 
911      pcCU->getSlice()->getDefaultRefViewIdxAvailableFlag() )
[833]912  {
[1179]913#endif
914    if( bRD )
915    {
916      uiAbsPartIdx = 0;
917    }
918    m_pcEntropyCoderIf->codeDBBPFlag( pcCU, uiAbsPartIdx );
919#if HHI_MOVE_SYN_K0052
[833]920  }
[1179]921#endif
[833]922}
923#endif
[56]924//! \}
Note: See TracBrowser for help on using the repository browser.