1 | /* The copyright in this software is being made available under the BSD |
---|
2 | * License, included below. This software may be subject to other third party |
---|
3 | * and contributor rights, including patent rights, and no such rights are |
---|
4 | * granted under this license. |
---|
5 | * |
---|
6 | * Copyright (c) 2010-2014, ITU/ISO/IEC |
---|
7 | * All rights reserved. |
---|
8 | * |
---|
9 | * Redistribution and use in source and binary forms, with or without |
---|
10 | * modification, are permitted provided that the following conditions are met: |
---|
11 | * |
---|
12 | * * Redistributions of source code must retain the above copyright notice, |
---|
13 | * this list of conditions and the following disclaimer. |
---|
14 | * * Redistributions in binary form must reproduce the above copyright notice, |
---|
15 | * this list of conditions and the following disclaimer in the documentation |
---|
16 | * and/or other materials provided with the distribution. |
---|
17 | * * Neither the name of the ITU/ISO/IEC nor the names of its contributors may |
---|
18 | * be used to endorse or promote products derived from this software without |
---|
19 | * specific prior written permission. |
---|
20 | * |
---|
21 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
---|
22 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
---|
23 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
---|
24 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS |
---|
25 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
---|
26 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
---|
27 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
---|
28 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
---|
29 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
---|
30 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF |
---|
31 | * THE POSSIBILITY OF SUCH DAMAGE. |
---|
32 | */ |
---|
33 | |
---|
34 | /** \file TEncSbac.cpp |
---|
35 | \brief SBAC encoder class |
---|
36 | */ |
---|
37 | |
---|
38 | #include "TEncTop.h" |
---|
39 | #include "TEncSbac.h" |
---|
40 | #include "TLibCommon/TComTU.h" |
---|
41 | |
---|
42 | #include <map> |
---|
43 | #include <algorithm> |
---|
44 | |
---|
45 | #if ENVIRONMENT_VARIABLE_DEBUG_AND_TEST |
---|
46 | #include "../TLibCommon/Debug.h" |
---|
47 | #endif |
---|
48 | |
---|
49 | |
---|
50 | //! \ingroup TLibEncoder |
---|
51 | //! \{ |
---|
52 | |
---|
53 | // ==================================================================================================================== |
---|
54 | // Constructor / destructor / create / destroy |
---|
55 | // ==================================================================================================================== |
---|
56 | |
---|
57 | TEncSbac::TEncSbac() |
---|
58 | // new structure here |
---|
59 | : m_pcBitIf ( NULL ) |
---|
60 | , m_pcSlice ( NULL ) |
---|
61 | , m_pcBinIf ( NULL ) |
---|
62 | , m_numContextModels ( 0 ) |
---|
63 | , m_cCUSplitFlagSCModel ( 1, 1, NUM_SPLIT_FLAG_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
64 | , m_cCUSkipFlagSCModel ( 1, 1, NUM_SKIP_FLAG_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
65 | , m_cCUMergeFlagExtSCModel ( 1, 1, NUM_MERGE_FLAG_EXT_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
66 | , m_cCUMergeIdxExtSCModel ( 1, 1, NUM_MERGE_IDX_EXT_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
67 | , m_cCUPartSizeSCModel ( 1, 1, NUM_PART_SIZE_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
68 | , m_cCUPredModeSCModel ( 1, 1, NUM_PRED_MODE_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
69 | , m_cCUIntraPredSCModel ( 1, 1, NUM_ADI_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
70 | , m_cCUChromaPredSCModel ( 1, 1, NUM_CHROMA_PRED_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
71 | , m_cCUDeltaQpSCModel ( 1, 1, NUM_DELTA_QP_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
72 | , m_cCUInterDirSCModel ( 1, 1, NUM_INTER_DIR_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
73 | , m_cCURefPicSCModel ( 1, 1, NUM_REF_NO_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
74 | , m_cCUMvdSCModel ( 1, 1, NUM_MV_RES_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
75 | , m_cCUQtCbfSCModel ( 1, NUM_QT_CBF_CTX_SETS, NUM_QT_CBF_CTX_PER_SET , m_contextModels + m_numContextModels, m_numContextModels) |
---|
76 | , m_cCUTransSubdivFlagSCModel ( 1, 1, NUM_TRANS_SUBDIV_FLAG_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
77 | , m_cCUQtRootCbfSCModel ( 1, 1, NUM_QT_ROOT_CBF_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
78 | , m_cCUSigCoeffGroupSCModel ( 1, 2, NUM_SIG_CG_FLAG_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
79 | , m_cCUSigSCModel ( 1, 1, NUM_SIG_FLAG_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
80 | , m_cCuCtxLastX ( 1, NUM_CTX_LAST_FLAG_SETS, NUM_CTX_LAST_FLAG_XY , m_contextModels + m_numContextModels, m_numContextModels) |
---|
81 | , m_cCuCtxLastY ( 1, NUM_CTX_LAST_FLAG_SETS, NUM_CTX_LAST_FLAG_XY , m_contextModels + m_numContextModels, m_numContextModels) |
---|
82 | , m_cCUOneSCModel ( 1, 1, NUM_ONE_FLAG_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
83 | , m_cCUAbsSCModel ( 1, 1, NUM_ABS_FLAG_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
84 | , m_cMVPIdxSCModel ( 1, 1, NUM_MVP_IDX_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
85 | , m_cSaoMergeSCModel ( 1, 1, NUM_SAO_MERGE_FLAG_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
86 | , m_cSaoTypeIdxSCModel ( 1, 1, NUM_SAO_TYPE_IDX_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
87 | , m_cTransformSkipSCModel ( 1, MAX_NUM_CHANNEL_TYPE, NUM_TRANSFORMSKIP_FLAG_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
88 | , m_CUTransquantBypassFlagSCModel ( 1, 1, NUM_CU_TRANSQUANT_BYPASS_FLAG_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
89 | , m_explicitRdpcmFlagSCModel ( 1, MAX_NUM_CHANNEL_TYPE, NUM_EXPLICIT_RDPCM_FLAG_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
90 | , m_explicitRdpcmDirSCModel ( 1, MAX_NUM_CHANNEL_TYPE, NUM_EXPLICIT_RDPCM_DIR_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
91 | , m_cCrossComponentPredictionSCModel ( 1, 1, NUM_CROSS_COMPONENT_PREDICTION_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
92 | , m_ChromaQpAdjFlagSCModel ( 1, 1, NUM_CHROMA_QP_ADJ_FLAG_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
93 | , m_ChromaQpAdjIdcSCModel ( 1, 1, NUM_CHROMA_QP_ADJ_IDC_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
94 | { |
---|
95 | assert( m_numContextModels <= MAX_NUM_CTX_MOD ); |
---|
96 | } |
---|
97 | |
---|
98 | TEncSbac::~TEncSbac() |
---|
99 | { |
---|
100 | } |
---|
101 | |
---|
102 | // ==================================================================================================================== |
---|
103 | // Public member functions |
---|
104 | // ==================================================================================================================== |
---|
105 | |
---|
106 | Void TEncSbac::resetEntropy () |
---|
107 | { |
---|
108 | Int iQp = m_pcSlice->getSliceQp(); |
---|
109 | SliceType eSliceType = m_pcSlice->getSliceType(); |
---|
110 | |
---|
111 | Int encCABACTableIdx = m_pcSlice->getPPS()->getEncCABACTableIdx(); |
---|
112 | if (!m_pcSlice->isIntra() && (encCABACTableIdx==B_SLICE || encCABACTableIdx==P_SLICE) && m_pcSlice->getPPS()->getCabacInitPresentFlag()) |
---|
113 | { |
---|
114 | eSliceType = (SliceType) encCABACTableIdx; |
---|
115 | } |
---|
116 | |
---|
117 | m_cCUSplitFlagSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_SPLIT_FLAG ); |
---|
118 | m_cCUSkipFlagSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_SKIP_FLAG ); |
---|
119 | m_cCUMergeFlagExtSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_MERGE_FLAG_EXT); |
---|
120 | m_cCUMergeIdxExtSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_MERGE_IDX_EXT); |
---|
121 | m_cCUPartSizeSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_PART_SIZE ); |
---|
122 | m_cCUPredModeSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_PRED_MODE ); |
---|
123 | m_cCUIntraPredSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_INTRA_PRED_MODE ); |
---|
124 | m_cCUChromaPredSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_CHROMA_PRED_MODE ); |
---|
125 | m_cCUInterDirSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_INTER_DIR ); |
---|
126 | m_cCUMvdSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_MVD ); |
---|
127 | m_cCURefPicSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_REF_PIC ); |
---|
128 | m_cCUDeltaQpSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_DQP ); |
---|
129 | m_cCUQtCbfSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_QT_CBF ); |
---|
130 | m_cCUQtRootCbfSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_QT_ROOT_CBF ); |
---|
131 | m_cCUSigCoeffGroupSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_SIG_CG_FLAG ); |
---|
132 | m_cCUSigSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_SIG_FLAG ); |
---|
133 | m_cCuCtxLastX.initBuffer ( eSliceType, iQp, (UChar*)INIT_LAST ); |
---|
134 | m_cCuCtxLastY.initBuffer ( eSliceType, iQp, (UChar*)INIT_LAST ); |
---|
135 | m_cCUOneSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_ONE_FLAG ); |
---|
136 | m_cCUAbsSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_ABS_FLAG ); |
---|
137 | m_cMVPIdxSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_MVP_IDX ); |
---|
138 | m_cCUTransSubdivFlagSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_TRANS_SUBDIV_FLAG ); |
---|
139 | m_cSaoMergeSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_SAO_MERGE_FLAG ); |
---|
140 | m_cSaoTypeIdxSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_SAO_TYPE_IDX ); |
---|
141 | m_cTransformSkipSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_TRANSFORMSKIP_FLAG ); |
---|
142 | m_CUTransquantBypassFlagSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_CU_TRANSQUANT_BYPASS_FLAG ); |
---|
143 | m_explicitRdpcmFlagSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_EXPLICIT_RDPCM_FLAG); |
---|
144 | m_explicitRdpcmDirSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_EXPLICIT_RDPCM_DIR); |
---|
145 | m_cCrossComponentPredictionSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_CROSS_COMPONENT_PREDICTION ); |
---|
146 | m_ChromaQpAdjFlagSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_CHROMA_QP_ADJ_FLAG ); |
---|
147 | m_ChromaQpAdjIdcSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_CHROMA_QP_ADJ_IDC ); |
---|
148 | |
---|
149 | for (UInt statisticIndex = 0; statisticIndex < RExt__GOLOMB_RICE_ADAPTATION_STATISTICS_SETS ; statisticIndex++) |
---|
150 | { |
---|
151 | m_golombRiceAdaptationStatistics[statisticIndex] = 0; |
---|
152 | } |
---|
153 | |
---|
154 | m_pcBinIf->start(); |
---|
155 | |
---|
156 | return; |
---|
157 | } |
---|
158 | |
---|
159 | /** The function does the following: |
---|
160 | * If current slice type is P/B then it determines the distance of initialisation type 1 and 2 from the current CABAC states and |
---|
161 | * stores the index of the closest table. This index is used for the next P/B slice when cabac_init_present_flag is true. |
---|
162 | */ |
---|
163 | Void TEncSbac::determineCabacInitIdx() |
---|
164 | { |
---|
165 | Int qp = m_pcSlice->getSliceQp(); |
---|
166 | |
---|
167 | if (!m_pcSlice->isIntra()) |
---|
168 | { |
---|
169 | SliceType aSliceTypeChoices[] = {B_SLICE, P_SLICE}; |
---|
170 | |
---|
171 | UInt bestCost = MAX_UINT; |
---|
172 | SliceType bestSliceType = aSliceTypeChoices[0]; |
---|
173 | for (UInt idx=0; idx<2; idx++) |
---|
174 | { |
---|
175 | UInt curCost = 0; |
---|
176 | SliceType curSliceType = aSliceTypeChoices[idx]; |
---|
177 | |
---|
178 | curCost = m_cCUSplitFlagSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_SPLIT_FLAG ); |
---|
179 | curCost += m_cCUSkipFlagSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_SKIP_FLAG ); |
---|
180 | curCost += m_cCUMergeFlagExtSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_MERGE_FLAG_EXT); |
---|
181 | curCost += m_cCUMergeIdxExtSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_MERGE_IDX_EXT); |
---|
182 | curCost += m_cCUPartSizeSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_PART_SIZE ); |
---|
183 | curCost += m_cCUPredModeSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_PRED_MODE ); |
---|
184 | curCost += m_cCUIntraPredSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_INTRA_PRED_MODE ); |
---|
185 | curCost += m_cCUChromaPredSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_CHROMA_PRED_MODE ); |
---|
186 | curCost += m_cCUInterDirSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_INTER_DIR ); |
---|
187 | curCost += m_cCUMvdSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_MVD ); |
---|
188 | curCost += m_cCURefPicSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_REF_PIC ); |
---|
189 | curCost += m_cCUDeltaQpSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_DQP ); |
---|
190 | curCost += m_cCUQtCbfSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_QT_CBF ); |
---|
191 | curCost += m_cCUQtRootCbfSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_QT_ROOT_CBF ); |
---|
192 | curCost += m_cCUSigCoeffGroupSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_SIG_CG_FLAG ); |
---|
193 | curCost += m_cCUSigSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_SIG_FLAG ); |
---|
194 | curCost += m_cCuCtxLastX.calcCost ( curSliceType, qp, (UChar*)INIT_LAST ); |
---|
195 | curCost += m_cCuCtxLastY.calcCost ( curSliceType, qp, (UChar*)INIT_LAST ); |
---|
196 | curCost += m_cCUOneSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_ONE_FLAG ); |
---|
197 | curCost += m_cCUAbsSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_ABS_FLAG ); |
---|
198 | curCost += m_cMVPIdxSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_MVP_IDX ); |
---|
199 | curCost += m_cCUTransSubdivFlagSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_TRANS_SUBDIV_FLAG ); |
---|
200 | curCost += m_cSaoMergeSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_SAO_MERGE_FLAG ); |
---|
201 | curCost += m_cSaoTypeIdxSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_SAO_TYPE_IDX ); |
---|
202 | curCost += m_cTransformSkipSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_TRANSFORMSKIP_FLAG ); |
---|
203 | curCost += m_CUTransquantBypassFlagSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_CU_TRANSQUANT_BYPASS_FLAG ); |
---|
204 | curCost += m_explicitRdpcmFlagSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_EXPLICIT_RDPCM_FLAG); |
---|
205 | curCost += m_explicitRdpcmDirSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_EXPLICIT_RDPCM_DIR); |
---|
206 | curCost += m_cCrossComponentPredictionSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_CROSS_COMPONENT_PREDICTION ); |
---|
207 | curCost += m_ChromaQpAdjFlagSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_CHROMA_QP_ADJ_FLAG ); |
---|
208 | curCost += m_ChromaQpAdjIdcSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_CHROMA_QP_ADJ_IDC ); |
---|
209 | |
---|
210 | if (curCost < bestCost) |
---|
211 | { |
---|
212 | bestSliceType = curSliceType; |
---|
213 | bestCost = curCost; |
---|
214 | } |
---|
215 | } |
---|
216 | m_pcSlice->getPPS()->setEncCABACTableIdx( bestSliceType ); |
---|
217 | } |
---|
218 | else |
---|
219 | { |
---|
220 | m_pcSlice->getPPS()->setEncCABACTableIdx( I_SLICE ); |
---|
221 | } |
---|
222 | } |
---|
223 | |
---|
224 | Void TEncSbac::codeVPS( TComVPS* pcVPS ) |
---|
225 | { |
---|
226 | assert (0); |
---|
227 | return; |
---|
228 | } |
---|
229 | |
---|
230 | Void TEncSbac::codeSPS( TComSPS* pcSPS ) |
---|
231 | { |
---|
232 | assert (0); |
---|
233 | return; |
---|
234 | } |
---|
235 | |
---|
236 | Void TEncSbac::codePPS( TComPPS* pcPPS |
---|
237 | #if CGS_3D_ASYMLUT |
---|
238 | , TEnc3DAsymLUT * pc3DAsymLUT |
---|
239 | #endif |
---|
240 | ) |
---|
241 | { |
---|
242 | assert (0); |
---|
243 | return; |
---|
244 | } |
---|
245 | |
---|
246 | Void TEncSbac::codeSliceHeader( TComSlice* pcSlice ) |
---|
247 | { |
---|
248 | assert (0); |
---|
249 | return; |
---|
250 | } |
---|
251 | |
---|
252 | Void TEncSbac::codeTilesWPPEntryPoint( TComSlice* pSlice ) |
---|
253 | { |
---|
254 | assert (0); |
---|
255 | return; |
---|
256 | } |
---|
257 | |
---|
258 | Void TEncSbac::codeTerminatingBit( UInt uilsLast ) |
---|
259 | { |
---|
260 | m_pcBinIf->encodeBinTrm( uilsLast ); |
---|
261 | } |
---|
262 | |
---|
263 | Void TEncSbac::codeSliceFinish() |
---|
264 | { |
---|
265 | m_pcBinIf->finish(); |
---|
266 | } |
---|
267 | |
---|
268 | Void TEncSbac::xWriteUnarySymbol( UInt uiSymbol, ContextModel* pcSCModel, Int iOffset ) |
---|
269 | { |
---|
270 | m_pcBinIf->encodeBin( uiSymbol ? 1 : 0, pcSCModel[0] ); |
---|
271 | |
---|
272 | if( 0 == uiSymbol) |
---|
273 | { |
---|
274 | return; |
---|
275 | } |
---|
276 | |
---|
277 | while( uiSymbol-- ) |
---|
278 | { |
---|
279 | m_pcBinIf->encodeBin( uiSymbol ? 1 : 0, pcSCModel[ iOffset ] ); |
---|
280 | } |
---|
281 | |
---|
282 | return; |
---|
283 | } |
---|
284 | |
---|
285 | Void TEncSbac::xWriteUnaryMaxSymbol( UInt uiSymbol, ContextModel* pcSCModel, Int iOffset, UInt uiMaxSymbol ) |
---|
286 | { |
---|
287 | if (uiMaxSymbol == 0) |
---|
288 | { |
---|
289 | return; |
---|
290 | } |
---|
291 | |
---|
292 | m_pcBinIf->encodeBin( uiSymbol ? 1 : 0, pcSCModel[ 0 ] ); |
---|
293 | |
---|
294 | if ( uiSymbol == 0 ) |
---|
295 | { |
---|
296 | return; |
---|
297 | } |
---|
298 | |
---|
299 | Bool bCodeLast = ( uiMaxSymbol > uiSymbol ); |
---|
300 | |
---|
301 | while( --uiSymbol ) |
---|
302 | { |
---|
303 | m_pcBinIf->encodeBin( 1, pcSCModel[ iOffset ] ); |
---|
304 | } |
---|
305 | if( bCodeLast ) |
---|
306 | { |
---|
307 | m_pcBinIf->encodeBin( 0, pcSCModel[ iOffset ] ); |
---|
308 | } |
---|
309 | |
---|
310 | return; |
---|
311 | } |
---|
312 | |
---|
313 | Void TEncSbac::xWriteEpExGolomb( UInt uiSymbol, UInt uiCount ) |
---|
314 | { |
---|
315 | UInt bins = 0; |
---|
316 | Int numBins = 0; |
---|
317 | |
---|
318 | while( uiSymbol >= (UInt)(1<<uiCount) ) |
---|
319 | { |
---|
320 | bins = 2 * bins + 1; |
---|
321 | numBins++; |
---|
322 | uiSymbol -= 1 << uiCount; |
---|
323 | uiCount ++; |
---|
324 | } |
---|
325 | bins = 2 * bins + 0; |
---|
326 | numBins++; |
---|
327 | |
---|
328 | bins = (bins << uiCount) | uiSymbol; |
---|
329 | numBins += uiCount; |
---|
330 | |
---|
331 | assert( numBins <= 32 ); |
---|
332 | m_pcBinIf->encodeBinsEP( bins, numBins ); |
---|
333 | } |
---|
334 | |
---|
335 | |
---|
336 | /** Coding of coeff_abs_level_minus3 |
---|
337 | * \param uiSymbol value of coeff_abs_level_minus3 |
---|
338 | * \param ruiGoRiceParam reference to Rice parameter |
---|
339 | * \returns Void |
---|
340 | */ |
---|
341 | Void TEncSbac::xWriteCoefRemainExGolomb ( UInt symbol, UInt &rParam, const Bool useLimitedPrefixLength, const ChannelType channelType ) |
---|
342 | { |
---|
343 | Int codeNumber = (Int)symbol; |
---|
344 | UInt length; |
---|
345 | |
---|
346 | if (codeNumber < (COEF_REMAIN_BIN_REDUCTION << rParam)) |
---|
347 | { |
---|
348 | length = codeNumber>>rParam; |
---|
349 | m_pcBinIf->encodeBinsEP( (1<<(length+1))-2 , length+1); |
---|
350 | m_pcBinIf->encodeBinsEP((codeNumber%(1<<rParam)),rParam); |
---|
351 | } |
---|
352 | else if (useLimitedPrefixLength) |
---|
353 | { |
---|
354 | const UInt maximumPrefixLength = (32 - (COEF_REMAIN_BIN_REDUCTION + g_maxTrDynamicRange[channelType])); |
---|
355 | |
---|
356 | UInt prefixLength = 0; |
---|
357 | UInt suffixLength = MAX_UINT; |
---|
358 | UInt codeValue = (symbol >> rParam) - COEF_REMAIN_BIN_REDUCTION; |
---|
359 | |
---|
360 | if (codeValue >= ((1 << maximumPrefixLength) - 1)) |
---|
361 | { |
---|
362 | prefixLength = maximumPrefixLength; |
---|
363 | suffixLength = g_maxTrDynamicRange[channelType] - rParam; |
---|
364 | } |
---|
365 | else |
---|
366 | { |
---|
367 | while (codeValue > ((2 << prefixLength) - 2)) |
---|
368 | { |
---|
369 | prefixLength++; |
---|
370 | } |
---|
371 | |
---|
372 | suffixLength = prefixLength + 1; //+1 for the separator bit |
---|
373 | } |
---|
374 | |
---|
375 | const UInt suffix = codeValue - ((1 << prefixLength) - 1); |
---|
376 | |
---|
377 | const UInt totalPrefixLength = prefixLength + COEF_REMAIN_BIN_REDUCTION; |
---|
378 | const UInt prefix = (1 << totalPrefixLength) - 1; |
---|
379 | const UInt rParamBitMask = (1 << rParam) - 1; |
---|
380 | |
---|
381 | m_pcBinIf->encodeBinsEP( prefix, totalPrefixLength ); //prefix |
---|
382 | m_pcBinIf->encodeBinsEP(((suffix << rParam) | (symbol & rParamBitMask)), (suffixLength + rParam)); //separator, suffix, and rParam bits |
---|
383 | } |
---|
384 | else |
---|
385 | { |
---|
386 | length = rParam; |
---|
387 | codeNumber = codeNumber - ( COEF_REMAIN_BIN_REDUCTION << rParam); |
---|
388 | |
---|
389 | while (codeNumber >= (1<<length)) |
---|
390 | { |
---|
391 | codeNumber -= (1<<(length++)); |
---|
392 | } |
---|
393 | |
---|
394 | m_pcBinIf->encodeBinsEP((1<<(COEF_REMAIN_BIN_REDUCTION+length+1-rParam))-2,COEF_REMAIN_BIN_REDUCTION+length+1-rParam); |
---|
395 | m_pcBinIf->encodeBinsEP(codeNumber,length); |
---|
396 | } |
---|
397 | } |
---|
398 | |
---|
399 | // SBAC RD |
---|
400 | Void TEncSbac::load ( const TEncSbac* pSrc) |
---|
401 | { |
---|
402 | this->xCopyFrom(pSrc); |
---|
403 | } |
---|
404 | |
---|
405 | Void TEncSbac::loadIntraDirMode( const TEncSbac* pSrc, const ChannelType chType ) |
---|
406 | { |
---|
407 | m_pcBinIf->copyState( pSrc->m_pcBinIf ); |
---|
408 | if (isLuma(chType)) |
---|
409 | this->m_cCUIntraPredSCModel .copyFrom( &pSrc->m_cCUIntraPredSCModel ); |
---|
410 | else |
---|
411 | this->m_cCUChromaPredSCModel .copyFrom( &pSrc->m_cCUChromaPredSCModel ); |
---|
412 | } |
---|
413 | |
---|
414 | |
---|
415 | Void TEncSbac::store( TEncSbac* pDest) const |
---|
416 | { |
---|
417 | pDest->xCopyFrom( this ); |
---|
418 | } |
---|
419 | |
---|
420 | |
---|
421 | Void TEncSbac::xCopyFrom( const TEncSbac* pSrc ) |
---|
422 | { |
---|
423 | m_pcBinIf->copyState( pSrc->m_pcBinIf ); |
---|
424 | xCopyContextsFrom(pSrc); |
---|
425 | } |
---|
426 | |
---|
427 | Void TEncSbac::codeMVPIdx ( TComDataCU* pcCU, UInt uiAbsPartIdx, RefPicList eRefList ) |
---|
428 | { |
---|
429 | Int iSymbol = pcCU->getMVPIdx(eRefList, uiAbsPartIdx); |
---|
430 | Int iNum = AMVP_MAX_NUM_CANDS; |
---|
431 | |
---|
432 | xWriteUnaryMaxSymbol(iSymbol, m_cMVPIdxSCModel.get(0), 1, iNum-1); |
---|
433 | } |
---|
434 | |
---|
435 | Void TEncSbac::codePartSize( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth ) |
---|
436 | { |
---|
437 | PartSize eSize = pcCU->getPartitionSize( uiAbsPartIdx ); |
---|
438 | |
---|
439 | if ( pcCU->isIntra( uiAbsPartIdx ) ) |
---|
440 | { |
---|
441 | if( uiDepth == g_uiMaxCUDepth - g_uiAddCUDepth ) |
---|
442 | { |
---|
443 | m_pcBinIf->encodeBin( eSize == SIZE_2Nx2N? 1 : 0, m_cCUPartSizeSCModel.get( 0, 0, 0 ) ); |
---|
444 | } |
---|
445 | return; |
---|
446 | } |
---|
447 | |
---|
448 | switch(eSize) |
---|
449 | { |
---|
450 | case SIZE_2Nx2N: |
---|
451 | { |
---|
452 | m_pcBinIf->encodeBin( 1, m_cCUPartSizeSCModel.get( 0, 0, 0) ); |
---|
453 | break; |
---|
454 | } |
---|
455 | case SIZE_2NxN: |
---|
456 | case SIZE_2NxnU: |
---|
457 | case SIZE_2NxnD: |
---|
458 | { |
---|
459 | m_pcBinIf->encodeBin( 0, m_cCUPartSizeSCModel.get( 0, 0, 0) ); |
---|
460 | m_pcBinIf->encodeBin( 1, m_cCUPartSizeSCModel.get( 0, 0, 1) ); |
---|
461 | if ( pcCU->getSlice()->getSPS()->getAMPAcc( uiDepth ) ) |
---|
462 | { |
---|
463 | if (eSize == SIZE_2NxN) |
---|
464 | { |
---|
465 | m_pcBinIf->encodeBin(1, m_cCUPartSizeSCModel.get( 0, 0, 3 )); |
---|
466 | } |
---|
467 | else |
---|
468 | { |
---|
469 | m_pcBinIf->encodeBin(0, m_cCUPartSizeSCModel.get( 0, 0, 3 )); |
---|
470 | m_pcBinIf->encodeBinEP((eSize == SIZE_2NxnU? 0: 1)); |
---|
471 | } |
---|
472 | } |
---|
473 | break; |
---|
474 | } |
---|
475 | case SIZE_Nx2N: |
---|
476 | case SIZE_nLx2N: |
---|
477 | case SIZE_nRx2N: |
---|
478 | { |
---|
479 | m_pcBinIf->encodeBin( 0, m_cCUPartSizeSCModel.get( 0, 0, 0) ); |
---|
480 | m_pcBinIf->encodeBin( 0, m_cCUPartSizeSCModel.get( 0, 0, 1) ); |
---|
481 | |
---|
482 | if( uiDepth == g_uiMaxCUDepth - g_uiAddCUDepth && !( pcCU->getWidth(uiAbsPartIdx) == 8 && pcCU->getHeight(uiAbsPartIdx) == 8 ) ) |
---|
483 | { |
---|
484 | m_pcBinIf->encodeBin( 1, m_cCUPartSizeSCModel.get( 0, 0, 2) ); |
---|
485 | } |
---|
486 | |
---|
487 | if ( pcCU->getSlice()->getSPS()->getAMPAcc( uiDepth ) ) |
---|
488 | { |
---|
489 | if (eSize == SIZE_Nx2N) |
---|
490 | { |
---|
491 | m_pcBinIf->encodeBin(1, m_cCUPartSizeSCModel.get( 0, 0, 3 )); |
---|
492 | } |
---|
493 | else |
---|
494 | { |
---|
495 | m_pcBinIf->encodeBin(0, m_cCUPartSizeSCModel.get( 0, 0, 3 )); |
---|
496 | m_pcBinIf->encodeBinEP((eSize == SIZE_nLx2N? 0: 1)); |
---|
497 | } |
---|
498 | } |
---|
499 | break; |
---|
500 | } |
---|
501 | case SIZE_NxN: |
---|
502 | { |
---|
503 | if( uiDepth == g_uiMaxCUDepth - g_uiAddCUDepth && !( pcCU->getWidth(uiAbsPartIdx) == 8 && pcCU->getHeight(uiAbsPartIdx) == 8 ) ) |
---|
504 | { |
---|
505 | m_pcBinIf->encodeBin( 0, m_cCUPartSizeSCModel.get( 0, 0, 0) ); |
---|
506 | m_pcBinIf->encodeBin( 0, m_cCUPartSizeSCModel.get( 0, 0, 1) ); |
---|
507 | m_pcBinIf->encodeBin( 0, m_cCUPartSizeSCModel.get( 0, 0, 2) ); |
---|
508 | } |
---|
509 | break; |
---|
510 | } |
---|
511 | default: |
---|
512 | { |
---|
513 | assert(0); |
---|
514 | break; |
---|
515 | } |
---|
516 | } |
---|
517 | } |
---|
518 | |
---|
519 | |
---|
520 | /** code prediction mode |
---|
521 | * \param pcCU |
---|
522 | * \param uiAbsPartIdx |
---|
523 | * \returns Void |
---|
524 | */ |
---|
525 | Void TEncSbac::codePredMode( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
526 | { |
---|
527 | // get context function is here |
---|
528 | m_pcBinIf->encodeBin( pcCU->isIntra( uiAbsPartIdx ) ? 1 : 0, m_cCUPredModeSCModel.get( 0, 0, 0 ) ); |
---|
529 | } |
---|
530 | |
---|
531 | Void TEncSbac::codeCUTransquantBypassFlag( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
532 | { |
---|
533 | UInt uiSymbol = pcCU->getCUTransquantBypass(uiAbsPartIdx); |
---|
534 | m_pcBinIf->encodeBin( uiSymbol, m_CUTransquantBypassFlagSCModel.get( 0, 0, 0 ) ); |
---|
535 | } |
---|
536 | |
---|
537 | /** code skip flag |
---|
538 | * \param pcCU |
---|
539 | * \param uiAbsPartIdx |
---|
540 | * \returns Void |
---|
541 | */ |
---|
542 | Void TEncSbac::codeSkipFlag( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
543 | { |
---|
544 | // get context function is here |
---|
545 | UInt uiSymbol = pcCU->isSkipped( uiAbsPartIdx ) ? 1 : 0; |
---|
546 | UInt uiCtxSkip = pcCU->getCtxSkipFlag( uiAbsPartIdx ) ; |
---|
547 | m_pcBinIf->encodeBin( uiSymbol, m_cCUSkipFlagSCModel.get( 0, 0, uiCtxSkip ) ); |
---|
548 | DTRACE_CABAC_VL( g_nSymbolCounter++ ); |
---|
549 | DTRACE_CABAC_T( "\tSkipFlag" ); |
---|
550 | DTRACE_CABAC_T( "\tuiCtxSkip: "); |
---|
551 | DTRACE_CABAC_V( uiCtxSkip ); |
---|
552 | DTRACE_CABAC_T( "\tuiSymbol: "); |
---|
553 | DTRACE_CABAC_V( uiSymbol ); |
---|
554 | DTRACE_CABAC_T( "\n"); |
---|
555 | } |
---|
556 | |
---|
557 | /** code merge flag |
---|
558 | * \param pcCU |
---|
559 | * \param uiAbsPartIdx |
---|
560 | * \returns Void |
---|
561 | */ |
---|
562 | Void TEncSbac::codeMergeFlag( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
563 | { |
---|
564 | const UInt uiSymbol = pcCU->getMergeFlag( uiAbsPartIdx ) ? 1 : 0; |
---|
565 | m_pcBinIf->encodeBin( uiSymbol, *m_cCUMergeFlagExtSCModel.get( 0 ) ); |
---|
566 | |
---|
567 | DTRACE_CABAC_VL( g_nSymbolCounter++ ); |
---|
568 | DTRACE_CABAC_T( "\tMergeFlag: " ); |
---|
569 | DTRACE_CABAC_V( uiSymbol ); |
---|
570 | DTRACE_CABAC_T( "\tAddress: " ); |
---|
571 | DTRACE_CABAC_V( pcCU->getCtuRsAddr() ); |
---|
572 | DTRACE_CABAC_T( "\tuiAbsPartIdx: " ); |
---|
573 | DTRACE_CABAC_V( uiAbsPartIdx ); |
---|
574 | DTRACE_CABAC_T( "\n" ); |
---|
575 | } |
---|
576 | |
---|
577 | /** code merge index |
---|
578 | * \param pcCU |
---|
579 | * \param uiAbsPartIdx |
---|
580 | * \returns Void |
---|
581 | */ |
---|
582 | Void TEncSbac::codeMergeIndex( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
583 | { |
---|
584 | UInt uiUnaryIdx = pcCU->getMergeIndex( uiAbsPartIdx ); |
---|
585 | UInt uiNumCand = pcCU->getSlice()->getMaxNumMergeCand(); |
---|
586 | if ( uiNumCand > 1 ) |
---|
587 | { |
---|
588 | for( UInt ui = 0; ui < uiNumCand - 1; ++ui ) |
---|
589 | { |
---|
590 | const UInt uiSymbol = ui == uiUnaryIdx ? 0 : 1; |
---|
591 | if ( ui==0 ) |
---|
592 | { |
---|
593 | m_pcBinIf->encodeBin( uiSymbol, m_cCUMergeIdxExtSCModel.get( 0, 0, 0 ) ); |
---|
594 | } |
---|
595 | else |
---|
596 | { |
---|
597 | m_pcBinIf->encodeBinEP( uiSymbol ); |
---|
598 | } |
---|
599 | if( uiSymbol == 0 ) |
---|
600 | { |
---|
601 | break; |
---|
602 | } |
---|
603 | } |
---|
604 | } |
---|
605 | DTRACE_CABAC_VL( g_nSymbolCounter++ ); |
---|
606 | DTRACE_CABAC_T( "\tparseMergeIndex()" ); |
---|
607 | DTRACE_CABAC_T( "\tuiMRGIdx= " ); |
---|
608 | DTRACE_CABAC_V( pcCU->getMergeIndex( uiAbsPartIdx ) ); |
---|
609 | DTRACE_CABAC_T( "\n" ); |
---|
610 | } |
---|
611 | |
---|
612 | Void TEncSbac::codeSplitFlag ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth ) |
---|
613 | { |
---|
614 | if( uiDepth == g_uiMaxCUDepth - g_uiAddCUDepth ) |
---|
615 | return; |
---|
616 | |
---|
617 | UInt uiCtx = pcCU->getCtxSplitFlag( uiAbsPartIdx, uiDepth ); |
---|
618 | UInt uiCurrSplitFlag = ( pcCU->getDepth( uiAbsPartIdx ) > uiDepth ) ? 1 : 0; |
---|
619 | |
---|
620 | assert( uiCtx < 3 ); |
---|
621 | m_pcBinIf->encodeBin( uiCurrSplitFlag, m_cCUSplitFlagSCModel.get( 0, 0, uiCtx ) ); |
---|
622 | DTRACE_CABAC_VL( g_nSymbolCounter++ ) |
---|
623 | DTRACE_CABAC_T( "\tSplitFlag\n" ) |
---|
624 | return; |
---|
625 | } |
---|
626 | |
---|
627 | Void TEncSbac::codeTransformSubdivFlag( UInt uiSymbol, UInt uiCtx ) |
---|
628 | { |
---|
629 | m_pcBinIf->encodeBin( uiSymbol, m_cCUTransSubdivFlagSCModel.get( 0, 0, uiCtx ) ); |
---|
630 | DTRACE_CABAC_VL( g_nSymbolCounter++ ) |
---|
631 | DTRACE_CABAC_T( "\tparseTransformSubdivFlag()" ) |
---|
632 | DTRACE_CABAC_T( "\tsymbol=" ) |
---|
633 | DTRACE_CABAC_V( uiSymbol ) |
---|
634 | DTRACE_CABAC_T( "\tctx=" ) |
---|
635 | DTRACE_CABAC_V( uiCtx ) |
---|
636 | DTRACE_CABAC_T( "\n" ) |
---|
637 | } |
---|
638 | |
---|
639 | |
---|
640 | Void TEncSbac::codeIntraDirLumaAng( TComDataCU* pcCU, UInt absPartIdx, Bool isMultiple) |
---|
641 | { |
---|
642 | UInt dir[4],j; |
---|
643 | Int preds[4][NUM_MOST_PROBABLE_MODES] = {{-1, -1, -1},{-1, -1, -1},{-1, -1, -1},{-1, -1, -1}}; |
---|
644 | Int predNum[4], predIdx[4] ={ -1,-1,-1,-1}; |
---|
645 | PartSize mode = pcCU->getPartitionSize( absPartIdx ); |
---|
646 | UInt partNum = isMultiple?(mode==SIZE_NxN?4:1):1; |
---|
647 | UInt partOffset = ( pcCU->getPic()->getNumPartitionsInCtu() >> ( pcCU->getDepth(absPartIdx) << 1 ) ) >> 2; |
---|
648 | for (j=0;j<partNum;j++) |
---|
649 | { |
---|
650 | dir[j] = pcCU->getIntraDir( CHANNEL_TYPE_LUMA, absPartIdx+partOffset*j ); |
---|
651 | predNum[j] = pcCU->getIntraDirPredictor(absPartIdx+partOffset*j, preds[j], COMPONENT_Y); |
---|
652 | for(UInt i = 0; i < predNum[j]; i++) |
---|
653 | { |
---|
654 | if(dir[j] == preds[j][i]) |
---|
655 | { |
---|
656 | predIdx[j] = i; |
---|
657 | } |
---|
658 | } |
---|
659 | m_pcBinIf->encodeBin((predIdx[j] != -1)? 1 : 0, m_cCUIntraPredSCModel.get( 0, 0, 0 ) ); |
---|
660 | } |
---|
661 | for (j=0;j<partNum;j++) |
---|
662 | { |
---|
663 | if(predIdx[j] != -1) |
---|
664 | { |
---|
665 | m_pcBinIf->encodeBinEP( predIdx[j] ? 1 : 0 ); |
---|
666 | if (predIdx[j]) |
---|
667 | { |
---|
668 | m_pcBinIf->encodeBinEP( predIdx[j]-1 ); |
---|
669 | } |
---|
670 | } |
---|
671 | else |
---|
672 | { |
---|
673 | assert(predNum[j]>=3); // It is currently always 3! |
---|
674 | if (preds[j][0] > preds[j][1]) |
---|
675 | { |
---|
676 | std::swap(preds[j][0], preds[j][1]); |
---|
677 | } |
---|
678 | if (preds[j][0] > preds[j][2]) |
---|
679 | { |
---|
680 | std::swap(preds[j][0], preds[j][2]); |
---|
681 | } |
---|
682 | if (preds[j][1] > preds[j][2]) |
---|
683 | { |
---|
684 | std::swap(preds[j][1], preds[j][2]); |
---|
685 | } |
---|
686 | for(Int i = (predNum[j] - 1); i >= 0; i--) |
---|
687 | { |
---|
688 | dir[j] = dir[j] > preds[j][i] ? dir[j] - 1 : dir[j]; |
---|
689 | } |
---|
690 | m_pcBinIf->encodeBinsEP( dir[j], 5 ); |
---|
691 | } |
---|
692 | } |
---|
693 | return; |
---|
694 | } |
---|
695 | |
---|
696 | Void TEncSbac::codeIntraDirChroma( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
697 | { |
---|
698 | UInt uiIntraDirChroma = pcCU->getIntraDir( CHANNEL_TYPE_CHROMA, uiAbsPartIdx ); |
---|
699 | |
---|
700 | if( uiIntraDirChroma == DM_CHROMA_IDX ) |
---|
701 | { |
---|
702 | m_pcBinIf->encodeBin( 0, m_cCUChromaPredSCModel.get( 0, 0, 0 ) ); |
---|
703 | } |
---|
704 | else |
---|
705 | { |
---|
706 | m_pcBinIf->encodeBin( 1, m_cCUChromaPredSCModel.get( 0, 0, 0 ) ); |
---|
707 | |
---|
708 | UInt uiAllowedChromaDir[ NUM_CHROMA_MODE ]; |
---|
709 | pcCU->getAllowedChromaDir( uiAbsPartIdx, uiAllowedChromaDir ); |
---|
710 | |
---|
711 | for( Int i = 0; i < NUM_CHROMA_MODE - 1; i++ ) |
---|
712 | { |
---|
713 | if( uiIntraDirChroma == uiAllowedChromaDir[i] ) |
---|
714 | { |
---|
715 | uiIntraDirChroma = i; |
---|
716 | break; |
---|
717 | } |
---|
718 | } |
---|
719 | |
---|
720 | m_pcBinIf->encodeBinsEP( uiIntraDirChroma, 2 ); |
---|
721 | } |
---|
722 | |
---|
723 | return; |
---|
724 | } |
---|
725 | |
---|
726 | |
---|
727 | Void TEncSbac::codeInterDir( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
728 | { |
---|
729 | const UInt uiInterDir = pcCU->getInterDir( uiAbsPartIdx ) - 1; |
---|
730 | const UInt uiCtx = pcCU->getCtxInterDir( uiAbsPartIdx ); |
---|
731 | ContextModel *pCtx = m_cCUInterDirSCModel.get( 0 ); |
---|
732 | |
---|
733 | if (pcCU->getPartitionSize(uiAbsPartIdx) == SIZE_2Nx2N || pcCU->getHeight(uiAbsPartIdx) != 8 ) |
---|
734 | { |
---|
735 | m_pcBinIf->encodeBin( uiInterDir == 2 ? 1 : 0, *( pCtx + uiCtx ) ); |
---|
736 | } |
---|
737 | |
---|
738 | if (uiInterDir < 2) |
---|
739 | { |
---|
740 | m_pcBinIf->encodeBin( uiInterDir, *( pCtx + 4 ) ); |
---|
741 | } |
---|
742 | |
---|
743 | return; |
---|
744 | } |
---|
745 | |
---|
746 | Void TEncSbac::codeRefFrmIdx( TComDataCU* pcCU, UInt uiAbsPartIdx, RefPicList eRefList ) |
---|
747 | { |
---|
748 | Int iRefFrame = pcCU->getCUMvField( eRefList )->getRefIdx( uiAbsPartIdx ); |
---|
749 | ContextModel *pCtx = m_cCURefPicSCModel.get( 0 ); |
---|
750 | m_pcBinIf->encodeBin( ( iRefFrame == 0 ? 0 : 1 ), *pCtx ); |
---|
751 | |
---|
752 | if( iRefFrame > 0 ) |
---|
753 | { |
---|
754 | UInt uiRefNum = pcCU->getSlice()->getNumRefIdx( eRefList ) - 2; |
---|
755 | pCtx++; |
---|
756 | iRefFrame--; |
---|
757 | for( UInt ui = 0; ui < uiRefNum; ++ui ) |
---|
758 | { |
---|
759 | const UInt uiSymbol = ui == iRefFrame ? 0 : 1; |
---|
760 | if( ui == 0 ) |
---|
761 | { |
---|
762 | m_pcBinIf->encodeBin( uiSymbol, *pCtx ); |
---|
763 | } |
---|
764 | else |
---|
765 | { |
---|
766 | m_pcBinIf->encodeBinEP( uiSymbol ); |
---|
767 | } |
---|
768 | if( uiSymbol == 0 ) |
---|
769 | { |
---|
770 | break; |
---|
771 | } |
---|
772 | } |
---|
773 | } |
---|
774 | return; |
---|
775 | } |
---|
776 | |
---|
777 | Void TEncSbac::codeMvd( TComDataCU* pcCU, UInt uiAbsPartIdx, RefPicList eRefList ) |
---|
778 | { |
---|
779 | if(pcCU->getSlice()->getMvdL1ZeroFlag() && eRefList == REF_PIC_LIST_1 && pcCU->getInterDir(uiAbsPartIdx)==3) |
---|
780 | { |
---|
781 | return; |
---|
782 | } |
---|
783 | |
---|
784 | const TComCUMvField* pcCUMvField = pcCU->getCUMvField( eRefList ); |
---|
785 | const Int iHor = pcCUMvField->getMvd( uiAbsPartIdx ).getHor(); |
---|
786 | const Int iVer = pcCUMvField->getMvd( uiAbsPartIdx ).getVer(); |
---|
787 | ContextModel* pCtx = m_cCUMvdSCModel.get( 0 ); |
---|
788 | |
---|
789 | m_pcBinIf->encodeBin( iHor != 0 ? 1 : 0, *pCtx ); |
---|
790 | m_pcBinIf->encodeBin( iVer != 0 ? 1 : 0, *pCtx ); |
---|
791 | |
---|
792 | const Bool bHorAbsGr0 = iHor != 0; |
---|
793 | const Bool bVerAbsGr0 = iVer != 0; |
---|
794 | const UInt uiHorAbs = 0 > iHor ? -iHor : iHor; |
---|
795 | const UInt uiVerAbs = 0 > iVer ? -iVer : iVer; |
---|
796 | pCtx++; |
---|
797 | |
---|
798 | if( bHorAbsGr0 ) |
---|
799 | { |
---|
800 | m_pcBinIf->encodeBin( uiHorAbs > 1 ? 1 : 0, *pCtx ); |
---|
801 | } |
---|
802 | |
---|
803 | if( bVerAbsGr0 ) |
---|
804 | { |
---|
805 | m_pcBinIf->encodeBin( uiVerAbs > 1 ? 1 : 0, *pCtx ); |
---|
806 | } |
---|
807 | |
---|
808 | if( bHorAbsGr0 ) |
---|
809 | { |
---|
810 | if( uiHorAbs > 1 ) |
---|
811 | { |
---|
812 | xWriteEpExGolomb( uiHorAbs-2, 1 ); |
---|
813 | } |
---|
814 | |
---|
815 | m_pcBinIf->encodeBinEP( 0 > iHor ? 1 : 0 ); |
---|
816 | } |
---|
817 | |
---|
818 | if( bVerAbsGr0 ) |
---|
819 | { |
---|
820 | if( uiVerAbs > 1 ) |
---|
821 | { |
---|
822 | xWriteEpExGolomb( uiVerAbs-2, 1 ); |
---|
823 | } |
---|
824 | |
---|
825 | m_pcBinIf->encodeBinEP( 0 > iVer ? 1 : 0 ); |
---|
826 | } |
---|
827 | |
---|
828 | return; |
---|
829 | } |
---|
830 | |
---|
831 | Void TEncSbac::codeCrossComponentPrediction( TComTU &rTu, ComponentID compID ) |
---|
832 | { |
---|
833 | TComDataCU *pcCU = rTu.getCU(); |
---|
834 | |
---|
835 | if( isLuma(compID) || !pcCU->getSlice()->getPPS()->getUseCrossComponentPrediction() ) return; |
---|
836 | |
---|
837 | const UInt uiAbsPartIdx = rTu.GetAbsPartIdxTU(); |
---|
838 | |
---|
839 | if (!pcCU->isIntra(uiAbsPartIdx) || (pcCU->getIntraDir( CHANNEL_TYPE_CHROMA, uiAbsPartIdx ) == DM_CHROMA_IDX)) |
---|
840 | { |
---|
841 | DTRACE_CABAC_VL( g_nSymbolCounter++ ) |
---|
842 | DTRACE_CABAC_T("\tparseCrossComponentPrediction()") |
---|
843 | DTRACE_CABAC_T( "\tAddr=" ) |
---|
844 | DTRACE_CABAC_V( compID ) |
---|
845 | DTRACE_CABAC_T( "\tuiAbsPartIdx=" ) |
---|
846 | DTRACE_CABAC_V( uiAbsPartIdx ) |
---|
847 | |
---|
848 | Int alpha = pcCU->getCrossComponentPredictionAlpha( uiAbsPartIdx, compID ); |
---|
849 | ContextModel *pCtx = m_cCrossComponentPredictionSCModel.get(0, 0) + ((compID == COMPONENT_Cr) ? (NUM_CROSS_COMPONENT_PREDICTION_CTX >> 1) : 0); |
---|
850 | m_pcBinIf->encodeBin(((alpha != 0) ? 1 : 0), pCtx[0]); |
---|
851 | |
---|
852 | if (alpha != 0) |
---|
853 | { |
---|
854 | static const Int log2AbsAlphaMinus1Table[8] = { 0, 1, 1, 2, 2, 2, 3, 3 }; |
---|
855 | assert(abs(alpha) <= 8); |
---|
856 | |
---|
857 | if (abs(alpha)>1) |
---|
858 | { |
---|
859 | m_pcBinIf->encodeBin(1, pCtx[1]); |
---|
860 | xWriteUnaryMaxSymbol( log2AbsAlphaMinus1Table[abs(alpha) - 1] - 1, (pCtx + 2), 1, 2 ); |
---|
861 | } |
---|
862 | else |
---|
863 | { |
---|
864 | m_pcBinIf->encodeBin(0, pCtx[1]); |
---|
865 | } |
---|
866 | m_pcBinIf->encodeBin( ((alpha < 0) ? 1 : 0), pCtx[4] ); |
---|
867 | } |
---|
868 | DTRACE_CABAC_T( "\tAlpha=" ) |
---|
869 | DTRACE_CABAC_V( pcCU->getCrossComponentPredictionAlpha( uiAbsPartIdx, compID ) ) |
---|
870 | DTRACE_CABAC_T( "\n" ) |
---|
871 | } |
---|
872 | } |
---|
873 | |
---|
874 | Void TEncSbac::codeDeltaQP( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
875 | { |
---|
876 | Int iDQp = pcCU->getQP( uiAbsPartIdx ) - pcCU->getRefQP( uiAbsPartIdx ); |
---|
877 | |
---|
878 | #if SVC_EXTENSION |
---|
879 | Int qpBdOffsetY = pcCU->getSlice()->getQpBDOffsetY(); |
---|
880 | #else |
---|
881 | Int qpBdOffsetY = pcCU->getSlice()->getSPS()->getQpBDOffset(CHANNEL_TYPE_LUMA); |
---|
882 | #endif |
---|
883 | iDQp = (iDQp + 78 + qpBdOffsetY + (qpBdOffsetY/2)) % (52 + qpBdOffsetY) - 26 - (qpBdOffsetY/2); |
---|
884 | |
---|
885 | UInt uiAbsDQp = (UInt)((iDQp > 0)? iDQp : (-iDQp)); |
---|
886 | UInt TUValue = min((Int)uiAbsDQp, CU_DQP_TU_CMAX); |
---|
887 | xWriteUnaryMaxSymbol( TUValue, &m_cCUDeltaQpSCModel.get( 0, 0, 0 ), 1, CU_DQP_TU_CMAX); |
---|
888 | if( uiAbsDQp >= CU_DQP_TU_CMAX ) |
---|
889 | { |
---|
890 | xWriteEpExGolomb( uiAbsDQp - CU_DQP_TU_CMAX, CU_DQP_EG_k ); |
---|
891 | } |
---|
892 | |
---|
893 | if ( uiAbsDQp > 0) |
---|
894 | { |
---|
895 | UInt uiSign = (iDQp > 0 ? 0 : 1); |
---|
896 | m_pcBinIf->encodeBinEP(uiSign); |
---|
897 | } |
---|
898 | |
---|
899 | return; |
---|
900 | } |
---|
901 | |
---|
902 | /** code chroma qp adjustment, converting from the internal table representation |
---|
903 | * \returns Void |
---|
904 | */ |
---|
905 | Void TEncSbac::codeChromaQpAdjustment( TComDataCU* cu, UInt absPartIdx ) |
---|
906 | { |
---|
907 | Int internalIdc = cu->getChromaQpAdj( absPartIdx ); |
---|
908 | Int tableSize = cu->getSlice()->getPPS()->getChromaQpAdjTableSize(); |
---|
909 | /* internal_idc == 0 => flag = 0 |
---|
910 | * internal_idc > 1 => code idc value (if table size warrents) */ |
---|
911 | m_pcBinIf->encodeBin( internalIdc > 0, m_ChromaQpAdjFlagSCModel.get( 0, 0, 0 ) ); |
---|
912 | |
---|
913 | if (internalIdc > 0 && tableSize > 1) |
---|
914 | { |
---|
915 | xWriteUnaryMaxSymbol( internalIdc - 1, &m_ChromaQpAdjIdcSCModel.get( 0, 0, 0 ), 0, tableSize - 1 ); |
---|
916 | } |
---|
917 | } |
---|
918 | |
---|
919 | Void TEncSbac::codeQtCbf( TComTU &rTu, const ComponentID compID, const Bool lowestLevel ) |
---|
920 | { |
---|
921 | TComDataCU* pcCU = rTu.getCU(); |
---|
922 | |
---|
923 | const UInt absPartIdx = rTu.GetAbsPartIdxTU(compID); |
---|
924 | const UInt TUDepth = rTu.GetTransformDepthRel(); |
---|
925 | UInt uiCtx = pcCU->getCtxQtCbf( rTu, toChannelType(compID) ); |
---|
926 | const UInt contextSet = toChannelType(compID); |
---|
927 | |
---|
928 | const UInt width = rTu.getRect(compID).width; |
---|
929 | const UInt height = rTu.getRect(compID).height; |
---|
930 | const Bool canQuadSplit = (width >= (MIN_TU_SIZE * 2)) && (height >= (MIN_TU_SIZE * 2)); |
---|
931 | |
---|
932 | // Since the CBF for chroma is coded at the highest level possible, if sub-TUs are |
---|
933 | // to be coded for a 4x8 chroma TU, their CBFs must be coded at the highest 4x8 level |
---|
934 | // (i.e. where luma TUs are 8x8 rather than 4x4) |
---|
935 | // ___ ___ |
---|
936 | // | | | <- 4 x (8x8 luma + 4x8 4:2:2 chroma) |
---|
937 | // |___|___| each quadrant has its own chroma CBF |
---|
938 | // | | | _ _ _ _ |
---|
939 | // |___|___| | |
---|
940 | // <--16---> V |
---|
941 | // _ _ |
---|
942 | // |_|_| <- 4 x 4x4 luma + 1 x 4x8 4:2:2 chroma |
---|
943 | // |_|_| no chroma CBF is coded - instead the parent CBF is inherited |
---|
944 | // <-8-> if sub-TUs are present, their CBFs had to be coded at the parent level |
---|
945 | |
---|
946 | const UInt lowestTUDepth = TUDepth + ((!lowestLevel && !canQuadSplit) ? 1 : 0); //unsplittable TUs inherit their parent's CBF |
---|
947 | |
---|
948 | if ((width != height) && (lowestLevel || !canQuadSplit)) //if sub-TUs are present |
---|
949 | { |
---|
950 | const UInt subTUDepth = lowestTUDepth + 1; //if this is the lowest level of the TU-tree, the sub-TUs are directly below. Otherwise, this must be the level above the lowest level (as specified above) |
---|
951 | const UInt partIdxesPerSubTU = rTu.GetAbsPartIdxNumParts(compID) >> 1; |
---|
952 | |
---|
953 | for (UInt subTU = 0; subTU < 2; subTU++) |
---|
954 | { |
---|
955 | const UInt subTUAbsPartIdx = absPartIdx + (subTU * partIdxesPerSubTU); |
---|
956 | const UInt uiCbf = pcCU->getCbf(subTUAbsPartIdx, compID, subTUDepth); |
---|
957 | |
---|
958 | m_pcBinIf->encodeBin(uiCbf, m_cCUQtCbfSCModel.get(0, contextSet, uiCtx)); |
---|
959 | |
---|
960 | DTRACE_CABAC_VL( g_nSymbolCounter++ ) |
---|
961 | DTRACE_CABAC_T( "\tparseQtCbf()" ) |
---|
962 | DTRACE_CABAC_T( "\tsub-TU=" ) |
---|
963 | DTRACE_CABAC_V( subTU ) |
---|
964 | DTRACE_CABAC_T( "\tsymbol=" ) |
---|
965 | DTRACE_CABAC_V( uiCbf ) |
---|
966 | DTRACE_CABAC_T( "\tctx=" ) |
---|
967 | DTRACE_CABAC_V( uiCtx ) |
---|
968 | DTRACE_CABAC_T( "\tetype=" ) |
---|
969 | DTRACE_CABAC_V( compID ) |
---|
970 | DTRACE_CABAC_T( "\tuiAbsPartIdx=" ) |
---|
971 | DTRACE_CABAC_V( subTUAbsPartIdx ) |
---|
972 | DTRACE_CABAC_T( "\n" ) |
---|
973 | } |
---|
974 | } |
---|
975 | else |
---|
976 | { |
---|
977 | const UInt uiCbf = pcCU->getCbf( absPartIdx, compID, lowestTUDepth ); |
---|
978 | m_pcBinIf->encodeBin( uiCbf , m_cCUQtCbfSCModel.get( 0, contextSet, uiCtx ) ); |
---|
979 | |
---|
980 | |
---|
981 | DTRACE_CABAC_VL( g_nSymbolCounter++ ) |
---|
982 | DTRACE_CABAC_T( "\tparseQtCbf()" ) |
---|
983 | DTRACE_CABAC_T( "\tsymbol=" ) |
---|
984 | DTRACE_CABAC_V( uiCbf ) |
---|
985 | DTRACE_CABAC_T( "\tctx=" ) |
---|
986 | DTRACE_CABAC_V( uiCtx ) |
---|
987 | DTRACE_CABAC_T( "\tetype=" ) |
---|
988 | DTRACE_CABAC_V( compID ) |
---|
989 | DTRACE_CABAC_T( "\tuiAbsPartIdx=" ) |
---|
990 | DTRACE_CABAC_V( rTu.GetAbsPartIdxTU(compID) ) |
---|
991 | DTRACE_CABAC_T( "\n" ) |
---|
992 | } |
---|
993 | } |
---|
994 | |
---|
995 | |
---|
996 | Void TEncSbac::codeTransformSkipFlags (TComTU &rTu, ComponentID component ) |
---|
997 | { |
---|
998 | TComDataCU* pcCU=rTu.getCU(); |
---|
999 | const UInt uiAbsPartIdx=rTu.GetAbsPartIdxTU(); |
---|
1000 | |
---|
1001 | if (pcCU->getCUTransquantBypass(uiAbsPartIdx)) |
---|
1002 | { |
---|
1003 | return; |
---|
1004 | } |
---|
1005 | |
---|
1006 | if (!TUCompRectHasAssociatedTransformSkipFlag(rTu.getRect(component), pcCU->getSlice()->getPPS()->getTransformSkipLog2MaxSize())) |
---|
1007 | { |
---|
1008 | return; |
---|
1009 | } |
---|
1010 | |
---|
1011 | UInt useTransformSkip = pcCU->getTransformSkip( uiAbsPartIdx,component); |
---|
1012 | m_pcBinIf->encodeBin( useTransformSkip, m_cTransformSkipSCModel.get( 0, toChannelType(component), 0 ) ); |
---|
1013 | |
---|
1014 | DTRACE_CABAC_VL( g_nSymbolCounter++ ) |
---|
1015 | DTRACE_CABAC_T("\tparseTransformSkip()"); |
---|
1016 | DTRACE_CABAC_T( "\tsymbol=" ) |
---|
1017 | DTRACE_CABAC_V( useTransformSkip ) |
---|
1018 | DTRACE_CABAC_T( "\tAddr=" ) |
---|
1019 | DTRACE_CABAC_V( pcCU->getCtuRsAddr() ) |
---|
1020 | DTRACE_CABAC_T( "\tetype=" ) |
---|
1021 | DTRACE_CABAC_V( component ) |
---|
1022 | DTRACE_CABAC_T( "\tuiAbsPartIdx=" ) |
---|
1023 | DTRACE_CABAC_V( rTu.GetAbsPartIdxTU() ) |
---|
1024 | DTRACE_CABAC_T( "\n" ) |
---|
1025 | } |
---|
1026 | |
---|
1027 | |
---|
1028 | /** Code I_PCM information. |
---|
1029 | * \param pcCU pointer to CU |
---|
1030 | * \param uiAbsPartIdx CU index |
---|
1031 | * \returns Void |
---|
1032 | */ |
---|
1033 | Void TEncSbac::codeIPCMInfo( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
1034 | { |
---|
1035 | UInt uiIPCM = (pcCU->getIPCMFlag(uiAbsPartIdx) == true)? 1 : 0; |
---|
1036 | |
---|
1037 | Bool writePCMSampleFlag = pcCU->getIPCMFlag(uiAbsPartIdx); |
---|
1038 | |
---|
1039 | m_pcBinIf->encodeBinTrm (uiIPCM); |
---|
1040 | |
---|
1041 | if (writePCMSampleFlag) |
---|
1042 | { |
---|
1043 | m_pcBinIf->encodePCMAlignBits(); |
---|
1044 | |
---|
1045 | const UInt minCoeffSizeY = pcCU->getPic()->getMinCUWidth() * pcCU->getPic()->getMinCUHeight(); |
---|
1046 | const UInt offsetY = minCoeffSizeY * uiAbsPartIdx; |
---|
1047 | for (UInt ch=0; ch < pcCU->getPic()->getNumberValidComponents(); ch++) |
---|
1048 | { |
---|
1049 | const ComponentID compID = ComponentID(ch); |
---|
1050 | const UInt offset = offsetY >> (pcCU->getPic()->getComponentScaleX(compID) + pcCU->getPic()->getComponentScaleY(compID)); |
---|
1051 | Pel * pPCMSample = pcCU->getPCMSample(compID) + offset; |
---|
1052 | const UInt width = pcCU->getWidth (uiAbsPartIdx) >> pcCU->getPic()->getComponentScaleX(compID); |
---|
1053 | const UInt height = pcCU->getHeight(uiAbsPartIdx) >> pcCU->getPic()->getComponentScaleY(compID); |
---|
1054 | const UInt sampleBits = pcCU->getSlice()->getSPS()->getPCMBitDepth(toChannelType(compID)); |
---|
1055 | for (UInt y=0; y<height; y++) |
---|
1056 | { |
---|
1057 | for (UInt x=0; x<width; x++) |
---|
1058 | { |
---|
1059 | UInt sample = pPCMSample[x]; |
---|
1060 | m_pcBinIf->xWritePCMCode(sample, sampleBits); |
---|
1061 | } |
---|
1062 | pPCMSample += width; |
---|
1063 | } |
---|
1064 | } |
---|
1065 | |
---|
1066 | m_pcBinIf->resetBac(); |
---|
1067 | } |
---|
1068 | } |
---|
1069 | |
---|
1070 | Void TEncSbac::codeQtRootCbf( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
1071 | { |
---|
1072 | UInt uiCbf = pcCU->getQtRootCbf( uiAbsPartIdx ); |
---|
1073 | UInt uiCtx = 0; |
---|
1074 | m_pcBinIf->encodeBin( uiCbf , m_cCUQtRootCbfSCModel.get( 0, 0, uiCtx ) ); |
---|
1075 | DTRACE_CABAC_VL( g_nSymbolCounter++ ) |
---|
1076 | DTRACE_CABAC_T( "\tparseQtRootCbf()" ) |
---|
1077 | DTRACE_CABAC_T( "\tsymbol=" ) |
---|
1078 | DTRACE_CABAC_V( uiCbf ) |
---|
1079 | DTRACE_CABAC_T( "\tctx=" ) |
---|
1080 | DTRACE_CABAC_V( uiCtx ) |
---|
1081 | DTRACE_CABAC_T( "\tuiAbsPartIdx=" ) |
---|
1082 | DTRACE_CABAC_V( uiAbsPartIdx ) |
---|
1083 | DTRACE_CABAC_T( "\n" ) |
---|
1084 | } |
---|
1085 | |
---|
1086 | Void TEncSbac::codeQtCbfZero( TComTU & rTu, const ChannelType chType ) |
---|
1087 | { |
---|
1088 | // this function is only used to estimate the bits when cbf is 0 |
---|
1089 | // and will never be called when writing the bistream. do not need to write log |
---|
1090 | UInt uiCbf = 0; |
---|
1091 | UInt uiCtx = rTu.getCU()->getCtxQtCbf( rTu, chType ); |
---|
1092 | |
---|
1093 | m_pcBinIf->encodeBin( uiCbf , m_cCUQtCbfSCModel.get( 0, chType, uiCtx ) ); |
---|
1094 | } |
---|
1095 | |
---|
1096 | Void TEncSbac::codeQtRootCbfZero( TComDataCU* pcCU ) |
---|
1097 | { |
---|
1098 | // this function is only used to estimate the bits when cbf is 0 |
---|
1099 | // and will never be called when writing the bistream. do not need to write log |
---|
1100 | UInt uiCbf = 0; |
---|
1101 | UInt uiCtx = 0; |
---|
1102 | m_pcBinIf->encodeBin( uiCbf , m_cCUQtRootCbfSCModel.get( 0, 0, uiCtx ) ); |
---|
1103 | } |
---|
1104 | |
---|
1105 | /** Encode (X,Y) position of the last significant coefficient |
---|
1106 | * \param uiPosX X component of last coefficient |
---|
1107 | * \param uiPosY Y component of last coefficient |
---|
1108 | * \param width Block width |
---|
1109 | * \param height Block height |
---|
1110 | * \param eTType plane type / luminance or chrominance |
---|
1111 | * \param uiScanIdx scan type (zig-zag, hor, ver) |
---|
1112 | * This method encodes the X and Y component within a block of the last significant coefficient. |
---|
1113 | */ |
---|
1114 | Void TEncSbac::codeLastSignificantXY( UInt uiPosX, UInt uiPosY, Int width, Int height, ComponentID component, UInt uiScanIdx ) |
---|
1115 | { |
---|
1116 | // swap |
---|
1117 | if( uiScanIdx == SCAN_VER ) |
---|
1118 | { |
---|
1119 | swap( uiPosX, uiPosY ); |
---|
1120 | swap( width, height ); |
---|
1121 | } |
---|
1122 | |
---|
1123 | UInt uiCtxLast; |
---|
1124 | UInt uiGroupIdxX = g_uiGroupIdx[ uiPosX ]; |
---|
1125 | UInt uiGroupIdxY = g_uiGroupIdx[ uiPosY ]; |
---|
1126 | |
---|
1127 | ContextModel *pCtxX = m_cCuCtxLastX.get( 0, toChannelType(component) ); |
---|
1128 | ContextModel *pCtxY = m_cCuCtxLastY.get( 0, toChannelType(component) ); |
---|
1129 | |
---|
1130 | Int blkSizeOffsetX, blkSizeOffsetY, shiftX, shiftY; |
---|
1131 | getLastSignificantContextParameters(component, width, height, blkSizeOffsetX, blkSizeOffsetY, shiftX, shiftY); |
---|
1132 | |
---|
1133 | //------------------ |
---|
1134 | |
---|
1135 | // posX |
---|
1136 | |
---|
1137 | for( uiCtxLast = 0; uiCtxLast < uiGroupIdxX; uiCtxLast++ ) |
---|
1138 | { |
---|
1139 | m_pcBinIf->encodeBin( 1, *( pCtxX + blkSizeOffsetX + (uiCtxLast >>shiftX) ) ); |
---|
1140 | } |
---|
1141 | if( uiGroupIdxX < g_uiGroupIdx[ width - 1 ]) |
---|
1142 | { |
---|
1143 | m_pcBinIf->encodeBin( 0, *( pCtxX + blkSizeOffsetX + (uiCtxLast >>shiftX) ) ); |
---|
1144 | } |
---|
1145 | |
---|
1146 | // posY |
---|
1147 | |
---|
1148 | for( uiCtxLast = 0; uiCtxLast < uiGroupIdxY; uiCtxLast++ ) |
---|
1149 | { |
---|
1150 | m_pcBinIf->encodeBin( 1, *( pCtxY + blkSizeOffsetY + (uiCtxLast >>shiftY) ) ); |
---|
1151 | } |
---|
1152 | if( uiGroupIdxY < g_uiGroupIdx[ height - 1 ]) |
---|
1153 | { |
---|
1154 | m_pcBinIf->encodeBin( 0, *( pCtxY + blkSizeOffsetY + (uiCtxLast >>shiftY) ) ); |
---|
1155 | } |
---|
1156 | |
---|
1157 | // EP-coded part |
---|
1158 | |
---|
1159 | if ( uiGroupIdxX > 3 ) |
---|
1160 | { |
---|
1161 | UInt uiCount = ( uiGroupIdxX - 2 ) >> 1; |
---|
1162 | uiPosX = uiPosX - g_uiMinInGroup[ uiGroupIdxX ]; |
---|
1163 | for (Int i = uiCount - 1 ; i >= 0; i-- ) |
---|
1164 | { |
---|
1165 | m_pcBinIf->encodeBinEP( ( uiPosX >> i ) & 1 ); |
---|
1166 | } |
---|
1167 | } |
---|
1168 | if ( uiGroupIdxY > 3 ) |
---|
1169 | { |
---|
1170 | UInt uiCount = ( uiGroupIdxY - 2 ) >> 1; |
---|
1171 | uiPosY = uiPosY - g_uiMinInGroup[ uiGroupIdxY ]; |
---|
1172 | for ( Int i = uiCount - 1 ; i >= 0; i-- ) |
---|
1173 | { |
---|
1174 | m_pcBinIf->encodeBinEP( ( uiPosY >> i ) & 1 ); |
---|
1175 | } |
---|
1176 | } |
---|
1177 | } |
---|
1178 | |
---|
1179 | |
---|
1180 | Void TEncSbac::codeCoeffNxN( TComTU &rTu, TCoeff* pcCoef, const ComponentID compID ) |
---|
1181 | { |
---|
1182 | TComDataCU* pcCU=rTu.getCU(); |
---|
1183 | const UInt uiAbsPartIdx=rTu.GetAbsPartIdxTU(compID); |
---|
1184 | const TComRectangle &tuRect=rTu.getRect(compID); |
---|
1185 | const UInt uiWidth=tuRect.width; |
---|
1186 | const UInt uiHeight=tuRect.height; |
---|
1187 | |
---|
1188 | DTRACE_CABAC_VL( g_nSymbolCounter++ ) |
---|
1189 | DTRACE_CABAC_T( "\tparseCoeffNxN()\teType=" ) |
---|
1190 | DTRACE_CABAC_V( compID ) |
---|
1191 | DTRACE_CABAC_T( "\twidth=" ) |
---|
1192 | DTRACE_CABAC_V( uiWidth ) |
---|
1193 | DTRACE_CABAC_T( "\theight=" ) |
---|
1194 | DTRACE_CABAC_V( uiHeight ) |
---|
1195 | DTRACE_CABAC_T( "\tdepth=" ) |
---|
1196 | // DTRACE_CABAC_V( rTu.GetTransformDepthTotalAdj(compID) ) |
---|
1197 | DTRACE_CABAC_V( rTu.GetTransformDepthTotal() ) |
---|
1198 | DTRACE_CABAC_T( "\tabspartidx=" ) |
---|
1199 | DTRACE_CABAC_V( uiAbsPartIdx ) |
---|
1200 | DTRACE_CABAC_T( "\ttoCU-X=" ) |
---|
1201 | DTRACE_CABAC_V( pcCU->getCUPelX() ) |
---|
1202 | DTRACE_CABAC_T( "\ttoCU-Y=" ) |
---|
1203 | DTRACE_CABAC_V( pcCU->getCUPelY() ) |
---|
1204 | DTRACE_CABAC_T( "\tCU-addr=" ) |
---|
1205 | DTRACE_CABAC_V( pcCU->getCtuRsAddr() ) |
---|
1206 | DTRACE_CABAC_T( "\tinCU-X=" ) |
---|
1207 | // DTRACE_CABAC_V( g_auiRasterToPelX[ g_auiZscanToRaster[uiAbsPartIdx] ] ) |
---|
1208 | DTRACE_CABAC_V( g_auiRasterToPelX[ g_auiZscanToRaster[rTu.GetAbsPartIdxTU(compID)] ] ) |
---|
1209 | DTRACE_CABAC_T( "\tinCU-Y=" ) |
---|
1210 | // DTRACE_CABAC_V( g_auiRasterToPelY[ g_auiZscanToRaster[uiAbsPartIdx] ] ) |
---|
1211 | DTRACE_CABAC_V( g_auiRasterToPelY[ g_auiZscanToRaster[rTu.GetAbsPartIdxTU(compID)] ] ) |
---|
1212 | DTRACE_CABAC_T( "\tpredmode=" ) |
---|
1213 | DTRACE_CABAC_V( pcCU->getPredictionMode( uiAbsPartIdx ) ) |
---|
1214 | DTRACE_CABAC_T( "\n" ) |
---|
1215 | |
---|
1216 | //-------------------------------------------------------------------------------------------------- |
---|
1217 | |
---|
1218 | if( uiWidth > m_pcSlice->getSPS()->getMaxTrSize() ) |
---|
1219 | { |
---|
1220 | std::cerr << "ERROR: codeCoeffNxN was passed a TU with dimensions larger than the maximum allowed size" << std::endl; |
---|
1221 | assert(false); |
---|
1222 | exit(1); |
---|
1223 | } |
---|
1224 | |
---|
1225 | // compute number of significant coefficients |
---|
1226 | UInt uiNumSig = TEncEntropy::countNonZeroCoeffs(pcCoef, uiWidth * uiHeight); |
---|
1227 | |
---|
1228 | if ( uiNumSig == 0 ) |
---|
1229 | { |
---|
1230 | std::cerr << "ERROR: codeCoeffNxN called for empty TU!" << std::endl; |
---|
1231 | assert(false); |
---|
1232 | exit(1); |
---|
1233 | } |
---|
1234 | |
---|
1235 | //-------------------------------------------------------------------------------------------------- |
---|
1236 | |
---|
1237 | //set parameters |
---|
1238 | |
---|
1239 | const ChannelType chType = toChannelType(compID); |
---|
1240 | const UInt uiLog2BlockWidth = g_aucConvertToBit[ uiWidth ] + 2; |
---|
1241 | const UInt uiLog2BlockHeight = g_aucConvertToBit[ uiHeight ] + 2; |
---|
1242 | |
---|
1243 | const ChannelType channelType = toChannelType(compID); |
---|
1244 | const Bool extendedPrecision = pcCU->getSlice()->getSPS()->getUseExtendedPrecision(); |
---|
1245 | |
---|
1246 | const Bool alignCABACBeforeBypass = pcCU->getSlice()->getSPS()->getAlignCABACBeforeBypass(); |
---|
1247 | |
---|
1248 | Bool beValid; |
---|
1249 | |
---|
1250 | { |
---|
1251 | Int uiIntraMode = -1; |
---|
1252 | const Bool bIsLuma = isLuma(compID); |
---|
1253 | Int isIntra = pcCU->isIntra(uiAbsPartIdx) ? 1 : 0; |
---|
1254 | if ( isIntra ) |
---|
1255 | { |
---|
1256 | uiIntraMode = pcCU->getIntraDir( toChannelType(compID), uiAbsPartIdx ); |
---|
1257 | |
---|
1258 | uiIntraMode = (uiIntraMode==DM_CHROMA_IDX && !bIsLuma) ? pcCU->getIntraDir(CHANNEL_TYPE_LUMA, getChromasCorrespondingPULumaIdx(uiAbsPartIdx, rTu.GetChromaFormat())) : uiIntraMode; |
---|
1259 | uiIntraMode = ((rTu.GetChromaFormat() == CHROMA_422) && !bIsLuma) ? g_chroma422IntraAngleMappingTable[uiIntraMode] : uiIntraMode; |
---|
1260 | } |
---|
1261 | |
---|
1262 | Int transformSkip = pcCU->getTransformSkip( uiAbsPartIdx,compID) ? 1 : 0; |
---|
1263 | Bool rdpcm_lossy = ( transformSkip && isIntra && ( (uiIntraMode == HOR_IDX) || (uiIntraMode == VER_IDX) ) ) && pcCU->isRDPCMEnabled(uiAbsPartIdx); |
---|
1264 | |
---|
1265 | if ( (pcCU->getCUTransquantBypass(uiAbsPartIdx)) || rdpcm_lossy ) |
---|
1266 | { |
---|
1267 | beValid = false; |
---|
1268 | if ( (!pcCU->isIntra(uiAbsPartIdx)) && pcCU->isRDPCMEnabled(uiAbsPartIdx)) |
---|
1269 | codeExplicitRdpcmMode( rTu, compID); |
---|
1270 | } |
---|
1271 | else |
---|
1272 | { |
---|
1273 | beValid = pcCU->getSlice()->getPPS()->getSignHideFlag() > 0; |
---|
1274 | } |
---|
1275 | } |
---|
1276 | |
---|
1277 | //-------------------------------------------------------------------------------------------------- |
---|
1278 | |
---|
1279 | if(pcCU->getSlice()->getPPS()->getUseTransformSkip()) |
---|
1280 | { |
---|
1281 | codeTransformSkipFlags(rTu, compID); |
---|
1282 | if(pcCU->getTransformSkip(uiAbsPartIdx, compID) && !pcCU->isIntra(uiAbsPartIdx) && pcCU->isRDPCMEnabled(uiAbsPartIdx)) |
---|
1283 | { |
---|
1284 | // This TU has coefficients and is transform skipped. Check whether is inter coded and if yes encode the explicit RDPCM mode |
---|
1285 | codeExplicitRdpcmMode( rTu, compID); |
---|
1286 | |
---|
1287 | if(pcCU->getExplicitRdpcmMode(compID, uiAbsPartIdx) != RDPCM_OFF) |
---|
1288 | { |
---|
1289 | // Sign data hiding is avoided for horizontal and vertical explicit RDPCM modes |
---|
1290 | beValid = false; |
---|
1291 | } |
---|
1292 | } |
---|
1293 | } |
---|
1294 | |
---|
1295 | //-------------------------------------------------------------------------------------------------- |
---|
1296 | |
---|
1297 | const Bool bUseGolombRiceParameterAdaptation = pcCU->getSlice()->getSPS()->getUseGolombRiceParameterAdaptation(); |
---|
1298 | UInt ¤tGolombRiceStatistic = m_golombRiceAdaptationStatistics[rTu.getGolombRiceStatisticsIndex(compID)]; |
---|
1299 | |
---|
1300 | //select scans |
---|
1301 | TUEntropyCodingParameters codingParameters; |
---|
1302 | getTUEntropyCodingParameters(codingParameters, rTu, compID); |
---|
1303 | |
---|
1304 | //----- encode significance map ----- |
---|
1305 | |
---|
1306 | // Find position of last coefficient |
---|
1307 | Int scanPosLast = -1; |
---|
1308 | Int posLast; |
---|
1309 | |
---|
1310 | |
---|
1311 | UInt uiSigCoeffGroupFlag[ MLS_GRP_NUM ]; |
---|
1312 | |
---|
1313 | memset( uiSigCoeffGroupFlag, 0, sizeof(UInt) * MLS_GRP_NUM ); |
---|
1314 | do |
---|
1315 | { |
---|
1316 | posLast = codingParameters.scan[ ++scanPosLast ]; |
---|
1317 | |
---|
1318 | if( pcCoef[ posLast ] != 0 ) |
---|
1319 | { |
---|
1320 | // get L1 sig map |
---|
1321 | UInt uiPosY = posLast >> uiLog2BlockWidth; |
---|
1322 | UInt uiPosX = posLast - ( uiPosY << uiLog2BlockWidth ); |
---|
1323 | |
---|
1324 | UInt uiBlkIdx = (codingParameters.widthInGroups * (uiPosY >> MLS_CG_LOG2_HEIGHT)) + (uiPosX >> MLS_CG_LOG2_WIDTH); |
---|
1325 | uiSigCoeffGroupFlag[ uiBlkIdx ] = 1; |
---|
1326 | |
---|
1327 | uiNumSig--; |
---|
1328 | } |
---|
1329 | } |
---|
1330 | while ( uiNumSig > 0 ); |
---|
1331 | |
---|
1332 | // Code position of last coefficient |
---|
1333 | Int posLastY = posLast >> uiLog2BlockWidth; |
---|
1334 | Int posLastX = posLast - ( posLastY << uiLog2BlockWidth ); |
---|
1335 | codeLastSignificantXY(posLastX, posLastY, uiWidth, uiHeight, compID, codingParameters.scanType); |
---|
1336 | |
---|
1337 | //===== code significance flag ===== |
---|
1338 | ContextModel * const baseCoeffGroupCtx = m_cCUSigCoeffGroupSCModel.get( 0, chType ); |
---|
1339 | ContextModel * const baseCtx = m_cCUSigSCModel.get( 0, 0 ) + getSignificanceMapContextOffset(compID); |
---|
1340 | |
---|
1341 | const Int iLastScanSet = scanPosLast >> MLS_CG_SIZE; |
---|
1342 | |
---|
1343 | UInt c1 = 1; |
---|
1344 | UInt uiGoRiceParam = 0; |
---|
1345 | Int iScanPosSig = scanPosLast; |
---|
1346 | |
---|
1347 | for( Int iSubSet = iLastScanSet; iSubSet >= 0; iSubSet-- ) |
---|
1348 | { |
---|
1349 | Int numNonZero = 0; |
---|
1350 | Int iSubPos = iSubSet << MLS_CG_SIZE; |
---|
1351 | uiGoRiceParam = currentGolombRiceStatistic / RExt__GOLOMB_RICE_INCREMENT_DIVISOR; |
---|
1352 | Bool updateGolombRiceStatistics = bUseGolombRiceParameterAdaptation; //leave the statistics at 0 when not using the adaptation system |
---|
1353 | UInt coeffSigns = 0; |
---|
1354 | |
---|
1355 | Int absCoeff[1 << MLS_CG_SIZE]; |
---|
1356 | |
---|
1357 | Int lastNZPosInCG = -1; |
---|
1358 | Int firstNZPosInCG = 1 << MLS_CG_SIZE; |
---|
1359 | |
---|
1360 | Bool escapeDataPresentInGroup = false; |
---|
1361 | |
---|
1362 | if( iScanPosSig == scanPosLast ) |
---|
1363 | { |
---|
1364 | absCoeff[ 0 ] = Int(abs( pcCoef[ posLast ] )); |
---|
1365 | coeffSigns = ( pcCoef[ posLast ] < 0 ); |
---|
1366 | numNonZero = 1; |
---|
1367 | lastNZPosInCG = iScanPosSig; |
---|
1368 | firstNZPosInCG = iScanPosSig; |
---|
1369 | iScanPosSig--; |
---|
1370 | } |
---|
1371 | |
---|
1372 | // encode significant_coeffgroup_flag |
---|
1373 | Int iCGBlkPos = codingParameters.scanCG[ iSubSet ]; |
---|
1374 | Int iCGPosY = iCGBlkPos / codingParameters.widthInGroups; |
---|
1375 | Int iCGPosX = iCGBlkPos - (iCGPosY * codingParameters.widthInGroups); |
---|
1376 | |
---|
1377 | if( iSubSet == iLastScanSet || iSubSet == 0) |
---|
1378 | { |
---|
1379 | uiSigCoeffGroupFlag[ iCGBlkPos ] = 1; |
---|
1380 | } |
---|
1381 | else |
---|
1382 | { |
---|
1383 | UInt uiSigCoeffGroup = (uiSigCoeffGroupFlag[ iCGBlkPos ] != 0); |
---|
1384 | UInt uiCtxSig = TComTrQuant::getSigCoeffGroupCtxInc( uiSigCoeffGroupFlag, iCGPosX, iCGPosY, codingParameters.widthInGroups, codingParameters.heightInGroups ); |
---|
1385 | m_pcBinIf->encodeBin( uiSigCoeffGroup, baseCoeffGroupCtx[ uiCtxSig ] ); |
---|
1386 | } |
---|
1387 | |
---|
1388 | // encode significant_coeff_flag |
---|
1389 | if( uiSigCoeffGroupFlag[ iCGBlkPos ] ) |
---|
1390 | { |
---|
1391 | const Int patternSigCtx = TComTrQuant::calcPatternSigCtx(uiSigCoeffGroupFlag, iCGPosX, iCGPosY, codingParameters.widthInGroups, codingParameters.heightInGroups); |
---|
1392 | |
---|
1393 | UInt uiBlkPos, uiSig, uiCtxSig; |
---|
1394 | for( ; iScanPosSig >= iSubPos; iScanPosSig-- ) |
---|
1395 | { |
---|
1396 | uiBlkPos = codingParameters.scan[ iScanPosSig ]; |
---|
1397 | uiSig = (pcCoef[ uiBlkPos ] != 0); |
---|
1398 | if( iScanPosSig > iSubPos || iSubSet == 0 || numNonZero ) |
---|
1399 | { |
---|
1400 | uiCtxSig = TComTrQuant::getSigCtxInc( patternSigCtx, codingParameters, iScanPosSig, uiLog2BlockWidth, uiLog2BlockHeight, chType ); |
---|
1401 | m_pcBinIf->encodeBin( uiSig, baseCtx[ uiCtxSig ] ); |
---|
1402 | } |
---|
1403 | if( uiSig ) |
---|
1404 | { |
---|
1405 | absCoeff[ numNonZero ] = Int(abs( pcCoef[ uiBlkPos ] )); |
---|
1406 | coeffSigns = 2 * coeffSigns + ( pcCoef[ uiBlkPos ] < 0 ); |
---|
1407 | numNonZero++; |
---|
1408 | if( lastNZPosInCG == -1 ) |
---|
1409 | { |
---|
1410 | lastNZPosInCG = iScanPosSig; |
---|
1411 | } |
---|
1412 | firstNZPosInCG = iScanPosSig; |
---|
1413 | } |
---|
1414 | } |
---|
1415 | } |
---|
1416 | else |
---|
1417 | { |
---|
1418 | iScanPosSig = iSubPos - 1; |
---|
1419 | } |
---|
1420 | |
---|
1421 | if( numNonZero > 0 ) |
---|
1422 | { |
---|
1423 | Bool signHidden = ( lastNZPosInCG - firstNZPosInCG >= SBH_THRESHOLD ); |
---|
1424 | |
---|
1425 | const UInt uiCtxSet = getContextSetIndex(compID, iSubSet, (c1 == 0)); |
---|
1426 | c1 = 1; |
---|
1427 | |
---|
1428 | ContextModel *baseCtxMod = m_cCUOneSCModel.get( 0, 0 ) + (NUM_ONE_FLAG_CTX_PER_SET * uiCtxSet); |
---|
1429 | |
---|
1430 | Int numC1Flag = min(numNonZero, C1FLAG_NUMBER); |
---|
1431 | Int firstC2FlagIdx = -1; |
---|
1432 | for( Int idx = 0; idx < numC1Flag; idx++ ) |
---|
1433 | { |
---|
1434 | UInt uiSymbol = absCoeff[ idx ] > 1; |
---|
1435 | m_pcBinIf->encodeBin( uiSymbol, baseCtxMod[c1] ); |
---|
1436 | if( uiSymbol ) |
---|
1437 | { |
---|
1438 | c1 = 0; |
---|
1439 | |
---|
1440 | if (firstC2FlagIdx == -1) |
---|
1441 | { |
---|
1442 | firstC2FlagIdx = idx; |
---|
1443 | } |
---|
1444 | else //if a greater-than-one has been encountered already this group |
---|
1445 | { |
---|
1446 | escapeDataPresentInGroup = true; |
---|
1447 | } |
---|
1448 | } |
---|
1449 | else if( (c1 < 3) && (c1 > 0) ) |
---|
1450 | { |
---|
1451 | c1++; |
---|
1452 | } |
---|
1453 | } |
---|
1454 | |
---|
1455 | if (c1 == 0) |
---|
1456 | { |
---|
1457 | baseCtxMod = m_cCUAbsSCModel.get( 0, 0 ) + (NUM_ABS_FLAG_CTX_PER_SET * uiCtxSet); |
---|
1458 | if ( firstC2FlagIdx != -1) |
---|
1459 | { |
---|
1460 | UInt symbol = absCoeff[ firstC2FlagIdx ] > 2; |
---|
1461 | m_pcBinIf->encodeBin( symbol, baseCtxMod[0] ); |
---|
1462 | if (symbol != 0) |
---|
1463 | { |
---|
1464 | escapeDataPresentInGroup = true; |
---|
1465 | } |
---|
1466 | } |
---|
1467 | } |
---|
1468 | |
---|
1469 | escapeDataPresentInGroup = escapeDataPresentInGroup || (numNonZero > C1FLAG_NUMBER); |
---|
1470 | |
---|
1471 | if (escapeDataPresentInGroup && alignCABACBeforeBypass) |
---|
1472 | { |
---|
1473 | m_pcBinIf->align(); |
---|
1474 | } |
---|
1475 | |
---|
1476 | if( beValid && signHidden ) |
---|
1477 | { |
---|
1478 | m_pcBinIf->encodeBinsEP( (coeffSigns >> 1), numNonZero-1 ); |
---|
1479 | } |
---|
1480 | else |
---|
1481 | { |
---|
1482 | m_pcBinIf->encodeBinsEP( coeffSigns, numNonZero ); |
---|
1483 | } |
---|
1484 | |
---|
1485 | Int iFirstCoeff2 = 1; |
---|
1486 | if (escapeDataPresentInGroup) |
---|
1487 | { |
---|
1488 | for ( Int idx = 0; idx < numNonZero; idx++ ) |
---|
1489 | { |
---|
1490 | UInt baseLevel = (idx < C1FLAG_NUMBER)? (2 + iFirstCoeff2 ) : 1; |
---|
1491 | |
---|
1492 | if( absCoeff[ idx ] >= baseLevel) |
---|
1493 | { |
---|
1494 | const UInt escapeCodeValue = absCoeff[idx] - baseLevel; |
---|
1495 | |
---|
1496 | xWriteCoefRemainExGolomb( escapeCodeValue, uiGoRiceParam, extendedPrecision, channelType ); |
---|
1497 | |
---|
1498 | if (absCoeff[idx] > (3 << uiGoRiceParam)) |
---|
1499 | { |
---|
1500 | uiGoRiceParam = bUseGolombRiceParameterAdaptation ? (uiGoRiceParam + 1) : (std::min<UInt>((uiGoRiceParam + 1), 4)); |
---|
1501 | } |
---|
1502 | |
---|
1503 | if (updateGolombRiceStatistics) |
---|
1504 | { |
---|
1505 | const UInt initialGolombRiceParameter = currentGolombRiceStatistic / RExt__GOLOMB_RICE_INCREMENT_DIVISOR; |
---|
1506 | |
---|
1507 | if (escapeCodeValue >= (3 << initialGolombRiceParameter)) |
---|
1508 | { |
---|
1509 | currentGolombRiceStatistic++; |
---|
1510 | } |
---|
1511 | else if (((escapeCodeValue * 2) < (1 << initialGolombRiceParameter)) && (currentGolombRiceStatistic > 0)) |
---|
1512 | { |
---|
1513 | currentGolombRiceStatistic--; |
---|
1514 | } |
---|
1515 | |
---|
1516 | updateGolombRiceStatistics = false; |
---|
1517 | } |
---|
1518 | } |
---|
1519 | |
---|
1520 | if(absCoeff[ idx ] >= 2) |
---|
1521 | { |
---|
1522 | iFirstCoeff2 = 0; |
---|
1523 | } |
---|
1524 | } |
---|
1525 | } |
---|
1526 | } |
---|
1527 | } |
---|
1528 | #if ENVIRONMENT_VARIABLE_DEBUG_AND_TEST |
---|
1529 | printSBACCoeffData(posLastX, posLastY, uiWidth, uiHeight, compID, uiAbsPartIdx, codingParameters.scanType, pcCoef, g_bFinalEncode); |
---|
1530 | #endif |
---|
1531 | |
---|
1532 | return; |
---|
1533 | } |
---|
1534 | |
---|
1535 | /** code SAO offset sign |
---|
1536 | * \param code sign value |
---|
1537 | */ |
---|
1538 | Void TEncSbac::codeSAOSign( UInt code ) |
---|
1539 | { |
---|
1540 | m_pcBinIf->encodeBinEP( code ); |
---|
1541 | } |
---|
1542 | |
---|
1543 | Void TEncSbac::codeSaoMaxUvlc ( UInt code, UInt maxSymbol ) |
---|
1544 | { |
---|
1545 | if (maxSymbol == 0) |
---|
1546 | { |
---|
1547 | return; |
---|
1548 | } |
---|
1549 | |
---|
1550 | Int i; |
---|
1551 | Bool bCodeLast = ( maxSymbol > code ); |
---|
1552 | |
---|
1553 | if ( code == 0 ) |
---|
1554 | { |
---|
1555 | m_pcBinIf->encodeBinEP( 0 ); |
---|
1556 | } |
---|
1557 | else |
---|
1558 | { |
---|
1559 | m_pcBinIf->encodeBinEP( 1 ); |
---|
1560 | for ( i=0; i<code-1; i++ ) |
---|
1561 | { |
---|
1562 | m_pcBinIf->encodeBinEP( 1 ); |
---|
1563 | } |
---|
1564 | if( bCodeLast ) |
---|
1565 | { |
---|
1566 | m_pcBinIf->encodeBinEP( 0 ); |
---|
1567 | } |
---|
1568 | } |
---|
1569 | } |
---|
1570 | |
---|
1571 | /** Code SAO EO class or BO band position |
---|
1572 | * \param uiLength |
---|
1573 | * \param uiCode |
---|
1574 | */ |
---|
1575 | Void TEncSbac::codeSaoUflc ( UInt uiLength, UInt uiCode ) |
---|
1576 | { |
---|
1577 | m_pcBinIf->encodeBinsEP ( uiCode, uiLength ); |
---|
1578 | } |
---|
1579 | |
---|
1580 | /** Code SAO merge flags |
---|
1581 | * \param uiCode |
---|
1582 | * \param uiCompIdx |
---|
1583 | */ |
---|
1584 | Void TEncSbac::codeSaoMerge ( UInt uiCode ) |
---|
1585 | { |
---|
1586 | m_pcBinIf->encodeBin(((uiCode == 0) ? 0 : 1), m_cSaoMergeSCModel.get( 0, 0, 0 )); |
---|
1587 | } |
---|
1588 | |
---|
1589 | /** Code SAO type index |
---|
1590 | * \param uiCode |
---|
1591 | */ |
---|
1592 | Void TEncSbac::codeSaoTypeIdx ( UInt uiCode) |
---|
1593 | { |
---|
1594 | if (uiCode == 0) |
---|
1595 | { |
---|
1596 | m_pcBinIf->encodeBin( 0, m_cSaoTypeIdxSCModel.get( 0, 0, 0 ) ); |
---|
1597 | } |
---|
1598 | else |
---|
1599 | { |
---|
1600 | m_pcBinIf->encodeBin( 1, m_cSaoTypeIdxSCModel.get( 0, 0, 0 ) ); |
---|
1601 | m_pcBinIf->encodeBinEP( uiCode == 1 ? 0 : 1 ); |
---|
1602 | } |
---|
1603 | } |
---|
1604 | #if SVC_EXTENSION |
---|
1605 | Void TEncSbac::codeSAOOffsetParam(ComponentID compIdx, SAOOffset& ctbParam, Bool sliceEnabled, UInt* saoMaxOffsetQVal) |
---|
1606 | #else |
---|
1607 | Void TEncSbac::codeSAOOffsetParam(ComponentID compIdx, SAOOffset& ctbParam, Bool sliceEnabled) |
---|
1608 | #endif |
---|
1609 | { |
---|
1610 | UInt uiSymbol; |
---|
1611 | if(!sliceEnabled) |
---|
1612 | { |
---|
1613 | assert(ctbParam.modeIdc == SAO_MODE_OFF); |
---|
1614 | return; |
---|
1615 | } |
---|
1616 | const Bool bIsFirstCompOfChType = (getFirstComponentOfChannel(toChannelType(compIdx)) == compIdx); |
---|
1617 | |
---|
1618 | //type |
---|
1619 | if(bIsFirstCompOfChType) |
---|
1620 | { |
---|
1621 | //sao_type_idx_luma or sao_type_idx_chroma |
---|
1622 | if(ctbParam.modeIdc == SAO_MODE_OFF) |
---|
1623 | { |
---|
1624 | uiSymbol =0; |
---|
1625 | } |
---|
1626 | else if(ctbParam.typeIdc == SAO_TYPE_BO) //BO |
---|
1627 | { |
---|
1628 | uiSymbol = 1; |
---|
1629 | } |
---|
1630 | else |
---|
1631 | { |
---|
1632 | assert(ctbParam.typeIdc < SAO_TYPE_START_BO); //EO |
---|
1633 | uiSymbol = 2; |
---|
1634 | } |
---|
1635 | codeSaoTypeIdx(uiSymbol); |
---|
1636 | } |
---|
1637 | |
---|
1638 | if(ctbParam.modeIdc == SAO_MODE_NEW) |
---|
1639 | { |
---|
1640 | Int numClasses = (ctbParam.typeIdc == SAO_TYPE_BO)?4:NUM_SAO_EO_CLASSES; |
---|
1641 | Int offset[4]; |
---|
1642 | Int k=0; |
---|
1643 | for(Int i=0; i< numClasses; i++) |
---|
1644 | { |
---|
1645 | if(ctbParam.typeIdc != SAO_TYPE_BO && i == SAO_CLASS_EO_PLAIN) |
---|
1646 | { |
---|
1647 | continue; |
---|
1648 | } |
---|
1649 | Int classIdx = (ctbParam.typeIdc == SAO_TYPE_BO)?( (ctbParam.typeAuxInfo+i)% NUM_SAO_BO_CLASSES ):i; |
---|
1650 | offset[k] = ctbParam.offset[classIdx]; |
---|
1651 | k++; |
---|
1652 | } |
---|
1653 | |
---|
1654 | for(Int i=0; i< 4; i++) |
---|
1655 | { |
---|
1656 | #if SVC_EXTENSION |
---|
1657 | codeSaoMaxUvlc((offset[i]<0)?(-offset[i]):(offset[i]), saoMaxOffsetQVal[compIdx] ); //sao_offset_abs |
---|
1658 | #else |
---|
1659 | codeSaoMaxUvlc((offset[i]<0)?(-offset[i]):(offset[i]), g_saoMaxOffsetQVal[compIdx] ); //sao_offset_abs |
---|
1660 | #endif |
---|
1661 | } |
---|
1662 | |
---|
1663 | |
---|
1664 | if(ctbParam.typeIdc == SAO_TYPE_BO) |
---|
1665 | { |
---|
1666 | for(Int i=0; i< 4; i++) |
---|
1667 | { |
---|
1668 | if(offset[i] != 0) |
---|
1669 | { |
---|
1670 | codeSAOSign((offset[i]< 0)?1:0); |
---|
1671 | } |
---|
1672 | } |
---|
1673 | |
---|
1674 | codeSaoUflc(NUM_SAO_BO_CLASSES_LOG2, ctbParam.typeAuxInfo ); //sao_band_position |
---|
1675 | } |
---|
1676 | else //EO |
---|
1677 | { |
---|
1678 | if(bIsFirstCompOfChType) |
---|
1679 | { |
---|
1680 | assert(ctbParam.typeIdc - SAO_TYPE_START_EO >=0); |
---|
1681 | codeSaoUflc(NUM_SAO_EO_TYPES_LOG2, ctbParam.typeIdc - SAO_TYPE_START_EO ); //sao_eo_class_luma or sao_eo_class_chroma |
---|
1682 | } |
---|
1683 | } |
---|
1684 | |
---|
1685 | } |
---|
1686 | } |
---|
1687 | |
---|
1688 | |
---|
1689 | Void TEncSbac::codeSAOBlkParam(SAOBlkParam& saoBlkParam |
---|
1690 | #if SVC_EXTENSION |
---|
1691 | , UInt* saoMaxOffsetQVal |
---|
1692 | #endif |
---|
1693 | , Bool* sliceEnabled |
---|
1694 | , Bool leftMergeAvail |
---|
1695 | , Bool aboveMergeAvail |
---|
1696 | , Bool onlyEstMergeInfo // = false |
---|
1697 | ) |
---|
1698 | { |
---|
1699 | |
---|
1700 | Bool isLeftMerge = false; |
---|
1701 | Bool isAboveMerge= false; |
---|
1702 | |
---|
1703 | if(leftMergeAvail) |
---|
1704 | { |
---|
1705 | isLeftMerge = ((saoBlkParam[COMPONENT_Y].modeIdc == SAO_MODE_MERGE) && (saoBlkParam[COMPONENT_Y].typeIdc == SAO_MERGE_LEFT)); |
---|
1706 | codeSaoMerge( isLeftMerge?1:0 ); //sao_merge_left_flag |
---|
1707 | } |
---|
1708 | |
---|
1709 | if( aboveMergeAvail && !isLeftMerge) |
---|
1710 | { |
---|
1711 | isAboveMerge = ((saoBlkParam[COMPONENT_Y].modeIdc == SAO_MODE_MERGE) && (saoBlkParam[COMPONENT_Y].typeIdc == SAO_MERGE_ABOVE)); |
---|
1712 | codeSaoMerge( isAboveMerge?1:0 ); //sao_merge_left_flag |
---|
1713 | } |
---|
1714 | |
---|
1715 | if(onlyEstMergeInfo) |
---|
1716 | { |
---|
1717 | return; //only for RDO |
---|
1718 | } |
---|
1719 | |
---|
1720 | if(!isLeftMerge && !isAboveMerge) //not merge mode |
---|
1721 | { |
---|
1722 | for(Int compIdx=0; compIdx < MAX_NUM_COMPONENT; compIdx++) |
---|
1723 | { |
---|
1724 | #if SVC_EXTENSION |
---|
1725 | codeSAOOffsetParam(ComponentID(compIdx), saoBlkParam[compIdx], sliceEnabled[compIdx], saoMaxOffsetQVal); |
---|
1726 | #else |
---|
1727 | codeSAOOffsetParam(ComponentID(compIdx), saoBlkParam[compIdx], sliceEnabled[compIdx]); |
---|
1728 | #endif |
---|
1729 | } |
---|
1730 | } |
---|
1731 | } |
---|
1732 | |
---|
1733 | /*! |
---|
1734 | **************************************************************************** |
---|
1735 | * \brief |
---|
1736 | * estimate bit cost for CBP, significant map and significant coefficients |
---|
1737 | **************************************************************************** |
---|
1738 | */ |
---|
1739 | Void TEncSbac::estBit( estBitsSbacStruct* pcEstBitsSbac, Int width, Int height, ChannelType chType ) |
---|
1740 | { |
---|
1741 | estCBFBit( pcEstBitsSbac ); |
---|
1742 | |
---|
1743 | estSignificantCoeffGroupMapBit( pcEstBitsSbac, chType ); |
---|
1744 | |
---|
1745 | // encode significance map |
---|
1746 | estSignificantMapBit( pcEstBitsSbac, width, height, chType ); |
---|
1747 | |
---|
1748 | // encode last significant position |
---|
1749 | estLastSignificantPositionBit( pcEstBitsSbac, width, height, chType ); |
---|
1750 | |
---|
1751 | // encode significant coefficients |
---|
1752 | estSignificantCoefficientsBit( pcEstBitsSbac, chType ); |
---|
1753 | |
---|
1754 | memcpy(pcEstBitsSbac->golombRiceAdaptationStatistics, m_golombRiceAdaptationStatistics, (sizeof(UInt) * RExt__GOLOMB_RICE_ADAPTATION_STATISTICS_SETS)); |
---|
1755 | } |
---|
1756 | |
---|
1757 | /*! |
---|
1758 | **************************************************************************** |
---|
1759 | * \brief |
---|
1760 | * estimate bit cost for each CBP bit |
---|
1761 | **************************************************************************** |
---|
1762 | */ |
---|
1763 | Void TEncSbac::estCBFBit( estBitsSbacStruct* pcEstBitsSbac ) |
---|
1764 | { |
---|
1765 | ContextModel *pCtx = m_cCUQtCbfSCModel.get( 0 ); |
---|
1766 | |
---|
1767 | for( UInt uiCtxInc = 0; uiCtxInc < (NUM_QT_CBF_CTX_SETS * NUM_QT_CBF_CTX_PER_SET); uiCtxInc++ ) |
---|
1768 | { |
---|
1769 | pcEstBitsSbac->blockCbpBits[ uiCtxInc ][ 0 ] = pCtx[ uiCtxInc ].getEntropyBits( 0 ); |
---|
1770 | pcEstBitsSbac->blockCbpBits[ uiCtxInc ][ 1 ] = pCtx[ uiCtxInc ].getEntropyBits( 1 ); |
---|
1771 | } |
---|
1772 | |
---|
1773 | pCtx = m_cCUQtRootCbfSCModel.get( 0 ); |
---|
1774 | |
---|
1775 | for( UInt uiCtxInc = 0; uiCtxInc < 4; uiCtxInc++ ) |
---|
1776 | { |
---|
1777 | pcEstBitsSbac->blockRootCbpBits[ uiCtxInc ][ 0 ] = pCtx[ uiCtxInc ].getEntropyBits( 0 ); |
---|
1778 | pcEstBitsSbac->blockRootCbpBits[ uiCtxInc ][ 1 ] = pCtx[ uiCtxInc ].getEntropyBits( 1 ); |
---|
1779 | } |
---|
1780 | } |
---|
1781 | |
---|
1782 | |
---|
1783 | /*! |
---|
1784 | **************************************************************************** |
---|
1785 | * \brief |
---|
1786 | * estimate SAMBAC bit cost for significant coefficient group map |
---|
1787 | **************************************************************************** |
---|
1788 | */ |
---|
1789 | Void TEncSbac::estSignificantCoeffGroupMapBit( estBitsSbacStruct* pcEstBitsSbac, ChannelType chType ) |
---|
1790 | { |
---|
1791 | Int firstCtx = 0, numCtx = NUM_SIG_CG_FLAG_CTX; |
---|
1792 | |
---|
1793 | for ( Int ctxIdx = firstCtx; ctxIdx < firstCtx + numCtx; ctxIdx++ ) |
---|
1794 | { |
---|
1795 | for( UInt uiBin = 0; uiBin < 2; uiBin++ ) |
---|
1796 | { |
---|
1797 | pcEstBitsSbac->significantCoeffGroupBits[ ctxIdx ][ uiBin ] = m_cCUSigCoeffGroupSCModel.get( 0, chType, ctxIdx ).getEntropyBits( uiBin ); |
---|
1798 | } |
---|
1799 | } |
---|
1800 | } |
---|
1801 | |
---|
1802 | |
---|
1803 | /*! |
---|
1804 | **************************************************************************** |
---|
1805 | * \brief |
---|
1806 | * estimate SAMBAC bit cost for significant coefficient map |
---|
1807 | **************************************************************************** |
---|
1808 | */ |
---|
1809 | Void TEncSbac::estSignificantMapBit( estBitsSbacStruct* pcEstBitsSbac, Int width, Int height, ChannelType chType ) |
---|
1810 | { |
---|
1811 | //-------------------------------------------------------------------------------------------------- |
---|
1812 | |
---|
1813 | //set up the number of channels and context variables |
---|
1814 | |
---|
1815 | const UInt firstComponent = ((isLuma(chType)) ? (COMPONENT_Y) : (COMPONENT_Cb)); |
---|
1816 | const UInt lastComponent = ((isLuma(chType)) ? (COMPONENT_Y) : (COMPONENT_Cb)); |
---|
1817 | |
---|
1818 | //---------------------------------------------------------- |
---|
1819 | |
---|
1820 | Int firstCtx = MAX_INT; |
---|
1821 | Int numCtx = MAX_INT; |
---|
1822 | |
---|
1823 | if ((width == 4) && (height == 4)) |
---|
1824 | { |
---|
1825 | firstCtx = significanceMapContextSetStart[chType][CONTEXT_TYPE_4x4]; |
---|
1826 | numCtx = significanceMapContextSetSize [chType][CONTEXT_TYPE_4x4]; |
---|
1827 | } |
---|
1828 | else if ((width == 8) && (height == 8)) |
---|
1829 | { |
---|
1830 | firstCtx = significanceMapContextSetStart[chType][CONTEXT_TYPE_8x8]; |
---|
1831 | numCtx = significanceMapContextSetSize [chType][CONTEXT_TYPE_8x8]; |
---|
1832 | } |
---|
1833 | else |
---|
1834 | { |
---|
1835 | firstCtx = significanceMapContextSetStart[chType][CONTEXT_TYPE_NxN]; |
---|
1836 | numCtx = significanceMapContextSetSize [chType][CONTEXT_TYPE_NxN]; |
---|
1837 | } |
---|
1838 | |
---|
1839 | //-------------------------------------------------------------------------------------------------- |
---|
1840 | |
---|
1841 | //fill the data for the significace map |
---|
1842 | |
---|
1843 | for (UInt component = firstComponent; component <= lastComponent; component++) |
---|
1844 | { |
---|
1845 | const UInt contextOffset = getSignificanceMapContextOffset(ComponentID(component)); |
---|
1846 | |
---|
1847 | if (firstCtx > 0) |
---|
1848 | { |
---|
1849 | for( UInt bin = 0; bin < 2; bin++ ) //always get the DC |
---|
1850 | { |
---|
1851 | pcEstBitsSbac->significantBits[ contextOffset ][ bin ] = m_cCUSigSCModel.get( 0, 0, contextOffset ).getEntropyBits( bin ); |
---|
1852 | } |
---|
1853 | } |
---|
1854 | |
---|
1855 | // This could be made optional, but would require this function to have knowledge of whether the |
---|
1856 | // TU is transform-skipped or transquant-bypassed and whether the SPS flag is set |
---|
1857 | for( UInt bin = 0; bin < 2; bin++ ) |
---|
1858 | { |
---|
1859 | const Int ctxIdx = significanceMapContextSetStart[chType][CONTEXT_TYPE_SINGLE]; |
---|
1860 | pcEstBitsSbac->significantBits[ contextOffset + ctxIdx ][ bin ] = m_cCUSigSCModel.get( 0, 0, (contextOffset + ctxIdx) ).getEntropyBits( bin ); |
---|
1861 | } |
---|
1862 | |
---|
1863 | for ( Int ctxIdx = firstCtx; ctxIdx < firstCtx + numCtx; ctxIdx++ ) |
---|
1864 | { |
---|
1865 | for( UInt uiBin = 0; uiBin < 2; uiBin++ ) |
---|
1866 | { |
---|
1867 | pcEstBitsSbac->significantBits[ contextOffset + ctxIdx ][ uiBin ] = m_cCUSigSCModel.get( 0, 0, (contextOffset + ctxIdx) ).getEntropyBits( uiBin ); |
---|
1868 | } |
---|
1869 | } |
---|
1870 | } |
---|
1871 | |
---|
1872 | //-------------------------------------------------------------------------------------------------- |
---|
1873 | } |
---|
1874 | |
---|
1875 | |
---|
1876 | /*! |
---|
1877 | **************************************************************************** |
---|
1878 | * \brief |
---|
1879 | * estimate bit cost of significant coefficient |
---|
1880 | **************************************************************************** |
---|
1881 | */ |
---|
1882 | |
---|
1883 | Void TEncSbac::estLastSignificantPositionBit( estBitsSbacStruct* pcEstBitsSbac, Int width, Int height, ChannelType chType ) |
---|
1884 | { |
---|
1885 | //--------------------------------------------------------------------------------------------------. |
---|
1886 | |
---|
1887 | //set up the number of channels |
---|
1888 | |
---|
1889 | const UInt firstComponent = ((isLuma(chType)) ? (COMPONENT_Y) : (COMPONENT_Cb)); |
---|
1890 | const UInt lastComponent = ((isLuma(chType)) ? (COMPONENT_Y) : (COMPONENT_Cb)); |
---|
1891 | |
---|
1892 | //-------------------------------------------------------------------------------------------------- |
---|
1893 | |
---|
1894 | //fill the data for the last-significant-coefficient position |
---|
1895 | |
---|
1896 | for (UInt componentIndex = firstComponent; componentIndex <= lastComponent; componentIndex++) |
---|
1897 | { |
---|
1898 | const ComponentID component = ComponentID(componentIndex); |
---|
1899 | |
---|
1900 | Int iBitsX = 0, iBitsY = 0; |
---|
1901 | |
---|
1902 | Int blkSizeOffsetX, blkSizeOffsetY, shiftX, shiftY; |
---|
1903 | getLastSignificantContextParameters(ComponentID(component), width, height, blkSizeOffsetX, blkSizeOffsetY, shiftX, shiftY); |
---|
1904 | |
---|
1905 | Int ctx; |
---|
1906 | |
---|
1907 | const ChannelType channelType = toChannelType(ComponentID(component)); |
---|
1908 | |
---|
1909 | ContextModel *const pCtxX = m_cCuCtxLastX.get( 0, channelType ); |
---|
1910 | ContextModel *const pCtxY = m_cCuCtxLastY.get( 0, channelType ); |
---|
1911 | Int *const lastXBitsArray = pcEstBitsSbac->lastXBits[channelType]; |
---|
1912 | Int *const lastYBitsArray = pcEstBitsSbac->lastYBits[channelType]; |
---|
1913 | |
---|
1914 | //------------------------------------------------ |
---|
1915 | |
---|
1916 | //X-coordinate |
---|
1917 | |
---|
1918 | for (ctx = 0; ctx < g_uiGroupIdx[ width - 1 ]; ctx++) |
---|
1919 | { |
---|
1920 | Int ctxOffset = blkSizeOffsetX + (ctx >>shiftX); |
---|
1921 | lastXBitsArray[ ctx ] = iBitsX + pCtxX[ ctxOffset ].getEntropyBits( 0 ); |
---|
1922 | iBitsX += pCtxX[ ctxOffset ].getEntropyBits( 1 ); |
---|
1923 | } |
---|
1924 | |
---|
1925 | lastXBitsArray[ctx] = iBitsX; |
---|
1926 | |
---|
1927 | //------------------------------------------------ |
---|
1928 | |
---|
1929 | //Y-coordinate |
---|
1930 | |
---|
1931 | for (ctx = 0; ctx < g_uiGroupIdx[ height - 1 ]; ctx++) |
---|
1932 | { |
---|
1933 | Int ctxOffset = blkSizeOffsetY + (ctx >>shiftY); |
---|
1934 | lastYBitsArray[ ctx ] = iBitsY + pCtxY[ ctxOffset ].getEntropyBits( 0 ); |
---|
1935 | iBitsY += pCtxY[ ctxOffset ].getEntropyBits( 1 ); |
---|
1936 | } |
---|
1937 | |
---|
1938 | lastYBitsArray[ctx] = iBitsY; |
---|
1939 | |
---|
1940 | } //end of component loop |
---|
1941 | |
---|
1942 | //-------------------------------------------------------------------------------------------------- |
---|
1943 | } |
---|
1944 | |
---|
1945 | |
---|
1946 | /*! |
---|
1947 | **************************************************************************** |
---|
1948 | * \brief |
---|
1949 | * estimate bit cost of significant coefficient |
---|
1950 | **************************************************************************** |
---|
1951 | */ |
---|
1952 | Void TEncSbac::estSignificantCoefficientsBit( estBitsSbacStruct* pcEstBitsSbac, ChannelType chType ) |
---|
1953 | { |
---|
1954 | ContextModel *ctxOne = m_cCUOneSCModel.get(0, 0); |
---|
1955 | ContextModel *ctxAbs = m_cCUAbsSCModel.get(0, 0); |
---|
1956 | |
---|
1957 | const UInt oneStartIndex = ((isLuma(chType)) ? (0) : (NUM_ONE_FLAG_CTX_LUMA)); |
---|
1958 | const UInt oneStopIndex = ((isLuma(chType)) ? (NUM_ONE_FLAG_CTX_LUMA) : (NUM_ONE_FLAG_CTX)); |
---|
1959 | const UInt absStartIndex = ((isLuma(chType)) ? (0) : (NUM_ABS_FLAG_CTX_LUMA)); |
---|
1960 | const UInt absStopIndex = ((isLuma(chType)) ? (NUM_ABS_FLAG_CTX_LUMA) : (NUM_ABS_FLAG_CTX)); |
---|
1961 | |
---|
1962 | for (Int ctxIdx = oneStartIndex; ctxIdx < oneStopIndex; ctxIdx++) |
---|
1963 | { |
---|
1964 | pcEstBitsSbac->m_greaterOneBits[ ctxIdx ][ 0 ] = ctxOne[ ctxIdx ].getEntropyBits( 0 ); |
---|
1965 | pcEstBitsSbac->m_greaterOneBits[ ctxIdx ][ 1 ] = ctxOne[ ctxIdx ].getEntropyBits( 1 ); |
---|
1966 | } |
---|
1967 | |
---|
1968 | for (Int ctxIdx = absStartIndex; ctxIdx < absStopIndex; ctxIdx++) |
---|
1969 | { |
---|
1970 | pcEstBitsSbac->m_levelAbsBits[ ctxIdx ][ 0 ] = ctxAbs[ ctxIdx ].getEntropyBits( 0 ); |
---|
1971 | pcEstBitsSbac->m_levelAbsBits[ ctxIdx ][ 1 ] = ctxAbs[ ctxIdx ].getEntropyBits( 1 ); |
---|
1972 | } |
---|
1973 | } |
---|
1974 | |
---|
1975 | /** |
---|
1976 | - Initialize our context information from the nominated source. |
---|
1977 | . |
---|
1978 | \param pSrc From where to copy context information. |
---|
1979 | */ |
---|
1980 | Void TEncSbac::xCopyContextsFrom( const TEncSbac* pSrc ) |
---|
1981 | { |
---|
1982 | memcpy(m_contextModels, pSrc->m_contextModels, m_numContextModels*sizeof(m_contextModels[0])); |
---|
1983 | memcpy(m_golombRiceAdaptationStatistics, pSrc->m_golombRiceAdaptationStatistics, (sizeof(UInt) * RExt__GOLOMB_RICE_ADAPTATION_STATISTICS_SETS)); |
---|
1984 | } |
---|
1985 | |
---|
1986 | Void TEncSbac::loadContexts ( const TEncSbac* pSrc) |
---|
1987 | { |
---|
1988 | xCopyContextsFrom(pSrc); |
---|
1989 | } |
---|
1990 | |
---|
1991 | /** Performs CABAC encoding of the explicit RDPCM mode |
---|
1992 | * \param rTu current TU data structure |
---|
1993 | * \param compID component identifier |
---|
1994 | */ |
---|
1995 | Void TEncSbac::codeExplicitRdpcmMode( TComTU &rTu, const ComponentID compID ) |
---|
1996 | { |
---|
1997 | TComDataCU *cu = rTu.getCU(); |
---|
1998 | const TComRectangle &rect = rTu.getRect(compID); |
---|
1999 | const UInt absPartIdx = rTu.GetAbsPartIdxTU(compID); |
---|
2000 | const UInt tuHeight = g_aucConvertToBit[rect.height]; |
---|
2001 | const UInt tuWidth = g_aucConvertToBit[rect.width]; |
---|
2002 | |
---|
2003 | assert(tuHeight == tuWidth); |
---|
2004 | assert(tuHeight < 4); |
---|
2005 | |
---|
2006 | UInt explicitRdpcmMode = cu->getExplicitRdpcmMode(compID, absPartIdx); |
---|
2007 | |
---|
2008 | if( explicitRdpcmMode == RDPCM_OFF ) |
---|
2009 | { |
---|
2010 | m_pcBinIf->encodeBin (0, m_explicitRdpcmFlagSCModel.get (0, toChannelType(compID), 0)); |
---|
2011 | } |
---|
2012 | else if( explicitRdpcmMode == RDPCM_HOR || explicitRdpcmMode == RDPCM_VER ) |
---|
2013 | { |
---|
2014 | m_pcBinIf->encodeBin (1, m_explicitRdpcmFlagSCModel.get (0, toChannelType(compID), 0)); |
---|
2015 | if(explicitRdpcmMode == RDPCM_HOR) |
---|
2016 | { |
---|
2017 | m_pcBinIf->encodeBin ( 0, m_explicitRdpcmDirSCModel.get(0, toChannelType(compID), 0)); |
---|
2018 | } |
---|
2019 | else |
---|
2020 | { |
---|
2021 | m_pcBinIf->encodeBin ( 1, m_explicitRdpcmDirSCModel.get(0, toChannelType(compID), 0)); |
---|
2022 | } |
---|
2023 | } |
---|
2024 | else |
---|
2025 | { |
---|
2026 | assert(0); |
---|
2027 | } |
---|
2028 | } |
---|
2029 | |
---|
2030 | #if SVC_EXTENSION |
---|
2031 | Void TEncSbac::codeSliceHeaderExtn( TComSlice* pSlice, Int shBitsWrittenTillNow ) |
---|
2032 | { |
---|
2033 | assert (0); |
---|
2034 | return; |
---|
2035 | } |
---|
2036 | #endif |
---|
2037 | |
---|
2038 | //! \} |
---|