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