[313] | 1 | /* The copyright in this software is being made available under the BSD |
---|
| 2 | * License, included below. This software may be subject to other third party |
---|
| 3 | * and contributor rights, including patent rights, and no such rights are |
---|
| 4 | * granted under this license. |
---|
| 5 | * |
---|
[595] | 6 | * Copyright (c) 2010-2014, ITU/ISO/IEC |
---|
[313] | 7 | * All rights reserved. |
---|
| 8 | * |
---|
| 9 | * Redistribution and use in source and binary forms, with or without |
---|
| 10 | * modification, are permitted provided that the following conditions are met: |
---|
| 11 | * |
---|
| 12 | * * Redistributions of source code must retain the above copyright notice, |
---|
| 13 | * this list of conditions and the following disclaimer. |
---|
| 14 | * * Redistributions in binary form must reproduce the above copyright notice, |
---|
| 15 | * this list of conditions and the following disclaimer in the documentation |
---|
| 16 | * and/or other materials provided with the distribution. |
---|
| 17 | * * Neither the name of the ITU/ISO/IEC nor the names of its contributors may |
---|
| 18 | * be used to endorse or promote products derived from this software without |
---|
| 19 | * specific prior written permission. |
---|
| 20 | * |
---|
| 21 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
---|
| 22 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
---|
| 23 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
---|
| 24 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS |
---|
| 25 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
---|
| 26 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
---|
| 27 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
---|
| 28 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
---|
| 29 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
---|
| 30 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF |
---|
| 31 | * THE POSSIBILITY OF SUCH DAMAGE. |
---|
| 32 | */ |
---|
| 33 | |
---|
| 34 | /** \file TEncEntropy.cpp |
---|
| 35 | \brief entropy encoder class |
---|
| 36 | */ |
---|
| 37 | |
---|
| 38 | #include "TEncEntropy.h" |
---|
| 39 | #include "TLibCommon/TypeDef.h" |
---|
| 40 | #include "TLibCommon/TComSampleAdaptiveOffset.h" |
---|
| 41 | |
---|
| 42 | //! \ingroup TLibEncoder |
---|
| 43 | //! \{ |
---|
| 44 | |
---|
| 45 | Void TEncEntropy::setEntropyCoder ( TEncEntropyIf* e, TComSlice* pcSlice ) |
---|
| 46 | { |
---|
| 47 | m_pcEntropyCoderIf = e; |
---|
| 48 | m_pcEntropyCoderIf->setSlice ( pcSlice ); |
---|
| 49 | } |
---|
| 50 | |
---|
| 51 | Void TEncEntropy::encodeSliceHeader ( TComSlice* pcSlice ) |
---|
| 52 | { |
---|
| 53 | m_pcEntropyCoderIf->codeSliceHeader( pcSlice ); |
---|
| 54 | return; |
---|
| 55 | } |
---|
| 56 | |
---|
| 57 | Void TEncEntropy::encodeTilesWPPEntryPoint( TComSlice* pSlice ) |
---|
| 58 | { |
---|
| 59 | m_pcEntropyCoderIf->codeTilesWPPEntryPoint( pSlice ); |
---|
| 60 | } |
---|
| 61 | |
---|
[644] | 62 | #if POC_RESET_IDC_SIGNALLING |
---|
| 63 | Void TEncEntropy::encodeSliceHeaderExtn( TComSlice* pSlice, Int shBitsWrittenTillNow ) |
---|
| 64 | { |
---|
| 65 | m_pcEntropyCoderIf->codeSliceHeaderExtn( pSlice, shBitsWrittenTillNow ); |
---|
| 66 | } |
---|
| 67 | #endif |
---|
| 68 | |
---|
[313] | 69 | Void TEncEntropy::encodeTerminatingBit ( UInt uiIsLast ) |
---|
| 70 | { |
---|
| 71 | m_pcEntropyCoderIf->codeTerminatingBit( uiIsLast ); |
---|
| 72 | |
---|
| 73 | return; |
---|
| 74 | } |
---|
| 75 | |
---|
| 76 | Void TEncEntropy::encodeSliceFinish() |
---|
| 77 | { |
---|
| 78 | m_pcEntropyCoderIf->codeSliceFinish(); |
---|
| 79 | } |
---|
| 80 | |
---|
[677] | 81 | #if Q0048_CGS_3D_ASYMLUT |
---|
[684] | 82 | Void TEncEntropy::encodePPS( TComPPS* pcPPS, TEnc3DAsymLUT * pc3DAsymLUT ) |
---|
[313] | 83 | { |
---|
[684] | 84 | m_pcEntropyCoderIf->codePPS( pcPPS, pc3DAsymLUT ); |
---|
[313] | 85 | return; |
---|
| 86 | } |
---|
[684] | 87 | #else |
---|
| 88 | Void TEncEntropy::encodePPS( TComPPS* pcPPS ) |
---|
| 89 | { |
---|
| 90 | m_pcEntropyCoderIf->codePPS( pcPPS ); |
---|
| 91 | return; |
---|
| 92 | } |
---|
| 93 | #endif |
---|
[313] | 94 | |
---|
| 95 | Void TEncEntropy::encodeSPS( TComSPS* pcSPS ) |
---|
| 96 | { |
---|
| 97 | m_pcEntropyCoderIf->codeSPS( pcSPS ); |
---|
| 98 | return; |
---|
| 99 | } |
---|
| 100 | |
---|
| 101 | Void TEncEntropy::encodeCUTransquantBypassFlag( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool bRD ) |
---|
| 102 | { |
---|
| 103 | if( bRD ) |
---|
| 104 | { |
---|
| 105 | uiAbsPartIdx = 0; |
---|
| 106 | } |
---|
| 107 | m_pcEntropyCoderIf->codeCUTransquantBypassFlag( pcCU, uiAbsPartIdx ); |
---|
| 108 | } |
---|
| 109 | |
---|
| 110 | Void TEncEntropy::encodeVPS( TComVPS* pcVPS ) |
---|
| 111 | { |
---|
| 112 | m_pcEntropyCoderIf->codeVPS( pcVPS ); |
---|
| 113 | return; |
---|
| 114 | } |
---|
| 115 | |
---|
| 116 | Void TEncEntropy::encodeSkipFlag( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool bRD ) |
---|
| 117 | { |
---|
| 118 | if ( pcCU->getSlice()->isIntra() ) |
---|
| 119 | { |
---|
| 120 | return; |
---|
| 121 | } |
---|
| 122 | if( bRD ) |
---|
| 123 | { |
---|
| 124 | uiAbsPartIdx = 0; |
---|
| 125 | } |
---|
| 126 | m_pcEntropyCoderIf->codeSkipFlag( pcCU, uiAbsPartIdx ); |
---|
| 127 | } |
---|
| 128 | |
---|
| 129 | /** encode merge flag |
---|
| 130 | * \param pcCU |
---|
| 131 | * \param uiAbsPartIdx |
---|
| 132 | * \returns Void |
---|
| 133 | */ |
---|
| 134 | Void TEncEntropy::encodeMergeFlag( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
| 135 | { |
---|
| 136 | // at least one merge candidate exists |
---|
| 137 | m_pcEntropyCoderIf->codeMergeFlag( pcCU, uiAbsPartIdx ); |
---|
| 138 | } |
---|
| 139 | |
---|
| 140 | /** encode merge index |
---|
| 141 | * \param pcCU |
---|
| 142 | * \param uiAbsPartIdx |
---|
| 143 | * \param uiPUIdx |
---|
| 144 | * \param bRD |
---|
| 145 | * \returns Void |
---|
| 146 | */ |
---|
| 147 | Void TEncEntropy::encodeMergeIndex( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool bRD ) |
---|
| 148 | { |
---|
| 149 | if( bRD ) |
---|
| 150 | { |
---|
| 151 | uiAbsPartIdx = 0; |
---|
| 152 | assert( pcCU->getPartitionSize(uiAbsPartIdx) == SIZE_2Nx2N ); |
---|
| 153 | } |
---|
| 154 | m_pcEntropyCoderIf->codeMergeIndex( pcCU, uiAbsPartIdx ); |
---|
| 155 | } |
---|
| 156 | |
---|
| 157 | /** encode prediction mode |
---|
| 158 | * \param pcCU |
---|
| 159 | * \param uiAbsPartIdx |
---|
| 160 | * \param bRD |
---|
| 161 | * \returns Void |
---|
| 162 | */ |
---|
| 163 | Void TEncEntropy::encodePredMode( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool bRD ) |
---|
| 164 | { |
---|
| 165 | if( bRD ) |
---|
| 166 | { |
---|
| 167 | uiAbsPartIdx = 0; |
---|
| 168 | } |
---|
| 169 | if ( pcCU->getSlice()->isIntra() ) |
---|
| 170 | { |
---|
| 171 | return; |
---|
| 172 | } |
---|
| 173 | |
---|
| 174 | m_pcEntropyCoderIf->codePredMode( pcCU, uiAbsPartIdx ); |
---|
| 175 | } |
---|
| 176 | |
---|
| 177 | // Split mode |
---|
| 178 | Void TEncEntropy::encodeSplitFlag( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, Bool bRD ) |
---|
| 179 | { |
---|
| 180 | if( bRD ) |
---|
| 181 | { |
---|
| 182 | uiAbsPartIdx = 0; |
---|
| 183 | } |
---|
| 184 | m_pcEntropyCoderIf->codeSplitFlag( pcCU, uiAbsPartIdx, uiDepth ); |
---|
| 185 | } |
---|
| 186 | |
---|
| 187 | /** encode partition size |
---|
| 188 | * \param pcCU |
---|
| 189 | * \param uiAbsPartIdx |
---|
| 190 | * \param uiDepth |
---|
| 191 | * \param bRD |
---|
| 192 | * \returns Void |
---|
| 193 | */ |
---|
| 194 | Void TEncEntropy::encodePartSize( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, Bool bRD ) |
---|
| 195 | { |
---|
| 196 | if( bRD ) |
---|
| 197 | { |
---|
| 198 | uiAbsPartIdx = 0; |
---|
| 199 | } |
---|
| 200 | m_pcEntropyCoderIf->codePartSize( pcCU, uiAbsPartIdx, uiDepth ); |
---|
| 201 | } |
---|
| 202 | |
---|
| 203 | /** Encode I_PCM information. |
---|
| 204 | * \param pcCU pointer to CU |
---|
| 205 | * \param uiAbsPartIdx CU index |
---|
| 206 | * \param bRD flag indicating estimation or encoding |
---|
| 207 | * \returns Void |
---|
| 208 | */ |
---|
| 209 | Void TEncEntropy::encodeIPCMInfo( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool bRD ) |
---|
| 210 | { |
---|
| 211 | if(!pcCU->getSlice()->getSPS()->getUsePCM() |
---|
| 212 | || pcCU->getWidth(uiAbsPartIdx) > (1<<pcCU->getSlice()->getSPS()->getPCMLog2MaxSize()) |
---|
| 213 | || pcCU->getWidth(uiAbsPartIdx) < (1<<pcCU->getSlice()->getSPS()->getPCMLog2MinSize())) |
---|
| 214 | { |
---|
| 215 | return; |
---|
| 216 | } |
---|
| 217 | |
---|
| 218 | if( bRD ) |
---|
| 219 | { |
---|
| 220 | uiAbsPartIdx = 0; |
---|
| 221 | } |
---|
| 222 | |
---|
| 223 | m_pcEntropyCoderIf->codeIPCMInfo ( pcCU, uiAbsPartIdx ); |
---|
| 224 | } |
---|
| 225 | |
---|
| 226 | Void TEncEntropy::xEncodeTransform( TComDataCU* pcCU,UInt offsetLuma, UInt offsetChroma, UInt uiAbsPartIdx, UInt uiDepth, UInt width, UInt height, UInt uiTrIdx, Bool& bCodeDQP ) |
---|
| 227 | { |
---|
| 228 | const UInt uiSubdiv = pcCU->getTransformIdx( uiAbsPartIdx ) + pcCU->getDepth( uiAbsPartIdx ) > uiDepth; |
---|
| 229 | const UInt uiLog2TrafoSize = g_aucConvertToBit[pcCU->getSlice()->getSPS()->getMaxCUWidth()]+2 - uiDepth; |
---|
| 230 | UInt cbfY = pcCU->getCbf( uiAbsPartIdx, TEXT_LUMA , uiTrIdx ); |
---|
| 231 | UInt cbfU = pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_U, uiTrIdx ); |
---|
| 232 | UInt cbfV = pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_V, uiTrIdx ); |
---|
| 233 | |
---|
| 234 | if(uiTrIdx==0) |
---|
| 235 | { |
---|
| 236 | m_bakAbsPartIdxCU = uiAbsPartIdx; |
---|
| 237 | } |
---|
| 238 | if( uiLog2TrafoSize == 2 ) |
---|
| 239 | { |
---|
| 240 | UInt partNum = pcCU->getPic()->getNumPartInCU() >> ( ( uiDepth - 1 ) << 1 ); |
---|
| 241 | if( ( uiAbsPartIdx % partNum ) == 0 ) |
---|
| 242 | { |
---|
| 243 | m_uiBakAbsPartIdx = uiAbsPartIdx; |
---|
| 244 | m_uiBakChromaOffset = offsetChroma; |
---|
| 245 | } |
---|
| 246 | else if( ( uiAbsPartIdx % partNum ) == (partNum - 1) ) |
---|
| 247 | { |
---|
| 248 | cbfU = pcCU->getCbf( m_uiBakAbsPartIdx, TEXT_CHROMA_U, uiTrIdx ); |
---|
| 249 | cbfV = pcCU->getCbf( m_uiBakAbsPartIdx, TEXT_CHROMA_V, uiTrIdx ); |
---|
| 250 | } |
---|
| 251 | } |
---|
| 252 | |
---|
| 253 | if( pcCU->getPredictionMode(uiAbsPartIdx) == MODE_INTRA && pcCU->getPartitionSize(uiAbsPartIdx) == SIZE_NxN && uiDepth == pcCU->getDepth(uiAbsPartIdx) ) |
---|
| 254 | { |
---|
| 255 | assert( uiSubdiv ); |
---|
| 256 | } |
---|
| 257 | else if( pcCU->getPredictionMode(uiAbsPartIdx) == MODE_INTER && (pcCU->getPartitionSize(uiAbsPartIdx) != SIZE_2Nx2N) && uiDepth == pcCU->getDepth(uiAbsPartIdx) && (pcCU->getSlice()->getSPS()->getQuadtreeTUMaxDepthInter() == 1) ) |
---|
| 258 | { |
---|
| 259 | if ( uiLog2TrafoSize > pcCU->getQuadtreeTULog2MinSizeInCU(uiAbsPartIdx) ) |
---|
| 260 | { |
---|
| 261 | assert( uiSubdiv ); |
---|
| 262 | } |
---|
| 263 | else |
---|
| 264 | { |
---|
| 265 | assert(!uiSubdiv ); |
---|
| 266 | } |
---|
| 267 | } |
---|
| 268 | else if( uiLog2TrafoSize > pcCU->getSlice()->getSPS()->getQuadtreeTULog2MaxSize() ) |
---|
| 269 | { |
---|
| 270 | assert( uiSubdiv ); |
---|
| 271 | } |
---|
| 272 | else if( uiLog2TrafoSize == pcCU->getSlice()->getSPS()->getQuadtreeTULog2MinSize() ) |
---|
| 273 | { |
---|
| 274 | assert( !uiSubdiv ); |
---|
| 275 | } |
---|
| 276 | else if( uiLog2TrafoSize == pcCU->getQuadtreeTULog2MinSizeInCU(uiAbsPartIdx) ) |
---|
| 277 | { |
---|
| 278 | assert( !uiSubdiv ); |
---|
| 279 | } |
---|
| 280 | else |
---|
| 281 | { |
---|
| 282 | assert( uiLog2TrafoSize > pcCU->getQuadtreeTULog2MinSizeInCU(uiAbsPartIdx) ); |
---|
| 283 | m_pcEntropyCoderIf->codeTransformSubdivFlag( uiSubdiv, 5 - uiLog2TrafoSize ); |
---|
| 284 | } |
---|
| 285 | |
---|
| 286 | const UInt uiTrDepthCurr = uiDepth - pcCU->getDepth( uiAbsPartIdx ); |
---|
| 287 | const Bool bFirstCbfOfCU = uiTrDepthCurr == 0; |
---|
[494] | 288 | #if AUXILIARY_PICTURES |
---|
| 289 | if (pcCU->getSlice()->getChromaFormatIdc() != CHROMA_400) |
---|
| 290 | { |
---|
| 291 | #endif |
---|
[313] | 292 | if( bFirstCbfOfCU || uiLog2TrafoSize > 2 ) |
---|
| 293 | { |
---|
| 294 | if( bFirstCbfOfCU || pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_U, uiTrDepthCurr - 1 ) ) |
---|
| 295 | { |
---|
| 296 | m_pcEntropyCoderIf->codeQtCbf( pcCU, uiAbsPartIdx, TEXT_CHROMA_U, uiTrDepthCurr ); |
---|
| 297 | } |
---|
| 298 | if( bFirstCbfOfCU || pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_V, uiTrDepthCurr - 1 ) ) |
---|
| 299 | { |
---|
| 300 | m_pcEntropyCoderIf->codeQtCbf( pcCU, uiAbsPartIdx, TEXT_CHROMA_V, uiTrDepthCurr ); |
---|
| 301 | } |
---|
| 302 | } |
---|
| 303 | else if( uiLog2TrafoSize == 2 ) |
---|
| 304 | { |
---|
| 305 | assert( pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_U, uiTrDepthCurr ) == pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_U, uiTrDepthCurr - 1 ) ); |
---|
| 306 | assert( pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_V, uiTrDepthCurr ) == pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_V, uiTrDepthCurr - 1 ) ); |
---|
| 307 | } |
---|
[494] | 308 | #if AUXILIARY_PICTURES |
---|
| 309 | } |
---|
| 310 | else |
---|
| 311 | { |
---|
| 312 | assert( pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_U, uiTrDepthCurr ) == 0 ); |
---|
| 313 | assert( pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_V, uiTrDepthCurr ) == 0 ); |
---|
| 314 | } |
---|
| 315 | #endif |
---|
[313] | 316 | |
---|
| 317 | if( uiSubdiv ) |
---|
| 318 | { |
---|
| 319 | UInt size; |
---|
| 320 | width >>= 1; |
---|
| 321 | height >>= 1; |
---|
| 322 | size = width*height; |
---|
| 323 | uiTrIdx++; |
---|
| 324 | ++uiDepth; |
---|
| 325 | const UInt partNum = pcCU->getPic()->getNumPartInCU() >> (uiDepth << 1); |
---|
| 326 | |
---|
| 327 | xEncodeTransform( pcCU, offsetLuma, offsetChroma, uiAbsPartIdx, uiDepth, width, height, uiTrIdx, bCodeDQP ); |
---|
| 328 | |
---|
| 329 | uiAbsPartIdx += partNum; offsetLuma += size; offsetChroma += (size>>2); |
---|
| 330 | xEncodeTransform( pcCU, offsetLuma, offsetChroma, uiAbsPartIdx, uiDepth, width, height, uiTrIdx, bCodeDQP ); |
---|
| 331 | |
---|
| 332 | uiAbsPartIdx += partNum; offsetLuma += size; offsetChroma += (size>>2); |
---|
| 333 | xEncodeTransform( pcCU, offsetLuma, offsetChroma, uiAbsPartIdx, uiDepth, width, height, uiTrIdx, bCodeDQP ); |
---|
| 334 | |
---|
| 335 | uiAbsPartIdx += partNum; offsetLuma += size; offsetChroma += (size>>2); |
---|
| 336 | xEncodeTransform( pcCU, offsetLuma, offsetChroma, uiAbsPartIdx, uiDepth, width, height, uiTrIdx, bCodeDQP ); |
---|
| 337 | } |
---|
| 338 | else |
---|
| 339 | { |
---|
| 340 | { |
---|
| 341 | DTRACE_CABAC_VL( g_nSymbolCounter++ ); |
---|
| 342 | DTRACE_CABAC_T( "\tTrIdx: abspart=" ); |
---|
| 343 | DTRACE_CABAC_V( uiAbsPartIdx ); |
---|
| 344 | DTRACE_CABAC_T( "\tdepth=" ); |
---|
| 345 | DTRACE_CABAC_V( uiDepth ); |
---|
| 346 | DTRACE_CABAC_T( "\ttrdepth=" ); |
---|
| 347 | DTRACE_CABAC_V( pcCU->getTransformIdx( uiAbsPartIdx ) ); |
---|
| 348 | DTRACE_CABAC_T( "\n" ); |
---|
| 349 | } |
---|
| 350 | |
---|
| 351 | if( pcCU->getPredictionMode(uiAbsPartIdx) != MODE_INTRA && uiDepth == pcCU->getDepth( uiAbsPartIdx ) && !pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_U, 0 ) && !pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_V, 0 ) ) |
---|
| 352 | { |
---|
| 353 | assert( pcCU->getCbf( uiAbsPartIdx, TEXT_LUMA, 0 ) ); |
---|
| 354 | // printf( "saved one bin! " ); |
---|
| 355 | } |
---|
| 356 | else |
---|
| 357 | { |
---|
| 358 | m_pcEntropyCoderIf->codeQtCbf( pcCU, uiAbsPartIdx, TEXT_LUMA, pcCU->getTransformIdx( uiAbsPartIdx ) ); |
---|
| 359 | } |
---|
| 360 | |
---|
| 361 | |
---|
| 362 | if ( cbfY || cbfU || cbfV ) |
---|
| 363 | { |
---|
| 364 | // dQP: only for LCU once |
---|
| 365 | if ( pcCU->getSlice()->getPPS()->getUseDQP() ) |
---|
| 366 | { |
---|
| 367 | if ( bCodeDQP ) |
---|
| 368 | { |
---|
| 369 | encodeQP( pcCU, m_bakAbsPartIdxCU ); |
---|
| 370 | bCodeDQP = false; |
---|
| 371 | } |
---|
| 372 | } |
---|
| 373 | } |
---|
| 374 | if( cbfY ) |
---|
| 375 | { |
---|
| 376 | Int trWidth = width; |
---|
| 377 | Int trHeight = height; |
---|
| 378 | m_pcEntropyCoderIf->codeCoeffNxN( pcCU, (pcCU->getCoeffY()+offsetLuma), uiAbsPartIdx, trWidth, trHeight, uiDepth, TEXT_LUMA ); |
---|
| 379 | } |
---|
| 380 | if( uiLog2TrafoSize > 2 ) |
---|
| 381 | { |
---|
| 382 | Int trWidth = width >> 1; |
---|
| 383 | Int trHeight = height >> 1; |
---|
| 384 | if( cbfU ) |
---|
| 385 | { |
---|
| 386 | m_pcEntropyCoderIf->codeCoeffNxN( pcCU, (pcCU->getCoeffCb()+offsetChroma), uiAbsPartIdx, trWidth, trHeight, uiDepth, TEXT_CHROMA_U ); |
---|
| 387 | } |
---|
| 388 | if( cbfV ) |
---|
| 389 | { |
---|
| 390 | m_pcEntropyCoderIf->codeCoeffNxN( pcCU, (pcCU->getCoeffCr()+offsetChroma), uiAbsPartIdx, trWidth, trHeight, uiDepth, TEXT_CHROMA_V ); |
---|
| 391 | } |
---|
| 392 | } |
---|
| 393 | else |
---|
| 394 | { |
---|
| 395 | UInt partNum = pcCU->getPic()->getNumPartInCU() >> ( ( uiDepth - 1 ) << 1 ); |
---|
| 396 | if( ( uiAbsPartIdx % partNum ) == (partNum - 1) ) |
---|
| 397 | { |
---|
| 398 | Int trWidth = width; |
---|
| 399 | Int trHeight = height; |
---|
| 400 | if( cbfU ) |
---|
| 401 | { |
---|
| 402 | m_pcEntropyCoderIf->codeCoeffNxN( pcCU, (pcCU->getCoeffCb()+m_uiBakChromaOffset), m_uiBakAbsPartIdx, trWidth, trHeight, uiDepth, TEXT_CHROMA_U ); |
---|
| 403 | } |
---|
| 404 | if( cbfV ) |
---|
| 405 | { |
---|
| 406 | m_pcEntropyCoderIf->codeCoeffNxN( pcCU, (pcCU->getCoeffCr()+m_uiBakChromaOffset), m_uiBakAbsPartIdx, trWidth, trHeight, uiDepth, TEXT_CHROMA_V ); |
---|
| 407 | } |
---|
| 408 | } |
---|
| 409 | } |
---|
| 410 | } |
---|
| 411 | } |
---|
| 412 | |
---|
| 413 | // Intra direction for Luma |
---|
| 414 | Void TEncEntropy::encodeIntraDirModeLuma ( TComDataCU* pcCU, UInt absPartIdx, Bool isMultiplePU ) |
---|
| 415 | { |
---|
| 416 | m_pcEntropyCoderIf->codeIntraDirLumaAng( pcCU, absPartIdx , isMultiplePU); |
---|
| 417 | } |
---|
| 418 | |
---|
| 419 | // Intra direction for Chroma |
---|
| 420 | Void TEncEntropy::encodeIntraDirModeChroma( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool bRD ) |
---|
| 421 | { |
---|
[494] | 422 | #if AUXILIARY_PICTURES |
---|
| 423 | if ( pcCU->getSlice()->getChromaFormatIdc() == CHROMA_400 ) |
---|
| 424 | { |
---|
| 425 | return; |
---|
| 426 | } |
---|
| 427 | #endif |
---|
[313] | 428 | if( bRD ) |
---|
| 429 | { |
---|
| 430 | uiAbsPartIdx = 0; |
---|
| 431 | } |
---|
| 432 | |
---|
| 433 | m_pcEntropyCoderIf->codeIntraDirChroma( pcCU, uiAbsPartIdx ); |
---|
| 434 | } |
---|
| 435 | |
---|
| 436 | Void TEncEntropy::encodePredInfo( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool bRD ) |
---|
| 437 | { |
---|
| 438 | if( bRD ) |
---|
| 439 | { |
---|
| 440 | uiAbsPartIdx = 0; |
---|
| 441 | } |
---|
| 442 | if( pcCU->isIntra( uiAbsPartIdx ) ) // If it is Intra mode, encode intra prediction mode. |
---|
| 443 | { |
---|
| 444 | encodeIntraDirModeLuma ( pcCU, uiAbsPartIdx,true ); |
---|
| 445 | encodeIntraDirModeChroma( pcCU, uiAbsPartIdx, bRD ); |
---|
| 446 | } |
---|
| 447 | else // if it is Inter mode, encode motion vector and reference index |
---|
| 448 | { |
---|
| 449 | encodePUWise( pcCU, uiAbsPartIdx, bRD ); |
---|
| 450 | } |
---|
| 451 | } |
---|
| 452 | |
---|
| 453 | /** encode motion information for every PU block |
---|
| 454 | * \param pcCU |
---|
| 455 | * \param uiAbsPartIdx |
---|
| 456 | * \param bRD |
---|
| 457 | * \returns Void |
---|
| 458 | */ |
---|
| 459 | Void TEncEntropy::encodePUWise( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool bRD ) |
---|
| 460 | { |
---|
| 461 | if ( bRD ) |
---|
| 462 | { |
---|
| 463 | uiAbsPartIdx = 0; |
---|
| 464 | } |
---|
| 465 | |
---|
| 466 | PartSize ePartSize = pcCU->getPartitionSize( uiAbsPartIdx ); |
---|
| 467 | UInt uiNumPU = ( ePartSize == SIZE_2Nx2N ? 1 : ( ePartSize == SIZE_NxN ? 4 : 2 ) ); |
---|
| 468 | UInt uiDepth = pcCU->getDepth( uiAbsPartIdx ); |
---|
| 469 | UInt uiPUOffset = ( g_auiPUOffset[UInt( ePartSize )] << ( ( pcCU->getSlice()->getSPS()->getMaxCUDepth() - uiDepth ) << 1 ) ) >> 4; |
---|
| 470 | |
---|
| 471 | for ( UInt uiPartIdx = 0, uiSubPartIdx = uiAbsPartIdx; uiPartIdx < uiNumPU; uiPartIdx++, uiSubPartIdx += uiPUOffset ) |
---|
| 472 | { |
---|
| 473 | encodeMergeFlag( pcCU, uiSubPartIdx ); |
---|
| 474 | if ( pcCU->getMergeFlag( uiSubPartIdx ) ) |
---|
| 475 | { |
---|
| 476 | encodeMergeIndex( pcCU, uiSubPartIdx ); |
---|
| 477 | } |
---|
| 478 | else |
---|
| 479 | { |
---|
| 480 | encodeInterDirPU( pcCU, uiSubPartIdx ); |
---|
| 481 | for ( UInt uiRefListIdx = 0; uiRefListIdx < 2; uiRefListIdx++ ) |
---|
| 482 | { |
---|
| 483 | if ( pcCU->getSlice()->getNumRefIdx( RefPicList( uiRefListIdx ) ) > 0 ) |
---|
| 484 | { |
---|
| 485 | encodeRefFrmIdxPU ( pcCU, uiSubPartIdx, RefPicList( uiRefListIdx ) ); |
---|
| 486 | encodeMvdPU ( pcCU, uiSubPartIdx, RefPicList( uiRefListIdx ) ); |
---|
| 487 | encodeMVPIdxPU ( pcCU, uiSubPartIdx, RefPicList( uiRefListIdx ) ); |
---|
| 488 | } |
---|
| 489 | } |
---|
| 490 | } |
---|
| 491 | } |
---|
| 492 | |
---|
| 493 | return; |
---|
| 494 | } |
---|
| 495 | |
---|
| 496 | Void TEncEntropy::encodeInterDirPU( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
| 497 | { |
---|
| 498 | if ( !pcCU->getSlice()->isInterB() ) |
---|
| 499 | { |
---|
| 500 | return; |
---|
| 501 | } |
---|
| 502 | |
---|
| 503 | m_pcEntropyCoderIf->codeInterDir( pcCU, uiAbsPartIdx ); |
---|
| 504 | return; |
---|
| 505 | } |
---|
| 506 | |
---|
| 507 | /** encode reference frame index for a PU block |
---|
| 508 | * \param pcCU |
---|
| 509 | * \param uiAbsPartIdx |
---|
| 510 | * \param eRefList |
---|
| 511 | * \returns Void |
---|
| 512 | */ |
---|
| 513 | Void TEncEntropy::encodeRefFrmIdxPU( TComDataCU* pcCU, UInt uiAbsPartIdx, RefPicList eRefList ) |
---|
| 514 | { |
---|
| 515 | assert( !pcCU->isIntra( uiAbsPartIdx ) ); |
---|
| 516 | { |
---|
| 517 | if ( ( pcCU->getSlice()->getNumRefIdx( eRefList ) == 1 ) ) |
---|
| 518 | { |
---|
| 519 | return; |
---|
| 520 | } |
---|
| 521 | |
---|
| 522 | if ( pcCU->getInterDir( uiAbsPartIdx ) & ( 1 << eRefList ) ) |
---|
| 523 | { |
---|
| 524 | m_pcEntropyCoderIf->codeRefFrmIdx( pcCU, uiAbsPartIdx, eRefList ); |
---|
| 525 | } |
---|
| 526 | } |
---|
| 527 | |
---|
| 528 | return; |
---|
| 529 | } |
---|
| 530 | |
---|
| 531 | /** encode motion vector difference for a PU block |
---|
| 532 | * \param pcCU |
---|
| 533 | * \param uiAbsPartIdx |
---|
| 534 | * \param eRefList |
---|
| 535 | * \returns Void |
---|
| 536 | */ |
---|
| 537 | Void TEncEntropy::encodeMvdPU( TComDataCU* pcCU, UInt uiAbsPartIdx, RefPicList eRefList ) |
---|
| 538 | { |
---|
| 539 | assert( !pcCU->isIntra( uiAbsPartIdx ) ); |
---|
| 540 | |
---|
| 541 | if ( pcCU->getInterDir( uiAbsPartIdx ) & ( 1 << eRefList ) ) |
---|
| 542 | { |
---|
| 543 | m_pcEntropyCoderIf->codeMvd( pcCU, uiAbsPartIdx, eRefList ); |
---|
| 544 | } |
---|
| 545 | return; |
---|
| 546 | } |
---|
| 547 | |
---|
| 548 | Void TEncEntropy::encodeMVPIdxPU( TComDataCU* pcCU, UInt uiAbsPartIdx, RefPicList eRefList ) |
---|
| 549 | { |
---|
| 550 | if ( (pcCU->getInterDir( uiAbsPartIdx ) & ( 1 << eRefList )) ) |
---|
| 551 | { |
---|
| 552 | m_pcEntropyCoderIf->codeMVPIdx( pcCU, uiAbsPartIdx, eRefList ); |
---|
| 553 | } |
---|
| 554 | |
---|
| 555 | return; |
---|
| 556 | } |
---|
| 557 | |
---|
| 558 | Void TEncEntropy::encodeQtCbf( TComDataCU* pcCU, UInt uiAbsPartIdx, TextType eType, UInt uiTrDepth ) |
---|
| 559 | { |
---|
| 560 | m_pcEntropyCoderIf->codeQtCbf( pcCU, uiAbsPartIdx, eType, uiTrDepth ); |
---|
| 561 | } |
---|
| 562 | |
---|
| 563 | Void TEncEntropy::encodeTransformSubdivFlag( UInt uiSymbol, UInt uiCtx ) |
---|
| 564 | { |
---|
| 565 | m_pcEntropyCoderIf->codeTransformSubdivFlag( uiSymbol, uiCtx ); |
---|
| 566 | } |
---|
| 567 | |
---|
| 568 | Void TEncEntropy::encodeQtRootCbf( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
| 569 | { |
---|
| 570 | m_pcEntropyCoderIf->codeQtRootCbf( pcCU, uiAbsPartIdx ); |
---|
| 571 | } |
---|
| 572 | |
---|
| 573 | Void TEncEntropy::encodeQtCbfZero( TComDataCU* pcCU, TextType eType, UInt uiTrDepth ) |
---|
| 574 | { |
---|
| 575 | m_pcEntropyCoderIf->codeQtCbfZero( pcCU, eType, uiTrDepth ); |
---|
| 576 | } |
---|
| 577 | Void TEncEntropy::encodeQtRootCbfZero( TComDataCU* pcCU ) |
---|
| 578 | { |
---|
| 579 | m_pcEntropyCoderIf->codeQtRootCbfZero( pcCU ); |
---|
| 580 | } |
---|
| 581 | |
---|
| 582 | // dQP |
---|
| 583 | Void TEncEntropy::encodeQP( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool bRD ) |
---|
| 584 | { |
---|
| 585 | if( bRD ) |
---|
| 586 | { |
---|
| 587 | uiAbsPartIdx = 0; |
---|
| 588 | } |
---|
| 589 | |
---|
| 590 | if ( pcCU->getSlice()->getPPS()->getUseDQP() ) |
---|
| 591 | { |
---|
| 592 | m_pcEntropyCoderIf->codeDeltaQP( pcCU, uiAbsPartIdx ); |
---|
| 593 | } |
---|
| 594 | } |
---|
| 595 | |
---|
| 596 | |
---|
| 597 | // texture |
---|
| 598 | /** encode coefficients |
---|
| 599 | * \param pcCU |
---|
| 600 | * \param uiAbsPartIdx |
---|
| 601 | * \param uiDepth |
---|
| 602 | * \param uiWidth |
---|
| 603 | * \param uiHeight |
---|
| 604 | */ |
---|
| 605 | Void TEncEntropy::encodeCoeff( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, UInt uiWidth, UInt uiHeight, Bool& bCodeDQP ) |
---|
| 606 | { |
---|
| 607 | UInt uiMinCoeffSize = pcCU->getPic()->getMinCUWidth()*pcCU->getPic()->getMinCUHeight(); |
---|
| 608 | UInt uiLumaOffset = uiMinCoeffSize*uiAbsPartIdx; |
---|
| 609 | UInt uiChromaOffset = uiLumaOffset>>2; |
---|
| 610 | |
---|
| 611 | if( pcCU->isIntra(uiAbsPartIdx) ) |
---|
| 612 | { |
---|
| 613 | DTRACE_CABAC_VL( g_nSymbolCounter++ ) |
---|
| 614 | DTRACE_CABAC_T( "\tdecodeTransformIdx()\tCUDepth=" ) |
---|
| 615 | DTRACE_CABAC_V( uiDepth ) |
---|
| 616 | DTRACE_CABAC_T( "\n" ) |
---|
| 617 | } |
---|
| 618 | else |
---|
| 619 | { |
---|
| 620 | if( !(pcCU->getMergeFlag( uiAbsPartIdx ) && pcCU->getPartitionSize(uiAbsPartIdx) == SIZE_2Nx2N ) ) |
---|
| 621 | { |
---|
| 622 | m_pcEntropyCoderIf->codeQtRootCbf( pcCU, uiAbsPartIdx ); |
---|
| 623 | } |
---|
| 624 | if ( !pcCU->getQtRootCbf( uiAbsPartIdx ) ) |
---|
| 625 | { |
---|
| 626 | return; |
---|
| 627 | } |
---|
| 628 | } |
---|
| 629 | |
---|
| 630 | xEncodeTransform( pcCU, uiLumaOffset, uiChromaOffset, uiAbsPartIdx, uiDepth, uiWidth, uiHeight, 0, bCodeDQP); |
---|
| 631 | } |
---|
| 632 | |
---|
| 633 | Void TEncEntropy::encodeCoeffNxN( TComDataCU* pcCU, TCoeff* pcCoeff, UInt uiAbsPartIdx, UInt uiTrWidth, UInt uiTrHeight, UInt uiDepth, TextType eType ) |
---|
| 634 | { |
---|
| 635 | // This is for Transform unit processing. This may be used at mode selection stage for Inter. |
---|
| 636 | m_pcEntropyCoderIf->codeCoeffNxN( pcCU, pcCoeff, uiAbsPartIdx, uiTrWidth, uiTrHeight, uiDepth, eType ); |
---|
| 637 | } |
---|
| 638 | |
---|
| 639 | Void TEncEntropy::estimateBit (estBitsSbacStruct* pcEstBitsSbac, Int width, Int height, TextType eTType) |
---|
| 640 | { |
---|
| 641 | eTType = eTType == TEXT_LUMA ? TEXT_LUMA : TEXT_CHROMA; |
---|
| 642 | |
---|
| 643 | m_pcEntropyCoderIf->estBit ( pcEstBitsSbac, width, height, eTType ); |
---|
| 644 | } |
---|
| 645 | |
---|
| 646 | Int TEncEntropy::countNonZeroCoeffs( TCoeff* pcCoef, UInt uiSize ) |
---|
| 647 | { |
---|
| 648 | Int count = 0; |
---|
| 649 | |
---|
| 650 | for ( Int i = 0; i < uiSize; i++ ) |
---|
| 651 | { |
---|
| 652 | count += pcCoef[i] != 0; |
---|
| 653 | } |
---|
| 654 | |
---|
| 655 | return count; |
---|
| 656 | } |
---|
| 657 | |
---|
| 658 | /** encode quantization matrix |
---|
| 659 | * \param scalingList quantization matrix information |
---|
| 660 | */ |
---|
| 661 | Void TEncEntropy::encodeScalingList( TComScalingList* scalingList ) |
---|
| 662 | { |
---|
| 663 | m_pcEntropyCoderIf->codeScalingList( scalingList ); |
---|
| 664 | } |
---|
| 665 | |
---|
| 666 | //! \} |
---|