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

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