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

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

Alignment of J0060 and J0107 (ALIGN_J0060_J0107)

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