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