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