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