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 || POZNAN_DBMP |
---|
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 | #if POZNAN_DBMP |
---|
673 | const Bool bDBMPAvailable = pcCU->getSlice()->getMP()->isDBMPEnabled(); |
---|
674 | #endif |
---|
675 | for( UInt uiIdx = 0; uiIdx < MRG_MAX_NUM_CANDS; uiIdx++ ) |
---|
676 | { |
---|
677 | #if HHI_MPI |
---|
678 | if( uiIdx == uiMviMergePos ) |
---|
679 | { |
---|
680 | abAvailable[ uiIdx ] = true; |
---|
681 | uiNumCand++; |
---|
682 | } |
---|
683 | else if( uiIdx > uiMviMergePos ) |
---|
684 | { |
---|
685 | if( ( abAvailable[ uiIdx ] = ( pcCU->getNeighbourCandIdx( uiIdx - 1, uiAbsPartIdx ) == uiIdx ) ) ) |
---|
686 | { |
---|
687 | uiNumCand++; |
---|
688 | } |
---|
689 | } |
---|
690 | else |
---|
691 | #endif |
---|
692 | if( ( abAvailable[ uiIdx ] = ( pcCU->getNeighbourCandIdx( uiIdx, uiAbsPartIdx ) == uiIdx + 1 ) ) ) |
---|
693 | { |
---|
694 | uiNumCand++; |
---|
695 | } |
---|
696 | } |
---|
697 | |
---|
698 | #if POZNAN_DBMP |
---|
699 | if(bDBMPAvailable) |
---|
700 | { |
---|
701 | UInt uiDBMPMergePos = POZNAN_DBMP_MERGE_POS; |
---|
702 | #if HHI_MPI |
---|
703 | if(bMVIAvailable && uiDBMPMergePos>=uiMviMergePos) uiDBMPMergePos++; |
---|
704 | #endif |
---|
705 | for( Int iIdx = MRG_MAX_NUM_CANDS-2; iIdx >= (Int)uiDBMPMergePos; iIdx-- ) |
---|
706 | { |
---|
707 | Int iWrIdx = iIdx+1; |
---|
708 | #if HHI_MPI |
---|
709 | if(bMVIAvailable) |
---|
710 | { |
---|
711 | if(iIdx==(Int)uiMviMergePos) continue; |
---|
712 | if(iWrIdx==(Int)uiMviMergePos) iWrIdx++; |
---|
713 | } |
---|
714 | #endif |
---|
715 | if(iWrIdx>=MRG_MAX_NUM_CANDS) continue; |
---|
716 | |
---|
717 | abAvailable[ iWrIdx ] = abAvailable[ iIdx ]; |
---|
718 | } |
---|
719 | abAvailable[ uiDBMPMergePos ] = ( pcCU->getNeighbourCandIdx( POZNAN_DBMP_MRG_CAND, uiAbsPartIdx ) == POZNAN_DBMP_MRG_CAND + 1 ); |
---|
720 | |
---|
721 | uiNumCand = 0; for( UInt uiIdx = 0; uiIdx < MRG_MAX_NUM_CANDS; uiIdx++ ) if(abAvailable[ uiIdx ]) uiNumCand++; |
---|
722 | } |
---|
723 | #endif |
---|
724 | |
---|
725 | AOF( uiNumCand > 1 ); |
---|
726 | |
---|
727 | //--- determine contexts --- |
---|
728 | AOF( NUM_MV_MERGE_IDX_EXT_CTX >= MRG_MAX_NUM_CANDS - 1 ); |
---|
729 | UInt auiCtx[ MRG_MAX_NUM_CANDS - 1 ]; |
---|
730 | for( UInt uiIdx = 0; uiIdx < MRG_MAX_NUM_CANDS - 1; uiIdx++ ) |
---|
731 | { |
---|
732 | auiCtx[ uiIdx ] = MRG_MAX_NUM_CANDS; |
---|
733 | if( uiNumCand > uiIdx + 1 ) |
---|
734 | { |
---|
735 | Bool bAvComb = false; |
---|
736 | for( UInt uiCId = uiIdx; uiCId < MRG_MAX_NUM_CANDS - 1; uiCId++ ) |
---|
737 | { |
---|
738 | bAvComb = ( bAvComb || abAvailable[ uiCId ] ); |
---|
739 | if( abAvailable[ uiCId + 1 ] && bAvComb ) |
---|
740 | { |
---|
741 | auiCtx[ uiIdx ] = uiCId; |
---|
742 | break; |
---|
743 | } |
---|
744 | } |
---|
745 | AOT( auiCtx[ uiIdx ] == MRG_MAX_NUM_CANDS ); |
---|
746 | } |
---|
747 | } |
---|
748 | |
---|
749 | //--- determine unary index --- |
---|
750 | UInt uiMergeIdx = pcCU->getMergeIndex( uiAbsPartIdx ); |
---|
751 | #if POZNAN_DBMP |
---|
752 | if(bDBMPAvailable) |
---|
753 | { |
---|
754 | if(uiMergeIdx==POZNAN_DBMP_MRG_CAND) uiMergeIdx = POZNAN_DBMP_MERGE_POS; |
---|
755 | else if(uiMergeIdx>=POZNAN_DBMP_MERGE_POS) uiMergeIdx++; |
---|
756 | } |
---|
757 | #endif |
---|
758 | #if HHI_MPI |
---|
759 | if( bMVIAvailable ) |
---|
760 | { |
---|
761 | const Bool bUseMVI = pcCU->getTextureModeDepth( uiAbsPartIdx ) != -1; |
---|
762 | if( bUseMVI ) |
---|
763 | { |
---|
764 | uiMergeIdx = HHI_MPI_MERGE_POS; |
---|
765 | } |
---|
766 | else if( uiMergeIdx >= HHI_MPI_MERGE_POS ) |
---|
767 | { |
---|
768 | uiMergeIdx++; |
---|
769 | } |
---|
770 | } |
---|
771 | #endif |
---|
772 | UInt uiUnaryIdx = uiMergeIdx; |
---|
773 | for( UInt uiIdx = 0; uiIdx < uiMergeIdx; uiIdx++ ) |
---|
774 | { |
---|
775 | if( ! abAvailable[ uiIdx ] ) |
---|
776 | { |
---|
777 | uiUnaryIdx--; |
---|
778 | } |
---|
779 | } |
---|
780 | |
---|
781 | //--- code unary index --- |
---|
782 | for( UInt ui = 0; ui < uiNumCand - 1; ui++ ) |
---|
783 | { |
---|
784 | const UInt uiSymbol = ( ui == uiUnaryIdx ? 0 : 1 ); |
---|
785 | m_pcBinIf->encodeBin( uiSymbol, m_cCUMVMergeIdxExtSCModel.get( 0, 0, auiCtx[ui] ) ); |
---|
786 | if( uiSymbol == 0 ) |
---|
787 | { |
---|
788 | break; |
---|
789 | } |
---|
790 | } |
---|
791 | |
---|
792 | //--- trace --- |
---|
793 | DTRACE_CABAC_V( g_nSymbolCounter++ ); |
---|
794 | DTRACE_CABAC_T( "\tparseMergeIndex():" ); |
---|
795 | DTRACE_CABAC_T( " MRGIdx = " ); |
---|
796 | DTRACE_CABAC_V( uiMergeIdx ); |
---|
797 | DTRACE_CABAC_T( " UnaryIdx = " ); |
---|
798 | DTRACE_CABAC_V( uiUnaryIdx ); |
---|
799 | DTRACE_CABAC_T( " NumCand = " ); |
---|
800 | DTRACE_CABAC_V( uiNumCand ); |
---|
801 | DTRACE_CABAC_T( " Availibility = " ); |
---|
802 | for( UInt uiIdx = 0; uiIdx < MRG_MAX_NUM_CANDS; uiIdx++ ) |
---|
803 | { |
---|
804 | DTRACE_CABAC_V( abAvailable[ uiIdx ] ? 1 : 0 ); |
---|
805 | } |
---|
806 | DTRACE_CABAC_T( " Contexts = " ); |
---|
807 | for( UInt uiIdx = 0; uiIdx < MRG_MAX_NUM_CANDS - 1; uiIdx++ ) |
---|
808 | { |
---|
809 | DTRACE_CABAC_V( auiCtx[ uiIdx ] ); |
---|
810 | } |
---|
811 | DTRACE_CABAC_T( "\n" ); |
---|
812 | } |
---|
813 | #endif |
---|
814 | |
---|
815 | |
---|
816 | /** code merge index |
---|
817 | * \param pcCU |
---|
818 | * \param uiAbsPartIdx |
---|
819 | * \returns Void |
---|
820 | */ |
---|
821 | Void TEncSbac::codeMergeIndex( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
822 | { |
---|
823 | /* todo jacek niech sie wypowie |
---|
824 | #if HHI_INTER_VIEW_MOTION_PRED || HHI_MPI |
---|
825 | #if HHI_INTER_VIEW_MOTION_PRED && HHI_MPI |
---|
826 | if( ( pcCU->getSlice()->getSPS()->getViewId() > 0 && ( pcCU->getSlice()->getSPS()->getMultiviewMvPredMode() & PDM_USE_FOR_MERGE ) == PDM_USE_FOR_MERGE ) || |
---|
827 | ( pcCU->getSlice()->getSPS()->getUseMVI() && pcCU->getSlice()->getSliceType() != I_SLICE && pcCU->getPartitionSize( uiAbsPartIdx ) == SIZE_2Nx2N ) ) |
---|
828 | #elif HHI_MPI |
---|
829 | if( pcCU->getSlice()->getSPS()->getUseMVI() && pcCU->getSlice()->getSliceType() != I_SLICE && pcCU->getPartitionSize( uiAbsPartIdx ) == SIZE_2Nx2N ) |
---|
830 | #else |
---|
831 | if( pcCU->getSlice()->getSPS()->getViewId() > 0 && ( pcCU->getSlice()->getSPS()->getMultiviewMvPredMode() & PDM_USE_FOR_MERGE ) == PDM_USE_FOR_MERGE ) |
---|
832 | #endif//*/ |
---|
833 | #if HHI_INTER_VIEW_MOTION_PRED || HHI_MPI || POZNAN_DBMP |
---|
834 | if( |
---|
835 | #if HHI_INTER_VIEW_MOTION_PRED |
---|
836 | ( pcCU->getSlice()->getSPS()->getViewId() > 0 && ( pcCU->getSlice()->getSPS()->getMultiviewMvPredMode() & PDM_USE_FOR_MERGE ) == PDM_USE_FOR_MERGE ) || |
---|
837 | #endif |
---|
838 | #if HHI_MPI |
---|
839 | ( pcCU->getSlice()->getSPS()->getUseMVI() && pcCU->getSlice()->getSliceType() != I_SLICE && pcCU->getPartitionSize( uiAbsPartIdx ) == SIZE_2Nx2N ) || |
---|
840 | #endif |
---|
841 | #if POZNAN_DBMP |
---|
842 | ( pcCU->getSlice()->getMP()->isDBMPEnabled() ) || |
---|
843 | #endif |
---|
844 | 0 |
---|
845 | ) |
---|
846 | { |
---|
847 | codeMergeIndexMV( pcCU, uiAbsPartIdx ); |
---|
848 | return; |
---|
849 | } |
---|
850 | #endif |
---|
851 | |
---|
852 | Bool bLeftInvolved = false; |
---|
853 | Bool bAboveInvolved = false; |
---|
854 | Bool bCollocatedInvolved = false; |
---|
855 | Bool bCornerInvolved = false; |
---|
856 | Bool bCornerBLInvolved = false; |
---|
857 | UInt uiNumCand = 0; |
---|
858 | for( UInt uiIter = 0; uiIter < MRG_MAX_NUM_CANDS; ++uiIter ) |
---|
859 | { |
---|
860 | if( pcCU->getNeighbourCandIdx( uiIter, uiAbsPartIdx ) == uiIter + 1 ) |
---|
861 | { |
---|
862 | uiNumCand++; |
---|
863 | if( uiIter == 0 ) |
---|
864 | { |
---|
865 | bLeftInvolved = true; |
---|
866 | } |
---|
867 | else if( uiIter == 1 ) |
---|
868 | { |
---|
869 | bAboveInvolved = true; |
---|
870 | } |
---|
871 | else if( uiIter == 2 ) |
---|
872 | { |
---|
873 | bCollocatedInvolved = true; |
---|
874 | } |
---|
875 | else if( uiIter == 3 ) |
---|
876 | { |
---|
877 | bCornerInvolved = true; |
---|
878 | } |
---|
879 | else if( uiIter == 4 ) |
---|
880 | { |
---|
881 | bCornerBLInvolved = true; |
---|
882 | } |
---|
883 | } |
---|
884 | } |
---|
885 | assert( uiNumCand > 1 ); |
---|
886 | |
---|
887 | UInt auiCtx[4] = { 0, 0, 0, 3 }; |
---|
888 | if( bLeftInvolved && bAboveInvolved ) |
---|
889 | { |
---|
890 | auiCtx[0] = 0; |
---|
891 | } |
---|
892 | else if( bLeftInvolved || bAboveInvolved ) |
---|
893 | { |
---|
894 | auiCtx[0] = bCollocatedInvolved ? 1 : 2; |
---|
895 | } |
---|
896 | else |
---|
897 | { |
---|
898 | auiCtx[0] = bCollocatedInvolved ? 2 : 3; |
---|
899 | } |
---|
900 | |
---|
901 | if( uiNumCand >= 3 ) |
---|
902 | { |
---|
903 | if( bAboveInvolved ) |
---|
904 | { |
---|
905 | auiCtx[1] = bCollocatedInvolved ? 1 : 2; |
---|
906 | } |
---|
907 | else |
---|
908 | { |
---|
909 | auiCtx[1] = bCollocatedInvolved ? 2 : 3; |
---|
910 | } |
---|
911 | } |
---|
912 | |
---|
913 | if( uiNumCand >= 4 ) |
---|
914 | { |
---|
915 | auiCtx[2] = bCollocatedInvolved ? 2 : 3; |
---|
916 | } |
---|
917 | |
---|
918 | UInt uiUnaryIdx = pcCU->getMergeIndex( uiAbsPartIdx ); |
---|
919 | |
---|
920 | if( !bCornerInvolved && uiUnaryIdx > 3 ) |
---|
921 | { |
---|
922 | --uiUnaryIdx; |
---|
923 | } |
---|
924 | if( !bCollocatedInvolved && uiUnaryIdx > 2 ) |
---|
925 | { |
---|
926 | --uiUnaryIdx; |
---|
927 | } |
---|
928 | if( !bAboveInvolved && uiUnaryIdx > 1 ) |
---|
929 | { |
---|
930 | --uiUnaryIdx; |
---|
931 | } |
---|
932 | if( !bLeftInvolved && uiUnaryIdx > 0 ) |
---|
933 | { |
---|
934 | --uiUnaryIdx; |
---|
935 | } |
---|
936 | |
---|
937 | for( UInt ui = 0; ui < uiNumCand - 1; ++ui ) |
---|
938 | { |
---|
939 | const UInt uiSymbol = ui == uiUnaryIdx ? 0 : 1; |
---|
940 | m_pcBinIf->encodeBin( uiSymbol, m_cCUMergeIdxExtSCModel.get( 0, 0, auiCtx[ui] ) ); |
---|
941 | if( uiSymbol == 0 ) |
---|
942 | { |
---|
943 | break; |
---|
944 | } |
---|
945 | } |
---|
946 | |
---|
947 | DTRACE_CABAC_V( g_nSymbolCounter++ ); |
---|
948 | DTRACE_CABAC_T( "\tparseMergeIndex()" ); |
---|
949 | DTRACE_CABAC_T( "\tuiMRGIdx= " ); |
---|
950 | DTRACE_CABAC_V( pcCU->getMergeIndex( uiAbsPartIdx ) ); |
---|
951 | DTRACE_CABAC_T( "\tuiNumCand= " ); |
---|
952 | DTRACE_CABAC_V( uiNumCand ); |
---|
953 | DTRACE_CABAC_T( "\tbLeftInvolved= " ); |
---|
954 | DTRACE_CABAC_V( bLeftInvolved ); |
---|
955 | DTRACE_CABAC_T( "\tbAboveInvolved= " ); |
---|
956 | DTRACE_CABAC_V( bAboveInvolved ); |
---|
957 | DTRACE_CABAC_T( "\tbCollocatedInvolved= " ); |
---|
958 | DTRACE_CABAC_V( bCollocatedInvolved ); |
---|
959 | DTRACE_CABAC_T( "\tbCornerRTInvolved= " ); |
---|
960 | DTRACE_CABAC_V( bCornerInvolved ); |
---|
961 | DTRACE_CABAC_T( "\tbCornerBLInvolved= " ); |
---|
962 | DTRACE_CABAC_V( bCornerBLInvolved ); |
---|
963 | DTRACE_CABAC_T( "\n" ); |
---|
964 | } |
---|
965 | |
---|
966 | |
---|
967 | #if HHI_INTER_VIEW_RESIDUAL_PRED |
---|
968 | Void |
---|
969 | TEncSbac::codeResPredFlag( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
970 | { |
---|
971 | UInt uiCtx = 0; |
---|
972 | UInt uiSymbol = ( pcCU->getResPredFlag( uiAbsPartIdx ) ? 1 : 0 ); |
---|
973 | m_pcBinIf->encodeBin( uiSymbol, m_cResPredFlagSCModel.get( 0, 0, uiCtx ) ); |
---|
974 | } |
---|
975 | #endif |
---|
976 | |
---|
977 | |
---|
978 | Void TEncSbac::codeSplitFlag ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth ) |
---|
979 | { |
---|
980 | if( uiDepth == g_uiMaxCUDepth - g_uiAddCUDepth ) |
---|
981 | return; |
---|
982 | |
---|
983 | UInt uiCtx = pcCU->getCtxSplitFlag( uiAbsPartIdx, uiDepth ); |
---|
984 | UInt uiCurrSplitFlag = ( pcCU->getDepth( uiAbsPartIdx ) > uiDepth ) ? 1 : 0; |
---|
985 | |
---|
986 | assert( uiCtx < 3 ); |
---|
987 | m_pcBinIf->encodeBin( uiCurrSplitFlag, m_cCUSplitFlagSCModel.get( 0, 0, uiCtx ) ); |
---|
988 | DTRACE_CABAC_V( g_nSymbolCounter++ ) |
---|
989 | DTRACE_CABAC_T( "\tSplitFlag\n" ) |
---|
990 | return; |
---|
991 | } |
---|
992 | |
---|
993 | Void TEncSbac::codeTransformSubdivFlag( UInt uiSymbol, UInt uiCtx ) |
---|
994 | { |
---|
995 | m_pcBinIf->encodeBin( uiSymbol, m_cCUTransSubdivFlagSCModel.get( 0, 0, uiCtx ) ); |
---|
996 | DTRACE_CABAC_V( g_nSymbolCounter++ ) |
---|
997 | DTRACE_CABAC_T( "\tparseTransformSubdivFlag()" ) |
---|
998 | DTRACE_CABAC_T( "\tsymbol=" ) |
---|
999 | DTRACE_CABAC_V( uiSymbol ) |
---|
1000 | DTRACE_CABAC_T( "\tctx=" ) |
---|
1001 | DTRACE_CABAC_V( uiCtx ) |
---|
1002 | DTRACE_CABAC_T( "\n" ) |
---|
1003 | } |
---|
1004 | |
---|
1005 | #if HHI_DMM_WEDGE_INTRA |
---|
1006 | Void TEncSbac::xCodeWedgeFullInfo( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
1007 | { |
---|
1008 | Int iIntraIdx = pcCU->getIntraSizeIdx(uiAbsPartIdx); |
---|
1009 | Int iBits = g_aucWedgeFullBitsListIdx[iIntraIdx]; |
---|
1010 | |
---|
1011 | UInt uiTabIdx = pcCU->getWedgeFullTabIdx( uiAbsPartIdx ); |
---|
1012 | |
---|
1013 | for ( Int i = 0; i < iBits; i++ ) |
---|
1014 | { |
---|
1015 | m_pcBinIf->encodeBin( ( uiTabIdx >> i ) & 1, m_cIntraWedgeSCModel.get(0, 0, 0) ); |
---|
1016 | } |
---|
1017 | } |
---|
1018 | |
---|
1019 | Void TEncSbac::xCodeWedgeFullDeltaInfo( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
1020 | { |
---|
1021 | Int iIntraIdx = pcCU->getIntraSizeIdx(uiAbsPartIdx); |
---|
1022 | Int iBits = g_aucWedgeFullBitsListIdx[iIntraIdx]; |
---|
1023 | |
---|
1024 | UInt uiTabIdx = pcCU->getWedgeFullTabIdx( uiAbsPartIdx ); |
---|
1025 | |
---|
1026 | for ( Int i = 0; i < iBits; i++ ) |
---|
1027 | { |
---|
1028 | m_pcBinIf->encodeBin( ( uiTabIdx >> i ) & 1, m_cIntraWedgeSCModel.get(0, 0, 0) ); |
---|
1029 | } |
---|
1030 | |
---|
1031 | Int iDeltaDC1 = pcCU->getWedgeFullDeltaDC1( uiAbsPartIdx ); |
---|
1032 | Int iDeltaDC2 = pcCU->getWedgeFullDeltaDC2( uiAbsPartIdx ); |
---|
1033 | |
---|
1034 | xWriteExGolombLevel( UInt( abs( iDeltaDC1 ) ), m_cIntraWedgeSCModel.get(0, 0, 1) ); |
---|
1035 | if ( iDeltaDC1 != 0 ) |
---|
1036 | { |
---|
1037 | UInt uiSign = iDeltaDC1 > 0 ? 0 : 1; |
---|
1038 | m_pcBinIf->encodeBinEP( uiSign ); |
---|
1039 | } |
---|
1040 | xWriteExGolombLevel( UInt( abs( iDeltaDC2 ) ), m_cIntraWedgeSCModel.get(0, 0, 1) ); |
---|
1041 | if ( iDeltaDC2 != 0 ) |
---|
1042 | { |
---|
1043 | UInt uiSign = iDeltaDC2 > 0 ? 0 : 1; |
---|
1044 | m_pcBinIf->encodeBinEP( uiSign ); |
---|
1045 | } |
---|
1046 | } |
---|
1047 | |
---|
1048 | Void TEncSbac::xCodeWedgePredDirInfo( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
1049 | { |
---|
1050 | if( DMM_WEDGE_PREDDIR_DELTAEND_MAX > 0 ) |
---|
1051 | { |
---|
1052 | Int iDeltaEnd = pcCU->getWedgePredDirDeltaEnd( uiAbsPartIdx ); |
---|
1053 | m_pcBinIf->encodeBin( (iDeltaEnd!=0), m_cIntraWedgeSCModel.get(0, 0, 3) ); |
---|
1054 | |
---|
1055 | if( iDeltaEnd != 0 ) |
---|
1056 | { |
---|
1057 | UInt uiAbsValMinus1 = abs(iDeltaEnd)-1; |
---|
1058 | m_pcBinIf->encodeBin( (uiAbsValMinus1 & 0x01), m_cIntraWedgeSCModel.get(0, 0, 3) ); |
---|
1059 | m_pcBinIf->encodeBin( (uiAbsValMinus1 & 0x02) >> 1, m_cIntraWedgeSCModel.get(0, 0, 3) ); |
---|
1060 | |
---|
1061 | UInt uiSign = iDeltaEnd > 0 ? 0 : 1; |
---|
1062 | m_pcBinIf->encodeBinEP( uiSign ); |
---|
1063 | } |
---|
1064 | } |
---|
1065 | } |
---|
1066 | |
---|
1067 | Void TEncSbac::xCodeWedgePredDirDeltaInfo( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
1068 | { |
---|
1069 | if( DMM_WEDGE_PREDDIR_DELTAEND_MAX > 0 ) |
---|
1070 | { |
---|
1071 | Int iDeltaEnd = pcCU->getWedgePredDirDeltaEnd( uiAbsPartIdx ); |
---|
1072 | m_pcBinIf->encodeBin( (iDeltaEnd!=0), m_cIntraWedgeSCModel.get(0, 0, 3) ); |
---|
1073 | |
---|
1074 | if( iDeltaEnd != 0 ) |
---|
1075 | { |
---|
1076 | UInt uiAbsValMinus1 = abs(iDeltaEnd)-1; |
---|
1077 | m_pcBinIf->encodeBin( (uiAbsValMinus1 & 0x01), m_cIntraWedgeSCModel.get(0, 0, 3) ); |
---|
1078 | m_pcBinIf->encodeBin( (uiAbsValMinus1 & 0x02) >> 1, m_cIntraWedgeSCModel.get(0, 0, 3) ); |
---|
1079 | |
---|
1080 | UInt uiSign = iDeltaEnd > 0 ? 0 : 1; |
---|
1081 | m_pcBinIf->encodeBinEP( uiSign ); |
---|
1082 | } |
---|
1083 | } |
---|
1084 | |
---|
1085 | Int iDeltaDC1 = pcCU->getWedgePredDirDeltaDC1( uiAbsPartIdx ); |
---|
1086 | Int iDeltaDC2 = pcCU->getWedgePredDirDeltaDC2( uiAbsPartIdx ); |
---|
1087 | |
---|
1088 | xWriteExGolombLevel( UInt( abs( iDeltaDC1 ) ), m_cIntraWedgeSCModel.get(0, 0, 1) ); |
---|
1089 | if ( iDeltaDC1 != 0 ) |
---|
1090 | { |
---|
1091 | UInt uiSign = iDeltaDC1 > 0 ? 0 : 1; |
---|
1092 | m_pcBinIf->encodeBinEP( uiSign ); |
---|
1093 | } |
---|
1094 | xWriteExGolombLevel( UInt( abs( iDeltaDC2 ) ), m_cIntraWedgeSCModel.get(0, 0, 1) ); |
---|
1095 | if ( iDeltaDC2 != 0 ) |
---|
1096 | { |
---|
1097 | UInt uiSign = iDeltaDC2 > 0 ? 0 : 1; |
---|
1098 | m_pcBinIf->encodeBinEP( uiSign ); |
---|
1099 | } |
---|
1100 | } |
---|
1101 | #endif |
---|
1102 | #if HHI_DMM_PRED_TEX |
---|
1103 | Void TEncSbac::xCodeWedgePredTexDeltaInfo( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
1104 | { |
---|
1105 | Int iDeltaDC1 = pcCU->getWedgePredTexDeltaDC1( uiAbsPartIdx ); |
---|
1106 | Int iDeltaDC2 = pcCU->getWedgePredTexDeltaDC2( uiAbsPartIdx ); |
---|
1107 | |
---|
1108 | xWriteExGolombLevel( UInt( abs( iDeltaDC1 ) ), m_cIntraWedgeSCModel.get(0, 0, 1) ); |
---|
1109 | if ( iDeltaDC1 != 0 ) |
---|
1110 | { |
---|
1111 | UInt uiSign = iDeltaDC1 > 0 ? 0 : 1; |
---|
1112 | m_pcBinIf->encodeBinEP( uiSign ); |
---|
1113 | } |
---|
1114 | xWriteExGolombLevel( UInt( abs( iDeltaDC2 ) ), m_cIntraWedgeSCModel.get(0, 0, 1) ); |
---|
1115 | if ( iDeltaDC2 != 0 ) |
---|
1116 | { |
---|
1117 | UInt uiSign = iDeltaDC2 > 0 ? 0 : 1; |
---|
1118 | m_pcBinIf->encodeBinEP( uiSign ); |
---|
1119 | } |
---|
1120 | } |
---|
1121 | |
---|
1122 | Void TEncSbac::xCodeContourPredTexDeltaInfo( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
1123 | { |
---|
1124 | Int iDeltaDC1 = pcCU->getContourPredTexDeltaDC1( uiAbsPartIdx ); |
---|
1125 | Int iDeltaDC2 = pcCU->getContourPredTexDeltaDC2( uiAbsPartIdx ); |
---|
1126 | |
---|
1127 | xWriteExGolombLevel( UInt( abs( iDeltaDC1 ) ), m_cIntraWedgeSCModel.get(0, 0, 1) ); |
---|
1128 | if ( iDeltaDC1 != 0 ) |
---|
1129 | { |
---|
1130 | UInt uiSign = iDeltaDC1 > 0 ? 0 : 1; |
---|
1131 | m_pcBinIf->encodeBinEP( uiSign ); |
---|
1132 | } |
---|
1133 | xWriteExGolombLevel( UInt( abs( iDeltaDC2 ) ), m_cIntraWedgeSCModel.get(0, 0, 1) ); |
---|
1134 | if ( iDeltaDC2 != 0 ) |
---|
1135 | { |
---|
1136 | UInt uiSign = iDeltaDC2 > 0 ? 0 : 1; |
---|
1137 | m_pcBinIf->encodeBinEP( uiSign ); |
---|
1138 | } |
---|
1139 | } |
---|
1140 | #endif |
---|
1141 | |
---|
1142 | #if MTK_DCM_MPM |
---|
1143 | Void TEncSbac::codeIntraDirLumaAng( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
1144 | { |
---|
1145 | UInt uiDir = pcCU->getLumaIntraDir( uiAbsPartIdx ); |
---|
1146 | |
---|
1147 | #if HHI_DMM_WEDGE_INTRA || HHI_DMM_PRED_TEX |
---|
1148 | if ( pcCU->getSlice()->getSPS()->isDepth() && pcCU->getSlice()->getSPS()->getUseDMM() && pcCU->getWidth( uiAbsPartIdx ) < 64 ) |
---|
1149 | { |
---|
1150 | m_pcBinIf->encodeBin( uiDir > MAX_MODE_ID_INTRA_DIR, m_cIntraDMMSCModel.get(0, 0, 0) ); |
---|
1151 | } |
---|
1152 | if( uiDir > MAX_MODE_ID_INTRA_DIR ) |
---|
1153 | { |
---|
1154 | assert( pcCU->getWidth( uiAbsPartIdx ) < 64 ); |
---|
1155 | UInt uiDMMode = uiDir - (MAX_MODE_ID_INTRA_DIR+1); |
---|
1156 | |
---|
1157 | #if HHI_DMM_WEDGE_INTRA && HHI_DMM_PRED_TEX |
---|
1158 | m_pcBinIf->encodeBin( (uiDMMode & 0x01), m_cIntraDMMSCModel.get(0, 0, 1) ); |
---|
1159 | m_pcBinIf->encodeBin( (uiDMMode & 0x02) >> 1, m_cIntraDMMSCModel.get(0, 0, 1) ); |
---|
1160 | |
---|
1161 | if ( pcCU->getPartitionSize( uiAbsPartIdx ) != SIZE_NxN && pcCU->getWidth( uiAbsPartIdx ) > 4 ) |
---|
1162 | { |
---|
1163 | m_pcBinIf->encodeBin( (uiDMMode & 0x04) >> 2, m_cIntraDMMSCModel.get(0, 0, 1) ); |
---|
1164 | } |
---|
1165 | #else |
---|
1166 | m_pcBinIf->encodeBin( (uiDMMode & 0x01), m_cIntraDMMSCModel.get(0, 0, 1) ); |
---|
1167 | |
---|
1168 | if ( pcCU->getPartitionSize( uiAbsPartIdx ) != SIZE_NxN && pcCU->getWidth( uiAbsPartIdx ) > 4 ) |
---|
1169 | { |
---|
1170 | m_pcBinIf->encodeBin( (uiDMMode & 0x02) >> 1, m_cIntraDMMSCModel.get(0, 0, 1) ); |
---|
1171 | } |
---|
1172 | #endif |
---|
1173 | #if HHI_DMM_WEDGE_INTRA |
---|
1174 | if( uiDir == DMM_WEDGE_FULL_IDX ) { xCodeWedgeFullInfo ( pcCU, uiAbsPartIdx ); } |
---|
1175 | if( uiDir == DMM_WEDGE_FULL_D_IDX ) { xCodeWedgeFullDeltaInfo ( pcCU, uiAbsPartIdx ); } |
---|
1176 | if( uiDir == DMM_WEDGE_PREDDIR_IDX ) { xCodeWedgePredDirInfo ( pcCU, uiAbsPartIdx ); } |
---|
1177 | if( uiDir == DMM_WEDGE_PREDDIR_D_IDX ) { xCodeWedgePredDirDeltaInfo ( pcCU, uiAbsPartIdx ); } |
---|
1178 | #endif |
---|
1179 | #if HHI_DMM_PRED_TEX |
---|
1180 | if( uiDir == DMM_WEDGE_PREDTEX_D_IDX ) { xCodeWedgePredTexDeltaInfo ( pcCU, uiAbsPartIdx ); } |
---|
1181 | if( uiDir == DMM_CONTOUR_PREDTEX_D_IDX ) { xCodeContourPredTexDeltaInfo( pcCU, uiAbsPartIdx ); } |
---|
1182 | #endif |
---|
1183 | } |
---|
1184 | else |
---|
1185 | #endif |
---|
1186 | { |
---|
1187 | Int iIntraIdx = pcCU->getIntraSizeIdx(uiAbsPartIdx); |
---|
1188 | #if ADD_PLANAR_MODE |
---|
1189 | UInt planarFlag = 0; |
---|
1190 | if (uiDir == PLANAR_IDX) |
---|
1191 | { |
---|
1192 | uiDir = 2; |
---|
1193 | planarFlag = 1; |
---|
1194 | } |
---|
1195 | #endif |
---|
1196 | |
---|
1197 | Int uiPreds[2] = {-1, -1}; |
---|
1198 | Int uiPredNum = pcCU->getIntraDirLumaPredictor(uiAbsPartIdx, uiPreds); |
---|
1199 | |
---|
1200 | Int uiPredIdx = -1; |
---|
1201 | |
---|
1202 | for(UInt i = 0; i < uiPredNum; i++) |
---|
1203 | { |
---|
1204 | if(uiDir == uiPreds[i]) |
---|
1205 | { |
---|
1206 | uiPredIdx = i; |
---|
1207 | } |
---|
1208 | } |
---|
1209 | |
---|
1210 | if(uiPredIdx != -1) |
---|
1211 | { |
---|
1212 | m_pcBinIf->encodeBin( 1, m_cCUIntraPredSCModel.get( 0, 0, 0 ) ); |
---|
1213 | if(uiPredNum == 2) |
---|
1214 | { |
---|
1215 | m_pcBinIf->encodeBin( uiPredIdx, m_cCUIntraPredSCModel.get( 0, 0, 2 ) ); |
---|
1216 | } |
---|
1217 | |
---|
1218 | } |
---|
1219 | else |
---|
1220 | { |
---|
1221 | m_pcBinIf->encodeBin( 0, m_cCUIntraPredSCModel.get( 0, 0, 0 ) ); |
---|
1222 | |
---|
1223 | for(Int i = (uiPredNum - 1); i >= 0; i--) |
---|
1224 | { |
---|
1225 | uiDir = uiDir > uiPreds[i] ? uiDir - 1 : uiDir; |
---|
1226 | } |
---|
1227 | |
---|
1228 | if ( g_aucIntraModeBitsAng[iIntraIdx] < 6 ) |
---|
1229 | { |
---|
1230 | m_pcBinIf->encodeBin((uiDir & 0x01), m_cCUIntraPredSCModel.get(0, 0, 1)); |
---|
1231 | if ( g_aucIntraModeBitsAng[iIntraIdx] > 2 ) { m_pcBinIf->encodeBin((uiDir & 0x02) >> 1, m_cCUIntraPredSCModel.get(0, 0, 1));} |
---|
1232 | if ( g_aucIntraModeBitsAng[iIntraIdx] > 3 ) { m_pcBinIf->encodeBin((uiDir & 0x04) >> 2, m_cCUIntraPredSCModel.get(0, 0, 1));} |
---|
1233 | if ( g_aucIntraModeBitsAng[iIntraIdx] > 4 ) { m_pcBinIf->encodeBin((uiDir & 0x08) >> 3, m_cCUIntraPredSCModel.get(0, 0, 1));} |
---|
1234 | } |
---|
1235 | else |
---|
1236 | { |
---|
1237 | 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 |
---|
1238 | m_pcBinIf->encodeBin((uiDir & 0x01), m_cCUIntraPredSCModel.get(0, 0, 1)); |
---|
1239 | m_pcBinIf->encodeBin((uiDir & 0x02) >> 1, m_cCUIntraPredSCModel.get(0, 0, 1)); |
---|
1240 | m_pcBinIf->encodeBin((uiDir & 0x04) >> 2, m_cCUIntraPredSCModel.get(0, 0, 1)); |
---|
1241 | m_pcBinIf->encodeBin((uiDir & 0x08) >> 3, m_cCUIntraPredSCModel.get(0, 0, 1)); |
---|
1242 | m_pcBinIf->encodeBin((uiDir & 0x10) >> 4, m_cCUIntraPredSCModel.get(0, 0, 1)); |
---|
1243 | } |
---|
1244 | else{ |
---|
1245 | m_pcBinIf->encodeBin(1, m_cCUIntraPredSCModel.get(0, 0, 1)); |
---|
1246 | m_pcBinIf->encodeBin(1, m_cCUIntraPredSCModel.get(0, 0, 1)); |
---|
1247 | m_pcBinIf->encodeBin(1, m_cCUIntraPredSCModel.get(0, 0, 1)); |
---|
1248 | m_pcBinIf->encodeBin(1, m_cCUIntraPredSCModel.get(0, 0, 1)); |
---|
1249 | m_pcBinIf->encodeBin(1, m_cCUIntraPredSCModel.get(0, 0, 1)); |
---|
1250 | m_pcBinIf->encodeBin((uiDir == 32) ? 1 : 0, m_cCUIntraPredSCModel.get(0, 0, 1)); |
---|
1251 | } |
---|
1252 | } |
---|
1253 | } |
---|
1254 | #if ADD_PLANAR_MODE |
---|
1255 | uiDir = pcCU->getLumaIntraDir( uiAbsPartIdx ); |
---|
1256 | if ( (uiDir == PLANAR_IDX) || (uiDir == 2) ) |
---|
1257 | { |
---|
1258 | m_pcBinIf->encodeBin( planarFlag, m_cPlanarFlagSCModel.get(0,0,0) ); |
---|
1259 | } |
---|
1260 | #endif |
---|
1261 | } |
---|
1262 | return; |
---|
1263 | } |
---|
1264 | #else |
---|
1265 | Void TEncSbac::codeIntraDirLumaAng( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
1266 | { |
---|
1267 | UInt uiDir = pcCU->getLumaIntraDir( uiAbsPartIdx ); |
---|
1268 | #if HHI_DMM_WEDGE_INTRA || HHI_DMM_PRED_TEX |
---|
1269 | if ( pcCU->getSlice()->getSPS()->isDepth() && pcCU->getSlice()->getSPS()->getUseDMM() && pcCU->getWidth( uiAbsPartIdx ) < 64 ) |
---|
1270 | { |
---|
1271 | m_pcBinIf->encodeBin( uiDir > MAX_MODE_ID_INTRA_DIR, m_cIntraDMMSCModel.get(0, 0, 0) ); |
---|
1272 | } |
---|
1273 | if( uiDir > MAX_MODE_ID_INTRA_DIR ) |
---|
1274 | { |
---|
1275 | assert( pcCU->getWidth( uiAbsPartIdx ) < 64 ); |
---|
1276 | UInt uiDMMode = uiDir - (MAX_MODE_ID_INTRA_DIR+1); |
---|
1277 | |
---|
1278 | #if HHI_DMM_WEDGE_INTRA && HHI_DMM_PRED_TEX |
---|
1279 | m_pcBinIf->encodeBin( (uiDMMode & 0x01), m_cIntraDMMSCModel.get(0, 0, 1) ); |
---|
1280 | m_pcBinIf->encodeBin( (uiDMMode & 0x02) >> 1, m_cIntraDMMSCModel.get(0, 0, 1) ); |
---|
1281 | |
---|
1282 | if ( pcCU->getPartitionSize( uiAbsPartIdx ) != SIZE_NxN && pcCU->getWidth( uiAbsPartIdx ) > 4 ) |
---|
1283 | { |
---|
1284 | m_pcBinIf->encodeBin( (uiDMMode & 0x04) >> 2, m_cIntraDMMSCModel.get(0, 0, 1) ); |
---|
1285 | } |
---|
1286 | #else |
---|
1287 | m_pcBinIf->encodeBin( (uiDMMode & 0x01), m_cIntraDMMSCModel.get(0, 0, 1) ); |
---|
1288 | |
---|
1289 | if ( pcCU->getPartitionSize( uiAbsPartIdx ) != SIZE_NxN && pcCU->getWidth( uiAbsPartIdx ) > 4 ) |
---|
1290 | { |
---|
1291 | m_pcBinIf->encodeBin( (uiDMMode & 0x02) >> 1, m_cIntraDMMSCModel.get(0, 0, 1) ); |
---|
1292 | } |
---|
1293 | #endif |
---|
1294 | #if HHI_DMM_WEDGE_INTRA |
---|
1295 | if( uiDir == DMM_WEDGE_FULL_IDX ) { xCodeWedgeFullInfo ( pcCU, uiAbsPartIdx ); } |
---|
1296 | if( uiDir == DMM_WEDGE_FULL_D_IDX ) { xCodeWedgeFullDeltaInfo ( pcCU, uiAbsPartIdx ); } |
---|
1297 | if( uiDir == DMM_WEDGE_PREDDIR_IDX ) { xCodeWedgePredDirInfo ( pcCU, uiAbsPartIdx ); } |
---|
1298 | if( uiDir == DMM_WEDGE_PREDDIR_D_IDX ) { xCodeWedgePredDirDeltaInfo ( pcCU, uiAbsPartIdx ); } |
---|
1299 | #endif |
---|
1300 | #if HHI_DMM_PRED_TEX |
---|
1301 | if( uiDir == DMM_WEDGE_PREDTEX_D_IDX ) { xCodeWedgePredTexDeltaInfo ( pcCU, uiAbsPartIdx ); } |
---|
1302 | if( uiDir == DMM_CONTOUR_PREDTEX_D_IDX ) { xCodeContourPredTexDeltaInfo( pcCU, uiAbsPartIdx ); } |
---|
1303 | #endif |
---|
1304 | } |
---|
1305 | else |
---|
1306 | #endif |
---|
1307 | { |
---|
1308 | Int iMostProbable = pcCU->getMostProbableIntraDirLuma( uiAbsPartIdx ); |
---|
1309 | #if ADD_PLANAR_MODE |
---|
1310 | UInt planarFlag = 0; |
---|
1311 | if (uiDir == PLANAR_IDX) |
---|
1312 | { |
---|
1313 | uiDir = 2; |
---|
1314 | planarFlag = 1; |
---|
1315 | } |
---|
1316 | #endif |
---|
1317 | |
---|
1318 | if (uiDir == iMostProbable) |
---|
1319 | m_pcBinIf->encodeBin( 1, m_cCUIntraPredSCModel.get( 0, 0, 0 ) ); |
---|
1320 | else |
---|
1321 | { |
---|
1322 | m_pcBinIf->encodeBin( 0, m_cCUIntraPredSCModel.get( 0, 0, 0 ) ); |
---|
1323 | uiDir = uiDir > iMostProbable ? uiDir - 1 : uiDir; |
---|
1324 | Int iIntraIdx = pcCU->getIntraSizeIdx(uiAbsPartIdx); |
---|
1325 | if ( g_aucIntraModeBitsAng[iIntraIdx] < 6 ) |
---|
1326 | { |
---|
1327 | m_pcBinIf->encodeBin((uiDir & 0x01), m_cCUIntraPredSCModel.get(0, 0, 1)); |
---|
1328 | if ( g_aucIntraModeBitsAng[iIntraIdx] > 2 ) m_pcBinIf->encodeBin((uiDir & 0x02) >> 1, m_cCUIntraPredSCModel.get(0, 0, 1)); |
---|
1329 | if ( g_aucIntraModeBitsAng[iIntraIdx] > 3 ) m_pcBinIf->encodeBin((uiDir & 0x04) >> 2, m_cCUIntraPredSCModel.get(0, 0, 1)); |
---|
1330 | if ( g_aucIntraModeBitsAng[iIntraIdx] > 4 ) m_pcBinIf->encodeBin((uiDir & 0x08) >> 3, m_cCUIntraPredSCModel.get(0, 0, 1)); |
---|
1331 | } |
---|
1332 | else |
---|
1333 | { |
---|
1334 | if (uiDir < 31) |
---|
1335 | { // 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 |
---|
1336 | m_pcBinIf->encodeBin((uiDir & 0x01), m_cCUIntraPredSCModel.get(0, 0, 1)); |
---|
1337 | m_pcBinIf->encodeBin((uiDir & 0x02) >> 1, m_cCUIntraPredSCModel.get(0, 0, 1)); |
---|
1338 | m_pcBinIf->encodeBin((uiDir & 0x04) >> 2, m_cCUIntraPredSCModel.get(0, 0, 1)); |
---|
1339 | m_pcBinIf->encodeBin((uiDir & 0x08) >> 3, m_cCUIntraPredSCModel.get(0, 0, 1)); |
---|
1340 | m_pcBinIf->encodeBin((uiDir & 0x10) >> 4, m_cCUIntraPredSCModel.get(0, 0, 1)); |
---|
1341 | } |
---|
1342 | else |
---|
1343 | { |
---|
1344 | m_pcBinIf->encodeBin(1, m_cCUIntraPredSCModel.get(0, 0, 1)); |
---|
1345 | m_pcBinIf->encodeBin(1, m_cCUIntraPredSCModel.get(0, 0, 1)); |
---|
1346 | m_pcBinIf->encodeBin(1, m_cCUIntraPredSCModel.get(0, 0, 1)); |
---|
1347 | m_pcBinIf->encodeBin(1, m_cCUIntraPredSCModel.get(0, 0, 1)); |
---|
1348 | m_pcBinIf->encodeBin(1, m_cCUIntraPredSCModel.get(0, 0, 1)); |
---|
1349 | m_pcBinIf->encodeBin((uiDir == 32) ? 1 : 0, m_cCUIntraPredSCModel.get(0, 0, 1)); |
---|
1350 | } |
---|
1351 | } |
---|
1352 | } |
---|
1353 | |
---|
1354 | #if ADD_PLANAR_MODE |
---|
1355 | uiDir = pcCU->getLumaIntraDir( uiAbsPartIdx ); |
---|
1356 | if ( (uiDir == PLANAR_IDX) || (uiDir == 2) ) |
---|
1357 | { |
---|
1358 | m_pcBinIf->encodeBin( planarFlag, m_cPlanarFlagSCModel.get(0,0,0) ); |
---|
1359 | } |
---|
1360 | #endif |
---|
1361 | } |
---|
1362 | return; |
---|
1363 | } |
---|
1364 | #endif |
---|
1365 | Void TEncSbac::codeIntraDirChroma( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
1366 | { |
---|
1367 | UInt uiCtx = pcCU->getCtxIntraDirChroma( uiAbsPartIdx ); |
---|
1368 | UInt uiIntraDirChroma = pcCU->getChromaIntraDir ( uiAbsPartIdx ); |
---|
1369 | #if ADD_PLANAR_MODE |
---|
1370 | UInt planarFlag = 0; |
---|
1371 | if (uiIntraDirChroma == PLANAR_IDX) |
---|
1372 | { |
---|
1373 | uiIntraDirChroma = 2; |
---|
1374 | planarFlag = 1; |
---|
1375 | } |
---|
1376 | #endif |
---|
1377 | |
---|
1378 | #if CHROMA_CODEWORD |
---|
1379 | UInt uiMode = pcCU->getLumaIntraDir(uiAbsPartIdx); |
---|
1380 | #if ADD_PLANAR_MODE |
---|
1381 | if ( (uiMode == 2 ) || (uiMode == PLANAR_IDX) ) |
---|
1382 | { |
---|
1383 | uiMode = 4; |
---|
1384 | } |
---|
1385 | #endif |
---|
1386 | |
---|
1387 | #if LM_CHROMA |
---|
1388 | |
---|
1389 | Bool bUseLMFlag = pcCU->getSlice()->getSPS()->getUseLMChroma(); |
---|
1390 | |
---|
1391 | Int iMaxMode = bUseLMFlag ? 3 : 4; |
---|
1392 | |
---|
1393 | Int iMax = uiMode < iMaxMode ? 2 : 3; |
---|
1394 | |
---|
1395 | //switch codeword |
---|
1396 | if (uiIntraDirChroma == 4) |
---|
1397 | { |
---|
1398 | uiIntraDirChroma = 0; |
---|
1399 | } |
---|
1400 | else if (uiIntraDirChroma == 3 && bUseLMFlag ) |
---|
1401 | { |
---|
1402 | uiIntraDirChroma = 1; |
---|
1403 | } |
---|
1404 | else |
---|
1405 | { |
---|
1406 | if (uiIntraDirChroma < uiMode) |
---|
1407 | uiIntraDirChroma++; |
---|
1408 | |
---|
1409 | if (bUseLMFlag) |
---|
1410 | uiIntraDirChroma++; |
---|
1411 | |
---|
1412 | #if CHROMA_CODEWORD_SWITCH |
---|
1413 | uiIntraDirChroma = ChromaMapping[iMax-2][uiIntraDirChroma]; |
---|
1414 | #endif |
---|
1415 | |
---|
1416 | } |
---|
1417 | |
---|
1418 | |
---|
1419 | #else // <-- LM_CHROMA |
---|
1420 | Int iMax = uiMode < 4 ? 2 : 3; |
---|
1421 | |
---|
1422 | //switch codeword |
---|
1423 | if (uiIntraDirChroma == 4) { |
---|
1424 | uiIntraDirChroma = 0; |
---|
1425 | } |
---|
1426 | #if CHROMA_CODEWORD_SWITCH |
---|
1427 | else { |
---|
1428 | if (uiIntraDirChroma < uiMode) { |
---|
1429 | uiIntraDirChroma++; |
---|
1430 | } |
---|
1431 | uiIntraDirChroma = ChromaMapping[iMax-2][uiIntraDirChroma]; |
---|
1432 | } |
---|
1433 | #else |
---|
1434 | else if (uiIntraDirChroma < uiMode) { |
---|
1435 | uiIntraDirChroma++; |
---|
1436 | } |
---|
1437 | #endif |
---|
1438 | #endif // <-- LM_CHROMA |
---|
1439 | |
---|
1440 | if ( 0 == uiIntraDirChroma ) |
---|
1441 | { |
---|
1442 | m_pcBinIf->encodeBin( 0, m_cCUChromaPredSCModel.get( 0, 0, uiCtx ) ); |
---|
1443 | } |
---|
1444 | else |
---|
1445 | { |
---|
1446 | m_pcBinIf->encodeBin( 1, m_cCUChromaPredSCModel.get( 0, 0, uiCtx ) ); |
---|
1447 | xWriteUnaryMaxSymbol( uiIntraDirChroma - 1, m_cCUChromaPredSCModel.get( 0, 0 ) + 3, 0, iMax ); |
---|
1448 | } |
---|
1449 | #else // CHROMA_CODEWORD |
---|
1450 | if ( 0 == uiIntraDirChroma ) |
---|
1451 | { |
---|
1452 | m_pcBinIf->encodeBin( 0, m_cCUChromaPredSCModel.get( 0, 0, uiCtx ) ); |
---|
1453 | } |
---|
1454 | else |
---|
1455 | { |
---|
1456 | m_pcBinIf->encodeBin( 1, m_cCUChromaPredSCModel.get( 0, 0, uiCtx ) ); |
---|
1457 | xWriteUnaryMaxSymbol( uiIntraDirChroma - 1, m_cCUChromaPredSCModel.get( 0, 0 ) + 3, 0, 3 ); |
---|
1458 | } |
---|
1459 | #endif |
---|
1460 | |
---|
1461 | #if ADD_PLANAR_MODE |
---|
1462 | uiIntraDirChroma = pcCU->getChromaIntraDir( uiAbsPartIdx ); |
---|
1463 | #if CHROMA_CODEWORD |
---|
1464 | uiMode = pcCU->getLumaIntraDir(uiAbsPartIdx); |
---|
1465 | mapPlanartoDC( uiIntraDirChroma ); |
---|
1466 | mapPlanartoDC( uiMode ); |
---|
1467 | if ( (uiIntraDirChroma == 2) && (uiMode != 2) ) |
---|
1468 | #else |
---|
1469 | if ( (uiIntraDirChroma == PLANAR_IDX) || (uiIntraDirChroma == 2) ) |
---|
1470 | #endif |
---|
1471 | { |
---|
1472 | m_pcBinIf->encodeBin( planarFlag, m_cPlanarFlagSCModel.get(0,0,1) ); |
---|
1473 | } |
---|
1474 | #endif |
---|
1475 | return; |
---|
1476 | } |
---|
1477 | |
---|
1478 | Void TEncSbac::codeInterDir( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
1479 | { |
---|
1480 | UInt uiInterDir = pcCU->getInterDir ( uiAbsPartIdx ); |
---|
1481 | UInt uiCtx = pcCU->getCtxInterDir( uiAbsPartIdx ); |
---|
1482 | uiInterDir--; |
---|
1483 | m_pcBinIf->encodeBin( ( uiInterDir == 2 ? 1 : 0 ), m_cCUInterDirSCModel.get( 0, 0, uiCtx ) ); |
---|
1484 | |
---|
1485 | if ( pcCU->getSlice()->getNoBackPredFlag() ) |
---|
1486 | { |
---|
1487 | assert( uiInterDir != 1 ); |
---|
1488 | return; |
---|
1489 | } |
---|
1490 | |
---|
1491 | #if DCM_COMB_LIST |
---|
1492 | if ( uiInterDir < 2 && pcCU->getSlice()->getNumRefIdx(REF_PIC_LIST_C) <= 0) |
---|
1493 | #else |
---|
1494 | if ( uiInterDir < 2 ) |
---|
1495 | #endif |
---|
1496 | { |
---|
1497 | m_pcBinIf->encodeBin( uiInterDir, m_cCUInterDirSCModel.get( 0, 0, 3 ) ); |
---|
1498 | } |
---|
1499 | |
---|
1500 | return; |
---|
1501 | } |
---|
1502 | |
---|
1503 | Void TEncSbac::codeRefFrmIdx( TComDataCU* pcCU, UInt uiAbsPartIdx, RefPicList eRefList ) |
---|
1504 | { |
---|
1505 | #if DCM_COMB_LIST |
---|
1506 | if ( pcCU->getSlice()->getNumRefIdx(REF_PIC_LIST_C) > 0 && pcCU->getInterDir( uiAbsPartIdx ) != 3) |
---|
1507 | { |
---|
1508 | Int iRefFrame = pcCU->getSlice()->getRefIdxOfLC(eRefList, pcCU->getCUMvField( eRefList )->getRefIdx( uiAbsPartIdx )); |
---|
1509 | UInt uiCtx; |
---|
1510 | |
---|
1511 | uiCtx = pcCU->getCtxRefIdx( uiAbsPartIdx, RefPicList(pcCU->getSlice()->getListIdFromIdxOfLC(0)) ); |
---|
1512 | |
---|
1513 | m_pcBinIf->encodeBin( ( iRefFrame == 0 ? 0 : 1 ), m_cCURefPicSCModel.get( 0, 0, uiCtx ) ); |
---|
1514 | |
---|
1515 | if ( iRefFrame > 0 ) |
---|
1516 | { |
---|
1517 | xWriteUnaryMaxSymbol( iRefFrame - 1, &m_cCURefPicSCModel.get( 0, 0, 4 ), 1, pcCU->getSlice()->getNumRefIdx( REF_PIC_LIST_C )-2 ); |
---|
1518 | } |
---|
1519 | } |
---|
1520 | else |
---|
1521 | { |
---|
1522 | #endif |
---|
1523 | Int iRefFrame = pcCU->getCUMvField( eRefList )->getRefIdx( uiAbsPartIdx ); |
---|
1524 | |
---|
1525 | UInt uiCtx = pcCU->getCtxRefIdx( uiAbsPartIdx, eRefList ); |
---|
1526 | |
---|
1527 | m_pcBinIf->encodeBin( ( iRefFrame == 0 ? 0 : 1 ), m_cCURefPicSCModel.get( 0, 0, uiCtx ) ); |
---|
1528 | |
---|
1529 | if ( iRefFrame > 0 ) |
---|
1530 | { |
---|
1531 | xWriteUnaryMaxSymbol( iRefFrame - 1, &m_cCURefPicSCModel.get( 0, 0, 4 ), 1, pcCU->getSlice()->getNumRefIdx( eRefList )-2 ); |
---|
1532 | } |
---|
1533 | #if DCM_COMB_LIST |
---|
1534 | } |
---|
1535 | #endif |
---|
1536 | return; |
---|
1537 | } |
---|
1538 | |
---|
1539 | Void TEncSbac::codeViewIdx(Int iViewIdx) |
---|
1540 | { |
---|
1541 | assert(0) ; // not implemented yet |
---|
1542 | xWriteUnaryMaxSymbol(iViewIdx, &m_cViewIdxSCModel.get( 0, 0, 4),1, MAX_NUMBER_VIEWS ); |
---|
1543 | } |
---|
1544 | |
---|
1545 | Void TEncSbac::codeMvd( TComDataCU* pcCU, UInt uiAbsPartIdx, RefPicList eRefList ) |
---|
1546 | { |
---|
1547 | TComCUMvField* pcCUMvField = pcCU->getCUMvField( eRefList ); |
---|
1548 | Int iHor = pcCUMvField->getMvd( uiAbsPartIdx ).getHor(); |
---|
1549 | Int iVer = pcCUMvField->getMvd( uiAbsPartIdx ).getVer(); |
---|
1550 | |
---|
1551 | UInt uiAbsPartIdxL, uiAbsPartIdxA; |
---|
1552 | #if MVD_CTX |
---|
1553 | Int iHorPredL, iVerPredL; |
---|
1554 | Int iHorPredA, iVerPredA; |
---|
1555 | #else |
---|
1556 | Int iHorPred, iVerPred; |
---|
1557 | #endif |
---|
1558 | |
---|
1559 | TComDataCU* pcCUL = pcCU->getPULeft ( uiAbsPartIdxL, pcCU->getZorderIdxInCU() + uiAbsPartIdx ); |
---|
1560 | TComDataCU* pcCUA = pcCU->getPUAbove( uiAbsPartIdxA, pcCU->getZorderIdxInCU() + uiAbsPartIdx ); |
---|
1561 | |
---|
1562 | TComCUMvField* pcCUMvFieldL = ( pcCUL == NULL || pcCUL->isIntra( uiAbsPartIdxL ) ) ? NULL : pcCUL->getCUMvField( eRefList ); |
---|
1563 | TComCUMvField* pcCUMvFieldA = ( pcCUA == NULL || pcCUA->isIntra( uiAbsPartIdxA ) ) ? NULL : pcCUA->getCUMvField( eRefList ); |
---|
1564 | |
---|
1565 | #if MVD_CTX |
---|
1566 | iHorPredA = ( (pcCUMvFieldA == NULL) ? 0 : pcCUMvFieldA->getMvd( uiAbsPartIdxA ).getAbsHor() ); |
---|
1567 | iVerPredA = ( (pcCUMvFieldA == NULL) ? 0 : pcCUMvFieldA->getMvd( uiAbsPartIdxA ).getAbsVer() ); |
---|
1568 | iHorPredL = ( (pcCUMvFieldL == NULL) ? 0 : pcCUMvFieldL->getMvd( uiAbsPartIdxL ).getAbsHor() ); |
---|
1569 | iVerPredL = ( (pcCUMvFieldL == NULL) ? 0 : pcCUMvFieldL->getMvd( uiAbsPartIdxL ).getAbsVer() ); |
---|
1570 | |
---|
1571 | xWriteMvd( iHor, iHorPredL, iHorPredA, 0 ); |
---|
1572 | xWriteMvd( iVer, iVerPredL, iVerPredA, 1 ); |
---|
1573 | #else |
---|
1574 | iHorPred = ( (pcCUMvFieldL == NULL) ? 0 : pcCUMvFieldL->getMvd( uiAbsPartIdxL ).getAbsHor() ) + |
---|
1575 | ( (pcCUMvFieldA == NULL) ? 0 : pcCUMvFieldA->getMvd( uiAbsPartIdxA ).getAbsHor() ); |
---|
1576 | iVerPred = ( (pcCUMvFieldL == NULL) ? 0 : pcCUMvFieldL->getMvd( uiAbsPartIdxL ).getAbsVer() ) + |
---|
1577 | ( (pcCUMvFieldA == NULL) ? 0 : pcCUMvFieldA->getMvd( uiAbsPartIdxA ).getAbsVer() ); |
---|
1578 | |
---|
1579 | xWriteMvd( iHor, iHorPred, 0 ); |
---|
1580 | xWriteMvd( iVer, iVerPred, 1 ); |
---|
1581 | #endif |
---|
1582 | |
---|
1583 | |
---|
1584 | return; |
---|
1585 | } |
---|
1586 | |
---|
1587 | Void TEncSbac::codeDeltaQP( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
1588 | { |
---|
1589 | Int iDQp = pcCU->getQP( uiAbsPartIdx ) - pcCU->getSlice()->getSliceQp(); |
---|
1590 | |
---|
1591 | if ( iDQp == 0 ) |
---|
1592 | { |
---|
1593 | m_pcBinIf->encodeBin( 0, m_cCUDeltaQpSCModel.get( 0, 0, 0 ) ); |
---|
1594 | } |
---|
1595 | else |
---|
1596 | { |
---|
1597 | m_pcBinIf->encodeBin( 1, m_cCUDeltaQpSCModel.get( 0, 0, 0 ) ); |
---|
1598 | |
---|
1599 | UInt uiDQp = (UInt)( iDQp > 0 ? ( 2 * iDQp - 2 ) : ( -2 * iDQp - 1 ) ); |
---|
1600 | xWriteUnarySymbol( uiDQp, &m_cCUDeltaQpSCModel.get( 0, 0, 2 ), 1 ); |
---|
1601 | } |
---|
1602 | |
---|
1603 | return; |
---|
1604 | } |
---|
1605 | |
---|
1606 | Void TEncSbac::codeQtCbf( TComDataCU* pcCU, UInt uiAbsPartIdx, TextType eType, UInt uiTrDepth ) |
---|
1607 | { |
---|
1608 | UInt uiCbf = pcCU->getCbf ( uiAbsPartIdx, eType, uiTrDepth ); |
---|
1609 | UInt uiCtx = pcCU->getCtxQtCbf( uiAbsPartIdx, eType, uiTrDepth ); |
---|
1610 | m_pcBinIf->encodeBin( uiCbf , m_cCUQtCbfSCModel.get( 0, eType ? eType - 1 : eType, uiCtx ) ); |
---|
1611 | DTRACE_CABAC_V( g_nSymbolCounter++ ) |
---|
1612 | DTRACE_CABAC_T( "\tparseQtCbf()" ) |
---|
1613 | DTRACE_CABAC_T( "\tsymbol=" ) |
---|
1614 | DTRACE_CABAC_V( uiCbf ) |
---|
1615 | DTRACE_CABAC_T( "\tctx=" ) |
---|
1616 | DTRACE_CABAC_V( uiCtx ) |
---|
1617 | DTRACE_CABAC_T( "\tetype=" ) |
---|
1618 | DTRACE_CABAC_V( eType ) |
---|
1619 | DTRACE_CABAC_T( "\tuiAbsPartIdx=" ) |
---|
1620 | DTRACE_CABAC_V( uiAbsPartIdx ) |
---|
1621 | DTRACE_CABAC_T( "\n" ) |
---|
1622 | } |
---|
1623 | |
---|
1624 | UInt xCheckCoeffPlainCNoRecur( const TCoeff* pcCoef, UInt uiSize, UInt uiDepth ) |
---|
1625 | { |
---|
1626 | UInt uiNumofCoeff = 0; |
---|
1627 | UInt ui = uiSize>>uiDepth; |
---|
1628 | { |
---|
1629 | UInt x, y; |
---|
1630 | const TCoeff* pCeoff = pcCoef; |
---|
1631 | for( y=0 ; y<ui ; y++ ) |
---|
1632 | { |
---|
1633 | for( x=0 ; x<ui ; x++ ) |
---|
1634 | { |
---|
1635 | if( pCeoff[x] != 0 ) |
---|
1636 | { |
---|
1637 | uiNumofCoeff++; |
---|
1638 | } |
---|
1639 | } |
---|
1640 | pCeoff += uiSize; |
---|
1641 | } |
---|
1642 | } |
---|
1643 | return uiNumofCoeff; |
---|
1644 | } |
---|
1645 | |
---|
1646 | Void TEncSbac::codeQtRootCbf( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
1647 | { |
---|
1648 | UInt uiCbf = pcCU->getQtRootCbf( uiAbsPartIdx ); |
---|
1649 | UInt uiCtx = pcCU->getCtxQtRootCbf( uiAbsPartIdx ); |
---|
1650 | m_pcBinIf->encodeBin( uiCbf , m_cCUQtRootCbfSCModel.get( 0, 0, uiCtx ) ); |
---|
1651 | DTRACE_CABAC_V( g_nSymbolCounter++ ) |
---|
1652 | DTRACE_CABAC_T( "\tparseQtRootCbf()" ) |
---|
1653 | DTRACE_CABAC_T( "\tsymbol=" ) |
---|
1654 | DTRACE_CABAC_V( uiCbf ) |
---|
1655 | DTRACE_CABAC_T( "\tctx=" ) |
---|
1656 | DTRACE_CABAC_V( uiCtx ) |
---|
1657 | DTRACE_CABAC_T( "\tuiAbsPartIdx=" ) |
---|
1658 | DTRACE_CABAC_V( uiAbsPartIdx ) |
---|
1659 | DTRACE_CABAC_T( "\n" ) |
---|
1660 | } |
---|
1661 | |
---|
1662 | Void TEncSbac::xCheckCoeff( TCoeff* pcCoef, UInt uiSize, UInt uiDepth, UInt& uiNumofCoeff, UInt& uiPart ) |
---|
1663 | { |
---|
1664 | UInt ui = uiSize>>uiDepth; |
---|
1665 | if( uiPart == 0 ) |
---|
1666 | { |
---|
1667 | if( ui <= 4 ) |
---|
1668 | { |
---|
1669 | UInt x, y; |
---|
1670 | TCoeff* pCeoff = pcCoef; |
---|
1671 | for( y=0 ; y<ui ; y++ ) |
---|
1672 | { |
---|
1673 | for( x=0 ; x<ui ; x++ ) |
---|
1674 | { |
---|
1675 | if( pCeoff[x] != 0 ) |
---|
1676 | { |
---|
1677 | uiNumofCoeff++; |
---|
1678 | } |
---|
1679 | } |
---|
1680 | pCeoff += uiSize; |
---|
1681 | } |
---|
1682 | } |
---|
1683 | else |
---|
1684 | { |
---|
1685 | xCheckCoeff( pcCoef, uiSize, uiDepth+1, uiNumofCoeff, uiPart ); uiPart++; //1st Part |
---|
1686 | xCheckCoeff( pcCoef + (ui>>1), uiSize, uiDepth+1, uiNumofCoeff, uiPart ); uiPart++; //2nd Part |
---|
1687 | xCheckCoeff( pcCoef + (ui>>1)*uiSize, uiSize, uiDepth+1, uiNumofCoeff, uiPart ); uiPart++; //3rd Part |
---|
1688 | xCheckCoeff( pcCoef + (ui>>1)*uiSize + (ui>>1), uiSize, uiDepth+1, uiNumofCoeff, uiPart ); //4th Part |
---|
1689 | } |
---|
1690 | } |
---|
1691 | else |
---|
1692 | { |
---|
1693 | UInt x, y; |
---|
1694 | TCoeff* pCeoff = pcCoef; |
---|
1695 | for( y=0 ; y<ui ; y++ ) |
---|
1696 | { |
---|
1697 | for( x=0 ; x<ui ; x++ ) |
---|
1698 | { |
---|
1699 | if( pCeoff[x] != 0 ) |
---|
1700 | { |
---|
1701 | uiNumofCoeff++; |
---|
1702 | } |
---|
1703 | } |
---|
1704 | pCeoff += uiSize; |
---|
1705 | } |
---|
1706 | } |
---|
1707 | } |
---|
1708 | |
---|
1709 | UInt xCheckCoeffPlainCNoRecur( const TCoeff* pcCoef, UInt uiSize, UInt uiDepth ); |
---|
1710 | |
---|
1711 | #if PCP_SIGMAP_SIMPLE_LAST |
---|
1712 | /** Encode (X,Y) position of the last significant coefficient |
---|
1713 | * \param uiPosX X component of last coefficient |
---|
1714 | * \param uiPosY Y component of last coefficient |
---|
1715 | * \param uiWidth block width |
---|
1716 | * \param eTType plane type / luminance or chrominance |
---|
1717 | * \param uiCTXIdx block size context |
---|
1718 | * \param uiScanIdx scan type (zig-zag, hor, ver) |
---|
1719 | * \returns Void |
---|
1720 | * This method encodes the X and Y component within a block of the last significant coefficient. |
---|
1721 | */ |
---|
1722 | __inline Void TEncSbac::codeLastSignificantXY( UInt uiPosX, UInt uiPosY, const UInt uiWidth, const TextType eTType, const UInt uiCTXIdx, const UInt uiScanIdx ) |
---|
1723 | { |
---|
1724 | UInt uiCtxLast; |
---|
1725 | const UInt uiCtxOffset = g_uiCtxXYOffset[uiCTXIdx]; |
---|
1726 | |
---|
1727 | if( uiScanIdx == SCAN_VER ) |
---|
1728 | { |
---|
1729 | swap( uiPosX, uiPosY ); |
---|
1730 | } |
---|
1731 | |
---|
1732 | for(uiCtxLast=0; uiCtxLast<uiPosX; uiCtxLast++) |
---|
1733 | { |
---|
1734 | m_pcBinIf->encodeBin( 0, m_cCuCtxLastX.get( 0, eTType, uiCtxOffset + g_uiCtxXY[uiCtxLast] ) ); |
---|
1735 | } |
---|
1736 | if(uiPosX < uiWidth - 1) |
---|
1737 | { |
---|
1738 | m_pcBinIf->encodeBin( 1, m_cCuCtxLastX.get( 0, eTType, uiCtxOffset + g_uiCtxXY[uiCtxLast] ) ); |
---|
1739 | } |
---|
1740 | |
---|
1741 | for(uiCtxLast=0; uiCtxLast<uiPosY; uiCtxLast++) |
---|
1742 | { |
---|
1743 | m_pcBinIf->encodeBin( 0, m_cCuCtxLastY.get( 0, eTType, uiCtxOffset + g_uiCtxXY[uiCtxLast] ) ); |
---|
1744 | } |
---|
1745 | if(uiPosY < uiWidth - 1) |
---|
1746 | { |
---|
1747 | m_pcBinIf->encodeBin( 1, m_cCuCtxLastY.get( 0, eTType, uiCtxOffset + g_uiCtxXY[uiCtxLast] ) ); |
---|
1748 | } |
---|
1749 | } |
---|
1750 | #endif |
---|
1751 | |
---|
1752 | Void TEncSbac::codeCoeffNxN( TComDataCU* pcCU, TCoeff* pcCoef, UInt uiAbsPartIdx, UInt uiWidth, UInt uiHeight, UInt uiDepth, TextType eTType, Bool bRD ) |
---|
1753 | { |
---|
1754 | DTRACE_CABAC_V( g_nSymbolCounter++ ) |
---|
1755 | DTRACE_CABAC_T( "\tparseCoeffNxN()\teType=" ) |
---|
1756 | DTRACE_CABAC_V( eTType ) |
---|
1757 | DTRACE_CABAC_T( "\twidth=" ) |
---|
1758 | DTRACE_CABAC_V( uiWidth ) |
---|
1759 | DTRACE_CABAC_T( "\theight=" ) |
---|
1760 | DTRACE_CABAC_V( uiHeight ) |
---|
1761 | DTRACE_CABAC_T( "\tdepth=" ) |
---|
1762 | DTRACE_CABAC_V( uiDepth ) |
---|
1763 | DTRACE_CABAC_T( "\tabspartidx=" ) |
---|
1764 | DTRACE_CABAC_V( uiAbsPartIdx ) |
---|
1765 | DTRACE_CABAC_T( "\ttoCU-X=" ) |
---|
1766 | DTRACE_CABAC_V( pcCU->getCUPelX() ) |
---|
1767 | DTRACE_CABAC_T( "\ttoCU-Y=" ) |
---|
1768 | DTRACE_CABAC_V( pcCU->getCUPelY() ) |
---|
1769 | DTRACE_CABAC_T( "\tCU-addr=" ) |
---|
1770 | DTRACE_CABAC_V( pcCU->getAddr() ) |
---|
1771 | DTRACE_CABAC_T( "\tinCU-X=" ) |
---|
1772 | DTRACE_CABAC_V( g_auiRasterToPelX[ g_auiZscanToRaster[uiAbsPartIdx] ] ) |
---|
1773 | DTRACE_CABAC_T( "\tinCU-Y=" ) |
---|
1774 | DTRACE_CABAC_V( g_auiRasterToPelY[ g_auiZscanToRaster[uiAbsPartIdx] ] ) |
---|
1775 | DTRACE_CABAC_T( "\tpredmode=" ) |
---|
1776 | DTRACE_CABAC_V( pcCU->getPredictionMode( uiAbsPartIdx ) ) |
---|
1777 | DTRACE_CABAC_T( "\n" ) |
---|
1778 | if( uiWidth > m_pcSlice->getSPS()->getMaxTrSize() ) |
---|
1779 | { |
---|
1780 | uiWidth = m_pcSlice->getSPS()->getMaxTrSize(); |
---|
1781 | uiHeight = m_pcSlice->getSPS()->getMaxTrSize(); |
---|
1782 | } |
---|
1783 | |
---|
1784 | UInt uiNumSig = 0; |
---|
1785 | UInt uiCTXIdx = 0; |
---|
1786 | |
---|
1787 | switch( uiWidth ) |
---|
1788 | { |
---|
1789 | case 2: uiCTXIdx = 6; break; |
---|
1790 | case 4: uiCTXIdx = 5; break; |
---|
1791 | case 8: uiCTXIdx = 4; break; |
---|
1792 | case 16: uiCTXIdx = 3; break; |
---|
1793 | case 32: uiCTXIdx = 2; break; |
---|
1794 | case 64: uiCTXIdx = 1; break; |
---|
1795 | default: uiCTXIdx = 0; break; |
---|
1796 | } |
---|
1797 | |
---|
1798 | // compute number of significant coefficients |
---|
1799 | UInt uiPart = 0; |
---|
1800 | xCheckCoeff(pcCoef, uiWidth, 0, uiNumSig, uiPart ); |
---|
1801 | |
---|
1802 | if ( bRD ) |
---|
1803 | { |
---|
1804 | UInt uiTempDepth = uiDepth - pcCU->getDepth( uiAbsPartIdx ); |
---|
1805 | pcCU->setCbfSubParts( ( uiNumSig ? 1 : 0 ) << uiTempDepth, eTType, uiAbsPartIdx, uiDepth ); |
---|
1806 | } |
---|
1807 | |
---|
1808 | if ( uiNumSig == 0 ) |
---|
1809 | return; |
---|
1810 | |
---|
1811 | eTType = eTType == TEXT_LUMA ? TEXT_LUMA : ( eTType == TEXT_NONE ? TEXT_NONE : TEXT_CHROMA ); |
---|
1812 | |
---|
1813 | //----- encode significance map ----- |
---|
1814 | const UInt uiLog2BlockSize = g_aucConvertToBit[ uiWidth ] + 2; |
---|
1815 | const UInt uiMaxNumCoeff = 1 << ( uiLog2BlockSize << 1 ); |
---|
1816 | #if !PCP_SIGMAP_SIMPLE_LAST |
---|
1817 | const UInt uiMaxNumCoeffM1 = uiMaxNumCoeff - 1; |
---|
1818 | #endif |
---|
1819 | const UInt uiNum4x4Blk = max<UInt>( 1, uiMaxNumCoeff >> 4 ); |
---|
1820 | #if QC_MDCS |
---|
1821 | const UInt uiScanIdx = pcCU->getCoefScanIdx(uiAbsPartIdx, uiWidth, eTType==TEXT_LUMA, pcCU->isIntra(uiAbsPartIdx)); |
---|
1822 | #endif //QC_MDCS |
---|
1823 | |
---|
1824 | #if PCP_SIGMAP_SIMPLE_LAST |
---|
1825 | //===== code last coeff ===== |
---|
1826 | UInt uiScanPosLast = 0, uiPosLastX, uiPosLastY; |
---|
1827 | for( UInt uiScanPos = 0; uiScanPos < uiMaxNumCoeff; uiScanPos++ ) |
---|
1828 | { |
---|
1829 | #if QC_MDCS |
---|
1830 | UInt uiBlkPos = g_auiSigLastScan[uiScanIdx][uiLog2BlockSize-1][uiScanPos]; |
---|
1831 | #else |
---|
1832 | UInt uiBlkPos = g_auiFrameScanXY[ uiLog2BlockSize-1 ][ uiScanPos ]; |
---|
1833 | #endif //QC_MDCS |
---|
1834 | uiPosLastY = uiBlkPos >> uiLog2BlockSize; |
---|
1835 | uiPosLastX = uiBlkPos - ( uiPosLastY << uiLog2BlockSize ); |
---|
1836 | |
---|
1837 | if( pcCoef[ uiBlkPos ] != 0 ) |
---|
1838 | { |
---|
1839 | uiNumSig--; |
---|
1840 | if( uiNumSig == 0 ) |
---|
1841 | { |
---|
1842 | codeLastSignificantXY(uiPosLastX, uiPosLastY, uiWidth, eTType, uiCTXIdx, uiScanIdx); |
---|
1843 | uiScanPosLast = uiScanPos; |
---|
1844 | break; |
---|
1845 | } |
---|
1846 | } |
---|
1847 | } |
---|
1848 | |
---|
1849 | //===== code significance flag ===== |
---|
1850 | { |
---|
1851 | for( UInt uiScanPos = 0; uiScanPos < uiScanPosLast; uiScanPos++ ) |
---|
1852 | { |
---|
1853 | #if QC_MDCS |
---|
1854 | UInt uiBlkPos = g_auiSigLastScan[uiScanIdx][uiLog2BlockSize-1][uiScanPos]; |
---|
1855 | #else |
---|
1856 | UInt uiBlkPos = g_auiFrameScanXY[ uiLog2BlockSize-1 ][ uiScanPos ]; |
---|
1857 | #endif //QC_MDCS |
---|
1858 | UInt uiPosY = uiBlkPos >> uiLog2BlockSize; |
---|
1859 | UInt uiPosX = uiBlkPos - ( uiPosY << uiLog2BlockSize ); |
---|
1860 | UInt uiSig = pcCoef[ uiBlkPos ] != 0 ? 1 : 0; |
---|
1861 | UInt uiCtxSig = TComTrQuant::getSigCtxInc( pcCoef, uiPosX, uiPosY, uiLog2BlockSize, uiWidth ); |
---|
1862 | #if SIMPLE_CONTEXT_SIG |
---|
1863 | if( uiCtxSig < 4 || eTType) |
---|
1864 | { |
---|
1865 | m_pcBinIf->encodeBin( uiSig, m_cCUSigSCModel.get( uiCTXIdx-2, eTType, uiCtxSig ) ); |
---|
1866 | } |
---|
1867 | else |
---|
1868 | { |
---|
1869 | m_pcBinIf->encodeBin( uiSig, m_cCUSigSCModel.get( uiCTXIdx-2 ? uiCTXIdx-2 : 1, eTType, uiCtxSig ) ); |
---|
1870 | } |
---|
1871 | #else |
---|
1872 | m_pcBinIf->encodeBin( uiSig, m_cCUSigSCModel.get( uiCTXIdx, eTType, uiCtxSig ) ); |
---|
1873 | #endif |
---|
1874 | } |
---|
1875 | } |
---|
1876 | |
---|
1877 | #else |
---|
1878 | for( UInt uiScanPos = 0; uiScanPos < uiMaxNumCoeffM1; uiScanPos++ ) |
---|
1879 | { |
---|
1880 | #if QC_MDCS |
---|
1881 | UInt uiBlkPos = g_auiSigLastScan[uiScanIdx][uiLog2BlockSize-1][uiScanPos]; |
---|
1882 | #else |
---|
1883 | UInt uiBlkPos = g_auiFrameScanXY[ uiLog2BlockSize-1 ][ uiScanPos ]; |
---|
1884 | #endif //QC_MDCS |
---|
1885 | UInt uiPosY = uiBlkPos >> uiLog2BlockSize; |
---|
1886 | UInt uiPosX = uiBlkPos - ( uiPosY << uiLog2BlockSize ); |
---|
1887 | |
---|
1888 | //===== code significance flag ===== |
---|
1889 | UInt uiSig = pcCoef[ uiBlkPos ] != 0 ? 1 : 0; |
---|
1890 | UInt uiCtxSig = TComTrQuant::getSigCtxInc( pcCoef, uiPosX, uiPosY, uiLog2BlockSize, uiWidth ); |
---|
1891 | #if SIMPLE_CONTEXT_SIG |
---|
1892 | if( uiCtxSig < 4 || eTType) |
---|
1893 | { |
---|
1894 | m_pcBinIf->encodeBin( uiSig, m_cCUSigSCModel.get( uiCTXIdx-2, eTType, uiCtxSig ) ); |
---|
1895 | } |
---|
1896 | else |
---|
1897 | { |
---|
1898 | m_pcBinIf->encodeBin( uiSig, m_cCUSigSCModel.get( uiCTXIdx-2 ? uiCTXIdx-2 : 1, eTType, uiCtxSig ) ); |
---|
1899 | } |
---|
1900 | #else |
---|
1901 | m_pcBinIf->encodeBin( uiSig, m_cCUSigSCModel.get( uiCTXIdx, eTType, uiCtxSig ) ); |
---|
1902 | #endif |
---|
1903 | if( uiSig ) |
---|
1904 | { |
---|
1905 | uiNumSig--; |
---|
1906 | |
---|
1907 | //===== code last flag ===== |
---|
1908 | UInt uiLast = ( uiNumSig == 0 ) ? 1 : 0; |
---|
1909 | UInt uiCtxLast = TComTrQuant::getLastCtxInc( uiPosX, uiPosY, uiLog2BlockSize ); |
---|
1910 | m_pcBinIf->encodeBin( uiLast, m_cCULastSCModel.get( uiCTXIdx, eTType, uiCtxLast ) ); |
---|
1911 | |
---|
1912 | if( uiLast ) |
---|
1913 | { |
---|
1914 | break; |
---|
1915 | } |
---|
1916 | } |
---|
1917 | } |
---|
1918 | #endif |
---|
1919 | /* |
---|
1920 | * Sign and bin0 PCP (Section 3.2 and 3.3 of JCTVC-B088) |
---|
1921 | */ |
---|
1922 | Int c1, c2; |
---|
1923 | UInt uiSign; |
---|
1924 | UInt uiAbs; |
---|
1925 | #if E253 |
---|
1926 | UInt uiGoRiceParam = 0; |
---|
1927 | #endif |
---|
1928 | |
---|
1929 | if( uiNum4x4Blk > 1 ) |
---|
1930 | { |
---|
1931 | Bool b1stBlk = true; |
---|
1932 | UInt uiNumOne = 0; |
---|
1933 | |
---|
1934 | for( UInt uiSubBlk = 0; uiSubBlk < uiNum4x4Blk; uiSubBlk++ ) |
---|
1935 | { |
---|
1936 | UInt uiCtxSet = 0; |
---|
1937 | UInt uiSubNumSig = 0; |
---|
1938 | UInt uiSubPosX = 0; |
---|
1939 | UInt uiSubPosY = 0; |
---|
1940 | #if E253 |
---|
1941 | uiGoRiceParam = 0; |
---|
1942 | #endif |
---|
1943 | |
---|
1944 | uiSubPosX = g_auiFrameScanX[ g_aucConvertToBit[ uiWidth ] - 1 ][ uiSubBlk ] << 2; |
---|
1945 | uiSubPosY = g_auiFrameScanY[ g_aucConvertToBit[ uiWidth ] - 1 ][ uiSubBlk ] << 2; |
---|
1946 | |
---|
1947 | TCoeff* piCurr = &pcCoef[ uiSubPosX + uiSubPosY * uiWidth ]; |
---|
1948 | |
---|
1949 | for( UInt uiY = 0; uiY < 4; uiY++ ) |
---|
1950 | { |
---|
1951 | for( UInt uiX = 0; uiX < 4; uiX++ ) |
---|
1952 | { |
---|
1953 | if( piCurr[ uiX ] ) |
---|
1954 | { |
---|
1955 | uiSubNumSig++; |
---|
1956 | } |
---|
1957 | } |
---|
1958 | piCurr += uiWidth; |
---|
1959 | } |
---|
1960 | |
---|
1961 | if( uiSubNumSig > 0 ) |
---|
1962 | { |
---|
1963 | c1 = 1; |
---|
1964 | c2 = 0; |
---|
1965 | |
---|
1966 | if( b1stBlk ) |
---|
1967 | { |
---|
1968 | b1stBlk = false; |
---|
1969 | uiCtxSet = 5; |
---|
1970 | } |
---|
1971 | else |
---|
1972 | { |
---|
1973 | uiCtxSet = ( uiNumOne >> 2 ) + 1; |
---|
1974 | uiNumOne = 0; |
---|
1975 | } |
---|
1976 | |
---|
1977 | for( UInt uiScanPos = 0; uiScanPos < 16; uiScanPos++ ) |
---|
1978 | { |
---|
1979 | UInt uiBlkPos = g_auiFrameScanXY[ 1 ][ 15 - uiScanPos ]; |
---|
1980 | UInt uiPosY = uiBlkPos >> 2; |
---|
1981 | UInt uiPosX = uiBlkPos - ( uiPosY << 2 ); |
---|
1982 | UInt uiIndex = ( ( uiSubPosY + uiPosY ) << uiLog2BlockSize ) + uiSubPosX + uiPosX; |
---|
1983 | |
---|
1984 | if( pcCoef[ uiIndex ] ) |
---|
1985 | { |
---|
1986 | if( pcCoef[ uiIndex ] > 0) { uiAbs = static_cast<UInt>( pcCoef[ uiIndex ]); uiSign = 0; } |
---|
1987 | else { uiAbs = static_cast<UInt>(-pcCoef[ uiIndex ]); uiSign = 1; } |
---|
1988 | |
---|
1989 | UInt uiCtx = min<UInt>(c1, 4); |
---|
1990 | UInt uiSymbol = uiAbs > 1 ? 1 : 0; |
---|
1991 | m_pcBinIf->encodeBin( uiSymbol, m_cCUOneSCModel.get( 0, eTType, ( uiCtxSet << 2 ) + uiCtxSet + uiCtx ) ); |
---|
1992 | |
---|
1993 | if( uiSymbol ) |
---|
1994 | { |
---|
1995 | c1 = 0; |
---|
1996 | } |
---|
1997 | else if( c1 ) |
---|
1998 | { |
---|
1999 | c1++; |
---|
2000 | } |
---|
2001 | } |
---|
2002 | } |
---|
2003 | |
---|
2004 | for( UInt uiScanPos = 0; uiScanPos < 16; uiScanPos++ ) |
---|
2005 | { |
---|
2006 | UInt uiBlkPos = g_auiFrameScanXY[ 1 ][ 15 - uiScanPos ]; |
---|
2007 | UInt uiPosY = uiBlkPos >> 2; |
---|
2008 | UInt uiPosX = uiBlkPos - ( uiPosY << 2 ); |
---|
2009 | UInt uiIndex = ( ( uiSubPosY + uiPosY ) << uiLog2BlockSize ) + uiSubPosX + uiPosX; |
---|
2010 | |
---|
2011 | if( pcCoef[ uiIndex ] ) |
---|
2012 | { |
---|
2013 | if( pcCoef[ uiIndex ] > 0) { uiAbs = static_cast<UInt>( pcCoef[ uiIndex ]); uiSign = 0; } |
---|
2014 | else { uiAbs = static_cast<UInt>(-pcCoef[ uiIndex ]); uiSign = 1; } |
---|
2015 | |
---|
2016 | UInt uiSymbol = uiAbs > 1 ? 1 : 0; |
---|
2017 | |
---|
2018 | if( uiSymbol ) |
---|
2019 | { |
---|
2020 | UInt uiCtx = min<UInt>(c2, 4); |
---|
2021 | uiAbs -= 2; |
---|
2022 | c2++; |
---|
2023 | uiNumOne++; |
---|
2024 | #if E253 |
---|
2025 | uiSymbol = uiAbs > 0 ? 1 : 0; |
---|
2026 | |
---|
2027 | m_pcBinIf->encodeBin( uiSymbol, m_cCUAbsSCModel.get( 0, eTType, ( uiCtxSet << 2 ) + uiCtxSet + uiCtx ) ); |
---|
2028 | |
---|
2029 | if( uiSymbol ) |
---|
2030 | { |
---|
2031 | uiAbs -= 1; |
---|
2032 | xWriteGoRiceExGolomb( uiAbs, uiGoRiceParam ); |
---|
2033 | } |
---|
2034 | #else |
---|
2035 | xWriteExGolombLevel( uiAbs, m_cCUAbsSCModel.get( 0, eTType, ( uiCtxSet << 2 ) + uiCtxSet + uiCtx ) ); |
---|
2036 | #endif |
---|
2037 | } |
---|
2038 | } |
---|
2039 | } |
---|
2040 | |
---|
2041 | for( UInt uiScanPos = 0; uiScanPos < 16; uiScanPos++ ) |
---|
2042 | { |
---|
2043 | UInt uiBlkPos = g_auiFrameScanXY[ 1 ][ 15 - uiScanPos ]; |
---|
2044 | UInt uiPosY = uiBlkPos >> 2; |
---|
2045 | UInt uiPosX = uiBlkPos - ( uiPosY << 2 ); |
---|
2046 | UInt uiIndex = ( ( uiSubPosY + uiPosY ) << uiLog2BlockSize ) + uiSubPosX + uiPosX; |
---|
2047 | |
---|
2048 | if( pcCoef[ uiIndex ] ) |
---|
2049 | { |
---|
2050 | if( pcCoef[ uiIndex ] > 0) { uiAbs = static_cast<UInt>( pcCoef[ uiIndex ]); uiSign = 0; } |
---|
2051 | else { uiAbs = static_cast<UInt>(-pcCoef[ uiIndex ]); uiSign = 1; } |
---|
2052 | m_pcBinIf->encodeBinEP( uiSign ); |
---|
2053 | } |
---|
2054 | } |
---|
2055 | |
---|
2056 | } |
---|
2057 | } |
---|
2058 | } |
---|
2059 | else |
---|
2060 | { |
---|
2061 | c1 = 1; |
---|
2062 | c2 = 0; |
---|
2063 | |
---|
2064 | for( UInt uiScanPos = 0; uiScanPos < 16; uiScanPos++ ) |
---|
2065 | { |
---|
2066 | UInt uiIndex = g_auiFrameScanXY[ 1 ][ 15 - uiScanPos ]; |
---|
2067 | |
---|
2068 | if( pcCoef[ uiIndex ] ) |
---|
2069 | { |
---|
2070 | if( pcCoef[ uiIndex ] > 0) { uiAbs = static_cast<UInt>( pcCoef[ uiIndex ]); uiSign = 0; } |
---|
2071 | else { uiAbs = static_cast<UInt>(-pcCoef[ uiIndex ]); uiSign = 1; } |
---|
2072 | |
---|
2073 | UInt uiCtx = min<UInt>(c1, 4); |
---|
2074 | UInt uiSymbol = uiAbs > 1 ? 1 : 0; |
---|
2075 | m_pcBinIf->encodeBin( uiSymbol, m_cCUOneSCModel.get( 0, eTType, uiCtx ) ); |
---|
2076 | |
---|
2077 | if( uiSymbol ) |
---|
2078 | { |
---|
2079 | c1 = 0; |
---|
2080 | } |
---|
2081 | else if( c1 ) |
---|
2082 | { |
---|
2083 | c1++; |
---|
2084 | } |
---|
2085 | } |
---|
2086 | } |
---|
2087 | |
---|
2088 | for( UInt uiScanPos = 0; uiScanPos < 16; uiScanPos++ ) |
---|
2089 | { |
---|
2090 | UInt uiIndex = g_auiFrameScanXY[ 1 ][ 15 - uiScanPos ]; |
---|
2091 | |
---|
2092 | if( pcCoef[ uiIndex ] ) |
---|
2093 | { |
---|
2094 | if( pcCoef[ uiIndex ] > 0) { uiAbs = static_cast<UInt>( pcCoef[ uiIndex ]); uiSign = 0; } |
---|
2095 | else { uiAbs = static_cast<UInt>(-pcCoef[ uiIndex ]); uiSign = 1; } |
---|
2096 | |
---|
2097 | UInt uiSymbol = uiAbs > 1 ? 1 : 0; |
---|
2098 | |
---|
2099 | if( uiSymbol ) |
---|
2100 | { |
---|
2101 | UInt uiCtx = min<UInt>(c2, 4); |
---|
2102 | uiAbs -= 2; |
---|
2103 | c2++; |
---|
2104 | #if E253 |
---|
2105 | uiSymbol = uiAbs > 0 ? 1 : 0; |
---|
2106 | |
---|
2107 | m_pcBinIf->encodeBin( uiSymbol, m_cCUAbsSCModel.get( 0, eTType, uiCtx ) ); |
---|
2108 | |
---|
2109 | if( uiSymbol ) |
---|
2110 | { |
---|
2111 | uiAbs -= 1; |
---|
2112 | xWriteGoRiceExGolomb( uiAbs, uiGoRiceParam ); |
---|
2113 | } |
---|
2114 | #else |
---|
2115 | xWriteExGolombLevel( uiAbs, m_cCUAbsSCModel.get( 0, eTType, uiCtx ) ); |
---|
2116 | #endif |
---|
2117 | } |
---|
2118 | } |
---|
2119 | } |
---|
2120 | |
---|
2121 | for( UInt uiScanPos = 0; uiScanPos < 16; uiScanPos++ ) |
---|
2122 | { |
---|
2123 | UInt uiIndex = g_auiFrameScanXY[ 1 ][ 15 - uiScanPos ]; |
---|
2124 | |
---|
2125 | if( pcCoef[ uiIndex ] ) |
---|
2126 | { |
---|
2127 | if( pcCoef[ uiIndex ] > 0) { uiAbs = static_cast<UInt>( pcCoef[ uiIndex ]); uiSign = 0; } |
---|
2128 | else { uiAbs = static_cast<UInt>(-pcCoef[ uiIndex ]); uiSign = 1; } |
---|
2129 | |
---|
2130 | m_pcBinIf->encodeBinEP( uiSign ); |
---|
2131 | } |
---|
2132 | } |
---|
2133 | } |
---|
2134 | return; |
---|
2135 | } |
---|
2136 | |
---|
2137 | #if MVD_CTX |
---|
2138 | /** Encode a motion vector difference |
---|
2139 | * \param iMvd motion vector difference |
---|
2140 | * \param uiAbsSumL motion vector difference of left PU |
---|
2141 | * \param uiAbsSumA motion vector difference of above PU |
---|
2142 | * \param uiCtx index for context set based on vertical or horizontal component |
---|
2143 | */ |
---|
2144 | Void TEncSbac::xWriteMvd( Int iMvd, UInt uiAbsSumL, UInt uiAbsSumA, UInt uiCtx ) |
---|
2145 | #else |
---|
2146 | Void TEncSbac::xWriteMvd( Int iMvd, UInt uiAbsSum, UInt uiCtx ) |
---|
2147 | #endif |
---|
2148 | { |
---|
2149 | UInt uiLocalCtx = 0; |
---|
2150 | #if MVD_CTX |
---|
2151 | uiLocalCtx += (uiAbsSumA>16) ? 1 : 0; |
---|
2152 | uiLocalCtx += (uiAbsSumL>16) ? 1 : 0; |
---|
2153 | #else |
---|
2154 | if ( uiAbsSum >= 3 ) |
---|
2155 | { |
---|
2156 | uiLocalCtx += ( uiAbsSum > 32 ) ? 2 : 1; |
---|
2157 | } |
---|
2158 | #endif |
---|
2159 | |
---|
2160 | UInt uiSymbol = ( 0 == iMvd ) ? 0 : 1; |
---|
2161 | m_pcBinIf->encodeBin( uiSymbol, m_cCUMvdSCModel.get( 0, uiCtx, uiLocalCtx ) ); |
---|
2162 | if ( 0 == uiSymbol ) |
---|
2163 | { |
---|
2164 | return; |
---|
2165 | } |
---|
2166 | |
---|
2167 | UInt uiSign = 0; |
---|
2168 | if ( 0 > iMvd ) |
---|
2169 | { |
---|
2170 | uiSign = 1; |
---|
2171 | iMvd = -iMvd; |
---|
2172 | } |
---|
2173 | xWriteExGolombMvd( iMvd-1, &m_cCUMvdSCModel.get( 0, uiCtx, 3 ), 3 ); |
---|
2174 | m_pcBinIf->encodeBinEP( uiSign ); |
---|
2175 | |
---|
2176 | return; |
---|
2177 | } |
---|
2178 | |
---|
2179 | Void TEncSbac::xWriteExGolombMvd( UInt uiSymbol, ContextModel* pcSCModel, UInt uiMaxBin ) |
---|
2180 | { |
---|
2181 | if ( ! uiSymbol ) |
---|
2182 | { |
---|
2183 | m_pcBinIf->encodeBin( 0, *pcSCModel ); |
---|
2184 | return; |
---|
2185 | } |
---|
2186 | |
---|
2187 | m_pcBinIf->encodeBin( 1, *pcSCModel ); |
---|
2188 | |
---|
2189 | Bool bNoExGo = ( uiSymbol < 8 ); |
---|
2190 | UInt uiCount = 1; |
---|
2191 | pcSCModel++; |
---|
2192 | |
---|
2193 | while ( --uiSymbol && ++uiCount <= 8 ) |
---|
2194 | { |
---|
2195 | m_pcBinIf->encodeBin( 1, *pcSCModel ); |
---|
2196 | if ( uiCount == 2 ) |
---|
2197 | { |
---|
2198 | pcSCModel++; |
---|
2199 | } |
---|
2200 | if ( uiCount == uiMaxBin ) |
---|
2201 | { |
---|
2202 | pcSCModel++; |
---|
2203 | } |
---|
2204 | } |
---|
2205 | |
---|
2206 | if ( bNoExGo ) |
---|
2207 | { |
---|
2208 | m_pcBinIf->encodeBin( 0, *pcSCModel ); |
---|
2209 | } |
---|
2210 | else |
---|
2211 | { |
---|
2212 | xWriteEpExGolomb( uiSymbol, 3 ); |
---|
2213 | } |
---|
2214 | |
---|
2215 | return; |
---|
2216 | } |
---|
2217 | |
---|
2218 | Void TEncSbac::codeAlfFlag ( UInt uiCode ) |
---|
2219 | { |
---|
2220 | UInt uiSymbol = ( ( uiCode == 0 ) ? 0 : 1 ); |
---|
2221 | m_pcBinIf->encodeBin( uiSymbol, m_cALFFlagSCModel.get( 0, 0, 0 ) ); |
---|
2222 | } |
---|
2223 | |
---|
2224 | #if TSB_ALF_HEADER |
---|
2225 | Void TEncSbac::codeAlfFlagNum( UInt uiCode, UInt minValue ) |
---|
2226 | { |
---|
2227 | UInt uiLength = 0; |
---|
2228 | UInt maxValue = (minValue << (this->getMaxAlfCtrlDepth()*2)); |
---|
2229 | assert((uiCode>=minValue)&&(uiCode<=maxValue)); |
---|
2230 | UInt temp = maxValue - minValue; |
---|
2231 | for(UInt i=0; i<32; i++) |
---|
2232 | { |
---|
2233 | if(temp&0x1) |
---|
2234 | { |
---|
2235 | uiLength = i+1; |
---|
2236 | } |
---|
2237 | temp = (temp >> 1); |
---|
2238 | } |
---|
2239 | UInt uiSymbol = uiCode - minValue; |
---|
2240 | if(uiLength) |
---|
2241 | { |
---|
2242 | while( uiLength-- ) |
---|
2243 | { |
---|
2244 | m_pcBinIf->encodeBinEP( (uiSymbol>>uiLength) & 0x1 ); |
---|
2245 | } |
---|
2246 | } |
---|
2247 | } |
---|
2248 | |
---|
2249 | Void TEncSbac::codeAlfCtrlFlag( UInt uiSymbol ) |
---|
2250 | { |
---|
2251 | m_pcBinIf->encodeBin( uiSymbol, m_cCUAlfCtrlFlagSCModel.get( 0, 0, 0) ); |
---|
2252 | } |
---|
2253 | #endif |
---|
2254 | |
---|
2255 | Void TEncSbac::codeAlfUvlc ( UInt uiCode ) |
---|
2256 | { |
---|
2257 | Int i; |
---|
2258 | |
---|
2259 | if ( uiCode == 0 ) |
---|
2260 | { |
---|
2261 | m_pcBinIf->encodeBin( 0, m_cALFUvlcSCModel.get( 0, 0, 0 ) ); |
---|
2262 | } |
---|
2263 | else |
---|
2264 | { |
---|
2265 | m_pcBinIf->encodeBin( 1, m_cALFUvlcSCModel.get( 0, 0, 0 ) ); |
---|
2266 | for ( i=0; i<uiCode-1; i++ ) |
---|
2267 | { |
---|
2268 | m_pcBinIf->encodeBin( 1, m_cALFUvlcSCModel.get( 0, 0, 1 ) ); |
---|
2269 | } |
---|
2270 | m_pcBinIf->encodeBin( 0, m_cALFUvlcSCModel.get( 0, 0, 1 ) ); |
---|
2271 | } |
---|
2272 | } |
---|
2273 | |
---|
2274 | Void TEncSbac::codeAlfSvlc ( Int iCode ) |
---|
2275 | { |
---|
2276 | Int i; |
---|
2277 | |
---|
2278 | if ( iCode == 0 ) |
---|
2279 | { |
---|
2280 | m_pcBinIf->encodeBin( 0, m_cALFSvlcSCModel.get( 0, 0, 0 ) ); |
---|
2281 | } |
---|
2282 | else |
---|
2283 | { |
---|
2284 | m_pcBinIf->encodeBin( 1, m_cALFSvlcSCModel.get( 0, 0, 0 ) ); |
---|
2285 | |
---|
2286 | // write sign |
---|
2287 | if ( iCode > 0 ) |
---|
2288 | { |
---|
2289 | m_pcBinIf->encodeBin( 0, m_cALFSvlcSCModel.get( 0, 0, 1 ) ); |
---|
2290 | } |
---|
2291 | else |
---|
2292 | { |
---|
2293 | m_pcBinIf->encodeBin( 1, m_cALFSvlcSCModel.get( 0, 0, 1 ) ); |
---|
2294 | iCode = -iCode; |
---|
2295 | } |
---|
2296 | |
---|
2297 | // write magnitude |
---|
2298 | for ( i=0; i<iCode-1; i++ ) |
---|
2299 | { |
---|
2300 | m_pcBinIf->encodeBin( 1, m_cALFSvlcSCModel.get( 0, 0, 2 ) ); |
---|
2301 | } |
---|
2302 | m_pcBinIf->encodeBin( 0, m_cALFSvlcSCModel.get( 0, 0, 2 ) ); |
---|
2303 | } |
---|
2304 | } |
---|
2305 | |
---|
2306 | #if MTK_SAO |
---|
2307 | Void TEncSbac::codeAoFlag ( UInt uiCode ) |
---|
2308 | { |
---|
2309 | UInt uiSymbol = ( ( uiCode == 0 ) ? 0 : 1 ); |
---|
2310 | m_pcBinIf->encodeBin( uiSymbol, m_cAOFlagSCModel.get( 0, 0, 0 ) ); |
---|
2311 | } |
---|
2312 | Void TEncSbac::codeAoUvlc ( UInt uiCode ) |
---|
2313 | { |
---|
2314 | Int i; |
---|
2315 | |
---|
2316 | if ( uiCode == 0 ) |
---|
2317 | { |
---|
2318 | m_pcBinIf->encodeBin( 0, m_cAOUvlcSCModel.get( 0, 0, 0 ) ); |
---|
2319 | } |
---|
2320 | else |
---|
2321 | { |
---|
2322 | m_pcBinIf->encodeBin( 1, m_cAOUvlcSCModel.get( 0, 0, 0 ) ); |
---|
2323 | for ( i=0; i<uiCode-1; i++ ) |
---|
2324 | { |
---|
2325 | m_pcBinIf->encodeBin( 1, m_cAOUvlcSCModel.get( 0, 0, 1 ) ); |
---|
2326 | } |
---|
2327 | m_pcBinIf->encodeBin( 0, m_cAOUvlcSCModel.get( 0, 0, 1 ) ); |
---|
2328 | } |
---|
2329 | } |
---|
2330 | Void TEncSbac::codeAoSvlc ( Int iCode ) |
---|
2331 | { |
---|
2332 | Int i; |
---|
2333 | |
---|
2334 | if ( iCode == 0 ) |
---|
2335 | { |
---|
2336 | m_pcBinIf->encodeBin( 0, m_cAOSvlcSCModel.get( 0, 0, 0 ) ); |
---|
2337 | } |
---|
2338 | else |
---|
2339 | { |
---|
2340 | m_pcBinIf->encodeBin( 1, m_cAOSvlcSCModel.get( 0, 0, 0 ) ); |
---|
2341 | |
---|
2342 | // write sign |
---|
2343 | if ( iCode > 0 ) |
---|
2344 | { |
---|
2345 | m_pcBinIf->encodeBin( 0, m_cAOSvlcSCModel.get( 0, 0, 1 ) ); |
---|
2346 | } |
---|
2347 | else |
---|
2348 | { |
---|
2349 | m_pcBinIf->encodeBin( 1, m_cAOSvlcSCModel.get( 0, 0, 1 ) ); |
---|
2350 | iCode = -iCode; |
---|
2351 | } |
---|
2352 | |
---|
2353 | // write magnitude |
---|
2354 | for ( i=0; i<iCode-1; i++ ) |
---|
2355 | { |
---|
2356 | m_pcBinIf->encodeBin( 1, m_cAOSvlcSCModel.get( 0, 0, 2 ) ); |
---|
2357 | } |
---|
2358 | m_pcBinIf->encodeBin( 0, m_cAOSvlcSCModel.get( 0, 0, 2 ) ); |
---|
2359 | } |
---|
2360 | } |
---|
2361 | #endif |
---|
2362 | |
---|
2363 | /*! |
---|
2364 | **************************************************************************** |
---|
2365 | * \brief |
---|
2366 | * estimate bit cost for CBP, significant map and significant coefficients |
---|
2367 | **************************************************************************** |
---|
2368 | */ |
---|
2369 | Void TEncSbac::estBit( estBitsSbacStruct* pcEstBitsSbac, UInt uiCTXIdx, TextType eTType ) |
---|
2370 | { |
---|
2371 | estCBFBit( pcEstBitsSbac, 0, eTType ); |
---|
2372 | |
---|
2373 | // encode significance map |
---|
2374 | estSignificantMapBit( pcEstBitsSbac, uiCTXIdx, eTType ); |
---|
2375 | |
---|
2376 | // encode significant coefficients |
---|
2377 | estSignificantCoefficientsBit( pcEstBitsSbac, uiCTXIdx, eTType ); |
---|
2378 | } |
---|
2379 | |
---|
2380 | /*! |
---|
2381 | **************************************************************************** |
---|
2382 | * \brief |
---|
2383 | * estimate bit cost for each CBP bit |
---|
2384 | **************************************************************************** |
---|
2385 | */ |
---|
2386 | Void TEncSbac::estCBFBit( estBitsSbacStruct* pcEstBitsSbac, UInt uiCTXIdx, TextType eTType ) |
---|
2387 | { |
---|
2388 | ContextModel *pCtx = m_cCUQtCbfSCModel.get( 0 ); |
---|
2389 | |
---|
2390 | for( UInt uiCtxInc = 0; uiCtxInc < 45; uiCtxInc++ ) |
---|
2391 | { |
---|
2392 | pcEstBitsSbac->blockCbpBits[ uiCtxInc ][ 0 ] = biari_no_bits( 0, pCtx[ uiCtxInc ] ); |
---|
2393 | pcEstBitsSbac->blockCbpBits[ uiCtxInc ][ 1 ] = biari_no_bits( 1, pCtx[ uiCtxInc ] ); |
---|
2394 | } |
---|
2395 | |
---|
2396 | for( UInt uiCtxInc = 0; uiCtxInc < 4; uiCtxInc++ ) |
---|
2397 | { |
---|
2398 | pcEstBitsSbac->blockRootCbpBits[ uiCtxInc ][ 0 ] = biari_no_bits( 0, m_cCUQtRootCbfSCModel.get( 0, 0, uiCtxInc ) ); |
---|
2399 | pcEstBitsSbac->blockRootCbpBits[ uiCtxInc ][ 1 ] = biari_no_bits( 1, m_cCUQtRootCbfSCModel.get( 0, 0, uiCtxInc ) ); |
---|
2400 | } |
---|
2401 | } |
---|
2402 | |
---|
2403 | |
---|
2404 | /*! |
---|
2405 | **************************************************************************** |
---|
2406 | * \brief |
---|
2407 | * estimate SAMBAC bit cost for significant coefficient map |
---|
2408 | **************************************************************************** |
---|
2409 | */ |
---|
2410 | Void TEncSbac::estSignificantMapBit( estBitsSbacStruct* pcEstBitsSbac, UInt uiCTXIdx, TextType eTType ) |
---|
2411 | { |
---|
2412 | for ( UInt uiCtx = 0; uiCtx < 16; uiCtx++ ) |
---|
2413 | { |
---|
2414 | for( UInt uiBin = 0; uiBin < 2; uiBin++ ) |
---|
2415 | { |
---|
2416 | #if SIMPLE_CONTEXT_SIG |
---|
2417 | if( uiCtx < 4 || eTType ) |
---|
2418 | { |
---|
2419 | pcEstBitsSbac->significantBits[ uiCtx ][ uiBin ] = biari_no_bits ( uiBin, m_cCUSigSCModel.get( uiCTXIdx-2, eTType, uiCtx ) ); |
---|
2420 | } |
---|
2421 | else |
---|
2422 | { |
---|
2423 | pcEstBitsSbac->significantBits[ uiCtx ][ uiBin ] = biari_no_bits ( uiBin, m_cCUSigSCModel.get( uiCTXIdx-2 ? uiCTXIdx-2 : 1, eTType, uiCtx ) ); |
---|
2424 | } |
---|
2425 | #else |
---|
2426 | pcEstBitsSbac->significantBits[ uiCtx ][ uiBin ] = biari_no_bits ( uiBin, m_cCUSigSCModel.get( uiCTXIdx, eTType, uiCtx ) ); |
---|
2427 | #endif |
---|
2428 | |
---|
2429 | #if !PCP_SIGMAP_SIMPLE_LAST |
---|
2430 | pcEstBitsSbac->lastBits[ uiCtx ][ uiBin ] = biari_no_bits ( uiBin, m_cCULastSCModel.get( uiCTXIdx, eTType, uiCtx ) ); |
---|
2431 | #endif |
---|
2432 | } |
---|
2433 | } |
---|
2434 | |
---|
2435 | #if PCP_SIGMAP_SIMPLE_LAST |
---|
2436 | Int iBitsX = 0, iBitsY = 0; |
---|
2437 | const UInt uiCtxOffset = g_uiCtxXYOffset[uiCTXIdx]; |
---|
2438 | const UInt uiWidthM1 = (1 << (7-uiCTXIdx)) - 1; |
---|
2439 | for ( UInt uiCtx = 0; uiCtx < uiWidthM1; uiCtx++ ) |
---|
2440 | { |
---|
2441 | pcEstBitsSbac->lastXBits[uiCtx] = iBitsX + biari_no_bits (1, m_cCuCtxLastX.get( 0, eTType, uiCtxOffset + g_uiCtxXY[uiCtx] )); |
---|
2442 | pcEstBitsSbac->lastYBits[uiCtx] = iBitsY + biari_no_bits (1, m_cCuCtxLastY.get( 0, eTType, uiCtxOffset + g_uiCtxXY[uiCtx] )); |
---|
2443 | iBitsX += biari_no_bits (0, m_cCuCtxLastX.get( 0, eTType, uiCtxOffset + g_uiCtxXY[uiCtx] )); |
---|
2444 | iBitsY += biari_no_bits (0, m_cCuCtxLastY.get( 0, eTType, uiCtxOffset + g_uiCtxXY[uiCtx] )); |
---|
2445 | } |
---|
2446 | pcEstBitsSbac->lastXBits[uiWidthM1] = iBitsX; |
---|
2447 | pcEstBitsSbac->lastYBits[uiWidthM1] = iBitsY; |
---|
2448 | #endif |
---|
2449 | } |
---|
2450 | |
---|
2451 | /*! |
---|
2452 | **************************************************************************** |
---|
2453 | * \brief |
---|
2454 | * estimate bit cost of significant coefficient |
---|
2455 | **************************************************************************** |
---|
2456 | */ |
---|
2457 | Void TEncSbac::estSignificantCoefficientsBit( estBitsSbacStruct* pcEstBitsSbac, UInt uiCTXIdx, TextType eTType ) |
---|
2458 | { |
---|
2459 | for( UInt uiSet = 0; uiSet < 6; uiSet++ ) |
---|
2460 | { |
---|
2461 | for( UInt uiCtx = 0; uiCtx < 5; uiCtx++ ) |
---|
2462 | { |
---|
2463 | pcEstBitsSbac->greaterOneBits[ uiSet ][ 0 ][ uiCtx ][ 0 ] = biari_no_bits( 0, m_cCUOneSCModel.get( 0, eTType, ( uiSet << 2 ) + uiSet + uiCtx ) ); |
---|
2464 | pcEstBitsSbac->greaterOneBits[ uiSet ][ 0 ][ uiCtx ][ 1 ] = biari_no_bits( 1, m_cCUOneSCModel.get( 0, eTType, ( uiSet << 2 ) + uiSet + uiCtx ) ); |
---|
2465 | pcEstBitsSbac->greaterOneBits[ uiSet ][ 1 ][ uiCtx ][ 0 ] = biari_no_bits( 0, m_cCUAbsSCModel.get( 0, eTType, ( uiSet << 2 ) + uiSet + uiCtx ) ); |
---|
2466 | pcEstBitsSbac->greaterOneBits[ uiSet ][ 1 ][ uiCtx ][ 1 ] = biari_no_bits( 1, m_cCUAbsSCModel.get( 0, eTType, ( uiSet << 2 ) + uiSet + uiCtx ) ); |
---|
2467 | } |
---|
2468 | } |
---|
2469 | } |
---|
2470 | |
---|
2471 | Int TEncSbac::biari_no_bits( Short symbol, ContextModel& rcSCModel ) |
---|
2472 | { |
---|
2473 | UInt uiEstBits; |
---|
2474 | Short ui16State; |
---|
2475 | |
---|
2476 | symbol = (Short)( symbol != 0 ); |
---|
2477 | ui16State = symbol == rcSCModel.getMps() ? 64 + rcSCModel.getState() : 63 - rcSCModel.getState(); |
---|
2478 | uiEstBits = entropyBits[ 127 - ui16State ]; |
---|
2479 | return uiEstBits; |
---|
2480 | } |
---|