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 | SliceType encCABACTableIdx = m_pcSlice->getEncCABACTableIdx(); |
---|
112 | if (!m_pcSlice->isIntra() && (encCABACTableIdx==B_SLICE || encCABACTableIdx==P_SLICE) && m_pcSlice->getPPS()->getCabacInitPresentFlag()) |
---|
113 | { |
---|
114 | eSliceType = 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 | SliceType 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 | return bestSliceType; |
---|
217 | } |
---|
218 | else |
---|
219 | { |
---|
220 | return I_SLICE; |
---|
221 | } |
---|
222 | } |
---|
223 | |
---|
224 | Void TEncSbac::codeVPS( const TComVPS* pcVPS ) |
---|
225 | { |
---|
226 | assert (0); |
---|
227 | return; |
---|
228 | } |
---|
229 | |
---|
230 | Void TEncSbac::codeSPS( const TComSPS* pcSPS ) |
---|
231 | { |
---|
232 | assert (0); |
---|
233 | return; |
---|
234 | } |
---|
235 | |
---|
236 | #if CGS_3D_ASYMLUT |
---|
237 | Void TEncSbac::codePPS( const TComPPS* pcPPS, TEnc3DAsymLUT * pc3DAsymLUT ) |
---|
238 | #else |
---|
239 | Void TEncSbac::codePPS( const TComPPS* pcPPS ) |
---|
240 | #endif |
---|
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 | { |
---|
410 | this->m_cCUIntraPredSCModel .copyFrom( &pSrc->m_cCUIntraPredSCModel ); |
---|
411 | } |
---|
412 | else |
---|
413 | { |
---|
414 | this->m_cCUChromaPredSCModel .copyFrom( &pSrc->m_cCUChromaPredSCModel ); |
---|
415 | } |
---|
416 | } |
---|
417 | |
---|
418 | |
---|
419 | Void TEncSbac::store( TEncSbac* pDest) const |
---|
420 | { |
---|
421 | pDest->xCopyFrom( this ); |
---|
422 | } |
---|
423 | |
---|
424 | |
---|
425 | Void TEncSbac::xCopyFrom( const TEncSbac* pSrc ) |
---|
426 | { |
---|
427 | m_pcBinIf->copyState( pSrc->m_pcBinIf ); |
---|
428 | xCopyContextsFrom(pSrc); |
---|
429 | } |
---|
430 | |
---|
431 | Void TEncSbac::codeMVPIdx ( TComDataCU* pcCU, UInt uiAbsPartIdx, RefPicList eRefList ) |
---|
432 | { |
---|
433 | Int iSymbol = pcCU->getMVPIdx(eRefList, uiAbsPartIdx); |
---|
434 | Int iNum = AMVP_MAX_NUM_CANDS; |
---|
435 | |
---|
436 | xWriteUnaryMaxSymbol(iSymbol, m_cMVPIdxSCModel.get(0), 1, iNum-1); |
---|
437 | } |
---|
438 | |
---|
439 | Void TEncSbac::codePartSize( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth ) |
---|
440 | { |
---|
441 | PartSize eSize = pcCU->getPartitionSize( uiAbsPartIdx ); |
---|
442 | |
---|
443 | if ( pcCU->isIntra( uiAbsPartIdx ) ) |
---|
444 | { |
---|
445 | if( uiDepth == g_uiMaxCUDepth - g_uiAddCUDepth ) |
---|
446 | { |
---|
447 | m_pcBinIf->encodeBin( eSize == SIZE_2Nx2N? 1 : 0, m_cCUPartSizeSCModel.get( 0, 0, 0 ) ); |
---|
448 | } |
---|
449 | return; |
---|
450 | } |
---|
451 | |
---|
452 | switch(eSize) |
---|
453 | { |
---|
454 | case SIZE_2Nx2N: |
---|
455 | { |
---|
456 | m_pcBinIf->encodeBin( 1, m_cCUPartSizeSCModel.get( 0, 0, 0) ); |
---|
457 | break; |
---|
458 | } |
---|
459 | case SIZE_2NxN: |
---|
460 | case SIZE_2NxnU: |
---|
461 | case SIZE_2NxnD: |
---|
462 | { |
---|
463 | m_pcBinIf->encodeBin( 0, m_cCUPartSizeSCModel.get( 0, 0, 0) ); |
---|
464 | m_pcBinIf->encodeBin( 1, m_cCUPartSizeSCModel.get( 0, 0, 1) ); |
---|
465 | if ( pcCU->getSlice()->getSPS()->getUseAMP() && uiDepth < g_uiMaxCUDepth-g_uiAddCUDepth ) |
---|
466 | { |
---|
467 | if (eSize == SIZE_2NxN) |
---|
468 | { |
---|
469 | m_pcBinIf->encodeBin(1, m_cCUPartSizeSCModel.get( 0, 0, 3 )); |
---|
470 | } |
---|
471 | else |
---|
472 | { |
---|
473 | m_pcBinIf->encodeBin(0, m_cCUPartSizeSCModel.get( 0, 0, 3 )); |
---|
474 | m_pcBinIf->encodeBinEP((eSize == SIZE_2NxnU? 0: 1)); |
---|
475 | } |
---|
476 | } |
---|
477 | break; |
---|
478 | } |
---|
479 | case SIZE_Nx2N: |
---|
480 | case SIZE_nLx2N: |
---|
481 | case SIZE_nRx2N: |
---|
482 | { |
---|
483 | m_pcBinIf->encodeBin( 0, m_cCUPartSizeSCModel.get( 0, 0, 0) ); |
---|
484 | m_pcBinIf->encodeBin( 0, m_cCUPartSizeSCModel.get( 0, 0, 1) ); |
---|
485 | |
---|
486 | if( uiDepth == g_uiMaxCUDepth - g_uiAddCUDepth && !( pcCU->getWidth(uiAbsPartIdx) == 8 && pcCU->getHeight(uiAbsPartIdx) == 8 ) ) |
---|
487 | { |
---|
488 | m_pcBinIf->encodeBin( 1, m_cCUPartSizeSCModel.get( 0, 0, 2) ); |
---|
489 | } |
---|
490 | |
---|
491 | if ( pcCU->getSlice()->getSPS()->getUseAMP() && uiDepth < g_uiMaxCUDepth-g_uiAddCUDepth ) |
---|
492 | { |
---|
493 | if (eSize == SIZE_Nx2N) |
---|
494 | { |
---|
495 | m_pcBinIf->encodeBin(1, m_cCUPartSizeSCModel.get( 0, 0, 3 )); |
---|
496 | } |
---|
497 | else |
---|
498 | { |
---|
499 | m_pcBinIf->encodeBin(0, m_cCUPartSizeSCModel.get( 0, 0, 3 )); |
---|
500 | m_pcBinIf->encodeBinEP((eSize == SIZE_nLx2N? 0: 1)); |
---|
501 | } |
---|
502 | } |
---|
503 | break; |
---|
504 | } |
---|
505 | case SIZE_NxN: |
---|
506 | { |
---|
507 | if( uiDepth == g_uiMaxCUDepth - g_uiAddCUDepth && !( pcCU->getWidth(uiAbsPartIdx) == 8 && pcCU->getHeight(uiAbsPartIdx) == 8 ) ) |
---|
508 | { |
---|
509 | m_pcBinIf->encodeBin( 0, m_cCUPartSizeSCModel.get( 0, 0, 0) ); |
---|
510 | m_pcBinIf->encodeBin( 0, m_cCUPartSizeSCModel.get( 0, 0, 1) ); |
---|
511 | m_pcBinIf->encodeBin( 0, m_cCUPartSizeSCModel.get( 0, 0, 2) ); |
---|
512 | } |
---|
513 | break; |
---|
514 | } |
---|
515 | default: |
---|
516 | { |
---|
517 | assert(0); |
---|
518 | break; |
---|
519 | } |
---|
520 | } |
---|
521 | } |
---|
522 | |
---|
523 | |
---|
524 | /** code prediction mode |
---|
525 | * \param pcCU |
---|
526 | * \param uiAbsPartIdx |
---|
527 | * \returns Void |
---|
528 | */ |
---|
529 | Void TEncSbac::codePredMode( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
530 | { |
---|
531 | // get context function is here |
---|
532 | m_pcBinIf->encodeBin( pcCU->isIntra( uiAbsPartIdx ) ? 1 : 0, m_cCUPredModeSCModel.get( 0, 0, 0 ) ); |
---|
533 | } |
---|
534 | |
---|
535 | Void TEncSbac::codeCUTransquantBypassFlag( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
536 | { |
---|
537 | UInt uiSymbol = pcCU->getCUTransquantBypass(uiAbsPartIdx); |
---|
538 | m_pcBinIf->encodeBin( uiSymbol, m_CUTransquantBypassFlagSCModel.get( 0, 0, 0 ) ); |
---|
539 | } |
---|
540 | |
---|
541 | /** code skip flag |
---|
542 | * \param pcCU |
---|
543 | * \param uiAbsPartIdx |
---|
544 | * \returns Void |
---|
545 | */ |
---|
546 | Void TEncSbac::codeSkipFlag( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
547 | { |
---|
548 | // get context function is here |
---|
549 | UInt uiSymbol = pcCU->isSkipped( uiAbsPartIdx ) ? 1 : 0; |
---|
550 | UInt uiCtxSkip = pcCU->getCtxSkipFlag( uiAbsPartIdx ) ; |
---|
551 | m_pcBinIf->encodeBin( uiSymbol, m_cCUSkipFlagSCModel.get( 0, 0, uiCtxSkip ) ); |
---|
552 | DTRACE_CABAC_VL( g_nSymbolCounter++ ); |
---|
553 | DTRACE_CABAC_T( "\tSkipFlag" ); |
---|
554 | DTRACE_CABAC_T( "\tuiCtxSkip: "); |
---|
555 | DTRACE_CABAC_V( uiCtxSkip ); |
---|
556 | DTRACE_CABAC_T( "\tuiSymbol: "); |
---|
557 | DTRACE_CABAC_V( uiSymbol ); |
---|
558 | DTRACE_CABAC_T( "\n"); |
---|
559 | } |
---|
560 | |
---|
561 | /** code merge flag |
---|
562 | * \param pcCU |
---|
563 | * \param uiAbsPartIdx |
---|
564 | * \returns Void |
---|
565 | */ |
---|
566 | Void TEncSbac::codeMergeFlag( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
567 | { |
---|
568 | const UInt uiSymbol = pcCU->getMergeFlag( uiAbsPartIdx ) ? 1 : 0; |
---|
569 | m_pcBinIf->encodeBin( uiSymbol, *m_cCUMergeFlagExtSCModel.get( 0 ) ); |
---|
570 | |
---|
571 | DTRACE_CABAC_VL( g_nSymbolCounter++ ); |
---|
572 | DTRACE_CABAC_T( "\tMergeFlag: " ); |
---|
573 | DTRACE_CABAC_V( uiSymbol ); |
---|
574 | DTRACE_CABAC_T( "\tAddress: " ); |
---|
575 | DTRACE_CABAC_V( pcCU->getCtuRsAddr() ); |
---|
576 | DTRACE_CABAC_T( "\tuiAbsPartIdx: " ); |
---|
577 | DTRACE_CABAC_V( uiAbsPartIdx ); |
---|
578 | DTRACE_CABAC_T( "\n" ); |
---|
579 | } |
---|
580 | |
---|
581 | /** code merge index |
---|
582 | * \param pcCU |
---|
583 | * \param uiAbsPartIdx |
---|
584 | * \returns Void |
---|
585 | */ |
---|
586 | Void TEncSbac::codeMergeIndex( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
587 | { |
---|
588 | UInt uiUnaryIdx = pcCU->getMergeIndex( uiAbsPartIdx ); |
---|
589 | UInt uiNumCand = pcCU->getSlice()->getMaxNumMergeCand(); |
---|
590 | if ( uiNumCand > 1 ) |
---|
591 | { |
---|
592 | for( UInt ui = 0; ui < uiNumCand - 1; ++ui ) |
---|
593 | { |
---|
594 | const UInt uiSymbol = ui == uiUnaryIdx ? 0 : 1; |
---|
595 | if ( ui==0 ) |
---|
596 | { |
---|
597 | m_pcBinIf->encodeBin( uiSymbol, m_cCUMergeIdxExtSCModel.get( 0, 0, 0 ) ); |
---|
598 | } |
---|
599 | else |
---|
600 | { |
---|
601 | m_pcBinIf->encodeBinEP( uiSymbol ); |
---|
602 | } |
---|
603 | if( uiSymbol == 0 ) |
---|
604 | { |
---|
605 | break; |
---|
606 | } |
---|
607 | } |
---|
608 | } |
---|
609 | DTRACE_CABAC_VL( g_nSymbolCounter++ ); |
---|
610 | DTRACE_CABAC_T( "\tparseMergeIndex()" ); |
---|
611 | DTRACE_CABAC_T( "\tuiMRGIdx= " ); |
---|
612 | DTRACE_CABAC_V( pcCU->getMergeIndex( uiAbsPartIdx ) ); |
---|
613 | DTRACE_CABAC_T( "\n" ); |
---|
614 | } |
---|
615 | |
---|
616 | Void TEncSbac::codeSplitFlag ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth ) |
---|
617 | { |
---|
618 | if( uiDepth == g_uiMaxCUDepth - g_uiAddCUDepth ) |
---|
619 | { |
---|
620 | return; |
---|
621 | } |
---|
622 | |
---|
623 | UInt uiCtx = pcCU->getCtxSplitFlag( uiAbsPartIdx, uiDepth ); |
---|
624 | UInt uiCurrSplitFlag = ( pcCU->getDepth( uiAbsPartIdx ) > uiDepth ) ? 1 : 0; |
---|
625 | |
---|
626 | assert( uiCtx < 3 ); |
---|
627 | m_pcBinIf->encodeBin( uiCurrSplitFlag, m_cCUSplitFlagSCModel.get( 0, 0, uiCtx ) ); |
---|
628 | DTRACE_CABAC_VL( g_nSymbolCounter++ ) |
---|
629 | DTRACE_CABAC_T( "\tSplitFlag\n" ) |
---|
630 | return; |
---|
631 | } |
---|
632 | |
---|
633 | Void TEncSbac::codeTransformSubdivFlag( UInt uiSymbol, UInt uiCtx ) |
---|
634 | { |
---|
635 | m_pcBinIf->encodeBin( uiSymbol, m_cCUTransSubdivFlagSCModel.get( 0, 0, uiCtx ) ); |
---|
636 | DTRACE_CABAC_VL( g_nSymbolCounter++ ) |
---|
637 | DTRACE_CABAC_T( "\tparseTransformSubdivFlag()" ) |
---|
638 | DTRACE_CABAC_T( "\tsymbol=" ) |
---|
639 | DTRACE_CABAC_V( uiSymbol ) |
---|
640 | DTRACE_CABAC_T( "\tctx=" ) |
---|
641 | DTRACE_CABAC_V( uiCtx ) |
---|
642 | DTRACE_CABAC_T( "\n" ) |
---|
643 | } |
---|
644 | |
---|
645 | |
---|
646 | Void TEncSbac::codeIntraDirLumaAng( TComDataCU* pcCU, UInt absPartIdx, Bool isMultiple) |
---|
647 | { |
---|
648 | UInt dir[4],j; |
---|
649 | Int preds[4][NUM_MOST_PROBABLE_MODES] = {{-1, -1, -1},{-1, -1, -1},{-1, -1, -1},{-1, -1, -1}}; |
---|
650 | Int predIdx[4] ={ -1,-1,-1,-1}; |
---|
651 | PartSize mode = pcCU->getPartitionSize( absPartIdx ); |
---|
652 | UInt partNum = isMultiple?(mode==SIZE_NxN?4:1):1; |
---|
653 | UInt partOffset = ( pcCU->getPic()->getNumPartitionsInCtu() >> ( pcCU->getDepth(absPartIdx) << 1 ) ) >> 2; |
---|
654 | for (j=0;j<partNum;j++) |
---|
655 | { |
---|
656 | dir[j] = pcCU->getIntraDir( CHANNEL_TYPE_LUMA, absPartIdx+partOffset*j ); |
---|
657 | pcCU->getIntraDirPredictor(absPartIdx+partOffset*j, preds[j], COMPONENT_Y); |
---|
658 | for(UInt i = 0; i < NUM_MOST_PROBABLE_MODES; i++) |
---|
659 | { |
---|
660 | if(dir[j] == preds[j][i]) |
---|
661 | { |
---|
662 | predIdx[j] = i; |
---|
663 | } |
---|
664 | } |
---|
665 | m_pcBinIf->encodeBin((predIdx[j] != -1)? 1 : 0, m_cCUIntraPredSCModel.get( 0, 0, 0 ) ); |
---|
666 | } |
---|
667 | for (j=0;j<partNum;j++) |
---|
668 | { |
---|
669 | if(predIdx[j] != -1) |
---|
670 | { |
---|
671 | m_pcBinIf->encodeBinEP( predIdx[j] ? 1 : 0 ); |
---|
672 | if (predIdx[j]) |
---|
673 | { |
---|
674 | m_pcBinIf->encodeBinEP( predIdx[j]-1 ); |
---|
675 | } |
---|
676 | } |
---|
677 | else |
---|
678 | { |
---|
679 | if (preds[j][0] > preds[j][1]) |
---|
680 | { |
---|
681 | std::swap(preds[j][0], preds[j][1]); |
---|
682 | } |
---|
683 | if (preds[j][0] > preds[j][2]) |
---|
684 | { |
---|
685 | std::swap(preds[j][0], preds[j][2]); |
---|
686 | } |
---|
687 | if (preds[j][1] > preds[j][2]) |
---|
688 | { |
---|
689 | std::swap(preds[j][1], preds[j][2]); |
---|
690 | } |
---|
691 | for(Int i = (Int(NUM_MOST_PROBABLE_MODES) - 1); i >= 0; i--) |
---|
692 | { |
---|
693 | dir[j] = dir[j] > preds[j][i] ? dir[j] - 1 : dir[j]; |
---|
694 | } |
---|
695 | m_pcBinIf->encodeBinsEP( dir[j], 5 ); |
---|
696 | } |
---|
697 | } |
---|
698 | return; |
---|
699 | } |
---|
700 | |
---|
701 | Void TEncSbac::codeIntraDirChroma( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
702 | { |
---|
703 | UInt uiIntraDirChroma = pcCU->getIntraDir( CHANNEL_TYPE_CHROMA, uiAbsPartIdx ); |
---|
704 | |
---|
705 | if( uiIntraDirChroma == DM_CHROMA_IDX ) |
---|
706 | { |
---|
707 | m_pcBinIf->encodeBin( 0, m_cCUChromaPredSCModel.get( 0, 0, 0 ) ); |
---|
708 | } |
---|
709 | else |
---|
710 | { |
---|
711 | m_pcBinIf->encodeBin( 1, m_cCUChromaPredSCModel.get( 0, 0, 0 ) ); |
---|
712 | |
---|
713 | UInt uiAllowedChromaDir[ NUM_CHROMA_MODE ]; |
---|
714 | pcCU->getAllowedChromaDir( uiAbsPartIdx, uiAllowedChromaDir ); |
---|
715 | |
---|
716 | for( Int i = 0; i < NUM_CHROMA_MODE - 1; i++ ) |
---|
717 | { |
---|
718 | if( uiIntraDirChroma == uiAllowedChromaDir[i] ) |
---|
719 | { |
---|
720 | uiIntraDirChroma = i; |
---|
721 | break; |
---|
722 | } |
---|
723 | } |
---|
724 | |
---|
725 | m_pcBinIf->encodeBinsEP( uiIntraDirChroma, 2 ); |
---|
726 | } |
---|
727 | |
---|
728 | return; |
---|
729 | } |
---|
730 | |
---|
731 | |
---|
732 | Void TEncSbac::codeInterDir( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
733 | { |
---|
734 | const UInt uiInterDir = pcCU->getInterDir( uiAbsPartIdx ) - 1; |
---|
735 | const UInt uiCtx = pcCU->getCtxInterDir( uiAbsPartIdx ); |
---|
736 | ContextModel *pCtx = m_cCUInterDirSCModel.get( 0 ); |
---|
737 | |
---|
738 | if (pcCU->getPartitionSize(uiAbsPartIdx) == SIZE_2Nx2N || pcCU->getHeight(uiAbsPartIdx) != 8 ) |
---|
739 | { |
---|
740 | m_pcBinIf->encodeBin( uiInterDir == 2 ? 1 : 0, *( pCtx + uiCtx ) ); |
---|
741 | } |
---|
742 | |
---|
743 | if (uiInterDir < 2) |
---|
744 | { |
---|
745 | m_pcBinIf->encodeBin( uiInterDir, *( pCtx + 4 ) ); |
---|
746 | } |
---|
747 | |
---|
748 | return; |
---|
749 | } |
---|
750 | |
---|
751 | Void TEncSbac::codeRefFrmIdx( TComDataCU* pcCU, UInt uiAbsPartIdx, RefPicList eRefList ) |
---|
752 | { |
---|
753 | Int iRefFrame = pcCU->getCUMvField( eRefList )->getRefIdx( uiAbsPartIdx ); |
---|
754 | ContextModel *pCtx = m_cCURefPicSCModel.get( 0 ); |
---|
755 | m_pcBinIf->encodeBin( ( iRefFrame == 0 ? 0 : 1 ), *pCtx ); |
---|
756 | |
---|
757 | if( iRefFrame > 0 ) |
---|
758 | { |
---|
759 | UInt uiRefNum = pcCU->getSlice()->getNumRefIdx( eRefList ) - 2; |
---|
760 | pCtx++; |
---|
761 | iRefFrame--; |
---|
762 | for( UInt ui = 0; ui < uiRefNum; ++ui ) |
---|
763 | { |
---|
764 | const UInt uiSymbol = ui == iRefFrame ? 0 : 1; |
---|
765 | if( ui == 0 ) |
---|
766 | { |
---|
767 | m_pcBinIf->encodeBin( uiSymbol, *pCtx ); |
---|
768 | } |
---|
769 | else |
---|
770 | { |
---|
771 | m_pcBinIf->encodeBinEP( uiSymbol ); |
---|
772 | } |
---|
773 | if( uiSymbol == 0 ) |
---|
774 | { |
---|
775 | break; |
---|
776 | } |
---|
777 | } |
---|
778 | } |
---|
779 | return; |
---|
780 | } |
---|
781 | |
---|
782 | Void TEncSbac::codeMvd( TComDataCU* pcCU, UInt uiAbsPartIdx, RefPicList eRefList ) |
---|
783 | { |
---|
784 | if(pcCU->getSlice()->getMvdL1ZeroFlag() && eRefList == REF_PIC_LIST_1 && pcCU->getInterDir(uiAbsPartIdx)==3) |
---|
785 | { |
---|
786 | return; |
---|
787 | } |
---|
788 | |
---|
789 | const TComCUMvField* pcCUMvField = pcCU->getCUMvField( eRefList ); |
---|
790 | const Int iHor = pcCUMvField->getMvd( uiAbsPartIdx ).getHor(); |
---|
791 | const Int iVer = pcCUMvField->getMvd( uiAbsPartIdx ).getVer(); |
---|
792 | ContextModel* pCtx = m_cCUMvdSCModel.get( 0 ); |
---|
793 | |
---|
794 | m_pcBinIf->encodeBin( iHor != 0 ? 1 : 0, *pCtx ); |
---|
795 | m_pcBinIf->encodeBin( iVer != 0 ? 1 : 0, *pCtx ); |
---|
796 | |
---|
797 | const Bool bHorAbsGr0 = iHor != 0; |
---|
798 | const Bool bVerAbsGr0 = iVer != 0; |
---|
799 | const UInt uiHorAbs = 0 > iHor ? -iHor : iHor; |
---|
800 | const UInt uiVerAbs = 0 > iVer ? -iVer : iVer; |
---|
801 | pCtx++; |
---|
802 | |
---|
803 | if( bHorAbsGr0 ) |
---|
804 | { |
---|
805 | m_pcBinIf->encodeBin( uiHorAbs > 1 ? 1 : 0, *pCtx ); |
---|
806 | } |
---|
807 | |
---|
808 | if( bVerAbsGr0 ) |
---|
809 | { |
---|
810 | m_pcBinIf->encodeBin( uiVerAbs > 1 ? 1 : 0, *pCtx ); |
---|
811 | } |
---|
812 | |
---|
813 | if( bHorAbsGr0 ) |
---|
814 | { |
---|
815 | if( uiHorAbs > 1 ) |
---|
816 | { |
---|
817 | xWriteEpExGolomb( uiHorAbs-2, 1 ); |
---|
818 | } |
---|
819 | |
---|
820 | m_pcBinIf->encodeBinEP( 0 > iHor ? 1 : 0 ); |
---|
821 | } |
---|
822 | |
---|
823 | if( bVerAbsGr0 ) |
---|
824 | { |
---|
825 | if( uiVerAbs > 1 ) |
---|
826 | { |
---|
827 | xWriteEpExGolomb( uiVerAbs-2, 1 ); |
---|
828 | } |
---|
829 | |
---|
830 | m_pcBinIf->encodeBinEP( 0 > iVer ? 1 : 0 ); |
---|
831 | } |
---|
832 | |
---|
833 | return; |
---|
834 | } |
---|
835 | |
---|
836 | Void TEncSbac::codeCrossComponentPrediction( TComTU &rTu, ComponentID compID ) |
---|
837 | { |
---|
838 | TComDataCU *pcCU = rTu.getCU(); |
---|
839 | |
---|
840 | if( isLuma(compID) || !pcCU->getSlice()->getPPS()->getUseCrossComponentPrediction() ) |
---|
841 | { |
---|
842 | return; |
---|
843 | } |
---|
844 | |
---|
845 | const UInt uiAbsPartIdx = rTu.GetAbsPartIdxTU(); |
---|
846 | |
---|
847 | if (!pcCU->isIntra(uiAbsPartIdx) || (pcCU->getIntraDir( CHANNEL_TYPE_CHROMA, uiAbsPartIdx ) == DM_CHROMA_IDX)) |
---|
848 | { |
---|
849 | DTRACE_CABAC_VL( g_nSymbolCounter++ ) |
---|
850 | DTRACE_CABAC_T("\tparseCrossComponentPrediction()") |
---|
851 | DTRACE_CABAC_T( "\tAddr=" ) |
---|
852 | DTRACE_CABAC_V( compID ) |
---|
853 | DTRACE_CABAC_T( "\tuiAbsPartIdx=" ) |
---|
854 | DTRACE_CABAC_V( uiAbsPartIdx ) |
---|
855 | |
---|
856 | Int alpha = pcCU->getCrossComponentPredictionAlpha( uiAbsPartIdx, compID ); |
---|
857 | ContextModel *pCtx = m_cCrossComponentPredictionSCModel.get(0, 0) + ((compID == COMPONENT_Cr) ? (NUM_CROSS_COMPONENT_PREDICTION_CTX >> 1) : 0); |
---|
858 | m_pcBinIf->encodeBin(((alpha != 0) ? 1 : 0), pCtx[0]); |
---|
859 | |
---|
860 | if (alpha != 0) |
---|
861 | { |
---|
862 | static const Int log2AbsAlphaMinus1Table[8] = { 0, 1, 1, 2, 2, 2, 3, 3 }; |
---|
863 | assert(abs(alpha) <= 8); |
---|
864 | |
---|
865 | if (abs(alpha)>1) |
---|
866 | { |
---|
867 | m_pcBinIf->encodeBin(1, pCtx[1]); |
---|
868 | xWriteUnaryMaxSymbol( log2AbsAlphaMinus1Table[abs(alpha) - 1] - 1, (pCtx + 2), 1, 2 ); |
---|
869 | } |
---|
870 | else |
---|
871 | { |
---|
872 | m_pcBinIf->encodeBin(0, pCtx[1]); |
---|
873 | } |
---|
874 | m_pcBinIf->encodeBin( ((alpha < 0) ? 1 : 0), pCtx[4] ); |
---|
875 | } |
---|
876 | DTRACE_CABAC_T( "\tAlpha=" ) |
---|
877 | DTRACE_CABAC_V( pcCU->getCrossComponentPredictionAlpha( uiAbsPartIdx, compID ) ) |
---|
878 | DTRACE_CABAC_T( "\n" ) |
---|
879 | } |
---|
880 | } |
---|
881 | |
---|
882 | Void TEncSbac::codeDeltaQP( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
883 | { |
---|
884 | Int iDQp = pcCU->getQP( uiAbsPartIdx ) - pcCU->getRefQP( uiAbsPartIdx ); |
---|
885 | |
---|
886 | #if SVC_EXTENSION |
---|
887 | Int qpBdOffsetY = pcCU->getSlice()->getQpBDOffsetY(); |
---|
888 | #else |
---|
889 | Int qpBdOffsetY = pcCU->getSlice()->getSPS()->getQpBDOffset(CHANNEL_TYPE_LUMA); |
---|
890 | #endif |
---|
891 | iDQp = (iDQp + 78 + qpBdOffsetY + (qpBdOffsetY/2)) % (52 + qpBdOffsetY) - 26 - (qpBdOffsetY/2); |
---|
892 | |
---|
893 | UInt uiAbsDQp = (UInt)((iDQp > 0)? iDQp : (-iDQp)); |
---|
894 | UInt TUValue = min((Int)uiAbsDQp, CU_DQP_TU_CMAX); |
---|
895 | xWriteUnaryMaxSymbol( TUValue, &m_cCUDeltaQpSCModel.get( 0, 0, 0 ), 1, CU_DQP_TU_CMAX); |
---|
896 | if( uiAbsDQp >= CU_DQP_TU_CMAX ) |
---|
897 | { |
---|
898 | xWriteEpExGolomb( uiAbsDQp - CU_DQP_TU_CMAX, CU_DQP_EG_k ); |
---|
899 | } |
---|
900 | |
---|
901 | if ( uiAbsDQp > 0) |
---|
902 | { |
---|
903 | UInt uiSign = (iDQp > 0 ? 0 : 1); |
---|
904 | m_pcBinIf->encodeBinEP(uiSign); |
---|
905 | } |
---|
906 | |
---|
907 | return; |
---|
908 | } |
---|
909 | |
---|
910 | /** code chroma qp adjustment, converting from the internal table representation |
---|
911 | * \returns Void |
---|
912 | */ |
---|
913 | Void TEncSbac::codeChromaQpAdjustment( TComDataCU* cu, UInt absPartIdx ) |
---|
914 | { |
---|
915 | Int internalIdc = cu->getChromaQpAdj( absPartIdx ); |
---|
916 | Int tableSize = cu->getSlice()->getPPS()->getChromaQpAdjTableSize(); |
---|
917 | /* internal_idc == 0 => flag = 0 |
---|
918 | * internal_idc > 1 => code idc value (if table size warrents) */ |
---|
919 | m_pcBinIf->encodeBin( internalIdc > 0, m_ChromaQpAdjFlagSCModel.get( 0, 0, 0 ) ); |
---|
920 | |
---|
921 | if (internalIdc > 0 && tableSize > 1) |
---|
922 | { |
---|
923 | xWriteUnaryMaxSymbol( internalIdc - 1, &m_ChromaQpAdjIdcSCModel.get( 0, 0, 0 ), 0, tableSize - 1 ); |
---|
924 | } |
---|
925 | } |
---|
926 | |
---|
927 | Void TEncSbac::codeQtCbf( TComTU &rTu, const ComponentID compID, const Bool lowestLevel ) |
---|
928 | { |
---|
929 | TComDataCU* pcCU = rTu.getCU(); |
---|
930 | |
---|
931 | const UInt absPartIdx = rTu.GetAbsPartIdxTU(compID); |
---|
932 | const UInt TUDepth = rTu.GetTransformDepthRel(); |
---|
933 | UInt uiCtx = pcCU->getCtxQtCbf( rTu, toChannelType(compID) ); |
---|
934 | const UInt contextSet = toChannelType(compID); |
---|
935 | |
---|
936 | const UInt width = rTu.getRect(compID).width; |
---|
937 | const UInt height = rTu.getRect(compID).height; |
---|
938 | const Bool canQuadSplit = (width >= (MIN_TU_SIZE * 2)) && (height >= (MIN_TU_SIZE * 2)); |
---|
939 | |
---|
940 | // Since the CBF for chroma is coded at the highest level possible, if sub-TUs are |
---|
941 | // to be coded for a 4x8 chroma TU, their CBFs must be coded at the highest 4x8 level |
---|
942 | // (i.e. where luma TUs are 8x8 rather than 4x4) |
---|
943 | // ___ ___ |
---|
944 | // | | | <- 4 x (8x8 luma + 4x8 4:2:2 chroma) |
---|
945 | // |___|___| each quadrant has its own chroma CBF |
---|
946 | // | | | _ _ _ _ |
---|
947 | // |___|___| | |
---|
948 | // <--16---> V |
---|
949 | // _ _ |
---|
950 | // |_|_| <- 4 x 4x4 luma + 1 x 4x8 4:2:2 chroma |
---|
951 | // |_|_| no chroma CBF is coded - instead the parent CBF is inherited |
---|
952 | // <-8-> if sub-TUs are present, their CBFs had to be coded at the parent level |
---|
953 | |
---|
954 | const UInt lowestTUDepth = TUDepth + ((!lowestLevel && !canQuadSplit) ? 1 : 0); //unsplittable TUs inherit their parent's CBF |
---|
955 | |
---|
956 | if ((width != height) && (lowestLevel || !canQuadSplit)) //if sub-TUs are present |
---|
957 | { |
---|
958 | 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) |
---|
959 | const UInt partIdxesPerSubTU = rTu.GetAbsPartIdxNumParts(compID) >> 1; |
---|
960 | |
---|
961 | for (UInt subTU = 0; subTU < 2; subTU++) |
---|
962 | { |
---|
963 | const UInt subTUAbsPartIdx = absPartIdx + (subTU * partIdxesPerSubTU); |
---|
964 | const UInt uiCbf = pcCU->getCbf(subTUAbsPartIdx, compID, subTUDepth); |
---|
965 | |
---|
966 | m_pcBinIf->encodeBin(uiCbf, m_cCUQtCbfSCModel.get(0, contextSet, uiCtx)); |
---|
967 | |
---|
968 | DTRACE_CABAC_VL( g_nSymbolCounter++ ) |
---|
969 | DTRACE_CABAC_T( "\tparseQtCbf()" ) |
---|
970 | DTRACE_CABAC_T( "\tsub-TU=" ) |
---|
971 | DTRACE_CABAC_V( subTU ) |
---|
972 | DTRACE_CABAC_T( "\tsymbol=" ) |
---|
973 | DTRACE_CABAC_V( uiCbf ) |
---|
974 | DTRACE_CABAC_T( "\tctx=" ) |
---|
975 | DTRACE_CABAC_V( uiCtx ) |
---|
976 | DTRACE_CABAC_T( "\tetype=" ) |
---|
977 | DTRACE_CABAC_V( compID ) |
---|
978 | DTRACE_CABAC_T( "\tuiAbsPartIdx=" ) |
---|
979 | DTRACE_CABAC_V( subTUAbsPartIdx ) |
---|
980 | DTRACE_CABAC_T( "\n" ) |
---|
981 | } |
---|
982 | } |
---|
983 | else |
---|
984 | { |
---|
985 | const UInt uiCbf = pcCU->getCbf( absPartIdx, compID, lowestTUDepth ); |
---|
986 | m_pcBinIf->encodeBin( uiCbf , m_cCUQtCbfSCModel.get( 0, contextSet, uiCtx ) ); |
---|
987 | |
---|
988 | |
---|
989 | DTRACE_CABAC_VL( g_nSymbolCounter++ ) |
---|
990 | DTRACE_CABAC_T( "\tparseQtCbf()" ) |
---|
991 | DTRACE_CABAC_T( "\tsymbol=" ) |
---|
992 | DTRACE_CABAC_V( uiCbf ) |
---|
993 | DTRACE_CABAC_T( "\tctx=" ) |
---|
994 | DTRACE_CABAC_V( uiCtx ) |
---|
995 | DTRACE_CABAC_T( "\tetype=" ) |
---|
996 | DTRACE_CABAC_V( compID ) |
---|
997 | DTRACE_CABAC_T( "\tuiAbsPartIdx=" ) |
---|
998 | DTRACE_CABAC_V( rTu.GetAbsPartIdxTU(compID) ) |
---|
999 | DTRACE_CABAC_T( "\n" ) |
---|
1000 | } |
---|
1001 | } |
---|
1002 | |
---|
1003 | |
---|
1004 | Void TEncSbac::codeTransformSkipFlags (TComTU &rTu, ComponentID component ) |
---|
1005 | { |
---|
1006 | TComDataCU* pcCU=rTu.getCU(); |
---|
1007 | const UInt uiAbsPartIdx=rTu.GetAbsPartIdxTU(); |
---|
1008 | |
---|
1009 | if (pcCU->getCUTransquantBypass(uiAbsPartIdx)) |
---|
1010 | { |
---|
1011 | return; |
---|
1012 | } |
---|
1013 | |
---|
1014 | if (!TUCompRectHasAssociatedTransformSkipFlag(rTu.getRect(component), pcCU->getSlice()->getPPS()->getTransformSkipLog2MaxSize())) |
---|
1015 | { |
---|
1016 | return; |
---|
1017 | } |
---|
1018 | |
---|
1019 | UInt useTransformSkip = pcCU->getTransformSkip( uiAbsPartIdx,component); |
---|
1020 | m_pcBinIf->encodeBin( useTransformSkip, m_cTransformSkipSCModel.get( 0, toChannelType(component), 0 ) ); |
---|
1021 | |
---|
1022 | DTRACE_CABAC_VL( g_nSymbolCounter++ ) |
---|
1023 | DTRACE_CABAC_T("\tparseTransformSkip()"); |
---|
1024 | DTRACE_CABAC_T( "\tsymbol=" ) |
---|
1025 | DTRACE_CABAC_V( useTransformSkip ) |
---|
1026 | DTRACE_CABAC_T( "\tAddr=" ) |
---|
1027 | DTRACE_CABAC_V( pcCU->getCtuRsAddr() ) |
---|
1028 | DTRACE_CABAC_T( "\tetype=" ) |
---|
1029 | DTRACE_CABAC_V( component ) |
---|
1030 | DTRACE_CABAC_T( "\tuiAbsPartIdx=" ) |
---|
1031 | DTRACE_CABAC_V( rTu.GetAbsPartIdxTU() ) |
---|
1032 | DTRACE_CABAC_T( "\n" ) |
---|
1033 | } |
---|
1034 | |
---|
1035 | |
---|
1036 | /** Code I_PCM information. |
---|
1037 | * \param pcCU pointer to CU |
---|
1038 | * \param uiAbsPartIdx CU index |
---|
1039 | * \returns Void |
---|
1040 | */ |
---|
1041 | Void TEncSbac::codeIPCMInfo( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
1042 | { |
---|
1043 | UInt uiIPCM = (pcCU->getIPCMFlag(uiAbsPartIdx) == true)? 1 : 0; |
---|
1044 | |
---|
1045 | Bool writePCMSampleFlag = pcCU->getIPCMFlag(uiAbsPartIdx); |
---|
1046 | |
---|
1047 | m_pcBinIf->encodeBinTrm (uiIPCM); |
---|
1048 | |
---|
1049 | if (writePCMSampleFlag) |
---|
1050 | { |
---|
1051 | m_pcBinIf->encodePCMAlignBits(); |
---|
1052 | |
---|
1053 | const UInt minCoeffSizeY = pcCU->getPic()->getMinCUWidth() * pcCU->getPic()->getMinCUHeight(); |
---|
1054 | const UInt offsetY = minCoeffSizeY * uiAbsPartIdx; |
---|
1055 | for (UInt ch=0; ch < pcCU->getPic()->getNumberValidComponents(); ch++) |
---|
1056 | { |
---|
1057 | const ComponentID compID = ComponentID(ch); |
---|
1058 | const UInt offset = offsetY >> (pcCU->getPic()->getComponentScaleX(compID) + pcCU->getPic()->getComponentScaleY(compID)); |
---|
1059 | Pel * pPCMSample = pcCU->getPCMSample(compID) + offset; |
---|
1060 | const UInt width = pcCU->getWidth (uiAbsPartIdx) >> pcCU->getPic()->getComponentScaleX(compID); |
---|
1061 | const UInt height = pcCU->getHeight(uiAbsPartIdx) >> pcCU->getPic()->getComponentScaleY(compID); |
---|
1062 | const UInt sampleBits = pcCU->getSlice()->getSPS()->getPCMBitDepth(toChannelType(compID)); |
---|
1063 | for (UInt y=0; y<height; y++) |
---|
1064 | { |
---|
1065 | for (UInt x=0; x<width; x++) |
---|
1066 | { |
---|
1067 | UInt sample = pPCMSample[x]; |
---|
1068 | m_pcBinIf->xWritePCMCode(sample, sampleBits); |
---|
1069 | } |
---|
1070 | pPCMSample += width; |
---|
1071 | } |
---|
1072 | } |
---|
1073 | |
---|
1074 | m_pcBinIf->resetBac(); |
---|
1075 | } |
---|
1076 | } |
---|
1077 | |
---|
1078 | Void TEncSbac::codeQtRootCbf( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
1079 | { |
---|
1080 | UInt uiCbf = pcCU->getQtRootCbf( uiAbsPartIdx ); |
---|
1081 | UInt uiCtx = 0; |
---|
1082 | m_pcBinIf->encodeBin( uiCbf , m_cCUQtRootCbfSCModel.get( 0, 0, uiCtx ) ); |
---|
1083 | DTRACE_CABAC_VL( g_nSymbolCounter++ ) |
---|
1084 | DTRACE_CABAC_T( "\tparseQtRootCbf()" ) |
---|
1085 | DTRACE_CABAC_T( "\tsymbol=" ) |
---|
1086 | DTRACE_CABAC_V( uiCbf ) |
---|
1087 | DTRACE_CABAC_T( "\tctx=" ) |
---|
1088 | DTRACE_CABAC_V( uiCtx ) |
---|
1089 | DTRACE_CABAC_T( "\tuiAbsPartIdx=" ) |
---|
1090 | DTRACE_CABAC_V( uiAbsPartIdx ) |
---|
1091 | DTRACE_CABAC_T( "\n" ) |
---|
1092 | } |
---|
1093 | |
---|
1094 | Void TEncSbac::codeQtCbfZero( TComTU & rTu, const ChannelType chType ) |
---|
1095 | { |
---|
1096 | // this function is only used to estimate the bits when cbf is 0 |
---|
1097 | // and will never be called when writing the bistream. do not need to write log |
---|
1098 | UInt uiCbf = 0; |
---|
1099 | UInt uiCtx = rTu.getCU()->getCtxQtCbf( rTu, chType ); |
---|
1100 | |
---|
1101 | m_pcBinIf->encodeBin( uiCbf , m_cCUQtCbfSCModel.get( 0, chType, uiCtx ) ); |
---|
1102 | } |
---|
1103 | |
---|
1104 | Void TEncSbac::codeQtRootCbfZero( TComDataCU* pcCU ) |
---|
1105 | { |
---|
1106 | // this function is only used to estimate the bits when cbf is 0 |
---|
1107 | // and will never be called when writing the bistream. do not need to write log |
---|
1108 | UInt uiCbf = 0; |
---|
1109 | UInt uiCtx = 0; |
---|
1110 | m_pcBinIf->encodeBin( uiCbf , m_cCUQtRootCbfSCModel.get( 0, 0, uiCtx ) ); |
---|
1111 | } |
---|
1112 | |
---|
1113 | /** Encode (X,Y) position of the last significant coefficient |
---|
1114 | * \param uiPosX X component of last coefficient |
---|
1115 | * \param uiPosY Y component of last coefficient |
---|
1116 | * \param width Block width |
---|
1117 | * \param height Block height |
---|
1118 | * \param eTType plane type / luminance or chrominance |
---|
1119 | * \param uiScanIdx scan type (zig-zag, hor, ver) |
---|
1120 | * This method encodes the X and Y component within a block of the last significant coefficient. |
---|
1121 | */ |
---|
1122 | Void TEncSbac::codeLastSignificantXY( UInt uiPosX, UInt uiPosY, Int width, Int height, ComponentID component, UInt uiScanIdx ) |
---|
1123 | { |
---|
1124 | // swap |
---|
1125 | if( uiScanIdx == SCAN_VER ) |
---|
1126 | { |
---|
1127 | swap( uiPosX, uiPosY ); |
---|
1128 | swap( width, height ); |
---|
1129 | } |
---|
1130 | |
---|
1131 | UInt uiCtxLast; |
---|
1132 | UInt uiGroupIdxX = g_uiGroupIdx[ uiPosX ]; |
---|
1133 | UInt uiGroupIdxY = g_uiGroupIdx[ uiPosY ]; |
---|
1134 | |
---|
1135 | ContextModel *pCtxX = m_cCuCtxLastX.get( 0, toChannelType(component) ); |
---|
1136 | ContextModel *pCtxY = m_cCuCtxLastY.get( 0, toChannelType(component) ); |
---|
1137 | |
---|
1138 | Int blkSizeOffsetX, blkSizeOffsetY, shiftX, shiftY; |
---|
1139 | getLastSignificantContextParameters(component, width, height, blkSizeOffsetX, blkSizeOffsetY, shiftX, shiftY); |
---|
1140 | |
---|
1141 | //------------------ |
---|
1142 | |
---|
1143 | // posX |
---|
1144 | |
---|
1145 | for( uiCtxLast = 0; uiCtxLast < uiGroupIdxX; uiCtxLast++ ) |
---|
1146 | { |
---|
1147 | m_pcBinIf->encodeBin( 1, *( pCtxX + blkSizeOffsetX + (uiCtxLast >>shiftX) ) ); |
---|
1148 | } |
---|
1149 | if( uiGroupIdxX < g_uiGroupIdx[ width - 1 ]) |
---|
1150 | { |
---|
1151 | m_pcBinIf->encodeBin( 0, *( pCtxX + blkSizeOffsetX + (uiCtxLast >>shiftX) ) ); |
---|
1152 | } |
---|
1153 | |
---|
1154 | // posY |
---|
1155 | |
---|
1156 | for( uiCtxLast = 0; uiCtxLast < uiGroupIdxY; uiCtxLast++ ) |
---|
1157 | { |
---|
1158 | m_pcBinIf->encodeBin( 1, *( pCtxY + blkSizeOffsetY + (uiCtxLast >>shiftY) ) ); |
---|
1159 | } |
---|
1160 | if( uiGroupIdxY < g_uiGroupIdx[ height - 1 ]) |
---|
1161 | { |
---|
1162 | m_pcBinIf->encodeBin( 0, *( pCtxY + blkSizeOffsetY + (uiCtxLast >>shiftY) ) ); |
---|
1163 | } |
---|
1164 | |
---|
1165 | // EP-coded part |
---|
1166 | |
---|
1167 | if ( uiGroupIdxX > 3 ) |
---|
1168 | { |
---|
1169 | UInt uiCount = ( uiGroupIdxX - 2 ) >> 1; |
---|
1170 | uiPosX = uiPosX - g_uiMinInGroup[ uiGroupIdxX ]; |
---|
1171 | for (Int i = uiCount - 1 ; i >= 0; i-- ) |
---|
1172 | { |
---|
1173 | m_pcBinIf->encodeBinEP( ( uiPosX >> i ) & 1 ); |
---|
1174 | } |
---|
1175 | } |
---|
1176 | if ( uiGroupIdxY > 3 ) |
---|
1177 | { |
---|
1178 | UInt uiCount = ( uiGroupIdxY - 2 ) >> 1; |
---|
1179 | uiPosY = uiPosY - g_uiMinInGroup[ uiGroupIdxY ]; |
---|
1180 | for ( Int i = uiCount - 1 ; i >= 0; i-- ) |
---|
1181 | { |
---|
1182 | m_pcBinIf->encodeBinEP( ( uiPosY >> i ) & 1 ); |
---|
1183 | } |
---|
1184 | } |
---|
1185 | } |
---|
1186 | |
---|
1187 | |
---|
1188 | Void TEncSbac::codeCoeffNxN( TComTU &rTu, TCoeff* pcCoef, const ComponentID compID ) |
---|
1189 | { |
---|
1190 | TComDataCU* pcCU=rTu.getCU(); |
---|
1191 | const UInt uiAbsPartIdx=rTu.GetAbsPartIdxTU(compID); |
---|
1192 | const TComRectangle &tuRect=rTu.getRect(compID); |
---|
1193 | const UInt uiWidth=tuRect.width; |
---|
1194 | const UInt uiHeight=tuRect.height; |
---|
1195 | |
---|
1196 | DTRACE_CABAC_VL( g_nSymbolCounter++ ) |
---|
1197 | DTRACE_CABAC_T( "\tparseCoeffNxN()\teType=" ) |
---|
1198 | DTRACE_CABAC_V( compID ) |
---|
1199 | DTRACE_CABAC_T( "\twidth=" ) |
---|
1200 | DTRACE_CABAC_V( uiWidth ) |
---|
1201 | DTRACE_CABAC_T( "\theight=" ) |
---|
1202 | DTRACE_CABAC_V( uiHeight ) |
---|
1203 | DTRACE_CABAC_T( "\tdepth=" ) |
---|
1204 | // DTRACE_CABAC_V( rTu.GetTransformDepthTotalAdj(compID) ) |
---|
1205 | DTRACE_CABAC_V( rTu.GetTransformDepthTotal() ) |
---|
1206 | DTRACE_CABAC_T( "\tabspartidx=" ) |
---|
1207 | DTRACE_CABAC_V( uiAbsPartIdx ) |
---|
1208 | DTRACE_CABAC_T( "\ttoCU-X=" ) |
---|
1209 | DTRACE_CABAC_V( pcCU->getCUPelX() ) |
---|
1210 | DTRACE_CABAC_T( "\ttoCU-Y=" ) |
---|
1211 | DTRACE_CABAC_V( pcCU->getCUPelY() ) |
---|
1212 | DTRACE_CABAC_T( "\tCU-addr=" ) |
---|
1213 | DTRACE_CABAC_V( pcCU->getCtuRsAddr() ) |
---|
1214 | DTRACE_CABAC_T( "\tinCU-X=" ) |
---|
1215 | // DTRACE_CABAC_V( g_auiRasterToPelX[ g_auiZscanToRaster[uiAbsPartIdx] ] ) |
---|
1216 | DTRACE_CABAC_V( g_auiRasterToPelX[ g_auiZscanToRaster[rTu.GetAbsPartIdxTU(compID)] ] ) |
---|
1217 | DTRACE_CABAC_T( "\tinCU-Y=" ) |
---|
1218 | // DTRACE_CABAC_V( g_auiRasterToPelY[ g_auiZscanToRaster[uiAbsPartIdx] ] ) |
---|
1219 | DTRACE_CABAC_V( g_auiRasterToPelY[ g_auiZscanToRaster[rTu.GetAbsPartIdxTU(compID)] ] ) |
---|
1220 | DTRACE_CABAC_T( "\tpredmode=" ) |
---|
1221 | DTRACE_CABAC_V( pcCU->getPredictionMode( uiAbsPartIdx ) ) |
---|
1222 | DTRACE_CABAC_T( "\n" ) |
---|
1223 | |
---|
1224 | //-------------------------------------------------------------------------------------------------- |
---|
1225 | |
---|
1226 | if( uiWidth > m_pcSlice->getSPS()->getMaxTrSize() ) |
---|
1227 | { |
---|
1228 | std::cerr << "ERROR: codeCoeffNxN was passed a TU with dimensions larger than the maximum allowed size" << std::endl; |
---|
1229 | assert(false); |
---|
1230 | exit(1); |
---|
1231 | } |
---|
1232 | |
---|
1233 | // compute number of significant coefficients |
---|
1234 | UInt uiNumSig = TEncEntropy::countNonZeroCoeffs(pcCoef, uiWidth * uiHeight); |
---|
1235 | |
---|
1236 | if ( uiNumSig == 0 ) |
---|
1237 | { |
---|
1238 | std::cerr << "ERROR: codeCoeffNxN called for empty TU!" << std::endl; |
---|
1239 | assert(false); |
---|
1240 | exit(1); |
---|
1241 | } |
---|
1242 | |
---|
1243 | //-------------------------------------------------------------------------------------------------- |
---|
1244 | |
---|
1245 | //set parameters |
---|
1246 | |
---|
1247 | const ChannelType chType = toChannelType(compID); |
---|
1248 | const UInt uiLog2BlockWidth = g_aucConvertToBit[ uiWidth ] + 2; |
---|
1249 | const UInt uiLog2BlockHeight = g_aucConvertToBit[ uiHeight ] + 2; |
---|
1250 | |
---|
1251 | const ChannelType channelType = toChannelType(compID); |
---|
1252 | const Bool extendedPrecision = pcCU->getSlice()->getSPS()->getUseExtendedPrecision(); |
---|
1253 | |
---|
1254 | const Bool alignCABACBeforeBypass = pcCU->getSlice()->getSPS()->getAlignCABACBeforeBypass(); |
---|
1255 | |
---|
1256 | Bool beValid; |
---|
1257 | |
---|
1258 | { |
---|
1259 | Int uiIntraMode = -1; |
---|
1260 | const Bool bIsLuma = isLuma(compID); |
---|
1261 | Int isIntra = pcCU->isIntra(uiAbsPartIdx) ? 1 : 0; |
---|
1262 | if ( isIntra ) |
---|
1263 | { |
---|
1264 | uiIntraMode = pcCU->getIntraDir( toChannelType(compID), uiAbsPartIdx ); |
---|
1265 | |
---|
1266 | uiIntraMode = (uiIntraMode==DM_CHROMA_IDX && !bIsLuma) ? pcCU->getIntraDir(CHANNEL_TYPE_LUMA, getChromasCorrespondingPULumaIdx(uiAbsPartIdx, rTu.GetChromaFormat())) : uiIntraMode; |
---|
1267 | uiIntraMode = ((rTu.GetChromaFormat() == CHROMA_422) && !bIsLuma) ? g_chroma422IntraAngleMappingTable[uiIntraMode] : uiIntraMode; |
---|
1268 | } |
---|
1269 | |
---|
1270 | Int transformSkip = pcCU->getTransformSkip( uiAbsPartIdx,compID) ? 1 : 0; |
---|
1271 | Bool rdpcm_lossy = ( transformSkip && isIntra && ( (uiIntraMode == HOR_IDX) || (uiIntraMode == VER_IDX) ) ) && pcCU->isRDPCMEnabled(uiAbsPartIdx); |
---|
1272 | |
---|
1273 | if ( (pcCU->getCUTransquantBypass(uiAbsPartIdx)) || rdpcm_lossy ) |
---|
1274 | { |
---|
1275 | beValid = false; |
---|
1276 | if ( (!pcCU->isIntra(uiAbsPartIdx)) && pcCU->isRDPCMEnabled(uiAbsPartIdx)) |
---|
1277 | { |
---|
1278 | codeExplicitRdpcmMode( rTu, compID); |
---|
1279 | } |
---|
1280 | } |
---|
1281 | else |
---|
1282 | { |
---|
1283 | beValid = pcCU->getSlice()->getPPS()->getSignHideFlag(); |
---|
1284 | } |
---|
1285 | } |
---|
1286 | |
---|
1287 | //-------------------------------------------------------------------------------------------------- |
---|
1288 | |
---|
1289 | if(pcCU->getSlice()->getPPS()->getUseTransformSkip()) |
---|
1290 | { |
---|
1291 | codeTransformSkipFlags(rTu, compID); |
---|
1292 | if(pcCU->getTransformSkip(uiAbsPartIdx, compID) && !pcCU->isIntra(uiAbsPartIdx) && pcCU->isRDPCMEnabled(uiAbsPartIdx)) |
---|
1293 | { |
---|
1294 | // This TU has coefficients and is transform skipped. Check whether is inter coded and if yes encode the explicit RDPCM mode |
---|
1295 | codeExplicitRdpcmMode( rTu, compID); |
---|
1296 | |
---|
1297 | if(pcCU->getExplicitRdpcmMode(compID, uiAbsPartIdx) != RDPCM_OFF) |
---|
1298 | { |
---|
1299 | // Sign data hiding is avoided for horizontal and vertical explicit RDPCM modes |
---|
1300 | beValid = false; |
---|
1301 | } |
---|
1302 | } |
---|
1303 | } |
---|
1304 | |
---|
1305 | //-------------------------------------------------------------------------------------------------- |
---|
1306 | |
---|
1307 | const Bool bUseGolombRiceParameterAdaptation = pcCU->getSlice()->getSPS()->getUseGolombRiceParameterAdaptation(); |
---|
1308 | UInt ¤tGolombRiceStatistic = m_golombRiceAdaptationStatistics[rTu.getGolombRiceStatisticsIndex(compID)]; |
---|
1309 | |
---|
1310 | //select scans |
---|
1311 | TUEntropyCodingParameters codingParameters; |
---|
1312 | getTUEntropyCodingParameters(codingParameters, rTu, compID); |
---|
1313 | |
---|
1314 | //----- encode significance map ----- |
---|
1315 | |
---|
1316 | // Find position of last coefficient |
---|
1317 | Int scanPosLast = -1; |
---|
1318 | Int posLast; |
---|
1319 | |
---|
1320 | |
---|
1321 | UInt uiSigCoeffGroupFlag[ MLS_GRP_NUM ]; |
---|
1322 | |
---|
1323 | memset( uiSigCoeffGroupFlag, 0, sizeof(UInt) * MLS_GRP_NUM ); |
---|
1324 | do |
---|
1325 | { |
---|
1326 | posLast = codingParameters.scan[ ++scanPosLast ]; |
---|
1327 | |
---|
1328 | if( pcCoef[ posLast ] != 0 ) |
---|
1329 | { |
---|
1330 | // get L1 sig map |
---|
1331 | UInt uiPosY = posLast >> uiLog2BlockWidth; |
---|
1332 | UInt uiPosX = posLast - ( uiPosY << uiLog2BlockWidth ); |
---|
1333 | |
---|
1334 | UInt uiBlkIdx = (codingParameters.widthInGroups * (uiPosY >> MLS_CG_LOG2_HEIGHT)) + (uiPosX >> MLS_CG_LOG2_WIDTH); |
---|
1335 | uiSigCoeffGroupFlag[ uiBlkIdx ] = 1; |
---|
1336 | |
---|
1337 | uiNumSig--; |
---|
1338 | } |
---|
1339 | } while ( uiNumSig > 0 ); |
---|
1340 | |
---|
1341 | // Code position of last coefficient |
---|
1342 | Int posLastY = posLast >> uiLog2BlockWidth; |
---|
1343 | Int posLastX = posLast - ( posLastY << uiLog2BlockWidth ); |
---|
1344 | codeLastSignificantXY(posLastX, posLastY, uiWidth, uiHeight, compID, codingParameters.scanType); |
---|
1345 | |
---|
1346 | //===== code significance flag ===== |
---|
1347 | ContextModel * const baseCoeffGroupCtx = m_cCUSigCoeffGroupSCModel.get( 0, chType ); |
---|
1348 | ContextModel * const baseCtx = m_cCUSigSCModel.get( 0, 0 ) + getSignificanceMapContextOffset(compID); |
---|
1349 | |
---|
1350 | const Int iLastScanSet = scanPosLast >> MLS_CG_SIZE; |
---|
1351 | |
---|
1352 | UInt c1 = 1; |
---|
1353 | UInt uiGoRiceParam = 0; |
---|
1354 | Int iScanPosSig = scanPosLast; |
---|
1355 | |
---|
1356 | for( Int iSubSet = iLastScanSet; iSubSet >= 0; iSubSet-- ) |
---|
1357 | { |
---|
1358 | Int numNonZero = 0; |
---|
1359 | Int iSubPos = iSubSet << MLS_CG_SIZE; |
---|
1360 | uiGoRiceParam = currentGolombRiceStatistic / RExt__GOLOMB_RICE_INCREMENT_DIVISOR; |
---|
1361 | Bool updateGolombRiceStatistics = bUseGolombRiceParameterAdaptation; //leave the statistics at 0 when not using the adaptation system |
---|
1362 | UInt coeffSigns = 0; |
---|
1363 | |
---|
1364 | Int absCoeff[1 << MLS_CG_SIZE]; |
---|
1365 | |
---|
1366 | Int lastNZPosInCG = -1; |
---|
1367 | Int firstNZPosInCG = 1 << MLS_CG_SIZE; |
---|
1368 | |
---|
1369 | Bool escapeDataPresentInGroup = false; |
---|
1370 | |
---|
1371 | if( iScanPosSig == scanPosLast ) |
---|
1372 | { |
---|
1373 | absCoeff[ 0 ] = Int(abs( pcCoef[ posLast ] )); |
---|
1374 | coeffSigns = ( pcCoef[ posLast ] < 0 ); |
---|
1375 | numNonZero = 1; |
---|
1376 | lastNZPosInCG = iScanPosSig; |
---|
1377 | firstNZPosInCG = iScanPosSig; |
---|
1378 | iScanPosSig--; |
---|
1379 | } |
---|
1380 | |
---|
1381 | // encode significant_coeffgroup_flag |
---|
1382 | Int iCGBlkPos = codingParameters.scanCG[ iSubSet ]; |
---|
1383 | Int iCGPosY = iCGBlkPos / codingParameters.widthInGroups; |
---|
1384 | Int iCGPosX = iCGBlkPos - (iCGPosY * codingParameters.widthInGroups); |
---|
1385 | |
---|
1386 | if( iSubSet == iLastScanSet || iSubSet == 0) |
---|
1387 | { |
---|
1388 | uiSigCoeffGroupFlag[ iCGBlkPos ] = 1; |
---|
1389 | } |
---|
1390 | else |
---|
1391 | { |
---|
1392 | UInt uiSigCoeffGroup = (uiSigCoeffGroupFlag[ iCGBlkPos ] != 0); |
---|
1393 | UInt uiCtxSig = TComTrQuant::getSigCoeffGroupCtxInc( uiSigCoeffGroupFlag, iCGPosX, iCGPosY, codingParameters.widthInGroups, codingParameters.heightInGroups ); |
---|
1394 | m_pcBinIf->encodeBin( uiSigCoeffGroup, baseCoeffGroupCtx[ uiCtxSig ] ); |
---|
1395 | } |
---|
1396 | |
---|
1397 | // encode significant_coeff_flag |
---|
1398 | if( uiSigCoeffGroupFlag[ iCGBlkPos ] ) |
---|
1399 | { |
---|
1400 | const Int patternSigCtx = TComTrQuant::calcPatternSigCtx(uiSigCoeffGroupFlag, iCGPosX, iCGPosY, codingParameters.widthInGroups, codingParameters.heightInGroups); |
---|
1401 | |
---|
1402 | UInt uiBlkPos, uiSig, uiCtxSig; |
---|
1403 | for( ; iScanPosSig >= iSubPos; iScanPosSig-- ) |
---|
1404 | { |
---|
1405 | uiBlkPos = codingParameters.scan[ iScanPosSig ]; |
---|
1406 | uiSig = (pcCoef[ uiBlkPos ] != 0); |
---|
1407 | if( iScanPosSig > iSubPos || iSubSet == 0 || numNonZero ) |
---|
1408 | { |
---|
1409 | uiCtxSig = TComTrQuant::getSigCtxInc( patternSigCtx, codingParameters, iScanPosSig, uiLog2BlockWidth, uiLog2BlockHeight, chType ); |
---|
1410 | m_pcBinIf->encodeBin( uiSig, baseCtx[ uiCtxSig ] ); |
---|
1411 | } |
---|
1412 | if( uiSig ) |
---|
1413 | { |
---|
1414 | absCoeff[ numNonZero ] = Int(abs( pcCoef[ uiBlkPos ] )); |
---|
1415 | coeffSigns = 2 * coeffSigns + ( pcCoef[ uiBlkPos ] < 0 ); |
---|
1416 | numNonZero++; |
---|
1417 | if( lastNZPosInCG == -1 ) |
---|
1418 | { |
---|
1419 | lastNZPosInCG = iScanPosSig; |
---|
1420 | } |
---|
1421 | firstNZPosInCG = iScanPosSig; |
---|
1422 | } |
---|
1423 | } |
---|
1424 | } |
---|
1425 | else |
---|
1426 | { |
---|
1427 | iScanPosSig = iSubPos - 1; |
---|
1428 | } |
---|
1429 | |
---|
1430 | if( numNonZero > 0 ) |
---|
1431 | { |
---|
1432 | Bool signHidden = ( lastNZPosInCG - firstNZPosInCG >= SBH_THRESHOLD ); |
---|
1433 | |
---|
1434 | const UInt uiCtxSet = getContextSetIndex(compID, iSubSet, (c1 == 0)); |
---|
1435 | c1 = 1; |
---|
1436 | |
---|
1437 | ContextModel *baseCtxMod = m_cCUOneSCModel.get( 0, 0 ) + (NUM_ONE_FLAG_CTX_PER_SET * uiCtxSet); |
---|
1438 | |
---|
1439 | Int numC1Flag = min(numNonZero, C1FLAG_NUMBER); |
---|
1440 | Int firstC2FlagIdx = -1; |
---|
1441 | for( Int idx = 0; idx < numC1Flag; idx++ ) |
---|
1442 | { |
---|
1443 | UInt uiSymbol = absCoeff[ idx ] > 1; |
---|
1444 | m_pcBinIf->encodeBin( uiSymbol, baseCtxMod[c1] ); |
---|
1445 | if( uiSymbol ) |
---|
1446 | { |
---|
1447 | c1 = 0; |
---|
1448 | |
---|
1449 | if (firstC2FlagIdx == -1) |
---|
1450 | { |
---|
1451 | firstC2FlagIdx = idx; |
---|
1452 | } |
---|
1453 | else //if a greater-than-one has been encountered already this group |
---|
1454 | { |
---|
1455 | escapeDataPresentInGroup = true; |
---|
1456 | } |
---|
1457 | } |
---|
1458 | else if( (c1 < 3) && (c1 > 0) ) |
---|
1459 | { |
---|
1460 | c1++; |
---|
1461 | } |
---|
1462 | } |
---|
1463 | |
---|
1464 | if (c1 == 0) |
---|
1465 | { |
---|
1466 | baseCtxMod = m_cCUAbsSCModel.get( 0, 0 ) + (NUM_ABS_FLAG_CTX_PER_SET * uiCtxSet); |
---|
1467 | if ( firstC2FlagIdx != -1) |
---|
1468 | { |
---|
1469 | UInt symbol = absCoeff[ firstC2FlagIdx ] > 2; |
---|
1470 | m_pcBinIf->encodeBin( symbol, baseCtxMod[0] ); |
---|
1471 | if (symbol != 0) |
---|
1472 | { |
---|
1473 | escapeDataPresentInGroup = true; |
---|
1474 | } |
---|
1475 | } |
---|
1476 | } |
---|
1477 | |
---|
1478 | escapeDataPresentInGroup = escapeDataPresentInGroup || (numNonZero > C1FLAG_NUMBER); |
---|
1479 | |
---|
1480 | if (escapeDataPresentInGroup && alignCABACBeforeBypass) |
---|
1481 | { |
---|
1482 | m_pcBinIf->align(); |
---|
1483 | } |
---|
1484 | |
---|
1485 | if( beValid && signHidden ) |
---|
1486 | { |
---|
1487 | m_pcBinIf->encodeBinsEP( (coeffSigns >> 1), numNonZero-1 ); |
---|
1488 | } |
---|
1489 | else |
---|
1490 | { |
---|
1491 | m_pcBinIf->encodeBinsEP( coeffSigns, numNonZero ); |
---|
1492 | } |
---|
1493 | |
---|
1494 | Int iFirstCoeff2 = 1; |
---|
1495 | if (escapeDataPresentInGroup) |
---|
1496 | { |
---|
1497 | for ( Int idx = 0; idx < numNonZero; idx++ ) |
---|
1498 | { |
---|
1499 | UInt baseLevel = (idx < C1FLAG_NUMBER)? (2 + iFirstCoeff2 ) : 1; |
---|
1500 | |
---|
1501 | if( absCoeff[ idx ] >= baseLevel) |
---|
1502 | { |
---|
1503 | const UInt escapeCodeValue = absCoeff[idx] - baseLevel; |
---|
1504 | |
---|
1505 | xWriteCoefRemainExGolomb( escapeCodeValue, uiGoRiceParam, extendedPrecision, channelType ); |
---|
1506 | |
---|
1507 | if (absCoeff[idx] > (3 << uiGoRiceParam)) |
---|
1508 | { |
---|
1509 | uiGoRiceParam = bUseGolombRiceParameterAdaptation ? (uiGoRiceParam + 1) : (std::min<UInt>((uiGoRiceParam + 1), 4)); |
---|
1510 | } |
---|
1511 | |
---|
1512 | if (updateGolombRiceStatistics) |
---|
1513 | { |
---|
1514 | const UInt initialGolombRiceParameter = currentGolombRiceStatistic / RExt__GOLOMB_RICE_INCREMENT_DIVISOR; |
---|
1515 | |
---|
1516 | if (escapeCodeValue >= (3 << initialGolombRiceParameter)) |
---|
1517 | { |
---|
1518 | currentGolombRiceStatistic++; |
---|
1519 | } |
---|
1520 | else if (((escapeCodeValue * 2) < (1 << initialGolombRiceParameter)) && (currentGolombRiceStatistic > 0)) |
---|
1521 | { |
---|
1522 | currentGolombRiceStatistic--; |
---|
1523 | } |
---|
1524 | |
---|
1525 | updateGolombRiceStatistics = false; |
---|
1526 | } |
---|
1527 | } |
---|
1528 | |
---|
1529 | if(absCoeff[ idx ] >= 2) |
---|
1530 | { |
---|
1531 | iFirstCoeff2 = 0; |
---|
1532 | } |
---|
1533 | } |
---|
1534 | } |
---|
1535 | } |
---|
1536 | } |
---|
1537 | #if ENVIRONMENT_VARIABLE_DEBUG_AND_TEST |
---|
1538 | printSBACCoeffData(posLastX, posLastY, uiWidth, uiHeight, compID, uiAbsPartIdx, codingParameters.scanType, pcCoef, g_bFinalEncode); |
---|
1539 | #endif |
---|
1540 | |
---|
1541 | return; |
---|
1542 | } |
---|
1543 | |
---|
1544 | /** code SAO offset sign |
---|
1545 | * \param code sign value |
---|
1546 | */ |
---|
1547 | Void TEncSbac::codeSAOSign( UInt code ) |
---|
1548 | { |
---|
1549 | m_pcBinIf->encodeBinEP( code ); |
---|
1550 | } |
---|
1551 | |
---|
1552 | Void TEncSbac::codeSaoMaxUvlc ( UInt code, UInt maxSymbol ) |
---|
1553 | { |
---|
1554 | if (maxSymbol == 0) |
---|
1555 | { |
---|
1556 | return; |
---|
1557 | } |
---|
1558 | |
---|
1559 | Int i; |
---|
1560 | Bool bCodeLast = ( maxSymbol > code ); |
---|
1561 | |
---|
1562 | if ( code == 0 ) |
---|
1563 | { |
---|
1564 | m_pcBinIf->encodeBinEP( 0 ); |
---|
1565 | } |
---|
1566 | else |
---|
1567 | { |
---|
1568 | m_pcBinIf->encodeBinEP( 1 ); |
---|
1569 | for ( i=0; i<code-1; i++ ) |
---|
1570 | { |
---|
1571 | m_pcBinIf->encodeBinEP( 1 ); |
---|
1572 | } |
---|
1573 | if( bCodeLast ) |
---|
1574 | { |
---|
1575 | m_pcBinIf->encodeBinEP( 0 ); |
---|
1576 | } |
---|
1577 | } |
---|
1578 | } |
---|
1579 | |
---|
1580 | /** Code SAO EO class or BO band position |
---|
1581 | * \param uiLength |
---|
1582 | * \param uiCode |
---|
1583 | */ |
---|
1584 | Void TEncSbac::codeSaoUflc ( UInt uiLength, UInt uiCode ) |
---|
1585 | { |
---|
1586 | m_pcBinIf->encodeBinsEP ( uiCode, uiLength ); |
---|
1587 | } |
---|
1588 | |
---|
1589 | /** Code SAO merge flags |
---|
1590 | * \param uiCode |
---|
1591 | * \param uiCompIdx |
---|
1592 | */ |
---|
1593 | Void TEncSbac::codeSaoMerge ( UInt uiCode ) |
---|
1594 | { |
---|
1595 | m_pcBinIf->encodeBin(((uiCode == 0) ? 0 : 1), m_cSaoMergeSCModel.get( 0, 0, 0 )); |
---|
1596 | } |
---|
1597 | |
---|
1598 | /** Code SAO type index |
---|
1599 | * \param uiCode |
---|
1600 | */ |
---|
1601 | Void TEncSbac::codeSaoTypeIdx ( UInt uiCode) |
---|
1602 | { |
---|
1603 | if (uiCode == 0) |
---|
1604 | { |
---|
1605 | m_pcBinIf->encodeBin( 0, m_cSaoTypeIdxSCModel.get( 0, 0, 0 ) ); |
---|
1606 | } |
---|
1607 | else |
---|
1608 | { |
---|
1609 | m_pcBinIf->encodeBin( 1, m_cSaoTypeIdxSCModel.get( 0, 0, 0 ) ); |
---|
1610 | m_pcBinIf->encodeBinEP( uiCode == 1 ? 0 : 1 ); |
---|
1611 | } |
---|
1612 | } |
---|
1613 | #if SVC_EXTENSION |
---|
1614 | Void TEncSbac::codeSAOOffsetParam(ComponentID compIdx, SAOOffset& ctbParam, Bool sliceEnabled, UInt* saoMaxOffsetQVal) |
---|
1615 | #else |
---|
1616 | Void TEncSbac::codeSAOOffsetParam(ComponentID compIdx, SAOOffset& ctbParam, Bool sliceEnabled) |
---|
1617 | #endif |
---|
1618 | { |
---|
1619 | UInt uiSymbol; |
---|
1620 | if(!sliceEnabled) |
---|
1621 | { |
---|
1622 | assert(ctbParam.modeIdc == SAO_MODE_OFF); |
---|
1623 | return; |
---|
1624 | } |
---|
1625 | const Bool bIsFirstCompOfChType = (getFirstComponentOfChannel(toChannelType(compIdx)) == compIdx); |
---|
1626 | |
---|
1627 | //type |
---|
1628 | if(bIsFirstCompOfChType) |
---|
1629 | { |
---|
1630 | //sao_type_idx_luma or sao_type_idx_chroma |
---|
1631 | if(ctbParam.modeIdc == SAO_MODE_OFF) |
---|
1632 | { |
---|
1633 | uiSymbol =0; |
---|
1634 | } |
---|
1635 | else if(ctbParam.typeIdc == SAO_TYPE_BO) //BO |
---|
1636 | { |
---|
1637 | uiSymbol = 1; |
---|
1638 | } |
---|
1639 | else |
---|
1640 | { |
---|
1641 | assert(ctbParam.typeIdc < SAO_TYPE_START_BO); //EO |
---|
1642 | uiSymbol = 2; |
---|
1643 | } |
---|
1644 | codeSaoTypeIdx(uiSymbol); |
---|
1645 | } |
---|
1646 | |
---|
1647 | if(ctbParam.modeIdc == SAO_MODE_NEW) |
---|
1648 | { |
---|
1649 | Int numClasses = (ctbParam.typeIdc == SAO_TYPE_BO)?4:NUM_SAO_EO_CLASSES; |
---|
1650 | Int offset[4]; |
---|
1651 | Int k=0; |
---|
1652 | for(Int i=0; i< numClasses; i++) |
---|
1653 | { |
---|
1654 | if(ctbParam.typeIdc != SAO_TYPE_BO && i == SAO_CLASS_EO_PLAIN) |
---|
1655 | { |
---|
1656 | continue; |
---|
1657 | } |
---|
1658 | Int classIdx = (ctbParam.typeIdc == SAO_TYPE_BO)?( (ctbParam.typeAuxInfo+i)% NUM_SAO_BO_CLASSES ):i; |
---|
1659 | offset[k] = ctbParam.offset[classIdx]; |
---|
1660 | k++; |
---|
1661 | } |
---|
1662 | |
---|
1663 | for(Int i=0; i< 4; i++) |
---|
1664 | { |
---|
1665 | #if SVC_EXTENSION |
---|
1666 | codeSaoMaxUvlc((offset[i]<0)?(-offset[i]):(offset[i]), saoMaxOffsetQVal[compIdx] ); //sao_offset_abs |
---|
1667 | #else |
---|
1668 | codeSaoMaxUvlc((offset[i]<0)?(-offset[i]):(offset[i]), g_saoMaxOffsetQVal[compIdx] ); //sao_offset_abs |
---|
1669 | #endif |
---|
1670 | } |
---|
1671 | |
---|
1672 | |
---|
1673 | if(ctbParam.typeIdc == SAO_TYPE_BO) |
---|
1674 | { |
---|
1675 | for(Int i=0; i< 4; i++) |
---|
1676 | { |
---|
1677 | if(offset[i] != 0) |
---|
1678 | { |
---|
1679 | codeSAOSign((offset[i]< 0)?1:0); |
---|
1680 | } |
---|
1681 | } |
---|
1682 | |
---|
1683 | codeSaoUflc(NUM_SAO_BO_CLASSES_LOG2, ctbParam.typeAuxInfo ); //sao_band_position |
---|
1684 | } |
---|
1685 | else //EO |
---|
1686 | { |
---|
1687 | if(bIsFirstCompOfChType) |
---|
1688 | { |
---|
1689 | assert(ctbParam.typeIdc - SAO_TYPE_START_EO >=0); |
---|
1690 | codeSaoUflc(NUM_SAO_EO_TYPES_LOG2, ctbParam.typeIdc - SAO_TYPE_START_EO ); //sao_eo_class_luma or sao_eo_class_chroma |
---|
1691 | } |
---|
1692 | } |
---|
1693 | |
---|
1694 | } |
---|
1695 | } |
---|
1696 | |
---|
1697 | |
---|
1698 | Void TEncSbac::codeSAOBlkParam(SAOBlkParam& saoBlkParam |
---|
1699 | #if SVC_EXTENSION |
---|
1700 | , UInt* saoMaxOffsetQVal |
---|
1701 | #endif |
---|
1702 | , Bool* sliceEnabled |
---|
1703 | , Bool leftMergeAvail |
---|
1704 | , Bool aboveMergeAvail |
---|
1705 | , Bool onlyEstMergeInfo // = false |
---|
1706 | ) |
---|
1707 | { |
---|
1708 | |
---|
1709 | Bool isLeftMerge = false; |
---|
1710 | Bool isAboveMerge= false; |
---|
1711 | |
---|
1712 | if(leftMergeAvail) |
---|
1713 | { |
---|
1714 | isLeftMerge = ((saoBlkParam[COMPONENT_Y].modeIdc == SAO_MODE_MERGE) && (saoBlkParam[COMPONENT_Y].typeIdc == SAO_MERGE_LEFT)); |
---|
1715 | codeSaoMerge( isLeftMerge?1:0 ); //sao_merge_left_flag |
---|
1716 | } |
---|
1717 | |
---|
1718 | if( aboveMergeAvail && !isLeftMerge) |
---|
1719 | { |
---|
1720 | isAboveMerge = ((saoBlkParam[COMPONENT_Y].modeIdc == SAO_MODE_MERGE) && (saoBlkParam[COMPONENT_Y].typeIdc == SAO_MERGE_ABOVE)); |
---|
1721 | codeSaoMerge( isAboveMerge?1:0 ); //sao_merge_left_flag |
---|
1722 | } |
---|
1723 | |
---|
1724 | if(onlyEstMergeInfo) |
---|
1725 | { |
---|
1726 | return; //only for RDO |
---|
1727 | } |
---|
1728 | |
---|
1729 | if(!isLeftMerge && !isAboveMerge) //not merge mode |
---|
1730 | { |
---|
1731 | for(Int compIdx=0; compIdx < MAX_NUM_COMPONENT; compIdx++) |
---|
1732 | { |
---|
1733 | #if SVC_EXTENSION |
---|
1734 | codeSAOOffsetParam(ComponentID(compIdx), saoBlkParam[compIdx], sliceEnabled[compIdx], saoMaxOffsetQVal); |
---|
1735 | #else |
---|
1736 | codeSAOOffsetParam(ComponentID(compIdx), saoBlkParam[compIdx], sliceEnabled[compIdx]); |
---|
1737 | #endif |
---|
1738 | } |
---|
1739 | } |
---|
1740 | } |
---|
1741 | |
---|
1742 | /*! |
---|
1743 | **************************************************************************** |
---|
1744 | * \brief |
---|
1745 | * estimate bit cost for CBP, significant map and significant coefficients |
---|
1746 | **************************************************************************** |
---|
1747 | */ |
---|
1748 | Void TEncSbac::estBit( estBitsSbacStruct* pcEstBitsSbac, Int width, Int height, ChannelType chType ) |
---|
1749 | { |
---|
1750 | estCBFBit( pcEstBitsSbac ); |
---|
1751 | |
---|
1752 | estSignificantCoeffGroupMapBit( pcEstBitsSbac, chType ); |
---|
1753 | |
---|
1754 | // encode significance map |
---|
1755 | estSignificantMapBit( pcEstBitsSbac, width, height, chType ); |
---|
1756 | |
---|
1757 | // encode last significant position |
---|
1758 | estLastSignificantPositionBit( pcEstBitsSbac, width, height, chType ); |
---|
1759 | |
---|
1760 | // encode significant coefficients |
---|
1761 | estSignificantCoefficientsBit( pcEstBitsSbac, chType ); |
---|
1762 | |
---|
1763 | memcpy(pcEstBitsSbac->golombRiceAdaptationStatistics, m_golombRiceAdaptationStatistics, (sizeof(UInt) * RExt__GOLOMB_RICE_ADAPTATION_STATISTICS_SETS)); |
---|
1764 | } |
---|
1765 | |
---|
1766 | /*! |
---|
1767 | **************************************************************************** |
---|
1768 | * \brief |
---|
1769 | * estimate bit cost for each CBP bit |
---|
1770 | **************************************************************************** |
---|
1771 | */ |
---|
1772 | Void TEncSbac::estCBFBit( estBitsSbacStruct* pcEstBitsSbac ) |
---|
1773 | { |
---|
1774 | ContextModel *pCtx = m_cCUQtCbfSCModel.get( 0 ); |
---|
1775 | |
---|
1776 | for( UInt uiCtxInc = 0; uiCtxInc < (NUM_QT_CBF_CTX_SETS * NUM_QT_CBF_CTX_PER_SET); uiCtxInc++ ) |
---|
1777 | { |
---|
1778 | pcEstBitsSbac->blockCbpBits[ uiCtxInc ][ 0 ] = pCtx[ uiCtxInc ].getEntropyBits( 0 ); |
---|
1779 | pcEstBitsSbac->blockCbpBits[ uiCtxInc ][ 1 ] = pCtx[ uiCtxInc ].getEntropyBits( 1 ); |
---|
1780 | } |
---|
1781 | |
---|
1782 | pCtx = m_cCUQtRootCbfSCModel.get( 0 ); |
---|
1783 | |
---|
1784 | for( UInt uiCtxInc = 0; uiCtxInc < 4; uiCtxInc++ ) |
---|
1785 | { |
---|
1786 | pcEstBitsSbac->blockRootCbpBits[ uiCtxInc ][ 0 ] = pCtx[ uiCtxInc ].getEntropyBits( 0 ); |
---|
1787 | pcEstBitsSbac->blockRootCbpBits[ uiCtxInc ][ 1 ] = pCtx[ uiCtxInc ].getEntropyBits( 1 ); |
---|
1788 | } |
---|
1789 | } |
---|
1790 | |
---|
1791 | |
---|
1792 | /*! |
---|
1793 | **************************************************************************** |
---|
1794 | * \brief |
---|
1795 | * estimate SAMBAC bit cost for significant coefficient group map |
---|
1796 | **************************************************************************** |
---|
1797 | */ |
---|
1798 | Void TEncSbac::estSignificantCoeffGroupMapBit( estBitsSbacStruct* pcEstBitsSbac, ChannelType chType ) |
---|
1799 | { |
---|
1800 | Int firstCtx = 0, numCtx = NUM_SIG_CG_FLAG_CTX; |
---|
1801 | |
---|
1802 | for ( Int ctxIdx = firstCtx; ctxIdx < firstCtx + numCtx; ctxIdx++ ) |
---|
1803 | { |
---|
1804 | for( UInt uiBin = 0; uiBin < 2; uiBin++ ) |
---|
1805 | { |
---|
1806 | pcEstBitsSbac->significantCoeffGroupBits[ ctxIdx ][ uiBin ] = m_cCUSigCoeffGroupSCModel.get( 0, chType, ctxIdx ).getEntropyBits( uiBin ); |
---|
1807 | } |
---|
1808 | } |
---|
1809 | } |
---|
1810 | |
---|
1811 | |
---|
1812 | /*! |
---|
1813 | **************************************************************************** |
---|
1814 | * \brief |
---|
1815 | * estimate SAMBAC bit cost for significant coefficient map |
---|
1816 | **************************************************************************** |
---|
1817 | */ |
---|
1818 | Void TEncSbac::estSignificantMapBit( estBitsSbacStruct* pcEstBitsSbac, Int width, Int height, ChannelType chType ) |
---|
1819 | { |
---|
1820 | //-------------------------------------------------------------------------------------------------- |
---|
1821 | |
---|
1822 | //set up the number of channels and context variables |
---|
1823 | |
---|
1824 | const UInt firstComponent = ((isLuma(chType)) ? (COMPONENT_Y) : (COMPONENT_Cb)); |
---|
1825 | const UInt lastComponent = ((isLuma(chType)) ? (COMPONENT_Y) : (COMPONENT_Cb)); |
---|
1826 | |
---|
1827 | //---------------------------------------------------------- |
---|
1828 | |
---|
1829 | Int firstCtx = MAX_INT; |
---|
1830 | Int numCtx = MAX_INT; |
---|
1831 | |
---|
1832 | if ((width == 4) && (height == 4)) |
---|
1833 | { |
---|
1834 | firstCtx = significanceMapContextSetStart[chType][CONTEXT_TYPE_4x4]; |
---|
1835 | numCtx = significanceMapContextSetSize [chType][CONTEXT_TYPE_4x4]; |
---|
1836 | } |
---|
1837 | else if ((width == 8) && (height == 8)) |
---|
1838 | { |
---|
1839 | firstCtx = significanceMapContextSetStart[chType][CONTEXT_TYPE_8x8]; |
---|
1840 | numCtx = significanceMapContextSetSize [chType][CONTEXT_TYPE_8x8]; |
---|
1841 | } |
---|
1842 | else |
---|
1843 | { |
---|
1844 | firstCtx = significanceMapContextSetStart[chType][CONTEXT_TYPE_NxN]; |
---|
1845 | numCtx = significanceMapContextSetSize [chType][CONTEXT_TYPE_NxN]; |
---|
1846 | } |
---|
1847 | |
---|
1848 | //-------------------------------------------------------------------------------------------------- |
---|
1849 | |
---|
1850 | //fill the data for the significace map |
---|
1851 | |
---|
1852 | for (UInt component = firstComponent; component <= lastComponent; component++) |
---|
1853 | { |
---|
1854 | const UInt contextOffset = getSignificanceMapContextOffset(ComponentID(component)); |
---|
1855 | |
---|
1856 | if (firstCtx > 0) |
---|
1857 | { |
---|
1858 | for( UInt bin = 0; bin < 2; bin++ ) //always get the DC |
---|
1859 | { |
---|
1860 | pcEstBitsSbac->significantBits[ contextOffset ][ bin ] = m_cCUSigSCModel.get( 0, 0, contextOffset ).getEntropyBits( bin ); |
---|
1861 | } |
---|
1862 | } |
---|
1863 | |
---|
1864 | // This could be made optional, but would require this function to have knowledge of whether the |
---|
1865 | // TU is transform-skipped or transquant-bypassed and whether the SPS flag is set |
---|
1866 | for( UInt bin = 0; bin < 2; bin++ ) |
---|
1867 | { |
---|
1868 | const Int ctxIdx = significanceMapContextSetStart[chType][CONTEXT_TYPE_SINGLE]; |
---|
1869 | pcEstBitsSbac->significantBits[ contextOffset + ctxIdx ][ bin ] = m_cCUSigSCModel.get( 0, 0, (contextOffset + ctxIdx) ).getEntropyBits( bin ); |
---|
1870 | } |
---|
1871 | |
---|
1872 | for ( Int ctxIdx = firstCtx; ctxIdx < firstCtx + numCtx; ctxIdx++ ) |
---|
1873 | { |
---|
1874 | for( UInt uiBin = 0; uiBin < 2; uiBin++ ) |
---|
1875 | { |
---|
1876 | pcEstBitsSbac->significantBits[ contextOffset + ctxIdx ][ uiBin ] = m_cCUSigSCModel.get( 0, 0, (contextOffset + ctxIdx) ).getEntropyBits( uiBin ); |
---|
1877 | } |
---|
1878 | } |
---|
1879 | } |
---|
1880 | |
---|
1881 | //-------------------------------------------------------------------------------------------------- |
---|
1882 | } |
---|
1883 | |
---|
1884 | |
---|
1885 | /*! |
---|
1886 | **************************************************************************** |
---|
1887 | * \brief |
---|
1888 | * estimate bit cost of significant coefficient |
---|
1889 | **************************************************************************** |
---|
1890 | */ |
---|
1891 | |
---|
1892 | Void TEncSbac::estLastSignificantPositionBit( estBitsSbacStruct* pcEstBitsSbac, Int width, Int height, ChannelType chType ) |
---|
1893 | { |
---|
1894 | //--------------------------------------------------------------------------------------------------. |
---|
1895 | |
---|
1896 | //set up the number of channels |
---|
1897 | |
---|
1898 | const UInt firstComponent = ((isLuma(chType)) ? (COMPONENT_Y) : (COMPONENT_Cb)); |
---|
1899 | const UInt lastComponent = ((isLuma(chType)) ? (COMPONENT_Y) : (COMPONENT_Cb)); |
---|
1900 | |
---|
1901 | //-------------------------------------------------------------------------------------------------- |
---|
1902 | |
---|
1903 | //fill the data for the last-significant-coefficient position |
---|
1904 | |
---|
1905 | for (UInt componentIndex = firstComponent; componentIndex <= lastComponent; componentIndex++) |
---|
1906 | { |
---|
1907 | const ComponentID component = ComponentID(componentIndex); |
---|
1908 | |
---|
1909 | Int iBitsX = 0, iBitsY = 0; |
---|
1910 | |
---|
1911 | Int blkSizeOffsetX, blkSizeOffsetY, shiftX, shiftY; |
---|
1912 | getLastSignificantContextParameters(ComponentID(component), width, height, blkSizeOffsetX, blkSizeOffsetY, shiftX, shiftY); |
---|
1913 | |
---|
1914 | Int ctx; |
---|
1915 | |
---|
1916 | const ChannelType channelType = toChannelType(ComponentID(component)); |
---|
1917 | |
---|
1918 | ContextModel *const pCtxX = m_cCuCtxLastX.get( 0, channelType ); |
---|
1919 | ContextModel *const pCtxY = m_cCuCtxLastY.get( 0, channelType ); |
---|
1920 | Int *const lastXBitsArray = pcEstBitsSbac->lastXBits[channelType]; |
---|
1921 | Int *const lastYBitsArray = pcEstBitsSbac->lastYBits[channelType]; |
---|
1922 | |
---|
1923 | //------------------------------------------------ |
---|
1924 | |
---|
1925 | //X-coordinate |
---|
1926 | |
---|
1927 | for (ctx = 0; ctx < g_uiGroupIdx[ width - 1 ]; ctx++) |
---|
1928 | { |
---|
1929 | Int ctxOffset = blkSizeOffsetX + (ctx >>shiftX); |
---|
1930 | lastXBitsArray[ ctx ] = iBitsX + pCtxX[ ctxOffset ].getEntropyBits( 0 ); |
---|
1931 | iBitsX += pCtxX[ ctxOffset ].getEntropyBits( 1 ); |
---|
1932 | } |
---|
1933 | |
---|
1934 | lastXBitsArray[ctx] = iBitsX; |
---|
1935 | |
---|
1936 | //------------------------------------------------ |
---|
1937 | |
---|
1938 | //Y-coordinate |
---|
1939 | |
---|
1940 | for (ctx = 0; ctx < g_uiGroupIdx[ height - 1 ]; ctx++) |
---|
1941 | { |
---|
1942 | Int ctxOffset = blkSizeOffsetY + (ctx >>shiftY); |
---|
1943 | lastYBitsArray[ ctx ] = iBitsY + pCtxY[ ctxOffset ].getEntropyBits( 0 ); |
---|
1944 | iBitsY += pCtxY[ ctxOffset ].getEntropyBits( 1 ); |
---|
1945 | } |
---|
1946 | |
---|
1947 | lastYBitsArray[ctx] = iBitsY; |
---|
1948 | |
---|
1949 | } //end of component loop |
---|
1950 | |
---|
1951 | //-------------------------------------------------------------------------------------------------- |
---|
1952 | } |
---|
1953 | |
---|
1954 | |
---|
1955 | /*! |
---|
1956 | **************************************************************************** |
---|
1957 | * \brief |
---|
1958 | * estimate bit cost of significant coefficient |
---|
1959 | **************************************************************************** |
---|
1960 | */ |
---|
1961 | Void TEncSbac::estSignificantCoefficientsBit( estBitsSbacStruct* pcEstBitsSbac, ChannelType chType ) |
---|
1962 | { |
---|
1963 | ContextModel *ctxOne = m_cCUOneSCModel.get(0, 0); |
---|
1964 | ContextModel *ctxAbs = m_cCUAbsSCModel.get(0, 0); |
---|
1965 | |
---|
1966 | const UInt oneStartIndex = ((isLuma(chType)) ? (0) : (NUM_ONE_FLAG_CTX_LUMA)); |
---|
1967 | const UInt oneStopIndex = ((isLuma(chType)) ? (NUM_ONE_FLAG_CTX_LUMA) : (NUM_ONE_FLAG_CTX)); |
---|
1968 | const UInt absStartIndex = ((isLuma(chType)) ? (0) : (NUM_ABS_FLAG_CTX_LUMA)); |
---|
1969 | const UInt absStopIndex = ((isLuma(chType)) ? (NUM_ABS_FLAG_CTX_LUMA) : (NUM_ABS_FLAG_CTX)); |
---|
1970 | |
---|
1971 | for (Int ctxIdx = oneStartIndex; ctxIdx < oneStopIndex; ctxIdx++) |
---|
1972 | { |
---|
1973 | pcEstBitsSbac->m_greaterOneBits[ ctxIdx ][ 0 ] = ctxOne[ ctxIdx ].getEntropyBits( 0 ); |
---|
1974 | pcEstBitsSbac->m_greaterOneBits[ ctxIdx ][ 1 ] = ctxOne[ ctxIdx ].getEntropyBits( 1 ); |
---|
1975 | } |
---|
1976 | |
---|
1977 | for (Int ctxIdx = absStartIndex; ctxIdx < absStopIndex; ctxIdx++) |
---|
1978 | { |
---|
1979 | pcEstBitsSbac->m_levelAbsBits[ ctxIdx ][ 0 ] = ctxAbs[ ctxIdx ].getEntropyBits( 0 ); |
---|
1980 | pcEstBitsSbac->m_levelAbsBits[ ctxIdx ][ 1 ] = ctxAbs[ ctxIdx ].getEntropyBits( 1 ); |
---|
1981 | } |
---|
1982 | } |
---|
1983 | |
---|
1984 | /** |
---|
1985 | - Initialize our context information from the nominated source. |
---|
1986 | . |
---|
1987 | \param pSrc From where to copy context information. |
---|
1988 | */ |
---|
1989 | Void TEncSbac::xCopyContextsFrom( const TEncSbac* pSrc ) |
---|
1990 | { |
---|
1991 | memcpy(m_contextModels, pSrc->m_contextModels, m_numContextModels*sizeof(m_contextModels[0])); |
---|
1992 | memcpy(m_golombRiceAdaptationStatistics, pSrc->m_golombRiceAdaptationStatistics, (sizeof(UInt) * RExt__GOLOMB_RICE_ADAPTATION_STATISTICS_SETS)); |
---|
1993 | } |
---|
1994 | |
---|
1995 | Void TEncSbac::loadContexts ( const TEncSbac* pSrc) |
---|
1996 | { |
---|
1997 | xCopyContextsFrom(pSrc); |
---|
1998 | } |
---|
1999 | |
---|
2000 | /** Performs CABAC encoding of the explicit RDPCM mode |
---|
2001 | * \param rTu current TU data structure |
---|
2002 | * \param compID component identifier |
---|
2003 | */ |
---|
2004 | Void TEncSbac::codeExplicitRdpcmMode( TComTU &rTu, const ComponentID compID ) |
---|
2005 | { |
---|
2006 | TComDataCU *cu = rTu.getCU(); |
---|
2007 | const TComRectangle &rect = rTu.getRect(compID); |
---|
2008 | const UInt absPartIdx = rTu.GetAbsPartIdxTU(compID); |
---|
2009 | const UInt tuHeight = g_aucConvertToBit[rect.height]; |
---|
2010 | const UInt tuWidth = g_aucConvertToBit[rect.width]; |
---|
2011 | |
---|
2012 | assert(tuHeight == tuWidth); |
---|
2013 | assert(tuHeight < 4); |
---|
2014 | |
---|
2015 | UInt explicitRdpcmMode = cu->getExplicitRdpcmMode(compID, absPartIdx); |
---|
2016 | |
---|
2017 | if( explicitRdpcmMode == RDPCM_OFF ) |
---|
2018 | { |
---|
2019 | m_pcBinIf->encodeBin (0, m_explicitRdpcmFlagSCModel.get (0, toChannelType(compID), 0)); |
---|
2020 | } |
---|
2021 | else if( explicitRdpcmMode == RDPCM_HOR || explicitRdpcmMode == RDPCM_VER ) |
---|
2022 | { |
---|
2023 | m_pcBinIf->encodeBin (1, m_explicitRdpcmFlagSCModel.get (0, toChannelType(compID), 0)); |
---|
2024 | if(explicitRdpcmMode == RDPCM_HOR) |
---|
2025 | { |
---|
2026 | m_pcBinIf->encodeBin ( 0, m_explicitRdpcmDirSCModel.get(0, toChannelType(compID), 0)); |
---|
2027 | } |
---|
2028 | else |
---|
2029 | { |
---|
2030 | m_pcBinIf->encodeBin ( 1, m_explicitRdpcmDirSCModel.get(0, toChannelType(compID), 0)); |
---|
2031 | } |
---|
2032 | } |
---|
2033 | else |
---|
2034 | { |
---|
2035 | assert(0); |
---|
2036 | } |
---|
2037 | } |
---|
2038 | |
---|
2039 | #if SVC_EXTENSION |
---|
2040 | Void TEncSbac::codeSliceHeaderExtn( TComSlice* pSlice, Int shBitsWrittenTillNow ) |
---|
2041 | { |
---|
2042 | assert (0); |
---|
2043 | return; |
---|
2044 | } |
---|
2045 | #endif |
---|
2046 | |
---|
2047 | //! \} |
---|