source: 3DVCSoftware/branches/HTM-11.2-dev3-MediaTek/source/Lib/TLibEncoder/TEncEntropy.cpp @ 983

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

Integration of Single Depth Mode proposed in JCT3V-I0095.
The MACRO is "MTK_SINGLE_DEPTH_MODE_I0095".

By Yi-Wen Chen (yiwen.chen@…)

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