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