source: 3DVCSoftware/branches/HTM-12.2-dev2-HHI/source/Lib/TLibEncoder/TEncEntropy.cpp @ 1106

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