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-2013, 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 | |
---|
51 | TEncSbac::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 | , m_cCUMergeFlagExtSCModel ( 1, 1, NUM_MERGE_FLAG_EXT_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
61 | , m_cCUMergeIdxExtSCModel ( 1, 1, NUM_MERGE_IDX_EXT_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
62 | , m_cCUPartSizeSCModel ( 1, 1, NUM_PART_SIZE_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
63 | , m_cCUPredModeSCModel ( 1, 1, NUM_PRED_MODE_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
64 | , m_cCUIntraPredSCModel ( 1, 1, NUM_ADI_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
65 | , m_cCUChromaPredSCModel ( 1, 1, NUM_CHROMA_PRED_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
66 | , m_cCUDeltaQpSCModel ( 1, 1, NUM_DELTA_QP_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
67 | , m_cCUInterDirSCModel ( 1, 1, NUM_INTER_DIR_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
68 | , m_cCURefPicSCModel ( 1, 1, NUM_REF_NO_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
69 | , m_cCUMvdSCModel ( 1, 1, NUM_MV_RES_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
70 | , m_cCUQtCbfSCModel ( 1, 2, NUM_QT_CBF_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
71 | , m_cCUTransSubdivFlagSCModel ( 1, 1, NUM_TRANS_SUBDIV_FLAG_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
72 | , m_cCUQtRootCbfSCModel ( 1, 1, NUM_QT_ROOT_CBF_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
73 | , m_cCUSigCoeffGroupSCModel ( 1, 2, NUM_SIG_CG_FLAG_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
74 | , m_cCUSigSCModel ( 1, 1, NUM_SIG_FLAG_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
75 | , m_cCuCtxLastX ( 1, 2, NUM_CTX_LAST_FLAG_XY , m_contextModels + m_numContextModels, m_numContextModels) |
---|
76 | , m_cCuCtxLastY ( 1, 2, NUM_CTX_LAST_FLAG_XY , m_contextModels + m_numContextModels, m_numContextModels) |
---|
77 | , m_cCUOneSCModel ( 1, 1, NUM_ONE_FLAG_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
78 | , m_cCUAbsSCModel ( 1, 1, NUM_ABS_FLAG_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
79 | , m_cMVPIdxSCModel ( 1, 1, NUM_MVP_IDX_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
80 | , m_cCUAMPSCModel ( 1, 1, NUM_CU_AMP_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
81 | , m_cSaoMergeSCModel ( 1, 1, NUM_SAO_MERGE_FLAG_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
82 | , m_cSaoTypeIdxSCModel ( 1, 1, NUM_SAO_TYPE_IDX_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
83 | , m_cTransformSkipSCModel ( 1, 2, NUM_TRANSFORMSKIP_FLAG_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
84 | , m_CUTransquantBypassFlagSCModel( 1, 1, NUM_CU_TRANSQUANT_BYPASS_FLAG_CTX, m_contextModels + m_numContextModels, m_numContextModels) |
---|
85 | #if H_3D_DIM |
---|
86 | , m_cDepthIntraModeSCModel ( 1, 1, NUM_DEPTH_INTRA_MODE_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
87 | , m_cDdcFlagSCModel ( 1, 1, NUM_DDC_FLAG_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
88 | , m_cDdcDataSCModel ( 1, 1, NUM_DDC_DATA_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
89 | #if H_3D_DIM_DMM |
---|
90 | , m_cDmm1DataSCModel ( 1, 1, NUM_DMM1_DATA_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
91 | , m_cDmm2DataSCModel ( 1, 1, NUM_DMM2_DATA_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
92 | , m_cDmm3DataSCModel ( 1, 1, NUM_DMM3_DATA_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
93 | #endif |
---|
94 | #if H_3D_DIM_RBC |
---|
95 | , m_cRbcDataSCModel ( 1, 1, NUM_RBC_DATA_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
96 | #endif |
---|
97 | #endif |
---|
98 | { |
---|
99 | assert( m_numContextModels <= MAX_NUM_CTX_MOD ); |
---|
100 | } |
---|
101 | |
---|
102 | TEncSbac::~TEncSbac() |
---|
103 | { |
---|
104 | } |
---|
105 | |
---|
106 | // ==================================================================================================================== |
---|
107 | // Public member functions |
---|
108 | // ==================================================================================================================== |
---|
109 | |
---|
110 | Void TEncSbac::resetEntropy () |
---|
111 | { |
---|
112 | Int iQp = m_pcSlice->getSliceQp(); |
---|
113 | SliceType eSliceType = m_pcSlice->getSliceType(); |
---|
114 | |
---|
115 | Int encCABACTableIdx = m_pcSlice->getPPS()->getEncCABACTableIdx(); |
---|
116 | if (!m_pcSlice->isIntra() && (encCABACTableIdx==B_SLICE || encCABACTableIdx==P_SLICE) && m_pcSlice->getPPS()->getCabacInitPresentFlag()) |
---|
117 | { |
---|
118 | eSliceType = (SliceType) encCABACTableIdx; |
---|
119 | } |
---|
120 | |
---|
121 | m_cCUSplitFlagSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_SPLIT_FLAG ); |
---|
122 | |
---|
123 | m_cCUSkipFlagSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_SKIP_FLAG ); |
---|
124 | m_cCUMergeFlagExtSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_MERGE_FLAG_EXT); |
---|
125 | m_cCUMergeIdxExtSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_MERGE_IDX_EXT); |
---|
126 | m_cCUPartSizeSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_PART_SIZE ); |
---|
127 | m_cCUAMPSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_CU_AMP_POS ); |
---|
128 | m_cCUPredModeSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_PRED_MODE ); |
---|
129 | m_cCUIntraPredSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_INTRA_PRED_MODE ); |
---|
130 | m_cCUChromaPredSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_CHROMA_PRED_MODE ); |
---|
131 | m_cCUInterDirSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_INTER_DIR ); |
---|
132 | m_cCUMvdSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_MVD ); |
---|
133 | m_cCURefPicSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_REF_PIC ); |
---|
134 | m_cCUDeltaQpSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_DQP ); |
---|
135 | m_cCUQtCbfSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_QT_CBF ); |
---|
136 | m_cCUQtRootCbfSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_QT_ROOT_CBF ); |
---|
137 | m_cCUSigCoeffGroupSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_SIG_CG_FLAG ); |
---|
138 | m_cCUSigSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_SIG_FLAG ); |
---|
139 | m_cCuCtxLastX.initBuffer ( eSliceType, iQp, (UChar*)INIT_LAST ); |
---|
140 | m_cCuCtxLastY.initBuffer ( eSliceType, iQp, (UChar*)INIT_LAST ); |
---|
141 | m_cCUOneSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_ONE_FLAG ); |
---|
142 | m_cCUAbsSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_ABS_FLAG ); |
---|
143 | m_cMVPIdxSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_MVP_IDX ); |
---|
144 | m_cCUTransSubdivFlagSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_TRANS_SUBDIV_FLAG ); |
---|
145 | m_cSaoMergeSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_SAO_MERGE_FLAG ); |
---|
146 | m_cSaoTypeIdxSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_SAO_TYPE_IDX ); |
---|
147 | m_cTransformSkipSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_TRANSFORMSKIP_FLAG ); |
---|
148 | m_CUTransquantBypassFlagSCModel.initBuffer( eSliceType, iQp, (UChar*)INIT_CU_TRANSQUANT_BYPASS_FLAG ); |
---|
149 | |
---|
150 | #if H_3D_DIM |
---|
151 | m_cDepthIntraModeSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_DEPTH_INTRA_MODE ); |
---|
152 | m_cDdcFlagSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_DDC_FLAG ); |
---|
153 | m_cDdcDataSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_DDC_DATA ); |
---|
154 | #if H_3D_DIM_DMM |
---|
155 | m_cDmm1DataSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_DMM1_DATA ); |
---|
156 | m_cDmm2DataSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_DMM2_DATA ); |
---|
157 | m_cDmm3DataSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_DMM3_DATA ); |
---|
158 | #endif |
---|
159 | #if H_3D_DIM_RBC |
---|
160 | m_cRbcDataSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_RBC_DATA ); |
---|
161 | #endif |
---|
162 | #endif |
---|
163 | // new structure |
---|
164 | m_uiLastQp = iQp; |
---|
165 | |
---|
166 | m_pcBinIf->start(); |
---|
167 | |
---|
168 | return; |
---|
169 | } |
---|
170 | |
---|
171 | /** The function does the following: |
---|
172 | * If current slice type is P/B then it determines the distance of initialisation type 1 and 2 from the current CABAC states and |
---|
173 | * stores the index of the closest table. This index is used for the next P/B slice when cabac_init_present_flag is true. |
---|
174 | */ |
---|
175 | Void TEncSbac::determineCabacInitIdx() |
---|
176 | { |
---|
177 | Int qp = m_pcSlice->getSliceQp(); |
---|
178 | |
---|
179 | if (!m_pcSlice->isIntra()) |
---|
180 | { |
---|
181 | SliceType aSliceTypeChoices[] = {B_SLICE, P_SLICE}; |
---|
182 | |
---|
183 | UInt bestCost = MAX_UINT; |
---|
184 | SliceType bestSliceType = aSliceTypeChoices[0]; |
---|
185 | for (UInt idx=0; idx<2; idx++) |
---|
186 | { |
---|
187 | UInt curCost = 0; |
---|
188 | SliceType curSliceType = aSliceTypeChoices[idx]; |
---|
189 | |
---|
190 | curCost = m_cCUSplitFlagSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_SPLIT_FLAG ); |
---|
191 | curCost += m_cCUSkipFlagSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_SKIP_FLAG ); |
---|
192 | curCost += m_cCUMergeFlagExtSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_MERGE_FLAG_EXT); |
---|
193 | curCost += m_cCUMergeIdxExtSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_MERGE_IDX_EXT); |
---|
194 | curCost += m_cCUPartSizeSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_PART_SIZE ); |
---|
195 | curCost += m_cCUAMPSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_CU_AMP_POS ); |
---|
196 | curCost += m_cCUPredModeSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_PRED_MODE ); |
---|
197 | curCost += m_cCUIntraPredSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_INTRA_PRED_MODE ); |
---|
198 | curCost += m_cCUChromaPredSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_CHROMA_PRED_MODE ); |
---|
199 | curCost += m_cCUInterDirSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_INTER_DIR ); |
---|
200 | curCost += m_cCUMvdSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_MVD ); |
---|
201 | curCost += m_cCURefPicSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_REF_PIC ); |
---|
202 | curCost += m_cCUDeltaQpSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_DQP ); |
---|
203 | curCost += m_cCUQtCbfSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_QT_CBF ); |
---|
204 | curCost += m_cCUQtRootCbfSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_QT_ROOT_CBF ); |
---|
205 | curCost += m_cCUSigCoeffGroupSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_SIG_CG_FLAG ); |
---|
206 | curCost += m_cCUSigSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_SIG_FLAG ); |
---|
207 | curCost += m_cCuCtxLastX.calcCost ( curSliceType, qp, (UChar*)INIT_LAST ); |
---|
208 | curCost += m_cCuCtxLastY.calcCost ( curSliceType, qp, (UChar*)INIT_LAST ); |
---|
209 | curCost += m_cCUOneSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_ONE_FLAG ); |
---|
210 | curCost += m_cCUAbsSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_ABS_FLAG ); |
---|
211 | curCost += m_cMVPIdxSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_MVP_IDX ); |
---|
212 | curCost += m_cCUTransSubdivFlagSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_TRANS_SUBDIV_FLAG ); |
---|
213 | curCost += m_cSaoMergeSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_SAO_MERGE_FLAG ); |
---|
214 | curCost += m_cSaoTypeIdxSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_SAO_TYPE_IDX ); |
---|
215 | curCost += m_cTransformSkipSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_TRANSFORMSKIP_FLAG ); |
---|
216 | curCost += m_CUTransquantBypassFlagSCModel.calcCost( curSliceType, qp, (UChar*)INIT_CU_TRANSQUANT_BYPASS_FLAG ); |
---|
217 | #if H_3D_DIM |
---|
218 | if( m_pcSlice->getVpsDepthModesFlag() ) |
---|
219 | { |
---|
220 | curCost += m_cDepthIntraModeSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_DEPTH_INTRA_MODE ); |
---|
221 | curCost += m_cDdcFlagSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_DDC_FLAG ); |
---|
222 | curCost += m_cDdcDataSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_DDC_DATA ); |
---|
223 | #if H_3D_DIM_DMM |
---|
224 | curCost += m_cDmm1DataSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_DMM1_DATA ); |
---|
225 | curCost += m_cDmm2DataSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_DMM2_DATA ); |
---|
226 | curCost += m_cDmm3DataSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_DMM3_DATA ); |
---|
227 | #endif |
---|
228 | #if H_3D_DIM_RBC |
---|
229 | curCost += m_cRbcDataSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_RBC_DATA ); |
---|
230 | #endif |
---|
231 | } |
---|
232 | #endif |
---|
233 | if (curCost < bestCost) |
---|
234 | { |
---|
235 | bestSliceType = curSliceType; |
---|
236 | bestCost = curCost; |
---|
237 | } |
---|
238 | } |
---|
239 | m_pcSlice->getPPS()->setEncCABACTableIdx( bestSliceType ); |
---|
240 | } |
---|
241 | else |
---|
242 | { |
---|
243 | m_pcSlice->getPPS()->setEncCABACTableIdx( I_SLICE ); |
---|
244 | } |
---|
245 | } |
---|
246 | |
---|
247 | |
---|
248 | /** The function does the followng: Write out terminate bit. Flush CABAC. Intialize CABAC states. Start CABAC. |
---|
249 | */ |
---|
250 | Void TEncSbac::updateContextTables( SliceType eSliceType, Int iQp, Bool bExecuteFinish ) |
---|
251 | { |
---|
252 | m_pcBinIf->encodeBinTrm(1); |
---|
253 | if (bExecuteFinish) m_pcBinIf->finish(); |
---|
254 | m_cCUSplitFlagSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_SPLIT_FLAG ); |
---|
255 | |
---|
256 | m_cCUSkipFlagSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_SKIP_FLAG ); |
---|
257 | m_cCUMergeFlagExtSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_MERGE_FLAG_EXT); |
---|
258 | m_cCUMergeIdxExtSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_MERGE_IDX_EXT); |
---|
259 | m_cCUPartSizeSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_PART_SIZE ); |
---|
260 | m_cCUAMPSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_CU_AMP_POS ); |
---|
261 | m_cCUPredModeSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_PRED_MODE ); |
---|
262 | m_cCUIntraPredSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_INTRA_PRED_MODE ); |
---|
263 | m_cCUChromaPredSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_CHROMA_PRED_MODE ); |
---|
264 | m_cCUInterDirSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_INTER_DIR ); |
---|
265 | m_cCUMvdSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_MVD ); |
---|
266 | m_cCURefPicSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_REF_PIC ); |
---|
267 | m_cCUDeltaQpSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_DQP ); |
---|
268 | m_cCUQtCbfSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_QT_CBF ); |
---|
269 | m_cCUQtRootCbfSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_QT_ROOT_CBF ); |
---|
270 | m_cCUSigCoeffGroupSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_SIG_CG_FLAG ); |
---|
271 | m_cCUSigSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_SIG_FLAG ); |
---|
272 | m_cCuCtxLastX.initBuffer ( eSliceType, iQp, (UChar*)INIT_LAST ); |
---|
273 | m_cCuCtxLastY.initBuffer ( eSliceType, iQp, (UChar*)INIT_LAST ); |
---|
274 | m_cCUOneSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_ONE_FLAG ); |
---|
275 | m_cCUAbsSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_ABS_FLAG ); |
---|
276 | m_cMVPIdxSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_MVP_IDX ); |
---|
277 | m_cCUTransSubdivFlagSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_TRANS_SUBDIV_FLAG ); |
---|
278 | m_cSaoMergeSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_SAO_MERGE_FLAG ); |
---|
279 | m_cSaoTypeIdxSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_SAO_TYPE_IDX ); |
---|
280 | m_cTransformSkipSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_TRANSFORMSKIP_FLAG ); |
---|
281 | m_CUTransquantBypassFlagSCModel.initBuffer( eSliceType, iQp, (UChar*)INIT_CU_TRANSQUANT_BYPASS_FLAG ); |
---|
282 | |
---|
283 | #if H_3D_DIM |
---|
284 | m_cDepthIntraModeSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_DEPTH_INTRA_MODE ); |
---|
285 | m_cDdcFlagSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_DDC_FLAG ); |
---|
286 | m_cDdcDataSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_DDC_DATA ); |
---|
287 | #if H_3D_DIM_DMM |
---|
288 | m_cDmm1DataSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_DMM1_DATA ); |
---|
289 | m_cDmm2DataSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_DMM2_DATA ); |
---|
290 | m_cDmm3DataSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_DMM3_DATA ); |
---|
291 | #endif |
---|
292 | #if H_3D_DIM_RBC |
---|
293 | m_cRbcDataSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_RBC_DATA ); |
---|
294 | #endif |
---|
295 | #endif |
---|
296 | m_pcBinIf->start(); |
---|
297 | } |
---|
298 | |
---|
299 | Void TEncSbac::codeVPS( TComVPS* pcVPS ) |
---|
300 | { |
---|
301 | assert (0); |
---|
302 | return; |
---|
303 | } |
---|
304 | |
---|
305 | #if H_3D |
---|
306 | Void TEncSbac::codeSPS( TComSPS* pcSPS, Int viewIndex, Bool depthFlag ) |
---|
307 | #else |
---|
308 | Void TEncSbac::codeSPS( TComSPS* pcSPS ) |
---|
309 | #endif |
---|
310 | { |
---|
311 | assert (0); |
---|
312 | return; |
---|
313 | } |
---|
314 | |
---|
315 | Void TEncSbac::codePPS( TComPPS* pcPPS ) |
---|
316 | { |
---|
317 | assert (0); |
---|
318 | return; |
---|
319 | } |
---|
320 | |
---|
321 | Void TEncSbac::codeSliceHeader( TComSlice* pcSlice ) |
---|
322 | { |
---|
323 | assert (0); |
---|
324 | return; |
---|
325 | } |
---|
326 | |
---|
327 | Void TEncSbac::codeTilesWPPEntryPoint( TComSlice* pSlice ) |
---|
328 | { |
---|
329 | assert (0); |
---|
330 | return; |
---|
331 | } |
---|
332 | |
---|
333 | Void TEncSbac::codeTerminatingBit( UInt uilsLast ) |
---|
334 | { |
---|
335 | m_pcBinIf->encodeBinTrm( uilsLast ); |
---|
336 | } |
---|
337 | |
---|
338 | Void TEncSbac::codeSliceFinish() |
---|
339 | { |
---|
340 | m_pcBinIf->finish(); |
---|
341 | } |
---|
342 | |
---|
343 | Void TEncSbac::xWriteUnarySymbol( UInt uiSymbol, ContextModel* pcSCModel, Int iOffset ) |
---|
344 | { |
---|
345 | m_pcBinIf->encodeBin( uiSymbol ? 1 : 0, pcSCModel[0] ); |
---|
346 | |
---|
347 | if( 0 == uiSymbol) |
---|
348 | { |
---|
349 | return; |
---|
350 | } |
---|
351 | |
---|
352 | while( uiSymbol-- ) |
---|
353 | { |
---|
354 | m_pcBinIf->encodeBin( uiSymbol ? 1 : 0, pcSCModel[ iOffset ] ); |
---|
355 | } |
---|
356 | |
---|
357 | return; |
---|
358 | } |
---|
359 | |
---|
360 | Void TEncSbac::xWriteUnaryMaxSymbol( UInt uiSymbol, ContextModel* pcSCModel, Int iOffset, UInt uiMaxSymbol ) |
---|
361 | { |
---|
362 | if (uiMaxSymbol == 0) |
---|
363 | { |
---|
364 | return; |
---|
365 | } |
---|
366 | |
---|
367 | m_pcBinIf->encodeBin( uiSymbol ? 1 : 0, pcSCModel[ 0 ] ); |
---|
368 | |
---|
369 | if ( uiSymbol == 0 ) |
---|
370 | { |
---|
371 | return; |
---|
372 | } |
---|
373 | |
---|
374 | Bool bCodeLast = ( uiMaxSymbol > uiSymbol ); |
---|
375 | |
---|
376 | while( --uiSymbol ) |
---|
377 | { |
---|
378 | m_pcBinIf->encodeBin( 1, pcSCModel[ iOffset ] ); |
---|
379 | } |
---|
380 | if( bCodeLast ) |
---|
381 | { |
---|
382 | m_pcBinIf->encodeBin( 0, pcSCModel[ iOffset ] ); |
---|
383 | } |
---|
384 | |
---|
385 | return; |
---|
386 | } |
---|
387 | |
---|
388 | Void TEncSbac::xWriteEpExGolomb( UInt uiSymbol, UInt uiCount ) |
---|
389 | { |
---|
390 | UInt bins = 0; |
---|
391 | Int numBins = 0; |
---|
392 | |
---|
393 | while( uiSymbol >= (UInt)(1<<uiCount) ) |
---|
394 | { |
---|
395 | bins = 2 * bins + 1; |
---|
396 | numBins++; |
---|
397 | uiSymbol -= 1 << uiCount; |
---|
398 | uiCount ++; |
---|
399 | } |
---|
400 | bins = 2 * bins + 0; |
---|
401 | numBins++; |
---|
402 | |
---|
403 | bins = (bins << uiCount) | uiSymbol; |
---|
404 | numBins += uiCount; |
---|
405 | |
---|
406 | assert( numBins <= 32 ); |
---|
407 | m_pcBinIf->encodeBinsEP( bins, numBins ); |
---|
408 | } |
---|
409 | |
---|
410 | /** Coding of coeff_abs_level_minus3 |
---|
411 | * \param uiSymbol value of coeff_abs_level_minus3 |
---|
412 | * \param ruiGoRiceParam reference to Rice parameter |
---|
413 | * \returns Void |
---|
414 | */ |
---|
415 | Void TEncSbac::xWriteCoefRemainExGolomb ( UInt symbol, UInt &rParam ) |
---|
416 | { |
---|
417 | Int codeNumber = (Int)symbol; |
---|
418 | UInt length; |
---|
419 | if (codeNumber < (COEF_REMAIN_BIN_REDUCTION << rParam)) |
---|
420 | { |
---|
421 | length = codeNumber>>rParam; |
---|
422 | m_pcBinIf->encodeBinsEP( (1<<(length+1))-2 , length+1); |
---|
423 | m_pcBinIf->encodeBinsEP((codeNumber%(1<<rParam)),rParam); |
---|
424 | } |
---|
425 | else |
---|
426 | { |
---|
427 | length = rParam; |
---|
428 | codeNumber = codeNumber - ( COEF_REMAIN_BIN_REDUCTION << rParam); |
---|
429 | while (codeNumber >= (1<<length)) |
---|
430 | { |
---|
431 | codeNumber -= (1<<(length++)); |
---|
432 | } |
---|
433 | m_pcBinIf->encodeBinsEP((1<<(COEF_REMAIN_BIN_REDUCTION+length+1-rParam))-2,COEF_REMAIN_BIN_REDUCTION+length+1-rParam); |
---|
434 | m_pcBinIf->encodeBinsEP(codeNumber,length); |
---|
435 | } |
---|
436 | } |
---|
437 | |
---|
438 | #if H_3D_DIM |
---|
439 | Void TEncSbac::xWriteExGolombLevel( UInt uiSymbol, ContextModel& rcSCModel ) |
---|
440 | { |
---|
441 | if( uiSymbol ) |
---|
442 | { |
---|
443 | m_pcBinIf->encodeBin( 1, rcSCModel ); |
---|
444 | UInt uiCount = 0; |
---|
445 | Bool bNoExGo = (uiSymbol < 13); |
---|
446 | |
---|
447 | while( --uiSymbol && ++uiCount < 13 ) |
---|
448 | { |
---|
449 | m_pcBinIf->encodeBin( 1, rcSCModel ); |
---|
450 | } |
---|
451 | if( bNoExGo ) |
---|
452 | { |
---|
453 | m_pcBinIf->encodeBin( 0, rcSCModel ); |
---|
454 | } |
---|
455 | else |
---|
456 | { |
---|
457 | xWriteEpExGolomb( uiSymbol, 0 ); |
---|
458 | } |
---|
459 | } |
---|
460 | else |
---|
461 | { |
---|
462 | m_pcBinIf->encodeBin( 0, rcSCModel ); |
---|
463 | } |
---|
464 | |
---|
465 | return; |
---|
466 | } |
---|
467 | |
---|
468 | Void TEncSbac::xCodeDimDeltaDC( Pel valDeltaDC, UInt dimType ) |
---|
469 | { |
---|
470 | xWriteExGolombLevel( UInt( abs( valDeltaDC ) ), m_cDdcDataSCModel.get(0, 0, (RBC_IDX == dimType) ? 1 : 0) ); |
---|
471 | if( valDeltaDC != 0 ) |
---|
472 | { |
---|
473 | UInt uiSign = valDeltaDC > 0 ? 0 : 1; |
---|
474 | m_pcBinIf->encodeBinEP( uiSign ); |
---|
475 | } |
---|
476 | } |
---|
477 | |
---|
478 | #if H_3D_DIM_DMM |
---|
479 | Void TEncSbac::xCodeDmm1WedgeIdx( UInt uiTabIdx, Int iNumBit ) |
---|
480 | { |
---|
481 | for ( Int i = 0; i < iNumBit; i++ ) |
---|
482 | { |
---|
483 | m_pcBinIf->encodeBin( ( uiTabIdx >> i ) & 1, m_cDmm1DataSCModel.get(0, 0, 0) ); |
---|
484 | } |
---|
485 | } |
---|
486 | |
---|
487 | Void TEncSbac::xCodeDmm2Offset( Int iOffset ) |
---|
488 | { |
---|
489 | if( DMM2_DELTAEND_MAX > 0 ) |
---|
490 | { |
---|
491 | m_pcBinIf->encodeBin( (iOffset != 0) , m_cDmm2DataSCModel.get(0, 0, 0) ); |
---|
492 | if( iOffset != 0 ) |
---|
493 | { |
---|
494 | UInt uiAbsValMinus1 = abs(iOffset)-1; |
---|
495 | m_pcBinIf->encodeBin( (uiAbsValMinus1 & 0x01), m_cDmm2DataSCModel.get(0, 0, 0) ); |
---|
496 | m_pcBinIf->encodeBin( (uiAbsValMinus1 & 0x02) >> 1, m_cDmm2DataSCModel.get(0, 0, 0) ); |
---|
497 | |
---|
498 | UInt uiSign = (iOffset > 0) ? 0 : 1; |
---|
499 | m_pcBinIf->encodeBinEP( uiSign ); |
---|
500 | } |
---|
501 | } |
---|
502 | } |
---|
503 | |
---|
504 | Void TEncSbac::xCodeDmm3WedgeIdx( UInt uiIntraIdx, Int iNumBit ) |
---|
505 | { |
---|
506 | for( Int i = 0; i < iNumBit; i++ ) |
---|
507 | { |
---|
508 | m_pcBinIf->encodeBin( ( uiIntraIdx >> i ) & 1, m_cDmm3DataSCModel.get(0, 0, 0) ); |
---|
509 | } |
---|
510 | } |
---|
511 | #endif |
---|
512 | #if H_3D_DIM_RBC |
---|
513 | Void TEncSbac::xCodeRbcEdge( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
514 | { |
---|
515 | UInt uiDepth = pcCU->getDepth( uiAbsPartIdx ) + (pcCU->getPartitionSize( uiAbsPartIdx ) == SIZE_NxN ? 1 : 0); |
---|
516 | UChar* pucSymbolList = pcCU->getEdgeCode ( uiAbsPartIdx ); |
---|
517 | UChar ucEdgeNumber = pcCU->getEdgeNumber ( uiAbsPartIdx ); |
---|
518 | Bool bLeft = pcCU->getEdgeLeftFirst( uiAbsPartIdx ); |
---|
519 | UChar ucStart = pcCU->getEdgeStartPos ( uiAbsPartIdx ); |
---|
520 | UInt uiSymbol; |
---|
521 | |
---|
522 | // 1. Top(0) or Left(1) |
---|
523 | uiSymbol = (bLeft == false) ? 0 : 1; |
---|
524 | m_pcBinIf->encodeBinEP( uiSymbol ); |
---|
525 | |
---|
526 | // 2. Start position (lowest bit first) |
---|
527 | uiSymbol = ucStart; |
---|
528 | for( UInt ui = 6; ui > uiDepth; ui-- ) // 64(0)->6, 32(1)->5, 16(2)->4, 8(3)->3, 4(4)->2 |
---|
529 | { |
---|
530 | m_pcBinIf->encodeBinEP( uiSymbol & 0x1 ); |
---|
531 | uiSymbol >>= 1; |
---|
532 | } |
---|
533 | |
---|
534 | // 3. Number of edges |
---|
535 | uiSymbol = ucEdgeNumber > 0 ? ucEdgeNumber - 1 : 0; |
---|
536 | for( UInt ui = 7; ui > uiDepth; ui-- ) // 64(0)->7, 32(1)->6, 16(2)->5, 8(3)->4, 4(4)->3 |
---|
537 | { |
---|
538 | m_pcBinIf->encodeBinEP( uiSymbol & 0x1 ); |
---|
539 | uiSymbol >>= 1; |
---|
540 | } |
---|
541 | |
---|
542 | if(uiSymbol != 0) |
---|
543 | { |
---|
544 | printf(" ucEdgeNumber %d at depth %d\n",ucEdgeNumber, uiDepth); |
---|
545 | assert(false); |
---|
546 | } |
---|
547 | |
---|
548 | // 4. Edges |
---|
549 | for( Int iPtr2 = 0; iPtr2 < ucEdgeNumber; iPtr2++ ) |
---|
550 | { |
---|
551 | UInt uiReorderSymbol = pucSymbolList[iPtr2]; |
---|
552 | for( UInt ui = 0; ui < uiReorderSymbol; ui++ ) |
---|
553 | { |
---|
554 | m_pcBinIf->encodeBin( 1, m_cRbcDataSCModel.get( 0, 0, 0 ) ); |
---|
555 | } |
---|
556 | |
---|
557 | if( uiReorderSymbol != 6 ) |
---|
558 | m_pcBinIf->encodeBin( 0, m_cRbcDataSCModel.get( 0, 0, 0 ) ); |
---|
559 | } |
---|
560 | } |
---|
561 | #endif |
---|
562 | #endif |
---|
563 | |
---|
564 | // SBAC RD |
---|
565 | Void TEncSbac::load ( TEncSbac* pSrc) |
---|
566 | { |
---|
567 | this->xCopyFrom(pSrc); |
---|
568 | } |
---|
569 | |
---|
570 | Void TEncSbac::loadIntraDirModeLuma( TEncSbac* pSrc) |
---|
571 | { |
---|
572 | m_pcBinIf->copyState( pSrc->m_pcBinIf ); |
---|
573 | |
---|
574 | this->m_cCUIntraPredSCModel .copyFrom( &pSrc->m_cCUIntraPredSCModel ); |
---|
575 | } |
---|
576 | #if H_3D_DIM |
---|
577 | Void TEncSbac::loadIntraDepthMode( TEncSbac* pSrc) |
---|
578 | { |
---|
579 | m_pcBinIf->copyState( pSrc->m_pcBinIf ); |
---|
580 | |
---|
581 | this->m_cDepthIntraModeSCModel .copyFrom( &pSrc->m_cDepthIntraModeSCModel ); |
---|
582 | this->m_cDdcFlagSCModel .copyFrom( &pSrc->m_cDdcFlagSCModel ); |
---|
583 | } |
---|
584 | #endif |
---|
585 | |
---|
586 | Void TEncSbac::store( TEncSbac* pDest) |
---|
587 | { |
---|
588 | pDest->xCopyFrom( this ); |
---|
589 | } |
---|
590 | |
---|
591 | |
---|
592 | Void TEncSbac::xCopyFrom( TEncSbac* pSrc ) |
---|
593 | { |
---|
594 | m_pcBinIf->copyState( pSrc->m_pcBinIf ); |
---|
595 | |
---|
596 | this->m_uiCoeffCost = pSrc->m_uiCoeffCost; |
---|
597 | this->m_uiLastQp = pSrc->m_uiLastQp; |
---|
598 | |
---|
599 | memcpy( m_contextModels, pSrc->m_contextModels, m_numContextModels * sizeof( ContextModel ) ); |
---|
600 | } |
---|
601 | |
---|
602 | Void TEncSbac::codeMVPIdx ( TComDataCU* pcCU, UInt uiAbsPartIdx, RefPicList eRefList ) |
---|
603 | { |
---|
604 | Int iSymbol = pcCU->getMVPIdx(eRefList, uiAbsPartIdx); |
---|
605 | Int iNum = AMVP_MAX_NUM_CANDS; |
---|
606 | |
---|
607 | xWriteUnaryMaxSymbol(iSymbol, m_cMVPIdxSCModel.get(0), 1, iNum-1); |
---|
608 | } |
---|
609 | |
---|
610 | Void TEncSbac::codePartSize( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth ) |
---|
611 | { |
---|
612 | PartSize eSize = pcCU->getPartitionSize( uiAbsPartIdx ); |
---|
613 | if ( pcCU->isIntra( uiAbsPartIdx ) ) |
---|
614 | { |
---|
615 | if( uiDepth == g_uiMaxCUDepth - g_uiAddCUDepth ) |
---|
616 | { |
---|
617 | m_pcBinIf->encodeBin( eSize == SIZE_2Nx2N? 1 : 0, m_cCUPartSizeSCModel.get( 0, 0, 0 ) ); |
---|
618 | } |
---|
619 | return; |
---|
620 | } |
---|
621 | |
---|
622 | switch(eSize) |
---|
623 | { |
---|
624 | case SIZE_2Nx2N: |
---|
625 | { |
---|
626 | m_pcBinIf->encodeBin( 1, m_cCUPartSizeSCModel.get( 0, 0, 0) ); |
---|
627 | break; |
---|
628 | } |
---|
629 | case SIZE_2NxN: |
---|
630 | case SIZE_2NxnU: |
---|
631 | case SIZE_2NxnD: |
---|
632 | { |
---|
633 | m_pcBinIf->encodeBin( 0, m_cCUPartSizeSCModel.get( 0, 0, 0) ); |
---|
634 | m_pcBinIf->encodeBin( 1, m_cCUPartSizeSCModel.get( 0, 0, 1) ); |
---|
635 | if ( pcCU->getSlice()->getSPS()->getAMPAcc( uiDepth ) ) |
---|
636 | { |
---|
637 | if (eSize == SIZE_2NxN) |
---|
638 | { |
---|
639 | m_pcBinIf->encodeBin(1, m_cCUAMPSCModel.get( 0, 0, 0 )); |
---|
640 | } |
---|
641 | else |
---|
642 | { |
---|
643 | m_pcBinIf->encodeBin(0, m_cCUAMPSCModel.get( 0, 0, 0 )); |
---|
644 | m_pcBinIf->encodeBinEP((eSize == SIZE_2NxnU? 0: 1)); |
---|
645 | } |
---|
646 | } |
---|
647 | break; |
---|
648 | } |
---|
649 | case SIZE_Nx2N: |
---|
650 | case SIZE_nLx2N: |
---|
651 | case SIZE_nRx2N: |
---|
652 | { |
---|
653 | m_pcBinIf->encodeBin( 0, m_cCUPartSizeSCModel.get( 0, 0, 0) ); |
---|
654 | m_pcBinIf->encodeBin( 0, m_cCUPartSizeSCModel.get( 0, 0, 1) ); |
---|
655 | if( uiDepth == g_uiMaxCUDepth - g_uiAddCUDepth && !( pcCU->getWidth(uiAbsPartIdx) == 8 && pcCU->getHeight(uiAbsPartIdx) == 8 ) ) |
---|
656 | { |
---|
657 | m_pcBinIf->encodeBin( 1, m_cCUPartSizeSCModel.get( 0, 0, 2) ); |
---|
658 | } |
---|
659 | if ( pcCU->getSlice()->getSPS()->getAMPAcc( uiDepth ) ) |
---|
660 | { |
---|
661 | if (eSize == SIZE_Nx2N) |
---|
662 | { |
---|
663 | m_pcBinIf->encodeBin(1, m_cCUAMPSCModel.get( 0, 0, 0 )); |
---|
664 | } |
---|
665 | else |
---|
666 | { |
---|
667 | m_pcBinIf->encodeBin(0, m_cCUAMPSCModel.get( 0, 0, 0 )); |
---|
668 | m_pcBinIf->encodeBinEP((eSize == SIZE_nLx2N? 0: 1)); |
---|
669 | } |
---|
670 | } |
---|
671 | break; |
---|
672 | } |
---|
673 | case SIZE_NxN: |
---|
674 | { |
---|
675 | if( uiDepth == g_uiMaxCUDepth - g_uiAddCUDepth && !( pcCU->getWidth(uiAbsPartIdx) == 8 && pcCU->getHeight(uiAbsPartIdx) == 8 ) ) |
---|
676 | { |
---|
677 | m_pcBinIf->encodeBin( 0, m_cCUPartSizeSCModel.get( 0, 0, 0) ); |
---|
678 | m_pcBinIf->encodeBin( 0, m_cCUPartSizeSCModel.get( 0, 0, 1) ); |
---|
679 | m_pcBinIf->encodeBin( 0, m_cCUPartSizeSCModel.get( 0, 0, 2) ); |
---|
680 | } |
---|
681 | break; |
---|
682 | } |
---|
683 | default: |
---|
684 | { |
---|
685 | assert(0); |
---|
686 | } |
---|
687 | } |
---|
688 | } |
---|
689 | |
---|
690 | /** code prediction mode |
---|
691 | * \param pcCU |
---|
692 | * \param uiAbsPartIdx |
---|
693 | * \returns Void |
---|
694 | */ |
---|
695 | Void TEncSbac::codePredMode( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
696 | { |
---|
697 | // get context function is here |
---|
698 | Int iPredMode = pcCU->getPredictionMode( uiAbsPartIdx ); |
---|
699 | m_pcBinIf->encodeBin( iPredMode == MODE_INTER ? 0 : 1, m_cCUPredModeSCModel.get( 0, 0, 0 ) ); |
---|
700 | } |
---|
701 | |
---|
702 | Void TEncSbac::codeCUTransquantBypassFlag( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
703 | { |
---|
704 | UInt uiSymbol = pcCU->getCUTransquantBypass(uiAbsPartIdx); |
---|
705 | m_pcBinIf->encodeBin( uiSymbol, m_CUTransquantBypassFlagSCModel.get( 0, 0, 0 ) ); |
---|
706 | } |
---|
707 | |
---|
708 | /** code skip flag |
---|
709 | * \param pcCU |
---|
710 | * \param uiAbsPartIdx |
---|
711 | * \returns Void |
---|
712 | */ |
---|
713 | Void TEncSbac::codeSkipFlag( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
714 | { |
---|
715 | // get context function is here |
---|
716 | UInt uiSymbol = pcCU->isSkipped( uiAbsPartIdx ) ? 1 : 0; |
---|
717 | UInt uiCtxSkip = pcCU->getCtxSkipFlag( uiAbsPartIdx ) ; |
---|
718 | m_pcBinIf->encodeBin( uiSymbol, m_cCUSkipFlagSCModel.get( 0, 0, uiCtxSkip ) ); |
---|
719 | DTRACE_CABAC_VL( g_nSymbolCounter++ ); |
---|
720 | DTRACE_CABAC_T( "\tSkipFlag" ); |
---|
721 | DTRACE_CABAC_T( "\tuiCtxSkip: "); |
---|
722 | DTRACE_CABAC_V( uiCtxSkip ); |
---|
723 | DTRACE_CABAC_T( "\tuiSymbol: "); |
---|
724 | DTRACE_CABAC_V( uiSymbol ); |
---|
725 | DTRACE_CABAC_T( "\n"); |
---|
726 | } |
---|
727 | |
---|
728 | /** code merge flag |
---|
729 | * \param pcCU |
---|
730 | * \param uiAbsPartIdx |
---|
731 | * \returns Void |
---|
732 | */ |
---|
733 | Void TEncSbac::codeMergeFlag( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
734 | { |
---|
735 | const UInt uiSymbol = pcCU->getMergeFlag( uiAbsPartIdx ) ? 1 : 0; |
---|
736 | m_pcBinIf->encodeBin( uiSymbol, *m_cCUMergeFlagExtSCModel.get( 0 ) ); |
---|
737 | |
---|
738 | DTRACE_CABAC_VL( g_nSymbolCounter++ ); |
---|
739 | DTRACE_CABAC_T( "\tMergeFlag: " ); |
---|
740 | DTRACE_CABAC_V( uiSymbol ); |
---|
741 | DTRACE_CABAC_T( "\tAddress: " ); |
---|
742 | DTRACE_CABAC_V( pcCU->getAddr() ); |
---|
743 | DTRACE_CABAC_T( "\tuiAbsPartIdx: " ); |
---|
744 | DTRACE_CABAC_V( uiAbsPartIdx ); |
---|
745 | DTRACE_CABAC_T( "\n" ); |
---|
746 | } |
---|
747 | |
---|
748 | /** code merge index |
---|
749 | * \param pcCU |
---|
750 | * \param uiAbsPartIdx |
---|
751 | * \returns Void |
---|
752 | */ |
---|
753 | Void TEncSbac::codeMergeIndex( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
754 | { |
---|
755 | UInt uiUnaryIdx = pcCU->getMergeIndex( uiAbsPartIdx ); |
---|
756 | UInt uiNumCand = pcCU->getSlice()->getMaxNumMergeCand(); |
---|
757 | if ( uiNumCand > 1 ) |
---|
758 | { |
---|
759 | for( UInt ui = 0; ui < uiNumCand - 1; ++ui ) |
---|
760 | { |
---|
761 | const UInt uiSymbol = ui == uiUnaryIdx ? 0 : 1; |
---|
762 | if ( ui==0 ) |
---|
763 | { |
---|
764 | m_pcBinIf->encodeBin( uiSymbol, m_cCUMergeIdxExtSCModel.get( 0, 0, 0 ) ); |
---|
765 | } |
---|
766 | else |
---|
767 | { |
---|
768 | m_pcBinIf->encodeBinEP( uiSymbol ); |
---|
769 | } |
---|
770 | if( uiSymbol == 0 ) |
---|
771 | { |
---|
772 | break; |
---|
773 | } |
---|
774 | } |
---|
775 | } |
---|
776 | DTRACE_CABAC_VL( g_nSymbolCounter++ ); |
---|
777 | DTRACE_CABAC_T( "\tparseMergeIndex()" ); |
---|
778 | DTRACE_CABAC_T( "\tuiMRGIdx= " ); |
---|
779 | DTRACE_CABAC_V( pcCU->getMergeIndex( uiAbsPartIdx ) ); |
---|
780 | DTRACE_CABAC_T( "\n" ); |
---|
781 | } |
---|
782 | |
---|
783 | Void TEncSbac::codeSplitFlag ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth ) |
---|
784 | { |
---|
785 | if( uiDepth == g_uiMaxCUDepth - g_uiAddCUDepth ) |
---|
786 | return; |
---|
787 | |
---|
788 | UInt uiCtx = pcCU->getCtxSplitFlag( uiAbsPartIdx, uiDepth ); |
---|
789 | UInt uiCurrSplitFlag = ( pcCU->getDepth( uiAbsPartIdx ) > uiDepth ) ? 1 : 0; |
---|
790 | |
---|
791 | assert( uiCtx < 3 ); |
---|
792 | m_pcBinIf->encodeBin( uiCurrSplitFlag, m_cCUSplitFlagSCModel.get( 0, 0, uiCtx ) ); |
---|
793 | DTRACE_CABAC_VL( g_nSymbolCounter++ ) |
---|
794 | DTRACE_CABAC_T( "\tSplitFlag\n" ) |
---|
795 | return; |
---|
796 | } |
---|
797 | |
---|
798 | Void TEncSbac::codeTransformSubdivFlag( UInt uiSymbol, UInt uiCtx ) |
---|
799 | { |
---|
800 | m_pcBinIf->encodeBin( uiSymbol, m_cCUTransSubdivFlagSCModel.get( 0, 0, uiCtx ) ); |
---|
801 | DTRACE_CABAC_VL( g_nSymbolCounter++ ) |
---|
802 | DTRACE_CABAC_T( "\tparseTransformSubdivFlag()" ) |
---|
803 | DTRACE_CABAC_T( "\tsymbol=" ) |
---|
804 | DTRACE_CABAC_V( uiSymbol ) |
---|
805 | DTRACE_CABAC_T( "\tctx=" ) |
---|
806 | DTRACE_CABAC_V( uiCtx ) |
---|
807 | DTRACE_CABAC_T( "\n" ) |
---|
808 | } |
---|
809 | |
---|
810 | Void TEncSbac::codeIntraDirLumaAng( TComDataCU* pcCU, UInt absPartIdx, Bool isMultiple) |
---|
811 | { |
---|
812 | UInt dir[4],j; |
---|
813 | Int preds[4][3] = {{-1, -1, -1},{-1, -1, -1},{-1, -1, -1},{-1, -1, -1}}; |
---|
814 | Int predNum[4], predIdx[4] ={ -1,-1,-1,-1}; |
---|
815 | PartSize mode = pcCU->getPartitionSize( absPartIdx ); |
---|
816 | UInt partNum = isMultiple?(mode==SIZE_NxN?4:1):1; |
---|
817 | UInt partOffset = ( pcCU->getPic()->getNumPartInCU() >> ( pcCU->getDepth(absPartIdx) << 1 ) ) >> 2; |
---|
818 | for (j=0;j<partNum;j++) |
---|
819 | { |
---|
820 | dir[j] = pcCU->getLumaIntraDir( absPartIdx+partOffset*j ); |
---|
821 | #if H_3D_DIM |
---|
822 | if( pcCU->getSlice()->getVpsDepthModesFlag() ) |
---|
823 | { |
---|
824 | codeIntraDepth( pcCU, absPartIdx+partOffset*j ); |
---|
825 | } |
---|
826 | if( pcCU->getLumaIntraDir( absPartIdx+partOffset*j ) < NUM_INTRA_MODE ) |
---|
827 | #if H_3D_DIM_SDC |
---|
828 | if( !pcCU->getSDCFlag( absPartIdx+partOffset*j ) ) |
---|
829 | #endif |
---|
830 | { |
---|
831 | #endif |
---|
832 | predNum[j] = pcCU->getIntraDirLumaPredictor(absPartIdx+partOffset*j, preds[j]); |
---|
833 | for(UInt i = 0; i < predNum[j]; i++) |
---|
834 | { |
---|
835 | if(dir[j] == preds[j][i]) |
---|
836 | { |
---|
837 | predIdx[j] = i; |
---|
838 | } |
---|
839 | } |
---|
840 | m_pcBinIf->encodeBin((predIdx[j] != -1)? 1 : 0, m_cCUIntraPredSCModel.get( 0, 0, 0 ) ); |
---|
841 | #if H_3D_DIM |
---|
842 | } |
---|
843 | #endif |
---|
844 | } |
---|
845 | for (j=0;j<partNum;j++) |
---|
846 | { |
---|
847 | #if H_3D_DIM |
---|
848 | if( pcCU->getLumaIntraDir( absPartIdx+partOffset*j ) < NUM_INTRA_MODE ) |
---|
849 | #if H_3D_DIM_SDC |
---|
850 | if( !pcCU->getSDCFlag( absPartIdx+partOffset*j ) ) |
---|
851 | #endif |
---|
852 | { |
---|
853 | #endif |
---|
854 | if(predIdx[j] != -1) |
---|
855 | { |
---|
856 | m_pcBinIf->encodeBinEP( predIdx[j] ? 1 : 0 ); |
---|
857 | if (predIdx[j]) |
---|
858 | { |
---|
859 | m_pcBinIf->encodeBinEP( predIdx[j]-1 ); |
---|
860 | } |
---|
861 | } |
---|
862 | else |
---|
863 | { |
---|
864 | if (preds[j][0] > preds[j][1]) |
---|
865 | { |
---|
866 | std::swap(preds[j][0], preds[j][1]); |
---|
867 | } |
---|
868 | if (preds[j][0] > preds[j][2]) |
---|
869 | { |
---|
870 | std::swap(preds[j][0], preds[j][2]); |
---|
871 | } |
---|
872 | if (preds[j][1] > preds[j][2]) |
---|
873 | { |
---|
874 | std::swap(preds[j][1], preds[j][2]); |
---|
875 | } |
---|
876 | for(Int i = (predNum[j] - 1); i >= 0; i--) |
---|
877 | { |
---|
878 | dir[j] = dir[j] > preds[j][i] ? dir[j] - 1 : dir[j]; |
---|
879 | } |
---|
880 | m_pcBinIf->encodeBinsEP( dir[j], 5 ); |
---|
881 | } |
---|
882 | #if H_3D_DIM |
---|
883 | } |
---|
884 | #endif |
---|
885 | } |
---|
886 | return; |
---|
887 | } |
---|
888 | |
---|
889 | Void TEncSbac::codeIntraDirChroma( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
890 | { |
---|
891 | UInt uiIntraDirChroma = pcCU->getChromaIntraDir( uiAbsPartIdx ); |
---|
892 | |
---|
893 | if( uiIntraDirChroma == DM_CHROMA_IDX ) |
---|
894 | { |
---|
895 | m_pcBinIf->encodeBin( 0, m_cCUChromaPredSCModel.get( 0, 0, 0 ) ); |
---|
896 | } |
---|
897 | else |
---|
898 | { |
---|
899 | UInt uiAllowedChromaDir[ NUM_CHROMA_MODE ]; |
---|
900 | pcCU->getAllowedChromaDir( uiAbsPartIdx, uiAllowedChromaDir ); |
---|
901 | |
---|
902 | for( Int i = 0; i < NUM_CHROMA_MODE - 1; i++ ) |
---|
903 | { |
---|
904 | if( uiIntraDirChroma == uiAllowedChromaDir[i] ) |
---|
905 | { |
---|
906 | uiIntraDirChroma = i; |
---|
907 | break; |
---|
908 | } |
---|
909 | } |
---|
910 | m_pcBinIf->encodeBin( 1, m_cCUChromaPredSCModel.get( 0, 0, 0 ) ); |
---|
911 | |
---|
912 | m_pcBinIf->encodeBinsEP( uiIntraDirChroma, 2 ); |
---|
913 | } |
---|
914 | return; |
---|
915 | } |
---|
916 | |
---|
917 | #if H_3D_DIM |
---|
918 | Void TEncSbac::codeIntraDepth( TComDataCU* pcCU, UInt absPartIdx, Bool sdcRD ) |
---|
919 | { |
---|
920 | codeIntraDepthMode( pcCU, absPartIdx ); |
---|
921 | |
---|
922 | UInt dir = pcCU->getLumaIntraDir( absPartIdx ); |
---|
923 | UInt dimType = getDimType( dir ); |
---|
924 | |
---|
925 | switch( dimType ) |
---|
926 | { |
---|
927 | #if H_3D_DIM_DMM |
---|
928 | case( DMM1_IDX ): |
---|
929 | { |
---|
930 | xCodeDmm1WedgeIdx( pcCU->getDmmWedgeTabIdx( dimType, absPartIdx ), g_dmm1TabIdxBits[pcCU->getIntraSizeIdx(absPartIdx)] ); |
---|
931 | } break; |
---|
932 | case( DMM2_IDX ): |
---|
933 | { |
---|
934 | xCodeDmm2Offset( pcCU->getDmm2DeltaEnd( absPartIdx ) ); |
---|
935 | } break; |
---|
936 | case( DMM3_IDX ): |
---|
937 | { |
---|
938 | xCodeDmm3WedgeIdx( pcCU->getDmm3IntraTabIdx( absPartIdx ), g_dmm3IntraTabIdxBits[pcCU->getIntraSizeIdx(absPartIdx)] ); |
---|
939 | } break; |
---|
940 | case( DMM4_IDX ): break; |
---|
941 | #endif |
---|
942 | #if H_3D_DIM_RBC |
---|
943 | case( RBC_IDX ): |
---|
944 | { |
---|
945 | assert( pcCU->getWidth( absPartIdx ) < 64 ); |
---|
946 | xCodeRbcEdge( pcCU, absPartIdx ); |
---|
947 | } break; |
---|
948 | #endif |
---|
949 | default: break; |
---|
950 | } |
---|
951 | |
---|
952 | #if H_3D_DIM_SDC |
---|
953 | if( pcCU->getSDCFlag( absPartIdx ) ) |
---|
954 | { |
---|
955 | // assert(pcCU->getPartitionSize(uiAbsPartIdx)==SIZE_2Nx2N); |
---|
956 | // UInt uiNumSegments = ( uiDir == DC_IDX || uiDir == PLANAR_IDX )? 1 : 2; |
---|
957 | // if(!bSdcRD) |
---|
958 | // { |
---|
959 | // for (int uiSeg=0; uiSeg<uiNumSegments; uiSeg++) |
---|
960 | // { |
---|
961 | // codeSDCResidualData(pcCU, uiAbsPartIdx, uiSeg); |
---|
962 | // } |
---|
963 | // } |
---|
964 | } |
---|
965 | else |
---|
966 | { |
---|
967 | #endif |
---|
968 | if( dimType < DIM_NUM_TYPE ) |
---|
969 | { |
---|
970 | UInt dimDeltaDC = isDimDeltaDC( dir ); |
---|
971 | m_pcBinIf->encodeBin( dimDeltaDC, m_cDdcFlagSCModel.get(0, 0, (RBC_IDX == dimType) ? 1 : 0) ); |
---|
972 | if( dimDeltaDC ) |
---|
973 | { |
---|
974 | for( UInt segment = 0; segment < 2; segment++ ) |
---|
975 | { |
---|
976 | xCodeDimDeltaDC( pcCU->getDimDeltaDC( dimType, segment, absPartIdx ), dimType ); |
---|
977 | } |
---|
978 | } |
---|
979 | } |
---|
980 | #if H_3D_DIM_SDC |
---|
981 | } |
---|
982 | #endif |
---|
983 | } |
---|
984 | |
---|
985 | Void TEncSbac::codeIntraDepthMode( TComDataCU* pcCU, UInt absPartIdx ) |
---|
986 | { |
---|
987 | UInt codeWordTable[3][9] = {{0, 0, 0, 2, 0,6, 0, 0, 7},{0, 2, 3, 4, 5, 6, 14, 31, 30},{0, 2, 0, 0, 0, 0, 3, 0, 0}}; |
---|
988 | UInt codeWordLenTable[3][9] = {{0, 1, 0, 2, 0,3, 0, 0, 3},{2, 3, 3, 3, 3, 3, 4, 5, 5},{1, 2, 0, 0, 0, 0, 2, 0, 0}}; |
---|
989 | UInt dir = pcCU->getLumaIntraDir( absPartIdx ); |
---|
990 | UInt puIdx = (pcCU->getWidth(absPartIdx) == 64) ? 2 : ( (pcCU->getPartitionSize(absPartIdx) == SIZE_NxN && pcCU->getWidth(absPartIdx) == 8) ? 0 : 1 ); |
---|
991 | UInt codeIdx = 0; |
---|
992 | |
---|
993 | if( dir < NUM_INTRA_MODE ) |
---|
994 | { |
---|
995 | codeIdx = 1; |
---|
996 | } |
---|
997 | if( isDimMode( dir ) ) |
---|
998 | { |
---|
999 | switch( getDimType( dir ) ) |
---|
1000 | { |
---|
1001 | case DMM1_IDX: codeIdx = 3; break; |
---|
1002 | case DMM4_IDX: codeIdx = 4; break; |
---|
1003 | case DMM3_IDX: codeIdx = 5; break; |
---|
1004 | case DMM2_IDX: codeIdx = 7; break; |
---|
1005 | case RBC_IDX: codeIdx = 8; break; |
---|
1006 | default: break; |
---|
1007 | } |
---|
1008 | } |
---|
1009 | |
---|
1010 | #if H_3D_DIM_SDC |
---|
1011 | if( pcCU->getSDCFlag( absPartIdx ) ) |
---|
1012 | { |
---|
1013 | // switch( dir ) |
---|
1014 | // { |
---|
1015 | // case PLANAR_IDX: codeIdx = 0; break; |
---|
1016 | // case DC_IDX: codeIdx = 6; break; |
---|
1017 | // case (2*DMM1_IDX+DIM_OFFSET): codeIdx = 2; break; |
---|
1018 | // default: break; |
---|
1019 | // } |
---|
1020 | } |
---|
1021 | #endif |
---|
1022 | //mode coding |
---|
1023 | for( UInt i = 0; i < codeWordLenTable[puIdx][codeIdx]; i++ ) |
---|
1024 | { |
---|
1025 | UInt bit = codeWordTable[puIdx][codeIdx] & ( 1<<(codeWordLenTable[puIdx][codeIdx] - i - 1) ); |
---|
1026 | UInt ctxDepthMode = puIdx*3 + ( (i >= 2) ? 2 : i ); |
---|
1027 | m_pcBinIf->encodeBin( bit!=0 , m_cDepthIntraModeSCModel.get(0, 0, ctxDepthMode) ); |
---|
1028 | } |
---|
1029 | } |
---|
1030 | #endif |
---|
1031 | |
---|
1032 | Void TEncSbac::codeInterDir( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
1033 | { |
---|
1034 | const UInt uiInterDir = pcCU->getInterDir( uiAbsPartIdx ) - 1; |
---|
1035 | const UInt uiCtx = pcCU->getCtxInterDir( uiAbsPartIdx ); |
---|
1036 | ContextModel *pCtx = m_cCUInterDirSCModel.get( 0 ); |
---|
1037 | if (pcCU->getPartitionSize(uiAbsPartIdx) == SIZE_2Nx2N || pcCU->getHeight(uiAbsPartIdx) != 8 ) |
---|
1038 | { |
---|
1039 | m_pcBinIf->encodeBin( uiInterDir == 2 ? 1 : 0, *( pCtx + uiCtx ) ); |
---|
1040 | } |
---|
1041 | if (uiInterDir < 2) |
---|
1042 | { |
---|
1043 | m_pcBinIf->encodeBin( uiInterDir, *( pCtx + 4 ) ); |
---|
1044 | } |
---|
1045 | return; |
---|
1046 | } |
---|
1047 | |
---|
1048 | Void TEncSbac::codeRefFrmIdx( TComDataCU* pcCU, UInt uiAbsPartIdx, RefPicList eRefList ) |
---|
1049 | { |
---|
1050 | { |
---|
1051 | Int iRefFrame = pcCU->getCUMvField( eRefList )->getRefIdx( uiAbsPartIdx ); |
---|
1052 | ContextModel *pCtx = m_cCURefPicSCModel.get( 0 ); |
---|
1053 | m_pcBinIf->encodeBin( ( iRefFrame == 0 ? 0 : 1 ), *pCtx ); |
---|
1054 | |
---|
1055 | if( iRefFrame > 0 ) |
---|
1056 | { |
---|
1057 | UInt uiRefNum = pcCU->getSlice()->getNumRefIdx( eRefList ) - 2; |
---|
1058 | pCtx++; |
---|
1059 | iRefFrame--; |
---|
1060 | for( UInt ui = 0; ui < uiRefNum; ++ui ) |
---|
1061 | { |
---|
1062 | const UInt uiSymbol = ui == iRefFrame ? 0 : 1; |
---|
1063 | if( ui == 0 ) |
---|
1064 | { |
---|
1065 | m_pcBinIf->encodeBin( uiSymbol, *pCtx ); |
---|
1066 | } |
---|
1067 | else |
---|
1068 | { |
---|
1069 | m_pcBinIf->encodeBinEP( uiSymbol ); |
---|
1070 | } |
---|
1071 | if( uiSymbol == 0 ) |
---|
1072 | { |
---|
1073 | break; |
---|
1074 | } |
---|
1075 | } |
---|
1076 | } |
---|
1077 | } |
---|
1078 | return; |
---|
1079 | } |
---|
1080 | |
---|
1081 | Void TEncSbac::codeMvd( TComDataCU* pcCU, UInt uiAbsPartIdx, RefPicList eRefList ) |
---|
1082 | { |
---|
1083 | if(pcCU->getSlice()->getMvdL1ZeroFlag() && eRefList == REF_PIC_LIST_1 && pcCU->getInterDir(uiAbsPartIdx)==3) |
---|
1084 | { |
---|
1085 | return; |
---|
1086 | } |
---|
1087 | |
---|
1088 | const TComCUMvField* pcCUMvField = pcCU->getCUMvField( eRefList ); |
---|
1089 | const Int iHor = pcCUMvField->getMvd( uiAbsPartIdx ).getHor(); |
---|
1090 | const Int iVer = pcCUMvField->getMvd( uiAbsPartIdx ).getVer(); |
---|
1091 | ContextModel* pCtx = m_cCUMvdSCModel.get( 0 ); |
---|
1092 | |
---|
1093 | m_pcBinIf->encodeBin( iHor != 0 ? 1 : 0, *pCtx ); |
---|
1094 | m_pcBinIf->encodeBin( iVer != 0 ? 1 : 0, *pCtx ); |
---|
1095 | |
---|
1096 | const Bool bHorAbsGr0 = iHor != 0; |
---|
1097 | const Bool bVerAbsGr0 = iVer != 0; |
---|
1098 | const UInt uiHorAbs = 0 > iHor ? -iHor : iHor; |
---|
1099 | const UInt uiVerAbs = 0 > iVer ? -iVer : iVer; |
---|
1100 | pCtx++; |
---|
1101 | |
---|
1102 | if( bHorAbsGr0 ) |
---|
1103 | { |
---|
1104 | m_pcBinIf->encodeBin( uiHorAbs > 1 ? 1 : 0, *pCtx ); |
---|
1105 | } |
---|
1106 | |
---|
1107 | if( bVerAbsGr0 ) |
---|
1108 | { |
---|
1109 | m_pcBinIf->encodeBin( uiVerAbs > 1 ? 1 : 0, *pCtx ); |
---|
1110 | } |
---|
1111 | |
---|
1112 | if( bHorAbsGr0 ) |
---|
1113 | { |
---|
1114 | if( uiHorAbs > 1 ) |
---|
1115 | { |
---|
1116 | xWriteEpExGolomb( uiHorAbs-2, 1 ); |
---|
1117 | } |
---|
1118 | |
---|
1119 | m_pcBinIf->encodeBinEP( 0 > iHor ? 1 : 0 ); |
---|
1120 | } |
---|
1121 | |
---|
1122 | if( bVerAbsGr0 ) |
---|
1123 | { |
---|
1124 | if( uiVerAbs > 1 ) |
---|
1125 | { |
---|
1126 | xWriteEpExGolomb( uiVerAbs-2, 1 ); |
---|
1127 | } |
---|
1128 | |
---|
1129 | m_pcBinIf->encodeBinEP( 0 > iVer ? 1 : 0 ); |
---|
1130 | } |
---|
1131 | |
---|
1132 | return; |
---|
1133 | } |
---|
1134 | |
---|
1135 | Void TEncSbac::codeDeltaQP( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
1136 | { |
---|
1137 | Int iDQp = pcCU->getQP( uiAbsPartIdx ) - pcCU->getRefQP( uiAbsPartIdx ); |
---|
1138 | |
---|
1139 | Int qpBdOffsetY = pcCU->getSlice()->getSPS()->getQpBDOffsetY(); |
---|
1140 | iDQp = (iDQp + 78 + qpBdOffsetY + (qpBdOffsetY/2)) % (52 + qpBdOffsetY) - 26 - (qpBdOffsetY/2); |
---|
1141 | |
---|
1142 | UInt uiAbsDQp = (UInt)((iDQp > 0)? iDQp : (-iDQp)); |
---|
1143 | UInt TUValue = min((Int)uiAbsDQp, CU_DQP_TU_CMAX); |
---|
1144 | xWriteUnaryMaxSymbol( TUValue, &m_cCUDeltaQpSCModel.get( 0, 0, 0 ), 1, CU_DQP_TU_CMAX); |
---|
1145 | if( uiAbsDQp >= CU_DQP_TU_CMAX ) |
---|
1146 | { |
---|
1147 | xWriteEpExGolomb( uiAbsDQp - CU_DQP_TU_CMAX, CU_DQP_EG_k ); |
---|
1148 | } |
---|
1149 | |
---|
1150 | if ( uiAbsDQp > 0) |
---|
1151 | { |
---|
1152 | UInt uiSign = (iDQp > 0 ? 0 : 1); |
---|
1153 | m_pcBinIf->encodeBinEP(uiSign); |
---|
1154 | } |
---|
1155 | |
---|
1156 | return; |
---|
1157 | } |
---|
1158 | |
---|
1159 | Void TEncSbac::codeQtCbf( TComDataCU* pcCU, UInt uiAbsPartIdx, TextType eType, UInt uiTrDepth ) |
---|
1160 | { |
---|
1161 | UInt uiCbf = pcCU->getCbf ( uiAbsPartIdx, eType, uiTrDepth ); |
---|
1162 | UInt uiCtx = pcCU->getCtxQtCbf( eType, uiTrDepth ); |
---|
1163 | m_pcBinIf->encodeBin( uiCbf , m_cCUQtCbfSCModel.get( 0, eType ? TEXT_CHROMA : eType, uiCtx ) ); |
---|
1164 | DTRACE_CABAC_VL( g_nSymbolCounter++ ) |
---|
1165 | DTRACE_CABAC_T( "\tparseQtCbf()" ) |
---|
1166 | DTRACE_CABAC_T( "\tsymbol=" ) |
---|
1167 | DTRACE_CABAC_V( uiCbf ) |
---|
1168 | DTRACE_CABAC_T( "\tctx=" ) |
---|
1169 | DTRACE_CABAC_V( uiCtx ) |
---|
1170 | DTRACE_CABAC_T( "\tetype=" ) |
---|
1171 | DTRACE_CABAC_V( eType ) |
---|
1172 | DTRACE_CABAC_T( "\tuiAbsPartIdx=" ) |
---|
1173 | DTRACE_CABAC_V( uiAbsPartIdx ) |
---|
1174 | DTRACE_CABAC_T( "\n" ) |
---|
1175 | } |
---|
1176 | |
---|
1177 | void TEncSbac::codeTransformSkipFlags (TComDataCU* pcCU, UInt uiAbsPartIdx, UInt width, UInt height, TextType eTType ) |
---|
1178 | { |
---|
1179 | if (pcCU->getCUTransquantBypass(uiAbsPartIdx)) |
---|
1180 | { |
---|
1181 | return; |
---|
1182 | } |
---|
1183 | if(width != 4 || height != 4) |
---|
1184 | { |
---|
1185 | return; |
---|
1186 | } |
---|
1187 | |
---|
1188 | UInt useTransformSkip = pcCU->getTransformSkip( uiAbsPartIdx,eTType); |
---|
1189 | m_pcBinIf->encodeBin( useTransformSkip, m_cTransformSkipSCModel.get( 0, eTType? TEXT_CHROMA: TEXT_LUMA, 0 ) ); |
---|
1190 | DTRACE_CABAC_VL( g_nSymbolCounter++ ) |
---|
1191 | DTRACE_CABAC_T("\tparseTransformSkip()"); |
---|
1192 | DTRACE_CABAC_T( "\tsymbol=" ) |
---|
1193 | DTRACE_CABAC_V( useTransformSkip ) |
---|
1194 | DTRACE_CABAC_T( "\tAddr=" ) |
---|
1195 | DTRACE_CABAC_V( pcCU->getAddr() ) |
---|
1196 | DTRACE_CABAC_T( "\tetype=" ) |
---|
1197 | DTRACE_CABAC_V( eTType ) |
---|
1198 | DTRACE_CABAC_T( "\tuiAbsPartIdx=" ) |
---|
1199 | DTRACE_CABAC_V( uiAbsPartIdx ) |
---|
1200 | DTRACE_CABAC_T( "\n" ) |
---|
1201 | } |
---|
1202 | |
---|
1203 | /** Code I_PCM information. |
---|
1204 | * \param pcCU pointer to CU |
---|
1205 | * \param uiAbsPartIdx CU index |
---|
1206 | * \returns Void |
---|
1207 | */ |
---|
1208 | Void TEncSbac::codeIPCMInfo( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
1209 | { |
---|
1210 | UInt uiIPCM = (pcCU->getIPCMFlag(uiAbsPartIdx) == true)? 1 : 0; |
---|
1211 | |
---|
1212 | Bool writePCMSampleFlag = pcCU->getIPCMFlag(uiAbsPartIdx); |
---|
1213 | |
---|
1214 | m_pcBinIf->encodeBinTrm (uiIPCM); |
---|
1215 | |
---|
1216 | if (writePCMSampleFlag) |
---|
1217 | { |
---|
1218 | m_pcBinIf->encodePCMAlignBits(); |
---|
1219 | |
---|
1220 | UInt uiMinCoeffSize = pcCU->getPic()->getMinCUWidth()*pcCU->getPic()->getMinCUHeight(); |
---|
1221 | UInt uiLumaOffset = uiMinCoeffSize*uiAbsPartIdx; |
---|
1222 | UInt uiChromaOffset = uiLumaOffset>>2; |
---|
1223 | Pel* piPCMSample; |
---|
1224 | UInt uiWidth; |
---|
1225 | UInt uiHeight; |
---|
1226 | UInt uiSampleBits; |
---|
1227 | UInt uiX, uiY; |
---|
1228 | |
---|
1229 | piPCMSample = pcCU->getPCMSampleY() + uiLumaOffset; |
---|
1230 | uiWidth = pcCU->getWidth(uiAbsPartIdx); |
---|
1231 | uiHeight = pcCU->getHeight(uiAbsPartIdx); |
---|
1232 | uiSampleBits = pcCU->getSlice()->getSPS()->getPCMBitDepthLuma(); |
---|
1233 | |
---|
1234 | for(uiY = 0; uiY < uiHeight; uiY++) |
---|
1235 | { |
---|
1236 | for(uiX = 0; uiX < uiWidth; uiX++) |
---|
1237 | { |
---|
1238 | UInt uiSample = piPCMSample[uiX]; |
---|
1239 | |
---|
1240 | m_pcBinIf->xWritePCMCode(uiSample, uiSampleBits); |
---|
1241 | } |
---|
1242 | piPCMSample += uiWidth; |
---|
1243 | } |
---|
1244 | |
---|
1245 | piPCMSample = pcCU->getPCMSampleCb() + uiChromaOffset; |
---|
1246 | uiWidth = pcCU->getWidth(uiAbsPartIdx)/2; |
---|
1247 | uiHeight = pcCU->getHeight(uiAbsPartIdx)/2; |
---|
1248 | uiSampleBits = pcCU->getSlice()->getSPS()->getPCMBitDepthChroma(); |
---|
1249 | |
---|
1250 | for(uiY = 0; uiY < uiHeight; uiY++) |
---|
1251 | { |
---|
1252 | for(uiX = 0; uiX < uiWidth; uiX++) |
---|
1253 | { |
---|
1254 | UInt uiSample = piPCMSample[uiX]; |
---|
1255 | |
---|
1256 | m_pcBinIf->xWritePCMCode(uiSample, uiSampleBits); |
---|
1257 | } |
---|
1258 | piPCMSample += uiWidth; |
---|
1259 | } |
---|
1260 | |
---|
1261 | piPCMSample = pcCU->getPCMSampleCr() + uiChromaOffset; |
---|
1262 | uiWidth = pcCU->getWidth(uiAbsPartIdx)/2; |
---|
1263 | uiHeight = pcCU->getHeight(uiAbsPartIdx)/2; |
---|
1264 | uiSampleBits = pcCU->getSlice()->getSPS()->getPCMBitDepthChroma(); |
---|
1265 | |
---|
1266 | for(uiY = 0; uiY < uiHeight; uiY++) |
---|
1267 | { |
---|
1268 | for(uiX = 0; uiX < uiWidth; uiX++) |
---|
1269 | { |
---|
1270 | UInt uiSample = piPCMSample[uiX]; |
---|
1271 | |
---|
1272 | m_pcBinIf->xWritePCMCode(uiSample, uiSampleBits); |
---|
1273 | } |
---|
1274 | piPCMSample += uiWidth; |
---|
1275 | } |
---|
1276 | m_pcBinIf->resetBac(); |
---|
1277 | } |
---|
1278 | } |
---|
1279 | |
---|
1280 | Void TEncSbac::codeQtRootCbf( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
1281 | { |
---|
1282 | UInt uiCbf = pcCU->getQtRootCbf( uiAbsPartIdx ); |
---|
1283 | UInt uiCtx = 0; |
---|
1284 | m_pcBinIf->encodeBin( uiCbf , m_cCUQtRootCbfSCModel.get( 0, 0, uiCtx ) ); |
---|
1285 | DTRACE_CABAC_VL( g_nSymbolCounter++ ) |
---|
1286 | DTRACE_CABAC_T( "\tparseQtRootCbf()" ) |
---|
1287 | DTRACE_CABAC_T( "\tsymbol=" ) |
---|
1288 | DTRACE_CABAC_V( uiCbf ) |
---|
1289 | DTRACE_CABAC_T( "\tctx=" ) |
---|
1290 | DTRACE_CABAC_V( uiCtx ) |
---|
1291 | DTRACE_CABAC_T( "\tuiAbsPartIdx=" ) |
---|
1292 | DTRACE_CABAC_V( uiAbsPartIdx ) |
---|
1293 | DTRACE_CABAC_T( "\n" ) |
---|
1294 | } |
---|
1295 | |
---|
1296 | Void TEncSbac::codeQtCbfZero( TComDataCU* pcCU, TextType eType, UInt uiTrDepth ) |
---|
1297 | { |
---|
1298 | // this function is only used to estimate the bits when cbf is 0 |
---|
1299 | // and will never be called when writing the bistream. do not need to write log |
---|
1300 | UInt uiCbf = 0; |
---|
1301 | UInt uiCtx = pcCU->getCtxQtCbf( eType, uiTrDepth ); |
---|
1302 | m_pcBinIf->encodeBin( uiCbf , m_cCUQtCbfSCModel.get( 0, eType ? TEXT_CHROMA : eType, uiCtx ) ); |
---|
1303 | } |
---|
1304 | |
---|
1305 | Void TEncSbac::codeQtRootCbfZero( TComDataCU* pcCU ) |
---|
1306 | { |
---|
1307 | // this function is only used to estimate the bits when cbf is 0 |
---|
1308 | // and will never be called when writing the bistream. do not need to write log |
---|
1309 | UInt uiCbf = 0; |
---|
1310 | UInt uiCtx = 0; |
---|
1311 | m_pcBinIf->encodeBin( uiCbf , m_cCUQtRootCbfSCModel.get( 0, 0, uiCtx ) ); |
---|
1312 | } |
---|
1313 | |
---|
1314 | /** Encode (X,Y) position of the last significant coefficient |
---|
1315 | * \param uiPosX X component of last coefficient |
---|
1316 | * \param uiPosY Y component of last coefficient |
---|
1317 | * \param width Block width |
---|
1318 | * \param height Block height |
---|
1319 | * \param eTType plane type / luminance or chrominance |
---|
1320 | * \param uiScanIdx scan type (zig-zag, hor, ver) |
---|
1321 | * This method encodes the X and Y component within a block of the last significant coefficient. |
---|
1322 | */ |
---|
1323 | Void TEncSbac::codeLastSignificantXY( UInt uiPosX, UInt uiPosY, Int width, Int height, TextType eTType, UInt uiScanIdx ) |
---|
1324 | { |
---|
1325 | // swap |
---|
1326 | if( uiScanIdx == SCAN_VER ) |
---|
1327 | { |
---|
1328 | swap( uiPosX, uiPosY ); |
---|
1329 | } |
---|
1330 | |
---|
1331 | UInt uiCtxLast; |
---|
1332 | ContextModel *pCtxX = m_cCuCtxLastX.get( 0, eTType ); |
---|
1333 | ContextModel *pCtxY = m_cCuCtxLastY.get( 0, eTType ); |
---|
1334 | UInt uiGroupIdxX = g_uiGroupIdx[ uiPosX ]; |
---|
1335 | UInt uiGroupIdxY = g_uiGroupIdx[ uiPosY ]; |
---|
1336 | |
---|
1337 | |
---|
1338 | Int blkSizeOffsetX, blkSizeOffsetY, shiftX, shiftY; |
---|
1339 | blkSizeOffsetX = eTType ? 0: (g_aucConvertToBit[ width ] *3 + ((g_aucConvertToBit[ width ] +1)>>2)); |
---|
1340 | blkSizeOffsetY = eTType ? 0: (g_aucConvertToBit[ height ]*3 + ((g_aucConvertToBit[ height ]+1)>>2)); |
---|
1341 | shiftX= eTType ? g_aucConvertToBit[ width ] :((g_aucConvertToBit[ width ]+3)>>2); |
---|
1342 | shiftY= eTType ? g_aucConvertToBit[ height ] :((g_aucConvertToBit[ height ]+3)>>2); |
---|
1343 | // posX |
---|
1344 | for( uiCtxLast = 0; uiCtxLast < uiGroupIdxX; uiCtxLast++ ) |
---|
1345 | { |
---|
1346 | m_pcBinIf->encodeBin( 1, *( pCtxX + blkSizeOffsetX + (uiCtxLast >>shiftX) ) ); |
---|
1347 | } |
---|
1348 | if( uiGroupIdxX < g_uiGroupIdx[ width - 1 ]) |
---|
1349 | { |
---|
1350 | m_pcBinIf->encodeBin( 0, *( pCtxX + blkSizeOffsetX + (uiCtxLast >>shiftX) ) ); |
---|
1351 | } |
---|
1352 | |
---|
1353 | // posY |
---|
1354 | for( uiCtxLast = 0; uiCtxLast < uiGroupIdxY; uiCtxLast++ ) |
---|
1355 | { |
---|
1356 | m_pcBinIf->encodeBin( 1, *( pCtxY + blkSizeOffsetY + (uiCtxLast >>shiftY) ) ); |
---|
1357 | } |
---|
1358 | if( uiGroupIdxY < g_uiGroupIdx[ height - 1 ]) |
---|
1359 | { |
---|
1360 | m_pcBinIf->encodeBin( 0, *( pCtxY + blkSizeOffsetY + (uiCtxLast >>shiftY) ) ); |
---|
1361 | } |
---|
1362 | if ( uiGroupIdxX > 3 ) |
---|
1363 | { |
---|
1364 | UInt uiCount = ( uiGroupIdxX - 2 ) >> 1; |
---|
1365 | uiPosX = uiPosX - g_uiMinInGroup[ uiGroupIdxX ]; |
---|
1366 | for (Int i = uiCount - 1 ; i >= 0; i-- ) |
---|
1367 | { |
---|
1368 | m_pcBinIf->encodeBinEP( ( uiPosX >> i ) & 1 ); |
---|
1369 | } |
---|
1370 | } |
---|
1371 | if ( uiGroupIdxY > 3 ) |
---|
1372 | { |
---|
1373 | UInt uiCount = ( uiGroupIdxY - 2 ) >> 1; |
---|
1374 | uiPosY = uiPosY - g_uiMinInGroup[ uiGroupIdxY ]; |
---|
1375 | for ( Int i = uiCount - 1 ; i >= 0; i-- ) |
---|
1376 | { |
---|
1377 | m_pcBinIf->encodeBinEP( ( uiPosY >> i ) & 1 ); |
---|
1378 | } |
---|
1379 | } |
---|
1380 | } |
---|
1381 | |
---|
1382 | Void TEncSbac::codeCoeffNxN( TComDataCU* pcCU, TCoeff* pcCoef, UInt uiAbsPartIdx, UInt uiWidth, UInt uiHeight, UInt uiDepth, TextType eTType ) |
---|
1383 | { |
---|
1384 | DTRACE_CABAC_VL( g_nSymbolCounter++ ) |
---|
1385 | DTRACE_CABAC_T( "\tparseCoeffNxN()\teType=" ) |
---|
1386 | DTRACE_CABAC_V( eTType ) |
---|
1387 | DTRACE_CABAC_T( "\twidth=" ) |
---|
1388 | DTRACE_CABAC_V( uiWidth ) |
---|
1389 | DTRACE_CABAC_T( "\theight=" ) |
---|
1390 | DTRACE_CABAC_V( uiHeight ) |
---|
1391 | DTRACE_CABAC_T( "\tdepth=" ) |
---|
1392 | DTRACE_CABAC_V( uiDepth ) |
---|
1393 | DTRACE_CABAC_T( "\tabspartidx=" ) |
---|
1394 | DTRACE_CABAC_V( uiAbsPartIdx ) |
---|
1395 | DTRACE_CABAC_T( "\ttoCU-X=" ) |
---|
1396 | DTRACE_CABAC_V( pcCU->getCUPelX() ) |
---|
1397 | DTRACE_CABAC_T( "\ttoCU-Y=" ) |
---|
1398 | DTRACE_CABAC_V( pcCU->getCUPelY() ) |
---|
1399 | DTRACE_CABAC_T( "\tCU-addr=" ) |
---|
1400 | DTRACE_CABAC_V( pcCU->getAddr() ) |
---|
1401 | DTRACE_CABAC_T( "\tinCU-X=" ) |
---|
1402 | DTRACE_CABAC_V( g_auiRasterToPelX[ g_auiZscanToRaster[uiAbsPartIdx] ] ) |
---|
1403 | DTRACE_CABAC_T( "\tinCU-Y=" ) |
---|
1404 | DTRACE_CABAC_V( g_auiRasterToPelY[ g_auiZscanToRaster[uiAbsPartIdx] ] ) |
---|
1405 | DTRACE_CABAC_T( "\tpredmode=" ) |
---|
1406 | DTRACE_CABAC_V( pcCU->getPredictionMode( uiAbsPartIdx ) ) |
---|
1407 | DTRACE_CABAC_T( "\n" ) |
---|
1408 | |
---|
1409 | if( uiWidth > m_pcSlice->getSPS()->getMaxTrSize() ) |
---|
1410 | { |
---|
1411 | uiWidth = m_pcSlice->getSPS()->getMaxTrSize(); |
---|
1412 | uiHeight = m_pcSlice->getSPS()->getMaxTrSize(); |
---|
1413 | } |
---|
1414 | |
---|
1415 | UInt uiNumSig = 0; |
---|
1416 | |
---|
1417 | // compute number of significant coefficients |
---|
1418 | uiNumSig = TEncEntropy::countNonZeroCoeffs(pcCoef, uiWidth * uiHeight); |
---|
1419 | |
---|
1420 | if ( uiNumSig == 0 ) |
---|
1421 | return; |
---|
1422 | if(pcCU->getSlice()->getPPS()->getUseTransformSkip()) |
---|
1423 | { |
---|
1424 | codeTransformSkipFlags( pcCU,uiAbsPartIdx, uiWidth, uiHeight, eTType ); |
---|
1425 | } |
---|
1426 | eTType = eTType == TEXT_LUMA ? TEXT_LUMA : ( eTType == TEXT_NONE ? TEXT_NONE : TEXT_CHROMA ); |
---|
1427 | |
---|
1428 | //----- encode significance map ----- |
---|
1429 | const UInt uiLog2BlockSize = g_aucConvertToBit[ uiWidth ] + 2; |
---|
1430 | UInt uiScanIdx = pcCU->getCoefScanIdx(uiAbsPartIdx, uiWidth, eTType==TEXT_LUMA, pcCU->isIntra(uiAbsPartIdx)); |
---|
1431 | const UInt *scan = g_auiSigLastScan[ uiScanIdx ][ uiLog2BlockSize - 1 ]; |
---|
1432 | |
---|
1433 | Bool beValid; |
---|
1434 | if (pcCU->getCUTransquantBypass(uiAbsPartIdx)) |
---|
1435 | { |
---|
1436 | beValid = false; |
---|
1437 | } |
---|
1438 | else |
---|
1439 | { |
---|
1440 | beValid = pcCU->getSlice()->getPPS()->getSignHideFlag() > 0; |
---|
1441 | } |
---|
1442 | |
---|
1443 | // Find position of last coefficient |
---|
1444 | Int scanPosLast = -1; |
---|
1445 | Int posLast; |
---|
1446 | |
---|
1447 | const UInt * scanCG; |
---|
1448 | { |
---|
1449 | scanCG = g_auiSigLastScan[ uiScanIdx ][ uiLog2BlockSize > 3 ? uiLog2BlockSize-2-1 : 0 ]; |
---|
1450 | if( uiLog2BlockSize == 3 ) |
---|
1451 | { |
---|
1452 | scanCG = g_sigLastScan8x8[ uiScanIdx ]; |
---|
1453 | } |
---|
1454 | else if( uiLog2BlockSize == 5 ) |
---|
1455 | { |
---|
1456 | scanCG = g_sigLastScanCG32x32; |
---|
1457 | } |
---|
1458 | } |
---|
1459 | UInt uiSigCoeffGroupFlag[ MLS_GRP_NUM ]; |
---|
1460 | static const UInt uiShift = MLS_CG_SIZE >> 1; |
---|
1461 | const UInt uiNumBlkSide = uiWidth >> uiShift; |
---|
1462 | |
---|
1463 | ::memset( uiSigCoeffGroupFlag, 0, sizeof(UInt) * MLS_GRP_NUM ); |
---|
1464 | |
---|
1465 | do |
---|
1466 | { |
---|
1467 | posLast = scan[ ++scanPosLast ]; |
---|
1468 | |
---|
1469 | // get L1 sig map |
---|
1470 | UInt uiPosY = posLast >> uiLog2BlockSize; |
---|
1471 | UInt uiPosX = posLast - ( uiPosY << uiLog2BlockSize ); |
---|
1472 | UInt uiBlkIdx = uiNumBlkSide * (uiPosY >> uiShift) + (uiPosX >> uiShift); |
---|
1473 | if( pcCoef[ posLast ] ) |
---|
1474 | { |
---|
1475 | uiSigCoeffGroupFlag[ uiBlkIdx ] = 1; |
---|
1476 | } |
---|
1477 | |
---|
1478 | uiNumSig -= ( pcCoef[ posLast ] != 0 ); |
---|
1479 | } |
---|
1480 | while ( uiNumSig > 0 ); |
---|
1481 | |
---|
1482 | // Code position of last coefficient |
---|
1483 | Int posLastY = posLast >> uiLog2BlockSize; |
---|
1484 | Int posLastX = posLast - ( posLastY << uiLog2BlockSize ); |
---|
1485 | codeLastSignificantXY(posLastX, posLastY, uiWidth, uiHeight, eTType, uiScanIdx); |
---|
1486 | |
---|
1487 | //===== code significance flag ===== |
---|
1488 | ContextModel * const baseCoeffGroupCtx = m_cCUSigCoeffGroupSCModel.get( 0, eTType ); |
---|
1489 | ContextModel * const baseCtx = (eTType==TEXT_LUMA) ? m_cCUSigSCModel.get( 0, 0 ) : m_cCUSigSCModel.get( 0, 0 ) + NUM_SIG_FLAG_CTX_LUMA; |
---|
1490 | |
---|
1491 | |
---|
1492 | const Int iLastScanSet = scanPosLast >> LOG2_SCAN_SET_SIZE; |
---|
1493 | UInt c1 = 1; |
---|
1494 | UInt uiGoRiceParam = 0; |
---|
1495 | Int iScanPosSig = scanPosLast; |
---|
1496 | |
---|
1497 | for( Int iSubSet = iLastScanSet; iSubSet >= 0; iSubSet-- ) |
---|
1498 | { |
---|
1499 | Int numNonZero = 0; |
---|
1500 | Int iSubPos = iSubSet << LOG2_SCAN_SET_SIZE; |
---|
1501 | uiGoRiceParam = 0; |
---|
1502 | Int absCoeff[16]; |
---|
1503 | UInt coeffSigns = 0; |
---|
1504 | |
---|
1505 | Int lastNZPosInCG = -1, firstNZPosInCG = SCAN_SET_SIZE; |
---|
1506 | |
---|
1507 | if( iScanPosSig == scanPosLast ) |
---|
1508 | { |
---|
1509 | absCoeff[ 0 ] = abs( pcCoef[ posLast ] ); |
---|
1510 | coeffSigns = ( pcCoef[ posLast ] < 0 ); |
---|
1511 | numNonZero = 1; |
---|
1512 | lastNZPosInCG = iScanPosSig; |
---|
1513 | firstNZPosInCG = iScanPosSig; |
---|
1514 | iScanPosSig--; |
---|
1515 | } |
---|
1516 | |
---|
1517 | // encode significant_coeffgroup_flag |
---|
1518 | Int iCGBlkPos = scanCG[ iSubSet ]; |
---|
1519 | Int iCGPosY = iCGBlkPos / uiNumBlkSide; |
---|
1520 | Int iCGPosX = iCGBlkPos - (iCGPosY * uiNumBlkSide); |
---|
1521 | if( iSubSet == iLastScanSet || iSubSet == 0) |
---|
1522 | { |
---|
1523 | uiSigCoeffGroupFlag[ iCGBlkPos ] = 1; |
---|
1524 | } |
---|
1525 | else |
---|
1526 | { |
---|
1527 | UInt uiSigCoeffGroup = (uiSigCoeffGroupFlag[ iCGBlkPos ] != 0); |
---|
1528 | UInt uiCtxSig = TComTrQuant::getSigCoeffGroupCtxInc( uiSigCoeffGroupFlag, iCGPosX, iCGPosY, uiWidth, uiHeight ); |
---|
1529 | m_pcBinIf->encodeBin( uiSigCoeffGroup, baseCoeffGroupCtx[ uiCtxSig ] ); |
---|
1530 | } |
---|
1531 | |
---|
1532 | // encode significant_coeff_flag |
---|
1533 | if( uiSigCoeffGroupFlag[ iCGBlkPos ] ) |
---|
1534 | { |
---|
1535 | Int patternSigCtx = TComTrQuant::calcPatternSigCtx( uiSigCoeffGroupFlag, iCGPosX, iCGPosY, uiWidth, uiHeight ); |
---|
1536 | UInt uiBlkPos, uiPosY, uiPosX, uiSig, uiCtxSig; |
---|
1537 | for( ; iScanPosSig >= iSubPos; iScanPosSig-- ) |
---|
1538 | { |
---|
1539 | uiBlkPos = scan[ iScanPosSig ]; |
---|
1540 | uiPosY = uiBlkPos >> uiLog2BlockSize; |
---|
1541 | uiPosX = uiBlkPos - ( uiPosY << uiLog2BlockSize ); |
---|
1542 | uiSig = (pcCoef[ uiBlkPos ] != 0); |
---|
1543 | if( iScanPosSig > iSubPos || iSubSet == 0 || numNonZero ) |
---|
1544 | { |
---|
1545 | uiCtxSig = TComTrQuant::getSigCtxInc( patternSigCtx, uiScanIdx, uiPosX, uiPosY, uiLog2BlockSize, eTType ); |
---|
1546 | m_pcBinIf->encodeBin( uiSig, baseCtx[ uiCtxSig ] ); |
---|
1547 | } |
---|
1548 | if( uiSig ) |
---|
1549 | { |
---|
1550 | absCoeff[ numNonZero ] = abs( pcCoef[ uiBlkPos ] ); |
---|
1551 | coeffSigns = 2 * coeffSigns + ( pcCoef[ uiBlkPos ] < 0 ); |
---|
1552 | numNonZero++; |
---|
1553 | if( lastNZPosInCG == -1 ) |
---|
1554 | { |
---|
1555 | lastNZPosInCG = iScanPosSig; |
---|
1556 | } |
---|
1557 | firstNZPosInCG = iScanPosSig; |
---|
1558 | } |
---|
1559 | } |
---|
1560 | } |
---|
1561 | else |
---|
1562 | { |
---|
1563 | iScanPosSig = iSubPos - 1; |
---|
1564 | } |
---|
1565 | |
---|
1566 | if( numNonZero > 0 ) |
---|
1567 | { |
---|
1568 | Bool signHidden = ( lastNZPosInCG - firstNZPosInCG >= SBH_THRESHOLD ); |
---|
1569 | UInt uiCtxSet = (iSubSet > 0 && eTType==TEXT_LUMA) ? 2 : 0; |
---|
1570 | |
---|
1571 | if( c1 == 0 ) |
---|
1572 | { |
---|
1573 | uiCtxSet++; |
---|
1574 | } |
---|
1575 | c1 = 1; |
---|
1576 | ContextModel *baseCtxMod = ( eTType==TEXT_LUMA ) ? m_cCUOneSCModel.get( 0, 0 ) + 4 * uiCtxSet : m_cCUOneSCModel.get( 0, 0 ) + NUM_ONE_FLAG_CTX_LUMA + 4 * uiCtxSet; |
---|
1577 | |
---|
1578 | Int numC1Flag = min(numNonZero, C1FLAG_NUMBER); |
---|
1579 | Int firstC2FlagIdx = -1; |
---|
1580 | for( Int idx = 0; idx < numC1Flag; idx++ ) |
---|
1581 | { |
---|
1582 | UInt uiSymbol = absCoeff[ idx ] > 1; |
---|
1583 | m_pcBinIf->encodeBin( uiSymbol, baseCtxMod[c1] ); |
---|
1584 | if( uiSymbol ) |
---|
1585 | { |
---|
1586 | c1 = 0; |
---|
1587 | |
---|
1588 | if (firstC2FlagIdx == -1) |
---|
1589 | { |
---|
1590 | firstC2FlagIdx = idx; |
---|
1591 | } |
---|
1592 | } |
---|
1593 | else if( (c1 < 3) && (c1 > 0) ) |
---|
1594 | { |
---|
1595 | c1++; |
---|
1596 | } |
---|
1597 | } |
---|
1598 | |
---|
1599 | if (c1 == 0) |
---|
1600 | { |
---|
1601 | |
---|
1602 | baseCtxMod = ( eTType==TEXT_LUMA ) ? m_cCUAbsSCModel.get( 0, 0 ) + uiCtxSet : m_cCUAbsSCModel.get( 0, 0 ) + NUM_ABS_FLAG_CTX_LUMA + uiCtxSet; |
---|
1603 | if ( firstC2FlagIdx != -1) |
---|
1604 | { |
---|
1605 | UInt symbol = absCoeff[ firstC2FlagIdx ] > 2; |
---|
1606 | m_pcBinIf->encodeBin( symbol, baseCtxMod[0] ); |
---|
1607 | } |
---|
1608 | } |
---|
1609 | |
---|
1610 | if( beValid && signHidden ) |
---|
1611 | { |
---|
1612 | m_pcBinIf->encodeBinsEP( (coeffSigns >> 1), numNonZero-1 ); |
---|
1613 | } |
---|
1614 | else |
---|
1615 | { |
---|
1616 | m_pcBinIf->encodeBinsEP( coeffSigns, numNonZero ); |
---|
1617 | } |
---|
1618 | |
---|
1619 | Int iFirstCoeff2 = 1; |
---|
1620 | if (c1 == 0 || numNonZero > C1FLAG_NUMBER) |
---|
1621 | { |
---|
1622 | for ( Int idx = 0; idx < numNonZero; idx++ ) |
---|
1623 | { |
---|
1624 | UInt baseLevel = (idx < C1FLAG_NUMBER)? (2 + iFirstCoeff2 ) : 1; |
---|
1625 | |
---|
1626 | if( absCoeff[ idx ] >= baseLevel) |
---|
1627 | { |
---|
1628 | xWriteCoefRemainExGolomb( absCoeff[ idx ] - baseLevel, uiGoRiceParam ); |
---|
1629 | if(absCoeff[idx] > 3*(1<<uiGoRiceParam)) |
---|
1630 | { |
---|
1631 | uiGoRiceParam = min<UInt>(uiGoRiceParam+ 1, 4); |
---|
1632 | } |
---|
1633 | } |
---|
1634 | if(absCoeff[ idx ] >= 2) |
---|
1635 | { |
---|
1636 | iFirstCoeff2 = 0; |
---|
1637 | } |
---|
1638 | } |
---|
1639 | } |
---|
1640 | } |
---|
1641 | } |
---|
1642 | |
---|
1643 | return; |
---|
1644 | } |
---|
1645 | |
---|
1646 | /** code SAO offset sign |
---|
1647 | * \param code sign value |
---|
1648 | */ |
---|
1649 | Void TEncSbac::codeSAOSign( UInt code ) |
---|
1650 | { |
---|
1651 | m_pcBinIf->encodeBinEP( code ); |
---|
1652 | } |
---|
1653 | |
---|
1654 | Void TEncSbac::codeSaoMaxUvlc ( UInt code, UInt maxSymbol ) |
---|
1655 | { |
---|
1656 | if (maxSymbol == 0) |
---|
1657 | { |
---|
1658 | return; |
---|
1659 | } |
---|
1660 | |
---|
1661 | Int i; |
---|
1662 | Bool bCodeLast = ( maxSymbol > code ); |
---|
1663 | |
---|
1664 | if ( code == 0 ) |
---|
1665 | { |
---|
1666 | m_pcBinIf->encodeBinEP( 0 ); |
---|
1667 | } |
---|
1668 | else |
---|
1669 | { |
---|
1670 | m_pcBinIf->encodeBinEP( 1 ); |
---|
1671 | for ( i=0; i<code-1; i++ ) |
---|
1672 | { |
---|
1673 | m_pcBinIf->encodeBinEP( 1 ); |
---|
1674 | } |
---|
1675 | if( bCodeLast ) |
---|
1676 | { |
---|
1677 | m_pcBinIf->encodeBinEP( 0 ); |
---|
1678 | } |
---|
1679 | } |
---|
1680 | } |
---|
1681 | |
---|
1682 | |
---|
1683 | /** Code SAO EO class or BO band position |
---|
1684 | * \param uiLength |
---|
1685 | * \param uiCode |
---|
1686 | */ |
---|
1687 | Void TEncSbac::codeSaoUflc ( UInt uiLength, UInt uiCode ) |
---|
1688 | { |
---|
1689 | m_pcBinIf->encodeBinsEP ( uiCode, uiLength ); |
---|
1690 | } |
---|
1691 | /** Code SAO merge flags |
---|
1692 | * \param uiCode |
---|
1693 | * \param uiCompIdx |
---|
1694 | */ |
---|
1695 | Void TEncSbac::codeSaoMerge ( UInt uiCode ) |
---|
1696 | { |
---|
1697 | if (uiCode == 0) |
---|
1698 | { |
---|
1699 | m_pcBinIf->encodeBin(0, m_cSaoMergeSCModel.get( 0, 0, 0 )); |
---|
1700 | } |
---|
1701 | else |
---|
1702 | { |
---|
1703 | m_pcBinIf->encodeBin(1, m_cSaoMergeSCModel.get( 0, 0, 0 )); |
---|
1704 | } |
---|
1705 | } |
---|
1706 | /** Code SAO type index |
---|
1707 | * \param uiCode |
---|
1708 | */ |
---|
1709 | Void TEncSbac::codeSaoTypeIdx ( UInt uiCode) |
---|
1710 | { |
---|
1711 | if (uiCode == 0) |
---|
1712 | { |
---|
1713 | m_pcBinIf->encodeBin( 0, m_cSaoTypeIdxSCModel.get( 0, 0, 0 ) ); |
---|
1714 | } |
---|
1715 | else |
---|
1716 | { |
---|
1717 | m_pcBinIf->encodeBin( 1, m_cSaoTypeIdxSCModel.get( 0, 0, 0 ) ); |
---|
1718 | m_pcBinIf->encodeBinEP( uiCode <= 4 ? 1 : 0 ); |
---|
1719 | } |
---|
1720 | } |
---|
1721 | /*! |
---|
1722 | **************************************************************************** |
---|
1723 | * \brief |
---|
1724 | * estimate bit cost for CBP, significant map and significant coefficients |
---|
1725 | **************************************************************************** |
---|
1726 | */ |
---|
1727 | Void TEncSbac::estBit( estBitsSbacStruct* pcEstBitsSbac, Int width, Int height, TextType eTType ) |
---|
1728 | { |
---|
1729 | estCBFBit( pcEstBitsSbac ); |
---|
1730 | |
---|
1731 | estSignificantCoeffGroupMapBit( pcEstBitsSbac, eTType ); |
---|
1732 | |
---|
1733 | // encode significance map |
---|
1734 | estSignificantMapBit( pcEstBitsSbac, width, height, eTType ); |
---|
1735 | |
---|
1736 | // encode significant coefficients |
---|
1737 | estSignificantCoefficientsBit( pcEstBitsSbac, eTType ); |
---|
1738 | } |
---|
1739 | |
---|
1740 | /*! |
---|
1741 | **************************************************************************** |
---|
1742 | * \brief |
---|
1743 | * estimate bit cost for each CBP bit |
---|
1744 | **************************************************************************** |
---|
1745 | */ |
---|
1746 | Void TEncSbac::estCBFBit( estBitsSbacStruct* pcEstBitsSbac ) |
---|
1747 | { |
---|
1748 | ContextModel *pCtx = m_cCUQtCbfSCModel.get( 0 ); |
---|
1749 | |
---|
1750 | for( UInt uiCtxInc = 0; uiCtxInc < 3*NUM_QT_CBF_CTX; uiCtxInc++ ) |
---|
1751 | { |
---|
1752 | pcEstBitsSbac->blockCbpBits[ uiCtxInc ][ 0 ] = pCtx[ uiCtxInc ].getEntropyBits( 0 ); |
---|
1753 | pcEstBitsSbac->blockCbpBits[ uiCtxInc ][ 1 ] = pCtx[ uiCtxInc ].getEntropyBits( 1 ); |
---|
1754 | } |
---|
1755 | |
---|
1756 | pCtx = m_cCUQtRootCbfSCModel.get( 0 ); |
---|
1757 | |
---|
1758 | for( UInt uiCtxInc = 0; uiCtxInc < 4; uiCtxInc++ ) |
---|
1759 | { |
---|
1760 | pcEstBitsSbac->blockRootCbpBits[ uiCtxInc ][ 0 ] = pCtx[ uiCtxInc ].getEntropyBits( 0 ); |
---|
1761 | pcEstBitsSbac->blockRootCbpBits[ uiCtxInc ][ 1 ] = pCtx[ uiCtxInc ].getEntropyBits( 1 ); |
---|
1762 | } |
---|
1763 | } |
---|
1764 | |
---|
1765 | |
---|
1766 | /*! |
---|
1767 | **************************************************************************** |
---|
1768 | * \brief |
---|
1769 | * estimate SAMBAC bit cost for significant coefficient group map |
---|
1770 | **************************************************************************** |
---|
1771 | */ |
---|
1772 | Void TEncSbac::estSignificantCoeffGroupMapBit( estBitsSbacStruct* pcEstBitsSbac, TextType eTType ) |
---|
1773 | { |
---|
1774 | Int firstCtx = 0, numCtx = NUM_SIG_CG_FLAG_CTX; |
---|
1775 | |
---|
1776 | for ( Int ctxIdx = firstCtx; ctxIdx < firstCtx + numCtx; ctxIdx++ ) |
---|
1777 | { |
---|
1778 | for( UInt uiBin = 0; uiBin < 2; uiBin++ ) |
---|
1779 | { |
---|
1780 | pcEstBitsSbac->significantCoeffGroupBits[ ctxIdx ][ uiBin ] = m_cCUSigCoeffGroupSCModel.get( 0, eTType, ctxIdx ).getEntropyBits( uiBin ); |
---|
1781 | } |
---|
1782 | } |
---|
1783 | } |
---|
1784 | |
---|
1785 | |
---|
1786 | /*! |
---|
1787 | **************************************************************************** |
---|
1788 | * \brief |
---|
1789 | * estimate SAMBAC bit cost for significant coefficient map |
---|
1790 | **************************************************************************** |
---|
1791 | */ |
---|
1792 | Void TEncSbac::estSignificantMapBit( estBitsSbacStruct* pcEstBitsSbac, Int width, Int height, TextType eTType ) |
---|
1793 | { |
---|
1794 | Int firstCtx = 1, numCtx = 8; |
---|
1795 | if (max(width, height) >= 16) |
---|
1796 | { |
---|
1797 | firstCtx = (eTType == TEXT_LUMA) ? 21 : 12; |
---|
1798 | numCtx = (eTType == TEXT_LUMA) ? 6 : 3; |
---|
1799 | } |
---|
1800 | else if (width == 8) |
---|
1801 | { |
---|
1802 | firstCtx = 9; |
---|
1803 | numCtx = (eTType == TEXT_LUMA) ? 12 : 3; |
---|
1804 | } |
---|
1805 | |
---|
1806 | if (eTType == TEXT_LUMA ) |
---|
1807 | { |
---|
1808 | for( UInt bin = 0; bin < 2; bin++ ) |
---|
1809 | { |
---|
1810 | pcEstBitsSbac->significantBits[ 0 ][ bin ] = m_cCUSigSCModel.get( 0, 0, 0 ).getEntropyBits( bin ); |
---|
1811 | } |
---|
1812 | |
---|
1813 | for ( Int ctxIdx = firstCtx; ctxIdx < firstCtx + numCtx; ctxIdx++ ) |
---|
1814 | { |
---|
1815 | for( UInt uiBin = 0; uiBin < 2; uiBin++ ) |
---|
1816 | { |
---|
1817 | pcEstBitsSbac->significantBits[ ctxIdx ][ uiBin ] = m_cCUSigSCModel.get( 0, 0, ctxIdx ).getEntropyBits( uiBin ); |
---|
1818 | } |
---|
1819 | } |
---|
1820 | } |
---|
1821 | else |
---|
1822 | { |
---|
1823 | for( UInt bin = 0; bin < 2; bin++ ) |
---|
1824 | { |
---|
1825 | pcEstBitsSbac->significantBits[ 0 ][ bin ] = m_cCUSigSCModel.get( 0, 0, NUM_SIG_FLAG_CTX_LUMA + 0 ).getEntropyBits( bin ); |
---|
1826 | } |
---|
1827 | for ( Int ctxIdx = firstCtx; ctxIdx < firstCtx + numCtx; ctxIdx++ ) |
---|
1828 | { |
---|
1829 | for( UInt uiBin = 0; uiBin < 2; uiBin++ ) |
---|
1830 | { |
---|
1831 | pcEstBitsSbac->significantBits[ ctxIdx ][ uiBin ] = m_cCUSigSCModel.get( 0, 0, NUM_SIG_FLAG_CTX_LUMA + ctxIdx ).getEntropyBits( uiBin ); |
---|
1832 | } |
---|
1833 | } |
---|
1834 | } |
---|
1835 | Int iBitsX = 0, iBitsY = 0; |
---|
1836 | Int blkSizeOffsetX, blkSizeOffsetY, shiftX, shiftY; |
---|
1837 | |
---|
1838 | blkSizeOffsetX = eTType ? 0: (g_aucConvertToBit[ width ] *3 + ((g_aucConvertToBit[ width ] +1)>>2)); |
---|
1839 | blkSizeOffsetY = eTType ? 0: (g_aucConvertToBit[ height ]*3 + ((g_aucConvertToBit[ height ]+1)>>2)); |
---|
1840 | shiftX = eTType ? g_aucConvertToBit[ width ] :((g_aucConvertToBit[ width ]+3)>>2); |
---|
1841 | shiftY = eTType ? g_aucConvertToBit[ height ] :((g_aucConvertToBit[ height ]+3)>>2); |
---|
1842 | |
---|
1843 | Int ctx; |
---|
1844 | ContextModel *pCtxX = m_cCuCtxLastX.get( 0, eTType ); |
---|
1845 | for (ctx = 0; ctx < g_uiGroupIdx[ width - 1 ]; ctx++) |
---|
1846 | { |
---|
1847 | Int ctxOffset = blkSizeOffsetX + (ctx >>shiftX); |
---|
1848 | pcEstBitsSbac->lastXBits[ ctx ] = iBitsX + pCtxX[ ctxOffset ].getEntropyBits( 0 ); |
---|
1849 | iBitsX += pCtxX[ ctxOffset ].getEntropyBits( 1 ); |
---|
1850 | } |
---|
1851 | pcEstBitsSbac->lastXBits[ctx] = iBitsX; |
---|
1852 | ContextModel *pCtxY = m_cCuCtxLastY.get( 0, eTType ); |
---|
1853 | for (ctx = 0; ctx < g_uiGroupIdx[ height - 1 ]; ctx++) |
---|
1854 | { |
---|
1855 | Int ctxOffset = blkSizeOffsetY + (ctx >>shiftY); |
---|
1856 | pcEstBitsSbac->lastYBits[ ctx ] = iBitsY + pCtxY[ ctxOffset ].getEntropyBits( 0 ); |
---|
1857 | iBitsY += pCtxY[ ctxOffset ].getEntropyBits( 1 ); |
---|
1858 | } |
---|
1859 | pcEstBitsSbac->lastYBits[ctx] = iBitsY; |
---|
1860 | } |
---|
1861 | |
---|
1862 | /*! |
---|
1863 | **************************************************************************** |
---|
1864 | * \brief |
---|
1865 | * estimate bit cost of significant coefficient |
---|
1866 | **************************************************************************** |
---|
1867 | */ |
---|
1868 | Void TEncSbac::estSignificantCoefficientsBit( estBitsSbacStruct* pcEstBitsSbac, TextType eTType ) |
---|
1869 | { |
---|
1870 | if (eTType==TEXT_LUMA) |
---|
1871 | { |
---|
1872 | ContextModel *ctxOne = m_cCUOneSCModel.get(0, 0); |
---|
1873 | ContextModel *ctxAbs = m_cCUAbsSCModel.get(0, 0); |
---|
1874 | |
---|
1875 | for (Int ctxIdx = 0; ctxIdx < NUM_ONE_FLAG_CTX_LUMA; ctxIdx++) |
---|
1876 | { |
---|
1877 | pcEstBitsSbac->m_greaterOneBits[ ctxIdx ][ 0 ] = ctxOne[ ctxIdx ].getEntropyBits( 0 ); |
---|
1878 | pcEstBitsSbac->m_greaterOneBits[ ctxIdx ][ 1 ] = ctxOne[ ctxIdx ].getEntropyBits( 1 ); |
---|
1879 | } |
---|
1880 | |
---|
1881 | for (Int ctxIdx = 0; ctxIdx < NUM_ABS_FLAG_CTX_LUMA; ctxIdx++) |
---|
1882 | { |
---|
1883 | pcEstBitsSbac->m_levelAbsBits[ ctxIdx ][ 0 ] = ctxAbs[ ctxIdx ].getEntropyBits( 0 ); |
---|
1884 | pcEstBitsSbac->m_levelAbsBits[ ctxIdx ][ 1 ] = ctxAbs[ ctxIdx ].getEntropyBits( 1 ); |
---|
1885 | } |
---|
1886 | } |
---|
1887 | else |
---|
1888 | { |
---|
1889 | ContextModel *ctxOne = m_cCUOneSCModel.get(0, 0) + NUM_ONE_FLAG_CTX_LUMA; |
---|
1890 | ContextModel *ctxAbs = m_cCUAbsSCModel.get(0, 0) + NUM_ABS_FLAG_CTX_LUMA; |
---|
1891 | |
---|
1892 | for (Int ctxIdx = 0; ctxIdx < NUM_ONE_FLAG_CTX_CHROMA; ctxIdx++) |
---|
1893 | { |
---|
1894 | pcEstBitsSbac->m_greaterOneBits[ ctxIdx ][ 0 ] = ctxOne[ ctxIdx ].getEntropyBits( 0 ); |
---|
1895 | pcEstBitsSbac->m_greaterOneBits[ ctxIdx ][ 1 ] = ctxOne[ ctxIdx ].getEntropyBits( 1 ); |
---|
1896 | } |
---|
1897 | |
---|
1898 | for (Int ctxIdx = 0; ctxIdx < NUM_ABS_FLAG_CTX_CHROMA; ctxIdx++) |
---|
1899 | { |
---|
1900 | pcEstBitsSbac->m_levelAbsBits[ ctxIdx ][ 0 ] = ctxAbs[ ctxIdx ].getEntropyBits( 0 ); |
---|
1901 | pcEstBitsSbac->m_levelAbsBits[ ctxIdx ][ 1 ] = ctxAbs[ ctxIdx ].getEntropyBits( 1 ); |
---|
1902 | } |
---|
1903 | } |
---|
1904 | } |
---|
1905 | |
---|
1906 | /** |
---|
1907 | - Initialize our context information from the nominated source. |
---|
1908 | . |
---|
1909 | \param pSrc From where to copy context information. |
---|
1910 | */ |
---|
1911 | Void TEncSbac::xCopyContextsFrom( TEncSbac* pSrc ) |
---|
1912 | { |
---|
1913 | memcpy(m_contextModels, pSrc->m_contextModels, m_numContextModels*sizeof(m_contextModels[0])); |
---|
1914 | } |
---|
1915 | |
---|
1916 | Void TEncSbac::loadContexts ( TEncSbac* pScr) |
---|
1917 | { |
---|
1918 | this->xCopyContextsFrom(pScr); |
---|
1919 | } |
---|
1920 | //! \} |
---|