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 | |
---|
419 | if ( pcCU->isIntra( uiAbsPartIdx ) ) |
---|
420 | { |
---|
421 | if( uiDepth == g_uiMaxCUDepth - g_uiAddCUDepth ) |
---|
422 | { |
---|
423 | m_pcBinIf->encodeBin( eSize == SIZE_2Nx2N? 1 : 0, m_cCUPartSizeSCModel.get( 0, 0, 0 ) ); |
---|
424 | } |
---|
425 | return; |
---|
426 | } |
---|
427 | |
---|
428 | switch(eSize) |
---|
429 | { |
---|
430 | case SIZE_2Nx2N: |
---|
431 | { |
---|
432 | m_pcBinIf->encodeBin( 1, m_cCUPartSizeSCModel.get( 0, 0, 0) ); |
---|
433 | break; |
---|
434 | } |
---|
435 | case SIZE_2NxN: |
---|
436 | case SIZE_2NxnU: |
---|
437 | case SIZE_2NxnD: |
---|
438 | { |
---|
439 | m_pcBinIf->encodeBin( 0, m_cCUPartSizeSCModel.get( 0, 0, 0) ); |
---|
440 | m_pcBinIf->encodeBin( 1, m_cCUPartSizeSCModel.get( 0, 0, 1) ); |
---|
441 | if ( pcCU->getSlice()->getSPS()->getAMPAcc( uiDepth ) ) |
---|
442 | { |
---|
443 | if (eSize == SIZE_2NxN) |
---|
444 | { |
---|
445 | m_pcBinIf->encodeBin(1, m_cCUAMPSCModel.get( 0, 0, 0 )); |
---|
446 | } |
---|
447 | else |
---|
448 | { |
---|
449 | m_pcBinIf->encodeBin(0, m_cCUAMPSCModel.get( 0, 0, 0 )); |
---|
450 | m_pcBinIf->encodeBinEP((eSize == SIZE_2NxnU? 0: 1)); |
---|
451 | } |
---|
452 | } |
---|
453 | break; |
---|
454 | } |
---|
455 | case SIZE_Nx2N: |
---|
456 | case SIZE_nLx2N: |
---|
457 | case SIZE_nRx2N: |
---|
458 | { |
---|
459 | m_pcBinIf->encodeBin( 0, m_cCUPartSizeSCModel.get( 0, 0, 0) ); |
---|
460 | m_pcBinIf->encodeBin( 0, m_cCUPartSizeSCModel.get( 0, 0, 1) ); |
---|
461 | if( uiDepth == g_uiMaxCUDepth - g_uiAddCUDepth && !( pcCU->getWidth(uiAbsPartIdx) == 8 && pcCU->getHeight(uiAbsPartIdx) == 8 ) ) |
---|
462 | { |
---|
463 | m_pcBinIf->encodeBin( 1, m_cCUPartSizeSCModel.get( 0, 0, 2) ); |
---|
464 | } |
---|
465 | if ( pcCU->getSlice()->getSPS()->getAMPAcc( uiDepth ) ) |
---|
466 | { |
---|
467 | if (eSize == SIZE_Nx2N) |
---|
468 | { |
---|
469 | m_pcBinIf->encodeBin(1, m_cCUAMPSCModel.get( 0, 0, 0 )); |
---|
470 | } |
---|
471 | else |
---|
472 | { |
---|
473 | m_pcBinIf->encodeBin(0, m_cCUAMPSCModel.get( 0, 0, 0 )); |
---|
474 | m_pcBinIf->encodeBinEP((eSize == SIZE_nLx2N? 0: 1)); |
---|
475 | } |
---|
476 | } |
---|
477 | break; |
---|
478 | } |
---|
479 | case SIZE_NxN: |
---|
480 | { |
---|
481 | if( uiDepth == g_uiMaxCUDepth - g_uiAddCUDepth && !( pcCU->getWidth(uiAbsPartIdx) == 8 && pcCU->getHeight(uiAbsPartIdx) == 8 ) ) |
---|
482 | { |
---|
483 | m_pcBinIf->encodeBin( 0, m_cCUPartSizeSCModel.get( 0, 0, 0) ); |
---|
484 | m_pcBinIf->encodeBin( 0, m_cCUPartSizeSCModel.get( 0, 0, 1) ); |
---|
485 | m_pcBinIf->encodeBin( 0, m_cCUPartSizeSCModel.get( 0, 0, 2) ); |
---|
486 | } |
---|
487 | break; |
---|
488 | } |
---|
489 | default: |
---|
490 | { |
---|
491 | assert(0); |
---|
492 | } |
---|
493 | } |
---|
494 | } |
---|
495 | |
---|
496 | /** code prediction mode |
---|
497 | * \param pcCU |
---|
498 | * \param uiAbsPartIdx |
---|
499 | * \returns Void |
---|
500 | */ |
---|
501 | Void TEncSbac::codePredMode( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
502 | { |
---|
503 | // get context function is here |
---|
504 | Int iPredMode = pcCU->getPredictionMode( uiAbsPartIdx ); |
---|
505 | m_pcBinIf->encodeBin( iPredMode == MODE_INTER ? 0 : 1, m_cCUPredModeSCModel.get( 0, 0, 0 ) ); |
---|
506 | } |
---|
507 | |
---|
508 | Void TEncSbac::codeCUTransquantBypassFlag( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
509 | { |
---|
510 | UInt uiSymbol = pcCU->getCUTransquantBypass(uiAbsPartIdx); |
---|
511 | m_pcBinIf->encodeBin( uiSymbol, m_CUTransquantBypassFlagSCModel.get( 0, 0, 0 ) ); |
---|
512 | } |
---|
513 | |
---|
514 | /** code skip flag |
---|
515 | * \param pcCU |
---|
516 | * \param uiAbsPartIdx |
---|
517 | * \returns Void |
---|
518 | */ |
---|
519 | Void TEncSbac::codeSkipFlag( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
520 | { |
---|
521 | // get context function is here |
---|
522 | UInt uiSymbol = pcCU->isSkipped( uiAbsPartIdx ) ? 1 : 0; |
---|
523 | UInt uiCtxSkip = pcCU->getCtxSkipFlag( uiAbsPartIdx ) ; |
---|
524 | m_pcBinIf->encodeBin( uiSymbol, m_cCUSkipFlagSCModel.get( 0, 0, uiCtxSkip ) ); |
---|
525 | DTRACE_CABAC_VL( g_nSymbolCounter++ ); |
---|
526 | DTRACE_CABAC_T( "\tSkipFlag" ); |
---|
527 | DTRACE_CABAC_T( "\tuiCtxSkip: "); |
---|
528 | DTRACE_CABAC_V( uiCtxSkip ); |
---|
529 | DTRACE_CABAC_T( "\tuiSymbol: "); |
---|
530 | DTRACE_CABAC_V( uiSymbol ); |
---|
531 | DTRACE_CABAC_T( "\n"); |
---|
532 | } |
---|
533 | |
---|
534 | /** code merge flag |
---|
535 | * \param pcCU |
---|
536 | * \param uiAbsPartIdx |
---|
537 | * \returns Void |
---|
538 | */ |
---|
539 | Void TEncSbac::codeMergeFlag( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
540 | { |
---|
541 | const UInt uiSymbol = pcCU->getMergeFlag( uiAbsPartIdx ) ? 1 : 0; |
---|
542 | m_pcBinIf->encodeBin( uiSymbol, *m_cCUMergeFlagExtSCModel.get( 0 ) ); |
---|
543 | |
---|
544 | DTRACE_CABAC_VL( g_nSymbolCounter++ ); |
---|
545 | DTRACE_CABAC_T( "\tMergeFlag: " ); |
---|
546 | DTRACE_CABAC_V( uiSymbol ); |
---|
547 | DTRACE_CABAC_T( "\tAddress: " ); |
---|
548 | DTRACE_CABAC_V( pcCU->getAddr() ); |
---|
549 | DTRACE_CABAC_T( "\tuiAbsPartIdx: " ); |
---|
550 | DTRACE_CABAC_V( uiAbsPartIdx ); |
---|
551 | DTRACE_CABAC_T( "\n" ); |
---|
552 | } |
---|
553 | |
---|
554 | /** code merge index |
---|
555 | * \param pcCU |
---|
556 | * \param uiAbsPartIdx |
---|
557 | * \returns Void |
---|
558 | */ |
---|
559 | Void TEncSbac::codeMergeIndex( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
560 | { |
---|
561 | UInt uiUnaryIdx = pcCU->getMergeIndex( uiAbsPartIdx ); |
---|
562 | UInt uiNumCand = pcCU->getSlice()->getMaxNumMergeCand(); |
---|
563 | if ( uiNumCand > 1 ) |
---|
564 | { |
---|
565 | for( UInt ui = 0; ui < uiNumCand - 1; ++ui ) |
---|
566 | { |
---|
567 | const UInt uiSymbol = ui == uiUnaryIdx ? 0 : 1; |
---|
568 | if ( ui==0 ) |
---|
569 | { |
---|
570 | m_pcBinIf->encodeBin( uiSymbol, m_cCUMergeIdxExtSCModel.get( 0, 0, 0 ) ); |
---|
571 | } |
---|
572 | else |
---|
573 | { |
---|
574 | m_pcBinIf->encodeBinEP( uiSymbol ); |
---|
575 | } |
---|
576 | if( uiSymbol == 0 ) |
---|
577 | { |
---|
578 | break; |
---|
579 | } |
---|
580 | } |
---|
581 | } |
---|
582 | DTRACE_CABAC_VL( g_nSymbolCounter++ ); |
---|
583 | DTRACE_CABAC_T( "\tparseMergeIndex()" ); |
---|
584 | DTRACE_CABAC_T( "\tuiMRGIdx= " ); |
---|
585 | DTRACE_CABAC_V( pcCU->getMergeIndex( uiAbsPartIdx ) ); |
---|
586 | DTRACE_CABAC_T( "\n" ); |
---|
587 | } |
---|
588 | |
---|
589 | Void TEncSbac::codeSplitFlag ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth ) |
---|
590 | { |
---|
591 | if( uiDepth == g_uiMaxCUDepth - g_uiAddCUDepth ) |
---|
592 | return; |
---|
593 | |
---|
594 | UInt uiCtx = pcCU->getCtxSplitFlag( uiAbsPartIdx, uiDepth ); |
---|
595 | UInt uiCurrSplitFlag = ( pcCU->getDepth( uiAbsPartIdx ) > uiDepth ) ? 1 : 0; |
---|
596 | |
---|
597 | assert( uiCtx < 3 ); |
---|
598 | m_pcBinIf->encodeBin( uiCurrSplitFlag, m_cCUSplitFlagSCModel.get( 0, 0, uiCtx ) ); |
---|
599 | DTRACE_CABAC_VL( g_nSymbolCounter++ ) |
---|
600 | DTRACE_CABAC_T( "\tSplitFlag\n" ) |
---|
601 | return; |
---|
602 | } |
---|
603 | |
---|
604 | Void TEncSbac::codeTransformSubdivFlag( UInt uiSymbol, UInt uiCtx ) |
---|
605 | { |
---|
606 | m_pcBinIf->encodeBin( uiSymbol, m_cCUTransSubdivFlagSCModel.get( 0, 0, uiCtx ) ); |
---|
607 | DTRACE_CABAC_VL( g_nSymbolCounter++ ) |
---|
608 | DTRACE_CABAC_T( "\tparseTransformSubdivFlag()" ) |
---|
609 | DTRACE_CABAC_T( "\tsymbol=" ) |
---|
610 | DTRACE_CABAC_V( uiSymbol ) |
---|
611 | DTRACE_CABAC_T( "\tctx=" ) |
---|
612 | DTRACE_CABAC_V( uiCtx ) |
---|
613 | DTRACE_CABAC_T( "\n" ) |
---|
614 | } |
---|
615 | |
---|
616 | Void TEncSbac::codeIntraDirLumaAng( TComDataCU* pcCU, UInt absPartIdx, Bool isMultiple) |
---|
617 | { |
---|
618 | UInt dir[4],j; |
---|
619 | Int preds[4][3] = {{-1, -1, -1},{-1, -1, -1},{-1, -1, -1},{-1, -1, -1}}; |
---|
620 | Int predNum[4], predIdx[4] ={ -1,-1,-1,-1}; |
---|
621 | PartSize mode = pcCU->getPartitionSize( absPartIdx ); |
---|
622 | UInt partNum = isMultiple?(mode==SIZE_NxN?4:1):1; |
---|
623 | UInt partOffset = ( pcCU->getPic()->getNumPartInCU() >> ( pcCU->getDepth(absPartIdx) << 1 ) ) >> 2; |
---|
624 | for (j=0;j<partNum;j++) |
---|
625 | { |
---|
626 | dir[j] = pcCU->getLumaIntraDir( absPartIdx+partOffset*j ); |
---|
627 | predNum[j] = pcCU->getIntraDirLumaPredictor(absPartIdx+partOffset*j, preds[j]); |
---|
628 | for(UInt i = 0; i < predNum[j]; i++) |
---|
629 | { |
---|
630 | if(dir[j] == preds[j][i]) |
---|
631 | { |
---|
632 | predIdx[j] = i; |
---|
633 | } |
---|
634 | } |
---|
635 | m_pcBinIf->encodeBin((predIdx[j] != -1)? 1 : 0, m_cCUIntraPredSCModel.get( 0, 0, 0 ) ); |
---|
636 | } |
---|
637 | for (j=0;j<partNum;j++) |
---|
638 | { |
---|
639 | if(predIdx[j] != -1) |
---|
640 | { |
---|
641 | m_pcBinIf->encodeBinEP( predIdx[j] ? 1 : 0 ); |
---|
642 | if (predIdx[j]) |
---|
643 | { |
---|
644 | m_pcBinIf->encodeBinEP( predIdx[j]-1 ); |
---|
645 | } |
---|
646 | } |
---|
647 | else |
---|
648 | { |
---|
649 | if (preds[j][0] > preds[j][1]) |
---|
650 | { |
---|
651 | std::swap(preds[j][0], preds[j][1]); |
---|
652 | } |
---|
653 | if (preds[j][0] > preds[j][2]) |
---|
654 | { |
---|
655 | std::swap(preds[j][0], preds[j][2]); |
---|
656 | } |
---|
657 | if (preds[j][1] > preds[j][2]) |
---|
658 | { |
---|
659 | std::swap(preds[j][1], preds[j][2]); |
---|
660 | } |
---|
661 | for(Int i = (predNum[j] - 1); i >= 0; i--) |
---|
662 | { |
---|
663 | dir[j] = dir[j] > preds[j][i] ? dir[j] - 1 : dir[j]; |
---|
664 | } |
---|
665 | m_pcBinIf->encodeBinsEP( dir[j], 5 ); |
---|
666 | } |
---|
667 | } |
---|
668 | return; |
---|
669 | } |
---|
670 | |
---|
671 | Void TEncSbac::codeIntraDirChroma( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
672 | { |
---|
673 | UInt uiIntraDirChroma = pcCU->getChromaIntraDir( uiAbsPartIdx ); |
---|
674 | |
---|
675 | if( uiIntraDirChroma == DM_CHROMA_IDX ) |
---|
676 | { |
---|
677 | m_pcBinIf->encodeBin( 0, m_cCUChromaPredSCModel.get( 0, 0, 0 ) ); |
---|
678 | } |
---|
679 | else |
---|
680 | { |
---|
681 | UInt uiAllowedChromaDir[ NUM_CHROMA_MODE ]; |
---|
682 | pcCU->getAllowedChromaDir( uiAbsPartIdx, uiAllowedChromaDir ); |
---|
683 | |
---|
684 | for( Int i = 0; i < NUM_CHROMA_MODE - 1; i++ ) |
---|
685 | { |
---|
686 | if( uiIntraDirChroma == uiAllowedChromaDir[i] ) |
---|
687 | { |
---|
688 | uiIntraDirChroma = i; |
---|
689 | break; |
---|
690 | } |
---|
691 | } |
---|
692 | m_pcBinIf->encodeBin( 1, m_cCUChromaPredSCModel.get( 0, 0, 0 ) ); |
---|
693 | |
---|
694 | m_pcBinIf->encodeBinsEP( uiIntraDirChroma, 2 ); |
---|
695 | } |
---|
696 | return; |
---|
697 | } |
---|
698 | |
---|
699 | Void TEncSbac::codeInterDir( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
700 | { |
---|
701 | const UInt uiInterDir = pcCU->getInterDir( uiAbsPartIdx ) - 1; |
---|
702 | const UInt uiCtx = pcCU->getCtxInterDir( uiAbsPartIdx ); |
---|
703 | ContextModel *pCtx = m_cCUInterDirSCModel.get( 0 ); |
---|
704 | if (pcCU->getPartitionSize(uiAbsPartIdx) == SIZE_2Nx2N || pcCU->getHeight(uiAbsPartIdx) != 8 ) |
---|
705 | { |
---|
706 | m_pcBinIf->encodeBin( uiInterDir == 2 ? 1 : 0, *( pCtx + uiCtx ) ); |
---|
707 | } |
---|
708 | if (uiInterDir < 2) |
---|
709 | { |
---|
710 | m_pcBinIf->encodeBin( uiInterDir, *( pCtx + 4 ) ); |
---|
711 | } |
---|
712 | return; |
---|
713 | } |
---|
714 | |
---|
715 | Void TEncSbac::codeRefFrmIdx( TComDataCU* pcCU, UInt uiAbsPartIdx, RefPicList eRefList ) |
---|
716 | { |
---|
717 | { |
---|
718 | Int iRefFrame = pcCU->getCUMvField( eRefList )->getRefIdx( uiAbsPartIdx ); |
---|
719 | ContextModel *pCtx = m_cCURefPicSCModel.get( 0 ); |
---|
720 | m_pcBinIf->encodeBin( ( iRefFrame == 0 ? 0 : 1 ), *pCtx ); |
---|
721 | |
---|
722 | if( iRefFrame > 0 ) |
---|
723 | { |
---|
724 | UInt uiRefNum = pcCU->getSlice()->getNumRefIdx( eRefList ) - 2; |
---|
725 | pCtx++; |
---|
726 | iRefFrame--; |
---|
727 | for( UInt ui = 0; ui < uiRefNum; ++ui ) |
---|
728 | { |
---|
729 | const UInt uiSymbol = ui == iRefFrame ? 0 : 1; |
---|
730 | if( ui == 0 ) |
---|
731 | { |
---|
732 | m_pcBinIf->encodeBin( uiSymbol, *pCtx ); |
---|
733 | } |
---|
734 | else |
---|
735 | { |
---|
736 | m_pcBinIf->encodeBinEP( uiSymbol ); |
---|
737 | } |
---|
738 | if( uiSymbol == 0 ) |
---|
739 | { |
---|
740 | break; |
---|
741 | } |
---|
742 | } |
---|
743 | } |
---|
744 | } |
---|
745 | return; |
---|
746 | } |
---|
747 | |
---|
748 | Void TEncSbac::codeMvd( TComDataCU* pcCU, UInt uiAbsPartIdx, RefPicList eRefList ) |
---|
749 | { |
---|
750 | if(pcCU->getSlice()->getMvdL1ZeroFlag() && eRefList == REF_PIC_LIST_1 && pcCU->getInterDir(uiAbsPartIdx)==3) |
---|
751 | { |
---|
752 | return; |
---|
753 | } |
---|
754 | |
---|
755 | const TComCUMvField* pcCUMvField = pcCU->getCUMvField( eRefList ); |
---|
756 | const Int iHor = pcCUMvField->getMvd( uiAbsPartIdx ).getHor(); |
---|
757 | const Int iVer = pcCUMvField->getMvd( uiAbsPartIdx ).getVer(); |
---|
758 | ContextModel* pCtx = m_cCUMvdSCModel.get( 0 ); |
---|
759 | |
---|
760 | m_pcBinIf->encodeBin( iHor != 0 ? 1 : 0, *pCtx ); |
---|
761 | m_pcBinIf->encodeBin( iVer != 0 ? 1 : 0, *pCtx ); |
---|
762 | |
---|
763 | const Bool bHorAbsGr0 = iHor != 0; |
---|
764 | const Bool bVerAbsGr0 = iVer != 0; |
---|
765 | const UInt uiHorAbs = 0 > iHor ? -iHor : iHor; |
---|
766 | const UInt uiVerAbs = 0 > iVer ? -iVer : iVer; |
---|
767 | pCtx++; |
---|
768 | |
---|
769 | if( bHorAbsGr0 ) |
---|
770 | { |
---|
771 | m_pcBinIf->encodeBin( uiHorAbs > 1 ? 1 : 0, *pCtx ); |
---|
772 | } |
---|
773 | |
---|
774 | if( bVerAbsGr0 ) |
---|
775 | { |
---|
776 | m_pcBinIf->encodeBin( uiVerAbs > 1 ? 1 : 0, *pCtx ); |
---|
777 | } |
---|
778 | |
---|
779 | if( bHorAbsGr0 ) |
---|
780 | { |
---|
781 | if( uiHorAbs > 1 ) |
---|
782 | { |
---|
783 | xWriteEpExGolomb( uiHorAbs-2, 1 ); |
---|
784 | } |
---|
785 | |
---|
786 | m_pcBinIf->encodeBinEP( 0 > iHor ? 1 : 0 ); |
---|
787 | } |
---|
788 | |
---|
789 | if( bVerAbsGr0 ) |
---|
790 | { |
---|
791 | if( uiVerAbs > 1 ) |
---|
792 | { |
---|
793 | xWriteEpExGolomb( uiVerAbs-2, 1 ); |
---|
794 | } |
---|
795 | |
---|
796 | m_pcBinIf->encodeBinEP( 0 > iVer ? 1 : 0 ); |
---|
797 | } |
---|
798 | |
---|
799 | return; |
---|
800 | } |
---|
801 | |
---|
802 | Void TEncSbac::codeDeltaQP( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
803 | { |
---|
804 | Int iDQp = pcCU->getQP( uiAbsPartIdx ) - pcCU->getRefQP( uiAbsPartIdx ); |
---|
805 | |
---|
806 | #if REPN_FORMAT_IN_VPS |
---|
807 | Int qpBdOffsetY = pcCU->getSlice()->getQpBDOffsetY(); |
---|
808 | #else |
---|
809 | Int qpBdOffsetY = pcCU->getSlice()->getSPS()->getQpBDOffsetY(); |
---|
810 | #endif |
---|
811 | iDQp = (iDQp + 78 + qpBdOffsetY + (qpBdOffsetY/2)) % (52 + qpBdOffsetY) - 26 - (qpBdOffsetY/2); |
---|
812 | |
---|
813 | UInt uiAbsDQp = (UInt)((iDQp > 0)? iDQp : (-iDQp)); |
---|
814 | UInt TUValue = min((Int)uiAbsDQp, CU_DQP_TU_CMAX); |
---|
815 | xWriteUnaryMaxSymbol( TUValue, &m_cCUDeltaQpSCModel.get( 0, 0, 0 ), 1, CU_DQP_TU_CMAX); |
---|
816 | if( uiAbsDQp >= CU_DQP_TU_CMAX ) |
---|
817 | { |
---|
818 | xWriteEpExGolomb( uiAbsDQp - CU_DQP_TU_CMAX, CU_DQP_EG_k ); |
---|
819 | } |
---|
820 | |
---|
821 | if ( uiAbsDQp > 0) |
---|
822 | { |
---|
823 | UInt uiSign = (iDQp > 0 ? 0 : 1); |
---|
824 | m_pcBinIf->encodeBinEP(uiSign); |
---|
825 | } |
---|
826 | |
---|
827 | return; |
---|
828 | } |
---|
829 | |
---|
830 | Void TEncSbac::codeQtCbf( TComDataCU* pcCU, UInt uiAbsPartIdx, TextType eType, UInt uiTrDepth ) |
---|
831 | { |
---|
832 | UInt uiCbf = pcCU->getCbf ( uiAbsPartIdx, eType, uiTrDepth ); |
---|
833 | UInt uiCtx = pcCU->getCtxQtCbf( eType, uiTrDepth ); |
---|
834 | m_pcBinIf->encodeBin( uiCbf , m_cCUQtCbfSCModel.get( 0, eType ? TEXT_CHROMA : eType, uiCtx ) ); |
---|
835 | DTRACE_CABAC_VL( g_nSymbolCounter++ ) |
---|
836 | DTRACE_CABAC_T( "\tparseQtCbf()" ) |
---|
837 | DTRACE_CABAC_T( "\tsymbol=" ) |
---|
838 | DTRACE_CABAC_V( uiCbf ) |
---|
839 | DTRACE_CABAC_T( "\tctx=" ) |
---|
840 | DTRACE_CABAC_V( uiCtx ) |
---|
841 | DTRACE_CABAC_T( "\tetype=" ) |
---|
842 | DTRACE_CABAC_V( eType ) |
---|
843 | DTRACE_CABAC_T( "\tuiAbsPartIdx=" ) |
---|
844 | DTRACE_CABAC_V( uiAbsPartIdx ) |
---|
845 | DTRACE_CABAC_T( "\n" ) |
---|
846 | } |
---|
847 | |
---|
848 | void TEncSbac::codeTransformSkipFlags (TComDataCU* pcCU, UInt uiAbsPartIdx, UInt width, UInt height, TextType eTType ) |
---|
849 | { |
---|
850 | if (pcCU->getCUTransquantBypass(uiAbsPartIdx)) |
---|
851 | { |
---|
852 | return; |
---|
853 | } |
---|
854 | if(width != 4 || height != 4) |
---|
855 | { |
---|
856 | return; |
---|
857 | } |
---|
858 | |
---|
859 | UInt useTransformSkip = pcCU->getTransformSkip( uiAbsPartIdx,eTType); |
---|
860 | m_pcBinIf->encodeBin( useTransformSkip, m_cTransformSkipSCModel.get( 0, eTType? TEXT_CHROMA: TEXT_LUMA, 0 ) ); |
---|
861 | DTRACE_CABAC_VL( g_nSymbolCounter++ ) |
---|
862 | DTRACE_CABAC_T("\tparseTransformSkip()"); |
---|
863 | DTRACE_CABAC_T( "\tsymbol=" ) |
---|
864 | DTRACE_CABAC_V( useTransformSkip ) |
---|
865 | DTRACE_CABAC_T( "\tAddr=" ) |
---|
866 | DTRACE_CABAC_V( pcCU->getAddr() ) |
---|
867 | DTRACE_CABAC_T( "\tetype=" ) |
---|
868 | DTRACE_CABAC_V( eTType ) |
---|
869 | DTRACE_CABAC_T( "\tuiAbsPartIdx=" ) |
---|
870 | DTRACE_CABAC_V( uiAbsPartIdx ) |
---|
871 | DTRACE_CABAC_T( "\n" ) |
---|
872 | } |
---|
873 | |
---|
874 | /** Code I_PCM information. |
---|
875 | * \param pcCU pointer to CU |
---|
876 | * \param uiAbsPartIdx CU index |
---|
877 | * \returns Void |
---|
878 | */ |
---|
879 | Void TEncSbac::codeIPCMInfo( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
880 | { |
---|
881 | UInt uiIPCM = (pcCU->getIPCMFlag(uiAbsPartIdx) == true)? 1 : 0; |
---|
882 | |
---|
883 | Bool writePCMSampleFlag = pcCU->getIPCMFlag(uiAbsPartIdx); |
---|
884 | |
---|
885 | m_pcBinIf->encodeBinTrm (uiIPCM); |
---|
886 | |
---|
887 | if (writePCMSampleFlag) |
---|
888 | { |
---|
889 | m_pcBinIf->encodePCMAlignBits(); |
---|
890 | |
---|
891 | UInt uiMinCoeffSize = pcCU->getPic()->getMinCUWidth()*pcCU->getPic()->getMinCUHeight(); |
---|
892 | UInt uiLumaOffset = uiMinCoeffSize*uiAbsPartIdx; |
---|
893 | UInt uiChromaOffset = uiLumaOffset>>2; |
---|
894 | Pel* piPCMSample; |
---|
895 | UInt uiWidth; |
---|
896 | UInt uiHeight; |
---|
897 | UInt uiSampleBits; |
---|
898 | UInt uiX, uiY; |
---|
899 | |
---|
900 | piPCMSample = pcCU->getPCMSampleY() + uiLumaOffset; |
---|
901 | uiWidth = pcCU->getWidth(uiAbsPartIdx); |
---|
902 | uiHeight = pcCU->getHeight(uiAbsPartIdx); |
---|
903 | uiSampleBits = pcCU->getSlice()->getSPS()->getPCMBitDepthLuma(); |
---|
904 | |
---|
905 | for(uiY = 0; uiY < uiHeight; uiY++) |
---|
906 | { |
---|
907 | for(uiX = 0; uiX < uiWidth; uiX++) |
---|
908 | { |
---|
909 | UInt uiSample = piPCMSample[uiX]; |
---|
910 | |
---|
911 | m_pcBinIf->xWritePCMCode(uiSample, uiSampleBits); |
---|
912 | } |
---|
913 | piPCMSample += uiWidth; |
---|
914 | } |
---|
915 | |
---|
916 | #if AUXILIARY_PICTURES |
---|
917 | if (pcCU->getSlice()->getChromaFormatIdc() != CHROMA_400) |
---|
918 | { |
---|
919 | #endif |
---|
920 | piPCMSample = pcCU->getPCMSampleCb() + uiChromaOffset; |
---|
921 | uiWidth = pcCU->getWidth(uiAbsPartIdx)/2; |
---|
922 | uiHeight = pcCU->getHeight(uiAbsPartIdx)/2; |
---|
923 | uiSampleBits = pcCU->getSlice()->getSPS()->getPCMBitDepthChroma(); |
---|
924 | |
---|
925 | for(uiY = 0; uiY < uiHeight; uiY++) |
---|
926 | { |
---|
927 | for(uiX = 0; uiX < uiWidth; uiX++) |
---|
928 | { |
---|
929 | UInt uiSample = piPCMSample[uiX]; |
---|
930 | |
---|
931 | m_pcBinIf->xWritePCMCode(uiSample, uiSampleBits); |
---|
932 | } |
---|
933 | piPCMSample += uiWidth; |
---|
934 | } |
---|
935 | |
---|
936 | piPCMSample = pcCU->getPCMSampleCr() + uiChromaOffset; |
---|
937 | uiWidth = pcCU->getWidth(uiAbsPartIdx)/2; |
---|
938 | uiHeight = pcCU->getHeight(uiAbsPartIdx)/2; |
---|
939 | uiSampleBits = pcCU->getSlice()->getSPS()->getPCMBitDepthChroma(); |
---|
940 | |
---|
941 | for(uiY = 0; uiY < uiHeight; uiY++) |
---|
942 | { |
---|
943 | for(uiX = 0; uiX < uiWidth; uiX++) |
---|
944 | { |
---|
945 | UInt uiSample = piPCMSample[uiX]; |
---|
946 | |
---|
947 | m_pcBinIf->xWritePCMCode(uiSample, uiSampleBits); |
---|
948 | } |
---|
949 | piPCMSample += uiWidth; |
---|
950 | } |
---|
951 | #if AUXILIARY_PICTURES |
---|
952 | } |
---|
953 | #endif |
---|
954 | m_pcBinIf->resetBac(); |
---|
955 | } |
---|
956 | } |
---|
957 | |
---|
958 | Void TEncSbac::codeQtRootCbf( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
959 | { |
---|
960 | UInt uiCbf = pcCU->getQtRootCbf( uiAbsPartIdx ); |
---|
961 | UInt uiCtx = 0; |
---|
962 | m_pcBinIf->encodeBin( uiCbf , m_cCUQtRootCbfSCModel.get( 0, 0, uiCtx ) ); |
---|
963 | DTRACE_CABAC_VL( g_nSymbolCounter++ ) |
---|
964 | DTRACE_CABAC_T( "\tparseQtRootCbf()" ) |
---|
965 | DTRACE_CABAC_T( "\tsymbol=" ) |
---|
966 | DTRACE_CABAC_V( uiCbf ) |
---|
967 | DTRACE_CABAC_T( "\tctx=" ) |
---|
968 | DTRACE_CABAC_V( uiCtx ) |
---|
969 | DTRACE_CABAC_T( "\tuiAbsPartIdx=" ) |
---|
970 | DTRACE_CABAC_V( uiAbsPartIdx ) |
---|
971 | DTRACE_CABAC_T( "\n" ) |
---|
972 | } |
---|
973 | |
---|
974 | Void TEncSbac::codeQtCbfZero( TComDataCU* pcCU, TextType eType, UInt uiTrDepth ) |
---|
975 | { |
---|
976 | // this function is only used to estimate the bits when cbf is 0 |
---|
977 | // and will never be called when writing the bistream. do not need to write log |
---|
978 | UInt uiCbf = 0; |
---|
979 | UInt uiCtx = pcCU->getCtxQtCbf( eType, uiTrDepth ); |
---|
980 | m_pcBinIf->encodeBin( uiCbf , m_cCUQtCbfSCModel.get( 0, eType ? TEXT_CHROMA : eType, uiCtx ) ); |
---|
981 | } |
---|
982 | |
---|
983 | Void TEncSbac::codeQtRootCbfZero( TComDataCU* pcCU ) |
---|
984 | { |
---|
985 | // this function is only used to estimate the bits when cbf is 0 |
---|
986 | // and will never be called when writing the bistream. do not need to write log |
---|
987 | UInt uiCbf = 0; |
---|
988 | UInt uiCtx = 0; |
---|
989 | m_pcBinIf->encodeBin( uiCbf , m_cCUQtRootCbfSCModel.get( 0, 0, uiCtx ) ); |
---|
990 | } |
---|
991 | |
---|
992 | /** Encode (X,Y) position of the last significant coefficient |
---|
993 | * \param uiPosX X component of last coefficient |
---|
994 | * \param uiPosY Y component of last coefficient |
---|
995 | * \param width Block width |
---|
996 | * \param height Block height |
---|
997 | * \param eTType plane type / luminance or chrominance |
---|
998 | * \param uiScanIdx scan type (zig-zag, hor, ver) |
---|
999 | * This method encodes the X and Y component within a block of the last significant coefficient. |
---|
1000 | */ |
---|
1001 | Void TEncSbac::codeLastSignificantXY( UInt uiPosX, UInt uiPosY, Int width, Int height, TextType eTType, UInt uiScanIdx ) |
---|
1002 | { |
---|
1003 | // swap |
---|
1004 | if( uiScanIdx == SCAN_VER ) |
---|
1005 | { |
---|
1006 | swap( uiPosX, uiPosY ); |
---|
1007 | } |
---|
1008 | |
---|
1009 | UInt uiCtxLast; |
---|
1010 | ContextModel *pCtxX = m_cCuCtxLastX.get( 0, eTType ); |
---|
1011 | ContextModel *pCtxY = m_cCuCtxLastY.get( 0, eTType ); |
---|
1012 | UInt uiGroupIdxX = g_uiGroupIdx[ uiPosX ]; |
---|
1013 | UInt uiGroupIdxY = g_uiGroupIdx[ uiPosY ]; |
---|
1014 | |
---|
1015 | |
---|
1016 | Int blkSizeOffsetX, blkSizeOffsetY, shiftX, shiftY; |
---|
1017 | blkSizeOffsetX = eTType ? 0: (g_aucConvertToBit[ width ] *3 + ((g_aucConvertToBit[ width ] +1)>>2)); |
---|
1018 | blkSizeOffsetY = eTType ? 0: (g_aucConvertToBit[ height ]*3 + ((g_aucConvertToBit[ height ]+1)>>2)); |
---|
1019 | shiftX= eTType ? g_aucConvertToBit[ width ] :((g_aucConvertToBit[ width ]+3)>>2); |
---|
1020 | shiftY= eTType ? g_aucConvertToBit[ height ] :((g_aucConvertToBit[ height ]+3)>>2); |
---|
1021 | // posX |
---|
1022 | for( uiCtxLast = 0; uiCtxLast < uiGroupIdxX; uiCtxLast++ ) |
---|
1023 | { |
---|
1024 | m_pcBinIf->encodeBin( 1, *( pCtxX + blkSizeOffsetX + (uiCtxLast >>shiftX) ) ); |
---|
1025 | } |
---|
1026 | if( uiGroupIdxX < g_uiGroupIdx[ width - 1 ]) |
---|
1027 | { |
---|
1028 | m_pcBinIf->encodeBin( 0, *( pCtxX + blkSizeOffsetX + (uiCtxLast >>shiftX) ) ); |
---|
1029 | } |
---|
1030 | |
---|
1031 | // posY |
---|
1032 | for( uiCtxLast = 0; uiCtxLast < uiGroupIdxY; uiCtxLast++ ) |
---|
1033 | { |
---|
1034 | m_pcBinIf->encodeBin( 1, *( pCtxY + blkSizeOffsetY + (uiCtxLast >>shiftY) ) ); |
---|
1035 | } |
---|
1036 | if( uiGroupIdxY < g_uiGroupIdx[ height - 1 ]) |
---|
1037 | { |
---|
1038 | m_pcBinIf->encodeBin( 0, *( pCtxY + blkSizeOffsetY + (uiCtxLast >>shiftY) ) ); |
---|
1039 | } |
---|
1040 | if ( uiGroupIdxX > 3 ) |
---|
1041 | { |
---|
1042 | UInt uiCount = ( uiGroupIdxX - 2 ) >> 1; |
---|
1043 | uiPosX = uiPosX - g_uiMinInGroup[ uiGroupIdxX ]; |
---|
1044 | for (Int i = uiCount - 1 ; i >= 0; i-- ) |
---|
1045 | { |
---|
1046 | m_pcBinIf->encodeBinEP( ( uiPosX >> i ) & 1 ); |
---|
1047 | } |
---|
1048 | } |
---|
1049 | if ( uiGroupIdxY > 3 ) |
---|
1050 | { |
---|
1051 | UInt uiCount = ( uiGroupIdxY - 2 ) >> 1; |
---|
1052 | uiPosY = uiPosY - g_uiMinInGroup[ uiGroupIdxY ]; |
---|
1053 | for ( Int i = uiCount - 1 ; i >= 0; i-- ) |
---|
1054 | { |
---|
1055 | m_pcBinIf->encodeBinEP( ( uiPosY >> i ) & 1 ); |
---|
1056 | } |
---|
1057 | } |
---|
1058 | } |
---|
1059 | |
---|
1060 | Void TEncSbac::codeCoeffNxN( TComDataCU* pcCU, TCoeff* pcCoef, UInt uiAbsPartIdx, UInt uiWidth, UInt uiHeight, UInt uiDepth, TextType eTType ) |
---|
1061 | { |
---|
1062 | DTRACE_CABAC_VL( g_nSymbolCounter++ ) |
---|
1063 | DTRACE_CABAC_T( "\tparseCoeffNxN()\teType=" ) |
---|
1064 | DTRACE_CABAC_V( eTType ) |
---|
1065 | DTRACE_CABAC_T( "\twidth=" ) |
---|
1066 | DTRACE_CABAC_V( uiWidth ) |
---|
1067 | DTRACE_CABAC_T( "\theight=" ) |
---|
1068 | DTRACE_CABAC_V( uiHeight ) |
---|
1069 | DTRACE_CABAC_T( "\tdepth=" ) |
---|
1070 | DTRACE_CABAC_V( uiDepth ) |
---|
1071 | DTRACE_CABAC_T( "\tabspartidx=" ) |
---|
1072 | DTRACE_CABAC_V( uiAbsPartIdx ) |
---|
1073 | DTRACE_CABAC_T( "\ttoCU-X=" ) |
---|
1074 | DTRACE_CABAC_V( pcCU->getCUPelX() ) |
---|
1075 | DTRACE_CABAC_T( "\ttoCU-Y=" ) |
---|
1076 | DTRACE_CABAC_V( pcCU->getCUPelY() ) |
---|
1077 | DTRACE_CABAC_T( "\tCU-addr=" ) |
---|
1078 | DTRACE_CABAC_V( pcCU->getAddr() ) |
---|
1079 | DTRACE_CABAC_T( "\tinCU-X=" ) |
---|
1080 | DTRACE_CABAC_V( g_auiRasterToPelX[ g_auiZscanToRaster[uiAbsPartIdx] ] ) |
---|
1081 | DTRACE_CABAC_T( "\tinCU-Y=" ) |
---|
1082 | DTRACE_CABAC_V( g_auiRasterToPelY[ g_auiZscanToRaster[uiAbsPartIdx] ] ) |
---|
1083 | DTRACE_CABAC_T( "\tpredmode=" ) |
---|
1084 | DTRACE_CABAC_V( pcCU->getPredictionMode( uiAbsPartIdx ) ) |
---|
1085 | DTRACE_CABAC_T( "\n" ) |
---|
1086 | |
---|
1087 | if( uiWidth > m_pcSlice->getSPS()->getMaxTrSize() ) |
---|
1088 | { |
---|
1089 | uiWidth = m_pcSlice->getSPS()->getMaxTrSize(); |
---|
1090 | uiHeight = m_pcSlice->getSPS()->getMaxTrSize(); |
---|
1091 | } |
---|
1092 | |
---|
1093 | UInt uiNumSig = 0; |
---|
1094 | |
---|
1095 | // compute number of significant coefficients |
---|
1096 | uiNumSig = TEncEntropy::countNonZeroCoeffs(pcCoef, uiWidth * uiHeight); |
---|
1097 | |
---|
1098 | if ( uiNumSig == 0 ) |
---|
1099 | return; |
---|
1100 | if(pcCU->getSlice()->getPPS()->getUseTransformSkip()) |
---|
1101 | { |
---|
1102 | codeTransformSkipFlags( pcCU,uiAbsPartIdx, uiWidth, uiHeight, eTType ); |
---|
1103 | } |
---|
1104 | eTType = eTType == TEXT_LUMA ? TEXT_LUMA : ( eTType == TEXT_NONE ? TEXT_NONE : TEXT_CHROMA ); |
---|
1105 | |
---|
1106 | //----- encode significance map ----- |
---|
1107 | const UInt uiLog2BlockSize = g_aucConvertToBit[ uiWidth ] + 2; |
---|
1108 | UInt uiScanIdx = pcCU->getCoefScanIdx(uiAbsPartIdx, uiWidth, eTType==TEXT_LUMA, pcCU->isIntra(uiAbsPartIdx)); |
---|
1109 | const UInt *scan = g_auiSigLastScan[ uiScanIdx ][ uiLog2BlockSize - 1 ]; |
---|
1110 | |
---|
1111 | Bool beValid; |
---|
1112 | if (pcCU->getCUTransquantBypass(uiAbsPartIdx)) |
---|
1113 | { |
---|
1114 | beValid = false; |
---|
1115 | } |
---|
1116 | else |
---|
1117 | { |
---|
1118 | beValid = pcCU->getSlice()->getPPS()->getSignHideFlag() > 0; |
---|
1119 | } |
---|
1120 | |
---|
1121 | // Find position of last coefficient |
---|
1122 | Int scanPosLast = -1; |
---|
1123 | Int posLast; |
---|
1124 | |
---|
1125 | const UInt * scanCG; |
---|
1126 | { |
---|
1127 | scanCG = g_auiSigLastScan[ uiScanIdx ][ uiLog2BlockSize > 3 ? uiLog2BlockSize-2-1 : 0 ]; |
---|
1128 | if( uiLog2BlockSize == 3 ) |
---|
1129 | { |
---|
1130 | scanCG = g_sigLastScan8x8[ uiScanIdx ]; |
---|
1131 | } |
---|
1132 | else if( uiLog2BlockSize == 5 ) |
---|
1133 | { |
---|
1134 | scanCG = g_sigLastScanCG32x32; |
---|
1135 | } |
---|
1136 | } |
---|
1137 | UInt uiSigCoeffGroupFlag[ MLS_GRP_NUM ]; |
---|
1138 | static const UInt uiShift = MLS_CG_SIZE >> 1; |
---|
1139 | const UInt uiNumBlkSide = uiWidth >> uiShift; |
---|
1140 | |
---|
1141 | ::memset( uiSigCoeffGroupFlag, 0, sizeof(UInt) * MLS_GRP_NUM ); |
---|
1142 | |
---|
1143 | do |
---|
1144 | { |
---|
1145 | posLast = scan[ ++scanPosLast ]; |
---|
1146 | |
---|
1147 | // get L1 sig map |
---|
1148 | UInt uiPosY = posLast >> uiLog2BlockSize; |
---|
1149 | UInt uiPosX = posLast - ( uiPosY << uiLog2BlockSize ); |
---|
1150 | UInt uiBlkIdx = uiNumBlkSide * (uiPosY >> uiShift) + (uiPosX >> uiShift); |
---|
1151 | if( pcCoef[ posLast ] ) |
---|
1152 | { |
---|
1153 | uiSigCoeffGroupFlag[ uiBlkIdx ] = 1; |
---|
1154 | } |
---|
1155 | |
---|
1156 | uiNumSig -= ( pcCoef[ posLast ] != 0 ); |
---|
1157 | } |
---|
1158 | while ( uiNumSig > 0 ); |
---|
1159 | |
---|
1160 | // Code position of last coefficient |
---|
1161 | Int posLastY = posLast >> uiLog2BlockSize; |
---|
1162 | Int posLastX = posLast - ( posLastY << uiLog2BlockSize ); |
---|
1163 | codeLastSignificantXY(posLastX, posLastY, uiWidth, uiHeight, eTType, uiScanIdx); |
---|
1164 | |
---|
1165 | //===== code significance flag ===== |
---|
1166 | ContextModel * const baseCoeffGroupCtx = m_cCUSigCoeffGroupSCModel.get( 0, eTType ); |
---|
1167 | ContextModel * const baseCtx = (eTType==TEXT_LUMA) ? m_cCUSigSCModel.get( 0, 0 ) : m_cCUSigSCModel.get( 0, 0 ) + NUM_SIG_FLAG_CTX_LUMA; |
---|
1168 | |
---|
1169 | |
---|
1170 | const Int iLastScanSet = scanPosLast >> LOG2_SCAN_SET_SIZE; |
---|
1171 | UInt c1 = 1; |
---|
1172 | UInt uiGoRiceParam = 0; |
---|
1173 | Int iScanPosSig = scanPosLast; |
---|
1174 | |
---|
1175 | for( Int iSubSet = iLastScanSet; iSubSet >= 0; iSubSet-- ) |
---|
1176 | { |
---|
1177 | Int numNonZero = 0; |
---|
1178 | Int iSubPos = iSubSet << LOG2_SCAN_SET_SIZE; |
---|
1179 | uiGoRiceParam = 0; |
---|
1180 | Int absCoeff[16]; |
---|
1181 | UInt coeffSigns = 0; |
---|
1182 | |
---|
1183 | Int lastNZPosInCG = -1, firstNZPosInCG = SCAN_SET_SIZE; |
---|
1184 | |
---|
1185 | if( iScanPosSig == scanPosLast ) |
---|
1186 | { |
---|
1187 | absCoeff[ 0 ] = abs( pcCoef[ posLast ] ); |
---|
1188 | coeffSigns = ( pcCoef[ posLast ] < 0 ); |
---|
1189 | numNonZero = 1; |
---|
1190 | lastNZPosInCG = iScanPosSig; |
---|
1191 | firstNZPosInCG = iScanPosSig; |
---|
1192 | iScanPosSig--; |
---|
1193 | } |
---|
1194 | |
---|
1195 | // encode significant_coeffgroup_flag |
---|
1196 | Int iCGBlkPos = scanCG[ iSubSet ]; |
---|
1197 | Int iCGPosY = iCGBlkPos / uiNumBlkSide; |
---|
1198 | Int iCGPosX = iCGBlkPos - (iCGPosY * uiNumBlkSide); |
---|
1199 | if( iSubSet == iLastScanSet || iSubSet == 0) |
---|
1200 | { |
---|
1201 | uiSigCoeffGroupFlag[ iCGBlkPos ] = 1; |
---|
1202 | } |
---|
1203 | else |
---|
1204 | { |
---|
1205 | UInt uiSigCoeffGroup = (uiSigCoeffGroupFlag[ iCGBlkPos ] != 0); |
---|
1206 | UInt uiCtxSig = TComTrQuant::getSigCoeffGroupCtxInc( uiSigCoeffGroupFlag, iCGPosX, iCGPosY, uiWidth, uiHeight ); |
---|
1207 | m_pcBinIf->encodeBin( uiSigCoeffGroup, baseCoeffGroupCtx[ uiCtxSig ] ); |
---|
1208 | } |
---|
1209 | |
---|
1210 | // encode significant_coeff_flag |
---|
1211 | if( uiSigCoeffGroupFlag[ iCGBlkPos ] ) |
---|
1212 | { |
---|
1213 | Int patternSigCtx = TComTrQuant::calcPatternSigCtx( uiSigCoeffGroupFlag, iCGPosX, iCGPosY, uiWidth, uiHeight ); |
---|
1214 | UInt uiBlkPos, uiPosY, uiPosX, uiSig, uiCtxSig; |
---|
1215 | for( ; iScanPosSig >= iSubPos; iScanPosSig-- ) |
---|
1216 | { |
---|
1217 | uiBlkPos = scan[ iScanPosSig ]; |
---|
1218 | uiPosY = uiBlkPos >> uiLog2BlockSize; |
---|
1219 | uiPosX = uiBlkPos - ( uiPosY << uiLog2BlockSize ); |
---|
1220 | uiSig = (pcCoef[ uiBlkPos ] != 0); |
---|
1221 | if( iScanPosSig > iSubPos || iSubSet == 0 || numNonZero ) |
---|
1222 | { |
---|
1223 | uiCtxSig = TComTrQuant::getSigCtxInc( patternSigCtx, uiScanIdx, uiPosX, uiPosY, uiLog2BlockSize, eTType ); |
---|
1224 | m_pcBinIf->encodeBin( uiSig, baseCtx[ uiCtxSig ] ); |
---|
1225 | } |
---|
1226 | if( uiSig ) |
---|
1227 | { |
---|
1228 | absCoeff[ numNonZero ] = abs( pcCoef[ uiBlkPos ] ); |
---|
1229 | coeffSigns = 2 * coeffSigns + ( pcCoef[ uiBlkPos ] < 0 ); |
---|
1230 | numNonZero++; |
---|
1231 | if( lastNZPosInCG == -1 ) |
---|
1232 | { |
---|
1233 | lastNZPosInCG = iScanPosSig; |
---|
1234 | } |
---|
1235 | firstNZPosInCG = iScanPosSig; |
---|
1236 | } |
---|
1237 | } |
---|
1238 | } |
---|
1239 | else |
---|
1240 | { |
---|
1241 | iScanPosSig = iSubPos - 1; |
---|
1242 | } |
---|
1243 | |
---|
1244 | if( numNonZero > 0 ) |
---|
1245 | { |
---|
1246 | Bool signHidden = ( lastNZPosInCG - firstNZPosInCG >= SBH_THRESHOLD ); |
---|
1247 | UInt uiCtxSet = (iSubSet > 0 && eTType==TEXT_LUMA) ? 2 : 0; |
---|
1248 | |
---|
1249 | if( c1 == 0 ) |
---|
1250 | { |
---|
1251 | uiCtxSet++; |
---|
1252 | } |
---|
1253 | c1 = 1; |
---|
1254 | ContextModel *baseCtxMod = ( eTType==TEXT_LUMA ) ? m_cCUOneSCModel.get( 0, 0 ) + 4 * uiCtxSet : m_cCUOneSCModel.get( 0, 0 ) + NUM_ONE_FLAG_CTX_LUMA + 4 * uiCtxSet; |
---|
1255 | |
---|
1256 | Int numC1Flag = min(numNonZero, C1FLAG_NUMBER); |
---|
1257 | Int firstC2FlagIdx = -1; |
---|
1258 | for( Int idx = 0; idx < numC1Flag; idx++ ) |
---|
1259 | { |
---|
1260 | UInt uiSymbol = absCoeff[ idx ] > 1; |
---|
1261 | m_pcBinIf->encodeBin( uiSymbol, baseCtxMod[c1] ); |
---|
1262 | if( uiSymbol ) |
---|
1263 | { |
---|
1264 | c1 = 0; |
---|
1265 | |
---|
1266 | if (firstC2FlagIdx == -1) |
---|
1267 | { |
---|
1268 | firstC2FlagIdx = idx; |
---|
1269 | } |
---|
1270 | } |
---|
1271 | else if( (c1 < 3) && (c1 > 0) ) |
---|
1272 | { |
---|
1273 | c1++; |
---|
1274 | } |
---|
1275 | } |
---|
1276 | |
---|
1277 | if (c1 == 0) |
---|
1278 | { |
---|
1279 | |
---|
1280 | baseCtxMod = ( eTType==TEXT_LUMA ) ? m_cCUAbsSCModel.get( 0, 0 ) + uiCtxSet : m_cCUAbsSCModel.get( 0, 0 ) + NUM_ABS_FLAG_CTX_LUMA + uiCtxSet; |
---|
1281 | if ( firstC2FlagIdx != -1) |
---|
1282 | { |
---|
1283 | UInt symbol = absCoeff[ firstC2FlagIdx ] > 2; |
---|
1284 | m_pcBinIf->encodeBin( symbol, baseCtxMod[0] ); |
---|
1285 | } |
---|
1286 | } |
---|
1287 | |
---|
1288 | if( beValid && signHidden ) |
---|
1289 | { |
---|
1290 | m_pcBinIf->encodeBinsEP( (coeffSigns >> 1), numNonZero-1 ); |
---|
1291 | } |
---|
1292 | else |
---|
1293 | { |
---|
1294 | m_pcBinIf->encodeBinsEP( coeffSigns, numNonZero ); |
---|
1295 | } |
---|
1296 | |
---|
1297 | Int iFirstCoeff2 = 1; |
---|
1298 | if (c1 == 0 || numNonZero > C1FLAG_NUMBER) |
---|
1299 | { |
---|
1300 | for ( Int idx = 0; idx < numNonZero; idx++ ) |
---|
1301 | { |
---|
1302 | UInt baseLevel = (idx < C1FLAG_NUMBER)? (2 + iFirstCoeff2 ) : 1; |
---|
1303 | |
---|
1304 | if( absCoeff[ idx ] >= baseLevel) |
---|
1305 | { |
---|
1306 | xWriteCoefRemainExGolomb( absCoeff[ idx ] - baseLevel, uiGoRiceParam ); |
---|
1307 | if(absCoeff[idx] > 3*(1<<uiGoRiceParam)) |
---|
1308 | { |
---|
1309 | uiGoRiceParam = min<UInt>(uiGoRiceParam+ 1, 4); |
---|
1310 | } |
---|
1311 | } |
---|
1312 | if(absCoeff[ idx ] >= 2) |
---|
1313 | { |
---|
1314 | iFirstCoeff2 = 0; |
---|
1315 | } |
---|
1316 | } |
---|
1317 | } |
---|
1318 | } |
---|
1319 | } |
---|
1320 | |
---|
1321 | return; |
---|
1322 | } |
---|
1323 | |
---|
1324 | /** code SAO offset sign |
---|
1325 | * \param code sign value |
---|
1326 | */ |
---|
1327 | Void TEncSbac::codeSAOSign( UInt code ) |
---|
1328 | { |
---|
1329 | m_pcBinIf->encodeBinEP( code ); |
---|
1330 | } |
---|
1331 | |
---|
1332 | Void TEncSbac::codeSaoMaxUvlc ( UInt code, UInt maxSymbol ) |
---|
1333 | { |
---|
1334 | if (maxSymbol == 0) |
---|
1335 | { |
---|
1336 | return; |
---|
1337 | } |
---|
1338 | |
---|
1339 | Int i; |
---|
1340 | Bool bCodeLast = ( maxSymbol > code ); |
---|
1341 | |
---|
1342 | if ( code == 0 ) |
---|
1343 | { |
---|
1344 | m_pcBinIf->encodeBinEP( 0 ); |
---|
1345 | } |
---|
1346 | else |
---|
1347 | { |
---|
1348 | m_pcBinIf->encodeBinEP( 1 ); |
---|
1349 | for ( i=0; i<code-1; i++ ) |
---|
1350 | { |
---|
1351 | m_pcBinIf->encodeBinEP( 1 ); |
---|
1352 | } |
---|
1353 | if( bCodeLast ) |
---|
1354 | { |
---|
1355 | m_pcBinIf->encodeBinEP( 0 ); |
---|
1356 | } |
---|
1357 | } |
---|
1358 | } |
---|
1359 | |
---|
1360 | |
---|
1361 | /** Code SAO EO class or BO band position |
---|
1362 | * \param uiLength |
---|
1363 | * \param uiCode |
---|
1364 | */ |
---|
1365 | Void TEncSbac::codeSaoUflc ( UInt uiLength, UInt uiCode ) |
---|
1366 | { |
---|
1367 | m_pcBinIf->encodeBinsEP ( uiCode, uiLength ); |
---|
1368 | } |
---|
1369 | /** Code SAO merge flags |
---|
1370 | * \param uiCode |
---|
1371 | * \param uiCompIdx |
---|
1372 | */ |
---|
1373 | Void TEncSbac::codeSaoMerge ( UInt uiCode ) |
---|
1374 | { |
---|
1375 | if (uiCode == 0) |
---|
1376 | { |
---|
1377 | m_pcBinIf->encodeBin(0, m_cSaoMergeSCModel.get( 0, 0, 0 )); |
---|
1378 | } |
---|
1379 | else |
---|
1380 | { |
---|
1381 | m_pcBinIf->encodeBin(1, m_cSaoMergeSCModel.get( 0, 0, 0 )); |
---|
1382 | } |
---|
1383 | } |
---|
1384 | /** Code SAO type index |
---|
1385 | * \param uiCode |
---|
1386 | */ |
---|
1387 | Void TEncSbac::codeSaoTypeIdx ( UInt uiCode) |
---|
1388 | { |
---|
1389 | if (uiCode == 0) |
---|
1390 | { |
---|
1391 | m_pcBinIf->encodeBin( 0, m_cSaoTypeIdxSCModel.get( 0, 0, 0 ) ); |
---|
1392 | } |
---|
1393 | else |
---|
1394 | { |
---|
1395 | m_pcBinIf->encodeBin( 1, m_cSaoTypeIdxSCModel.get( 0, 0, 0 ) ); |
---|
1396 | m_pcBinIf->encodeBinEP( uiCode <= 4 ? 1 : 0 ); |
---|
1397 | } |
---|
1398 | } |
---|
1399 | /*! |
---|
1400 | **************************************************************************** |
---|
1401 | * \brief |
---|
1402 | * estimate bit cost for CBP, significant map and significant coefficients |
---|
1403 | **************************************************************************** |
---|
1404 | */ |
---|
1405 | Void TEncSbac::estBit( estBitsSbacStruct* pcEstBitsSbac, Int width, Int height, TextType eTType ) |
---|
1406 | { |
---|
1407 | estCBFBit( pcEstBitsSbac ); |
---|
1408 | |
---|
1409 | estSignificantCoeffGroupMapBit( pcEstBitsSbac, eTType ); |
---|
1410 | |
---|
1411 | // encode significance map |
---|
1412 | estSignificantMapBit( pcEstBitsSbac, width, height, eTType ); |
---|
1413 | |
---|
1414 | // encode significant coefficients |
---|
1415 | estSignificantCoefficientsBit( pcEstBitsSbac, eTType ); |
---|
1416 | } |
---|
1417 | |
---|
1418 | /*! |
---|
1419 | **************************************************************************** |
---|
1420 | * \brief |
---|
1421 | * estimate bit cost for each CBP bit |
---|
1422 | **************************************************************************** |
---|
1423 | */ |
---|
1424 | Void TEncSbac::estCBFBit( estBitsSbacStruct* pcEstBitsSbac ) |
---|
1425 | { |
---|
1426 | ContextModel *pCtx = m_cCUQtCbfSCModel.get( 0 ); |
---|
1427 | |
---|
1428 | for( UInt uiCtxInc = 0; uiCtxInc < 3*NUM_QT_CBF_CTX; uiCtxInc++ ) |
---|
1429 | { |
---|
1430 | pcEstBitsSbac->blockCbpBits[ uiCtxInc ][ 0 ] = pCtx[ uiCtxInc ].getEntropyBits( 0 ); |
---|
1431 | pcEstBitsSbac->blockCbpBits[ uiCtxInc ][ 1 ] = pCtx[ uiCtxInc ].getEntropyBits( 1 ); |
---|
1432 | } |
---|
1433 | |
---|
1434 | pCtx = m_cCUQtRootCbfSCModel.get( 0 ); |
---|
1435 | |
---|
1436 | for( UInt uiCtxInc = 0; uiCtxInc < 4; uiCtxInc++ ) |
---|
1437 | { |
---|
1438 | pcEstBitsSbac->blockRootCbpBits[ uiCtxInc ][ 0 ] = pCtx[ uiCtxInc ].getEntropyBits( 0 ); |
---|
1439 | pcEstBitsSbac->blockRootCbpBits[ uiCtxInc ][ 1 ] = pCtx[ uiCtxInc ].getEntropyBits( 1 ); |
---|
1440 | } |
---|
1441 | } |
---|
1442 | |
---|
1443 | |
---|
1444 | /*! |
---|
1445 | **************************************************************************** |
---|
1446 | * \brief |
---|
1447 | * estimate SAMBAC bit cost for significant coefficient group map |
---|
1448 | **************************************************************************** |
---|
1449 | */ |
---|
1450 | Void TEncSbac::estSignificantCoeffGroupMapBit( estBitsSbacStruct* pcEstBitsSbac, TextType eTType ) |
---|
1451 | { |
---|
1452 | Int firstCtx = 0, numCtx = NUM_SIG_CG_FLAG_CTX; |
---|
1453 | |
---|
1454 | for ( Int ctxIdx = firstCtx; ctxIdx < firstCtx + numCtx; ctxIdx++ ) |
---|
1455 | { |
---|
1456 | for( UInt uiBin = 0; uiBin < 2; uiBin++ ) |
---|
1457 | { |
---|
1458 | pcEstBitsSbac->significantCoeffGroupBits[ ctxIdx ][ uiBin ] = m_cCUSigCoeffGroupSCModel.get( 0, eTType, ctxIdx ).getEntropyBits( uiBin ); |
---|
1459 | } |
---|
1460 | } |
---|
1461 | } |
---|
1462 | |
---|
1463 | |
---|
1464 | /*! |
---|
1465 | **************************************************************************** |
---|
1466 | * \brief |
---|
1467 | * estimate SAMBAC bit cost for significant coefficient map |
---|
1468 | **************************************************************************** |
---|
1469 | */ |
---|
1470 | Void TEncSbac::estSignificantMapBit( estBitsSbacStruct* pcEstBitsSbac, Int width, Int height, TextType eTType ) |
---|
1471 | { |
---|
1472 | Int firstCtx = 1, numCtx = 8; |
---|
1473 | if (max(width, height) >= 16) |
---|
1474 | { |
---|
1475 | firstCtx = (eTType == TEXT_LUMA) ? 21 : 12; |
---|
1476 | numCtx = (eTType == TEXT_LUMA) ? 6 : 3; |
---|
1477 | } |
---|
1478 | else if (width == 8) |
---|
1479 | { |
---|
1480 | firstCtx = 9; |
---|
1481 | numCtx = (eTType == TEXT_LUMA) ? 12 : 3; |
---|
1482 | } |
---|
1483 | |
---|
1484 | if (eTType == TEXT_LUMA ) |
---|
1485 | { |
---|
1486 | for( UInt bin = 0; bin < 2; bin++ ) |
---|
1487 | { |
---|
1488 | pcEstBitsSbac->significantBits[ 0 ][ bin ] = m_cCUSigSCModel.get( 0, 0, 0 ).getEntropyBits( bin ); |
---|
1489 | } |
---|
1490 | |
---|
1491 | for ( Int ctxIdx = firstCtx; ctxIdx < firstCtx + numCtx; ctxIdx++ ) |
---|
1492 | { |
---|
1493 | for( UInt uiBin = 0; uiBin < 2; uiBin++ ) |
---|
1494 | { |
---|
1495 | pcEstBitsSbac->significantBits[ ctxIdx ][ uiBin ] = m_cCUSigSCModel.get( 0, 0, ctxIdx ).getEntropyBits( uiBin ); |
---|
1496 | } |
---|
1497 | } |
---|
1498 | } |
---|
1499 | else |
---|
1500 | { |
---|
1501 | for( UInt bin = 0; bin < 2; bin++ ) |
---|
1502 | { |
---|
1503 | pcEstBitsSbac->significantBits[ 0 ][ bin ] = m_cCUSigSCModel.get( 0, 0, NUM_SIG_FLAG_CTX_LUMA + 0 ).getEntropyBits( bin ); |
---|
1504 | } |
---|
1505 | for ( Int ctxIdx = firstCtx; ctxIdx < firstCtx + numCtx; ctxIdx++ ) |
---|
1506 | { |
---|
1507 | for( UInt uiBin = 0; uiBin < 2; uiBin++ ) |
---|
1508 | { |
---|
1509 | pcEstBitsSbac->significantBits[ ctxIdx ][ uiBin ] = m_cCUSigSCModel.get( 0, 0, NUM_SIG_FLAG_CTX_LUMA + ctxIdx ).getEntropyBits( uiBin ); |
---|
1510 | } |
---|
1511 | } |
---|
1512 | } |
---|
1513 | Int iBitsX = 0, iBitsY = 0; |
---|
1514 | Int blkSizeOffsetX, blkSizeOffsetY, shiftX, shiftY; |
---|
1515 | |
---|
1516 | blkSizeOffsetX = eTType ? 0: (g_aucConvertToBit[ width ] *3 + ((g_aucConvertToBit[ width ] +1)>>2)); |
---|
1517 | blkSizeOffsetY = eTType ? 0: (g_aucConvertToBit[ height ]*3 + ((g_aucConvertToBit[ height ]+1)>>2)); |
---|
1518 | shiftX = eTType ? g_aucConvertToBit[ width ] :((g_aucConvertToBit[ width ]+3)>>2); |
---|
1519 | shiftY = eTType ? g_aucConvertToBit[ height ] :((g_aucConvertToBit[ height ]+3)>>2); |
---|
1520 | |
---|
1521 | Int ctx; |
---|
1522 | ContextModel *pCtxX = m_cCuCtxLastX.get( 0, eTType ); |
---|
1523 | for (ctx = 0; ctx < g_uiGroupIdx[ width - 1 ]; ctx++) |
---|
1524 | { |
---|
1525 | Int ctxOffset = blkSizeOffsetX + (ctx >>shiftX); |
---|
1526 | pcEstBitsSbac->lastXBits[ ctx ] = iBitsX + pCtxX[ ctxOffset ].getEntropyBits( 0 ); |
---|
1527 | iBitsX += pCtxX[ ctxOffset ].getEntropyBits( 1 ); |
---|
1528 | } |
---|
1529 | pcEstBitsSbac->lastXBits[ctx] = iBitsX; |
---|
1530 | ContextModel *pCtxY = m_cCuCtxLastY.get( 0, eTType ); |
---|
1531 | for (ctx = 0; ctx < g_uiGroupIdx[ height - 1 ]; ctx++) |
---|
1532 | { |
---|
1533 | Int ctxOffset = blkSizeOffsetY + (ctx >>shiftY); |
---|
1534 | pcEstBitsSbac->lastYBits[ ctx ] = iBitsY + pCtxY[ ctxOffset ].getEntropyBits( 0 ); |
---|
1535 | iBitsY += pCtxY[ ctxOffset ].getEntropyBits( 1 ); |
---|
1536 | } |
---|
1537 | pcEstBitsSbac->lastYBits[ctx] = iBitsY; |
---|
1538 | } |
---|
1539 | |
---|
1540 | /*! |
---|
1541 | **************************************************************************** |
---|
1542 | * \brief |
---|
1543 | * estimate bit cost of significant coefficient |
---|
1544 | **************************************************************************** |
---|
1545 | */ |
---|
1546 | Void TEncSbac::estSignificantCoefficientsBit( estBitsSbacStruct* pcEstBitsSbac, TextType eTType ) |
---|
1547 | { |
---|
1548 | if (eTType==TEXT_LUMA) |
---|
1549 | { |
---|
1550 | ContextModel *ctxOne = m_cCUOneSCModel.get(0, 0); |
---|
1551 | ContextModel *ctxAbs = m_cCUAbsSCModel.get(0, 0); |
---|
1552 | |
---|
1553 | for (Int ctxIdx = 0; ctxIdx < NUM_ONE_FLAG_CTX_LUMA; ctxIdx++) |
---|
1554 | { |
---|
1555 | pcEstBitsSbac->m_greaterOneBits[ ctxIdx ][ 0 ] = ctxOne[ ctxIdx ].getEntropyBits( 0 ); |
---|
1556 | pcEstBitsSbac->m_greaterOneBits[ ctxIdx ][ 1 ] = ctxOne[ ctxIdx ].getEntropyBits( 1 ); |
---|
1557 | } |
---|
1558 | |
---|
1559 | for (Int ctxIdx = 0; ctxIdx < NUM_ABS_FLAG_CTX_LUMA; ctxIdx++) |
---|
1560 | { |
---|
1561 | pcEstBitsSbac->m_levelAbsBits[ ctxIdx ][ 0 ] = ctxAbs[ ctxIdx ].getEntropyBits( 0 ); |
---|
1562 | pcEstBitsSbac->m_levelAbsBits[ ctxIdx ][ 1 ] = ctxAbs[ ctxIdx ].getEntropyBits( 1 ); |
---|
1563 | } |
---|
1564 | } |
---|
1565 | else |
---|
1566 | { |
---|
1567 | ContextModel *ctxOne = m_cCUOneSCModel.get(0, 0) + NUM_ONE_FLAG_CTX_LUMA; |
---|
1568 | ContextModel *ctxAbs = m_cCUAbsSCModel.get(0, 0) + NUM_ABS_FLAG_CTX_LUMA; |
---|
1569 | |
---|
1570 | for (Int ctxIdx = 0; ctxIdx < NUM_ONE_FLAG_CTX_CHROMA; ctxIdx++) |
---|
1571 | { |
---|
1572 | pcEstBitsSbac->m_greaterOneBits[ ctxIdx ][ 0 ] = ctxOne[ ctxIdx ].getEntropyBits( 0 ); |
---|
1573 | pcEstBitsSbac->m_greaterOneBits[ ctxIdx ][ 1 ] = ctxOne[ ctxIdx ].getEntropyBits( 1 ); |
---|
1574 | } |
---|
1575 | |
---|
1576 | for (Int ctxIdx = 0; ctxIdx < NUM_ABS_FLAG_CTX_CHROMA; ctxIdx++) |
---|
1577 | { |
---|
1578 | pcEstBitsSbac->m_levelAbsBits[ ctxIdx ][ 0 ] = ctxAbs[ ctxIdx ].getEntropyBits( 0 ); |
---|
1579 | pcEstBitsSbac->m_levelAbsBits[ ctxIdx ][ 1 ] = ctxAbs[ ctxIdx ].getEntropyBits( 1 ); |
---|
1580 | } |
---|
1581 | } |
---|
1582 | } |
---|
1583 | |
---|
1584 | /** |
---|
1585 | - Initialize our context information from the nominated source. |
---|
1586 | . |
---|
1587 | \param pSrc From where to copy context information. |
---|
1588 | */ |
---|
1589 | Void TEncSbac::xCopyContextsFrom( TEncSbac* pSrc ) |
---|
1590 | { |
---|
1591 | memcpy(m_contextModels, pSrc->m_contextModels, m_numContextModels*sizeof(m_contextModels[0])); |
---|
1592 | } |
---|
1593 | |
---|
1594 | Void TEncSbac::loadContexts ( TEncSbac* pScr) |
---|
1595 | { |
---|
1596 | this->xCopyContextsFrom(pScr); |
---|
1597 | } |
---|
1598 | |
---|
1599 | //! \} |
---|