source: 3DVCSoftware/branches/HTM-12.2-dev1-Mediatek/source/Lib/TLibEncoder/TEncEntropy.cpp

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

Integration of JCT3V-J0060. The MACRO is "MTK_SINGLE_DEPTH_VPS_FLAG_J0060".

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