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