1 | |
---|
2 | |
---|
3 | /** \file TEncCavlc.cpp |
---|
4 | \brief CAVLC encoder class |
---|
5 | */ |
---|
6 | |
---|
7 | #include "TEncCavlc.h" |
---|
8 | #include "SEIwrite.h" |
---|
9 | |
---|
10 | // ==================================================================================================================== |
---|
11 | // Constructor / destructor / create / destroy |
---|
12 | // ==================================================================================================================== |
---|
13 | |
---|
14 | TEncCavlc::TEncCavlc() |
---|
15 | { |
---|
16 | m_pcBitIf = NULL; |
---|
17 | m_bRunLengthCoding = false; // m_bRunLengthCoding = !rcSliceHeader.isIntra(); |
---|
18 | m_uiCoeffCost = 0; |
---|
19 | m_bAlfCtrl = false; |
---|
20 | m_uiMaxAlfCtrlDepth = 0; |
---|
21 | |
---|
22 | m_bAdaptFlag = true; // adaptive VLC table |
---|
23 | } |
---|
24 | |
---|
25 | TEncCavlc::~TEncCavlc() |
---|
26 | { |
---|
27 | } |
---|
28 | |
---|
29 | |
---|
30 | // ==================================================================================================================== |
---|
31 | // Public member functions |
---|
32 | // ==================================================================================================================== |
---|
33 | |
---|
34 | Void TEncCavlc::resetEntropy() |
---|
35 | { |
---|
36 | m_bRunLengthCoding = ! m_pcSlice->isIntra(); |
---|
37 | m_uiRun = 0; |
---|
38 | #if !CAVLC_COEF_LRG_BLK |
---|
39 | ::memcpy(m_uiLPTableE8, g_auiLPTableE8, 10*128*sizeof(UInt)); |
---|
40 | ::memcpy(m_uiLPTableD8, g_auiLPTableD8, 10*128*sizeof(UInt)); |
---|
41 | #endif |
---|
42 | ::memcpy(m_uiLPTableE4, g_auiLPTableE4, 3*32*sizeof(UInt)); |
---|
43 | ::memcpy(m_uiLPTableD4, g_auiLPTableD4, 3*32*sizeof(UInt)); |
---|
44 | ::memcpy(m_uiLastPosVlcIndex, g_auiLastPosVlcIndex, 10*sizeof(UInt)); |
---|
45 | |
---|
46 | #if LCEC_INTRA_MODE |
---|
47 | #if MTK_DCM_MPM |
---|
48 | ::memcpy(m_uiIntraModeTableD17[0], g_auiIntraModeTableD17[0], 16*sizeof(UInt)); |
---|
49 | ::memcpy(m_uiIntraModeTableE17[0], g_auiIntraModeTableE17[0], 16*sizeof(UInt)); |
---|
50 | ::memcpy(m_uiIntraModeTableD17[1], g_auiIntraModeTableD17[1], 16*sizeof(UInt)); |
---|
51 | ::memcpy(m_uiIntraModeTableE17[1], g_auiIntraModeTableE17[1], 16*sizeof(UInt)); |
---|
52 | |
---|
53 | ::memcpy(m_uiIntraModeTableD34[0], g_auiIntraModeTableD34[0], 33*sizeof(UInt)); |
---|
54 | ::memcpy(m_uiIntraModeTableE34[0], g_auiIntraModeTableE34[0], 33*sizeof(UInt)); |
---|
55 | ::memcpy(m_uiIntraModeTableD34[1], g_auiIntraModeTableD34[1], 33*sizeof(UInt)); |
---|
56 | ::memcpy(m_uiIntraModeTableE34[1], g_auiIntraModeTableE34[1], 33*sizeof(UInt)); |
---|
57 | #else |
---|
58 | ::memcpy(m_uiIntraModeTableD17, g_auiIntraModeTableD17, 16*sizeof(UInt)); |
---|
59 | ::memcpy(m_uiIntraModeTableE17, g_auiIntraModeTableE17, 16*sizeof(UInt)); |
---|
60 | |
---|
61 | ::memcpy(m_uiIntraModeTableD34, g_auiIntraModeTableD34, 33*sizeof(UInt)); |
---|
62 | ::memcpy(m_uiIntraModeTableE34, g_auiIntraModeTableE34, 33*sizeof(UInt)); |
---|
63 | #endif |
---|
64 | #endif |
---|
65 | |
---|
66 | #if CAVLC_RQT_CBP |
---|
67 | ::memcpy(m_uiCBP_YUV_TableE, g_auiCBP_YUV_TableE, 4*8*sizeof(UInt)); |
---|
68 | ::memcpy(m_uiCBP_YUV_TableD, g_auiCBP_YUV_TableD, 4*8*sizeof(UInt)); |
---|
69 | ::memcpy(m_uiCBP_YS_TableE, g_auiCBP_YS_TableE, 2*4*sizeof(UInt)); |
---|
70 | ::memcpy(m_uiCBP_YS_TableD, g_auiCBP_YS_TableD, 2*4*sizeof(UInt)); |
---|
71 | ::memcpy(m_uiCBP_YCS_TableE, g_auiCBP_YCS_TableE, 2*8*sizeof(UInt)); |
---|
72 | ::memcpy(m_uiCBP_YCS_TableD, g_auiCBP_YCS_TableD, 2*8*sizeof(UInt)); |
---|
73 | ::memcpy(m_uiCBP_4Y_TableE, g_auiCBP_4Y_TableE, 2*15*sizeof(UInt)); |
---|
74 | ::memcpy(m_uiCBP_4Y_TableD, g_auiCBP_4Y_TableD, 2*15*sizeof(UInt)); |
---|
75 | m_uiCBP_4Y_VlcIdx = 0; |
---|
76 | #else |
---|
77 | ::memcpy(m_uiCBPTableE, g_auiCBPTableE, 2*8*sizeof(UInt)); |
---|
78 | ::memcpy(m_uiCBPTableD, g_auiCBPTableD, 2*8*sizeof(UInt)); |
---|
79 | m_uiCbpVlcIdx[0] = 0; |
---|
80 | m_uiCbpVlcIdx[1] = 0; |
---|
81 | ::memcpy(m_uiBlkCBPTableE, g_auiBlkCBPTableE, 2*15*sizeof(UInt)); |
---|
82 | ::memcpy(m_uiBlkCBPTableD, g_auiBlkCBPTableD, 2*15*sizeof(UInt)); |
---|
83 | m_uiBlkCbpVlcIdx = 0; |
---|
84 | #endif |
---|
85 | |
---|
86 | #if UNIFY_INTER_TABLE |
---|
87 | ::memcpy(m_uiMI1TableE, g_auiComMI1TableE, 9*sizeof(UInt)); |
---|
88 | ::memcpy(m_uiMI1TableD, g_auiComMI1TableD, 9*sizeof(UInt)); |
---|
89 | #else |
---|
90 | ::memcpy(m_uiMI1TableE, g_auiMI1TableE, 8*sizeof(UInt)); |
---|
91 | ::memcpy(m_uiMI1TableD, g_auiMI1TableD, 8*sizeof(UInt)); |
---|
92 | ::memcpy(m_uiMI2TableE, g_auiMI2TableE, 15*sizeof(UInt)); |
---|
93 | ::memcpy(m_uiMI2TableD, g_auiMI2TableD, 15*sizeof(UInt)); |
---|
94 | |
---|
95 | #if DCM_COMB_LIST |
---|
96 | if ( m_pcSlice->getNoBackPredFlag() || m_pcSlice->getNumRefIdx(REF_PIC_LIST_C)>0) |
---|
97 | #else |
---|
98 | if ( m_pcSlice->getNoBackPredFlag() ) |
---|
99 | #endif |
---|
100 | { |
---|
101 | ::memcpy(m_uiMI1TableE, g_auiMI1TableENoL1, 8*sizeof(UInt)); |
---|
102 | ::memcpy(m_uiMI1TableD, g_auiMI1TableDNoL1, 8*sizeof(UInt)); |
---|
103 | ::memcpy(m_uiMI2TableE, g_auiMI2TableENoL1, 15*sizeof(UInt)); |
---|
104 | ::memcpy(m_uiMI2TableD, g_auiMI2TableDNoL1, 15*sizeof(UInt)); |
---|
105 | } |
---|
106 | #if MS_LCEC_ONE_FRAME |
---|
107 | if ( m_pcSlice->getNumRefIdx(REF_PIC_LIST_0) <= 1 && m_pcSlice->getNumRefIdx(REF_PIC_LIST_1) <= 1 ) |
---|
108 | { |
---|
109 | if ( m_pcSlice->getNoBackPredFlag() || ( m_pcSlice->getNumRefIdx(REF_PIC_LIST_C) > 0 && m_pcSlice->getNumRefIdx(REF_PIC_LIST_C) <= 1 ) ) |
---|
110 | { |
---|
111 | ::memcpy(m_uiMI1TableE, g_auiMI1TableEOnly1RefNoL1, 8*sizeof(UInt)); |
---|
112 | ::memcpy(m_uiMI1TableD, g_auiMI1TableDOnly1RefNoL1, 8*sizeof(UInt)); |
---|
113 | } |
---|
114 | else |
---|
115 | { |
---|
116 | ::memcpy(m_uiMI1TableE, g_auiMI1TableEOnly1Ref, 8*sizeof(UInt)); |
---|
117 | ::memcpy(m_uiMI1TableD, g_auiMI1TableDOnly1Ref, 8*sizeof(UInt)); |
---|
118 | } |
---|
119 | } |
---|
120 | #endif |
---|
121 | #if MS_LCEC_LOOKUP_TABLE_EXCEPTION |
---|
122 | if (m_pcSlice->getNumRefIdx(REF_PIC_LIST_C)>0) |
---|
123 | { |
---|
124 | m_uiMI1TableE[8] = 8; |
---|
125 | m_uiMI1TableD[8] = 8; |
---|
126 | } |
---|
127 | else // GPB case |
---|
128 | { |
---|
129 | m_uiMI1TableD[8] = m_uiMI1TableD[6]; |
---|
130 | m_uiMI1TableD[6] = 8; |
---|
131 | |
---|
132 | m_uiMI1TableE[m_uiMI1TableD[8]] = 8; |
---|
133 | m_uiMI1TableE[m_uiMI1TableD[6]] = 6; |
---|
134 | } |
---|
135 | #endif |
---|
136 | #endif |
---|
137 | |
---|
138 | #if QC_LCEC_INTER_MODE |
---|
139 | ::memcpy(m_uiSplitTableE, g_auiInterModeTableE, 4*7*sizeof(UInt)); |
---|
140 | ::memcpy(m_uiSplitTableD, g_auiInterModeTableD, 4*7*sizeof(UInt)); |
---|
141 | #endif |
---|
142 | |
---|
143 | m_uiMITableVlcIdx = 0; |
---|
144 | |
---|
145 | #if CAVLC_COUNTER_ADAPT |
---|
146 | #if CAVLC_RQT_CBP |
---|
147 | ::memset(m_ucCBP_YUV_TableCounter, 0, 4*4*sizeof(UChar)); |
---|
148 | ::memset(m_ucCBP_4Y_TableCounter, 0, 2*2*sizeof(UChar)); |
---|
149 | ::memset(m_ucCBP_YCS_TableCounter, 0, 2*4*sizeof(UChar)); |
---|
150 | ::memset(m_ucCBP_YS_TableCounter, 0, 2*3*sizeof(UChar)); |
---|
151 | #else |
---|
152 | ::memset(m_ucCBFTableCounter, 0, 2*4*sizeof(UChar)); |
---|
153 | ::memset(m_ucBlkCBPTableCounter, 0, 2*2*sizeof(UChar)); |
---|
154 | #endif |
---|
155 | |
---|
156 | ::memset(m_ucMI1TableCounter, 0, 4*sizeof(UChar)); |
---|
157 | ::memset(m_ucSplitTableCounter, 0, 4*4*sizeof(UChar)); |
---|
158 | |
---|
159 | #if CAVLC_RQT_CBP |
---|
160 | m_ucCBP_YUV_TableCounterSum[0] = m_ucCBP_YUV_TableCounterSum[1] = m_ucCBP_YUV_TableCounterSum[2] = m_ucCBP_YUV_TableCounterSum[3] = 0; |
---|
161 | m_ucCBP_4Y_TableCounterSum[0] = m_ucCBP_4Y_TableCounterSum[1] = 0; |
---|
162 | m_ucCBP_YCS_TableCounterSum[0] = m_ucCBP_YCS_TableCounterSum[1] = 0; |
---|
163 | m_ucCBP_YS_TableCounterSum[0] = m_ucCBP_YS_TableCounterSum[1] = 0; |
---|
164 | #else |
---|
165 | m_ucCBFTableCounterSum[0] = m_ucCBFTableCounterSum[1] = 0; |
---|
166 | m_ucBlkCBPTableCounterSum[0] = m_ucBlkCBPTableCounterSum[1] = 0; |
---|
167 | #endif |
---|
168 | m_ucSplitTableCounterSum[0] = m_ucSplitTableCounterSum[1] = m_ucSplitTableCounterSum[2]= m_ucSplitTableCounterSum[3] = 0; |
---|
169 | m_ucMI1TableCounterSum = 0; |
---|
170 | #endif |
---|
171 | } |
---|
172 | |
---|
173 | #if !CAVLC_COEF_LRG_BLK |
---|
174 | UInt* TEncCavlc::GetLP8Table() |
---|
175 | { |
---|
176 | return &m_uiLPTableE8[0][0]; |
---|
177 | } |
---|
178 | #endif |
---|
179 | |
---|
180 | UInt* TEncCavlc::GetLP4Table() |
---|
181 | { |
---|
182 | return &m_uiLPTableE4[0][0]; |
---|
183 | } |
---|
184 | |
---|
185 | #if QC_MOD_LCEC |
---|
186 | UInt* TEncCavlc::GetLastPosVlcIndexTable() |
---|
187 | { |
---|
188 | return &m_uiLastPosVlcIndex[0]; |
---|
189 | } |
---|
190 | #endif |
---|
191 | |
---|
192 | /** |
---|
193 | * marshall the SEI message @sei. |
---|
194 | */ |
---|
195 | void TEncCavlc::codeSEI(const SEI& sei) |
---|
196 | { |
---|
197 | codeNALUnitHeader(NAL_UNIT_SEI, NAL_REF_IDC_PRIORITY_LOWEST); |
---|
198 | writeSEImessage(*m_pcBitIf, sei); |
---|
199 | } |
---|
200 | |
---|
201 | Void TEncCavlc::codePPS( TComPPS* pcPPS ) |
---|
202 | { |
---|
203 | // uiFirstByte |
---|
204 | codeNALUnitHeader( NAL_UNIT_PPS, NAL_REF_IDC_PRIORITY_HIGHEST ); |
---|
205 | |
---|
206 | xWriteUvlc( pcPPS->getPPSId() ); |
---|
207 | xWriteUvlc( pcPPS->getSPSId() ); |
---|
208 | #if CONSTRAINED_INTRA_PRED |
---|
209 | xWriteFlag( pcPPS->getConstrainedIntraPred() ? 1 : 0 ); |
---|
210 | #endif |
---|
211 | #ifdef WEIGHT_PRED |
---|
212 | xWriteCode( pcPPS->getUseWP(), 1); // Use of Weighting Prediction (P_SLICE) |
---|
213 | xWriteCode( pcPPS->getWPBiPredIdc(), 2); // Use of Weighting Bi-Prediction (B_SLICE) |
---|
214 | #endif |
---|
215 | return; |
---|
216 | } |
---|
217 | |
---|
218 | Void TEncCavlc::codeNALUnitHeader( NalUnitType eNalUnitType, NalRefIdc eNalRefIdc, UInt TemporalId, Bool bOutputFlag ) |
---|
219 | { |
---|
220 | // uiFirstByte |
---|
221 | xWriteCode( 0, 1); // forbidden_zero_flag |
---|
222 | xWriteCode( eNalRefIdc, 2); // nal_ref_idc |
---|
223 | xWriteCode( eNalUnitType, 5); // nal_unit_type |
---|
224 | |
---|
225 | if ( (eNalUnitType == NAL_UNIT_CODED_SLICE) || (eNalUnitType == NAL_UNIT_CODED_SLICE_IDR) || (eNalUnitType == NAL_UNIT_CODED_SLICE_CDR) ) |
---|
226 | { |
---|
227 | xWriteCode( TemporalId, 3); // temporal_id |
---|
228 | xWriteFlag( bOutputFlag ); // output_flag |
---|
229 | xWriteCode( 1, 4); // reseved_one_4bits |
---|
230 | } |
---|
231 | } |
---|
232 | |
---|
233 | Void TEncCavlc::codeSPS( TComSPS* pcSPS ) |
---|
234 | { |
---|
235 | // uiFirstByte |
---|
236 | codeNALUnitHeader( NAL_UNIT_SPS, NAL_REF_IDC_PRIORITY_HIGHEST ); |
---|
237 | |
---|
238 | // Structure |
---|
239 | xWriteUvlc ( pcSPS->getSPSId() ); |
---|
240 | xWriteUvlc ( pcSPS->getWidth () ); |
---|
241 | xWriteUvlc ( pcSPS->getHeight() ); |
---|
242 | |
---|
243 | xWriteUvlc ( pcSPS->getPad (0) ); |
---|
244 | xWriteUvlc ( pcSPS->getPad (1) ); |
---|
245 | |
---|
246 | assert( pcSPS->getMaxCUWidth() == pcSPS->getMaxCUHeight() ); |
---|
247 | xWriteUvlc ( pcSPS->getMaxCUWidth() ); |
---|
248 | xWriteUvlc ( pcSPS->getMaxCUDepth()-g_uiAddCUDepth ); |
---|
249 | |
---|
250 | xWriteUvlc( pcSPS->getQuadtreeTULog2MinSize() - 2 ); |
---|
251 | xWriteUvlc( pcSPS->getQuadtreeTULog2MaxSize() - pcSPS->getQuadtreeTULog2MinSize() ); |
---|
252 | xWriteUvlc( pcSPS->getQuadtreeTUMaxDepthInter() - 1 ); |
---|
253 | xWriteUvlc( pcSPS->getQuadtreeTUMaxDepthIntra() - 1 ); |
---|
254 | |
---|
255 | xWriteUvlc( pcSPS->getCodedPictureBufferSize() ); |
---|
256 | |
---|
257 | // Tools |
---|
258 | xWriteFlag ( (pcSPS->getUseALF ()) ? 1 : 0 ); |
---|
259 | xWriteFlag ( (pcSPS->getUseDQP ()) ? 1 : 0 ); |
---|
260 | #if !SB_NO_LowDelayCoding |
---|
261 | xWriteFlag ( (pcSPS->getUseLDC ()) ? 1 : 0 ); |
---|
262 | #endif |
---|
263 | xWriteFlag ( (pcSPS->getUseMRG ()) ? 1 : 0 ); // SOPH: |
---|
264 | |
---|
265 | #if LM_CHROMA |
---|
266 | xWriteFlag ( (pcSPS->getUseLMChroma ()) ? 1 : 0 ); |
---|
267 | #endif |
---|
268 | |
---|
269 | #if HHI_RMP_SWITCH |
---|
270 | xWriteFlag ( (pcSPS->getUseRMP()) ? 1 : 0 ); |
---|
271 | #endif |
---|
272 | |
---|
273 | // AMVP mode for each depth |
---|
274 | for (Int i = 0; i < pcSPS->getMaxCUDepth(); i++) |
---|
275 | { |
---|
276 | xWriteFlag( pcSPS->getAMVPMode(i) ? 1 : 0); |
---|
277 | } |
---|
278 | |
---|
279 | // Bit-depth information |
---|
280 | #if FULL_NBIT |
---|
281 | xWriteUvlc( pcSPS->getBitDepth() - 8 ); |
---|
282 | #else |
---|
283 | #if ENABLE_IBDI |
---|
284 | xWriteUvlc( pcSPS->getBitDepth() - 8 ); |
---|
285 | #endif |
---|
286 | xWriteUvlc( pcSPS->getBitIncrement() ); |
---|
287 | #endif |
---|
288 | |
---|
289 | #if MTK_NONCROSS_INLOOP_FILTER |
---|
290 | xWriteFlag( pcSPS->getLFCrossSliceBoundaryFlag()?1 : 0); |
---|
291 | #endif |
---|
292 | #if MTK_SAO |
---|
293 | xWriteFlag( pcSPS->getUseSAO() ? 1 : 0); |
---|
294 | #endif |
---|
295 | |
---|
296 | if( pcSPS->getViewId() || pcSPS->isDepth() ) |
---|
297 | { |
---|
298 | xWriteFlag( 0 ); // inverse of RBSP stop bit (for backwards compatible extension) |
---|
299 | if( pcSPS->isDepth() ) |
---|
300 | { |
---|
301 | xWriteFlag( 1 ); // depth |
---|
302 | xWriteUvlc( pcSPS->getViewId() ); |
---|
303 | xWriteSvlc( pcSPS->getViewOrderIdx() ); |
---|
304 | #if HHI_DMM_INTRA |
---|
305 | xWriteFlag( pcSPS->getUseDepthModelModes() ? 1 : 0 ); |
---|
306 | #endif |
---|
307 | xWriteFlag( pcSPS->getUseMVI() ? 1 : 0 ); |
---|
308 | } |
---|
309 | else |
---|
310 | { |
---|
311 | xWriteFlag( 0 ); // not depth |
---|
312 | xWriteUvlc( pcSPS->getViewId() - 1 ); |
---|
313 | xWriteSvlc( pcSPS->getViewOrderIdx() ); |
---|
314 | xWriteUvlc( pcSPS->getCamParPrecision() ); |
---|
315 | xWriteFlag( pcSPS->hasCamParInSliceHeader() ? 1 : 0 ); |
---|
316 | if( !pcSPS->hasCamParInSliceHeader() ) |
---|
317 | { |
---|
318 | for( UInt uiId = 0; uiId < pcSPS->getViewId(); uiId++ ) |
---|
319 | { |
---|
320 | xWriteSvlc( pcSPS->getCodedScale ()[ uiId ] ); |
---|
321 | xWriteSvlc( pcSPS->getCodedOffset ()[ uiId ] ); |
---|
322 | xWriteSvlc( pcSPS->getInvCodedScale ()[ uiId ] + pcSPS->getCodedScale ()[ uiId ] ); |
---|
323 | xWriteSvlc( pcSPS->getInvCodedOffset()[ uiId ] + pcSPS->getCodedOffset()[ uiId ] ); |
---|
324 | } |
---|
325 | } |
---|
326 | xWriteUvlc( pcSPS->getPredDepthMapGeneration() ); |
---|
327 | if( pcSPS->getPredDepthMapGeneration() ) |
---|
328 | { |
---|
329 | xWriteUvlc ( pcSPS->getPdmPrecision() ); |
---|
330 | for( UInt uiId = 0; uiId < pcSPS->getViewId(); uiId++ ) |
---|
331 | { |
---|
332 | xWriteSvlc( pcSPS->getPdmScaleNomDelta()[ uiId ] ); |
---|
333 | xWriteSvlc( pcSPS->getPdmOffset ()[ uiId ] ); |
---|
334 | } |
---|
335 | xWriteUvlc ( pcSPS->getMultiviewMvPredMode() ); |
---|
336 | xWriteFlag ( pcSPS->getMultiviewResPredMode() ); |
---|
337 | } |
---|
338 | } |
---|
339 | } |
---|
340 | } |
---|
341 | |
---|
342 | Void TEncCavlc::codeSliceHeader ( TComSlice* pcSlice ) |
---|
343 | { |
---|
344 | // here someone can add an appropriated NalRefIdc type |
---|
345 | #if DCM_DECODING_REFRESH |
---|
346 | codeNALUnitHeader (pcSlice->getNalUnitType(), NAL_REF_IDC_PRIORITY_HIGHEST, 1, true); |
---|
347 | #else |
---|
348 | codeNALUnitHeader (NAL_UNIT_CODED_SLICE, NAL_REF_IDC_PRIORITY_HIGHEST); |
---|
349 | #endif |
---|
350 | |
---|
351 | Bool bEntropySlice = false; |
---|
352 | if (pcSlice->isNextSlice()) |
---|
353 | { |
---|
354 | xWriteFlag( 0 ); // Entropy slice flag |
---|
355 | } |
---|
356 | else |
---|
357 | { |
---|
358 | bEntropySlice = true; |
---|
359 | xWriteFlag( 1 ); // Entropy slice flag |
---|
360 | } |
---|
361 | if (!bEntropySlice) |
---|
362 | { |
---|
363 | assert( pcSlice->getPPS()->getPPSId() == pcSlice->getPPSId() ); |
---|
364 | xWriteUvlc ( pcSlice->getPPSId() ); |
---|
365 | xWriteCode (pcSlice->getPOC(), 10 ); // 9 == SPS->Log2MaxFrameNum |
---|
366 | xWriteUvlc (pcSlice->getSliceType() ); |
---|
367 | xWriteSvlc (pcSlice->getSliceQp() ); |
---|
368 | } |
---|
369 | if (pcSlice->isNextSlice()) |
---|
370 | { |
---|
371 | xWriteUvlc(pcSlice->getSliceCurStartCUAddr()); // start CU addr for slice |
---|
372 | } |
---|
373 | else |
---|
374 | { |
---|
375 | xWriteUvlc(pcSlice->getEntropySliceCurStartCUAddr()); // start CU addr for entropy slice |
---|
376 | } |
---|
377 | if (!bEntropySlice) |
---|
378 | { |
---|
379 | xWriteFlag (pcSlice->getSymbolMode() > 0 ? 1 : 0); |
---|
380 | |
---|
381 | if (!pcSlice->isIntra()) |
---|
382 | { |
---|
383 | xWriteFlag (pcSlice->isReferenced() ? 1 : 0); |
---|
384 | #if !HIGH_ACCURACY_BI |
---|
385 | #ifdef ROUNDING_CONTROL_BIPRED |
---|
386 | xWriteFlag (pcSlice->isRounding() ? 1 : 0); |
---|
387 | #endif |
---|
388 | #endif |
---|
389 | } |
---|
390 | |
---|
391 | xWriteFlag (pcSlice->getLoopFilterDisable()); |
---|
392 | |
---|
393 | if (!pcSlice->isIntra()) |
---|
394 | { |
---|
395 | xWriteCode ((pcSlice->getNumRefIdx( REF_PIC_LIST_0 )), 3 ); |
---|
396 | } |
---|
397 | else |
---|
398 | { |
---|
399 | pcSlice->setNumRefIdx(REF_PIC_LIST_0, 0); |
---|
400 | } |
---|
401 | if (pcSlice->isInterB()) |
---|
402 | { |
---|
403 | xWriteCode ((pcSlice->getNumRefIdx( REF_PIC_LIST_1 )), 3 ); |
---|
404 | } |
---|
405 | else |
---|
406 | { |
---|
407 | pcSlice->setNumRefIdx(REF_PIC_LIST_1, 0); |
---|
408 | } |
---|
409 | |
---|
410 | if (!pcSlice->isIntra()) |
---|
411 | { |
---|
412 | |
---|
413 | for(Int i = 0; i<pcSlice->getNumRefIdx(REF_PIC_LIST_0);i++) |
---|
414 | { |
---|
415 | const bool bInterViewRef = pcSlice->getViewIdx() != pcSlice->getRefPic( REF_PIC_LIST_0,i )->getViewIdx(); |
---|
416 | xWriteFlag( bInterViewRef ); |
---|
417 | if( bInterViewRef ) |
---|
418 | { |
---|
419 | xWriteUvlc( pcSlice->getRefPic( REF_PIC_LIST_0,i )->getViewIdx() ); |
---|
420 | } |
---|
421 | else |
---|
422 | { |
---|
423 | xWriteSvlc(pcSlice->getPOC()-pcSlice->getRefPOC(REF_PIC_LIST_0,i)); |
---|
424 | } |
---|
425 | } |
---|
426 | |
---|
427 | } |
---|
428 | if( pcSlice->isInterB()) |
---|
429 | { |
---|
430 | for(Int i = 0; i<pcSlice->getNumRefIdx(REF_PIC_LIST_1);i++) |
---|
431 | { |
---|
432 | const bool bInterViewRef = pcSlice->getViewIdx() != pcSlice->getRefPic( REF_PIC_LIST_1,i )->getViewIdx(); |
---|
433 | xWriteFlag( bInterViewRef ); |
---|
434 | if( bInterViewRef ) |
---|
435 | { |
---|
436 | xWriteUvlc( pcSlice->getRefPic( REF_PIC_LIST_1,i )->getViewIdx() ); |
---|
437 | } |
---|
438 | else |
---|
439 | { |
---|
440 | xWriteSvlc(pcSlice->getPOC()-pcSlice->getRefPOC(REF_PIC_LIST_1,i)); |
---|
441 | } |
---|
442 | } |
---|
443 | } |
---|
444 | |
---|
445 | |
---|
446 | #if DCM_COMB_LIST |
---|
447 | if (pcSlice->isInterB()) |
---|
448 | { |
---|
449 | xWriteFlag (pcSlice->getRefPicListCombinationFlag() ? 1 : 0 ); |
---|
450 | if(pcSlice->getRefPicListCombinationFlag()) |
---|
451 | { |
---|
452 | xWriteUvlc( pcSlice->getNumRefIdx(REF_PIC_LIST_C)-1); |
---|
453 | |
---|
454 | xWriteFlag (pcSlice->getRefPicListModificationFlagLC() ? 1 : 0 ); |
---|
455 | if(pcSlice->getRefPicListModificationFlagLC()) |
---|
456 | { |
---|
457 | for (UInt i=0;i<pcSlice->getNumRefIdx(REF_PIC_LIST_C);i++) |
---|
458 | { |
---|
459 | xWriteFlag( pcSlice->getListIdFromIdxOfLC(i)); |
---|
460 | xWriteUvlc( pcSlice->getRefIdxFromIdxOfLC(i)); |
---|
461 | } |
---|
462 | } |
---|
463 | } |
---|
464 | } |
---|
465 | #endif |
---|
466 | |
---|
467 | #if 0 |
---|
468 | xWriteFlag (pcSlice->getDRBFlag() ? 1 : 0 ); |
---|
469 | if ( !pcSlice->getDRBFlag() ) |
---|
470 | { |
---|
471 | xWriteCode (pcSlice->getERBIndex(), 2); |
---|
472 | } |
---|
473 | #endif |
---|
474 | |
---|
475 | #if AMVP_NEIGH_COL |
---|
476 | if ( pcSlice->getSliceType() == B_SLICE ) |
---|
477 | { |
---|
478 | xWriteFlag( pcSlice->getColDir() ); |
---|
479 | } |
---|
480 | #endif |
---|
481 | |
---|
482 | #ifdef WEIGHT_PRED |
---|
483 | if ( (pcSlice->getPPS()->getUseWP() && pcSlice->getSliceType()==P_SLICE) || (pcSlice->getPPS()->getWPBiPredIdc()==1 && pcSlice->getSliceType()==B_SLICE) ) |
---|
484 | { |
---|
485 | codeWeightPredTable( pcSlice ); |
---|
486 | } |
---|
487 | #endif |
---|
488 | if( pcSlice->getSPS()->hasCamParInSliceHeader() ) |
---|
489 | { |
---|
490 | for( UInt uiId = 0; uiId < pcSlice->getSPS()->getViewId(); uiId++ ) |
---|
491 | { |
---|
492 | xWriteSvlc( pcSlice->getCodedScale ()[ uiId ] ); |
---|
493 | xWriteSvlc( pcSlice->getCodedOffset ()[ uiId ] ); |
---|
494 | xWriteSvlc( pcSlice->getInvCodedScale ()[ uiId ] + pcSlice->getCodedScale ()[ uiId ] ); |
---|
495 | xWriteSvlc( pcSlice->getInvCodedOffset()[ uiId ] + pcSlice->getCodedOffset()[ uiId ] ); |
---|
496 | } |
---|
497 | } |
---|
498 | } |
---|
499 | } |
---|
500 | |
---|
501 | Void TEncCavlc::codeTerminatingBit ( UInt uilsLast ) |
---|
502 | { |
---|
503 | } |
---|
504 | |
---|
505 | Void TEncCavlc::codeSliceFinish () |
---|
506 | { |
---|
507 | if ( m_bRunLengthCoding && m_uiRun) |
---|
508 | { |
---|
509 | xWriteUvlc(m_uiRun); |
---|
510 | } |
---|
511 | } |
---|
512 | |
---|
513 | Void TEncCavlc::codeMVPIdx ( TComDataCU* pcCU, UInt uiAbsPartIdx, RefPicList eRefList ) |
---|
514 | { |
---|
515 | Int iSymbol = pcCU->getMVPIdx(eRefList, uiAbsPartIdx); |
---|
516 | Int iNum = pcCU->getMVPNum(eRefList, uiAbsPartIdx); |
---|
517 | |
---|
518 | xWriteUnaryMaxSymbol(iSymbol, iNum-1); |
---|
519 | } |
---|
520 | #if QC_LCEC_INTER_MODE |
---|
521 | Void TEncCavlc::codePartSize( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth ) |
---|
522 | { |
---|
523 | if ( pcCU->getSlice()->isIntra() && pcCU->isIntra( uiAbsPartIdx ) ) |
---|
524 | { |
---|
525 | #if MTK_DISABLE_INTRA_NxN_SPLIT |
---|
526 | if( uiDepth == (g_uiMaxCUDepth - g_uiAddCUDepth)) |
---|
527 | #endif |
---|
528 | xWriteFlag( pcCU->getPartitionSize(uiAbsPartIdx ) == SIZE_2Nx2N? 1 : 0 ); |
---|
529 | return; |
---|
530 | } |
---|
531 | |
---|
532 | |
---|
533 | #if MTK_DISABLE_INTRA_NxN_SPLIT && HHI_DISABLE_INTER_NxN_SPLIT |
---|
534 | if( uiDepth == g_uiMaxCUDepth - g_uiAddCUDepth ) |
---|
535 | #endif |
---|
536 | { |
---|
537 | if ((pcCU->getPartitionSize(uiAbsPartIdx ) == SIZE_NxN) || pcCU->isIntra( uiAbsPartIdx )) |
---|
538 | { |
---|
539 | UInt uiIntraFlag = ( pcCU->isIntra(uiAbsPartIdx)); |
---|
540 | if (pcCU->getPartitionSize(uiAbsPartIdx ) == SIZE_2Nx2N) |
---|
541 | { |
---|
542 | xWriteFlag(1); |
---|
543 | } |
---|
544 | else |
---|
545 | { |
---|
546 | xWriteFlag(0); |
---|
547 | #if MTK_DISABLE_INTRA_NxN_SPLIT && !HHI_DISABLE_INTER_NxN_SPLIT |
---|
548 | if( uiDepth == g_uiMaxCUDepth - g_uiAddCUDepth ) |
---|
549 | #elif !MTK_DISABLE_INTRA_NxN_SPLIT && HHI_DISABLE_INTER_NxN_SPLIT |
---|
550 | if( uiDepth == g_uiMaxCUDepth - g_uiAddCUDepth ) |
---|
551 | #endif |
---|
552 | xWriteFlag( uiIntraFlag? 1 : 0 ); |
---|
553 | } |
---|
554 | |
---|
555 | return; |
---|
556 | } |
---|
557 | } |
---|
558 | } |
---|
559 | #else |
---|
560 | Void TEncCavlc::codePartSize( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth ) |
---|
561 | { |
---|
562 | PartSize eSize = pcCU->getPartitionSize( uiAbsPartIdx ); |
---|
563 | |
---|
564 | if ( pcCU->getSlice()->isInterB() && pcCU->isIntra( uiAbsPartIdx ) ) |
---|
565 | { |
---|
566 | xWriteFlag( 0 ); |
---|
567 | #if HHI_RMP_SWITCH |
---|
568 | if( pcCU->getSlice()->getSPS()->getUseRMP() ) |
---|
569 | #endif |
---|
570 | { |
---|
571 | xWriteFlag( 0 ); |
---|
572 | xWriteFlag( 0 ); |
---|
573 | } |
---|
574 | #if HHI_DISABLE_INTER_NxN_SPLIT |
---|
575 | if( uiDepth == g_uiMaxCUDepth - g_uiAddCUDepth ) |
---|
576 | { |
---|
577 | xWriteFlag( 0 ); |
---|
578 | } |
---|
579 | #else |
---|
580 | xWriteFlag( 0 ); |
---|
581 | #endif |
---|
582 | #if MTK_DISABLE_INTRA_NxN_SPLIT |
---|
583 | if( uiDepth == g_uiMaxCUDepth - g_uiAddCUDepth ) |
---|
584 | #endif |
---|
585 | { |
---|
586 | xWriteFlag( (eSize == SIZE_2Nx2N? 0 : 1) ); |
---|
587 | } |
---|
588 | return; |
---|
589 | } |
---|
590 | |
---|
591 | if ( pcCU->isIntra( uiAbsPartIdx ) ) |
---|
592 | { |
---|
593 | #if MTK_DISABLE_INTRA_NxN_SPLIT |
---|
594 | if( uiDepth == g_uiMaxCUDepth - g_uiAddCUDepth ) |
---|
595 | #endif |
---|
596 | { |
---|
597 | xWriteFlag( eSize == SIZE_2Nx2N? 1 : 0 ); |
---|
598 | } |
---|
599 | return; |
---|
600 | } |
---|
601 | |
---|
602 | switch(eSize) |
---|
603 | { |
---|
604 | case SIZE_2Nx2N: |
---|
605 | { |
---|
606 | xWriteFlag( 1 ); |
---|
607 | break; |
---|
608 | } |
---|
609 | case SIZE_2NxN: |
---|
610 | { |
---|
611 | xWriteFlag( 0 ); |
---|
612 | xWriteFlag( 1 ); |
---|
613 | break; |
---|
614 | } |
---|
615 | case SIZE_Nx2N: |
---|
616 | { |
---|
617 | xWriteFlag( 0 ); |
---|
618 | xWriteFlag( 0 ); |
---|
619 | xWriteFlag( 1 ); |
---|
620 | break; |
---|
621 | } |
---|
622 | case SIZE_NxN: |
---|
623 | { |
---|
624 | #if HHI_DISABLE_INTER_NxN_SPLIT |
---|
625 | if( uiDepth == g_uiMaxCUDepth - g_uiAddCUDepth ) |
---|
626 | #endif |
---|
627 | { |
---|
628 | xWriteFlag( 0 ); |
---|
629 | #if HHI_RMP_SWITCH |
---|
630 | if( pcCU->getSlice()->getSPS()->getUseRMP()) |
---|
631 | #endif |
---|
632 | { |
---|
633 | xWriteFlag( 0 ); |
---|
634 | xWriteFlag( 0 ); |
---|
635 | } |
---|
636 | if (pcCU->getSlice()->isInterB()) |
---|
637 | { |
---|
638 | xWriteFlag( 1 ); |
---|
639 | } |
---|
640 | } |
---|
641 | break; |
---|
642 | } |
---|
643 | default: |
---|
644 | { |
---|
645 | assert(0); |
---|
646 | } |
---|
647 | } |
---|
648 | } |
---|
649 | #endif |
---|
650 | |
---|
651 | /** code prediction mode |
---|
652 | * \param pcCU |
---|
653 | * \param uiAbsPartIdx |
---|
654 | * \returns Void |
---|
655 | */ |
---|
656 | Void TEncCavlc::codePredMode( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
657 | { |
---|
658 | #if QC_LCEC_INTER_MODE |
---|
659 | codeInterModeFlag(pcCU, uiAbsPartIdx,(UInt)pcCU->getDepth(uiAbsPartIdx),2); |
---|
660 | return; |
---|
661 | #else |
---|
662 | // get context function is here |
---|
663 | Int iPredMode = pcCU->getPredictionMode( uiAbsPartIdx ); |
---|
664 | if ( pcCU->getSlice()->isInterB() ) |
---|
665 | { |
---|
666 | return; |
---|
667 | } |
---|
668 | xWriteFlag( iPredMode == MODE_INTER ? 0 : 1 ); |
---|
669 | #endif |
---|
670 | } |
---|
671 | |
---|
672 | /** code merge flag |
---|
673 | * \param pcCU |
---|
674 | * \param uiAbsPartIdx |
---|
675 | * \returns Void |
---|
676 | */ |
---|
677 | Void TEncCavlc::codeMergeFlag ( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
678 | { |
---|
679 | #if QC_LCEC_INTER_MODE |
---|
680 | if (pcCU->getPartitionSize(uiAbsPartIdx) == SIZE_2Nx2N ) |
---|
681 | return; |
---|
682 | #endif |
---|
683 | UInt uiSymbol = pcCU->getMergeFlag( uiAbsPartIdx ) ? 1 : 0; |
---|
684 | xWriteFlag( uiSymbol ); |
---|
685 | } |
---|
686 | |
---|
687 | |
---|
688 | Void |
---|
689 | TEncCavlc::codeMergeIndexMV( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
690 | { |
---|
691 | UInt uiNumCand = 0; |
---|
692 | UInt uiMergeIdx = pcCU->getMergeIndex( uiAbsPartIdx ); |
---|
693 | #if MW_MVI_SIGNALLING_MODE == 1 |
---|
694 | const Bool bMVIAvailable = pcCU->getSlice()->getSPS()->getUseMVI() && pcCU->getSlice()->getSliceType() != I_SLICE; |
---|
695 | const UInt uiMviMergePos = bMVIAvailable ? MVI_MERGE_POS : MRG_MAX_NUM_CANDS; |
---|
696 | if( bMVIAvailable ) |
---|
697 | { |
---|
698 | uiNumCand++; |
---|
699 | const Bool bUseMVI = pcCU->getTextureModeDepth( uiAbsPartIdx ) != -1; |
---|
700 | if( bUseMVI ) |
---|
701 | uiMergeIdx = MVI_MERGE_POS; |
---|
702 | else if( uiMergeIdx >= MVI_MERGE_POS ) |
---|
703 | uiMergeIdx++; |
---|
704 | } |
---|
705 | UInt uiUnaryIdx = uiMergeIdx; |
---|
706 | for( UInt uiIdx = 0; uiIdx < MRG_MAX_NUM_CANDS; uiIdx++ ) |
---|
707 | { |
---|
708 | if( uiIdx < uiMviMergePos ) |
---|
709 | { |
---|
710 | if( pcCU->getNeighbourCandIdx( uiIdx, uiAbsPartIdx ) == uiIdx + 1 ) |
---|
711 | { |
---|
712 | uiNumCand++; |
---|
713 | } |
---|
714 | else if( uiIdx < uiMergeIdx ) |
---|
715 | { |
---|
716 | uiUnaryIdx--; |
---|
717 | } |
---|
718 | } |
---|
719 | else if( uiIdx > uiMviMergePos ) |
---|
720 | { |
---|
721 | if( pcCU->getNeighbourCandIdx( uiIdx - 1, uiAbsPartIdx ) == uiIdx ) |
---|
722 | { |
---|
723 | uiNumCand++; |
---|
724 | } |
---|
725 | else if( uiIdx < uiMergeIdx ) |
---|
726 | { |
---|
727 | uiUnaryIdx--; |
---|
728 | } |
---|
729 | } |
---|
730 | } |
---|
731 | #else |
---|
732 | UInt uiUnaryIdx = uiMergeIdx; |
---|
733 | for( UInt uiIdx = 0; uiIdx < MRG_MAX_NUM_CANDS; uiIdx++ ) |
---|
734 | { |
---|
735 | if( pcCU->getNeighbourCandIdx( uiIdx, uiAbsPartIdx ) == uiIdx + 1 ) |
---|
736 | { |
---|
737 | uiNumCand++; |
---|
738 | } |
---|
739 | else if( uiIdx < uiMergeIdx ) |
---|
740 | { |
---|
741 | uiUnaryIdx--; |
---|
742 | } |
---|
743 | } |
---|
744 | #endif |
---|
745 | AOF( uiNumCand > 1 ); |
---|
746 | for( UInt ui = 0; ui < uiNumCand - 1; ui++ ) |
---|
747 | { |
---|
748 | const UInt uiSymbol = ( ui == uiUnaryIdx ? 0 : 1 ); |
---|
749 | xWriteFlag( uiSymbol ); |
---|
750 | if( uiSymbol == 0 ) |
---|
751 | { |
---|
752 | break; |
---|
753 | } |
---|
754 | } |
---|
755 | } |
---|
756 | |
---|
757 | |
---|
758 | |
---|
759 | /** code merge index |
---|
760 | * \param pcCU |
---|
761 | * \param uiAbsPartIdx |
---|
762 | * \returns Void |
---|
763 | */ |
---|
764 | Void TEncCavlc::codeMergeIndex ( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
765 | { |
---|
766 | #if MW_MVI_SIGNALLING_MODE == 1 |
---|
767 | if( ( pcCU->getSlice()->getSPS()->getViewId() > 0 && ( pcCU->getSlice()->getSPS()->getMultiviewMvPredMode() & PDM_USE_FOR_MERGE ) == PDM_USE_FOR_MERGE ) || |
---|
768 | ( pcCU->getSlice()->getSPS()->getUseMVI() && pcCU->getSlice()->getSliceType() != I_SLICE && pcCU->getPartitionSize( uiAbsPartIdx ) == SIZE_2Nx2N ) ) |
---|
769 | #else |
---|
770 | if( pcCU->getSlice()->getSPS()->getViewId() > 0 && ( pcCU->getSlice()->getSPS()->getMultiviewMvPredMode() & PDM_USE_FOR_MERGE ) == PDM_USE_FOR_MERGE ) |
---|
771 | #endif |
---|
772 | { |
---|
773 | codeMergeIndexMV( pcCU, uiAbsPartIdx ); |
---|
774 | return; |
---|
775 | } |
---|
776 | |
---|
777 | Bool bLeftInvolved = false; |
---|
778 | Bool bAboveInvolved = false; |
---|
779 | Bool bCollocatedInvolved = false; |
---|
780 | Bool bCornerInvolved = false; |
---|
781 | UInt uiNumCand = 0; |
---|
782 | for( UInt uiIter = 0; uiIter < MRG_MAX_NUM_CANDS; ++uiIter ) |
---|
783 | { |
---|
784 | if( pcCU->getNeighbourCandIdx( uiIter, uiAbsPartIdx ) == uiIter + 1 ) |
---|
785 | { |
---|
786 | uiNumCand++; |
---|
787 | if( uiIter == 0 ) |
---|
788 | { |
---|
789 | bLeftInvolved = true; |
---|
790 | } |
---|
791 | else if( uiIter == 1 ) |
---|
792 | { |
---|
793 | bAboveInvolved = true; |
---|
794 | } |
---|
795 | else if( uiIter == 2 ) |
---|
796 | { |
---|
797 | bCollocatedInvolved = true; |
---|
798 | } |
---|
799 | else if( uiIter == 3 ) |
---|
800 | { |
---|
801 | bCornerInvolved = true; |
---|
802 | } |
---|
803 | } |
---|
804 | } |
---|
805 | assert( uiNumCand > 1 ); |
---|
806 | UInt uiUnaryIdx = pcCU->getMergeIndex( uiAbsPartIdx ); |
---|
807 | if( !bCornerInvolved && uiUnaryIdx > 3 ) |
---|
808 | { |
---|
809 | --uiUnaryIdx; |
---|
810 | } |
---|
811 | if( !bCollocatedInvolved && uiUnaryIdx > 2 ) |
---|
812 | { |
---|
813 | --uiUnaryIdx; |
---|
814 | } |
---|
815 | if( !bAboveInvolved && uiUnaryIdx > 1 ) |
---|
816 | { |
---|
817 | --uiUnaryIdx; |
---|
818 | } |
---|
819 | if( !bLeftInvolved && uiUnaryIdx > 0 ) |
---|
820 | { |
---|
821 | --uiUnaryIdx; |
---|
822 | } |
---|
823 | for( UInt ui = 0; ui < uiNumCand - 1; ++ui ) |
---|
824 | { |
---|
825 | const UInt uiSymbol = ui == uiUnaryIdx ? 0 : 1; |
---|
826 | xWriteFlag( uiSymbol ); |
---|
827 | if( uiSymbol == 0 ) |
---|
828 | { |
---|
829 | break; |
---|
830 | } |
---|
831 | } |
---|
832 | } |
---|
833 | |
---|
834 | |
---|
835 | Void |
---|
836 | TEncCavlc::codeResPredFlag( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
837 | { |
---|
838 | UInt uiSymbol = ( pcCU->getResPredFlag( uiAbsPartIdx ) ? 1 : 0 ); |
---|
839 | xWriteFlag( uiSymbol ); |
---|
840 | } |
---|
841 | |
---|
842 | |
---|
843 | Void TEncCavlc::codeAlfCtrlFlag( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
844 | { |
---|
845 | if (!m_bAlfCtrl) |
---|
846 | return; |
---|
847 | |
---|
848 | if( pcCU->getDepth(uiAbsPartIdx) > m_uiMaxAlfCtrlDepth && !pcCU->isFirstAbsZorderIdxInDepth(uiAbsPartIdx, m_uiMaxAlfCtrlDepth)) |
---|
849 | { |
---|
850 | return; |
---|
851 | } |
---|
852 | |
---|
853 | // get context function is here |
---|
854 | UInt uiSymbol = pcCU->getAlfCtrlFlag( uiAbsPartIdx ) ? 1 : 0; |
---|
855 | |
---|
856 | xWriteFlag( uiSymbol ); |
---|
857 | } |
---|
858 | |
---|
859 | Void TEncCavlc::codeAlfCtrlDepth() |
---|
860 | { |
---|
861 | if (!m_bAlfCtrl) |
---|
862 | return; |
---|
863 | |
---|
864 | UInt uiDepth = m_uiMaxAlfCtrlDepth; |
---|
865 | |
---|
866 | xWriteUnaryMaxSymbol(uiDepth, g_uiMaxCUDepth-1); |
---|
867 | } |
---|
868 | #if QC_LCEC_INTER_MODE |
---|
869 | Void TEncCavlc::codeInterModeFlag( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, UInt uiEncMode ) |
---|
870 | { |
---|
871 | Bool bHasSplit = ( uiDepth == g_uiMaxCUDepth - g_uiAddCUDepth )? 0 : 1; |
---|
872 | UInt uiSplitFlag = ( pcCU->getDepth( uiAbsPartIdx ) > uiDepth ) ? 1 : 0; |
---|
873 | UInt uiMode=0,uiControl=0; |
---|
874 | UInt uiTableDepth = uiDepth; |
---|
875 | if ( !bHasSplit ) |
---|
876 | { |
---|
877 | uiTableDepth = 3; |
---|
878 | } |
---|
879 | if(!uiSplitFlag || !bHasSplit) |
---|
880 | { |
---|
881 | uiMode = 1; |
---|
882 | uiControl = 1; |
---|
883 | if (!pcCU->isSkipped(uiAbsPartIdx )) |
---|
884 | { |
---|
885 | uiControl = 2; |
---|
886 | uiMode = 6; |
---|
887 | if (pcCU->getPredictionMode(uiAbsPartIdx) == MODE_INTER) |
---|
888 | { |
---|
889 | if(pcCU->getPartitionSize(uiAbsPartIdx) == SIZE_2Nx2N) |
---|
890 | uiMode=pcCU->getMergeFlag(uiAbsPartIdx) ? 2 : 3; |
---|
891 | else |
---|
892 | uiMode=3+(UInt)pcCU->getPartitionSize(uiAbsPartIdx); |
---|
893 | } |
---|
894 | } |
---|
895 | } |
---|
896 | if (uiEncMode != uiControl ) |
---|
897 | return; |
---|
898 | UInt uiEndSym = bHasSplit ? 7 : 6; |
---|
899 | uiDepth = uiTableDepth; |
---|
900 | UInt uiLength = m_uiSplitTableE[uiDepth][uiMode] + 1; |
---|
901 | if (uiLength == uiEndSym) |
---|
902 | { |
---|
903 | xWriteCode( 0, uiLength - 1); |
---|
904 | } |
---|
905 | else |
---|
906 | { |
---|
907 | xWriteCode( 1, uiLength ); |
---|
908 | } |
---|
909 | UInt x = uiMode; |
---|
910 | UInt cx = m_uiSplitTableE[uiDepth][x]; |
---|
911 | /* Adapt table */ |
---|
912 | if ( m_bAdaptFlag) |
---|
913 | { |
---|
914 | #if CAVLC_COUNTER_ADAPT |
---|
915 | adaptCodeword(cx, m_ucSplitTableCounter[uiDepth], m_ucSplitTableCounterSum[uiDepth], m_uiSplitTableD[uiDepth], m_uiSplitTableE[uiDepth], 4); |
---|
916 | #else |
---|
917 | if(cx>0) |
---|
918 | { |
---|
919 | UInt cy = Max(0,cx-1); |
---|
920 | UInt y = m_uiSplitTableD[uiDepth][cy]; |
---|
921 | m_uiSplitTableD[uiDepth][cy] = x; |
---|
922 | m_uiSplitTableD[uiDepth][cx] = y; |
---|
923 | m_uiSplitTableE[uiDepth][x] = cy; |
---|
924 | m_uiSplitTableE[uiDepth][y] = cx; |
---|
925 | } |
---|
926 | #endif |
---|
927 | } |
---|
928 | return; |
---|
929 | } |
---|
930 | #endif |
---|
931 | Void TEncCavlc::codeSkipFlag( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
932 | { |
---|
933 | #if QC_LCEC_INTER_MODE |
---|
934 | codeInterModeFlag(pcCU,uiAbsPartIdx,(UInt)pcCU->getDepth(uiAbsPartIdx),1); |
---|
935 | return; |
---|
936 | #else |
---|
937 | // get context function is here |
---|
938 | UInt uiSymbol = pcCU->isSkipped( uiAbsPartIdx ) ? 1 : 0; |
---|
939 | xWriteFlag( uiSymbol ); |
---|
940 | #endif |
---|
941 | } |
---|
942 | |
---|
943 | #if MW_MVI_SIGNALLING_MODE == 0 |
---|
944 | Void TEncCavlc::codeMvInheritanceFlag( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth ) |
---|
945 | { |
---|
946 | const Int iTextureModeDepth = pcCU->getTextureModeDepth( uiAbsPartIdx ); |
---|
947 | if( iTextureModeDepth != -1 && uiDepth > iTextureModeDepth ) |
---|
948 | return; |
---|
949 | UInt uiSymbol = iTextureModeDepth == uiDepth ? 1 : 0; |
---|
950 | xWriteFlag( uiSymbol ); |
---|
951 | } |
---|
952 | #endif |
---|
953 | |
---|
954 | Void TEncCavlc::codeSplitFlag ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth ) |
---|
955 | { |
---|
956 | if( uiDepth == g_uiMaxCUDepth - g_uiAddCUDepth ) |
---|
957 | return; |
---|
958 | #if QC_LCEC_INTER_MODE |
---|
959 | if (!pcCU->getSlice()->isIntra()) |
---|
960 | { |
---|
961 | codeInterModeFlag(pcCU,uiAbsPartIdx,uiDepth,0); |
---|
962 | return; |
---|
963 | } |
---|
964 | #endif |
---|
965 | UInt uiCurrSplitFlag = ( pcCU->getDepth( uiAbsPartIdx ) > uiDepth ) ? 1 : 0; |
---|
966 | |
---|
967 | xWriteFlag( uiCurrSplitFlag ); |
---|
968 | return; |
---|
969 | } |
---|
970 | |
---|
971 | Void TEncCavlc::codeTransformSubdivFlag( UInt uiSymbol, UInt uiCtx ) |
---|
972 | { |
---|
973 | xWriteFlag( uiSymbol ); |
---|
974 | } |
---|
975 | |
---|
976 | Void TEncCavlc::codeQtCbf( TComDataCU* pcCU, UInt uiAbsPartIdx, TextType eType, UInt uiTrDepth ) |
---|
977 | { |
---|
978 | UInt uiCbf = pcCU->getCbf( uiAbsPartIdx, eType, uiTrDepth ); |
---|
979 | xWriteFlag( uiCbf ); |
---|
980 | } |
---|
981 | |
---|
982 | Void TEncCavlc::codeQtRootCbf( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
983 | { |
---|
984 | UInt uiCbf = pcCU->getQtRootCbf( uiAbsPartIdx ); |
---|
985 | xWriteFlag( uiCbf ? 1 : 0 ); |
---|
986 | } |
---|
987 | |
---|
988 | #if LCEC_INTRA_MODE |
---|
989 | #if MTK_DCM_MPM |
---|
990 | Void TEncCavlc::codeIntraDirLumaAng( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
991 | { |
---|
992 | Int iDir = pcCU->getLumaIntraDir( uiAbsPartIdx ); |
---|
993 | Int iIntraIdx = pcCU->getIntraSizeIdx(uiAbsPartIdx); |
---|
994 | #if ADD_PLANAR_MODE |
---|
995 | UInt planarFlag = 0; |
---|
996 | if (iDir == PLANAR_IDX) |
---|
997 | { |
---|
998 | iDir = 2; |
---|
999 | planarFlag = 1; |
---|
1000 | } |
---|
1001 | #endif |
---|
1002 | |
---|
1003 | Int uiPreds[2] = {-1, -1}; |
---|
1004 | Int uiPredNum = pcCU->getIntraDirLumaPredictor(uiAbsPartIdx, uiPreds); |
---|
1005 | |
---|
1006 | Int uiPredIdx = -1; |
---|
1007 | |
---|
1008 | for(UInt i = 0; i < uiPredNum; i++) |
---|
1009 | { |
---|
1010 | if(iDir == uiPreds[i]) |
---|
1011 | { |
---|
1012 | uiPredIdx = i; |
---|
1013 | } |
---|
1014 | } |
---|
1015 | |
---|
1016 | if ( g_aucIntraModeBitsAng[iIntraIdx] < 5 ) |
---|
1017 | { |
---|
1018 | if(uiPredIdx != -1) |
---|
1019 | { |
---|
1020 | xWriteFlag(1); |
---|
1021 | if(uiPredNum == 2) |
---|
1022 | { |
---|
1023 | xWriteFlag((UInt)uiPredIdx); |
---|
1024 | } |
---|
1025 | } |
---|
1026 | else |
---|
1027 | { |
---|
1028 | xWriteFlag(0); |
---|
1029 | for(Int i = (uiPredNum - 1); i >= 0; i--) |
---|
1030 | { |
---|
1031 | iDir = iDir > uiPreds[i] ? iDir - 1 : iDir; |
---|
1032 | } |
---|
1033 | |
---|
1034 | |
---|
1035 | xWriteFlag( iDir & 0x01 ? 1 : 0 ); |
---|
1036 | if ( g_aucIntraModeBitsAng[iIntraIdx] > 2 ) { xWriteFlag( iDir & 0x02 ? 1 : 0 ); } |
---|
1037 | if ( g_aucIntraModeBitsAng[iIntraIdx] > 3 ) { xWriteFlag( iDir & 0x04 ? 1 : 0 ); } |
---|
1038 | } |
---|
1039 | |
---|
1040 | } |
---|
1041 | else |
---|
1042 | { |
---|
1043 | UInt uiCode, uiLength; |
---|
1044 | Int iRankIntraMode, iRankIntraModeLarger, iDirLarger; |
---|
1045 | |
---|
1046 | const UInt *huff; |
---|
1047 | const UInt *lengthHuff; |
---|
1048 | UInt *m_uiIntraModeTableD; |
---|
1049 | UInt *m_uiIntraModeTableE; |
---|
1050 | |
---|
1051 | if ( g_aucIntraModeBitsAng[iIntraIdx] == 5 ) |
---|
1052 | { |
---|
1053 | huff = huff17_2[uiPredNum - 1]; |
---|
1054 | lengthHuff = lengthHuff17_2[uiPredNum - 1]; |
---|
1055 | m_uiIntraModeTableD = m_uiIntraModeTableD17[uiPredNum - 1]; |
---|
1056 | m_uiIntraModeTableE = m_uiIntraModeTableE17[uiPredNum - 1]; |
---|
1057 | } |
---|
1058 | else |
---|
1059 | { |
---|
1060 | huff = huff34_2[uiPredNum - 1]; |
---|
1061 | lengthHuff = lengthHuff34_2[uiPredNum - 1]; |
---|
1062 | m_uiIntraModeTableD = m_uiIntraModeTableD34[uiPredNum - 1]; |
---|
1063 | m_uiIntraModeTableE = m_uiIntraModeTableE34[uiPredNum - 1]; |
---|
1064 | } |
---|
1065 | |
---|
1066 | if(uiPredIdx != -1) |
---|
1067 | { |
---|
1068 | uiCode=huff[0]; |
---|
1069 | uiLength=lengthHuff[0]; |
---|
1070 | xWriteCode(uiCode, uiLength); |
---|
1071 | |
---|
1072 | if(uiPredNum == 2) |
---|
1073 | { |
---|
1074 | xWriteFlag((UInt)uiPredIdx); |
---|
1075 | } |
---|
1076 | } |
---|
1077 | else |
---|
1078 | { |
---|
1079 | for(Int i = (uiPredNum - 1); i >= 0; i--) |
---|
1080 | { |
---|
1081 | iDir = iDir > uiPreds[i] ? iDir - 1 : iDir; |
---|
1082 | } |
---|
1083 | iRankIntraMode=m_uiIntraModeTableE[iDir]; |
---|
1084 | |
---|
1085 | uiCode=huff[iRankIntraMode+1]; |
---|
1086 | uiLength=lengthHuff[iRankIntraMode+1]; |
---|
1087 | |
---|
1088 | xWriteCode(uiCode, uiLength); |
---|
1089 | |
---|
1090 | if ( m_bAdaptFlag ) |
---|
1091 | { |
---|
1092 | iRankIntraModeLarger = Max(0,iRankIntraMode-1); |
---|
1093 | iDirLarger = m_uiIntraModeTableD[iRankIntraModeLarger]; |
---|
1094 | |
---|
1095 | m_uiIntraModeTableD[iRankIntraModeLarger] = iDir; |
---|
1096 | m_uiIntraModeTableD[iRankIntraMode] = iDirLarger; |
---|
1097 | m_uiIntraModeTableE[iDir] = iRankIntraModeLarger; |
---|
1098 | m_uiIntraModeTableE[iDirLarger] = iRankIntraMode; |
---|
1099 | } |
---|
1100 | } |
---|
1101 | } |
---|
1102 | #if ADD_PLANAR_MODE |
---|
1103 | iDir = pcCU->getLumaIntraDir( uiAbsPartIdx ); |
---|
1104 | if ( (iDir == PLANAR_IDX) || (iDir == 2) ) |
---|
1105 | { |
---|
1106 | xWriteFlag( planarFlag ); |
---|
1107 | } |
---|
1108 | #endif |
---|
1109 | } |
---|
1110 | #else |
---|
1111 | Void TEncCavlc::codeIntraDirLumaAng( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
1112 | { |
---|
1113 | Int iDir = pcCU->getLumaIntraDir( uiAbsPartIdx ); |
---|
1114 | Int iMostProbable = pcCU->getMostProbableIntraDirLuma( uiAbsPartIdx ); |
---|
1115 | Int iIntraIdx = pcCU->getIntraSizeIdx(uiAbsPartIdx); |
---|
1116 | UInt uiCode, uiLength; |
---|
1117 | Int iRankIntraMode, iRankIntraModeLarger, iDirLarger; |
---|
1118 | #if ADD_PLANAR_MODE |
---|
1119 | UInt planarFlag = 0; |
---|
1120 | if (iDir == PLANAR_IDX) |
---|
1121 | { |
---|
1122 | iDir = 2; |
---|
1123 | planarFlag = 1; |
---|
1124 | } |
---|
1125 | #endif |
---|
1126 | |
---|
1127 | UInt ind=(pcCU->getLeftIntraDirLuma( uiAbsPartIdx )==pcCU->getAboveIntraDirLuma( uiAbsPartIdx ))? 0 : 1; |
---|
1128 | |
---|
1129 | const UInt *huff17=huff17_2[ind]; |
---|
1130 | const UInt *lengthHuff17=lengthHuff17_2[ind]; |
---|
1131 | const UInt *huff34=huff34_2[ind]; |
---|
1132 | const UInt *lengthHuff34=lengthHuff34_2[ind]; |
---|
1133 | |
---|
1134 | if ( g_aucIntraModeBitsAng[iIntraIdx] < 5 ) |
---|
1135 | { |
---|
1136 | if (iDir == iMostProbable) |
---|
1137 | xWriteFlag( 1 ); |
---|
1138 | else{ |
---|
1139 | if (iDir>iMostProbable) |
---|
1140 | iDir--; |
---|
1141 | xWriteFlag( 0 ); |
---|
1142 | xWriteFlag( iDir & 0x01 ? 1 : 0 ); |
---|
1143 | if ( g_aucIntraModeBitsAng[iIntraIdx] > 2 ) xWriteFlag( iDir & 0x02 ? 1 : 0 ); |
---|
1144 | if ( g_aucIntraModeBitsAng[iIntraIdx] > 3 ) xWriteFlag( iDir & 0x04 ? 1 : 0 ); |
---|
1145 | } |
---|
1146 | } |
---|
1147 | else if ( g_aucIntraModeBitsAng[iIntraIdx] == 5 ) |
---|
1148 | { |
---|
1149 | |
---|
1150 | if (iDir==iMostProbable) |
---|
1151 | { |
---|
1152 | uiCode=huff17[0]; |
---|
1153 | uiLength=lengthHuff17[0]; |
---|
1154 | } |
---|
1155 | else |
---|
1156 | { |
---|
1157 | if (iDir>iMostProbable) |
---|
1158 | { |
---|
1159 | iDir--; |
---|
1160 | } |
---|
1161 | iRankIntraMode=m_uiIntraModeTableE17[iDir]; |
---|
1162 | |
---|
1163 | uiCode=huff17[iRankIntraMode+1]; |
---|
1164 | uiLength=lengthHuff17[iRankIntraMode+1]; |
---|
1165 | |
---|
1166 | if ( m_bAdaptFlag ) |
---|
1167 | { |
---|
1168 | iRankIntraModeLarger = Max(0,iRankIntraMode-1); |
---|
1169 | iDirLarger = m_uiIntraModeTableD17[iRankIntraModeLarger]; |
---|
1170 | |
---|
1171 | m_uiIntraModeTableD17[iRankIntraModeLarger] = iDir; |
---|
1172 | m_uiIntraModeTableD17[iRankIntraMode] = iDirLarger; |
---|
1173 | m_uiIntraModeTableE17[iDir] = iRankIntraModeLarger; |
---|
1174 | m_uiIntraModeTableE17[iDirLarger] = iRankIntraMode; |
---|
1175 | } |
---|
1176 | } |
---|
1177 | xWriteCode(uiCode, uiLength); |
---|
1178 | } |
---|
1179 | else{ |
---|
1180 | if (iDir==iMostProbable) |
---|
1181 | { |
---|
1182 | uiCode=huff34[0]; |
---|
1183 | uiLength=lengthHuff34[0]; |
---|
1184 | } |
---|
1185 | else{ |
---|
1186 | if (iDir>iMostProbable) |
---|
1187 | { |
---|
1188 | iDir--; |
---|
1189 | } |
---|
1190 | iRankIntraMode=m_uiIntraModeTableE34[iDir]; |
---|
1191 | |
---|
1192 | uiCode=huff34[iRankIntraMode+1]; |
---|
1193 | uiLength=lengthHuff34[iRankIntraMode+1]; |
---|
1194 | |
---|
1195 | if ( m_bAdaptFlag ) |
---|
1196 | { |
---|
1197 | iRankIntraModeLarger = Max(0,iRankIntraMode-1); |
---|
1198 | iDirLarger = m_uiIntraModeTableD34[iRankIntraModeLarger]; |
---|
1199 | |
---|
1200 | m_uiIntraModeTableD34[iRankIntraModeLarger] = iDir; |
---|
1201 | m_uiIntraModeTableD34[iRankIntraMode] = iDirLarger; |
---|
1202 | m_uiIntraModeTableE34[iDir] = iRankIntraModeLarger; |
---|
1203 | m_uiIntraModeTableE34[iDirLarger] = iRankIntraMode; |
---|
1204 | } |
---|
1205 | } |
---|
1206 | |
---|
1207 | xWriteCode(uiCode, uiLength); |
---|
1208 | } |
---|
1209 | |
---|
1210 | #if ADD_PLANAR_MODE |
---|
1211 | iDir = pcCU->getLumaIntraDir( uiAbsPartIdx ); |
---|
1212 | if ( (iDir == PLANAR_IDX) || (iDir == 2) ) |
---|
1213 | { |
---|
1214 | xWriteFlag( planarFlag ); |
---|
1215 | } |
---|
1216 | #endif |
---|
1217 | |
---|
1218 | } |
---|
1219 | #endif |
---|
1220 | #else |
---|
1221 | |
---|
1222 | Void TEncCavlc::codeIntraDirLumaAng( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
1223 | { |
---|
1224 | UInt uiDir = pcCU->getLumaIntraDir( uiAbsPartIdx ); |
---|
1225 | Int iMostProbable = pcCU->getMostProbableIntraDirLuma( uiAbsPartIdx ); |
---|
1226 | #if ADD_PLANAR_MODE |
---|
1227 | UInt planarFlag = 0; |
---|
1228 | if (uiDir == PLANAR_IDX) |
---|
1229 | { |
---|
1230 | uiDir = 2; |
---|
1231 | planarFlag = 1; |
---|
1232 | } |
---|
1233 | #endif |
---|
1234 | |
---|
1235 | if (uiDir == iMostProbable) |
---|
1236 | { |
---|
1237 | xWriteFlag( 1 ); |
---|
1238 | } |
---|
1239 | else |
---|
1240 | { |
---|
1241 | xWriteFlag( 0 ); |
---|
1242 | uiDir = uiDir > iMostProbable ? uiDir - 1 : uiDir; |
---|
1243 | Int iIntraIdx = pcCU->getIntraSizeIdx(uiAbsPartIdx); |
---|
1244 | if ( g_aucIntraModeBitsAng[iIntraIdx] < 6 ) |
---|
1245 | { |
---|
1246 | xWriteFlag( uiDir & 0x01 ? 1 : 0 ); |
---|
1247 | if ( g_aucIntraModeBitsAng[iIntraIdx] > 2 ) xWriteFlag( uiDir & 0x02 ? 1 : 0 ); |
---|
1248 | if ( g_aucIntraModeBitsAng[iIntraIdx] > 3 ) xWriteFlag( uiDir & 0x04 ? 1 : 0 ); |
---|
1249 | if ( g_aucIntraModeBitsAng[iIntraIdx] > 4 ) xWriteFlag( uiDir & 0x08 ? 1 : 0 ); |
---|
1250 | } |
---|
1251 | else |
---|
1252 | { |
---|
1253 | if (uiDir < 31) |
---|
1254 | { // 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 |
---|
1255 | xWriteFlag( uiDir & 0x01 ? 1 : 0 ); |
---|
1256 | xWriteFlag( uiDir & 0x02 ? 1 : 0 ); |
---|
1257 | xWriteFlag( uiDir & 0x04 ? 1 : 0 ); |
---|
1258 | xWriteFlag( uiDir & 0x08 ? 1 : 0 ); |
---|
1259 | xWriteFlag( uiDir & 0x10 ? 1 : 0 ); |
---|
1260 | } |
---|
1261 | else |
---|
1262 | { |
---|
1263 | xWriteFlag( 1 ); |
---|
1264 | xWriteFlag( 1 ); |
---|
1265 | xWriteFlag( 1 ); |
---|
1266 | xWriteFlag( 1 ); |
---|
1267 | xWriteFlag( 1 ); |
---|
1268 | xWriteFlag( uiDir == 32 ? 1 : 0 ); |
---|
1269 | } |
---|
1270 | } |
---|
1271 | } |
---|
1272 | |
---|
1273 | #if ADD_PLANAR_MODE |
---|
1274 | uiDir = pcCU->getLumaIntraDir( uiAbsPartIdx ); |
---|
1275 | if ( (uiDir == PLANAR_IDX) || (uiDir == 2) ) |
---|
1276 | { |
---|
1277 | xWriteFlag( planarFlag ); |
---|
1278 | } |
---|
1279 | #endif |
---|
1280 | |
---|
1281 | } |
---|
1282 | #endif |
---|
1283 | |
---|
1284 | Void TEncCavlc::codeIntraDirChroma( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
1285 | { |
---|
1286 | UInt uiIntraDirChroma = pcCU->getChromaIntraDir ( uiAbsPartIdx ); |
---|
1287 | #if ADD_PLANAR_MODE |
---|
1288 | UInt planarFlag = 0; |
---|
1289 | if (uiIntraDirChroma == PLANAR_IDX) |
---|
1290 | { |
---|
1291 | uiIntraDirChroma = 2; |
---|
1292 | planarFlag = 1; |
---|
1293 | } |
---|
1294 | #endif |
---|
1295 | |
---|
1296 | #if CHROMA_CODEWORD |
---|
1297 | UInt uiMode = pcCU->getLumaIntraDir(uiAbsPartIdx); |
---|
1298 | #if ADD_PLANAR_MODE |
---|
1299 | if ( (uiMode == 2 ) || (uiMode == PLANAR_IDX) ) |
---|
1300 | { |
---|
1301 | uiMode = 4; |
---|
1302 | } |
---|
1303 | #endif |
---|
1304 | #if LM_CHROMA |
---|
1305 | Bool bUseLMFlag = pcCU->getSlice()->getSPS()->getUseLMChroma(); |
---|
1306 | |
---|
1307 | Int iMaxMode = bUseLMFlag ? 3 : 4; |
---|
1308 | |
---|
1309 | Int iMax = uiMode < iMaxMode ? 3 : 4; |
---|
1310 | |
---|
1311 | //switch codeword |
---|
1312 | if (uiIntraDirChroma == 4) |
---|
1313 | { |
---|
1314 | uiIntraDirChroma = 0; |
---|
1315 | } |
---|
1316 | else if (uiIntraDirChroma == 3 && bUseLMFlag ) |
---|
1317 | { |
---|
1318 | uiIntraDirChroma = 1; |
---|
1319 | } |
---|
1320 | else |
---|
1321 | { |
---|
1322 | if (uiIntraDirChroma < uiMode) |
---|
1323 | uiIntraDirChroma++; |
---|
1324 | |
---|
1325 | if (bUseLMFlag) |
---|
1326 | uiIntraDirChroma++; |
---|
1327 | #if CHROMA_CODEWORD_SWITCH |
---|
1328 | uiIntraDirChroma = ChromaMapping[iMax-3][uiIntraDirChroma]; |
---|
1329 | #endif |
---|
1330 | } |
---|
1331 | |
---|
1332 | xWriteUnaryMaxSymbol( uiIntraDirChroma, iMax); |
---|
1333 | |
---|
1334 | #else //<--LM_CHROMA |
---|
1335 | Int iMax = uiMode < 4 ? 3 : 4; |
---|
1336 | |
---|
1337 | //switch codeword |
---|
1338 | if (uiIntraDirChroma == 4) |
---|
1339 | { |
---|
1340 | uiIntraDirChroma = 0; |
---|
1341 | } |
---|
1342 | #if CHROMA_CODEWORD_SWITCH |
---|
1343 | else |
---|
1344 | { |
---|
1345 | if (uiIntraDirChroma < uiMode) |
---|
1346 | { |
---|
1347 | uiIntraDirChroma++; |
---|
1348 | } |
---|
1349 | uiIntraDirChroma = ChromaMapping[iMax-3][uiIntraDirChroma]; |
---|
1350 | } |
---|
1351 | #else |
---|
1352 | else if (uiIntraDirChroma < uiMode) |
---|
1353 | { |
---|
1354 | uiIntraDirChroma++; |
---|
1355 | } |
---|
1356 | #endif |
---|
1357 | xWriteUnaryMaxSymbol( uiIntraDirChroma, iMax); |
---|
1358 | #endif //<-- LM_CHROMA |
---|
1359 | |
---|
1360 | #else // CHROMA_CODEWORD |
---|
1361 | if ( 0 == uiIntraDirChroma ) |
---|
1362 | { |
---|
1363 | xWriteFlag( 0 ); |
---|
1364 | } |
---|
1365 | else |
---|
1366 | { |
---|
1367 | xWriteFlag( 1 ); |
---|
1368 | xWriteUnaryMaxSymbol( uiIntraDirChroma - 1, 3 ); |
---|
1369 | } |
---|
1370 | #endif |
---|
1371 | |
---|
1372 | #if ADD_PLANAR_MODE |
---|
1373 | uiIntraDirChroma = pcCU->getChromaIntraDir( uiAbsPartIdx ); |
---|
1374 | #if CHROMA_CODEWORD |
---|
1375 | uiMode = pcCU->getLumaIntraDir(uiAbsPartIdx); |
---|
1376 | mapPlanartoDC( uiIntraDirChroma ); |
---|
1377 | mapPlanartoDC( uiMode ); |
---|
1378 | if ( (uiIntraDirChroma == 2) && (uiMode != 2) ) |
---|
1379 | #else |
---|
1380 | if ( (uiIntraDirChroma == PLANAR_IDX) || (uiIntraDirChroma == 2) ) |
---|
1381 | #endif |
---|
1382 | { |
---|
1383 | xWriteFlag( planarFlag ); |
---|
1384 | } |
---|
1385 | #endif |
---|
1386 | return; |
---|
1387 | } |
---|
1388 | |
---|
1389 | Void TEncCavlc::codeInterDir( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
1390 | { |
---|
1391 | UInt uiInterDir = pcCU->getInterDir ( uiAbsPartIdx ); |
---|
1392 | uiInterDir--; |
---|
1393 | |
---|
1394 | #if UNIFY_INTER_TABLE |
---|
1395 | #if DCM_COMB_LIST |
---|
1396 | UInt uiNumRefIdxOfLC = pcCU->getSlice()->getNumRefIdx(REF_PIC_LIST_C); |
---|
1397 | #endif |
---|
1398 | #define min(a, b) (((a) < (b)) ? (a) : (b)) |
---|
1399 | #if DCM_COMB_LIST |
---|
1400 | UInt uiValNumRefIdxOfLC = min(4,pcCU->getSlice()->getNumRefIdx(REF_PIC_LIST_C)); |
---|
1401 | #endif |
---|
1402 | UInt uiValNumRefIdxOfL0 = min(2,pcCU->getSlice()->getNumRefIdx(REF_PIC_LIST_0)); |
---|
1403 | UInt uiValNumRefIdxOfL1 = min(2,pcCU->getSlice()->getNumRefIdx(REF_PIC_LIST_1)); |
---|
1404 | |
---|
1405 | if ( pcCU->getSlice()->getRefIdxCombineCoding() ) |
---|
1406 | { |
---|
1407 | #if CAVLC_COUNTER_ADAPT |
---|
1408 | Int x,cx; |
---|
1409 | #else |
---|
1410 | Int x,cx,y,cy; |
---|
1411 | #endif |
---|
1412 | Int iRefFrame0,iRefFrame1; |
---|
1413 | UInt uiIndex = 0; |
---|
1414 | |
---|
1415 | UInt *m_uiMITableE; |
---|
1416 | UInt *m_uiMITableD; |
---|
1417 | |
---|
1418 | m_uiMITableE = m_uiMI1TableE; |
---|
1419 | m_uiMITableD = m_uiMI1TableD; |
---|
1420 | |
---|
1421 | UInt uiMaxVal; |
---|
1422 | #if DCM_COMB_LIST |
---|
1423 | if (uiNumRefIdxOfLC > 0) |
---|
1424 | { |
---|
1425 | uiMaxVal = uiValNumRefIdxOfLC + uiValNumRefIdxOfL0*uiValNumRefIdxOfL1; |
---|
1426 | } |
---|
1427 | else |
---|
1428 | #endif |
---|
1429 | if (m_pcSlice->getNoBackPredFlag()) |
---|
1430 | { |
---|
1431 | uiMaxVal = uiValNumRefIdxOfL0 + uiValNumRefIdxOfL0*uiValNumRefIdxOfL1; |
---|
1432 | } |
---|
1433 | else |
---|
1434 | { |
---|
1435 | uiMaxVal = uiValNumRefIdxOfL0 + uiValNumRefIdxOfL1 + uiValNumRefIdxOfL0*uiValNumRefIdxOfL1; |
---|
1436 | } |
---|
1437 | |
---|
1438 | if (uiInterDir==0) |
---|
1439 | { |
---|
1440 | #if DCM_COMB_LIST |
---|
1441 | if(uiNumRefIdxOfLC > 0) |
---|
1442 | { |
---|
1443 | iRefFrame0 = pcCU->getSlice()->getRefIdxOfLC(REF_PIC_LIST_0, pcCU->getCUMvField( REF_PIC_LIST_0 )->getRefIdx( uiAbsPartIdx )); |
---|
1444 | } |
---|
1445 | else |
---|
1446 | #endif |
---|
1447 | { |
---|
1448 | iRefFrame0 = pcCU->getCUMvField( REF_PIC_LIST_0 )->getRefIdx( uiAbsPartIdx ); |
---|
1449 | } |
---|
1450 | uiIndex = iRefFrame0; |
---|
1451 | #if DCM_COMB_LIST |
---|
1452 | if(uiNumRefIdxOfLC > 0) |
---|
1453 | { |
---|
1454 | if ( iRefFrame0 >= 4 ) |
---|
1455 | { |
---|
1456 | uiIndex = uiMaxVal; |
---|
1457 | } |
---|
1458 | } |
---|
1459 | else |
---|
1460 | #endif |
---|
1461 | { |
---|
1462 | if ( iRefFrame0 > 1 ) |
---|
1463 | { |
---|
1464 | uiIndex = uiMaxVal; |
---|
1465 | } |
---|
1466 | } |
---|
1467 | } |
---|
1468 | else if (uiInterDir==1) |
---|
1469 | { |
---|
1470 | #if DCM_COMB_LIST |
---|
1471 | if(uiNumRefIdxOfLC > 0) |
---|
1472 | { |
---|
1473 | iRefFrame1 = pcCU->getSlice()->getRefIdxOfLC(REF_PIC_LIST_1, pcCU->getCUMvField( REF_PIC_LIST_1 )->getRefIdx( uiAbsPartIdx )); |
---|
1474 | uiIndex = iRefFrame1; |
---|
1475 | } |
---|
1476 | else |
---|
1477 | #endif |
---|
1478 | { |
---|
1479 | iRefFrame1 = pcCU->getCUMvField( REF_PIC_LIST_1 )->getRefIdx( uiAbsPartIdx ); |
---|
1480 | uiIndex = uiValNumRefIdxOfL0 + iRefFrame1; |
---|
1481 | } |
---|
1482 | #if DCM_COMB_LIST |
---|
1483 | if(uiNumRefIdxOfLC > 0) |
---|
1484 | { |
---|
1485 | if ( iRefFrame1 >= 4 ) |
---|
1486 | { |
---|
1487 | uiIndex = uiMaxVal; |
---|
1488 | } |
---|
1489 | } |
---|
1490 | else |
---|
1491 | #endif |
---|
1492 | { |
---|
1493 | if ( iRefFrame1 > 1 ) |
---|
1494 | { |
---|
1495 | uiIndex = uiMaxVal; |
---|
1496 | } |
---|
1497 | } |
---|
1498 | } |
---|
1499 | else |
---|
1500 | { |
---|
1501 | iRefFrame0 = pcCU->getCUMvField( REF_PIC_LIST_0 )->getRefIdx( uiAbsPartIdx ); |
---|
1502 | iRefFrame1 = pcCU->getCUMvField( REF_PIC_LIST_1 )->getRefIdx( uiAbsPartIdx ); |
---|
1503 | if ( iRefFrame0 >= 2 || iRefFrame1 >= 2 ) |
---|
1504 | { |
---|
1505 | uiIndex = uiMaxVal; |
---|
1506 | } |
---|
1507 | else |
---|
1508 | { |
---|
1509 | #if DCM_COMB_LIST |
---|
1510 | if(uiNumRefIdxOfLC > 0) |
---|
1511 | { |
---|
1512 | uiIndex = uiValNumRefIdxOfLC + iRefFrame0*uiValNumRefIdxOfL1 + iRefFrame1; |
---|
1513 | } |
---|
1514 | else |
---|
1515 | #endif |
---|
1516 | if (m_pcSlice->getNoBackPredFlag()) |
---|
1517 | { |
---|
1518 | uiMaxVal = uiValNumRefIdxOfL0 + iRefFrame0*uiValNumRefIdxOfL1 + iRefFrame1; |
---|
1519 | } |
---|
1520 | else |
---|
1521 | { |
---|
1522 | uiIndex = uiValNumRefIdxOfL0 + uiValNumRefIdxOfL1 + iRefFrame0*uiValNumRefIdxOfL1 + iRefFrame1; |
---|
1523 | } |
---|
1524 | } |
---|
1525 | } |
---|
1526 | |
---|
1527 | x = uiIndex; |
---|
1528 | |
---|
1529 | cx = m_uiMITableE[x]; |
---|
1530 | |
---|
1531 | /* Adapt table */ |
---|
1532 | if ( m_bAdaptFlag ) |
---|
1533 | { |
---|
1534 | #if CAVLC_COUNTER_ADAPT |
---|
1535 | adaptCodeword(cx, m_ucMI1TableCounter, m_ucMI1TableCounterSum, m_uiMITableD, m_uiMITableE, 4); |
---|
1536 | #else |
---|
1537 | cy = Max(0,cx-1); |
---|
1538 | y = m_uiMITableD[cy]; |
---|
1539 | m_uiMITableD[cy] = x; |
---|
1540 | m_uiMITableD[cx] = y; |
---|
1541 | m_uiMITableE[x] = cy; |
---|
1542 | m_uiMITableE[y] = cx; |
---|
1543 | m_uiMITableVlcIdx += cx == m_uiMITableVlcIdx ? 0 : (cx < m_uiMITableVlcIdx ? -1 : 1); |
---|
1544 | #endif |
---|
1545 | } |
---|
1546 | |
---|
1547 | xWriteUnaryMaxSymbol( cx, uiMaxVal ); |
---|
1548 | |
---|
1549 | if ( x<uiMaxVal ) |
---|
1550 | { |
---|
1551 | return; |
---|
1552 | } |
---|
1553 | } |
---|
1554 | |
---|
1555 | #else //UNIFY_INTER_TABLE |
---|
1556 | #if MS_LCEC_LOOKUP_TABLE_EXCEPTION |
---|
1557 | if ( pcCU->getSlice()->getRefIdxCombineCoding() ) |
---|
1558 | #else |
---|
1559 | if(pcCU->getSlice()->getNumRefIdx( REF_PIC_LIST_0 ) <= 2 && pcCU->getSlice()->getNumRefIdx( REF_PIC_LIST_1 ) <= 2) |
---|
1560 | #endif |
---|
1561 | { |
---|
1562 | #if CAVLC_COUNTER_ADAPT |
---|
1563 | Int x,cx; |
---|
1564 | #else |
---|
1565 | Int x,cx,y,cy; |
---|
1566 | #endif |
---|
1567 | Int iRefFrame0,iRefFrame1; |
---|
1568 | UInt uiIndex; |
---|
1569 | |
---|
1570 | UInt *m_uiMITableE; |
---|
1571 | UInt *m_uiMITableD; |
---|
1572 | { |
---|
1573 | m_uiMITableE = m_uiMI1TableE; |
---|
1574 | m_uiMITableD = m_uiMI1TableD; |
---|
1575 | if (uiInterDir==0) |
---|
1576 | { |
---|
1577 | #if DCM_COMB_LIST |
---|
1578 | if(pcCU->getSlice()->getNumRefIdx(REF_PIC_LIST_C) > 0) |
---|
1579 | { |
---|
1580 | iRefFrame0 = pcCU->getSlice()->getRefIdxOfLC(REF_PIC_LIST_0, pcCU->getCUMvField( REF_PIC_LIST_0 )->getRefIdx( uiAbsPartIdx )); |
---|
1581 | } |
---|
1582 | else |
---|
1583 | { |
---|
1584 | iRefFrame0 = pcCU->getCUMvField( REF_PIC_LIST_0 )->getRefIdx( uiAbsPartIdx ); |
---|
1585 | } |
---|
1586 | #else |
---|
1587 | iRefFrame0 = pcCU->getCUMvField( REF_PIC_LIST_0 )->getRefIdx( uiAbsPartIdx ); |
---|
1588 | #endif |
---|
1589 | uiIndex = iRefFrame0; |
---|
1590 | |
---|
1591 | #if MS_LCEC_LOOKUP_TABLE_EXCEPTION |
---|
1592 | if(pcCU->getSlice()->getNumRefIdx(REF_PIC_LIST_C) > 0) |
---|
1593 | { |
---|
1594 | if ( iRefFrame0 >= 4 ) |
---|
1595 | { |
---|
1596 | uiIndex = 8; |
---|
1597 | } |
---|
1598 | } |
---|
1599 | else |
---|
1600 | { |
---|
1601 | if ( iRefFrame0 > MS_LCEC_UNI_EXCEPTION_THRES ) |
---|
1602 | { |
---|
1603 | uiIndex = 8; |
---|
1604 | } |
---|
1605 | } |
---|
1606 | #endif |
---|
1607 | } |
---|
1608 | else if (uiInterDir==1) |
---|
1609 | { |
---|
1610 | #if DCM_COMB_LIST |
---|
1611 | if(pcCU->getSlice()->getNumRefIdx(REF_PIC_LIST_C) > 0) |
---|
1612 | { |
---|
1613 | iRefFrame1 = pcCU->getSlice()->getRefIdxOfLC(REF_PIC_LIST_1, pcCU->getCUMvField( REF_PIC_LIST_1 )->getRefIdx( uiAbsPartIdx )); |
---|
1614 | uiIndex = iRefFrame1; |
---|
1615 | } |
---|
1616 | else |
---|
1617 | { |
---|
1618 | iRefFrame1 = pcCU->getCUMvField( REF_PIC_LIST_1 )->getRefIdx( uiAbsPartIdx ); |
---|
1619 | uiIndex = 2 + iRefFrame1; |
---|
1620 | } |
---|
1621 | #if MS_LCEC_LOOKUP_TABLE_EXCEPTION |
---|
1622 | if(pcCU->getSlice()->getNumRefIdx(REF_PIC_LIST_C) > 0) |
---|
1623 | { |
---|
1624 | if ( iRefFrame1 >= 4 ) |
---|
1625 | { |
---|
1626 | uiIndex = 8; |
---|
1627 | } |
---|
1628 | } |
---|
1629 | else |
---|
1630 | { |
---|
1631 | if ( iRefFrame1 > MS_LCEC_UNI_EXCEPTION_THRES ) |
---|
1632 | { |
---|
1633 | uiIndex = 8; |
---|
1634 | } |
---|
1635 | } |
---|
1636 | #endif |
---|
1637 | #else |
---|
1638 | iRefFrame1 = pcCU->getCUMvField( REF_PIC_LIST_1 )->getRefIdx( uiAbsPartIdx ); |
---|
1639 | uiIndex = 2 + iRefFrame1; |
---|
1640 | #endif |
---|
1641 | } |
---|
1642 | else |
---|
1643 | { |
---|
1644 | iRefFrame0 = pcCU->getCUMvField( REF_PIC_LIST_0 )->getRefIdx( uiAbsPartIdx ); |
---|
1645 | iRefFrame1 = pcCU->getCUMvField( REF_PIC_LIST_1 )->getRefIdx( uiAbsPartIdx ); |
---|
1646 | uiIndex = 4 + 2*iRefFrame0 + iRefFrame1; |
---|
1647 | #if MS_LCEC_LOOKUP_TABLE_EXCEPTION |
---|
1648 | if ( iRefFrame0 >= 2 || iRefFrame1 >= 2 ) |
---|
1649 | { |
---|
1650 | uiIndex = 8; |
---|
1651 | } |
---|
1652 | #endif |
---|
1653 | } |
---|
1654 | } |
---|
1655 | |
---|
1656 | x = uiIndex; |
---|
1657 | |
---|
1658 | cx = m_uiMITableE[x]; |
---|
1659 | |
---|
1660 | /* Adapt table */ |
---|
1661 | #if !MS_LCEC_LOOKUP_TABLE_MAX_VALUE |
---|
1662 | UInt vlcn = g_auiMITableVlcNum[m_uiMITableVlcIdx]; |
---|
1663 | #endif |
---|
1664 | if ( m_bAdaptFlag ) |
---|
1665 | { |
---|
1666 | #if CAVLC_COUNTER_ADAPT |
---|
1667 | adaptCodeword(cx, m_ucMI1TableCounter, m_ucMI1TableCounterSum, m_uiMITableD, m_uiMITableE, 4); |
---|
1668 | #else |
---|
1669 | cy = Max(0,cx-1); |
---|
1670 | y = m_uiMITableD[cy]; |
---|
1671 | m_uiMITableD[cy] = x; |
---|
1672 | m_uiMITableD[cx] = y; |
---|
1673 | m_uiMITableE[x] = cy; |
---|
1674 | m_uiMITableE[y] = cx; |
---|
1675 | m_uiMITableVlcIdx += cx == m_uiMITableVlcIdx ? 0 : (cx < m_uiMITableVlcIdx ? -1 : 1); |
---|
1676 | #endif |
---|
1677 | } |
---|
1678 | |
---|
1679 | { |
---|
1680 | #if MS_LCEC_LOOKUP_TABLE_MAX_VALUE |
---|
1681 | UInt uiMaxVal = 7; |
---|
1682 | #if MS_LCEC_LOOKUP_TABLE_EXCEPTION |
---|
1683 | uiMaxVal = 8; |
---|
1684 | #endif |
---|
1685 | if ( pcCU->getSlice()->getNumRefIdx( REF_PIC_LIST_0 ) <= 1 && pcCU->getSlice()->getNumRefIdx( REF_PIC_LIST_1 ) <= 1 ) |
---|
1686 | { |
---|
1687 | if ( pcCU->getSlice()->getNoBackPredFlag() || ( pcCU->getSlice()->getNumRefIdx(REF_PIC_LIST_C) > 0 && pcCU->getSlice()->getNumRefIdx(REF_PIC_LIST_C) <= 1 ) ) |
---|
1688 | { |
---|
1689 | uiMaxVal = 1; |
---|
1690 | } |
---|
1691 | else |
---|
1692 | { |
---|
1693 | uiMaxVal = 2; |
---|
1694 | } |
---|
1695 | } |
---|
1696 | else if ( pcCU->getSlice()->getNumRefIdx( REF_PIC_LIST_0 ) <= 2 && pcCU->getSlice()->getNumRefIdx( REF_PIC_LIST_1 ) <= 2 ) |
---|
1697 | { |
---|
1698 | if ( pcCU->getSlice()->getNoBackPredFlag() || ( pcCU->getSlice()->getNumRefIdx(REF_PIC_LIST_C) > 0 && pcCU->getSlice()->getNumRefIdx(REF_PIC_LIST_C) <= 2 ) ) |
---|
1699 | { |
---|
1700 | uiMaxVal = 5; |
---|
1701 | } |
---|
1702 | else |
---|
1703 | { |
---|
1704 | uiMaxVal = 7; |
---|
1705 | } |
---|
1706 | } |
---|
1707 | else if ( pcCU->getSlice()->getNumRefIdx(REF_PIC_LIST_C) <= 0 ) // GPB case |
---|
1708 | { |
---|
1709 | uiMaxVal = 4+1+MS_LCEC_UNI_EXCEPTION_THRES; |
---|
1710 | } |
---|
1711 | |
---|
1712 | xWriteUnaryMaxSymbol( cx, uiMaxVal ); |
---|
1713 | #else |
---|
1714 | xWriteVlc( vlcn, cx ); |
---|
1715 | #endif |
---|
1716 | } |
---|
1717 | |
---|
1718 | #if MS_LCEC_LOOKUP_TABLE_EXCEPTION |
---|
1719 | if ( x<8 ) |
---|
1720 | #endif |
---|
1721 | { |
---|
1722 | return; |
---|
1723 | } |
---|
1724 | } |
---|
1725 | #endif //UNIFY_INTER_TABLE |
---|
1726 | |
---|
1727 | xWriteFlag( ( uiInterDir == 2 ? 1 : 0 )); |
---|
1728 | if ( pcCU->getSlice()->getNoBackPredFlag() ) |
---|
1729 | { |
---|
1730 | assert( uiInterDir != 1 ); |
---|
1731 | return; |
---|
1732 | } |
---|
1733 | #if DCM_COMB_LIST |
---|
1734 | if ( uiInterDir < 2 && pcCU->getSlice()->getNumRefIdx(REF_PIC_LIST_C) <= 0) |
---|
1735 | #else |
---|
1736 | if ( uiInterDir < 2 ) |
---|
1737 | #endif |
---|
1738 | { |
---|
1739 | xWriteFlag( uiInterDir ); |
---|
1740 | } |
---|
1741 | |
---|
1742 | return; |
---|
1743 | } |
---|
1744 | |
---|
1745 | Void TEncCavlc::codeRefFrmIdx( TComDataCU* pcCU, UInt uiAbsPartIdx, RefPicList eRefList ) |
---|
1746 | { |
---|
1747 | #if DCM_COMB_LIST |
---|
1748 | Int iRefFrame; |
---|
1749 | RefPicList eRefListTemp; |
---|
1750 | |
---|
1751 | if( pcCU->getSlice()->getNumRefIdx(REF_PIC_LIST_C)>0) |
---|
1752 | { |
---|
1753 | if ( pcCU->getInterDir( uiAbsPartIdx ) != 3) |
---|
1754 | { |
---|
1755 | eRefListTemp = REF_PIC_LIST_C; |
---|
1756 | iRefFrame = pcCU->getSlice()->getRefIdxOfLC(eRefList, pcCU->getCUMvField( eRefList )->getRefIdx( uiAbsPartIdx )); |
---|
1757 | } |
---|
1758 | else |
---|
1759 | { |
---|
1760 | eRefListTemp = eRefList; |
---|
1761 | iRefFrame = pcCU->getCUMvField( eRefList )->getRefIdx( uiAbsPartIdx ); |
---|
1762 | } |
---|
1763 | } |
---|
1764 | else |
---|
1765 | { |
---|
1766 | eRefListTemp = eRefList; |
---|
1767 | iRefFrame = pcCU->getCUMvField( eRefList )->getRefIdx( uiAbsPartIdx ); |
---|
1768 | } |
---|
1769 | #else |
---|
1770 | Int iRefFrame = pcCU->getCUMvField( eRefList )->getRefIdx( uiAbsPartIdx ); |
---|
1771 | #endif |
---|
1772 | |
---|
1773 | if (pcCU->getSlice()->getNumRefIdx( REF_PIC_LIST_0 ) <= 2 && pcCU->getSlice()->getNumRefIdx( REF_PIC_LIST_1 ) <= 2 && pcCU->getSlice()->isInterB()) |
---|
1774 | { |
---|
1775 | return; |
---|
1776 | } |
---|
1777 | |
---|
1778 | #if MS_LCEC_LOOKUP_TABLE_EXCEPTION |
---|
1779 | if ( pcCU->getSlice()->getRefIdxCombineCoding() && pcCU->getInterDir(uiAbsPartIdx)==3 && |
---|
1780 | pcCU->getCUMvField( REF_PIC_LIST_0 )->getRefIdx( uiAbsPartIdx ) < 2 && |
---|
1781 | pcCU->getCUMvField( REF_PIC_LIST_1 )->getRefIdx( uiAbsPartIdx ) < 2 ) |
---|
1782 | { |
---|
1783 | return; |
---|
1784 | } |
---|
1785 | else if ( pcCU->getSlice()->getRefIdxCombineCoding() && pcCU->getInterDir(uiAbsPartIdx)==1 && |
---|
1786 | ( ( pcCU->getSlice()->getNumRefIdx(REF_PIC_LIST_C)>0 && pcCU->getSlice()->getRefIdxOfLC(REF_PIC_LIST_0, pcCU->getCUMvField( REF_PIC_LIST_0 )->getRefIdx( uiAbsPartIdx )) < 4 ) || |
---|
1787 | ( pcCU->getSlice()->getNumRefIdx(REF_PIC_LIST_C)<=0 && pcCU->getCUMvField( REF_PIC_LIST_0 )->getRefIdx( uiAbsPartIdx ) <= MS_LCEC_UNI_EXCEPTION_THRES ) ) ) |
---|
1788 | { |
---|
1789 | return; |
---|
1790 | } |
---|
1791 | else if ( pcCU->getSlice()->getRefIdxCombineCoding() && pcCU->getInterDir(uiAbsPartIdx)==2 && pcCU->getSlice()->getRefIdxOfLC(REF_PIC_LIST_1, pcCU->getCUMvField( REF_PIC_LIST_1 )->getRefIdx( uiAbsPartIdx )) < 4 ) |
---|
1792 | { |
---|
1793 | return; |
---|
1794 | } |
---|
1795 | |
---|
1796 | UInt uiRefFrmIdxMinus = 0; |
---|
1797 | if ( pcCU->getSlice()->getRefIdxCombineCoding() ) |
---|
1798 | { |
---|
1799 | if ( pcCU->getInterDir( uiAbsPartIdx ) != 3 ) |
---|
1800 | { |
---|
1801 | if ( pcCU->getSlice()->getNumRefIdx(REF_PIC_LIST_C) > 0 ) |
---|
1802 | { |
---|
1803 | uiRefFrmIdxMinus = 4; |
---|
1804 | assert( iRefFrame >=4 ); |
---|
1805 | } |
---|
1806 | else |
---|
1807 | { |
---|
1808 | uiRefFrmIdxMinus = MS_LCEC_UNI_EXCEPTION_THRES+1; |
---|
1809 | assert( iRefFrame > MS_LCEC_UNI_EXCEPTION_THRES ); |
---|
1810 | } |
---|
1811 | |
---|
1812 | } |
---|
1813 | else if ( eRefList == REF_PIC_LIST_1 && pcCU->getCUMvField( REF_PIC_LIST_0 )->getRefIdx( uiAbsPartIdx ) < 2 ) |
---|
1814 | { |
---|
1815 | uiRefFrmIdxMinus = 2; |
---|
1816 | assert( iRefFrame >= 2 ); |
---|
1817 | } |
---|
1818 | } |
---|
1819 | |
---|
1820 | if ( pcCU->getSlice()->getNumRefIdx( eRefListTemp ) - uiRefFrmIdxMinus <= 1 ) |
---|
1821 | { |
---|
1822 | return; |
---|
1823 | } |
---|
1824 | xWriteFlag( ( iRefFrame - uiRefFrmIdxMinus == 0 ? 0 : 1 ) ); |
---|
1825 | #else |
---|
1826 | xWriteFlag( ( iRefFrame == 0 ? 0 : 1 ) ); |
---|
1827 | #endif |
---|
1828 | |
---|
1829 | #if MS_LCEC_LOOKUP_TABLE_EXCEPTION |
---|
1830 | if ( iRefFrame - uiRefFrmIdxMinus > 0 ) |
---|
1831 | #else |
---|
1832 | if ( iRefFrame > 0 ) |
---|
1833 | #endif |
---|
1834 | { |
---|
1835 | { |
---|
1836 | #if DCM_COMB_LIST |
---|
1837 | #if MS_LCEC_LOOKUP_TABLE_EXCEPTION |
---|
1838 | xWriteUnaryMaxSymbol( iRefFrame - 1 - uiRefFrmIdxMinus, pcCU->getSlice()->getNumRefIdx( eRefListTemp )-2 - uiRefFrmIdxMinus ); |
---|
1839 | #else |
---|
1840 | xWriteUnaryMaxSymbol( iRefFrame - 1, pcCU->getSlice()->getNumRefIdx( eRefListTemp )-2 ); |
---|
1841 | #endif |
---|
1842 | #else |
---|
1843 | #if MS_LCEC_LOOKUP_TABLE_EXCEPTION |
---|
1844 | xWriteUnaryMaxSymbol( iRefFrame - 1 - uiRefFrmIdxMinus, pcCU->getSlice()->getNumRefIdx( eRefList )-2 - uiRefFrmIdxMinus ); |
---|
1845 | #else |
---|
1846 | xWriteUnaryMaxSymbol( iRefFrame - 1, pcCU->getSlice()->getNumRefIdx( eRefList )-2 ); |
---|
1847 | #endif |
---|
1848 | #endif |
---|
1849 | } |
---|
1850 | } |
---|
1851 | return; |
---|
1852 | } |
---|
1853 | |
---|
1854 | Void TEncCavlc::codeViewIdx(Int iViewIdx) |
---|
1855 | { |
---|
1856 | xWriteUnaryMaxSymbol(iViewIdx, MAX_NUMBER_VIEWS ); |
---|
1857 | } |
---|
1858 | |
---|
1859 | Void TEncCavlc::codeMvd( TComDataCU* pcCU, UInt uiAbsPartIdx, RefPicList eRefList ) |
---|
1860 | { |
---|
1861 | TComCUMvField* pcCUMvField = pcCU->getCUMvField( eRefList ); |
---|
1862 | Int iHor = pcCUMvField->getMvd( uiAbsPartIdx ).getHor(); |
---|
1863 | Int iVer = pcCUMvField->getMvd( uiAbsPartIdx ).getVer(); |
---|
1864 | |
---|
1865 | UInt uiAbsPartIdxL, uiAbsPartIdxA; |
---|
1866 | Int iHorPred, iVerPred; |
---|
1867 | |
---|
1868 | TComDataCU* pcCUL = pcCU->getPULeft ( uiAbsPartIdxL, pcCU->getZorderIdxInCU() + uiAbsPartIdx ); |
---|
1869 | TComDataCU* pcCUA = pcCU->getPUAbove( uiAbsPartIdxA, pcCU->getZorderIdxInCU() + uiAbsPartIdx ); |
---|
1870 | |
---|
1871 | TComCUMvField* pcCUMvFieldL = ( pcCUL == NULL || pcCUL->isIntra( uiAbsPartIdxL ) ) ? NULL : pcCUL->getCUMvField( eRefList ); |
---|
1872 | TComCUMvField* pcCUMvFieldA = ( pcCUA == NULL || pcCUA->isIntra( uiAbsPartIdxA ) ) ? NULL : pcCUA->getCUMvField( eRefList ); |
---|
1873 | iHorPred = ( (pcCUMvFieldL == NULL) ? 0 : pcCUMvFieldL->getMvd( uiAbsPartIdxL ).getAbsHor() ) + |
---|
1874 | ( (pcCUMvFieldA == NULL) ? 0 : pcCUMvFieldA->getMvd( uiAbsPartIdxA ).getAbsHor() ); |
---|
1875 | iVerPred = ( (pcCUMvFieldL == NULL) ? 0 : pcCUMvFieldL->getMvd( uiAbsPartIdxL ).getAbsVer() ) + |
---|
1876 | ( (pcCUMvFieldA == NULL) ? 0 : pcCUMvFieldA->getMvd( uiAbsPartIdxA ).getAbsVer() ); |
---|
1877 | |
---|
1878 | xWriteSvlc( iHor ); |
---|
1879 | xWriteSvlc( iVer ); |
---|
1880 | |
---|
1881 | return; |
---|
1882 | } |
---|
1883 | |
---|
1884 | Void TEncCavlc::codeDeltaQP( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
1885 | { |
---|
1886 | Int iDQp = pcCU->getQP( uiAbsPartIdx ) - pcCU->getSlice()->getSliceQp(); |
---|
1887 | |
---|
1888 | if ( iDQp == 0 ) |
---|
1889 | { |
---|
1890 | xWriteFlag( 0 ); |
---|
1891 | } |
---|
1892 | else |
---|
1893 | { |
---|
1894 | xWriteFlag( 1 ); |
---|
1895 | xWriteSvlc( iDQp ); |
---|
1896 | } |
---|
1897 | |
---|
1898 | return; |
---|
1899 | } |
---|
1900 | |
---|
1901 | #if CAVLC_RQT_CBP |
---|
1902 | /** Function for coding cbf and split flag |
---|
1903 | * \param pcCU pointer to CU |
---|
1904 | * \param uiAbsPartIdx CU index |
---|
1905 | * \param uiDepth CU Depth |
---|
1906 | * \returns |
---|
1907 | * This function performs coding of cbf and split flag |
---|
1908 | */ |
---|
1909 | Void TEncCavlc::codeCbfTrdiv( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth ) |
---|
1910 | { |
---|
1911 | UInt n,cx; |
---|
1912 | UInt uiTrDepth = uiDepth - pcCU->getDepth(uiAbsPartIdx); |
---|
1913 | UInt uiCBFY = pcCU->getCbf(uiAbsPartIdx, TEXT_LUMA, uiTrDepth); |
---|
1914 | UInt uiCBFU = pcCU->getCbf(uiAbsPartIdx, TEXT_CHROMA_U, uiTrDepth); |
---|
1915 | UInt uiCBFV = pcCU->getCbf(uiAbsPartIdx, TEXT_CHROMA_V, uiTrDepth); |
---|
1916 | UInt uiQPartNumParent = pcCU->getPic()->getNumPartInCU() >> ((uiDepth-1) << 1); |
---|
1917 | UInt uiQPartNumCurr = pcCU->getPic()->getNumPartInCU() >> ((uiDepth) << 1); |
---|
1918 | |
---|
1919 | const UInt uiSubdiv = pcCU->getTransformIdx( uiAbsPartIdx ) + pcCU->getDepth( uiAbsPartIdx ) > uiDepth; |
---|
1920 | UInt uiFlagPattern = xGetFlagPattern( pcCU, uiAbsPartIdx, uiDepth ); |
---|
1921 | n = pcCU->isIntra( uiAbsPartIdx ) ? 0 : 1; |
---|
1922 | |
---|
1923 | if(uiFlagPattern < 8) |
---|
1924 | { |
---|
1925 | UInt uiFullDepth = pcCU->getDepth(uiAbsPartIdx) + uiTrDepth; |
---|
1926 | UInt uiLog2TrSize = g_aucConvertToBit[ pcCU->getSlice()->getSPS()->getMaxCUWidth() >> uiFullDepth ] + 2; |
---|
1927 | if( uiLog2TrSize > pcCU->getSlice()->getSPS()->getQuadtreeTULog2MinSize() ) |
---|
1928 | { |
---|
1929 | UInt uiCBFU_Parent = pcCU->getCbf(uiAbsPartIdx, TEXT_CHROMA_U, uiTrDepth-1); |
---|
1930 | UInt uiCBFV_Parent = pcCU->getCbf(uiAbsPartIdx, TEXT_CHROMA_V, uiTrDepth-1); |
---|
1931 | if(uiCBFU_Parent) |
---|
1932 | { |
---|
1933 | xWriteFlag(uiCBFU); |
---|
1934 | } |
---|
1935 | if(uiCBFV_Parent) |
---|
1936 | { |
---|
1937 | xWriteFlag(uiCBFV); |
---|
1938 | } |
---|
1939 | } |
---|
1940 | |
---|
1941 | if(uiFlagPattern & 0x01) |
---|
1942 | { |
---|
1943 | codeTransformSubdivFlag( uiSubdiv, 0); |
---|
1944 | } |
---|
1945 | } |
---|
1946 | else |
---|
1947 | { |
---|
1948 | if(uiFlagPattern == 8) |
---|
1949 | { |
---|
1950 | if (uiAbsPartIdx % uiQPartNumParent ==0) |
---|
1951 | { |
---|
1952 | codeBlockCbf(pcCU, uiAbsPartIdx, TEXT_LUMA, uiTrDepth, uiQPartNumCurr); |
---|
1953 | } |
---|
1954 | } |
---|
1955 | else if(uiFlagPattern == 9) |
---|
1956 | { |
---|
1957 | bool bNeedToCode = true; |
---|
1958 | if ( n==1 && (uiAbsPartIdx%uiQPartNumParent) / uiQPartNumCurr == 3 ) |
---|
1959 | { |
---|
1960 | UInt uiTempAbsPartIdx = uiAbsPartIdx/uiQPartNumParent*uiQPartNumParent; |
---|
1961 | if ( pcCU->getCbf( uiTempAbsPartIdx + uiQPartNumCurr*0, TEXT_LUMA, uiTrDepth ) || |
---|
1962 | pcCU->getCbf( uiTempAbsPartIdx + uiQPartNumCurr*1, TEXT_LUMA, uiTrDepth ) || |
---|
1963 | pcCU->getCbf( uiTempAbsPartIdx + uiQPartNumCurr*2, TEXT_LUMA, uiTrDepth ) ) |
---|
1964 | { |
---|
1965 | bNeedToCode = true; |
---|
1966 | } |
---|
1967 | else |
---|
1968 | { |
---|
1969 | bNeedToCode = false; |
---|
1970 | xWriteFlag( uiSubdiv ); |
---|
1971 | } |
---|
1972 | } |
---|
1973 | if ( bNeedToCode ) |
---|
1974 | { |
---|
1975 | cx = m_uiCBP_YS_TableE[n][(uiCBFY<<1)+uiSubdiv]; |
---|
1976 | xWriteUnaryMaxSymbol(cx,n?2:3);//intra 3; inter 2 |
---|
1977 | |
---|
1978 | if ( m_bAdaptFlag ) |
---|
1979 | { |
---|
1980 | adaptCodeword(cx, m_ucCBP_YS_TableCounter[n], m_ucCBP_YS_TableCounterSum[n], m_uiCBP_YS_TableD[n], m_uiCBP_YS_TableE[n], 3); |
---|
1981 | } |
---|
1982 | } |
---|
1983 | } |
---|
1984 | else if( uiFlagPattern == 14) |
---|
1985 | { |
---|
1986 | UInt uiIdx = uiTrDepth? (2 + n) : n; |
---|
1987 | cx = m_uiCBP_YUV_TableE[uiIdx][(uiCBFV<<0) + (uiCBFU<<1) + (uiCBFY<<2)]; |
---|
1988 | xWriteUnaryMaxSymbol(cx,7); |
---|
1989 | |
---|
1990 | if ( m_bAdaptFlag ) |
---|
1991 | { |
---|
1992 | adaptCodeword(cx, m_ucCBP_YUV_TableCounter[uiIdx], m_ucCBP_YUV_TableCounterSum[uiIdx], m_uiCBP_YUV_TableD[uiIdx], m_uiCBP_YUV_TableE[uiIdx], 4); |
---|
1993 | } |
---|
1994 | } |
---|
1995 | else if ( uiFlagPattern == 11 || uiFlagPattern == 13 || uiFlagPattern == 15 ) |
---|
1996 | { |
---|
1997 | cx = m_uiCBP_YCS_TableE[n][(uiCBFY<<2)+((uiCBFU||uiCBFV?1:0)<<1)+uiSubdiv]; |
---|
1998 | xWriteCode(g_auiCBP_YCS_Table[n][cx], g_auiCBP_YCS_TableLen[n][cx]); |
---|
1999 | |
---|
2000 | if ( m_bAdaptFlag ) |
---|
2001 | { |
---|
2002 | adaptCodeword(cx, m_ucCBP_YCS_TableCounter[n], m_ucCBP_YCS_TableCounterSum[n], m_uiCBP_YCS_TableD[n], m_uiCBP_YCS_TableE[n], 4); |
---|
2003 | } |
---|
2004 | |
---|
2005 | //U and V |
---|
2006 | if ( uiFlagPattern == 15) |
---|
2007 | { |
---|
2008 | UInt uiCBFUV = (uiCBFU<<1) + uiCBFV; |
---|
2009 | if(uiCBFUV > 0) |
---|
2010 | { |
---|
2011 | xWriteUnaryMaxSymbol(n? (uiCBFUV - 1) : (3-uiCBFUV), 2); |
---|
2012 | } |
---|
2013 | } |
---|
2014 | } |
---|
2015 | else if (uiFlagPattern == 10 || uiFlagPattern == 12) |
---|
2016 | { |
---|
2017 | xWriteUnaryMaxSymbol(g_auiCBP_YC_TableE[n][(uiCBFY<<1)+(uiCBFU||uiCBFV?1:0)],3);//intra 3; inter 2 |
---|
2018 | } |
---|
2019 | } |
---|
2020 | return; |
---|
2021 | } |
---|
2022 | |
---|
2023 | |
---|
2024 | /** Function for parsing cbf and split |
---|
2025 | * \param pcCU pointer to CU |
---|
2026 | * \param uiAbsPartIdx CU index |
---|
2027 | * \param uiDepth CU Depth |
---|
2028 | * \returns flag pattern |
---|
2029 | * This function gets flagpattern for cbf and split flag |
---|
2030 | */ |
---|
2031 | UInt TEncCavlc::xGetFlagPattern( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth ) |
---|
2032 | { |
---|
2033 | const UInt uiLog2TrafoSize = g_aucConvertToBit[pcCU->getSlice()->getSPS()->getMaxCUWidth()]+2 - uiDepth; |
---|
2034 | UInt uiTrDepth = uiDepth - pcCU->getDepth( uiAbsPartIdx ); |
---|
2035 | UInt patternYUV, patternDiv; |
---|
2036 | UInt bY, bU, bV; |
---|
2037 | |
---|
2038 | UInt uiFullDepth = uiDepth; |
---|
2039 | UInt uiLog2TrSize = g_aucConvertToBit[ pcCU->getSlice()->getSPS()->getMaxCUWidth() >> uiFullDepth ] + 2; |
---|
2040 | if(uiTrDepth == 0) |
---|
2041 | { |
---|
2042 | patternYUV = 7; |
---|
2043 | } |
---|
2044 | else if( uiLog2TrSize > pcCU->getSlice()->getSPS()->getQuadtreeTULog2MinSize() ) |
---|
2045 | { |
---|
2046 | bY = pcCU->getCbf(uiAbsPartIdx, TEXT_LUMA, uiTrDepth - 1)?1:0; |
---|
2047 | bU = pcCU->getCbf(uiAbsPartIdx, TEXT_CHROMA_U, uiTrDepth - 1)?1:0; |
---|
2048 | bV = pcCU->getCbf(uiAbsPartIdx, TEXT_CHROMA_V, uiTrDepth - 1)?1:0; |
---|
2049 | patternYUV = (bY<<2) + (bU<<1) + bV; |
---|
2050 | } |
---|
2051 | else |
---|
2052 | { |
---|
2053 | bY = pcCU->getCbf(uiAbsPartIdx, TEXT_LUMA, uiTrDepth - 1)?1:0; |
---|
2054 | patternYUV = bY<<2; |
---|
2055 | } |
---|
2056 | |
---|
2057 | if( pcCU->getPredictionMode(uiAbsPartIdx) == MODE_INTRA && pcCU->getPartitionSize(uiAbsPartIdx) == SIZE_NxN && uiDepth == pcCU->getDepth(uiAbsPartIdx) ) |
---|
2058 | { |
---|
2059 | patternDiv = 0; |
---|
2060 | } |
---|
2061 | else if( uiLog2TrafoSize > pcCU->getSlice()->getSPS()->getQuadtreeTULog2MaxSize() ) |
---|
2062 | { |
---|
2063 | patternDiv = 0; |
---|
2064 | } |
---|
2065 | else if( uiLog2TrafoSize == pcCU->getSlice()->getSPS()->getQuadtreeTULog2MinSize() ) |
---|
2066 | { |
---|
2067 | patternDiv = 0; |
---|
2068 | } |
---|
2069 | else if( uiLog2TrafoSize == pcCU->getQuadtreeTULog2MinSizeInCU(uiAbsPartIdx) ) |
---|
2070 | { |
---|
2071 | patternDiv = 0; |
---|
2072 | } |
---|
2073 | else |
---|
2074 | { |
---|
2075 | patternDiv = 1; |
---|
2076 | } |
---|
2077 | return ((patternYUV<<1)+patternDiv); |
---|
2078 | } |
---|
2079 | #endif |
---|
2080 | |
---|
2081 | Void TEncCavlc::codeCbf( TComDataCU* pcCU, UInt uiAbsPartIdx, TextType eType, UInt uiTrDepth ) |
---|
2082 | { |
---|
2083 | if (eType == TEXT_ALL) |
---|
2084 | { |
---|
2085 | #if CAVLC_COUNTER_ADAPT |
---|
2086 | Int n,x,cx; |
---|
2087 | #else |
---|
2088 | Int n,x,cx,y,cy; |
---|
2089 | #endif |
---|
2090 | |
---|
2091 | UInt uiCBFY = pcCU->getCbf(uiAbsPartIdx, TEXT_LUMA, 0); |
---|
2092 | UInt uiCBFU = pcCU->getCbf(uiAbsPartIdx, TEXT_CHROMA_U, 0); |
---|
2093 | UInt uiCBFV = pcCU->getCbf(uiAbsPartIdx, TEXT_CHROMA_V, 0); |
---|
2094 | UInt uiCBP = (uiCBFV<<2) + (uiCBFU<<1) + (uiCBFY<<0); |
---|
2095 | |
---|
2096 | /* Start adaptation */ |
---|
2097 | n = pcCU->isIntra( uiAbsPartIdx ) ? 0 : 1; |
---|
2098 | x = uiCBP; |
---|
2099 | #if CAVLC_RQT_CBP |
---|
2100 | cx = m_uiCBP_YUV_TableE[n][x]; |
---|
2101 | UInt vlcn = 0; |
---|
2102 | #else |
---|
2103 | cx = m_uiCBPTableE[n][x]; |
---|
2104 | UInt vlcn = g_auiCbpVlcNum[n][m_uiCbpVlcIdx[n]]; |
---|
2105 | #endif |
---|
2106 | |
---|
2107 | if ( m_bAdaptFlag ) |
---|
2108 | { |
---|
2109 | #if CAVLC_COUNTER_ADAPT |
---|
2110 | #if CAVLC_RQT_CBP |
---|
2111 | adaptCodeword(cx, m_ucCBP_YUV_TableCounter[n], m_ucCBP_YUV_TableCounterSum[n], m_uiCBP_YUV_TableD[n], m_uiCBP_YUV_TableE[n], 4); |
---|
2112 | #else |
---|
2113 | adaptCodeword(cx, m_ucCBFTableCounter[n], m_ucCBFTableCounterSum[n], m_uiCBPTableD[n], m_uiCBPTableE[n], 4); |
---|
2114 | #endif |
---|
2115 | #else |
---|
2116 | cy = Max(0,cx-1); |
---|
2117 | y = m_uiCBPTableD[n][cy]; |
---|
2118 | m_uiCBPTableD[n][cy] = x; |
---|
2119 | m_uiCBPTableD[n][cx] = y; |
---|
2120 | m_uiCBPTableE[n][x] = cy; |
---|
2121 | m_uiCBPTableE[n][y] = cx; |
---|
2122 | m_uiCbpVlcIdx[n] += cx == m_uiCbpVlcIdx[n] ? 0 : (cx < m_uiCbpVlcIdx[n] ? -1 : 1); |
---|
2123 | #endif |
---|
2124 | } |
---|
2125 | xWriteVlc( vlcn, cx ); |
---|
2126 | } |
---|
2127 | } |
---|
2128 | |
---|
2129 | Void TEncCavlc::codeBlockCbf( TComDataCU* pcCU, UInt uiAbsPartIdx, TextType eType, UInt uiTrDepth, UInt uiQPartNum, Bool bRD ) |
---|
2130 | { |
---|
2131 | UInt uiCbf0 = pcCU->getCbf ( uiAbsPartIdx, eType, uiTrDepth ); |
---|
2132 | UInt uiCbf1 = pcCU->getCbf ( uiAbsPartIdx + uiQPartNum, eType, uiTrDepth ); |
---|
2133 | UInt uiCbf2 = pcCU->getCbf ( uiAbsPartIdx + uiQPartNum*2, eType, uiTrDepth ); |
---|
2134 | UInt uiCbf3 = pcCU->getCbf ( uiAbsPartIdx + uiQPartNum*3, eType, uiTrDepth ); |
---|
2135 | UInt uiCbf = (uiCbf0<<3) | (uiCbf1<<2) | (uiCbf2<<1) | uiCbf3; |
---|
2136 | |
---|
2137 | assert(uiTrDepth > 0); |
---|
2138 | |
---|
2139 | if(bRD && uiCbf==0) |
---|
2140 | { |
---|
2141 | xWriteCode(0, 4); |
---|
2142 | return; |
---|
2143 | } |
---|
2144 | |
---|
2145 | assert(uiCbf > 0); |
---|
2146 | |
---|
2147 | uiCbf --; |
---|
2148 | |
---|
2149 | #if CAVLC_COUNTER_ADAPT |
---|
2150 | Int x,cx; |
---|
2151 | #else |
---|
2152 | Int x,cx,y,cy; |
---|
2153 | #endif |
---|
2154 | |
---|
2155 | UInt n = (pcCU->isIntra(uiAbsPartIdx) && eType == TEXT_LUMA)? 0:1; |
---|
2156 | x = uiCbf; |
---|
2157 | |
---|
2158 | #if CAVLC_RQT_CBP |
---|
2159 | cx = m_uiCBP_4Y_TableE[n][uiCbf]; |
---|
2160 | UInt vlcn = (n==0)?g_auiCBP_4Y_VlcNum[m_uiCBP_4Y_VlcIdx]:11; |
---|
2161 | #else |
---|
2162 | cx = m_uiBlkCBPTableE[n][uiCbf]; |
---|
2163 | UInt vlcn = (n==0)?g_auiBlkCbpVlcNum[m_uiBlkCbpVlcIdx]:11; |
---|
2164 | #endif |
---|
2165 | |
---|
2166 | |
---|
2167 | if ( m_bAdaptFlag ) |
---|
2168 | { |
---|
2169 | |
---|
2170 | #if CAVLC_COUNTER_ADAPT |
---|
2171 | #if CAVLC_RQT_CBP |
---|
2172 | adaptCodeword(cx, m_ucCBP_4Y_TableCounter[n], m_ucCBP_4Y_TableCounterSum[n], m_uiCBP_4Y_TableD[n], m_uiCBP_4Y_TableE[n], 2); |
---|
2173 | #else |
---|
2174 | adaptCodeword(cx, m_ucBlkCBPTableCounter[n], m_ucBlkCBPTableCounterSum[n], m_uiBlkCBPTableD[n], m_uiBlkCBPTableE[n], 2); |
---|
2175 | #endif |
---|
2176 | #else |
---|
2177 | cy = Max(0,cx-1); |
---|
2178 | y = m_uiBlkCBPTableD[n][cy]; |
---|
2179 | m_uiBlkCBPTableD[n][cy] = x; |
---|
2180 | m_uiBlkCBPTableD[n][cx] = y; |
---|
2181 | m_uiBlkCBPTableE[n][x] = cy; |
---|
2182 | m_uiBlkCBPTableE[n][y] = cx; |
---|
2183 | #endif |
---|
2184 | |
---|
2185 | #if CAVLC_RQT_CBP |
---|
2186 | if(n==0) |
---|
2187 | m_uiCBP_4Y_VlcIdx += cx == m_uiCBP_4Y_VlcIdx ? 0 : (cx < m_uiCBP_4Y_VlcIdx ? -1 : 1); |
---|
2188 | #else |
---|
2189 | if(n==0) |
---|
2190 | m_uiBlkCbpVlcIdx += cx == m_uiBlkCbpVlcIdx ? 0 : (cx < m_uiBlkCbpVlcIdx ? -1 : 1); |
---|
2191 | #endif |
---|
2192 | } |
---|
2193 | |
---|
2194 | xWriteVlc( vlcn, cx ); |
---|
2195 | return; |
---|
2196 | } |
---|
2197 | |
---|
2198 | Void TEncCavlc::codeCoeffNxN ( TComDataCU* pcCU, TCoeff* pcCoef, UInt uiAbsPartIdx, UInt uiWidth, UInt uiHeight, UInt uiDepth, TextType eTType, Bool bRD ) |
---|
2199 | { |
---|
2200 | if ( uiWidth > m_pcSlice->getSPS()->getMaxTrSize() ) |
---|
2201 | { |
---|
2202 | uiWidth = m_pcSlice->getSPS()->getMaxTrSize(); |
---|
2203 | uiHeight = m_pcSlice->getSPS()->getMaxTrSize(); |
---|
2204 | } |
---|
2205 | UInt uiSize = uiWidth*uiHeight; |
---|
2206 | |
---|
2207 | // point to coefficient |
---|
2208 | TCoeff* piCoeff = pcCoef; |
---|
2209 | UInt uiNumSig = 0; |
---|
2210 | UInt uiScanning; |
---|
2211 | |
---|
2212 | // compute number of significant coefficients |
---|
2213 | UInt uiPart = 0; |
---|
2214 | xCheckCoeff(piCoeff, uiWidth, 0, uiNumSig, uiPart ); |
---|
2215 | |
---|
2216 | if ( bRD ) |
---|
2217 | { |
---|
2218 | UInt uiTempDepth = uiDepth - pcCU->getDepth( uiAbsPartIdx ); |
---|
2219 | pcCU->setCbfSubParts( ( uiNumSig ? 1 : 0 ) << uiTempDepth, eTType, uiAbsPartIdx, uiDepth ); |
---|
2220 | codeCbf( pcCU, uiAbsPartIdx, eTType, uiTempDepth ); |
---|
2221 | } |
---|
2222 | |
---|
2223 | if ( uiNumSig == 0 ) |
---|
2224 | { |
---|
2225 | return; |
---|
2226 | } |
---|
2227 | |
---|
2228 | // initialize scan |
---|
2229 | const UInt* pucScan; |
---|
2230 | |
---|
2231 | #if CAVLC_COEF_LRG_BLK |
---|
2232 | UInt maxBlSize = (eTType==TEXT_LUMA)?32:8; |
---|
2233 | UInt uiBlSize = Min(maxBlSize,uiWidth); |
---|
2234 | UInt uiConvBit = g_aucConvertToBit[ pcCU->isIntra( uiAbsPartIdx ) ? uiWidth :uiBlSize]; |
---|
2235 | UInt uiNoCoeff = uiBlSize*uiBlSize; |
---|
2236 | #else |
---|
2237 | //UInt uiConvBit = g_aucConvertToBit[ Min(8,uiWidth) ]; |
---|
2238 | UInt uiConvBit = g_aucConvertToBit[ pcCU->isIntra( uiAbsPartIdx ) ? uiWidth : Min(8,uiWidth) ]; |
---|
2239 | #endif |
---|
2240 | pucScan = g_auiFrameScanXY [ uiConvBit + 1 ]; |
---|
2241 | |
---|
2242 | #if QC_MDCS |
---|
2243 | UInt uiBlkPos; |
---|
2244 | #if CAVLC_COEF_LRG_BLK |
---|
2245 | UInt uiLog2BlkSize = g_aucConvertToBit[ pcCU->isIntra( uiAbsPartIdx ) ? uiWidth : uiBlSize] + 2; |
---|
2246 | #else |
---|
2247 | UInt uiLog2BlkSize = g_aucConvertToBit[ pcCU->isIntra( uiAbsPartIdx ) ? uiWidth : Min(8,uiWidth) ] + 2; |
---|
2248 | #endif |
---|
2249 | const UInt uiScanIdx = pcCU->getCoefScanIdx(uiAbsPartIdx, uiWidth, eTType==TEXT_LUMA, pcCU->isIntra(uiAbsPartIdx)); |
---|
2250 | #endif //QC_MDCS |
---|
2251 | |
---|
2252 | #if CAVLC_COEF_LRG_BLK |
---|
2253 | static TCoeff scoeff[1024]; |
---|
2254 | #else |
---|
2255 | TCoeff scoeff[64]; |
---|
2256 | #endif |
---|
2257 | Int iBlockType; |
---|
2258 | UInt uiCodeDCCoef = 0; |
---|
2259 | TCoeff dcCoeff = 0; |
---|
2260 | if (pcCU->isIntra(uiAbsPartIdx)) |
---|
2261 | { |
---|
2262 | UInt uiAbsPartIdxL, uiAbsPartIdxA; |
---|
2263 | TComDataCU* pcCUL = pcCU->getPULeft (uiAbsPartIdxL, pcCU->getZorderIdxInCU() + uiAbsPartIdx); |
---|
2264 | TComDataCU* pcCUA = pcCU->getPUAbove(uiAbsPartIdxA, pcCU->getZorderIdxInCU() + uiAbsPartIdx); |
---|
2265 | if (pcCUL == NULL && pcCUA == NULL) |
---|
2266 | { |
---|
2267 | uiCodeDCCoef = 1; |
---|
2268 | xWriteVlc((eTType == TEXT_LUMA ? 3 : 1) , abs(piCoeff[0])); |
---|
2269 | if (piCoeff[0] != 0) |
---|
2270 | { |
---|
2271 | UInt sign = (piCoeff[0] < 0) ? 1 : 0; |
---|
2272 | xWriteFlag(sign); |
---|
2273 | } |
---|
2274 | dcCoeff = piCoeff[0]; |
---|
2275 | piCoeff[0] = 1; |
---|
2276 | } |
---|
2277 | } |
---|
2278 | |
---|
2279 | if( uiSize == 2*2 ) |
---|
2280 | { |
---|
2281 | // hack: re-use 4x4 coding |
---|
2282 | ::memset( scoeff, 0, 16*sizeof(TCoeff) ); |
---|
2283 | for (uiScanning=0; uiScanning<4; uiScanning++) |
---|
2284 | { |
---|
2285 | #if QC_MDCS |
---|
2286 | uiBlkPos = g_auiSigLastScan[uiScanIdx][uiLog2BlkSize-1][uiScanning]; |
---|
2287 | scoeff[15-uiScanning] = piCoeff[ uiBlkPos ]; |
---|
2288 | #else |
---|
2289 | scoeff[15-uiScanning] = piCoeff[ pucScan[ uiScanning ] ]; |
---|
2290 | #endif //QC_MDCS |
---|
2291 | } |
---|
2292 | #if QC_MOD_LCEC |
---|
2293 | if (eTType==TEXT_CHROMA_U || eTType==TEXT_CHROMA_V) |
---|
2294 | iBlockType = eTType-2; |
---|
2295 | else |
---|
2296 | iBlockType = 2 + ( pcCU->isIntra(uiAbsPartIdx) ? 0 : pcCU->getSlice()->getSliceType() ); |
---|
2297 | #else |
---|
2298 | iBlockType = pcCU->isIntra(uiAbsPartIdx) ? 0 : pcCU->getSlice()->getSliceType(); |
---|
2299 | #endif |
---|
2300 | |
---|
2301 | #if CAVLC_COEF_LRG_BLK |
---|
2302 | xCodeCoeff( scoeff, iBlockType, 4 ); |
---|
2303 | #else |
---|
2304 | xCodeCoeff4x4( scoeff, iBlockType ); |
---|
2305 | #endif |
---|
2306 | } |
---|
2307 | else if ( uiSize == 4*4 ) |
---|
2308 | { |
---|
2309 | for (uiScanning=0; uiScanning<16; uiScanning++) |
---|
2310 | { |
---|
2311 | #if QC_MDCS |
---|
2312 | uiBlkPos = g_auiSigLastScan[uiScanIdx][uiLog2BlkSize-1][uiScanning]; |
---|
2313 | scoeff[15-uiScanning] = piCoeff[ uiBlkPos ]; |
---|
2314 | #else |
---|
2315 | scoeff[15-uiScanning] = piCoeff[ pucScan[ uiScanning ] ]; |
---|
2316 | #endif //QC_MDCS |
---|
2317 | } |
---|
2318 | #if QC_MOD_LCEC |
---|
2319 | if (eTType==TEXT_CHROMA_U || eTType==TEXT_CHROMA_V) |
---|
2320 | iBlockType = eTType-2; |
---|
2321 | else |
---|
2322 | iBlockType = 2 + ( pcCU->isIntra(uiAbsPartIdx) ? 0 : pcCU->getSlice()->getSliceType() ); |
---|
2323 | #else |
---|
2324 | iBlockType = pcCU->isIntra(uiAbsPartIdx) ? 0 : pcCU->getSlice()->getSliceType(); |
---|
2325 | #endif |
---|
2326 | |
---|
2327 | #if CAVLC_COEF_LRG_BLK |
---|
2328 | xCodeCoeff( scoeff, iBlockType, 4 ); |
---|
2329 | #else |
---|
2330 | xCodeCoeff4x4( scoeff, iBlockType ); |
---|
2331 | #endif |
---|
2332 | } |
---|
2333 | else if ( uiSize == 8*8 ) |
---|
2334 | { |
---|
2335 | for (uiScanning=0; uiScanning<64; uiScanning++) |
---|
2336 | { |
---|
2337 | #if QC_MDCS |
---|
2338 | uiBlkPos = g_auiSigLastScan[uiScanIdx][uiLog2BlkSize-1][uiScanning]; |
---|
2339 | scoeff[63-uiScanning] = piCoeff[ uiBlkPos ]; |
---|
2340 | #else |
---|
2341 | scoeff[63-uiScanning] = piCoeff[ pucScan[ uiScanning ] ]; |
---|
2342 | #endif //QC_MDCS |
---|
2343 | } |
---|
2344 | if (eTType==TEXT_CHROMA_U || eTType==TEXT_CHROMA_V) |
---|
2345 | iBlockType = eTType-2; |
---|
2346 | else |
---|
2347 | iBlockType = 2 + ( pcCU->isIntra(uiAbsPartIdx) ? 0 : pcCU->getSlice()->getSliceType() ); |
---|
2348 | |
---|
2349 | #if CAVLC_COEF_LRG_BLK |
---|
2350 | xCodeCoeff( scoeff, iBlockType, 8 ); |
---|
2351 | #else |
---|
2352 | xCodeCoeff8x8( scoeff, iBlockType ); |
---|
2353 | #endif |
---|
2354 | } |
---|
2355 | else |
---|
2356 | { |
---|
2357 | if(!pcCU->isIntra( uiAbsPartIdx )) |
---|
2358 | { |
---|
2359 | #if CAVLC_COEF_LRG_BLK |
---|
2360 | UInt uiBlSizeInBit = g_aucConvertToBit[uiBlSize] + 2; |
---|
2361 | UInt uiWidthInBit = g_aucConvertToBit[uiWidth] + 2; |
---|
2362 | for (uiScanning=0; uiScanning<uiNoCoeff; uiScanning++) |
---|
2363 | { |
---|
2364 | #if QC_MDCS |
---|
2365 | uiBlkPos = g_auiSigLastScan[uiScanIdx][uiLog2BlkSize-1][uiScanning]; |
---|
2366 | uiBlkPos = ((uiBlkPos>>uiBlSizeInBit) <<uiWidthInBit) + (uiBlkPos&(uiBlSize-1)); |
---|
2367 | scoeff[uiNoCoeff-uiScanning-1] = piCoeff[ uiBlkPos ]; |
---|
2368 | #else |
---|
2369 | scoeff[uiNoCoeff-uiScanning-1] = piCoeff[((pucScan[uiScanning]>>uiBlSizeInBit)<<uiWidthInBit) + (pucScan[uiScanning]&(uiBlSize-1))]; |
---|
2370 | #endif |
---|
2371 | } |
---|
2372 | #else |
---|
2373 | for (uiScanning=0; uiScanning<64; uiScanning++) |
---|
2374 | { |
---|
2375 | #if QC_MDCS |
---|
2376 | uiBlkPos = g_auiSigLastScan[uiScanIdx][uiLog2BlkSize-1][uiScanning]; |
---|
2377 | uiBlkPos = (uiBlkPos/8) * uiWidth + uiBlkPos%8; |
---|
2378 | scoeff[63-uiScanning] = piCoeff[ uiBlkPos ]; |
---|
2379 | #else |
---|
2380 | scoeff[63-uiScanning] = piCoeff[(pucScan[uiScanning]/8)*uiWidth + (pucScan[uiScanning]%8)]; |
---|
2381 | #endif //QC_MDCS |
---|
2382 | } |
---|
2383 | if (eTType==TEXT_CHROMA_U || eTType==TEXT_CHROMA_V) |
---|
2384 | iBlockType = eTType-2; |
---|
2385 | else |
---|
2386 | iBlockType = 5 + ( pcCU->isIntra(uiAbsPartIdx) ? 0 : pcCU->getSlice()->getSliceType() ); |
---|
2387 | xCodeCoeff8x8( scoeff, iBlockType ); |
---|
2388 | return; |
---|
2389 | #endif |
---|
2390 | } |
---|
2391 | |
---|
2392 | if(pcCU->isIntra( uiAbsPartIdx )) |
---|
2393 | { |
---|
2394 | #if CAVLC_COEF_LRG_BLK |
---|
2395 | for (uiScanning=0; uiScanning<uiNoCoeff; uiScanning++) |
---|
2396 | { |
---|
2397 | #if QC_MDCS |
---|
2398 | uiBlkPos = g_auiSigLastScan[uiScanIdx][uiLog2BlkSize-1][uiScanning]; |
---|
2399 | scoeff[uiNoCoeff-uiScanning-1] = piCoeff[ uiBlkPos ]; |
---|
2400 | #else |
---|
2401 | scoeff[uiNoCoeff-uiScanning-1] = piCoeff[ pucScan[ uiScanning ] ]; |
---|
2402 | #endif |
---|
2403 | } |
---|
2404 | #else |
---|
2405 | for (uiScanning=0; uiScanning<64; uiScanning++) |
---|
2406 | { |
---|
2407 | #if QC_MDCS |
---|
2408 | uiBlkPos = g_auiSigLastScan[uiScanIdx][uiLog2BlkSize-1][uiScanning]; |
---|
2409 | scoeff[63-uiScanning] = piCoeff[ uiBlkPos ]; |
---|
2410 | #else |
---|
2411 | scoeff[63-uiScanning] = piCoeff[ pucScan[ uiScanning ] ]; |
---|
2412 | #endif //QC_MDCS |
---|
2413 | } |
---|
2414 | |
---|
2415 | if (eTType==TEXT_CHROMA_U || eTType==TEXT_CHROMA_V) |
---|
2416 | iBlockType = eTType-2; |
---|
2417 | else |
---|
2418 | iBlockType = 5 + ( pcCU->isIntra(uiAbsPartIdx) ? 0 : pcCU->getSlice()->getSliceType() ); |
---|
2419 | xCodeCoeff8x8( scoeff, iBlockType ); |
---|
2420 | #endif |
---|
2421 | } |
---|
2422 | |
---|
2423 | #if CAVLC_COEF_LRG_BLK |
---|
2424 | if (eTType==TEXT_CHROMA_U || eTType==TEXT_CHROMA_V) |
---|
2425 | { |
---|
2426 | iBlockType = eTType-2; |
---|
2427 | } |
---|
2428 | else |
---|
2429 | { |
---|
2430 | iBlockType = 5 + ( pcCU->isIntra(uiAbsPartIdx) ? 0 : pcCU->getSlice()->getSliceType() ); |
---|
2431 | } |
---|
2432 | xCodeCoeff( scoeff, iBlockType, uiBlSize); |
---|
2433 | #endif |
---|
2434 | |
---|
2435 | //#endif |
---|
2436 | } |
---|
2437 | |
---|
2438 | if (uiCodeDCCoef == 1) |
---|
2439 | { |
---|
2440 | piCoeff[0] = dcCoeff; |
---|
2441 | } |
---|
2442 | } |
---|
2443 | |
---|
2444 | Void TEncCavlc::codeAlfFlag( UInt uiCode ) |
---|
2445 | { |
---|
2446 | |
---|
2447 | xWriteFlag( uiCode ); |
---|
2448 | } |
---|
2449 | |
---|
2450 | #if TSB_ALF_HEADER |
---|
2451 | Void TEncCavlc::codeAlfFlagNum( UInt uiCode, UInt minValue ) |
---|
2452 | { |
---|
2453 | UInt uiLength = 0; |
---|
2454 | UInt maxValue = (minValue << (this->getMaxAlfCtrlDepth()*2)); |
---|
2455 | assert((uiCode>=minValue)&&(uiCode<=maxValue)); |
---|
2456 | UInt temp = maxValue - minValue; |
---|
2457 | for(UInt i=0; i<32; i++) |
---|
2458 | { |
---|
2459 | if(temp&0x1) |
---|
2460 | { |
---|
2461 | uiLength = i+1; |
---|
2462 | } |
---|
2463 | temp = (temp >> 1); |
---|
2464 | } |
---|
2465 | if(uiLength) |
---|
2466 | { |
---|
2467 | xWriteCode( uiCode - minValue, uiLength ); |
---|
2468 | } |
---|
2469 | } |
---|
2470 | |
---|
2471 | Void TEncCavlc::codeAlfCtrlFlag( UInt uiSymbol ) |
---|
2472 | { |
---|
2473 | xWriteFlag( uiSymbol ); |
---|
2474 | } |
---|
2475 | #endif |
---|
2476 | |
---|
2477 | Void TEncCavlc::codeAlfUvlc( UInt uiCode ) |
---|
2478 | { |
---|
2479 | xWriteUvlc( uiCode ); |
---|
2480 | } |
---|
2481 | |
---|
2482 | Void TEncCavlc::codeAlfSvlc( Int iCode ) |
---|
2483 | { |
---|
2484 | xWriteSvlc( iCode ); |
---|
2485 | } |
---|
2486 | #if MTK_SAO |
---|
2487 | Void TEncCavlc::codeAoFlag( UInt uiCode ) |
---|
2488 | { |
---|
2489 | |
---|
2490 | xWriteFlag( uiCode ); |
---|
2491 | #if LCEC_STAT |
---|
2492 | if (m_bAdaptFlag) |
---|
2493 | m_uiBitAlfFlag += 1; |
---|
2494 | #endif |
---|
2495 | } |
---|
2496 | |
---|
2497 | Void TEncCavlc::codeAoUvlc( UInt uiCode ) |
---|
2498 | { |
---|
2499 | #if LCEC_STAT |
---|
2500 | if (m_bAdaptFlag) |
---|
2501 | m_uiBitAlfUvlc += xWriteUvlc( uiCode ); |
---|
2502 | else |
---|
2503 | #endif |
---|
2504 | xWriteUvlc( uiCode ); |
---|
2505 | } |
---|
2506 | |
---|
2507 | Void TEncCavlc::codeAoSvlc( Int iCode ) |
---|
2508 | { |
---|
2509 | #if LCEC_STAT |
---|
2510 | if (m_bAdaptFlag) |
---|
2511 | m_uiBitAlfSvlc += xWriteSvlc( iCode ); |
---|
2512 | else |
---|
2513 | #endif |
---|
2514 | xWriteSvlc( iCode ); |
---|
2515 | } |
---|
2516 | |
---|
2517 | #endif |
---|
2518 | |
---|
2519 | Void TEncCavlc::estBit( estBitsSbacStruct* pcEstBitsCabac, UInt uiCTXIdx, TextType eTType ) |
---|
2520 | { |
---|
2521 | // printf("error : no VLC mode support in this version\n"); |
---|
2522 | return; |
---|
2523 | } |
---|
2524 | |
---|
2525 | // ==================================================================================================================== |
---|
2526 | // Protected member functions |
---|
2527 | // ==================================================================================================================== |
---|
2528 | |
---|
2529 | Void TEncCavlc::xWriteCode ( UInt uiCode, UInt uiLength ) |
---|
2530 | { |
---|
2531 | assert ( uiLength > 0 ); |
---|
2532 | m_pcBitIf->write( uiCode, uiLength ); |
---|
2533 | } |
---|
2534 | |
---|
2535 | Void TEncCavlc::xWriteUvlc ( UInt uiCode ) |
---|
2536 | { |
---|
2537 | UInt uiLength = 1; |
---|
2538 | UInt uiTemp = ++uiCode; |
---|
2539 | |
---|
2540 | assert ( uiTemp ); |
---|
2541 | |
---|
2542 | while( 1 != uiTemp ) |
---|
2543 | { |
---|
2544 | uiTemp >>= 1; |
---|
2545 | uiLength += 2; |
---|
2546 | } |
---|
2547 | |
---|
2548 | m_pcBitIf->write( uiCode, uiLength ); |
---|
2549 | } |
---|
2550 | |
---|
2551 | Void TEncCavlc::xWriteSvlc ( Int iCode ) |
---|
2552 | { |
---|
2553 | UInt uiCode; |
---|
2554 | |
---|
2555 | uiCode = xConvertToUInt( iCode ); |
---|
2556 | xWriteUvlc( uiCode ); |
---|
2557 | } |
---|
2558 | |
---|
2559 | Void TEncCavlc::xWriteFlag( UInt uiCode ) |
---|
2560 | { |
---|
2561 | m_pcBitIf->write( uiCode, 1 ); |
---|
2562 | } |
---|
2563 | |
---|
2564 | Void TEncCavlc::xCheckCoeff( TCoeff* pcCoef, UInt uiSize, UInt uiDepth, UInt& uiNumofCoeff, UInt& uiPart ) |
---|
2565 | { |
---|
2566 | UInt ui = uiSize>>uiDepth; |
---|
2567 | if( uiPart == 0 ) |
---|
2568 | { |
---|
2569 | if( ui <= 4 ) |
---|
2570 | { |
---|
2571 | UInt x, y; |
---|
2572 | TCoeff* pCeoff = pcCoef; |
---|
2573 | for( y=0 ; y<ui ; y++ ) |
---|
2574 | { |
---|
2575 | for( x=0 ; x<ui ; x++ ) |
---|
2576 | { |
---|
2577 | if( pCeoff[x] != 0 ) |
---|
2578 | { |
---|
2579 | uiNumofCoeff++; |
---|
2580 | } |
---|
2581 | } |
---|
2582 | pCeoff += uiSize; |
---|
2583 | } |
---|
2584 | } |
---|
2585 | else |
---|
2586 | { |
---|
2587 | xCheckCoeff( pcCoef, uiSize, uiDepth+1, uiNumofCoeff, uiPart ); uiPart++; //1st Part |
---|
2588 | xCheckCoeff( pcCoef + (ui>>1), uiSize, uiDepth+1, uiNumofCoeff, uiPart ); uiPart++; //2nd Part |
---|
2589 | xCheckCoeff( pcCoef + (ui>>1)*uiSize, uiSize, uiDepth+1, uiNumofCoeff, uiPart ); uiPart++; //3rd Part |
---|
2590 | xCheckCoeff( pcCoef + (ui>>1)*uiSize + (ui>>1), uiSize, uiDepth+1, uiNumofCoeff, uiPart ); //4th Part |
---|
2591 | } |
---|
2592 | } |
---|
2593 | else |
---|
2594 | { |
---|
2595 | UInt x, y; |
---|
2596 | TCoeff* pCeoff = pcCoef; |
---|
2597 | for( y=0 ; y<ui ; y++ ) |
---|
2598 | { |
---|
2599 | for( x=0 ; x<ui ; x++ ) |
---|
2600 | { |
---|
2601 | if( pCeoff[x] != 0 ) |
---|
2602 | { |
---|
2603 | uiNumofCoeff++; |
---|
2604 | } |
---|
2605 | } |
---|
2606 | pCeoff += uiSize; |
---|
2607 | } |
---|
2608 | } |
---|
2609 | } |
---|
2610 | |
---|
2611 | Void TEncCavlc::xWriteUnaryMaxSymbol( UInt uiSymbol, UInt uiMaxSymbol ) |
---|
2612 | { |
---|
2613 | if (uiMaxSymbol == 0) |
---|
2614 | { |
---|
2615 | return; |
---|
2616 | } |
---|
2617 | xWriteFlag( uiSymbol ? 1 : 0 ); |
---|
2618 | if ( uiSymbol == 0 ) |
---|
2619 | { |
---|
2620 | return; |
---|
2621 | } |
---|
2622 | |
---|
2623 | Bool bCodeLast = ( uiMaxSymbol > uiSymbol ); |
---|
2624 | |
---|
2625 | while( --uiSymbol ) |
---|
2626 | { |
---|
2627 | xWriteFlag( 1 ); |
---|
2628 | } |
---|
2629 | if( bCodeLast ) |
---|
2630 | { |
---|
2631 | xWriteFlag( 0 ); |
---|
2632 | } |
---|
2633 | return; |
---|
2634 | } |
---|
2635 | |
---|
2636 | Void TEncCavlc::xWriteExGolombLevel( UInt uiSymbol ) |
---|
2637 | { |
---|
2638 | if( uiSymbol ) |
---|
2639 | { |
---|
2640 | xWriteFlag( 1 ); |
---|
2641 | UInt uiCount = 0; |
---|
2642 | Bool bNoExGo = (uiSymbol < 13); |
---|
2643 | |
---|
2644 | while( --uiSymbol && ++uiCount < 13 ) |
---|
2645 | { |
---|
2646 | xWriteFlag( 1 ); |
---|
2647 | } |
---|
2648 | if( bNoExGo ) |
---|
2649 | { |
---|
2650 | xWriteFlag( 0 ); |
---|
2651 | } |
---|
2652 | else |
---|
2653 | { |
---|
2654 | xWriteEpExGolomb( uiSymbol, 0 ); |
---|
2655 | } |
---|
2656 | } |
---|
2657 | else |
---|
2658 | { |
---|
2659 | xWriteFlag( 0 ); |
---|
2660 | } |
---|
2661 | return; |
---|
2662 | } |
---|
2663 | |
---|
2664 | Void TEncCavlc::xWriteEpExGolomb( UInt uiSymbol, UInt uiCount ) |
---|
2665 | { |
---|
2666 | while( uiSymbol >= (UInt)(1<<uiCount) ) |
---|
2667 | { |
---|
2668 | xWriteFlag( 1 ); |
---|
2669 | uiSymbol -= 1<<uiCount; |
---|
2670 | uiCount ++; |
---|
2671 | } |
---|
2672 | xWriteFlag( 0 ); |
---|
2673 | while( uiCount-- ) |
---|
2674 | { |
---|
2675 | xWriteFlag( (uiSymbol>>uiCount) & 1 ); |
---|
2676 | } |
---|
2677 | return; |
---|
2678 | } |
---|
2679 | |
---|
2680 | #if !QC_MOD_LCEC_RDOQ |
---|
2681 | UInt TEncCavlc::xLeadingZeros(UInt uiCode) |
---|
2682 | { |
---|
2683 | UInt uiCount = 0; |
---|
2684 | Int iDone = 0; |
---|
2685 | |
---|
2686 | if (uiCode) |
---|
2687 | { |
---|
2688 | while (!iDone) |
---|
2689 | { |
---|
2690 | uiCode >>= 1; |
---|
2691 | if (!uiCode) iDone = 1; |
---|
2692 | else uiCount++; |
---|
2693 | } |
---|
2694 | } |
---|
2695 | return uiCount; |
---|
2696 | } |
---|
2697 | #endif |
---|
2698 | |
---|
2699 | Void TEncCavlc::xWriteVlc(UInt uiTableNumber, UInt uiCodeNumber) |
---|
2700 | { |
---|
2701 | #if CAVLC_COEF_LRG_BLK |
---|
2702 | assert( uiTableNumber<=13 ); |
---|
2703 | #else |
---|
2704 | assert( uiTableNumber<=11 ); |
---|
2705 | #endif |
---|
2706 | |
---|
2707 | UInt uiTemp; |
---|
2708 | UInt uiLength = 0; |
---|
2709 | UInt uiCode = 0; |
---|
2710 | |
---|
2711 | if ( uiTableNumber < 5 ) |
---|
2712 | { |
---|
2713 | if ((Int)uiCodeNumber < (6 * (1 << uiTableNumber))) |
---|
2714 | { |
---|
2715 | uiTemp = 1<<uiTableNumber; |
---|
2716 | uiCode = uiTemp+uiCodeNumber%uiTemp; |
---|
2717 | uiLength = 1+uiTableNumber+(uiCodeNumber>>uiTableNumber); |
---|
2718 | } |
---|
2719 | else |
---|
2720 | { |
---|
2721 | uiCode = uiCodeNumber - (6 * (1 << uiTableNumber)) + (1 << uiTableNumber); |
---|
2722 | uiLength = (6-uiTableNumber)+1+2*xLeadingZeros(uiCode); |
---|
2723 | } |
---|
2724 | } |
---|
2725 | else if (uiTableNumber < 8) |
---|
2726 | { |
---|
2727 | uiTemp = 1<<(uiTableNumber-4); |
---|
2728 | uiCode = uiTemp+uiCodeNumber%uiTemp; |
---|
2729 | uiLength = 1+(uiTableNumber-4)+(uiCodeNumber>>(uiTableNumber-4)); |
---|
2730 | } |
---|
2731 | else if (uiTableNumber == 8) |
---|
2732 | { |
---|
2733 | assert( uiCodeNumber<=2 ); |
---|
2734 | if (uiCodeNumber == 0) |
---|
2735 | { |
---|
2736 | uiCode = 1; |
---|
2737 | uiLength = 1; |
---|
2738 | } |
---|
2739 | else if (uiCodeNumber == 1) |
---|
2740 | { |
---|
2741 | uiCode = 1; |
---|
2742 | uiLength = 2; |
---|
2743 | } |
---|
2744 | else if (uiCodeNumber == 2) |
---|
2745 | { |
---|
2746 | uiCode = 0; |
---|
2747 | uiLength = 2; |
---|
2748 | } |
---|
2749 | } |
---|
2750 | else if (uiTableNumber == 9) |
---|
2751 | { |
---|
2752 | if (uiCodeNumber == 0) |
---|
2753 | { |
---|
2754 | uiCode = 4; |
---|
2755 | uiLength = 3; |
---|
2756 | } |
---|
2757 | else if (uiCodeNumber == 1) |
---|
2758 | { |
---|
2759 | uiCode = 10; |
---|
2760 | uiLength = 4; |
---|
2761 | } |
---|
2762 | else if (uiCodeNumber == 2) |
---|
2763 | { |
---|
2764 | uiCode = 11; |
---|
2765 | uiLength = 4; |
---|
2766 | } |
---|
2767 | else if (uiCodeNumber < 11) |
---|
2768 | { |
---|
2769 | uiCode = uiCodeNumber+21; |
---|
2770 | uiLength = 5; |
---|
2771 | } |
---|
2772 | else |
---|
2773 | { |
---|
2774 | uiTemp = 1<<4; |
---|
2775 | uiCode = uiTemp+(uiCodeNumber+5)%uiTemp; |
---|
2776 | uiLength = 5+((uiCodeNumber+5)>>4); |
---|
2777 | } |
---|
2778 | } |
---|
2779 | else if (uiTableNumber == 10) |
---|
2780 | { |
---|
2781 | uiCode = uiCodeNumber+1; |
---|
2782 | uiLength = 1+2*xLeadingZeros(uiCode); |
---|
2783 | } |
---|
2784 | else if (uiTableNumber == 11) |
---|
2785 | { |
---|
2786 | if (uiCodeNumber == 0) |
---|
2787 | { |
---|
2788 | uiCode = 0; |
---|
2789 | uiLength = 3; |
---|
2790 | } |
---|
2791 | else |
---|
2792 | { |
---|
2793 | uiCode = uiCodeNumber + 1; |
---|
2794 | uiLength = 4; |
---|
2795 | } |
---|
2796 | } |
---|
2797 | #if CAVLC_COEF_LRG_BLK |
---|
2798 | else if (uiTableNumber == 12) |
---|
2799 | { |
---|
2800 | uiCode = 64+(uiCodeNumber&0x3f); |
---|
2801 | uiLength = 7+(uiCodeNumber>>6); |
---|
2802 | if (uiLength>32) |
---|
2803 | { |
---|
2804 | xWriteCode(0, uiLength-32); |
---|
2805 | uiLength = 32; |
---|
2806 | } |
---|
2807 | } |
---|
2808 | else if (uiTableNumber == 13) |
---|
2809 | { |
---|
2810 | uiTemp = 1<<4; |
---|
2811 | uiCode = uiTemp+(uiCodeNumber&0x0f); |
---|
2812 | uiLength = 5+(uiCodeNumber>>4); |
---|
2813 | } |
---|
2814 | #endif |
---|
2815 | |
---|
2816 | xWriteCode(uiCode, uiLength); |
---|
2817 | } |
---|
2818 | |
---|
2819 | #if CAVLC_COEF_LRG_BLK |
---|
2820 | /** Function for encoding a block of transform coeffcients in CAVLC. |
---|
2821 | * \param scoeff pointer to transform coefficient buffer |
---|
2822 | * \param n block type information, e.g. luma, chroma, intra, inter, etc. |
---|
2823 | * \param blSize block size |
---|
2824 | * \returns |
---|
2825 | * This function performs encoding for a block of transform coefficient in CAVLC. |
---|
2826 | */ |
---|
2827 | Void TEncCavlc::xCodeCoeff( TCoeff* scoeff, Int n, Int blSize) |
---|
2828 | { |
---|
2829 | static const int switch_thr[10] = {49,49,0,49,49,0,49,49,49,49}; |
---|
2830 | int i, noCoeff = blSize*blSize; |
---|
2831 | unsigned int cn; |
---|
2832 | int level,vlc,sign,done,last_pos,start; |
---|
2833 | int run_done,maxrun,run,lev; |
---|
2834 | int tmprun,vlc_adaptive=0; |
---|
2835 | static const int atable[5] = {4,6,14,28,0xfffffff}; |
---|
2836 | int sum_big_coef = 0; |
---|
2837 | Int tr1; |
---|
2838 | |
---|
2839 | /* Do the last coefficient first */ |
---|
2840 | i = 0; |
---|
2841 | done = 0; |
---|
2842 | while (!done && i < noCoeff) |
---|
2843 | { |
---|
2844 | if (scoeff[i]) |
---|
2845 | { |
---|
2846 | done = 1; |
---|
2847 | } |
---|
2848 | else |
---|
2849 | { |
---|
2850 | i++; |
---|
2851 | } |
---|
2852 | } |
---|
2853 | if (i == noCoeff) |
---|
2854 | { |
---|
2855 | return; |
---|
2856 | } |
---|
2857 | |
---|
2858 | last_pos = noCoeff-i-1; |
---|
2859 | level = abs(scoeff[i]); |
---|
2860 | lev = (level == 1) ? 0 : 1; |
---|
2861 | |
---|
2862 | if(blSize >= 8) |
---|
2863 | { |
---|
2864 | cn = xLastLevelInd(lev, last_pos, blSize); |
---|
2865 | // ADAPT_VLC_NUM |
---|
2866 | vlc = g_auiLastPosVlcNum[n][Min(16,m_uiLastPosVlcIndex[n])]; |
---|
2867 | xWriteVlc( vlc, cn ); |
---|
2868 | |
---|
2869 | if ( m_bAdaptFlag ){ |
---|
2870 | // ADAPT_VLC_NUM |
---|
2871 | cn = (blSize==8)? cn:(cn>>2); |
---|
2872 | m_uiLastPosVlcIndex[n] += cn == m_uiLastPosVlcIndex[n] ? 0 : (cn < m_uiLastPosVlcIndex[n] ? -1 : 1); |
---|
2873 | } |
---|
2874 | } |
---|
2875 | else |
---|
2876 | { |
---|
2877 | int x,y,cx,cy; |
---|
2878 | int nTab = max(0,n-2); |
---|
2879 | |
---|
2880 | x = (lev<<4) + last_pos; |
---|
2881 | cx = m_uiLPTableE4[nTab][x]; |
---|
2882 | xWriteVlc( 2, cx ); |
---|
2883 | |
---|
2884 | if ( m_bAdaptFlag ) |
---|
2885 | { |
---|
2886 | cy = Max( 0, cx-1 ); |
---|
2887 | y = m_uiLPTableD4[nTab][cy]; |
---|
2888 | m_uiLPTableD4[nTab][cy] = x; |
---|
2889 | m_uiLPTableD4[nTab][cx] = y; |
---|
2890 | m_uiLPTableE4[nTab][x] = cy; |
---|
2891 | m_uiLPTableE4[nTab][y] = cx; |
---|
2892 | } |
---|
2893 | } |
---|
2894 | |
---|
2895 | sign = (scoeff[i++] < 0) ? 1 : 0; |
---|
2896 | if (level > 1) |
---|
2897 | { |
---|
2898 | xWriteVlc( 0, ((level-2)<<1)+sign ); |
---|
2899 | tr1=0; |
---|
2900 | } |
---|
2901 | else |
---|
2902 | { |
---|
2903 | xWriteFlag( sign ); |
---|
2904 | tr1=1; |
---|
2905 | } |
---|
2906 | |
---|
2907 | if (i < noCoeff) |
---|
2908 | { |
---|
2909 | /* Go into run mode */ |
---|
2910 | run_done = 0; |
---|
2911 | const UInt *vlcTable = (n==2||n==5)? ((blSize<=8)? g_auiVlcTable8x8Intra:g_auiVlcTable16x16Intra): |
---|
2912 | ((blSize<=8)? g_auiVlcTable8x8Inter:g_auiVlcTable16x16Inter); |
---|
2913 | const UInt **pLumaRunTr1 = (blSize==4)? g_pLumaRunTr14x4:g_pLumaRunTr18x8; |
---|
2914 | while ( !run_done ) |
---|
2915 | { |
---|
2916 | maxrun = noCoeff-i-1; |
---|
2917 | tmprun = Min(maxrun, 28); |
---|
2918 | |
---|
2919 | vlc = vlcTable[tmprun]; |
---|
2920 | run = 0; |
---|
2921 | done = 0; |
---|
2922 | while (!done) |
---|
2923 | { |
---|
2924 | if (!scoeff[i]) |
---|
2925 | { |
---|
2926 | run++; |
---|
2927 | } |
---|
2928 | else |
---|
2929 | { |
---|
2930 | level = abs(scoeff[i]); |
---|
2931 | lev = (level == 1) ? 0 : 1; |
---|
2932 | |
---|
2933 | if(n == 2 || n == 5) |
---|
2934 | { |
---|
2935 | cn = xRunLevelInd(lev, run, maxrun, pLumaRunTr1[tr1][tmprun]); |
---|
2936 | } |
---|
2937 | else |
---|
2938 | { |
---|
2939 | cn = xRunLevelIndInter(lev, run, maxrun); |
---|
2940 | } |
---|
2941 | |
---|
2942 | xWriteVlc( vlc, cn ); |
---|
2943 | |
---|
2944 | if (tr1==0 || level>=2) |
---|
2945 | { |
---|
2946 | tr1=0; |
---|
2947 | } |
---|
2948 | else if (tr1 < MAX_TR1) |
---|
2949 | { |
---|
2950 | tr1++; |
---|
2951 | } |
---|
2952 | |
---|
2953 | sign = (scoeff[i] < 0) ? 1 : 0; |
---|
2954 | if (level > 1) |
---|
2955 | { |
---|
2956 | xWriteVlc( 0, ((level-2)<<1)+sign ); |
---|
2957 | |
---|
2958 | sum_big_coef += level; |
---|
2959 | if (blSize == 4 || i > switch_thr[n] || sum_big_coef > 2) |
---|
2960 | { |
---|
2961 | run_done = 1; |
---|
2962 | } |
---|
2963 | } |
---|
2964 | else |
---|
2965 | { |
---|
2966 | xWriteFlag( sign ); |
---|
2967 | } |
---|
2968 | run = 0; |
---|
2969 | done = 1; |
---|
2970 | } |
---|
2971 | if (i == (noCoeff-1)) |
---|
2972 | { |
---|
2973 | done = 1; |
---|
2974 | run_done = 1; |
---|
2975 | if (run) |
---|
2976 | { |
---|
2977 | if(n == 2 || n == 5) |
---|
2978 | { |
---|
2979 | cn = xRunLevelInd(0, run, maxrun, pLumaRunTr1[tr1][tmprun]); |
---|
2980 | } |
---|
2981 | else |
---|
2982 | { |
---|
2983 | cn = xRunLevelIndInter(0, run, maxrun); |
---|
2984 | } |
---|
2985 | |
---|
2986 | xWriteVlc( vlc, cn ); |
---|
2987 | } |
---|
2988 | } |
---|
2989 | i++; |
---|
2990 | } |
---|
2991 | } |
---|
2992 | } |
---|
2993 | |
---|
2994 | /* Code the rest in level mode */ |
---|
2995 | start = i; |
---|
2996 | for ( i=start; i<noCoeff; i++ ) |
---|
2997 | { |
---|
2998 | int tmp = abs(scoeff[i]); |
---|
2999 | |
---|
3000 | xWriteVlc( vlc_adaptive, tmp ); |
---|
3001 | if (scoeff[i]) |
---|
3002 | { |
---|
3003 | xWriteFlag( (scoeff[i] < 0) ? 1 : 0 ); |
---|
3004 | if (tmp > atable[vlc_adaptive]) |
---|
3005 | { |
---|
3006 | vlc_adaptive++; |
---|
3007 | } |
---|
3008 | } |
---|
3009 | } |
---|
3010 | |
---|
3011 | return; |
---|
3012 | } |
---|
3013 | |
---|
3014 | #else |
---|
3015 | Void TEncCavlc::xCodeCoeff4x4(TCoeff* scoeff, Int n ) |
---|
3016 | { |
---|
3017 | Int i; |
---|
3018 | UInt cn; |
---|
3019 | Int level,vlc,sign,done,last_pos,start; |
---|
3020 | Int run_done,maxrun,run,lev; |
---|
3021 | #if QC_MOD_LCEC |
---|
3022 | Int vlc_adaptive=0; |
---|
3023 | #else |
---|
3024 | Int tmprun, vlc_adaptive=0; |
---|
3025 | #endif |
---|
3026 | static const int atable[5] = {4,6,14,28,0xfffffff}; |
---|
3027 | Int tmp; |
---|
3028 | #if QC_MOD_LCEC |
---|
3029 | Int nTab = max(0,n-2); |
---|
3030 | Int tr1; |
---|
3031 | #endif |
---|
3032 | |
---|
3033 | /* Do the last coefficient first */ |
---|
3034 | i = 0; |
---|
3035 | done = 0; |
---|
3036 | |
---|
3037 | while (!done && i < 16) |
---|
3038 | { |
---|
3039 | if (scoeff[i]) |
---|
3040 | { |
---|
3041 | done = 1; |
---|
3042 | } |
---|
3043 | else |
---|
3044 | { |
---|
3045 | i++; |
---|
3046 | } |
---|
3047 | } |
---|
3048 | if (i == 16) |
---|
3049 | { |
---|
3050 | return; |
---|
3051 | } |
---|
3052 | |
---|
3053 | last_pos = 15-i; |
---|
3054 | level = abs(scoeff[i]); |
---|
3055 | lev = (level == 1) ? 0 : 1; |
---|
3056 | |
---|
3057 | #if QC_MOD_LCEC |
---|
3058 | if (level>1) |
---|
3059 | { |
---|
3060 | tr1=0; |
---|
3061 | } |
---|
3062 | else |
---|
3063 | { |
---|
3064 | tr1=1; |
---|
3065 | } |
---|
3066 | #endif |
---|
3067 | |
---|
3068 | { |
---|
3069 | int x,y,cx,cy,vlcNum; |
---|
3070 | int vlcTable[3] = {2,2,2}; |
---|
3071 | |
---|
3072 | x = 16*lev + last_pos; |
---|
3073 | |
---|
3074 | #if QC_MOD_LCEC |
---|
3075 | cx = m_uiLPTableE4[nTab][x]; |
---|
3076 | vlcNum = vlcTable[nTab]; |
---|
3077 | #else |
---|
3078 | cx = m_uiLPTableE4[n][x]; |
---|
3079 | vlcNum = vlcTable[n]; |
---|
3080 | #endif |
---|
3081 | |
---|
3082 | xWriteVlc( vlcNum, cx ); |
---|
3083 | |
---|
3084 | if ( m_bAdaptFlag ) |
---|
3085 | { |
---|
3086 | cy = Max( 0, cx-1 ); |
---|
3087 | #if QC_MOD_LCEC |
---|
3088 | y = m_uiLPTableD4[nTab][cy]; |
---|
3089 | m_uiLPTableD4[nTab][cy] = x; |
---|
3090 | m_uiLPTableD4[nTab][cx] = y; |
---|
3091 | m_uiLPTableE4[nTab][x] = cy; |
---|
3092 | m_uiLPTableE4[nTab][y] = cx; |
---|
3093 | #else |
---|
3094 | y = m_uiLPTableD4[n][cy]; |
---|
3095 | m_uiLPTableD4[n][cy] = x; |
---|
3096 | m_uiLPTableD4[n][cx] = y; |
---|
3097 | m_uiLPTableE4[n][x] = cy; |
---|
3098 | m_uiLPTableE4[n][y] = cx; |
---|
3099 | #endif |
---|
3100 | } |
---|
3101 | } |
---|
3102 | |
---|
3103 | sign = (scoeff[i] < 0) ? 1 : 0; |
---|
3104 | if (level > 1) |
---|
3105 | { |
---|
3106 | xWriteVlc( 0, 2*(level-2)+sign ); |
---|
3107 | } |
---|
3108 | else |
---|
3109 | { |
---|
3110 | xWriteFlag( sign ); |
---|
3111 | } |
---|
3112 | i++; |
---|
3113 | |
---|
3114 | if (i < 16) |
---|
3115 | { |
---|
3116 | /* Go into run mode */ |
---|
3117 | run_done = 0; |
---|
3118 | while (!run_done) |
---|
3119 | { |
---|
3120 | maxrun = 15-i; |
---|
3121 | #if QC_MOD_LCEC |
---|
3122 | if ( n == 2 ) |
---|
3123 | vlc = g_auiVlcTable8x8Intra[maxrun]; |
---|
3124 | else |
---|
3125 | vlc = g_auiVlcTable8x8Inter[maxrun]; |
---|
3126 | #else |
---|
3127 | tmprun = maxrun; |
---|
3128 | if (maxrun > 27) |
---|
3129 | { |
---|
3130 | vlc = 3; |
---|
3131 | tmprun = 28; |
---|
3132 | } |
---|
3133 | else |
---|
3134 | { |
---|
3135 | vlc = g_auiVlcTable8x8[maxrun]; |
---|
3136 | } |
---|
3137 | #endif |
---|
3138 | |
---|
3139 | run = 0; |
---|
3140 | done = 0; |
---|
3141 | while (!done) |
---|
3142 | { |
---|
3143 | if (!scoeff[i]) |
---|
3144 | { |
---|
3145 | run++; |
---|
3146 | } |
---|
3147 | else |
---|
3148 | { |
---|
3149 | level = abs(scoeff[i]); |
---|
3150 | lev = (level == 1) ? 0 : 1; |
---|
3151 | #if QC_MOD_LCEC |
---|
3152 | if ( n == 2 ){ |
---|
3153 | cn = xRunLevelInd(lev, run, maxrun, g_auiLumaRunTr14x4[tr1][maxrun]); |
---|
3154 | } |
---|
3155 | else{ |
---|
3156 | #if RUNLEVEL_TABLE_CUT |
---|
3157 | cn = xRunLevelIndInter(lev, run, maxrun); |
---|
3158 | #else |
---|
3159 | cn = g_auiLumaRun8x8[maxrun][lev][run]; |
---|
3160 | #endif |
---|
3161 | } |
---|
3162 | #else |
---|
3163 | if (maxrun > 27) |
---|
3164 | { |
---|
3165 | cn = g_auiLumaRun8x8[28][lev][run]; |
---|
3166 | } |
---|
3167 | else |
---|
3168 | { |
---|
3169 | cn = g_auiLumaRun8x8[maxrun][lev][run]; |
---|
3170 | } |
---|
3171 | #endif |
---|
3172 | xWriteVlc( vlc, cn ); |
---|
3173 | |
---|
3174 | #if QC_MOD_LCEC |
---|
3175 | if (tr1>0 && tr1 < MAX_TR1) |
---|
3176 | { |
---|
3177 | tr1++; |
---|
3178 | } |
---|
3179 | #endif |
---|
3180 | sign = (scoeff[i] < 0) ? 1 : 0; |
---|
3181 | if (level > 1) |
---|
3182 | { |
---|
3183 | xWriteVlc( 0, 2*(level-2)+sign ); |
---|
3184 | run_done = 1; |
---|
3185 | } |
---|
3186 | else |
---|
3187 | { |
---|
3188 | xWriteFlag( sign ); |
---|
3189 | } |
---|
3190 | |
---|
3191 | run = 0; |
---|
3192 | done = 1; |
---|
3193 | } |
---|
3194 | if (i == 15) |
---|
3195 | { |
---|
3196 | done = 1; |
---|
3197 | run_done = 1; |
---|
3198 | if (run) |
---|
3199 | { |
---|
3200 | #if QC_MOD_LCEC |
---|
3201 | if (n==2){ |
---|
3202 | cn=xRunLevelInd(0, run, maxrun, g_auiLumaRunTr14x4[tr1][maxrun]); |
---|
3203 | } |
---|
3204 | else{ |
---|
3205 | #if RUNLEVEL_TABLE_CUT |
---|
3206 | cn = xRunLevelIndInter(0, run, maxrun); |
---|
3207 | #else |
---|
3208 | cn = g_auiLumaRun8x8[maxrun][0][run]; |
---|
3209 | #endif |
---|
3210 | } |
---|
3211 | #else |
---|
3212 | if (maxrun > 27) |
---|
3213 | { |
---|
3214 | cn = g_auiLumaRun8x8[28][0][run]; |
---|
3215 | } |
---|
3216 | else |
---|
3217 | { |
---|
3218 | cn = g_auiLumaRun8x8[maxrun][0][run]; |
---|
3219 | } |
---|
3220 | #endif |
---|
3221 | xWriteVlc( vlc, cn ); |
---|
3222 | } |
---|
3223 | } |
---|
3224 | i++; |
---|
3225 | } |
---|
3226 | } |
---|
3227 | } |
---|
3228 | |
---|
3229 | /* Code the rest in level mode */ |
---|
3230 | start = i; |
---|
3231 | for ( i=start; i<16; i++ ) |
---|
3232 | { |
---|
3233 | tmp = abs(scoeff[i]); |
---|
3234 | xWriteVlc( vlc_adaptive, tmp ); |
---|
3235 | if (scoeff[i]) |
---|
3236 | { |
---|
3237 | sign = (scoeff[i] < 0) ? 1 : 0; |
---|
3238 | xWriteFlag( sign ); |
---|
3239 | } |
---|
3240 | if ( tmp > atable[vlc_adaptive] ) |
---|
3241 | { |
---|
3242 | vlc_adaptive++; |
---|
3243 | } |
---|
3244 | } |
---|
3245 | return; |
---|
3246 | } |
---|
3247 | |
---|
3248 | Void TEncCavlc::xCodeCoeff8x8( TCoeff* scoeff, Int n ) |
---|
3249 | { |
---|
3250 | int i; |
---|
3251 | unsigned int cn; |
---|
3252 | int level,vlc,sign,done,last_pos,start; |
---|
3253 | int run_done,maxrun,run,lev; |
---|
3254 | #if QC_MOD_LCEC |
---|
3255 | int vlc_adaptive=0; |
---|
3256 | #else |
---|
3257 | int tmprun,vlc_adaptive=0; |
---|
3258 | #endif |
---|
3259 | static const int atable[5] = {4,6,14,28,0xfffffff}; |
---|
3260 | int tmp; |
---|
3261 | #if QC_MOD_LCEC |
---|
3262 | Int tr1; |
---|
3263 | #endif |
---|
3264 | |
---|
3265 | static const int switch_thr[10] = {49,49,0,49,49,0,49,49,49,49}; |
---|
3266 | int sum_big_coef = 0; |
---|
3267 | |
---|
3268 | |
---|
3269 | /* Do the last coefficient first */ |
---|
3270 | i = 0; |
---|
3271 | done = 0; |
---|
3272 | while (!done && i < 64) |
---|
3273 | { |
---|
3274 | if (scoeff[i]) |
---|
3275 | { |
---|
3276 | done = 1; |
---|
3277 | } |
---|
3278 | else |
---|
3279 | { |
---|
3280 | i++; |
---|
3281 | } |
---|
3282 | } |
---|
3283 | if (i == 64) |
---|
3284 | { |
---|
3285 | return; |
---|
3286 | } |
---|
3287 | |
---|
3288 | last_pos = 63-i; |
---|
3289 | level = abs(scoeff[i]); |
---|
3290 | lev = (level == 1) ? 0 : 1; |
---|
3291 | |
---|
3292 | { |
---|
3293 | int x,y,cx,cy,vlcNum; |
---|
3294 | x = 64*lev + last_pos; |
---|
3295 | |
---|
3296 | cx = m_uiLPTableE8[n][x]; |
---|
3297 | // ADAPT_VLC_NUM |
---|
3298 | vlcNum = g_auiLastPosVlcNum[n][Min(16,m_uiLastPosVlcIndex[n])]; |
---|
3299 | xWriteVlc( vlcNum, cx ); |
---|
3300 | |
---|
3301 | if ( m_bAdaptFlag ) |
---|
3302 | { |
---|
3303 | // ADAPT_VLC_NUM |
---|
3304 | m_uiLastPosVlcIndex[n] += cx == m_uiLastPosVlcIndex[n] ? 0 : (cx < m_uiLastPosVlcIndex[n] ? -1 : 1); |
---|
3305 | cy = Max(0,cx-1); |
---|
3306 | y = m_uiLPTableD8[n][cy]; |
---|
3307 | m_uiLPTableD8[n][cy] = x; |
---|
3308 | m_uiLPTableD8[n][cx] = y; |
---|
3309 | m_uiLPTableE8[n][x] = cy; |
---|
3310 | m_uiLPTableE8[n][y] = cx; |
---|
3311 | } |
---|
3312 | } |
---|
3313 | |
---|
3314 | sign = (scoeff[i] < 0) ? 1 : 0; |
---|
3315 | if (level > 1) |
---|
3316 | { |
---|
3317 | xWriteVlc( 0, 2*(level-2)+sign ); |
---|
3318 | } |
---|
3319 | else |
---|
3320 | { |
---|
3321 | xWriteFlag( sign ); |
---|
3322 | } |
---|
3323 | i++; |
---|
3324 | #if QC_MOD_LCEC |
---|
3325 | if (level>1){ |
---|
3326 | tr1=0; |
---|
3327 | } |
---|
3328 | else |
---|
3329 | { |
---|
3330 | tr1=1; |
---|
3331 | } |
---|
3332 | #endif |
---|
3333 | |
---|
3334 | if (i < 64) |
---|
3335 | { |
---|
3336 | /* Go into run mode */ |
---|
3337 | run_done = 0; |
---|
3338 | while ( !run_done ) |
---|
3339 | { |
---|
3340 | maxrun = 63-i; |
---|
3341 | #if QC_MOD_LCEC |
---|
3342 | if(n == 2 || n == 5) |
---|
3343 | vlc = g_auiVlcTable8x8Intra[Min(maxrun,28)]; |
---|
3344 | else |
---|
3345 | vlc = g_auiVlcTable8x8Inter[Min(maxrun,28)]; |
---|
3346 | #else |
---|
3347 | tmprun = maxrun; |
---|
3348 | if (maxrun > 27) |
---|
3349 | { |
---|
3350 | vlc = 3; |
---|
3351 | tmprun = 28; |
---|
3352 | } |
---|
3353 | else |
---|
3354 | { |
---|
3355 | vlc = g_auiVlcTable8x8[maxrun]; |
---|
3356 | } |
---|
3357 | #endif |
---|
3358 | |
---|
3359 | run = 0; |
---|
3360 | done = 0; |
---|
3361 | while (!done) |
---|
3362 | { |
---|
3363 | if (!scoeff[i]) |
---|
3364 | { |
---|
3365 | run++; |
---|
3366 | } |
---|
3367 | else |
---|
3368 | { |
---|
3369 | level = abs(scoeff[i]); |
---|
3370 | lev = (level == 1) ? 0 : 1; |
---|
3371 | #if QC_MOD_LCEC |
---|
3372 | if(n == 2 || n == 5) |
---|
3373 | cn = xRunLevelInd(lev, run, maxrun, g_auiLumaRunTr18x8[tr1][min(maxrun,28)]); |
---|
3374 | else |
---|
3375 | #if RUNLEVEL_TABLE_CUT |
---|
3376 | cn = xRunLevelIndInter(lev, run, maxrun); |
---|
3377 | #else |
---|
3378 | cn = g_auiLumaRun8x8[min(maxrun,28)][lev][run]; |
---|
3379 | #endif |
---|
3380 | #else |
---|
3381 | if (maxrun > 27) |
---|
3382 | { |
---|
3383 | cn = g_auiLumaRun8x8[28][lev][run]; |
---|
3384 | } |
---|
3385 | else |
---|
3386 | { |
---|
3387 | cn = g_auiLumaRun8x8[maxrun][lev][run]; |
---|
3388 | } |
---|
3389 | #endif |
---|
3390 | xWriteVlc( vlc, cn ); |
---|
3391 | |
---|
3392 | #if QC_MOD_LCEC |
---|
3393 | if (tr1==0 || level >=2) |
---|
3394 | { |
---|
3395 | tr1=0; |
---|
3396 | } |
---|
3397 | else if (tr1 < MAX_TR1) |
---|
3398 | { |
---|
3399 | tr1++; |
---|
3400 | } |
---|
3401 | #endif |
---|
3402 | sign = (scoeff[i] < 0) ? 1 : 0; |
---|
3403 | if (level > 1) |
---|
3404 | { |
---|
3405 | xWriteVlc( 0, 2*(level-2)+sign ); |
---|
3406 | |
---|
3407 | sum_big_coef += level; |
---|
3408 | if (i > switch_thr[n] || sum_big_coef > 2) |
---|
3409 | { |
---|
3410 | run_done = 1; |
---|
3411 | } |
---|
3412 | } |
---|
3413 | else |
---|
3414 | { |
---|
3415 | xWriteFlag( sign ); |
---|
3416 | } |
---|
3417 | run = 0; |
---|
3418 | done = 1; |
---|
3419 | } |
---|
3420 | if (i == 63) |
---|
3421 | { |
---|
3422 | done = 1; |
---|
3423 | run_done = 1; |
---|
3424 | if (run) |
---|
3425 | { |
---|
3426 | #if QC_MOD_LCEC |
---|
3427 | if(n == 2 || n == 5) |
---|
3428 | cn=xRunLevelInd(0, run, maxrun, g_auiLumaRunTr18x8[tr1][min(maxrun,28)]); |
---|
3429 | else |
---|
3430 | #if RUNLEVEL_TABLE_CUT |
---|
3431 | cn = xRunLevelIndInter(0, run, maxrun); |
---|
3432 | #else |
---|
3433 | cn = g_auiLumaRun8x8[min(maxrun,28)][0][run]; |
---|
3434 | #endif |
---|
3435 | #else |
---|
3436 | if (maxrun > 27) |
---|
3437 | { |
---|
3438 | cn = g_auiLumaRun8x8[28][0][run]; |
---|
3439 | } |
---|
3440 | else |
---|
3441 | { |
---|
3442 | cn = g_auiLumaRun8x8[maxrun][0][run]; |
---|
3443 | } |
---|
3444 | #endif |
---|
3445 | xWriteVlc( vlc, cn ); |
---|
3446 | } |
---|
3447 | } |
---|
3448 | i++; |
---|
3449 | } |
---|
3450 | } |
---|
3451 | } |
---|
3452 | |
---|
3453 | /* Code the rest in level mode */ |
---|
3454 | start = i; |
---|
3455 | for ( i=start; i<64; i++ ) |
---|
3456 | { |
---|
3457 | tmp = abs(scoeff[i]); |
---|
3458 | xWriteVlc( vlc_adaptive, tmp ); |
---|
3459 | if (scoeff[i]) |
---|
3460 | { |
---|
3461 | sign = (scoeff[i] < 0) ? 1 : 0; |
---|
3462 | xWriteFlag( sign ); |
---|
3463 | } |
---|
3464 | if (tmp>atable[vlc_adaptive]) |
---|
3465 | { |
---|
3466 | vlc_adaptive++; |
---|
3467 | } |
---|
3468 | } |
---|
3469 | |
---|
3470 | return; |
---|
3471 | } |
---|
3472 | #endif |
---|
3473 | |
---|
3474 | #ifdef WEIGHT_PRED |
---|
3475 | Void TEncCavlc::codeWeightPredTable( TComSlice* pcSlice ) |
---|
3476 | { |
---|
3477 | wpScalingParam *wp; |
---|
3478 | Bool bChroma = true; // color always present in HEVC ? |
---|
3479 | Int nbRef = (pcSlice->getSliceType() == B_SLICE ) ? (2) : (1); |
---|
3480 | Bool denomCoded = false; |
---|
3481 | |
---|
3482 | for ( Int numRef=0 ; numRef<nbRef ; numRef++ ) { |
---|
3483 | RefPicList eRefPicList = ( numRef ? REF_PIC_LIST_1 : REF_PIC_LIST_0 ); |
---|
3484 | for ( Int iRefIdx=0 ; iRefIdx<pcSlice->getNumRefIdx(eRefPicList) ; iRefIdx++ ) { |
---|
3485 | pcSlice->getWpScaling(eRefPicList, iRefIdx, wp); |
---|
3486 | if ( !denomCoded ) { |
---|
3487 | // code luma_log2_weight_denom : |
---|
3488 | xWriteUvlc( wp[0].uiLog2WeightDenom ); // ue(v): luma_log2_weight_denom |
---|
3489 | if( bChroma ) |
---|
3490 | xWriteUvlc( wp[1].uiLog2WeightDenom ); // ue(v): chroma_log2_weight_denom |
---|
3491 | denomCoded = true; |
---|
3492 | } |
---|
3493 | |
---|
3494 | xWriteFlag( wp[0].bPresentFlag ); // u(1): luma_weight_l0_flag |
---|
3495 | if ( wp[0].bPresentFlag ) { |
---|
3496 | xWriteSvlc( wp[0].iWeight ); // se(v): luma_weight_l0[i] |
---|
3497 | xWriteSvlc( wp[0].iOffset ); // se(v): luma_offset_l0[i] |
---|
3498 | } |
---|
3499 | if ( bChroma ) { |
---|
3500 | xWriteFlag( wp[1].bPresentFlag ); // u(1): chroma_weight_l0_flag |
---|
3501 | if ( wp[1].bPresentFlag ) { |
---|
3502 | for ( Int j=1 ; j<3 ; j++ ) { |
---|
3503 | xWriteSvlc( wp[j].iWeight ); // se(v): chroma_weight_l0[i][j] |
---|
3504 | xWriteSvlc( wp[j].iOffset ); // se(v): chroma_offset_l0[i][j] |
---|
3505 | } |
---|
3506 | } |
---|
3507 | } |
---|
3508 | } |
---|
3509 | } |
---|
3510 | |
---|
3511 | } |
---|
3512 | #endif |
---|