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