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