1 | |
---|
2 | |
---|
3 | /** \file TEncEntropy.cpp |
---|
4 | \brief entropy encoder class |
---|
5 | */ |
---|
6 | |
---|
7 | #include "TEncEntropy.h" |
---|
8 | |
---|
9 | Void TEncEntropy::setEntropyCoder ( TEncEntropyIf* e, TComSlice* pcSlice ) |
---|
10 | { |
---|
11 | m_pcEntropyCoderIf = e; |
---|
12 | m_pcEntropyCoderIf->setSlice ( pcSlice ); |
---|
13 | } |
---|
14 | |
---|
15 | Void TEncEntropy::encodeSliceHeader ( TComSlice* pcSlice ) |
---|
16 | { |
---|
17 | m_pcEntropyCoderIf->codeSliceHeader( pcSlice ); |
---|
18 | return; |
---|
19 | } |
---|
20 | |
---|
21 | Void TEncEntropy::encodeTerminatingBit ( UInt uiIsLast ) |
---|
22 | { |
---|
23 | m_pcEntropyCoderIf->codeTerminatingBit( uiIsLast ); |
---|
24 | |
---|
25 | return; |
---|
26 | } |
---|
27 | |
---|
28 | Void TEncEntropy::encodeSliceFinish() |
---|
29 | { |
---|
30 | m_pcEntropyCoderIf->codeSliceFinish(); |
---|
31 | } |
---|
32 | |
---|
33 | void TEncEntropy::encodeSEI(const SEI& sei) |
---|
34 | { |
---|
35 | m_pcEntropyCoderIf->codeSEI(sei); |
---|
36 | return; |
---|
37 | } |
---|
38 | |
---|
39 | Void TEncEntropy::encodePPS( TComPPS* pcPPS ) |
---|
40 | { |
---|
41 | m_pcEntropyCoderIf->codePPS( pcPPS ); |
---|
42 | return; |
---|
43 | } |
---|
44 | |
---|
45 | Void TEncEntropy::encodeSPS( TComSPS* pcSPS ) |
---|
46 | { |
---|
47 | m_pcEntropyCoderIf->codeSPS( pcSPS ); |
---|
48 | return; |
---|
49 | } |
---|
50 | |
---|
51 | Void TEncEntropy::encodeSkipFlag( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool bRD ) |
---|
52 | { |
---|
53 | if ( pcCU->getSlice()->isIntra() ) |
---|
54 | { |
---|
55 | return; |
---|
56 | } |
---|
57 | if( bRD ) |
---|
58 | uiAbsPartIdx = 0; |
---|
59 | m_pcEntropyCoderIf->codeSkipFlag( pcCU, uiAbsPartIdx ); |
---|
60 | } |
---|
61 | |
---|
62 | #include "../TLibCommon/TypeDef.h" |
---|
63 | #include "../TLibCommon/TComAdaptiveLoopFilter.h" |
---|
64 | Void TEncEntropy::codeFiltCountBit(ALFParam* pAlfParam, Int64* ruiRate) |
---|
65 | { |
---|
66 | resetEntropy(); |
---|
67 | resetBits(); |
---|
68 | codeFilt(pAlfParam); |
---|
69 | *ruiRate = getNumberOfWrittenBits(); |
---|
70 | resetEntropy(); |
---|
71 | resetBits(); |
---|
72 | } |
---|
73 | |
---|
74 | Void TEncEntropy::codeAuxCountBit(ALFParam* pAlfParam, Int64* ruiRate) |
---|
75 | { |
---|
76 | resetEntropy(); |
---|
77 | resetBits(); |
---|
78 | codeAux(pAlfParam); |
---|
79 | *ruiRate = getNumberOfWrittenBits(); |
---|
80 | resetEntropy(); |
---|
81 | resetBits(); |
---|
82 | } |
---|
83 | |
---|
84 | Void TEncEntropy::codeAux(ALFParam* pAlfParam) |
---|
85 | { |
---|
86 | #if ENABLE_FORCECOEFF0 |
---|
87 | if (pAlfParam->filtNo>=0) m_pcEntropyCoderIf->codeAlfFlag(1); |
---|
88 | else m_pcEntropyCoderIf->codeAlfFlag(0); |
---|
89 | #endif |
---|
90 | Int FiltTab[3] = {9, 7, 5}; |
---|
91 | Int Tab = FiltTab[pAlfParam->realfiltNo]; |
---|
92 | // m_pcEntropyCoderIf->codeAlfUvlc(pAlfParam->realfiltNo); |
---|
93 | |
---|
94 | #if MQT_BA_RA |
---|
95 | m_pcEntropyCoderIf->codeAlfFlag(pAlfParam->alf_pcr_region_flag); |
---|
96 | #endif |
---|
97 | |
---|
98 | m_pcEntropyCoderIf->codeAlfUvlc((Tab-5)/2); |
---|
99 | |
---|
100 | if (pAlfParam->filtNo>=0) |
---|
101 | { |
---|
102 | if(pAlfParam->realfiltNo >= 0) |
---|
103 | { |
---|
104 | // filters_per_fr |
---|
105 | m_pcEntropyCoderIf->codeAlfUvlc(pAlfParam->noFilters); |
---|
106 | |
---|
107 | if(pAlfParam->noFilters == 1) |
---|
108 | { |
---|
109 | m_pcEntropyCoderIf->codeAlfUvlc(pAlfParam->startSecondFilter); |
---|
110 | } |
---|
111 | else if (pAlfParam->noFilters == 2) |
---|
112 | { |
---|
113 | for (int i=1; i<NO_VAR_BINS; i++) m_pcEntropyCoderIf->codeAlfFlag (pAlfParam->filterPattern[i]); |
---|
114 | } |
---|
115 | } |
---|
116 | } |
---|
117 | } |
---|
118 | |
---|
119 | Int TEncEntropy::lengthGolomb(int coeffVal, int k) |
---|
120 | { |
---|
121 | int m = 2 << (k - 1); |
---|
122 | int q = coeffVal / m; |
---|
123 | if(coeffVal != 0) |
---|
124 | return(q + 2 + k); |
---|
125 | else |
---|
126 | return(q + 1 + k); |
---|
127 | } |
---|
128 | |
---|
129 | Int TEncEntropy::codeFilterCoeff(ALFParam* ALFp) |
---|
130 | { |
---|
131 | int filters_per_group = ALFp->filters_per_group_diff; |
---|
132 | int sqrFiltLength = ALFp->num_coeff; |
---|
133 | int filtNo = ALFp->realfiltNo; |
---|
134 | int flTab[]={9/2, 7/2, 5/2}; |
---|
135 | int fl = flTab[filtNo]; |
---|
136 | int i, k, kMin, kStart, minBits, ind, scanPos, maxScanVal, coeffVal, len = 0, |
---|
137 | *pDepthInt=NULL, kMinTab[MAX_SQR_FILT_LENGTH], bitsCoeffScan[MAX_SCAN_VAL][MAX_EXP_GOLOMB], |
---|
138 | minKStart, minBitsKStart, bitsKStart; |
---|
139 | |
---|
140 | pDepthInt = pDepthIntTab[fl-2]; |
---|
141 | |
---|
142 | maxScanVal = 0; |
---|
143 | for(i = 0; i < sqrFiltLength; i++) |
---|
144 | maxScanVal = max(maxScanVal, pDepthInt[i]); |
---|
145 | |
---|
146 | // vlc for all |
---|
147 | memset(bitsCoeffScan, 0, MAX_SCAN_VAL * MAX_EXP_GOLOMB * sizeof(int)); |
---|
148 | for(ind=0; ind<filters_per_group; ++ind) |
---|
149 | { |
---|
150 | for(i = 0; i < sqrFiltLength; i++) |
---|
151 | { |
---|
152 | scanPos=pDepthInt[i]-1; |
---|
153 | coeffVal=abs(ALFp->coeffmulti[ind][i]); |
---|
154 | for (k=1; k<15; k++) |
---|
155 | { |
---|
156 | bitsCoeffScan[scanPos][k]+=lengthGolomb(coeffVal, k); |
---|
157 | } |
---|
158 | } |
---|
159 | } |
---|
160 | |
---|
161 | minBitsKStart = 0; |
---|
162 | minKStart = -1; |
---|
163 | for(k = 1; k < 8; k++) |
---|
164 | { |
---|
165 | bitsKStart = 0; |
---|
166 | kStart = k; |
---|
167 | for(scanPos = 0; scanPos < maxScanVal; scanPos++) |
---|
168 | { |
---|
169 | kMin = kStart; |
---|
170 | minBits = bitsCoeffScan[scanPos][kMin]; |
---|
171 | |
---|
172 | if(bitsCoeffScan[scanPos][kStart+1] < minBits) |
---|
173 | { |
---|
174 | kMin = kStart + 1; |
---|
175 | minBits = bitsCoeffScan[scanPos][kMin]; |
---|
176 | } |
---|
177 | kStart = kMin; |
---|
178 | bitsKStart += minBits; |
---|
179 | } |
---|
180 | if((bitsKStart < minBitsKStart) || (k == 1)) |
---|
181 | { |
---|
182 | minBitsKStart = bitsKStart; |
---|
183 | minKStart = k; |
---|
184 | } |
---|
185 | } |
---|
186 | |
---|
187 | kStart = minKStart; |
---|
188 | for(scanPos = 0; scanPos < maxScanVal; scanPos++) |
---|
189 | { |
---|
190 | kMin = kStart; |
---|
191 | minBits = bitsCoeffScan[scanPos][kMin]; |
---|
192 | |
---|
193 | if(bitsCoeffScan[scanPos][kStart+1] < minBits) |
---|
194 | { |
---|
195 | kMin = kStart + 1; |
---|
196 | minBits = bitsCoeffScan[scanPos][kMin]; |
---|
197 | } |
---|
198 | |
---|
199 | kMinTab[scanPos] = kMin; |
---|
200 | kStart = kMin; |
---|
201 | } |
---|
202 | |
---|
203 | // Coding parameters |
---|
204 | ALFp->minKStart = minKStart; |
---|
205 | ALFp->maxScanVal = maxScanVal; |
---|
206 | for(scanPos = 0; scanPos < maxScanVal; scanPos++) |
---|
207 | { |
---|
208 | ALFp->kMinTab[scanPos] = kMinTab[scanPos]; |
---|
209 | } |
---|
210 | len += writeFilterCodingParams(minKStart, maxScanVal, kMinTab); |
---|
211 | |
---|
212 | // Filter coefficients |
---|
213 | len += writeFilterCoeffs(sqrFiltLength, filters_per_group, pDepthInt, ALFp->coeffmulti, kMinTab); |
---|
214 | |
---|
215 | return len; |
---|
216 | } |
---|
217 | |
---|
218 | Int TEncEntropy::writeFilterCodingParams(int minKStart, int maxScanVal, int kMinTab[]) |
---|
219 | { |
---|
220 | int scanPos; |
---|
221 | int golombIndexBit; |
---|
222 | int kMin; |
---|
223 | |
---|
224 | // Golomb parameters |
---|
225 | m_pcEntropyCoderIf->codeAlfUvlc(minKStart - 1); |
---|
226 | |
---|
227 | kMin = minKStart; |
---|
228 | for(scanPos = 0; scanPos < maxScanVal; scanPos++) |
---|
229 | { |
---|
230 | golombIndexBit = (kMinTab[scanPos] != kMin)? 1: 0; |
---|
231 | |
---|
232 | assert(kMinTab[scanPos] <= kMin + 1); |
---|
233 | |
---|
234 | m_pcEntropyCoderIf->codeAlfFlag(golombIndexBit); |
---|
235 | kMin = kMinTab[scanPos]; |
---|
236 | } |
---|
237 | |
---|
238 | return 0; |
---|
239 | } |
---|
240 | |
---|
241 | Int TEncEntropy::writeFilterCoeffs(int sqrFiltLength, int filters_per_group, int pDepthInt[], |
---|
242 | int **FilterCoeff, int kMinTab[]) |
---|
243 | { |
---|
244 | int ind, scanPos, i; |
---|
245 | |
---|
246 | for(ind = 0; ind < filters_per_group; ++ind) |
---|
247 | { |
---|
248 | for(i = 0; i < sqrFiltLength; i++) |
---|
249 | { |
---|
250 | scanPos = pDepthInt[i] - 1; |
---|
251 | golombEncode(FilterCoeff[ind][i], kMinTab[scanPos]); |
---|
252 | } |
---|
253 | } |
---|
254 | return 0; |
---|
255 | } |
---|
256 | |
---|
257 | Int TEncEntropy::golombEncode(int coeff, int k) |
---|
258 | { |
---|
259 | int q, i, m; |
---|
260 | int symbol = abs(coeff); |
---|
261 | |
---|
262 | m = (int)pow(2.0, k); |
---|
263 | q = symbol / m; |
---|
264 | |
---|
265 | for (i = 0; i < q; i++) |
---|
266 | m_pcEntropyCoderIf->codeAlfFlag(1); |
---|
267 | m_pcEntropyCoderIf->codeAlfFlag(0); |
---|
268 | // write one zero |
---|
269 | |
---|
270 | for(i = 0; i < k; i++) |
---|
271 | { |
---|
272 | m_pcEntropyCoderIf->codeAlfFlag(symbol & 0x01); |
---|
273 | symbol >>= 1; |
---|
274 | } |
---|
275 | |
---|
276 | if(coeff != 0) |
---|
277 | { |
---|
278 | int sign = (coeff > 0)? 1: 0; |
---|
279 | m_pcEntropyCoderIf->codeAlfFlag(sign); |
---|
280 | } |
---|
281 | return 0; |
---|
282 | } |
---|
283 | |
---|
284 | Void TEncEntropy::codeFilt(ALFParam* pAlfParam) |
---|
285 | { |
---|
286 | if(pAlfParam->filters_per_group > 1) |
---|
287 | { |
---|
288 | #if ENABLE_FORCECOEFF0 |
---|
289 | m_pcEntropyCoderIf->codeAlfFlag (pAlfParam->forceCoeff0); |
---|
290 | if (pAlfParam->forceCoeff0) |
---|
291 | { |
---|
292 | for (int i=0; i<pAlfParam->filters_per_group; i++) m_pcEntropyCoderIf->codeAlfFlag (pAlfParam->codedVarBins[i]); |
---|
293 | } |
---|
294 | #endif |
---|
295 | m_pcEntropyCoderIf->codeAlfFlag (pAlfParam->predMethod); |
---|
296 | } |
---|
297 | codeFilterCoeff (pAlfParam); |
---|
298 | } |
---|
299 | |
---|
300 | Void print(ALFParam* pAlfParam) |
---|
301 | { |
---|
302 | Int i=0; |
---|
303 | Int ind=0; |
---|
304 | Int FiltLengthTab[] = {22, 14, 8}; //0:9tap |
---|
305 | Int FiltLength = FiltLengthTab[pAlfParam->realfiltNo]; |
---|
306 | |
---|
307 | printf("set of params\n"); |
---|
308 | printf("realfiltNo:%d\n", pAlfParam->realfiltNo); |
---|
309 | printf("filtNo:%d\n", pAlfParam->filtNo); |
---|
310 | printf("filterPattern:"); |
---|
311 | for (i=0; i<NO_VAR_BINS; i++) printf("%d ", pAlfParam->filterPattern[i]); |
---|
312 | printf("\n"); |
---|
313 | |
---|
314 | printf("startSecondFilter:%d\n", pAlfParam->startSecondFilter); |
---|
315 | printf("noFilters:%d\n", pAlfParam->noFilters); |
---|
316 | printf("varIndTab:"); |
---|
317 | for (i=0; i<NO_VAR_BINS; i++) printf("%d ", pAlfParam->varIndTab[i]); |
---|
318 | printf("\n"); |
---|
319 | printf("filters_per_group_diff:%d\n", pAlfParam->filters_per_group_diff); |
---|
320 | printf("filters_per_group:%d\n", pAlfParam->filters_per_group); |
---|
321 | printf("codedVarBins:"); |
---|
322 | for (i=0; i<NO_VAR_BINS; i++) printf("%d ", pAlfParam->codedVarBins[i]); |
---|
323 | printf("\n"); |
---|
324 | printf("forceCoeff0:%d\n", pAlfParam->forceCoeff0); |
---|
325 | printf("predMethod:%d\n", pAlfParam->predMethod); |
---|
326 | |
---|
327 | for (ind=0; ind<pAlfParam->filters_per_group_diff; ind++) |
---|
328 | { |
---|
329 | printf("coeffmulti(%d):", ind); |
---|
330 | for (i=0; i<FiltLength; i++) printf("%d ", pAlfParam->coeffmulti[ind][i]); |
---|
331 | printf("\n"); |
---|
332 | } |
---|
333 | |
---|
334 | printf("minKStart:%d\n", pAlfParam->minKStart); |
---|
335 | printf("maxScanVal:%d\n", pAlfParam->maxScanVal); |
---|
336 | printf("kMinTab:"); |
---|
337 | for(Int scanPos = 0; scanPos < pAlfParam->maxScanVal; scanPos++) |
---|
338 | { |
---|
339 | printf("%d ", pAlfParam->kMinTab[scanPos]); |
---|
340 | } |
---|
341 | printf("\n"); |
---|
342 | |
---|
343 | printf("chroma_idc:%d\n", pAlfParam->chroma_idc); |
---|
344 | printf("tap_chroma:%d\n", pAlfParam->tap_chroma); |
---|
345 | printf("chroma_coeff:"); |
---|
346 | for(Int scanPos = 0; scanPos < pAlfParam->num_coeff_chroma; scanPos++) |
---|
347 | { |
---|
348 | printf("%d ", pAlfParam->coeff_chroma[scanPos]); |
---|
349 | } |
---|
350 | printf("\n"); |
---|
351 | } |
---|
352 | |
---|
353 | /** encode merge flag |
---|
354 | * \param pcCU |
---|
355 | * \param uiAbsPartIdx |
---|
356 | * \param uiPUIdx |
---|
357 | * \returns Void |
---|
358 | */ |
---|
359 | Void TEncEntropy::encodeMergeFlag( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiPUIdx ) |
---|
360 | { |
---|
361 | UInt uiNumCand = 0; |
---|
362 | for(UInt uiIter = 0; uiIter < MRG_MAX_NUM_CANDS; uiIter++ ) |
---|
363 | { |
---|
364 | if( pcCU->getNeighbourCandIdx( uiIter, uiAbsPartIdx ) == uiIter + 1 ) |
---|
365 | { |
---|
366 | uiNumCand++; |
---|
367 | break; |
---|
368 | } |
---|
369 | } |
---|
370 | if ( uiNumCand ) |
---|
371 | { |
---|
372 | // at least one merge candidate exists |
---|
373 | m_pcEntropyCoderIf->codeMergeFlag( pcCU, uiAbsPartIdx ); |
---|
374 | } |
---|
375 | else |
---|
376 | { |
---|
377 | assert( !pcCU->getMergeFlag( uiAbsPartIdx ) ); |
---|
378 | } |
---|
379 | } |
---|
380 | |
---|
381 | #if HHI_MRG_SKIP |
---|
382 | /** encode merge index |
---|
383 | * \param pcCU |
---|
384 | * \param uiAbsPartIdx |
---|
385 | * \param uiPUIdx |
---|
386 | * \param bRD |
---|
387 | * \returns Void |
---|
388 | */ |
---|
389 | Void TEncEntropy::encodeMergeIndex( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiPUIdx, Bool bRD ) |
---|
390 | #else |
---|
391 | Void TEncEntropy::encodeMergeIndex( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiPUIdx ) |
---|
392 | #endif |
---|
393 | { |
---|
394 | #if HHI_MRG_SKIP |
---|
395 | if( bRD ) |
---|
396 | { |
---|
397 | uiAbsPartIdx = 0; |
---|
398 | assert( pcCU->getPartitionSize(uiAbsPartIdx) == SIZE_2Nx2N ); |
---|
399 | } |
---|
400 | #endif |
---|
401 | |
---|
402 | UInt uiNumCand = 0; |
---|
403 | for(UInt uiIter = 0; uiIter < MRG_MAX_NUM_CANDS; uiIter++ ) |
---|
404 | { |
---|
405 | if( pcCU->getNeighbourCandIdx( uiIter, uiAbsPartIdx ) == uiIter + 1 ) |
---|
406 | { |
---|
407 | uiNumCand++; |
---|
408 | } |
---|
409 | } |
---|
410 | #if MW_MVI_SIGNALLING_MODE == 1 |
---|
411 | if( pcCU->getSlice()->getSPS()->getUseMVI() && pcCU->getSlice()->getSliceType() != I_SLICE && pcCU->getPartitionSize( uiAbsPartIdx ) == SIZE_2Nx2N ) |
---|
412 | uiNumCand++; |
---|
413 | #endif |
---|
414 | if ( uiNumCand > 1 ) |
---|
415 | { |
---|
416 | m_pcEntropyCoderIf->codeMergeIndex( pcCU, uiAbsPartIdx ); |
---|
417 | } |
---|
418 | } |
---|
419 | |
---|
420 | |
---|
421 | Void |
---|
422 | TEncEntropy::encodeResPredFlag( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiPUIdx, Bool bRD ) |
---|
423 | { |
---|
424 | if( bRD ) |
---|
425 | { |
---|
426 | uiAbsPartIdx = 0; |
---|
427 | } |
---|
428 | |
---|
429 | // check whether flag is coded |
---|
430 | ROTVS( pcCU->getSlice()->getSPS()->isDepth () ); |
---|
431 | ROFVS( pcCU->getSlice()->getSPS()->getViewId () ); |
---|
432 | ROFVS( pcCU->getSlice()->getSPS()->getMultiviewResPredMode() ); |
---|
433 | ROTVS( pcCU->isIntra ( uiAbsPartIdx ) ); |
---|
434 | ROFVS( pcCU->getResPredAvail ( uiAbsPartIdx ) ); |
---|
435 | |
---|
436 | // encode flag |
---|
437 | m_pcEntropyCoderIf->codeResPredFlag( pcCU, uiAbsPartIdx ); |
---|
438 | } |
---|
439 | |
---|
440 | |
---|
441 | Void TEncEntropy::encodeAlfParam(ALFParam* pAlfParam) |
---|
442 | { |
---|
443 | m_pcEntropyCoderIf->codeAlfFlag(pAlfParam->alf_flag); |
---|
444 | if (!pAlfParam->alf_flag) |
---|
445 | return; |
---|
446 | Int pos; |
---|
447 | codeAux(pAlfParam); |
---|
448 | codeFilt(pAlfParam); |
---|
449 | |
---|
450 | // filter parameters for chroma |
---|
451 | m_pcEntropyCoderIf->codeAlfUvlc(pAlfParam->chroma_idc); |
---|
452 | if(pAlfParam->chroma_idc) |
---|
453 | { |
---|
454 | m_pcEntropyCoderIf->codeAlfUvlc((pAlfParam->tap_chroma-5)/2); |
---|
455 | |
---|
456 | // filter coefficients for chroma |
---|
457 | for(pos=0; pos<pAlfParam->num_coeff_chroma; pos++) |
---|
458 | { |
---|
459 | m_pcEntropyCoderIf->codeAlfSvlc(pAlfParam->coeff_chroma[pos]); |
---|
460 | } |
---|
461 | } |
---|
462 | |
---|
463 | // region control parameters for luma |
---|
464 | m_pcEntropyCoderIf->codeAlfFlag(pAlfParam->cu_control_flag); |
---|
465 | if (pAlfParam->cu_control_flag) |
---|
466 | { |
---|
467 | assert( (pAlfParam->cu_control_flag && m_pcEntropyCoderIf->getAlfCtrl()) || (!pAlfParam->cu_control_flag && !m_pcEntropyCoderIf->getAlfCtrl())); |
---|
468 | m_pcEntropyCoderIf->codeAlfCtrlDepth(); |
---|
469 | } |
---|
470 | } |
---|
471 | |
---|
472 | Void TEncEntropy::encodeAlfCtrlFlag( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool bRD ) |
---|
473 | { |
---|
474 | if( bRD ) |
---|
475 | uiAbsPartIdx = 0; |
---|
476 | |
---|
477 | m_pcEntropyCoderIf->codeAlfCtrlFlag( pcCU, uiAbsPartIdx ); |
---|
478 | } |
---|
479 | |
---|
480 | #if TSB_ALF_HEADER |
---|
481 | Void TEncEntropy::encodeAlfCtrlParam( ALFParam* pAlfParam ) |
---|
482 | { |
---|
483 | m_pcEntropyCoderIf->codeAlfFlagNum( pAlfParam->num_alf_cu_flag, pAlfParam->num_cus_in_frame ); |
---|
484 | |
---|
485 | for(UInt i=0; i<pAlfParam->num_alf_cu_flag; i++) |
---|
486 | { |
---|
487 | m_pcEntropyCoderIf->codeAlfCtrlFlag( pAlfParam->alf_cu_flag[i] ); |
---|
488 | } |
---|
489 | } |
---|
490 | #endif |
---|
491 | |
---|
492 | /** encode prediction mode |
---|
493 | * \param pcCU |
---|
494 | * \param uiAbsPartIdx |
---|
495 | * \param bRD |
---|
496 | * \returns Void |
---|
497 | */ |
---|
498 | Void TEncEntropy::encodePredMode( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool bRD ) |
---|
499 | { |
---|
500 | if( bRD ) |
---|
501 | uiAbsPartIdx = 0; |
---|
502 | |
---|
503 | if ( pcCU->getSlice()->isIntra() ) |
---|
504 | { |
---|
505 | return; |
---|
506 | } |
---|
507 | |
---|
508 | m_pcEntropyCoderIf->codePredMode( pcCU, uiAbsPartIdx ); |
---|
509 | } |
---|
510 | |
---|
511 | // Split mode |
---|
512 | Void TEncEntropy::encodeSplitFlag( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, Bool bRD ) |
---|
513 | { |
---|
514 | if( bRD ) |
---|
515 | uiAbsPartIdx = 0; |
---|
516 | |
---|
517 | m_pcEntropyCoderIf->codeSplitFlag( pcCU, uiAbsPartIdx, uiDepth ); |
---|
518 | } |
---|
519 | |
---|
520 | #if MW_MVI_SIGNALLING_MODE == 0 |
---|
521 | Void TEncEntropy::encodeMvInheritanceFlag( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, Bool bRD ) |
---|
522 | { |
---|
523 | if( bRD ) |
---|
524 | uiAbsPartIdx = 0; |
---|
525 | m_pcEntropyCoderIf->codeMvInheritanceFlag( pcCU, uiAbsPartIdx, uiDepth ); |
---|
526 | } |
---|
527 | #endif |
---|
528 | |
---|
529 | /** encode partition size |
---|
530 | * \param pcCU |
---|
531 | * \param uiAbsPartIdx |
---|
532 | * \param uiDepth |
---|
533 | * \param bRD |
---|
534 | * \returns Void |
---|
535 | */ |
---|
536 | Void TEncEntropy::encodePartSize( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, Bool bRD ) |
---|
537 | { |
---|
538 | if( bRD ) |
---|
539 | uiAbsPartIdx = 0; |
---|
540 | |
---|
541 | m_pcEntropyCoderIf->codePartSize( pcCU, uiAbsPartIdx, uiDepth ); |
---|
542 | } |
---|
543 | |
---|
544 | Void TEncEntropy::xEncodeTransformSubdiv( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, UInt uiInnerQuadIdx, UInt& uiYCbfFront3, UInt& uiUCbfFront3, UInt& uiVCbfFront3 ) |
---|
545 | { |
---|
546 | const UInt uiSubdiv = pcCU->getTransformIdx( uiAbsPartIdx ) + pcCU->getDepth( uiAbsPartIdx ) > uiDepth; |
---|
547 | const UInt uiLog2TrafoSize = g_aucConvertToBit[pcCU->getSlice()->getSPS()->getMaxCUWidth()]+2 - uiDepth; |
---|
548 | #if CAVLC_RQT_CBP |
---|
549 | if(pcCU->getSlice()->getSymbolMode() == 0) |
---|
550 | { |
---|
551 | m_pcEntropyCoderIf->codeCbfTrdiv( pcCU, uiAbsPartIdx, uiDepth ); |
---|
552 | } |
---|
553 | else |
---|
554 | {//CABAC |
---|
555 | #endif |
---|
556 | if( pcCU->getPredictionMode(uiAbsPartIdx) == MODE_INTRA && pcCU->getPartitionSize(uiAbsPartIdx) == SIZE_NxN && uiDepth == pcCU->getDepth(uiAbsPartIdx) ) |
---|
557 | { |
---|
558 | assert( uiSubdiv ); |
---|
559 | } |
---|
560 | else |
---|
561 | if( uiLog2TrafoSize > pcCU->getSlice()->getSPS()->getQuadtreeTULog2MaxSize() ) |
---|
562 | { |
---|
563 | assert( uiSubdiv ); |
---|
564 | } |
---|
565 | else if( uiLog2TrafoSize == pcCU->getSlice()->getSPS()->getQuadtreeTULog2MinSize() ) |
---|
566 | { |
---|
567 | assert( !uiSubdiv ); |
---|
568 | } |
---|
569 | else if( uiLog2TrafoSize == pcCU->getQuadtreeTULog2MinSizeInCU(uiAbsPartIdx) ) |
---|
570 | { |
---|
571 | assert( !uiSubdiv ); |
---|
572 | } |
---|
573 | else |
---|
574 | { |
---|
575 | assert( uiLog2TrafoSize > pcCU->getQuadtreeTULog2MinSizeInCU(uiAbsPartIdx) ); |
---|
576 | #if HHI_RQT_FORCE_SPLIT_ACC2_PU |
---|
577 | UInt uiCtx = uiDepth; |
---|
578 | const UInt uiTrMode = uiDepth - pcCU->getDepth( uiAbsPartIdx ); |
---|
579 | #if HHI_RQT_FORCE_SPLIT_NxN |
---|
580 | const Bool bNxNOK = pcCU->getPartitionSize( uiAbsPartIdx ) == SIZE_NxN && uiTrMode > 0; |
---|
581 | #else |
---|
582 | const Bool bNxNOK = pcCU->getPartitionSize( uiAbsPartIdx ) == SIZE_NxN; |
---|
583 | #endif |
---|
584 | #if HHI_RQT_FORCE_SPLIT_RECT |
---|
585 | const Bool bSymmetricOK = pcCU->getPartitionSize( uiAbsPartIdx ) >= SIZE_2NxN && pcCU->getPartitionSize( uiAbsPartIdx ) < SIZE_NxN && uiTrMode > 0; |
---|
586 | #else |
---|
587 | const Bool bSymmetricOK = pcCU->getPartitionSize( uiAbsPartIdx ) >= SIZE_2NxN && pcCU->getPartitionSize( uiAbsPartIdx ) < SIZE_NxN; |
---|
588 | #endif |
---|
589 | const Bool bNeedSubdivFlag = pcCU->getPartitionSize( uiAbsPartIdx ) == SIZE_2Nx2N || pcCU->getPredictionMode( uiAbsPartIdx ) == MODE_INTRA || |
---|
590 | bNxNOK || bSymmetricOK; |
---|
591 | if( bNeedSubdivFlag ) |
---|
592 | { |
---|
593 | m_pcEntropyCoderIf->codeTransformSubdivFlag( uiSubdiv, uiCtx ); |
---|
594 | } |
---|
595 | #else |
---|
596 | m_pcEntropyCoderIf->codeTransformSubdivFlag( uiSubdiv, uiDepth ); |
---|
597 | #endif |
---|
598 | } |
---|
599 | #if CAVLC_RQT_CBP |
---|
600 | } |
---|
601 | #endif |
---|
602 | |
---|
603 | if(pcCU->getSlice()->getSymbolMode() == 0) |
---|
604 | { |
---|
605 | if( uiSubdiv ) |
---|
606 | { |
---|
607 | ++uiDepth; |
---|
608 | const UInt uiQPartNum = pcCU->getPic()->getNumPartInCU() >> (uiDepth << 1); |
---|
609 | UInt uiDummyCbfY = 0; |
---|
610 | UInt uiDummyCbfU = 0; |
---|
611 | UInt uiDummyCbfV = 0; |
---|
612 | xEncodeTransformSubdiv( pcCU, uiAbsPartIdx, uiDepth, 0, uiDummyCbfY, uiDummyCbfU, uiDummyCbfV ); |
---|
613 | uiAbsPartIdx += uiQPartNum; |
---|
614 | xEncodeTransformSubdiv( pcCU, uiAbsPartIdx, uiDepth, 1, uiDummyCbfY, uiDummyCbfU, uiDummyCbfV ); |
---|
615 | uiAbsPartIdx += uiQPartNum; |
---|
616 | xEncodeTransformSubdiv( pcCU, uiAbsPartIdx, uiDepth, 2, uiDummyCbfY, uiDummyCbfU, uiDummyCbfV ); |
---|
617 | uiAbsPartIdx += uiQPartNum; |
---|
618 | xEncodeTransformSubdiv( pcCU, uiAbsPartIdx, uiDepth, 3, uiDummyCbfY, uiDummyCbfU, uiDummyCbfV ); |
---|
619 | } |
---|
620 | } |
---|
621 | else |
---|
622 | { |
---|
623 | if( pcCU->getPredictionMode(uiAbsPartIdx) != MODE_INTRA && uiLog2TrafoSize <= pcCU->getSlice()->getSPS()->getQuadtreeTULog2MaxSize() ) |
---|
624 | { |
---|
625 | const UInt uiTrDepthCurr = uiDepth - pcCU->getDepth( uiAbsPartIdx ); |
---|
626 | const Bool bFirstCbfOfCU = uiLog2TrafoSize == pcCU->getSlice()->getSPS()->getQuadtreeTULog2MaxSize() || uiTrDepthCurr == 0; |
---|
627 | if( bFirstCbfOfCU || uiLog2TrafoSize > pcCU->getSlice()->getSPS()->getQuadtreeTULog2MinSize() ) |
---|
628 | { |
---|
629 | if( bFirstCbfOfCU || pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_U, uiTrDepthCurr - 1 ) ) |
---|
630 | { |
---|
631 | if ( uiInnerQuadIdx == 3 && uiUCbfFront3 == 0 && uiLog2TrafoSize < pcCU->getSlice()->getSPS()->getQuadtreeTULog2MaxSize() ) |
---|
632 | { |
---|
633 | uiUCbfFront3++; |
---|
634 | } |
---|
635 | else |
---|
636 | { |
---|
637 | m_pcEntropyCoderIf->codeQtCbf( pcCU, uiAbsPartIdx, TEXT_CHROMA_U, uiTrDepthCurr ); |
---|
638 | uiUCbfFront3 += pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_U, uiTrDepthCurr ); |
---|
639 | } |
---|
640 | } |
---|
641 | if( bFirstCbfOfCU || pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_V, uiTrDepthCurr - 1 ) ) |
---|
642 | { |
---|
643 | if ( uiInnerQuadIdx == 3 && uiVCbfFront3 == 0 && uiLog2TrafoSize < pcCU->getSlice()->getSPS()->getQuadtreeTULog2MaxSize() ) |
---|
644 | { |
---|
645 | uiVCbfFront3++; |
---|
646 | } |
---|
647 | else |
---|
648 | { |
---|
649 | m_pcEntropyCoderIf->codeQtCbf( pcCU, uiAbsPartIdx, TEXT_CHROMA_V, uiTrDepthCurr ); |
---|
650 | uiVCbfFront3 += pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_V, uiTrDepthCurr ); |
---|
651 | } |
---|
652 | } |
---|
653 | } |
---|
654 | else if( uiLog2TrafoSize == pcCU->getSlice()->getSPS()->getQuadtreeTULog2MinSize() ) |
---|
655 | { |
---|
656 | assert( pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_U, uiTrDepthCurr ) == pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_U, uiTrDepthCurr - 1 ) ); |
---|
657 | assert( pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_V, uiTrDepthCurr ) == pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_V, uiTrDepthCurr - 1 ) ); |
---|
658 | |
---|
659 | uiUCbfFront3 += pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_U, uiTrDepthCurr ); |
---|
660 | uiVCbfFront3 += pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_V, uiTrDepthCurr ); |
---|
661 | } |
---|
662 | } |
---|
663 | |
---|
664 | if( uiSubdiv ) |
---|
665 | { |
---|
666 | ++uiDepth; |
---|
667 | const UInt uiQPartNum = pcCU->getPic()->getNumPartInCU() >> (uiDepth << 1); |
---|
668 | |
---|
669 | UInt uiCurrentCbfY = 0; |
---|
670 | UInt uiCurrentCbfU = 0; |
---|
671 | UInt uiCurrentCbfV = 0; |
---|
672 | |
---|
673 | xEncodeTransformSubdiv( pcCU, uiAbsPartIdx, uiDepth, 0, uiCurrentCbfY, uiCurrentCbfU, uiCurrentCbfV ); |
---|
674 | uiAbsPartIdx += uiQPartNum; |
---|
675 | xEncodeTransformSubdiv( pcCU, uiAbsPartIdx, uiDepth, 1, uiCurrentCbfY, uiCurrentCbfU, uiCurrentCbfV ); |
---|
676 | uiAbsPartIdx += uiQPartNum; |
---|
677 | xEncodeTransformSubdiv( pcCU, uiAbsPartIdx, uiDepth, 2, uiCurrentCbfY, uiCurrentCbfU, uiCurrentCbfV ); |
---|
678 | uiAbsPartIdx += uiQPartNum; |
---|
679 | xEncodeTransformSubdiv( pcCU, uiAbsPartIdx, uiDepth, 3, uiCurrentCbfY, uiCurrentCbfU, uiCurrentCbfV ); |
---|
680 | |
---|
681 | uiYCbfFront3 += uiCurrentCbfY; |
---|
682 | uiUCbfFront3 += uiCurrentCbfU; |
---|
683 | uiVCbfFront3 += uiCurrentCbfV; |
---|
684 | } |
---|
685 | else |
---|
686 | { |
---|
687 | { |
---|
688 | DTRACE_CABAC_V( g_nSymbolCounter++ ); |
---|
689 | DTRACE_CABAC_T( "\tTrIdx: abspart=" ); |
---|
690 | DTRACE_CABAC_V( uiAbsPartIdx ); |
---|
691 | DTRACE_CABAC_T( "\tdepth=" ); |
---|
692 | DTRACE_CABAC_V( uiDepth ); |
---|
693 | DTRACE_CABAC_T( "\ttrdepth=" ); |
---|
694 | DTRACE_CABAC_V( pcCU->getTransformIdx( uiAbsPartIdx ) ); |
---|
695 | DTRACE_CABAC_T( "\n" ); |
---|
696 | } |
---|
697 | UInt uiLumaTrMode, uiChromaTrMode; |
---|
698 | pcCU->convertTransIdx( uiAbsPartIdx, pcCU->getTransformIdx( uiAbsPartIdx ), uiLumaTrMode, uiChromaTrMode ); |
---|
699 | if( pcCU->getPredictionMode(uiAbsPartIdx) != MODE_INTRA && uiDepth == pcCU->getDepth( uiAbsPartIdx ) && !pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_U, 0 ) && !pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_V, 0 ) ) |
---|
700 | { |
---|
701 | assert( pcCU->getCbf( uiAbsPartIdx, TEXT_LUMA, 0 ) ); |
---|
702 | // printf( "saved one bin! " ); |
---|
703 | } |
---|
704 | else |
---|
705 | { |
---|
706 | if ( pcCU->getPredictionMode( uiAbsPartIdx ) != MODE_INTRA && uiInnerQuadIdx == 3 && uiYCbfFront3 == 0 && uiUCbfFront3 == 0 && uiVCbfFront3 == 0 |
---|
707 | && uiLog2TrafoSize < pcCU->getSlice()->getSPS()->getQuadtreeTULog2MaxSize() && pcCU->getCbf( uiAbsPartIdx, TEXT_LUMA, uiLumaTrMode ) ) |
---|
708 | { |
---|
709 | uiYCbfFront3++; |
---|
710 | } |
---|
711 | else |
---|
712 | { |
---|
713 | m_pcEntropyCoderIf->codeQtCbf( pcCU, uiAbsPartIdx, TEXT_LUMA, uiLumaTrMode ); |
---|
714 | uiYCbfFront3 += pcCU->getCbf( uiAbsPartIdx, TEXT_LUMA, uiLumaTrMode ); |
---|
715 | } |
---|
716 | } |
---|
717 | |
---|
718 | if( pcCU->getPredictionMode(uiAbsPartIdx) == MODE_INTRA ) |
---|
719 | { |
---|
720 | Bool bCodeChroma = true; |
---|
721 | if( uiLog2TrafoSize == pcCU->getSlice()->getSPS()->getQuadtreeTULog2MinSize() ) |
---|
722 | { |
---|
723 | UInt uiQPDiv = pcCU->getPic()->getNumPartInCU() >> ( ( uiDepth - 1 ) << 1 ); |
---|
724 | bCodeChroma = ( ( uiAbsPartIdx % uiQPDiv ) == 0 ); |
---|
725 | } |
---|
726 | if( bCodeChroma ) |
---|
727 | { |
---|
728 | m_pcEntropyCoderIf->codeQtCbf( pcCU, uiAbsPartIdx, TEXT_CHROMA_U, uiChromaTrMode ); |
---|
729 | m_pcEntropyCoderIf->codeQtCbf( pcCU, uiAbsPartIdx, TEXT_CHROMA_V, uiChromaTrMode ); |
---|
730 | } |
---|
731 | } |
---|
732 | } |
---|
733 | } |
---|
734 | } |
---|
735 | |
---|
736 | // transform index |
---|
737 | Void TEncEntropy::encodeTransformIdx( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, Bool bRD ) |
---|
738 | { |
---|
739 | assert( !bRD ); // parameter bRD can be removed |
---|
740 | if( bRD ) |
---|
741 | uiAbsPartIdx = 0; |
---|
742 | |
---|
743 | DTRACE_CABAC_V( g_nSymbolCounter++ ) |
---|
744 | DTRACE_CABAC_T( "\tdecodeTransformIdx()\tCUDepth=" ) |
---|
745 | DTRACE_CABAC_V( uiDepth ) |
---|
746 | DTRACE_CABAC_T( "\n" ) |
---|
747 | UInt temp = 0; |
---|
748 | UInt temp1 = 0; |
---|
749 | UInt temp2 = 0; |
---|
750 | xEncodeTransformSubdiv( pcCU, uiAbsPartIdx, uiDepth, 0, temp, temp1, temp2 ); |
---|
751 | } |
---|
752 | |
---|
753 | // Intra direction for Luma |
---|
754 | Void TEncEntropy::encodeIntraDirModeLuma ( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
755 | { |
---|
756 | m_pcEntropyCoderIf->codeIntraDirLumaAng( pcCU, uiAbsPartIdx ); |
---|
757 | } |
---|
758 | |
---|
759 | // Intra direction for Chroma |
---|
760 | Void TEncEntropy::encodeIntraDirModeChroma( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool bRD ) |
---|
761 | { |
---|
762 | if( bRD ) |
---|
763 | uiAbsPartIdx = 0; |
---|
764 | |
---|
765 | m_pcEntropyCoderIf->codeIntraDirChroma( pcCU, uiAbsPartIdx ); |
---|
766 | } |
---|
767 | |
---|
768 | Void TEncEntropy::encodePredInfo( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool bRD ) |
---|
769 | { |
---|
770 | if( bRD ) |
---|
771 | uiAbsPartIdx = 0; |
---|
772 | |
---|
773 | PartSize eSize = pcCU->getPartitionSize( uiAbsPartIdx ); |
---|
774 | |
---|
775 | if( pcCU->isIntra( uiAbsPartIdx ) ) // If it is Intra mode, encode intra prediction mode. |
---|
776 | { |
---|
777 | if( eSize == SIZE_NxN ) // if it is NxN size, encode 4 intra directions. |
---|
778 | { |
---|
779 | UInt uiPartOffset = ( pcCU->getPic()->getNumPartInCU() >> ( pcCU->getDepth(uiAbsPartIdx) << 1 ) ) >> 2; |
---|
780 | // if it is NxN size, this size might be the smallest partition size. |
---|
781 | encodeIntraDirModeLuma( pcCU, uiAbsPartIdx ); |
---|
782 | encodeIntraDirModeLuma( pcCU, uiAbsPartIdx + uiPartOffset ); |
---|
783 | encodeIntraDirModeLuma( pcCU, uiAbsPartIdx + uiPartOffset*2 ); |
---|
784 | encodeIntraDirModeLuma( pcCU, uiAbsPartIdx + uiPartOffset*3 ); |
---|
785 | encodeIntraDirModeChroma( pcCU, uiAbsPartIdx, bRD ); |
---|
786 | } |
---|
787 | else // if it is not NxN size, encode 1 intra directions |
---|
788 | { |
---|
789 | encodeIntraDirModeLuma ( pcCU, uiAbsPartIdx ); |
---|
790 | encodeIntraDirModeChroma( pcCU, uiAbsPartIdx, bRD ); |
---|
791 | } |
---|
792 | } |
---|
793 | else // if it is Inter mode, encode motion vector and reference index |
---|
794 | { |
---|
795 | if ( pcCU->getSlice()->getSPS()->getUseMRG() ) |
---|
796 | { |
---|
797 | encodePUWise( pcCU, uiAbsPartIdx, bRD ); |
---|
798 | } |
---|
799 | else |
---|
800 | { |
---|
801 | #if MS_LCEC_LOOKUP_TABLE_EXCEPTION |
---|
802 | if ( pcCU->getSlice()->getSymbolMode() == 0 ) |
---|
803 | { |
---|
804 | if ( pcCU->isSuroundingRefIdxException( uiAbsPartIdx ) ) |
---|
805 | { |
---|
806 | pcCU->getSlice()->setRefIdxCombineCoding( false ); |
---|
807 | } |
---|
808 | else |
---|
809 | { |
---|
810 | pcCU->getSlice()->setRefIdxCombineCoding( true ); |
---|
811 | } |
---|
812 | } |
---|
813 | #endif |
---|
814 | encodeInterDir( pcCU, uiAbsPartIdx, bRD ); |
---|
815 | |
---|
816 | { |
---|
817 | if ( pcCU->getSlice()->getNumRefIdx( REF_PIC_LIST_0 ) > 0 ) // if ( ref. frame list0 has at least 1 entry ) |
---|
818 | { |
---|
819 | encodeRefFrmIdx ( pcCU, uiAbsPartIdx, REF_PIC_LIST_0, bRD ); |
---|
820 | encodeMvd ( pcCU, uiAbsPartIdx, REF_PIC_LIST_0, bRD ); |
---|
821 | encodeMVPIdx ( pcCU, uiAbsPartIdx, REF_PIC_LIST_0 ); |
---|
822 | } |
---|
823 | |
---|
824 | if ( pcCU->getSlice()->getNumRefIdx( REF_PIC_LIST_1 ) > 0 ) // if ( ref. frame list1 has at least 1 entry ) |
---|
825 | { |
---|
826 | encodeRefFrmIdx ( pcCU, uiAbsPartIdx, REF_PIC_LIST_1, bRD ); |
---|
827 | encodeMvd ( pcCU, uiAbsPartIdx, REF_PIC_LIST_1, bRD ); |
---|
828 | encodeMVPIdx ( pcCU, uiAbsPartIdx, REF_PIC_LIST_1 ); |
---|
829 | } |
---|
830 | } |
---|
831 | } |
---|
832 | } |
---|
833 | } |
---|
834 | |
---|
835 | /** encode inter direction |
---|
836 | * \param pcCU |
---|
837 | * \param uiAbsPartIdx |
---|
838 | * \param bRD |
---|
839 | * \returns Void |
---|
840 | */ |
---|
841 | Void TEncEntropy::encodeInterDir( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool bRD ) |
---|
842 | { |
---|
843 | assert( !pcCU->isIntra( uiAbsPartIdx ) ); |
---|
844 | assert( pcCU->getSlice()->isInterB()); |
---|
845 | |
---|
846 | if( bRD ) |
---|
847 | uiAbsPartIdx = 0; |
---|
848 | |
---|
849 | if ( !pcCU->getSlice()->isInterB() ) |
---|
850 | { |
---|
851 | return; |
---|
852 | } |
---|
853 | |
---|
854 | UInt uiPartOffset = ( pcCU->getPic()->getNumPartInCU() >> ( pcCU->getDepth(uiAbsPartIdx) << 1 ) ) >> 2; |
---|
855 | |
---|
856 | switch ( pcCU->getPartitionSize( uiAbsPartIdx ) ) |
---|
857 | { |
---|
858 | case SIZE_2Nx2N: |
---|
859 | { |
---|
860 | m_pcEntropyCoderIf->codeInterDir( pcCU, uiAbsPartIdx ); |
---|
861 | break; |
---|
862 | } |
---|
863 | |
---|
864 | case SIZE_2NxN: |
---|
865 | { |
---|
866 | m_pcEntropyCoderIf->codeInterDir( pcCU, uiAbsPartIdx ); |
---|
867 | uiAbsPartIdx += uiPartOffset << 1; |
---|
868 | m_pcEntropyCoderIf->codeInterDir( pcCU, uiAbsPartIdx ); |
---|
869 | break; |
---|
870 | } |
---|
871 | |
---|
872 | case SIZE_Nx2N: |
---|
873 | { |
---|
874 | m_pcEntropyCoderIf->codeInterDir( pcCU, uiAbsPartIdx ); |
---|
875 | uiAbsPartIdx += uiPartOffset; |
---|
876 | m_pcEntropyCoderIf->codeInterDir( pcCU, uiAbsPartIdx ); |
---|
877 | break; |
---|
878 | } |
---|
879 | |
---|
880 | case SIZE_NxN: |
---|
881 | { |
---|
882 | for ( Int iPartIdx = 0; iPartIdx < 4; iPartIdx++ ) |
---|
883 | { |
---|
884 | m_pcEntropyCoderIf->codeInterDir( pcCU, uiAbsPartIdx ); |
---|
885 | uiAbsPartIdx += uiPartOffset; |
---|
886 | } |
---|
887 | break; |
---|
888 | } |
---|
889 | default: |
---|
890 | break; |
---|
891 | } |
---|
892 | |
---|
893 | return; |
---|
894 | } |
---|
895 | |
---|
896 | /** encode motion information for every PU block |
---|
897 | * \param pcCU |
---|
898 | * \param uiAbsPartIdx |
---|
899 | * \param bRD |
---|
900 | * \returns Void |
---|
901 | * This function is called only if merge is enabled. |
---|
902 | */ |
---|
903 | Void TEncEntropy::encodePUWise( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool bRD ) |
---|
904 | { |
---|
905 | if ( bRD ) |
---|
906 | uiAbsPartIdx = 0; |
---|
907 | |
---|
908 | PartSize ePartSize = pcCU->getPartitionSize( uiAbsPartIdx ); |
---|
909 | UInt uiNumPU = ( ePartSize == SIZE_2Nx2N ? 1 : ( ePartSize == SIZE_NxN ? 4 : 2 ) ); |
---|
910 | UInt uiDepth = pcCU->getDepth( uiAbsPartIdx ); |
---|
911 | UInt uiPUOffset = ( g_auiPUOffset[UInt( ePartSize )] << ( ( pcCU->getSlice()->getSPS()->getMaxCUDepth() - uiDepth ) << 1 ) ) >> 4; |
---|
912 | |
---|
913 | for ( UInt uiPartIdx = 0, uiSubPartIdx = uiAbsPartIdx; uiPartIdx < uiNumPU; uiPartIdx++, uiSubPartIdx += uiPUOffset ) |
---|
914 | { |
---|
915 | #if PART_MRG |
---|
916 | if (pcCU->getWidth( uiAbsPartIdx ) <= 8 || uiNumPU != 2 || uiPartIdx != 0) |
---|
917 | #endif |
---|
918 | encodeMergeFlag( pcCU, uiSubPartIdx, uiPartIdx ); |
---|
919 | if ( pcCU->getMergeFlag( uiSubPartIdx ) ) |
---|
920 | { |
---|
921 | encodeMergeIndex( pcCU, uiSubPartIdx, uiPartIdx ); |
---|
922 | } |
---|
923 | else |
---|
924 | { |
---|
925 | #if MS_LCEC_LOOKUP_TABLE_EXCEPTION |
---|
926 | if ( pcCU->getSlice()->getSymbolMode() == 0 ) |
---|
927 | { |
---|
928 | if ( pcCU->isSuroundingRefIdxException( uiAbsPartIdx ) ) |
---|
929 | { |
---|
930 | pcCU->getSlice()->setRefIdxCombineCoding( false ); |
---|
931 | } |
---|
932 | else |
---|
933 | { |
---|
934 | pcCU->getSlice()->setRefIdxCombineCoding( true ); |
---|
935 | } |
---|
936 | } |
---|
937 | #endif |
---|
938 | encodeInterDirPU( pcCU, uiSubPartIdx ); |
---|
939 | for ( UInt uiRefListIdx = 0; uiRefListIdx < 2; uiRefListIdx++ ) |
---|
940 | { |
---|
941 | if ( pcCU->getSlice()->getNumRefIdx( RefPicList( uiRefListIdx ) ) > 0 ) |
---|
942 | { |
---|
943 | encodeRefFrmIdxPU ( pcCU, uiSubPartIdx, RefPicList( uiRefListIdx ) ); |
---|
944 | encodeMvdPU ( pcCU, uiSubPartIdx, RefPicList( uiRefListIdx ) ); |
---|
945 | encodeMVPIdxPU ( pcCU, uiSubPartIdx, RefPicList( uiRefListIdx ) ); |
---|
946 | } |
---|
947 | } |
---|
948 | } |
---|
949 | } |
---|
950 | |
---|
951 | return; |
---|
952 | } |
---|
953 | |
---|
954 | Void TEncEntropy::encodeInterDirPU( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
955 | { |
---|
956 | if ( !pcCU->getSlice()->isInterB() ) |
---|
957 | { |
---|
958 | return; |
---|
959 | } |
---|
960 | |
---|
961 | m_pcEntropyCoderIf->codeInterDir( pcCU, uiAbsPartIdx ); |
---|
962 | return; |
---|
963 | } |
---|
964 | |
---|
965 | /** encode reference frame index for a PU block |
---|
966 | * \param pcCU |
---|
967 | * \param uiAbsPartIdx |
---|
968 | * \param eRefList |
---|
969 | * \returns Void |
---|
970 | */ |
---|
971 | Void TEncEntropy::encodeRefFrmIdxPU( TComDataCU* pcCU, UInt uiAbsPartIdx, RefPicList eRefList ) |
---|
972 | { |
---|
973 | assert( !pcCU->isIntra( uiAbsPartIdx ) ); |
---|
974 | |
---|
975 | #if DCM_COMB_LIST |
---|
976 | if(pcCU->getSlice()->getNumRefIdx(REF_PIC_LIST_C)>0 && pcCU->getInterDir( uiAbsPartIdx ) != 3) |
---|
977 | { |
---|
978 | if ((eRefList== REF_PIC_LIST_1) || ( pcCU->getSlice()->getNumRefIdx( REF_PIC_LIST_C ) == 1 ) ) |
---|
979 | { |
---|
980 | return; |
---|
981 | } |
---|
982 | |
---|
983 | if ( pcCU->getSlice()->getNumRefIdx ( REF_PIC_LIST_C ) > 1 ) |
---|
984 | { |
---|
985 | m_pcEntropyCoderIf->codeRefFrmIdx( pcCU, uiAbsPartIdx, RefPicList(pcCU->getInterDir( uiAbsPartIdx )-1) ); |
---|
986 | } |
---|
987 | |
---|
988 | } |
---|
989 | else |
---|
990 | { |
---|
991 | #endif |
---|
992 | |
---|
993 | if ( ( pcCU->getSlice()->getNumRefIdx( eRefList ) == 1 ) ) |
---|
994 | { |
---|
995 | return; |
---|
996 | } |
---|
997 | |
---|
998 | if ( pcCU->getInterDir( uiAbsPartIdx ) & ( 1 << eRefList ) ) |
---|
999 | { |
---|
1000 | m_pcEntropyCoderIf->codeRefFrmIdx( pcCU, uiAbsPartIdx, eRefList ); |
---|
1001 | } |
---|
1002 | |
---|
1003 | #if DCM_COMB_LIST |
---|
1004 | } |
---|
1005 | #endif |
---|
1006 | |
---|
1007 | return; |
---|
1008 | } |
---|
1009 | |
---|
1010 | /** encode motion vector difference for a PU block |
---|
1011 | * \param pcCU |
---|
1012 | * \param uiAbsPartIdx |
---|
1013 | * \param eRefList |
---|
1014 | * \returns Void |
---|
1015 | */ |
---|
1016 | Void TEncEntropy::encodeMvdPU( TComDataCU* pcCU, UInt uiAbsPartIdx, RefPicList eRefList ) |
---|
1017 | { |
---|
1018 | assert( !pcCU->isIntra( uiAbsPartIdx ) ); |
---|
1019 | |
---|
1020 | if ( pcCU->getInterDir( uiAbsPartIdx ) & ( 1 << eRefList ) ) |
---|
1021 | { |
---|
1022 | m_pcEntropyCoderIf->codeMvd( pcCU, uiAbsPartIdx, eRefList ); |
---|
1023 | } |
---|
1024 | return; |
---|
1025 | } |
---|
1026 | |
---|
1027 | Void TEncEntropy::encodeMVPIdxPU( TComDataCU* pcCU, UInt uiAbsPartIdx, RefPicList eRefList ) |
---|
1028 | { |
---|
1029 | if ( (pcCU->getInterDir( uiAbsPartIdx ) & ( 1 << eRefList )) && (pcCU->getMVPNum(eRefList, uiAbsPartIdx)> 1) && (pcCU->getAMVPMode(uiAbsPartIdx) == AM_EXPL) ) |
---|
1030 | { |
---|
1031 | m_pcEntropyCoderIf->codeMVPIdx( pcCU, uiAbsPartIdx, eRefList ); |
---|
1032 | } |
---|
1033 | |
---|
1034 | return; |
---|
1035 | } |
---|
1036 | |
---|
1037 | Void TEncEntropy::encodeMVPIdx( TComDataCU* pcCU, UInt uiAbsPartIdx, RefPicList eRefList, Bool bRD ) |
---|
1038 | { |
---|
1039 | if( bRD ) |
---|
1040 | uiAbsPartIdx = 0; |
---|
1041 | |
---|
1042 | UInt uiPartOffset = ( pcCU->getPic()->getNumPartInCU() >> ( pcCU->getDepth(uiAbsPartIdx) << 1 ) ) >> 2; |
---|
1043 | |
---|
1044 | switch ( pcCU->getPartitionSize( uiAbsPartIdx ) ) |
---|
1045 | { |
---|
1046 | case SIZE_2Nx2N: |
---|
1047 | { |
---|
1048 | if ( (pcCU->getInterDir( uiAbsPartIdx ) & ( 1 << eRefList )) && (pcCU->getMVPNum(eRefList, uiAbsPartIdx)> 1) && (pcCU->getAMVPMode(uiAbsPartIdx) == AM_EXPL) ) |
---|
1049 | { |
---|
1050 | m_pcEntropyCoderIf->codeMVPIdx( pcCU, uiAbsPartIdx, eRefList ); |
---|
1051 | } |
---|
1052 | break; |
---|
1053 | } |
---|
1054 | |
---|
1055 | case SIZE_2NxN: |
---|
1056 | { |
---|
1057 | if ( (pcCU->getInterDir( uiAbsPartIdx ) & ( 1 << eRefList )) && (pcCU->getMVPNum(eRefList, uiAbsPartIdx)> 1) && (pcCU->getAMVPMode(uiAbsPartIdx) == AM_EXPL) ) |
---|
1058 | { |
---|
1059 | m_pcEntropyCoderIf->codeMVPIdx( pcCU, uiAbsPartIdx, eRefList ); |
---|
1060 | } |
---|
1061 | uiAbsPartIdx += uiPartOffset << 1; |
---|
1062 | if ( (pcCU->getInterDir( uiAbsPartIdx ) & ( 1 << eRefList )) && (pcCU->getMVPNum(eRefList, uiAbsPartIdx)> 1) && (pcCU->getAMVPMode(uiAbsPartIdx) == AM_EXPL) ) |
---|
1063 | { |
---|
1064 | m_pcEntropyCoderIf->codeMVPIdx( pcCU, uiAbsPartIdx, eRefList ); |
---|
1065 | } |
---|
1066 | break; |
---|
1067 | } |
---|
1068 | |
---|
1069 | case SIZE_Nx2N: |
---|
1070 | { |
---|
1071 | if ( (pcCU->getInterDir( uiAbsPartIdx ) & ( 1 << eRefList )) && (pcCU->getMVPNum(eRefList, uiAbsPartIdx)> 1) && (pcCU->getAMVPMode(uiAbsPartIdx) == AM_EXPL) ) |
---|
1072 | { |
---|
1073 | m_pcEntropyCoderIf->codeMVPIdx( pcCU, uiAbsPartIdx, eRefList ); |
---|
1074 | } |
---|
1075 | |
---|
1076 | uiAbsPartIdx += uiPartOffset; |
---|
1077 | if ( (pcCU->getInterDir( uiAbsPartIdx ) & ( 1 << eRefList )) && (pcCU->getMVPNum(eRefList, uiAbsPartIdx)> 1) && (pcCU->getAMVPMode(uiAbsPartIdx) == AM_EXPL) ) |
---|
1078 | { |
---|
1079 | m_pcEntropyCoderIf->codeMVPIdx( pcCU, uiAbsPartIdx, eRefList ); |
---|
1080 | } |
---|
1081 | |
---|
1082 | break; |
---|
1083 | } |
---|
1084 | |
---|
1085 | case SIZE_NxN: |
---|
1086 | { |
---|
1087 | for ( Int iPartIdx = 0; iPartIdx < 4; iPartIdx++ ) |
---|
1088 | { |
---|
1089 | if ( (pcCU->getInterDir( uiAbsPartIdx ) & ( 1 << eRefList )) && (pcCU->getMVPNum(eRefList, uiAbsPartIdx)> 1) && (pcCU->getAMVPMode(uiAbsPartIdx) == AM_EXPL) ) |
---|
1090 | { |
---|
1091 | m_pcEntropyCoderIf->codeMVPIdx( pcCU, uiAbsPartIdx, eRefList ); |
---|
1092 | } |
---|
1093 | uiAbsPartIdx += uiPartOffset; |
---|
1094 | } |
---|
1095 | break; |
---|
1096 | } |
---|
1097 | default: |
---|
1098 | break; |
---|
1099 | } |
---|
1100 | |
---|
1101 | return; |
---|
1102 | |
---|
1103 | } |
---|
1104 | |
---|
1105 | Void TEncEntropy::encodeViewIdx(Int iViewIdx ) |
---|
1106 | { |
---|
1107 | m_pcEntropyCoderIf->codeViewIdx(iViewIdx); |
---|
1108 | } |
---|
1109 | |
---|
1110 | /** encode reference frame index |
---|
1111 | * \param pcCU |
---|
1112 | * \param uiAbsPartIdx |
---|
1113 | * \param eRefList |
---|
1114 | * \param bRD |
---|
1115 | * \returns Void |
---|
1116 | */ |
---|
1117 | Void TEncEntropy::encodeRefFrmIdx( TComDataCU* pcCU, UInt uiAbsPartIdx, RefPicList eRefList, Bool bRD ) |
---|
1118 | { |
---|
1119 | assert( !pcCU->isIntra( uiAbsPartIdx ) ); |
---|
1120 | |
---|
1121 | if( bRD ) |
---|
1122 | uiAbsPartIdx = 0; |
---|
1123 | |
---|
1124 | #if DCM_COMB_LIST |
---|
1125 | if(pcCU->getSlice()->getNumRefIdx(REF_PIC_LIST_C) > 0) |
---|
1126 | { |
---|
1127 | UInt uiPartOffset = ( pcCU->getPic()->getNumPartInCU() >> ( pcCU->getDepth(uiAbsPartIdx) << 1 ) ) >> 2; |
---|
1128 | |
---|
1129 | switch ( pcCU->getPartitionSize( uiAbsPartIdx ) ) |
---|
1130 | { |
---|
1131 | case SIZE_2Nx2N: |
---|
1132 | { |
---|
1133 | if ( pcCU->getInterDir( uiAbsPartIdx ) != 3 && eRefList== REF_PIC_LIST_0 && pcCU->getSlice()->getNumRefIdx( REF_PIC_LIST_C ) > 1) |
---|
1134 | { |
---|
1135 | if ( pcCU->getSlice()->getNumRefIdx ( REF_PIC_LIST_C ) > 1 ) |
---|
1136 | { |
---|
1137 | m_pcEntropyCoderIf->codeRefFrmIdx( pcCU, uiAbsPartIdx, RefPicList(pcCU->getInterDir( uiAbsPartIdx )-1) ); |
---|
1138 | } |
---|
1139 | } |
---|
1140 | else if (pcCU->getInterDir( uiAbsPartIdx ) == 3 && pcCU->getSlice()->getNumRefIdx( eRefList ) > 1) |
---|
1141 | { |
---|
1142 | if ( pcCU->getInterDir( uiAbsPartIdx ) & ( 1 << eRefList ) ) |
---|
1143 | { |
---|
1144 | m_pcEntropyCoderIf->codeRefFrmIdx( pcCU, uiAbsPartIdx, eRefList ); |
---|
1145 | } |
---|
1146 | } |
---|
1147 | break; |
---|
1148 | } |
---|
1149 | case SIZE_2NxN: |
---|
1150 | { |
---|
1151 | if ( pcCU->getInterDir( uiAbsPartIdx ) != 3 && eRefList== REF_PIC_LIST_0 && pcCU->getSlice()->getNumRefIdx( REF_PIC_LIST_C ) > 1) |
---|
1152 | { |
---|
1153 | if ( pcCU->getSlice()->getNumRefIdx ( REF_PIC_LIST_C ) > 1 ) |
---|
1154 | { |
---|
1155 | m_pcEntropyCoderIf->codeRefFrmIdx( pcCU, uiAbsPartIdx, RefPicList(pcCU->getInterDir( uiAbsPartIdx )-1) ); |
---|
1156 | } |
---|
1157 | } |
---|
1158 | else if (pcCU->getInterDir( uiAbsPartIdx ) == 3 && pcCU->getSlice()->getNumRefIdx( eRefList ) > 1) |
---|
1159 | { |
---|
1160 | if ( pcCU->getInterDir( uiAbsPartIdx ) & ( 1 << eRefList ) ) |
---|
1161 | { |
---|
1162 | m_pcEntropyCoderIf->codeRefFrmIdx( pcCU, uiAbsPartIdx, eRefList ); |
---|
1163 | } |
---|
1164 | } |
---|
1165 | |
---|
1166 | uiAbsPartIdx += uiPartOffset << 1; |
---|
1167 | |
---|
1168 | if ( pcCU->getInterDir( uiAbsPartIdx ) != 3 && eRefList== REF_PIC_LIST_0 && pcCU->getSlice()->getNumRefIdx( REF_PIC_LIST_C ) > 1) |
---|
1169 | { |
---|
1170 | if ( pcCU->getSlice()->getNumRefIdx ( REF_PIC_LIST_C ) > 1 ) |
---|
1171 | { |
---|
1172 | m_pcEntropyCoderIf->codeRefFrmIdx( pcCU, uiAbsPartIdx, RefPicList(pcCU->getInterDir( uiAbsPartIdx )-1) ); |
---|
1173 | } |
---|
1174 | } |
---|
1175 | else if (pcCU->getInterDir( uiAbsPartIdx ) == 3 && pcCU->getSlice()->getNumRefIdx( eRefList ) > 1) |
---|
1176 | { |
---|
1177 | if ( pcCU->getInterDir( uiAbsPartIdx ) & ( 1 << eRefList ) ) |
---|
1178 | { |
---|
1179 | m_pcEntropyCoderIf->codeRefFrmIdx( pcCU, uiAbsPartIdx, eRefList ); |
---|
1180 | } |
---|
1181 | } |
---|
1182 | break; |
---|
1183 | } |
---|
1184 | case SIZE_Nx2N: |
---|
1185 | { |
---|
1186 | if ( pcCU->getInterDir( uiAbsPartIdx ) != 3 && eRefList== REF_PIC_LIST_0 && pcCU->getSlice()->getNumRefIdx( REF_PIC_LIST_C ) > 1) |
---|
1187 | { |
---|
1188 | if ( pcCU->getSlice()->getNumRefIdx ( REF_PIC_LIST_C ) > 1 ) |
---|
1189 | { |
---|
1190 | m_pcEntropyCoderIf->codeRefFrmIdx( pcCU, uiAbsPartIdx, RefPicList(pcCU->getInterDir( uiAbsPartIdx )-1) ); |
---|
1191 | } |
---|
1192 | } |
---|
1193 | else if (pcCU->getInterDir( uiAbsPartIdx ) == 3 && pcCU->getSlice()->getNumRefIdx( eRefList ) > 1) |
---|
1194 | { |
---|
1195 | if ( pcCU->getInterDir( uiAbsPartIdx ) & ( 1 << eRefList ) ) |
---|
1196 | { |
---|
1197 | m_pcEntropyCoderIf->codeRefFrmIdx( pcCU, uiAbsPartIdx, eRefList ); |
---|
1198 | } |
---|
1199 | } |
---|
1200 | |
---|
1201 | uiAbsPartIdx += uiPartOffset; |
---|
1202 | |
---|
1203 | if ( pcCU->getInterDir( uiAbsPartIdx ) != 3 && eRefList== REF_PIC_LIST_0 && pcCU->getSlice()->getNumRefIdx( REF_PIC_LIST_C ) > 1) |
---|
1204 | { |
---|
1205 | if ( pcCU->getSlice()->getNumRefIdx ( REF_PIC_LIST_C ) > 1 ) |
---|
1206 | { |
---|
1207 | m_pcEntropyCoderIf->codeRefFrmIdx( pcCU, uiAbsPartIdx, RefPicList(pcCU->getInterDir( uiAbsPartIdx )-1) ); |
---|
1208 | } |
---|
1209 | } |
---|
1210 | else if (pcCU->getInterDir( uiAbsPartIdx ) == 3 && pcCU->getSlice()->getNumRefIdx( eRefList ) > 1) |
---|
1211 | { |
---|
1212 | if ( pcCU->getInterDir( uiAbsPartIdx ) & ( 1 << eRefList ) ) |
---|
1213 | { |
---|
1214 | m_pcEntropyCoderIf->codeRefFrmIdx( pcCU, uiAbsPartIdx, eRefList ); |
---|
1215 | } |
---|
1216 | } |
---|
1217 | break; |
---|
1218 | } |
---|
1219 | case SIZE_NxN: |
---|
1220 | { |
---|
1221 | for ( Int iPartIdx = 0; iPartIdx < 4; iPartIdx++ ) |
---|
1222 | { |
---|
1223 | if ( pcCU->getInterDir( uiAbsPartIdx ) != 3 && eRefList== REF_PIC_LIST_0 && pcCU->getSlice()->getNumRefIdx( REF_PIC_LIST_C ) > 1) |
---|
1224 | { |
---|
1225 | if ( pcCU->getSlice()->getNumRefIdx ( REF_PIC_LIST_C ) > 1 ) |
---|
1226 | { |
---|
1227 | m_pcEntropyCoderIf->codeRefFrmIdx( pcCU, uiAbsPartIdx, RefPicList(pcCU->getInterDir( uiAbsPartIdx )-1) ); |
---|
1228 | } |
---|
1229 | } |
---|
1230 | else if (pcCU->getInterDir( uiAbsPartIdx ) == 3 && pcCU->getSlice()->getNumRefIdx( eRefList ) > 1) |
---|
1231 | { |
---|
1232 | if ( pcCU->getInterDir( uiAbsPartIdx ) & ( 1 << eRefList ) ) |
---|
1233 | { |
---|
1234 | m_pcEntropyCoderIf->codeRefFrmIdx( pcCU, uiAbsPartIdx, eRefList ); |
---|
1235 | } |
---|
1236 | } |
---|
1237 | |
---|
1238 | uiAbsPartIdx += uiPartOffset; |
---|
1239 | } |
---|
1240 | break; |
---|
1241 | } |
---|
1242 | default: |
---|
1243 | break; |
---|
1244 | } |
---|
1245 | } |
---|
1246 | else |
---|
1247 | { |
---|
1248 | #endif |
---|
1249 | if ( pcCU->getSlice()->getNumRefIdx( eRefList ) == 1 ) |
---|
1250 | { |
---|
1251 | return; |
---|
1252 | } |
---|
1253 | |
---|
1254 | UInt uiPartOffset = ( pcCU->getPic()->getNumPartInCU() >> ( pcCU->getDepth(uiAbsPartIdx) << 1 ) ) >> 2; |
---|
1255 | |
---|
1256 | switch ( pcCU->getPartitionSize( uiAbsPartIdx ) ) |
---|
1257 | { |
---|
1258 | case SIZE_2Nx2N: |
---|
1259 | { |
---|
1260 | if ( pcCU->getInterDir( uiAbsPartIdx ) & ( 1 << eRefList ) ) |
---|
1261 | { |
---|
1262 | m_pcEntropyCoderIf->codeRefFrmIdx( pcCU, uiAbsPartIdx, eRefList ); |
---|
1263 | } |
---|
1264 | break; |
---|
1265 | } |
---|
1266 | case SIZE_2NxN: |
---|
1267 | { |
---|
1268 | if ( pcCU->getInterDir( uiAbsPartIdx ) & ( 1 << eRefList ) ) |
---|
1269 | { |
---|
1270 | m_pcEntropyCoderIf->codeRefFrmIdx( pcCU, uiAbsPartIdx, eRefList ); |
---|
1271 | } |
---|
1272 | |
---|
1273 | uiAbsPartIdx += uiPartOffset << 1; |
---|
1274 | if ( pcCU->getInterDir( uiAbsPartIdx ) & ( 1 << eRefList ) ) |
---|
1275 | { |
---|
1276 | m_pcEntropyCoderIf->codeRefFrmIdx( pcCU, uiAbsPartIdx, eRefList ); |
---|
1277 | } |
---|
1278 | break; |
---|
1279 | } |
---|
1280 | case SIZE_Nx2N: |
---|
1281 | { |
---|
1282 | if ( pcCU->getInterDir( uiAbsPartIdx ) & ( 1 << eRefList ) ) |
---|
1283 | { |
---|
1284 | m_pcEntropyCoderIf->codeRefFrmIdx( pcCU, uiAbsPartIdx, eRefList ); |
---|
1285 | } |
---|
1286 | |
---|
1287 | uiAbsPartIdx += uiPartOffset; |
---|
1288 | if ( pcCU->getInterDir( uiAbsPartIdx ) & ( 1 << eRefList ) ) |
---|
1289 | { |
---|
1290 | m_pcEntropyCoderIf->codeRefFrmIdx( pcCU, uiAbsPartIdx, eRefList ); |
---|
1291 | } |
---|
1292 | break; |
---|
1293 | } |
---|
1294 | case SIZE_NxN: |
---|
1295 | { |
---|
1296 | for ( Int iPartIdx = 0; iPartIdx < 4; iPartIdx++ ) |
---|
1297 | { |
---|
1298 | if ( pcCU->getInterDir( uiAbsPartIdx ) & ( 1 << eRefList ) ) |
---|
1299 | { |
---|
1300 | m_pcEntropyCoderIf->codeRefFrmIdx( pcCU, uiAbsPartIdx, eRefList ); |
---|
1301 | } |
---|
1302 | uiAbsPartIdx += uiPartOffset; |
---|
1303 | } |
---|
1304 | break; |
---|
1305 | } |
---|
1306 | default: |
---|
1307 | break; |
---|
1308 | } |
---|
1309 | |
---|
1310 | #if DCM_COMB_LIST |
---|
1311 | } |
---|
1312 | #endif |
---|
1313 | |
---|
1314 | return; |
---|
1315 | } |
---|
1316 | |
---|
1317 | /** encode motion vector difference |
---|
1318 | * \param pcCU |
---|
1319 | * \param uiAbsPartIdx |
---|
1320 | * \param eRefList |
---|
1321 | * \param bRD |
---|
1322 | * \returns Void |
---|
1323 | */ |
---|
1324 | Void TEncEntropy::encodeMvd( TComDataCU* pcCU, UInt uiAbsPartIdx, RefPicList eRefList, Bool bRD ) |
---|
1325 | { |
---|
1326 | assert( !pcCU->isIntra( uiAbsPartIdx ) ); |
---|
1327 | |
---|
1328 | if( bRD ) |
---|
1329 | uiAbsPartIdx = 0; |
---|
1330 | |
---|
1331 | UInt uiPartOffset = ( pcCU->getPic()->getNumPartInCU() >> ( pcCU->getDepth(uiAbsPartIdx) << 1 ) ) >> 2; |
---|
1332 | |
---|
1333 | switch ( pcCU->getPartitionSize( uiAbsPartIdx ) ) |
---|
1334 | { |
---|
1335 | case SIZE_2Nx2N: |
---|
1336 | { |
---|
1337 | if ( pcCU->getInterDir( uiAbsPartIdx ) & ( 1 << eRefList ) ) |
---|
1338 | { |
---|
1339 | m_pcEntropyCoderIf->codeMvd( pcCU, uiAbsPartIdx, eRefList ); |
---|
1340 | } |
---|
1341 | break; |
---|
1342 | } |
---|
1343 | |
---|
1344 | case SIZE_2NxN: |
---|
1345 | { |
---|
1346 | if ( pcCU->getInterDir( uiAbsPartIdx ) & ( 1 << eRefList ) ) |
---|
1347 | { |
---|
1348 | m_pcEntropyCoderIf->codeMvd( pcCU, uiAbsPartIdx, eRefList ); |
---|
1349 | } |
---|
1350 | |
---|
1351 | uiAbsPartIdx += uiPartOffset << 1; |
---|
1352 | if ( pcCU->getInterDir( uiAbsPartIdx ) & ( 1 << eRefList ) ) |
---|
1353 | { |
---|
1354 | m_pcEntropyCoderIf->codeMvd( pcCU, uiAbsPartIdx, eRefList ); |
---|
1355 | } |
---|
1356 | break; |
---|
1357 | } |
---|
1358 | |
---|
1359 | case SIZE_Nx2N: |
---|
1360 | { |
---|
1361 | if ( pcCU->getInterDir( uiAbsPartIdx ) & ( 1 << eRefList ) ) |
---|
1362 | { |
---|
1363 | m_pcEntropyCoderIf->codeMvd( pcCU, uiAbsPartIdx, eRefList ); |
---|
1364 | } |
---|
1365 | |
---|
1366 | uiAbsPartIdx += uiPartOffset; |
---|
1367 | if ( pcCU->getInterDir( uiAbsPartIdx ) & ( 1 << eRefList ) ) |
---|
1368 | { |
---|
1369 | m_pcEntropyCoderIf->codeMvd( pcCU, uiAbsPartIdx, eRefList ); |
---|
1370 | } |
---|
1371 | break; |
---|
1372 | } |
---|
1373 | |
---|
1374 | case SIZE_NxN: |
---|
1375 | { |
---|
1376 | for ( Int iPartIdx = 0; iPartIdx < 4; iPartIdx++ ) |
---|
1377 | { |
---|
1378 | if ( pcCU->getInterDir( uiAbsPartIdx ) & ( 1 << eRefList ) ) |
---|
1379 | { |
---|
1380 | m_pcEntropyCoderIf->codeMvd( pcCU, uiAbsPartIdx, eRefList ); |
---|
1381 | } |
---|
1382 | uiAbsPartIdx += uiPartOffset; |
---|
1383 | } |
---|
1384 | break; |
---|
1385 | } |
---|
1386 | default: |
---|
1387 | break; |
---|
1388 | } |
---|
1389 | |
---|
1390 | return; |
---|
1391 | } |
---|
1392 | |
---|
1393 | |
---|
1394 | Void TEncEntropy::encodeQtCbf( TComDataCU* pcCU, UInt uiAbsPartIdx, TextType eType, UInt uiTrDepth ) |
---|
1395 | { |
---|
1396 | m_pcEntropyCoderIf->codeQtCbf( pcCU, uiAbsPartIdx, eType, uiTrDepth ); |
---|
1397 | } |
---|
1398 | |
---|
1399 | Void TEncEntropy::encodeTransformSubdivFlag( UInt uiSymbol, UInt uiCtx ) |
---|
1400 | { |
---|
1401 | m_pcEntropyCoderIf->codeTransformSubdivFlag( uiSymbol, uiCtx ); |
---|
1402 | } |
---|
1403 | |
---|
1404 | Void TEncEntropy::encodeQtRootCbf( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
1405 | { |
---|
1406 | m_pcEntropyCoderIf->codeQtRootCbf( pcCU, uiAbsPartIdx ); |
---|
1407 | } |
---|
1408 | |
---|
1409 | // dQP |
---|
1410 | Void TEncEntropy::encodeQP( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool bRD ) |
---|
1411 | { |
---|
1412 | if( bRD ) |
---|
1413 | uiAbsPartIdx = 0; |
---|
1414 | |
---|
1415 | if ( pcCU->getSlice()->getSPS()->getUseDQP() ) |
---|
1416 | { |
---|
1417 | m_pcEntropyCoderIf->codeDeltaQP( pcCU, uiAbsPartIdx ); |
---|
1418 | } |
---|
1419 | } |
---|
1420 | |
---|
1421 | |
---|
1422 | // texture |
---|
1423 | Void TEncEntropy::xEncodeCoeff( TComDataCU* pcCU, TCoeff* pcCoeff, UInt uiAbsPartIdx, UInt uiDepth, UInt uiWidth, UInt uiHeight, UInt uiTrIdx, UInt uiCurrTrIdx, TextType eType, Bool bRD ) |
---|
1424 | { |
---|
1425 | if ( pcCU->getCbf( uiAbsPartIdx, eType, uiTrIdx ) ) |
---|
1426 | { |
---|
1427 | #if SNY_DQP |
---|
1428 | // dQP: only for LCU once |
---|
1429 | if ( pcCU->getSlice()->getSPS()->getUseDQP() ) |
---|
1430 | { |
---|
1431 | if ( pcCU->getdQPFlag())// non-skip |
---|
1432 | { |
---|
1433 | encodeQP( pcCU, 0 ); |
---|
1434 | pcCU->setdQPFlag(false); |
---|
1435 | } |
---|
1436 | } |
---|
1437 | #endif//SNY_DQP |
---|
1438 | UInt uiLumaTrMode, uiChromaTrMode; |
---|
1439 | pcCU->convertTransIdx( uiAbsPartIdx, pcCU->getTransformIdx( uiAbsPartIdx ), uiLumaTrMode, uiChromaTrMode ); |
---|
1440 | const UInt uiStopTrMode = eType == TEXT_LUMA ? uiLumaTrMode : uiChromaTrMode; |
---|
1441 | |
---|
1442 | assert(1); // as long as quadtrees are not used for residual transform |
---|
1443 | |
---|
1444 | if( uiTrIdx == uiStopTrMode ) |
---|
1445 | { |
---|
1446 | assert( !bRD ); // parameter bRD can be removed |
---|
1447 | |
---|
1448 | UInt uiLog2TrSize = g_aucConvertToBit[ pcCU->getSlice()->getSPS()->getMaxCUWidth() >> uiDepth ] + 2; |
---|
1449 | if( eType != TEXT_LUMA && uiLog2TrSize == pcCU->getSlice()->getSPS()->getQuadtreeTULog2MinSize() ) |
---|
1450 | { |
---|
1451 | UInt uiQPDiv = pcCU->getPic()->getNumPartInCU() >> ( ( uiDepth - 1 ) << 1 ); |
---|
1452 | if( ( uiAbsPartIdx % uiQPDiv ) != 0 ) |
---|
1453 | { |
---|
1454 | return; |
---|
1455 | } |
---|
1456 | uiWidth <<= 1; |
---|
1457 | uiHeight <<= 1; |
---|
1458 | } |
---|
1459 | m_pcEntropyCoderIf->codeCoeffNxN( pcCU, pcCoeff, uiAbsPartIdx, uiWidth, uiHeight, uiDepth, eType, bRD ); |
---|
1460 | } |
---|
1461 | else |
---|
1462 | { |
---|
1463 | { |
---|
1464 | DTRACE_CABAC_V( g_nSymbolCounter++ ); |
---|
1465 | DTRACE_CABAC_T( "\tgoing down\tdepth=" ); |
---|
1466 | DTRACE_CABAC_V( uiDepth ); |
---|
1467 | DTRACE_CABAC_T( "\ttridx=" ); |
---|
1468 | DTRACE_CABAC_V( uiTrIdx ); |
---|
1469 | DTRACE_CABAC_T( "\n" ); |
---|
1470 | } |
---|
1471 | if( uiCurrTrIdx <= uiTrIdx ) |
---|
1472 | assert(1); |
---|
1473 | |
---|
1474 | UInt uiSize; |
---|
1475 | uiWidth >>= 1; |
---|
1476 | uiHeight >>= 1; |
---|
1477 | uiSize = uiWidth*uiHeight; |
---|
1478 | uiDepth++; |
---|
1479 | uiTrIdx++; |
---|
1480 | |
---|
1481 | UInt uiQPartNum = pcCU->getPic()->getNumPartInCU() >> (uiDepth << 1); |
---|
1482 | UInt uiIdx = uiAbsPartIdx; |
---|
1483 | |
---|
1484 | #if !CAVLC_RQT_CBP |
---|
1485 | if(pcCU->getSlice()->getSymbolMode() == 0) |
---|
1486 | { |
---|
1487 | UInt uiLog2TrSize = g_aucConvertToBit[ pcCU->getSlice()->getSPS()->getMaxCUWidth() >> uiDepth ] + 2; |
---|
1488 | if( eType == TEXT_LUMA || uiLog2TrSize > pcCU->getSlice()->getSPS()->getQuadtreeTULog2MinSize() ) |
---|
1489 | m_pcEntropyCoderIf->codeBlockCbf(pcCU, uiIdx, eType, uiTrIdx, uiQPartNum); |
---|
1490 | xEncodeCoeff( pcCU, pcCoeff, uiIdx, uiDepth, uiWidth, uiHeight, uiTrIdx, uiCurrTrIdx, eType, bRD ); pcCoeff += uiSize; uiIdx += uiQPartNum; |
---|
1491 | xEncodeCoeff( pcCU, pcCoeff, uiIdx, uiDepth, uiWidth, uiHeight, uiTrIdx, uiCurrTrIdx, eType, bRD ); pcCoeff += uiSize; uiIdx += uiQPartNum; |
---|
1492 | xEncodeCoeff( pcCU, pcCoeff, uiIdx, uiDepth, uiWidth, uiHeight, uiTrIdx, uiCurrTrIdx, eType, bRD ); pcCoeff += uiSize; uiIdx += uiQPartNum; |
---|
1493 | xEncodeCoeff( pcCU, pcCoeff, uiIdx, uiDepth, uiWidth, uiHeight, uiTrIdx, uiCurrTrIdx, eType, bRD ); |
---|
1494 | } |
---|
1495 | else |
---|
1496 | { |
---|
1497 | #endif |
---|
1498 | xEncodeCoeff( pcCU, pcCoeff, uiIdx, uiDepth, uiWidth, uiHeight, uiTrIdx, uiCurrTrIdx, eType, bRD ); pcCoeff += uiSize; uiIdx += uiQPartNum; |
---|
1499 | xEncodeCoeff( pcCU, pcCoeff, uiIdx, uiDepth, uiWidth, uiHeight, uiTrIdx, uiCurrTrIdx, eType, bRD ); pcCoeff += uiSize; uiIdx += uiQPartNum; |
---|
1500 | xEncodeCoeff( pcCU, pcCoeff, uiIdx, uiDepth, uiWidth, uiHeight, uiTrIdx, uiCurrTrIdx, eType, bRD ); pcCoeff += uiSize; uiIdx += uiQPartNum; |
---|
1501 | xEncodeCoeff( pcCU, pcCoeff, uiIdx, uiDepth, uiWidth, uiHeight, uiTrIdx, uiCurrTrIdx, eType, bRD ); |
---|
1502 | #if !CAVLC_RQT_CBP |
---|
1503 | } |
---|
1504 | #endif |
---|
1505 | { |
---|
1506 | DTRACE_CABAC_V( g_nSymbolCounter++ ); |
---|
1507 | DTRACE_CABAC_T( "\tgoing up\n" ); |
---|
1508 | } |
---|
1509 | } |
---|
1510 | } |
---|
1511 | } |
---|
1512 | |
---|
1513 | Void TEncEntropy::encodeCoeff( TComDataCU* pcCU, TCoeff* pCoeff, UInt uiAbsPartIdx, UInt uiDepth, UInt uiWidth, UInt uiHeight, UInt uiMaxTrMode, UInt uiTrMode, TextType eType, Bool bRD ) |
---|
1514 | { |
---|
1515 | xEncodeCoeff( pcCU, pCoeff, uiAbsPartIdx, uiDepth, uiWidth, uiHeight, uiTrMode, uiMaxTrMode, eType, bRD ); |
---|
1516 | } |
---|
1517 | |
---|
1518 | /** encode coefficients |
---|
1519 | * \param pcCU |
---|
1520 | * \param uiAbsPartIdx |
---|
1521 | * \param uiDepth |
---|
1522 | * \param uiWidth |
---|
1523 | * \param uiHeight |
---|
1524 | * \returns Void |
---|
1525 | */ |
---|
1526 | Void TEncEntropy::encodeCoeff( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, UInt uiWidth, UInt uiHeight ) |
---|
1527 | { |
---|
1528 | UInt uiMinCoeffSize = pcCU->getPic()->getMinCUWidth()*pcCU->getPic()->getMinCUHeight(); |
---|
1529 | UInt uiLumaOffset = uiMinCoeffSize*uiAbsPartIdx; |
---|
1530 | UInt uiChromaOffset = uiLumaOffset>>2; |
---|
1531 | |
---|
1532 | UInt uiLumaTrMode, uiChromaTrMode; |
---|
1533 | pcCU->convertTransIdx( uiAbsPartIdx, pcCU->getTransformIdx(uiAbsPartIdx), uiLumaTrMode, uiChromaTrMode ); |
---|
1534 | |
---|
1535 | if( pcCU->isIntra(uiAbsPartIdx) ) |
---|
1536 | { |
---|
1537 | DTRACE_CABAC_V( g_nSymbolCounter++ ) |
---|
1538 | DTRACE_CABAC_T( "\tdecodeTransformIdx()\tCUDepth=" ) |
---|
1539 | DTRACE_CABAC_V( uiDepth ) |
---|
1540 | DTRACE_CABAC_T( "\n" ) |
---|
1541 | UInt temp = 0; |
---|
1542 | UInt temp1 = 0; |
---|
1543 | UInt temp2 = 0; |
---|
1544 | xEncodeTransformSubdiv( pcCU, uiAbsPartIdx, uiDepth, 0, temp, temp1, temp2 ); |
---|
1545 | |
---|
1546 | #if !CAVLC_RQT_CBP |
---|
1547 | if (pcCU->getSlice()->getSymbolMode() == 0) |
---|
1548 | { |
---|
1549 | m_pcEntropyCoderIf->codeCbf( pcCU, uiAbsPartIdx, TEXT_ALL, 0 ); |
---|
1550 | if(pcCU->getCbf(uiAbsPartIdx, TEXT_LUMA, 0)==0 && pcCU->getCbf(uiAbsPartIdx, TEXT_CHROMA_U, 0)==0 |
---|
1551 | && pcCU->getCbf(uiAbsPartIdx, TEXT_CHROMA_V, 0)==0) |
---|
1552 | return; |
---|
1553 | } |
---|
1554 | #endif |
---|
1555 | } |
---|
1556 | else |
---|
1557 | { |
---|
1558 | if (pcCU->getSlice()->getSymbolMode()==0) |
---|
1559 | { |
---|
1560 | #if !CAVLC_RQT_CBP |
---|
1561 | m_pcEntropyCoderIf->codeCbf( pcCU, uiAbsPartIdx, TEXT_ALL, 0 ); |
---|
1562 | if(pcCU->getCbf(uiAbsPartIdx, TEXT_LUMA, 0)==0 && pcCU->getCbf(uiAbsPartIdx, TEXT_CHROMA_U, 0)==0 |
---|
1563 | && pcCU->getCbf(uiAbsPartIdx, TEXT_CHROMA_V, 0)==0) |
---|
1564 | return; |
---|
1565 | #endif |
---|
1566 | } |
---|
1567 | else |
---|
1568 | { |
---|
1569 | #if HHI_MRG_SKIP |
---|
1570 | #if MW_MVI_SIGNALLING_MODE == 1 |
---|
1571 | if( !(pcCU->getMergeFlag( uiAbsPartIdx ) && pcCU->getPartitionSize(uiAbsPartIdx) == SIZE_2Nx2N && |
---|
1572 | ( pcCU->getTextureModeDepth( uiAbsPartIdx ) == -1 || uiDepth == pcCU->getTextureModeDepth( uiAbsPartIdx ) ) ) ) |
---|
1573 | #else |
---|
1574 | if( !(pcCU->getMergeFlag( uiAbsPartIdx ) && pcCU->getPartitionSize(uiAbsPartIdx) == SIZE_2Nx2N ) ) |
---|
1575 | #endif |
---|
1576 | { |
---|
1577 | m_pcEntropyCoderIf->codeQtRootCbf( pcCU, uiAbsPartIdx ); |
---|
1578 | } |
---|
1579 | #else |
---|
1580 | m_pcEntropyCoderIf->codeQtRootCbf( pcCU, uiAbsPartIdx ); |
---|
1581 | #endif |
---|
1582 | if ( !pcCU->getQtRootCbf( uiAbsPartIdx ) ) |
---|
1583 | { |
---|
1584 | pcCU->setTrIdxSubParts( 0 , uiAbsPartIdx, uiDepth ); |
---|
1585 | return; |
---|
1586 | } |
---|
1587 | } |
---|
1588 | |
---|
1589 | encodeTransformIdx( pcCU, uiAbsPartIdx, pcCU->getDepth(uiAbsPartIdx) ); |
---|
1590 | } |
---|
1591 | |
---|
1592 | xEncodeCoeff( pcCU, pcCU->getCoeffY() + uiLumaOffset, uiAbsPartIdx, uiDepth, uiWidth, uiHeight, 0, uiLumaTrMode, TEXT_LUMA ); |
---|
1593 | xEncodeCoeff( pcCU, pcCU->getCoeffCb() + uiChromaOffset, uiAbsPartIdx, uiDepth, uiWidth>>1, uiHeight>>1, 0, uiChromaTrMode, TEXT_CHROMA_U ); |
---|
1594 | xEncodeCoeff( pcCU, pcCU->getCoeffCr() + uiChromaOffset, uiAbsPartIdx, uiDepth, uiWidth>>1, uiHeight>>1, 0, uiChromaTrMode, TEXT_CHROMA_V ); |
---|
1595 | } |
---|
1596 | |
---|
1597 | Void TEncEntropy::encodeCoeffNxN( TComDataCU* pcCU, TCoeff* pcCoeff, UInt uiAbsPartIdx, UInt uiTrWidth, UInt uiTrHeight, UInt uiDepth, TextType eType, Bool bRD ) |
---|
1598 | { // This is for Transform unit processing. This may be used at mode selection stage for Inter. |
---|
1599 | m_pcEntropyCoderIf->codeCoeffNxN( pcCU, pcCoeff, uiAbsPartIdx, uiTrWidth, uiTrHeight, uiDepth, eType, bRD ); |
---|
1600 | } |
---|
1601 | |
---|
1602 | Void TEncEntropy::estimateBit (estBitsSbacStruct* pcEstBitsSbac, UInt uiWidth, TextType eTType) |
---|
1603 | { |
---|
1604 | UInt uiCTXIdx; |
---|
1605 | |
---|
1606 | switch(uiWidth) |
---|
1607 | { |
---|
1608 | case 2: uiCTXIdx = 6; break; |
---|
1609 | case 4: uiCTXIdx = 5; break; |
---|
1610 | case 8: uiCTXIdx = 4; break; |
---|
1611 | case 16: uiCTXIdx = 3; break; |
---|
1612 | case 32: uiCTXIdx = 2; break; |
---|
1613 | case 64: uiCTXIdx = 1; break; |
---|
1614 | default: uiCTXIdx = 0; break; |
---|
1615 | } |
---|
1616 | |
---|
1617 | eTType = eTType == TEXT_LUMA ? TEXT_LUMA : TEXT_CHROMA; |
---|
1618 | |
---|
1619 | m_pcEntropyCoderIf->estBit ( pcEstBitsSbac, uiCTXIdx, eTType ); |
---|
1620 | } |
---|
1621 | |
---|
1622 | #if MTK_SAO |
---|
1623 | /** encode QAO One Part |
---|
1624 | * \param pQaoParam, iPartIdx |
---|
1625 | */ |
---|
1626 | Void TEncEntropy::encodeQAOOnePart(SAOParam* pQaoParam, Int iPartIdx ) |
---|
1627 | { |
---|
1628 | SAOQTPart* pAlfPart = &(pQaoParam->psSaoPart[iPartIdx]); |
---|
1629 | UInt uiSymbol; |
---|
1630 | |
---|
1631 | if(!pAlfPart->bSplit) |
---|
1632 | { |
---|
1633 | if (pAlfPart->bEnableFlag) |
---|
1634 | uiSymbol = pAlfPart->iBestType + 1; |
---|
1635 | else |
---|
1636 | uiSymbol = 0; |
---|
1637 | |
---|
1638 | m_pcEntropyCoderIf->codeAoUvlc(uiSymbol); |
---|
1639 | if (pAlfPart->bEnableFlag) |
---|
1640 | { |
---|
1641 | for(Int i=0; i< pAlfPart->iLength; i++) |
---|
1642 | { |
---|
1643 | m_pcEntropyCoderIf->codeAoSvlc(pAlfPart->iOffset[i]); |
---|
1644 | } |
---|
1645 | } |
---|
1646 | return; |
---|
1647 | } |
---|
1648 | |
---|
1649 | //split |
---|
1650 | if (pAlfPart->PartLevel < pQaoParam->iMaxSplitLevel) |
---|
1651 | { |
---|
1652 | for (Int i=0;i<NUM_DOWN_PART;i++) |
---|
1653 | { |
---|
1654 | encodeQAOOnePart(pQaoParam, pAlfPart->DownPartsIdx[i]); |
---|
1655 | } |
---|
1656 | } |
---|
1657 | } |
---|
1658 | /** encode QuadTree Split Flag |
---|
1659 | * \param pQaoParam, iPartIdx |
---|
1660 | */ |
---|
1661 | Void TEncEntropy::encodeQuadTreeSplitFlag(SAOParam* pSaoParam, Int iPartIdx) |
---|
1662 | { |
---|
1663 | |
---|
1664 | SAOQTPart* pSaoPart = &(pSaoParam->psSaoPart[iPartIdx]); |
---|
1665 | |
---|
1666 | if(pSaoPart->PartLevel < pSaoParam->iMaxSplitLevel) |
---|
1667 | { |
---|
1668 | |
---|
1669 | //send one flag |
---|
1670 | m_pcEntropyCoderIf->codeAoFlag( (pSaoPart->bSplit)?(1):(0) ); |
---|
1671 | if(pSaoPart->bSplit) |
---|
1672 | { |
---|
1673 | for (Int i=0;i<NUM_DOWN_PART;i++) |
---|
1674 | { |
---|
1675 | encodeQuadTreeSplitFlag(pSaoParam, pSaoPart->DownPartsIdx[i]); |
---|
1676 | } |
---|
1677 | } |
---|
1678 | } |
---|
1679 | |
---|
1680 | } |
---|
1681 | |
---|
1682 | /** encode Sao Param |
---|
1683 | * \param pQaoParam |
---|
1684 | */ |
---|
1685 | Void TEncEntropy::encodeSaoParam(SAOParam* pSaoParam) |
---|
1686 | { |
---|
1687 | |
---|
1688 | m_pcEntropyCoderIf->codeAoFlag(pSaoParam->bSaoFlag); |
---|
1689 | if (pSaoParam->bSaoFlag) |
---|
1690 | { |
---|
1691 | encodeQuadTreeSplitFlag(pSaoParam, 0); |
---|
1692 | encodeQAOOnePart(pSaoParam, 0); |
---|
1693 | } |
---|
1694 | |
---|
1695 | } |
---|
1696 | |
---|
1697 | |
---|
1698 | |
---|
1699 | #endif |
---|