[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 | |
---|
[77] | 123 | #if VIDYO_VPS_INTEGRATION |
---|
| 124 | Void TEncEntropy::encodeVPS( TComVPS* pcVPS ) |
---|
| 125 | { |
---|
| 126 | m_pcEntropyCoderIf->codeVPS( pcVPS ); |
---|
| 127 | return; |
---|
| 128 | } |
---|
| 129 | #endif |
---|
| 130 | |
---|
| 131 | #if VIDYO_VPS_INTEGRATION |
---|
| 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 | |
---|
[152] | 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 | |
---|
[2] | 907 | if ( pcCU->getSlice()->isIntra() ) |
---|
| 908 | { |
---|
| 909 | return; |
---|
| 910 | } |
---|
[56] | 911 | |
---|
[2] | 912 | m_pcEntropyCoderIf->codePredMode( pcCU, uiAbsPartIdx ); |
---|
| 913 | } |
---|
| 914 | |
---|
| 915 | // Split mode |
---|
| 916 | Void TEncEntropy::encodeSplitFlag( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, Bool bRD ) |
---|
| 917 | { |
---|
| 918 | if( bRD ) |
---|
[56] | 919 | { |
---|
[2] | 920 | uiAbsPartIdx = 0; |
---|
[56] | 921 | } |
---|
| 922 | #if BURST_IPCM |
---|
| 923 | if( !bRD ) |
---|
| 924 | { |
---|
| 925 | if( pcCU->getLastCUSucIPCMFlag() && pcCU->getIPCMFlag(uiAbsPartIdx) ) |
---|
| 926 | { |
---|
| 927 | return; |
---|
| 928 | } |
---|
| 929 | } |
---|
| 930 | #endif |
---|
| 931 | |
---|
[2] | 932 | m_pcEntropyCoderIf->codeSplitFlag( pcCU, uiAbsPartIdx, uiDepth ); |
---|
| 933 | } |
---|
| 934 | |
---|
| 935 | /** encode partition size |
---|
| 936 | * \param pcCU |
---|
| 937 | * \param uiAbsPartIdx |
---|
| 938 | * \param uiDepth |
---|
| 939 | * \param bRD |
---|
| 940 | * \returns Void |
---|
| 941 | */ |
---|
| 942 | Void TEncEntropy::encodePartSize( 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 |
---|
[2] | 957 | m_pcEntropyCoderIf->codePartSize( pcCU, uiAbsPartIdx, uiDepth ); |
---|
| 958 | } |
---|
| 959 | |
---|
[56] | 960 | /** Encode I_PCM information. |
---|
| 961 | * \param pcCU pointer to CU |
---|
| 962 | * \param uiAbsPartIdx CU index |
---|
| 963 | * \param bRD flag indicating estimation or encoding |
---|
| 964 | * \returns Void |
---|
| 965 | */ |
---|
| 966 | Void TEncEntropy::encodeIPCMInfo( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool bRD ) |
---|
[2] | 967 | { |
---|
[56] | 968 | if(!pcCU->getSlice()->getSPS()->getUsePCM() |
---|
| 969 | || pcCU->getWidth(uiAbsPartIdx) > (1<<pcCU->getSlice()->getSPS()->getPCMLog2MaxSize()) |
---|
| 970 | || pcCU->getWidth(uiAbsPartIdx) < (1<<pcCU->getSlice()->getSPS()->getPCMLog2MinSize())) |
---|
| 971 | { |
---|
| 972 | return; |
---|
| 973 | } |
---|
| 974 | |
---|
| 975 | if( bRD ) |
---|
| 976 | { |
---|
| 977 | uiAbsPartIdx = 0; |
---|
| 978 | } |
---|
| 979 | |
---|
| 980 | #if BURST_IPCM |
---|
| 981 | Int numIPCM = 0; |
---|
| 982 | Bool firstIPCMFlag = false; |
---|
| 983 | |
---|
| 984 | if( pcCU->getIPCMFlag(uiAbsPartIdx) ) |
---|
| 985 | { |
---|
| 986 | numIPCM = 1; |
---|
| 987 | firstIPCMFlag = true; |
---|
| 988 | |
---|
| 989 | if( !bRD ) |
---|
| 990 | { |
---|
| 991 | numIPCM = pcCU->getNumSucIPCM(); |
---|
| 992 | firstIPCMFlag = !pcCU->getLastCUSucIPCMFlag(); |
---|
| 993 | } |
---|
| 994 | } |
---|
| 995 | m_pcEntropyCoderIf->codeIPCMInfo ( pcCU, uiAbsPartIdx, numIPCM, firstIPCMFlag); |
---|
| 996 | #else |
---|
| 997 | m_pcEntropyCoderIf->codeIPCMInfo ( pcCU, uiAbsPartIdx ); |
---|
| 998 | #endif |
---|
| 999 | |
---|
| 1000 | } |
---|
| 1001 | |
---|
| 1002 | #if UNIFIED_TRANSFORM_TREE |
---|
| 1003 | 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 ) |
---|
| 1004 | #else |
---|
| 1005 | Void TEncEntropy::xEncodeTransformSubdiv( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt absTUPartIdx, UInt uiDepth, UInt uiInnerQuadIdx, UInt& uiYCbfFront3, UInt& uiUCbfFront3, UInt& uiVCbfFront3 ) |
---|
| 1006 | #endif |
---|
| 1007 | { |
---|
[2] | 1008 | const UInt uiSubdiv = pcCU->getTransformIdx( uiAbsPartIdx ) + pcCU->getDepth( uiAbsPartIdx ) > uiDepth; |
---|
| 1009 | const UInt uiLog2TrafoSize = g_aucConvertToBit[pcCU->getSlice()->getSPS()->getMaxCUWidth()]+2 - uiDepth; |
---|
[56] | 1010 | #if UNIFIED_TRANSFORM_TREE |
---|
| 1011 | UInt cbfY = pcCU->getCbf( uiAbsPartIdx, TEXT_LUMA , uiTrIdx ); |
---|
| 1012 | UInt cbfU = pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_U, uiTrIdx ); |
---|
| 1013 | UInt cbfV = pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_V, uiTrIdx ); |
---|
| 1014 | |
---|
| 1015 | if(uiTrIdx==0) |
---|
[2] | 1016 | { |
---|
[56] | 1017 | m_bakAbsPartIdxCU = uiAbsPartIdx; |
---|
[2] | 1018 | } |
---|
[56] | 1019 | if( uiLog2TrafoSize == 2 ) |
---|
[2] | 1020 | { |
---|
[56] | 1021 | UInt partNum = pcCU->getPic()->getNumPartInCU() >> ( ( uiDepth - 1 ) << 1 ); |
---|
| 1022 | if( ( uiAbsPartIdx % partNum ) == 0 ) |
---|
| 1023 | { |
---|
| 1024 | m_uiBakAbsPartIdx = uiAbsPartIdx; |
---|
| 1025 | m_uiBakChromaOffset = offsetChroma; |
---|
| 1026 | } |
---|
| 1027 | else if( ( uiAbsPartIdx % partNum ) == (partNum - 1) ) |
---|
| 1028 | { |
---|
| 1029 | cbfU = pcCU->getCbf( m_uiBakAbsPartIdx, TEXT_CHROMA_U, uiTrIdx ); |
---|
| 1030 | cbfV = pcCU->getCbf( m_uiBakAbsPartIdx, TEXT_CHROMA_V, uiTrIdx ); |
---|
| 1031 | } |
---|
[2] | 1032 | } |
---|
[56] | 1033 | #endif // UNIFIED_TRANSFORM_TREE |
---|
| 1034 | {//CABAC |
---|
| 1035 | if( pcCU->getPredictionMode(uiAbsPartIdx) == MODE_INTRA && pcCU->getPartitionSize(uiAbsPartIdx) == SIZE_NxN && uiDepth == pcCU->getDepth(uiAbsPartIdx) ) |
---|
[2] | 1036 | { |
---|
| 1037 | assert( uiSubdiv ); |
---|
| 1038 | } |
---|
[56] | 1039 | else if( pcCU->getPredictionMode(uiAbsPartIdx) == MODE_INTER && (pcCU->getPartitionSize(uiAbsPartIdx) != SIZE_2Nx2N) && uiDepth == pcCU->getDepth(uiAbsPartIdx) && (pcCU->getSlice()->getSPS()->getQuadtreeTUMaxDepthInter() == 1) ) |
---|
| 1040 | { |
---|
| 1041 | if ( uiLog2TrafoSize > pcCU->getQuadtreeTULog2MinSizeInCU(uiAbsPartIdx) ) |
---|
| 1042 | { |
---|
| 1043 | assert( uiSubdiv ); |
---|
| 1044 | } |
---|
| 1045 | else |
---|
| 1046 | { |
---|
| 1047 | assert(!uiSubdiv ); |
---|
| 1048 | } |
---|
| 1049 | } |
---|
| 1050 | else if( uiLog2TrafoSize > pcCU->getSlice()->getSPS()->getQuadtreeTULog2MaxSize() ) |
---|
| 1051 | { |
---|
| 1052 | assert( uiSubdiv ); |
---|
| 1053 | } |
---|
[2] | 1054 | else if( uiLog2TrafoSize == pcCU->getSlice()->getSPS()->getQuadtreeTULog2MinSize() ) |
---|
| 1055 | { |
---|
| 1056 | assert( !uiSubdiv ); |
---|
| 1057 | } |
---|
| 1058 | else if( uiLog2TrafoSize == pcCU->getQuadtreeTULog2MinSizeInCU(uiAbsPartIdx) ) |
---|
| 1059 | { |
---|
| 1060 | assert( !uiSubdiv ); |
---|
| 1061 | } |
---|
| 1062 | else |
---|
| 1063 | { |
---|
| 1064 | assert( uiLog2TrafoSize > pcCU->getQuadtreeTULog2MinSizeInCU(uiAbsPartIdx) ); |
---|
| 1065 | m_pcEntropyCoderIf->codeTransformSubdivFlag( uiSubdiv, uiDepth ); |
---|
| 1066 | } |
---|
| 1067 | } |
---|
[56] | 1068 | |
---|
[2] | 1069 | { |
---|
[56] | 1070 | if( uiLog2TrafoSize <= pcCU->getSlice()->getSPS()->getQuadtreeTULog2MaxSize() ) |
---|
[2] | 1071 | { |
---|
| 1072 | const UInt uiTrDepthCurr = uiDepth - pcCU->getDepth( uiAbsPartIdx ); |
---|
| 1073 | const Bool bFirstCbfOfCU = uiLog2TrafoSize == pcCU->getSlice()->getSPS()->getQuadtreeTULog2MaxSize() || uiTrDepthCurr == 0; |
---|
[56] | 1074 | if( bFirstCbfOfCU || uiLog2TrafoSize > 2 ) |
---|
[2] | 1075 | { |
---|
| 1076 | if( bFirstCbfOfCU || pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_U, uiTrDepthCurr - 1 ) ) |
---|
| 1077 | { |
---|
| 1078 | if ( uiInnerQuadIdx == 3 && uiUCbfFront3 == 0 && uiLog2TrafoSize < pcCU->getSlice()->getSPS()->getQuadtreeTULog2MaxSize() ) |
---|
| 1079 | { |
---|
| 1080 | uiUCbfFront3++; |
---|
| 1081 | } |
---|
| 1082 | else |
---|
| 1083 | { |
---|
| 1084 | m_pcEntropyCoderIf->codeQtCbf( pcCU, uiAbsPartIdx, TEXT_CHROMA_U, uiTrDepthCurr ); |
---|
| 1085 | uiUCbfFront3 += pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_U, uiTrDepthCurr ); |
---|
| 1086 | } |
---|
| 1087 | } |
---|
| 1088 | if( bFirstCbfOfCU || pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_V, uiTrDepthCurr - 1 ) ) |
---|
| 1089 | { |
---|
| 1090 | if ( uiInnerQuadIdx == 3 && uiVCbfFront3 == 0 && uiLog2TrafoSize < pcCU->getSlice()->getSPS()->getQuadtreeTULog2MaxSize() ) |
---|
| 1091 | { |
---|
| 1092 | uiVCbfFront3++; |
---|
| 1093 | } |
---|
| 1094 | else |
---|
| 1095 | { |
---|
| 1096 | m_pcEntropyCoderIf->codeQtCbf( pcCU, uiAbsPartIdx, TEXT_CHROMA_V, uiTrDepthCurr ); |
---|
| 1097 | uiVCbfFront3 += pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_V, uiTrDepthCurr ); |
---|
| 1098 | } |
---|
| 1099 | } |
---|
| 1100 | } |
---|
[56] | 1101 | else if( uiLog2TrafoSize == 2 ) |
---|
[2] | 1102 | { |
---|
| 1103 | assert( pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_U, uiTrDepthCurr ) == pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_U, uiTrDepthCurr - 1 ) ); |
---|
| 1104 | assert( pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_V, uiTrDepthCurr ) == pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_V, uiTrDepthCurr - 1 ) ); |
---|
| 1105 | |
---|
| 1106 | uiUCbfFront3 += pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_U, uiTrDepthCurr ); |
---|
| 1107 | uiVCbfFront3 += pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_V, uiTrDepthCurr ); |
---|
| 1108 | } |
---|
| 1109 | } |
---|
| 1110 | |
---|
| 1111 | if( uiSubdiv ) |
---|
| 1112 | { |
---|
[56] | 1113 | #if UNIFIED_TRANSFORM_TREE |
---|
| 1114 | UInt size; |
---|
| 1115 | width >>= 1; |
---|
| 1116 | height >>= 1; |
---|
| 1117 | size = width*height; |
---|
| 1118 | uiTrIdx++; |
---|
| 1119 | #endif // UNIFIED_TRANSFORM_TREE |
---|
[2] | 1120 | ++uiDepth; |
---|
[56] | 1121 | #if UNIFIED_TRANSFORM_TREE |
---|
| 1122 | const UInt partNum = pcCU->getPic()->getNumPartInCU() >> (uiDepth << 1); |
---|
| 1123 | #else |
---|
[2] | 1124 | const UInt uiQPartNum = pcCU->getPic()->getNumPartInCU() >> (uiDepth << 1); |
---|
[56] | 1125 | #endif |
---|
[2] | 1126 | |
---|
| 1127 | UInt uiCurrentCbfY = 0; |
---|
| 1128 | UInt uiCurrentCbfU = 0; |
---|
| 1129 | UInt uiCurrentCbfV = 0; |
---|
| 1130 | |
---|
[56] | 1131 | #if UNIFIED_TRANSFORM_TREE |
---|
| 1132 | UInt nsAddr = 0; |
---|
| 1133 | nsAddr = pcCU->getNSAbsPartIdx( uiLog2TrafoSize-1, uiAbsPartIdx, absTUPartIdx, 0, uiDepth - pcCU->getDepth( uiAbsPartIdx ) ); |
---|
| 1134 | xEncodeTransform( pcCU, offsetLuma, offsetChroma, uiAbsPartIdx, nsAddr, uiDepth, width, height, uiTrIdx, 0, uiCurrentCbfY, uiCurrentCbfU, uiCurrentCbfV, bCodeDQP ); |
---|
| 1135 | |
---|
| 1136 | uiAbsPartIdx += partNum; offsetLuma += size; offsetChroma += (size>>2); |
---|
| 1137 | nsAddr = pcCU->getNSAbsPartIdx( uiLog2TrafoSize-1, uiAbsPartIdx, absTUPartIdx, 1, uiDepth - pcCU->getDepth( uiAbsPartIdx ) ); |
---|
| 1138 | xEncodeTransform( pcCU, offsetLuma, offsetChroma, uiAbsPartIdx, nsAddr, uiDepth, width, height, uiTrIdx, 1, uiCurrentCbfY, uiCurrentCbfU, uiCurrentCbfV, bCodeDQP ); |
---|
| 1139 | |
---|
| 1140 | uiAbsPartIdx += partNum; offsetLuma += size; offsetChroma += (size>>2); |
---|
| 1141 | nsAddr = pcCU->getNSAbsPartIdx( uiLog2TrafoSize-1, uiAbsPartIdx, absTUPartIdx, 2, uiDepth - pcCU->getDepth( uiAbsPartIdx ) ); |
---|
| 1142 | xEncodeTransform( pcCU, offsetLuma, offsetChroma, uiAbsPartIdx, nsAddr, uiDepth, width, height, uiTrIdx, 2, uiCurrentCbfY, uiCurrentCbfU, uiCurrentCbfV, bCodeDQP ); |
---|
| 1143 | |
---|
| 1144 | uiAbsPartIdx += partNum; offsetLuma += size; offsetChroma += (size>>2); |
---|
| 1145 | nsAddr = pcCU->getNSAbsPartIdx( uiLog2TrafoSize-1, uiAbsPartIdx, absTUPartIdx, 3, uiDepth - pcCU->getDepth( uiAbsPartIdx ) ); |
---|
| 1146 | xEncodeTransform( pcCU, offsetLuma, offsetChroma, uiAbsPartIdx, nsAddr, uiDepth, width, height, uiTrIdx, 3, uiCurrentCbfY, uiCurrentCbfU, uiCurrentCbfV, bCodeDQP ); |
---|
| 1147 | #else // UNIFIED_TRANSFORM_TREE |
---|
| 1148 | UInt nsAddr = 0; |
---|
| 1149 | nsAddr = pcCU->getNSAbsPartIdx( uiLog2TrafoSize-1, uiAbsPartIdx, absTUPartIdx, 0, uiDepth - pcCU->getDepth( uiAbsPartIdx ) ); |
---|
| 1150 | xEncodeTransformSubdiv( pcCU, uiAbsPartIdx, nsAddr, uiDepth, 0, uiCurrentCbfY, uiCurrentCbfU, uiCurrentCbfV ); |
---|
| 1151 | |
---|
[2] | 1152 | uiAbsPartIdx += uiQPartNum; |
---|
[56] | 1153 | nsAddr = pcCU->getNSAbsPartIdx( uiLog2TrafoSize-1, uiAbsPartIdx, absTUPartIdx, 1, uiDepth - pcCU->getDepth( uiAbsPartIdx ) ); |
---|
| 1154 | xEncodeTransformSubdiv( pcCU, uiAbsPartIdx, nsAddr, uiDepth, 1, uiCurrentCbfY, uiCurrentCbfU, uiCurrentCbfV ); |
---|
| 1155 | |
---|
[2] | 1156 | uiAbsPartIdx += uiQPartNum; |
---|
[56] | 1157 | nsAddr = pcCU->getNSAbsPartIdx( uiLog2TrafoSize-1, uiAbsPartIdx, absTUPartIdx, 2, uiDepth - pcCU->getDepth( uiAbsPartIdx ) ); |
---|
| 1158 | xEncodeTransformSubdiv( pcCU, uiAbsPartIdx, nsAddr, uiDepth, 2, uiCurrentCbfY, uiCurrentCbfU, uiCurrentCbfV ); |
---|
| 1159 | |
---|
[2] | 1160 | uiAbsPartIdx += uiQPartNum; |
---|
[56] | 1161 | nsAddr = pcCU->getNSAbsPartIdx( uiLog2TrafoSize-1, uiAbsPartIdx, absTUPartIdx, 3, uiDepth - pcCU->getDepth( uiAbsPartIdx ) ); |
---|
| 1162 | xEncodeTransformSubdiv( pcCU, uiAbsPartIdx, nsAddr, uiDepth, 3, uiCurrentCbfY, uiCurrentCbfU, uiCurrentCbfV ); |
---|
| 1163 | #endif // UNIFIED_TRANSFORM_TREE |
---|
[2] | 1164 | |
---|
| 1165 | uiYCbfFront3 += uiCurrentCbfY; |
---|
| 1166 | uiUCbfFront3 += uiCurrentCbfU; |
---|
| 1167 | uiVCbfFront3 += uiCurrentCbfV; |
---|
| 1168 | } |
---|
| 1169 | else |
---|
| 1170 | { |
---|
| 1171 | { |
---|
[56] | 1172 | DTRACE_CABAC_VL( g_nSymbolCounter++ ); |
---|
[2] | 1173 | DTRACE_CABAC_T( "\tTrIdx: abspart=" ); |
---|
| 1174 | DTRACE_CABAC_V( uiAbsPartIdx ); |
---|
| 1175 | DTRACE_CABAC_T( "\tdepth=" ); |
---|
| 1176 | DTRACE_CABAC_V( uiDepth ); |
---|
| 1177 | DTRACE_CABAC_T( "\ttrdepth=" ); |
---|
| 1178 | DTRACE_CABAC_V( pcCU->getTransformIdx( uiAbsPartIdx ) ); |
---|
| 1179 | DTRACE_CABAC_T( "\n" ); |
---|
| 1180 | } |
---|
| 1181 | UInt uiLumaTrMode, uiChromaTrMode; |
---|
| 1182 | pcCU->convertTransIdx( uiAbsPartIdx, pcCU->getTransformIdx( uiAbsPartIdx ), uiLumaTrMode, uiChromaTrMode ); |
---|
[56] | 1183 | if(pcCU->getPredictionMode( uiAbsPartIdx ) == MODE_INTER && pcCU->useNonSquarePU( uiAbsPartIdx ) ) |
---|
| 1184 | { |
---|
| 1185 | pcCU->setNSQTIdxSubParts( uiLog2TrafoSize, uiAbsPartIdx, absTUPartIdx, uiLumaTrMode ); |
---|
| 1186 | } |
---|
[2] | 1187 | if( pcCU->getPredictionMode(uiAbsPartIdx) != MODE_INTRA && uiDepth == pcCU->getDepth( uiAbsPartIdx ) && !pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_U, 0 ) && !pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_V, 0 ) ) |
---|
| 1188 | { |
---|
| 1189 | assert( pcCU->getCbf( uiAbsPartIdx, TEXT_LUMA, 0 ) ); |
---|
| 1190 | // printf( "saved one bin! " ); |
---|
| 1191 | } |
---|
| 1192 | else |
---|
| 1193 | { |
---|
[56] | 1194 | const UInt uiLog2CUSize = g_aucConvertToBit[pcCU->getSlice()->getSPS()->getMaxCUWidth()] + 2 - pcCU->getDepth( uiAbsPartIdx ); |
---|
[2] | 1195 | if ( pcCU->getPredictionMode( uiAbsPartIdx ) != MODE_INTRA && uiInnerQuadIdx == 3 && uiYCbfFront3 == 0 && uiUCbfFront3 == 0 && uiVCbfFront3 == 0 |
---|
[56] | 1196 | && ( uiLog2CUSize <= pcCU->getSlice()->getSPS()->getQuadtreeTULog2MaxSize() + 1 || uiLog2TrafoSize < pcCU->getSlice()->getSPS()->getQuadtreeTULog2MaxSize() ) ) |
---|
[2] | 1197 | { |
---|
| 1198 | uiYCbfFront3++; |
---|
| 1199 | } |
---|
| 1200 | else |
---|
| 1201 | { |
---|
| 1202 | m_pcEntropyCoderIf->codeQtCbf( pcCU, uiAbsPartIdx, TEXT_LUMA, uiLumaTrMode ); |
---|
| 1203 | uiYCbfFront3 += pcCU->getCbf( uiAbsPartIdx, TEXT_LUMA, uiLumaTrMode ); |
---|
| 1204 | } |
---|
| 1205 | } |
---|
| 1206 | |
---|
[56] | 1207 | #if UNIFIED_TRANSFORM_TREE |
---|
| 1208 | if ( cbfY || cbfU || cbfV ) |
---|
[2] | 1209 | { |
---|
[56] | 1210 | // dQP: only for LCU once |
---|
| 1211 | if ( pcCU->getSlice()->getPPS()->getUseDQP() ) |
---|
[2] | 1212 | { |
---|
[56] | 1213 | if ( bCodeDQP ) |
---|
| 1214 | { |
---|
| 1215 | encodeQP( pcCU, m_bakAbsPartIdxCU ); |
---|
| 1216 | bCodeDQP = false; |
---|
| 1217 | } |
---|
[2] | 1218 | } |
---|
[56] | 1219 | } |
---|
| 1220 | if( cbfY ) |
---|
| 1221 | { |
---|
| 1222 | Int trWidth = width; |
---|
| 1223 | Int trHeight = height; |
---|
| 1224 | pcCU->getNSQTSize( uiTrIdx, uiAbsPartIdx, trWidth, trHeight ); |
---|
| 1225 | m_pcEntropyCoderIf->codeCoeffNxN( pcCU, (pcCU->getCoeffY()+offsetLuma), uiAbsPartIdx, trWidth, trHeight, uiDepth, TEXT_LUMA ); |
---|
| 1226 | } |
---|
| 1227 | if( uiLog2TrafoSize > 2 ) |
---|
| 1228 | { |
---|
| 1229 | Int trWidth = width >> 1; |
---|
| 1230 | Int trHeight = height >> 1; |
---|
| 1231 | pcCU->getNSQTSize( uiTrIdx, uiAbsPartIdx, trWidth, trHeight ); |
---|
| 1232 | if( cbfU ) |
---|
[2] | 1233 | { |
---|
[56] | 1234 | m_pcEntropyCoderIf->codeCoeffNxN( pcCU, (pcCU->getCoeffCb()+offsetChroma), uiAbsPartIdx, trWidth, trHeight, uiDepth, TEXT_CHROMA_U ); |
---|
[2] | 1235 | } |
---|
[56] | 1236 | if( cbfV ) |
---|
| 1237 | { |
---|
| 1238 | m_pcEntropyCoderIf->codeCoeffNxN( pcCU, (pcCU->getCoeffCr()+offsetChroma), uiAbsPartIdx, trWidth, trHeight, uiDepth, TEXT_CHROMA_V ); |
---|
| 1239 | } |
---|
[2] | 1240 | } |
---|
[56] | 1241 | else |
---|
| 1242 | { |
---|
| 1243 | UInt partNum = pcCU->getPic()->getNumPartInCU() >> ( ( uiDepth - 1 ) << 1 ); |
---|
| 1244 | if( ( uiAbsPartIdx % partNum ) == (partNum - 1) ) |
---|
| 1245 | { |
---|
| 1246 | Int trWidth = width; |
---|
| 1247 | Int trHeight = height; |
---|
| 1248 | pcCU->getNSQTSize( uiTrIdx - 1, uiAbsPartIdx, trWidth, trHeight ); |
---|
| 1249 | if( cbfU ) |
---|
| 1250 | { |
---|
| 1251 | m_pcEntropyCoderIf->codeCoeffNxN( pcCU, (pcCU->getCoeffCb()+m_uiBakChromaOffset), m_uiBakAbsPartIdx, trWidth, trHeight, uiDepth, TEXT_CHROMA_U ); |
---|
| 1252 | } |
---|
| 1253 | if( cbfV ) |
---|
| 1254 | { |
---|
| 1255 | m_pcEntropyCoderIf->codeCoeffNxN( pcCU, (pcCU->getCoeffCr()+m_uiBakChromaOffset), m_uiBakAbsPartIdx, trWidth, trHeight, uiDepth, TEXT_CHROMA_V ); |
---|
| 1256 | } |
---|
| 1257 | } |
---|
| 1258 | } |
---|
| 1259 | #endif // UNIFIED_TRANSFORM_TREE |
---|
[2] | 1260 | } |
---|
| 1261 | } |
---|
| 1262 | } |
---|
| 1263 | |
---|
[56] | 1264 | #if !UNIFIED_TRANSFORM_TREE |
---|
[2] | 1265 | // transform index |
---|
| 1266 | Void TEncEntropy::encodeTransformIdx( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, Bool bRD ) |
---|
| 1267 | { |
---|
| 1268 | assert( !bRD ); // parameter bRD can be removed |
---|
| 1269 | if( bRD ) |
---|
[56] | 1270 | { |
---|
[2] | 1271 | uiAbsPartIdx = 0; |
---|
[56] | 1272 | } |
---|
[2] | 1273 | |
---|
[56] | 1274 | DTRACE_CABAC_VL( g_nSymbolCounter++ ) |
---|
[2] | 1275 | DTRACE_CABAC_T( "\tdecodeTransformIdx()\tCUDepth=" ) |
---|
| 1276 | DTRACE_CABAC_V( uiDepth ) |
---|
| 1277 | DTRACE_CABAC_T( "\n" ) |
---|
| 1278 | UInt temp = 0; |
---|
| 1279 | UInt temp1 = 0; |
---|
| 1280 | UInt temp2 = 0; |
---|
[56] | 1281 | xEncodeTransformSubdiv( pcCU, uiAbsPartIdx, uiAbsPartIdx, uiDepth, 0, temp, temp1, temp2 ); |
---|
[2] | 1282 | } |
---|
[56] | 1283 | #endif // !UNIFIED_TRANSFORM_TREE |
---|
[2] | 1284 | |
---|
| 1285 | // Intra direction for Luma |
---|
| 1286 | Void TEncEntropy::encodeIntraDirModeLuma ( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
| 1287 | { |
---|
| 1288 | m_pcEntropyCoderIf->codeIntraDirLumaAng( pcCU, uiAbsPartIdx ); |
---|
| 1289 | } |
---|
| 1290 | |
---|
| 1291 | // Intra direction for Chroma |
---|
| 1292 | Void TEncEntropy::encodeIntraDirModeChroma( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool bRD ) |
---|
| 1293 | { |
---|
| 1294 | if( bRD ) |
---|
[56] | 1295 | { |
---|
[2] | 1296 | uiAbsPartIdx = 0; |
---|
[56] | 1297 | } |
---|
[2] | 1298 | |
---|
| 1299 | m_pcEntropyCoderIf->codeIntraDirChroma( pcCU, uiAbsPartIdx ); |
---|
| 1300 | } |
---|
| 1301 | |
---|
| 1302 | Void TEncEntropy::encodePredInfo( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool bRD ) |
---|
| 1303 | { |
---|
| 1304 | if( bRD ) |
---|
[56] | 1305 | { |
---|
[2] | 1306 | uiAbsPartIdx = 0; |
---|
[56] | 1307 | } |
---|
[2] | 1308 | |
---|
| 1309 | PartSize eSize = pcCU->getPartitionSize( uiAbsPartIdx ); |
---|
| 1310 | |
---|
| 1311 | if( pcCU->isIntra( uiAbsPartIdx ) ) // If it is Intra mode, encode intra prediction mode. |
---|
| 1312 | { |
---|
| 1313 | if( eSize == SIZE_NxN ) // if it is NxN size, encode 4 intra directions. |
---|
| 1314 | { |
---|
| 1315 | UInt uiPartOffset = ( pcCU->getPic()->getNumPartInCU() >> ( pcCU->getDepth(uiAbsPartIdx) << 1 ) ) >> 2; |
---|
| 1316 | // if it is NxN size, this size might be the smallest partition size. |
---|
| 1317 | encodeIntraDirModeLuma( pcCU, uiAbsPartIdx ); |
---|
| 1318 | encodeIntraDirModeLuma( pcCU, uiAbsPartIdx + uiPartOffset ); |
---|
| 1319 | encodeIntraDirModeLuma( pcCU, uiAbsPartIdx + uiPartOffset*2 ); |
---|
| 1320 | encodeIntraDirModeLuma( pcCU, uiAbsPartIdx + uiPartOffset*3 ); |
---|
| 1321 | encodeIntraDirModeChroma( pcCU, uiAbsPartIdx, bRD ); |
---|
| 1322 | } |
---|
| 1323 | else // if it is not NxN size, encode 1 intra directions |
---|
| 1324 | { |
---|
| 1325 | encodeIntraDirModeLuma ( pcCU, uiAbsPartIdx ); |
---|
| 1326 | encodeIntraDirModeChroma( pcCU, uiAbsPartIdx, bRD ); |
---|
| 1327 | } |
---|
| 1328 | } |
---|
| 1329 | else // if it is Inter mode, encode motion vector and reference index |
---|
| 1330 | { |
---|
[56] | 1331 | encodePUWise( pcCU, uiAbsPartIdx, bRD ); |
---|
[2] | 1332 | } |
---|
| 1333 | } |
---|
| 1334 | |
---|
| 1335 | /** encode motion information for every PU block |
---|
| 1336 | * \param pcCU |
---|
| 1337 | * \param uiAbsPartIdx |
---|
| 1338 | * \param bRD |
---|
| 1339 | * \returns Void |
---|
| 1340 | */ |
---|
| 1341 | Void TEncEntropy::encodePUWise( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool bRD ) |
---|
| 1342 | { |
---|
| 1343 | if ( bRD ) |
---|
[56] | 1344 | { |
---|
[2] | 1345 | uiAbsPartIdx = 0; |
---|
[56] | 1346 | } |
---|
| 1347 | |
---|
[2] | 1348 | PartSize ePartSize = pcCU->getPartitionSize( uiAbsPartIdx ); |
---|
| 1349 | UInt uiNumPU = ( ePartSize == SIZE_2Nx2N ? 1 : ( ePartSize == SIZE_NxN ? 4 : 2 ) ); |
---|
| 1350 | UInt uiDepth = pcCU->getDepth( uiAbsPartIdx ); |
---|
| 1351 | UInt uiPUOffset = ( g_auiPUOffset[UInt( ePartSize )] << ( ( pcCU->getSlice()->getSPS()->getMaxCUDepth() - uiDepth ) << 1 ) ) >> 4; |
---|
| 1352 | |
---|
| 1353 | for ( UInt uiPartIdx = 0, uiSubPartIdx = uiAbsPartIdx; uiPartIdx < uiNumPU; uiPartIdx++, uiSubPartIdx += uiPUOffset ) |
---|
| 1354 | { |
---|
| 1355 | encodeMergeFlag( pcCU, uiSubPartIdx, uiPartIdx ); |
---|
| 1356 | if ( pcCU->getMergeFlag( uiSubPartIdx ) ) |
---|
| 1357 | { |
---|
| 1358 | encodeMergeIndex( pcCU, uiSubPartIdx, uiPartIdx ); |
---|
| 1359 | } |
---|
| 1360 | else |
---|
| 1361 | { |
---|
| 1362 | encodeInterDirPU( pcCU, uiSubPartIdx ); |
---|
| 1363 | for ( UInt uiRefListIdx = 0; uiRefListIdx < 2; uiRefListIdx++ ) |
---|
| 1364 | { |
---|
| 1365 | if ( pcCU->getSlice()->getNumRefIdx( RefPicList( uiRefListIdx ) ) > 0 ) |
---|
| 1366 | { |
---|
| 1367 | encodeRefFrmIdxPU ( pcCU, uiSubPartIdx, RefPicList( uiRefListIdx ) ); |
---|
| 1368 | encodeMvdPU ( pcCU, uiSubPartIdx, RefPicList( uiRefListIdx ) ); |
---|
| 1369 | encodeMVPIdxPU ( pcCU, uiSubPartIdx, RefPicList( uiRefListIdx ) ); |
---|
| 1370 | } |
---|
| 1371 | } |
---|
| 1372 | } |
---|
| 1373 | } |
---|
| 1374 | |
---|
| 1375 | return; |
---|
| 1376 | } |
---|
| 1377 | |
---|
| 1378 | Void TEncEntropy::encodeInterDirPU( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
| 1379 | { |
---|
| 1380 | if ( !pcCU->getSlice()->isInterB() ) |
---|
| 1381 | { |
---|
| 1382 | return; |
---|
| 1383 | } |
---|
| 1384 | |
---|
| 1385 | m_pcEntropyCoderIf->codeInterDir( pcCU, uiAbsPartIdx ); |
---|
| 1386 | return; |
---|
| 1387 | } |
---|
| 1388 | |
---|
| 1389 | /** encode reference frame index for a PU block |
---|
| 1390 | * \param pcCU |
---|
| 1391 | * \param uiAbsPartIdx |
---|
| 1392 | * \param eRefList |
---|
| 1393 | * \returns Void |
---|
| 1394 | */ |
---|
| 1395 | Void TEncEntropy::encodeRefFrmIdxPU( TComDataCU* pcCU, UInt uiAbsPartIdx, RefPicList eRefList ) |
---|
| 1396 | { |
---|
| 1397 | assert( !pcCU->isIntra( uiAbsPartIdx ) ); |
---|
| 1398 | |
---|
| 1399 | if(pcCU->getSlice()->getNumRefIdx(REF_PIC_LIST_C)>0 && pcCU->getInterDir( uiAbsPartIdx ) != 3) |
---|
| 1400 | { |
---|
| 1401 | if ((eRefList== REF_PIC_LIST_1) || ( pcCU->getSlice()->getNumRefIdx( REF_PIC_LIST_C ) == 1 ) ) |
---|
| 1402 | { |
---|
| 1403 | return; |
---|
| 1404 | } |
---|
| 1405 | |
---|
| 1406 | if ( pcCU->getSlice()->getNumRefIdx ( REF_PIC_LIST_C ) > 1 ) |
---|
| 1407 | { |
---|
| 1408 | m_pcEntropyCoderIf->codeRefFrmIdx( pcCU, uiAbsPartIdx, RefPicList(pcCU->getInterDir( uiAbsPartIdx )-1) ); |
---|
| 1409 | } |
---|
| 1410 | |
---|
| 1411 | } |
---|
| 1412 | else |
---|
| 1413 | { |
---|
[56] | 1414 | if ( ( pcCU->getSlice()->getNumRefIdx( eRefList ) == 1 ) ) |
---|
| 1415 | { |
---|
| 1416 | return; |
---|
| 1417 | } |
---|
[2] | 1418 | |
---|
[56] | 1419 | if ( pcCU->getInterDir( uiAbsPartIdx ) & ( 1 << eRefList ) ) |
---|
| 1420 | { |
---|
| 1421 | m_pcEntropyCoderIf->codeRefFrmIdx( pcCU, uiAbsPartIdx, eRefList ); |
---|
| 1422 | } |
---|
[2] | 1423 | } |
---|
| 1424 | |
---|
| 1425 | return; |
---|
| 1426 | } |
---|
| 1427 | |
---|
| 1428 | /** encode motion vector difference for a PU block |
---|
| 1429 | * \param pcCU |
---|
| 1430 | * \param uiAbsPartIdx |
---|
| 1431 | * \param eRefList |
---|
| 1432 | * \returns Void |
---|
| 1433 | */ |
---|
| 1434 | Void TEncEntropy::encodeMvdPU( TComDataCU* pcCU, UInt uiAbsPartIdx, RefPicList eRefList ) |
---|
| 1435 | { |
---|
| 1436 | assert( !pcCU->isIntra( uiAbsPartIdx ) ); |
---|
| 1437 | |
---|
| 1438 | if ( pcCU->getInterDir( uiAbsPartIdx ) & ( 1 << eRefList ) ) |
---|
| 1439 | { |
---|
| 1440 | m_pcEntropyCoderIf->codeMvd( pcCU, uiAbsPartIdx, eRefList ); |
---|
| 1441 | } |
---|
| 1442 | return; |
---|
| 1443 | } |
---|
| 1444 | |
---|
| 1445 | Void TEncEntropy::encodeMVPIdxPU( TComDataCU* pcCU, UInt uiAbsPartIdx, RefPicList eRefList ) |
---|
| 1446 | { |
---|
[56] | 1447 | if ( (pcCU->getInterDir( uiAbsPartIdx ) & ( 1 << eRefList )) && (pcCU->getAMVPMode(uiAbsPartIdx) == AM_EXPL) ) |
---|
[2] | 1448 | { |
---|
[56] | 1449 | #if HHI_INTER_VIEW_MOTION_PRED |
---|
| 1450 | const Int iNumCands = AMVP_MAX_NUM_CANDS + ( pcCU->getSlice()->getSPS()->getMultiviewMvPredMode() ? 1 : 0 ); |
---|
| 1451 | m_pcEntropyCoderIf->codeMVPIdx( pcCU, uiAbsPartIdx, eRefList, iNumCands ); |
---|
| 1452 | #else |
---|
[2] | 1453 | m_pcEntropyCoderIf->codeMVPIdx( pcCU, uiAbsPartIdx, eRefList ); |
---|
| 1454 | #endif |
---|
| 1455 | } |
---|
| 1456 | |
---|
| 1457 | return; |
---|
| 1458 | } |
---|
| 1459 | |
---|
| 1460 | Void TEncEntropy::encodeQtCbf( TComDataCU* pcCU, UInt uiAbsPartIdx, TextType eType, UInt uiTrDepth ) |
---|
| 1461 | { |
---|
| 1462 | m_pcEntropyCoderIf->codeQtCbf( pcCU, uiAbsPartIdx, eType, uiTrDepth ); |
---|
| 1463 | } |
---|
| 1464 | |
---|
| 1465 | Void TEncEntropy::encodeTransformSubdivFlag( UInt uiSymbol, UInt uiCtx ) |
---|
| 1466 | { |
---|
| 1467 | m_pcEntropyCoderIf->codeTransformSubdivFlag( uiSymbol, uiCtx ); |
---|
| 1468 | } |
---|
| 1469 | |
---|
| 1470 | Void TEncEntropy::encodeQtRootCbf( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
| 1471 | { |
---|
| 1472 | m_pcEntropyCoderIf->codeQtRootCbf( pcCU, uiAbsPartIdx ); |
---|
| 1473 | } |
---|
| 1474 | |
---|
| 1475 | // dQP |
---|
| 1476 | Void TEncEntropy::encodeQP( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool bRD ) |
---|
| 1477 | { |
---|
| 1478 | if( bRD ) |
---|
[56] | 1479 | { |
---|
[2] | 1480 | uiAbsPartIdx = 0; |
---|
[56] | 1481 | } |
---|
[2] | 1482 | |
---|
[56] | 1483 | if ( pcCU->getSlice()->getPPS()->getUseDQP() ) |
---|
[2] | 1484 | { |
---|
| 1485 | m_pcEntropyCoderIf->codeDeltaQP( pcCU, uiAbsPartIdx ); |
---|
| 1486 | } |
---|
| 1487 | } |
---|
| 1488 | |
---|
| 1489 | |
---|
| 1490 | // texture |
---|
[56] | 1491 | #if !UNIFIED_TRANSFORM_TREE |
---|
| 1492 | Void TEncEntropy::xEncodeCoeff( TComDataCU* pcCU, UInt uiLumaOffset, UInt uiChromaOffset, UInt uiAbsPartIdx, UInt uiDepth, UInt uiWidth, UInt uiHeight, UInt uiTrIdx, UInt uiCurrTrIdx, Bool& bCodeDQP ) |
---|
[2] | 1493 | { |
---|
[56] | 1494 | UInt uiLog2TrSize = g_aucConvertToBit[ pcCU->getSlice()->getSPS()->getMaxCUWidth() >> uiDepth ] + 2; |
---|
| 1495 | UInt uiCbfY = pcCU->getCbf( uiAbsPartIdx, TEXT_LUMA, uiTrIdx ); |
---|
| 1496 | UInt uiCbfU = pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_U, uiTrIdx ); |
---|
| 1497 | UInt uiCbfV = pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_V, uiTrIdx ); |
---|
| 1498 | |
---|
| 1499 | if( uiLog2TrSize == 2 ) |
---|
[2] | 1500 | { |
---|
[56] | 1501 | UInt uiQPDiv = pcCU->getPic()->getNumPartInCU() >> ( ( uiDepth - 1 ) << 1 ); |
---|
| 1502 | if( ( uiAbsPartIdx % uiQPDiv ) == 0 ) |
---|
| 1503 | { |
---|
| 1504 | m_uiBakAbsPartIdx = uiAbsPartIdx; |
---|
| 1505 | m_uiBakChromaOffset = uiChromaOffset; |
---|
| 1506 | } |
---|
| 1507 | else if( ( uiAbsPartIdx % uiQPDiv ) == (uiQPDiv - 1) ) |
---|
| 1508 | { |
---|
| 1509 | uiCbfU = pcCU->getCbf( m_uiBakAbsPartIdx, TEXT_CHROMA_U, uiTrIdx ); |
---|
| 1510 | uiCbfV = pcCU->getCbf( m_uiBakAbsPartIdx, TEXT_CHROMA_V, uiTrIdx ); |
---|
| 1511 | } |
---|
| 1512 | } |
---|
| 1513 | |
---|
| 1514 | if ( uiCbfY || uiCbfU || uiCbfV ) |
---|
| 1515 | { |
---|
[2] | 1516 | // dQP: only for LCU once |
---|
[56] | 1517 | if ( pcCU->getSlice()->getPPS()->getUseDQP() ) |
---|
[2] | 1518 | { |
---|
[56] | 1519 | if ( bCodeDQP ) |
---|
[2] | 1520 | { |
---|
[56] | 1521 | encodeQP( pcCU, uiAbsPartIdx ); |
---|
| 1522 | bCodeDQP = false; |
---|
[2] | 1523 | } |
---|
| 1524 | } |
---|
| 1525 | UInt uiLumaTrMode, uiChromaTrMode; |
---|
| 1526 | pcCU->convertTransIdx( uiAbsPartIdx, pcCU->getTransformIdx( uiAbsPartIdx ), uiLumaTrMode, uiChromaTrMode ); |
---|
[56] | 1527 | const UInt uiStopTrMode = uiLumaTrMode; |
---|
[2] | 1528 | |
---|
| 1529 | assert(1); // as long as quadtrees are not used for residual transform |
---|
| 1530 | |
---|
| 1531 | if( uiTrIdx == uiStopTrMode ) |
---|
| 1532 | { |
---|
[56] | 1533 | if( pcCU->getCbf( uiAbsPartIdx, TEXT_LUMA, uiTrIdx ) ) |
---|
[2] | 1534 | { |
---|
[56] | 1535 | Int trWidth = uiWidth; |
---|
| 1536 | Int trHeight = uiHeight; |
---|
| 1537 | pcCU->getNSQTSize( uiTrIdx, uiAbsPartIdx, trWidth, trHeight ); |
---|
| 1538 | m_pcEntropyCoderIf->codeCoeffNxN( pcCU, (pcCU->getCoeffY()+uiLumaOffset), uiAbsPartIdx, trWidth, trHeight, uiDepth, TEXT_LUMA ); |
---|
| 1539 | } |
---|
| 1540 | |
---|
| 1541 | uiWidth >>= 1; |
---|
| 1542 | uiHeight >>= 1; |
---|
| 1543 | |
---|
| 1544 | if( uiLog2TrSize == 2 ) |
---|
| 1545 | { |
---|
[2] | 1546 | UInt uiQPDiv = pcCU->getPic()->getNumPartInCU() >> ( ( uiDepth - 1 ) << 1 ); |
---|
[56] | 1547 | if( ( uiAbsPartIdx % uiQPDiv ) == (uiQPDiv - 1) ) |
---|
[2] | 1548 | { |
---|
[56] | 1549 | uiWidth <<= 1; |
---|
| 1550 | uiHeight <<= 1; |
---|
| 1551 | Int trWidth = uiWidth; |
---|
| 1552 | Int trHeight = uiHeight; |
---|
| 1553 | pcCU->getNSQTSize( uiTrIdx-1, uiAbsPartIdx, trWidth, trHeight ); |
---|
| 1554 | if( pcCU->getCbf( m_uiBakAbsPartIdx, TEXT_CHROMA_U, uiTrIdx ) ) |
---|
| 1555 | { |
---|
| 1556 | m_pcEntropyCoderIf->codeCoeffNxN( pcCU, (pcCU->getCoeffCb()+m_uiBakChromaOffset), m_uiBakAbsPartIdx, trWidth, trHeight, uiDepth, TEXT_CHROMA_U ); |
---|
| 1557 | } |
---|
| 1558 | if( pcCU->getCbf( m_uiBakAbsPartIdx, TEXT_CHROMA_V, uiTrIdx ) ) |
---|
| 1559 | { |
---|
| 1560 | m_pcEntropyCoderIf->codeCoeffNxN( pcCU, (pcCU->getCoeffCr()+m_uiBakChromaOffset), m_uiBakAbsPartIdx, trWidth, trHeight, uiDepth, TEXT_CHROMA_V ); |
---|
| 1561 | } |
---|
[2] | 1562 | } |
---|
| 1563 | } |
---|
[56] | 1564 | else |
---|
| 1565 | { |
---|
| 1566 | Int trWidth = uiWidth; |
---|
| 1567 | Int trHeight = uiHeight; |
---|
| 1568 | pcCU->getNSQTSize( uiTrIdx, uiAbsPartIdx, trWidth, trHeight ); |
---|
| 1569 | if( pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_U, uiTrIdx ) ) |
---|
| 1570 | { |
---|
| 1571 | m_pcEntropyCoderIf->codeCoeffNxN( pcCU, (pcCU->getCoeffCb()+uiChromaOffset), uiAbsPartIdx, trWidth, trHeight, uiDepth, TEXT_CHROMA_U ); |
---|
| 1572 | } |
---|
| 1573 | if( pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_V, uiTrIdx ) ) |
---|
| 1574 | { |
---|
| 1575 | m_pcEntropyCoderIf->codeCoeffNxN( pcCU, (pcCU->getCoeffCr()+uiChromaOffset), uiAbsPartIdx, trWidth, trHeight, uiDepth, TEXT_CHROMA_V ); |
---|
| 1576 | } |
---|
| 1577 | } |
---|
[2] | 1578 | } |
---|
| 1579 | else |
---|
| 1580 | { |
---|
| 1581 | { |
---|
[56] | 1582 | DTRACE_CABAC_VL( g_nSymbolCounter++ ); |
---|
[2] | 1583 | DTRACE_CABAC_T( "\tgoing down\tdepth=" ); |
---|
| 1584 | DTRACE_CABAC_V( uiDepth ); |
---|
| 1585 | DTRACE_CABAC_T( "\ttridx=" ); |
---|
| 1586 | DTRACE_CABAC_V( uiTrIdx ); |
---|
| 1587 | DTRACE_CABAC_T( "\n" ); |
---|
| 1588 | } |
---|
| 1589 | if( uiCurrTrIdx <= uiTrIdx ) |
---|
| 1590 | assert(1); |
---|
| 1591 | |
---|
| 1592 | UInt uiSize; |
---|
| 1593 | uiWidth >>= 1; |
---|
| 1594 | uiHeight >>= 1; |
---|
| 1595 | uiSize = uiWidth*uiHeight; |
---|
| 1596 | uiDepth++; |
---|
| 1597 | uiTrIdx++; |
---|
| 1598 | |
---|
| 1599 | UInt uiQPartNum = pcCU->getPic()->getNumPartInCU() >> (uiDepth << 1); |
---|
| 1600 | UInt uiIdx = uiAbsPartIdx; |
---|
| 1601 | |
---|
| 1602 | { |
---|
[56] | 1603 | xEncodeCoeff( pcCU, uiLumaOffset, uiChromaOffset, uiIdx, uiDepth, uiWidth, uiHeight, uiTrIdx, uiCurrTrIdx, bCodeDQP ); |
---|
| 1604 | uiLumaOffset += uiSize; uiChromaOffset += (uiSize>>2); uiIdx += uiQPartNum; |
---|
| 1605 | |
---|
| 1606 | xEncodeCoeff( pcCU, uiLumaOffset, uiChromaOffset, uiIdx, uiDepth, uiWidth, uiHeight, uiTrIdx, uiCurrTrIdx, bCodeDQP ); |
---|
| 1607 | uiLumaOffset += uiSize; uiChromaOffset += (uiSize>>2); uiIdx += uiQPartNum; |
---|
| 1608 | |
---|
| 1609 | xEncodeCoeff( pcCU, uiLumaOffset, uiChromaOffset, uiIdx, uiDepth, uiWidth, uiHeight, uiTrIdx, uiCurrTrIdx, bCodeDQP ); |
---|
| 1610 | uiLumaOffset += uiSize; uiChromaOffset += (uiSize>>2); uiIdx += uiQPartNum; |
---|
| 1611 | |
---|
| 1612 | xEncodeCoeff( pcCU, uiLumaOffset, uiChromaOffset, uiIdx, uiDepth, uiWidth, uiHeight, uiTrIdx, uiCurrTrIdx, bCodeDQP ); |
---|
[2] | 1613 | } |
---|
| 1614 | { |
---|
[56] | 1615 | DTRACE_CABAC_VL( g_nSymbolCounter++ ); |
---|
[2] | 1616 | DTRACE_CABAC_T( "\tgoing up\n" ); |
---|
| 1617 | } |
---|
| 1618 | } |
---|
| 1619 | } |
---|
| 1620 | } |
---|
[56] | 1621 | #endif // !UNIFIED_TRANSFORM_TREE |
---|
[2] | 1622 | |
---|
| 1623 | /** encode coefficients |
---|
| 1624 | * \param pcCU |
---|
| 1625 | * \param uiAbsPartIdx |
---|
| 1626 | * \param uiDepth |
---|
| 1627 | * \param uiWidth |
---|
| 1628 | * \param uiHeight |
---|
| 1629 | */ |
---|
[56] | 1630 | Void TEncEntropy::encodeCoeff( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, UInt uiWidth, UInt uiHeight, Bool& bCodeDQP ) |
---|
[2] | 1631 | { |
---|
| 1632 | UInt uiMinCoeffSize = pcCU->getPic()->getMinCUWidth()*pcCU->getPic()->getMinCUHeight(); |
---|
| 1633 | UInt uiLumaOffset = uiMinCoeffSize*uiAbsPartIdx; |
---|
| 1634 | UInt uiChromaOffset = uiLumaOffset>>2; |
---|
| 1635 | |
---|
| 1636 | UInt uiLumaTrMode, uiChromaTrMode; |
---|
| 1637 | pcCU->convertTransIdx( uiAbsPartIdx, pcCU->getTransformIdx(uiAbsPartIdx), uiLumaTrMode, uiChromaTrMode ); |
---|
| 1638 | |
---|
| 1639 | if( pcCU->isIntra(uiAbsPartIdx) ) |
---|
| 1640 | { |
---|
[56] | 1641 | DTRACE_CABAC_VL( g_nSymbolCounter++ ) |
---|
[2] | 1642 | DTRACE_CABAC_T( "\tdecodeTransformIdx()\tCUDepth=" ) |
---|
| 1643 | DTRACE_CABAC_V( uiDepth ) |
---|
| 1644 | DTRACE_CABAC_T( "\n" ) |
---|
[56] | 1645 | #if !UNIFIED_TRANSFORM_TREE |
---|
[2] | 1646 | UInt temp = 0; |
---|
| 1647 | UInt temp1 = 0; |
---|
| 1648 | UInt temp2 = 0; |
---|
[56] | 1649 | xEncodeTransformSubdiv( pcCU, uiAbsPartIdx, uiAbsPartIdx, uiDepth, 0, temp, temp1, temp2 ); |
---|
| 1650 | #endif // !UNIFIED_TRANSFORM_TREE |
---|
[2] | 1651 | } |
---|
| 1652 | else |
---|
| 1653 | { |
---|
| 1654 | { |
---|
[5] | 1655 | #if HHI_MPI |
---|
[2] | 1656 | if( !(pcCU->getMergeFlag( uiAbsPartIdx ) && pcCU->getPartitionSize(uiAbsPartIdx) == SIZE_2Nx2N && |
---|
| 1657 | ( pcCU->getTextureModeDepth( uiAbsPartIdx ) == -1 || uiDepth == pcCU->getTextureModeDepth( uiAbsPartIdx ) ) ) ) |
---|
| 1658 | #else |
---|
| 1659 | if( !(pcCU->getMergeFlag( uiAbsPartIdx ) && pcCU->getPartitionSize(uiAbsPartIdx) == SIZE_2Nx2N ) ) |
---|
| 1660 | #endif |
---|
| 1661 | { |
---|
| 1662 | m_pcEntropyCoderIf->codeQtRootCbf( pcCU, uiAbsPartIdx ); |
---|
| 1663 | } |
---|
| 1664 | if ( !pcCU->getQtRootCbf( uiAbsPartIdx ) ) |
---|
| 1665 | { |
---|
[56] | 1666 | #if 1 // MW Bug Fix |
---|
| 1667 | pcCU->setCbfSubParts( 0, 0, 0, uiAbsPartIdx, uiDepth ); |
---|
[2] | 1668 | pcCU->setTrIdxSubParts( 0 , uiAbsPartIdx, uiDepth ); |
---|
[56] | 1669 | #endif |
---|
| 1670 | pcCU->setNSQTIdxSubParts( uiAbsPartIdx, uiDepth ); |
---|
[2] | 1671 | return; |
---|
| 1672 | } |
---|
| 1673 | } |
---|
[56] | 1674 | #if !UNIFIED_TRANSFORM_TREE |
---|
[2] | 1675 | encodeTransformIdx( pcCU, uiAbsPartIdx, pcCU->getDepth(uiAbsPartIdx) ); |
---|
[56] | 1676 | #endif |
---|
[2] | 1677 | } |
---|
| 1678 | |
---|
[56] | 1679 | #if UNIFIED_TRANSFORM_TREE |
---|
| 1680 | UInt temp = 0; |
---|
| 1681 | UInt temp1 = 0; |
---|
| 1682 | UInt temp2 = 0; |
---|
| 1683 | xEncodeTransform( pcCU, uiLumaOffset, uiChromaOffset, uiAbsPartIdx, uiAbsPartIdx, uiDepth, uiWidth, uiHeight, 0, 0, temp, temp1, temp2, bCodeDQP ); |
---|
| 1684 | #else // UNIFIED_TRANSFORM_TREE |
---|
| 1685 | xEncodeCoeff( pcCU, uiLumaOffset, uiChromaOffset, uiAbsPartIdx, uiDepth, uiWidth, uiHeight, 0, uiLumaTrMode, bCodeDQP ); |
---|
| 1686 | #endif // UNIFIED_TRANSFORM_TREE |
---|
[2] | 1687 | } |
---|
| 1688 | |
---|
[56] | 1689 | Void TEncEntropy::encodeCoeffNxN( TComDataCU* pcCU, TCoeff* pcCoeff, UInt uiAbsPartIdx, UInt uiTrWidth, UInt uiTrHeight, UInt uiDepth, TextType eType ) |
---|
[2] | 1690 | { // This is for Transform unit processing. This may be used at mode selection stage for Inter. |
---|
[56] | 1691 | m_pcEntropyCoderIf->codeCoeffNxN( pcCU, pcCoeff, uiAbsPartIdx, uiTrWidth, uiTrHeight, uiDepth, eType ); |
---|
[2] | 1692 | } |
---|
| 1693 | |
---|
[56] | 1694 | Void TEncEntropy::estimateBit (estBitsSbacStruct* pcEstBitsSbac, Int width, Int height, TextType eTType) |
---|
| 1695 | { |
---|
| 1696 | eTType = eTType == TEXT_LUMA ? TEXT_LUMA : TEXT_CHROMA; |
---|
| 1697 | |
---|
| 1698 | m_pcEntropyCoderIf->estBit ( pcEstBitsSbac, width, height, eTType ); |
---|
| 1699 | } |
---|
| 1700 | |
---|
| 1701 | #if SAO_UNIT_INTERLEAVING |
---|
| 1702 | /** Encode SAO Offset |
---|
| 1703 | * \param saoLcuParam SAO LCU paramters |
---|
| 1704 | */ |
---|
| 1705 | Void TEncEntropy::encodeSaoOffset(SaoLcuParam* saoLcuParam) |
---|
[2] | 1706 | { |
---|
[56] | 1707 | UInt uiSymbol; |
---|
| 1708 | Int i; |
---|
| 1709 | |
---|
| 1710 | uiSymbol = saoLcuParam->typeIdx + 1; |
---|
| 1711 | m_pcEntropyCoderIf->codeSaoTypeIdx(uiSymbol); |
---|
| 1712 | if (uiSymbol) |
---|
[2] | 1713 | { |
---|
[56] | 1714 | if( saoLcuParam->typeIdx == SAO_BO ) |
---|
| 1715 | { |
---|
| 1716 | // Code Left Band Index |
---|
| 1717 | uiSymbol = (UInt) (saoLcuParam->bandPosition); |
---|
| 1718 | m_pcEntropyCoderIf->codeSaoUflc(uiSymbol); |
---|
| 1719 | for( i=0; i< saoLcuParam->length; i++) |
---|
| 1720 | { |
---|
| 1721 | m_pcEntropyCoderIf->codeSaoSvlc(saoLcuParam->offset[i]); |
---|
| 1722 | } |
---|
| 1723 | } |
---|
| 1724 | else |
---|
| 1725 | if( saoLcuParam->typeIdx < 4 ) |
---|
| 1726 | { |
---|
| 1727 | m_pcEntropyCoderIf->codeSaoUvlc( saoLcuParam->offset[0]); |
---|
| 1728 | m_pcEntropyCoderIf->codeSaoUvlc( saoLcuParam->offset[1]); |
---|
| 1729 | m_pcEntropyCoderIf->codeSaoUvlc(-saoLcuParam->offset[2]); |
---|
| 1730 | m_pcEntropyCoderIf->codeSaoUvlc(-saoLcuParam->offset[3]); |
---|
| 1731 | } |
---|
[2] | 1732 | } |
---|
| 1733 | } |
---|
[56] | 1734 | /** Encode SAO unit |
---|
| 1735 | * \param rx |
---|
| 1736 | * \param ry |
---|
| 1737 | * \param iCompIdx |
---|
| 1738 | * \param pSaoParam |
---|
| 1739 | * \param bRepeatedRow |
---|
| 1740 | */ |
---|
| 1741 | Void TEncEntropy::encodeSaoUnit(Int rx, Int ry, Int compIdx, SAOParam* saoParam, Int repeatedRow ) |
---|
| 1742 | { |
---|
| 1743 | int addr, addrLeft; |
---|
| 1744 | int numCuInWidth = saoParam->numCuInWidth; |
---|
| 1745 | SaoLcuParam* saoOneLcu; |
---|
| 1746 | Int runLeft; |
---|
[2] | 1747 | |
---|
[56] | 1748 | addr = rx + ry*numCuInWidth; |
---|
| 1749 | addrLeft = (addr%numCuInWidth == 0) ? -1 : addr - 1; |
---|
| 1750 | |
---|
| 1751 | if (!repeatedRow) |
---|
| 1752 | { |
---|
| 1753 | saoOneLcu = &(saoParam->saoLcuParam[compIdx][addr]); |
---|
| 1754 | runLeft = (addrLeft>=0 ) ? saoParam->saoLcuParam[compIdx][addrLeft].run : -1; |
---|
| 1755 | if (rx == 0 || runLeft==0) |
---|
| 1756 | { |
---|
| 1757 | if (ry == 0) |
---|
| 1758 | { |
---|
| 1759 | m_pcEntropyCoderIf->codeSaoRun(saoOneLcu->runDiff, numCuInWidth-rx-1); |
---|
| 1760 | saoOneLcu->mergeUpFlag = 0; |
---|
| 1761 | } |
---|
| 1762 | else |
---|
| 1763 | { |
---|
| 1764 | m_pcEntropyCoderIf->codeSaoSvlc(saoOneLcu->runDiff); |
---|
| 1765 | m_pcEntropyCoderIf->codeSaoFlag(saoOneLcu->mergeUpFlag); |
---|
| 1766 | } |
---|
| 1767 | if (!saoOneLcu->mergeUpFlag) |
---|
| 1768 | { |
---|
| 1769 | encodeSaoOffset(saoOneLcu); |
---|
| 1770 | } |
---|
| 1771 | } |
---|
| 1772 | } |
---|
| 1773 | } |
---|
| 1774 | |
---|
| 1775 | /** Encode SAO unit interleaving |
---|
| 1776 | * \param rx |
---|
| 1777 | * \param ry |
---|
| 1778 | * \param pSaoParam |
---|
| 1779 | * \param pcCU |
---|
| 1780 | * \param iCUAddrInSlice |
---|
| 1781 | * \param iCUAddrUpInSlice |
---|
| 1782 | * \param bLFCrossSliceBoundaryFlag |
---|
[2] | 1783 | */ |
---|
[56] | 1784 | Void TEncEntropy::encodeSaoUnitInterleaving(Int rx, Int ry, SAOParam* saoParam, TComDataCU* cu, Int cuAddrInSlice, Int cuAddrUpInSlice, Bool lfCrossSliceBoundaryFlag) |
---|
[2] | 1785 | { |
---|
[56] | 1786 | Int addr = cu->getAddr(); |
---|
| 1787 | for (Int compIdx=0; compIdx<3; compIdx++) |
---|
| 1788 | { |
---|
| 1789 | if (saoParam->bSaoFlag[compIdx]) |
---|
| 1790 | { |
---|
| 1791 | if (rx>0 && cuAddrInSlice!=0) |
---|
| 1792 | { |
---|
| 1793 | m_pcEntropyCoderIf->codeSaoMergeLeft(saoParam->saoLcuParam[compIdx][addr].mergeLeftFlag,compIdx); |
---|
| 1794 | } |
---|
| 1795 | else |
---|
| 1796 | { |
---|
| 1797 | saoParam->saoLcuParam[compIdx][addr].mergeLeftFlag = 0; |
---|
| 1798 | } |
---|
| 1799 | if (saoParam->saoLcuParam[compIdx][addr].mergeLeftFlag == 0) |
---|
| 1800 | { |
---|
| 1801 | if ( (ry > 0) && (cuAddrUpInSlice>0||lfCrossSliceBoundaryFlag)) |
---|
| 1802 | { |
---|
| 1803 | m_pcEntropyCoderIf->codeSaoMergeUp(saoParam->saoLcuParam[compIdx][addr].mergeUpFlag); |
---|
| 1804 | } |
---|
| 1805 | else |
---|
| 1806 | { |
---|
| 1807 | saoParam->saoLcuParam[compIdx][addr].mergeUpFlag = 0; |
---|
| 1808 | } |
---|
| 1809 | if (!saoParam->saoLcuParam[compIdx][addr].mergeUpFlag) |
---|
| 1810 | { |
---|
| 1811 | encodeSaoOffset(&(saoParam->saoLcuParam[compIdx][addr])); |
---|
| 1812 | } |
---|
| 1813 | } |
---|
| 1814 | } |
---|
| 1815 | } |
---|
| 1816 | } |
---|
| 1817 | |
---|
| 1818 | /** Encode SAO parameter |
---|
| 1819 | * \param pcAPS |
---|
| 1820 | */ |
---|
| 1821 | Void TEncEntropy::encodeSaoParam(TComAPS* aps) |
---|
| 1822 | { |
---|
| 1823 | SaoLcuParam* psSaoOneLcu; |
---|
| 1824 | int i,j,k, compIdx; |
---|
| 1825 | int numCuInWidth ; |
---|
| 1826 | int numCuInHeight ; |
---|
| 1827 | Bool repeatedRow[3]; |
---|
| 1828 | Int addr; |
---|
| 1829 | m_pcEntropyCoderIf->codeSaoFlag(aps->getSaoInterleavingFlag()); |
---|
| 1830 | if(!aps->getSaoInterleavingFlag()) |
---|
| 1831 | { |
---|
| 1832 | m_pcEntropyCoderIf->codeSaoFlag(aps->getSaoEnabled()); |
---|
| 1833 | if (aps->getSaoEnabled()) |
---|
| 1834 | { |
---|
| 1835 | SAOParam* pSaoParam = aps->getSaoParam(); |
---|
| 1836 | numCuInWidth = pSaoParam->numCuInWidth; |
---|
| 1837 | numCuInHeight = pSaoParam->numCuInHeight; |
---|
| 1838 | m_pcEntropyCoderIf->codeSaoFlag(pSaoParam->bSaoFlag[1]); |
---|
| 1839 | m_pcEntropyCoderIf->codeSaoFlag(pSaoParam->bSaoFlag[2]); |
---|
| 1840 | m_pcEntropyCoderIf->codeSaoUvlc(numCuInWidth-1); |
---|
| 1841 | m_pcEntropyCoderIf->codeSaoUvlc(numCuInHeight-1); |
---|
| 1842 | for (compIdx=0;compIdx<3;compIdx++) |
---|
| 1843 | { |
---|
| 1844 | if (pSaoParam->bSaoFlag[compIdx]) |
---|
| 1845 | { |
---|
| 1846 | m_pcEntropyCoderIf->codeSaoFlag(pSaoParam->oneUnitFlag[compIdx]); |
---|
| 1847 | if (pSaoParam->oneUnitFlag[compIdx]) |
---|
| 1848 | { |
---|
| 1849 | psSaoOneLcu = &(pSaoParam->saoLcuParam[compIdx][0]); |
---|
| 1850 | encodeSaoOffset(psSaoOneLcu); |
---|
| 1851 | } |
---|
| 1852 | } |
---|
| 1853 | } |
---|
| 1854 | |
---|
| 1855 | for (j=0;j<numCuInHeight;j++) |
---|
| 1856 | { |
---|
| 1857 | for (compIdx=0; compIdx<3; compIdx++) |
---|
| 1858 | { |
---|
| 1859 | repeatedRow[compIdx] = true; |
---|
| 1860 | for (k=0;k<numCuInWidth;k++) |
---|
| 1861 | { |
---|
| 1862 | addr = k + j*numCuInWidth; |
---|
| 1863 | psSaoOneLcu = &(pSaoParam->saoLcuParam[compIdx][addr]); |
---|
| 1864 | if (!psSaoOneLcu->mergeUpFlag || psSaoOneLcu->runDiff) |
---|
| 1865 | { |
---|
| 1866 | repeatedRow[compIdx] = false; |
---|
| 1867 | break; |
---|
| 1868 | } |
---|
| 1869 | } |
---|
| 1870 | } |
---|
| 1871 | for (i=0;i<numCuInWidth;i++) |
---|
| 1872 | { |
---|
| 1873 | for (compIdx=0; compIdx<3; compIdx++) |
---|
| 1874 | { |
---|
| 1875 | if (pSaoParam->bSaoFlag[compIdx] && !pSaoParam->oneUnitFlag[compIdx]) |
---|
| 1876 | { |
---|
| 1877 | if (j>0 && i==0) |
---|
| 1878 | { |
---|
| 1879 | m_pcEntropyCoderIf->codeSaoFlag(repeatedRow[compIdx]); |
---|
| 1880 | } |
---|
| 1881 | encodeSaoUnit (i,j, compIdx, pSaoParam, repeatedRow[compIdx]); |
---|
| 1882 | } |
---|
| 1883 | } |
---|
| 1884 | } |
---|
| 1885 | } |
---|
| 1886 | } |
---|
| 1887 | } |
---|
| 1888 | } |
---|
| 1889 | #else |
---|
| 1890 | /** Encode SAO for one partition |
---|
| 1891 | * \param pSaoParam, iPartIdx |
---|
| 1892 | */ |
---|
| 1893 | Void TEncEntropy::encodeSaoOnePart(SAOParam* pSaoParam, Int iPartIdx, Int iYCbCr) |
---|
| 1894 | { |
---|
| 1895 | SAOQTPart* pAlfPart = NULL; |
---|
| 1896 | pAlfPart = &(pSaoParam->psSaoPart[iYCbCr][iPartIdx]); |
---|
| 1897 | |
---|
[2] | 1898 | UInt uiSymbol; |
---|
| 1899 | |
---|
| 1900 | if(!pAlfPart->bSplit) |
---|
| 1901 | { |
---|
| 1902 | if (pAlfPart->bEnableFlag) |
---|
[56] | 1903 | { |
---|
[2] | 1904 | uiSymbol = pAlfPart->iBestType + 1; |
---|
[56] | 1905 | } |
---|
[2] | 1906 | else |
---|
[56] | 1907 | { |
---|
[2] | 1908 | uiSymbol = 0; |
---|
[56] | 1909 | } |
---|
| 1910 | |
---|
| 1911 | m_pcEntropyCoderIf->codeSaoUvlc(uiSymbol); |
---|
[2] | 1912 | |
---|
| 1913 | if (pAlfPart->bEnableFlag) |
---|
| 1914 | { |
---|
| 1915 | for(Int i=0; i< pAlfPart->iLength; i++) |
---|
| 1916 | { |
---|
[56] | 1917 | m_pcEntropyCoderIf->codeSaoSvlc(pAlfPart->iOffset[i]); |
---|
[2] | 1918 | } |
---|
| 1919 | } |
---|
| 1920 | return; |
---|
| 1921 | } |
---|
| 1922 | |
---|
| 1923 | //split |
---|
[56] | 1924 | if (pAlfPart->PartLevel < pSaoParam->iMaxSplitLevel) |
---|
[2] | 1925 | { |
---|
| 1926 | for (Int i=0;i<NUM_DOWN_PART;i++) |
---|
| 1927 | { |
---|
[56] | 1928 | encodeSaoOnePart(pSaoParam, pAlfPart->DownPartsIdx[i], iYCbCr); |
---|
[2] | 1929 | } |
---|
| 1930 | } |
---|
| 1931 | } |
---|
[56] | 1932 | |
---|
| 1933 | /** Encode quadtree split flag |
---|
| 1934 | * \param pSaoParam, iPartIdx |
---|
[2] | 1935 | */ |
---|
[56] | 1936 | Void TEncEntropy::encodeQuadTreeSplitFlag(SAOParam* pSaoParam, Int iPartIdx, Int iYCbCr) |
---|
[2] | 1937 | { |
---|
[56] | 1938 | SAOQTPart* pSaoPart = NULL; |
---|
| 1939 | pSaoPart = &(pSaoParam->psSaoPart[iYCbCr][iPartIdx]); |
---|
[2] | 1940 | |
---|
| 1941 | if(pSaoPart->PartLevel < pSaoParam->iMaxSplitLevel) |
---|
| 1942 | { |
---|
[56] | 1943 | //send one flag |
---|
| 1944 | m_pcEntropyCoderIf->codeSaoFlag( (pSaoPart->bSplit)?(1):(0) ); |
---|
[2] | 1945 | |
---|
| 1946 | if(pSaoPart->bSplit) |
---|
| 1947 | { |
---|
| 1948 | for (Int i=0;i<NUM_DOWN_PART;i++) |
---|
| 1949 | { |
---|
[56] | 1950 | encodeQuadTreeSplitFlag(pSaoParam, pSaoPart->DownPartsIdx[i], iYCbCr); |
---|
[2] | 1951 | } |
---|
| 1952 | } |
---|
| 1953 | } |
---|
| 1954 | } |
---|
[56] | 1955 | /** Encode SAO parameters |
---|
| 1956 | * \param pSaoParam |
---|
[2] | 1957 | */ |
---|
| 1958 | Void TEncEntropy::encodeSaoParam(SAOParam* pSaoParam) |
---|
| 1959 | { |
---|
[56] | 1960 | if (pSaoParam->bSaoFlag[0]) |
---|
| 1961 | { |
---|
| 1962 | encodeQuadTreeSplitFlag(pSaoParam, 0, 0); |
---|
| 1963 | encodeSaoOnePart(pSaoParam, 0, 0); |
---|
| 1964 | m_pcEntropyCoderIf->codeSaoFlag(pSaoParam->bSaoFlag[1]); |
---|
| 1965 | if (pSaoParam->bSaoFlag[1]) |
---|
| 1966 | { |
---|
| 1967 | encodeQuadTreeSplitFlag(pSaoParam, 0, 1); |
---|
| 1968 | encodeSaoOnePart(pSaoParam, 0, 1); |
---|
| 1969 | } |
---|
| 1970 | m_pcEntropyCoderIf->codeSaoFlag(pSaoParam->bSaoFlag[2]); |
---|
| 1971 | if (pSaoParam->bSaoFlag[2]) |
---|
| 1972 | { |
---|
| 1973 | encodeQuadTreeSplitFlag(pSaoParam, 0, 2); |
---|
| 1974 | encodeSaoOnePart(pSaoParam, 0, 2); |
---|
| 1975 | } |
---|
| 1976 | } |
---|
| 1977 | } |
---|
| 1978 | #endif |
---|
[2] | 1979 | |
---|
[56] | 1980 | Int TEncEntropy::countNonZeroCoeffs( TCoeff* pcCoef, UInt uiSize ) |
---|
| 1981 | { |
---|
| 1982 | Int count = 0; |
---|
| 1983 | |
---|
| 1984 | for ( Int i = 0; i < uiSize; i++ ) |
---|
[2] | 1985 | { |
---|
[56] | 1986 | count += pcCoef[i] != 0; |
---|
[2] | 1987 | } |
---|
[56] | 1988 | |
---|
| 1989 | return count; |
---|
| 1990 | } |
---|
[2] | 1991 | |
---|
[56] | 1992 | /** encode quantization matrix |
---|
| 1993 | * \param scalingList quantization matrix information |
---|
| 1994 | */ |
---|
| 1995 | Void TEncEntropy::encodeScalingList( TComScalingList* scalingList ) |
---|
| 1996 | { |
---|
| 1997 | m_pcEntropyCoderIf->codeScalingList( scalingList ); |
---|
[2] | 1998 | } |
---|
| 1999 | |
---|
[56] | 2000 | Void TEncEntropy::encodeDFParams(TComAPS* pcAPS) |
---|
| 2001 | { |
---|
| 2002 | m_pcEntropyCoderIf->codeDFFlag(pcAPS->getLoopFilterDisable(), "loop_filter_disable"); |
---|
[2] | 2003 | |
---|
[56] | 2004 | if (!pcAPS->getLoopFilterDisable()) |
---|
| 2005 | { |
---|
| 2006 | m_pcEntropyCoderIf->codeDFSvlc(pcAPS->getLoopFilterBetaOffset(), "beta_offset_div2"); |
---|
| 2007 | m_pcEntropyCoderIf->codeDFSvlc(pcAPS->getLoopFilterTcOffset(), "tc_offset_div2"); |
---|
| 2008 | } |
---|
| 2009 | } |
---|
[2] | 2010 | |
---|
[56] | 2011 | //! \} |
---|