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-2011, 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 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 | |
---|
35 | |
---|
36 | /** \file TEncSbac.cpp |
---|
37 | \brief SBAC encoder class |
---|
38 | */ |
---|
39 | |
---|
40 | #include "TEncTop.h" |
---|
41 | #include "TEncSbac.h" |
---|
42 | |
---|
43 | #include <map> |
---|
44 | |
---|
45 | extern UChar stateMappingTable[113]; |
---|
46 | extern Int entropyBits[128]; |
---|
47 | |
---|
48 | // ==================================================================================================================== |
---|
49 | // Constructor / destructor / create / destroy |
---|
50 | // ==================================================================================================================== |
---|
51 | |
---|
52 | TEncSbac::TEncSbac() |
---|
53 | // new structure here |
---|
54 | : m_pcBitIf ( NULL ) |
---|
55 | , m_pcSlice ( NULL ) |
---|
56 | , m_pcBinIf ( NULL ) |
---|
57 | , m_bAlfCtrl ( false ) |
---|
58 | , m_uiCoeffCost ( 0 ) |
---|
59 | , m_uiMaxAlfCtrlDepth ( 0 ) |
---|
60 | , m_cCUSplitFlagSCModel ( 1, 1, NUM_SPLIT_FLAG_CTX ) |
---|
61 | , m_cCUSkipFlagSCModel ( 1, 1, NUM_SKIP_FLAG_CTX ) |
---|
62 | , m_cCUMergeFlagExtSCModel ( 1, 1, NUM_MERGE_FLAG_EXT_CTX ) |
---|
63 | , m_cCUMergeIdxExtSCModel ( 1, 1, NUM_MERGE_IDX_EXT_CTX ) |
---|
64 | , m_cCUMVMergeIdxExtSCModel ( 1, 1, NUM_MV_MERGE_IDX_EXT_CTX ) |
---|
65 | , m_cResPredFlagSCModel ( 1, 1, NUM_RES_PRED_FLAG_CTX ) |
---|
66 | , m_cCUPartSizeSCModel ( 1, 1, NUM_PART_SIZE_CTX ) |
---|
67 | , m_cCUPredModeSCModel ( 1, 1, NUM_PRED_MODE_CTX ) |
---|
68 | , m_cCUAlfCtrlFlagSCModel ( 1, 1, NUM_ALF_CTRL_FLAG_CTX ) |
---|
69 | , m_cCUIntraPredSCModel ( 1, 1, NUM_ADI_CTX ) |
---|
70 | #if ADD_PLANAR_MODE |
---|
71 | , m_cPlanarFlagSCModel ( 1, 1, NUM_PLANARFLAG_CTX ) |
---|
72 | #endif |
---|
73 | , m_cCUChromaPredSCModel ( 1, 1, NUM_CHROMA_PRED_CTX ) |
---|
74 | , m_cCUDeltaQpSCModel ( 1, 1, NUM_DELTA_QP_CTX ) |
---|
75 | , m_cCUInterDirSCModel ( 1, 1, NUM_INTER_DIR_CTX ) |
---|
76 | , m_cCURefPicSCModel ( 1, 1, NUM_REF_NO_CTX ) |
---|
77 | , m_cCUMvdSCModel ( 1, 2, NUM_MV_RES_CTX ) |
---|
78 | , m_cCUQtCbfSCModel ( 1, 3, NUM_QT_CBF_CTX ) |
---|
79 | , m_cCUTransSubdivFlagSCModel ( 1, 1, NUM_TRANS_SUBDIV_FLAG_CTX ) |
---|
80 | , m_cCUQtRootCbfSCModel ( 1, 1, NUM_QT_ROOT_CBF_CTX ) |
---|
81 | #if SIMPLE_CONTEXT_SIG |
---|
82 | , m_cCUSigSCModel ( 4, 2, NUM_SIG_FLAG_CTX ) |
---|
83 | #else |
---|
84 | , m_cCUSigSCModel ( MAX_CU_DEPTH, 2, NUM_SIG_FLAG_CTX ) |
---|
85 | #endif |
---|
86 | #if PCP_SIGMAP_SIMPLE_LAST |
---|
87 | , m_cCuCtxLastX ( 1, 2, NUM_CTX_LAST_FLAG_XY ) |
---|
88 | , m_cCuCtxLastY ( 1, 2, NUM_CTX_LAST_FLAG_XY ) |
---|
89 | #else |
---|
90 | , m_cCULastSCModel ( MAX_CU_DEPTH, 2, NUM_LAST_FLAG_CTX ) |
---|
91 | #endif |
---|
92 | , m_cCUOneSCModel ( 1, 2, NUM_ONE_FLAG_CTX ) |
---|
93 | , m_cCUAbsSCModel ( 1, 2, NUM_ABS_FLAG_CTX ) |
---|
94 | , m_cMVPIdxSCModel ( 1, 1, NUM_MVP_IDX_CTX ) |
---|
95 | , m_cALFFlagSCModel ( 1, 1, NUM_ALF_FLAG_CTX ) |
---|
96 | , m_cALFUvlcSCModel ( 1, 1, NUM_ALF_UVLC_CTX ) |
---|
97 | , m_cALFSvlcSCModel ( 1, 1, NUM_ALF_SVLC_CTX ) |
---|
98 | #if MTK_SAO |
---|
99 | , m_cAOFlagSCModel ( 1, 1, NUM_AO_FLAG_CTX ) |
---|
100 | , m_cAOUvlcSCModel ( 1, 1, NUM_AO_UVLC_CTX ) |
---|
101 | , m_cAOSvlcSCModel ( 1, 1, NUM_AO_SVLC_CTX ) |
---|
102 | #endif |
---|
103 | , m_cViewIdxSCModel ( 1, 1, NUM_VIEW_IDX_CTX ) |
---|
104 | #if HHI_DMM_WEDGE_INTRA || HHI_DMM_PRED_TEX |
---|
105 | , m_cIntraDMMSCModel ( 1, 1, NUM_DMM_CTX ) |
---|
106 | , m_cIntraWedgeSCModel ( 1, 1, NUM_WEDGE_CTX ) |
---|
107 | #endif |
---|
108 | { |
---|
109 | |
---|
110 | } |
---|
111 | |
---|
112 | TEncSbac::~TEncSbac() |
---|
113 | { |
---|
114 | } |
---|
115 | |
---|
116 | // ==================================================================================================================== |
---|
117 | // Public member functions |
---|
118 | // ==================================================================================================================== |
---|
119 | |
---|
120 | Void TEncSbac::resetEntropy () |
---|
121 | { |
---|
122 | Int iQp = m_pcSlice->getSliceQp(); |
---|
123 | SliceType eSliceType = m_pcSlice->getSliceType(); |
---|
124 | |
---|
125 | m_cCUSplitFlagSCModel.initBuffer ( eSliceType, iQp, (Short*)INIT_SPLIT_FLAG ); |
---|
126 | |
---|
127 | m_cCUSkipFlagSCModel.initBuffer ( eSliceType, iQp, (Short*)INIT_SKIP_FLAG ); |
---|
128 | m_cCUAlfCtrlFlagSCModel.initBuffer ( eSliceType, iQp, (Short*)INIT_ALF_CTRL_FLAG ); |
---|
129 | m_cCUMergeFlagExtSCModel.initBuffer ( eSliceType, iQp, (Short*)INIT_MERGE_FLAG_EXT); |
---|
130 | m_cCUMergeIdxExtSCModel.initBuffer ( eSliceType, iQp, (Short*)INIT_MERGE_IDX_EXT); |
---|
131 | m_cCUMVMergeIdxExtSCModel.initBuffer ( eSliceType, iQp, (Short*)INIT_MV_MERGE_IDX_EXT ); |
---|
132 | m_cResPredFlagSCModel.initBuffer ( eSliceType, iQp, (Short*)INIT_RES_PRED_FLAG ); |
---|
133 | m_cCUPartSizeSCModel.initBuffer ( eSliceType, iQp, (Short*)INIT_PART_SIZE ); |
---|
134 | m_cCUPredModeSCModel.initBuffer ( eSliceType, iQp, (Short*)INIT_PRED_MODE ); |
---|
135 | m_cCUIntraPredSCModel.initBuffer ( eSliceType, iQp, (Short*)INIT_INTRA_PRED_MODE ); |
---|
136 | #if ADD_PLANAR_MODE |
---|
137 | m_cPlanarFlagSCModel.initBuffer ( eSliceType, iQp, (Short*)INIT_PLANARFLAG ); |
---|
138 | #endif |
---|
139 | m_cCUChromaPredSCModel.initBuffer ( eSliceType, iQp, (Short*)INIT_CHROMA_PRED_MODE ); |
---|
140 | m_cCUInterDirSCModel.initBuffer ( eSliceType, iQp, (Short*)INIT_INTER_DIR ); |
---|
141 | m_cCUMvdSCModel.initBuffer ( eSliceType, iQp, (Short*)INIT_MVD ); |
---|
142 | m_cCURefPicSCModel.initBuffer ( eSliceType, iQp, (Short*)INIT_REF_PIC ); |
---|
143 | m_cCUDeltaQpSCModel.initBuffer ( eSliceType, iQp, (Short*)INIT_DQP ); |
---|
144 | m_cCUQtCbfSCModel.initBuffer ( eSliceType, iQp, (Short*)INIT_QT_CBF ); |
---|
145 | m_cCUQtRootCbfSCModel.initBuffer ( eSliceType, iQp, (Short*)INIT_QT_ROOT_CBF ); |
---|
146 | m_cCUSigSCModel.initBuffer ( eSliceType, iQp, (Short*)INIT_SIG_FLAG ); |
---|
147 | #if PCP_SIGMAP_SIMPLE_LAST |
---|
148 | m_cCuCtxLastX.initBuffer ( eSliceType, iQp, (Short*)INIT_LAST_X ); |
---|
149 | m_cCuCtxLastY.initBuffer ( eSliceType, iQp, (Short*)INIT_LAST_Y ); |
---|
150 | #else |
---|
151 | m_cCULastSCModel.initBuffer ( eSliceType, iQp, (Short*)INIT_LAST_FLAG ); |
---|
152 | #endif |
---|
153 | m_cCUOneSCModel.initBuffer ( eSliceType, iQp, (Short*)INIT_ONE_FLAG ); |
---|
154 | m_cCUAbsSCModel.initBuffer ( eSliceType, iQp, (Short*)INIT_ABS_FLAG ); |
---|
155 | m_cMVPIdxSCModel.initBuffer ( eSliceType, iQp, (Short*)INIT_MVP_IDX ); |
---|
156 | m_cALFFlagSCModel.initBuffer ( eSliceType, iQp, (Short*)INIT_ALF_FLAG ); |
---|
157 | m_cALFUvlcSCModel.initBuffer ( eSliceType, iQp, (Short*)INIT_ALF_UVLC ); |
---|
158 | m_cALFSvlcSCModel.initBuffer ( eSliceType, iQp, (Short*)INIT_ALF_SVLC ); |
---|
159 | m_cCUTransSubdivFlagSCModel.initBuffer ( eSliceType, iQp, (Short*)INIT_TRANS_SUBDIV_FLAG ); |
---|
160 | #if MTK_SAO |
---|
161 | m_cAOFlagSCModel.initBuffer ( eSliceType, iQp, (Short*)INIT_AO_FLAG ); |
---|
162 | m_cAOUvlcSCModel.initBuffer ( eSliceType, iQp, (Short*)INIT_AO_UVLC ); |
---|
163 | m_cAOSvlcSCModel.initBuffer ( eSliceType, iQp, (Short*)INIT_AO_SVLC ); |
---|
164 | #endif |
---|
165 | m_cViewIdxSCModel.initBuffer ( eSliceType, iQp, (Short*)INIT_VIEW_IDX ); |
---|
166 | #if HHI_DMM_WEDGE_INTRA || HHI_DMM_PRED_TEX |
---|
167 | m_cIntraDMMSCModel.initBuffer ( eSliceType, iQp, (Short*)INIT_INTRA_DMM ); |
---|
168 | m_cIntraWedgeSCModel.initBuffer ( eSliceType, iQp, (Short*)INIT_INTRA_WEDGELET ); |
---|
169 | #endif |
---|
170 | |
---|
171 | // new structure |
---|
172 | m_uiLastQp = iQp; |
---|
173 | |
---|
174 | m_pcBinIf->start(); |
---|
175 | |
---|
176 | return; |
---|
177 | } |
---|
178 | |
---|
179 | Void TEncSbac::codeNALUnitHeader( NalUnitType eNalUnitType, NalRefIdc eNalRefIdc, UInt TemporalId, Bool bOutputFlag ) |
---|
180 | { |
---|
181 | assert (0); |
---|
182 | return; |
---|
183 | } |
---|
184 | |
---|
185 | void TEncSbac::codeSEI(const SEI&) |
---|
186 | { |
---|
187 | assert(0); |
---|
188 | } |
---|
189 | |
---|
190 | Void TEncSbac::codeSPS( TComSPS* pcSPS ) |
---|
191 | { |
---|
192 | assert (0); |
---|
193 | return; |
---|
194 | } |
---|
195 | |
---|
196 | Void TEncSbac::codePPS( TComPPS* pcPPS ) |
---|
197 | { |
---|
198 | assert (0); |
---|
199 | return; |
---|
200 | } |
---|
201 | |
---|
202 | Void TEncSbac::codeSliceHeader( TComSlice* pcSlice ) |
---|
203 | { |
---|
204 | assert (0); |
---|
205 | return; |
---|
206 | } |
---|
207 | |
---|
208 | Void TEncSbac::codeTerminatingBit( UInt uilsLast ) |
---|
209 | { |
---|
210 | m_pcBinIf->encodeBinTrm( uilsLast ); |
---|
211 | } |
---|
212 | |
---|
213 | Void TEncSbac::codeSliceFinish() |
---|
214 | { |
---|
215 | m_pcBinIf->finish(); |
---|
216 | } |
---|
217 | |
---|
218 | |
---|
219 | |
---|
220 | Void TEncSbac::xWriteUnarySymbol( UInt uiSymbol, ContextModel* pcSCModel, Int iOffset ) |
---|
221 | { |
---|
222 | m_pcBinIf->encodeBin( uiSymbol ? 1 : 0, pcSCModel[0] ); |
---|
223 | |
---|
224 | if( 0 == uiSymbol) |
---|
225 | { |
---|
226 | return; |
---|
227 | } |
---|
228 | |
---|
229 | while( uiSymbol-- ) |
---|
230 | { |
---|
231 | m_pcBinIf->encodeBin( uiSymbol ? 1 : 0, pcSCModel[ iOffset ] ); |
---|
232 | } |
---|
233 | |
---|
234 | return; |
---|
235 | } |
---|
236 | |
---|
237 | Void TEncSbac::xWriteUnaryMaxSymbol( UInt uiSymbol, ContextModel* pcSCModel, Int iOffset, UInt uiMaxSymbol ) |
---|
238 | { |
---|
239 | if (uiMaxSymbol == 0) |
---|
240 | { |
---|
241 | return; |
---|
242 | } |
---|
243 | |
---|
244 | m_pcBinIf->encodeBin( uiSymbol ? 1 : 0, pcSCModel[ 0 ] ); |
---|
245 | |
---|
246 | if ( uiSymbol == 0 ) |
---|
247 | { |
---|
248 | return; |
---|
249 | } |
---|
250 | |
---|
251 | Bool bCodeLast = ( uiMaxSymbol > uiSymbol ); |
---|
252 | |
---|
253 | while( --uiSymbol ) |
---|
254 | { |
---|
255 | m_pcBinIf->encodeBin( 1, pcSCModel[ iOffset ] ); |
---|
256 | } |
---|
257 | if( bCodeLast ) |
---|
258 | { |
---|
259 | m_pcBinIf->encodeBin( 0, pcSCModel[ iOffset ] ); |
---|
260 | } |
---|
261 | |
---|
262 | return; |
---|
263 | } |
---|
264 | |
---|
265 | Void TEncSbac::xWriteEpExGolomb( UInt uiSymbol, UInt uiCount ) |
---|
266 | { |
---|
267 | while( uiSymbol >= (UInt)(1<<uiCount) ) |
---|
268 | { |
---|
269 | m_pcBinIf->encodeBinEP( 1 ); |
---|
270 | uiSymbol -= 1<<uiCount; |
---|
271 | uiCount ++; |
---|
272 | } |
---|
273 | m_pcBinIf->encodeBinEP( 0 ); |
---|
274 | while( uiCount-- ) |
---|
275 | { |
---|
276 | m_pcBinIf->encodeBinEP( (uiSymbol>>uiCount) & 1 ); |
---|
277 | } |
---|
278 | |
---|
279 | return; |
---|
280 | } |
---|
281 | |
---|
282 | #if E253 |
---|
283 | /** Coding of coeff_abs_level_minus3 |
---|
284 | * \param uiSymbol value of coeff_abs_level_minus3 |
---|
285 | * \param ruiGoRiceParam reference to Rice parameter |
---|
286 | * \returns Void |
---|
287 | */ |
---|
288 | Void TEncSbac::xWriteGoRiceExGolomb( UInt uiSymbol, UInt &ruiGoRiceParam ) |
---|
289 | { |
---|
290 | UInt uiCount = 0; |
---|
291 | UInt uiMaxVlc = g_auiGoRiceRange[ ruiGoRiceParam ]; |
---|
292 | Bool bExGolomb = ( uiSymbol > uiMaxVlc ); |
---|
293 | UInt uiCodeWord = min<UInt>( uiSymbol, ( uiMaxVlc + 1 ) ); |
---|
294 | UInt uiQuotient = uiCodeWord >> ruiGoRiceParam; |
---|
295 | UInt uiUnaryPart = uiQuotient; |
---|
296 | UInt uiRemainder = 1; |
---|
297 | UInt uiMaxPreLen = g_auiGoRicePrefixLen[ ruiGoRiceParam ]; |
---|
298 | |
---|
299 | if( uiUnaryPart ) |
---|
300 | { |
---|
301 | m_pcBinIf->encodeBinEP( 1 ); |
---|
302 | uiCount++; |
---|
303 | |
---|
304 | while( --uiUnaryPart && uiCount < uiMaxPreLen ) |
---|
305 | { |
---|
306 | m_pcBinIf->encodeBinEP( 1 ); |
---|
307 | uiCount++; |
---|
308 | } |
---|
309 | |
---|
310 | if( uiCount < uiMaxPreLen ) |
---|
311 | { |
---|
312 | m_pcBinIf->encodeBinEP( uiUnaryPart ? 1 : 0 ); |
---|
313 | } |
---|
314 | } |
---|
315 | else |
---|
316 | { |
---|
317 | m_pcBinIf->encodeBinEP( 0 ); |
---|
318 | } |
---|
319 | |
---|
320 | for( UInt ui = 0; ui < ruiGoRiceParam; ui++ ) |
---|
321 | { |
---|
322 | m_pcBinIf->encodeBinEP( ( uiRemainder & uiCodeWord ) ? 1 : 0 ); |
---|
323 | uiRemainder = uiRemainder << 1; |
---|
324 | } |
---|
325 | |
---|
326 | ruiGoRiceParam = g_aauiGoRiceUpdate[ ruiGoRiceParam ][ min<UInt>( uiSymbol, 15 ) ]; |
---|
327 | |
---|
328 | if( bExGolomb ) |
---|
329 | { |
---|
330 | uiSymbol -= uiMaxVlc + 1; |
---|
331 | xWriteEpExGolomb( uiSymbol, 0 ); |
---|
332 | } |
---|
333 | |
---|
334 | return; |
---|
335 | } |
---|
336 | #if HHI_DMM_WEDGE_INTRA || HHI_DMM_PRED_TEX |
---|
337 | Void TEncSbac::xWriteExGolombLevel( UInt uiSymbol, ContextModel& rcSCModel ) |
---|
338 | { |
---|
339 | if( uiSymbol ) |
---|
340 | { |
---|
341 | m_pcBinIf->encodeBin( 1, rcSCModel ); |
---|
342 | UInt uiCount = 0; |
---|
343 | Bool bNoExGo = (uiSymbol < 13); |
---|
344 | |
---|
345 | while( --uiSymbol && ++uiCount < 13 ) |
---|
346 | { |
---|
347 | m_pcBinIf->encodeBin( 1, rcSCModel ); |
---|
348 | } |
---|
349 | if( bNoExGo ) |
---|
350 | { |
---|
351 | m_pcBinIf->encodeBin( 0, rcSCModel ); |
---|
352 | } |
---|
353 | else |
---|
354 | { |
---|
355 | xWriteEpExGolomb( uiSymbol, 0 ); |
---|
356 | } |
---|
357 | } |
---|
358 | else |
---|
359 | { |
---|
360 | m_pcBinIf->encodeBin( 0, rcSCModel ); |
---|
361 | } |
---|
362 | |
---|
363 | return; |
---|
364 | } |
---|
365 | #endif |
---|
366 | #else |
---|
367 | Void TEncSbac::xWriteExGolombLevel( UInt uiSymbol, ContextModel& rcSCModel ) |
---|
368 | { |
---|
369 | if( uiSymbol ) |
---|
370 | { |
---|
371 | m_pcBinIf->encodeBin( 1, rcSCModel ); |
---|
372 | UInt uiCount = 0; |
---|
373 | Bool bNoExGo = (uiSymbol < 13); |
---|
374 | |
---|
375 | while( --uiSymbol && ++uiCount < 13 ) |
---|
376 | { |
---|
377 | m_pcBinIf->encodeBin( 1, rcSCModel ); |
---|
378 | } |
---|
379 | if( bNoExGo ) |
---|
380 | { |
---|
381 | m_pcBinIf->encodeBin( 0, rcSCModel ); |
---|
382 | } |
---|
383 | else |
---|
384 | { |
---|
385 | xWriteEpExGolomb( uiSymbol, 0 ); |
---|
386 | } |
---|
387 | } |
---|
388 | else |
---|
389 | { |
---|
390 | m_pcBinIf->encodeBin( 0, rcSCModel ); |
---|
391 | } |
---|
392 | |
---|
393 | return; |
---|
394 | } |
---|
395 | #endif |
---|
396 | |
---|
397 | // SBAC RD |
---|
398 | Void TEncSbac::load ( TEncSbac* pScr) |
---|
399 | { |
---|
400 | this->xCopyFrom(pScr); |
---|
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 | this->m_cCUSplitFlagSCModel .copyFrom( &pSrc->m_cCUSplitFlagSCModel ); |
---|
417 | this->m_cCUSkipFlagSCModel .copyFrom( &pSrc->m_cCUSkipFlagSCModel ); |
---|
418 | this->m_cCUMergeFlagExtSCModel .copyFrom( &pSrc->m_cCUMergeFlagExtSCModel); |
---|
419 | this->m_cCUMergeIdxExtSCModel .copyFrom( &pSrc->m_cCUMergeIdxExtSCModel); |
---|
420 | this->m_cCUMVMergeIdxExtSCModel .copyFrom( &pSrc->m_cCUMVMergeIdxExtSCModel ); |
---|
421 | this->m_cResPredFlagSCModel .copyFrom( &pSrc->m_cResPredFlagSCModel ); |
---|
422 | this->m_cCUPartSizeSCModel .copyFrom( &pSrc->m_cCUPartSizeSCModel ); |
---|
423 | this->m_cCUPredModeSCModel .copyFrom( &pSrc->m_cCUPredModeSCModel ); |
---|
424 | this->m_cCUIntraPredSCModel .copyFrom( &pSrc->m_cCUIntraPredSCModel ); |
---|
425 | #if ADD_PLANAR_MODE |
---|
426 | this->m_cPlanarFlagSCModel .copyFrom( &pSrc->m_cPlanarFlagSCModel ); |
---|
427 | #endif |
---|
428 | this->m_cCUChromaPredSCModel .copyFrom( &pSrc->m_cCUChromaPredSCModel ); |
---|
429 | this->m_cCUDeltaQpSCModel .copyFrom( &pSrc->m_cCUDeltaQpSCModel ); |
---|
430 | this->m_cCUInterDirSCModel .copyFrom( &pSrc->m_cCUInterDirSCModel ); |
---|
431 | this->m_cCURefPicSCModel .copyFrom( &pSrc->m_cCURefPicSCModel ); |
---|
432 | this->m_cCUMvdSCModel .copyFrom( &pSrc->m_cCUMvdSCModel ); |
---|
433 | this->m_cCUQtCbfSCModel .copyFrom( &pSrc->m_cCUQtCbfSCModel ); |
---|
434 | this->m_cCUTransSubdivFlagSCModel.copyFrom( &pSrc->m_cCUTransSubdivFlagSCModel ); |
---|
435 | this->m_cCUQtRootCbfSCModel .copyFrom( &pSrc->m_cCUQtRootCbfSCModel ); |
---|
436 | this->m_cCUSigSCModel .copyFrom( &pSrc->m_cCUSigSCModel ); |
---|
437 | #if PCP_SIGMAP_SIMPLE_LAST |
---|
438 | this->m_cCuCtxLastX .copyFrom( &pSrc->m_cCuCtxLastX ); |
---|
439 | this->m_cCuCtxLastY .copyFrom( &pSrc->m_cCuCtxLastY ); |
---|
440 | #else |
---|
441 | this->m_cCULastSCModel .copyFrom( &pSrc->m_cCULastSCModel ); |
---|
442 | #endif |
---|
443 | this->m_cCUOneSCModel .copyFrom( &pSrc->m_cCUOneSCModel ); |
---|
444 | this->m_cCUAbsSCModel .copyFrom( &pSrc->m_cCUAbsSCModel ); |
---|
445 | this->m_cMVPIdxSCModel .copyFrom( &pSrc->m_cMVPIdxSCModel ); |
---|
446 | this->m_cViewIdxSCModel .copyFrom( &pSrc->m_cViewIdxSCModel ); |
---|
447 | #if HHI_DMM_WEDGE_INTRA || HHI_DMM_PRED_TEX |
---|
448 | this->m_cIntraDMMSCModel .copyFrom( &pSrc->m_cIntraDMMSCModel ); |
---|
449 | this->m_cIntraWedgeSCModel .copyFrom( &pSrc->m_cIntraWedgeSCModel ); |
---|
450 | #endif |
---|
451 | } |
---|
452 | |
---|
453 | Void TEncSbac::codeMVPIdx ( TComDataCU* pcCU, UInt uiAbsPartIdx, RefPicList eRefList ) |
---|
454 | { |
---|
455 | Int iSymbol = pcCU->getMVPIdx(eRefList, uiAbsPartIdx); |
---|
456 | Int iNum = pcCU->getMVPNum(eRefList, uiAbsPartIdx); |
---|
457 | |
---|
458 | xWriteUnaryMaxSymbol(iSymbol, m_cMVPIdxSCModel.get(0), 1, iNum-1); |
---|
459 | } |
---|
460 | |
---|
461 | Void TEncSbac::codePartSize( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth ) |
---|
462 | { |
---|
463 | PartSize eSize = pcCU->getPartitionSize( uiAbsPartIdx ); |
---|
464 | |
---|
465 | if ( pcCU->getSlice()->isInterB() && pcCU->isIntra( uiAbsPartIdx ) ) |
---|
466 | { |
---|
467 | m_pcBinIf->encodeBin( 0, m_cCUPartSizeSCModel.get( 0, 0, 0) ); |
---|
468 | #if HHI_RMP_SWITCH |
---|
469 | if( pcCU->getSlice()->getSPS()->getUseRMP() ) |
---|
470 | #endif |
---|
471 | { |
---|
472 | m_pcBinIf->encodeBin( 0, m_cCUPartSizeSCModel.get( 0, 0, 1) ); |
---|
473 | m_pcBinIf->encodeBin( 0, m_cCUPartSizeSCModel.get( 0, 0, 2) ); |
---|
474 | } |
---|
475 | #if HHI_DISABLE_INTER_NxN_SPLIT |
---|
476 | if( uiDepth == g_uiMaxCUDepth - g_uiAddCUDepth ) |
---|
477 | #endif |
---|
478 | { |
---|
479 | m_pcBinIf->encodeBin( 0, m_cCUPartSizeSCModel.get( 0, 0, 3) ); |
---|
480 | } |
---|
481 | #if MTK_DISABLE_INTRA_NxN_SPLIT |
---|
482 | if( uiDepth == g_uiMaxCUDepth - g_uiAddCUDepth ) |
---|
483 | #endif |
---|
484 | { |
---|
485 | m_pcBinIf->encodeBin( (eSize == SIZE_2Nx2N? 0 : 1), m_cCUPartSizeSCModel.get( 0, 0, 4) ); |
---|
486 | } |
---|
487 | return; |
---|
488 | } |
---|
489 | |
---|
490 | if ( pcCU->isIntra( uiAbsPartIdx ) ) |
---|
491 | { |
---|
492 | #if MTK_DISABLE_INTRA_NxN_SPLIT |
---|
493 | if( uiDepth == g_uiMaxCUDepth - g_uiAddCUDepth ) |
---|
494 | #endif |
---|
495 | { |
---|
496 | m_pcBinIf->encodeBin( eSize == SIZE_2Nx2N? 1 : 0, m_cCUPartSizeSCModel.get( 0, 0, 0 ) ); |
---|
497 | } |
---|
498 | return; |
---|
499 | } |
---|
500 | |
---|
501 | switch(eSize) |
---|
502 | { |
---|
503 | case SIZE_2Nx2N: |
---|
504 | { |
---|
505 | m_pcBinIf->encodeBin( 1, m_cCUPartSizeSCModel.get( 0, 0, 0) ); |
---|
506 | break; |
---|
507 | } |
---|
508 | case SIZE_2NxN: |
---|
509 | { |
---|
510 | m_pcBinIf->encodeBin( 0, m_cCUPartSizeSCModel.get( 0, 0, 0) ); |
---|
511 | m_pcBinIf->encodeBin( 1, m_cCUPartSizeSCModel.get( 0, 0, 1) ); |
---|
512 | |
---|
513 | break; |
---|
514 | } |
---|
515 | case SIZE_Nx2N: |
---|
516 | { |
---|
517 | m_pcBinIf->encodeBin( 0, m_cCUPartSizeSCModel.get( 0, 0, 0) ); |
---|
518 | m_pcBinIf->encodeBin( 0, m_cCUPartSizeSCModel.get( 0, 0, 1) ); |
---|
519 | m_pcBinIf->encodeBin( 1, m_cCUPartSizeSCModel.get( 0, 0, 2) ); |
---|
520 | |
---|
521 | break; |
---|
522 | } |
---|
523 | case SIZE_NxN: |
---|
524 | { |
---|
525 | #if HHI_DISABLE_INTER_NxN_SPLIT |
---|
526 | if( uiDepth == g_uiMaxCUDepth - g_uiAddCUDepth ) |
---|
527 | #endif |
---|
528 | { |
---|
529 | m_pcBinIf->encodeBin( 0, m_cCUPartSizeSCModel.get( 0, 0, 0) ); |
---|
530 | #if HHI_RMP_SWITCH |
---|
531 | if( pcCU->getSlice()->getSPS()->getUseRMP() ) |
---|
532 | #endif |
---|
533 | { |
---|
534 | m_pcBinIf->encodeBin( 0, m_cCUPartSizeSCModel.get( 0, 0, 1) ); |
---|
535 | m_pcBinIf->encodeBin( 0, m_cCUPartSizeSCModel.get( 0, 0, 2) ); |
---|
536 | } |
---|
537 | |
---|
538 | if (pcCU->getSlice()->isInterB()) |
---|
539 | { |
---|
540 | m_pcBinIf->encodeBin( 1, m_cCUPartSizeSCModel.get( 0, 0, 3) ); |
---|
541 | } |
---|
542 | } |
---|
543 | break; |
---|
544 | } |
---|
545 | default: |
---|
546 | { |
---|
547 | assert(0); |
---|
548 | } |
---|
549 | } |
---|
550 | } |
---|
551 | |
---|
552 | /** code prediction mode |
---|
553 | * \param pcCU |
---|
554 | * \param uiAbsPartIdx |
---|
555 | * \returns Void |
---|
556 | */ |
---|
557 | Void TEncSbac::codePredMode( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
558 | { |
---|
559 | // get context function is here |
---|
560 | Int iPredMode = pcCU->getPredictionMode( uiAbsPartIdx ); |
---|
561 | if (pcCU->getSlice()->isInterB() ) |
---|
562 | { |
---|
563 | return; |
---|
564 | } |
---|
565 | |
---|
566 | m_pcBinIf->encodeBin( iPredMode == MODE_INTER ? 0 : 1, m_cCUPredModeSCModel.get( 0, 0, 1 ) ); |
---|
567 | } |
---|
568 | |
---|
569 | Void TEncSbac::codeAlfCtrlFlag( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
570 | { |
---|
571 | if (!m_bAlfCtrl) |
---|
572 | return; |
---|
573 | |
---|
574 | if( pcCU->getDepth(uiAbsPartIdx) > m_uiMaxAlfCtrlDepth && !pcCU->isFirstAbsZorderIdxInDepth(uiAbsPartIdx, m_uiMaxAlfCtrlDepth)) |
---|
575 | { |
---|
576 | return; |
---|
577 | } |
---|
578 | |
---|
579 | // get context function is here |
---|
580 | UInt uiSymbol = pcCU->getAlfCtrlFlag( uiAbsPartIdx ) ? 1 : 0; |
---|
581 | |
---|
582 | m_pcBinIf->encodeBin( uiSymbol, m_cCUAlfCtrlFlagSCModel.get( 0, 0, pcCU->getCtxAlfCtrlFlag( uiAbsPartIdx) ) ); |
---|
583 | } |
---|
584 | |
---|
585 | Void TEncSbac::codeAlfCtrlDepth() |
---|
586 | { |
---|
587 | if (!m_bAlfCtrl) |
---|
588 | return; |
---|
589 | |
---|
590 | UInt uiDepth = m_uiMaxAlfCtrlDepth; |
---|
591 | xWriteUnaryMaxSymbol(uiDepth, m_cALFUvlcSCModel.get(0), 1, g_uiMaxCUDepth-1); |
---|
592 | } |
---|
593 | |
---|
594 | /** code skip flag |
---|
595 | * \param pcCU |
---|
596 | * \param uiAbsPartIdx |
---|
597 | * \returns Void |
---|
598 | */ |
---|
599 | Void TEncSbac::codeSkipFlag( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
600 | { |
---|
601 | // get context function is here |
---|
602 | UInt uiSymbol = pcCU->isSkipped( uiAbsPartIdx ) ? 1 : 0; |
---|
603 | UInt uiCtxSkip = pcCU->getCtxSkipFlag( uiAbsPartIdx ) ; |
---|
604 | m_pcBinIf->encodeBin( uiSymbol, m_cCUSkipFlagSCModel.get( 0, 0, uiCtxSkip ) ); |
---|
605 | DTRACE_CABAC_V( g_nSymbolCounter++ ); |
---|
606 | DTRACE_CABAC_T( "\tSkipFlag" ); |
---|
607 | DTRACE_CABAC_T( "\tuiCtxSkip: "); |
---|
608 | DTRACE_CABAC_V( uiCtxSkip ); |
---|
609 | DTRACE_CABAC_T( "\tuiSymbol: "); |
---|
610 | DTRACE_CABAC_V( uiSymbol ); |
---|
611 | DTRACE_CABAC_T( "\n"); |
---|
612 | } |
---|
613 | |
---|
614 | /** code merge flag |
---|
615 | * \param pcCU |
---|
616 | * \param uiAbsPartIdx |
---|
617 | * \returns Void |
---|
618 | */ |
---|
619 | Void TEncSbac::codeMergeFlag( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
620 | { |
---|
621 | UInt uiCtx = 0; |
---|
622 | #if CHANGE_MERGE_CONTEXT |
---|
623 | uiCtx = pcCU->getCtxMergeFlag( uiAbsPartIdx ); |
---|
624 | #else |
---|
625 | for(UInt uiIter = 0; uiIter < MRG_MAX_NUM_CANDS; uiIter++ ) |
---|
626 | { |
---|
627 | if( pcCU->getNeighbourCandIdx( uiIter, uiAbsPartIdx ) == uiIter + 1 ) |
---|
628 | { |
---|
629 | if( uiIter == 0 ) |
---|
630 | { |
---|
631 | uiCtx++; |
---|
632 | } |
---|
633 | else if( uiIter == 1 ) |
---|
634 | { |
---|
635 | uiCtx++; |
---|
636 | } |
---|
637 | } |
---|
638 | } |
---|
639 | #endif |
---|
640 | UInt uiSymbol = pcCU->getMergeFlag( uiAbsPartIdx ) ? 1 : 0; |
---|
641 | m_pcBinIf->encodeBin( uiSymbol, m_cCUMergeFlagExtSCModel.get( 0, 0, uiCtx ) ); |
---|
642 | |
---|
643 | DTRACE_CABAC_V( g_nSymbolCounter++ ); |
---|
644 | DTRACE_CABAC_T( "\tMergeFlag: " ); |
---|
645 | DTRACE_CABAC_V( uiSymbol ); |
---|
646 | DTRACE_CABAC_T( "\tAddress: " ); |
---|
647 | DTRACE_CABAC_V( pcCU->getAddr() ); |
---|
648 | DTRACE_CABAC_T( "\tuiAbsPartIdx: " ); |
---|
649 | DTRACE_CABAC_V( uiAbsPartIdx ); |
---|
650 | for( UInt ui = 0; ui < MRG_MAX_NUM_CANDS; ui++ ) |
---|
651 | { |
---|
652 | DTRACE_CABAC_T( "\tNumMrgCand: " ); |
---|
653 | DTRACE_CABAC_V( ui ); |
---|
654 | DTRACE_CABAC_T( "\t==\t" ); |
---|
655 | DTRACE_CABAC_V( UInt( pcCU->getNeighbourCandIdx( ui, uiAbsPartIdx ) ) ); |
---|
656 | } |
---|
657 | DTRACE_CABAC_T( "\n" ); |
---|
658 | } |
---|
659 | |
---|
660 | |
---|
661 | |
---|
662 | #if HHI_INTER_VIEW_MOTION_PRED || HHI_MPI |
---|
663 | Void TEncSbac::codeMergeIndexMV( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
664 | { |
---|
665 | //--- set number of candidates and availability --- |
---|
666 | Bool abAvailable[ MRG_MAX_NUM_CANDS ]; |
---|
667 | UInt uiNumCand = 0; |
---|
668 | #if HHI_MPI |
---|
669 | const Bool bMVIAvailable = pcCU->getSlice()->getSPS()->getUseMVI() && pcCU->getSlice()->getSliceType() != I_SLICE; |
---|
670 | const UInt uiMviMergePos = bMVIAvailable ? HHI_MPI_MERGE_POS : MRG_MAX_NUM_CANDS; |
---|
671 | #endif |
---|
672 | for( UInt uiIdx = 0; uiIdx < MRG_MAX_NUM_CANDS; uiIdx++ ) |
---|
673 | { |
---|
674 | #if HHI_MPI |
---|
675 | if( uiIdx == uiMviMergePos ) |
---|
676 | { |
---|
677 | abAvailable[ uiIdx ] = true; |
---|
678 | uiNumCand++; |
---|
679 | } |
---|
680 | else if( uiIdx > uiMviMergePos ) |
---|
681 | { |
---|
682 | if( ( abAvailable[ uiIdx ] = ( pcCU->getNeighbourCandIdx( uiIdx - 1, uiAbsPartIdx ) == uiIdx ) ) ) |
---|
683 | { |
---|
684 | uiNumCand++; |
---|
685 | } |
---|
686 | } |
---|
687 | else |
---|
688 | #endif |
---|
689 | if( ( abAvailable[ uiIdx ] = ( pcCU->getNeighbourCandIdx( uiIdx, uiAbsPartIdx ) == uiIdx + 1 ) ) ) |
---|
690 | { |
---|
691 | uiNumCand++; |
---|
692 | } |
---|
693 | } |
---|
694 | AOF( uiNumCand > 1 ); |
---|
695 | |
---|
696 | //--- determine contexts --- |
---|
697 | AOF( NUM_MV_MERGE_IDX_EXT_CTX >= MRG_MAX_NUM_CANDS - 1 ); |
---|
698 | UInt auiCtx[ MRG_MAX_NUM_CANDS - 1 ]; |
---|
699 | for( UInt uiIdx = 0; uiIdx < MRG_MAX_NUM_CANDS - 1; uiIdx++ ) |
---|
700 | { |
---|
701 | auiCtx[ uiIdx ] = MRG_MAX_NUM_CANDS; |
---|
702 | if( uiNumCand > uiIdx + 1 ) |
---|
703 | { |
---|
704 | Bool bAvComb = false; |
---|
705 | for( UInt uiCId = uiIdx; uiCId < MRG_MAX_NUM_CANDS - 1; uiCId++ ) |
---|
706 | { |
---|
707 | bAvComb = ( bAvComb || abAvailable[ uiCId ] ); |
---|
708 | if( abAvailable[ uiCId + 1 ] && bAvComb ) |
---|
709 | { |
---|
710 | auiCtx[ uiIdx ] = uiCId; |
---|
711 | break; |
---|
712 | } |
---|
713 | } |
---|
714 | AOT( auiCtx[ uiIdx ] == MRG_MAX_NUM_CANDS ); |
---|
715 | } |
---|
716 | } |
---|
717 | |
---|
718 | //--- determine unary index --- |
---|
719 | UInt uiMergeIdx = pcCU->getMergeIndex( uiAbsPartIdx ); |
---|
720 | #if HHI_MPI |
---|
721 | if( bMVIAvailable ) |
---|
722 | { |
---|
723 | const Bool bUseMVI = pcCU->getTextureModeDepth( uiAbsPartIdx ) != -1; |
---|
724 | if( bUseMVI ) |
---|
725 | { |
---|
726 | uiMergeIdx = HHI_MPI_MERGE_POS; |
---|
727 | } |
---|
728 | else if( uiMergeIdx >= HHI_MPI_MERGE_POS ) |
---|
729 | { |
---|
730 | uiMergeIdx++; |
---|
731 | } |
---|
732 | } |
---|
733 | #endif |
---|
734 | UInt uiUnaryIdx = uiMergeIdx; |
---|
735 | for( UInt uiIdx = 0; uiIdx < uiMergeIdx; uiIdx++ ) |
---|
736 | { |
---|
737 | if( ! abAvailable[ uiIdx ] ) |
---|
738 | { |
---|
739 | uiUnaryIdx--; |
---|
740 | } |
---|
741 | } |
---|
742 | |
---|
743 | //--- code unary index --- |
---|
744 | for( UInt ui = 0; ui < uiNumCand - 1; ui++ ) |
---|
745 | { |
---|
746 | const UInt uiSymbol = ( ui == uiUnaryIdx ? 0 : 1 ); |
---|
747 | m_pcBinIf->encodeBin( uiSymbol, m_cCUMVMergeIdxExtSCModel.get( 0, 0, auiCtx[ui] ) ); |
---|
748 | if( uiSymbol == 0 ) |
---|
749 | { |
---|
750 | break; |
---|
751 | } |
---|
752 | } |
---|
753 | |
---|
754 | //--- trace --- |
---|
755 | DTRACE_CABAC_V( g_nSymbolCounter++ ); |
---|
756 | DTRACE_CABAC_T( "\tparseMergeIndex():" ); |
---|
757 | DTRACE_CABAC_T( " MRGIdx = " ); |
---|
758 | DTRACE_CABAC_V( uiMergeIdx ); |
---|
759 | DTRACE_CABAC_T( " UnaryIdx = " ); |
---|
760 | DTRACE_CABAC_V( uiUnaryIdx ); |
---|
761 | DTRACE_CABAC_T( " NumCand = " ); |
---|
762 | DTRACE_CABAC_V( uiNumCand ); |
---|
763 | DTRACE_CABAC_T( " Availibility = " ); |
---|
764 | for( UInt uiIdx = 0; uiIdx < MRG_MAX_NUM_CANDS; uiIdx++ ) |
---|
765 | { |
---|
766 | DTRACE_CABAC_V( abAvailable[ uiIdx ] ? 1 : 0 ); |
---|
767 | } |
---|
768 | DTRACE_CABAC_T( " Contexts = " ); |
---|
769 | for( UInt uiIdx = 0; uiIdx < MRG_MAX_NUM_CANDS - 1; uiIdx++ ) |
---|
770 | { |
---|
771 | DTRACE_CABAC_V( auiCtx[ uiIdx ] ); |
---|
772 | } |
---|
773 | DTRACE_CABAC_T( "\n" ); |
---|
774 | } |
---|
775 | #endif |
---|
776 | |
---|
777 | |
---|
778 | /** code merge index |
---|
779 | * \param pcCU |
---|
780 | * \param uiAbsPartIdx |
---|
781 | * \returns Void |
---|
782 | */ |
---|
783 | Void TEncSbac::codeMergeIndex( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
784 | { |
---|
785 | #if HHI_INTER_VIEW_MOTION_PRED || HHI_MPI |
---|
786 | #if HHI_INTER_VIEW_MOTION_PRED && HHI_MPI |
---|
787 | if( ( pcCU->getSlice()->getSPS()->getViewId() > 0 && ( pcCU->getSlice()->getSPS()->getMultiviewMvPredMode() & PDM_USE_FOR_MERGE ) == PDM_USE_FOR_MERGE ) || |
---|
788 | ( pcCU->getSlice()->getSPS()->getUseMVI() && pcCU->getSlice()->getSliceType() != I_SLICE && pcCU->getPartitionSize( uiAbsPartIdx ) == SIZE_2Nx2N ) ) |
---|
789 | #elif HHI_MPI |
---|
790 | if( pcCU->getSlice()->getSPS()->getUseMVI() && pcCU->getSlice()->getSliceType() != I_SLICE && pcCU->getPartitionSize( uiAbsPartIdx ) == SIZE_2Nx2N ) |
---|
791 | #else |
---|
792 | if( pcCU->getSlice()->getSPS()->getViewId() > 0 && ( pcCU->getSlice()->getSPS()->getMultiviewMvPredMode() & PDM_USE_FOR_MERGE ) == PDM_USE_FOR_MERGE ) |
---|
793 | #endif |
---|
794 | { |
---|
795 | codeMergeIndexMV( pcCU, uiAbsPartIdx ); |
---|
796 | return; |
---|
797 | } |
---|
798 | #endif |
---|
799 | |
---|
800 | Bool bLeftInvolved = false; |
---|
801 | Bool bAboveInvolved = false; |
---|
802 | Bool bCollocatedInvolved = false; |
---|
803 | Bool bCornerInvolved = false; |
---|
804 | Bool bCornerBLInvolved = false; |
---|
805 | UInt uiNumCand = 0; |
---|
806 | for( UInt uiIter = 0; uiIter < MRG_MAX_NUM_CANDS; ++uiIter ) |
---|
807 | { |
---|
808 | if( pcCU->getNeighbourCandIdx( uiIter, uiAbsPartIdx ) == uiIter + 1 ) |
---|
809 | { |
---|
810 | uiNumCand++; |
---|
811 | if( uiIter == 0 ) |
---|
812 | { |
---|
813 | bLeftInvolved = true; |
---|
814 | } |
---|
815 | else if( uiIter == 1 ) |
---|
816 | { |
---|
817 | bAboveInvolved = true; |
---|
818 | } |
---|
819 | else if( uiIter == 2 ) |
---|
820 | { |
---|
821 | bCollocatedInvolved = true; |
---|
822 | } |
---|
823 | else if( uiIter == 3 ) |
---|
824 | { |
---|
825 | bCornerInvolved = true; |
---|
826 | } |
---|
827 | else if( uiIter == 4 ) |
---|
828 | { |
---|
829 | bCornerBLInvolved = true; |
---|
830 | } |
---|
831 | } |
---|
832 | } |
---|
833 | assert( uiNumCand > 1 ); |
---|
834 | |
---|
835 | UInt auiCtx[4] = { 0, 0, 0, 3 }; |
---|
836 | if( bLeftInvolved && bAboveInvolved ) |
---|
837 | { |
---|
838 | auiCtx[0] = 0; |
---|
839 | } |
---|
840 | else if( bLeftInvolved || bAboveInvolved ) |
---|
841 | { |
---|
842 | auiCtx[0] = bCollocatedInvolved ? 1 : 2; |
---|
843 | } |
---|
844 | else |
---|
845 | { |
---|
846 | auiCtx[0] = bCollocatedInvolved ? 2 : 3; |
---|
847 | } |
---|
848 | |
---|
849 | if( uiNumCand >= 3 ) |
---|
850 | { |
---|
851 | if( bAboveInvolved ) |
---|
852 | { |
---|
853 | auiCtx[1] = bCollocatedInvolved ? 1 : 2; |
---|
854 | } |
---|
855 | else |
---|
856 | { |
---|
857 | auiCtx[1] = bCollocatedInvolved ? 2 : 3; |
---|
858 | } |
---|
859 | } |
---|
860 | |
---|
861 | if( uiNumCand >= 4 ) |
---|
862 | { |
---|
863 | auiCtx[2] = bCollocatedInvolved ? 2 : 3; |
---|
864 | } |
---|
865 | |
---|
866 | UInt uiUnaryIdx = pcCU->getMergeIndex( uiAbsPartIdx ); |
---|
867 | |
---|
868 | if( !bCornerInvolved && uiUnaryIdx > 3 ) |
---|
869 | { |
---|
870 | --uiUnaryIdx; |
---|
871 | } |
---|
872 | if( !bCollocatedInvolved && uiUnaryIdx > 2 ) |
---|
873 | { |
---|
874 | --uiUnaryIdx; |
---|
875 | } |
---|
876 | if( !bAboveInvolved && uiUnaryIdx > 1 ) |
---|
877 | { |
---|
878 | --uiUnaryIdx; |
---|
879 | } |
---|
880 | if( !bLeftInvolved && uiUnaryIdx > 0 ) |
---|
881 | { |
---|
882 | --uiUnaryIdx; |
---|
883 | } |
---|
884 | |
---|
885 | for( UInt ui = 0; ui < uiNumCand - 1; ++ui ) |
---|
886 | { |
---|
887 | const UInt uiSymbol = ui == uiUnaryIdx ? 0 : 1; |
---|
888 | m_pcBinIf->encodeBin( uiSymbol, m_cCUMergeIdxExtSCModel.get( 0, 0, auiCtx[ui] ) ); |
---|
889 | if( uiSymbol == 0 ) |
---|
890 | { |
---|
891 | break; |
---|
892 | } |
---|
893 | } |
---|
894 | |
---|
895 | DTRACE_CABAC_V( g_nSymbolCounter++ ); |
---|
896 | DTRACE_CABAC_T( "\tparseMergeIndex()" ); |
---|
897 | DTRACE_CABAC_T( "\tuiMRGIdx= " ); |
---|
898 | DTRACE_CABAC_V( pcCU->getMergeIndex( uiAbsPartIdx ) ); |
---|
899 | DTRACE_CABAC_T( "\tuiNumCand= " ); |
---|
900 | DTRACE_CABAC_V( uiNumCand ); |
---|
901 | DTRACE_CABAC_T( "\tbLeftInvolved= " ); |
---|
902 | DTRACE_CABAC_V( bLeftInvolved ); |
---|
903 | DTRACE_CABAC_T( "\tbAboveInvolved= " ); |
---|
904 | DTRACE_CABAC_V( bAboveInvolved ); |
---|
905 | DTRACE_CABAC_T( "\tbCollocatedInvolved= " ); |
---|
906 | DTRACE_CABAC_V( bCollocatedInvolved ); |
---|
907 | DTRACE_CABAC_T( "\tbCornerRTInvolved= " ); |
---|
908 | DTRACE_CABAC_V( bCornerInvolved ); |
---|
909 | DTRACE_CABAC_T( "\tbCornerBLInvolved= " ); |
---|
910 | DTRACE_CABAC_V( bCornerBLInvolved ); |
---|
911 | DTRACE_CABAC_T( "\n" ); |
---|
912 | } |
---|
913 | |
---|
914 | |
---|
915 | #if HHI_INTER_VIEW_RESIDUAL_PRED |
---|
916 | Void |
---|
917 | TEncSbac::codeResPredFlag( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
918 | { |
---|
919 | UInt uiCtx = 0; |
---|
920 | UInt uiSymbol = ( pcCU->getResPredFlag( uiAbsPartIdx ) ? 1 : 0 ); |
---|
921 | m_pcBinIf->encodeBin( uiSymbol, m_cResPredFlagSCModel.get( 0, 0, uiCtx ) ); |
---|
922 | } |
---|
923 | #endif |
---|
924 | |
---|
925 | |
---|
926 | Void TEncSbac::codeSplitFlag ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth ) |
---|
927 | { |
---|
928 | if( uiDepth == g_uiMaxCUDepth - g_uiAddCUDepth ) |
---|
929 | return; |
---|
930 | |
---|
931 | UInt uiCtx = pcCU->getCtxSplitFlag( uiAbsPartIdx, uiDepth ); |
---|
932 | UInt uiCurrSplitFlag = ( pcCU->getDepth( uiAbsPartIdx ) > uiDepth ) ? 1 : 0; |
---|
933 | |
---|
934 | assert( uiCtx < 3 ); |
---|
935 | m_pcBinIf->encodeBin( uiCurrSplitFlag, m_cCUSplitFlagSCModel.get( 0, 0, uiCtx ) ); |
---|
936 | DTRACE_CABAC_V( g_nSymbolCounter++ ) |
---|
937 | DTRACE_CABAC_T( "\tSplitFlag\n" ) |
---|
938 | return; |
---|
939 | } |
---|
940 | |
---|
941 | Void TEncSbac::codeTransformSubdivFlag( UInt uiSymbol, UInt uiCtx ) |
---|
942 | { |
---|
943 | m_pcBinIf->encodeBin( uiSymbol, m_cCUTransSubdivFlagSCModel.get( 0, 0, uiCtx ) ); |
---|
944 | DTRACE_CABAC_V( g_nSymbolCounter++ ) |
---|
945 | DTRACE_CABAC_T( "\tparseTransformSubdivFlag()" ) |
---|
946 | DTRACE_CABAC_T( "\tsymbol=" ) |
---|
947 | DTRACE_CABAC_V( uiSymbol ) |
---|
948 | DTRACE_CABAC_T( "\tctx=" ) |
---|
949 | DTRACE_CABAC_V( uiCtx ) |
---|
950 | DTRACE_CABAC_T( "\n" ) |
---|
951 | } |
---|
952 | |
---|
953 | #if HHI_DMM_WEDGE_INTRA |
---|
954 | Void TEncSbac::xCodeWedgeFullInfo( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
955 | { |
---|
956 | Int iIntraIdx = pcCU->getIntraSizeIdx(uiAbsPartIdx); |
---|
957 | Int iBits = g_aucWedgeFullBitsListIdx[iIntraIdx]; |
---|
958 | |
---|
959 | UInt uiTabIdx = pcCU->getWedgeFullTabIdx( uiAbsPartIdx ); |
---|
960 | |
---|
961 | for ( Int i = 0; i < iBits; i++ ) |
---|
962 | { |
---|
963 | m_pcBinIf->encodeBin( ( uiTabIdx >> i ) & 1, m_cIntraWedgeSCModel.get(0, 0, 0) ); |
---|
964 | } |
---|
965 | } |
---|
966 | |
---|
967 | Void TEncSbac::xCodeWedgeFullDeltaInfo( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
968 | { |
---|
969 | Int iIntraIdx = pcCU->getIntraSizeIdx(uiAbsPartIdx); |
---|
970 | Int iBits = g_aucWedgeFullBitsListIdx[iIntraIdx]; |
---|
971 | |
---|
972 | UInt uiTabIdx = pcCU->getWedgeFullTabIdx( uiAbsPartIdx ); |
---|
973 | |
---|
974 | for ( Int i = 0; i < iBits; i++ ) |
---|
975 | { |
---|
976 | m_pcBinIf->encodeBin( ( uiTabIdx >> i ) & 1, m_cIntraWedgeSCModel.get(0, 0, 0) ); |
---|
977 | } |
---|
978 | |
---|
979 | Int iDeltaDC1 = pcCU->getWedgeFullDeltaDC1( uiAbsPartIdx ); |
---|
980 | Int iDeltaDC2 = pcCU->getWedgeFullDeltaDC2( uiAbsPartIdx ); |
---|
981 | |
---|
982 | xWriteExGolombLevel( UInt( abs( iDeltaDC1 ) ), m_cIntraWedgeSCModel.get(0, 0, 1) ); |
---|
983 | if ( iDeltaDC1 != 0 ) |
---|
984 | { |
---|
985 | UInt uiSign = iDeltaDC1 > 0 ? 0 : 1; |
---|
986 | m_pcBinIf->encodeBinEP( uiSign ); |
---|
987 | } |
---|
988 | xWriteExGolombLevel( UInt( abs( iDeltaDC2 ) ), m_cIntraWedgeSCModel.get(0, 0, 1) ); |
---|
989 | if ( iDeltaDC2 != 0 ) |
---|
990 | { |
---|
991 | UInt uiSign = iDeltaDC2 > 0 ? 0 : 1; |
---|
992 | m_pcBinIf->encodeBinEP( uiSign ); |
---|
993 | } |
---|
994 | } |
---|
995 | |
---|
996 | Void TEncSbac::xCodeWedgePredDirInfo( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
997 | { |
---|
998 | if( DMM_WEDGE_PREDDIR_DELTAEND_MAX > 0 ) |
---|
999 | { |
---|
1000 | Int iDeltaEnd = pcCU->getWedgePredDirDeltaEnd( uiAbsPartIdx ); |
---|
1001 | m_pcBinIf->encodeBin( (iDeltaEnd!=0), m_cIntraWedgeSCModel.get(0, 0, 3) ); |
---|
1002 | |
---|
1003 | if( iDeltaEnd != 0 ) |
---|
1004 | { |
---|
1005 | UInt uiAbsValMinus1 = abs(iDeltaEnd)-1; |
---|
1006 | m_pcBinIf->encodeBin( (uiAbsValMinus1 & 0x01), m_cIntraWedgeSCModel.get(0, 0, 3) ); |
---|
1007 | m_pcBinIf->encodeBin( (uiAbsValMinus1 & 0x02) >> 1, m_cIntraWedgeSCModel.get(0, 0, 3) ); |
---|
1008 | |
---|
1009 | UInt uiSign = iDeltaEnd > 0 ? 0 : 1; |
---|
1010 | m_pcBinIf->encodeBinEP( uiSign ); |
---|
1011 | } |
---|
1012 | } |
---|
1013 | } |
---|
1014 | |
---|
1015 | Void TEncSbac::xCodeWedgePredDirDeltaInfo( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
1016 | { |
---|
1017 | if( DMM_WEDGE_PREDDIR_DELTAEND_MAX > 0 ) |
---|
1018 | { |
---|
1019 | Int iDeltaEnd = pcCU->getWedgePredDirDeltaEnd( uiAbsPartIdx ); |
---|
1020 | m_pcBinIf->encodeBin( (iDeltaEnd!=0), m_cIntraWedgeSCModel.get(0, 0, 3) ); |
---|
1021 | |
---|
1022 | if( iDeltaEnd != 0 ) |
---|
1023 | { |
---|
1024 | UInt uiAbsValMinus1 = abs(iDeltaEnd)-1; |
---|
1025 | m_pcBinIf->encodeBin( (uiAbsValMinus1 & 0x01), m_cIntraWedgeSCModel.get(0, 0, 3) ); |
---|
1026 | m_pcBinIf->encodeBin( (uiAbsValMinus1 & 0x02) >> 1, m_cIntraWedgeSCModel.get(0, 0, 3) ); |
---|
1027 | |
---|
1028 | UInt uiSign = iDeltaEnd > 0 ? 0 : 1; |
---|
1029 | m_pcBinIf->encodeBinEP( uiSign ); |
---|
1030 | } |
---|
1031 | } |
---|
1032 | |
---|
1033 | Int iDeltaDC1 = pcCU->getWedgePredDirDeltaDC1( uiAbsPartIdx ); |
---|
1034 | Int iDeltaDC2 = pcCU->getWedgePredDirDeltaDC2( uiAbsPartIdx ); |
---|
1035 | |
---|
1036 | xWriteExGolombLevel( UInt( abs( iDeltaDC1 ) ), m_cIntraWedgeSCModel.get(0, 0, 1) ); |
---|
1037 | if ( iDeltaDC1 != 0 ) |
---|
1038 | { |
---|
1039 | UInt uiSign = iDeltaDC1 > 0 ? 0 : 1; |
---|
1040 | m_pcBinIf->encodeBinEP( uiSign ); |
---|
1041 | } |
---|
1042 | xWriteExGolombLevel( UInt( abs( iDeltaDC2 ) ), m_cIntraWedgeSCModel.get(0, 0, 1) ); |
---|
1043 | if ( iDeltaDC2 != 0 ) |
---|
1044 | { |
---|
1045 | UInt uiSign = iDeltaDC2 > 0 ? 0 : 1; |
---|
1046 | m_pcBinIf->encodeBinEP( uiSign ); |
---|
1047 | } |
---|
1048 | } |
---|
1049 | #endif |
---|
1050 | #if HHI_DMM_PRED_TEX |
---|
1051 | Void TEncSbac::xCodeWedgePredTexDeltaInfo( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
1052 | { |
---|
1053 | Int iDeltaDC1 = pcCU->getWedgePredTexDeltaDC1( uiAbsPartIdx ); |
---|
1054 | Int iDeltaDC2 = pcCU->getWedgePredTexDeltaDC2( uiAbsPartIdx ); |
---|
1055 | |
---|
1056 | xWriteExGolombLevel( UInt( abs( iDeltaDC1 ) ), m_cIntraWedgeSCModel.get(0, 0, 1) ); |
---|
1057 | if ( iDeltaDC1 != 0 ) |
---|
1058 | { |
---|
1059 | UInt uiSign = iDeltaDC1 > 0 ? 0 : 1; |
---|
1060 | m_pcBinIf->encodeBinEP( uiSign ); |
---|
1061 | } |
---|
1062 | xWriteExGolombLevel( UInt( abs( iDeltaDC2 ) ), m_cIntraWedgeSCModel.get(0, 0, 1) ); |
---|
1063 | if ( iDeltaDC2 != 0 ) |
---|
1064 | { |
---|
1065 | UInt uiSign = iDeltaDC2 > 0 ? 0 : 1; |
---|
1066 | m_pcBinIf->encodeBinEP( uiSign ); |
---|
1067 | } |
---|
1068 | } |
---|
1069 | |
---|
1070 | Void TEncSbac::xCodeContourPredTexDeltaInfo( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
1071 | { |
---|
1072 | Int iDeltaDC1 = pcCU->getContourPredTexDeltaDC1( uiAbsPartIdx ); |
---|
1073 | Int iDeltaDC2 = pcCU->getContourPredTexDeltaDC2( uiAbsPartIdx ); |
---|
1074 | |
---|
1075 | xWriteExGolombLevel( UInt( abs( iDeltaDC1 ) ), m_cIntraWedgeSCModel.get(0, 0, 1) ); |
---|
1076 | if ( iDeltaDC1 != 0 ) |
---|
1077 | { |
---|
1078 | UInt uiSign = iDeltaDC1 > 0 ? 0 : 1; |
---|
1079 | m_pcBinIf->encodeBinEP( uiSign ); |
---|
1080 | } |
---|
1081 | xWriteExGolombLevel( UInt( abs( iDeltaDC2 ) ), m_cIntraWedgeSCModel.get(0, 0, 1) ); |
---|
1082 | if ( iDeltaDC2 != 0 ) |
---|
1083 | { |
---|
1084 | UInt uiSign = iDeltaDC2 > 0 ? 0 : 1; |
---|
1085 | m_pcBinIf->encodeBinEP( uiSign ); |
---|
1086 | } |
---|
1087 | } |
---|
1088 | #endif |
---|
1089 | |
---|
1090 | #if MTK_DCM_MPM |
---|
1091 | Void TEncSbac::codeIntraDirLumaAng( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
1092 | { |
---|
1093 | UInt uiDir = pcCU->getLumaIntraDir( uiAbsPartIdx ); |
---|
1094 | |
---|
1095 | #if HHI_DMM_WEDGE_INTRA || HHI_DMM_PRED_TEX |
---|
1096 | if ( pcCU->getSlice()->getSPS()->isDepth() && pcCU->getSlice()->getSPS()->getUseDMM() && pcCU->getWidth( uiAbsPartIdx ) < 64 ) |
---|
1097 | { |
---|
1098 | m_pcBinIf->encodeBin( uiDir > MAX_MODE_ID_INTRA_DIR, m_cIntraDMMSCModel.get(0, 0, 0) ); |
---|
1099 | } |
---|
1100 | if( uiDir > MAX_MODE_ID_INTRA_DIR ) |
---|
1101 | { |
---|
1102 | assert( pcCU->getWidth( uiAbsPartIdx ) < 64 ); |
---|
1103 | UInt uiDMMode = uiDir - (MAX_MODE_ID_INTRA_DIR+1); |
---|
1104 | |
---|
1105 | #if HHI_DMM_WEDGE_INTRA && HHI_DMM_PRED_TEX |
---|
1106 | m_pcBinIf->encodeBin( (uiDMMode & 0x01), m_cIntraDMMSCModel.get(0, 0, 1) ); |
---|
1107 | m_pcBinIf->encodeBin( (uiDMMode & 0x02) >> 1, m_cIntraDMMSCModel.get(0, 0, 1) ); |
---|
1108 | |
---|
1109 | if ( pcCU->getPartitionSize( uiAbsPartIdx ) != SIZE_NxN && pcCU->getWidth( uiAbsPartIdx ) > 4 ) |
---|
1110 | { |
---|
1111 | m_pcBinIf->encodeBin( (uiDMMode & 0x04) >> 2, m_cIntraDMMSCModel.get(0, 0, 1) ); |
---|
1112 | } |
---|
1113 | #else |
---|
1114 | m_pcBinIf->encodeBin( (uiDMMode & 0x01), m_cIntraDMMSCModel.get(0, 0, 1) ); |
---|
1115 | |
---|
1116 | if ( pcCU->getPartitionSize( uiAbsPartIdx ) != SIZE_NxN && pcCU->getWidth( uiAbsPartIdx ) > 4 ) |
---|
1117 | { |
---|
1118 | m_pcBinIf->encodeBin( (uiDMMode & 0x02) >> 1, m_cIntraDMMSCModel.get(0, 0, 1) ); |
---|
1119 | } |
---|
1120 | #endif |
---|
1121 | #if HHI_DMM_WEDGE_INTRA |
---|
1122 | if( uiDir == DMM_WEDGE_FULL_IDX ) { xCodeWedgeFullInfo ( pcCU, uiAbsPartIdx ); } |
---|
1123 | if( uiDir == DMM_WEDGE_FULL_D_IDX ) { xCodeWedgeFullDeltaInfo ( pcCU, uiAbsPartIdx ); } |
---|
1124 | if( uiDir == DMM_WEDGE_PREDDIR_IDX ) { xCodeWedgePredDirInfo ( pcCU, uiAbsPartIdx ); } |
---|
1125 | if( uiDir == DMM_WEDGE_PREDDIR_D_IDX ) { xCodeWedgePredDirDeltaInfo ( pcCU, uiAbsPartIdx ); } |
---|
1126 | #endif |
---|
1127 | #if HHI_DMM_PRED_TEX |
---|
1128 | if( uiDir == DMM_WEDGE_PREDTEX_D_IDX ) { xCodeWedgePredTexDeltaInfo ( pcCU, uiAbsPartIdx ); } |
---|
1129 | if( uiDir == DMM_CONTOUR_PREDTEX_D_IDX ) { xCodeContourPredTexDeltaInfo( pcCU, uiAbsPartIdx ); } |
---|
1130 | #endif |
---|
1131 | } |
---|
1132 | else |
---|
1133 | #endif |
---|
1134 | { |
---|
1135 | Int iIntraIdx = pcCU->getIntraSizeIdx(uiAbsPartIdx); |
---|
1136 | #if ADD_PLANAR_MODE |
---|
1137 | UInt planarFlag = 0; |
---|
1138 | if (uiDir == PLANAR_IDX) |
---|
1139 | { |
---|
1140 | uiDir = 2; |
---|
1141 | planarFlag = 1; |
---|
1142 | } |
---|
1143 | #endif |
---|
1144 | |
---|
1145 | Int uiPreds[2] = {-1, -1}; |
---|
1146 | Int uiPredNum = pcCU->getIntraDirLumaPredictor(uiAbsPartIdx, uiPreds); |
---|
1147 | |
---|
1148 | Int uiPredIdx = -1; |
---|
1149 | |
---|
1150 | for(UInt i = 0; i < uiPredNum; i++) |
---|
1151 | { |
---|
1152 | if(uiDir == uiPreds[i]) |
---|
1153 | { |
---|
1154 | uiPredIdx = i; |
---|
1155 | } |
---|
1156 | } |
---|
1157 | |
---|
1158 | if(uiPredIdx != -1) |
---|
1159 | { |
---|
1160 | m_pcBinIf->encodeBin( 1, m_cCUIntraPredSCModel.get( 0, 0, 0 ) ); |
---|
1161 | if(uiPredNum == 2) |
---|
1162 | { |
---|
1163 | m_pcBinIf->encodeBin( uiPredIdx, m_cCUIntraPredSCModel.get( 0, 0, 2 ) ); |
---|
1164 | } |
---|
1165 | |
---|
1166 | } |
---|
1167 | else |
---|
1168 | { |
---|
1169 | m_pcBinIf->encodeBin( 0, m_cCUIntraPredSCModel.get( 0, 0, 0 ) ); |
---|
1170 | |
---|
1171 | for(Int i = (uiPredNum - 1); i >= 0; i--) |
---|
1172 | { |
---|
1173 | uiDir = uiDir > uiPreds[i] ? uiDir - 1 : uiDir; |
---|
1174 | } |
---|
1175 | |
---|
1176 | if ( g_aucIntraModeBitsAng[iIntraIdx] < 6 ) |
---|
1177 | { |
---|
1178 | m_pcBinIf->encodeBin((uiDir & 0x01), m_cCUIntraPredSCModel.get(0, 0, 1)); |
---|
1179 | if ( g_aucIntraModeBitsAng[iIntraIdx] > 2 ) { m_pcBinIf->encodeBin((uiDir & 0x02) >> 1, m_cCUIntraPredSCModel.get(0, 0, 1));} |
---|
1180 | if ( g_aucIntraModeBitsAng[iIntraIdx] > 3 ) { m_pcBinIf->encodeBin((uiDir & 0x04) >> 2, m_cCUIntraPredSCModel.get(0, 0, 1));} |
---|
1181 | if ( g_aucIntraModeBitsAng[iIntraIdx] > 4 ) { m_pcBinIf->encodeBin((uiDir & 0x08) >> 3, m_cCUIntraPredSCModel.get(0, 0, 1));} |
---|
1182 | } |
---|
1183 | else |
---|
1184 | { |
---|
1185 | if (uiDir < 31){ // uiDir is here 0...32, 5 bits for uiDir 0...30, 31 is an escape code for coding one more bit for 31 and 32 |
---|
1186 | m_pcBinIf->encodeBin((uiDir & 0x01), m_cCUIntraPredSCModel.get(0, 0, 1)); |
---|
1187 | m_pcBinIf->encodeBin((uiDir & 0x02) >> 1, m_cCUIntraPredSCModel.get(0, 0, 1)); |
---|
1188 | m_pcBinIf->encodeBin((uiDir & 0x04) >> 2, m_cCUIntraPredSCModel.get(0, 0, 1)); |
---|
1189 | m_pcBinIf->encodeBin((uiDir & 0x08) >> 3, m_cCUIntraPredSCModel.get(0, 0, 1)); |
---|
1190 | m_pcBinIf->encodeBin((uiDir & 0x10) >> 4, m_cCUIntraPredSCModel.get(0, 0, 1)); |
---|
1191 | } |
---|
1192 | else{ |
---|
1193 | m_pcBinIf->encodeBin(1, m_cCUIntraPredSCModel.get(0, 0, 1)); |
---|
1194 | m_pcBinIf->encodeBin(1, m_cCUIntraPredSCModel.get(0, 0, 1)); |
---|
1195 | m_pcBinIf->encodeBin(1, m_cCUIntraPredSCModel.get(0, 0, 1)); |
---|
1196 | m_pcBinIf->encodeBin(1, m_cCUIntraPredSCModel.get(0, 0, 1)); |
---|
1197 | m_pcBinIf->encodeBin(1, m_cCUIntraPredSCModel.get(0, 0, 1)); |
---|
1198 | m_pcBinIf->encodeBin((uiDir == 32) ? 1 : 0, m_cCUIntraPredSCModel.get(0, 0, 1)); |
---|
1199 | } |
---|
1200 | } |
---|
1201 | } |
---|
1202 | #if ADD_PLANAR_MODE |
---|
1203 | uiDir = pcCU->getLumaIntraDir( uiAbsPartIdx ); |
---|
1204 | if ( (uiDir == PLANAR_IDX) || (uiDir == 2) ) |
---|
1205 | { |
---|
1206 | m_pcBinIf->encodeBin( planarFlag, m_cPlanarFlagSCModel.get(0,0,0) ); |
---|
1207 | } |
---|
1208 | #endif |
---|
1209 | } |
---|
1210 | return; |
---|
1211 | } |
---|
1212 | #else |
---|
1213 | Void TEncSbac::codeIntraDirLumaAng( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
1214 | { |
---|
1215 | UInt uiDir = pcCU->getLumaIntraDir( uiAbsPartIdx ); |
---|
1216 | #if HHI_DMM_WEDGE_INTRA || HHI_DMM_PRED_TEX |
---|
1217 | if ( pcCU->getSlice()->getSPS()->isDepth() && pcCU->getSlice()->getSPS()->getUseDMM() && pcCU->getWidth( uiAbsPartIdx ) < 64 ) |
---|
1218 | { |
---|
1219 | m_pcBinIf->encodeBin( uiDir > MAX_MODE_ID_INTRA_DIR, m_cIntraDMMSCModel.get(0, 0, 0) ); |
---|
1220 | } |
---|
1221 | if( uiDir > MAX_MODE_ID_INTRA_DIR ) |
---|
1222 | { |
---|
1223 | assert( pcCU->getWidth( uiAbsPartIdx ) < 64 ); |
---|
1224 | UInt uiDMMode = uiDir - (MAX_MODE_ID_INTRA_DIR+1); |
---|
1225 | |
---|
1226 | #if HHI_DMM_WEDGE_INTRA && HHI_DMM_PRED_TEX |
---|
1227 | m_pcBinIf->encodeBin( (uiDMMode & 0x01), m_cIntraDMMSCModel.get(0, 0, 1) ); |
---|
1228 | m_pcBinIf->encodeBin( (uiDMMode & 0x02) >> 1, m_cIntraDMMSCModel.get(0, 0, 1) ); |
---|
1229 | |
---|
1230 | if ( pcCU->getPartitionSize( uiAbsPartIdx ) != SIZE_NxN && pcCU->getWidth( uiAbsPartIdx ) > 4 ) |
---|
1231 | { |
---|
1232 | m_pcBinIf->encodeBin( (uiDMMode & 0x04) >> 2, m_cIntraDMMSCModel.get(0, 0, 1) ); |
---|
1233 | } |
---|
1234 | #else |
---|
1235 | m_pcBinIf->encodeBin( (uiDMMode & 0x01), m_cIntraDMMSCModel.get(0, 0, 1) ); |
---|
1236 | |
---|
1237 | if ( pcCU->getPartitionSize( uiAbsPartIdx ) != SIZE_NxN && pcCU->getWidth( uiAbsPartIdx ) > 4 ) |
---|
1238 | { |
---|
1239 | m_pcBinIf->encodeBin( (uiDMMode & 0x02) >> 1, m_cIntraDMMSCModel.get(0, 0, 1) ); |
---|
1240 | } |
---|
1241 | #endif |
---|
1242 | #if HHI_DMM_WEDGE_INTRA |
---|
1243 | if( uiDir == DMM_WEDGE_FULL_IDX ) { xCodeWedgeFullInfo ( pcCU, uiAbsPartIdx ); } |
---|
1244 | if( uiDir == DMM_WEDGE_FULL_D_IDX ) { xCodeWedgeFullDeltaInfo ( pcCU, uiAbsPartIdx ); } |
---|
1245 | if( uiDir == DMM_WEDGE_PREDDIR_IDX ) { xCodeWedgePredDirInfo ( pcCU, uiAbsPartIdx ); } |
---|
1246 | if( uiDir == DMM_WEDGE_PREDDIR_D_IDX ) { xCodeWedgePredDirDeltaInfo ( pcCU, uiAbsPartIdx ); } |
---|
1247 | #endif |
---|
1248 | #if HHI_DMM_PRED_TEX |
---|
1249 | if( uiDir == DMM_WEDGE_PREDTEX_D_IDX ) { xCodeWedgePredTexDeltaInfo ( pcCU, uiAbsPartIdx ); } |
---|
1250 | if( uiDir == DMM_CONTOUR_PREDTEX_D_IDX ) { xCodeContourPredTexDeltaInfo( pcCU, uiAbsPartIdx ); } |
---|
1251 | #endif |
---|
1252 | } |
---|
1253 | else |
---|
1254 | #endif |
---|
1255 | { |
---|
1256 | Int iMostProbable = pcCU->getMostProbableIntraDirLuma( uiAbsPartIdx ); |
---|
1257 | #if ADD_PLANAR_MODE |
---|
1258 | UInt planarFlag = 0; |
---|
1259 | if (uiDir == PLANAR_IDX) |
---|
1260 | { |
---|
1261 | uiDir = 2; |
---|
1262 | planarFlag = 1; |
---|
1263 | } |
---|
1264 | #endif |
---|
1265 | |
---|
1266 | if (uiDir == iMostProbable) |
---|
1267 | m_pcBinIf->encodeBin( 1, m_cCUIntraPredSCModel.get( 0, 0, 0 ) ); |
---|
1268 | else |
---|
1269 | { |
---|
1270 | m_pcBinIf->encodeBin( 0, m_cCUIntraPredSCModel.get( 0, 0, 0 ) ); |
---|
1271 | uiDir = uiDir > iMostProbable ? uiDir - 1 : uiDir; |
---|
1272 | Int iIntraIdx = pcCU->getIntraSizeIdx(uiAbsPartIdx); |
---|
1273 | if ( g_aucIntraModeBitsAng[iIntraIdx] < 6 ) |
---|
1274 | { |
---|
1275 | m_pcBinIf->encodeBin((uiDir & 0x01), m_cCUIntraPredSCModel.get(0, 0, 1)); |
---|
1276 | if ( g_aucIntraModeBitsAng[iIntraIdx] > 2 ) m_pcBinIf->encodeBin((uiDir & 0x02) >> 1, m_cCUIntraPredSCModel.get(0, 0, 1)); |
---|
1277 | if ( g_aucIntraModeBitsAng[iIntraIdx] > 3 ) m_pcBinIf->encodeBin((uiDir & 0x04) >> 2, m_cCUIntraPredSCModel.get(0, 0, 1)); |
---|
1278 | if ( g_aucIntraModeBitsAng[iIntraIdx] > 4 ) m_pcBinIf->encodeBin((uiDir & 0x08) >> 3, m_cCUIntraPredSCModel.get(0, 0, 1)); |
---|
1279 | } |
---|
1280 | else |
---|
1281 | { |
---|
1282 | if (uiDir < 31) |
---|
1283 | { // uiDir is here 0...32, 5 bits for uiDir 0...30, 31 is an escape code for coding one more bit for 31 and 32 |
---|
1284 | m_pcBinIf->encodeBin((uiDir & 0x01), m_cCUIntraPredSCModel.get(0, 0, 1)); |
---|
1285 | m_pcBinIf->encodeBin((uiDir & 0x02) >> 1, m_cCUIntraPredSCModel.get(0, 0, 1)); |
---|
1286 | m_pcBinIf->encodeBin((uiDir & 0x04) >> 2, m_cCUIntraPredSCModel.get(0, 0, 1)); |
---|
1287 | m_pcBinIf->encodeBin((uiDir & 0x08) >> 3, m_cCUIntraPredSCModel.get(0, 0, 1)); |
---|
1288 | m_pcBinIf->encodeBin((uiDir & 0x10) >> 4, m_cCUIntraPredSCModel.get(0, 0, 1)); |
---|
1289 | } |
---|
1290 | else |
---|
1291 | { |
---|
1292 | m_pcBinIf->encodeBin(1, m_cCUIntraPredSCModel.get(0, 0, 1)); |
---|
1293 | m_pcBinIf->encodeBin(1, m_cCUIntraPredSCModel.get(0, 0, 1)); |
---|
1294 | m_pcBinIf->encodeBin(1, m_cCUIntraPredSCModel.get(0, 0, 1)); |
---|
1295 | m_pcBinIf->encodeBin(1, m_cCUIntraPredSCModel.get(0, 0, 1)); |
---|
1296 | m_pcBinIf->encodeBin(1, m_cCUIntraPredSCModel.get(0, 0, 1)); |
---|
1297 | m_pcBinIf->encodeBin((uiDir == 32) ? 1 : 0, m_cCUIntraPredSCModel.get(0, 0, 1)); |
---|
1298 | } |
---|
1299 | } |
---|
1300 | } |
---|
1301 | |
---|
1302 | #if ADD_PLANAR_MODE |
---|
1303 | uiDir = pcCU->getLumaIntraDir( uiAbsPartIdx ); |
---|
1304 | if ( (uiDir == PLANAR_IDX) || (uiDir == 2) ) |
---|
1305 | { |
---|
1306 | m_pcBinIf->encodeBin( planarFlag, m_cPlanarFlagSCModel.get(0,0,0) ); |
---|
1307 | } |
---|
1308 | #endif |
---|
1309 | } |
---|
1310 | return; |
---|
1311 | } |
---|
1312 | #endif |
---|
1313 | Void TEncSbac::codeIntraDirChroma( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
1314 | { |
---|
1315 | UInt uiCtx = pcCU->getCtxIntraDirChroma( uiAbsPartIdx ); |
---|
1316 | UInt uiIntraDirChroma = pcCU->getChromaIntraDir ( uiAbsPartIdx ); |
---|
1317 | #if ADD_PLANAR_MODE |
---|
1318 | UInt planarFlag = 0; |
---|
1319 | if (uiIntraDirChroma == PLANAR_IDX) |
---|
1320 | { |
---|
1321 | uiIntraDirChroma = 2; |
---|
1322 | planarFlag = 1; |
---|
1323 | } |
---|
1324 | #endif |
---|
1325 | |
---|
1326 | #if CHROMA_CODEWORD |
---|
1327 | UInt uiMode = pcCU->getLumaIntraDir(uiAbsPartIdx); |
---|
1328 | #if ADD_PLANAR_MODE |
---|
1329 | if ( (uiMode == 2 ) || (uiMode == PLANAR_IDX) ) |
---|
1330 | { |
---|
1331 | uiMode = 4; |
---|
1332 | } |
---|
1333 | #endif |
---|
1334 | |
---|
1335 | #if LM_CHROMA |
---|
1336 | |
---|
1337 | Bool bUseLMFlag = pcCU->getSlice()->getSPS()->getUseLMChroma(); |
---|
1338 | |
---|
1339 | Int iMaxMode = bUseLMFlag ? 3 : 4; |
---|
1340 | |
---|
1341 | Int iMax = uiMode < iMaxMode ? 2 : 3; |
---|
1342 | |
---|
1343 | //switch codeword |
---|
1344 | if (uiIntraDirChroma == 4) |
---|
1345 | { |
---|
1346 | uiIntraDirChroma = 0; |
---|
1347 | } |
---|
1348 | else if (uiIntraDirChroma == 3 && bUseLMFlag ) |
---|
1349 | { |
---|
1350 | uiIntraDirChroma = 1; |
---|
1351 | } |
---|
1352 | else |
---|
1353 | { |
---|
1354 | if (uiIntraDirChroma < uiMode) |
---|
1355 | uiIntraDirChroma++; |
---|
1356 | |
---|
1357 | if (bUseLMFlag) |
---|
1358 | uiIntraDirChroma++; |
---|
1359 | |
---|
1360 | #if CHROMA_CODEWORD_SWITCH |
---|
1361 | uiIntraDirChroma = ChromaMapping[iMax-2][uiIntraDirChroma]; |
---|
1362 | #endif |
---|
1363 | |
---|
1364 | } |
---|
1365 | |
---|
1366 | |
---|
1367 | #else // <-- LM_CHROMA |
---|
1368 | Int iMax = uiMode < 4 ? 2 : 3; |
---|
1369 | |
---|
1370 | //switch codeword |
---|
1371 | if (uiIntraDirChroma == 4) { |
---|
1372 | uiIntraDirChroma = 0; |
---|
1373 | } |
---|
1374 | #if CHROMA_CODEWORD_SWITCH |
---|
1375 | else { |
---|
1376 | if (uiIntraDirChroma < uiMode) { |
---|
1377 | uiIntraDirChroma++; |
---|
1378 | } |
---|
1379 | uiIntraDirChroma = ChromaMapping[iMax-2][uiIntraDirChroma]; |
---|
1380 | } |
---|
1381 | #else |
---|
1382 | else if (uiIntraDirChroma < uiMode) { |
---|
1383 | uiIntraDirChroma++; |
---|
1384 | } |
---|
1385 | #endif |
---|
1386 | #endif // <-- LM_CHROMA |
---|
1387 | |
---|
1388 | if ( 0 == uiIntraDirChroma ) |
---|
1389 | { |
---|
1390 | m_pcBinIf->encodeBin( 0, m_cCUChromaPredSCModel.get( 0, 0, uiCtx ) ); |
---|
1391 | } |
---|
1392 | else |
---|
1393 | { |
---|
1394 | m_pcBinIf->encodeBin( 1, m_cCUChromaPredSCModel.get( 0, 0, uiCtx ) ); |
---|
1395 | xWriteUnaryMaxSymbol( uiIntraDirChroma - 1, m_cCUChromaPredSCModel.get( 0, 0 ) + 3, 0, iMax ); |
---|
1396 | } |
---|
1397 | #else // CHROMA_CODEWORD |
---|
1398 | if ( 0 == uiIntraDirChroma ) |
---|
1399 | { |
---|
1400 | m_pcBinIf->encodeBin( 0, m_cCUChromaPredSCModel.get( 0, 0, uiCtx ) ); |
---|
1401 | } |
---|
1402 | else |
---|
1403 | { |
---|
1404 | m_pcBinIf->encodeBin( 1, m_cCUChromaPredSCModel.get( 0, 0, uiCtx ) ); |
---|
1405 | xWriteUnaryMaxSymbol( uiIntraDirChroma - 1, m_cCUChromaPredSCModel.get( 0, 0 ) + 3, 0, 3 ); |
---|
1406 | } |
---|
1407 | #endif |
---|
1408 | |
---|
1409 | #if ADD_PLANAR_MODE |
---|
1410 | uiIntraDirChroma = pcCU->getChromaIntraDir( uiAbsPartIdx ); |
---|
1411 | #if CHROMA_CODEWORD |
---|
1412 | uiMode = pcCU->getLumaIntraDir(uiAbsPartIdx); |
---|
1413 | mapPlanartoDC( uiIntraDirChroma ); |
---|
1414 | mapPlanartoDC( uiMode ); |
---|
1415 | if ( (uiIntraDirChroma == 2) && (uiMode != 2) ) |
---|
1416 | #else |
---|
1417 | if ( (uiIntraDirChroma == PLANAR_IDX) || (uiIntraDirChroma == 2) ) |
---|
1418 | #endif |
---|
1419 | { |
---|
1420 | m_pcBinIf->encodeBin( planarFlag, m_cPlanarFlagSCModel.get(0,0,1) ); |
---|
1421 | } |
---|
1422 | #endif |
---|
1423 | return; |
---|
1424 | } |
---|
1425 | |
---|
1426 | Void TEncSbac::codeInterDir( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
1427 | { |
---|
1428 | UInt uiInterDir = pcCU->getInterDir ( uiAbsPartIdx ); |
---|
1429 | UInt uiCtx = pcCU->getCtxInterDir( uiAbsPartIdx ); |
---|
1430 | uiInterDir--; |
---|
1431 | m_pcBinIf->encodeBin( ( uiInterDir == 2 ? 1 : 0 ), m_cCUInterDirSCModel.get( 0, 0, uiCtx ) ); |
---|
1432 | |
---|
1433 | if ( pcCU->getSlice()->getNoBackPredFlag() ) |
---|
1434 | { |
---|
1435 | assert( uiInterDir != 1 ); |
---|
1436 | return; |
---|
1437 | } |
---|
1438 | |
---|
1439 | #if DCM_COMB_LIST |
---|
1440 | if ( uiInterDir < 2 && pcCU->getSlice()->getNumRefIdx(REF_PIC_LIST_C) <= 0) |
---|
1441 | #else |
---|
1442 | if ( uiInterDir < 2 ) |
---|
1443 | #endif |
---|
1444 | { |
---|
1445 | m_pcBinIf->encodeBin( uiInterDir, m_cCUInterDirSCModel.get( 0, 0, 3 ) ); |
---|
1446 | } |
---|
1447 | |
---|
1448 | return; |
---|
1449 | } |
---|
1450 | |
---|
1451 | Void TEncSbac::codeRefFrmIdx( TComDataCU* pcCU, UInt uiAbsPartIdx, RefPicList eRefList ) |
---|
1452 | { |
---|
1453 | #if DCM_COMB_LIST |
---|
1454 | if ( pcCU->getSlice()->getNumRefIdx(REF_PIC_LIST_C) > 0 && pcCU->getInterDir( uiAbsPartIdx ) != 3) |
---|
1455 | { |
---|
1456 | Int iRefFrame = pcCU->getSlice()->getRefIdxOfLC(eRefList, pcCU->getCUMvField( eRefList )->getRefIdx( uiAbsPartIdx )); |
---|
1457 | UInt uiCtx; |
---|
1458 | |
---|
1459 | uiCtx = pcCU->getCtxRefIdx( uiAbsPartIdx, RefPicList(pcCU->getSlice()->getListIdFromIdxOfLC(0)) ); |
---|
1460 | |
---|
1461 | m_pcBinIf->encodeBin( ( iRefFrame == 0 ? 0 : 1 ), m_cCURefPicSCModel.get( 0, 0, uiCtx ) ); |
---|
1462 | |
---|
1463 | if ( iRefFrame > 0 ) |
---|
1464 | { |
---|
1465 | xWriteUnaryMaxSymbol( iRefFrame - 1, &m_cCURefPicSCModel.get( 0, 0, 4 ), 1, pcCU->getSlice()->getNumRefIdx( REF_PIC_LIST_C )-2 ); |
---|
1466 | } |
---|
1467 | } |
---|
1468 | else |
---|
1469 | { |
---|
1470 | #endif |
---|
1471 | Int iRefFrame = pcCU->getCUMvField( eRefList )->getRefIdx( uiAbsPartIdx ); |
---|
1472 | |
---|
1473 | UInt uiCtx = pcCU->getCtxRefIdx( uiAbsPartIdx, eRefList ); |
---|
1474 | |
---|
1475 | m_pcBinIf->encodeBin( ( iRefFrame == 0 ? 0 : 1 ), m_cCURefPicSCModel.get( 0, 0, uiCtx ) ); |
---|
1476 | |
---|
1477 | if ( iRefFrame > 0 ) |
---|
1478 | { |
---|
1479 | xWriteUnaryMaxSymbol( iRefFrame - 1, &m_cCURefPicSCModel.get( 0, 0, 4 ), 1, pcCU->getSlice()->getNumRefIdx( eRefList )-2 ); |
---|
1480 | } |
---|
1481 | #if DCM_COMB_LIST |
---|
1482 | } |
---|
1483 | #endif |
---|
1484 | return; |
---|
1485 | } |
---|
1486 | |
---|
1487 | Void TEncSbac::codeViewIdx(Int iViewIdx) |
---|
1488 | { |
---|
1489 | assert(0) ; // not implemented yet |
---|
1490 | xWriteUnaryMaxSymbol(iViewIdx, &m_cViewIdxSCModel.get( 0, 0, 4),1, MAX_NUMBER_VIEWS ); |
---|
1491 | } |
---|
1492 | |
---|
1493 | Void TEncSbac::codeMvd( TComDataCU* pcCU, UInt uiAbsPartIdx, RefPicList eRefList ) |
---|
1494 | { |
---|
1495 | TComCUMvField* pcCUMvField = pcCU->getCUMvField( eRefList ); |
---|
1496 | Int iHor = pcCUMvField->getMvd( uiAbsPartIdx ).getHor(); |
---|
1497 | Int iVer = pcCUMvField->getMvd( uiAbsPartIdx ).getVer(); |
---|
1498 | |
---|
1499 | UInt uiAbsPartIdxL, uiAbsPartIdxA; |
---|
1500 | #if MVD_CTX |
---|
1501 | Int iHorPredL, iVerPredL; |
---|
1502 | Int iHorPredA, iVerPredA; |
---|
1503 | #else |
---|
1504 | Int iHorPred, iVerPred; |
---|
1505 | #endif |
---|
1506 | |
---|
1507 | TComDataCU* pcCUL = pcCU->getPULeft ( uiAbsPartIdxL, pcCU->getZorderIdxInCU() + uiAbsPartIdx ); |
---|
1508 | TComDataCU* pcCUA = pcCU->getPUAbove( uiAbsPartIdxA, pcCU->getZorderIdxInCU() + uiAbsPartIdx ); |
---|
1509 | |
---|
1510 | TComCUMvField* pcCUMvFieldL = ( pcCUL == NULL || pcCUL->isIntra( uiAbsPartIdxL ) ) ? NULL : pcCUL->getCUMvField( eRefList ); |
---|
1511 | TComCUMvField* pcCUMvFieldA = ( pcCUA == NULL || pcCUA->isIntra( uiAbsPartIdxA ) ) ? NULL : pcCUA->getCUMvField( eRefList ); |
---|
1512 | |
---|
1513 | #if MVD_CTX |
---|
1514 | iHorPredA = ( (pcCUMvFieldA == NULL) ? 0 : pcCUMvFieldA->getMvd( uiAbsPartIdxA ).getAbsHor() ); |
---|
1515 | iVerPredA = ( (pcCUMvFieldA == NULL) ? 0 : pcCUMvFieldA->getMvd( uiAbsPartIdxA ).getAbsVer() ); |
---|
1516 | iHorPredL = ( (pcCUMvFieldL == NULL) ? 0 : pcCUMvFieldL->getMvd( uiAbsPartIdxL ).getAbsHor() ); |
---|
1517 | iVerPredL = ( (pcCUMvFieldL == NULL) ? 0 : pcCUMvFieldL->getMvd( uiAbsPartIdxL ).getAbsVer() ); |
---|
1518 | |
---|
1519 | xWriteMvd( iHor, iHorPredL, iHorPredA, 0 ); |
---|
1520 | xWriteMvd( iVer, iVerPredL, iVerPredA, 1 ); |
---|
1521 | #else |
---|
1522 | iHorPred = ( (pcCUMvFieldL == NULL) ? 0 : pcCUMvFieldL->getMvd( uiAbsPartIdxL ).getAbsHor() ) + |
---|
1523 | ( (pcCUMvFieldA == NULL) ? 0 : pcCUMvFieldA->getMvd( uiAbsPartIdxA ).getAbsHor() ); |
---|
1524 | iVerPred = ( (pcCUMvFieldL == NULL) ? 0 : pcCUMvFieldL->getMvd( uiAbsPartIdxL ).getAbsVer() ) + |
---|
1525 | ( (pcCUMvFieldA == NULL) ? 0 : pcCUMvFieldA->getMvd( uiAbsPartIdxA ).getAbsVer() ); |
---|
1526 | |
---|
1527 | xWriteMvd( iHor, iHorPred, 0 ); |
---|
1528 | xWriteMvd( iVer, iVerPred, 1 ); |
---|
1529 | #endif |
---|
1530 | |
---|
1531 | |
---|
1532 | return; |
---|
1533 | } |
---|
1534 | |
---|
1535 | Void TEncSbac::codeDeltaQP( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
1536 | { |
---|
1537 | Int iDQp = pcCU->getQP( uiAbsPartIdx ) - pcCU->getSlice()->getSliceQp(); |
---|
1538 | |
---|
1539 | if ( iDQp == 0 ) |
---|
1540 | { |
---|
1541 | m_pcBinIf->encodeBin( 0, m_cCUDeltaQpSCModel.get( 0, 0, 0 ) ); |
---|
1542 | } |
---|
1543 | else |
---|
1544 | { |
---|
1545 | m_pcBinIf->encodeBin( 1, m_cCUDeltaQpSCModel.get( 0, 0, 0 ) ); |
---|
1546 | |
---|
1547 | UInt uiDQp = (UInt)( iDQp > 0 ? ( 2 * iDQp - 2 ) : ( -2 * iDQp - 1 ) ); |
---|
1548 | xWriteUnarySymbol( uiDQp, &m_cCUDeltaQpSCModel.get( 0, 0, 2 ), 1 ); |
---|
1549 | } |
---|
1550 | |
---|
1551 | return; |
---|
1552 | } |
---|
1553 | |
---|
1554 | Void TEncSbac::codeQtCbf( TComDataCU* pcCU, UInt uiAbsPartIdx, TextType eType, UInt uiTrDepth ) |
---|
1555 | { |
---|
1556 | UInt uiCbf = pcCU->getCbf ( uiAbsPartIdx, eType, uiTrDepth ); |
---|
1557 | UInt uiCtx = pcCU->getCtxQtCbf( uiAbsPartIdx, eType, uiTrDepth ); |
---|
1558 | m_pcBinIf->encodeBin( uiCbf , m_cCUQtCbfSCModel.get( 0, eType ? eType - 1 : eType, uiCtx ) ); |
---|
1559 | DTRACE_CABAC_V( g_nSymbolCounter++ ) |
---|
1560 | DTRACE_CABAC_T( "\tparseQtCbf()" ) |
---|
1561 | DTRACE_CABAC_T( "\tsymbol=" ) |
---|
1562 | DTRACE_CABAC_V( uiCbf ) |
---|
1563 | DTRACE_CABAC_T( "\tctx=" ) |
---|
1564 | DTRACE_CABAC_V( uiCtx ) |
---|
1565 | DTRACE_CABAC_T( "\tetype=" ) |
---|
1566 | DTRACE_CABAC_V( eType ) |
---|
1567 | DTRACE_CABAC_T( "\tuiAbsPartIdx=" ) |
---|
1568 | DTRACE_CABAC_V( uiAbsPartIdx ) |
---|
1569 | DTRACE_CABAC_T( "\n" ) |
---|
1570 | } |
---|
1571 | |
---|
1572 | UInt xCheckCoeffPlainCNoRecur( const TCoeff* pcCoef, UInt uiSize, UInt uiDepth ) |
---|
1573 | { |
---|
1574 | UInt uiNumofCoeff = 0; |
---|
1575 | UInt ui = uiSize>>uiDepth; |
---|
1576 | { |
---|
1577 | UInt x, y; |
---|
1578 | const TCoeff* pCeoff = pcCoef; |
---|
1579 | for( y=0 ; y<ui ; y++ ) |
---|
1580 | { |
---|
1581 | for( x=0 ; x<ui ; x++ ) |
---|
1582 | { |
---|
1583 | if( pCeoff[x] != 0 ) |
---|
1584 | { |
---|
1585 | uiNumofCoeff++; |
---|
1586 | } |
---|
1587 | } |
---|
1588 | pCeoff += uiSize; |
---|
1589 | } |
---|
1590 | } |
---|
1591 | return uiNumofCoeff; |
---|
1592 | } |
---|
1593 | |
---|
1594 | Void TEncSbac::codeQtRootCbf( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
1595 | { |
---|
1596 | UInt uiCbf = pcCU->getQtRootCbf( uiAbsPartIdx ); |
---|
1597 | UInt uiCtx = pcCU->getCtxQtRootCbf( uiAbsPartIdx ); |
---|
1598 | m_pcBinIf->encodeBin( uiCbf , m_cCUQtRootCbfSCModel.get( 0, 0, uiCtx ) ); |
---|
1599 | DTRACE_CABAC_V( g_nSymbolCounter++ ) |
---|
1600 | DTRACE_CABAC_T( "\tparseQtRootCbf()" ) |
---|
1601 | DTRACE_CABAC_T( "\tsymbol=" ) |
---|
1602 | DTRACE_CABAC_V( uiCbf ) |
---|
1603 | DTRACE_CABAC_T( "\tctx=" ) |
---|
1604 | DTRACE_CABAC_V( uiCtx ) |
---|
1605 | DTRACE_CABAC_T( "\tuiAbsPartIdx=" ) |
---|
1606 | DTRACE_CABAC_V( uiAbsPartIdx ) |
---|
1607 | DTRACE_CABAC_T( "\n" ) |
---|
1608 | } |
---|
1609 | |
---|
1610 | Void TEncSbac::xCheckCoeff( TCoeff* pcCoef, UInt uiSize, UInt uiDepth, UInt& uiNumofCoeff, UInt& uiPart ) |
---|
1611 | { |
---|
1612 | UInt ui = uiSize>>uiDepth; |
---|
1613 | if( uiPart == 0 ) |
---|
1614 | { |
---|
1615 | if( ui <= 4 ) |
---|
1616 | { |
---|
1617 | UInt x, y; |
---|
1618 | TCoeff* pCeoff = pcCoef; |
---|
1619 | for( y=0 ; y<ui ; y++ ) |
---|
1620 | { |
---|
1621 | for( x=0 ; x<ui ; x++ ) |
---|
1622 | { |
---|
1623 | if( pCeoff[x] != 0 ) |
---|
1624 | { |
---|
1625 | uiNumofCoeff++; |
---|
1626 | } |
---|
1627 | } |
---|
1628 | pCeoff += uiSize; |
---|
1629 | } |
---|
1630 | } |
---|
1631 | else |
---|
1632 | { |
---|
1633 | xCheckCoeff( pcCoef, uiSize, uiDepth+1, uiNumofCoeff, uiPart ); uiPart++; //1st Part |
---|
1634 | xCheckCoeff( pcCoef + (ui>>1), uiSize, uiDepth+1, uiNumofCoeff, uiPart ); uiPart++; //2nd Part |
---|
1635 | xCheckCoeff( pcCoef + (ui>>1)*uiSize, uiSize, uiDepth+1, uiNumofCoeff, uiPart ); uiPart++; //3rd Part |
---|
1636 | xCheckCoeff( pcCoef + (ui>>1)*uiSize + (ui>>1), uiSize, uiDepth+1, uiNumofCoeff, uiPart ); //4th Part |
---|
1637 | } |
---|
1638 | } |
---|
1639 | else |
---|
1640 | { |
---|
1641 | UInt x, y; |
---|
1642 | TCoeff* pCeoff = pcCoef; |
---|
1643 | for( y=0 ; y<ui ; y++ ) |
---|
1644 | { |
---|
1645 | for( x=0 ; x<ui ; x++ ) |
---|
1646 | { |
---|
1647 | if( pCeoff[x] != 0 ) |
---|
1648 | { |
---|
1649 | uiNumofCoeff++; |
---|
1650 | } |
---|
1651 | } |
---|
1652 | pCeoff += uiSize; |
---|
1653 | } |
---|
1654 | } |
---|
1655 | } |
---|
1656 | |
---|
1657 | UInt xCheckCoeffPlainCNoRecur( const TCoeff* pcCoef, UInt uiSize, UInt uiDepth ); |
---|
1658 | |
---|
1659 | #if PCP_SIGMAP_SIMPLE_LAST |
---|
1660 | /** Encode (X,Y) position of the last significant coefficient |
---|
1661 | * \param uiPosX X component of last coefficient |
---|
1662 | * \param uiPosY Y component of last coefficient |
---|
1663 | * \param uiWidth block width |
---|
1664 | * \param eTType plane type / luminance or chrominance |
---|
1665 | * \param uiCTXIdx block size context |
---|
1666 | * \param uiScanIdx scan type (zig-zag, hor, ver) |
---|
1667 | * \returns Void |
---|
1668 | * This method encodes the X and Y component within a block of the last significant coefficient. |
---|
1669 | */ |
---|
1670 | __inline Void TEncSbac::codeLastSignificantXY( UInt uiPosX, UInt uiPosY, const UInt uiWidth, const TextType eTType, const UInt uiCTXIdx, const UInt uiScanIdx ) |
---|
1671 | { |
---|
1672 | UInt uiCtxLast; |
---|
1673 | const UInt uiCtxOffset = g_uiCtxXYOffset[uiCTXIdx]; |
---|
1674 | |
---|
1675 | if( uiScanIdx == SCAN_VER ) |
---|
1676 | { |
---|
1677 | swap( uiPosX, uiPosY ); |
---|
1678 | } |
---|
1679 | |
---|
1680 | for(uiCtxLast=0; uiCtxLast<uiPosX; uiCtxLast++) |
---|
1681 | { |
---|
1682 | m_pcBinIf->encodeBin( 0, m_cCuCtxLastX.get( 0, eTType, uiCtxOffset + g_uiCtxXY[uiCtxLast] ) ); |
---|
1683 | } |
---|
1684 | if(uiPosX < uiWidth - 1) |
---|
1685 | { |
---|
1686 | m_pcBinIf->encodeBin( 1, m_cCuCtxLastX.get( 0, eTType, uiCtxOffset + g_uiCtxXY[uiCtxLast] ) ); |
---|
1687 | } |
---|
1688 | |
---|
1689 | for(uiCtxLast=0; uiCtxLast<uiPosY; uiCtxLast++) |
---|
1690 | { |
---|
1691 | m_pcBinIf->encodeBin( 0, m_cCuCtxLastY.get( 0, eTType, uiCtxOffset + g_uiCtxXY[uiCtxLast] ) ); |
---|
1692 | } |
---|
1693 | if(uiPosY < uiWidth - 1) |
---|
1694 | { |
---|
1695 | m_pcBinIf->encodeBin( 1, m_cCuCtxLastY.get( 0, eTType, uiCtxOffset + g_uiCtxXY[uiCtxLast] ) ); |
---|
1696 | } |
---|
1697 | } |
---|
1698 | #endif |
---|
1699 | |
---|
1700 | Void TEncSbac::codeCoeffNxN( TComDataCU* pcCU, TCoeff* pcCoef, UInt uiAbsPartIdx, UInt uiWidth, UInt uiHeight, UInt uiDepth, TextType eTType, Bool bRD ) |
---|
1701 | { |
---|
1702 | DTRACE_CABAC_V( g_nSymbolCounter++ ) |
---|
1703 | DTRACE_CABAC_T( "\tparseCoeffNxN()\teType=" ) |
---|
1704 | DTRACE_CABAC_V( eTType ) |
---|
1705 | DTRACE_CABAC_T( "\twidth=" ) |
---|
1706 | DTRACE_CABAC_V( uiWidth ) |
---|
1707 | DTRACE_CABAC_T( "\theight=" ) |
---|
1708 | DTRACE_CABAC_V( uiHeight ) |
---|
1709 | DTRACE_CABAC_T( "\tdepth=" ) |
---|
1710 | DTRACE_CABAC_V( uiDepth ) |
---|
1711 | DTRACE_CABAC_T( "\tabspartidx=" ) |
---|
1712 | DTRACE_CABAC_V( uiAbsPartIdx ) |
---|
1713 | DTRACE_CABAC_T( "\ttoCU-X=" ) |
---|
1714 | DTRACE_CABAC_V( pcCU->getCUPelX() ) |
---|
1715 | DTRACE_CABAC_T( "\ttoCU-Y=" ) |
---|
1716 | DTRACE_CABAC_V( pcCU->getCUPelY() ) |
---|
1717 | DTRACE_CABAC_T( "\tCU-addr=" ) |
---|
1718 | DTRACE_CABAC_V( pcCU->getAddr() ) |
---|
1719 | DTRACE_CABAC_T( "\tinCU-X=" ) |
---|
1720 | DTRACE_CABAC_V( g_auiRasterToPelX[ g_auiZscanToRaster[uiAbsPartIdx] ] ) |
---|
1721 | DTRACE_CABAC_T( "\tinCU-Y=" ) |
---|
1722 | DTRACE_CABAC_V( g_auiRasterToPelY[ g_auiZscanToRaster[uiAbsPartIdx] ] ) |
---|
1723 | DTRACE_CABAC_T( "\tpredmode=" ) |
---|
1724 | DTRACE_CABAC_V( pcCU->getPredictionMode( uiAbsPartIdx ) ) |
---|
1725 | DTRACE_CABAC_T( "\n" ) |
---|
1726 | if( uiWidth > m_pcSlice->getSPS()->getMaxTrSize() ) |
---|
1727 | { |
---|
1728 | uiWidth = m_pcSlice->getSPS()->getMaxTrSize(); |
---|
1729 | uiHeight = m_pcSlice->getSPS()->getMaxTrSize(); |
---|
1730 | } |
---|
1731 | |
---|
1732 | UInt uiNumSig = 0; |
---|
1733 | UInt uiCTXIdx = 0; |
---|
1734 | |
---|
1735 | switch( uiWidth ) |
---|
1736 | { |
---|
1737 | case 2: uiCTXIdx = 6; break; |
---|
1738 | case 4: uiCTXIdx = 5; break; |
---|
1739 | case 8: uiCTXIdx = 4; break; |
---|
1740 | case 16: uiCTXIdx = 3; break; |
---|
1741 | case 32: uiCTXIdx = 2; break; |
---|
1742 | case 64: uiCTXIdx = 1; break; |
---|
1743 | default: uiCTXIdx = 0; break; |
---|
1744 | } |
---|
1745 | |
---|
1746 | // compute number of significant coefficients |
---|
1747 | UInt uiPart = 0; |
---|
1748 | xCheckCoeff(pcCoef, uiWidth, 0, uiNumSig, uiPart ); |
---|
1749 | |
---|
1750 | if ( bRD ) |
---|
1751 | { |
---|
1752 | UInt uiTempDepth = uiDepth - pcCU->getDepth( uiAbsPartIdx ); |
---|
1753 | pcCU->setCbfSubParts( ( uiNumSig ? 1 : 0 ) << uiTempDepth, eTType, uiAbsPartIdx, uiDepth ); |
---|
1754 | } |
---|
1755 | |
---|
1756 | if ( uiNumSig == 0 ) |
---|
1757 | return; |
---|
1758 | |
---|
1759 | eTType = eTType == TEXT_LUMA ? TEXT_LUMA : ( eTType == TEXT_NONE ? TEXT_NONE : TEXT_CHROMA ); |
---|
1760 | |
---|
1761 | //----- encode significance map ----- |
---|
1762 | const UInt uiLog2BlockSize = g_aucConvertToBit[ uiWidth ] + 2; |
---|
1763 | const UInt uiMaxNumCoeff = 1 << ( uiLog2BlockSize << 1 ); |
---|
1764 | #if !PCP_SIGMAP_SIMPLE_LAST |
---|
1765 | const UInt uiMaxNumCoeffM1 = uiMaxNumCoeff - 1; |
---|
1766 | #endif |
---|
1767 | const UInt uiNum4x4Blk = max<UInt>( 1, uiMaxNumCoeff >> 4 ); |
---|
1768 | #if QC_MDCS |
---|
1769 | const UInt uiScanIdx = pcCU->getCoefScanIdx(uiAbsPartIdx, uiWidth, eTType==TEXT_LUMA, pcCU->isIntra(uiAbsPartIdx)); |
---|
1770 | #endif //QC_MDCS |
---|
1771 | |
---|
1772 | #if PCP_SIGMAP_SIMPLE_LAST |
---|
1773 | //===== code last coeff ===== |
---|
1774 | UInt uiScanPosLast = 0, uiPosLastX, uiPosLastY; |
---|
1775 | for( UInt uiScanPos = 0; uiScanPos < uiMaxNumCoeff; uiScanPos++ ) |
---|
1776 | { |
---|
1777 | #if QC_MDCS |
---|
1778 | UInt uiBlkPos = g_auiSigLastScan[uiScanIdx][uiLog2BlockSize-1][uiScanPos]; |
---|
1779 | #else |
---|
1780 | UInt uiBlkPos = g_auiFrameScanXY[ uiLog2BlockSize-1 ][ uiScanPos ]; |
---|
1781 | #endif //QC_MDCS |
---|
1782 | uiPosLastY = uiBlkPos >> uiLog2BlockSize; |
---|
1783 | uiPosLastX = uiBlkPos - ( uiPosLastY << uiLog2BlockSize ); |
---|
1784 | |
---|
1785 | if( pcCoef[ uiBlkPos ] != 0 ) |
---|
1786 | { |
---|
1787 | uiNumSig--; |
---|
1788 | if( uiNumSig == 0 ) |
---|
1789 | { |
---|
1790 | codeLastSignificantXY(uiPosLastX, uiPosLastY, uiWidth, eTType, uiCTXIdx, uiScanIdx); |
---|
1791 | uiScanPosLast = uiScanPos; |
---|
1792 | break; |
---|
1793 | } |
---|
1794 | } |
---|
1795 | } |
---|
1796 | |
---|
1797 | //===== code significance flag ===== |
---|
1798 | { |
---|
1799 | for( UInt uiScanPos = 0; uiScanPos < uiScanPosLast; uiScanPos++ ) |
---|
1800 | { |
---|
1801 | #if QC_MDCS |
---|
1802 | UInt uiBlkPos = g_auiSigLastScan[uiScanIdx][uiLog2BlockSize-1][uiScanPos]; |
---|
1803 | #else |
---|
1804 | UInt uiBlkPos = g_auiFrameScanXY[ uiLog2BlockSize-1 ][ uiScanPos ]; |
---|
1805 | #endif //QC_MDCS |
---|
1806 | UInt uiPosY = uiBlkPos >> uiLog2BlockSize; |
---|
1807 | UInt uiPosX = uiBlkPos - ( uiPosY << uiLog2BlockSize ); |
---|
1808 | UInt uiSig = pcCoef[ uiBlkPos ] != 0 ? 1 : 0; |
---|
1809 | UInt uiCtxSig = TComTrQuant::getSigCtxInc( pcCoef, uiPosX, uiPosY, uiLog2BlockSize, uiWidth ); |
---|
1810 | #if SIMPLE_CONTEXT_SIG |
---|
1811 | if( uiCtxSig < 4 || eTType) |
---|
1812 | { |
---|
1813 | m_pcBinIf->encodeBin( uiSig, m_cCUSigSCModel.get( uiCTXIdx-2, eTType, uiCtxSig ) ); |
---|
1814 | } |
---|
1815 | else |
---|
1816 | { |
---|
1817 | m_pcBinIf->encodeBin( uiSig, m_cCUSigSCModel.get( uiCTXIdx-2 ? uiCTXIdx-2 : 1, eTType, uiCtxSig ) ); |
---|
1818 | } |
---|
1819 | #else |
---|
1820 | m_pcBinIf->encodeBin( uiSig, m_cCUSigSCModel.get( uiCTXIdx, eTType, uiCtxSig ) ); |
---|
1821 | #endif |
---|
1822 | } |
---|
1823 | } |
---|
1824 | |
---|
1825 | #else |
---|
1826 | for( UInt uiScanPos = 0; uiScanPos < uiMaxNumCoeffM1; uiScanPos++ ) |
---|
1827 | { |
---|
1828 | #if QC_MDCS |
---|
1829 | UInt uiBlkPos = g_auiSigLastScan[uiScanIdx][uiLog2BlockSize-1][uiScanPos]; |
---|
1830 | #else |
---|
1831 | UInt uiBlkPos = g_auiFrameScanXY[ uiLog2BlockSize-1 ][ uiScanPos ]; |
---|
1832 | #endif //QC_MDCS |
---|
1833 | UInt uiPosY = uiBlkPos >> uiLog2BlockSize; |
---|
1834 | UInt uiPosX = uiBlkPos - ( uiPosY << uiLog2BlockSize ); |
---|
1835 | |
---|
1836 | //===== code significance flag ===== |
---|
1837 | UInt uiSig = pcCoef[ uiBlkPos ] != 0 ? 1 : 0; |
---|
1838 | UInt uiCtxSig = TComTrQuant::getSigCtxInc( pcCoef, uiPosX, uiPosY, uiLog2BlockSize, uiWidth ); |
---|
1839 | #if SIMPLE_CONTEXT_SIG |
---|
1840 | if( uiCtxSig < 4 || eTType) |
---|
1841 | { |
---|
1842 | m_pcBinIf->encodeBin( uiSig, m_cCUSigSCModel.get( uiCTXIdx-2, eTType, uiCtxSig ) ); |
---|
1843 | } |
---|
1844 | else |
---|
1845 | { |
---|
1846 | m_pcBinIf->encodeBin( uiSig, m_cCUSigSCModel.get( uiCTXIdx-2 ? uiCTXIdx-2 : 1, eTType, uiCtxSig ) ); |
---|
1847 | } |
---|
1848 | #else |
---|
1849 | m_pcBinIf->encodeBin( uiSig, m_cCUSigSCModel.get( uiCTXIdx, eTType, uiCtxSig ) ); |
---|
1850 | #endif |
---|
1851 | if( uiSig ) |
---|
1852 | { |
---|
1853 | uiNumSig--; |
---|
1854 | |
---|
1855 | //===== code last flag ===== |
---|
1856 | UInt uiLast = ( uiNumSig == 0 ) ? 1 : 0; |
---|
1857 | UInt uiCtxLast = TComTrQuant::getLastCtxInc( uiPosX, uiPosY, uiLog2BlockSize ); |
---|
1858 | m_pcBinIf->encodeBin( uiLast, m_cCULastSCModel.get( uiCTXIdx, eTType, uiCtxLast ) ); |
---|
1859 | |
---|
1860 | if( uiLast ) |
---|
1861 | { |
---|
1862 | break; |
---|
1863 | } |
---|
1864 | } |
---|
1865 | } |
---|
1866 | #endif |
---|
1867 | /* |
---|
1868 | * Sign and bin0 PCP (Section 3.2 and 3.3 of JCTVC-B088) |
---|
1869 | */ |
---|
1870 | Int c1, c2; |
---|
1871 | UInt uiSign; |
---|
1872 | UInt uiAbs; |
---|
1873 | #if E253 |
---|
1874 | UInt uiGoRiceParam = 0; |
---|
1875 | #endif |
---|
1876 | |
---|
1877 | if( uiNum4x4Blk > 1 ) |
---|
1878 | { |
---|
1879 | Bool b1stBlk = true; |
---|
1880 | UInt uiNumOne = 0; |
---|
1881 | |
---|
1882 | for( UInt uiSubBlk = 0; uiSubBlk < uiNum4x4Blk; uiSubBlk++ ) |
---|
1883 | { |
---|
1884 | UInt uiCtxSet = 0; |
---|
1885 | UInt uiSubNumSig = 0; |
---|
1886 | UInt uiSubPosX = 0; |
---|
1887 | UInt uiSubPosY = 0; |
---|
1888 | #if E253 |
---|
1889 | uiGoRiceParam = 0; |
---|
1890 | #endif |
---|
1891 | |
---|
1892 | uiSubPosX = g_auiFrameScanX[ g_aucConvertToBit[ uiWidth ] - 1 ][ uiSubBlk ] << 2; |
---|
1893 | uiSubPosY = g_auiFrameScanY[ g_aucConvertToBit[ uiWidth ] - 1 ][ uiSubBlk ] << 2; |
---|
1894 | |
---|
1895 | TCoeff* piCurr = &pcCoef[ uiSubPosX + uiSubPosY * uiWidth ]; |
---|
1896 | |
---|
1897 | for( UInt uiY = 0; uiY < 4; uiY++ ) |
---|
1898 | { |
---|
1899 | for( UInt uiX = 0; uiX < 4; uiX++ ) |
---|
1900 | { |
---|
1901 | if( piCurr[ uiX ] ) |
---|
1902 | { |
---|
1903 | uiSubNumSig++; |
---|
1904 | } |
---|
1905 | } |
---|
1906 | piCurr += uiWidth; |
---|
1907 | } |
---|
1908 | |
---|
1909 | if( uiSubNumSig > 0 ) |
---|
1910 | { |
---|
1911 | c1 = 1; |
---|
1912 | c2 = 0; |
---|
1913 | |
---|
1914 | if( b1stBlk ) |
---|
1915 | { |
---|
1916 | b1stBlk = false; |
---|
1917 | uiCtxSet = 5; |
---|
1918 | } |
---|
1919 | else |
---|
1920 | { |
---|
1921 | uiCtxSet = ( uiNumOne >> 2 ) + 1; |
---|
1922 | uiNumOne = 0; |
---|
1923 | } |
---|
1924 | |
---|
1925 | for( UInt uiScanPos = 0; uiScanPos < 16; uiScanPos++ ) |
---|
1926 | { |
---|
1927 | UInt uiBlkPos = g_auiFrameScanXY[ 1 ][ 15 - uiScanPos ]; |
---|
1928 | UInt uiPosY = uiBlkPos >> 2; |
---|
1929 | UInt uiPosX = uiBlkPos - ( uiPosY << 2 ); |
---|
1930 | UInt uiIndex = ( ( uiSubPosY + uiPosY ) << uiLog2BlockSize ) + uiSubPosX + uiPosX; |
---|
1931 | |
---|
1932 | if( pcCoef[ uiIndex ] ) |
---|
1933 | { |
---|
1934 | if( pcCoef[ uiIndex ] > 0) { uiAbs = static_cast<UInt>( pcCoef[ uiIndex ]); uiSign = 0; } |
---|
1935 | else { uiAbs = static_cast<UInt>(-pcCoef[ uiIndex ]); uiSign = 1; } |
---|
1936 | |
---|
1937 | UInt uiCtx = min<UInt>(c1, 4); |
---|
1938 | UInt uiSymbol = uiAbs > 1 ? 1 : 0; |
---|
1939 | m_pcBinIf->encodeBin( uiSymbol, m_cCUOneSCModel.get( 0, eTType, ( uiCtxSet << 2 ) + uiCtxSet + uiCtx ) ); |
---|
1940 | |
---|
1941 | if( uiSymbol ) |
---|
1942 | { |
---|
1943 | c1 = 0; |
---|
1944 | } |
---|
1945 | else if( c1 ) |
---|
1946 | { |
---|
1947 | c1++; |
---|
1948 | } |
---|
1949 | } |
---|
1950 | } |
---|
1951 | |
---|
1952 | for( UInt uiScanPos = 0; uiScanPos < 16; uiScanPos++ ) |
---|
1953 | { |
---|
1954 | UInt uiBlkPos = g_auiFrameScanXY[ 1 ][ 15 - uiScanPos ]; |
---|
1955 | UInt uiPosY = uiBlkPos >> 2; |
---|
1956 | UInt uiPosX = uiBlkPos - ( uiPosY << 2 ); |
---|
1957 | UInt uiIndex = ( ( uiSubPosY + uiPosY ) << uiLog2BlockSize ) + uiSubPosX + uiPosX; |
---|
1958 | |
---|
1959 | if( pcCoef[ uiIndex ] ) |
---|
1960 | { |
---|
1961 | if( pcCoef[ uiIndex ] > 0) { uiAbs = static_cast<UInt>( pcCoef[ uiIndex ]); uiSign = 0; } |
---|
1962 | else { uiAbs = static_cast<UInt>(-pcCoef[ uiIndex ]); uiSign = 1; } |
---|
1963 | |
---|
1964 | UInt uiSymbol = uiAbs > 1 ? 1 : 0; |
---|
1965 | |
---|
1966 | if( uiSymbol ) |
---|
1967 | { |
---|
1968 | UInt uiCtx = min<UInt>(c2, 4); |
---|
1969 | uiAbs -= 2; |
---|
1970 | c2++; |
---|
1971 | uiNumOne++; |
---|
1972 | #if E253 |
---|
1973 | uiSymbol = uiAbs > 0 ? 1 : 0; |
---|
1974 | |
---|
1975 | m_pcBinIf->encodeBin( uiSymbol, m_cCUAbsSCModel.get( 0, eTType, ( uiCtxSet << 2 ) + uiCtxSet + uiCtx ) ); |
---|
1976 | |
---|
1977 | if( uiSymbol ) |
---|
1978 | { |
---|
1979 | uiAbs -= 1; |
---|
1980 | xWriteGoRiceExGolomb( uiAbs, uiGoRiceParam ); |
---|
1981 | } |
---|
1982 | #else |
---|
1983 | xWriteExGolombLevel( uiAbs, m_cCUAbsSCModel.get( 0, eTType, ( uiCtxSet << 2 ) + uiCtxSet + uiCtx ) ); |
---|
1984 | #endif |
---|
1985 | } |
---|
1986 | } |
---|
1987 | } |
---|
1988 | |
---|
1989 | for( UInt uiScanPos = 0; uiScanPos < 16; uiScanPos++ ) |
---|
1990 | { |
---|
1991 | UInt uiBlkPos = g_auiFrameScanXY[ 1 ][ 15 - uiScanPos ]; |
---|
1992 | UInt uiPosY = uiBlkPos >> 2; |
---|
1993 | UInt uiPosX = uiBlkPos - ( uiPosY << 2 ); |
---|
1994 | UInt uiIndex = ( ( uiSubPosY + uiPosY ) << uiLog2BlockSize ) + uiSubPosX + uiPosX; |
---|
1995 | |
---|
1996 | if( pcCoef[ uiIndex ] ) |
---|
1997 | { |
---|
1998 | if( pcCoef[ uiIndex ] > 0) { uiAbs = static_cast<UInt>( pcCoef[ uiIndex ]); uiSign = 0; } |
---|
1999 | else { uiAbs = static_cast<UInt>(-pcCoef[ uiIndex ]); uiSign = 1; } |
---|
2000 | m_pcBinIf->encodeBinEP( uiSign ); |
---|
2001 | } |
---|
2002 | } |
---|
2003 | |
---|
2004 | } |
---|
2005 | } |
---|
2006 | } |
---|
2007 | else |
---|
2008 | { |
---|
2009 | c1 = 1; |
---|
2010 | c2 = 0; |
---|
2011 | |
---|
2012 | for( UInt uiScanPos = 0; uiScanPos < 16; uiScanPos++ ) |
---|
2013 | { |
---|
2014 | UInt uiIndex = g_auiFrameScanXY[ 1 ][ 15 - uiScanPos ]; |
---|
2015 | |
---|
2016 | if( pcCoef[ uiIndex ] ) |
---|
2017 | { |
---|
2018 | if( pcCoef[ uiIndex ] > 0) { uiAbs = static_cast<UInt>( pcCoef[ uiIndex ]); uiSign = 0; } |
---|
2019 | else { uiAbs = static_cast<UInt>(-pcCoef[ uiIndex ]); uiSign = 1; } |
---|
2020 | |
---|
2021 | UInt uiCtx = min<UInt>(c1, 4); |
---|
2022 | UInt uiSymbol = uiAbs > 1 ? 1 : 0; |
---|
2023 | m_pcBinIf->encodeBin( uiSymbol, m_cCUOneSCModel.get( 0, eTType, uiCtx ) ); |
---|
2024 | |
---|
2025 | if( uiSymbol ) |
---|
2026 | { |
---|
2027 | c1 = 0; |
---|
2028 | } |
---|
2029 | else if( c1 ) |
---|
2030 | { |
---|
2031 | c1++; |
---|
2032 | } |
---|
2033 | } |
---|
2034 | } |
---|
2035 | |
---|
2036 | for( UInt uiScanPos = 0; uiScanPos < 16; uiScanPos++ ) |
---|
2037 | { |
---|
2038 | UInt uiIndex = g_auiFrameScanXY[ 1 ][ 15 - uiScanPos ]; |
---|
2039 | |
---|
2040 | if( pcCoef[ uiIndex ] ) |
---|
2041 | { |
---|
2042 | if( pcCoef[ uiIndex ] > 0) { uiAbs = static_cast<UInt>( pcCoef[ uiIndex ]); uiSign = 0; } |
---|
2043 | else { uiAbs = static_cast<UInt>(-pcCoef[ uiIndex ]); uiSign = 1; } |
---|
2044 | |
---|
2045 | UInt uiSymbol = uiAbs > 1 ? 1 : 0; |
---|
2046 | |
---|
2047 | if( uiSymbol ) |
---|
2048 | { |
---|
2049 | UInt uiCtx = min<UInt>(c2, 4); |
---|
2050 | uiAbs -= 2; |
---|
2051 | c2++; |
---|
2052 | #if E253 |
---|
2053 | uiSymbol = uiAbs > 0 ? 1 : 0; |
---|
2054 | |
---|
2055 | m_pcBinIf->encodeBin( uiSymbol, m_cCUAbsSCModel.get( 0, eTType, uiCtx ) ); |
---|
2056 | |
---|
2057 | if( uiSymbol ) |
---|
2058 | { |
---|
2059 | uiAbs -= 1; |
---|
2060 | xWriteGoRiceExGolomb( uiAbs, uiGoRiceParam ); |
---|
2061 | } |
---|
2062 | #else |
---|
2063 | xWriteExGolombLevel( uiAbs, m_cCUAbsSCModel.get( 0, eTType, uiCtx ) ); |
---|
2064 | #endif |
---|
2065 | } |
---|
2066 | } |
---|
2067 | } |
---|
2068 | |
---|
2069 | for( UInt uiScanPos = 0; uiScanPos < 16; uiScanPos++ ) |
---|
2070 | { |
---|
2071 | UInt uiIndex = g_auiFrameScanXY[ 1 ][ 15 - uiScanPos ]; |
---|
2072 | |
---|
2073 | if( pcCoef[ uiIndex ] ) |
---|
2074 | { |
---|
2075 | if( pcCoef[ uiIndex ] > 0) { uiAbs = static_cast<UInt>( pcCoef[ uiIndex ]); uiSign = 0; } |
---|
2076 | else { uiAbs = static_cast<UInt>(-pcCoef[ uiIndex ]); uiSign = 1; } |
---|
2077 | |
---|
2078 | m_pcBinIf->encodeBinEP( uiSign ); |
---|
2079 | } |
---|
2080 | } |
---|
2081 | } |
---|
2082 | return; |
---|
2083 | } |
---|
2084 | |
---|
2085 | #if MVD_CTX |
---|
2086 | /** Encode a motion vector difference |
---|
2087 | * \param iMvd motion vector difference |
---|
2088 | * \param uiAbsSumL motion vector difference of left PU |
---|
2089 | * \param uiAbsSumA motion vector difference of above PU |
---|
2090 | * \param uiCtx index for context set based on vertical or horizontal component |
---|
2091 | */ |
---|
2092 | Void TEncSbac::xWriteMvd( Int iMvd, UInt uiAbsSumL, UInt uiAbsSumA, UInt uiCtx ) |
---|
2093 | #else |
---|
2094 | Void TEncSbac::xWriteMvd( Int iMvd, UInt uiAbsSum, UInt uiCtx ) |
---|
2095 | #endif |
---|
2096 | { |
---|
2097 | UInt uiLocalCtx = 0; |
---|
2098 | #if MVD_CTX |
---|
2099 | uiLocalCtx += (uiAbsSumA>16) ? 1 : 0; |
---|
2100 | uiLocalCtx += (uiAbsSumL>16) ? 1 : 0; |
---|
2101 | #else |
---|
2102 | if ( uiAbsSum >= 3 ) |
---|
2103 | { |
---|
2104 | uiLocalCtx += ( uiAbsSum > 32 ) ? 2 : 1; |
---|
2105 | } |
---|
2106 | #endif |
---|
2107 | |
---|
2108 | UInt uiSymbol = ( 0 == iMvd ) ? 0 : 1; |
---|
2109 | m_pcBinIf->encodeBin( uiSymbol, m_cCUMvdSCModel.get( 0, uiCtx, uiLocalCtx ) ); |
---|
2110 | if ( 0 == uiSymbol ) |
---|
2111 | { |
---|
2112 | return; |
---|
2113 | } |
---|
2114 | |
---|
2115 | UInt uiSign = 0; |
---|
2116 | if ( 0 > iMvd ) |
---|
2117 | { |
---|
2118 | uiSign = 1; |
---|
2119 | iMvd = -iMvd; |
---|
2120 | } |
---|
2121 | xWriteExGolombMvd( iMvd-1, &m_cCUMvdSCModel.get( 0, uiCtx, 3 ), 3 ); |
---|
2122 | m_pcBinIf->encodeBinEP( uiSign ); |
---|
2123 | |
---|
2124 | return; |
---|
2125 | } |
---|
2126 | |
---|
2127 | Void TEncSbac::xWriteExGolombMvd( UInt uiSymbol, ContextModel* pcSCModel, UInt uiMaxBin ) |
---|
2128 | { |
---|
2129 | if ( ! uiSymbol ) |
---|
2130 | { |
---|
2131 | m_pcBinIf->encodeBin( 0, *pcSCModel ); |
---|
2132 | return; |
---|
2133 | } |
---|
2134 | |
---|
2135 | m_pcBinIf->encodeBin( 1, *pcSCModel ); |
---|
2136 | |
---|
2137 | Bool bNoExGo = ( uiSymbol < 8 ); |
---|
2138 | UInt uiCount = 1; |
---|
2139 | pcSCModel++; |
---|
2140 | |
---|
2141 | while ( --uiSymbol && ++uiCount <= 8 ) |
---|
2142 | { |
---|
2143 | m_pcBinIf->encodeBin( 1, *pcSCModel ); |
---|
2144 | if ( uiCount == 2 ) |
---|
2145 | { |
---|
2146 | pcSCModel++; |
---|
2147 | } |
---|
2148 | if ( uiCount == uiMaxBin ) |
---|
2149 | { |
---|
2150 | pcSCModel++; |
---|
2151 | } |
---|
2152 | } |
---|
2153 | |
---|
2154 | if ( bNoExGo ) |
---|
2155 | { |
---|
2156 | m_pcBinIf->encodeBin( 0, *pcSCModel ); |
---|
2157 | } |
---|
2158 | else |
---|
2159 | { |
---|
2160 | xWriteEpExGolomb( uiSymbol, 3 ); |
---|
2161 | } |
---|
2162 | |
---|
2163 | return; |
---|
2164 | } |
---|
2165 | |
---|
2166 | Void TEncSbac::codeAlfFlag ( UInt uiCode ) |
---|
2167 | { |
---|
2168 | UInt uiSymbol = ( ( uiCode == 0 ) ? 0 : 1 ); |
---|
2169 | m_pcBinIf->encodeBin( uiSymbol, m_cALFFlagSCModel.get( 0, 0, 0 ) ); |
---|
2170 | } |
---|
2171 | |
---|
2172 | #if TSB_ALF_HEADER |
---|
2173 | Void TEncSbac::codeAlfFlagNum( UInt uiCode, UInt minValue ) |
---|
2174 | { |
---|
2175 | UInt uiLength = 0; |
---|
2176 | UInt maxValue = (minValue << (this->getMaxAlfCtrlDepth()*2)); |
---|
2177 | assert((uiCode>=minValue)&&(uiCode<=maxValue)); |
---|
2178 | UInt temp = maxValue - minValue; |
---|
2179 | for(UInt i=0; i<32; i++) |
---|
2180 | { |
---|
2181 | if(temp&0x1) |
---|
2182 | { |
---|
2183 | uiLength = i+1; |
---|
2184 | } |
---|
2185 | temp = (temp >> 1); |
---|
2186 | } |
---|
2187 | UInt uiSymbol = uiCode - minValue; |
---|
2188 | if(uiLength) |
---|
2189 | { |
---|
2190 | while( uiLength-- ) |
---|
2191 | { |
---|
2192 | m_pcBinIf->encodeBinEP( (uiSymbol>>uiLength) & 0x1 ); |
---|
2193 | } |
---|
2194 | } |
---|
2195 | } |
---|
2196 | |
---|
2197 | Void TEncSbac::codeAlfCtrlFlag( UInt uiSymbol ) |
---|
2198 | { |
---|
2199 | m_pcBinIf->encodeBin( uiSymbol, m_cCUAlfCtrlFlagSCModel.get( 0, 0, 0) ); |
---|
2200 | } |
---|
2201 | #endif |
---|
2202 | |
---|
2203 | Void TEncSbac::codeAlfUvlc ( UInt uiCode ) |
---|
2204 | { |
---|
2205 | Int i; |
---|
2206 | |
---|
2207 | if ( uiCode == 0 ) |
---|
2208 | { |
---|
2209 | m_pcBinIf->encodeBin( 0, m_cALFUvlcSCModel.get( 0, 0, 0 ) ); |
---|
2210 | } |
---|
2211 | else |
---|
2212 | { |
---|
2213 | m_pcBinIf->encodeBin( 1, m_cALFUvlcSCModel.get( 0, 0, 0 ) ); |
---|
2214 | for ( i=0; i<uiCode-1; i++ ) |
---|
2215 | { |
---|
2216 | m_pcBinIf->encodeBin( 1, m_cALFUvlcSCModel.get( 0, 0, 1 ) ); |
---|
2217 | } |
---|
2218 | m_pcBinIf->encodeBin( 0, m_cALFUvlcSCModel.get( 0, 0, 1 ) ); |
---|
2219 | } |
---|
2220 | } |
---|
2221 | |
---|
2222 | Void TEncSbac::codeAlfSvlc ( Int iCode ) |
---|
2223 | { |
---|
2224 | Int i; |
---|
2225 | |
---|
2226 | if ( iCode == 0 ) |
---|
2227 | { |
---|
2228 | m_pcBinIf->encodeBin( 0, m_cALFSvlcSCModel.get( 0, 0, 0 ) ); |
---|
2229 | } |
---|
2230 | else |
---|
2231 | { |
---|
2232 | m_pcBinIf->encodeBin( 1, m_cALFSvlcSCModel.get( 0, 0, 0 ) ); |
---|
2233 | |
---|
2234 | // write sign |
---|
2235 | if ( iCode > 0 ) |
---|
2236 | { |
---|
2237 | m_pcBinIf->encodeBin( 0, m_cALFSvlcSCModel.get( 0, 0, 1 ) ); |
---|
2238 | } |
---|
2239 | else |
---|
2240 | { |
---|
2241 | m_pcBinIf->encodeBin( 1, m_cALFSvlcSCModel.get( 0, 0, 1 ) ); |
---|
2242 | iCode = -iCode; |
---|
2243 | } |
---|
2244 | |
---|
2245 | // write magnitude |
---|
2246 | for ( i=0; i<iCode-1; i++ ) |
---|
2247 | { |
---|
2248 | m_pcBinIf->encodeBin( 1, m_cALFSvlcSCModel.get( 0, 0, 2 ) ); |
---|
2249 | } |
---|
2250 | m_pcBinIf->encodeBin( 0, m_cALFSvlcSCModel.get( 0, 0, 2 ) ); |
---|
2251 | } |
---|
2252 | } |
---|
2253 | |
---|
2254 | #if MTK_SAO |
---|
2255 | Void TEncSbac::codeAoFlag ( UInt uiCode ) |
---|
2256 | { |
---|
2257 | UInt uiSymbol = ( ( uiCode == 0 ) ? 0 : 1 ); |
---|
2258 | m_pcBinIf->encodeBin( uiSymbol, m_cAOFlagSCModel.get( 0, 0, 0 ) ); |
---|
2259 | } |
---|
2260 | Void TEncSbac::codeAoUvlc ( UInt uiCode ) |
---|
2261 | { |
---|
2262 | Int i; |
---|
2263 | |
---|
2264 | if ( uiCode == 0 ) |
---|
2265 | { |
---|
2266 | m_pcBinIf->encodeBin( 0, m_cAOUvlcSCModel.get( 0, 0, 0 ) ); |
---|
2267 | } |
---|
2268 | else |
---|
2269 | { |
---|
2270 | m_pcBinIf->encodeBin( 1, m_cAOUvlcSCModel.get( 0, 0, 0 ) ); |
---|
2271 | for ( i=0; i<uiCode-1; i++ ) |
---|
2272 | { |
---|
2273 | m_pcBinIf->encodeBin( 1, m_cAOUvlcSCModel.get( 0, 0, 1 ) ); |
---|
2274 | } |
---|
2275 | m_pcBinIf->encodeBin( 0, m_cAOUvlcSCModel.get( 0, 0, 1 ) ); |
---|
2276 | } |
---|
2277 | } |
---|
2278 | Void TEncSbac::codeAoSvlc ( Int iCode ) |
---|
2279 | { |
---|
2280 | Int i; |
---|
2281 | |
---|
2282 | if ( iCode == 0 ) |
---|
2283 | { |
---|
2284 | m_pcBinIf->encodeBin( 0, m_cAOSvlcSCModel.get( 0, 0, 0 ) ); |
---|
2285 | } |
---|
2286 | else |
---|
2287 | { |
---|
2288 | m_pcBinIf->encodeBin( 1, m_cAOSvlcSCModel.get( 0, 0, 0 ) ); |
---|
2289 | |
---|
2290 | // write sign |
---|
2291 | if ( iCode > 0 ) |
---|
2292 | { |
---|
2293 | m_pcBinIf->encodeBin( 0, m_cAOSvlcSCModel.get( 0, 0, 1 ) ); |
---|
2294 | } |
---|
2295 | else |
---|
2296 | { |
---|
2297 | m_pcBinIf->encodeBin( 1, m_cAOSvlcSCModel.get( 0, 0, 1 ) ); |
---|
2298 | iCode = -iCode; |
---|
2299 | } |
---|
2300 | |
---|
2301 | // write magnitude |
---|
2302 | for ( i=0; i<iCode-1; i++ ) |
---|
2303 | { |
---|
2304 | m_pcBinIf->encodeBin( 1, m_cAOSvlcSCModel.get( 0, 0, 2 ) ); |
---|
2305 | } |
---|
2306 | m_pcBinIf->encodeBin( 0, m_cAOSvlcSCModel.get( 0, 0, 2 ) ); |
---|
2307 | } |
---|
2308 | } |
---|
2309 | #endif |
---|
2310 | |
---|
2311 | /*! |
---|
2312 | **************************************************************************** |
---|
2313 | * \brief |
---|
2314 | * estimate bit cost for CBP, significant map and significant coefficients |
---|
2315 | **************************************************************************** |
---|
2316 | */ |
---|
2317 | Void TEncSbac::estBit( estBitsSbacStruct* pcEstBitsSbac, UInt uiCTXIdx, TextType eTType ) |
---|
2318 | { |
---|
2319 | estCBFBit( pcEstBitsSbac, 0, eTType ); |
---|
2320 | |
---|
2321 | // encode significance map |
---|
2322 | estSignificantMapBit( pcEstBitsSbac, uiCTXIdx, eTType ); |
---|
2323 | |
---|
2324 | // encode significant coefficients |
---|
2325 | estSignificantCoefficientsBit( pcEstBitsSbac, uiCTXIdx, eTType ); |
---|
2326 | } |
---|
2327 | |
---|
2328 | /*! |
---|
2329 | **************************************************************************** |
---|
2330 | * \brief |
---|
2331 | * estimate bit cost for each CBP bit |
---|
2332 | **************************************************************************** |
---|
2333 | */ |
---|
2334 | Void TEncSbac::estCBFBit( estBitsSbacStruct* pcEstBitsSbac, UInt uiCTXIdx, TextType eTType ) |
---|
2335 | { |
---|
2336 | ContextModel *pCtx = m_cCUQtCbfSCModel.get( 0 ); |
---|
2337 | |
---|
2338 | for( UInt uiCtxInc = 0; uiCtxInc < 45; uiCtxInc++ ) |
---|
2339 | { |
---|
2340 | pcEstBitsSbac->blockCbpBits[ uiCtxInc ][ 0 ] = biari_no_bits( 0, pCtx[ uiCtxInc ] ); |
---|
2341 | pcEstBitsSbac->blockCbpBits[ uiCtxInc ][ 1 ] = biari_no_bits( 1, pCtx[ uiCtxInc ] ); |
---|
2342 | } |
---|
2343 | |
---|
2344 | for( UInt uiCtxInc = 0; uiCtxInc < 4; uiCtxInc++ ) |
---|
2345 | { |
---|
2346 | pcEstBitsSbac->blockRootCbpBits[ uiCtxInc ][ 0 ] = biari_no_bits( 0, m_cCUQtRootCbfSCModel.get( 0, 0, uiCtxInc ) ); |
---|
2347 | pcEstBitsSbac->blockRootCbpBits[ uiCtxInc ][ 1 ] = biari_no_bits( 1, m_cCUQtRootCbfSCModel.get( 0, 0, uiCtxInc ) ); |
---|
2348 | } |
---|
2349 | } |
---|
2350 | |
---|
2351 | |
---|
2352 | /*! |
---|
2353 | **************************************************************************** |
---|
2354 | * \brief |
---|
2355 | * estimate SAMBAC bit cost for significant coefficient map |
---|
2356 | **************************************************************************** |
---|
2357 | */ |
---|
2358 | Void TEncSbac::estSignificantMapBit( estBitsSbacStruct* pcEstBitsSbac, UInt uiCTXIdx, TextType eTType ) |
---|
2359 | { |
---|
2360 | for ( UInt uiCtx = 0; uiCtx < 16; uiCtx++ ) |
---|
2361 | { |
---|
2362 | for( UInt uiBin = 0; uiBin < 2; uiBin++ ) |
---|
2363 | { |
---|
2364 | #if SIMPLE_CONTEXT_SIG |
---|
2365 | if( uiCtx < 4 || eTType ) |
---|
2366 | { |
---|
2367 | pcEstBitsSbac->significantBits[ uiCtx ][ uiBin ] = biari_no_bits ( uiBin, m_cCUSigSCModel.get( uiCTXIdx-2, eTType, uiCtx ) ); |
---|
2368 | } |
---|
2369 | else |
---|
2370 | { |
---|
2371 | pcEstBitsSbac->significantBits[ uiCtx ][ uiBin ] = biari_no_bits ( uiBin, m_cCUSigSCModel.get( uiCTXIdx-2 ? uiCTXIdx-2 : 1, eTType, uiCtx ) ); |
---|
2372 | } |
---|
2373 | #else |
---|
2374 | pcEstBitsSbac->significantBits[ uiCtx ][ uiBin ] = biari_no_bits ( uiBin, m_cCUSigSCModel.get( uiCTXIdx, eTType, uiCtx ) ); |
---|
2375 | #endif |
---|
2376 | |
---|
2377 | #if !PCP_SIGMAP_SIMPLE_LAST |
---|
2378 | pcEstBitsSbac->lastBits[ uiCtx ][ uiBin ] = biari_no_bits ( uiBin, m_cCULastSCModel.get( uiCTXIdx, eTType, uiCtx ) ); |
---|
2379 | #endif |
---|
2380 | } |
---|
2381 | } |
---|
2382 | |
---|
2383 | #if PCP_SIGMAP_SIMPLE_LAST |
---|
2384 | Int iBitsX = 0, iBitsY = 0; |
---|
2385 | const UInt uiCtxOffset = g_uiCtxXYOffset[uiCTXIdx]; |
---|
2386 | const UInt uiWidthM1 = (1 << (7-uiCTXIdx)) - 1; |
---|
2387 | for ( UInt uiCtx = 0; uiCtx < uiWidthM1; uiCtx++ ) |
---|
2388 | { |
---|
2389 | pcEstBitsSbac->lastXBits[uiCtx] = iBitsX + biari_no_bits (1, m_cCuCtxLastX.get( 0, eTType, uiCtxOffset + g_uiCtxXY[uiCtx] )); |
---|
2390 | pcEstBitsSbac->lastYBits[uiCtx] = iBitsY + biari_no_bits (1, m_cCuCtxLastY.get( 0, eTType, uiCtxOffset + g_uiCtxXY[uiCtx] )); |
---|
2391 | iBitsX += biari_no_bits (0, m_cCuCtxLastX.get( 0, eTType, uiCtxOffset + g_uiCtxXY[uiCtx] )); |
---|
2392 | iBitsY += biari_no_bits (0, m_cCuCtxLastY.get( 0, eTType, uiCtxOffset + g_uiCtxXY[uiCtx] )); |
---|
2393 | } |
---|
2394 | pcEstBitsSbac->lastXBits[uiWidthM1] = iBitsX; |
---|
2395 | pcEstBitsSbac->lastYBits[uiWidthM1] = iBitsY; |
---|
2396 | #endif |
---|
2397 | } |
---|
2398 | |
---|
2399 | /*! |
---|
2400 | **************************************************************************** |
---|
2401 | * \brief |
---|
2402 | * estimate bit cost of significant coefficient |
---|
2403 | **************************************************************************** |
---|
2404 | */ |
---|
2405 | Void TEncSbac::estSignificantCoefficientsBit( estBitsSbacStruct* pcEstBitsSbac, UInt uiCTXIdx, TextType eTType ) |
---|
2406 | { |
---|
2407 | for( UInt uiSet = 0; uiSet < 6; uiSet++ ) |
---|
2408 | { |
---|
2409 | for( UInt uiCtx = 0; uiCtx < 5; uiCtx++ ) |
---|
2410 | { |
---|
2411 | pcEstBitsSbac->greaterOneBits[ uiSet ][ 0 ][ uiCtx ][ 0 ] = biari_no_bits( 0, m_cCUOneSCModel.get( 0, eTType, ( uiSet << 2 ) + uiSet + uiCtx ) ); |
---|
2412 | pcEstBitsSbac->greaterOneBits[ uiSet ][ 0 ][ uiCtx ][ 1 ] = biari_no_bits( 1, m_cCUOneSCModel.get( 0, eTType, ( uiSet << 2 ) + uiSet + uiCtx ) ); |
---|
2413 | pcEstBitsSbac->greaterOneBits[ uiSet ][ 1 ][ uiCtx ][ 0 ] = biari_no_bits( 0, m_cCUAbsSCModel.get( 0, eTType, ( uiSet << 2 ) + uiSet + uiCtx ) ); |
---|
2414 | pcEstBitsSbac->greaterOneBits[ uiSet ][ 1 ][ uiCtx ][ 1 ] = biari_no_bits( 1, m_cCUAbsSCModel.get( 0, eTType, ( uiSet << 2 ) + uiSet + uiCtx ) ); |
---|
2415 | } |
---|
2416 | } |
---|
2417 | } |
---|
2418 | |
---|
2419 | Int TEncSbac::biari_no_bits( Short symbol, ContextModel& rcSCModel ) |
---|
2420 | { |
---|
2421 | UInt uiEstBits; |
---|
2422 | Short ui16State; |
---|
2423 | |
---|
2424 | symbol = (Short)( symbol != 0 ); |
---|
2425 | ui16State = symbol == rcSCModel.getMps() ? 64 + rcSCModel.getState() : 63 - rcSCModel.getState(); |
---|
2426 | uiEstBits = entropyBits[ 127 - ui16State ]; |
---|
2427 | return uiEstBits; |
---|
2428 | } |
---|