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