source: 3DVCSoftware/branches/HTM-13.1-dev0/source/Lib/TLibEncoder/TEncEntropy.cpp @ 1175

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

Added direct dependency type for qtl.
Updated cfg files.
updated copy right headers.

  • Property svn:eol-style set to native
File size: 25.2 KB
Line 
1/* The copyright in this software is being made available under the BSD
2 * License, included below. This software may be subject to other third party
3 * and contributor rights, including patent rights, and no such rights are
4 * granted under this license. 
5 *
6* Copyright (c) 2010-2015, ITU/ISO/IEC
7 * All rights reserved.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions are met:
11 *
12 *  * Redistributions of source code must retain the above copyright notice,
13 *    this list of conditions and the following disclaimer.
14 *  * Redistributions in binary form must reproduce the above copyright notice,
15 *    this list of conditions and the following disclaimer in the documentation
16 *    and/or other materials provided with the distribution.
17 *  * Neither the name of the ITU/ISO/IEC nor the names of its contributors may
18 *    be used to endorse or promote products derived from this software without
19 *    specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS
25 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
31 * THE POSSIBILITY OF SUCH DAMAGE.
32 */
33
34/** \file     TEncEntropy.cpp
35    \brief    entropy encoder class
36*/
37
38#include "TEncEntropy.h"
39#include "TLibCommon/TypeDef.h"
40#include "TLibCommon/TComSampleAdaptiveOffset.h"
41
42//! \ingroup TLibEncoder
43//! \{
44
45Void TEncEntropy::setEntropyCoder ( TEncEntropyIf* e, TComSlice* pcSlice )
46{
47  m_pcEntropyCoderIf = e;
48  m_pcEntropyCoderIf->setSlice ( pcSlice );
49}
50
51Void TEncEntropy::encodeSliceHeader ( TComSlice* pcSlice )
52{
53  m_pcEntropyCoderIf->codeSliceHeader( pcSlice );
54  return;
55}
56
57Void  TEncEntropy::encodeTilesWPPEntryPoint( TComSlice* pSlice )
58{
59  m_pcEntropyCoderIf->codeTilesWPPEntryPoint( pSlice );
60}
61
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
80Void TEncEntropy::encodeSPS( TComSPS* pcSPS )
81{
82  m_pcEntropyCoderIf->codeSPS( pcSPS );
83  return;
84}
85
86Void TEncEntropy::encodeCUTransquantBypassFlag( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool bRD )
87{
88  if( bRD )
89  {
90    uiAbsPartIdx = 0;
91  }
92  m_pcEntropyCoderIf->codeCUTransquantBypassFlag( pcCU, uiAbsPartIdx );
93}
94
95Void TEncEntropy::encodeVPS( TComVPS* pcVPS )
96{
97  m_pcEntropyCoderIf->codeVPS( pcVPS );
98  return;
99}
100
101Void TEncEntropy::encodeSkipFlag( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool bRD )
102{
103  if ( pcCU->getSlice()->isIntra() )
104  {
105    return;
106  }
107  if( bRD )
108  {
109    uiAbsPartIdx = 0;
110  }
111  m_pcEntropyCoderIf->codeSkipFlag( pcCU, uiAbsPartIdx );
112}
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
128#if H_3D_SINGLE_DEPTH
129Void TEncEntropy::encodeSingleDepthMode( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool bRD )
130{
131  if(!pcCU->getSlice()->getIntraSingleFlag() )
132  {
133    return;
134  }
135  if( bRD )
136  {
137    uiAbsPartIdx = 0;
138  }
139  m_pcEntropyCoderIf->codeSingleDepthMode( pcCU, uiAbsPartIdx );
140}
141#endif
142#endif
143
144/** encode merge flag
145 * \param pcCU
146 * \param uiAbsPartIdx
147 * \returns Void
148 */
149Void TEncEntropy::encodeMergeFlag( TComDataCU* pcCU, UInt uiAbsPartIdx )
150{ 
151  // at least one merge candidate exists
152  m_pcEntropyCoderIf->codeMergeFlag( pcCU, uiAbsPartIdx );
153}
154
155/** encode merge index
156 * \param pcCU
157 * \param uiAbsPartIdx
158 * \param uiPUIdx
159 * \param bRD
160 * \returns Void
161 */
162Void TEncEntropy::encodeMergeIndex( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool bRD )
163{
164  if( bRD )
165  {
166    uiAbsPartIdx = 0;
167    assert( pcCU->getPartitionSize(uiAbsPartIdx) == SIZE_2Nx2N );
168  }
169  m_pcEntropyCoderIf->codeMergeIndex( pcCU, uiAbsPartIdx );
170}
171
172#if H_3D_IC
173Void TEncEntropy::encodeICFlag( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool bRD )
174{
175  if ( pcCU->isIntra( uiAbsPartIdx ) || ( pcCU->getSlice()->getViewIndex() == 0 ) || pcCU->getSlice()->getIsDepth() || pcCU->getARPW( uiAbsPartIdx ) > 0 )
176  {
177    return;
178  }
179
180  if( !pcCU->getSlice()->getApplyIC() )
181  {
182    return;
183  }
184
185  if( bRD )
186  {
187    uiAbsPartIdx = 0;
188  }
189  else
190  {
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);
200  }
201  if( pcCU->isICFlagRequired( uiAbsPartIdx ) )
202  {
203    m_pcEntropyCoderIf->codeICFlag( pcCU, uiAbsPartIdx );
204  }
205}
206#endif
207
208#if H_3D_ARP
209Void TEncEntropy::encodeARPW( TComDataCU* pcCU, UInt uiAbsPartIdx )
210{
211  if( !pcCU->getSlice()->getARPStepNum() || pcCU->isIntra( uiAbsPartIdx ) ) 
212  {
213    return;
214  }
215
216  if ( pcCU->getPartitionSize(uiAbsPartIdx)!=SIZE_2Nx2N )
217  {
218    assert(pcCU->getARPW (uiAbsPartIdx) == 0);
219  }
220  else
221  {
222    m_pcEntropyCoderIf->codeARPW( pcCU, uiAbsPartIdx );
223  }
224}
225#endif
226
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 )
236  {
237    uiAbsPartIdx = 0;
238  }
239  if ( pcCU->getSlice()->isIntra() )
240  {
241    return;
242  }
243
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 )
251  {
252    uiAbsPartIdx = 0;
253  }
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 )
267  {
268    uiAbsPartIdx = 0;
269  }
270 
271  m_pcEntropyCoderIf->codePartSize( pcCU, uiAbsPartIdx, uiDepth );
272 
273#if !HHI_MOVE_SYN_K0052
274#if H_3D_DBBP
275  if( pcCU->getSlice()->getDepthBasedBlkPartFlag() && (pcCU->getPartitionSize(uiAbsPartIdx) == SIZE_2NxN || pcCU->getPartitionSize(uiAbsPartIdx) == SIZE_Nx2N) && pcCU->getWidth(uiAbsPartIdx) > 8 && pcCU->getSlice()->getDefaultRefViewIdxAvailableFlag() )
276  {
277    encodeDBBPFlag(pcCU, uiAbsPartIdx, bRD);
278  }
279#endif
280#endif
281}
282
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 )
290{
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  }
297 
298  if( bRD )
299  {
300    uiAbsPartIdx = 0;
301  }
302 
303  m_pcEntropyCoderIf->codeIPCMInfo ( pcCU, uiAbsPartIdx );
304}
305
306Void TEncEntropy::xEncodeTransform( TComDataCU* pcCU,UInt offsetLuma, UInt offsetChroma, UInt uiAbsPartIdx, UInt uiDepth, UInt width, UInt height, UInt uiTrIdx, Bool& bCodeDQP )
307{
308
309#if H_MV_ENC_DEC_TRAC
310#if ENC_DEC_TRACE
311  UInt uiLPelX   = pcCU->getCUPelX() + g_auiRasterToPelX[ g_auiZscanToRaster[uiAbsPartIdx] ];
312  UInt uiTPelY   = pcCU->getCUPelY() + g_auiRasterToPelY[ g_auiZscanToRaster[uiAbsPartIdx] ];
313
314  DTRACE_TU_S("=========== transform_tree ===========\n")
315  DTRACE_TU("x0", uiLPelX)
316  DTRACE_TU("x1", uiTPelY)
317  DTRACE_TU("log2TrafoSize", g_uiMaxCUWidth>>uiDepth)
318  DTRACE_TU("trafoDepth"  , uiDepth)
319#endif
320#endif
321
322  const UInt uiSubdiv = pcCU->getTransformIdx( uiAbsPartIdx ) + pcCU->getDepth( uiAbsPartIdx ) > uiDepth;
323  const UInt uiLog2TrafoSize = g_aucConvertToBit[pcCU->getSlice()->getSPS()->getMaxCUWidth()]+2 - uiDepth;
324  UInt cbfY = pcCU->getCbf( uiAbsPartIdx, TEXT_LUMA    , uiTrIdx );
325  UInt cbfU = pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_U, uiTrIdx );
326  UInt cbfV = pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_V, uiTrIdx );
327
328  if(uiTrIdx==0)
329  {
330    m_bakAbsPartIdxCU = uiAbsPartIdx;
331  }
332  if( uiLog2TrafoSize == 2 )
333  {
334    UInt partNum = pcCU->getPic()->getNumPartInCU() >> ( ( uiDepth - 1 ) << 1 );
335    if( ( uiAbsPartIdx % partNum ) == 0 )
336    {
337      m_uiBakAbsPartIdx   = uiAbsPartIdx;
338      m_uiBakChromaOffset = offsetChroma;
339    }
340    else if( ( uiAbsPartIdx % partNum ) == (partNum - 1) )
341    {
342      cbfU = pcCU->getCbf( m_uiBakAbsPartIdx, TEXT_CHROMA_U, uiTrIdx );
343      cbfV = pcCU->getCbf( m_uiBakAbsPartIdx, TEXT_CHROMA_V, uiTrIdx );
344    }
345  }
346 
347  if( pcCU->getPredictionMode(uiAbsPartIdx) == MODE_INTRA && pcCU->getPartitionSize(uiAbsPartIdx) == SIZE_NxN && uiDepth == pcCU->getDepth(uiAbsPartIdx) )
348  {
349    assert( uiSubdiv );
350  }
351  else if( pcCU->getPredictionMode(uiAbsPartIdx) == MODE_INTER && (pcCU->getPartitionSize(uiAbsPartIdx) != SIZE_2Nx2N) && uiDepth == pcCU->getDepth(uiAbsPartIdx) &&  (pcCU->getSlice()->getSPS()->getQuadtreeTUMaxDepthInter() == 1) )
352  {
353    if ( uiLog2TrafoSize > pcCU->getQuadtreeTULog2MinSizeInCU(uiAbsPartIdx) )
354    {
355      assert( uiSubdiv );
356    }
357    else
358    {
359      assert(!uiSubdiv );
360    }
361  }
362  else if( uiLog2TrafoSize > pcCU->getSlice()->getSPS()->getQuadtreeTULog2MaxSize() )
363  {
364    assert( uiSubdiv );
365  }
366  else if( uiLog2TrafoSize == pcCU->getSlice()->getSPS()->getQuadtreeTULog2MinSize() )
367  {
368    assert( !uiSubdiv );
369  }
370  else if( uiLog2TrafoSize == pcCU->getQuadtreeTULog2MinSizeInCU(uiAbsPartIdx) )
371  {
372    assert( !uiSubdiv );
373  }
374  else
375  {
376    assert( uiLog2TrafoSize > pcCU->getQuadtreeTULog2MinSizeInCU(uiAbsPartIdx) );
377    m_pcEntropyCoderIf->codeTransformSubdivFlag( uiSubdiv, 5 - uiLog2TrafoSize );
378  }
379
380  const UInt uiTrDepthCurr = uiDepth - pcCU->getDepth( uiAbsPartIdx );
381  const Bool bFirstCbfOfCU = uiTrDepthCurr == 0;
382  if( bFirstCbfOfCU || uiLog2TrafoSize > 2 )
383  {
384#if H_3D_DISABLE_CHROMA
385    if (!pcCU->getSlice()->getIsDepth() )
386    {
387      if( bFirstCbfOfCU || pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_U, uiTrDepthCurr - 1 ) )
388      {
389        m_pcEntropyCoderIf->codeQtCbf( pcCU, uiAbsPartIdx, TEXT_CHROMA_U, uiTrDepthCurr );
390      }
391      if( bFirstCbfOfCU || pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_V, uiTrDepthCurr - 1 ) )
392      {
393        m_pcEntropyCoderIf->codeQtCbf( pcCU, uiAbsPartIdx, TEXT_CHROMA_V, uiTrDepthCurr );
394      }
395    }
396    else
397    {
398      if( bFirstCbfOfCU || pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_U, uiTrDepthCurr - 1 ) )
399      {
400        assert( pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_U, uiTrDepthCurr ) == 0 );
401      }
402      if( bFirstCbfOfCU || pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_V, uiTrDepthCurr - 1 ) )
403      {
404        assert( pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_V, uiTrDepthCurr ) == 0  );
405      }
406    }
407#else
408    if( bFirstCbfOfCU || pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_U, uiTrDepthCurr - 1 ) )
409    {
410      m_pcEntropyCoderIf->codeQtCbf( pcCU, uiAbsPartIdx, TEXT_CHROMA_U, uiTrDepthCurr );
411    }
412    if( bFirstCbfOfCU || pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_V, uiTrDepthCurr - 1 ) )
413    {
414      m_pcEntropyCoderIf->codeQtCbf( pcCU, uiAbsPartIdx, TEXT_CHROMA_V, uiTrDepthCurr );
415    }
416#endif
417  }
418  else if( uiLog2TrafoSize == 2 )
419  {
420    assert( pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_U, uiTrDepthCurr ) == pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_U, uiTrDepthCurr - 1 ) );
421    assert( pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_V, uiTrDepthCurr ) == pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_V, uiTrDepthCurr - 1 ) );
422  }
423 
424  if( uiSubdiv )
425  {
426    UInt size;
427    width  >>= 1;
428    height >>= 1;
429    size = width*height;
430    uiTrIdx++;
431    ++uiDepth;
432    const UInt partNum = pcCU->getPic()->getNumPartInCU() >> (uiDepth << 1);
433   
434    xEncodeTransform( pcCU, offsetLuma, offsetChroma, uiAbsPartIdx, uiDepth, width, height, uiTrIdx, bCodeDQP );
435
436    uiAbsPartIdx += partNum;  offsetLuma += size;  offsetChroma += (size>>2);
437    xEncodeTransform( pcCU, offsetLuma, offsetChroma, uiAbsPartIdx, uiDepth, width, height, uiTrIdx, bCodeDQP );
438
439    uiAbsPartIdx += partNum;  offsetLuma += size;  offsetChroma += (size>>2);
440    xEncodeTransform( pcCU, offsetLuma, offsetChroma, uiAbsPartIdx, uiDepth, width, height, uiTrIdx, bCodeDQP );
441
442    uiAbsPartIdx += partNum;  offsetLuma += size;  offsetChroma += (size>>2);
443    xEncodeTransform( pcCU, offsetLuma, offsetChroma, uiAbsPartIdx, uiDepth, width, height, uiTrIdx, bCodeDQP );
444  }
445  else
446  {
447#if !H_MV_ENC_DEC_TRAC
448    {
449      DTRACE_CABAC_VL( g_nSymbolCounter++ );
450      DTRACE_CABAC_T( "\tTrIdx: abspart=" );
451      DTRACE_CABAC_V( uiAbsPartIdx );
452      DTRACE_CABAC_T( "\tdepth=" );
453      DTRACE_CABAC_V( uiDepth );
454      DTRACE_CABAC_T( "\ttrdepth=" );
455      DTRACE_CABAC_V( pcCU->getTransformIdx( uiAbsPartIdx ) );
456      DTRACE_CABAC_T( "\n" );
457    }
458#endif
459   
460    if( pcCU->getPredictionMode(uiAbsPartIdx) != MODE_INTRA && uiDepth == pcCU->getDepth( uiAbsPartIdx ) && !pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_U, 0 ) && !pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_V, 0 ) )
461    {
462      assert( pcCU->getCbf( uiAbsPartIdx, TEXT_LUMA, 0 ) );
463      //      printf( "saved one bin! " );
464    }
465    else
466    {
467      m_pcEntropyCoderIf->codeQtCbf( pcCU, uiAbsPartIdx, TEXT_LUMA, pcCU->getTransformIdx( uiAbsPartIdx ) );
468    }
469
470
471    if ( cbfY || cbfU || cbfV )
472    {
473      // dQP: only for LCU once
474      if ( pcCU->getSlice()->getPPS()->getUseDQP() )
475      {
476        if ( bCodeDQP )
477        {
478          encodeQP( pcCU, m_bakAbsPartIdxCU );
479          bCodeDQP = false;
480        }
481      }
482    }
483    if( cbfY )
484    {
485      Int trWidth = width;
486      Int trHeight = height;
487      m_pcEntropyCoderIf->codeCoeffNxN( pcCU, (pcCU->getCoeffY()+offsetLuma), uiAbsPartIdx, trWidth, trHeight, uiDepth, TEXT_LUMA );
488    }
489    if( uiLog2TrafoSize > 2 )
490    {
491      Int trWidth = width >> 1;
492      Int trHeight = height >> 1;
493      if( cbfU )
494      {
495        m_pcEntropyCoderIf->codeCoeffNxN( pcCU, (pcCU->getCoeffCb()+offsetChroma), uiAbsPartIdx, trWidth, trHeight, uiDepth, TEXT_CHROMA_U );
496      }
497      if( cbfV )
498      {
499        m_pcEntropyCoderIf->codeCoeffNxN( pcCU, (pcCU->getCoeffCr()+offsetChroma), uiAbsPartIdx, trWidth, trHeight, uiDepth, TEXT_CHROMA_V );
500      }
501    }
502    else
503    {
504      UInt partNum = pcCU->getPic()->getNumPartInCU() >> ( ( uiDepth - 1 ) << 1 );
505      if( ( uiAbsPartIdx % partNum ) == (partNum - 1) )
506      {
507        Int trWidth = width;
508        Int trHeight = height;
509        if( cbfU )
510        {
511          m_pcEntropyCoderIf->codeCoeffNxN( pcCU, (pcCU->getCoeffCb()+m_uiBakChromaOffset), m_uiBakAbsPartIdx, trWidth, trHeight, uiDepth, TEXT_CHROMA_U );
512        }
513        if( cbfV )
514        {
515          m_pcEntropyCoderIf->codeCoeffNxN( pcCU, (pcCU->getCoeffCr()+m_uiBakChromaOffset), m_uiBakAbsPartIdx, trWidth, trHeight, uiDepth, TEXT_CHROMA_V );
516        }
517      }
518    }
519  }
520}
521
522// Intra direction for Luma
523Void TEncEntropy::encodeIntraDirModeLuma  ( TComDataCU* pcCU, UInt absPartIdx, Bool isMultiplePU )
524{
525  m_pcEntropyCoderIf->codeIntraDirLumaAng( pcCU, absPartIdx , isMultiplePU);
526}
527
528// Intra direction for Chroma
529Void TEncEntropy::encodeIntraDirModeChroma( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool bRD )
530{
531  if( bRD )
532  {
533    uiAbsPartIdx = 0;
534  }
535 
536  m_pcEntropyCoderIf->codeIntraDirChroma( pcCU, uiAbsPartIdx );
537}
538
539Void TEncEntropy::encodePredInfo( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool bRD )
540{
541  if( bRD )
542  {
543    uiAbsPartIdx = 0;
544  }
545  if( pcCU->isIntra( uiAbsPartIdx ) )                                 // If it is Intra mode, encode intra prediction mode.
546  {
547    encodeIntraDirModeLuma  ( pcCU, uiAbsPartIdx,true );
548#if H_3D_DIM_SDC
549#if H_3D_DISABLE_CHROMA
550    if(!pcCU->getSDCFlag(uiAbsPartIdx) && !pcCU->getSlice()->getIsDepth() )
551#else
552    if(!pcCU->getSDCFlag(uiAbsPartIdx))
553#endif
554#endif
555    encodeIntraDirModeChroma( pcCU, uiAbsPartIdx, bRD );
556  }
557  else                                                                // if it is Inter mode, encode motion vector and reference index
558  {
559    encodePUWise( pcCU, uiAbsPartIdx, bRD );
560  }
561}
562
563/** encode motion information for every PU block
564 * \param pcCU
565 * \param uiAbsPartIdx
566 * \param bRD
567 * \returns Void
568 */
569Void TEncEntropy::encodePUWise( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool bRD )
570{
571  if ( bRD )
572  {
573    uiAbsPartIdx = 0;
574  }
575 
576  PartSize ePartSize = pcCU->getPartitionSize( uiAbsPartIdx );
577  UInt uiNumPU = ( ePartSize == SIZE_2Nx2N ? 1 : ( ePartSize == SIZE_NxN ? 4 : 2 ) );
578  UInt uiDepth = pcCU->getDepth( uiAbsPartIdx );
579  UInt uiPUOffset = ( g_auiPUOffset[UInt( ePartSize )] << ( ( pcCU->getSlice()->getSPS()->getMaxCUDepth() - uiDepth ) << 1 ) ) >> 4;
580
581  for ( UInt uiPartIdx = 0, uiSubPartIdx = uiAbsPartIdx; uiPartIdx < uiNumPU; uiPartIdx++, uiSubPartIdx += uiPUOffset )
582  {
583#if H_MV_ENC_DEC_TRAC
584    DTRACE_PU_S("=========== prediction_unit ===========\n")
585       //Todo:
586      //DTRACE_PU("x0", uiLPelX)
587      //DTRACE_PU("x1", uiTPelY)
588#endif
589    encodeMergeFlag( pcCU, uiSubPartIdx );
590    if ( pcCU->getMergeFlag( uiSubPartIdx ) )
591    {
592      encodeMergeIndex( pcCU, uiSubPartIdx );
593    }
594    else
595    {
596      encodeInterDirPU( pcCU, uiSubPartIdx );
597      for ( UInt uiRefListIdx = 0; uiRefListIdx < 2; uiRefListIdx++ )
598      {
599        if ( pcCU->getSlice()->getNumRefIdx( RefPicList( uiRefListIdx ) ) > 0 )
600        {
601          encodeRefFrmIdxPU ( pcCU, uiSubPartIdx, RefPicList( uiRefListIdx ) );
602          encodeMvdPU       ( pcCU, uiSubPartIdx, RefPicList( uiRefListIdx ) );
603          encodeMVPIdxPU    ( pcCU, uiSubPartIdx, RefPicList( uiRefListIdx ) );
604        }
605      }
606    }
607  }
608
609  return;
610}
611
612Void TEncEntropy::encodeInterDirPU( TComDataCU* pcCU, UInt uiAbsPartIdx )
613{
614  if ( !pcCU->getSlice()->isInterB() )
615  {
616    return;
617  }
618
619  m_pcEntropyCoderIf->codeInterDir( pcCU, uiAbsPartIdx );
620  return;
621}
622
623/** encode reference frame index for a PU block
624 * \param pcCU
625 * \param uiAbsPartIdx
626 * \param eRefList
627 * \returns Void
628 */
629Void TEncEntropy::encodeRefFrmIdxPU( TComDataCU* pcCU, UInt uiAbsPartIdx, RefPicList eRefList )
630{
631  assert( !pcCU->isIntra( uiAbsPartIdx ) );
632  {
633    if ( ( pcCU->getSlice()->getNumRefIdx( eRefList ) == 1 ) )
634    {
635      return;
636    }
637
638    if ( pcCU->getInterDir( uiAbsPartIdx ) & ( 1 << eRefList ) )
639    {
640      m_pcEntropyCoderIf->codeRefFrmIdx( pcCU, uiAbsPartIdx, eRefList );
641    }
642  }
643
644  return;
645}
646
647/** encode motion vector difference for a PU block
648 * \param pcCU
649 * \param uiAbsPartIdx
650 * \param eRefList
651 * \returns Void
652 */
653Void TEncEntropy::encodeMvdPU( TComDataCU* pcCU, UInt uiAbsPartIdx, RefPicList eRefList )
654{
655  assert( !pcCU->isIntra( uiAbsPartIdx ) );
656
657  if ( pcCU->getInterDir( uiAbsPartIdx ) & ( 1 << eRefList ) )
658  {
659    m_pcEntropyCoderIf->codeMvd( pcCU, uiAbsPartIdx, eRefList );
660  }
661  return;
662}
663
664Void TEncEntropy::encodeMVPIdxPU( TComDataCU* pcCU, UInt uiAbsPartIdx, RefPicList eRefList )
665{
666  if ( (pcCU->getInterDir( uiAbsPartIdx ) & ( 1 << eRefList )) )
667  {
668    m_pcEntropyCoderIf->codeMVPIdx( pcCU, uiAbsPartIdx, eRefList );
669  }
670
671  return;
672}
673
674Void TEncEntropy::encodeQtCbf( TComDataCU* pcCU, UInt uiAbsPartIdx, TextType eType, UInt uiTrDepth )
675{
676  m_pcEntropyCoderIf->codeQtCbf( pcCU, uiAbsPartIdx, eType, uiTrDepth );
677}
678
679Void TEncEntropy::encodeTransformSubdivFlag( UInt uiSymbol, UInt uiCtx )
680{
681  m_pcEntropyCoderIf->codeTransformSubdivFlag( uiSymbol, uiCtx );
682}
683
684Void TEncEntropy::encodeQtRootCbf( TComDataCU* pcCU, UInt uiAbsPartIdx )
685{
686  m_pcEntropyCoderIf->codeQtRootCbf( pcCU, uiAbsPartIdx );
687}
688
689Void TEncEntropy::encodeQtCbfZero( TComDataCU* pcCU, TextType eType, UInt uiTrDepth )
690{
691  m_pcEntropyCoderIf->codeQtCbfZero( pcCU, eType, uiTrDepth );
692}
693Void TEncEntropy::encodeQtRootCbfZero( TComDataCU* pcCU )
694{
695  m_pcEntropyCoderIf->codeQtRootCbfZero( pcCU );
696}
697
698// dQP
699Void TEncEntropy::encodeQP( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool bRD )
700{
701  if( bRD )
702  {
703    uiAbsPartIdx = 0;
704  }
705 
706  if ( pcCU->getSlice()->getPPS()->getUseDQP() )
707  {
708    m_pcEntropyCoderIf->codeDeltaQP( pcCU, uiAbsPartIdx );
709  }
710}
711
712
713// texture
714/** encode coefficients
715 * \param pcCU
716 * \param uiAbsPartIdx
717 * \param uiDepth
718 * \param uiWidth
719 * \param uiHeight
720 */
721Void TEncEntropy::encodeCoeff( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, UInt uiWidth, UInt uiHeight, Bool& bCodeDQP )
722{
723  UInt uiMinCoeffSize = pcCU->getPic()->getMinCUWidth()*pcCU->getPic()->getMinCUHeight();
724  UInt uiLumaOffset   = uiMinCoeffSize*uiAbsPartIdx;
725  UInt uiChromaOffset = uiLumaOffset>>2;
726#if H_3D_DIM_SDC
727  if( pcCU->getSDCFlag( uiAbsPartIdx ) && pcCU->isIntra( uiAbsPartIdx ) )
728  {
729    assert( pcCU->getPartitionSize(uiAbsPartIdx) == SIZE_2Nx2N );
730    assert( pcCU->getTransformIdx(uiAbsPartIdx) == 0 );
731    assert( pcCU->getCbf(uiAbsPartIdx, TEXT_LUMA) == 1 );
732#if H_3D_DISABLE_CHROMA
733    if (!pcCU->getSlice()->getIsDepth() )
734    {
735      assert( pcCU->getCbf(uiAbsPartIdx, TEXT_CHROMA_U) == 1 );
736      assert( pcCU->getCbf(uiAbsPartIdx, TEXT_CHROMA_V) == 1 );
737    }
738#else
739    assert( pcCU->getCbf(uiAbsPartIdx, TEXT_CHROMA_U) == 1 );
740    assert( pcCU->getCbf(uiAbsPartIdx, TEXT_CHROMA_V) == 1 );
741#endif
742  }
743
744
745  if( pcCU->getSDCFlag( uiAbsPartIdx ) && !pcCU->isIntra( uiAbsPartIdx ) )
746  {
747    assert( !pcCU->isSkipped( uiAbsPartIdx ) );
748    assert( !pcCU->isIntra( uiAbsPartIdx) );
749    assert( pcCU->getSlice()->getIsDepth() );
750  }
751
752  if( pcCU->getSlice()->getIsDepth() && ( pcCU->getSDCFlag( uiAbsPartIdx ) || pcCU->isIntra( uiAbsPartIdx ) ) )
753  {
754    Int iPartNum = ( pcCU->isIntra( uiAbsPartIdx ) && pcCU->getPartitionSize( uiAbsPartIdx ) == SIZE_NxN ) ? 4 : 1;
755    UInt uiPartOffset = ( pcCU->getPic()->getNumPartInCU() >> ( pcCU->getDepth( uiAbsPartIdx ) << 1 ) ) >> 2;
756   
757    if( !pcCU->getSDCFlag( uiAbsPartIdx ) )
758    {
759      for( Int iPart = 0; iPart < iPartNum; iPart++ )
760      {
761        if( getDimType( pcCU->getLumaIntraDir( uiAbsPartIdx + uiPartOffset*iPart ) ) < DIM_NUM_TYPE ) 
762        {
763          m_pcEntropyCoderIf->codeDeltaDC( pcCU, uiAbsPartIdx + uiPartOffset*iPart );
764        }
765      }
766    }
767    else
768    {
769      m_pcEntropyCoderIf->codeDeltaDC( pcCU, uiAbsPartIdx );
770      return;
771    }
772  }
773#endif
774
775  if( pcCU->isIntra(uiAbsPartIdx) )
776  {
777#if !H_MV
778    DTRACE_CABAC_VL( g_nSymbolCounter++ )
779    DTRACE_CABAC_T( "\tdecodeTransformIdx()\tCUDepth=" )
780    DTRACE_CABAC_V( uiDepth )
781    DTRACE_CABAC_T( "\n" )
782#endif
783  }
784  else
785  {
786    if( !(pcCU->getMergeFlag( uiAbsPartIdx ) && pcCU->getPartitionSize(uiAbsPartIdx) == SIZE_2Nx2N ) )
787    {
788      m_pcEntropyCoderIf->codeQtRootCbf( pcCU, uiAbsPartIdx );
789    }
790    if ( !pcCU->getQtRootCbf( uiAbsPartIdx ) )
791    {
792      return;
793    }
794  }
795 
796  xEncodeTransform( pcCU, uiLumaOffset, uiChromaOffset, uiAbsPartIdx, uiDepth, uiWidth, uiHeight, 0, bCodeDQP);
797}
798
799Void TEncEntropy::encodeCoeffNxN( TComDataCU* pcCU, TCoeff* pcCoeff, UInt uiAbsPartIdx, UInt uiTrWidth, UInt uiTrHeight, UInt uiDepth, TextType eType )
800{
801  // This is for Transform unit processing. This may be used at mode selection stage for Inter.
802  m_pcEntropyCoderIf->codeCoeffNxN( pcCU, pcCoeff, uiAbsPartIdx, uiTrWidth, uiTrHeight, uiDepth, eType );
803}
804
805Void TEncEntropy::estimateBit (estBitsSbacStruct* pcEstBitsSbac, Int width, Int height, TextType eTType)
806{ 
807  eTType = eTType == TEXT_LUMA ? TEXT_LUMA : TEXT_CHROMA;
808 
809  m_pcEntropyCoderIf->estBit ( pcEstBitsSbac, width, height, eTType );
810}
811
812Int TEncEntropy::countNonZeroCoeffs( TCoeff* pcCoef, UInt uiSize )
813{
814  Int count = 0;
815 
816  for ( Int i = 0; i < uiSize; i++ )
817  {
818    count += pcCoef[i] != 0;
819  }
820 
821  return count;
822}
823
824/** encode quantization matrix
825 * \param scalingList quantization matrix information
826 */
827Void TEncEntropy::encodeScalingList( TComScalingList* scalingList )
828{
829  m_pcEntropyCoderIf->codeScalingList( scalingList );
830}
831
832#if H_3D_INTER_SDC
833Void TEncEntropy::encodeDeltaDC  ( TComDataCU* pcCU, UInt absPartIdx )
834{
835  m_pcEntropyCoderIf->codeDeltaDC( pcCU, absPartIdx );
836}
837
838Void TEncEntropy::encodeSDCFlag( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool bRD )
839{
840  if( ( !pcCU->isIntra( uiAbsPartIdx ) && !pcCU->getSlice()->getInterSdcFlag() ) || 
841    ( pcCU->isIntra( uiAbsPartIdx ) && !pcCU->getSlice()->getIntraSdcWedgeFlag() ) )
842  {
843    return;
844  }
845
846  if( !pcCU->getSlice()->getIsDepth() || pcCU->getPartitionSize( uiAbsPartIdx ) != SIZE_2Nx2N || pcCU->isSkipped( uiAbsPartIdx ) )
847  {
848    return;
849  }
850
851  assert( pcCU->getPartitionSize( uiAbsPartIdx ) == SIZE_2Nx2N || ( !pcCU->isIntra( uiAbsPartIdx ) && !pcCU->isSkipped( uiAbsPartIdx ) ) );
852
853  if( bRD )
854  {
855    uiAbsPartIdx = 0;
856  }
857
858  m_pcEntropyCoderIf->codeSDCFlag( pcCU, uiAbsPartIdx );
859}
860
861#endif
862#if H_3D_DBBP
863Void TEncEntropy::encodeDBBPFlag( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool bRD )
864{
865#if HHI_MOVE_SYN_K0052
866  if( pcCU->getSlice()->getDepthBasedBlkPartFlag() && 
867    ( pcCU->getPartitionSize(uiAbsPartIdx) == SIZE_2NxN || 
868      pcCU->getPartitionSize(uiAbsPartIdx) == SIZE_Nx2N) && 
869      pcCU->getWidth(uiAbsPartIdx) > 8 && 
870      pcCU->getSlice()->getDefaultRefViewIdxAvailableFlag() )
871  {
872#endif
873    if( bRD )
874    {
875      uiAbsPartIdx = 0;
876    }
877    m_pcEntropyCoderIf->codeDBBPFlag( pcCU, uiAbsPartIdx );
878#if HHI_MOVE_SYN_K0052
879  }
880#endif
881}
882#endif
883//! \}
Note: See TracBrowser for help on using the repository browser.