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