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