source: 3DVCSoftware/branches/HTM-12.2-dev0/source/Lib/TLibEncoder/TEncEntropy.cpp @ 1118

Last change on this file since 1118 was 1118, checked in by tech, 9 years ago

Merged 12.2-dev1-Hisilicon@1116.

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