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