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