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