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

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

Merged 10.2-dev0@949.

  • Property svn:eol-style set to native
File size: 23.4 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    return;
160
161  if( bRD )
162  {
163    uiAbsPartIdx = 0;
164  }
165#if MTK_LOW_LATENCY_IC_ENCODING_H0086
166  else
167  {
168    g_aICEnableCANDIDATE[pcCU->getSlice()->getDepth()]++;
169    if(pcCU->getICFlag(uiAbsPartIdx))
170    {
171      g_aICEnableNUM[pcCU->getSlice()->getDepth()]++;
172    }
173  }
174#endif
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 
243#if H_3D_DBBP
244  PartSize eVirtualPartSize = pcCU->getPartitionSize(uiAbsPartIdx);
245  if( pcCU->getDBBPFlag(uiAbsPartIdx) )
246  {
247    AOF( pcCU->getSlice()->getVPS()->getUseDBBP(pcCU->getSlice()->getLayerIdInVps()) );
248   
249    // temporarily change partition size for DBBP blocks
250    pcCU->setPartSizeSubParts(RWTH_DBBP_PACK_MODE, uiAbsPartIdx, uiDepth);
251  }
252#endif
253 
254  m_pcEntropyCoderIf->codePartSize( pcCU, uiAbsPartIdx, uiDepth );
255 
256#if H_3D_DBBP
257
258#if MTK_DBBP_SIGNALING_H0094
259  if( pcCU->getSlice()->getVPS()->getUseDBBP(pcCU->getSlice()->getLayerIdInVps()) )
260#else
261  if( pcCU->getSlice()->getVPS()->getUseDBBP(pcCU->getSlice()->getLayerIdInVps()) && pcCU->getPartitionSize(uiAbsPartIdx) == RWTH_DBBP_PACK_MODE )
262#endif
263  {
264    encodeDBBPFlag(pcCU, uiAbsPartIdx, bRD);
265   
266    if( pcCU->getDBBPFlag(uiAbsPartIdx) )
267    {
268#if !MTK_DBBP_SIGNALING_H0094
269      AOF( pcCU->getPartitionSize(uiAbsPartIdx) == RWTH_DBBP_PACK_MODE );
270#endif
271      // restore virtual partition size for DBBP blocks
272      pcCU->setPartSizeSubParts(eVirtualPartSize, uiAbsPartIdx, uiDepth);
273    }
274  }
275#endif
276}
277
278/** Encode I_PCM information.
279 * \param pcCU pointer to CU
280 * \param uiAbsPartIdx CU index
281 * \param bRD flag indicating estimation or encoding
282 * \returns Void
283 */
284Void TEncEntropy::encodeIPCMInfo( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool bRD )
285{
286  if(!pcCU->getSlice()->getSPS()->getUsePCM()
287    || pcCU->getWidth(uiAbsPartIdx) > (1<<pcCU->getSlice()->getSPS()->getPCMLog2MaxSize())
288    || pcCU->getWidth(uiAbsPartIdx) < (1<<pcCU->getSlice()->getSPS()->getPCMLog2MinSize()))
289  {
290    return;
291  }
292#if !MTK_SDC_FLAG_FIX_H0095
293#if H_3D_DIM_SDC
294  if( pcCU->getSDCFlag(uiAbsPartIdx) )
295  {
296    return;
297  }
298#endif
299#endif
300 
301  if( bRD )
302  {
303    uiAbsPartIdx = 0;
304  }
305 
306  m_pcEntropyCoderIf->codeIPCMInfo ( pcCU, uiAbsPartIdx );
307}
308
309Void TEncEntropy::xEncodeTransform( TComDataCU* pcCU,UInt offsetLuma, UInt offsetChroma, UInt uiAbsPartIdx, UInt uiDepth, UInt width, UInt height, UInt uiTrIdx, Bool& bCodeDQP )
310{
311  const UInt uiSubdiv = pcCU->getTransformIdx( uiAbsPartIdx ) + pcCU->getDepth( uiAbsPartIdx ) > uiDepth;
312  const UInt uiLog2TrafoSize = g_aucConvertToBit[pcCU->getSlice()->getSPS()->getMaxCUWidth()]+2 - uiDepth;
313  UInt cbfY = pcCU->getCbf( uiAbsPartIdx, TEXT_LUMA    , uiTrIdx );
314  UInt cbfU = pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_U, uiTrIdx );
315  UInt cbfV = pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_V, uiTrIdx );
316
317  if(uiTrIdx==0)
318  {
319    m_bakAbsPartIdxCU = uiAbsPartIdx;
320  }
321  if( uiLog2TrafoSize == 2 )
322  {
323    UInt partNum = pcCU->getPic()->getNumPartInCU() >> ( ( uiDepth - 1 ) << 1 );
324    if( ( uiAbsPartIdx % partNum ) == 0 )
325    {
326      m_uiBakAbsPartIdx   = uiAbsPartIdx;
327      m_uiBakChromaOffset = offsetChroma;
328    }
329    else if( ( uiAbsPartIdx % partNum ) == (partNum - 1) )
330    {
331      cbfU = pcCU->getCbf( m_uiBakAbsPartIdx, TEXT_CHROMA_U, uiTrIdx );
332      cbfV = pcCU->getCbf( m_uiBakAbsPartIdx, TEXT_CHROMA_V, uiTrIdx );
333    }
334  }
335 
336  if( pcCU->getPredictionMode(uiAbsPartIdx) == MODE_INTRA && pcCU->getPartitionSize(uiAbsPartIdx) == SIZE_NxN && uiDepth == pcCU->getDepth(uiAbsPartIdx) )
337  {
338    assert( uiSubdiv );
339  }
340  else if( pcCU->getPredictionMode(uiAbsPartIdx) == MODE_INTER && (pcCU->getPartitionSize(uiAbsPartIdx) != SIZE_2Nx2N) && uiDepth == pcCU->getDepth(uiAbsPartIdx) &&  (pcCU->getSlice()->getSPS()->getQuadtreeTUMaxDepthInter() == 1) )
341  {
342    if ( uiLog2TrafoSize > pcCU->getQuadtreeTULog2MinSizeInCU(uiAbsPartIdx) )
343    {
344      assert( uiSubdiv );
345    }
346    else
347    {
348      assert(!uiSubdiv );
349    }
350  }
351  else if( uiLog2TrafoSize > pcCU->getSlice()->getSPS()->getQuadtreeTULog2MaxSize() )
352  {
353    assert( uiSubdiv );
354  }
355  else if( uiLog2TrafoSize == pcCU->getSlice()->getSPS()->getQuadtreeTULog2MinSize() )
356  {
357    assert( !uiSubdiv );
358  }
359  else if( uiLog2TrafoSize == pcCU->getQuadtreeTULog2MinSizeInCU(uiAbsPartIdx) )
360  {
361    assert( !uiSubdiv );
362  }
363  else
364  {
365    assert( uiLog2TrafoSize > pcCU->getQuadtreeTULog2MinSizeInCU(uiAbsPartIdx) );
366    m_pcEntropyCoderIf->codeTransformSubdivFlag( uiSubdiv, 5 - uiLog2TrafoSize );
367  }
368
369  const UInt uiTrDepthCurr = uiDepth - pcCU->getDepth( uiAbsPartIdx );
370  const Bool bFirstCbfOfCU = uiTrDepthCurr == 0;
371  if( bFirstCbfOfCU || uiLog2TrafoSize > 2 )
372  {
373    if( bFirstCbfOfCU || pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_U, uiTrDepthCurr - 1 ) )
374    {
375      m_pcEntropyCoderIf->codeQtCbf( pcCU, uiAbsPartIdx, TEXT_CHROMA_U, uiTrDepthCurr );
376    }
377    if( bFirstCbfOfCU || pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_V, uiTrDepthCurr - 1 ) )
378    {
379      m_pcEntropyCoderIf->codeQtCbf( pcCU, uiAbsPartIdx, TEXT_CHROMA_V, uiTrDepthCurr );
380    }
381  }
382  else if( uiLog2TrafoSize == 2 )
383  {
384    assert( pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_U, uiTrDepthCurr ) == pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_U, uiTrDepthCurr - 1 ) );
385    assert( pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_V, uiTrDepthCurr ) == pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_V, uiTrDepthCurr - 1 ) );
386  }
387 
388  if( uiSubdiv )
389  {
390    UInt size;
391    width  >>= 1;
392    height >>= 1;
393    size = width*height;
394    uiTrIdx++;
395    ++uiDepth;
396    const UInt partNum = pcCU->getPic()->getNumPartInCU() >> (uiDepth << 1);
397   
398    xEncodeTransform( pcCU, offsetLuma, offsetChroma, uiAbsPartIdx, uiDepth, width, height, uiTrIdx, bCodeDQP );
399
400    uiAbsPartIdx += partNum;  offsetLuma += size;  offsetChroma += (size>>2);
401    xEncodeTransform( pcCU, offsetLuma, offsetChroma, uiAbsPartIdx, uiDepth, width, height, uiTrIdx, bCodeDQP );
402
403    uiAbsPartIdx += partNum;  offsetLuma += size;  offsetChroma += (size>>2);
404    xEncodeTransform( pcCU, offsetLuma, offsetChroma, uiAbsPartIdx, uiDepth, width, height, uiTrIdx, bCodeDQP );
405
406    uiAbsPartIdx += partNum;  offsetLuma += size;  offsetChroma += (size>>2);
407    xEncodeTransform( pcCU, offsetLuma, offsetChroma, uiAbsPartIdx, uiDepth, width, height, uiTrIdx, bCodeDQP );
408  }
409  else
410  {
411#if !H_MV_ENC_DEC_TRAC
412    {
413      DTRACE_CABAC_VL( g_nSymbolCounter++ );
414      DTRACE_CABAC_T( "\tTrIdx: abspart=" );
415      DTRACE_CABAC_V( uiAbsPartIdx );
416      DTRACE_CABAC_T( "\tdepth=" );
417      DTRACE_CABAC_V( uiDepth );
418      DTRACE_CABAC_T( "\ttrdepth=" );
419      DTRACE_CABAC_V( pcCU->getTransformIdx( uiAbsPartIdx ) );
420      DTRACE_CABAC_T( "\n" );
421    }
422#endif
423   
424    if( pcCU->getPredictionMode(uiAbsPartIdx) != MODE_INTRA && uiDepth == pcCU->getDepth( uiAbsPartIdx ) && !pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_U, 0 ) && !pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_V, 0 ) )
425    {
426      assert( pcCU->getCbf( uiAbsPartIdx, TEXT_LUMA, 0 ) );
427      //      printf( "saved one bin! " );
428    }
429    else
430    {
431      m_pcEntropyCoderIf->codeQtCbf( pcCU, uiAbsPartIdx, TEXT_LUMA, pcCU->getTransformIdx( uiAbsPartIdx ) );
432    }
433
434
435    if ( cbfY || cbfU || cbfV )
436    {
437      // dQP: only for LCU once
438      if ( pcCU->getSlice()->getPPS()->getUseDQP() )
439      {
440        if ( bCodeDQP )
441        {
442          encodeQP( pcCU, m_bakAbsPartIdxCU );
443          bCodeDQP = false;
444        }
445      }
446    }
447    if( cbfY )
448    {
449      Int trWidth = width;
450      Int trHeight = height;
451      m_pcEntropyCoderIf->codeCoeffNxN( pcCU, (pcCU->getCoeffY()+offsetLuma), uiAbsPartIdx, trWidth, trHeight, uiDepth, TEXT_LUMA );
452    }
453    if( uiLog2TrafoSize > 2 )
454    {
455      Int trWidth = width >> 1;
456      Int trHeight = height >> 1;
457      if( cbfU )
458      {
459        m_pcEntropyCoderIf->codeCoeffNxN( pcCU, (pcCU->getCoeffCb()+offsetChroma), uiAbsPartIdx, trWidth, trHeight, uiDepth, TEXT_CHROMA_U );
460      }
461      if( cbfV )
462      {
463        m_pcEntropyCoderIf->codeCoeffNxN( pcCU, (pcCU->getCoeffCr()+offsetChroma), uiAbsPartIdx, trWidth, trHeight, uiDepth, TEXT_CHROMA_V );
464      }
465    }
466    else
467    {
468      UInt partNum = pcCU->getPic()->getNumPartInCU() >> ( ( uiDepth - 1 ) << 1 );
469      if( ( uiAbsPartIdx % partNum ) == (partNum - 1) )
470      {
471        Int trWidth = width;
472        Int trHeight = height;
473        if( cbfU )
474        {
475          m_pcEntropyCoderIf->codeCoeffNxN( pcCU, (pcCU->getCoeffCb()+m_uiBakChromaOffset), m_uiBakAbsPartIdx, trWidth, trHeight, uiDepth, TEXT_CHROMA_U );
476        }
477        if( cbfV )
478        {
479          m_pcEntropyCoderIf->codeCoeffNxN( pcCU, (pcCU->getCoeffCr()+m_uiBakChromaOffset), m_uiBakAbsPartIdx, trWidth, trHeight, uiDepth, TEXT_CHROMA_V );
480        }
481      }
482    }
483  }
484}
485
486// Intra direction for Luma
487Void TEncEntropy::encodeIntraDirModeLuma  ( TComDataCU* pcCU, UInt absPartIdx, Bool isMultiplePU )
488{
489  m_pcEntropyCoderIf->codeIntraDirLumaAng( pcCU, absPartIdx , isMultiplePU);
490}
491
492// Intra direction for Chroma
493Void TEncEntropy::encodeIntraDirModeChroma( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool bRD )
494{
495  if( bRD )
496  {
497    uiAbsPartIdx = 0;
498  }
499 
500  m_pcEntropyCoderIf->codeIntraDirChroma( pcCU, uiAbsPartIdx );
501}
502
503Void TEncEntropy::encodePredInfo( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool bRD )
504{
505  if( bRD )
506  {
507    uiAbsPartIdx = 0;
508  }
509  if( pcCU->isIntra( uiAbsPartIdx ) )                                 // If it is Intra mode, encode intra prediction mode.
510  {
511    encodeIntraDirModeLuma  ( pcCU, uiAbsPartIdx,true );
512#if H_3D_DIM_SDC
513    if(!pcCU->getSDCFlag(uiAbsPartIdx))
514#endif
515    encodeIntraDirModeChroma( pcCU, uiAbsPartIdx, bRD );
516  }
517  else                                                                // if it is Inter mode, encode motion vector and reference index
518  {
519    encodePUWise( pcCU, uiAbsPartIdx, bRD );
520  }
521}
522
523/** encode motion information for every PU block
524 * \param pcCU
525 * \param uiAbsPartIdx
526 * \param bRD
527 * \returns Void
528 */
529Void TEncEntropy::encodePUWise( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool bRD )
530{
531  if ( bRD )
532  {
533    uiAbsPartIdx = 0;
534  }
535 
536  PartSize ePartSize = pcCU->getPartitionSize( uiAbsPartIdx );
537  UInt uiNumPU = ( ePartSize == SIZE_2Nx2N ? 1 : ( ePartSize == SIZE_NxN ? 4 : 2 ) );
538  UInt uiDepth = pcCU->getDepth( uiAbsPartIdx );
539  UInt uiPUOffset = ( g_auiPUOffset[UInt( ePartSize )] << ( ( pcCU->getSlice()->getSPS()->getMaxCUDepth() - uiDepth ) << 1 ) ) >> 4;
540
541  for ( UInt uiPartIdx = 0, uiSubPartIdx = uiAbsPartIdx; uiPartIdx < uiNumPU; uiPartIdx++, uiSubPartIdx += uiPUOffset )
542  {
543#if H_MV_ENC_DEC_TRAC
544    DTRACE_PU_S("=========== prediction_unit ===========\n")
545       //Todo:
546      //DTRACE_PU("x0", uiLPelX)
547      //DTRACE_PU("x1", uiTPelY)
548#endif
549    encodeMergeFlag( pcCU, uiSubPartIdx );
550    if ( pcCU->getMergeFlag( uiSubPartIdx ) )
551    {
552      encodeMergeIndex( pcCU, uiSubPartIdx );
553    }
554    else
555    {
556      encodeInterDirPU( pcCU, uiSubPartIdx );
557      for ( UInt uiRefListIdx = 0; uiRefListIdx < 2; uiRefListIdx++ )
558      {
559        if ( pcCU->getSlice()->getNumRefIdx( RefPicList( uiRefListIdx ) ) > 0 )
560        {
561          encodeRefFrmIdxPU ( pcCU, uiSubPartIdx, RefPicList( uiRefListIdx ) );
562          encodeMvdPU       ( pcCU, uiSubPartIdx, RefPicList( uiRefListIdx ) );
563          encodeMVPIdxPU    ( pcCU, uiSubPartIdx, RefPicList( uiRefListIdx ) );
564        }
565      }
566    }
567  }
568
569  return;
570}
571
572Void TEncEntropy::encodeInterDirPU( TComDataCU* pcCU, UInt uiAbsPartIdx )
573{
574  if ( !pcCU->getSlice()->isInterB() )
575  {
576    return;
577  }
578
579  m_pcEntropyCoderIf->codeInterDir( pcCU, uiAbsPartIdx );
580  return;
581}
582
583/** encode reference frame index for a PU block
584 * \param pcCU
585 * \param uiAbsPartIdx
586 * \param eRefList
587 * \returns Void
588 */
589Void TEncEntropy::encodeRefFrmIdxPU( TComDataCU* pcCU, UInt uiAbsPartIdx, RefPicList eRefList )
590{
591  assert( !pcCU->isIntra( uiAbsPartIdx ) );
592  {
593    if ( ( pcCU->getSlice()->getNumRefIdx( eRefList ) == 1 ) )
594    {
595      return;
596    }
597
598    if ( pcCU->getInterDir( uiAbsPartIdx ) & ( 1 << eRefList ) )
599    {
600      m_pcEntropyCoderIf->codeRefFrmIdx( pcCU, uiAbsPartIdx, eRefList );
601    }
602  }
603
604  return;
605}
606
607/** encode motion vector difference for a PU block
608 * \param pcCU
609 * \param uiAbsPartIdx
610 * \param eRefList
611 * \returns Void
612 */
613Void TEncEntropy::encodeMvdPU( TComDataCU* pcCU, UInt uiAbsPartIdx, RefPicList eRefList )
614{
615  assert( !pcCU->isIntra( uiAbsPartIdx ) );
616
617  if ( pcCU->getInterDir( uiAbsPartIdx ) & ( 1 << eRefList ) )
618  {
619    m_pcEntropyCoderIf->codeMvd( pcCU, uiAbsPartIdx, eRefList );
620  }
621  return;
622}
623
624Void TEncEntropy::encodeMVPIdxPU( TComDataCU* pcCU, UInt uiAbsPartIdx, RefPicList eRefList )
625{
626  if ( (pcCU->getInterDir( uiAbsPartIdx ) & ( 1 << eRefList )) )
627  {
628    m_pcEntropyCoderIf->codeMVPIdx( pcCU, uiAbsPartIdx, eRefList );
629  }
630
631  return;
632}
633
634Void TEncEntropy::encodeQtCbf( TComDataCU* pcCU, UInt uiAbsPartIdx, TextType eType, UInt uiTrDepth )
635{
636  m_pcEntropyCoderIf->codeQtCbf( pcCU, uiAbsPartIdx, eType, uiTrDepth );
637}
638
639Void TEncEntropy::encodeTransformSubdivFlag( UInt uiSymbol, UInt uiCtx )
640{
641  m_pcEntropyCoderIf->codeTransformSubdivFlag( uiSymbol, uiCtx );
642}
643
644Void TEncEntropy::encodeQtRootCbf( TComDataCU* pcCU, UInt uiAbsPartIdx )
645{
646  m_pcEntropyCoderIf->codeQtRootCbf( pcCU, uiAbsPartIdx );
647}
648
649Void TEncEntropy::encodeQtCbfZero( TComDataCU* pcCU, TextType eType, UInt uiTrDepth )
650{
651  m_pcEntropyCoderIf->codeQtCbfZero( pcCU, eType, uiTrDepth );
652}
653Void TEncEntropy::encodeQtRootCbfZero( TComDataCU* pcCU )
654{
655  m_pcEntropyCoderIf->codeQtRootCbfZero( pcCU );
656}
657
658// dQP
659Void TEncEntropy::encodeQP( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool bRD )
660{
661  if( bRD )
662  {
663    uiAbsPartIdx = 0;
664  }
665 
666  if ( pcCU->getSlice()->getPPS()->getUseDQP() )
667  {
668    m_pcEntropyCoderIf->codeDeltaQP( pcCU, uiAbsPartIdx );
669  }
670}
671
672
673// texture
674/** encode coefficients
675 * \param pcCU
676 * \param uiAbsPartIdx
677 * \param uiDepth
678 * \param uiWidth
679 * \param uiHeight
680 */
681Void TEncEntropy::encodeCoeff( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, UInt uiWidth, UInt uiHeight, Bool& bCodeDQP )
682{
683  UInt uiMinCoeffSize = pcCU->getPic()->getMinCUWidth()*pcCU->getPic()->getMinCUHeight();
684  UInt uiLumaOffset   = uiMinCoeffSize*uiAbsPartIdx;
685  UInt uiChromaOffset = uiLumaOffset>>2;
686#if H_3D_DIM_SDC
687  if( pcCU->getSDCFlag( uiAbsPartIdx ) && pcCU->isIntra( uiAbsPartIdx ) )
688  {
689    assert( pcCU->getPartitionSize(uiAbsPartIdx) == SIZE_2Nx2N );
690    assert( pcCU->getTransformIdx(uiAbsPartIdx) == 0 );
691    assert( pcCU->getCbf(uiAbsPartIdx, TEXT_LUMA) == 1 );
692    assert( pcCU->getCbf(uiAbsPartIdx, TEXT_CHROMA_U) == 1 );
693    assert( pcCU->getCbf(uiAbsPartIdx, TEXT_CHROMA_V) == 1 );
694  }
695
696  if( pcCU->getSDCFlag( uiAbsPartIdx ) && !pcCU->isIntra( uiAbsPartIdx ) )
697  {
698    assert( !pcCU->isSkipped( uiAbsPartIdx ) );
699    assert( !pcCU->isIntra( uiAbsPartIdx) );
700    assert( pcCU->getSlice()->getIsDepth() );
701  }
702
703  if( pcCU->getSlice()->getIsDepth() && ( pcCU->getSDCFlag( uiAbsPartIdx ) || pcCU->isIntra( uiAbsPartIdx ) ) )
704  {
705    Int iPartNum = ( pcCU->isIntra( uiAbsPartIdx ) && pcCU->getPartitionSize( uiAbsPartIdx ) == SIZE_NxN ) ? 4 : 1;
706    UInt uiPartOffset = ( pcCU->getPic()->getNumPartInCU() >> ( pcCU->getDepth( uiAbsPartIdx ) << 1 ) ) >> 2;
707   
708    if( !pcCU->getSDCFlag( uiAbsPartIdx ) )
709    {
710      for( Int iPart = 0; iPart < iPartNum; iPart++ )
711      {
712        if( getDimType( pcCU->getLumaIntraDir( uiAbsPartIdx + uiPartOffset*iPart ) ) < DIM_NUM_TYPE ) 
713        {
714          m_pcEntropyCoderIf->codeDeltaDC( pcCU, uiAbsPartIdx + uiPartOffset*iPart );
715        }
716      }
717    }
718    else
719    {
720      m_pcEntropyCoderIf->codeDeltaDC( pcCU, uiAbsPartIdx );
721      return;
722    }
723  }
724#endif
725
726  if( pcCU->isIntra(uiAbsPartIdx) )
727  {
728#if !H_MV
729    DTRACE_CABAC_VL( g_nSymbolCounter++ )
730    DTRACE_CABAC_T( "\tdecodeTransformIdx()\tCUDepth=" )
731    DTRACE_CABAC_V( uiDepth )
732    DTRACE_CABAC_T( "\n" )
733#endif
734  }
735  else
736  {
737    if( !(pcCU->getMergeFlag( uiAbsPartIdx ) && pcCU->getPartitionSize(uiAbsPartIdx) == SIZE_2Nx2N ) )
738    {
739      m_pcEntropyCoderIf->codeQtRootCbf( pcCU, uiAbsPartIdx );
740    }
741    if ( !pcCU->getQtRootCbf( uiAbsPartIdx ) )
742    {
743      return;
744    }
745  }
746 
747  xEncodeTransform( pcCU, uiLumaOffset, uiChromaOffset, uiAbsPartIdx, uiDepth, uiWidth, uiHeight, 0, bCodeDQP);
748}
749
750Void TEncEntropy::encodeCoeffNxN( TComDataCU* pcCU, TCoeff* pcCoeff, UInt uiAbsPartIdx, UInt uiTrWidth, UInt uiTrHeight, UInt uiDepth, TextType eType )
751{
752  // This is for Transform unit processing. This may be used at mode selection stage for Inter.
753  m_pcEntropyCoderIf->codeCoeffNxN( pcCU, pcCoeff, uiAbsPartIdx, uiTrWidth, uiTrHeight, uiDepth, eType );
754}
755
756Void TEncEntropy::estimateBit (estBitsSbacStruct* pcEstBitsSbac, Int width, Int height, TextType eTType)
757{ 
758  eTType = eTType == TEXT_LUMA ? TEXT_LUMA : TEXT_CHROMA;
759 
760  m_pcEntropyCoderIf->estBit ( pcEstBitsSbac, width, height, eTType );
761}
762
763Int TEncEntropy::countNonZeroCoeffs( TCoeff* pcCoef, UInt uiSize )
764{
765  Int count = 0;
766 
767  for ( Int i = 0; i < uiSize; i++ )
768  {
769    count += pcCoef[i] != 0;
770  }
771 
772  return count;
773}
774
775/** encode quantization matrix
776 * \param scalingList quantization matrix information
777 */
778Void TEncEntropy::encodeScalingList( TComScalingList* scalingList )
779{
780  m_pcEntropyCoderIf->codeScalingList( scalingList );
781}
782
783#if H_3D_INTER_SDC
784Void TEncEntropy::encodeDeltaDC  ( TComDataCU* pcCU, UInt absPartIdx )
785{
786  m_pcEntropyCoderIf->codeDeltaDC( pcCU, absPartIdx );
787}
788
789Void TEncEntropy::encodeSDCFlag( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool bRD )
790{
791  if( ( !pcCU->isIntra( uiAbsPartIdx ) && !pcCU->getSlice()->getVPS()->getInterSDCFlag( pcCU->getSlice()->getLayerIdInVps() ) ) || 
792    ( pcCU->isIntra( uiAbsPartIdx ) && !pcCU->getSlice()->getVPS()->getVpsDepthModesFlag( pcCU->getSlice()->getLayerIdInVps() ) ) )
793  {
794    return;
795  }
796
797  if( !pcCU->getSlice()->getIsDepth() || pcCU->getPartitionSize( uiAbsPartIdx ) != SIZE_2Nx2N || pcCU->isSkipped( uiAbsPartIdx ) )
798  {
799    return;
800  }
801
802  assert( pcCU->getPartitionSize( uiAbsPartIdx ) == SIZE_2Nx2N || ( !pcCU->isIntra( uiAbsPartIdx ) && !pcCU->isSkipped( uiAbsPartIdx ) ) );
803
804  if( bRD )
805  {
806    uiAbsPartIdx = 0;
807  }
808
809  m_pcEntropyCoderIf->codeSDCFlag( pcCU, uiAbsPartIdx );
810}
811
812#endif
813#if H_3D_DBBP
814Void TEncEntropy::encodeDBBPFlag( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool bRD )
815{
816  if( bRD )
817  {
818    uiAbsPartIdx = 0;
819  }
820  m_pcEntropyCoderIf->codeDBBPFlag( pcCU, uiAbsPartIdx );
821}
822#endif
823//! \}
Note: See TracBrowser for help on using the repository browser.