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