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-2012, ITU/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 ITU/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 | /** \file TEncEntropy.cpp |
---|
35 | \brief entropy encoder class |
---|
36 | */ |
---|
37 | |
---|
38 | #include "TEncEntropy.h" |
---|
39 | #include "TLibCommon/TypeDef.h" |
---|
40 | #include "TLibCommon/TComAdaptiveLoopFilter.h" |
---|
41 | #include "TLibCommon/TComSampleAdaptiveOffset.h" |
---|
42 | |
---|
43 | //! \ingroup TLibEncoder |
---|
44 | //! \{ |
---|
45 | |
---|
46 | Void TEncEntropy::setEntropyCoder ( TEncEntropyIf* e, TComSlice* pcSlice ) |
---|
47 | { |
---|
48 | m_pcEntropyCoderIf = e; |
---|
49 | m_pcEntropyCoderIf->setSlice ( pcSlice ); |
---|
50 | } |
---|
51 | |
---|
52 | Void TEncEntropy::encodeSliceHeader ( TComSlice* pcSlice ) |
---|
53 | { |
---|
54 | #if SAO_UNIT_INTERLEAVING |
---|
55 | if (pcSlice->getSPS()->getUseSAO()) |
---|
56 | { |
---|
57 | pcSlice->setSaoInterleavingFlag(pcSlice->getAPS()->getSaoInterleavingFlag()); |
---|
58 | pcSlice->setSaoEnabledFlag (pcSlice->getAPS()->getSaoParam()->bSaoFlag[0]); |
---|
59 | if (pcSlice->getAPS()->getSaoInterleavingFlag()) |
---|
60 | { |
---|
61 | pcSlice->setSaoEnabledFlagCb (pcSlice->getAPS()->getSaoParam()->bSaoFlag[1]); |
---|
62 | pcSlice->setSaoEnabledFlagCr (pcSlice->getAPS()->getSaoParam()->bSaoFlag[2]); |
---|
63 | } |
---|
64 | else |
---|
65 | { |
---|
66 | pcSlice->setSaoEnabledFlagCb (0); |
---|
67 | pcSlice->setSaoEnabledFlagCr (0); |
---|
68 | } |
---|
69 | } |
---|
70 | #endif |
---|
71 | |
---|
72 | m_pcEntropyCoderIf->codeSliceHeader( pcSlice ); |
---|
73 | return; |
---|
74 | } |
---|
75 | |
---|
76 | #if TILES_WPP_ENTRY_POINT_SIGNALLING |
---|
77 | Void TEncEntropy::encodeTilesWPPEntryPoint( TComSlice* pSlice ) |
---|
78 | { |
---|
79 | m_pcEntropyCoderIf->codeTilesWPPEntryPoint( pSlice ); |
---|
80 | } |
---|
81 | #else |
---|
82 | Void TEncEntropy::encodeSliceHeaderSubstreamTable( TComSlice* pcSlice ) |
---|
83 | { |
---|
84 | m_pcEntropyCoderIf->codeSliceHeaderSubstreamTable( pcSlice ); |
---|
85 | } |
---|
86 | #endif |
---|
87 | |
---|
88 | Void TEncEntropy::encodeTerminatingBit ( UInt uiIsLast ) |
---|
89 | { |
---|
90 | m_pcEntropyCoderIf->codeTerminatingBit( uiIsLast ); |
---|
91 | |
---|
92 | return; |
---|
93 | } |
---|
94 | |
---|
95 | Void TEncEntropy::encodeSliceFinish() |
---|
96 | { |
---|
97 | m_pcEntropyCoderIf->codeSliceFinish(); |
---|
98 | } |
---|
99 | |
---|
100 | #if OL_FLUSH |
---|
101 | Void TEncEntropy::encodeFlush() |
---|
102 | { |
---|
103 | m_pcEntropyCoderIf->codeFlush(); |
---|
104 | } |
---|
105 | Void TEncEntropy::encodeStart() |
---|
106 | { |
---|
107 | m_pcEntropyCoderIf->encodeStart(); |
---|
108 | } |
---|
109 | #endif |
---|
110 | |
---|
111 | Void TEncEntropy::encodeSEI(const SEI& sei) |
---|
112 | { |
---|
113 | m_pcEntropyCoderIf->codeSEI(sei); |
---|
114 | return; |
---|
115 | } |
---|
116 | |
---|
117 | Void TEncEntropy::encodePPS( TComPPS* pcPPS ) |
---|
118 | { |
---|
119 | m_pcEntropyCoderIf->codePPS( pcPPS ); |
---|
120 | return; |
---|
121 | } |
---|
122 | |
---|
123 | #if HHI_MPI |
---|
124 | Void TEncEntropy::encodeSPS( TComSPS* pcSPS, Bool bIsDepth ) |
---|
125 | { |
---|
126 | m_pcEntropyCoderIf->codeSPS( pcSPS, bIsDepth ); |
---|
127 | return; |
---|
128 | } |
---|
129 | #else |
---|
130 | Void TEncEntropy::encodeSPS( TComSPS* pcSPS ) |
---|
131 | { |
---|
132 | m_pcEntropyCoderIf->codeSPS( pcSPS ); |
---|
133 | return; |
---|
134 | } |
---|
135 | #endif |
---|
136 | |
---|
137 | Void TEncEntropy::encodeSkipFlag( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool bRD ) |
---|
138 | { |
---|
139 | if ( pcCU->getSlice()->isIntra() ) |
---|
140 | { |
---|
141 | return; |
---|
142 | } |
---|
143 | if( bRD ) |
---|
144 | { |
---|
145 | uiAbsPartIdx = 0; |
---|
146 | } |
---|
147 | #if BURST_IPCM |
---|
148 | if( !bRD ) |
---|
149 | { |
---|
150 | if( pcCU->getLastCUSucIPCMFlag() && pcCU->getIPCMFlag(uiAbsPartIdx) ) |
---|
151 | { |
---|
152 | return; |
---|
153 | } |
---|
154 | } |
---|
155 | #endif |
---|
156 | m_pcEntropyCoderIf->codeSkipFlag( pcCU, uiAbsPartIdx ); |
---|
157 | } |
---|
158 | |
---|
159 | Void TEncEntropy::codeFiltCountBit(ALFParam* pAlfParam, Int64* ruiRate) |
---|
160 | { |
---|
161 | resetEntropy(); |
---|
162 | resetBits(); |
---|
163 | codeFilt(pAlfParam); |
---|
164 | *ruiRate = getNumberOfWrittenBits(); |
---|
165 | resetEntropy(); |
---|
166 | resetBits(); |
---|
167 | } |
---|
168 | |
---|
169 | Void TEncEntropy::codeAuxCountBit(ALFParam* pAlfParam, Int64* ruiRate) |
---|
170 | { |
---|
171 | resetEntropy(); |
---|
172 | resetBits(); |
---|
173 | codeAux(pAlfParam); |
---|
174 | *ruiRate = getNumberOfWrittenBits(); |
---|
175 | resetEntropy(); |
---|
176 | resetBits(); |
---|
177 | } |
---|
178 | |
---|
179 | Void TEncEntropy::codeAux(ALFParam* pAlfParam) |
---|
180 | { |
---|
181 | // m_pcEntropyCoderIf->codeAlfUvlc(pAlfParam->realfiltNo); |
---|
182 | |
---|
183 | #if !LCU_SYNTAX_ALF |
---|
184 | m_pcEntropyCoderIf->codeAlfFlag(pAlfParam->alf_pcr_region_flag); |
---|
185 | #endif |
---|
186 | #if !ALF_SINGLE_FILTER_SHAPE |
---|
187 | m_pcEntropyCoderIf->codeAlfUvlc(pAlfParam->filter_shape); |
---|
188 | #endif |
---|
189 | Int noFilters = min(pAlfParam->filters_per_group-1, 2); |
---|
190 | m_pcEntropyCoderIf->codeAlfUvlc(noFilters); |
---|
191 | |
---|
192 | if(noFilters == 1) |
---|
193 | { |
---|
194 | m_pcEntropyCoderIf->codeAlfUvlc(pAlfParam->startSecondFilter); |
---|
195 | } |
---|
196 | else if (noFilters == 2) |
---|
197 | { |
---|
198 | #if LCU_SYNTAX_ALF |
---|
199 | #if ALF_16_BA_GROUPS |
---|
200 | Int numMergeFlags = 16; |
---|
201 | #else |
---|
202 | Int numMergeFlags = 15; |
---|
203 | #endif |
---|
204 | #else |
---|
205 | #if ALF_16_BA_GROUPS |
---|
206 | Int numMergeFlags = 16; |
---|
207 | #else |
---|
208 | Int numMergeFlags = pAlfParam->alf_pcr_region_flag ? 16 : 15; |
---|
209 | #endif |
---|
210 | #endif |
---|
211 | for (Int i=1; i<numMergeFlags; i++) |
---|
212 | { |
---|
213 | m_pcEntropyCoderIf->codeAlfFlag (pAlfParam->filterPattern[i]); |
---|
214 | } |
---|
215 | } |
---|
216 | } |
---|
217 | |
---|
218 | Int TEncEntropy::lengthGolomb(int coeffVal, int k) |
---|
219 | { |
---|
220 | int m = 2 << (k - 1); |
---|
221 | int q = coeffVal / m; |
---|
222 | if(coeffVal != 0) |
---|
223 | { |
---|
224 | return(q + 2 + k); |
---|
225 | } |
---|
226 | else |
---|
227 | { |
---|
228 | return(q + 1 + k); |
---|
229 | } |
---|
230 | } |
---|
231 | |
---|
232 | Int TEncEntropy::codeFilterCoeff(ALFParam* ALFp) |
---|
233 | { |
---|
234 | Int filters_per_group = ALFp->filters_per_group; |
---|
235 | int sqrFiltLength = ALFp->num_coeff; |
---|
236 | int i, k, kMin, kStart, minBits, ind, scanPos, maxScanVal, coeffVal, len = 0, |
---|
237 | *pDepthInt=NULL, kMinTab[MAX_SCAN_VAL], bitsCoeffScan[MAX_SCAN_VAL][MAX_EXP_GOLOMB], |
---|
238 | minKStart, minBitsKStart, bitsKStart; |
---|
239 | |
---|
240 | pDepthInt = pDepthIntTabShapes[ALFp->filter_shape]; |
---|
241 | maxScanVal = 0; |
---|
242 | #if ALF_SINGLE_FILTER_SHAPE |
---|
243 | int minScanVal = MIN_SCAN_POS_CROSS; |
---|
244 | #else |
---|
245 | int minScanVal = ( ALFp->filter_shape==ALF_STAR5x5 ) ? 0 : MIN_SCAN_POS_CROSS; |
---|
246 | #endif |
---|
247 | |
---|
248 | for(i = 0; i < sqrFiltLength; i++) |
---|
249 | { |
---|
250 | maxScanVal = max(maxScanVal, pDepthInt[i]); |
---|
251 | } |
---|
252 | |
---|
253 | // vlc for all |
---|
254 | memset(bitsCoeffScan, 0, MAX_SCAN_VAL * MAX_EXP_GOLOMB * sizeof(int)); |
---|
255 | for(ind=0; ind<filters_per_group; ++ind) |
---|
256 | { |
---|
257 | for(i = 0; i < sqrFiltLength; i++) |
---|
258 | { |
---|
259 | scanPos=pDepthInt[i]-1; |
---|
260 | coeffVal=abs(ALFp->coeffmulti[ind][i]); |
---|
261 | for (k=1; k<15; k++) |
---|
262 | { |
---|
263 | bitsCoeffScan[scanPos][k]+=lengthGolomb(coeffVal, k); |
---|
264 | } |
---|
265 | } |
---|
266 | } |
---|
267 | |
---|
268 | minBitsKStart = 0; |
---|
269 | minKStart = -1; |
---|
270 | for(k = 1; k < 8; k++) |
---|
271 | { |
---|
272 | bitsKStart = 0; |
---|
273 | kStart = k; |
---|
274 | for(scanPos = minScanVal; scanPos < maxScanVal; scanPos++) |
---|
275 | { |
---|
276 | kMin = kStart; |
---|
277 | minBits = bitsCoeffScan[scanPos][kMin]; |
---|
278 | |
---|
279 | if(bitsCoeffScan[scanPos][kStart+1] < minBits) |
---|
280 | { |
---|
281 | kMin = kStart + 1; |
---|
282 | minBits = bitsCoeffScan[scanPos][kMin]; |
---|
283 | } |
---|
284 | kStart = kMin; |
---|
285 | bitsKStart += minBits; |
---|
286 | } |
---|
287 | if((bitsKStart < minBitsKStart) || (k == 1)) |
---|
288 | { |
---|
289 | minBitsKStart = bitsKStart; |
---|
290 | minKStart = k; |
---|
291 | } |
---|
292 | } |
---|
293 | |
---|
294 | kStart = minKStart; |
---|
295 | for(scanPos = minScanVal; scanPos < maxScanVal; scanPos++) |
---|
296 | { |
---|
297 | kMin = kStart; |
---|
298 | minBits = bitsCoeffScan[scanPos][kMin]; |
---|
299 | |
---|
300 | if(bitsCoeffScan[scanPos][kStart+1] < minBits) |
---|
301 | { |
---|
302 | kMin = kStart + 1; |
---|
303 | minBits = bitsCoeffScan[scanPos][kMin]; |
---|
304 | } |
---|
305 | |
---|
306 | kMinTab[scanPos] = kMin; |
---|
307 | kStart = kMin; |
---|
308 | } |
---|
309 | |
---|
310 | // Coding parameters |
---|
311 | ALFp->minKStart = minKStart; |
---|
312 | #if !LCU_SYNTAX_ALF |
---|
313 | ALFp->maxScanVal = maxScanVal; |
---|
314 | #endif |
---|
315 | for(scanPos = minScanVal; scanPos < maxScanVal; scanPos++) |
---|
316 | { |
---|
317 | ALFp->kMinTab[scanPos] = kMinTab[scanPos]; |
---|
318 | } |
---|
319 | |
---|
320 | #if LCU_SYNTAX_ALF |
---|
321 | if (ALFp->filters_per_group == 1) |
---|
322 | { |
---|
323 | len += writeFilterCoeffs(sqrFiltLength, filters_per_group, pDepthInt, ALFp->coeffmulti, kTableTabShapes[ALF_CROSS9x7_SQUARE3x3]); |
---|
324 | } |
---|
325 | else |
---|
326 | { |
---|
327 | #endif |
---|
328 | len += writeFilterCodingParams(minKStart, minScanVal, maxScanVal, kMinTab); |
---|
329 | |
---|
330 | // Filter coefficients |
---|
331 | len += writeFilterCoeffs(sqrFiltLength, filters_per_group, pDepthInt, ALFp->coeffmulti, kMinTab); |
---|
332 | #if LCU_SYNTAX_ALF |
---|
333 | } |
---|
334 | #endif |
---|
335 | |
---|
336 | return len; |
---|
337 | } |
---|
338 | |
---|
339 | Int TEncEntropy::writeFilterCodingParams(int minKStart, int minScanVal, int maxScanVal, int kMinTab[]) |
---|
340 | { |
---|
341 | int scanPos; |
---|
342 | int golombIndexBit; |
---|
343 | int kMin; |
---|
344 | |
---|
345 | // Golomb parameters |
---|
346 | m_pcEntropyCoderIf->codeAlfUvlc(minKStart - 1); |
---|
347 | |
---|
348 | kMin = minKStart; |
---|
349 | for(scanPos = minScanVal; scanPos < maxScanVal; scanPos++) |
---|
350 | { |
---|
351 | golombIndexBit = (kMinTab[scanPos] != kMin)? 1: 0; |
---|
352 | |
---|
353 | assert(kMinTab[scanPos] <= kMin + 1); |
---|
354 | |
---|
355 | m_pcEntropyCoderIf->codeAlfFlag(golombIndexBit); |
---|
356 | kMin = kMinTab[scanPos]; |
---|
357 | } |
---|
358 | |
---|
359 | return 0; |
---|
360 | } |
---|
361 | |
---|
362 | Int TEncEntropy::writeFilterCoeffs(int sqrFiltLength, int filters_per_group, int pDepthInt[], |
---|
363 | int **FilterCoeff, int kMinTab[]) |
---|
364 | { |
---|
365 | int ind, scanPos, i; |
---|
366 | |
---|
367 | for(ind = 0; ind < filters_per_group; ++ind) |
---|
368 | { |
---|
369 | for(i = 0; i < sqrFiltLength; i++) |
---|
370 | { |
---|
371 | scanPos = pDepthInt[i] - 1; |
---|
372 | #if LCU_SYNTAX_ALF |
---|
373 | Int k = (filters_per_group == 1) ? kMinTab[i] : kMinTab[scanPos]; |
---|
374 | golombEncode(FilterCoeff[ind][i], k); |
---|
375 | #else |
---|
376 | golombEncode(FilterCoeff[ind][i], kMinTab[scanPos]); |
---|
377 | #endif |
---|
378 | } |
---|
379 | } |
---|
380 | return 0; |
---|
381 | } |
---|
382 | |
---|
383 | Int TEncEntropy::golombEncode(int coeff, int k) |
---|
384 | { |
---|
385 | int q, i; |
---|
386 | int symbol = abs(coeff); |
---|
387 | |
---|
388 | q = symbol >> k; |
---|
389 | |
---|
390 | for (i = 0; i < q; i++) |
---|
391 | { |
---|
392 | m_pcEntropyCoderIf->codeAlfFlag(1); |
---|
393 | } |
---|
394 | m_pcEntropyCoderIf->codeAlfFlag(0); |
---|
395 | // write one zero |
---|
396 | |
---|
397 | for(i = 0; i < k; i++) |
---|
398 | { |
---|
399 | m_pcEntropyCoderIf->codeAlfFlag(symbol & 0x01); |
---|
400 | symbol >>= 1; |
---|
401 | } |
---|
402 | |
---|
403 | if(coeff != 0) |
---|
404 | { |
---|
405 | int sign = (coeff > 0)? 1: 0; |
---|
406 | m_pcEntropyCoderIf->codeAlfFlag(sign); |
---|
407 | } |
---|
408 | return 0; |
---|
409 | } |
---|
410 | |
---|
411 | Void TEncEntropy::codeFilt(ALFParam* pAlfParam) |
---|
412 | { |
---|
413 | if(pAlfParam->filters_per_group > 1) |
---|
414 | { |
---|
415 | m_pcEntropyCoderIf->codeAlfFlag (pAlfParam->predMethod); |
---|
416 | } |
---|
417 | for(Int ind = 0; ind < pAlfParam->filters_per_group; ++ind) |
---|
418 | { |
---|
419 | m_pcEntropyCoderIf->codeAlfFlag (pAlfParam->nbSPred[ind]); |
---|
420 | } |
---|
421 | codeFilterCoeff (pAlfParam); |
---|
422 | } |
---|
423 | |
---|
424 | /** encode merge flag |
---|
425 | * \param pcCU |
---|
426 | * \param uiAbsPartIdx |
---|
427 | * \param uiPUIdx |
---|
428 | * \returns Void |
---|
429 | */ |
---|
430 | Void TEncEntropy::encodeMergeFlag( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiPUIdx ) |
---|
431 | { |
---|
432 | // at least one merge candidate exists |
---|
433 | m_pcEntropyCoderIf->codeMergeFlag( pcCU, uiAbsPartIdx ); |
---|
434 | } |
---|
435 | |
---|
436 | /** encode merge index |
---|
437 | * \param pcCU |
---|
438 | * \param uiAbsPartIdx |
---|
439 | * \param uiPUIdx |
---|
440 | * \param bRD |
---|
441 | * \returns Void |
---|
442 | */ |
---|
443 | Void TEncEntropy::encodeMergeIndex( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiPUIdx, Bool bRD ) |
---|
444 | { |
---|
445 | if( bRD ) |
---|
446 | { |
---|
447 | uiAbsPartIdx = 0; |
---|
448 | assert( pcCU->getPartitionSize(uiAbsPartIdx) == SIZE_2Nx2N ); |
---|
449 | } |
---|
450 | |
---|
451 | UInt uiNumCand = MRG_MAX_NUM_CANDS; |
---|
452 | if ( uiNumCand > 1 ) |
---|
453 | { |
---|
454 | m_pcEntropyCoderIf->codeMergeIndex( pcCU, uiAbsPartIdx ); |
---|
455 | } |
---|
456 | } |
---|
457 | |
---|
458 | #if HHI_INTER_VIEW_RESIDUAL_PRED |
---|
459 | Void |
---|
460 | TEncEntropy::encodeResPredFlag( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiPUIdx, Bool bRD ) |
---|
461 | { |
---|
462 | if( bRD ) |
---|
463 | { |
---|
464 | uiAbsPartIdx = 0; |
---|
465 | } |
---|
466 | |
---|
467 | // check whether flag is coded |
---|
468 | ROTVS( pcCU->getSlice()->getSPS()->isDepth () ); |
---|
469 | ROFVS( pcCU->getSlice()->getSPS()->getViewId () ); |
---|
470 | ROFVS( pcCU->getSlice()->getSPS()->getMultiviewResPredMode() ); |
---|
471 | ROTVS( pcCU->isIntra ( uiAbsPartIdx ) ); |
---|
472 | ROFVS( pcCU->getResPredAvail ( uiAbsPartIdx ) ); |
---|
473 | #if LG_RESTRICTEDRESPRED_M24766 |
---|
474 | Int iPUResiPredShift[4]; |
---|
475 | pcCU->getPUResiPredShift(iPUResiPredShift, uiAbsPartIdx); |
---|
476 | if(iPUResiPredShift[0] >= 0 || iPUResiPredShift[1] >= 0 || iPUResiPredShift[2] >= 0 || iPUResiPredShift[3] >= 0 ) |
---|
477 | #endif |
---|
478 | // encode flag |
---|
479 | m_pcEntropyCoderIf->codeResPredFlag( pcCU, uiAbsPartIdx ); |
---|
480 | } |
---|
481 | #endif |
---|
482 | |
---|
483 | #if LCU_SYNTAX_ALF |
---|
484 | /** parse the fixed length code (smaller than one max value) in ALF |
---|
485 | * \param run: coded value |
---|
486 | * \param rx: cur addr |
---|
487 | * \param numLCUInWidth: # of LCU in one LCU |
---|
488 | * \returns Void |
---|
489 | */ |
---|
490 | Void TEncEntropy::encodeAlfFixedLengthRun(UInt run, UInt rx, UInt numLCUInWidth) |
---|
491 | { |
---|
492 | assert(numLCUInWidth > rx); |
---|
493 | UInt maxValue = numLCUInWidth - rx - 1; |
---|
494 | m_pcEntropyCoderIf->codeAlfFixedLengthIdx(run, maxValue); |
---|
495 | } |
---|
496 | |
---|
497 | /** parse the fixed length code (smaller than one max value) in ALF |
---|
498 | * \param idx: coded value |
---|
499 | * \param numFilterSetsInBuffer: max value |
---|
500 | * \returns Void |
---|
501 | */ |
---|
502 | Void TEncEntropy::encodeAlfStoredFilterSetIdx(UInt idx, UInt numFilterSetsInBuffer) |
---|
503 | { |
---|
504 | assert(numFilterSetsInBuffer > 0); |
---|
505 | UInt maxValue = numFilterSetsInBuffer - 1; |
---|
506 | m_pcEntropyCoderIf->codeAlfFixedLengthIdx(idx, maxValue); |
---|
507 | } |
---|
508 | |
---|
509 | Void TEncEntropy::encodeAlfParam(AlfParamSet* pAlfParamSet, Bool bSentInAPS, Int firstLCUAddr, Bool alfAcrossSlice) |
---|
510 | { |
---|
511 | Bool isEnabled[NUM_ALF_COMPONENT]; |
---|
512 | Bool isUniParam[NUM_ALF_COMPONENT]; |
---|
513 | |
---|
514 | isEnabled[ALF_Y] = true; |
---|
515 | isEnabled[ALF_Cb]= pAlfParamSet->isEnabled[ALF_Cb]; |
---|
516 | isEnabled[ALF_Cr]= pAlfParamSet->isEnabled[ALF_Cr]; |
---|
517 | |
---|
518 | isUniParam[ALF_Y]= pAlfParamSet->isUniParam[ALF_Y]; |
---|
519 | isUniParam[ALF_Cb]= pAlfParamSet->isUniParam[ALF_Cb]; |
---|
520 | isUniParam[ALF_Cr]= pAlfParamSet->isUniParam[ALF_Cr]; |
---|
521 | |
---|
522 | |
---|
523 | //alf_cb_enable_flag |
---|
524 | m_pcEntropyCoderIf->codeAlfFlag(isEnabled[ALF_Cb]?1:0); |
---|
525 | //alf_cr_enable_flag |
---|
526 | m_pcEntropyCoderIf->codeAlfFlag(isEnabled[ALF_Cr]?1:0); |
---|
527 | |
---|
528 | for(Int compIdx = 0; compIdx< NUM_ALF_COMPONENT; compIdx++) |
---|
529 | { |
---|
530 | if(isEnabled[compIdx]) |
---|
531 | { |
---|
532 | //alf_one_{luma, cb, cr}_unit_per_slice_flag |
---|
533 | m_pcEntropyCoderIf->codeAlfFlag(isUniParam[compIdx]?1:0); |
---|
534 | } |
---|
535 | } |
---|
536 | if(bSentInAPS) |
---|
537 | { |
---|
538 | //alf_num_lcu_in_width_minus1 |
---|
539 | m_pcEntropyCoderIf->codeAlfUvlc(pAlfParamSet->numLCUInWidth-1); |
---|
540 | //alf_num_lcu_in_height_minus1 |
---|
541 | m_pcEntropyCoderIf->codeAlfUvlc(pAlfParamSet->numLCUInHeight-1); |
---|
542 | } |
---|
543 | else //sent in slice header |
---|
544 | { |
---|
545 | //alf_num_lcu_in_slice_minus1 |
---|
546 | m_pcEntropyCoderIf->codeAlfUvlc(pAlfParamSet->numLCU-1); |
---|
547 | } |
---|
548 | |
---|
549 | |
---|
550 | encodeAlfParamSet(pAlfParamSet, pAlfParamSet->numLCUInWidth, pAlfParamSet->numLCU, firstLCUAddr, alfAcrossSlice, 0, (Int)NUM_ALF_COMPONENT-1); |
---|
551 | |
---|
552 | } |
---|
553 | |
---|
554 | Bool TEncEntropy::getAlfRepeatRowFlag(Int compIdx, AlfParamSet* pAlfParamSet |
---|
555 | , Int lcuIdxInSlice, Int lcuPos |
---|
556 | , Int startlcuPosX, Int endlcuPosX |
---|
557 | , Int numLCUInWidth |
---|
558 | ) |
---|
559 | { |
---|
560 | assert(startlcuPosX == 0); //only the beginning of one LCU row needs to send repeat_row_flag |
---|
561 | |
---|
562 | Int len = endlcuPosX - startlcuPosX +1; |
---|
563 | Bool isRepeatRow = true; |
---|
564 | Int curPos; |
---|
565 | |
---|
566 | for(Int i= 0; i < len; i++) |
---|
567 | { |
---|
568 | curPos = lcuIdxInSlice +i; |
---|
569 | AlfUnitParam& alfUnitParam = pAlfParamSet->alfUnitParam[compIdx][curPos]; |
---|
570 | AlfUnitParam& alfUpUnitParam = pAlfParamSet->alfUnitParam[compIdx][curPos-numLCUInWidth]; |
---|
571 | |
---|
572 | if ( !(alfUnitParam == alfUpUnitParam) ) |
---|
573 | { |
---|
574 | isRepeatRow = false; |
---|
575 | break; |
---|
576 | } |
---|
577 | } |
---|
578 | |
---|
579 | return isRepeatRow; |
---|
580 | } |
---|
581 | |
---|
582 | |
---|
583 | Int TEncEntropy::getAlfRun(Int compIdx, AlfParamSet* pAlfParamSet |
---|
584 | , Int lcuIdxInSlice, Int lcuPos |
---|
585 | , Int startlcuPosX, Int endlcuPosX |
---|
586 | ) |
---|
587 | { |
---|
588 | Int alfRun = 0; |
---|
589 | Int len = endlcuPosX - startlcuPosX +1; |
---|
590 | AlfUnitParam& alfLeftUnitParam = pAlfParamSet->alfUnitParam[compIdx][lcuIdxInSlice]; |
---|
591 | |
---|
592 | |
---|
593 | |
---|
594 | for(Int i= 1; i < len; i++) |
---|
595 | { |
---|
596 | AlfUnitParam& alfUnitParam = pAlfParamSet->alfUnitParam[compIdx][lcuIdxInSlice+ i]; |
---|
597 | |
---|
598 | if (alfUnitParam == alfLeftUnitParam) |
---|
599 | { |
---|
600 | alfRun++; |
---|
601 | } |
---|
602 | else |
---|
603 | { |
---|
604 | break; |
---|
605 | } |
---|
606 | } |
---|
607 | |
---|
608 | return alfRun; |
---|
609 | |
---|
610 | } |
---|
611 | |
---|
612 | |
---|
613 | |
---|
614 | Void TEncEntropy::encodeAlfParamSet(AlfParamSet* pAlfParamSet, Int numLCUInWidth, Int numLCU, Int firstLCUAddr, Bool alfAcrossSlice, Int startCompIdx, Int endCompIdx) |
---|
615 | { |
---|
616 | Int endLCUY = (numLCU -1 + firstLCUAddr)/numLCUInWidth; |
---|
617 | Int endLCUX = (numLCU -1 + firstLCUAddr)%numLCUInWidth; |
---|
618 | |
---|
619 | static Bool isRepeatedRow [NUM_ALF_COMPONENT]; |
---|
620 | static Int numStoredFilters[NUM_ALF_COMPONENT]; |
---|
621 | static Int* run [NUM_ALF_COMPONENT]; |
---|
622 | |
---|
623 | for(Int compIdx =startCompIdx; compIdx <= endCompIdx; compIdx++) |
---|
624 | { |
---|
625 | isRepeatedRow[compIdx] = false; |
---|
626 | numStoredFilters[compIdx] = 0; |
---|
627 | |
---|
628 | run[compIdx] = new Int[numLCU+1]; |
---|
629 | run[compIdx][0] = -1; |
---|
630 | } |
---|
631 | |
---|
632 | Int ry, rx, addrUp, endrX, lcuPos; |
---|
633 | |
---|
634 | for(Int i=0; i< numLCU; i++) |
---|
635 | { |
---|
636 | lcuPos= firstLCUAddr+ i; |
---|
637 | rx = lcuPos% numLCUInWidth; |
---|
638 | ry = lcuPos/ numLCUInWidth; |
---|
639 | endrX = ( ry == endLCUY)?( endLCUX ):(numLCUInWidth-1); |
---|
640 | |
---|
641 | for(Int compIdx =startCompIdx; compIdx <= endCompIdx; compIdx++) |
---|
642 | { |
---|
643 | AlfUnitParam& alfUnitParam = pAlfParamSet->alfUnitParam[compIdx][i]; |
---|
644 | if(pAlfParamSet->isEnabled[compIdx]) |
---|
645 | { |
---|
646 | if(!pAlfParamSet->isUniParam[compIdx]) |
---|
647 | { |
---|
648 | addrUp = i-numLCUInWidth; |
---|
649 | if(rx ==0 && addrUp >=0) |
---|
650 | { |
---|
651 | isRepeatedRow[compIdx] = getAlfRepeatRowFlag(compIdx, pAlfParamSet, i, lcuPos, rx, endrX, numLCUInWidth); |
---|
652 | |
---|
653 | //alf_repeat_row_flag |
---|
654 | m_pcEntropyCoderIf->codeAlfFlag(isRepeatedRow[compIdx]?1:0); |
---|
655 | } |
---|
656 | |
---|
657 | if(isRepeatedRow[compIdx]) |
---|
658 | { |
---|
659 | assert(addrUp >=0); |
---|
660 | run[compIdx][i] = run[compIdx][addrUp]; |
---|
661 | } |
---|
662 | else |
---|
663 | { |
---|
664 | if(rx == 0 || run[compIdx][i] < 0) |
---|
665 | { |
---|
666 | run[compIdx][i] = getAlfRun(compIdx, pAlfParamSet, i, lcuPos, rx, endrX); |
---|
667 | |
---|
668 | if(addrUp < 0) |
---|
669 | { |
---|
670 | //alf_run_diff u(v) |
---|
671 | encodeAlfFixedLengthRun(run[compIdx][i], rx, numLCUInWidth); |
---|
672 | } |
---|
673 | else |
---|
674 | { |
---|
675 | //alf_run_diff s(v) |
---|
676 | m_pcEntropyCoderIf->codeAlfSvlc(run[compIdx][i]- run[compIdx][addrUp]); |
---|
677 | |
---|
678 | } |
---|
679 | |
---|
680 | if(ry > 0 && (addrUp >=0 || alfAcrossSlice)) |
---|
681 | { |
---|
682 | //alf_merge_up_flag |
---|
683 | m_pcEntropyCoderIf->codeAlfFlag( (alfUnitParam.mergeType == ALF_MERGE_UP)?1:0 ); |
---|
684 | } |
---|
685 | |
---|
686 | if(alfUnitParam.mergeType != ALF_MERGE_UP) |
---|
687 | { |
---|
688 | assert(alfUnitParam.mergeType == ALF_MERGE_DISABLED); |
---|
689 | |
---|
690 | //alf_lcu_enable_flag |
---|
691 | m_pcEntropyCoderIf->codeAlfFlag(alfUnitParam.isEnabled ? 1 : 0); |
---|
692 | |
---|
693 | if(alfUnitParam.isEnabled) |
---|
694 | { |
---|
695 | if(numStoredFilters[compIdx] > 0) |
---|
696 | { |
---|
697 | //alf_new_filter_set_flag |
---|
698 | m_pcEntropyCoderIf->codeAlfFlag(alfUnitParam.isNewFilt ? 1:0); |
---|
699 | |
---|
700 | if(!alfUnitParam.isNewFilt) |
---|
701 | { |
---|
702 | //alf_stored_filter_set_idx |
---|
703 | encodeAlfStoredFilterSetIdx(alfUnitParam.storedFiltIdx, numStoredFilters[compIdx]); |
---|
704 | |
---|
705 | } |
---|
706 | } |
---|
707 | else |
---|
708 | { |
---|
709 | assert(alfUnitParam.isNewFilt); |
---|
710 | } |
---|
711 | |
---|
712 | if(alfUnitParam.isNewFilt) |
---|
713 | { |
---|
714 | assert(alfUnitParam.alfFiltParam->alf_flag == 1); |
---|
715 | encodeAlfParam(alfUnitParam.alfFiltParam); |
---|
716 | numStoredFilters[compIdx]++; |
---|
717 | } |
---|
718 | } |
---|
719 | |
---|
720 | } |
---|
721 | } |
---|
722 | |
---|
723 | run[compIdx][i+1] = run[compIdx][i] -1; |
---|
724 | } |
---|
725 | |
---|
726 | } |
---|
727 | else // uni-param |
---|
728 | { |
---|
729 | if(i == 0) |
---|
730 | { |
---|
731 | //alf_lcu_enable_flag |
---|
732 | m_pcEntropyCoderIf->codeAlfFlag(alfUnitParam.isEnabled?1:0); |
---|
733 | if(alfUnitParam.isEnabled) |
---|
734 | { |
---|
735 | encodeAlfParam(alfUnitParam.alfFiltParam); |
---|
736 | } |
---|
737 | } |
---|
738 | } |
---|
739 | } // component enabled/disable |
---|
740 | } //comp |
---|
741 | |
---|
742 | } |
---|
743 | |
---|
744 | for(Int compIdx =startCompIdx; compIdx <= endCompIdx; compIdx++) |
---|
745 | { |
---|
746 | delete[] run[compIdx]; |
---|
747 | } |
---|
748 | |
---|
749 | } |
---|
750 | #endif |
---|
751 | |
---|
752 | |
---|
753 | Void TEncEntropy::encodeAlfParam(ALFParam* pAlfParam) |
---|
754 | { |
---|
755 | #if LCU_SYNTAX_ALF |
---|
756 | const Int numCoeff = (Int)ALF_MAX_NUM_COEF; |
---|
757 | |
---|
758 | switch(pAlfParam->componentID) |
---|
759 | { |
---|
760 | case ALF_Cb: |
---|
761 | case ALF_Cr: |
---|
762 | { |
---|
763 | for(Int pos=0; pos< numCoeff; pos++) |
---|
764 | { |
---|
765 | m_pcEntropyCoderIf->codeAlfSvlc( pAlfParam->coeffmulti[0][pos]); |
---|
766 | |
---|
767 | } |
---|
768 | } |
---|
769 | break; |
---|
770 | case ALF_Y: |
---|
771 | { |
---|
772 | codeAux(pAlfParam); |
---|
773 | codeFilt(pAlfParam); |
---|
774 | } |
---|
775 | break; |
---|
776 | default: |
---|
777 | { |
---|
778 | printf("Not a legal component ID\n"); |
---|
779 | assert(0); |
---|
780 | exit(-1); |
---|
781 | } |
---|
782 | } |
---|
783 | #else |
---|
784 | if (!pAlfParam->alf_flag) |
---|
785 | { |
---|
786 | return; |
---|
787 | } |
---|
788 | Int pos; |
---|
789 | codeAux(pAlfParam); |
---|
790 | codeFilt(pAlfParam); |
---|
791 | |
---|
792 | // filter parameters for chroma |
---|
793 | m_pcEntropyCoderIf->codeAlfUvlc(pAlfParam->chroma_idc); |
---|
794 | if(pAlfParam->chroma_idc) |
---|
795 | { |
---|
796 | #if !ALF_SINGLE_FILTER_SHAPE |
---|
797 | m_pcEntropyCoderIf->codeAlfUvlc(pAlfParam->filter_shape_chroma); |
---|
798 | #endif |
---|
799 | // filter coefficients for chroma |
---|
800 | for(pos=0; pos<pAlfParam->num_coeff_chroma; pos++) |
---|
801 | { |
---|
802 | m_pcEntropyCoderIf->codeAlfSvlc(pAlfParam->coeff_chroma[pos]); |
---|
803 | } |
---|
804 | } |
---|
805 | #endif |
---|
806 | } |
---|
807 | |
---|
808 | Void TEncEntropy::encodeAlfCtrlFlag( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool bRD ) |
---|
809 | { |
---|
810 | if( bRD ) |
---|
811 | { |
---|
812 | uiAbsPartIdx = 0; |
---|
813 | } |
---|
814 | m_pcEntropyCoderIf->codeAlfCtrlFlag( pcCU, uiAbsPartIdx ); |
---|
815 | } |
---|
816 | |
---|
817 | |
---|
818 | /** Encode ALF CU control flag |
---|
819 | * \param uiFlag ALF CU control flag: 0 or 1 |
---|
820 | */ |
---|
821 | Void TEncEntropy::encodeAlfCtrlFlag(UInt uiFlag) |
---|
822 | { |
---|
823 | assert(uiFlag == 0 || uiFlag == 1); |
---|
824 | m_pcEntropyCoderIf->codeAlfCtrlFlag( uiFlag ); |
---|
825 | } |
---|
826 | |
---|
827 | |
---|
828 | /** Encode ALF CU control flag parameters |
---|
829 | * \param pAlfParam ALF parameters |
---|
830 | */ |
---|
831 | Void TEncEntropy::encodeAlfCtrlParam(AlfCUCtrlInfo& cAlfParam, Int iNumCUsInPic) |
---|
832 | { |
---|
833 | // region control parameters for luma |
---|
834 | m_pcEntropyCoderIf->codeAlfFlag(cAlfParam.cu_control_flag); |
---|
835 | |
---|
836 | if (cAlfParam.cu_control_flag == 0) |
---|
837 | { |
---|
838 | return; |
---|
839 | } |
---|
840 | |
---|
841 | m_pcEntropyCoderIf->codeAlfCtrlDepth(); |
---|
842 | |
---|
843 | Int iSymbol = ((Int)cAlfParam.num_alf_cu_flag - iNumCUsInPic); |
---|
844 | m_pcEntropyCoderIf->codeAlfSvlc(iSymbol); |
---|
845 | |
---|
846 | for(UInt i=0; i< cAlfParam.num_alf_cu_flag; i++) |
---|
847 | { |
---|
848 | m_pcEntropyCoderIf->codeAlfCtrlFlag( cAlfParam.alf_cu_flag[i] ); |
---|
849 | } |
---|
850 | } |
---|
851 | |
---|
852 | /** encode prediction mode |
---|
853 | * \param pcCU |
---|
854 | * \param uiAbsPartIdx |
---|
855 | * \param bRD |
---|
856 | * \returns Void |
---|
857 | */ |
---|
858 | Void TEncEntropy::encodePredMode( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool bRD ) |
---|
859 | { |
---|
860 | if( bRD ) |
---|
861 | { |
---|
862 | uiAbsPartIdx = 0; |
---|
863 | } |
---|
864 | #if BURST_IPCM |
---|
865 | if( !bRD ) |
---|
866 | { |
---|
867 | if( pcCU->getLastCUSucIPCMFlag() && pcCU->getIPCMFlag(uiAbsPartIdx) ) |
---|
868 | { |
---|
869 | return; |
---|
870 | } |
---|
871 | } |
---|
872 | #endif |
---|
873 | |
---|
874 | if ( pcCU->getSlice()->isIntra() ) |
---|
875 | { |
---|
876 | return; |
---|
877 | } |
---|
878 | |
---|
879 | m_pcEntropyCoderIf->codePredMode( pcCU, uiAbsPartIdx ); |
---|
880 | } |
---|
881 | |
---|
882 | // Split mode |
---|
883 | Void TEncEntropy::encodeSplitFlag( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, Bool bRD ) |
---|
884 | { |
---|
885 | if( bRD ) |
---|
886 | { |
---|
887 | uiAbsPartIdx = 0; |
---|
888 | } |
---|
889 | #if BURST_IPCM |
---|
890 | if( !bRD ) |
---|
891 | { |
---|
892 | if( pcCU->getLastCUSucIPCMFlag() && pcCU->getIPCMFlag(uiAbsPartIdx) ) |
---|
893 | { |
---|
894 | return; |
---|
895 | } |
---|
896 | } |
---|
897 | #endif |
---|
898 | |
---|
899 | m_pcEntropyCoderIf->codeSplitFlag( pcCU, uiAbsPartIdx, uiDepth ); |
---|
900 | } |
---|
901 | |
---|
902 | /** encode partition size |
---|
903 | * \param pcCU |
---|
904 | * \param uiAbsPartIdx |
---|
905 | * \param uiDepth |
---|
906 | * \param bRD |
---|
907 | * \returns Void |
---|
908 | */ |
---|
909 | Void TEncEntropy::encodePartSize( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, Bool bRD ) |
---|
910 | { |
---|
911 | if( bRD ) |
---|
912 | { |
---|
913 | uiAbsPartIdx = 0; |
---|
914 | } |
---|
915 | #if BURST_IPCM |
---|
916 | if( !bRD ) |
---|
917 | { |
---|
918 | if( pcCU->getLastCUSucIPCMFlag() && pcCU->getIPCMFlag(uiAbsPartIdx) ) |
---|
919 | { |
---|
920 | return; |
---|
921 | } |
---|
922 | } |
---|
923 | #endif |
---|
924 | m_pcEntropyCoderIf->codePartSize( pcCU, uiAbsPartIdx, uiDepth ); |
---|
925 | } |
---|
926 | |
---|
927 | /** Encode I_PCM information. |
---|
928 | * \param pcCU pointer to CU |
---|
929 | * \param uiAbsPartIdx CU index |
---|
930 | * \param bRD flag indicating estimation or encoding |
---|
931 | * \returns Void |
---|
932 | */ |
---|
933 | Void TEncEntropy::encodeIPCMInfo( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool bRD ) |
---|
934 | { |
---|
935 | if(!pcCU->getSlice()->getSPS()->getUsePCM() |
---|
936 | || pcCU->getWidth(uiAbsPartIdx) > (1<<pcCU->getSlice()->getSPS()->getPCMLog2MaxSize()) |
---|
937 | || pcCU->getWidth(uiAbsPartIdx) < (1<<pcCU->getSlice()->getSPS()->getPCMLog2MinSize())) |
---|
938 | { |
---|
939 | return; |
---|
940 | } |
---|
941 | |
---|
942 | if( bRD ) |
---|
943 | { |
---|
944 | uiAbsPartIdx = 0; |
---|
945 | } |
---|
946 | |
---|
947 | #if BURST_IPCM |
---|
948 | Int numIPCM = 0; |
---|
949 | Bool firstIPCMFlag = false; |
---|
950 | |
---|
951 | if( pcCU->getIPCMFlag(uiAbsPartIdx) ) |
---|
952 | { |
---|
953 | numIPCM = 1; |
---|
954 | firstIPCMFlag = true; |
---|
955 | |
---|
956 | if( !bRD ) |
---|
957 | { |
---|
958 | numIPCM = pcCU->getNumSucIPCM(); |
---|
959 | firstIPCMFlag = !pcCU->getLastCUSucIPCMFlag(); |
---|
960 | } |
---|
961 | } |
---|
962 | m_pcEntropyCoderIf->codeIPCMInfo ( pcCU, uiAbsPartIdx, numIPCM, firstIPCMFlag); |
---|
963 | #else |
---|
964 | m_pcEntropyCoderIf->codeIPCMInfo ( pcCU, uiAbsPartIdx ); |
---|
965 | #endif |
---|
966 | |
---|
967 | } |
---|
968 | |
---|
969 | #if UNIFIED_TRANSFORM_TREE |
---|
970 | Void TEncEntropy::xEncodeTransform( TComDataCU* pcCU,UInt offsetLuma, UInt offsetChroma, UInt uiAbsPartIdx, UInt absTUPartIdx, UInt uiDepth, UInt width, UInt height, UInt uiTrIdx, UInt uiInnerQuadIdx, UInt& uiYCbfFront3, UInt& uiUCbfFront3, UInt& uiVCbfFront3, Bool& bCodeDQP ) |
---|
971 | #else |
---|
972 | Void TEncEntropy::xEncodeTransformSubdiv( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt absTUPartIdx, UInt uiDepth, UInt uiInnerQuadIdx, UInt& uiYCbfFront3, UInt& uiUCbfFront3, UInt& uiVCbfFront3 ) |
---|
973 | #endif |
---|
974 | { |
---|
975 | const UInt uiSubdiv = pcCU->getTransformIdx( uiAbsPartIdx ) + pcCU->getDepth( uiAbsPartIdx ) > uiDepth; |
---|
976 | const UInt uiLog2TrafoSize = g_aucConvertToBit[pcCU->getSlice()->getSPS()->getMaxCUWidth()]+2 - uiDepth; |
---|
977 | #if UNIFIED_TRANSFORM_TREE |
---|
978 | UInt cbfY = pcCU->getCbf( uiAbsPartIdx, TEXT_LUMA , uiTrIdx ); |
---|
979 | UInt cbfU = pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_U, uiTrIdx ); |
---|
980 | UInt cbfV = pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_V, uiTrIdx ); |
---|
981 | |
---|
982 | if(uiTrIdx==0) |
---|
983 | { |
---|
984 | m_bakAbsPartIdxCU = uiAbsPartIdx; |
---|
985 | } |
---|
986 | if( uiLog2TrafoSize == 2 ) |
---|
987 | { |
---|
988 | UInt partNum = pcCU->getPic()->getNumPartInCU() >> ( ( uiDepth - 1 ) << 1 ); |
---|
989 | if( ( uiAbsPartIdx % partNum ) == 0 ) |
---|
990 | { |
---|
991 | m_uiBakAbsPartIdx = uiAbsPartIdx; |
---|
992 | m_uiBakChromaOffset = offsetChroma; |
---|
993 | } |
---|
994 | else if( ( uiAbsPartIdx % partNum ) == (partNum - 1) ) |
---|
995 | { |
---|
996 | cbfU = pcCU->getCbf( m_uiBakAbsPartIdx, TEXT_CHROMA_U, uiTrIdx ); |
---|
997 | cbfV = pcCU->getCbf( m_uiBakAbsPartIdx, TEXT_CHROMA_V, uiTrIdx ); |
---|
998 | } |
---|
999 | } |
---|
1000 | #endif // UNIFIED_TRANSFORM_TREE |
---|
1001 | {//CABAC |
---|
1002 | if( pcCU->getPredictionMode(uiAbsPartIdx) == MODE_INTRA && pcCU->getPartitionSize(uiAbsPartIdx) == SIZE_NxN && uiDepth == pcCU->getDepth(uiAbsPartIdx) ) |
---|
1003 | { |
---|
1004 | assert( uiSubdiv ); |
---|
1005 | } |
---|
1006 | else if( pcCU->getPredictionMode(uiAbsPartIdx) == MODE_INTER && (pcCU->getPartitionSize(uiAbsPartIdx) != SIZE_2Nx2N) && uiDepth == pcCU->getDepth(uiAbsPartIdx) && (pcCU->getSlice()->getSPS()->getQuadtreeTUMaxDepthInter() == 1) ) |
---|
1007 | { |
---|
1008 | if ( uiLog2TrafoSize > pcCU->getQuadtreeTULog2MinSizeInCU(uiAbsPartIdx) ) |
---|
1009 | { |
---|
1010 | assert( uiSubdiv ); |
---|
1011 | } |
---|
1012 | else |
---|
1013 | { |
---|
1014 | assert(!uiSubdiv ); |
---|
1015 | } |
---|
1016 | } |
---|
1017 | else if( uiLog2TrafoSize > pcCU->getSlice()->getSPS()->getQuadtreeTULog2MaxSize() ) |
---|
1018 | { |
---|
1019 | assert( uiSubdiv ); |
---|
1020 | } |
---|
1021 | else if( uiLog2TrafoSize == pcCU->getSlice()->getSPS()->getQuadtreeTULog2MinSize() ) |
---|
1022 | { |
---|
1023 | assert( !uiSubdiv ); |
---|
1024 | } |
---|
1025 | else if( uiLog2TrafoSize == pcCU->getQuadtreeTULog2MinSizeInCU(uiAbsPartIdx) ) |
---|
1026 | { |
---|
1027 | assert( !uiSubdiv ); |
---|
1028 | } |
---|
1029 | else |
---|
1030 | { |
---|
1031 | assert( uiLog2TrafoSize > pcCU->getQuadtreeTULog2MinSizeInCU(uiAbsPartIdx) ); |
---|
1032 | m_pcEntropyCoderIf->codeTransformSubdivFlag( uiSubdiv, uiDepth ); |
---|
1033 | } |
---|
1034 | } |
---|
1035 | |
---|
1036 | { |
---|
1037 | if( uiLog2TrafoSize <= pcCU->getSlice()->getSPS()->getQuadtreeTULog2MaxSize() ) |
---|
1038 | { |
---|
1039 | const UInt uiTrDepthCurr = uiDepth - pcCU->getDepth( uiAbsPartIdx ); |
---|
1040 | const Bool bFirstCbfOfCU = uiLog2TrafoSize == pcCU->getSlice()->getSPS()->getQuadtreeTULog2MaxSize() || uiTrDepthCurr == 0; |
---|
1041 | if( bFirstCbfOfCU || uiLog2TrafoSize > 2 ) |
---|
1042 | { |
---|
1043 | if( bFirstCbfOfCU || pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_U, uiTrDepthCurr - 1 ) ) |
---|
1044 | { |
---|
1045 | if ( uiInnerQuadIdx == 3 && uiUCbfFront3 == 0 && uiLog2TrafoSize < pcCU->getSlice()->getSPS()->getQuadtreeTULog2MaxSize() ) |
---|
1046 | { |
---|
1047 | uiUCbfFront3++; |
---|
1048 | } |
---|
1049 | else |
---|
1050 | { |
---|
1051 | m_pcEntropyCoderIf->codeQtCbf( pcCU, uiAbsPartIdx, TEXT_CHROMA_U, uiTrDepthCurr ); |
---|
1052 | uiUCbfFront3 += pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_U, uiTrDepthCurr ); |
---|
1053 | } |
---|
1054 | } |
---|
1055 | if( bFirstCbfOfCU || pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_V, uiTrDepthCurr - 1 ) ) |
---|
1056 | { |
---|
1057 | if ( uiInnerQuadIdx == 3 && uiVCbfFront3 == 0 && uiLog2TrafoSize < pcCU->getSlice()->getSPS()->getQuadtreeTULog2MaxSize() ) |
---|
1058 | { |
---|
1059 | uiVCbfFront3++; |
---|
1060 | } |
---|
1061 | else |
---|
1062 | { |
---|
1063 | m_pcEntropyCoderIf->codeQtCbf( pcCU, uiAbsPartIdx, TEXT_CHROMA_V, uiTrDepthCurr ); |
---|
1064 | uiVCbfFront3 += pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_V, uiTrDepthCurr ); |
---|
1065 | } |
---|
1066 | } |
---|
1067 | } |
---|
1068 | else if( uiLog2TrafoSize == 2 ) |
---|
1069 | { |
---|
1070 | assert( pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_U, uiTrDepthCurr ) == pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_U, uiTrDepthCurr - 1 ) ); |
---|
1071 | assert( pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_V, uiTrDepthCurr ) == pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_V, uiTrDepthCurr - 1 ) ); |
---|
1072 | |
---|
1073 | uiUCbfFront3 += pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_U, uiTrDepthCurr ); |
---|
1074 | uiVCbfFront3 += pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_V, uiTrDepthCurr ); |
---|
1075 | } |
---|
1076 | } |
---|
1077 | |
---|
1078 | if( uiSubdiv ) |
---|
1079 | { |
---|
1080 | #if UNIFIED_TRANSFORM_TREE |
---|
1081 | UInt size; |
---|
1082 | width >>= 1; |
---|
1083 | height >>= 1; |
---|
1084 | size = width*height; |
---|
1085 | uiTrIdx++; |
---|
1086 | #endif // UNIFIED_TRANSFORM_TREE |
---|
1087 | ++uiDepth; |
---|
1088 | #if UNIFIED_TRANSFORM_TREE |
---|
1089 | const UInt partNum = pcCU->getPic()->getNumPartInCU() >> (uiDepth << 1); |
---|
1090 | #else |
---|
1091 | const UInt uiQPartNum = pcCU->getPic()->getNumPartInCU() >> (uiDepth << 1); |
---|
1092 | #endif |
---|
1093 | |
---|
1094 | UInt uiCurrentCbfY = 0; |
---|
1095 | UInt uiCurrentCbfU = 0; |
---|
1096 | UInt uiCurrentCbfV = 0; |
---|
1097 | |
---|
1098 | #if UNIFIED_TRANSFORM_TREE |
---|
1099 | UInt nsAddr = 0; |
---|
1100 | nsAddr = pcCU->getNSAbsPartIdx( uiLog2TrafoSize-1, uiAbsPartIdx, absTUPartIdx, 0, uiDepth - pcCU->getDepth( uiAbsPartIdx ) ); |
---|
1101 | xEncodeTransform( pcCU, offsetLuma, offsetChroma, uiAbsPartIdx, nsAddr, uiDepth, width, height, uiTrIdx, 0, uiCurrentCbfY, uiCurrentCbfU, uiCurrentCbfV, bCodeDQP ); |
---|
1102 | |
---|
1103 | uiAbsPartIdx += partNum; offsetLuma += size; offsetChroma += (size>>2); |
---|
1104 | nsAddr = pcCU->getNSAbsPartIdx( uiLog2TrafoSize-1, uiAbsPartIdx, absTUPartIdx, 1, uiDepth - pcCU->getDepth( uiAbsPartIdx ) ); |
---|
1105 | xEncodeTransform( pcCU, offsetLuma, offsetChroma, uiAbsPartIdx, nsAddr, uiDepth, width, height, uiTrIdx, 1, uiCurrentCbfY, uiCurrentCbfU, uiCurrentCbfV, bCodeDQP ); |
---|
1106 | |
---|
1107 | uiAbsPartIdx += partNum; offsetLuma += size; offsetChroma += (size>>2); |
---|
1108 | nsAddr = pcCU->getNSAbsPartIdx( uiLog2TrafoSize-1, uiAbsPartIdx, absTUPartIdx, 2, uiDepth - pcCU->getDepth( uiAbsPartIdx ) ); |
---|
1109 | xEncodeTransform( pcCU, offsetLuma, offsetChroma, uiAbsPartIdx, nsAddr, uiDepth, width, height, uiTrIdx, 2, uiCurrentCbfY, uiCurrentCbfU, uiCurrentCbfV, bCodeDQP ); |
---|
1110 | |
---|
1111 | uiAbsPartIdx += partNum; offsetLuma += size; offsetChroma += (size>>2); |
---|
1112 | nsAddr = pcCU->getNSAbsPartIdx( uiLog2TrafoSize-1, uiAbsPartIdx, absTUPartIdx, 3, uiDepth - pcCU->getDepth( uiAbsPartIdx ) ); |
---|
1113 | xEncodeTransform( pcCU, offsetLuma, offsetChroma, uiAbsPartIdx, nsAddr, uiDepth, width, height, uiTrIdx, 3, uiCurrentCbfY, uiCurrentCbfU, uiCurrentCbfV, bCodeDQP ); |
---|
1114 | #else // UNIFIED_TRANSFORM_TREE |
---|
1115 | UInt nsAddr = 0; |
---|
1116 | nsAddr = pcCU->getNSAbsPartIdx( uiLog2TrafoSize-1, uiAbsPartIdx, absTUPartIdx, 0, uiDepth - pcCU->getDepth( uiAbsPartIdx ) ); |
---|
1117 | xEncodeTransformSubdiv( pcCU, uiAbsPartIdx, nsAddr, uiDepth, 0, uiCurrentCbfY, uiCurrentCbfU, uiCurrentCbfV ); |
---|
1118 | |
---|
1119 | uiAbsPartIdx += uiQPartNum; |
---|
1120 | nsAddr = pcCU->getNSAbsPartIdx( uiLog2TrafoSize-1, uiAbsPartIdx, absTUPartIdx, 1, uiDepth - pcCU->getDepth( uiAbsPartIdx ) ); |
---|
1121 | xEncodeTransformSubdiv( pcCU, uiAbsPartIdx, nsAddr, uiDepth, 1, uiCurrentCbfY, uiCurrentCbfU, uiCurrentCbfV ); |
---|
1122 | |
---|
1123 | uiAbsPartIdx += uiQPartNum; |
---|
1124 | nsAddr = pcCU->getNSAbsPartIdx( uiLog2TrafoSize-1, uiAbsPartIdx, absTUPartIdx, 2, uiDepth - pcCU->getDepth( uiAbsPartIdx ) ); |
---|
1125 | xEncodeTransformSubdiv( pcCU, uiAbsPartIdx, nsAddr, uiDepth, 2, uiCurrentCbfY, uiCurrentCbfU, uiCurrentCbfV ); |
---|
1126 | |
---|
1127 | uiAbsPartIdx += uiQPartNum; |
---|
1128 | nsAddr = pcCU->getNSAbsPartIdx( uiLog2TrafoSize-1, uiAbsPartIdx, absTUPartIdx, 3, uiDepth - pcCU->getDepth( uiAbsPartIdx ) ); |
---|
1129 | xEncodeTransformSubdiv( pcCU, uiAbsPartIdx, nsAddr, uiDepth, 3, uiCurrentCbfY, uiCurrentCbfU, uiCurrentCbfV ); |
---|
1130 | #endif // UNIFIED_TRANSFORM_TREE |
---|
1131 | |
---|
1132 | uiYCbfFront3 += uiCurrentCbfY; |
---|
1133 | uiUCbfFront3 += uiCurrentCbfU; |
---|
1134 | uiVCbfFront3 += uiCurrentCbfV; |
---|
1135 | } |
---|
1136 | else |
---|
1137 | { |
---|
1138 | { |
---|
1139 | DTRACE_CABAC_VL( g_nSymbolCounter++ ); |
---|
1140 | DTRACE_CABAC_T( "\tTrIdx: abspart=" ); |
---|
1141 | DTRACE_CABAC_V( uiAbsPartIdx ); |
---|
1142 | DTRACE_CABAC_T( "\tdepth=" ); |
---|
1143 | DTRACE_CABAC_V( uiDepth ); |
---|
1144 | DTRACE_CABAC_T( "\ttrdepth=" ); |
---|
1145 | DTRACE_CABAC_V( pcCU->getTransformIdx( uiAbsPartIdx ) ); |
---|
1146 | DTRACE_CABAC_T( "\n" ); |
---|
1147 | } |
---|
1148 | UInt uiLumaTrMode, uiChromaTrMode; |
---|
1149 | pcCU->convertTransIdx( uiAbsPartIdx, pcCU->getTransformIdx( uiAbsPartIdx ), uiLumaTrMode, uiChromaTrMode ); |
---|
1150 | if(pcCU->getPredictionMode( uiAbsPartIdx ) == MODE_INTER && pcCU->useNonSquarePU( uiAbsPartIdx ) ) |
---|
1151 | { |
---|
1152 | pcCU->setNSQTIdxSubParts( uiLog2TrafoSize, uiAbsPartIdx, absTUPartIdx, uiLumaTrMode ); |
---|
1153 | } |
---|
1154 | if( pcCU->getPredictionMode(uiAbsPartIdx) != MODE_INTRA && uiDepth == pcCU->getDepth( uiAbsPartIdx ) && !pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_U, 0 ) && !pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_V, 0 ) ) |
---|
1155 | { |
---|
1156 | assert( pcCU->getCbf( uiAbsPartIdx, TEXT_LUMA, 0 ) ); |
---|
1157 | // printf( "saved one bin! " ); |
---|
1158 | } |
---|
1159 | else |
---|
1160 | { |
---|
1161 | const UInt uiLog2CUSize = g_aucConvertToBit[pcCU->getSlice()->getSPS()->getMaxCUWidth()] + 2 - pcCU->getDepth( uiAbsPartIdx ); |
---|
1162 | if ( pcCU->getPredictionMode( uiAbsPartIdx ) != MODE_INTRA && uiInnerQuadIdx == 3 && uiYCbfFront3 == 0 && uiUCbfFront3 == 0 && uiVCbfFront3 == 0 |
---|
1163 | && ( uiLog2CUSize <= pcCU->getSlice()->getSPS()->getQuadtreeTULog2MaxSize() + 1 || uiLog2TrafoSize < pcCU->getSlice()->getSPS()->getQuadtreeTULog2MaxSize() ) ) |
---|
1164 | { |
---|
1165 | uiYCbfFront3++; |
---|
1166 | } |
---|
1167 | else |
---|
1168 | { |
---|
1169 | m_pcEntropyCoderIf->codeQtCbf( pcCU, uiAbsPartIdx, TEXT_LUMA, uiLumaTrMode ); |
---|
1170 | uiYCbfFront3 += pcCU->getCbf( uiAbsPartIdx, TEXT_LUMA, uiLumaTrMode ); |
---|
1171 | } |
---|
1172 | } |
---|
1173 | |
---|
1174 | #if UNIFIED_TRANSFORM_TREE |
---|
1175 | if ( cbfY || cbfU || cbfV ) |
---|
1176 | { |
---|
1177 | // dQP: only for LCU once |
---|
1178 | if ( pcCU->getSlice()->getPPS()->getUseDQP() ) |
---|
1179 | { |
---|
1180 | if ( bCodeDQP ) |
---|
1181 | { |
---|
1182 | encodeQP( pcCU, m_bakAbsPartIdxCU ); |
---|
1183 | bCodeDQP = false; |
---|
1184 | } |
---|
1185 | } |
---|
1186 | } |
---|
1187 | if( cbfY ) |
---|
1188 | { |
---|
1189 | Int trWidth = width; |
---|
1190 | Int trHeight = height; |
---|
1191 | pcCU->getNSQTSize( uiTrIdx, uiAbsPartIdx, trWidth, trHeight ); |
---|
1192 | m_pcEntropyCoderIf->codeCoeffNxN( pcCU, (pcCU->getCoeffY()+offsetLuma), uiAbsPartIdx, trWidth, trHeight, uiDepth, TEXT_LUMA ); |
---|
1193 | } |
---|
1194 | if( uiLog2TrafoSize > 2 ) |
---|
1195 | { |
---|
1196 | Int trWidth = width >> 1; |
---|
1197 | Int trHeight = height >> 1; |
---|
1198 | pcCU->getNSQTSize( uiTrIdx, uiAbsPartIdx, trWidth, trHeight ); |
---|
1199 | if( cbfU ) |
---|
1200 | { |
---|
1201 | m_pcEntropyCoderIf->codeCoeffNxN( pcCU, (pcCU->getCoeffCb()+offsetChroma), uiAbsPartIdx, trWidth, trHeight, uiDepth, TEXT_CHROMA_U ); |
---|
1202 | } |
---|
1203 | if( cbfV ) |
---|
1204 | { |
---|
1205 | m_pcEntropyCoderIf->codeCoeffNxN( pcCU, (pcCU->getCoeffCr()+offsetChroma), uiAbsPartIdx, trWidth, trHeight, uiDepth, TEXT_CHROMA_V ); |
---|
1206 | } |
---|
1207 | } |
---|
1208 | else |
---|
1209 | { |
---|
1210 | UInt partNum = pcCU->getPic()->getNumPartInCU() >> ( ( uiDepth - 1 ) << 1 ); |
---|
1211 | if( ( uiAbsPartIdx % partNum ) == (partNum - 1) ) |
---|
1212 | { |
---|
1213 | Int trWidth = width; |
---|
1214 | Int trHeight = height; |
---|
1215 | pcCU->getNSQTSize( uiTrIdx - 1, uiAbsPartIdx, trWidth, trHeight ); |
---|
1216 | if( cbfU ) |
---|
1217 | { |
---|
1218 | m_pcEntropyCoderIf->codeCoeffNxN( pcCU, (pcCU->getCoeffCb()+m_uiBakChromaOffset), m_uiBakAbsPartIdx, trWidth, trHeight, uiDepth, TEXT_CHROMA_U ); |
---|
1219 | } |
---|
1220 | if( cbfV ) |
---|
1221 | { |
---|
1222 | m_pcEntropyCoderIf->codeCoeffNxN( pcCU, (pcCU->getCoeffCr()+m_uiBakChromaOffset), m_uiBakAbsPartIdx, trWidth, trHeight, uiDepth, TEXT_CHROMA_V ); |
---|
1223 | } |
---|
1224 | } |
---|
1225 | } |
---|
1226 | #endif // UNIFIED_TRANSFORM_TREE |
---|
1227 | } |
---|
1228 | } |
---|
1229 | } |
---|
1230 | |
---|
1231 | #if !UNIFIED_TRANSFORM_TREE |
---|
1232 | // transform index |
---|
1233 | Void TEncEntropy::encodeTransformIdx( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, Bool bRD ) |
---|
1234 | { |
---|
1235 | assert( !bRD ); // parameter bRD can be removed |
---|
1236 | if( bRD ) |
---|
1237 | { |
---|
1238 | uiAbsPartIdx = 0; |
---|
1239 | } |
---|
1240 | |
---|
1241 | DTRACE_CABAC_VL( g_nSymbolCounter++ ) |
---|
1242 | DTRACE_CABAC_T( "\tdecodeTransformIdx()\tCUDepth=" ) |
---|
1243 | DTRACE_CABAC_V( uiDepth ) |
---|
1244 | DTRACE_CABAC_T( "\n" ) |
---|
1245 | UInt temp = 0; |
---|
1246 | UInt temp1 = 0; |
---|
1247 | UInt temp2 = 0; |
---|
1248 | xEncodeTransformSubdiv( pcCU, uiAbsPartIdx, uiAbsPartIdx, uiDepth, 0, temp, temp1, temp2 ); |
---|
1249 | } |
---|
1250 | #endif // !UNIFIED_TRANSFORM_TREE |
---|
1251 | |
---|
1252 | // Intra direction for Luma |
---|
1253 | Void TEncEntropy::encodeIntraDirModeLuma ( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
1254 | { |
---|
1255 | m_pcEntropyCoderIf->codeIntraDirLumaAng( pcCU, uiAbsPartIdx ); |
---|
1256 | } |
---|
1257 | |
---|
1258 | // Intra direction for Chroma |
---|
1259 | Void TEncEntropy::encodeIntraDirModeChroma( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool bRD ) |
---|
1260 | { |
---|
1261 | if( bRD ) |
---|
1262 | { |
---|
1263 | uiAbsPartIdx = 0; |
---|
1264 | } |
---|
1265 | |
---|
1266 | m_pcEntropyCoderIf->codeIntraDirChroma( pcCU, uiAbsPartIdx ); |
---|
1267 | } |
---|
1268 | |
---|
1269 | Void TEncEntropy::encodePredInfo( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool bRD ) |
---|
1270 | { |
---|
1271 | if( bRD ) |
---|
1272 | { |
---|
1273 | uiAbsPartIdx = 0; |
---|
1274 | } |
---|
1275 | |
---|
1276 | PartSize eSize = pcCU->getPartitionSize( uiAbsPartIdx ); |
---|
1277 | |
---|
1278 | if( pcCU->isIntra( uiAbsPartIdx ) ) // If it is Intra mode, encode intra prediction mode. |
---|
1279 | { |
---|
1280 | if( eSize == SIZE_NxN ) // if it is NxN size, encode 4 intra directions. |
---|
1281 | { |
---|
1282 | UInt uiPartOffset = ( pcCU->getPic()->getNumPartInCU() >> ( pcCU->getDepth(uiAbsPartIdx) << 1 ) ) >> 2; |
---|
1283 | // if it is NxN size, this size might be the smallest partition size. |
---|
1284 | encodeIntraDirModeLuma( pcCU, uiAbsPartIdx ); |
---|
1285 | encodeIntraDirModeLuma( pcCU, uiAbsPartIdx + uiPartOffset ); |
---|
1286 | encodeIntraDirModeLuma( pcCU, uiAbsPartIdx + uiPartOffset*2 ); |
---|
1287 | encodeIntraDirModeLuma( pcCU, uiAbsPartIdx + uiPartOffset*3 ); |
---|
1288 | encodeIntraDirModeChroma( pcCU, uiAbsPartIdx, bRD ); |
---|
1289 | } |
---|
1290 | else // if it is not NxN size, encode 1 intra directions |
---|
1291 | { |
---|
1292 | encodeIntraDirModeLuma ( pcCU, uiAbsPartIdx ); |
---|
1293 | encodeIntraDirModeChroma( pcCU, uiAbsPartIdx, bRD ); |
---|
1294 | } |
---|
1295 | } |
---|
1296 | else // if it is Inter mode, encode motion vector and reference index |
---|
1297 | { |
---|
1298 | encodePUWise( pcCU, uiAbsPartIdx, bRD ); |
---|
1299 | } |
---|
1300 | } |
---|
1301 | |
---|
1302 | /** encode motion information for every PU block |
---|
1303 | * \param pcCU |
---|
1304 | * \param uiAbsPartIdx |
---|
1305 | * \param bRD |
---|
1306 | * \returns Void |
---|
1307 | */ |
---|
1308 | Void TEncEntropy::encodePUWise( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool bRD ) |
---|
1309 | { |
---|
1310 | if ( bRD ) |
---|
1311 | { |
---|
1312 | uiAbsPartIdx = 0; |
---|
1313 | } |
---|
1314 | |
---|
1315 | PartSize ePartSize = pcCU->getPartitionSize( uiAbsPartIdx ); |
---|
1316 | UInt uiNumPU = ( ePartSize == SIZE_2Nx2N ? 1 : ( ePartSize == SIZE_NxN ? 4 : 2 ) ); |
---|
1317 | UInt uiDepth = pcCU->getDepth( uiAbsPartIdx ); |
---|
1318 | UInt uiPUOffset = ( g_auiPUOffset[UInt( ePartSize )] << ( ( pcCU->getSlice()->getSPS()->getMaxCUDepth() - uiDepth ) << 1 ) ) >> 4; |
---|
1319 | |
---|
1320 | for ( UInt uiPartIdx = 0, uiSubPartIdx = uiAbsPartIdx; uiPartIdx < uiNumPU; uiPartIdx++, uiSubPartIdx += uiPUOffset ) |
---|
1321 | { |
---|
1322 | encodeMergeFlag( pcCU, uiSubPartIdx, uiPartIdx ); |
---|
1323 | if ( pcCU->getMergeFlag( uiSubPartIdx ) ) |
---|
1324 | { |
---|
1325 | encodeMergeIndex( pcCU, uiSubPartIdx, uiPartIdx ); |
---|
1326 | } |
---|
1327 | else |
---|
1328 | { |
---|
1329 | encodeInterDirPU( pcCU, uiSubPartIdx ); |
---|
1330 | for ( UInt uiRefListIdx = 0; uiRefListIdx < 2; uiRefListIdx++ ) |
---|
1331 | { |
---|
1332 | if ( pcCU->getSlice()->getNumRefIdx( RefPicList( uiRefListIdx ) ) > 0 ) |
---|
1333 | { |
---|
1334 | encodeRefFrmIdxPU ( pcCU, uiSubPartIdx, RefPicList( uiRefListIdx ) ); |
---|
1335 | encodeMvdPU ( pcCU, uiSubPartIdx, RefPicList( uiRefListIdx ) ); |
---|
1336 | encodeMVPIdxPU ( pcCU, uiSubPartIdx, RefPicList( uiRefListIdx ) ); |
---|
1337 | } |
---|
1338 | } |
---|
1339 | } |
---|
1340 | } |
---|
1341 | |
---|
1342 | return; |
---|
1343 | } |
---|
1344 | |
---|
1345 | Void TEncEntropy::encodeInterDirPU( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
1346 | { |
---|
1347 | if ( !pcCU->getSlice()->isInterB() ) |
---|
1348 | { |
---|
1349 | return; |
---|
1350 | } |
---|
1351 | |
---|
1352 | m_pcEntropyCoderIf->codeInterDir( pcCU, uiAbsPartIdx ); |
---|
1353 | return; |
---|
1354 | } |
---|
1355 | |
---|
1356 | /** encode reference frame index for a PU block |
---|
1357 | * \param pcCU |
---|
1358 | * \param uiAbsPartIdx |
---|
1359 | * \param eRefList |
---|
1360 | * \returns Void |
---|
1361 | */ |
---|
1362 | Void TEncEntropy::encodeRefFrmIdxPU( TComDataCU* pcCU, UInt uiAbsPartIdx, RefPicList eRefList ) |
---|
1363 | { |
---|
1364 | assert( !pcCU->isIntra( uiAbsPartIdx ) ); |
---|
1365 | |
---|
1366 | if(pcCU->getSlice()->getNumRefIdx(REF_PIC_LIST_C)>0 && pcCU->getInterDir( uiAbsPartIdx ) != 3) |
---|
1367 | { |
---|
1368 | if ((eRefList== REF_PIC_LIST_1) || ( pcCU->getSlice()->getNumRefIdx( REF_PIC_LIST_C ) == 1 ) ) |
---|
1369 | { |
---|
1370 | return; |
---|
1371 | } |
---|
1372 | |
---|
1373 | if ( pcCU->getSlice()->getNumRefIdx ( REF_PIC_LIST_C ) > 1 ) |
---|
1374 | { |
---|
1375 | m_pcEntropyCoderIf->codeRefFrmIdx( pcCU, uiAbsPartIdx, RefPicList(pcCU->getInterDir( uiAbsPartIdx )-1) ); |
---|
1376 | } |
---|
1377 | |
---|
1378 | } |
---|
1379 | else |
---|
1380 | { |
---|
1381 | if ( ( pcCU->getSlice()->getNumRefIdx( eRefList ) == 1 ) ) |
---|
1382 | { |
---|
1383 | return; |
---|
1384 | } |
---|
1385 | |
---|
1386 | if ( pcCU->getInterDir( uiAbsPartIdx ) & ( 1 << eRefList ) ) |
---|
1387 | { |
---|
1388 | m_pcEntropyCoderIf->codeRefFrmIdx( pcCU, uiAbsPartIdx, eRefList ); |
---|
1389 | } |
---|
1390 | } |
---|
1391 | |
---|
1392 | return; |
---|
1393 | } |
---|
1394 | |
---|
1395 | /** encode motion vector difference for a PU block |
---|
1396 | * \param pcCU |
---|
1397 | * \param uiAbsPartIdx |
---|
1398 | * \param eRefList |
---|
1399 | * \returns Void |
---|
1400 | */ |
---|
1401 | Void TEncEntropy::encodeMvdPU( TComDataCU* pcCU, UInt uiAbsPartIdx, RefPicList eRefList ) |
---|
1402 | { |
---|
1403 | assert( !pcCU->isIntra( uiAbsPartIdx ) ); |
---|
1404 | |
---|
1405 | if ( pcCU->getInterDir( uiAbsPartIdx ) & ( 1 << eRefList ) ) |
---|
1406 | { |
---|
1407 | m_pcEntropyCoderIf->codeMvd( pcCU, uiAbsPartIdx, eRefList ); |
---|
1408 | } |
---|
1409 | return; |
---|
1410 | } |
---|
1411 | |
---|
1412 | Void TEncEntropy::encodeMVPIdxPU( TComDataCU* pcCU, UInt uiAbsPartIdx, RefPicList eRefList ) |
---|
1413 | { |
---|
1414 | if ( (pcCU->getInterDir( uiAbsPartIdx ) & ( 1 << eRefList )) && (pcCU->getAMVPMode(uiAbsPartIdx) == AM_EXPL) ) |
---|
1415 | { |
---|
1416 | #if HHI_INTER_VIEW_MOTION_PRED |
---|
1417 | const Int iNumCands = AMVP_MAX_NUM_CANDS + ( pcCU->getSlice()->getSPS()->getMultiviewMvPredMode() ? 1 : 0 ); |
---|
1418 | m_pcEntropyCoderIf->codeMVPIdx( pcCU, uiAbsPartIdx, eRefList, iNumCands ); |
---|
1419 | #else |
---|
1420 | m_pcEntropyCoderIf->codeMVPIdx( pcCU, uiAbsPartIdx, eRefList ); |
---|
1421 | #endif |
---|
1422 | } |
---|
1423 | |
---|
1424 | return; |
---|
1425 | } |
---|
1426 | |
---|
1427 | Void TEncEntropy::encodeQtCbf( TComDataCU* pcCU, UInt uiAbsPartIdx, TextType eType, UInt uiTrDepth ) |
---|
1428 | { |
---|
1429 | m_pcEntropyCoderIf->codeQtCbf( pcCU, uiAbsPartIdx, eType, uiTrDepth ); |
---|
1430 | } |
---|
1431 | |
---|
1432 | Void TEncEntropy::encodeTransformSubdivFlag( UInt uiSymbol, UInt uiCtx ) |
---|
1433 | { |
---|
1434 | m_pcEntropyCoderIf->codeTransformSubdivFlag( uiSymbol, uiCtx ); |
---|
1435 | } |
---|
1436 | |
---|
1437 | Void TEncEntropy::encodeQtRootCbf( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
1438 | { |
---|
1439 | m_pcEntropyCoderIf->codeQtRootCbf( pcCU, uiAbsPartIdx ); |
---|
1440 | } |
---|
1441 | |
---|
1442 | // dQP |
---|
1443 | Void TEncEntropy::encodeQP( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool bRD ) |
---|
1444 | { |
---|
1445 | if( bRD ) |
---|
1446 | { |
---|
1447 | uiAbsPartIdx = 0; |
---|
1448 | } |
---|
1449 | |
---|
1450 | if ( pcCU->getSlice()->getPPS()->getUseDQP() ) |
---|
1451 | { |
---|
1452 | m_pcEntropyCoderIf->codeDeltaQP( pcCU, uiAbsPartIdx ); |
---|
1453 | } |
---|
1454 | } |
---|
1455 | |
---|
1456 | |
---|
1457 | // texture |
---|
1458 | #if !UNIFIED_TRANSFORM_TREE |
---|
1459 | Void TEncEntropy::xEncodeCoeff( TComDataCU* pcCU, UInt uiLumaOffset, UInt uiChromaOffset, UInt uiAbsPartIdx, UInt uiDepth, UInt uiWidth, UInt uiHeight, UInt uiTrIdx, UInt uiCurrTrIdx, Bool& bCodeDQP ) |
---|
1460 | { |
---|
1461 | UInt uiLog2TrSize = g_aucConvertToBit[ pcCU->getSlice()->getSPS()->getMaxCUWidth() >> uiDepth ] + 2; |
---|
1462 | UInt uiCbfY = pcCU->getCbf( uiAbsPartIdx, TEXT_LUMA, uiTrIdx ); |
---|
1463 | UInt uiCbfU = pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_U, uiTrIdx ); |
---|
1464 | UInt uiCbfV = pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_V, uiTrIdx ); |
---|
1465 | |
---|
1466 | if( uiLog2TrSize == 2 ) |
---|
1467 | { |
---|
1468 | UInt uiQPDiv = pcCU->getPic()->getNumPartInCU() >> ( ( uiDepth - 1 ) << 1 ); |
---|
1469 | if( ( uiAbsPartIdx % uiQPDiv ) == 0 ) |
---|
1470 | { |
---|
1471 | m_uiBakAbsPartIdx = uiAbsPartIdx; |
---|
1472 | m_uiBakChromaOffset = uiChromaOffset; |
---|
1473 | } |
---|
1474 | else if( ( uiAbsPartIdx % uiQPDiv ) == (uiQPDiv - 1) ) |
---|
1475 | { |
---|
1476 | uiCbfU = pcCU->getCbf( m_uiBakAbsPartIdx, TEXT_CHROMA_U, uiTrIdx ); |
---|
1477 | uiCbfV = pcCU->getCbf( m_uiBakAbsPartIdx, TEXT_CHROMA_V, uiTrIdx ); |
---|
1478 | } |
---|
1479 | } |
---|
1480 | |
---|
1481 | if ( uiCbfY || uiCbfU || uiCbfV ) |
---|
1482 | { |
---|
1483 | // dQP: only for LCU once |
---|
1484 | if ( pcCU->getSlice()->getPPS()->getUseDQP() ) |
---|
1485 | { |
---|
1486 | if ( bCodeDQP ) |
---|
1487 | { |
---|
1488 | encodeQP( pcCU, uiAbsPartIdx ); |
---|
1489 | bCodeDQP = false; |
---|
1490 | } |
---|
1491 | } |
---|
1492 | UInt uiLumaTrMode, uiChromaTrMode; |
---|
1493 | pcCU->convertTransIdx( uiAbsPartIdx, pcCU->getTransformIdx( uiAbsPartIdx ), uiLumaTrMode, uiChromaTrMode ); |
---|
1494 | const UInt uiStopTrMode = uiLumaTrMode; |
---|
1495 | |
---|
1496 | assert(1); // as long as quadtrees are not used for residual transform |
---|
1497 | |
---|
1498 | if( uiTrIdx == uiStopTrMode ) |
---|
1499 | { |
---|
1500 | if( pcCU->getCbf( uiAbsPartIdx, TEXT_LUMA, uiTrIdx ) ) |
---|
1501 | { |
---|
1502 | Int trWidth = uiWidth; |
---|
1503 | Int trHeight = uiHeight; |
---|
1504 | pcCU->getNSQTSize( uiTrIdx, uiAbsPartIdx, trWidth, trHeight ); |
---|
1505 | m_pcEntropyCoderIf->codeCoeffNxN( pcCU, (pcCU->getCoeffY()+uiLumaOffset), uiAbsPartIdx, trWidth, trHeight, uiDepth, TEXT_LUMA ); |
---|
1506 | } |
---|
1507 | |
---|
1508 | uiWidth >>= 1; |
---|
1509 | uiHeight >>= 1; |
---|
1510 | |
---|
1511 | if( uiLog2TrSize == 2 ) |
---|
1512 | { |
---|
1513 | UInt uiQPDiv = pcCU->getPic()->getNumPartInCU() >> ( ( uiDepth - 1 ) << 1 ); |
---|
1514 | if( ( uiAbsPartIdx % uiQPDiv ) == (uiQPDiv - 1) ) |
---|
1515 | { |
---|
1516 | uiWidth <<= 1; |
---|
1517 | uiHeight <<= 1; |
---|
1518 | Int trWidth = uiWidth; |
---|
1519 | Int trHeight = uiHeight; |
---|
1520 | pcCU->getNSQTSize( uiTrIdx-1, uiAbsPartIdx, trWidth, trHeight ); |
---|
1521 | if( pcCU->getCbf( m_uiBakAbsPartIdx, TEXT_CHROMA_U, uiTrIdx ) ) |
---|
1522 | { |
---|
1523 | m_pcEntropyCoderIf->codeCoeffNxN( pcCU, (pcCU->getCoeffCb()+m_uiBakChromaOffset), m_uiBakAbsPartIdx, trWidth, trHeight, uiDepth, TEXT_CHROMA_U ); |
---|
1524 | } |
---|
1525 | if( pcCU->getCbf( m_uiBakAbsPartIdx, TEXT_CHROMA_V, uiTrIdx ) ) |
---|
1526 | { |
---|
1527 | m_pcEntropyCoderIf->codeCoeffNxN( pcCU, (pcCU->getCoeffCr()+m_uiBakChromaOffset), m_uiBakAbsPartIdx, trWidth, trHeight, uiDepth, TEXT_CHROMA_V ); |
---|
1528 | } |
---|
1529 | } |
---|
1530 | } |
---|
1531 | else |
---|
1532 | { |
---|
1533 | Int trWidth = uiWidth; |
---|
1534 | Int trHeight = uiHeight; |
---|
1535 | pcCU->getNSQTSize( uiTrIdx, uiAbsPartIdx, trWidth, trHeight ); |
---|
1536 | if( pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_U, uiTrIdx ) ) |
---|
1537 | { |
---|
1538 | m_pcEntropyCoderIf->codeCoeffNxN( pcCU, (pcCU->getCoeffCb()+uiChromaOffset), uiAbsPartIdx, trWidth, trHeight, uiDepth, TEXT_CHROMA_U ); |
---|
1539 | } |
---|
1540 | if( pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_V, uiTrIdx ) ) |
---|
1541 | { |
---|
1542 | m_pcEntropyCoderIf->codeCoeffNxN( pcCU, (pcCU->getCoeffCr()+uiChromaOffset), uiAbsPartIdx, trWidth, trHeight, uiDepth, TEXT_CHROMA_V ); |
---|
1543 | } |
---|
1544 | } |
---|
1545 | } |
---|
1546 | else |
---|
1547 | { |
---|
1548 | { |
---|
1549 | DTRACE_CABAC_VL( g_nSymbolCounter++ ); |
---|
1550 | DTRACE_CABAC_T( "\tgoing down\tdepth=" ); |
---|
1551 | DTRACE_CABAC_V( uiDepth ); |
---|
1552 | DTRACE_CABAC_T( "\ttridx=" ); |
---|
1553 | DTRACE_CABAC_V( uiTrIdx ); |
---|
1554 | DTRACE_CABAC_T( "\n" ); |
---|
1555 | } |
---|
1556 | if( uiCurrTrIdx <= uiTrIdx ) |
---|
1557 | assert(1); |
---|
1558 | |
---|
1559 | UInt uiSize; |
---|
1560 | uiWidth >>= 1; |
---|
1561 | uiHeight >>= 1; |
---|
1562 | uiSize = uiWidth*uiHeight; |
---|
1563 | uiDepth++; |
---|
1564 | uiTrIdx++; |
---|
1565 | |
---|
1566 | UInt uiQPartNum = pcCU->getPic()->getNumPartInCU() >> (uiDepth << 1); |
---|
1567 | UInt uiIdx = uiAbsPartIdx; |
---|
1568 | |
---|
1569 | { |
---|
1570 | xEncodeCoeff( pcCU, uiLumaOffset, uiChromaOffset, uiIdx, uiDepth, uiWidth, uiHeight, uiTrIdx, uiCurrTrIdx, bCodeDQP ); |
---|
1571 | uiLumaOffset += uiSize; uiChromaOffset += (uiSize>>2); uiIdx += uiQPartNum; |
---|
1572 | |
---|
1573 | xEncodeCoeff( pcCU, uiLumaOffset, uiChromaOffset, uiIdx, uiDepth, uiWidth, uiHeight, uiTrIdx, uiCurrTrIdx, bCodeDQP ); |
---|
1574 | uiLumaOffset += uiSize; uiChromaOffset += (uiSize>>2); uiIdx += uiQPartNum; |
---|
1575 | |
---|
1576 | xEncodeCoeff( pcCU, uiLumaOffset, uiChromaOffset, uiIdx, uiDepth, uiWidth, uiHeight, uiTrIdx, uiCurrTrIdx, bCodeDQP ); |
---|
1577 | uiLumaOffset += uiSize; uiChromaOffset += (uiSize>>2); uiIdx += uiQPartNum; |
---|
1578 | |
---|
1579 | xEncodeCoeff( pcCU, uiLumaOffset, uiChromaOffset, uiIdx, uiDepth, uiWidth, uiHeight, uiTrIdx, uiCurrTrIdx, bCodeDQP ); |
---|
1580 | } |
---|
1581 | { |
---|
1582 | DTRACE_CABAC_VL( g_nSymbolCounter++ ); |
---|
1583 | DTRACE_CABAC_T( "\tgoing up\n" ); |
---|
1584 | } |
---|
1585 | } |
---|
1586 | } |
---|
1587 | } |
---|
1588 | #endif // !UNIFIED_TRANSFORM_TREE |
---|
1589 | |
---|
1590 | /** encode coefficients |
---|
1591 | * \param pcCU |
---|
1592 | * \param uiAbsPartIdx |
---|
1593 | * \param uiDepth |
---|
1594 | * \param uiWidth |
---|
1595 | * \param uiHeight |
---|
1596 | */ |
---|
1597 | Void TEncEntropy::encodeCoeff( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, UInt uiWidth, UInt uiHeight, Bool& bCodeDQP ) |
---|
1598 | { |
---|
1599 | UInt uiMinCoeffSize = pcCU->getPic()->getMinCUWidth()*pcCU->getPic()->getMinCUHeight(); |
---|
1600 | UInt uiLumaOffset = uiMinCoeffSize*uiAbsPartIdx; |
---|
1601 | UInt uiChromaOffset = uiLumaOffset>>2; |
---|
1602 | |
---|
1603 | UInt uiLumaTrMode, uiChromaTrMode; |
---|
1604 | pcCU->convertTransIdx( uiAbsPartIdx, pcCU->getTransformIdx(uiAbsPartIdx), uiLumaTrMode, uiChromaTrMode ); |
---|
1605 | |
---|
1606 | if( pcCU->isIntra(uiAbsPartIdx) ) |
---|
1607 | { |
---|
1608 | DTRACE_CABAC_VL( g_nSymbolCounter++ ) |
---|
1609 | DTRACE_CABAC_T( "\tdecodeTransformIdx()\tCUDepth=" ) |
---|
1610 | DTRACE_CABAC_V( uiDepth ) |
---|
1611 | DTRACE_CABAC_T( "\n" ) |
---|
1612 | #if !UNIFIED_TRANSFORM_TREE |
---|
1613 | UInt temp = 0; |
---|
1614 | UInt temp1 = 0; |
---|
1615 | UInt temp2 = 0; |
---|
1616 | xEncodeTransformSubdiv( pcCU, uiAbsPartIdx, uiAbsPartIdx, uiDepth, 0, temp, temp1, temp2 ); |
---|
1617 | #endif // !UNIFIED_TRANSFORM_TREE |
---|
1618 | } |
---|
1619 | else |
---|
1620 | { |
---|
1621 | { |
---|
1622 | #if HHI_MPI |
---|
1623 | if( !(pcCU->getMergeFlag( uiAbsPartIdx ) && pcCU->getPartitionSize(uiAbsPartIdx) == SIZE_2Nx2N && |
---|
1624 | ( pcCU->getTextureModeDepth( uiAbsPartIdx ) == -1 || uiDepth == pcCU->getTextureModeDepth( uiAbsPartIdx ) ) ) ) |
---|
1625 | #else |
---|
1626 | if( !(pcCU->getMergeFlag( uiAbsPartIdx ) && pcCU->getPartitionSize(uiAbsPartIdx) == SIZE_2Nx2N ) ) |
---|
1627 | #endif |
---|
1628 | { |
---|
1629 | m_pcEntropyCoderIf->codeQtRootCbf( pcCU, uiAbsPartIdx ); |
---|
1630 | } |
---|
1631 | if ( !pcCU->getQtRootCbf( uiAbsPartIdx ) ) |
---|
1632 | { |
---|
1633 | #if 1 // MW Bug Fix |
---|
1634 | pcCU->setCbfSubParts( 0, 0, 0, uiAbsPartIdx, uiDepth ); |
---|
1635 | pcCU->setTrIdxSubParts( 0 , uiAbsPartIdx, uiDepth ); |
---|
1636 | #endif |
---|
1637 | pcCU->setNSQTIdxSubParts( uiAbsPartIdx, uiDepth ); |
---|
1638 | return; |
---|
1639 | } |
---|
1640 | } |
---|
1641 | #if !UNIFIED_TRANSFORM_TREE |
---|
1642 | encodeTransformIdx( pcCU, uiAbsPartIdx, pcCU->getDepth(uiAbsPartIdx) ); |
---|
1643 | #endif |
---|
1644 | } |
---|
1645 | |
---|
1646 | #if UNIFIED_TRANSFORM_TREE |
---|
1647 | UInt temp = 0; |
---|
1648 | UInt temp1 = 0; |
---|
1649 | UInt temp2 = 0; |
---|
1650 | xEncodeTransform( pcCU, uiLumaOffset, uiChromaOffset, uiAbsPartIdx, uiAbsPartIdx, uiDepth, uiWidth, uiHeight, 0, 0, temp, temp1, temp2, bCodeDQP ); |
---|
1651 | #else // UNIFIED_TRANSFORM_TREE |
---|
1652 | xEncodeCoeff( pcCU, uiLumaOffset, uiChromaOffset, uiAbsPartIdx, uiDepth, uiWidth, uiHeight, 0, uiLumaTrMode, bCodeDQP ); |
---|
1653 | #endif // UNIFIED_TRANSFORM_TREE |
---|
1654 | } |
---|
1655 | |
---|
1656 | Void TEncEntropy::encodeCoeffNxN( TComDataCU* pcCU, TCoeff* pcCoeff, UInt uiAbsPartIdx, UInt uiTrWidth, UInt uiTrHeight, UInt uiDepth, TextType eType ) |
---|
1657 | { // This is for Transform unit processing. This may be used at mode selection stage for Inter. |
---|
1658 | m_pcEntropyCoderIf->codeCoeffNxN( pcCU, pcCoeff, uiAbsPartIdx, uiTrWidth, uiTrHeight, uiDepth, eType ); |
---|
1659 | } |
---|
1660 | |
---|
1661 | Void TEncEntropy::estimateBit (estBitsSbacStruct* pcEstBitsSbac, Int width, Int height, TextType eTType) |
---|
1662 | { |
---|
1663 | eTType = eTType == TEXT_LUMA ? TEXT_LUMA : TEXT_CHROMA; |
---|
1664 | |
---|
1665 | m_pcEntropyCoderIf->estBit ( pcEstBitsSbac, width, height, eTType ); |
---|
1666 | } |
---|
1667 | |
---|
1668 | #if SAO_UNIT_INTERLEAVING |
---|
1669 | /** Encode SAO Offset |
---|
1670 | * \param saoLcuParam SAO LCU paramters |
---|
1671 | */ |
---|
1672 | Void TEncEntropy::encodeSaoOffset(SaoLcuParam* saoLcuParam) |
---|
1673 | { |
---|
1674 | UInt uiSymbol; |
---|
1675 | Int i; |
---|
1676 | |
---|
1677 | uiSymbol = saoLcuParam->typeIdx + 1; |
---|
1678 | m_pcEntropyCoderIf->codeSaoTypeIdx(uiSymbol); |
---|
1679 | if (uiSymbol) |
---|
1680 | { |
---|
1681 | if( saoLcuParam->typeIdx == SAO_BO ) |
---|
1682 | { |
---|
1683 | // Code Left Band Index |
---|
1684 | uiSymbol = (UInt) (saoLcuParam->bandPosition); |
---|
1685 | m_pcEntropyCoderIf->codeSaoUflc(uiSymbol); |
---|
1686 | for( i=0; i< saoLcuParam->length; i++) |
---|
1687 | { |
---|
1688 | m_pcEntropyCoderIf->codeSaoSvlc(saoLcuParam->offset[i]); |
---|
1689 | } |
---|
1690 | } |
---|
1691 | else |
---|
1692 | if( saoLcuParam->typeIdx < 4 ) |
---|
1693 | { |
---|
1694 | m_pcEntropyCoderIf->codeSaoUvlc( saoLcuParam->offset[0]); |
---|
1695 | m_pcEntropyCoderIf->codeSaoUvlc( saoLcuParam->offset[1]); |
---|
1696 | m_pcEntropyCoderIf->codeSaoUvlc(-saoLcuParam->offset[2]); |
---|
1697 | m_pcEntropyCoderIf->codeSaoUvlc(-saoLcuParam->offset[3]); |
---|
1698 | } |
---|
1699 | } |
---|
1700 | } |
---|
1701 | /** Encode SAO unit |
---|
1702 | * \param rx |
---|
1703 | * \param ry |
---|
1704 | * \param iCompIdx |
---|
1705 | * \param pSaoParam |
---|
1706 | * \param bRepeatedRow |
---|
1707 | */ |
---|
1708 | Void TEncEntropy::encodeSaoUnit(Int rx, Int ry, Int compIdx, SAOParam* saoParam, Int repeatedRow ) |
---|
1709 | { |
---|
1710 | int addr, addrLeft; |
---|
1711 | int numCuInWidth = saoParam->numCuInWidth; |
---|
1712 | SaoLcuParam* saoOneLcu; |
---|
1713 | Int runLeft; |
---|
1714 | |
---|
1715 | addr = rx + ry*numCuInWidth; |
---|
1716 | addrLeft = (addr%numCuInWidth == 0) ? -1 : addr - 1; |
---|
1717 | |
---|
1718 | if (!repeatedRow) |
---|
1719 | { |
---|
1720 | saoOneLcu = &(saoParam->saoLcuParam[compIdx][addr]); |
---|
1721 | runLeft = (addrLeft>=0 ) ? saoParam->saoLcuParam[compIdx][addrLeft].run : -1; |
---|
1722 | if (rx == 0 || runLeft==0) |
---|
1723 | { |
---|
1724 | if (ry == 0) |
---|
1725 | { |
---|
1726 | m_pcEntropyCoderIf->codeSaoRun(saoOneLcu->runDiff, numCuInWidth-rx-1); |
---|
1727 | saoOneLcu->mergeUpFlag = 0; |
---|
1728 | } |
---|
1729 | else |
---|
1730 | { |
---|
1731 | m_pcEntropyCoderIf->codeSaoSvlc(saoOneLcu->runDiff); |
---|
1732 | m_pcEntropyCoderIf->codeSaoFlag(saoOneLcu->mergeUpFlag); |
---|
1733 | } |
---|
1734 | if (!saoOneLcu->mergeUpFlag) |
---|
1735 | { |
---|
1736 | encodeSaoOffset(saoOneLcu); |
---|
1737 | } |
---|
1738 | } |
---|
1739 | } |
---|
1740 | } |
---|
1741 | |
---|
1742 | /** Encode SAO unit interleaving |
---|
1743 | * \param rx |
---|
1744 | * \param ry |
---|
1745 | * \param pSaoParam |
---|
1746 | * \param pcCU |
---|
1747 | * \param iCUAddrInSlice |
---|
1748 | * \param iCUAddrUpInSlice |
---|
1749 | * \param bLFCrossSliceBoundaryFlag |
---|
1750 | */ |
---|
1751 | Void TEncEntropy::encodeSaoUnitInterleaving(Int rx, Int ry, SAOParam* saoParam, TComDataCU* cu, Int cuAddrInSlice, Int cuAddrUpInSlice, Bool lfCrossSliceBoundaryFlag) |
---|
1752 | { |
---|
1753 | Int addr = cu->getAddr(); |
---|
1754 | for (Int compIdx=0; compIdx<3; compIdx++) |
---|
1755 | { |
---|
1756 | if (saoParam->bSaoFlag[compIdx]) |
---|
1757 | { |
---|
1758 | if (rx>0 && cuAddrInSlice!=0) |
---|
1759 | { |
---|
1760 | m_pcEntropyCoderIf->codeSaoMergeLeft(saoParam->saoLcuParam[compIdx][addr].mergeLeftFlag,compIdx); |
---|
1761 | } |
---|
1762 | else |
---|
1763 | { |
---|
1764 | saoParam->saoLcuParam[compIdx][addr].mergeLeftFlag = 0; |
---|
1765 | } |
---|
1766 | if (saoParam->saoLcuParam[compIdx][addr].mergeLeftFlag == 0) |
---|
1767 | { |
---|
1768 | if ( (ry > 0) && (cuAddrUpInSlice>0||lfCrossSliceBoundaryFlag)) |
---|
1769 | { |
---|
1770 | m_pcEntropyCoderIf->codeSaoMergeUp(saoParam->saoLcuParam[compIdx][addr].mergeUpFlag); |
---|
1771 | } |
---|
1772 | else |
---|
1773 | { |
---|
1774 | saoParam->saoLcuParam[compIdx][addr].mergeUpFlag = 0; |
---|
1775 | } |
---|
1776 | if (!saoParam->saoLcuParam[compIdx][addr].mergeUpFlag) |
---|
1777 | { |
---|
1778 | encodeSaoOffset(&(saoParam->saoLcuParam[compIdx][addr])); |
---|
1779 | } |
---|
1780 | } |
---|
1781 | } |
---|
1782 | } |
---|
1783 | } |
---|
1784 | |
---|
1785 | /** Encode SAO parameter |
---|
1786 | * \param pcAPS |
---|
1787 | */ |
---|
1788 | Void TEncEntropy::encodeSaoParam(TComAPS* aps) |
---|
1789 | { |
---|
1790 | SaoLcuParam* psSaoOneLcu; |
---|
1791 | int i,j,k, compIdx; |
---|
1792 | int numCuInWidth ; |
---|
1793 | int numCuInHeight ; |
---|
1794 | Bool repeatedRow[3]; |
---|
1795 | Int addr; |
---|
1796 | m_pcEntropyCoderIf->codeSaoFlag(aps->getSaoInterleavingFlag()); |
---|
1797 | if(!aps->getSaoInterleavingFlag()) |
---|
1798 | { |
---|
1799 | m_pcEntropyCoderIf->codeSaoFlag(aps->getSaoEnabled()); |
---|
1800 | if (aps->getSaoEnabled()) |
---|
1801 | { |
---|
1802 | SAOParam* pSaoParam = aps->getSaoParam(); |
---|
1803 | numCuInWidth = pSaoParam->numCuInWidth; |
---|
1804 | numCuInHeight = pSaoParam->numCuInHeight; |
---|
1805 | m_pcEntropyCoderIf->codeSaoFlag(pSaoParam->bSaoFlag[1]); |
---|
1806 | m_pcEntropyCoderIf->codeSaoFlag(pSaoParam->bSaoFlag[2]); |
---|
1807 | m_pcEntropyCoderIf->codeSaoUvlc(numCuInWidth-1); |
---|
1808 | m_pcEntropyCoderIf->codeSaoUvlc(numCuInHeight-1); |
---|
1809 | for (compIdx=0;compIdx<3;compIdx++) |
---|
1810 | { |
---|
1811 | if (pSaoParam->bSaoFlag[compIdx]) |
---|
1812 | { |
---|
1813 | m_pcEntropyCoderIf->codeSaoFlag(pSaoParam->oneUnitFlag[compIdx]); |
---|
1814 | if (pSaoParam->oneUnitFlag[compIdx]) |
---|
1815 | { |
---|
1816 | psSaoOneLcu = &(pSaoParam->saoLcuParam[compIdx][0]); |
---|
1817 | encodeSaoOffset(psSaoOneLcu); |
---|
1818 | } |
---|
1819 | } |
---|
1820 | } |
---|
1821 | |
---|
1822 | for (j=0;j<numCuInHeight;j++) |
---|
1823 | { |
---|
1824 | for (compIdx=0; compIdx<3; compIdx++) |
---|
1825 | { |
---|
1826 | repeatedRow[compIdx] = true; |
---|
1827 | for (k=0;k<numCuInWidth;k++) |
---|
1828 | { |
---|
1829 | addr = k + j*numCuInWidth; |
---|
1830 | psSaoOneLcu = &(pSaoParam->saoLcuParam[compIdx][addr]); |
---|
1831 | if (!psSaoOneLcu->mergeUpFlag || psSaoOneLcu->runDiff) |
---|
1832 | { |
---|
1833 | repeatedRow[compIdx] = false; |
---|
1834 | break; |
---|
1835 | } |
---|
1836 | } |
---|
1837 | } |
---|
1838 | for (i=0;i<numCuInWidth;i++) |
---|
1839 | { |
---|
1840 | for (compIdx=0; compIdx<3; compIdx++) |
---|
1841 | { |
---|
1842 | if (pSaoParam->bSaoFlag[compIdx] && !pSaoParam->oneUnitFlag[compIdx]) |
---|
1843 | { |
---|
1844 | if (j>0 && i==0) |
---|
1845 | { |
---|
1846 | m_pcEntropyCoderIf->codeSaoFlag(repeatedRow[compIdx]); |
---|
1847 | } |
---|
1848 | encodeSaoUnit (i,j, compIdx, pSaoParam, repeatedRow[compIdx]); |
---|
1849 | } |
---|
1850 | } |
---|
1851 | } |
---|
1852 | } |
---|
1853 | } |
---|
1854 | } |
---|
1855 | } |
---|
1856 | #else |
---|
1857 | /** Encode SAO for one partition |
---|
1858 | * \param pSaoParam, iPartIdx |
---|
1859 | */ |
---|
1860 | Void TEncEntropy::encodeSaoOnePart(SAOParam* pSaoParam, Int iPartIdx, Int iYCbCr) |
---|
1861 | { |
---|
1862 | SAOQTPart* pAlfPart = NULL; |
---|
1863 | pAlfPart = &(pSaoParam->psSaoPart[iYCbCr][iPartIdx]); |
---|
1864 | |
---|
1865 | UInt uiSymbol; |
---|
1866 | |
---|
1867 | if(!pAlfPart->bSplit) |
---|
1868 | { |
---|
1869 | if (pAlfPart->bEnableFlag) |
---|
1870 | { |
---|
1871 | uiSymbol = pAlfPart->iBestType + 1; |
---|
1872 | } |
---|
1873 | else |
---|
1874 | { |
---|
1875 | uiSymbol = 0; |
---|
1876 | } |
---|
1877 | |
---|
1878 | m_pcEntropyCoderIf->codeSaoUvlc(uiSymbol); |
---|
1879 | |
---|
1880 | if (pAlfPart->bEnableFlag) |
---|
1881 | { |
---|
1882 | for(Int i=0; i< pAlfPart->iLength; i++) |
---|
1883 | { |
---|
1884 | m_pcEntropyCoderIf->codeSaoSvlc(pAlfPart->iOffset[i]); |
---|
1885 | } |
---|
1886 | } |
---|
1887 | return; |
---|
1888 | } |
---|
1889 | |
---|
1890 | //split |
---|
1891 | if (pAlfPart->PartLevel < pSaoParam->iMaxSplitLevel) |
---|
1892 | { |
---|
1893 | for (Int i=0;i<NUM_DOWN_PART;i++) |
---|
1894 | { |
---|
1895 | encodeSaoOnePart(pSaoParam, pAlfPart->DownPartsIdx[i], iYCbCr); |
---|
1896 | } |
---|
1897 | } |
---|
1898 | } |
---|
1899 | |
---|
1900 | /** Encode quadtree split flag |
---|
1901 | * \param pSaoParam, iPartIdx |
---|
1902 | */ |
---|
1903 | Void TEncEntropy::encodeQuadTreeSplitFlag(SAOParam* pSaoParam, Int iPartIdx, Int iYCbCr) |
---|
1904 | { |
---|
1905 | SAOQTPart* pSaoPart = NULL; |
---|
1906 | pSaoPart = &(pSaoParam->psSaoPart[iYCbCr][iPartIdx]); |
---|
1907 | |
---|
1908 | if(pSaoPart->PartLevel < pSaoParam->iMaxSplitLevel) |
---|
1909 | { |
---|
1910 | //send one flag |
---|
1911 | m_pcEntropyCoderIf->codeSaoFlag( (pSaoPart->bSplit)?(1):(0) ); |
---|
1912 | |
---|
1913 | if(pSaoPart->bSplit) |
---|
1914 | { |
---|
1915 | for (Int i=0;i<NUM_DOWN_PART;i++) |
---|
1916 | { |
---|
1917 | encodeQuadTreeSplitFlag(pSaoParam, pSaoPart->DownPartsIdx[i], iYCbCr); |
---|
1918 | } |
---|
1919 | } |
---|
1920 | } |
---|
1921 | } |
---|
1922 | /** Encode SAO parameters |
---|
1923 | * \param pSaoParam |
---|
1924 | */ |
---|
1925 | Void TEncEntropy::encodeSaoParam(SAOParam* pSaoParam) |
---|
1926 | { |
---|
1927 | if (pSaoParam->bSaoFlag[0]) |
---|
1928 | { |
---|
1929 | encodeQuadTreeSplitFlag(pSaoParam, 0, 0); |
---|
1930 | encodeSaoOnePart(pSaoParam, 0, 0); |
---|
1931 | m_pcEntropyCoderIf->codeSaoFlag(pSaoParam->bSaoFlag[1]); |
---|
1932 | if (pSaoParam->bSaoFlag[1]) |
---|
1933 | { |
---|
1934 | encodeQuadTreeSplitFlag(pSaoParam, 0, 1); |
---|
1935 | encodeSaoOnePart(pSaoParam, 0, 1); |
---|
1936 | } |
---|
1937 | m_pcEntropyCoderIf->codeSaoFlag(pSaoParam->bSaoFlag[2]); |
---|
1938 | if (pSaoParam->bSaoFlag[2]) |
---|
1939 | { |
---|
1940 | encodeQuadTreeSplitFlag(pSaoParam, 0, 2); |
---|
1941 | encodeSaoOnePart(pSaoParam, 0, 2); |
---|
1942 | } |
---|
1943 | } |
---|
1944 | } |
---|
1945 | #endif |
---|
1946 | |
---|
1947 | Int TEncEntropy::countNonZeroCoeffs( TCoeff* pcCoef, UInt uiSize ) |
---|
1948 | { |
---|
1949 | Int count = 0; |
---|
1950 | |
---|
1951 | for ( Int i = 0; i < uiSize; i++ ) |
---|
1952 | { |
---|
1953 | count += pcCoef[i] != 0; |
---|
1954 | } |
---|
1955 | |
---|
1956 | return count; |
---|
1957 | } |
---|
1958 | |
---|
1959 | /** encode quantization matrix |
---|
1960 | * \param scalingList quantization matrix information |
---|
1961 | */ |
---|
1962 | Void TEncEntropy::encodeScalingList( TComScalingList* scalingList ) |
---|
1963 | { |
---|
1964 | m_pcEntropyCoderIf->codeScalingList( scalingList ); |
---|
1965 | } |
---|
1966 | |
---|
1967 | Void TEncEntropy::encodeDFParams(TComAPS* pcAPS) |
---|
1968 | { |
---|
1969 | m_pcEntropyCoderIf->codeDFFlag(pcAPS->getLoopFilterDisable(), "loop_filter_disable"); |
---|
1970 | |
---|
1971 | if (!pcAPS->getLoopFilterDisable()) |
---|
1972 | { |
---|
1973 | m_pcEntropyCoderIf->codeDFSvlc(pcAPS->getLoopFilterBetaOffset(), "beta_offset_div2"); |
---|
1974 | m_pcEntropyCoderIf->codeDFSvlc(pcAPS->getLoopFilterTcOffset(), "tc_offset_div2"); |
---|
1975 | } |
---|
1976 | } |
---|
1977 | |
---|
1978 | //! \} |
---|