1 | /* ==================================================================================================================== |
---|
2 | |
---|
3 | The copyright in this software is being made available under the License included below. |
---|
4 | This software may be subject to other third party and contributor rights, including patent rights, and no such |
---|
5 | rights are granted under this license. |
---|
6 | |
---|
7 | Copyright (c) 2010, SAMSUNG ELECTRONICS CO., LTD. and BRITISH BROADCASTING CORPORATION |
---|
8 | All rights reserved. |
---|
9 | |
---|
10 | Redistribution and use in source and binary forms, with or without modification, are permitted only for |
---|
11 | the purpose of developing standards within the Joint Collaborative Team on Video Coding and for testing and |
---|
12 | promoting such standards. The following conditions are required to be met: |
---|
13 | |
---|
14 | * Redistributions of source code must retain the above copyright notice, this list of conditions and |
---|
15 | the following disclaimer. |
---|
16 | * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and |
---|
17 | the following disclaimer in the documentation and/or other materials provided with the distribution. |
---|
18 | * Neither the name of SAMSUNG ELECTRONICS CO., LTD. nor the name of the BRITISH BROADCASTING CORPORATION |
---|
19 | may be used to endorse or promote products derived from this software without specific prior written permission. |
---|
20 | |
---|
21 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, |
---|
22 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
---|
23 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, |
---|
24 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
---|
25 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
---|
26 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
---|
27 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
---|
28 | |
---|
29 | * ==================================================================================================================== |
---|
30 | */ |
---|
31 | |
---|
32 | /** \file TEncCavlc.cpp |
---|
33 | \brief CAVLC encoder class |
---|
34 | */ |
---|
35 | |
---|
36 | #include "TEncCavlc.h" |
---|
37 | |
---|
38 | // ==================================================================================================================== |
---|
39 | // Constructor / destructor / create / destroy |
---|
40 | // ==================================================================================================================== |
---|
41 | |
---|
42 | TEncCavlc::TEncCavlc() |
---|
43 | { |
---|
44 | m_pcBitIf = NULL; |
---|
45 | m_bRunLengthCoding = false; // m_bRunLengthCoding = !rcSliceHeader.isIntra(); |
---|
46 | m_uiCoeffCost = 0; |
---|
47 | m_bAlfCtrl = false; |
---|
48 | m_uiMaxAlfCtrlDepth = 0; |
---|
49 | |
---|
50 | m_bAdaptFlag = true; // adaptive VLC table |
---|
51 | |
---|
52 | #if LCEC_STAT |
---|
53 | m_uiBitHLS = 0; |
---|
54 | m_uiBitMVPId = 0; |
---|
55 | m_uiBitPartSize = 0; |
---|
56 | m_uiBitPredMode = 0; |
---|
57 | m_uiBitMergeFlag = 0; |
---|
58 | m_uiBitMergeIndex = 0; |
---|
59 | m_uiBitAlfCtrlFlag = 0; |
---|
60 | m_uiBitAlfCtrlDepth = 0; |
---|
61 | m_uiBitSkipFlag = 0; |
---|
62 | m_uiBitCurrSplitFlag = 0; |
---|
63 | m_uiBitTransformSubdivFlag = 0; |
---|
64 | m_uiBitQtCbf = 0; |
---|
65 | m_uiBitIntraDir = 0; |
---|
66 | m_uiBitIRefFrmIdx = 0; |
---|
67 | m_uiBitMVD = 0; |
---|
68 | m_uiBitDeltaQP = 0; |
---|
69 | m_uiBitAlfFlag = 0; |
---|
70 | m_uiBitAlfUvlc = 0; |
---|
71 | m_uiBitAlfSvlc = 0; |
---|
72 | m_uiBitMVPIdx = 0; |
---|
73 | m_uiBitInterDir = 0; |
---|
74 | m_uiBitMI = 0; |
---|
75 | m_uiBitCoeff = 0; |
---|
76 | m_uiBitCbp = 0; |
---|
77 | #endif |
---|
78 | } |
---|
79 | |
---|
80 | TEncCavlc::~TEncCavlc() |
---|
81 | { |
---|
82 | } |
---|
83 | |
---|
84 | #if LCEC_STAT |
---|
85 | #define NUM_PASSES 2 |
---|
86 | Void TEncCavlc::statistics(Bool bResetFlag, UInt uiPrintVar) |
---|
87 | { |
---|
88 | if (bResetFlag) |
---|
89 | { |
---|
90 | m_uiBitHLS = 0; |
---|
91 | m_uiBitMVPId = 0; |
---|
92 | m_uiBitPartSize = 0; |
---|
93 | m_uiBitPredMode = 0; |
---|
94 | |
---|
95 | m_uiBitMergeFlag = 0; |
---|
96 | m_uiBitMergeIndex = 0; |
---|
97 | m_uiBitAlfCtrlFlag = 0; |
---|
98 | m_uiBitAlfCtrlDepth = 0; |
---|
99 | |
---|
100 | m_uiBitSkipFlag = 0; |
---|
101 | m_uiBitCurrSplitFlag = 0; |
---|
102 | m_uiBitTransformSubdivFlag = 0; |
---|
103 | m_uiBitQtCbf = 0; |
---|
104 | |
---|
105 | m_uiBitIntraDir = 0; |
---|
106 | m_uiBitIRefFrmIdx = 0; |
---|
107 | m_uiBitMVD = 0; |
---|
108 | m_uiBitDeltaQP = 0; |
---|
109 | |
---|
110 | m_uiBitCbp = 0; |
---|
111 | m_uiBitAlfFlag = 0; |
---|
112 | m_uiBitAlfUvlc = 0; |
---|
113 | m_uiBitAlfSvlc = 0; |
---|
114 | m_uiBitMVPIdx = 0; |
---|
115 | |
---|
116 | m_uiBitInterDir = 0; |
---|
117 | m_uiBitMI = 0; |
---|
118 | m_uiBitCoeff = 0; |
---|
119 | } |
---|
120 | |
---|
121 | |
---|
122 | if (uiPrintVar) |
---|
123 | { |
---|
124 | UInt uiTotalBits = 0; |
---|
125 | |
---|
126 | /* Divide some of the variables by by number of passes */ |
---|
127 | m_uiBitMVPId = m_uiBitMVPId/NUM_PASSES; |
---|
128 | m_uiBitPartSize = m_uiBitPartSize/NUM_PASSES; |
---|
129 | m_uiBitPredMode = m_uiBitPredMode/NUM_PASSES; |
---|
130 | m_uiBitMergeFlag = m_uiBitMergeFlag/NUM_PASSES; |
---|
131 | m_uiBitMergeIndex = m_uiBitMergeIndex/NUM_PASSES; |
---|
132 | m_uiBitSkipFlag = m_uiBitSkipFlag/NUM_PASSES; |
---|
133 | m_uiBitCurrSplitFlag = m_uiBitCurrSplitFlag/NUM_PASSES; |
---|
134 | m_uiBitTransformSubdivFlag = m_uiBitTransformSubdivFlag/NUM_PASSES; |
---|
135 | m_uiBitQtCbf = m_uiBitQtCbf/NUM_PASSES; |
---|
136 | m_uiBitIntraDir = m_uiBitIntraDir/NUM_PASSES; |
---|
137 | m_uiBitIRefFrmIdx = m_uiBitIRefFrmIdx/NUM_PASSES; |
---|
138 | m_uiBitMVD = m_uiBitMVD/NUM_PASSES; |
---|
139 | m_uiBitDeltaQP = m_uiBitDeltaQP/NUM_PASSES; |
---|
140 | m_uiBitCbp = m_uiBitCbp/NUM_PASSES; |
---|
141 | m_uiBitMVPIdx = m_uiBitMVPIdx/NUM_PASSES; |
---|
142 | m_uiBitInterDir = m_uiBitInterDir/NUM_PASSES; |
---|
143 | m_uiBitMI = m_uiBitMI/NUM_PASSES; |
---|
144 | m_uiBitCoeff = m_uiBitCoeff/NUM_PASSES; |
---|
145 | |
---|
146 | |
---|
147 | /* Calculate total bit usage */ |
---|
148 | uiTotalBits += m_uiBitHLS; |
---|
149 | uiTotalBits += m_uiBitMVPId; |
---|
150 | uiTotalBits += m_uiBitPartSize; |
---|
151 | uiTotalBits += m_uiBitPredMode; |
---|
152 | |
---|
153 | uiTotalBits += m_uiBitMergeFlag; |
---|
154 | uiTotalBits += m_uiBitMergeIndex; |
---|
155 | uiTotalBits += m_uiBitAlfCtrlFlag; |
---|
156 | uiTotalBits += m_uiBitAlfCtrlDepth; |
---|
157 | |
---|
158 | uiTotalBits += m_uiBitSkipFlag; |
---|
159 | uiTotalBits += m_uiBitCurrSplitFlag; |
---|
160 | uiTotalBits += m_uiBitTransformSubdivFlag; |
---|
161 | uiTotalBits += m_uiBitQtCbf; |
---|
162 | |
---|
163 | uiTotalBits += m_uiBitIntraDir; |
---|
164 | uiTotalBits += m_uiBitIRefFrmIdx; |
---|
165 | uiTotalBits += m_uiBitMVD; |
---|
166 | uiTotalBits += m_uiBitDeltaQP; |
---|
167 | |
---|
168 | uiTotalBits += m_uiBitCbp; |
---|
169 | uiTotalBits += m_uiBitAlfFlag; |
---|
170 | uiTotalBits += m_uiBitAlfUvlc; |
---|
171 | uiTotalBits += m_uiBitAlfSvlc; |
---|
172 | uiTotalBits += m_uiBitMVPIdx; |
---|
173 | |
---|
174 | uiTotalBits += m_uiBitInterDir; |
---|
175 | uiTotalBits += m_uiBitMI; |
---|
176 | uiTotalBits += m_uiBitCoeff; |
---|
177 | |
---|
178 | /* Printout statistics */ |
---|
179 | printf("\n"); |
---|
180 | printf("m_uiBitHLS = %12d %6.1f\n",m_uiBitHLS,100.0*(float)m_uiBitHLS/(float)uiTotalBits); |
---|
181 | printf("m_uiBitMVPId = %12d %6.1f\n",m_uiBitMVPId,100.0*(float)m_uiBitMVPId/(float)uiTotalBits); |
---|
182 | printf("m_uiBitPartSize = %12d %6.1f\n",m_uiBitPartSize,100.0*(float)m_uiBitPartSize/(float)uiTotalBits); |
---|
183 | printf("m_uiBitPredMode = %12d %6.1f\n",m_uiBitPredMode,100.0*(float)m_uiBitPredMode/(float)uiTotalBits); |
---|
184 | |
---|
185 | printf("m_uiBitMergeFlag = %12d %6.1f\n",m_uiBitMergeFlag,100.0*(float)m_uiBitMergeFlag/(float)uiTotalBits); |
---|
186 | printf("m_uiBitMergeIndex = %12d %6.1f\n",m_uiBitMergeIndex,100.0*(float)m_uiBitMergeIndex/(float)uiTotalBits); |
---|
187 | printf("m_uiBitAlfCtrlFlag = %12d %6.1f\n",m_uiBitAlfCtrlFlag,100.0*(float)m_uiBitAlfCtrlFlag/(float)uiTotalBits); |
---|
188 | printf("m_uiBitAlfCtrlDepth = %12d %6.1f\n",m_uiBitAlfCtrlDepth,100.0*(float)m_uiBitAlfCtrlDepth/(float)uiTotalBits); |
---|
189 | |
---|
190 | printf("m_uiBitSkipFlag = %12d %6.1f\n",m_uiBitSkipFlag,100.0*(float)m_uiBitSkipFlag/(float)uiTotalBits); |
---|
191 | printf("m_uiBitCurrSplitFlag = %12d %6.1f\n",m_uiBitCurrSplitFlag,100.0*(float)m_uiBitCurrSplitFlag/(float)uiTotalBits); |
---|
192 | printf("m_uiBitTransformSubdivFlag = %12d %6.1f\n",m_uiBitTransformSubdivFlag,100.0*(float)m_uiBitTransformSubdivFlag/(float)uiTotalBits); |
---|
193 | printf("m_uiBitQtCbf = %12d %6.1f\n",m_uiBitQtCbf,100.0*(float)m_uiBitQtCbf/(float)uiTotalBits); |
---|
194 | |
---|
195 | printf("m_uiBitIntraDir = %12d %6.1f\n",m_uiBitIntraDir,100.0*(float)m_uiBitIntraDir/(float)uiTotalBits); |
---|
196 | printf("m_uiBitIRefFrmIdx = %12d %6.1f\n",m_uiBitIRefFrmIdx,100.0*(float)m_uiBitIRefFrmIdx/(float)uiTotalBits); |
---|
197 | printf("m_uiBitMVD = %12d %6.1f\n",m_uiBitMVD,100.0*(float)m_uiBitMVD/(float)uiTotalBits); |
---|
198 | printf("m_uiBitDeltaQP = %12d %6.1f\n",m_uiBitDeltaQP,100.0*(float)m_uiBitDeltaQP/(float)uiTotalBits); |
---|
199 | |
---|
200 | printf("m_uiBitCbp = %12d %6.1f\n",m_uiBitCbp,100.0*(float)m_uiBitCbp/(float)uiTotalBits); |
---|
201 | printf("m_uiBitAlfFlag = %12d %6.1f\n",m_uiBitAlfFlag,100.0*(float)m_uiBitAlfFlag/(float)uiTotalBits); |
---|
202 | printf("m_uiBitAlfUvlc = %12d %6.1f\n",m_uiBitAlfUvlc,100.0*(float)m_uiBitAlfUvlc/(float)uiTotalBits); |
---|
203 | printf("m_uiBitAlfSvlc = %12d %6.1f\n",m_uiBitAlfSvlc,100.0*(float)m_uiBitAlfSvlc/(float)uiTotalBits); |
---|
204 | printf("m_uiBitMVPIdx = %12d %6.1f\n",m_uiBitMVPIdx,100.0*(float)m_uiBitMVPIdx/(float)uiTotalBits); |
---|
205 | |
---|
206 | printf("m_uiBitInterDir = %12d %6.1f\n",m_uiBitInterDir,100.0*(float)m_uiBitInterDir/(float)uiTotalBits); |
---|
207 | printf("m_uiBitMI = %12d %6.1f\n",m_uiBitMI,100.0*(float)m_uiBitMI/(float)uiTotalBits); |
---|
208 | printf("m_uiBitCoeff = %12d %6.1f\n",m_uiBitCoeff,100.0*(float)m_uiBitCoeff/(float)uiTotalBits); |
---|
209 | |
---|
210 | printf("uiTotalBits = %12d\n",uiTotalBits); |
---|
211 | |
---|
212 | } //if uiPrintFlag |
---|
213 | } |
---|
214 | #endif |
---|
215 | |
---|
216 | // ==================================================================================================================== |
---|
217 | // Public member functions |
---|
218 | // ==================================================================================================================== |
---|
219 | |
---|
220 | Void TEncCavlc::resetEntropy() |
---|
221 | { |
---|
222 | m_bRunLengthCoding = ! m_pcSlice->isIntra(); |
---|
223 | m_uiRun = 0; |
---|
224 | ::memcpy(m_uiLPTableE8, g_auiLPTableE8, 10*128*sizeof(UInt)); |
---|
225 | ::memcpy(m_uiLPTableD8, g_auiLPTableD8, 10*128*sizeof(UInt)); |
---|
226 | ::memcpy(m_uiLPTableE4, g_auiLPTableE4, 3*32*sizeof(UInt)); |
---|
227 | ::memcpy(m_uiLPTableD4, g_auiLPTableD4, 3*32*sizeof(UInt)); |
---|
228 | ::memcpy(m_uiLastPosVlcIndex, g_auiLastPosVlcIndex, 10*sizeof(UInt)); |
---|
229 | |
---|
230 | #if LCEC_INTRA_MODE |
---|
231 | ::memcpy(m_uiIntraModeTableD17, g_auiIntraModeTableD17, 16*sizeof(UInt)); |
---|
232 | ::memcpy(m_uiIntraModeTableE17, g_auiIntraModeTableE17, 16*sizeof(UInt)); |
---|
233 | |
---|
234 | ::memcpy(m_uiIntraModeTableD34, g_auiIntraModeTableD34, 33*sizeof(UInt)); |
---|
235 | ::memcpy(m_uiIntraModeTableE34, g_auiIntraModeTableE34, 33*sizeof(UInt)); |
---|
236 | #endif |
---|
237 | |
---|
238 | ::memcpy(m_uiCBPTableE, g_auiCBPTableE, 2*8*sizeof(UInt)); |
---|
239 | ::memcpy(m_uiCBPTableD, g_auiCBPTableD, 2*8*sizeof(UInt)); |
---|
240 | m_uiCbpVlcIdx[0] = 0; |
---|
241 | m_uiCbpVlcIdx[1] = 0; |
---|
242 | |
---|
243 | #if QC_BLK_CBP |
---|
244 | ::memcpy(m_uiBlkCBPTableE, g_auiBlkCBPTableE, 2*15*sizeof(UInt)); |
---|
245 | ::memcpy(m_uiBlkCBPTableD, g_auiBlkCBPTableD, 2*15*sizeof(UInt)); |
---|
246 | m_uiBlkCbpVlcIdx = 0; |
---|
247 | #endif |
---|
248 | |
---|
249 | ::memcpy(m_uiMI1TableE, g_auiMI1TableE, 8*sizeof(UInt)); |
---|
250 | ::memcpy(m_uiMI1TableD, g_auiMI1TableD, 8*sizeof(UInt)); |
---|
251 | ::memcpy(m_uiMI2TableE, g_auiMI2TableE, 15*sizeof(UInt)); |
---|
252 | ::memcpy(m_uiMI2TableD, g_auiMI2TableD, 15*sizeof(UInt)); |
---|
253 | |
---|
254 | #if MS_NO_BACK_PRED_IN_B0 |
---|
255 | #if DCM_COMB_LIST |
---|
256 | if ( m_pcSlice->getNoBackPredFlag() || m_pcSlice->getNumRefIdx(REF_PIC_LIST_C)>0) |
---|
257 | #else |
---|
258 | if ( m_pcSlice->getNoBackPredFlag() ) |
---|
259 | #endif |
---|
260 | { |
---|
261 | ::memcpy(m_uiMI1TableE, g_auiMI1TableENoL1, 8*sizeof(UInt)); |
---|
262 | ::memcpy(m_uiMI1TableD, g_auiMI1TableDNoL1, 8*sizeof(UInt)); |
---|
263 | ::memcpy(m_uiMI2TableE, g_auiMI2TableENoL1, 15*sizeof(UInt)); |
---|
264 | ::memcpy(m_uiMI2TableD, g_auiMI2TableDNoL1, 15*sizeof(UInt)); |
---|
265 | } |
---|
266 | #endif |
---|
267 | #if MS_LCEC_ONE_FRAME |
---|
268 | if ( m_pcSlice->getNumRefIdx(REF_PIC_LIST_0) <= 1 && m_pcSlice->getNumRefIdx(REF_PIC_LIST_1) <= 1 ) |
---|
269 | { |
---|
270 | if ( m_pcSlice->getNoBackPredFlag() || ( m_pcSlice->getNumRefIdx(REF_PIC_LIST_C) > 0 && m_pcSlice->getNumRefIdx(REF_PIC_LIST_C) <= 1 ) ) |
---|
271 | { |
---|
272 | ::memcpy(m_uiMI1TableE, g_auiMI1TableEOnly1RefNoL1, 8*sizeof(UInt)); |
---|
273 | ::memcpy(m_uiMI1TableD, g_auiMI1TableDOnly1RefNoL1, 8*sizeof(UInt)); |
---|
274 | } |
---|
275 | else |
---|
276 | { |
---|
277 | ::memcpy(m_uiMI1TableE, g_auiMI1TableEOnly1Ref, 8*sizeof(UInt)); |
---|
278 | ::memcpy(m_uiMI1TableD, g_auiMI1TableDOnly1Ref, 8*sizeof(UInt)); |
---|
279 | } |
---|
280 | } |
---|
281 | #endif |
---|
282 | #if MS_LCEC_LOOKUP_TABLE_EXCEPTION |
---|
283 | if (m_pcSlice->getNumRefIdx(REF_PIC_LIST_C)>0) |
---|
284 | { |
---|
285 | m_uiMI1TableE[8] = 8; |
---|
286 | m_uiMI1TableD[8] = 8; |
---|
287 | } |
---|
288 | else // GPB case |
---|
289 | { |
---|
290 | m_uiMI1TableD[8] = m_uiMI1TableD[6]; |
---|
291 | m_uiMI1TableD[6] = 8; |
---|
292 | |
---|
293 | m_uiMI1TableE[m_uiMI1TableD[8]] = 8; |
---|
294 | m_uiMI1TableE[m_uiMI1TableD[6]] = 6; |
---|
295 | } |
---|
296 | #endif |
---|
297 | #if QC_LCEC_INTER_MODE |
---|
298 | ::memcpy(m_uiSplitTableE, g_auiInterModeTableE, 4*7*sizeof(UInt)); |
---|
299 | ::memcpy(m_uiSplitTableD, g_auiInterModeTableD, 4*7*sizeof(UInt)); |
---|
300 | #endif |
---|
301 | |
---|
302 | m_uiMITableVlcIdx = 0; |
---|
303 | } |
---|
304 | |
---|
305 | UInt* TEncCavlc::GetLP8Table() |
---|
306 | { |
---|
307 | return &m_uiLPTableE8[0][0]; |
---|
308 | } |
---|
309 | |
---|
310 | UInt* TEncCavlc::GetLP4Table() |
---|
311 | { |
---|
312 | return &m_uiLPTableE4[0][0]; |
---|
313 | } |
---|
314 | |
---|
315 | #if QC_MOD_LCEC |
---|
316 | UInt* TEncCavlc::GetLastPosVlcIndexTable() |
---|
317 | { |
---|
318 | return &m_uiLastPosVlcIndex[0]; |
---|
319 | } |
---|
320 | #endif |
---|
321 | |
---|
322 | #if LCEC_STAT |
---|
323 | Void TEncCavlc::codePPS( TComPPS* pcPPS ) |
---|
324 | { |
---|
325 | // uiFirstByte |
---|
326 | xWriteCode( NAL_REF_IDC_PRIORITY_HIGHEST, 2); |
---|
327 | xWriteCode( 0, 1); |
---|
328 | xWriteCode( NAL_UNIT_PPS, 5); |
---|
329 | m_uiBitHLS += 8; |
---|
330 | return; |
---|
331 | } |
---|
332 | |
---|
333 | |
---|
334 | |
---|
335 | Void TEncCavlc::codeSPS( TComSPS* pcSPS ) |
---|
336 | { |
---|
337 | // uiFirstByte |
---|
338 | xWriteCode( NAL_REF_IDC_PRIORITY_HIGHEST, 2); |
---|
339 | xWriteCode( 0, 1); |
---|
340 | xWriteCode( NAL_UNIT_SPS, 5); |
---|
341 | m_uiBitHLS += 8; |
---|
342 | |
---|
343 | // Structure |
---|
344 | m_uiBitHLS += xWriteUvlc ( pcSPS->getWidth () ); |
---|
345 | m_uiBitHLS += xWriteUvlc ( pcSPS->getHeight() ); |
---|
346 | |
---|
347 | m_uiBitHLS += xWriteUvlc ( pcSPS->getPad (0) ); |
---|
348 | m_uiBitHLS += xWriteUvlc ( pcSPS->getPad (1) ); |
---|
349 | |
---|
350 | assert( pcSPS->getMaxCUWidth() == pcSPS->getMaxCUHeight() ); |
---|
351 | m_uiBitHLS += xWriteUvlc ( pcSPS->getMaxCUWidth() ); |
---|
352 | m_uiBitHLS += xWriteUvlc ( pcSPS->getMaxCUDepth()-g_uiAddCUDepth ); |
---|
353 | |
---|
354 | m_uiBitHLS += xWriteUvlc( pcSPS->getQuadtreeTULog2MinSize() - 2 ); |
---|
355 | m_uiBitHLS += xWriteUvlc( pcSPS->getQuadtreeTULog2MaxSize() - pcSPS->getQuadtreeTULog2MinSize() ); |
---|
356 | m_uiBitHLS += xWriteUvlc( pcSPS->getQuadtreeTUMaxDepthInter() - 1 ); |
---|
357 | m_uiBitHLS += xWriteUvlc( pcSPS->getQuadtreeTUMaxDepthIntra() - 1 ); |
---|
358 | |
---|
359 | // Tools |
---|
360 | xWriteFlag ( (pcSPS->getUseALF ()) ? 1 : 0 ); |
---|
361 | xWriteFlag ( (pcSPS->getUseDQP ()) ? 1 : 0 ); |
---|
362 | xWriteFlag ( (pcSPS->getUseLDC ()) ? 1 : 0 ); |
---|
363 | m_uiBitHLS += 5; |
---|
364 | #if HHI_MRG |
---|
365 | xWriteFlag ( (pcSPS->getUseMRG ()) ? 1 : 0 ); // SOPH: |
---|
366 | m_uiBitHLS += 1; |
---|
367 | #endif |
---|
368 | #if HHI_RMP_SWITCH |
---|
369 | xWriteFlag ( (pcSPS->getUseRMP ()) ? 1 : 0 ); |
---|
370 | m_uiBitHLS += 1; |
---|
371 | #endif |
---|
372 | |
---|
373 | // write number of taps for DIF |
---|
374 | m_uiBitHLS += xWriteUvlc ( (pcSPS->getDIFTap ()>>1)-2 ); // 4, 6, 8, 10, 12 |
---|
375 | |
---|
376 | // AMVP mode for each depth |
---|
377 | for (Int i = 0; i < pcSPS->getMaxCUDepth(); i++) |
---|
378 | { |
---|
379 | xWriteFlag( pcSPS->getAMVPMode(i) ? 1 : 0); |
---|
380 | m_uiBitHLS += 1; |
---|
381 | } |
---|
382 | |
---|
383 | // Bit-depth information |
---|
384 | #if FULL_NBIT |
---|
385 | m_uiBitHLS += xWriteUvlc( pcSPS->getBitDepth() - 8 ); |
---|
386 | #else |
---|
387 | #if ENABLE_IBDI |
---|
388 | m_uiBitHLS += xWriteUvlc( pcSPS->getBitDepth() - 8 ); |
---|
389 | #endif |
---|
390 | m_uiBitHLS += xWriteUvlc( pcSPS->getBitIncrement() ); |
---|
391 | #endif |
---|
392 | } |
---|
393 | |
---|
394 | Void TEncCavlc::codeSliceHeader ( TComSlice* pcSlice ) |
---|
395 | { |
---|
396 | // here someone can add an appropriated NalRefIdc type |
---|
397 | xWriteCode( NAL_REF_IDC_PRIORITY_HIGHEST, 2); |
---|
398 | xWriteCode( 0, 1); |
---|
399 | xWriteCode( NAL_UNIT_CODED_SLICE, 5); |
---|
400 | m_uiBitHLS += 8; |
---|
401 | |
---|
402 | m_uiBitHLS += xWriteCode (pcSlice->getPOC(), 10 ); // 9 == SPS->Log2MaxFrameNum |
---|
403 | m_uiBitHLS += xWriteUvlc (pcSlice->getSliceType() ); |
---|
404 | m_uiBitHLS += xWriteSvlc (pcSlice->getSliceQp() ); |
---|
405 | |
---|
406 | xWriteFlag (pcSlice->getSymbolMode() > 0 ? 1 : 0); |
---|
407 | m_uiBitHLS += 1; |
---|
408 | |
---|
409 | if (!pcSlice->isIntra()) |
---|
410 | { |
---|
411 | xWriteFlag (pcSlice->isReferenced() ? 1 : 0); |
---|
412 | m_uiBitHLS += 1; |
---|
413 | #ifdef ROUNDING_CONTROL_BIPRED |
---|
414 | xWriteFlag (pcSlice->isRounding() ? 1 : 0); |
---|
415 | m_uiBitHLS += 1; |
---|
416 | #endif |
---|
417 | } |
---|
418 | |
---|
419 | xWriteFlag (pcSlice->getLoopFilterDisable()); |
---|
420 | m_uiBitHLS += 1; |
---|
421 | |
---|
422 | if (!pcSlice->isIntra()) |
---|
423 | { |
---|
424 | m_uiBitHLS += xWriteCode ((pcSlice->getNumRefIdx( REF_PIC_LIST_0 )), 3 ); |
---|
425 | } |
---|
426 | else |
---|
427 | { |
---|
428 | pcSlice->setNumRefIdx(REF_PIC_LIST_0, 0); |
---|
429 | } |
---|
430 | if (pcSlice->isInterB()) |
---|
431 | { |
---|
432 | m_uiBitHLS += xWriteCode ((pcSlice->getNumRefIdx( REF_PIC_LIST_1 )), 3 ); |
---|
433 | } |
---|
434 | else |
---|
435 | { |
---|
436 | pcSlice->setNumRefIdx(REF_PIC_LIST_1, 0); |
---|
437 | } |
---|
438 | |
---|
439 | #if DCM_COMB_LIST |
---|
440 | if (pcSlice->isInterB()) |
---|
441 | { |
---|
442 | xWriteFlag (pcSlice->getRefPicListCombinationFlag() ? 1 : 0 ); |
---|
443 | m_uiBitHLS += 1; |
---|
444 | if(pcSlice->getRefPicListCombinationFlag()) |
---|
445 | { |
---|
446 | m_uiBitHLS += xWriteUvlc( pcSlice->getNumRefIdx(REF_PIC_LIST_C)-1); |
---|
447 | |
---|
448 | xWriteFlag (pcSlice->getRefPicListModificationFlagLC() ? 1 : 0 ); |
---|
449 | m_uiBitHLS += 1; |
---|
450 | if(pcSlice->getRefPicListModificationFlagLC()) |
---|
451 | { |
---|
452 | for (UInt i=0;i<pcSlice->getNumRefIdx(REF_PIC_LIST_C);i++) |
---|
453 | { |
---|
454 | m_uiBitHLS += xWriteFlag( pcSlice->getListIdFromIdxOfLC(i)); |
---|
455 | m_uiBitHLS += xWriteUvlc( pcSlice->getRefIdxFromIdxOfLC(i)); |
---|
456 | } |
---|
457 | } |
---|
458 | } |
---|
459 | } |
---|
460 | #endif |
---|
461 | |
---|
462 | xWriteFlag (pcSlice->getDRBFlag() ? 1 : 0 ); |
---|
463 | m_uiBitHLS += 1; |
---|
464 | if ( !pcSlice->getDRBFlag() ) |
---|
465 | { |
---|
466 | m_uiBitHLS += xWriteCode (pcSlice->getERBIndex(), 2); |
---|
467 | } |
---|
468 | |
---|
469 | #if !DCTIF_8_6_LUMA |
---|
470 | m_uiBitHLS += xWriteUvlc ( pcSlice->getInterpFilterType() ); |
---|
471 | #endif |
---|
472 | |
---|
473 | #if AMVP_NEIGH_COL |
---|
474 | if ( pcSlice->getSliceType() == B_SLICE ) |
---|
475 | { |
---|
476 | xWriteFlag( pcSlice->getColDir() ); |
---|
477 | m_uiBitHLS += 1; |
---|
478 | } |
---|
479 | #endif |
---|
480 | } |
---|
481 | |
---|
482 | Void TEncCavlc::codeTerminatingBit ( UInt uilsLast ) |
---|
483 | { |
---|
484 | xWriteFlag( uilsLast ); |
---|
485 | m_uiBitHLS += 1; |
---|
486 | } |
---|
487 | |
---|
488 | Void TEncCavlc::codeSliceFinish () |
---|
489 | { |
---|
490 | if ( m_bRunLengthCoding && m_uiRun) |
---|
491 | { |
---|
492 | m_uiBitHLS += xWriteUvlc(m_uiRun); |
---|
493 | } |
---|
494 | } |
---|
495 | #else |
---|
496 | |
---|
497 | Void TEncCavlc::codePPS( TComPPS* pcPPS ) |
---|
498 | { |
---|
499 | // uiFirstByte |
---|
500 | xWriteCode( NAL_REF_IDC_PRIORITY_HIGHEST, 2); |
---|
501 | xWriteCode( 0, 1); |
---|
502 | xWriteCode( NAL_UNIT_PPS, 5); |
---|
503 | return; |
---|
504 | } |
---|
505 | |
---|
506 | Void TEncCavlc::codeSPS( TComSPS* pcSPS ) |
---|
507 | { |
---|
508 | // uiFirstByte |
---|
509 | xWriteCode( NAL_REF_IDC_PRIORITY_HIGHEST, 2); |
---|
510 | xWriteCode( 0, 1); |
---|
511 | xWriteCode( NAL_UNIT_SPS, 5); |
---|
512 | |
---|
513 | // Structure |
---|
514 | xWriteUvlc ( pcSPS->getWidth () ); |
---|
515 | xWriteUvlc ( pcSPS->getHeight() ); |
---|
516 | |
---|
517 | xWriteUvlc ( pcSPS->getPad (0) ); |
---|
518 | xWriteUvlc ( pcSPS->getPad (1) ); |
---|
519 | |
---|
520 | assert( pcSPS->getMaxCUWidth() == pcSPS->getMaxCUHeight() ); |
---|
521 | xWriteUvlc ( pcSPS->getMaxCUWidth() ); |
---|
522 | xWriteUvlc ( pcSPS->getMaxCUDepth()-g_uiAddCUDepth ); |
---|
523 | |
---|
524 | xWriteUvlc( pcSPS->getQuadtreeTULog2MinSize() - 2 ); |
---|
525 | xWriteUvlc( pcSPS->getQuadtreeTULog2MaxSize() - pcSPS->getQuadtreeTULog2MinSize() ); |
---|
526 | xWriteUvlc( pcSPS->getQuadtreeTUMaxDepthInter() - 1 ); |
---|
527 | xWriteUvlc( pcSPS->getQuadtreeTUMaxDepthIntra() - 1 ); |
---|
528 | |
---|
529 | |
---|
530 | // Tools |
---|
531 | xWriteFlag ( (pcSPS->getUseALF ()) ? 1 : 0 ); |
---|
532 | xWriteFlag ( (pcSPS->getUseDQP ()) ? 1 : 0 ); |
---|
533 | xWriteFlag ( (pcSPS->getUseLDC ()) ? 1 : 0 ); |
---|
534 | #if HHI_MRG |
---|
535 | xWriteFlag ( (pcSPS->getUseMRG ()) ? 1 : 0 ); // SOPH: |
---|
536 | #endif |
---|
537 | |
---|
538 | #if HHI_RMP_SWITCH |
---|
539 | xWriteFlag ( (pcSPS->getUseRMP()) ? 1 : 0 ); |
---|
540 | #endif |
---|
541 | |
---|
542 | #if !DCTIF_8_6_LUMA |
---|
543 | // write number of taps for DIF |
---|
544 | xWriteUvlc ( (pcSPS->getDIFTap ()>>1)-2 ); // 4, 6, 8, 10, 12 |
---|
545 | #endif |
---|
546 | |
---|
547 | // AMVP mode for each depth |
---|
548 | for (Int i = 0; i < pcSPS->getMaxCUDepth(); i++) |
---|
549 | { |
---|
550 | xWriteFlag( pcSPS->getAMVPMode(i) ? 1 : 0); |
---|
551 | } |
---|
552 | |
---|
553 | // Bit-depth information |
---|
554 | #if FULL_NBIT |
---|
555 | xWriteUvlc( pcSPS->getBitDepth() - 8 ); |
---|
556 | #else |
---|
557 | #if ENABLE_IBDI |
---|
558 | xWriteUvlc( pcSPS->getBitDepth() - 8 ); |
---|
559 | #endif |
---|
560 | xWriteUvlc( pcSPS->getBitIncrement() ); |
---|
561 | #endif |
---|
562 | } |
---|
563 | |
---|
564 | Void TEncCavlc::codeSliceHeader ( TComSlice* pcSlice ) |
---|
565 | { |
---|
566 | // here someone can add an appropriated NalRefIdc type |
---|
567 | xWriteCode( NAL_REF_IDC_PRIORITY_HIGHEST, 2); |
---|
568 | xWriteCode( 0, 1); |
---|
569 | #if DCM_DECODING_REFRESH |
---|
570 | xWriteCode( pcSlice->getNalUnitType(), 5); |
---|
571 | #else |
---|
572 | xWriteCode( NAL_UNIT_CODED_SLICE, 5); |
---|
573 | #endif |
---|
574 | |
---|
575 | xWriteCode (pcSlice->getPOC(), 10 ); // 9 == SPS->Log2MaxFrameNum |
---|
576 | xWriteUvlc (pcSlice->getSliceType() ); |
---|
577 | xWriteSvlc (pcSlice->getSliceQp() ); |
---|
578 | |
---|
579 | xWriteFlag (pcSlice->getSymbolMode() > 0 ? 1 : 0); |
---|
580 | |
---|
581 | if (!pcSlice->isIntra()) |
---|
582 | { |
---|
583 | xWriteFlag (pcSlice->isReferenced() ? 1 : 0); |
---|
584 | #if !HIGH_ACCURACY_BI |
---|
585 | #ifdef ROUNDING_CONTROL_BIPRED |
---|
586 | xWriteFlag (pcSlice->isRounding() ? 1 : 0); |
---|
587 | #endif |
---|
588 | #endif |
---|
589 | } |
---|
590 | |
---|
591 | xWriteFlag (pcSlice->getLoopFilterDisable()); |
---|
592 | |
---|
593 | if (!pcSlice->isIntra()) |
---|
594 | { |
---|
595 | xWriteCode ((pcSlice->getNumRefIdx( REF_PIC_LIST_0 )), 3 ); |
---|
596 | } |
---|
597 | else |
---|
598 | { |
---|
599 | pcSlice->setNumRefIdx(REF_PIC_LIST_0, 0); |
---|
600 | } |
---|
601 | if (pcSlice->isInterB()) |
---|
602 | { |
---|
603 | xWriteCode ((pcSlice->getNumRefIdx( REF_PIC_LIST_1 )), 3 ); |
---|
604 | } |
---|
605 | else |
---|
606 | { |
---|
607 | pcSlice->setNumRefIdx(REF_PIC_LIST_1, 0); |
---|
608 | } |
---|
609 | |
---|
610 | #if DCM_COMB_LIST |
---|
611 | if (pcSlice->isInterB()) |
---|
612 | { |
---|
613 | xWriteFlag (pcSlice->getRefPicListCombinationFlag() ? 1 : 0 ); |
---|
614 | if(pcSlice->getRefPicListCombinationFlag()) |
---|
615 | { |
---|
616 | xWriteUvlc( pcSlice->getNumRefIdx(REF_PIC_LIST_C)-1); |
---|
617 | |
---|
618 | xWriteFlag (pcSlice->getRefPicListModificationFlagLC() ? 1 : 0 ); |
---|
619 | if(pcSlice->getRefPicListModificationFlagLC()) |
---|
620 | { |
---|
621 | for (UInt i=0;i<pcSlice->getNumRefIdx(REF_PIC_LIST_C);i++) |
---|
622 | { |
---|
623 | xWriteFlag( pcSlice->getListIdFromIdxOfLC(i)); |
---|
624 | xWriteUvlc( pcSlice->getRefIdxFromIdxOfLC(i)); |
---|
625 | } |
---|
626 | } |
---|
627 | } |
---|
628 | } |
---|
629 | #endif |
---|
630 | |
---|
631 | xWriteFlag (pcSlice->getDRBFlag() ? 1 : 0 ); |
---|
632 | if ( !pcSlice->getDRBFlag() ) |
---|
633 | { |
---|
634 | xWriteCode (pcSlice->getERBIndex(), 2); |
---|
635 | } |
---|
636 | |
---|
637 | #if !DCTIF_8_6_LUMA |
---|
638 | xWriteUvlc ( pcSlice->getInterpFilterType() ); |
---|
639 | #endif |
---|
640 | |
---|
641 | #if AMVP_NEIGH_COL |
---|
642 | if ( pcSlice->getSliceType() == B_SLICE ) |
---|
643 | { |
---|
644 | xWriteFlag( pcSlice->getColDir() ); |
---|
645 | } |
---|
646 | #endif |
---|
647 | } |
---|
648 | |
---|
649 | Void TEncCavlc::codeTerminatingBit ( UInt uilsLast ) |
---|
650 | { |
---|
651 | #if !BUGFIX102 |
---|
652 | xWriteFlag( uilsLast ); |
---|
653 | #endif |
---|
654 | } |
---|
655 | |
---|
656 | Void TEncCavlc::codeSliceFinish () |
---|
657 | { |
---|
658 | if ( m_bRunLengthCoding && m_uiRun) |
---|
659 | { |
---|
660 | xWriteUvlc(m_uiRun); |
---|
661 | } |
---|
662 | } |
---|
663 | #endif //LCEC_STAT |
---|
664 | |
---|
665 | Void TEncCavlc::codeMVPIdx ( TComDataCU* pcCU, UInt uiAbsPartIdx, RefPicList eRefList ) |
---|
666 | { |
---|
667 | Int iSymbol = pcCU->getMVPIdx(eRefList, uiAbsPartIdx); |
---|
668 | Int iNum = pcCU->getMVPNum(eRefList, uiAbsPartIdx); |
---|
669 | |
---|
670 | #if LCEC_STAT |
---|
671 | if (m_bAdaptFlag) |
---|
672 | m_uiBitMVPIdx += xWriteUnaryMaxSymbol(iSymbol, iNum-1); |
---|
673 | else |
---|
674 | #endif |
---|
675 | xWriteUnaryMaxSymbol(iSymbol, iNum-1); |
---|
676 | } |
---|
677 | #if QC_LCEC_INTER_MODE |
---|
678 | Void TEncCavlc::codePartSize( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth ) |
---|
679 | { |
---|
680 | if ( pcCU->getSlice()->isIntra() && pcCU->isIntra( uiAbsPartIdx ) ) |
---|
681 | { |
---|
682 | #if MTK_DISABLE_INTRA_NxN_SPLIT |
---|
683 | if( uiDepth == (g_uiMaxCUDepth - g_uiAddCUDepth)) |
---|
684 | #endif |
---|
685 | xWriteFlag( pcCU->getPartitionSize(uiAbsPartIdx ) == SIZE_2Nx2N? 1 : 0 ); |
---|
686 | return; |
---|
687 | } |
---|
688 | |
---|
689 | |
---|
690 | #if MTK_DISABLE_INTRA_NxN_SPLIT && HHI_DISABLE_INTER_NxN_SPLIT |
---|
691 | if( uiDepth == g_uiMaxCUDepth - g_uiAddCUDepth ) |
---|
692 | #endif |
---|
693 | { |
---|
694 | if ((pcCU->getPartitionSize(uiAbsPartIdx ) == SIZE_NxN) || pcCU->isIntra( uiAbsPartIdx )) |
---|
695 | { |
---|
696 | UInt uiIntraFlag = ( pcCU->isIntra(uiAbsPartIdx)); |
---|
697 | if (pcCU->getPartitionSize(uiAbsPartIdx ) == SIZE_2Nx2N) |
---|
698 | { |
---|
699 | xWriteFlag(1); |
---|
700 | } |
---|
701 | else |
---|
702 | { |
---|
703 | xWriteFlag(0); |
---|
704 | #if MTK_DISABLE_INTRA_NxN_SPLIT && !HHI_DISABLE_INTER_NxN_SPLIT |
---|
705 | if( uiDepth == g_uiMaxCUDepth - g_uiAddCUDepth ) |
---|
706 | #elif !MTK_DISABLE_INTRA_NxN_SPLIT && HHI_DISABLE_INTER_NxN_SPLIT |
---|
707 | if( uiDepth == g_uiMaxCUDepth - g_uiAddCUDepth ) |
---|
708 | #endif |
---|
709 | xWriteFlag( uiIntraFlag? 1 : 0 ); |
---|
710 | } |
---|
711 | |
---|
712 | return; |
---|
713 | } |
---|
714 | } |
---|
715 | } |
---|
716 | #else |
---|
717 | Void TEncCavlc::codePartSize( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth ) |
---|
718 | { |
---|
719 | PartSize eSize = pcCU->getPartitionSize( uiAbsPartIdx ); |
---|
720 | |
---|
721 | if ( pcCU->getSlice()->isInterB() && pcCU->isIntra( uiAbsPartIdx ) ) |
---|
722 | { |
---|
723 | xWriteFlag( 0 ); |
---|
724 | #if HHI_RMP_SWITCH |
---|
725 | if( pcCU->getSlice()->getSPS()->getUseRMP() ) |
---|
726 | #endif |
---|
727 | { |
---|
728 | xWriteFlag( 0 ); |
---|
729 | xWriteFlag( 0 ); |
---|
730 | } |
---|
731 | #if HHI_DISABLE_INTER_NxN_SPLIT |
---|
732 | if( pcCU->getWidth( uiAbsPartIdx ) == 8 ) |
---|
733 | { |
---|
734 | xWriteFlag( 0 ); |
---|
735 | } |
---|
736 | #else |
---|
737 | xWriteFlag( 0 ); |
---|
738 | #endif |
---|
739 | #if MTK_DISABLE_INTRA_NxN_SPLIT |
---|
740 | if( pcCU->getWidth( uiAbsPartIdx ) == 8 ) |
---|
741 | #endif |
---|
742 | { |
---|
743 | xWriteFlag( (eSize == SIZE_2Nx2N? 0 : 1) ); |
---|
744 | } |
---|
745 | #if LCEC_STAT |
---|
746 | if (m_bAdaptFlag) |
---|
747 | m_uiBitPartSize += 5; // TODO: this needs to be fixed according to macro settings |
---|
748 | #endif |
---|
749 | return; |
---|
750 | } |
---|
751 | |
---|
752 | if ( pcCU->isIntra( uiAbsPartIdx ) ) |
---|
753 | { |
---|
754 | #if MTK_DISABLE_INTRA_NxN_SPLIT |
---|
755 | if( pcCU->getWidth( uiAbsPartIdx ) == 8 ) |
---|
756 | #endif |
---|
757 | { |
---|
758 | xWriteFlag( eSize == SIZE_2Nx2N? 1 : 0 ); |
---|
759 | #if LCEC_STAT |
---|
760 | if (m_bAdaptFlag) |
---|
761 | m_uiBitPartSize += 1; |
---|
762 | #endif |
---|
763 | } |
---|
764 | return; |
---|
765 | } |
---|
766 | |
---|
767 | switch(eSize) |
---|
768 | { |
---|
769 | case SIZE_2Nx2N: |
---|
770 | { |
---|
771 | xWriteFlag( 1 ); |
---|
772 | #if LCEC_STAT |
---|
773 | if (m_bAdaptFlag) |
---|
774 | m_uiBitPartSize += 1; |
---|
775 | #endif |
---|
776 | break; |
---|
777 | } |
---|
778 | case SIZE_2NxN: |
---|
779 | { |
---|
780 | xWriteFlag( 0 ); |
---|
781 | xWriteFlag( 1 ); |
---|
782 | #if LCEC_STAT |
---|
783 | if (m_bAdaptFlag) |
---|
784 | m_uiBitPartSize += 2; |
---|
785 | #endif |
---|
786 | break; |
---|
787 | } |
---|
788 | case SIZE_Nx2N: |
---|
789 | { |
---|
790 | xWriteFlag( 0 ); |
---|
791 | xWriteFlag( 0 ); |
---|
792 | xWriteFlag( 1 ); |
---|
793 | #if LCEC_STAT |
---|
794 | if (m_bAdaptFlag) |
---|
795 | m_uiBitPartSize += 3; |
---|
796 | #endif |
---|
797 | break; |
---|
798 | } |
---|
799 | case SIZE_NxN: |
---|
800 | { |
---|
801 | #if HHI_DISABLE_INTER_NxN_SPLIT |
---|
802 | if( pcCU->getWidth( uiAbsPartIdx ) == 8 ) |
---|
803 | #endif |
---|
804 | { |
---|
805 | xWriteFlag( 0 ); |
---|
806 | #if HHI_RMP_SWITCH |
---|
807 | if( pcCU->getSlice()->getSPS()->getUseRMP()) |
---|
808 | #endif |
---|
809 | { |
---|
810 | xWriteFlag( 0 ); |
---|
811 | xWriteFlag( 0 ); |
---|
812 | } |
---|
813 | #if LCEC_STAT |
---|
814 | if (m_bAdaptFlag) |
---|
815 | m_uiBitPartSize += 3; |
---|
816 | #endif |
---|
817 | if (pcCU->getSlice()->isInterB()) |
---|
818 | { |
---|
819 | xWriteFlag( 1 ); |
---|
820 | } |
---|
821 | #if LCEC_STAT |
---|
822 | if (m_bAdaptFlag) |
---|
823 | m_uiBitPartSize += 1; |
---|
824 | #endif |
---|
825 | } |
---|
826 | break; |
---|
827 | } |
---|
828 | default: |
---|
829 | { |
---|
830 | assert(0); |
---|
831 | } |
---|
832 | } |
---|
833 | } |
---|
834 | #endif |
---|
835 | |
---|
836 | Void TEncCavlc::codePredMode( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
837 | { |
---|
838 | #if QC_LCEC_INTER_MODE |
---|
839 | codeInterModeFlag(pcCU, uiAbsPartIdx,(UInt)pcCU->getDepth(uiAbsPartIdx),2); |
---|
840 | return; |
---|
841 | #else |
---|
842 | // get context function is here |
---|
843 | Int iPredMode = pcCU->getPredictionMode( uiAbsPartIdx ); |
---|
844 | if ( pcCU->getSlice()->isInterB() ) |
---|
845 | { |
---|
846 | return; |
---|
847 | } |
---|
848 | |
---|
849 | if ( iPredMode != MODE_SKIP ) |
---|
850 | { |
---|
851 | xWriteFlag( iPredMode == MODE_INTER ? 0 : 1 ); |
---|
852 | #if LCEC_STAT |
---|
853 | if (m_bAdaptFlag) |
---|
854 | m_uiBitPredMode += 1; |
---|
855 | #endif |
---|
856 | } |
---|
857 | #endif |
---|
858 | } |
---|
859 | |
---|
860 | #if HHI_MRG |
---|
861 | Void TEncCavlc::codeMergeFlag ( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
862 | { |
---|
863 | #if QC_LCEC_INTER_MODE |
---|
864 | if (pcCU->getPartitionSize(uiAbsPartIdx) == SIZE_2Nx2N ) |
---|
865 | return; |
---|
866 | #endif |
---|
867 | UInt uiSymbol = pcCU->getMergeFlag( uiAbsPartIdx ) ? 1 : 0; |
---|
868 | xWriteFlag( uiSymbol ); |
---|
869 | #if LCEC_STAT |
---|
870 | if (m_bAdaptFlag) |
---|
871 | m_uiBitMergeFlag += 1; |
---|
872 | #endif |
---|
873 | } |
---|
874 | |
---|
875 | Void TEncCavlc::codeMergeIndex ( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
876 | { |
---|
877 | Bool bLeftInvolved = false; |
---|
878 | Bool bAboveInvolved = false; |
---|
879 | Bool bCollocatedInvolved = false; |
---|
880 | Bool bCornerInvolved = false; |
---|
881 | #if !HHI_MRG_LCEC_FIX |
---|
882 | Bool bCornerBLInvolved = false; |
---|
883 | #endif |
---|
884 | UInt uiNumCand = 0; |
---|
885 | for( UInt uiIter = 0; uiIter < HHI_NUM_MRG_CAND; ++uiIter ) |
---|
886 | { |
---|
887 | if( pcCU->getNeighbourCandIdx( uiIter, uiAbsPartIdx ) == uiIter + 1 ) |
---|
888 | { |
---|
889 | uiNumCand++; |
---|
890 | if( uiIter == 0 ) |
---|
891 | { |
---|
892 | bLeftInvolved = true; |
---|
893 | } |
---|
894 | else if( uiIter == 1 ) |
---|
895 | { |
---|
896 | bAboveInvolved = true; |
---|
897 | } |
---|
898 | else if( uiIter == 2 ) |
---|
899 | { |
---|
900 | bCollocatedInvolved = true; |
---|
901 | } |
---|
902 | else if( uiIter == 3 ) |
---|
903 | { |
---|
904 | bCornerInvolved = true; |
---|
905 | } |
---|
906 | #if !HHI_MRG_LCEC_FIX |
---|
907 | else if( uiIter == 4 ) |
---|
908 | { |
---|
909 | bCornerBLInvolved = true; |
---|
910 | } |
---|
911 | #endif |
---|
912 | } |
---|
913 | } |
---|
914 | assert( uiNumCand > 1 ); |
---|
915 | #if HHI_MRG_LCEC_FIX |
---|
916 | UInt uiUnaryIdx = pcCU->getMergeIndex( uiAbsPartIdx ); |
---|
917 | if( !bCornerInvolved && uiUnaryIdx > 3 ) |
---|
918 | { |
---|
919 | --uiUnaryIdx; |
---|
920 | } |
---|
921 | if( !bCollocatedInvolved && uiUnaryIdx > 2 ) |
---|
922 | { |
---|
923 | --uiUnaryIdx; |
---|
924 | } |
---|
925 | if( !bAboveInvolved && uiUnaryIdx > 1 ) |
---|
926 | { |
---|
927 | --uiUnaryIdx; |
---|
928 | } |
---|
929 | if( !bLeftInvolved && uiUnaryIdx > 0 ) |
---|
930 | { |
---|
931 | --uiUnaryIdx; |
---|
932 | } |
---|
933 | for( UInt ui = 0; ui < uiNumCand - 1; ++ui ) |
---|
934 | { |
---|
935 | const UInt uiSymbol = ui == uiUnaryIdx ? 0 : 1; |
---|
936 | xWriteFlag( uiSymbol ); |
---|
937 | if( uiSymbol == 0 ) |
---|
938 | { |
---|
939 | break; |
---|
940 | } |
---|
941 | } |
---|
942 | #else |
---|
943 | const UInt uiMergeIdx = pcCU->getMergeIndex( uiAbsPartIdx ); |
---|
944 | if( uiNumCand == 2 ) |
---|
945 | { |
---|
946 | UInt uiSymbol = 0; |
---|
947 | if( ( !bCornerInvolved && !bCornerBLInvolved && uiMergeIdx == 2 ) || ( !bCollocatedInvolved && !bCornerBLInvolved && !bCornerInvolved && uiMergeIdx == 1 ) || ( !bCornerBLInvolved && uiMergeIdx == 3 ) || uiMergeIdx == 4 ) |
---|
948 | { |
---|
949 | uiSymbol = 1; |
---|
950 | } |
---|
951 | xWriteFlag( uiSymbol ); |
---|
952 | return; |
---|
953 | } |
---|
954 | else if( uiNumCand == 3 )//uiMRGCands == 3 |
---|
955 | { |
---|
956 | if( uiMergeIdx == 0 || ( uiMergeIdx == 1 && !bLeftInvolved ) || ( uiMergeIdx == 2 && !bLeftInvolved && !bAboveInvolved ) ) |
---|
957 | { |
---|
958 | xWriteFlag( 0 ); |
---|
959 | } |
---|
960 | else |
---|
961 | { |
---|
962 | xWriteFlag( 1 ); |
---|
963 | if( uiMergeIdx == 4 || ( !bCornerBLInvolved && uiMergeIdx == 3 ) || ( !bCornerBLInvolved && !bCornerInvolved && uiMergeIdx == 2 ) ) |
---|
964 | { |
---|
965 | xWriteFlag( 1 ); |
---|
966 | } |
---|
967 | else |
---|
968 | { |
---|
969 | xWriteFlag( 0 ); |
---|
970 | } |
---|
971 | } |
---|
972 | } |
---|
973 | else //uiNumCand > 3 |
---|
974 | { |
---|
975 | if( uiMergeIdx == 0 ) |
---|
976 | { |
---|
977 | xWriteFlag( 0 ); |
---|
978 | } |
---|
979 | else |
---|
980 | { |
---|
981 | xWriteFlag( 1 ); |
---|
982 | if( uiMergeIdx == 1 ) |
---|
983 | { |
---|
984 | xWriteFlag( 0 ); |
---|
985 | } |
---|
986 | else |
---|
987 | { |
---|
988 | xWriteFlag( 1 ); |
---|
989 | if( uiMergeIdx == 2 ) |
---|
990 | { |
---|
991 | xWriteFlag( 0 ); |
---|
992 | } |
---|
993 | else |
---|
994 | { |
---|
995 | xWriteFlag( 1 ); |
---|
996 | if( uiMergeIdx == 3 ) |
---|
997 | { |
---|
998 | xWriteFlag( 0 ); |
---|
999 | } |
---|
1000 | else |
---|
1001 | { |
---|
1002 | xWriteFlag( 1 ); |
---|
1003 | } |
---|
1004 | } |
---|
1005 | } |
---|
1006 | } |
---|
1007 | } |
---|
1008 | #endif //HHI_MRG_LCEC_FIX |
---|
1009 | } |
---|
1010 | #endif //HHI_MRG |
---|
1011 | |
---|
1012 | Void TEncCavlc::codeAlfCtrlFlag( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
1013 | { |
---|
1014 | if (!m_bAlfCtrl) |
---|
1015 | return; |
---|
1016 | |
---|
1017 | if( pcCU->getDepth(uiAbsPartIdx) > m_uiMaxAlfCtrlDepth && !pcCU->isFirstAbsZorderIdxInDepth(uiAbsPartIdx, m_uiMaxAlfCtrlDepth)) |
---|
1018 | { |
---|
1019 | return; |
---|
1020 | } |
---|
1021 | |
---|
1022 | // get context function is here |
---|
1023 | UInt uiSymbol = pcCU->getAlfCtrlFlag( uiAbsPartIdx ) ? 1 : 0; |
---|
1024 | |
---|
1025 | xWriteFlag( uiSymbol ); |
---|
1026 | #if LCEC_STAT |
---|
1027 | if (m_bAdaptFlag) |
---|
1028 | m_uiBitAlfCtrlFlag += 1; |
---|
1029 | #endif |
---|
1030 | } |
---|
1031 | |
---|
1032 | Void TEncCavlc::codeAlfCtrlDepth() |
---|
1033 | { |
---|
1034 | if (!m_bAlfCtrl) |
---|
1035 | return; |
---|
1036 | |
---|
1037 | UInt uiDepth = m_uiMaxAlfCtrlDepth; |
---|
1038 | |
---|
1039 | #if LCEC_STAT |
---|
1040 | if (m_bAdaptFlag) |
---|
1041 | m_uiBitAlfCtrlDepth += xWriteUnaryMaxSymbol(uiDepth, g_uiMaxCUDepth-1); |
---|
1042 | else |
---|
1043 | #endif |
---|
1044 | xWriteUnaryMaxSymbol(uiDepth, g_uiMaxCUDepth-1); |
---|
1045 | } |
---|
1046 | #if QC_LCEC_INTER_MODE |
---|
1047 | Void TEncCavlc::codeInterModeFlag( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, UInt uiEncMode ) |
---|
1048 | { |
---|
1049 | Bool bHasSplit = ( uiDepth == g_uiMaxCUDepth - g_uiAddCUDepth )? 0 : 1; |
---|
1050 | UInt uiSplitFlag = ( pcCU->getDepth( uiAbsPartIdx ) > uiDepth ) ? 1 : 0; |
---|
1051 | UInt uiMode=0,uiControl=0; |
---|
1052 | if(!uiSplitFlag || !bHasSplit) |
---|
1053 | { |
---|
1054 | uiMode = 1; |
---|
1055 | uiControl = 1; |
---|
1056 | if (!pcCU->isSkipped(uiAbsPartIdx )) |
---|
1057 | { |
---|
1058 | uiControl = 2; |
---|
1059 | uiMode = 6; |
---|
1060 | if (pcCU->getPredictionMode(uiAbsPartIdx) == MODE_INTER) |
---|
1061 | { |
---|
1062 | if(pcCU->getPartitionSize(uiAbsPartIdx) == SIZE_2Nx2N) |
---|
1063 | uiMode=pcCU->getMergeFlag(uiAbsPartIdx) ? 2 : 3; |
---|
1064 | else |
---|
1065 | uiMode=3+(UInt)pcCU->getPartitionSize(uiAbsPartIdx); |
---|
1066 | } |
---|
1067 | } |
---|
1068 | } |
---|
1069 | if (uiEncMode != uiControl ) |
---|
1070 | return; |
---|
1071 | UInt uiEndSym = bHasSplit ? 7 : 6; |
---|
1072 | UInt uiLength = m_uiSplitTableE[uiDepth][uiMode] + 1; |
---|
1073 | if (uiLength == uiEndSym) |
---|
1074 | { |
---|
1075 | xWriteCode( 0, uiLength - 1); |
---|
1076 | } |
---|
1077 | else |
---|
1078 | { |
---|
1079 | xWriteCode( 1, uiLength ); |
---|
1080 | } |
---|
1081 | UInt x = uiMode; |
---|
1082 | UInt cx = m_uiSplitTableE[uiDepth][x]; |
---|
1083 | /* Adapt table */ |
---|
1084 | if ( m_bAdaptFlag) |
---|
1085 | { |
---|
1086 | if(cx>0) |
---|
1087 | { |
---|
1088 | UInt cy = Max(0,cx-1); |
---|
1089 | UInt y = m_uiSplitTableD[uiDepth][cy]; |
---|
1090 | m_uiSplitTableD[uiDepth][cy] = x; |
---|
1091 | m_uiSplitTableD[uiDepth][cx] = y; |
---|
1092 | m_uiSplitTableE[uiDepth][x] = cy; |
---|
1093 | m_uiSplitTableE[uiDepth][y] = cx; |
---|
1094 | } |
---|
1095 | } |
---|
1096 | return; |
---|
1097 | } |
---|
1098 | #endif |
---|
1099 | Void TEncCavlc::codeSkipFlag( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
1100 | { |
---|
1101 | #if QC_LCEC_INTER_MODE |
---|
1102 | codeInterModeFlag(pcCU,uiAbsPartIdx,(UInt)pcCU->getDepth(uiAbsPartIdx),1); |
---|
1103 | return; |
---|
1104 | #else |
---|
1105 | // get context function is here |
---|
1106 | UInt uiSymbol = pcCU->isSkipped( uiAbsPartIdx ) ? 1 : 0; |
---|
1107 | xWriteFlag( uiSymbol ); |
---|
1108 | #if LCEC_STAT |
---|
1109 | if (m_bAdaptFlag) |
---|
1110 | m_uiBitSkipFlag += 1; |
---|
1111 | #endif |
---|
1112 | #endif |
---|
1113 | } |
---|
1114 | |
---|
1115 | Void TEncCavlc::codeSplitFlag ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth ) |
---|
1116 | { |
---|
1117 | if( uiDepth == g_uiMaxCUDepth - g_uiAddCUDepth ) |
---|
1118 | return; |
---|
1119 | #if QC_LCEC_INTER_MODE |
---|
1120 | if (!pcCU->getSlice()->isIntra()) |
---|
1121 | { |
---|
1122 | codeInterModeFlag(pcCU,uiAbsPartIdx,uiDepth,0); |
---|
1123 | return; |
---|
1124 | } |
---|
1125 | #endif |
---|
1126 | UInt uiCurrSplitFlag = ( pcCU->getDepth( uiAbsPartIdx ) > uiDepth ) ? 1 : 0; |
---|
1127 | |
---|
1128 | xWriteFlag( uiCurrSplitFlag ); |
---|
1129 | #if LCEC_STAT |
---|
1130 | if (m_bAdaptFlag) |
---|
1131 | m_uiBitCurrSplitFlag += 1; |
---|
1132 | #endif |
---|
1133 | return; |
---|
1134 | } |
---|
1135 | |
---|
1136 | Void TEncCavlc::codeTransformSubdivFlag( UInt uiSymbol, UInt uiCtx ) |
---|
1137 | { |
---|
1138 | xWriteFlag( uiSymbol ); |
---|
1139 | #if LCEC_STAT |
---|
1140 | if (m_bAdaptFlag) |
---|
1141 | m_uiBitTransformSubdivFlag += 1; |
---|
1142 | #endif |
---|
1143 | } |
---|
1144 | |
---|
1145 | Void TEncCavlc::codeQtCbf( TComDataCU* pcCU, UInt uiAbsPartIdx, TextType eType, UInt uiTrDepth ) |
---|
1146 | { |
---|
1147 | UInt uiCbf = pcCU->getCbf( uiAbsPartIdx, eType, uiTrDepth ); |
---|
1148 | xWriteFlag( uiCbf ); |
---|
1149 | #if LCEC_STAT |
---|
1150 | if (m_bAdaptFlag) |
---|
1151 | m_uiBitQtCbf += 1; |
---|
1152 | #endif |
---|
1153 | } |
---|
1154 | |
---|
1155 | Void TEncCavlc::codeQtRootCbf( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
1156 | { |
---|
1157 | UInt uiCbf = pcCU->getQtRootCbf( uiAbsPartIdx ); |
---|
1158 | xWriteFlag( uiCbf ? 1 : 0 ); |
---|
1159 | } |
---|
1160 | |
---|
1161 | #if LCEC_INTRA_MODE |
---|
1162 | Void TEncCavlc::codeIntraDirLumaAng( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
1163 | { |
---|
1164 | Int iDir = pcCU->getLumaIntraDir( uiAbsPartIdx ); |
---|
1165 | Int iMostProbable = pcCU->getMostProbableIntraDirLuma( uiAbsPartIdx ); |
---|
1166 | Int iIntraIdx = pcCU->getIntraSizeIdx(uiAbsPartIdx); |
---|
1167 | UInt uiCode, uiLength; |
---|
1168 | Int iRankIntraMode, iRankIntraModeLarger, iDirLarger; |
---|
1169 | |
---|
1170 | UInt ind=(pcCU->getLeftIntraDirLuma( uiAbsPartIdx )==pcCU->getAboveIntraDirLuma( uiAbsPartIdx ))? 0 : 1; |
---|
1171 | |
---|
1172 | const UInt *huff17=huff17_2[ind]; |
---|
1173 | const UInt *lengthHuff17=lengthHuff17_2[ind]; |
---|
1174 | const UInt *huff34=huff34_2[ind]; |
---|
1175 | const UInt *lengthHuff34=lengthHuff34_2[ind]; |
---|
1176 | |
---|
1177 | if ( g_aucIntraModeBitsAng[iIntraIdx] < 5 ) |
---|
1178 | { |
---|
1179 | if (iDir == iMostProbable) |
---|
1180 | xWriteFlag( 1 ); |
---|
1181 | else{ |
---|
1182 | if (iDir>iMostProbable) |
---|
1183 | iDir--; |
---|
1184 | xWriteFlag( 0 ); |
---|
1185 | xWriteFlag( iDir & 0x01 ? 1 : 0 ); |
---|
1186 | if ( g_aucIntraModeBitsAng[iIntraIdx] > 2 ) xWriteFlag( iDir & 0x02 ? 1 : 0 ); |
---|
1187 | if ( g_aucIntraModeBitsAng[iIntraIdx] > 3 ) xWriteFlag( iDir & 0x04 ? 1 : 0 ); |
---|
1188 | } |
---|
1189 | } |
---|
1190 | else if ( g_aucIntraModeBitsAng[iIntraIdx] == 5 ){ |
---|
1191 | |
---|
1192 | if (iDir==iMostProbable){ |
---|
1193 | uiCode=huff17[0]; |
---|
1194 | uiLength=lengthHuff17[0]; |
---|
1195 | } |
---|
1196 | else{ |
---|
1197 | if (iDir>iMostProbable){ |
---|
1198 | iDir--; |
---|
1199 | } |
---|
1200 | iRankIntraMode=m_uiIntraModeTableE17[iDir]; |
---|
1201 | |
---|
1202 | uiCode=huff17[iRankIntraMode+1]; |
---|
1203 | uiLength=lengthHuff17[iRankIntraMode+1]; |
---|
1204 | |
---|
1205 | if ( m_bAdaptFlag ) |
---|
1206 | { |
---|
1207 | iRankIntraModeLarger = Max(0,iRankIntraMode-1); |
---|
1208 | iDirLarger = m_uiIntraModeTableD17[iRankIntraModeLarger]; |
---|
1209 | |
---|
1210 | m_uiIntraModeTableD17[iRankIntraModeLarger] = iDir; |
---|
1211 | m_uiIntraModeTableD17[iRankIntraMode] = iDirLarger; |
---|
1212 | m_uiIntraModeTableE17[iDir] = iRankIntraModeLarger; |
---|
1213 | m_uiIntraModeTableE17[iDirLarger] = iRankIntraMode; |
---|
1214 | } |
---|
1215 | } |
---|
1216 | xWriteCode(uiCode, uiLength); |
---|
1217 | } |
---|
1218 | else{ |
---|
1219 | if (iDir==iMostProbable){ |
---|
1220 | uiCode=huff34[0]; |
---|
1221 | uiLength=lengthHuff34[0]; |
---|
1222 | } |
---|
1223 | else{ |
---|
1224 | if (iDir>iMostProbable){ |
---|
1225 | iDir--; |
---|
1226 | } |
---|
1227 | iRankIntraMode=m_uiIntraModeTableE34[iDir]; |
---|
1228 | |
---|
1229 | uiCode=huff34[iRankIntraMode+1]; |
---|
1230 | uiLength=lengthHuff34[iRankIntraMode+1]; |
---|
1231 | |
---|
1232 | if ( m_bAdaptFlag ) |
---|
1233 | { |
---|
1234 | iRankIntraModeLarger = Max(0,iRankIntraMode-1); |
---|
1235 | iDirLarger = m_uiIntraModeTableD34[iRankIntraModeLarger]; |
---|
1236 | |
---|
1237 | m_uiIntraModeTableD34[iRankIntraModeLarger] = iDir; |
---|
1238 | m_uiIntraModeTableD34[iRankIntraMode] = iDirLarger; |
---|
1239 | m_uiIntraModeTableE34[iDir] = iRankIntraModeLarger; |
---|
1240 | m_uiIntraModeTableE34[iDirLarger] = iRankIntraMode; |
---|
1241 | } |
---|
1242 | } |
---|
1243 | |
---|
1244 | xWriteCode(uiCode, uiLength); |
---|
1245 | } |
---|
1246 | } |
---|
1247 | |
---|
1248 | #else |
---|
1249 | |
---|
1250 | Void TEncCavlc::codeIntraDirLumaAng( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
1251 | { |
---|
1252 | UInt uiDir = pcCU->getLumaIntraDir( uiAbsPartIdx ); |
---|
1253 | Int iMostProbable = pcCU->getMostProbableIntraDirLuma( uiAbsPartIdx ); |
---|
1254 | |
---|
1255 | if (uiDir == iMostProbable) |
---|
1256 | { |
---|
1257 | xWriteFlag( 1 ); |
---|
1258 | #if LCEC_STAT |
---|
1259 | if (m_bAdaptFlag) |
---|
1260 | m_uiBitIntraDir += 1; |
---|
1261 | #endif |
---|
1262 | } |
---|
1263 | else |
---|
1264 | { |
---|
1265 | xWriteFlag( 0 ); |
---|
1266 | #if LCEC_STAT |
---|
1267 | if (m_bAdaptFlag) |
---|
1268 | m_uiBitIntraDir += 1; |
---|
1269 | #endif |
---|
1270 | uiDir = uiDir > iMostProbable ? uiDir - 1 : uiDir; |
---|
1271 | Int iIntraIdx = pcCU->getIntraSizeIdx(uiAbsPartIdx); |
---|
1272 | if ( g_aucIntraModeBitsAng[iIntraIdx] < 6 ) |
---|
1273 | { |
---|
1274 | xWriteFlag( uiDir & 0x01 ? 1 : 0 ); |
---|
1275 | if ( g_aucIntraModeBitsAng[iIntraIdx] > 2 ) xWriteFlag( uiDir & 0x02 ? 1 : 0 ); |
---|
1276 | if ( g_aucIntraModeBitsAng[iIntraIdx] > 3 ) xWriteFlag( uiDir & 0x04 ? 1 : 0 ); |
---|
1277 | if ( g_aucIntraModeBitsAng[iIntraIdx] > 4 ) xWriteFlag( uiDir & 0x08 ? 1 : 0 ); |
---|
1278 | |
---|
1279 | #if LCEC_STAT |
---|
1280 | if (m_bAdaptFlag) |
---|
1281 | { |
---|
1282 | m_uiBitIntraDir += 1; |
---|
1283 | if ( g_aucIntraModeBitsAng[iIntraIdx] > 2 ) m_uiBitIntraDir += 1; |
---|
1284 | if ( g_aucIntraModeBitsAng[iIntraIdx] > 3 ) m_uiBitIntraDir += 1; |
---|
1285 | if ( g_aucIntraModeBitsAng[iIntraIdx] > 4 ) m_uiBitIntraDir += 1; |
---|
1286 | } |
---|
1287 | #endif |
---|
1288 | |
---|
1289 | } |
---|
1290 | else |
---|
1291 | { |
---|
1292 | if (uiDir < 31) |
---|
1293 | { // 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 |
---|
1294 | xWriteFlag( uiDir & 0x01 ? 1 : 0 ); |
---|
1295 | xWriteFlag( uiDir & 0x02 ? 1 : 0 ); |
---|
1296 | xWriteFlag( uiDir & 0x04 ? 1 : 0 ); |
---|
1297 | xWriteFlag( uiDir & 0x08 ? 1 : 0 ); |
---|
1298 | xWriteFlag( uiDir & 0x10 ? 1 : 0 ); |
---|
1299 | #if LCEC_STAT |
---|
1300 | if (m_bAdaptFlag) |
---|
1301 | m_uiBitIntraDir += 5; |
---|
1302 | #endif |
---|
1303 | } |
---|
1304 | else |
---|
1305 | { |
---|
1306 | xWriteFlag( 1 ); |
---|
1307 | xWriteFlag( 1 ); |
---|
1308 | xWriteFlag( 1 ); |
---|
1309 | xWriteFlag( 1 ); |
---|
1310 | xWriteFlag( 1 ); |
---|
1311 | xWriteFlag( uiDir == 32 ? 1 : 0 ); |
---|
1312 | #if LCEC_STAT |
---|
1313 | if (m_bAdaptFlag) |
---|
1314 | m_uiBitIntraDir += 6; |
---|
1315 | #endif |
---|
1316 | } |
---|
1317 | } |
---|
1318 | } |
---|
1319 | } |
---|
1320 | #endif |
---|
1321 | |
---|
1322 | Void TEncCavlc::codeIntraDirChroma( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
1323 | { |
---|
1324 | UInt uiIntraDirChroma = pcCU->getChromaIntraDir ( uiAbsPartIdx ); |
---|
1325 | #if CHROMA_CODEWORD |
---|
1326 | UInt uiMode = pcCU->getLumaIntraDir(uiAbsPartIdx); |
---|
1327 | Int iMax = uiMode < 4 ? 3 : 4; |
---|
1328 | |
---|
1329 | //switch codeword |
---|
1330 | if (uiIntraDirChroma == 4) |
---|
1331 | { |
---|
1332 | uiIntraDirChroma = 0; |
---|
1333 | } |
---|
1334 | #if CHROMA_CODEWORD_SWITCH |
---|
1335 | else |
---|
1336 | { |
---|
1337 | if (uiIntraDirChroma < uiMode) |
---|
1338 | { |
---|
1339 | uiIntraDirChroma++; |
---|
1340 | } |
---|
1341 | uiIntraDirChroma = ChromaMapping[iMax-3][uiIntraDirChroma]; |
---|
1342 | } |
---|
1343 | #else |
---|
1344 | else if (uiIntraDirChroma < uiMode) |
---|
1345 | { |
---|
1346 | uiIntraDirChroma++; |
---|
1347 | } |
---|
1348 | #endif |
---|
1349 | xWriteUnaryMaxSymbol( uiIntraDirChroma, iMax); |
---|
1350 | #else // CHROMA_CODEWORD |
---|
1351 | if ( 0 == uiIntraDirChroma ) |
---|
1352 | { |
---|
1353 | xWriteFlag( 0 ); |
---|
1354 | #if LCEC_STAT |
---|
1355 | if (m_bAdaptFlag) |
---|
1356 | m_uiBitIntraDir += 1; |
---|
1357 | #endif |
---|
1358 | } |
---|
1359 | else |
---|
1360 | { |
---|
1361 | xWriteFlag( 1 ); |
---|
1362 | #if LCEC_STAT |
---|
1363 | if (m_bAdaptFlag) |
---|
1364 | { |
---|
1365 | m_uiBitIntraDir += 1; |
---|
1366 | m_uiBitIntraDir += xWriteUnaryMaxSymbol( uiIntraDirChroma - 1, 3 ); |
---|
1367 | } |
---|
1368 | else |
---|
1369 | #endif |
---|
1370 | xWriteUnaryMaxSymbol( uiIntraDirChroma - 1, 3 ); |
---|
1371 | } |
---|
1372 | #endif |
---|
1373 | return; |
---|
1374 | } |
---|
1375 | |
---|
1376 | Void TEncCavlc::codeInterDir( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
1377 | { |
---|
1378 | UInt uiInterDir = pcCU->getInterDir ( uiAbsPartIdx ); |
---|
1379 | uiInterDir--; |
---|
1380 | |
---|
1381 | #if MS_LCEC_LOOKUP_TABLE_EXCEPTION |
---|
1382 | if ( pcCU->getSlice()->getRefIdxCombineCoding() ) |
---|
1383 | #else |
---|
1384 | if(pcCU->getSlice()->getNumRefIdx( REF_PIC_LIST_0 ) <= 2 && pcCU->getSlice()->getNumRefIdx( REF_PIC_LIST_1 ) <= 2) |
---|
1385 | #endif |
---|
1386 | { |
---|
1387 | Int x,cx,y,cy; |
---|
1388 | Int iRefFrame0,iRefFrame1; |
---|
1389 | UInt uiIndex; |
---|
1390 | |
---|
1391 | UInt *m_uiMITableE; |
---|
1392 | UInt *m_uiMITableD; |
---|
1393 | { |
---|
1394 | m_uiMITableE = m_uiMI1TableE; |
---|
1395 | m_uiMITableD = m_uiMI1TableD; |
---|
1396 | if (uiInterDir==0) |
---|
1397 | { |
---|
1398 | #if DCM_COMB_LIST |
---|
1399 | if(pcCU->getSlice()->getNumRefIdx(REF_PIC_LIST_C) > 0) |
---|
1400 | { |
---|
1401 | iRefFrame0 = pcCU->getSlice()->getRefIdxOfLC(REF_PIC_LIST_0, pcCU->getCUMvField( REF_PIC_LIST_0 )->getRefIdx( uiAbsPartIdx )); |
---|
1402 | } |
---|
1403 | else |
---|
1404 | { |
---|
1405 | iRefFrame0 = pcCU->getCUMvField( REF_PIC_LIST_0 )->getRefIdx( uiAbsPartIdx ); |
---|
1406 | } |
---|
1407 | #else |
---|
1408 | iRefFrame0 = pcCU->getCUMvField( REF_PIC_LIST_0 )->getRefIdx( uiAbsPartIdx ); |
---|
1409 | #endif |
---|
1410 | uiIndex = iRefFrame0; |
---|
1411 | |
---|
1412 | #if MS_LCEC_LOOKUP_TABLE_EXCEPTION |
---|
1413 | if(pcCU->getSlice()->getNumRefIdx(REF_PIC_LIST_C) > 0) |
---|
1414 | { |
---|
1415 | if ( iRefFrame0 >= 4 ) |
---|
1416 | { |
---|
1417 | uiIndex = 8; |
---|
1418 | } |
---|
1419 | } |
---|
1420 | else |
---|
1421 | { |
---|
1422 | if ( iRefFrame0 > MS_LCEC_UNI_EXCEPTION_THRES ) |
---|
1423 | { |
---|
1424 | uiIndex = 8; |
---|
1425 | } |
---|
1426 | } |
---|
1427 | #endif |
---|
1428 | } |
---|
1429 | else if (uiInterDir==1) |
---|
1430 | { |
---|
1431 | #if DCM_COMB_LIST |
---|
1432 | if(pcCU->getSlice()->getNumRefIdx(REF_PIC_LIST_C) > 0) |
---|
1433 | { |
---|
1434 | iRefFrame1 = pcCU->getSlice()->getRefIdxOfLC(REF_PIC_LIST_1, pcCU->getCUMvField( REF_PIC_LIST_1 )->getRefIdx( uiAbsPartIdx )); |
---|
1435 | uiIndex = iRefFrame1; |
---|
1436 | } |
---|
1437 | else |
---|
1438 | { |
---|
1439 | iRefFrame1 = pcCU->getCUMvField( REF_PIC_LIST_1 )->getRefIdx( uiAbsPartIdx ); |
---|
1440 | uiIndex = 2 + iRefFrame1; |
---|
1441 | } |
---|
1442 | #if MS_LCEC_LOOKUP_TABLE_EXCEPTION |
---|
1443 | if(pcCU->getSlice()->getNumRefIdx(REF_PIC_LIST_C) > 0) |
---|
1444 | { |
---|
1445 | if ( iRefFrame1 >= 4 ) |
---|
1446 | { |
---|
1447 | uiIndex = 8; |
---|
1448 | } |
---|
1449 | } |
---|
1450 | else |
---|
1451 | { |
---|
1452 | if ( iRefFrame1 > MS_LCEC_UNI_EXCEPTION_THRES ) |
---|
1453 | { |
---|
1454 | uiIndex = 8; |
---|
1455 | } |
---|
1456 | } |
---|
1457 | #endif |
---|
1458 | #else |
---|
1459 | iRefFrame1 = pcCU->getCUMvField( REF_PIC_LIST_1 )->getRefIdx( uiAbsPartIdx ); |
---|
1460 | uiIndex = 2 + iRefFrame1; |
---|
1461 | #endif |
---|
1462 | } |
---|
1463 | else |
---|
1464 | { |
---|
1465 | iRefFrame0 = pcCU->getCUMvField( REF_PIC_LIST_0 )->getRefIdx( uiAbsPartIdx ); |
---|
1466 | iRefFrame1 = pcCU->getCUMvField( REF_PIC_LIST_1 )->getRefIdx( uiAbsPartIdx ); |
---|
1467 | uiIndex = 4 + 2*iRefFrame0 + iRefFrame1; |
---|
1468 | #if MS_LCEC_LOOKUP_TABLE_EXCEPTION |
---|
1469 | if ( iRefFrame0 >= 2 || iRefFrame1 >= 2 ) |
---|
1470 | { |
---|
1471 | uiIndex = 8; |
---|
1472 | } |
---|
1473 | #endif |
---|
1474 | } |
---|
1475 | } |
---|
1476 | |
---|
1477 | x = uiIndex; |
---|
1478 | |
---|
1479 | cx = m_uiMITableE[x]; |
---|
1480 | |
---|
1481 | /* Adapt table */ |
---|
1482 | #if !MS_LCEC_LOOKUP_TABLE_MAX_VALUE |
---|
1483 | UInt vlcn = g_auiMITableVlcNum[m_uiMITableVlcIdx]; |
---|
1484 | #endif |
---|
1485 | if ( m_bAdaptFlag ) |
---|
1486 | { |
---|
1487 | cy = Max(0,cx-1); |
---|
1488 | y = m_uiMITableD[cy]; |
---|
1489 | m_uiMITableD[cy] = x; |
---|
1490 | m_uiMITableD[cx] = y; |
---|
1491 | m_uiMITableE[x] = cy; |
---|
1492 | m_uiMITableE[y] = cx; |
---|
1493 | m_uiMITableVlcIdx += cx == m_uiMITableVlcIdx ? 0 : (cx < m_uiMITableVlcIdx ? -1 : 1); |
---|
1494 | } |
---|
1495 | |
---|
1496 | #if LCEC_STAT |
---|
1497 | if (m_bAdaptFlag) |
---|
1498 | m_uiBitMI += xWriteVlc( vlcn, cx ); |
---|
1499 | else |
---|
1500 | #endif |
---|
1501 | { |
---|
1502 | #if MS_LCEC_LOOKUP_TABLE_MAX_VALUE |
---|
1503 | UInt uiMaxVal = 7; |
---|
1504 | #if MS_LCEC_LOOKUP_TABLE_EXCEPTION |
---|
1505 | uiMaxVal = 8; |
---|
1506 | #endif |
---|
1507 | if ( pcCU->getSlice()->getNumRefIdx( REF_PIC_LIST_0 ) <= 1 && pcCU->getSlice()->getNumRefIdx( REF_PIC_LIST_1 ) <= 1 ) |
---|
1508 | { |
---|
1509 | if ( pcCU->getSlice()->getNoBackPredFlag() || ( pcCU->getSlice()->getNumRefIdx(REF_PIC_LIST_C) > 0 && pcCU->getSlice()->getNumRefIdx(REF_PIC_LIST_C) <= 1 ) ) |
---|
1510 | { |
---|
1511 | uiMaxVal = 1; |
---|
1512 | } |
---|
1513 | else |
---|
1514 | { |
---|
1515 | uiMaxVal = 2; |
---|
1516 | } |
---|
1517 | } |
---|
1518 | else if ( pcCU->getSlice()->getNumRefIdx( REF_PIC_LIST_0 ) <= 2 && pcCU->getSlice()->getNumRefIdx( REF_PIC_LIST_1 ) <= 2 ) |
---|
1519 | { |
---|
1520 | if ( pcCU->getSlice()->getNoBackPredFlag() || ( pcCU->getSlice()->getNumRefIdx(REF_PIC_LIST_C) > 0 && pcCU->getSlice()->getNumRefIdx(REF_PIC_LIST_C) <= 2 ) ) |
---|
1521 | { |
---|
1522 | uiMaxVal = 5; |
---|
1523 | } |
---|
1524 | else |
---|
1525 | { |
---|
1526 | uiMaxVal = 7; |
---|
1527 | } |
---|
1528 | } |
---|
1529 | else if ( pcCU->getSlice()->getNumRefIdx(REF_PIC_LIST_C) <= 0 ) // GPB case |
---|
1530 | { |
---|
1531 | uiMaxVal = 4+1+MS_LCEC_UNI_EXCEPTION_THRES; |
---|
1532 | } |
---|
1533 | |
---|
1534 | xWriteUnaryMaxSymbol( cx, uiMaxVal ); |
---|
1535 | #else |
---|
1536 | xWriteVlc( vlcn, cx ); |
---|
1537 | #endif |
---|
1538 | } |
---|
1539 | |
---|
1540 | #if MS_LCEC_LOOKUP_TABLE_EXCEPTION |
---|
1541 | if ( x<8 ) |
---|
1542 | #endif |
---|
1543 | { |
---|
1544 | return; |
---|
1545 | } |
---|
1546 | } |
---|
1547 | |
---|
1548 | xWriteFlag( ( uiInterDir == 2 ? 1 : 0 )); |
---|
1549 | #if LCEC_STAT |
---|
1550 | if (m_bAdaptFlag) |
---|
1551 | m_uiBitInterDir += 1; |
---|
1552 | #endif |
---|
1553 | #if MS_NO_BACK_PRED_IN_B0 |
---|
1554 | if ( pcCU->getSlice()->getNoBackPredFlag() ) |
---|
1555 | { |
---|
1556 | assert( uiInterDir != 1 ); |
---|
1557 | return; |
---|
1558 | } |
---|
1559 | #endif |
---|
1560 | #if DCM_COMB_LIST |
---|
1561 | if ( uiInterDir < 2 && pcCU->getSlice()->getNumRefIdx(REF_PIC_LIST_C) <= 0) |
---|
1562 | #else |
---|
1563 | if ( uiInterDir < 2 ) |
---|
1564 | #endif |
---|
1565 | { |
---|
1566 | xWriteFlag( uiInterDir ); |
---|
1567 | #if LCEC_STAT |
---|
1568 | if (m_bAdaptFlag) |
---|
1569 | m_uiBitInterDir += 1; |
---|
1570 | #endif |
---|
1571 | } |
---|
1572 | |
---|
1573 | return; |
---|
1574 | } |
---|
1575 | |
---|
1576 | Void TEncCavlc::codeRefFrmIdx( TComDataCU* pcCU, UInt uiAbsPartIdx, RefPicList eRefList ) |
---|
1577 | { |
---|
1578 | #if DCM_COMB_LIST |
---|
1579 | Int iRefFrame; |
---|
1580 | RefPicList eRefListTemp; |
---|
1581 | |
---|
1582 | if( pcCU->getSlice()->getNumRefIdx(REF_PIC_LIST_C)>0) |
---|
1583 | { |
---|
1584 | if ( pcCU->getInterDir( uiAbsPartIdx ) != 3) |
---|
1585 | { |
---|
1586 | eRefListTemp = REF_PIC_LIST_C; |
---|
1587 | iRefFrame = pcCU->getSlice()->getRefIdxOfLC(eRefList, pcCU->getCUMvField( eRefList )->getRefIdx( uiAbsPartIdx )); |
---|
1588 | } |
---|
1589 | else |
---|
1590 | { |
---|
1591 | eRefListTemp = eRefList; |
---|
1592 | iRefFrame = pcCU->getCUMvField( eRefList )->getRefIdx( uiAbsPartIdx ); |
---|
1593 | } |
---|
1594 | } |
---|
1595 | else |
---|
1596 | { |
---|
1597 | eRefListTemp = eRefList; |
---|
1598 | iRefFrame = pcCU->getCUMvField( eRefList )->getRefIdx( uiAbsPartIdx ); |
---|
1599 | } |
---|
1600 | #else |
---|
1601 | Int iRefFrame = pcCU->getCUMvField( eRefList )->getRefIdx( uiAbsPartIdx ); |
---|
1602 | #endif |
---|
1603 | |
---|
1604 | if (pcCU->getSlice()->getNumRefIdx( REF_PIC_LIST_0 ) <= 2 && pcCU->getSlice()->getNumRefIdx( REF_PIC_LIST_1 ) <= 2 && pcCU->getSlice()->isInterB()) |
---|
1605 | { |
---|
1606 | return; |
---|
1607 | } |
---|
1608 | |
---|
1609 | #if MS_LCEC_LOOKUP_TABLE_EXCEPTION |
---|
1610 | if ( pcCU->getSlice()->getRefIdxCombineCoding() && pcCU->getInterDir(uiAbsPartIdx)==3 && |
---|
1611 | pcCU->getCUMvField( REF_PIC_LIST_0 )->getRefIdx( uiAbsPartIdx ) < 2 && |
---|
1612 | pcCU->getCUMvField( REF_PIC_LIST_1 )->getRefIdx( uiAbsPartIdx ) < 2 ) |
---|
1613 | { |
---|
1614 | return; |
---|
1615 | } |
---|
1616 | else if ( pcCU->getSlice()->getRefIdxCombineCoding() && pcCU->getInterDir(uiAbsPartIdx)==1 && |
---|
1617 | ( ( pcCU->getSlice()->getNumRefIdx(REF_PIC_LIST_C)>0 && pcCU->getSlice()->getRefIdxOfLC(REF_PIC_LIST_0, pcCU->getCUMvField( REF_PIC_LIST_0 )->getRefIdx( uiAbsPartIdx )) < 4 ) || |
---|
1618 | ( pcCU->getSlice()->getNumRefIdx(REF_PIC_LIST_C)<=0 && pcCU->getCUMvField( REF_PIC_LIST_0 )->getRefIdx( uiAbsPartIdx ) <= MS_LCEC_UNI_EXCEPTION_THRES ) ) ) |
---|
1619 | { |
---|
1620 | return; |
---|
1621 | } |
---|
1622 | 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 ) |
---|
1623 | { |
---|
1624 | return; |
---|
1625 | } |
---|
1626 | |
---|
1627 | UInt uiRefFrmIdxMinus = 0; |
---|
1628 | if ( pcCU->getSlice()->getRefIdxCombineCoding() ) |
---|
1629 | { |
---|
1630 | if ( pcCU->getInterDir( uiAbsPartIdx ) != 3 ) |
---|
1631 | { |
---|
1632 | if ( pcCU->getSlice()->getNumRefIdx(REF_PIC_LIST_C) > 0 ) |
---|
1633 | { |
---|
1634 | uiRefFrmIdxMinus = 4; |
---|
1635 | assert( iRefFrame >=4 ); |
---|
1636 | } |
---|
1637 | else |
---|
1638 | { |
---|
1639 | uiRefFrmIdxMinus = MS_LCEC_UNI_EXCEPTION_THRES+1; |
---|
1640 | assert( iRefFrame > MS_LCEC_UNI_EXCEPTION_THRES ); |
---|
1641 | } |
---|
1642 | |
---|
1643 | } |
---|
1644 | else if ( eRefList == REF_PIC_LIST_1 && pcCU->getCUMvField( REF_PIC_LIST_0 )->getRefIdx( uiAbsPartIdx ) < 2 ) |
---|
1645 | { |
---|
1646 | uiRefFrmIdxMinus = 2; |
---|
1647 | assert( iRefFrame >= 2 ); |
---|
1648 | } |
---|
1649 | } |
---|
1650 | |
---|
1651 | if ( pcCU->getSlice()->getNumRefIdx( eRefListTemp ) - uiRefFrmIdxMinus <= 1 ) |
---|
1652 | { |
---|
1653 | return; |
---|
1654 | } |
---|
1655 | xWriteFlag( ( iRefFrame - uiRefFrmIdxMinus == 0 ? 0 : 1 ) ); |
---|
1656 | #else |
---|
1657 | xWriteFlag( ( iRefFrame == 0 ? 0 : 1 ) ); |
---|
1658 | #endif |
---|
1659 | |
---|
1660 | #if LCEC_STAT |
---|
1661 | if (m_bAdaptFlag) |
---|
1662 | m_uiBitIRefFrmIdx += 1; |
---|
1663 | #endif |
---|
1664 | |
---|
1665 | #if MS_LCEC_LOOKUP_TABLE_EXCEPTION |
---|
1666 | if ( iRefFrame - uiRefFrmIdxMinus > 0 ) |
---|
1667 | #else |
---|
1668 | if ( iRefFrame > 0 ) |
---|
1669 | #endif |
---|
1670 | { |
---|
1671 | #if LCEC_STAT |
---|
1672 | if (m_bAdaptFlag) |
---|
1673 | { |
---|
1674 | #if DCM_COMB_LIST |
---|
1675 | #if MS_LCEC_LOOKUP_TABLE_EXCEPTION |
---|
1676 | m_uiBitIRefFrmIdx += xWriteUnaryMaxSymbol( iRefFrame - 1 - uiRefFrmIdxMinus, pcCU->getSlice()->getNumRefIdx( eRefListTemp )-2 - uiRefFrmIdxMinus ); |
---|
1677 | #else |
---|
1678 | m_uiBitIRefFrmIdx += xWriteUnaryMaxSymbol( iRefFrame - 1, pcCU->getSlice()->getNumRefIdx( eRefListTemp )-2 ); |
---|
1679 | #endif |
---|
1680 | #else |
---|
1681 | #if MS_LCEC_LOOKUP_TABLE_EXCEPTION |
---|
1682 | m_uiBitIRefFrmIdx += xWriteUnaryMaxSymbol( iRefFrame - 1 - uiRefFrmIdxMinus, pcCU->getSlice()->getNumRefIdx( eRefList )-2 - uiRefFrmIdxMinus ); |
---|
1683 | #else |
---|
1684 | m_uiBitIRefFrmIdx += xWriteUnaryMaxSymbol( iRefFrame - 1, pcCU->getSlice()->getNumRefIdx( eRefList )-2 ); |
---|
1685 | #endif |
---|
1686 | #endif |
---|
1687 | } |
---|
1688 | else |
---|
1689 | #endif |
---|
1690 | { |
---|
1691 | #if DCM_COMB_LIST |
---|
1692 | #if MS_LCEC_LOOKUP_TABLE_EXCEPTION |
---|
1693 | xWriteUnaryMaxSymbol( iRefFrame - 1 - uiRefFrmIdxMinus, pcCU->getSlice()->getNumRefIdx( eRefListTemp )-2 - uiRefFrmIdxMinus ); |
---|
1694 | #else |
---|
1695 | xWriteUnaryMaxSymbol( iRefFrame - 1, pcCU->getSlice()->getNumRefIdx( eRefListTemp )-2 ); |
---|
1696 | #endif |
---|
1697 | #else |
---|
1698 | #if MS_LCEC_LOOKUP_TABLE_EXCEPTION |
---|
1699 | xWriteUnaryMaxSymbol( iRefFrame - 1 - uiRefFrmIdxMinus, pcCU->getSlice()->getNumRefIdx( eRefList )-2 - uiRefFrmIdxMinus ); |
---|
1700 | #else |
---|
1701 | xWriteUnaryMaxSymbol( iRefFrame - 1, pcCU->getSlice()->getNumRefIdx( eRefList )-2 ); |
---|
1702 | #endif |
---|
1703 | #endif |
---|
1704 | } |
---|
1705 | } |
---|
1706 | return; |
---|
1707 | } |
---|
1708 | |
---|
1709 | Void TEncCavlc::codeMvd( TComDataCU* pcCU, UInt uiAbsPartIdx, RefPicList eRefList ) |
---|
1710 | { |
---|
1711 | TComCUMvField* pcCUMvField = pcCU->getCUMvField( eRefList ); |
---|
1712 | Int iHor = pcCUMvField->getMvd( uiAbsPartIdx ).getHor(); |
---|
1713 | Int iVer = pcCUMvField->getMvd( uiAbsPartIdx ).getVer(); |
---|
1714 | |
---|
1715 | UInt uiAbsPartIdxL, uiAbsPartIdxA; |
---|
1716 | Int iHorPred, iVerPred; |
---|
1717 | |
---|
1718 | TComDataCU* pcCUL = pcCU->getPULeft ( uiAbsPartIdxL, pcCU->getZorderIdxInCU() + uiAbsPartIdx ); |
---|
1719 | TComDataCU* pcCUA = pcCU->getPUAbove( uiAbsPartIdxA, pcCU->getZorderIdxInCU() + uiAbsPartIdx ); |
---|
1720 | |
---|
1721 | TComCUMvField* pcCUMvFieldL = ( pcCUL == NULL || pcCUL->isIntra( uiAbsPartIdxL ) ) ? NULL : pcCUL->getCUMvField( eRefList ); |
---|
1722 | TComCUMvField* pcCUMvFieldA = ( pcCUA == NULL || pcCUA->isIntra( uiAbsPartIdxA ) ) ? NULL : pcCUA->getCUMvField( eRefList ); |
---|
1723 | iHorPred = ( (pcCUMvFieldL == NULL) ? 0 : pcCUMvFieldL->getMvd( uiAbsPartIdxL ).getAbsHor() ) + |
---|
1724 | ( (pcCUMvFieldA == NULL) ? 0 : pcCUMvFieldA->getMvd( uiAbsPartIdxA ).getAbsHor() ); |
---|
1725 | iVerPred = ( (pcCUMvFieldL == NULL) ? 0 : pcCUMvFieldL->getMvd( uiAbsPartIdxL ).getAbsVer() ) + |
---|
1726 | ( (pcCUMvFieldA == NULL) ? 0 : pcCUMvFieldA->getMvd( uiAbsPartIdxA ).getAbsVer() ); |
---|
1727 | |
---|
1728 | #if LCEC_STAT |
---|
1729 | if (m_bAdaptFlag) |
---|
1730 | m_uiBitMVD += xWriteSvlc( iHor); |
---|
1731 | else |
---|
1732 | xWriteSvlc( iHor); |
---|
1733 | if (m_bAdaptFlag) |
---|
1734 | m_uiBitMVD += xWriteSvlc( iVer); |
---|
1735 | else |
---|
1736 | xWriteSvlc( iVer); |
---|
1737 | #else |
---|
1738 | xWriteSvlc( iHor ); |
---|
1739 | xWriteSvlc( iVer ); |
---|
1740 | #endif |
---|
1741 | |
---|
1742 | return; |
---|
1743 | } |
---|
1744 | |
---|
1745 | Void TEncCavlc::codeDeltaQP( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
1746 | { |
---|
1747 | Int iDQp = pcCU->getQP( uiAbsPartIdx ) - pcCU->getSlice()->getSliceQp(); |
---|
1748 | |
---|
1749 | #if LCEC_STAT |
---|
1750 | if (m_bAdaptFlag) |
---|
1751 | m_uiBitDeltaQP += 1; |
---|
1752 | #endif |
---|
1753 | |
---|
1754 | if ( iDQp == 0 ) |
---|
1755 | { |
---|
1756 | xWriteFlag( 0 ); |
---|
1757 | } |
---|
1758 | else |
---|
1759 | { |
---|
1760 | xWriteFlag( 1 ); |
---|
1761 | #if LCEC_STAT |
---|
1762 | if (m_bAdaptFlag) |
---|
1763 | m_uiBitDeltaQP += xWriteSvlc( iDQp ); |
---|
1764 | else |
---|
1765 | #endif |
---|
1766 | xWriteSvlc( iDQp ); |
---|
1767 | } |
---|
1768 | |
---|
1769 | return; |
---|
1770 | } |
---|
1771 | |
---|
1772 | #if LCEC_CBP_YUV_ROOT |
---|
1773 | Void TEncCavlc::codeCbf( TComDataCU* pcCU, UInt uiAbsPartIdx, TextType eType, UInt uiTrDepth ) |
---|
1774 | { |
---|
1775 | if (eType == TEXT_ALL) |
---|
1776 | { |
---|
1777 | Int n,x,cx,y,cy; |
---|
1778 | UInt uiCBFY = pcCU->getCbf(uiAbsPartIdx, TEXT_LUMA, 0); |
---|
1779 | UInt uiCBFU = pcCU->getCbf(uiAbsPartIdx, TEXT_CHROMA_U, 0); |
---|
1780 | UInt uiCBFV = pcCU->getCbf(uiAbsPartIdx, TEXT_CHROMA_V, 0); |
---|
1781 | UInt uiCBP = (uiCBFV<<2) + (uiCBFU<<1) + (uiCBFY<<0); |
---|
1782 | |
---|
1783 | /* Start adaptation */ |
---|
1784 | n = pcCU->isIntra( uiAbsPartIdx ) ? 0 : 1; |
---|
1785 | x = uiCBP; |
---|
1786 | cx = m_uiCBPTableE[n][x]; |
---|
1787 | |
---|
1788 | UInt vlcn = g_auiCbpVlcNum[n][m_uiCbpVlcIdx[n]]; |
---|
1789 | |
---|
1790 | if ( m_bAdaptFlag ) |
---|
1791 | { |
---|
1792 | |
---|
1793 | cy = Max(0,cx-1); |
---|
1794 | y = m_uiCBPTableD[n][cy]; |
---|
1795 | m_uiCBPTableD[n][cy] = x; |
---|
1796 | m_uiCBPTableD[n][cx] = y; |
---|
1797 | m_uiCBPTableE[n][x] = cy; |
---|
1798 | m_uiCBPTableE[n][y] = cx; |
---|
1799 | m_uiCbpVlcIdx[n] += cx == m_uiCbpVlcIdx[n] ? 0 : (cx < m_uiCbpVlcIdx[n] ? -1 : 1); |
---|
1800 | } |
---|
1801 | #if LCEC_STAT |
---|
1802 | if (m_bAdaptFlag) |
---|
1803 | m_uiBitCbp += xWriteVlc( vlcn, cx ); |
---|
1804 | else |
---|
1805 | #endif |
---|
1806 | xWriteVlc( vlcn, cx ); |
---|
1807 | } |
---|
1808 | } |
---|
1809 | |
---|
1810 | Void TEncCavlc::codeBlockCbf( TComDataCU* pcCU, UInt uiAbsPartIdx, TextType eType, UInt uiTrDepth, UInt uiQPartNum, Bool bRD ) |
---|
1811 | { |
---|
1812 | UInt uiCbf0 = pcCU->getCbf ( uiAbsPartIdx, eType, uiTrDepth ); |
---|
1813 | UInt uiCbf1 = pcCU->getCbf ( uiAbsPartIdx + uiQPartNum, eType, uiTrDepth ); |
---|
1814 | UInt uiCbf2 = pcCU->getCbf ( uiAbsPartIdx + uiQPartNum*2, eType, uiTrDepth ); |
---|
1815 | UInt uiCbf3 = pcCU->getCbf ( uiAbsPartIdx + uiQPartNum*3, eType, uiTrDepth ); |
---|
1816 | UInt uiCbf = (uiCbf0<<3) | (uiCbf1<<2) | (uiCbf2<<1) | uiCbf3; |
---|
1817 | |
---|
1818 | assert(uiTrDepth > 0); |
---|
1819 | |
---|
1820 | #if QC_BLK_CBP |
---|
1821 | if(bRD && uiCbf==0) |
---|
1822 | { |
---|
1823 | xWriteCode(0, 4); |
---|
1824 | return; |
---|
1825 | } |
---|
1826 | |
---|
1827 | assert(uiCbf > 0); |
---|
1828 | |
---|
1829 | uiCbf --; |
---|
1830 | |
---|
1831 | Int x,cx,y,cy; |
---|
1832 | |
---|
1833 | UInt n = (pcCU->isIntra(uiAbsPartIdx) && eType == TEXT_LUMA)? 0:1; |
---|
1834 | cx = m_uiBlkCBPTableE[n][uiCbf]; |
---|
1835 | x = uiCbf; |
---|
1836 | UInt vlcn = (n==0)?g_auiBlkCbpVlcNum[m_uiBlkCbpVlcIdx]:11; |
---|
1837 | |
---|
1838 | if ( m_bAdaptFlag ) |
---|
1839 | { |
---|
1840 | cy = Max(0,cx-1); |
---|
1841 | y = m_uiBlkCBPTableD[n][cy]; |
---|
1842 | m_uiBlkCBPTableD[n][cy] = x; |
---|
1843 | m_uiBlkCBPTableD[n][cx] = y; |
---|
1844 | m_uiBlkCBPTableE[n][x] = cy; |
---|
1845 | m_uiBlkCBPTableE[n][y] = cx; |
---|
1846 | if(n==0) |
---|
1847 | m_uiBlkCbpVlcIdx += cx == m_uiBlkCbpVlcIdx ? 0 : (cx < m_uiBlkCbpVlcIdx ? -1 : 1); |
---|
1848 | |
---|
1849 | } |
---|
1850 | |
---|
1851 | xWriteVlc( vlcn, cx ); |
---|
1852 | return; |
---|
1853 | #else |
---|
1854 | xWriteCode(uiCbf, 4); |
---|
1855 | #endif |
---|
1856 | } |
---|
1857 | #endif |
---|
1858 | |
---|
1859 | Void TEncCavlc::codeCoeffNxN ( TComDataCU* pcCU, TCoeff* pcCoef, UInt uiAbsPartIdx, UInt uiWidth, UInt uiHeight, UInt uiDepth, TextType eTType, Bool bRD ) |
---|
1860 | { |
---|
1861 | if ( uiWidth > m_pcSlice->getSPS()->getMaxTrSize() ) |
---|
1862 | { |
---|
1863 | uiWidth = m_pcSlice->getSPS()->getMaxTrSize(); |
---|
1864 | uiHeight = m_pcSlice->getSPS()->getMaxTrSize(); |
---|
1865 | } |
---|
1866 | UInt uiSize = uiWidth*uiHeight; |
---|
1867 | |
---|
1868 | // point to coefficient |
---|
1869 | TCoeff* piCoeff = pcCoef; |
---|
1870 | UInt uiNumSig = 0; |
---|
1871 | UInt uiScanning; |
---|
1872 | |
---|
1873 | // compute number of significant coefficients |
---|
1874 | UInt uiPart = 0; |
---|
1875 | xCheckCoeff(piCoeff, uiWidth, 0, uiNumSig, uiPart ); |
---|
1876 | |
---|
1877 | if ( bRD ) |
---|
1878 | { |
---|
1879 | UInt uiTempDepth = uiDepth - pcCU->getDepth( uiAbsPartIdx ); |
---|
1880 | pcCU->setCbfSubParts( ( uiNumSig ? 1 : 0 ) << uiTempDepth, eTType, uiAbsPartIdx, uiDepth ); |
---|
1881 | codeCbf( pcCU, uiAbsPartIdx, eTType, uiTempDepth ); |
---|
1882 | } |
---|
1883 | |
---|
1884 | if ( uiNumSig == 0 ) |
---|
1885 | { |
---|
1886 | return; |
---|
1887 | } |
---|
1888 | |
---|
1889 | // initialize scan |
---|
1890 | const UInt* pucScan; |
---|
1891 | //UInt uiConvBit = g_aucConvertToBit[ Min(8,uiWidth) ]; |
---|
1892 | UInt uiConvBit = g_aucConvertToBit[ pcCU->isIntra( uiAbsPartIdx ) ? uiWidth : Min(8,uiWidth) ]; |
---|
1893 | pucScan = g_auiFrameScanXY [ uiConvBit + 1 ]; |
---|
1894 | |
---|
1895 | #if QC_MDCS |
---|
1896 | UInt uiBlkPos; |
---|
1897 | UInt uiLog2BlkSize = g_aucConvertToBit[ pcCU->isIntra( uiAbsPartIdx ) ? uiWidth : Min(8,uiWidth) ] + 2; |
---|
1898 | const UInt uiScanIdx = pcCU->getCoefScanIdx(uiAbsPartIdx, uiWidth, eTType==TEXT_LUMA, pcCU->isIntra(uiAbsPartIdx)); |
---|
1899 | #endif //QC_MDCS |
---|
1900 | |
---|
1901 | TCoeff scoeff[64]; |
---|
1902 | Int iBlockType; |
---|
1903 | UInt uiCodeDCCoef = 0; |
---|
1904 | TCoeff dcCoeff = 0; |
---|
1905 | if (pcCU->isIntra(uiAbsPartIdx)) |
---|
1906 | { |
---|
1907 | UInt uiAbsPartIdxL, uiAbsPartIdxA; |
---|
1908 | TComDataCU* pcCUL = pcCU->getPULeft (uiAbsPartIdxL, pcCU->getZorderIdxInCU() + uiAbsPartIdx); |
---|
1909 | TComDataCU* pcCUA = pcCU->getPUAbove(uiAbsPartIdxA, pcCU->getZorderIdxInCU() + uiAbsPartIdx); |
---|
1910 | if (pcCUL == NULL && pcCUA == NULL) |
---|
1911 | { |
---|
1912 | uiCodeDCCoef = 1; |
---|
1913 | xWriteVlc((eTType == TEXT_LUMA ? 3 : 1) , abs(piCoeff[0])); |
---|
1914 | if (piCoeff[0] != 0) |
---|
1915 | { |
---|
1916 | UInt sign = (piCoeff[0] < 0) ? 1 : 0; |
---|
1917 | xWriteFlag(sign); |
---|
1918 | } |
---|
1919 | dcCoeff = piCoeff[0]; |
---|
1920 | piCoeff[0] = 1; |
---|
1921 | } |
---|
1922 | } |
---|
1923 | |
---|
1924 | if( uiSize == 2*2 ) |
---|
1925 | { |
---|
1926 | // hack: re-use 4x4 coding |
---|
1927 | ::memset( scoeff, 0, 16*sizeof(TCoeff) ); |
---|
1928 | for (uiScanning=0; uiScanning<4; uiScanning++) |
---|
1929 | { |
---|
1930 | #if QC_MDCS |
---|
1931 | uiBlkPos = g_auiSigLastScan[uiScanIdx][uiLog2BlkSize-1][uiScanning]; |
---|
1932 | scoeff[15-uiScanning] = piCoeff[ uiBlkPos ]; |
---|
1933 | #else |
---|
1934 | scoeff[15-uiScanning] = piCoeff[ pucScan[ uiScanning ] ]; |
---|
1935 | #endif //QC_MDCS |
---|
1936 | } |
---|
1937 | #if QC_MOD_LCEC |
---|
1938 | if (eTType==TEXT_CHROMA_U || eTType==TEXT_CHROMA_V) |
---|
1939 | iBlockType = eTType-2; |
---|
1940 | else |
---|
1941 | iBlockType = 2 + ( pcCU->isIntra(uiAbsPartIdx) ? 0 : pcCU->getSlice()->getSliceType() ); |
---|
1942 | #else |
---|
1943 | iBlockType = pcCU->isIntra(uiAbsPartIdx) ? 0 : pcCU->getSlice()->getSliceType(); |
---|
1944 | #endif |
---|
1945 | |
---|
1946 | xCodeCoeff4x4( scoeff, iBlockType ); |
---|
1947 | } |
---|
1948 | else if ( uiSize == 4*4 ) |
---|
1949 | { |
---|
1950 | for (uiScanning=0; uiScanning<16; uiScanning++) |
---|
1951 | { |
---|
1952 | #if QC_MDCS |
---|
1953 | uiBlkPos = g_auiSigLastScan[uiScanIdx][uiLog2BlkSize-1][uiScanning]; |
---|
1954 | scoeff[15-uiScanning] = piCoeff[ uiBlkPos ]; |
---|
1955 | #else |
---|
1956 | scoeff[15-uiScanning] = piCoeff[ pucScan[ uiScanning ] ]; |
---|
1957 | #endif //QC_MDCS |
---|
1958 | } |
---|
1959 | #if QC_MOD_LCEC |
---|
1960 | if (eTType==TEXT_CHROMA_U || eTType==TEXT_CHROMA_V) |
---|
1961 | iBlockType = eTType-2; |
---|
1962 | else |
---|
1963 | iBlockType = 2 + ( pcCU->isIntra(uiAbsPartIdx) ? 0 : pcCU->getSlice()->getSliceType() ); |
---|
1964 | #else |
---|
1965 | iBlockType = pcCU->isIntra(uiAbsPartIdx) ? 0 : pcCU->getSlice()->getSliceType(); |
---|
1966 | #endif |
---|
1967 | |
---|
1968 | xCodeCoeff4x4( scoeff, iBlockType ); |
---|
1969 | } |
---|
1970 | else if ( uiSize == 8*8 ) |
---|
1971 | { |
---|
1972 | for (uiScanning=0; uiScanning<64; uiScanning++) |
---|
1973 | { |
---|
1974 | #if QC_MDCS |
---|
1975 | uiBlkPos = g_auiSigLastScan[uiScanIdx][uiLog2BlkSize-1][uiScanning]; |
---|
1976 | scoeff[63-uiScanning] = piCoeff[ uiBlkPos ]; |
---|
1977 | #else |
---|
1978 | scoeff[63-uiScanning] = piCoeff[ pucScan[ uiScanning ] ]; |
---|
1979 | #endif //QC_MDCS |
---|
1980 | } |
---|
1981 | if (eTType==TEXT_CHROMA_U || eTType==TEXT_CHROMA_V) |
---|
1982 | iBlockType = eTType-2; |
---|
1983 | else |
---|
1984 | iBlockType = 2 + ( pcCU->isIntra(uiAbsPartIdx) ? 0 : pcCU->getSlice()->getSliceType() ); |
---|
1985 | |
---|
1986 | xCodeCoeff8x8( scoeff, iBlockType ); |
---|
1987 | } |
---|
1988 | else |
---|
1989 | { |
---|
1990 | if(!pcCU->isIntra( uiAbsPartIdx )) |
---|
1991 | { |
---|
1992 | for (uiScanning=0; uiScanning<64; uiScanning++) |
---|
1993 | { |
---|
1994 | #if QC_MDCS |
---|
1995 | uiBlkPos = g_auiSigLastScan[uiScanIdx][uiLog2BlkSize-1][uiScanning]; |
---|
1996 | uiBlkPos = (uiBlkPos/8) * uiWidth + uiBlkPos%8; |
---|
1997 | scoeff[63-uiScanning] = piCoeff[ uiBlkPos ]; |
---|
1998 | #else |
---|
1999 | scoeff[63-uiScanning] = piCoeff[(pucScan[uiScanning]/8)*uiWidth + (pucScan[uiScanning]%8)]; |
---|
2000 | #endif //QC_MDCS |
---|
2001 | } |
---|
2002 | if (eTType==TEXT_CHROMA_U || eTType==TEXT_CHROMA_V) |
---|
2003 | iBlockType = eTType-2; |
---|
2004 | else |
---|
2005 | iBlockType = 5 + ( pcCU->isIntra(uiAbsPartIdx) ? 0 : pcCU->getSlice()->getSliceType() ); |
---|
2006 | xCodeCoeff8x8( scoeff, iBlockType ); |
---|
2007 | return; |
---|
2008 | } |
---|
2009 | |
---|
2010 | if(pcCU->isIntra( uiAbsPartIdx )) |
---|
2011 | { |
---|
2012 | for (uiScanning=0; uiScanning<64; uiScanning++) |
---|
2013 | { |
---|
2014 | #if QC_MDCS |
---|
2015 | uiBlkPos = g_auiSigLastScan[uiScanIdx][uiLog2BlkSize-1][uiScanning]; |
---|
2016 | scoeff[63-uiScanning] = piCoeff[ uiBlkPos ]; |
---|
2017 | #else |
---|
2018 | scoeff[63-uiScanning] = piCoeff[ pucScan[ uiScanning ] ]; |
---|
2019 | #endif //QC_MDCS |
---|
2020 | } |
---|
2021 | |
---|
2022 | if (eTType==TEXT_CHROMA_U || eTType==TEXT_CHROMA_V) |
---|
2023 | iBlockType = eTType-2; |
---|
2024 | else |
---|
2025 | iBlockType = 5 + ( pcCU->isIntra(uiAbsPartIdx) ? 0 : pcCU->getSlice()->getSliceType() ); |
---|
2026 | xCodeCoeff8x8( scoeff, iBlockType ); |
---|
2027 | } |
---|
2028 | //#endif |
---|
2029 | } |
---|
2030 | |
---|
2031 | if (uiCodeDCCoef == 1) |
---|
2032 | { |
---|
2033 | piCoeff[0] = dcCoeff; |
---|
2034 | } |
---|
2035 | } |
---|
2036 | |
---|
2037 | Void TEncCavlc::codeAlfFlag( UInt uiCode ) |
---|
2038 | { |
---|
2039 | |
---|
2040 | xWriteFlag( uiCode ); |
---|
2041 | #if LCEC_STAT |
---|
2042 | if (m_bAdaptFlag) |
---|
2043 | m_uiBitAlfFlag += 1; |
---|
2044 | #endif |
---|
2045 | } |
---|
2046 | |
---|
2047 | #if TSB_ALF_HEADER |
---|
2048 | Void TEncCavlc::codeAlfFlagNum( UInt uiCode, UInt minValue ) |
---|
2049 | { |
---|
2050 | UInt uiLength = 0; |
---|
2051 | UInt maxValue = (minValue << (this->getMaxAlfCtrlDepth()*2)); |
---|
2052 | assert((uiCode>=minValue)&&(uiCode<=maxValue)); |
---|
2053 | UInt temp = maxValue - minValue; |
---|
2054 | for(UInt i=0; i<32; i++) |
---|
2055 | { |
---|
2056 | if(temp&0x1) |
---|
2057 | { |
---|
2058 | uiLength = i+1; |
---|
2059 | } |
---|
2060 | temp = (temp >> 1); |
---|
2061 | } |
---|
2062 | if(uiLength) |
---|
2063 | { |
---|
2064 | xWriteCode( uiCode - minValue, uiLength ); |
---|
2065 | } |
---|
2066 | } |
---|
2067 | |
---|
2068 | Void TEncCavlc::codeAlfCtrlFlag( UInt uiSymbol ) |
---|
2069 | { |
---|
2070 | xWriteFlag( uiSymbol ); |
---|
2071 | } |
---|
2072 | #endif |
---|
2073 | |
---|
2074 | Void TEncCavlc::codeAlfUvlc( UInt uiCode ) |
---|
2075 | { |
---|
2076 | #if LCEC_STAT |
---|
2077 | if (m_bAdaptFlag) |
---|
2078 | m_uiBitAlfUvlc += xWriteUvlc( uiCode ); |
---|
2079 | else |
---|
2080 | #endif |
---|
2081 | xWriteUvlc( uiCode ); |
---|
2082 | } |
---|
2083 | |
---|
2084 | Void TEncCavlc::codeAlfSvlc( Int iCode ) |
---|
2085 | { |
---|
2086 | #if LCEC_STAT |
---|
2087 | if (m_bAdaptFlag) |
---|
2088 | m_uiBitAlfSvlc += xWriteSvlc( iCode ); |
---|
2089 | else |
---|
2090 | #endif |
---|
2091 | xWriteSvlc( iCode ); |
---|
2092 | } |
---|
2093 | |
---|
2094 | Void TEncCavlc::estBit( estBitsSbacStruct* pcEstBitsCabac, UInt uiCTXIdx, TextType eTType ) |
---|
2095 | { |
---|
2096 | // printf("error : no VLC mode support in this version\n"); |
---|
2097 | return; |
---|
2098 | } |
---|
2099 | |
---|
2100 | // ==================================================================================================================== |
---|
2101 | // Protected member functions |
---|
2102 | // ==================================================================================================================== |
---|
2103 | |
---|
2104 | #if LCEC_STAT |
---|
2105 | UInt TEncCavlc::xWriteCode ( UInt uiCode, UInt uiLength ) |
---|
2106 | #else |
---|
2107 | Void TEncCavlc::xWriteCode ( UInt uiCode, UInt uiLength ) |
---|
2108 | #endif |
---|
2109 | { |
---|
2110 | assert ( uiLength > 0 ); |
---|
2111 | m_pcBitIf->write( uiCode, uiLength ); |
---|
2112 | #if LCEC_STAT |
---|
2113 | return uiLength; |
---|
2114 | #endif |
---|
2115 | } |
---|
2116 | |
---|
2117 | #if LCEC_STAT |
---|
2118 | UInt TEncCavlc::xWriteUvlc ( UInt uiCode ) |
---|
2119 | #else |
---|
2120 | Void TEncCavlc::xWriteUvlc ( UInt uiCode ) |
---|
2121 | #endif |
---|
2122 | { |
---|
2123 | UInt uiLength = 1; |
---|
2124 | UInt uiTemp = ++uiCode; |
---|
2125 | |
---|
2126 | assert ( uiTemp ); |
---|
2127 | |
---|
2128 | while( 1 != uiTemp ) |
---|
2129 | { |
---|
2130 | uiTemp >>= 1; |
---|
2131 | uiLength += 2; |
---|
2132 | } |
---|
2133 | |
---|
2134 | m_pcBitIf->write( uiCode, uiLength ); |
---|
2135 | #if LCEC_STAT |
---|
2136 | return uiLength; |
---|
2137 | #endif |
---|
2138 | } |
---|
2139 | |
---|
2140 | #if LCEC_STAT |
---|
2141 | UInt TEncCavlc::xWriteSvlc ( Int iCode ) |
---|
2142 | { |
---|
2143 | UInt uiCode; |
---|
2144 | UInt uiNumBits; |
---|
2145 | |
---|
2146 | uiCode = xConvertToUInt( iCode ); |
---|
2147 | uiNumBits = xWriteUvlc( uiCode ); |
---|
2148 | return uiNumBits; |
---|
2149 | } |
---|
2150 | #else |
---|
2151 | Void TEncCavlc::xWriteSvlc ( Int iCode ) |
---|
2152 | { |
---|
2153 | UInt uiCode; |
---|
2154 | |
---|
2155 | uiCode = xConvertToUInt( iCode ); |
---|
2156 | xWriteUvlc( uiCode ); |
---|
2157 | } |
---|
2158 | #endif |
---|
2159 | |
---|
2160 | Void TEncCavlc::xWriteFlag( UInt uiCode ) |
---|
2161 | { |
---|
2162 | m_pcBitIf->write( uiCode, 1 ); |
---|
2163 | } |
---|
2164 | |
---|
2165 | Void TEncCavlc::xCheckCoeff( TCoeff* pcCoef, UInt uiSize, UInt uiDepth, UInt& uiNumofCoeff, UInt& uiPart ) |
---|
2166 | { |
---|
2167 | UInt ui = uiSize>>uiDepth; |
---|
2168 | if( uiPart == 0 ) |
---|
2169 | { |
---|
2170 | if( ui <= 4 ) |
---|
2171 | { |
---|
2172 | UInt x, y; |
---|
2173 | TCoeff* pCeoff = pcCoef; |
---|
2174 | for( y=0 ; y<ui ; y++ ) |
---|
2175 | { |
---|
2176 | for( x=0 ; x<ui ; x++ ) |
---|
2177 | { |
---|
2178 | if( pCeoff[x] != 0 ) |
---|
2179 | { |
---|
2180 | uiNumofCoeff++; |
---|
2181 | } |
---|
2182 | } |
---|
2183 | pCeoff += uiSize; |
---|
2184 | } |
---|
2185 | } |
---|
2186 | else |
---|
2187 | { |
---|
2188 | xCheckCoeff( pcCoef, uiSize, uiDepth+1, uiNumofCoeff, uiPart ); uiPart++; //1st Part |
---|
2189 | xCheckCoeff( pcCoef + (ui>>1), uiSize, uiDepth+1, uiNumofCoeff, uiPart ); uiPart++; //2nd Part |
---|
2190 | xCheckCoeff( pcCoef + (ui>>1)*uiSize, uiSize, uiDepth+1, uiNumofCoeff, uiPart ); uiPart++; //3rd Part |
---|
2191 | xCheckCoeff( pcCoef + (ui>>1)*uiSize + (ui>>1), uiSize, uiDepth+1, uiNumofCoeff, uiPart ); //4th Part |
---|
2192 | } |
---|
2193 | } |
---|
2194 | else |
---|
2195 | { |
---|
2196 | UInt x, y; |
---|
2197 | TCoeff* pCeoff = pcCoef; |
---|
2198 | for( y=0 ; y<ui ; y++ ) |
---|
2199 | { |
---|
2200 | for( x=0 ; x<ui ; x++ ) |
---|
2201 | { |
---|
2202 | if( pCeoff[x] != 0 ) |
---|
2203 | { |
---|
2204 | uiNumofCoeff++; |
---|
2205 | } |
---|
2206 | } |
---|
2207 | pCeoff += uiSize; |
---|
2208 | } |
---|
2209 | } |
---|
2210 | } |
---|
2211 | |
---|
2212 | #if LCEC_STAT |
---|
2213 | UInt TEncCavlc::xWriteUnaryMaxSymbol( UInt uiSymbol, UInt uiMaxSymbol ) |
---|
2214 | #else |
---|
2215 | Void TEncCavlc::xWriteUnaryMaxSymbol( UInt uiSymbol, UInt uiMaxSymbol ) |
---|
2216 | #endif |
---|
2217 | { |
---|
2218 | if (uiMaxSymbol == 0) |
---|
2219 | { |
---|
2220 | #if LCEC_STAT |
---|
2221 | return 0; |
---|
2222 | #else |
---|
2223 | return; |
---|
2224 | #endif |
---|
2225 | } |
---|
2226 | #if LCEC_STAT |
---|
2227 | UInt uiNumBits = 0; |
---|
2228 | #endif |
---|
2229 | xWriteFlag( uiSymbol ? 1 : 0 ); |
---|
2230 | #if LCEC_STAT |
---|
2231 | uiNumBits +=1; |
---|
2232 | #endif |
---|
2233 | if ( uiSymbol == 0 ) |
---|
2234 | { |
---|
2235 | #if LCEC_STAT |
---|
2236 | return uiNumBits; |
---|
2237 | #else |
---|
2238 | return; |
---|
2239 | #endif |
---|
2240 | } |
---|
2241 | |
---|
2242 | Bool bCodeLast = ( uiMaxSymbol > uiSymbol ); |
---|
2243 | |
---|
2244 | while( --uiSymbol ) |
---|
2245 | { |
---|
2246 | xWriteFlag( 1 ); |
---|
2247 | #if LCEC_STAT |
---|
2248 | uiNumBits +=1; |
---|
2249 | #endif |
---|
2250 | } |
---|
2251 | if( bCodeLast ) |
---|
2252 | { |
---|
2253 | xWriteFlag( 0 ); |
---|
2254 | #if LCEC_STAT |
---|
2255 | uiNumBits +=1; |
---|
2256 | #endif |
---|
2257 | } |
---|
2258 | #if LCEC_STAT |
---|
2259 | return uiNumBits; |
---|
2260 | #else |
---|
2261 | return; |
---|
2262 | #endif |
---|
2263 | } |
---|
2264 | |
---|
2265 | #if LCEC_STAT |
---|
2266 | UInt TEncCavlc::xWriteExGolombLevel( UInt uiSymbol ) |
---|
2267 | #else |
---|
2268 | Void TEncCavlc::xWriteExGolombLevel( UInt uiSymbol ) |
---|
2269 | #endif |
---|
2270 | { |
---|
2271 | #if LCEC_STAT |
---|
2272 | UInt uiNumBits = 0; |
---|
2273 | #endif |
---|
2274 | if( uiSymbol ) |
---|
2275 | { |
---|
2276 | xWriteFlag( 1 ); |
---|
2277 | #if LCEC_STAT |
---|
2278 | uiNumBits += 1; |
---|
2279 | #endif |
---|
2280 | UInt uiCount = 0; |
---|
2281 | Bool bNoExGo = (uiSymbol < 13); |
---|
2282 | |
---|
2283 | while( --uiSymbol && ++uiCount < 13 ) |
---|
2284 | { |
---|
2285 | xWriteFlag( 1 ); |
---|
2286 | #if LCEC_STAT |
---|
2287 | uiNumBits += 1; |
---|
2288 | #endif |
---|
2289 | } |
---|
2290 | if( bNoExGo ) |
---|
2291 | { |
---|
2292 | xWriteFlag( 0 ); |
---|
2293 | #if LCEC_STAT |
---|
2294 | uiNumBits += 1; |
---|
2295 | #endif |
---|
2296 | } |
---|
2297 | else |
---|
2298 | { |
---|
2299 | #if LCEC_STAT |
---|
2300 | uiNumBits += xWriteEpExGolomb( uiSymbol, 0 ); |
---|
2301 | #else |
---|
2302 | xWriteEpExGolomb( uiSymbol, 0 ); |
---|
2303 | #endif |
---|
2304 | } |
---|
2305 | } |
---|
2306 | else |
---|
2307 | { |
---|
2308 | xWriteFlag( 0 ); |
---|
2309 | #if LCEC_STAT |
---|
2310 | uiNumBits += 1; |
---|
2311 | #endif |
---|
2312 | } |
---|
2313 | |
---|
2314 | #if LCEC_STAT |
---|
2315 | return uiNumBits; |
---|
2316 | #else |
---|
2317 | return; |
---|
2318 | #endif |
---|
2319 | } |
---|
2320 | |
---|
2321 | #if LCEC_STAT |
---|
2322 | UInt TEncCavlc::xWriteEpExGolomb( UInt uiSymbol, UInt uiCount ) |
---|
2323 | #else |
---|
2324 | Void TEncCavlc::xWriteEpExGolomb( UInt uiSymbol, UInt uiCount ) |
---|
2325 | #endif |
---|
2326 | { |
---|
2327 | #if LCEC_STAT |
---|
2328 | UInt uiNumBits = 0; |
---|
2329 | #endif |
---|
2330 | while( uiSymbol >= (UInt)(1<<uiCount) ) |
---|
2331 | { |
---|
2332 | xWriteFlag( 1 ); |
---|
2333 | #if LCEC_STAT |
---|
2334 | uiNumBits += 1; |
---|
2335 | #endif |
---|
2336 | uiSymbol -= 1<<uiCount; |
---|
2337 | uiCount ++; |
---|
2338 | } |
---|
2339 | xWriteFlag( 0 ); |
---|
2340 | #if LCEC_STAT |
---|
2341 | uiNumBits += 1; |
---|
2342 | #endif |
---|
2343 | while( uiCount-- ) |
---|
2344 | { |
---|
2345 | xWriteFlag( (uiSymbol>>uiCount) & 1 ); |
---|
2346 | #if LCEC_STAT |
---|
2347 | uiNumBits += 1; |
---|
2348 | #endif |
---|
2349 | } |
---|
2350 | #if LCEC_STAT |
---|
2351 | return uiNumBits; |
---|
2352 | #else |
---|
2353 | return; |
---|
2354 | #endif |
---|
2355 | } |
---|
2356 | |
---|
2357 | #if !QC_MOD_LCEC_RDOQ |
---|
2358 | UInt TEncCavlc::xLeadingZeros(UInt uiCode) |
---|
2359 | { |
---|
2360 | UInt uiCount = 0; |
---|
2361 | Int iDone = 0; |
---|
2362 | |
---|
2363 | if (uiCode) |
---|
2364 | { |
---|
2365 | while (!iDone) |
---|
2366 | { |
---|
2367 | uiCode >>= 1; |
---|
2368 | if (!uiCode) iDone = 1; |
---|
2369 | else uiCount++; |
---|
2370 | } |
---|
2371 | } |
---|
2372 | return uiCount; |
---|
2373 | } |
---|
2374 | #endif |
---|
2375 | |
---|
2376 | #if LCEC_STAT |
---|
2377 | UInt TEncCavlc::xWriteVlc(UInt uiTableNumber, UInt uiCodeNumber) |
---|
2378 | #else |
---|
2379 | Void TEncCavlc::xWriteVlc(UInt uiTableNumber, UInt uiCodeNumber) |
---|
2380 | #endif |
---|
2381 | { |
---|
2382 | #if QC_BLK_CBP |
---|
2383 | assert( uiTableNumber<=11 ); |
---|
2384 | #else |
---|
2385 | assert( uiTableNumber<=10 ); |
---|
2386 | #endif |
---|
2387 | |
---|
2388 | UInt uiTemp; |
---|
2389 | UInt uiLength = 0; |
---|
2390 | UInt uiCode = 0; |
---|
2391 | |
---|
2392 | if ( uiTableNumber < 5 ) |
---|
2393 | { |
---|
2394 | if ((Int)uiCodeNumber < (6 * (1 << uiTableNumber))) |
---|
2395 | { |
---|
2396 | uiTemp = 1<<uiTableNumber; |
---|
2397 | uiCode = uiTemp+uiCodeNumber%uiTemp; |
---|
2398 | uiLength = 1+uiTableNumber+(uiCodeNumber>>uiTableNumber); |
---|
2399 | } |
---|
2400 | else |
---|
2401 | { |
---|
2402 | uiCode = uiCodeNumber - (6 * (1 << uiTableNumber)) + (1 << uiTableNumber); |
---|
2403 | uiLength = (6-uiTableNumber)+1+2*xLeadingZeros(uiCode); |
---|
2404 | } |
---|
2405 | } |
---|
2406 | else if (uiTableNumber < 8) |
---|
2407 | { |
---|
2408 | uiTemp = 1<<(uiTableNumber-4); |
---|
2409 | uiCode = uiTemp+uiCodeNumber%uiTemp; |
---|
2410 | uiLength = 1+(uiTableNumber-4)+(uiCodeNumber>>(uiTableNumber-4)); |
---|
2411 | } |
---|
2412 | else if (uiTableNumber == 8) |
---|
2413 | { |
---|
2414 | assert( uiCodeNumber<=2 ); |
---|
2415 | if (uiCodeNumber == 0) |
---|
2416 | { |
---|
2417 | uiCode = 1; |
---|
2418 | uiLength = 1; |
---|
2419 | } |
---|
2420 | else if (uiCodeNumber == 1) |
---|
2421 | { |
---|
2422 | uiCode = 1; |
---|
2423 | uiLength = 2; |
---|
2424 | } |
---|
2425 | else if (uiCodeNumber == 2) |
---|
2426 | { |
---|
2427 | uiCode = 0; |
---|
2428 | uiLength = 2; |
---|
2429 | } |
---|
2430 | } |
---|
2431 | else if (uiTableNumber == 9) |
---|
2432 | { |
---|
2433 | if (uiCodeNumber == 0) |
---|
2434 | { |
---|
2435 | uiCode = 4; |
---|
2436 | uiLength = 3; |
---|
2437 | } |
---|
2438 | else if (uiCodeNumber == 1) |
---|
2439 | { |
---|
2440 | uiCode = 10; |
---|
2441 | uiLength = 4; |
---|
2442 | } |
---|
2443 | else if (uiCodeNumber == 2) |
---|
2444 | { |
---|
2445 | uiCode = 11; |
---|
2446 | uiLength = 4; |
---|
2447 | } |
---|
2448 | else if (uiCodeNumber < 11) |
---|
2449 | { |
---|
2450 | uiCode = uiCodeNumber+21; |
---|
2451 | uiLength = 5; |
---|
2452 | } |
---|
2453 | else |
---|
2454 | { |
---|
2455 | uiTemp = 1<<4; |
---|
2456 | uiCode = uiTemp+(uiCodeNumber+5)%uiTemp; |
---|
2457 | uiLength = 5+((uiCodeNumber+5)>>4); |
---|
2458 | } |
---|
2459 | } |
---|
2460 | else if (uiTableNumber == 10) |
---|
2461 | { |
---|
2462 | uiCode = uiCodeNumber+1; |
---|
2463 | uiLength = 1+2*xLeadingZeros(uiCode); |
---|
2464 | } |
---|
2465 | #if QC_BLK_CBP |
---|
2466 | else if (uiTableNumber == 11) |
---|
2467 | { |
---|
2468 | if (uiCodeNumber == 0) |
---|
2469 | { |
---|
2470 | uiCode = 0; |
---|
2471 | uiLength = 3; |
---|
2472 | } |
---|
2473 | else |
---|
2474 | { |
---|
2475 | uiCode = uiCodeNumber + 1; |
---|
2476 | uiLength = 4; |
---|
2477 | } |
---|
2478 | } |
---|
2479 | #endif |
---|
2480 | xWriteCode(uiCode, uiLength); |
---|
2481 | #if LCEC_STAT |
---|
2482 | return uiLength; |
---|
2483 | #endif |
---|
2484 | } |
---|
2485 | |
---|
2486 | Void TEncCavlc::xCodeCoeff4x4(TCoeff* scoeff, Int n ) |
---|
2487 | { |
---|
2488 | Int i; |
---|
2489 | UInt cn; |
---|
2490 | Int level,vlc,sign,done,last_pos,start; |
---|
2491 | Int run_done,maxrun,run,lev; |
---|
2492 | #if QC_MOD_LCEC |
---|
2493 | Int vlc_adaptive=0; |
---|
2494 | #else |
---|
2495 | Int tmprun, vlc_adaptive=0; |
---|
2496 | #endif |
---|
2497 | static const int atable[5] = {4,6,14,28,0xfffffff}; |
---|
2498 | Int tmp; |
---|
2499 | #if QC_MOD_LCEC |
---|
2500 | Int nTab = max(0,n-2); |
---|
2501 | Int tr1; |
---|
2502 | #endif |
---|
2503 | |
---|
2504 | /* Do the last coefficient first */ |
---|
2505 | i = 0; |
---|
2506 | done = 0; |
---|
2507 | |
---|
2508 | while (!done && i < 16) |
---|
2509 | { |
---|
2510 | if (scoeff[i]) |
---|
2511 | { |
---|
2512 | done = 1; |
---|
2513 | } |
---|
2514 | else |
---|
2515 | { |
---|
2516 | i++; |
---|
2517 | } |
---|
2518 | } |
---|
2519 | if (i == 16) |
---|
2520 | { |
---|
2521 | return; |
---|
2522 | } |
---|
2523 | |
---|
2524 | last_pos = 15-i; |
---|
2525 | level = abs(scoeff[i]); |
---|
2526 | lev = (level == 1) ? 0 : 1; |
---|
2527 | |
---|
2528 | #if QC_MOD_LCEC |
---|
2529 | if (level>1){ |
---|
2530 | tr1=0; |
---|
2531 | } |
---|
2532 | else{ |
---|
2533 | tr1=1; |
---|
2534 | } |
---|
2535 | #endif |
---|
2536 | |
---|
2537 | { |
---|
2538 | int x,y,cx,cy,vlcNum; |
---|
2539 | int vlcTable[3] = {2,2,2}; |
---|
2540 | |
---|
2541 | x = 16*lev + last_pos; |
---|
2542 | |
---|
2543 | #if QC_MOD_LCEC |
---|
2544 | cx = m_uiLPTableE4[nTab][x]; |
---|
2545 | vlcNum = vlcTable[nTab]; |
---|
2546 | #else |
---|
2547 | cx = m_uiLPTableE4[n][x]; |
---|
2548 | vlcNum = vlcTable[n]; |
---|
2549 | #endif |
---|
2550 | |
---|
2551 | #if LCEC_STAT |
---|
2552 | if (m_bAdaptFlag) |
---|
2553 | m_uiBitCoeff += xWriteVlc( vlcNum, cx ); |
---|
2554 | else |
---|
2555 | #endif |
---|
2556 | xWriteVlc( vlcNum, cx ); |
---|
2557 | |
---|
2558 | if ( m_bAdaptFlag ) |
---|
2559 | { |
---|
2560 | |
---|
2561 | cy = Max( 0, cx-1 ); |
---|
2562 | #if QC_MOD_LCEC |
---|
2563 | y = m_uiLPTableD4[nTab][cy]; |
---|
2564 | m_uiLPTableD4[nTab][cy] = x; |
---|
2565 | m_uiLPTableD4[nTab][cx] = y; |
---|
2566 | m_uiLPTableE4[nTab][x] = cy; |
---|
2567 | m_uiLPTableE4[nTab][y] = cx; |
---|
2568 | #else |
---|
2569 | y = m_uiLPTableD4[n][cy]; |
---|
2570 | m_uiLPTableD4[n][cy] = x; |
---|
2571 | m_uiLPTableD4[n][cx] = y; |
---|
2572 | m_uiLPTableE4[n][x] = cy; |
---|
2573 | m_uiLPTableE4[n][y] = cx; |
---|
2574 | #endif |
---|
2575 | } |
---|
2576 | } |
---|
2577 | |
---|
2578 | sign = (scoeff[i] < 0) ? 1 : 0; |
---|
2579 | if (level > 1) |
---|
2580 | { |
---|
2581 | #if LCEC_STAT |
---|
2582 | if (m_bAdaptFlag) |
---|
2583 | m_uiBitCoeff += xWriteVlc( 0, 2*(level-2)+sign ); |
---|
2584 | else |
---|
2585 | #endif |
---|
2586 | xWriteVlc( 0, 2*(level-2)+sign ); |
---|
2587 | } |
---|
2588 | else |
---|
2589 | { |
---|
2590 | xWriteFlag( sign ); |
---|
2591 | #if LCEC_STAT |
---|
2592 | if (m_bAdaptFlag) |
---|
2593 | m_uiBitCoeff += 1; |
---|
2594 | #endif |
---|
2595 | } |
---|
2596 | i++; |
---|
2597 | |
---|
2598 | if (i < 16) |
---|
2599 | { |
---|
2600 | /* Go into run mode */ |
---|
2601 | run_done = 0; |
---|
2602 | while (!run_done) |
---|
2603 | { |
---|
2604 | maxrun = 15-i; |
---|
2605 | #if QC_MOD_LCEC |
---|
2606 | if ( n == 2 ) |
---|
2607 | vlc = g_auiVlcTable8x8Intra[maxrun]; |
---|
2608 | else |
---|
2609 | vlc = g_auiVlcTable8x8Inter[maxrun]; |
---|
2610 | #else |
---|
2611 | tmprun = maxrun; |
---|
2612 | if (maxrun > 27) |
---|
2613 | { |
---|
2614 | vlc = 3; |
---|
2615 | tmprun = 28; |
---|
2616 | } |
---|
2617 | else |
---|
2618 | { |
---|
2619 | vlc = g_auiVlcTable8x8[maxrun]; |
---|
2620 | } |
---|
2621 | #endif |
---|
2622 | |
---|
2623 | run = 0; |
---|
2624 | done = 0; |
---|
2625 | while (!done) |
---|
2626 | { |
---|
2627 | if (!scoeff[i]) |
---|
2628 | { |
---|
2629 | run++; |
---|
2630 | } |
---|
2631 | else |
---|
2632 | { |
---|
2633 | level = abs(scoeff[i]); |
---|
2634 | lev = (level == 1) ? 0 : 1; |
---|
2635 | #if QC_MOD_LCEC |
---|
2636 | if ( n == 2 ){ |
---|
2637 | cn = xRunLevelInd(lev, run, maxrun, g_auiLumaRunTr14x4[tr1][maxrun]); |
---|
2638 | } |
---|
2639 | else{ |
---|
2640 | cn = g_auiLumaRun8x8[maxrun][lev][run]; |
---|
2641 | } |
---|
2642 | #else |
---|
2643 | if (maxrun > 27) |
---|
2644 | { |
---|
2645 | cn = g_auiLumaRun8x8[28][lev][run]; |
---|
2646 | } |
---|
2647 | else |
---|
2648 | { |
---|
2649 | cn = g_auiLumaRun8x8[maxrun][lev][run]; |
---|
2650 | } |
---|
2651 | #endif |
---|
2652 | #if LCEC_STAT |
---|
2653 | if (m_bAdaptFlag) |
---|
2654 | m_uiBitCoeff += xWriteVlc( vlc, cn ); |
---|
2655 | else |
---|
2656 | #endif |
---|
2657 | xWriteVlc( vlc, cn ); |
---|
2658 | |
---|
2659 | #if QC_MOD_LCEC |
---|
2660 | if (tr1>0 && tr1 < MAX_TR1) |
---|
2661 | { |
---|
2662 | tr1++; |
---|
2663 | } |
---|
2664 | #endif |
---|
2665 | sign = (scoeff[i] < 0) ? 1 : 0; |
---|
2666 | if (level > 1) |
---|
2667 | { |
---|
2668 | #if LCEC_STAT |
---|
2669 | if (m_bAdaptFlag) |
---|
2670 | m_uiBitCoeff += xWriteVlc( 0, 2*(level-2)+sign ); |
---|
2671 | else |
---|
2672 | #endif |
---|
2673 | xWriteVlc( 0, 2*(level-2)+sign ); |
---|
2674 | run_done = 1; |
---|
2675 | } |
---|
2676 | else |
---|
2677 | { |
---|
2678 | xWriteFlag( sign ); |
---|
2679 | #if LCEC_STAT |
---|
2680 | if (m_bAdaptFlag) |
---|
2681 | m_uiBitCoeff += 1; |
---|
2682 | #endif |
---|
2683 | } |
---|
2684 | |
---|
2685 | run = 0; |
---|
2686 | done = 1; |
---|
2687 | } |
---|
2688 | if (i == 15) |
---|
2689 | { |
---|
2690 | done = 1; |
---|
2691 | run_done = 1; |
---|
2692 | if (run) |
---|
2693 | { |
---|
2694 | #if QC_MOD_LCEC |
---|
2695 | if (n==2){ |
---|
2696 | cn=xRunLevelInd(0, run, maxrun, g_auiLumaRunTr14x4[tr1][maxrun]); |
---|
2697 | } |
---|
2698 | else{ |
---|
2699 | cn = g_auiLumaRun8x8[maxrun][0][run]; |
---|
2700 | } |
---|
2701 | #else |
---|
2702 | if (maxrun > 27) |
---|
2703 | { |
---|
2704 | cn = g_auiLumaRun8x8[28][0][run]; |
---|
2705 | } |
---|
2706 | else |
---|
2707 | { |
---|
2708 | cn = g_auiLumaRun8x8[maxrun][0][run]; |
---|
2709 | } |
---|
2710 | #endif |
---|
2711 | #if LCEC_STAT |
---|
2712 | if (m_bAdaptFlag) |
---|
2713 | m_uiBitCoeff += xWriteVlc( vlc, cn ); |
---|
2714 | else |
---|
2715 | #endif |
---|
2716 | xWriteVlc( vlc, cn ); |
---|
2717 | } |
---|
2718 | } |
---|
2719 | i++; |
---|
2720 | } |
---|
2721 | } |
---|
2722 | } |
---|
2723 | |
---|
2724 | /* Code the rest in level mode */ |
---|
2725 | start = i; |
---|
2726 | for ( i=start; i<16; i++ ) |
---|
2727 | { |
---|
2728 | tmp = abs(scoeff[i]); |
---|
2729 | #if LCEC_STAT |
---|
2730 | if (m_bAdaptFlag) |
---|
2731 | m_uiBitCoeff += xWriteVlc( vlc_adaptive, tmp ); |
---|
2732 | else |
---|
2733 | #endif |
---|
2734 | xWriteVlc( vlc_adaptive, tmp ); |
---|
2735 | if (scoeff[i]) |
---|
2736 | { |
---|
2737 | sign = (scoeff[i] < 0) ? 1 : 0; |
---|
2738 | xWriteFlag( sign ); |
---|
2739 | #if LCEC_STAT |
---|
2740 | if (m_bAdaptFlag) |
---|
2741 | m_uiBitCoeff += 1; |
---|
2742 | #endif |
---|
2743 | } |
---|
2744 | if ( tmp > atable[vlc_adaptive] ) |
---|
2745 | { |
---|
2746 | vlc_adaptive++; |
---|
2747 | } |
---|
2748 | } |
---|
2749 | return; |
---|
2750 | } |
---|
2751 | |
---|
2752 | Void TEncCavlc::xCodeCoeff8x8( TCoeff* scoeff, Int n ) |
---|
2753 | { |
---|
2754 | int i; |
---|
2755 | unsigned int cn; |
---|
2756 | int level,vlc,sign,done,last_pos,start; |
---|
2757 | int run_done,maxrun,run,lev; |
---|
2758 | #if QC_MOD_LCEC |
---|
2759 | int vlc_adaptive=0; |
---|
2760 | #else |
---|
2761 | int tmprun,vlc_adaptive=0; |
---|
2762 | #endif |
---|
2763 | static const int atable[5] = {4,6,14,28,0xfffffff}; |
---|
2764 | int tmp; |
---|
2765 | #if QC_MOD_LCEC |
---|
2766 | Int tr1; |
---|
2767 | #endif |
---|
2768 | |
---|
2769 | static const int switch_thr[10] = {49,49,0,49,49,0,49,49,49,49}; |
---|
2770 | int sum_big_coef = 0; |
---|
2771 | |
---|
2772 | |
---|
2773 | /* Do the last coefficient first */ |
---|
2774 | i = 0; |
---|
2775 | done = 0; |
---|
2776 | while (!done && i < 64) |
---|
2777 | { |
---|
2778 | if (scoeff[i]) |
---|
2779 | { |
---|
2780 | done = 1; |
---|
2781 | } |
---|
2782 | else |
---|
2783 | { |
---|
2784 | i++; |
---|
2785 | } |
---|
2786 | } |
---|
2787 | if (i == 64) |
---|
2788 | { |
---|
2789 | return; |
---|
2790 | } |
---|
2791 | |
---|
2792 | last_pos = 63-i; |
---|
2793 | level = abs(scoeff[i]); |
---|
2794 | lev = (level == 1) ? 0 : 1; |
---|
2795 | |
---|
2796 | { |
---|
2797 | int x,y,cx,cy,vlcNum; |
---|
2798 | x = 64*lev + last_pos; |
---|
2799 | |
---|
2800 | cx = m_uiLPTableE8[n][x]; |
---|
2801 | // ADAPT_VLC_NUM |
---|
2802 | vlcNum = g_auiLastPosVlcNum[n][Min(16,m_uiLastPosVlcIndex[n])]; |
---|
2803 | #if LCEC_STAT |
---|
2804 | if (m_bAdaptFlag) |
---|
2805 | m_uiBitCoeff += xWriteVlc( vlcNum, cx ); |
---|
2806 | else |
---|
2807 | #endif |
---|
2808 | xWriteVlc( vlcNum, cx ); |
---|
2809 | |
---|
2810 | if ( m_bAdaptFlag ) |
---|
2811 | { |
---|
2812 | |
---|
2813 | // ADAPT_VLC_NUM |
---|
2814 | m_uiLastPosVlcIndex[n] += cx == m_uiLastPosVlcIndex[n] ? 0 : (cx < m_uiLastPosVlcIndex[n] ? -1 : 1); |
---|
2815 | cy = Max(0,cx-1); |
---|
2816 | y = m_uiLPTableD8[n][cy]; |
---|
2817 | m_uiLPTableD8[n][cy] = x; |
---|
2818 | m_uiLPTableD8[n][cx] = y; |
---|
2819 | m_uiLPTableE8[n][x] = cy; |
---|
2820 | m_uiLPTableE8[n][y] = cx; |
---|
2821 | } |
---|
2822 | } |
---|
2823 | |
---|
2824 | sign = (scoeff[i] < 0) ? 1 : 0; |
---|
2825 | if (level > 1) |
---|
2826 | { |
---|
2827 | #if LCEC_STAT |
---|
2828 | if (m_bAdaptFlag) |
---|
2829 | m_uiBitCoeff += xWriteVlc( 0, 2*(level-2)+sign ); |
---|
2830 | else |
---|
2831 | #endif |
---|
2832 | xWriteVlc( 0, 2*(level-2)+sign ); |
---|
2833 | } |
---|
2834 | else |
---|
2835 | { |
---|
2836 | xWriteFlag( sign ); |
---|
2837 | #if LCEC_STAT |
---|
2838 | if (m_bAdaptFlag) |
---|
2839 | m_uiBitCoeff += 1; |
---|
2840 | #endif |
---|
2841 | } |
---|
2842 | i++; |
---|
2843 | #if QC_MOD_LCEC |
---|
2844 | if (level>1){ |
---|
2845 | tr1=0; |
---|
2846 | } |
---|
2847 | else{ |
---|
2848 | tr1=1; |
---|
2849 | } |
---|
2850 | #endif |
---|
2851 | |
---|
2852 | if (i < 64) |
---|
2853 | { |
---|
2854 | /* Go into run mode */ |
---|
2855 | run_done = 0; |
---|
2856 | while ( !run_done ) |
---|
2857 | { |
---|
2858 | maxrun = 63-i; |
---|
2859 | #if QC_MOD_LCEC |
---|
2860 | if(n == 2 || n == 5) |
---|
2861 | vlc = g_auiVlcTable8x8Intra[Min(maxrun,28)]; |
---|
2862 | else |
---|
2863 | vlc = g_auiVlcTable8x8Inter[Min(maxrun,28)]; |
---|
2864 | #else |
---|
2865 | tmprun = maxrun; |
---|
2866 | if (maxrun > 27) |
---|
2867 | { |
---|
2868 | vlc = 3; |
---|
2869 | tmprun = 28; |
---|
2870 | } |
---|
2871 | else |
---|
2872 | { |
---|
2873 | vlc = g_auiVlcTable8x8[maxrun]; |
---|
2874 | } |
---|
2875 | #endif |
---|
2876 | |
---|
2877 | run = 0; |
---|
2878 | done = 0; |
---|
2879 | while (!done) |
---|
2880 | { |
---|
2881 | if (!scoeff[i]) |
---|
2882 | { |
---|
2883 | run++; |
---|
2884 | } |
---|
2885 | else |
---|
2886 | { |
---|
2887 | level = abs(scoeff[i]); |
---|
2888 | lev = (level == 1) ? 0 : 1; |
---|
2889 | #if QC_MOD_LCEC |
---|
2890 | if(n == 2 || n == 5) |
---|
2891 | cn = xRunLevelInd(lev, run, maxrun, g_auiLumaRunTr18x8[tr1][min(maxrun,28)]); |
---|
2892 | else |
---|
2893 | cn = g_auiLumaRun8x8[min(maxrun,28)][lev][run]; |
---|
2894 | #else |
---|
2895 | if (maxrun > 27) |
---|
2896 | { |
---|
2897 | cn = g_auiLumaRun8x8[28][lev][run]; |
---|
2898 | } |
---|
2899 | else |
---|
2900 | { |
---|
2901 | cn = g_auiLumaRun8x8[maxrun][lev][run]; |
---|
2902 | } |
---|
2903 | #endif |
---|
2904 | #if LCEC_STAT |
---|
2905 | if (m_bAdaptFlag) |
---|
2906 | m_uiBitCoeff += xWriteVlc( vlc, cn ); |
---|
2907 | else |
---|
2908 | #endif |
---|
2909 | xWriteVlc( vlc, cn ); |
---|
2910 | |
---|
2911 | #if QC_MOD_LCEC |
---|
2912 | if (tr1==0 || level >=2) |
---|
2913 | { |
---|
2914 | tr1=0; |
---|
2915 | } |
---|
2916 | else if (tr1 < MAX_TR1) |
---|
2917 | { |
---|
2918 | tr1++; |
---|
2919 | } |
---|
2920 | #endif |
---|
2921 | sign = (scoeff[i] < 0) ? 1 : 0; |
---|
2922 | if (level > 1) |
---|
2923 | { |
---|
2924 | #if LCEC_STAT |
---|
2925 | if (m_bAdaptFlag) |
---|
2926 | m_uiBitCoeff += xWriteVlc( 0, 2*(level-2)+sign ); |
---|
2927 | else |
---|
2928 | #endif |
---|
2929 | xWriteVlc( 0, 2*(level-2)+sign ); |
---|
2930 | |
---|
2931 | sum_big_coef += level; |
---|
2932 | if (i > switch_thr[n] || sum_big_coef > 2) |
---|
2933 | { |
---|
2934 | run_done = 1; |
---|
2935 | } |
---|
2936 | } |
---|
2937 | else |
---|
2938 | { |
---|
2939 | xWriteFlag( sign ); |
---|
2940 | #if LCEC_STAT |
---|
2941 | if (m_bAdaptFlag) |
---|
2942 | m_uiBitCoeff += 1; |
---|
2943 | #endif |
---|
2944 | } |
---|
2945 | run = 0; |
---|
2946 | done = 1; |
---|
2947 | } |
---|
2948 | if (i == 63) |
---|
2949 | { |
---|
2950 | done = 1; |
---|
2951 | run_done = 1; |
---|
2952 | if (run) |
---|
2953 | { |
---|
2954 | #if QC_MOD_LCEC |
---|
2955 | if(n == 2 || n == 5) |
---|
2956 | cn=xRunLevelInd(0, run, maxrun, g_auiLumaRunTr18x8[tr1][min(maxrun,28)]); |
---|
2957 | else |
---|
2958 | cn = g_auiLumaRun8x8[min(maxrun,28)][0][run]; |
---|
2959 | #else |
---|
2960 | if (maxrun > 27) |
---|
2961 | { |
---|
2962 | cn = g_auiLumaRun8x8[28][0][run]; |
---|
2963 | } |
---|
2964 | else |
---|
2965 | { |
---|
2966 | cn = g_auiLumaRun8x8[maxrun][0][run]; |
---|
2967 | } |
---|
2968 | #endif |
---|
2969 | #if LCEC_STAT |
---|
2970 | if (m_bAdaptFlag) |
---|
2971 | m_uiBitCoeff += xWriteVlc( vlc, cn ); |
---|
2972 | else |
---|
2973 | #endif |
---|
2974 | xWriteVlc( vlc, cn ); |
---|
2975 | } |
---|
2976 | } |
---|
2977 | i++; |
---|
2978 | } |
---|
2979 | } |
---|
2980 | } |
---|
2981 | |
---|
2982 | /* Code the rest in level mode */ |
---|
2983 | start = i; |
---|
2984 | for ( i=start; i<64; i++ ) |
---|
2985 | { |
---|
2986 | tmp = abs(scoeff[i]); |
---|
2987 | #if LCEC_STAT |
---|
2988 | if (m_bAdaptFlag) |
---|
2989 | m_uiBitCoeff += xWriteVlc( vlc_adaptive, tmp ); |
---|
2990 | else |
---|
2991 | #endif |
---|
2992 | xWriteVlc( vlc_adaptive, tmp ); |
---|
2993 | if (scoeff[i]) |
---|
2994 | { |
---|
2995 | sign = (scoeff[i] < 0) ? 1 : 0; |
---|
2996 | xWriteFlag( sign ); |
---|
2997 | #if LCEC_STAT |
---|
2998 | if (m_bAdaptFlag) |
---|
2999 | m_uiBitCoeff += 1; |
---|
3000 | #endif |
---|
3001 | } |
---|
3002 | if (tmp>atable[vlc_adaptive]) |
---|
3003 | { |
---|
3004 | vlc_adaptive++; |
---|
3005 | } |
---|
3006 | } |
---|
3007 | |
---|
3008 | return; |
---|
3009 | } |
---|