source: 3DVCSoftware/branches/HTM-DEV-0.3-dev2a/source/Lib/TLibEncoder/TEncEntropy.cpp @ 468

Last change on this file since 468 was 468, checked in by lg, 11 years ago

1.IC and full pel depth coding are integrated and is guarded by Macro H_3D_IC.

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