source: 3DVCSoftware/branches/HTM-9.3-dev2-Samsung/source/Lib/TLibEncoder/TEncEntropy.cpp @ 785

Last change on this file since 785 was 785, checked in by samsung-htm, 10 years ago

Integration of JCT3V-G0072: IC and ARP Flags Signaling

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