[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 | * |
---|
[608] | 6 | * Copyright (c) 2010-2013, 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/TComSampleAdaptiveOffset.h" |
---|
[2] | 41 | |
---|
[56] | 42 | //! \ingroup TLibEncoder |
---|
| 43 | //! \{ |
---|
| 44 | |
---|
[2] | 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 | { |
---|
[56] | 53 | if (pcSlice->getSPS()->getUseSAO()) |
---|
| 54 | { |
---|
[608] | 55 | SAOParam *saoParam = pcSlice->getPic()->getPicSym()->getSaoParam(); |
---|
| 56 | pcSlice->setSaoEnabledFlag (saoParam->bSaoFlag[0]); |
---|
[443] | 57 | { |
---|
[608] | 58 | pcSlice->setSaoEnabledFlagChroma (saoParam->bSaoFlag[1]); |
---|
[443] | 59 | } |
---|
[56] | 60 | } |
---|
| 61 | |
---|
[2] | 62 | m_pcEntropyCoderIf->codeSliceHeader( pcSlice ); |
---|
| 63 | return; |
---|
| 64 | } |
---|
| 65 | |
---|
[56] | 66 | Void TEncEntropy::encodeTilesWPPEntryPoint( TComSlice* pSlice ) |
---|
| 67 | { |
---|
| 68 | m_pcEntropyCoderIf->codeTilesWPPEntryPoint( pSlice ); |
---|
| 69 | } |
---|
| 70 | |
---|
[2] | 71 | Void TEncEntropy::encodeTerminatingBit ( UInt uiIsLast ) |
---|
| 72 | { |
---|
| 73 | m_pcEntropyCoderIf->codeTerminatingBit( uiIsLast ); |
---|
| 74 | |
---|
| 75 | return; |
---|
| 76 | } |
---|
| 77 | |
---|
| 78 | Void TEncEntropy::encodeSliceFinish() |
---|
| 79 | { |
---|
| 80 | m_pcEntropyCoderIf->codeSliceFinish(); |
---|
| 81 | } |
---|
| 82 | |
---|
| 83 | Void TEncEntropy::encodePPS( TComPPS* pcPPS ) |
---|
| 84 | { |
---|
| 85 | m_pcEntropyCoderIf->codePPS( pcPPS ); |
---|
| 86 | return; |
---|
| 87 | } |
---|
| 88 | |
---|
[608] | 89 | #if H_3D |
---|
| 90 | Void TEncEntropy::encodeSPS( TComSPS* pcSPS, Int viewIndex, Bool depthFlag ) |
---|
[77] | 91 | { |
---|
[608] | 92 | m_pcEntropyCoderIf->codeSPS( pcSPS, viewIndex, depthFlag ); |
---|
[77] | 93 | return; |
---|
| 94 | } |
---|
[56] | 95 | #else |
---|
[2] | 96 | Void TEncEntropy::encodeSPS( TComSPS* pcSPS ) |
---|
| 97 | { |
---|
| 98 | m_pcEntropyCoderIf->codeSPS( pcSPS ); |
---|
| 99 | return; |
---|
| 100 | } |
---|
[56] | 101 | #endif |
---|
[2] | 102 | |
---|
[608] | 103 | Void TEncEntropy::encodeCUTransquantBypassFlag( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool bRD ) |
---|
[2] | 104 | { |
---|
| 105 | if( bRD ) |
---|
[56] | 106 | { |
---|
[2] | 107 | uiAbsPartIdx = 0; |
---|
[56] | 108 | } |
---|
[608] | 109 | m_pcEntropyCoderIf->codeCUTransquantBypassFlag( pcCU, uiAbsPartIdx ); |
---|
[2] | 110 | } |
---|
| 111 | |
---|
[608] | 112 | Void TEncEntropy::encodeVPS( TComVPS* pcVPS ) |
---|
[189] | 113 | { |
---|
[608] | 114 | m_pcEntropyCoderIf->codeVPS( pcVPS ); |
---|
| 115 | return; |
---|
| 116 | } |
---|
| 117 | |
---|
| 118 | Void TEncEntropy::encodeSkipFlag( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool bRD ) |
---|
| 119 | { |
---|
| 120 | if ( pcCU->getSlice()->isIntra() ) |
---|
[189] | 121 | { |
---|
| 122 | return; |
---|
| 123 | } |
---|
| 124 | if( bRD ) |
---|
| 125 | { |
---|
| 126 | uiAbsPartIdx = 0; |
---|
| 127 | } |
---|
[608] | 128 | m_pcEntropyCoderIf->codeSkipFlag( pcCU, uiAbsPartIdx ); |
---|
[189] | 129 | } |
---|
| 130 | |
---|
[2] | 131 | /** encode merge flag |
---|
| 132 | * \param pcCU |
---|
| 133 | * \param uiAbsPartIdx |
---|
| 134 | * \returns Void |
---|
| 135 | */ |
---|
[608] | 136 | Void TEncEntropy::encodeMergeFlag( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
[2] | 137 | { |
---|
[56] | 138 | // at least one merge candidate exists |
---|
| 139 | m_pcEntropyCoderIf->codeMergeFlag( pcCU, uiAbsPartIdx ); |
---|
[2] | 140 | } |
---|
| 141 | |
---|
| 142 | /** encode merge index |
---|
| 143 | * \param pcCU |
---|
| 144 | * \param uiAbsPartIdx |
---|
| 145 | * \param uiPUIdx |
---|
| 146 | * \param bRD |
---|
| 147 | * \returns Void |
---|
| 148 | */ |
---|
[608] | 149 | Void TEncEntropy::encodeMergeIndex( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool bRD ) |
---|
[2] | 150 | { |
---|
| 151 | if( bRD ) |
---|
| 152 | { |
---|
| 153 | uiAbsPartIdx = 0; |
---|
| 154 | assert( pcCU->getPartitionSize(uiAbsPartIdx) == SIZE_2Nx2N ); |
---|
| 155 | } |
---|
[608] | 156 | m_pcEntropyCoderIf->codeMergeIndex( pcCU, uiAbsPartIdx ); |
---|
[2] | 157 | } |
---|
| 158 | |
---|
[608] | 159 | #if H_3D_IC |
---|
| 160 | Void TEncEntropy::encodeICFlag( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool bRD ) |
---|
[443] | 161 | { |
---|
[724] | 162 | if ( pcCU->isIntra( uiAbsPartIdx ) || ( pcCU->getSlice()->getViewIndex() == 0 ) || pcCU->getSlice()->getIsDepth() ) |
---|
[443] | 163 | { |
---|
| 164 | return; |
---|
| 165 | } |
---|
[608] | 166 | |
---|
| 167 | if( !pcCU->getSlice()->getApplyIC() ) |
---|
| 168 | return; |
---|
| 169 | |
---|
[443] | 170 | if( bRD ) |
---|
| 171 | { |
---|
| 172 | uiAbsPartIdx = 0; |
---|
| 173 | } |
---|
[608] | 174 | |
---|
| 175 | if( pcCU->isICFlagRequired( uiAbsPartIdx ) ) |
---|
| 176 | m_pcEntropyCoderIf->codeICFlag( pcCU, uiAbsPartIdx ); |
---|
[443] | 177 | } |
---|
| 178 | #endif |
---|
[2] | 179 | |
---|
[608] | 180 | #if H_3D_ARP |
---|
| 181 | Void TEncEntropy::encodeARPW( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
[56] | 182 | { |
---|
[608] | 183 | if( !pcCU->getSlice()->getARPStepNum() || pcCU->isIntra( uiAbsPartIdx ) ) |
---|
[56] | 184 | { |
---|
[608] | 185 | return; |
---|
[56] | 186 | } |
---|
| 187 | |
---|
[608] | 188 | if ( pcCU->getPartitionSize(uiAbsPartIdx)!=SIZE_2Nx2N ) |
---|
[56] | 189 | { |
---|
[608] | 190 | assert(pcCU->getARPW (uiAbsPartIdx) == 0); |
---|
[56] | 191 | } |
---|
[608] | 192 | else |
---|
[56] | 193 | { |
---|
[608] | 194 | m_pcEntropyCoderIf->codeARPW( pcCU, uiAbsPartIdx ); |
---|
[56] | 195 | } |
---|
| 196 | } |
---|
[608] | 197 | #endif |
---|
[56] | 198 | |
---|
[2] | 199 | /** encode prediction mode |
---|
| 200 | * \param pcCU |
---|
| 201 | * \param uiAbsPartIdx |
---|
| 202 | * \param bRD |
---|
| 203 | * \returns Void |
---|
| 204 | */ |
---|
| 205 | Void TEncEntropy::encodePredMode( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool bRD ) |
---|
| 206 | { |
---|
| 207 | if( bRD ) |
---|
[56] | 208 | { |
---|
[2] | 209 | uiAbsPartIdx = 0; |
---|
[56] | 210 | } |
---|
[2] | 211 | if ( pcCU->getSlice()->isIntra() ) |
---|
| 212 | { |
---|
| 213 | return; |
---|
| 214 | } |
---|
[56] | 215 | |
---|
[2] | 216 | m_pcEntropyCoderIf->codePredMode( pcCU, uiAbsPartIdx ); |
---|
| 217 | } |
---|
| 218 | |
---|
| 219 | // Split mode |
---|
| 220 | Void TEncEntropy::encodeSplitFlag( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, Bool bRD ) |
---|
| 221 | { |
---|
| 222 | if( bRD ) |
---|
[56] | 223 | { |
---|
[2] | 224 | uiAbsPartIdx = 0; |
---|
[56] | 225 | } |
---|
[2] | 226 | m_pcEntropyCoderIf->codeSplitFlag( pcCU, uiAbsPartIdx, uiDepth ); |
---|
| 227 | } |
---|
| 228 | |
---|
| 229 | /** encode partition size |
---|
| 230 | * \param pcCU |
---|
| 231 | * \param uiAbsPartIdx |
---|
| 232 | * \param uiDepth |
---|
| 233 | * \param bRD |
---|
| 234 | * \returns Void |
---|
| 235 | */ |
---|
| 236 | Void TEncEntropy::encodePartSize( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, Bool bRD ) |
---|
| 237 | { |
---|
| 238 | if( bRD ) |
---|
[56] | 239 | { |
---|
[2] | 240 | uiAbsPartIdx = 0; |
---|
[56] | 241 | } |
---|
[2] | 242 | m_pcEntropyCoderIf->codePartSize( pcCU, uiAbsPartIdx, uiDepth ); |
---|
| 243 | } |
---|
| 244 | |
---|
[56] | 245 | /** Encode I_PCM information. |
---|
| 246 | * \param pcCU pointer to CU |
---|
| 247 | * \param uiAbsPartIdx CU index |
---|
| 248 | * \param bRD flag indicating estimation or encoding |
---|
| 249 | * \returns Void |
---|
| 250 | */ |
---|
| 251 | Void TEncEntropy::encodeIPCMInfo( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool bRD ) |
---|
[2] | 252 | { |
---|
[56] | 253 | if(!pcCU->getSlice()->getSPS()->getUsePCM() |
---|
| 254 | || pcCU->getWidth(uiAbsPartIdx) > (1<<pcCU->getSlice()->getSPS()->getPCMLog2MaxSize()) |
---|
| 255 | || pcCU->getWidth(uiAbsPartIdx) < (1<<pcCU->getSlice()->getSPS()->getPCMLog2MinSize())) |
---|
| 256 | { |
---|
| 257 | return; |
---|
| 258 | } |
---|
[608] | 259 | #if H_3D_DIM_SDC |
---|
[189] | 260 | if( pcCU->getSDCFlag(uiAbsPartIdx) ) |
---|
| 261 | { |
---|
| 262 | return; |
---|
| 263 | } |
---|
| 264 | #endif |
---|
| 265 | |
---|
[56] | 266 | if( bRD ) |
---|
| 267 | { |
---|
| 268 | uiAbsPartIdx = 0; |
---|
| 269 | } |
---|
| 270 | |
---|
[608] | 271 | m_pcEntropyCoderIf->codeIPCMInfo ( pcCU, uiAbsPartIdx ); |
---|
[56] | 272 | } |
---|
| 273 | |
---|
[608] | 274 | Void TEncEntropy::xEncodeTransform( TComDataCU* pcCU,UInt offsetLuma, UInt offsetChroma, UInt uiAbsPartIdx, UInt uiDepth, UInt width, UInt height, UInt uiTrIdx, Bool& bCodeDQP ) |
---|
[56] | 275 | { |
---|
[2] | 276 | const UInt uiSubdiv = pcCU->getTransformIdx( uiAbsPartIdx ) + pcCU->getDepth( uiAbsPartIdx ) > uiDepth; |
---|
| 277 | const UInt uiLog2TrafoSize = g_aucConvertToBit[pcCU->getSlice()->getSPS()->getMaxCUWidth()]+2 - uiDepth; |
---|
[56] | 278 | UInt cbfY = pcCU->getCbf( uiAbsPartIdx, TEXT_LUMA , uiTrIdx ); |
---|
| 279 | UInt cbfU = pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_U, uiTrIdx ); |
---|
| 280 | UInt cbfV = pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_V, uiTrIdx ); |
---|
| 281 | |
---|
| 282 | if(uiTrIdx==0) |
---|
[2] | 283 | { |
---|
[56] | 284 | m_bakAbsPartIdxCU = uiAbsPartIdx; |
---|
[2] | 285 | } |
---|
[56] | 286 | if( uiLog2TrafoSize == 2 ) |
---|
[2] | 287 | { |
---|
[56] | 288 | UInt partNum = pcCU->getPic()->getNumPartInCU() >> ( ( uiDepth - 1 ) << 1 ); |
---|
| 289 | if( ( uiAbsPartIdx % partNum ) == 0 ) |
---|
| 290 | { |
---|
| 291 | m_uiBakAbsPartIdx = uiAbsPartIdx; |
---|
| 292 | m_uiBakChromaOffset = offsetChroma; |
---|
| 293 | } |
---|
| 294 | else if( ( uiAbsPartIdx % partNum ) == (partNum - 1) ) |
---|
| 295 | { |
---|
| 296 | cbfU = pcCU->getCbf( m_uiBakAbsPartIdx, TEXT_CHROMA_U, uiTrIdx ); |
---|
| 297 | cbfV = pcCU->getCbf( m_uiBakAbsPartIdx, TEXT_CHROMA_V, uiTrIdx ); |
---|
| 298 | } |
---|
[2] | 299 | } |
---|
[608] | 300 | |
---|
| 301 | if( pcCU->getPredictionMode(uiAbsPartIdx) == MODE_INTRA && pcCU->getPartitionSize(uiAbsPartIdx) == SIZE_NxN && uiDepth == pcCU->getDepth(uiAbsPartIdx) ) |
---|
| 302 | { |
---|
| 303 | assert( uiSubdiv ); |
---|
| 304 | } |
---|
| 305 | else if( pcCU->getPredictionMode(uiAbsPartIdx) == MODE_INTER && (pcCU->getPartitionSize(uiAbsPartIdx) != SIZE_2Nx2N) && uiDepth == pcCU->getDepth(uiAbsPartIdx) && (pcCU->getSlice()->getSPS()->getQuadtreeTUMaxDepthInter() == 1) ) |
---|
| 306 | { |
---|
| 307 | if ( uiLog2TrafoSize > pcCU->getQuadtreeTULog2MinSizeInCU(uiAbsPartIdx) ) |
---|
[2] | 308 | { |
---|
| 309 | assert( uiSubdiv ); |
---|
| 310 | } |
---|
[608] | 311 | else |
---|
[56] | 312 | { |
---|
[608] | 313 | assert(!uiSubdiv ); |
---|
[56] | 314 | } |
---|
[608] | 315 | } |
---|
| 316 | else if( uiLog2TrafoSize > pcCU->getSlice()->getSPS()->getQuadtreeTULog2MaxSize() ) |
---|
| 317 | { |
---|
| 318 | assert( uiSubdiv ); |
---|
| 319 | } |
---|
| 320 | else if( uiLog2TrafoSize == pcCU->getSlice()->getSPS()->getQuadtreeTULog2MinSize() ) |
---|
| 321 | { |
---|
| 322 | assert( !uiSubdiv ); |
---|
| 323 | } |
---|
| 324 | else if( uiLog2TrafoSize == pcCU->getQuadtreeTULog2MinSizeInCU(uiAbsPartIdx) ) |
---|
| 325 | { |
---|
| 326 | assert( !uiSubdiv ); |
---|
| 327 | } |
---|
| 328 | else |
---|
| 329 | { |
---|
| 330 | assert( uiLog2TrafoSize > pcCU->getQuadtreeTULog2MinSizeInCU(uiAbsPartIdx) ); |
---|
| 331 | m_pcEntropyCoderIf->codeTransformSubdivFlag( uiSubdiv, 5 - uiLog2TrafoSize ); |
---|
| 332 | } |
---|
| 333 | |
---|
| 334 | const UInt uiTrDepthCurr = uiDepth - pcCU->getDepth( uiAbsPartIdx ); |
---|
| 335 | const Bool bFirstCbfOfCU = uiTrDepthCurr == 0; |
---|
| 336 | if( bFirstCbfOfCU || uiLog2TrafoSize > 2 ) |
---|
| 337 | { |
---|
| 338 | if( bFirstCbfOfCU || pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_U, uiTrDepthCurr - 1 ) ) |
---|
[56] | 339 | { |
---|
[608] | 340 | m_pcEntropyCoderIf->codeQtCbf( pcCU, uiAbsPartIdx, TEXT_CHROMA_U, uiTrDepthCurr ); |
---|
[56] | 341 | } |
---|
[608] | 342 | if( bFirstCbfOfCU || pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_V, uiTrDepthCurr - 1 ) ) |
---|
[2] | 343 | { |
---|
[608] | 344 | m_pcEntropyCoderIf->codeQtCbf( pcCU, uiAbsPartIdx, TEXT_CHROMA_V, uiTrDepthCurr ); |
---|
[2] | 345 | } |
---|
[608] | 346 | } |
---|
| 347 | else if( uiLog2TrafoSize == 2 ) |
---|
| 348 | { |
---|
| 349 | assert( pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_U, uiTrDepthCurr ) == pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_U, uiTrDepthCurr - 1 ) ); |
---|
| 350 | assert( pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_V, uiTrDepthCurr ) == pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_V, uiTrDepthCurr - 1 ) ); |
---|
| 351 | } |
---|
| 352 | |
---|
| 353 | if( uiSubdiv ) |
---|
| 354 | { |
---|
| 355 | UInt size; |
---|
| 356 | width >>= 1; |
---|
| 357 | height >>= 1; |
---|
| 358 | size = width*height; |
---|
| 359 | uiTrIdx++; |
---|
| 360 | ++uiDepth; |
---|
| 361 | const UInt partNum = pcCU->getPic()->getNumPartInCU() >> (uiDepth << 1); |
---|
| 362 | |
---|
| 363 | xEncodeTransform( pcCU, offsetLuma, offsetChroma, uiAbsPartIdx, uiDepth, width, height, uiTrIdx, bCodeDQP ); |
---|
| 364 | |
---|
| 365 | uiAbsPartIdx += partNum; offsetLuma += size; offsetChroma += (size>>2); |
---|
| 366 | xEncodeTransform( pcCU, offsetLuma, offsetChroma, uiAbsPartIdx, uiDepth, width, height, uiTrIdx, bCodeDQP ); |
---|
| 367 | |
---|
| 368 | uiAbsPartIdx += partNum; offsetLuma += size; offsetChroma += (size>>2); |
---|
| 369 | xEncodeTransform( pcCU, offsetLuma, offsetChroma, uiAbsPartIdx, uiDepth, width, height, uiTrIdx, bCodeDQP ); |
---|
| 370 | |
---|
| 371 | uiAbsPartIdx += partNum; offsetLuma += size; offsetChroma += (size>>2); |
---|
| 372 | xEncodeTransform( pcCU, offsetLuma, offsetChroma, uiAbsPartIdx, uiDepth, width, height, uiTrIdx, bCodeDQP ); |
---|
| 373 | } |
---|
| 374 | else |
---|
| 375 | { |
---|
| 376 | #if !H_MV_ENC_DEC_TRAC |
---|
[2] | 377 | { |
---|
[608] | 378 | DTRACE_CABAC_VL( g_nSymbolCounter++ ); |
---|
| 379 | DTRACE_CABAC_T( "\tTrIdx: abspart=" ); |
---|
| 380 | DTRACE_CABAC_V( uiAbsPartIdx ); |
---|
| 381 | DTRACE_CABAC_T( "\tdepth=" ); |
---|
| 382 | DTRACE_CABAC_V( uiDepth ); |
---|
| 383 | DTRACE_CABAC_T( "\ttrdepth=" ); |
---|
| 384 | DTRACE_CABAC_V( pcCU->getTransformIdx( uiAbsPartIdx ) ); |
---|
| 385 | DTRACE_CABAC_T( "\n" ); |
---|
[2] | 386 | } |
---|
[608] | 387 | #endif |
---|
| 388 | |
---|
| 389 | if( pcCU->getPredictionMode(uiAbsPartIdx) != MODE_INTRA && uiDepth == pcCU->getDepth( uiAbsPartIdx ) && !pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_U, 0 ) && !pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_V, 0 ) ) |
---|
| 390 | { |
---|
| 391 | assert( pcCU->getCbf( uiAbsPartIdx, TEXT_LUMA, 0 ) ); |
---|
| 392 | // printf( "saved one bin! " ); |
---|
| 393 | } |
---|
[2] | 394 | else |
---|
| 395 | { |
---|
[608] | 396 | m_pcEntropyCoderIf->codeQtCbf( pcCU, uiAbsPartIdx, TEXT_LUMA, pcCU->getTransformIdx( uiAbsPartIdx ) ); |
---|
[2] | 397 | } |
---|
[56] | 398 | |
---|
[608] | 399 | |
---|
| 400 | if ( cbfY || cbfU || cbfV ) |
---|
[2] | 401 | { |
---|
[608] | 402 | // dQP: only for LCU once |
---|
| 403 | if ( pcCU->getSlice()->getPPS()->getUseDQP() ) |
---|
[2] | 404 | { |
---|
[608] | 405 | if ( bCodeDQP ) |
---|
[2] | 406 | { |
---|
[608] | 407 | encodeQP( pcCU, m_bakAbsPartIdxCU ); |
---|
| 408 | bCodeDQP = false; |
---|
[2] | 409 | } |
---|
| 410 | } |
---|
| 411 | } |
---|
[608] | 412 | if( cbfY ) |
---|
[2] | 413 | { |
---|
[608] | 414 | Int trWidth = width; |
---|
| 415 | Int trHeight = height; |
---|
| 416 | m_pcEntropyCoderIf->codeCoeffNxN( pcCU, (pcCU->getCoeffY()+offsetLuma), uiAbsPartIdx, trWidth, trHeight, uiDepth, TEXT_LUMA ); |
---|
[2] | 417 | } |
---|
[608] | 418 | if( uiLog2TrafoSize > 2 ) |
---|
[2] | 419 | { |
---|
[608] | 420 | Int trWidth = width >> 1; |
---|
| 421 | Int trHeight = height >> 1; |
---|
| 422 | if( cbfU ) |
---|
[2] | 423 | { |
---|
[608] | 424 | m_pcEntropyCoderIf->codeCoeffNxN( pcCU, (pcCU->getCoeffCb()+offsetChroma), uiAbsPartIdx, trWidth, trHeight, uiDepth, TEXT_CHROMA_U ); |
---|
[2] | 425 | } |
---|
[608] | 426 | if( cbfV ) |
---|
[56] | 427 | { |
---|
[608] | 428 | m_pcEntropyCoderIf->codeCoeffNxN( pcCU, (pcCU->getCoeffCr()+offsetChroma), uiAbsPartIdx, trWidth, trHeight, uiDepth, TEXT_CHROMA_V ); |
---|
[56] | 429 | } |
---|
[608] | 430 | } |
---|
| 431 | else |
---|
| 432 | { |
---|
| 433 | UInt partNum = pcCU->getPic()->getNumPartInCU() >> ( ( uiDepth - 1 ) << 1 ); |
---|
| 434 | if( ( uiAbsPartIdx % partNum ) == (partNum - 1) ) |
---|
[2] | 435 | { |
---|
[56] | 436 | Int trWidth = width; |
---|
| 437 | Int trHeight = height; |
---|
| 438 | if( cbfU ) |
---|
[2] | 439 | { |
---|
[608] | 440 | m_pcEntropyCoderIf->codeCoeffNxN( pcCU, (pcCU->getCoeffCb()+m_uiBakChromaOffset), m_uiBakAbsPartIdx, trWidth, trHeight, uiDepth, TEXT_CHROMA_U ); |
---|
[2] | 441 | } |
---|
[56] | 442 | if( cbfV ) |
---|
| 443 | { |
---|
[608] | 444 | m_pcEntropyCoderIf->codeCoeffNxN( pcCU, (pcCU->getCoeffCr()+m_uiBakChromaOffset), m_uiBakAbsPartIdx, trWidth, trHeight, uiDepth, TEXT_CHROMA_V ); |
---|
[56] | 445 | } |
---|
[2] | 446 | } |
---|
| 447 | } |
---|
| 448 | } |
---|
| 449 | } |
---|
| 450 | |
---|
| 451 | // Intra direction for Luma |
---|
[608] | 452 | Void TEncEntropy::encodeIntraDirModeLuma ( TComDataCU* pcCU, UInt absPartIdx, Bool isMultiplePU ) |
---|
[2] | 453 | { |
---|
[608] | 454 | m_pcEntropyCoderIf->codeIntraDirLumaAng( pcCU, absPartIdx , isMultiplePU); |
---|
[2] | 455 | } |
---|
| 456 | |
---|
| 457 | // Intra direction for Chroma |
---|
| 458 | Void TEncEntropy::encodeIntraDirModeChroma( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool bRD ) |
---|
| 459 | { |
---|
| 460 | if( bRD ) |
---|
[56] | 461 | { |
---|
[2] | 462 | uiAbsPartIdx = 0; |
---|
[56] | 463 | } |
---|
[2] | 464 | |
---|
| 465 | m_pcEntropyCoderIf->codeIntraDirChroma( pcCU, uiAbsPartIdx ); |
---|
| 466 | } |
---|
| 467 | |
---|
[608] | 468 | Void TEncEntropy::encodePredInfo( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool bRD ) |
---|
[2] | 469 | { |
---|
| 470 | if( bRD ) |
---|
[56] | 471 | { |
---|
[2] | 472 | uiAbsPartIdx = 0; |
---|
[56] | 473 | } |
---|
[2] | 474 | if( pcCU->isIntra( uiAbsPartIdx ) ) // If it is Intra mode, encode intra prediction mode. |
---|
| 475 | { |
---|
[608] | 476 | encodeIntraDirModeLuma ( pcCU, uiAbsPartIdx,true ); |
---|
| 477 | #if H_3D_DIM_SDC |
---|
| 478 | if(!pcCU->getSDCFlag(uiAbsPartIdx)) |
---|
[443] | 479 | #endif |
---|
[608] | 480 | encodeIntraDirModeChroma( pcCU, uiAbsPartIdx, bRD ); |
---|
[2] | 481 | } |
---|
| 482 | else // if it is Inter mode, encode motion vector and reference index |
---|
| 483 | { |
---|
[56] | 484 | encodePUWise( pcCU, uiAbsPartIdx, bRD ); |
---|
[2] | 485 | } |
---|
| 486 | } |
---|
| 487 | |
---|
| 488 | /** encode motion information for every PU block |
---|
| 489 | * \param pcCU |
---|
| 490 | * \param uiAbsPartIdx |
---|
| 491 | * \param bRD |
---|
| 492 | * \returns Void |
---|
| 493 | */ |
---|
| 494 | Void TEncEntropy::encodePUWise( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool bRD ) |
---|
| 495 | { |
---|
| 496 | if ( bRD ) |
---|
[56] | 497 | { |
---|
[2] | 498 | uiAbsPartIdx = 0; |
---|
[56] | 499 | } |
---|
| 500 | |
---|
[2] | 501 | PartSize ePartSize = pcCU->getPartitionSize( uiAbsPartIdx ); |
---|
| 502 | UInt uiNumPU = ( ePartSize == SIZE_2Nx2N ? 1 : ( ePartSize == SIZE_NxN ? 4 : 2 ) ); |
---|
| 503 | UInt uiDepth = pcCU->getDepth( uiAbsPartIdx ); |
---|
| 504 | UInt uiPUOffset = ( g_auiPUOffset[UInt( ePartSize )] << ( ( pcCU->getSlice()->getSPS()->getMaxCUDepth() - uiDepth ) << 1 ) ) >> 4; |
---|
| 505 | |
---|
| 506 | for ( UInt uiPartIdx = 0, uiSubPartIdx = uiAbsPartIdx; uiPartIdx < uiNumPU; uiPartIdx++, uiSubPartIdx += uiPUOffset ) |
---|
| 507 | { |
---|
[608] | 508 | #if H_MV_ENC_DEC_TRAC |
---|
| 509 | DTRACE_PU_S("=========== prediction_unit ===========\n") |
---|
| 510 | //Todo: |
---|
| 511 | //DTRACE_PU("x0", uiLPelX) |
---|
| 512 | //DTRACE_PU("x1", uiTPelY) |
---|
| 513 | #endif |
---|
| 514 | encodeMergeFlag( pcCU, uiSubPartIdx ); |
---|
[2] | 515 | if ( pcCU->getMergeFlag( uiSubPartIdx ) ) |
---|
| 516 | { |
---|
[608] | 517 | encodeMergeIndex( pcCU, uiSubPartIdx ); |
---|
[2] | 518 | } |
---|
| 519 | else |
---|
| 520 | { |
---|
| 521 | encodeInterDirPU( pcCU, uiSubPartIdx ); |
---|
| 522 | for ( UInt uiRefListIdx = 0; uiRefListIdx < 2; uiRefListIdx++ ) |
---|
| 523 | { |
---|
| 524 | if ( pcCU->getSlice()->getNumRefIdx( RefPicList( uiRefListIdx ) ) > 0 ) |
---|
| 525 | { |
---|
| 526 | encodeRefFrmIdxPU ( pcCU, uiSubPartIdx, RefPicList( uiRefListIdx ) ); |
---|
| 527 | encodeMvdPU ( pcCU, uiSubPartIdx, RefPicList( uiRefListIdx ) ); |
---|
| 528 | encodeMVPIdxPU ( pcCU, uiSubPartIdx, RefPicList( uiRefListIdx ) ); |
---|
| 529 | } |
---|
| 530 | } |
---|
| 531 | } |
---|
| 532 | } |
---|
| 533 | |
---|
| 534 | return; |
---|
| 535 | } |
---|
| 536 | |
---|
| 537 | Void TEncEntropy::encodeInterDirPU( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
| 538 | { |
---|
| 539 | if ( !pcCU->getSlice()->isInterB() ) |
---|
| 540 | { |
---|
| 541 | return; |
---|
| 542 | } |
---|
| 543 | |
---|
| 544 | m_pcEntropyCoderIf->codeInterDir( pcCU, uiAbsPartIdx ); |
---|
| 545 | return; |
---|
| 546 | } |
---|
| 547 | |
---|
| 548 | /** encode reference frame index for a PU block |
---|
| 549 | * \param pcCU |
---|
| 550 | * \param uiAbsPartIdx |
---|
| 551 | * \param eRefList |
---|
| 552 | * \returns Void |
---|
| 553 | */ |
---|
| 554 | Void TEncEntropy::encodeRefFrmIdxPU( TComDataCU* pcCU, UInt uiAbsPartIdx, RefPicList eRefList ) |
---|
| 555 | { |
---|
| 556 | assert( !pcCU->isIntra( uiAbsPartIdx ) ); |
---|
| 557 | { |
---|
[56] | 558 | if ( ( pcCU->getSlice()->getNumRefIdx( eRefList ) == 1 ) ) |
---|
| 559 | { |
---|
| 560 | return; |
---|
| 561 | } |
---|
[2] | 562 | |
---|
[56] | 563 | if ( pcCU->getInterDir( uiAbsPartIdx ) & ( 1 << eRefList ) ) |
---|
| 564 | { |
---|
| 565 | m_pcEntropyCoderIf->codeRefFrmIdx( pcCU, uiAbsPartIdx, eRefList ); |
---|
| 566 | } |
---|
[2] | 567 | } |
---|
| 568 | |
---|
| 569 | return; |
---|
| 570 | } |
---|
| 571 | |
---|
| 572 | /** encode motion vector difference for a PU block |
---|
| 573 | * \param pcCU |
---|
| 574 | * \param uiAbsPartIdx |
---|
| 575 | * \param eRefList |
---|
| 576 | * \returns Void |
---|
| 577 | */ |
---|
| 578 | Void TEncEntropy::encodeMvdPU( TComDataCU* pcCU, UInt uiAbsPartIdx, RefPicList eRefList ) |
---|
| 579 | { |
---|
| 580 | assert( !pcCU->isIntra( uiAbsPartIdx ) ); |
---|
| 581 | |
---|
| 582 | if ( pcCU->getInterDir( uiAbsPartIdx ) & ( 1 << eRefList ) ) |
---|
| 583 | { |
---|
| 584 | m_pcEntropyCoderIf->codeMvd( pcCU, uiAbsPartIdx, eRefList ); |
---|
| 585 | } |
---|
| 586 | return; |
---|
| 587 | } |
---|
| 588 | |
---|
| 589 | Void TEncEntropy::encodeMVPIdxPU( TComDataCU* pcCU, UInt uiAbsPartIdx, RefPicList eRefList ) |
---|
| 590 | { |
---|
[608] | 591 | if ( (pcCU->getInterDir( uiAbsPartIdx ) & ( 1 << eRefList )) ) |
---|
[2] | 592 | { |
---|
| 593 | m_pcEntropyCoderIf->codeMVPIdx( pcCU, uiAbsPartIdx, eRefList ); |
---|
| 594 | } |
---|
| 595 | |
---|
| 596 | return; |
---|
| 597 | } |
---|
| 598 | |
---|
| 599 | Void TEncEntropy::encodeQtCbf( TComDataCU* pcCU, UInt uiAbsPartIdx, TextType eType, UInt uiTrDepth ) |
---|
| 600 | { |
---|
| 601 | m_pcEntropyCoderIf->codeQtCbf( pcCU, uiAbsPartIdx, eType, uiTrDepth ); |
---|
| 602 | } |
---|
| 603 | |
---|
| 604 | Void TEncEntropy::encodeTransformSubdivFlag( UInt uiSymbol, UInt uiCtx ) |
---|
| 605 | { |
---|
| 606 | m_pcEntropyCoderIf->codeTransformSubdivFlag( uiSymbol, uiCtx ); |
---|
| 607 | } |
---|
| 608 | |
---|
| 609 | Void TEncEntropy::encodeQtRootCbf( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
| 610 | { |
---|
| 611 | m_pcEntropyCoderIf->codeQtRootCbf( pcCU, uiAbsPartIdx ); |
---|
| 612 | } |
---|
| 613 | |
---|
[608] | 614 | Void TEncEntropy::encodeQtCbfZero( TComDataCU* pcCU, TextType eType, UInt uiTrDepth ) |
---|
| 615 | { |
---|
| 616 | m_pcEntropyCoderIf->codeQtCbfZero( pcCU, eType, uiTrDepth ); |
---|
| 617 | } |
---|
| 618 | Void TEncEntropy::encodeQtRootCbfZero( TComDataCU* pcCU ) |
---|
| 619 | { |
---|
| 620 | m_pcEntropyCoderIf->codeQtRootCbfZero( pcCU ); |
---|
| 621 | } |
---|
| 622 | |
---|
[2] | 623 | // dQP |
---|
| 624 | Void TEncEntropy::encodeQP( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool bRD ) |
---|
| 625 | { |
---|
| 626 | if( bRD ) |
---|
[56] | 627 | { |
---|
[2] | 628 | uiAbsPartIdx = 0; |
---|
[56] | 629 | } |
---|
[2] | 630 | |
---|
[56] | 631 | if ( pcCU->getSlice()->getPPS()->getUseDQP() ) |
---|
[2] | 632 | { |
---|
| 633 | m_pcEntropyCoderIf->codeDeltaQP( pcCU, uiAbsPartIdx ); |
---|
| 634 | } |
---|
| 635 | } |
---|
| 636 | |
---|
| 637 | |
---|
| 638 | // texture |
---|
| 639 | /** encode coefficients |
---|
| 640 | * \param pcCU |
---|
| 641 | * \param uiAbsPartIdx |
---|
| 642 | * \param uiDepth |
---|
| 643 | * \param uiWidth |
---|
| 644 | * \param uiHeight |
---|
| 645 | */ |
---|
[56] | 646 | Void TEncEntropy::encodeCoeff( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, UInt uiWidth, UInt uiHeight, Bool& bCodeDQP ) |
---|
[2] | 647 | { |
---|
| 648 | UInt uiMinCoeffSize = pcCU->getPic()->getMinCUWidth()*pcCU->getPic()->getMinCUHeight(); |
---|
| 649 | UInt uiLumaOffset = uiMinCoeffSize*uiAbsPartIdx; |
---|
| 650 | UInt uiChromaOffset = uiLumaOffset>>2; |
---|
[782] | 651 | #if QC_SDC_UNIFY_G0130 |
---|
[608] | 652 | #if H_3D_DIM_SDC |
---|
[782] | 653 | if( pcCU->getSDCFlag( uiAbsPartIdx ) && pcCU->isIntra( uiAbsPartIdx ) ) |
---|
| 654 | { |
---|
| 655 | assert( pcCU->getPartitionSize(uiAbsPartIdx) == SIZE_2Nx2N ); |
---|
| 656 | assert( pcCU->getTransformIdx(uiAbsPartIdx) == 0 ); |
---|
| 657 | assert( pcCU->getCbf(uiAbsPartIdx, TEXT_LUMA) == 1 ); |
---|
| 658 | assert( pcCU->getCbf(uiAbsPartIdx, TEXT_CHROMA_U) == 1 ); |
---|
| 659 | assert( pcCU->getCbf(uiAbsPartIdx, TEXT_CHROMA_V) == 1 ); |
---|
| 660 | } |
---|
| 661 | #endif |
---|
| 662 | |
---|
| 663 | #if H_3D_INTER_SDC |
---|
| 664 | if( pcCU->getSDCFlag( uiAbsPartIdx ) && !pcCU->isIntra( uiAbsPartIdx ) ) |
---|
| 665 | { |
---|
| 666 | assert( !pcCU->isSkipped( uiAbsPartIdx ) ); |
---|
| 667 | assert( !pcCU->isIntra( uiAbsPartIdx) ); |
---|
| 668 | assert( pcCU->getSlice()->getIsDepth() ); |
---|
| 669 | } |
---|
| 670 | #endif |
---|
| 671 | |
---|
| 672 | if( pcCU->getSDCFlag( uiAbsPartIdx ) || pcCU->isIntra( uiAbsPartIdx ) ) |
---|
| 673 | { |
---|
| 674 | Int iPartNum = ( pcCU->isIntra( uiAbsPartIdx ) && pcCU->getPartitionSize( uiAbsPartIdx ) == SIZE_NxN ) ? 4 : 1; |
---|
| 675 | UInt uiPartOffset = ( pcCU->getPic()->getNumPartInCU() >> ( pcCU->getDepth( uiAbsPartIdx ) << 1 ) ) >> 2; |
---|
| 676 | |
---|
| 677 | if( !pcCU->getSDCFlag( uiAbsPartIdx ) ) |
---|
| 678 | { |
---|
| 679 | for( Int iPart = 0; iPart < iPartNum; iPart++ ) |
---|
| 680 | { |
---|
| 681 | if( getDimType( pcCU->getLumaIntraDir( uiAbsPartIdx + uiPartOffset*iPart ) ) < DIM_NUM_TYPE ) |
---|
| 682 | { |
---|
| 683 | m_pcEntropyCoderIf->codeDeltaDC( pcCU, uiAbsPartIdx + uiPartOffset*iPart ); |
---|
| 684 | } |
---|
| 685 | } |
---|
| 686 | } |
---|
| 687 | else |
---|
| 688 | { |
---|
| 689 | m_pcEntropyCoderIf->codeDeltaDC( pcCU, uiAbsPartIdx ); |
---|
| 690 | return; |
---|
| 691 | } |
---|
| 692 | } |
---|
| 693 | #else |
---|
| 694 | #if H_3D_DIM_SDC |
---|
[189] | 695 | if( pcCU->getSDCFlag( uiAbsPartIdx ) ) |
---|
| 696 | { |
---|
| 697 | assert( pcCU->getPartitionSize(uiAbsPartIdx) == SIZE_2Nx2N ); |
---|
| 698 | assert( pcCU->getTransformIdx(uiAbsPartIdx) == 0 ); |
---|
| 699 | assert( pcCU->getCbf(uiAbsPartIdx, TEXT_LUMA) == 1 ); |
---|
| 700 | assert( pcCU->getCbf(uiAbsPartIdx, TEXT_CHROMA_U) == 1 ); |
---|
| 701 | assert( pcCU->getCbf(uiAbsPartIdx, TEXT_CHROMA_V) == 1 ); |
---|
[608] | 702 | return; |
---|
| 703 | } |
---|
[443] | 704 | #endif |
---|
[608] | 705 | |
---|
[655] | 706 | #if H_3D_INTER_SDC |
---|
[608] | 707 | if( pcCU->getInterSDCFlag( uiAbsPartIdx ) ) |
---|
| 708 | { |
---|
| 709 | assert( !pcCU->isSkipped( uiAbsPartIdx ) ); |
---|
| 710 | assert( !pcCU->isIntra( uiAbsPartIdx) ); |
---|
| 711 | assert( pcCU->getSlice()->getIsDepth() ); |
---|
| 712 | |
---|
| 713 | encodeInterSDCResidualData( pcCU, uiAbsPartIdx, false ); |
---|
[189] | 714 | return; |
---|
| 715 | } |
---|
| 716 | #endif |
---|
[782] | 717 | #endif |
---|
[608] | 718 | |
---|
[2] | 719 | if( pcCU->isIntra(uiAbsPartIdx) ) |
---|
| 720 | { |
---|
[608] | 721 | #if !H_MV |
---|
[56] | 722 | DTRACE_CABAC_VL( g_nSymbolCounter++ ) |
---|
[2] | 723 | DTRACE_CABAC_T( "\tdecodeTransformIdx()\tCUDepth=" ) |
---|
| 724 | DTRACE_CABAC_V( uiDepth ) |
---|
| 725 | DTRACE_CABAC_T( "\n" ) |
---|
[608] | 726 | #endif |
---|
[2] | 727 | } |
---|
| 728 | else |
---|
| 729 | { |
---|
[608] | 730 | if( !(pcCU->getMergeFlag( uiAbsPartIdx ) && pcCU->getPartitionSize(uiAbsPartIdx) == SIZE_2Nx2N ) ) |
---|
[2] | 731 | { |
---|
[608] | 732 | m_pcEntropyCoderIf->codeQtRootCbf( pcCU, uiAbsPartIdx ); |
---|
[2] | 733 | } |
---|
[608] | 734 | if ( !pcCU->getQtRootCbf( uiAbsPartIdx ) ) |
---|
[189] | 735 | { |
---|
[608] | 736 | return; |
---|
[189] | 737 | } |
---|
| 738 | } |
---|
[608] | 739 | |
---|
| 740 | xEncodeTransform( pcCU, uiLumaOffset, uiChromaOffset, uiAbsPartIdx, uiDepth, uiWidth, uiHeight, 0, bCodeDQP); |
---|
[2] | 741 | } |
---|
| 742 | |
---|
[56] | 743 | Void TEncEntropy::encodeCoeffNxN( TComDataCU* pcCU, TCoeff* pcCoeff, UInt uiAbsPartIdx, UInt uiTrWidth, UInt uiTrHeight, UInt uiDepth, TextType eType ) |
---|
[608] | 744 | { |
---|
| 745 | // This is for Transform unit processing. This may be used at mode selection stage for Inter. |
---|
[56] | 746 | m_pcEntropyCoderIf->codeCoeffNxN( pcCU, pcCoeff, uiAbsPartIdx, uiTrWidth, uiTrHeight, uiDepth, eType ); |
---|
[2] | 747 | } |
---|
| 748 | |
---|
[56] | 749 | Void TEncEntropy::estimateBit (estBitsSbacStruct* pcEstBitsSbac, Int width, Int height, TextType eTType) |
---|
| 750 | { |
---|
| 751 | eTType = eTType == TEXT_LUMA ? TEXT_LUMA : TEXT_CHROMA; |
---|
| 752 | |
---|
| 753 | m_pcEntropyCoderIf->estBit ( pcEstBitsSbac, width, height, eTType ); |
---|
| 754 | } |
---|
| 755 | |
---|
| 756 | /** Encode SAO Offset |
---|
| 757 | * \param saoLcuParam SAO LCU paramters |
---|
| 758 | */ |
---|
[608] | 759 | Void TEncEntropy::encodeSaoOffset(SaoLcuParam* saoLcuParam, UInt compIdx) |
---|
[2] | 760 | { |
---|
[56] | 761 | UInt uiSymbol; |
---|
| 762 | Int i; |
---|
| 763 | |
---|
| 764 | uiSymbol = saoLcuParam->typeIdx + 1; |
---|
[608] | 765 | if (compIdx!=2) |
---|
| 766 | { |
---|
| 767 | m_pcEntropyCoderIf->codeSaoTypeIdx(uiSymbol); |
---|
| 768 | } |
---|
[56] | 769 | if (uiSymbol) |
---|
[2] | 770 | { |
---|
[608] | 771 | if (saoLcuParam->typeIdx < 4 && compIdx != 2) |
---|
| 772 | { |
---|
| 773 | saoLcuParam->subTypeIdx = saoLcuParam->typeIdx; |
---|
| 774 | } |
---|
| 775 | Int bitDepth = compIdx ? g_bitDepthC : g_bitDepthY; |
---|
| 776 | Int offsetTh = 1 << min(bitDepth - 5,5); |
---|
[56] | 777 | if( saoLcuParam->typeIdx == SAO_BO ) |
---|
| 778 | { |
---|
| 779 | for( i=0; i< saoLcuParam->length; i++) |
---|
| 780 | { |
---|
[608] | 781 | UInt absOffset = ( (saoLcuParam->offset[i] < 0) ? -saoLcuParam->offset[i] : saoLcuParam->offset[i]); |
---|
| 782 | m_pcEntropyCoderIf->codeSaoMaxUvlc(absOffset, offsetTh-1); |
---|
[56] | 783 | } |
---|
[608] | 784 | for( i=0; i< saoLcuParam->length; i++) |
---|
[56] | 785 | { |
---|
[608] | 786 | if (saoLcuParam->offset[i] != 0) |
---|
| 787 | { |
---|
| 788 | UInt sign = (saoLcuParam->offset[i] < 0) ? 1 : 0 ; |
---|
| 789 | m_pcEntropyCoderIf->codeSAOSign(sign); |
---|
| 790 | } |
---|
[56] | 791 | } |
---|
[608] | 792 | uiSymbol = (UInt) (saoLcuParam->subTypeIdx); |
---|
| 793 | m_pcEntropyCoderIf->codeSaoUflc(5, uiSymbol); |
---|
| 794 | } |
---|
| 795 | else if( saoLcuParam->typeIdx < 4 ) |
---|
[56] | 796 | { |
---|
[608] | 797 | m_pcEntropyCoderIf->codeSaoMaxUvlc( saoLcuParam->offset[0], offsetTh-1); |
---|
| 798 | m_pcEntropyCoderIf->codeSaoMaxUvlc( saoLcuParam->offset[1], offsetTh-1); |
---|
| 799 | m_pcEntropyCoderIf->codeSaoMaxUvlc(-saoLcuParam->offset[2], offsetTh-1); |
---|
| 800 | m_pcEntropyCoderIf->codeSaoMaxUvlc(-saoLcuParam->offset[3], offsetTh-1); |
---|
| 801 | if (compIdx!=2) |
---|
[56] | 802 | { |
---|
[608] | 803 | uiSymbol = (UInt) (saoLcuParam->subTypeIdx); |
---|
| 804 | m_pcEntropyCoderIf->codeSaoUflc(2, uiSymbol); |
---|
[56] | 805 | } |
---|
| 806 | } |
---|
| 807 | } |
---|
| 808 | } |
---|
| 809 | |
---|
| 810 | /** Encode SAO unit interleaving |
---|
| 811 | * \param rx |
---|
| 812 | * \param ry |
---|
| 813 | * \param pSaoParam |
---|
| 814 | * \param pcCU |
---|
| 815 | * \param iCUAddrInSlice |
---|
| 816 | * \param iCUAddrUpInSlice |
---|
| 817 | * \param bLFCrossSliceBoundaryFlag |
---|
[2] | 818 | */ |
---|
[608] | 819 | Void TEncEntropy::encodeSaoUnitInterleaving(Int compIdx, Bool saoFlag, Int rx, Int ry, SaoLcuParam* saoLcuParam, Int cuAddrInSlice, Int cuAddrUpInSlice, Int allowMergeLeft, Int allowMergeUp) |
---|
[2] | 820 | { |
---|
[608] | 821 | if (saoFlag) |
---|
[56] | 822 | { |
---|
[608] | 823 | if (rx>0 && cuAddrInSlice!=0 && allowMergeLeft) |
---|
[56] | 824 | { |
---|
[608] | 825 | m_pcEntropyCoderIf->codeSaoMerge(saoLcuParam->mergeLeftFlag); |
---|
| 826 | } |
---|
| 827 | else |
---|
| 828 | { |
---|
| 829 | saoLcuParam->mergeLeftFlag = 0; |
---|
| 830 | } |
---|
| 831 | if (saoLcuParam->mergeLeftFlag == 0) |
---|
| 832 | { |
---|
| 833 | if ( (ry > 0) && (cuAddrUpInSlice>=0) && allowMergeUp ) |
---|
[56] | 834 | { |
---|
[608] | 835 | m_pcEntropyCoderIf->codeSaoMerge(saoLcuParam->mergeUpFlag); |
---|
[56] | 836 | } |
---|
| 837 | else |
---|
| 838 | { |
---|
[608] | 839 | saoLcuParam->mergeUpFlag = 0; |
---|
[56] | 840 | } |
---|
[608] | 841 | if (!saoLcuParam->mergeUpFlag) |
---|
[56] | 842 | { |
---|
[608] | 843 | encodeSaoOffset(saoLcuParam, compIdx); |
---|
[56] | 844 | } |
---|
| 845 | } |
---|
| 846 | } |
---|
| 847 | } |
---|
| 848 | |
---|
| 849 | Int TEncEntropy::countNonZeroCoeffs( TCoeff* pcCoef, UInt uiSize ) |
---|
| 850 | { |
---|
| 851 | Int count = 0; |
---|
| 852 | |
---|
| 853 | for ( Int i = 0; i < uiSize; i++ ) |
---|
[2] | 854 | { |
---|
[56] | 855 | count += pcCoef[i] != 0; |
---|
[2] | 856 | } |
---|
[56] | 857 | |
---|
| 858 | return count; |
---|
| 859 | } |
---|
[2] | 860 | |
---|
[56] | 861 | /** encode quantization matrix |
---|
| 862 | * \param scalingList quantization matrix information |
---|
| 863 | */ |
---|
| 864 | Void TEncEntropy::encodeScalingList( TComScalingList* scalingList ) |
---|
| 865 | { |
---|
| 866 | m_pcEntropyCoderIf->codeScalingList( scalingList ); |
---|
[2] | 867 | } |
---|
| 868 | |
---|
[655] | 869 | #if H_3D_INTER_SDC |
---|
[782] | 870 | #if QC_SDC_UNIFY_G0130 |
---|
| 871 | Void TEncEntropy::encodeDeltaDC ( TComDataCU* pcCU, UInt absPartIdx ) |
---|
| 872 | { |
---|
| 873 | m_pcEntropyCoderIf->codeDeltaDC( pcCU, absPartIdx ); |
---|
| 874 | } |
---|
| 875 | |
---|
| 876 | Void TEncEntropy::encodeSDCFlag( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool bRD ) |
---|
| 877 | { |
---|
| 878 | if( ( !pcCU->isIntra( uiAbsPartIdx ) && !pcCU->getSlice()->getVPS()->getInterSDCFlag( pcCU->getSlice()->getLayerIdInVps() ) ) || |
---|
| 879 | ( pcCU->isIntra( uiAbsPartIdx ) && !pcCU->getSlice()->getVPS()->getVpsDepthModesFlag( pcCU->getSlice()->getLayerIdInVps() ) ) ) |
---|
| 880 | { |
---|
| 881 | return; |
---|
| 882 | } |
---|
| 883 | |
---|
| 884 | if( !pcCU->getSlice()->getIsDepth() || ( pcCU->isIntra( uiAbsPartIdx ) && pcCU->getPartitionSize( uiAbsPartIdx ) != SIZE_2Nx2N ) || pcCU->isSkipped( uiAbsPartIdx ) ) |
---|
| 885 | { |
---|
| 886 | return; |
---|
| 887 | } |
---|
| 888 | |
---|
| 889 | assert( ( pcCU->isIntra( uiAbsPartIdx ) && pcCU->getPartitionSize( uiAbsPartIdx ) == SIZE_2Nx2N ) || ( !pcCU->isIntra( uiAbsPartIdx ) && !pcCU->isSkipped( uiAbsPartIdx ) ) ); |
---|
| 890 | |
---|
| 891 | if( bRD ) |
---|
| 892 | { |
---|
| 893 | uiAbsPartIdx = 0; |
---|
| 894 | } |
---|
| 895 | |
---|
| 896 | m_pcEntropyCoderIf->codeSDCFlag( pcCU, uiAbsPartIdx ); |
---|
| 897 | } |
---|
| 898 | #else |
---|
[608] | 899 | Void TEncEntropy::encodeInterSDCFlag( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool bRD ) |
---|
[56] | 900 | { |
---|
[608] | 901 | if( !pcCU->getSlice()->getVPS()->getInterSDCFlag( pcCU->getSlice()->getLayerIdInVps() ) ) |
---|
| 902 | { |
---|
| 903 | return; |
---|
| 904 | } |
---|
[2] | 905 | |
---|
[608] | 906 | if( !pcCU->getSlice()->getIsDepth() || pcCU->isIntra( uiAbsPartIdx ) || pcCU->isSkipped( uiAbsPartIdx ) ) |
---|
[56] | 907 | { |
---|
[608] | 908 | return; |
---|
[56] | 909 | } |
---|
[2] | 910 | |
---|
[189] | 911 | if( bRD ) |
---|
[608] | 912 | { |
---|
[189] | 913 | uiAbsPartIdx = 0; |
---|
[608] | 914 | } |
---|
| 915 | |
---|
| 916 | m_pcEntropyCoderIf->codeInterSDCFlag( pcCU, uiAbsPartIdx ); |
---|
[189] | 917 | } |
---|
| 918 | |
---|
[608] | 919 | Void TEncEntropy::encodeInterSDCResidualData( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool bRD ) |
---|
[189] | 920 | { |
---|
[608] | 921 | if( !pcCU->getSlice()->getVPS()->getInterSDCFlag( pcCU->getSlice()->getLayerIdInVps() ) ) |
---|
| 922 | { |
---|
| 923 | return; |
---|
| 924 | } |
---|
| 925 | |
---|
| 926 | if( !pcCU->getSlice()->getIsDepth() || pcCU->isIntra( uiAbsPartIdx ) || !pcCU->getInterSDCFlag( uiAbsPartIdx ) ) |
---|
| 927 | { |
---|
| 928 | return; |
---|
| 929 | } |
---|
| 930 | |
---|
[189] | 931 | if( bRD ) |
---|
[608] | 932 | { |
---|
[189] | 933 | uiAbsPartIdx = 0; |
---|
[608] | 934 | } |
---|
| 935 | |
---|
[189] | 936 | // number of segments depends on prediction mode for INTRA |
---|
[608] | 937 | UInt uiNumSegments = ( pcCU->getPartitionSize( uiAbsPartIdx ) == SIZE_2Nx2N ) ? 1 : ( pcCU->getPartitionSize( uiAbsPartIdx ) == SIZE_NxN ? 4 : 2 ); |
---|
| 938 | |
---|
[189] | 939 | // encode residual data for each segment |
---|
| 940 | for( UInt uiSeg = 0; uiSeg < uiNumSegments; uiSeg++ ) |
---|
[608] | 941 | { |
---|
| 942 | m_pcEntropyCoderIf->codeInterSDCResidualData( pcCU, uiAbsPartIdx, uiSeg ); |
---|
| 943 | } |
---|
[189] | 944 | } |
---|
| 945 | #endif |
---|
[782] | 946 | #endif |
---|
[189] | 947 | |
---|
[56] | 948 | //! \} |
---|