source: 3DVCSoftware/trunk/source/Lib/TLibEncoder/TEncSbac.cpp @ 1179

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

Merged branch 13.1-dev0@1178.

  • Property svn:eol-style set to native
File size: 78.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-2015, 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     TEncSbac.cpp
35    \brief    SBAC encoder class
36*/
37
38#include "TEncTop.h"
39#include "TEncSbac.h"
40
41#include <map>
42#include <algorithm>
43
44//! \ingroup TLibEncoder
45//! \{
46
47// ====================================================================================================================
48// Constructor / destructor / create / destroy
49// ====================================================================================================================
50
51TEncSbac::TEncSbac()
52// new structure here
53: m_pcBitIf                   ( NULL )
54, m_pcSlice                   ( NULL )
55, m_pcBinIf                   ( NULL )
56, m_uiCoeffCost               ( 0 )
57, m_numContextModels          ( 0 )
58, m_cCUSplitFlagSCModel       ( 1,             1,               NUM_SPLIT_FLAG_CTX            , m_contextModels + m_numContextModels, m_numContextModels )
59, m_cCUSkipFlagSCModel        ( 1,             1,               NUM_SKIP_FLAG_CTX             , m_contextModels + m_numContextModels, m_numContextModels)
60#if SEC_DEPTH_INTRA_SKIP_MODE_K0033
61, m_cCUDISFlagSCModel         ( 1,             1,               NUM_DIS_FLAG_CTX              , m_contextModels + m_numContextModels, m_numContextModels)
62, m_cCUDISTypeSCModel         ( 1,             1,               NUM_DIS_TYPE_CTX              , m_contextModels + m_numContextModels, m_numContextModels)
63#else
64#if H_3D_SINGLE_DEPTH
65, m_cCUSingleDepthFlagSCModel        ( 1,             1,               NUM_SINGLEDEPTH_FLAG_CTX             , m_contextModels + m_numContextModels, m_numContextModels)
66, m_cSingleDepthValueSCModel         ( 1,             1,               NUM_SINGLE_DEPTH_VALUE_DATA_CTX      , m_contextModels + m_numContextModels, m_numContextModels)
67#endif
68#endif
69, m_cCUMergeFlagExtSCModel    ( 1,             1,               NUM_MERGE_FLAG_EXT_CTX        , m_contextModels + m_numContextModels, m_numContextModels)
70, m_cCUMergeIdxExtSCModel     ( 1,             1,               NUM_MERGE_IDX_EXT_CTX         , m_contextModels + m_numContextModels, m_numContextModels)
71#if H_3D_ARP
72, m_cCUPUARPWSCModel          ( 1,             1,               NUM_ARPW_CTX                  , m_contextModels + m_numContextModels, m_numContextModels)
73#endif
74#if H_3D_IC
75, m_cCUICFlagSCModel          ( 1,             1,               NUM_IC_FLAG_CTX               , m_contextModels + m_numContextModels, m_numContextModels)
76#endif
77, m_cCUPartSizeSCModel        ( 1,             1,               NUM_PART_SIZE_CTX             , m_contextModels + m_numContextModels, m_numContextModels)
78, m_cCUPredModeSCModel        ( 1,             1,               NUM_PRED_MODE_CTX             , m_contextModels + m_numContextModels, m_numContextModels)
79, m_cCUIntraPredSCModel       ( 1,             1,               NUM_ADI_CTX                   , m_contextModels + m_numContextModels, m_numContextModels)
80, m_cCUChromaPredSCModel      ( 1,             1,               NUM_CHROMA_PRED_CTX           , m_contextModels + m_numContextModels, m_numContextModels)
81, m_cCUDeltaQpSCModel         ( 1,             1,               NUM_DELTA_QP_CTX              , m_contextModels + m_numContextModels, m_numContextModels)
82, m_cCUInterDirSCModel        ( 1,             1,               NUM_INTER_DIR_CTX             , m_contextModels + m_numContextModels, m_numContextModels)
83, m_cCURefPicSCModel          ( 1,             1,               NUM_REF_NO_CTX                , m_contextModels + m_numContextModels, m_numContextModels)
84, m_cCUMvdSCModel             ( 1,             1,               NUM_MV_RES_CTX                , m_contextModels + m_numContextModels, m_numContextModels)
85, m_cCUQtCbfSCModel           ( 1,             2,               NUM_QT_CBF_CTX                , m_contextModels + m_numContextModels, m_numContextModels)
86, m_cCUTransSubdivFlagSCModel ( 1,             1,               NUM_TRANS_SUBDIV_FLAG_CTX     , m_contextModels + m_numContextModels, m_numContextModels)
87, m_cCUQtRootCbfSCModel       ( 1,             1,               NUM_QT_ROOT_CBF_CTX           , m_contextModels + m_numContextModels, m_numContextModels)
88, m_cCUSigCoeffGroupSCModel   ( 1,             2,               NUM_SIG_CG_FLAG_CTX           , m_contextModels + m_numContextModels, m_numContextModels)
89, m_cCUSigSCModel             ( 1,             1,               NUM_SIG_FLAG_CTX              , m_contextModels + m_numContextModels, m_numContextModels)
90, m_cCuCtxLastX               ( 1,             2,               NUM_CTX_LAST_FLAG_XY          , m_contextModels + m_numContextModels, m_numContextModels)
91, m_cCuCtxLastY               ( 1,             2,               NUM_CTX_LAST_FLAG_XY          , m_contextModels + m_numContextModels, m_numContextModels)
92, m_cCUOneSCModel             ( 1,             1,               NUM_ONE_FLAG_CTX              , m_contextModels + m_numContextModels, m_numContextModels)
93, m_cCUAbsSCModel             ( 1,             1,               NUM_ABS_FLAG_CTX              , m_contextModels + m_numContextModels, m_numContextModels)
94, m_cMVPIdxSCModel            ( 1,             1,               NUM_MVP_IDX_CTX               , m_contextModels + m_numContextModels, m_numContextModels)
95, m_cSaoMergeSCModel          ( 1,             1,               NUM_SAO_MERGE_FLAG_CTX   , m_contextModels + m_numContextModels, m_numContextModels)
96, m_cSaoTypeIdxSCModel        ( 1,             1,               NUM_SAO_TYPE_IDX_CTX          , m_contextModels + m_numContextModels, m_numContextModels)
97, m_cTransformSkipSCModel     ( 1,             2,               NUM_TRANSFORMSKIP_FLAG_CTX    , m_contextModels + m_numContextModels, m_numContextModels)
98, m_CUTransquantBypassFlagSCModel( 1,          1,               NUM_CU_TRANSQUANT_BYPASS_FLAG_CTX, m_contextModels + m_numContextModels, m_numContextModels)
99#if H_3D_DIM
100, m_cDepthIntraModeSCModel    ( 1,             1,               NUM_DEPTH_INTRA_MODE_CTX      , m_contextModels + m_numContextModels, m_numContextModels)
101, m_cDdcFlagSCModel           ( 1,             1,               NUM_DDC_FLAG_CTX              , m_contextModels + m_numContextModels, m_numContextModels)
102, m_cDdcDataSCModel           ( 1,             1,               NUM_DDC_DATA_CTX              , m_contextModels + m_numContextModels, m_numContextModels)
103, m_cAngleFlagSCModel         ( 1,             1,               NUM_ANGLE_FLAG_CTX            , m_contextModels + m_numContextModels, m_numContextModels)
104#if H_3D_DIM_SDC
105, m_cSDCResidualFlagSCModel   ( 1,             1,               SDC_NUM_RESIDUAL_FLAG_CTX     , m_contextModels + m_numContextModels, m_numContextModels)
106, m_cSDCResidualSCModel       ( 1,             1,               SDC_NUM_RESIDUAL_CTX          , m_contextModels + m_numContextModels, m_numContextModels)
107#endif
108#endif
109#if H_3D_DIM_SDC
110, m_cSDCFlagSCModel                  ( 1,             1,  NUM_SDC_FLAG_CTX                 , m_contextModels + m_numContextModels, m_numContextModels)
111#endif
112#if H_3D_DBBP
113, m_cDBBPFlagSCModel             ( 1,             1,                 DBBP_NUM_FLAG_CTX           , m_contextModels + m_numContextModels, m_numContextModels)
114#endif
115{
116  assert( m_numContextModels <= MAX_NUM_CTX_MOD );
117}
118
119TEncSbac::~TEncSbac()
120{
121}
122
123// ====================================================================================================================
124// Public member functions
125// ====================================================================================================================
126
127Void TEncSbac::resetEntropy           ()
128{
129  Int  iQp              = m_pcSlice->getSliceQp();
130  SliceType eSliceType  = m_pcSlice->getSliceType();
131 
132  Int  encCABACTableIdx = m_pcSlice->getPPS()->getEncCABACTableIdx();
133  if (!m_pcSlice->isIntra() && (encCABACTableIdx==B_SLICE || encCABACTableIdx==P_SLICE) && m_pcSlice->getPPS()->getCabacInitPresentFlag())
134  {
135    eSliceType = (SliceType) encCABACTableIdx;
136  }
137
138  m_cCUSplitFlagSCModel.initBuffer       ( eSliceType, iQp, (UChar*)INIT_SPLIT_FLAG );
139 
140  m_cCUSkipFlagSCModel.initBuffer        ( eSliceType, iQp, (UChar*)INIT_SKIP_FLAG );
141#if SEC_DEPTH_INTRA_SKIP_MODE_K0033
142  m_cCUDISFlagSCModel.initBuffer         ( eSliceType, iQp, (UChar*)INIT_DIS_FLAG );
143  m_cCUDISTypeSCModel.initBuffer         ( eSliceType, iQp, (UChar*)INIT_DIS_TYPE );
144#else
145#if H_3D_SINGLE_DEPTH
146  m_cCUSingleDepthFlagSCModel.initBuffer        ( eSliceType, iQp, (UChar*)INIT_SINGLEDEPTH_FLAG );
147  m_cSingleDepthValueSCModel.initBuffer         ( eSliceType, iQp, (UChar*)INIT_SINGLE_DEPTH_VALUE_DATA );
148#endif
149#endif
150  m_cCUMergeFlagExtSCModel.initBuffer    ( eSliceType, iQp, (UChar*)INIT_MERGE_FLAG_EXT);
151  m_cCUMergeIdxExtSCModel.initBuffer     ( eSliceType, iQp, (UChar*)INIT_MERGE_IDX_EXT);
152#if H_3D_ARP
153  m_cCUPUARPWSCModel.initBuffer          ( eSliceType, iQp, (UChar*)INIT_ARPW );
154#endif
155#if H_3D_IC
156  m_cCUICFlagSCModel.initBuffer          ( eSliceType, iQp, (UChar*)INIT_IC_FLAG );
157#endif
158  m_cCUPartSizeSCModel.initBuffer        ( eSliceType, iQp, (UChar*)INIT_PART_SIZE );
159  m_cCUPredModeSCModel.initBuffer        ( eSliceType, iQp, (UChar*)INIT_PRED_MODE );
160  m_cCUIntraPredSCModel.initBuffer       ( eSliceType, iQp, (UChar*)INIT_INTRA_PRED_MODE );
161  m_cCUChromaPredSCModel.initBuffer      ( eSliceType, iQp, (UChar*)INIT_CHROMA_PRED_MODE );
162  m_cCUInterDirSCModel.initBuffer        ( eSliceType, iQp, (UChar*)INIT_INTER_DIR );
163  m_cCUMvdSCModel.initBuffer             ( eSliceType, iQp, (UChar*)INIT_MVD );
164  m_cCURefPicSCModel.initBuffer          ( eSliceType, iQp, (UChar*)INIT_REF_PIC );
165  m_cCUDeltaQpSCModel.initBuffer         ( eSliceType, iQp, (UChar*)INIT_DQP );
166  m_cCUQtCbfSCModel.initBuffer           ( eSliceType, iQp, (UChar*)INIT_QT_CBF );
167  m_cCUQtRootCbfSCModel.initBuffer       ( eSliceType, iQp, (UChar*)INIT_QT_ROOT_CBF );
168  m_cCUSigCoeffGroupSCModel.initBuffer   ( eSliceType, iQp, (UChar*)INIT_SIG_CG_FLAG );
169  m_cCUSigSCModel.initBuffer             ( eSliceType, iQp, (UChar*)INIT_SIG_FLAG );
170  m_cCuCtxLastX.initBuffer               ( eSliceType, iQp, (UChar*)INIT_LAST );
171  m_cCuCtxLastY.initBuffer               ( eSliceType, iQp, (UChar*)INIT_LAST );
172  m_cCUOneSCModel.initBuffer             ( eSliceType, iQp, (UChar*)INIT_ONE_FLAG );
173  m_cCUAbsSCModel.initBuffer             ( eSliceType, iQp, (UChar*)INIT_ABS_FLAG );
174  m_cMVPIdxSCModel.initBuffer            ( eSliceType, iQp, (UChar*)INIT_MVP_IDX );
175  m_cCUTransSubdivFlagSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_TRANS_SUBDIV_FLAG );
176  m_cSaoMergeSCModel.initBuffer      ( eSliceType, iQp, (UChar*)INIT_SAO_MERGE_FLAG );
177  m_cSaoTypeIdxSCModel.initBuffer        ( eSliceType, iQp, (UChar*)INIT_SAO_TYPE_IDX );
178  m_cTransformSkipSCModel.initBuffer     ( eSliceType, iQp, (UChar*)INIT_TRANSFORMSKIP_FLAG );
179  m_CUTransquantBypassFlagSCModel.initBuffer( eSliceType, iQp, (UChar*)INIT_CU_TRANSQUANT_BYPASS_FLAG );
180
181#if H_3D_DIM
182  m_cDepthIntraModeSCModel.initBuffer    ( eSliceType, iQp, (UChar*)INIT_DEPTH_INTRA_MODE );
183  m_cDdcFlagSCModel.initBuffer           ( eSliceType, iQp, (UChar*)INIT_DDC_FLAG );
184  m_cDdcDataSCModel.initBuffer           ( eSliceType, iQp, (UChar*)INIT_DDC_DATA );
185  m_cAngleFlagSCModel.initBuffer         ( eSliceType, iQp, (UChar*)INIT_ANGLE_FLAG );
186#if H_3D_DIM_SDC
187  m_cSDCResidualFlagSCModel.initBuffer   ( eSliceType, iQp, (UChar*)INIT_SDC_RESIDUAL_FLAG );
188  m_cSDCResidualSCModel.initBuffer       ( eSliceType, iQp, (UChar*)INIT_SDC_RESIDUAL );
189#endif
190#endif
191#if H_3D_DIM_SDC
192  m_cSDCFlagSCModel.initBuffer              ( eSliceType, iQp, (UChar*)INIT_SDC_FLAG );
193#endif
194#if H_3D_DBBP
195  m_cDBBPFlagSCModel.initBuffer              ( eSliceType, iQp, (UChar*)INIT_DBBP_FLAG );
196#endif
197  // new structure
198  m_uiLastQp = iQp;
199 
200  m_pcBinIf->start();
201 
202  return;
203}
204
205/** The function does the following:
206 * If current slice type is P/B then it determines the distance of initialisation type 1 and 2 from the current CABAC states and
207 * stores the index of the closest table.  This index is used for the next P/B slice when cabac_init_present_flag is true.
208 */
209Void TEncSbac::determineCabacInitIdx()
210{
211  Int  qp              = m_pcSlice->getSliceQp();
212
213  if (!m_pcSlice->isIntra())
214  {
215    SliceType aSliceTypeChoices[] = {B_SLICE, P_SLICE};
216
217    UInt bestCost             = MAX_UINT;
218    SliceType bestSliceType   = aSliceTypeChoices[0];
219    for (UInt idx=0; idx<2; idx++)
220    {
221      UInt curCost          = 0;
222      SliceType curSliceType  = aSliceTypeChoices[idx];
223
224      curCost  = m_cCUSplitFlagSCModel.calcCost       ( curSliceType, qp, (UChar*)INIT_SPLIT_FLAG );
225      curCost += m_cCUSkipFlagSCModel.calcCost        ( curSliceType, qp, (UChar*)INIT_SKIP_FLAG );
226#if SEC_DEPTH_INTRA_SKIP_MODE_K0033
227      curCost += m_cCUDISFlagSCModel.calcCost         ( curSliceType, qp, (UChar*)INIT_DIS_FLAG );
228      curCost += m_cCUDISTypeSCModel.calcCost         ( curSliceType, qp, (UChar*)INIT_DIS_TYPE );
229#else
230#if H_3D_SINGLE_DEPTH
231      curCost += m_cCUSingleDepthFlagSCModel.calcCost        ( curSliceType, qp, (UChar*)INIT_SINGLEDEPTH_FLAG );
232      curCost += m_cSingleDepthValueSCModel.calcCost         ( curSliceType, qp, (UChar*)INIT_SINGLE_DEPTH_VALUE_DATA );
233#endif
234#endif
235      curCost += m_cCUMergeFlagExtSCModel.calcCost    ( curSliceType, qp, (UChar*)INIT_MERGE_FLAG_EXT);
236      curCost += m_cCUMergeIdxExtSCModel.calcCost     ( curSliceType, qp, (UChar*)INIT_MERGE_IDX_EXT);
237#if H_3D_ARP
238      curCost += m_cCUPUARPWSCModel.calcCost          ( curSliceType, qp, (UChar*)INIT_ARPW );
239#endif
240#if H_3D_IC
241      curCost += m_cCUICFlagSCModel.calcCost          ( curSliceType, qp, (UChar*)INIT_IC_FLAG );
242#endif
243#if H_3D_DIM_SDC
244      curCost += m_cSDCFlagSCModel.calcCost           ( curSliceType, qp, (UChar*)INIT_SDC_FLAG );
245#endif
246#if H_3D_DBBP
247      curCost += m_cDBBPFlagSCModel.calcCost          ( curSliceType, qp, (UChar*)INIT_DBBP_FLAG );
248#endif
249      curCost += m_cCUPartSizeSCModel.calcCost        ( curSliceType, qp, (UChar*)INIT_PART_SIZE );
250      curCost += m_cCUPredModeSCModel.calcCost        ( curSliceType, qp, (UChar*)INIT_PRED_MODE );
251      curCost += m_cCUIntraPredSCModel.calcCost       ( curSliceType, qp, (UChar*)INIT_INTRA_PRED_MODE );
252      curCost += m_cCUChromaPredSCModel.calcCost      ( curSliceType, qp, (UChar*)INIT_CHROMA_PRED_MODE );
253      curCost += m_cCUInterDirSCModel.calcCost        ( curSliceType, qp, (UChar*)INIT_INTER_DIR );
254      curCost += m_cCUMvdSCModel.calcCost             ( curSliceType, qp, (UChar*)INIT_MVD );
255      curCost += m_cCURefPicSCModel.calcCost          ( curSliceType, qp, (UChar*)INIT_REF_PIC );
256      curCost += m_cCUDeltaQpSCModel.calcCost         ( curSliceType, qp, (UChar*)INIT_DQP );
257      curCost += m_cCUQtCbfSCModel.calcCost           ( curSliceType, qp, (UChar*)INIT_QT_CBF );
258      curCost += m_cCUQtRootCbfSCModel.calcCost       ( curSliceType, qp, (UChar*)INIT_QT_ROOT_CBF );
259      curCost += m_cCUSigCoeffGroupSCModel.calcCost   ( curSliceType, qp, (UChar*)INIT_SIG_CG_FLAG );
260      curCost += m_cCUSigSCModel.calcCost             ( curSliceType, qp, (UChar*)INIT_SIG_FLAG );
261      curCost += m_cCuCtxLastX.calcCost               ( curSliceType, qp, (UChar*)INIT_LAST );
262      curCost += m_cCuCtxLastY.calcCost               ( curSliceType, qp, (UChar*)INIT_LAST );
263      curCost += m_cCUOneSCModel.calcCost             ( curSliceType, qp, (UChar*)INIT_ONE_FLAG );
264      curCost += m_cCUAbsSCModel.calcCost             ( curSliceType, qp, (UChar*)INIT_ABS_FLAG );
265      curCost += m_cMVPIdxSCModel.calcCost            ( curSliceType, qp, (UChar*)INIT_MVP_IDX );
266      curCost += m_cCUTransSubdivFlagSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_TRANS_SUBDIV_FLAG );
267      curCost += m_cSaoMergeSCModel.calcCost      ( curSliceType, qp, (UChar*)INIT_SAO_MERGE_FLAG );
268      curCost += m_cSaoTypeIdxSCModel.calcCost        ( curSliceType, qp, (UChar*)INIT_SAO_TYPE_IDX );
269      curCost += m_cTransformSkipSCModel.calcCost     ( curSliceType, qp, (UChar*)INIT_TRANSFORMSKIP_FLAG );
270      curCost += m_CUTransquantBypassFlagSCModel.calcCost( curSliceType, qp, (UChar*)INIT_CU_TRANSQUANT_BYPASS_FLAG );
271#if H_3D_DIM
272    if( m_pcSlice->getIntraSdcWedgeFlag() || m_pcSlice->getIntraContourFlag() )
273    {
274      curCost += m_cDepthIntraModeSCModel.calcCost    ( curSliceType, qp, (UChar*)INIT_DEPTH_INTRA_MODE );
275      curCost += m_cDdcFlagSCModel.calcCost           ( curSliceType, qp, (UChar*)INIT_DDC_FLAG );
276      curCost += m_cDdcDataSCModel.calcCost           ( curSliceType, qp, (UChar*)INIT_DDC_DATA );
277      curCost += m_cAngleFlagSCModel.calcCost         ( curSliceType, qp, (UChar*)INIT_ANGLE_FLAG ); 
278    }
279#endif
280      if (curCost < bestCost)
281      {
282        bestSliceType = curSliceType;
283        bestCost      = curCost;
284      }
285    }
286    m_pcSlice->getPPS()->setEncCABACTableIdx( bestSliceType );
287  }
288  else
289  {
290    m_pcSlice->getPPS()->setEncCABACTableIdx( I_SLICE );
291  } 
292}
293
294
295/** The function does the followng: Write out terminate bit. Flush CABAC. Intialize CABAC states. Start CABAC.
296 */
297Void TEncSbac::updateContextTables( SliceType eSliceType, Int iQp, Bool bExecuteFinish )
298{
299  m_pcBinIf->encodeBinTrm(1);
300  if (bExecuteFinish) m_pcBinIf->finish();
301  m_cCUSplitFlagSCModel.initBuffer       ( eSliceType, iQp, (UChar*)INIT_SPLIT_FLAG );
302 
303  m_cCUSkipFlagSCModel.initBuffer        ( eSliceType, iQp, (UChar*)INIT_SKIP_FLAG );
304#if SEC_DEPTH_INTRA_SKIP_MODE_K0033
305  m_cCUDISFlagSCModel.initBuffer         ( eSliceType, iQp, (UChar*)INIT_DIS_FLAG );
306  m_cCUDISTypeSCModel.initBuffer         ( eSliceType, iQp, (UChar*)INIT_DIS_TYPE );
307#else
308#if H_3D_SINGLE_DEPTH
309  m_cCUSingleDepthFlagSCModel.initBuffer        ( eSliceType, iQp, (UChar*)INIT_SINGLEDEPTH_FLAG );
310  m_cSingleDepthValueSCModel.initBuffer         ( eSliceType, iQp, (UChar*)INIT_SINGLE_DEPTH_VALUE_DATA );
311#endif
312#endif
313  m_cCUMergeFlagExtSCModel.initBuffer    ( eSliceType, iQp, (UChar*)INIT_MERGE_FLAG_EXT);
314  m_cCUMergeIdxExtSCModel.initBuffer     ( eSliceType, iQp, (UChar*)INIT_MERGE_IDX_EXT);
315#if H_3D_ARP
316  m_cCUPUARPWSCModel.initBuffer          ( eSliceType, iQp, (UChar*)INIT_ARPW );
317#endif
318#if H_3D_IC
319  m_cCUICFlagSCModel.initBuffer          ( eSliceType, iQp, (UChar*)INIT_IC_FLAG );
320#endif
321  m_cCUPartSizeSCModel.initBuffer        ( eSliceType, iQp, (UChar*)INIT_PART_SIZE );
322  m_cCUPredModeSCModel.initBuffer        ( eSliceType, iQp, (UChar*)INIT_PRED_MODE );
323  m_cCUIntraPredSCModel.initBuffer       ( eSliceType, iQp, (UChar*)INIT_INTRA_PRED_MODE );
324  m_cCUChromaPredSCModel.initBuffer      ( eSliceType, iQp, (UChar*)INIT_CHROMA_PRED_MODE );
325  m_cCUInterDirSCModel.initBuffer        ( eSliceType, iQp, (UChar*)INIT_INTER_DIR );
326  m_cCUMvdSCModel.initBuffer             ( eSliceType, iQp, (UChar*)INIT_MVD );
327  m_cCURefPicSCModel.initBuffer          ( eSliceType, iQp, (UChar*)INIT_REF_PIC );
328  m_cCUDeltaQpSCModel.initBuffer         ( eSliceType, iQp, (UChar*)INIT_DQP );
329  m_cCUQtCbfSCModel.initBuffer           ( eSliceType, iQp, (UChar*)INIT_QT_CBF );
330  m_cCUQtRootCbfSCModel.initBuffer       ( eSliceType, iQp, (UChar*)INIT_QT_ROOT_CBF );
331  m_cCUSigCoeffGroupSCModel.initBuffer   ( eSliceType, iQp, (UChar*)INIT_SIG_CG_FLAG );
332  m_cCUSigSCModel.initBuffer             ( eSliceType, iQp, (UChar*)INIT_SIG_FLAG );
333  m_cCuCtxLastX.initBuffer               ( eSliceType, iQp, (UChar*)INIT_LAST );
334  m_cCuCtxLastY.initBuffer               ( eSliceType, iQp, (UChar*)INIT_LAST );
335  m_cCUOneSCModel.initBuffer             ( eSliceType, iQp, (UChar*)INIT_ONE_FLAG );
336  m_cCUAbsSCModel.initBuffer             ( eSliceType, iQp, (UChar*)INIT_ABS_FLAG );
337  m_cMVPIdxSCModel.initBuffer            ( eSliceType, iQp, (UChar*)INIT_MVP_IDX );
338  m_cCUTransSubdivFlagSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_TRANS_SUBDIV_FLAG );
339  m_cSaoMergeSCModel.initBuffer      ( eSliceType, iQp, (UChar*)INIT_SAO_MERGE_FLAG );
340  m_cSaoTypeIdxSCModel.initBuffer        ( eSliceType, iQp, (UChar*)INIT_SAO_TYPE_IDX );
341  m_cTransformSkipSCModel.initBuffer     ( eSliceType, iQp, (UChar*)INIT_TRANSFORMSKIP_FLAG );
342  m_CUTransquantBypassFlagSCModel.initBuffer( eSliceType, iQp, (UChar*)INIT_CU_TRANSQUANT_BYPASS_FLAG );
343#if H_3D_DIM
344  m_cDepthIntraModeSCModel.initBuffer    ( eSliceType, iQp, (UChar*)INIT_DEPTH_INTRA_MODE );
345  m_cDdcFlagSCModel.initBuffer           ( eSliceType, iQp, (UChar*)INIT_DDC_FLAG );
346  m_cDdcDataSCModel.initBuffer           ( eSliceType, iQp, (UChar*)INIT_DDC_DATA );
347  m_cAngleFlagSCModel.initBuffer         ( eSliceType, iQp, (UChar*)INIT_ANGLE_FLAG );
348#if H_3D_DIM_SDC
349  m_cSDCResidualFlagSCModel.initBuffer   ( eSliceType, iQp, (UChar*)INIT_SDC_RESIDUAL_FLAG );
350  m_cSDCResidualSCModel.initBuffer       ( eSliceType, iQp, (UChar*)INIT_SDC_RESIDUAL );
351#endif
352#endif
353#if H_3D_DIM_SDC
354  m_cSDCFlagSCModel.initBuffer              ( eSliceType, iQp, (UChar*)INIT_SDC_FLAG );
355#endif
356#if H_3D_DBBP
357  m_cDBBPFlagSCModel.initBuffer              ( eSliceType, iQp, (UChar*)INIT_DBBP_FLAG );
358#endif
359  m_pcBinIf->start();
360}
361
362Void TEncSbac::codeVPS( TComVPS* pcVPS )
363{
364  assert (0);
365  return;
366}
367
368Void TEncSbac::codeSPS( TComSPS* pcSPS )
369{
370  assert (0);
371  return;
372}
373
374Void TEncSbac::codePPS( TComPPS* pcPPS )
375{
376  assert (0);
377  return;
378}
379
380Void TEncSbac::codeSliceHeader( TComSlice* pcSlice )
381{
382  assert (0);
383  return;
384}
385
386Void TEncSbac::codeTilesWPPEntryPoint( TComSlice* pSlice )
387{
388  assert (0);
389  return;
390}
391
392Void TEncSbac::codeTerminatingBit( UInt uilsLast )
393{
394  m_pcBinIf->encodeBinTrm( uilsLast );
395}
396
397Void TEncSbac::codeSliceFinish()
398{
399  m_pcBinIf->finish();
400}
401
402Void TEncSbac::xWriteUnarySymbol( UInt uiSymbol, ContextModel* pcSCModel, Int iOffset )
403{
404  m_pcBinIf->encodeBin( uiSymbol ? 1 : 0, pcSCModel[0] );
405 
406  if( 0 == uiSymbol)
407  {
408    return;
409  }
410 
411  while( uiSymbol-- )
412  {
413    m_pcBinIf->encodeBin( uiSymbol ? 1 : 0, pcSCModel[ iOffset ] );
414  }
415 
416  return;
417}
418
419Void TEncSbac::xWriteUnaryMaxSymbol( UInt uiSymbol, ContextModel* pcSCModel, Int iOffset, UInt uiMaxSymbol )
420{
421  if (uiMaxSymbol == 0)
422  {
423    return;
424  }
425 
426  m_pcBinIf->encodeBin( uiSymbol ? 1 : 0, pcSCModel[ 0 ] );
427 
428  if ( uiSymbol == 0 )
429  {
430    return;
431  }
432 
433  Bool bCodeLast = ( uiMaxSymbol > uiSymbol );
434 
435  while( --uiSymbol )
436  {
437    m_pcBinIf->encodeBin( 1, pcSCModel[ iOffset ] );
438  }
439  if( bCodeLast )
440  {
441    m_pcBinIf->encodeBin( 0, pcSCModel[ iOffset ] );
442  }
443 
444  return;
445}
446
447Void TEncSbac::xWriteEpExGolomb( UInt uiSymbol, UInt uiCount )
448{
449  UInt bins = 0;
450  Int numBins = 0;
451 
452  while( uiSymbol >= (UInt)(1<<uiCount) )
453  {
454    bins = 2 * bins + 1;
455    numBins++;
456    uiSymbol -= 1 << uiCount;
457    uiCount  ++;
458  }
459  bins = 2 * bins + 0;
460  numBins++;
461 
462  bins = (bins << uiCount) | uiSymbol;
463  numBins += uiCount;
464 
465  assert( numBins <= 32 );
466  m_pcBinIf->encodeBinsEP( bins, numBins );
467}
468
469#if SEC_DEPTH_INTRA_SKIP_MODE_K0033
470Void TEncSbac::codeDIS( TComDataCU* pcCU, UInt uiAbsPartIdx )
471{
472  UInt uiSymbol = pcCU->getDISFlag(uiAbsPartIdx ) ? 1 : 0;
473  m_pcBinIf->encodeBin( uiSymbol, m_cCUDISFlagSCModel.get( 0, 0, 0 ) );
474  if(uiSymbol)
475  {
476    UInt uiUnaryIdx = (UInt) pcCU->getDISType(uiAbsPartIdx);
477    UInt uiNumCand  = 4;
478
479    if ( uiNumCand > 1 )
480    {
481      for( UInt ui = 0; ui < uiNumCand - 1; ++ui )
482      {
483        const UInt uiSymbol2 = ui == uiUnaryIdx ? 0 : 1;
484        if ( ui == 0 )
485        {
486          m_pcBinIf->encodeBin( uiSymbol2, m_cCUDISTypeSCModel.get( 0, 0, 0 ) );
487        }
488        else
489        {
490          m_pcBinIf->encodeBinEP( uiSymbol2 );
491        }
492        if( uiSymbol2 == 0 )
493        {
494          break;
495        }
496      }
497    }
498  }
499}
500#else
501#if H_3D_SINGLE_DEPTH
502Void TEncSbac::codeSingleDepthMode( TComDataCU* pcCU, UInt uiAbsPartIdx )
503{
504  UInt uiSymbol = pcCU->getSingleDepthFlag(uiAbsPartIdx ) ? 1 : 0;
505  m_pcBinIf->encodeBin( uiSymbol, m_cCUSingleDepthFlagSCModel.get( 0, 0, 0 ) );
506  if(uiSymbol)
507  {
508    UInt uiUnaryIdx = (UInt) pcCU->getSingleDepthValue(uiAbsPartIdx);
509    UInt uiNumCand = SINGLE_DEPTH_MODE_CAND_LIST_SIZE;
510    if ( uiNumCand > 1 )
511    {
512      for( UInt ui = 0; ui < uiNumCand - 1; ++ui )
513      {
514        const UInt uiSymbol2 = ui == uiUnaryIdx ? 0 : 1;
515        if ( ui==0 )
516        {
517          m_pcBinIf->encodeBin( uiSymbol2, m_cSingleDepthValueSCModel.get( 0, 0, 0 ) );
518        }
519        else
520        {
521          m_pcBinIf->encodeBinEP( uiSymbol2 );
522        }
523        if( uiSymbol2 == 0 )
524        {
525          break;
526        }
527      }
528    }
529  }
530}
531#endif
532#endif
533
534/** Coding of coeff_abs_level_minus3
535 * \param uiSymbol value of coeff_abs_level_minus3
536 * \param ruiGoRiceParam reference to Rice parameter
537 * \returns Void
538 */
539Void TEncSbac::xWriteCoefRemainExGolomb ( UInt symbol, UInt &rParam )
540{
541  Int codeNumber  = (Int)symbol;
542  UInt length;
543  if (codeNumber < (COEF_REMAIN_BIN_REDUCTION << rParam))
544  {
545    length = codeNumber>>rParam;
546    m_pcBinIf->encodeBinsEP( (1<<(length+1))-2 , length+1);
547    m_pcBinIf->encodeBinsEP((codeNumber%(1<<rParam)),rParam);
548  }
549  else
550  {
551    length = rParam;
552    codeNumber  = codeNumber - ( COEF_REMAIN_BIN_REDUCTION << rParam);
553    while (codeNumber >= (1<<length))
554    {
555      codeNumber -=  (1<<(length++));   
556    }
557    m_pcBinIf->encodeBinsEP((1<<(COEF_REMAIN_BIN_REDUCTION+length+1-rParam))-2,COEF_REMAIN_BIN_REDUCTION+length+1-rParam);
558    m_pcBinIf->encodeBinsEP(codeNumber,length);
559  }
560}
561
562#if H_3D_DIM
563Void TEncSbac::xWriteExGolombLevel( UInt uiSymbol, ContextModel& rcSCModel  )
564{
565  if( uiSymbol )
566  {
567    m_pcBinIf->encodeBin( 1, rcSCModel );
568    UInt uiCount = 0;
569    Bool bNoExGo = ( uiSymbol < 3 );
570
571    while( --uiSymbol && ++uiCount < 3 )
572    {
573      m_pcBinIf->encodeBin( 1, rcSCModel );
574    }
575    if( bNoExGo )
576    {
577      m_pcBinIf->encodeBin( 0, rcSCModel );
578    }
579    else
580    {
581      xWriteEpExGolomb( uiSymbol, 0 );
582    }
583  }
584  else
585  {
586    m_pcBinIf->encodeBin( 0, rcSCModel );
587  }
588
589  return;
590}
591
592Void TEncSbac::xCodeDimDeltaDC( Pel valDeltaDC, UInt uiNumSeg )
593{
594  xWriteExGolombLevel( UInt( abs( valDeltaDC ) - ( uiNumSeg > 1 ? 0 : 1 ) ), m_cDdcDataSCModel.get(0, 0, 0) );
595  if( valDeltaDC != 0 )
596  {
597    UInt uiSign = valDeltaDC > 0 ? 0 : 1;
598    m_pcBinIf->encodeBinEP( uiSign );
599  }
600}
601
602#if H_3D_DIM_DMM
603Void TEncSbac::xCodeDmm1WedgeIdx( UInt uiTabIdx, Int iNumBit )
604{
605  for ( Int i = 0; i < iNumBit; i++ )
606  {
607    m_pcBinIf->encodeBinEP( ( uiTabIdx >> i ) & 1 );
608  }
609}
610
611#endif
612#endif
613
614
615// SBAC RD
616Void  TEncSbac::load ( TEncSbac* pSrc)
617{
618  this->xCopyFrom(pSrc);
619}
620
621Void  TEncSbac::loadIntraDirModeLuma( TEncSbac* pSrc)
622{
623  m_pcBinIf->copyState( pSrc->m_pcBinIf );
624 
625  this->m_cCUIntraPredSCModel      .copyFrom( &pSrc->m_cCUIntraPredSCModel       );
626}
627#if H_3D_DIM
628Void TEncSbac::loadIntraDepthMode( TEncSbac* pSrc)
629{
630  m_pcBinIf->copyState( pSrc->m_pcBinIf );
631
632  this->m_cDepthIntraModeSCModel .copyFrom( &pSrc->m_cDepthIntraModeSCModel );
633  this->m_cDdcFlagSCModel        .copyFrom( &pSrc->m_cDdcFlagSCModel );
634  this->m_cAngleFlagSCModel      .copyFrom( &pSrc->m_cAngleFlagSCModel );
635}
636#endif
637
638Void  TEncSbac::store( TEncSbac* pDest)
639{
640  pDest->xCopyFrom( this );
641}
642
643
644Void TEncSbac::xCopyFrom( TEncSbac* pSrc )
645{
646  m_pcBinIf->copyState( pSrc->m_pcBinIf );
647 
648  this->m_uiCoeffCost = pSrc->m_uiCoeffCost;
649  this->m_uiLastQp    = pSrc->m_uiLastQp;
650 
651  memcpy( m_contextModels, pSrc->m_contextModels, m_numContextModels * sizeof( ContextModel ) );
652}
653
654Void TEncSbac::codeMVPIdx ( TComDataCU* pcCU, UInt uiAbsPartIdx, RefPicList eRefList )
655{
656  Int iSymbol = pcCU->getMVPIdx(eRefList, uiAbsPartIdx);
657  Int iNum = AMVP_MAX_NUM_CANDS;
658
659  xWriteUnaryMaxSymbol(iSymbol, m_cMVPIdxSCModel.get(0), 1, iNum-1);
660#if H_MV_ENC_DEC_TRAC
661#if ENC_DEC_TRACE
662  if ( eRefList == REF_PIC_LIST_0 )
663  {
664    DTRACE_PU("mvp_l0_flag", iSymbol)
665  }
666  else
667  {
668    DTRACE_PU("mvp_l1_flag", iSymbol)
669  }
670#endif
671#endif
672}
673
674Void TEncSbac::codePartSize( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
675{
676  PartSize eSize         = pcCU->getPartitionSize( uiAbsPartIdx );
677#if H_3D_QTLPC
678  Bool    bLimQtPredFlag = pcCU->getPic()->getSlice(0)->getQtPredFlag();
679  TComPic *pcTexture     = pcCU->getSlice()->getTexturePic();
680  Bool bDepthMapDetect   = (pcTexture != NULL);
681  Bool bIntraSliceDetect = (pcCU->getSlice()->getSliceType() == I_SLICE);
682 
683  Bool rapPic     = (pcCU->getSlice()->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_W_RADL || pcCU->getSlice()->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_N_LP || pcCU->getSlice()->getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA);
684
685  Bool depthDependent = false;
686  UInt uiTexturePart = eSize;
687
688#if H_3D_FCO
689  if(bDepthMapDetect && !bIntraSliceDetect && !rapPic && pcCU->getPic()->getReduceBitsFlag() && bLimQtPredFlag && pcTexture->getReconMark())
690#else
691  if(bDepthMapDetect && !bIntraSliceDetect && !rapPic && pcCU->getPic()->getReduceBitsFlag() && bLimQtPredFlag )
692#endif
693  {
694    TComDataCU *pcTextureCU = pcTexture->getCU(pcCU->getAddr());
695    UInt uiCUIdx            = (pcCU->getZorderIdxInCU() == 0) ? uiAbsPartIdx : pcCU->getZorderIdxInCU();
696    assert(pcTextureCU->getDepth(uiCUIdx) >= uiDepth);
697    if(pcTextureCU->getDepth(uiCUIdx) == uiDepth )
698    {
699      depthDependent = true;
700      uiTexturePart = pcTextureCU->getPartitionSize( uiCUIdx );
701    }
702    if (pcTextureCU->getDepth(uiCUIdx) == uiDepth && pcTextureCU->getPartitionSize( uiCUIdx ) == SIZE_2Nx2N)
703    {
704      assert( eSize == SIZE_2Nx2N );
705      return;
706    }
707  }
708#endif
709  if ( pcCU->isIntra( uiAbsPartIdx ) )
710  {
711    if( uiDepth == g_uiMaxCUDepth - g_uiAddCUDepth )
712    {
713      m_pcBinIf->encodeBin( eSize == SIZE_2Nx2N? 1 : 0, m_cCUPartSizeSCModel.get( 0, 0, 0 ) );
714#if H_MV_ENC_DEC_TRAC
715      DTRACE_CU("part_mode", eSize == SIZE_2Nx2N? 1 : 0)
716#endif       
717    }
718    return;
719  }
720 
721#if H_MV_ENC_DEC_TRAC         
722  DTRACE_CU("part_mode", eSize )
723#endif       
724#if H_3D_QTLPC
725    if (depthDependent==false || uiTexturePart == SIZE_NxN|| uiTexturePart == SIZE_2Nx2N)
726    {
727#endif
728  switch(eSize)
729  {
730    case SIZE_2Nx2N:
731    {
732      m_pcBinIf->encodeBin( 1, m_cCUPartSizeSCModel.get( 0, 0, 0) );
733      break;
734    }
735    case SIZE_2NxN:
736    case SIZE_2NxnU:
737    case SIZE_2NxnD:
738    {
739      m_pcBinIf->encodeBin( 0, m_cCUPartSizeSCModel.get( 0, 0, 0) );
740      m_pcBinIf->encodeBin( 1, m_cCUPartSizeSCModel.get( 0, 0, 1) );
741      if ( pcCU->getSlice()->getSPS()->getAMPAcc( uiDepth ) )
742      {
743        if (eSize == SIZE_2NxN)
744        {
745          m_pcBinIf->encodeBin(1, m_cCUPartSizeSCModel.get( 0, 0, 3 ));
746        }
747        else
748        {
749          m_pcBinIf->encodeBin(0, m_cCUPartSizeSCModel.get( 0, 0, 3 ));
750          m_pcBinIf->encodeBinEP((eSize == SIZE_2NxnU? 0: 1));
751        }
752      }
753      break;
754    }
755    case SIZE_Nx2N:
756    case SIZE_nLx2N:
757    case SIZE_nRx2N:
758    {
759      m_pcBinIf->encodeBin( 0, m_cCUPartSizeSCModel.get( 0, 0, 0) );
760      m_pcBinIf->encodeBin( 0, m_cCUPartSizeSCModel.get( 0, 0, 1) );
761      if( uiDepth == g_uiMaxCUDepth - g_uiAddCUDepth && !( pcCU->getWidth(uiAbsPartIdx) == 8 && pcCU->getHeight(uiAbsPartIdx) == 8 ) )
762      {
763        m_pcBinIf->encodeBin( 1, m_cCUPartSizeSCModel.get( 0, 0, 2) );
764      }
765      if ( pcCU->getSlice()->getSPS()->getAMPAcc( uiDepth ) )
766      {
767        if (eSize == SIZE_Nx2N)
768        {
769          m_pcBinIf->encodeBin(1, m_cCUPartSizeSCModel.get( 0, 0, 3 ));
770        }
771        else
772        {
773          m_pcBinIf->encodeBin(0, m_cCUPartSizeSCModel.get( 0, 0, 3 ));
774          m_pcBinIf->encodeBinEP((eSize == SIZE_nLx2N? 0: 1));
775        }
776      }
777      break;
778    }
779    case SIZE_NxN:
780    {
781      if( uiDepth == g_uiMaxCUDepth - g_uiAddCUDepth && !( pcCU->getWidth(uiAbsPartIdx) == 8 && pcCU->getHeight(uiAbsPartIdx) == 8 ) )
782      {
783        m_pcBinIf->encodeBin( 0, m_cCUPartSizeSCModel.get( 0, 0, 0) );
784        m_pcBinIf->encodeBin( 0, m_cCUPartSizeSCModel.get( 0, 0, 1) );
785        m_pcBinIf->encodeBin( 0, m_cCUPartSizeSCModel.get( 0, 0, 2) );
786      }
787      break;
788    }
789    default:
790    {
791      assert(0);
792    }
793  }
794#if H_3D_QTLPC
795    }
796    else if(uiTexturePart == SIZE_2NxN || uiTexturePart == SIZE_2NxnU || uiTexturePart == SIZE_2NxnD)
797    {
798      //assert(eSize!=SIZE_NxN);
799      //assert(eSize!=SIZE_Nx2N);
800      //assert(eSize==SIZE_2Nx2N || eSize==SIZE_2NxN || eSize==SIZE_2NxnU || eSize==SIZE_2NxnD);
801      switch(eSize)
802      {
803      case SIZE_2Nx2N:
804        {
805          m_pcBinIf->encodeBin( 1, m_cCUPartSizeSCModel.get( 0, 0, 0) );
806          break;
807        }
808      case SIZE_2NxN:
809        {
810          m_pcBinIf->encodeBin( 0, m_cCUPartSizeSCModel.get( 0, 0, 0) );
811          if ( pcCU->getSlice()->getSPS()->getAMPAcc( uiDepth ) )
812          {     
813            m_pcBinIf->encodeBin( 1, m_cCUPartSizeSCModel.get( 0, 0, 1) );
814          }
815          break;
816        }
817      case SIZE_2NxnU:
818      case SIZE_2NxnD:
819        {
820          m_pcBinIf->encodeBin( 0, m_cCUPartSizeSCModel.get( 0, 0, 0) );
821          m_pcBinIf->encodeBin( 0, m_cCUPartSizeSCModel.get( 0, 0, 1) );
822          m_pcBinIf->encodeBinEP((eSize == SIZE_2NxnU? 0: 1));
823          break;
824        }
825      default:
826        {
827          assert(0);
828        }
829      }
830    }
831    else if(uiTexturePart == SIZE_Nx2N|| uiTexturePart==SIZE_nLx2N || uiTexturePart==SIZE_nRx2N)
832    {
833      //assert(eSize!=SIZE_NxN);
834      //assert(eSize!=SIZE_2NxN);
835      //assert(eSize==SIZE_2Nx2N ||eSize==SIZE_Nx2N || eSize==SIZE_nLx2N || eSize==SIZE_nRx2N);
836      switch(eSize)
837      {
838      case SIZE_2Nx2N:
839        {
840          m_pcBinIf->encodeBin( 1, m_cCUPartSizeSCModel.get( 0, 0, 0) );
841          break;
842        }
843      case SIZE_Nx2N:
844        {
845          m_pcBinIf->encodeBin( 0, m_cCUPartSizeSCModel.get( 0, 0, 0) );
846          if ( pcCU->getSlice()->getSPS()->getAMPAcc( uiDepth ) )
847          {     
848            m_pcBinIf->encodeBin( 1, m_cCUPartSizeSCModel.get( 0, 0, 1) );
849          }
850          break;
851        }
852      case SIZE_nLx2N:
853      case SIZE_nRx2N:
854        {
855          m_pcBinIf->encodeBin( 0, m_cCUPartSizeSCModel.get( 0, 0, 0) );
856          m_pcBinIf->encodeBin( 0, m_cCUPartSizeSCModel.get( 0, 0, 1) );
857          m_pcBinIf->encodeBinEP((eSize == SIZE_nLx2N? 0: 1));
858          break;
859        }
860      default:
861        {
862          assert(0);
863        }
864      }
865    }
866    else
867    {
868      printf("uiTexturePart=%d",uiTexturePart);
869      assert(0);
870    }
871#endif
872}
873
874/** code prediction mode
875 * \param pcCU
876 * \param uiAbsPartIdx 
877 * \returns Void
878 */
879Void TEncSbac::codePredMode( TComDataCU* pcCU, UInt uiAbsPartIdx )
880{
881#if H_3D_DIM_SDC
882  if ( pcCU->getSlice()->isIntra() )
883  {
884    assert( pcCU->isIntra(uiAbsPartIdx) );
885    return;
886  }
887#endif
888 
889  // get context function is here
890  Int iPredMode = pcCU->getPredictionMode( uiAbsPartIdx );
891  m_pcBinIf->encodeBin( iPredMode == MODE_INTER ? 0 : 1, m_cCUPredModeSCModel.get( 0, 0, 0 ) );
892#if H_MV_ENC_DEC_TRAC
893  DTRACE_CU("pred_mode_flag", iPredMode == MODE_INTER ? 0 : 1); 
894#endif
895}
896
897Void TEncSbac::codeCUTransquantBypassFlag( TComDataCU* pcCU, UInt uiAbsPartIdx )
898{
899  UInt uiSymbol = pcCU->getCUTransquantBypass(uiAbsPartIdx);
900  m_pcBinIf->encodeBin( uiSymbol, m_CUTransquantBypassFlagSCModel.get( 0, 0, 0 ) );
901#if H_MV_ENC_DEC_TRAC
902  DTRACE_CU("cu_transquant_bypass_flag", uiSymbol); 
903#endif
904}
905
906/** code skip flag
907 * \param pcCU
908 * \param uiAbsPartIdx
909 * \returns Void
910 */
911Void TEncSbac::codeSkipFlag( TComDataCU* pcCU, UInt uiAbsPartIdx )
912{
913  // get context function is here
914  UInt uiSymbol = pcCU->isSkipped( uiAbsPartIdx ) ? 1 : 0;
915  UInt uiCtxSkip = pcCU->getCtxSkipFlag( uiAbsPartIdx ) ;
916  m_pcBinIf->encodeBin( uiSymbol, m_cCUSkipFlagSCModel.get( 0, 0, uiCtxSkip ) );
917#if !H_MV_ENC_DEC_TRAC
918  DTRACE_CABAC_VL( g_nSymbolCounter++ );
919  DTRACE_CABAC_T( "\tSkipFlag" );
920  DTRACE_CABAC_T( "\tuiCtxSkip: ");
921  DTRACE_CABAC_V( uiCtxSkip );
922  DTRACE_CABAC_T( "\tuiSymbol: ");
923  DTRACE_CABAC_V( uiSymbol );
924  DTRACE_CABAC_T( "\n");
925#else
926  DTRACE_CU("cu_skip_flag", uiSymbol); 
927#endif
928}
929
930/** code merge flag
931 * \param pcCU
932 * \param uiAbsPartIdx
933 * \returns Void
934 */
935Void TEncSbac::codeMergeFlag( TComDataCU* pcCU, UInt uiAbsPartIdx )
936{
937  const UInt uiSymbol = pcCU->getMergeFlag( uiAbsPartIdx ) ? 1 : 0;
938  m_pcBinIf->encodeBin( uiSymbol, *m_cCUMergeFlagExtSCModel.get( 0 ) );
939
940#if H_MV_ENC_DEC_TRAC
941  DTRACE_PU("merge_flag", uiSymbol); 
942#else
943  DTRACE_CABAC_VL( g_nSymbolCounter++ );
944  DTRACE_CABAC_T( "\tMergeFlag: " );
945  DTRACE_CABAC_V( uiSymbol );
946  DTRACE_CABAC_T( "\tAddress: " );
947  DTRACE_CABAC_V( pcCU->getAddr() );
948  DTRACE_CABAC_T( "\tuiAbsPartIdx: " );
949  DTRACE_CABAC_V( uiAbsPartIdx );
950  DTRACE_CABAC_T( "\n" );
951#endif
952}
953
954/** code merge index
955 * \param pcCU
956 * \param uiAbsPartIdx
957 * \returns Void
958 */
959Void TEncSbac::codeMergeIndex( TComDataCU* pcCU, UInt uiAbsPartIdx )
960{
961  UInt uiUnaryIdx = pcCU->getMergeIndex( uiAbsPartIdx );
962  UInt uiNumCand = pcCU->getSlice()->getMaxNumMergeCand();
963  if ( uiNumCand > 1 )
964  {
965    for( UInt ui = 0; ui < uiNumCand - 1; ++ui )
966    {
967      const UInt uiSymbol = ui == uiUnaryIdx ? 0 : 1;
968      if ( ui==0 )
969      {
970        m_pcBinIf->encodeBin( uiSymbol, m_cCUMergeIdxExtSCModel.get( 0, 0, 0 ) );
971      }
972      else
973      {
974        m_pcBinIf->encodeBinEP( uiSymbol );
975      }
976      if( uiSymbol == 0 )
977      {
978        break;
979      }
980    }
981#if H_MV_ENC_DEC_TRAC
982    DTRACE_PU("merge_idx", uiUnaryIdx); 
983#endif
984  }
985#if !H_MV_ENC_DEC_TRAC
986  DTRACE_CABAC_VL( g_nSymbolCounter++ );
987  DTRACE_CABAC_T( "\tparseMergeIndex()" );
988  DTRACE_CABAC_T( "\tuiMRGIdx= " );
989  DTRACE_CABAC_V( pcCU->getMergeIndex( uiAbsPartIdx ) );
990  DTRACE_CABAC_T( "\n" );
991#endif
992}
993
994#if H_3D_ARP
995Void TEncSbac::codeARPW( TComDataCU* pcCU, UInt uiAbsPartIdx )
996{
997  Int  iW = (Int)pcCU->getARPW( uiAbsPartIdx );
998  Int  iMaxW = pcCU->getSlice()->getARPStepNum() - 1;
999  assert( iMaxW > 0);
1000
1001  Int nOffset = pcCU->getCTXARPWFlag(uiAbsPartIdx);
1002  Int nBinNum = iW + ( iW != iMaxW );
1003  m_pcBinIf->encodeBin( iW ? 1 : 0 , m_cCUPUARPWSCModel.get( 0, 0, 0 + nOffset ) );
1004  if( nBinNum > 1 )
1005  {
1006     m_pcBinIf->encodeBin( ( iW == iMaxW ) ? 1 : 0, m_cCUPUARPWSCModel.get( 0, 0, 2 ) );
1007  }
1008#if H_MV_ENC_DEC_TRAC
1009  DTRACE_CU("iv_res_pred_weight_idx", iW); 
1010#endif
1011}
1012#endif
1013
1014#if H_3D_IC
1015/** code Illumination Compensation flag
1016 * \param pcCU
1017 * \param uiAbsPartIdx
1018 * \returns Void
1019 */
1020Void TEncSbac::codeICFlag( TComDataCU* pcCU, UInt uiAbsPartIdx )
1021{
1022  // get context function is here
1023  UInt uiSymbol = pcCU->getICFlag( uiAbsPartIdx ) ? 1 : 0;
1024  m_pcBinIf->encodeBin( uiSymbol, m_cCUICFlagSCModel.get( 0, 0, 0 ) );
1025#if !H_MV_ENC_DEC_TRAC
1026  DTRACE_CABAC_VL( g_nSymbolCounter++ );
1027  DTRACE_CABAC_T( "\tICFlag" );
1028  DTRACE_CABAC_T( "\tuiSymbol: ");
1029  DTRACE_CABAC_V( uiSymbol );
1030  DTRACE_CABAC_T( "\n");
1031#else
1032  DTRACE_CU("ic_flag", uiSymbol ); 
1033#endif
1034}
1035#endif
1036
1037
1038Void TEncSbac::codeSplitFlag   ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
1039{
1040  if( uiDepth == g_uiMaxCUDepth - g_uiAddCUDepth )
1041    return;
1042 
1043  UInt uiCtx           = pcCU->getCtxSplitFlag( uiAbsPartIdx, uiDepth );
1044  UInt uiCurrSplitFlag = ( pcCU->getDepth( uiAbsPartIdx ) > uiDepth ) ? 1 : 0;
1045 
1046  assert( uiCtx < 3 );
1047#if H_3D_QTLPC
1048  Bool bCodeSplitFlag    = true;
1049
1050 
1051  Bool    bLimQtPredFlag = pcCU->getPic()->getSlice(0)->getQtPredFlag(); 
1052  TComPic *pcTexture     = pcCU->getSlice()->getTexturePic();
1053  Bool bDepthMapDetect   = (pcTexture != NULL);
1054  Bool bIntraSliceDetect = (pcCU->getSlice()->getSliceType() == I_SLICE);
1055
1056  Bool rapPic     = (pcCU->getSlice()->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_W_RADL || pcCU->getSlice()->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_N_LP || pcCU->getSlice()->getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA);
1057
1058#if H_3D_FCO
1059  if(bDepthMapDetect && !bIntraSliceDetect && !rapPic && pcCU->getPic()->getReduceBitsFlag() && bLimQtPredFlag && pcTexture->getReconMark() )
1060#else
1061  if(bDepthMapDetect && !bIntraSliceDetect && !rapPic && pcCU->getPic()->getReduceBitsFlag() && bLimQtPredFlag  )
1062#endif
1063  {
1064    TComDataCU *pcTextureCU = pcTexture->getCU(pcCU->getAddr());
1065    UInt uiCUIdx            = (pcCU->getZorderIdxInCU() == 0) ? uiAbsPartIdx : pcCU->getZorderIdxInCU();
1066    assert(pcTextureCU->getDepth(uiCUIdx) >= uiDepth);
1067    bCodeSplitFlag          = (pcTextureCU->getDepth(uiCUIdx) > uiDepth);
1068  }
1069
1070  if(!bCodeSplitFlag)
1071  {
1072    assert(uiCurrSplitFlag == 0);
1073    return;
1074  }
1075#endif
1076  m_pcBinIf->encodeBin( uiCurrSplitFlag, m_cCUSplitFlagSCModel.get( 0, 0, uiCtx ) );
1077#if !H_MV_ENC_DEC_TRAC
1078  DTRACE_CABAC_VL( g_nSymbolCounter++ )
1079  DTRACE_CABAC_T( "\tSplitFlag\n" )
1080#else
1081  DTRACE_CU("split_cu_flag", uiCurrSplitFlag ); 
1082#endif
1083  return;
1084}
1085
1086Void TEncSbac::codeTransformSubdivFlag( UInt uiSymbol, UInt uiCtx )
1087{
1088  m_pcBinIf->encodeBin( uiSymbol, m_cCUTransSubdivFlagSCModel.get( 0, 0, uiCtx ) );
1089#if !H_MV_ENC_DEC_TRAC
1090  DTRACE_CABAC_VL( g_nSymbolCounter++ )
1091  DTRACE_CABAC_T( "\tparseTransformSubdivFlag()" )
1092  DTRACE_CABAC_T( "\tsymbol=" )
1093  DTRACE_CABAC_V( uiSymbol )
1094  DTRACE_CABAC_T( "\tctx=" )
1095  DTRACE_CABAC_V( uiCtx )
1096  DTRACE_CABAC_T( "\n" )
1097#else
1098  DTRACE_TU("split_transform_flag", uiSymbol )
1099#endif
1100
1101}
1102
1103Void TEncSbac::codeIntraDirLumaAng( TComDataCU* pcCU, UInt absPartIdx, Bool isMultiple)
1104{
1105  UInt dir[4],j;
1106  Int preds[4][3] = {{-1, -1, -1},{-1, -1, -1},{-1, -1, -1},{-1, -1, -1}};
1107  Int predNum[4], predIdx[4] ={ -1,-1,-1,-1};
1108  PartSize mode = pcCU->getPartitionSize( absPartIdx );
1109  UInt partNum = isMultiple?(mode==SIZE_NxN?4:1):1;
1110  UInt partOffset = ( pcCU->getPic()->getNumPartInCU() >> ( pcCU->getDepth(absPartIdx) << 1 ) ) >> 2;
1111  for (j=0;j<partNum;j++)
1112  {
1113    dir[j] = pcCU->getLumaIntraDir( absPartIdx+partOffset*j );
1114#if H_3D_DIM
1115    if( pcCU->getSlice()->getIntraSdcWedgeFlag() ||  pcCU->getSlice()->getIntraContourFlag() )
1116    {
1117      codeIntraDepth( pcCU, absPartIdx+partOffset*j );
1118    }
1119    if( pcCU->getLumaIntraDir( absPartIdx+partOffset*j ) < NUM_INTRA_MODE )
1120    {
1121#endif
1122      predNum[j] = pcCU->getIntraDirLumaPredictor(absPartIdx+partOffset*j, preds[j]); 
1123      for(UInt i = 0; i < predNum[j]; i++)
1124      {
1125        if(dir[j] == preds[j][i])
1126        {
1127          predIdx[j] = i;
1128        }
1129      }
1130      m_pcBinIf->encodeBin((predIdx[j] != -1)? 1 : 0, m_cCUIntraPredSCModel.get( 0, 0, 0 ) );
1131#if H_MV_ENC_DEC_TRAC
1132      DTRACE_CU("prev_intra_luma_pred_flag", (predIdx[j] != -1)? 1 : 0); 
1133#endif
1134#if H_3D_DIM
1135    }
1136#endif
1137
1138  } 
1139  for (j=0;j<partNum;j++)
1140  {
1141#if H_3D_DIM
1142    if( pcCU->getLumaIntraDir( absPartIdx+partOffset*j ) < NUM_INTRA_MODE )
1143    {
1144#endif
1145    if(predIdx[j] != -1)
1146    {
1147      m_pcBinIf->encodeBinEP( predIdx[j] ? 1 : 0 );
1148      if (predIdx[j])
1149      {
1150        m_pcBinIf->encodeBinEP( predIdx[j]-1 );
1151      }
1152#if H_MV_ENC_DEC_TRAC
1153      DTRACE_CU("mpm_idx", predIdx[j] ); 
1154#endif
1155    }
1156    else
1157    {
1158      if (preds[j][0] > preds[j][1])
1159      { 
1160        std::swap(preds[j][0], preds[j][1]); 
1161      }
1162      if (preds[j][0] > preds[j][2])
1163      {
1164        std::swap(preds[j][0], preds[j][2]);
1165      }
1166      if (preds[j][1] > preds[j][2])
1167      {
1168        std::swap(preds[j][1], preds[j][2]);
1169      }
1170      for(Int i = (predNum[j] - 1); i >= 0; i--)
1171      {
1172        dir[j] = dir[j] > preds[j][i] ? dir[j] - 1 : dir[j];
1173      }
1174      m_pcBinIf->encodeBinsEP( dir[j], 5 );
1175#if H_MV_ENC_DEC_TRAC
1176      DTRACE_CU("rem_intra_luma_pred_mode", dir[j] ); 
1177#endif
1178    }
1179#if H_3D_DIM
1180    }
1181#endif
1182  }
1183  return;
1184}
1185
1186Void TEncSbac::codeIntraDirChroma( TComDataCU* pcCU, UInt uiAbsPartIdx )
1187{
1188  UInt uiIntraDirChroma = pcCU->getChromaIntraDir( uiAbsPartIdx );
1189
1190  if( uiIntraDirChroma == DM_CHROMA_IDX ) 
1191  {
1192    m_pcBinIf->encodeBin( 0, m_cCUChromaPredSCModel.get( 0, 0, 0 ) );
1193#if H_MV_ENC_DEC_TRAC
1194    DTRACE_CU("intra_chroma_pred_mode", 0 ); 
1195#endif
1196  }
1197  else
1198  { 
1199    UInt uiAllowedChromaDir[ NUM_CHROMA_MODE ];
1200    pcCU->getAllowedChromaDir( uiAbsPartIdx, uiAllowedChromaDir );
1201
1202    for( Int i = 0; i < NUM_CHROMA_MODE - 1; i++ )
1203    {
1204      if( uiIntraDirChroma == uiAllowedChromaDir[i] )
1205      {
1206        uiIntraDirChroma = i;
1207        break;
1208      }
1209    }
1210    m_pcBinIf->encodeBin( 1, m_cCUChromaPredSCModel.get( 0, 0, 0 ) );
1211
1212    m_pcBinIf->encodeBinsEP( uiIntraDirChroma, 2 );
1213#if H_MV_ENC_DEC_TRAC
1214    DTRACE_CU("intra_chroma_pred_mode", uiIntraDirChroma ); 
1215#endif
1216
1217  }
1218  return;
1219}
1220
1221#if H_3D_DIM
1222Void TEncSbac::codeIntraDepth( TComDataCU* pcCU, UInt absPartIdx )
1223{
1224  codeIntraDepthMode( pcCU, absPartIdx );
1225
1226  UInt dir     = pcCU->getLumaIntraDir( absPartIdx );
1227  UInt dimType = getDimType( dir );
1228
1229  switch( dimType )
1230  {
1231#if H_3D_DIM_DMM
1232  case( DMM1_IDX ):
1233    {
1234      xCodeDmm1WedgeIdx( pcCU->getDmmWedgeTabIdx( dimType, absPartIdx ), g_dmm1TabIdxBits[pcCU->getIntraSizeIdx(absPartIdx)] );
1235    } break;
1236  case( DMM4_IDX ): break;
1237#endif
1238  default: break;
1239  }
1240}
1241
1242Void TEncSbac::codeIntraDepthMode( TComDataCU* pcCU, UInt absPartIdx )
1243{
1244  UInt dir = pcCU->getLumaIntraDir( absPartIdx );
1245
1246  if( ( pcCU->getSlice()->getSPS()->getMaxCUWidth() >> pcCU->getDepth( absPartIdx ) ) < 64 ) //DMM and HEVC intra modes are both allowed
1247  {
1248    m_pcBinIf->encodeBin( isDimMode( dir ) ? 0 : 1, m_cAngleFlagSCModel.get( 0, 0, 0 ) );
1249  }
1250  if( isDimMode( dir ) )
1251  {
1252    UInt uiCodeIdx = 0;
1253
1254    switch( getDimType( dir ) )
1255    {
1256    case DMM1_IDX: uiCodeIdx = 0; break;
1257    case DMM4_IDX: uiCodeIdx = 1; break;
1258    default:                      break;
1259    }
1260    //mode coding
1261    if( pcCU->getSlice()->getIntraSdcWedgeFlag() && pcCU->getSlice()->getIntraContourFlag())
1262    {
1263      m_pcBinIf->encodeBin( uiCodeIdx == 0 ? 0 : 1, m_cDepthIntraModeSCModel.get( 0, 0, 0 ) );
1264    }
1265  }
1266}
1267#endif
1268
1269
1270Void TEncSbac::codeInterDir( TComDataCU* pcCU, UInt uiAbsPartIdx )
1271{
1272  const UInt uiInterDir = pcCU->getInterDir( uiAbsPartIdx ) - 1;
1273  const UInt uiCtx      = pcCU->getCtxInterDir( uiAbsPartIdx );
1274  ContextModel *pCtx    = m_cCUInterDirSCModel.get( 0 );
1275  if (pcCU->getPartitionSize(uiAbsPartIdx) == SIZE_2Nx2N || pcCU->getHeight(uiAbsPartIdx) != 8 )
1276  {
1277    m_pcBinIf->encodeBin( uiInterDir == 2 ? 1 : 0, *( pCtx + uiCtx ) );
1278  }
1279  if (uiInterDir < 2)
1280  {
1281    m_pcBinIf->encodeBin( uiInterDir, *( pCtx + 4 ) );
1282  }
1283#if H_MV_ENC_DEC_TRAC
1284  DTRACE_PU("inter_pred_idc", uiInterDir ); 
1285#endif
1286
1287  return;
1288}
1289
1290Void TEncSbac::codeRefFrmIdx( TComDataCU* pcCU, UInt uiAbsPartIdx, RefPicList eRefList )
1291{
1292  {
1293    Int iRefFrame = pcCU->getCUMvField( eRefList )->getRefIdx( uiAbsPartIdx );
1294    ContextModel *pCtx = m_cCURefPicSCModel.get( 0 );
1295    m_pcBinIf->encodeBin( ( iRefFrame == 0 ? 0 : 1 ), *pCtx );
1296   
1297    if( iRefFrame > 0 )
1298    {
1299      UInt uiRefNum = pcCU->getSlice()->getNumRefIdx( eRefList ) - 2;
1300      pCtx++;
1301      iRefFrame--;
1302      for( UInt ui = 0; ui < uiRefNum; ++ui )
1303      {
1304        const UInt uiSymbol = ui == iRefFrame ? 0 : 1;
1305        if( ui == 0 )
1306        {
1307          m_pcBinIf->encodeBin( uiSymbol, *pCtx );       
1308        }
1309        else
1310        {
1311          m_pcBinIf->encodeBinEP( uiSymbol );
1312        }
1313        if( uiSymbol == 0 )
1314        {
1315          break;
1316        }
1317      }
1318    }
1319#if H_MV_ENC_DEC_TRAC
1320#if ENC_DEC_TRACE
1321    iRefFrame = pcCU->getCUMvField( eRefList )->getRefIdx( uiAbsPartIdx ); 
1322    if ( eRefList == REF_PIC_LIST_0 )
1323    {
1324      DTRACE_PU("ref_idx_l0", iRefFrame)
1325    }
1326    else
1327    {
1328      DTRACE_PU("ref_idx_l1", iRefFrame)
1329    }
1330#endif
1331#endif
1332  }
1333  return;
1334}
1335
1336Void TEncSbac::codeMvd( TComDataCU* pcCU, UInt uiAbsPartIdx, RefPicList eRefList )
1337{
1338  if(pcCU->getSlice()->getMvdL1ZeroFlag() && eRefList == REF_PIC_LIST_1 && pcCU->getInterDir(uiAbsPartIdx)==3)
1339  {
1340    return;
1341  }
1342
1343  const TComCUMvField* pcCUMvField = pcCU->getCUMvField( eRefList );
1344  const Int iHor = pcCUMvField->getMvd( uiAbsPartIdx ).getHor();
1345  const Int iVer = pcCUMvField->getMvd( uiAbsPartIdx ).getVer();
1346  ContextModel* pCtx = m_cCUMvdSCModel.get( 0 );
1347
1348  m_pcBinIf->encodeBin( iHor != 0 ? 1 : 0, *pCtx );
1349  m_pcBinIf->encodeBin( iVer != 0 ? 1 : 0, *pCtx );
1350
1351  const Bool bHorAbsGr0 = iHor != 0;
1352  const Bool bVerAbsGr0 = iVer != 0;
1353  const UInt uiHorAbs   = 0 > iHor ? -iHor : iHor;
1354  const UInt uiVerAbs   = 0 > iVer ? -iVer : iVer;
1355  pCtx++;
1356
1357  if( bHorAbsGr0 )
1358  {
1359    m_pcBinIf->encodeBin( uiHorAbs > 1 ? 1 : 0, *pCtx );
1360  }
1361
1362  if( bVerAbsGr0 )
1363  {
1364    m_pcBinIf->encodeBin( uiVerAbs > 1 ? 1 : 0, *pCtx );
1365  }
1366
1367  if( bHorAbsGr0 )
1368  {
1369    if( uiHorAbs > 1 )
1370    {
1371      xWriteEpExGolomb( uiHorAbs-2, 1 );
1372    }
1373
1374    m_pcBinIf->encodeBinEP( 0 > iHor ? 1 : 0 );
1375  }
1376
1377  if( bVerAbsGr0 )
1378  {
1379    if( uiVerAbs > 1 )
1380    {
1381      xWriteEpExGolomb( uiVerAbs-2, 1 );
1382    }
1383
1384    m_pcBinIf->encodeBinEP( 0 > iVer ? 1 : 0 );
1385  }
1386 
1387  return;
1388}
1389
1390Void TEncSbac::codeDeltaQP( TComDataCU* pcCU, UInt uiAbsPartIdx )
1391{
1392  Int iDQp  = pcCU->getQP( uiAbsPartIdx ) - pcCU->getRefQP( uiAbsPartIdx );
1393 
1394  Int qpBdOffsetY =  pcCU->getSlice()->getSPS()->getQpBDOffsetY();
1395  iDQp = (iDQp + 78 + qpBdOffsetY + (qpBdOffsetY/2)) % (52 + qpBdOffsetY) - 26 - (qpBdOffsetY/2);
1396
1397  UInt uiAbsDQp = (UInt)((iDQp > 0)? iDQp  : (-iDQp));
1398  UInt TUValue = min((Int)uiAbsDQp, CU_DQP_TU_CMAX);
1399  xWriteUnaryMaxSymbol( TUValue, &m_cCUDeltaQpSCModel.get( 0, 0, 0 ), 1, CU_DQP_TU_CMAX);
1400  if( uiAbsDQp >= CU_DQP_TU_CMAX )
1401  {
1402    xWriteEpExGolomb( uiAbsDQp - CU_DQP_TU_CMAX, CU_DQP_EG_k );
1403  }
1404
1405  if ( uiAbsDQp > 0)
1406  {
1407    UInt uiSign = (iDQp > 0 ? 0 : 1);
1408    m_pcBinIf->encodeBinEP(uiSign);
1409  }
1410
1411  return;
1412}
1413
1414Void TEncSbac::codeQtCbf( TComDataCU* pcCU, UInt uiAbsPartIdx, TextType eType, UInt uiTrDepth )
1415{
1416  UInt uiCbf = pcCU->getCbf     ( uiAbsPartIdx, eType, uiTrDepth );
1417  UInt uiCtx = pcCU->getCtxQtCbf( eType, uiTrDepth );
1418  m_pcBinIf->encodeBin( uiCbf , m_cCUQtCbfSCModel.get( 0, eType ? TEXT_CHROMA : eType, uiCtx ) );
1419#if !H_MV_ENC_DEC_TRAC
1420  DTRACE_CABAC_VL( g_nSymbolCounter++ )
1421  DTRACE_CABAC_T( "\tparseQtCbf()" )
1422  DTRACE_CABAC_T( "\tsymbol=" )
1423  DTRACE_CABAC_V( uiCbf )
1424  DTRACE_CABAC_T( "\tctx=" )
1425  DTRACE_CABAC_V( uiCtx )
1426  DTRACE_CABAC_T( "\tetype=" )
1427  DTRACE_CABAC_V( eType )
1428  DTRACE_CABAC_T( "\tuiAbsPartIdx=" )
1429  DTRACE_CABAC_V( uiAbsPartIdx )
1430  DTRACE_CABAC_T( "\n" )
1431#else
1432  if ( eType == TEXT_CHROMA_U )
1433  {
1434    DTRACE_TU("cbf_cb", uiCbf )
1435  }
1436  else if ( eType == TEXT_CHROMA_V )
1437  {
1438    DTRACE_TU("cbf_cr", uiCbf )
1439  }
1440  else
1441  {
1442    DTRACE_TU("cbf_luma", uiCbf )
1443  }
1444#endif
1445}
1446
1447void TEncSbac::codeTransformSkipFlags (TComDataCU* pcCU, UInt uiAbsPartIdx, UInt width, UInt height, TextType eTType )
1448{
1449  if (pcCU->getCUTransquantBypass(uiAbsPartIdx))
1450  {
1451    return;
1452  }
1453  if(width != 4 || height != 4)
1454  {
1455    return;
1456  }
1457
1458  UInt useTransformSkip = pcCU->getTransformSkip( uiAbsPartIdx,eTType);
1459  m_pcBinIf->encodeBin( useTransformSkip, m_cTransformSkipSCModel.get( 0, eTType? TEXT_CHROMA: TEXT_LUMA, 0 ) );
1460#if !H_MV_ENC_DEC_TRAC
1461  DTRACE_CABAC_VL( g_nSymbolCounter++ )
1462  DTRACE_CABAC_T("\tparseTransformSkip()");
1463  DTRACE_CABAC_T( "\tsymbol=" )
1464  DTRACE_CABAC_V( useTransformSkip )
1465  DTRACE_CABAC_T( "\tAddr=" )
1466  DTRACE_CABAC_V( pcCU->getAddr() )
1467  DTRACE_CABAC_T( "\tetype=" )
1468  DTRACE_CABAC_V( eTType )
1469  DTRACE_CABAC_T( "\tuiAbsPartIdx=" )
1470  DTRACE_CABAC_V( uiAbsPartIdx )
1471  DTRACE_CABAC_T( "\n" )
1472#endif
1473}
1474
1475/** Code I_PCM information.
1476 * \param pcCU pointer to CU
1477 * \param uiAbsPartIdx CU index
1478 * \returns Void
1479 */
1480Void TEncSbac::codeIPCMInfo( TComDataCU* pcCU, UInt uiAbsPartIdx )
1481{
1482  UInt uiIPCM = (pcCU->getIPCMFlag(uiAbsPartIdx) == true)? 1 : 0;
1483
1484  Bool writePCMSampleFlag = pcCU->getIPCMFlag(uiAbsPartIdx);
1485
1486  m_pcBinIf->encodeBinTrm (uiIPCM);
1487#if H_MV_ENC_DEC_TRAC         
1488  DTRACE_CU("pcm_flag", uiIPCM)
1489#endif
1490  if (writePCMSampleFlag)
1491  {
1492    m_pcBinIf->encodePCMAlignBits();
1493
1494    UInt uiMinCoeffSize = pcCU->getPic()->getMinCUWidth()*pcCU->getPic()->getMinCUHeight();
1495    UInt uiLumaOffset   = uiMinCoeffSize*uiAbsPartIdx;
1496    UInt uiChromaOffset = uiLumaOffset>>2;
1497    Pel* piPCMSample;
1498    UInt uiWidth;
1499    UInt uiHeight;
1500    UInt uiSampleBits;
1501    UInt uiX, uiY;
1502
1503    piPCMSample = pcCU->getPCMSampleY() + uiLumaOffset;
1504    uiWidth = pcCU->getWidth(uiAbsPartIdx);
1505    uiHeight = pcCU->getHeight(uiAbsPartIdx);
1506    uiSampleBits = pcCU->getSlice()->getSPS()->getPCMBitDepthLuma();
1507
1508    for(uiY = 0; uiY < uiHeight; uiY++)
1509    {
1510      for(uiX = 0; uiX < uiWidth; uiX++)
1511      {
1512        UInt uiSample = piPCMSample[uiX];
1513
1514        m_pcBinIf->xWritePCMCode(uiSample, uiSampleBits);
1515      }
1516      piPCMSample += uiWidth;
1517    }
1518
1519#if H_3D_DISABLE_CHROMA
1520    if( pcCU->getSlice()->getSPS()->getChromaFormatIdc() != 0 )
1521    {   
1522#endif
1523    piPCMSample = pcCU->getPCMSampleCb() + uiChromaOffset;
1524    uiWidth = pcCU->getWidth(uiAbsPartIdx)/2;
1525    uiHeight = pcCU->getHeight(uiAbsPartIdx)/2;
1526    uiSampleBits = pcCU->getSlice()->getSPS()->getPCMBitDepthChroma();
1527
1528    for(uiY = 0; uiY < uiHeight; uiY++)
1529    {
1530      for(uiX = 0; uiX < uiWidth; uiX++)
1531      {
1532        UInt uiSample = piPCMSample[uiX];
1533
1534        m_pcBinIf->xWritePCMCode(uiSample, uiSampleBits);
1535      }
1536      piPCMSample += uiWidth;
1537    }
1538
1539    piPCMSample = pcCU->getPCMSampleCr() + uiChromaOffset;
1540    uiWidth = pcCU->getWidth(uiAbsPartIdx)/2;
1541    uiHeight = pcCU->getHeight(uiAbsPartIdx)/2;
1542    uiSampleBits = pcCU->getSlice()->getSPS()->getPCMBitDepthChroma();
1543
1544    for(uiY = 0; uiY < uiHeight; uiY++)
1545    {
1546      for(uiX = 0; uiX < uiWidth; uiX++)
1547      {
1548        UInt uiSample = piPCMSample[uiX];
1549
1550        m_pcBinIf->xWritePCMCode(uiSample, uiSampleBits);
1551      }
1552      piPCMSample += uiWidth;
1553    }
1554#if H_3D_DISABLE_CHROMA
1555    }
1556#endif
1557    m_pcBinIf->resetBac();
1558  }
1559}
1560
1561Void TEncSbac::codeQtRootCbf( TComDataCU* pcCU, UInt uiAbsPartIdx )
1562{
1563  UInt uiCbf = pcCU->getQtRootCbf( uiAbsPartIdx );
1564  UInt uiCtx = 0;
1565  m_pcBinIf->encodeBin( uiCbf , m_cCUQtRootCbfSCModel.get( 0, 0, uiCtx ) );
1566#if !H_MV_ENC_DEC_TRAC
1567  DTRACE_CABAC_VL( g_nSymbolCounter++ )
1568  DTRACE_CABAC_T( "\tparseQtRootCbf()" )
1569  DTRACE_CABAC_T( "\tsymbol=" )
1570  DTRACE_CABAC_V( uiCbf )
1571  DTRACE_CABAC_T( "\tctx=" )
1572  DTRACE_CABAC_V( uiCtx )
1573  DTRACE_CABAC_T( "\tuiAbsPartIdx=" )
1574  DTRACE_CABAC_V( uiAbsPartIdx )
1575  DTRACE_CABAC_T( "\n" )
1576#else
1577  DTRACE_CU( "rqt_root_cbf", uiCbf )
1578#endif
1579}
1580
1581Void TEncSbac::codeQtCbfZero( TComDataCU* pcCU, TextType eType, UInt uiTrDepth )
1582{
1583  // this function is only used to estimate the bits when cbf is 0
1584  // and will never be called when writing the bistream. do not need to write log
1585  UInt uiCbf = 0;
1586  UInt uiCtx = pcCU->getCtxQtCbf( eType, uiTrDepth );
1587  m_pcBinIf->encodeBin( uiCbf , m_cCUQtCbfSCModel.get( 0, eType ? TEXT_CHROMA : eType, uiCtx ) );
1588}
1589
1590Void TEncSbac::codeQtRootCbfZero( TComDataCU* pcCU )
1591{
1592  // this function is only used to estimate the bits when cbf is 0
1593  // and will never be called when writing the bistream. do not need to write log
1594  UInt uiCbf = 0;
1595  UInt uiCtx = 0;
1596  m_pcBinIf->encodeBin( uiCbf , m_cCUQtRootCbfSCModel.get( 0, 0, uiCtx ) );
1597}
1598
1599/** Encode (X,Y) position of the last significant coefficient
1600 * \param uiPosX X component of last coefficient
1601 * \param uiPosY Y component of last coefficient
1602 * \param width  Block width
1603 * \param height Block height
1604 * \param eTType plane type / luminance or chrominance
1605 * \param uiScanIdx scan type (zig-zag, hor, ver)
1606 * This method encodes the X and Y component within a block of the last significant coefficient.
1607 */
1608Void TEncSbac::codeLastSignificantXY( UInt uiPosX, UInt uiPosY, Int width, Int height, TextType eTType, UInt uiScanIdx )
1609{ 
1610  // swap
1611  if( uiScanIdx == SCAN_VER )
1612  {
1613    swap( uiPosX, uiPosY );
1614  }
1615
1616  UInt uiCtxLast;
1617  ContextModel *pCtxX = m_cCuCtxLastX.get( 0, eTType );
1618  ContextModel *pCtxY = m_cCuCtxLastY.get( 0, eTType );
1619  UInt uiGroupIdxX    = g_uiGroupIdx[ uiPosX ];
1620  UInt uiGroupIdxY    = g_uiGroupIdx[ uiPosY ];
1621
1622
1623  Int blkSizeOffsetX, blkSizeOffsetY, shiftX, shiftY;
1624  blkSizeOffsetX = eTType ? 0: (g_aucConvertToBit[ width ] *3 + ((g_aucConvertToBit[ width ] +1)>>2));
1625  blkSizeOffsetY = eTType ? 0: (g_aucConvertToBit[ height ]*3 + ((g_aucConvertToBit[ height ]+1)>>2));
1626  shiftX= eTType ? g_aucConvertToBit[ width  ] :((g_aucConvertToBit[ width  ]+3)>>2);
1627  shiftY= eTType ? g_aucConvertToBit[ height ] :((g_aucConvertToBit[ height ]+3)>>2);
1628  // posX
1629  for( uiCtxLast = 0; uiCtxLast < uiGroupIdxX; uiCtxLast++ )
1630  {
1631      m_pcBinIf->encodeBin( 1, *( pCtxX + blkSizeOffsetX + (uiCtxLast >>shiftX) ) );
1632  }
1633  if( uiGroupIdxX < g_uiGroupIdx[ width - 1 ])
1634  {
1635      m_pcBinIf->encodeBin( 0, *( pCtxX + blkSizeOffsetX + (uiCtxLast >>shiftX) ) );
1636  }
1637
1638  // posY
1639  for( uiCtxLast = 0; uiCtxLast < uiGroupIdxY; uiCtxLast++ )
1640  {
1641    m_pcBinIf->encodeBin( 1, *( pCtxY + blkSizeOffsetY + (uiCtxLast >>shiftY) ) );
1642  }
1643  if( uiGroupIdxY < g_uiGroupIdx[ height - 1 ])
1644  {
1645    m_pcBinIf->encodeBin( 0, *( pCtxY + blkSizeOffsetY + (uiCtxLast >>shiftY) ) );
1646  }
1647  if ( uiGroupIdxX > 3 )
1648  {     
1649    UInt uiCount = ( uiGroupIdxX - 2 ) >> 1;
1650    uiPosX       = uiPosX - g_uiMinInGroup[ uiGroupIdxX ];
1651    for (Int i = uiCount - 1 ; i >= 0; i-- )
1652    {
1653      m_pcBinIf->encodeBinEP( ( uiPosX >> i ) & 1 );
1654    }
1655  }
1656  if ( uiGroupIdxY > 3 )
1657  {     
1658    UInt uiCount = ( uiGroupIdxY - 2 ) >> 1;
1659    uiPosY       = uiPosY - g_uiMinInGroup[ uiGroupIdxY ];
1660    for ( Int i = uiCount - 1 ; i >= 0; i-- )
1661    {
1662      m_pcBinIf->encodeBinEP( ( uiPosY >> i ) & 1 );
1663    }
1664  }
1665}
1666
1667Void TEncSbac::codeCoeffNxN( TComDataCU* pcCU, TCoeff* pcCoef, UInt uiAbsPartIdx, UInt uiWidth, UInt uiHeight, UInt uiDepth, TextType eTType )
1668{
1669#if !H_MV_ENC_DEC_TRAC
1670  DTRACE_CABAC_VL( g_nSymbolCounter++ )
1671  DTRACE_CABAC_T( "\tparseCoeffNxN()\teType=" )
1672  DTRACE_CABAC_V( eTType )
1673  DTRACE_CABAC_T( "\twidth=" )
1674  DTRACE_CABAC_V( uiWidth )
1675  DTRACE_CABAC_T( "\theight=" )
1676  DTRACE_CABAC_V( uiHeight )
1677  DTRACE_CABAC_T( "\tdepth=" )
1678  DTRACE_CABAC_V( uiDepth )
1679  DTRACE_CABAC_T( "\tabspartidx=" )
1680  DTRACE_CABAC_V( uiAbsPartIdx )
1681  DTRACE_CABAC_T( "\ttoCU-X=" )
1682  DTRACE_CABAC_V( pcCU->getCUPelX() )
1683  DTRACE_CABAC_T( "\ttoCU-Y=" )
1684  DTRACE_CABAC_V( pcCU->getCUPelY() )
1685  DTRACE_CABAC_T( "\tCU-addr=" )
1686  DTRACE_CABAC_V(  pcCU->getAddr() )
1687  DTRACE_CABAC_T( "\tinCU-X=" )
1688  DTRACE_CABAC_V( g_auiRasterToPelX[ g_auiZscanToRaster[uiAbsPartIdx] ] )
1689  DTRACE_CABAC_T( "\tinCU-Y=" )
1690  DTRACE_CABAC_V( g_auiRasterToPelY[ g_auiZscanToRaster[uiAbsPartIdx] ] )
1691  DTRACE_CABAC_T( "\tpredmode=" )
1692  DTRACE_CABAC_V(  pcCU->getPredictionMode( uiAbsPartIdx ) )
1693  DTRACE_CABAC_T( "\n" )
1694#endif
1695  if( uiWidth > m_pcSlice->getSPS()->getMaxTrSize() )
1696  {
1697    uiWidth  = m_pcSlice->getSPS()->getMaxTrSize();
1698    uiHeight = m_pcSlice->getSPS()->getMaxTrSize();
1699  }
1700 
1701  UInt uiNumSig = 0;
1702 
1703  // compute number of significant coefficients
1704  uiNumSig = TEncEntropy::countNonZeroCoeffs(pcCoef, uiWidth * uiHeight);
1705 
1706  if ( uiNumSig == 0 )
1707    return;
1708  if(pcCU->getSlice()->getPPS()->getUseTransformSkip())
1709  {
1710    codeTransformSkipFlags( pcCU,uiAbsPartIdx, uiWidth, uiHeight, eTType );
1711  }
1712  eTType = eTType == TEXT_LUMA ? TEXT_LUMA : ( eTType == TEXT_NONE ? TEXT_NONE : TEXT_CHROMA );
1713 
1714  //----- encode significance map -----
1715  const UInt   uiLog2BlockSize = g_aucConvertToBit[ uiWidth ] + 2;
1716  UInt uiScanIdx = pcCU->getCoefScanIdx(uiAbsPartIdx, uiWidth, eTType==TEXT_LUMA, pcCU->isIntra(uiAbsPartIdx));
1717  const UInt *scan = g_auiSigLastScan[ uiScanIdx ][ uiLog2BlockSize - 1 ];
1718 
1719  Bool beValid;
1720  if (pcCU->getCUTransquantBypass(uiAbsPartIdx))
1721  {
1722    beValid = false;
1723  }
1724  else 
1725  {
1726    beValid = pcCU->getSlice()->getPPS()->getSignHideFlag() > 0;
1727  }
1728
1729  // Find position of last coefficient
1730  Int scanPosLast = -1;
1731  Int posLast;
1732
1733  const UInt * scanCG;
1734  {
1735    scanCG = g_auiSigLastScan[ uiScanIdx ][ uiLog2BlockSize > 3 ? uiLog2BlockSize-2-1 : 0 ];
1736    if( uiLog2BlockSize == 3 )
1737    {
1738      scanCG = g_sigLastScan8x8[ uiScanIdx ];
1739    }
1740    else if( uiLog2BlockSize == 5 )
1741    {
1742      scanCG = g_sigLastScanCG32x32;
1743    }
1744  }
1745  UInt uiSigCoeffGroupFlag[ MLS_GRP_NUM ];
1746  static const UInt uiShift = MLS_CG_SIZE >> 1;
1747  const UInt uiNumBlkSide = uiWidth >> uiShift;
1748
1749    ::memset( uiSigCoeffGroupFlag, 0, sizeof(UInt) * MLS_GRP_NUM );
1750
1751    do
1752    {
1753      posLast = scan[ ++scanPosLast ];
1754
1755      // get L1 sig map
1756      UInt uiPosY    = posLast >> uiLog2BlockSize;
1757      UInt uiPosX    = posLast - ( uiPosY << uiLog2BlockSize );
1758      UInt uiBlkIdx  = uiNumBlkSide * (uiPosY >> uiShift) + (uiPosX >> uiShift);
1759      if( pcCoef[ posLast ] )
1760      {
1761        uiSigCoeffGroupFlag[ uiBlkIdx ] = 1;
1762      }
1763
1764      uiNumSig -= ( pcCoef[ posLast ] != 0 );
1765    }
1766    while ( uiNumSig > 0 );
1767
1768  // Code position of last coefficient
1769  Int posLastY = posLast >> uiLog2BlockSize;
1770  Int posLastX = posLast - ( posLastY << uiLog2BlockSize );
1771  codeLastSignificantXY(posLastX, posLastY, uiWidth, uiHeight, eTType, uiScanIdx);
1772 
1773  //===== code significance flag =====
1774  ContextModel * const baseCoeffGroupCtx = m_cCUSigCoeffGroupSCModel.get( 0, eTType );
1775  ContextModel * const baseCtx = (eTType==TEXT_LUMA) ? m_cCUSigSCModel.get( 0, 0 ) : m_cCUSigSCModel.get( 0, 0 ) + NUM_SIG_FLAG_CTX_LUMA;
1776
1777
1778  const Int  iLastScanSet      = scanPosLast >> LOG2_SCAN_SET_SIZE;
1779  UInt c1 = 1;
1780  UInt uiGoRiceParam           = 0;
1781  Int  iScanPosSig             = scanPosLast;
1782
1783  for( Int iSubSet = iLastScanSet; iSubSet >= 0; iSubSet-- )
1784  {
1785    Int numNonZero = 0;
1786    Int  iSubPos     = iSubSet << LOG2_SCAN_SET_SIZE;
1787    uiGoRiceParam    = 0;
1788    Int absCoeff[16];
1789    UInt coeffSigns = 0;
1790
1791    Int lastNZPosInCG = -1, firstNZPosInCG = SCAN_SET_SIZE;
1792
1793    if( iScanPosSig == scanPosLast )
1794    {
1795      absCoeff[ 0 ] = abs( pcCoef[ posLast ] );
1796      coeffSigns    = ( pcCoef[ posLast ] < 0 );
1797      numNonZero    = 1;
1798      lastNZPosInCG  = iScanPosSig;
1799      firstNZPosInCG = iScanPosSig;
1800      iScanPosSig--;
1801    }
1802
1803      // encode significant_coeffgroup_flag
1804      Int iCGBlkPos = scanCG[ iSubSet ];
1805      Int iCGPosY   = iCGBlkPos / uiNumBlkSide;
1806      Int iCGPosX   = iCGBlkPos - (iCGPosY * uiNumBlkSide);
1807      if( iSubSet == iLastScanSet || iSubSet == 0)
1808      {
1809        uiSigCoeffGroupFlag[ iCGBlkPos ] = 1;
1810      }
1811      else
1812      {
1813          UInt uiSigCoeffGroup   = (uiSigCoeffGroupFlag[ iCGBlkPos ] != 0);
1814          UInt uiCtxSig  = TComTrQuant::getSigCoeffGroupCtxInc( uiSigCoeffGroupFlag, iCGPosX, iCGPosY, uiWidth, uiHeight );
1815          m_pcBinIf->encodeBin( uiSigCoeffGroup, baseCoeffGroupCtx[ uiCtxSig ] );
1816      }
1817     
1818      // encode significant_coeff_flag
1819      if( uiSigCoeffGroupFlag[ iCGBlkPos ] )
1820      {
1821        Int patternSigCtx = TComTrQuant::calcPatternSigCtx( uiSigCoeffGroupFlag, iCGPosX, iCGPosY, uiWidth, uiHeight );
1822        UInt uiBlkPos, uiPosY, uiPosX, uiSig, uiCtxSig;
1823        for( ; iScanPosSig >= iSubPos; iScanPosSig-- )
1824        {
1825          uiBlkPos  = scan[ iScanPosSig ]; 
1826          uiPosY    = uiBlkPos >> uiLog2BlockSize;
1827          uiPosX    = uiBlkPos - ( uiPosY << uiLog2BlockSize );
1828          uiSig     = (pcCoef[ uiBlkPos ] != 0);
1829          if( iScanPosSig > iSubPos || iSubSet == 0 || numNonZero )
1830          {
1831            uiCtxSig  = TComTrQuant::getSigCtxInc( patternSigCtx, uiScanIdx, uiPosX, uiPosY, uiLog2BlockSize, eTType );
1832            m_pcBinIf->encodeBin( uiSig, baseCtx[ uiCtxSig ] );
1833          }
1834          if( uiSig )
1835          {
1836            absCoeff[ numNonZero ] = abs( pcCoef[ uiBlkPos ] );
1837            coeffSigns = 2 * coeffSigns + ( pcCoef[ uiBlkPos ] < 0 );
1838            numNonZero++;
1839            if( lastNZPosInCG == -1 )
1840            {
1841              lastNZPosInCG = iScanPosSig;
1842            }
1843            firstNZPosInCG = iScanPosSig;
1844          }
1845        }
1846      }
1847      else
1848      {
1849        iScanPosSig = iSubPos - 1;
1850      }
1851
1852    if( numNonZero > 0 )
1853    {
1854      Bool signHidden = ( lastNZPosInCG - firstNZPosInCG >= SBH_THRESHOLD );
1855      UInt uiCtxSet = (iSubSet > 0 && eTType==TEXT_LUMA) ? 2 : 0;
1856     
1857      if( c1 == 0 )
1858      {
1859        uiCtxSet++;
1860      }
1861      c1 = 1;
1862      ContextModel *baseCtxMod = ( eTType==TEXT_LUMA ) ? m_cCUOneSCModel.get( 0, 0 ) + 4 * uiCtxSet : m_cCUOneSCModel.get( 0, 0 ) + NUM_ONE_FLAG_CTX_LUMA + 4 * uiCtxSet;
1863     
1864      Int numC1Flag = min(numNonZero, C1FLAG_NUMBER);
1865      Int firstC2FlagIdx = -1;
1866      for( Int idx = 0; idx < numC1Flag; idx++ )
1867      {
1868        UInt uiSymbol = absCoeff[ idx ] > 1;
1869        m_pcBinIf->encodeBin( uiSymbol, baseCtxMod[c1] );
1870        if( uiSymbol )
1871        {
1872          c1 = 0;
1873
1874          if (firstC2FlagIdx == -1)
1875          {
1876            firstC2FlagIdx = idx;
1877          }
1878        }
1879        else if( (c1 < 3) && (c1 > 0) )
1880        {
1881          c1++;
1882        }
1883      }
1884     
1885      if (c1 == 0)
1886      {
1887
1888        baseCtxMod = ( eTType==TEXT_LUMA ) ? m_cCUAbsSCModel.get( 0, 0 ) + uiCtxSet : m_cCUAbsSCModel.get( 0, 0 ) + NUM_ABS_FLAG_CTX_LUMA + uiCtxSet;
1889        if ( firstC2FlagIdx != -1)
1890        {
1891          UInt symbol = absCoeff[ firstC2FlagIdx ] > 2;
1892          m_pcBinIf->encodeBin( symbol, baseCtxMod[0] );
1893        }
1894      }
1895     
1896      if( beValid && signHidden )
1897      {
1898        m_pcBinIf->encodeBinsEP( (coeffSigns >> 1), numNonZero-1 );
1899      }
1900      else
1901      {
1902        m_pcBinIf->encodeBinsEP( coeffSigns, numNonZero );
1903      }
1904     
1905      Int iFirstCoeff2 = 1;   
1906      if (c1 == 0 || numNonZero > C1FLAG_NUMBER)
1907      {
1908        for ( Int idx = 0; idx < numNonZero; idx++ )
1909        {
1910          UInt baseLevel  = (idx < C1FLAG_NUMBER)? (2 + iFirstCoeff2 ) : 1;
1911
1912          if( absCoeff[ idx ] >= baseLevel)
1913          {
1914            xWriteCoefRemainExGolomb( absCoeff[ idx ] - baseLevel, uiGoRiceParam );
1915            if(absCoeff[idx] > 3*(1<<uiGoRiceParam))
1916            {
1917               uiGoRiceParam = min<UInt>(uiGoRiceParam+ 1, 4);
1918            }
1919          }
1920          if(absCoeff[ idx ] >= 2) 
1921          {
1922            iFirstCoeff2 = 0;
1923          }
1924        }       
1925      }
1926    }
1927  }
1928
1929  return;
1930}
1931
1932/** code SAO offset sign
1933 * \param code sign value
1934 */
1935Void TEncSbac::codeSAOSign( UInt code )
1936{
1937  m_pcBinIf->encodeBinEP( code );
1938}
1939
1940Void TEncSbac::codeSaoMaxUvlc    ( UInt code, UInt maxSymbol )
1941{
1942  if (maxSymbol == 0)
1943  {
1944    return;
1945  }
1946
1947  Int i;
1948  Bool bCodeLast = ( maxSymbol > code );
1949
1950  if ( code == 0 )
1951  {
1952    m_pcBinIf->encodeBinEP( 0 );
1953  }
1954  else
1955  {
1956    m_pcBinIf->encodeBinEP( 1 );
1957    for ( i=0; i<code-1; i++ )
1958    {
1959      m_pcBinIf->encodeBinEP( 1 );
1960    }
1961    if( bCodeLast )
1962    {
1963      m_pcBinIf->encodeBinEP( 0 );
1964    }
1965  }
1966}
1967
1968
1969/** Code SAO EO class or BO band position
1970 * \param uiLength
1971 * \param uiCode
1972 */
1973Void TEncSbac::codeSaoUflc       ( UInt uiLength, UInt uiCode )
1974{
1975   m_pcBinIf->encodeBinsEP ( uiCode, uiLength );
1976}
1977/** Code SAO merge flags
1978 * \param uiCode
1979 * \param uiCompIdx
1980 */
1981Void TEncSbac::codeSaoMerge       ( UInt uiCode )
1982{
1983  if (uiCode == 0)
1984  {
1985    m_pcBinIf->encodeBin(0,  m_cSaoMergeSCModel.get( 0, 0, 0 ));
1986  }
1987  else
1988  {
1989    m_pcBinIf->encodeBin(1,  m_cSaoMergeSCModel.get( 0, 0, 0 ));
1990  }
1991}
1992/** Code SAO type index
1993 * \param uiCode
1994 */
1995Void TEncSbac::codeSaoTypeIdx       ( UInt uiCode)
1996{
1997  if (uiCode == 0)
1998  {
1999    m_pcBinIf->encodeBin( 0, m_cSaoTypeIdxSCModel.get( 0, 0, 0 ) );
2000  }
2001  else
2002  {
2003    m_pcBinIf->encodeBin( 1, m_cSaoTypeIdxSCModel.get( 0, 0, 0 ) );
2004    m_pcBinIf->encodeBinEP( uiCode == 1 ? 0 : 1 );
2005  }
2006}
2007/*!
2008 ****************************************************************************
2009 * \brief
2010 *   estimate bit cost for CBP, significant map and significant coefficients
2011 ****************************************************************************
2012 */
2013Void TEncSbac::estBit( estBitsSbacStruct* pcEstBitsSbac, Int width, Int height, TextType eTType )
2014{
2015  estCBFBit( pcEstBitsSbac );
2016
2017  estSignificantCoeffGroupMapBit( pcEstBitsSbac, eTType );
2018 
2019  // encode significance map
2020  estSignificantMapBit( pcEstBitsSbac, width, height, eTType );
2021 
2022  // encode significant coefficients
2023  estSignificantCoefficientsBit( pcEstBitsSbac, eTType );
2024}
2025
2026/*!
2027 ****************************************************************************
2028 * \brief
2029 *    estimate bit cost for each CBP bit
2030 ****************************************************************************
2031 */
2032Void TEncSbac::estCBFBit( estBitsSbacStruct* pcEstBitsSbac )
2033{
2034  ContextModel *pCtx = m_cCUQtCbfSCModel.get( 0 );
2035
2036  for( UInt uiCtxInc = 0; uiCtxInc < 3*NUM_QT_CBF_CTX; uiCtxInc++ )
2037  {
2038    pcEstBitsSbac->blockCbpBits[ uiCtxInc ][ 0 ] = pCtx[ uiCtxInc ].getEntropyBits( 0 );
2039    pcEstBitsSbac->blockCbpBits[ uiCtxInc ][ 1 ] = pCtx[ uiCtxInc ].getEntropyBits( 1 );
2040  }
2041
2042  pCtx = m_cCUQtRootCbfSCModel.get( 0 );
2043 
2044  for( UInt uiCtxInc = 0; uiCtxInc < 4; uiCtxInc++ )
2045  {
2046    pcEstBitsSbac->blockRootCbpBits[ uiCtxInc ][ 0 ] = pCtx[ uiCtxInc ].getEntropyBits( 0 );
2047    pcEstBitsSbac->blockRootCbpBits[ uiCtxInc ][ 1 ] = pCtx[ uiCtxInc ].getEntropyBits( 1 );
2048  }
2049}
2050
2051
2052/*!
2053 ****************************************************************************
2054 * \brief
2055 *    estimate SAMBAC bit cost for significant coefficient group map
2056 ****************************************************************************
2057 */
2058Void TEncSbac::estSignificantCoeffGroupMapBit( estBitsSbacStruct* pcEstBitsSbac, TextType eTType )
2059{
2060  Int firstCtx = 0, numCtx = NUM_SIG_CG_FLAG_CTX;
2061
2062  for ( Int ctxIdx = firstCtx; ctxIdx < firstCtx + numCtx; ctxIdx++ )
2063  {
2064    for( UInt uiBin = 0; uiBin < 2; uiBin++ )
2065    {
2066      pcEstBitsSbac->significantCoeffGroupBits[ ctxIdx ][ uiBin ] = m_cCUSigCoeffGroupSCModel.get(  0, eTType, ctxIdx ).getEntropyBits( uiBin );
2067    }
2068  }
2069}
2070
2071
2072/*!
2073 ****************************************************************************
2074 * \brief
2075 *    estimate SAMBAC bit cost for significant coefficient map
2076 ****************************************************************************
2077 */
2078Void TEncSbac::estSignificantMapBit( estBitsSbacStruct* pcEstBitsSbac, Int width, Int height, TextType eTType )
2079{
2080  Int firstCtx = 1, numCtx = 8;
2081  if (max(width, height) >= 16)
2082  {
2083    firstCtx = (eTType == TEXT_LUMA) ? 21 : 12;
2084    numCtx = (eTType == TEXT_LUMA) ? 6 : 3;
2085  }
2086  else if (width == 8)
2087  {
2088    firstCtx = 9;
2089    numCtx = (eTType == TEXT_LUMA) ? 12 : 3;
2090  }
2091 
2092  if (eTType == TEXT_LUMA )
2093  {
2094    for( UInt bin = 0; bin < 2; bin++ )
2095    {
2096      pcEstBitsSbac->significantBits[ 0 ][ bin ] = m_cCUSigSCModel.get(  0, 0, 0 ).getEntropyBits( bin );
2097    }
2098
2099    for ( Int ctxIdx = firstCtx; ctxIdx < firstCtx + numCtx; ctxIdx++ )
2100    {
2101      for( UInt uiBin = 0; uiBin < 2; uiBin++ )
2102      {
2103        pcEstBitsSbac->significantBits[ ctxIdx ][ uiBin ] = m_cCUSigSCModel.get(  0, 0, ctxIdx ).getEntropyBits( uiBin );
2104      }
2105    }
2106  }
2107  else
2108  {
2109    for( UInt bin = 0; bin < 2; bin++ )
2110    {
2111      pcEstBitsSbac->significantBits[ 0 ][ bin ] = m_cCUSigSCModel.get(  0, 0, NUM_SIG_FLAG_CTX_LUMA + 0 ).getEntropyBits( bin );
2112    }
2113    for ( Int ctxIdx = firstCtx; ctxIdx < firstCtx + numCtx; ctxIdx++ )
2114    {
2115      for( UInt uiBin = 0; uiBin < 2; uiBin++ )
2116      {
2117        pcEstBitsSbac->significantBits[ ctxIdx ][ uiBin ] = m_cCUSigSCModel.get(  0, 0, NUM_SIG_FLAG_CTX_LUMA + ctxIdx ).getEntropyBits( uiBin );
2118      }
2119    }
2120  }
2121  Int iBitsX = 0, iBitsY = 0;
2122  Int blkSizeOffsetX, blkSizeOffsetY, shiftX, shiftY;
2123
2124  blkSizeOffsetX = eTType ? 0: (g_aucConvertToBit[ width ] *3 + ((g_aucConvertToBit[ width ] +1)>>2));
2125  blkSizeOffsetY = eTType ? 0: (g_aucConvertToBit[ height ]*3 + ((g_aucConvertToBit[ height ]+1)>>2));
2126  shiftX = eTType ? g_aucConvertToBit[ width  ] :((g_aucConvertToBit[ width  ]+3)>>2);
2127  shiftY = eTType ? g_aucConvertToBit[ height ] :((g_aucConvertToBit[ height ]+3)>>2);
2128
2129  Int ctx;
2130  ContextModel *pCtxX      = m_cCuCtxLastX.get( 0, eTType );
2131  for (ctx = 0; ctx < g_uiGroupIdx[ width - 1 ]; ctx++)
2132  {
2133    Int ctxOffset = blkSizeOffsetX + (ctx >>shiftX);
2134    pcEstBitsSbac->lastXBits[ ctx ] = iBitsX + pCtxX[ ctxOffset ].getEntropyBits( 0 );
2135    iBitsX += pCtxX[ ctxOffset ].getEntropyBits( 1 );
2136  }
2137  pcEstBitsSbac->lastXBits[ctx] = iBitsX;
2138  ContextModel *pCtxY      = m_cCuCtxLastY.get( 0, eTType );
2139  for (ctx = 0; ctx < g_uiGroupIdx[ height - 1 ]; ctx++)
2140  {
2141    Int ctxOffset = blkSizeOffsetY + (ctx >>shiftY);
2142    pcEstBitsSbac->lastYBits[ ctx ] = iBitsY + pCtxY[ ctxOffset ].getEntropyBits( 0 );
2143    iBitsY += pCtxY[ ctxOffset ].getEntropyBits( 1 );
2144  }
2145  pcEstBitsSbac->lastYBits[ctx] = iBitsY;
2146}
2147
2148/*!
2149 ****************************************************************************
2150 * \brief
2151 *    estimate bit cost of significant coefficient
2152 ****************************************************************************
2153 */
2154Void TEncSbac::estSignificantCoefficientsBit( estBitsSbacStruct* pcEstBitsSbac, TextType eTType )
2155{
2156  if (eTType==TEXT_LUMA)
2157  {
2158    ContextModel *ctxOne = m_cCUOneSCModel.get(0, 0);
2159    ContextModel *ctxAbs = m_cCUAbsSCModel.get(0, 0);
2160
2161    for (Int ctxIdx = 0; ctxIdx < NUM_ONE_FLAG_CTX_LUMA; ctxIdx++)
2162    {
2163      pcEstBitsSbac->m_greaterOneBits[ ctxIdx ][ 0 ] = ctxOne[ ctxIdx ].getEntropyBits( 0 );
2164      pcEstBitsSbac->m_greaterOneBits[ ctxIdx ][ 1 ] = ctxOne[ ctxIdx ].getEntropyBits( 1 );   
2165    }
2166
2167    for (Int ctxIdx = 0; ctxIdx < NUM_ABS_FLAG_CTX_LUMA; ctxIdx++)
2168    {
2169      pcEstBitsSbac->m_levelAbsBits[ ctxIdx ][ 0 ] = ctxAbs[ ctxIdx ].getEntropyBits( 0 );
2170      pcEstBitsSbac->m_levelAbsBits[ ctxIdx ][ 1 ] = ctxAbs[ ctxIdx ].getEntropyBits( 1 );   
2171    }
2172  }
2173  else
2174  {
2175    ContextModel *ctxOne = m_cCUOneSCModel.get(0, 0) + NUM_ONE_FLAG_CTX_LUMA;
2176    ContextModel *ctxAbs = m_cCUAbsSCModel.get(0, 0) + NUM_ABS_FLAG_CTX_LUMA;
2177
2178    for (Int ctxIdx = 0; ctxIdx < NUM_ONE_FLAG_CTX_CHROMA; ctxIdx++)
2179    {
2180      pcEstBitsSbac->m_greaterOneBits[ ctxIdx ][ 0 ] = ctxOne[ ctxIdx ].getEntropyBits( 0 );
2181      pcEstBitsSbac->m_greaterOneBits[ ctxIdx ][ 1 ] = ctxOne[ ctxIdx ].getEntropyBits( 1 );   
2182    }
2183
2184    for (Int ctxIdx = 0; ctxIdx < NUM_ABS_FLAG_CTX_CHROMA; ctxIdx++)
2185    {
2186      pcEstBitsSbac->m_levelAbsBits[ ctxIdx ][ 0 ] = ctxAbs[ ctxIdx ].getEntropyBits( 0 );
2187      pcEstBitsSbac->m_levelAbsBits[ ctxIdx ][ 1 ] = ctxAbs[ ctxIdx ].getEntropyBits( 1 );   
2188    }
2189  }
2190}
2191
2192/**
2193 - Initialize our context information from the nominated source.
2194 .
2195 \param pSrc From where to copy context information.
2196 */
2197Void TEncSbac::xCopyContextsFrom( TEncSbac* pSrc )
2198{ 
2199  memcpy(m_contextModels, pSrc->m_contextModels, m_numContextModels*sizeof(m_contextModels[0]));
2200}
2201
2202Void  TEncSbac::loadContexts ( TEncSbac* pScr)
2203{
2204  this->xCopyContextsFrom(pScr);
2205}
2206
2207Void TEncSbac::codeSAOOffsetParam(Int compIdx, SAOOffset& ctbParam, Bool sliceEnabled)
2208{
2209  UInt uiSymbol;
2210  if(!sliceEnabled)
2211  {
2212    assert(ctbParam.modeIdc == SAO_MODE_OFF);
2213    return;
2214  }
2215
2216  //type
2217  if(compIdx == SAO_Y || compIdx == SAO_Cb)
2218  {
2219    //sao_type_idx_luma or sao_type_idx_chroma
2220    if(ctbParam.modeIdc == SAO_MODE_OFF)
2221    {
2222      uiSymbol =0;
2223    }
2224    else if(ctbParam.typeIdc == SAO_TYPE_BO) //BO
2225    {
2226      uiSymbol = 1;
2227    }
2228    else
2229    {
2230      assert(ctbParam.typeIdc < SAO_TYPE_START_BO); //EO
2231      uiSymbol = 2;
2232    }
2233    codeSaoTypeIdx(uiSymbol); 
2234  }
2235
2236  if(ctbParam.modeIdc == SAO_MODE_NEW)
2237  {
2238    Int numClasses = (ctbParam.typeIdc == SAO_TYPE_BO)?4:NUM_SAO_EO_CLASSES; 
2239    Int offset[4];
2240    Int k=0;
2241    for(Int i=0; i< numClasses; i++)
2242    {
2243      if(ctbParam.typeIdc != SAO_TYPE_BO && i == SAO_CLASS_EO_PLAIN)
2244      {
2245        continue;
2246      }
2247      Int classIdx = (ctbParam.typeIdc == SAO_TYPE_BO)?(  (ctbParam.typeAuxInfo+i)% NUM_SAO_BO_CLASSES   ):i;
2248      offset[k] = ctbParam.offset[classIdx];
2249      k++;
2250    }
2251
2252    for(Int i=0; i< 4; i++)
2253    {
2254      codeSaoMaxUvlc((offset[i]<0)?(-offset[i]):(offset[i]),  g_saoMaxOffsetQVal[compIdx] ); //sao_offset_abs
2255    }
2256
2257
2258    if(ctbParam.typeIdc == SAO_TYPE_BO)
2259    {
2260      for(Int i=0; i< 4; i++)
2261      {
2262        if(offset[i] != 0)
2263        {
2264          codeSAOSign((offset[i]< 0)?1:0);
2265        }
2266      }
2267
2268      codeSaoUflc(NUM_SAO_BO_CLASSES_LOG2, ctbParam.typeAuxInfo ); //sao_band_position
2269    }
2270    else //EO
2271    {
2272      if(compIdx == SAO_Y || compIdx == SAO_Cb)
2273      {
2274        assert(ctbParam.typeIdc - SAO_TYPE_START_EO >=0);
2275        codeSaoUflc(NUM_SAO_EO_TYPES_LOG2, ctbParam.typeIdc - SAO_TYPE_START_EO ); //sao_eo_class_luma or sao_eo_class_chroma
2276      }
2277    }
2278
2279  }
2280}
2281
2282
2283Void TEncSbac::codeSAOBlkParam(SAOBlkParam& saoBlkParam
2284                              , Bool* sliceEnabled
2285                              , Bool leftMergeAvail
2286                              , Bool aboveMergeAvail
2287                              , Bool onlyEstMergeInfo // = false
2288                              )
2289{
2290
2291  Bool isLeftMerge = false;
2292  Bool isAboveMerge= false;
2293
2294  if(leftMergeAvail)
2295  {
2296    isLeftMerge = ((saoBlkParam[SAO_Y].modeIdc == SAO_MODE_MERGE) && (saoBlkParam[SAO_Y].typeIdc == SAO_MERGE_LEFT));
2297    codeSaoMerge( isLeftMerge?1:0  ); //sao_merge_left_flag
2298  }
2299
2300  if( aboveMergeAvail && !isLeftMerge)
2301  {
2302    isAboveMerge = ((saoBlkParam[SAO_Y].modeIdc == SAO_MODE_MERGE) && (saoBlkParam[SAO_Y].typeIdc == SAO_MERGE_ABOVE)); 
2303    codeSaoMerge( isAboveMerge?1:0  ); //sao_merge_left_flag
2304  }
2305
2306  if(onlyEstMergeInfo)
2307  {
2308    return; //only for RDO
2309  }
2310
2311  if(!isLeftMerge && !isAboveMerge) //not merge mode
2312  {
2313    for(Int compIdx=0; compIdx < NUM_SAO_COMPONENTS; compIdx++)
2314    {
2315      codeSAOOffsetParam(compIdx, saoBlkParam[compIdx], sliceEnabled[compIdx]);
2316    }
2317  }
2318}
2319
2320#if H_3D_INTER_SDC
2321Void TEncSbac::codeDeltaDC( TComDataCU* pcCU, UInt absPartIdx )
2322{
2323  if( !( pcCU->getSDCFlag( absPartIdx ) || ( pcCU->isIntra( absPartIdx ) && getDimType( pcCU->getLumaIntraDir( absPartIdx ) ) < DIM_NUM_TYPE ) ) )
2324  {
2325    assert( 0 );
2326  }
2327
2328  UInt uiNumSegments = isDimMode( pcCU->getLumaIntraDir( absPartIdx ) ) ? 2 : 1;
2329  UInt dimDeltaDC = 1;
2330
2331  if( pcCU->isIntra( absPartIdx ) && pcCU->getSDCFlag( absPartIdx ))
2332  {
2333      if( uiNumSegments == 1 )
2334      {
2335        dimDeltaDC = pcCU->getSDCSegmentDCOffset( 0, absPartIdx ) ? 1 : 0;
2336      }
2337      else
2338      {
2339        dimDeltaDC = ( pcCU->getSDCSegmentDCOffset( 0, absPartIdx ) || pcCU->getSDCSegmentDCOffset( 1, absPartIdx ) ) ? 1 : 0;
2340      }
2341    m_pcBinIf->encodeBin( dimDeltaDC, m_cDdcFlagSCModel.get( 0, 0, 0 ) );
2342  }
2343
2344  if( dimDeltaDC )
2345  {
2346    for( UInt segment = 0; segment < uiNumSegments; segment++ )
2347    {
2348      Pel deltaDC = 0;
2349
2350      if( pcCU->isIntra( absPartIdx ) )
2351      {
2352        UInt dir     = pcCU->getLumaIntraDir( absPartIdx );
2353        deltaDC = pcCU->getSDCFlag( absPartIdx ) ? pcCU->getSDCSegmentDCOffset( segment, absPartIdx ) : pcCU->getDimDeltaDC( getDimType( dir ), segment, absPartIdx );
2354      }
2355      else
2356      {
2357        deltaDC = pcCU->getSDCSegmentDCOffset( segment, absPartIdx );
2358      }
2359
2360      xCodeDimDeltaDC( deltaDC, uiNumSegments );
2361    }
2362  }
2363}
2364
2365Void TEncSbac::codeSDCFlag( TComDataCU* pcCU, UInt uiAbsPartIdx )
2366{
2367  UInt uiSymbol = pcCU->getSDCFlag( uiAbsPartIdx ) ? 1 : 0;
2368  UInt uiCtxSDCFlag = pcCU->getCtxSDCFlag( uiAbsPartIdx );
2369  DTRACE_CU("dc_only_flag", uiSymbol)
2370  m_pcBinIf->encodeBin( uiSymbol, m_cSDCFlagSCModel.get( 0, 0, uiCtxSDCFlag ) );
2371}
2372
2373#endif
2374
2375#if H_3D_DBBP
2376Void TEncSbac::codeDBBPFlag( TComDataCU* pcCU, UInt uiAbsPartIdx )
2377{
2378  PartSize ePartSize = pcCU->getPartitionSize( uiAbsPartIdx );
2379  AOF( ePartSize == SIZE_2NxN || ePartSize == SIZE_Nx2N );
2380  AOF( pcCU->getSlice()->getDepthBasedBlkPartFlag() ); 
2381  AOF( !pcCU->getSlice()->getIsDepth() );
2382 
2383  UInt uiSymbol = pcCU->getDBBPFlag( uiAbsPartIdx ) ? 1 : 0;
2384  m_pcBinIf->encodeBin( uiSymbol, m_cDBBPFlagSCModel.get( 0, 0, 0 ) );
2385  DTRACE_CU("dbbp_flag", uiSymbol)
2386}
2387#endif
2388
2389//! \}
Note: See TracBrowser for help on using the repository browser.