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

Last change on this file since 464 was 464, checked in by zhang, 11 years ago

Implementation of ARP from QC

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