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 | Bool bCornerBLInvolved = false; |
---|
882 | UInt uiNumCand = 0; |
---|
883 | for( UInt uiIter = 0; uiIter < HHI_NUM_MRG_CAND; ++uiIter ) |
---|
884 | { |
---|
885 | if( pcCU->getNeighbourCandIdx( uiIter, uiAbsPartIdx ) == uiIter + 1 ) |
---|
886 | { |
---|
887 | uiNumCand++; |
---|
888 | if( uiIter == 0 ) |
---|
889 | { |
---|
890 | bLeftInvolved = true; |
---|
891 | } |
---|
892 | else if( uiIter == 1 ) |
---|
893 | { |
---|
894 | bAboveInvolved = true; |
---|
895 | } |
---|
896 | else if( uiIter == 2 ) |
---|
897 | { |
---|
898 | bCollocatedInvolved = true; |
---|
899 | } |
---|
900 | else if( uiIter == 3 ) |
---|
901 | { |
---|
902 | bCornerInvolved = true; |
---|
903 | } |
---|
904 | else if( uiIter == 4 ) |
---|
905 | { |
---|
906 | bCornerBLInvolved = true; |
---|
907 | } |
---|
908 | } |
---|
909 | } |
---|
910 | assert( uiNumCand > 1 ); |
---|
911 | const UInt uiMergeIdx = pcCU->getMergeIndex( uiAbsPartIdx ); |
---|
912 | if( uiNumCand == 2 ) |
---|
913 | { |
---|
914 | UInt uiSymbol = 0; |
---|
915 | if( ( !bCornerInvolved && !bCornerBLInvolved && uiMergeIdx == 2 ) || ( !bCollocatedInvolved && !bCornerBLInvolved && !bCornerInvolved && uiMergeIdx == 1 ) || ( !bCornerBLInvolved && uiMergeIdx == 3 ) || uiMergeIdx == 4 ) |
---|
916 | { |
---|
917 | uiSymbol = 1; |
---|
918 | } |
---|
919 | xWriteFlag( uiSymbol ); |
---|
920 | return; |
---|
921 | } |
---|
922 | else if( uiNumCand == 3 )//uiMRGCands == 3 |
---|
923 | { |
---|
924 | if( uiMergeIdx == 0 || ( uiMergeIdx == 1 && !bLeftInvolved ) || ( uiMergeIdx == 2 && !bLeftInvolved && !bAboveInvolved ) ) |
---|
925 | { |
---|
926 | xWriteFlag( 0 ); |
---|
927 | } |
---|
928 | else |
---|
929 | { |
---|
930 | xWriteFlag( 1 ); |
---|
931 | if( uiMergeIdx == 4 || ( !bCornerBLInvolved && uiMergeIdx == 3 ) || ( !bCornerBLInvolved && !bCornerInvolved && uiMergeIdx == 2 ) ) |
---|
932 | { |
---|
933 | xWriteFlag( 1 ); |
---|
934 | } |
---|
935 | else |
---|
936 | { |
---|
937 | xWriteFlag( 0 ); |
---|
938 | } |
---|
939 | } |
---|
940 | } |
---|
941 | else //uiNumCand > 3 |
---|
942 | { |
---|
943 | if( uiMergeIdx == 0 ) |
---|
944 | { |
---|
945 | xWriteFlag( 0 ); |
---|
946 | } |
---|
947 | else |
---|
948 | { |
---|
949 | xWriteFlag( 1 ); |
---|
950 | if( uiMergeIdx == 1 ) |
---|
951 | { |
---|
952 | xWriteFlag( 0 ); |
---|
953 | } |
---|
954 | else |
---|
955 | { |
---|
956 | xWriteFlag( 1 ); |
---|
957 | if( uiMergeIdx == 2 ) |
---|
958 | { |
---|
959 | xWriteFlag( 0 ); |
---|
960 | } |
---|
961 | else |
---|
962 | { |
---|
963 | xWriteFlag( 1 ); |
---|
964 | if( uiMergeIdx == 3 ) |
---|
965 | { |
---|
966 | xWriteFlag( 0 ); |
---|
967 | } |
---|
968 | else |
---|
969 | { |
---|
970 | xWriteFlag( 1 ); |
---|
971 | } |
---|
972 | } |
---|
973 | } |
---|
974 | } |
---|
975 | } |
---|
976 | } |
---|
977 | #endif |
---|
978 | |
---|
979 | Void TEncCavlc::codeAlfCtrlFlag( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
980 | { |
---|
981 | if (!m_bAlfCtrl) |
---|
982 | return; |
---|
983 | |
---|
984 | if( pcCU->getDepth(uiAbsPartIdx) > m_uiMaxAlfCtrlDepth && !pcCU->isFirstAbsZorderIdxInDepth(uiAbsPartIdx, m_uiMaxAlfCtrlDepth)) |
---|
985 | { |
---|
986 | return; |
---|
987 | } |
---|
988 | |
---|
989 | // get context function is here |
---|
990 | UInt uiSymbol = pcCU->getAlfCtrlFlag( uiAbsPartIdx ) ? 1 : 0; |
---|
991 | |
---|
992 | xWriteFlag( uiSymbol ); |
---|
993 | #if LCEC_STAT |
---|
994 | if (m_bAdaptFlag) |
---|
995 | m_uiBitAlfCtrlFlag += 1; |
---|
996 | #endif |
---|
997 | } |
---|
998 | |
---|
999 | Void TEncCavlc::codeAlfCtrlDepth() |
---|
1000 | { |
---|
1001 | if (!m_bAlfCtrl) |
---|
1002 | return; |
---|
1003 | |
---|
1004 | UInt uiDepth = m_uiMaxAlfCtrlDepth; |
---|
1005 | |
---|
1006 | #if LCEC_STAT |
---|
1007 | if (m_bAdaptFlag) |
---|
1008 | m_uiBitAlfCtrlDepth += xWriteUnaryMaxSymbol(uiDepth, g_uiMaxCUDepth-1); |
---|
1009 | else |
---|
1010 | #endif |
---|
1011 | xWriteUnaryMaxSymbol(uiDepth, g_uiMaxCUDepth-1); |
---|
1012 | } |
---|
1013 | #if QC_LCEC_INTER_MODE |
---|
1014 | Void TEncCavlc::codeInterModeFlag( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, UInt uiEncMode ) |
---|
1015 | { |
---|
1016 | Bool bHasSplit = ( uiDepth == g_uiMaxCUDepth - g_uiAddCUDepth )? 0 : 1; |
---|
1017 | UInt uiSplitFlag = ( pcCU->getDepth( uiAbsPartIdx ) > uiDepth ) ? 1 : 0; |
---|
1018 | UInt uiMode=0,uiControl=0; |
---|
1019 | #if LCEC_INTER_MODE_BUG_FIX |
---|
1020 | UInt uiTableDepth = uiDepth; |
---|
1021 | if ( !bHasSplit ) |
---|
1022 | { |
---|
1023 | uiTableDepth = 3; |
---|
1024 | } |
---|
1025 | #endif |
---|
1026 | if(!uiSplitFlag || !bHasSplit) |
---|
1027 | { |
---|
1028 | uiMode = 1; |
---|
1029 | uiControl = 1; |
---|
1030 | if (!pcCU->isSkipped(uiAbsPartIdx )) |
---|
1031 | { |
---|
1032 | uiControl = 2; |
---|
1033 | uiMode = 6; |
---|
1034 | if (pcCU->getPredictionMode(uiAbsPartIdx) == MODE_INTER) |
---|
1035 | { |
---|
1036 | if(pcCU->getPartitionSize(uiAbsPartIdx) == SIZE_2Nx2N) |
---|
1037 | uiMode=pcCU->getMergeFlag(uiAbsPartIdx) ? 2 : 3; |
---|
1038 | else |
---|
1039 | uiMode=3+(UInt)pcCU->getPartitionSize(uiAbsPartIdx); |
---|
1040 | } |
---|
1041 | } |
---|
1042 | } |
---|
1043 | if (uiEncMode != uiControl ) |
---|
1044 | return; |
---|
1045 | UInt uiEndSym = bHasSplit ? 7 : 6; |
---|
1046 | #if LCEC_INTER_MODE_BUG_FIX |
---|
1047 | uiDepth = uiTableDepth; |
---|
1048 | #endif |
---|
1049 | UInt uiLength = m_uiSplitTableE[uiDepth][uiMode] + 1; |
---|
1050 | if (uiLength == uiEndSym) |
---|
1051 | { |
---|
1052 | xWriteCode( 0, uiLength - 1); |
---|
1053 | } |
---|
1054 | else |
---|
1055 | { |
---|
1056 | xWriteCode( 1, uiLength ); |
---|
1057 | } |
---|
1058 | UInt x = uiMode; |
---|
1059 | UInt cx = m_uiSplitTableE[uiDepth][x]; |
---|
1060 | /* Adapt table */ |
---|
1061 | if ( m_bAdaptFlag) |
---|
1062 | { |
---|
1063 | if(cx>0) |
---|
1064 | { |
---|
1065 | UInt cy = Max(0,cx-1); |
---|
1066 | UInt y = m_uiSplitTableD[uiDepth][cy]; |
---|
1067 | m_uiSplitTableD[uiDepth][cy] = x; |
---|
1068 | m_uiSplitTableD[uiDepth][cx] = y; |
---|
1069 | m_uiSplitTableE[uiDepth][x] = cy; |
---|
1070 | m_uiSplitTableE[uiDepth][y] = cx; |
---|
1071 | } |
---|
1072 | } |
---|
1073 | return; |
---|
1074 | } |
---|
1075 | #endif |
---|
1076 | Void TEncCavlc::codeSkipFlag( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
1077 | { |
---|
1078 | #if QC_LCEC_INTER_MODE |
---|
1079 | codeInterModeFlag(pcCU,uiAbsPartIdx,(UInt)pcCU->getDepth(uiAbsPartIdx),1); |
---|
1080 | return; |
---|
1081 | #else |
---|
1082 | // get context function is here |
---|
1083 | UInt uiSymbol = pcCU->isSkipped( uiAbsPartIdx ) ? 1 : 0; |
---|
1084 | xWriteFlag( uiSymbol ); |
---|
1085 | #if LCEC_STAT |
---|
1086 | if (m_bAdaptFlag) |
---|
1087 | m_uiBitSkipFlag += 1; |
---|
1088 | #endif |
---|
1089 | #endif |
---|
1090 | } |
---|
1091 | |
---|
1092 | Void TEncCavlc::codeSplitFlag ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth ) |
---|
1093 | { |
---|
1094 | if( uiDepth == g_uiMaxCUDepth - g_uiAddCUDepth ) |
---|
1095 | return; |
---|
1096 | #if QC_LCEC_INTER_MODE |
---|
1097 | if (!pcCU->getSlice()->isIntra()) |
---|
1098 | { |
---|
1099 | codeInterModeFlag(pcCU,uiAbsPartIdx,uiDepth,0); |
---|
1100 | return; |
---|
1101 | } |
---|
1102 | #endif |
---|
1103 | UInt uiCurrSplitFlag = ( pcCU->getDepth( uiAbsPartIdx ) > uiDepth ) ? 1 : 0; |
---|
1104 | |
---|
1105 | xWriteFlag( uiCurrSplitFlag ); |
---|
1106 | #if LCEC_STAT |
---|
1107 | if (m_bAdaptFlag) |
---|
1108 | m_uiBitCurrSplitFlag += 1; |
---|
1109 | #endif |
---|
1110 | return; |
---|
1111 | } |
---|
1112 | |
---|
1113 | Void TEncCavlc::codeTransformSubdivFlag( UInt uiSymbol, UInt uiCtx ) |
---|
1114 | { |
---|
1115 | xWriteFlag( uiSymbol ); |
---|
1116 | #if LCEC_STAT |
---|
1117 | if (m_bAdaptFlag) |
---|
1118 | m_uiBitTransformSubdivFlag += 1; |
---|
1119 | #endif |
---|
1120 | } |
---|
1121 | |
---|
1122 | Void TEncCavlc::codeQtCbf( TComDataCU* pcCU, UInt uiAbsPartIdx, TextType eType, UInt uiTrDepth ) |
---|
1123 | { |
---|
1124 | UInt uiCbf = pcCU->getCbf( uiAbsPartIdx, eType, uiTrDepth ); |
---|
1125 | xWriteFlag( uiCbf ); |
---|
1126 | #if LCEC_STAT |
---|
1127 | if (m_bAdaptFlag) |
---|
1128 | m_uiBitQtCbf += 1; |
---|
1129 | #endif |
---|
1130 | } |
---|
1131 | |
---|
1132 | Void TEncCavlc::codeQtRootCbf( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
1133 | { |
---|
1134 | UInt uiCbf = pcCU->getQtRootCbf( uiAbsPartIdx ); |
---|
1135 | xWriteFlag( uiCbf ? 1 : 0 ); |
---|
1136 | } |
---|
1137 | |
---|
1138 | #if LCEC_INTRA_MODE |
---|
1139 | Void TEncCavlc::codeIntraDirLumaAng( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
1140 | { |
---|
1141 | Int iDir = pcCU->getLumaIntraDir( uiAbsPartIdx ); |
---|
1142 | Int iMostProbable = pcCU->getMostProbableIntraDirLuma( uiAbsPartIdx ); |
---|
1143 | Int iIntraIdx = pcCU->getIntraSizeIdx(uiAbsPartIdx); |
---|
1144 | UInt uiCode, uiLength; |
---|
1145 | Int iRankIntraMode, iRankIntraModeLarger, iDirLarger; |
---|
1146 | |
---|
1147 | UInt ind=(pcCU->getLeftIntraDirLuma( uiAbsPartIdx )==pcCU->getAboveIntraDirLuma( uiAbsPartIdx ))? 0 : 1; |
---|
1148 | |
---|
1149 | const UInt *huff17=huff17_2[ind]; |
---|
1150 | const UInt *lengthHuff17=lengthHuff17_2[ind]; |
---|
1151 | const UInt *huff34=huff34_2[ind]; |
---|
1152 | const UInt *lengthHuff34=lengthHuff34_2[ind]; |
---|
1153 | |
---|
1154 | if ( g_aucIntraModeBitsAng[iIntraIdx] < 5 ) |
---|
1155 | { |
---|
1156 | if (iDir == iMostProbable) |
---|
1157 | xWriteFlag( 1 ); |
---|
1158 | else{ |
---|
1159 | if (iDir>iMostProbable) |
---|
1160 | iDir--; |
---|
1161 | xWriteFlag( 0 ); |
---|
1162 | xWriteFlag( iDir & 0x01 ? 1 : 0 ); |
---|
1163 | if ( g_aucIntraModeBitsAng[iIntraIdx] > 2 ) xWriteFlag( iDir & 0x02 ? 1 : 0 ); |
---|
1164 | if ( g_aucIntraModeBitsAng[iIntraIdx] > 3 ) xWriteFlag( iDir & 0x04 ? 1 : 0 ); |
---|
1165 | } |
---|
1166 | } |
---|
1167 | else if ( g_aucIntraModeBitsAng[iIntraIdx] == 5 ){ |
---|
1168 | |
---|
1169 | if (iDir==iMostProbable){ |
---|
1170 | uiCode=huff17[0]; |
---|
1171 | uiLength=lengthHuff17[0]; |
---|
1172 | } |
---|
1173 | else{ |
---|
1174 | if (iDir>iMostProbable){ |
---|
1175 | iDir--; |
---|
1176 | } |
---|
1177 | iRankIntraMode=m_uiIntraModeTableE17[iDir]; |
---|
1178 | |
---|
1179 | uiCode=huff17[iRankIntraMode+1]; |
---|
1180 | uiLength=lengthHuff17[iRankIntraMode+1]; |
---|
1181 | |
---|
1182 | if ( m_bAdaptFlag ) |
---|
1183 | { |
---|
1184 | iRankIntraModeLarger = Max(0,iRankIntraMode-1); |
---|
1185 | iDirLarger = m_uiIntraModeTableD17[iRankIntraModeLarger]; |
---|
1186 | |
---|
1187 | m_uiIntraModeTableD17[iRankIntraModeLarger] = iDir; |
---|
1188 | m_uiIntraModeTableD17[iRankIntraMode] = iDirLarger; |
---|
1189 | m_uiIntraModeTableE17[iDir] = iRankIntraModeLarger; |
---|
1190 | m_uiIntraModeTableE17[iDirLarger] = iRankIntraMode; |
---|
1191 | } |
---|
1192 | } |
---|
1193 | xWriteCode(uiCode, uiLength); |
---|
1194 | } |
---|
1195 | else{ |
---|
1196 | if (iDir==iMostProbable){ |
---|
1197 | uiCode=huff34[0]; |
---|
1198 | uiLength=lengthHuff34[0]; |
---|
1199 | } |
---|
1200 | else{ |
---|
1201 | if (iDir>iMostProbable){ |
---|
1202 | iDir--; |
---|
1203 | } |
---|
1204 | iRankIntraMode=m_uiIntraModeTableE34[iDir]; |
---|
1205 | |
---|
1206 | uiCode=huff34[iRankIntraMode+1]; |
---|
1207 | uiLength=lengthHuff34[iRankIntraMode+1]; |
---|
1208 | |
---|
1209 | if ( m_bAdaptFlag ) |
---|
1210 | { |
---|
1211 | iRankIntraModeLarger = Max(0,iRankIntraMode-1); |
---|
1212 | iDirLarger = m_uiIntraModeTableD34[iRankIntraModeLarger]; |
---|
1213 | |
---|
1214 | m_uiIntraModeTableD34[iRankIntraModeLarger] = iDir; |
---|
1215 | m_uiIntraModeTableD34[iRankIntraMode] = iDirLarger; |
---|
1216 | m_uiIntraModeTableE34[iDir] = iRankIntraModeLarger; |
---|
1217 | m_uiIntraModeTableE34[iDirLarger] = iRankIntraMode; |
---|
1218 | } |
---|
1219 | } |
---|
1220 | |
---|
1221 | xWriteCode(uiCode, uiLength); |
---|
1222 | } |
---|
1223 | } |
---|
1224 | |
---|
1225 | #else |
---|
1226 | |
---|
1227 | Void TEncCavlc::codeIntraDirLumaAng( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
1228 | { |
---|
1229 | UInt uiDir = pcCU->getLumaIntraDir( uiAbsPartIdx ); |
---|
1230 | Int iMostProbable = pcCU->getMostProbableIntraDirLuma( uiAbsPartIdx ); |
---|
1231 | |
---|
1232 | if (uiDir == iMostProbable) |
---|
1233 | { |
---|
1234 | xWriteFlag( 1 ); |
---|
1235 | #if LCEC_STAT |
---|
1236 | if (m_bAdaptFlag) |
---|
1237 | m_uiBitIntraDir += 1; |
---|
1238 | #endif |
---|
1239 | } |
---|
1240 | else |
---|
1241 | { |
---|
1242 | xWriteFlag( 0 ); |
---|
1243 | #if LCEC_STAT |
---|
1244 | if (m_bAdaptFlag) |
---|
1245 | m_uiBitIntraDir += 1; |
---|
1246 | #endif |
---|
1247 | uiDir = uiDir > iMostProbable ? uiDir - 1 : uiDir; |
---|
1248 | Int iIntraIdx = pcCU->getIntraSizeIdx(uiAbsPartIdx); |
---|
1249 | if ( g_aucIntraModeBitsAng[iIntraIdx] < 6 ) |
---|
1250 | { |
---|
1251 | xWriteFlag( uiDir & 0x01 ? 1 : 0 ); |
---|
1252 | if ( g_aucIntraModeBitsAng[iIntraIdx] > 2 ) xWriteFlag( uiDir & 0x02 ? 1 : 0 ); |
---|
1253 | if ( g_aucIntraModeBitsAng[iIntraIdx] > 3 ) xWriteFlag( uiDir & 0x04 ? 1 : 0 ); |
---|
1254 | if ( g_aucIntraModeBitsAng[iIntraIdx] > 4 ) xWriteFlag( uiDir & 0x08 ? 1 : 0 ); |
---|
1255 | |
---|
1256 | #if LCEC_STAT |
---|
1257 | if (m_bAdaptFlag) |
---|
1258 | { |
---|
1259 | m_uiBitIntraDir += 1; |
---|
1260 | if ( g_aucIntraModeBitsAng[iIntraIdx] > 2 ) m_uiBitIntraDir += 1; |
---|
1261 | if ( g_aucIntraModeBitsAng[iIntraIdx] > 3 ) m_uiBitIntraDir += 1; |
---|
1262 | if ( g_aucIntraModeBitsAng[iIntraIdx] > 4 ) m_uiBitIntraDir += 1; |
---|
1263 | } |
---|
1264 | #endif |
---|
1265 | |
---|
1266 | } |
---|
1267 | else |
---|
1268 | { |
---|
1269 | if (uiDir < 31) |
---|
1270 | { // 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 |
---|
1271 | xWriteFlag( uiDir & 0x01 ? 1 : 0 ); |
---|
1272 | xWriteFlag( uiDir & 0x02 ? 1 : 0 ); |
---|
1273 | xWriteFlag( uiDir & 0x04 ? 1 : 0 ); |
---|
1274 | xWriteFlag( uiDir & 0x08 ? 1 : 0 ); |
---|
1275 | xWriteFlag( uiDir & 0x10 ? 1 : 0 ); |
---|
1276 | #if LCEC_STAT |
---|
1277 | if (m_bAdaptFlag) |
---|
1278 | m_uiBitIntraDir += 5; |
---|
1279 | #endif |
---|
1280 | } |
---|
1281 | else |
---|
1282 | { |
---|
1283 | xWriteFlag( 1 ); |
---|
1284 | xWriteFlag( 1 ); |
---|
1285 | xWriteFlag( 1 ); |
---|
1286 | xWriteFlag( 1 ); |
---|
1287 | xWriteFlag( 1 ); |
---|
1288 | xWriteFlag( uiDir == 32 ? 1 : 0 ); |
---|
1289 | #if LCEC_STAT |
---|
1290 | if (m_bAdaptFlag) |
---|
1291 | m_uiBitIntraDir += 6; |
---|
1292 | #endif |
---|
1293 | } |
---|
1294 | } |
---|
1295 | } |
---|
1296 | } |
---|
1297 | #endif |
---|
1298 | |
---|
1299 | Void TEncCavlc::codeIntraDirChroma( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
1300 | { |
---|
1301 | UInt uiIntraDirChroma = pcCU->getChromaIntraDir ( uiAbsPartIdx ); |
---|
1302 | #if CHROMA_CODEWORD |
---|
1303 | UInt uiMode = pcCU->getLumaIntraDir(uiAbsPartIdx); |
---|
1304 | Int iMax = uiMode < 4 ? 3 : 4; |
---|
1305 | |
---|
1306 | //switch codeword |
---|
1307 | if (uiIntraDirChroma == 4) |
---|
1308 | { |
---|
1309 | uiIntraDirChroma = 0; |
---|
1310 | } |
---|
1311 | #if CHROMA_CODEWORD_SWITCH |
---|
1312 | else |
---|
1313 | { |
---|
1314 | if (uiIntraDirChroma < uiMode) |
---|
1315 | { |
---|
1316 | uiIntraDirChroma++; |
---|
1317 | } |
---|
1318 | uiIntraDirChroma = ChromaMapping[iMax-3][uiIntraDirChroma]; |
---|
1319 | } |
---|
1320 | #else |
---|
1321 | else if (uiIntraDirChroma < uiMode) |
---|
1322 | { |
---|
1323 | uiIntraDirChroma++; |
---|
1324 | } |
---|
1325 | #endif |
---|
1326 | xWriteUnaryMaxSymbol( uiIntraDirChroma, iMax); |
---|
1327 | #else // CHROMA_CODEWORD |
---|
1328 | if ( 0 == uiIntraDirChroma ) |
---|
1329 | { |
---|
1330 | xWriteFlag( 0 ); |
---|
1331 | #if LCEC_STAT |
---|
1332 | if (m_bAdaptFlag) |
---|
1333 | m_uiBitIntraDir += 1; |
---|
1334 | #endif |
---|
1335 | } |
---|
1336 | else |
---|
1337 | { |
---|
1338 | xWriteFlag( 1 ); |
---|
1339 | #if LCEC_STAT |
---|
1340 | if (m_bAdaptFlag) |
---|
1341 | { |
---|
1342 | m_uiBitIntraDir += 1; |
---|
1343 | m_uiBitIntraDir += xWriteUnaryMaxSymbol( uiIntraDirChroma - 1, 3 ); |
---|
1344 | } |
---|
1345 | else |
---|
1346 | #endif |
---|
1347 | xWriteUnaryMaxSymbol( uiIntraDirChroma - 1, 3 ); |
---|
1348 | } |
---|
1349 | #endif |
---|
1350 | return; |
---|
1351 | } |
---|
1352 | |
---|
1353 | Void TEncCavlc::codeInterDir( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
1354 | { |
---|
1355 | UInt uiInterDir = pcCU->getInterDir ( uiAbsPartIdx ); |
---|
1356 | uiInterDir--; |
---|
1357 | |
---|
1358 | #if MS_LCEC_LOOKUP_TABLE_EXCEPTION |
---|
1359 | if ( pcCU->getSlice()->getRefIdxCombineCoding() ) |
---|
1360 | #else |
---|
1361 | if(pcCU->getSlice()->getNumRefIdx( REF_PIC_LIST_0 ) <= 2 && pcCU->getSlice()->getNumRefIdx( REF_PIC_LIST_1 ) <= 2) |
---|
1362 | #endif |
---|
1363 | { |
---|
1364 | Int x,cx,y,cy; |
---|
1365 | Int iRefFrame0,iRefFrame1; |
---|
1366 | UInt uiIndex; |
---|
1367 | |
---|
1368 | UInt *m_uiMITableE; |
---|
1369 | UInt *m_uiMITableD; |
---|
1370 | { |
---|
1371 | m_uiMITableE = m_uiMI1TableE; |
---|
1372 | m_uiMITableD = m_uiMI1TableD; |
---|
1373 | if (uiInterDir==0) |
---|
1374 | { |
---|
1375 | #if DCM_COMB_LIST |
---|
1376 | if(pcCU->getSlice()->getNumRefIdx(REF_PIC_LIST_C) > 0) |
---|
1377 | { |
---|
1378 | iRefFrame0 = pcCU->getSlice()->getRefIdxOfLC(REF_PIC_LIST_0, pcCU->getCUMvField( REF_PIC_LIST_0 )->getRefIdx( uiAbsPartIdx )); |
---|
1379 | } |
---|
1380 | else |
---|
1381 | { |
---|
1382 | iRefFrame0 = pcCU->getCUMvField( REF_PIC_LIST_0 )->getRefIdx( uiAbsPartIdx ); |
---|
1383 | } |
---|
1384 | #else |
---|
1385 | iRefFrame0 = pcCU->getCUMvField( REF_PIC_LIST_0 )->getRefIdx( uiAbsPartIdx ); |
---|
1386 | #endif |
---|
1387 | uiIndex = iRefFrame0; |
---|
1388 | |
---|
1389 | #if MS_LCEC_LOOKUP_TABLE_EXCEPTION |
---|
1390 | if(pcCU->getSlice()->getNumRefIdx(REF_PIC_LIST_C) > 0) |
---|
1391 | { |
---|
1392 | if ( iRefFrame0 >= 4 ) |
---|
1393 | { |
---|
1394 | uiIndex = 8; |
---|
1395 | } |
---|
1396 | } |
---|
1397 | else |
---|
1398 | { |
---|
1399 | if ( iRefFrame0 > MS_LCEC_UNI_EXCEPTION_THRES ) |
---|
1400 | { |
---|
1401 | uiIndex = 8; |
---|
1402 | } |
---|
1403 | } |
---|
1404 | #endif |
---|
1405 | } |
---|
1406 | else if (uiInterDir==1) |
---|
1407 | { |
---|
1408 | #if DCM_COMB_LIST |
---|
1409 | if(pcCU->getSlice()->getNumRefIdx(REF_PIC_LIST_C) > 0) |
---|
1410 | { |
---|
1411 | iRefFrame1 = pcCU->getSlice()->getRefIdxOfLC(REF_PIC_LIST_1, pcCU->getCUMvField( REF_PIC_LIST_1 )->getRefIdx( uiAbsPartIdx )); |
---|
1412 | uiIndex = iRefFrame1; |
---|
1413 | } |
---|
1414 | else |
---|
1415 | { |
---|
1416 | iRefFrame1 = pcCU->getCUMvField( REF_PIC_LIST_1 )->getRefIdx( uiAbsPartIdx ); |
---|
1417 | uiIndex = 2 + iRefFrame1; |
---|
1418 | } |
---|
1419 | #if MS_LCEC_LOOKUP_TABLE_EXCEPTION |
---|
1420 | if(pcCU->getSlice()->getNumRefIdx(REF_PIC_LIST_C) > 0) |
---|
1421 | { |
---|
1422 | if ( iRefFrame1 >= 4 ) |
---|
1423 | { |
---|
1424 | uiIndex = 8; |
---|
1425 | } |
---|
1426 | } |
---|
1427 | else |
---|
1428 | { |
---|
1429 | if ( iRefFrame1 > MS_LCEC_UNI_EXCEPTION_THRES ) |
---|
1430 | { |
---|
1431 | uiIndex = 8; |
---|
1432 | } |
---|
1433 | } |
---|
1434 | #endif |
---|
1435 | #else |
---|
1436 | iRefFrame1 = pcCU->getCUMvField( REF_PIC_LIST_1 )->getRefIdx( uiAbsPartIdx ); |
---|
1437 | uiIndex = 2 + iRefFrame1; |
---|
1438 | #endif |
---|
1439 | } |
---|
1440 | else |
---|
1441 | { |
---|
1442 | iRefFrame0 = pcCU->getCUMvField( REF_PIC_LIST_0 )->getRefIdx( uiAbsPartIdx ); |
---|
1443 | iRefFrame1 = pcCU->getCUMvField( REF_PIC_LIST_1 )->getRefIdx( uiAbsPartIdx ); |
---|
1444 | uiIndex = 4 + 2*iRefFrame0 + iRefFrame1; |
---|
1445 | #if MS_LCEC_LOOKUP_TABLE_EXCEPTION |
---|
1446 | if ( iRefFrame0 >= 2 || iRefFrame1 >= 2 ) |
---|
1447 | { |
---|
1448 | uiIndex = 8; |
---|
1449 | } |
---|
1450 | #endif |
---|
1451 | } |
---|
1452 | } |
---|
1453 | |
---|
1454 | x = uiIndex; |
---|
1455 | |
---|
1456 | cx = m_uiMITableE[x]; |
---|
1457 | |
---|
1458 | /* Adapt table */ |
---|
1459 | #if !MS_LCEC_LOOKUP_TABLE_MAX_VALUE |
---|
1460 | UInt vlcn = g_auiMITableVlcNum[m_uiMITableVlcIdx]; |
---|
1461 | #endif |
---|
1462 | if ( m_bAdaptFlag ) |
---|
1463 | { |
---|
1464 | cy = Max(0,cx-1); |
---|
1465 | y = m_uiMITableD[cy]; |
---|
1466 | m_uiMITableD[cy] = x; |
---|
1467 | m_uiMITableD[cx] = y; |
---|
1468 | m_uiMITableE[x] = cy; |
---|
1469 | m_uiMITableE[y] = cx; |
---|
1470 | m_uiMITableVlcIdx += cx == m_uiMITableVlcIdx ? 0 : (cx < m_uiMITableVlcIdx ? -1 : 1); |
---|
1471 | } |
---|
1472 | |
---|
1473 | #if LCEC_STAT |
---|
1474 | if (m_bAdaptFlag) |
---|
1475 | m_uiBitMI += xWriteVlc( vlcn, cx ); |
---|
1476 | else |
---|
1477 | #endif |
---|
1478 | { |
---|
1479 | #if MS_LCEC_LOOKUP_TABLE_MAX_VALUE |
---|
1480 | UInt uiMaxVal = 7; |
---|
1481 | #if MS_LCEC_LOOKUP_TABLE_EXCEPTION |
---|
1482 | uiMaxVal = 8; |
---|
1483 | #endif |
---|
1484 | if ( pcCU->getSlice()->getNumRefIdx( REF_PIC_LIST_0 ) <= 1 && pcCU->getSlice()->getNumRefIdx( REF_PIC_LIST_1 ) <= 1 ) |
---|
1485 | { |
---|
1486 | if ( pcCU->getSlice()->getNoBackPredFlag() || ( pcCU->getSlice()->getNumRefIdx(REF_PIC_LIST_C) > 0 && pcCU->getSlice()->getNumRefIdx(REF_PIC_LIST_C) <= 1 ) ) |
---|
1487 | { |
---|
1488 | uiMaxVal = 1; |
---|
1489 | } |
---|
1490 | else |
---|
1491 | { |
---|
1492 | uiMaxVal = 2; |
---|
1493 | } |
---|
1494 | } |
---|
1495 | else if ( pcCU->getSlice()->getNumRefIdx( REF_PIC_LIST_0 ) <= 2 && pcCU->getSlice()->getNumRefIdx( REF_PIC_LIST_1 ) <= 2 ) |
---|
1496 | { |
---|
1497 | if ( pcCU->getSlice()->getNoBackPredFlag() || ( pcCU->getSlice()->getNumRefIdx(REF_PIC_LIST_C) > 0 && pcCU->getSlice()->getNumRefIdx(REF_PIC_LIST_C) <= 2 ) ) |
---|
1498 | { |
---|
1499 | uiMaxVal = 5; |
---|
1500 | } |
---|
1501 | else |
---|
1502 | { |
---|
1503 | uiMaxVal = 7; |
---|
1504 | } |
---|
1505 | } |
---|
1506 | else if ( pcCU->getSlice()->getNumRefIdx(REF_PIC_LIST_C) <= 0 ) // GPB case |
---|
1507 | { |
---|
1508 | uiMaxVal = 4+1+MS_LCEC_UNI_EXCEPTION_THRES; |
---|
1509 | } |
---|
1510 | |
---|
1511 | xWriteUnaryMaxSymbol( cx, uiMaxVal ); |
---|
1512 | #else |
---|
1513 | xWriteVlc( vlcn, cx ); |
---|
1514 | #endif |
---|
1515 | } |
---|
1516 | |
---|
1517 | #if MS_LCEC_LOOKUP_TABLE_EXCEPTION |
---|
1518 | if ( x<8 ) |
---|
1519 | #endif |
---|
1520 | { |
---|
1521 | return; |
---|
1522 | } |
---|
1523 | } |
---|
1524 | |
---|
1525 | xWriteFlag( ( uiInterDir == 2 ? 1 : 0 )); |
---|
1526 | #if LCEC_STAT |
---|
1527 | if (m_bAdaptFlag) |
---|
1528 | m_uiBitInterDir += 1; |
---|
1529 | #endif |
---|
1530 | #if MS_NO_BACK_PRED_IN_B0 |
---|
1531 | if ( pcCU->getSlice()->getNoBackPredFlag() ) |
---|
1532 | { |
---|
1533 | assert( uiInterDir != 1 ); |
---|
1534 | return; |
---|
1535 | } |
---|
1536 | #endif |
---|
1537 | #if DCM_COMB_LIST |
---|
1538 | if ( uiInterDir < 2 && pcCU->getSlice()->getNumRefIdx(REF_PIC_LIST_C) <= 0) |
---|
1539 | #else |
---|
1540 | if ( uiInterDir < 2 ) |
---|
1541 | #endif |
---|
1542 | { |
---|
1543 | xWriteFlag( uiInterDir ); |
---|
1544 | #if LCEC_STAT |
---|
1545 | if (m_bAdaptFlag) |
---|
1546 | m_uiBitInterDir += 1; |
---|
1547 | #endif |
---|
1548 | } |
---|
1549 | |
---|
1550 | return; |
---|
1551 | } |
---|
1552 | |
---|
1553 | Void TEncCavlc::codeRefFrmIdx( TComDataCU* pcCU, UInt uiAbsPartIdx, RefPicList eRefList ) |
---|
1554 | { |
---|
1555 | #if DCM_COMB_LIST |
---|
1556 | Int iRefFrame; |
---|
1557 | RefPicList eRefListTemp; |
---|
1558 | |
---|
1559 | if( pcCU->getSlice()->getNumRefIdx(REF_PIC_LIST_C)>0) |
---|
1560 | { |
---|
1561 | if ( pcCU->getInterDir( uiAbsPartIdx ) != 3) |
---|
1562 | { |
---|
1563 | eRefListTemp = REF_PIC_LIST_C; |
---|
1564 | iRefFrame = pcCU->getSlice()->getRefIdxOfLC(eRefList, pcCU->getCUMvField( eRefList )->getRefIdx( uiAbsPartIdx )); |
---|
1565 | } |
---|
1566 | else |
---|
1567 | { |
---|
1568 | eRefListTemp = eRefList; |
---|
1569 | iRefFrame = pcCU->getCUMvField( eRefList )->getRefIdx( uiAbsPartIdx ); |
---|
1570 | } |
---|
1571 | } |
---|
1572 | else |
---|
1573 | { |
---|
1574 | eRefListTemp = eRefList; |
---|
1575 | iRefFrame = pcCU->getCUMvField( eRefList )->getRefIdx( uiAbsPartIdx ); |
---|
1576 | } |
---|
1577 | #else |
---|
1578 | Int iRefFrame = pcCU->getCUMvField( eRefList )->getRefIdx( uiAbsPartIdx ); |
---|
1579 | #endif |
---|
1580 | |
---|
1581 | if (pcCU->getSlice()->getNumRefIdx( REF_PIC_LIST_0 ) <= 2 && pcCU->getSlice()->getNumRefIdx( REF_PIC_LIST_1 ) <= 2 && pcCU->getSlice()->isInterB()) |
---|
1582 | { |
---|
1583 | return; |
---|
1584 | } |
---|
1585 | |
---|
1586 | #if MS_LCEC_LOOKUP_TABLE_EXCEPTION |
---|
1587 | if ( pcCU->getSlice()->getRefIdxCombineCoding() && pcCU->getInterDir(uiAbsPartIdx)==3 && |
---|
1588 | pcCU->getCUMvField( REF_PIC_LIST_0 )->getRefIdx( uiAbsPartIdx ) < 2 && |
---|
1589 | pcCU->getCUMvField( REF_PIC_LIST_1 )->getRefIdx( uiAbsPartIdx ) < 2 ) |
---|
1590 | { |
---|
1591 | return; |
---|
1592 | } |
---|
1593 | else if ( pcCU->getSlice()->getRefIdxCombineCoding() && pcCU->getInterDir(uiAbsPartIdx)==1 && |
---|
1594 | ( ( pcCU->getSlice()->getNumRefIdx(REF_PIC_LIST_C)>0 && pcCU->getSlice()->getRefIdxOfLC(REF_PIC_LIST_0, pcCU->getCUMvField( REF_PIC_LIST_0 )->getRefIdx( uiAbsPartIdx )) < 4 ) || |
---|
1595 | ( pcCU->getSlice()->getNumRefIdx(REF_PIC_LIST_C)<=0 && pcCU->getCUMvField( REF_PIC_LIST_0 )->getRefIdx( uiAbsPartIdx ) <= MS_LCEC_UNI_EXCEPTION_THRES ) ) ) |
---|
1596 | { |
---|
1597 | return; |
---|
1598 | } |
---|
1599 | 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 ) |
---|
1600 | { |
---|
1601 | return; |
---|
1602 | } |
---|
1603 | |
---|
1604 | UInt uiRefFrmIdxMinus = 0; |
---|
1605 | if ( pcCU->getSlice()->getRefIdxCombineCoding() ) |
---|
1606 | { |
---|
1607 | if ( pcCU->getInterDir( uiAbsPartIdx ) != 3 ) |
---|
1608 | { |
---|
1609 | if ( pcCU->getSlice()->getNumRefIdx(REF_PIC_LIST_C) > 0 ) |
---|
1610 | { |
---|
1611 | uiRefFrmIdxMinus = 4; |
---|
1612 | assert( iRefFrame >=4 ); |
---|
1613 | } |
---|
1614 | else |
---|
1615 | { |
---|
1616 | uiRefFrmIdxMinus = MS_LCEC_UNI_EXCEPTION_THRES+1; |
---|
1617 | assert( iRefFrame > MS_LCEC_UNI_EXCEPTION_THRES ); |
---|
1618 | } |
---|
1619 | |
---|
1620 | } |
---|
1621 | else if ( eRefList == REF_PIC_LIST_1 && pcCU->getCUMvField( REF_PIC_LIST_0 )->getRefIdx( uiAbsPartIdx ) < 2 ) |
---|
1622 | { |
---|
1623 | uiRefFrmIdxMinus = 2; |
---|
1624 | assert( iRefFrame >= 2 ); |
---|
1625 | } |
---|
1626 | } |
---|
1627 | |
---|
1628 | if ( pcCU->getSlice()->getNumRefIdx( eRefListTemp ) - uiRefFrmIdxMinus <= 1 ) |
---|
1629 | { |
---|
1630 | return; |
---|
1631 | } |
---|
1632 | xWriteFlag( ( iRefFrame - uiRefFrmIdxMinus == 0 ? 0 : 1 ) ); |
---|
1633 | #else |
---|
1634 | xWriteFlag( ( iRefFrame == 0 ? 0 : 1 ) ); |
---|
1635 | #endif |
---|
1636 | |
---|
1637 | #if LCEC_STAT |
---|
1638 | if (m_bAdaptFlag) |
---|
1639 | m_uiBitIRefFrmIdx += 1; |
---|
1640 | #endif |
---|
1641 | |
---|
1642 | #if MS_LCEC_LOOKUP_TABLE_EXCEPTION |
---|
1643 | if ( iRefFrame - uiRefFrmIdxMinus > 0 ) |
---|
1644 | #else |
---|
1645 | if ( iRefFrame > 0 ) |
---|
1646 | #endif |
---|
1647 | { |
---|
1648 | #if LCEC_STAT |
---|
1649 | if (m_bAdaptFlag) |
---|
1650 | { |
---|
1651 | #if DCM_COMB_LIST |
---|
1652 | #if MS_LCEC_LOOKUP_TABLE_EXCEPTION |
---|
1653 | m_uiBitIRefFrmIdx += xWriteUnaryMaxSymbol( iRefFrame - 1 - uiRefFrmIdxMinus, pcCU->getSlice()->getNumRefIdx( eRefListTemp )-2 - uiRefFrmIdxMinus ); |
---|
1654 | #else |
---|
1655 | m_uiBitIRefFrmIdx += xWriteUnaryMaxSymbol( iRefFrame - 1, pcCU->getSlice()->getNumRefIdx( eRefListTemp )-2 ); |
---|
1656 | #endif |
---|
1657 | #else |
---|
1658 | #if MS_LCEC_LOOKUP_TABLE_EXCEPTION |
---|
1659 | m_uiBitIRefFrmIdx += xWriteUnaryMaxSymbol( iRefFrame - 1 - uiRefFrmIdxMinus, pcCU->getSlice()->getNumRefIdx( eRefList )-2 - uiRefFrmIdxMinus ); |
---|
1660 | #else |
---|
1661 | m_uiBitIRefFrmIdx += xWriteUnaryMaxSymbol( iRefFrame - 1, pcCU->getSlice()->getNumRefIdx( eRefList )-2 ); |
---|
1662 | #endif |
---|
1663 | #endif |
---|
1664 | } |
---|
1665 | else |
---|
1666 | #endif |
---|
1667 | { |
---|
1668 | #if DCM_COMB_LIST |
---|
1669 | #if MS_LCEC_LOOKUP_TABLE_EXCEPTION |
---|
1670 | xWriteUnaryMaxSymbol( iRefFrame - 1 - uiRefFrmIdxMinus, pcCU->getSlice()->getNumRefIdx( eRefListTemp )-2 - uiRefFrmIdxMinus ); |
---|
1671 | #else |
---|
1672 | xWriteUnaryMaxSymbol( iRefFrame - 1, pcCU->getSlice()->getNumRefIdx( eRefListTemp )-2 ); |
---|
1673 | #endif |
---|
1674 | #else |
---|
1675 | #if MS_LCEC_LOOKUP_TABLE_EXCEPTION |
---|
1676 | xWriteUnaryMaxSymbol( iRefFrame - 1 - uiRefFrmIdxMinus, pcCU->getSlice()->getNumRefIdx( eRefList )-2 - uiRefFrmIdxMinus ); |
---|
1677 | #else |
---|
1678 | xWriteUnaryMaxSymbol( iRefFrame - 1, pcCU->getSlice()->getNumRefIdx( eRefList )-2 ); |
---|
1679 | #endif |
---|
1680 | #endif |
---|
1681 | } |
---|
1682 | } |
---|
1683 | return; |
---|
1684 | } |
---|
1685 | |
---|
1686 | Void TEncCavlc::codeMvd( TComDataCU* pcCU, UInt uiAbsPartIdx, RefPicList eRefList ) |
---|
1687 | { |
---|
1688 | TComCUMvField* pcCUMvField = pcCU->getCUMvField( eRefList ); |
---|
1689 | Int iHor = pcCUMvField->getMvd( uiAbsPartIdx ).getHor(); |
---|
1690 | Int iVer = pcCUMvField->getMvd( uiAbsPartIdx ).getVer(); |
---|
1691 | |
---|
1692 | UInt uiAbsPartIdxL, uiAbsPartIdxA; |
---|
1693 | Int iHorPred, iVerPred; |
---|
1694 | |
---|
1695 | TComDataCU* pcCUL = pcCU->getPULeft ( uiAbsPartIdxL, pcCU->getZorderIdxInCU() + uiAbsPartIdx ); |
---|
1696 | TComDataCU* pcCUA = pcCU->getPUAbove( uiAbsPartIdxA, pcCU->getZorderIdxInCU() + uiAbsPartIdx ); |
---|
1697 | |
---|
1698 | TComCUMvField* pcCUMvFieldL = ( pcCUL == NULL || pcCUL->isIntra( uiAbsPartIdxL ) ) ? NULL : pcCUL->getCUMvField( eRefList ); |
---|
1699 | TComCUMvField* pcCUMvFieldA = ( pcCUA == NULL || pcCUA->isIntra( uiAbsPartIdxA ) ) ? NULL : pcCUA->getCUMvField( eRefList ); |
---|
1700 | iHorPred = ( (pcCUMvFieldL == NULL) ? 0 : pcCUMvFieldL->getMvd( uiAbsPartIdxL ).getAbsHor() ) + |
---|
1701 | ( (pcCUMvFieldA == NULL) ? 0 : pcCUMvFieldA->getMvd( uiAbsPartIdxA ).getAbsHor() ); |
---|
1702 | iVerPred = ( (pcCUMvFieldL == NULL) ? 0 : pcCUMvFieldL->getMvd( uiAbsPartIdxL ).getAbsVer() ) + |
---|
1703 | ( (pcCUMvFieldA == NULL) ? 0 : pcCUMvFieldA->getMvd( uiAbsPartIdxA ).getAbsVer() ); |
---|
1704 | |
---|
1705 | #if LCEC_STAT |
---|
1706 | if (m_bAdaptFlag) |
---|
1707 | m_uiBitMVD += xWriteSvlc( iHor); |
---|
1708 | else |
---|
1709 | xWriteSvlc( iHor); |
---|
1710 | if (m_bAdaptFlag) |
---|
1711 | m_uiBitMVD += xWriteSvlc( iVer); |
---|
1712 | else |
---|
1713 | xWriteSvlc( iVer); |
---|
1714 | #else |
---|
1715 | xWriteSvlc( iHor ); |
---|
1716 | xWriteSvlc( iVer ); |
---|
1717 | #endif |
---|
1718 | |
---|
1719 | return; |
---|
1720 | } |
---|
1721 | |
---|
1722 | Void TEncCavlc::codeDeltaQP( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
1723 | { |
---|
1724 | Int iDQp = pcCU->getQP( uiAbsPartIdx ) - pcCU->getSlice()->getSliceQp(); |
---|
1725 | |
---|
1726 | #if LCEC_STAT |
---|
1727 | if (m_bAdaptFlag) |
---|
1728 | m_uiBitDeltaQP += 1; |
---|
1729 | #endif |
---|
1730 | |
---|
1731 | if ( iDQp == 0 ) |
---|
1732 | { |
---|
1733 | xWriteFlag( 0 ); |
---|
1734 | } |
---|
1735 | else |
---|
1736 | { |
---|
1737 | xWriteFlag( 1 ); |
---|
1738 | #if LCEC_STAT |
---|
1739 | if (m_bAdaptFlag) |
---|
1740 | m_uiBitDeltaQP += xWriteSvlc( iDQp ); |
---|
1741 | else |
---|
1742 | #endif |
---|
1743 | xWriteSvlc( iDQp ); |
---|
1744 | } |
---|
1745 | |
---|
1746 | return; |
---|
1747 | } |
---|
1748 | |
---|
1749 | #if LCEC_CBP_YUV_ROOT |
---|
1750 | Void TEncCavlc::codeCbf( TComDataCU* pcCU, UInt uiAbsPartIdx, TextType eType, UInt uiTrDepth ) |
---|
1751 | { |
---|
1752 | if (eType == TEXT_ALL) |
---|
1753 | { |
---|
1754 | Int n,x,cx,y,cy; |
---|
1755 | UInt uiCBFY = pcCU->getCbf(uiAbsPartIdx, TEXT_LUMA, 0); |
---|
1756 | UInt uiCBFU = pcCU->getCbf(uiAbsPartIdx, TEXT_CHROMA_U, 0); |
---|
1757 | UInt uiCBFV = pcCU->getCbf(uiAbsPartIdx, TEXT_CHROMA_V, 0); |
---|
1758 | UInt uiCBP = (uiCBFV<<2) + (uiCBFU<<1) + (uiCBFY<<0); |
---|
1759 | |
---|
1760 | /* Start adaptation */ |
---|
1761 | n = pcCU->isIntra( uiAbsPartIdx ) ? 0 : 1; |
---|
1762 | x = uiCBP; |
---|
1763 | cx = m_uiCBPTableE[n][x]; |
---|
1764 | |
---|
1765 | UInt vlcn = g_auiCbpVlcNum[n][m_uiCbpVlcIdx[n]]; |
---|
1766 | |
---|
1767 | if ( m_bAdaptFlag ) |
---|
1768 | { |
---|
1769 | |
---|
1770 | cy = Max(0,cx-1); |
---|
1771 | y = m_uiCBPTableD[n][cy]; |
---|
1772 | m_uiCBPTableD[n][cy] = x; |
---|
1773 | m_uiCBPTableD[n][cx] = y; |
---|
1774 | m_uiCBPTableE[n][x] = cy; |
---|
1775 | m_uiCBPTableE[n][y] = cx; |
---|
1776 | m_uiCbpVlcIdx[n] += cx == m_uiCbpVlcIdx[n] ? 0 : (cx < m_uiCbpVlcIdx[n] ? -1 : 1); |
---|
1777 | } |
---|
1778 | #if LCEC_STAT |
---|
1779 | if (m_bAdaptFlag) |
---|
1780 | m_uiBitCbp += xWriteVlc( vlcn, cx ); |
---|
1781 | else |
---|
1782 | #endif |
---|
1783 | xWriteVlc( vlcn, cx ); |
---|
1784 | } |
---|
1785 | } |
---|
1786 | |
---|
1787 | Void TEncCavlc::codeBlockCbf( TComDataCU* pcCU, UInt uiAbsPartIdx, TextType eType, UInt uiTrDepth, UInt uiQPartNum, Bool bRD ) |
---|
1788 | { |
---|
1789 | UInt uiCbf0 = pcCU->getCbf ( uiAbsPartIdx, eType, uiTrDepth ); |
---|
1790 | UInt uiCbf1 = pcCU->getCbf ( uiAbsPartIdx + uiQPartNum, eType, uiTrDepth ); |
---|
1791 | UInt uiCbf2 = pcCU->getCbf ( uiAbsPartIdx + uiQPartNum*2, eType, uiTrDepth ); |
---|
1792 | UInt uiCbf3 = pcCU->getCbf ( uiAbsPartIdx + uiQPartNum*3, eType, uiTrDepth ); |
---|
1793 | UInt uiCbf = (uiCbf0<<3) | (uiCbf1<<2) | (uiCbf2<<1) | uiCbf3; |
---|
1794 | |
---|
1795 | assert(uiTrDepth > 0); |
---|
1796 | |
---|
1797 | #if QC_BLK_CBP |
---|
1798 | if(bRD && uiCbf==0) |
---|
1799 | { |
---|
1800 | xWriteCode(0, 4); |
---|
1801 | return; |
---|
1802 | } |
---|
1803 | |
---|
1804 | assert(uiCbf > 0); |
---|
1805 | |
---|
1806 | uiCbf --; |
---|
1807 | |
---|
1808 | Int x,cx,y,cy; |
---|
1809 | |
---|
1810 | UInt n = (pcCU->isIntra(uiAbsPartIdx) && eType == TEXT_LUMA)? 0:1; |
---|
1811 | cx = m_uiBlkCBPTableE[n][uiCbf]; |
---|
1812 | x = uiCbf; |
---|
1813 | UInt vlcn = (n==0)?g_auiBlkCbpVlcNum[m_uiBlkCbpVlcIdx]:11; |
---|
1814 | |
---|
1815 | if ( m_bAdaptFlag ) |
---|
1816 | { |
---|
1817 | cy = Max(0,cx-1); |
---|
1818 | y = m_uiBlkCBPTableD[n][cy]; |
---|
1819 | m_uiBlkCBPTableD[n][cy] = x; |
---|
1820 | m_uiBlkCBPTableD[n][cx] = y; |
---|
1821 | m_uiBlkCBPTableE[n][x] = cy; |
---|
1822 | m_uiBlkCBPTableE[n][y] = cx; |
---|
1823 | if(n==0) |
---|
1824 | m_uiBlkCbpVlcIdx += cx == m_uiBlkCbpVlcIdx ? 0 : (cx < m_uiBlkCbpVlcIdx ? -1 : 1); |
---|
1825 | |
---|
1826 | } |
---|
1827 | |
---|
1828 | xWriteVlc( vlcn, cx ); |
---|
1829 | return; |
---|
1830 | #else |
---|
1831 | xWriteCode(uiCbf, 4); |
---|
1832 | #endif |
---|
1833 | } |
---|
1834 | #endif |
---|
1835 | |
---|
1836 | Void TEncCavlc::codeCoeffNxN ( TComDataCU* pcCU, TCoeff* pcCoef, UInt uiAbsPartIdx, UInt uiWidth, UInt uiHeight, UInt uiDepth, TextType eTType, Bool bRD ) |
---|
1837 | { |
---|
1838 | if ( uiWidth > m_pcSlice->getSPS()->getMaxTrSize() ) |
---|
1839 | { |
---|
1840 | uiWidth = m_pcSlice->getSPS()->getMaxTrSize(); |
---|
1841 | uiHeight = m_pcSlice->getSPS()->getMaxTrSize(); |
---|
1842 | } |
---|
1843 | UInt uiSize = uiWidth*uiHeight; |
---|
1844 | |
---|
1845 | // point to coefficient |
---|
1846 | TCoeff* piCoeff = pcCoef; |
---|
1847 | UInt uiNumSig = 0; |
---|
1848 | UInt uiScanning; |
---|
1849 | |
---|
1850 | // compute number of significant coefficients |
---|
1851 | UInt uiPart = 0; |
---|
1852 | xCheckCoeff(piCoeff, uiWidth, 0, uiNumSig, uiPart ); |
---|
1853 | |
---|
1854 | if ( bRD ) |
---|
1855 | { |
---|
1856 | UInt uiTempDepth = uiDepth - pcCU->getDepth( uiAbsPartIdx ); |
---|
1857 | pcCU->setCbfSubParts( ( uiNumSig ? 1 : 0 ) << uiTempDepth, eTType, uiAbsPartIdx, uiDepth ); |
---|
1858 | codeCbf( pcCU, uiAbsPartIdx, eTType, uiTempDepth ); |
---|
1859 | } |
---|
1860 | |
---|
1861 | if ( uiNumSig == 0 ) |
---|
1862 | { |
---|
1863 | return; |
---|
1864 | } |
---|
1865 | |
---|
1866 | // initialize scan |
---|
1867 | const UInt* pucScan; |
---|
1868 | //UInt uiConvBit = g_aucConvertToBit[ Min(8,uiWidth) ]; |
---|
1869 | UInt uiConvBit = g_aucConvertToBit[ pcCU->isIntra( uiAbsPartIdx ) ? uiWidth : Min(8,uiWidth) ]; |
---|
1870 | pucScan = g_auiFrameScanXY [ uiConvBit + 1 ]; |
---|
1871 | |
---|
1872 | #if QC_MDCS |
---|
1873 | UInt uiBlkPos; |
---|
1874 | UInt uiLog2BlkSize = g_aucConvertToBit[ pcCU->isIntra( uiAbsPartIdx ) ? uiWidth : Min(8,uiWidth) ] + 2; |
---|
1875 | const UInt uiScanIdx = pcCU->getCoefScanIdx(uiAbsPartIdx, uiWidth, eTType==TEXT_LUMA, pcCU->isIntra(uiAbsPartIdx)); |
---|
1876 | #endif //QC_MDCS |
---|
1877 | |
---|
1878 | TCoeff scoeff[64]; |
---|
1879 | Int iBlockType; |
---|
1880 | UInt uiCodeDCCoef = 0; |
---|
1881 | TCoeff dcCoeff = 0; |
---|
1882 | if (pcCU->isIntra(uiAbsPartIdx)) |
---|
1883 | { |
---|
1884 | UInt uiAbsPartIdxL, uiAbsPartIdxA; |
---|
1885 | TComDataCU* pcCUL = pcCU->getPULeft (uiAbsPartIdxL, pcCU->getZorderIdxInCU() + uiAbsPartIdx); |
---|
1886 | TComDataCU* pcCUA = pcCU->getPUAbove(uiAbsPartIdxA, pcCU->getZorderIdxInCU() + uiAbsPartIdx); |
---|
1887 | if (pcCUL == NULL && pcCUA == NULL) |
---|
1888 | { |
---|
1889 | uiCodeDCCoef = 1; |
---|
1890 | xWriteVlc((eTType == TEXT_LUMA ? 3 : 1) , abs(piCoeff[0])); |
---|
1891 | if (piCoeff[0] != 0) |
---|
1892 | { |
---|
1893 | UInt sign = (piCoeff[0] < 0) ? 1 : 0; |
---|
1894 | xWriteFlag(sign); |
---|
1895 | } |
---|
1896 | dcCoeff = piCoeff[0]; |
---|
1897 | piCoeff[0] = 1; |
---|
1898 | } |
---|
1899 | } |
---|
1900 | |
---|
1901 | if( uiSize == 2*2 ) |
---|
1902 | { |
---|
1903 | // hack: re-use 4x4 coding |
---|
1904 | ::memset( scoeff, 0, 16*sizeof(TCoeff) ); |
---|
1905 | for (uiScanning=0; uiScanning<4; uiScanning++) |
---|
1906 | { |
---|
1907 | #if QC_MDCS |
---|
1908 | uiBlkPos = g_auiSigLastScan[uiScanIdx][uiLog2BlkSize-1][uiScanning]; |
---|
1909 | scoeff[15-uiScanning] = piCoeff[ uiBlkPos ]; |
---|
1910 | #else |
---|
1911 | scoeff[15-uiScanning] = piCoeff[ pucScan[ uiScanning ] ]; |
---|
1912 | #endif //QC_MDCS |
---|
1913 | } |
---|
1914 | #if QC_MOD_LCEC |
---|
1915 | if (eTType==TEXT_CHROMA_U || eTType==TEXT_CHROMA_V) |
---|
1916 | iBlockType = eTType-2; |
---|
1917 | else |
---|
1918 | iBlockType = 2 + ( pcCU->isIntra(uiAbsPartIdx) ? 0 : pcCU->getSlice()->getSliceType() ); |
---|
1919 | #else |
---|
1920 | iBlockType = pcCU->isIntra(uiAbsPartIdx) ? 0 : pcCU->getSlice()->getSliceType(); |
---|
1921 | #endif |
---|
1922 | |
---|
1923 | xCodeCoeff4x4( scoeff, iBlockType ); |
---|
1924 | } |
---|
1925 | else if ( uiSize == 4*4 ) |
---|
1926 | { |
---|
1927 | for (uiScanning=0; uiScanning<16; uiScanning++) |
---|
1928 | { |
---|
1929 | #if QC_MDCS |
---|
1930 | uiBlkPos = g_auiSigLastScan[uiScanIdx][uiLog2BlkSize-1][uiScanning]; |
---|
1931 | scoeff[15-uiScanning] = piCoeff[ uiBlkPos ]; |
---|
1932 | #else |
---|
1933 | scoeff[15-uiScanning] = piCoeff[ pucScan[ uiScanning ] ]; |
---|
1934 | #endif //QC_MDCS |
---|
1935 | } |
---|
1936 | #if QC_MOD_LCEC |
---|
1937 | if (eTType==TEXT_CHROMA_U || eTType==TEXT_CHROMA_V) |
---|
1938 | iBlockType = eTType-2; |
---|
1939 | else |
---|
1940 | iBlockType = 2 + ( pcCU->isIntra(uiAbsPartIdx) ? 0 : pcCU->getSlice()->getSliceType() ); |
---|
1941 | #else |
---|
1942 | iBlockType = pcCU->isIntra(uiAbsPartIdx) ? 0 : pcCU->getSlice()->getSliceType(); |
---|
1943 | #endif |
---|
1944 | |
---|
1945 | xCodeCoeff4x4( scoeff, iBlockType ); |
---|
1946 | } |
---|
1947 | else if ( uiSize == 8*8 ) |
---|
1948 | { |
---|
1949 | for (uiScanning=0; uiScanning<64; uiScanning++) |
---|
1950 | { |
---|
1951 | #if QC_MDCS |
---|
1952 | uiBlkPos = g_auiSigLastScan[uiScanIdx][uiLog2BlkSize-1][uiScanning]; |
---|
1953 | scoeff[63-uiScanning] = piCoeff[ uiBlkPos ]; |
---|
1954 | #else |
---|
1955 | scoeff[63-uiScanning] = piCoeff[ pucScan[ uiScanning ] ]; |
---|
1956 | #endif //QC_MDCS |
---|
1957 | } |
---|
1958 | if (eTType==TEXT_CHROMA_U || eTType==TEXT_CHROMA_V) |
---|
1959 | iBlockType = eTType-2; |
---|
1960 | else |
---|
1961 | iBlockType = 2 + ( pcCU->isIntra(uiAbsPartIdx) ? 0 : pcCU->getSlice()->getSliceType() ); |
---|
1962 | |
---|
1963 | xCodeCoeff8x8( scoeff, iBlockType ); |
---|
1964 | } |
---|
1965 | else |
---|
1966 | { |
---|
1967 | if(!pcCU->isIntra( uiAbsPartIdx )) |
---|
1968 | { |
---|
1969 | for (uiScanning=0; uiScanning<64; uiScanning++) |
---|
1970 | { |
---|
1971 | #if QC_MDCS |
---|
1972 | uiBlkPos = g_auiSigLastScan[uiScanIdx][uiLog2BlkSize-1][uiScanning]; |
---|
1973 | uiBlkPos = (uiBlkPos/8) * uiWidth + uiBlkPos%8; |
---|
1974 | scoeff[63-uiScanning] = piCoeff[ uiBlkPos ]; |
---|
1975 | #else |
---|
1976 | scoeff[63-uiScanning] = piCoeff[(pucScan[uiScanning]/8)*uiWidth + (pucScan[uiScanning]%8)]; |
---|
1977 | #endif //QC_MDCS |
---|
1978 | } |
---|
1979 | if (eTType==TEXT_CHROMA_U || eTType==TEXT_CHROMA_V) |
---|
1980 | iBlockType = eTType-2; |
---|
1981 | else |
---|
1982 | iBlockType = 5 + ( pcCU->isIntra(uiAbsPartIdx) ? 0 : pcCU->getSlice()->getSliceType() ); |
---|
1983 | xCodeCoeff8x8( scoeff, iBlockType ); |
---|
1984 | return; |
---|
1985 | } |
---|
1986 | |
---|
1987 | if(pcCU->isIntra( uiAbsPartIdx )) |
---|
1988 | { |
---|
1989 | for (uiScanning=0; uiScanning<64; uiScanning++) |
---|
1990 | { |
---|
1991 | #if QC_MDCS |
---|
1992 | uiBlkPos = g_auiSigLastScan[uiScanIdx][uiLog2BlkSize-1][uiScanning]; |
---|
1993 | scoeff[63-uiScanning] = piCoeff[ uiBlkPos ]; |
---|
1994 | #else |
---|
1995 | scoeff[63-uiScanning] = piCoeff[ pucScan[ uiScanning ] ]; |
---|
1996 | #endif //QC_MDCS |
---|
1997 | } |
---|
1998 | |
---|
1999 | if (eTType==TEXT_CHROMA_U || eTType==TEXT_CHROMA_V) |
---|
2000 | iBlockType = eTType-2; |
---|
2001 | else |
---|
2002 | iBlockType = 5 + ( pcCU->isIntra(uiAbsPartIdx) ? 0 : pcCU->getSlice()->getSliceType() ); |
---|
2003 | xCodeCoeff8x8( scoeff, iBlockType ); |
---|
2004 | } |
---|
2005 | //#endif |
---|
2006 | } |
---|
2007 | |
---|
2008 | if (uiCodeDCCoef == 1) |
---|
2009 | { |
---|
2010 | piCoeff[0] = dcCoeff; |
---|
2011 | } |
---|
2012 | } |
---|
2013 | |
---|
2014 | Void TEncCavlc::codeAlfFlag( UInt uiCode ) |
---|
2015 | { |
---|
2016 | |
---|
2017 | xWriteFlag( uiCode ); |
---|
2018 | #if LCEC_STAT |
---|
2019 | if (m_bAdaptFlag) |
---|
2020 | m_uiBitAlfFlag += 1; |
---|
2021 | #endif |
---|
2022 | } |
---|
2023 | |
---|
2024 | #if TSB_ALF_HEADER |
---|
2025 | Void TEncCavlc::codeAlfFlagNum( UInt uiCode, UInt minValue ) |
---|
2026 | { |
---|
2027 | UInt uiLength = 0; |
---|
2028 | UInt maxValue = (minValue << (this->getMaxAlfCtrlDepth()*2)); |
---|
2029 | assert((uiCode>=minValue)&&(uiCode<=maxValue)); |
---|
2030 | UInt temp = maxValue - minValue; |
---|
2031 | for(UInt i=0; i<32; i++) |
---|
2032 | { |
---|
2033 | if(temp&0x1) |
---|
2034 | { |
---|
2035 | uiLength = i+1; |
---|
2036 | } |
---|
2037 | temp = (temp >> 1); |
---|
2038 | } |
---|
2039 | if(uiLength) |
---|
2040 | { |
---|
2041 | xWriteCode( uiCode - minValue, uiLength ); |
---|
2042 | } |
---|
2043 | } |
---|
2044 | |
---|
2045 | Void TEncCavlc::codeAlfCtrlFlag( UInt uiSymbol ) |
---|
2046 | { |
---|
2047 | xWriteFlag( uiSymbol ); |
---|
2048 | } |
---|
2049 | #endif |
---|
2050 | |
---|
2051 | Void TEncCavlc::codeAlfUvlc( UInt uiCode ) |
---|
2052 | { |
---|
2053 | #if LCEC_STAT |
---|
2054 | if (m_bAdaptFlag) |
---|
2055 | m_uiBitAlfUvlc += xWriteUvlc( uiCode ); |
---|
2056 | else |
---|
2057 | #endif |
---|
2058 | xWriteUvlc( uiCode ); |
---|
2059 | } |
---|
2060 | |
---|
2061 | Void TEncCavlc::codeAlfSvlc( Int iCode ) |
---|
2062 | { |
---|
2063 | #if LCEC_STAT |
---|
2064 | if (m_bAdaptFlag) |
---|
2065 | m_uiBitAlfSvlc += xWriteSvlc( iCode ); |
---|
2066 | else |
---|
2067 | #endif |
---|
2068 | xWriteSvlc( iCode ); |
---|
2069 | } |
---|
2070 | |
---|
2071 | Void TEncCavlc::estBit( estBitsSbacStruct* pcEstBitsCabac, UInt uiCTXIdx, TextType eTType ) |
---|
2072 | { |
---|
2073 | // printf("error : no VLC mode support in this version\n"); |
---|
2074 | return; |
---|
2075 | } |
---|
2076 | |
---|
2077 | // ==================================================================================================================== |
---|
2078 | // Protected member functions |
---|
2079 | // ==================================================================================================================== |
---|
2080 | |
---|
2081 | #if LCEC_STAT |
---|
2082 | UInt TEncCavlc::xWriteCode ( UInt uiCode, UInt uiLength ) |
---|
2083 | #else |
---|
2084 | Void TEncCavlc::xWriteCode ( UInt uiCode, UInt uiLength ) |
---|
2085 | #endif |
---|
2086 | { |
---|
2087 | assert ( uiLength > 0 ); |
---|
2088 | m_pcBitIf->write( uiCode, uiLength ); |
---|
2089 | #if LCEC_STAT |
---|
2090 | return uiLength; |
---|
2091 | #endif |
---|
2092 | } |
---|
2093 | |
---|
2094 | #if LCEC_STAT |
---|
2095 | UInt TEncCavlc::xWriteUvlc ( UInt uiCode ) |
---|
2096 | #else |
---|
2097 | Void TEncCavlc::xWriteUvlc ( UInt uiCode ) |
---|
2098 | #endif |
---|
2099 | { |
---|
2100 | UInt uiLength = 1; |
---|
2101 | UInt uiTemp = ++uiCode; |
---|
2102 | |
---|
2103 | assert ( uiTemp ); |
---|
2104 | |
---|
2105 | while( 1 != uiTemp ) |
---|
2106 | { |
---|
2107 | uiTemp >>= 1; |
---|
2108 | uiLength += 2; |
---|
2109 | } |
---|
2110 | |
---|
2111 | m_pcBitIf->write( uiCode, uiLength ); |
---|
2112 | #if LCEC_STAT |
---|
2113 | return uiLength; |
---|
2114 | #endif |
---|
2115 | } |
---|
2116 | |
---|
2117 | #if LCEC_STAT |
---|
2118 | UInt TEncCavlc::xWriteSvlc ( Int iCode ) |
---|
2119 | { |
---|
2120 | UInt uiCode; |
---|
2121 | UInt uiNumBits; |
---|
2122 | |
---|
2123 | uiCode = xConvertToUInt( iCode ); |
---|
2124 | uiNumBits = xWriteUvlc( uiCode ); |
---|
2125 | return uiNumBits; |
---|
2126 | } |
---|
2127 | #else |
---|
2128 | Void TEncCavlc::xWriteSvlc ( Int iCode ) |
---|
2129 | { |
---|
2130 | UInt uiCode; |
---|
2131 | |
---|
2132 | uiCode = xConvertToUInt( iCode ); |
---|
2133 | xWriteUvlc( uiCode ); |
---|
2134 | } |
---|
2135 | #endif |
---|
2136 | |
---|
2137 | Void TEncCavlc::xWriteFlag( UInt uiCode ) |
---|
2138 | { |
---|
2139 | m_pcBitIf->write( uiCode, 1 ); |
---|
2140 | } |
---|
2141 | |
---|
2142 | Void TEncCavlc::xCheckCoeff( TCoeff* pcCoef, UInt uiSize, UInt uiDepth, UInt& uiNumofCoeff, UInt& uiPart ) |
---|
2143 | { |
---|
2144 | UInt ui = uiSize>>uiDepth; |
---|
2145 | if( uiPart == 0 ) |
---|
2146 | { |
---|
2147 | if( ui <= 4 ) |
---|
2148 | { |
---|
2149 | UInt x, y; |
---|
2150 | TCoeff* pCeoff = pcCoef; |
---|
2151 | for( y=0 ; y<ui ; y++ ) |
---|
2152 | { |
---|
2153 | for( x=0 ; x<ui ; x++ ) |
---|
2154 | { |
---|
2155 | if( pCeoff[x] != 0 ) |
---|
2156 | { |
---|
2157 | uiNumofCoeff++; |
---|
2158 | } |
---|
2159 | } |
---|
2160 | pCeoff += uiSize; |
---|
2161 | } |
---|
2162 | } |
---|
2163 | else |
---|
2164 | { |
---|
2165 | xCheckCoeff( pcCoef, uiSize, uiDepth+1, uiNumofCoeff, uiPart ); uiPart++; //1st Part |
---|
2166 | xCheckCoeff( pcCoef + (ui>>1), uiSize, uiDepth+1, uiNumofCoeff, uiPart ); uiPart++; //2nd Part |
---|
2167 | xCheckCoeff( pcCoef + (ui>>1)*uiSize, uiSize, uiDepth+1, uiNumofCoeff, uiPart ); uiPart++; //3rd Part |
---|
2168 | xCheckCoeff( pcCoef + (ui>>1)*uiSize + (ui>>1), uiSize, uiDepth+1, uiNumofCoeff, uiPart ); //4th Part |
---|
2169 | } |
---|
2170 | } |
---|
2171 | else |
---|
2172 | { |
---|
2173 | UInt x, y; |
---|
2174 | TCoeff* pCeoff = pcCoef; |
---|
2175 | for( y=0 ; y<ui ; y++ ) |
---|
2176 | { |
---|
2177 | for( x=0 ; x<ui ; x++ ) |
---|
2178 | { |
---|
2179 | if( pCeoff[x] != 0 ) |
---|
2180 | { |
---|
2181 | uiNumofCoeff++; |
---|
2182 | } |
---|
2183 | } |
---|
2184 | pCeoff += uiSize; |
---|
2185 | } |
---|
2186 | } |
---|
2187 | } |
---|
2188 | |
---|
2189 | #if LCEC_STAT |
---|
2190 | UInt TEncCavlc::xWriteUnaryMaxSymbol( UInt uiSymbol, UInt uiMaxSymbol ) |
---|
2191 | #else |
---|
2192 | Void TEncCavlc::xWriteUnaryMaxSymbol( UInt uiSymbol, UInt uiMaxSymbol ) |
---|
2193 | #endif |
---|
2194 | { |
---|
2195 | if (uiMaxSymbol == 0) |
---|
2196 | { |
---|
2197 | #if LCEC_STAT |
---|
2198 | return 0; |
---|
2199 | #else |
---|
2200 | return; |
---|
2201 | #endif |
---|
2202 | } |
---|
2203 | #if LCEC_STAT |
---|
2204 | UInt uiNumBits = 0; |
---|
2205 | #endif |
---|
2206 | xWriteFlag( uiSymbol ? 1 : 0 ); |
---|
2207 | #if LCEC_STAT |
---|
2208 | uiNumBits +=1; |
---|
2209 | #endif |
---|
2210 | if ( uiSymbol == 0 ) |
---|
2211 | { |
---|
2212 | #if LCEC_STAT |
---|
2213 | return uiNumBits; |
---|
2214 | #else |
---|
2215 | return; |
---|
2216 | #endif |
---|
2217 | } |
---|
2218 | |
---|
2219 | Bool bCodeLast = ( uiMaxSymbol > uiSymbol ); |
---|
2220 | |
---|
2221 | while( --uiSymbol ) |
---|
2222 | { |
---|
2223 | xWriteFlag( 1 ); |
---|
2224 | #if LCEC_STAT |
---|
2225 | uiNumBits +=1; |
---|
2226 | #endif |
---|
2227 | } |
---|
2228 | if( bCodeLast ) |
---|
2229 | { |
---|
2230 | xWriteFlag( 0 ); |
---|
2231 | #if LCEC_STAT |
---|
2232 | uiNumBits +=1; |
---|
2233 | #endif |
---|
2234 | } |
---|
2235 | #if LCEC_STAT |
---|
2236 | return uiNumBits; |
---|
2237 | #else |
---|
2238 | return; |
---|
2239 | #endif |
---|
2240 | } |
---|
2241 | |
---|
2242 | #if LCEC_STAT |
---|
2243 | UInt TEncCavlc::xWriteExGolombLevel( UInt uiSymbol ) |
---|
2244 | #else |
---|
2245 | Void TEncCavlc::xWriteExGolombLevel( UInt uiSymbol ) |
---|
2246 | #endif |
---|
2247 | { |
---|
2248 | #if LCEC_STAT |
---|
2249 | UInt uiNumBits = 0; |
---|
2250 | #endif |
---|
2251 | if( uiSymbol ) |
---|
2252 | { |
---|
2253 | xWriteFlag( 1 ); |
---|
2254 | #if LCEC_STAT |
---|
2255 | uiNumBits += 1; |
---|
2256 | #endif |
---|
2257 | UInt uiCount = 0; |
---|
2258 | Bool bNoExGo = (uiSymbol < 13); |
---|
2259 | |
---|
2260 | while( --uiSymbol && ++uiCount < 13 ) |
---|
2261 | { |
---|
2262 | xWriteFlag( 1 ); |
---|
2263 | #if LCEC_STAT |
---|
2264 | uiNumBits += 1; |
---|
2265 | #endif |
---|
2266 | } |
---|
2267 | if( bNoExGo ) |
---|
2268 | { |
---|
2269 | xWriteFlag( 0 ); |
---|
2270 | #if LCEC_STAT |
---|
2271 | uiNumBits += 1; |
---|
2272 | #endif |
---|
2273 | } |
---|
2274 | else |
---|
2275 | { |
---|
2276 | #if LCEC_STAT |
---|
2277 | uiNumBits += xWriteEpExGolomb( uiSymbol, 0 ); |
---|
2278 | #else |
---|
2279 | xWriteEpExGolomb( uiSymbol, 0 ); |
---|
2280 | #endif |
---|
2281 | } |
---|
2282 | } |
---|
2283 | else |
---|
2284 | { |
---|
2285 | xWriteFlag( 0 ); |
---|
2286 | #if LCEC_STAT |
---|
2287 | uiNumBits += 1; |
---|
2288 | #endif |
---|
2289 | } |
---|
2290 | |
---|
2291 | #if LCEC_STAT |
---|
2292 | return uiNumBits; |
---|
2293 | #else |
---|
2294 | return; |
---|
2295 | #endif |
---|
2296 | } |
---|
2297 | |
---|
2298 | #if LCEC_STAT |
---|
2299 | UInt TEncCavlc::xWriteEpExGolomb( UInt uiSymbol, UInt uiCount ) |
---|
2300 | #else |
---|
2301 | Void TEncCavlc::xWriteEpExGolomb( UInt uiSymbol, UInt uiCount ) |
---|
2302 | #endif |
---|
2303 | { |
---|
2304 | #if LCEC_STAT |
---|
2305 | UInt uiNumBits = 0; |
---|
2306 | #endif |
---|
2307 | while( uiSymbol >= (UInt)(1<<uiCount) ) |
---|
2308 | { |
---|
2309 | xWriteFlag( 1 ); |
---|
2310 | #if LCEC_STAT |
---|
2311 | uiNumBits += 1; |
---|
2312 | #endif |
---|
2313 | uiSymbol -= 1<<uiCount; |
---|
2314 | uiCount ++; |
---|
2315 | } |
---|
2316 | xWriteFlag( 0 ); |
---|
2317 | #if LCEC_STAT |
---|
2318 | uiNumBits += 1; |
---|
2319 | #endif |
---|
2320 | while( uiCount-- ) |
---|
2321 | { |
---|
2322 | xWriteFlag( (uiSymbol>>uiCount) & 1 ); |
---|
2323 | #if LCEC_STAT |
---|
2324 | uiNumBits += 1; |
---|
2325 | #endif |
---|
2326 | } |
---|
2327 | #if LCEC_STAT |
---|
2328 | return uiNumBits; |
---|
2329 | #else |
---|
2330 | return; |
---|
2331 | #endif |
---|
2332 | } |
---|
2333 | |
---|
2334 | #if !QC_MOD_LCEC_RDOQ |
---|
2335 | UInt TEncCavlc::xLeadingZeros(UInt uiCode) |
---|
2336 | { |
---|
2337 | UInt uiCount = 0; |
---|
2338 | Int iDone = 0; |
---|
2339 | |
---|
2340 | if (uiCode) |
---|
2341 | { |
---|
2342 | while (!iDone) |
---|
2343 | { |
---|
2344 | uiCode >>= 1; |
---|
2345 | if (!uiCode) iDone = 1; |
---|
2346 | else uiCount++; |
---|
2347 | } |
---|
2348 | } |
---|
2349 | return uiCount; |
---|
2350 | } |
---|
2351 | #endif |
---|
2352 | |
---|
2353 | #if LCEC_STAT |
---|
2354 | UInt TEncCavlc::xWriteVlc(UInt uiTableNumber, UInt uiCodeNumber) |
---|
2355 | #else |
---|
2356 | Void TEncCavlc::xWriteVlc(UInt uiTableNumber, UInt uiCodeNumber) |
---|
2357 | #endif |
---|
2358 | { |
---|
2359 | #if QC_BLK_CBP |
---|
2360 | assert( uiTableNumber<=11 ); |
---|
2361 | #else |
---|
2362 | assert( uiTableNumber<=10 ); |
---|
2363 | #endif |
---|
2364 | |
---|
2365 | UInt uiTemp; |
---|
2366 | UInt uiLength = 0; |
---|
2367 | UInt uiCode = 0; |
---|
2368 | |
---|
2369 | if ( uiTableNumber < 5 ) |
---|
2370 | { |
---|
2371 | if ((Int)uiCodeNumber < (6 * (1 << uiTableNumber))) |
---|
2372 | { |
---|
2373 | uiTemp = 1<<uiTableNumber; |
---|
2374 | uiCode = uiTemp+uiCodeNumber%uiTemp; |
---|
2375 | uiLength = 1+uiTableNumber+(uiCodeNumber>>uiTableNumber); |
---|
2376 | } |
---|
2377 | else |
---|
2378 | { |
---|
2379 | uiCode = uiCodeNumber - (6 * (1 << uiTableNumber)) + (1 << uiTableNumber); |
---|
2380 | uiLength = (6-uiTableNumber)+1+2*xLeadingZeros(uiCode); |
---|
2381 | } |
---|
2382 | } |
---|
2383 | else if (uiTableNumber < 8) |
---|
2384 | { |
---|
2385 | uiTemp = 1<<(uiTableNumber-4); |
---|
2386 | uiCode = uiTemp+uiCodeNumber%uiTemp; |
---|
2387 | uiLength = 1+(uiTableNumber-4)+(uiCodeNumber>>(uiTableNumber-4)); |
---|
2388 | } |
---|
2389 | else if (uiTableNumber == 8) |
---|
2390 | { |
---|
2391 | assert( uiCodeNumber<=2 ); |
---|
2392 | if (uiCodeNumber == 0) |
---|
2393 | { |
---|
2394 | uiCode = 1; |
---|
2395 | uiLength = 1; |
---|
2396 | } |
---|
2397 | else if (uiCodeNumber == 1) |
---|
2398 | { |
---|
2399 | uiCode = 1; |
---|
2400 | uiLength = 2; |
---|
2401 | } |
---|
2402 | else if (uiCodeNumber == 2) |
---|
2403 | { |
---|
2404 | uiCode = 0; |
---|
2405 | uiLength = 2; |
---|
2406 | } |
---|
2407 | } |
---|
2408 | else if (uiTableNumber == 9) |
---|
2409 | { |
---|
2410 | if (uiCodeNumber == 0) |
---|
2411 | { |
---|
2412 | uiCode = 4; |
---|
2413 | uiLength = 3; |
---|
2414 | } |
---|
2415 | else if (uiCodeNumber == 1) |
---|
2416 | { |
---|
2417 | uiCode = 10; |
---|
2418 | uiLength = 4; |
---|
2419 | } |
---|
2420 | else if (uiCodeNumber == 2) |
---|
2421 | { |
---|
2422 | uiCode = 11; |
---|
2423 | uiLength = 4; |
---|
2424 | } |
---|
2425 | else if (uiCodeNumber < 11) |
---|
2426 | { |
---|
2427 | uiCode = uiCodeNumber+21; |
---|
2428 | uiLength = 5; |
---|
2429 | } |
---|
2430 | else |
---|
2431 | { |
---|
2432 | uiTemp = 1<<4; |
---|
2433 | uiCode = uiTemp+(uiCodeNumber+5)%uiTemp; |
---|
2434 | uiLength = 5+((uiCodeNumber+5)>>4); |
---|
2435 | } |
---|
2436 | } |
---|
2437 | else if (uiTableNumber == 10) |
---|
2438 | { |
---|
2439 | uiCode = uiCodeNumber+1; |
---|
2440 | uiLength = 1+2*xLeadingZeros(uiCode); |
---|
2441 | } |
---|
2442 | #if QC_BLK_CBP |
---|
2443 | else if (uiTableNumber == 11) |
---|
2444 | { |
---|
2445 | if (uiCodeNumber == 0) |
---|
2446 | { |
---|
2447 | uiCode = 0; |
---|
2448 | uiLength = 3; |
---|
2449 | } |
---|
2450 | else |
---|
2451 | { |
---|
2452 | uiCode = uiCodeNumber + 1; |
---|
2453 | uiLength = 4; |
---|
2454 | } |
---|
2455 | } |
---|
2456 | #endif |
---|
2457 | xWriteCode(uiCode, uiLength); |
---|
2458 | #if LCEC_STAT |
---|
2459 | return uiLength; |
---|
2460 | #endif |
---|
2461 | } |
---|
2462 | |
---|
2463 | Void TEncCavlc::xCodeCoeff4x4(TCoeff* scoeff, Int n ) |
---|
2464 | { |
---|
2465 | Int i; |
---|
2466 | UInt cn; |
---|
2467 | Int level,vlc,sign,done,last_pos,start; |
---|
2468 | Int run_done,maxrun,run,lev; |
---|
2469 | #if QC_MOD_LCEC |
---|
2470 | Int vlc_adaptive=0; |
---|
2471 | #else |
---|
2472 | Int tmprun, vlc_adaptive=0; |
---|
2473 | #endif |
---|
2474 | static const int atable[5] = {4,6,14,28,0xfffffff}; |
---|
2475 | Int tmp; |
---|
2476 | #if QC_MOD_LCEC |
---|
2477 | Int nTab = max(0,n-2); |
---|
2478 | Int tr1; |
---|
2479 | #endif |
---|
2480 | |
---|
2481 | /* Do the last coefficient first */ |
---|
2482 | i = 0; |
---|
2483 | done = 0; |
---|
2484 | |
---|
2485 | while (!done && i < 16) |
---|
2486 | { |
---|
2487 | if (scoeff[i]) |
---|
2488 | { |
---|
2489 | done = 1; |
---|
2490 | } |
---|
2491 | else |
---|
2492 | { |
---|
2493 | i++; |
---|
2494 | } |
---|
2495 | } |
---|
2496 | if (i == 16) |
---|
2497 | { |
---|
2498 | return; |
---|
2499 | } |
---|
2500 | |
---|
2501 | last_pos = 15-i; |
---|
2502 | level = abs(scoeff[i]); |
---|
2503 | lev = (level == 1) ? 0 : 1; |
---|
2504 | |
---|
2505 | #if QC_MOD_LCEC |
---|
2506 | if (level>1){ |
---|
2507 | tr1=0; |
---|
2508 | } |
---|
2509 | else{ |
---|
2510 | tr1=1; |
---|
2511 | } |
---|
2512 | #endif |
---|
2513 | |
---|
2514 | { |
---|
2515 | int x,y,cx,cy,vlcNum; |
---|
2516 | int vlcTable[3] = {2,2,2}; |
---|
2517 | |
---|
2518 | x = 16*lev + last_pos; |
---|
2519 | |
---|
2520 | #if QC_MOD_LCEC |
---|
2521 | cx = m_uiLPTableE4[nTab][x]; |
---|
2522 | vlcNum = vlcTable[nTab]; |
---|
2523 | #else |
---|
2524 | cx = m_uiLPTableE4[n][x]; |
---|
2525 | vlcNum = vlcTable[n]; |
---|
2526 | #endif |
---|
2527 | |
---|
2528 | #if LCEC_STAT |
---|
2529 | if (m_bAdaptFlag) |
---|
2530 | m_uiBitCoeff += xWriteVlc( vlcNum, cx ); |
---|
2531 | else |
---|
2532 | #endif |
---|
2533 | xWriteVlc( vlcNum, cx ); |
---|
2534 | |
---|
2535 | if ( m_bAdaptFlag ) |
---|
2536 | { |
---|
2537 | |
---|
2538 | cy = Max( 0, cx-1 ); |
---|
2539 | #if QC_MOD_LCEC |
---|
2540 | y = m_uiLPTableD4[nTab][cy]; |
---|
2541 | m_uiLPTableD4[nTab][cy] = x; |
---|
2542 | m_uiLPTableD4[nTab][cx] = y; |
---|
2543 | m_uiLPTableE4[nTab][x] = cy; |
---|
2544 | m_uiLPTableE4[nTab][y] = cx; |
---|
2545 | #else |
---|
2546 | y = m_uiLPTableD4[n][cy]; |
---|
2547 | m_uiLPTableD4[n][cy] = x; |
---|
2548 | m_uiLPTableD4[n][cx] = y; |
---|
2549 | m_uiLPTableE4[n][x] = cy; |
---|
2550 | m_uiLPTableE4[n][y] = cx; |
---|
2551 | #endif |
---|
2552 | } |
---|
2553 | } |
---|
2554 | |
---|
2555 | sign = (scoeff[i] < 0) ? 1 : 0; |
---|
2556 | if (level > 1) |
---|
2557 | { |
---|
2558 | #if LCEC_STAT |
---|
2559 | if (m_bAdaptFlag) |
---|
2560 | m_uiBitCoeff += xWriteVlc( 0, 2*(level-2)+sign ); |
---|
2561 | else |
---|
2562 | #endif |
---|
2563 | xWriteVlc( 0, 2*(level-2)+sign ); |
---|
2564 | } |
---|
2565 | else |
---|
2566 | { |
---|
2567 | xWriteFlag( sign ); |
---|
2568 | #if LCEC_STAT |
---|
2569 | if (m_bAdaptFlag) |
---|
2570 | m_uiBitCoeff += 1; |
---|
2571 | #endif |
---|
2572 | } |
---|
2573 | i++; |
---|
2574 | |
---|
2575 | if (i < 16) |
---|
2576 | { |
---|
2577 | /* Go into run mode */ |
---|
2578 | run_done = 0; |
---|
2579 | while (!run_done) |
---|
2580 | { |
---|
2581 | maxrun = 15-i; |
---|
2582 | #if QC_MOD_LCEC |
---|
2583 | if ( n == 2 ) |
---|
2584 | vlc = g_auiVlcTable8x8Intra[maxrun]; |
---|
2585 | else |
---|
2586 | vlc = g_auiVlcTable8x8Inter[maxrun]; |
---|
2587 | #else |
---|
2588 | tmprun = maxrun; |
---|
2589 | if (maxrun > 27) |
---|
2590 | { |
---|
2591 | vlc = 3; |
---|
2592 | tmprun = 28; |
---|
2593 | } |
---|
2594 | else |
---|
2595 | { |
---|
2596 | vlc = g_auiVlcTable8x8[maxrun]; |
---|
2597 | } |
---|
2598 | #endif |
---|
2599 | |
---|
2600 | run = 0; |
---|
2601 | done = 0; |
---|
2602 | while (!done) |
---|
2603 | { |
---|
2604 | if (!scoeff[i]) |
---|
2605 | { |
---|
2606 | run++; |
---|
2607 | } |
---|
2608 | else |
---|
2609 | { |
---|
2610 | level = abs(scoeff[i]); |
---|
2611 | lev = (level == 1) ? 0 : 1; |
---|
2612 | #if QC_MOD_LCEC |
---|
2613 | if ( n == 2 ){ |
---|
2614 | cn = xRunLevelInd(lev, run, maxrun, g_auiLumaRunTr14x4[tr1][maxrun]); |
---|
2615 | } |
---|
2616 | else{ |
---|
2617 | cn = g_auiLumaRun8x8[maxrun][lev][run]; |
---|
2618 | } |
---|
2619 | #else |
---|
2620 | if (maxrun > 27) |
---|
2621 | { |
---|
2622 | cn = g_auiLumaRun8x8[28][lev][run]; |
---|
2623 | } |
---|
2624 | else |
---|
2625 | { |
---|
2626 | cn = g_auiLumaRun8x8[maxrun][lev][run]; |
---|
2627 | } |
---|
2628 | #endif |
---|
2629 | #if LCEC_STAT |
---|
2630 | if (m_bAdaptFlag) |
---|
2631 | m_uiBitCoeff += xWriteVlc( vlc, cn ); |
---|
2632 | else |
---|
2633 | #endif |
---|
2634 | xWriteVlc( vlc, cn ); |
---|
2635 | |
---|
2636 | #if QC_MOD_LCEC |
---|
2637 | if (tr1>0 && tr1 < MAX_TR1) |
---|
2638 | { |
---|
2639 | tr1++; |
---|
2640 | } |
---|
2641 | #endif |
---|
2642 | sign = (scoeff[i] < 0) ? 1 : 0; |
---|
2643 | if (level > 1) |
---|
2644 | { |
---|
2645 | #if LCEC_STAT |
---|
2646 | if (m_bAdaptFlag) |
---|
2647 | m_uiBitCoeff += xWriteVlc( 0, 2*(level-2)+sign ); |
---|
2648 | else |
---|
2649 | #endif |
---|
2650 | xWriteVlc( 0, 2*(level-2)+sign ); |
---|
2651 | run_done = 1; |
---|
2652 | } |
---|
2653 | else |
---|
2654 | { |
---|
2655 | xWriteFlag( sign ); |
---|
2656 | #if LCEC_STAT |
---|
2657 | if (m_bAdaptFlag) |
---|
2658 | m_uiBitCoeff += 1; |
---|
2659 | #endif |
---|
2660 | } |
---|
2661 | |
---|
2662 | run = 0; |
---|
2663 | done = 1; |
---|
2664 | } |
---|
2665 | if (i == 15) |
---|
2666 | { |
---|
2667 | done = 1; |
---|
2668 | run_done = 1; |
---|
2669 | if (run) |
---|
2670 | { |
---|
2671 | #if QC_MOD_LCEC |
---|
2672 | if (n==2){ |
---|
2673 | cn=xRunLevelInd(0, run, maxrun, g_auiLumaRunTr14x4[tr1][maxrun]); |
---|
2674 | } |
---|
2675 | else{ |
---|
2676 | cn = g_auiLumaRun8x8[maxrun][0][run]; |
---|
2677 | } |
---|
2678 | #else |
---|
2679 | if (maxrun > 27) |
---|
2680 | { |
---|
2681 | cn = g_auiLumaRun8x8[28][0][run]; |
---|
2682 | } |
---|
2683 | else |
---|
2684 | { |
---|
2685 | cn = g_auiLumaRun8x8[maxrun][0][run]; |
---|
2686 | } |
---|
2687 | #endif |
---|
2688 | #if LCEC_STAT |
---|
2689 | if (m_bAdaptFlag) |
---|
2690 | m_uiBitCoeff += xWriteVlc( vlc, cn ); |
---|
2691 | else |
---|
2692 | #endif |
---|
2693 | xWriteVlc( vlc, cn ); |
---|
2694 | } |
---|
2695 | } |
---|
2696 | i++; |
---|
2697 | } |
---|
2698 | } |
---|
2699 | } |
---|
2700 | |
---|
2701 | /* Code the rest in level mode */ |
---|
2702 | start = i; |
---|
2703 | for ( i=start; i<16; i++ ) |
---|
2704 | { |
---|
2705 | tmp = abs(scoeff[i]); |
---|
2706 | #if LCEC_STAT |
---|
2707 | if (m_bAdaptFlag) |
---|
2708 | m_uiBitCoeff += xWriteVlc( vlc_adaptive, tmp ); |
---|
2709 | else |
---|
2710 | #endif |
---|
2711 | xWriteVlc( vlc_adaptive, tmp ); |
---|
2712 | if (scoeff[i]) |
---|
2713 | { |
---|
2714 | sign = (scoeff[i] < 0) ? 1 : 0; |
---|
2715 | xWriteFlag( sign ); |
---|
2716 | #if LCEC_STAT |
---|
2717 | if (m_bAdaptFlag) |
---|
2718 | m_uiBitCoeff += 1; |
---|
2719 | #endif |
---|
2720 | } |
---|
2721 | if ( tmp > atable[vlc_adaptive] ) |
---|
2722 | { |
---|
2723 | vlc_adaptive++; |
---|
2724 | } |
---|
2725 | } |
---|
2726 | return; |
---|
2727 | } |
---|
2728 | |
---|
2729 | Void TEncCavlc::xCodeCoeff8x8( TCoeff* scoeff, Int n ) |
---|
2730 | { |
---|
2731 | int i; |
---|
2732 | unsigned int cn; |
---|
2733 | int level,vlc,sign,done,last_pos,start; |
---|
2734 | int run_done,maxrun,run,lev; |
---|
2735 | #if QC_MOD_LCEC |
---|
2736 | int vlc_adaptive=0; |
---|
2737 | #else |
---|
2738 | int tmprun,vlc_adaptive=0; |
---|
2739 | #endif |
---|
2740 | static const int atable[5] = {4,6,14,28,0xfffffff}; |
---|
2741 | int tmp; |
---|
2742 | #if QC_MOD_LCEC |
---|
2743 | Int tr1; |
---|
2744 | #endif |
---|
2745 | |
---|
2746 | static const int switch_thr[10] = {49,49,0,49,49,0,49,49,49,49}; |
---|
2747 | int sum_big_coef = 0; |
---|
2748 | |
---|
2749 | |
---|
2750 | /* Do the last coefficient first */ |
---|
2751 | i = 0; |
---|
2752 | done = 0; |
---|
2753 | while (!done && i < 64) |
---|
2754 | { |
---|
2755 | if (scoeff[i]) |
---|
2756 | { |
---|
2757 | done = 1; |
---|
2758 | } |
---|
2759 | else |
---|
2760 | { |
---|
2761 | i++; |
---|
2762 | } |
---|
2763 | } |
---|
2764 | if (i == 64) |
---|
2765 | { |
---|
2766 | return; |
---|
2767 | } |
---|
2768 | |
---|
2769 | last_pos = 63-i; |
---|
2770 | level = abs(scoeff[i]); |
---|
2771 | lev = (level == 1) ? 0 : 1; |
---|
2772 | |
---|
2773 | { |
---|
2774 | int x,y,cx,cy,vlcNum; |
---|
2775 | x = 64*lev + last_pos; |
---|
2776 | |
---|
2777 | cx = m_uiLPTableE8[n][x]; |
---|
2778 | // ADAPT_VLC_NUM |
---|
2779 | vlcNum = g_auiLastPosVlcNum[n][Min(16,m_uiLastPosVlcIndex[n])]; |
---|
2780 | #if LCEC_STAT |
---|
2781 | if (m_bAdaptFlag) |
---|
2782 | m_uiBitCoeff += xWriteVlc( vlcNum, cx ); |
---|
2783 | else |
---|
2784 | #endif |
---|
2785 | xWriteVlc( vlcNum, cx ); |
---|
2786 | |
---|
2787 | if ( m_bAdaptFlag ) |
---|
2788 | { |
---|
2789 | |
---|
2790 | // ADAPT_VLC_NUM |
---|
2791 | m_uiLastPosVlcIndex[n] += cx == m_uiLastPosVlcIndex[n] ? 0 : (cx < m_uiLastPosVlcIndex[n] ? -1 : 1); |
---|
2792 | cy = Max(0,cx-1); |
---|
2793 | y = m_uiLPTableD8[n][cy]; |
---|
2794 | m_uiLPTableD8[n][cy] = x; |
---|
2795 | m_uiLPTableD8[n][cx] = y; |
---|
2796 | m_uiLPTableE8[n][x] = cy; |
---|
2797 | m_uiLPTableE8[n][y] = cx; |
---|
2798 | } |
---|
2799 | } |
---|
2800 | |
---|
2801 | sign = (scoeff[i] < 0) ? 1 : 0; |
---|
2802 | if (level > 1) |
---|
2803 | { |
---|
2804 | #if LCEC_STAT |
---|
2805 | if (m_bAdaptFlag) |
---|
2806 | m_uiBitCoeff += xWriteVlc( 0, 2*(level-2)+sign ); |
---|
2807 | else |
---|
2808 | #endif |
---|
2809 | xWriteVlc( 0, 2*(level-2)+sign ); |
---|
2810 | } |
---|
2811 | else |
---|
2812 | { |
---|
2813 | xWriteFlag( sign ); |
---|
2814 | #if LCEC_STAT |
---|
2815 | if (m_bAdaptFlag) |
---|
2816 | m_uiBitCoeff += 1; |
---|
2817 | #endif |
---|
2818 | } |
---|
2819 | i++; |
---|
2820 | #if QC_MOD_LCEC |
---|
2821 | if (level>1){ |
---|
2822 | tr1=0; |
---|
2823 | } |
---|
2824 | else{ |
---|
2825 | tr1=1; |
---|
2826 | } |
---|
2827 | #endif |
---|
2828 | |
---|
2829 | if (i < 64) |
---|
2830 | { |
---|
2831 | /* Go into run mode */ |
---|
2832 | run_done = 0; |
---|
2833 | while ( !run_done ) |
---|
2834 | { |
---|
2835 | maxrun = 63-i; |
---|
2836 | #if QC_MOD_LCEC |
---|
2837 | if(n == 2 || n == 5) |
---|
2838 | vlc = g_auiVlcTable8x8Intra[Min(maxrun,28)]; |
---|
2839 | else |
---|
2840 | vlc = g_auiVlcTable8x8Inter[Min(maxrun,28)]; |
---|
2841 | #else |
---|
2842 | tmprun = maxrun; |
---|
2843 | if (maxrun > 27) |
---|
2844 | { |
---|
2845 | vlc = 3; |
---|
2846 | tmprun = 28; |
---|
2847 | } |
---|
2848 | else |
---|
2849 | { |
---|
2850 | vlc = g_auiVlcTable8x8[maxrun]; |
---|
2851 | } |
---|
2852 | #endif |
---|
2853 | |
---|
2854 | run = 0; |
---|
2855 | done = 0; |
---|
2856 | while (!done) |
---|
2857 | { |
---|
2858 | if (!scoeff[i]) |
---|
2859 | { |
---|
2860 | run++; |
---|
2861 | } |
---|
2862 | else |
---|
2863 | { |
---|
2864 | level = abs(scoeff[i]); |
---|
2865 | lev = (level == 1) ? 0 : 1; |
---|
2866 | #if QC_MOD_LCEC |
---|
2867 | if(n == 2 || n == 5) |
---|
2868 | cn = xRunLevelInd(lev, run, maxrun, g_auiLumaRunTr18x8[tr1][min(maxrun,28)]); |
---|
2869 | else |
---|
2870 | cn = g_auiLumaRun8x8[min(maxrun,28)][lev][run]; |
---|
2871 | #else |
---|
2872 | if (maxrun > 27) |
---|
2873 | { |
---|
2874 | cn = g_auiLumaRun8x8[28][lev][run]; |
---|
2875 | } |
---|
2876 | else |
---|
2877 | { |
---|
2878 | cn = g_auiLumaRun8x8[maxrun][lev][run]; |
---|
2879 | } |
---|
2880 | #endif |
---|
2881 | #if LCEC_STAT |
---|
2882 | if (m_bAdaptFlag) |
---|
2883 | m_uiBitCoeff += xWriteVlc( vlc, cn ); |
---|
2884 | else |
---|
2885 | #endif |
---|
2886 | xWriteVlc( vlc, cn ); |
---|
2887 | |
---|
2888 | #if QC_MOD_LCEC |
---|
2889 | if (tr1==0 || level >=2) |
---|
2890 | { |
---|
2891 | tr1=0; |
---|
2892 | } |
---|
2893 | else if (tr1 < MAX_TR1) |
---|
2894 | { |
---|
2895 | tr1++; |
---|
2896 | } |
---|
2897 | #endif |
---|
2898 | sign = (scoeff[i] < 0) ? 1 : 0; |
---|
2899 | if (level > 1) |
---|
2900 | { |
---|
2901 | #if LCEC_STAT |
---|
2902 | if (m_bAdaptFlag) |
---|
2903 | m_uiBitCoeff += xWriteVlc( 0, 2*(level-2)+sign ); |
---|
2904 | else |
---|
2905 | #endif |
---|
2906 | xWriteVlc( 0, 2*(level-2)+sign ); |
---|
2907 | |
---|
2908 | sum_big_coef += level; |
---|
2909 | if (i > switch_thr[n] || sum_big_coef > 2) |
---|
2910 | { |
---|
2911 | run_done = 1; |
---|
2912 | } |
---|
2913 | } |
---|
2914 | else |
---|
2915 | { |
---|
2916 | xWriteFlag( sign ); |
---|
2917 | #if LCEC_STAT |
---|
2918 | if (m_bAdaptFlag) |
---|
2919 | m_uiBitCoeff += 1; |
---|
2920 | #endif |
---|
2921 | } |
---|
2922 | run = 0; |
---|
2923 | done = 1; |
---|
2924 | } |
---|
2925 | if (i == 63) |
---|
2926 | { |
---|
2927 | done = 1; |
---|
2928 | run_done = 1; |
---|
2929 | if (run) |
---|
2930 | { |
---|
2931 | #if QC_MOD_LCEC |
---|
2932 | if(n == 2 || n == 5) |
---|
2933 | cn=xRunLevelInd(0, run, maxrun, g_auiLumaRunTr18x8[tr1][min(maxrun,28)]); |
---|
2934 | else |
---|
2935 | cn = g_auiLumaRun8x8[min(maxrun,28)][0][run]; |
---|
2936 | #else |
---|
2937 | if (maxrun > 27) |
---|
2938 | { |
---|
2939 | cn = g_auiLumaRun8x8[28][0][run]; |
---|
2940 | } |
---|
2941 | else |
---|
2942 | { |
---|
2943 | cn = g_auiLumaRun8x8[maxrun][0][run]; |
---|
2944 | } |
---|
2945 | #endif |
---|
2946 | #if LCEC_STAT |
---|
2947 | if (m_bAdaptFlag) |
---|
2948 | m_uiBitCoeff += xWriteVlc( vlc, cn ); |
---|
2949 | else |
---|
2950 | #endif |
---|
2951 | xWriteVlc( vlc, cn ); |
---|
2952 | } |
---|
2953 | } |
---|
2954 | i++; |
---|
2955 | } |
---|
2956 | } |
---|
2957 | } |
---|
2958 | |
---|
2959 | /* Code the rest in level mode */ |
---|
2960 | start = i; |
---|
2961 | for ( i=start; i<64; i++ ) |
---|
2962 | { |
---|
2963 | tmp = abs(scoeff[i]); |
---|
2964 | #if LCEC_STAT |
---|
2965 | if (m_bAdaptFlag) |
---|
2966 | m_uiBitCoeff += xWriteVlc( vlc_adaptive, tmp ); |
---|
2967 | else |
---|
2968 | #endif |
---|
2969 | xWriteVlc( vlc_adaptive, tmp ); |
---|
2970 | if (scoeff[i]) |
---|
2971 | { |
---|
2972 | sign = (scoeff[i] < 0) ? 1 : 0; |
---|
2973 | xWriteFlag( sign ); |
---|
2974 | #if LCEC_STAT |
---|
2975 | if (m_bAdaptFlag) |
---|
2976 | m_uiBitCoeff += 1; |
---|
2977 | #endif |
---|
2978 | } |
---|
2979 | if (tmp>atable[vlc_adaptive]) |
---|
2980 | { |
---|
2981 | vlc_adaptive++; |
---|
2982 | } |
---|
2983 | } |
---|
2984 | |
---|
2985 | return; |
---|
2986 | } |
---|