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