1 | /* The copyright in this software is being made available under the BSD |
---|
2 | * License, included below. This software may be subject to other third party |
---|
3 | * and contributor rights, including patent rights, and no such rights are |
---|
4 | * granted under this license. |
---|
5 | * |
---|
6 | * Copyright (c) 2010-2013, ITU/ISO/IEC |
---|
7 | * All rights reserved. |
---|
8 | * |
---|
9 | * Redistribution and use in source and binary forms, with or without |
---|
10 | * modification, are permitted provided that the following conditions are met: |
---|
11 | * |
---|
12 | * * Redistributions of source code must retain the above copyright notice, |
---|
13 | * this list of conditions and the following disclaimer. |
---|
14 | * * Redistributions in binary form must reproduce the above copyright notice, |
---|
15 | * this list of conditions and the following disclaimer in the documentation |
---|
16 | * and/or other materials provided with the distribution. |
---|
17 | * * Neither the name of the ITU/ISO/IEC nor the names of its contributors may |
---|
18 | * be used to endorse or promote products derived from this software without |
---|
19 | * specific prior written permission. |
---|
20 | * |
---|
21 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
---|
22 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
---|
23 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
---|
24 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS |
---|
25 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
---|
26 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
---|
27 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
---|
28 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
---|
29 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
---|
30 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF |
---|
31 | * THE POSSIBILITY OF SUCH DAMAGE. |
---|
32 | */ |
---|
33 | |
---|
34 | /** \file TEncSbac.cpp |
---|
35 | \brief SBAC encoder class |
---|
36 | */ |
---|
37 | |
---|
38 | #include "TEncTop.h" |
---|
39 | #include "TEncSbac.h" |
---|
40 | |
---|
41 | #include <map> |
---|
42 | #include <algorithm> |
---|
43 | |
---|
44 | //! \ingroup TLibEncoder |
---|
45 | //! \{ |
---|
46 | |
---|
47 | // ==================================================================================================================== |
---|
48 | // Constructor / destructor / create / destroy |
---|
49 | // ==================================================================================================================== |
---|
50 | |
---|
51 | TEncSbac::TEncSbac() |
---|
52 | // new structure here |
---|
53 | : m_pcBitIf ( NULL ) |
---|
54 | , m_pcSlice ( NULL ) |
---|
55 | , m_pcBinIf ( NULL ) |
---|
56 | , m_uiCoeffCost ( 0 ) |
---|
57 | , m_numContextModels ( 0 ) |
---|
58 | , m_cCUSplitFlagSCModel ( 1, 1, NUM_SPLIT_FLAG_CTX , m_contextModels + m_numContextModels, m_numContextModels ) |
---|
59 | , m_cCUSkipFlagSCModel ( 1, 1, NUM_SKIP_FLAG_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
60 | , m_cCUMergeFlagExtSCModel ( 1, 1, NUM_MERGE_FLAG_EXT_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
61 | , m_cCUMergeIdxExtSCModel ( 1, 1, NUM_MERGE_IDX_EXT_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
62 | , m_cCUPartSizeSCModel ( 1, 1, NUM_PART_SIZE_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
63 | , m_cCUPredModeSCModel ( 1, 1, NUM_PRED_MODE_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
64 | , m_cCUIntraPredSCModel ( 1, 1, NUM_ADI_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
65 | , m_cCUChromaPredSCModel ( 1, 1, NUM_CHROMA_PRED_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
66 | , m_cCUDeltaQpSCModel ( 1, 1, NUM_DELTA_QP_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
67 | , m_cCUInterDirSCModel ( 1, 1, NUM_INTER_DIR_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
68 | , m_cCURefPicSCModel ( 1, 1, NUM_REF_NO_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
69 | , m_cCUMvdSCModel ( 1, 1, NUM_MV_RES_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
70 | , m_cCUQtCbfSCModel ( 1, 2, NUM_QT_CBF_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
71 | , m_cCUTransSubdivFlagSCModel ( 1, 1, NUM_TRANS_SUBDIV_FLAG_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
72 | , m_cCUQtRootCbfSCModel ( 1, 1, NUM_QT_ROOT_CBF_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
73 | , m_cCUSigCoeffGroupSCModel ( 1, 2, NUM_SIG_CG_FLAG_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
74 | , m_cCUSigSCModel ( 1, 1, NUM_SIG_FLAG_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
75 | , m_cCuCtxLastX ( 1, 2, NUM_CTX_LAST_FLAG_XY , m_contextModels + m_numContextModels, m_numContextModels) |
---|
76 | , m_cCuCtxLastY ( 1, 2, NUM_CTX_LAST_FLAG_XY , m_contextModels + m_numContextModels, m_numContextModels) |
---|
77 | , m_cCUOneSCModel ( 1, 1, NUM_ONE_FLAG_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
78 | , m_cCUAbsSCModel ( 1, 1, NUM_ABS_FLAG_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
79 | , m_cMVPIdxSCModel ( 1, 1, NUM_MVP_IDX_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
80 | , m_cCUAMPSCModel ( 1, 1, NUM_CU_AMP_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
81 | , m_cSaoMergeSCModel ( 1, 1, NUM_SAO_MERGE_FLAG_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
82 | , m_cSaoTypeIdxSCModel ( 1, 1, NUM_SAO_TYPE_IDX_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
83 | , m_cTransformSkipSCModel ( 1, 2, NUM_TRANSFORMSKIP_FLAG_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
84 | , m_CUTransquantBypassFlagSCModel( 1, 1, NUM_CU_TRANSQUANT_BYPASS_FLAG_CTX, m_contextModels + m_numContextModels, m_numContextModels) |
---|
85 | { |
---|
86 | assert( m_numContextModels <= MAX_NUM_CTX_MOD ); |
---|
87 | } |
---|
88 | |
---|
89 | TEncSbac::~TEncSbac() |
---|
90 | { |
---|
91 | } |
---|
92 | |
---|
93 | // ==================================================================================================================== |
---|
94 | // Public member functions |
---|
95 | // ==================================================================================================================== |
---|
96 | |
---|
97 | Void TEncSbac::resetEntropy () |
---|
98 | { |
---|
99 | Int iQp = m_pcSlice->getSliceQp(); |
---|
100 | SliceType eSliceType = m_pcSlice->getSliceType(); |
---|
101 | |
---|
102 | Int encCABACTableIdx = m_pcSlice->getPPS()->getEncCABACTableIdx(); |
---|
103 | if (!m_pcSlice->isIntra() && (encCABACTableIdx==B_SLICE || encCABACTableIdx==P_SLICE) && m_pcSlice->getPPS()->getCabacInitPresentFlag()) |
---|
104 | { |
---|
105 | eSliceType = (SliceType) encCABACTableIdx; |
---|
106 | } |
---|
107 | |
---|
108 | m_cCUSplitFlagSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_SPLIT_FLAG ); |
---|
109 | |
---|
110 | m_cCUSkipFlagSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_SKIP_FLAG ); |
---|
111 | m_cCUMergeFlagExtSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_MERGE_FLAG_EXT); |
---|
112 | m_cCUMergeIdxExtSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_MERGE_IDX_EXT); |
---|
113 | m_cCUPartSizeSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_PART_SIZE ); |
---|
114 | m_cCUAMPSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_CU_AMP_POS ); |
---|
115 | m_cCUPredModeSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_PRED_MODE ); |
---|
116 | m_cCUIntraPredSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_INTRA_PRED_MODE ); |
---|
117 | m_cCUChromaPredSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_CHROMA_PRED_MODE ); |
---|
118 | m_cCUInterDirSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_INTER_DIR ); |
---|
119 | m_cCUMvdSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_MVD ); |
---|
120 | m_cCURefPicSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_REF_PIC ); |
---|
121 | m_cCUDeltaQpSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_DQP ); |
---|
122 | m_cCUQtCbfSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_QT_CBF ); |
---|
123 | m_cCUQtRootCbfSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_QT_ROOT_CBF ); |
---|
124 | m_cCUSigCoeffGroupSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_SIG_CG_FLAG ); |
---|
125 | m_cCUSigSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_SIG_FLAG ); |
---|
126 | m_cCuCtxLastX.initBuffer ( eSliceType, iQp, (UChar*)INIT_LAST ); |
---|
127 | m_cCuCtxLastY.initBuffer ( eSliceType, iQp, (UChar*)INIT_LAST ); |
---|
128 | m_cCUOneSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_ONE_FLAG ); |
---|
129 | m_cCUAbsSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_ABS_FLAG ); |
---|
130 | m_cMVPIdxSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_MVP_IDX ); |
---|
131 | m_cCUTransSubdivFlagSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_TRANS_SUBDIV_FLAG ); |
---|
132 | m_cSaoMergeSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_SAO_MERGE_FLAG ); |
---|
133 | m_cSaoTypeIdxSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_SAO_TYPE_IDX ); |
---|
134 | m_cTransformSkipSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_TRANSFORMSKIP_FLAG ); |
---|
135 | m_CUTransquantBypassFlagSCModel.initBuffer( eSliceType, iQp, (UChar*)INIT_CU_TRANSQUANT_BYPASS_FLAG ); |
---|
136 | // new structure |
---|
137 | m_uiLastQp = iQp; |
---|
138 | |
---|
139 | m_pcBinIf->start(); |
---|
140 | |
---|
141 | return; |
---|
142 | } |
---|
143 | |
---|
144 | /** The function does the following: |
---|
145 | * If current slice type is P/B then it determines the distance of initialisation type 1 and 2 from the current CABAC states and |
---|
146 | * stores the index of the closest table. This index is used for the next P/B slice when cabac_init_present_flag is true. |
---|
147 | */ |
---|
148 | Void TEncSbac::determineCabacInitIdx() |
---|
149 | { |
---|
150 | Int qp = m_pcSlice->getSliceQp(); |
---|
151 | |
---|
152 | if (!m_pcSlice->isIntra()) |
---|
153 | { |
---|
154 | SliceType aSliceTypeChoices[] = {B_SLICE, P_SLICE}; |
---|
155 | |
---|
156 | UInt bestCost = MAX_UINT; |
---|
157 | SliceType bestSliceType = aSliceTypeChoices[0]; |
---|
158 | for (UInt idx=0; idx<2; idx++) |
---|
159 | { |
---|
160 | UInt curCost = 0; |
---|
161 | SliceType curSliceType = aSliceTypeChoices[idx]; |
---|
162 | |
---|
163 | curCost = m_cCUSplitFlagSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_SPLIT_FLAG ); |
---|
164 | curCost += m_cCUSkipFlagSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_SKIP_FLAG ); |
---|
165 | curCost += m_cCUMergeFlagExtSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_MERGE_FLAG_EXT); |
---|
166 | curCost += m_cCUMergeIdxExtSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_MERGE_IDX_EXT); |
---|
167 | curCost += m_cCUPartSizeSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_PART_SIZE ); |
---|
168 | curCost += m_cCUAMPSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_CU_AMP_POS ); |
---|
169 | curCost += m_cCUPredModeSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_PRED_MODE ); |
---|
170 | curCost += m_cCUIntraPredSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_INTRA_PRED_MODE ); |
---|
171 | curCost += m_cCUChromaPredSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_CHROMA_PRED_MODE ); |
---|
172 | curCost += m_cCUInterDirSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_INTER_DIR ); |
---|
173 | curCost += m_cCUMvdSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_MVD ); |
---|
174 | curCost += m_cCURefPicSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_REF_PIC ); |
---|
175 | curCost += m_cCUDeltaQpSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_DQP ); |
---|
176 | curCost += m_cCUQtCbfSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_QT_CBF ); |
---|
177 | curCost += m_cCUQtRootCbfSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_QT_ROOT_CBF ); |
---|
178 | curCost += m_cCUSigCoeffGroupSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_SIG_CG_FLAG ); |
---|
179 | curCost += m_cCUSigSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_SIG_FLAG ); |
---|
180 | curCost += m_cCuCtxLastX.calcCost ( curSliceType, qp, (UChar*)INIT_LAST ); |
---|
181 | curCost += m_cCuCtxLastY.calcCost ( curSliceType, qp, (UChar*)INIT_LAST ); |
---|
182 | curCost += m_cCUOneSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_ONE_FLAG ); |
---|
183 | curCost += m_cCUAbsSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_ABS_FLAG ); |
---|
184 | curCost += m_cMVPIdxSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_MVP_IDX ); |
---|
185 | curCost += m_cCUTransSubdivFlagSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_TRANS_SUBDIV_FLAG ); |
---|
186 | curCost += m_cSaoMergeSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_SAO_MERGE_FLAG ); |
---|
187 | curCost += m_cSaoTypeIdxSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_SAO_TYPE_IDX ); |
---|
188 | curCost += m_cTransformSkipSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_TRANSFORMSKIP_FLAG ); |
---|
189 | curCost += m_CUTransquantBypassFlagSCModel.calcCost( curSliceType, qp, (UChar*)INIT_CU_TRANSQUANT_BYPASS_FLAG ); |
---|
190 | if (curCost < bestCost) |
---|
191 | { |
---|
192 | bestSliceType = curSliceType; |
---|
193 | bestCost = curCost; |
---|
194 | } |
---|
195 | } |
---|
196 | m_pcSlice->getPPS()->setEncCABACTableIdx( bestSliceType ); |
---|
197 | } |
---|
198 | else |
---|
199 | { |
---|
200 | m_pcSlice->getPPS()->setEncCABACTableIdx( I_SLICE ); |
---|
201 | } |
---|
202 | } |
---|
203 | |
---|
204 | |
---|
205 | /** The function does the followng: Write out terminate bit. Flush CABAC. Intialize CABAC states. Start CABAC. |
---|
206 | */ |
---|
207 | Void TEncSbac::updateContextTables( SliceType eSliceType, Int iQp, Bool bExecuteFinish ) |
---|
208 | { |
---|
209 | m_pcBinIf->encodeBinTrm(1); |
---|
210 | if (bExecuteFinish) m_pcBinIf->finish(); |
---|
211 | m_cCUSplitFlagSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_SPLIT_FLAG ); |
---|
212 | |
---|
213 | m_cCUSkipFlagSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_SKIP_FLAG ); |
---|
214 | m_cCUMergeFlagExtSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_MERGE_FLAG_EXT); |
---|
215 | m_cCUMergeIdxExtSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_MERGE_IDX_EXT); |
---|
216 | m_cCUPartSizeSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_PART_SIZE ); |
---|
217 | m_cCUAMPSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_CU_AMP_POS ); |
---|
218 | m_cCUPredModeSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_PRED_MODE ); |
---|
219 | m_cCUIntraPredSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_INTRA_PRED_MODE ); |
---|
220 | m_cCUChromaPredSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_CHROMA_PRED_MODE ); |
---|
221 | m_cCUInterDirSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_INTER_DIR ); |
---|
222 | m_cCUMvdSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_MVD ); |
---|
223 | m_cCURefPicSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_REF_PIC ); |
---|
224 | m_cCUDeltaQpSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_DQP ); |
---|
225 | m_cCUQtCbfSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_QT_CBF ); |
---|
226 | m_cCUQtRootCbfSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_QT_ROOT_CBF ); |
---|
227 | m_cCUSigCoeffGroupSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_SIG_CG_FLAG ); |
---|
228 | m_cCUSigSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_SIG_FLAG ); |
---|
229 | m_cCuCtxLastX.initBuffer ( eSliceType, iQp, (UChar*)INIT_LAST ); |
---|
230 | m_cCuCtxLastY.initBuffer ( eSliceType, iQp, (UChar*)INIT_LAST ); |
---|
231 | m_cCUOneSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_ONE_FLAG ); |
---|
232 | m_cCUAbsSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_ABS_FLAG ); |
---|
233 | m_cMVPIdxSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_MVP_IDX ); |
---|
234 | m_cCUTransSubdivFlagSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_TRANS_SUBDIV_FLAG ); |
---|
235 | m_cSaoMergeSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_SAO_MERGE_FLAG ); |
---|
236 | m_cSaoTypeIdxSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_SAO_TYPE_IDX ); |
---|
237 | m_cTransformSkipSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_TRANSFORMSKIP_FLAG ); |
---|
238 | m_CUTransquantBypassFlagSCModel.initBuffer( eSliceType, iQp, (UChar*)INIT_CU_TRANSQUANT_BYPASS_FLAG ); |
---|
239 | m_pcBinIf->start(); |
---|
240 | } |
---|
241 | |
---|
242 | Void TEncSbac::codeVPS( TComVPS* pcVPS ) |
---|
243 | { |
---|
244 | assert (0); |
---|
245 | return; |
---|
246 | } |
---|
247 | |
---|
248 | Void TEncSbac::codeSPS( TComSPS* pcSPS ) |
---|
249 | { |
---|
250 | assert (0); |
---|
251 | return; |
---|
252 | } |
---|
253 | |
---|
254 | Void TEncSbac::codePPS( TComPPS* pcPPS ) |
---|
255 | { |
---|
256 | assert (0); |
---|
257 | return; |
---|
258 | } |
---|
259 | |
---|
260 | Void TEncSbac::codeSliceHeader( TComSlice* pcSlice ) |
---|
261 | { |
---|
262 | assert (0); |
---|
263 | return; |
---|
264 | } |
---|
265 | |
---|
266 | Void TEncSbac::codeTilesWPPEntryPoint( TComSlice* pSlice ) |
---|
267 | { |
---|
268 | assert (0); |
---|
269 | return; |
---|
270 | } |
---|
271 | |
---|
272 | Void TEncSbac::codeTerminatingBit( UInt uilsLast ) |
---|
273 | { |
---|
274 | m_pcBinIf->encodeBinTrm( uilsLast ); |
---|
275 | } |
---|
276 | |
---|
277 | Void TEncSbac::codeSliceFinish() |
---|
278 | { |
---|
279 | m_pcBinIf->finish(); |
---|
280 | } |
---|
281 | |
---|
282 | Void TEncSbac::xWriteUnarySymbol( UInt uiSymbol, ContextModel* pcSCModel, Int iOffset ) |
---|
283 | { |
---|
284 | m_pcBinIf->encodeBin( uiSymbol ? 1 : 0, pcSCModel[0] ); |
---|
285 | |
---|
286 | if( 0 == uiSymbol) |
---|
287 | { |
---|
288 | return; |
---|
289 | } |
---|
290 | |
---|
291 | while( uiSymbol-- ) |
---|
292 | { |
---|
293 | m_pcBinIf->encodeBin( uiSymbol ? 1 : 0, pcSCModel[ iOffset ] ); |
---|
294 | } |
---|
295 | |
---|
296 | return; |
---|
297 | } |
---|
298 | |
---|
299 | Void TEncSbac::xWriteUnaryMaxSymbol( UInt uiSymbol, ContextModel* pcSCModel, Int iOffset, UInt uiMaxSymbol ) |
---|
300 | { |
---|
301 | if (uiMaxSymbol == 0) |
---|
302 | { |
---|
303 | return; |
---|
304 | } |
---|
305 | |
---|
306 | m_pcBinIf->encodeBin( uiSymbol ? 1 : 0, pcSCModel[ 0 ] ); |
---|
307 | |
---|
308 | if ( uiSymbol == 0 ) |
---|
309 | { |
---|
310 | return; |
---|
311 | } |
---|
312 | |
---|
313 | Bool bCodeLast = ( uiMaxSymbol > uiSymbol ); |
---|
314 | |
---|
315 | while( --uiSymbol ) |
---|
316 | { |
---|
317 | m_pcBinIf->encodeBin( 1, pcSCModel[ iOffset ] ); |
---|
318 | } |
---|
319 | if( bCodeLast ) |
---|
320 | { |
---|
321 | m_pcBinIf->encodeBin( 0, pcSCModel[ iOffset ] ); |
---|
322 | } |
---|
323 | |
---|
324 | return; |
---|
325 | } |
---|
326 | |
---|
327 | Void TEncSbac::xWriteEpExGolomb( UInt uiSymbol, UInt uiCount ) |
---|
328 | { |
---|
329 | UInt bins = 0; |
---|
330 | Int numBins = 0; |
---|
331 | |
---|
332 | while( uiSymbol >= (UInt)(1<<uiCount) ) |
---|
333 | { |
---|
334 | bins = 2 * bins + 1; |
---|
335 | numBins++; |
---|
336 | uiSymbol -= 1 << uiCount; |
---|
337 | uiCount ++; |
---|
338 | } |
---|
339 | bins = 2 * bins + 0; |
---|
340 | numBins++; |
---|
341 | |
---|
342 | bins = (bins << uiCount) | uiSymbol; |
---|
343 | numBins += uiCount; |
---|
344 | |
---|
345 | assert( numBins <= 32 ); |
---|
346 | m_pcBinIf->encodeBinsEP( bins, numBins ); |
---|
347 | } |
---|
348 | |
---|
349 | /** Coding of coeff_abs_level_minus3 |
---|
350 | * \param uiSymbol value of coeff_abs_level_minus3 |
---|
351 | * \param ruiGoRiceParam reference to Rice parameter |
---|
352 | * \returns Void |
---|
353 | */ |
---|
354 | Void TEncSbac::xWriteCoefRemainExGolomb ( UInt symbol, UInt &rParam ) |
---|
355 | { |
---|
356 | Int codeNumber = (Int)symbol; |
---|
357 | UInt length; |
---|
358 | if (codeNumber < (COEF_REMAIN_BIN_REDUCTION << rParam)) |
---|
359 | { |
---|
360 | length = codeNumber>>rParam; |
---|
361 | m_pcBinIf->encodeBinsEP( (1<<(length+1))-2 , length+1); |
---|
362 | m_pcBinIf->encodeBinsEP((codeNumber%(1<<rParam)),rParam); |
---|
363 | } |
---|
364 | else |
---|
365 | { |
---|
366 | length = rParam; |
---|
367 | codeNumber = codeNumber - ( COEF_REMAIN_BIN_REDUCTION << rParam); |
---|
368 | while (codeNumber >= (1<<length)) |
---|
369 | { |
---|
370 | codeNumber -= (1<<(length++)); |
---|
371 | } |
---|
372 | m_pcBinIf->encodeBinsEP((1<<(COEF_REMAIN_BIN_REDUCTION+length+1-rParam))-2,COEF_REMAIN_BIN_REDUCTION+length+1-rParam); |
---|
373 | m_pcBinIf->encodeBinsEP(codeNumber,length); |
---|
374 | } |
---|
375 | } |
---|
376 | |
---|
377 | // SBAC RD |
---|
378 | Void TEncSbac::load ( TEncSbac* pSrc) |
---|
379 | { |
---|
380 | this->xCopyFrom(pSrc); |
---|
381 | } |
---|
382 | |
---|
383 | Void TEncSbac::loadIntraDirModeLuma( TEncSbac* pSrc) |
---|
384 | { |
---|
385 | m_pcBinIf->copyState( pSrc->m_pcBinIf ); |
---|
386 | |
---|
387 | this->m_cCUIntraPredSCModel .copyFrom( &pSrc->m_cCUIntraPredSCModel ); |
---|
388 | } |
---|
389 | |
---|
390 | |
---|
391 | Void TEncSbac::store( TEncSbac* pDest) |
---|
392 | { |
---|
393 | pDest->xCopyFrom( this ); |
---|
394 | } |
---|
395 | |
---|
396 | |
---|
397 | Void TEncSbac::xCopyFrom( TEncSbac* pSrc ) |
---|
398 | { |
---|
399 | m_pcBinIf->copyState( pSrc->m_pcBinIf ); |
---|
400 | |
---|
401 | this->m_uiCoeffCost = pSrc->m_uiCoeffCost; |
---|
402 | this->m_uiLastQp = pSrc->m_uiLastQp; |
---|
403 | |
---|
404 | memcpy( m_contextModels, pSrc->m_contextModels, m_numContextModels * sizeof( ContextModel ) ); |
---|
405 | } |
---|
406 | |
---|
407 | Void TEncSbac::codeMVPIdx ( TComDataCU* pcCU, UInt uiAbsPartIdx, RefPicList eRefList ) |
---|
408 | { |
---|
409 | Int iSymbol = pcCU->getMVPIdx(eRefList, uiAbsPartIdx); |
---|
410 | Int iNum = AMVP_MAX_NUM_CANDS; |
---|
411 | |
---|
412 | xWriteUnaryMaxSymbol(iSymbol, m_cMVPIdxSCModel.get(0), 1, iNum-1); |
---|
413 | } |
---|
414 | |
---|
415 | Void TEncSbac::codePartSize( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth ) |
---|
416 | { |
---|
417 | PartSize eSize = pcCU->getPartitionSize( uiAbsPartIdx ); |
---|
418 | if ( pcCU->isIntra( uiAbsPartIdx ) ) |
---|
419 | { |
---|
420 | if( uiDepth == g_uiMaxCUDepth - g_uiAddCUDepth ) |
---|
421 | { |
---|
422 | m_pcBinIf->encodeBin( eSize == SIZE_2Nx2N? 1 : 0, m_cCUPartSizeSCModel.get( 0, 0, 0 ) ); |
---|
423 | } |
---|
424 | return; |
---|
425 | } |
---|
426 | |
---|
427 | switch(eSize) |
---|
428 | { |
---|
429 | case SIZE_2Nx2N: |
---|
430 | { |
---|
431 | m_pcBinIf->encodeBin( 1, m_cCUPartSizeSCModel.get( 0, 0, 0) ); |
---|
432 | break; |
---|
433 | } |
---|
434 | case SIZE_2NxN: |
---|
435 | case SIZE_2NxnU: |
---|
436 | case SIZE_2NxnD: |
---|
437 | { |
---|
438 | m_pcBinIf->encodeBin( 0, m_cCUPartSizeSCModel.get( 0, 0, 0) ); |
---|
439 | m_pcBinIf->encodeBin( 1, m_cCUPartSizeSCModel.get( 0, 0, 1) ); |
---|
440 | if ( pcCU->getSlice()->getSPS()->getAMPAcc( uiDepth ) ) |
---|
441 | { |
---|
442 | if (eSize == SIZE_2NxN) |
---|
443 | { |
---|
444 | m_pcBinIf->encodeBin(1, m_cCUAMPSCModel.get( 0, 0, 0 )); |
---|
445 | } |
---|
446 | else |
---|
447 | { |
---|
448 | m_pcBinIf->encodeBin(0, m_cCUAMPSCModel.get( 0, 0, 0 )); |
---|
449 | m_pcBinIf->encodeBinEP((eSize == SIZE_2NxnU? 0: 1)); |
---|
450 | } |
---|
451 | } |
---|
452 | break; |
---|
453 | } |
---|
454 | case SIZE_Nx2N: |
---|
455 | case SIZE_nLx2N: |
---|
456 | case SIZE_nRx2N: |
---|
457 | { |
---|
458 | m_pcBinIf->encodeBin( 0, m_cCUPartSizeSCModel.get( 0, 0, 0) ); |
---|
459 | m_pcBinIf->encodeBin( 0, m_cCUPartSizeSCModel.get( 0, 0, 1) ); |
---|
460 | if( uiDepth == g_uiMaxCUDepth - g_uiAddCUDepth && !( pcCU->getWidth(uiAbsPartIdx) == 8 && pcCU->getHeight(uiAbsPartIdx) == 8 ) ) |
---|
461 | { |
---|
462 | m_pcBinIf->encodeBin( 1, m_cCUPartSizeSCModel.get( 0, 0, 2) ); |
---|
463 | } |
---|
464 | if ( pcCU->getSlice()->getSPS()->getAMPAcc( uiDepth ) ) |
---|
465 | { |
---|
466 | if (eSize == SIZE_Nx2N) |
---|
467 | { |
---|
468 | m_pcBinIf->encodeBin(1, m_cCUAMPSCModel.get( 0, 0, 0 )); |
---|
469 | } |
---|
470 | else |
---|
471 | { |
---|
472 | m_pcBinIf->encodeBin(0, m_cCUAMPSCModel.get( 0, 0, 0 )); |
---|
473 | m_pcBinIf->encodeBinEP((eSize == SIZE_nLx2N? 0: 1)); |
---|
474 | } |
---|
475 | } |
---|
476 | break; |
---|
477 | } |
---|
478 | case SIZE_NxN: |
---|
479 | { |
---|
480 | if( uiDepth == g_uiMaxCUDepth - g_uiAddCUDepth && !( pcCU->getWidth(uiAbsPartIdx) == 8 && pcCU->getHeight(uiAbsPartIdx) == 8 ) ) |
---|
481 | { |
---|
482 | m_pcBinIf->encodeBin( 0, m_cCUPartSizeSCModel.get( 0, 0, 0) ); |
---|
483 | m_pcBinIf->encodeBin( 0, m_cCUPartSizeSCModel.get( 0, 0, 1) ); |
---|
484 | m_pcBinIf->encodeBin( 0, m_cCUPartSizeSCModel.get( 0, 0, 2) ); |
---|
485 | } |
---|
486 | break; |
---|
487 | } |
---|
488 | default: |
---|
489 | { |
---|
490 | assert(0); |
---|
491 | } |
---|
492 | } |
---|
493 | } |
---|
494 | |
---|
495 | /** code prediction mode |
---|
496 | * \param pcCU |
---|
497 | * \param uiAbsPartIdx |
---|
498 | * \returns Void |
---|
499 | */ |
---|
500 | Void TEncSbac::codePredMode( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
501 | { |
---|
502 | // get context function is here |
---|
503 | Int iPredMode = pcCU->getPredictionMode( uiAbsPartIdx ); |
---|
504 | m_pcBinIf->encodeBin( iPredMode == MODE_INTER ? 0 : 1, m_cCUPredModeSCModel.get( 0, 0, 0 ) ); |
---|
505 | } |
---|
506 | |
---|
507 | Void TEncSbac::codeCUTransquantBypassFlag( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
508 | { |
---|
509 | UInt uiSymbol = pcCU->getCUTransquantBypass(uiAbsPartIdx); |
---|
510 | m_pcBinIf->encodeBin( uiSymbol, m_CUTransquantBypassFlagSCModel.get( 0, 0, 0 ) ); |
---|
511 | } |
---|
512 | |
---|
513 | /** code skip flag |
---|
514 | * \param pcCU |
---|
515 | * \param uiAbsPartIdx |
---|
516 | * \returns Void |
---|
517 | */ |
---|
518 | Void TEncSbac::codeSkipFlag( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
519 | { |
---|
520 | // get context function is here |
---|
521 | UInt uiSymbol = pcCU->isSkipped( uiAbsPartIdx ) ? 1 : 0; |
---|
522 | UInt uiCtxSkip = pcCU->getCtxSkipFlag( uiAbsPartIdx ) ; |
---|
523 | m_pcBinIf->encodeBin( uiSymbol, m_cCUSkipFlagSCModel.get( 0, 0, uiCtxSkip ) ); |
---|
524 | DTRACE_CABAC_VL( g_nSymbolCounter++ ); |
---|
525 | DTRACE_CABAC_T( "\tSkipFlag" ); |
---|
526 | DTRACE_CABAC_T( "\tuiCtxSkip: "); |
---|
527 | DTRACE_CABAC_V( uiCtxSkip ); |
---|
528 | DTRACE_CABAC_T( "\tuiSymbol: "); |
---|
529 | DTRACE_CABAC_V( uiSymbol ); |
---|
530 | DTRACE_CABAC_T( "\n"); |
---|
531 | } |
---|
532 | |
---|
533 | /** code merge flag |
---|
534 | * \param pcCU |
---|
535 | * \param uiAbsPartIdx |
---|
536 | * \returns Void |
---|
537 | */ |
---|
538 | Void TEncSbac::codeMergeFlag( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
539 | { |
---|
540 | const UInt uiSymbol = pcCU->getMergeFlag( uiAbsPartIdx ) ? 1 : 0; |
---|
541 | m_pcBinIf->encodeBin( uiSymbol, *m_cCUMergeFlagExtSCModel.get( 0 ) ); |
---|
542 | |
---|
543 | DTRACE_CABAC_VL( g_nSymbolCounter++ ); |
---|
544 | DTRACE_CABAC_T( "\tMergeFlag: " ); |
---|
545 | DTRACE_CABAC_V( uiSymbol ); |
---|
546 | DTRACE_CABAC_T( "\tAddress: " ); |
---|
547 | DTRACE_CABAC_V( pcCU->getAddr() ); |
---|
548 | DTRACE_CABAC_T( "\tuiAbsPartIdx: " ); |
---|
549 | DTRACE_CABAC_V( uiAbsPartIdx ); |
---|
550 | DTRACE_CABAC_T( "\n" ); |
---|
551 | } |
---|
552 | |
---|
553 | /** code merge index |
---|
554 | * \param pcCU |
---|
555 | * \param uiAbsPartIdx |
---|
556 | * \returns Void |
---|
557 | */ |
---|
558 | Void TEncSbac::codeMergeIndex( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
559 | { |
---|
560 | UInt uiUnaryIdx = pcCU->getMergeIndex( uiAbsPartIdx ); |
---|
561 | UInt uiNumCand = pcCU->getSlice()->getMaxNumMergeCand(); |
---|
562 | if ( uiNumCand > 1 ) |
---|
563 | { |
---|
564 | for( UInt ui = 0; ui < uiNumCand - 1; ++ui ) |
---|
565 | { |
---|
566 | const UInt uiSymbol = ui == uiUnaryIdx ? 0 : 1; |
---|
567 | if ( ui==0 ) |
---|
568 | { |
---|
569 | m_pcBinIf->encodeBin( uiSymbol, m_cCUMergeIdxExtSCModel.get( 0, 0, 0 ) ); |
---|
570 | } |
---|
571 | else |
---|
572 | { |
---|
573 | m_pcBinIf->encodeBinEP( uiSymbol ); |
---|
574 | } |
---|
575 | if( uiSymbol == 0 ) |
---|
576 | { |
---|
577 | break; |
---|
578 | } |
---|
579 | } |
---|
580 | } |
---|
581 | DTRACE_CABAC_VL( g_nSymbolCounter++ ); |
---|
582 | DTRACE_CABAC_T( "\tparseMergeIndex()" ); |
---|
583 | DTRACE_CABAC_T( "\tuiMRGIdx= " ); |
---|
584 | DTRACE_CABAC_V( pcCU->getMergeIndex( uiAbsPartIdx ) ); |
---|
585 | DTRACE_CABAC_T( "\n" ); |
---|
586 | } |
---|
587 | |
---|
588 | Void TEncSbac::codeSplitFlag ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth ) |
---|
589 | { |
---|
590 | if( uiDepth == g_uiMaxCUDepth - g_uiAddCUDepth ) |
---|
591 | return; |
---|
592 | |
---|
593 | UInt uiCtx = pcCU->getCtxSplitFlag( uiAbsPartIdx, uiDepth ); |
---|
594 | UInt uiCurrSplitFlag = ( pcCU->getDepth( uiAbsPartIdx ) > uiDepth ) ? 1 : 0; |
---|
595 | |
---|
596 | assert( uiCtx < 3 ); |
---|
597 | m_pcBinIf->encodeBin( uiCurrSplitFlag, m_cCUSplitFlagSCModel.get( 0, 0, uiCtx ) ); |
---|
598 | DTRACE_CABAC_VL( g_nSymbolCounter++ ) |
---|
599 | DTRACE_CABAC_T( "\tSplitFlag\n" ) |
---|
600 | return; |
---|
601 | } |
---|
602 | |
---|
603 | Void TEncSbac::codeTransformSubdivFlag( UInt uiSymbol, UInt uiCtx ) |
---|
604 | { |
---|
605 | m_pcBinIf->encodeBin( uiSymbol, m_cCUTransSubdivFlagSCModel.get( 0, 0, uiCtx ) ); |
---|
606 | DTRACE_CABAC_VL( g_nSymbolCounter++ ) |
---|
607 | DTRACE_CABAC_T( "\tparseTransformSubdivFlag()" ) |
---|
608 | DTRACE_CABAC_T( "\tsymbol=" ) |
---|
609 | DTRACE_CABAC_V( uiSymbol ) |
---|
610 | DTRACE_CABAC_T( "\tctx=" ) |
---|
611 | DTRACE_CABAC_V( uiCtx ) |
---|
612 | DTRACE_CABAC_T( "\n" ) |
---|
613 | } |
---|
614 | |
---|
615 | Void TEncSbac::codeIntraDirLumaAng( TComDataCU* pcCU, UInt absPartIdx, Bool isMultiple) |
---|
616 | { |
---|
617 | UInt dir[4],j; |
---|
618 | Int preds[4][3] = {{-1, -1, -1},{-1, -1, -1},{-1, -1, -1},{-1, -1, -1}}; |
---|
619 | Int predNum[4], predIdx[4] ={ -1,-1,-1,-1}; |
---|
620 | PartSize mode = pcCU->getPartitionSize( absPartIdx ); |
---|
621 | UInt partNum = isMultiple?(mode==SIZE_NxN?4:1):1; |
---|
622 | UInt partOffset = ( pcCU->getPic()->getNumPartInCU() >> ( pcCU->getDepth(absPartIdx) << 1 ) ) >> 2; |
---|
623 | for (j=0;j<partNum;j++) |
---|
624 | { |
---|
625 | dir[j] = pcCU->getLumaIntraDir( absPartIdx+partOffset*j ); |
---|
626 | predNum[j] = pcCU->getIntraDirLumaPredictor(absPartIdx+partOffset*j, preds[j]); |
---|
627 | for(UInt i = 0; i < predNum[j]; i++) |
---|
628 | { |
---|
629 | if(dir[j] == preds[j][i]) |
---|
630 | { |
---|
631 | predIdx[j] = i; |
---|
632 | } |
---|
633 | } |
---|
634 | m_pcBinIf->encodeBin((predIdx[j] != -1)? 1 : 0, m_cCUIntraPredSCModel.get( 0, 0, 0 ) ); |
---|
635 | } |
---|
636 | for (j=0;j<partNum;j++) |
---|
637 | { |
---|
638 | if(predIdx[j] != -1) |
---|
639 | { |
---|
640 | m_pcBinIf->encodeBinEP( predIdx[j] ? 1 : 0 ); |
---|
641 | if (predIdx[j]) |
---|
642 | { |
---|
643 | m_pcBinIf->encodeBinEP( predIdx[j]-1 ); |
---|
644 | } |
---|
645 | } |
---|
646 | else |
---|
647 | { |
---|
648 | if (preds[j][0] > preds[j][1]) |
---|
649 | { |
---|
650 | std::swap(preds[j][0], preds[j][1]); |
---|
651 | } |
---|
652 | if (preds[j][0] > preds[j][2]) |
---|
653 | { |
---|
654 | std::swap(preds[j][0], preds[j][2]); |
---|
655 | } |
---|
656 | if (preds[j][1] > preds[j][2]) |
---|
657 | { |
---|
658 | std::swap(preds[j][1], preds[j][2]); |
---|
659 | } |
---|
660 | for(Int i = (predNum[j] - 1); i >= 0; i--) |
---|
661 | { |
---|
662 | dir[j] = dir[j] > preds[j][i] ? dir[j] - 1 : dir[j]; |
---|
663 | } |
---|
664 | m_pcBinIf->encodeBinsEP( dir[j], 5 ); |
---|
665 | } |
---|
666 | } |
---|
667 | return; |
---|
668 | } |
---|
669 | |
---|
670 | Void TEncSbac::codeIntraDirChroma( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
671 | { |
---|
672 | UInt uiIntraDirChroma = pcCU->getChromaIntraDir( uiAbsPartIdx ); |
---|
673 | |
---|
674 | if( uiIntraDirChroma == DM_CHROMA_IDX ) |
---|
675 | { |
---|
676 | m_pcBinIf->encodeBin( 0, m_cCUChromaPredSCModel.get( 0, 0, 0 ) ); |
---|
677 | } |
---|
678 | else |
---|
679 | { |
---|
680 | UInt uiAllowedChromaDir[ NUM_CHROMA_MODE ]; |
---|
681 | pcCU->getAllowedChromaDir( uiAbsPartIdx, uiAllowedChromaDir ); |
---|
682 | |
---|
683 | for( Int i = 0; i < NUM_CHROMA_MODE - 1; i++ ) |
---|
684 | { |
---|
685 | if( uiIntraDirChroma == uiAllowedChromaDir[i] ) |
---|
686 | { |
---|
687 | uiIntraDirChroma = i; |
---|
688 | break; |
---|
689 | } |
---|
690 | } |
---|
691 | m_pcBinIf->encodeBin( 1, m_cCUChromaPredSCModel.get( 0, 0, 0 ) ); |
---|
692 | |
---|
693 | m_pcBinIf->encodeBinsEP( uiIntraDirChroma, 2 ); |
---|
694 | } |
---|
695 | return; |
---|
696 | } |
---|
697 | |
---|
698 | Void TEncSbac::codeInterDir( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
699 | { |
---|
700 | const UInt uiInterDir = pcCU->getInterDir( uiAbsPartIdx ) - 1; |
---|
701 | const UInt uiCtx = pcCU->getCtxInterDir( uiAbsPartIdx ); |
---|
702 | ContextModel *pCtx = m_cCUInterDirSCModel.get( 0 ); |
---|
703 | if (pcCU->getPartitionSize(uiAbsPartIdx) == SIZE_2Nx2N || pcCU->getHeight(uiAbsPartIdx) != 8 ) |
---|
704 | { |
---|
705 | m_pcBinIf->encodeBin( uiInterDir == 2 ? 1 : 0, *( pCtx + uiCtx ) ); |
---|
706 | } |
---|
707 | if (uiInterDir < 2) |
---|
708 | { |
---|
709 | m_pcBinIf->encodeBin( uiInterDir, *( pCtx + 4 ) ); |
---|
710 | } |
---|
711 | return; |
---|
712 | } |
---|
713 | |
---|
714 | Void TEncSbac::codeRefFrmIdx( TComDataCU* pcCU, UInt uiAbsPartIdx, RefPicList eRefList ) |
---|
715 | { |
---|
716 | { |
---|
717 | Int iRefFrame = pcCU->getCUMvField( eRefList )->getRefIdx( uiAbsPartIdx ); |
---|
718 | ContextModel *pCtx = m_cCURefPicSCModel.get( 0 ); |
---|
719 | m_pcBinIf->encodeBin( ( iRefFrame == 0 ? 0 : 1 ), *pCtx ); |
---|
720 | |
---|
721 | if( iRefFrame > 0 ) |
---|
722 | { |
---|
723 | UInt uiRefNum = pcCU->getSlice()->getNumRefIdx( eRefList ) - 2; |
---|
724 | pCtx++; |
---|
725 | iRefFrame--; |
---|
726 | for( UInt ui = 0; ui < uiRefNum; ++ui ) |
---|
727 | { |
---|
728 | const UInt uiSymbol = ui == iRefFrame ? 0 : 1; |
---|
729 | if( ui == 0 ) |
---|
730 | { |
---|
731 | m_pcBinIf->encodeBin( uiSymbol, *pCtx ); |
---|
732 | } |
---|
733 | else |
---|
734 | { |
---|
735 | m_pcBinIf->encodeBinEP( uiSymbol ); |
---|
736 | } |
---|
737 | if( uiSymbol == 0 ) |
---|
738 | { |
---|
739 | break; |
---|
740 | } |
---|
741 | } |
---|
742 | } |
---|
743 | } |
---|
744 | return; |
---|
745 | } |
---|
746 | |
---|
747 | Void TEncSbac::codeMvd( TComDataCU* pcCU, UInt uiAbsPartIdx, RefPicList eRefList ) |
---|
748 | { |
---|
749 | if(pcCU->getSlice()->getMvdL1ZeroFlag() && eRefList == REF_PIC_LIST_1 && pcCU->getInterDir(uiAbsPartIdx)==3) |
---|
750 | { |
---|
751 | return; |
---|
752 | } |
---|
753 | |
---|
754 | const TComCUMvField* pcCUMvField = pcCU->getCUMvField( eRefList ); |
---|
755 | const Int iHor = pcCUMvField->getMvd( uiAbsPartIdx ).getHor(); |
---|
756 | const Int iVer = pcCUMvField->getMvd( uiAbsPartIdx ).getVer(); |
---|
757 | ContextModel* pCtx = m_cCUMvdSCModel.get( 0 ); |
---|
758 | |
---|
759 | m_pcBinIf->encodeBin( iHor != 0 ? 1 : 0, *pCtx ); |
---|
760 | m_pcBinIf->encodeBin( iVer != 0 ? 1 : 0, *pCtx ); |
---|
761 | |
---|
762 | const Bool bHorAbsGr0 = iHor != 0; |
---|
763 | const Bool bVerAbsGr0 = iVer != 0; |
---|
764 | const UInt uiHorAbs = 0 > iHor ? -iHor : iHor; |
---|
765 | const UInt uiVerAbs = 0 > iVer ? -iVer : iVer; |
---|
766 | pCtx++; |
---|
767 | |
---|
768 | if( bHorAbsGr0 ) |
---|
769 | { |
---|
770 | m_pcBinIf->encodeBin( uiHorAbs > 1 ? 1 : 0, *pCtx ); |
---|
771 | } |
---|
772 | |
---|
773 | if( bVerAbsGr0 ) |
---|
774 | { |
---|
775 | m_pcBinIf->encodeBin( uiVerAbs > 1 ? 1 : 0, *pCtx ); |
---|
776 | } |
---|
777 | |
---|
778 | if( bHorAbsGr0 ) |
---|
779 | { |
---|
780 | if( uiHorAbs > 1 ) |
---|
781 | { |
---|
782 | xWriteEpExGolomb( uiHorAbs-2, 1 ); |
---|
783 | } |
---|
784 | |
---|
785 | m_pcBinIf->encodeBinEP( 0 > iHor ? 1 : 0 ); |
---|
786 | } |
---|
787 | |
---|
788 | if( bVerAbsGr0 ) |
---|
789 | { |
---|
790 | if( uiVerAbs > 1 ) |
---|
791 | { |
---|
792 | xWriteEpExGolomb( uiVerAbs-2, 1 ); |
---|
793 | } |
---|
794 | |
---|
795 | m_pcBinIf->encodeBinEP( 0 > iVer ? 1 : 0 ); |
---|
796 | } |
---|
797 | |
---|
798 | return; |
---|
799 | } |
---|
800 | |
---|
801 | Void TEncSbac::codeDeltaQP( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
802 | { |
---|
803 | Int iDQp = pcCU->getQP( uiAbsPartIdx ) - pcCU->getRefQP( uiAbsPartIdx ); |
---|
804 | |
---|
805 | Int qpBdOffsetY = pcCU->getSlice()->getSPS()->getQpBDOffsetY(); |
---|
806 | iDQp = (iDQp + 78 + qpBdOffsetY + (qpBdOffsetY/2)) % (52 + qpBdOffsetY) - 26 - (qpBdOffsetY/2); |
---|
807 | |
---|
808 | UInt uiAbsDQp = (UInt)((iDQp > 0)? iDQp : (-iDQp)); |
---|
809 | UInt TUValue = min((Int)uiAbsDQp, CU_DQP_TU_CMAX); |
---|
810 | xWriteUnaryMaxSymbol( TUValue, &m_cCUDeltaQpSCModel.get( 0, 0, 0 ), 1, CU_DQP_TU_CMAX); |
---|
811 | if( uiAbsDQp >= CU_DQP_TU_CMAX ) |
---|
812 | { |
---|
813 | xWriteEpExGolomb( uiAbsDQp - CU_DQP_TU_CMAX, CU_DQP_EG_k ); |
---|
814 | } |
---|
815 | |
---|
816 | if ( uiAbsDQp > 0) |
---|
817 | { |
---|
818 | UInt uiSign = (iDQp > 0 ? 0 : 1); |
---|
819 | m_pcBinIf->encodeBinEP(uiSign); |
---|
820 | } |
---|
821 | |
---|
822 | return; |
---|
823 | } |
---|
824 | |
---|
825 | Void TEncSbac::codeQtCbf( TComDataCU* pcCU, UInt uiAbsPartIdx, TextType eType, UInt uiTrDepth ) |
---|
826 | { |
---|
827 | UInt uiCbf = pcCU->getCbf ( uiAbsPartIdx, eType, uiTrDepth ); |
---|
828 | UInt uiCtx = pcCU->getCtxQtCbf( eType, uiTrDepth ); |
---|
829 | m_pcBinIf->encodeBin( uiCbf , m_cCUQtCbfSCModel.get( 0, eType ? TEXT_CHROMA : eType, uiCtx ) ); |
---|
830 | DTRACE_CABAC_VL( g_nSymbolCounter++ ) |
---|
831 | DTRACE_CABAC_T( "\tparseQtCbf()" ) |
---|
832 | DTRACE_CABAC_T( "\tsymbol=" ) |
---|
833 | DTRACE_CABAC_V( uiCbf ) |
---|
834 | DTRACE_CABAC_T( "\tctx=" ) |
---|
835 | DTRACE_CABAC_V( uiCtx ) |
---|
836 | DTRACE_CABAC_T( "\tetype=" ) |
---|
837 | DTRACE_CABAC_V( eType ) |
---|
838 | DTRACE_CABAC_T( "\tuiAbsPartIdx=" ) |
---|
839 | DTRACE_CABAC_V( uiAbsPartIdx ) |
---|
840 | DTRACE_CABAC_T( "\n" ) |
---|
841 | } |
---|
842 | |
---|
843 | void TEncSbac::codeTransformSkipFlags (TComDataCU* pcCU, UInt uiAbsPartIdx, UInt width, UInt height, TextType eTType ) |
---|
844 | { |
---|
845 | if (pcCU->getCUTransquantBypass(uiAbsPartIdx)) |
---|
846 | { |
---|
847 | return; |
---|
848 | } |
---|
849 | if(width != 4 || height != 4) |
---|
850 | { |
---|
851 | return; |
---|
852 | } |
---|
853 | |
---|
854 | UInt useTransformSkip = pcCU->getTransformSkip( uiAbsPartIdx,eTType); |
---|
855 | m_pcBinIf->encodeBin( useTransformSkip, m_cTransformSkipSCModel.get( 0, eTType? TEXT_CHROMA: TEXT_LUMA, 0 ) ); |
---|
856 | DTRACE_CABAC_VL( g_nSymbolCounter++ ) |
---|
857 | DTRACE_CABAC_T("\tparseTransformSkip()"); |
---|
858 | DTRACE_CABAC_T( "\tsymbol=" ) |
---|
859 | DTRACE_CABAC_V( useTransformSkip ) |
---|
860 | DTRACE_CABAC_T( "\tAddr=" ) |
---|
861 | DTRACE_CABAC_V( pcCU->getAddr() ) |
---|
862 | DTRACE_CABAC_T( "\tetype=" ) |
---|
863 | DTRACE_CABAC_V( eTType ) |
---|
864 | DTRACE_CABAC_T( "\tuiAbsPartIdx=" ) |
---|
865 | DTRACE_CABAC_V( uiAbsPartIdx ) |
---|
866 | DTRACE_CABAC_T( "\n" ) |
---|
867 | } |
---|
868 | |
---|
869 | /** Code I_PCM information. |
---|
870 | * \param pcCU pointer to CU |
---|
871 | * \param uiAbsPartIdx CU index |
---|
872 | * \returns Void |
---|
873 | */ |
---|
874 | Void TEncSbac::codeIPCMInfo( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
875 | { |
---|
876 | UInt uiIPCM = (pcCU->getIPCMFlag(uiAbsPartIdx) == true)? 1 : 0; |
---|
877 | |
---|
878 | Bool writePCMSampleFlag = pcCU->getIPCMFlag(uiAbsPartIdx); |
---|
879 | |
---|
880 | m_pcBinIf->encodeBinTrm (uiIPCM); |
---|
881 | |
---|
882 | if (writePCMSampleFlag) |
---|
883 | { |
---|
884 | m_pcBinIf->encodePCMAlignBits(); |
---|
885 | |
---|
886 | UInt uiMinCoeffSize = pcCU->getPic()->getMinCUWidth()*pcCU->getPic()->getMinCUHeight(); |
---|
887 | UInt uiLumaOffset = uiMinCoeffSize*uiAbsPartIdx; |
---|
888 | UInt uiChromaOffset = uiLumaOffset>>2; |
---|
889 | Pel* piPCMSample; |
---|
890 | UInt uiWidth; |
---|
891 | UInt uiHeight; |
---|
892 | UInt uiSampleBits; |
---|
893 | UInt uiX, uiY; |
---|
894 | |
---|
895 | piPCMSample = pcCU->getPCMSampleY() + uiLumaOffset; |
---|
896 | uiWidth = pcCU->getWidth(uiAbsPartIdx); |
---|
897 | uiHeight = pcCU->getHeight(uiAbsPartIdx); |
---|
898 | uiSampleBits = pcCU->getSlice()->getSPS()->getPCMBitDepthLuma(); |
---|
899 | |
---|
900 | for(uiY = 0; uiY < uiHeight; uiY++) |
---|
901 | { |
---|
902 | for(uiX = 0; uiX < uiWidth; uiX++) |
---|
903 | { |
---|
904 | UInt uiSample = piPCMSample[uiX]; |
---|
905 | |
---|
906 | m_pcBinIf->xWritePCMCode(uiSample, uiSampleBits); |
---|
907 | } |
---|
908 | piPCMSample += uiWidth; |
---|
909 | } |
---|
910 | |
---|
911 | piPCMSample = pcCU->getPCMSampleCb() + uiChromaOffset; |
---|
912 | uiWidth = pcCU->getWidth(uiAbsPartIdx)/2; |
---|
913 | uiHeight = pcCU->getHeight(uiAbsPartIdx)/2; |
---|
914 | uiSampleBits = pcCU->getSlice()->getSPS()->getPCMBitDepthChroma(); |
---|
915 | |
---|
916 | for(uiY = 0; uiY < uiHeight; uiY++) |
---|
917 | { |
---|
918 | for(uiX = 0; uiX < uiWidth; uiX++) |
---|
919 | { |
---|
920 | UInt uiSample = piPCMSample[uiX]; |
---|
921 | |
---|
922 | m_pcBinIf->xWritePCMCode(uiSample, uiSampleBits); |
---|
923 | } |
---|
924 | piPCMSample += uiWidth; |
---|
925 | } |
---|
926 | |
---|
927 | piPCMSample = pcCU->getPCMSampleCr() + uiChromaOffset; |
---|
928 | uiWidth = pcCU->getWidth(uiAbsPartIdx)/2; |
---|
929 | uiHeight = pcCU->getHeight(uiAbsPartIdx)/2; |
---|
930 | uiSampleBits = pcCU->getSlice()->getSPS()->getPCMBitDepthChroma(); |
---|
931 | |
---|
932 | for(uiY = 0; uiY < uiHeight; uiY++) |
---|
933 | { |
---|
934 | for(uiX = 0; uiX < uiWidth; uiX++) |
---|
935 | { |
---|
936 | UInt uiSample = piPCMSample[uiX]; |
---|
937 | |
---|
938 | m_pcBinIf->xWritePCMCode(uiSample, uiSampleBits); |
---|
939 | } |
---|
940 | piPCMSample += uiWidth; |
---|
941 | } |
---|
942 | m_pcBinIf->resetBac(); |
---|
943 | } |
---|
944 | } |
---|
945 | |
---|
946 | Void TEncSbac::codeQtRootCbf( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
947 | { |
---|
948 | UInt uiCbf = pcCU->getQtRootCbf( uiAbsPartIdx ); |
---|
949 | UInt uiCtx = 0; |
---|
950 | m_pcBinIf->encodeBin( uiCbf , m_cCUQtRootCbfSCModel.get( 0, 0, uiCtx ) ); |
---|
951 | DTRACE_CABAC_VL( g_nSymbolCounter++ ) |
---|
952 | DTRACE_CABAC_T( "\tparseQtRootCbf()" ) |
---|
953 | DTRACE_CABAC_T( "\tsymbol=" ) |
---|
954 | DTRACE_CABAC_V( uiCbf ) |
---|
955 | DTRACE_CABAC_T( "\tctx=" ) |
---|
956 | DTRACE_CABAC_V( uiCtx ) |
---|
957 | DTRACE_CABAC_T( "\tuiAbsPartIdx=" ) |
---|
958 | DTRACE_CABAC_V( uiAbsPartIdx ) |
---|
959 | DTRACE_CABAC_T( "\n" ) |
---|
960 | } |
---|
961 | |
---|
962 | Void TEncSbac::codeQtCbfZero( TComDataCU* pcCU, TextType eType, UInt uiTrDepth ) |
---|
963 | { |
---|
964 | // this function is only used to estimate the bits when cbf is 0 |
---|
965 | // and will never be called when writing the bistream. do not need to write log |
---|
966 | UInt uiCbf = 0; |
---|
967 | UInt uiCtx = pcCU->getCtxQtCbf( eType, uiTrDepth ); |
---|
968 | m_pcBinIf->encodeBin( uiCbf , m_cCUQtCbfSCModel.get( 0, eType ? TEXT_CHROMA : eType, uiCtx ) ); |
---|
969 | } |
---|
970 | |
---|
971 | Void TEncSbac::codeQtRootCbfZero( TComDataCU* pcCU ) |
---|
972 | { |
---|
973 | // this function is only used to estimate the bits when cbf is 0 |
---|
974 | // and will never be called when writing the bistream. do not need to write log |
---|
975 | UInt uiCbf = 0; |
---|
976 | UInt uiCtx = 0; |
---|
977 | m_pcBinIf->encodeBin( uiCbf , m_cCUQtRootCbfSCModel.get( 0, 0, uiCtx ) ); |
---|
978 | } |
---|
979 | |
---|
980 | /** Encode (X,Y) position of the last significant coefficient |
---|
981 | * \param uiPosX X component of last coefficient |
---|
982 | * \param uiPosY Y component of last coefficient |
---|
983 | * \param width Block width |
---|
984 | * \param height Block height |
---|
985 | * \param eTType plane type / luminance or chrominance |
---|
986 | * \param uiScanIdx scan type (zig-zag, hor, ver) |
---|
987 | * This method encodes the X and Y component within a block of the last significant coefficient. |
---|
988 | */ |
---|
989 | Void TEncSbac::codeLastSignificantXY( UInt uiPosX, UInt uiPosY, Int width, Int height, TextType eTType, UInt uiScanIdx ) |
---|
990 | { |
---|
991 | // swap |
---|
992 | if( uiScanIdx == SCAN_VER ) |
---|
993 | { |
---|
994 | swap( uiPosX, uiPosY ); |
---|
995 | } |
---|
996 | |
---|
997 | UInt uiCtxLast; |
---|
998 | ContextModel *pCtxX = m_cCuCtxLastX.get( 0, eTType ); |
---|
999 | ContextModel *pCtxY = m_cCuCtxLastY.get( 0, eTType ); |
---|
1000 | UInt uiGroupIdxX = g_uiGroupIdx[ uiPosX ]; |
---|
1001 | UInt uiGroupIdxY = g_uiGroupIdx[ uiPosY ]; |
---|
1002 | |
---|
1003 | |
---|
1004 | Int blkSizeOffsetX, blkSizeOffsetY, shiftX, shiftY; |
---|
1005 | blkSizeOffsetX = eTType ? 0: (g_aucConvertToBit[ width ] *3 + ((g_aucConvertToBit[ width ] +1)>>2)); |
---|
1006 | blkSizeOffsetY = eTType ? 0: (g_aucConvertToBit[ height ]*3 + ((g_aucConvertToBit[ height ]+1)>>2)); |
---|
1007 | shiftX= eTType ? g_aucConvertToBit[ width ] :((g_aucConvertToBit[ width ]+3)>>2); |
---|
1008 | shiftY= eTType ? g_aucConvertToBit[ height ] :((g_aucConvertToBit[ height ]+3)>>2); |
---|
1009 | // posX |
---|
1010 | for( uiCtxLast = 0; uiCtxLast < uiGroupIdxX; uiCtxLast++ ) |
---|
1011 | { |
---|
1012 | m_pcBinIf->encodeBin( 1, *( pCtxX + blkSizeOffsetX + (uiCtxLast >>shiftX) ) ); |
---|
1013 | } |
---|
1014 | if( uiGroupIdxX < g_uiGroupIdx[ width - 1 ]) |
---|
1015 | { |
---|
1016 | m_pcBinIf->encodeBin( 0, *( pCtxX + blkSizeOffsetX + (uiCtxLast >>shiftX) ) ); |
---|
1017 | } |
---|
1018 | |
---|
1019 | // posY |
---|
1020 | for( uiCtxLast = 0; uiCtxLast < uiGroupIdxY; uiCtxLast++ ) |
---|
1021 | { |
---|
1022 | m_pcBinIf->encodeBin( 1, *( pCtxY + blkSizeOffsetY + (uiCtxLast >>shiftY) ) ); |
---|
1023 | } |
---|
1024 | if( uiGroupIdxY < g_uiGroupIdx[ height - 1 ]) |
---|
1025 | { |
---|
1026 | m_pcBinIf->encodeBin( 0, *( pCtxY + blkSizeOffsetY + (uiCtxLast >>shiftY) ) ); |
---|
1027 | } |
---|
1028 | if ( uiGroupIdxX > 3 ) |
---|
1029 | { |
---|
1030 | UInt uiCount = ( uiGroupIdxX - 2 ) >> 1; |
---|
1031 | uiPosX = uiPosX - g_uiMinInGroup[ uiGroupIdxX ]; |
---|
1032 | for (Int i = uiCount - 1 ; i >= 0; i-- ) |
---|
1033 | { |
---|
1034 | m_pcBinIf->encodeBinEP( ( uiPosX >> i ) & 1 ); |
---|
1035 | } |
---|
1036 | } |
---|
1037 | if ( uiGroupIdxY > 3 ) |
---|
1038 | { |
---|
1039 | UInt uiCount = ( uiGroupIdxY - 2 ) >> 1; |
---|
1040 | uiPosY = uiPosY - g_uiMinInGroup[ uiGroupIdxY ]; |
---|
1041 | for ( Int i = uiCount - 1 ; i >= 0; i-- ) |
---|
1042 | { |
---|
1043 | m_pcBinIf->encodeBinEP( ( uiPosY >> i ) & 1 ); |
---|
1044 | } |
---|
1045 | } |
---|
1046 | } |
---|
1047 | |
---|
1048 | Void TEncSbac::codeCoeffNxN( TComDataCU* pcCU, TCoeff* pcCoef, UInt uiAbsPartIdx, UInt uiWidth, UInt uiHeight, UInt uiDepth, TextType eTType ) |
---|
1049 | { |
---|
1050 | DTRACE_CABAC_VL( g_nSymbolCounter++ ) |
---|
1051 | DTRACE_CABAC_T( "\tparseCoeffNxN()\teType=" ) |
---|
1052 | DTRACE_CABAC_V( eTType ) |
---|
1053 | DTRACE_CABAC_T( "\twidth=" ) |
---|
1054 | DTRACE_CABAC_V( uiWidth ) |
---|
1055 | DTRACE_CABAC_T( "\theight=" ) |
---|
1056 | DTRACE_CABAC_V( uiHeight ) |
---|
1057 | DTRACE_CABAC_T( "\tdepth=" ) |
---|
1058 | DTRACE_CABAC_V( uiDepth ) |
---|
1059 | DTRACE_CABAC_T( "\tabspartidx=" ) |
---|
1060 | DTRACE_CABAC_V( uiAbsPartIdx ) |
---|
1061 | DTRACE_CABAC_T( "\ttoCU-X=" ) |
---|
1062 | DTRACE_CABAC_V( pcCU->getCUPelX() ) |
---|
1063 | DTRACE_CABAC_T( "\ttoCU-Y=" ) |
---|
1064 | DTRACE_CABAC_V( pcCU->getCUPelY() ) |
---|
1065 | DTRACE_CABAC_T( "\tCU-addr=" ) |
---|
1066 | DTRACE_CABAC_V( pcCU->getAddr() ) |
---|
1067 | DTRACE_CABAC_T( "\tinCU-X=" ) |
---|
1068 | DTRACE_CABAC_V( g_auiRasterToPelX[ g_auiZscanToRaster[uiAbsPartIdx] ] ) |
---|
1069 | DTRACE_CABAC_T( "\tinCU-Y=" ) |
---|
1070 | DTRACE_CABAC_V( g_auiRasterToPelY[ g_auiZscanToRaster[uiAbsPartIdx] ] ) |
---|
1071 | DTRACE_CABAC_T( "\tpredmode=" ) |
---|
1072 | DTRACE_CABAC_V( pcCU->getPredictionMode( uiAbsPartIdx ) ) |
---|
1073 | DTRACE_CABAC_T( "\n" ) |
---|
1074 | |
---|
1075 | if( uiWidth > m_pcSlice->getSPS()->getMaxTrSize() ) |
---|
1076 | { |
---|
1077 | uiWidth = m_pcSlice->getSPS()->getMaxTrSize(); |
---|
1078 | uiHeight = m_pcSlice->getSPS()->getMaxTrSize(); |
---|
1079 | } |
---|
1080 | |
---|
1081 | UInt uiNumSig = 0; |
---|
1082 | |
---|
1083 | // compute number of significant coefficients |
---|
1084 | uiNumSig = TEncEntropy::countNonZeroCoeffs(pcCoef, uiWidth * uiHeight); |
---|
1085 | |
---|
1086 | if ( uiNumSig == 0 ) |
---|
1087 | return; |
---|
1088 | if(pcCU->getSlice()->getPPS()->getUseTransformSkip()) |
---|
1089 | { |
---|
1090 | codeTransformSkipFlags( pcCU,uiAbsPartIdx, uiWidth, uiHeight, eTType ); |
---|
1091 | } |
---|
1092 | eTType = eTType == TEXT_LUMA ? TEXT_LUMA : ( eTType == TEXT_NONE ? TEXT_NONE : TEXT_CHROMA ); |
---|
1093 | |
---|
1094 | //----- encode significance map ----- |
---|
1095 | const UInt uiLog2BlockSize = g_aucConvertToBit[ uiWidth ] + 2; |
---|
1096 | UInt uiScanIdx = pcCU->getCoefScanIdx(uiAbsPartIdx, uiWidth, eTType==TEXT_LUMA, pcCU->isIntra(uiAbsPartIdx)); |
---|
1097 | const UInt *scan = g_auiSigLastScan[ uiScanIdx ][ uiLog2BlockSize - 1 ]; |
---|
1098 | |
---|
1099 | Bool beValid; |
---|
1100 | if (pcCU->getCUTransquantBypass(uiAbsPartIdx)) |
---|
1101 | { |
---|
1102 | beValid = false; |
---|
1103 | } |
---|
1104 | else |
---|
1105 | { |
---|
1106 | beValid = pcCU->getSlice()->getPPS()->getSignHideFlag() > 0; |
---|
1107 | } |
---|
1108 | |
---|
1109 | // Find position of last coefficient |
---|
1110 | Int scanPosLast = -1; |
---|
1111 | Int posLast; |
---|
1112 | |
---|
1113 | const UInt * scanCG; |
---|
1114 | { |
---|
1115 | scanCG = g_auiSigLastScan[ uiScanIdx ][ uiLog2BlockSize > 3 ? uiLog2BlockSize-2-1 : 0 ]; |
---|
1116 | if( uiLog2BlockSize == 3 ) |
---|
1117 | { |
---|
1118 | scanCG = g_sigLastScan8x8[ uiScanIdx ]; |
---|
1119 | } |
---|
1120 | else if( uiLog2BlockSize == 5 ) |
---|
1121 | { |
---|
1122 | scanCG = g_sigLastScanCG32x32; |
---|
1123 | } |
---|
1124 | } |
---|
1125 | UInt uiSigCoeffGroupFlag[ MLS_GRP_NUM ]; |
---|
1126 | static const UInt uiShift = MLS_CG_SIZE >> 1; |
---|
1127 | const UInt uiNumBlkSide = uiWidth >> uiShift; |
---|
1128 | |
---|
1129 | ::memset( uiSigCoeffGroupFlag, 0, sizeof(UInt) * MLS_GRP_NUM ); |
---|
1130 | |
---|
1131 | do |
---|
1132 | { |
---|
1133 | posLast = scan[ ++scanPosLast ]; |
---|
1134 | |
---|
1135 | // get L1 sig map |
---|
1136 | UInt uiPosY = posLast >> uiLog2BlockSize; |
---|
1137 | UInt uiPosX = posLast - ( uiPosY << uiLog2BlockSize ); |
---|
1138 | UInt uiBlkIdx = uiNumBlkSide * (uiPosY >> uiShift) + (uiPosX >> uiShift); |
---|
1139 | if( pcCoef[ posLast ] ) |
---|
1140 | { |
---|
1141 | uiSigCoeffGroupFlag[ uiBlkIdx ] = 1; |
---|
1142 | } |
---|
1143 | |
---|
1144 | uiNumSig -= ( pcCoef[ posLast ] != 0 ); |
---|
1145 | } |
---|
1146 | while ( uiNumSig > 0 ); |
---|
1147 | |
---|
1148 | // Code position of last coefficient |
---|
1149 | Int posLastY = posLast >> uiLog2BlockSize; |
---|
1150 | Int posLastX = posLast - ( posLastY << uiLog2BlockSize ); |
---|
1151 | codeLastSignificantXY(posLastX, posLastY, uiWidth, uiHeight, eTType, uiScanIdx); |
---|
1152 | |
---|
1153 | //===== code significance flag ===== |
---|
1154 | ContextModel * const baseCoeffGroupCtx = m_cCUSigCoeffGroupSCModel.get( 0, eTType ); |
---|
1155 | ContextModel * const baseCtx = (eTType==TEXT_LUMA) ? m_cCUSigSCModel.get( 0, 0 ) : m_cCUSigSCModel.get( 0, 0 ) + NUM_SIG_FLAG_CTX_LUMA; |
---|
1156 | |
---|
1157 | |
---|
1158 | const Int iLastScanSet = scanPosLast >> LOG2_SCAN_SET_SIZE; |
---|
1159 | UInt c1 = 1; |
---|
1160 | UInt uiGoRiceParam = 0; |
---|
1161 | Int iScanPosSig = scanPosLast; |
---|
1162 | |
---|
1163 | for( Int iSubSet = iLastScanSet; iSubSet >= 0; iSubSet-- ) |
---|
1164 | { |
---|
1165 | Int numNonZero = 0; |
---|
1166 | Int iSubPos = iSubSet << LOG2_SCAN_SET_SIZE; |
---|
1167 | uiGoRiceParam = 0; |
---|
1168 | Int absCoeff[16]; |
---|
1169 | UInt coeffSigns = 0; |
---|
1170 | |
---|
1171 | Int lastNZPosInCG = -1, firstNZPosInCG = SCAN_SET_SIZE; |
---|
1172 | |
---|
1173 | if( iScanPosSig == scanPosLast ) |
---|
1174 | { |
---|
1175 | absCoeff[ 0 ] = abs( pcCoef[ posLast ] ); |
---|
1176 | coeffSigns = ( pcCoef[ posLast ] < 0 ); |
---|
1177 | numNonZero = 1; |
---|
1178 | lastNZPosInCG = iScanPosSig; |
---|
1179 | firstNZPosInCG = iScanPosSig; |
---|
1180 | iScanPosSig--; |
---|
1181 | } |
---|
1182 | |
---|
1183 | // encode significant_coeffgroup_flag |
---|
1184 | Int iCGBlkPos = scanCG[ iSubSet ]; |
---|
1185 | Int iCGPosY = iCGBlkPos / uiNumBlkSide; |
---|
1186 | Int iCGPosX = iCGBlkPos - (iCGPosY * uiNumBlkSide); |
---|
1187 | if( iSubSet == iLastScanSet || iSubSet == 0) |
---|
1188 | { |
---|
1189 | uiSigCoeffGroupFlag[ iCGBlkPos ] = 1; |
---|
1190 | } |
---|
1191 | else |
---|
1192 | { |
---|
1193 | UInt uiSigCoeffGroup = (uiSigCoeffGroupFlag[ iCGBlkPos ] != 0); |
---|
1194 | UInt uiCtxSig = TComTrQuant::getSigCoeffGroupCtxInc( uiSigCoeffGroupFlag, iCGPosX, iCGPosY, uiWidth, uiHeight ); |
---|
1195 | m_pcBinIf->encodeBin( uiSigCoeffGroup, baseCoeffGroupCtx[ uiCtxSig ] ); |
---|
1196 | } |
---|
1197 | |
---|
1198 | // encode significant_coeff_flag |
---|
1199 | if( uiSigCoeffGroupFlag[ iCGBlkPos ] ) |
---|
1200 | { |
---|
1201 | Int patternSigCtx = TComTrQuant::calcPatternSigCtx( uiSigCoeffGroupFlag, iCGPosX, iCGPosY, uiWidth, uiHeight ); |
---|
1202 | UInt uiBlkPos, uiPosY, uiPosX, uiSig, uiCtxSig; |
---|
1203 | for( ; iScanPosSig >= iSubPos; iScanPosSig-- ) |
---|
1204 | { |
---|
1205 | uiBlkPos = scan[ iScanPosSig ]; |
---|
1206 | uiPosY = uiBlkPos >> uiLog2BlockSize; |
---|
1207 | uiPosX = uiBlkPos - ( uiPosY << uiLog2BlockSize ); |
---|
1208 | uiSig = (pcCoef[ uiBlkPos ] != 0); |
---|
1209 | if( iScanPosSig > iSubPos || iSubSet == 0 || numNonZero ) |
---|
1210 | { |
---|
1211 | uiCtxSig = TComTrQuant::getSigCtxInc( patternSigCtx, uiScanIdx, uiPosX, uiPosY, uiLog2BlockSize, eTType ); |
---|
1212 | m_pcBinIf->encodeBin( uiSig, baseCtx[ uiCtxSig ] ); |
---|
1213 | } |
---|
1214 | if( uiSig ) |
---|
1215 | { |
---|
1216 | absCoeff[ numNonZero ] = abs( pcCoef[ uiBlkPos ] ); |
---|
1217 | coeffSigns = 2 * coeffSigns + ( pcCoef[ uiBlkPos ] < 0 ); |
---|
1218 | numNonZero++; |
---|
1219 | if( lastNZPosInCG == -1 ) |
---|
1220 | { |
---|
1221 | lastNZPosInCG = iScanPosSig; |
---|
1222 | } |
---|
1223 | firstNZPosInCG = iScanPosSig; |
---|
1224 | } |
---|
1225 | } |
---|
1226 | } |
---|
1227 | else |
---|
1228 | { |
---|
1229 | iScanPosSig = iSubPos - 1; |
---|
1230 | } |
---|
1231 | |
---|
1232 | if( numNonZero > 0 ) |
---|
1233 | { |
---|
1234 | Bool signHidden = ( lastNZPosInCG - firstNZPosInCG >= SBH_THRESHOLD ); |
---|
1235 | UInt uiCtxSet = (iSubSet > 0 && eTType==TEXT_LUMA) ? 2 : 0; |
---|
1236 | |
---|
1237 | if( c1 == 0 ) |
---|
1238 | { |
---|
1239 | uiCtxSet++; |
---|
1240 | } |
---|
1241 | c1 = 1; |
---|
1242 | ContextModel *baseCtxMod = ( eTType==TEXT_LUMA ) ? m_cCUOneSCModel.get( 0, 0 ) + 4 * uiCtxSet : m_cCUOneSCModel.get( 0, 0 ) + NUM_ONE_FLAG_CTX_LUMA + 4 * uiCtxSet; |
---|
1243 | |
---|
1244 | Int numC1Flag = min(numNonZero, C1FLAG_NUMBER); |
---|
1245 | Int firstC2FlagIdx = -1; |
---|
1246 | for( Int idx = 0; idx < numC1Flag; idx++ ) |
---|
1247 | { |
---|
1248 | UInt uiSymbol = absCoeff[ idx ] > 1; |
---|
1249 | m_pcBinIf->encodeBin( uiSymbol, baseCtxMod[c1] ); |
---|
1250 | if( uiSymbol ) |
---|
1251 | { |
---|
1252 | c1 = 0; |
---|
1253 | |
---|
1254 | if (firstC2FlagIdx == -1) |
---|
1255 | { |
---|
1256 | firstC2FlagIdx = idx; |
---|
1257 | } |
---|
1258 | } |
---|
1259 | else if( (c1 < 3) && (c1 > 0) ) |
---|
1260 | { |
---|
1261 | c1++; |
---|
1262 | } |
---|
1263 | } |
---|
1264 | |
---|
1265 | if (c1 == 0) |
---|
1266 | { |
---|
1267 | |
---|
1268 | baseCtxMod = ( eTType==TEXT_LUMA ) ? m_cCUAbsSCModel.get( 0, 0 ) + uiCtxSet : m_cCUAbsSCModel.get( 0, 0 ) + NUM_ABS_FLAG_CTX_LUMA + uiCtxSet; |
---|
1269 | if ( firstC2FlagIdx != -1) |
---|
1270 | { |
---|
1271 | UInt symbol = absCoeff[ firstC2FlagIdx ] > 2; |
---|
1272 | m_pcBinIf->encodeBin( symbol, baseCtxMod[0] ); |
---|
1273 | } |
---|
1274 | } |
---|
1275 | |
---|
1276 | if( beValid && signHidden ) |
---|
1277 | { |
---|
1278 | m_pcBinIf->encodeBinsEP( (coeffSigns >> 1), numNonZero-1 ); |
---|
1279 | } |
---|
1280 | else |
---|
1281 | { |
---|
1282 | m_pcBinIf->encodeBinsEP( coeffSigns, numNonZero ); |
---|
1283 | } |
---|
1284 | |
---|
1285 | Int iFirstCoeff2 = 1; |
---|
1286 | if (c1 == 0 || numNonZero > C1FLAG_NUMBER) |
---|
1287 | { |
---|
1288 | for ( Int idx = 0; idx < numNonZero; idx++ ) |
---|
1289 | { |
---|
1290 | UInt baseLevel = (idx < C1FLAG_NUMBER)? (2 + iFirstCoeff2 ) : 1; |
---|
1291 | |
---|
1292 | if( absCoeff[ idx ] >= baseLevel) |
---|
1293 | { |
---|
1294 | xWriteCoefRemainExGolomb( absCoeff[ idx ] - baseLevel, uiGoRiceParam ); |
---|
1295 | if(absCoeff[idx] > 3*(1<<uiGoRiceParam)) |
---|
1296 | { |
---|
1297 | uiGoRiceParam = min<UInt>(uiGoRiceParam+ 1, 4); |
---|
1298 | } |
---|
1299 | } |
---|
1300 | if(absCoeff[ idx ] >= 2) |
---|
1301 | { |
---|
1302 | iFirstCoeff2 = 0; |
---|
1303 | } |
---|
1304 | } |
---|
1305 | } |
---|
1306 | } |
---|
1307 | } |
---|
1308 | |
---|
1309 | return; |
---|
1310 | } |
---|
1311 | |
---|
1312 | /** code SAO offset sign |
---|
1313 | * \param code sign value |
---|
1314 | */ |
---|
1315 | Void TEncSbac::codeSAOSign( UInt code ) |
---|
1316 | { |
---|
1317 | m_pcBinIf->encodeBinEP( code ); |
---|
1318 | } |
---|
1319 | |
---|
1320 | Void TEncSbac::codeSaoMaxUvlc ( UInt code, UInt maxSymbol ) |
---|
1321 | { |
---|
1322 | if (maxSymbol == 0) |
---|
1323 | { |
---|
1324 | return; |
---|
1325 | } |
---|
1326 | |
---|
1327 | Int i; |
---|
1328 | Bool bCodeLast = ( maxSymbol > code ); |
---|
1329 | |
---|
1330 | if ( code == 0 ) |
---|
1331 | { |
---|
1332 | m_pcBinIf->encodeBinEP( 0 ); |
---|
1333 | } |
---|
1334 | else |
---|
1335 | { |
---|
1336 | m_pcBinIf->encodeBinEP( 1 ); |
---|
1337 | for ( i=0; i<code-1; i++ ) |
---|
1338 | { |
---|
1339 | m_pcBinIf->encodeBinEP( 1 ); |
---|
1340 | } |
---|
1341 | if( bCodeLast ) |
---|
1342 | { |
---|
1343 | m_pcBinIf->encodeBinEP( 0 ); |
---|
1344 | } |
---|
1345 | } |
---|
1346 | } |
---|
1347 | |
---|
1348 | |
---|
1349 | /** Code SAO EO class or BO band position |
---|
1350 | * \param uiLength |
---|
1351 | * \param uiCode |
---|
1352 | */ |
---|
1353 | Void TEncSbac::codeSaoUflc ( UInt uiLength, UInt uiCode ) |
---|
1354 | { |
---|
1355 | m_pcBinIf->encodeBinsEP ( uiCode, uiLength ); |
---|
1356 | } |
---|
1357 | /** Code SAO merge flags |
---|
1358 | * \param uiCode |
---|
1359 | * \param uiCompIdx |
---|
1360 | */ |
---|
1361 | Void TEncSbac::codeSaoMerge ( UInt uiCode ) |
---|
1362 | { |
---|
1363 | if (uiCode == 0) |
---|
1364 | { |
---|
1365 | m_pcBinIf->encodeBin(0, m_cSaoMergeSCModel.get( 0, 0, 0 )); |
---|
1366 | } |
---|
1367 | else |
---|
1368 | { |
---|
1369 | m_pcBinIf->encodeBin(1, m_cSaoMergeSCModel.get( 0, 0, 0 )); |
---|
1370 | } |
---|
1371 | } |
---|
1372 | /** Code SAO type index |
---|
1373 | * \param uiCode |
---|
1374 | */ |
---|
1375 | Void TEncSbac::codeSaoTypeIdx ( UInt uiCode) |
---|
1376 | { |
---|
1377 | if (uiCode == 0) |
---|
1378 | { |
---|
1379 | m_pcBinIf->encodeBin( 0, m_cSaoTypeIdxSCModel.get( 0, 0, 0 ) ); |
---|
1380 | } |
---|
1381 | else |
---|
1382 | { |
---|
1383 | m_pcBinIf->encodeBin( 1, m_cSaoTypeIdxSCModel.get( 0, 0, 0 ) ); |
---|
1384 | m_pcBinIf->encodeBinEP( uiCode <= 4 ? 1 : 0 ); |
---|
1385 | } |
---|
1386 | } |
---|
1387 | /*! |
---|
1388 | **************************************************************************** |
---|
1389 | * \brief |
---|
1390 | * estimate bit cost for CBP, significant map and significant coefficients |
---|
1391 | **************************************************************************** |
---|
1392 | */ |
---|
1393 | Void TEncSbac::estBit( estBitsSbacStruct* pcEstBitsSbac, Int width, Int height, TextType eTType ) |
---|
1394 | { |
---|
1395 | estCBFBit( pcEstBitsSbac ); |
---|
1396 | |
---|
1397 | estSignificantCoeffGroupMapBit( pcEstBitsSbac, eTType ); |
---|
1398 | |
---|
1399 | // encode significance map |
---|
1400 | estSignificantMapBit( pcEstBitsSbac, width, height, eTType ); |
---|
1401 | |
---|
1402 | // encode significant coefficients |
---|
1403 | estSignificantCoefficientsBit( pcEstBitsSbac, eTType ); |
---|
1404 | } |
---|
1405 | |
---|
1406 | /*! |
---|
1407 | **************************************************************************** |
---|
1408 | * \brief |
---|
1409 | * estimate bit cost for each CBP bit |
---|
1410 | **************************************************************************** |
---|
1411 | */ |
---|
1412 | Void TEncSbac::estCBFBit( estBitsSbacStruct* pcEstBitsSbac ) |
---|
1413 | { |
---|
1414 | ContextModel *pCtx = m_cCUQtCbfSCModel.get( 0 ); |
---|
1415 | |
---|
1416 | for( UInt uiCtxInc = 0; uiCtxInc < 3*NUM_QT_CBF_CTX; uiCtxInc++ ) |
---|
1417 | { |
---|
1418 | pcEstBitsSbac->blockCbpBits[ uiCtxInc ][ 0 ] = pCtx[ uiCtxInc ].getEntropyBits( 0 ); |
---|
1419 | pcEstBitsSbac->blockCbpBits[ uiCtxInc ][ 1 ] = pCtx[ uiCtxInc ].getEntropyBits( 1 ); |
---|
1420 | } |
---|
1421 | |
---|
1422 | pCtx = m_cCUQtRootCbfSCModel.get( 0 ); |
---|
1423 | |
---|
1424 | for( UInt uiCtxInc = 0; uiCtxInc < 4; uiCtxInc++ ) |
---|
1425 | { |
---|
1426 | pcEstBitsSbac->blockRootCbpBits[ uiCtxInc ][ 0 ] = pCtx[ uiCtxInc ].getEntropyBits( 0 ); |
---|
1427 | pcEstBitsSbac->blockRootCbpBits[ uiCtxInc ][ 1 ] = pCtx[ uiCtxInc ].getEntropyBits( 1 ); |
---|
1428 | } |
---|
1429 | } |
---|
1430 | |
---|
1431 | |
---|
1432 | /*! |
---|
1433 | **************************************************************************** |
---|
1434 | * \brief |
---|
1435 | * estimate SAMBAC bit cost for significant coefficient group map |
---|
1436 | **************************************************************************** |
---|
1437 | */ |
---|
1438 | Void TEncSbac::estSignificantCoeffGroupMapBit( estBitsSbacStruct* pcEstBitsSbac, TextType eTType ) |
---|
1439 | { |
---|
1440 | Int firstCtx = 0, numCtx = NUM_SIG_CG_FLAG_CTX; |
---|
1441 | |
---|
1442 | for ( Int ctxIdx = firstCtx; ctxIdx < firstCtx + numCtx; ctxIdx++ ) |
---|
1443 | { |
---|
1444 | for( UInt uiBin = 0; uiBin < 2; uiBin++ ) |
---|
1445 | { |
---|
1446 | pcEstBitsSbac->significantCoeffGroupBits[ ctxIdx ][ uiBin ] = m_cCUSigCoeffGroupSCModel.get( 0, eTType, ctxIdx ).getEntropyBits( uiBin ); |
---|
1447 | } |
---|
1448 | } |
---|
1449 | } |
---|
1450 | |
---|
1451 | |
---|
1452 | /*! |
---|
1453 | **************************************************************************** |
---|
1454 | * \brief |
---|
1455 | * estimate SAMBAC bit cost for significant coefficient map |
---|
1456 | **************************************************************************** |
---|
1457 | */ |
---|
1458 | Void TEncSbac::estSignificantMapBit( estBitsSbacStruct* pcEstBitsSbac, Int width, Int height, TextType eTType ) |
---|
1459 | { |
---|
1460 | Int firstCtx = 1, numCtx = 8; |
---|
1461 | if (max(width, height) >= 16) |
---|
1462 | { |
---|
1463 | firstCtx = (eTType == TEXT_LUMA) ? 21 : 12; |
---|
1464 | numCtx = (eTType == TEXT_LUMA) ? 6 : 3; |
---|
1465 | } |
---|
1466 | else if (width == 8) |
---|
1467 | { |
---|
1468 | firstCtx = 9; |
---|
1469 | numCtx = (eTType == TEXT_LUMA) ? 12 : 3; |
---|
1470 | } |
---|
1471 | |
---|
1472 | if (eTType == TEXT_LUMA ) |
---|
1473 | { |
---|
1474 | for( UInt bin = 0; bin < 2; bin++ ) |
---|
1475 | { |
---|
1476 | pcEstBitsSbac->significantBits[ 0 ][ bin ] = m_cCUSigSCModel.get( 0, 0, 0 ).getEntropyBits( bin ); |
---|
1477 | } |
---|
1478 | |
---|
1479 | for ( Int ctxIdx = firstCtx; ctxIdx < firstCtx + numCtx; ctxIdx++ ) |
---|
1480 | { |
---|
1481 | for( UInt uiBin = 0; uiBin < 2; uiBin++ ) |
---|
1482 | { |
---|
1483 | pcEstBitsSbac->significantBits[ ctxIdx ][ uiBin ] = m_cCUSigSCModel.get( 0, 0, ctxIdx ).getEntropyBits( uiBin ); |
---|
1484 | } |
---|
1485 | } |
---|
1486 | } |
---|
1487 | else |
---|
1488 | { |
---|
1489 | for( UInt bin = 0; bin < 2; bin++ ) |
---|
1490 | { |
---|
1491 | pcEstBitsSbac->significantBits[ 0 ][ bin ] = m_cCUSigSCModel.get( 0, 0, NUM_SIG_FLAG_CTX_LUMA + 0 ).getEntropyBits( bin ); |
---|
1492 | } |
---|
1493 | for ( Int ctxIdx = firstCtx; ctxIdx < firstCtx + numCtx; ctxIdx++ ) |
---|
1494 | { |
---|
1495 | for( UInt uiBin = 0; uiBin < 2; uiBin++ ) |
---|
1496 | { |
---|
1497 | pcEstBitsSbac->significantBits[ ctxIdx ][ uiBin ] = m_cCUSigSCModel.get( 0, 0, NUM_SIG_FLAG_CTX_LUMA + ctxIdx ).getEntropyBits( uiBin ); |
---|
1498 | } |
---|
1499 | } |
---|
1500 | } |
---|
1501 | Int iBitsX = 0, iBitsY = 0; |
---|
1502 | Int blkSizeOffsetX, blkSizeOffsetY, shiftX, shiftY; |
---|
1503 | |
---|
1504 | blkSizeOffsetX = eTType ? 0: (g_aucConvertToBit[ width ] *3 + ((g_aucConvertToBit[ width ] +1)>>2)); |
---|
1505 | blkSizeOffsetY = eTType ? 0: (g_aucConvertToBit[ height ]*3 + ((g_aucConvertToBit[ height ]+1)>>2)); |
---|
1506 | shiftX = eTType ? g_aucConvertToBit[ width ] :((g_aucConvertToBit[ width ]+3)>>2); |
---|
1507 | shiftY = eTType ? g_aucConvertToBit[ height ] :((g_aucConvertToBit[ height ]+3)>>2); |
---|
1508 | |
---|
1509 | Int ctx; |
---|
1510 | ContextModel *pCtxX = m_cCuCtxLastX.get( 0, eTType ); |
---|
1511 | for (ctx = 0; ctx < g_uiGroupIdx[ width - 1 ]; ctx++) |
---|
1512 | { |
---|
1513 | Int ctxOffset = blkSizeOffsetX + (ctx >>shiftX); |
---|
1514 | pcEstBitsSbac->lastXBits[ ctx ] = iBitsX + pCtxX[ ctxOffset ].getEntropyBits( 0 ); |
---|
1515 | iBitsX += pCtxX[ ctxOffset ].getEntropyBits( 1 ); |
---|
1516 | } |
---|
1517 | pcEstBitsSbac->lastXBits[ctx] = iBitsX; |
---|
1518 | ContextModel *pCtxY = m_cCuCtxLastY.get( 0, eTType ); |
---|
1519 | for (ctx = 0; ctx < g_uiGroupIdx[ height - 1 ]; ctx++) |
---|
1520 | { |
---|
1521 | Int ctxOffset = blkSizeOffsetY + (ctx >>shiftY); |
---|
1522 | pcEstBitsSbac->lastYBits[ ctx ] = iBitsY + pCtxY[ ctxOffset ].getEntropyBits( 0 ); |
---|
1523 | iBitsY += pCtxY[ ctxOffset ].getEntropyBits( 1 ); |
---|
1524 | } |
---|
1525 | pcEstBitsSbac->lastYBits[ctx] = iBitsY; |
---|
1526 | } |
---|
1527 | |
---|
1528 | /*! |
---|
1529 | **************************************************************************** |
---|
1530 | * \brief |
---|
1531 | * estimate bit cost of significant coefficient |
---|
1532 | **************************************************************************** |
---|
1533 | */ |
---|
1534 | Void TEncSbac::estSignificantCoefficientsBit( estBitsSbacStruct* pcEstBitsSbac, TextType eTType ) |
---|
1535 | { |
---|
1536 | if (eTType==TEXT_LUMA) |
---|
1537 | { |
---|
1538 | ContextModel *ctxOne = m_cCUOneSCModel.get(0, 0); |
---|
1539 | ContextModel *ctxAbs = m_cCUAbsSCModel.get(0, 0); |
---|
1540 | |
---|
1541 | for (Int ctxIdx = 0; ctxIdx < NUM_ONE_FLAG_CTX_LUMA; ctxIdx++) |
---|
1542 | { |
---|
1543 | pcEstBitsSbac->m_greaterOneBits[ ctxIdx ][ 0 ] = ctxOne[ ctxIdx ].getEntropyBits( 0 ); |
---|
1544 | pcEstBitsSbac->m_greaterOneBits[ ctxIdx ][ 1 ] = ctxOne[ ctxIdx ].getEntropyBits( 1 ); |
---|
1545 | } |
---|
1546 | |
---|
1547 | for (Int ctxIdx = 0; ctxIdx < NUM_ABS_FLAG_CTX_LUMA; ctxIdx++) |
---|
1548 | { |
---|
1549 | pcEstBitsSbac->m_levelAbsBits[ ctxIdx ][ 0 ] = ctxAbs[ ctxIdx ].getEntropyBits( 0 ); |
---|
1550 | pcEstBitsSbac->m_levelAbsBits[ ctxIdx ][ 1 ] = ctxAbs[ ctxIdx ].getEntropyBits( 1 ); |
---|
1551 | } |
---|
1552 | } |
---|
1553 | else |
---|
1554 | { |
---|
1555 | ContextModel *ctxOne = m_cCUOneSCModel.get(0, 0) + NUM_ONE_FLAG_CTX_LUMA; |
---|
1556 | ContextModel *ctxAbs = m_cCUAbsSCModel.get(0, 0) + NUM_ABS_FLAG_CTX_LUMA; |
---|
1557 | |
---|
1558 | for (Int ctxIdx = 0; ctxIdx < NUM_ONE_FLAG_CTX_CHROMA; ctxIdx++) |
---|
1559 | { |
---|
1560 | pcEstBitsSbac->m_greaterOneBits[ ctxIdx ][ 0 ] = ctxOne[ ctxIdx ].getEntropyBits( 0 ); |
---|
1561 | pcEstBitsSbac->m_greaterOneBits[ ctxIdx ][ 1 ] = ctxOne[ ctxIdx ].getEntropyBits( 1 ); |
---|
1562 | } |
---|
1563 | |
---|
1564 | for (Int ctxIdx = 0; ctxIdx < NUM_ABS_FLAG_CTX_CHROMA; ctxIdx++) |
---|
1565 | { |
---|
1566 | pcEstBitsSbac->m_levelAbsBits[ ctxIdx ][ 0 ] = ctxAbs[ ctxIdx ].getEntropyBits( 0 ); |
---|
1567 | pcEstBitsSbac->m_levelAbsBits[ ctxIdx ][ 1 ] = ctxAbs[ ctxIdx ].getEntropyBits( 1 ); |
---|
1568 | } |
---|
1569 | } |
---|
1570 | } |
---|
1571 | |
---|
1572 | /** |
---|
1573 | - Initialize our context information from the nominated source. |
---|
1574 | . |
---|
1575 | \param pSrc From where to copy context information. |
---|
1576 | */ |
---|
1577 | Void TEncSbac::xCopyContextsFrom( TEncSbac* pSrc ) |
---|
1578 | { |
---|
1579 | memcpy(m_contextModels, pSrc->m_contextModels, m_numContextModels*sizeof(m_contextModels[0])); |
---|
1580 | } |
---|
1581 | |
---|
1582 | Void TEncSbac::loadContexts ( TEncSbac* pScr) |
---|
1583 | { |
---|
1584 | this->xCopyContextsFrom(pScr); |
---|
1585 | } |
---|
1586 | //! \} |
---|